@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
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-adapted version of test/workers-signing.spec.ts
|
|
3
|
+
* Replaces Node.js crypto.randomBytes with browser-safe alternative.
|
|
4
|
+
* Excludes Worker Code Integrity tests (Node-specific worker code generation).
|
|
5
|
+
*/
|
|
6
|
+
import { beforeAll, describe, expect, it } from 'vitest';
|
|
7
|
+
import * as ecc from 'tiny-secp256k1';
|
|
8
|
+
|
|
9
|
+
import { randomBytes } from './setup.js';
|
|
10
|
+
import { SignatureType, type WorkerEccLib } from '../../src/workers/types.js';
|
|
11
|
+
import { toXOnly } from '../../src/pubkey.js';
|
|
12
|
+
import { initEccLib } from '../../src/ecc/context.js';
|
|
13
|
+
import type { EccLib } from '../../src/types.js';
|
|
14
|
+
import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
|
|
15
|
+
import { bitcoin } from '../../src/networks.js';
|
|
16
|
+
|
|
17
|
+
const backend = createNobleBackend();
|
|
18
|
+
const ECPair = {
|
|
19
|
+
makeRandom: () => ECPairSigner.makeRandom(backend, bitcoin),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('Worker Signing - Signature Verification', () => {
|
|
23
|
+
beforeAll(() => {
|
|
24
|
+
initEccLib(ecc as unknown as EccLib);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('ECDSA Signature Generation and Verification', () => {
|
|
28
|
+
it('should generate valid ECDSA signature that verifies', () => {
|
|
29
|
+
const keyPair = ECPair.makeRandom();
|
|
30
|
+
const privateKey = keyPair.privateKey!;
|
|
31
|
+
const publicKey = keyPair.publicKey;
|
|
32
|
+
|
|
33
|
+
const hash = randomBytes(32);
|
|
34
|
+
|
|
35
|
+
const signature = ecc.sign(hash, privateKey);
|
|
36
|
+
|
|
37
|
+
const isValid = ecc.verify(hash, publicKey, signature);
|
|
38
|
+
expect(isValid).toBe(true);
|
|
39
|
+
|
|
40
|
+
expect(signature.length).toBe(64);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should generate valid ECDSA signature with lowR', () => {
|
|
44
|
+
const keyPair = ECPair.makeRandom();
|
|
45
|
+
const privateKey = keyPair.privateKey!;
|
|
46
|
+
const publicKey = keyPair.publicKey;
|
|
47
|
+
const hash = randomBytes(32);
|
|
48
|
+
|
|
49
|
+
const signature = ecc.sign(hash, privateKey, undefined);
|
|
50
|
+
|
|
51
|
+
const isValid = ecc.verify(hash, publicKey, signature);
|
|
52
|
+
expect(isValid).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should produce different signatures for different hashes', () => {
|
|
56
|
+
const keyPair = ECPair.makeRandom();
|
|
57
|
+
const privateKey = keyPair.privateKey!;
|
|
58
|
+
|
|
59
|
+
const hash1 = randomBytes(32);
|
|
60
|
+
const hash2 = randomBytes(32);
|
|
61
|
+
|
|
62
|
+
const sig1 = ecc.sign(hash1, privateKey);
|
|
63
|
+
const sig2 = ecc.sign(hash2, privateKey);
|
|
64
|
+
|
|
65
|
+
expect(Buffer.from(sig1).equals(Buffer.from(sig2))).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should fail verification with wrong public key', () => {
|
|
69
|
+
const keyPair1 = ECPair.makeRandom();
|
|
70
|
+
const keyPair2 = ECPair.makeRandom();
|
|
71
|
+
const hash = randomBytes(32);
|
|
72
|
+
|
|
73
|
+
const signature = ecc.sign(hash, keyPair1.privateKey!);
|
|
74
|
+
|
|
75
|
+
const isValid = ecc.verify(hash, keyPair2.publicKey, signature);
|
|
76
|
+
expect(isValid).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should fail verification with modified hash', () => {
|
|
80
|
+
const keyPair = ECPair.makeRandom();
|
|
81
|
+
const hash = randomBytes(32);
|
|
82
|
+
|
|
83
|
+
const signature = ecc.sign(hash, keyPair.privateKey!);
|
|
84
|
+
|
|
85
|
+
const modifiedHash = Buffer.from(hash);
|
|
86
|
+
modifiedHash[0] ^= 0xff;
|
|
87
|
+
|
|
88
|
+
const isValid = ecc.verify(modifiedHash, keyPair.publicKey, signature);
|
|
89
|
+
expect(isValid).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should fail verification with corrupted signature', () => {
|
|
93
|
+
const keyPair = ECPair.makeRandom();
|
|
94
|
+
const hash = randomBytes(32);
|
|
95
|
+
|
|
96
|
+
const signature = Buffer.from(ecc.sign(hash, keyPair.privateKey!));
|
|
97
|
+
|
|
98
|
+
signature[0] ^= 0xff;
|
|
99
|
+
|
|
100
|
+
const isValid = ecc.verify(hash, keyPair.publicKey, signature);
|
|
101
|
+
expect(isValid).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('Schnorr Signature Generation and Verification', () => {
|
|
106
|
+
it('should generate valid Schnorr signature that verifies', () => {
|
|
107
|
+
const keyPair = ECPair.makeRandom();
|
|
108
|
+
const privateKey = keyPair.privateKey!;
|
|
109
|
+
const publicKey = keyPair.publicKey;
|
|
110
|
+
const hash = randomBytes(32);
|
|
111
|
+
|
|
112
|
+
const signature = ecc.signSchnorr(hash, privateKey);
|
|
113
|
+
|
|
114
|
+
expect(signature.length).toBe(64);
|
|
115
|
+
|
|
116
|
+
const xOnlyPubkey = toXOnly(publicKey);
|
|
117
|
+
const isValid = ecc.verifySchnorr(hash, xOnlyPubkey, signature);
|
|
118
|
+
expect(isValid).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should produce different Schnorr signatures for different hashes', () => {
|
|
122
|
+
const keyPair = ECPair.makeRandom();
|
|
123
|
+
const privateKey = keyPair.privateKey!;
|
|
124
|
+
|
|
125
|
+
const hash1 = randomBytes(32);
|
|
126
|
+
const hash2 = randomBytes(32);
|
|
127
|
+
|
|
128
|
+
const sig1 = ecc.signSchnorr(hash1, privateKey);
|
|
129
|
+
const sig2 = ecc.signSchnorr(hash2, privateKey);
|
|
130
|
+
|
|
131
|
+
expect(Buffer.from(sig1).equals(Buffer.from(sig2))).toBe(false);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should fail Schnorr verification with wrong public key', () => {
|
|
135
|
+
const keyPair1 = ECPair.makeRandom();
|
|
136
|
+
const keyPair2 = ECPair.makeRandom();
|
|
137
|
+
const hash = randomBytes(32);
|
|
138
|
+
|
|
139
|
+
const signature = ecc.signSchnorr(hash, keyPair1.privateKey!);
|
|
140
|
+
|
|
141
|
+
const xOnlyPubkey2 = toXOnly(keyPair2.publicKey);
|
|
142
|
+
const isValid = ecc.verifySchnorr(hash, xOnlyPubkey2, signature);
|
|
143
|
+
expect(isValid).toBe(false);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should fail Schnorr verification with modified hash', () => {
|
|
147
|
+
const keyPair = ECPair.makeRandom();
|
|
148
|
+
const hash = randomBytes(32);
|
|
149
|
+
|
|
150
|
+
const signature = ecc.signSchnorr(hash, keyPair.privateKey!);
|
|
151
|
+
|
|
152
|
+
const modifiedHash = Buffer.from(hash);
|
|
153
|
+
modifiedHash[0] ^= 0xff;
|
|
154
|
+
|
|
155
|
+
const xOnlyPubkey = toXOnly(keyPair.publicKey);
|
|
156
|
+
const isValid = ecc.verifySchnorr(modifiedHash, xOnlyPubkey, signature);
|
|
157
|
+
expect(isValid).toBe(false);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should fail Schnorr verification with corrupted signature', () => {
|
|
161
|
+
const keyPair = ECPair.makeRandom();
|
|
162
|
+
const hash = randomBytes(32);
|
|
163
|
+
|
|
164
|
+
const signature = Buffer.from(ecc.signSchnorr(hash, keyPair.privateKey!));
|
|
165
|
+
signature[0] ^= 0xff;
|
|
166
|
+
|
|
167
|
+
const xOnlyPubkey = toXOnly(keyPair.publicKey);
|
|
168
|
+
const isValid = ecc.verifySchnorr(hash, xOnlyPubkey, signature);
|
|
169
|
+
expect(isValid).toBe(false);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe('WorkerEccLib Interface Compatibility', () => {
|
|
174
|
+
it('should create WorkerEccLib compatible wrapper', () => {
|
|
175
|
+
const eccLib: WorkerEccLib = {
|
|
176
|
+
sign: (hash: Uint8Array, privateKey: Uint8Array, lowR?: boolean): Uint8Array => {
|
|
177
|
+
return ecc.sign(hash, privateKey, undefined);
|
|
178
|
+
},
|
|
179
|
+
signSchnorr: (hash: Uint8Array, privateKey: Uint8Array): Uint8Array => {
|
|
180
|
+
return ecc.signSchnorr(hash, privateKey);
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const keyPair = ECPair.makeRandom();
|
|
185
|
+
const hash = randomBytes(32);
|
|
186
|
+
|
|
187
|
+
const ecdsaSig = eccLib.sign(hash, keyPair.privateKey!);
|
|
188
|
+
expect(ecc.verify(hash, keyPair.publicKey, ecdsaSig)).toBe(true);
|
|
189
|
+
|
|
190
|
+
const schnorrSig = eccLib.signSchnorr!(hash, keyPair.privateKey!);
|
|
191
|
+
expect(ecc.verifySchnorr(hash, toXOnly(keyPair.publicKey), schnorrSig)).toBe(true);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should handle signing type dispatch correctly', () => {
|
|
195
|
+
const eccLib: WorkerEccLib = {
|
|
196
|
+
sign: (hash: Uint8Array, privateKey: Uint8Array): Uint8Array => {
|
|
197
|
+
return ecc.sign(hash, privateKey);
|
|
198
|
+
},
|
|
199
|
+
signSchnorr: (hash: Uint8Array, privateKey: Uint8Array): Uint8Array => {
|
|
200
|
+
return ecc.signSchnorr(hash, privateKey);
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const keyPair = ECPair.makeRandom();
|
|
205
|
+
const hash = randomBytes(32);
|
|
206
|
+
|
|
207
|
+
const signatureType = SignatureType.Schnorr;
|
|
208
|
+
|
|
209
|
+
let signature: Uint8Array;
|
|
210
|
+
if (signatureType === SignatureType.Schnorr) {
|
|
211
|
+
signature = eccLib.signSchnorr!(hash, keyPair.privateKey!);
|
|
212
|
+
} else {
|
|
213
|
+
signature = eccLib.sign(hash, keyPair.privateKey!);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
expect(signature.length).toBe(64);
|
|
217
|
+
expect(ecc.verifySchnorr(hash, toXOnly(keyPair.publicKey), signature)).toBe(true);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe('Key Zeroing Security', () => {
|
|
222
|
+
it('should verify secureZero clears key data', () => {
|
|
223
|
+
const secureZero = (arr: Uint8Array): void => {
|
|
224
|
+
arr.fill(0);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const privateKey = new Uint8Array(randomBytes(32));
|
|
228
|
+
expect(privateKey.some((b) => b !== 0)).toBe(true);
|
|
229
|
+
|
|
230
|
+
secureZero(privateKey);
|
|
231
|
+
|
|
232
|
+
expect(privateKey.every((b) => b === 0)).toBe(true);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('should verify key is zeroed after signing (simulation)', () => {
|
|
236
|
+
const keyPair = ECPair.makeRandom();
|
|
237
|
+
const hash = randomBytes(32);
|
|
238
|
+
|
|
239
|
+
const keyCopy = new Uint8Array(keyPair.privateKey!);
|
|
240
|
+
|
|
241
|
+
const signature = ecc.sign(hash, keyCopy);
|
|
242
|
+
|
|
243
|
+
keyCopy.fill(0);
|
|
244
|
+
|
|
245
|
+
expect(ecc.verify(hash, keyPair.publicKey, signature)).toBe(true);
|
|
246
|
+
|
|
247
|
+
expect(keyCopy.every((b) => b === 0)).toBe(true);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
describe('Batch Signing Simulation', () => {
|
|
252
|
+
it('should sign multiple inputs with same key', () => {
|
|
253
|
+
const keyPair = ECPair.makeRandom();
|
|
254
|
+
const hashes = Array.from({ length: 10 }, () => randomBytes(32));
|
|
255
|
+
|
|
256
|
+
const signatures = hashes.map((hash) => ecc.sign(hash, keyPair.privateKey!));
|
|
257
|
+
|
|
258
|
+
for (let i = 0; i < hashes.length; i++) {
|
|
259
|
+
expect(ecc.verify(hashes[i], keyPair.publicKey, signatures[i])).toBe(true);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('should sign mixed ECDSA and Schnorr in batch', () => {
|
|
264
|
+
const keyPair = ECPair.makeRandom();
|
|
265
|
+
const tasks = [
|
|
266
|
+
{ hash: randomBytes(32), type: SignatureType.ECDSA },
|
|
267
|
+
{ hash: randomBytes(32), type: SignatureType.Schnorr },
|
|
268
|
+
{ hash: randomBytes(32), type: SignatureType.ECDSA },
|
|
269
|
+
{ hash: randomBytes(32), type: SignatureType.Schnorr },
|
|
270
|
+
];
|
|
271
|
+
|
|
272
|
+
const results = tasks.map((task) => {
|
|
273
|
+
if (task.type === SignatureType.Schnorr) {
|
|
274
|
+
return {
|
|
275
|
+
signature: ecc.signSchnorr(task.hash, keyPair.privateKey!),
|
|
276
|
+
type: task.type,
|
|
277
|
+
hash: task.hash,
|
|
278
|
+
};
|
|
279
|
+
} else {
|
|
280
|
+
return {
|
|
281
|
+
signature: ecc.sign(task.hash, keyPair.privateKey!),
|
|
282
|
+
type: task.type,
|
|
283
|
+
hash: task.hash,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
for (const result of results) {
|
|
289
|
+
if (result.type === SignatureType.Schnorr) {
|
|
290
|
+
expect(
|
|
291
|
+
ecc.verifySchnorr(
|
|
292
|
+
result.hash,
|
|
293
|
+
toXOnly(keyPair.publicKey),
|
|
294
|
+
result.signature,
|
|
295
|
+
),
|
|
296
|
+
).toBe(true);
|
|
297
|
+
} else {
|
|
298
|
+
expect(ecc.verify(result.hash, keyPair.publicKey, result.signature)).toBe(true);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('should handle 100 signatures in parallel simulation', () => {
|
|
304
|
+
const keyPair = ECPair.makeRandom();
|
|
305
|
+
const tasks = Array.from({ length: 100 }, (_, i) => ({
|
|
306
|
+
hash: randomBytes(32),
|
|
307
|
+
type: i % 2 === 0 ? SignatureType.ECDSA : SignatureType.Schnorr,
|
|
308
|
+
}));
|
|
309
|
+
|
|
310
|
+
const startTime = Date.now();
|
|
311
|
+
|
|
312
|
+
const results = tasks.map((task) => {
|
|
313
|
+
if (task.type === SignatureType.Schnorr) {
|
|
314
|
+
return {
|
|
315
|
+
signature: ecc.signSchnorr(task.hash, keyPair.privateKey!),
|
|
316
|
+
type: task.type,
|
|
317
|
+
hash: task.hash,
|
|
318
|
+
};
|
|
319
|
+
} else {
|
|
320
|
+
return {
|
|
321
|
+
signature: ecc.sign(task.hash, keyPair.privateKey!),
|
|
322
|
+
type: task.type,
|
|
323
|
+
hash: task.hash,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const duration = Date.now() - startTime;
|
|
329
|
+
|
|
330
|
+
let validCount = 0;
|
|
331
|
+
for (const result of results) {
|
|
332
|
+
let isValid: boolean;
|
|
333
|
+
if (result.type === SignatureType.Schnorr) {
|
|
334
|
+
isValid = ecc.verifySchnorr(
|
|
335
|
+
result.hash,
|
|
336
|
+
toXOnly(keyPair.publicKey),
|
|
337
|
+
result.signature,
|
|
338
|
+
);
|
|
339
|
+
} else {
|
|
340
|
+
isValid = ecc.verify(result.hash, keyPair.publicKey, result.signature);
|
|
341
|
+
}
|
|
342
|
+
if (isValid) validCount++;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
expect(validCount).toBe(100);
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
describe('Edge Cases', () => {
|
|
350
|
+
it('should handle hash with all zeros', () => {
|
|
351
|
+
const keyPair = ECPair.makeRandom();
|
|
352
|
+
const hash = new Uint8Array(32).fill(0);
|
|
353
|
+
|
|
354
|
+
const signature = ecc.sign(hash, keyPair.privateKey!);
|
|
355
|
+
expect(ecc.verify(hash, keyPair.publicKey, signature)).toBe(true);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('should handle hash with all 0xff', () => {
|
|
359
|
+
const keyPair = ECPair.makeRandom();
|
|
360
|
+
const hash = new Uint8Array(32).fill(0xff);
|
|
361
|
+
|
|
362
|
+
const signature = ecc.sign(hash, keyPair.privateKey!);
|
|
363
|
+
expect(ecc.verify(hash, keyPair.publicKey, signature)).toBe(true);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('should handle sequential hashes', () => {
|
|
367
|
+
const keyPair = ECPair.makeRandom();
|
|
368
|
+
|
|
369
|
+
for (let i = 0; i < 10; i++) {
|
|
370
|
+
const hash = new Uint8Array(32);
|
|
371
|
+
hash[0] = i;
|
|
372
|
+
|
|
373
|
+
const signature = ecc.sign(hash, keyPair.privateKey!);
|
|
374
|
+
expect(ecc.verify(hash, keyPair.publicKey, signature)).toBe(true);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it('should handle deterministic signatures (same hash, same key)', () => {
|
|
379
|
+
const privateKey = new Uint8Array(32).fill(0x42);
|
|
380
|
+
if (!ecc.isPrivate(privateKey)) {
|
|
381
|
+
privateKey.fill(0);
|
|
382
|
+
privateKey[31] = 1;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const hash = new Uint8Array(32).fill(0xab);
|
|
386
|
+
|
|
387
|
+
const sig1 = ecc.sign(hash, privateKey);
|
|
388
|
+
const sig2 = ecc.sign(hash, privateKey);
|
|
389
|
+
|
|
390
|
+
expect(Buffer.from(sig1).equals(Buffer.from(sig2))).toBe(true);
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
describe('Worker Code Execution Simulation', () => {
|
|
395
|
+
it('should execute simulated worker signing flow', () => {
|
|
396
|
+
const eccLib: WorkerEccLib = {
|
|
397
|
+
sign: (hash, privateKey) => ecc.sign(hash, privateKey),
|
|
398
|
+
signSchnorr: (hash, privateKey) => ecc.signSchnorr(hash, privateKey),
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const keyPair = ECPair.makeRandom();
|
|
402
|
+
const privateKeyCopy = new Uint8Array(keyPair.privateKey!);
|
|
403
|
+
const hash = randomBytes(32);
|
|
404
|
+
|
|
405
|
+
const signatureType = SignatureType.ECDSA;
|
|
406
|
+
let signature: Uint8Array;
|
|
407
|
+
|
|
408
|
+
try {
|
|
409
|
+
if (signatureType === SignatureType.Schnorr) {
|
|
410
|
+
if (!eccLib.signSchnorr) {
|
|
411
|
+
throw new Error('ECC library does not support Schnorr');
|
|
412
|
+
}
|
|
413
|
+
signature = eccLib.signSchnorr(hash, privateKeyCopy);
|
|
414
|
+
} else {
|
|
415
|
+
signature = eccLib.sign(hash, privateKeyCopy);
|
|
416
|
+
}
|
|
417
|
+
} finally {
|
|
418
|
+
privateKeyCopy.fill(0);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
expect(ecc.verify(hash, keyPair.publicKey, signature)).toBe(true);
|
|
422
|
+
|
|
423
|
+
expect(privateKeyCopy.every((b) => b === 0)).toBe(true);
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it('should handle signing errors gracefully', () => {
|
|
427
|
+
const invalidPrivateKey = new Uint8Array(32).fill(0);
|
|
428
|
+
const hash = randomBytes(32);
|
|
429
|
+
|
|
430
|
+
expect(() => {
|
|
431
|
+
ecc.sign(hash, invalidPrivateKey);
|
|
432
|
+
}).toThrow();
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('should validate hash length', () => {
|
|
436
|
+
const keyPair = ECPair.makeRandom();
|
|
437
|
+
|
|
438
|
+
const shortHash = new Uint8Array(31);
|
|
439
|
+
expect(() => {
|
|
440
|
+
ecc.sign(shortHash, keyPair.privateKey!);
|
|
441
|
+
}).toThrow();
|
|
442
|
+
|
|
443
|
+
const longHash = new Uint8Array(33);
|
|
444
|
+
expect(() => {
|
|
445
|
+
ecc.sign(longHash, keyPair.privateKey!);
|
|
446
|
+
}).toThrow();
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it('should validate private key length', () => {
|
|
450
|
+
const hash = randomBytes(32);
|
|
451
|
+
|
|
452
|
+
const shortKey = new Uint8Array(31).fill(0x42);
|
|
453
|
+
expect(() => {
|
|
454
|
+
ecc.sign(hash, shortKey);
|
|
455
|
+
}).toThrow();
|
|
456
|
+
|
|
457
|
+
const longKey = new Uint8Array(33).fill(0x42);
|
|
458
|
+
expect(() => {
|
|
459
|
+
ecc.sign(hash, longKey);
|
|
460
|
+
}).toThrow();
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
describe('Taproot-Specific Tests', () => {
|
|
465
|
+
it('should generate valid key-path Taproot signature', () => {
|
|
466
|
+
const keyPair = ECPair.makeRandom();
|
|
467
|
+
const hash = randomBytes(32);
|
|
468
|
+
|
|
469
|
+
const signature = ecc.signSchnorr(hash, keyPair.privateKey!);
|
|
470
|
+
const xOnlyPubkey = toXOnly(keyPair.publicKey);
|
|
471
|
+
|
|
472
|
+
expect(signature.length).toBe(64);
|
|
473
|
+
expect(xOnlyPubkey.length).toBe(32);
|
|
474
|
+
expect(ecc.verifySchnorr(hash, xOnlyPubkey, signature)).toBe(true);
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
it('should generate valid script-path Taproot signature', () => {
|
|
478
|
+
const keyPair = ECPair.makeRandom();
|
|
479
|
+
const hash = randomBytes(32);
|
|
480
|
+
const leafHash = randomBytes(32);
|
|
481
|
+
|
|
482
|
+
const signature = ecc.signSchnorr(hash, keyPair.privateKey!);
|
|
483
|
+
const xOnlyPubkey = toXOnly(keyPair.publicKey);
|
|
484
|
+
|
|
485
|
+
expect(ecc.verifySchnorr(hash, xOnlyPubkey, signature)).toBe(true);
|
|
486
|
+
|
|
487
|
+
expect(leafHash.length).toBe(32);
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it('should verify x-only pubkey extraction', () => {
|
|
491
|
+
const keyPair = ECPair.makeRandom();
|
|
492
|
+
const fullPubkey = keyPair.publicKey;
|
|
493
|
+
const xOnlyPubkey = toXOnly(fullPubkey);
|
|
494
|
+
|
|
495
|
+
expect(xOnlyPubkey.length).toBe(32);
|
|
496
|
+
|
|
497
|
+
expect(Buffer.from(xOnlyPubkey).equals(Buffer.from(fullPubkey.subarray(1, 33)))).toBe(
|
|
498
|
+
true,
|
|
499
|
+
);
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
describe('Real Transaction Hash Signing', () => {
|
|
504
|
+
it('should sign a real transaction sighash', () => {
|
|
505
|
+
const keyPair = ECPair.makeRandom();
|
|
506
|
+
|
|
507
|
+
const sighash = Buffer.from(
|
|
508
|
+
'0100000000000000000000000000000000000000000000000000000000000000',
|
|
509
|
+
'hex',
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
const signature = ecc.sign(sighash, keyPair.privateKey!);
|
|
513
|
+
|
|
514
|
+
expect(ecc.verify(sighash, keyPair.publicKey, signature)).toBe(true);
|
|
515
|
+
|
|
516
|
+
expect(signature.length).toBe(64);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it('should handle multiple sighash types', () => {
|
|
520
|
+
const keyPair = ECPair.makeRandom();
|
|
521
|
+
|
|
522
|
+
const sighashAll = randomBytes(32);
|
|
523
|
+
const sighashNone = randomBytes(32);
|
|
524
|
+
const sighashSingle = randomBytes(32);
|
|
525
|
+
|
|
526
|
+
const sigAll = ecc.sign(sighashAll, keyPair.privateKey!);
|
|
527
|
+
const sigNone = ecc.sign(sighashNone, keyPair.privateKey!);
|
|
528
|
+
const sigSingle = ecc.sign(sighashSingle, keyPair.privateKey!);
|
|
529
|
+
|
|
530
|
+
expect(ecc.verify(sighashAll, keyPair.publicKey, sigAll)).toBe(true);
|
|
531
|
+
expect(ecc.verify(sighashNone, keyPair.publicKey, sigNone)).toBe(true);
|
|
532
|
+
expect(ecc.verify(sighashSingle, keyPair.publicKey, sigSingle)).toBe(true);
|
|
533
|
+
|
|
534
|
+
expect(ecc.verify(sighashAll, keyPair.publicKey, sigNone)).toBe(false);
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
});
|
package/test/crypto.spec.ts
CHANGED
|
@@ -2,9 +2,9 @@ import assert from 'assert';
|
|
|
2
2
|
import { describe, it } from 'vitest';
|
|
3
3
|
import { crypto as bcrypto } from '../src/index.js';
|
|
4
4
|
import type { TaggedHashPrefix } from '../src/crypto.js';
|
|
5
|
-
import fixtures from './fixtures/crypto.json' with { type: 'json' };
|
|
6
5
|
import { sha256, TAGGED_HASH_PREFIXES, TAGS } from '../src/crypto.js';
|
|
7
|
-
import
|
|
6
|
+
import fixtures from './fixtures/crypto.json' with { type: 'json' };
|
|
7
|
+
import { concat, equals, fromHex, fromUtf8, toHex } from '../src/io/index.js';
|
|
8
8
|
|
|
9
9
|
describe('crypto', () => {
|
|
10
10
|
['hash160', 'hash256', 'ripemd160', 'sha1', 'sha256'].forEach((algorithm) => {
|