@opcat-labs/opcat 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cjs2esm.json +18 -0
- package/.mocharc.yaml +1 -1
- package/CHANGELOG.md +13 -0
- package/README.md +6 -0
- package/{lib/address.js → cjs/address.cjs} +77 -72
- package/cjs/block/block.cjs +332 -0
- package/{lib/block/blockheader.js → cjs/block/blockheader.cjs} +8 -7
- package/cjs/block/index.cjs +2 -0
- package/{lib/block/merkleblock.js → cjs/block/merkleblock.cjs} +23 -15
- package/cjs/bn.cjs +3411 -0
- package/{lib/crypto/bn.js → cjs/crypto/bn.cjs} +3 -3
- package/{lib/crypto/ecdsa.js → cjs/crypto/ecdsa.cjs} +150 -14
- package/{lib/crypto/hash.node.js → cjs/crypto/hash.cjs} +13 -2
- package/cjs/crypto/index.cjs +16 -0
- package/{lib/crypto/point.js → cjs/crypto/point.cjs} +11 -4
- package/cjs/crypto/random.cjs +18 -0
- package/{lib/crypto/signature.js → cjs/crypto/signature.cjs} +158 -8
- package/{lib/encoding/base58.js → cjs/encoding/base58.cjs} +58 -2
- package/cjs/encoding/base58check.cjs +192 -0
- package/cjs/encoding/bufferreader.cjs +333 -0
- package/cjs/encoding/bufferwriter.cjs +244 -0
- package/{lib/encoding/decode-asm.js → cjs/encoding/decode-asm.cjs} +4 -4
- package/{lib/encoding/decode-hex.js → cjs/encoding/decode-hex.cjs} +1 -1
- package/cjs/encoding/index.cjs +14 -0
- package/cjs/encoding/varint.cjs +116 -0
- package/{lib/errors/index.js → cjs/errors/index.cjs} +9 -9
- package/{lib/errors/spec.js → cjs/errors/spec.cjs} +2 -2
- package/cjs/hash-cache.cjs +98 -0
- package/{lib/hdprivatekey.js → cjs/hdprivatekey.cjs} +232 -140
- package/{lib/hdpublickey.js → cjs/hdpublickey.cjs} +120 -93
- package/cjs/index.cjs +94 -0
- package/cjs/interpreter/index.cjs +2 -0
- package/cjs/interpreter/interpreter.cjs +1988 -0
- package/{lib/script/stack.js → cjs/interpreter/stack.cjs} +9 -2
- package/{lib/message/message.js → cjs/message/message.cjs} +62 -25
- package/cjs/mnemonic/index.cjs +3 -0
- package/{lib/mnemonic/mnemonic.js → cjs/mnemonic/mnemonic.cjs} +44 -13
- package/{lib/mnemonic/pbkdf2.node.js → cjs/mnemonic/pbkdf2.cjs} +9 -2
- package/cjs/mnemonic/words/index.cjs +66 -0
- package/cjs/network.cjs +13 -0
- package/cjs/networks.cjs +321 -0
- package/{lib/opcode.js → cjs/opcode.cjs} +69 -5
- package/cjs/privatekey.cjs +422 -0
- package/{lib/publickey.js → cjs/publickey.cjs} +14 -16
- package/cjs/script/index.cjs +2 -0
- package/{lib/script/script.js → cjs/script/script.cjs} +322 -67
- package/cjs/transaction/index.cjs +5 -0
- package/cjs/transaction/input/index.cjs +34 -0
- package/cjs/transaction/input/input.cjs +396 -0
- package/{lib/transaction/input/multisig.js → cjs/transaction/input/multisig.cjs} +112 -18
- package/{lib/transaction/input/publickey.js → cjs/transaction/input/publickey.cjs} +29 -19
- package/{lib/transaction/input/publickeyhash.js → cjs/transaction/input/publickeyhash.cjs} +25 -17
- package/{lib/transaction/output.js → cjs/transaction/output.cjs} +100 -15
- package/cjs/transaction/sighash.cjs +187 -0
- package/{lib/transaction/signature.js → cjs/transaction/signature.cjs} +30 -6
- package/cjs/transaction/transaction.cjs +2000 -0
- package/{lib/transaction/unspentoutput.js → cjs/transaction/unspentoutput.cjs} +5 -5
- package/cjs/util/derivation.cjs +53 -0
- package/cjs/util/index.cjs +11 -0
- package/cjs/util/js.cjs +95 -0
- package/{lib/util/preconditions.js → cjs/util/preconditions.cjs} +2 -2
- package/esm/address.js +483 -0
- package/{lib → esm}/block/block.js +82 -27
- package/esm/block/blockheader.js +296 -0
- package/esm/block/index.js +2 -0
- package/esm/block/merkleblock.js +331 -0
- package/esm/bn.js +3411 -0
- package/esm/crypto/bn.js +278 -0
- package/esm/crypto/ecdsa.js +475 -0
- package/{lib/crypto/hash.browser.js → esm/crypto/hash.js} +18 -7
- package/esm/crypto/index.js +16 -0
- package/esm/crypto/point.js +228 -0
- package/esm/crypto/random.js +18 -0
- package/esm/crypto/signature.js +475 -0
- package/esm/encoding/base58.js +167 -0
- package/esm/encoding/base58check.js +192 -0
- package/esm/encoding/bufferreader.js +333 -0
- package/esm/encoding/bufferwriter.js +243 -0
- package/esm/encoding/decode-asm.js +24 -0
- package/esm/encoding/decode-hex.js +32 -0
- package/esm/encoding/decode-script-chunks.js +43 -0
- package/esm/encoding/encode-hex.js +284 -0
- package/esm/encoding/index.js +14 -0
- package/esm/encoding/is-hex.js +7 -0
- package/esm/encoding/varint.js +116 -0
- package/esm/errors/index.js +54 -0
- package/esm/errors/spec.js +314 -0
- package/esm/hash-cache.js +98 -0
- package/esm/hdprivatekey.js +768 -0
- package/esm/hdpublickey.js +549 -0
- package/esm/index.js +66 -0
- package/esm/interpreter/index.js +2 -0
- package/{lib/script → esm/interpreter}/interpreter.js +219 -66
- package/esm/interpreter/stack.js +116 -0
- package/esm/message/message.js +228 -0
- package/esm/mnemonic/index.js +3 -0
- package/esm/mnemonic/mnemonic.js +332 -0
- package/{lib/mnemonic/pbkdf2.browser.js → esm/mnemonic/pbkdf2.js} +13 -6
- package/esm/mnemonic/words/chinese.js +2054 -0
- package/esm/mnemonic/words/english.js +2054 -0
- package/esm/mnemonic/words/french.js +2054 -0
- package/esm/mnemonic/words/index.js +66 -0
- package/esm/mnemonic/words/italian.js +2054 -0
- package/esm/mnemonic/words/japanese.js +2054 -0
- package/esm/mnemonic/words/spanish.js +2054 -0
- package/esm/network.js +13 -0
- package/{lib → esm}/networks.js +61 -120
- package/esm/opcode.js +319 -0
- package/{lib → esm}/privatekey.js +76 -28
- package/esm/publickey.js +384 -0
- package/esm/script/index.js +2 -0
- package/esm/script/script.js +1329 -0
- package/esm/script/write-i32-le.js +17 -0
- package/esm/script/write-push-data.js +35 -0
- package/esm/script/write-u16-le.js +12 -0
- package/esm/script/write-u32-le.js +16 -0
- package/esm/script/write-u64-le.js +24 -0
- package/esm/script/write-u8-le.js +8 -0
- package/esm/script/write-varint.js +46 -0
- package/esm/transaction/index.js +5 -0
- package/esm/transaction/input/index.js +33 -0
- package/{lib → esm}/transaction/input/input.js +132 -90
- package/esm/transaction/input/multisig.js +335 -0
- package/esm/transaction/input/publickey.js +108 -0
- package/esm/transaction/input/publickeyhash.js +124 -0
- package/esm/transaction/output.js +316 -0
- package/{lib → esm}/transaction/sighash.js +42 -22
- package/esm/transaction/signature.js +120 -0
- package/{lib → esm}/transaction/transaction.js +522 -163
- package/esm/transaction/unspentoutput.js +112 -0
- package/esm/util/_.js +47 -0
- package/esm/util/derivation.js +53 -0
- package/esm/util/index.js +12 -0
- package/esm/util/js.js +95 -0
- package/esm/util/preconditions.js +33 -0
- package/fixup.cjs +17 -0
- package/package.json +40 -26
- package/test/{address.js → address.cjs} +14 -43
- package/test/block/{block.js → block.cjs} +3 -5
- package/test/block/{blockheader.js → blockheader.cjs} +2 -2
- package/test/block/{merklebloack.js → merklebloack.cjs} +2 -2
- package/test/crypto/{ecdsa.js → ecdsa.cjs} +9 -9
- package/test/crypto/{hash.browser.js → hash.browser.cjs} +2 -1
- package/test/crypto/{signature.js → signature.cjs} +2 -2
- package/test/data/bitcoind/script_tests.json +5 -5
- package/test/{hashCache.js → hashCache.cjs} +2 -1
- package/test/{hdkeys.js → hdkeys.cjs} +4 -2
- package/test/{hdprivatekey.js → hdprivatekey.cjs} +7 -6
- package/test/{hdpublickey.js → hdpublickey.cjs} +2 -7
- package/test/mnemonic/{pbkdf2.test.js → pbkdf2.test.cjs} +2 -2
- package/test/{networks.js → networks.cjs} +12 -31
- package/test/{publickey.js → publickey.cjs} +2 -2
- package/test/script/{interpreter.js → interpreter.cjs} +5 -5
- package/test/script/{script.js → script.cjs} +8 -2
- package/test/transaction/{deserialize.js → deserialize.cjs} +2 -2
- package/test/transaction/input/{input.js → input.cjs} +1 -1
- package/test/transaction/input/{multisig.js → multisig.cjs} +2 -1
- package/test/transaction/input/{publickeyhash.js → publickeyhash.cjs} +1 -1
- package/test/transaction/{sighash.js → sighash.cjs} +1 -1
- package/test/transaction/{transaction.js → transaction.cjs} +2 -2
- package/tsconfig.json +13 -0
- package/types/address.d.cts +252 -0
- package/types/block/block.d.cts +139 -0
- package/types/block/blockheader.d.cts +125 -0
- package/types/block/index.d.cts +2 -0
- package/types/block/merkleblock.d.cts +95 -0
- package/types/bn.d.cts +202 -0
- package/types/crypto/bn.d.cts +2 -0
- package/types/crypto/ecdsa.d.cts +187 -0
- package/types/crypto/hash.d.cts +118 -0
- package/types/crypto/index.d.cts +7 -0
- package/types/crypto/point.d.cts +134 -0
- package/types/crypto/random.d.cts +13 -0
- package/types/crypto/signature.d.cts +160 -0
- package/types/encoding/base58.d.cts +106 -0
- package/types/encoding/base58check.d.cts +107 -0
- package/types/encoding/bufferreader.d.cts +164 -0
- package/types/encoding/bufferwriter.d.cts +126 -0
- package/types/encoding/decode-asm.d.cts +2 -0
- package/types/encoding/decode-hex.d.cts +2 -0
- package/types/encoding/decode-script-chunks.d.cts +14 -0
- package/types/encoding/encode-hex.d.cts +2 -0
- package/types/encoding/index.d.cts +6 -0
- package/types/encoding/is-hex.d.cts +2 -0
- package/types/encoding/varint.d.cts +66 -0
- package/types/errors/index.d.cts +4 -0
- package/types/errors/spec.d.cts +22 -0
- package/types/hash-cache.d.cts +65 -0
- package/types/hdprivatekey.d.cts +281 -0
- package/types/hdpublickey.d.cts +240 -0
- package/types/index.d.cts +26 -0
- package/types/interpreter/index.d.cts +2 -0
- package/types/interpreter/interpreter.d.cts +228 -0
- package/types/interpreter/stack.d.cts +35 -0
- package/types/message/message.d.cts +110 -0
- package/types/mnemonic/index.d.cts +2 -0
- package/types/mnemonic/mnemonic.d.cts +171 -0
- package/types/mnemonic/pbkdf2.d.cts +14 -0
- package/types/mnemonic/words/chinese.d.cts +2 -0
- package/types/mnemonic/words/english.d.cts +2 -0
- package/types/mnemonic/words/french.d.cts +2 -0
- package/types/mnemonic/words/index.d.cts +22 -0
- package/types/mnemonic/words/italian.d.cts +2 -0
- package/types/mnemonic/words/japanese.d.cts +2 -0
- package/types/mnemonic/words/spanish.d.cts +2 -0
- package/types/network.d.cts +11 -0
- package/types/networks.d.cts +76 -0
- package/types/opcode.d.cts +93 -0
- package/types/privatekey.d.cts +169 -0
- package/types/publickey.d.cts +202 -0
- package/types/script/index.d.cts +2 -0
- package/types/script/script.d.cts +449 -0
- package/types/script/write-i32-le.d.cts +2 -0
- package/types/script/write-push-data.d.cts +2 -0
- package/types/script/write-u16-le.d.cts +2 -0
- package/types/script/write-u32-le.d.cts +2 -0
- package/types/script/write-u64-le.d.cts +2 -0
- package/types/script/write-u8-le.d.cts +2 -0
- package/types/script/write-varint.d.cts +2 -0
- package/types/transaction/index.d.cts +2 -0
- package/types/transaction/input/index.d.cts +2 -0
- package/types/transaction/input/input.d.cts +178 -0
- package/types/transaction/input/multisig.d.cts +127 -0
- package/types/transaction/input/publickey.d.cts +44 -0
- package/types/transaction/input/publickeyhash.d.cts +45 -0
- package/types/transaction/output.d.cts +118 -0
- package/types/transaction/sighash.d.cts +61 -0
- package/types/transaction/signature.d.cts +43 -0
- package/types/transaction/transaction.d.cts +716 -0
- package/types/transaction/unspentoutput.d.cts +83 -0
- package/types/util/_.d.cts +26 -0
- package/types/util/derivation.d.cts +21 -0
- package/types/util/index.d.cts +5 -0
- package/types/util/js.d.cts +50 -0
- package/types/util/preconditions.d.cts +3 -0
- package/index.d.ts +0 -1541
- package/index.js +0 -74
- package/lib/block/index.js +0 -4
- package/lib/bn.js +0 -3423
- package/lib/crypto/hash.js +0 -2
- package/lib/crypto/random.browser.js +0 -28
- package/lib/crypto/random.js +0 -2
- package/lib/crypto/random.node.js +0 -11
- package/lib/encoding/base58check.js +0 -121
- package/lib/encoding/bufferreader.js +0 -212
- package/lib/encoding/bufferwriter.js +0 -140
- package/lib/encoding/varint.js +0 -75
- package/lib/hash-cache.js +0 -50
- package/lib/mnemonic/pbkdf2.js +0 -2
- package/lib/mnemonic/words/index.js +0 -8
- package/lib/script/index.js +0 -5
- package/lib/transaction/index.js +0 -7
- package/lib/transaction/input/index.js +0 -5
- package/lib/util/js.js +0 -90
- /package/{lib/encoding/decode-script-chunks.js → cjs/encoding/decode-script-chunks.cjs} +0 -0
- /package/{lib/encoding/encode-hex.js → cjs/encoding/encode-hex.cjs} +0 -0
- /package/{lib/encoding/is-hex.js → cjs/encoding/is-hex.cjs} +0 -0
- /package/{lib/mnemonic/words/chinese.js → cjs/mnemonic/words/chinese.cjs} +0 -0
- /package/{lib/mnemonic/words/english.js → cjs/mnemonic/words/english.cjs} +0 -0
- /package/{lib/mnemonic/words/french.js → cjs/mnemonic/words/french.cjs} +0 -0
- /package/{lib/mnemonic/words/italian.js → cjs/mnemonic/words/italian.cjs} +0 -0
- /package/{lib/mnemonic/words/japanese.js → cjs/mnemonic/words/japanese.cjs} +0 -0
- /package/{lib/mnemonic/words/spanish.js → cjs/mnemonic/words/spanish.cjs} +0 -0
- /package/{lib/script/write-i32-le.js → cjs/script/write-i32-le.cjs} +0 -0
- /package/{lib/script/write-push-data.js → cjs/script/write-push-data.cjs} +0 -0
- /package/{lib/script/write-u16-le.js → cjs/script/write-u16-le.cjs} +0 -0
- /package/{lib/script/write-u32-le.js → cjs/script/write-u32-le.cjs} +0 -0
- /package/{lib/script/write-u64-le.js → cjs/script/write-u64-le.cjs} +0 -0
- /package/{lib/script/write-u8-le.js → cjs/script/write-u8-le.cjs} +0 -0
- /package/{lib/script/write-varint.js → cjs/script/write-varint.cjs} +0 -0
- /package/{lib/util/_.js → cjs/util/_.cjs} +0 -0
- /package/test/crypto/{bn.js → bn.cjs} +0 -0
- /package/test/crypto/{hash.js → hash.cjs} +0 -0
- /package/test/crypto/{point.js → point.cjs} +0 -0
- /package/test/crypto/{random.js → random.cjs} +0 -0
- /package/test/data/{blk86756-testnet.js → blk86756-testnet.cjs} +0 -0
- /package/test/data/{merkleblocks.js → merkleblocks.cjs} +0 -0
- /package/test/encoding/{base58.js → base58.cjs} +0 -0
- /package/test/encoding/{base58check.js → base58check.cjs} +0 -0
- /package/test/encoding/{bufferreader.js → bufferreader.cjs} +0 -0
- /package/test/encoding/{bufferwriter.js → bufferwriter.cjs} +0 -0
- /package/test/encoding/{varint.js → varint.cjs} +0 -0
- /package/test/{index.js → index.cjs} +0 -0
- /package/test/message/{message.js → message.cjs} +0 -0
- /package/test/mnemonic/{mnemonic.js → mnemonic.cjs} +0 -0
- /package/test/{opcode.js → opcode.cjs} +0 -0
- /package/test/{privatekey.js → privatekey.cjs} +0 -0
- /package/test/transaction/input/{publickey.js → publickey.cjs} +0 -0
- /package/test/transaction/{output.js → output.cjs} +0 -0
- /package/test/transaction/{signature.js → signature.cjs} +0 -0
- /package/test/transaction/{unspentoutput.js → unspentoutput.cjs} +0 -0
- /package/test/util/{js.js → js.cjs} +0 -0
- /package/test/util/{preconditions.js → preconditions.cjs} +0 -0
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
export = Transaction;
|
|
2
|
+
/**
|
|
3
|
+
* Represents a transaction, a set of inputs and outputs to change ownership of tokens
|
|
4
|
+
* @constructor
|
|
5
|
+
* @param {string|Buffer|Object|Transaction} [serialized] - Optional serialized data to initialize the transaction.
|
|
6
|
+
* Can be a hex string, Buffer, plain object, or another Transaction instance.
|
|
7
|
+
* @throws {errors.InvalidArgument} If invalid serialization format is provided.
|
|
8
|
+
* @property {Array} inputs - Transaction input objects.
|
|
9
|
+
* @property {Array} outputs - Transaction output objects.
|
|
10
|
+
* @property {boolean} sealed - Indicates if transaction is finalized.
|
|
11
|
+
*/
|
|
12
|
+
declare function Transaction(serialized?: string | Buffer | any | Transaction): import("./transaction.cjs");
|
|
13
|
+
declare class Transaction {
|
|
14
|
+
/**
|
|
15
|
+
* Represents a transaction, a set of inputs and outputs to change ownership of tokens
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param {string|Buffer|Object|Transaction} [serialized] - Optional serialized data to initialize the transaction.
|
|
18
|
+
* Can be a hex string, Buffer, plain object, or another Transaction instance.
|
|
19
|
+
* @throws {errors.InvalidArgument} If invalid serialization format is provided.
|
|
20
|
+
* @property {Array} inputs - Transaction input objects.
|
|
21
|
+
* @property {Array} outputs - Transaction output objects.
|
|
22
|
+
* @property {boolean} sealed - Indicates if transaction is finalized.
|
|
23
|
+
*/
|
|
24
|
+
constructor(serialized?: string | Buffer | any | Transaction);
|
|
25
|
+
inputs: any[];
|
|
26
|
+
outputs: any[];
|
|
27
|
+
_inputAmount: number;
|
|
28
|
+
_outputAmount: number;
|
|
29
|
+
_inputsMap: Map<any, any>;
|
|
30
|
+
_outputsMap: Map<any, any>;
|
|
31
|
+
_privateKey: Buffer | Buffer[];
|
|
32
|
+
_sigType: number;
|
|
33
|
+
sealed: boolean;
|
|
34
|
+
readonly hash: any;
|
|
35
|
+
readonly id: any;
|
|
36
|
+
get inputAmount(): number;
|
|
37
|
+
get outputAmount(): number;
|
|
38
|
+
private _getHash;
|
|
39
|
+
/**
|
|
40
|
+
* Retrieve a hexa string that can be used with bitcoind's CLI interface
|
|
41
|
+
* (decoderawtransaction, sendrawtransaction)
|
|
42
|
+
*
|
|
43
|
+
* @param {Object|boolean=} unsafe if true, skip all tests. if it's an object,
|
|
44
|
+
* it's expected to contain a set of flags to skip certain tests:
|
|
45
|
+
* * `disableAll`: disable all checks
|
|
46
|
+
* * `disableLargeFees`: disable checking for fees that are too large
|
|
47
|
+
* * `disableIsFullySigned`: disable checking if all inputs are fully signed
|
|
48
|
+
* * `disableDustOutputs`: disable checking if there are no outputs that are dust amounts
|
|
49
|
+
* * `disableMoreOutputThanInput`: disable checking if the transaction spends more bitcoins than the sum of the input amounts
|
|
50
|
+
* @return {string}
|
|
51
|
+
*/
|
|
52
|
+
serialize(unsafe?: (any | boolean) | undefined): string;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a deep clone of the Transaction instance.
|
|
55
|
+
* @returns {Transaction} A new Transaction instance with cloned inputs.
|
|
56
|
+
*/
|
|
57
|
+
clone(): Transaction;
|
|
58
|
+
/**
|
|
59
|
+
* Serializes the transaction to a hexadecimal string.
|
|
60
|
+
* This method is aliased as `toString()` and `toHex()` for convenience.
|
|
61
|
+
* @returns {string} Hexadecimal representation of the transaction.
|
|
62
|
+
*/
|
|
63
|
+
uncheckedSerialize: () => string;
|
|
64
|
+
toString: () => string;
|
|
65
|
+
toHex(): string;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieve a hexa string that can be used with bitcoind's CLI interface
|
|
68
|
+
* (decoderawtransaction, sendrawtransaction)
|
|
69
|
+
*
|
|
70
|
+
* @param {Object} opts allows to skip certain tests. {@see Transaction#serialize}
|
|
71
|
+
* @return {string}
|
|
72
|
+
*/
|
|
73
|
+
checkedSerialize(opts: any): string;
|
|
74
|
+
/**
|
|
75
|
+
* Checks if any output in the transaction has invalid satoshis.
|
|
76
|
+
* @returns {boolean} True if at least one output has invalid satoshis, false otherwise.
|
|
77
|
+
*/
|
|
78
|
+
invalidSatoshis(): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Retrieve a possible error that could appear when trying to serialize and
|
|
81
|
+
* broadcast this transaction.
|
|
82
|
+
*
|
|
83
|
+
* @param {Object} opts allows to skip certain tests. {@see Transaction#serialize}
|
|
84
|
+
* @return {opcat.Error}
|
|
85
|
+
*/
|
|
86
|
+
getSerializationError(opts: any): opcat.Error;
|
|
87
|
+
private _hasFeeError;
|
|
88
|
+
private _missingChange;
|
|
89
|
+
private _hasDustOutputs;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if the transaction is missing signatures.
|
|
92
|
+
* @param {Object} opts - Options object.
|
|
93
|
+
* @param {boolean} [opts.disableIsFullySigned] - If true, skips the check.
|
|
94
|
+
* @returns {errors.Transaction.MissingSignatures|undefined} Returns MissingSignatures error if not fully signed, otherwise undefined.
|
|
95
|
+
*/
|
|
96
|
+
_isMissingSignatures(opts: {
|
|
97
|
+
disableIsFullySigned?: boolean;
|
|
98
|
+
}): errors.Transaction.MissingSignatures | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Returns a string representation of the Transaction object for debugging/inspection.
|
|
101
|
+
* The format is: '<Transaction: [serializedData]>' where serializedData comes from uncheckedSerialize().
|
|
102
|
+
* @returns {string} Formatted transaction inspection string.
|
|
103
|
+
*/
|
|
104
|
+
inspect(): string;
|
|
105
|
+
/**
|
|
106
|
+
* Converts the transaction to a Buffer.
|
|
107
|
+
* @returns {Buffer} The serialized transaction as a Buffer.
|
|
108
|
+
*/
|
|
109
|
+
toBuffer(): Buffer;
|
|
110
|
+
/**
|
|
111
|
+
* Calculates the double SHA-256 hash of the transaction preimage for signature verification.
|
|
112
|
+
* The resulting hash is returned in reverse byte order (little-endian).
|
|
113
|
+
*
|
|
114
|
+
* @param {number} inputIndex - Index of the input being signed
|
|
115
|
+
* @param {number} hashType - SIGHASH type flag
|
|
116
|
+
* @returns {Buffer} The hash result in little-endian format
|
|
117
|
+
*/
|
|
118
|
+
hashForSignature(inputIndex: number, hashType: number): Buffer;
|
|
119
|
+
/**
|
|
120
|
+
* Converts the transaction to a hash preimage by serializing it into a buffer.
|
|
121
|
+
* @returns {Buffer} The serialized transaction data as a buffer.
|
|
122
|
+
*/
|
|
123
|
+
toTxHashPreimage(): Buffer;
|
|
124
|
+
/**
|
|
125
|
+
* Serializes the transaction to a BufferWriter.
|
|
126
|
+
* @param {boolean} forTxHash - Whether to serialize for transaction hash calculation (excludes some fields)
|
|
127
|
+
* @param {BufferWriter} [writer] - Optional BufferWriter instance to write to
|
|
128
|
+
* @returns {BufferWriter} The BufferWriter containing serialized transaction data
|
|
129
|
+
*/
|
|
130
|
+
toBufferWriter(forTxHash: boolean, writer?: BufferWriter): BufferWriter;
|
|
131
|
+
/**
|
|
132
|
+
* Initializes the transaction from a buffer.
|
|
133
|
+
* @param {Buffer} buffer - The buffer containing transaction data.
|
|
134
|
+
* @returns {Transaction} The transaction instance.
|
|
135
|
+
*/
|
|
136
|
+
fromBuffer(buffer: Buffer): Transaction;
|
|
137
|
+
/**
|
|
138
|
+
* Reads transaction data from a buffer reader and populates the transaction instance.
|
|
139
|
+
* @param {BufferReader} reader - The buffer reader containing transaction data.
|
|
140
|
+
* @returns {Transaction} The transaction instance with populated data.
|
|
141
|
+
* @throws {Error} If no transaction data is received (reader is finished).
|
|
142
|
+
*/
|
|
143
|
+
fromBufferReader(reader: BufferReader): Transaction;
|
|
144
|
+
version: any;
|
|
145
|
+
nLockTime: any;
|
|
146
|
+
/**
|
|
147
|
+
* Converts the Transaction object to a plain JavaScript object (POJO) for serialization.
|
|
148
|
+
* Includes transaction details like hash, version, inputs, outputs, and lock time.
|
|
149
|
+
* Optionally includes change script, change address, change index, and fee if they are defined.
|
|
150
|
+
* @returns {Object} A plain object representation of the transaction.
|
|
151
|
+
*/
|
|
152
|
+
toObject: () => any;
|
|
153
|
+
toJSON(): any;
|
|
154
|
+
/**
|
|
155
|
+
* Creates a Transaction instance from a plain object or another Transaction.
|
|
156
|
+
* Handles conversion of inputs/outputs and other transaction properties.
|
|
157
|
+
*
|
|
158
|
+
* @param {Object|Transaction} arg - Either a transaction object or Transaction instance
|
|
159
|
+
* @returns {Transaction} The populated Transaction instance
|
|
160
|
+
* @throws {Error} If argument is not an object or Transaction instance
|
|
161
|
+
*/
|
|
162
|
+
fromObject(arg: any | Transaction): Transaction;
|
|
163
|
+
_changeIndex: any;
|
|
164
|
+
_changeScript: Script;
|
|
165
|
+
_changeAddress: any;
|
|
166
|
+
_changeData: any;
|
|
167
|
+
_fee: any;
|
|
168
|
+
private _checkConsistency;
|
|
169
|
+
/**
|
|
170
|
+
* Sets nLockTime so that transaction is not valid until the desired date(a
|
|
171
|
+
* timestamp in seconds since UNIX epoch is also accepted)
|
|
172
|
+
* @param {number|Date} time - The lock time as a timestamp (number) or Date object.
|
|
173
|
+
* @throws {Transaction.LockTimeTooEarly} If the time is a number below NLOCKTIME_BLOCKHEIGHT_LIMIT.
|
|
174
|
+
* @returns {Transaction} The transaction instance for chaining.
|
|
175
|
+
*/
|
|
176
|
+
lockUntilDate(time: number | Date): Transaction;
|
|
177
|
+
/**
|
|
178
|
+
* Sets the transaction's lock time to a specific block height.
|
|
179
|
+
* Validates the height is within allowed bounds (0 <= height < NLOCKTIME_BLOCKHEIGHT_LIMIT).
|
|
180
|
+
* Updates sequence numbers of inputs to enable lock time if using default sequence.
|
|
181
|
+
* @param {number} height - The block height to lock until (must be non-negative and below limit)
|
|
182
|
+
* @returns {Transaction} Returns the transaction instance for chaining
|
|
183
|
+
* @throws {Transaction.BlockHeightTooHigh} If height exceeds block height limit
|
|
184
|
+
* @throws {Transaction.NLockTimeOutOfRange} If height is negative
|
|
185
|
+
*/
|
|
186
|
+
lockUntilBlockHeight(height: number): Transaction;
|
|
187
|
+
/**
|
|
188
|
+
* Returns a semantic version of the transaction's nLockTime.
|
|
189
|
+
* @return {Number|Date}
|
|
190
|
+
* If nLockTime is 0, it returns null,
|
|
191
|
+
* if it is < 500000000, it returns a block height (number)
|
|
192
|
+
* else it returns a Date object.
|
|
193
|
+
*/
|
|
194
|
+
getLockTime(): number | Date;
|
|
195
|
+
/**
|
|
196
|
+
* Converts a hex string into a transaction buffer and initializes the transaction.
|
|
197
|
+
* @param {string} string - Hex string representation of the transaction data.
|
|
198
|
+
* @returns {Transaction} The transaction instance initialized from the hex string.
|
|
199
|
+
*/
|
|
200
|
+
fromString(string: string): Transaction;
|
|
201
|
+
private _newTransaction;
|
|
202
|
+
/**
|
|
203
|
+
* @typedef {Object} Transaction~fromObject
|
|
204
|
+
* @property {string} prevTxId
|
|
205
|
+
* @property {number} outputIndex
|
|
206
|
+
* @property {(Buffer|string|Script)} script
|
|
207
|
+
* @property {number} satoshis
|
|
208
|
+
*/
|
|
209
|
+
/**
|
|
210
|
+
* Add an input to this transaction. This is a high level interface
|
|
211
|
+
* to add an input, for more control, use @{link Transaction#addInput}.
|
|
212
|
+
*
|
|
213
|
+
* Can receive, as output information, the output of bitcoind's `listunspent` command,
|
|
214
|
+
* and a slightly fancier format recognized by opcat:
|
|
215
|
+
*
|
|
216
|
+
* ```
|
|
217
|
+
* {
|
|
218
|
+
* address: 'mszYqVnqKoQx4jcTdJXxwKAissE3Jbrrc1',
|
|
219
|
+
* txId: 'a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458',
|
|
220
|
+
* outputIndex: 0,
|
|
221
|
+
* script: Script.empty(),
|
|
222
|
+
* satoshis: 1020000
|
|
223
|
+
* }
|
|
224
|
+
* ```
|
|
225
|
+
* Where `address` can be either a string or a opcat Address object. The
|
|
226
|
+
* same is true for `script`, which can be a string or a opcat Script.
|
|
227
|
+
*
|
|
228
|
+
* Beware that this resets all the signatures for inputs (in further versions,
|
|
229
|
+
* SIGHASH_SINGLE or SIGHASH_NONE signatures will not be reset).
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```javascript
|
|
233
|
+
* var transaction = new Transaction();
|
|
234
|
+
*
|
|
235
|
+
* // From a pay to public key hash output from bitcoind's listunspent
|
|
236
|
+
* transaction.from({'txid': '0000...', vout: 0, amount: 0.1, scriptPubKey: 'OP_DUP ...'});
|
|
237
|
+
*
|
|
238
|
+
* // From a pay to public key hash output
|
|
239
|
+
* transaction.from({'txId': '0000...', outputIndex: 0, satoshis: 1000, script: 'OP_DUP ...'});
|
|
240
|
+
*
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @param {(Array.<Transaction~fromObject>|Transaction~fromObject)} utxo
|
|
244
|
+
* @param {Array=} pubkeys
|
|
245
|
+
* @param {number=} threshold
|
|
246
|
+
* @returns {Transaction} The transaction instance for chaining.
|
|
247
|
+
*/
|
|
248
|
+
from(utxo: any): Transaction;
|
|
249
|
+
private _fromUTXO;
|
|
250
|
+
/**
|
|
251
|
+
* Add an input to this transaction. The input must be an instance of the `Input` class.
|
|
252
|
+
* It should have information about the Output that it's spending, but if it's not already
|
|
253
|
+
* set, three additional parameters, `outputScript`, `satoshis` and `data` can be provided.
|
|
254
|
+
* @param {Input} input - The input to add
|
|
255
|
+
* @param {Script|string} [outputScript] - The output script (required if input doesn't have output)
|
|
256
|
+
* @param {number} [satoshis] - The satoshis amount (required if input doesn't have output)
|
|
257
|
+
* @param {Buffer|string} [data] - Additional data for the output
|
|
258
|
+
* @returns {Transaction} The transaction instance for chaining
|
|
259
|
+
* @throws {errors.Transaction.NeedMoreInfo} If input has no output and missing required params
|
|
260
|
+
*/
|
|
261
|
+
addInput(input: Input, outputScript?: Script | string, satoshis?: number, data?: Buffer | string): Transaction;
|
|
262
|
+
/**
|
|
263
|
+
* Add an input to this transaction, without checking that the input has information about
|
|
264
|
+
* the output that it's spending.
|
|
265
|
+
*
|
|
266
|
+
* @param {Input} input
|
|
267
|
+
* @return Transaction this, for chaining
|
|
268
|
+
*/
|
|
269
|
+
uncheckedAddInput(input: Input): this;
|
|
270
|
+
/**
|
|
271
|
+
* Returns true if the transaction has enough info on all inputs to be correctly validated
|
|
272
|
+
*
|
|
273
|
+
* @return {boolean}
|
|
274
|
+
*/
|
|
275
|
+
hasAllUtxoInfo(): boolean;
|
|
276
|
+
/**
|
|
277
|
+
* Manually set the fee for this transaction. Beware that this resets all the signatures
|
|
278
|
+
* for inputs (in further versions, SIGHASH_SINGLE or SIGHASH_NONE signatures will not
|
|
279
|
+
* be reset).
|
|
280
|
+
*
|
|
281
|
+
* @param {number} amount satoshis to be sent
|
|
282
|
+
* @return {Transaction} this, for chaining
|
|
283
|
+
*/
|
|
284
|
+
fee(amount: number): Transaction;
|
|
285
|
+
/**
|
|
286
|
+
* Manually set the fee per KB for this transaction. Beware that this resets all the signatures
|
|
287
|
+
* for inputs (in further versions, SIGHASH_SINGLE or SIGHASH_NONE signatures will not
|
|
288
|
+
* be reset).
|
|
289
|
+
*
|
|
290
|
+
* @param {number} amount satoshis per KB to be sent
|
|
291
|
+
* @return {Transaction} this, for chaining
|
|
292
|
+
*/
|
|
293
|
+
feePerKb(amount: number): Transaction;
|
|
294
|
+
_feePerKb: number;
|
|
295
|
+
/**
|
|
296
|
+
* Set the change address for this transaction
|
|
297
|
+
*
|
|
298
|
+
* Beware that this resets all the signatures for inputs (in further versions,
|
|
299
|
+
* SIGHASH_SINGLE or SIGHASH_NONE signatures will not be reset).
|
|
300
|
+
*
|
|
301
|
+
* @param {Address} address An address for change to be sent to.
|
|
302
|
+
* @param {Buffer|string} data The data to be stored in the change output.
|
|
303
|
+
* @return {Transaction} this, for chaining
|
|
304
|
+
*/
|
|
305
|
+
change(address: Address, data: Buffer | string): Transaction;
|
|
306
|
+
/**
|
|
307
|
+
* Gets the change output from the transaction outputs.
|
|
308
|
+
* @returns {Output|null} The change output object if defined, otherwise null.
|
|
309
|
+
*/
|
|
310
|
+
getChangeOutput(): Output | null;
|
|
311
|
+
/**
|
|
312
|
+
* Gets the change address for this transaction.
|
|
313
|
+
* @returns {Address|null} The change address if set, otherwise null.
|
|
314
|
+
*/
|
|
315
|
+
getChangeAddress(): Address | null;
|
|
316
|
+
/**
|
|
317
|
+
* Add an output to the transaction.
|
|
318
|
+
*
|
|
319
|
+
* Beware that this resets all the signatures for inputs (in further versions,
|
|
320
|
+
* SIGHASH_SINGLE or SIGHASH_NONE signatures will not be reset).
|
|
321
|
+
*
|
|
322
|
+
* @param {(string|Address|Array<Address>)} address
|
|
323
|
+
* @param {number} amount in satoshis
|
|
324
|
+
* @return {Transaction} this, for chaining
|
|
325
|
+
*/
|
|
326
|
+
to(address: (string | Address | Array<Address>), amount: number): Transaction;
|
|
327
|
+
/**
|
|
328
|
+
* Add an OP_RETURN output to the transaction.
|
|
329
|
+
*
|
|
330
|
+
* Beware that this resets all the signatures for inputs (in further versions,
|
|
331
|
+
* SIGHASH_SINGLE or SIGHASH_NONE signatures will not be reset).
|
|
332
|
+
*
|
|
333
|
+
* @param {Buffer|string} value the data to be stored in the OP_RETURN output.
|
|
334
|
+
* In case of a string, the UTF-8 representation will be stored
|
|
335
|
+
* @return {Transaction} this, for chaining
|
|
336
|
+
*/
|
|
337
|
+
addData(value: Buffer | string): Transaction;
|
|
338
|
+
/**
|
|
339
|
+
* Add an OP_FALSE | OP_RETURN output to the transaction.
|
|
340
|
+
*
|
|
341
|
+
* Beware that this resets all the signatures for inputs (in further versions,
|
|
342
|
+
* SIGHASH_SINGLE or SIGHASH_NONE signatures will not be reset).
|
|
343
|
+
*
|
|
344
|
+
* @param {Buffer|string} value the data to be stored in the OP_RETURN output.
|
|
345
|
+
* In case of a string, the UTF-8 representation will be stored
|
|
346
|
+
* @return {Transaction} this, for chaining
|
|
347
|
+
*/
|
|
348
|
+
addSafeData(value: Buffer | string): Transaction;
|
|
349
|
+
/**
|
|
350
|
+
* Add an output to the transaction.
|
|
351
|
+
*
|
|
352
|
+
* @param {Output} output the output to add.
|
|
353
|
+
* @return {Transaction} this, for chaining
|
|
354
|
+
*/
|
|
355
|
+
addOutput(output: Output): Transaction;
|
|
356
|
+
/**
|
|
357
|
+
* Remove all outputs from the transaction.
|
|
358
|
+
*
|
|
359
|
+
* @return {Transaction} this, for chaining
|
|
360
|
+
*/
|
|
361
|
+
clearOutputs(): Transaction;
|
|
362
|
+
private _addOutput;
|
|
363
|
+
private _getOutputAmount;
|
|
364
|
+
private _getInputAmount;
|
|
365
|
+
private _updateChangeOutput;
|
|
366
|
+
/**
|
|
367
|
+
* Calculates the fee of the transaction.
|
|
368
|
+
*
|
|
369
|
+
* If there's a fixed fee set, return that.
|
|
370
|
+
*
|
|
371
|
+
* If there is no change output set, the fee is the
|
|
372
|
+
* total value of the outputs minus inputs. Note that
|
|
373
|
+
* a serialized transaction only specifies the value
|
|
374
|
+
* of its outputs. (The value of inputs are recorded
|
|
375
|
+
* in the previous transaction outputs being spent.)
|
|
376
|
+
* This method therefore raises a "MissingPreviousOutput"
|
|
377
|
+
* error when called on a serialized transaction.
|
|
378
|
+
*
|
|
379
|
+
* If there's no fee set and no change address,
|
|
380
|
+
* estimate the fee based on size.
|
|
381
|
+
*
|
|
382
|
+
* @return {Number} fee of this transaction in satoshis
|
|
383
|
+
*/
|
|
384
|
+
getFee(): number;
|
|
385
|
+
private _estimateFee;
|
|
386
|
+
/**
|
|
387
|
+
* Calculates the unspent value (difference between input and output amounts) of the transaction.
|
|
388
|
+
* @returns {number} The unspent value (input amount minus output amount).
|
|
389
|
+
*/
|
|
390
|
+
getUnspentValue(): number;
|
|
391
|
+
private _clearSignatures;
|
|
392
|
+
/**
|
|
393
|
+
* Gets the estimated size of the transaction.
|
|
394
|
+
* @returns {number} The estimated size in bytes.
|
|
395
|
+
*/
|
|
396
|
+
getEstimateSize(): number;
|
|
397
|
+
private _estimateSize;
|
|
398
|
+
private _removeOutput;
|
|
399
|
+
/**
|
|
400
|
+
* Removes an output from the transaction at the specified index and updates the change output.
|
|
401
|
+
* @param {number} index - The index of the output to remove.
|
|
402
|
+
*/
|
|
403
|
+
removeOutput(index: number): void;
|
|
404
|
+
/**
|
|
405
|
+
* Sort a transaction's inputs and outputs according to BIP69
|
|
406
|
+
*
|
|
407
|
+
* @see {https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki}
|
|
408
|
+
* @return {Transaction} this
|
|
409
|
+
*/
|
|
410
|
+
sort(): Transaction;
|
|
411
|
+
/**
|
|
412
|
+
* Randomize this transaction's outputs ordering. The shuffling algorithm is a
|
|
413
|
+
* version of the Fisher-Yates shuffle.
|
|
414
|
+
*
|
|
415
|
+
* @return {Transaction} this
|
|
416
|
+
*/
|
|
417
|
+
shuffleOutputs(): Transaction;
|
|
418
|
+
/**
|
|
419
|
+
* Sort this transaction's outputs, according to a given sorting function that
|
|
420
|
+
* takes an array as argument and returns a new array, with the same elements
|
|
421
|
+
* but with a different order. The argument function MUST NOT modify the order
|
|
422
|
+
* of the original array
|
|
423
|
+
*
|
|
424
|
+
* @param {Function} sortingFunction
|
|
425
|
+
* @return {Transaction} this
|
|
426
|
+
*/
|
|
427
|
+
sortOutputs(sortingFunction: Function): Transaction;
|
|
428
|
+
/**
|
|
429
|
+
* Sort this transaction's inputs, according to a given sorting function that
|
|
430
|
+
* takes an array as argument and returns a new array, with the same elements
|
|
431
|
+
* but with a different order.
|
|
432
|
+
*
|
|
433
|
+
* @param {Function} sortingFunction
|
|
434
|
+
* @return {Transaction} this
|
|
435
|
+
*/
|
|
436
|
+
sortInputs(sortingFunction: Function): Transaction;
|
|
437
|
+
private _newOutputOrder;
|
|
438
|
+
/**
|
|
439
|
+
* Removes an input from the transaction by either its index or txId/outputIndex pair.
|
|
440
|
+
* @param {string|number} txId - Transaction ID (as hex string) or input index if outputIndex is omitted.
|
|
441
|
+
* @param {number} [outputIndex] - Output index of the input to remove (required if txId is string).
|
|
442
|
+
* @throws {Transaction.InvalidIndex} If input index is out of bounds.
|
|
443
|
+
*/
|
|
444
|
+
removeInput(txId: string | number, outputIndex?: number): void;
|
|
445
|
+
/**
|
|
446
|
+
* Sign the transaction using one or more private keys.
|
|
447
|
+
*
|
|
448
|
+
* It tries to sign each input, verifying that the signature will be valid
|
|
449
|
+
* (matches a public key).
|
|
450
|
+
* @param {Buffer|Array<Buffer>} privateKey - Private key(s) to sign the transaction with.
|
|
451
|
+
* @param {number} [sigtype] - Optional signature type.
|
|
452
|
+
* @returns {Transaction} Returns the transaction instance for chaining.
|
|
453
|
+
* @throws {Error} Throws if not all UTXO information is available.
|
|
454
|
+
*/
|
|
455
|
+
sign(privateKey: Buffer | Array<Buffer>, sigtype?: number): Transaction;
|
|
456
|
+
/**
|
|
457
|
+
* Generates signatures for all inputs in the transaction using the provided private key.
|
|
458
|
+
* @param {string|PrivateKey} privKey - The private key to sign with (can be string or PrivateKey instance).
|
|
459
|
+
* @param {number} [sigtype=Signature.SIGHASH_ALL] - The signature hash type (defaults to SIGHASH_ALL).
|
|
460
|
+
* @returns {Array} Array of generated signatures for the transaction inputs.
|
|
461
|
+
*/
|
|
462
|
+
getSignatures(privKey: string | PrivateKey, sigtype?: number): any[];
|
|
463
|
+
/**
|
|
464
|
+
* Add a signature to the transaction
|
|
465
|
+
*
|
|
466
|
+
* @param {Object} signature
|
|
467
|
+
* @param {number} signature.inputIndex
|
|
468
|
+
* @param {number} signature.sigtype
|
|
469
|
+
* @param {PublicKey} signature.publicKey
|
|
470
|
+
* @param {Signature} signature.signature
|
|
471
|
+
* @return {Transaction} this, for chaining
|
|
472
|
+
*/
|
|
473
|
+
applySignature(signature: {
|
|
474
|
+
inputIndex: number;
|
|
475
|
+
sigtype: number;
|
|
476
|
+
publicKey: PublicKey;
|
|
477
|
+
signature: Signature;
|
|
478
|
+
}): Transaction;
|
|
479
|
+
/**
|
|
480
|
+
* Checks if all inputs in the transaction are fully signed.
|
|
481
|
+
* @returns {boolean} True if all inputs have valid signatures, false otherwise.
|
|
482
|
+
* @throws {errors.Transaction.UnableToVerifySignature} If any input has an unrecognized script kind
|
|
483
|
+
* or insufficient information to verify signatures (common when deserializing transactions).
|
|
484
|
+
*/
|
|
485
|
+
isFullySigned(): boolean;
|
|
486
|
+
/**
|
|
487
|
+
* Validates a signature for a transaction input.
|
|
488
|
+
* @param {Object} signature - The signature object to validate.
|
|
489
|
+
* @throws {errors.Transaction.UnableToVerifySignature} If the input script is unrecognized or lacks execution info.
|
|
490
|
+
* @returns {boolean} True if the signature is valid for the specified input.
|
|
491
|
+
*/
|
|
492
|
+
isValidSignature(signature: any): boolean;
|
|
493
|
+
/**
|
|
494
|
+
* Verifies a signature for this transaction.
|
|
495
|
+
* @param {Buffer} sig - The signature to verify.
|
|
496
|
+
* @param {Buffer} pubkey - The public key corresponding to the signature.
|
|
497
|
+
* @param {number} nin - The input index being signed.
|
|
498
|
+
* @returns {boolean} True if the signature is valid, false otherwise.
|
|
499
|
+
*/
|
|
500
|
+
verifySignature(sig: Buffer, pubkey: Buffer, nin: number): boolean;
|
|
501
|
+
/**
|
|
502
|
+
* Check that a transaction passes basic sanity tests. If not, return a string
|
|
503
|
+
* describing the error. This function contains the same logic as
|
|
504
|
+
* CheckTransaction in bitcoin core.
|
|
505
|
+
*
|
|
506
|
+
* Checks include:
|
|
507
|
+
* - Non-empty inputs and outputs
|
|
508
|
+
* - Valid output satoshis (non-negative, not exceeding MAX_MONEY)
|
|
509
|
+
* - No duplicate inputs
|
|
510
|
+
* - Coinbase script size validation (if coinbase)
|
|
511
|
+
* - Input null checks and verification (if not coinbase and notVerifyInput is false)
|
|
512
|
+
*
|
|
513
|
+
* @param {boolean} [notVerifyInput=false] - Whether to skip input verification
|
|
514
|
+
* @returns {true|string} Returns true if valid, or an error message string if invalid
|
|
515
|
+
*/
|
|
516
|
+
verify(notVerifyInput?: boolean): true | string;
|
|
517
|
+
/**
|
|
518
|
+
* Checks if the transaction is a coinbase transaction.
|
|
519
|
+
* A coinbase transaction has exactly one input and that input is null.
|
|
520
|
+
* @returns {boolean} True if the transaction is a coinbase, false otherwise.
|
|
521
|
+
*/
|
|
522
|
+
isCoinbase(): boolean;
|
|
523
|
+
/**
|
|
524
|
+
* Sets the input script for a transaction input.
|
|
525
|
+
* @param {number|Object} options - Either an input index number or an options object
|
|
526
|
+
* @param {number} [options.inputIndex=0] - Input index if options is an object
|
|
527
|
+
* @param {string} [options.privateKey] - Private key for signing
|
|
528
|
+
* @param {number} [options.sigtype=Signature.SIGHASH_ALL] - Signature hash type
|
|
529
|
+
* @param {boolean} [options.isLowS=false] - Whether to use low-S signatures
|
|
530
|
+
* @param {Function|Script} unlockScriptOrCallback - Either a script or callback function that returns a script
|
|
531
|
+
* @returns {Transaction} Returns the transaction instance for chaining
|
|
532
|
+
*/
|
|
533
|
+
setInputScript(options: number | any, unlockScriptOrCallback: Function | Script): Transaction;
|
|
534
|
+
/**
|
|
535
|
+
* Sets the sequence number for a specific transaction input.
|
|
536
|
+
* @param {number} inputIndex - The index of the input to update.
|
|
537
|
+
* @param {number} sequence - The sequence number to set.
|
|
538
|
+
* @returns {Transaction} Returns the transaction instance for chaining.
|
|
539
|
+
*/
|
|
540
|
+
setInputSequence(inputIndex: number, sequence: number): Transaction;
|
|
541
|
+
/**
|
|
542
|
+
* Sets an output at the specified index, either directly or via a callback function.
|
|
543
|
+
* If a callback is provided, it will be invoked with the transaction instance to generate the output value.
|
|
544
|
+
* Automatically updates the change output after setting.
|
|
545
|
+
* @param {number} outputIndex - The index of the output to set
|
|
546
|
+
* @param {any|Function} outputOrcb - The output value or a callback function that returns the output value
|
|
547
|
+
* @returns {Transaction} Returns the transaction instance for chaining
|
|
548
|
+
*/
|
|
549
|
+
setOutput(outputIndex: number, outputOrcb: any | Function): Transaction;
|
|
550
|
+
/**
|
|
551
|
+
* Seals the transaction by processing all outputs and inputs.
|
|
552
|
+
* - For each output, executes the registered callback to generate the final output.
|
|
553
|
+
* - Updates the change output if applicable.
|
|
554
|
+
* - For each input, generates and sets the unlock script using the registered callback.
|
|
555
|
+
* - If a private key is provided, signs the transaction.
|
|
556
|
+
* - Marks the transaction as sealed and returns the instance.
|
|
557
|
+
* @returns {Transaction} The sealed transaction instance.
|
|
558
|
+
*/
|
|
559
|
+
seal(): Transaction;
|
|
560
|
+
/**
|
|
561
|
+
* Sets the lock time for the transaction.
|
|
562
|
+
* @param {number} nLockTime - The lock time to set.
|
|
563
|
+
* @returns {Transaction} Returns the transaction instance for chaining.
|
|
564
|
+
*/
|
|
565
|
+
setLockTime(nLockTime: number): Transaction;
|
|
566
|
+
/**
|
|
567
|
+
* Gets the amount of change (in satoshis) for this transaction.
|
|
568
|
+
* @returns {number} The change amount in satoshis, or 0 if no change exists.
|
|
569
|
+
*/
|
|
570
|
+
getChangeAmount(): number;
|
|
571
|
+
/**
|
|
572
|
+
* Gets the estimated fee for the transaction.
|
|
573
|
+
* @returns {number} The estimated fee value.
|
|
574
|
+
*/
|
|
575
|
+
getEstimateFee(): number;
|
|
576
|
+
/**
|
|
577
|
+
* Checks if the transaction's fee rate meets or exceeds the expected rate.
|
|
578
|
+
* @param {number} [feePerKb] - Optional fee per KB (in satoshis). Falls back to instance or default fee.
|
|
579
|
+
* @returns {boolean} True if actual fee rate (fee/size) >= expected rate.
|
|
580
|
+
*/
|
|
581
|
+
checkFeeRate(feePerKb?: number): boolean;
|
|
582
|
+
/**
|
|
583
|
+
* Serializes the transaction's inputs (prevTxId and outputIndex) into a hex string.
|
|
584
|
+
* @returns {string} Hex-encoded serialized input data.
|
|
585
|
+
*/
|
|
586
|
+
prevouts(): string;
|
|
587
|
+
/**
|
|
588
|
+
* Checks if the transaction is sealed.
|
|
589
|
+
* @returns {boolean} True if the transaction is sealed, false otherwise.
|
|
590
|
+
*/
|
|
591
|
+
isSealed(): boolean;
|
|
592
|
+
/**
|
|
593
|
+
* Gets the preimage for a transaction input.
|
|
594
|
+
* @param {number} inputIndex - The index of the input to get the preimage for.
|
|
595
|
+
* @param {number} [sigtype=Signature.SIGHASH_ALL] - The signature hash type.
|
|
596
|
+
* @param {boolean} [isLowS=false] - Whether to use low-S signatures.
|
|
597
|
+
* @returns {*} The preimage for the specified input.
|
|
598
|
+
*/
|
|
599
|
+
getPreimage(inputIndex: number, sigtype?: number, isLowS?: boolean): any;
|
|
600
|
+
/**
|
|
601
|
+
* Gets the signature(s) for a transaction input.
|
|
602
|
+
* @param {number} inputIndex - Index of the input to sign.
|
|
603
|
+
* @param {Array|Buffer|string} [privateKeys] - Private key(s) to sign with. Defaults to input's privateKey or transaction's _privateKey.
|
|
604
|
+
* @param {number} [sigtypes] - Signature hash type. Defaults to SIGHASH_ALL.
|
|
605
|
+
* @returns {string|Array} - Single signature hex string or array of signatures. Returns empty array if no privateKeys provided.
|
|
606
|
+
*/
|
|
607
|
+
getSignature(inputIndex: number, privateKeys?: any[] | Buffer | string, sigtypes?: number): string | any[];
|
|
608
|
+
/**
|
|
609
|
+
* Adds an input to the transaction from a previous transaction's output.
|
|
610
|
+
* @param {Transaction} prevTx - The previous transaction containing the output to spend.
|
|
611
|
+
* @param {number} [outputIndex=0] - The index of the output in the previous transaction.
|
|
612
|
+
* @returns {Transaction} The transaction instance for chaining.
|
|
613
|
+
* @throws {Error} If prevTx is not a valid Transaction.
|
|
614
|
+
*/
|
|
615
|
+
addInputFromPrevTx(prevTx: Transaction, outputIndex?: number): Transaction;
|
|
616
|
+
/**
|
|
617
|
+
* Adds a dummy input to the transaction with the specified script and satoshis.
|
|
618
|
+
* The dummy input uses a placeholder script and a fixed previous transaction ID.
|
|
619
|
+
*
|
|
620
|
+
* @param {Script} script - The script to use for the output of the dummy input.
|
|
621
|
+
* @param {number} satoshis - The amount in satoshis for the output of the dummy input.
|
|
622
|
+
* @returns {Transaction} The transaction instance for chaining.
|
|
623
|
+
*/
|
|
624
|
+
addDummyInput(script: Script, satoshis: number): Transaction;
|
|
625
|
+
/**
|
|
626
|
+
* Same as change(addresss), but using the address of Transaction.DUMMY_PRIVATEKEY as default change address
|
|
627
|
+
*
|
|
628
|
+
* Beware that this resets all the signatures for inputs (in further versions,
|
|
629
|
+
* SIGHASH_SINGLE or SIGHASH_NONE signatures will not be reset).
|
|
630
|
+
*
|
|
631
|
+
* @return {Transaction} this, for chaining
|
|
632
|
+
*/
|
|
633
|
+
dummyChange(): Transaction;
|
|
634
|
+
/**
|
|
635
|
+
* Verifies the script for a specific transaction input.
|
|
636
|
+
* @param {number} inputIndex - Index of the input to verify.
|
|
637
|
+
* @throws {errors.Transaction.Input.MissingInput} If input at given index doesn't exist.
|
|
638
|
+
* @returns {boolean} True if the script verification passes.
|
|
639
|
+
*/
|
|
640
|
+
verifyScript(inputIndex: number): boolean;
|
|
641
|
+
/**
|
|
642
|
+
* Verifies the input script for a specific input index in the transaction.
|
|
643
|
+
* @param {number} inputIndex - The index of the input to verify.
|
|
644
|
+
* @returns {boolean} True if the input script is valid, false otherwise.
|
|
645
|
+
*/
|
|
646
|
+
verifyInputScript(inputIndex: number): boolean;
|
|
647
|
+
/**
|
|
648
|
+
* Gets the amount of satoshis for a specific transaction input.
|
|
649
|
+
* @param {number} inputIndex - The index of the input to query.
|
|
650
|
+
* @returns {number} The satoshis amount of the specified input.
|
|
651
|
+
* @throws {errors.Transaction.Input.MissingInput} If the input at the specified index doesn't exist.
|
|
652
|
+
*/
|
|
653
|
+
getInputAmount(inputIndex: number): number;
|
|
654
|
+
/**
|
|
655
|
+
* Gets the output amount in satoshis for the specified output index.
|
|
656
|
+
* @param {number} outputIndex - The index of the output to retrieve.
|
|
657
|
+
* @returns {number} The output amount in satoshis.
|
|
658
|
+
* @throws {errors.Transaction.MissingOutput} If the output index is invalid.
|
|
659
|
+
*/
|
|
660
|
+
getOutputAmount(outputIndex: number): number;
|
|
661
|
+
}
|
|
662
|
+
declare namespace Transaction {
|
|
663
|
+
export { DUST_AMOUNT, FEE_SECURITY_MARGIN, MAX_MONEY, NLOCKTIME_BLOCKHEIGHT_LIMIT, NLOCKTIME_MAX_VALUE, FEE_PER_KB, DUMMY_PRIVATEKEY, fromString, fromBuffer, fromObject, shallowCopy, Input, Output, Sighash, UnspentOutput, TransactionSignature as Signature, Transaction };
|
|
664
|
+
}
|
|
665
|
+
import BufferWriter = require("../encoding/bufferwriter.cjs");
|
|
666
|
+
import BufferReader = require("../encoding/bufferreader.cjs");
|
|
667
|
+
import Script = require("../script/script.cjs");
|
|
668
|
+
import Input = require("./input/input.cjs");
|
|
669
|
+
import Address = require("../address.cjs");
|
|
670
|
+
import Output = require("./output.cjs");
|
|
671
|
+
import PrivateKey = require("../privatekey.cjs");
|
|
672
|
+
import Signature = require("../crypto/signature.cjs");
|
|
673
|
+
declare var DUST_AMOUNT: number;
|
|
674
|
+
declare var FEE_SECURITY_MARGIN: number;
|
|
675
|
+
declare var MAX_MONEY: number;
|
|
676
|
+
declare var NLOCKTIME_BLOCKHEIGHT_LIMIT: number;
|
|
677
|
+
declare var NLOCKTIME_MAX_VALUE: number;
|
|
678
|
+
declare var FEE_PER_KB: number;
|
|
679
|
+
declare var DUMMY_PRIVATEKEY: PrivateKey;
|
|
680
|
+
/**
|
|
681
|
+
* Creates a Transaction instance from a raw hexadecimal string.
|
|
682
|
+
* @param {string} rawHex - The hexadecimal string representation of the transaction.
|
|
683
|
+
* @returns {Transaction} A new Transaction instance populated from the input string.
|
|
684
|
+
*/
|
|
685
|
+
declare function fromString(rawHex: string): Transaction;
|
|
686
|
+
/**
|
|
687
|
+
* Creates a Transaction instance from a buffer.
|
|
688
|
+
* @param {Buffer} buffer - The input buffer containing transaction data.
|
|
689
|
+
* @returns {Transaction} A new Transaction instance populated from the buffer.
|
|
690
|
+
*/
|
|
691
|
+
declare function fromBuffer(buffer: Buffer): Transaction;
|
|
692
|
+
/**
|
|
693
|
+
* Creates a Transaction instance from a plain object.
|
|
694
|
+
* @param {Object} obj - The plain object to convert to a Transaction.
|
|
695
|
+
* @returns {Transaction} A new Transaction instance populated from the object.
|
|
696
|
+
*/
|
|
697
|
+
declare function fromObject(obj: any): Transaction;
|
|
698
|
+
/**
|
|
699
|
+
* Create a 'shallow' copy of the transaction, by serializing and deserializing
|
|
700
|
+
* it dropping any additional information that inputs and outputs may have hold
|
|
701
|
+
* @param {Transaction} transaction - The transaction to copy.
|
|
702
|
+
* @returns {Transaction} A new Transaction instance with the same data.
|
|
703
|
+
*/
|
|
704
|
+
declare function shallowCopy(transaction: Transaction): Transaction;
|
|
705
|
+
import Sighash = require("./sighash.cjs");
|
|
706
|
+
import UnspentOutput = require("./unspentoutput.cjs");
|
|
707
|
+
import TransactionSignature = require("./signature.cjs");
|
|
708
|
+
/**
|
|
709
|
+
* ~fromObject
|
|
710
|
+
*/
|
|
711
|
+
type Transaction = {
|
|
712
|
+
prevTxId: string;
|
|
713
|
+
outputIndex: number;
|
|
714
|
+
script: (Buffer | string | Script);
|
|
715
|
+
satoshis: number;
|
|
716
|
+
};
|