@btc-vision/bitcoin 7.0.0-alpha.1 → 7.0.0-alpha.2
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/browser/address.d.ts +5 -1
- package/browser/address.d.ts.map +1 -1
- package/browser/branded.d.ts +3 -14
- package/browser/branded.d.ts.map +1 -1
- package/browser/ecc/context.d.ts.map +1 -1
- package/browser/index.d.ts +2 -1
- package/browser/index.d.ts.map +1 -1
- package/browser/index.js +2964 -2919
- package/browser/opcodes.d.ts +11 -0
- package/browser/opcodes.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/types.d.ts +13 -13
- 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 +27 -39
- 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 +4 -2
- package/browser/types.d.ts.map +1 -1
- package/browser/workers/index.d.ts +3 -50
- package/browser/workers/index.d.ts.map +1 -1
- package/browser/workers/index.node.d.ts +24 -0
- package/browser/workers/index.node.d.ts.map +1 -0
- package/build/address.d.ts +5 -1
- package/build/address.d.ts.map +1 -1
- package/build/address.js +29 -17
- package/build/address.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/ecc/context.d.ts.map +1 -1
- package/build/ecc/context.js +68 -45
- package/build/ecc/context.js.map +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/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/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/types.d.ts +13 -13
- 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.d.ts +27 -39
- package/build/psbt.d.ts.map +1 -1
- package/build/psbt.js +139 -746
- package/build/psbt.js.map +1 -1
- package/build/script.d.ts.map +1 -1
- package/build/script.js +2 -2
- 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 +5 -4
- package/build/transaction.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.d.ts +4 -2
- package/build/types.d.ts.map +1 -1
- package/build/types.js +9 -0
- package/build/types.js.map +1 -1
- package/build/workers/WorkerSigningPool.js +1 -1
- package/build/workers/WorkerSigningPool.js.map +1 -1
- package/build/workers/index.d.ts +3 -3
- package/build/workers/index.d.ts.map +1 -1
- package/build/workers/index.js +0 -3
- package/build/workers/index.js.map +1 -1
- package/build/workers/index.node.d.ts +24 -0
- package/build/workers/index.node.d.ts.map +1 -0
- package/build/workers/index.node.js +26 -0
- package/build/workers/index.node.js.map +1 -0
- package/package.json +28 -9
- package/src/address.ts +41 -18
- package/src/branded.ts +15 -13
- package/src/ecc/context.ts +75 -57
- package/src/index.ts +36 -1
- package/src/opcodes.ts +21 -4
- 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/types.ts +13 -13
- package/src/psbt/validation.ts +1 -1
- package/src/psbt.ts +299 -1090
- package/src/script.ts +2 -2
- package/src/transaction.ts +9 -8
- package/src/types.ts +13 -0
- package/src/workers/WorkerSigningPool.ts +1 -1
- package/src/workers/index.node.ts +27 -0
- package/src/workers/index.ts +7 -9
- 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/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 +22 -23
- package/test/workers-signing.spec.ts +7 -3
- package/test/workers.spec.ts +6 -7
- package/typedoc.json +11 -1
- package/vitest.config.browser.ts +68 -0
- package/browser/ecpair.d.ts +0 -99
- package/src/ecpair.d.ts +0 -99
- package/test/taproot-cache.spec.ts +0 -694
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import {
|
|
3
|
-
SignatureType,
|
|
4
|
-
WorkerState,
|
|
5
3
|
type BatchSigningTaskResult,
|
|
6
|
-
type SigningTask,
|
|
7
4
|
type ParallelSignerKeyPair,
|
|
5
|
+
SignatureType,
|
|
6
|
+
type SigningTask,
|
|
8
7
|
type WorkerResponse,
|
|
9
|
-
type SigningResultMessage,
|
|
10
|
-
type WorkerPoolConfig,
|
|
11
8
|
} from '../src/workers/types.js';
|
|
12
9
|
|
|
13
10
|
// Mock Worker class for browser pool testing
|
|
@@ -60,14 +57,16 @@ class MockWorker {
|
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
// Generate results for all tasks
|
|
63
|
-
const results = batchMsg.tasks.map(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
const results = batchMsg.tasks.map(
|
|
61
|
+
(task): BatchSigningTaskResult => ({
|
|
62
|
+
taskId: task.taskId,
|
|
63
|
+
signature: new Uint8Array(64).fill(0xab),
|
|
64
|
+
inputIndex: task.inputIndex,
|
|
65
|
+
publicKey: task.publicKey,
|
|
66
|
+
signatureType: task.signatureType,
|
|
67
|
+
...(task.leafHash ? { leafHash: task.leafHash } : {}),
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
71
70
|
|
|
72
71
|
this.simulateMessage({
|
|
73
72
|
type: 'batchResult',
|
|
@@ -104,6 +103,15 @@ class MockWorker {
|
|
|
104
103
|
this.errorHandlers = [];
|
|
105
104
|
}
|
|
106
105
|
|
|
106
|
+
simulateError(error: Error): void {
|
|
107
|
+
if (this.onerror) {
|
|
108
|
+
this.onerror(error);
|
|
109
|
+
}
|
|
110
|
+
for (const handler of this.errorHandlers) {
|
|
111
|
+
handler(error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
107
115
|
private simulateMessage(data: WorkerResponse): void {
|
|
108
116
|
const event = { data };
|
|
109
117
|
if (this.onmessage) {
|
|
@@ -113,15 +121,6 @@ class MockWorker {
|
|
|
113
121
|
handler(event);
|
|
114
122
|
}
|
|
115
123
|
}
|
|
116
|
-
|
|
117
|
-
simulateError(error: Error): void {
|
|
118
|
-
if (this.onerror) {
|
|
119
|
-
this.onerror(error);
|
|
120
|
-
}
|
|
121
|
-
for (const handler of this.errorHandlers) {
|
|
122
|
-
handler(error);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
124
|
}
|
|
126
125
|
|
|
127
126
|
// Mock Worker that fails signing
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* infrastructure are cryptographically valid.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { beforeAll, describe, expect, it } from 'vitest';
|
|
9
9
|
import * as ecc from 'tiny-secp256k1';
|
|
10
|
-
import { ECPairFactory } from 'ecpair';
|
|
11
10
|
import { randomBytes } from 'crypto';
|
|
12
11
|
|
|
13
12
|
import { SignatureType, type WorkerEccLib } from '../src/workers/types.js';
|
|
@@ -15,8 +14,13 @@ import { generateWorkerCode } from '../src/workers/signing-worker.js';
|
|
|
15
14
|
import { toXOnly } from '../src/pubkey.js';
|
|
16
15
|
import { initEccLib } from '../src/ecc/context.js';
|
|
17
16
|
import type { EccLib } from '../src/types.js';
|
|
17
|
+
import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
|
|
18
|
+
import { bitcoin } from '../src/networks.js';
|
|
18
19
|
|
|
19
|
-
const
|
|
20
|
+
const backend = createNobleBackend();
|
|
21
|
+
const ECPair = {
|
|
22
|
+
makeRandom: () => ECPairSigner.makeRandom(backend, bitcoin),
|
|
23
|
+
};
|
|
20
24
|
|
|
21
25
|
describe('Worker Signing - Signature Verification', () => {
|
|
22
26
|
beforeAll(() => {
|
package/test/workers.spec.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
import {
|
|
3
|
-
SignatureType,
|
|
4
|
-
WorkerState,
|
|
5
3
|
isSigningError,
|
|
6
4
|
isSigningResult,
|
|
7
5
|
isWorkerReady,
|
|
8
|
-
type
|
|
9
|
-
|
|
6
|
+
type ParallelSignerKeyPair,
|
|
7
|
+
SignatureType,
|
|
10
8
|
type SigningErrorMessage,
|
|
11
|
-
type
|
|
9
|
+
type SigningResultMessage,
|
|
12
10
|
type SigningTask,
|
|
13
|
-
type
|
|
11
|
+
type WorkerReadyMessage,
|
|
12
|
+
WorkerState,
|
|
14
13
|
} from '../src/workers/types.js';
|
|
15
14
|
import { generateWorkerCode } from '../src/workers/signing-worker.js';
|
|
16
15
|
|
package/typedoc.json
CHANGED
|
@@ -25,5 +25,15 @@
|
|
|
25
25
|
"plugin": [
|
|
26
26
|
"typedoc-material-theme"
|
|
27
27
|
],
|
|
28
|
-
"themeColor": "#F7931A"
|
|
28
|
+
"themeColor": "#F7931A",
|
|
29
|
+
"intentionallyNotExported": [
|
|
30
|
+
"Brand",
|
|
31
|
+
"HashLeaf",
|
|
32
|
+
"HashBranch",
|
|
33
|
+
"TaggedHashPrefixes",
|
|
34
|
+
"__module",
|
|
35
|
+
"PrevOut",
|
|
36
|
+
"TxInCacheMap",
|
|
37
|
+
"NodeEccLibrary"
|
|
38
|
+
]
|
|
29
39
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { defineConfig } from 'vitest/config';
|
|
3
|
+
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
|
4
|
+
import wasm from 'vite-plugin-wasm';
|
|
5
|
+
import topLevelAwait from 'vite-plugin-top-level-await';
|
|
6
|
+
import { playwright } from '@vitest/browser-playwright';
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
resolve: {
|
|
10
|
+
alias: {
|
|
11
|
+
crypto: resolve(__dirname, 'src/crypto/crypto-browser.js'),
|
|
12
|
+
stream: 'stream-browserify',
|
|
13
|
+
buffer: 'buffer',
|
|
14
|
+
zlib: 'browserify-zlib',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
plugins: [
|
|
18
|
+
wasm(),
|
|
19
|
+
topLevelAwait(),
|
|
20
|
+
nodePolyfills({
|
|
21
|
+
globals: {
|
|
22
|
+
Buffer: true,
|
|
23
|
+
global: true,
|
|
24
|
+
process: true,
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
optimizeDeps: {
|
|
29
|
+
exclude: ['tiny-secp256k1'],
|
|
30
|
+
},
|
|
31
|
+
test: {
|
|
32
|
+
globals: true,
|
|
33
|
+
include: [
|
|
34
|
+
// Browser-compatible existing tests (no Node.js deps)
|
|
35
|
+
'test/address.spec.ts',
|
|
36
|
+
'test/block.spec.ts',
|
|
37
|
+
'test/bufferutils.spec.ts',
|
|
38
|
+
'test/crypto.spec.ts',
|
|
39
|
+
'test/bitcoin.core.spec.ts',
|
|
40
|
+
'test/transaction.spec.ts',
|
|
41
|
+
'test/types.spec.ts',
|
|
42
|
+
'test/script_number.spec.ts',
|
|
43
|
+
'test/script_signature.spec.ts',
|
|
44
|
+
'test/workers.spec.ts',
|
|
45
|
+
'test/workers-pool.spec.ts',
|
|
46
|
+
// Browser-adapted versions
|
|
47
|
+
'test/browser/payments.spec.ts',
|
|
48
|
+
'test/browser/psbt.spec.ts',
|
|
49
|
+
'test/browser/workers-signing.spec.ts',
|
|
50
|
+
'test/browser/script.spec.ts',
|
|
51
|
+
],
|
|
52
|
+
exclude: [
|
|
53
|
+
'test/integration/**/*.ts',
|
|
54
|
+
// Originals that need Node.js APIs
|
|
55
|
+
'test/payments.spec.ts',
|
|
56
|
+
'test/psbt.spec.ts',
|
|
57
|
+
'test/workers-signing.spec.ts',
|
|
58
|
+
'test/script.spec.ts',
|
|
59
|
+
],
|
|
60
|
+
testTimeout: 30000,
|
|
61
|
+
browser: {
|
|
62
|
+
enabled: true,
|
|
63
|
+
provider: playwright(),
|
|
64
|
+
instances: [{ browser: 'chromium' }],
|
|
65
|
+
headless: true,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
package/browser/ecpair.d.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ambient module declaration for ecpair.
|
|
3
|
-
*
|
|
4
|
-
* The upstream ecpair@3 .d.ts files depend on valibot@^0.37 type-level APIs.
|
|
5
|
-
* When a different valibot major is hoisted (e.g. v1.x required by bip32),
|
|
6
|
-
* @typescript-eslint resolves valibot from the project root instead of
|
|
7
|
-
* ecpair's nested node_modules, turning every ecpair type into an error type.
|
|
8
|
-
*
|
|
9
|
-
* This local declaration re-exports the subset of ecpair's public API that
|
|
10
|
-
* this project actually uses, without any valibot dependency.
|
|
11
|
-
*/
|
|
12
|
-
declare module 'ecpair' {
|
|
13
|
-
interface Network {
|
|
14
|
-
messagePrefix: string | Uint8Array;
|
|
15
|
-
bech32: string;
|
|
16
|
-
bip32: {
|
|
17
|
-
public: number;
|
|
18
|
-
private: number;
|
|
19
|
-
};
|
|
20
|
-
pubKeyHash: number;
|
|
21
|
-
scriptHash: number;
|
|
22
|
-
wif: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface Signer {
|
|
26
|
-
publicKey: Uint8Array;
|
|
27
|
-
network?: unknown;
|
|
28
|
-
sign(hash: Uint8Array, lowR?: boolean): Uint8Array;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface SignerAsync {
|
|
32
|
-
publicKey: Uint8Array;
|
|
33
|
-
network?: unknown;
|
|
34
|
-
sign(hash: Uint8Array, lowR?: boolean): Promise<Uint8Array>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface ECPairInterface extends Signer {
|
|
38
|
-
compressed: boolean;
|
|
39
|
-
network: Network;
|
|
40
|
-
lowR: boolean;
|
|
41
|
-
privateKey?: Uint8Array;
|
|
42
|
-
toWIF(): string;
|
|
43
|
-
tweak(t: Uint8Array): ECPairInterface;
|
|
44
|
-
verify(hash: Uint8Array, signature: Uint8Array): boolean;
|
|
45
|
-
verifySchnorr(hash: Uint8Array, signature: Uint8Array): boolean;
|
|
46
|
-
signSchnorr(hash: Uint8Array): Uint8Array;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
interface ECPairOptions {
|
|
50
|
-
compressed?: boolean;
|
|
51
|
-
network?: Network;
|
|
52
|
-
rng?: (arg?: number) => Uint8Array;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
interface ECPairAPI {
|
|
56
|
-
isPoint(maybePoint: unknown): boolean;
|
|
57
|
-
fromPrivateKey(buffer: Uint8Array, options?: ECPairOptions): ECPairInterface;
|
|
58
|
-
fromPublicKey(buffer: Uint8Array, options?: ECPairOptions): ECPairInterface;
|
|
59
|
-
fromWIF(wifString: string, network?: Network | Network[]): ECPairInterface;
|
|
60
|
-
makeRandom(options?: ECPairOptions): ECPairInterface;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
interface TinySecp256k1Interface {
|
|
64
|
-
isPoint(p: Uint8Array): boolean;
|
|
65
|
-
pointCompress(p: Uint8Array, compressed?: boolean): Uint8Array;
|
|
66
|
-
isPrivate(d: Uint8Array): boolean;
|
|
67
|
-
pointFromScalar(d: Uint8Array, compressed?: boolean): Uint8Array | null;
|
|
68
|
-
xOnlyPointAddTweak(
|
|
69
|
-
p: Uint8Array,
|
|
70
|
-
tweak: Uint8Array,
|
|
71
|
-
): { parity: 1 | 0; xOnlyPubkey: Uint8Array } | null;
|
|
72
|
-
privateAdd(d: Uint8Array, tweak: Uint8Array): Uint8Array | null;
|
|
73
|
-
privateNegate(d: Uint8Array): Uint8Array;
|
|
74
|
-
sign(h: Uint8Array, d: Uint8Array, e?: Uint8Array): Uint8Array;
|
|
75
|
-
signSchnorr?(h: Uint8Array, d: Uint8Array, e?: Uint8Array): Uint8Array;
|
|
76
|
-
verify(h: Uint8Array, Q: Uint8Array, signature: Uint8Array, strict?: boolean): boolean;
|
|
77
|
-
verifySchnorr?(h: Uint8Array, Q: Uint8Array, signature: Uint8Array): boolean;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const networks: {
|
|
81
|
-
bitcoin: Network;
|
|
82
|
-
testnet: Network;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
function ECPairFactory(ecc: TinySecp256k1Interface): ECPairAPI;
|
|
86
|
-
export default ECPairFactory;
|
|
87
|
-
|
|
88
|
-
export {
|
|
89
|
-
ECPairFactory,
|
|
90
|
-
Signer,
|
|
91
|
-
SignerAsync,
|
|
92
|
-
ECPairAPI,
|
|
93
|
-
ECPairInterface,
|
|
94
|
-
ECPairOptions,
|
|
95
|
-
TinySecp256k1Interface,
|
|
96
|
-
Network,
|
|
97
|
-
networks,
|
|
98
|
-
};
|
|
99
|
-
}
|
package/src/ecpair.d.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ambient module declaration for ecpair.
|
|
3
|
-
*
|
|
4
|
-
* The upstream ecpair@3 .d.ts files depend on valibot@^0.37 type-level APIs.
|
|
5
|
-
* When a different valibot major is hoisted (e.g. v1.x required by bip32),
|
|
6
|
-
* @typescript-eslint resolves valibot from the project root instead of
|
|
7
|
-
* ecpair's nested node_modules, turning every ecpair type into an error type.
|
|
8
|
-
*
|
|
9
|
-
* This local declaration re-exports the subset of ecpair's public API that
|
|
10
|
-
* this project actually uses, without any valibot dependency.
|
|
11
|
-
*/
|
|
12
|
-
declare module 'ecpair' {
|
|
13
|
-
interface Network {
|
|
14
|
-
messagePrefix: string | Uint8Array;
|
|
15
|
-
bech32: string;
|
|
16
|
-
bip32: {
|
|
17
|
-
public: number;
|
|
18
|
-
private: number;
|
|
19
|
-
};
|
|
20
|
-
pubKeyHash: number;
|
|
21
|
-
scriptHash: number;
|
|
22
|
-
wif: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface Signer {
|
|
26
|
-
publicKey: Uint8Array;
|
|
27
|
-
network?: unknown;
|
|
28
|
-
sign(hash: Uint8Array, lowR?: boolean): Uint8Array;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface SignerAsync {
|
|
32
|
-
publicKey: Uint8Array;
|
|
33
|
-
network?: unknown;
|
|
34
|
-
sign(hash: Uint8Array, lowR?: boolean): Promise<Uint8Array>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface ECPairInterface extends Signer {
|
|
38
|
-
compressed: boolean;
|
|
39
|
-
network: Network;
|
|
40
|
-
lowR: boolean;
|
|
41
|
-
privateKey?: Uint8Array;
|
|
42
|
-
toWIF(): string;
|
|
43
|
-
tweak(t: Uint8Array): ECPairInterface;
|
|
44
|
-
verify(hash: Uint8Array, signature: Uint8Array): boolean;
|
|
45
|
-
verifySchnorr(hash: Uint8Array, signature: Uint8Array): boolean;
|
|
46
|
-
signSchnorr(hash: Uint8Array): Uint8Array;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
interface ECPairOptions {
|
|
50
|
-
compressed?: boolean;
|
|
51
|
-
network?: Network;
|
|
52
|
-
rng?: (arg?: number) => Uint8Array;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
interface ECPairAPI {
|
|
56
|
-
isPoint(maybePoint: unknown): boolean;
|
|
57
|
-
fromPrivateKey(buffer: Uint8Array, options?: ECPairOptions): ECPairInterface;
|
|
58
|
-
fromPublicKey(buffer: Uint8Array, options?: ECPairOptions): ECPairInterface;
|
|
59
|
-
fromWIF(wifString: string, network?: Network | Network[]): ECPairInterface;
|
|
60
|
-
makeRandom(options?: ECPairOptions): ECPairInterface;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
interface TinySecp256k1Interface {
|
|
64
|
-
isPoint(p: Uint8Array): boolean;
|
|
65
|
-
pointCompress(p: Uint8Array, compressed?: boolean): Uint8Array;
|
|
66
|
-
isPrivate(d: Uint8Array): boolean;
|
|
67
|
-
pointFromScalar(d: Uint8Array, compressed?: boolean): Uint8Array | null;
|
|
68
|
-
xOnlyPointAddTweak(
|
|
69
|
-
p: Uint8Array,
|
|
70
|
-
tweak: Uint8Array,
|
|
71
|
-
): { parity: 1 | 0; xOnlyPubkey: Uint8Array } | null;
|
|
72
|
-
privateAdd(d: Uint8Array, tweak: Uint8Array): Uint8Array | null;
|
|
73
|
-
privateNegate(d: Uint8Array): Uint8Array;
|
|
74
|
-
sign(h: Uint8Array, d: Uint8Array, e?: Uint8Array): Uint8Array;
|
|
75
|
-
signSchnorr?(h: Uint8Array, d: Uint8Array, e?: Uint8Array): Uint8Array;
|
|
76
|
-
verify(h: Uint8Array, Q: Uint8Array, signature: Uint8Array, strict?: boolean): boolean;
|
|
77
|
-
verifySchnorr?(h: Uint8Array, Q: Uint8Array, signature: Uint8Array): boolean;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const networks: {
|
|
81
|
-
bitcoin: Network;
|
|
82
|
-
testnet: Network;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
function ECPairFactory(ecc: TinySecp256k1Interface): ECPairAPI;
|
|
86
|
-
export default ECPairFactory;
|
|
87
|
-
|
|
88
|
-
export {
|
|
89
|
-
ECPairFactory,
|
|
90
|
-
Signer,
|
|
91
|
-
SignerAsync,
|
|
92
|
-
ECPairAPI,
|
|
93
|
-
ECPairInterface,
|
|
94
|
-
ECPairOptions,
|
|
95
|
-
TinySecp256k1Interface,
|
|
96
|
-
Network,
|
|
97
|
-
networks,
|
|
98
|
-
};
|
|
99
|
-
}
|