diff --git a/README.md b/README.md index 4ba8258..2f86f66 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ let keyUtils = { }, getPublicKey: async function (txInput, i) { - let privKeyBytes = getPrivateKey(txInput, i); + let privKeyBytes = await keyUtils.getPrivateKey(txInput, i); let pubKeyBytes = await keyUtils.toPublicKey(privKeyBytes); return pubKeyBytes; diff --git a/dashtx.js b/dashtx.js index 905973f..9cd7da5 100644 --- a/dashtx.js +++ b/dashtx.js @@ -1269,14 +1269,13 @@ var DashTx = ("object" === typeof module && exports) || {}; } } if (output.memo) { - let invalid = output.satoshis || output.address || output.pubKeyHash; + let invalid = output.address || output.pubKeyHash; if (invalid) { - throw new Error( - `memo outputs must not have 'satoshis', 'address', or 'pubKeyHash'`, - ); + throw new Error(`memo outputs must not have 'address' or 'pubKeyHash'`); } - let memoScriptHex = Tx._createMemoScript(output.memo, i); + let sats = output.satoshis || 0; + let memoScriptHex = Tx._createMemoScript(output.memo, sats, i); let txOut = memoScriptHex.join(_sep); tx.push(txOut); @@ -1320,11 +1319,12 @@ var DashTx = ("object" === typeof module && exports) || {}; /** * @param {String} memoHex - the memo bytes, in hex + * @param {Uint53} sats - typically 0, but 1.0 for proposal collateral * @returns {Array} - memo script hex */ - Tx._createMemoScript = function (memoHex, i = 0) { + Tx._createMemoScript = function (memoHex, sats, i = 0) { let outputHex = []; - let satoshis = TxUtils._toUint64LE(0); + let satoshis = TxUtils._toUint64LE(sats); outputHex.push(satoshis); assertHex(memoHex, `output[${i}].memo`); diff --git a/index.js b/index.js deleted file mode 100644 index b635aa5..0000000 --- a/index.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -// auto-generated by `jswt reexport` -// DO NOT EDIT - -module.exports = require("./dashtx.js"); - -// these typedef reexports will be available to dependent packages -/** - * @typedef {import('./dashtx.js').Tx} Tx - * @typedef {import('./dashtx.js').TxUtils} TxUtils - * @typedef {import('./dashtx.js').tx} tx - * @typedef {import('./dashtx.js').Float64} Float64 - * @typedef {import('./dashtx.js').Uint8} Uint8 - * @typedef {import('./dashtx.js').Uint32} Uint32 - * @typedef {import('./dashtx.js').Uint53} Uint53 - * @typedef {import('./dashtx.js').Hex} Hex - * @typedef {import('./dashtx.js').TxPrivateKey} TxPrivateKey - * @typedef {import('./dashtx.js').TxPublicKey} TxPublicKey - * @typedef {import('./dashtx.js').TxSignature} TxSignature - * @typedef {import('./dashtx.js').CoreUtxo} CoreUtxo - * @typedef {import('./dashtx.js').TxDeps} TxDeps - * @typedef {import('./dashtx.js').TxFees} TxFees - * @typedef {import('./dashtx.js').TxInfo} TxInfo - * @typedef {import('./dashtx.js').TxDraft} TxDraft - * @typedef {import('./dashtx.js').TxDraftPartial} TxDraftPartial - * @typedef {import('./dashtx.js').TxInfoSigned} TxInfoSigned - * @typedef {import('./dashtx.js').TxSummary} TxSummary - * @typedef {import('./dashtx.js').TxSummaryPartial} TxSummaryPartial - * @typedef {import('./dashtx.js').TxInput} TxInput - * @typedef {import('./dashtx.js').TxInputForSig} TxInputForSig - * @typedef {import('./dashtx.js').TxInputRaw} TxInputRaw - * @typedef {import('./dashtx.js').TxInputUnspent} TxInputUnspent - * @typedef {import('./dashtx.js').TxInputSortable} TxInputSortable - * @typedef {import('./dashtx.js').TxHasSats} TxHasSats - * @typedef {import('./dashtx.js').TxInputSigned} TxInputSigned - * @typedef {import('./dashtx.js').TxOutput} TxOutput - * @typedef {import('./dashtx.js').TxOutputSortable} TxOutputSortable - */ diff --git a/package-lock.json b/package-lock.json index 8e88289..6337532 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "dashtx", - "version": "0.18.1", + "version": "0.18.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dashtx", - "version": "0.18.1", + "version": "0.18.2", "license": "SEE LICENSE IN LICENSE", "bin": { "dashtx-inspect": "bin/inspect.js" diff --git a/package.json b/package.json index f363adc..98668eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dashtx", - "version": "0.18.1", + "version": "0.18.2", "description": "Create DASH Transactions with Vanilla JS (0 deps, cross-platform)", "main": "dashtx.js", "module": "dashtx.mjs", @@ -30,7 +30,7 @@ "test": "node ./tests/", "--------------": "-----------------------------------------------", "jshint": "npx -p jshint@2.x -- jshint -c ./.jshintrc ./*.js", - "prettier": "npx -p prettier@2.x -- prettier -w '**/*.{js,md}'", + "prettier": "npx -p prettier@3.x -- prettier -w '**/*.{js,md}'", "reexport-types": "npx -p jswt@1.x -- reexport", "tsc": "! npx -p typescript@5.x -- tsc -p ./jsconfig.json | grep '\\.js(\\d\\+,\\d\\+): error' | grep -v '\\ 80 bytes should throw an error", ); - let tx1 = DashTx._createMemoScript(memo1); + let tx1 = DashTx._createMemoScript(memo1, 0); let tx1a = `0000000000000000${size3}6a${size1}${memo1}`; let tx1b = tx1.join(""); t.deepEqual(tx1b, tx1a, "single-byte memo fits"); - let tx75 = DashTx._createMemoScript(memo75); + let tx75 = DashTx._createMemoScript(memo75, 0); let tx75a = `0000000000000000${size77}6a${size75}${memo75}`; let tx75b = tx75.join(""); t.deepEqual(tx75b, tx75a, "75-byte memo fits"); let tx76a = `0000000000000000${size79}6a${OP_PD1}${size76}${memo76}`; - let tx76 = DashTx._createMemoScript(memo76); + let tx76 = DashTx._createMemoScript(memo76, 0); let tx76b = tx76.join(""); t.deepEqual(tx76b, tx76a, "76-byte memo fits with OP_PUSHDATA1"); let tx77a = `0000000000000000${size80}6a${OP_PD1}${size77}${memo77}`; - let tx77 = DashTx._createMemoScript(memo77); + let tx77 = DashTx._createMemoScript(memo77, 0); let tx77b = tx77.join(""); t.deepEqual(tx77b, tx77a, "77-byte memo fits with OP_PUSHDATA1"); let tx80a = `0000000000000000${size83}6a${OP_PD1}${size80}${memo80}`; - let tx80 = DashTx._createMemoScript(memo80); + let tx80 = DashTx._createMemoScript(memo80, 0); let tx80b = tx80.join(""); t.deepEqual(tx80b, tx80a, "80-byte memo fits with OP_PUSHDATA1"); + + let txProposalA = `00e1f50500000000226a202f3dbf4094c26594c7cd4b1c3d0af3740181d7e57f9f4faf5b7edbf6eddf4954`; + let txProposal = DashTx._createMemoScript(memoProposal, 100000000); + let txProposalB = txProposal.join(""); + t.deepEqual(txProposalB, txProposalA, "32-byte memo fits with OP_PUSHDATA1"); }); Zora.test("can create memo tx", async function (t) { diff --git a/types.js b/types.js deleted file mode 100644 index a9e65a0..0000000 --- a/types.js +++ /dev/null @@ -1,8 +0,0 @@ -// auto-generated by `jswt reexport` -// DO NOT EDIT - -// global types (DO NOT include in `package.json.files`) - -/** - * N/A - see reexports in 'index.js' - */