@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,6 @@
1
+ import { kemContentDigest, recipientPayloadDigest } from '../crypto/recipient.js';
2
+ import { decryptWithCommitteePartials } from '../decryption/sealed.js';
3
+ import { sha256 } from '@noble/hashes/sha256';
1
4
  // High-level committee-authorization orchestration.
2
5
  //
3
6
  // The low-level pieces already exist: `gatherCommitteeToken` (fan out + assemble) and
@@ -12,11 +15,10 @@
12
15
  // or raw viem. Proofs are OPTIONAL: when the verifier directory lacks operator/pubkey or no
13
16
  // snapshot is anchored, the token is submitted without proofs and the keeper falls back to its
14
17
  // configured verifier set.
15
- import { gatherCommitteeToken, committeeSign, committeeDecrypt, requestIbeExtractionPartials, } from './client.js';
18
+ import { gatherCommitteeToken, committeeSign, requestIbeExtractionPartials, } from './client.js';
16
19
  import { ibeCombineDecrypt, ibeCombineExtract } from '../crypto/ibe.js';
17
- import { merkleRoot, merkleProof, verifierLeaf, clientBindingHash, compoundTokenHash, decodeCompoundToken, } from './token.js';
20
+ import { merkleRoot, merkleProof, verifierLeaf, } from './token.js';
18
21
  import { hexToBytes, bytesToHex } from '../crypto/hex.js';
19
- import { ed25519 } from '@noble/curves/ed25519';
20
22
  import { createHolderProof } from '../auth/holderProof.js';
21
23
  /**
22
24
  * One holder proof-of-possession per drawn verifier: fetch THAT verifier's nonce, sign it
@@ -36,17 +38,6 @@ export function holderProofPerVerifier(opts) {
36
38
  ttlSecs: opts.ttlSecs,
37
39
  });
38
40
  }
39
- /**
40
- * A {@link ClientSigner} from a 32-byte ed25519 secret key (the common `did:key` holder).
41
- *
42
- * @param secretKey - 32-byte Ed25519 secret seed used to sign client request bindings.
43
- */
44
- export function ed25519ClientSigner(secretKey) {
45
- return {
46
- publicKey: ed25519.getPublicKey(secretKey),
47
- sign: (bindingHash) => ed25519.sign(bindingHash, secretKey),
48
- };
49
- }
50
41
  function bytesEqual(a, b) {
51
42
  return a.length === b.length && a.every((x, i) => x === b[i]);
52
43
  }
