@t3foundry/tasra-sdk 0.0.0-stage → 0.3.1-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +94 -0
  4. package/README.md +137 -2
  5. package/SECURITY.md +115 -0
  6. package/dist/app/approvals.d.ts +50 -0
  7. package/dist/app/approvals.js +90 -0
  8. package/dist/app/authorization.d.ts +19 -0
  9. package/dist/app/authorization.js +20 -0
  10. package/dist/app/client.d.ts +231 -0
  11. package/dist/app/client.js +272 -0
  12. package/dist/app/creation.d.ts +73 -0
  13. package/dist/app/creation.js +77 -0
  14. package/dist/app/deployment.d.ts +36 -0
  15. package/dist/app/deployment.js +18 -0
  16. package/dist/app/identity.d.ts +211 -0
  17. package/dist/app/identity.js +287 -0
  18. package/dist/app/index.d.ts +22 -0
  19. package/dist/app/index.js +12 -0
  20. package/dist/app/manifest.d.ts +74 -0
  21. package/dist/app/manifest.js +120 -0
  22. package/dist/app/node.d.ts +30 -0
  23. package/dist/app/node.js +159 -0
  24. package/dist/app/ready-slot.d.ts +157 -0
  25. package/dist/app/ready-slot.js +199 -0
  26. package/dist/app/tasra-client.d.ts +125 -0
  27. package/dist/app/tasra-client.js +79 -0
  28. package/dist/app/viem.d.ts +10 -0
  29. package/dist/app/viem.js +32 -0
  30. package/dist/app/wallet.d.ts +126 -0
  31. package/dist/app/wallet.js +137 -0
  32. package/dist/auth/dpop.d.ts +86 -0
  33. package/dist/auth/dpop.js +142 -0
  34. package/dist/auth/holderProof.d.ts +102 -0
  35. package/dist/auth/holderProof.js +161 -0
  36. package/dist/auth/identityScope.d.ts +19 -0
  37. package/dist/auth/identityScope.js +82 -0
  38. package/dist/auth/index.d.ts +11 -0
  39. package/dist/auth/index.js +13 -0
  40. package/dist/auth/oid4vp.d.ts +230 -0
  41. package/dist/auth/oid4vp.js +780 -0
  42. package/dist/auth/rego/wasm/PINS.json +11 -0
  43. package/dist/auth/rego/wasm/keykeeper_rego_wasm.d.ts +76 -0
  44. package/dist/auth/rego/wasm/keykeeper_rego_wasm.js +379 -0
  45. package/dist/auth/rego/wasm/keykeeper_rego_wasm_bg.wasm +0 -0
  46. package/dist/auth/rego.d.ts +192 -0
  47. package/dist/auth/rego.js +492 -0
  48. package/dist/auth/verifier.d.ts +166 -0
  49. package/dist/auth/verifier.js +211 -0
  50. package/dist/chain/abis/accountantSetRegistry.d.ts +441 -0
  51. package/dist/chain/abis/accountantSetRegistry.js +574 -0
  52. package/dist/chain/abis/accountantSlashing.d.ts +2071 -0
  53. package/dist/chain/abis/accountantSlashing.js +2670 -0
  54. package/dist/chain/abis/bondingCurve.d.ts +398 -0
  55. package/dist/chain/abis/bondingCurve.js +521 -0
  56. package/dist/chain/abis/equivocationSlasher.d.ts +292 -0
  57. package/dist/chain/abis/equivocationSlasher.js +379 -0
  58. package/dist/chain/abis/fixedTasraPriceOracle.d.ts +52 -0
  59. package/dist/chain/abis/fixedTasraPriceOracle.js +72 -0
  60. package/dist/chain/abis/index.d.ts +12801 -0
  61. package/dist/chain/abis/index.js +64 -0
  62. package/dist/chain/abis/keeperShareRegistry.d.ts +519 -0
  63. package/dist/chain/abis/keeperShareRegistry.js +675 -0
  64. package/dist/chain/abis/keyRegistry.d.ts +2421 -0
  65. package/dist/chain/abis/keyRegistry.js +3114 -0
  66. package/dist/chain/abis/livenessRegistry.d.ts +402 -0
  67. package/dist/chain/abis/livenessRegistry.js +524 -0
  68. package/dist/chain/abis/mockEurc.d.ts +210 -0
  69. package/dist/chain/abis/mockEurc.js +276 -0
  70. package/dist/chain/abis/nodeRegistry.d.ts +1630 -0
  71. package/dist/chain/abis/nodeRegistry.js +2113 -0
  72. package/dist/chain/abis/platformExecutor.d.ts +328 -0
  73. package/dist/chain/abis/platformExecutor.js +429 -0
  74. package/dist/chain/abis/prevrandaoSaltBeacon.d.ts +16 -0
  75. package/dist/chain/abis/prevrandaoSaltBeacon.js +24 -0
  76. package/dist/chain/abis/serviceRegistry.d.ts +556 -0
  77. package/dist/chain/abis/serviceRegistry.js +719 -0
  78. package/dist/chain/abis/settlement.d.ts +1624 -0
  79. package/dist/chain/abis/settlement.js +2096 -0
  80. package/dist/chain/abis/tasraSwapRouter.d.ts +92 -0
  81. package/dist/chain/abis/tasraSwapRouter.js +122 -0
  82. package/dist/chain/abis/tasraToken.d.ts +455 -0
  83. package/dist/chain/abis/tasraToken.js +599 -0
  84. package/dist/chain/abis/tasraVestingVault.d.ts +165 -0
  85. package/dist/chain/abis/tasraVestingVault.js +215 -0
  86. package/dist/chain/abis/thresholdRandomBeacon.d.ts +378 -0
  87. package/dist/chain/abis/thresholdRandomBeacon.js +494 -0
  88. package/dist/chain/abis/treasury.d.ts +301 -0
  89. package/dist/chain/abis/treasury.js +390 -0
  90. package/dist/chain/abis/verifierSetRegistry.d.ts +445 -0
  91. package/dist/chain/abis/verifierSetRegistry.js +579 -0
  92. package/dist/chain/client.d.ts +212 -0
  93. package/dist/chain/client.js +576 -0
  94. package/dist/chain/commitmentRecovery.d.ts +21 -0
  95. package/dist/chain/commitmentRecovery.js +44 -0
  96. package/dist/chain/committeeClient.d.ts +102 -0
  97. package/dist/chain/committeeClient.js +137 -0
  98. package/dist/chain/deployments.d.ts +56 -0
  99. package/dist/chain/deployments.js +269 -0
  100. package/dist/chain/discovery.d.ts +49 -0
  101. package/dist/chain/discovery.js +107 -0
  102. package/dist/chain/events.d.ts +58 -0
  103. package/dist/chain/events.js +125 -0
  104. package/dist/chain/format.d.ts +25 -0
  105. package/dist/chain/format.js +51 -0
  106. package/dist/chain/index.d.ts +41 -0
  107. package/dist/chain/index.js +56 -0
  108. package/dist/chain/manifest.d.ts +165 -0
  109. package/dist/chain/manifest.js +132 -0
  110. package/dist/chain/network-profiles.json +75 -0
  111. package/dist/chain/networks.d.ts +73 -0
  112. package/dist/chain/networks.js +62 -0
  113. package/dist/chain/node.d.ts +44 -0
  114. package/dist/chain/node.js +176 -0
  115. package/dist/chain/offchain.d.ts +149 -0
  116. package/dist/chain/offchain.js +73 -0
  117. package/dist/chain/provisionRule.d.ts +164 -0
  118. package/dist/chain/provisionRule.js +212 -0
  119. package/dist/chain/registeredAgent.d.ts +64 -0
  120. package/dist/chain/registeredAgent.js +140 -0
  121. package/dist/chain/registeredOperation.d.ts +49 -0
  122. package/dist/chain/registeredOperation.js +136 -0
  123. package/dist/chain/registeredRelay.d.ts +206 -0
  124. package/dist/chain/registeredRelay.js +312 -0
  125. package/dist/chain/revertReason.d.ts +14 -0
  126. package/dist/chain/revertReason.js +62 -0
  127. package/dist/chain/ruleAmendment.d.ts +80 -0
  128. package/dist/chain/ruleAmendment.js +195 -0
  129. package/dist/chain/ruleAmendmentCore.d.ts +129 -0
  130. package/dist/chain/ruleAmendmentCore.js +152 -0
  131. package/dist/chain/ruleInput.d.ts +10 -0
  132. package/dist/chain/ruleInput.js +13 -0
  133. package/dist/chain/serviceIdentity.d.ts +176 -0
  134. package/dist/chain/serviceIdentity.js +237 -0
  135. package/dist/chain/serviceProfiles.d.ts +39 -0
  136. package/dist/chain/serviceProfiles.js +74 -0
  137. package/dist/chain/services.d.ts +141 -0
  138. package/dist/chain/services.js +79 -0
  139. package/dist/chain/slotClient.d.ts +55 -0
  140. package/dist/chain/slotClient.js +62 -0
  141. package/dist/chain/slotSeed.d.ts +31 -0
  142. package/dist/chain/slotSeed.js +98 -0
  143. package/dist/chain/write.d.ts +431 -0
  144. package/dist/chain/write.js +958 -0
  145. package/dist/client/client.d.ts +112 -0
  146. package/dist/client/client.js +111 -0
  147. package/dist/client/index.d.ts +3 -0
  148. package/dist/client/index.js +2 -0
  149. package/dist/client/session.d.ts +67 -0
  150. package/dist/client/session.js +238 -0
  151. package/dist/committee/client.d.ts +284 -0
  152. package/dist/committee/client.js +351 -0
  153. package/dist/committee/dual-sign.d.ts +110 -0
  154. package/dist/committee/dual-sign.js +202 -0
  155. package/dist/committee/ecdsa.d.ts +36 -0
  156. package/dist/committee/ecdsa.js +45 -0
  157. package/dist/committee/extraction.d.ts +82 -0
  158. package/dist/committee/extraction.js +96 -0
  159. package/dist/committee/index.d.ts +19 -0
  160. package/dist/committee/index.js +13 -0
  161. package/dist/committee/oauth.d.ts +51 -0
  162. package/dist/committee/oauth.js +90 -0
  163. package/dist/committee/receipts.d.ts +51 -0
  164. package/dist/committee/receipts.js +59 -0
  165. package/dist/committee/request.d.ts +264 -0
  166. package/dist/committee/request.js +305 -0
  167. package/dist/committee/token.d.ts +274 -0
  168. package/dist/committee/token.js +418 -0
  169. package/dist/crypto/constants.d.ts +10 -0
  170. package/dist/crypto/constants.js +32 -0
  171. package/dist/crypto/detect.d.ts +20 -0
  172. package/dist/crypto/detect.js +44 -0
  173. package/dist/crypto/envelope.d.ts +60 -0
  174. package/dist/crypto/envelope.js +243 -0
  175. package/dist/crypto/frost.d.ts +49 -0
  176. package/dist/crypto/frost.js +152 -0
  177. package/dist/crypto/hex.d.ts +7 -0
  178. package/dist/crypto/hex.js +24 -0
  179. package/dist/crypto/ibe-blob.d.ts +114 -0
  180. package/dist/crypto/ibe-blob.js +208 -0
  181. package/dist/crypto/ibe.d.ts +88 -0
  182. package/dist/crypto/ibe.js +262 -0
  183. package/dist/crypto/index.d.ts +12 -0
  184. package/dist/crypto/index.js +12 -0
  185. package/dist/crypto/kem.d.ts +55 -0
  186. package/dist/crypto/kem.js +241 -0
  187. package/dist/decryption/client.d.ts +64 -0
  188. package/dist/decryption/client.js +82 -0
  189. package/dist/decryption/index.d.ts +2 -0
  190. package/dist/decryption/index.js +2 -0
  191. package/dist/errors.d.ts +124 -0
  192. package/dist/errors.js +167 -0
  193. package/dist/index.d.ts +43 -0
  194. package/dist/index.js +98 -0
  195. package/dist/keys/index.d.ts +1 -0
  196. package/dist/keys/index.js +4 -0
  197. package/dist/keys/node-client.d.ts +27 -0
  198. package/dist/keys/node-client.js +97 -0
  199. package/dist/oid4vp/binding.d.ts +76 -0
  200. package/dist/oid4vp/binding.js +118 -0
  201. package/dist/oid4vp/did-web.d.ts +49 -0
  202. package/dist/oid4vp/did-web.js +57 -0
  203. package/dist/oid4vp/index.d.ts +9 -0
  204. package/dist/oid4vp/index.js +10 -0
  205. package/dist/oid4vp/jose.d.ts +166 -0
  206. package/dist/oid4vp/jose.js +242 -0
  207. package/dist/oid4vp/jwe.d.ts +30 -0
  208. package/dist/oid4vp/jwe.js +93 -0
  209. package/dist/oid4vp/oid4vci.d.ts +84 -0
  210. package/dist/oid4vp/oid4vci.js +85 -0
  211. package/dist/oid4vp/request-object.d.ts +109 -0
  212. package/dist/oid4vp/request-object.js +96 -0
  213. package/dist/oid4vp/sd-jwt.d.ts +177 -0
  214. package/dist/oid4vp/sd-jwt.js +208 -0
  215. package/dist/oid4vp/verifier-agent.d.ts +161 -0
  216. package/dist/oid4vp/verifier-agent.js +132 -0
  217. package/dist/oid4vp/wallet.d.ts +116 -0
  218. package/dist/oid4vp/wallet.js +108 -0
  219. package/dist/recipient/store.d.ts +67 -0
  220. package/dist/recipient/store.js +98 -0
  221. package/dist/signing/ecdsa.d.ts +49 -0
  222. package/dist/signing/ecdsa.js +79 -0
  223. package/dist/signing/frost.d.ts +88 -0
  224. package/dist/signing/frost.js +145 -0
  225. package/dist/signing/index.d.ts +4 -0
  226. package/dist/signing/index.js +3 -0
  227. package/dist/slots/faucet.d.ts +23 -0
  228. package/dist/slots/faucet.js +35 -0
  229. package/dist/slots/index.d.ts +2 -0
  230. package/dist/slots/index.js +4 -0
  231. package/dist/verifier-agent/index.d.ts +241 -0
  232. package/dist/verifier-agent/index.js +411 -0
  233. package/docs/DEVELOPER-EXPERIENCE.md +62 -0
  234. package/docs/README.md +33 -0
  235. package/docs/access-control.md +76 -0
  236. package/docs/ai-development.md +292 -0
  237. package/docs/api.md +338 -0
  238. package/docs/application-api.md +335 -0
  239. package/docs/architecture.md +65 -0
  240. package/docs/basics.md +48 -0
  241. package/docs/capabilities.md +86 -0
  242. package/docs/chain.md +153 -0
  243. package/docs/compatibility.md +36 -0
  244. package/docs/consumer-migrations.md +80 -0
  245. package/docs/create-slot.md +104 -0
  246. package/docs/document-signing.md +243 -0
  247. package/docs/encrypted-notes.md +129 -0
  248. package/docs/encryption.md +100 -0
  249. package/docs/errors.md +76 -0
  250. package/docs/flows.md +289 -0
  251. package/docs/fuji.md +127 -0
  252. package/docs/funding.md +126 -0
  253. package/docs/getting-started.md +94 -0
  254. package/docs/glossary.md +44 -0
  255. package/docs/installation.md +132 -0
  256. package/docs/manage-slot.md +95 -0
  257. package/docs/native-approvals.md +124 -0
  258. package/docs/prerequisites.md +137 -0
  259. package/docs/read-slot.md +41 -0
  260. package/docs/reference/README.md +30 -0
  261. package/docs/reference/app-node.md +102 -0
  262. package/docs/reference/app.md +1737 -0
  263. package/docs/reference/chain-node.md +159 -0
  264. package/docs/reference/chain.md +3609 -0
  265. package/docs/reference/committee.md +2176 -0
  266. package/docs/reference/main.md +4068 -0
  267. package/docs/reference/oid4vp.md +2547 -0
  268. package/docs/reference/verifier-agent.md +498 -0
  269. package/docs/shared-account.md +168 -0
  270. package/docs/signing-and-encryption.md +52 -0
  271. package/docs/signing.md +172 -0
  272. package/examples/committee-slot.ts +16 -0
  273. package/examples/connect-fuji.ts +41 -0
  274. package/examples/connect-network.ts +14 -0
  275. package/examples/credential-approvals.ts +46 -0
  276. package/examples/document-signing/README.md +59 -0
  277. package/examples/document-signing/backend.ts +132 -0
  278. package/examples/document-signing/build.mjs +19 -0
  279. package/examples/document-signing/config.ts +34 -0
  280. package/examples/document-signing/gitignore.template +9 -0
  281. package/examples/document-signing/model.ts +140 -0
  282. package/examples/document-signing/network.ts +58 -0
  283. package/examples/document-signing/package.json +25 -0
  284. package/examples/document-signing/public/index.html +27 -0
  285. package/examples/document-signing/public/sample.pdf +31 -0
  286. package/examples/document-signing/public/styles.css +531 -0
  287. package/examples/document-signing/server.ts +358 -0
  288. package/examples/document-signing/setup.ts +111 -0
  289. package/examples/document-signing/store.ts +105 -0
  290. package/examples/document-signing/tsconfig.json +24 -0
  291. package/examples/document-signing/verify.ts +24 -0
  292. package/examples/document-signing/web/app.ts +312 -0
  293. package/examples/document-signing/web/preview.ts +67 -0
  294. package/examples/document-signing/web/wallet.ts +146 -0
  295. package/examples/document-signing/workflow.test.ts +228 -0
  296. package/examples/document-signing/workflow.ts +241 -0
  297. package/examples/document-signing.ts +96 -0
  298. package/examples/encrypted-notes.ts +86 -0
  299. package/examples/ethers-signer.ts +204 -0
  300. package/examples/fund-slot.ts +73 -0
  301. package/examples/getting-started.ts +25 -0
  302. package/examples/learning-authorize.ts +23 -0
  303. package/examples/learning-cancel-slot.ts +11 -0
  304. package/examples/learning-context.ts +28 -0
  305. package/examples/learning-create-slot.ts +25 -0
  306. package/examples/learning-read-slot.ts +8 -0
  307. package/examples/learning-renew-slot.ts +12 -0
  308. package/examples/learning-sign.ts +8 -0
  309. package/examples/live-config.ts +71 -0
  310. package/examples/minimal.ts +6 -0
  311. package/examples/native-approvals.ts +57 -0
  312. package/examples/network.ts +58 -0
  313. package/examples/offline.ts +16 -0
  314. package/examples/personal-vault.ts +20 -0
  315. package/examples/provision-slot.ts +47 -0
  316. package/examples/shared-account.ts +46 -0
  317. package/examples/slot-address.ts +13 -0
  318. package/examples/slot-creation.ts +9 -0
  319. package/examples/tutorial-negative.ts +26 -0
  320. package/examples/tutorial-support.ts +76 -0
  321. package/examples/viem-account.ts +203 -0
  322. package/package.json +303 -4
