@btc-vision/transaction 1.7.19 → 1.7.23

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.
Files changed (139) hide show
  1. package/.babelrc +10 -1
  2. package/LICENSE +190 -21
  3. package/README.md +1 -1
  4. package/browser/_version.d.ts +1 -1
  5. package/browser/bip39.js +204 -0
  6. package/browser/bitcoin-utils.js +3172 -0
  7. package/browser/btc-vision-bip32.js +805 -0
  8. package/browser/btc-vision-bitcoin.js +4179 -0
  9. package/browser/btc-vision-logger.js +273 -0
  10. package/browser/btc-vision-post-quantum.js +542 -0
  11. package/browser/chain/ChainData.d.ts +1 -1
  12. package/browser/crypto/crypto.d.ts +1 -1
  13. package/browser/generators/AddressGenerator.d.ts +1 -1
  14. package/browser/generators/Generator.d.ts +1 -1
  15. package/browser/generators/MLDSAData.d.ts +1 -1
  16. package/browser/generators/builders/CalldataGenerator.d.ts +1 -1
  17. package/browser/generators/builders/CustomGenerator.d.ts +1 -1
  18. package/browser/generators/builders/DeploymentGenerator.d.ts +1 -1
  19. package/browser/generators/builders/HashCommitmentGenerator.d.ts +49 -0
  20. package/browser/generators/builders/LegacyCalldataGenerator.d.ts +1 -1
  21. package/browser/generators/builders/P2WDAGenerator.d.ts +1 -1
  22. package/browser/index.js +10775 -2
  23. package/browser/keypair/Address.d.ts +5 -3
  24. package/browser/keypair/AddressVerificator.d.ts +2 -2
  25. package/browser/keypair/EcKeyPair.d.ts +2 -2
  26. package/browser/keypair/MessageSigner.d.ts +2 -2
  27. package/browser/keypair/Wallet.d.ts +2 -2
  28. package/browser/metadata/ContractBaseMetadata.d.ts +1 -1
  29. package/browser/mnemonic/Mnemonic.d.ts +2 -2
  30. package/browser/noble-curves.js +3316 -0
  31. package/browser/noble-hashes.js +1608 -0
  32. package/browser/opnet.d.ts +15 -2
  33. package/browser/p2wda/P2WDADetector.d.ts +2 -2
  34. package/browser/polyfills.js +4590 -0
  35. package/browser/scure-base.js +410 -0
  36. package/browser/signer/AddressRotation.d.ts +12 -0
  37. package/browser/signer/SignerUtils.d.ts +1 -1
  38. package/browser/signer/TweakedSigner.d.ts +1 -1
  39. package/browser/transaction/TransactionFactory.d.ts +15 -1
  40. package/browser/transaction/browser/BrowserSignerBase.d.ts +1 -1
  41. package/browser/transaction/browser/Web3Provider.d.ts +1 -1
  42. package/browser/transaction/browser/extensions/UnisatSigner.d.ts +1 -1
  43. package/browser/transaction/browser/extensions/XverseSigner.d.ts +1 -1
  44. package/browser/transaction/builders/CancelTransaction.d.ts +1 -1
  45. package/browser/transaction/builders/ConsolidatedInteractionTransaction.d.ts +44 -0
  46. package/browser/transaction/builders/CustomScriptTransaction.d.ts +1 -1
  47. package/browser/transaction/builders/DeploymentTransaction.d.ts +1 -1
  48. package/browser/transaction/builders/FundingTransaction.d.ts +1 -1
  49. package/browser/transaction/builders/InteractionTransaction.d.ts +1 -1
  50. package/browser/transaction/builders/InteractionTransactionP2WDA.d.ts +2 -2
  51. package/browser/transaction/builders/MultiSignTransaction.d.ts +1 -1
  52. package/browser/transaction/builders/SharedInteractionTransaction.d.ts +1 -1
  53. package/browser/transaction/builders/TransactionBuilder.d.ts +1 -1
  54. package/browser/transaction/enums/TransactionType.d.ts +3 -1
  55. package/browser/transaction/interfaces/IConsolidatedTransactionParameters.d.ts +31 -0
  56. package/browser/transaction/interfaces/ITransactionParameters.d.ts +3 -1
  57. package/browser/transaction/interfaces/Tap.d.ts +1 -1
  58. package/browser/transaction/mineable/TimelockGenerator.d.ts +1 -1
  59. package/browser/transaction/offline/OfflineTransactionManager.d.ts +69 -0
  60. package/browser/transaction/offline/TransactionReconstructor.d.ts +28 -0
  61. package/browser/transaction/offline/TransactionSerializer.d.ts +50 -0
  62. package/browser/transaction/offline/TransactionStateCapture.d.ts +52 -0
  63. package/browser/transaction/offline/interfaces/ISerializableState.d.ts +62 -0
  64. package/browser/transaction/offline/interfaces/ITypeSpecificData.d.ts +62 -0
  65. package/browser/transaction/processor/PsbtTransaction.d.ts +1 -1
  66. package/browser/transaction/shared/P2TR_MS.d.ts +1 -1
  67. package/browser/transaction/shared/TweakedTransaction.d.ts +15 -4
  68. package/browser/utxo/OPNetLimitedProvider.d.ts +1 -1
  69. package/browser/utxo/interfaces/IUTXO.d.ts +2 -0
  70. package/browser/valibot.js +4948 -0
  71. package/browser/vendors.js +12913 -0
  72. package/browser/verification/TapscriptVerificator.d.ts +1 -1
  73. package/build/_version.d.ts +1 -1
  74. package/build/_version.js +1 -1
  75. package/build/generators/builders/HashCommitmentGenerator.d.ts +49 -0
  76. package/build/generators/builders/HashCommitmentGenerator.js +229 -0
  77. package/build/keypair/Address.d.ts +3 -1
  78. package/build/keypair/Address.js +87 -54
  79. package/build/opnet.d.ts +14 -1
  80. package/build/opnet.js +11 -1
  81. package/build/signer/AddressRotation.d.ts +12 -0
  82. package/build/signer/AddressRotation.js +16 -0
  83. package/build/transaction/TransactionFactory.d.ts +14 -0
  84. package/build/transaction/TransactionFactory.js +36 -0
  85. package/build/transaction/builders/ConsolidatedInteractionTransaction.d.ts +44 -0
  86. package/build/transaction/builders/ConsolidatedInteractionTransaction.js +259 -0
  87. package/build/transaction/builders/TransactionBuilder.js +2 -0
  88. package/build/transaction/enums/TransactionType.d.ts +3 -1
  89. package/build/transaction/enums/TransactionType.js +2 -0
  90. package/build/transaction/interfaces/IConsolidatedTransactionParameters.d.ts +31 -0
  91. package/build/transaction/interfaces/IConsolidatedTransactionParameters.js +1 -0
  92. package/build/transaction/interfaces/ITransactionParameters.d.ts +2 -0
  93. package/build/transaction/offline/OfflineTransactionManager.d.ts +69 -0
  94. package/build/transaction/offline/OfflineTransactionManager.js +255 -0
  95. package/build/transaction/offline/TransactionReconstructor.d.ts +28 -0
  96. package/build/transaction/offline/TransactionReconstructor.js +243 -0
  97. package/build/transaction/offline/TransactionSerializer.d.ts +50 -0
  98. package/build/transaction/offline/TransactionSerializer.js +700 -0
  99. package/build/transaction/offline/TransactionStateCapture.d.ts +52 -0
  100. package/build/transaction/offline/TransactionStateCapture.js +275 -0
  101. package/build/transaction/offline/interfaces/ISerializableState.d.ts +62 -0
  102. package/build/transaction/offline/interfaces/ISerializableState.js +2 -0
  103. package/build/transaction/offline/interfaces/ITypeSpecificData.d.ts +62 -0
  104. package/build/transaction/offline/interfaces/ITypeSpecificData.js +19 -0
  105. package/build/transaction/shared/TweakedTransaction.d.ts +12 -1
  106. package/build/transaction/shared/TweakedTransaction.js +75 -8
  107. package/build/utxo/interfaces/IUTXO.d.ts +2 -0
  108. package/documentation/README.md +5 -0
  109. package/documentation/offline-transaction-signing.md +650 -0
  110. package/documentation/transaction-building.md +603 -0
  111. package/package.json +62 -4
  112. package/src/_version.ts +1 -1
  113. package/src/generators/builders/HashCommitmentGenerator.ts +495 -0
  114. package/src/keypair/Address.ts +123 -70
  115. package/src/opnet.ts +16 -1
  116. package/src/signer/AddressRotation.ts +72 -0
  117. package/src/transaction/TransactionFactory.ts +87 -0
  118. package/src/transaction/builders/CancelTransaction.ts +4 -2
  119. package/src/transaction/builders/ConsolidatedInteractionTransaction.ts +561 -0
  120. package/src/transaction/builders/CustomScriptTransaction.ts +4 -2
  121. package/src/transaction/builders/MultiSignTransaction.ts +4 -2
  122. package/src/transaction/builders/TransactionBuilder.ts +8 -2
  123. package/src/transaction/enums/TransactionType.ts +2 -0
  124. package/src/transaction/interfaces/IConsolidatedTransactionParameters.ts +78 -0
  125. package/src/transaction/interfaces/ITransactionParameters.ts +8 -0
  126. package/src/transaction/offline/OfflineTransactionManager.ts +630 -0
  127. package/src/transaction/offline/TransactionReconstructor.ts +402 -0
  128. package/src/transaction/offline/TransactionSerializer.ts +920 -0
  129. package/src/transaction/offline/TransactionStateCapture.ts +469 -0
  130. package/src/transaction/offline/interfaces/ISerializableState.ts +141 -0
  131. package/src/transaction/offline/interfaces/ITypeSpecificData.ts +172 -0
  132. package/src/transaction/shared/TweakedTransaction.ts +156 -9
  133. package/src/utxo/interfaces/IUTXO.ts +8 -0
  134. package/test/address-rotation.test.ts +553 -0
  135. package/test/offline-transaction.test.ts +2065 -0
  136. package/vite.config.browser.ts +92 -0
  137. package/webpack.config.js +143 -2
  138. package/browser/crypto/crypto-browser.d.ts +0 -11
  139. package/browser/index.js.LICENSE.txt +0 -29
