Skip to content

Commit 83f6388

Browse files
committed
doc: update exported constants and functions
1 parent 5808e54 commit 83f6388

File tree

2 files changed

+102
-17
lines changed

2 files changed

+102
-17
lines changed

README.md

+93-17
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,52 @@ above, there were 2 inputs and 2 outputs. The example is truncated for brevity.
262262
# API
263263

264264
<!--
265-
rg '^\s+Tx\.'
265+
rg '^\s+Tx\.[A-Z_]+ ='
266266
-->
267267

268-
```txt
269-
Tx.HEADER_SIZE // 10
270-
Tx.MIN_INPUT_SIZE // 147
271-
Tx.MAX_INPUT_SIZE // 150
272-
Tx.MAX_INPUT_PAD // 3
273-
Tx.OUTPUT_SIZE // 34
268+
```text
269+
Tx.SATOSHIS // 1_000_00000
270+
Tx.LEGACY_DUST // 02000
271+
272+
Tx.HEADER_SIZE // 10
273+
Tx.MIN_INPUT_SIZE // 147
274+
Tx.MAX_INPUT_SIZE // 149
275+
Tx.MAX_INPUT_PAD // 2
276+
Tx.OUTPUT_SIZE // 34
277+
```
278+
279+
```text
280+
Tx.create({ sign, getPrivateKey });
281+
tx.hashAndSignAll(txInfo);
282+
tx.legacy.draftSingleOutput({ utxos, inputs, output });
283+
tx.legacy.finalizePresorted(txDraft, keys);
284+
285+
Tx.appraise({ inputs, outputs });
286+
Tx.getId(txHex);
287+
288+
// Byte-level helpers
289+
Tx.utils.toVarInt(n);
290+
Tx.utils.toVarIntSize(n);
291+
Tx.utils.reverseHex(hex);
292+
Tx.utils.bytesToHex(bytes);
293+
Tx.utils.hexToBytes(hex);
294+
Tx.utils.strToHex(str);
295+
296+
// Low-level helpers
297+
Tx.createRaw(txInfoMinimal);
298+
Tx.createHashable(txInfo, inputIndex);
299+
Tx.createSigned(txInfoSigned);
300+
Tx.hashPartial(txHex);
301+
302+
// Deprecated
303+
Tx.createLegacyTx(coins, outputs, changeOutput);
304+
Tx.utils.hexToU8 // Tx.utils.hexToBytes;
305+
Tx.utils.u8ToHex // Tx.utils.bytesToHex;
306+
307+
// Not API-locked, May change
308+
Tx.utils.sign(privateKey, txHashBytes);
309+
Tx.utils.toPublicKey(privKeyBytes);
310+
Tx.utils.addrToPubKeyHash(addr);
274311
```
275312

276313
```js
@@ -280,14 +317,16 @@ Tx.OUTPUT_SIZE // 34
280317
Tx.create({ sign, getPrivateKey });
281318

282319
/**
283-
* Estimates the min, mid, and max sizes of (fees for) a transaction.
320+
* Estimates the min, mid, and max sizes of (fees for) a transaction (including memos).
284321
* (if in doubt, start with the mid - its's 75% likely to match the signed size)
285322
* (non-deterministic because signed size is based on the variable-size signature)
286323
*/
287324
Tx.appraise({ inputs, outputs });
288325
// { min: 191, mid: 192, max: 193 }
289326

