Skip to content

Latest commit

 

History

History
52 lines (42 loc) · 1.94 KB

File metadata and controls

52 lines (42 loc) · 1.94 KB

bitcore-wallet-client (BWC)

JavaScript/TypeScript client for Bitcore Wallet Service.

Key classes

  • API — main client, extends EventEmitter (polls notifications)
  • Key — HD seed manager (mnemonic/xprv), derives Credentials
  • Credentials — serializable wallet identity (chain, network, xpub, request keys)
  • Request — HTTP wrapper used by API
  • Verifier, Utils, PayPro, PayProV2, BulkClient — helpers

Quickstart

import { API, Key } from 'bitcore-wallet-client';

// 1) Point to your BWS instance
const client = new API({ baseUrl: 'http://localhost:3232/bws/api', logLevel: 'info' });

// 2) Create a new seed and derive credentials (single-sig BTC, livenet, account 0)
const key = new Key({ seedType: 'new' });
const credentials = key.createCredentials(undefined, {
  coin: 'btc', chain: 'btc', network: 'livenet', account: 0, n: 1
});

// 3) Attach credentials to client
client.fromObj(credentials.toObj());

// 4) Create a wallet (server enforces auth via headers built by client)
client['request'].post('/v2/wallets/', { // or use high-level API methods if available
  name: 'My Wallet', m: 1, n: 1, network: 'livenet', coin: 'btc'
}, (err, res) => { /* ... */ });

Notifications

client.initialize({ notificationIncludeOwn: true }, () => {
  client.on('notification', n => console.log('notification', n));
});

Common flows (outline)

  • Create/join wallet: POST /v2/wallets/, then /v2/wallets/:id/copayers/
  • Create address: POST /v4/addresses/
  • Balance: GET /v1/balance/
  • UTXOs: GET /v1/utxos/
  • Create TXP: POST /v3/txproposals/
  • Sign TXP: POST /v2/txproposals/:id/signatures/ (signatures generated using Key + Utils)
  • Publish/broadcast: POST /v1/txproposals/:id/publish/ then /v1/txproposals/:id/broadcast/

Notes:

  • See Credentials.FIELDS for serializable fields and Key for encryption helpers.
  • The client sets required headers/signatures automatically using the attached credentials.