@@ -0,0 +1,92 @@
1
+ import { resolve } from 'path';
2
+ import { defineConfig } from 'vite';
3
+ import { nodePolyfills } from 'vite-plugin-node-polyfills';
4
+ import dts from 'vite-plugin-dts';
5
+
6
+ export default defineConfig({
7
+ build: {
8
+ outDir: 'browser',
9
+ emptyOutDir: true,
10
+ target: 'esnext',
11
+ minify: 'esbuild',
12
+ lib: {
13
+ entry: resolve(__dirname, 'src/index.ts'),
14
+ formats: ['es'],
15
+ fileName: () => 'index.js',
16
+ },
17
+ rollupOptions: {
18
+ output: {
19
+ chunkFileNames: '[name].js',
20
+ manualChunks: (id) => {
21
+ // BTC Vision packages (check before node_modules since aliases resolve differently)
22
+ if (id.includes('@btc-vision/bitcoin') || id.includes('/bitcoin/build/') || id.includes('/bitcoin/src/')) {
23
+ return 'btc-vision-bitcoin';
24
+ }
25
+ if (id.includes('@btc-vision/bip32') || id.includes('/bip32/src/')) {
26
+ return 'btc-vision-bip32';
27
+ }
28
+ if (id.includes('node_modules')) {
29
+ // Noble crypto
30
+ if (id.includes('@noble/curves')) return 'noble-curves';
31
+ if (id.includes('@noble/hashes')) return 'noble-hashes';
32
+ // BTC Vision packages
33
+ if (id.includes('@btc-vision/post-quantum')) return 'btc-vision-post-quantum';
34
+ if (id.includes('@btc-vision/logger')) return 'btc-vision-logger';
35
+ // Bitcoin utilities
36
+ if (id.includes('bip39')) return 'bip39';
37
+ if (id.includes('ecpair') || id.includes('@bitcoinerlab/secp256k1') ||
38
+ id.includes('bech32') || id.includes('bip174') || id.includes('bs58') ||
39
+ id.includes('typeforce') || id.includes('varuint')) {
40
+ return 'bitcoin-utils';
41
+ }
42
+ // Validation
43
+ if (id.includes('valibot')) return 'valibot';
44
+ // Scure
45
+ if (id.includes('@scure/')) return 'scure-base';
46
+ // Polyfills
47
+ if (id.includes('buffer/') || id.includes('process/') || id.includes('stream-browserify') ||
48
+ id.includes('readable-stream') || id.includes('safe-buffer') || id.includes('events/') ||
49
+ id.includes('util/') || id.includes('inherits') || id.includes('ieee754') ||
50
+ id.includes('base64-js') || id.includes('string_decoder')) {
51
+ return 'polyfills';
52
+ }
53
+ // Other vendors
54
+ return 'vendors';
55
+ }
56
+ },
57
+ },
58
+ },
59
+ },
60
+ resolve: {
61
+ alias: {
62
+ crypto: resolve(__dirname, 'src/crypto/crypto-browser.js'),
63
+ stream: 'stream-browserify',
64
+ buffer: 'buffer',
65
+ // Use source versions for proper tree-shaking (not browser bundles)
66
+ '@btc-vision/bitcoin': resolve(__dirname, 'node_modules/@btc-vision/bitcoin/build/index.js'),
67
+ '@btc-vision/bip32': resolve(__dirname, 'node_modules/@btc-vision/bip32/src/cjs/index.cjs'),
68
+ },
69
+ mainFields: ['module', 'main'],
70
+ },
71
+ define: {
72
+ 'process.env.NODE_ENV': JSON.stringify('production'),
73
+ global: 'globalThis',
74
+ },
75
+ plugins: [
76
+ nodePolyfills({
77
+ globals: {
78
+ Buffer: true,
79
+ global: true,
80
+ process: true,
81
+ },
82
+ // Exclude heavy polyfills we don't need
83
+ exclude: ['fs', 'path', 'os', 'http', 'https', 'zlib', 'net', 'tls', 'dns', 'child_process', 'cluster', 'dgram', 'readline', 'repl', 'tty', 'vm', 'worker_threads', 'perf_hooks', 'inspector', 'async_hooks', 'trace_events', 'v8', 'wasi'],
84
+ }),
85
+ dts({
86
+ outDir: 'browser',
87
+ include: ['src/**/*.ts'],
88
+ exclude: ['src/**/*.test.ts', 'src/**/*.spec.ts'],
89
+ insertTypesEntry: true,
90
+ }),
91
+ ],
92
+ });
package/webpack.config.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import webpack from 'webpack';
2
+ import TerserPlugin from 'terser-webpack-plugin';
2
3
 