290327
/**
328+
* Deprecated. Use `dashTx.legacy.draftSingleOutput()` instead.
329+
*
291330
* Magic. The old kind.
292331
*
293332
* Calculates totals, fees and output change, AND selects
@@ -300,15 +339,52 @@ Tx.createLegacyTx(coins, outputs, changeOutput);
300339
// { version, inputs, outputs, changeIndex, locktime}
301340
// let change = txInfo.outputs[txInfo.changeIndex];
302341

303-
/**
304-
* Creates the variety of required hashable transactions
305-
* (one per each input), signs them, and then constructs
306-
* a broadcastable transaction.
307-
*
308-
* Note: your inputs and outputs will be sorted according to
309-
* "Lexicographical Indexing of Transaction Inputs and Outputs"
310-
*/
311-
tx.hashAndSignAll(txInfo);
342+
{
343+
/**
344+
* Creates the variety of required hashable transactions
345+
* (one per each input), signs them, and then constructs
346+
* a broadcastable transaction.
347+
*
348+
* Note: your inputs and outputs should be sorted according to
349+
* "Lexicographical Indexing of Transaction Inputs and Outputs":
350+
*
351+
* txInfo.inputs.sort(Tx.sortInputs)
352+
* txInfo.outputs.sort(Tx.sortOutputs)
353+
*/
354+
tx.hashAndSignAll(txInfo);
355+
356+
/**
357+
* Drafts a multiple-input, single-output transaction.
358+
* (each `input.address` and the `output.address` may be set before or after)
359+
*
360+
* Sending Modes:
361+
* - "Automatic Coin Selection": use `utxos`, NOT `inputs`
362+
* - "Coin Control" : use `inputs`, NOT `utxos`
363+
* - "Full Balance Transfer" : use `inputs`, NOT `utxos` and
364+
* set `output.satoshis = null`
365+
*
366+
* Change:
367+
* - `txDraft.change` is a reference to the relevant `txDraft.outputs[i]`
368+
* - `txDraft.change.address` MUST be set before signing the transaction
369+
*
370+
* BIP-69 Secure Sorting must be done AFTER setting each `address`
371+
* - `Tx.sortInputs(txDraft.inputs)`
372+
* - `Tx.sortOutputs(txDraft.outputs)`
373+
*/
374+
let txDraft = tx.legacy.draftSingleOutput({ utxos, inputs, output });
375+
376+
/**
377+
* Signs the draft with variations to find a signature whose fee will
378+
* closely match `txDraft.feeTarget`.
379+
*
380+
* - `inputs` and `outputs` MUST be sorted BEFORE calling this
381+
* - `txDraft.feeTarget` should be at least 10% likely
382+
* - the likelihood of `fees.min` is `1 / Math.pow(4, inputs.length)`
383+
* - the likelihood of `fees.mid` is 75%
384+
* - the likelihood of `fees.max` is 100%
385+
*/
386+
let txSummary = tx.legacy.finalizePresorted(txDraft, keys);
387+
}
312388

313389
/**
314390
* Creates an "null" transaction with minimal information.

index.js

+9
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ module.exports = require("./dashtx.js");
99
* @typedef {import('./dashtx.js').Tx} Tx
1010
* @typedef {import('./dashtx.js').TxUtils} TxUtils
1111
* @typedef {import('./dashtx.js').tx} tx
12+
* @typedef {import('./dashtx.js').Float64} Float64
13+
* @typedef {import('./dashtx.js').Uint53} Uint53
14+
* @typedef {import('./dashtx.js').Uint32} Uint32
15+
* @typedef {import('./dashtx.js').Uint8} Uint8
1216
* @typedef {import('./dashtx.js').TxPrivateKey} TxPrivateKey
1317
* @typedef {import('./dashtx.js').TxPublicKey} TxPublicKey
1418
* @typedef {import('./dashtx.js').TxSignature} TxSignature
19+
* @typedef {import('./dashtx.js').CoreUtxo} CoreUtxo
1520
* @typedef {import('./dashtx.js').TxDeps} TxDeps
1621
* @typedef {import('./dashtx.js').TxFees} TxFees
1722
* @typedef {import('./dashtx.js').TxInfo} TxInfo
23+
* @typedef {import('./dashtx.js').TxDraft} TxDraft
24+
* @typedef {import('./dashtx.js').TxDraftPartial} TxDraftPartial
1825
* @typedef {import('./dashtx.js').TxInfoSigned} TxInfoSigned
26+
* @typedef {import('./dashtx.js').TxSummary} TxSummary
27+
* @typedef {import('./dashtx.js').TxSummaryPartial} TxSummaryPartial
1928
* @typedef {import('./dashtx.js').TxInput} TxInput
2029
* @typedef {import('./dashtx.js').TxInputHashable} TxInputHashable
2130
* @typedef {import('./dashtx.js').TxInputRaw} TxInputRaw

0 commit comments

Comments
 (0)