@btc-vision/bitcoin 7.0.0-alpha.0 → 7.0.0-alpha.10
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/README.md +455 -155
- package/browser/address.d.ts +6 -2
- package/browser/address.d.ts.map +1 -1
- package/browser/block.d.ts.map +1 -1
- package/browser/branded.d.ts +3 -14
- package/browser/branded.d.ts.map +1 -1
- package/browser/chunks/psbt-parallel-BBFlkmiv.js +10717 -0
- package/browser/crypto.d.ts +1 -1
- package/browser/ecc/context.d.ts +25 -24
- package/browser/ecc/context.d.ts.map +1 -1
- package/browser/ecc/index.d.ts +1 -1
- package/browser/ecc/index.d.ts.map +1 -1
- package/browser/ecc/types.d.ts +10 -123
- package/browser/ecc/types.d.ts.map +1 -1
- package/browser/env.d.ts +13 -0
- package/browser/env.d.ts.map +1 -0
- package/browser/index.d.ts +7 -7
- package/browser/index.d.ts.map +1 -1
- package/browser/index.js +2497 -11686
- package/browser/io/BinaryReader.d.ts +15 -15
- package/browser/io/BinaryReader.d.ts.map +1 -1
- package/browser/io/BinaryWriter.d.ts +17 -17
- package/browser/io/BinaryWriter.d.ts.map +1 -1
- package/browser/io/hex.d.ts.map +1 -1
- package/browser/io/index.d.ts +0 -1
- package/browser/io/index.d.ts.map +1 -1
- package/browser/opcodes.d.ts +11 -0
- package/browser/opcodes.d.ts.map +1 -1
- package/browser/payments/bip341.d.ts +1 -1
- package/browser/payments/bip341.d.ts.map +1 -1
- package/browser/payments/embed.d.ts +1 -1
- package/browser/payments/embed.d.ts.map +1 -1
- package/browser/payments/p2ms.d.ts.map +1 -1
- package/browser/payments/p2op.d.ts +1 -1
- package/browser/payments/p2op.d.ts.map +1 -1
- package/browser/payments/p2pk.d.ts +1 -1
- package/browser/payments/p2pk.d.ts.map +1 -1
- package/browser/payments/p2pkh.d.ts +1 -1
- package/browser/payments/p2pkh.d.ts.map +1 -1
- package/browser/payments/p2sh.d.ts.map +1 -1
- package/browser/payments/p2tr.d.ts +2 -2
- package/browser/payments/p2tr.d.ts.map +1 -1
- package/browser/payments/p2wpkh.d.ts +1 -1
- package/browser/payments/p2wpkh.d.ts.map +1 -1
- package/browser/payments/p2wsh.d.ts.map +1 -1
- package/browser/payments/types.d.ts +1 -1
- package/browser/payments/types.d.ts.map +1 -1
- package/browser/psbt/PsbtCache.d.ts +54 -0
- package/browser/psbt/PsbtCache.d.ts.map +1 -0
- package/browser/psbt/PsbtFinalizer.d.ts +21 -0
- package/browser/psbt/PsbtFinalizer.d.ts.map +1 -0
- package/browser/psbt/PsbtSigner.d.ts +32 -0
- package/browser/psbt/PsbtSigner.d.ts.map +1 -0
- package/browser/psbt/PsbtTransaction.d.ts +25 -0
- package/browser/psbt/PsbtTransaction.d.ts.map +1 -0
- package/browser/psbt/bip371.d.ts.map +1 -1
- package/browser/psbt/types.d.ts +5 -71
- package/browser/psbt/types.d.ts.map +1 -1
- package/browser/psbt/validation.d.ts +1 -1
- package/browser/psbt/validation.d.ts.map +1 -1
- package/browser/psbt.d.ts +26 -40
- package/browser/psbt.d.ts.map +1 -1
- package/browser/script.d.ts.map +1 -1
- package/browser/transaction.d.ts +4 -4
- package/browser/transaction.d.ts.map +1 -1
- package/browser/types.d.ts +5 -3
- package/browser/types.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.d.ts +24 -17
- package/browser/workers/WorkerSigningPool.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.node.d.ts +19 -12
- package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.sequential.d.ts +67 -0
- package/browser/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.worklet.d.ts +64 -0
- package/browser/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
- package/browser/workers/index.browser.d.ts +16 -0
- package/browser/workers/index.browser.d.ts.map +1 -0
- package/browser/workers/index.d.ts +4 -64
- package/browser/workers/index.d.ts.map +1 -1
- package/browser/workers/index.js +28 -0
- package/browser/workers/index.node.d.ts +17 -0
- package/browser/workers/index.node.d.ts.map +1 -0
- package/browser/workers/index.react-native.d.ts +28 -0
- package/browser/workers/index.react-native.d.ts.map +1 -0
- package/browser/workers/index.shared.d.ts +15 -0
- package/browser/workers/index.shared.d.ts.map +1 -0
- package/browser/workers/psbt-parallel.d.ts +2 -3
- package/browser/workers/psbt-parallel.d.ts.map +1 -1
- package/browser/workers/types.d.ts +17 -0
- package/browser/workers/types.d.ts.map +1 -1
- package/build/address.d.ts +6 -2
- package/build/address.d.ts.map +1 -1
- package/build/address.js +32 -19
- package/build/address.js.map +1 -1
- package/build/bech32utils.js.map +1 -1
- package/build/block.d.ts.map +1 -1
- package/build/block.js +2 -4
- package/build/block.js.map +1 -1
- package/build/branded.d.ts +3 -14
- package/build/branded.d.ts.map +1 -1
- package/build/branded.js +0 -5
- package/build/branded.js.map +1 -1
- package/build/crypto.d.ts +1 -1
- package/build/ecc/context.d.ts +25 -24
- package/build/ecc/context.d.ts.map +1 -1
- package/build/ecc/context.js +29 -101
- package/build/ecc/context.js.map +1 -1
- package/build/ecc/index.d.ts +1 -1
- package/build/ecc/index.d.ts.map +1 -1
- package/build/ecc/types.d.ts +7 -126
- package/build/ecc/types.d.ts.map +1 -1
- package/build/ecc/types.js +4 -1
- package/build/ecc/types.js.map +1 -1
- package/build/env.d.ts +13 -0
- package/build/env.d.ts.map +1 -0
- package/build/env.js +198 -0
- package/build/env.js.map +1 -0
- package/build/index.d.ts +8 -7
- package/build/index.d.ts.map +1 -1
- package/build/index.js +9 -7
- package/build/index.js.map +1 -1
- package/build/io/BinaryReader.d.ts +15 -15
- package/build/io/BinaryReader.d.ts.map +1 -1
- package/build/io/BinaryReader.js +17 -17
- package/build/io/BinaryReader.js.map +1 -1
- package/build/io/BinaryWriter.d.ts +17 -17
- package/build/io/BinaryWriter.d.ts.map +1 -1
- package/build/io/BinaryWriter.js +39 -39
- package/build/io/BinaryWriter.js.map +1 -1
- package/build/io/hex.d.ts.map +1 -1
- package/build/io/hex.js +2 -1
- package/build/io/hex.js.map +1 -1
- package/build/io/index.d.ts +0 -1
- package/build/io/index.d.ts.map +1 -1
- package/build/io/index.js +0 -2
- package/build/io/index.js.map +1 -1
- package/build/opcodes.d.ts +11 -0
- package/build/opcodes.d.ts.map +1 -1
- package/build/opcodes.js +19 -4
- package/build/opcodes.js.map +1 -1
- package/build/payments/bip341.d.ts +1 -2
- package/build/payments/bip341.d.ts.map +1 -1
- package/build/payments/bip341.js +1 -2
- package/build/payments/bip341.js.map +1 -1
- package/build/payments/embed.d.ts +1 -1
- package/build/payments/embed.d.ts.map +1 -1
- package/build/payments/embed.js +14 -14
- package/build/payments/embed.js.map +1 -1
- package/build/payments/p2ms.d.ts.map +1 -1
- package/build/payments/p2ms.js +21 -21
- package/build/payments/p2ms.js.map +1 -1
- package/build/payments/p2op.d.ts +1 -1
- package/build/payments/p2op.d.ts.map +1 -1
- package/build/payments/p2op.js +18 -18
- package/build/payments/p2op.js.map +1 -1
- package/build/payments/p2pk.d.ts +1 -1
- package/build/payments/p2pk.d.ts.map +1 -1
- package/build/payments/p2pk.js +17 -17
- package/build/payments/p2pk.js.map +1 -1
- package/build/payments/p2pkh.d.ts +1 -1
- package/build/payments/p2pkh.d.ts.map +1 -1
- package/build/payments/p2pkh.js +20 -20
- package/build/payments/p2pkh.js.map +1 -1
- package/build/payments/p2sh.d.ts.map +1 -1
- package/build/payments/p2sh.js +22 -20
- package/build/payments/p2sh.js.map +1 -1
- package/build/payments/p2tr.d.ts +2 -2
- package/build/payments/p2tr.d.ts.map +1 -1
- package/build/payments/p2tr.js +25 -26
- package/build/payments/p2tr.js.map +1 -1
- package/build/payments/p2wpkh.d.ts +1 -1
- package/build/payments/p2wpkh.d.ts.map +1 -1
- package/build/payments/p2wpkh.js +20 -20
- package/build/payments/p2wpkh.js.map +1 -1
- package/build/payments/p2wsh.d.ts.map +1 -1
- package/build/payments/p2wsh.js +22 -22
- package/build/payments/p2wsh.js.map +1 -1
- package/build/payments/types.d.ts +1 -1
- package/build/payments/types.d.ts.map +1 -1
- package/build/psbt/PsbtCache.d.ts +54 -0
- package/build/psbt/PsbtCache.d.ts.map +1 -0
- package/build/psbt/PsbtCache.js +249 -0
- package/build/psbt/PsbtCache.js.map +1 -0
- package/build/psbt/PsbtFinalizer.d.ts +21 -0
- package/build/psbt/PsbtFinalizer.d.ts.map +1 -0
- package/build/psbt/PsbtFinalizer.js +157 -0
- package/build/psbt/PsbtFinalizer.js.map +1 -0
- package/build/psbt/PsbtSigner.d.ts +32 -0
- package/build/psbt/PsbtSigner.d.ts.map +1 -0
- package/build/psbt/PsbtSigner.js +192 -0
- package/build/psbt/PsbtSigner.js.map +1 -0
- package/build/psbt/PsbtTransaction.d.ts +25 -0
- package/build/psbt/PsbtTransaction.d.ts.map +1 -0
- package/build/psbt/PsbtTransaction.js +61 -0
- package/build/psbt/PsbtTransaction.js.map +1 -0
- package/build/psbt/bip371.d.ts.map +1 -1
- package/build/psbt/bip371.js +6 -2
- package/build/psbt/bip371.js.map +1 -1
- package/build/psbt/psbtutils.js +1 -1
- package/build/psbt/psbtutils.js.map +1 -1
- package/build/psbt/types.d.ts +5 -71
- package/build/psbt/types.d.ts.map +1 -1
- package/build/psbt/validation.d.ts +1 -1
- package/build/psbt/validation.d.ts.map +1 -1
- package/build/psbt/validation.js +1 -1
- package/build/psbt/validation.js.map +1 -1
- package/build/psbt.d.ts +26 -40
- package/build/psbt.d.ts.map +1 -1
- package/build/psbt.js +180 -808
- package/build/psbt.js.map +1 -1
- package/build/script.d.ts.map +1 -1
- package/build/script.js +4 -4
- package/build/script.js.map +1 -1
- package/build/transaction.d.ts +4 -4
- package/build/transaction.d.ts.map +1 -1
- package/build/transaction.js +6 -5
- package/build/transaction.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.d.ts +5 -3
- package/build/types.d.ts.map +1 -1
- package/build/types.js +14 -25
- package/build/types.js.map +1 -1
- package/build/workers/WorkerSigningPool.d.ts +24 -17
- package/build/workers/WorkerSigningPool.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.js +36 -25
- package/build/workers/WorkerSigningPool.js.map +1 -1
- package/build/workers/WorkerSigningPool.node.d.ts +19 -12
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.node.js +60 -28
- package/build/workers/WorkerSigningPool.node.js.map +1 -1
- package/build/workers/WorkerSigningPool.sequential.d.ts +76 -0
- package/build/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.sequential.js +160 -0
- package/build/workers/WorkerSigningPool.sequential.js.map +1 -0
- package/build/workers/WorkerSigningPool.worklet.d.ts +79 -0
- package/build/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.worklet.js +390 -0
- package/build/workers/WorkerSigningPool.worklet.js.map +1 -0
- package/build/workers/index.browser.d.ts +24 -0
- package/build/workers/index.browser.d.ts.map +1 -0
- package/build/workers/index.browser.js +30 -0
- package/build/workers/index.browser.js.map +1 -0
- package/build/workers/index.d.ts +6 -18
- package/build/workers/index.d.ts.map +1 -1
- package/build/workers/index.js +12 -14
- package/build/workers/index.js.map +1 -1
- package/build/workers/index.node.d.ts +38 -0
- package/build/workers/index.node.d.ts.map +1 -0
- package/build/workers/index.node.js +45 -0
- package/build/workers/index.node.js.map +1 -0
- package/build/workers/index.react-native.d.ts +28 -0
- package/build/workers/index.react-native.d.ts.map +1 -0
- package/build/workers/index.react-native.js +67 -0
- package/build/workers/index.react-native.js.map +1 -0
- package/build/workers/index.shared.d.ts +15 -0
- package/build/workers/index.shared.d.ts.map +1 -0
- package/build/workers/index.shared.js +20 -0
- package/build/workers/index.shared.js.map +1 -0
- package/build/workers/psbt-parallel.d.ts +2 -3
- package/build/workers/psbt-parallel.d.ts.map +1 -1
- package/build/workers/psbt-parallel.js +4 -4
- package/build/workers/psbt-parallel.js.map +1 -1
- package/build/workers/types.d.ts +17 -0
- package/build/workers/types.d.ts.map +1 -1
- package/build/workers/types.js.map +1 -1
- package/package.json +48 -9
- package/src/address.ts +53 -21
- package/src/bech32utils.ts +3 -3
- package/src/block.ts +17 -10
- package/src/branded.ts +15 -13
- package/src/crypto.ts +1 -1
- package/src/ecc/context.ts +36 -136
- package/src/ecc/index.ts +2 -2
- package/src/ecc/types.ts +7 -145
- package/src/env.ts +239 -0
- package/src/index.ts +57 -22
- package/src/io/BinaryReader.ts +18 -18
- package/src/io/BinaryWriter.ts +43 -43
- package/src/io/hex.ts +2 -1
- package/src/io/index.ts +0 -3
- package/src/opcodes.ts +21 -4
- package/src/payments/bip341.ts +5 -7
- package/src/payments/embed.ts +19 -19
- package/src/payments/p2ms.ts +34 -27
- package/src/payments/p2op.ts +22 -22
- package/src/payments/p2pk.ts +22 -22
- package/src/payments/p2pkh.ts +28 -28
- package/src/payments/p2sh.ts +33 -30
- package/src/payments/p2tr.ts +40 -40
- package/src/payments/p2wpkh.ts +30 -30
- package/src/payments/p2wsh.ts +29 -29
- package/src/payments/types.ts +1 -1
- package/src/psbt/PsbtCache.ts +325 -0
- package/src/psbt/PsbtFinalizer.ts +213 -0
- package/src/psbt/PsbtSigner.ts +302 -0
- package/src/psbt/PsbtTransaction.ts +82 -0
- package/src/psbt/bip371.ts +7 -3
- package/src/psbt/psbtutils.ts +1 -1
- package/src/psbt/types.ts +5 -94
- package/src/psbt/validation.ts +5 -12
- package/src/psbt.ts +376 -1201
- package/src/script.ts +6 -9
- package/src/transaction.ts +19 -15
- package/src/types.ts +33 -45
- package/src/workers/WorkerSigningPool.node.ts +72 -36
- package/src/workers/WorkerSigningPool.sequential.ts +191 -0
- package/src/workers/WorkerSigningPool.ts +48 -39
- package/src/workers/WorkerSigningPool.worklet.ts +522 -0
- package/src/workers/index.browser.ts +34 -0
- package/src/workers/index.node.ts +50 -0
- package/src/workers/index.react-native.ts +110 -0
- package/src/workers/index.shared.ts +58 -0
- package/src/workers/index.ts +14 -65
- package/src/workers/psbt-parallel.ts +8 -13
- package/src/workers/types.ts +26 -1
- package/test/address.spec.ts +2 -2
- package/test/bitcoin.core.spec.ts +5 -2
- package/test/browser/payments.spec.ts +151 -0
- package/test/browser/psbt.spec.ts +1510 -0
- package/test/browser/script.spec.ts +223 -0
- package/test/browser/setup.ts +13 -0
- package/test/browser/workers-signing.spec.ts +537 -0
- package/test/crypto.spec.ts +2 -2
- package/test/env.spec.ts +418 -0
- package/test/fixtures/core/base58_encode_decode.json +12 -48
- package/test/fixtures/core/base58_keys_invalid.json +50 -150
- package/test/fixtures/core/sighash.json +1 -3
- package/test/fixtures/core/tx_valid.json +133 -501
- package/test/fixtures/embed.json +3 -11
- package/test/fixtures/p2ms.json +21 -91
- package/test/fixtures/p2pk.json +5 -24
- package/test/fixtures/p2pkh.json +7 -36
- package/test/fixtures/p2sh.json +8 -54
- package/test/fixtures/p2tr.json +2 -6
- package/test/fixtures/p2wpkh.json +7 -36
- package/test/fixtures/p2wsh.json +14 -59
- package/test/fixtures/psbt.json +2 -6
- package/test/fixtures/script.json +12 -48
- package/test/integration/addresses.spec.ts +11 -5
- package/test/integration/bip32.spec.ts +1 -1
- package/test/integration/cltv.spec.ts +10 -6
- package/test/integration/csv.spec.ts +10 -9
- package/test/integration/payments.spec.ts +8 -4
- package/test/integration/taproot.spec.ts +26 -6
- package/test/integration/transactions.spec.ts +22 -8
- package/test/payments.spec.ts +1 -1
- package/test/payments.utils.ts +1 -1
- package/test/psbt.spec.ts +250 -64
- package/test/script_signature.spec.ts +1 -1
- package/test/transaction.spec.ts +18 -5
- package/test/tsconfig.json +6 -20
- package/test/workers-pool.spec.ts +65 -23
- package/test/workers-sequential.spec.ts +669 -0
- package/test/workers-signing.spec.ts +7 -3
- package/test/workers-worklet.spec.ts +500 -0
- package/test/workers.spec.ts +6 -7
- package/typedoc.json +39 -0
- package/vite.config.browser.ts +31 -6
- package/vitest.config.browser.ts +68 -0
- package/browser/ecpair.d.ts +0 -99
- package/browser/io/MemoryPool.d.ts +0 -220
- package/browser/io/MemoryPool.d.ts.map +0 -1
- package/build/io/MemoryPool.d.ts +0 -220
- package/build/io/MemoryPool.d.ts.map +0 -1
- package/build/io/MemoryPool.js +0 -309
- package/build/io/MemoryPool.js.map +0 -1
- package/src/ecpair.d.ts +0 -99
- package/src/io/MemoryPool.ts +0 -343
- package/test/taproot-cache.spec.ts +0 -694
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btc-vision/bitcoin",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-alpha.
|
|
4
|
+
"version": "7.0.0-alpha.10",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"overrides": {
|
|
7
|
-
"ecpair": {
|
|
8
|
-
"valibot": "^1.2.0"
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
6
|
"description": "Client-side Bitcoin JavaScript library",
|
|
12
7
|
"engines": {
|
|
13
8
|
"node": ">=24.0.0"
|
|
14
9
|
},
|
|
15
10
|
"exports": {
|
|
16
11
|
".": {
|
|
12
|
+
"react-native": {
|
|
13
|
+
"types": "./build/index.d.ts",
|
|
14
|
+
"import": "./build/index.js",
|
|
15
|
+
"default": "./build/index.js"
|
|
16
|
+
},
|
|
17
17
|
"browser": {
|
|
18
18
|
"types": "./browser/index.d.ts",
|
|
19
19
|
"import": "./browser/index.js",
|
|
@@ -33,6 +33,26 @@
|
|
|
33
33
|
"import": "./browser/index.js",
|
|
34
34
|
"default": "./browser/index.js"
|
|
35
35
|
},
|
|
36
|
+
"./workers": {
|
|
37
|
+
"react-native": {
|
|
38
|
+
"types": "./build/workers/index.react-native.d.ts",
|
|
39
|
+
"import": "./build/workers/index.react-native.js",
|
|
40
|
+
"default": "./build/workers/index.react-native.js"
|
|
41
|
+
},
|
|
42
|
+
"browser": {
|
|
43
|
+
"types": "./browser/workers/index.d.ts",
|
|
44
|
+
"import": "./browser/workers/index.js",
|
|
45
|
+
"default": "./browser/workers/index.js"
|
|
46
|
+
},
|
|
47
|
+
"node": {
|
|
48
|
+
"types": "./build/workers/index.node.d.ts",
|
|
49
|
+
"import": "./build/workers/index.node.js",
|
|
50
|
+
"default": "./build/workers/index.node.js"
|
|
51
|
+
},
|
|
52
|
+
"types": "./build/workers/index.d.ts",
|
|
53
|
+
"import": "./build/workers/index.js",
|
|
54
|
+
"default": "./build/workers/index.js"
|
|
55
|
+
},
|
|
36
56
|
"./address": {
|
|
37
57
|
"types": "./build/address.d.ts",
|
|
38
58
|
"import": "./build/address.js"
|
|
@@ -89,6 +109,8 @@
|
|
|
89
109
|
"browser": {
|
|
90
110
|
"./build/index.js": "./browser/index.js",
|
|
91
111
|
"./build/index.d.ts": "./browser/index.d.ts",
|
|
112
|
+
"./build/workers/index.node.js": "./browser/workers/index.js",
|
|
113
|
+
"./build/workers/index.node.d.ts": "./browser/workers/index.d.ts",
|
|
92
114
|
"Buffer": "buffer",
|
|
93
115
|
"crypto": "./src/crypto/crypto-browser.js",
|
|
94
116
|
"stream": "stream-browserify",
|
|
@@ -122,7 +144,7 @@
|
|
|
122
144
|
"audit": "better-npm-audit audit -l high",
|
|
123
145
|
"clean": "rimraf build",
|
|
124
146
|
"coverage": "vitest run --coverage",
|
|
125
|
-
"doc": "typedoc",
|
|
147
|
+
"doc": "typedoc --options typedoc.json",
|
|
126
148
|
"format:ci": "npm run prettier -- --check && npm run prettier -- --check",
|
|
127
149
|
"gitdiff:ci": "npm run build && git diff --exit-code",
|
|
128
150
|
"integration": "vitest run --config vitest.config.integration.ts",
|
|
@@ -132,6 +154,8 @@
|
|
|
132
154
|
"test": "npm run build && npm run lint && vitest run",
|
|
133
155
|
"test:watch": "vitest",
|
|
134
156
|
"unit": "vitest run",
|
|
157
|
+
"test:browser": "vitest run --config vitest.config.browser.ts",
|
|
158
|
+
"test:browser:watch": "vitest --config vitest.config.browser.ts",
|
|
135
159
|
"bench": "vitest bench benchmark/",
|
|
136
160
|
"bench:run": "npx tsx benchmark/signing.bench.ts",
|
|
137
161
|
"check:circular": "madge --circular --extensions ts,tsx src/",
|
|
@@ -143,6 +167,8 @@
|
|
|
143
167
|
"@types/bs58check": "^3.0.1",
|
|
144
168
|
"@types/node": "^25.0.10",
|
|
145
169
|
"@types/randombytes": "^2.0.3",
|
|
170
|
+
"@vitest/browser": "^4.0.18",
|
|
171
|
+
"@vitest/browser-playwright": "^4.0.18",
|
|
146
172
|
"@vitest/coverage-v8": "^4.0.18",
|
|
147
173
|
"better-npm-audit": "^3.11.0",
|
|
148
174
|
"bip39": "^3.1.0",
|
|
@@ -150,12 +176,12 @@
|
|
|
150
176
|
"bip68": "^1.0.4",
|
|
151
177
|
"bs58": "^6.0.0",
|
|
152
178
|
"dhttp": "^3.0.3",
|
|
153
|
-
"ecpair": "^3.0.0",
|
|
154
179
|
"eslint": "^9.39.2",
|
|
155
180
|
"https-browserify": "^1.0.0",
|
|
156
181
|
"madge": "^8.0.0",
|
|
157
182
|
"minimaldata": "^1.0.2",
|
|
158
183
|
"os-browserify": "^0.3.0",
|
|
184
|
+
"playwright": "^1.58.0",
|
|
159
185
|
"prettier": "^3.8.1",
|
|
160
186
|
"randombytes": "^2.1.0",
|
|
161
187
|
"regtest-client": "0.2.1",
|
|
@@ -165,15 +191,27 @@
|
|
|
165
191
|
"tiny-secp256k1": "^2.2.4",
|
|
166
192
|
"ts-node": "^10.9.2",
|
|
167
193
|
"typedoc": "^0.28.16",
|
|
194
|
+
"typedoc-material-theme": "^1.4.1",
|
|
168
195
|
"typescript": "^5.9.3",
|
|
169
196
|
"typescript-eslint": "^8.53.1",
|
|
170
197
|
"vite": "^7.3.1",
|
|
171
198
|
"vite-plugin-dts": "^4.5.4",
|
|
172
199
|
"vite-plugin-node-polyfills": "^0.25.0",
|
|
200
|
+
"vite-plugin-top-level-await": "^1.6.0",
|
|
201
|
+
"vite-plugin-wasm": "^3.5.0",
|
|
173
202
|
"vitest": "^4.0.18"
|
|
174
203
|
},
|
|
204
|
+
"peerDependencies": {
|
|
205
|
+
"react-native-worklets": ">=0.7.0"
|
|
206
|
+
},
|
|
207
|
+
"peerDependenciesMeta": {
|
|
208
|
+
"react-native-worklets": {
|
|
209
|
+
"optional": true
|
|
210
|
+
}
|
|
211
|
+
},
|
|
175
212
|
"dependencies": {
|
|
176
|
-
"@btc-vision/bip32": "^
|
|
213
|
+
"@btc-vision/bip32": "^7.0.2",
|
|
214
|
+
"@btc-vision/ecpair": "^4.0.2",
|
|
177
215
|
"@btc-vision/logger": "^1.0.8",
|
|
178
216
|
"@noble/hashes": "^2.0.1",
|
|
179
217
|
"@noble/secp256k1": "^3.0.0",
|
|
@@ -183,6 +221,7 @@
|
|
|
183
221
|
"browserify-zlib": "^0.2.0",
|
|
184
222
|
"bs58check": "^4.0.0",
|
|
185
223
|
"buffer": "^6.0.3",
|
|
224
|
+
"esbuild": "^0.27.2",
|
|
186
225
|
"process": "^0.11.10",
|
|
187
226
|
"varuint-bitcoin": "^2.0.0"
|
|
188
227
|
}
|
package/src/address.ts
CHANGED
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { bech32, bech32m } from 'bech32';
|
|
11
11
|
import * as bs58check from 'bs58check';
|
|
12
|
-
import {
|
|
12
|
+
import { type Bech32Result, fromBech32 } from './bech32utils.js';
|
|
13
13
|
import { alloc } from './io/index.js';
|
|
14
|
-
import * as networks from './networks.js';
|
|
15
14
|
import type { Network } from './networks.js';
|
|
15
|
+
import * as networks from './networks.js';
|
|
16
16
|
import { p2op } from './payments/p2op.js';
|
|
17
17
|
import { p2pkh } from './payments/p2pkh.js';
|
|
18
18
|
import { p2sh } from './payments/p2sh.js';
|
|
@@ -21,7 +21,14 @@ import { p2wpkh } from './payments/p2wpkh.js';
|
|
|
21
21
|
import { p2wsh } from './payments/p2wsh.js';
|
|
22
22
|
import * as bscript from './script.js';
|
|
23
23
|
import { opcodes } from './script.js';
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
type Bytes20,
|
|
26
|
+
isBytes20,
|
|
27
|
+
isUInt8,
|
|
28
|
+
toBytes20,
|
|
29
|
+
toBytes32,
|
|
30
|
+
type XOnlyPublicKey,
|
|
31
|
+
} from './types.js';
|
|
25
32
|
|
|
26
33
|
export { fromBech32, type Bech32Result };
|
|
27
34
|
|
|
@@ -180,27 +187,51 @@ export function toBech32(
|
|
|
180
187
|
}
|
|
181
188
|
|
|
182
189
|
/**
|
|
183
|
-
* decode address from output script with network, return address if matched
|
|
190
|
+
* decode address from output script with network, return address if matched.
|
|
191
|
+
*
|
|
192
|
+
* Uses fast byte-pattern matching for common script types (P2PKH, P2SH,
|
|
193
|
+
* P2WPKH, P2WSH, P2TR) to avoid constructing payment objects and catching
|
|
194
|
+
* exceptions. Falls back to payment constructors for exotic types.
|
|
184
195
|
*/
|
|
185
196
|
export function fromOutputScript(output: Uint8Array, network?: Network): string {
|
|
186
|
-
// TODO: Network
|
|
187
197
|
network = network || networks.bitcoin;
|
|
198
|
+
const len = output.length;
|
|
199
|
+
|
|
200
|
+
// P2PKH: OP_DUP(0x76) OP_HASH160(0xa9) 0x14 <20-byte hash> OP_EQUALVERIFY(0x88) OP_CHECKSIG(0xac)
|
|
201
|
+
if (
|
|
202
|
+
len === 25 &&
|
|
203
|
+
output[0] === 0x76 &&
|
|
204
|
+
output[1] === 0xa9 &&
|
|
205
|
+
output[2] === 0x14 &&
|
|
206
|
+
output[23] === 0x88 &&
|
|
207
|
+
output[24] === 0xac
|
|
208
|
+
) {
|
|
209
|
+
return toBase58Check(output.subarray(3, 23) as Bytes20, network.pubKeyHash);
|
|
210
|
+
}
|
|
188
211
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
212
|
+
// P2SH: OP_HASH160(0xa9) 0x14 <20-byte hash> OP_EQUAL(0x87)
|
|
213
|
+
if (len === 23 && output[0] === 0xa9 && output[1] === 0x14 && output[22] === 0x87) {
|
|
214
|
+
return toBase58Check(output.subarray(2, 22) as Bytes20, network.scriptHash);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// P2WPKH: OP_0(0x00) 0x14 <20-byte hash>
|
|
218
|
+
if (len === 22 && output[0] === 0x00 && output[1] === 0x14) {
|
|
219
|
+
return toBech32(output.subarray(2, 22), 0, network.bech32);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// P2WSH: OP_0(0x00) 0x20 <32-byte hash>
|
|
223
|
+
if (len === 34 && output[0] === 0x00 && output[1] === 0x20) {
|
|
224
|
+
return toBech32(output.subarray(2, 34), 0, network.bech32);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// P2TR: OP_1(0x51) 0x20 <32-byte x-only pubkey>
|
|
228
|
+
if (len === 34 && output[0] === 0x51 && output[1] === 0x20) {
|
|
229
|
+
const words = bech32m.toWords(output.subarray(2, 34));
|
|
230
|
+
words.unshift(1);
|
|
231
|
+
return bech32m.encode(network.bech32, words);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Fallback for exotic types
|
|
204
235
|
try {
|
|
205
236
|
return toFutureOPNetAddress(output, network);
|
|
206
237
|
} catch (e) {}
|
|
@@ -282,7 +313,8 @@ export function toOutputScript(
|
|
|
282
313
|
return p2wsh({ hash: toBytes32(decodeBech32.data) }).output as Uint8Array;
|
|
283
314
|
} else if (decodeBech32.version === 1) {
|
|
284
315
|
if (decodeBech32.data.length === 32)
|
|
285
|
-
return p2tr({ pubkey: decodeBech32.data as XOnlyPublicKey })
|
|
316
|
+
return p2tr({ pubkey: decodeBech32.data as XOnlyPublicKey })
|
|
317
|
+
.output as Uint8Array;
|
|
286
318
|
} else if (decodeBech32.version === FUTURE_OPNET_VERSION) {
|
|
287
319
|
if (!network.bech32Opnet) throw new Error(address + ' has an invalid prefix');
|
|
288
320
|
return p2op({
|
package/src/bech32utils.ts
CHANGED
|
@@ -25,18 +25,18 @@ export function fromBech32(address: string): Bech32Result {
|
|
|
25
25
|
} catch (e) {}
|
|
26
26
|
|
|
27
27
|
if (result) {
|
|
28
|
-
version = result.words[0];
|
|
28
|
+
version = result.words[0] as number;
|
|
29
29
|
if (version !== 0) throw new TypeError(address + ' uses wrong encoding');
|
|
30
30
|
} else {
|
|
31
31
|
result = bech32m.decode(address);
|
|
32
|
-
version = result.words[0];
|
|
32
|
+
version = result.words[0] as number;
|
|
33
33
|
if (version === 0) throw new TypeError(address + ' uses wrong encoding');
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const data = bech32.fromWords(result.words.slice(1));
|
|
37
37
|
|
|
38
38
|
return {
|
|
39
|
-
version: version
|
|
39
|
+
version: version,
|
|
40
40
|
prefix: result.prefix,
|
|
41
41
|
data: new Uint8Array(data),
|
|
42
42
|
};
|
package/src/block.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import * as bcrypto from './crypto.js';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
alloc,
|
|
4
|
+
BinaryReader,
|
|
5
|
+
BinaryWriter,
|
|
6
|
+
compare,
|
|
7
|
+
equals,
|
|
8
|
+
fromHex,
|
|
9
|
+
reverse,
|
|
10
|
+
toHex,
|
|
11
|
+
varuint,
|
|
12
|
+
} from './io/index.js';
|
|
3
13
|
import { fastMerkleRoot } from './merkle.js';
|
|
4
14
|
import { Transaction } from './transaction.js';
|
|
5
15
|
import type { Bytes32 } from './types.js';
|
|
@@ -70,10 +80,7 @@ export class Block {
|
|
|
70
80
|
if (buffer.length === 80) return block;
|
|
71
81
|
|
|
72
82
|
const readTransaction = (): Transaction => {
|
|
73
|
-
const tx = Transaction.fromBuffer(
|
|
74
|
-
reader.data.subarray(reader.offset),
|
|
75
|
-
true,
|
|
76
|
-
);
|
|
83
|
+
const tx = Transaction.fromBuffer(reader.data.subarray(reader.offset), true);
|
|
77
84
|
reader.offset += tx.byteLength();
|
|
78
85
|
return tx;
|
|
79
86
|
};
|
|
@@ -138,11 +145,11 @@ export class Block {
|
|
|
138
145
|
const rootHash = fastMerkleRoot(hashes, bcrypto.hash256);
|
|
139
146
|
|
|
140
147
|
if (forWitness) {
|
|
141
|
-
const witness = transactions[0]!.ins[0]!.witness
|
|
148
|
+
const witness = transactions[0]!.ins[0]!.witness[0]!;
|
|
142
149
|
const combined = new Uint8Array(rootHash.length + witness.length);
|
|
143
150
|
combined.set(rootHash);
|
|
144
151
|
combined.set(witness, rootHash.length);
|
|
145
|
-
return bcrypto.hash256(combined)
|
|
152
|
+
return bcrypto.hash256(combined);
|
|
146
153
|
}
|
|
147
154
|
return rootHash as Bytes32;
|
|
148
155
|
}
|
|
@@ -158,9 +165,9 @@ export class Block {
|
|
|
158
165
|
// There is no rule for the index of the output, so use filter to find it.
|
|
159
166
|
// The root is prepended with 0xaa21a9ed so check for 0x6a24aa21a9ed
|
|
160
167
|
// If multiple commits are found, the output with highest index is assumed.
|
|
161
|
-
const witnessCommits = this.transactions[0]!.outs
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
const witnessCommits = this.transactions[0]!.outs.filter((out) =>
|
|
169
|
+
equals(out.script.subarray(0, 6), WITNESS_COMMIT_PREFIX),
|
|
170
|
+
).map((out) => out.script.subarray(6, 38));
|
|
164
171
|
if (witnessCommits.length === 0) return null;
|
|
165
172
|
// Use the commit with the highest output (should only be one though)
|
|
166
173
|
const result = witnessCommits[witnessCommits.length - 1];
|
package/src/branded.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Branded type definitions for type-safe primitives.
|
|
3
3
|
*
|
|
4
|
+
* Re-exported from @btc-vision/ecpair to ensure cross-package type compatibility.
|
|
5
|
+
*
|
|
4
6
|
* @packageDocumentation
|
|
5
7
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
export type {
|
|
9
|
+
Brand,
|
|
10
|
+
Bytes32,
|
|
11
|
+
Bytes20,
|
|
12
|
+
PublicKey,
|
|
13
|
+
XOnlyPublicKey,
|
|
14
|
+
Satoshi,
|
|
15
|
+
PrivateKey,
|
|
16
|
+
Signature,
|
|
17
|
+
SchnorrSignature,
|
|
18
|
+
MessageHash,
|
|
19
|
+
Script,
|
|
20
|
+
} from '@btc-vision/ecpair';
|
package/src/crypto.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { ripemd160 as _ripemd160, sha1 as _sha1 } from '@noble/hashes/legacy.js';
|
|
8
8
|
import { sha256 as _sha256 } from '@noble/hashes/sha2.js';
|
|
9
9
|
import { concat } from './io/index.js';
|
|
10
|
-
import type {
|
|
10
|
+
import type { Bytes20, Bytes32 } from './types.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Computes RIPEMD-160 hash of the input.
|
package/src/ecc/context.ts
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
import {
|
|
9
|
-
import type { Bytes32, XOnlyPublicKey } from '../types.js';
|
|
7
|
+
import type { CryptoBackend } from '@btc-vision/ecpair';
|
|
8
|
+
import { verifyCryptoBackend } from '@btc-vision/ecpair';
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Context class for managing the ECC library instance.
|
|
@@ -15,10 +14,11 @@ import type { Bytes32, XOnlyPublicKey } from '../types.js';
|
|
|
15
14
|
* @example
|
|
16
15
|
* ```typescript
|
|
17
16
|
* import { EccContext } from '@btc-vision/bitcoin';
|
|
18
|
-
* import
|
|
17
|
+
* import { createNobleBackend } from '@btc-vision/ecpair';
|
|
19
18
|
*
|
|
20
19
|
* // Initialize once at app startup
|
|
21
|
-
*
|
|
20
|
+
* const backend = createNobleBackend();
|
|
21
|
+
* EccContext.init(backend);
|
|
22
22
|
*
|
|
23
23
|
* // Get instance anywhere in your code
|
|
24
24
|
* const ecc = EccContext.get();
|
|
@@ -29,30 +29,41 @@ import type { Bytes32, XOnlyPublicKey } from '../types.js';
|
|
|
29
29
|
*/
|
|
30
30
|
export class EccContext {
|
|
31
31
|
static #instance: EccContext | undefined;
|
|
32
|
-
readonly #lib:
|
|
32
|
+
readonly #lib: CryptoBackend;
|
|
33
33
|
|
|
34
|
-
private constructor(lib:
|
|
34
|
+
private constructor(lib: CryptoBackend) {
|
|
35
35
|
this.#lib = lib;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* The underlying ECC library instance.
|
|
40
|
+
*/
|
|
41
|
+
get lib(): CryptoBackend {
|
|
42
|
+
return this.#lib;
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
/**
|
|
39
46
|
* Initializes the ECC context with the provided library.
|
|
40
47
|
* The library is verified before being set as active.
|
|
41
48
|
*
|
|
42
|
-
* @param lib - The
|
|
49
|
+
* @param lib - The CryptoBackend instance to initialize
|
|
43
50
|
* @returns The initialized EccContext instance
|
|
44
|
-
* @throws Error if the
|
|
51
|
+
* @throws Error if the CryptoBackend fails verification
|
|
45
52
|
*
|
|
46
53
|
* @example
|
|
47
54
|
* ```typescript
|
|
48
55
|
* import { EccContext } from '@btc-vision/bitcoin';
|
|
49
|
-
* import
|
|
56
|
+
* import { createNobleBackend } from '@btc-vision/ecpair';
|
|
50
57
|
*
|
|
51
|
-
* const context = EccContext.init(
|
|
58
|
+
* const context = EccContext.init(createNobleBackend());
|
|
52
59
|
* ```
|
|
53
60
|
*/
|
|
54
|
-
static init(lib:
|
|
55
|
-
|
|
61
|
+
static init(lib: CryptoBackend): EccContext {
|
|
62
|
+
// Skip re-verification if same lib is already initialized
|
|
63
|
+
if (EccContext.#instance && EccContext.#instance.#lib === lib) {
|
|
64
|
+
return EccContext.#instance;
|
|
65
|
+
}
|
|
66
|
+
verifyCryptoBackend(lib);
|
|
56
67
|
EccContext.#instance = new EccContext(lib);
|
|
57
68
|
return EccContext.#instance;
|
|
58
69
|
}
|
|
@@ -68,7 +79,7 @@ export class EccContext {
|
|
|
68
79
|
* import { EccContext } from '@btc-vision/bitcoin';
|
|
69
80
|
*
|
|
70
81
|
* const context = EccContext.get();
|
|
71
|
-
* const
|
|
82
|
+
* const tweaked = context.lib.xOnlyPointAddTweak(key, tweak);
|
|
72
83
|
* ```
|
|
73
84
|
*/
|
|
74
85
|
static get(): EccContext {
|
|
@@ -106,20 +117,13 @@ export class EccContext {
|
|
|
106
117
|
* import { EccContext } from '@btc-vision/bitcoin';
|
|
107
118
|
*
|
|
108
119
|
* if (!EccContext.isInitialized()) {
|
|
109
|
-
* EccContext.init(
|
|
120
|
+
* EccContext.init(createNobleBackend());
|
|
110
121
|
* }
|
|
111
122
|
* ```
|
|
112
123
|
*/
|
|
113
124
|
static isInitialized(): boolean {
|
|
114
125
|
return EccContext.#instance !== undefined;
|
|
115
126
|
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* The underlying ECC library instance.
|
|
119
|
-
*/
|
|
120
|
-
get lib(): EccLib {
|
|
121
|
-
return this.#lib;
|
|
122
|
-
}
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
/**
|
|
@@ -127,22 +131,22 @@ export class EccContext {
|
|
|
127
131
|
* This is a convenience function that wraps EccContext.init().
|
|
128
132
|
* Pass `undefined` to clear the library.
|
|
129
133
|
*
|
|
130
|
-
* @param eccLib - The
|
|
131
|
-
* @throws Error if the
|
|
134
|
+
* @param eccLib - The CryptoBackend instance to initialize, or undefined to clear
|
|
135
|
+
* @throws Error if the CryptoBackend fails verification
|
|
132
136
|
*
|
|
133
137
|
* @example
|
|
134
138
|
* ```typescript
|
|
135
139
|
* import { initEccLib } from '@btc-vision/bitcoin';
|
|
136
|
-
* import
|
|
140
|
+
* import { createNobleBackend } from '@btc-vision/ecpair';
|
|
137
141
|
*
|
|
138
142
|
* // Initialize the ECC library
|
|
139
|
-
* initEccLib(
|
|
143
|
+
* initEccLib(createNobleBackend());
|
|
140
144
|
*
|
|
141
145
|
* // Clear the library
|
|
142
146
|
* initEccLib(undefined);
|
|
143
147
|
* ```
|
|
144
148
|
*/
|
|
145
|
-
export function initEccLib(eccLib:
|
|
149
|
+
export function initEccLib(eccLib: CryptoBackend | undefined): void {
|
|
146
150
|
if (eccLib === undefined) {
|
|
147
151
|
EccContext.clear();
|
|
148
152
|
return;
|
|
@@ -154,124 +158,20 @@ export function initEccLib(eccLib: EccLib | undefined): void {
|
|
|
154
158
|
* Retrieves the initialized ECC library instance.
|
|
155
159
|
* This is a convenience function that wraps EccContext.get().lib.
|
|
156
160
|
*
|
|
157
|
-
* @returns The
|
|
161
|
+
* @returns The CryptoBackend instance
|
|
158
162
|
* @throws Error if the ECC library has not been initialized
|
|
159
163
|
*
|
|
160
164
|
* @example
|
|
161
165
|
* ```typescript
|
|
162
166
|
* import { getEccLib, initEccLib } from '@btc-vision/bitcoin';
|
|
163
|
-
* import
|
|
167
|
+
* import { createNobleBackend } from '@btc-vision/ecpair';
|
|
164
168
|
*
|
|
165
|
-
* initEccLib(
|
|
169
|
+
* initEccLib(createNobleBackend());
|
|
166
170
|
*
|
|
167
171
|
* const ecc = getEccLib();
|
|
168
|
-
* const
|
|
172
|
+
* const tweaked = ecc.xOnlyPointAddTweak(pubkey, tweak);
|
|
169
173
|
* ```
|
|
170
174
|
*/
|
|
171
|
-
export function getEccLib():
|
|
175
|
+
export function getEccLib(): CryptoBackend {
|
|
172
176
|
return EccContext.get().lib;
|
|
173
177
|
}
|
|
174
|
-
|
|
175
|
-
// ============================================================================
|
|
176
|
-
// Verification
|
|
177
|
-
// ============================================================================
|
|
178
|
-
|
|
179
|
-
interface TweakAddVector {
|
|
180
|
-
pubkey: string;
|
|
181
|
-
tweak: string;
|
|
182
|
-
parity: 0 | 1 | -1;
|
|
183
|
-
result: string | null;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const TWEAK_ADD_VECTORS: TweakAddVector[] = [
|
|
187
|
-
{
|
|
188
|
-
pubkey: '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
|
|
189
|
-
tweak: 'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140',
|
|
190
|
-
parity: -1,
|
|
191
|
-
result: null,
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
pubkey: '1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b',
|
|
195
|
-
tweak: 'a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac',
|
|
196
|
-
parity: 1,
|
|
197
|
-
result: 'e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf',
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
pubkey: '2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991',
|
|
201
|
-
tweak: '823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47',
|
|
202
|
-
parity: 0,
|
|
203
|
-
result: '9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c',
|
|
204
|
-
},
|
|
205
|
-
];
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Verifies that the ECC library implementation is correct.
|
|
209
|
-
* Tests `isXOnlyPoint` and `xOnlyPointAddTweak` with known test vectors.
|
|
210
|
-
*
|
|
211
|
-
* @param ecc - The ECC library to verify
|
|
212
|
-
* @throws Error if any verification test fails
|
|
213
|
-
*/
|
|
214
|
-
function verifyEcc(ecc: EccLib): void {
|
|
215
|
-
if (typeof ecc.isXOnlyPoint !== 'function') {
|
|
216
|
-
throw new Error('ECC library missing isXOnlyPoint function');
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Test isXOnlyPoint with valid points
|
|
220
|
-
const validPoints = [
|
|
221
|
-
'79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
|
|
222
|
-
'fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e',
|
|
223
|
-
'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9',
|
|
224
|
-
'0000000000000000000000000000000000000000000000000000000000000001',
|
|
225
|
-
];
|
|
226
|
-
|
|
227
|
-
for (const hex of validPoints) {
|
|
228
|
-
if (!ecc.isXOnlyPoint(fromHex(hex))) {
|
|
229
|
-
throw new Error(`ECC library isXOnlyPoint failed for valid point: ${hex}`);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Test isXOnlyPoint with invalid points
|
|
234
|
-
const invalidPoints = [
|
|
235
|
-
'0000000000000000000000000000000000000000000000000000000000000000',
|
|
236
|
-
'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
|
|
237
|
-
];
|
|
238
|
-
|
|
239
|
-
for (const hex of invalidPoints) {
|
|
240
|
-
if (ecc.isXOnlyPoint(fromHex(hex))) {
|
|
241
|
-
throw new Error(`ECC library isXOnlyPoint should reject invalid point: ${hex}`);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Test xOnlyPointAddTweak
|
|
246
|
-
if (typeof ecc.xOnlyPointAddTweak !== 'function') {
|
|
247
|
-
throw new Error('ECC library missing xOnlyPointAddTweak function');
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
for (const vector of TWEAK_ADD_VECTORS) {
|
|
251
|
-
const result = ecc.xOnlyPointAddTweak(fromHex(vector.pubkey) as XOnlyPublicKey, fromHex(vector.tweak) as Bytes32);
|
|
252
|
-
|
|
253
|
-
if (vector.result === null) {
|
|
254
|
-
if (result !== null) {
|
|
255
|
-
throw new Error(
|
|
256
|
-
`ECC library xOnlyPointAddTweak should return null for: ${vector.pubkey}`,
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
} else {
|
|
260
|
-
if (result === null) {
|
|
261
|
-
throw new Error(
|
|
262
|
-
`ECC library xOnlyPointAddTweak returned null unexpectedly for: ${vector.pubkey}`,
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
if (result.parity !== vector.parity) {
|
|
266
|
-
throw new Error(
|
|
267
|
-
`ECC library xOnlyPointAddTweak parity mismatch for: ${vector.pubkey}`,
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
if (!equals(result.xOnlyPubkey, fromHex(vector.result))) {
|
|
271
|
-
throw new Error(
|
|
272
|
-
`ECC library xOnlyPointAddTweak result mismatch for: ${vector.pubkey}`,
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
package/src/ecc/index.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
// Core types
|
|
11
|
-
export type { EccLib, XOnlyPointAddTweakResult, Parity } from './types.js';
|
|
10
|
+
// Core types (CryptoBackend is the canonical name; EccLib is a deprecated alias)
|
|
11
|
+
export type { CryptoBackend, EccLib, XOnlyPointAddTweakResult, Parity } from './types.js';
|
|
12
12
|
|
|
13
13
|
// Context management
|
|
14
14
|
export { EccContext, initEccLib, getEccLib } from './context.js';
|