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:
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")
]
let mnemonic = try Mnemonic(numberOfWords: .twentyFour)
let mnemonic = try Mnemonic(seedPhrase: "word1 word2 word3 ...")
let keyPair = KeyPair.regular(fromMnemonic: mnemonic, passphrase: "", andSigningCurve: .ed25519)
print(keyPair.publicKey.publicKeyHash) // tz1Abc123...
let keyPair = KeyPair.regular(fromMnemonic: mnemonic, passphrase: "", andSigningCurve: .secp256k1)
print(keyPair.publicKey.publicKeyHash) // tz2def456...
let keyPair = KeyPair.hd(fromMnemonic: mnemonic, passphrase: "", andDerivationPath: "44'/1729'/0'/0'")
let messageToSign = "something very interesting that needs to be signed".bytes
let result = keyPair.privateKey.sign(bytes: messageToSign)
print("Result hex: \(result.hexString)") // c4d20c77d627d8c07e....
Compiled Swift Doc's can be found here