The Dawn Wallet Key Management repo provides a new SDK that allows you to manage, create, encrypt wallets and sign transactions on Ethereum. This package leverages the Secure Enclave to keep your keys protected, by using a secret in the Secure Enclave to encrypt a user private key.
To integrate this package into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:
dependencies: [
.package(url: "https://github.com/dawnwallet/dawn-key-management", branch: "main")
]
EthereumWallet
object is used to describe a standard wallet.
Create a new instance by injecting the EthereumPrivateKey
.
let privateKey = EthereumPrivateKey(rawBytes: [])
let standardWallet = EthereumWallet(privateKey: privateKey)
The following method encrypts the wallet using a secret generated in the secure enclave, the resolved ciphertext is stored in the Keychain. It returns the wallet in case no error is thrown.
standardWallet.encryptWallet()
The EthereumAccount
object is used to perform crypto operations over the encrypted wallet. In order to have full access to its capabilities, the injected address should have been previously encrypted.
Create a new instance by injecting the EthereumAddress
.
let address = EthereumAddress(hex: "0x7851b240aCE79FA6961AE36c865802D1416611e7")
let account = EthereumAccount(address: address)
It resolves a signature given the digest. You may only sign digests if the address injected has been encrypted before. If not, a notImported
error will be thrown.
account.signDigest([])
It decrypts the privateKey, and returns the closure containing its reference.
account.accessPrivateKey { privateKey in }
HDEthereumWallet
object is used to describe a Hierarchical deterministic Wallet.
Return the HD Wallet with the given mnemonic string.
let hdWallet = HDEthereumWallet(mnemonicString: "test test test")
Generate a new HD Wallet with the desired length.
let hdWallet = HDEthereumWallet(length: .word12)
Encrypt the mnemonic, and return the Id used as reference.
let id = hdwallet.encryptSeedPhrase()
It decrypts the seed phrase, generates an account at the indicated index, and returns the generated private key.
HDEthereumWallet.generateExternalPrivateKey(id: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F", index: UInt32(0)) { privateKey in }
It decrypts the seed phrase, and returns the closure containing its reference.
HDEthereumWallet.accessSeedPhrase(id: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F") { seedPhrase in }
In part based on the key manager written at Light Wallet (https://github.com/LightDotSo/Wallet).
GPL-3.0 license