npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

digicore-wallet-client

v2.4.2

Published

Client for digicore-wallet-service

Downloads

5

Readme

digicore-wallet-client

NPM Package Build Status Coverage Status

The official client library for [digicore-wallet-service] (https://github.com/bitpay/digicore-wallet-service).

Description

This package communicates with BWS Digicore 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 [Digicore-wallet] (https://github.com/bitpay/digicore-wallet) for a simple CLI wallet implementation that relays on BWS and uses digicore-wallet-client.

Get Started

You can start using digicore-wallet-client in any of these two ways:

  • via Bower: by running bower install digicore-wallet-client from your console
  • or via NPM: by running npm install digicore-wallet-client from your console.

Example

Start your own local Digicore wallet service instance. In this example we assume you have digicore-wallet-service running on your localhost:3232.

Then create two files irene.js and thomas.js with the content below:

irene.js

var Client = require('digicore-wallet-client');
var fs = require('fs');
var BWS_INSTANCE_URL = 'http://localhost:3232/bws/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('digicore-wallet-client');
var fs = require('fs');
var BWS_INSTANCE_URL = 'http://localhost:3232/bws/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 digicore-wallet-client before start:

npm i digicore-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.

API Client

###new API(opts) ClientAPI constructor.

Params

  • opts Object

###API.seedFromExtendedPrivateKey(xPrivKey) Seed from extended private key

Params

  • xPrivKey String

###API.seedFromRandom(xPrivKey) Seed from random

Params

  • network String

###API.export(opts) Export wallet

Params

  • opts Object
    • compressed Boolean
    • noSign Boolean

###API.import(opts) Import wallet

Params

  • opts Object
    • compressed Boolean

###API.isComplete() Return if wallet is complete

###API.openWallet(cb) Open a wallet and try to complete the public key ring.

Params

  • cb Callback

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

  • walletName String
  • copayerName String
  • m Number
  • n Number
  • opts Object
  • opts.network String - 'livenet' or 'testnet'
  • opts.walletPrivKey String - Optional: Shared private key for the wallet (used by copayers). Default: create a random one
  • opts.id String - Optional: ID for the wallet. Default: Create a random one
  • cb Callback

Returns: Callback - cb - Returns the wallet
###API.joinWallet(secret, copayerName, cb) Join to an existent wallet

Params

  • secret String
  • copayerName String
  • cb Callback

Returns: Callback - cb - Returns the wallet
###API.getStatus(cb) Get status of the wallet

Params

  • cb Callback

Returns: Callback - cb - Returns error or an object with status information
###API.sendTxProposal(opts) Send a transaction proposal

Params

For a proposal with one output:

  • opts Object
    • toAddress String
    • amount Number
    • message String

For a proposal with multiple outputs:

  • opts Object
    • type String - 'multiple_outputs'
    • outputs Array
      • toAddress String
      • amount Number
      • message String

Returns: Callback - cb - Return error or the transaction proposal

###API.getTx(id, cb) Gets a transaction proposal

Params

  • id String

Returns: Callback - cb - Return error or the transaction proposal

###API.createAddress(cb) Create a new address

Params

  • cb Callback

Returns: Callback - cb - Return error or the address
###API.getMainAddresses(opts, cb) Get your main addresses

Params

  • opts Object
    • doNotVerify Boolean
  • cb Callback

Returns: Callback - cb - Return error or the array of addresses
###API.getBalance(cb) Update wallet balance

Params

  • cb Callback

##API.getTxProposals(opts) Get list of transactions proposals

Params

  • opts Object
    • doNotVerify Boolean
    • forAirGapped Boolean

Returns: Callback - cb - Return error or array of transactions proposals
###API.signTxProposal(txp, cb) Sign a transaction proposal

Params

  • txp Object
  • cb Callback

Returns: Callback - cb - Return error or object
###API.signTxProposalFromAirGapped(txp, encryptedPkr, m, n) Sign a transaction proposal from an airgapped device

Params

  • txp Object
  • encryptedPkr String
  • m Number
  • n Number
  • cb Callback

Returns: Callback - cb - Return error or object
###API.rejectTxProposal(txp, reason, cb) Reject a transaction proposal

Params

  • txp Object
  • reason String
  • cb Callback

Returns: Callback - cb - Return error or object
###API.broadcastTxProposal(txp, cb) Broadcast a transaction proposal

Params

  • txp Object
  • cb Callback

Returns: Callback - cb - Return error or object
###API.removeTxProposal(txp, cb) Remove a transaction proposal

Params

  • txp Object
  • cb Callback

Returns: Callback - cb - Return error or empty
###API.getTxHistory(opts, cb) Get transaction history

Params

  • opts Object
    • skip Number
    • limit Number
  • cb Callback

Returns: Callback - cb - Return error or array of transactions

###API.setPrivateKeyEncryption(password, opts)

Sets up encryption for the extended private key

params

  • password string
  • opts Object Optional SJCL's encrypting options (like .iten and .salt)

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

  • password string

###api.lock()

Removes the unencrypted private key.

###api.getUtxos() Get list of wallet's Unspent Transaction Outputs.