0.7.1 • Published 1 month ago

dashwallet v0.7.1

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
1 month ago

DashWallet.js

A more civilized DASH Wallet SDK for a less civilized age...

Table of Contents

  • Install
    • Web Browsers
    • Node.js & Bundlers
  • Usage
  • API

Install

Web Browsers

<script src="https://unpkg.com/@dashincubator/secp256k1@1.x/secp256k1.js"></script>
<script src="https://unpkg.com/dashkeys@1.x/dashkeys.js"></script>
<script src="https://unpkg.com/dashsight@1.x/dashsight.js"></script>
<script src="https://unpkg.com/dashsight@1.x/dashsocket.js"></script>
<script src="https://unpkg.com/dashtx@0.x/dashtx.js"></script>
<script src="https://unpkg.com/dashwallet@0.5/dashwallet.js"></script>

Node.js & Bundlers

  1. Install node

    # Mac, Linux
    curl -sS https://webi.sh/node | sh
    
    # Windows
    curl.exe https://webi.ms/node | powershell
  2. Install the dashwallet library

    npm install --save dashwallet0.5
    npm install --save @dashincubator/secp256k1@1.7
  3. Install dashwallet-cli for testing locally

    npm install --location=global dashwallet-cli@0.5

Usage

// TODO
// (look at dashwallet-cli to see current usage)

Alpha API (will change)

Wallet.create(config)

Creates a wallet instance with the given config

  • DashSight adapter - or any interface matching:
    • getTxs(addr, page)
    • getUtxos(addr)
    • instantSend(txHex)
  • safe
    • wallets
    • addresses
  • Storage adapter
    • save() storage adapter (and "safe").
let w = await Wallet.create({ storage, safe, dashsight });

Wallet.generate(walletInfo)

Generates a complete PrivateWallet object.

Wallet.generate({
  name: "main",
  label: "Main",
  priority: 1, // lower sorts higher
});
{
  "name": "main",
  "label": "Main",
  "device": null,
  "contact": null,
  "priority": 1,
  "phrase": "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong",
  "created_at": "2022-02-22T22:02:22.000Z",
  "archived_at": null
}

Wallet.generateAddress(addrInfo)

Generates a complete addrInfo object.

Wallet.generateAddress({
  wallet: "main",
  hdpath: "m/44'/5'/0'/0",
  index: 0,
});
{
  "checked_at": 0,
  "hdpath": "m/44'/5'/0'/0",
  "index": 0,
  "txs": [],
  "utxos": [],
  "wallet": "main"
}

Wallet.generatePayWallet(walletInfo)

Generates a complete PayWallet object.

{
  "name": "@johndoe",
  "label": "@johndoe",
  "device": null,
  "contact": "@johndoe",
  "priority": 1668919000655,
  "xpub": "xpubXXXX...XXXX",
  "address": "Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "created_at": "2022-02-22T22:02:22.000Z",
  "archived_at": null
}

Wallet#balances()

Show spendable duffs / satoshis per each wallet.

You may need to await wallet.sync() first.

await wallet.balances();
{
  "main": 1212000,
  "@johndoe:1": 120000
}

Wallet#befriend(friendDetails)

Generate or show an xpub for your contact, and import their xpub for you, if any.

await wallet.befriend({
  handle: "@johndoe",
  // optional (either or, not both)
  xpub: "<the-xpub-that-john-doe-gave-to-you>",
  addr: "<a-static-pay-addr-from-john-doe>",
});
["<xpub-YOU-should-give-to-john>", "xpub-JOHN-gave-to-you", "addr-from-JOHN"]

wallet.createTx(txOpts)

TODO: Creates a clean (fingerprint-free) transaction.

wallet.createDirtyTx(txOpts)

Creates a dirty (fingerprint) transaction (hex string) for the given amount to the given contact using utxos from across all PrivateWallets.

await wallet.createDirtyTx({ handle, amount, utxos });
{
  "hex": "abc123...",
  "utxos": [
    {
      "address": "...",
      "outputIndex": 0,
      "satoshis": 1000,
      "script": "...",
      "txId": "..."
    }
  ]
}

The result can be used with dashsight.instantSend(tx.hex).

wallet#findChangeWallet(friendOpts)

Finds your PrivateWallet for the given contact.

await wallet.findChangeWallet({ handle: "@johndoe" });

Returns a PrivateWallet, as described above.

wallet#findFriend(friendOpts)

Finds the xpub-only (pay-to, send-only) wallet for the given contact.

await wallet.findFriend({ handle: "@johndoe" });

Returns a PayWallet, as described above.

wallet#nextChangeAddr(friendOpts)

Find the next unused change address for the PrivateWallet associated with the given contact, or from the main wallet as a fallback.

await wallet.nextChangAddr({ handle: "@johndoe" });

Returns a PayAddr.

"Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

Wallet#sync(syncOpts)

(Re)index addresses for each wallet and fetch latest transactions for the next few addresses.

let now = Date.now();
let staletime = 60 * 1000; // 0 to force immediate sync
await wallet.sync({ now, staletime });

Wallet#utxos()

Get all utxos across all PrivateWallets.

await wallet.utxos();

The results are in dashcore/bitcore format:

[
 txId: '<hex-tx-id>',
 outputIndex: 0,
 address: "Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 script: 'xxxx...',
 satoshis: 100000000
]

There's no response, just updates to safe.addresses, and store.save() will be called.

0.7.1

1 month ago

0.7.0

1 month ago

0.7.0-1

2 months ago

0.7.0-0

2 months ago

0.6.1

3 months ago

0.6.0

11 months ago

0.3.0

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.5

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.2.2

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago