Skip to content

Commit ca3ee55

Browse files
committed
doc: update for latest APIs
1 parent f7fe9fc commit ca3ee55

File tree

2 files changed

+74
-14
lines changed

2 files changed

+74
-14
lines changed

README.md

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,15 @@ Tx.OUTPUT_SIZE // 34
385385
```text
386386
Tx.create({ getPrivateKey, getPublicKey, sign, toPublicKey });
387387
tx.hashAndSignAll(txInfo);
388+
tx.hashAndSignInput(privBytes, txInfo, i, sigHashType);
388389
tx.legacy.draftSingleOutput({ utxos, inputs, output });
389390
tx.legacy.finalizePresorted(txDraft, keys);
390391
391392
Tx.createDonationOutput();
392393
393394
Tx.appraise({ inputs, outputs });
394-
Tx.getId(txHex);
395+
396+
Tx.parseUnknown(serializedHex);
395397
396398
// Byte-level helpers
397399
Tx.utils.toVarInt(n);
@@ -402,10 +404,28 @@ Tx.utils.hexToBytes(hex);
402404
Tx.utils.strToHex(str);
403405
404406
// Low-level helpers
405-
Tx.createRaw(txInfoMinimal);
406-
Tx.createHashable(txInfo, inputIndex);
407+
Tx.SIGHASH_ALL // 0x01
408+
Tx.SIGHASH_NONE // 0x02
409+
Tx.SIGHASH_ANYONECANPAY // 0x80
410+
411+
Tx.createRaw(txRequestInfo);
412+
Tx.createForSig(txInfo, inputIndex, sigHashType);
407413
Tx.createSigned(txInfoSigned);
408-
Tx.hashPartial(txHex, Tx.SIGHASH_ALL);
414+
415+
Tx.serialize(txRequestOrTxSigned);
416+
Tx.serializeForSig(txInfo, sigHashType);
417+
418+
Tx.createInputRaw(input, i);
419+
Tx.createInputForSig(input, i);
420+
421+
Tx.serializeInputs(inputs);
422+
Tx.serializeOutputs(outputs, opts);
423+
424+
Tx.serializeInput(input, i);
425+
Tx.serializeOutput(output, i);
426+
427+
Tx.sum(coins);
428+
Tx.doubleSha256(txBytes) {
409429
410430
// Deprecated
411431
Tx.createLegacyTx(coins, outputs, changeOutput);
@@ -415,7 +435,7 @@ Tx.createLegacyTx(coins, outputs, changeOutput);
415435
/**
416436
* Creates a tx signer instance.
417437
*/
418-
Tx.create({ getPrivateKey, getPublicKey, sign, toPublicKey });
438+
Tx.create(keyUtils);
419439

420440
/**
421441
* Estimates the min, mid, and max sizes of (fees for) a transaction (including memos).
@@ -488,32 +508,47 @@ Tx.createLegacyTx(coins, outputs, changeOutput);
488508
}
489509

490510
/**
491-
* Creates an "null" transaction with minimal information.
492-
* It which CANNOT be used for hashing or signing... and
493-
* we're not sure what it is useful for. Seemingly nothing.
511+
* Creates a transaction request object with minimal information.
512+
* It CANNOT be used for hashing or signing. Useful for sharing
513+
* between wallets as a request to create a shared transaction.
514+
* (i.e. for CoinJoin)
494515
*
495516
* Note: although these basically encode enough information
496517
* for a payment request, there are better ways to do that.
497518
*/
498519
Tx.createRaw(txInfoMinimal);
499520

500521
/**
501-
* Creates a transaction with all inputs "null"ed out,
502-
* except for the one corresponding to the given input index.
522+
* Creates a transaction object with all inputs omitted
523+
* (SIGHASH_ANYONECANPAY), or "null"ed out, except for the one
524+
* corresponding to the given input index. That index will
525+
* contain the lockscript from its previous output.
503526
*
504527
* This creates a one-off copy of the transaction suitable for
505528
* hashing to create the signature that will be inserted into
506529
* the (unrelated) final transaction.
507530
*/
508-
Tx.createHashable(txInfo, inputIndex);
531+
Tx.createForSig(txInfo, inputIndex);
509532

510533
/**
511534
* Creates a transaction that is ready to broadcast to the
512-
* network. It contains signatures from the one-off emphemeral,
513-
* hashable transactions created for each input.
535+
* network. Each input contains signatures from the one-off
536+
* emphemeral, ready-to-sign transactions described above.
514537
*/
515538
Tx.createSigned(txInfoSigned);
516539

540+
/**
541+
* Creates a transaction hex either for a raw request, or
542+
* that is signed and ready to broadcast to the network.
543+
*/
544+
Tx.serialize(txInfo);
545+
546+
/**
547+
* Serialized a transaction as hex, appending the sigHashType
548+
* of the target input, which is required for signing.
549+
*/
550+
Tx.serializeForSig(txInfo, sigHashType);
551+
517552
/**
518553
* Double sha256 hashes the signed, broadcastable transaction
519554
* and reverses the byte order of the reseult.
@@ -526,7 +561,14 @@ Tx.getId(txHex);
526561
* order because we use a standard ECSDA signing function that
527562
* expects bytes in the normal order.
528563
*/
529-
Tx.hashPartial(txHex, Tx.SIGHASH_ALL);
564+
Tx.doubleSha256(txBytes);
565+
566+
/**
567+
* Parse a transaction hex, which may be a raw request will "null"-ed
568+
* inputs, a ready-to-sign transaction with lockscript inputs, or a
569+
* ready-to-broadcast transaction with signed inputs.
570+
*/
571+
Tx.parseUnknown(serializedHex);
530572
```
531573

