Bytom Mobile wallet SDK Development Basics

Source: Internet
Author: User
Tags git clone

Compared to the original project warehouse:

GitHub Address: Https://github.com/Bytom/bytom

Gitee Address: Https://gitee.com/BytomBlockchain/bytom

BYTOM-MOBILE-WALLET-SDK is the wallet layer code from the Bytom source, and the wallet layer code is modified. Using Gomobile, you can compile your code into an SDK available for Android and iOS platforms, and use the compiled Android and iOS Wallet SDK to create Bytom keys, accounts, addresses, and transaction signing functions on the mobile side.

BYTOM-MOBILE-WALLET-SDK Source Introduction

The SDK source is stacked in the project's SDK folder, the Android and iOS folders are demo projects using the SDK, and the bind.go can be externally called functions as an API for Android and iOS calls. The key pair created by Bytom is stored in a separate file on the disk, and the private key is encrypted, and the account address data is stored in the leveldb of the go implementation, so the Android and iOS platforms also need to provide the path to the data store.

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}}

Android and iOS platform call the other Wallet API before you need to call Initwallet This API, parameter is the absolute path on disk, Initwallet will be a whole wallet initialization, the most important of which is to initialize LEVELDB storage. Other CreateKey, CreateAccount, Createaccountreceiver is the creation of keys, accounts, addresses, etc. api,restorewallet API to the wallet all account address assets to back up the export data in JSON format.

Compilation of BYTOM-MOBILE-WALLET-SDK

The compilation of SDK code first requires the correct installation of Golang and Gomobile,golang requires more than 1.7 versions.
The Android platform requires the installation of the JDK, Android SDK, Android NDK, and the Platform-tools, Ndk-bundle of the Android SDK to be added to the path system environment variable. iOS platform compilation environment configuration is relatively simple only need to install Xcode.
Clone project to local $GOPATH/SRC:

 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/ndkcd $GOPATH/src/github.com/bytom-community/mobilegomobile bind -target=android github.com/bytom-community/mobile/sdk/

If you need to reduce the volume of the SDK to the gomobile bind Directive plus the-ldflags=-s parameter:

gomobile bind -target=android -ldflags=-s github.com/bytom-community/mobile/sdk/

The Wallet.aar and Wallet-sources.jar files are generated in the Mobile folder after the instruction is executed.

Ios

cd $GOPATH/src/github.com/bytom-community/mobilegomobile bind -target=ios github.com/bytom-community/mobile/sdk/

If you need to reduce the volume of the SDK to the gomobile bind Directive plus the-LDFLAGS=-W parameter:

$ gomobile bind -target=ios -ldflags=-w github.com/bytom-community/mobile/sdk/

The Wallet.framework file is generated in the Mobile folder after the instruction is executed.
Because Gomobile does not now support Bitcode, the generated iOS SDK does not support Bitcode.

Use of BYTOM-MOBILE-WALLET-SDK

Android

Copy Wallet.aar and Wallet-sources.ja to the Android Project's Libs folder and add it 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')}

After Sync project, you can make calls to the SDK API in your 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

By adding wallet.framework to your project through the project Target's linked frameworks and libraries, you can invoke the SDK API in your 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  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.