diff --git a/README.md b/README.md index edbb328..68f90ea 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Fireblocks NCW SDK bridge for React Native npm install @fireblocks/react-native-ncw-sdk ``` +### Android additional setup + +Add the Maven repository and SDK dependency to your app as described [here](https://ncw-developers.fireblocks.com/docs/setup-4#android-sdk-installation) + ### iOS additional setup 1. Edit the following line to your app's `Podfile` @@ -19,11 +23,13 @@ npm install @fireblocks/react-native-ncw-sdk 2. Install pod dependencies: ```sh -cd example/ios && bundle exec pod install +cd ios && bundle exec pod install ``` -3. Open your project's workspace in xcode +3. Open your project's workspace in Xcode + +4. Add Fireblocks SDK Swift Package as described [here](https://ncw-developers.fireblocks.com/docs/setup-4#ios-sdk-installation), or: -4. File > Add Package Dependecies... > https://github.com/fireblocks/ncw-ios-sdk > Add Package > Add to Target: "Your Project" > Add Package +File > Add Package Dependecies... > https://github.com/fireblocks/ncw-ios-sdk > Add Package > Add to Target: "Your Project" > Add Package ## Usage diff --git a/android/src/main/java/com/fireblocks/reactnativencwsdk/ReactNativeNcwSdkModule.kt b/android/src/main/java/com/fireblocks/reactnativencwsdk/ReactNativeNcwSdkModule.kt index eee2bcc..feaf228 100644 --- a/android/src/main/java/com/fireblocks/reactnativencwsdk/ReactNativeNcwSdkModule.kt +++ b/android/src/main/java/com/fireblocks/reactnativencwsdk/ReactNativeNcwSdkModule.kt @@ -118,6 +118,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont listenerCount -= count } + @ReactMethod override fun handleResponse(response: ReadableMap, promise: Promise) { val opId = response.getInt("opId") val cb = operations.remove(opId) @@ -129,10 +130,12 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont } } + @ReactMethod override fun getPhysicalDeviceId(): String { return Fireblocks.getPhysicalDeviceId() } + @ReactMethod override fun initialize(deviceId: String, promise: Promise) { if (ReactNativeNcwSdkModule.initializedDevices.contains(deviceId)) { Log.d(TAG, "Device already initialized: $deviceId") @@ -400,6 +403,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont } } + @ReactMethod override fun getKeysStatus(deviceId: String, promise: Promise) { try { val instance: Fireblocks = Fireblocks.getInstance(deviceId) @@ -419,6 +423,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont } } + @ReactMethod override fun generateMPCKeys(deviceId: String, algorithms: ReadableArray, promise: Promise) { try { val instance: Fireblocks = Fireblocks.getInstance(deviceId) @@ -443,6 +448,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont } } + @ReactMethod override fun backupKeys( deviceId: String, passphrase: String, @@ -467,6 +473,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont } } + @ReactMethod override fun recoverKeys(deviceId: String, promise: Promise) { try { val instance: Fireblocks = Fireblocks.getInstance(deviceId) @@ -511,6 +518,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont } } + @ReactMethod override fun takeover(deviceId: String, promise: Promise) { try { Log.d(TAG, "Takeover deviceId: $deviceId") @@ -534,6 +542,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont } } + @ReactMethod override fun requestJoinExistingWallet(deviceId: String, promise: Promise) { try { val handler = JoinWalletHandler( @@ -568,6 +577,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont } } + @ReactMethod override fun stopJoinWallet(deviceId: String) { try { Log.d(TAG, "Stop Join Wallet deviceId: $deviceId") @@ -578,6 +588,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont } } + @ReactMethod override fun approveJoinWalletRequest(deviceId: String, requestId: String, promise: Promise) { try { Log.d(TAG, "Approve Join Wallet Request deviceId: $deviceId") @@ -637,6 +648,7 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont // } // } + @ReactMethod override fun deriveAssetKey( deviceId: String, extendedPrivateKey: String, @@ -660,34 +672,36 @@ class ReactNativeNcwSdkModule internal constructor(context: ReactApplicationCont } } - override fun signTransaction(deviceId: String, txId: String, promise: Promise) { - try { - val instance: Fireblocks = Fireblocks.getInstance(deviceId) - instance.signTransaction(txId) { signedTx: TransactionSignature -> - promise.resolve(signedTx.transactionSignatureStatus.toString()) - } - } catch (e: Exception) { - promise.reject("Error", e.message) - return - } - } + @ReactMethod + override fun signTransaction(deviceId: String, txId: String, promise: Promise) { + try { + val instance: Fireblocks = Fireblocks.getInstance(deviceId) + instance.signTransaction(txId) { signedTx: TransactionSignature -> + promise.resolve(signedTx.transactionSignatureStatus.toString()) + } + } catch (e: Exception) { + promise.reject("Error", e.message) + return + } + } - override fun getTransactionSignatureStatus(deviceId: String, txId: String, promise: Promise) { - try { - val instance: Fireblocks = Fireblocks.getInstance(deviceId) - val signedTx: TransactionSignature? = instance.getTransactionSignatureStatus(txId) - promise.resolve(signedTx?.transactionSignatureStatus.toString()) - } catch (e: Exception) { - promise.reject("Error", e.message) - return - } - } + @ReactMethod + override fun getTransactionSignatureStatus(deviceId: String, txId: String, promise: Promise) { + try { + val instance: Fireblocks = Fireblocks.getInstance(deviceId) + val signedTx: TransactionSignature? = instance.getTransactionSignatureStatus(txId) + promise.resolve(signedTx?.transactionSignatureStatus.toString()) + } catch (e: Exception) { + promise.reject("Error", e.message) + return + } + } - companion object { - private const val TAG = "Fireblocks:NCW" + companion object { + private const val TAG = "Fireblocks:NCW" - const val NAME = "ReactNativeNcwSdk" + const val NAME = "ReactNativeNcwSdk" - private val initializedDevices: MutableSet = HashSet() - } + private val initializedDevices: MutableSet = HashSet() + } } diff --git a/android/src/oldarch/ReactNativeNcwSdkSpec.kt b/android/src/oldarch/ReactNativeNcwSdkSpec.kt index 24ab453..e266468 100644 --- a/android/src/oldarch/ReactNativeNcwSdkSpec.kt +++ b/android/src/oldarch/ReactNativeNcwSdkSpec.kt @@ -2,10 +2,34 @@ package com.fireblocks.reactnativencwsdk import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule +import com.facebook.react.bridge.ReadableArray +import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.Promise abstract class ReactNativeNcwSdkSpec internal constructor(context: ReactApplicationContext) : ReactContextBaseJavaModule(context) { - abstract fun multiply(a: Double, b: Double, promise: Promise) + abstract fun handleResponse(response: ReadableMap, promise: Promise) + abstract fun getPhysicalDeviceId(): String + abstract fun initialize(deviceId: String, promise: Promise) + abstract fun getKeysStatus(deviceId: String, promise: Promise) + abstract fun generateMPCKeys(deviceId: String, algorithms: ReadableArray, promise: Promise) + abstract fun backupKeys( + deviceId: String, + passphrase: String, + passphraseId: String, + promise: Promise + ) + abstract fun recoverKeys(deviceId: String, promise: Promise) + abstract fun takeover(deviceId: String, promise: Promise) + abstract fun requestJoinExistingWallet(deviceId: String, promise: Promise) + abstract fun stopJoinWallet(deviceId: String) + abstract fun approveJoinWalletRequest(deviceId: String, requestId: String, promise: Promise) + abstract fun deriveAssetKey( + deviceId: String, + extendedPrivateKey: String, + bip44DerivationParams: ReadableMap + ): String? + abstract fun signTransaction(deviceId: String, txId: String, promise: Promise) + abstract fun getTransactionSignatureStatus(deviceId: String, txId: String, promise: Promise) } diff --git a/package.json b/package.json index d1517d2..4ee053f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fireblocks/react-native-ncw-sdk", - "version": "0.1.5", + "version": "0.1.6", "description": "NCW SDK Native bridge", "main": "lib/commonjs/index", "module": "lib/module/index",