@noble/curves 0.5.2 → 0.6.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 +115 -41
- package/lib/_shortw_utils.d.ts +13 -24
- package/lib/abstract/bls.d.ts +39 -32
- package/lib/abstract/bls.js +74 -73
- package/lib/abstract/{group.d.ts → curve.d.ts} +30 -1
- package/lib/abstract/{group.js → curve.js} +33 -2
- package/lib/abstract/edwards.d.ts +30 -72
- package/lib/abstract/edwards.js +206 -389
- package/lib/abstract/hash-to-curve.d.ts +25 -6
- package/lib/abstract/hash-to-curve.js +40 -12
- package/lib/abstract/modular.d.ts +21 -8
- package/lib/abstract/modular.js +72 -48
- package/lib/abstract/montgomery.js +23 -68
- package/lib/abstract/poseidon.d.ts +29 -0
- package/lib/abstract/poseidon.js +115 -0
- package/lib/abstract/utils.d.ts +9 -37
- package/lib/abstract/utils.js +61 -87
- package/lib/abstract/weierstrass.d.ts +58 -81
- package/lib/abstract/weierstrass.js +485 -679
- package/lib/bls12-381.js +63 -58
- package/lib/bn.js +1 -1
- package/lib/ed25519.d.ts +7 -5
- package/lib/ed25519.js +82 -79
- package/lib/ed448.d.ts +3 -0
- package/lib/ed448.js +86 -83
- package/lib/esm/abstract/bls.js +75 -74
- package/lib/esm/abstract/{group.js → curve.js} +31 -1
- package/lib/esm/abstract/edwards.js +204 -387
- package/lib/esm/abstract/hash-to-curve.js +38 -11
- package/lib/esm/abstract/modular.js +69 -47
- package/lib/esm/abstract/montgomery.js +24 -69
- package/lib/esm/abstract/poseidon.js +109 -0
- package/lib/esm/abstract/utils.js +58 -82
- package/lib/esm/abstract/weierstrass.js +484 -678
- package/lib/esm/bls12-381.js +75 -70
- package/lib/esm/bn.js +1 -1
- package/lib/esm/ed25519.js +80 -78
- package/lib/esm/ed448.js +84 -82
- package/lib/esm/jubjub.js +1 -1
- package/lib/esm/p224.js +1 -1
- package/lib/esm/p256.js +11 -9
- package/lib/esm/p384.js +11 -9
- package/lib/esm/p521.js +12 -23
- package/lib/esm/secp256k1.js +124 -162
- package/lib/esm/stark.js +105 -41
- package/lib/jubjub.d.ts +2 -2
- package/lib/jubjub.js +1 -1
- package/lib/p192.d.ts +26 -48
- package/lib/p224.d.ts +26 -48
- package/lib/p224.js +1 -1
- package/lib/p256.d.ts +29 -48
- package/lib/p256.js +13 -10
- package/lib/p384.d.ts +29 -48
- package/lib/p384.js +13 -10
- package/lib/p521.d.ts +37 -57
- package/lib/p521.js +14 -24
- package/lib/secp256k1.d.ts +37 -46
- package/lib/secp256k1.js +124 -162
- package/lib/stark.d.ts +39 -22
- package/lib/stark.js +108 -41
- package/package.json +15 -10
package/README.md
CHANGED
|
@@ -6,11 +6,12 @@ Minimal, auditable JS implementation of elliptic curve cryptography.
|
|
|
6
6
|
- ECDSA, EdDSA, Schnorr, BLS signature schemes, ECDH key agreement
|
|
7
7
|
- [hash to curve](https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve/)
|
|
8
8
|
for encoding or hashing an arbitrary string to a point on an elliptic curve
|
|
9
|
-
-
|
|
9
|
+
- [Poseidon](https://www.poseidon-hash.info) ZK-friendly hash
|
|
10
|
+
- 🏎 [Ultra-fast](#speed), hand-optimized for caveats of JS engines
|
|
10
11
|
- 🔍 Unique tests ensure correctness. Wycheproof vectors included
|
|
11
12
|
- 🔻 Tree-shaking-friendly: there is no entry point, which ensures small size of your app
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
Package consists of two parts:
|
|
14
15
|
|
|
15
16
|
1. `abstract/` directory specifies zero-dependency EC algorithms
|
|
16
17
|
2. root directory utilizes one dependency `@noble/hashes` and provides ready-to-use:
|
|
@@ -24,7 +25,7 @@ Curves incorporate work from previous noble packages
|
|
|
24
25
|
[ed25519](https://github.com/paulmillr/noble-ed25519),
|
|
25
26
|
[bls12-381](https://github.com/paulmillr/noble-bls12-381)),
|
|
26
27
|
which had security audits and were developed from 2019 to 2022.
|
|
27
|
-
|
|
28
|
+
Check out [Upgrading](#upgrading) section if you've used them before.
|
|
28
29
|
|
|
29
30
|
### This library belongs to _noble_ crypto
|
|
30
31
|
|
|
@@ -88,6 +89,7 @@ To define a custom curve, check out API below.
|
|
|
88
89
|
- [abstract/montgomery: Montgomery curve](#abstractmontgomery-montgomery-curve)
|
|
89
90
|
- [abstract/weierstrass: Short Weierstrass curve](#abstractweierstrass-short-weierstrass-curve)
|
|
90
91
|
- [abstract/hash-to-curve: Hashing strings to curve points](#abstracthash-to-curve-hashing-strings-to-curve-points)
|
|
92
|
+
- [abstract/poseidon: Poseidon hash](#abstractposeidon-poseidon-hash)
|
|
91
93
|
- [abstract/modular](#abstractmodular)
|
|
92
94
|
- [abstract/utils](#abstractutils)
|
|
93
95
|
|
|
@@ -302,13 +304,12 @@ const shared = secp256k1.getSharedSecret(key, someonesPubkey);
|
|
|
302
304
|
export type CurveFn = {
|
|
303
305
|
CURVE: ReturnType<typeof validateOpts>;
|
|
304
306
|
getPublicKey: (privateKey: PrivKey, isCompressed?: boolean) => Uint8Array;
|
|
305
|
-
getSharedSecret: (privateA: PrivKey, publicB:
|
|
307
|
+
getSharedSecret: (privateA: PrivKey, publicB: Hex, isCompressed?: boolean) => Uint8Array;
|
|
306
308
|
sign: (msgHash: Hex, privKey: PrivKey, opts?: SignOpts) => SignatureType;
|
|
307
|
-
signUnhashed: (msg: Uint8Array, privKey: PrivKey, opts?: SignOpts) => SignatureType;
|
|
308
309
|
verify: (
|
|
309
310
|
signature: Hex | SignatureType,
|
|
310
311
|
msgHash: Hex,
|
|
311
|
-
publicKey:
|
|
312
|
+
publicKey: Hex,
|
|
312
313
|
opts?: { lowS?: boolean }
|
|
313
314
|
) => boolean;
|
|
314
315
|
Point: PointConstructor;
|
|
@@ -370,6 +371,30 @@ hashes arbitrary-length byte strings to a list of one or more elements of a fini
|
|
|
370
371
|
};
|
|
371
372
|
```
|
|
372
373
|
|
|
374
|
+
### abstract/poseidon: Poseidon hash
|
|
375
|
+
|
|
376
|
+
Implements [Poseidon](https://www.poseidon-hash.info) ZK-friendly hash.
|
|
377
|
+
|
|
378
|
+
There are many poseidon instances with different constants. We don't provide them,
|
|
379
|
+
but we provide ability to specify them manually. For actual usage, check out
|
|
380
|
+
stark curve source code.
|
|
381
|
+
|
|
382
|
+
```ts
|
|
383
|
+
import { poseidon } from '@noble/curves/abstract/poseidon';
|
|
384
|
+
|
|
385
|
+
type PoseidonOpts = {
|
|
386
|
+
Fp: Field<bigint>;
|
|
387
|
+
t: number;
|
|
388
|
+
roundsFull: number;
|
|
389
|
+
roundsPartial: number;
|
|
390
|
+
sboxPower?: number;
|
|
391
|
+
reversePartialPowIdx?: boolean; // Hack for stark
|
|
392
|
+
mds: bigint[][];
|
|
393
|
+
roundConstants: bigint[][];
|
|
394
|
+
};
|
|
395
|
+
const instance = poseidon(opts: PoseidonOpts);
|
|
396
|
+
```
|
|
397
|
+
|
|
373
398
|
### abstract/modular
|
|
374
399
|
|
|
375
400
|
Modular arithmetics utilities.
|
|
@@ -420,45 +445,94 @@ We consider infrastructure attacks like rogue NPM modules very important; that's
|
|
|
420
445
|
Benchmark results on Apple M2 with node v18.10:
|
|
421
446
|
|
|
422
447
|
```
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
sign
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
verify
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
448
|
+
secp256k1
|
|
449
|
+
init x 57 ops/sec @ 17ms/op
|
|
450
|
+
getPublicKey x 4,946 ops/sec @ 202μs/op
|
|
451
|
+
sign x 3,914 ops/sec @ 255μs/op
|
|
452
|
+
verify x 682 ops/sec @ 1ms/op
|
|
453
|
+
getSharedSecret x 427 ops/sec @ 2ms/op
|
|
454
|
+
recoverPublicKey x 683 ops/sec @ 1ms/op
|
|
455
|
+
schnorr.sign x 539 ops/sec @ 1ms/op
|
|
456
|
+
schnorr.verify x 716 ops/sec @ 1ms/op
|
|
457
|
+
|
|
458
|
+
P256
|
|
459
|
+
init x 30 ops/sec @ 32ms/op
|
|
460
|
+
getPublicKey x 5,008 ops/sec @ 199μs/op
|
|
461
|
+
sign x 3,970 ops/sec @ 251μs/op
|
|
462
|
+
verify x 515 ops/sec @ 1ms/op
|
|
463
|
+
|
|
464
|
+
P384
|
|
465
|
+
init x 14 ops/sec @ 66ms/op
|
|
466
|
+
getPublicKey x 2,434 ops/sec @ 410μs/op
|
|
467
|
+
sign x 1,942 ops/sec @ 514μs/op
|
|
468
|
+
verify x 206 ops/sec @ 4ms/op
|
|
469
|
+
|
|
470
|
+
P521
|
|
471
|
+
init x 7 ops/sec @ 126ms/op
|
|
472
|
+
getPublicKey x 1,282 ops/sec @ 779μs/op
|
|
473
|
+
sign x 1,077 ops/sec @ 928μs/op
|
|
474
|
+
verify x 110 ops/sec @ 9ms/op
|
|
475
|
+
|
|
476
|
+
ed25519
|
|
477
|
+
init x 37 ops/sec @ 26ms/op
|
|
478
|
+
getPublicKey x 8,147 ops/sec @ 122μs/op
|
|
479
|
+
sign x 3,979 ops/sec @ 251μs/op
|
|
480
|
+
verify x 848 ops/sec @ 1ms/op
|
|
481
|
+
|
|
482
|
+
ed448
|
|
483
|
+
init x 17 ops/sec @ 58ms/op
|
|
484
|
+
getPublicKey x 3,083 ops/sec @ 324μs/op
|
|
485
|
+
sign x 1,473 ops/sec @ 678μs/op
|
|
486
|
+
verify x 323 ops/sec @ 3ms/op
|
|
487
|
+
|
|
488
|
+
bls12-381
|
|
489
|
+
init x 30 ops/sec @ 33ms/op
|
|
490
|
+
getPublicKey x 788 ops/sec @ 1ms/op
|
|
491
|
+
sign x 45 ops/sec @ 21ms/op
|
|
492
|
+
verify x 32 ops/sec @ 30ms/op
|
|
493
|
+
pairing x 88 ops/sec @ 11ms/op
|
|
494
|
+
|
|
495
|
+
stark
|
|
496
|
+
init x 31 ops/sec @ 31ms/op
|
|
454
497
|
pedersen
|
|
455
|
-
|
|
456
|
-
|
|
498
|
+
├─old x 84 ops/sec @ 11ms/op
|
|
499
|
+
└─noble x 802 ops/sec @ 1ms/op
|
|
500
|
+
poseidon x 7,466 ops/sec @ 133μs/op
|
|
457
501
|
verify
|
|
458
|
-
|
|
459
|
-
|
|
502
|
+
├─old x 300 ops/sec @ 3ms/op
|
|
503
|
+
└─noble x 474 ops/sec @ 2ms/op
|
|
460
504
|
```
|
|
461
505
|
|
|
506
|
+
## Upgrading
|
|
507
|
+
|
|
508
|
+
If you're coming from single-curve noble packages, the following changes need to be kept in mind:
|
|
509
|
+
|
|
510
|
+
- 2d affine (x, y) points have been removed to reduce complexity and improve speed
|
|
511
|
+
- Removed `number` support as a type for private keys. `bigint` is still supported
|
|
512
|
+
- `mod`, `invert` are no longer present in `utils`. Use `@noble/curves/abstract/modular.js` now.
|
|
513
|
+
|
|
514
|
+
Upgrading from @noble/secp256k1 1.7:
|
|
515
|
+
|
|
516
|
+
- Compressed (33-byte) public keys are now returned by default, instead of uncompressed
|
|
517
|
+
- Methods are now synchronous. Setting `secp.utils.hmacSha256` is no longer required
|
|
518
|
+
- `sign()`
|
|
519
|
+
- `der`, `recovered` options were removed
|
|
520
|
+
- `canonical` was renamed to `lowS`
|
|
521
|
+
- Return type is now `{ r: bigint, s: bigint, recovery: number }` instance of `Signature`
|
|
522
|
+
- `verify()`
|
|
523
|
+
- `strict` was renamed to `lowS`
|
|
524
|
+
- `recoverPublicKey()`: moved to sig instance `Signature#recoverPublicKey(msgHash)`
|
|
525
|
+
- `Point` was removed: use `ProjectivePoint` in xyz coordinates
|
|
526
|
+
- `utils`: Many methods were removed, others were moved to `schnorr` namespace
|
|
527
|
+
|
|
528
|
+
Upgrading from @noble/ed25519 1.7:
|
|
529
|
+
|
|
530
|
+
- Methods are now synchronous. Setting `secp.utils.hmacSha256` is no longer required
|
|
531
|
+
- ed25519ph, ed25519ctx
|
|
532
|
+
- `Point` was removed: use `ExtendedPoint` in xyzt coordinates
|
|
533
|
+
- `Signature` was removed
|
|
534
|
+
- `getSharedSecret` was removed: use separate x25519 sub-module
|
|
535
|
+
|
|
462
536
|
## Contributing & testing
|
|
463
537
|
|
|
464
538
|
1. Clone the repository
|
package/lib/_shortw_utils.d.ts
CHANGED
|
@@ -18,11 +18,11 @@ export declare function createCurve(curveDef: CurveDef, defHash: CHash): Readonl
|
|
|
18
18
|
readonly hEff?: bigint | undefined;
|
|
19
19
|
readonly Gx: bigint;
|
|
20
20
|
readonly Gy: bigint;
|
|
21
|
-
readonly wrapPrivateKey?: boolean | undefined;
|
|
22
21
|
readonly allowInfinityPoint?: boolean | undefined;
|
|
23
22
|
readonly a: bigint;
|
|
24
23
|
readonly b: bigint;
|
|
25
|
-
readonly
|
|
24
|
+
readonly allowedPrivateKeyLengths?: readonly number[] | undefined;
|
|
25
|
+
readonly wrapPrivateKey?: boolean | undefined;
|
|
26
26
|
readonly endo?: {
|
|
27
27
|
beta: bigint;
|
|
28
28
|
splitScalar: (k: bigint) => {
|
|
@@ -32,37 +32,26 @@ export declare function createCurve(curveDef: CurveDef, defHash: CHash): Readonl
|
|
|
32
32
|
k2: bigint;
|
|
33
33
|
};
|
|
34
34
|
} | undefined;
|
|
35
|
-
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").
|
|
36
|
-
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").
|
|
37
|
-
readonly htfDefaults?: import("./abstract/hash-to-curve.js").htfOpts | undefined;
|
|
38
|
-
readonly mapToCurve?: ((scalar: bigint[]) => {
|
|
39
|
-
x: bigint;
|
|
40
|
-
y: bigint;
|
|
41
|
-
}) | undefined;
|
|
42
|
-
lowS: boolean;
|
|
35
|
+
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjPointType<bigint>) => boolean) | undefined;
|
|
36
|
+
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjPointType<bigint>) => import("./abstract/weierstrass.js").ProjPointType<bigint>) | undefined;
|
|
43
37
|
readonly hash: CHash;
|
|
44
38
|
readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
|
|
45
39
|
readonly randomBytes: (bytesLength?: number | undefined) => Uint8Array;
|
|
46
|
-
|
|
40
|
+
lowS: boolean;
|
|
41
|
+
readonly bits2int?: ((bytes: Uint8Array) => bigint) | undefined;
|
|
42
|
+
readonly bits2int_modN?: ((bytes: Uint8Array) => bigint) | undefined;
|
|
47
43
|
}>;
|
|
48
44
|
getPublicKey: (privateKey: import("./abstract/utils.js").PrivKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
49
|
-
getSharedSecret: (privateA: import("./abstract/utils.js").PrivKey, publicB: import("./abstract/
|
|
45
|
+
getSharedSecret: (privateA: import("./abstract/utils.js").PrivKey, publicB: import("./abstract/utils.js").Hex, isCompressed?: boolean | undefined) => Uint8Array;
|
|
50
46
|
sign: (msgHash: import("./abstract/utils.js").Hex, privKey: import("./abstract/utils.js").PrivKey, opts?: import("./abstract/weierstrass.js").SignOpts | undefined) => import("./abstract/weierstrass.js").SignatureType;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} | undefined) => boolean;
|
|
55
|
-
|
|
56
|
-
ProjectivePoint: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>;
|
|
47
|
+
verify: (signature: import("./abstract/utils.js").Hex | {
|
|
48
|
+
r: bigint;
|
|
49
|
+
s: bigint;
|
|
50
|
+
}, msgHash: import("./abstract/utils.js").Hex, publicKey: import("./abstract/utils.js").Hex, opts?: import("./abstract/weierstrass.js").VerOpts | undefined) => boolean;
|
|
51
|
+
ProjectivePoint: import("./abstract/weierstrass.js").ProjConstructor<bigint>;
|
|
57
52
|
Signature: import("./abstract/weierstrass.js").SignatureConstructor;
|
|
58
53
|
utils: {
|
|
59
|
-
_bigintToBytes: (num: bigint) => Uint8Array;
|
|
60
|
-
_bigintToString: (num: bigint) => string;
|
|
61
54
|
_normalizePrivateKey: (key: import("./abstract/utils.js").PrivKey) => bigint;
|
|
62
|
-
_normalizePublicKey: (publicKey: import("./abstract/weierstrass.js").PubKey) => import("./abstract/weierstrass.js").PointType<bigint>;
|
|
63
|
-
_isWithinCurveOrder: (num: bigint) => boolean;
|
|
64
|
-
_isValidFieldElement: (num: bigint) => boolean;
|
|
65
|
-
_weierstrassEquation: (x: bigint) => bigint;
|
|
66
55
|
isValidPrivateKey(privateKey: import("./abstract/utils.js").PrivKey): boolean;
|
|
67
56
|
hashToPrivateKey: (hash: import("./abstract/utils.js").Hex) => Uint8Array;
|
|
68
57
|
randomPrivateKey: () => Uint8Array;
|
package/lib/abstract/bls.d.ts
CHANGED
|
@@ -11,26 +11,31 @@
|
|
|
11
11
|
* We are using Fp for private keys (shorter) and Fp₂ for signatures (longer).
|
|
12
12
|
* Some projects may prefer to swap this relation, it is not supported for now.
|
|
13
13
|
*/
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import { Hex, PrivKey } from './utils.js';
|
|
17
|
-
import
|
|
18
|
-
import { CurvePointsType,
|
|
14
|
+
import { AffinePoint } from './curve.js';
|
|
15
|
+
import { Field } from './modular.js';
|
|
16
|
+
import { Hex, PrivKey, CHash } from './utils.js';
|
|
17
|
+
import * as htf from './hash-to-curve.js';
|
|
18
|
+
import { CurvePointsType, ProjPointType as ProjPointType, CurvePointsRes } from './weierstrass.js';
|
|
19
19
|
declare type Fp = bigint;
|
|
20
20
|
export declare type SignatureCoder<Fp2> = {
|
|
21
|
-
decode(hex: Hex):
|
|
22
|
-
encode(point:
|
|
21
|
+
decode(hex: Hex): ProjPointType<Fp2>;
|
|
22
|
+
encode(point: ProjPointType<Fp2>): Uint8Array;
|
|
23
23
|
};
|
|
24
24
|
export declare type CurveType<Fp, Fp2, Fp6, Fp12> = {
|
|
25
25
|
r: bigint;
|
|
26
|
-
G1: Omit<CurvePointsType<Fp>, 'n'
|
|
26
|
+
G1: Omit<CurvePointsType<Fp>, 'n'> & {
|
|
27
|
+
mapToCurve: htf.MapToCurve<Fp>;
|
|
28
|
+
htfDefaults: htf.Opts;
|
|
29
|
+
};
|
|
27
30
|
G2: Omit<CurvePointsType<Fp2>, 'n'> & {
|
|
28
31
|
Signature: SignatureCoder<Fp2>;
|
|
32
|
+
mapToCurve: htf.MapToCurve<Fp2>;
|
|
33
|
+
htfDefaults: htf.Opts;
|
|
29
34
|
};
|
|
30
35
|
x: bigint;
|
|
31
|
-
Fp:
|
|
32
|
-
Fr:
|
|
33
|
-
Fp2:
|
|
36
|
+
Fp: Field<Fp>;
|
|
37
|
+
Fr: Field<bigint>;
|
|
38
|
+
Fp2: Field<Fp2> & {
|
|
34
39
|
reim: (num: Fp2) => {
|
|
35
40
|
re: bigint;
|
|
36
41
|
im: bigint;
|
|
@@ -38,51 +43,53 @@ export declare type CurveType<Fp, Fp2, Fp6, Fp12> = {
|
|
|
38
43
|
multiplyByB: (num: Fp2) => Fp2;
|
|
39
44
|
frobeniusMap(num: Fp2, power: number): Fp2;
|
|
40
45
|
};
|
|
41
|
-
Fp6:
|
|
42
|
-
Fp12:
|
|
46
|
+
Fp6: Field<Fp6>;
|
|
47
|
+
Fp12: Field<Fp12> & {
|
|
43
48
|
frobeniusMap(num: Fp12, power: number): Fp12;
|
|
44
49
|
multiplyBy014(num: Fp12, o0: Fp2, o1: Fp2, o4: Fp2): Fp12;
|
|
45
50
|
conjugate(num: Fp12): Fp12;
|
|
46
51
|
finalExponentiate(num: Fp12): Fp12;
|
|
47
52
|
};
|
|
48
|
-
htfDefaults:
|
|
49
|
-
hash:
|
|
53
|
+
htfDefaults: htf.Opts;
|
|
54
|
+
hash: CHash;
|
|
50
55
|
randomBytes: (bytesLength?: number) => Uint8Array;
|
|
51
56
|
};
|
|
52
57
|
export declare type CurveFn<Fp, Fp2, Fp6, Fp12> = {
|
|
53
58
|
CURVE: CurveType<Fp, Fp2, Fp6, Fp12>;
|
|
54
|
-
Fr:
|
|
55
|
-
Fp:
|
|
56
|
-
Fp2:
|
|
57
|
-
Fp6:
|
|
58
|
-
Fp12:
|
|
59
|
+
Fr: Field<bigint>;
|
|
60
|
+
Fp: Field<Fp>;
|
|
61
|
+
Fp2: Field<Fp2>;
|
|
62
|
+
Fp6: Field<Fp6>;
|
|
63
|
+
Fp12: Field<Fp12>;
|
|
59
64
|
G1: CurvePointsRes<Fp>;
|
|
60
65
|
G2: CurvePointsRes<Fp2>;
|
|
61
66
|
Signature: SignatureCoder<Fp2>;
|
|
62
67
|
millerLoop: (ell: [Fp2, Fp2, Fp2][], g1: [Fp, Fp]) => Fp12;
|
|
63
|
-
calcPairingPrecomputes: (
|
|
64
|
-
|
|
68
|
+
calcPairingPrecomputes: (p: AffinePoint<Fp2>) => [Fp2, Fp2, Fp2][];
|
|
69
|
+
hashToCurve: {
|
|
70
|
+
G1: ReturnType<(typeof htf.hashToCurve<Fp>)>;
|
|
71
|
+
G2: ReturnType<(typeof htf.hashToCurve<Fp2>)>;
|
|
72
|
+
};
|
|
73
|
+
pairing: (P: ProjPointType<Fp>, Q: ProjPointType<Fp2>, withFinalExponent?: boolean) => Fp12;
|
|
65
74
|
getPublicKey: (privateKey: PrivKey) => Uint8Array;
|
|
66
75
|
sign: {
|
|
67
76
|
(message: Hex, privateKey: PrivKey): Uint8Array;
|
|
68
|
-
(message:
|
|
77
|
+
(message: ProjPointType<Fp2>, privateKey: PrivKey): ProjPointType<Fp2>;
|
|
69
78
|
};
|
|
70
|
-
verify: (signature: Hex |
|
|
79
|
+
verify: (signature: Hex | ProjPointType<Fp2>, message: Hex | ProjPointType<Fp2>, publicKey: Hex | ProjPointType<Fp>) => boolean;
|
|
71
80
|
aggregatePublicKeys: {
|
|
72
81
|
(publicKeys: Hex[]): Uint8Array;
|
|
73
|
-
(publicKeys:
|
|
82
|
+
(publicKeys: ProjPointType<Fp>[]): ProjPointType<Fp>;
|
|
74
83
|
};
|
|
75
84
|
aggregateSignatures: {
|
|
76
85
|
(signatures: Hex[]): Uint8Array;
|
|
77
|
-
(signatures:
|
|
86
|
+
(signatures: ProjPointType<Fp2>[]): ProjPointType<Fp2>;
|
|
78
87
|
};
|
|
79
|
-
verifyBatch: (signature: Hex |
|
|
88
|
+
verifyBatch: (signature: Hex | ProjPointType<Fp2>, messages: (Hex | ProjPointType<Fp2>)[], publicKeys: (Hex | ProjPointType<Fp>)[]) => boolean;
|
|
80
89
|
utils: {
|
|
81
|
-
stringToBytes: typeof stringToBytes;
|
|
82
|
-
hashToField: typeof
|
|
83
|
-
expandMessageXMD: typeof
|
|
84
|
-
getDSTLabel: () => string;
|
|
85
|
-
setDSTLabel(newLabel: string): void;
|
|
90
|
+
stringToBytes: typeof htf.stringToBytes;
|
|
91
|
+
hashToField: typeof htf.hash_to_field;
|
|
92
|
+
expandMessageXMD: typeof htf.expand_message_xmd;
|
|
86
93
|
};
|
|
87
94
|
};
|
|
88
95
|
export declare function bls<Fp2, Fp6, Fp12>(CURVE: CurveType<Fp, Fp2, Fp6, Fp12>): CurveFn<Fp, Fp2, Fp6, Fp12>;
|