@t3foundry/tasra-sdk 0.0.0-stage → 0.3.1-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,51 @@
1
+ /** The OAuth response route is `{PREFIX}{sessionId}{SUFFIX}` under the agent origin. */
2
+ export declare const OAUTH_RESPONSE_PATH_PREFIX = "/v1/sessions/";
3
+ /** The trailing segment of the OAuth response route. */
4
+ export declare const OAUTH_RESPONSE_PATH_SUFFIX = "/oauth-response";
5
+ /** The longest session id an `htu` may carry — mirrors `MAX_SESSION_ID_LEN`. */
6
+ export declare const MAX_SESSION_ID_LEN = 128;
7
+ /**
8
+ * Whether `sessionId` is one plain path segment: `[A-Za-z0-9_-]{1,128}`. Mirrors
9
+ * `keykeeper_committee::oauth::validate_session_id`, which every drawn verifier runs.
10
+ *
11
+ * @param sessionId - Session id returned by the verifier agent when the session was opened.
12
+ */
13
+ export declare function isValidSessionId(sessionId: string): boolean;
14
+ /**
15
+ * Normalise an origin the way the reference endpoint normaliser
16
+ * does: trim, drop a trailing slash, lower-case the scheme and authority, keep the path as
17
+ * written.
18
+ *
19
+ * The PATH keeps its case deliberately - a path is case-sensitive, and lower-casing it
20
+ * would silently rewrite an agent deployed under `/API`.
21
+ *
22
+ * @param url - Endpoint text to normalize; scheme and authority are lowercased while the path is preserved.
23
+ */
24
+ export declare function normalizeOrigin(url: string): string;
25
+ /**
26
+ * The OAuth audience the tenant registers with its IdP and every rule pins:
27
+ * `{origin}/authz/{chainId}`.
28
+ *
29
+ * The chain id is in it so a token minted for a testnet deployment of the same platform
30
+ * cannot authorize on mainnet.
31
+ *
32
+ * @param origin - Platform origin used to derive the token audience.
33
+ * @param chainId - EVM chain identifier for the selected network.
34
+ */
35
+ export declare function platformAudience(origin: string, chainId: number | bigint): string;
36
+ /**
37
+ * The `htu` (RFC 9449 §4.2) a DPoP proof for an OAuth response must carry:
38
+ * `{origin}/v1/sessions/{sessionId}/oauth-response` — the URL the proof is presented at.
39
+ *
40
+ * Per session, because RFC 9449 §4.3 checks `htu` against the request URI and a conformant
41
+ * client library derives it from the URL it calls. The ORIGIN is still the agent origin the
42
+ * verifiers approved, so a client posting to a different base URL (an internal hostname, a
43
+ * proxy) must still sign over the value the agent returned, not over the URL it called.
44
+ *
45
+ * Throws on a session id that is not one plain path segment, exactly as the verifiers refuse
46
+ * one.
47
+ *
48
+ * @param origin - Verifier-agent public origin the verifiers approved.
49
+ * @param sessionId - Id of the OAuth session the proof is presented to.
50
+ */
51
+ export declare function dpopHtu(origin: string, sessionId: string): string;
@@ -0,0 +1,90 @@
1
+ // The two strings an OAuth+DPoP authorization is bound to, DERIVED.
2
+ //
3
+ // Mirrors the reference OAuth derivations exactly, including its normalisation, because
4
+ // three independent parties have to agree on these byte for byte: the tenant (which
5
+ // registers the audience with its IdP), the client (which mints a DPoP proof over the `htu`)
6
+ // and every drawn verifier (which checks both). Only one of the three has a config file we
7
+ // control, so neither string is ever configured anywhere.
8
+ //
9
+ // The agent RETURNS both values from `createOauthSession`, so a client normally never
10
+ // calls these. They exist for the step that happens BEFORE any session: telling a tenant
11
+ // which `aud` to register with their IdP.
12
+ import { TasraError } from '../errors.js';
13
+ /** Path segment identifying the platform's authorization API, under the agent origin. */
14
+ const AUDIENCE_PATH = 'authz';
15
+ /** The OAuth response route is `{PREFIX}{sessionId}{SUFFIX}` under the agent origin. */
16
+ export const OAUTH_RESPONSE_PATH_PREFIX = '/v1/sessions/';
17
+ /** The trailing segment of the OAuth response route. */
18
+ export const OAUTH_RESPONSE_PATH_SUFFIX = '/oauth-response';
19
+ /** The longest session id an `htu` may carry — mirrors `MAX_SESSION_ID_LEN`. */
20
+ export const MAX_SESSION_ID_LEN = 128;
21
+ const SESSION_ID = /^[A-Za-z0-9_-]+$/;
22
+ /**
23
+ * Whether `sessionId` is one plain path segment: `[A-Za-z0-9_-]{1,128}`. Mirrors
24
+ * `keykeeper_committee::oauth::validate_session_id`, which every drawn verifier runs.
25
+ *
26
+ * @param sessionId - Session id returned by the verifier agent when the session was opened.
27
+ */
28
+ export function isValidSessionId(sessionId) {
29
+ return typeof sessionId === 'string' && sessionId.length > 0 && sessionId.length <= MAX_SESSION_ID_LEN && SESSION_ID.test(sessionId);
30
+ }
31
+ /**
32
+ * Normalise an origin the way the reference endpoint normaliser
33
+ * does: trim, drop a trailing slash, lower-case the scheme and authority, keep the path as
34
+ * written.
35
+ *
36
+ * The PATH keeps its case deliberately - a path is case-sensitive, and lower-casing it
37
+ * would silently rewrite an agent deployed under `/API`.
38
+ *
39
+ * @param url - Endpoint text to normalize; scheme and authority are lowercased while the path is preserved.
40
+ */
41
+ export function normalizeOrigin(url) {
42
+ const input = url.trim();
43
+ let end = input.length;
44
+ while (end > 0 && input[end - 1] === '/')
45
+ end--;
46
+ const trimmed = input.slice(0, end);
47
+ const i = trimmed.indexOf('://');
48
+ if (i < 0)
49
+ return trimmed;
50
+ const scheme = trimmed.slice(0, i);
51
+ const rest = trimmed.slice(i + 3);
52
+ const slash = rest.indexOf('/');
53
+ const authority = slash < 0 ? rest : rest.slice(0, slash);
54
+ const path = slash < 0 ? '' : rest.slice(slash);
55
+ return `${scheme.toLowerCase()}://${authority.toLowerCase()}${path}`;
56
+ }
57
+ /**
58
+ * The OAuth audience the tenant registers with its IdP and every rule pins:
59
+ * `{origin}/authz/{chainId}`.
60
+ *
61
+ * The chain id is in it so a token minted for a testnet deployment of the same platform
62
+ * cannot authorize on mainnet.
63
+ *
64
+ * @param origin - Platform origin used to derive the token audience.
65
+ * @param chainId - EVM chain identifier for the selected network.
66
+ */
67
+ export function platformAudience(origin, chainId) {
68
+ return `${normalizeOrigin(origin)}/${AUDIENCE_PATH}/${chainId.toString()}`;
69
+ }
70
+ /**
71
+ * The `htu` (RFC 9449 §4.2) a DPoP proof for an OAuth response must carry:
72
+ * `{origin}/v1/sessions/{sessionId}/oauth-response` — the URL the proof is presented at.
73
+ *
74
+ * Per session, because RFC 9449 §4.3 checks `htu` against the request URI and a conformant
75
+ * client library derives it from the URL it calls. The ORIGIN is still the agent origin the
76
+ * verifiers approved, so a client posting to a different base URL (an internal hostname, a
77
+ * proxy) must still sign over the value the agent returned, not over the URL it called.
78
+ *
79
+ * Throws on a session id that is not one plain path segment, exactly as the verifiers refuse
80
+ * one.
81
+ *
82
+ * @param origin - Verifier-agent public origin the verifiers approved.
83
+ * @param sessionId - Id of the OAuth session the proof is presented to.
84
+ */
85
+ export function dpopHtu(origin, sessionId) {
86
+ if (!isValidSessionId(sessionId)) {
87
+ throw new TasraError(`dpopHtu: session id must be 1..=${MAX_SESSION_ID_LEN} characters of [A-Za-z0-9_-]`, { retryable: false });
88
+ }
89
+ return `${normalizeOrigin(origin)}${OAUTH_RESPONSE_PATH_PREFIX}${sessionId}${OAUTH_RESPONSE_PATH_SUFFIX}`;
90
+ }
@@ -0,0 +1,51 @@
1
+ /** A keeper's operation attestation. Presence alone does not mean verified. */
2
+ export interface OperationReceipt {
3
+ /** 32-byte audit operation identifier. */
4
+ opId: Uint8Array;
5
+ /** 32-byte compound token hash. */
6
+ tokenHash: Uint8Array;
7
+ /** Ed25519 signature over the chain-bound operation attestation hash. */
8
+ attestation: Uint8Array;
9
+ }
10
+ /** Decode a fixed-size protocol hex value without silently accepting malformed bytes. */
11
+ export declare function protocolHex(value: unknown, size: number, field: string): Uint8Array;
12
+ /**
13
+ * Decode the optional receipt tuple. Incomplete tuples are protocol errors.
14
+ *
15
+ * @param reply - Keeper response fields for operation identifier, token hash and signature.
16
+ */
17
+ export declare function decodeOperationReceipt(reply: {
18
+ op_id?: unknown;
19
+ token_hash?: unknown;
20
+ op_attestation?: unknown;
21
+ }): OperationReceipt | undefined;
22
+ /**
23
+ * Deterministic operation ID, matching keykeeper_committee::audit_op_id.
24
+ *
25
+ * @param slotId - 32-byte slot identifier.
26
+ * @param operation - Operation name bound into the audit identifier.
27
+ * @param tokenHash - 32-byte compound token hash.
28
+ * @param payloadDigest - 32-byte operation payload digest.
29
+ */
30
+ export declare function auditOperationId(slotId: Uint8Array, operation: 'sign' | 'decrypt' | 'ibe-extract', tokenHash: Uint8Array, payloadDigest: Uint8Array): Uint8Array;
31
+ /** Expected operation hashes and independently authenticated keeper key for receipt verification. */
32
+ export interface ReceiptExpectation {
33
+ /** EVM chain identifier. */
34
+ chainId: number | bigint;
35
+ /** 32-byte slot identifier. */
36
+ slotId: Uint8Array;
37
+ /** 32-byte audit operation identifier. */
38
+ opId: Uint8Array;
39
+ /** 32-byte compound token hash. */
40
+ tokenHash: Uint8Array;
41
+ /** Ed25519 identity key authenticated independently, e.g. from NodeRegistry. */
42
+ keeperPublicKey: Uint8Array;
43
+ }
44
+ /**
45
+ * Verify the receipt against independently established operation and keeper identities.
46
+ * Returns false for absent, malformed or mismatched evidence. Does not prove log completeness.
47
+ *
48
+ * @param receipt - Decoded receipt, or undefined if the keeper supplied none.
49
+ * @param expected - Trusted operation hashes, chain identifier and keeper public key.
50
+ */
51
+ export declare function verifyOperationReceipt(receipt: OperationReceipt | undefined, expected: ReceiptExpectation): boolean;
@@ -0,0 +1,59 @@
1
+ import { equalBytes } from '@noble/curves/utils.js';
2
+ import { ed25519 } from '@noble/curves/ed25519';
3
+ import { keccak_256 } from '@noble/hashes/sha3';
4
+ import { concatBytes, utf8ToBytes } from '@noble/hashes/utils';
5
+ import { hexToBytes } from '../crypto/hex.js';
6
+ import { TasraError } from '../errors.js';
7
+ import { opAttestationHash } from './token.js';
8
+ /** Decode a fixed-size protocol hex value without silently accepting malformed bytes. */
9
+ export function protocolHex(value, size, field) {
10
+ if (typeof value !== 'string' || !new RegExp(`^(?:0x)?[a-fA-F0-9]{${size * 2}}$`).test(value)) {
11
+ throw new TasraError(`Invalid ${field}: expected ${size} bytes`);
12
+ }
13
+ return hexToBytes(value);
14
+ }
15
+ /**
16
+ * Decode the optional receipt tuple. Incomplete tuples are protocol errors.
17
+ *
18
+ * @param reply - Keeper response fields for operation identifier, token hash and signature.
19
+ */
20
+ export function decodeOperationReceipt(reply) {
21
+ if (reply.op_id == null && reply.token_hash == null && reply.op_attestation == null)
22
+ return undefined;
23
+ return {
24
+ opId: protocolHex(reply.op_id, 32, 'operation id'),
25
+ tokenHash: protocolHex(reply.token_hash, 32, 'token hash'),
26
+ attestation: protocolHex(reply.op_attestation, 64, 'operation attestation'),
27
+ };
28
+ }
29
+ /**
30
+ * Deterministic operation ID, matching keykeeper_committee::audit_op_id.
31
+ *
32
+ * @param slotId - 32-byte slot identifier.
33
+ * @param operation - Operation name bound into the audit identifier.
34
+ * @param tokenHash - 32-byte compound token hash.
35
+ * @param payloadDigest - 32-byte operation payload digest.
36
+ */
37
+ export function auditOperationId(slotId, operation, tokenHash, payloadDigest) {
38
+ if ([slotId, tokenHash, payloadDigest].some(bytes => bytes.length !== 32))
39
+ throw new TasraError('Operation binding must contain 32-byte hashes');
40
+ return keccak_256(concatBytes(utf8ToBytes('keykeeper-node/audit-op-id/v1'), slotId, utf8ToBytes(operation), tokenHash, payloadDigest));
41
+ }
42
+ /**
43
+ * Verify the receipt against independently established operation and keeper identities.
44
+ * Returns false for absent, malformed or mismatched evidence. Does not prove log completeness.
45
+ *
46
+ * @param receipt - Decoded receipt, or undefined if the keeper supplied none.
47
+ * @param expected - Trusted operation hashes, chain identifier and keeper public key.
48
+ */
49
+ export function verifyOperationReceipt(receipt, expected) {
50
+ try {
51
+ if (!receipt || [expected.slotId, expected.opId, expected.tokenHash, expected.keeperPublicKey].some(bytes => bytes.length !== 32) ||
52
+ receipt.attestation.length !== 64 || !equalBytes(receipt.opId, expected.opId) || !equalBytes(receipt.tokenHash, expected.tokenHash))
53
+ return false;
54
+ return ed25519.verify(receipt.attestation, opAttestationHash(expected.chainId, expected.opId, expected.slotId, expected.tokenHash), expected.keeperPublicKey, { zip215: false });
55
+ }
56
+ catch {
57
+ return false;
58
+ }
59
+ }
@@ -0,0 +1,264 @@
1
+ import { type VerifierProof, type CommitteeDecryptOpts } from './client.js';
2
+ import { type IbeCiphertext } from '../crypto/ibe.js';
3
+ import { type TokenType, type CompoundTokenWire } from './token.js';
4
+ import { type HolderSigner } from '../auth/holderProof.js';
5
+ import type { FrostSignResult } from '../signing/frost.js';
6
+ /**
7
+ * client request signature. The client (== the credential holder) proves it authorized
8
+ * this exact request by signing `clientBindingHash(slotId, tokenHash)`. Supply an ed25519 signer
9
+ * (the holder's authentication key) - the keeper (hot path) and the accountant (audit) verify it.
10
+ */
11
+ export interface ClientSigner {
12
+ /** 32-byte ed25519 public key. */
13
+ publicKey: Uint8Array;
14
+ /** Sign the 32-byte client-binding hash to 64-byte ed25519 signature. */
15
+ sign(bindingHash: Uint8Array): Uint8Array | Promise<Uint8Array>;
16
+ }
17
+ /**
18
+ * Callback that mints a separate holder proof for each verifier.
19
+ *
20
+ * A single proof cannot serve a committee: it is bound to a nonce that lives in ONE
21
+ * verifier's store, consumed atomically, so the first verifier to answer spends it and the
22
+ * rest refuse (401) under `require_holder_binding`. Pass a function instead of a string and
23
+ * the gather asks each candidate verifier for its own nonce.
24
+ */
25
+ export type HolderProofPerVerifier = (verifier: CommitteeVerifier) => Promise<string> | string;
26
+ /**
27
+ * One holder proof-of-possession per drawn verifier: fetch THAT verifier's nonce, sign it
28
+ * with the holder key over the same credentials + slot, hand it back for that verifier only.
29
+ * Pass the result as `holderProof` to {@link requestCommitteeToken} (or the one-call
30
+ * helpers built on it).
31
+ *
32
+ * @param opts - Holder signer, credentials, audience and optional operation binding.
33
+ */
34
+ export declare function holderProofPerVerifier(opts: {
35
+ signer: HolderSigner;
36
+ /** The verifiers' expected audience (their token `iss`). */
37
+ audience: string;
38
+ credentials: string[];
39
+ slotId?: string;
40
+ action?: string;
41
+ ttlSecs?: number;
42
+ }): HolderProofPerVerifier;
43
+ /**
44
+ * A {@link ClientSigner} from a 32-byte ed25519 secret key (the common `did:key` holder).
45
+ *
46
+ * @param secretKey - 32-byte Ed25519 secret seed used to sign client request bindings.
47
+ */
48
+ export declare function ed25519ClientSigner(secretKey: Uint8Array): ClientSigner;
49
+ /** One member of the active verifier set. `operator`+`pubkey` are needed only to build the
50
+ * trustless snapshot proofs; `index`+`url` alone suffice for the keeper's configured-set path. */
51
+ export interface CommitteeVerifier {
52
+ /** Zero-based verifier registry index. */
53
+ index: number;
54
+ /** Verifier HTTP base URL. */
55
+ url: string;
56
+ /** 20-byte operator address (hex). */
57
+ operator?: string;
58
+ /** 32-byte ed25519 signing pubkey (hex). */
59
+ pubkey?: string;
60
+ }
61
+ /** The chain reads the committee flow needs. Adapt from the SDK chain client with
62
+ * {@link committeeChainReadsFromClient}, or supply raw viem reads. */
63
+ export interface CommitteeChainReads {
64
+ /** 32-byte beacon seed for the current epoch. */
65
+ seed(): Promise<`0x${string}` | Uint8Array>;
66
+ /** Current beacon epoch. */
67
+ epoch(): Promise<bigint | number>;
68
+ /** Seed of a past epoch (`ThresholdRandomBeacon.seedAt`) - needed for `epochLag > 0`. */
69
+ seedAt?(epoch: bigint): Promise<`0x${string}` | Uint8Array>;
70
+ /** The slot's `[committee, quorum]` verifier policy (both `uint16`). */
71
+ verifierPolicy(slotId: `0x${string}`): Promise<readonly [number, number]>;
72
+ /** Optional anchored verifier-set snapshot `{root, size}` at an epoch - enables trustless
73
+ * proofs. Return `null` when none is anchored. */
74
+ snapshot?(epoch: bigint): Promise<{
75
+ root: `0x${string}` | Uint8Array;
76
+ size: number;
77
+ } | null>;
78
+ }
79
+ /**
80
+ * Adapt the SDK chain client's `readers` into {@link CommitteeChainReads}.
81
+ *
82
+ * @param readers - Chain reader methods for the beacon, slot verifier policy and optional verifier snapshots.
83
+ */
84
+ export declare function committeeChainReadsFromClient(readers: {
85
+ beacon: {
86
+ seed(): Promise<unknown>;
87
+ epoch(): Promise<unknown>;
88
+ seedAt?(epoch: bigint): Promise<unknown>;
89
+ };
90
+ keyRegistry: {
91
+ verifierPolicy(id: `0x${string}`): Promise<readonly [number, number]>;
92
+ };
93
+ verifierSet?: {
94
+ snapshotAt(epoch: bigint): Promise<unknown>;
95
+ };
96
+ }): CommitteeChainReads;
97
+ /** Chain reads, verifier directory, credential presentation and optional request-signing context. */
98
+ export interface RequestCommitteeTokenOpts {
99
+ /** Reader methods for the beacon and slot verifier policy. */
100
+ chain: CommitteeChainReads;
101
+ /** Pin the draw to `latest - epochLag` (0 or 1). 1 = the previous epoch, always anchored: no wait for the accountants. */
102
+ epochLag?: number;
103
+ /** The active verifier set (index to URL; add operator+pubkey to enable trustless proofs).
104
+ * Asking the whole set is fine - non-drawn verifiers reply 403 and are skipped. */
105
+ verifiers: CommitteeVerifier[];
106
+ /** 0x-prefixed 32-byte slot id. */
107
+ slotId: string;
108
+ /** Holder DID (the credentials' subject). */
109
+ holder: string;
110
+ /** Compact-JWS verifiable credentials. */
111
+ credentials: string[];
112
+ /** Proof of holder-key possession. Supply a per-verifier callback when each verifier has its own nonce store. Omitting it requires allowNoHolderProof and compatible verifier policy. */
113
+ holderProof?: string | HolderProofPerVerifier;
114
+ /** Send no holder proof. Only valid against `require_holder_binding = false`. */
115
+ allowNoHolderProof?: boolean;
116
+ /** Token type - default `'JWT'`. */
117
+ tokenType?: TokenType;
118
+ /** Token TTL in seconds - default 300. */
119
+ ttlSecs?: number;
120
+ /** Override "now" (unix seconds), mainly for tests. */
121
+ nowSecs?: number;
122
+ /** sign the request bundle with the holder's key so the keeper + audit can verify
123
+ * the user authorized this operation. Omit to skip (keeper accepts unless it requires it). */
124
+ clientSigner?: ClientSigner;
125
+ /** Identity string for an IBE-scoped operation. Verifiers bind its hash into the token and evaluate the credential scope. Omit for group signing and group decryption; ciphertext associated data is a separate field. */
126
+ scopedIdentity?: string;
127
+ }
128
+ /** Assembled compound token, committee draw and optional proofs and client signature. */
129
+ export interface CommitteeTokenResult {
130
+ /** Compound committee authorization token. */
131
+ token: CompoundTokenWire;
132
+ /** Number of verifiers selected for the committee. */
133
+ committee: number;
134
+ /** Minimum required verifier signatures. */
135
+ quorum: number;
136
+ /** Number of entries in the verifier registry. */
137
+ registrySize: number;
138
+ /** Beacon seed used for committee selection. */
139
+ seed: Uint8Array;
140
+ /** Beacon epoch used for the verifier committee draw. */
141
+ epoch: number;
142
+ /** Trustless snapshot-inclusion proofs for the token's signers, when derivable; else
143
+ * `undefined` (the keeper then uses its configured verifier set). */
144
+ verifierProofs?: VerifierProof[];
145
+ /** Ed25519 client public key corresponding to clientSignature, when a client signer was supplied. */
146
+ clientPubkey?: Uint8Array;
147
+ /** Client signature over the slot and compound token binding. */
148
+ clientSignature?: Uint8Array;
149
+ /** Policy version reported by the verifiers, when available. Diagnostic only; the keeper enforces the token rule hash against its current rule. */
150
+ ruleVersion?: number;
151
+ }
152
+ /**
153
+ * Build snapshot-inclusion proofs for the token's `signerIndexes` from the full ordered verifier
154
+ * directory. Returns `undefined` (never a wrong proof) when the directory is incomplete, a key is
155
+ * missing, or the reconstructed root disagrees with the anchored `snapshotRoot` - so a mismatch
156
+ * degrades to the keeper's configured-set path rather than shipping a proof the keeper rejects.
157
+ *
158
+ * @param verifiers - Complete verifier directory including indices, operators and public keys.
159
+ * @param registrySize - Expected number of registry entries.
160
+ * @param signerIndexes - Verifier indices whose inclusion proofs are required.
161
+ * @param snapshotRoot - Optional independently anchored verifier snapshot root.
162
+ */
163
+ export declare function buildVerifierProofs(verifiers: CommitteeVerifier[], registrySize: number, signerIndexes: number[], snapshotRoot?: Uint8Array): VerifierProof[] | undefined;
164
+ /**
165
+ * Resolve the per-request randomness + the slot's committee policy from chain, fan out to the
166
+ * drawn verifiers to gather a quorum of attributable signatures, and assemble the compound token
167
+ * (+ trustless verifier proofs when derivable). Throws if the slot has no verifierPolicy or a
168
+ * quorum can't be gathered.
169
+ */
170
+ /**
171
+ * Which beacon epoch a draw is pinned to. Keepers and verifiers admit `{latest, latest - 1}`
172
+ * (the seed pin). The accountants anchor an epoch's verifier-set snapshot one settle
173
+ * tick after the epoch starts, so a token pinned to `latest` right after a flip is refused by
174
+ * the keeper ("no verifier-set snapshot anchored at epoch N") until then; `epochLag: 1` pins
175
+ * the draw to the previous epoch, which is always anchored - no wait, same security bound.
176
+ */
177
+ export declare function pinnedDraw(chain: Pick<CommitteeChainReads, 'seed' | 'seedAt'>, latest: number, epochLag?: number): Promise<{
178
+ epoch: number;
179
+ seed: Uint8Array;
180
+ }>;
181
+ /**
182
+ * Read the verifier committee draw, request authorization and assemble the quorum token with available membership proofs.
183
+ *
184
+ * @param opts - Chain draw, verifier directory, credentials and holder authorization.
185
+ */
186
+ export declare function requestCommitteeToken(opts: RequestCommitteeTokenOpts): Promise<CommitteeTokenResult>;
187
+ /** Operation-specific fields for {@link committeeSignRequest} (everything `committeeSign` needs
188
+ * except the token, which this resolves). */
189
+ export interface CommitteeSignRequestOpts extends RequestCommitteeTokenOpts {
190
+ /** Keeper HTTP base URL. */
191
+ nodeUrl: string;
192
+ /** Raw message bytes to sign. */
193
+ message: Uint8Array;
194
+ /** Optional threshold participant identifiers for the signing ceremony. */
195
+ signingSet?: number[];
196
+ /** Optional Ed25519 owner signature over the canonical operation request. */
197
+ userSignature?: Uint8Array;
198
+ /** The keeper this request targets (anti-Sybil). Defaults to letting the node accept it. */
199
+ targetKeykeeper?: string;
200
+ }
201
+ /**
202
+ * One-call committee-authorized threshold sign: resolve token (+proofs) then POST to the keeper.
203
+ *
204
+ * @param opts - Token request settings, keeper endpoint and message to sign.
205
+ */
206
+ export declare function committeeSignRequest(opts: CommitteeSignRequestOpts): Promise<FrostSignResult>;
207
+ /** Operation-specific fields for {@link committeeDecryptRequest}. */
208
+ export interface CommitteeDecryptRequestOpts extends RequestCommitteeTokenOpts {
209
+ /** Keeper HTTP base URL. */
210
+ nodeUrl: string;
211
+ /** Ciphertext to decrypt. */
212
+ ciphertext: CommitteeDecryptOpts['ciphertext'];
213
+ /** Original encryption associated data. */
214
+ identity: Uint8Array;
215
+ /** Threshold participant identifiers for the decryption ceremony. */
216
+ decryptingSet: number[];
217
+ /** Peer identifiers for the selected BLS participants. */
218
+ blsPeers: CommitteeDecryptOpts['blsPeers'];
219
+ /** Optional Ed25519 owner signature over the canonical operation request. */
220
+ userSignature?: Uint8Array;
221
+ /** Expected key epoch of the ciphertext; used to detect rotation. */
222
+ ciphertextEpoch?: number;
223
+ /** Optional 20-byte operator address to pin the intended keeper. */
224
+ targetKeykeeper?: string;
225
+ }
226
+ /**
227
+ * One-call committee-authorized threshold decrypt.
228
+ *
229
+ * @param opts - Token request settings, keeper endpoint, ciphertext and associated data.
230
+ */
231
+ export declare function committeeDecryptRequest(opts: CommitteeDecryptRequestOpts): Promise<Uint8Array>;
232
+ /** Operation-specific fields for {@link ibeDecryptRequest} / {@link ibeExtractRequest}. */
233
+ export interface IbeExtractRequestOpts extends RequestCommitteeTokenOpts {
234
+ /** Base URLs of at least k keeper nodes holding the slot's BLS shards. */
235
+ nodeUrls: string[];
236
+ /** The IBE identity to extract for - becomes the token's `scopedIdentity`, so a quorum
237
+ * attests exactly this identity and the keepers enforce the hash binding. */
238
+ identity: string;
239
+ /** Owner signature over the identity-bound extract marker, when the slot has one. */
240
+ userSignature?: Uint8Array;
241
+ /** Expected key epoch of the ciphertext; used to detect rotation. */
242
+ ciphertextEpoch?: number;
243
+ }
244
+ /**
245
+ * Resolve an identity-scoped committee token, fan out for extraction partials, verify
246
+ * each (identifiable abort - the error names the node), and return `sk_ID` (48-byte
247
+ * compressed G1).
248
+ *
249
+ * CUSTODY OPT-IN: holding `sk_ID` is a durable capability over every past and future
250
+ * ciphertext to this identity. Prefer {@link ibeDecryptRequest}, which combines,
251
+ * decrypts and drops it. Zeroize the returned bytes when done.
252
+ *
253
+ * @param opts - Authorization context, keeper endpoints and requested identity.
254
+ */
255
+ export declare function ibeExtractRequest(opts: IbeExtractRequestOpts): Promise<Uint8Array>;
256
+ /**
257
+ * One-call identity-scoped decrypt (the read path): token to extraction fan-out
258
+ * to verify each partial to combine to decrypt. The intermediate `sk_ID` never surfaces.
259
+ *
260
+ * @param opts - Authorization context, identity and IBE ciphertext to decrypt.
261
+ */
262
+ export declare function ibeDecryptRequest(opts: IbeExtractRequestOpts & {
263
+ ciphertext: IbeCiphertext;
264
+ }): Promise<Uint8Array>;