@t3foundry/tasra-sdk 0.3.1-next.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/CHANGELOG.md +1067 -28
  2. package/README.md +15 -0
  3. package/dist/app/approvals.d.ts +66 -4
  4. package/dist/app/approvals.js +153 -16
  5. package/dist/app/authorization.d.ts +1 -1
  6. package/dist/app/authorization.js +1 -1
  7. package/dist/app/browser.d.ts +63 -0
  8. package/dist/app/browser.js +242 -0
  9. package/dist/app/client.d.ts +114 -13
  10. package/dist/app/client.js +302 -76
  11. package/dist/app/identity.js +21 -9
  12. package/dist/app/index.d.ts +28 -3
  13. package/dist/app/index.js +16 -1
  14. package/dist/app/memory-store.d.ts +7 -0
  15. package/dist/app/memory-store.js +55 -0
  16. package/dist/app/node.d.ts +34 -6
  17. package/dist/app/node.js +387 -64
  18. package/dist/app/paid-allowance.d.ts +325 -0
  19. package/dist/app/paid-allowance.js +1290 -0
  20. package/dist/app/paid-approval.d.ts +122 -0
  21. package/dist/app/paid-approval.js +379 -0
  22. package/dist/app/paid-journal.d.ts +51 -0
  23. package/dist/app/paid-journal.js +117 -0
  24. package/dist/app/paid-keys.d.ts +12 -0
  25. package/dist/app/paid-keys.js +20 -0
  26. package/dist/app/paid-operation.d.ts +821 -0
  27. package/dist/app/paid-operation.js +1720 -0
  28. package/dist/app/paid-reservation.d.ts +157 -0
  29. package/dist/app/paid-reservation.js +323 -0
  30. package/dist/app/paid-session.d.ts +147 -0
  31. package/dist/app/paid-session.js +578 -0
  32. package/dist/app/payer-queue.d.ts +11 -0
  33. package/dist/app/payer-queue.js +27 -0
  34. package/dist/app/policy-bootstrap.d.ts +342 -0
  35. package/dist/app/policy-bootstrap.js +365 -0
  36. package/dist/app/policy-operation.d.ts +47 -0
  37. package/dist/app/policy-operation.js +101 -0
  38. package/dist/app/ready-slot.d.ts +12 -0
  39. package/dist/app/ready-slot.js +5 -2
  40. package/dist/app/rotation-lock.d.ts +38 -0
  41. package/dist/app/rotation-lock.js +42 -0
  42. package/dist/app/session-decrypt.d.ts +135 -0
  43. package/dist/app/session-decrypt.js +335 -0
  44. package/dist/app/session-grants.d.ts +349 -0
  45. package/dist/app/session-grants.js +811 -0
  46. package/dist/app/signing-intents.d.ts +78 -0
  47. package/dist/app/signing-intents.js +95 -0
  48. package/dist/app/store-commit.d.ts +63 -0
  49. package/dist/app/store-commit.js +126 -0
  50. package/dist/app/store-errors.d.ts +8 -0
  51. package/dist/app/store-errors.js +11 -0
  52. package/dist/app/tasra-client.d.ts +2 -0
  53. package/dist/app/tasra-client.js +1 -1
  54. package/dist/app/wallet.js +4 -1
  55. package/dist/auth/holderProof.d.ts +3 -0
  56. package/dist/auth/holderProof.js +8 -7
  57. package/dist/auth/verifier.d.ts +4 -2
  58. package/dist/auth/verifier.js +5 -2
  59. package/dist/chain/abis/index.d.ts +6178 -4101
  60. package/dist/chain/abis/index.js +3 -0
  61. package/dist/chain/abis/keyRegistry.d.ts +256 -0
  62. package/dist/chain/abis/keyRegistry.js +333 -0
  63. package/dist/chain/abis/prepaidFaultOracle.d.ts +321 -0
  64. package/dist/chain/abis/prepaidFaultOracle.js +413 -0
  65. package/dist/chain/abis/settlement.d.ts +2203 -703
  66. package/dist/chain/abis/settlement.js +2685 -764
  67. package/dist/chain/allowance.d.ts +358 -0
  68. package/dist/chain/allowance.js +800 -0
  69. package/dist/chain/billing.d.ts +85 -0
  70. package/dist/chain/billing.js +197 -0
  71. package/dist/chain/chainId.d.ts +13 -0
  72. package/dist/chain/chainId.js +26 -0
  73. package/dist/chain/client.d.ts +15 -1
  74. package/dist/chain/client.js +57 -1
  75. package/dist/chain/commitmentRecovery.d.ts +51 -0
  76. package/dist/chain/commitmentRecovery.js +38 -0
  77. package/dist/chain/committeeClient.d.ts +17 -10
  78. package/dist/chain/committeeClient.js +64 -16
  79. package/dist/chain/committeeDraw.d.ts +12 -0
  80. package/dist/chain/committeeDraw.js +56 -0
  81. package/dist/chain/custodyHealth.d.ts +212 -0
  82. package/dist/chain/custodyHealth.js +365 -0
  83. package/dist/chain/deployments.js +2 -0
  84. package/dist/chain/events.js +2 -0
  85. package/dist/chain/headFollower.d.ts +77 -0
  86. package/dist/chain/headFollower.js +219 -0
  87. package/dist/chain/headPrefetch.d.ts +23 -0
  88. package/dist/chain/headPrefetch.js +67 -0
  89. package/dist/chain/index.d.ts +50 -8
  90. package/dist/chain/index.js +28 -3
  91. package/dist/chain/keeperExecution.d.ts +44 -0
  92. package/dist/chain/keeperExecution.js +127 -0
  93. package/dist/chain/keeperRecovery.d.ts +78 -0
  94. package/dist/chain/keeperRecovery.js +91 -0
  95. package/dist/chain/node.d.ts +24 -1
  96. package/dist/chain/node.js +88 -43
  97. package/dist/chain/offchain.d.ts +2 -0
  98. package/dist/chain/paidAgentTransport.d.ts +38 -0
  99. package/dist/chain/paidAgentTransport.js +1 -0
  100. package/dist/chain/paidEpoch.d.ts +66 -0
  101. package/dist/chain/paidEpoch.js +139 -0
  102. package/dist/chain/paidPacing.d.ts +81 -0
  103. package/dist/chain/paidPacing.js +136 -0
  104. package/dist/chain/pinnedReads.d.ts +49 -0
  105. package/dist/chain/pinnedReads.js +218 -0
  106. package/dist/chain/prepaid.d.ts +383 -0
  107. package/dist/chain/prepaid.js +1046 -0
  108. package/dist/chain/prepaidEscape.d.ts +274 -0
  109. package/dist/chain/prepaidEscape.js +432 -0
  110. package/dist/chain/prepaidFault.d.ts +94 -0
  111. package/dist/chain/prepaidFault.js +148 -0
  112. package/dist/chain/receipt.d.ts +24 -0
  113. package/dist/chain/receipt.js +82 -0
  114. package/dist/chain/registeredAgent.d.ts +68 -3
  115. package/dist/chain/registeredAgent.js +143 -42
  116. package/dist/chain/registeredOperation.d.ts +10 -1
  117. package/dist/chain/registeredOperation.js +18 -3
  118. package/dist/chain/registeredPaidAgent.d.ts +254 -0
  119. package/dist/chain/registeredPaidAgent.js +889 -0
  120. package/dist/chain/registeredRelay.d.ts +31 -1
  121. package/dist/chain/registeredRelay.js +164 -43
  122. package/dist/chain/relayVoucher.d.ts +64 -0
  123. package/dist/chain/relayVoucher.js +69 -0
  124. package/dist/chain/reservation.d.ts +239 -0
  125. package/dist/chain/reservation.js +746 -0
  126. package/dist/chain/reshareRoster.d.ts +64 -0
  127. package/dist/chain/reshareRoster.js +85 -0
  128. package/dist/chain/revertReason.d.ts +8 -0
  129. package/dist/chain/revertReason.js +2 -1
  130. package/dist/chain/rotationLock.d.ts +130 -0
  131. package/dist/chain/rotationLock.js +168 -0
  132. package/dist/chain/serviceRequestPolicy.d.ts +47 -0
  133. package/dist/chain/serviceRequestPolicy.js +86 -0
  134. package/dist/chain/services.d.ts +7 -0
  135. package/dist/chain/services.js +44 -4
  136. package/dist/chain/slotClient.js +11 -2
  137. package/dist/chain/slotHandoff.d.ts +81 -0
  138. package/dist/chain/slotHandoff.js +166 -0
  139. package/dist/chain/slotSeed.d.ts +47 -5
  140. package/dist/chain/slotSeed.js +173 -42
  141. package/dist/chain/verifierSnapshot.d.ts +36 -0
  142. package/dist/chain/verifierSnapshot.js +197 -0
  143. package/dist/chain/write.d.ts +111 -21
  144. package/dist/chain/write.js +378 -146
  145. package/dist/committee/blsSharing.d.ts +53 -0
  146. package/dist/committee/blsSharing.js +90 -0
  147. package/dist/committee/client.d.ts +62 -23
  148. package/dist/committee/client.js +288 -72
  149. package/dist/committee/dual-operation.d.ts +165 -0
  150. package/dist/committee/dual-operation.js +229 -0
  151. package/dist/committee/dual-sign.d.ts +26 -1
  152. package/dist/committee/dual-sign.js +85 -7
  153. package/dist/committee/ecdsa.d.ts +38 -0
  154. package/dist/committee/ecdsa.js +87 -15
  155. package/dist/committee/evidence.d.ts +30 -0
  156. package/dist/committee/evidence.js +65 -0
  157. package/dist/committee/execution.d.ts +414 -0
  158. package/dist/committee/execution.js +446 -0
  159. package/dist/committee/extraction.js +33 -26
  160. package/dist/committee/index.d.ts +30 -7
  161. package/dist/committee/index.js +18 -6
  162. package/dist/committee/keeperExecution.d.ts +37 -0
  163. package/dist/committee/keeperExecution.js +141 -0
  164. package/dist/committee/oauth.d.ts +14 -4
  165. package/dist/committee/oauth.js +17 -5
  166. package/dist/committee/payment.d.ts +369 -0
  167. package/dist/committee/payment.js +339 -0
  168. package/dist/committee/recovery.d.ts +136 -0
  169. package/dist/committee/recovery.js +204 -0
  170. package/dist/committee/recoveryJson.d.ts +2 -0
  171. package/dist/committee/recoveryJson.js +87 -0
  172. package/dist/committee/request.d.ts +63 -27
  173. package/dist/committee/request.js +77 -66
  174. package/dist/committee/session-grant.d.ts +320 -0
  175. package/dist/committee/session-grant.js +397 -0
  176. package/dist/committee/status-refresh.d.ts +257 -0
  177. package/dist/committee/status-refresh.js +619 -0
  178. package/dist/committee/token.d.ts +163 -15
  179. package/dist/committee/token.js +247 -10
  180. package/dist/crypto/bn254.d.ts +70 -0
  181. package/dist/crypto/bn254.js +222 -0
  182. package/dist/crypto/ibe.d.ts +32 -0
  183. package/dist/crypto/ibe.js +56 -8
  184. package/dist/crypto/index.d.ts +1 -1
  185. package/dist/crypto/index.js +1 -1
  186. package/dist/crypto/kem.d.ts +31 -0
  187. package/dist/crypto/kem.js +113 -7
  188. package/dist/crypto/recipient.d.ts +75 -0
  189. package/dist/crypto/recipient.js +107 -0
  190. package/dist/decryption/client.d.ts +10 -16
  191. package/dist/decryption/client.js +8 -76
  192. package/dist/decryption/index.d.ts +2 -0
  193. package/dist/decryption/index.js +2 -0
  194. package/dist/decryption/sealed.d.ts +72 -0
  195. package/dist/decryption/sealed.js +147 -0
  196. package/dist/decryption/session.d.ts +115 -0
  197. package/dist/decryption/session.js +358 -0
  198. package/dist/errors.d.ts +406 -1
  199. package/dist/errors.js +400 -5
  200. package/dist/index.d.ts +9 -2
  201. package/dist/index.js +6 -1
  202. package/dist/internal/bounded.d.ts +66 -0
  203. package/dist/internal/bounded.js +126 -0
  204. package/dist/internal/network.d.ts +4 -0
  205. package/dist/internal/network.js +40 -0
  206. package/dist/internal/retryAfter.d.ts +8 -0
  207. package/dist/internal/retryAfter.js +28 -0
  208. package/dist/internal/sleep.d.ts +6 -0
  209. package/dist/internal/sleep.js +15 -0
  210. package/dist/internal/typedData.d.ts +13 -0
  211. package/dist/internal/typedData.js +77 -0
  212. package/dist/internal/viemErrors.d.ts +26 -0
  213. package/dist/internal/viemErrors.js +49 -0
  214. package/dist/oid4vp/binding.d.ts +27 -1
  215. package/dist/oid4vp/binding.js +36 -1
  216. package/dist/oid4vp/jose.d.ts +4 -2
  217. package/dist/oid4vp/jose.js +39 -7
  218. package/dist/oid4vp/request-object.d.ts +61 -4
  219. package/dist/oid4vp/request-object.js +140 -5
  220. package/dist/oid4vp/verifier-agent.d.ts +18 -8
  221. package/dist/oid4vp/verifier-agent.js +48 -6
  222. package/dist/oid4vp/wallet.d.ts +2 -4
  223. package/dist/oid4vp/wallet.js +1 -0
  224. package/dist/retry.d.ts +78 -0
  225. package/dist/retry.js +137 -0
  226. package/dist/signing/frost.d.ts +1 -1
  227. package/dist/verifier-agent/index.d.ts +41 -5
  228. package/dist/verifier-agent/index.js +124 -9
  229. package/dist/verifier-agent/payment.d.ts +7 -0
  230. package/dist/verifier-agent/payment.js +17 -0
  231. package/docs/api.md +8 -2
  232. package/docs/application-api.md +25 -2
  233. package/docs/chain.md +155 -9
  234. package/docs/consumer-migrations.md +61 -0
  235. package/docs/encrypted-notes.md +3 -2
  236. package/docs/encryption.md +4 -2
  237. package/docs/errors.md +14 -1
  238. package/docs/flows.md +2 -2
  239. package/docs/funding.md +902 -0
  240. package/docs/native-approvals.md +63 -0
  241. package/docs/reference/README.md +9 -8
  242. package/docs/reference/app-browser.md +232 -0
  243. package/docs/reference/app-node.md +38 -8
  244. package/docs/reference/app.md +4621 -805
  245. package/docs/reference/chain-node.md +74 -16
  246. package/docs/reference/chain.md +6740 -1592
  247. package/docs/reference/committee.md +5630 -987
  248. package/docs/reference/main.md +1439 -140
  249. package/docs/reference/oid4vp.md +297 -144
  250. package/docs/reference/verifier-agent.md +77 -35
  251. package/docs/signing.md +6 -0
  252. package/examples/encrypted-notes.ts +21 -6
  253. package/examples/getting-started.ts +2 -7
  254. package/examples/live-config.ts +24 -17
  255. package/package.json +17 -5
