Address: https://github.com/Bytom-Community/Bytom-Mobile-Wallet-SDK
The code of wallet layer is extracted from the bytom source code,and modified the code of wallet layer . Gomobile can be used to compile the code into SDK available on Android and iOS platforms, while the compiled Android and iOS wallet SDK can be used to create bytom keys, accounts, addresses and transaction signatures on the mobile side.
Bytom Mobile Wallet SDK source code introduction
The SDK source code is placed in the SDK file of the project, the android and ios files are the demo projects which using the SDK.bind. Go
The function that can be called externally with the first letter in uppercase will be the API provided for Android and iOS calls in “bind.go.”The private key created by bytom are stored in separate files on disk and encrypted with the private key, and the account address data is stored in leveldb on the go implementation, so Android and iOS platforms also need to provide a path to store the data .
func InitWallet(storagePath string) {
hsm := pseudohsm.New(storagePath)
walletDB := db.NewDB("wallet", "leveldb", storagePath)
accounts := account.NewManager(walletDB)
assets := asset.NewRegistry(walletDB)
wallet := aWallet.NewWallet(walletDB, accounts, assets, hsm)
api = aApi.API{Wallet: wallet}
}
The Android and iOS platforms need to call InitWallet before calling other wallets’ api. The parameter is the absolute path on disk. InitWallet will initialize the whole wallet.
The most important is to initialize leveldb’s storage. Other CreateKey, CreateAccount, CreateAccountReceiver are apis for creating keys, accounts, addresses, and so on.RestoreWallet
API can back up all of the wallet accounts ,addresses and assets to export data in json format.
Bytom Mobile Wallet SDK compile
Compiling the SDK code first requires the proper installation of golang and gomobile, and golang version requires more than 1.7.
The Android platform needs to install JDK, Android SDK, Android NDK, and need to install platform-tools and ndk-bundle of Android SDK
to add to the environment variable of PATH system. The configuration of iOS platform compiler’s environment is relatively simple and only needs to install Xcode.
Clone project to local $GOPATH/ SRC below:
git clone https://github.com/Bytom-Community/Bytom-Mobile-Wallet-SDK $GOPATH/src/github.com/bytom-community/mobile
Android
gomobile init -ndk ~/path/to/your/ndk
cd $GOPATH/src/github.com/bytom-community/mobile
gomobile bind -target=android github.com/bytom-community/mobile/sdk/
If you need to reduce the volume of the SDK, add the -ldflags=-s parameter to the gomobile bind instruction:
gomobile bind -target=android -ldflags=-s github.com/bytom-community/mobile/sdk/
After executing the instruction, the wallet.aar and the wallet sources.jar files will be generated in the mobile file.
iOS
cd $GOPATH/src/github.com/bytom-community/mobile
gomobile bind -target=ios github.com/bytom-community/mobile/sdk/
If you need to reduce the volume of the SDK,add the -ldflags=-w parameter to the gomibile bind instrucution:
$ gomobile bind -target=ios -ldflags=-w github.com/bytom-community/mobile/sdk/
After executing the instruction, the wallet. Framework file will be generated in the mobile file.
Since gomobile does not currently support bitcode, the generated iOS SDK does not support bitcode either.
Bytom Mobile Wallet SDK use:
Android
Copy the wallet. Aar and the wallet sources.ja to the libs file of the Android project’s app, and add to the build.gradle file in the app module:
android {
repositories {
flatDir { dirs 'libs' }
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation(name: 'wallet', ext: 'aar')
}
sync project could call for the SDK’s APO in Android project:
package io.bytom.community;import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import wallet.Wallet;public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView keyTextView = (TextView) findViewById(R.id.key_textview); String storagePath = getFilesDir().toString();
Log.d(“storagePath”, storagePath); Wallet.initWallet(storagePath);
String keyResult = Wallet.createKey(“Marshall”, “123456”);
Log.d(“keyResult”, keyResult);
keyTextView.setText(keyResult);
}
}
iOS
Add the wallet. Framework to the project through the Linked frameworks and libraries of project target. The SDK API can be called in the iOS project:
#import “ViewController.h”
#import “Wallet/Wallet.h” // Gomobile bind generated framework@interface ViewController ()
@end@implementation ViewController@synthesize textLabel;- (void)loadView {
[super loadView];
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
WalletInitWallet(docPath);
textLabel.text = WalletCreateKey(@”kevin”,@”123456");
}@end