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

dashsight

Package Overview
Dependencies
Maintainers
1
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.3.5 to 1.4.0-0

166

bin/create-tx.js

@@ -10,6 +10,2 @@ #!/usr/bin/env node

let Dashcore = require("@dashevo/dashcore-lib");
let Transaction = Dashcore.Transaction;
let baseUrl = process.env.INSIGHT_BASE_URL || "https://insight.dash.org";
let dashsightBaseUrl =

@@ -21,9 +17,88 @@ process.env.DASHSIGHT_BASE_URL || "https://insight.dash.org/insight-api";

let dashsight = Dashsight.create({
baseUrl: baseUrl,
insightBaseUrl: dashsightBaseUrl,
dashsightBaseUrl: dashsightBaseUrl,
dashsightBaseUrl: "", // not needed here
dashsocketBaseUrl: "", // not needed here
});
let Pub = require("./_wif-to-addr.js");
let Base58Check = require("@dashincubator/base58check").Base58Check;
let b58c = Base58Check.create({
pubKeyHashVersion: "4c",
privateKeyVersion: "cc",
});
let BlockTx = require("@dashincubator/blocktx");
let RIPEMD160 = require("@dashincubator/ripemd160");
let Secp256k1 = require("@dashincubator/secp256k1");
//@ts-ignore
let Crypto = exports.crypto || require("../shims/crypto-node.js");
/**
* @param {import('@dashincubator/blocktx').TxSignOpts} opts
*/
async function signTx({ privateKey, hash }) {
let sigOpts = { canonical: true };
let sigBuf = await Secp256k1.sign(hash, privateKey, sigOpts);
return BlockTx.utils.u8ToHex(sigBuf);
}
/**
* @param {import('@dashincubator/blocktx').TxPrivateKey} privBuf
*/
function toPublicKey(privBuf) {
let isCompressed = true;
let pubKey = Secp256k1.getPublicKey(privBuf, isCompressed);
return pubKey;
}
/**
* @param {import('@dashincubator/blocktx').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;
}
/**
* @param {String} wif
* @returns {Promise<Uint8Array>}
*/
async function wifToPrivateKey(wif) {
let parts = await b58c.verify(wif);
let privBuf = Buffer.from(parts.privateKey, "hex");
return privBuf;
}
/**
* @param {String} wif
* @returns {Promise<String>}
*/
async function wifToAddr(wif) {
let parts = await b58c.verify(wif);
let privBuf = Buffer.from(parts.privateKey, "hex");
let isCompressed = true;
let pubBuf = Secp256k1.getPublicKey(privBuf, isCompressed);
let pubKeyHash = await hashPublicKey(pubBuf);
let addr = await b58c.encode({
version: "4c",
pubKeyHash: pubKeyHash,
});
return addr;
}
/**
* @param {String} addr - base58check
* @returns {Promise<String>} - pubKeyHash as hex
*/
async function addrToPubKeyHash(addr) {
let parts = await b58c.verify(addr);
return parts.pubKeyHash;
}
async function main() {

@@ -33,3 +108,3 @@ let addrs = process.argv.slice(2);

if (2 !== addrs.length) {
console.error(`Usage: create-tx <wif> <payaddr>`);
console.error(`Usage: create-tx <wif> <pay-addr>`);
process.exit(1);

@@ -40,3 +115,3 @@ return;

let wifpath = addrs[0];
let payaddr = addrs[1];
let payAddr = addrs[1];

@@ -48,9 +123,10 @@ console.info();

let source = await Pub.wifToAddr(wif);
let source = await wifToAddr(wif);
console.info(`Source: ${source}`);
console.info(`Destination: ${payaddr}`);
console.info(`Destination: ${payAddr}`);
console.info();
let utxos = await dashsight.getUtxos(source);
let hasUtxos = utxos.length > 0;
let insightUtxos = await dashsight.getUtxos(source);
let coreUtxos = Dashsight.toCoreUtxos(insightUtxos);
let hasUtxos = coreUtxos.length > 0;
if (!hasUtxos) {

@@ -62,17 +138,11 @@ console.error(`'${source}' is completely spent`);

let utxo = utxos[0];
let duffs = toDuffs(utxo.satoshis);
let dash = toDash(utxo.satoshis);
let coreUtxo = coreUtxos[0];
let key = await wifToPrivateKey(wif);
let duffs = toDuffs(coreUtxo.satoshis);
let dash = toDash(coreUtxo.satoshis);
console.info(`First Unspent Tx: ${dash} (${duffs})`);
let coreUtxo = {
txId: utxo.txid,
outputIndex: utxo.vout,
address: utxo.address,
script: utxo.scriptPubKey,
satoshis: utxo.satoshis,
};
// max bytes for single tx with both bigint pads is 193
let fee = 193;
let fee = 191;
let feeDash = toDash(fee);

@@ -82,16 +152,40 @@ let feeDuffs = toDuffs(fee);

let amount = coreUtxo.satoshis - fee;
let amountDash = toDash(amount);
let amountDuffs = toDuffs(amount);
let units = coreUtxo.satoshis - fee;
let amountDash = toDash(units);
let amountDuffs = toDuffs(units);
console.info(`Payment Amount: ${amountDash} (${amountDuffs})`);
//@ts-ignore - no input required, actually
let tx = new Transaction()
//@ts-ignore - allows single value or array
.from([coreUtxo]);
tx.to(payaddr, amount);
tx.fee(fee);
tx.sign(wif);
let keys = [key];
let inputs = [coreUtxo];
let pubKeyHash = await addrToPubKeyHash(payAddr);
let outputs = [{ pubKeyHash, units }];
let txInfo = {
version: 3, // (will be) optional
inputs: inputs,
outputs: outputs,
// TODO any sort of minimum fee guessing?
locktime: 0, // optional
};
let txHex = tx.toString();
let dashTx = BlockTx.create({
version: 3,
//@ts-ignore
sign: signTx,
//@ts-ignore
getPrivateKey: async function (txInput, i) {
let privKey = keys[i];
return privKey;
},
//@ts-ignore
getPublicKey: async function (txInput, i) {
let privKey = keys[i];
let pubKey = toPublicKey(privKey);
return pubKey;
},
});
//@ts-ignore
let txInfoSigned = await dashTx.hashAndSignAll(txInfo, keys);
let txHex = txInfoSigned.transaction.toString();
console.info();

@@ -98,0 +192,0 @@ console.info(txHex);

@@ -10,14 +10,15 @@ #!/usr/bin/env node

let baseUrl = process.env.INSIGHT_BASE_URL || "https://insight.dash.org";
let dashsightBaseUrl =
// "https://dashsight.dashincubator.dev/insight-api";
process.env.DASHSIGHT_BASE_URL || "https://insight.dash.org/insight-api";
if (!dashsightBaseUrl) {
dashsightBaseUrl = `${baseUrl}/insight-api`;
}
process.env.DASHSIGHT_BASE_URL ||
"https://dashsight.dashincubator.dev/insight-api";
let dashsocketBaseUrl =
process.env.DASHSOCKET_BASE_URL || "https://insight.dash.org/socket.io";
let insightBaseUrl =
process.env.INSIGHT_BASE_URL || "https://insight.dash.org/insight-api";
let Dashsight = require("../");
let dashsight = Dashsight.create({
baseUrl,
dashsightBaseUrl,
dashsocketBaseUrl,
insightBaseUrl,
});

@@ -24,0 +25,0 @@

@@ -28,2 +28,3 @@ (function (exports) {

/** @typedef {import('./').GetUtxos} GetUtxos */
/** @typedef {import('./').ToCoreUtxo} ToCoreUtxo */
/** @typedef {import('./').ToCoreUtxos} ToCoreUtxos */

@@ -189,17 +190,8 @@

/** @type {ToCoreUtxo} */
insight.toCoreUtxo = Dashsight.toCoreUtxo;
/** @type {ToCoreUtxos} */
insight.toCoreUtxos = function (insightUtxos) {
let coreUtxos = insightUtxos.map(function (utxo) {
return {
txId: utxo.txid,
outputIndex: utxo.vout,
address: utxo.address,
script: utxo.scriptPubKey,
satoshis: utxo.satoshis,
};
});
insight.toCoreUtxos = Dashsight.toCoreUtxos;
return coreUtxos;
};
/**

@@ -278,6 +270,26 @@ * Handles UTXOs that have NO MORE THAN ONE page of transactions

/** @type {ToCoreUtxo} */
Dashsight.toCoreUtxo = function (utxo) {
return {
txId: utxo.txid,
outputIndex: utxo.vout,
address: utxo.address,
script: utxo.scriptPubKey,
satoshis: utxo.satoshis,
};
};
/** @type {ToCoreUtxos} */
Dashsight.toCoreUtxos = function (insightUtxos) {
let coreUtxos = insightUtxos.map(Dashsight.toCoreUtxo);
return coreUtxos;
};
if ("undefined" !== typeof module) {
module.exports.Dashsight = Dashsight;
module.exports.create = Dashsight.create;
module.exports.toCoreUtxo = Dashsight.toCoreUtxo;
module.exports.toCoreUtxos = Dashsight.toCoreUtxos;
}
})(("undefined" !== typeof module && module.exports) || window);

@@ -64,2 +64,8 @@ "use strict";

/**
* @callback ToCoreUtxo
* @param {InsightUtxo} insightUtxo
* @returns {CoreUtxo}
*/
/**
* @callback ToCoreUtxos

@@ -66,0 +72,0 @@ * @param {Array<InsightUtxo>} insightUtxos

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

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

"test": "echo \"Error: no test specified\" && exit 1",
"version": "npm version -m \"chore(release): bump to v%s\""
"bump": "npm version -m \"chore(release): bump to v%s\""
},

@@ -58,11 +58,11 @@ "files": [

"dependencies": {
"@dashincubator/blocktx": "^0.9.0-0",
"@root/request": "^1.9.2"
},
"devDependencies": {
"@dashevo/dashcore-lib": "^0.19.44",
"@root/base58check": "^1.0.0",
"@types/tough-cookie": "^4.0.2",
"ripemd160": "^2.0.2",
"secp256k1": "^4.0.3"
"@dashincubator/base58check": "^1.3.1",
"@dashincubator/ripemd160": "^2.3.0",
"@dashincubator/secp256k1": "^1.7.1-1",
"@types/tough-cookie": "^4.0.2"
}
}
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