Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dashsight

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dashsight - npm Package Compare versions

Comparing version 1.4.0-0 to 1.4.0-1

dashfetch.js

20

bin/create-tx.js

@@ -26,3 +26,3 @@ #!/usr/bin/env node

});
let BlockTx = require("@dashincubator/blocktx");
let DashTx = require("dashtx");
let RIPEMD160 = require("@dashincubator/ripemd160");

@@ -34,3 +34,3 @@ let Secp256k1 = require("@dashincubator/secp256k1");

/**
* @param {import('@dashincubator/blocktx').TxSignOpts} opts
* @param {import('dashtx').TxSignOpts} opts
*/

@@ -40,27 +40,23 @@ async function signTx({ privateKey, hash }) {

let sigBuf = await Secp256k1.sign(hash, privateKey, sigOpts);
return BlockTx.utils.u8ToHex(sigBuf);
return sigBuf;
}
/**
* @param {import('@dashincubator/blocktx').TxPrivateKey} privBuf
* @param {import('dashtx').TxPrivateKey} privBuf
*/
function toPublicKey(privBuf) {
let isCompressed = true;
let pubKey = Secp256k1.getPublicKey(privBuf, isCompressed);
return pubKey;
let pubBuf = Secp256k1.getPublicKey(privBuf, isCompressed);
return pubBuf;
}
/**
* @param {import('@dashincubator/blocktx').TxPublicKey} pubBuf
* @param {import('dashtx').TxPublicKey} pubBuf
*/
async function hashPublicKey(pubBuf) {
//console.log("DEBUG pubBuf", pubBuf);
let sha = await Crypto.subtle.digest("SHA-256", pubBuf);
let shaU8 = new Uint8Array(sha);
//console.log("DEBUG shaU8", shaU8);
let ripemd = RIPEMD160.create();
let hash = ripemd.update(shaU8);
//console.log("DEBUG hash", hash);
let pkh = hash.digest("hex");
//console.log("DEBUG pkh", pkh);
return pkh;

@@ -166,3 +162,3 @@ }

