@taceo/oprf-client 0.8.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 +244 -0
- package/dist/index.cjs +550 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +207 -0
- package/dist/index.d.ts +207 -0
- package/dist/index.js +521 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { PartialDLogEqualityCommitments, PartialDLogCommitmentsShamir, DLogCommitmentsShamir, DLogProofShareShamir, DLogEqualityProof } from '@taceo/oprf-core';
|
|
2
|
+
import { AffinePoint } from '@noble/curves/abstract/curve.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wire and API types for OPRF client.
|
|
6
|
+
* Matches nullifier-oracle-service oprf-types (OprfRequest, OprfResponse, etc.).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Affine point as JSON: a 2-element array [x, y] of decimal strings.
|
|
11
|
+
* Matches Rust ark_serde_compat::babyjubjub::serialize_affine / deserialize_affine.
|
|
12
|
+
*/
|
|
13
|
+
type AffinePointWire = [string, string];
|
|
14
|
+
/** DLogCommitmentsShamir wire (server expects snake_case: contributing_parties). */
|
|
15
|
+
interface DLogCommitmentsShamirWire {
|
|
16
|
+
c: AffinePointWire;
|
|
17
|
+
d1: AffinePointWire;
|
|
18
|
+
d2: AffinePointWire;
|
|
19
|
+
e1: AffinePointWire;
|
|
20
|
+
e2: AffinePointWire;
|
|
21
|
+
contributing_parties: number[];
|
|
22
|
+
}
|
|
23
|
+
/** OprfPublicKeyWithEpoch (internal: affine points). */
|
|
24
|
+
interface OprfPublicKeyWithEpoch {
|
|
25
|
+
key: AffinePoint<bigint>;
|
|
26
|
+
epoch: number;
|
|
27
|
+
}
|
|
28
|
+
/** OprfRequest (internal: affine for blinded_query). */
|
|
29
|
+
interface OprfRequest<Auth = unknown> {
|
|
30
|
+
request_id: string;
|
|
31
|
+
blinded_query: AffinePoint<bigint>;
|
|
32
|
+
auth: Auth;
|
|
33
|
+
}
|
|
34
|
+
/** OprfResponse (internal: affine points). */
|
|
35
|
+
interface OprfResponse {
|
|
36
|
+
commitments: PartialDLogEqualityCommitments;
|
|
37
|
+
party_id: number;
|
|
38
|
+
oprf_pub_key_with_epoch: OprfPublicKeyWithEpoch;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* WebSocket session for a single OPRF service connection.
|
|
43
|
+
* Takes a pre-built WS URL (see uri.ts). Errors are NodeError variants.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Thin WebSocket session: connect, send JSON, receive JSON, handle close.
|
|
48
|
+
* Uses text (JSON) frames. Browser WebSocket cannot set headers; version is sent as query param.
|
|
49
|
+
* All errors are thrown as NodeError.
|
|
50
|
+
*/
|
|
51
|
+
declare class WebSocketSession {
|
|
52
|
+
private ws;
|
|
53
|
+
private readonly service;
|
|
54
|
+
private constructor();
|
|
55
|
+
get serviceUrl(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Open a new WebSocket to the given pre-built WS URL.
|
|
58
|
+
* Connect errors throw NodeError('WsError', ...).
|
|
59
|
+
*/
|
|
60
|
+
static connect(url: string): Promise<WebSocketSession>;
|
|
61
|
+
/** Send a JSON-serializable message as text frame. Throws NodeError('WsError') on failure. */
|
|
62
|
+
send<T extends object>(msg: T): void;
|
|
63
|
+
/**
|
|
64
|
+
* Read next message. Returns text data.
|
|
65
|
+
* Rejects with NodeError on:
|
|
66
|
+
* - Binary frame → UnexpectedMessage
|
|
67
|
+
* - Non-normal close → ServiceError
|
|
68
|
+
* - Normal/1005 close → UnexpectedMessage('Server closed websocket')
|
|
69
|
+
* - Error event → WsError
|
|
70
|
+
* - null/end → UnexpectedMessage('Server closed connection')
|
|
71
|
+
*/
|
|
72
|
+
private readNext;
|
|
73
|
+
/** Read and parse OprfResponse. Parse errors → NodeError('UnexpectedMessage'). */
|
|
74
|
+
readOprfResponse(): Promise<OprfResponse>;
|
|
75
|
+
/** Read and parse DLogProofShareShamir. Parse errors → NodeError('UnexpectedMessage'). */
|
|
76
|
+
readProofShare(): Promise<{
|
|
77
|
+
value: bigint;
|
|
78
|
+
}>;
|
|
79
|
+
/** Send challenge (DLogCommitmentsShamir wire). */
|
|
80
|
+
sendChallenge(wire: DLogCommitmentsShamirWire): void;
|
|
81
|
+
/** Gracefully close with normal code. */
|
|
82
|
+
close(): void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Session management: initSessions (parallel connect, collect by epoch to threshold),
|
|
87
|
+
* finishSessions (send challenge, collect proof shares). Mirrors Rust oprf-client sessions.
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
interface OprfSessions {
|
|
91
|
+
readonly ws: WebSocketSession[];
|
|
92
|
+
readonly partyIds: number[];
|
|
93
|
+
readonly commitments: PartialDLogCommitmentsShamir[];
|
|
94
|
+
readonly oprfPublicKeys: AffinePointLike[];
|
|
95
|
+
readonly epoch: number;
|
|
96
|
+
}
|
|
97
|
+
/** Internal: we only need key as affine for verification. */
|
|
98
|
+
interface AffinePointLike {
|
|
99
|
+
x: bigint;
|
|
100
|
+
y: bigint;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Open WebSockets to each service in parallel, send oprfRequest, collect OprfResponse.
|
|
104
|
+
* Services must be pre-built WS URLs (see toOprfUri / toOprfUriMany).
|
|
105
|
+
* Group by epoch; when an epoch has >= threshold responses with distinct party_id, return those sessions (sorted by party_id).
|
|
106
|
+
* On failure: throws NodeError[] (caller wraps via aggregateError).
|
|
107
|
+
*/
|
|
108
|
+
declare function initSessions<Auth>(services: string[], threshold: number, oprfRequest: OprfRequest<Auth>): Promise<OprfSessions>;
|
|
109
|
+
/**
|
|
110
|
+
* Send the same challenge to each session, read proof share, then close.
|
|
111
|
+
* Returns proof shares in the same order as sessions.ws.
|
|
112
|
+
* Errors bubble up as NodeError (thrown from ws methods).
|
|
113
|
+
*/
|
|
114
|
+
declare function finishSessions(sessions: OprfSessions, challenge: DLogCommitmentsShamir): Promise<DLogProofShareShamir[]>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* High-level client: generateChallengeRequest, verifyDlogEquality, distributedOprf.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
interface VerifiableOprfOutput {
|
|
121
|
+
output: bigint;
|
|
122
|
+
dlogProof: DLogEqualityProof;
|
|
123
|
+
blindedRequest: AffinePoint<bigint>;
|
|
124
|
+
blindedResponse: AffinePoint<bigint>;
|
|
125
|
+
unblindedResponse: AffinePoint<bigint>;
|
|
126
|
+
oprfPublicKey: AffinePoint<bigint>;
|
|
127
|
+
epoch: number;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build challenge from sessions: contributingParties = party_id + 1 per party, then combineCommitments.
|
|
131
|
+
*/
|
|
132
|
+
declare function generateChallengeRequest(sessions: OprfSessions): DLogCommitmentsShamir;
|
|
133
|
+
/**
|
|
134
|
+
* Combine proof shares, verify DLog proof. Throws OprfClientError if invalid.
|
|
135
|
+
*/
|
|
136
|
+
declare function verifyDlogEquality(requestId: string, oprfPublicKey: AffinePoint<bigint>, blindedRequest: AffinePoint<bigint>, proofShares: DLogProofShareShamir[], challenge: DLogCommitmentsShamir): DLogEqualityProof;
|
|
137
|
+
interface DistributedOprfOptions<Auth = unknown> {
|
|
138
|
+
/** Auth payload sent in OprfRequest (must be JSON-serializable). */
|
|
139
|
+
auth?: Auth;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Full distributed OPRF: blind → init sessions → challenge → finish → verify → unblind → finalize.
|
|
143
|
+
* Services must be pre-built WS URLs (use toOprfUri / toOprfUriMany).
|
|
144
|
+
*/
|
|
145
|
+
declare function distributedOprf(services: string[], threshold: number, query: bigint, domainSeparator: bigint, options?: DistributedOprfOptions): Promise<VerifiableOprfOutput>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Client error types matching the Rust oprf-client Error enum.
|
|
149
|
+
* Two-tier model: NodeError (per-node) and OprfClientError (protocol-level).
|
|
150
|
+
*/
|
|
151
|
+
/**
|
|
152
|
+
* Application-level error received in a WebSocket close frame from a node.
|
|
153
|
+
*/
|
|
154
|
+
declare class ServiceError extends Error {
|
|
155
|
+
readonly errorCode: number;
|
|
156
|
+
readonly msg?: string;
|
|
157
|
+
constructor(errorCode: number, msg?: string);
|
|
158
|
+
}
|
|
159
|
+
type NodeErrorCode = 'ServiceError' | 'WsError' | 'UnexpectedMessage' | 'Unknown';
|
|
160
|
+
/**
|
|
161
|
+
* Per-node error, discriminated by `code`.
|
|
162
|
+
*/
|
|
163
|
+
declare class NodeError extends Error {
|
|
164
|
+
readonly code: NodeErrorCode;
|
|
165
|
+
readonly reason?: string;
|
|
166
|
+
readonly cause?: Error;
|
|
167
|
+
readonly serviceError?: ServiceError;
|
|
168
|
+
constructor(code: NodeErrorCode, opts?: {
|
|
169
|
+
reason?: string;
|
|
170
|
+
cause?: Error;
|
|
171
|
+
serviceError?: ServiceError;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
declare function isNodeError(err: unknown): err is NodeError;
|
|
175
|
+
type OprfClientErrorCode = 'NonUniqueServices' | 'InvalidDLogProof' | 'InconsistentOprfPublicKeys' | 'ThresholdServiceError' | 'Networking' | 'UnexpectedMessage' | 'CannotFinishSession' | 'NodeErrorDisagreement' | 'Unknown';
|
|
176
|
+
interface OprfClientErrorDetails {
|
|
177
|
+
nodeErrors?: NodeError[];
|
|
178
|
+
serviceError?: ServiceError;
|
|
179
|
+
cause?: NodeError;
|
|
180
|
+
networkingErrors?: Error[];
|
|
181
|
+
}
|
|
182
|
+
declare class OprfClientError extends Error {
|
|
183
|
+
readonly code: OprfClientErrorCode;
|
|
184
|
+
readonly details?: OprfClientErrorDetails;
|
|
185
|
+
constructor(code: OprfClientErrorCode, message: string, details?: OprfClientErrorDetails);
|
|
186
|
+
}
|
|
187
|
+
declare function isOprfClientError(err: unknown): err is OprfClientError;
|
|
188
|
+
/**
|
|
189
|
+
* Aggregate per-node errors into a protocol-level OprfClientError.
|
|
190
|
+
* Mirrors Rust oprf-client aggregate_error logic:
|
|
191
|
+
* - >= threshold ServiceErrors with same code → ThresholdServiceError
|
|
192
|
+
* - >= threshold UnexpectedMessage with same reason → UnexpectedMessage
|
|
193
|
+
* - >= threshold WsErrors → Networking
|
|
194
|
+
* - Otherwise → NodeErrorDisagreement
|
|
195
|
+
*/
|
|
196
|
+
declare function aggregateError(threshold: number, errors: NodeError[]): OprfClientError;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* URI construction helpers for OPRF service endpoints.
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* Build a WebSocket URL for a single OPRF service.
|
|
203
|
+
* http → ws, https → wss. Appends /api/{auth_module_name}/oprf?version={clientVersion}.
|
|
204
|
+
*/
|
|
205
|
+
declare function toOprfUri(service: string, auth_module_name: string, clientVersion?: string): string;
|
|
206
|
+
|
|
207
|
+
export { NodeError, type NodeErrorCode, OprfClientError, type OprfClientErrorCode, type OprfPublicKeyWithEpoch, type OprfRequest, type OprfResponse, type OprfSessions, ServiceError, type VerifiableOprfOutput, aggregateError, distributedOprf, finishSessions, generateChallengeRequest, initSessions, isNodeError, isOprfClientError, toOprfUri, verifyDlogEquality };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { PartialDLogEqualityCommitments, PartialDLogCommitmentsShamir, DLogCommitmentsShamir, DLogProofShareShamir, DLogEqualityProof } from '@taceo/oprf-core';
|
|
2
|
+
import { AffinePoint } from '@noble/curves/abstract/curve.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wire and API types for OPRF client.
|
|
6
|
+
* Matches nullifier-oracle-service oprf-types (OprfRequest, OprfResponse, etc.).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Affine point as JSON: a 2-element array [x, y] of decimal strings.
|
|
11
|
+
* Matches Rust ark_serde_compat::babyjubjub::serialize_affine / deserialize_affine.
|
|
12
|
+
*/
|
|
13
|
+
type AffinePointWire = [string, string];
|
|
14
|
+
/** DLogCommitmentsShamir wire (server expects snake_case: contributing_parties). */
|
|
15
|
+
interface DLogCommitmentsShamirWire {
|
|
16
|
+
c: AffinePointWire;
|
|
17
|
+
d1: AffinePointWire;
|
|
18
|
+
d2: AffinePointWire;
|
|
19
|
+
e1: AffinePointWire;
|
|
20
|
+
e2: AffinePointWire;
|
|
21
|
+
contributing_parties: number[];
|
|
22
|
+
}
|
|
23
|
+
/** OprfPublicKeyWithEpoch (internal: affine points). */
|
|
24
|
+
interface OprfPublicKeyWithEpoch {
|
|
25
|
+
key: AffinePoint<bigint>;
|
|
26
|
+
epoch: number;
|
|
27
|
+
}
|
|
28
|
+
/** OprfRequest (internal: affine for blinded_query). */
|
|
29
|
+
interface OprfRequest<Auth = unknown> {
|
|
30
|
+
request_id: string;
|
|
31
|
+
blinded_query: AffinePoint<bigint>;
|
|
32
|
+
auth: Auth;
|
|
33
|
+
}
|
|
34
|
+
/** OprfResponse (internal: affine points). */
|
|
35
|
+
interface OprfResponse {
|
|
36
|
+
commitments: PartialDLogEqualityCommitments;
|
|
37
|
+
party_id: number;
|
|
38
|
+
oprf_pub_key_with_epoch: OprfPublicKeyWithEpoch;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* WebSocket session for a single OPRF service connection.
|
|
43
|
+
* Takes a pre-built WS URL (see uri.ts). Errors are NodeError variants.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Thin WebSocket session: connect, send JSON, receive JSON, handle close.
|
|
48
|
+
* Uses text (JSON) frames. Browser WebSocket cannot set headers; version is sent as query param.
|
|
49
|
+
* All errors are thrown as NodeError.
|
|
50
|
+
*/
|
|
51
|
+
declare class WebSocketSession {
|
|
52
|
+
private ws;
|
|
53
|
+
private readonly service;
|
|
54
|
+
private constructor();
|
|
55
|
+
get serviceUrl(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Open a new WebSocket to the given pre-built WS URL.
|
|
58
|
+
* Connect errors throw NodeError('WsError', ...).
|
|
59
|
+
*/
|
|
60
|
+
static connect(url: string): Promise<WebSocketSession>;
|
|
61
|
+
/** Send a JSON-serializable message as text frame. Throws NodeError('WsError') on failure. */
|
|
62
|
+
send<T extends object>(msg: T): void;
|
|
63
|
+
/**
|
|
64
|
+
* Read next message. Returns text data.
|
|
65
|
+
* Rejects with NodeError on:
|
|
66
|
+
* - Binary frame → UnexpectedMessage
|
|
67
|
+
* - Non-normal close → ServiceError
|
|
68
|
+
* - Normal/1005 close → UnexpectedMessage('Server closed websocket')
|
|
69
|
+
* - Error event → WsError
|
|
70
|
+
* - null/end → UnexpectedMessage('Server closed connection')
|
|
71
|
+
*/
|
|
72
|
+
private readNext;
|
|
73
|
+
/** Read and parse OprfResponse. Parse errors → NodeError('UnexpectedMessage'). */
|
|
74
|
+
readOprfResponse(): Promise<OprfResponse>;
|
|
75
|
+
/** Read and parse DLogProofShareShamir. Parse errors → NodeError('UnexpectedMessage'). */
|
|
76
|
+
readProofShare(): Promise<{
|
|
77
|
+
value: bigint;
|
|
78
|
+
}>;
|
|
79
|
+
/** Send challenge (DLogCommitmentsShamir wire). */
|
|
80
|
+
sendChallenge(wire: DLogCommitmentsShamirWire): void;
|
|
81
|
+
/** Gracefully close with normal code. */
|
|
82
|
+
close(): void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Session management: initSessions (parallel connect, collect by epoch to threshold),
|
|
87
|
+
* finishSessions (send challenge, collect proof shares). Mirrors Rust oprf-client sessions.
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
interface OprfSessions {
|
|
91
|
+
readonly ws: WebSocketSession[];
|
|
92
|
+
readonly partyIds: number[];
|
|
93
|
+
readonly commitments: PartialDLogCommitmentsShamir[];
|
|
94
|
+
readonly oprfPublicKeys: AffinePointLike[];
|
|
95
|
+
readonly epoch: number;
|
|
96
|
+
}
|
|
97
|
+
/** Internal: we only need key as affine for verification. */
|
|
98
|
+
interface AffinePointLike {
|
|
99
|
+
x: bigint;
|
|
100
|
+
y: bigint;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Open WebSockets to each service in parallel, send oprfRequest, collect OprfResponse.
|
|
104
|
+
* Services must be pre-built WS URLs (see toOprfUri / toOprfUriMany).
|
|
105
|
+
* Group by epoch; when an epoch has >= threshold responses with distinct party_id, return those sessions (sorted by party_id).
|
|
106
|
+
* On failure: throws NodeError[] (caller wraps via aggregateError).
|
|
107
|
+
*/
|
|
108
|
+
declare function initSessions<Auth>(services: string[], threshold: number, oprfRequest: OprfRequest<Auth>): Promise<OprfSessions>;
|
|
109
|
+
/**
|
|
110
|
+
* Send the same challenge to each session, read proof share, then close.
|
|
111
|
+
* Returns proof shares in the same order as sessions.ws.
|
|
112
|
+
* Errors bubble up as NodeError (thrown from ws methods).
|
|
113
|
+
*/
|
|
114
|
+
declare function finishSessions(sessions: OprfSessions, challenge: DLogCommitmentsShamir): Promise<DLogProofShareShamir[]>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* High-level client: generateChallengeRequest, verifyDlogEquality, distributedOprf.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
interface VerifiableOprfOutput {
|
|
121
|
+
output: bigint;
|
|
122
|
+
dlogProof: DLogEqualityProof;
|
|
123
|
+
blindedRequest: AffinePoint<bigint>;
|
|
124
|
+
blindedResponse: AffinePoint<bigint>;
|
|
125
|
+
unblindedResponse: AffinePoint<bigint>;
|
|
126
|
+
oprfPublicKey: AffinePoint<bigint>;
|
|
127
|
+
epoch: number;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build challenge from sessions: contributingParties = party_id + 1 per party, then combineCommitments.
|
|
131
|
+
*/
|
|
132
|
+
declare function generateChallengeRequest(sessions: OprfSessions): DLogCommitmentsShamir;
|
|
133
|
+
/**
|
|
134
|
+
* Combine proof shares, verify DLog proof. Throws OprfClientError if invalid.
|
|
135
|
+
*/
|
|
136
|
+
declare function verifyDlogEquality(requestId: string, oprfPublicKey: AffinePoint<bigint>, blindedRequest: AffinePoint<bigint>, proofShares: DLogProofShareShamir[], challenge: DLogCommitmentsShamir): DLogEqualityProof;
|
|
137
|
+
interface DistributedOprfOptions<Auth = unknown> {
|
|
138
|
+
/** Auth payload sent in OprfRequest (must be JSON-serializable). */
|
|
139
|
+
auth?: Auth;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Full distributed OPRF: blind → init sessions → challenge → finish → verify → unblind → finalize.
|
|
143
|
+
* Services must be pre-built WS URLs (use toOprfUri / toOprfUriMany).
|
|
144
|
+
*/
|
|
145
|
+
declare function distributedOprf(services: string[], threshold: number, query: bigint, domainSeparator: bigint, options?: DistributedOprfOptions): Promise<VerifiableOprfOutput>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Client error types matching the Rust oprf-client Error enum.
|
|
149
|
+
* Two-tier model: NodeError (per-node) and OprfClientError (protocol-level).
|
|
150
|
+
*/
|
|
151
|
+
/**
|
|
152
|
+
* Application-level error received in a WebSocket close frame from a node.
|
|
153
|
+
*/
|
|
154
|
+
declare class ServiceError extends Error {
|
|
155
|
+
readonly errorCode: number;
|
|
156
|
+
readonly msg?: string;
|
|
157
|
+
constructor(errorCode: number, msg?: string);
|
|
158
|
+
}
|
|
159
|
+
type NodeErrorCode = 'ServiceError' | 'WsError' | 'UnexpectedMessage' | 'Unknown';
|
|
160
|
+
/**
|
|
161
|
+
* Per-node error, discriminated by `code`.
|
|
162
|
+
*/
|
|
163
|
+
declare class NodeError extends Error {
|
|
164
|
+
readonly code: NodeErrorCode;
|
|
165
|
+
readonly reason?: string;
|
|
166
|
+
readonly cause?: Error;
|
|
167
|
+
readonly serviceError?: ServiceError;
|
|
168
|
+
constructor(code: NodeErrorCode, opts?: {
|
|
169
|
+
reason?: string;
|
|
170
|
+
cause?: Error;
|
|
171
|
+
serviceError?: ServiceError;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
declare function isNodeError(err: unknown): err is NodeError;
|
|
175
|
+
type OprfClientErrorCode = 'NonUniqueServices' | 'InvalidDLogProof' | 'InconsistentOprfPublicKeys' | 'ThresholdServiceError' | 'Networking' | 'UnexpectedMessage' | 'CannotFinishSession' | 'NodeErrorDisagreement' | 'Unknown';
|
|
176
|
+
interface OprfClientErrorDetails {
|
|
177
|
+
nodeErrors?: NodeError[];
|
|
178
|
+
serviceError?: ServiceError;
|
|
179
|
+
cause?: NodeError;
|
|
180
|
+
networkingErrors?: Error[];
|
|
181
|
+
}
|
|
182
|
+
declare class OprfClientError extends Error {
|
|
183
|
+
readonly code: OprfClientErrorCode;
|
|
184
|
+
readonly details?: OprfClientErrorDetails;
|
|
185
|
+
constructor(code: OprfClientErrorCode, message: string, details?: OprfClientErrorDetails);
|
|
186
|
+
}
|
|
187
|
+
declare function isOprfClientError(err: unknown): err is OprfClientError;
|
|
188
|
+
/**
|
|
189
|
+
* Aggregate per-node errors into a protocol-level OprfClientError.
|
|
190
|
+
* Mirrors Rust oprf-client aggregate_error logic:
|
|
191
|
+
* - >= threshold ServiceErrors with same code → ThresholdServiceError
|
|
192
|
+
* - >= threshold UnexpectedMessage with same reason → UnexpectedMessage
|
|
193
|
+
* - >= threshold WsErrors → Networking
|
|
194
|
+
* - Otherwise → NodeErrorDisagreement
|
|
195
|
+
*/
|
|
196
|
+
declare function aggregateError(threshold: number, errors: NodeError[]): OprfClientError;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* URI construction helpers for OPRF service endpoints.
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* Build a WebSocket URL for a single OPRF service.
|
|
203
|
+
* http → ws, https → wss. Appends /api/{auth_module_name}/oprf?version={clientVersion}.
|
|
204
|
+
*/
|
|
205
|
+
declare function toOprfUri(service: string, auth_module_name: string, clientVersion?: string): string;
|
|
206
|
+
|
|
207
|
+
export { NodeError, type NodeErrorCode, OprfClientError, type OprfClientErrorCode, type OprfPublicKeyWithEpoch, type OprfRequest, type OprfResponse, type OprfSessions, ServiceError, type VerifiableOprfOutput, aggregateError, distributedOprf, finishSessions, generateChallengeRequest, initSessions, isNodeError, isOprfClientError, toOprfUri, verifyDlogEquality };
|