Skip to content

Commit 2d08f6e

Browse files
authored
feat: isMultipath and fingerprint
1 parent 6405e97 commit 2d08f6e

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

BDKSwiftExampleWallet.xcodeproj/project.pbxproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
AE91CEED2C0FDB70000AAD20 /* SentAndReceivedValues+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE91CEEC2C0FDB70000AAD20 /* SentAndReceivedValues+Extensions.swift */; };
7070
AE91CEEF2C0FDBC7000AAD20 /* CanonicalTx+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE91CEEE2C0FDBC7000AAD20 /* CanonicalTx+Extensions.swift */; };
7171
AE96F6622A424C400055623C /* BDKSwiftExampleWalletReceiveViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE96F6612A424C400055623C /* BDKSwiftExampleWalletReceiveViewModelTests.swift */; };
72+
AEA1F6432CE43702004EC538 /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = AEA1F6422CE43702004EC538 /* BitcoinDevKit */; };
7273
AEAB03112ABDDB86000C9528 /* FeeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEAB03102ABDDB86000C9528 /* FeeViewModel.swift */; };
7374
AEAB03132ABDDBF4000C9528 /* AmountViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEAB03122ABDDBF4000C9528 /* AmountViewModel.swift */; };
7475
AEAF83B62B7BD4D10019B23B /* CodeScanner in Frameworks */ = {isa = PBXBuildFile; productRef = AEAF83B52B7BD4D10019B23B /* CodeScanner */; };
@@ -89,6 +90,7 @@
8990
AEE6C74C2ABCB3E200442ADD /* Transaction+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6C74B2ABCB3E200442ADD /* Transaction+Extensions.swift */; };
9091
AEE6C74F2ABCBA4600442ADD /* WalletSyncState.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6C74E2ABCBA4600442ADD /* WalletSyncState.swift */; };
9192
AEE83A492C07F54B00834468 /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = AEE83A482C07F54B00834468 /* BitcoinDevKit */; };
93+
AEEA24572D136898000C1694 /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = AEEA24562D136898000C1694 /* BitcoinDevKit */; };
9294
/* End PBXBuildFile section */
9395

9496
/* Begin PBXContainerItemProxy section */
@@ -1032,6 +1034,14 @@
10321034
kind = branch;
10331035
};
10341036
};
1037+
AEEA24552D136898000C1694 /* XCRemoteSwiftPackageReference "bdk-swift" */ = {
1038+
isa = XCRemoteSwiftPackageReference;
1039+
repositoryURL = "https://github.com/bitcoindevkit/bdk-swift.git";
1040+
requirement = {
1041+
kind = exactVersion;
1042+
version = "1.0.0-beta.6";
1043+
};
1044+
};
10351045
/* End XCRemoteSwiftPackageReference section */
10361046

10371047
/* Begin XCSwiftPackageProductDependency section */
@@ -1061,6 +1071,10 @@
10611071
package = AE7D5A0C2A7EE62200EAC8CE /* XCRemoteSwiftPackageReference "KeychainAccess" */;
10621072
productName = KeychainAccess;
10631073
};
1074+
AEA1F6422CE43702004EC538 /* BitcoinDevKit */ = {
1075+
isa = XCSwiftPackageProductDependency;
1076+
productName = BitcoinDevKit;
1077+
};
10641078
AEAF83B52B7BD4D10019B23B /* CodeScanner */ = {
10651079
isa = XCSwiftPackageProductDependency;
10661080
package = AEAF83B42B7BD4D10019B23B /* XCRemoteSwiftPackageReference "CodeScanner" */;
@@ -1075,6 +1089,11 @@
10751089
isa = XCSwiftPackageProductDependency;
10761090
productName = BitcoinDevKit;
10771091
};
1092+
AEEA24562D136898000C1694 /* BitcoinDevKit */ = {
1093+
isa = XCSwiftPackageProductDependency;
1094+
package = AEEA24552D136898000C1694 /* XCRemoteSwiftPackageReference "bdk-swift" */;
1095+
productName = BitcoinDevKit;
1096+
};
10781097
/* End XCSwiftPackageProductDependency section */
10791098
};
10801099
rootObject = AE4984702A1BBBD6009951E2 /* Project object */;

BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,28 @@ private class BDKService {
164164
throw WalletError.walletNotFound
165165
}
166166

167-
let cleanDescriptor =
168-
descriptorString.split(separator: "#").first.map(String.init) ?? descriptorString
169-
let descriptor = try Descriptor(descriptor: cleanDescriptor, network: network)
170-
let changeDescriptorString = cleanDescriptor.replacingOccurrences(of: "/0/*", with: "/1/*")
171-
let changeDescriptor = try Descriptor(descriptor: changeDescriptorString, network: network)
167+
let descriptorStrings = descriptorString.components(separatedBy: "\n")
168+
.map { $0.split(separator: "#").first?.trimmingCharacters(in: .whitespaces) ?? "" }
169+
.filter { !$0.isEmpty }
170+
let descriptor: Descriptor
171+
let changeDescriptor: Descriptor
172+
if descriptorStrings.count == 1 {
173+
let parsedDescriptor = try Descriptor(
174+
descriptor: descriptorStrings[0],
175+
network: network
176+
)
177+
let singleDescriptors = try parsedDescriptor.toSingleDescriptors()
178+
guard singleDescriptors.count >= 2 else {
179+
throw WalletError.walletNotFound
180+
}
181+
descriptor = singleDescriptors[0]
182+
changeDescriptor = singleDescriptors[1]
183+
} else if descriptorStrings.count == 2 {
184+
descriptor = try Descriptor(descriptor: descriptorStrings[0], network: network)
185+
changeDescriptor = try Descriptor(descriptor: descriptorStrings[1], network: network)
186+
} else {
187+
throw WalletError.walletNotFound
188+
}
172189

173190
let backupInfo = BackupInfo(
174191
mnemonic: "",
@@ -211,10 +228,20 @@ private class BDKService {
211228
throw WalletError.walletNotFound
212229
}
213230

214-
let descriptorString = "tr(\(xpubString)/0/*)"
215-
let changeDescriptorString = "tr(\(xpubString)/1/*)"
216-
let descriptor = try Descriptor(descriptor: descriptorString, network: network)
217-
let changeDescriptor = try Descriptor(descriptor: changeDescriptorString, network: network)
231+
let descriptorPublicKey = try DescriptorPublicKey.fromString(publicKey: xpubString)
232+
let fingerprint = descriptorPublicKey.masterFingerprint()
233+
let descriptor = Descriptor.newBip86Public(
234+
publicKey: descriptorPublicKey,
235+
fingerprint: fingerprint,
236+
keychain: .external,
237+
network: network
238+
)
239+
let changeDescriptor = Descriptor.newBip86Public(
240+
publicKey: descriptorPublicKey,
241+
fingerprint: fingerprint,
242+
keychain: .internal,
243+
network: network
244+
)
218245

219246
let backupInfo = BackupInfo(
220247
mnemonic: "",

0 commit comments

Comments
 (0)