@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.
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/abstract/bls.d.ts +410 -0
- package/abstract/bls.js +433 -0
- package/abstract/curve.d.ts +441 -0
- package/abstract/curve.js +622 -0
- package/abstract/edwards.d.ts +319 -0
- package/abstract/edwards.js +697 -0
- package/abstract/fft.d.ts +438 -0
- package/abstract/fft.js +580 -0
- package/abstract/frost.d.ts +292 -0
- package/abstract/frost.js +705 -0
- package/abstract/hash-to-curve.d.ts +238 -0
- package/abstract/hash-to-curve.js +353 -0
- package/abstract/modular.d.ts +550 -0
- package/abstract/modular.js +872 -0
- package/abstract/montgomery.d.ts +95 -0
- package/abstract/montgomery.js +180 -0
- package/abstract/oprf.d.ts +354 -0
- package/abstract/oprf.js +358 -0
- package/abstract/poseidon.d.ts +198 -0
- package/abstract/poseidon.js +471 -0
- package/abstract/tower.d.ts +213 -0
- package/abstract/tower.js +963 -0
- package/abstract/weierstrass.d.ts +587 -0
- package/abstract/weierstrass.js +1421 -0
- package/bls12-381.d.ts +23 -0
- package/bls12-381.js +680 -0
- package/bn254.d.ts +74 -0
- package/bn254.js +248 -0
- package/ed25519.d.ts +211 -0
- package/ed25519.js +626 -0
- package/ed448.d.ts +184 -0
- package/ed448.js +596 -0
- package/esm/abstract/bls.js +429 -0
- package/esm/abstract/curve.js +610 -0
- package/esm/abstract/edwards.js +691 -0
- package/esm/abstract/fft.js +567 -0
- package/esm/abstract/frost.js +702 -0
- package/esm/abstract/hash-to-curve.js +345 -0
- package/esm/abstract/modular.js +849 -0
- package/esm/abstract/montgomery.js +177 -0
- package/esm/abstract/oprf.js +355 -0
- package/esm/abstract/poseidon.js +462 -0
- package/esm/abstract/tower.js +925 -0
- package/esm/abstract/weierstrass.js +1411 -0
- package/esm/bls12-381.js +677 -0
- package/esm/bn254.js +244 -0
- package/esm/ed25519.js +622 -0
- package/esm/ed448.js +593 -0
- package/esm/index.js +38 -0
- package/esm/misc.js +211 -0
- package/esm/nist.js +266 -0
- package/esm/secp256k1.js +465 -0
- package/esm/utils.js +597 -0
- package/esm/webcrypto.js +362 -0
- package/index.d.ts +0 -0
- package/index.js +38 -0
- package/misc.d.ts +113 -0
- package/misc.js +216 -0
- package/nist.d.ts +136 -0
- package/nist.js +269 -0
- package/package.json +46 -0
- package/secp256k1.d.ts +152 -0
- package/secp256k1.js +468 -0
- package/utils.d.ts +535 -0
- package/utils.js +626 -0
- package/webcrypto.d.ts +240 -0
- 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 {};
|