Kukai Crypto Swift

Platforms Swift Package Manager License

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: "word1 word2 word3 ...")

Create a regular key pair and get a Tezos address

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...

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".bytes
let result = keyPair.privateKey.sign(bytes: messageToSign)

print("Result hex: \(result.hexString)") // c4d20c77d627d8c07e....



Documentation

Compiled Swift Doc’s can be found here