@@ -262,15 +262,52 @@ above, there were 2 inputs and 2 outputs. The example is truncated for brevity.
262
262
# API
263
263
264
264
<!--
265
- rg '^\s+Tx\.'
265
+ rg '^\s+Tx\.[A-Z_]+ = '
266
266
-->
267
267
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);
274
311
```
275
312
276
313
``` js
@@ -280,14 +317,16 @@ Tx.OUTPUT_SIZE // 34
280
317
Tx .create ({ sign, getPrivateKey });
281
318
282
319
/**
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) .
284
321
* (if in doubt, start with the mid - its's 75% likely to match the signed size)
285
322
* (non-deterministic because signed size is based on the variable-size signature)
286
323
*/
287
324
Tx .appraise ({ inputs, outputs });
288
325
// { min: 191, mid: 192, max: 193 }
289
326
290
327
/**
328
+ * Deprecated. Use `dashTx.legacy.draftSingleOutput()` instead.
329
+ *
291
330
* Magic. The old kind.
292
331
*
293
332
* Calculates totals, fees and output change, AND selects
@@ -300,15 +339,52 @@ Tx.createLegacyTx(coins, outputs, changeOutput);
300
339
// { version, inputs, outputs, changeIndex, locktime}
301
340
// let change = txInfo.outputs[txInfo.changeIndex];
302
341
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
+ }
312
388
313
389
/**
314
390
* Creates an "null" transaction with minimal information.
0 commit comments