New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tokel/bitgo-komodo-cc-lib

Package Overview
Dependencies
Maintainers
2
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tokel/bitgo-komodo-cc-lib - npm Package Compare versions

Comparing version 0.1.16 to 0.1.17

61

cc/ccutils.js

@@ -27,2 +27,4 @@ /**

exports.getCCUtxos = getCCUtxos;
exports.getUtxos = getUtxos;
exports.getTxids = getTxids;
exports.hex2Base64 = hex2Base64;

@@ -205,6 +207,14 @@ exports.byte2Base64 = byte2Base64;

function getUtxos(peers, address, isCC)
/**
* returns utxos for an address
* @param {*} peers PeerGroup object with NspvPeers ext
* @param {*} address address to get utxos from
* @param {*} isCC if 1 get cc or if 0 get normal utxos
* @param {*} skipCount number of utxo to skip
* @param {*} filter unused must be 0
*/
function getUtxos(peers, address, isCC, skipCount, filter)
{
return new Promise((resolve, reject) => {
peers.nspvGetUtxos(address, isCC, {}, (err, res, peer) => {
peers.nspvGetUtxos(address, isCC, skipCount, filter, {}, (err, res, peer) => {
//console.log('err=', err, 'res=', res);

@@ -220,2 +230,23 @@ if (!err)

/**
* returns txids for an address
* @param {*} peers PeerGroup object with NspvPeers additions
* @param {*} address address to get txids from
* @param {*} isCC get txids with normal (isCC is 0) or cc (isCC is 1) utxos on this address
* @param {*} skipCount number of txids to skip
* @param {*} filter unused must be 0
*/
function getTxids(peers, address, isCC, skipCount, filter)
{
return new Promise((resolve, reject) => {
peers.nspvGetTxids(address, isCC, skipCount, filter, {}, (err, res, peer) => {
//console.log('err=', err, 'res=', res);
if (!err)
resolve(res);
else
reject(err);
});
});
}
/**
*

@@ -261,3 +292,3 @@ * @param {*} peers PeerGroup object with NspvPeers ext

return getUtxos(peers, address, false);
return getUtxos(peers, address, 0);
}

@@ -274,3 +305,3 @@ /**

return getUtxos(peers, address, true);
return getUtxos(peers, address, 1);
}

@@ -344,6 +375,3 @@ /**

if (Buffer.isBuffer(txid)) {
let reversed = Buffer.allocUnsafe(txid.length);
txid.copy(reversed);
bufferutils.reverseBuffer(reversed);
txidhex = reversed.toString('hex');
txidhex = txidToHex(txid);
}

@@ -484,2 +512,19 @@ else

exports.txidReverse = txidReverse;
/**
* reverse txid, this is used by cc modules to write txid in opreturn (for readability)
* @param {string} txid
* @returns {Buffer} reversed txid as Buffer or empty Buffer
*/
function txidReverse(txid)
{
if (txid.length > 0) {
let reversed = Buffer.allocUnsafe(txid.length);
txid.copy(reversed);
bufferutils.reverseBuffer(reversed);
return reversed;
}
return Buffer.from([]);
}
exports.toSatoshi = function (val) {

@@ -486,0 +531,0 @@ if (typeof val !== 'number')

54

net/kmdtypes.js

@@ -244,2 +244,3 @@ 'use strict'

NSPV_BROADCAST: 0x0c,
NSPV_TXIDS: 0x0e,
NSPV_REMOTERPC: 0x14 // 0x15 for varbuffer experimental version in faucet-nspv-ext

@@ -252,2 +253,3 @@ };

NSPV_BROADCASTRESP: 0x0d,
NSPV_TXIDSRESP: 0x0f,
NSPV_REMOTERPCRESP: 0x15, // 0x16 is varbuffer, decided not use i on client side

@@ -262,5 +264,5 @@ };

let utxoreq = struct([
let utxosreq = struct([
{ name: 'reqCode', type: struct.UInt8 },
{ name: 'coinaddr', type: struct.VarString(varint, 'ascii') }, // TODO or simply UInt8 as komodod currently checks only 1 byte len
{ name: 'coinaddr', type: struct.VarString(struct.UInt8, 'ascii') }, // simply UInt8 as komodod currently checks only 1 byte len
{ name: 'CCflag', type: struct.UInt8 },

@@ -271,3 +273,3 @@ { name: 'skipcoint', type: struct.UInt32LE },

let utxoresp = struct([
let utxosresp = struct([
{ name: 'respCode', type: struct.UInt8 },

@@ -291,4 +293,3 @@ {

{ name: 'skipcount', type: struct.UInt32LE },
{ name: 'bufCoinaddr', type: bufferaddr }
{ name: 'coinaddr', type: bufferaddr }
]);

@@ -368,20 +369,31 @@

/* if varBuffe is supported on the nspv server side, see the 'faucet-nspv-ext' experimental branch
let nspvRemoteRpc = struct([
let txidsreq = struct([
{ name: 'reqCode', type: struct.UInt8 },
{ name: 'jsonSer', type: exports.varBuffer }
{ name: 'coinaddr', type: struct.VarString(struct.UInt8, 'ascii') }, // simply UInt8 as komodod currently checks only 1 byte len
{ name: 'CCflag', type: struct.UInt8 },
{ name: 'skipcoint', type: struct.UInt32LE },
{ name: 'filter', type: struct.UInt32LE }
]);
let nspvRemoteRpcResp = struct([
let txidsresp = struct([
{ name: 'respCode', type: struct.UInt8 },
{ name: 'method', type: methodtype },
{ name: 'jsonSer', type: exports.varBuffer }
{
name: 'txids',
type: struct.VarArray(struct.UInt16LE, struct([
{ name: 'txid', type: exports.buffer32 },
{ name: 'satoshis', type: struct.UInt64LE },
{ name: 'vout', type: struct.UInt32LE },
{ name: 'height', type: struct.UInt32LE },
]))
},
{ name: 'nodeheight', type: struct.UInt32LE },
{ name: 'filter', type: struct.UInt32LE },
{ name: 'CCflag', type: struct.UInt16LE },
{ name: 'skipcount', type: struct.UInt32LE },
{ name: 'coinaddr', type: bufferaddr }
]);
*/
// custom parse rempte rpc req/resp as varBuffer is not supported on the server side
// custom parse for txproof rpc req/resp as varBuffer is not supported on the server side
let nspvTxproof = (function(){
function encode(value, buffer, offset) {
typeforce({ reqCode: 'Number', height: 'Number', vout: 'Number', txid: types.Buffer256bit, }, value)
let bufferWriter = new bufferutils.BufferWriter(buffer, offset);

@@ -423,3 +435,3 @@ bufferWriter.writeUInt8(value.reqCode);

return { respCode: respCode, txid: txid, unspentValue: unspentValue, height: height, vout: vout, tx: txbuf, txproof: txproofbuf };
return { respCode: respCode, txid: txid, unspentValue: unspentValue, height: height, vout: vout, txbin: txbuf, txproof: txproofbuf };
}

@@ -448,3 +460,3 @@ return { encode, decode, encodingLength }

case NSPVREQ.NSPV_UTXOS:
type = utxoreq;
type = utxosreq;
break;

@@ -457,2 +469,5 @@ case NSPVREQ.NSPV_BROADCAST:

break;
case NSPVREQ.NSPV_TXIDS:
type = txidsreq;
break;
case NSPVREQ.NSPV_REMOTERPC:

@@ -506,3 +521,3 @@ type = nspvRemoteRpc;

case NSPVRESP.NSPV_UTXOSRESP:
type = utxoresp;
type = utxosresp;
break;

@@ -515,2 +530,5 @@ case NSPVRESP.NSPV_BROADCASTRESP:

break;
case NSPVRESP.NSPV_TXIDSRESP:
type = txidsresp;
break;
case NSPVRESP.NSPV_REMOTERPCRESP:

@@ -517,0 +535,0 @@ type = nspvRemoteRpcResp;

@@ -12,2 +12,3 @@ 'use strict'

const { NSPVREQ, NSPVRESP, nspvReq, nspvResp } = require('./kmdtypes');
const { txidFromHex, txidToHex } = require('../cc/ccutils');

@@ -24,3 +25,3 @@ Peer.prototype._registerListenersPrev = Peer.prototype._registerListeners;

// nspv get utxos
Peer.prototype.nspvGetUtxos = function(address, isCC, opts, cb) {
Peer.prototype.nspvGetUtxos = function(address, isCC, skipCount, filter, opts, cb) {
if (typeof opts === 'function') {

@@ -44,4 +45,4 @@ cb = opts

CCflag: isCC ? 1 : 0,
skipcount: 0,
filter: 0
skipcount: skipCount,
filter: filter
}

@@ -60,2 +61,37 @@ let buf = nspvReq.encode(nspvReqUtxos)

// nspv get txids
Peer.prototype.nspvGetTxids = function(address, isCC, skipCount, filter, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = {}
}
if (opts.timeout == null) opts.timeout = this._getTimeout()
var timeout
var onNspvResp = (resp) => {
if (timeout) clearTimeout(timeout)
cb(null, resp)
//this._nextHeadersRequest() // TODO: do we also need call to next?
}
this.once(`nSPV:${NSPVRESP.NSPV_TXIDSRESP}`, onNspvResp)
let nspvReqTxids = {
reqCode: NSPVREQ.NSPV_TXIDS,
coinaddr: address,
CCflag: isCC ? 1 : 0,
skipcount: skipCount,
filter: filter
}
let buf = nspvReq.encode(nspvReqTxids)
this.send('getnSPV', buf)
if (!opts.timeout) return
timeout = setTimeout(() => {
errorlog(`getnSPV NSPV_TXIDSRESP timed out: ${opts.timeout} ms`)
var error = new Error('Request timed out')
error.timeout = true
cb(error)
}, opts.timeout)
}
// call nspv remote rpc

@@ -109,3 +145,3 @@ Peer.prototype.nspvRemoteRpc = function(rpcMethod, _mypk, _params, opts, cb) {

if (result.result !== undefined && result.result.error) {
cb(new Error('nspv remote error' + result.result.error));
cb(new Error(`nspv remote error: ${result.result.error}`));
return;

@@ -171,6 +207,3 @@ }

}
let reversed = Buffer.allocUnsafe(resp.txid.length);
resp.txid.copy(reversed);
bufferutils.reverseBuffer(reversed);
cb(null, { retcode: resp.retcode, txid: reversed.toString('hex') });
cb(null, { retcode: resp.retcode, txid: txidToHex(resp.txid) });
}

@@ -181,3 +214,3 @@ this.once(`nSPV:${NSPVRESP.NSPV_BROADCASTRESP}`, onNspvResp)

reqCode: NSPVREQ.NSPV_BROADCAST,
txid: Buffer.from(txidhex, 'hex'),
txid: txidFromHex(txidhex),
txdata: Buffer.from(txhex, 'hex')

@@ -197,2 +230,55 @@ }

// nspv broadcast
Peer.prototype.nspvTxproof = function(txidhex, vout, height, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = {}
}
if (!opts.timeout) opts.timeout = this._getTimeout()
if (typeof txidhex !== 'string' || txidhex.length != 64) {
cb(new Error('txid hex should be a string of 64'));
return;
}
if (typeof vout !== 'number') {
cb(new Error('vout not a number'));
return;
}
if (typeof height !== 'number') {
cb(new Error('vout not a number'));
return;
}
var timeout
var onNspvResp = (resp) => {
if (timeout) clearTimeout(timeout)
if (!resp || !resp.respCode || typeof resp.txid === undefined || typeof resp.unspentValue === undefined || typeof resp.vout === undefined || typeof resp.height === undefined || typeof resp.tx === undefined || typeof resp.txproof === undefined) { // check all props?
cb(new Error("could not parse nspv txproof response"));
return;
}
cb(null, { retcode: resp.retcode, txid: txidToHex(resp.txid), unspentValue: resp.unspentValue, height: resp.height, vout: resp.vout, txbin: resp.txbin, txproof: resp.txproof });
}
this.once(`nSPV:${NSPVRESP.NSPV_TXPROOFRESP}`, onNspvResp)
let nspvTxproofReq = {
reqCode: NSPVREQ.NSPV_TXPROOF,
txid: txidFromHex(txidhex),
vout: vout,
height: height,
}
let buf = nspvReq.encode(nspvTxproofReq)
this.send('getnSPV', buf)
if (!opts.timeout) return
timeout = setTimeout(() => {
errorlog(`getnSPV NSPV_TXPROOF timed out: ${opts.timeout} ms`)
var error = new Error('Request timed out')
error.timeout = true
cb(error)
}, opts.timeout)
}

@@ -26,6 +26,10 @@ 'use strict'

PeerGroup.prototype.nspvGetUtxos = function(address, isCC, opts, cb) {
this._request('nspvGetUtxos', address, isCC, opts, cb)
PeerGroup.prototype.nspvGetUtxos = function(address, isCC, skipCount, filter, opts, cb) {
this._request('nspvGetUtxos', address, isCC, skipCount, filter, opts, cb)
}
PeerGroup.prototype.nspvGetTxids = function(address, isCC, skipCount, filter, opts, cb) {
this._request('nspvGetTxids', address, isCC, skipCount, filter, opts, cb)
}
PeerGroup.prototype.nspvRemoteRpc = function(rpcMethod, mypk, params, opts, cb) {

@@ -39,2 +43,6 @@ this._request('nspvRemoteRpc', rpcMethod, mypk, params, opts, cb)

PeerGroup.prototype.nspvTxproof = function(txidhex, vout, height, opts, cb) {
this._request('nspvTxproof', txidhex, vout, height, opts, cb)
}
module.exports = old(NspvPeerGroup)
{
"name": "@tokel/bitgo-komodo-cc-lib",
"version": "0.1.16",
"version": "0.1.17",
"description": "Client-side Bitcoin JavaScript library with Komodo cryptocondions support",

@@ -39,2 +39,3 @@ "main": "./src/index.js",

"dependencies": {
"@tokel/cryptoconditions": "0.1.0",
"bech32": "0.0.3",

@@ -53,3 +54,2 @@ "bigi": "1.4.2",

"create-hmac": "^1.1.3",
"cryptoconditions-js": "@tokel/cryptoconditions",
"debug": "~3.1.0",

@@ -56,0 +56,0 @@ "ecurve": "^1.0.0",

@@ -24,6 +24,6 @@ /*

ZEC: 'zec',
DASH: 'dash'
}
DASH: 'dash',
};
function getDefaultBip32Mainnet () {
function getDefaultBip32Mainnet() {
return {

@@ -33,7 +33,7 @@ // base58 'xpub'

// base58 'xprv'
private: 0x0488ade4
}
private: 0x0488ade4,
};
}
function getDefaultBip32Testnet () {
function getDefaultBip32Testnet() {
return {

@@ -43,7 +43,7 @@ // base58 'tpub'

// base58 'tprv'
private: 0x04358394
}
private: 0x04358394,
};
}
module.exports = {
module.exports = {
// https://github.com/bitcoin/bitcoin/blob/master/src/validation.cpp

@@ -58,3 +58,3 @@ // https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp

wif: 0x80,
coin: coins.BTC
coin: coins.BTC,
},

@@ -68,3 +68,3 @@ testnet: {

wif: 0xef,
coin: coins.BTC
coin: coins.BTC,
},

@@ -81,3 +81,3 @@

coin: coins.BCH,
forkId: 0x00
forkId: 0x00,
},

@@ -90,3 +90,3 @@ bitcoincashTestnet: {

wif: 0xef,
coin: coins.BCH
coin: coins.BCH,
},

@@ -104,3 +104,3 @@

coin: coins.BTG,
forkId: 0x4F /* 79 */
forkId: 0x4f /* 79 */,
},

@@ -118,3 +118,3 @@ // bitcoingoldTest: TODO

coin: coins.BSV,
forkId: 0x00
forkId: 0x00,
},

@@ -127,3 +127,3 @@ bitcoinsvTestnet: {

wif: 0xef,
coin: coins.BSV
coin: coins.BSV,
},

@@ -139,3 +139,3 @@

wif: 0xcc,
coin: coins.DASH
coin: coins.DASH,
},

@@ -148,3 +148,3 @@ dashTest: {

wif: 0xef,
coin: coins.DASH
coin: coins.DASH,
},

@@ -161,3 +161,3 @@

wif: 0xb0,
coin: coins.LTC
coin: coins.LTC,
},

@@ -171,3 +171,3 @@ litecoinTest: {

wif: 0xef,
coin: coins.LTC
coin: coins.LTC,
},

@@ -191,5 +191,5 @@

// 4: 0x2bb40e60
4: 0xf5b9230b
4: 0xf5b9230b,
},
coin: coins.ZEC
coin: coins.ZEC,
},

@@ -208,5 +208,5 @@ zcashTest: {

// 4: 0x2bb40e60
4: 0xf5b9230b
4: 0xf5b9230b,
},
coin: coins.ZEC
coin: coins.ZEC,
},

@@ -224,3 +224,3 @@ dimxy19: {

3: 0x5ba81b19,
4: 0x76b809bb // (old Sapling branch id - used in kmd)
4: 0x76b809bb, // (old Sapling branch id - used in kmd)
// 4: 0x2bb40e60

@@ -231,3 +231,3 @@ // 4: 0xf5b9230b

komodoAssetNet: true,
magic: 0xb00668b4
magic: 0xb00668b4,
},

@@ -246,3 +246,3 @@

3: 0x5ba81b19,
4: 0x76b809bb // (old Sapling branch id - used in kmd)
4: 0x76b809bb, // (old Sapling branch id - used in kmd)
// 4: 0x2bb40e60

@@ -253,3 +253,3 @@ // 4: 0xf5b9230b

komodoAssetNet: true,
magic: 0x09262b14
magic: 0x09262b14,
},

@@ -268,3 +268,3 @@

3: 0x5ba81b19,
4: 0x76b809bb // (old Sapling branch id, used in kmd)
4: 0x76b809bb, // (old Sapling branch id, used in kmd)
// 4: 0x2bb40e60

@@ -275,3 +275,3 @@ // 4: 0xf5b9230b

komodoAssetNet: true,
magic: 0xfd750df6
magic: 0xfd750df6,
},

@@ -290,3 +290,3 @@

3: 0x5ba81b19,
4: 0x76b809bb // (old Sapling branch id - used in kmd)
4: 0x76b809bb, // (old Sapling branch id - used in kmd)
// 4: 0x2bb40e60

@@ -297,3 +297,3 @@ // 4: 0xf5b9230b

komodoAssetNet: true,
magic: 0xf4b89a4f
magic: 0xf4b89a4f,
},

@@ -312,3 +312,3 @@

3: 0x5ba81b19,
4: 0x76b809bb // (old Sapling branch id - used in kmd)
4: 0x76b809bb, // (old Sapling branch id - used in kmd)
// 4: 0x2bb40e60

@@ -319,5 +319,25 @@ // 4: 0xf5b9230b

komodoAssetNet: true,
magic: 0x902f7aae
magic: 0x902f7aae,
},
dimxy24: {
messagePrefix: '\x18DIMXY24 asset chain:\n',
bech32: 'R',
bip32: getDefaultBip32Mainnet(),
pubKeyHash: 0x3c,
scriptHash: 0x55,
wif: 0xbc,
consensusBranchId: {
1: 0x00,
2: 0x00,
3: 0x5ba81b19,
4: 0x76b809bb, // (old Sapling branch id - used in kmd)
// 4: 0x2bb40e60
// 4: 0xf5b9230b
},
coin: coins.ZEC,
komodoAssetNet: true,
magic: 0x0e4bef0d,
},
dimxy25: {

@@ -334,3 +354,3 @@ messagePrefix: '\x18DIMXY25 asset chain:\n',

3: 0x5ba81b19,
4: 0x76b809bb // (old Sapling branch id - used in kmd)
4: 0x76b809bb, // (old Sapling branch id - used in kmd)
// 4: 0x2bb40e60

@@ -341,3 +361,3 @@ // 4: 0xf5b9230b

komodoAssetNet: true,
magic: 0x794cdf9b // 0x9bdf4c79
magic: 0x794cdf9b, // 0x9bdf4c79
},

@@ -356,3 +376,3 @@

3: 0x5ba81b19,
4: 0x76b809bb // (old Sapling branch id - used in kmd)
4: 0x76b809bb, // (old Sapling branch id - used in kmd)
// 4: 0x2bb40e60

@@ -363,4 +383,24 @@ // 4: 0xf5b9230b

komodoAssetNet: true,
magic: 0xf6475548
magic: 0xf6475548,
},
}
tokel: {
messagePrefix: '\x18TOKEL chain:\n',
bech32: 'R',
bip32: getDefaultBip32Mainnet(),
pubKeyHash: 0x3c,
scriptHash: 0x55,
wif: 0xbc,
consensusBranchId: {
1: 0x00,
2: 0x00,
3: 0x5ba81b19,
4: 0x76b809bb, // (old Sapling branch id - used in kmd)
// 4: 0x2bb40e60
// 4: 0xf5b9230b
},
coin: coins.ZEC,
komodoAssetNet: true,
magic: 0x86c2fdd0,
},
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc