Skip to content

Commit

Permalink
- remove commented out code, as test successful
Browse files Browse the repository at this point in the history
- more appropriate naming for Regular wallet init function
  • Loading branch information
simonmcl committed Nov 13, 2023
1 parent d622d50 commit 08bda80
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 29 deletions.
17 changes: 7 additions & 10 deletions Sources/KukaiCoreSwift/Models/RegularWallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/KukaiCoreSwift/Models/TorusWallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


Expand Down
9 changes: 1 addition & 8 deletions Tests/KukaiCoreSwiftTests/Models/RegularWalletTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 0 additions & 10 deletions Tests/KukaiCoreSwiftTests/Services/WalletCacheServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 08bda80

Please sign in to comment.