Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions BDKSwiftExampleWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@
AF77B2242F4B2C9E00000004 /* XCRemoteSwiftPackageReference "KeychainAccess" */,
AF77B2232F4B2C9E00000003 /* XCRemoteSwiftPackageReference "BitcoinUI" */,
AF77B2222F4B2C9E00000002 /* XCRemoteSwiftPackageReference "CodeScanner" */,
AF77B2212F4B2C9E00000001 /* XCRemoteSwiftPackageReference "bdk-swift" */,
AF77B2212F4B2C9E00000001 /* XCLocalSwiftPackageReference "bdk-swift" */,
);
productRefGroup = AE4984792A1BBBD6009951E2 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -1069,15 +1069,14 @@
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
AF77B2212F4B2C9E00000001 /* XCRemoteSwiftPackageReference "bdk-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/bitcoindevkit/bdk-swift";
requirement = {
kind = exactVersion;
version = 2.3.1;
};
/* Begin XCLocalSwiftPackageReference section */
AF77B2212F4B2C9E00000001 /* XCLocalSwiftPackageReference "bdk-swift" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = "../bdk-ffi-release-3.0/bdk-swift";
};
/* End XCLocalSwiftPackageReference section */

/* Begin XCRemoteSwiftPackageReference section */
AF77B2222F4B2C9E00000002 /* XCRemoteSwiftPackageReference "CodeScanner" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/twostraws/CodeScanner.git";
Expand Down Expand Up @@ -1107,7 +1106,7 @@
/* Begin XCSwiftPackageProductDependency section */
AF77B2142F4B2C9E00000001 /* BitcoinDevKit */ = {
isa = XCSwiftPackageProductDependency;
package = AF77B2212F4B2C9E00000001 /* XCRemoteSwiftPackageReference "bdk-swift" */;
package = AF77B2212F4B2C9E00000001 /* XCLocalSwiftPackageReference "bdk-swift" */;
productName = BitcoinDevKit;
};
AF77B2152F4B2C9E00000002 /* CodeScanner */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import BitcoinDevKit
import Foundation

