diff --git a/BDKSwiftExampleWallet.xcodeproj/project.pbxproj b/BDKSwiftExampleWallet.xcodeproj/project.pbxproj index 6e396fa..df04026 100644 --- a/BDKSwiftExampleWallet.xcodeproj/project.pbxproj +++ b/BDKSwiftExampleWallet.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 56; + objectVersion = 60; objects = { /* Begin PBXBuildFile section */ @@ -66,6 +66,7 @@ AE91CEED2C0FDB70000AAD20 /* SentAndReceivedValues+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE91CEEC2C0FDB70000AAD20 /* SentAndReceivedValues+Extensions.swift */; }; AE91CEEF2C0FDBC7000AAD20 /* CanonicalTx+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE91CEEE2C0FDBC7000AAD20 /* CanonicalTx+Extensions.swift */; }; AE96F6622A424C400055623C /* BDKSwiftExampleWalletReceiveViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE96F6612A424C400055623C /* BDKSwiftExampleWalletReceiveViewModelTests.swift */; }; + AEA1F6432CE43702004EC538 /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = AEA1F6422CE43702004EC538 /* BitcoinDevKit */; }; AEAB03112ABDDB86000C9528 /* FeeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEAB03102ABDDB86000C9528 /* FeeViewModel.swift */; }; AEAB03132ABDDBF4000C9528 /* AmountViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEAB03122ABDDBF4000C9528 /* AmountViewModel.swift */; }; AEAF83B62B7BD4D10019B23B /* CodeScanner in Frameworks */ = {isa = PBXBuildFile; productRef = AEAF83B52B7BD4D10019B23B /* CodeScanner */; }; @@ -74,7 +75,6 @@ AEB735D32B2CC4B900F99DBB /* BitcoinUI in Frameworks */ = {isa = PBXBuildFile; productRef = AEB735D22B2CC4B900F99DBB /* BitcoinUI */; }; AEB905C32A7EEBF000CD0337 /* BackupInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEB905C22A7EEBF000CD0337 /* BackupInfo.swift */; }; AEC2CF5A2ABFBA19008065E4 /* BuildTransactionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC2CF592ABFBA19008065E4 /* BuildTransactionViewModel.swift */; }; - AED02B912C9D0B44006DAAAF /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = AED02B902C9D0B44006DAAAF /* BitcoinDevKit */; }; AED062712A9BB1D6001DC6BD /* BDKSwiftExampleWalletFeeServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED062702A9BB1D6001DC6BD /* BDKSwiftExampleWalletFeeServiceTests.swift */; }; AED062732A9BD698001DC6BD /* BDKSwiftExampleWalletKeyServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED062722A9BD698001DC6BD /* BDKSwiftExampleWalletKeyServiceTests.swift */; }; AED062752A9BD7FA001DC6BD /* BDKSwiftExampleWalletBDKServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED062742A9BD7FA001DC6BD /* BDKSwiftExampleWalletBDKServiceTests.swift */; }; @@ -186,7 +186,7 @@ AE187D782C9BB3B50081D0C3 /* BitcoinDevKit in Frameworks */, AE29ED0F2BBE2E7100EB9C4F /* BitcoinDevKit in Frameworks */, AEAF83B62B7BD4D10019B23B /* CodeScanner in Frameworks */, - AED02B912C9D0B44006DAAAF /* BitcoinDevKit in Frameworks */, + AEA1F6432CE43702004EC538 /* BitcoinDevKit in Frameworks */, AEB735D32B2CC4B900F99DBB /* BitcoinUI in Frameworks */, AEE83A492C07F54B00834468 /* BitcoinDevKit in Frameworks */, AE7D5A0E2A7EE62200EAC8CE /* KeychainAccess in Frameworks */, @@ -540,7 +540,7 @@ AE29ED0E2BBE2E7100EB9C4F /* BitcoinDevKit */, AEE83A482C07F54B00834468 /* BitcoinDevKit */, AE187D772C9BB3B50081D0C3 /* BitcoinDevKit */, - AED02B902C9D0B44006DAAAF /* BitcoinDevKit */, + AEA1F6422CE43702004EC538 /* BitcoinDevKit */, ); productName = BDKSwiftExampleWallet; productReference = AE4984782A1BBBD6009951E2 /* BDKSwiftExampleWallet.app */; @@ -597,7 +597,7 @@ AE7D5A0C2A7EE62200EAC8CE /* XCRemoteSwiftPackageReference "KeychainAccess" */, AEB735D12B2CC4B900F99DBB /* XCRemoteSwiftPackageReference "BitcoinUI" */, AEAF83B42B7BD4D10019B23B /* XCRemoteSwiftPackageReference "CodeScanner" */, - AED02B8F2C9D0B44006DAAAF /* XCRemoteSwiftPackageReference "bdk-swift" */, + AEA1F6412CE43702004EC538 /* XCLocalSwiftPackageReference "../bdk-ffi/bdk-swift" */, ); productRefGroup = AE4984792A1BBBD6009951E2 /* Products */; projectDirPath = ""; @@ -987,6 +987,13 @@ }; /* End XCConfigurationList section */ +/* Begin XCLocalSwiftPackageReference section */ + AEA1F6412CE43702004EC538 /* XCLocalSwiftPackageReference "../bdk-ffi/bdk-swift" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = "../bdk-ffi/bdk-swift"; + }; +/* End XCLocalSwiftPackageReference section */ + /* Begin XCRemoteSwiftPackageReference section */ AE7D5A0C2A7EE62200EAC8CE /* XCRemoteSwiftPackageReference "KeychainAccess" */ = { isa = XCRemoteSwiftPackageReference; @@ -1012,14 +1019,6 @@ kind = branch; }; }; - AED02B8F2C9D0B44006DAAAF /* XCRemoteSwiftPackageReference "bdk-swift" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/bitcoindevkit/bdk-swift.git"; - requirement = { - kind = exactVersion; - version = "1.0.0-beta.5"; - }; - }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -1036,6 +1035,10 @@ package = AE7D5A0C2A7EE62200EAC8CE /* XCRemoteSwiftPackageReference "KeychainAccess" */; productName = KeychainAccess; }; + AEA1F6422CE43702004EC538 /* BitcoinDevKit */ = { + isa = XCSwiftPackageProductDependency; + productName = BitcoinDevKit; + }; AEAF83B52B7BD4D10019B23B /* CodeScanner */ = { isa = XCSwiftPackageProductDependency; package = AEAF83B42B7BD4D10019B23B /* XCRemoteSwiftPackageReference "CodeScanner" */; @@ -1046,11 +1049,6 @@ package = AEB735D12B2CC4B900F99DBB /* XCRemoteSwiftPackageReference "BitcoinUI" */; productName = BitcoinUI; }; - AED02B902C9D0B44006DAAAF /* BitcoinDevKit */ = { - isa = XCSwiftPackageProductDependency; - package = AED02B8F2C9D0B44006DAAAF /* XCRemoteSwiftPackageReference "bdk-swift" */; - productName = BitcoinDevKit; - }; AEE83A482C07F54B00834468 /* BitcoinDevKit */ = { isa = XCSwiftPackageProductDependency; productName = BitcoinDevKit; diff --git a/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift b/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift index a32d5b3..a31a2a8 100644 --- a/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift +++ b/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift @@ -164,11 +164,35 @@ private class BDKService { throw WalletError.walletNotFound } - let cleanDescriptor = - descriptorString.split(separator: "#").first.map(String.init) ?? descriptorString - let descriptor = try Descriptor(descriptor: cleanDescriptor, network: network) - let changeDescriptorString = cleanDescriptor.replacingOccurrences(of: "/0/*", with: "/1/*") - let changeDescriptor = try Descriptor(descriptor: changeDescriptorString, network: network) + let descriptor: Descriptor + let changeDescriptor: Descriptor + + let cleanDescriptorString = descriptorString.components(separatedBy: "\n") + .map { $0.split(separator: "#").first?.trimmingCharacters(in: .whitespaces) ?? "" } + .filter { !$0.isEmpty } + .joined(separator: "\n") + + if let firstDescriptor = try? Descriptor( + descriptor: cleanDescriptorString.components(separatedBy: "\n")[0], + network: network + ), + firstDescriptor.isMultipath() + { + let baseDescriptor = cleanDescriptorString.components(separatedBy: "\n")[0] + descriptor = try Descriptor( + descriptor: baseDescriptor.replacingOccurrences(of: "<0;1>", with: "0"), + network: network + ) + changeDescriptor = try Descriptor( + descriptor: baseDescriptor.replacingOccurrences(of: "<0;1>", with: "1"), + network: network + ) + } else { + let descriptors = cleanDescriptorString.components(separatedBy: "\n") + guard descriptors.count == 2 else { throw WalletError.walletNotFound } + descriptor = try Descriptor(descriptor: descriptors[0], network: network) + changeDescriptor = try Descriptor(descriptor: descriptors[1], network: network) + } let backupInfo = BackupInfo( mnemonic: "", @@ -211,10 +235,20 @@ private class BDKService { throw WalletError.walletNotFound } - let descriptorString = "tr(\(xpubString)/0/*)" - let changeDescriptorString = "tr(\(xpubString)/1/*)" - let descriptor = try Descriptor(descriptor: descriptorString, network: network) - let changeDescriptor = try Descriptor(descriptor: changeDescriptorString, network: network) + let descriptorPublicKey = try DescriptorPublicKey.fromString(publicKey: xpubString) + let fingerprint = descriptorPublicKey.masterFingerprint() + let descriptor = Descriptor.newBip86Public( + publicKey: descriptorPublicKey, + fingerprint: fingerprint, + keychain: .external, + network: network + ) + let changeDescriptor = Descriptor.newBip86Public( + publicKey: descriptorPublicKey, + fingerprint: fingerprint, + keychain: .internal, + network: network + ) let backupInfo = BackupInfo( mnemonic: "",