Giter Club home page Giter Club logo

blockchain-ts-wallet-core's Introduction

BLOCKCHAIN-TS-WALLET-CORE

Codacy Badge Build Status

About

TS library that implements wallet functionality for multiple blockchains. Allows to create multiple private keys from one mnemonic, get public key, get address or sign transaction

Supported blockchains

Index Name Symbol Logo URL
0 Bitcoin BTC https://bitcoin.org
2 Litecoin LTC https://litecoin.org
60 Ethereum ETH https://ethereum.org
61 Ethereum Classic ETC https://ethereumclassic.org
145 Bitcoin Cash BCH https://bitcoincash.org
148 Stellar XLM https://stellar.org
178 POA Network POA https://poa.network
5741564 Waves WAVES https://wavesplatform.com

Inspiration

Trust Wallet: Wallet Core project - C++ version for multiple platforms, except frontend.

Installation

  • npm i -s @buttonwallet/blockchain-ts-wallet-core

Usage

import * as TsWalletCore from '@buttonwallet/blockchain-ts-wallet-core'  

or

const TsWalletCore = require('@buttonwallet/blockchain-ts-wallet-core');

For Browser

git clone https://github.com/button-tech/blockchain-ts-wallet-core.git

cd blockchain-ts-wallet-core

npm i

npm run build:browser 

# the output data will be located in the build folder

HDWallet

Generate mnemonic

const phrase = TsWalletCore.HdWallet.generateMnemonic()
console.log(phrase) // control sock axis field icon jewel gown duck amateur type step save

Generate all key pairs

const phrase = 'control sock axis field icon jewel gown duck amateur type step save'
const password = ''
const wallet = new TsWalletCore.HdWallet(phrase, password)

const derivationIndex = 0;
const currencies = wallet.generateAllKeyPairs(derivationIndex)
console.log(currencies)
/*
  eth: {
    privateKey: 'e3776b46699e2a6e55b19d7033b7724758b753c7391137e3eb5eaf3daed1db54',
    publicKey: '032348140ab3270e02cf9cce9e1fd3201cb9068671c490f3e2fabe0308a8afd284',
    address: '0xC9330Ce433DfB0046efc7dD8aB1A8ACC433f37Aa'
  },
  etc: {
    privateKey: '4e3ddb695f387f186a052409f8d0ae7c567f7e655fcfc8ed5beba155ef540f6e',
    publicKey: '030e5902714da28790c042ac1eacf514f2122665b44f6b2edcf0fc8114563821b4',
    address: '0x73974c2e5F442969b443Aed9c31Df94d854584c3'
  },
  bch: {
    address: '1F4JWB8UfqwBLpQRFGru7495Bc5y6PSZeS',
    publicKey: '0237fb66a27dae7af50ea29682fb780c700a8040f3336841f3abb5049afe49e26a',
    privateKey: '3e02ddbfd138dd84d9723d87e6d0533b298ffe54dc3b70a51d4009fb328f6b5a'
  },
  btc: {
    address: '1B7eaEtrFd2vzQDC2NcVXrbj8mCiTJDEAj',
    publicKey: '0324c0bd0f0f95c4177add9bdc40c57f1bf2472e6eaf8e67c9fa6f16f55516aed6',
    privateKey: '81beacae2014a62dedd8315325f698230fd8a8512825b5e1492a1dd4dcf05615'
  },
  ltc: {
    address: 'LMMN6Ybq87MhTf7YRfhapg33BWH53LkCgF',
    publicKey: '0273cd45409947a21a3b1ba66e947042afd4bf60a0ff1d1bf9f5af8e5ccae70a41',
    privateKey: 'd0f301b8f13f41cc53b6a5d15fd9d9920a0708076dc0233a762e306de0b0ee52'
  },
  waves: {
    privateKey: '180aa4d28f002b5a8a9381816376ea3b99fd2d6e1576a631e3d9e6ae2dac086b',
    publicKey: '3bcc2164560b1dd5557f9087b1dbb59b90601652d297a202bfe97601410dc219',
    address: '3PCAeB89wih4jnVSG9cUPptoy9AJij4c9fP'
  }
*/

Generate specific keys

const phrase = 'control sock axis field icon jewel gown duck amateur type step save'
const password = ''
const wallet = new TsWalletCore.HdWallet(phrase, password)

const derivationIndex = 0;
const currency = wallet.generateKeyPair(TsWalletCore.DomainEthereum.Instance(), derivationIndex);
console.log(currency)
/*
{
  privateKey: 'e3776b46699e2a6e55b19d7033b7724758b753c7391137e3eb5eaf3daed1db54',
  publicKey: '032348140ab3270e02cf9cce9e1fd3201cb9068671c490f3e2fabe0308a8afd284',
  address: '0xC9330Ce433DfB0046efc7dD8aB1A8ACC433f37Aa'
}
*/

Transaction Example

You can find an example how to sign transactions for different blockchains here

// TsWalletCore.MnemonicDescriptor or private key
const privateKey = '04e17ebf3b33a81a98ee779e50b725e03bbbacaca689c9f02a465800dd955e7c';

// transaction parameters (specific almost for each blockchain)
const params: TsWalletCore.TransactionParams = {
  toAddress: '0x6f387b7d5FA35a874218128E778F568294069e4C',
  amount: '0.00059655',
  nonce: 342,
  gasPrice: 7200000000,
  gasLimit: 21000
};
const blockchain = TsWalletCore.Ethereum(privateKey);
const signedTx = blockchain.signTransaction(params)
  .then(console.log)
