@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,112 @@
1
+ import { type HolderSigner } from '../auth/holderProof.js';
2
+ import { type Session } from './session.js';
3
+ /**
4
+ * Connection parameters for {@link createTasraClient}. Set once and reused by
5
+ * every session the client opens.
6
+ *
7
+ * `verifier` and `identity` are optional in the type because `{jwt}` auth needs
8
+ * neither, but each is enforced at `openSession` time for the modes that do.
9
+ */
10
+ export interface TasraClientConfig {
11
+ /** k-of-n keykeeper-node base URLs. */
12
+ nodes: readonly string[];
13
+ /** Verifier base URL - required for renewalToken / redemptionToken / vpJwt auth. */
14
+ verifier?: string;
15
+ /** This holder's DID - recipient_did / holder for credential & vp-jwt auth. */
16
+ identity?: string;
17
+ }
18
+ /**
19
+ * Holder proof-of-possession options (F1/F4). The SDK fetches a `/v1/nonce` and
20
+ * signs a holder proof with `signer` (the holder DID's authentication key), bound
21
+ * to `audience` (the verifier's token `iss`) and the presented credentials.
22
+ */
23
+ export interface HolderProofAuth {
24
+ /** Holder DID authentication key or signing callback. */
25
+ signer: HolderSigner;
26
+ /** The verifier's expected audience (its token `iss`). */
27
+ audience: string;
28
+ /** Optionally scope the proof to a slot / action (must match the slot being opened). */
29
+ slotId?: string;
30
+ /** Optional action bound into the nonce and holder proof. */
31
+ action?: string;
32
+ /** Holder-proof lifetime in seconds. */
33
+ ttlSecs?: number;
34
+ }
35
+ /** The `vpJwt` auth mode's payload: signed VCs + a holder-key proof to JWT. */
36
+ export interface VpJwtAuth {
37
+ /** DCQL policy JSON to evaluate. */
38
+ dcqlRule: string;
39
+ /** Compact signed credentials presented to the verifier. */
40
+ credentials: string[];
41
+ /** Holder-key possession proof settings. */
42
+ holderProof: HolderProofAuth;
43
+ }
44
+ /** Choose exactly one JWT authorization mode. Renewal tokens support automatic refresh; other modes require a new session after expiry. */
45
+ export type SessionAuth = {
46
+ /** Caller-supplied bearer JWT; omit when another authorization mode is selected. */
47
+ jwt: string;
48
+ /** Renewal token for obtaining and refreshing bearer JWTs; omit when another mode is selected. */
49
+ renewalToken?: undefined;
50
+ /** Single-use token exchanged for a bearer JWT; omit when another mode is selected. */
51
+ redemptionToken?: undefined;
52
+ /** Credential presentation and holder proof for obtaining a bearer JWT; omit when another mode is selected. */
53
+ vpJwt?: undefined;
54
+ } | {
55
+ /** Renewal token for obtaining and refreshing bearer JWTs; omit when another mode is selected. */
56
+ renewalToken: string;
57
+ /** Caller-supplied bearer JWT; omit when another authorization mode is selected. */
58
+ jwt?: undefined;
59
+ /** Single-use token exchanged for a bearer JWT; omit when another mode is selected. */
60
+ redemptionToken?: undefined;
61
+ /** Credential presentation and holder proof for obtaining a bearer JWT; omit when another mode is selected. */
62
+ vpJwt?: undefined;
63
+ } | {
64
+ /** Single-use token exchanged for a bearer JWT; omit when another mode is selected. */
65
+ redemptionToken: string;
66
+ /** Caller-supplied bearer JWT; omit when another authorization mode is selected. */
67
+ jwt?: undefined;
68
+ /** Renewal token for obtaining and refreshing bearer JWTs; omit when another mode is selected. */
69
+ renewalToken?: undefined;
70
+ /** Credential presentation and holder proof for obtaining a bearer JWT; omit when another mode is selected. */
71
+ vpJwt?: undefined;
72
+ } | {
73
+ /** Credential presentation and holder proof for obtaining a bearer JWT; omit when another mode is selected. */
74
+ vpJwt: VpJwtAuth;
75
+ /** Caller-supplied bearer JWT; omit when another authorization mode is selected. */
76
+ jwt?: undefined;
77
+ /** Renewal token for obtaining and refreshing bearer JWTs; omit when another mode is selected. */
78
+ renewalToken?: undefined;
79
+ /** Single-use token exchanged for a bearer JWT; omit when another mode is selected. */
80
+ redemptionToken?: undefined;
81
+ };
82
+ /** Associated data and token refresh skew for a managed slot session. */
83
+ export interface OpenSessionOpts {
84
+ /** AAD for envelopes this session encrypts. Default = the 32-byte slot id. */
85
+ identity?: Uint8Array;
86
+ /** JWT refresh skew (ms) for isJwtExpiringSoon. Default 30_000. */
87
+ skewMs?: number;
88
+ }
89
+ /**
90
+ * A configured client. Holds no key material itself - each {@link Session} it
91
+ * opens owns its own JWT and (lazily) assembled master key.
92
+ */
93
+ export interface TasraClient {
94
+ /** Read-only snapshot of connection settings supplied when the client was created. */
95
+ readonly config: Readonly<TasraClientConfig>;
96
+ /** Obtain a JWT (per `auth`), assemble the slot key, and return a managed Session. */
97
+ openSession(slotId: string, auth: SessionAuth, opts?: OpenSessionOpts): Promise<Session>;
98
+ /** Currently-open sessions (live references). */
99
+ sessions(): readonly Session[];
100
+ /** Zeroize + close every open session. */
101
+ closeAll(): Promise<void>;
102
+ }
103
+ /**
104
+ * Create a client for JWT-authorized slot sessions. Configure endpoints from a network manifest downloaded from the tasra-releases repository.
105
+ *
106
+ * Sessions assemble the master key lazily on first decryption and clear it on close. Only renewal-token authorization renews automatically; other modes require a new session after expiry.
107
+ *
108
+ * @param config - Keeper URLs and the verifier or holder identity required by the selected authorization mode.
109
+ * @returns A client that opens and tracks managed slot sessions.
110
+ * @throws If no keeper URL is supplied.
111
+ */
112
+ export declare function createTasraClient(config: TasraClientConfig): TasraClient;
@@ -0,0 +1,111 @@
1
+ // TasraClient - configure connection params once (nodes + verifier +
2
+ // identity), then open managed Sessions per slot. The few-lines integration
3
+ // surface; product-agnostic (no transport/roster/messaging).
4
+ import { redeemRenewalToken, redeemCredential, verifyVpJwt, decodeJwtClaims, } from '../auth/verifier.js';
5
+ import { createHolderProof } from '../auth/holderProof.js';
6
+ import { fetchMpk } from '../keys/node-client.js';
7
+ import { hexToBytes } from '../crypto/hex.js';
8
+ import { newSession } from './session.js';
9
+ async function resolveAuth(auth, verifier, identity) {
10
+ if (auth.jwt !== undefined) {
11
+ return { jwt: auth.jwt, holder: decodeJwtClaims(auth.jwt)?.sub ?? identity ?? '' };
12
+ }
13
+ if (auth.renewalToken !== undefined) {
14
+ if (!verifier)
15
+ throw new Error('openSession({renewalToken}): config.verifier is required');
16
+ const t = await redeemRenewalToken(verifier, auth.renewalToken);
17
+ return { jwt: t.token, holder: t.holder, renewalToken: auth.renewalToken };
18
+ }
19
+ if (auth.redemptionToken !== undefined) {
20
+ if (!verifier)
21
+ throw new Error('openSession({redemptionToken}): config.verifier is required');
22
+ if (!identity)
23
+ throw new Error('openSession({redemptionToken}): config.identity (recipient DID) is required');
24
+ const t = await redeemCredential(verifier, auth.redemptionToken, identity);
25
+ return { jwt: t.token, holder: t.holder };
26
+ }
27
+ if (auth.vpJwt !== undefined) {
28
+ if (!verifier)
29
+ throw new Error('openSession({vpJwt}): config.verifier is required');
30
+ if (!identity)
31
+ throw new Error('openSession({vpJwt}): config.identity (holder DID) is required');
32
+ if (!auth.vpJwt.holderProof) {
33
+ throw new Error('openSession({vpJwt}): holderProof is required to prove control of the holder DID');
34
+ }
35
+ // F1/F4: fetch a nonce + sign a proof bound to these exact credentials.
36
+ const holderProof = await createHolderProof(verifier, {
37
+ signer: auth.vpJwt.holderProof.signer,
38
+ audience: auth.vpJwt.holderProof.audience,
39
+ credentials: auth.vpJwt.credentials,
40
+ slotId: auth.vpJwt.holderProof.slotId,
41
+ action: auth.vpJwt.holderProof.action,
42
+ ttlSecs: auth.vpJwt.holderProof.ttlSecs,
43
+ });
44
+ const t = await verifyVpJwt(verifier, {
45
+ dcql_rule: auth.vpJwt.dcqlRule,
46
+ holder: identity,
47
+ credentials: auth.vpJwt.credentials,
48
+ holder_proof: holderProof,
49
+ });
50
+ return { jwt: t.token, holder: t.holder };
51
+ }
52
+ throw new Error('openSession: unrecognized auth (expected jwt | renewalToken | redemptionToken | vpJwt)');
53
+ }
54
+ /**
55
+ * Create a client for JWT-authorized slot sessions. Configure endpoints from a network manifest downloaded from the tasra-releases repository.
56
+ *
57
+ * Sessions assemble the master key lazily on first decryption and clear it on close. Only renewal-token authorization renews automatically; other modes require a new session after expiry.
58
+ *
59
+ * @param config - Keeper URLs and the verifier or holder identity required by the selected authorization mode.
60
+ * @returns A client that opens and tracks managed slot sessions.
61
+ * @throws If no keeper URL is supplied.
62
+ */
63
+ export function createTasraClient(config) {
64
+ if (!config.nodes || config.nodes.length === 0) {
65
+ throw new Error('createTasraClient: at least one node URL is required');
66
+ }
67
+ const open = new Set();
68
+ // A shallow freeze leaves the caller's array mutable and can redirect JWT requests.
69
+ const nodes = [...config.nodes];
70
+ for (const node of nodes) {
71
+ if (typeof node !== 'string')
72
+ throw new Error('createTasraClient: invalid node URL');
73
+ const url = new URL(node);
74
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash)
75
+ throw new Error('createTasraClient: invalid node URL');
76
+ }
77
+ Object.freeze(nodes);
78
+ const frozen = Object.freeze({ ...config, nodes });
79
+ return {
80
+ config: frozen,
81
+ async openSession(slotId, auth, opts) {
82
+ const resolved = await resolveAuth(auth, frozen.verifier, frozen.identity);
83
+ const { mpkBytes, epoch } = await fetchMpk(frozen.nodes[0], slotId);
84
+ const slotIdBytes = hexToBytes(slotId);
85
+ const session = newSession({
86
+ slotId,
87
+ slotIdBytes,
88
+ nodes: frozen.nodes,
89
+ verifier: frozen.verifier,
90
+ jwt: resolved.jwt,
91
+ holder: resolved.holder,
92
+ renewalToken: resolved.renewalToken,
93
+ mpkBytes,
94
+ // Assembled lazily on the first decrypt - sign/encrypt need no shard fetch.
95
+ msk: null,
96
+ epoch,
97
+ identity: opts?.identity ?? slotIdBytes,
98
+ skewMs: opts?.skewMs ?? 30_000,
99
+ onClose: s => open.delete(s),
100
+ });
101
+ open.add(session);
102
+ return session;
103
+ },
104
+ sessions() {
105
+ return [...open];
106
+ },
107
+ async closeAll() {
108
+ await Promise.all([...open].map(s => s.close()));
109
+ },
110
+ };
111
+ }
@@ -0,0 +1,3 @@
1
+ export { createTasraClient } from './client.js';
2
+ export type { TasraClient, TasraClientConfig, SessionAuth, VpJwtAuth, HolderProofAuth, OpenSessionOpts, } from './client.js';
3
+ export type { Session, SignOpts } from './session.js';
@@ -0,0 +1,2 @@
1
+ // Managed Client + Session - the high-level, few-lines integration surface.
2
+ export { createTasraClient } from './client.js';
@@ -0,0 +1,67 @@
1
+ import { type GroupEnvelope } from '../crypto/envelope.js';
2
+ import { type FrostSignResult } from '../signing/frost.js';
3
+ import { type EoaSignature } from '../signing/ecdsa.js';
4
+ /** Per-call overrides for a FROST custody signature. */
5
+ export interface SignOpts {
6
+ /** Explicit signer set (u16 ids); omit to node uses 1..k. */
7
+ signingSet?: number[];
8
+ /** 64-byte Ed25519 user signature - required iff the slot has an owner key. */
9
+ userSignature?: Uint8Array;
10
+ /** 20-byte operator address to pin (anti-Sybil). */
11
+ targetKeykeeper?: string;
12
+ /** Idempotency key (required when userSignature is set). */
13
+ requestId?: string;
14
+ }
15
+ /** A live, managed access session for one key slot. */
16
+ export interface Session {
17
+ /** 0x-prefixed bytes32 slot id. */
18
+ readonly slotId: string;
19
+ /** Subject the JWT was minted for. */
20
+ readonly holder: string;
21
+ /** 96-byte compressed G2 group public key of the currently-assembled epoch. */
22
+ readonly mpkBytes: Uint8Array;
23
+ /** Epoch of the currently-assembled master key. */
24
+ readonly epoch: number;
25
+ /** The current JWT. Access after close throws. */
26
+ readonly jwt: string;
27
+ /** Encrypt to this slot's group key. Local + synchronous (needs no JWT). */
28
+ encrypt(plaintext: Uint8Array, opts?: {
29
+ identity?: Uint8Array;
30
+ epoch?: bigint | null;
31
+ }): Uint8Array;
32
+ /** Decrypt with the assembled master key. Refreshes the JWT first and, on an
33
+ * epoch mismatch (the slot rotated), re-assembles and retries once. */
34
+ decrypt(envelope: Uint8Array | GroupEnvelope): Promise<Uint8Array>;
35
+ /** FROST-Ed25519 custody signature over `message`. */
36
+ sign(message: Uint8Array, opts?: SignOpts): Promise<FrostSignResult>;
37
+ /** Threshold-ECDSA signature over a 32-byte digest (EVM EOA slots). */
38
+ signDigest(digest: Uint8Array, opts?: {
39
+ targetKeykeeper?: string;
40
+ }): Promise<EoaSignature>;
41
+ /** Renew the JWT if it is near expiry and re-assemble on rotation. */
42
+ ensureFresh(): Promise<void>;
43
+ /** End this session, clear held key material and prevent further operations. Safe to call again. */
44
+ close(): Promise<void>;
45
+ }
46
+ /** Construction inputs - internal to the client/session pair. */
47
+ export interface SessionInit {
48
+ slotId: string;
49
+ slotIdBytes: Uint8Array;
50
+ nodes: readonly string[];
51
+ verifier: string | undefined;
52
+ jwt: string;
53
+ holder: string;
54
+ /** Long-lived renewal token - the only auth mode that can silently re-mint. */
55
+ renewalToken: string | undefined;
56
+ mpkBytes: Uint8Array;
57
+ /** Assembled master key, or `null` to assemble lazily on the first decrypt - so a
58
+ * sign-only session (e.g. a FROST slot, which has no reconstructable key) never
59
+ * reconstructs one, and encrypt/sign pay no shard-fetch cost. */
60
+ msk: Uint8Array | null;
61
+ epoch: number;
62
+ identity: Uint8Array;
63
+ skewMs: number;
64
+ onClose: (session: Session) => void;
65
+ }
66
+ /** Build a managed session from resolved inputs (used by the client). */
67
+ export declare function newSession(init: SessionInit): Session;
@@ -0,0 +1,238 @@
1
+ // Session - the managed, product-agnostic handle returned by
2
+ // `client.openSession(...)`. It holds a slot's assembled master key + the
3
+ // current JWT, keeps the JWT fresh (lazy, no timers), re-assembles the key when
4
+ // the slot rotates, and exposes encrypt / decrypt / sign bound to the slot.
5
+ //
6
+ // All crypto/HTTP is delegated to the existing primitives - this layer only
7
+ // orchestrates them. No transport/roster/messaging concepts live here.
8
+ import { encryptEnvelope, decryptEnvelope, toBytes, fromBytes, } from '../crypto/envelope.js';
9
+ import { fetchMpk, fetchAndAssembleKey } from '../keys/node-client.js';
10
+ import { redeemRenewalToken, isJwtExpiringSoon } from '../auth/verifier.js';
11
+ import { signCustody } from '../signing/frost.js';
12
+ import { signEoaDigest } from '../signing/ecdsa.js';
13
+ import { SlotRotatedError, TasraError } from '../errors.js';
14
+ class ManagedSession {
15
+ #slotId;
16
+ #slotIdBytes;
17
+ #nodes;
18
+ #verifier;
19
+ #holder;
20
+ #renewalToken;
21
+ #identity;
22
+ #skewMs;
23
+ #onClose;
24
+ #jwt;
25
+ #msk;
26
+ #assembling = null;
27
+ #mpkBytes;
28
+ #epoch;
29
+ #closed = false;
30
+ constructor(init) {
31
+ this.#slotId = init.slotId;
32
+ this.#slotIdBytes = init.slotIdBytes.slice();
33
+ this.#nodes = init.nodes.slice();
34
+ this.#verifier = init.verifier;
35
+ this.#holder = init.holder;
36
+ this.#renewalToken = init.renewalToken;
37
+ this.#identity = init.identity.slice();
38
+ this.#skewMs = init.skewMs;
39
+ this.#onClose = init.onClose;
40
+ this.#jwt = init.jwt;
41
+ this.#msk = init.msk;
42
+ this.#mpkBytes = init.mpkBytes.slice();
43
+ this.#epoch = init.epoch;
44
+ }
45
+ #assertOpen() {
46
+ if (this.#closed)
47
+ throw new TasraError('Session is closed');
48
+ }
49
+ get slotId() {
50
+ return this.#slotId;
51
+ }
52
+ get holder() {
53
+ return this.#holder;
54
+ }
55
+ get mpkBytes() {
56
+ this.#assertOpen();
57
+ return this.#mpkBytes.slice();
58
+ }
59
+ get epoch() {
60
+ return this.#epoch;
61
+ }
62
+ get jwt() {
63
+ this.#assertOpen();
64
+ return this.#jwt;
65
+ }
66
+ encrypt(plaintext, opts) {
67
+ this.#assertOpen();
68
+ const identity = opts?.identity ?? this.#identity;
69
+ const epoch = opts?.epoch !== undefined ? opts.epoch : BigInt(this.#epoch);
70
+ return toBytes(encryptEnvelope(this.#slotIdBytes, this.#mpkBytes, identity, plaintext, epoch));
71
+ }
72
+ async decrypt(envelope) {
73
+ this.#assertOpen();
74
+ const env = envelope instanceof Uint8Array ? fromBytes(envelope) : envelope;
75
+ await this.ensureFresh();
76
+ const msk = await this.#ensureAssembled();
77
+ this.#assertOpen();
78
+ try {
79
+ return decryptEnvelope(env, msk);
80
+ }
81
+ catch (err) {
82
+ // Rotation: a v0x02 envelope produced under a different epoch than our
83
+ // assembled key. Re-assemble against the live slot and retry exactly once.
84
+ if (env.epoch !== null && Number(env.epoch) !== this.#epoch) {
85
+ const staleEpoch = this.#epoch;
86
+ await this.#reassemble();
87
+ try {
88
+ return decryptEnvelope(env, this.#msk);
89
+ }
90
+ catch (retryErr) {
91
+ // Still failing after re-assembling: the epoch mismatch was real but
92
+ // re-keying did not resolve it. Surface it as a rotation error carrying
93
+ // both epochs rather than the opaque AEAD failure.
94
+ throw new SlotRotatedError({
95
+ expected: Number(env.epoch),
96
+ actual: this.#epoch,
97
+ slotId: this.#slotId,
98
+ message: `decrypt failed for slot ${this.#slotId.slice(0, 10)}…: envelope is epoch ` +
99
+ `${Number(env.epoch)}, key was epoch ${staleEpoch}, slot is now epoch ${this.#epoch} ` +
100
+ `(${retryErr instanceof Error ? retryErr.message : String(retryErr)})`,
101
+ });
102
+ }
103
+ }
104
+ throw err;
105
+ }
106
+ }
107
+ // Lazily Lagrange-assemble the master key from k-of-n shards on the first decrypt.
108
+ // `encrypt` (public key only) and `sign` (JWT only) never call this - so a FROST /
109
+ // sign-only session never fetches shards or reconstructs a key.
110
+ async #ensureAssembled() {
111
+ this.#assertOpen();
112
+ if (this.#msk !== null)
113
+ return this.#msk;
114
+ if (this.#assembling === null) {
115
+ this.#assembling = fetchAndAssembleKey({ urls: this.#nodes, jwt: this.#jwt }, this.#slotId)
116
+ .then(key => {
117
+ if (this.#closed) {
118
+ key.fill(0);
119
+ this.#assertOpen();
120
+ }
121
+ this.#msk = key;
122
+ return key;
123
+ })
124
+ .finally(() => { this.#assembling = null; });
125
+ }
126
+ const key = await this.#assembling;
127
+ this.#assertOpen();
128
+ return key;
129
+ }
130
+ async sign(message, opts) {
131
+ await this.ensureFresh();
132
+ this.#assertOpen();
133
+ return signCustody({
134
+ nodeUrl: this.#nodes[0],
135
+ jwt: this.#jwt,
136
+ slotId: this.#slotId,
137
+ message,
138
+ signingSet: opts?.signingSet,
139
+ userSignature: opts?.userSignature,
140
+ targetKeykeeper: opts?.targetKeykeeper,
141
+ requestId: opts?.requestId,
142
+ });
143
+ }
144
+ async signDigest(digest, opts) {
145
+ await this.ensureFresh();
146
+ this.#assertOpen();
147
+ return signEoaDigest({
148
+ nodeUrl: this.#nodes[0],
149
+ jwt: this.#jwt,
150
+ slotId: this.#slotId,
151
+ digest,
152
+ targetKeykeeper: opts?.targetKeykeeper,
153
+ });
154
+ }
155
+ /**
156
+ * Renew the JWT if it is near expiry and this session can renew silently. Returns whether
157
+ * it actually renewed.
158
+ *
159
+ * THE ONE COPY of that policy. It used to be written out in both `ensureFresh` and
160
+ * `#reassemble`; the duplicate in `#reassemble` was unreachable (its only caller runs
161
+ * `ensureFresh` first), so relaxing the skew or the auth-mode condition here would have
162
+ * left a second, diverging copy enforcing the old rule on a path nothing exercises. Both
163
+ * callers now go through this, and calling it twice is a pure no-op - the check is
164
+ * synchronous and costs no I/O once the token is fresh.
165
+ */
166
+ async #renewJwtIfStale() {
167
+ // Hot path: a still-valid JWT costs zero I/O.
168
+ if (!isJwtExpiringSoon(this.#jwt, this.#skewMs))
169
+ return false;
170
+ // Silent renewal is only possible with a long-lived renewal token. The
171
+ // other auth modes fail loud on the next node call (401/403) to re-open.
172
+ if (!this.#renewalToken || !this.#verifier)
173
+ return false;
174
+ const t = await redeemRenewalToken(this.#verifier, this.#renewalToken);
175
+ this.#assertOpen();
176
+ this.#jwt = t.token;
177
+ return true;
178
+ }
179
+ async ensureFresh() {
180
+ this.#assertOpen();
181
+ const renewed = await this.#renewJwtIfStale();
182
+ this.#assertOpen();
183
+ if (!renewed)
184
+ return;
185
+ // A renewal often coincides with a slot rotation (revocation rotates the
186
+ // slot). Pick up a new epoch + key if it changed.
187
+ const { mpkBytes, epoch } = await fetchMpk(this.#nodes[0], this.#slotId);
188
+ this.#assertOpen();
189
+ if (epoch !== this.#epoch) {
190
+ // Re-assemble only if we'd already assembled (a decrypt happened); otherwise the
191
+ // next decrypt assembles fresh against the new epoch.
192
+ if (this.#msk !== null) {
193
+ const fresh = await fetchAndAssembleKey({ urls: this.#nodes, jwt: this.#jwt }, this.#slotId);
194
+ if (this.#closed) {
195
+ fresh.fill(0);
196
+ this.#assertOpen();
197
+ }
198
+ this.#msk.fill(0);
199
+ this.#msk = fresh;
200
+ }
201
+ this.#mpkBytes = mpkBytes;
202
+ this.#epoch = epoch;
203
+ }
204
+ }
205
+ async #reassemble() {
206
+ this.#assertOpen();
207
+ // The shard fetch below is AUTHENTICATED, so it must never go out with a token that has
208
+ // aged out. Today its only caller (`decrypt`) has already run `ensureFresh`, which makes
209
+ // this a no-op - but the call stays so the guarantee belongs to this method rather than to
210
+ // its caller's ordering, which nothing enforces.
211
+ await this.#renewJwtIfStale();
212
+ const { mpkBytes, epoch } = await fetchMpk(this.#nodes[0], this.#slotId);
213
+ this.#assertOpen();
214
+ const fresh = await fetchAndAssembleKey({ urls: this.#nodes, jwt: this.#jwt }, this.#slotId);
215
+ if (this.#closed) {
216
+ fresh.fill(0);
217
+ this.#assertOpen();
218
+ }
219
+ this.#msk?.fill(0);
220
+ this.#msk = fresh;
221
+ this.#mpkBytes = mpkBytes;
222
+ this.#epoch = epoch;
223
+ }
224
+ async close() {
225
+ if (this.#closed)
226
+ return;
227
+ this.#closed = true;
228
+ this.#msk?.fill(0);
229
+ this.#msk = null;
230
+ this.#jwt = '';
231
+ this.#renewalToken = undefined;
232
+ this.#onClose(this);
233
+ }
234
+ }
235
+ /** Build a managed session from resolved inputs (used by the client). */
236
+ export function newSession(init) {
237
+ return new ManagedSession(init);
238
+ }