Skip to content

Pure Swift account manager for some blockchain networks

License

Notifications You must be signed in to change notification settings

lumoscompany/keestore

Repository files navigation

Keestore Tests

Pure Swift account manager for web2 & web3

  • BIP32, BIP39, BIP44

Installation

.package(
    url: "https://github.com/lumoscompany/keestore.git",
    .upToNextMajor(from: "0.9.0")
)

Usage samples

Importing blockchain accounts

import Keestore

let key = DerivedKey(string: "123456")
let passphrase = "12/24/32 words"

let account = try Account.Blockchain.create(
    for: .ethereum(),
    with: .mnemonica(
        passphrase.components(separatedBy: " "),
        HDWallet(coin: .ethereum).derivationPath
    ),
    using: key
)

print(account.address)

Storing accounts using .keestore document

let fileName = "default"
let directoryURL = URL(fileURLWithPath: "file:https:///")
let file = Document(direcotryURL: directoryURL, fileNamed: fileName)

guard file.isExists
else {
    return
}

let keestore = try await file.read()
let account = keestore.accounts[0]

switch account.kind {
case let .blockchain(value):
    let key = DerivedKey(string: "${key}")
    let credentials = try? account.credentials?.decrypt(using: key)
    print(credentials)
default:
    break
}

Signing

let account: Account
let key: DerivedKey

let signature = try? account.signer?.sign(data, using: key)
print(signature)

Authors