3
4
  export default {
4
5
  mode: 'production',
@@ -10,9 +11,12 @@ export default {
10
11
  },
11
12
  watch: false,
12
13
  output: {
13
- filename: 'index.js',
14
+ filename: '[name].js',
15
+ chunkFilename: 'chunks/[name].js',
14
16
  path: import.meta.dirname + '/browser',
15
17
  libraryTarget: 'module',
18
+ chunkFormat: 'module',
19
+ chunkLoading: 'import',
16
20
  },
17
21
  node: {
18
22
  __dirname: false,
@@ -28,9 +32,12 @@ export default {
28
32
  },
29
33
  modules: ['.', 'node_modules'],
30
34
  extensions: ['.*', '.js', '.jsx', '.tsx', '.ts', '.wasm'],
35
+ alias: {
36
+ // Dedupe noble/curves to single version
37
+ '@noble/curves': import.meta.dirname + '/node_modules/@noble/curves',
38
+ },
31
39
  fallback: {
32
40
  buffer: import.meta.resolve('buffer/'),
33
-
34
41
  assert: import.meta.resolve('assert/'),
35
42
  crypto: import.meta.resolve('./src/crypto/crypto-browser.js'),
36
43
  http: import.meta.resolve('stream-http/'),
@@ -66,6 +73,132 @@ export default {
66
73
  },
67
74
  optimization: {
68
75
  usedExports: true,
76
+ minimize: true,
77
+ minimizer: [
78
+ new TerserPlugin({
79
+ terserOptions: {
80
+ compress: {
81
+ drop_console: false,
82
+ drop_debugger: true,
83
+ passes: 3,
84
+ pure_funcs: ['console.debug'],
85
+ dead_code: true,
86
+ unused: true,
87
+ },
88
+ mangle: {
89
+ safari10: true,
90
+ },
91
+ format: {
92
+ comments: false,
93
+ },
94
+ },
95
+ extractComments: false,
96
+ }),
97
+ ],
98
+ concatenateModules: true,
99
+ sideEffects: true,
100
+ providedExports: true,
101
+ innerGraph: true,
102
+ splitChunks: {
103
+ chunks: 'all',
104
+ minSize: 1000,
105
+ maxInitialRequests: Infinity,
106
+ cacheGroups: {
107
+ // Noble cryptographic libraries (curves + hashes)
108
+ nobleCurves: {
109
+ test: /[\\/]node_modules[\\/]@noble[\\/]curves[\\/]/,
110
+ name: 'noble-curves',
111
+ priority: 50,
112
+ reuseExistingChunk: true,
113
+ },
114
+ nobleHashes: {
115
+ test: /[\\/]node_modules[\\/]@noble[\\/]hashes[\\/]/,
116
+ name: 'noble-hashes',
117
+ priority: 49,
118
+ reuseExistingChunk: true,
119
+ },
120
+ nobleSecp: {
121
+ test: /[\\/]node_modules[\\/]@noble[\\/]secp256k1[\\/]/,
122
+ name: 'noble-secp256k1',
123
+ priority: 48,
124
+ reuseExistingChunk: true,
125
+ },
126
+ // Separate @btc-vision packages
127
+ btcBitcoin: {
128
+ test: /[\\/]node_modules[\\/]@btc-vision[\\/]bitcoin[\\/]/,
129
+ name: 'btc-vision-bitcoin',
130
+ priority: 45,
131
+ reuseExistingChunk: true,
132
+ },
133
+ btcBip32: {
134
+ test: /[\\/]node_modules[\\/]@btc-vision[\\/]bip32[\\/]/,
135
+ name: 'btc-vision-bip32',
136
+ priority: 44,
137
+ reuseExistingChunk: true,
138
+ },
139
+ btcPostQuantum: {
140
+ test: /[\\/]node_modules[\\/]@btc-vision[\\/]post-quantum[\\/]/,
141
+ name: 'btc-vision-post-quantum',
142
+ priority: 43,
143
+ reuseExistingChunk: true,
144
+ },
145
+ btcLogger: {
146
+ test: /[\\/]node_modules[\\/]@btc-vision[\\/]logger[\\/]/,
147
+ name: 'btc-vision-logger',
148
+ priority: 42,
149
+ reuseExistingChunk: true,
150
+ },
151
+ // Valibot validation library
152
+ valibot: {
153
+ test: /[\\/]node_modules[\\/]valibot[\\/]/,
154
+ name: 'valibot',
155
+ priority: 40,
156
+ reuseExistingChunk: true,
157
+ },
158
+ // Pako compression
159
+ pako: {
160
+ test: /[\\/]node_modules[\\/]pako[\\/]/,
161
+ name: 'pako',
162
+ priority: 39,
163
+ reuseExistingChunk: true,
164
+ },
165
+ // BIP39 mnemonic (wordlists are stripped via IgnorePlugin)
166
+ bip39: {
167
+ test: /[\\/]node_modules[\\/]bip39[\\/]/,
168
+ name: 'bip39',
169
+ priority: 38,
170
+ reuseExistingChunk: true,
171
+ },
172
+ // Bitcoin utilities
173
+ bitcoin: {
174
+ test: /[\\/]node_modules[\\/](bip174|bech32|ecpair|@bitcoinerlab)[\\/]/,
175
+ name: 'bitcoin-utils',
176
+ priority: 35,
177
+ reuseExistingChunk: true,
178
+ },
179
+ // Scure base encoding
180
+ scure: {
181
+ test: /[\\/]node_modules[\\/]@scure[\\/]/,
182
+ name: 'scure-base',
183
+ priority: 34,
184
+ reuseExistingChunk: true,
185
+ },
186
+ // Buffer and stream polyfills
187
+ polyfills: {
188
+ test: /[\\/]node_modules[\\/](buffer|stream-browserify|browserify-zlib|process|assert|os-browserify|https-browserify|stream-http)[\\/]/,
189
+ name: 'polyfills',
190
+ priority: 25,
191
+ reuseExistingChunk: true,
192
+ },
193
+ // Remaining vendor code
194
+ vendors: {
195
+ test: /[\\/]node_modules[\\/]/,
196
+ name: 'vendors',
197
+ priority: 10,
198
+ reuseExistingChunk: true,
199
+ },
200
+ },
201
+ },
69
202
  },
70
203
  plugins: [
71
204
  new webpack.ProvidePlugin({
@@ -75,5 +208,13 @@ export default {
75
208
  zlib: 'browserify-zlib',
76
209
  bitcoin: '@btc-vision/bitcoin',
77
210
  }),
211
+ // Strip unused bip39 wordlists (keep only English) - saves ~150KB
212
+ new webpack.IgnorePlugin({
213
+ resourceRegExp: /^\.\/wordlists\/(?!english)/,
214
+ contextRegExp: /bip39/,
215
+ }),
78
216
  ],
217
+ // Externals config for dependent packages to avoid duplication
218
+ // Other packages can set these externals and import chunks from @btc-vision/transaction
219
+ externalsType: 'module',
79
220
  };
@@ -1,11 +0,0 @@
1
- export function createHash(algo: any): import("@noble/hashes/utils").Hash<import("@noble/hashes/utils").Hash<any>> | undefined;
2
- export function createHmac(_algo: any, key: any): import("@noble/hashes/hmac").HMAC<any>;
3
- export function pbkdf2Sync(password: any, salt: any, iterations: any, keylen: any, _algo: any): Uint8Array<ArrayBufferLike>;
4
- export function randomBytes(length: any): Uint8Array<any>;
5
- declare namespace _default {
6
- export { createHash };
7
- export { createHmac };
8
- export { pbkdf2Sync };
9
- export { randomBytes };
10
- }
11
- export default _default;
@@ -1,29 +0,0 @@
1
- /*!
2
- * The buffer module from node.js, for the browser.
3
- *
4
- * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
5
- * @license MIT
6
- */
7
-
8
- /*!
9
- * The buffer module from node.js, for the browser.
10
- *
11
- * @author Feross Aboukhadijeh <https://feross.org>
12
- * @license MIT
13
- */
14
-
15
- /*! For license information please see index.js.LICENSE.txt */
16
-
17
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
18
-
19
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
20
-
21
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
22
-
23
- /*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
24
-
25
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
26
-
27
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
28
-
29
- /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */