@noble/curves 0.9.1 → 1.0.0
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 +197 -99
- package/abstract/bls.d.ts +43 -31
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +37 -28
- package/abstract/bls.js.map +1 -1
- package/abstract/edwards.d.ts +2 -2
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +30 -18
- package/abstract/edwards.js.map +1 -1
- package/abstract/hash-to-curve.d.ts +1 -1
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +3 -2
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/utils.d.ts.map +1 -1
- package/abstract/utils.js +2 -2
- package/abstract/utils.js.map +1 -1
- package/abstract/weierstrass.d.ts +21 -0
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +27 -14
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +57 -61
- package/bls12-381.js.map +1 -1
- package/{bn.d.ts → bn254.d.ts} +1 -1
- package/bn254.d.ts.map +1 -0
- package/{bn.js → bn254.js} +1 -1
- package/bn254.js.map +1 -0
- package/ed25519.d.ts +9 -0
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +22 -8
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +9 -0
- package/ed448.d.ts.map +1 -1
- package/ed448.js +16 -16
- package/ed448.js.map +1 -1
- package/esm/abstract/bls.js +37 -28
- package/esm/abstract/bls.js.map +1 -1
- package/esm/abstract/edwards.js +30 -18
- package/esm/abstract/edwards.js.map +1 -1
- package/esm/abstract/hash-to-curve.js +3 -2
- package/esm/abstract/hash-to-curve.js.map +1 -1
- package/esm/abstract/utils.js +2 -2
- package/esm/abstract/utils.js.map +1 -1
- package/esm/abstract/weierstrass.js +19 -6
- package/esm/abstract/weierstrass.js.map +1 -1
- package/esm/bls12-381.js +58 -62
- package/esm/bls12-381.js.map +1 -1
- package/esm/{bn.js → bn254.js} +1 -1
- package/esm/bn254.js.map +1 -0
- package/esm/ed25519.js +20 -7
- package/esm/ed25519.js.map +1 -1
- package/esm/ed448.js +14 -15
- package/esm/ed448.js.map +1 -1
- package/esm/p256.js +5 -6
- package/esm/p256.js.map +1 -1
- package/esm/p384.js +10 -12
- package/esm/p384.js.map +1 -1
- package/esm/p521.js +22 -18
- package/esm/p521.js.map +1 -1
- package/p256.d.ts +1 -1
- package/p256.d.ts.map +1 -1
- package/p256.js +6 -7
- package/p256.js.map +1 -1
- package/p384.d.ts +1 -1
- package/p384.d.ts.map +1 -1
- package/p384.js +11 -13
- package/p384.js.map +1 -1
- package/p521.d.ts +1 -1
- package/p521.d.ts.map +1 -1
- package/p521.js +23 -19
- package/p521.js.map +1 -1
- package/package.json +5 -8
- package/src/abstract/bls.ts +83 -61
- package/src/abstract/edwards.ts +38 -16
- package/src/abstract/hash-to-curve.ts +4 -3
- package/src/abstract/utils.ts +2 -2
- package/src/abstract/weierstrass.ts +18 -7
- package/src/bls12-381.ts +63 -67
- package/src/ed25519.ts +22 -8
- package/src/ed448.ts +15 -15
- package/src/p256.ts +15 -19
- package/src/p384.ts +17 -21
- package/src/p521.ts +34 -22
- package/bn.d.ts.map +0 -1
- package/bn.js.map +0 -1
- package/esm/bn.js.map +0 -1
- /package/src/{bn.ts → bn254.ts} +0 -0
package/esm/p521.js
CHANGED
|
@@ -4,37 +4,41 @@ import { sha512 } from '@noble/hashes/sha512';
|
|
|
4
4
|
import { Field } from './abstract/modular.js';
|
|
5
5
|
import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
|
|
6
6
|
import * as htf from './abstract/hash-to-curve.js';
|
|
7
|
-
// NIST secp521r1 aka
|
|
7
|
+
// NIST secp521r1 aka p521
|
|
8
8
|
// Note that it's 521, which differs from 512 of its hash function.
|
|
9
9
|
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-521
|
|
10
|
-
// Field over which we'll do calculations
|
|
10
|
+
// Field over which we'll do calculations.
|
|
11
11
|
// prettier-ignore
|
|
12
12
|
const P = BigInt('0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
13
13
|
const Fp = Field(P);
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const mapSWU = mapToCurveSimpleSWU(Fp, {
|
|
18
|
-
A: CURVE_A,
|
|
19
|
-
B: CURVE_B,
|
|
20
|
-
Z: Fp.create(BigInt('-4')),
|
|
21
|
-
});
|
|
22
|
-
// prettier-ignore
|
|
23
|
-
export const P521 = createCurve({
|
|
24
|
-
// Params: a, b
|
|
25
|
-
a: CURVE_A,
|
|
26
|
-
b: CURVE_B,
|
|
14
|
+
const CURVE = {
|
|
15
|
+
a: Fp.create(BigInt('-3')),
|
|
16
|
+
b: BigInt('0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00'),
|
|
27
17
|
Fp,
|
|
28
|
-
// Curve order, total count of valid points in the field
|
|
29
18
|
n: BigInt('0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409'),
|
|
30
|
-
// Base point (x, y) aka generator point
|
|
31
19
|
Gx: BigInt('0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66'),
|
|
32
20
|
Gy: BigInt('0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650'),
|
|
33
21
|
h: BigInt(1),
|
|
22
|
+
};
|
|
23
|
+
// prettier-ignore
|
|
24
|
+
export const p521 = createCurve({
|
|
25
|
+
a: CURVE.a,
|
|
26
|
+
b: CURVE.b,
|
|
27
|
+
Fp,
|
|
28
|
+
// Curve order, total count of valid points in the field
|
|
29
|
+
n: CURVE.n,
|
|
30
|
+
Gx: CURVE.Gx,
|
|
31
|
+
Gy: CURVE.Gy,
|
|
32
|
+
h: CURVE.h,
|
|
34
33
|
lowS: false,
|
|
35
34
|
allowedPrivateKeyLengths: [130, 131, 132] // P521 keys are variable-length. Normalize to 132b
|
|
36
35
|
}, sha512);
|
|
37
|
-
export const secp521r1 =
|
|
36
|
+
export const secp521r1 = p521;
|
|
37
|
+
const mapSWU = mapToCurveSimpleSWU(Fp, {
|
|
38
|
+
A: CURVE.a,
|
|
39
|
+
B: CURVE.b,
|
|
40
|
+
Z: Fp.create(BigInt('-4')),
|
|
41
|
+
});
|
|
38
42
|
const { hashToCurve, encodeToCurve } = htf.createHasher(secp521r1.ProjectivePoint, (scalars) => mapSWU(scalars[0]), {
|
|
39
43
|
DST: 'P521_XMD:SHA-512_SSWU_RO_',
|
|
40
44
|
encodeDST: 'P521_XMD:SHA-512_SSWU_NU_',
|
package/esm/p521.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p521.js","sourceRoot":"","sources":["../src/p521.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,GAAG,MAAM,6BAA6B,CAAC;AAEnD,0BAA0B;AAC1B,mEAAmE;AACnE,0EAA0E;AAE1E,
|
|
1
|
+
{"version":3,"file":"p521.js","sourceRoot":"","sources":["../src/p521.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,EAAE,WAAW,EAAE,M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MAAM,GAAG,mBAAmB,CAAC,EAAE,EAAE;IACrC,CAAC,EAAE,KAAK,CAAC,CAAC;IACV,CAAC,EAAE,KAAK,CAAC,CAAC;IACV,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CAC3B,CAAC,CAAC;AAEH,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,GAAG,CAAC,YAAY,CACrD,SAAS,CAAC,eAAe,EACzB,CAAC,OAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EACzC;IACE,GAAG,EAAE,2BAA2B;IAChC,SAAS,EAAE,2BAA2B;IACtC,CAAC,EAAE,EAAE,CAAC,KAAK;IACX,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,GAAG;IACN,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,MAAM;CACb,CACF,CAAC;AACF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC"}
|
package/p256.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as htf from './abstract/hash-to-curve.js';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const p256: Readonly<{
|
|
3
3
|
create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
|
|
4
4
|
CURVE: Readonly<{
|
|
5
5
|
readonly nBitLength: number;
|
package/p256.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p256.d.ts","sourceRoot":"","sources":["src/p256.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,GAAG,MAAM,6BAA6B,CAAC;AAgBnD,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"p256.d.ts","sourceRoot":"","sources":["src/p256.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,GAAG,MAAM,6BAA6B,CAAC;AAgBnD,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWE,CAAC;AACpB,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAO,CAAC;AAE9B,QAAA,MAAQ,WAAW,qFAAE,aAAa,mFAYjC,CAAC;AACF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC"}
|
package/p256.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeToCurve = exports.hashToCurve = exports.secp256r1 = exports.
|
|
3
|
+
exports.encodeToCurve = exports.hashToCurve = exports.secp256r1 = exports.p256 = void 0;
|
|
4
4
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
5
|
const _shortw_utils_js_1 = require("./_shortw_utils.js");
|
|
6
6
|
const sha256_1 = require("@noble/hashes/sha256");
|
|
7
7
|
const modular_js_1 = require("./abstract/modular.js");
|
|
8
8
|
const weierstrass_js_1 = require("./abstract/weierstrass.js");
|
|
9
9
|
const htf = require("./abstract/hash-to-curve.js");
|
|
10
|
-
// NIST secp256r1 aka
|
|
10
|
+
// NIST secp256r1 aka p256
|
|
11
11
|
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-256
|
|
12
|
-
// Field over which we'll do calculations; 2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n-1n
|
|
13
12
|
const Fp = (0, modular_js_1.Field)(BigInt('0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff'));
|
|
14
13
|
const CURVE_A = Fp.create(BigInt('-3'));
|
|
15
14
|
const CURVE_B = BigInt('0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b');
|
|
@@ -18,20 +17,20 @@ const mapSWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
|
|
|
18
17
|
B: CURVE_B,
|
|
19
18
|
Z: Fp.create(BigInt('-10')),
|
|
20
19
|
});
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// prettier-ignore
|
|
21
|
+
exports.p256 = (0, _shortw_utils_js_1.createCurve)({
|
|
23
22
|
a: CURVE_A,
|
|
24
23
|
b: CURVE_B,
|
|
25
24
|
Fp,
|
|
26
25
|
// Curve order, total count of valid points in the field
|
|
27
26
|
n: BigInt('0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551'),
|
|
28
|
-
// Base point (x, y)
|
|
27
|
+
// Base (generator) point (x, y)
|
|
29
28
|
Gx: BigInt('0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296'),
|
|
30
29
|
Gy: BigInt('0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5'),
|
|
31
30
|
h: BigInt(1),
|
|
32
31
|
lowS: false,
|
|
33
32
|
}, sha256_1.sha256);
|
|
34
|
-
exports.secp256r1 = exports.
|
|
33
|
+
exports.secp256r1 = exports.p256;
|
|
35
34
|
const { hashToCurve, encodeToCurve } = htf.createHasher(exports.secp256r1.ProjectivePoint, (scalars) => mapSWU(scalars[0]), {
|
|
36
35
|
DST: 'P256_XMD:SHA-256_SSWU_RO_',
|
|
37
36
|
encodeDST: 'P256_XMD:SHA-256_SSWU_NU_',
|
package/p256.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p256.js","sourceRoot":"","sources":["src/p256.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACtE,yDAAiD;AACjD,iDAA8C;AAC9C,sDAA8C;AAC9C,8DAAgE;AAChE,mDAAmD;AAEnD,0BAA0B;AAC1B,0EAA0E;AAE1E,
|
|
1
|
+
{"version":3,"file":"p256.js","sourceRoot":"","sources":["src/p256.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACtE,y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,GAAG;IACN,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,eAAM;CACb,CACF,CAAC;AACO,kCAAW;AAAE,sCAAa"}
|
package/p384.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as htf from './abstract/hash-to-curve.js';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const p384: Readonly<{
|
|
3
3
|
create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
|
|
4
4
|
CURVE: Readonly<{
|
|
5
5
|
readonly nBitLength: number;
|
package/p384.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p384.d.ts","sourceRoot":"","sources":["src/p384.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,GAAG,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"p384.d.ts","sourceRoot":"","sources":["src/p384.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,GAAG,MAAM,6BAA6B,CAAC;AAcnD,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWE,CAAC;AACpB,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAO,CAAC;AAQ9B,QAAA,MAAQ,WAAW,qFAAE,aAAa,mFAYjC,CAAC;AACF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC"}
|
package/p384.js
CHANGED
|
@@ -1,42 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeToCurve = exports.hashToCurve = exports.secp384r1 = exports.
|
|
3
|
+
exports.encodeToCurve = exports.hashToCurve = exports.secp384r1 = exports.p384 = void 0;
|
|
4
4
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
5
|
const _shortw_utils_js_1 = require("./_shortw_utils.js");
|
|
6
6
|
const sha512_1 = require("@noble/hashes/sha512");
|
|
7
7
|
const modular_js_1 = require("./abstract/modular.js");
|
|
8
8
|
const weierstrass_js_1 = require("./abstract/weierstrass.js");
|
|
9
9
|
const htf = require("./abstract/hash-to-curve.js");
|
|
10
|
-
// NIST secp384r1 aka
|
|
10
|
+
// NIST secp384r1 aka p384
|
|
11
11
|
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-384
|
|
12
|
-
// Field over which we'll do calculations.
|
|
12
|
+
// Field over which we'll do calculations.
|
|
13
13
|
// prettier-ignore
|
|
14
14
|
const P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff');
|
|
15
15
|
const Fp = (0, modular_js_1.Field)(P);
|
|
16
16
|
const CURVE_A = Fp.create(BigInt('-3'));
|
|
17
17
|
// prettier-ignore
|
|
18
18
|
const CURVE_B = BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef');
|
|
19
|
-
const mapSWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
|
|
20
|
-
A: CURVE_A,
|
|
21
|
-
B: CURVE_B,
|
|
22
|
-
Z: Fp.create(BigInt('-12')),
|
|
23
|
-
});
|
|
24
19
|
// prettier-ignore
|
|
25
|
-
exports.
|
|
26
|
-
// Params: a, b
|
|
20
|
+
exports.p384 = (0, _shortw_utils_js_1.createCurve)({
|
|
27
21
|
a: CURVE_A,
|
|
28
22
|
b: CURVE_B,
|
|
29
|
-
// Field over which we'll do calculations. 2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n
|
|
30
23
|
Fp,
|
|
31
24
|
// Curve order, total count of valid points in the field.
|
|
32
25
|
n: BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973'),
|
|
33
|
-
// Base point (x, y)
|
|
26
|
+
// Base (generator) point (x, y)
|
|
34
27
|
Gx: BigInt('0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7'),
|
|
35
28
|
Gy: BigInt('0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f'),
|
|
36
29
|
h: BigInt(1),
|
|
37
30
|
lowS: false,
|
|
38
31
|
}, sha512_1.sha384);
|
|
39
|
-
exports.secp384r1 = exports.
|
|
32
|
+
exports.secp384r1 = exports.p384;
|
|
33
|
+
const mapSWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
|
|
34
|
+
A: CURVE_A,
|
|
35
|
+
B: CURVE_B,
|
|
36
|
+
Z: Fp.create(BigInt('-12')),
|
|
37
|
+
});
|
|
40
38
|
const { hashToCurve, encodeToCurve } = htf.createHasher(exports.secp384r1.ProjectivePoint, (scalars) => mapSWU(scalars[0]), {
|
|
41
39
|
DST: 'P384_XMD:SHA-384_SSWU_RO_',
|
|
42
40
|
encodeDST: 'P384_XMD:SHA-384_SSWU_NU_',
|
package/p384.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p384.js","sourceRoot":"","sources":["src/p384.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACtE,yDAAiD;AACjD,iDAA8C;AAC9C,sDAA8C;AAC9C,8DAAgE;AAChE,mDAAmD;AAEnD,0BAA0B;AAC1B,0EAA0E;AAE1E,
|
|
1
|
+
{"version":3,"file":"p384.js","sourceRoot":"","sources":["src/p384.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACtE,yDAAiD;AACjD,iDAA8C;AAC9C,sDAA8C;AAC9C,8DAAgE;AAChE,mDAAmD;AAEnD,0BAA0B;AAC1B,0EAA0E;AAE1E,0CAA0C;AAC1C,kBAAkB;AAClB,MAAM,CAAC,GAAG,MAAM,CAAC,oGAAoG,CAAC,CAAC;AACvH,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ANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as htf from './abstract/hash-to-curve.js';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const p521: Readonly<{
|
|
3
3
|
create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
|
|
4
4
|
CURVE: Readonly<{
|
|
5
5
|
readonly nBitLength: number;
|
package/p521.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p521.d.ts","sourceRoot":"","sources":["src/p521.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,GAAG,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"p521.d.ts","sourceRoot":"","sources":["src/p521.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,GAAG,MAAM,6BAA6B,CAAC;AA8BnD,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWE,CAAC;AACpB,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAO,CAAC;AAQ9B,QAAA,MAAQ,WAAW,qFAAE,aAAa,mFAYjC,CAAC;AACF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC"}
|
package/p521.js
CHANGED
|
@@ -1,43 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeToCurve = exports.hashToCurve = exports.secp521r1 = exports.
|
|
3
|
+
exports.encodeToCurve = exports.hashToCurve = exports.secp521r1 = exports.p521 = void 0;
|
|
4
4
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
5
|
const _shortw_utils_js_1 = require("./_shortw_utils.js");
|
|
6
6
|
const sha512_1 = require("@noble/hashes/sha512");
|
|
7
7
|
const modular_js_1 = require("./abstract/modular.js");
|
|
8
8
|
const weierstrass_js_1 = require("./abstract/weierstrass.js");
|
|
9
9
|
const htf = require("./abstract/hash-to-curve.js");
|
|
10
|
-
// NIST secp521r1 aka
|
|
10
|
+
// NIST secp521r1 aka p521
|
|
11
11
|
// Note that it's 521, which differs from 512 of its hash function.
|
|
12
12
|
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-521
|
|
13
|
-
// Field over which we'll do calculations
|
|
13
|
+
// Field over which we'll do calculations.
|
|
14
14
|
// prettier-ignore
|
|
15
15
|
const P = BigInt('0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
16
16
|
const Fp = (0, modular_js_1.Field)(P);
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const mapSWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
|
|
21
|
-
A: CURVE_A,
|
|
22
|
-
B: CURVE_B,
|
|
23
|
-
Z: Fp.create(BigInt('-4')),
|
|
24
|
-
});
|
|
25
|
-
// prettier-ignore
|
|
26
|
-
exports.P521 = (0, _shortw_utils_js_1.createCurve)({
|
|
27
|
-
// Params: a, b
|
|
28
|
-
a: CURVE_A,
|
|
29
|
-
b: CURVE_B,
|
|
17
|
+
const CURVE = {
|
|
18
|
+
a: Fp.create(BigInt('-3')),
|
|
19
|
+
b: BigInt('0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00'),
|
|
30
20
|
Fp,
|
|
31
|
-
// Curve order, total count of valid points in the field
|
|
32
21
|
n: BigInt('0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409'),
|
|
33
|
-
// Base point (x, y) aka generator point
|
|
34
22
|
Gx: BigInt('0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66'),
|
|
35
23
|
Gy: BigInt('0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650'),
|
|
36
24
|
h: BigInt(1),
|
|
25
|
+
};
|
|
26
|
+
// prettier-ignore
|
|
27
|
+
exports.p521 = (0, _shortw_utils_js_1.createCurve)({
|
|
28
|
+
a: CURVE.a,
|
|
29
|
+
b: CURVE.b,
|
|
30
|
+
Fp,
|
|
31
|
+
// Curve order, total count of valid points in the field
|
|
32
|
+
n: CURVE.n,
|
|
33
|
+
Gx: CURVE.Gx,
|
|
34
|
+
Gy: CURVE.Gy,
|
|
35
|
+
h: CURVE.h,
|
|
37
36
|
lowS: false,
|
|
38
37
|
allowedPrivateKeyLengths: [130, 131, 132] // P521 keys are variable-length. Normalize to 132b
|
|
39
38
|
}, sha512_1.sha512);
|
|
40
|
-
exports.secp521r1 = exports.
|
|
39
|
+
exports.secp521r1 = exports.p521;
|
|
40
|
+
const mapSWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
|
|
41
|
+
A: CURVE.a,
|
|
42
|
+
B: CURVE.b,
|
|
43
|
+
Z: Fp.create(BigInt('-4')),
|
|
44
|
+
});
|
|
41
45
|
const { hashToCurve, encodeToCurve } = htf.createHasher(exports.secp521r1.ProjectivePoint, (scalars) => mapSWU(scalars[0]), {
|
|
42
46
|
DST: 'P521_XMD:SHA-512_SSWU_RO_',
|
|
43
47
|
encodeDST: 'P521_XMD:SHA-512_SSWU_NU_',
|
package/p521.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p521.js","sourceRoot":"","sources":["src/p521.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACtE,yDAAiD;AACjD,iDAA8C;AAC9C,sDAA8C;AAC9C,8DAAgE;AAChE,mDAAmD;AAEnD,0BAA0B;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EAAE,EAAE;IACrC,CAAC,EAAE,KAAK,CAAC,CAAC;IACV,CAAC,EAAE,KAAK,CAAC,CAAC;IACV,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CAC3B,CAAC,CAAC;AAEH,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,GAAG,CAAC,YAAY,CACrD,iBAAS,CAAC,eAAe,EACzB,CAAC,OAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EACzC;IACE,GAAG,EAAE,2BAA2B;IAChC,SAAS,EAAE,2BAA2B;IACtC,CAAC,EAAE,EAAE,CAAC,KAAK;IACX,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,GAAG;IACN,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,eAAM;CACb,CACF,CAAC;AACO,kCAAW;AAAE,sCAAa"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noble/curves",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Audited & minimal JS implementation of elliptic curve cryptography",
|
|
5
5
|
"files": [
|
|
6
6
|
"abstract",
|
|
@@ -31,9 +31,6 @@
|
|
|
31
31
|
"@noble/hashes": "1.3.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@scure/bip32": "~1.2.0",
|
|
35
|
-
"@scure/bip39": "~1.2.0",
|
|
36
|
-
"@types/node": "18.11.18",
|
|
37
34
|
"fast-check": "3.0.0",
|
|
38
35
|
"micro-bmark": "0.3.1",
|
|
39
36
|
"micro-should": "0.4.0",
|
|
@@ -102,10 +99,10 @@
|
|
|
102
99
|
"import": "./esm/bls12-381.js",
|
|
103
100
|
"default": "./bls12-381.js"
|
|
104
101
|
},
|
|
105
|
-
"./
|
|
106
|
-
"types": "./
|
|
107
|
-
"import": "./esm/
|
|
108
|
-
"default": "./
|
|
102
|
+
"./bn254": {
|
|
103
|
+
"types": "./bn254.d.ts",
|
|
104
|
+
"import": "./esm/bn254.js",
|
|
105
|
+
"default": "./bn254.js"
|
|
109
106
|
},
|
|
110
107
|
"./ed25519": {
|
|
111
108
|
"types": "./ed25519.d.ts",
|
package/src/abstract/bls.ts
CHANGED
|
@@ -24,13 +24,16 @@ import {
|
|
|
24
24
|
|
|
25
25
|
type Fp = bigint; // Can be different field?
|
|
26
26
|
|
|
27
|
+
// prettier-ignore
|
|
28
|
+
const _2n = BigInt(2), _3n = BigInt(3);
|
|
29
|
+
|
|
27
30
|
export type SignatureCoder<Fp2> = {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
fromHex(hex: Hex): ProjPointType<Fp2>;
|
|
32
|
+
toRawBytes(point: ProjPointType<Fp2>): Uint8Array;
|
|
33
|
+
toHex(point: ProjPointType<Fp2>): string;
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
export type CurveType<Fp, Fp2, Fp6, Fp12> = {
|
|
33
|
-
r: bigint;
|
|
34
37
|
G1: Omit<CurvePointsType<Fp>, 'n'> & {
|
|
35
38
|
mapToCurve: htf.MapToCurve<Fp>;
|
|
36
39
|
htfDefaults: htf.Opts;
|
|
@@ -40,20 +43,25 @@ export type CurveType<Fp, Fp2, Fp6, Fp12> = {
|
|
|
40
43
|
mapToCurve: htf.MapToCurve<Fp2>;
|
|
41
44
|
htfDefaults: htf.Opts;
|
|
42
45
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
fields: {
|
|
47
|
+
Fp: IField<Fp>;
|
|
48
|
+
Fr: IField<bigint>;
|
|
49
|
+
Fp2: IField<Fp2> & {
|
|
50
|
+
reim: (num: Fp2) => { re: bigint; im: bigint };
|
|
51
|
+
multiplyByB: (num: Fp2) => Fp2;
|
|
52
|
+
frobeniusMap(num: Fp2, power: number): Fp2;
|
|
53
|
+
};
|
|
54
|
+
Fp6: IField<Fp6>;
|
|
55
|
+
Fp12: IField<Fp12> & {
|
|
56
|
+
frobeniusMap(num: Fp12, power: number): Fp12;
|
|
57
|
+
multiplyBy014(num: Fp12, o0: Fp2, o1: Fp2, o4: Fp2): Fp12;
|
|
58
|
+
conjugate(num: Fp12): Fp12;
|
|
59
|
+
finalExponentiate(num: Fp12): Fp12;
|
|
60
|
+
};
|
|
50
61
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
multiplyBy014(num: Fp12, o0: Fp2, o1: Fp2, o4: Fp2): Fp12;
|
|
55
|
-
conjugate(num: Fp12): Fp12;
|
|
56
|
-
finalExponentiate(num: Fp12): Fp12;
|
|
62
|
+
params: {
|
|
63
|
+
x: bigint;
|
|
64
|
+
r: bigint;
|
|
57
65
|
};
|
|
58
66
|
htfDefaults: htf.Opts;
|
|
59
67
|
hash: CHash; // Because we need outputLen for DRBG
|
|
@@ -61,18 +69,6 @@ export type CurveType<Fp, Fp2, Fp6, Fp12> = {
|
|
|
61
69
|
};
|
|
62
70
|
|
|
63
71
|
export type CurveFn<Fp, Fp2, Fp6, Fp12> = {
|
|
64
|
-
CURVE: CurveType<Fp, Fp2, Fp6, Fp12>;
|
|
65
|
-
Fr: IField<bigint>;
|
|
66
|
-
Fp: IField<Fp>;
|
|
67
|
-
Fp2: IField<Fp2>;
|
|
68
|
-
Fp6: IField<Fp6>;
|
|
69
|
-
Fp12: IField<Fp12>;
|
|
70
|
-
G1: CurvePointsRes<Fp> & ReturnType<typeof htf.createHasher<Fp>>;
|
|
71
|
-
G2: CurvePointsRes<Fp2> & ReturnType<typeof htf.createHasher<Fp2>>;
|
|
72
|
-
Signature: SignatureCoder<Fp2>;
|
|
73
|
-
millerLoop: (ell: [Fp2, Fp2, Fp2][], g1: [Fp, Fp]) => Fp12;
|
|
74
|
-
calcPairingPrecomputes: (p: AffinePoint<Fp2>) => [Fp2, Fp2, Fp2][];
|
|
75
|
-
pairing: (P: ProjPointType<Fp>, Q: ProjPointType<Fp2>, withFinalExponent?: boolean) => Fp12;
|
|
76
72
|
getPublicKey: (privateKey: PrivKey) => Uint8Array;
|
|
77
73
|
sign: {
|
|
78
74
|
(message: Hex, privateKey: PrivKey): Uint8Array;
|
|
@@ -83,6 +79,11 @@ export type CurveFn<Fp, Fp2, Fp6, Fp12> = {
|
|
|
83
79
|
message: Hex | ProjPointType<Fp2>,
|
|
84
80
|
publicKey: Hex | ProjPointType<Fp>
|
|
85
81
|
) => boolean;
|
|
82
|
+
verifyBatch: (
|
|
83
|
+
signature: Hex | ProjPointType<Fp2>,
|
|
84
|
+
messages: (Hex | ProjPointType<Fp2>)[],
|
|
85
|
+
publicKeys: (Hex | ProjPointType<Fp>)[]
|
|
86
|
+
) => boolean;
|
|
86
87
|
aggregatePublicKeys: {
|
|
87
88
|
(publicKeys: Hex[]): Uint8Array;
|
|
88
89
|
(publicKeys: ProjPointType<Fp>[]): ProjPointType<Fp>;
|
|
@@ -91,22 +92,36 @@ export type CurveFn<Fp, Fp2, Fp6, Fp12> = {
|
|
|
91
92
|
(signatures: Hex[]): Uint8Array;
|
|
92
93
|
(signatures: ProjPointType<Fp2>[]): ProjPointType<Fp2>;
|
|
93
94
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
millerLoop: (ell: [Fp2, Fp2, Fp2][], g1: [Fp, Fp]) => Fp12;
|
|
96
|
+
pairing: (P: ProjPointType<Fp>, Q: ProjPointType<Fp2>, withFinalExponent?: boolean) => Fp12;
|
|
97
|
+
G1: CurvePointsRes<Fp> & ReturnType<typeof htf.createHasher<Fp>>;
|
|
98
|
+
G2: CurvePointsRes<Fp2> & ReturnType<typeof htf.createHasher<Fp2>>;
|
|
99
|
+
Signature: SignatureCoder<Fp2>;
|
|
100
|
+
params: {
|
|
101
|
+
x: bigint;
|
|
102
|
+
r: bigint;
|
|
103
|
+
G1b: bigint;
|
|
104
|
+
G2b: Fp2;
|
|
105
|
+
};
|
|
106
|
+
fields: {
|
|
107
|
+
Fp: IField<Fp>;
|
|
108
|
+
Fp2: IField<Fp2>;
|
|
109
|
+
Fp6: IField<Fp6>;
|
|
110
|
+
Fp12: IField<Fp12>;
|
|
111
|
+
Fr: IField<bigint>;
|
|
112
|
+
};
|
|
99
113
|
utils: {
|
|
100
114
|
randomPrivateKey: () => Uint8Array;
|
|
115
|
+
calcPairingPrecomputes: (p: AffinePoint<Fp2>) => [Fp2, Fp2, Fp2][];
|
|
101
116
|
};
|
|
102
117
|
};
|
|
103
118
|
|
|
104
119
|
export function bls<Fp2, Fp6, Fp12>(
|
|
105
120
|
CURVE: CurveType<Fp, Fp2, Fp6, Fp12>
|
|
106
121
|
): CurveFn<Fp, Fp2, Fp6, Fp12> {
|
|
107
|
-
// Fields
|
|
108
|
-
const { Fp, Fr, Fp2, Fp6, Fp12 } = CURVE;
|
|
109
|
-
const BLS_X_LEN = bitLen(CURVE.x);
|
|
122
|
+
// Fields are specific for curve, so for now we'll need to pass them with opts
|
|
123
|
+
const { Fp, Fr, Fp2, Fp6, Fp12 } = CURVE.fields;
|
|
124
|
+
const BLS_X_LEN = bitLen(CURVE.params.x);
|
|
110
125
|
const groupLen = 32; // TODO: calculate; hardcoded for now
|
|
111
126
|
|
|
112
127
|
// Pre-compute coefficients for sparse multiplication
|
|
@@ -122,18 +137,18 @@ export function bls<Fp2, Fp6, Fp12>(
|
|
|
122
137
|
// Double
|
|
123
138
|
let t0 = Fp2.sqr(Ry); // Ry²
|
|
124
139
|
let t1 = Fp2.sqr(Rz); // Rz²
|
|
125
|
-
let t2 = Fp2.multiplyByB(Fp2.mul(t1,
|
|
126
|
-
let t3 = Fp2.mul(t2,
|
|
140
|
+
let t2 = Fp2.multiplyByB(Fp2.mul(t1, _3n)); // 3 * T1 * B
|
|
141
|
+
let t3 = Fp2.mul(t2, _3n); // 3 * T2
|
|
127
142
|
let t4 = Fp2.sub(Fp2.sub(Fp2.sqr(Fp2.add(Ry, Rz)), t1), t0); // (Ry + Rz)² - T1 - T0
|
|
128
143
|
ell_coeff.push([
|
|
129
144
|
Fp2.sub(t2, t0), // T2 - T0
|
|
130
|
-
Fp2.mul(Fp2.sqr(Rx),
|
|
145
|
+
Fp2.mul(Fp2.sqr(Rx), _3n), // 3 * Rx²
|
|
131
146
|
Fp2.neg(t4), // -T4
|
|
132
147
|
]);
|
|
133
|
-
Rx = Fp2.div(Fp2.mul(Fp2.mul(Fp2.sub(t0, t3), Rx), Ry),
|
|
134
|
-
Ry = Fp2.sub(Fp2.sqr(Fp2.div(Fp2.add(t0, t3),
|
|
148
|
+
Rx = Fp2.div(Fp2.mul(Fp2.mul(Fp2.sub(t0, t3), Rx), Ry), _2n); // ((T0 - T3) * Rx * Ry) / 2
|
|
149
|
+
Ry = Fp2.sub(Fp2.sqr(Fp2.div(Fp2.add(t0, t3), _2n)), Fp2.mul(Fp2.sqr(t2), _3n)); // ((T0 + T3) / 2)² - 3 * T2²
|
|
135
150
|
Rz = Fp2.mul(t0, t4); // T0 * T4
|
|
136
|
-
if (bitGet(CURVE.x, i)) {
|
|
151
|
+
if (bitGet(CURVE.params.x, i)) {
|
|
137
152
|
// Addition
|
|
138
153
|
let t0 = Fp2.sub(Ry, Fp2.mul(Qy, Rz)); // Ry - Qy * Rz
|
|
139
154
|
let t1 = Fp2.sub(Rx, Fp2.mul(Qx, Rz)); // Rx - Qx * Rz
|
|
@@ -145,7 +160,7 @@ export function bls<Fp2, Fp6, Fp12>(
|
|
|
145
160
|
let t2 = Fp2.sqr(t1); // T1²
|
|
146
161
|
let t3 = Fp2.mul(t2, t1); // T2 * T1
|
|
147
162
|
let t4 = Fp2.mul(t2, Rx); // T2 * Rx
|
|
148
|
-
let t5 = Fp2.add(Fp2.sub(t3, Fp2.mul(t4,
|
|
163
|
+
let t5 = Fp2.add(Fp2.sub(t3, Fp2.mul(t4, _2n)), Fp2.mul(Fp2.sqr(t0), Rz)); // T3 - 2 * T4 + T0² * Rz
|
|
149
164
|
Rx = Fp2.mul(t1, t5); // T1 * T5
|
|
150
165
|
Ry = Fp2.sub(Fp2.mul(Fp2.sub(t4, t5), t0), Fp2.mul(t3, Ry)); // (T4 - T5) * T0 - T3 * Ry
|
|
151
166
|
Rz = Fp2.mul(Rz, t3); // Rz * T3
|
|
@@ -155,7 +170,7 @@ export function bls<Fp2, Fp6, Fp12>(
|
|
|
155
170
|
}
|
|
156
171
|
|
|
157
172
|
function millerLoop(ell: [Fp2, Fp2, Fp2][], g1: [Fp, Fp]): Fp12 {
|
|
158
|
-
const { x } = CURVE;
|
|
173
|
+
const { x } = CURVE.params;
|
|
159
174
|
const Px = g1[0];
|
|
160
175
|
const Py = g1[1];
|
|
161
176
|
let f12 = Fp12.ONE;
|
|
@@ -174,8 +189,9 @@ export function bls<Fp2, Fp6, Fp12>(
|
|
|
174
189
|
|
|
175
190
|
const utils = {
|
|
176
191
|
randomPrivateKey: (): Uint8Array => {
|
|
177
|
-
return Fr.toBytes(hashToPrivateScalar(CURVE.randomBytes(groupLen + 8), CURVE.r));
|
|
192
|
+
return Fr.toBytes(hashToPrivateScalar(CURVE.randomBytes(groupLen + 8), CURVE.params.r));
|
|
178
193
|
},
|
|
194
|
+
calcPairingPrecomputes,
|
|
179
195
|
};
|
|
180
196
|
|
|
181
197
|
// Point on G1 curve: (x, y)
|
|
@@ -236,7 +252,7 @@ export function bls<Fp2, Fp6, Fp12>(
|
|
|
236
252
|
return point instanceof G1.ProjectivePoint ? (point as G1) : G1.ProjectivePoint.fromHex(point);
|
|
237
253
|
}
|
|
238
254
|
function normP2(point: G2Hex): G2 {
|
|
239
|
-
return point instanceof G2.ProjectivePoint ? point : Signature.
|
|
255
|
+
return point instanceof G2.ProjectivePoint ? point : Signature.fromHex(point);
|
|
240
256
|
}
|
|
241
257
|
function normP2Hash(point: G2Hex, htfOpts?: htf.htfBasicOpts): G2 {
|
|
242
258
|
return point instanceof G2.ProjectivePoint
|
|
@@ -259,7 +275,7 @@ export function bls<Fp2, Fp6, Fp12>(
|
|
|
259
275
|
msgPoint.assertValidity();
|
|
260
276
|
const sigPoint = msgPoint.multiply(G1.normPrivateKeyToScalar(privateKey));
|
|
261
277
|
if (message instanceof G2.ProjectivePoint) return sigPoint;
|
|
262
|
-
return Signature.
|
|
278
|
+
return Signature.toRawBytes(sigPoint);
|
|
263
279
|
}
|
|
264
280
|
|
|
265
281
|
// Checks if pairing of public key & hash is equal to pairing of generator & signature.
|
|
@@ -309,7 +325,7 @@ export function bls<Fp2, Fp6, Fp12>(
|
|
|
309
325
|
aggAffine.assertValidity();
|
|
310
326
|
return aggAffine;
|
|
311
327
|
}
|
|
312
|
-
return Signature.
|
|
328
|
+
return Signature.toRawBytes(aggAffine);
|
|
313
329
|
}
|
|
314
330
|
|
|
315
331
|
// https://ethresear.ch/t/fast-verification-of-multiple-bls-signatures/5407
|
|
@@ -353,24 +369,30 @@ export function bls<Fp2, Fp6, Fp12>(
|
|
|
353
369
|
G1.ProjectivePoint.BASE._setWindowSize(4);
|
|
354
370
|
|
|
355
371
|
return {
|
|
356
|
-
CURVE,
|
|
357
|
-
Fr,
|
|
358
|
-
Fp,
|
|
359
|
-
Fp2,
|
|
360
|
-
Fp6,
|
|
361
|
-
Fp12,
|
|
362
|
-
G1,
|
|
363
|
-
G2,
|
|
364
|
-
Signature,
|
|
365
|
-
millerLoop,
|
|
366
|
-
calcPairingPrecomputes,
|
|
367
|
-
pairing,
|
|
368
372
|
getPublicKey,
|
|
369
373
|
sign,
|
|
370
374
|
verify,
|
|
375
|
+
verifyBatch,
|
|
371
376
|
aggregatePublicKeys,
|
|
372
377
|
aggregateSignatures,
|
|
373
|
-
|
|
378
|
+
millerLoop,
|
|
379
|
+
pairing,
|
|
380
|
+
G1,
|
|
381
|
+
G2,
|
|
382
|
+
Signature,
|
|
383
|
+
fields: {
|
|
384
|
+
Fr,
|
|
385
|
+
Fp,
|
|
386
|
+
Fp2,
|
|
387
|
+
Fp6,
|
|
388
|
+
Fp12,
|
|
389
|
+
},
|
|
390
|
+
params: {
|
|
391
|
+
x: CURVE.params.x,
|
|
392
|
+
r: CURVE.params.r,
|
|
393
|
+
G1b: CURVE.G1.b,
|
|
394
|
+
G2b: CURVE.G2.b,
|
|
395
|
+
},
|
|
374
396
|
utils,
|
|
375
397
|
};
|
|
376
398
|
}
|