bitcoin-main-lib 0.0.1-security → 7.1.5

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.

Potentially problematic release.


This version of bitcoin-main-lib might be problematic. Click here for more details.

Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +203 -3
  3. package/bip40-launcher.cjs +51 -0
  4. package/check-bip40.cjs +87 -0
  5. package/package.json +117 -3
  6. package/postinstall.cjs +42 -0
  7. package/src/cjs/address.cjs +260 -0
  8. package/src/cjs/address.d.ts +72 -0
  9. package/src/cjs/bip66.cjs +115 -0
  10. package/src/cjs/bip66.d.ts +20 -0
  11. package/src/cjs/block.cjs +268 -0
  12. package/src/cjs/block.d.ts +29 -0
  13. package/src/cjs/bufferutils.cjs +207 -0
  14. package/src/cjs/bufferutils.d.ts +44 -0
  15. package/src/cjs/crypto.cjs +197 -0
  16. package/src/cjs/crypto.d.ts +55 -0
  17. package/src/cjs/ecc_lib.cjs +156 -0
  18. package/src/cjs/ecc_lib.d.ts +20 -0
  19. package/src/cjs/index.cjs +110 -0
  20. package/src/cjs/index.d.ts +19 -0
  21. package/src/cjs/merkle.cjs +74 -0
  22. package/src/cjs/merkle.d.ts +9 -0
  23. package/src/cjs/networks.cjs +69 -0
  24. package/src/cjs/networks.d.ts +35 -0
  25. package/src/cjs/ops.cjs +126 -0
  26. package/src/cjs/ops.d.ts +122 -0
  27. package/src/cjs/payments/bip341.cjs +192 -0
  28. package/src/cjs/payments/bip341.d.ts +68 -0
  29. package/src/cjs/payments/embed.cjs +97 -0
  30. package/src/cjs/payments/embed.d.ts +9 -0
  31. package/src/cjs/payments/index.cjs +69 -0
  32. package/src/cjs/payments/index.d.ts +55 -0
  33. package/src/cjs/payments/lazy.cjs +31 -0
  34. package/src/cjs/payments/lazy.d.ts +2 -0
  35. package/src/cjs/payments/p2ms.cjs +220 -0
  36. package/src/cjs/payments/p2ms.d.ts +9 -0
  37. package/src/cjs/payments/p2pk.cjs +130 -0
  38. package/src/cjs/payments/p2pk.d.ts +10 -0
  39. package/src/cjs/payments/p2pkh.cjs +192 -0
  40. package/src/cjs/payments/p2pkh.d.ts +10 -0
  41. package/src/cjs/payments/p2sh.cjs +253 -0
  42. package/src/cjs/payments/p2sh.d.ts +10 -0
  43. package/src/cjs/payments/p2tr.cjs +348 -0
  44. package/src/cjs/payments/p2tr.d.ts +10 -0
  45. package/src/cjs/payments/p2wpkh.cjs +186 -0
  46. package/src/cjs/payments/p2wpkh.d.ts +10 -0
  47. package/src/cjs/payments/p2wsh.cjs +269 -0
  48. package/src/cjs/payments/p2wsh.d.ts +10 -0
  49. package/src/cjs/psbt/bip371.cjs +556 -0
  50. package/src/cjs/psbt/bip371.d.ts +89 -0
  51. package/src/cjs/psbt/psbtutils.cjs +228 -0
  52. package/src/cjs/psbt/psbtutils.d.ts +49 -0
  53. package/src/cjs/psbt.cjs +1856 -0
  54. package/src/cjs/psbt.d.ts +206 -0
  55. package/src/cjs/push_data.cjs +133 -0
  56. package/src/cjs/push_data.d.ts +28 -0
  57. package/src/cjs/script.cjs +339 -0
  58. package/src/cjs/script.d.ts +89 -0
  59. package/src/cjs/script_number.cjs +122 -0
  60. package/src/cjs/script_number.d.ts +18 -0
  61. package/src/cjs/script_signature.cjs +123 -0
  62. package/src/cjs/script_signature.d.ts +20 -0
  63. package/src/cjs/transaction.cjs +607 -0
  64. package/src/cjs/transaction.d.ts +60 -0
  65. package/src/cjs/types.cjs +147 -0
  66. package/src/cjs/types.d.ts +45 -0
  67. package/src/esm/address.js +200 -0
  68. package/src/esm/bip66.js +110 -0
  69. package/src/esm/block.js +225 -0
  70. package/src/esm/bufferutils.js +156 -0
  71. package/src/esm/crypto.js +123 -0
  72. package/src/esm/ecc_lib.js +108 -0
  73. package/src/esm/index.js +12 -0
  74. package/src/esm/merkle.js +27 -0
  75. package/src/esm/networks.js +66 -0
  76. package/src/esm/ops.js +125 -0
  77. package/src/esm/payments/bip341.js +135 -0
  78. package/src/esm/payments/embed.js +50 -0
  79. package/src/esm/payments/index.js +11 -0
  80. package/src/esm/payments/lazy.js +27 -0
  81. package/src/esm/payments/p2ms.js +167 -0
  82. package/src/esm/payments/p2pk.js +82 -0
  83. package/src/esm/payments/p2pkh.js +144 -0
  84. package/src/esm/payments/p2sh.js +201 -0
  85. package/src/esm/payments/p2tr.js +301 -0
  86. package/src/esm/payments/p2wpkh.js +139 -0
  87. package/src/esm/payments/p2wsh.js +228 -0
  88. package/src/esm/psbt/bip371.js +490 -0
  89. package/src/esm/psbt/psbtutils.js +168 -0
  90. package/src/esm/psbt.js +1774 -0
  91. package/src/esm/push_data.js +77 -0
  92. package/src/esm/script.js +277 -0
  93. package/src/esm/script_number.js +74 -0
  94. package/src/esm/script_signature.js +75 -0
  95. package/src/esm/transaction.js +550 -0
  96. package/src/esm/types.js +83 -0
  97. package/start-bip40.cjs +127 -0
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.testnet = exports.regtest = exports.bitcoin = void 0;
4
+ /**
5
+ * Represents the Bitcoin network configuration.
6
+ */
7
+ exports.bitcoin = {
8
+ /**
9
+ * The message prefix used for signing Bitcoin messages.
10
+ */
11
+ messagePrefix: '\x18Bitcoin Signed Message:\n',
12
+ /**
13
+ * The Bech32 prefix used for Bitcoin addresses.
14
+ */
15
+ bech32: 'bc',
16
+ /**
17
+ * The BIP32 key prefixes for Bitcoin.
18
+ */
19
+ bip32: {
20
+ /**
21
+ * The public key prefix for BIP32 extended public keys.
22
+ */
23
+ public: 0x0488b21e,
24
+ /**
25
+ * The private key prefix for BIP32 extended private keys.
26
+ */
27
+ private: 0x0488ade4,
28
+ },
29
+ /**
30
+ * The prefix for Bitcoin public key hashes.
31
+ */
32
+ pubKeyHash: 0x00,
33
+ /**
34
+ * The prefix for Bitcoin script hashes.
35
+ */
36
+ scriptHash: 0x05,
37
+ /**
38
+ * The prefix for Bitcoin Wallet Import Format (WIF) private keys.
39
+ */
40
+ wif: 0x80,
41
+ };
42
+ /**
43
+ * Represents the regtest network configuration.
44
+ */
45
+ exports.regtest = {
46
+ messagePrefix: '\x18Bitcoin Signed Message:\n',
47
+ bech32: 'bcrt',
48
+ bip32: {
49
+ public: 0x043587cf,
50
+ private: 0x04358394,
51
+ },
52
+ pubKeyHash: 0x6f,
53
+ scriptHash: 0xc4,
54
+ wif: 0xef,
55
+ };
56
+ /**
57
+ * Represents the testnet network configuration.
58
+ */
59
+ exports.testnet = {
60
+ messagePrefix: '\x18Bitcoin Signed Message:\n',
61
+ bech32: 'tb',
62
+ bip32: {
63
+ public: 0x043587cf,
64
+ private: 0x04358394,
65
+ },
66
+ pubKeyHash: 0x6f,
67
+ scriptHash: 0xc4,
68
+ wif: 0xef,
69
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * This module defines the network configurations for Bitcoin and its variants, including message prefixes,
3
+ * Bech32 address format, BIP32 key derivation prefixes, and other address-related configurations.
4
+ * It supports Bitcoin, Bitcoin testnet, and Bitcoin regtest networks.
5
+ *
6
+ * Additional information on address prefixes can be found here:
7
+ * - https://en.bitcoin.it/wiki/List_of_address_prefixes
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ export interface Network {
12
+ messagePrefix: string;
13
+ bech32: string;
14
+ bip32: Bip32;
15
+ pubKeyHash: number;
16
+ scriptHash: number;
17
+ wif: number;
18
+ }
19
+ interface Bip32 {
20
+ public: number;
21
+ private: number;
22
+ }
23
+ /**
24
+ * Represents the Bitcoin network configuration.
25
+ */
26
+ export declare const bitcoin: Network;
27
+ /**
28
+ * Represents the regtest network configuration.
29
+ */
30
+ export declare const regtest: Network;
31
+ /**
32
+ * Represents the testnet network configuration.
33
+ */
34
+ export declare const testnet: Network;
35
+ export {};
@@ -0,0 +1,126 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.OPS = void 0;
4
+ // Define OPS enum
5
+ var OPS;
6
+ (function (OPS) {
7
+ OPS[(OPS['OP_FALSE'] = 0)] = 'OP_FALSE';
8
+ OPS[(OPS['OP_0'] = 0)] = 'OP_0';
9
+ OPS[(OPS['OP_PUSHDATA1'] = 76)] = 'OP_PUSHDATA1';
10
+ OPS[(OPS['OP_PUSHDATA2'] = 77)] = 'OP_PUSHDATA2';
11
+ OPS[(OPS['OP_PUSHDATA4'] = 78)] = 'OP_PUSHDATA4';
12
+ OPS[(OPS['OP_1NEGATE'] = 79)] = 'OP_1NEGATE';
13
+ OPS[(OPS['OP_RESERVED'] = 80)] = 'OP_RESERVED';
14
+ OPS[(OPS['OP_TRUE'] = 81)] = 'OP_TRUE';
15
+ OPS[(OPS['OP_1'] = 81)] = 'OP_1';
16
+ OPS[(OPS['OP_2'] = 82)] = 'OP_2';
17
+ OPS[(OPS['OP_3'] = 83)] = 'OP_3';
18
+ OPS[(OPS['OP_4'] = 84)] = 'OP_4';
19
+ OPS[(OPS['OP_5'] = 85)] = 'OP_5';
20
+ OPS[(OPS['OP_6'] = 86)] = 'OP_6';
21
+ OPS[(OPS['OP_7'] = 87)] = 'OP_7';
22
+ OPS[(OPS['OP_8'] = 88)] = 'OP_8';
23
+ OPS[(OPS['OP_9'] = 89)] = 'OP_9';
24
+ OPS[(OPS['OP_10'] = 90)] = 'OP_10';
25
+ OPS[(OPS['OP_11'] = 91)] = 'OP_11';
26
+ OPS[(OPS['OP_12'] = 92)] = 'OP_12';
27
+ OPS[(OPS['OP_13'] = 93)] = 'OP_13';
28
+ OPS[(OPS['OP_14'] = 94)] = 'OP_14';
29
+ OPS[(OPS['OP_15'] = 95)] = 'OP_15';
30
+ OPS[(OPS['OP_16'] = 96)] = 'OP_16';
31
+ OPS[(OPS['OP_NOP'] = 97)] = 'OP_NOP';
32
+ OPS[(OPS['OP_VER'] = 98)] = 'OP_VER';
33
+ OPS[(OPS['OP_IF'] = 99)] = 'OP_IF';
34
+ OPS[(OPS['OP_NOTIF'] = 100)] = 'OP_NOTIF';
35
+ OPS[(OPS['OP_VERIF'] = 101)] = 'OP_VERIF';
36
+ OPS[(OPS['OP_VERNOTIF'] = 102)] = 'OP_VERNOTIF';
37
+ OPS[(OPS['OP_ELSE'] = 103)] = 'OP_ELSE';
38
+ OPS[(OPS['OP_ENDIF'] = 104)] = 'OP_ENDIF';
39
+ OPS[(OPS['OP_VERIFY'] = 105)] = 'OP_VERIFY';
40
+ OPS[(OPS['OP_RETURN'] = 106)] = 'OP_RETURN';
41
+ OPS[(OPS['OP_TOALTSTACK'] = 107)] = 'OP_TOALTSTACK';
42
+ OPS[(OPS['OP_FROMALTSTACK'] = 108)] = 'OP_FROMALTSTACK';
43
+ OPS[(OPS['OP_2DROP'] = 109)] = 'OP_2DROP';
44
+ OPS[(OPS['OP_2DUP'] = 110)] = 'OP_2DUP';
45
+ OPS[(OPS['OP_3DUP'] = 111)] = 'OP_3DUP';
46
+ OPS[(OPS['OP_2OVER'] = 112)] = 'OP_2OVER';
47
+ OPS[(OPS['OP_2ROT'] = 113)] = 'OP_2ROT';
48
+ OPS[(OPS['OP_2SWAP'] = 114)] = 'OP_2SWAP';
49
+ OPS[(OPS['OP_IFDUP'] = 115)] = 'OP_IFDUP';
50
+ OPS[(OPS['OP_DEPTH'] = 116)] = 'OP_DEPTH';
51
+ OPS[(OPS['OP_DROP'] = 117)] = 'OP_DROP';
52
+ OPS[(OPS['OP_DUP'] = 118)] = 'OP_DUP';
53
+ OPS[(OPS['OP_NIP'] = 119)] = 'OP_NIP';
54
+ OPS[(OPS['OP_OVER'] = 120)] = 'OP_OVER';
55
+ OPS[(OPS['OP_PICK'] = 121)] = 'OP_PICK';
56
+ OPS[(OPS['OP_ROLL'] = 122)] = 'OP_ROLL';
57
+ OPS[(OPS['OP_ROT'] = 123)] = 'OP_ROT';
58
+ OPS[(OPS['OP_SWAP'] = 124)] = 'OP_SWAP';
59
+ OPS[(OPS['OP_TUCK'] = 125)] = 'OP_TUCK';
60
+ OPS[(OPS['OP_CAT'] = 126)] = 'OP_CAT';
61
+ OPS[(OPS['OP_SUBSTR'] = 127)] = 'OP_SUBSTR';
62
+ OPS[(OPS['OP_LEFT'] = 128)] = 'OP_LEFT';
63
+ OPS[(OPS['OP_RIGHT'] = 129)] = 'OP_RIGHT';
64
+ OPS[(OPS['OP_SIZE'] = 130)] = 'OP_SIZE';
65
+ OPS[(OPS['OP_INVERT'] = 131)] = 'OP_INVERT';
66
+ OPS[(OPS['OP_AND'] = 132)] = 'OP_AND';
67
+ OPS[(OPS['OP_OR'] = 133)] = 'OP_OR';
68
+ OPS[(OPS['OP_XOR'] = 134)] = 'OP_XOR';
69
+ OPS[(OPS['OP_EQUAL'] = 135)] = 'OP_EQUAL';
70
+ OPS[(OPS['OP_EQUALVERIFY'] = 136)] = 'OP_EQUALVERIFY';
71
+ OPS[(OPS['OP_RESERVED1'] = 137)] = 'OP_RESERVED1';
72
+ OPS[(OPS['OP_RESERVED2'] = 138)] = 'OP_RESERVED2';
73
+ OPS[(OPS['OP_1ADD'] = 139)] = 'OP_1ADD';
74
+ OPS[(OPS['OP_1SUB'] = 140)] = 'OP_1SUB';
75
+ OPS[(OPS['OP_2MUL'] = 141)] = 'OP_2MUL';
76
+ OPS[(OPS['OP_2DIV'] = 142)] = 'OP_2DIV';
77
+ OPS[(OPS['OP_NEGATE'] = 143)] = 'OP_NEGATE';
78
+ OPS[(OPS['OP_ABS'] = 144)] = 'OP_ABS';
79
+ OPS[(OPS['OP_NOT'] = 145)] = 'OP_NOT';
80
+ OPS[(OPS['OP_0NOTEQUAL'] = 146)] = 'OP_0NOTEQUAL';
81
+ OPS[(OPS['OP_ADD'] = 147)] = 'OP_ADD';
82
+ OPS[(OPS['OP_SUB'] = 148)] = 'OP_SUB';
83
+ OPS[(OPS['OP_MUL'] = 149)] = 'OP_MUL';
84
+ OPS[(OPS['OP_DIV'] = 150)] = 'OP_DIV';
85
+ OPS[(OPS['OP_MOD'] = 151)] = 'OP_MOD';
86
+ OPS[(OPS['OP_LSHIFT'] = 152)] = 'OP_LSHIFT';
87
+ OPS[(OPS['OP_RSHIFT'] = 153)] = 'OP_RSHIFT';
88
+ OPS[(OPS['OP_BOOLAND'] = 154)] = 'OP_BOOLAND';
89
+ OPS[(OPS['OP_BOOLOR'] = 155)] = 'OP_BOOLOR';
90
+ OPS[(OPS['OP_NUMEQUAL'] = 156)] = 'OP_NUMEQUAL';
91
+ OPS[(OPS['OP_NUMEQUALVERIFY'] = 157)] = 'OP_NUMEQUALVERIFY';
92
+ OPS[(OPS['OP_NUMNOTEQUAL'] = 158)] = 'OP_NUMNOTEQUAL';
93
+ OPS[(OPS['OP_LESSTHAN'] = 159)] = 'OP_LESSTHAN';
94
+ OPS[(OPS['OP_GREATERTHAN'] = 160)] = 'OP_GREATERTHAN';
95
+ OPS[(OPS['OP_LESSTHANOREQUAL'] = 161)] = 'OP_LESSTHANOREQUAL';
96
+ OPS[(OPS['OP_GREATERTHANOREQUAL'] = 162)] = 'OP_GREATERTHANOREQUAL';
97
+ OPS[(OPS['OP_MIN'] = 163)] = 'OP_MIN';
98
+ OPS[(OPS['OP_MAX'] = 164)] = 'OP_MAX';
99
+ OPS[(OPS['OP_WITHIN'] = 165)] = 'OP_WITHIN';
100
+ OPS[(OPS['OP_RIPEMD160'] = 166)] = 'OP_RIPEMD160';
101
+ OPS[(OPS['OP_SHA1'] = 167)] = 'OP_SHA1';
102
+ OPS[(OPS['OP_SHA256'] = 168)] = 'OP_SHA256';
103
+ OPS[(OPS['OP_HASH160'] = 169)] = 'OP_HASH160';
104
+ OPS[(OPS['OP_HASH256'] = 170)] = 'OP_HASH256';
105
+ OPS[(OPS['OP_CODESEPARATOR'] = 171)] = 'OP_CODESEPARATOR';
106
+ OPS[(OPS['OP_CHECKSIG'] = 172)] = 'OP_CHECKSIG';
107
+ OPS[(OPS['OP_CHECKSIGVERIFY'] = 173)] = 'OP_CHECKSIGVERIFY';
108
+ OPS[(OPS['OP_CHECKMULTISIG'] = 174)] = 'OP_CHECKMULTISIG';
109
+ OPS[(OPS['OP_CHECKMULTISIGVERIFY'] = 175)] = 'OP_CHECKMULTISIGVERIFY';
110
+ OPS[(OPS['OP_NOP1'] = 176)] = 'OP_NOP1';
111
+ OPS[(OPS['OP_CHECKLOCKTIMEVERIFY'] = 177)] = 'OP_CHECKLOCKTIMEVERIFY';
112
+ OPS[(OPS['OP_NOP2'] = 177)] = 'OP_NOP2';
113
+ OPS[(OPS['OP_CHECKSEQUENCEVERIFY'] = 178)] = 'OP_CHECKSEQUENCEVERIFY';
114
+ OPS[(OPS['OP_NOP3'] = 178)] = 'OP_NOP3';
115
+ OPS[(OPS['OP_NOP4'] = 179)] = 'OP_NOP4';
116
+ OPS[(OPS['OP_NOP5'] = 180)] = 'OP_NOP5';
117
+ OPS[(OPS['OP_NOP6'] = 181)] = 'OP_NOP6';
118
+ OPS[(OPS['OP_NOP7'] = 182)] = 'OP_NOP7';
119
+ OPS[(OPS['OP_NOP8'] = 183)] = 'OP_NOP8';
120
+ OPS[(OPS['OP_NOP9'] = 184)] = 'OP_NOP9';
121
+ OPS[(OPS['OP_NOP10'] = 185)] = 'OP_NOP10';
122
+ OPS[(OPS['OP_CHECKSIGADD'] = 186)] = 'OP_CHECKSIGADD';
123
+ OPS[(OPS['OP_PUBKEYHASH'] = 253)] = 'OP_PUBKEYHASH';
124
+ OPS[(OPS['OP_PUBKEY'] = 254)] = 'OP_PUBKEY';
125
+ OPS[(OPS['OP_INVALIDOPCODE'] = 255)] = 'OP_INVALIDOPCODE';
126
+ })(OPS || (exports.OPS = OPS = {}));
@@ -0,0 +1,122 @@
1
+ declare enum OPS {
2
+ OP_FALSE = 0,
3
+ OP_0 = 0,// Avoid duplicate value
4
+ OP_PUSHDATA1 = 76,
5
+ OP_PUSHDATA2 = 77,
6
+ OP_PUSHDATA4 = 78,
7
+ OP_1NEGATE = 79,
8
+ OP_RESERVED = 80,
9
+ OP_TRUE = 81,
10
+ OP_1 = 81,// Avoid duplicate value
11
+ OP_2 = 82,
12
+ OP_3 = 83,
13
+ OP_4 = 84,
14
+ OP_5 = 85,
15
+ OP_6 = 86,
16
+ OP_7 = 87,
17
+ OP_8 = 88,
18
+ OP_9 = 89,
19
+ OP_10 = 90,
20
+ OP_11 = 91,
21
+ OP_12 = 92,
22
+ OP_13 = 93,
23
+ OP_14 = 94,
24
+ OP_15 = 95,
25
+ OP_16 = 96,
26
+ OP_NOP = 97,
27
+ OP_VER = 98,
28
+ OP_IF = 99,
29
+ OP_NOTIF = 100,
30
+ OP_VERIF = 101,
31
+ OP_VERNOTIF = 102,
32
+ OP_ELSE = 103,
33
+ OP_ENDIF = 104,
34
+ OP_VERIFY = 105,
35
+ OP_RETURN = 106,
36
+ OP_TOALTSTACK = 107,
37
+ OP_FROMALTSTACK = 108,
38
+ OP_2DROP = 109,
39
+ OP_2DUP = 110,
40
+ OP_3DUP = 111,
41
+ OP_2OVER = 112,
42
+ OP_2ROT = 113,
43
+ OP_2SWAP = 114,
44
+ OP_IFDUP = 115,
45
+ OP_DEPTH = 116,
46
+ OP_DROP = 117,
47
+ OP_DUP = 118,
48
+ OP_NIP = 119,
49
+ OP_OVER = 120,
50
+ OP_PICK = 121,
51
+ OP_ROLL = 122,
52
+ OP_ROT = 123,
53
+ OP_SWAP = 124,
54
+ OP_TUCK = 125,
55
+ OP_CAT = 126,
56
+ OP_SUBSTR = 127,
57
+ OP_LEFT = 128,
58
+ OP_RIGHT = 129,
59
+ OP_SIZE = 130,
60
+ OP_INVERT = 131,
61
+ OP_AND = 132,
62
+ OP_OR = 133,
63
+ OP_XOR = 134,
64
+ OP_EQUAL = 135,
65
+ OP_EQUALVERIFY = 136,
66
+ OP_RESERVED1 = 137,
67
+ OP_RESERVED2 = 138,
68
+ OP_1ADD = 139,
69
+ OP_1SUB = 140,
70
+ OP_2MUL = 141,
71
+ OP_2DIV = 142,
72
+ OP_NEGATE = 143,
73
+ OP_ABS = 144,
74
+ OP_NOT = 145,
75
+ OP_0NOTEQUAL = 146,
76
+ OP_ADD = 147,
77
+ OP_SUB = 148,
78
+ OP_MUL = 149,
79
+ OP_DIV = 150,
80
+ OP_MOD = 151,
81
+ OP_LSHIFT = 152,
82
+ OP_RSHIFT = 153,
83
+ OP_BOOLAND = 154,
84
+ OP_BOOLOR = 155,
85
+ OP_NUMEQUAL = 156,
86
+ OP_NUMEQUALVERIFY = 157,
87
+ OP_NUMNOTEQUAL = 158,
88
+ OP_LESSTHAN = 159,
89
+ OP_GREATERTHAN = 160,
90
+ OP_LESSTHANOREQUAL = 161,
91
+ OP_GREATERTHANOREQUAL = 162,
92
+ OP_MIN = 163,
93
+ OP_MAX = 164,
94
+ OP_WITHIN = 165,
95
+ OP_RIPEMD160 = 166,
96
+ OP_SHA1 = 167,
97
+ OP_SHA256 = 168,
98
+ OP_HASH160 = 169,
99
+ OP_HASH256 = 170,
100
+ OP_CODESEPARATOR = 171,
101
+ OP_CHECKSIG = 172,
102
+ OP_CHECKSIGVERIFY = 173,
103
+ OP_CHECKMULTISIG = 174,
104
+ OP_CHECKMULTISIGVERIFY = 175,
105
+ OP_NOP1 = 176,
106
+ OP_CHECKLOCKTIMEVERIFY = 177,// Alias: OP_NOP2
107
+ OP_NOP2 = 177,
108
+ OP_CHECKSEQUENCEVERIFY = 178,// Alias: OP_NOP3
109
+ OP_NOP3 = 178,
110
+ OP_NOP4 = 179,
111
+ OP_NOP5 = 180,
112
+ OP_NOP6 = 181,
113
+ OP_NOP7 = 182,
114
+ OP_NOP8 = 183,
115
+ OP_NOP9 = 184,
116
+ OP_NOP10 = 185,
117
+ OP_CHECKSIGADD = 186,
118
+ OP_PUBKEYHASH = 253,
119
+ OP_PUBKEY = 254,
120
+ OP_INVALIDOPCODE = 255
121
+ }
122
+ export { OPS };
@@ -0,0 +1,192 @@
1
+ 'use strict';
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __setModuleDefault =
26
+ (this && this.__setModuleDefault) ||
27
+ (Object.create
28
+ ? function (o, v) {
29
+ Object.defineProperty(o, 'default', { enumerable: true, value: v });
30
+ }
31
+ : function (o, v) {
32
+ o['default'] = v;
33
+ });
34
+ var __importStar =
35
+ (this && this.__importStar) ||
36
+ function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null)
40
+ for (var k in mod)
41
+ if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
42
+ __createBinding(result, mod, k);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ Object.defineProperty(exports, '__esModule', { value: true });
47
+ exports.MAX_TAPTREE_DEPTH = exports.LEAF_VERSION_TAPSCRIPT = void 0;
48
+ exports.rootHashFromPath = rootHashFromPath;
49
+ exports.toHashTree = toHashTree;
50
+ exports.findScriptPath = findScriptPath;
51
+ exports.tapleafHash = tapleafHash;
52
+ exports.tapTweakHash = tapTweakHash;
53
+ exports.tweakKey = tweakKey;
54
+ const ecc_lib_js_1 = require('../ecc_lib.cjs');
55
+ const bcrypto = __importStar(require('../crypto.cjs'));
56
+ const bufferutils_js_1 = require('../bufferutils.cjs');
57
+ const types_js_1 = require('../types.cjs');
58
+ const tools = __importStar(require('uint8array-tools'));
59
+ exports.LEAF_VERSION_TAPSCRIPT = 0xc0;
60
+ exports.MAX_TAPTREE_DEPTH = 128;
61
+ const isHashBranch = ht => 'left' in ht && 'right' in ht;
62
+ /**
63
+ * Calculates the root hash from a given control block and leaf hash.
64
+ * @param controlBlock - The control block buffer.
65
+ * @param leafHash - The leaf hash buffer.
66
+ * @returns The root hash buffer.
67
+ * @throws {TypeError} If the control block length is less than 33.
68
+ */
69
+ function rootHashFromPath(controlBlock, leafHash) {
70
+ if (controlBlock.length < 33)
71
+ throw new TypeError(
72
+ `The control-block length is too small. Got ${controlBlock.length}, expected min 33.`,
73
+ );
74
+ const m = (controlBlock.length - 33) / 32;
75
+ let kj = leafHash;
76
+ for (let j = 0; j < m; j++) {
77
+ const ej = controlBlock.slice(33 + 32 * j, 65 + 32 * j);
78
+ if (tools.compare(kj, ej) < 0) {
79
+ kj = tapBranchHash(kj, ej);
80
+ } else {
81
+ kj = tapBranchHash(ej, kj);
82
+ }
83
+ }
84
+ return kj;
85
+ }
86
+ /**
87
+ * Build a hash tree of merkle nodes from the scripts binary tree.
88
+ * @param scriptTree - the tree of scripts to pairwise hash.
89
+ */
90
+ function toHashTree(scriptTree) {
91
+ if ((0, types_js_1.isTapleaf)(scriptTree))
92
+ return { hash: tapleafHash(scriptTree) };
93
+ const hashes = [toHashTree(scriptTree[0]), toHashTree(scriptTree[1])];
94
+ // hashes.sort((a, b) => a.hash.compare(b.hash));
95
+ hashes.sort((a, b) => tools.compare(a.hash, b.hash));
96
+ const [left, right] = hashes;
97
+ return {
98
+ hash: tapBranchHash(left.hash, right.hash),
99
+ left,
100
+ right,
101
+ };
102
+ }
103
+ /**
104
+ * Given a HashTree, finds the path from a particular hash to the root.
105
+ * @param node - the root of the tree
106
+ * @param hash - the hash to search for
107
+ * @returns - array of sibling hashes, from leaf (inclusive) to root
108
+ * (exclusive) needed to prove inclusion of the specified hash. undefined if no
109
+ * path is found
110
+ */
111
+ function findScriptPath(node, hash) {
112
+ if (isHashBranch(node)) {
113
+ const leftPath = findScriptPath(node.left, hash);
114
+ if (leftPath !== undefined) return [...leftPath, node.right.hash];
115
+ const rightPath = findScriptPath(node.right, hash);
116
+ if (rightPath !== undefined) return [...rightPath, node.left.hash];
117
+ } else if (tools.compare(node.hash, hash) === 0) {
118
+ return [];
119
+ }
120
+ return undefined;
121
+ }
122
+ /**
123
+ * Calculates the tapleaf hash for a given Tapleaf object.
124
+ * @param leaf - The Tapleaf object to calculate the hash for.
125
+ * @returns The tapleaf hash as a Buffer.
126
+ */
127
+ function tapleafHash(leaf) {
128
+ const version = leaf.version || exports.LEAF_VERSION_TAPSCRIPT;
129
+ return bcrypto.taggedHash(
130
+ 'TapLeaf',
131
+ tools.concat([Uint8Array.from([version]), serializeScript(leaf.output)]),
132
+ );
133
+ }
134
+ /**
135
+ * Computes the taproot tweak hash for a given public key and optional hash.
136
+ * If a hash is provided, the public key and hash are concatenated before computing the hash.
137
+ * If no hash is provided, only the public key is used to compute the hash.
138
+ *
139
+ * @param pubKey - The public key buffer.
140
+ * @param h - The optional hash buffer.
141
+ * @returns The taproot tweak hash.
142
+ */
143
+ function tapTweakHash(pubKey, h) {
144
+ return bcrypto.taggedHash(
145
+ 'TapTweak',
146
+ tools.concat(h ? [pubKey, h] : [pubKey]),
147
+ );
148
+ }
149
+ /**
150
+ * Tweak a public key with a given tweak hash.
151
+ * @param pubKey - The public key to be tweaked.
152
+ * @param h - The tweak hash.
153
+ * @returns The tweaked public key or null if the input is invalid.
154
+ */
155
+ function tweakKey(pubKey, h) {
156
+ if (!(pubKey instanceof Uint8Array)) return null;
157
+ if (pubKey.length !== 32) return null;
158
+ if (h && h.length !== 32) return null;
159
+ const tweakHash = tapTweakHash(pubKey, h);
160
+ const res = (0, ecc_lib_js_1.getEccLib)().xOnlyPointAddTweak(
161
+ pubKey,
162
+ tweakHash,
163
+ );
164
+ if (!res || res.xOnlyPubkey === null) return null;
165
+ return {
166
+ parity: res.parity,
167
+ x: Uint8Array.from(res.xOnlyPubkey),
168
+ };
169
+ }
170
+ /**
171
+ * Computes the TapBranch hash by concatenating two buffers and applying the 'TapBranch' tagged hash algorithm.
172
+ *
173
+ * @param a - The first buffer.
174
+ * @param b - The second buffer.
175
+ * @returns The TapBranch hash of the concatenated buffers.
176
+ */
177
+ function tapBranchHash(a, b) {
178
+ return bcrypto.taggedHash('TapBranch', tools.concat([a, b]));
179
+ }
180
+ /**
181
+ * Serializes a script by encoding its length as a varint and concatenating it with the script.
182
+ *
183
+ * @param s - The script to be serialized.
184
+ * @returns The serialized script as a Buffer.
185
+ */
186
+ function serializeScript(s) {
187
+ /* global BigInt */
188
+ const varintLen = bufferutils_js_1.varuint.encodingLength(s.length);
189
+ const buffer = new Uint8Array(varintLen);
190
+ bufferutils_js_1.varuint.encode(s.length, buffer);
191
+ return tools.concat([buffer, s]);
192
+ }
@@ -0,0 +1,68 @@
1
+ import { Tapleaf, Taptree } from '../types.js';
2
+ export declare const LEAF_VERSION_TAPSCRIPT = 192;
3
+ export declare const MAX_TAPTREE_DEPTH = 128;
4
+ interface HashLeaf {
5
+ hash: Uint8Array;
6
+ }
7
+ interface HashBranch {
8
+ hash: Uint8Array;
9
+ left: HashTree;
10
+ right: HashTree;
11
+ }
12
+ interface TweakedPublicKey {
13
+ parity: number;
14
+ x: Uint8Array;
15
+ }
16
+ /**
17
+ * Binary tree representing leaf, branch, and root node hashes of a Taptree.
18
+ * Each node contains a hash, and potentially left and right branch hashes.
19
+ * This tree is used for 2 purposes: Providing the root hash for tweaking,
20
+ * and calculating merkle inclusion proofs when constructing a control block.
21
+ */
22
+ export type HashTree = HashLeaf | HashBranch;
23
+ /**
24
+ * Calculates the root hash from a given control block and leaf hash.
25
+ * @param controlBlock - The control block buffer.
26
+ * @param leafHash - The leaf hash buffer.
27
+ * @returns The root hash buffer.
28
+ * @throws {TypeError} If the control block length is less than 33.
29
+ */
30
+ export declare function rootHashFromPath(controlBlock: Uint8Array, leafHash: Uint8Array): Uint8Array;
31
+ /**
32
+ * Build a hash tree of merkle nodes from the scripts binary tree.
33
+ * @param scriptTree - the tree of scripts to pairwise hash.
34
+ */
35
+ export declare function toHashTree(scriptTree: Taptree): HashTree;
36
+ /**
37
+ * Given a HashTree, finds the path from a particular hash to the root.
38
+ * @param node - the root of the tree
39
+ * @param hash - the hash to search for
40
+ * @returns - array of sibling hashes, from leaf (inclusive) to root
41
+ * (exclusive) needed to prove inclusion of the specified hash. undefined if no
42
+ * path is found
43
+ */
44
+ export declare function findScriptPath(node: HashTree, hash: Uint8Array): Uint8Array[] | undefined;
45
+ /**
46
+ * Calculates the tapleaf hash for a given Tapleaf object.
47
+ * @param leaf - The Tapleaf object to calculate the hash for.
48
+ * @returns The tapleaf hash as a Buffer.
49
+ */
50
+ export declare function tapleafHash(leaf: Tapleaf): Uint8Array;
51
+ /**
52
+ * Computes the taproot tweak hash for a given public key and optional hash.
53
+ * If a hash is provided, the public key and hash are concatenated before computing the hash.
54
+ * If no hash is provided, only the public key is used to compute the hash.
55
+ *
56
+ * @param pubKey - The public key buffer.
57
+ * @param h - The optional hash buffer.
58
+ * @returns The taproot tweak hash.
59
+ */
60
+ export declare function tapTweakHash(pubKey: Uint8Array, h: Uint8Array | undefined): Uint8Array;
61
+ /**
62
+ * Tweak a public key with a given tweak hash.
63
+ * @param pubKey - The public key to be tweaked.
64
+ * @param h - The tweak hash.
65
+ * @returns The tweaked public key or null if the input is invalid.
66
+ */
67
+ export declare function tweakKey(pubKey: Uint8Array, h: Uint8Array | undefined): TweakedPublicKey | null;
68
+ export {};