Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to create the sighash tx with the trailing sighash byte #61

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions dashtx.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,8 @@ var DashTx = ("object" === typeof module && exports) || {};
// TODO script -> lockScript, sigScript
//let lockScriptHex = txInput.script;
let _sigHashType = txInput.sigHashType ?? Tx.SIGHASH_ALL;
let txHashable = Tx.createHashable(txInfo, i);
let txHashBuf = await Tx.hashPartial(txHashable, _sigHashType);
let txHashable = Tx.createHashable(txInfo, i, _sigHashType);
let txHashBuf = await Tx.hashPartial(txHashable, 0x00);
let privKey = await keyUtils.getPrivateKey(txInput, i, txInfo.inputs);

let sigBuf = await keyUtils.sign(privKey, txHashBuf);
Expand Down Expand Up @@ -1047,7 +1047,7 @@ var DashTx = ("object" === typeof module && exports) || {};
return hex;
};

Tx.createHashable = function (txInfo, inputIndex) {
Tx.createHashable = function (txInfo, inputIndex, sigHashType) {
let txInfoHashable = Object.assign({}, txInfo);
/** @type {Array<TxInputRaw|TxInputHashable>} */
txInfoHashable.inputs = txInfo.inputs.map(function (input, i) {
Expand Down Expand Up @@ -1078,8 +1078,12 @@ var DashTx = ("object" === typeof module && exports) || {};
};
});

let hex = Tx._create(txInfoHashable);
return hex;
let sigHashTxHex = Tx._create(txInfoHashable);
if (sigHashTxHex) {
let sigHashTypeHex = TxUtils._toUint32LE(sigHashType);
sigHashTxHex = `${sigHashTxHex}${sigHashTypeHex}`;
}
return sigHashTxHex;
};

Tx.createSigned = function (opts) {
Expand Down Expand Up @@ -2061,6 +2065,7 @@ if ("object" === typeof module) {
* @callback TxCreateHashable
* @param {TxInfo} txInfo
* @param {Uint32} inputIndex - create hashable tx for this input
* @param {Uint32} sigHashType - 0x01 for ALL, or 0x81 for ALL + ANYONECANPAY
* @returns {String} - hashable tx hex
*/

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dashtx",
"version": "0.15.1",
"version": "0.15.2",
"description": "Create DASH Transactions with Vanilla JS (0 deps, cross-platform)",
"main": "dashtx.js",
"module": "dashtx.mjs",
Expand Down
Loading