GithubHelp home page GithubHelp logo

shady-record-s / bitcoinkit Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 5.53 MB

Bitcoin protocol toolkit for Swift maintained by the Bitcoin.com Wallet Team. Enjoy!

Home Page: https://wallet.bitcoin.com

License: MIT License

Swift 98.30% Ruby 0.22% Objective-C 1.14% Shell 0.34%

bitcoinkit's Introduction

BitcoinKit: Let’s Play with Bitcoin in Swift!

Build Status codecov Version Platform

Welcome to BitcoinKit

The BitcoinKit library is a Swift implementation of the Bitcoin protocol, supporting both of BCH and BTC. Our mission is improving the mobile ecosystem for Bitcoin developers.

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.

 

Features

  • Encoding/decoding addresses: base58, Cashaddr, SLP, 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 BitcoinKit.

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

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

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

Then, run the following command:

$ pod install

Swift Package Manager

BitcoinKit is available through Swift Package Manager. To install it, simply add the following lines to dependencies of your Package.swift:

.package(url: "https://github.com/Bitcoin-com/BitcoinKit.git", .upToNextMinor(from: "0.1.0"))

Note that following data types and features are currently not supported on Linux platform.

  • Peer and PeerGroup
  • SQLite based BlockStore

Contribute

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

Authors

Maintainers

About

Visit our website or on twitter (@BitcoinCom)

License

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

Contributors

This project exists thanks to all the people who contribute. See the contributors

bitcoinkit's People

Contributors

usatie avatar kishikawakatsumi avatar s2mr avatar mizorin avatar tttakaoka avatar federicobond avatar jenbitcoin avatar pebble8888 avatar akifumi avatar holemcross avatar monkeywithacupcake avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.