@noble/curves 0.8.3 → 0.9.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.
Files changed (108) hide show
  1. package/README.md +87 -62
  2. package/_shortw_utils.d.ts +2 -1
  3. package/_shortw_utils.d.ts.map +1 -1
  4. package/abstract/bls.d.ts +11 -11
  5. package/abstract/bls.d.ts.map +1 -1
  6. package/abstract/bls.js.map +1 -1
  7. package/abstract/curve.d.ts +5 -3
  8. package/abstract/curve.d.ts.map +1 -1
  9. package/abstract/curve.js +5 -1
  10. package/abstract/curve.js.map +1 -1
  11. package/abstract/edwards.d.ts +6 -1
  12. package/abstract/edwards.d.ts.map +1 -1
  13. package/abstract/edwards.js +8 -9
  14. package/abstract/edwards.js.map +1 -1
  15. package/abstract/hash-to-curve.d.ts +2 -2
  16. package/abstract/hash-to-curve.d.ts.map +1 -1
  17. package/abstract/hash-to-curve.js.map +1 -1
  18. package/abstract/modular.d.ts +24 -12
  19. package/abstract/modular.d.ts.map +1 -1
  20. package/abstract/modular.js +17 -4
  21. package/abstract/modular.js.map +1 -1
  22. package/abstract/poseidon.d.ts +3 -3
  23. package/abstract/poseidon.d.ts.map +1 -1
  24. package/abstract/poseidon.js.map +1 -1
  25. package/abstract/weierstrass.d.ts +29 -5
  26. package/abstract/weierstrass.d.ts.map +1 -1
  27. package/abstract/weierstrass.js +37 -23
  28. package/abstract/weierstrass.js.map +1 -1
  29. package/bls12-381.d.ts +4 -4
  30. package/bls12-381.d.ts.map +1 -1
  31. package/bls12-381.js +109 -106
  32. package/bls12-381.js.map +1 -1
  33. package/bn.js +1 -1
  34. package/bn.js.map +1 -1
  35. package/ed25519.js +2 -2
  36. package/ed25519.js.map +1 -1
  37. package/ed448.d.ts.map +1 -1
  38. package/ed448.js +4 -3
  39. package/ed448.js.map +1 -1
  40. package/esm/abstract/bls.js.map +1 -1
  41. package/esm/abstract/curve.js +5 -1
  42. package/esm/abstract/curve.js.map +1 -1
  43. package/esm/abstract/edwards.js +8 -9
  44. package/esm/abstract/edwards.js.map +1 -1
  45. package/esm/abstract/hash-to-curve.js.map +1 -1
  46. package/esm/abstract/modular.js +15 -2
  47. package/esm/abstract/modular.js.map +1 -1
  48. package/esm/abstract/poseidon.js.map +1 -1
  49. package/esm/abstract/weierstrass.js +37 -23
  50. package/esm/abstract/weierstrass.js.map +1 -1
  51. package/esm/bls12-381.js +109 -106
  52. package/esm/bls12-381.js.map +1 -1
  53. package/esm/bn.js +2 -2
  54. package/esm/bn.js.map +1 -1
  55. package/esm/ed25519.js +2 -2
  56. package/esm/ed25519.js.map +1 -1
  57. package/esm/ed448.js +4 -3
  58. package/esm/ed448.js.map +1 -1
  59. package/esm/jubjub.js +2 -2
  60. package/esm/jubjub.js.map +1 -1
  61. package/esm/p256.js +1 -1
  62. package/esm/p256.js.map +1 -1
  63. package/esm/p384.js +1 -1
  64. package/esm/p384.js.map +1 -1
  65. package/esm/p521.js +1 -1
  66. package/esm/p521.js.map +1 -1
  67. package/esm/pasta.js +2 -2
  68. package/esm/pasta.js.map +1 -1
  69. package/esm/secp256k1.js +2 -2
  70. package/esm/secp256k1.js.map +1 -1
  71. package/jubjub.js +1 -1
  72. package/jubjub.js.map +1 -1
  73. package/p256.d.ts +4 -2
  74. package/p256.d.ts.map +1 -1
  75. package/p256.js +1 -1
  76. package/p256.js.map +1 -1
  77. package/p384.d.ts +4 -2
  78. package/p384.d.ts.map +1 -1
  79. package/p384.js +1 -1
  80. package/p384.js.map +1 -1
  81. package/p521.d.ts +4 -2
  82. package/p521.d.ts.map +1 -1
  83. package/p521.js +1 -1
  84. package/p521.js.map +1 -1
  85. package/package.json +5 -5
  86. package/pasta.js +2 -2
  87. package/pasta.js.map +1 -1
  88. package/secp256k1.d.ts +2 -1
  89. package/secp256k1.d.ts.map +1 -1
  90. package/secp256k1.js +2 -2
  91. package/secp256k1.js.map +1 -1
  92. package/src/abstract/bls.ts +11 -11
  93. package/src/abstract/curve.ts +7 -3
  94. package/src/abstract/edwards.ts +12 -9
  95. package/src/abstract/hash-to-curve.ts +2 -2
  96. package/src/abstract/modular.ts +29 -20
  97. package/src/abstract/poseidon.ts +2 -2
  98. package/src/abstract/weierstrass.ts +45 -27
  99. package/src/bls12-381.ts +199 -114
  100. package/src/bn.ts +2 -2
  101. package/src/ed25519.ts +2 -2
  102. package/src/ed448.ts +4 -3
  103. package/src/jubjub.ts +2 -2
  104. package/src/p256.ts +1 -1
  105. package/src/p384.ts +1 -1
  106. package/src/p521.ts +1 -1
  107. package/src/pasta.ts +2 -2
  108. package/src/secp256k1.ts +3 -4
