Mobile SDK 对 imkey-core 做了封装,可以在android 和 ios 平台方便地接入 imkey-core。
-
初始化蓝牙
Ble.getInstance().initialize(mContext,new Locale("en"));
-
搜索imkey
Ble.getInstance().startScan(20, new ScanCallback() {...
-
连接imkey
Ble.getInstance().connect(bleDevice, 30, new ConnectCallback() {...
-
连接成功后可以调用业务接口,例如更新applet:
DeviceApi.updateApplet(appletName);
-
绑定设备(资产相关接口需要先绑定设备)
-
检查绑定状态
String status = DeviceApi.bindCheck();
-
如果是首次绑定需要调用显示绑定码接口
DeviceApi.displayBindCode();
-
绑定设备,传入imkey显示的绑定码(首次绑定)或用户输入的绑定码(非首次绑定)
String status = DeviceApi.bindAcquire(bindCode);
-
-
绑定成功即可调用资产相关接口例如:
-
获取以太坊地址
EthApi.getAddress(Path.ETH_LEDGER);
-
以太坊交易签名
ethapi.Eth.EthTxReq ethTxReq = ethapi.Eth.EthTxReq.newBuilder() .setPath(Path.ETH_LEDGER) .setChainId("28") .setNonce("8") .setGasPrice("20000000008") .setGasLimit("189000") .setTo("0x3535353535353535353535353535353535353535") .setValue("512") .setData("") .setPayment("0.01 ETH") .setReceiver("0xE6F4142dfFA574D1d9f18770BF73814df07931F3") .setSender("0x6031564e7b2F5cc33737807b2E58DaFF870B590b") .setFee("0.0032 ether") .build(); Eth.EthTxRes res = null; try { res = EthApi.signTx(ethTxReq); } catch (Exception e) { e.printStackTrace(); }
-
-
初始化蓝牙
let initRes = BLE.shared().initialize()
-
搜索imkey
let res:Int = BLE.shared().startScan()
-
连接imkey
let result = try BLE.shared().connect(address: device.address,timeout: 12*1000)
-
连接成功后可以调用业务接口,例如更新applet:
try DeviceAPI.updateApp(appletName: appletName)
-
绑定设备(资产相关接口需要先绑定设备)
-
检查绑定状态
let status = try DeviceAPI.bindCheck()
-
如果是首次绑定需要调用显示绑定码接口
try DeviceAPI.displayBindCode()
-
绑定设备,传入imkey显示的绑定码(首次绑定)或用户输入的绑定码(非首次绑定)
let bindResult = try DeviceAPI.bindAcquire(bindCode: bindCode!)
-
-
绑定成功即可调用资产相关接口例如:
-
获取以太坊地址
let address = try EthApi.getAddress(path: BIP44.eth)
-
以太坊交易签名
var ethInput = Ethapi_EthTxReq() ethInput.nonce = "8" ethInput.gasPrice = "20000000008" ethInput.gasLimit = "189000" ethInput.to = "0x3535353535353535353535353535353535353535" ethInput.value = "512" ethInput.data = "" ethInput.payment = "0.01 ETH" ethInput.receiver = "0xE6F4142dfFA574D1d9f18770BF73814df07931F3" ethInput.sender = "0x6031564e7b2F5cc33737807b2E58DaFF870B590b" ethInput.fee = "0.0032 ether" ethInput.path = "m/44'/60'/0'/0/0" ethInput.chainID = "28" let output = try! EthApi.signTX(ethInput: ethInput)
-