@@ -1,3 +1,5 @@
1
+ import type { EvidenceBindingWire } from './evidence.js';
2
+ import { type PaymentIntentWire } from './payment.js';
1
3
  /** Compound authorization token category, used in the signed canonical encoding. */
2
4
  export type TokenType = 'JWT' | 'refresh';
3
5
  /**
@@ -33,6 +35,10 @@ export interface CompoundTokenPayload {
33
35
  identityHash?: Uint8Array;
34
36
  /** Keccak-256 operation-binding hash. Required when keepers enforce request binding; absent only on authorization paths that do not derive it. */
35
37
  requestHash?: Uint8Array;
38
+ /** Creator payment intent hash; uses a distinct signing domain when present. */
39
+ paymentHash?: Uint8Array;
40
+ /** Optional transport preimage. Must match paymentHash; chain backing is checked separately. */
41
+ payment?: PaymentIntentWire;
36
42
  /**
37
43
  * How the holder's key possession was proved. `0x00` = Unbound (no proof),
38
44
  * `0x01` = HolderKey (KB-JWT nonce verified), `0x02` = IssuerAsserted (reserved).
@@ -125,6 +131,8 @@ export interface VerifierSet {
125
131
  }
126
132
  /** What a valid compound token attests. */
127
133
  export interface VerifiedToken {
134
+ /** Creator payment commitment authenticated by the verifier quorum, when present. */
135
+ paymentHash?: Uint8Array;
128
136
  /** 32-byte slot identifier. */
129
137
  slotId: Uint8Array;
130
138
  /** Hash of the credential presentation bound into the token. */
@@ -175,7 +183,7 @@ export interface CommitteeSignatureWire {
175
183
  signature: string;
176
184
  }
177
185
  /** The compound token JSON a client submits with `/v1/committee/{sign,decrypt}`. */
178
- export interface CompoundTokenWire {
186
+ export interface CompoundTokenWire extends EvidenceBindingWire {
179
187
  /** Compound authorization token category. */
180
188
  token_type: TokenType;
181
189
  /** Hexadecimal beacon seed. */
@@ -195,6 +203,10 @@ export interface CompoundTokenWire {
195
203
  identity_hash?: string;
196
204
  /** `0x..` request binding hash - present when minted via the verifier-agent flow. */
197
205
  request_hash?: string;
206
+ /** Creator payment-intent hash, attested by the verifier quorum. */
207
+ payment_hash?: string;
208
+ /** Creator-signed intent carried to keepers for independent reservation checks. */
209
+ payment?: PaymentIntentWire;
198
210
  /** `"unbound"` | `"holder_key"` | `"issuer_asserted"`. */
199
211
  binding?: string;
200
212
  /** Indices of the selected verifier committee. */
@@ -205,19 +217,17 @@ export interface CompoundTokenWire {
205
217
  exp: number;
206
218
  /** Hexadecimal verifier signatures and their registry indices. */
207
219
  signatures: CommitteeSignatureWire[];
208
- /** `0x..` keccak256 of the sealed presentation the quorum evaluated (the
209
- * ciphertext travels BESIDE the token as `evidence_ct`, never inside it). Present together
210
- * with `evidence_key_id` and `evidence_signatures`, or not at all. NOT part of the signed
211
- * canonical bytes — each signer's {@link evidenceBindingMessage} signature binds it. */
212
- evidence_hash?: string;
213
- /** `0x..` keccak256 of the accountant evidence key it is sealed to. */
214
- evidence_key_id?: string;
215
- /** each signer's ed25519 signature over {@link evidenceBindingMessage}. */
216
- evidence_signatures?: CommitteeSignatureWire[];
220
+ /**
221
+ * Revocation-status freshness attestations (`keykeeper/committee-status-attestation/v1`),
222
+ * one per drawn verifier that vouched. OUTSIDE the signed token bytes: it never moves the
223
+ * token hash. Keepers in production posture require a quorum of fresh ones.
224
+ */
225
+ status_attestations?: StatusAttestationWire[];
217
226
  }
218
227
  /** `keccak256(DOMAIN ‖ tokenHash ‖ evidenceHash ‖ evidenceKeyId)` — the message each drawn
219
228
  * verifier signs beside its token signature. Byte-identical to the Rust
220
- * `keykeeper_committee::evidence_binding_message`.
229
+ * `keykeeper_committee::evidence_binding_message`. The SDK's own sealed-evidence path
230
+ * (`./evidence.ts`) signs and verifies over this same function.
221
231
  *
222
232
  * @param tokenHash - 32-byte compound-token signing hash.
223
233
  * @param evidenceHash - 32-byte keccak256 of the sealed evidence ciphertext.
@@ -243,9 +253,9 @@ export interface VerifyEvidenceBindingOptions {
243
253
  }
244
254
  /**
245
255
  * Mirror of the Rust `verify_evidence_binding`: every signature must come from a DRAWN
246
- * verifier in `set` and verify over {@link evidenceBindingMessage}; distinct signers are
247
- * counted once and must satisfy `quorum` of the drawn committee. Throws on any failure;
248
- * returns the verified indexes.
256
+ * verifier in `set` and verify (strict, non-ZIP-215) over {@link evidenceBindingMessage};
257
+ * distinct signers are counted once and must satisfy `quorum` of the drawn committee.
258
+ * Throws on any failure; returns the verified indexes.
249
259
  *
250
260
  * @param opts - Token and evidence hashes, the signatures, the verifier set, the drawn committee and the quorum.
251
261
  */
@@ -262,8 +272,9 @@ export declare function bindingFromWire(s: string | undefined): number;
262
272
  *
263
273
  * @param p - Compound token payload, excluding signatures.
264
274
  * @param signatures - Verifier signatures to include in the wire object.
275
+ * @param statusAttestations - Optional revocation-status attestations, carried beside the signatures and never hashed. Validated strictly; an empty list is omitted.
265
276
  */
266
- export declare function assembleCompoundToken(p: CompoundTokenPayload, signatures: CommitteeSignature[]): CompoundTokenWire;
277
+ export declare function assembleCompoundToken(p: CompoundTokenPayload, signatures: CommitteeSignature[], statusAttestations?: StatusAttestation[]): CompoundTokenWire;
267
278
  /**
268
279
  * Decode a wire compound token into the byte-level payload + signatures for verification.
269
280
  *
@@ -271,4 +282,141 @@ export declare function assembleCompoundToken(p: CompoundTokenPayload, signature
271
282
  */
272
283
  export declare function decodeCompoundToken(w: CompoundTokenWire): CompoundTokenPayload & {
273
284
  signatures: CommitteeSignature[];
285
+ statusAttestations?: StatusAttestation[];
274
286
  };
287
+ /** Domain separator of the status-freshness statement (new name, `/v1`). */
288
+ export declare const STATUS_ATTESTATION_DOMAIN = "keykeeper/committee-status-attestation/v1";
289
+ /** Decided revocation bound: no keeper accepts a grant later than `R + 60 s`. */
290
+ export declare const REVOCATION_BOUND_SECS = 60;
291
+ /** The only skew a keeper allows past `status_until` (reserved inside the 60 s bound). */
292
+ export declare const STATUS_SKEW_SECS = 5;
293
+ /** The verifier's attestation cache bound: `REVOCATION_BOUND_SECS - STATUS_SKEW_SECS`. */
294
+ export declare const STATUS_CACHE_BOUND_SECS: number;
295
+ /** Longest usable window a verifier may attest (`55 - 10`). */
296
+ export declare const MAX_STATUS_WINDOW_SECS = 45;
297
+ /** Default attested window (`[committee] status_window_secs`). */
298
+ export declare const DEFAULT_STATUS_WINDOW_SECS = 30;
299
+ /** Most attestations one token may carry (mirrors the keeper cap). */
300
+ export declare const MAX_STATUS_ATTESTATIONS = 64;
301
+ /** Stable keeper refusal code: attestations present but fewer than a quorum valid and fresh. */
302
+ export declare const STATUS_STALE_CODE = "revocation_status_stale";
303
+ /** Stable keeper refusal code: the keeper requires attestations and the grant carries none. */
304
+ export declare const STATUS_MISSING_CODE = "revocation_status_missing";
305
+ /**
306
+ * Stable client preflight code: attestations are present but malformed, duplicated, over the cap
307
+ * or carry a bad signature from a counted verifier (a keeper refuses these without a stable code).
308
+ */
309
+ export declare const STATUS_INVALID_CODE = "revocation_status_invalid";
310
+ /** One decoded status-freshness attestation. */
311
+ export interface StatusAttestation {
312
+ /** Zero-based verifier registry index (u32). */
313
+ verifierIndex: number;
314
+ /** Unix seconds until which this verifier vouches for the holder's credential status. */
315
+ statusUntil: number;
316
+ /** 64-byte Ed25519 signature over {@link statusAttestationHash}. */
317
+ signature: Uint8Array;
318
+ }
319
+ /** One status attestation on the wire - exactly these three keys. */
320
+ export interface StatusAttestationWire {
321
+ /** Zero-based verifier registry index (u32). */
322
+ verifier_index: number;
323
+ /** Unix seconds (i64, a JavaScript safe integer). */
324
+ status_until: number;
325
+ /** `0x` + 128 hex characters: the 64-byte Ed25519 signature. */
326
+ signature: string;
327
+ }
328
+ /**
329
+ * The 32-byte digest a drawn verifier signs to attest credential-status freshness for one token:
330
+ * `keccak256(DOMAIN || tokenHash || verifierIndex(u32 BE) || statusUntil(i64 BE))`.
331
+ * Byte-identical to the reference `status_attestation_hash`.
332
+ *
333
+ * @param tokenHash - 32-byte compound token hash ({@link compoundTokenHash}).
334
+ * @param verifierIndex - Zero-based verifier registry index.
335
+ * @param statusUntil - Unix seconds the verifier vouches until.
336
+ */
337
+ export declare function statusAttestationHash(tokenHash: Uint8Array, verifierIndex: number, statusUntil: number): Uint8Array;
338
+ /**
339
+ * Verify ONE attestation's Ed25519 signature under the verifier's committee key over `tokenHash`
340
+ * (no freshness, no quorum) - what a relay checks before forwarding it.
341
+ *
342
+ * @param pubkey - 32-byte Ed25519 committee public key of `attestation.verifierIndex`.
343
+ * @param tokenHash - 32-byte compound token hash.
344
+ * @param attestation - Decoded attestation.
345
+ * @returns Whether the signature verifies (strict: non-canonical encodings refused).
346
+ */
347
+ export declare function verifyStatusAttestation(pubkey: Uint8Array, tokenHash: Uint8Array, attestation: StatusAttestation): boolean;
348
+ /** Inputs of {@link verifyStatusAttestations}, as a keeper checks them. */
349
+ export interface VerifyStatusAttestationsOptions {
350
+ /** The token's canonical hash (already verified by the caller). */
351
+ tokenHash: Uint8Array;
352
+ /** The token's attestations. */
353
+ attestations: StatusAttestation[];
354
+ /** Verifier indexes whose TOKEN signature verified (and that still stand). Others are ignored. */
355
+ counted: number[];
356
+ /** Active verifier set the token signatures were verified against. */
357
+ set: VerifierSet;
358
+ /** The token's quorum. */
359
+ quorum: number;
360
+ /** Current time, Unix seconds. */
361
+ now: number;
362
+ }
363
+ /**
364
+ * Verify a token's status attestations exactly as a keeper does and return the effective status
365
+ * deadline (the quorum-th largest attested `status_until`). Throws on a duplicate index, an
366
+ * oversize list, a bad signature from a counted verifier, or fewer than `quorum` attestations
367
+ * fresh at `now` (`now <= status_until + STATUS_SKEW_SECS`; the token leeway is NOT applied).
368
+ *
369
+ * @param opts - Token hash, attestations, counted signers, verifier set, quorum and time.
370
+ */
371
+ export declare function verifyStatusAttestations(opts: VerifyStatusAttestationsOptions): number;
372
+ /**
373
+ * The registry indexes whose Ed25519 signature over the token's own canonical hash verifies under
374
+ * `set` (strict), distinct and drawn. Mirrors the reference `signers_that_verify`: no rule, draw,
375
+ * lifetime or quorum check - only "which signatures are real", for counting status attestations.
376
+ *
377
+ * @param token - Decoded token (payload + signatures).
378
+ * @param set - Anchored verifier keys.
379
+ */
380
+ export declare function signersThatVerify(token: CompoundTokenPayload & {
381
+ signatures: CommitteeSignature[];
382
+ }, set: VerifierSet): number[];
383
+ /** Inputs of {@link requireStatusAttestations}. */
384
+ export interface RequireStatusAttestationsOptions extends Omit<VerifyStatusAttestationsOptions, 'attestations'> {
385
+ /** The token's attestations; `undefined` or empty means missing (as a keeper reads it). */
386
+ attestations: StatusAttestation[] | undefined;
387
+ /**
388
+ * Accept a grant WITHOUT attestations (warning), for a deployment still inside the keepers'
389
+ * documented status-freshness migration window. Default false. Present-but-invalid or stale
390
+ * attestations are refused whatever this says.
391
+ */
392
+ allowMissing?: boolean;
393
+ }
394
+ /** Accepted preflight outcome. */
395
+ export type StatusFreshness = {
396
+ /** A quorum attests freshness. */
397
+ kind: 'fresh';
398
+ /** Effective status deadline (Unix seconds). */
399
+ statusUntil: number;
400
+ } | {
401
+ /** No attestations, accepted only under the migration opt-out. */
402
+ kind: 'missing-accepted';
403
+ };
404
+ /**
405
+ * The keeper's status-freshness rule as a REQUIRED client preflight, run before any keeper call:
406
+ * a missing list throws `revocation_status_missing` (unless `allowMissing`), fewer than `quorum`
407
+ * fresh counted attestations `revocation_status_stale`, a malformed or forged list
408
+ * `revocation_status_invalid` - each a {@link RevocationStatusPreflightError}.
409
+ *
410
+ * @param opts - Token hash, attestations, counted signers, verifier set, quorum, time and opt-out.
411
+ */
412
+ export declare function requireStatusAttestations(opts: RequireStatusAttestationsOptions): StatusFreshness;
413
+ /**
414
+ * Strictly validate an untrusted `status_attestations` value: an array of at most
415
+ * `maxEntries` (and {@link MAX_STATUS_ATTESTATIONS}) objects with EXACTLY
416
+ * `{verifier_index: u32, status_until: safe integer, signature: "0x" + 128 hex}` and distinct
417
+ * indexes. Returns a fresh copy (the value a keeper receives unchanged).
418
+ *
419
+ * @param raw - Untrusted wire value.
420
+ * @param maxEntries - Upper bound, normally the token's committee draw length.
421
+ */
422
+ export declare function assertStatusAttestationsWire(raw: unknown, maxEntries?: number): StatusAttestationWire[];
@@ -13,8 +13,11 @@ import { keccak_256 } from '@noble/hashes/sha3';
13
13
  import { concatBytes } from '@noble/hashes/utils';
14
14
  import { ed25519 } from '@noble/curves/ed25519';
15
15
  import { bytesToHex, hexToBytes } from '../crypto/hex.js';
16
+ import { RevocationStatusPreflightError } from '../errors.js';
17
+ import { assertPaymentIntentWire, paymentIntentHash } from './payment.js';
16
18
  // Domain separators (must equal the reference constants verbatim)
17
19
  const SELECT_DOMAIN = new TextEncoder().encode('keykeeper-committee/select/v1');
20
+ const PAID_TOKEN_DOMAIN = new TextEncoder().encode('keykeeper-committee/paid-token/v1');
18
21
  const TOKEN_DOMAIN = new TextEncoder().encode('keykeeper-committee/token/v1');
19
22
  const OP_ATTEST_DOMAIN = new TextEncoder().encode('keykeeper-committee/op-attest/v1');
20
23
  const VERIFIER_LEAF_DOMAIN = new TextEncoder().encode('keykeeper-verifier-leaf:v1');
@@ -106,8 +109,15 @@ export function selectVerifierCommittee(slotId, epoch, seed, registrySize, count
106
109
  * @param p - Compound token payload, excluding signatures.
107
110
  */
108
111
  export function compoundTokenCanonicalBytes(p) {
112
+ if (p.paymentHash !== undefined && p.paymentHash.length !== 32)
113
+ throw new Error('paymentHash must be 32 bytes');
114
+ if (p.payment !== undefined) {
115
+ assertPaymentIntentWire(p.payment);
116
+ if (!p.paymentHash || paymentIntentHash(p.payment).toLowerCase() !== bytesToHex(p.paymentHash).toLowerCase())
117
+ throw new Error('payment preimage differs from paymentHash');
118
+ }
109
119
  const parts = [
110
- TOKEN_DOMAIN,
120
+ ...(p.paymentHash !== undefined ? [PAID_TOKEN_DOMAIN, p.paymentHash] : [TOKEN_DOMAIN]),
111
121
  Uint8Array.of(discriminant(p.tokenType)),
112
122
  p.seed,
113
123
  u64be(p.epoch),
@@ -299,6 +309,7 @@ export function verifyCompoundToken(opts) {
299
309
  ...(token.identityHash !== undefined ? { identityHash: token.identityHash } : {}),
300
310
  epoch: token.epoch,
301
311
  tokenType: token.tokenType,
312
+ ...(token.paymentHash !== undefined ? { paymentHash: token.paymentHash } : {}),
302
313
  verifiedSigners: verified,
303
314
  };
304
315
  }
@@ -306,7 +317,8 @@ export function verifyCompoundToken(opts) {
306
317
  const EVIDENCE_BINDING_DOMAIN = new TextEncoder().encode('keykeeper-committee/evidence-binding/v1');
307
318
  /** `keccak256(DOMAIN ‖ tokenHash ‖ evidenceHash ‖ evidenceKeyId)` — the message each drawn
308
319
  * verifier signs beside its token signature. Byte-identical to the Rust
309
- * `keykeeper_committee::evidence_binding_message`.
320
+ * `keykeeper_committee::evidence_binding_message`. The SDK's own sealed-evidence path
321
+ * (`./evidence.ts`) signs and verifies over this same function.
310
322
  *
311
323
  * @param tokenHash - 32-byte compound-token signing hash.
312
324
  * @param evidenceHash - 32-byte keccak256 of the sealed evidence ciphertext.
@@ -319,27 +331,38 @@ export function evidenceBindingMessage(tokenHash, evidenceHash, evidenceKeyId) {
319
331
  }
320
332
  return keccak_256(concatBytes(EVIDENCE_BINDING_DOMAIN, tokenHash, evidenceHash, evidenceKeyId));
321
333
  }
334
+ const isU32 = (n) => Number.isSafeInteger(n) && n >= 0 && n <= 0xffff_ffff;
322
335
  /**
323
336
  * Mirror of the Rust `verify_evidence_binding`: every signature must come from a DRAWN
324
- * verifier in `set` and verify over {@link evidenceBindingMessage}; distinct signers are
325
- * counted once and must satisfy `quorum` of the drawn committee. Throws on any failure;
326
- * returns the verified indexes.
337
+ * verifier in `set` and verify (strict, non-ZIP-215) over {@link evidenceBindingMessage};
338
+ * distinct signers are counted once and must satisfy `quorum` of the drawn committee.
339
+ * Throws on any failure; returns the verified indexes.
327
340
  *
328
341
  * @param opts - Token and evidence hashes, the signatures, the verifier set, the drawn committee and the quorum.
329
342
  */
330
343
  export function verifyEvidenceBinding(opts) {
331
344
  const { tokenHash, evidenceHash, evidenceKeyId, signatures, set, drawn, quorum } = opts;
332
- if (quorum === 0)
333
- throw new Error('evidence binding: quorum must be positive');
345
+ // Rust takes `quorum: u32` and `u32` indexes; a JS number does not, so the bounds are checked
346
+ // here. A negative or NaN quorum would otherwise be met by zero signatures.
347
+ if (!isU32(quorum) || quorum === 0)
348
+ throw new Error('evidence binding: quorum must be a positive 32-bit integer');
349
+ if (!Array.isArray(drawn) || !drawn.every(isU32))
350
+ throw new Error('evidence binding: drawn committee must be 32-bit indexes');
351
+ if (!Array.isArray(signatures))
352
+ throw new Error('evidence binding: signatures must be a list');
334
353
  const msg = evidenceBindingMessage(tokenHash, evidenceHash, evidenceKeyId);
335
354
  const verified = [];
336
355
  for (const { verifierIndex, signature } of signatures) {
356
+ if (!isU32(verifierIndex))
357
+ throw new Error('evidence binding: verifier index must be a 32-bit integer');
358
+ if (!(signature instanceof Uint8Array) || signature.length !== 64)
359
+ throw new Error(`evidence binding: signature from verifier index ${verifierIndex} must be 64 bytes`);
337
360
  if (!drawn.includes(verifierIndex))
338
361
  throw new Error(`evidence binding: index ${verifierIndex} is not in the drawn committee`);
339
362
  const pk = set.pubkeys.get(verifierIndex);
340
363
  if (!pk)
341
364
  throw new Error(`evidence binding: index ${verifierIndex} is not in the verifier set`);
342
- if (!ed25519.verify(signature, msg, pk))
365
+ if (!ed25519.verify(signature, msg, pk, { zip215: false }))
343
366
  throw new Error(`evidence binding: invalid signature from verifier index ${verifierIndex}`);
344
367
  if (!verified.includes(verifierIndex))
345
368
  verified.push(verifierIndex);
@@ -374,8 +397,13 @@ export function bindingFromWire(s) {
374
397
  *
375
398
  * @param p - Compound token payload, excluding signatures.
376
399
  * @param signatures - Verifier signatures to include in the wire object.
400
+ * @param statusAttestations - Optional revocation-status attestations, carried beside the signatures and never hashed. Validated strictly; an empty list is omitted.
377
401
  */
378
- export function assembleCompoundToken(p, signatures) {
402
+ export function assembleCompoundToken(p, signatures, statusAttestations) {
403
+ compoundTokenCanonicalBytes(p);
404
+ const attestations = statusAttestations?.length
405
+ ? assertStatusAttestationsWire(statusAttestations.map(statusAttestationToWire), p.verifierIndexes.length)
406
+ : undefined;
379
407
  return {
380
408
  token_type: p.tokenType,
381
409
  seed: bytesToHex(p.seed),
@@ -387,10 +415,13 @@ export function assembleCompoundToken(p, signatures) {
387
415
  ...(p.identityHash !== undefined ? { identity_hash: bytesToHex(p.identityHash) } : {}),
388
416
  ...(p.requestHash !== undefined ? { request_hash: bytesToHex(p.requestHash) } : {}),
389
417
  ...(bindingToWire(p.binding) !== undefined ? { binding: bindingToWire(p.binding) } : {}),
418
+ ...(p.paymentHash !== undefined ? { payment_hash: bytesToHex(p.paymentHash) } : {}),
419
+ ...(p.payment !== undefined ? { payment: p.payment } : {}),
390
420
  verifier_indexes: p.verifierIndexes,
391
421
  iat: Number(p.iat),
392
422
  exp: Number(p.exp),
393
423
  signatures: signatures.map(s => ({ verifier_index: s.verifierIndex, signature: bytesToHex(s.signature) })),
424
+ ...(attestations !== undefined ? { status_attestations: attestations } : {}),
394
425
  };
395
426
  }
396
427
  /**
@@ -399,7 +430,11 @@ export function assembleCompoundToken(p, signatures) {
399
430
  * @param w - Keeper JSON token representation to decode into byte fields.
400
431
  */
401
432
  export function decodeCompoundToken(w) {
402
- return {
433
+ // Validated, never hashed: the attestations sit beside the signed bytes.
434
+ const attestations = w.status_attestations == null
435
+ ? undefined
436
+ : assertStatusAttestationsWire(w.status_attestations, w.verifier_indexes.length).map(statusAttestationFromWire);
437
+ const result = {
403
438
  tokenType: w.token_type,
404
439
  seed: hexToBytes(w.seed),
405
440
  epoch: w.epoch,
@@ -410,9 +445,211 @@ export function decodeCompoundToken(w) {
410
445
  ...(w.identity_hash !== undefined ? { identityHash: hexToBytes(w.identity_hash) } : {}),
411
446
  ...(w.request_hash !== undefined ? { requestHash: hexToBytes(w.request_hash) } : {}),
412
447
  binding: bindingFromWire(w.binding),
448
+ ...(w.payment_hash != null ? { paymentHash: hexToBytes(w.payment_hash) } : {}),
449
+ ...(w.payment != null ? { payment: w.payment } : {}),
413
450
  verifierIndexes: w.verifier_indexes,
414
451
  iat: w.iat,
415
452
  exp: w.exp,
416
453
  signatures: w.signatures.map(s => ({ verifierIndex: s.verifier_index, signature: hexToBytes(s.signature) })),
454
+ ...(attestations !== undefined ? { statusAttestations: attestations } : {}),
417
455
  };
456
+ compoundTokenCanonicalBytes(result);
457
+ return result;
458
+ }
459
+ // Revocation-status freshness (mirrors `keykeeper_committee::status_attestation`)
460
+ //
461
+ // A drawn verifier signs, beside its token signature, a SEPARATE statement that the holder's
462
+ // credential status it relied on was fresh until `status_until`:
463
+ //
464
+ // keccak256("keykeeper/committee-status-attestation/v1" || token_hash(32)
465
+ // || verifier_index(u32 BE) || status_until(i64 BE))
466
+ //
467
+ // with the same Ed25519 committee key. Keepers accept the grant while
468
+ // `now <= status_until + STATUS_SKEW_SECS` for a quorum of counted verifiers. The statement is
469
+ // NOT part of the token payload: the canonical bytes, the token hash and the pinned
470
+ // `committee-token-vectors.json` are unchanged.
471
+ const STATUS_ATTESTATION_DOMAIN_BYTES = new TextEncoder().encode('keykeeper/committee-status-attestation/v1');
472
+ /** Domain separator of the status-freshness statement (new name, `/v1`). */
473
+ export const STATUS_ATTESTATION_DOMAIN = 'keykeeper/committee-status-attestation/v1';
474
+ /** Decided revocation bound: no keeper accepts a grant later than `R + 60 s`. */
475
+ export const REVOCATION_BOUND_SECS = 60;
476
+ /** The only skew a keeper allows past `status_until` (reserved inside the 60 s bound). */
477
+ export const STATUS_SKEW_SECS = 5;
478
+ /** The verifier's attestation cache bound: `REVOCATION_BOUND_SECS - STATUS_SKEW_SECS`. */
479
+ export const STATUS_CACHE_BOUND_SECS = REVOCATION_BOUND_SECS - STATUS_SKEW_SECS;
480
+ /** Longest usable window a verifier may attest (`55 - 10`). */
481
+ export const MAX_STATUS_WINDOW_SECS = 45;
482
+ /** Default attested window (`[committee] status_window_secs`). */
483
+ export const DEFAULT_STATUS_WINDOW_SECS = 30;
484
+ /** Most attestations one token may carry (mirrors the keeper cap). */
485
+ export const MAX_STATUS_ATTESTATIONS = 64;
486
+ /** Stable keeper refusal code: attestations present but fewer than a quorum valid and fresh. */
487
+ export const STATUS_STALE_CODE = 'revocation_status_stale';
488
+ /** Stable keeper refusal code: the keeper requires attestations and the grant carries none. */
489
+ export const STATUS_MISSING_CODE = 'revocation_status_missing';
490
+ /**
491
+ * Stable client preflight code: attestations are present but malformed, duplicated, over the cap
492
+ * or carry a bad signature from a counted verifier (a keeper refuses these without a stable code).
493
+ */
494
+ export const STATUS_INVALID_CODE = 'revocation_status_invalid';
495
+ const invalidStatus = (message) => new RevocationStatusPreflightError({ code: STATUS_INVALID_CODE, message });
496
+ const SIGNATURE_HEX = /^0x[0-9a-fA-F]{128}$/;
497
+ const U32_MAX = 0xffff_ffff;
498
+ function statusAttestationToWire(a) {
499
+ return { verifier_index: a.verifierIndex, status_until: a.statusUntil, signature: bytesToHex(a.signature) };
500
+ }
501
+ function statusAttestationFromWire(w) {
502
+ return { verifierIndex: w.verifier_index, statusUntil: w.status_until, signature: hexToBytes(w.signature) };
503
+ }
504
+ function assertAttestationInputs(tokenHash, verifierIndex, statusUntil) {
505
+ if (!(tokenHash instanceof Uint8Array) || tokenHash.length !== 32)
506
+ throw new Error('status attestation token hash must be 32 bytes');
507
+ if (!Number.isSafeInteger(verifierIndex) || verifierIndex < 0 || verifierIndex > U32_MAX)
508
+ throw new Error('status attestation verifier_index must be a u32');
509
+ if (!Number.isSafeInteger(statusUntil))
510
+ throw new Error('status attestation status_until must be a safe integer');
511
+ }
512
+ /**
513
+ * The 32-byte digest a drawn verifier signs to attest credential-status freshness for one token:
514
+ * `keccak256(DOMAIN || tokenHash || verifierIndex(u32 BE) || statusUntil(i64 BE))`.
515
+ * Byte-identical to the reference `status_attestation_hash`.
516
+ *
517
+ * @param tokenHash - 32-byte compound token hash ({@link compoundTokenHash}).
518
+ * @param verifierIndex - Zero-based verifier registry index.
519
+ * @param statusUntil - Unix seconds the verifier vouches until.
520
+ */
521
+ export function statusAttestationHash(tokenHash, verifierIndex, statusUntil) {
522
+ assertAttestationInputs(tokenHash, verifierIndex, statusUntil);
523
+ return keccak_256(concatBytes(STATUS_ATTESTATION_DOMAIN_BYTES, tokenHash, u32be(verifierIndex), i64be(statusUntil)));
524
+ }
525
+ /**
526
+ * Verify ONE attestation's Ed25519 signature under the verifier's committee key over `tokenHash`
527
+ * (no freshness, no quorum) - what a relay checks before forwarding it.
528
+ *
529
+ * @param pubkey - 32-byte Ed25519 committee public key of `attestation.verifierIndex`.
530
+ * @param tokenHash - 32-byte compound token hash.
531
+ * @param attestation - Decoded attestation.
532
+ * @returns Whether the signature verifies (strict: non-canonical encodings refused).
533
+ */
534
+ export function verifyStatusAttestation(pubkey, tokenHash, attestation) {
535
+ try {
536
+ if (pubkey.length !== 32 || attestation.signature.length !== 64)
537
+ return false;
538
+ const digest = statusAttestationHash(tokenHash, attestation.verifierIndex, attestation.statusUntil);
539
+ return ed25519.verify(attestation.signature, digest, pubkey, { zip215: false });
540
+ }
541
+ catch {
542
+ return false;
543
+ }
544
+ }
545
+ /**
546
+ * Verify a token's status attestations exactly as a keeper does and return the effective status
547
+ * deadline (the quorum-th largest attested `status_until`). Throws on a duplicate index, an
548
+ * oversize list, a bad signature from a counted verifier, or fewer than `quorum` attestations
549
+ * fresh at `now` (`now <= status_until + STATUS_SKEW_SECS`; the token leeway is NOT applied).
550
+ *
551
+ * @param opts - Token hash, attestations, counted signers, verifier set, quorum and time.
552
+ */
553
+ export function verifyStatusAttestations(opts) {
554
+ const { tokenHash, attestations, counted, set, quorum, now } = opts;
555
+ if (attestations.length > MAX_STATUS_ATTESTATIONS)
556
+ throw invalidStatus(`more than ${MAX_STATUS_ATTESTATIONS} status attestations`);
557
+ const seen = new Set(), valid = [];
558
+ for (const a of attestations) {
559
+ if (seen.has(a.verifierIndex))
560
+ throw invalidStatus(`duplicate status attestation from verifier index ${a.verifierIndex}`);
561
+ seen.add(a.verifierIndex);
562
+ if (!counted.includes(a.verifierIndex))
563
+ continue;
564
+ const pk = set.pubkeys.get(a.verifierIndex);
565
+ if (!pk || !verifyStatusAttestation(pk, tokenHash, a))
566
+ throw invalidStatus(`invalid status attestation signature from verifier index ${a.verifierIndex}`);
567
+ valid.push(a.statusUntil);
568
+ }
569
+ valid.sort((a, b) => b - a);
570
+ const needed = Math.max(1, quorum);
571
+ const deadline = valid[needed - 1];
572
+ if (deadline !== undefined && now <= deadline + STATUS_SKEW_SECS)
573
+ return deadline;
574
+ const fresh = valid.filter(until => now <= until + STATUS_SKEW_SECS).length;
575
+ throw new RevocationStatusPreflightError({ code: STATUS_STALE_CODE,
576
+ message: `revocation status freshness (${STATUS_STALE_CODE}): ${fresh} of the token's verifiers attest the holder's credential status fresh at ${now}, need ${quorum}; present again for a fresh grant` });
577
+ }
578
+ /**
579
+ * The registry indexes whose Ed25519 signature over the token's own canonical hash verifies under
580
+ * `set` (strict), distinct and drawn. Mirrors the reference `signers_that_verify`: no rule, draw,
581
+ * lifetime or quorum check - only "which signatures are real", for counting status attestations.
582
+ *
583
+ * @param token - Decoded token (payload + signatures).
584
+ * @param set - Anchored verifier keys.
585
+ */
586
+ export function signersThatVerify(token, set) {
587
+ const hash = compoundTokenHash(token), out = [];
588
+ for (const { verifierIndex, signature } of token.signatures) {
589
+ const pk = set.pubkeys.get(verifierIndex);
590
+ if (!pk || out.includes(verifierIndex) || !token.verifierIndexes.includes(verifierIndex))
591
+ continue;
592
+ try {
593
+ if (ed25519.verify(signature, hash, pk, { zip215: false }))
594
+ out.push(verifierIndex);
595
+ }
596
+ catch { /* not counted */ }
597
+ }
598
+ return out;
599
+ }
600
+ /**
601
+ * The keeper's status-freshness rule as a REQUIRED client preflight, run before any keeper call:
602
+ * a missing list throws `revocation_status_missing` (unless `allowMissing`), fewer than `quorum`
603
+ * fresh counted attestations `revocation_status_stale`, a malformed or forged list
604
+ * `revocation_status_invalid` - each a {@link RevocationStatusPreflightError}.
605
+ *
606
+ * @param opts - Token hash, attestations, counted signers, verifier set, quorum, time and opt-out.
607
+ */
608
+ export function requireStatusAttestations(opts) {
609
+ const { attestations, allowMissing, ...rest } = opts;
610
+ if (attestations === undefined || attestations.length === 0) {
611
+ if (allowMissing === true) {
612
+ console.warn(`${STATUS_MISSING_CODE} accepted by allowMissingStatusAttestations; a keeper outside its migration window will refuse this grant`);
613
+ return { kind: 'missing-accepted' };
614
+ }
615
+ throw new RevocationStatusPreflightError({ code: STATUS_MISSING_CODE,
616
+ message: `revocation status freshness (${STATUS_MISSING_CODE}): the grant carries no revocation-status attestations; nothing was sent - present again for a fresh grant` });
617
+ }
618
+ return { kind: 'fresh', statusUntil: verifyStatusAttestations({ ...rest, attestations }) };
619
+ }
620
+ /**
621
+ * Strictly validate an untrusted `status_attestations` value: an array of at most
622
+ * `maxEntries` (and {@link MAX_STATUS_ATTESTATIONS}) objects with EXACTLY
623
+ * `{verifier_index: u32, status_until: safe integer, signature: "0x" + 128 hex}` and distinct
624
+ * indexes. Returns a fresh copy (the value a keeper receives unchanged).
625
+ *
626
+ * @param raw - Untrusted wire value.
627
+ * @param maxEntries - Upper bound, normally the token's committee draw length.
628
+ */
629
+ export function assertStatusAttestationsWire(raw, maxEntries = MAX_STATUS_ATTESTATIONS) {
630
+ if (!Array.isArray(raw))
631
+ throw invalidStatus('status_attestations is not an array');
632
+ if (raw.length > Math.min(maxEntries, MAX_STATUS_ATTESTATIONS))
633
+ throw invalidStatus('status_attestations exceeds the committee draw');
634
+ const seen = new Set();
635
+ return raw.map((entry) => {
636
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry))
637
+ throw invalidStatus('a status attestation is not an object');
638
+ const e = entry;
639
+ const keys = Object.keys(e);
640
+ if (keys.length !== 3 || !['verifier_index', 'status_until', 'signature'].every(k => Object.hasOwn(e, k))) {
641
+ throw invalidStatus('a status attestation is not exactly {verifier_index, status_until, signature}');
642
+ }
643
+ const index = e.verifier_index, until = e.status_until, signature = e.signature;
644
+ if (typeof index !== 'number' || !Number.isSafeInteger(index) || index < 0 || index > U32_MAX)
645
+ throw invalidStatus('status attestation verifier_index is not a u32');
646
+ if (typeof until !== 'number' || !Number.isSafeInteger(until))
647
+ throw invalidStatus('status attestation status_until is not a safe integer');
648
+ if (typeof signature !== 'string' || !SIGNATURE_HEX.test(signature))
649
+ throw invalidStatus('status attestation signature is not 0x + 64 bytes of hex');
650
+ if (seen.has(index))
651
+ throw invalidStatus(`duplicate status attestation from verifier index ${index}`);
652
+ seen.add(index);
653
+ return { verifier_index: index, status_until: until, signature };
654
+ });
418
655
  }
@@ -0,0 +1,70 @@
1
+ declare const G1: import("@noble/curves/abstract/weierstrass").WeierstrassPointCons<bigint>, G2: import("@noble/curves/abstract/weierstrass").WeierstrassPointCons<import("@noble/curves/abstract/tower").Fp2>;
2
+ type G1Point = InstanceType<typeof G1>;
3
+ type G2Point = InstanceType<typeof G2>;
4
+ /** A BN254 encoding or verification failure; `reason` names the operand. */
5
+ export declare class Bn254Error extends Error {
6
+ constructor(message: string);
7
+ }
8
+ /**
9
+ * Map a 32-byte digest to G1 exactly as the Solidity verifier and the Rust signer do.
10
+ * @param digest - 32-byte message digest.
11
+ */
12
+ export declare function hashToG1(digest: Uint8Array): G1Point;
13
+ /**
14
+ * Decode a 64-byte `x || y` G1 point; all-zero is infinity (the EVM spelling), returned as ZERO.
15
+ * @param bytes - 64-byte EVM encoding.
16
+ */
17
+ export declare function decodeG1(bytes: Uint8Array): G1Point;
18
+ /**
19
+ * Encode a G1 point as `x || y` (all-zero for infinity).
20
+ * @param point - G1 point.
21
+ */
22
+ export declare function encodeG1(point: G1Point): Uint8Array;
23
+ /**
24
+ * Decode a 128-byte G2 point (imaginary part first), subgroup-checked: BN254's G2 has a large
25
+ * cofactor, so on-curve alone is not enough. All-zero is infinity.
26
+ * @param bytes - 128-byte EVM encoding.
27
+ */
28
+ export declare function decodeG2(bytes: Uint8Array): G2Point;
29
+ /**
30
+ * Encode a G2 point (imaginary part first; all-zero for infinity).
31
+ * @param point - G2 point.
32
+ */
33
+ export declare function encodeG2(point: G2Point): Uint8Array;
34
+ /**
35
+ * Verify a 64-byte signature over `digest` against a 128-byte G2 key: `e(-sigma, g2) * e(H(m), key) == 1`.
36
+ * Infinity on either side is refused (it would satisfy the equation trivially).
37
+ * @param key - Group public key or a member's verifying share.
38
+ * @param digest - 32-byte digest.
39
+ * @param signature - 64-byte G1 signature or partial.
40
+ */
41
+ export declare function verifyBn254(key: Uint8Array, digest: Uint8Array, signature: Uint8Array): boolean;
42
+ /** One member's partial over a digest, with the verifying share it is checked against. */
43
+ export interface Bn254Partial {
44
+ /** Nonzero member identifier (the Lagrange abscissa). */
45
+ identifier: number;
46
+ /** 64-byte G1 partial `s_i * H(digest)`. */
47
+ partial: Uint8Array;
48
+ /** 128-byte G2 verifying share `s_i * g2`. */
49
+ verifyingShare: Uint8Array;
50
+ }
51
+ /**
52
+ * Lagrange-interpolate exactly `threshold` partials at zero, WITHOUT any verification: the result
53
+ * is a signature only if the caller then verifies it against the group key (one pairing check,
54
+ * where {@link combineBn254} spends one per partial as well). Undefined when the identifiers are
55
+ * invalid or repeated, too few partials are given, or a partial is not a valid G1 point.
56
+ * @param partials - Distinct members' partials (the first `threshold` are used).
57
+ * @param threshold - k.
58
+ */
59
+ export declare function interpolateBn254(partials: readonly Pick<Bn254Partial, 'identifier' | 'partial'>[], threshold: number): Uint8Array | undefined;
60
+ /**
61
+ * Lagrange-combine exactly `threshold` partials (each pre-verified against its own verifying share,
62
+ * so a byzantine member is named, not merely detected) and verify the aggregate against the group
63
+ * key: a below-threshold or mismatched set interpolates to the wrong point and is caught there.
64
+ * @param groupKey - 128-byte group public key.
65
+ * @param digest - 32-byte digest.
66
+ * @param partials - Distinct members' partials.
67
+ * @param threshold - k; exactly k partials are combined.
68
+ */
69
+ export declare function combineBn254(groupKey: Uint8Array, digest: Uint8Array, partials: readonly Bn254Partial[], threshold: number): Uint8Array;
70
+ export {};