diff --git a/Sources/KukaiCoreSwift/Models/RegularWallet.swift b/Sources/KukaiCoreSwift/Models/RegularWallet.swift index 7ad0ce49..572390b7 100644 --- a/Sources/KukaiCoreSwift/Models/RegularWallet.swift +++ b/Sources/KukaiCoreSwift/Models/RegularWallet.swift @@ -41,12 +41,11 @@ public class RegularWallet: Wallet { /** Attempt to create an instance of a `RegularWallet` from an encoded string containing a private key - - parameter withBase58String: String containing the Base58 encoded private key, prefixed with the curve's secret - - parameter ellipticalCurve: The ellipcatical curve used to create the key + - parameter secp256k1WithBase58String: String containing the Base58 encoded private key, prefixed with the curve's secret - parameter type: WalletType indicating the top most type of wallet */ - public init?(withBase58String: String, ellipticalCurve: EllipticalCurve, type: WalletType) { - guard let privateKey = PrivateKey(withBase58String, signingCurve: ellipticalCurve), + public init?(secp256k1WithBase58String base58String: String, type: WalletType) { + guard let privateKey = PrivateKey(base58String, signingCurve: .secp256k1), let pubKey = KeyPair.secp256k1PublicKey(fromPrivateKeyBytes: privateKey.bytes), let tempAddress = pubKey.publicKeyHash else { os_log("Failed to construct private/public key", log: .kukaiCoreSwift, type: .error) @@ -64,10 +63,9 @@ public class RegularWallet: Wallet { Create a `RegularWallet` by supplying a `Mnemonic` and a passphrase (or "" if none). - Parameter withMnemonic: A `Mnemonic` representing a BIP39 menmonic - Parameter passphrase: String contianing a passphrase, or empty string if none - - Parameter ellipticalCurve: Optional: Choose the `EllipticalCurve` used to generate the wallet address */ - public init?(withMnemonic mnemonic: Mnemonic, passphrase: String/*, ellipticalCurve: EllipticalCurve = .ed25519*/) { - guard let keyPair = KeyPair.regular(fromMnemonic: mnemonic, passphrase: passphrase/*, andSigningCurve: ellipticalCurve*/), let pkh = keyPair.publicKey.publicKeyHash else { + public init?(withMnemonic mnemonic: Mnemonic, passphrase: String) { + guard let keyPair = KeyPair.regular(fromMnemonic: mnemonic, passphrase: passphrase), let pkh = keyPair.publicKey.publicKeyHash else { return nil } @@ -82,11 +80,10 @@ public class RegularWallet: Wallet { Create a `RegularWallet` by asking for a mnemonic of a given number of words and a passphrase (or "" if none). - Parameter withMnemonicLength: `Mnemonic.NumberOfWords` the number of words to use when creating a mnemonic - Parameter passphrase: String contianing a passphrase, or empty string if none - - Parameter ellipticalCurve: Optional: Choose the `EllipticalCurve` used to generate the wallet address */ - public convenience init?(withMnemonicLength length: Mnemonic.NumberOfWords, passphrase: String/*, ellipticalCurve: EllipticalCurve = .ed25519*/) { + public convenience init?(withMnemonicLength length: Mnemonic.NumberOfWords, passphrase: String) { if let mnemonic = try? Mnemonic(numberOfWords: length) { - self.init(withMnemonic: mnemonic, passphrase: passphrase/*, ellipticalCurve: ellipticalCurve*/) + self.init(withMnemonic: mnemonic, passphrase: passphrase) } else { return nil diff --git a/Sources/KukaiCoreSwift/Models/TorusWallet.swift b/Sources/KukaiCoreSwift/Models/TorusWallet.swift index c26bd6e3..4dece7c5 100644 --- a/Sources/KukaiCoreSwift/Models/TorusWallet.swift +++ b/Sources/KukaiCoreSwift/Models/TorusWallet.swift @@ -59,7 +59,7 @@ public class TorusWallet: RegularWallet { self.socialUserId = userId self.socialProfilePictureURL = URL(string: profilePicture ?? "") - super.init(withBase58String: base58encode, ellipticalCurve: .secp256k1, type: .social) + super.init(secp256k1WithBase58String: base58encode, type: .social) } diff --git a/Tests/KukaiCoreSwiftTests/Models/RegularWalletTests.swift b/Tests/KukaiCoreSwiftTests/Models/RegularWalletTests.swift index 483e0f84..8d7bd61f 100644 --- a/Tests/KukaiCoreSwiftTests/Models/RegularWalletTests.swift +++ b/Tests/KukaiCoreSwiftTests/Models/RegularWalletTests.swift @@ -45,17 +45,10 @@ class RegularWalletTests: XCTestCase { } func testCurves() { - let wallet1 = RegularWallet(withMnemonic: MockConstants.mnemonic, passphrase: ""/*, ellipticalCurve: .ed25519*/) + let wallet1 = RegularWallet(withMnemonic: MockConstants.mnemonic, passphrase: "") XCTAssert(wallet1?.address == MockConstants.linearWalletEd255519.address, wallet1?.address ?? "-") XCTAssert(wallet1?.privateKey.bytes.toHexString() == MockConstants.linearWalletEd255519.privateKey, wallet1?.privateKey.bytes.toHexString() ?? "-") XCTAssert(wallet1?.publicKey.bytes.toHexString() == MockConstants.linearWalletEd255519.publicKey, wallet1?.publicKey.bytes.toHexString() ?? "-") - - /* - let wallet2 = RegularWallet(withMnemonic: MockConstants.mnemonic, passphrase: "", ellipticalCurve: .secp256k1) - XCTAssert(wallet2?.address == MockConstants.linearWalletSecp256k1.address, wallet2?.address ?? "-") - XCTAssert(wallet2?.privateKey.bytes.toHexString() == MockConstants.linearWalletSecp256k1.privateKey, wallet2?.privateKey.bytes.toHexString() ?? "-") - XCTAssert(wallet2?.publicKey.bytes.toHexString() == MockConstants.linearWalletSecp256k1.publicKey, wallet2?.publicKey.bytes.toHexString() ?? "-") - */ } func testSigning() { diff --git a/Tests/KukaiCoreSwiftTests/Services/WalletCacheServiceTests.swift b/Tests/KukaiCoreSwiftTests/Services/WalletCacheServiceTests.swift index 0516afd6..611b9a60 100644 --- a/Tests/KukaiCoreSwiftTests/Services/WalletCacheServiceTests.swift +++ b/Tests/KukaiCoreSwiftTests/Services/WalletCacheServiceTests.swift @@ -129,16 +129,6 @@ class WalletCacheServiceTests: XCTestCase { XCTAssert(walletCacheService.deleteAllCacheAndKeys()) } - func testCurves() { - /*let wallet = RegularWallet(withMnemonic: MockConstants.mnemonic, passphrase: "", ellipticalCurve: .secp256k1)! - XCTAssert(walletCacheService.cache(wallet: wallet, childOfIndex: nil, backedUp: false)) - - let wallet1 = walletCacheService.fetchWallet(forAddress: wallet.address) - XCTAssert(wallet1 != nil) - XCTAssert(wallet1?.address == MockConstants.linearWalletSecp256k1.address, wallet1?.address ?? "-") - XCTAssert(walletCacheService.deleteAllCacheAndKeys())*/ - } - func testDerivationPaths() { let wallet = HDWallet(withMnemonic: MockConstants.mnemonic, passphrase: MockConstants.passphrase, derivationPath: MockConstants.hdWallet_hardened_change.derivationPath)! XCTAssert(walletCacheService.cache(wallet: wallet, childOfIndex: nil, backedUp: false))