@opcat-labs/opcat 1.0.1 → 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 +6 -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 +18 -4
- 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,228 @@
|
|
|
1
|
+
export = Interpreter;
|
|
2
|
+
/**
|
|
3
|
+
* Bitcoin transactions contain scripts. Each input has a script called the
|
|
4
|
+
* scriptSig, and each output has a script called the scriptPubkey. To validate
|
|
5
|
+
* an input, the input's script is concatenated with the referenced output script,
|
|
6
|
+
* and the result is executed. If at the end of execution the stack contains a
|
|
7
|
+
* "true" value, then the transaction is valid.
|
|
8
|
+
*
|
|
9
|
+
* The primary way to use this class is via the verify function.
|
|
10
|
+
* e.g., Interpreter().verify( ... );
|
|
11
|
+
* @constructor
|
|
12
|
+
* @param {Object} [obj] - Optional object to initialize the interpreter with.
|
|
13
|
+
* @returns {Interpreter} A new Interpreter instance.
|
|
14
|
+
*/
|
|
15
|
+
declare function Interpreter(obj?: any): Interpreter;
|
|
16
|
+
declare class Interpreter {
|
|
17
|
+
/**
|
|
18
|
+
* Bitcoin transactions contain scripts. Each input has a script called the
|
|
19
|
+
* scriptSig, and each output has a script called the scriptPubkey. To validate
|
|
20
|
+
* an input, the input's script is concatenated with the referenced output script,
|
|
21
|
+
* and the result is executed. If at the end of execution the stack contains a
|
|
22
|
+
* "true" value, then the transaction is valid.
|
|
23
|
+
*
|
|
24
|
+
* The primary way to use this class is via the verify function.
|
|
25
|
+
* e.g., Interpreter().verify( ... );
|
|
26
|
+
* @constructor
|
|
27
|
+
* @param {Object} [obj] - Optional object to initialize the interpreter with.
|
|
28
|
+
* @returns {Interpreter} A new Interpreter instance.
|
|
29
|
+
*/
|
|
30
|
+
constructor(obj?: any);
|
|
31
|
+
/**
|
|
32
|
+
* Verifies a Script by executing it and returns true if it is valid.
|
|
33
|
+
* This function needs to be provided with the scriptSig and the scriptPubkey
|
|
34
|
+
* separately.
|
|
35
|
+
* @param {Script} scriptSig - the script's first part (corresponding to the tx input)
|
|
36
|
+
* @param {Script} scriptPubkey - the script's last part (corresponding to the tx output)
|
|
37
|
+
* @param {Transaction=} tx - the Transaction containing the scriptSig in one input (used
|
|
38
|
+
* to check signature validity for some opcodes like OP_CHECKSIG)
|
|
39
|
+
* @param {number} nin - index of the transaction input containing the scriptSig verified.
|
|
40
|
+
* @param {number} flags - evaluation flags. See Interpreter.SCRIPT_* constants
|
|
41
|
+
* @param {number} satoshisBN - amount in satoshis of the input to be verified (when FORKID signhash is used)
|
|
42
|
+
*
|
|
43
|
+
* Translated from bitcoind's VerifyScript
|
|
44
|
+
*/
|
|
45
|
+
verify(scriptSig: Script, scriptPubkey: Script, tx?: Transaction | undefined, nin: number, flags: number, satoshisBN: number): boolean;
|
|
46
|
+
errstr: any;
|
|
47
|
+
/**
|
|
48
|
+
* Initializes the interpreter instance with default values.
|
|
49
|
+
* Sets up empty stacks, resets program counter and execution flags,
|
|
50
|
+
* and initializes state tracking variables for script execution.
|
|
51
|
+
*/
|
|
52
|
+
initialize(): void;
|
|
53
|
+
stack: any;
|
|
54
|
+
altstack: any;
|
|
55
|
+
pc: any;
|
|
56
|
+
pbegincodehash: any;
|
|
57
|
+
nOpCount: any;
|
|
58
|
+
vfExec: any;
|
|
59
|
+
vfElse: any;
|
|
60
|
+
flags: any;
|
|
61
|
+
nonTopLevelReturnAfterGenesis: boolean;
|
|
62
|
+
returned: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Updates the interpreter's state with provided values.
|
|
65
|
+
* @param {Object} obj - Object containing properties to update
|
|
66
|
+
* @param {Buffer} [obj.script] - Script buffer
|
|
67
|
+
* @param {Object} [obj.tx] - Transaction object
|
|
68
|
+
* @param {boolean} [obj.nin] - Non-input flag
|
|
69
|
+
* @param {BN} [obj.satoshisBN] - Satoshis as BN.js instance
|
|
70
|
+
* @param {Array} [obj.stack] - Main stack
|
|
71
|
+
* @param {Array} [obj.altstack] - Alternate stack
|
|
72
|
+
* @param {number} [obj.pc] - Program counter
|
|
73
|
+
* @param {number} [obj.pbegincodehash] - Begin code hash position
|
|
74
|
+
* @param {number} [obj.nOpCount] - Operation count
|
|
75
|
+
* @param {Array} [obj.vfExec] - Execution flags
|
|
76
|
+
* @param {Array} [obj.vfElse] - Else flags
|
|
77
|
+
* @param {string} [obj.errstr] - Error string
|
|
78
|
+
* @param {number} [obj.flags] - Interpreter flags
|
|
79
|
+
*/
|
|
80
|
+
set(obj: {
|
|
81
|
+
script?: Buffer;
|
|
82
|
+
tx?: any;
|
|
83
|
+
nin?: boolean;
|
|
84
|
+
satoshisBN?: BN;
|
|
85
|
+
stack?: any[];
|
|
86
|
+
altstack?: any[];
|
|
87
|
+
pc?: number;
|
|
88
|
+
pbegincodehash?: number;
|
|
89
|
+
nOpCount?: number;
|
|
90
|
+
vfExec?: any[];
|
|
91
|
+
vfElse?: any[];
|
|
92
|
+
errstr?: string;
|
|
93
|
+
flags?: number;
|
|
94
|
+
}): void;
|
|
95
|
+
script: any;
|
|
96
|
+
tx: any;
|
|
97
|
+
nin: any;
|
|
98
|
+
satoshisBN: any;
|
|
99
|
+
/**
|
|
100
|
+
* Returns a subset of the script starting from the most recent OP_CODESEPARATOR.
|
|
101
|
+
* @returns {Script} A new Script instance containing the sliced chunks.
|
|
102
|
+
*/
|
|
103
|
+
subscript(): Script;
|
|
104
|
+
/**
|
|
105
|
+
* Checks if a signature encoding is valid according to the interpreter's flags.
|
|
106
|
+
* - For empty signatures: always valid (used for compact invalid signatures in CHECK(MULTI)SIG)
|
|
107
|
+
* - With DERSIG/STRICTENC flags: validates DER encoding and strict encoding rules
|
|
108
|
+
* - With LOW_S flag: ensures signature uses low S value
|
|
109
|
+
* - With STRICTENC flag: validates defined hash type
|
|
110
|
+
* @param {Buffer} buf - The signature buffer to validate
|
|
111
|
+
* @returns {boolean} True if valid, false otherwise (sets errstr on failure)
|
|
112
|
+
*/
|
|
113
|
+
checkSignatureEncoding(buf: Buffer): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Checks if the provided public key buffer is valid according to strict encoding rules.
|
|
116
|
+
* Sets an error message if validation fails under SCRIPT_VERIFY_STRICTENC flag.
|
|
117
|
+
* @param {Buffer} buf - The public key buffer to validate.
|
|
118
|
+
* @returns {boolean} True if valid, false otherwise (with error string set).
|
|
119
|
+
*/
|
|
120
|
+
checkPubkeyEncoding(buf: Buffer): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Evaluates a script by executing each opcode step-by-step.
|
|
123
|
+
* Performs size checks on the script and stacks before execution.
|
|
124
|
+
*
|
|
125
|
+
* Based on bitcoind's EvalScript function, with the inner loop moved to `Interpreter.prototype.step()`
|
|
126
|
+
* bitcoind commit: b5d1b1092998bc95313856d535c632ea5a8f9104
|
|
127
|
+
* @param {string} scriptType - The type of script being evaluated
|
|
128
|
+
* @returns {boolean} True if evaluation succeeds, false if any error occurs
|
|
129
|
+
* @throws {Error} If an unknown error occurs during evaluation
|
|
130
|
+
*/
|
|
131
|
+
evaluate(scriptType: string): boolean;
|
|
132
|
+
private _callbackStep;
|
|
133
|
+
private _callbackStack;
|
|
134
|
+
/**
|
|
135
|
+
* Checks a locktime parameter with the transaction's locktime.
|
|
136
|
+
* There are two times of nLockTime: lock-by-blockheight and lock-by-blocktime,
|
|
137
|
+
* distinguished by whether nLockTime < LOCKTIME_THRESHOLD = 500000000
|
|
138
|
+
*
|
|
139
|
+
* See the corresponding code on bitcoin core:
|
|
140
|
+
* https://github.com/bitcoin/bitcoin/blob/ffd75adce01a78b3461b3ff05bcc2b530a9ce994/src/script/interpreter.cpp#L1129
|
|
141
|
+
*
|
|
142
|
+
* @param {BN} nLockTime the locktime read from the script
|
|
143
|
+
* @return {boolean} true if the transaction's locktime is less than or equal to
|
|
144
|
+
* the transaction's locktime
|
|
145
|
+
*/
|
|
146
|
+
checkLockTime(nLockTime: BN): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Checks a sequence parameter with the transaction's sequence.
|
|
149
|
+
* @param {BN} nSequence the sequence read from the script
|
|
150
|
+
* @return {boolean} true if the transaction's sequence is less than or equal to
|
|
151
|
+
* the transaction's sequence
|
|
152
|
+
*/
|
|
153
|
+
checkSequence(nSequence: BN): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Executes a single step in the script interpreter.
|
|
156
|
+
*
|
|
157
|
+
* This method processes the current opcode in the script, performs the corresponding operation,
|
|
158
|
+
* and updates the stack or interpreter state accordingly. It handles various opcode types including
|
|
159
|
+
* stack operations, arithmetic, bitwise logic, cryptographic operations, and control flow.
|
|
160
|
+
*
|
|
161
|
+
* Based on the inner loop of bitcoind's EvalScript function
|
|
162
|
+
* bitcoind commit: b5d1b1092998bc95313856d535c632ea5a8f9104
|
|
163
|
+
* @param {string} scriptType - The type of script being executed (e.g., scriptPubkey, scriptSig).
|
|
164
|
+
* @returns {boolean} Returns `true` if the step executed successfully, or `false` if an error occurred.
|
|
165
|
+
* Errors are stored in `this.errstr`.
|
|
166
|
+
*/
|
|
167
|
+
step(scriptType: string): boolean;
|
|
168
|
+
}
|
|
169
|
+
declare namespace Interpreter {
|
|
170
|
+
function getTrue(): Buffer;
|
|
171
|
+
function getFalse(): Buffer;
|
|
172
|
+
let MAX_SCRIPT_ELEMENT_SIZE: number;
|
|
173
|
+
let MAXIMUM_ELEMENT_SIZE: number;
|
|
174
|
+
let LOCKTIME_THRESHOLD: number;
|
|
175
|
+
let LOCKTIME_THRESHOLD_BN: BN;
|
|
176
|
+
let SCRIPT_VERIFY_NONE: number;
|
|
177
|
+
let SCRIPT_VERIFY_STRICTENC: number;
|
|
178
|
+
let SCRIPT_VERIFY_DERSIG: number;
|
|
179
|
+
let SCRIPT_VERIFY_LOW_S: number;
|
|
180
|
+
let SCRIPT_VERIFY_NULLDUMMY: number;
|
|
181
|
+
let SCRIPT_VERIFY_SIGPUSHONLY: number;
|
|
182
|
+
let SCRIPT_VERIFY_MINIMALDATA: number;
|
|
183
|
+
let SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS: number;
|
|
184
|
+
let SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY: number;
|
|
185
|
+
let SCRIPT_VERIFY_CHECKSEQUENCEVERIFY: number;
|
|
186
|
+
let SCRIPT_VERIFY_NULLFAIL: number;
|
|
187
|
+
let SCRIPT_VERIFY_COMPRESSED_PUBKEYTYPE: number;
|
|
188
|
+
let SCRIPT_ENABLE_MONOLITH_OPCODES: number;
|
|
189
|
+
let SCRIPT_ENABLE_MAGNETIC_OPCODES: number;
|
|
190
|
+
let SEQUENCE_LOCKTIME_DISABLE_FLAG: number;
|
|
191
|
+
let SEQUENCE_LOCKTIME_TYPE_FLAG: number;
|
|
192
|
+
let SEQUENCE_LOCKTIME_MASK: number;
|
|
193
|
+
let MAX_SCRIPT_SIZE: number;
|
|
194
|
+
let MAX_OPCODE_COUNT: number;
|
|
195
|
+
let DEFAULT_FLAGS: number;
|
|
196
|
+
/**
|
|
197
|
+
* Casts a buffer to a boolean value.
|
|
198
|
+
* Returns true if any byte in the buffer is non-zero (except for the special case of negative zero).
|
|
199
|
+
* Returns false if all bytes are zero or if the last byte is 0x80 (negative zero case).
|
|
200
|
+
* @param {Buffer} buf - The input buffer to check
|
|
201
|
+
* @returns {boolean} The boolean representation of the buffer
|
|
202
|
+
*/
|
|
203
|
+
function castToBool(buf: Buffer): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Checks if a buffer is minimally encoded (see https://github.com/bitcoincashorg/spec/blob/master/may-2018-reenabled-opcodes.md#op_bin2num) as a number.
|
|
206
|
+
* @param {Buffer} buf - The buffer to check.
|
|
207
|
+
* @param {number} [nMaxNumSize=Interpreter.MAXIMUM_ELEMENT_SIZE] - Maximum allowed size for the buffer.
|
|
208
|
+
* @returns {boolean} True if the buffer is minimally encoded, false otherwise.
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
function _isMinimallyEncoded(buf: Buffer, nMaxNumSize?: number): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Minimally encodes a buffer by removing unnecessary trailing zeros.
|
|
214
|
+
*
|
|
215
|
+
* This function implements minimal encoding rules for script numbers:
|
|
216
|
+
* - Empty buffer remains empty
|
|
217
|
+
* - Last byte must not be 0x00 or 0x80 unless necessary
|
|
218
|
+
* - Single zero byte encodes as empty buffer
|
|
219
|
+
* - Preserves sign bit when trimming
|
|
220
|
+
*
|
|
221
|
+
* @param {Buffer} buf - The input buffer to encode
|
|
222
|
+
* @returns {Buffer} Minimally encoded buffer (may be empty)
|
|
223
|
+
*/
|
|
224
|
+
function _minimallyEncode(buf: Buffer): Buffer;
|
|
225
|
+
}
|
|
226
|
+
import Script = require("../script/script.cjs");
|
|
227
|
+
import Transaction = require("../transaction/transaction.cjs");
|
|
228
|
+
import BN = require("../bn.cjs");
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export = Stack;
|
|
2
|
+
/**
|
|
3
|
+
* Represents a stack structure with optional variable stack support.
|
|
4
|
+
* @constructor
|
|
5
|
+
* @param {Array} rawstack - The initial stack array
|
|
6
|
+
* @param {Array} [varStack] - Optional variable stack array
|
|
7
|
+
*/
|
|
8
|
+
declare function Stack(rawstack: any[], varStack?: any[]): void;
|
|
9
|
+
declare class Stack {
|
|
10
|
+
/**
|
|
11
|
+
* Represents a stack structure with optional variable stack support.
|
|
12
|
+
* @constructor
|
|
13
|
+
* @param {Array} rawstack - The initial stack array
|
|
14
|
+
* @param {Array} [varStack] - Optional variable stack array
|
|
15
|
+
*/
|
|
16
|
+
constructor(rawstack: any[], varStack?: any[]);
|
|
17
|
+
stack: any[];
|
|
18
|
+
varStack: any[];
|
|
19
|
+
pushVar(varName: any): void;
|
|
20
|
+
popVar(): void;
|
|
21
|
+
push(n: any, varName: any): void;
|
|
22
|
+
pop(): any;
|
|
23
|
+
updateTopVars(vars: any): void;
|
|
24
|
+
stacktop(i: any): any;
|
|
25
|
+
vartop(i: any): any;
|
|
26
|
+
slice(start: any, end: any): any[];
|
|
27
|
+
splice(start: any, deleteCount: any, ...items: any[]): any[];
|
|
28
|
+
write(i: any, value: any): void;
|
|
29
|
+
copy(): Stack;
|
|
30
|
+
printVarStack(): void;
|
|
31
|
+
checkConsistency(): void;
|
|
32
|
+
checkConsistencyWithVars(varStack: any): void;
|
|
33
|
+
get length(): number;
|
|
34
|
+
get rawstack(): any[];
|
|
35
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export = Message;
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Message instance from a string or Buffer.
|
|
4
|
+
* @constructor
|
|
5
|
+
* @param {string|Buffer} message - The message content as either a string or Buffer
|
|
6
|
+
* @throws {Error} Will throw if message is not a string or Buffer
|
|
7
|
+
* @returns {Message} A new Message instance containing the message buffer
|
|
8
|
+
*/
|
|
9
|
+
declare function Message(message: string | Buffer): Message;
|
|
10
|
+
declare class Message {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Message instance from a string or Buffer.
|
|
13
|
+
* @constructor
|
|
14
|
+
* @param {string|Buffer} message - The message content as either a string or Buffer
|
|
15
|
+
* @throws {Error} Will throw if message is not a string or Buffer
|
|
16
|
+
* @returns {Message} A new Message instance containing the message buffer
|
|
17
|
+
*/
|
|
18
|
+
constructor(message: string | Buffer);
|
|
19
|
+
messageBuffer: Buffer;
|
|
20
|
+
/**
|
|
21
|
+
* Calculates the magic hash for the message by concatenating magic bytes prefixes
|
|
22
|
+
* with the message buffer and computing a double SHA-256 hash.
|
|
23
|
+
* @returns {Buffer} The resulting 32-byte hash.
|
|
24
|
+
*/
|
|
25
|
+
magicHash(): Buffer;
|
|
26
|
+
private _sign;
|
|
27
|
+
/**
|
|
28
|
+
* Will sign a message with a given bitcoin private key.
|
|
29
|
+
*
|
|
30
|
+
* @param {PrivateKey} privateKey - An instance of PrivateKey
|
|
31
|
+
* @returns {String} A base64 encoded compact signature
|
|
32
|
+
*/
|
|
33
|
+
sign(privateKey: PrivateKey): string;
|
|
34
|
+
/**
|
|
35
|
+
* Verifies the message signature using the provided public key.
|
|
36
|
+
* @param {PublicKey} publicKey - The public key to verify against
|
|
37
|
+
* @param {Signature} signature - The signature to verify
|
|
38
|
+
* @returns {boolean} True if signature is valid, false otherwise
|
|
39
|
+
* @throws {Error} If arguments are not valid PublicKey/Signature instances
|
|
40
|
+
*/
|
|
41
|
+
_verify(publicKey: PublicKey, signature: Signature): boolean;
|
|
42
|
+
error: string;
|
|
43
|
+
/**
|
|
44
|
+
* Will return a boolean of the signature is valid for a given bitcoin address.
|
|
45
|
+
* If it isn't the specific reason is accessible via the "error" member.
|
|
46
|
+
*
|
|
47
|
+
* @param {Address|String} bitcoinAddress - A bitcoin address
|
|
48
|
+
* @param {String} signatureString - A base64 encoded compact signature
|
|
49
|
+
* @returns {Boolean}
|
|
50
|
+
*/
|
|
51
|
+
verify(bitcoinAddress: Address | string, signatureString: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Converts the message to a plain object with hex representation.
|
|
54
|
+
* @returns {Object} An object containing the hex string of the message buffer.
|
|
55
|
+
*/
|
|
56
|
+
toObject(): any;
|
|
57
|
+
/**
|
|
58
|
+
* Converts the Message instance to a JSON string representation.
|
|
59
|
+
* @returns {string} The JSON string representation of the Message object.
|
|
60
|
+
*/
|
|
61
|
+
toJSON(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Converts the message buffer to a string representation.
|
|
64
|
+
* @returns {string} The string representation of the message buffer.
|
|
65
|
+
*/
|
|
66
|
+
toString(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Custom inspect method for Message instances.
|
|
69
|
+
* @returns {string} String representation in format '<Message: [content]>'.
|
|
70
|
+
*/
|
|
71
|
+
inspect(): string;
|
|
72
|
+
}
|
|
73
|
+
declare namespace Message {
|
|
74
|
+
/**
|
|
75
|
+
* Signs a message with the given private key.
|
|
76
|
+
* @param {string|Buffer} message - The message to sign.
|
|
77
|
+
* @param {PrivateKey} privateKey - The private key used for signing.
|
|
78
|
+
* @returns {Message} The signed message instance.
|
|
79
|
+
*/
|
|
80
|
+
function sign(message: string | Buffer, privateKey: PrivateKey): Message;
|
|
81
|
+
function verify(message: any, address: any, signature: any): boolean;
|
|
82
|
+
let MAGIC_BYTES: Buffer;
|
|
83
|
+
/**
|
|
84
|
+
* Instantiate a message from a message string
|
|
85
|
+
*
|
|
86
|
+
* @param {String} str - A string of the message
|
|
87
|
+
* @returns {Message} A new instance of a Message
|
|
88
|
+
*/
|
|
89
|
+
function fromString(str: string): Message;
|
|
90
|
+
/**
|
|
91
|
+
* Instantiate a message from JSON
|
|
92
|
+
*
|
|
93
|
+
* @param {String} json - An JSON string or Object with keys: message
|
|
94
|
+
* @returns {Message} A new instance of a Message
|
|
95
|
+
*/
|
|
96
|
+
function fromJSON(json: string): Message;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a Message instance from an object containing a hex-encoded message.
|
|
99
|
+
* @param {Object} obj - The source object containing the message data.
|
|
100
|
+
* @param {string} obj.messageHex - Hex-encoded message string.
|
|
101
|
+
* @returns {Message} A new Message instance created from the decoded buffer.
|
|
102
|
+
*/
|
|
103
|
+
function fromObject(obj: {
|
|
104
|
+
messageHex: string;
|
|
105
|
+
}): Message;
|
|
106
|
+
}
|
|
107
|
+
import PrivateKey = require("../privatekey.cjs");
|
|
108
|
+
import PublicKey = require("../publickey.cjs");
|
|
109
|
+
import Signature = require("../crypto/signature.cjs");
|
|
110
|
+
import Address = require("../address.cjs");
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
export = Mnemonic;
|
|
2
|
+
/**
|
|
3
|
+
* This is an immutable class that represents a BIP39 Mnemonic code.
|
|
4
|
+
* See BIP39 specification for more info: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
|
|
5
|
+
* A Mnemonic code is a a group of easy to remember words used for the generation
|
|
6
|
+
* of deterministic wallets. A Mnemonic can be used to generate a seed using
|
|
7
|
+
* an optional passphrase, for later generate a HDPrivateKey.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // generate a random mnemonic
|
|
11
|
+
* var mnemonic = new Mnemonic();
|
|
12
|
+
* var phrase = mnemonic.phrase;
|
|
13
|
+
*
|
|
14
|
+
* // use a different language
|
|
15
|
+
* var mnemonic = new Mnemonic(Mnemonic.Words.SPANISH);
|
|
16
|
+
* var xprivkey = mnemonic.toHDPrivateKey();
|
|
17
|
+
*
|
|
18
|
+
* @param {Buffer|string|number} [data] - Input data (Buffer for seed, string for phrase, or number for entropy bits)
|
|
19
|
+
* @param {Array} [wordlist] - Optional wordlist for phrase generation/validation
|
|
20
|
+
* @throws {InvalidArgument} If invalid data type provided
|
|
21
|
+
* @throws {Mnemonic.UnknownWordlist} If phrase language can't be detected
|
|
22
|
+
* @throws {Mnemonic.InvalidMnemonic} If phrase is invalid
|
|
23
|
+
* @throws {InvalidArgument} If invalid ENT value (must be >=128 and divisible by 32)
|
|
24
|
+
* @returns {Mnemonic} A new instance of Mnemonic
|
|
25
|
+
* @constructor
|
|
26
|
+
*/
|
|
27
|
+
declare function Mnemonic(data?: Buffer | string | number, wordlist?: any[]): Mnemonic;
|
|
28
|
+
declare class Mnemonic {
|
|
29
|
+
/**
|
|
30
|
+
* This is an immutable class that represents a BIP39 Mnemonic code.
|
|
31
|
+
* See BIP39 specification for more info: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
|
|
32
|
+
* A Mnemonic code is a a group of easy to remember words used for the generation
|
|
33
|
+
* of deterministic wallets. A Mnemonic can be used to generate a seed using
|
|
34
|
+
* an optional passphrase, for later generate a HDPrivateKey.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // generate a random mnemonic
|
|
38
|
+
* var mnemonic = new Mnemonic();
|
|
39
|
+
* var phrase = mnemonic.phrase;
|
|
40
|
+
*
|
|
41
|
+
* // use a different language
|
|
42
|
+
* var mnemonic = new Mnemonic(Mnemonic.Words.SPANISH);
|
|
43
|
+
* var xprivkey = mnemonic.toHDPrivateKey();
|
|
44
|
+
*
|
|
45
|
+
* @param {Buffer|string|number} [data] - Input data (Buffer for seed, string for phrase, or number for entropy bits)
|
|
46
|
+
* @param {Array} [wordlist] - Optional wordlist for phrase generation/validation
|
|
47
|
+
* @throws {InvalidArgument} If invalid data type provided
|
|
48
|
+
* @throws {Mnemonic.UnknownWordlist} If phrase language can't be detected
|
|
49
|
+
* @throws {Mnemonic.InvalidMnemonic} If phrase is invalid
|
|
50
|
+
* @throws {InvalidArgument} If invalid ENT value (must be >=128 and divisible by 32)
|
|
51
|
+
* @returns {Mnemonic} A new instance of Mnemonic
|
|
52
|
+
* @constructor
|
|
53
|
+
*/
|
|
54
|
+
constructor(data?: Buffer | string | number, wordlist?: any[]);
|
|
55
|
+
/**
|
|
56
|
+
* Will generate a seed based on the mnemonic and optional passphrase. Note that
|
|
57
|
+
* this seed is absolutely NOT the seed that is output by .toSeed(). These are
|
|
58
|
+
* two different seeds. The seed you want to put in here, if any, is just some
|
|
59
|
+
* random byte string. Normally you should rely on the .fromRandom() method.
|
|
60
|
+
*
|
|
61
|
+
* @param {String} [passphrase]
|
|
62
|
+
* @returns {Buffer}
|
|
63
|
+
*/
|
|
64
|
+
toSeed(passphrase?: string): Buffer;
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* Generates a HD Private Key from a Mnemonic.
|
|
68
|
+
* Optionally receive a passphrase and bitcoin network.
|
|
69
|
+
*
|
|
70
|
+
* @param {String=} [passphrase]
|
|
71
|
+
* @param {Network|String|number=} [network] - The network: 'livenet' or 'testnet'
|
|
72
|
+
* @returns {HDPrivateKey}
|
|
73
|
+
*/
|
|
74
|
+
toHDPrivateKey(passphrase?: string | undefined, network?: (Network | string | number) | undefined): HDPrivateKey;
|
|
75
|
+
/**
|
|
76
|
+
* Will return a the string representation of the mnemonic
|
|
77
|
+
*
|
|
78
|
+
* @returns {String} Mnemonic
|
|
79
|
+
*/
|
|
80
|
+
toString(): string;
|
|
81
|
+
/**
|
|
82
|
+
* Will return a string formatted for the console
|
|
83
|
+
*
|
|
84
|
+
* @returns {String} Mnemonic
|
|
85
|
+
*/
|
|
86
|
+
inspect(): string;
|
|
87
|
+
}
|
|
88
|
+
declare namespace Mnemonic {
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new Mnemonic instance with random entropy using the specified wordlist.
|
|
91
|
+
* @param {Array} [wordlist=Mnemonic.Words.ENGLISH] - The wordlist to use for mnemonic generation (defaults to English).
|
|
92
|
+
* @returns {Mnemonic} A new Mnemonic instance with random entropy.
|
|
93
|
+
*/
|
|
94
|
+
export function fromRandom(wordlist?: any[]): Mnemonic;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a Mnemonic instance from a mnemonic string.
|
|
97
|
+
* @param {string} mnemonic - The mnemonic phrase string.
|
|
98
|
+
* @param {string} [wordlist=Mnemonic.Words.ENGLISH] - Optional wordlist (defaults to English).
|
|
99
|
+
* @returns {Mnemonic} A new Mnemonic instance.
|
|
100
|
+
*/
|
|
101
|
+
export function fromString(mnemonic: string, wordlist?: string): Mnemonic;
|
|
102
|
+
/**
|
|
103
|
+
* Will return a boolean if the mnemonic is valid
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
*
|
|
107
|
+
* var valid = Mnemonic.isValid('lab rescue lunch elbow recall phrase perfect donkey biology guess moment husband');
|
|
108
|
+
* // true
|
|
109
|
+
*
|
|
110
|
+
* @param {String} mnemonic - The mnemonic string
|
|
111
|
+
* @param {String} [wordlist] - The wordlist used
|
|
112
|
+
* @returns {boolean}
|
|
113
|
+
*/
|
|
114
|
+
export function isValid(mnemonic: string, wordlist?: string): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Internal function to check if a mnemonic belongs to a wordlist.
|
|
117
|
+
*
|
|
118
|
+
* @param {String} mnemonic - The mnemonic string
|
|
119
|
+
* @param {String} wordlist - The wordlist
|
|
120
|
+
* @returns {boolean}
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
export function _belongsToWordlist(mnemonic: string, wordlist: string): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Internal function to detect the wordlist used to generate the mnemonic.
|
|
126
|
+
*
|
|
127
|
+
* @param {String} mnemonic - The mnemonic string
|
|
128
|
+
* @returns {Array} the wordlist or null
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
export function _getDictionary(mnemonic: string): any[];
|
|
132
|
+
/**
|
|
133
|
+
* Will generate a Mnemonic object based on a seed.
|
|
134
|
+
*
|
|
135
|
+
* @param {Buffer} [seed]
|
|
136
|
+
* @param {string} [wordlist]
|
|
137
|
+
* @returns {Mnemonic}
|
|
138
|
+
*/
|
|
139
|
+
export function fromSeed(seed?: Buffer, wordlist?: string): Mnemonic;
|
|
140
|
+
/**
|
|
141
|
+
* Internal function to generate a random mnemonic
|
|
142
|
+
*
|
|
143
|
+
* @param {Number} ENT - Entropy size, defaults to 128
|
|
144
|
+
* @param {Array} wordlist - Array of words to generate the mnemonic
|
|
145
|
+
* @returns {String} Mnemonic string
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
148
|
+
export function _mnemonic(ENT: number, wordlist: any[]): string;
|
|
149
|
+
/**
|
|
150
|
+
* Internal function to generate mnemonic based on entropy
|
|
151
|
+
*
|
|
152
|
+
* @param {Number} entropy - Entropy buffer
|
|
153
|
+
* @param {Array} wordlist - Array of words to generate the mnemonic
|
|
154
|
+
* @returns {String} Mnemonic string
|
|
155
|
+
* @private
|
|
156
|
+
*/
|
|
157
|
+
export function _entropy2mnemonic(entropy: number, wordlist: any[]): string;
|
|
158
|
+
/**
|
|
159
|
+
* Internal function to create checksum of entropy
|
|
160
|
+
*
|
|
161
|
+
* @param entropy
|
|
162
|
+
* @returns {string} Checksum of entropy length / 32
|
|
163
|
+
* @private
|
|
164
|
+
*/
|
|
165
|
+
export function _entropyChecksum(entropy: any): string;
|
|
166
|
+
export { Words };
|
|
167
|
+
export { pbkdf2 };
|
|
168
|
+
}
|
|
169
|
+
import HDPrivateKey = require("../hdprivatekey.cjs");
|
|
170
|
+
import Words = require("./words/index.cjs");
|
|
171
|
+
import pbkdf2 = require("./pbkdf2.cjs");
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export = pbkdf2;
|
|
2
|
+
/**
|
|
3
|
+
* PDKBF2: Derives a key using PBKDF2 (Password-Based Key Derivation Function 2) with HMAC-SHA512.
|
|
4
|
+
* Credit to: https://github.com/stayradiated/pbkdf2-sha512
|
|
5
|
+
*
|
|
6
|
+
* @param {string|Buffer} key - The input key/password (as string or Buffer)
|
|
7
|
+
* @param {string|Buffer} salt - The salt value (as string or Buffer)
|
|
8
|
+
* @param {number} iterations - Number of iterations to perform
|
|
9
|
+
* @param {number} dkLen - Desired length of the derived key in bytes
|
|
10
|
+
* @returns {Buffer} Derived key as Buffer
|
|
11
|
+
* @throws {TypeError} If key or salt are not strings or Buffers
|
|
12
|
+
* @throws {Error} If requested key length is too long
|
|
13
|
+
*/
|
|
14
|
+
declare function pbkdf2(key: string | Buffer, salt: string | Buffer, iterations: number, dkLen: number): Buffer;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export = Words;
|
|
2
|
+
/**
|
|
3
|
+
* Represents a collection of words for mnemonic purposes.
|
|
4
|
+
* @constructor
|
|
5
|
+
*/
|
|
6
|
+
declare function Words(): void;
|
|
7
|
+
declare class Words {
|
|
8
|
+
}
|
|
9
|
+
declare namespace Words {
|
|
10
|
+
export { chinese as CHINESE };
|
|
11
|
+
export { english as ENGLISH };
|
|
12
|
+
export { french as FRENCH };
|
|
13
|
+
export { italian as ITALIAN };
|
|
14
|
+
export { japanese as JAPANESE };
|
|
15
|
+
export { spanish as SPANISH };
|
|
16
|
+
}
|
|
17
|
+
import chinese = require("./chinese.cjs");
|
|
18
|
+
import english = require("./english.cjs");
|
|
19
|
+
import french = require("./french.cjs");
|
|
20
|
+
import italian = require("./italian.cjs");
|
|
21
|
+
import japanese = require("./japanese.cjs");
|
|
22
|
+
import spanish = require("./spanish.cjs");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export = Network;
|
|
2
|
+
/**
|
|
3
|
+
* A network is merely a map containing values that correspond to version
|
|
4
|
+
* numbers for each bitcoin network. Currently only supporting "livenet"
|
|
5
|
+
* (a.k.a. "mainnet"), "testnet", "regtest".
|
|
6
|
+
* @constructor
|
|
7
|
+
*/
|
|
8
|
+
declare function Network(): void;
|
|
9
|
+
declare class Network {
|
|
10
|
+
toString(): any;
|
|
11
|
+
}
|