@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
package/SECURITY.md ADDED
@@ -0,0 +1,115 @@
1
+ # Security policy
2
+
3
+ `@t3foundry/tasra-sdk` is the client half of a threshold key-management protocol. It handles
4
+ private key material, assembles master secret keys in process memory, and decides
5
+ whether a credential satisfies an access rule. Bugs here can expose keys or grant
6
+ access that policy should have refused. We take reports seriously and we will not
7
+ argue about severity before fixing something real.
8
+
9
+ ## Reporting a vulnerability
10
+
11
+ **Do not open a public issue for a security problem.**
12
+
13
+ Report privately through
14
+ [GitHub Security Advisories](https://github.com/t3foundry/tasra-sdk/security/advisories/new),
15
+ which lets us collaborate on a fix in a private fork before anything is disclosed.
16
+ This requires no special access — any GitHub user can file one, and only the
17
+ maintainers can read it.
18
+
19
+ Private disclosure is also enabled on the repository, so the **Report a
20
+ vulnerability** button on the Security tab reaches the same place.
21
+
22
+ If you cannot or would rather not use GitHub, email **waldemar@managination.com**
23
+ with `@t3foundry/tasra-sdk` in the subject. Encrypted mail is welcome; say so in the
24
+ first message and we will arrange keys.
25
+
26
+ Please include, as far as you have it:
27
+
28
+ - the version (`npm ls @t3foundry/tasra-sdk`) and Node or browser runtime;
29
+ - what an attacker gains — key material, unauthorized decryption, policy bypass,
30
+ signature forgery, denial of service;
31
+ - the smallest reproduction you can manage, ideally a failing script against a
32
+ network selected from a verified tasra-releases manifest;
33
+ - whether you have told anyone else.
34
+
35
+ ### What to expect
36
+
37
+ | | |
38
+ |---|---|
39
+ | First response | within 3 business days |
40
+ | Triage and initial assessment | within 10 business days |
41
+ | Fix or mitigation plan communicated | within 30 days of triage |
42
+ | Coordinated disclosure | by agreement, default 90 days from report |
43
+
44
+ We will credit you in the advisory and the changelog unless you ask us not to.
45
+ We do not currently run a paid bounty.
46
+
47
+ ## Scope
48
+
49
+ **In scope** — anything shipped from this repository:
50
+
51
+ - the envelope format and its crypto (`encryptEnvelope`, `decryptWithMasterKey`);
52
+ - shard fetch and master-key assembly, including zeroization on `close`;
53
+ - DCQL validation and evaluation — in particular a subject being granted access it
54
+ should not have, or a rule that validates here but is refused by the network's own
55
+ evaluator (a conformance divergence is a security bug, not a nit);
56
+ - credential, JWT and holder-proof handling, including replay and binding;
57
+ - committee token assembly and verification, and verifier-set inclusion proofs;
58
+ - threshold signing and decryption paths;
59
+ - the chain write client — anything that could sign a transaction for the wrong
60
+ chain, the wrong contract, or with the wrong arguments;
61
+ - dependency vulnerabilities that are actually reachable from this package's code.
62
+
63
+ **Out of scope here** — report these to the network, not the SDK:
64
+
65
+ - keeper node, verifier, verifier-agent or issuer implementations;
66
+ - contract vulnerabilities;
67
+ - the operational security of any particular deployment.
68
+
69
+ If you are not sure which side a bug is on, report it here and we will route it.
70
+
71
+ ## Known non-issues
72
+
73
+ Things that look alarming, are already known, and do not need reporting:
74
+
75
+ - **`test/fixtures/service-test-key.pem` is a committed private key.** It is a
76
+ self-signed `CN=localhost` key, generated once for this repository, never used by any
77
+ deployment, and it grants access to nothing. It exists so the hermetic suite can
78
+ stand up real HTTPS servers — `test/specs/chain.service-transport.test.ts` exercises
79
+ TLS pinning and the `isPublicServiceAddress` SSRF guard against an actual socket,
80
+ which a mock cannot do honestly. `test/` is excluded from the published package, so it
81
+ reaches nobody who installs `@t3foundry/tasra-sdk`. Secret scanners flag it; that is expected.
82
+
83
+ ## Supported versions
84
+
85
+ Pre-1.0, only the latest published minor receives security fixes. After 1.0 this
86
+ table will state a support window per major.
87
+
88
+ | Version | Supported |
89
+ |---|---|
90
+ | 0.1.x | ✅ |
91
+
92
+ ## Cryptographic posture
93
+
94
+ Worth knowing before you file:
95
+
96
+ - Primitives come from [`@noble`](https://github.com/paulmillr/noble-curves)
97
+ (`curves`, `ciphers`, `hashes`). We do not implement primitives ourselves; we
98
+ implement protocol on top of them. A flaw in a primitive belongs upstream, though
99
+ we still want to hear about it.
100
+ - The SDK persists nothing — no localStorage, no key files. Key material lives in
101
+ process memory and is zeroized on `Session.close()`. **If your application writes
102
+ an assembled key to disk, that is your boundary, not ours.**
103
+ - `decryptWithMasterKey` requires an assembled master key, which means the local
104
+ decrypt model: `k`-of-`n` nodes revealed their shards to you. If your threat model
105
+ cannot tolerate reconstruction, use the threshold path — `decryptCustody`,
106
+ `decryptWithShardDelivery`, `combineDecryptShares` — which never assembles it.
107
+ - Conformance with the network's own implementation is checked against **vendored**
108
+ known-answer vectors, computed by that implementation. Nothing here detects a change
109
+ made on its side, so a divergence can exist without a test going red until the
110
+ vectors are refreshed. A divergence in DCQL evaluation, IBE, or committee-token
111
+ hashing is a protocol disagreement and we treat it as a security issue — report one
112
+ even if the suites are green.
113
+
114
+ This package has **not** had an independent third-party cryptographic audit. Weigh
115
+ that before putting it in front of real user secrets.
@@ -0,0 +1,50 @@
1
+ import { type Hex } from 'viem';
2
+ import { type DualSignApprover, type DualSignRequest } from '../committee/dual-sign.js';
3
+ import type { TasraApplication, OperationAuthorizer } from './client.js';
4
+ import type { TasraIdentity } from './identity.js';
5
+ import type { ApplicationStore } from './ready-slot.js';
6
+ import type { TasraWallet } from './wallet.js';
7
+ /**
8
+ * Required approval count and either trusted Ed25519 keys or a credential rule.
9
+ */
10
+ export interface ApprovalPolicy {
11
+ /**
12
+ * Minimum distinct approvals required to complete a signing request.
13
+ */
14
+ quorum: number;
15
+ /** Static Ed25519 approver keys. Use either this list or a credential policy. */
16
+ approvers?: readonly Uint8Array[];
17
+ /** Exact raw DCQL rule whose unsalted hash the network must enforce. */
18
+ credentialPolicy?: string;
19
+ }
20
+ /**
21
+ * Install an explicit native FROST approval policy using a durable named transaction.
22
+ * @param app Application client for the slot deployment.
23
+ * @param slotId FROST slot whose approval policy is being installed.
24
+ * @param input Required quorum and either approver keys or a credential rule.
25
+ * @param options Creator wallet and durable store for the named policy transaction.
26
+ */
27
+ export declare function setApprovalPolicy(app: Pick<TasraApplication, 'deployment' | 'chain' | 'slots'>, slotId: Hex, input: ApprovalPolicy, options: {
28
+ wallet: TasraWallet;
29
+ store: ApplicationStore;
30
+ name?: string;
31
+ }): Promise<import("./wallet.js").WalletTransactionJournal>;
32
+ /**
33
+ * Adapt an SDK Ed25519 identity to native approval signatures without exporting its key.
34
+ * @param identity Live Ed25519 identity used to sign approval payloads.
35
+ * @returns Approver adapter exposing the public key and signing callback.
36
+ */
37
+ export declare function identityApprover(identity: TasraIdentity): DualSignApprover;
38
+ /**
39
+ * Present a credential for this exact request, then sign its canonical approval payload.
40
+ * @param app Application client for the request deployment.
41
+ * @param request Native signing request awaiting an approval.
42
+ * @param message Exact document bytes identified by the request.
43
+ * @param options Approver identity, credential authorizer and cancellation controls.
44
+ */
45
+ export declare function approveWithCredential(app: Pick<TasraApplication, 'deployment' | 'slots'>, request: DualSignRequest, message: Uint8Array, options: {
46
+ identity: TasraIdentity;
47
+ authorize: OperationAuthorizer;
48
+ signal?: AbortSignal;
49
+ description?: string;
50
+ }): Promise<import("../committee/dual-sign.js").DualSignStatus>;
@@ -0,0 +1,90 @@
1
+ import { ed25519 } from '@noble/curves/ed25519';
2
+ import { equalBytes } from '@noble/curves/utils.js';
3
+ import { sha256 } from '@noble/hashes/sha256';
4
+ import { encodeFunctionData, keccak256, toHex } from 'viem';
5
+ import { validate } from '../auth/oid4vp.js';
6
+ import { keyRegistryAbi } from '../chain/abis/index.js';
7
+ import { dualSignApprovalPayload } from '../committee/dual-sign.js';
8
+ import { protocolHex } from '../committee/receipts.js';
9
+ import { b64urlDecode } from '../oid4vp/jose.js';
10
+ /**
11
+ * Install an explicit native FROST approval policy using a durable named transaction.
12
+ * @param app Application client for the slot deployment.
13
+ * @param slotId FROST slot whose approval policy is being installed.
14
+ * @param input Required quorum and either approver keys or a credential rule.
15
+ * @param options Creator wallet and durable store for the named policy transaction.
16
+ */
17
+ export async function setApprovalPolicy(app, slotId, input, options) {
18
+ protocolHex(slotId, 32, 'slot id');
19
+ const { quorum, credentialPolicy } = input, approvers = input.approvers?.map(key => key.slice());
20
+ const { wallet, store } = options, name = options.name ?? `approval-${slotId.slice(2)}`;
21
+ if (!Number.isSafeInteger(quorum) || quorum < 1 || quorum > 65535)
22
+ throw new Error('Invalid approval quorum');
23
+ if ((approvers !== undefined) === (credentialPolicy !== undefined))
24
+ throw new Error('Choose static approvers or a credential policy');
25
+ if (approvers && (quorum > approvers.length || approvers.some(key => key.length !== 32) || new Set(approvers.map(key => toHex(key))).size !== approvers.length))
26
+ throw new Error('Approval keys must be distinct and satisfy the quorum');
27
+ for (const key of approvers ?? []) {
28
+ const point = ed25519.Point.fromHex(key, false);
29
+ if (point.isSmallOrder() || !point.isTorsionFree())
30
+ throw new Error('Approval keys must be prime-order Ed25519 points');
31
+ }
32
+ if (credentialPolicy !== undefined)
33
+ validate(credentialPolicy);
34
+ const ruleHash = credentialPolicy === undefined ? `0x${'00'.repeat(32)}` : keccak256(toHex(credentialPolicy));
35
+ const data = encodeFunctionData({ abi: keyRegistryAbi, functionName: 'setDualControlPolicy', args: [slotId, quorum, ruleHash, (approvers ?? []).map(key => toHex(key))] });
36
+ await app.slots.frost(slotId);
37
+ if (wallet.wallet.chain.id !== app.deployment.chainId)
38
+ throw new Error('Approval wallet uses a different chain');
39
+ const transaction = await wallet.transfer(name, { to: app.deployment.addresses.KeyRegistry, data }, store);
40
+ const [observed, observedKeys] = await Promise.all([
41
+ app.chain.client.readContract({ address: app.deployment.addresses.KeyRegistry, abi: keyRegistryAbi, functionName: 'dualControlPolicy', args: [slotId] }),
42
+ app.chain.client.readContract({ address: app.deployment.addresses.KeyRegistry, abi: keyRegistryAbi, functionName: 'dualControlApprovers', args: [slotId] }),
43
+ ]);
44
+ if (observed[0] !== quorum || observed[1].toLowerCase() !== ruleHash.toLowerCase())
45
+ throw new Error('On-chain approval policy differs from the requested policy');
46
+ const expectedKeys = (approvers ?? []).map(key => toHex(key)).sort();
47
+ const actualKeys = observedKeys.map(key => key.toLowerCase()).sort();
48
+ if (expectedKeys.length !== actualKeys.length || expectedKeys.some((key, i) => key !== actualKeys[i]))
49
+ throw new Error('On-chain approval keys differ from the requested policy');
50
+ return transaction;
51
+ }
52
+ /**
53
+ * Adapt an SDK Ed25519 identity to native approval signatures without exporting its key.
54
+ * @param identity Live Ed25519 identity used to sign approval payloads.
55
+ * @returns Approver adapter exposing the public key and signing callback.
56
+ */
57
+ export function identityApprover(identity) {
58
+ if (identity.algorithm !== 'Ed25519')
59
+ throw new Error('Native approval requires an Ed25519 identity');
60
+ const publicKey = b64urlDecode(identity.holder.publicJwk.x);
61
+ return { publicKey: publicKey.slice(), async sign(payload) {
62
+ const secret = identity.exportPrivateKey();
63
+ try {
64
+ if (!equalBytes(ed25519.getPublicKey(secret), publicKey))
65
+ throw new Error('Approval identity key changed');
66
+ return ed25519.sign(payload, secret);
67
+ }
68
+ finally {
69
+ secret.fill(0);
70
+ }
71
+ } };
72
+ }
73
+ /**
74
+ * Present a credential for this exact request, then sign its canonical approval payload.
75
+ * @param app Application client for the request deployment.
76
+ * @param request Native signing request awaiting an approval.
77
+ * @param message Exact document bytes identified by the request.
78
+ * @param options Approver identity, credential authorizer and cancellation controls.
79
+ */
80
+ export async function approveWithCredential(app, request, message, options) {
81
+ const { identity, authorize, signal, description } = options;
82
+ const slotId = request.slotId, canonical = dualSignApprovalPayload(slotId, message.slice(), request.requestId);
83
+ const signer = identityApprover(identity);
84
+ signal?.throwIfAborted();
85
+ await app.slots.frost(slotId);
86
+ const authorization = await authorize({ chainId: app.deployment.chainId, keyRegistry: app.deployment.addresses.KeyRegistry,
87
+ slotId, action: 'dual-approve', payloadDigest: sha256(canonical), description: description ?? 'Approve exact document request', signal });
88
+ signal?.throwIfAborted();
89
+ return request.approve({ signer, authorization, signal });
90
+ }
@@ -0,0 +1,19 @@
1
+ import { type RegisteredVerifierAgentSession } from '../chain/registeredOperation.js';
2
+ import { createRegisteredAgentClient } from '../chain/registeredAgent.js';
3
+ import type { TypedDataSigner } from '../oid4vp/verifier-agent.js';
4
+ import type { PresentationDelegation, SessionPhase } from '../verifier-agent/index.js';
5
+ import type { OperationAuthorizer } from './client.js';
6
+ /**
7
+ * Request-bound authorization through an independently approved registered agent.
8
+ * `present` displays a QR/deep link or runs the application's credential wallet.
9
+ * It never changes the selected provider or transfers a presentation to a fallback.
10
+ * @param config Approved agent client, operation signer, wallet presentation callback and polling controls.
11
+ */
12
+ export declare function registeredWalletAuthorization(config: {
13
+ client: ReturnType<typeof createRegisteredAgentClient>;
14
+ signer: TypedDataSigner;
15
+ delegation?: PresentationDelegation;
16
+ present: (session: RegisteredVerifierAgentSession, signal?: AbortSignal) => Promise<void>;
17
+ onPhase?: (phase: SessionPhase) => void;
18
+ timeoutMs?: number;
19
+ }): OperationAuthorizer;
@@ -0,0 +1,20 @@
1
+ import { openRegisteredVerifierAgentSession, awaitRegisteredVerifierAgentResult } from '../chain/registeredOperation.js';
2
+ /**
3
+ * Request-bound authorization through an independently approved registered agent.
4
+ * `present` displays a QR/deep link or runs the application's credential wallet.
5
+ * It never changes the selected provider or transfers a presentation to a fallback.
6
+ * @param config Approved agent client, operation signer, wallet presentation callback and polling controls.
7
+ */
8
+ export function registeredWalletAuthorization(config) {
9
+ const { client, signer, delegation, present, onPhase, timeoutMs } = config;
10
+ return async (request) => {
11
+ const session = await openRegisteredVerifierAgentSession(client, { ...request, signer, delegation });
12
+ request.signal?.throwIfAborted();
13
+ await present(session, request.signal);
14
+ request.signal?.throwIfAborted();
15
+ const result = await awaitRegisteredVerifierAgentResult(session, { signal: request.signal, onPhase, timeoutMs });
16
+ if (!result.verifierProofs?.length)
17
+ throw new Error('Authorization did not include verifier membership proofs');
18
+ return { token: result.token, verifierProofs: result.verifierProofs };
19
+ };
20
+ }
@@ -0,0 +1,231 @@
1
+ import { type Hex } from 'viem';
2
+ import { type TasraChainClient } from '../chain/client.js';
3
+ import { type EoaSignature } from '../signing/ecdsa.js';
4
+ import { type Ciphertext } from '../crypto/envelope.js';
5
+ import { TasraError } from '../errors.js';
6
+ import { type VerifierProof } from '../committee/client.js';
7
+ import { type CompoundTokenWire } from '../committee/token.js';
8
+ import type { OperationInput } from '../oid4vp/verifier-agent.js';
9
+ import { type TasraDeployment } from './deployment.js';
10
+ /**
11
+ * Failure categories for deployment, slot, authorization and result validation.
12
+ */
13
+ export type ApplicationErrorCode = 'CHAIN_MISMATCH' | 'SLOT_NOT_FOUND' | 'SLOT_CANCELLED' | 'WRONG_SLOT_MODE' | 'KEY_NOT_READY' | 'SLOT_CHANGED' | 'INVALID_AUTHORIZATION' | 'INVALID_RESULT';
14
+ /**
15
+ * An application operation rejected because its deployment, slot, authorization or result failed validation.
16
+ */
17
+ export declare class TasraApplicationError extends TasraError {
18
+ readonly code: ApplicationErrorCode;
19
+ constructor(/** Stable application error category used to choose recovery behavior. */ code: ApplicationErrorCode, message: string);
20
+ }
21
+ /**
22
+ * Holder-bound committee token and verifier membership proofs for one operation.
23
+ */
24
+ export interface OperationGrant {
25
+ /** Fresh compound verifier token bound to the holder and exact operation. */
26
+ token: CompoundTokenWire;
27
+ /** Membership proofs for the verifiers that authorized the operation. */
28
+ verifierProofs: VerifierProof[];
29
+ }
30
+ /**
31
+ * Immutable operation details presented to the application authorizer.
32
+ */
33
+ export type AuthorizationRequest = Readonly<OperationInput & {
34
+ /** Cancellation signal propagated to the authorization provider. */
35
+ signal?: AbortSignal;
36
+ }>;
37
+ /** Called once for the exact operation. Applications display the wallet request here. */
38
+ export type OperationAuthorizer = (request: AuthorizationRequest) => Promise<OperationGrant>;
39
+ /**
40
+ * Authorization callback, consent description and cancellation controls for a protected operation.
41
+ */
42
+ export interface AuthorizedOperationOptions {
43
+ /**
44
+ * Obtain a fresh holder-bound grant for this exact operation.
45
+ */
46
+ authorize: OperationAuthorizer;
47
+ /**
48
+ * Human-readable consent text attached to the authorization request.
49
+ */
50
+ description?: string;
51
+ /**
52
+ * Cancel pending authorization or network work.
53
+ */
54
+ signal?: AbortSignal;
55
+ /**
56
+ * Optional holder signature forwarded to the keeper operation.
57
+ */
58
+ userSignature?: Uint8Array;
59
+ }
60
+ /**
61
+ * Deployment, chain reader and transport choices used by the application client.
62
+ */
63
+ export interface TasraApplicationConfig {
64
+ /** Application-approved chain, registry and coordinator configuration. */
65
+ deployment: TasraDeployment;
66
+ /** Reuse the read client in an existing app. Its actual chain is checked before use. */
67
+ chain?: TasraChainClient;
68
+ /** Caller-approved routing, e.g. local Docker hostnames to published loopback ports. */
69
+ keeperUrl?: (registeredUrl: string) => string;
70
+ /** HTTP implementation used for keeper operation requests. */
71
+ fetchImpl?: typeof fetch;
72
+ }
73
+ /**
74
+ * Current slot mode, key epoch, threshold and anchored public key.
75
+ */
76
+ export interface SlotMetadata {
77
+ /**
78
+ * 32-byte identifier of the slot on this deployment.
79
+ */
80
+ slotId: Hex;
81
+ /**
82
+ * Registry key-mode ordinal: 0 for FROST, 1 for BLS or 2 for threshold ECDSA.
83
+ */
84
+ mode: number;
85
+ /**
86
+ * Current key epoch recorded by the registry.
87
+ */
88
+ epoch: number;
89
+ /**
90
+ * Minimum participating shares k and total assigned shares n.
91
+ */
92
+ threshold: {
93
+ k: number;
94
+ n: number;
95
+ };
96
+ /**
97
+ * Anchored group public key as hexadecimal bytes.
98
+ */
99
+ publicKey: Hex;
100
+ /**
101
+ * Whether the registry contains a nonempty group public key.
102
+ */
103
+ ready: boolean;
104
+ }
105
+ /**
106
+ * Configure one application client. Construction does no I/O and holds no wallet credentials.
107
+ * Start with `await tasra.slots.ecdsa(slotId)` and `await account.getAddress()`;
108
+ * provide an authorizer only when signing or decrypting.
109
+ * @param config Validated deployment settings and optional transport adapters.
110
+ * @returns A client with read-only checks and authorized slot operations.
111
+ */
112
+ export declare function createTasra(config: TasraApplicationConfig): {
113
+ /** Validated configuration for the selected deployment. */
114
+ deployment: Readonly<TasraDeployment>;
115
+ /** Read-only chain client bound to the selected deployment. */
116
+ chain: TasraChainClient;
117
+ /** Read-only chain and registry probe. Does not claim keeper/issuer compatibility. */
118
+ check(): Promise<{
119
+ chainId: number;
120
+ registries: {
121
+ name: "NodeRegistry" | "KeyRegistry";
122
+ deployed: boolean;
123
+ }[];
124
+ ready: boolean;
125
+ authorization: "unknown";
126
+ nativeMultiApproverIbe: "unsupported";
127
+ taskContextEnforcement: "unsupported";
128
+ }>;
129
+ /** Slot metadata reads and capability-specific signing or encryption adapters. */
130
+ slots: {
131
+ get: (slotId: Hex) => Promise<SlotMetadata>;
132
+ /**
133
+ * Open a ready threshold ECDSA slot for verified Ethereum signatures.
134
+ * @param slotId Identifier of the ECDSA slot.
135
+ */
136
+ ecdsa(slotId: Hex): Promise<{
137
+ /** Identifier of the threshold ECDSA slot. */
138
+ slotId: `0x${string}`;
139
+ /** Recheck slot readiness and derive its Ethereum address from the current public key. */
140
+ getAddress: () => Promise<`0x${string}`>;
141
+ /**
142
+ * Authorize and sign an exact 32-byte Ethereum digest, then verify the recovered account.
143
+ * @param input Exactly 32 digest bytes.
144
+ * @param options Fresh operation authorization and cancellation controls.
145
+ */
146
+ signDigest(input: Uint8Array, options: AuthorizedOperationOptions): Promise<EoaSignature>;
147
+ }>;
148
+ /**
149
+ * Open a ready FROST slot for verified Ed25519 signatures and native approvals.
150
+ * @param slotId Identifier of the FROST slot.
151
+ */
152
+ frost(slotId: Hex): Promise<{
153
+ /** Identifier of the FROST signing slot. */
154
+ slotId: `0x${string}`;
155
+ /**
156
+ * Authorize the exact message and verify the returned signature, epoch and optional receipt.
157
+ * @param input Message bytes to sign.
158
+ * @param options Fresh authorization and optional verified-receipt requirement.
159
+ */
160
+ sign(input: Uint8Array, options: AuthorizedOperationOptions & {
161
+ requireReceipt?: boolean;
162
+ }): Promise<{
163
+ receiptStatus: "absent" | "verified";
164
+ receipt?: import("../committee/receipts.js").OperationReceipt;
165
+ keySlotId: string;
166
+ groupPublicKey: Uint8Array;
167
+ signature: import("../crypto/frost.js").FrostSignature;
168
+ messageSha256: Uint8Array;
169
+ epoch: number;
170
+ }>;
171
+ /** Quorum and approval mode must come from the application's independently pinned policy. */
172
+ approvals(policy: {
173
+ quorum: number;
174
+ credentialGated: boolean;
175
+ }): Promise<{
176
+ create(message: Uint8Array, options?: {
177
+ signal?: AbortSignal;
178
+ }): Promise<import("../committee/dual-sign.js").DualSignRequest>;
179
+ resume(requestId: string, expectedMessage: Uint8Array): import("../committee/dual-sign.js").DualSignRequest;
180
+ }>;
181
+ }>;
182
+ /**
183
+ * Open a ready BLS slot for KEM key wrapping and committee-authorized unwrapping.
184
+ * @param slotId Identifier of the BLS slot.
185
+ */
186
+ bls(slotId: Hex): Promise<{
187
+ /** Identifier of the BLS key-encryption slot. */
188
+ slotId: `0x${string}`;
189
+ /**
190
+ * BLS KEM-wrap a symmetric data key. Local — no credential or network round-trip needed.
191
+ * @param aad Additional authenticated data binding the key to an application scope.
192
+ * @param dataKey 32-byte symmetric key to wrap under the slot's group public key.
193
+ */
194
+ encrypt(aad: Uint8Array, dataKey: Uint8Array): Promise<Ciphertext>;
195
+ /**
196
+ * Authorize and recover the KEM-wrapped symmetric key via committee custody decrypt.
197
+ * @param aad Original authenticated data from encryption.
198
+ * @param kemCt BLS KEM ciphertext wrapping the symmetric key.
199
+ * @param options Fresh authorization and optional verified-receipt requirement.
200
+ */
201
+ decrypt(aad: Uint8Array, kemCt: Ciphertext, options: AuthorizedOperationOptions & {
202
+ requireReceipts?: boolean;
203
+ }): Promise<{
204
+ plaintext: Uint8Array<ArrayBufferLike>;
205
+ shareTrust: "anchored-group";
206
+ evidence: {
207
+ operator: `0x${string}`;
208
+ identifier: number;
209
+ nodeUrl: string;
210
+ receiptStatus: "unverified";
211
+ }[];
212
+ }>;
213
+ }>;
214
+ };
215
+ };
216
+ /**
217
+ * Application client exposing checked slot operations and deployment readiness probes.
218
+ */
219
+ export type TasraApplication = ReturnType<typeof createTasra>;
220
+ /**
221
+ * Threshold Ethereum account handle that verifies each signature against the anchored public key.
222
+ */
223
+ export type EcdsaSlot = Awaited<ReturnType<TasraApplication['slots']['ecdsa']>>;
224
+ /**
225
+ * Threshold Ed25519 signing handle with optional receipt checks and native approval sessions.
226
+ */
227
+ export type FrostSlot = Awaited<ReturnType<TasraApplication['slots']['frost']>>;
228
+ /**
229
+ * BLS KEM handle: wraps/unwraps a symmetric key with authorized custody decryption.
230
+ */
231
+ export type BlsSlot = Awaited<ReturnType<TasraApplication['slots']['bls']>>;