@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,129 @@
1
+ # Build encrypted notes
2
+
3
+ Encrypt a private note and let Alice open it with her credential. Bob receives a
4
+ credential from the same issuer, but the slot policy gives him no access. The app
5
+ also proves that changing an encrypted byte fails authentication.
6
+
7
+ The complete application is [encrypted-notes.ts](../examples/encrypted-notes.ts).
8
+ It uses Node.js and `@t3foundry/tasra-sdk`; Web Crypto for AES-256-GCM is built into Node.
9
+
10
+ ## Architecture
11
+
12
+ Encryption uses two layers:
13
+
14
+ 1. **AES-256-GCM** encrypts the actual payload (the note) with a random 32-byte
15
+ data key. The authenticated additional data (AAD) is derived from a stable
16
+ record identifier: `SHA-256("tasra-encrypt/v2:" + recordId)`.
17
+ 2. **BLS KEM** (BLS12-381 ElGamal in G₂ with ChaCha20-Poly1305) wraps the
18
+ AES data key under the slot's threshold group public key. Encryption needs
19
+ only the public key — no credential, no network round-trip.
20
+
21
+ Decryption reverses the flow: the verifier committee authorizes the operation,
22
+ the keeper committee provides partial decryptions, the BLS KEM recovers the
23
+ AES data key, and the application decrypts the payload. The slot never sees
24
+ the payload.
25
+
26
+ This is the `tasra-encrypt/v2` scheme. See the `tasra-encryption` skill
27
+ for the envelope schema and lower-level KEM operations.
28
+
29
+ ## 1. Create the project
30
+
31
+ Install Node.js **24**. The example downloads and checksum-verifies the testnet
32
+ manifest from [tasra-releases](https://github.com/t3foundry/tasra-releases).
33
+ The deployment needs BLS key generation, creator-signed rule provisioning,
34
+ OID4VP with SD-JWT and `did:jwk` support, keeper receipts and committee
35
+ decryption. It must support the requested 2-of-3 keeper and verifier policies
36
+ and provide any usage credits needed by the operations.
37
+
38
+ Use a macOS/Linux shell or WSL for these commands and the private file store.
39
+
40
+ ```sh
41
+ mkdir my-encrypted-notes
42
+ cd my-encrypted-notes
43
+ npm init -y
44
+ npm pkg set type=module
45
+ npm install @t3foundry/tasra-sdk@latest
46
+ npm install --save-dev tsx typescript @types/node
47
+ cp node_modules/@t3foundry/tasra-sdk/examples/encrypted-notes.ts app.ts
48
+ cp node_modules/@t3foundry/tasra-sdk/examples/tutorial-support.ts .
49
+ cp node_modules/@t3foundry/tasra-sdk/examples/tutorial-negative.ts .
50
+ cp node_modules/@t3foundry/tasra-sdk/examples/network.ts .
51
+ cp node_modules/@t3foundry/tasra-sdk/examples/fund-slot.ts .
52
+ printf '.tasra/\nnode_modules/\n' > .gitignore
53
+ ```
54
+
55
+ `network.ts` downloads the release pointer and verifies the manifest bytes.
56
+ `tutorial-support.ts` creates and privately saves fresh wallets and identities.
57
+ It prints the creator address and waits for you to fund it through the selected
58
+ network's faucet or your own wallet. `tutorial-negative.ts` submits an unauthorized
59
+ credential to test server refusal. The application creates its own slot.
60
+
61
+ ## 2. Check and run
62
+
63
+ Before protected operations, the terminal example pauses for **TSRA usage credit**.
64
+ In a second terminal in the same project, run its printed `fund-slot.ts ... status`
65
+ command. Follow [Fund a slot](funding.md) to obtain EURC, buy TSRA from BondingCurve,
66
+ and deposit TSRA into the printed slot. Replace `.tasra/first-slot` in those commands
67
+ with this app's printed directory. Fund every new slot; creator AVAX pays gas and
68
+ does not provide usage credits. Keep the app running while funding. After its
69
+ 15-minute wait expires, a new run creates fresh accounts and slots; funding
70
+ the old slot does not resume the exited run.
71
+
72
+
73
+ Typecheck on any platform:
74
+
75
+ ```sh
76
+ npx tsc --noEmit --target ES2022 --module NodeNext --moduleResolution NodeNext --strict --skipLibCheck --resolveJsonModule app.ts
77
+ ```
78
+
79
+ Run the application and fund the printed creator address on the selected chain
80
+ within its 15-minute funding wait:
81
+
82
+ ```sh
83
+ npx tsx network.ts
84
+ npx tsx app.ts
85
+ ```
86
+
87
+ Expect a final `PASS: Alice decrypted, Bob refused by verifier, tamper rejected.`
88
+ The app prints the new private directory and its `evidence.json` path. It creates
89
+ all its own identities, credentials and slot; no existing learner account or slot
90
+ ID is required. Every full run creates fresh state.
91
+
92
+ ## 3. Read the code
93
+
94
+ 1. **Create identities and credentials.** `tasra.identities.create()` creates each
95
+ person. `tasra.credentials.issue()` gives them a document-scoped credential
96
+ pinned to a random record identifier.
97
+ 2. **Create the slot.** `tasra.credentials.policy()` pins the issuer, Alice's DID,
98
+ role and document scope. `tasra.slots.create()` saves the intent, commits and
99
+ reveals it, waits for the 2-of-3 BLS key, and provisions the policy.
100
+ 3. **Encrypt.** The app generates a random 32-byte AES-256 data key, derives
101
+ AAD from the record identifier, and encrypts the plaintext with AES-256-GCM
102
+ (Web Crypto). `notes.encrypt(aad, dataKey)` BLS KEM-wraps the data key
103
+ using only the slot's public key — offline, no credential needed.
104
+ 4. **Decrypt and open.** `notes.decrypt(aad, kemCt, {authorize, requireReceipts: true})`
105
+ verifies Alice's operation authorization, collects keeper partial decryptions,
106
+ recovers the AES data key, and zeroizes it after the application decrypts
107
+ the AES-GCM payload.
108
+ 5. **Check failures.** Bob's credential is submitted to the real verifier with the
109
+ `decrypt` action and the ciphertext's payload digest; the verifier agent refuses
110
+ him. The tamper test flips a byte in the KEM ciphertext's AEAD tag and calls
111
+ `notes.decrypt` again — the committee still provides partial decryptions (they
112
+ depend only on `U`, which is unchanged), but the ChaCha20-Poly1305
113
+ authentication fails after combining.
114
+
115
+ Private keys, credentials and durable SDK journals stay below `.tasra/`. Only
116
+ `evidence.json` is intended for review: it contains transaction references,
117
+ receipt references and the three test outcomes. Do not publish the whole directory.
118
+
119
+ The slot policy authorizes decryption per cryptographic operation — the verifier
120
+ commitee checks Alice's credential before the keeper committee releases partial
121
+ decryptions. The application layer enforces record-level access through the AAD
122
+ derived from the record identifier. The SDK reports anchored-group assurance,
123
+ not independently certified per-keeper verifying shares.
124
+
125
+ `npx tsx network.ts` saves the verified manifest and its checksum pin. Keep both
126
+ files with the application so restarts use the same deployment. The examples use
127
+ `lowest-operator-id` as the explicit coordinator convention; confirm it matches
128
+ the selected service. Fund each newly printed creator address with at least 0.05
129
+ AVAX on Fuji before continuing; more may be needed if gas costs rise.
@@ -0,0 +1,100 @@
1
+ # Encrypt data and authorize decryption
2
+
3
+ Use a **non-exportable BLS slot** when credential holders should decrypt data
4
+ without receiving the master key. A slot is the network-managed key plus its access rule.
5
+
6
+ ## Start with a new application
7
+
8
+ Follow [Build encrypted notes](encrypted-notes.md) for exact installation and run
9
+ commands. It creates a fresh issuer, Alice and Bob, then a BLS slot from the public
10
+ manifest. The only application runtime dependency is `@t3foundry/tasra-sdk`.
11
+
12
+ 1. Connect with `new TasraClient({manifest, wallet, store})`.
13
+ 2. Issue a holder-bound credential with `tasra.credentials.issue` and define the
14
+ issuer-rooted document scope with `tasra.credentials.policy`.
15
+ 3. Call `tasra.slots.create({name, mode: 'bls', policy, threshold, verifiers})`.
16
+ 4. Encrypt using `slot.encrypt(identity, bytes)`; decrypt using `slot.decrypt`
17
+ with `tasra.credentials.authorize(...)` and required keeper receipts.
18
+ 5. Verify the plaintext, actual server refusal for Bob, and ciphertext tampering.
19
+
20
+ Creation, rule commitment/delivery, key readiness and verifier setup are SDK
21
+ operations. Keep the private store and original intent when resuming; reconcile
22
+ unknown transaction outcomes before another submission.
23
+
24
+ ## Advanced existing committee integrations
25
+
26
+ The remaining sections describe the lower-level committee/session path for
27
+ applications that already supply credentials and slots. Use it only when its
28
+ protocol matches your deployment; it is not the setup for the new tutorial.
29
+
30
+ ### Before you start
31
+
32
+
33
+ Download and checksum-verify the selected manifest from
34
+ [tasra-releases](https://github.com/t3foundry/tasra-releases). Confirm that the
35
+ deployment supports the chosen authorization and decryption routes, then prepare:
36
+
37
+ | Input | Where it comes from |
38
+ |---|---|
39
+ | Deployment manifest, trusted checksum, RPC | The downloaded release manifest and its trusted pointer. |
40
+ | BLS slot ID | [Create and provision a slot](prerequisites.md#operator-setup), or use one supplied by the fleet owner. |
41
+ | Credential issued to your holder DID | An issuer accepted by the slot's credential rule. Creating a holder key does not issue a credential. |
42
+ | Holder signing key and verifier audience | Your wallet/key store and the deployment's verifier configuration. |
43
+ | Metering balance and verifier-set snapshot | The slot's funding and the deployment's active verifier set. |
44
+
45
+ Use [the configuration table](prerequisites.md#application-configuration) to set the
46
+ `KK_*` inputs for the shipped Node example. If the fleet uses a private CA, configure
47
+ `NODE_EXTRA_CA_CERTS` with its public CA file before starting Node.
48
+
49
+ The direct committee example requires a fleet that accepts compound tokens without
50
+ request binding. For a fleet enforcing request binding, use the
51
+ [verifier-agent presentation flow](api.md#t3foundrytasra-sdkoid4vp--credential-wallets-against-the-verifier-agent).
52
+
53
+ ### Run the complete example
54
+
55
+ From your application directory, after installing the compatible SDK and `tsx` as developer tooling:
56
+
57
+ ```sh
58
+ npx tsx node_modules/@t3foundry/tasra-sdk/examples/getting-started.ts
59
+ ```
60
+
61
+ Expected result:
62
+
63
+ ```text
64
+ Threshold decrypt succeeded; the master key was not exported.
65
+ ```
66
+
67
+ Read [the application](../examples/getting-started.ts) and its
68
+ [configuration helpers](../examples/live-config.ts). Both ship in the npm package.
69
+ The helpers load your files, verify the deployment, discover keepers, and create
70
+ a fresh holder proof for each verifier. They do not start services or issue credentials.
71
+
72
+ ### Understand the two operations
73
+
74
+ `createCommitteeSlotClient` is the application client for this flow:
75
+
76
+ | Operation | Behavior |
77
+ |---|---|
78
+ | `client.encrypt(slotId, plaintext, {identity})` | Reads the slot's public key and encrypts locally. Returns serialized envelope bytes. |
79
+ | `client.decrypt(slotId, request)` | Obtains authorization, requests threshold decryption from keepers, and returns plaintext bytes. |
80
+
81
+ Decode the encrypted envelope with `fromBytes` to obtain `ciphertext`, `identity`,
82
+ and `epoch`. Decryption also needs the keeper IDs and peer records discovered from
83
+ the slot. The complete example supplies these rather than assuming a fixed committee.
84
+
85
+ To verify access control, repeat with a holder whose credential does not satisfy
86
+ the rule. Record the authorization denial separately from connectivity failures.
87
+ If testing revocation, wait for the deployment's documented propagation/token-expiry
88
+ window. Revocation cannot erase plaintext already received.
89
+
90
+ ### If you want an exportable personal vault
91
+
92
+ Use [examples/personal-vault.ts](../examples/personal-vault.ts) with an explicitly
93
+ exportable BLS slot and `createTasraSlotClient`. Its managed session assembles and
94
+ caches the master key for local decryption. A holder can retain that key after
95
+ revocation. Close sessions with `client.closeAll()` when finished.
96
+
97
+ See [errors and retry decisions](errors.md) for failures, and
98
+ [Advanced clients and OAuth](api.md) for other custody and encryption APIs.
99
+
100
+ [Documentation index](README.md)
package/docs/errors.md ADDED
@@ -0,0 +1,76 @@
1
+ # Handling failures
2
+
3
+ > The error taxonomy, what is retryable, and how to tell a denial from an outage.
4
+
5
+ Use exported error classes and fields instead of matching `err.message`.
6
+ `TasraError` covers the typed failures in the table below, but some SDK errors
7
+ extend plain `Error`, including the reconciliation errors described later.
8
+
9
+ For a read that is safe to repeat, classify the failure before scheduling a
10
+ bounded retry. The recovery functions below are application callbacks:
11
+
12
+ ```ts
13
+ import {
14
+ isAuthDenied, isRetryable, ThresholdNotMetError, SlotRotatedError,
15
+ } from '@t3foundry/tasra-sdk'
16
+
17
+ try {
18
+ await readStatus() // An application read with no write effects.
19
+ } catch (e) {
20
+ if (isAuthDenied(e)) return reclaimCredential() // 401/403 — retrying is futile
21
+ if (e instanceof ThresholdNotMetError) {
22
+ // One reason per participant that failed.
23
+ console.warn(`only ${e.got}/${e.need} answered:`, e.reasons)
24
+ }
25
+ if (e instanceof SlotRotatedError) throw e // Review the changed slot.
26
+ if (isRetryable(e)) return scheduleBoundedReadRetry()
27
+ throw e
28
+ }
29
+ ```
30
+
31
+ | Class | Carries | `retryable` |
32
+ |---|---|---|
33
+ | `TasraError` | base for all of the below | — |
34
+ | `TasraHttpError` | `status`, `url`, `body` (200 chars) | 5xx / 429 |
35
+ | `AuthDeniedError` | as above; 401/403 | **never** |
36
+ | `NodeUnreachableError` | `url` — no HTTP answer at all | yes |
37
+ | `ThresholdNotMetError` | `got`, `need`, `reasons[]` | yes, unless every node denied |
38
+ | `SlotRotatedError` | `expected`, `actual` epoch | yes |
39
+ | `CommitteeAuthorizeError` | as `TasraHttpError` — a verifier refused to co-sign | 5xx / 429 |
40
+ | `DcqlMalformedError` | the rule is not well-formed OID4VP-DCQL | **never** |
41
+ | `VerifierAgentSessionError` | `kind`, `correlation`, `httpStatus?` — a Verifier Agent session failed | `timeout` / `unavailable` only |
42
+ | `RuleAmendmentError` | `code`, `slotId`, and when known `pendingVersion`, `pendingCommitment`, `hasGuardian`, `notBefore`, `chainTime`, `have`, `need`, `results`, `phase` — a rule amendment refused before signing, or one that did not reach the asked state | `timelock` / `below-threshold` / `timeout` only |
43
+
44
+ `isRetryable(e)` returns `false` for errors outside the `TasraError` hierarchy.
45
+ A `true` result describes a possibly transient failure; it does not prove that
46
+ repeating the operation is safe. Restrict automatic retries to safe reads, with
47
+ an attempt limit, deadline and cancellation. Never automatically repeat a
48
+ transaction, signing request or approval submission after an uncertain outcome.
49
+ `isAuthDenied(e)` is keyed on HTTP status rather than class, so it also catches a
50
+ 403 from `CommitteeAuthorizeError`.
51
+
52
+ Argument validation (a malformed slot id, a client configured with no nodes) still
53
+ throws plain `Error` — those are programming mistakes, not runtime conditions to
54
+ branch on.
55
+
56
+ ## Uncertain submissions
57
+
58
+ Retain the original operation details and reconcile before submitting again:
59
+
60
+ | Error | Import | Retained details and recovery |
61
+ |---|---|---|
62
+ | `CreationReconciliationRequiredError` | `@t3foundry/tasra-sdk/app` | `slotId`, `step`; preserve the creation journal and reconcile the wallet transaction before resuming. |
63
+ | `ApplicationSlotRecoveryError` | `@t3foundry/tasra-sdk/app` | `code`, `recoveryName`, optional `slotId` and `transactionHash`; inspect the saved named intent or original verifier-policy transaction before resuming. `VERIFIER_POLICY_OUTCOME_UNKNOWN` means a submission may have happened without a recorded hash; never submit another policy transaction until reconciled. `VERIFIER_POLICY_RECEIPT_PENDING` has a saved hash and can resume receipt observation. |
64
+ | `OperationOutcomeUnknownError` | `@t3foundry/tasra-sdk/committee` | `operation`, optional `requestId`; inspect the original approval request. If its ID was lost, retain that uncertainty. |
65
+ | `RelayOutcomeUnknownError` | `@t3foundry/tasra-sdk/chain` | `attempt`; use `reconcileRelayAttempt` with that signed request and the trusted chain reader before considering a replacement. |
66
+ | `AgentSessionCreationUnknownError` | `@t3foundry/tasra-sdk/chain` | `profile`; session creation may have reached that provider. A replacement requires explicitly opening a fresh wallet session; do not transfer session secrets or presentations. |
67
+
68
+ The last two classes extend plain `Error`, so check them explicitly with
69
+ `instanceof`. Unknown errors and cancellation after submission also leave the
70
+ remote outcome uncertain. Stopping local work does not undo a submitted request.
71
+ Log only public diagnostic references, never entire errors, signed requests,
72
+ credentials or tokens.
73
+
74
+ ---
75
+
76
+ [Back to the README](../README.md) · [Documentation index](README.md)
package/docs/flows.md ADDED
@@ -0,0 +1,289 @@
1
+ # Application flows
2
+
3
+ New to TASRA? Follow the [step-by-step learning path](README.md) first. This page
4
+ is a detailed reference for returning developers.
5
+
6
+ Build around an outcome: create a shared account, let a user approve a document,
7
+ or decrypt a file they are allowed to read. The application API combines the
8
+ protocol steps behind these outcomes so your app does not need to assemble
9
+ transaction state machines, credential presentations and threshold cryptography.
10
+
11
+ Start with `TasraClient` from `@t3foundry/tasra-sdk/app`. Install with
12
+ `npm install @t3foundry/tasra-sdk@latest`, then [connect your first app](getting-started.md).
13
+ See [installation](installation.md) for runtime and TypeScript setup. The snippets
14
+ below illustrate individual steps; the linked tutorials contain complete projects,
15
+ including fresh keys, funding, policies and storage.
16
+ Building with a coding agent? Use [Skills and example prompts](ai-development.md)
17
+ to turn these flows into application requests.
18
+
19
+ ## Choose a flow
20
+
21
+ | Your application needs to… | Flow |
22
+ |---|---|
23
+ | Connect to a TASRA deployment | [Load a manifest](#connect-to-a-deployment) |
24
+ | Set up a usable slot and continue after an interruption | [Create and resume a slot](#create-and-resume-a-slot) |
25
+ | Create an account or connect a user's Ethereum wallet | [Use wallets and recorded transfers](#use-wallets-and-recorded-transfers) |
26
+ | Give users credentials for an application | [Create identities and credentials](#create-identities-and-credentials) |
27
+ | Ask a credential holder to authorize an action | [Authorize an exact operation](#authorize-an-exact-operation) |
28
+ | Let multiple eligible users use one Ethereum account | [Use a shared Ethereum account](#use-a-shared-ethereum-account) |
29
+ | Encrypt files and control who may decrypt them | [Encrypt and decrypt documents](#encrypt-and-decrypt-documents) |
30
+ | Produce a verified document signature | [Sign a document](#sign-a-document) |
31
+ | Require several people to approve one signature | [Collect multiple approvals](#collect-multiple-approvals) |
32
+ | Use an organization's identity provider | [Integrate OAuth authorization](#integrate-oauth-authorization) |
33
+
34
+ ## Connect to a deployment
35
+
36
+ ```ts
37
+ import {TasraClient} from '@t3foundry/tasra-sdk/app'
38
+
39
+ // manifest is a checksum-verified download from tasra-releases.
40
+ const tasra = new TasraClient({manifest, coordinator: 'lowest-operator-id'})
41
+ const status = await tasra.check()
42
+ ```
43
+
44
+ The SDK resolves the chain, contract addresses and configured service endpoints.
45
+ `await TasraClient.fromManifest(manifestUrl, {sha256, coordinator})` downloads
46
+ and verifies a release manifest from tasra-releases. The coordinator convention
47
+ must match the selected deployment. You keep deployment configuration in one place instead of constructing a
48
+ separate client for every service.
49
+
50
+ Your app chooses a trusted deployment. Manifest shape validation does not prove
51
+ its authenticity; a hosted manifest can be pinned with an independently trusted
52
+ SHA-256 digest. `check()` checks the chain and registry bytecode, not end-to-end
53
+ keeper readiness or compatibility with a particular credential wallet. Release
54
+ manifests currently also need an explicit coordinator option.
55
+
56
+ [Connect and check a deployment](application-api.md#connect-using-the-deployments-manifest).
57
+
58
+ ## Create and resume a slot
59
+
60
+ ```ts
61
+ // creator is funded; store durably saves private state and locks each operation.
62
+ const account = await tasra.slots.create({
63
+ name: 'team-account', mode: 'ecdsa', policy,
64
+ threshold: {k: 2, n: 3}, verifiers: {committee: 3, quorum: 2},
65
+ }, {wallet: creator, store})
66
+ ```
67
+
68
+ This one call saves the creation intent and salts, calculates the rule commitment,
69
+ executes commit/reveal, waits for distributed key generation, provisions the clear
70
+ rule to keepers and confirms the verifier policy. It returns a slot interface for
71
+ the selected mode:
72
+
73
+ | Mode | Resulting capability |
74
+ |---|---|
75
+ | `ecdsa` | Ethereum account and transaction signing |
76
+ | `bls` | Identity-based document encryption and authorized decryption |
77
+ | `frost` | Document signatures and native approval workflows |
78
+
79
+ You choose the access policy and thresholds, supply a funded creator and retain
80
+ the private store. The `policy` argument is the clear authorization rule; the SDK
81
+ computes its salted on-chain commitment. Advanced creation and provisioning APIs
82
+ accept that rule as `rule`.
83
+
84
+ Repeat the same call with the same name, request, creator, deployment and store
85
+ to continue its recorded progress. This avoids rebuilding a recovery state machine
86
+ in every application. It is not a guarantee of automatic recovery from every
87
+ failure: an uncertain submission without a hash needs reconciliation; expired
88
+ commitments and abandoned file locks have no automatic recovery. Preserve the
89
+ journal rather than changing the name to force another creation.
90
+
91
+ [Complete setup](application-api.md#create-a-wallet-identity-and-slot) ·
92
+ [Recovery boundaries](application-api.md#recovery-boundaries).
93
+
94
+ ## Use wallets and recorded transfers
95
+
96
+ `tasra.wallets.create()` creates a local Ethereum wallet.
97
+ `await tasra.wallets.connect(provider)` connects an external EIP-1193 wallet,
98
+ requests account access and checks its selected chain. Your app decides when to
99
+ ask for access and handles any chain switch through the wallet.
100
+
101
+ ```ts
102
+ // A stable name identifies this exact transfer in the private store.
103
+ const payment = await wallet.transfer('invoice-1042', {
104
+ to: recipient, value: 1_000_000_000_000_000n,
105
+ }, store)
106
+ console.log(payment.hash)
107
+ ```
108
+
109
+ The SDK records submission progress and waits for confirmation. Local and slot
110
+ wallets save signed bytes and their hash before broadcast. Reusing the same name
111
+ and request follows the recorded transaction; a different request under that name
112
+ is rejected. An unknown external-wallet outcome still needs reconciliation.
113
+
114
+ You persist a newly generated local wallet's exported private key before funding
115
+ it, protect that key and keep transaction records. The SDK does not automatically
116
+ fund accounts or choose payment recipients. A browser or database app supplies a
117
+ durable `ApplicationStore`; Node applications can use `createFileStore` from
118
+ `@t3foundry/tasra-sdk/app/node`.
119
+
120
+ [Wallet setup and persistence](application-api.md#create-a-wallet-identity-and-slot) ·
121
+ [Shared account tutorial](shared-account.md).
122
+
123
+ ## Create identities and credentials
124
+
125
+ ```ts
126
+ const issuer = tasra.identities.create()
127
+ const alice = tasra.identities.create()
128
+ const credential = tasra.credentials.issue({
129
+ issuer, holder: alice, type: 'urn:my-app:member', claims: {role: 'editor'},
130
+ })
131
+ const policy = tasra.credentials.policy({
132
+ issuer, type: 'urn:my-app:member', claims: {role: ['editor']},
133
+ })
134
+ ```
135
+
136
+ The SDK generates a `did:jwk` identity and key, issues a holder-bound SD-JWT
137
+ credential and builds a validated policy pinned to the chosen issuer. The
138
+ `credentials.verify()` helper checks supported signatures, lifetime and supplied
139
+ issuer, holder, credential type and subject pins. You do not need a separate application dependency
140
+ for these supported identity and credential operations.
141
+
142
+ Your app decides who may issue credentials and what membership means. Save keys
143
+ that must survive a restart and protect credentials. Local verification does not
144
+ establish issuer trust, check revocation or resolve `did:web` issuers. The built-in
145
+ helpers cover SD-JWT and supported key/DID formats; they are not a universal
146
+ credential-format converter.
147
+
148
+ [Issue credentials and authorize a user](application-api.md#issue-credentials-and-authorize-a-user).
149
+
150
+ ## Authorize an exact operation
151
+
152
+ ```ts
153
+ const authorize = tasra.credentials.authorize({
154
+ verifierAgentUrl: tasra.verifierAgentUrl!, signer: creator.signer,
155
+ identity: alice, credentials: [credential],
156
+ approve: request => showConsent(request), // Your application presents the action.
157
+ })
158
+ ```
159
+
160
+ Pass `authorize` to a slot's signing or decryption call. For each invocation the
161
+ SDK can ask for consent, opens an operation-specific verifier session, presents
162
+ the selected credential and collects authorization proofs. The protected slot
163
+ operation checks holder binding, expiry and the exact request before contacting
164
+ keepers. This replaces session, presentation and polling code in your app.
165
+
166
+ Passing credentials without an `approve` callback permits their presentation for
167
+ each requested operation. Your application owns the consent UI and selects a
168
+ trusted verifier. To present credentials to an existing request directly, use
169
+ `tasra.credentials.present(requestUri, identity, credentials, options)`.
170
+
171
+ For an **external credential wallet**, use
172
+ `registeredWalletAuthorization({client, signer, present})`. The `present` callback
173
+ displays the session's QR/deep link or runs your wallet integration; the SDK keeps
174
+ the selected registered agent and waits for that session's result. This is
175
+ separate from connecting an Ethereum wallet with `wallets.connect`.
176
+
177
+ External wallets and issuers must match the verifier's supported formats,
178
+ algorithms, trust configuration and holder-binding requirements. Compatibility
179
+ with every third-party implementation has not been established.
180
+
181
+ [Operation authorization and external wallets](application-api.md#authorize-each-exact-operation).
182
+
183
+ ## Use a shared Ethereum account
184
+
185
+ ```ts
186
+ const sharedWallet = await tasra.wallets.fromSlot(account.slotId, {authorize})
187
+ console.log(sharedWallet.address)
188
+ await sharedWallet.transfer('team-payment-1', {to: recipient, value: 1n}, store)
189
+ ```
190
+
191
+ An ECDSA slot becomes a wallet backed by threshold signing. The SDK adapts message,
192
+ typed-data and transaction signing, asks for fresh authorization on each signature
193
+ and checks that the result matches the anchored Ethereum account. Different
194
+ eligible users supply their own authorizers to use the same slot.
195
+
196
+ Your app defines who is eligible, [funds the slot's TASRA usage balance](funding.md),
197
+ and sends AVAX to the slot's Ethereum address for payments and gas. A policy allowing Alice or Bob to act does not require both to
198
+ approve. Reading the address needs no credential presentation.
199
+
200
+ [Build the shared account app](shared-account.md) ·
201
+ [Integrate an Ethereum library](application-api.md#use-your-normal-ethereum-library).
202
+
203
+ ## Encrypt and decrypt documents
204
+
205
+ ```ts
206
+ const documents = await tasra.slots.bls(slotId)
207
+ const ciphertext = await documents.encrypt(documentIdentity, documentBytes)
208
+ const {plaintext} = await documents.decrypt(documentIdentity, ciphertext, {authorize})
209
+ ```
210
+
211
+ Encryption uses the slot's anchored public key. Decryption obtains authorization,
212
+ collects threshold extraction shares, combines and checks the identity key, and
213
+ decrypts the bytes. The SDK clears temporary extraction material. You work with
214
+ file bytes rather than implementing distributed key extraction.
215
+
216
+ Your app stores the ciphertext and its identity, pins the issuer and requires a
217
+ credential scope matching that identity. Use a fresh identity for each immutable
218
+ document version. An explicitly extracted identity key remains a decryption
219
+ capability after an authorization token expires; token expiry cannot revoke an
220
+ already obtained key or plaintext. The current application flow does not provide
221
+ native multi-person approval for decryption.
222
+
223
+ [Build the encrypted notes app](encrypted-notes.md) ·
224
+ [Extraction and trust boundaries](application-api.md#encrypt-a-note).
225
+
226
+ ## Sign a document
227
+
228
+ ```ts
229
+ const documents = await tasra.slots.frost(slotId)
230
+ const signed = await documents.sign(documentManifestBytes, {authorize})
231
+ ```
232
+
233
+ The SDK obtains authorization, coordinates threshold signing and verifies the
234
+ returned signature against the exact message, slot, epoch and anchored key.
235
+ Optional keeper receipts can be required with `requireReceipt: true`.
236
+
237
+ Your app defines the immutable bytes to sign, including a document digest and
238
+ workflow version, and stores the document and signature. A cryptographic signature
239
+ does not supply your application's review UI or establish legal-signature status.
240
+ Two detached signatures from two signer-specific slots and one signature requiring
241
+ a native approval quorum are different workflows.
242
+
243
+ [Build the document signing app](document-signing.md).
244
+
245
+ ## Collect multiple approvals
246
+
247
+ Use `setApprovalPolicy(tasra, slotId, policy, {wallet, store})` to configure a FROST
248
+ slot with explicit approver keys or a credential policy and an approval quorum.
249
+ The helper records the policy transaction and checks the resulting on-chain policy.
250
+
251
+ Then `slot.approvals(...)` opens the approval client. Create a request for the exact
252
+ message, collect each person's `request.approve(...)`, and call `request.wait()`
253
+ for the verified final signature. `identityApprover(identity)` adapts an SDK
254
+ identity; `approveWithCredential(...)` presents a credential for the exact request
255
+ and signs its canonical approval payload.
256
+
257
+ This saves your app from implementing approval payloads, protocol polling and
258
+ final signature verification. Your app still provides the approval UI, pins the
259
+ expected policy and saves the original request ID, coordinator and message for
260
+ resume. A lost request ID after an ambiguous creation cannot currently be
261
+ automatically discovered. The approval quorum counts distinct approvers; the
262
+ keeper threshold counts cryptographic shares. Neither substitutes for the other.
263
+
264
+ [Complete static-key and credential approval examples](native-approvals.md).
265
+
266
+ ## Integrate OAuth authorization
267
+
268
+ Create a slot with `authType: 'oauth'` and an OAuth policy using the
269
+ `oauth+access-token+dpop` query format. The creation flow validates the authorization
270
+ family, commits the rule and provisions the slot, just as for credential policies.
271
+
272
+ When a claim test is more than a value list (a role in a nested array, an organization
273
+ plus an authentication method, a helper rule), write the policy in Rego instead.
274
+ `packEnvelope(policy, tokens)` produces a `kk_oauth` policy envelope that is committed and
275
+ provisioned like any rule; `createSlot` and `createSlotCommitReveal` from
276
+ `@t3foundry/tasra-sdk/chain` also take `oauthPolicy: {policy, tokens}` directly and require
277
+ `authType: 'oauth'`. `lintEnvelope` reports whether keepers would store it, and
278
+ `evaluateEnvelope` previews a decision over a token's claims with the network's own
279
+ engine. A refused holder sees only `kk_oauth policy refused`; the policy itself is
280
+ confidential to the network operators.
281
+
282
+ IdP sign-in is still an application integration. Obtain the IdP token and its bound
283
+ DPoP signer, then use `createOauthSession`, `submitOauthResponse` and
284
+ `waitForSession` from `@t3foundry/tasra-sdk/verifier-agent` inside an `OperationAuthorizer`.
285
+ `credentials.authorize()` handles SD-JWT/OID4VP presentations; it does not acquire
286
+ or present OAuth tokens. Choose the trusted issuer, audience and token age in your
287
+ policy and keep token handling private.
288
+
289
+ [Credential and OAuth configuration](application-api.md#choose-credential-or-oauth-authorization).