diff --git a/example/Dev.tsx b/example/Dev.tsx index e3e2b0d6..f01f31c5 100644 --- a/example/Dev.tsx +++ b/example/Dev.tsx @@ -14,16 +14,17 @@ import { import Clipboard from '@react-native-clipboard/clipboard'; import { backupAccount, + getAddressBalance, importAccount, setupLdk, syncLdk, - getAddressBalance, updateHeader, } from './ldk'; import { connectToElectrum, subscribeToHeader } from './electrum'; import ldk from '@synonymdev/react-native-ldk/dist/ldk'; import lm, { EEventTypes, + ENetworks, TChannelManagerClaim, TChannelManagerPaymentPathFailed, TChannelManagerPaymentPathSuccessful, @@ -646,6 +647,7 @@ const Dev = (): ReactElement => { const restoreRes = await lm.restoreFromRemoteServer({ account, serverDetails: backupServerDetails, + network: ENetworks.regtest, overwrite: true, }); diff --git a/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt b/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt index 592c8870..c28b90e8 100644 --- a/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt +++ b/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt @@ -1144,17 +1144,14 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod @ReactMethod fun backupSetup(seed: String, network: String, server: String, serverPubKey: String, promise: Promise) { val seedBytes = seed.hexa() - if (keysManager == null) { - val nanoSeconds = System.currentTimeMillis() * 1000 - val seconds = nanoSeconds / 1000 / 1000 - if (seedBytes.count() != 32) { - return handleReject(promise, LdkErrors.invalid_seed_hex) - } - - keysManager = KeysManager.of(seedBytes, seconds, nanoSeconds.toInt()) + if (seedBytes.count() != 32) { + return handleReject(promise, LdkErrors.invalid_seed_hex) } - val pubKeyRes = keysManager!!.as_NodeSigner().get_node_id(Recipient.LDKRecipient_Node) + val nanoSeconds = System.currentTimeMillis() * 1000 + val seconds = nanoSeconds / 1000 / 1000 + val keysManager = KeysManager.of(seedBytes, seconds, nanoSeconds.toInt()) + val pubKeyRes = keysManager.as_NodeSigner().get_node_id(Recipient.LDKRecipient_Node) if (!pubKeyRes.is_ok) { return handleReject(promise, LdkErrors.backup_setup_failed) } @@ -1162,7 +1159,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod try { BackupClient.skipRemoteBackup = false BackupClient.setup( - keysManager!!._node_secret_key, + keysManager._node_secret_key, (pubKeyRes as Result_PublicKeyNoneZ_OK).res, network, server, diff --git a/lib/ios/Ldk.swift b/lib/ios/Ldk.swift index 01a61345..61aeb150 100644 --- a/lib/ios/Ldk.swift +++ b/lib/ios/Ldk.swift @@ -1230,25 +1230,27 @@ class Ldk: NSObject { @objc func backupSetup(_ seed: NSString, network: NSString, server: NSString, serverPubKey: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { let seedBytes = String(seed).hexaBytes - if keysManager == nil { - let seconds = UInt64(NSDate().timeIntervalSince1970) - let nanoSeconds = UInt32.init(truncating: NSNumber(value: seconds * 1000 * 1000)) - - guard seedBytes.count == 32 else { - return handleReject(reject, .invalid_seed_hex) - } - - keysManager = KeysManager(seed: String(seed).hexaBytes, startingTimeSecs: seconds, startingTimeNanos: nanoSeconds) + + guard seedBytes.count == 32 else { + return handleReject(reject, .invalid_seed_hex) } + + let seconds = UInt64(NSDate().timeIntervalSince1970) + let nanoSeconds = UInt32.init(truncating: NSNumber(value: seconds * 1000 * 1000)) + let keysManager = KeysManager( + seed: String(seed).hexaBytes, + startingTimeSecs: seconds, + startingTimeNanos: nanoSeconds + ) - guard let pubKey = keysManager!.asNodeSigner().getNodeId(recipient: .Node).getValue() else { + guard let pubKey = keysManager.asNodeSigner().getNodeId(recipient: .Node).getValue() else { return handleReject(reject, .backup_setup_failed, "Failed to get nodeID from keysManager") } do { BackupClient.skipRemoteBackup = false try BackupClient.setup( - secretKey: keysManager!.getNodeSecretKey(), + secretKey: keysManager.getNodeSecretKey(), pubKey: pubKey, network: String(network), server: String(server), diff --git a/lib/src/lightning-manager.ts b/lib/src/lightning-manager.ts index a778a4cc..6f9b8482 100644 --- a/lib/src/lightning-manager.ts +++ b/lib/src/lightning-manager.ts @@ -905,10 +905,12 @@ class LightningManager { restoreFromRemoteServer = async ({ account, serverDetails, + network, overwrite = false, }: { account: TAccount; serverDetails: TBackupServerDetails; + network: ENetworks; overwrite?: boolean; }): Promise> => { //Make sure LDK is not running. @@ -924,7 +926,7 @@ class LightningManager { const backupSetupRes = await ldk.backupSetup({ seed: account.seed, - network: this.network, + network, details: serverDetails, }); if (backupSetupRes.isErr()) {