Swiftpack.co - KevinVitale/WalletKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by KevinVitale.
KevinVitale/WalletKit 0.0.3
Modern Swift implementations of BIP39, BIP32, and BIP44
⭐️ 11
🕓 1 year ago
iOS macOS
.package(url: "https://github.com/KevinVitale/WalletKit.git", from: "0.0.3")

Platforms

  • macOS, v10.15+;
  • iOS, v13+;
  • Linux

CLI Utility

This CLI utility is cross-platform, and demonstrates a portion of this framework's functionality.

Adding WalletKit as a Dependency

To use the WalletKit library in a Swift Package Manager (SPM) project, add the following line to the dependencies in you Package.swift file:

.package(url: "https://github.com/KevinVitale/WalletKit", from: "0.0.3"),

The WalletKit library is under active development, and while attempts are made to maintain source-stability, this is not guaranteed between minor versions. You may specify .upToNextMinor(from:), instead of from(_:), if you need to be at a specific version.

Usage

import WalletKit

let wallet  = try Mnemonic().createWallet()
let account = try wallet.account(coinType: .ETH, atIndex: 0)

// 'Normal' addresses...
account[.normal(0..<10)].forEach { 
    print($0.address)
}

// 'Hardened' addresses...
account[.hardened(0..<10)].forEach { 
    print($0.address)
}

Examples

let mnemonic = try Mnemonic()
  print(mnemonic.phrase)

  let accounts = try mnemonic.createWallet().account(coinType: .ETH, atIndex: 0)
  accounts[.hardened(0..<10)].enumerated().forEach { (index, account) in
    let address = account.address
    let privateKey = "0x" + account.privateKey.key.dropFirst().hexString
    
    print("[idx: \(index)]", address, privateKey)
  }
}

// Console output
<24-word seed phrase>
[idx: 0] 0x95e18dd2115c49651a5195cdaed1e4589d9a882d 0x...privatekey...
[idx: 1] 0x70c52be490029822278eecf2d9e4324c6e0505b8 0x...privatekey...
[idx: 2] 0x11194b63c701ba9612d8b4c29e9d34127160043c 0x...privatekey...
[idx: 3] 0x90ec34dd860c4e2876ea3e2ce3f7362d6ef9c8b5 0x...privatekey...
[idx: 4] 0x3a0a814ad24e703aae2b1acb2211dba4dab7330f 0x...privatekey...
[idx: 5] 0x9cc103ff117e604fbf5fee3d4b90b2646576190f 0x...privatekey...
[idx: 6] 0x263c0757284090a3ceec27243d483399bbc0a570 0x...privatekey...
[idx: 7] 0x645b93bda895c130451b5e20341130665f693c53 0x...privatekey...
[idx: 8] 0x14b6fdfdbe37fbcd6a2e4a6f85a303bcc8327552 0x...privatekey...
[idx: 9] 0xffd4e7a268a8cf75f4215f06a8ebc049195c1b4e 0x...privatekey...

Command-Line Interface

USAGE: cli [--seed-phrase <seed-phrase>] [--passphrase <passphrase>]

OPTIONS:
  -s, --seed-phrase <seed-phrase>
                          A specific mnemonic seed phrase used to create the wallet. 
  -p, --passphrase <passphrase>
                          An optional passphrase for improving entropy. 
  -h, --help              Show help information.

GitHub

link
Stars: 11
Last commit: 15 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

Release Notes

Bug fixes
1 year ago

Fixed some compiler issues:

  • Updated swift-crypto url to use the appropriate branch (s/master/main);
  • Fixed a compiler issue with protocol conformance on Account;
  • Added two tests to BIP44 showing how to create wallets from randomly generated seed phrases

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics