From bca81ae539f4c083980fed8360349ae4e812fe32 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 13 Nov 2024 12:51:52 -0600 Subject: [PATCH 1/3] feat: isMultipath and fingerprint --- .../project.pbxproj | 14 ++++- .../Service/BDK Service/BDKService.swift | 52 +++++++++++++++---- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/BDKSwiftExampleWallet.xcodeproj/project.pbxproj b/BDKSwiftExampleWallet.xcodeproj/project.pbxproj index baf80dec..3954772e 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 */ @@ -69,6 +69,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 */; }; @@ -999,6 +1000,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 */ AE52D68D2D1367C80042119D /* XCRemoteSwiftPackageReference "bdk-swift" */ = { isa = XCRemoteSwiftPackageReference; @@ -1061,6 +1069,10 @@ package = AE7D5A0C2A7EE62200EAC8CE /* XCRemoteSwiftPackageReference "KeychainAccess" */; productName = KeychainAccess; }; + AEA1F6422CE43702004EC538 /* BitcoinDevKit */ = { + isa = XCSwiftPackageProductDependency; + productName = BitcoinDevKit; + }; AEAF83B52B7BD4D10019B23B /* CodeScanner */ = { isa = XCSwiftPackageProductDependency; package = AEAF83B42B7BD4D10019B23B /* XCRemoteSwiftPackageReference "CodeScanner" */; diff --git a/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift b/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift index a32d5b37..a31a2a8e 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: "", From 59941918d087ed86e5a151309a53880168fc74ce Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 14 Nov 2024 14:31:13 -0600 Subject: [PATCH 2/3] use into_single_descriptor --- .../Service/BDK Service/BDKService.swift | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift b/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift index a31a2a8e..0cd0fdb9 100644 --- a/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift +++ b/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift @@ -164,34 +164,27 @@ private class BDKService { throw WalletError.walletNotFound } - let descriptor: Descriptor - let changeDescriptor: Descriptor - - let cleanDescriptorString = descriptorString.components(separatedBy: "\n") + let descriptorStrings = 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"), + let descriptor: Descriptor + let changeDescriptor: Descriptor + if descriptorStrings.count == 1 { + let parsedDescriptor = try Descriptor( + descriptor: descriptorStrings[0], network: network ) + let singleDescriptors = try parsedDescriptor.toSingleDescriptors() + guard singleDescriptors.count >= 2 else { + throw WalletError.walletNotFound + } + descriptor = singleDescriptors[0] + changeDescriptor = singleDescriptors[1] + } else if descriptorStrings.count == 2 { + descriptor = try Descriptor(descriptor: descriptorStrings[0], network: network) + changeDescriptor = try Descriptor(descriptor: descriptorStrings[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) + throw WalletError.walletNotFound } let backupInfo = BackupInfo( From 7aaa21003a3f5abc1f4ba8d00656414d239488db Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 18 Dec 2024 14:33:43 -0600 Subject: [PATCH 3/3] spm: remote 1.0.0-beta.6 --- .../project.pbxproj | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/BDKSwiftExampleWallet.xcodeproj/project.pbxproj b/BDKSwiftExampleWallet.xcodeproj/project.pbxproj index 3954772e..c67ca016 100644 --- a/BDKSwiftExampleWallet.xcodeproj/project.pbxproj +++ b/BDKSwiftExampleWallet.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 60; + objectVersion = 56; objects = { /* Begin PBXBuildFile section */ @@ -90,6 +90,7 @@ AEE6C74C2ABCB3E200442ADD /* Transaction+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6C74B2ABCB3E200442ADD /* Transaction+Extensions.swift */; }; AEE6C74F2ABCBA4600442ADD /* WalletSyncState.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6C74E2ABCBA4600442ADD /* WalletSyncState.swift */; }; AEE83A492C07F54B00834468 /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = AEE83A482C07F54B00834468 /* BitcoinDevKit */; }; + AEEA24572D136898000C1694 /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = AEEA24562D136898000C1694 /* BitcoinDevKit */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -1000,13 +1001,6 @@ }; /* 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 */ AE52D68D2D1367C80042119D /* XCRemoteSwiftPackageReference "bdk-swift" */ = { isa = XCRemoteSwiftPackageReference; @@ -1040,6 +1034,14 @@ kind = branch; }; }; + AEEA24552D136898000C1694 /* XCRemoteSwiftPackageReference "bdk-swift" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/bitcoindevkit/bdk-swift.git"; + requirement = { + kind = exactVersion; + version = "1.0.0-beta.6"; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -1087,6 +1089,11 @@ isa = XCSwiftPackageProductDependency; productName = BitcoinDevKit; }; + AEEA24562D136898000C1694 /* BitcoinDevKit */ = { + isa = XCSwiftPackageProductDependency; + package = AEEA24552D136898000C1694 /* XCRemoteSwiftPackageReference "bdk-swift" */; + productName = BitcoinDevKit; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = AE4984702A1BBBD6009951E2 /* Project object */;