| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
The official client library for [bitcore-wallet-service] (https://github.com/bitpay/bitcore-wallet-service).
This package communicates with BWS Bitcore wallet service using the REST API. All REST endpoints are wrapped as simple async methods. All relevant responses from BWS are checked independently by the peers, thus the importance of using this library when talking to a third party BWS instance.
See [Bitcore-wallet] (https://github.com/bitpay/bitcore-wallet) for a simple CLI wallet implementation that relays on BWS and uses bitcore-wallet-client.
You can start using bitcore-wallet-client in any of these two ways:
Start your own local Bitcore wallet service instance. In this example we assume you have bitcore-wallet-service running on your localhost:3001.
Then create two files irene.js and thomas.js with the content below:
irene.js
var Client = require('bitcore-wallet-client');
var fs = require('fs');
var BWS_INSTANCE_URL = 'http://localhost:3001/copay/api'
var client = new Client({
baseUrl: BWS_INSTANCE_URL,
verbose: false,
});
client.createWallet("My Wallet", "Irene", 2, 2, {network: 'testnet'}, function(err, secret) {
// Handle err
console.log('Wallet Created. Share this secret with your copayers: ' + secret);
fs.writeFileSync('irene.dat', client.export());
});thomas.js
var Client = require('bitcore-wallet-client');
var fs = require('fs');
var BWS_INSTANCE_URL = 'http://localhost:3001/copay/api'
var secret = process.argv[2];
var client = new Client({
baseUrl: BWS_INSTANCE_URL,
verbose: false,
});
client.joinWallet(secret, "Thomas", function(err, wallet) {
// Handle err
console.log('Joined ' + wallet.name + '!');
fs.writeFileSync('thomas.dat', client.export());
});Install bitcore-wallet-client before start:
npm i bitcore-wallet-client
Create a new wallet with the first script:
$ node irene.js info Generating new keys Wallet Created. Share this secret with your copayers: JbTDjtUkvWS4c3mgAtJf4zKyRGzdQzZacfx2S7gRqPLcbeAWaSDEnazFJF6mKbzBvY1ZRwZCbvT
Join to this wallet with generated secret:
$ node thomas.js JbTDjtUkvWS4c3mgAtJf4zKyRGzdQzZacfx2S7gRqPLcbeAWaSDEnazFJF6mKbzBvY1ZRwZCbvT Joined My Wallet!
Note that the scripts created two files named irene.dat and thomas.dat. With these files you can get status, generate addresses, create proposals, sign transactions, etc.
###new API(opts) ClientAPI constructor.
Params
###API.seedFromExtendedPrivateKey(xPrivKey) Seed from extended private key
Params
###API.seedFromRandom(xPrivKey) Seed from random
Params
###API.export(opts) Export wallet
Params
###API.import(opts) Import wallet
Params
###API.isComplete() Return if wallet is complete
###API.openWallet(cb) Open a wallet and try to complete the public key ring.
Params
Returns: Callback - cb - Returns an error and a flag indicating that the wallet has just been completed and needs to be persisted
###API.createWallet(walletName, copayerName, m, n, network, cb)
Create a wallet.
Params
Returns: Callback - cb - Returns the wallet
###API.joinWallet(secret, copayerName, cb)
Join to an existent wallet
Params
Returns: Callback - cb - Returns the wallet
###API.getStatus(cb)
Get status of the wallet
Params
Returns: Callback - cb - Returns error or an object with status information
###API.sendTxProposal(opts)
Send a transaction proposal
Params
Returns: Callback - cb - Return error or the transaction proposal
###API.getTx(id, cb) Gets a transaction proposal
Params
Returns: Callback - cb - Return error or the transaction proposal
###API.createAddress(cb) Create a new address
Params
Returns: Callback - cb - Return error or the address
###API.getMainAddresses(opts, cb)
Get your main addresses
Params
Returns: Callback - cb - Return error or the array of addresses
###API.getBalance(cb)
Update wallet balance
Params
##API.getTxProposals(opts) Get list of transactions proposals
Params
Returns: Callback - cb - Return error or array of transactions proposals
###API.signTxProposal(txp, cb)
Sign a transaction proposal
Params
Returns: Callback - cb - Return error or object
###API.signTxProposalFromAirGapped(txp, encryptedPkr, m, n)
Sign a transaction proposal from an airgapped device
Params
Returns: Callback - cb - Return error or object
###API.rejectTxProposal(txp, reason, cb)
Reject a transaction proposal
Params
Returns: Callback - cb - Return error or object
###API.broadcastTxProposal(txp, cb)
Broadcast a transaction proposal
Params
Returns: Callback - cb - Return error or object
###API.removeTxProposal(txp, cb)
Remove a transaction proposal
Params
Returns: Callback - cb - Return error or empty
###API.getTxHistory(opts, cb)
Get transaction history
Params
Returns: Callback - cb - Return error or array of transactions
###API.setPrivateKeyEncryption(password, opts)
Sets up encryption for the extended private key
params
Usage example:
api.setPrivateKeyEncryption('mypassword');
...
api.getTxProposals({}, function(err, txps) {
api.unlock('mypassword');
api.signTxProposal(txps[0], function (err){
api.lock();
});
})###api.unlock(password)
Tries to unlock (decrypt) the extened private key with the provided password. (setprivatekeyencryption should be called first). lock must be called afterwards to remove the uncrypted private key.
params
###api.unlock()
Removes the unencrypted private key.
| Back | FazBrowse Home | New Git URL |