Skip to content

Commit 00cd0a5

Browse files
committed
ref!: doc SIGHASH_*, set default as ALL+ANYONECANPAY
1 parent 42502d4 commit 00cd0a5

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ Tx.utils.strToHex(str);
407407
Tx.SIGHASH_ALL // 0x01
408408
Tx.SIGHASH_NONE // 0x02
409409
Tx.SIGHASH_ANYONECANPAY // 0x80
410+
Tx.SIGHASH_DEFAULT // 0x81 (ALL + ANYONECANPAY)
410411
411412
Tx.createRaw(txRequestInfo);
412413
Tx.createForSig(txInfo, inputIndex, sigHashType);

dashtx.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @prop {Uint32|0x00000002} SIGHASH_NONE - 0x02
1313
* @prop {Uint32|0x00000003} SIGHASH_SINGLE - 0x03 - Not Supported
1414
* @prop {Uint32|0x00000080} SIGHASH_ANYONECANPAY - 0x80
15+
* @prop {Uint32|0x00000081} SIGHASH_DEFAULT - 0x81
1516
* @prop {TxAppraise} appraise
1617
* @prop {TxAppraiseCounts} _appraiseCounts
1718
* @prop {TxAppraiseMemos} _appraiseMemos
@@ -173,6 +174,7 @@ var DashTx = ("object" === typeof module && exports) || {};
173174
Tx.SIGHASH_NONE = 0x02;
174175
Tx.SIGHASH_SINGLE = 0x03; // Not Supported
175176
Tx.SIGHASH_ANYONECANPAY = 0x80;
177+
Tx.SIGHASH_DEFAULT = Tx.SIGHASH_ALL | Tx.SIGHASH_ANYONECANPAY;
176178

177179
Tx.appraise = function (txInfo) {
178180
let extraSize = Tx._appraiseMemos(txInfo.outputs);
@@ -343,7 +345,8 @@ var DashTx = ("object" === typeof module && exports) || {};
343345
) {
344346
let txInput = txInfo.inputs[i];
345347

346-
let _sigHashType = txInput.sigHashType ?? sigHashType ?? Tx.SIGHASH_ALL;
348+
let _sigHashType =
349+
txInput.sigHashType ?? sigHashType ?? Tx.SIGHASH_DEFAULT;
347350

348351
// let inputs = Tx.selectSigHashInputs(txInfo, i, _sigHashType);
349352
// let outputs = Tx.selectSigHashOutputs(txInfo, i, _sigHashType);
@@ -635,8 +638,12 @@ var DashTx = ("object" === typeof module && exports) || {};
635638
return txInst;
636639
};
637640

638-
Tx.selectSigHashInputs = function (txInfo, i, sigHashType = Tx.SIGHASH_ALL) {
639-
let inputs = txInfo.inputs; // default (not Tx.SIGHASH_ANYONECANPAY)
641+
Tx.selectSigHashInputs = function (
642+
txInfo,
643+
i,
644+
sigHashType = Tx.SIGHASH_DEFAULT,
645+
) {
646+
let inputs = txInfo.inputs;
640647

641648
if (sigHashType & Tx.SIGHASH_ANYONECANPAY) {
642649
let txInput = txInfo.inputs[i];
@@ -646,7 +653,11 @@ var DashTx = ("object" === typeof module && exports) || {};
646653
return inputs;
647654
};
648655

649-
Tx.selectSigHashOutputs = function (txInfo, i, sigHashType = Tx.SIGHASH_ALL) {
656+
Tx.selectSigHashOutputs = function (
657+
txInfo,
658+
i,
659+
sigHashType = Tx.SIGHASH_DEFAULT,
660+
) {
650661
let outputs = txInfo.outputs;
651662
if (sigHashType & Tx.SIGHASH_ALL) {
652663
return outputs;
@@ -1954,7 +1965,7 @@ if ("object" === typeof module) {
19541965
* @prop {String} [script] - the previous lock script (default: derived from public key as p2pkh)
19551966
* @prop {String} publicKey - hex-encoded public key (typically starts with a 0x02 or 0x03 prefix)
19561967
* @prop {String} [pubKeyHash] - the 20-byte pubKeyHash (address without magic byte or checksum)
1957-
* @prop {Uint32} sigHashType - typically 0x01 (SIGHASH_ALL)
1968+
* @prop {Uint32} sigHashType - typically 0x81 (SIGHASH_ALL|SIGHASH_ANYONECANPAY)
19581969
*/
19591970

19601971
/**
@@ -1968,7 +1979,7 @@ if ("object" === typeof module) {
19681979
* @prop {String} [script] - the previous lock script (default: derived from public key as p2pkh)
19691980
* @prop {String} [publicKey] - hex-encoded public key (typically starts with a 0x02 or 0x03 prefix)
19701981
* @prop {String} [pubKeyHash] - the 20-byte pubKeyHash (address without magic byte or checksum)
1971-
* @prop {Uint32} [sigHashType] - typically 0x01 (SIGHASH_ALL)
1982+
* @prop {Uint32} sigHashType - typically 0x81 (SIGHASH_ALL|SIGHASH_ANYONECANPAY)
19721983
*/
19731984

19741985
/**

0 commit comments

Comments
 (0)