1.1.0 • Published 2 years ago
@root/merchant-wallet v1.1.0
Merchant Wallet
HD Wallet + QR Code Generator
Generate secure (unique) per-customer Payment Addresses (PubKeyHash) and QR Codes for receiving payments via Digital Cash (Dash, or similar).
====== [DASH] (Derived) Public Key Hash ======
DASH: XcsLKywcU85QginxhJNYibJc3j4Aawa41Q
Use this library and included tools to generate a private key, and an "extended" public key, which will allow you to create payment addresses on your server without storing your private key on your server.
Watch the Video
Features
- QuickStart
- Get a Wallet and "Extended" Public Key
- Generate Payment QR Codes
- Generate WIFs & QR Codes \ (for importing private keys)
- Config
- Generate Passphrase
- Generate XPub Key
- Tools for Exploring & Debugging
- Payment Addresses via Private Key & XPub Key
- QR Codes for Payment Addresses
- QR Codes (WIF) for Payment import
Usage & QuickStart
npm install --save @root/merchant-wallet
Create XPub Key
"use strict";
require("dotenv").config({ path: ".env" });
require("dotenv").config({ path: ".env.secret" });
let Coins = require("@root/merchant-wallet/lib/coins.json");
let Wallet = require("@root/merchant-wallet").Wallet;
let wallet = Wallet.create(Coins.dash);
// The mnemonic *is* the wallet, more or less
// (it can be used by any wallet app)
let mnemonic = process.env.BASE2048_PASSPHRASE;
let xpubkey = await wallet.xpubKeyFromMnemonic(mnemonic);
Generate Payment Addrs & QR Codes
let index = 0;
let amount = 0.01;
let paymentAddr = await wallet.addrFromXPubKey(xpubKey, index);
let qr = await wallet.qrFromXPubKey(xpubKey, index, amount, { format: "svg" });
let qrAscii = await wallet.qrFromXPubKey(xpubKey, index, amount, {
format: "ascii",
});
console.info(`Wallet Import Format for Private Key:\n${wifQrAscii}`);
console.info(`${wif}`);
Generate Private Key WIFs & QR Codes
let index = 0;
let wif = await wallet.wifFromMnemonic(mnemonic, index);
let wifQr = await wallet.wifQrFromMnemonic(mnemonic, index, {
format: "svg",
});
let wifQrAscii = await wallet.wifQrFromMnemonic(mnemonic, index, {
format: "ascii",
});
console.info(`Wallet Import Format for Private Key:\n${wifQrAscii}`);
console.info(`${wif}`);
Config
See ./example.env.
- Add your wallet passphrase (mnemonic) to
.env.secret
asBASE2048_PASSPHRASE
, or generate a new one:bash bin/mnemonic-to-secret-env.sh
- Add your xpub (extended public) key to
.env
asXPUB_KEY
, or generate it from the existing ENVs:bash bin/xpubkey-to-env.sh
Examples
.env
:
WALLET_TYPE=dash
XPUB_KEY=xpub6EVfukfarxzs7NhxQbMQybLvsfLDEYrex5SdDsEuZ7oddnPxaLSW4wX9ZAR5zVYSFnxAum6oiSH4CYmLvJrpe75NXNnVuyWGoz9vdNcwGVJ
.env.secret
:
BASE2048_PASSPHRASE="peanut valley bargain affair zebra antenna govern bind myth doll weekend elbow"
Exploring & Debugging
git clone https://github.com/therootcompany/merchant-wallet.js.git
pushd ./merchant-wallet.js/
Passphrase (mnemonic) + Extended Public Key (xpub)
# Create a passphrase / mnemonic
bash bin/mnemonic-to-secret-env.sh
# See derived keys
node bin/derive-xpub-key.js
Generate Payment Addresses & QR Codes
index
should start from 0 and count up sequentiallyamount
is optional for Dash
# node bin/addr-from-xpub.js <customer-index> <amount>
node bin/addr-from-xpub.js 0
Generate Wallet Import Addresses & QR Codes
From the Dash app you can choose "Send" to scan a wallet (private key) and send the money to your primary wallet.
node bin/wif-from-mnemonic.js 0