Latest 0.2.1
Homepage https://github.com/BitcoinCashKit/BitcoinCashKit
License MIT
Platforms ios 8.0, requires ARC
Authors

BitcoinCashKit: Let's Play with Bitcoin in Swift!

CI Status
codecov
Carthage compatible
Version
Platform

Welcome to BitcoinCashKit

The BitcoinCashKit library is a Swift implementation of the Bitcoin cash protocol. This library is a fork of Katsumi Kishikawa’s original BitcoinKit library aimed at supporting the Bitcoin cash eco-system.

It allows maintaining a wallet and sending/receiving transactions without needing a full blockchain node. It comes with a simple wallet app showing how to use it.

Release notes are here.

BitcoinCashKit BitcoinCashKit

Features

  • Encoding/decoding addresses: base58, Cashaddr, P2PKH, P2SH, WIF format.
  • Transaction building blocks: inputs, outputs, scripts.
  • EC keys and signatures.
  • BIP32, BIP44 hierarchical deterministic wallets.
  • BIP39 implementation.
  • SPV features are under construction. The following functions cannot work well sometimes.
    • Send/receive transactions.
    • See current balance in a wallet.

Usage

Generate addresses

// from Testnet Cashaddr
let cashaddrTest = try AddressFactory.create("bchtest:pr6m7j9njldwwzlg9v7v53unlr4jkmx6eyvwc0uz5t")

// from Mainnet Cashaddr
let cashaddrMain = try AddressFactory.create("bitcoincash:qpjdpjrm5zvp2al5u4uzmp36t9m0ll7gd525rss978")

// from Base58 format
let address = try AddressFactory.create("1AC4gh14wwZPULVPCdxUkgqbtPvC92PQPN")

Creating new wallet

let privateKey = PrivateKey(network: .testnet) // You can choose .mainnet or .testnet
let wallet = Wallet(privateKey: privateKey)

Import wallet from WIF

let wallet = try Wallet(wif: "92pMamV6jNyEq9pDpY4f6nBy9KpV2cfJT4L5zDUYiGqyQHJfF1K")

Hierarchical Deterministic Wallet

// Generate mnemonic
let mnemonic = try Mnemonic.generate()

// Generate seed from the mnemonic
let seed = Mnemonic.seed(mnemonic: mnemonic)

let wallet = HDWallet(seed: seed, network: .testnet)

Key derivation

let mnemonic = try Mnemonic.generate()
let seed = Mnemonic.seed(mnemonic: mnemonic)

let privateKey = HDPrivateKey(seed: seed, network: .testnet)

// m/0'
let m0prv = try! privateKey.derived(at: 0, hardened: true)

// m/0'/1
let m01prv = try! m0prv.derived(at: 1)

// m/0'/1/2'
let m012prv = try! m01prv.derived(at: 2, hardened: true)

HD Wallet Key derivation

let keychain = HDKeychain(seed: seed, network: .mainnet)
let privateKey = try! keychain.derivedKey(path: "m/44'/1'/0'/0/0")

Extended Keys

let extendedKey = privateKey.extended()

Sync blockchain

let blockStore = try! SQLiteBlockStore.default()
let blockChain = BlockChain(network: .testnet, blockStore: blockStore)

let peerGroup = PeerGroup(blockChain: blockChain)
let peerGroup.delegate = self

let peerGroup.start()

Requirements

  • iOS 9.0+ / Mac OS X 10.11+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 9.0+
  • Swift 4.1+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.5.0+ is required to build BitcoinCashKit.

To integrate BitcoinCashKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'BitcoinCashKit'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate BitcoinCashKit into your Xcode project using Carthage, specify it in your Cartfile:

github "BitcoinCashKit/BitcoinCashKit"

Run carthage update to build the framework and drag the built BitcoinCashKit.framework into your Xcode project.

Contribute

Contributions to BitcoinCashKit are welcome and encouraged!
Feel free to open issues, drop us pull requests.

Authors & Maintainers

License

BitcoinCashKit is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "BitcoinCashKit",
    "version": "0.2.1",
    "summary": "Bitcoin cash protocol toolkit for Swift",
    "description": "The BitcoinCashKit library is a Swift implementation of the Bitcoin cash protocol. This library is a fork of Katsumi Kishikawa's original BitcoinKit library aimed at supporting the Bitcoin cash eco-system. It allows maintaining a wallet and sending/receiving transactions without needing a full blockchain node. It comes with a simple wallet app showing how to use it.n```",
    "homepage": "https://github.com/BitcoinCashKit/BitcoinCashKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "BitcoinCashKit developers": "[email protected]"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/BitcoinCashKit/BitcoinCashKit.git",
        "tag": "v0.2.1"
    },
    "source_files": "BitcoinCashKit/**/*.{h,m,swift}",
    "private_header_files": "BitcoinCashKit/**/BitcoinCashKitPrivate.h",
    "module_map": "BitcoinCashKit/BitcoinCashKit.modulemap",
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.1",
    "pod_target_xcconfig": {
        "SWIFT_WHOLE_MODULE_OPTIMIZATION": "YES",
        "APPLICATION_EXTENSION_API_ONLY": "YES",
        "SWIFT_INCLUDE_PATHS": "${PODS_ROOT}/BitcoinCashKit/Libraries",
        "HEADER_SEARCH_PATHS": ""${PODS_ROOT}/BitcoinCashKit/Libraries/openssl/include" "${PODS_ROOT}/BitcoinCashKit/Libraries/secp256k1/include"",
        "LIBRARY_SEARCH_PATHS": ""${PODS_ROOT}/BitcoinCashKit/Libraries/openssl/lib" "${PODS_ROOT}/BitcoinCashKit/Libraries/secp256k1/lib""
    },
    "preserve_paths": [
        "setup",
        "Libraries"
    ],
    "prepare_command": "sh setup/build_libraries.sh"
}

Pin It on Pinterest

Share This