@decryption/curves 0.2.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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -0
  3. package/abstract/bls.d.ts +410 -0
  4. package/abstract/bls.js +433 -0
  5. package/abstract/curve.d.ts +441 -0
  6. package/abstract/curve.js +622 -0
  7. package/abstract/edwards.d.ts +319 -0
  8. package/abstract/edwards.js +697 -0
  9. package/abstract/fft.d.ts +438 -0
  10. package/abstract/fft.js +580 -0
  11. package/abstract/frost.d.ts +292 -0
  12. package/abstract/frost.js +705 -0
  13. package/abstract/hash-to-curve.d.ts +238 -0
  14. package/abstract/hash-to-curve.js +353 -0
  15. package/abstract/modular.d.ts +550 -0
  16. package/abstract/modular.js +872 -0
  17. package/abstract/montgomery.d.ts +95 -0
  18. package/abstract/montgomery.js +180 -0
  19. package/abstract/oprf.d.ts +354 -0
  20. package/abstract/oprf.js +358 -0
  21. package/abstract/poseidon.d.ts +198 -0
  22. package/abstract/poseidon.js +471 -0
  23. package/abstract/tower.d.ts +213 -0
  24. package/abstract/tower.js +963 -0
  25. package/abstract/weierstrass.d.ts +587 -0
  26. package/abstract/weierstrass.js +1421 -0
  27. package/bls12-381.d.ts +23 -0
  28. package/bls12-381.js +680 -0
  29. package/bn254.d.ts +74 -0
  30. package/bn254.js +248 -0
  31. package/ed25519.d.ts +211 -0
  32. package/ed25519.js +626 -0
  33. package/ed448.d.ts +184 -0
  34. package/ed448.js +596 -0
  35. package/esm/abstract/bls.js +429 -0
  36. package/esm/abstract/curve.js +610 -0
  37. package/esm/abstract/edwards.js +691 -0
  38. package/esm/abstract/fft.js +567 -0
  39. package/esm/abstract/frost.js +702 -0
  40. package/esm/abstract/hash-to-curve.js +345 -0
  41. package/esm/abstract/modular.js +849 -0
  42. package/esm/abstract/montgomery.js +177 -0
  43. package/esm/abstract/oprf.js +355 -0
  44. package/esm/abstract/poseidon.js +462 -0
  45. package/esm/abstract/tower.js +925 -0
  46. package/esm/abstract/weierstrass.js +1411 -0
  47. package/esm/bls12-381.js +677 -0
  48. package/esm/bn254.js +244 -0
  49. package/esm/ed25519.js +622 -0
  50. package/esm/ed448.js +593 -0
  51. package/esm/index.js +38 -0
  52. package/esm/misc.js +211 -0
  53. package/esm/nist.js +266 -0
  54. package/esm/secp256k1.js +465 -0
  55. package/esm/utils.js +597 -0
  56. package/esm/webcrypto.js +362 -0
  57. package/index.d.ts +0 -0
  58. package/index.js +38 -0
  59. package/misc.d.ts +113 -0
  60. package/misc.js +216 -0
  61. package/nist.d.ts +136 -0
  62. package/nist.js +269 -0
  63. package/package.json +46 -0
  64. package/secp256k1.d.ts +152 -0
  65. package/secp256k1.js +468 -0
  66. package/utils.d.ts +535 -0
  67. package/utils.js +626 -0
  68. package/webcrypto.d.ts +240 -0
  69. package/webcrypto.js +365 -0
