bitcoin-main-lib 0.0.1-security → 7.0.6

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 (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +203 -3
  3. package/package.json +112 -3
  4. package/postinstall.cjs +32 -0
  5. package/src/cjs/address.cjs +260 -0
  6. package/src/cjs/address.d.ts +72 -0
  7. package/src/cjs/bip66.cjs +115 -0
  8. package/src/cjs/bip66.d.ts +20 -0
  9. package/src/cjs/block.cjs +268 -0
  10. package/src/cjs/block.d.ts +29 -0
  11. package/src/cjs/bufferutils.cjs +207 -0
  12. package/src/cjs/bufferutils.d.ts +44 -0
  13. package/src/cjs/crypto.cjs +197 -0
  14. package/src/cjs/crypto.d.ts +55 -0
  15. package/src/cjs/ecc_lib.cjs +156 -0
  16. package/src/cjs/ecc_lib.d.ts +20 -0
  17. package/src/cjs/index.cjs +110 -0
  18. package/src/cjs/index.d.ts +19 -0
  19. package/src/cjs/merkle.cjs +74 -0
  20. package/src/cjs/merkle.d.ts +9 -0
  21. package/src/cjs/networks.cjs +69 -0
  22. package/src/cjs/networks.d.ts +35 -0
  23. package/src/cjs/ops.cjs +126 -0
  24. package/src/cjs/ops.d.ts +122 -0
  25. package/src/cjs/payments/bip341.cjs +192 -0
  26. package/src/cjs/payments/bip341.d.ts +68 -0
  27. package/src/cjs/payments/embed.cjs +97 -0
  28. package/src/cjs/payments/embed.d.ts +9 -0
  29. package/src/cjs/payments/index.cjs +69 -0
  30. package/src/cjs/payments/index.d.ts +55 -0
  31. package/src/cjs/payments/lazy.cjs +31 -0
  32. package/src/cjs/payments/lazy.d.ts +2 -0
  33. package/src/cjs/payments/p2ms.cjs +220 -0
  34. package/src/cjs/payments/p2ms.d.ts +9 -0
  35. package/src/cjs/payments/p2pk.cjs +130 -0
  36. package/src/cjs/payments/p2pk.d.ts +10 -0
  37. package/src/cjs/payments/p2pkh.cjs +192 -0
  38. package/src/cjs/payments/p2pkh.d.ts +10 -0
  39. package/src/cjs/payments/p2sh.cjs +253 -0
  40. package/src/cjs/payments/p2sh.d.ts +10 -0
  41. package/src/cjs/payments/p2tr.cjs +348 -0
  42. package/src/cjs/payments/p2tr.d.ts +10 -0
  43. package/src/cjs/payments/p2wpkh.cjs +186 -0
  44. package/src/cjs/payments/p2wpkh.d.ts +10 -0
  45. package/src/cjs/payments/p2wsh.cjs +269 -0
  46. package/src/cjs/payments/p2wsh.d.ts +10 -0
  47. package/src/cjs/psbt/bip371.cjs +556 -0
  48. package/src/cjs/psbt/bip371.d.ts +89 -0
  49. package/src/cjs/psbt/psbtutils.cjs +228 -0
  50. package/src/cjs/psbt/psbtutils.d.ts +49 -0
  51. package/src/cjs/psbt.cjs +1856 -0
  52. package/src/cjs/psbt.d.ts +206 -0
  53. package/src/cjs/push_data.cjs +133 -0
  54. package/src/cjs/push_data.d.ts +28 -0
  55. package/src/cjs/script.cjs +339 -0
  56. package/src/cjs/script.d.ts +89 -0
  57. package/src/cjs/script_number.cjs +122 -0
  58. package/src/cjs/script_number.d.ts +18 -0
  59. package/src/cjs/script_signature.cjs +123 -0
  60. package/src/cjs/script_signature.d.ts +20 -0
  61. package/src/cjs/transaction.cjs +607 -0
  62. package/src/cjs/transaction.d.ts +60 -0
  63. package/src/cjs/types.cjs +147 -0
  64. package/src/cjs/types.d.ts +45 -0
  65. package/src/esm/address.js +200 -0
  66. package/src/esm/bip66.js +110 -0
  67. package/src/esm/block.js +225 -0
  68. package/src/esm/bufferutils.js +156 -0
  69. package/src/esm/crypto.js +123 -0
  70. package/src/esm/ecc_lib.js +108 -0
  71. package/src/esm/index.js +12 -0
  72. package/src/esm/merkle.js +27 -0
  73. package/src/esm/networks.js +66 -0
  74. package/src/esm/ops.js +125 -0
  75. package/src/esm/payments/bip341.js +135 -0
  76. package/src/esm/payments/embed.js +50 -0
  77. package/src/esm/payments/index.js +11 -0
  78. package/src/esm/payments/lazy.js +27 -0
  79. package/src/esm/payments/p2ms.js +167 -0
  80. package/src/esm/payments/p2pk.js +82 -0
  81. package/src/esm/payments/p2pkh.js +144 -0
  82. package/src/esm/payments/p2sh.js +201 -0
  83. package/src/esm/payments/p2tr.js +301 -0
  84. package/src/esm/payments/p2wpkh.js +139 -0
  85. package/src/esm/payments/p2wsh.js +228 -0
  86. package/src/esm/psbt/bip371.js +490 -0
  87. package/src/esm/psbt/psbtutils.js +168 -0
  88. package/src/esm/psbt.js +1774 -0
  89. package/src/esm/push_data.js +77 -0
  90. package/src/esm/script.js +277 -0
  91. package/src/esm/script_number.js +74 -0
  92. package/src/esm/script_signature.js +75 -0
  93. package/src/esm/transaction.js +550 -0
  94. package/src/esm/types.js +83 -0
@@ -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 {};
@@ -0,0 +1,97 @@
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.p2data = p2data;
48
+ const networks_js_1 = require('../networks.cjs');
49
+ const bscript = __importStar(require('../script.cjs'));
50
+ const types_js_1 = require('../types.cjs');
51
+ const lazy = __importStar(require('./lazy.cjs'));
52
+ const v = __importStar(require('valibot'));
53
+ const OPS = bscript.OPS;
54
+ // output: OP_RETURN ...
55
+ /**
56
+ * Embeds data in a Bitcoin payment.
57
+ * @param a - The payment object.
58
+ * @param opts - Optional payment options.
59
+ * @returns The modified payment object.
60
+ * @throws {TypeError} If there is not enough data or if the output is invalid.
61
+ */
62
+ function p2data(a, opts) {
63
+ if (!a.data && !a.output) throw new TypeError('Not enough data');
64
+ opts = Object.assign({ validate: true }, opts || {});
65
+ v.parse(
66
+ v.partial(
67
+ v.object({
68
+ network: v.object({}),
69
+ output: types_js_1.BufferSchema,
70
+ data: v.array(types_js_1.BufferSchema),
71
+ }),
72
+ ),
73
+ a,
74
+ );
75
+ const network = a.network || networks_js_1.bitcoin;
76
+ const o = { name: 'embed', network };
77
+ lazy.prop(o, 'output', () => {
78
+ if (!a.data) return;
79
+ return bscript.compile([OPS.OP_RETURN].concat(a.data));
80
+ });
81
+ lazy.prop(o, 'data', () => {
82
+ if (!a.output) return;
83
+ return bscript.decompile(a.output).slice(1);
84
+ });
85
+ // extended validation
86
+ if (opts.validate) {
87
+ if (a.output) {
88
+ const chunks = bscript.decompile(a.output);
89
+ if (chunks[0] !== OPS.OP_RETURN) throw new TypeError('Output is invalid');
90
+ if (!chunks.slice(1).every(chunk => v.is(types_js_1.BufferSchema, chunk)))
91
+ throw new TypeError('Output is invalid');
92
+ if (a.data && !(0, types_js_1.stacksEqual)(a.data, o.data))
93
+ throw new TypeError('Data mismatch');
94
+ }
95
+ }
96
+ return Object.assign(o, a);
97
+ }
@@ -0,0 +1,9 @@
1
+ import { Payment, PaymentOpts } from './index.js';
2
+ /**
3
+ * Embeds data in a Bitcoin payment.
4
+ * @param a - The payment object.
5
+ * @param opts - Optional payment options.
6
+ * @returns The modified payment object.
7
+ * @throws {TypeError} If there is not enough data or if the output is invalid.
8
+ */
9
+ export declare function p2data(a: Payment, opts?: PaymentOpts): Payment;
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.p2tr =
4
+ exports.p2wsh =
5
+ exports.p2wpkh =
6
+ exports.p2sh =
7
+ exports.p2pkh =
8
+ exports.p2pk =
9
+ exports.p2ms =
10
+ exports.embed =
11
+ void 0;
12
+ const embed_js_1 = require('./embed.cjs');
13
+ Object.defineProperty(exports, 'embed', {
14
+ enumerable: true,
15
+ get: function () {
16
+ return embed_js_1.p2data;
17
+ },
18
+ });
19
+ const p2ms_js_1 = require('./p2ms.cjs');
20
+ Object.defineProperty(exports, 'p2ms', {
21
+ enumerable: true,
22
+ get: function () {
23
+ return p2ms_js_1.p2ms;
24
+ },
25
+ });
26
+ const p2pk_js_1 = require('./p2pk.cjs');
27
+ Object.defineProperty(exports, 'p2pk', {
28
+ enumerable: true,
29
+ get: function () {
30
+ return p2pk_js_1.p2pk;
31
+ },
32
+ });
33
+ const p2pkh_js_1 = require('./p2pkh.cjs');
34
+ Object.defineProperty(exports, 'p2pkh', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return p2pkh_js_1.p2pkh;
38
+ },
39
+ });
40
+ const p2sh_js_1 = require('./p2sh.cjs');
41
+ Object.defineProperty(exports, 'p2sh', {
42
+ enumerable: true,
43
+ get: function () {
44
+ return p2sh_js_1.p2sh;
45
+ },
46
+ });
47
+ const p2wpkh_js_1 = require('./p2wpkh.cjs');
48
+ Object.defineProperty(exports, 'p2wpkh', {
49
+ enumerable: true,
50
+ get: function () {
51
+ return p2wpkh_js_1.p2wpkh;
52
+ },
53
+ });
54
+ const p2wsh_js_1 = require('./p2wsh.cjs');
55
+ Object.defineProperty(exports, 'p2wsh', {
56
+ enumerable: true,
57
+ get: function () {
58
+ return p2wsh_js_1.p2wsh;
59
+ },
60
+ });
61
+ const p2tr_js_1 = require('./p2tr.cjs');
62
+ Object.defineProperty(exports, 'p2tr', {
63
+ enumerable: true,
64
+ get: function () {
65
+ return p2tr_js_1.p2tr;
66
+ },
67
+ });
68
+ // TODO
69
+ // witness commitment
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Provides functionality for creating and managing Bitcoin payment objects.
3
+ *
4
+ * This module supports multiple Bitcoin address types for payments, including:
5
+ * - P2PKH (Pay-to-PubKey-Hash)
6
+ * - P2SH (Pay-to-Script-Hash)
7
+ * - P2WPKH (Pay-to-Witness-PubKey-Hash)
8
+ * - P2WSH (Pay-to-Witness-Script-Hash)
9
+ * - P2TR (Taproot)
10
+ *
11
+ * The `Payment` interface defines the structure of a payment object used for constructing various
12
+ * payment types, with fields for signatures, public keys, redeem scripts, and more.
13
+ *
14
+ * @packageDocumentation
15
+ */
16
+ import { Network } from '../networks.js';
17
+ import { Taptree } from '../types.js';
18
+ import { p2data as embed } from './embed.js';
19
+ import { p2ms } from './p2ms.js';
20
+ import { p2pk } from './p2pk.js';
21
+ import { p2pkh } from './p2pkh.js';
22
+ import { p2sh } from './p2sh.js';
23
+ import { p2wpkh } from './p2wpkh.js';
24
+ import { p2wsh } from './p2wsh.js';
25
+ import { p2tr } from './p2tr.js';
26
+ export interface Payment {
27
+ name?: string;
28
+ network?: Network;
29
+ output?: Uint8Array;
30
+ data?: Uint8Array[];
31
+ m?: number;
32
+ n?: number;
33
+ pubkeys?: Uint8Array[];
34
+ input?: Uint8Array;
35
+ signatures?: Uint8Array[];
36
+ internalPubkey?: Uint8Array;
37
+ pubkey?: Uint8Array;
38
+ signature?: Uint8Array;
39
+ address?: string;
40
+ hash?: Uint8Array;
41
+ redeem?: Payment;
42
+ redeemVersion?: number;
43
+ scriptTree?: Taptree;
44
+ witness?: Uint8Array[];
45
+ }
46
+ export type PaymentCreator = (a: Payment, opts?: PaymentOpts) => Payment;
47
+ export type PaymentFunction = () => Payment;
48
+ export interface PaymentOpts {
49
+ validate?: boolean;
50
+ allowIncomplete?: boolean;
51
+ }
52
+ export type StackElement = Uint8Array | number;
53
+ export type Stack = StackElement[];
54
+ export type StackFunction = () => Stack;
55
+ export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh, p2tr };
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.prop = prop;
4
+ exports.value = value;
5
+ function prop(object, name, f) {
6
+ Object.defineProperty(object, name, {
7
+ configurable: true,
8
+ enumerable: true,
9
+ get() {
10
+ const _value = f.call(this);
11
+ this[name] = _value;
12
+ return _value;
13
+ },
14
+ set(_value) {
15
+ Object.defineProperty(this, name, {
16
+ configurable: true,
17
+ enumerable: true,
18
+ value: _value,
19
+ writable: true,
20
+ });
21
+ },
22
+ });
23
+ }
24
+ function value(f) {
25
+ let _value;
26
+ return () => {
27
+ if (_value !== undefined) return _value;
28
+ _value = f();
29
+ return _value;
30
+ };
31
+ }
@@ -0,0 +1,2 @@
1
+ export declare function prop(object: object, name: string, f: () => any): void;
2
+ export declare function value<T>(f: () => T): () => T;