@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
+ import type { Address, Hex, PublicClient } from 'viem';
2
+ import { TasraError } from '../errors.js';
3
+ import type { KeeperProvisionResult } from './provisionRule.js';
4
+ /**
5
+ * Stable refusal categories of the rule-amendment API; branch on `code`, never on the message.
6
+ * `timelock`, `below-threshold` and `timeout` may succeed later; every other code needs a change first.
7
+ */
8
+ export type RuleAmendmentErrorCode = 'no-slot' | 'immutable' | 'not-admin' | 'pending' | 'same-rule' | 'wrong-auth-type' | 'not-admissible' | 'no-pending' | 'timelock' | 'below-threshold' | 'not-guardian' | 'not-deliverer' | 'not-pending' | 'pending-changed' | 'timeout' | 'not-activated';
9
+ /** Optional detail fields carried by a {@link RuleAmendmentError}. */
10
+ export interface RuleAmendmentErrorDetails {
11
+ /** Version of the amendment already pending on chain. */
12
+ pendingVersion?: number;
13
+ /** Salted commitment of the amendment already pending on chain. */
14
+ pendingCommitment?: Hex;
15
+ /** Whether the slot has a guardian that could veto the pending amendment. */
16
+ hasGuardian?: boolean;
17
+ /** Chain time (Unix seconds) from which the pending amendment may activate. */
18
+ notBefore?: number;
19
+ /** Latest block timestamp (Unix seconds) the check was made against. */
20
+ chainTime?: number;
21
+ /** Keeper adoption votes recorded for the pending amendment. */
22
+ have?: number;
23
+ /** Keeper adoption votes activation needs. */
24
+ need?: number;
25
+ /** Per-keeper delivery outcomes, when the refusal came from rule delivery. */
26
+ results?: readonly KeeperProvisionResult[];
27
+ /** Orchestrator phase that was running when the refusal was raised. */
28
+ phase?: string;
29
+ /** Underlying failure, when there is one. */
30
+ cause?: unknown;
31
+ }
32
+ /**
33
+ * A rule-amendment call refused before signing, or an amendment that did not reach the state the
34
+ * caller asked for. Retryable only for `timelock`, `below-threshold` and `timeout`.
35
+ */
36
+ export declare class RuleAmendmentError extends TasraError {
37
+ /** Refusal category; never infer it from the message. */
38
+ readonly code: RuleAmendmentErrorCode;
39
+ /** Slot the refused call targeted. */
40
+ readonly slotId: Hex;
41
+ /** Version of the amendment already pending on chain. */
42
+ readonly pendingVersion?: number;
43
+ /** Salted commitment of the amendment already pending on chain. */
44
+ readonly pendingCommitment?: Hex;
45
+ /** Whether the slot has a guardian that could veto the pending amendment. */
46
+ readonly hasGuardian?: boolean;
47
+ /** Chain time (Unix seconds) from which the pending amendment may activate. */
48
+ readonly notBefore?: number;
49
+ /** Latest block timestamp (Unix seconds) the check was made against. */
50
+ readonly chainTime?: number;
51
+ /** Keeper adoption votes recorded for the pending amendment. */
52
+ readonly have?: number;
53
+ /** Keeper adoption votes activation needs. */
54
+ readonly need?: number;
55
+ /** Per-keeper delivery outcomes, when the refusal came from rule delivery. */
56
+ readonly results?: readonly KeeperProvisionResult[];
57
+ /** Orchestrator phase that was running when the refusal was raised. */
58
+ readonly phase?: string;
59
+ constructor(code: RuleAmendmentErrorCode, slotId: Hex, message: string, details?: RuleAmendmentErrorDetails);
60
+ }
61
+ /** A pending amendment as the chain records it. */
62
+ export interface PendingAmendmentOnChain {
63
+ /** Salted commitment of the proposed rule. */
64
+ ruleCommitment: Hex;
65
+ /** Amendment version. */
66
+ version: number;
67
+ /** Chain time (Unix seconds) from which it may activate. */
68
+ notBefore: number;
69
+ /** Keeper adoption votes so far; read only when asked for. */
70
+ adoptions?: number;
71
+ /** Keeper adoption votes activation needs; read only when asked for. */
72
+ needed?: number;
73
+ }
74
+ /** A slot's amendment-relevant on-chain state, as plain numbers and addresses. */
75
+ export interface AmendmentOnChain {
76
+ /** Slot creator. */
77
+ creator: Address;
78
+ /** Salted commitment of the ACTIVE rule. */
79
+ ruleCommitment: Hex;
80
+ /** Version of the active rule. */
81
+ ruleVersion: number;
82
+ /** `KeyRegistry.AuthType` ordinal recorded at creation. */
83
+ authOrdinal: number;
84
+ /** Rule admin; the zero address means the rule is immutable. */
85
+ admin: Address;
86
+ /** Rule guardian; the zero address means none. */
87
+ guardian: Address;
88
+ /** Amendment delay in seconds. */
89
+ timelockSecs: number;
90
+ /** The pending amendment, or null when none is pending. */
91
+ pending: PendingAmendmentOnChain | null;
92
+ }
93
+ /** The zero address the contract uses for "no admin" / "no guardian". */
94
+ export declare const AMENDMENT_ZERO_ADDRESS: Address;
95
+ /**
96
+ * Case-insensitive address equality.
97
+ * @param a First address.
98
+ * @param b Second address.
99
+ */
100
+ export declare function sameAddress(a: string, b: string): boolean;
101
+ /**
102
+ * Read a slot's amendment state: the slot, its rule policy and its pending amendment, in parallel.
103
+ * Refuses `no-slot` for a missing or cancelled slot before reading anything else, because a missing
104
+ * slot reads an all-zero policy that would otherwise report a misleading `immutable`.
105
+ * @param read A `readContract` function, from a viem public client.
106
+ * @param keyRegistry KeyRegistry address of the deployment.
107
+ * @param slotId Slot to read.
108
+ * @param opts `withVotes` also reads the adoption votes and threshold when an amendment is pending.
109
+ */
110
+ export declare function readAmendmentOnChain(read: PublicClient['readContract'], keyRegistry: Address, slotId: Hex, opts?: {
111
+ withVotes?: boolean;
112
+ }): Promise<AmendmentOnChain>;
113
+ /**
114
+ * The `immutable` refusal: a slot created without a rule policy.
115
+ * @param slotId Slot whose rule cannot change.
116
+ */
117
+ export declare function immutableError(slotId: Hex): RuleAmendmentError;
118
+ /**
119
+ * The `pending` refusal: another amendment is already pending, naming its version and whether a guardian can clear it.
120
+ * @param slotId Slot with a pending amendment.
121
+ * @param state The slot's amendment state; `pending` must be set.
122
+ */
123
+ export declare function pendingError(slotId: Hex, state: AmendmentOnChain): RuleAmendmentError;
124
+ /**
125
+ * Wait `ms` milliseconds, rejecting with the signal's reason as soon as it aborts.
126
+ * @param ms Milliseconds to wait.
127
+ * @param signal Optional cancellation signal.
128
+ */
129
+ export declare function abortableDelay(ms: number, signal?: AbortSignal): Promise<void>;
@@ -0,0 +1,152 @@
1
+ // Shared pieces of the rule-amendment path: the typed refusal every amendment call throws, and the
2
+ // one on-chain read the writes, the status read and the orchestrator all judge from.
3
+ //
4
+ // A separate module so `write.ts` (the four writes) and `ruleAmendment.ts` (status read +
5
+ // orchestrator) both import it without a value cycle between them.
6
+ //
7
+ // Every refusal here is raised BEFORE anything is signed. A proposal no keeper will store never
8
+ // activates, and `proposeRuleUpdate` refuses while one is pending - so on a slot without a guardian
9
+ // a bad proposal freezes the rule for good. Failing in the SDK costs nothing; failing on chain can
10
+ // cost the slot its amendability.
11
+ import { TasraError } from '../errors.js';
12
+ import { keyRegistryAbi } from './abis/keyRegistry.js';
13
+ /** Codes a later identical attempt may clear without any change by the caller. */
14
+ const RETRYABLE_CODES = new Set(['timelock', 'below-threshold', 'timeout']);
15
+ /**
16
+ * A rule-amendment call refused before signing, or an amendment that did not reach the state the
17
+ * caller asked for. Retryable only for `timelock`, `below-threshold` and `timeout`.
18
+ */
19
+ export class RuleAmendmentError extends TasraError {
20
+ /** Refusal category; never infer it from the message. */
21
+ code;
22
+ /** Slot the refused call targeted. */
23
+ slotId;
24
+ /** Version of the amendment already pending on chain. */
25
+ pendingVersion;
26
+ /** Salted commitment of the amendment already pending on chain. */
27
+ pendingCommitment;
28
+ /** Whether the slot has a guardian that could veto the pending amendment. */
29
+ hasGuardian;
30
+ /** Chain time (Unix seconds) from which the pending amendment may activate. */
31
+ notBefore;
32
+ /** Latest block timestamp (Unix seconds) the check was made against. */
33
+ chainTime;
34
+ /** Keeper adoption votes recorded for the pending amendment. */
35
+ have;
36
+ /** Keeper adoption votes activation needs. */
37
+ need;
38
+ /** Per-keeper delivery outcomes, when the refusal came from rule delivery. */
39
+ results;
40
+ /** Orchestrator phase that was running when the refusal was raised. */
41
+ phase;
42
+ constructor(code, slotId, message, details = {}) {
43
+ super(message, { cause: details.cause, retryable: RETRYABLE_CODES.has(code) });
44
+ this.code = code;
45
+ this.slotId = slotId;
46
+ this.pendingVersion = details.pendingVersion;
47
+ this.pendingCommitment = details.pendingCommitment;
48
+ this.hasGuardian = details.hasGuardian;
49
+ this.notBefore = details.notBefore;
50
+ this.chainTime = details.chainTime;
51
+ this.have = details.have;
52
+ this.need = details.need;
53
+ this.results = details.results;
54
+ this.phase = details.phase;
55
+ }
56
+ }
57
+ /** The zero address the contract uses for "no admin" / "no guardian". */
58
+ export const AMENDMENT_ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
59
+ /**
60
+ * Case-insensitive address equality.
61
+ * @param a First address.
62
+ * @param b Second address.
63
+ */
64
+ export function sameAddress(a, b) {
65
+ return a.toLowerCase() === b.toLowerCase();
66
+ }
67
+ /**
68
+ * Read a slot's amendment state: the slot, its rule policy and its pending amendment, in parallel.
69
+ * Refuses `no-slot` for a missing or cancelled slot before reading anything else, because a missing
70
+ * slot reads an all-zero policy that would otherwise report a misleading `immutable`.
71
+ * @param read A `readContract` function, from a viem public client.
72
+ * @param keyRegistry KeyRegistry address of the deployment.
73
+ * @param slotId Slot to read.
74
+ * @param opts `withVotes` also reads the adoption votes and threshold when an amendment is pending.
75
+ */
76
+ export async function readAmendmentOnChain(read, keyRegistry, slotId, opts = {}) {
77
+ const [slot, policy, pending] = await Promise.all([
78
+ read({ address: keyRegistry, abi: keyRegistryAbi, functionName: 'getKeySlot', args: [slotId] }),
79
+ read({ address: keyRegistry, abi: keyRegistryAbi, functionName: 'rulePolicy', args: [slotId] }),
80
+ read({ address: keyRegistry, abi: keyRegistryAbi, functionName: 'pendingRule', args: [slotId] }),
81
+ ]);
82
+ if (!slot.exists || slot.cancelled) {
83
+ throw new RuleAmendmentError('no-slot', slotId, `slot ${slotId} does not exist or is cancelled on this KeyRegistry; check the slot id and the network`);
84
+ }
85
+ const [pendingCommitment, pendingVersion, notBefore] = pending;
86
+ let pend = null;
87
+ if (BigInt(pendingVersion) !== 0n) {
88
+ pend = { ruleCommitment: pendingCommitment, version: Number(pendingVersion), notBefore: Number(notBefore) };
89
+ if (opts.withVotes) {
90
+ const [adoptions, needed] = await Promise.all([
91
+ read({ address: keyRegistry, abi: keyRegistryAbi, functionName: 'ruleAdoptionVotes', args: [slotId] }),
92
+ read({ address: keyRegistry, abi: keyRegistryAbi, functionName: 'ruleAdoptionThreshold', args: [slotId] }),
93
+ ]);
94
+ pend.adoptions = Number(adoptions);
95
+ pend.needed = Number(needed);
96
+ }
97
+ }
98
+ const [admin, guardian, timelock] = policy;
99
+ return {
100
+ creator: slot.creator,
101
+ ruleCommitment: slot.ruleCommitment,
102
+ ruleVersion: Number(slot.ruleVersion),
103
+ authOrdinal: Number(slot.auth),
104
+ admin,
105
+ guardian,
106
+ timelockSecs: Number(timelock),
107
+ pending: pend,
108
+ };
109
+ }
110
+ /**
111
+ * The `immutable` refusal: a slot created without a rule policy.
112
+ * @param slotId Slot whose rule cannot change.
113
+ */
114
+ export function immutableError(slotId) {
115
+ return new RuleAmendmentError('immutable', slotId, `slot ${slotId} was created without a rulePolicy; its rule can never change; create a new slot with a rulePolicy instead`);
116
+ }
117
+ /**
118
+ * The `pending` refusal: another amendment is already pending, naming its version and whether a guardian can clear it.
119
+ * @param slotId Slot with a pending amendment.
120
+ * @param state The slot's amendment state; `pending` must be set.
121
+ */
122
+ export function pendingError(slotId, state) {
123
+ const p = state.pending;
124
+ const hasGuardian = !sameAddress(state.guardian, AMENDMENT_ZERO_ADDRESS);
125
+ const remedy = hasGuardian
126
+ ? `the guardian ${state.guardian} can veto it with vetoRuleUpdate, or it can be delivered and activated`
127
+ : 'the slot has no guardian, so nobody can veto it: it must be delivered to the keepers and activated';
128
+ return new RuleAmendmentError('pending', slotId, `slot ${slotId} already has amendment version ${p.version} pending (commitment ${p.ruleCommitment}); ` +
129
+ `a new proposal is refused until it is activated or vetoed - ${remedy}`, { pendingVersion: p.version, pendingCommitment: p.ruleCommitment, hasGuardian });
130
+ }
131
+ /**
132
+ * Wait `ms` milliseconds, rejecting with the signal's reason as soon as it aborts.
133
+ * @param ms Milliseconds to wait.
134
+ * @param signal Optional cancellation signal.
135
+ */
136
+ export function abortableDelay(ms, signal) {
137
+ return new Promise((resolve, reject) => {
138
+ if (signal?.aborted) {
139
+ reject(signal.reason);
140
+ return;
141
+ }
142
+ const onAbort = () => {
143
+ clearTimeout(timer);
144
+ reject(signal?.reason);
145
+ };
146
+ const timer = setTimeout(() => {
147
+ signal?.removeEventListener('abort', onAbort);
148
+ resolve();
149
+ }, ms);
150
+ signal?.addEventListener('abort', onAbort, { once: true });
151
+ });
152
+ }
@@ -0,0 +1,10 @@
1
+ /** Clear authorization policy, not its salted on-chain commitment. */
2
+ export interface RuleInput {
3
+ /** Clear rule. OAuth and wallet policies share the DCQL grammar. */
4
+ rule: string;
5
+ }
6
+ /**
7
+ * Require the current input contract before I/O; old fields are not aliases.
8
+ * @param input Rule-bearing input to validate.
9
+ */
10
+ export declare function requireRule(input: RuleInput): string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Require the current input contract before I/O; old fields are not aliases.
3
+ * @param input Rule-bearing input to validate.
4
+ */
5
+ export function requireRule(input) {
6
+ if ('dcqlRule' in input) {
7
+ throw new Error('dcqlRule is not supported; use rule. Saved intents require explicit migration.');
8
+ }
9
+ const { rule } = input;
10
+ if (typeof rule !== 'string' || rule.length === 0)
11
+ throw new Error('rule must be a non-empty string');
12
+ return rule;
13
+ }
@@ -0,0 +1,176 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ import { type ServiceApproval, type ServiceRecord, type ServiceType } from './services.js';
3
+ import type { TasraChainClient } from './client.js';
4
+ /**
5
+ * HTTPS path where a registered service publishes its canonical manifest.
6
+ */
7
+ export declare const SERVICE_MANIFEST_PATH = "/.well-known/keykeeper-service.json";
8
+ /**
9
+ * HTTPS endpoint that signs a registered-service identity challenge.
10
+ */
11
+ export declare const SERVICE_IDENTITY_PATH = "/v1/service/identity";
12
+ /**
13
+ * Maximum accepted service manifest size in bytes.
14
+ */
15
+ export declare const SERVICE_MANIFEST_MAX_BYTES = 16384;
16
+ /**
17
+ * Maximum accepted identity challenge response size in bytes.
18
+ */
19
+ export declare const SERVICE_IDENTITY_MAX_BYTES = 2048;
20
+ /**
21
+ * Maximum accepted identity challenge validity window in seconds.
22
+ */
23
+ export declare const SERVICE_CHALLENGE_SECONDS = 30;
24
+ /**
25
+ * Challenge lifetime in seconds, leaving room for clock differences.
26
+ */
27
+ export declare const SERVICE_CHALLENGE_LIFETIME_SECONDS = 25;
28
+ /**
29
+ * Protocol identifier required in registered-service manifests.
30
+ */
31
+ export declare const SERVICE_IDENTITY_PROTOCOL = "keykeeper-service-identity-v1";
32
+ /**
33
+ * Canonical public metadata binding a service endpoint to its registry identity.
34
+ */
35
+ export interface ServiceManifest {
36
+ /** Service manifest encoding version; currently 1. */
37
+ schemaVersion: 1;
38
+ /** Chain on which the service identity is registered. */
39
+ chainId: number;
40
+ /** ServiceRegistry contract holding the approved identity. */
41
+ registry: Address;
42
+ /** 32-byte registered service identifier. */
43
+ serviceId: Hex;
44
+ /** Registered service category: relayer, verifier agent or vault service. */
45
+ serviceType: ServiceType;
46
+ /** Canonical HTTPS service base URL pinned by the manifest. */
47
+ endpoint: string;
48
+ /** Required service identity protocol identifier. */
49
+ protocol: typeof SERVICE_IDENTITY_PROTOCOL;
50
+ /** Unique capability names committed in the service manifest. */
51
+ capabilities: string[];
52
+ }
53
+ /** JSON wire shape. Revision is decimal text to preserve all uint64 values in JavaScript. */
54
+ export interface ServiceChallenge {
55
+ /** Service challenge format version; currently 1. */
56
+ version: 1;
57
+ /** Chain containing the approved service identity. */
58
+ chainId: number;
59
+ /** ServiceRegistry contract for the challenge. */
60
+ registry: Address;
61
+ /** Registered service identity that must answer the challenge. */
62
+ serviceId: Hex;
63
+ /** Approved uint64 registry revision represented as decimal text. */
64
+ revision: string;
65
+ /** Canonical HTTPS endpoint bound into the challenge. */
66
+ endpoint: string;
67
+ /** Approved hash of the canonical service manifest bytes. */
68
+ manifestHash: Hex;
69
+ /** Fresh 32-byte challenge nonce encoded as lowercase hexadecimal. */
70
+ nonce: Hex;
71
+ /** Challenge expiration time in Unix seconds. */
72
+ expiresAt: number;
73
+ }
74
+ /**
75
+ * Reject aliases instead of signing a URL which another implementation normalizes differently.
76
+ * @param endpoint Canonical HTTPS base URL without credentials, query or fragment.
77
+ */
78
+ export declare function validateServiceEndpoint(endpoint: string): URL;
79
+ /**
80
+ * Canonical v1 bytes: fixed field order, compact ASCII JSON, one LF. No optional/unknown fields.
81
+ * @param manifest Versioned service metadata to validate and encode canonically.
82
+ */
83
+ export declare function encodeServiceManifest(manifest: ServiceManifest): Uint8Array;
84
+ /**
85
+ * Verify exact manifest bytes against the approved hash, canonical encoding and registry record.
86
+ * @param bytes Exact downloaded service manifest bytes.
87
+ * @param approval Application-approved service identity and pinned manifest hash.
88
+ * @param record Registry record whose endpoint and hash must match the manifest.
89
+ */
90
+ export declare function verifyServiceManifest(bytes: Uint8Array, approval: ServiceApproval, record: ServiceRecord): ServiceManifest;
91
+ /**
92
+ * Build validated EIP-712 data binding a challenge to the approved service revision and endpoint.
93
+ * @param challenge Challenge binding the service revision, endpoint, nonce and expiry.
94
+ */
95
+ export declare function serviceChallengeTypedData(challenge: ServiceChallenge): {
96
+ domain: {
97
+ name: string;
98
+ version: string;
99
+ chainId: number;
100
+ verifyingContract: `0x${string}`;
101
+ };
102
+ primaryType: "ServiceIdentity";
103
+ types: {
104
+ ServiceIdentity: {
105
+ name: string;
106
+ type: string;
107
+ }[];
108
+ };
109
+ message: {
110
+ serviceId: `0x${string}`;
111
+ revision: bigint;
112
+ endpoint: string;
113
+ manifestHash: `0x${string}`;
114
+ nonce: `0x${string}`;
115
+ expiresAt: bigint;
116
+ };
117
+ };
118
+ /**
119
+ * Canonical wire encoding accepted by both responder implementations.
120
+ * @param challenge Validated challenge to encode in the protocol wire format.
121
+ */
122
+ export declare function encodeServiceChallenge(challenge: ServiceChallenge): Uint8Array;
123
+ /**
124
+ * Call only after enforcing the same limit while receiving the HTTP body.
125
+ * @param bytes UTF-8 challenge JSON bytes to decode and validate.
126
+ */
127
+ export declare function parseServiceChallenge(bytes: Uint8Array): ServiceChallenge;
128
+ /**
129
+ * Responder must validate against its own configured profile before asking its dedicated key to sign.
130
+ * @param challenge Parsed challenge received from the client.
131
+ * @param approval Approved service identity and revision.
132
+ * @param endpoint Expected canonical service endpoint.
133
+ * @param now Current Unix time in seconds used to validate the expiry.
134
+ */
135
+ export declare function validateServiceChallenge(challenge: ServiceChallenge, approval: ServiceApproval, endpoint: string, now: number): void;
136
+ /**
137
+ * Verify the challenge response against the registry authentication key and expected request digest.
138
+ * @param challenge Expected challenge whose digest must be signed.
139
+ * @param signature Hex-encoded EIP-712 signature returned by the service.
140
+ * @param authKey Authentication address pinned by the registry record.
141
+ * @param now Current Unix time in seconds used to validate the expiry.
142
+ */
143
+ export declare function verifyServiceIdentity(challenge: ServiceChallenge, signature: Hex, authKey: Address, now: number): Promise<void>;
144
+ /** Trusted transport boundary. Implementations must enforce destination policy at connection time,
145
+ * verified TLS, no redirects/proxies/credentials, body limits and cancellation. Use chain/node in Node.
146
+ * Native browser fetch cannot enforce DNS policy; it is intentionally not a default implementation. */
147
+ export interface ServiceDiscoveryTransport {
148
+ /** Perform a bounded request using the required destination, TLS and cancellation policy; return response bytes. */
149
+ request(url: string, options: {
150
+ body?: Uint8Array;
151
+ maxBytes: number;
152
+ signal: AbortSignal;
153
+ }): Promise<Uint8Array>;
154
+ }
155
+ /**
156
+ * Approved registry record and canonical manifest authenticated by a fresh endpoint challenge.
157
+ */
158
+ export interface AuthenticatedService {
159
+ /** Application-supplied service identity and metadata pins that were checked. */
160
+ approval: ServiceApproval;
161
+ /** Registry record checked during endpoint authentication. */
162
+ record: ServiceRecord;
163
+ /** Canonical service manifest matching the approved hash and registry record. */
164
+ manifest: ServiceManifest;
165
+ /** Chain block used for the final registry record check. */
166
+ blockNumber: bigint;
167
+ /** Expiration of the endpoint authentication challenge in Unix seconds. */
168
+ expiresAt: number;
169
+ }
170
+ /**
171
+ * Uncached, bounded discovery only. A result is a short-lived observation, not verifier-agent or gas authorization.
172
+ * @param chain Trusted chain reader for the service registry.
173
+ * @param approved Application-approved service identity, revision and manifest hash.
174
+ * @param transport Guarded HTTPS transport for manifest and identity requests.
175
+ */
176
+ export declare function authenticateApprovedService(chain: TasraChainClient, approved: ServiceApproval, transport: ServiceDiscoveryTransport): Promise<AuthenticatedService>;