/*
f86d8201568501ad274800825208946f387b7d5fa35a874218128e778f568294069e4c87021e8f1ed73c008025a0af698edeaae7cfb5a7c6b5091f000baaaa741a9cd7cf60e53dccc21a1dcec22fa03ad3edf9cfc535c21e4d4ddebccad05ea07d3d09bba1be9fdffc40ce2adef040
*/

Contributing

The best way to submit feedback and report bugs is to open a GitHub issue

License

blockchain-ts-wallet-core is available under the MIT license. See the LICENSE file for more info.

blockchain-ts-wallet-core's People

Contributors

codacy-badger avatar krboktv avatar prazd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

blockchain-ts-wallet-core's Issues

How do I open this I'm new to this I want to get this into my btc wallet I was given this to me but have no idea what to do can you help me

get a $ bitcoin-cli listunspent
[txid": "ca4898d8f950df03d6bfaa00578bd0305d041d24788b630d0c4a32debcac9f36",
"vout": 0,
"address": "mi25UrzHnvn3bpEfFCNqJhPWJn5b77a5NE",
"label": "",
"scriptPubKey": "76a9141b72503639a13f190bf79acf6d76255d772360b788ac",
"amount": 0.00010000,
"confirmations": 20,
"spendable": true,
"solvable": true,
"desc": "pkh ([d6043800/0'/0'/1'] a)#62rud39c",
"safe": true
},
{
"txid": "61f3b7016bf1ecc3987b8805207e79362e4de8026682e149107999b779426e3a",
"vout": 1, chi
"address": "mjehC2KHzXcBDcwTd4LhZ2GzyzrZ3Kd3ff",
"label": "",
"scriptPubKey": "76a9142d573900aa357a38afd741fbf24b075d263ea6e088ac",
"amount": 0.00050000,
"confirmations": 3,
"spendable": true,
"solvable": true,
"desc": "pkh([d6043800/0'/0'/3']0278608b54b8fb0d8379d3823d31f03a7c6ab0adffb07dd3811819fdfc34f8c132)#nhjc3f8y",
"safe": true
},
{
"txid": "91261eafae15ea53dedbea7c1db748c52bbc04a85859ffd0d839bda1421fda4c",
"vout": 0,
"address": "mjehC2KHzXcBDcwTd4LhZ2GzyzrZ3Kd3ff",
"label": "",
"scriptPubKey": "76a9142d573900aa357a38afd741fbf24b075d263ea6e088ac",
"amount": 0.00022000,
"confirmations": 3,
"spendable": true,
"solvable": true,
"desc": "pkh([d6043800/0'/0'$ bitcoin-cli listunspent
[
{
"txid": "ca4898d8f950df03d6bfaa00578bd0305d041d24788b630d0c4a32debcac9f36",
"vout": 0,
"address": "mi25UrzHnvn3bpEfFCNqJhPWJn5b77a5NE",
"label": "",
"scriptPubKey": "76a9141b72503639a13f190bf79acf6d76255d772360b788ac",
"amount": 0.00010000,
"confirmations": 20,
"spendable": true,
"solvable": true,
"desc": "pkh([d6043800/0'/0'/1']02fd5740996d853ea51a6904cf03257fc11204b0179f344c49739ec5b20b39c9ba)#62rud39c",
"safe": true
},
{
"txid": "61f3b7016bf1ecc3987b8805207e79362e4de8026682e149107999b779426e3a",
"vout": 1,
"address": "mjehC2KHzXcBDcwTd4LhZ2GzyzrZ3Kd3ff",
"label": "",
"scriptPubKey": "76a9142d573900aa357a38afd741fbf24b075d263ea6e088ac",
"amount": 0.00050000,
"confirmations": 3,
"spendable": true,
"solvable": true,
"desc": "pkh([d6043800/0'/0'/3']0278608b54b8fb0d8379d3823d31f03a7c6ab0adffb07dd3811819fdfc34f8c132)#nhjc3f8y",
"safe": true
},
{
"txid": "91261eafae15ea53dedbea7c1db748c52bbc04a85859ffd0d839bda1421fda4c",
"vout": 0,
"address": "mjehC2KHzXcBDcwTd4LhZ2GzyzrZ3Kd3ff",
"label": "",
"scriptPubKey": "76a9142d573900aa357a38afd741fbf24b075d263ea6e088ac",
"amount": 0.00022000,
"confirmations": 3,
"spendable": true,
"solvable": true,
"desc": "pkh([d6043800/0'/0'/3']w)#nhjc3f8y",
"safe": true
}
]

/3']0278608b54b8fb0d8379d3823d31f03a7c6ab0adffb07dd3811819fdfc34f8c132)#nhjc3f8y",
"safe": true
}
]

transactions from a known address (supposedly Silk Road) $ curl https://api.blockcypher.com/v1/btc/main/https://api.blockcypher.com/v1/btc/main/txs/a40c283de4c26b027a5734ff89ce78ade1220fc313befa107ec6c245c24bdec0/1rundZJCMJhUiWQNFS5uT3BvisBuLxkAp?limit=2 # get one of the two transactions (a big one) $ curl # retrieve the block it was included in by height $ curl https://api.blockcypher.com/v1/btc/main/blocks/319957 -

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.