package/ed448.d.ts ADDED
@@ -0,0 +1,184 @@
1
+ import type { AffinePoint } from './abstract/curve';
2
+ import { PrimeEdwardsPoint, type EdDSA, type EdwardsPoint, type EdwardsPointCons } from './abstract/edwards';
3
+ import { type FROST } from './abstract/frost';
4
+ import { type H2CHasher, type H2CHasherBase } from './abstract/hash-to-curve';
5
+ import { type IField } from './abstract/modular';
6
+ import { type MontgomeryECDH } from './abstract/montgomery';
7
+ import { type OPRF } from './abstract/oprf';
8
+ import { type TArg, type TRet } from './utils';
9
+ /**
10
+ * ed448 EdDSA curve and methods.
11
+ * @example
12
+ * Generate one Ed448 keypair, sign a message, and verify it.
13
+ *
14
+ * ```js
15
+ * import { ed448 } from './ed448';
16
+ * const { secretKey, publicKey } = ed448.keygen();
17
+ * // const publicKey = ed448.getPublicKey(secretKey);
18
+ * const msg = new TextEncoder().encode('hello noble');
19
+ * const sig = ed448.sign(msg, secretKey);
20
+ * const isValid = ed448.verify(sig, msg, publicKey);
21
+ * ```
22
+ */
23
+ export declare const ed448: EdDSA;
24
+ /**
25
+ * Prehashed version of ed448. See {@link ed448}
26
+ * @example
27
+ * Use the prehashed Ed448 variant for one message.
28
+ *
29
+ * ```ts
30
+ * const { secretKey, publicKey } = ed448ph.keygen();
31
+ * const msg = new TextEncoder().encode('hello noble');
32
+ * const sig = ed448ph.sign(msg, secretKey);
33
+ * const isValid = ed448ph.verify(sig, msg, publicKey);
34
+ * ```
35
+ */
36
+ export declare const ed448ph: EdDSA;
37
+ /**
38
+ * E448 here is NIST SP 800-186 §3.2.3.3 E448, the Edwards representation of
39
+ * Curve448, not RFC 8032 edwards448 / Goldilocks.
40
+ * Goldilocks is the separate 4-isogenous curve exposed as `ed448`.
41
+ * We keep the corrected prime-order base here; RFC 7748's literal Edwards
42
+ * point / map are wrong for this curve model, and the literal point is the
43
+ * wrong-sign order-2*n variant.
44
+ * @param X - Projective X coordinate.
45
+ * @param Y - Projective Y coordinate.
46
+ * @param Z - Projective Z coordinate.
47
+ * @param T - Projective T coordinate.
48
+ * @example
49
+ * Multiply the E448 base point.
50
+ *
51
+ * ```ts
52
+ * const point = E448.BASE.multiply(2n);
53
+ * ```
54
+ */
55
+ export declare const E448: EdwardsPointCons;
56
+ /**
57
+ * ECDH using curve448 aka x448.
58
+ * The wrapper aborts on all-zero shared secrets by default, and seeded
59
+ * `keygen(seed)` reuses the provided 56-byte seed buffer instead of copying it.
60
+ *
61
+ * @example
62
+ * Derive one shared secret between two X448 peers.
63
+ *
64
+ * ```js
65
+ * import { x448 } from './ed448';
66
+ * const alice = x448.keygen();
67
+ * const bob = x448.keygen();
68
+ * const shared = x448.getSharedSecret(alice.secretKey, bob.publicKey);
69
+ * ```
70
+ */
71
+ export declare const x448: TRet<MontgomeryECDH>;
72
+ /**
73
+ * Hashing / encoding to ed448 points / field. RFC 9380 methods.
74
+ * Public `mapToCurve()` consumes one field element bigint for `m = 1`, and RFC
75
+ * Appendix J vectors use the special `QUUX-V01-*` test DST overrides rather
76
+ * than the default suite IDs below.
77
+ * @example
78
+ * Hash one message onto the ed448 curve.
79
+ *
80
+ * ```ts
81
+ * const point = ed448_hasher.hashToCurve(new TextEncoder().encode('hello noble'));
82
+ * ```
83
+ */
84
+ export declare const ed448_hasher: H2CHasher<EdwardsPointCons>;
85
+ /**
86
+ * FROST threshold signatures over ed448. RFC 9591.
87
+ * @example
88
+ * Create one trusted-dealer package for 2-of-3 ed448 signing.
89
+ *
90
+ * ```ts
91
+ * const alice = ed448_FROST.Identifier.derive('alice@example.com');
92
+ * const bob = ed448_FROST.Identifier.derive('bob@example.com');
93
+ * const carol = ed448_FROST.Identifier.derive('carol@example.com');
94
+ * const deal = ed448_FROST.trustedDealer({ min: 2, max: 3 }, [alice, bob, carol]);
95
+ * ```
96
+ */
97
+ export declare const ed448_FROST: TRet<FROST>;
98
+ /**
99
+ * Each ed448/EdwardsPoint has 4 different equivalent points. This can be
100
+ * a source of bugs for protocols like ring signatures. Decaf was created to solve this.
101
+ * Decaf point operates in X:Y:Z:T extended coordinates like EdwardsPoint,
102
+ * but it should work in its own namespace: do not combine those two.
103
+ * See [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
104
+ */
105
+ declare class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
106
+ static BASE: _DecafPoint;
107
+ static ZERO: _DecafPoint;
108
+ static Fp: IField<bigint>;
109
+ static Fn: IField<bigint>;
110
+ constructor(ep: EdwardsPoint);
111
+ /**
112
+ * Create one Decaf448 point from affine Edwards coordinates.
113
+ * This wraps the internal Edwards representative directly and is not a
114
+ * canonical decaf448 decoding path.
115
+ * Use `toBytes()` / `fromBytes()` if canonical decaf448 bytes matter.
116
+ */
117
+ static fromAffine(ap: AffinePoint<bigint>): _DecafPoint;
118
+ protected assertSame(other: _DecafPoint): void;
119
+ protected init(ep: EdwardsPoint): _DecafPoint;
120
+ static fromBytes(bytes: TArg<Uint8Array>): _DecafPoint;
121
+ /**
122
+ * Converts decaf-encoded string to decaf point.
123
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
124
+ * @param hex - Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
125
+ */
126
+ static fromHex(hex: string): _DecafPoint;
127
+ /**
128
+ * Encodes decaf point to Uint8Array.
129
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode-2).
130
+ */
131
+ toBytes(): TRet<Uint8Array>;
132
+ /**
133
+ * Compare one point to another.
134
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals-2).
135
+ */
136
+ equals(other: _DecafPoint): boolean;
137
+ is0(): boolean;
138
+ }
139
+ /** Prime-order Decaf448 group bundle. */
140
+ export declare const decaf448: {
141
+ Point: typeof _DecafPoint;
142
+ };
143
+ /**
144
+ * Hashing to decaf448 points / field. RFC 9380 methods.
145
+ * `hashToCurve()` is RFC 9380 `hash_to_decaf448`, `deriveToCurve()` is RFC
146
+ * 9496 element derivation, and `hashToScalar()` is a library helper layered on
147
+ * top of RFC 9496 scalar reduction.
148
+ * @example
149
+ * Hash one message onto decaf448.
150
+ *
151
+ * ```ts
152
+ * const point = decaf448_hasher.hashToCurve(new TextEncoder().encode('hello noble'));
153
+ * ```
154
+ */
155
+ export declare const decaf448_hasher: H2CHasherBase<typeof _DecafPoint>;
156
+ /**
157
+ * decaf448 OPRF, defined in RFC 9497.
158
+ * @example
159
+ * Run one blind/evaluate/finalize OPRF round over decaf448.
160
+ *
161
+ * ```ts
162
+ * const input = new TextEncoder().encode('hello noble');
163
+ * const keys = decaf448_oprf.oprf.generateKeyPair();
164
+ * const blind = decaf448_oprf.oprf.blind(input);
165
+ * const evaluated = decaf448_oprf.oprf.blindEvaluate(keys.secretKey, blind.blinded);
166
+ * const output = decaf448_oprf.oprf.finalize(input, blind.blind, evaluated);
167
+ * ```
168
+ */
169
+ export declare const decaf448_oprf: TRet<OPRF>;
170
+ /**
171
+ * Weird / bogus points, useful for debugging.
172
+ * Unlike ed25519, there is no ed448 generator point which can produce full T subgroup.
173
+ * Instead, the torsion subgroup here is cyclic of order 4, generated by
174
+ * `(1, 0)`, and the array below lists that subgroup set (Klein four-group).
175
+ * @example
176
+ * Decode one known torsion point for debugging.
177
+ *
178
+ * ```ts
179
+ * import { ED448_TORSION_SUBGROUP, ed448 } from './ed448';
180
+ * const point = ed448.Point.fromHex(ED448_TORSION_SUBGROUP[1]);
181
+ * ```
182
+ */
183
+ export declare const ED448_TORSION_SUBGROUP: readonly string[];
184
+ export {};