@noble/curves 1.9.7 → 2.0.0-beta.2
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 +520 -505
- package/abstract/bls.d.ts +58 -120
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +108 -152
- package/abstract/bls.js.map +1 -1
- package/abstract/curve.d.ts +18 -54
- package/abstract/curve.d.ts.map +1 -1
- package/abstract/curve.js +30 -49
- package/abstract/curve.js.map +1 -1
- package/abstract/edwards.d.ts +18 -77
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +68 -144
- package/abstract/edwards.js.map +1 -1
- package/abstract/fft.js +14 -27
- package/abstract/fft.js.map +1 -1
- package/abstract/hash-to-curve.d.ts +35 -47
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +42 -46
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts +5 -17
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +170 -169
- package/abstract/modular.js.map +1 -1
- package/abstract/montgomery.d.ts +7 -12
- package/abstract/montgomery.d.ts.map +1 -1
- package/abstract/montgomery.js +22 -29
- package/abstract/montgomery.js.map +1 -1
- package/abstract/oprf.d.ts +282 -0
- package/abstract/oprf.d.ts.map +1 -0
- package/abstract/oprf.js +297 -0
- package/abstract/oprf.js.map +1 -0
- package/abstract/poseidon.d.ts.map +1 -1
- package/abstract/poseidon.js +26 -31
- package/abstract/poseidon.js.map +1 -1
- package/abstract/tower.d.ts.map +1 -1
- package/abstract/tower.js +43 -19
- package/abstract/tower.js.map +1 -1
- package/abstract/weierstrass.d.ts +77 -168
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +184 -389
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts +5 -11
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +161 -181
- package/bls12-381.js.map +1 -1
- package/bn254.d.ts +59 -11
- package/bn254.d.ts.map +1 -1
- package/bn254.js +69 -97
- package/bn254.js.map +1 -1
- package/ed25519.d.ts +33 -48
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +147 -161
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +27 -36
- package/ed448.d.ts.map +1 -1
- package/ed448.js +143 -164
- package/ed448.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +20 -4
- package/index.js.map +1 -1
- package/misc.d.ts +10 -14
- package/misc.d.ts.map +1 -1
- package/misc.js +53 -62
- package/misc.js.map +1 -1
- package/nist.d.ts +31 -16
- package/nist.d.ts.map +1 -1
- package/nist.js +75 -64
- package/nist.js.map +1 -1
- package/package.json +20 -234
- package/secp256k1.d.ts +17 -30
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +59 -73
- package/secp256k1.js.map +1 -1
- package/src/abstract/bls.ts +207 -354
- package/src/abstract/curve.ts +25 -84
- package/src/abstract/edwards.ts +68 -193
- package/src/abstract/hash-to-curve.ts +71 -85
- package/src/abstract/modular.ts +150 -134
- package/src/abstract/montgomery.ts +28 -35
- package/src/abstract/oprf.ts +600 -0
- package/src/abstract/poseidon.ts +6 -8
- package/src/abstract/tower.ts +0 -3
- package/src/abstract/weierstrass.ts +203 -525
- package/src/bls12-381.ts +133 -139
- package/src/bn254.ts +69 -93
- package/src/ed25519.ts +106 -133
- package/src/ed448.ts +111 -138
- package/src/index.ts +19 -3
- package/src/misc.ts +68 -51
- package/src/nist.ts +77 -70
- package/src/secp256k1.ts +46 -81
- package/src/utils.ts +67 -137
- package/src/webcrypto.ts +403 -0
- package/utils.d.ts +31 -38
- package/utils.d.ts.map +1 -1
- package/utils.js +66 -185
- package/utils.js.map +1 -1
- package/webcrypto.d.ts +99 -0
- package/webcrypto.d.ts.map +1 -0
- package/webcrypto.js +256 -0
- package/webcrypto.js.map +1 -0
- package/_shortw_utils.d.ts +0 -19
- package/_shortw_utils.d.ts.map +0 -1
- package/_shortw_utils.js +0 -20
- package/_shortw_utils.js.map +0 -1
- package/abstract/utils.d.ts +0 -78
- package/abstract/utils.d.ts.map +0 -1
- package/abstract/utils.js +0 -73
- package/abstract/utils.js.map +0 -1
- package/esm/_shortw_utils.d.ts +0 -19
- package/esm/_shortw_utils.d.ts.map +0 -1
- package/esm/_shortw_utils.js +0 -16
- package/esm/_shortw_utils.js.map +0 -1
- package/esm/abstract/bls.d.ts +0 -190
- package/esm/abstract/bls.d.ts.map +0 -1
- package/esm/abstract/bls.js +0 -408
- package/esm/abstract/bls.js.map +0 -1
- package/esm/abstract/curve.d.ts +0 -231
- package/esm/abstract/curve.d.ts.map +0 -1
- package/esm/abstract/curve.js +0 -465
- package/esm/abstract/curve.js.map +0 -1
- package/esm/abstract/edwards.d.ts +0 -243
- package/esm/abstract/edwards.d.ts.map +0 -1
- package/esm/abstract/edwards.js +0 -627
- package/esm/abstract/edwards.js.map +0 -1
- package/esm/abstract/fft.d.ts +0 -122
- package/esm/abstract/fft.d.ts.map +0 -1
- package/esm/abstract/fft.js +0 -425
- package/esm/abstract/fft.js.map +0 -1
- package/esm/abstract/hash-to-curve.d.ts +0 -102
- package/esm/abstract/hash-to-curve.d.ts.map +0 -1
- package/esm/abstract/hash-to-curve.js +0 -203
- package/esm/abstract/hash-to-curve.js.map +0 -1
- package/esm/abstract/modular.d.ts +0 -171
- package/esm/abstract/modular.d.ts.map +0 -1
- package/esm/abstract/modular.js +0 -530
- package/esm/abstract/modular.js.map +0 -1
- package/esm/abstract/montgomery.d.ts +0 -30
- package/esm/abstract/montgomery.d.ts.map +0 -1
- package/esm/abstract/montgomery.js +0 -157
- package/esm/abstract/montgomery.js.map +0 -1
- package/esm/abstract/poseidon.d.ts +0 -68
- package/esm/abstract/poseidon.d.ts.map +0 -1
- package/esm/abstract/poseidon.js +0 -296
- package/esm/abstract/poseidon.js.map +0 -1
- package/esm/abstract/tower.d.ts +0 -95
- package/esm/abstract/tower.d.ts.map +0 -1
- package/esm/abstract/tower.js +0 -714
- package/esm/abstract/tower.js.map +0 -1
- package/esm/abstract/utils.d.ts +0 -78
- package/esm/abstract/utils.d.ts.map +0 -1
- package/esm/abstract/utils.js +0 -70
- package/esm/abstract/utils.js.map +0 -1
- package/esm/abstract/weierstrass.d.ts +0 -416
- package/esm/abstract/weierstrass.d.ts.map +0 -1
- package/esm/abstract/weierstrass.js +0 -1413
- package/esm/abstract/weierstrass.js.map +0 -1
- package/esm/bls12-381.d.ts +0 -16
- package/esm/bls12-381.d.ts.map +0 -1
- package/esm/bls12-381.js +0 -705
- package/esm/bls12-381.js.map +0 -1
- package/esm/bn254.d.ts +0 -18
- package/esm/bn254.d.ts.map +0 -1
- package/esm/bn254.js +0 -214
- package/esm/bn254.js.map +0 -1
- package/esm/ed25519.d.ts +0 -106
- package/esm/ed25519.d.ts.map +0 -1
- package/esm/ed25519.js +0 -467
- package/esm/ed25519.js.map +0 -1
- package/esm/ed448.d.ts +0 -100
- package/esm/ed448.d.ts.map +0 -1
- package/esm/ed448.js +0 -459
- package/esm/ed448.js.map +0 -1
- package/esm/index.d.ts +0 -2
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -17
- package/esm/index.js.map +0 -1
- package/esm/jubjub.d.ts +0 -12
- package/esm/jubjub.d.ts.map +0 -1
- package/esm/jubjub.js +0 -12
- package/esm/jubjub.js.map +0 -1
- package/esm/misc.d.ts +0 -19
- package/esm/misc.d.ts.map +0 -1
- package/esm/misc.js +0 -109
- package/esm/misc.js.map +0 -1
- package/esm/nist.d.ts +0 -21
- package/esm/nist.d.ts.map +0 -1
- package/esm/nist.js +0 -132
- package/esm/nist.js.map +0 -1
- package/esm/p256.d.ts +0 -16
- package/esm/p256.d.ts.map +0 -1
- package/esm/p256.js +0 -16
- package/esm/p256.js.map +0 -1
- package/esm/p384.d.ts +0 -16
- package/esm/p384.d.ts.map +0 -1
- package/esm/p384.js +0 -16
- package/esm/p384.js.map +0 -1
- package/esm/p521.d.ts +0 -16
- package/esm/p521.d.ts.map +0 -1
- package/esm/p521.js +0 -16
- package/esm/p521.js.map +0 -1
- package/esm/package.json +0 -4
- package/esm/pasta.d.ts +0 -10
- package/esm/pasta.d.ts.map +0 -1
- package/esm/pasta.js +0 -10
- package/esm/pasta.js.map +0 -1
- package/esm/secp256k1.d.ts +0 -89
- package/esm/secp256k1.d.ts.map +0 -1
- package/esm/secp256k1.js +0 -294
- package/esm/secp256k1.js.map +0 -1
- package/esm/utils.d.ts +0 -110
- package/esm/utils.d.ts.map +0 -1
- package/esm/utils.js +0 -322
- package/esm/utils.js.map +0 -1
- package/jubjub.d.ts +0 -12
- package/jubjub.d.ts.map +0 -1
- package/jubjub.js +0 -15
- package/jubjub.js.map +0 -1
- package/p256.d.ts +0 -16
- package/p256.d.ts.map +0 -1
- package/p256.js +0 -13
- package/p256.js.map +0 -1
- package/p384.d.ts +0 -16
- package/p384.d.ts.map +0 -1
- package/p384.js +0 -13
- package/p384.js.map +0 -1
- package/p521.d.ts +0 -16
- package/p521.d.ts.map +0 -1
- package/p521.js +0 -13
- package/p521.js.map +0 -1
- package/pasta.d.ts +0 -10
- package/pasta.d.ts.map +0 -1
- package/pasta.js +0 -13
- package/pasta.js.map +0 -1
- package/src/_shortw_utils.ts +0 -21
- package/src/abstract/utils.ts +0 -80
- package/src/jubjub.ts +0 -12
- package/src/p256.ts +0 -15
- package/src/p384.ts +0 -15
- package/src/p521.ts +0 -15
- package/src/package.json +0 -3
- package/src/pasta.ts +0 -9
package/abstract/montgomery.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.montgomery = montgomery;
|
|
4
1
|
/**
|
|
5
2
|
* Montgomery curve methods. It's not really whole montgomery curve,
|
|
6
3
|
* just bunch of very specific methods for X25519 / X448 from
|
|
@@ -8,25 +5,26 @@ exports.montgomery = montgomery;
|
|
|
8
5
|
* @module
|
|
9
6
|
*/
|
|
10
7
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
import { abytes, aInRange, bytesToNumberLE, copyBytes, numberToBytesLE, randomBytes, validateObject, } from "../utils.js";
|
|
9
|
+
import { createKeygen } from "./curve.js";
|
|
10
|
+
import { mod } from "./modular.js";
|
|
13
11
|
const _0n = BigInt(0);
|
|
14
12
|
const _1n = BigInt(1);
|
|
15
13
|
const _2n = BigInt(2);
|
|
16
14
|
function validateOpts(curve) {
|
|
17
|
-
(
|
|
15
|
+
validateObject(curve, {
|
|
18
16
|
adjustScalarBytes: 'function',
|
|
19
17
|
powPminus2: 'function',
|
|
20
18
|
});
|
|
21
19
|
return Object.freeze({ ...curve });
|
|
22
20
|
}
|
|
23
|
-
function montgomery(curveDef) {
|
|
21
|
+
export function montgomery(curveDef) {
|
|
24
22
|
const CURVE = validateOpts(curveDef);
|
|
25
23
|
const { P, type, adjustScalarBytes, powPminus2, randomBytes: rand } = CURVE;
|
|
26
24
|
const is25519 = type === 'x25519';
|
|
27
25
|
if (!is25519 && type !== 'x448')
|
|
28
26
|
throw new Error('invalid type');
|
|
29
|
-
const randomBytes_ = rand ||
|
|
27
|
+
const randomBytes_ = rand || randomBytes;
|
|
30
28
|
const montgomeryBits = is25519 ? 255 : 448;
|
|
31
29
|
const fieldLen = is25519 ? 32 : 56;
|
|
32
30
|
const Gu = is25519 ? BigInt(9) : BigInt(5);
|
|
@@ -43,13 +41,13 @@ function montgomery(curveDef) {
|
|
|
43
41
|
? BigInt(8) * _2n ** BigInt(251) - _1n
|
|
44
42
|
: BigInt(4) * _2n ** BigInt(445) - _1n;
|
|
45
43
|
const maxScalar = minScalar + maxAdded + _1n; // (inclusive)
|
|
46
|
-
const modP = (n) =>
|
|
44
|
+
const modP = (n) => mod(n, P);
|
|
47
45
|
const GuBytes = encodeU(Gu);
|
|
48
46
|
function encodeU(u) {
|
|
49
|
-
return
|
|
47
|
+
return numberToBytesLE(modP(u), fieldLen);
|
|
50
48
|
}
|
|
51
49
|
function decodeU(u) {
|
|
52
|
-
const _u = (
|
|
50
|
+
const _u = copyBytes(abytes(u, fieldLen, 'uCoordinate'));
|
|
53
51
|
// RFC: When receiving such an array, implementations of X25519
|
|
54
52
|
// (but not X448) MUST mask the most significant bit in the final byte.
|
|
55
53
|
if (is25519)
|
|
@@ -58,10 +56,10 @@ function montgomery(curveDef) {
|
|
|
58
56
|
// if they had been reduced modulo the field prime. The non-canonical
|
|
59
57
|
// values are 2^255 - 19 through 2^255 - 1 for X25519 and 2^448 - 2^224
|
|
60
58
|
// - 1 through 2^448 - 1 for X448.
|
|
61
|
-
return modP(
|
|
59
|
+
return modP(bytesToNumberLE(_u));
|
|
62
60
|
}
|
|
63
61
|
function decodeScalar(scalar) {
|
|
64
|
-
return
|
|
62
|
+
return bytesToNumberLE(adjustScalarBytes(copyBytes(abytes(scalar, fieldLen, 'scalar'))));
|
|
65
63
|
}
|
|
66
64
|
function scalarMult(scalar, u) {
|
|
67
65
|
const pu = montgomeryLadder(decodeU(u), decodeScalar(scalar));
|
|
@@ -76,6 +74,8 @@ function montgomery(curveDef) {
|
|
|
76
74
|
function scalarMultBase(scalar) {
|
|
77
75
|
return scalarMult(scalar, GuBytes);
|
|
78
76
|
}
|
|
77
|
+
const getPublicKey = scalarMultBase;
|
|
78
|
+
const getSharedSecret = scalarMult;
|
|
79
79
|
// cswap from RFC7748 "example code"
|
|
80
80
|
function cswap(swap, x_2, x_3) {
|
|
81
81
|
// dummy = mask(swap) AND (x_2 XOR x_3)
|
|
@@ -93,8 +93,8 @@ function montgomery(curveDef) {
|
|
|
93
93
|
* @returns new Point on Montgomery curve
|
|
94
94
|
*/
|
|
95
95
|
function montgomeryLadder(u, scalar) {
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
aInRange('u', u, _0n, P);
|
|
97
|
+
aInRange('scalar', scalar, minScalar, maxScalar);
|
|
98
98
|
const k = scalar;
|
|
99
99
|
const x_1 = u;
|
|
100
100
|
let x_2 = _1n;
|
|
@@ -135,26 +135,19 @@ function montgomery(curveDef) {
|
|
|
135
135
|
seed: fieldLen,
|
|
136
136
|
};
|
|
137
137
|
const randomSecretKey = (seed = randomBytes_(fieldLen)) => {
|
|
138
|
-
|
|
138
|
+
abytes(seed, lengths.seed, 'seed');
|
|
139
139
|
return seed;
|
|
140
140
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
randomSecretKey,
|
|
147
|
-
randomPrivateKey: randomSecretKey,
|
|
148
|
-
};
|
|
149
|
-
return {
|
|
150
|
-
keygen,
|
|
151
|
-
getSharedSecret: (secretKey, publicKey) => scalarMult(secretKey, publicKey),
|
|
152
|
-
getPublicKey: (secretKey) => scalarMultBase(secretKey),
|
|
141
|
+
const utils = { randomSecretKey };
|
|
142
|
+
return Object.freeze({
|
|
143
|
+
keygen: createKeygen(randomSecretKey, getPublicKey),
|
|
144
|
+
getSharedSecret,
|
|
145
|
+
getPublicKey,
|
|
153
146
|
scalarMult,
|
|
154
147
|
scalarMultBase,
|
|
155
148
|
utils,
|
|
156
149
|
GuBytes: GuBytes.slice(),
|
|
157
150
|
lengths,
|
|
158
|
-
};
|
|
151
|
+
});
|
|
159
152
|
}
|
|
160
153
|
//# sourceMappingURL=montgomery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"montgomery.js","sourceRoot":"","sources":["../src/abstract/montgomery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"montgomery.js","sourceRoot":"","sources":["../src/abstract/montgomery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,sEAAsE;AACtE,OAAO,EACL,MAAM,EACN,QAAQ,EACR,eAAe,EACf,SAAS,EACT,eAAe,EACf,WAAW,EACX,cAAc,GAEf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAqB,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,C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,CAAC,eAAe,EAAE,YAAY,CAAC;QACnD,eAAe;QACf,YAAY;QACZ,UAAU;QACV,cAAc;QACd,KAAK;QACL,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE;QACxB,OAAO;KACR,CAAsB,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 9497: Oblivious Pseudorandom Functions (OPRFs) Using Prime-Order Groups.
|
|
3
|
+
* https://www.rfc-editor.org/rfc/rfc9497
|
|
4
|
+
*
|
|
5
|
+
|
|
6
|
+
OPRF allows to interactively create an `Output = PRF(Input, serverSecretKey)`:
|
|
7
|
+
|
|
8
|
+
- Server cannot calculate Output by itself: it doesn't know Input
|
|
9
|
+
- Client cannot calculate Output by itself: it doesn't know server secretKey
|
|
10
|
+
- An attacker interception the communication can't restore Input/Output/serverSecretKey and can't
|
|
11
|
+
link Input to some value.
|
|
12
|
+
|
|
13
|
+
## Issues
|
|
14
|
+
|
|
15
|
+
- Low-entropy inputs (e.g. password '123') enable brute-forced dictionary attacks by the server
|
|
16
|
+
(solveable by domain separation in POPRF)
|
|
17
|
+
- High-level protocol needs to be constructed on top, because OPRF is low-level
|
|
18
|
+
|
|
19
|
+
## Use cases
|
|
20
|
+
|
|
21
|
+
1. **Password-Authenticated Key Exchange (PAKE):** Enables secure password login (e.g., OPAQUE)
|
|
22
|
+
without revealing the password to the server.
|
|
23
|
+
2. **Private Set Intersection (PSI):** Allows two parties to compute the intersection of their
|
|
24
|
+
private sets without revealing non-intersecting elements.
|
|
25
|
+
3. **Anonymous Credential Systems:** Supports issuance of anonymous, unlinkable credentials
|
|
26
|
+
(e.g., Privacy Pass) using blind OPRF evaluation.
|
|
27
|
+
4. **Private Information Retrieval (PIR):** Helps users query databases without revealing which
|
|
28
|
+
item they accessed.
|
|
29
|
+
5. **Encrypted Search / Secure Indexing:** Enables keyword search over encrypted data while keeping
|
|
30
|
+
queries private.
|
|
31
|
+
6. **Spam Prevention and Rate-Limiting:** Issues anonymous tokens to prevent abuse
|
|
32
|
+
(e.g., CAPTCHA bypass) without compromising user privacy.
|
|
33
|
+
|
|
34
|
+
## Modes
|
|
35
|
+
|
|
36
|
+
- OPRF: simple mode, client doesn't need to know server public key
|
|
37
|
+
- VOPRF: verifable mode, allows client to verify that server used secret key corresponding to known public key
|
|
38
|
+
- POPRF: partially oblivious mode, VOPRF + domain separation
|
|
39
|
+
|
|
40
|
+
There is also non-interactive mode (Evaluate) that supports creating Output in non-interactive mode with knowledge of secret key.
|
|
41
|
+
|
|
42
|
+
Flow:
|
|
43
|
+
- (once) Server generates secret and public keys, distributes public keys to clients
|
|
44
|
+
- deterministically: `deriveKeyPair` or just random: `generateKeyPair`
|
|
45
|
+
- Client blinds input: `blind(secretInput)`
|
|
46
|
+
- Server evaluates blinded input: `blindEvaluate` generated by client, sends result to client
|
|
47
|
+
- Client creates output using result of evaluation via 'finalize'
|
|
48
|
+
|
|
49
|
+
* @module
|
|
50
|
+
*/
|
|
51
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
52
|
+
import { randomBytes } from '../utils.ts';
|
|
53
|
+
import { type CurvePoint, type CurvePointCons } from './curve.ts';
|
|
54
|
+
import { type H2CDSTOpts } from './hash-to-curve.ts';
|
|
55
|
+
export type PointBytes = Uint8Array;
|
|
56
|
+
export type ScalarBytes = Uint8Array;
|
|
57
|
+
export type Bytes = Uint8Array;
|
|
58
|
+
export type RNG = typeof randomBytes;
|
|
59
|
+
export type OPRFOpts<P extends CurvePoint<any, P>> = {
|
|
60
|
+
name: string;
|
|
61
|
+
Point: CurvePointCons<P>;
|
|
62
|
+
hash(msg: Bytes): Bytes;
|
|
63
|
+
hashToScalar(msg: Uint8Array, options: H2CDSTOpts): bigint;
|
|
64
|
+
hashToGroup(msg: Uint8Array, options: H2CDSTOpts): P;
|
|
65
|
+
};
|
|
66
|
+
export type OPRFKeys = {
|
|
67
|
+
secretKey: ScalarBytes;
|
|
68
|
+
publicKey: PointBytes;
|
|
69
|
+
};
|
|
70
|
+
export type OPRFBlind = {
|
|
71
|
+
blind: Uint8Array;
|
|
72
|
+
blinded: Uint8Array;
|
|
73
|
+
};
|
|
74
|
+
export type OPRFBlindEval = {
|
|
75
|
+
evaluated: PointBytes;
|
|
76
|
+
proof: Bytes;
|
|
77
|
+
};
|
|
78
|
+
export type OPRFBlindEvalBatch = {
|
|
79
|
+
evaluated: PointBytes[];
|
|
80
|
+
proof: Bytes;
|
|
81
|
+
};
|
|
82
|
+
export type OPRFFinalizeItem = {
|
|
83
|
+
input: Bytes;
|
|
84
|
+
blind: ScalarBytes;
|
|
85
|
+
evaluated: PointBytes;
|
|
86
|
+
blinded: PointBytes;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Represents a full OPRF ciphersuite implementation according to RFC 9497.
|
|
90
|
+
* This object bundles the three protocol variants (OPRF, VOPRF, POPRF) for a specific
|
|
91
|
+
* prime-order group and hash function combination.
|
|
92
|
+
*
|
|
93
|
+
* @see https://www.rfc-editor.org/rfc/rfc9497.html
|
|
94
|
+
*/
|
|
95
|
+
export type OPRF = {
|
|
96
|
+
/**
|
|
97
|
+
* The unique identifier for the ciphersuite, e.g., "ristretto255-SHA512".
|
|
98
|
+
* This name is used for domain separation to prevent cross-protocol attacks.
|
|
99
|
+
*/
|
|
100
|
+
readonly name: string;
|
|
101
|
+
/**
|
|
102
|
+
* The base Oblivious Pseudorandom Function (OPRF) mode (mode 0x00).
|
|
103
|
+
* This is a two-party protocol between a client and a server to compute F(k, x)
|
|
104
|
+
* where 'k' is the server's key and 'x' is the client's input.
|
|
105
|
+
*
|
|
106
|
+
* The client learns the output F(k, x) but nothing about 'k'.
|
|
107
|
+
* The server learns nothing about 'x' or F(k, x).
|
|
108
|
+
* This mode is NOT verifiable; the client cannot prove the server used a specific key.
|
|
109
|
+
*/
|
|
110
|
+
readonly oprf: {
|
|
111
|
+
/**
|
|
112
|
+
* (Server-side) Generates a new random private/public key pair for the server.
|
|
113
|
+
* @returns A new key pair.
|
|
114
|
+
*/
|
|
115
|
+
generateKeyPair(): OPRFKeys;
|
|
116
|
+
/**
|
|
117
|
+
* (Server-side) Deterministically derives a private/public key pair from a seed.
|
|
118
|
+
* @param seed A 32-byte cryptographically secure random seed.
|
|
119
|
+
* @param keyInfo An optional byte string for domain separation.
|
|
120
|
+
* @returns The derived key pair.
|
|
121
|
+
*/
|
|
122
|
+
deriveKeyPair(seed: Bytes, keyInfo: Bytes): OPRFKeys;
|
|
123
|
+
/**
|
|
124
|
+
* (Client-side) The first step of the protocol. The client blinds its private input.
|
|
125
|
+
* @param input The client's private input bytes.
|
|
126
|
+
* @param rng An optional cryptographically secure random number generator.
|
|
127
|
+
* @returns An object containing the `blind` scalar (which the client MUST keep secret)
|
|
128
|
+
* and the `blinded` element (which the client sends to the server).
|
|
129
|
+
*/
|
|
130
|
+
blind(input: Bytes, rng?: RNG): OPRFBlind;
|
|
131
|
+
/**
|
|
132
|
+
* (Server-side) The second step. The server evaluates the client's blinded element
|
|
133
|
+
* using its secret key.
|
|
134
|
+
* @param secretKey The server's private key.
|
|
135
|
+
* @param blinded The blinded group element received from the client.
|
|
136
|
+
* @returns The evaluated group element, to be sent back to the client.
|
|
137
|
+
*/
|
|
138
|
+
blindEvaluate(secretKey: ScalarBytes, blinded: PointBytes): PointBytes;
|
|
139
|
+
/**
|
|
140
|
+
* (Client-side) The final step. The client unblinds the server's response to
|
|
141
|
+
* compute the final OPRF output.
|
|
142
|
+
* @param input The original private input from the `blind` step.
|
|
143
|
+
* @param blind The secret scalar from the `blind` step.
|
|
144
|
+
* @param evaluated The evaluated group element received from the server.
|
|
145
|
+
* @returns The final OPRF output, `Hash(len(input)||input||len(unblinded)||unblinded||"Finalize")`.
|
|
146
|
+
*/
|
|
147
|
+
finalize(input: Bytes, blind: ScalarBytes, evaluated: PointBytes): Bytes;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* The Verifiable Oblivious Pseudorandom Function (VOPRF) mode (mode 0x01).
|
|
151
|
+
* This mode extends the base OPRF by providing a proof that the server used the
|
|
152
|
+
* secret key corresponding to its known public key.
|
|
153
|
+
*/
|
|
154
|
+
readonly voprf: {
|
|
155
|
+
/** (Server-side) Generates a key pair for the VOPRF mode. */
|
|
156
|
+
generateKeyPair(): OPRFKeys;
|
|
157
|
+
/** (Server-side) Deterministically derives a key pair for the VOPRF mode. */
|
|
158
|
+
deriveKeyPair(seed: Bytes, keyInfo: Bytes): OPRFKeys;
|
|
159
|
+
/** (Client-side) Blinds the client's private input for the VOPRF protocol. */
|
|
160
|
+
blind(input: Bytes, rng?: RNG): OPRFBlind;
|
|
161
|
+
/**
|
|
162
|
+
* (Server-side) Evaluates the client's blinded element and generates a DLEQ proof
|
|
163
|
+
* of correctness.
|
|
164
|
+
* @param secretKey The server's private key.
|
|
165
|
+
* @param publicKey The server's public key, used in proof generation.
|
|
166
|
+
* @param blinded The blinded group element received from the client.
|
|
167
|
+
* @param rng An optional cryptographically secure random number generator for the proof.
|
|
168
|
+
* @returns The evaluated element and a proof of correct computation.
|
|
169
|
+
*/
|
|
170
|
+
blindEvaluate(secretKey: ScalarBytes, publicKey: PointBytes, blinded: PointBytes, rng?: RNG): OPRFBlindEval;
|
|
171
|
+
/**
|
|
172
|
+
* (Server-side) An optimized batch version of `blindEvaluate`. It evaluates multiple
|
|
173
|
+
* blinded elements and produces a single, constant-size proof for the entire batch,
|
|
174
|
+
* amortizing the cost of proof generation.
|
|
175
|
+
* @param secretKey The server's private key.
|
|
176
|
+
* @param publicKey The server's public key.
|
|
177
|
+
* @param blinded An array of blinded group elements from one or more clients.
|
|
178
|
+
* @param rng An optional cryptographically secure random number generator for the proof.
|
|
179
|
+
* @returns An array of evaluated elements and a single proof for the batch.
|
|
180
|
+
*/
|
|
181
|
+
blindEvaluateBatch(secretKey: ScalarBytes, publicKey: PointBytes, blinded: PointBytes[], rng?: RNG): OPRFBlindEvalBatch;
|
|
182
|
+
/**
|
|
183
|
+
* (Client-side) The final step. The client verifies the server's proof, and if valid,
|
|
184
|
+
* unblinds the result to compute the final VOPRF output.
|
|
185
|
+
* @param input The original private input.
|
|
186
|
+
* @param blind The secret scalar from the `blind` step.
|
|
187
|
+
* @param evaluated The evaluated element from the server.
|
|
188
|
+
* @param blinded The blinded element sent to the server (needed for proof verification).
|
|
189
|
+
* @param publicKey The server's public key against which the proof is verified.
|
|
190
|
+
* @param proof The DLEQ proof from the server.
|
|
191
|
+
* @returns The final VOPRF output.
|
|
192
|
+
* @throws If the proof verification fails.
|
|
193
|
+
*/
|
|
194
|
+
finalize(input: Bytes, blind: ScalarBytes, evaluated: PointBytes, blinded: PointBytes, publicKey: PointBytes, proof: Bytes): Bytes;
|
|
195
|
+
/**
|
|
196
|
+
* (Client-side) The batch-aware version of `finalize`. It verifies a single batch proof
|
|
197
|
+
* against a list of corresponding inputs and outputs.
|
|
198
|
+
* @param items An array of objects, each containing the parameters for a single finalization.
|
|
199
|
+
* @param publicKey The server's public key.
|
|
200
|
+
* @param proof The single DLEQ proof for the entire batch.
|
|
201
|
+
* @returns An array of final VOPRF outputs, one for each item in the input.
|
|
202
|
+
* @throws If the proof verification fails.
|
|
203
|
+
*/
|
|
204
|
+
finalizeBatch(items: OPRFFinalizeItem[], publicKey: PointBytes, proof: Bytes): Bytes[];
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* A factory for the Partially Oblivious Pseudorandom Function (POPRF) mode (mode 0x02).
|
|
208
|
+
* This mode extends VOPRF to include a public `info` parameter, known to both client and
|
|
209
|
+
* server, which is cryptographically bound to the final output.
|
|
210
|
+
* This is useful for domain separation at the application level.
|
|
211
|
+
* @param info A public byte string to be mixed into the computation.
|
|
212
|
+
* @returns An object with the POPRF protocol functions.
|
|
213
|
+
*/
|
|
214
|
+
readonly poprf: (info: Bytes) => {
|
|
215
|
+
/** (Server-side) Generates a key pair for the POPRF mode. */
|
|
216
|
+
generateKeyPair(): OPRFKeys;
|
|
217
|
+
/** (Server-side) Deterministically derives a key pair for the POPRF mode. */
|
|
218
|
+
deriveKeyPair(seed: Bytes, keyInfo: Bytes): OPRFKeys;
|
|
219
|
+
/**
|
|
220
|
+
* (Client-side) Blinds the client's private input and computes the "tweaked key".
|
|
221
|
+
* The tweaked key is a public value derived from the server's public key and the public `info`.
|
|
222
|
+
* @param input The client's private input.
|
|
223
|
+
* @param publicKey The server's public key.
|
|
224
|
+
* @param rng An optional cryptographically secure random number generator.
|
|
225
|
+
* @returns The `blind`, `blinded` element, and the `tweakedKey` which the client uses for verification.
|
|
226
|
+
*/
|
|
227
|
+
blind(input: Bytes, publicKey: PointBytes, rng?: RNG): OPRFBlind & {
|
|
228
|
+
tweakedKey: PointBytes;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* (Server-side) Evaluates the blinded element using a key derived from its secret key and the public `info`.
|
|
232
|
+
* It generates a DLEQ proof against the tweaked key.
|
|
233
|
+
* @param secretKey The server's private key.
|
|
234
|
+
* @param blinded The blinded element from the client.
|
|
235
|
+
* @param rng An optional RNG for the proof.
|
|
236
|
+
* @returns The evaluated element and a proof of correct computation.
|
|
237
|
+
*/
|
|
238
|
+
blindEvaluate(secretKey: ScalarBytes, blinded: PointBytes, rng?: RNG): OPRFBlindEval;
|
|
239
|
+
/**
|
|
240
|
+
* (Server-side) A batch-aware version of `blindEvaluate` for the POPRF mode.
|
|
241
|
+
* @param secretKey The server's private key.
|
|
242
|
+
* @param blinded An array of blinded elements.
|
|
243
|
+
* @param rng An optional RNG for the proof.
|
|
244
|
+
* @returns An array of evaluated elements and a single proof for the batch.
|
|
245
|
+
*/
|
|
246
|
+
blindEvaluateBatch(secretKey: ScalarBytes, blinded: PointBytes[], rng: RNG): OPRFBlindEvalBatch;
|
|
247
|
+
/**
|
|
248
|
+
* (Client-side) A batch-aware version of `finalize` for the POPRF mode.
|
|
249
|
+
* It verifies the proof against the tweaked key.
|
|
250
|
+
* @param items An array containing the parameters for each finalization.
|
|
251
|
+
* @param proof The single DLEQ proof for the batch.
|
|
252
|
+
* @param tweakedKey The tweaked key corresponding to the proof (all items must share the same `info` and `publicKey`).
|
|
253
|
+
* @returns An array of final POPRF outputs.
|
|
254
|
+
* @throws If proof verification fails.
|
|
255
|
+
*/
|
|
256
|
+
finalizeBatch(items: OPRFFinalizeItem[], proof: Bytes, tweakedKey: PointBytes): Bytes[];
|
|
257
|
+
/**
|
|
258
|
+
* (Client-side) Finalizes the POPRF protocol. It verifies the server's proof against the
|
|
259
|
+
* `tweakedKey` computed in the `blind` step. The final output is bound to the public `info`.
|
|
260
|
+
* @param input The original private input.
|
|
261
|
+
* @param blind The secret scalar.
|
|
262
|
+
* @param evaluated The evaluated element from the server.
|
|
263
|
+
* @param blinded The blinded element sent to the server.
|
|
264
|
+
* @param proof The DLEQ proof from the server.
|
|
265
|
+
* @param tweakedKey The public tweaked key computed by the client during the `blind` step.
|
|
266
|
+
* @returns The final POPRF output.
|
|
267
|
+
* @throws If proof verification fails.
|
|
268
|
+
*/
|
|
269
|
+
finalize(input: Bytes, blind: ScalarBytes, evaluated: PointBytes, blinded: PointBytes, proof: Bytes, tweakedKey: PointBytes): Bytes;
|
|
270
|
+
/**
|
|
271
|
+
* A non-interactive evaluation function for an entity that knows all inputs.
|
|
272
|
+
* Computes the final POPRF output directly. Useful for testing or specific applications
|
|
273
|
+
* where the server needs to compute the output for a known input.
|
|
274
|
+
* @param secretKey The server's private key.
|
|
275
|
+
* @param input The client's private input.
|
|
276
|
+
* @returns The final POPRF output.
|
|
277
|
+
*/
|
|
278
|
+
evaluate(secretKey: ScalarBytes, input: Bytes): Bytes;
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
export declare function createORPF<P extends CurvePoint<any, P>>(opts: OPRFOpts<P>): OPRF;
|
|
282
|
+
//# sourceMappingURL=oprf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oprf.d.ts","sourceRoot":"","sources":["../src/abstract/oprf.ts"],"names":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