Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Update password may does not work #72

Open
zhaojiewen opened this issue Oct 31, 2018 · 0 comments
Open

Update password may does not work #72

zhaojiewen opened this issue Oct 31, 2018 · 0 comments

Comments

@zhaojiewen
Copy link

In KeyStore.swift:
''public func update(wallet: Wallet, password: String, newPassword: String)''
I does not see rewritting KeystoreKey to local file, so I add this code to the method

public func update(wallet: Wallet, password: String, newPassword: String) throws {
guard let index = wallets.index(of: wallet) else {
fatalError("Missing wallet")
}

    var privateKeyData = try wallet.key.decrypt(password: password)
    defer {
        privateKeyData.resetBytes(in: 0 ..< privateKeyData.count)
    }

    switch wallet.key.type {
    case .encryptedKey:
        guard let privateKey = PrivateKey(data: privateKeyData) else {
            throw Error.invalidKey
        }
        wallets[index].key = try KeystoreKey(password: newPassword, key: privateKey, coin: wallet.key.coin)
    case .hierarchicalDeterministicWallet:
        guard let string = String(data: privateKeyData, encoding: .ascii) else {
            throw EncryptError.invalidMnemonic
        }
        wallets[index].key = try KeystoreKey(password: newPassword, mnemonic: string, passphrase: wallet.key.passphrase)
    }
    // fix bugs: write to local key file
    // @author xuhaiqing
    try save(key: wallets[index].key, to: keyDirectory)
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant