@collectorcrypt/vrf-client 0.1.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.
@@ -0,0 +1,417 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.decodeAuthority = decodeAuthority;
37
+ exports.decodeProofCommit = decodeProofCommit;
38
+ exports.decodeProofCommitWithBeta = decodeProofCommitWithBeta;
39
+ exports.fetchAuthority = fetchAuthority;
40
+ exports.fetchProofCommit = fetchProofCommit;
41
+ exports.buildInitAuthorityIx = buildInitAuthorityIx;
42
+ exports.buildFreezeAuthorityIx = buildFreezeAuthorityIx;
43
+ exports.buildRevokeAuthorityIx = buildRevokeAuthorityIx;
44
+ exports.buildCommitProofIx = buildCommitProofIx;
45
+ exports.buildCommitProofEventIx = buildCommitProofEventIx;
46
+ exports.fetchProofCommitEvents = fetchProofCommitEvents;
47
+ exports.buildCommitProofWithBetaIx = buildCommitProofWithBetaIx;
48
+ exports.fetchProofCommitWithBeta = fetchProofCommitWithBeta;
49
+ exports.asTx = asTx;
50
+ const anchor = __importStar(require("@coral-xyz/anchor"));
51
+ const anchor_1 = require("@coral-xyz/anchor");
52
+ const web3_js_1 = require("@solana/web3.js");
53
+ const stateless_js_1 = require("@lightprotocol/stateless.js");
54
+ const ecvrf_1 = require("@collectorcrypt/ecvrf");
55
+ const addresses_1 = require("./addresses");
56
+ const constants_1 = require("./constants");
57
+ const light_1 = require("./light");
58
+ /**
59
+ * Decode a VrfAuthority record from a fetched compressed-account row.
60
+ * Wraps the Anchor coder so callers can stay in terms of typed fields.
61
+ */
62
+ function decodeAuthority(program, dataBytes) {
63
+ // Anchor 0.31 normalizes IDL type names to camelCase on `program.idl`.
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ return program.coder.types.decode("vrfAuthority", Buffer.from(dataBytes));
66
+ }
67
+ function decodeProofCommit(program, dataBytes) {
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
+ return program.coder.types.decode("vrfProofCommit", Buffer.from(dataBytes));
70
+ }
71
+ function decodeProofCommitWithBeta(program, dataBytes) {
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
+ return program.coder.types.decode("vrfProofCommitWithBeta", Buffer.from(dataBytes));
74
+ }
75
+ /**
76
+ * Fetch a VrfAuthority compressed account by (owner, label). Returns null
77
+ * if no such authority exists.
78
+ */
79
+ async function fetchAuthority(program, rpc, owner, label) {
80
+ (0, light_1.forceLightV2)();
81
+ const labelBytes = typeof label === "string" ? (0, addresses_1.encodeLabel)(label) : label;
82
+ const authorityAddress = (0, addresses_1.deriveAuthorityAddress)(owner, labelBytes, program.programId);
83
+ const account = await rpc.getCompressedAccount((0, stateless_js_1.bn)(authorityAddress.toBytes()));
84
+ if (!account)
85
+ return null;
86
+ const decoded = decodeAuthority(program, Uint8Array.from(account.data.data));
87
+ return {
88
+ authorityAddress,
89
+ account,
90
+ decoded,
91
+ onChainAuthority: {
92
+ authorityAddress,
93
+ owner: decoded.owner,
94
+ pk: Uint8Array.from(decoded.pk),
95
+ suite: decoded.suite,
96
+ frozen: decoded.frozen,
97
+ revoked: decoded.revoked,
98
+ label: Uint8Array.from(decoded.label),
99
+ },
100
+ };
101
+ }
102
+ /**
103
+ * Fetch a VrfProofCommit by (authority, memo). Returns null if no such
104
+ * commit exists yet.
105
+ */
106
+ async function fetchProofCommit(program, rpc, authority, memo) {
107
+ (0, light_1.forceLightV2)();
108
+ const mh = (0, addresses_1.memoHash)(memo);
109
+ const commitAddress = (0, addresses_1.deriveProofCommitAddress)(authority, mh, program.programId);
110
+ const account = await rpc.getCompressedAccount((0, stateless_js_1.bn)(commitAddress.toBytes()));
111
+ if (!account)
112
+ return null;
113
+ const decoded = decodeProofCommit(program, Uint8Array.from(account.data.data));
114
+ return {
115
+ commitAddress,
116
+ account,
117
+ decoded,
118
+ onChainCommit: {
119
+ authority: decoded.authority,
120
+ memoHash: Uint8Array.from(decoded.memoHash),
121
+ proofHash: Uint8Array.from(decoded.proofHash),
122
+ alphaHash: Uint8Array.from(decoded.alphaHash),
123
+ committedSlot: BigInt(decoded.committedSlot.toString()),
124
+ },
125
+ };
126
+ }
127
+ /**
128
+ * Build the init_authority instruction. Caller is responsible for adding it
129
+ * to a transaction with the owner as signer and submitting it.
130
+ */
131
+ async function buildInitAuthorityIx(program, rpc, input) {
132
+ if (input.pk.length !== 32) {
133
+ throw new Error("pk must be 32 bytes");
134
+ }
135
+ if (input.suite !== constants_1.SUITE_EDWARDS25519_SHA512_TAI) {
136
+ throw new Error("only ECVRF-EDWARDS25519-SHA512-TAI suite 0x03 is supported");
137
+ }
138
+ const labelBytes = typeof input.label === "string" ? (0, addresses_1.encodeLabel)(input.label) : input.label;
139
+ if (labelBytes.length !== 32) {
140
+ throw new Error("label must encode to exactly 32 bytes");
141
+ }
142
+ const authorityAddress = (0, addresses_1.deriveAuthorityAddress)(input.owner, labelBytes, program.programId);
143
+ const ctx = await (0, light_1.buildCreateContext)(rpc, program.programId, authorityAddress);
144
+ const ix = await program.methods
145
+ // @ts-ignore: Anchor IDL types are dynamic at this layer
146
+ .initAuthority(ctx.proof, ctx.packedAddressTreeInfo, ctx.outputStateTreeIndex, Array.from(input.pk), input.suite, Array.from(labelBytes))
147
+ .accounts({
148
+ owner: input.owner,
149
+ systemProgram: anchor.web3.SystemProgram.programId,
150
+ })
151
+ .remainingAccounts(ctx.remainingAccountMetas)
152
+ .instruction();
153
+ return { ix, authorityAddress };
154
+ }
155
+ async function buildFreezeAuthorityIx(program, rpc, input) {
156
+ const auth = await fetchAuthority(program, rpc, input.owner, input.label);
157
+ if (!auth)
158
+ throw new Error("authority not found");
159
+ const ctx = await (0, light_1.buildMutateContext)(rpc, program.programId, auth.account);
160
+ const ix = await program.methods
161
+ // @ts-ignore: Anchor IDL types are dynamic at this layer
162
+ .freezeAuthority(ctx.proof, auth.decoded, ctx.accountMeta)
163
+ .accounts({ owner: input.owner })
164
+ .remainingAccounts(ctx.remainingAccountMetas)
165
+ .instruction();
166
+ return ix;
167
+ }
168
+ async function buildRevokeAuthorityIx(program, rpc, input) {
169
+ const auth = await fetchAuthority(program, rpc, input.owner, input.label);
170
+ if (!auth)
171
+ throw new Error("authority not found");
172
+ const ctx = await (0, light_1.buildMutateContext)(rpc, program.programId, auth.account);
173
+ const ix = await program.methods
174
+ // @ts-ignore: Anchor IDL types are dynamic at this layer
175
+ .revokeAuthority(ctx.proof, auth.decoded, ctx.accountMeta)
176
+ .accounts({ owner: input.owner })
177
+ .remainingAccounts(ctx.remainingAccountMetas)
178
+ .instruction();
179
+ return ix;
180
+ }
181
+ function assertAuthorityCanCommit(auth) {
182
+ if (!auth)
183
+ throw new Error("authority not found");
184
+ if (auth.decoded.suite !== constants_1.SUITE_EDWARDS25519_SHA512_TAI) {
185
+ throw new Error("authority suite is not supported");
186
+ }
187
+ if (!auth.decoded.frozen)
188
+ throw new Error("authority is not frozen");
189
+ if (auth.decoded.revoked)
190
+ throw new Error("authority is revoked");
191
+ }
192
+ function assertProofMatchesAuthority(auth, input) {
193
+ const pk = Uint8Array.from(auth.decoded.pk);
194
+ if (!(0, ecvrf_1.verifyVRF)(pk, input.alpha, input.proof)) {
195
+ throw new Error("proof does not verify against authority pk and alpha");
196
+ }
197
+ }
198
+ /**
199
+ * Build the commit_proof instruction. The authority is looked up via
200
+ * (owner, label) — must already exist on chain. memo/alpha/proof are hashed
201
+ * via SHA-256 and stored in the new VrfProofCommit PDA.
202
+ */
203
+ async function buildCommitProofIx(program, rpc, input) {
204
+ if (input.proof.length !== 80) {
205
+ throw new Error("proof must be 80 bytes (RFC 9381 Ed25519 ECVRF proof)");
206
+ }
207
+ const auth = await fetchAuthority(program, rpc, input.owner, input.label);
208
+ assertAuthorityCanCommit(auth);
209
+ assertProofMatchesAuthority(auth, input);
210
+ const mh = (0, addresses_1.memoHash)(input.memo);
211
+ const commitAddress = (0, addresses_1.deriveProofCommitAddress)(auth.authorityAddress, mh, program.programId);
212
+ // One unified context: a single validity proof covers both the authority
213
+ // input (read-only) and the new commit address, and both pack against the
214
+ // same remainingAccounts list.
215
+ const ctx = await (0, light_1.buildCommitProofContext)(rpc, program.programId, auth.account, commitAddress);
216
+ const ix = await program.methods
217
+ // @ts-ignore: Anchor IDL types are dynamic at this layer
218
+ .commitProof(ctx.proof, ctx.authorityReadOnlyMeta, auth.decoded, ctx.packedAddressTreeInfo, ctx.outputStateTreeIndex, Array.from(mh), Array.from((0, addresses_1.proofHash)(input.proof)), Array.from((0, addresses_1.alphaHash)(input.alpha)))
219
+ .accounts({ owner: input.owner })
220
+ .remainingAccounts(ctx.remainingAccountMetas)
221
+ .instruction();
222
+ return { ix, commitAddress };
223
+ }
224
+ /**
225
+ * Build the commit_proof_event instruction (event mode). Proves the authority
226
+ * read-only, requires it to be frozen and unrevoked, and emits a Solana log
227
+ * event rather than writing a compressed PDA.
228
+ *
229
+ * The trade-off is that the chain doesn't enforce one-commit-per-memo;
230
+ * verifiers must scan for duplicate `memo_hash` events and pick the one where
231
+ * ECVRF math passes.
232
+ */
233
+ async function buildCommitProofEventIx(program, rpc, input) {
234
+ if (input.proof.length !== 80) {
235
+ throw new Error("proof must be 80 bytes (RFC 9381 Ed25519 ECVRF proof)");
236
+ }
237
+ const labelBytes = typeof input.label === "string" ? (0, addresses_1.encodeLabel)(input.label) : input.label;
238
+ if (labelBytes.length !== 32) {
239
+ throw new Error("label must encode to exactly 32 bytes");
240
+ }
241
+ const auth = await fetchAuthority(program, rpc, input.owner, labelBytes);
242
+ assertAuthorityCanCommit(auth);
243
+ assertProofMatchesAuthority(auth, input);
244
+ const ctx = await (0, light_1.buildReadOnlyAuthorityContext)(rpc, program.programId, auth.account);
245
+ const mh = (0, addresses_1.memoHash)(input.memo);
246
+ const ix = await program.methods
247
+ // @ts-ignore: Anchor IDL types are dynamic at this layer
248
+ .commitProofEvent(ctx.proof, ctx.authorityReadOnlyMeta, auth.decoded, Array.from(labelBytes), Array.from(mh), Array.from((0, addresses_1.proofHash)(input.proof)), Array.from((0, addresses_1.alphaHash)(input.alpha)))
249
+ .accounts({ owner: input.owner })
250
+ .remainingAccounts(ctx.remainingAccountMetas)
251
+ .instruction();
252
+ return ix;
253
+ }
254
+ /**
255
+ * Fetch all `VrfProofCommitted` events emitted for a given `(owner, label,
256
+ * memo)` tuple, ordered oldest → newest. Returns an empty array if none
257
+ * exist.
258
+ *
259
+ * IMPORTANT: this can return MORE than one row. The on-chain program does
260
+ * not enforce uniqueness in event mode. A safe verifier:
261
+ *
262
+ * 1. Collects all matches for the requested memo.
263
+ * 2. Runs `verifyAuthorityCommitEndToEnd` against each candidate proof.
264
+ * 3. Accepts the unique row where the ECVRF math passes.
265
+ *
266
+ * Because ECVRF proofs are deterministic for a fixed (pk, alpha), at most
267
+ * one of the candidates can have a valid `proof_hash`. The presence of extra
268
+ * events is detectable noise, not a successful forgery — but a naive verifier
269
+ * that picks "the latest event" without running ECVRF can be misled, which is
270
+ * the only soundness gap relative to the PDA path.
271
+ *
272
+ * `connection` and `programId` are passed in explicitly so log scanning works
273
+ * against a plain Solana RPC. Fetching compressed authority state still needs
274
+ * a Photon-capable RPC unless the verifier already has that state.
275
+ *
276
+ * `limit` caps how many recent signatures to scan (default 1000); pagination
277
+ * happens automatically via `getSignaturesForAddress`'s `before` cursor.
278
+ */
279
+ async function fetchProofCommitEvents(program, connection, owner, label, memo, options = {}) {
280
+ const labelBytes = typeof label === "string" ? (0, addresses_1.encodeLabel)(label) : label;
281
+ const targetMemoHash = (0, addresses_1.memoHash)(memo);
282
+ const parser = new anchor_1.EventParser(program.programId, new anchor_1.BorshCoder(program.idl));
283
+ const out = [];
284
+ const limit = options.limit ?? 1000;
285
+ let before;
286
+ let scanned = 0;
287
+ while (scanned < limit) {
288
+ const pageLimit = Math.min(1000, limit - scanned);
289
+ const sigInfos = await connection.getSignaturesForAddress(owner, {
290
+ limit: pageLimit,
291
+ before,
292
+ });
293
+ if (sigInfos.length === 0)
294
+ break;
295
+ scanned += sigInfos.length;
296
+ before = sigInfos[sigInfos.length - 1].signature;
297
+ for (const sigInfo of sigInfos) {
298
+ if (sigInfo.err)
299
+ continue;
300
+ const tx = await connection.getTransaction(sigInfo.signature, {
301
+ commitment: "confirmed",
302
+ maxSupportedTransactionVersion: 0,
303
+ });
304
+ if (!tx?.meta?.logMessages)
305
+ continue;
306
+ for (const ev of parser.parseLogs(tx.meta.logMessages, false)) {
307
+ if (ev.name !== "VrfProofCommitted" && ev.name !== "vrfProofCommitted")
308
+ continue;
309
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
310
+ const data = ev.data;
311
+ const eventOwner = data.owner;
312
+ const eventLabel = Uint8Array.from(data.label);
313
+ const eventMemoHash = Uint8Array.from(data.memoHash);
314
+ if (!eventOwner.equals(owner))
315
+ continue;
316
+ if (!bytesEqual(eventLabel, labelBytes))
317
+ continue;
318
+ if (!bytesEqual(eventMemoHash, targetMemoHash))
319
+ continue;
320
+ const authority = (0, addresses_1.deriveAuthorityAddress)(eventOwner, eventLabel, program.programId);
321
+ out.push({
322
+ owner: eventOwner,
323
+ label: eventLabel,
324
+ txSignature: sigInfo.signature,
325
+ slot: tx.slot,
326
+ onChainCommit: {
327
+ authority,
328
+ memoHash: eventMemoHash,
329
+ proofHash: Uint8Array.from(data.proofHash),
330
+ alphaHash: Uint8Array.from(data.alphaHash),
331
+ committedSlot: BigInt(data.committedSlot.toString()),
332
+ },
333
+ });
334
+ }
335
+ }
336
+ }
337
+ // RPC returns newest first — reverse so oldest comes first.
338
+ out.reverse();
339
+ return out;
340
+ }
341
+ function bytesEqual(a, b) {
342
+ if (a.length !== b.length)
343
+ return false;
344
+ for (let i = 0; i < a.length; i++)
345
+ if (a[i] !== b[i])
346
+ return false;
347
+ return true;
348
+ }
349
+ /**
350
+ * Build the commit_proof_with_beta instruction (PDA mode + on-chain beta).
351
+ * Like buildCommitProofIx, but additionally stores the 64-byte ECVRF beta
352
+ * (output of vrfProofToHash) in the new compressed PDA so other Solana
353
+ * programs can read it via a Light SDK CPI.
354
+ *
355
+ * Stored at the same seed prefix as regular commits, so one authority+memo can
356
+ * only use one registry mode.
357
+ */
358
+ async function buildCommitProofWithBetaIx(program, rpc, input) {
359
+ if (input.proof.length !== 80) {
360
+ throw new Error("proof must be 80 bytes (RFC 9381 Ed25519 ECVRF proof)");
361
+ }
362
+ if (input.beta.length !== 64) {
363
+ throw new Error("beta must be 64 bytes (SHA-512 output of vrfProofToHash)");
364
+ }
365
+ const auth = await fetchAuthority(program, rpc, input.owner, input.label);
366
+ assertAuthorityCanCommit(auth);
367
+ assertProofMatchesAuthority(auth, input);
368
+ if (!bytesEqual(input.beta, (0, ecvrf_1.vrfProofToHash)(input.proof))) {
369
+ throw new Error("beta does not match vrfProofToHash(proof)");
370
+ }
371
+ const mh = (0, addresses_1.memoHash)(input.memo);
372
+ const commitAddress = (0, addresses_1.deriveProofCommitWithBetaAddress)(auth.authorityAddress, mh, program.programId);
373
+ const ctx = await (0, light_1.buildCommitProofContext)(rpc, program.programId, auth.account, commitAddress);
374
+ // Split beta into two 32-byte halves to match the on-chain field layout.
375
+ const betaLo = input.beta.slice(0, 32);
376
+ const betaHi = input.beta.slice(32, 64);
377
+ const ix = await program.methods
378
+ // @ts-ignore: Anchor IDL types are dynamic at this layer
379
+ .commitProofWithBeta(ctx.proof, ctx.authorityReadOnlyMeta, auth.decoded, ctx.packedAddressTreeInfo, ctx.outputStateTreeIndex, Array.from(mh), Array.from((0, addresses_1.proofHash)(input.proof)), Array.from((0, addresses_1.alphaHash)(input.alpha)), Array.from(betaLo), Array.from(betaHi))
380
+ .accounts({ owner: input.owner })
381
+ .remainingAccounts(ctx.remainingAccountMetas)
382
+ .instruction();
383
+ return { ix, commitAddress };
384
+ }
385
+ /**
386
+ * Fetch a VrfProofCommitWithBeta by (authority, memo). Returns null if no such
387
+ * commit exists yet. Reassembles the 64-byte beta from its two on-chain halves.
388
+ */
389
+ async function fetchProofCommitWithBeta(program, rpc, authority, memo) {
390
+ const mh = (0, addresses_1.memoHash)(memo);
391
+ const commitAddress = (0, addresses_1.deriveProofCommitWithBetaAddress)(authority, mh, program.programId);
392
+ const account = await rpc.getCompressedAccount((0, stateless_js_1.bn)(commitAddress.toBytes()));
393
+ if (!account)
394
+ return null;
395
+ const decoded = decodeProofCommitWithBeta(program, Uint8Array.from(account.data.data));
396
+ const beta = new Uint8Array(64);
397
+ beta.set(Uint8Array.from(decoded.betaLo), 0);
398
+ beta.set(Uint8Array.from(decoded.betaHi), 32);
399
+ return {
400
+ commitAddress,
401
+ account,
402
+ decoded,
403
+ beta,
404
+ onChainCommit: {
405
+ authority: decoded.authority,
406
+ memoHash: Uint8Array.from(decoded.memoHash),
407
+ proofHash: Uint8Array.from(decoded.proofHash),
408
+ alphaHash: Uint8Array.from(decoded.alphaHash),
409
+ committedSlot: BigInt(decoded.committedSlot.toString()),
410
+ },
411
+ };
412
+ }
413
+ /** Convenience: wrap a single ix into a Transaction. */
414
+ function asTx(ix) {
415
+ return new web3_js_1.Transaction().add(ix);
416
+ }
417
+ //# sourceMappingURL=operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.js","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,0CAeC;AAED,8CAYC;AAED,8DAiBC;AAMD,wCAqCC;AAMD,4CAoCC;AAaD,oDAgDC;AAOD,wDAiBC;AAED,wDAiBC;AAsCD,gDA+CC;AAWD,0DAwCC;AA0CD,wDA4EC;AAiBD,gEAwDC;AAMD,4DAyCC;AAGD,oBAEC;AA9oBD,0DAA4C;AAC5C,8CAAqE;AACrE,6CAKyB;AACzB,8DAIqC;AACrC,iDAAkE;AAElE,2CAQqB;AACrB,2CAA4D;AAC5D,mCAMiB;AAGjB;;;GAGG;AACH,SAAgB,eAAe,CAAC,OAAgB,EAAE,SAAqB;IACrE,uEAAuE;IACvE,8DAA8D;IAC9D,OAAQ,OAAe,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CACxC,cAAc,EACd,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CASvB,CAAC;AACJ,CAAC;AAED,SAAgB,iBAAiB,CAAC,OAAgB,EAAE,SAAqB;IACvE,8DAA8D;IAC9D,OAAQ,OAAe,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CACxC,gBAAgB,EAChB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAOvB,CAAC;AACJ,CAAC;AAED,SAAgB,yBAAyB,CACvC,OAAgB,EAChB,SAAqB;IAErB,8DAA8D;IAC9D,OAAQ,OAAe,CAAC,KAAK,CAAC,KAAK,CAAC,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IAAI,qBAAW,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import * as anchor from "@coral-xyz/anchor";
2
+ import { Program } from "@coral-xyz/anchor";
3
+ /**
4
+ * Build an Anchor Program handle for cc-vrf. Pass an AnchorProvider with a
5
+ * Connection and Wallet — operations that mutate state (init/freeze/etc)
6
+ * use this provider's wallet as signer.
7
+ */
8
+ export declare function getProgram(provider: anchor.AnchorProvider): Program;
9
+ //# sourceMappingURL=program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAO5C;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,cAAc,GAAG,OAAO,CAGnE"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getProgram = getProgram;
7
+ const anchor_1 = require("@coral-xyz/anchor");
8
+ // IDL is vendored into the package so the SDK is browser-safe. Refresh
9
+ // the file with `pnpm refresh:idl` from the workspace root whenever the
10
+ // program changes (it copies target/idl/cc_vrf.json here).
11
+ const cc_vrf_json_1 = __importDefault(require("./idl/cc_vrf.json"));
12
+ /**
13
+ * Build an Anchor Program handle for cc-vrf. Pass an AnchorProvider with a
14
+ * Connection and Wallet — operations that mutate state (init/freeze/etc)
15
+ * use this provider's wallet as signer.
16
+ */
17
+ function getProgram(provider) {
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ return new anchor_1.Program(cc_vrf_json_1.default, provider);
20
+ }
21
+ //# sourceMappingURL=program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":";;;;;AAaA,gCAGC;AAfD,8CAA4C;AAE5C,uEAAuE;AACvE,wEAAwE;AACxE,2DAA2D;AAC3D,oEAAoC;AAEpC;;;;GAIG;AACH,SAAgB,UAAU,CAAC,QAA+B;IACxD,8DAA8D;IAC9D,OAAO,IAAI,gBAAO,CAAC,qBAAU,EAAE,QAAQ,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,124 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ export interface OnChainAuthority {
3
+ authorityAddress?: PublicKey;
4
+ owner: PublicKey;
5
+ pk: Uint8Array;
6
+ suite: number;
7
+ frozen: boolean;
8
+ revoked: boolean;
9
+ label: Uint8Array;
10
+ }
11
+ /**
12
+ * On-chain commitment record fetched from a VrfProofCommit compressed PDA.
13
+ * Either the consumer fetches this themselves via fetchProofCommit() and
14
+ * passes it in, or they construct it from raw fields if validating offline.
15
+ */
16
+ export interface OnChainCommit {
17
+ authority?: PublicKey;
18
+ memoHash: Uint8Array;
19
+ proofHash: Uint8Array;
20
+ alphaHash: Uint8Array;
21
+ committedSlot: bigint | number;
22
+ }
23
+ export interface VerifyEndToEndInput {
24
+ /** The operator's published VRF public key (32 bytes Ed25519). */
25
+ pk: Uint8Array;
26
+ /** The exact alpha bytes the operator hashed and signed over. */
27
+ alpha: Uint8Array;
28
+ /** The 80-byte VRF proof the operator produced. */
29
+ proof: Uint8Array;
30
+ /** The on-chain commitment row, fetched from the program. */
31
+ onChainCommit: OnChainCommit;
32
+ /** Original memo string/bytes, used to verify the memo hash. */
33
+ memo: string | Uint8Array;
34
+ /** VRF suite. Omitted means RFC 9381 Ed25519-SHA512-TAI. */
35
+ suite?: number;
36
+ }
37
+ export interface VerifyEndToEndResult {
38
+ /**
39
+ * True iff every check passed: ECVRF math, on-chain proof hash, on-chain
40
+ * alpha hash, on-chain memo hash. Any failure flips this false.
41
+ */
42
+ valid: boolean;
43
+ ecvrfValid: boolean;
44
+ suiteSupported: boolean;
45
+ proofHashMatches: boolean;
46
+ alphaHashMatches: boolean;
47
+ memoHashMatches: boolean;
48
+ /** SHA-512 (64-byte) beta derived from the proof, present iff `ecvrfValid`. */
49
+ beta: Uint8Array | null;
50
+ reasons: string[];
51
+ }
52
+ /**
53
+ * Single-call full verification for a VRF outcome that's been committed
54
+ * on-chain. Validates:
55
+ *
56
+ * 1. ECVRF math: `verifyVRF(pk, alpha, proof)` → true
57
+ * 2. sha256(proof) == on-chain commit.proof_hash
58
+ * 3. sha256(alpha) == on-chain commit.alpha_hash
59
+ * 4. sha256(memo) == on-chain commit.memo_hash
60
+ *
61
+ * If all four hold, the operator cannot have substituted the proof, alpha,
62
+ * or memo after the fact — the result is provably tied to the on-chain
63
+ * commitment.
64
+ */
65
+ /**
66
+ * Result of picking the canonical commit from a list of events for the same
67
+ * `(authority, memo)`. The "canonical" commit is the unique event whose
68
+ * `proof_hash` matches the SHA-256 of a proof that verifies under ECVRF.
69
+ *
70
+ * Because ECVRF proofs are deterministic for a given (pk, alpha), at most one
71
+ * candidate can have a valid `proof_hash`. Extra events (which the chain
72
+ * allows in event-mode) are simply garbage payloads — detectable, not a
73
+ * successful forgery.
74
+ */
75
+ export interface PickCanonicalResult {
76
+ /** The single event whose committed hash matches the verifying proof, or null if none verify. */
77
+ canonical: OnChainCommit | null;
78
+ /** All candidates inspected, in the order supplied. */
79
+ candidates: OnChainCommit[];
80
+ /** Whether more than one event was found for the same memo. Informational. */
81
+ duplicateMemoEvents: boolean;
82
+ /** Whether more than one candidate's `proof_hash` matched a verifying proof (should be impossible if ECVRF is sound). */
83
+ multipleVerifying: boolean;
84
+ }
85
+ export interface VerifyAuthorityCommitEndToEndInput extends Omit<VerifyEndToEndInput, "pk" | "suite"> {
86
+ /** Authority state fetched from the VrfAuthority compressed PDA. */
87
+ authority: OnChainAuthority;
88
+ /** Expected owner for the authority, usually the operator wallet. */
89
+ expectedOwner?: PublicKey;
90
+ /** Expected 32-byte authority label. */
91
+ expectedLabel?: Uint8Array;
92
+ /**
93
+ * Optional sanity check: redundant against the address rederived from
94
+ * `(owner, label)` inside the verifier. If provided, it must match the
95
+ * derived address or `valid` flips false.
96
+ */
97
+ expectedAuthorityAddress?: PublicKey;
98
+ /**
99
+ * Optional program ID override. Defaults to the canonical cc-vrf program
100
+ * ID and only needs to be set for forked deployments.
101
+ */
102
+ programId?: PublicKey;
103
+ /** 64-byte beta fetched from a VrfProofCommitWithBeta account. */
104
+ onChainBeta?: Uint8Array;
105
+ }
106
+ export interface VerifyAuthorityCommitEndToEndResult extends VerifyEndToEndResult {
107
+ authorityFrozen: boolean;
108
+ authorityNotRevoked: boolean;
109
+ authorityOwnerMatches: boolean;
110
+ authorityLabelMatches: boolean;
111
+ commitAuthorityMatches: boolean;
112
+ betaMatches: boolean | null;
113
+ }
114
+ /**
115
+ * Resolve which committed event corresponds to a known-valid proof. Use this
116
+ * when fetching event-mode commits where the chain doesn't enforce
117
+ * one-commit-per-memo. Pass in all candidates from `fetchProofCommitEvents`
118
+ * plus the proof bytes the operator gave you; you get back the unique
119
+ * canonical row (or null if none match).
120
+ */
121
+ export declare function pickCanonicalCommit(candidates: OnChainCommit[], proof: Uint8Array): PickCanonicalResult;
122
+ export declare function verifyEndToEnd(input: VerifyEndToEndInput): VerifyEndToEndResult;
123
+ export declare function verifyAuthorityCommitEndToEnd(input: VerifyAuthorityCommitEndToEndInput): VerifyAuthorityCommitEndToEndResult;
124
+ //# sourceMappingURL=verifyEndToEnd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyEndToEnd.d.ts","sourceRoot":"","sources":["../src/verifyEndToEnd.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,CAAC,EAAE,SAAS,CAAC;IAC7B,KAAK,EAAE,SAAS,CAAC;IACjB,EAAE,EAAE,UAAU,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