let dashTx = BlockTx.create({
let dashTx = DashTx.create({
version: 3,

@@ -169,0 +165,0 @@ //@ts-ignore

51

dashsight.js

@@ -9,3 +9,3 @@ (function (exports) {

//@ts-ignore
let request = exports.__dashsight_request || require("./lib/request.js");
const dashfetch = exports.__dashsight_fetch || require('./dashfetch.js')

@@ -77,3 +77,3 @@ const DUFFS = 100000000;

let txUrl = `${insightBaseUrl}/addr/${address}/?noTxList=1`;
let txResp = await request({ url: txUrl, json: true });
let txResp = await dashfetch(txUrl);

@@ -88,3 +88,3 @@ /** @type {InsightBalance} */

let utxos = await insight.getUtxos(address);
let balanceDuffs = utxos.reduce(function (total, utxo) {
let balanceDuffs = utxos?.reduce(function (total, utxo) {
return total + utxo.satoshis;

@@ -110,6 +110,6 @@ }, 0);

let utxoUrl = `${insightBaseUrl}/addr/${address}/utxo`;
let utxoResp = await request({ url: utxoUrl, json: true });
let utxoResp = await dashfetch(utxoUrl);
/** @type Array<InsightUtxo> */
let utxos = utxoResp.body;
let utxos = await utxoResp.json();
return utxos;

@@ -133,6 +133,6 @@ };

let txUrl = `${insightBaseUrl}/tx/${txid}`;
let txResp = await request({ url: txUrl, json: true });
let txResp = await dashfetch(txUrl);
/** @type InsightTx */
let data = txResp.body;
let data = await txResp.json();
return data;

@@ -144,6 +144,6 @@ };

let txUrl = `${insightBaseUrl}/txs?address=${addr}&pageNum=0`;
let txResp = await request({ url: txUrl, json: true });
let txResp = await dashfetch(txUrl);
/** @type {InsightTxResponse} */
let body = txResp.body;
let body = await txResp.json();

@@ -162,9 +162,9 @@ let data = await getAllPages(body, addr, maxPages);

for (let cursor = 1; cursor < pagesTotal; cursor += 1) {
let nextResp = await request({
url: `${insightBaseUrl}/txs?address=${addr}&pageNum=${cursor}`,
json: true,
});
let nextResp = await dashfetch(
`${insightBaseUrl}/txs?address=${addr}&pageNum=${cursor}`);
nextResp = await nextResp.json();
// Note: this could still be wrong, but I don't think we have
// a better way to page so... whatever
body.txs = body.txs.concat(nextResp.body.txs);
// @ts-ignore
body.txs = body.txs.concat(nextResp?.txs);
}

@@ -180,11 +180,5 @@ return body;

let instUrl = `${dashsightBaseUrl}/tx/sendix`;
let reqObj = {
let txResp = await dashfetch(instUrl, {
method: "POST",
url: instUrl,
json: true,
form: {
rawtx: hexTx,
},
};
let txResp = await request(reqObj);
});
if (!txResp.ok) {

@@ -194,6 +188,17 @@ // TODO better error check

}
return txResp.toJSON();
return txResp.json();
};
/** @type {ToCoreUtxo} */
insight.toCoreUtxo = function (utxo) {
return {
txId: utxo.txid,
outputIndex: utxo.vout,
address: utxo.address,
script: utxo.scriptPubKey,
satoshis: utxo.satoshis,
};
};
/** @type {ToCoreUtxo} */
insight.toCoreUtxo = Dashsight.toCoreUtxo;

@@ -200,0 +205,0 @@

@@ -204,4 +204,6 @@ (function (exports) {

let pingTimeout
let ws = await Eio3.connectWs(session.sid);
wsc._ws = ws;
ws._pingTimeout = null;

@@ -213,3 +215,3 @@ setPing();

function setPing() {
setTimeout(function () {
ws._pingTimeout = setTimeout(function () {
//ws.ping(); // standard

@@ -273,3 +275,4 @@ ws.send("2"); // socket.io

ws.onclose = null;
ws.removeEventListener(_onMessage);
ws.removeEventListener("message", _onMessage);
clearTimeout(ws._pingTimeout)
if (debug) {

@@ -376,2 +379,80 @@ console.debug("WebSocket Close");

};
// TODO waitForVouts(baseUrl, [{ address, satoshis }])
/**
* @param {String} dashsocketBaseUrl
* @param {String} addr
* @param {Number} [amount]
* @param {Number} [maxTxLockWait]
* @param {WsOpts} [opts]
* @returns {Promise<SocketPayment>}
*/
Ws.waitForVout = async function (
dashsocketBaseUrl,
addr,
amount = 0,
maxTxLockWait = 3000,
opts = {},
) {
if ("https://insight.dash.org" === dashsocketBaseUrl) {
dashsocketBaseUrl = "https://insight.dash.org/socket.io";
}
// Listen for Response
/** @type SocketPayment */
let mempoolTx;
return await Ws.listen(dashsocketBaseUrl, findResponse, opts);
/**
* @param {String} evname
* @param {InsightSocketEventData} data
*/
function findResponse(evname, data) {
if (!["tx", "txlock"].includes(evname)) {
return;
}
let now = Date.now();
if (mempoolTx?.timestamp) {
// don't wait longer than 3s for a txlock
if (now - mempoolTx.timestamp > maxTxLockWait) {
return mempoolTx;
}
}
let result;
// TODO should fetch tx and match hotwallet as vin
data.vout.some(function (vout) {
if (!(addr in vout)) {
return false;
}
let duffs = vout[addr];
if (amount && duffs !== amount) {
return false;
}
let newTx = {
address: addr,
timestamp: now,
txid: data.txid,
satoshis: duffs,
txlock: data.txlock,
};
if ("txlock" !== evname) {
if (!mempoolTx) {
mempoolTx = newTx;
}
return false;
}
result = newTx;
return true;
});
return result;
}
};
})(("undefined" !== typeof module && module.exports) || window);

@@ -112,3 +112,3 @@ "use strict";

/**
* @typedef InsightBalance
* @typedef {Object | null} InsightBalance
* @property {String} addrStr

@@ -115,0 +115,0 @@ * @property {Number} balance

{
"name": "dashsight",
"version": "1.4.0-0",
"version": "1.4.0-1",
"description": "SDK for Dash's flavor of the Insight API",

@@ -8,3 +8,3 @@ "main": "index.js",

"./ws/index.js": "./dashsocket.js",
"./lib/request.js": "./dashrequest.js"
"crypto": false
},

@@ -26,7 +26,6 @@ "bin": {

"bin",
"dashrequest.js",
"dashfetch.js",
"dashsight.js",
"dashsocket.js",
"index.js",
"lib",
"typings",

@@ -59,4 +58,3 @@ "ws"

"dependencies": {
"@dashincubator/blocktx": "^0.9.0-0",
"@root/request": "^1.9.2"
"dashtx": "^0.9.0-3"
},

@@ -63,0 +61,0 @@ "devDependencies": {

@@ -21,3 +21,4 @@ # [dashsight.js](https://github.com/dashhive/dashsight.js)

let dashsightBaseUrl =
process.env.DASHSIGHT_BASE_URL || "https://dashsight.dashincubator.dev/insight-api";
process.env.DASHSIGHT_BASE_URL ||
"https://dashsight.dashincubator.dev/insight-api";
let dashsocketBaseUrl =

@@ -265,3 +266,4 @@ process.env.DASHSOCKET_BASE_URL || "https://insight.dash.org/socket.io";

Gets all unspent transaction outputs (the usable "coins") for the given address,
including all information needed by `dashcore-lib.Transaction`.
including all information needed by `DashTx#hashAndSignAll()` (and
`dashcore-lib.Transaction`).

@@ -304,5 +306,41 @@ ```js

```js
let Dashcore = require("@dashevo/dashcore-lib");
let Transaction = Dashcore.Transaction;
"use strict";
let DashTx = require("dashtx");
let dashTx = DashTx.create({
version: 3,
sign: signTx,
toPublicKey: toPublicKey,
addrToPubKeyHash: addrToPubKeyHash,
});
async function signTx({ privateKey, hash }) {
let sigOpts = { canonical: true };
let sigBuf = await Secp256k1.sign(hash, privateKey, sigOpts);
return sigBuf;
}
async function toPublicKey(privKeyBuf) {
let Secp256k1 = require("@dashincubator/secp256k1");
let isCompressed = true;
let pubBuf = Secp256k1.getPublicKey(privKeyBuf, isCompressed);
return pubBuf;
}
async function addrToPubKeyHash(addr) {
let Base58Check = require("@dashincubator/base58check").Base58Check;
let b58c = Base58Check.create({
pubKeyHashVersion: "4c",
privateKeyVersion: "cc",
});
let parts = await b58c.verify(addr);
return parts.pubKeyHash;
}
// keys that correspond to the available utxos
let privateKeys = {
XmCyQ6qARLWXap74QubFMunngoiiA1QgCL: "YOUR_PRIVATE_KEY_HERE",
};
let coreUtxos = [

@@ -322,14 +360,15 @@ {

let privateKeys = [
// keys that correspond to the available utxos
"YOUR_KEY_HERE",
];
let txInfo = {
inputs: coreUtxos,
outputs: payments,
};
let tx = new Transaction();
tx.from(coreUtxos);
tx.to(payments);
tx.change(changeAddr);
tx.sign(privateKeys);
let keys = coreUtxos.map(function (utxo) {
let privHex = privateKeys[utxo.address];
let privBuf = Tx.utils.hexToU8(privHex);
return privBuf;
});
let tx = dashTx.hashAndSignAll(txInfo, keys);
let txHex = tx.serialize();
let txHex = tx.transaction;

@@ -336,0 +375,0 @@ let result = await dashsight.instantSend(txHex);

@@ -7,4 +7,2 @@ "use strict";

let request = require("../lib/request.js");
let WSClient = require("ws");

@@ -55,5 +53,4 @@

let cookies = await cookieStore.get(sidUrl);
let sidResp = await request({
let sidResp = await fetch(sidUrl, {
//agent: httpAgent,
url: sidUrl,
//@ts-ignore - request function is not typed correctly

@@ -63,6 +60,5 @@ headers: {

},
json: false,
});
if (!sidResp.ok) {
console.error(sidResp.toJSON());
console.error(await sidResp.json());
throw new Error("bad response");

@@ -73,3 +69,3 @@ }

// ex: `97:0{"sid":"xxxx",...}`
let msg = sidResp.body;
let msg = await sidResp.json();
let colonIndex = msg.indexOf(":");

@@ -107,6 +103,6 @@ // 0 is CONNECT, which will always follow our first message

let cookies = await cookieStore.get(subUrl);
let subResp = await request({
let subResp = await fetch(subUrl,
{
//agent: httpAgent,
method: "POST",
url: subUrl,
headers: {

@@ -119,3 +115,3 @@ "Content-Type": "text/plain;charset=UTF-8",

if (!subResp.ok) {
console.error(subResp.toJSON());
console.error(await subResp.json());
throw new Error("bad response");

@@ -126,3 +122,3 @@ }

// "ok"
return subResp.body;
return await subResp.json();
};

@@ -136,6 +132,5 @@

let cookies = await cookieStore.get(pollUrl);
let pollResp = await request({
let pollResp = await fetch(pollUrl, {
//agent: httpAgent,
method: "GET",
url: pollUrl,
headers: Object.assign(

@@ -142,0 +137,0 @@ {

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