Skip to content
forked from anquii/BIP32

An implementation of BIP-0032 in Swift

License

Notifications You must be signed in to change notification settings

unstoppablefi/BIP32

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BIP32

Platform Swift Package Manager compatible License

An implementation of BIP-0032 in Swift.

Platforms

  • macOS 10.15+
  • iOS 13+

Installation

Swift Package Manager

Add the following line to your Package.swift file:

.package(url: "https://github.com/anquii/BIP32.git", from: "1.0.0")

...or integrate with Xcode via File -> Swift Packages -> Add Package Dependency... using the URL of the repository.

Usage

import BIP32

let keySerializer: KeySerializing = KeySerializer()
let serializedKeyCoder: SerializedKeyCoding = SerializedKeyCoder()

let privateMasterKeyDerivator: PrivateMasterKeyDerivating = PrivateMasterKeyDerivator()
let privateMasterKey = try privateMasterKeyDerivator.privateMasterKey(seed: seed)
let privateMasterKeyAttributes = MasterKeyAttributes(accessControl: .`private`, version: version)
let serializedPrivateMasterKey = try keySerializer.serializedKey(extendedKey: privateMasterKey, attributes: privateMasterKeyAttributes)
let encodedPrivateMasterKey = serializedKeyCoder.encode(serializedKey: serializedPrivateMasterKey)
// e.g. xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi

let publicMasterKeyDerivator: PublicMasterKeyDerivating = PublicMasterKeyDerivator()
let publicMasterKey = try publicMasterKeyDerivator.publicKey(privateKey: privateMasterKey)
let publicMasterKeyAttributes = MasterKeyAttributes(accessControl: .`public`, version: version)
let serializedPublicMasterKey = try keySerializer.serializedKey(extendedKey: publicMasterKey, attributes: publicMasterKeyAttributes)
let encodedPublicMasterKey = serializedKeyCoder.encode(serializedKey: serializedPublicMasterKey)
// e.g. xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8

Find out more by exploring the public API (e.g. for child key derivation), and by looking through the tests.

License

BIP32 is licensed under the terms of the MIT license. See the LICENSE file for more information.

Acknowledgments

In developing BIP32, KevinVitale's WalletKit has been used as a reference implementation. In addition, BIP32 depends on krzyzanowskim's CryptoSwift, GigaBitcoin's secp256k1.swift and attaswift's BigInt.

About

An implementation of BIP-0032 in Swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%