New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dapsjs

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dapsjs

JavaScript library for the creation, scanning and sending of DAPS privacy coins

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

DAPSJS

NodeJS library for making DAPS privacy transactions

API Call List:

RequestResponse
DescriptionsVerbURI PrefixMethodParams
Requests API to scan for utxos and return thempostwalletscanviewkey:${viewkey} spendpub:${pubspenkey} sinceblock: ${sinceblock} filterspents: true/false => true means only return unspent utxos"scanning": false, "scannedheight": 477302, "utxos": [keyimage],"txes": { "keyimage": { "vin": [], "vout": [], "blockindex": 476098, "blocktime": 1592551400, "txfee": 1.496, "ringsize": 13, "_id": "5eec67d9824cf9f9a0195dd8", "txid": "keyimage", "__v": 0, "blockhash": "36540454e15e8a4fc20311feff8e4084e14fb532a855a70a43cbb2beeaca5e76", "type": "standard" } },
Requests the last scanned height for the key pairpostwalletgetscannedheightviewkey:${viewkey} spendpub:${pubspenkey}
getapikeyimages${keyimages}{"spents":[],"unspents":["13a3caf5416c349f362735b70b6a2f63c2f94fca9ce2bbfb70848d3f102cb054"]}
Get the latest API block heightgetapiblockcount
Get decoys from the APIgetapidecoys$(number)
Generates the bulletproof for the given paramsgetapibulletproofs${bpinputSerializedHex}
Broadcasts the raw transactionpostapibroadcasttx${rawSignedTx}
server public key for encrypting view key and spend public keygetapigetencryptionkey
Allows utxo's to be added to the APIpostwalletaddutxosviewkey:${viewkey} spendpub:${pubspenkey} scannedheight: ${scannedheight} utxos: string in format txid-index:txid-index...
Marks the given utxos as spent in the APIPostwalletmarkspentsviewkey:${viewkey} spendpub:${pubspenkey} spents: string in format txid-index:txid-index...

Note: You must obtain API info and Server Encryption Key from the DAPS team to be able to access the API. These are placed in the src/dapslib/config.js.

Usage

  • Create a wallet object from mnemonics
const Wallet = require('dapsjs').Wallet;
const config = require('dapsjs').Constants;
var walletObject = new Wallet({mnemonics: mnemonics.mnemonics}, config.DAPS_SERVER, config.DAPSCHAIN, "Bitcoin seed");

Once wallet object created, then it will automatically send requests to the RPC server to scan for all transactions belonging to the wallet.

  • Get wallet balances: wallet balances are only available (and correct) if and only if the transaction scanning is finished.
function getBalance(wl) {
   if (wl.isScanning) return 'wallet is scanning';
   return {spendable: wl.spendable, immature: wl.immature, pending: wl.pending}
}

Note that wl.isScanning should be always false, except if the user is logging-in the wallet, which might take from 5 second to 1 minute to finishn scanning, depending whether the user log-in the wallet previously or not.

Wallet will periodically send request to the server every minute to scan for new wallet transactions.

For third-party integration, nothing needs to be done except initialize the wallet object and uses it to show information on the apps of the third-parties.

  • Get the current block height:
wl.currentBlockHeight
  • Create transaction and broadcast it:
walletObject.sendTo(destination, amount, function(ret) {
  if (ret.success) {
    state.txCreateResult = {success: true, message: "Successfully create transaction " + ret.txid + " sending " + input.amount + " to " + input.destination};
  } else {
    state.txCreateResult = {success: false, message: "Error:" + ret.reason};
  }
  walletObject.recomputeBalance();
})

** destination: the receiver address ** amount: amount to send. Amount should be in decimal string

It is worth noting that the wallet object will manage and recompute balances so that third-parties only need to inject the wallet object in their app.

API "sinceblock" Parameter Usage

  • Server has already seen the key:
    • sinceBlock = XXX => Server scans from the scanned height stored in the server and return all utxos in block > XXX
  • Server has never seen the key:
    • sinceBlock = 0 => Server scans the entire chain and returns all utxos found
    • sinceBlock = XXX => Server scan all blocks > XXX and returns all utxos included in blocks > XXX

If it’s a new wallet, you would only need to set sinceBlock = the currentBlock height => done!

EncryptedViewKey and EncryptedSpendPub

  • Call getencryptionkey from API to get the public key of the server to encrypt view key and public spend key => EncryptionKey
  • Encryption:
    • Generate random r (32 bytes), compute R = r*G
    • Compute ECDH = Hash(r*EncryptionKey)
    • Compute encryptedviewkey = viewkey + ECDH
    • Compute encryptedspendpub
      • X = X of public spend key
      • EncryptedX = X + ECDH
      • encryptedspendpub = EncryptedX|| (03|02)
  • Send to server: {method=.., encryptedviewkey=encryptedviewkey, encryptedspendpub=encryptedspendpub, encrypted=true}

Note: r in the request sent to server is R in the formulae

DAPSJS Statuses / Status Values (currentStatus/currentStatusVal)

Statuses have been added to keep the user up to date as to what the wallet is currently doing. Each status also has a corresponding currentStatusVal integer that can be accessed as well.

  • Idle - 1 - Starting state
  • Scanning - 2 - When the wallet is scanning for UTXOs belonging to a restored phrase
  • Processing UTXOs - 3 - Taking the UTXOs that were scanned and processing them all
  • Generating transaction history - 4 - Creation of the transaction history from scanned UTXOs
  • Recomputing wallet balance - 5 - Recomputing wallet balance
  • Complete - 6 - The process is complete

Get the current Status:

wl.currentStatus

Get the current StatusVal:

wl.currentStatusValue

Basic Test

Requires

  • node.js
  • Mnemonic Recovery Phrase
  • DAPS

Start Testing

  • Create a new wallet
  • Write down the Mnemonic Recovery Phrase
  • Send some coins (minimum 5 DAPS recommended)
  • Add the Mnemonic Recovery Phrase on \tests\wallet\createwallet.js
  • Edit the amount of DAPS to send on \tests\wallet\createwallet.js
  • Run npm install
  • Edit src/dapslib/config.js with the required information
  • Run npm run tests

Keywords

DAPS

FAQs

Package last updated on 15 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts