@t3foundry/tasra-sdk 0.0.0-stage → 0.3.0-next.1

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 (322) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +94 -0
  4. package/README.md +137 -2
  5. package/SECURITY.md +115 -0
  6. package/dist/app/approvals.d.ts +50 -0
  7. package/dist/app/approvals.js +90 -0
  8. package/dist/app/authorization.d.ts +19 -0
  9. package/dist/app/authorization.js +20 -0
  10. package/dist/app/client.d.ts +231 -0
  11. package/dist/app/client.js +272 -0
  12. package/dist/app/creation.d.ts +73 -0
  13. package/dist/app/creation.js +77 -0
  14. package/dist/app/deployment.d.ts +36 -0
  15. package/dist/app/deployment.js +18 -0
  16. package/dist/app/identity.d.ts +211 -0
  17. package/dist/app/identity.js +287 -0
  18. package/dist/app/index.d.ts +22 -0
  19. package/dist/app/index.js +12 -0
  20. package/dist/app/manifest.d.ts +74 -0
  21. package/dist/app/manifest.js +120 -0
  22. package/dist/app/node.d.ts +30 -0
  23. package/dist/app/node.js +159 -0
  24. package/dist/app/ready-slot.d.ts +157 -0
  25. package/dist/app/ready-slot.js +199 -0
  26. package/dist/app/tasra-client.d.ts +125 -0
  27. package/dist/app/tasra-client.js +79 -0
  28. package/dist/app/viem.d.ts +10 -0
  29. package/dist/app/viem.js +32 -0
  30. package/dist/app/wallet.d.ts +126 -0
  31. package/dist/app/wallet.js +137 -0
  32. package/dist/auth/dpop.d.ts +86 -0
  33. package/dist/auth/dpop.js +142 -0
  34. package/dist/auth/holderProof.d.ts +102 -0
  35. package/dist/auth/holderProof.js +161 -0
  36. package/dist/auth/identityScope.d.ts +19 -0
  37. package/dist/auth/identityScope.js +82 -0
  38. package/dist/auth/index.d.ts +11 -0
  39. package/dist/auth/index.js +13 -0
  40. package/dist/auth/oid4vp.d.ts +230 -0
  41. package/dist/auth/oid4vp.js +780 -0
  42. package/dist/auth/rego/wasm/PINS.json +11 -0
  43. package/dist/auth/rego/wasm/keykeeper_rego_wasm.d.ts +76 -0
  44. package/dist/auth/rego/wasm/keykeeper_rego_wasm.js +379 -0
  45. package/dist/auth/rego/wasm/keykeeper_rego_wasm_bg.wasm +0 -0
  46. package/dist/auth/rego.d.ts +192 -0
  47. package/dist/auth/rego.js +492 -0
  48. package/dist/auth/verifier.d.ts +166 -0
  49. package/dist/auth/verifier.js +211 -0
  50. package/dist/chain/abis/accountantSetRegistry.d.ts +441 -0
  51. package/dist/chain/abis/accountantSetRegistry.js +574 -0
  52. package/dist/chain/abis/accountantSlashing.d.ts +2071 -0
  53. package/dist/chain/abis/accountantSlashing.js +2670 -0
  54. package/dist/chain/abis/bondingCurve.d.ts +398 -0
  55. package/dist/chain/abis/bondingCurve.js +521 -0
  56. package/dist/chain/abis/equivocationSlasher.d.ts +292 -0
  57. package/dist/chain/abis/equivocationSlasher.js +379 -0
  58. package/dist/chain/abis/fixedTasraPriceOracle.d.ts +52 -0
  59. package/dist/chain/abis/fixedTasraPriceOracle.js +72 -0
  60. package/dist/chain/abis/index.d.ts +12801 -0
  61. package/dist/chain/abis/index.js +64 -0
  62. package/dist/chain/abis/keeperShareRegistry.d.ts +519 -0
  63. package/dist/chain/abis/keeperShareRegistry.js +675 -0
  64. package/dist/chain/abis/keyRegistry.d.ts +2421 -0
  65. package/dist/chain/abis/keyRegistry.js +3114 -0
  66. package/dist/chain/abis/livenessRegistry.d.ts +402 -0
  67. package/dist/chain/abis/livenessRegistry.js +524 -0
  68. package/dist/chain/abis/mockEurc.d.ts +210 -0
  69. package/dist/chain/abis/mockEurc.js +276 -0
  70. package/dist/chain/abis/nodeRegistry.d.ts +1630 -0
  71. package/dist/chain/abis/nodeRegistry.js +2113 -0
  72. package/dist/chain/abis/platformExecutor.d.ts +328 -0
  73. package/dist/chain/abis/platformExecutor.js +429 -0
  74. package/dist/chain/abis/prevrandaoSaltBeacon.d.ts +16 -0
  75. package/dist/chain/abis/prevrandaoSaltBeacon.js +24 -0
  76. package/dist/chain/abis/serviceRegistry.d.ts +556 -0
  77. package/dist/chain/abis/serviceRegistry.js +719 -0
  78. package/dist/chain/abis/settlement.d.ts +1624 -0
  79. package/dist/chain/abis/settlement.js +2096 -0
  80. package/dist/chain/abis/tasraSwapRouter.d.ts +92 -0
  81. package/dist/chain/abis/tasraSwapRouter.js +122 -0
  82. package/dist/chain/abis/tasraToken.d.ts +455 -0
  83. package/dist/chain/abis/tasraToken.js +599 -0
  84. package/dist/chain/abis/tasraVestingVault.d.ts +165 -0
  85. package/dist/chain/abis/tasraVestingVault.js +215 -0
  86. package/dist/chain/abis/thresholdRandomBeacon.d.ts +378 -0
  87. package/dist/chain/abis/thresholdRandomBeacon.js +494 -0
  88. package/dist/chain/abis/treasury.d.ts +301 -0
  89. package/dist/chain/abis/treasury.js +390 -0
  90. package/dist/chain/abis/verifierSetRegistry.d.ts +445 -0
  91. package/dist/chain/abis/verifierSetRegistry.js +579 -0
  92. package/dist/chain/client.d.ts +212 -0
  93. package/dist/chain/client.js +576 -0
  94. package/dist/chain/commitmentRecovery.d.ts +21 -0
  95. package/dist/chain/commitmentRecovery.js +44 -0
  96. package/dist/chain/committeeClient.d.ts +102 -0
  97. package/dist/chain/committeeClient.js +137 -0
  98. package/dist/chain/deployments.d.ts +56 -0
  99. package/dist/chain/deployments.js +269 -0
  100. package/dist/chain/discovery.d.ts +49 -0
  101. package/dist/chain/discovery.js +107 -0
  102. package/dist/chain/events.d.ts +58 -0
  103. package/dist/chain/events.js +125 -0
  104. package/dist/chain/format.d.ts +25 -0
  105. package/dist/chain/format.js +51 -0
  106. package/dist/chain/index.d.ts +41 -0
  107. package/dist/chain/index.js +56 -0
  108. package/dist/chain/manifest.d.ts +165 -0
  109. package/dist/chain/manifest.js +132 -0
  110. package/dist/chain/network-profiles.json +75 -0
  111. package/dist/chain/networks.d.ts +73 -0
  112. package/dist/chain/networks.js +62 -0
  113. package/dist/chain/node.d.ts +44 -0
  114. package/dist/chain/node.js +176 -0
  115. package/dist/chain/offchain.d.ts +149 -0
  116. package/dist/chain/offchain.js +73 -0
  117. package/dist/chain/provisionRule.d.ts +164 -0
  118. package/dist/chain/provisionRule.js +212 -0
  119. package/dist/chain/registeredAgent.d.ts +64 -0
  120. package/dist/chain/registeredAgent.js +140 -0
  121. package/dist/chain/registeredOperation.d.ts +49 -0
  122. package/dist/chain/registeredOperation.js +136 -0
  123. package/dist/chain/registeredRelay.d.ts +206 -0
  124. package/dist/chain/registeredRelay.js +312 -0
  125. package/dist/chain/revertReason.d.ts +14 -0
  126. package/dist/chain/revertReason.js +62 -0
  127. package/dist/chain/ruleAmendment.d.ts +80 -0
  128. package/dist/chain/ruleAmendment.js +195 -0
  129. package/dist/chain/ruleAmendmentCore.d.ts +129 -0
  130. package/dist/chain/ruleAmendmentCore.js +152 -0
  131. package/dist/chain/ruleInput.d.ts +10 -0
  132. package/dist/chain/ruleInput.js +13 -0
  133. package/dist/chain/serviceIdentity.d.ts +176 -0
  134. package/dist/chain/serviceIdentity.js +237 -0
  135. package/dist/chain/serviceProfiles.d.ts +39 -0
  136. package/dist/chain/serviceProfiles.js +74 -0
  137. package/dist/chain/services.d.ts +141 -0
  138. package/dist/chain/services.js +79 -0
  139. package/dist/chain/slotClient.d.ts +55 -0
  140. package/dist/chain/slotClient.js +62 -0
  141. package/dist/chain/slotSeed.d.ts +31 -0
  142. package/dist/chain/slotSeed.js +98 -0
  143. package/dist/chain/write.d.ts +431 -0
  144. package/dist/chain/write.js +958 -0
  145. package/dist/client/client.d.ts +112 -0
  146. package/dist/client/client.js +111 -0
  147. package/dist/client/index.d.ts +3 -0
  148. package/dist/client/index.js +2 -0
  149. package/dist/client/session.d.ts +67 -0
  150. package/dist/client/session.js +238 -0
  151. package/dist/committee/client.d.ts +284 -0
  152. package/dist/committee/client.js +351 -0
  153. package/dist/committee/dual-sign.d.ts +110 -0
  154. package/dist/committee/dual-sign.js +202 -0
  155. package/dist/committee/ecdsa.d.ts +36 -0
  156. package/dist/committee/ecdsa.js +45 -0
  157. package/dist/committee/extraction.d.ts +82 -0
  158. package/dist/committee/extraction.js +96 -0
  159. package/dist/committee/index.d.ts +19 -0
  160. package/dist/committee/index.js +13 -0
  161. package/dist/committee/oauth.d.ts +51 -0
  162. package/dist/committee/oauth.js +90 -0
  163. package/dist/committee/receipts.d.ts +51 -0
  164. package/dist/committee/receipts.js +59 -0
  165. package/dist/committee/request.d.ts +264 -0
  166. package/dist/committee/request.js +305 -0
  167. package/dist/committee/token.d.ts +274 -0
  168. package/dist/committee/token.js +418 -0
  169. package/dist/crypto/constants.d.ts +10 -0
  170. package/dist/crypto/constants.js +32 -0
  171. package/dist/crypto/detect.d.ts +20 -0
  172. package/dist/crypto/detect.js +44 -0
  173. package/dist/crypto/envelope.d.ts +60 -0
  174. package/dist/crypto/envelope.js +243 -0
  175. package/dist/crypto/frost.d.ts +49 -0
  176. package/dist/crypto/frost.js +152 -0
  177. package/dist/crypto/hex.d.ts +7 -0
  178. package/dist/crypto/hex.js +24 -0
  179. package/dist/crypto/ibe-blob.d.ts +114 -0
  180. package/dist/crypto/ibe-blob.js +208 -0
  181. package/dist/crypto/ibe.d.ts +88 -0
  182. package/dist/crypto/ibe.js +262 -0
  183. package/dist/crypto/index.d.ts +12 -0
  184. package/dist/crypto/index.js +12 -0
  185. package/dist/crypto/kem.d.ts +55 -0
  186. package/dist/crypto/kem.js +241 -0
  187. package/dist/decryption/client.d.ts +64 -0
  188. package/dist/decryption/client.js +82 -0
  189. package/dist/decryption/index.d.ts +2 -0
  190. package/dist/decryption/index.js +2 -0
  191. package/dist/errors.d.ts +124 -0
  192. package/dist/errors.js +167 -0
  193. package/dist/index.d.ts +43 -0
  194. package/dist/index.js +98 -0
  195. package/dist/keys/index.d.ts +1 -0
  196. package/dist/keys/index.js +4 -0
  197. package/dist/keys/node-client.d.ts +27 -0
  198. package/dist/keys/node-client.js +97 -0
  199. package/dist/oid4vp/binding.d.ts +76 -0
  200. package/dist/oid4vp/binding.js +118 -0
  201. package/dist/oid4vp/did-web.d.ts +49 -0
  202. package/dist/oid4vp/did-web.js +57 -0
  203. package/dist/oid4vp/index.d.ts +9 -0
  204. package/dist/oid4vp/index.js +10 -0
  205. package/dist/oid4vp/jose.d.ts +166 -0
  206. package/dist/oid4vp/jose.js +242 -0
  207. package/dist/oid4vp/jwe.d.ts +30 -0
  208. package/dist/oid4vp/jwe.js +93 -0
  209. package/dist/oid4vp/oid4vci.d.ts +84 -0
  210. package/dist/oid4vp/oid4vci.js +85 -0
  211. package/dist/oid4vp/request-object.d.ts +109 -0
  212. package/dist/oid4vp/request-object.js +96 -0
  213. package/dist/oid4vp/sd-jwt.d.ts +177 -0
  214. package/dist/oid4vp/sd-jwt.js +208 -0
  215. package/dist/oid4vp/verifier-agent.d.ts +161 -0
  216. package/dist/oid4vp/verifier-agent.js +132 -0
  217. package/dist/oid4vp/wallet.d.ts +116 -0
  218. package/dist/oid4vp/wallet.js +108 -0
  219. package/dist/recipient/store.d.ts +67 -0
  220. package/dist/recipient/store.js +98 -0
  221. package/dist/signing/ecdsa.d.ts +49 -0
  222. package/dist/signing/ecdsa.js +79 -0
  223. package/dist/signing/frost.d.ts +88 -0
  224. package/dist/signing/frost.js +145 -0
  225. package/dist/signing/index.d.ts +4 -0
  226. package/dist/signing/index.js +3 -0
  227. package/dist/slots/faucet.d.ts +23 -0
  228. package/dist/slots/faucet.js +35 -0
  229. package/dist/slots/index.d.ts +2 -0
  230. package/dist/slots/index.js +4 -0
  231. package/dist/verifier-agent/index.d.ts +241 -0
  232. package/dist/verifier-agent/index.js +411 -0
  233. package/docs/DEVELOPER-EXPERIENCE.md +62 -0
  234. package/docs/README.md +33 -0
  235. package/docs/access-control.md +76 -0
  236. package/docs/ai-development.md +292 -0
  237. package/docs/api.md +338 -0
  238. package/docs/application-api.md +335 -0
  239. package/docs/architecture.md +65 -0
  240. package/docs/basics.md +48 -0
  241. package/docs/capabilities.md +86 -0
  242. package/docs/chain.md +153 -0
  243. package/docs/compatibility.md +36 -0
  244. package/docs/consumer-migrations.md +80 -0
  245. package/docs/create-slot.md +104 -0
  246. package/docs/document-signing.md +243 -0
  247. package/docs/encrypted-notes.md +129 -0
  248. package/docs/encryption.md +100 -0
  249. package/docs/errors.md +76 -0
  250. package/docs/flows.md +289 -0
  251. package/docs/fuji.md +127 -0
  252. package/docs/funding.md +126 -0
  253. package/docs/getting-started.md +94 -0
  254. package/docs/glossary.md +44 -0
  255. package/docs/installation.md +132 -0
  256. package/docs/manage-slot.md +95 -0
  257. package/docs/native-approvals.md +124 -0
  258. package/docs/prerequisites.md +137 -0
  259. package/docs/read-slot.md +41 -0
  260. package/docs/reference/README.md +30 -0
  261. package/docs/reference/app-node.md +102 -0
  262. package/docs/reference/app.md +1737 -0
  263. package/docs/reference/chain-node.md +159 -0
  264. package/docs/reference/chain.md +3609 -0
  265. package/docs/reference/committee.md +2176 -0
  266. package/docs/reference/main.md +4068 -0
  267. package/docs/reference/oid4vp.md +2547 -0
  268. package/docs/reference/verifier-agent.md +498 -0
  269. package/docs/shared-account.md +168 -0
  270. package/docs/signing-and-encryption.md +52 -0
  271. package/docs/signing.md +172 -0
  272. package/examples/committee-slot.ts +16 -0
  273. package/examples/connect-fuji.ts +41 -0
  274. package/examples/connect-network.ts +14 -0
  275. package/examples/credential-approvals.ts +46 -0
  276. package/examples/document-signing/README.md +59 -0
  277. package/examples/document-signing/backend.ts +132 -0
  278. package/examples/document-signing/build.mjs +19 -0
  279. package/examples/document-signing/config.ts +34 -0
  280. package/examples/document-signing/gitignore.template +9 -0
  281. package/examples/document-signing/model.ts +140 -0
  282. package/examples/document-signing/network.ts +58 -0
  283. package/examples/document-signing/package.json +25 -0
  284. package/examples/document-signing/public/index.html +27 -0
  285. package/examples/document-signing/public/sample.pdf +31 -0
  286. package/examples/document-signing/public/styles.css +531 -0
  287. package/examples/document-signing/server.ts +358 -0
  288. package/examples/document-signing/setup.ts +111 -0
  289. package/examples/document-signing/store.ts +105 -0
  290. package/examples/document-signing/tsconfig.json +24 -0
  291. package/examples/document-signing/verify.ts +24 -0
  292. package/examples/document-signing/web/app.ts +312 -0
  293. package/examples/document-signing/web/preview.ts +67 -0
  294. package/examples/document-signing/web/wallet.ts +146 -0
  295. package/examples/document-signing/workflow.test.ts +228 -0
  296. package/examples/document-signing/workflow.ts +241 -0
  297. package/examples/document-signing.ts +96 -0
  298. package/examples/encrypted-notes.ts +86 -0
  299. package/examples/ethers-signer.ts +204 -0
  300. package/examples/fund-slot.ts +73 -0
  301. package/examples/getting-started.ts +25 -0
  302. package/examples/learning-authorize.ts +23 -0
  303. package/examples/learning-cancel-slot.ts +11 -0
  304. package/examples/learning-context.ts +28 -0
  305. package/examples/learning-create-slot.ts +25 -0
  306. package/examples/learning-read-slot.ts +8 -0
  307. package/examples/learning-renew-slot.ts +12 -0
  308. package/examples/learning-sign.ts +8 -0
  309. package/examples/live-config.ts +71 -0
  310. package/examples/minimal.ts +6 -0
  311. package/examples/native-approvals.ts +57 -0
  312. package/examples/network.ts +58 -0
  313. package/examples/offline.ts +16 -0
  314. package/examples/personal-vault.ts +20 -0
  315. package/examples/provision-slot.ts +47 -0
  316. package/examples/shared-account.ts +46 -0
  317. package/examples/slot-address.ts +13 -0
  318. package/examples/slot-creation.ts +9 -0
  319. package/examples/tutorial-negative.ts +26 -0
  320. package/examples/tutorial-support.ts +76 -0
  321. package/examples/viem-account.ts +203 -0
  322. package/package.json +303 -4
@@ -0,0 +1,418 @@
1
+ // per-request verifier-committee selection + canonical compound-authorization
2
+ // token, the recipient-side (coordinator) counterpart of the reference implementation.
3
+ //
4
+ // This module is the single source of truth the SDK shares with the verifier (producer) and
5
+ // the keykeeper node (reconstructor/validator): the committee draw, the canonical token hash,
6
+ // the keeper op-attestation hash, and the verifier-set Merkle leaf must agree BYTE-FOR-BYTE
7
+ // with the reference implementation, or authorization silently breaks. `test/committee.conformance.ts` pins
8
+ // every value against vectors computed from that crate.
9
+ //
10
+ // It is pure (no HTTP, no chain) - assembling/verifying a token from already-fetched verifier
11
+ // replies + on-chain reads is the caller's job.
12
+ import { keccak_256 } from '@noble/hashes/sha3';
13
+ import { concatBytes } from '@noble/hashes/utils';
14
+ import { ed25519 } from '@noble/curves/ed25519';
15
+ import { bytesToHex, hexToBytes } from '../crypto/hex.js';
16
+ // Domain separators (must equal the reference constants verbatim)
17
+ const SELECT_DOMAIN = new TextEncoder().encode('keykeeper-committee/select/v1');
18
+ const TOKEN_DOMAIN = new TextEncoder().encode('keykeeper-committee/token/v1');
19
+ const OP_ATTEST_DOMAIN = new TextEncoder().encode('keykeeper-committee/op-attest/v1');
20
+ const VERIFIER_LEAF_DOMAIN = new TextEncoder().encode('keykeeper-verifier-leaf:v1');
21
+ function discriminant(t) {
22
+ return t === 'JWT' ? 1 : 2;
23
+ }
24
+ // Big-endian integer encoders (mirror the reference big-endian encoders)
25
+ function u32be(n) {
26
+ const b = new Uint8Array(4);
27
+ new DataView(b.buffer).setUint32(0, n >>> 0, false);
28
+ return b;
29
+ }
30
+ function u64be(n) {
31
+ const b = new Uint8Array(8);
32
+ new DataView(b.buffer).setBigUint64(0, BigInt(n), false);
33
+ return b;
34
+ }
35
+ function i64be(n) {
36
+ const b = new Uint8Array(8);
37
+ new DataView(b.buffer).setBigInt64(0, BigInt(n), false);
38
+ return b;
39
+ }
40
+ function bytesEqual(a, b) {
41
+ if (a.length !== b.length)
42
+ return false;
43
+ for (let i = 0; i < a.length; i++)
44
+ if (a[i] !== b[i])
45
+ return false;
46
+ return true;
47
+ }
48
+ // Lexicographic byte comparison (the OpenZeppelin sorted-pair convention).
49
+ function compareBytes(a, b) {
50
+ const n = Math.min(a.length, b.length);
51
+ for (let i = 0; i < n; i++) {
52
+ const x = a[i];
53
+ const y = b[i];
54
+ if (x !== y)
55
+ return x < y ? -1 : 1;
56
+ }
57
+ return a.length - b.length;
58
+ }
59
+ // Committee selection (mirrors `select_committee`)
60
+ // SECURITY (kill-chain-A fix): the draw takes NO caller-chosen input. It used to hash the
61
+ // caller-picked `vpHash`, so a Byzantine verifier coalition ground it offline until the draw
62
+ // seated its own keys. It now hashes only pinned (slotId, epoch, seed) - mirrors the reference committee draw.
63
+ function drawIndex(slotId, epoch, seed, iter, registrySize) {
64
+ const h = keccak_256(concatBytes(SELECT_DOMAIN, slotId, u64be(epoch), seed, u64be(iter)));
65
+ let lead = 0n;
66
+ for (let i = 0; i < 8; i++)
67
+ lead = (lead << 8n) | BigInt(h[i]);
68
+ return Number(lead % BigInt(registrySize));
69
+ }
70
+ /**
71
+ * Deterministically select `count` distinct verifier indexes in `[0, registrySize)` for one
72
+ * request: `index = keccak256(SELECT_DOMAIN || slotId || epoch(u64 BE) || seed || iter(u64 BE)) mod registrySize`,
73
+ * skipping a repeat and incrementing `iter`. Identical, identically-ordered to what the
74
+ * verifier selects and the keeper reconstructs.
75
+ *
76
+ * @param slotId - 32-byte slot identifier.
77
+ * @param epoch - Beacon epoch for the committee draw.
78
+ * @param seed - 32-byte beacon seed for that epoch.
79
+ * @param registrySize - Number of entries in the verifier registry.
80
+ * @param count - Number of distinct verifier indices to select.
81
+ */
82
+ export function selectVerifierCommittee(slotId, epoch, seed, registrySize, count) {
83
+ if (registrySize === 0)
84
+ throw new Error('verifier registry is empty');
85
+ if (count > registrySize) {
86
+ throw new Error(`requested ${count} distinct members from a registry of only ${registrySize}`);
87
+ }
88
+ const selected = [];
89
+ if (count === 0)
90
+ return selected;
91
+ const cap = BigInt(registrySize) * 64n + 1024n;
92
+ let iter = 0n;
93
+ while (selected.length < count) {
94
+ if (iter >= cap)
95
+ throw new Error(`selection exhausted: collected ${selected.length} of ${count}`);
96
+ const candidate = drawIndex(slotId, epoch, seed, iter, registrySize);
97
+ if (!selected.includes(candidate))
98
+ selected.push(candidate);
99
+ iter += 1n;
100
+ }
101
+ return selected;
102
+ }
103
+ /**
104
+ * Canonical, domain-separated, length-prefixed byte encoding hashed for signing.
105
+ *
106
+ * @param p - Compound token payload, excluding signatures.
107
+ */
108
+ export function compoundTokenCanonicalBytes(p) {
109
+ const parts = [
110
+ TOKEN_DOMAIN,
111
+ Uint8Array.of(discriminant(p.tokenType)),
112
+ p.seed,
113
+ u64be(p.epoch),
114
+ p.slotId,
115
+ p.vpHash,
116
+ p.holderHash,
117
+ p.ruleHash,
118
+ ];
119
+ // identity binding: an explicit presence byte, then the hash (mirrors the
120
+ // reference encoding - a zero sentinel would make "no identity" and an all-zero hash the
121
+ // same bytes).
122
+ if (p.identityHash === undefined)
123
+ parts.push(Uint8Array.of(0x00));
124
+ else
125
+ parts.push(Uint8Array.of(0x01), p.identityHash);
126
+ // request binding: same presence-byte pattern as identityHash.
127
+ if (p.requestHash === undefined)
128
+ parts.push(Uint8Array.of(0x00));
129
+ else
130
+ parts.push(Uint8Array.of(0x01), p.requestHash);
131
+ // Binding strength - one byte, always present (0x00 = Unbound, 0x01 = HolderKey).
132
+ parts.push(Uint8Array.of(p.binding ?? 0x00));
133
+ parts.push(u32be(p.verifierIndexes.length));
134
+ for (const idx of p.verifierIndexes)
135
+ parts.push(u32be(idx));
136
+ parts.push(i64be(p.iat), i64be(p.exp));
137
+ return concatBytes(...parts);
138
+ }
139
+ /**
140
+ * `keccak256` of the canonical bytes - the value each quorum verifier signs.
141
+ *
142
+ * @param p - Compound token payload, excluding signatures.
143
+ */
144
+ export function compoundTokenHash(p) {
145
+ return keccak_256(compoundTokenCanonicalBytes(p));
146
+ }
147
+ // Keeper op-attestation hash (mirrors `op_attestation_hash`)
148
+ /**
149
+ * The hash a keeper signs to attest it served `opId` on `slotId` under the token `tokenHash`.
150
+ *
151
+ * @param chainId - EVM chain identifier.
152
+ * @param opId - 32-byte audit operation identifier.
153
+ * @param slotId - 32-byte slot identifier.
154
+ * @param tokenHash - 32-byte compound token hash.
155
+ */
156
+ export function opAttestationHash(chainId, opId, slotId, tokenHash) {
157
+ return keccak_256(concatBytes(OP_ATTEST_DOMAIN, u64be(chainId), opId, slotId, tokenHash));
158
+ }
159
+ // Client request-binding hash (mirrors `client_binding_hash`)
160
+ const CLIENT_BINDING_DOMAIN = new TextEncoder().encode('keykeeper-committee/client-binding/v1');
161
+ /**
162
+ * The 32-byte hash the client (== the credential holder) signs to attest it authorized this
163
+ * operation on `slotId` under the compound token whose canonical hash is `tokenHash`:
164
+ * `keccak256(DOMAIN || slotId || tokenHash)`. Byte-identical to the reference `client_binding_hash`, so
165
+ * the keeper (hot path) and accountant (audit) verify the client signature over the same bytes.
166
+ *
167
+ * @param slotId - 32-byte slot identifier.
168
+ * @param tokenHash - 32-byte compound token hash.
169
+ */
170
+ export function clientBindingHash(slotId, tokenHash) {
171
+ return keccak_256(concatBytes(CLIENT_BINDING_DOMAIN, slotId, tokenHash));
172
+ }
173
+ // Verifier-set Merkle leaf + proof (mirrors `verifier_leaf`)
174
+ /**
175
+ * `keccak256(DOMAIN || index(u32 BE) || operator(20) || keccak256(pubkey))` - matches the on-chain leaf.
176
+ *
177
+ * @param index - Zero-based verifier registry index.
178
+ * @param operator - 20-byte operator address.
179
+ * @param pubkey - 32-byte Ed25519 verifier public key.
180
+ */
181
+ export function verifierLeaf(index, operator, pubkey) {
182
+ return keccak_256(concatBytes(VERIFIER_LEAF_DOMAIN, u32be(index), operator, keccak_256(pubkey)));
183
+ }
184
+ function hashPair(a, b) {
185
+ return compareBytes(a, b) <= 0 ? keccak_256(concatBytes(a, b)) : keccak_256(concatBytes(b, a));
186
+ }
187
+ /**
188
+ * Verify a sorted-pair keccak Merkle inclusion proof (leaf to root).
189
+ *
190
+ * @param leaf - Leaf hash to prove.
191
+ * @param proof - Sibling hashes ordered from the leaf toward the root.
192
+ * @param root - Expected Merkle root.
193
+ */
194
+ export function verifyMerkleProof(leaf, proof, root) {
195
+ let computed = leaf;
196
+ for (const sib of proof)
197
+ computed = hashPair(computed, sib);
198
+ return bytesEqual(computed, root);
199
+ }
200
+ // One level up the sorted-pair tree; an odd trailing node is promoted unchanged
201
+ // (mirrors the reference `next_level`).
202
+ function nextLevel(level) {
203
+ const next = [];
204
+ for (let i = 0; i < level.length; i += 2) {
205
+ if (i + 1 < level.length)
206
+ next.push(hashPair(level[i], level[i + 1]));
207
+ else
208
+ next.push(level[i]);
209
+ }
210
+ return next;
211
+ }
212
+ /**
213
+ * Build the Merkle root over `leaves` (sorted-pair; an odd node is promoted unchanged to the
214
+ * next level). `null` for an empty set. Byte-identical to the reference `merkle_root`, so a root
215
+ * built here matches the on-chain `VerifierSetRegistry`/`Settlement` anchored root.
216
+ *
217
+ * @param leaves - Ordered Merkle leaf hashes.
218
+ */
219
+ export function merkleRoot(leaves) {
220
+ if (leaves.length === 0)
221
+ return null;
222
+ let level = leaves.slice();
223
+ while (level.length > 1)
224
+ level = nextLevel(level);
225
+ return level[0];
226
+ }
227
+ /**
228
+ * The inclusion proof (sibling hashes, leaf to root) for `index` in `leaves`. `null` if `index`
229
+ * is out of range. Mirrors the reference `merkle_proof`; pairs with [`verifyMerkleProof`].
230
+ *
231
+ * @param leaves - Ordered Merkle leaf hashes.
232
+ * @param index - Zero-based index of the leaf to prove.
233
+ */
234
+ export function merkleProof(leaves, index) {
235
+ if (index < 0 || index >= leaves.length)
236
+ return null;
237
+ const proof = [];
238
+ let level = leaves.slice();
239
+ let idx = index;
240
+ while (level.length > 1) {
241
+ if (idx % 2 === 1)
242
+ proof.push(level[idx - 1]);
243
+ else if (idx + 1 < level.length)
244
+ proof.push(level[idx + 1]);
245
+ level = nextLevel(level);
246
+ idx = Math.floor(idx / 2);
247
+ }
248
+ return proof;
249
+ }
250
+ function quorumSatisfied(signers, expected, quorum) {
251
+ const exp = new Set(expected);
252
+ const distinct = new Set();
253
+ for (const s of signers) {
254
+ if (!exp.has(s))
255
+ return false;
256
+ distinct.add(s);
257
+ }
258
+ return distinct.size >= quorum;
259
+ }
260
+ /**
261
+ * Verify rule binding, committee selection, token lifetime, Ed25519 signatures and quorum against the supplied verifier set.
262
+ *
263
+ * @param opts - Decoded token and independently established verifier, rule and time constraints.
264
+ * @returns Fields attested by the verified committee token.
265
+ * @throws If any binding, freshness, signer or quorum check fails.
266
+ */
267
+ export function verifyCompoundToken(opts) {
268
+ const { token, set, committee, quorum, now, leeway, slotRuleHash } = opts;
269
+ if (!bytesEqual(token.ruleHash, slotRuleHash))
270
+ throw new Error('token rule_hash does not match the slot rule hash');
271
+ const expected = selectVerifierCommittee(token.slotId, token.epoch, token.seed, set.registrySize, committee);
272
+ if (token.verifierIndexes.length !== expected.length || token.verifierIndexes.some((v, i) => v !== expected[i])) {
273
+ throw new Error('token committee is not the expected draw');
274
+ }
275
+ if (now > Number(token.exp) + leeway)
276
+ throw new Error('token expired');
277
+ if (now + leeway < Number(token.iat))
278
+ throw new Error('token not yet valid');
279
+ const hash = compoundTokenHash(token);
280
+ const verified = [];
281
+ for (const { verifierIndex, signature } of token.signatures) {
282
+ const pk = set.pubkeys.get(verifierIndex);
283
+ if (!pk)
284
+ throw new Error(`signer index ${verifierIndex} is not in the active verifier set`);
285
+ if (!ed25519.verify(signature, hash, pk))
286
+ throw new Error(`invalid signature from verifier index ${verifierIndex}`);
287
+ if (!verified.includes(verifierIndex))
288
+ verified.push(verifierIndex);
289
+ }
290
+ if (!quorumSatisfied(verified, expected, quorum)) {
291
+ throw new Error(`quorum not met: ${verified.length} of the drawn committee signed, need ${quorum}`);
292
+ }
293
+ return {
294
+ slotId: token.slotId,
295
+ vpHash: token.vpHash,
296
+ holderHash: token.holderHash,
297
+ // Attested, not merely transported: inside the signed bytes, so it survives only if
298
+ // every signature verified over it.
299
+ ...(token.identityHash !== undefined ? { identityHash: token.identityHash } : {}),
300
+ epoch: token.epoch,
301
+ tokenType: token.tokenType,
302
+ verifiedSigners: verified,
303
+ };
304
+ }
305
+ // Sealed committee evidence binding
306
+ const EVIDENCE_BINDING_DOMAIN = new TextEncoder().encode('keykeeper-committee/evidence-binding/v1');
307
+ /** `keccak256(DOMAIN ‖ tokenHash ‖ evidenceHash ‖ evidenceKeyId)` — the message each drawn
308
+ * verifier signs beside its token signature. Byte-identical to the Rust
309
+ * `keykeeper_committee::evidence_binding_message`.
310
+ *
311
+ * @param tokenHash - 32-byte compound-token signing hash.
312
+ * @param evidenceHash - 32-byte keccak256 of the sealed evidence ciphertext.
313
+ * @param evidenceKeyId - 32-byte keccak256 of the accountant evidence key it is sealed to.
314
+ */
315
+ export function evidenceBindingMessage(tokenHash, evidenceHash, evidenceKeyId) {
316
+ for (const [n, v] of [['tokenHash', tokenHash], ['evidenceHash', evidenceHash], ['evidenceKeyId', evidenceKeyId]]) {
317
+ if (v.length !== 32)
318
+ throw new Error(`${n} must be 32 bytes`);
319
+ }
320
+ return keccak_256(concatBytes(EVIDENCE_BINDING_DOMAIN, tokenHash, evidenceHash, evidenceKeyId));
321
+ }
322
+ /**
323
+ * 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.
327
+ *
328
+ * @param opts - Token and evidence hashes, the signatures, the verifier set, the drawn committee and the quorum.
329
+ */
330
+ export function verifyEvidenceBinding(opts) {
331
+ const { tokenHash, evidenceHash, evidenceKeyId, signatures, set, drawn, quorum } = opts;
332
+ if (quorum === 0)
333
+ throw new Error('evidence binding: quorum must be positive');
334
+ const msg = evidenceBindingMessage(tokenHash, evidenceHash, evidenceKeyId);
335
+ const verified = [];
336
+ for (const { verifierIndex, signature } of signatures) {
337
+ if (!drawn.includes(verifierIndex))
338
+ throw new Error(`evidence binding: index ${verifierIndex} is not in the drawn committee`);
339
+ const pk = set.pubkeys.get(verifierIndex);
340
+ if (!pk)
341
+ throw new Error(`evidence binding: index ${verifierIndex} is not in the verifier set`);
342
+ if (!ed25519.verify(signature, msg, pk))
343
+ throw new Error(`evidence binding: invalid signature from verifier index ${verifierIndex}`);
344
+ if (!verified.includes(verifierIndex))
345
+ verified.push(verifierIndex);
346
+ }
347
+ if (!quorumSatisfied(verified, drawn, quorum)) {
348
+ throw new Error(`evidence binding: quorum not met: ${verified.length} of the drawn committee, need ${quorum}`);
349
+ }
350
+ return verified;
351
+ }
352
+ /** Assemble the wire compound token from a payload + the gathered quorum signatures. */
353
+ /** binding strengths: `0x00` Unbound, `0x01` HolderKey (KB-JWT / holder proof verified), `0x02` IssuerAsserted. */
354
+ export const BINDING_UNBOUND = 0x00;
355
+ export const BINDING_HOLDER_KEY = 0x01;
356
+ export const BINDING_ISSUER_ASSERTED = 0x02;
357
+ const BINDING_NAMES = { 0x00: 'unbound', 0x01: 'holder_key', 0x02: 'issuer_asserted' };
358
+ export function bindingToWire(b) {
359
+ if (b === undefined || b === 0x00)
360
+ return undefined;
361
+ return BINDING_NAMES[b] ?? `unknown_${b}`;
362
+ }
363
+ export function bindingFromWire(s) {
364
+ if (s === undefined || s === 'unbound')
365
+ return 0x00;
366
+ if (s === 'holder_key')
367
+ return 0x01;
368
+ if (s === 'issuer_asserted')
369
+ return 0x02;
370
+ return 0x00;
371
+ }
372
+ /**
373
+ * Encode a token payload and verifier signatures into the keeper JSON wire format. This does not verify signatures.
374
+ *
375
+ * @param p - Compound token payload, excluding signatures.
376
+ * @param signatures - Verifier signatures to include in the wire object.
377
+ */
378
+ export function assembleCompoundToken(p, signatures) {
379
+ return {
380
+ token_type: p.tokenType,
381
+ seed: bytesToHex(p.seed),
382
+ epoch: Number(p.epoch),
383
+ slot_id: bytesToHex(p.slotId),
384
+ vp_hash: bytesToHex(p.vpHash),
385
+ holder_hash: bytesToHex(p.holderHash),
386
+ rule_hash: bytesToHex(p.ruleHash),
387
+ ...(p.identityHash !== undefined ? { identity_hash: bytesToHex(p.identityHash) } : {}),
388
+ ...(p.requestHash !== undefined ? { request_hash: bytesToHex(p.requestHash) } : {}),
389
+ ...(bindingToWire(p.binding) !== undefined ? { binding: bindingToWire(p.binding) } : {}),
390
+ verifier_indexes: p.verifierIndexes,
391
+ iat: Number(p.iat),
392
+ exp: Number(p.exp),
393
+ signatures: signatures.map(s => ({ verifier_index: s.verifierIndex, signature: bytesToHex(s.signature) })),
394
+ };
395
+ }
396
+ /**
397
+ * Decode a wire compound token into the byte-level payload + signatures for verification.
398
+ *
399
+ * @param w - Keeper JSON token representation to decode into byte fields.
400
+ */
401
+ export function decodeCompoundToken(w) {
402
+ return {
403
+ tokenType: w.token_type,
404
+ seed: hexToBytes(w.seed),
405
+ epoch: w.epoch,
406
+ slotId: hexToBytes(w.slot_id),
407
+ vpHash: hexToBytes(w.vp_hash),
408
+ holderHash: hexToBytes(w.holder_hash),
409
+ ruleHash: hexToBytes(w.rule_hash),
410
+ ...(w.identity_hash !== undefined ? { identityHash: hexToBytes(w.identity_hash) } : {}),
411
+ ...(w.request_hash !== undefined ? { requestHash: hexToBytes(w.request_hash) } : {}),
412
+ binding: bindingFromWire(w.binding),
413
+ verifierIndexes: w.verifier_indexes,
414
+ iat: w.iat,
415
+ exp: w.exp,
416
+ signatures: w.signatures.map(s => ({ verifierIndex: s.verifier_index, signature: hexToBytes(s.signature) })),
417
+ };
418
+ }
@@ -0,0 +1,10 @@
1
+ export declare const KEM_DOMAIN: Uint8Array<ArrayBuffer>;
2
+ export declare const ENVELOPE_VERSION_V1: 1;
3
+ export declare const ENVELOPE_VERSION_V2: 2;
4
+ export declare const MAX_IDENTITY_LEN: 1024;
5
+ export declare const MAX_AEAD_CT_LEN = 1048576;
6
+ export declare const COMPRESSED_G2_LEN: 96;
7
+ export declare const NONCE_LEN: 12;
8
+ export declare const SLOT_ID_LEN: 32;
9
+ export declare const KK_PREFIX = "[KK]";
10
+ export declare const KK_MIN_B64_LEN = 196;
@@ -0,0 +1,32 @@
1
+ // Pinned wire-format constants. These values are baked into every encrypted
2
+ // message in production. A change to any of them makes existing ciphertexts
3
+ // undecryptable - treat them as cryptographic invariants, not refactor targets.
4
+ // Each assertion below mirrors the pin tests in the reference envelope implementation
5
+ // and the reference KEM implementation.
6
+ // Domain-separation tag for the BLS KEM key-derivation and nonce-derivation
7
+ // functions. Hashed into the AEAD key for EVERY group-encryption envelope.
8
+ // NEVER change after a production rollout - a version bump silently turns
9
+ // every encrypted chat message on disk into garbage.
10
+ // Mirrors: the reference KEM implementation KEM_DOMAIN = b"BLS12381-ElGamalG2-KEM-v1"
11
+ export const KEM_DOMAIN = new TextEncoder().encode('BLS12381-ElGamalG2-KEM-v1');
12
+ // Wire-format version byte for the legacy (no-epoch) layout.
13
+ export const ENVELOPE_VERSION_V1 = 0x01;
14
+ // Wire-format version byte for the strict-mode (embedded-epoch) layout.
15
+ export const ENVELOPE_VERSION_V2 = 0x02;
16
+ // Hard cap on identity length (bytes). Mirrors the reference MAX_IDENTITY_LEN.
17
+ export const MAX_IDENTITY_LEN = 1024;
18
+ // Hard cap on AEAD ciphertext length (bytes). Mirrors the reference MAX_AEAD_CT_LEN.
19
+ export const MAX_AEAD_CT_LEN = 1_048_576; // 1024 * 1024
20
+ // BLS12-381 G2 compressed point width (bytes). Externally fixed by the curve.
21
+ export const COMPRESSED_G2_LEN = 96;
22
+ // ChaCha20-Poly1305 nonce width (bytes). Externally fixed by the cipher.
23
+ export const NONCE_LEN = 12;
24
+ // On-chain slot-id width (bytes32). Fixed by the Ethereum contract.
25
+ export const SLOT_ID_LEN = 32;
26
+ // [KK] envelope-in-text detection (was kk-constants.ts)
27
+ // Tasra envelope prefix embedded in a transport's message text.
28
+ // Clients without the key see the raw prefix + base64; a Tasra-aware
29
+ // client replaces it with the decrypted message inline.
30
+ export const KK_PREFIX = '[KK]';
31
+ // Minimum length of a base64 GroupEnvelope v0x01 (147 bytes overhead to ~196 b64 chars).
32
+ export const KK_MIN_B64_LEN = 196;
@@ -0,0 +1,20 @@
1
+ import { type GroupEnvelope } from './envelope.js';
2
+ /**
3
+ * Check the Tasra text prefix and minimum length. This does not validate the envelope.
4
+ *
5
+ * @param text - Text payload to inspect for the Tasra prefix.
6
+ */
7
+ export declare function isTasraPost(text: string): boolean;
8
+ export declare function extractEnvelopeB64(text: string): string;
9
+ /**
10
+ * Decode a Tasra text payload into an envelope; return null for invalid input.
11
+ *
12
+ * @param text - Text payload to inspect and decode.
13
+ */
14
+ export declare function parseTasraPost(text: string): GroupEnvelope | null;
15
+ /**
16
+ * Encode serialized envelope bytes as a Tasra encrypted text payload.
17
+ *
18
+ * @param envelopeBytes - Binary envelope produced by the envelope serializer.
19
+ */
20
+ export declare function buildTasraText(envelopeBytes: Uint8Array): string;
@@ -0,0 +1,44 @@
1
+ import { fromBytes } from './envelope.js';
2
+ import { base64Decode, base64Encode } from './envelope.js';
3
+ import { KK_MIN_B64_LEN, KK_PREFIX } from './constants.js';
4
+ // Returns true when the post text carries a Tasra encrypted envelope.
5
+ /**
6
+ * Check the Tasra text prefix and minimum length. This does not validate the envelope.
7
+ *
8
+ * @param text - Text payload to inspect for the Tasra prefix.
9
+ */
10
+ export function isTasraPost(text) {
11
+ return (text.startsWith(KK_PREFIX) &&
12
+ text.length >= KK_PREFIX.length + KK_MIN_B64_LEN);
13
+ }
14
+ // Extract the base64 envelope string from a Tasra post text.
15
+ export function extractEnvelopeB64(text) {
16
+ return text.slice(KK_PREFIX.length);
17
+ }
18
+ // Parse the envelope from a Tasra post text. Returns null on malformed input.
19
+ /**
20
+ * Decode a Tasra text payload into an envelope; return null for invalid input.
21
+ *
22
+ * @param text - Text payload to inspect and decode.
23
+ */
24
+ export function parseTasraPost(text) {
25
+ if (!isTasraPost(text))
26
+ return null;
27
+ try {
28
+ const b64 = extractEnvelopeB64(text);
29
+ const bytes = base64Decode(b64);
30
+ return fromBytes(bytes);
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ }
36
+ // Build the post text for an encrypted message.
37
+ /**
38
+ * Encode serialized envelope bytes as a Tasra encrypted text payload.
39
+ *
40
+ * @param envelopeBytes - Binary envelope produced by the envelope serializer.
41
+ */
42
+ export function buildTasraText(envelopeBytes) {
43
+ return `${KK_PREFIX}${base64Encode(envelopeBytes)}`;
44
+ }
@@ -0,0 +1,60 @@
1
+ import { assembleKey, type Ciphertext, decryptWithMasterKey, encrypt as kemEncrypt, type Shard } from './kem.js';
2
+ export type { Ciphertext, Shard };
3
+ /** Serialized group ciphertext context: slot, associated data and optional key epoch. */
4
+ export interface GroupEnvelope {
5
+ /** On-chain key-slot identifier (bytes32). */
6
+ slotId: Uint8Array;
7
+ /** AEAD additional authenticated data - must match at decrypt time. */
8
+ identity: Uint8Array;
9
+ /** KEM ciphertext (U, nonce, AEAD output). */
10
+ ciphertext: Ciphertext;
11
+ /** Slot epoch this envelope was produced under. Present in v0x02 only. */
12
+ epoch: bigint | null;
13
+ }
14
+ /**
15
+ * Serialize an envelope using the version selected by its epoch. Reject invalid epoch and oversized fields.
16
+ *
17
+ * @param env - Envelope to serialize, including its slot, ciphertext and optional epoch.
18
+ */
19
+ export declare function toBytes(env: GroupEnvelope): Uint8Array;
20
+ /**
21
+ * Parse a supported binary envelope and validate its version, field lengths and boundaries.
22
+ *
23
+ * @param bytes - Complete binary envelope to parse.
24
+ */
25
+ export declare function fromBytes(bytes: Uint8Array): GroupEnvelope;
26
+ /**
27
+ * Encrypt `plaintext` to a slot's group key - ChaCha20-Poly1305 under a BLS12-381
28
+ * G2 ElGamal KEM. Local and synchronous: it needs only the slot's **public** key,
29
+ * so no JWT, no node round-trip, and no assembled secret.
30
+ *
31
+ * @param slotId the 32-byte slot id (raw bytes, not hex)
32
+ * @param mpkBytes the slot's 96-byte compressed G2 group public key, as served by
33
+ * `GET /v1/keys/{slot}/public` (see `fetchMpk`)
34
+ * @param identity additional authenticated data bound into the AEAD. Conventionally
35
+ * the slot id itself; the managed session defaults to exactly that.
36
+ * @param plaintext the bytes to encrypt
37
+ * @param epoch the current slot epoch, producing a v0x02 envelope; `null` produces
38
+ * a legacy v0x01 envelope with no epoch binding
39
+ * @returns the envelope - pass through `toBytes()` then `buildTasraText()` for
40
+ * the opaque `[KK]<base64>` wire form
41
+ * @throws {Error} if `slotId` is not 32 bytes, `identity` exceeds its cap, `plaintext`
42
+ * exceeds {@link MAX_PLAINTEXT_LEN}, or `epoch` is negative or above 2^63 - 1
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const {mpkBytes, epoch} = await fetchMpk(nodeUrl, slotHex)
47
+ * const env = encryptEnvelope(hexToBytes(slotHex), mpkBytes, hexToBytes(slotHex), bytes, BigInt(epoch))
48
+ * const wire = buildTasraText(toBytes(env)) // hand to ANY transport
49
+ * ```
50
+ */
51
+ export declare function encryptEnvelope(slotId: Uint8Array, mpkBytes: Uint8Array, identity: Uint8Array, plaintext: Uint8Array, epoch?: bigint | null): GroupEnvelope;
52
+ export declare function decryptEnvelope(env: GroupEnvelope, mskBytes: Uint8Array): Uint8Array;
53
+ export declare function decryptEnvelopeBase64(envelopeBase64: string, mskBytes: Uint8Array): Uint8Array;
54
+ /** Largest plaintext one envelope carries: the AEAD ciphertext cap minus the 16-byte tag. */
55
+ export declare const MAX_PLAINTEXT_LEN: number;
56
+ export declare function base64Encode(bytes: Uint8Array): string;
57
+ export declare function base64Decode(b64: string): Uint8Array;
58
+ export { assembleKey, decryptWithMasterKey, kemEncrypt };
59
+ export declare function mpkFromBase64(base64: string): Uint8Array;
60
+ export declare function parseMpk(bytes: Uint8Array): import("@noble/curves/abstract/weierstrass").WeierstrassPoint<import("@noble/curves/abstract/tower").Fp2>;