532574
### Utility Functions

dashtx.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* @prop {TxSelectSigHashInputs} selectSigHashInputs
3535
* @prop {TxSelectSigHashOutputs} selectSigHashOutputs
3636
* @prop {TxSerialize} serialize
37+
* @prop {TxSerializeForSig} serializeForSig
3738
* @prop {TxSerializeInputs} serializeInputs
3839
* @prop {TxSerializeInput} serializeInput
3940
* @prop {TxSerializeOutputs} serializeOutputs
@@ -424,6 +425,7 @@ var DashTx = ("object" === typeof module && exports) || {};
424425
}
425426

426427
let totalAvailable = DashTx.sum(inputs);
428+
//@ts-ignore - TODO update typedefs
427429
let fees = DashTx.appraise({ inputs: inputs, outputs: [output] });
428430

429431
//let EXTRA_SIG_BYTES_PER_INPUT = 2;
@@ -471,6 +473,7 @@ var DashTx = ("object" === typeof module && exports) || {};
471473
fullTransfer,
472474
};
473475

476+
//@ts-ignore - TODO update typedefs
474477
return txInfoRaw;
475478
};
476479

@@ -672,6 +675,7 @@ var DashTx = ("object" === typeof module && exports) || {};
672675
* the smallest coin that is bigger or equal to the amount sent + fees,
673676
* or the largest available coins until that total is met.
674677
*/
678+
//@ts-ignore - TODO update typedefs
675679
Tx.createLegacyTx = async function (coins, outputs, changeOutput) {
676680
// TODO bump to 4 for DIP: enforce tx hygiene
677681
let version = CURRENT_VERSION;
@@ -686,6 +690,7 @@ var DashTx = ("object" === typeof module && exports) || {};
686690

687691
/** @type {Array<TxInputUnspent>} */
688692
let inputs = [];
693+
//@ts-ignore - TODO update typedefs
689694
let fees = DashTx.appraise({ inputs, outputs });
690695
let taxes = fees.max;
691696
// requires at least one input
@@ -1137,6 +1142,8 @@ var DashTx = ("object" === typeof module && exports) || {};
11371142

11381143
return txHex;
11391144
};
1145+
//@ts-ignore - same function, but typed and documented separately for clarity
1146+
Tx.serializeForSig = Tx.serialize;
11401147

11411148
Tx.serializeInputs = function (inputs, _opts) {
11421149
let tx = _opts?._tx || [];
@@ -2205,6 +2212,17 @@ if ("object" === typeof module) {
22052212
* @param {Uint32} [sigHashType]
22062213
*/
22072214

2215+
/**
2216+
* @callback TxSerializeForSig
2217+
* @param {Object} txInfo
2218+
* @param {Array<TxInputRaw|TxInputForSig>} txInfo.inputs
2219+
* @param {Uint32} [txInfo.locktime]
2220+
* @param {Array<TxOutput>} txInfo.outputs
2221+
* @param {Uint32} [txInfo.version]
2222+
* @param {Boolean} [txInfo._debug] - bespoke debug output
2223+
* @param {Uint32} sigHashType
2224+
*/
2225+
22082226
/**
22092227
* @callback TxSerializeInputs
22102228
* @param {Array<TxInput|TxInputRaw|TxInputForSig|TxInputSigned>} txInputs

0 commit comments

Comments
 (0)