package/src/jubjub.ts CHANGED
@@ -3,7 +3,7 @@ import { sha512 } from '@noble/hashes/sha512';
3
3
  import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils';
4
4
  import { twistedEdwards } from './abstract/edwards.js';
5
5
  import { blake2s } from '@noble/hashes/blake2s';
6
- import { Fp } from './abstract/modular.js';
6
+ import { Field } from './abstract/modular.js';
7
7
 
8
8
  /**
9
9
  * jubjub Twisted Edwards curve.
@@ -17,7 +17,7 @@ export const jubjub = twistedEdwards({
17
17
  d: BigInt('0x2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1'),
18
18
  // Finite field 𝔽p over which we'll do calculations
19
19
  // Same value as bls12-381 Fr (not Fp)
20
- Fp: Fp(BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001')),
20
+ Fp: Field(BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001')),
21
21
  // Subgroup order: how many points curve has
22
22
  n: BigInt('0xe7db4ea6533afa906673b0101343b00a6682093ccc81082d0970e5ed6f72cb7'),
23
23
  // Cofactor
package/src/p256.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
2
  import { createCurve } from './_shortw_utils.js';
3
3
  import { sha256 } from '@noble/hashes/sha256';
4
- import { Fp as Field } from './abstract/modular.js';
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
7
 
package/src/p384.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
2
  import { createCurve } from './_shortw_utils.js';
3
3
  import { sha384 } from '@noble/hashes/sha512';
4
- import { Fp as Field } from './abstract/modular.js';
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
7
 
package/src/p521.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
2
  import { createCurve } from './_shortw_utils.js';
3
3
  import { sha512 } from '@noble/hashes/sha512';
4
- import { Fp as Field } from './abstract/modular.js';
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
7
 
package/src/pasta.ts CHANGED
@@ -11,7 +11,7 @@ export const q = BigInt('0x40000000000000000000000000000000224698fc0994a8dd8c46e
11
11
  export const pallas = weierstrass({
12
12
  a: BigInt(0),
13
13
  b: BigInt(5),
14
- Fp: mod.Fp(p),
14
+ Fp: mod.Field(p),
15
15
  n: q,
16
16
  Gx: mod.mod(BigInt(-1), p),
17
17
  Gy: BigInt(2),
@@ -22,7 +22,7 @@ export const pallas = weierstrass({
22
22
  export const vesta = weierstrass({
23
23
  a: BigInt(0),
24
24
  b: BigInt(5),
25
- Fp: mod.Fp(q),
25
+ Fp: mod.Field(q),
26
26
  n: p,
27
27
  Gx: mod.mod(BigInt(-1), q),
28
28
  Gy: BigInt(2),
package/src/secp256k1.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
2
  import { sha256 } from '@noble/hashes/sha256';
3
3
  import { randomBytes } from '@noble/hashes/utils';
4
- import { Fp as Field, mod, pow2 } from './abstract/modular.js';
4
+ import { Field, mod, pow2 } from './abstract/modular.js';
5
5
  import { ProjPointType as PointType, mapToCurveSimpleSWU } from './abstract/weierstrass.js';
6
6
  import type { Hex, PrivKey } from './abstract/utils.js';
7
7
  import { bytesToNumberBE, concatBytes, ensureBytes, numberToBytesBE } from './abstract/utils.js';
@@ -43,7 +43,6 @@ function sqrtMod(y: bigint): bigint {
43
43
  }
44
44
 
45
45
  const Fp = Field(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
46
- type Fp = bigint;
47
46
 
48
47
  export const secp256k1 = createCurve(
49
48
  {
@@ -132,7 +131,7 @@ function lift_x(x: bigint): PointType<bigint> {
132
131
  const xx = modP(x * x);
133
132
  const c = modP(xx * x + BigInt(7)); // Let c = x³ + 7 mod p.
134
133
  let y = sqrtMod(c); // Let y = c^(p+1)/4 mod p.
135
- if (y % 2n !== 0n) y = modP(-y); // Return the unique point P such that x(P) = x and
134
+ if (y % _2n !== _0n) y = modP(-y); // Return the unique point P such that x(P) = x and
136
135
  const p = new Point(x, y, _1n); // y(P) = y if y mod 2 = 0 or y(P) = p-y otherwise.
137
136
  p.assertValidity();
138
137
  return p;
@@ -245,7 +244,7 @@ const isoMap = htf.isogenyMap(
245
244
  '0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f',
246
245
  '0x0000000000000000000000000000000000000000000000000000000000000001', // LAST 1
247
246
  ],
248
- ].map((i) => i.map((j) => BigInt(j))) as [Fp[], Fp[], Fp[], Fp[]]
247
+ ].map((i) => i.map((j) => BigInt(j))) as [bigint[], bigint[], bigint[], bigint[]]
249
248
  );
250
249
  const mapSWU = mapToCurveSimpleSWU(Fp, {
251
250
  A: BigInt('0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533'),