@@ -164,11 +164,28 @@ private class BDKService {
164
164
throw WalletError . walletNotFound
165
165
}
166
166
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
+ }
172
189
173
190
let backupInfo = BackupInfo (
174
191
mnemonic: " " ,
@@ -211,10 +228,20 @@ private class BDKService {
211
228
throw WalletError . walletNotFound
212
229
}
213
230
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
+ )
218
245
219
246
let backupInfo = BackupInfo (
220
247
mnemonic: " " ,
0 commit comments