Kukai Crypto Swift - A native Swift library for creating regular or HD wallets for the Tezos blockchain
Kukai Crypto Swift
Kukai Crypto Swift is a native Swift library for creating regular and HD key pairs for the Tezos blockchain. Supporting both TZ1 (Ed25519) and TZ2 (secp256k1) for regular pairs, and TZ1 (Ed25519 (BIP44 via SLIP-0010)) for HD pairs.
Feature set includes:
- Create BIP39 mnemonics in English or Chinese
- Generate a cryptographic seed from a Menmonic in a tiny fraction of a second
- Create TZ1 or TZ2 key pair from a seed
- Derive HD key pair from a seed and derivation path
- Support for optional passwords
Based off:
Install
Kukai Crypto Swift supports the Swift Package Manager. Either use the Xcode editor to add to your project by clicking File
-> Swift Packages
-> Add Package Dependency
, search for the git repo https://github.com/kukai-wallet/kukai-crypto-swift.git
and choose from version 1.0.0
.
Or add it to your Package.swift
dependencies like so:
dependencies: [ .package(url: "https://github.com/kukai-wallet/kukai-crypto-swift", from: "1.0.0")]
How to use
Create a new Mnemonic
let mnemonic = try Mnemonic(numberOfWords: .twentyFour)
Create a Mnemonic from an existing phrase
let mnemonic = try Mnemonic(seedPhrase: "remember smile trip tumble era cube worry fuel bracket eight kitten inform")
Create a regular key pair and get a Tezos address
let keyPair = KeyPair.regular(fromMnemonic: mnemonic, passphrase: "", andSigningCurve: .ed25519)print(keyPair.publicKey.publicKeyHash) // tz1T3QZ5w4K11RS3vy4TXiZepraV9R5GzsxG
let keyPair = KeyPair.regular(fromMnemonic: mnemonic, passphrase: "", andSigningCurve: .secp256k1)print(keyPair.publicKey.publicKeyHash) // tz2UiZQJwaVAKxRuYxV8Tx5k8a64gZx1ZwYJ
Create a HD key pair
let keyPair = KeyPair.hd(fromMnemonic: mnemonic, passphrase: "", andDerivationPath: "44'/1729'/0'/0'")
Sign a message
let messageToSign = "something very interesting that needs to be signed".byteslet result = keyPair.privateKey.sign(bytes: messageToSign)print("Result hex: \(result.hexString)") // c4d20c77d627d8c07e....
Documentation
Compiled Swift Doc’s can be found here