ecash-lib 4.13.0 → 4.14.1
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 +2 -0
- package/dist/blindSchnorr.d.ts +27 -0
- package/dist/blindSchnorr.d.ts.map +1 -0
- package/dist/blindSchnorr.js +206 -0
- package/dist/blindSchnorr.js.map +1 -0
- package/dist/ecc.d.ts +15 -0
- package/dist/ecc.d.ts.map +1 -1
- package/dist/ecc.js +36 -1
- package/dist/ecc.js.map +1 -1
- package/dist/eccScalar.d.ts +12 -0
- package/dist/eccScalar.d.ts.map +1 -0
- package/dist/eccScalar.js +42 -0
- package/dist/eccScalar.js.map +1 -0
- package/dist/ffi/ecash_lib_wasm_bg_browser.js +21408 -22085
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +5 -0
- package/dist/ffi/ecash_lib_wasm_browser.d.ts +39 -0
- package/dist/ffi/ecash_lib_wasm_browser.js +135 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/io/array.d.ts +16 -0
- package/dist/io/array.d.ts.map +1 -0
- package/dist/io/array.js +71 -0
- package/dist/io/array.js.map +1 -0
- package/dist/payment/action.d.ts +7 -0
- package/dist/payment/action.d.ts.map +1 -1
- package/dist/payment/action.js.map +1 -1
- package/dist/pedersen.d.ts +62 -0
- package/dist/pedersen.d.ts.map +1 -0
- package/dist/pedersen.js +257 -0
- package/dist/pedersen.js.map +1 -0
- package/dist/script.d.ts.map +1 -1
- package/dist/script.js +13 -0
- package/dist/script.js.map +1 -1
- package/package.json +3 -3
- package/src/blindSchnorr.ts +241 -0
- package/src/ecc.ts +61 -1
- package/src/eccScalar.ts +41 -0
- package/src/ffi/ecash_lib_wasm_bg_browser.js +21408 -22085
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +5 -0
- package/src/ffi/ecash_lib_wasm_browser.d.ts +39 -0
- package/src/ffi/ecash_lib_wasm_browser.js +135 -0
- package/src/index.ts +4 -0
- package/src/io/array.ts +70 -0
- package/src/payment/action.ts +7 -0
- package/src/pedersen.ts +280 -0
- package/src/script.ts +23 -0
package/src/ecc.ts
CHANGED
|
@@ -35,9 +35,24 @@ export interface Ecc {
|
|
|
35
35
|
/** Add a scalar to a secret key */
|
|
36
36
|
seckeyAdd(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
37
37
|
|
|
38
|
+
/** Multiply a secret key by a scalar (a * b) */
|
|
39
|
+
seckeyMul(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
40
|
+
|
|
41
|
+
/** Negate a secret key (−a mod n) */
|
|
42
|
+
seckeyNegate(a: Uint8Array): Uint8Array;
|
|
43
|
+
|
|
38
44
|
/** Add a scalar to a public key (adding G*b) */
|
|
39
45
|
pubkeyAdd(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
40
46
|
|
|
47
|
+
/** Multiply a public key by a scalar (P * b) */
|
|
48
|
+
pubkeyMul(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
49
|
+
|
|
50
|
+
/** Add two public keys (P + Q). Errors if the sum is infinity. */
|
|
51
|
+
pubkeyCombine(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
52
|
+
|
|
53
|
+
/** Decompress a compressed public key to 65-byte uncompressed (0x04||x||y) */
|
|
54
|
+
uncompressPk(pk: Uint8Array): Uint8Array;
|
|
55
|
+
|
|
41
56
|
/** Sign a ECDSA recoverable signature, includes the recovery ID */
|
|
42
57
|
signRecoverable(seckey: Uint8Array, msg: Uint8Array): Uint8Array;
|
|
43
58
|
|
|
@@ -74,10 +89,30 @@ export class EccDummy implements Ecc {
|
|
|
74
89
|
return new Uint8Array(32);
|
|
75
90
|
}
|
|
76
91
|
|
|
77
|
-
|
|
92
|
+
seckeyMul(_a: Uint8Array, _b: Uint8Array): Uint8Array {
|
|
93
|
+
return new Uint8Array(32);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
seckeyNegate(_a: Uint8Array): Uint8Array {
|
|
78
97
|
return new Uint8Array(32);
|
|
79
98
|
}
|
|
80
99
|
|
|
100
|
+
pubkeyAdd(_a: Uint8Array, _b: Uint8Array): Uint8Array {
|
|
101
|
+
return new Uint8Array(33);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
pubkeyMul(_a: Uint8Array, _b: Uint8Array): Uint8Array {
|
|
105
|
+
return new Uint8Array(33);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
pubkeyCombine(_a: Uint8Array, _b: Uint8Array): Uint8Array {
|
|
109
|
+
return new Uint8Array(33);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
uncompressPk(_pk: Uint8Array): Uint8Array {
|
|
113
|
+
return new Uint8Array(65);
|
|
114
|
+
}
|
|
115
|
+
|
|
81
116
|
signRecoverable(_seckey: Uint8Array, _msg: Uint8Array): Uint8Array {
|
|
82
117
|
return new Uint8Array(65);
|
|
83
118
|
}
|
|
@@ -144,11 +179,36 @@ export class Ecc implements Ecc {
|
|
|
144
179
|
return ECC.ecc!.seckeyAdd(a, b);
|
|
145
180
|
}
|
|
146
181
|
|
|
182
|
+
/** Multiply a secret key by a scalar (a * b) */
|
|
183
|
+
seckeyMul(a: Uint8Array, b: Uint8Array): Uint8Array {
|
|
184
|
+
return ECC.ecc!.seckeyMul(a, b);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Negate a secret key (−a mod n) */
|
|
188
|
+
seckeyNegate(a: Uint8Array): Uint8Array {
|
|
189
|
+
return ECC.ecc!.seckeyNegate(a);
|
|
190
|
+
}
|
|
191
|
+
|
|
147
192
|
/** Add a scalar to a public key (adding G*b) */
|
|
148
193
|
pubkeyAdd(a: Uint8Array, b: Uint8Array): Uint8Array {
|
|
149
194
|
return ECC.ecc!.pubkeyAdd(a, b);
|
|
150
195
|
}
|
|
151
196
|
|
|
197
|
+
/** Multiply a public key by a scalar (P * b) */
|
|
198
|
+
pubkeyMul(a: Uint8Array, b: Uint8Array): Uint8Array {
|
|
199
|
+
return ECC.ecc!.pubkeyMul(a, b);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Add two public keys (P + Q). Errors if the sum is infinity. */
|
|
203
|
+
pubkeyCombine(a: Uint8Array, b: Uint8Array): Uint8Array {
|
|
204
|
+
return ECC.ecc!.pubkeyCombine(a, b);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Decompress a compressed public key to 65-byte uncompressed (0x04||x||y) */
|
|
208
|
+
uncompressPk(pk: Uint8Array): Uint8Array {
|
|
209
|
+
return ECC.ecc!.uncompressPk(pk);
|
|
210
|
+
}
|
|
211
|
+
|
|
152
212
|
signRecoverable(seckey: Uint8Array, msg: Uint8Array): Uint8Array {
|
|
153
213
|
return ECC.ecc!.signRecoverable(seckey, msg);
|
|
154
214
|
}
|
package/src/eccScalar.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) 2026 The Bitcoin developers
|
|
2
|
+
// Distributed under the MIT software license, see the accompanying
|
|
3
|
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
4
|
+
|
|
5
|
+
import { bytesToScalar } from './io/array.js';
|
|
6
|
+
|
|
7
|
+
/** secp256k1 group order n. */
|
|
8
|
+
export const CURVE_ORDER =
|
|
9
|
+
0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;
|
|
10
|
+
|
|
11
|
+
/** Reduce `n` into [0, CURVE_ORDER). */
|
|
12
|
+
export function modCurveOrder(n: bigint): bigint {
|
|
13
|
+
const r = n % CURVE_ORDER;
|
|
14
|
+
return r < 0n ? r + CURVE_ORDER : r;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Big-endian 32-byte encoding of a scalar reduced into [0, n). */
|
|
18
|
+
export function scalarToBytes(n: bigint): Uint8Array {
|
|
19
|
+
let x = modCurveOrder(n);
|
|
20
|
+
const out = new Uint8Array(32);
|
|
21
|
+
for (let i = 31; i >= 0; i--) {
|
|
22
|
+
out[i] = Number(x & 0xffn);
|
|
23
|
+
x >>= 8n;
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Cryptographically random 32-byte scalar in [1, n).
|
|
30
|
+
* Rejection sampling — no modular reduction of the RNG output (avoids bias).
|
|
31
|
+
*/
|
|
32
|
+
export function randomScalarBytes(): Uint8Array {
|
|
33
|
+
const buf = new Uint8Array(32);
|
|
34
|
+
for (;;) {
|
|
35
|
+
crypto.getRandomValues(buf);
|
|
36
|
+
const n = bytesToScalar(buf);
|
|
37
|
+
if (n > 0n && n < CURVE_ORDER) {
|
|
38
|
+
return buf;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|