Home

Awesome

Zerion Wallet Core

This repository contains Wallet Core used by Zerion app.

Examples

Check tests to see all examples.

Define wallet storage and manager:

let storage = ZerionWalletStorage(service: "com.mywallet")
let manager = ZerionWalletManager(storage: storage)

Import or create wallet:

let walletContainer = try manager.importWalletPersist(mnemonic: mnemonic, password: password, name: "My wallet")
// or
let walletContainer = try manager.importWalletPersist(privateKey: privateKey, password: password, name: "My wallet")
// or
let walletContainer = try manager.createWalletPersist(password: password, name: "My wallet")

Derive accounts with index or derivation path:

let account0 = walletContainer.deriveAccount(accountIndex: 0, password: password)
let account1 = walletContainer.deriveAccount(derivationPath: "m/44'/60'/0'/0/1", password: password)

Access private key via index or derivation path:

let privateKey0 = try walletContainer.decryptPrivateKey(accountIndex: 0, password: password).hexString
let privateKey1 = try walletContainer.decryptPrivateKey(derivationPath: "m/44'/60'/0'/0/1", password: password).hexString

Access seed phrase:

let mnemonic = walletContainer.decryptMnemonic(password: password)

Sign transaction:

let transaction = TransactionInput(
  chainID: ...,
  nonce: ...,
  gasPrice: ...,
  gas: ...,
  toAddress: ...,
  data: ...,
  amount: ...,
)

let signed = try Signer.sign(input: .transaction(transaction), privateKey: privateKey).hexString

Installation via Swift Package Manager

Xcode

Select File > Add Packages... > Add Package Dependency... and insert git url.

CLI

First, create Package.swift that its package declaration includes:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "MyLibrary",
    products: [
        .library(name: "MyLibrary", targets: ["MyLibrary"]),
    ],
    dependencies: [
        .package(url: "https://github.com/zeriontech/zerion-wallet-core-ios.git", branch: "master"),
    ],
    targets: [
        .target(name: "MyLibrary", dependencies: ["ZerionWalletCore"]),
    ]
)

Then, type

$ swift build

Dependencies

TrustWalletCore - low level wallet cryptography functionality, written in C++ with Swift wrappers.

KeychainAccess - wrapper for iOS keychain.

SwiftyJSON - easy JSON handling with Swift.

CryptoSwift - crypto related functions and helpers for Swift implemented in Swift.

License

Zerion Wallet Core is available under the Apache 2.0 license. See the LICENSE file for more info.