@@ -0,0 +1,98 @@
1
+ // In-memory credential matching for advisory access checks. No network requests
2
+ // are made; network authorization still depends on credential verification.
3
+ import { evaluate, validate, DcqlMalformedError, jsonCredential } from '../auth/oid4vp.js';
4
+ import { isOauthEnvelope } from '../auth/rego.js';
5
+ /**
6
+ * Held credentials never satisfy a `kk_oauth` envelope: it is decided over an organization's
7
+ * DPoP-bound access token, which a credential store does not hold. Refused by name rather than
8
+ * left to the DCQL parser's generic complaint, so the caller learns which tool applies.
9
+ */
10
+ function refuseEnvelope(rule) {
11
+ if (isOauthEnvelope(rule)) {
12
+ throw new DcqlMalformedError('rule is a kk_oauth policy envelope, decided over an OAuth access token rather than held credentials; use evaluateEnvelope');
13
+ }
14
+ }
15
+ /**
16
+ * A recipient's local credential store. Holds structured credentials and
17
+ * evaluates them against DCQL rules for advisory matching. It does not verify
18
+ * credential signatures or establish issuer trust.
19
+ *
20
+ * Everything here is in-memory and synchronous: deciding access reveals nothing
21
+ * to the platform.
22
+ */
23
+ export class RecipientStore {
24
+ /** Held credential views used for local policy evaluation. */
25
+ credentials;
26
+ constructor(credentials = []) {
27
+ this.credentials = credentials.map(c => 'claim' in c && typeof c.claim === 'function'
28
+ ? c
29
+ : jsonCredential(c));
30
+ }
31
+ /** Add a credential (returns `this` for chaining). */
32
+ add(credential) {
33
+ this.credentials.push('claim' in credential && typeof credential.claim === 'function'
34
+ ? credential
35
+ : jsonCredential(credential));
36
+ return this;
37
+ }
38
+ /** The credential views held in this store. */
39
+ views() {
40
+ return this.credentials;
41
+ }
42
+ /**
43
+ * Check whether held credential views match the DCQL rule without network access.
44
+ *
45
+ * @returns Whether the supplied credential views satisfy the rule; this is not network authorization.
46
+ * @throws {DcqlMalformedError} if the rule itself is broken (a slot-author
47
+ * bug - the same class the node returns as 400, not a 403 deny), or is a `kk_oauth`
48
+ * policy envelope, which held credentials cannot satisfy. Callers
49
+ * who want a never-throwing check should use {@link canAccess}.
50
+ */
51
+ satisfies(rule) {
52
+ refuseEnvelope(rule);
53
+ return evaluate(rule, this.credentials);
54
+ }
55
+ /**
56
+ * Build a store from parsed JWT credential bodies.
57
+ * Each entry needs a `type` array and an `iss` field in the body at minimum.
58
+ */
59
+ static fromJwtBodies(bodies) {
60
+ const held = bodies.map(b => ({
61
+ format: 'jwt_vc_json',
62
+ types: b.type,
63
+ body: b,
64
+ }));
65
+ return new RecipientStore(held);
66
+ }
67
+ }
68
+ /**
69
+ * Check whether held credential views match a DCQL rule without network access.
70
+ *
71
+ * Accepts a {@link RecipientStore} or a bare {@link HeldCredential} list.
72
+ * Unlike {@link RecipientStore.satisfies}, a malformed rule returns `false`
73
+ * (fail-closed) rather than throwing.
74
+ *
75
+ * @param rule - DCQL policy encoded as JSON text.
76
+ * @param store - Held credential views used for the local access decision.
77
+ */
78
+ export function canAccess(rule, store) {
79
+ const s = Array.isArray(store) ? new RecipientStore(store) : store;
80
+ try {
81
+ return s.satisfies(rule);
82
+ }
83
+ catch (e) {
84
+ if (e instanceof DcqlMalformedError)
85
+ return false;
86
+ throw e;
87
+ }
88
+ }
89
+ /**
90
+ * Explicitly validate a slot's rule client-side: returns normally if well-formed,
91
+ * throws {@link DcqlMalformedError} otherwise.
92
+ *
93
+ * @param rule - DCQL policy encoded as JSON text.
94
+ */
95
+ export function validateRule(rule) {
96
+ refuseEnvelope(rule);
97
+ validate(rule);
98
+ }
@@ -0,0 +1,49 @@
1
+ /** Keeper endpoint, JWT, slot and 32-byte digest for threshold ECDSA signing. */
2
+ export interface EoaSignOpts {
3
+ /** Keeper HTTP base URL. */
4
+ nodeUrl: string;
5
+ /** Compact bearer JWT authorizing the request. */
6
+ jwt: string;
7
+ /** 0x-prefixed (or bare) bytes32 slot id (must be a tecdsa-mode slot). */
8
+ slotId: string;
9
+ /** The 32-byte prehash to sign (e.g. the EIP-1559 signing hash). */
10
+ digest: Uint8Array;
11
+ /** 20-byte operator address to pin (anti-Sybil). */
12
+ targetKeykeeper?: string;
13
+ }
14
+ /** Threshold ECDSA signature components, recovery identifier and signing public key. */
15
+ export interface EoaSignature {
16
+ /** 33-byte compressed secp256k1 group public key (the EOA's pubkey). */
17
+ groupPublicKey: Uint8Array;
18
+ /** 32-byte big-endian r. */
19
+ r: Uint8Array;
20
+ /** 32-byte big-endian s (low-s normalized per EIP-2). */
21
+ s: Uint8Array;
22
+ /** Raw recovery id, 0 or 1. Use ethSignatureV() to get the EVM `v`. */
23
+ yParity: 0 | 1;
24
+ }
25
+ /**
26
+ * Threshold-sign a 32-byte digest with a tecdsa slot's key. Returns the raw
27
+ * Ethereum signature components; assemble into a transaction with ethSignatureV().
28
+ *
29
+ * @param opts - Keeper endpoint, JWT, slot and 32-byte ECDSA digest.
30
+ */
31
+ export declare function signEoaDigest(opts: EoaSignOpts): Promise<EoaSignature>;
32
+ /**
33
+ * Map the raw recovery id (0/1) to an Ethereum `v`: legacy 27/28, or EIP-155
34
+ * (`35 + 2*chainId + yParity`) when a chainId is given.
35
+ *
36
+ * @param yParity - Recovery parity, zero or one.
37
+ * @param chainId - Optional chain identifier for an EIP-155 transaction signature.
38
+ */
39
+ export declare function ethSignatureV(yParity: number, chainId?: number): number;
40
+ /**
41
+ * Derive the EIP-55 checksummed `0x` Ethereum address of a threshold EOA from its
42
+ * secp256k1 group public key - pass `EoaSignature.groupPublicKey` (33-byte
43
+ * compressed) or a 65-byte uncompressed key. Pure `@noble` (no ethers/web3): the
44
+ * key is decompressed, keccak-256'd over X||Y, and the low 20 bytes are checksummed.
45
+ * This is what an ethers `Signer.getAddress()` returns for a Tasra EOA slot.
46
+ *
47
+ * @param pubkey - SEC1-encoded secp256k1 public key, compressed or uncompressed.
48
+ */
49
+ export declare function addressFromEoaPubkey(pubkey: Uint8Array): `0x${string}`;
@@ -0,0 +1,79 @@
1
+ // Threshold ECDSA (secp256k1) signing for EVM EOAs - POST /v1/sign/eoa-digest.
2
+ // The node coordinates the signing ceremony internally; the client makes one
3
+ // round-trip with a 32-byte prehash digest and gets back Ethereum (r, s, v).
4
+ // The slot must be a `tecdsa`-mode slot.
5
+ //
6
+ // Bodies use BARE hex (no 0x): the node hex-decodes key_slot_id and digest
7
+ // directly.
8
+ import { hexToBytes } from '../crypto/hex.js';
9
+ import { bytesToHex as toHex } from '@noble/hashes/utils';
10
+ import { secp256k1 } from '@noble/curves/secp256k1';
11
+ import { keccak_256 } from '@noble/hashes/sha3';
12
+ import { httpError } from '../errors.js';
13
+ const strip0x = (s) => (s.startsWith('0x') ? s.slice(2) : s);
14
+ const base = (u) => u.replace(/\/$/, '');
15
+ /**
16
+ * Threshold-sign a 32-byte digest with a tecdsa slot's key. Returns the raw
17
+ * Ethereum signature components; assemble into a transaction with ethSignatureV().
18
+ *
19
+ * @param opts - Keeper endpoint, JWT, slot and 32-byte ECDSA digest.
20
+ */
21
+ export async function signEoaDigest(opts) {
22
+ if (opts.digest.length !== 32) {
23
+ throw new Error(`signEoaDigest: digest must be 32 bytes, got ${opts.digest.length}`);
24
+ }
25
+ const body = {
26
+ key_slot_id: strip0x(opts.slotId),
27
+ digest: toHex(opts.digest),
28
+ };
29
+ if (opts.targetKeykeeper)
30
+ body.target_keykeeper = strip0x(opts.targetKeykeeper);
31
+ const url = `${base(opts.nodeUrl)}/v1/sign/eoa-digest`;
32
+ const res = await fetch(url, {
33
+ method: 'POST',
34
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${opts.jwt}` },
35
+ body: JSON.stringify(body),
36
+ });
37
+ if (!res.ok)
38
+ throw await httpError(res, url, 'sign/eoa-digest');
39
+ const d = (await res.json());
40
+ return {
41
+ groupPublicKey: hexToBytes(d.group_public_key),
42
+ r: hexToBytes(d.signature_r),
43
+ s: hexToBytes(d.signature_s),
44
+ yParity: Number(d.signature_v) === 1 ? 1 : 0,
45
+ };
46
+ }
47
+ /**
48
+ * Map the raw recovery id (0/1) to an Ethereum `v`: legacy 27/28, or EIP-155
49
+ * (`35 + 2*chainId + yParity`) when a chainId is given.
50
+ *
51
+ * @param yParity - Recovery parity, zero or one.
52
+ * @param chainId - Optional chain identifier for an EIP-155 transaction signature.
53
+ */
54
+ export function ethSignatureV(yParity, chainId) {
55
+ return chainId === undefined ? 27 + yParity : 35 + 2 * chainId + yParity;
56
+ }
57
+ // EIP-55 checksum: uppercase each hex nibble whose matching keccak nibble is at least 8.
58
+ function toChecksumAddress(addrLowerNoPrefix) {
59
+ const hash = toHex(keccak_256(addrLowerNoPrefix)); // keccak of the lowercase ASCII hex
60
+ let out = '';
61
+ for (let i = 0; i < addrLowerNoPrefix.length; i++) {
62
+ out += parseInt(hash[i], 16) >= 8 ? addrLowerNoPrefix[i].toUpperCase() : addrLowerNoPrefix[i];
63
+ }
64
+ return out;
65
+ }
66
+ /**
67
+ * Derive the EIP-55 checksummed `0x` Ethereum address of a threshold EOA from its
68
+ * secp256k1 group public key - pass `EoaSignature.groupPublicKey` (33-byte
69
+ * compressed) or a 65-byte uncompressed key. Pure `@noble` (no ethers/web3): the
70
+ * key is decompressed, keccak-256'd over X||Y, and the low 20 bytes are checksummed.
71
+ * This is what an ethers `Signer.getAddress()` returns for a Tasra EOA slot.
72
+ *
73
+ * @param pubkey - SEC1-encoded secp256k1 public key, compressed or uncompressed.
74
+ */
75
+ export function addressFromEoaPubkey(pubkey) {
76
+ const uncompressed = secp256k1.ProjectivePoint.fromHex(pubkey).toRawBytes(false);
77
+ const addr = toHex(keccak_256(uncompressed.subarray(1)).subarray(12)); // keccak(X||Y) to last 20B
78
+ return `0x${toChecksumAddress(addr)}`;
79
+ }
@@ -0,0 +1,88 @@
1
+ import { type FrostSignature } from '../crypto/frost.js';
2
+ import type { OperationReceipt } from '../committee/receipts.js';
3
+ /** JWT-authorized FROST signing coordinated by one keeper, with optional owner approval. */
4
+ export interface SignCustodyOpts {
5
+ /** Keeper HTTP base URL. */
6
+ nodeUrl: string;
7
+ /** Compact bearer JWT authorizing the request. */
8
+ jwt: string;
9
+ /** 0x-prefixed (or bare) bytes32 slot id. */
10
+ slotId: string;
11
+ /** Raw message bytes to sign. */
12
+ message: Uint8Array;
13
+ /** Explicit signer set (u16 ids). Omit to node uses 1..k. Passing MORE than k
14
+ * ids makes the node use the robust ROAST coordinator. */
15
+ signingSet?: number[];
16
+ /** 64-byte Ed25519 user signature - required iff the slot has a registered
17
+ * owner pubkey. Build with signUserRequest(). */
18
+ userSignature?: Uint8Array;
19
+ /** 20-byte operator address to pin (anti-Sybil). */
20
+ targetKeykeeper?: string;
21
+ /** Idempotency key. Required when userSignature is set. */
22
+ requestId?: string;
23
+ }
24
+ /** FROST group signature with slot, key epoch, message digest and optional keeper receipt. */
25
+ export interface FrostSignResult {
26
+ /** Optional keeper evidence; verify separately with verifyOperationReceipt. */
27
+ receipt?: OperationReceipt;
28
+ /** Identifier of the slot that produced the result. */
29
+ keySlotId: string;
30
+ /** 32-byte compressed Edwards group public key. */
31
+ groupPublicKey: Uint8Array;
32
+ /** The group signature (R, z). Verify with verifyFrostSignature(). */
33
+ signature: FrostSignature;
34
+ /** SHA-256 of the signed message, as returned by the node. */
35
+ messageSha256: Uint8Array;
36
+ /** Slot key epoch reported with the signature. */
37
+ epoch: number;
38
+ }
39
+ /**
40
+ * Sign a message via the custody path: the node runs the whole FROST ceremony
41
+ * and returns the final group signature (one HTTP round-trip).
42
+ *
43
+ * @param opts - Keeper endpoint, JWT, message and optional participant or owner-approval settings.
44
+ */
45
+ export declare function signCustody(opts: SignCustodyOpts): Promise<FrostSignResult>;
46
+ /**
47
+ * The canonical payload the node verifies for a user-gated sign:
48
+ * domain || u64_LE(len slot) || slot || u64_LE(32) || SHA256(message) ||
49
+ * u64_LE(len requestId) || requestId.
50
+ *
51
+ * @param slotId - 32-byte slot identifier as hexadecimal text.
52
+ * @param message - Raw message bytes to authorize.
53
+ * @param requestId - Request identifier to bind into the owner approval.
54
+ */
55
+ export declare function userSignaturePayload(slotId: string, message: Uint8Array, requestId: string): Uint8Array;
56
+ /**
57
+ * Sign the user-gated payload with the slot owner's 32-byte Ed25519 secret key.
58
+ * The result goes in SignCustodyOpts.userSignature (also pass the same requestId).
59
+ *
60
+ * @param secretKey - 32-byte Ed25519 owner secret key.
61
+ * @param slotId - 32-byte slot identifier as hexadecimal text.
62
+ * @param message - Raw message bytes to authorize.
63
+ * @param requestId - Request identifier to bind into the owner approval.
64
+ */
65
+ export declare function signUserRequest(secretKey: Uint8Array, slotId: string, message: Uint8Array, requestId: string): Uint8Array;
66
+ /** JWT-authorized FROST signing coordinated by the caller across selected keepers. */
67
+ export interface ShardSignOpts {
68
+ /** Base URLs of exactly the k chosen committee nodes. */
69
+ nodeUrls: string[];
70
+ /** Compact bearer JWT authorizing the request. */
71
+ jwt: string;
72
+ /** 32-byte slot identifier. */
73
+ slotId: string;
74
+ /** Raw message bytes to sign. */
75
+ message: Uint8Array;
76
+ /** The slot's 32-byte group public key. Fetched from nodeUrls[0] if omitted. */
77
+ groupPublicKey?: Uint8Array;
78
+ /** Verify the aggregate locally before returning (default true). */
79
+ verify?: boolean;
80
+ }
81
+ /**
82
+ * Sign via the shard-delivery path: the CLIENT fans out to k nodes (Round 1
83
+ * commit, Round 2 partial) and aggregates the shares locally into the group
84
+ * signature. The node URLs must be exactly the k committee members.
85
+ *
86
+ * @param opts - Selected keepers, JWT, message and local signature verification settings.
87
+ */
88
+ export declare function signWithShardDelivery(opts: ShardSignOpts): Promise<FrostSignature>;
@@ -0,0 +1,145 @@
1
+ // FROST-Ed25519 signing - HTTP clients for the two node paths:
2
+ // - custody (POST /v1/sign) - node coordinates, one round-trip
3
+ // - shard-delivery (POST /v1/shards/sign/{commit,partial})
4
+ // - CLIENT coordinates k nodes and
5
+ // aggregates locally (frost-crypto)
6
+ //
7
+ // Bodies use BARE hex (no 0x): some node handlers hex-decode directly. Slot ids
8
+ // are sent 0x-stripped; the node tolerates either, the shard message_hex path
9
+ // does not.
10
+ import { hexToBytes } from '../crypto/hex.js';
11
+ import { bytesToHex as toHex, utf8ToBytes, concatBytes } from '@noble/hashes/utils';
12
+ import { sha256 } from '@noble/hashes/sha256';
13
+ import { ed25519 } from '@noble/curves/ed25519';
14
+ import { fetchMpk } from '../keys/node-client.js';
15
+ import { aggregate, verify, } from '../crypto/frost.js';
16
+ import { httpError } from '../errors.js';
17
+ const strip0x = (s) => (s.startsWith('0x') ? s.slice(2) : s);
18
+ const base = (u) => u.replace(/\/$/, '');
19
+ function u64le(n) {
20
+ const b = new Uint8Array(8);
21
+ new DataView(b.buffer).setBigUint64(0, BigInt(n), true);
22
+ return b;
23
+ }
24
+ async function nodePost(url, jwt, body, requestId) {
25
+ const headers = {
26
+ 'Content-Type': 'application/json',
27
+ Authorization: `Bearer ${jwt}`,
28
+ };
29
+ if (requestId)
30
+ headers['x-request-id'] = requestId;
31
+ const res = await fetch(url, { method: 'POST', headers, body: JSON.stringify(body) });
32
+ if (!res.ok)
33
+ throw await httpError(res, url, `POST ${url}`);
34
+ return res.json();
35
+ }
36
+ /**
37
+ * Sign a message via the custody path: the node runs the whole FROST ceremony
38
+ * and returns the final group signature (one HTTP round-trip).
39
+ *
40
+ * @param opts - Keeper endpoint, JWT, message and optional participant or owner-approval settings.
41
+ */
42
+ export async function signCustody(opts) {
43
+ const body = {
44
+ key_slot_id: strip0x(opts.slotId),
45
+ message_hex: toHex(opts.message),
46
+ };
47
+ if (opts.signingSet)
48
+ body.signing_set = opts.signingSet;
49
+ if (opts.userSignature)
50
+ body.user_signature = toHex(opts.userSignature);
51
+ if (opts.targetKeykeeper)
52
+ body.target_keykeeper = strip0x(opts.targetKeykeeper);
53
+ const d = await nodePost(`${base(opts.nodeUrl)}/v1/sign`, opts.jwt, body, opts.requestId);
54
+ return {
55
+ keySlotId: d.key_slot_id,
56
+ groupPublicKey: hexToBytes(d.group_public_key),
57
+ signature: { r: hexToBytes(d.signature_r), z: hexToBytes(d.signature_z) },
58
+ messageSha256: hexToBytes(d.message_sha256),
59
+ epoch: Number(d.epoch ?? 0),
60
+ };
61
+ }
62
+ // user-gated signature helper
63
+ const USER_SIG_DOMAIN = 'keykeeper:user-sig:v1';
64
+ /**
65
+ * The canonical payload the node verifies for a user-gated sign:
66
+ * domain || u64_LE(len slot) || slot || u64_LE(32) || SHA256(message) ||
67
+ * u64_LE(len requestId) || requestId.
68
+ *
69
+ * @param slotId - 32-byte slot identifier as hexadecimal text.
70
+ * @param message - Raw message bytes to authorize.
71
+ * @param requestId - Request identifier to bind into the owner approval.
72
+ */
73
+ export function userSignaturePayload(slotId, message, requestId) {
74
+ const slot = hexToBytes(slotId);
75
+ const rid = utf8ToBytes(requestId);
76
+ return concatBytes(utf8ToBytes(USER_SIG_DOMAIN), u64le(slot.length), slot, u64le(32), sha256(message), u64le(rid.length), rid);
77
+ }
78
+ /**
79
+ * Sign the user-gated payload with the slot owner's 32-byte Ed25519 secret key.
80
+ * The result goes in SignCustodyOpts.userSignature (also pass the same requestId).
81
+ *
82
+ * @param secretKey - 32-byte Ed25519 owner secret key.
83
+ * @param slotId - 32-byte slot identifier as hexadecimal text.
84
+ * @param message - Raw message bytes to authorize.
85
+ * @param requestId - Request identifier to bind into the owner approval.
86
+ */
87
+ export function signUserRequest(secretKey, slotId, message, requestId) {
88
+ return ed25519.sign(userSignaturePayload(slotId, message, requestId), secretKey);
89
+ }
90
+ async function commitRound(nodeUrl, jwt, slotId, message) {
91
+ const d = await nodePost(`${base(nodeUrl)}/v1/shards/sign/commit`, jwt, {
92
+ key_slot_id: strip0x(slotId),
93
+ message_hex: toHex(message),
94
+ });
95
+ return {
96
+ nodeUrl,
97
+ sessionId: d.session_id,
98
+ identifier: Number(d.identifier),
99
+ hiding: hexToBytes(d.hiding),
100
+ binding: hexToBytes(d.binding),
101
+ };
102
+ }
103
+ async function partialRound(nodeUrl, jwt, slotId, message, sessionId, commitments) {
104
+ const d = await nodePost(`${base(nodeUrl)}/v1/shards/sign/partial`, jwt, {
105
+ session_id: sessionId,
106
+ key_slot_id: strip0x(slotId),
107
+ message_hex: toHex(message),
108
+ commitments: commitments.map(c => ({
109
+ identifier: c.identifier,
110
+ hiding: toHex(c.hiding),
111
+ binding: toHex(c.binding),
112
+ })),
113
+ });
114
+ return {
115
+ identifier: Number(d.identifier),
116
+ z: hexToBytes(d.z),
117
+ verifyingShare: hexToBytes(d.verifying_share),
118
+ };
119
+ }
120
+ /**
121
+ * Sign via the shard-delivery path: the CLIENT fans out to k nodes (Round 1
122
+ * commit, Round 2 partial) and aggregates the shares locally into the group
123
+ * signature. The node URLs must be exactly the k committee members.
124
+ *
125
+ * @param opts - Selected keepers, JWT, message and local signature verification settings.
126
+ */
127
+ export async function signWithShardDelivery(opts) {
128
+ if (opts.nodeUrls.length === 0)
129
+ throw new Error('signWithShardDelivery: no node URLs');
130
+ // For a FROST slot, /v1/keys/{id}/public returns the 32-byte Ed25519 group key.
131
+ const groupPublicKey = opts.groupPublicKey ?? (await fetchMpk(opts.nodeUrls[0], opts.slotId)).mpkBytes;
132
+ // Round 1.
133
+ const commits = await Promise.all(opts.nodeUrls.map(u => commitRound(u, opts.jwt, opts.slotId, opts.message)));
134
+ // Canonical commitment order - sent to every node AND used to aggregate.
135
+ const commitmentList = [...commits]
136
+ .sort((a, b) => a.identifier - b.identifier)
137
+ .map(c => ({ identifier: c.identifier, hiding: c.hiding, binding: c.binding }));
138
+ // Round 2.
139
+ const shares = await Promise.all(commits.map(c => partialRound(c.nodeUrl, opts.jwt, opts.slotId, opts.message, c.sessionId, commitmentList)));
140
+ const sig = aggregate(opts.message, groupPublicKey, commitmentList, shares);
141
+ if (opts.verify !== false && !verify(groupPublicKey, opts.message, sig)) {
142
+ throw new Error('signWithShardDelivery: aggregated signature failed local verification');
143
+ }
144
+ return sig;
145
+ }
@@ -0,0 +1,4 @@
1
+ export { signCustody, signWithShardDelivery, signUserRequest, userSignaturePayload } from './frost.js';
2
+ export type { SignCustodyOpts, FrostSignResult, ShardSignOpts } from './frost.js';
3
+ export { signEoaDigest, ethSignatureV, addressFromEoaPubkey } from './ecdsa.js';
4
+ export type { EoaSignOpts, EoaSignature } from './ecdsa.js';
@@ -0,0 +1,3 @@
1
+ // Threshold signing over the node fleet - FROST-Ed25519 + threshold ECDSA (EVM EOA).
2
+ export { signCustody, signWithShardDelivery, signUserRequest, userSignaturePayload } from './frost.js';
3
+ export { signEoaDigest, ethSignatureV, addressFromEoaPubkey } from './ecdsa.js';
@@ -0,0 +1,23 @@
1
+ /** Account funding result with optional amounts and transaction hashes reported by the faucet. */
2
+ export interface FaucetGrant {
3
+ /** Account that received or was requested to receive funding. */
4
+ address: string;
5
+ /** Native gas funded, wei (decimal string). */
6
+ ethWei?: string;
7
+ /** TSRA funded, base units (decimal string). */
8
+ tsra?: string;
9
+ /** Funding tx hashes, if the faucet reports them. */
10
+ txHashes?: string[];
11
+ }
12
+ /** Funding adapter that requests native gas and TSRA for an account. */
13
+ export interface Faucet {
14
+ /** Top up `address` with gas + TSRA. */
15
+ fund(address: string): Promise<FaucetGrant>;
16
+ }
17
+ /**
18
+ * HTTP faucet client: POST {faucetUrl}/faucet {address} to FaucetGrant.
19
+ * Matches the network faucet service.
20
+ *
21
+ * @param faucetUrl - Faucet HTTP base URL advertised for the selected network.
22
+ */
23
+ export declare function httpFaucet(faucetUrl: string): Faucet;
@@ -0,0 +1,35 @@
1
+ // Faucet client - funds a fresh sovereign client account with gas (ETH) + TSRA
2
+ // so it can create and operate a slot. The faucet is an HTTP service on the
3
+ // network (dev/testnet); the client just asks it to top up an address.
4
+ //
5
+ // Interface-driven: products inject a Faucet implementation; a test or another
6
+ // environment can supply a different funding source behind the same shape.
7
+ /**
8
+ * HTTP faucet client: POST {faucetUrl}/faucet {address} to FaucetGrant.
9
+ * Matches the network faucet service.
10
+ *
11
+ * @param faucetUrl - Faucet HTTP base URL advertised for the selected network.
12
+ */
13
+ export function httpFaucet(faucetUrl) {
14
+ const base = faucetUrl.replace(/\/$/, '');
15
+ return {
16
+ async fund(address) {
17
+ const res = await fetch(`${base}/faucet`, {
18
+ method: 'POST',
19
+ headers: { 'Content-Type': 'application/json' },
20
+ body: JSON.stringify({ address }),
21
+ });
22
+ if (!res.ok) {
23
+ let detail = '';
24
+ try {
25
+ detail = (await res.text()).slice(0, 200);
26
+ }
27
+ catch {
28
+ /* ignore */
29
+ }
30
+ throw new Error(`faucet: HTTP ${res.status}${detail ? `: ${detail}` : ''}`);
31
+ }
32
+ return (await res.json());
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,2 @@
1
+ export { httpFaucet } from './faucet.js';
2
+ export type { Faucet, FaucetGrant } from './faucet.js';
@@ -0,0 +1,4 @@
1
+ // Slot funding - faucet: fund a sovereign account so it can self-create a slot
2
+ // on-chain (createTasraWriteClient().createSlot). The managed relayer
3
+ // "provisioner" path was removed - nothing used it; every consumer self-signs.
4
+ export { httpFaucet } from './faucet.js';