@@ -128,8 +119,10 @@ export function buildVerifierProofs(verifiers, registrySize, signerIndexes, snap
128
119
  export async function pinnedDraw(chain, latest, epochLag = 0) {
129
120
  const lag = Math.max(0, Math.min(1, Math.floor(epochLag)));
130
121
  const epoch = Math.max(0, latest - lag);
122
+ // The seed OF that epoch when the reads can say so: `seed()` is the current seed, which a beacon
123
+ // push between the epoch read and this one makes N+1's (P6).
131
124
  if (epoch === latest)
132
- return { epoch, seed: toBytes32(await chain.seed()) };
125
+ return { epoch, seed: toBytes32(await (chain.seedAt ? chain.seedAt(BigInt(epoch)) : chain.seed())) };
133
126
  if (!chain.seedAt)
134
127
  throw new Error('epochLag needs chain.seedAt (ThresholdRandomBeacon.seedAt); adapt the chain reads with committeeChainReadsFromClient');
135
128
  return { epoch, seed: toBytes32(await chain.seedAt(BigInt(epoch))) };
@@ -146,35 +139,45 @@ export async function requestCommitteeToken(opts) {
146
139
  'A verifier with `require_holder_binding = false` will accept the request without one — ' +
147
140
  'pass `allowNoHolderProof: true` to say so deliberately.');
148
141
  }
149
- const [epochRaw, policy] = await Promise.all([opts.chain.epoch(), opts.chain.verifierPolicy(slotId)]);
150
- const { epoch, seed } = await pinnedDraw(opts.chain, Number(epochRaw), opts.epochLag);
142
+ // P6 (robustness audit 2026-11-13): the draw - epoch, its seed and its anchored snapshot - comes
143
+ // from ONE block when the reads can do that; otherwise the seed is that epoch's own. The registry
144
+ // size (the draw modulus) is ALWAYS the anchored snapshot's - the value every verifier and keeper
145
+ // derives - never the directory length, and a failed snapshot read is an error, never a fallback.
146
+ const [policy, drawn] = await Promise.all([opts.chain.verifierPolicy(slotId), (async () => {
147
+ if (opts.chain.drawAt) {
148
+ const d = await opts.chain.drawAt(opts.epochLag);
149
+ return { epoch: d.epoch, seed: toBytes32(d.seed), snap: { root: d.root, size: d.size } };
150
+ }
151
+ const { epoch, seed } = await pinnedDraw(opts.chain, Number(await opts.chain.epoch()), opts.epochLag);
152
+ if (!opts.chain.snapshot)
153
+ throw new Error('requestCommitteeToken: the chain reads need snapshot (VerifierSetRegistry.snapshotAt) - the draw runs over the anchored verifier snapshot, never the directory size');
154
+ const snap = await opts.chain.snapshot(BigInt(epoch)).catch((cause) => {
155
+ throw new Error(`no anchored verifier snapshot readable at epoch ${epoch}: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
156
+ });
157
+ return { epoch, seed, snap };
158
+ })()]);
159
+ const { epoch, seed, snap } = drawn;
151
160
  const committee = Number(policy[0]);
152
161
  const quorum = Number(policy[1]);
153
162
  if (committee === 0) {
154
163
  throw new Error(`slot ${slotId.slice(0, 10)}… has no verifierPolicy (committee path not wired); use the JWT path`);
155
164
  }
156
- // Registry size (the committee-draw modulus): the anchored snapshot's size when available -
157
- // it's the value the verifier/keeper agree on - else the directory length.
158
- let registrySize = opts.verifiers.length;
159
- let snapshotRoot;
160
- if (opts.chain.snapshot) {
161
- const snap = await opts.chain.snapshot(BigInt(epoch)).catch(() => null);
162
- if (snap && snap.size > 0) {
163
- registrySize = snap.size;
164
- snapshotRoot = toBytes32(snap.root);
165
- }
166
- }
165
+ if (!snap || !(snap.size > 0))
166
+ throw new Error(`no anchored verifier snapshot at epoch ${epoch}: the committee draw needs it`);
167
+ const registrySize = snap.size;
168
+ const snapshotRoot = toBytes32(snap.root);
167
169
  if (registrySize < committee) {
168
170
  throw new Error(`active verifier set (${registrySize}) is smaller than the committee size (${committee})`);
169
171
  }
170
172
  const now = opts.nowSecs ?? Math.floor(Date.now() / 1000);
171
173
  const iat = now - 5;
172
- const exp = now + (opts.ttlSecs ?? 300);
174
+ const exp = opts.payment?.expires ?? now + (opts.ttlSecs ?? 300);
173
175
  // Taken from the REFERENCE reply - the one whose ruleHash built the
174
176
  // token - so the version and the hash describe one evaluation. Verifiers that
175
177
  // straddle an activation legitimately disagree, and pairing a version from one
176
178
  // with a hash from another would describe a state that never existed.
177
179
  let ruleVersion;
180
+ let evidenceCt;
178
181
  // A per-verifier proof function is resolved inside the gather, against each verifier's
179
182
  // own URL; a string is the legacy single proof (fine when holder binding is off).
180
183
  const byIndex = new Map(opts.verifiers.map(v => [v.index, v]));
@@ -182,13 +185,16 @@ export async function requestCommitteeToken(opts) {
182
185
  ? (v) => opts.holderProof(byIndex.get(v.index) ?? { index: v.index, url: v.url })
183
186
  : undefined;
184
187
  const token = await gatherCommitteeToken({
185
- verifiers: opts.verifiers.map(v => ({ index: v.index, url: v.url })),
188
+ verifiers: opts.verifiers.map(v => ({ index: v.index, url: v.url, ...(v.pubkey ? { pubkey: v.pubkey } : {}) })),
186
189
  quorum,
187
190
  holderProofFor,
191
+ onEvidence: ct => { evidenceCt = ct; },
188
192
  onReplies: (_all, reference) => {
189
193
  ruleVersion = reference.ruleVersion;
190
194
  },
191
195
  authorize: {
196
+ binding: opts.binding,
197
+ payment: opts.payment,
192
198
  holder: opts.holder,
193
199
  credentials: opts.credentials,
194
200
  holderProof: typeof opts.holderProof === 'string' ? opts.holderProof : '',
@@ -205,16 +211,7 @@ export async function requestCommitteeToken(opts) {
205
211
  });
206
212
  const signerIndexes = token.signatures.map(s => s.verifier_index);
207
213
  const verifierProofs = buildVerifierProofs(opts.verifiers, registrySize, signerIndexes, snapshotRoot);
208
- // Sign the request bundle (bound to the token's canonical hash + the slot).
209
- let clientPubkey;
210
- let clientSignature;
211
- if (opts.clientSigner) {
212
- const tokenHash = compoundTokenHash(decodeCompoundToken(token));
213
- const binding = clientBindingHash(hexToBytes(slotId), tokenHash);
214
- clientSignature = await opts.clientSigner.sign(binding);
215
- clientPubkey = opts.clientSigner.publicKey;
216
- }
217
- return { token, committee, quorum, registrySize, seed, epoch, verifierProofs, clientPubkey, clientSignature, ruleVersion };
214
+ return { token, committee, quorum, registrySize, seed, epoch, verifierProofs, ruleVersion, ...(evidenceCt !== undefined ? { evidenceCt } : {}) };
218
215
  }
219
216
  /**
220
217
  * One-call committee-authorized threshold sign: resolve token (+proofs) then POST to the keeper.
@@ -222,17 +219,17 @@ export async function requestCommitteeToken(opts) {
222
219
  * @param opts - Token request settings, keeper endpoint and message to sign.
223
220
  */
224
221
  export async function committeeSignRequest(opts) {
225
- const { token, verifierProofs, clientPubkey, clientSignature } = await requestCommitteeToken(opts);
222
+ const { token, verifierProofs, evidenceCt } = await requestCommitteeToken(opts);
226
223
  const signOpts = {
227
224
  nodeUrl: opts.nodeUrl,
228
225
  committeeToken: token,
226
+ evidenceCt,
229
227
  message: opts.message,
230
228
  signingSet: opts.signingSet,
231
229
  userSignature: opts.userSignature,
232
230
  targetKeykeeper: opts.targetKeykeeper,
233
231
  verifierProofs,
234
- clientPubkey,
235
- clientSignature,
232
+ approveExecution: opts.approveExecution,
236
233
  };
237
234
  return committeeSign(signOpts);
238
235
  }
@@ -242,22 +239,13 @@ export async function committeeSignRequest(opts) {
242
239
  * @param opts - Token request settings, keeper endpoint, ciphertext and associated data.
243
240
  */
244
241
  export async function committeeDecryptRequest(opts) {
245
- const { token, verifierProofs, clientPubkey, clientSignature } = await requestCommitteeToken(opts);
246
- const decOpts = {
247
- nodeUrl: opts.nodeUrl,
248
- committeeToken: token,
249
- ciphertext: opts.ciphertext,
250
- identity: opts.identity,
251
- decryptingSet: opts.decryptingSet,
252
- blsPeers: opts.blsPeers,
253
- userSignature: opts.userSignature,
254
- ciphertextEpoch: opts.ciphertextEpoch,
255
- targetKeykeeper: opts.targetKeykeeper,
256
- verifierProofs,
257
- clientPubkey,
258
- clientSignature,
259
- };
260
- return committeeDecrypt(decOpts);
242
+ if (!opts.recipient || !opts.binding || opts.ciphertextEpoch === undefined || !opts.verifyingShares || !opts.nodeUrls || opts.threshold === undefined)
243
+ throw new Error('Client recipient, bound authorization, epoch, authenticated sharing and keeper quorum are required');
244
+ const digest = recipientPayloadDigest(kemContentDigest(opts.ciphertext, opts.identity), opts.ciphertextEpoch, opts.recipient.recipient);
245
+ if (opts.binding.action !== 'decrypt' || !bytesEqual(opts.binding.payloadDigest, digest))
246
+ throw new Error('Authorization preimage differs from client recipient/ciphertext');
247
+ const { token, verifierProofs, evidenceCt } = await requestCommitteeToken(opts);
248
+ return decryptWithCommitteePartials({ nodeUrls: opts.nodeUrls, chainId: opts.binding.chainId, committeeToken: token, recipient: opts.recipient, ciphertextEpoch: opts.ciphertextEpoch, verifyingShares: opts.verifyingShares, threshold: opts.threshold, verifierProofs, evidenceCt, approveExecution: opts.approveExecution, signal: opts.signal, fetchImpl: opts.fetchImpl, userSignature: opts.userSignature, targetKeykeeper: opts.targetKeykeeper, ciphertext: opts.ciphertext, identity: opts.identity });
261
249
  }
262
250
  /**
263
251
  * Resolve an identity-scoped committee token, fan out for extraction partials, verify
@@ -272,8 +260,14 @@ export async function committeeDecryptRequest(opts) {
272
260
  */
273
261
  export async function ibeExtractRequest(opts) {
274
262
  const { partials, identityBytes } = await gatherIbePartials(opts);
275
- const vsMap = new Map(partials.map(p => [p.identifier, p.verifyingShareG2]));
276
- return ibeCombineExtract(vsMap, partials.map(p => ({ identifier: p.identifier, value: p.value })), identityBytes);
263
+ try {
264
+ const vsMap = new Map(partials.map(p => [p.identifier, p.verifyingShareG2]));
265
+ return ibeCombineExtract(vsMap, partials.map(p => ({ identifier: p.identifier, value: p.value })), identityBytes);
266
+ }
267
+ finally {
268
+ for (const p of partials)
269
+ p.value.fill(0);
270
+ }
277
271
  }
278
272
  /**
279
273
  * One-call identity-scoped decrypt (the read path): token to extraction fan-out
@@ -283,23 +277,40 @@ export async function ibeExtractRequest(opts) {
283
277
  */
284
278
  export async function ibeDecryptRequest(opts) {
285
279
  const { partials, identityBytes } = await gatherIbePartials(opts);
286
- const vsMap = new Map(partials.map(p => [p.identifier, p.verifyingShareG2]));
287
- return ibeCombineDecrypt(vsMap, partials.map(p => ({ identifier: p.identifier, value: p.value })), opts.ciphertext, identityBytes);
280
+ try {
281
+ const vsMap = new Map(partials.map(p => [p.identifier, p.verifyingShareG2]));
282
+ return ibeCombineDecrypt(vsMap, partials.map(p => ({ identifier: p.identifier, value: p.value })), opts.ciphertext, identityBytes);
283
+ }
284
+ finally {
285
+ for (const p of partials)
286
+ p.value.fill(0);
287
+ }
288
288
  }
289
289
  async function gatherIbePartials(opts) {
290
- const { token, verifierProofs, clientPubkey, clientSignature } = await requestCommitteeToken({
290
+ opts.signal?.throwIfAborted();
291
+ if (!opts.recipient || !opts.binding || opts.ciphertextEpoch === undefined || !opts.verifyingShares)
292
+ throw new Error('Client recipient, bound authorization, epoch and authenticated IBE sharing are required');
293
+ const digest = recipientPayloadDigest(sha256(new TextEncoder().encode(opts.identity)), opts.ciphertextEpoch, opts.recipient.recipient);
294
+ if (opts.binding.action !== 'ibe-extract' || !bytesEqual(opts.binding.payloadDigest, digest))
295
+ throw new Error('Authorization preimage differs from client recipient/identity');
296
+ const { token, verifierProofs, evidenceCt } = await requestCommitteeToken({
291
297
  ...opts,
292
298
  scopedIdentity: opts.identity,
293
299
  });
294
300
  const partials = await requestIbeExtractionPartials({
301
+ recipient: opts.recipient, chainId: opts.binding.chainId, verifyingShares: opts.verifyingShares,
295
302
  nodeUrls: opts.nodeUrls,
296
303
  committeeToken: token,
304
+ evidenceCt,
297
305
  identity: opts.identity,
298
306
  userSignature: opts.userSignature,
299
307
  ciphertextEpoch: opts.ciphertextEpoch,
300
308
  verifierProofs,
301
- clientPubkey,
302
- clientSignature,
309
+ approveExecution: opts.approveExecution,
310
+ threshold: opts.threshold,
311
+ timeoutMs: opts.timeoutMs,
312
+ signal: opts.signal,
313
+ fetchImpl: opts.fetchImpl,
303
314
  });
304
315
  return { partials, identityBytes: new TextEncoder().encode(opts.identity) };
305
316
  }
@@ -0,0 +1,320 @@
1
+ import { TasraError } from '../errors.js';
2
+ import { type VerifierSet } from './token.js';
3
+ /** Domain of the quorum-signed grant bytes. */
4
+ export declare const SESSION_GRANT_DOMAIN = "keykeeper-committee/session-grant/v1";
5
+ /** Domain of a single-operation session-key proof. */
6
+ export declare const SESSION_PROOF_DOMAIN = "keykeeper-committee/session-proof/v1";
7
+ /** Domain of a batch session-key proof; a one-item batch proof never verifies as a single proof. */
8
+ export declare const SESSION_BATCH_PROOF_DOMAIN = "keykeeper-committee/session-batch-proof/v1";
9
+ /** Domain of a refresh request signed by the session key (plan: phase 1's own domain). */
10
+ export declare const SESSION_REFRESH_DOMAIN = "keykeeper-committee/session-refresh/v1";
11
+ /** Domain of a revoke request signed by the session key. */
12
+ export declare const SESSION_REVOKE_DOMAIN = "keykeeper-committee/session-revoke/v1";
13
+ /** Most slots one grant may name. */
14
+ export declare const MAX_SESSION_SLOTS = 16;
15
+ /** Most items one batch proof may cover. */
16
+ export declare const MAX_BATCH_ITEMS = 64;
17
+ /** Longest `exp - iat`: the status attestation's longest window (the grant's `exp` is its status deadline). */
18
+ export declare const MAX_ACCESS_TTL_SECS = 45;
19
+ /** Default `exp - iat` when the SDK requests none. */
20
+ export declare const DEFAULT_ACCESS_TTL_SECS = 30;
21
+ /** Longest idle period between two refreshes (30 min). */
22
+ export declare const MAX_IDLE_TIMEOUT_SECS: number;
23
+ /** Longest a session may live from its opening presentation (12 h). */
24
+ export declare const MAX_ABSOLUTE_TTL_SECS: number;
25
+ /** `|proof.iat - now|` a keeper accepts. */
26
+ export declare const SESSION_PROOF_FRESHNESS_SECS = 30;
27
+ /** Bounds of a proof's `jti` (URL-safe characters only). */
28
+ export declare const MIN_JTI_LEN = 16;
29
+ /** Longest accepted proof `jti`, in characters. */
30
+ export declare const MAX_JTI_LEN = 64;
31
+ /** One slot a grant authorizes and the rule its committee evaluated (keccak256 of the RAW rule). */
32
+ export interface GrantSlot {
33
+ /** 32-byte slot identifier. */
34
+ slotId: Uint8Array;
35
+ /** keccak256 of the raw rule bytes, the same value a compound token carries. */
36
+ ruleHash: Uint8Array;
37
+ }
38
+ /** The bytes a verifier quorum signs. Build through {@link sessionGrantPayload}, which enforces every bound. */
39
+ export interface SessionGrantPayload {
40
+ /** Chain id the grant is valid on (u64). */
41
+ chainId: bigint;
42
+ /** 32-byte session identifier. */
43
+ sessionId: Uint8Array;
44
+ /** keccak256 of the holder DID the verifiers authenticated (32 bytes). */
45
+ holderHash: Uint8Array;
46
+ /** RFC 7638 SHA-256 JWK thumbprint of the session key (32 bytes). */
47
+ sessionKeyThumbprint: Uint8Array;
48
+ /** Binding strength byte (`BINDING_*` in token.ts). */
49
+ binding: number;
50
+ /** Always `decrypt` (KEM only). */
51
+ action: 'decrypt';
52
+ /** 32-byte beacon seed of `epoch`; every slot's committee is drawn on it. */
53
+ seed: Uint8Array;
54
+ /** Beacon epoch of the committee draw (u64). */
55
+ epoch: bigint;
56
+ /** Strictly ascending by slot id. */
57
+ slots: GrantSlot[];
58
+ /** Issued-at, Unix seconds. */
59
+ iat: number;
60
+ /** Expiry and status deadline, Unix seconds; `exp - iat` is at most {@link MAX_ACCESS_TTL_SECS}. */
61
+ exp: number;
62
+ /** Longest idle period between two refreshes, seconds. */
63
+ idleTimeoutSecs: number;
64
+ /** Latest expiry any refresh may reach, Unix seconds (at most `iat` + 12 h). */
65
+ absoluteExp: number;
66
+ }
67
+ /** A grant as received: payload plus `(verifierIndex, ed25519 signature)` pairs over its signing hash. */
68
+ export interface SessionGrant {
69
+ /** The signed payload. */
70
+ payload: SessionGrantPayload;
71
+ /** Verifier registry index and 64-byte Ed25519 signature over {@link sessionGrantHash}. */
72
+ signatures: {
73
+ verifierIndex: number;
74
+ signature: Uint8Array;
75
+ }[];
76
+ }
77
+ /** One granted slot on the wire. */
78
+ export interface GrantSlotWire {
79
+ /** 0x-prefixed 32-byte slot identifier. */
80
+ slot_id: string;
81
+ /** 0x-prefixed keccak256 of the slot's raw rule. */
82
+ rule_hash: string;
83
+ }
84
+ /** One verifier signature on the wire. */
85
+ export interface GrantSignatureWire {
86
+ /** Signer's index in the verifier registry. */
87
+ verifier_index: number;
88
+ /** 0x-prefixed 64-byte Ed25519 signature over the grant hash. */
89
+ signature: string;
90
+ }
91
+ /** The session grant as the verifier-agent returns it and the client sends it to keepers. */
92
+ export interface SessionGrantWire {
93
+ /** {@link SessionGrantPayload.chainId}. */
94
+ chain_id: number;
95
+ /** 0x-prefixed {@link SessionGrantPayload.sessionId}. */
96
+ session_id: string;
97
+ /** 0x-prefixed {@link SessionGrantPayload.holderHash}. */
98
+ holder_hash: string;
99
+ /** 0x-prefixed {@link SessionGrantPayload.sessionKeyThumbprint}. */
100
+ session_key_thumbprint: string;
101
+ /** Binding strength name: `unbound`, `holder_key` or `issuer_asserted`. */
102
+ binding: string;
103
+ /** Always `decrypt`. */
104
+ action: string;
105
+ /** 0x-prefixed {@link SessionGrantPayload.seed}. */
106
+ seed: string;
107
+ /** {@link SessionGrantPayload.epoch}. */
108
+ epoch: number;
109
+ /** Granted slots, strictly ascending by slot id. */
110
+ slots: GrantSlotWire[];
111
+ /** Issued-at, Unix seconds. */
112
+ iat: number;
113
+ /** Expiry and status deadline, Unix seconds. */
114
+ exp: number;
115
+ /** {@link SessionGrantPayload.idleTimeoutSecs}. */
116
+ idle_timeout_secs: number;
117
+ /** {@link SessionGrantPayload.absoluteExp}. */
118
+ absolute_exp: number;
119
+ /** Verifier quorum signatures over the grant hash. */
120
+ signatures: GrantSignatureWire[];
121
+ }
122
+ /** A session-key proof on the wire. */
123
+ export interface SessionProofWire {
124
+ /** Proof issued-at, Unix seconds. */
125
+ iat: number;
126
+ /** One-time proof identifier (16..64 URL-safe characters). */
127
+ jti: string;
128
+ /** 0x-prefixed 64-byte session-key signature (Ed25519, or P-256 `r ‖ s`). */
129
+ signature: string;
130
+ }
131
+ /**
132
+ * `session_grant` on `POST /v1/sessions` (session mode), exactly the agent's
133
+ * `SessionGrantRequestBody` (deny_unknown_fields): the public session JWK, the requested slots and
134
+ * the requested lifetimes in seconds.
135
+ */
136
+ export interface SessionGrantRequestWire {
137
+ session_key: SessionKeyJwk;
138
+ slots: string[];
139
+ access_ttl_secs: number;
140
+ idle_timeout_secs: number;
141
+ absolute_ttl_secs: number;
142
+ }
143
+ /** A refused grant, key or proof. `code` names the failed check. */
144
+ export declare class SessionGrantError extends TasraError {
145
+ /** Stable reason (`slot-not-granted`, `expired`, `quorum-not-met`, ...). */
146
+ readonly code: string;
147
+ constructor(code: string, message: string);
148
+ }
149
+ /**
150
+ * Unpadded base64url (RFC 4648 §5), as JWK members and jtis use.
151
+ * @param bytes - Bytes to encode.
152
+ */
153
+ export declare function toBase64Url(bytes: Uint8Array): string;
154
+ /**
155
+ * Validate and build a grant payload with the reference bounds: KEM decrypt only, 1..16 strictly
156
+ * ascending slots, `0 < exp - iat <= 45`, `1 <= idle <= 1800`, `exp <= absoluteExp <= iat + 12 h`.
157
+ * @param p - Every payload field.
158
+ */
159
+ export declare function sessionGrantPayload(p: SessionGrantPayload): SessionGrantPayload;
160
+ /**
161
+ * The canonical grant bytes (reference module docs give the layout).
162
+ * @param p - Grant payload.
163
+ */
164
+ export declare function sessionGrantCanonicalBytes(p: SessionGrantPayload): Uint8Array;
165
+ /**
166
+ * keccak256 of the canonical bytes: what each verifier signs and every session proof binds to.
167
+ * @param p - Grant payload.
168
+ */
169
+ export declare function sessionGrantHash(p: SessionGrantPayload): Uint8Array;
170
+ /**
171
+ * Decode a wire grant through the payload bounds. Refuses unknown fields and malformed hex.
172
+ * @param wire - Grant as received on the wire.
173
+ */
174
+ export declare function decodeSessionGrant(wire: SessionGrantWire): SessionGrant;
175
+ /**
176
+ * Encode a grant to its wire form (the inverse of {@link decodeSessionGrant}).
177
+ * @param grant - Decoded grant.
178
+ */
179
+ export declare function encodeSessionGrant(grant: SessionGrant): SessionGrantWire;
180
+ /** What a grant verified for ONE slot attests. */
181
+ export interface VerifiedSessionGrant {
182
+ /** The grant's signing hash; every session proof binds to it. */
183
+ grantHash: Uint8Array;
184
+ /** The slot the grant was verified for. */
185
+ slotId: Uint8Array;
186
+ /** {@link SessionGrantPayload.chainId}. */
187
+ chainId: bigint;
188
+ /** {@link SessionGrantPayload.holderHash}. */
189
+ holderHash: Uint8Array;
190
+ /** {@link SessionGrantPayload.sessionKeyThumbprint}. */
191
+ sessionKeyThumbprint: Uint8Array;
192
+ /** Binding strength byte (`BINDING_*` in token.ts). */
193
+ binding: number;
194
+ /** Grant issued-at, Unix seconds. */
195
+ iat: number;
196
+ /** Grant expiry and status deadline, Unix seconds. */
197
+ exp: number;
198
+ /** Distinct drawn verifiers of this slot whose signatures verified. */
199
+ verifiedSigners: number[];
200
+ }
201
+ /** The anchored set and the slot's own policy a grant is verified against. */
202
+ export interface VerifySessionGrantOptions {
203
+ /** Decoded grant to verify. */
204
+ grant: SessionGrant;
205
+ /** Active verifier set (registry size + index to Ed25519 key), established independently. */
206
+ set: VerifierSet;
207
+ /** Slot to be served. */
208
+ slotId: Uint8Array;
209
+ /** The slot's committee size and quorum. */
210
+ committee: number;
211
+ /** Signatures from the slot's drawn committee required. */
212
+ quorum: number;
213
+ /** keccak256 of the slot's raw rule, read independently. */
214
+ slotRuleHash: Uint8Array;
215
+ /**
216
+ * The beacon seed of the grant's epoch, `beacon.seedAt(epoch)`, read independently. A grant
217
+ * drawn on any other seed is refused: k colluding verifiers cannot pick a seed that draws
218
+ * themselves (C8 review F4).
219
+ */
220
+ seed: Uint8Array;
221
+ /** Current time, Unix seconds. */
222
+ now: number;
223
+ }
224
+ /**
225
+ * Verify a grant for serving one slot, with the reference steps in their order: the slot is
226
+ * granted with the slot's own rule; the quorum is non-zero; `now <= exp + 5` and `now + 5 >= iat`
227
+ * (the status deadline, never a token leeway); the grant's seed is the beacon seed of its epoch;
228
+ * the slot's OWN draw `(slot, epoch, seed)`; every
229
+ * signature verifies strictly (a forged one refuses the grant); a quorum of the slot's drawn
230
+ * committee signed. Signatures from outside the draw are checked but do not count.
231
+ * @param o - Grant, verifier set, slot policy and time.
232
+ */
233
+ export declare function verifySessionGrant(o: VerifySessionGrantOptions): VerifiedSessionGrant;
234
+ /** A public session key JWK (RFC 7517) with exactly the RFC 7638 required members. */
235
+ export type SessionKeyJwk = {
236
+ /** Key type. */
237
+ kty: 'OKP';
238
+ /** Curve. */
239
+ crv: 'Ed25519';
240
+ /** base64url public key (32 bytes). */
241
+ x: string;
242
+ } | {
243
+ /** Key type. */
244
+ kty: 'EC';
245
+ /** Curve. */
246
+ crv: 'P-256';
247
+ /** base64url x coordinate (32 bytes). */
248
+ x: string;
249
+ /** base64url y coordinate (32 bytes). */
250
+ y: string;
251
+ };
252
+ /**
253
+ * Parse a public session JWK; any private member or unsupported curve is refused.
254
+ * @param jwk - Candidate JWK.
255
+ */
256
+ export declare function parseSessionKeyJwk(jwk: unknown): SessionKeyJwk;
257
+ /**
258
+ * RFC 7638 thumbprint: SHA-256 of the required members in lexicographic order, no whitespace.
259
+ * @param jwk - Public session key.
260
+ */
261
+ export declare function sessionKeyThumbprint(jwk: SessionKeyJwk): Uint8Array;
262
+ /**
263
+ * Refuse a jti outside 16..64 URL-safe characters.
264
+ * @param jti - Proof identifier.
265
+ */
266
+ export declare function checkJti(jti: string): void;
267
+ /**
268
+ * `keccak256(SESSION_PROOF_DOMAIN ‖ grant_hash ‖ request_hash ‖ iat i64 BE ‖ len(jti) u8 ‖ jti)`.
269
+ * @param grantHash - 32-byte grant hash.
270
+ * @param requestHash - 32-byte request hash of the operation.
271
+ * @param iat - Proof issued-at, Unix seconds.
272
+ * @param jti - Proof identifier.
273
+ */
274
+ export declare function sessionProofHash(grantHash: Uint8Array, requestHash: Uint8Array, iat: number, jti: string): Uint8Array;
275
+ /**
276
+ * `keccak256(SESSION_BATCH_PROOF_DOMAIN ‖ grant_hash ‖ count u32 BE ‖ request_hash* ‖ iat ‖ len(jti) ‖ jti)`, items in order.
277
+ * @param grantHash - 32-byte grant hash.
278
+ * @param requestHashes - 1..64 32-byte request hashes, in batch order.
279
+ * @param iat - Proof issued-at, Unix seconds.
280
+ * @param jti - Proof identifier.
281
+ */
282
+ export declare function sessionBatchProofHash(grantHash: Uint8Array, requestHashes: Uint8Array[], iat: number, jti: string): Uint8Array;
283
+ /**
284
+ * The 32-byte hash a session key signs to refresh (or revoke) a grant:
285
+ * `keccak256(domain ‖ grant_hash ‖ seq u64 BE ‖ issued_at i64 BE)`.
286
+ * Integer inputs are encoded big-endian as u64/i64, as in the rest of the session-grant module.
287
+ * @param kind - Which control domain to use.
288
+ * @param grantHash - 32-byte grant hash.
289
+ * @param seq - Request sequence number (u64).
290
+ * @param issuedAt - Request time, Unix seconds.
291
+ */
292
+ export declare function sessionControlHash(kind: 'refresh' | 'revoke', grantHash: Uint8Array, seq: number, issuedAt: number): Uint8Array;
293
+ /**
294
+ * Verify a 64-byte session-key signature over a 32-byte hash exactly as a keeper does: Ed25519
295
+ * strict, or ES256 (ECDSA over SHA-256 of the hash, `r ‖ s`; high-S accepted like WebCrypto).
296
+ * @param jwk - Public session key.
297
+ * @param hash - 32-byte proof or control hash.
298
+ * @param signature - 64-byte signature.
299
+ */
300
+ export declare function verifySessionSignature(jwk: SessionKeyJwk, hash: Uint8Array, signature: Uint8Array): boolean;
301
+ /**
302
+ * A client-side check that a proof would pass a keeper's freshness and key checks.
303
+ * @param grant - Verified grant the proof binds to.
304
+ * @param jwk - Session key that signs the proof.
305
+ * @param proof - The proof's `iat` and `jti`.
306
+ * @param now - Current time, Unix seconds.
307
+ */
308
+ export declare function checkProofWindow(grant: VerifiedSessionGrant, jwk: SessionKeyJwk, proof: {
309
+ iat: number;
310
+ jti: string;
311
+ }, now: number): void;
312
+ /**
313
+ * Encode a proof for the wire.
314
+ * @param proof - Proof with its 64-byte signature.
315
+ */
316
+ export declare function encodeSessionProof(proof: {
317
+ iat: number;
318
+ jti: string;
319
+ signature: Uint8Array;
320
+ }): SessionProofWire;