extension Network {
var kind: NetworkKind {
switch self {
case .bitcoin: return .main
case .testnet, .testnet4, .signet, .regtest: return .test
}
}

var description: String {
switch self {
case .bitcoin: return "bitcoin"
Expand Down
38 changes: 23 additions & 15 deletions BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,30 @@ final class BDKService {
secretKey: DescriptorSecretKey,
network: Network
) -> (descriptor: Descriptor, changeDescriptor: Descriptor) {
let networkKind = network.kind
switch addressType {
case .bip86:
let descriptor = Descriptor.newBip86(
secretKey: secretKey,
keychainKind: .external,
network: network
networkKind: networkKind
)
let changeDescriptor = Descriptor.newBip86(
secretKey: secretKey,
keychainKind: .internal,
network: network
networkKind: networkKind
)
return (descriptor, changeDescriptor)
case .bip84:
let descriptor = Descriptor.newBip84(
secretKey: secretKey,
keychainKind: .external,
network: network
networkKind: networkKind
)
let changeDescriptor = Descriptor.newBip84(
secretKey: secretKey,
keychainKind: .internal,
network: network
networkKind: networkKind
)
return (descriptor, changeDescriptor)
}
Expand All @@ -233,33 +234,34 @@ final class BDKService {
fingerprint: String,
network: Network
) throws -> (descriptor: Descriptor, changeDescriptor: Descriptor) {
let networkKind = network.kind
switch addressType {
case .bip86:
let descriptor = try Descriptor.newBip86Public(
publicKey: publicKey,
fingerprint: fingerprint,
keychainKind: .external,
network: network
networkKind: networkKind
)
let changeDescriptor = try Descriptor.newBip86Public(
publicKey: publicKey,
fingerprint: fingerprint,
keychainKind: .internal,
network: network
networkKind: networkKind
)
return (descriptor, changeDescriptor)
case .bip84:
let descriptor = try Descriptor.newBip84Public(
publicKey: publicKey,
fingerprint: fingerprint,
keychainKind: .external,
network: network
networkKind: networkKind
)
let changeDescriptor = try Descriptor.newBip84Public(
publicKey: publicKey,
fingerprint: fingerprint,
keychainKind: .internal,
network: network
networkKind: networkKind
)
return (descriptor, changeDescriptor)
}
Expand Down Expand Up @@ -327,7 +329,7 @@ final class BDKService {
}
let mnemonic = try Mnemonic.fromString(mnemonic: words12)
let secretKey = DescriptorSecretKey(
network: network,
networkKind: network.kind,
mnemonic: mnemonic,
password: nil
)
Expand Down Expand Up @@ -381,7 +383,7 @@ final class BDKService {
if descriptorStrings.count == 1 {
let parsedDescriptor = try Descriptor(
descriptor: descriptorStrings[0],
network: network
networkKind: network.kind
)
let singleDescriptors = try parsedDescriptor.toSingleDescriptors()
guard singleDescriptors.count >= 2 else {
Expand All @@ -390,8 +392,11 @@ final class BDKService {
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)
descriptor = try Descriptor(descriptor: descriptorStrings[0], networkKind: network.kind)
changeDescriptor = try Descriptor(
descriptor: descriptorStrings[1],
networkKind: network.kind
)
} else {
throw WalletError.walletNotFound
}
Expand Down Expand Up @@ -515,10 +520,13 @@ final class BDKService {

func loadWalletFromBackup() throws {
let backupInfo = try keyClient.getBackupInfo()
let descriptor = try Descriptor(descriptor: backupInfo.descriptor, network: self.network)
let descriptor = try Descriptor(
descriptor: backupInfo.descriptor,
networkKind: self.network.kind
)
let changeDescriptor = try Descriptor(
descriptor: backupInfo.changeDescriptor,
network: self.network
networkKind: self.network.kind
)
try self.loadWallet(descriptor: descriptor, changeDescriptor: changeDescriptor)
}
Expand Down Expand Up @@ -578,7 +586,7 @@ final class BDKService {
guard
let descriptor = try? Descriptor(
descriptor: descriptorString,
network: self.network
networkKind: self.network.kind
)
else {
continue
Expand Down
6 changes: 3 additions & 3 deletions BDKSwiftExampleWallet/Service/Key Service/KeyService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ extension KeyClient {
"space echo position wrist orient erupt relief museum myself grain wisdom tumble"
let mnemonic = try Mnemonic.fromString(mnemonic: words12)
let secretKey = DescriptorSecretKey(
network: mockKeyClientNetwork,
networkKind: mockKeyClientNetwork.kind,
mnemonic: mnemonic,
password: nil
)
let descriptor = Descriptor.newBip86(
secretKey: secretKey,
keychainKind: .external,
network: mockKeyClientNetwork
networkKind: mockKeyClientNetwork.kind
)
let changeDescriptor = Descriptor.newBip86(
secretKey: secretKey,
keychainKind: .internal,
network: mockKeyClientNetwork
networkKind: mockKeyClientNetwork.kind
)
let backupInfo = BackupInfo(
mnemonic: mnemonic.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ class WalletRecoveryViewModel {

let externalPublicDescriptor = try Descriptor.init(
descriptor: backupInfo.descriptor,
network: network
networkKind: network.kind
)
self.publicDescriptor = externalPublicDescriptor

let internalPublicDescriptor = try Descriptor.init(
descriptor: backupInfo.changeDescriptor,
network: network
networkKind: network.kind
)
self.publicChangeDescriptor = internalPublicDescriptor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ final class BDKSwiftExampleWalletKeyServiceTests: XCTestCase {
"space echo position wrist orient erupt relief museum myself grain wisdom tumble"
let mnemonic = try Mnemonic.fromString(mnemonic: words12)
let secretKey = DescriptorSecretKey(
network: mockKeyClientNetwork,
networkKind: mockKeyClientNetwork.kind,
mnemonic: mnemonic,
password: nil
)
let descriptor = Descriptor.newBip86(
secretKey: secretKey,
keychainKind: .external,
network: mockKeyClientNetwork
networkKind: mockKeyClientNetwork.kind
)
let changeDescriptor = Descriptor.newBip86(
secretKey: secretKey,
keychainKind: .internal,
network: mockKeyClientNetwork
networkKind: mockKeyClientNetwork.kind
)
let backupInfoMock = BackupInfo(
mnemonic: mnemonic.description,
Expand Down
Loading