@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,43 @@
1
+ export { createTasraClient } from './client/index.js';
2
+ export type { TasraClient, TasraClientConfig, Session, SessionAuth, VpJwtAuth, HolderProofAuth, OpenSessionOpts, SignOpts, } from './client/index.js';
3
+ export { encryptEnvelope, toBytes, fromBytes } from './crypto/index.js';
4
+ export { decryptWithMasterKey } from './crypto/index.js';
5
+ export { buildTasraText, parseTasraPost, isTasraPost, MAX_PLAINTEXT_LEN } from './crypto/index.js';
6
+ export { fetchAndAssembleKey, fetchMpk } from './keys/index.js';
7
+ export { signCustody, signWithShardDelivery, signUserRequest, userSignaturePayload, } from './signing/index.js';
8
+ export type { SignCustodyOpts, FrostSignResult, ShardSignOpts } from './signing/index.js';
9
+ export { aggregate as aggregateFrostSignature, verify as verifyFrostSignature, } from './crypto/index.js';
10
+ export type { FrostSignature, FrostCommitment, FrostShare } from './crypto/index.js';
11
+ export { signEoaDigest, ethSignatureV, addressFromEoaPubkey } from './signing/index.js';
12
+ export type { EoaSignOpts, EoaSignature } from './signing/index.js';
13
+ export { decryptCustody, decryptWithShardDelivery } from './decryption/index.js';
14
+ export type { DecryptCustodyOpts, ShardDecryptOpts, BlsPeer } from './decryption/index.js';
15
+ export { combineDecryptShares, verifyDecryptShare } from './crypto/index.js';
16
+ export type { DecryptShare, Ciphertext } from './crypto/index.js';
17
+ export { httpFaucet } from './slots/index.js';
18
+ export type { Faucet, FaucetGrant } from './slots/index.js';
19
+ export { TasraError, TasraHttpError, AuthDeniedError, NodeUnreachableError, ThresholdNotMetError, SlotRotatedError, isAuthDenied, isRetryable, } from './errors.js';
20
+ export { CommitteeAuthorizeError } from './committee/index.js';
21
+ export { hexToBytes } from './crypto/index.js';
22
+ export { validate as validateDcql, evaluate as evaluateDcql, select as selectDcql, canonicalize as canonicalizeDcql, isOid4vpRule, jsonCredential, FORMAT_JWT_VC_JSON, DcqlMalformedError, MAX_RULE_LEN as DCQL_MAX_RULE_LEN, } from './auth/index.js';
23
+ export type { Query as DcqlQuery, CredentialQuery as DcqlCredentialQuery, CredentialSetQuery as DcqlCredentialSetQuery, ClaimQuery as DcqlClaimQuery, Meta as DcqlMeta, CredentialView, ClaimResult, Selection as DcqlSelection, } from './auth/index.js';
24
+ export { isOauthEnvelope, loadRego, packEnvelope, unpackEnvelope, lintEnvelope, evaluateEnvelope, RegoEnvelopeError, OAUTH_ENVELOPE_KEY, DEFAULT_REGO_ENTRYPOINT, REGO_POLICY_REFUSED, REGO_WASM_SHA256, } from './auth/index.js';
25
+ export type { OauthTokenSpec, OauthTokens, OauthPolicyInput, UnpackedEnvelope, EnvelopeGateReport, EnvelopeLint, OauthPresentation, EnvelopeVerdict, RegoEngine, LoadRegoOptions, } from './auth/index.js';
26
+ export { evaluateIdentityScoped, scopeCovers, MAX_IDENTITY_LEN, type ScopeNamespace, } from './auth/index.js';
27
+ export { RecipientStore, canAccess, validateRule as validateRecipientRule, type HeldCredential, } from './recipient/store.js';
28
+ export { redeemRenewalToken, createRenewal, revokeRenewal, redeemCredential, issueAdminCredential, revokeSlotUser, verifyPresentation, verifyVpJwt, decodeJwtClaims, jwtExpMs, isJwtExpiringSoon, } from './auth/index.js';
29
+ export type { RenewalGrant } from './auth/index.js';
30
+ export type { IssuedToken, JwtClaims, RedemptionGrant } from './auth/index.js';
31
+ export { credentialsCommitment, fetchHolderNonce, buildHolderProof, createHolderProof, ed25519DidKey, } from './auth/index.js';
32
+ export type { HolderSigner, HolderNonce, BuildHolderProofOpts } from './auth/index.js';
33
+ export { ibeExtractRequest, ibeDecryptRequest, requestIbeExtractionPartials, } from './committee/index.js';
34
+ export type { IbeExtractRequestOpts, IbeExtractOpts, IbeExtractionPartial } from './committee/index.js';
35
+ export { ibeEncrypt, ibeVerifyShare, ibeCombineExtract, ibeCombineDecrypt, ibeDecryptWithKey, } from './crypto/index.js';
36
+ export type { IbeCiphertext, IbeDecryptionShare, IbeVerifyingShares } from './crypto/index.js';
37
+ export { ibeSealBlob, ibeOpenBlob, ibeUnwrapBlobKey, ibeBlobDecryptKey, ibeDecryptBlobChunk, ibeBlobChunkRange, ibeBlobWrappedKey, ibeBlobDigest, IBE_BLOB_DEFAULT_CHUNK, } from './crypto/index.js';
38
+ export type { IbeBlobHeader, SealedBlob } from './crypto/index.js';
39
+ export { createOid4vpSession, pollOid4vpSession, waitForSession, payloadDigest, VerifierAgentSessionError, createOauthSession, submitOauthResponse, } from './verifier-agent/index.js';
40
+ export type { VerifierAgentSessionErrorKind, PresentationOperation, PresentationDelegation, CreateSessionParams, CreateSessionResult, CreateOauthSessionResult, SessionStatusResult, } from './verifier-agent/index.js';
41
+ export { createDpopKey, auth0DpopSigner, jwkThumbprint, accessTokenHash, isHeaderSafeNonce, } from './auth/dpop.js';
42
+ export type { DpopSigner, DpopKey } from './auth/dpop.js';
43
+ export type { GroupEnvelope } from './crypto/index.js';
package/dist/index.js ADDED
@@ -0,0 +1,98 @@
1
+ // @t3foundry/tasra-sdk - a TypeScript access gate that exposes the full functionality
2
+ // of a Tasra Network (keykeeper-node + verifier + contracts) to developers.
3
+ //
4
+ // Two layers, both product-agnostic:
5
+ // - A high-level managed client - `createTasraClient(...).openSession(slot, auth)`
6
+ // returns a Session that holds the JWT + assembled key, auto-renews on
7
+ // expiry, re-assembles on rotation, and exposes encrypt/decrypt/sign/close.
8
+ // - The underlying composable primitives - fetch BLS shards from k-of-n
9
+ // keykeeper-nodes and Lagrange-assemble the master secret key in-process
10
+ // (the nodes never reveal it), redeem/refresh DCQL-gated JWTs, assemble
11
+ // compound committee authorization tokens, encrypt/decrypt message envelopes
12
+ // (ChaCha20-Poly1305 over BLS-G2 ElGamal), create slots (sovereign or
13
+ // relayer), and read/write on-chain state (see the `@t3foundry/tasra-sdk/chain`
14
+ // subpath export).
15
+ //
16
+ // What this SDK is NOT: a product. It has no knowledge of any specific
17
+ // transport, messaging shape, or application - a developer composes these on top.
18
+ // Managed Client + Session (the few-lines integration surface)
19
+ export { createTasraClient } from './client/index.js';
20
+ // Crypto primitives
21
+ export { encryptEnvelope, toBytes, fromBytes } from './crypto/index.js';
22
+ export { decryptWithMasterKey } from './crypto/index.js';
23
+ // Envelope detection in transport payloads
24
+ export { buildTasraText, parseTasraPost, isTasraPost, MAX_PLAINTEXT_LEN } from './crypto/index.js';
25
+ // Node client
26
+ export { fetchAndAssembleKey, fetchMpk } from './keys/index.js';
27
+ // Signing
28
+ // FROST-Ed25519 (custody one-shot + client-coordinated shard-delivery, with
29
+ // local aggregation/verification) and threshold ECDSA for EVM EOAs.
30
+ export { signCustody, signWithShardDelivery, signUserRequest, userSignaturePayload, } from './signing/index.js';
31
+ export { aggregate as aggregateFrostSignature, verify as verifyFrostSignature, } from './crypto/index.js';
32
+ export { signEoaDigest, ethSignatureV, addressFromEoaPubkey } from './signing/index.js';
33
+ // Decryption (BLS threshold)
34
+ // Custody (node-coordinated) and shard-delivery (client combines partial G2
35
+ // decryption shares without ever assembling the master key).
36
+ export { decryptCustody, decryptWithShardDelivery } from './decryption/index.js';
37
+ export { combineDecryptShares, verifyDecryptShare } from './crypto/index.js';
38
+ // Slots: faucet - fund a sovereign account so it can self-create a slot
39
+ export { httpFaucet } from './slots/index.js';
40
+ // Errors
41
+ // Branch on the type instead of matching `err.message`. Typed failures in this
42
+ // module extend TasraError; some other SDK and argument errors extend Error.
43
+ // `retryable` describes transience, never whether a write is safe to repeat.
44
+ //
45
+ // catch (e) {
46
+ // if (isAuthDenied(e)) return reclaim() // 401/403 - never retry
47
+ // if (e instanceof ThresholdNotMetError) ... // e.got / e.need / e.reasons
48
+ // if (isRetryable(e)) return backoffAndRetry()
49
+ // }
50
+ export { TasraError, TasraHttpError, AuthDeniedError, NodeUnreachableError, ThresholdNotMetError, SlotRotatedError, isAuthDenied, isRetryable, } from './errors.js';
51
+ // The committee flow's HTTP error lives with the committee code but is caught
52
+ // by consumers of the managed clients, so it is reachable from the main entry.
53
+ export { CommitteeAuthorizeError } from './committee/index.js';
54
+ // Utils
55
+ export { hexToBytes } from './crypto/index.js';
56
+ // DCQL policy grammar (OID4VP-DCQL)
57
+ // The OpenID Foundation's Digital Credentials Query Language. The rule IS the
58
+ // wallet request - no compiler between the policy of record and what the user
59
+ // is shown. Validate a rule before paying for a slot, or evaluate whether
60
+ // credentials satisfy a rule client-side.
61
+ export { validate as validateDcql, evaluate as evaluateDcql, select as selectDcql, canonicalize as canonicalizeDcql, isOid4vpRule, jsonCredential, FORMAT_JWT_VC_JSON, DcqlMalformedError, MAX_RULE_LEN as DCQL_MAX_RULE_LEN, } from './auth/index.js';
62
+ // OAuth policy envelopes (ADR-0078)
63
+ // A slot whose holders authenticate with their organization's own IdP can commit a Rego
64
+ // policy over the access token's claims instead of a DCQL query. Pack, lint and evaluate it
65
+ // locally with the network's own engine (WebAssembly, loaded on first use and hash-checked);
66
+ // `isOauthEnvelope` is pure and needs no engine.
67
+ export { isOauthEnvelope, loadRego, packEnvelope, unpackEnvelope, lintEnvelope, evaluateEnvelope, RegoEnvelopeError, OAUTH_ENVELOPE_KEY, DEFAULT_REGO_ENTRYPOINT, REGO_POLICY_REFUSED, REGO_WASM_SHA256, } from './auth/index.js';
68
+ // identity-scoped rules (WHO + WHICH)
69
+ export { evaluateIdentityScoped, scopeCovers, MAX_IDENTITY_LEN, } from './auth/index.js';
70
+ // Recipient-side DCQL access gate (platform-blind)
71
+ // A recipient decides LOCALLY whether their held credentials satisfy a slot's
72
+ // rule - no query reaches the platform. Pure; reuses the shared evaluator.
73
+ export { RecipientStore, canAccess, validateRule as validateRecipientRule, } from './recipient/store.js';
74
+ // Verifier auth + JWT helpers (agnostic)
75
+ // Obtain/refresh a DCQL-gated JWT and inspect it client-side. Pure HTTP/JSON;
76
+ // no product or transport assumptions.
77
+ export { redeemRenewalToken, createRenewal, revokeRenewal, redeemCredential, issueAdminCredential, revokeSlotUser, verifyPresentation, verifyVpJwt, decodeJwtClaims, jwtExpMs, isJwtExpiringSoon, } from './auth/index.js';
78
+ // F1/F4 holder proof-of-possession (for verifiers with require_holder_binding).
79
+ export { credentialsCommitment, fetchHolderNonce, buildHolderProof, createHolderProof, ed25519DidKey, } from './auth/index.js';
80
+ // identity-scoped encryption + extraction
81
+ // Encrypt offline to an identity under a slot's MPK (`ibeEncrypt` - permissionless, the
82
+ // key need not exist yet); read back via `ibeDecryptRequest` (token to k extraction
83
+ // partials to verify each to combine to decrypt; `sk_ID` never surfaces) or opt into
84
+ // custody with `ibeExtractRequest` (returns `sk_ID` - durable for that identity;
85
+ // zeroize when done).
86
+ export { ibeExtractRequest, ibeDecryptRequest, requestIbeExtractionPartials, } from './committee/index.js';
87
+ export { ibeEncrypt, ibeVerifyShare, ibeCombineExtract, ibeCombineDecrypt, ibeDecryptWithKey, } from './crypto/index.js';
88
+ // Large objects (images, scans, documents): a per-object data key IBE-wrapped to the
89
+ // identity, the body as independently decryptable AES-256-GCM chunks (WebCrypto). One
90
+ // extracted `sk_ID` opens every object under that identity; the unwrap is one pairing
91
+ // whatever the size.
92
+ export { ibeSealBlob, ibeOpenBlob, ibeUnwrapBlobKey, ibeBlobDecryptKey, ibeDecryptBlobChunk, ibeBlobChunkRange, ibeBlobWrappedKey, ibeBlobDigest, IBE_BLOB_DEFAULT_CHUNK, } from './crypto/index.js';
93
+ // Verifier Agent (OID4VP relay)
94
+ export { createOid4vpSession, pollOid4vpSession, waitForSession, payloadDigest, VerifierAgentSessionError,
95
+ // The OAuth (BYO-IdP) session kind.
96
+ createOauthSession, submitOauthResponse, } from './verifier-agent/index.js';
97
+ // DPoP (RFC 9449)
98
+ export { createDpopKey, auth0DpopSigner, jwkThumbprint, accessTokenHash, isHeaderSafeNonce, } from './auth/dpop.js';
@@ -0,0 +1 @@
1
+ export { fetchAndAssembleKey, fetchMpk } from './node-client.js';
@@ -0,0 +1,4 @@
1
+ // Key material from the node fleet: the group public key and k-of-n shard
2
+ // assembly. The session built on top of these lives in `client/` (the managed
3
+ // `Session`); there is no channel-shaped layer any more.
4
+ export { fetchAndAssembleKey, fetchMpk } from './node-client.js';
@@ -0,0 +1,27 @@
1
+ export interface NodeConfig {
2
+ urls: string[];
3
+ jwt: string;
4
+ }
5
+ export interface MpkResponse {
6
+ group_public_key: string;
7
+ epoch: number;
8
+ }
9
+ /**
10
+ * Fetch a slot's group public key and epoch from a keeper. Reject a reply without a ready key.
11
+ *
12
+ * @param nodeUrl - Keeper HTTP base URL from the downloaded network manifest or authenticated registry.
13
+ * @param slotHex - 32-byte slot identifier, with or without the 0x prefix.
14
+ */
15
+ export declare function fetchMpk(nodeUrl: string, slotHex: string): Promise<{
16
+ mpkBytes: Uint8Array;
17
+ epoch: number;
18
+ }>;
19
+ /**
20
+ * Fetch key shards concurrently and interpolate the slot's master secret key in this process. The caller must obtain a sufficient threshold from one epoch and clear the returned key after use.
21
+ *
22
+ * @param cfg - Keeper URLs and a JWT authorizing shard release.
23
+ * @param slotHex - 32-byte slot identifier, with or without the 0x prefix.
24
+ * @returns The reconstructed master secret key as a 32-byte little-endian scalar.
25
+ * @throws If no shards are returned or interpolation fails.
26
+ */
27
+ export declare function fetchAndAssembleKey(cfg: NodeConfig, slotHex: string): Promise<Uint8Array>;
@@ -0,0 +1,97 @@
1
+ // HTTP client for the keykeeper node API. Talks to nodes directly. A browser
2
+ // app needs the node's `api.cors_allowed_origins` to include its origin; there
3
+ // is no proxy in this package.
4
+ import { assembleKey } from '../crypto/kem.js';
5
+ import { hexToBytes } from '../crypto/hex.js';
6
+ import { httpError, isAuthDenied, TasraError, ThresholdNotMetError } from '../errors.js';
7
+ /**
8
+ * Fetch a slot's group public key and epoch from a keeper. Reject a reply without a ready key.
9
+ *
10
+ * @param nodeUrl - Keeper HTTP base URL from the downloaded network manifest or authenticated registry.
11
+ * @param slotHex - 32-byte slot identifier, with or without the 0x prefix.
12
+ */
13
+ export async function fetchMpk(nodeUrl, slotHex) {
14
+ const clean = slotHex.startsWith('0x') ? slotHex : `0x${slotHex}`;
15
+ const res = await fetch(`${nodeUrl.replace(/\/$/, '')}/v1/keys/${clean}/public`);
16
+ // This is on the critical path of every openSession, so the error has to carry
17
+ // enough to debug: which slot, which node, and what the node actually said.
18
+ if (!res.ok) {
19
+ throw await httpError(res, nodeUrl, `fetchMpk(${clean.slice(0, 10)}…)`);
20
+ }
21
+ const body = (await res.json());
22
+ if (!body.group_public_key) {
23
+ // A known-but-unkeyed slot answers 200 with an empty key - DKG has not
24
+ // finished yet. Transient, unlike a 404.
25
+ throw new TasraError(`fetchMpk: ${nodeUrl} served slot ${clean.slice(0, 10)}… with no group_public_key ` +
26
+ `(DKG has not completed for this slot yet)`, { retryable: true });
27
+ }
28
+ return { mpkBytes: hexToBytes(body.group_public_key), epoch: body.epoch ?? 0 };
29
+ }
30
+ /**
31
+ * Fetch key shards concurrently and interpolate the slot's master secret key in this process. The caller must obtain a sufficient threshold from one epoch and clear the returned key after use.
32
+ *
33
+ * @param cfg - Keeper URLs and a JWT authorizing shard release.
34
+ * @param slotHex - 32-byte slot identifier, with or without the 0x prefix.
35
+ * @returns The reconstructed master secret key as a 32-byte little-endian scalar.
36
+ * @throws If no shards are returned or interpolation fails.
37
+ */
38
+ export async function fetchAndAssembleKey(cfg, slotHex) {
39
+ const clean = slotHex.startsWith('0x') ? slotHex : `0x${slotHex}`;
40
+ const body = JSON.stringify({ key_slot_id: clean });
41
+ const shards = [];
42
+ const results = await Promise.allSettled(cfg.urls.map(async (nodeUrl) => {
43
+ const headers = {
44
+ 'Content-Type': 'application/json',
45
+ Authorization: `Bearer ${cfg.jwt}`,
46
+ };
47
+ const res = await fetch(`${nodeUrl.replace(/\/$/, '')}/v1/shards/key`, { method: 'POST', headers, body });
48
+ if (!res.ok)
49
+ throw await httpError(res, nodeUrl, `shards/key from ${nodeUrl}`);
50
+ const data = (await res.json());
51
+ return { id: data.identifier, bytes: b64ToBytes(data.shard) };
52
+ }));
53
+ const reasons = [];
54
+ const errors = [];
55
+ for (const r of results) {
56
+ if (r.status === 'fulfilled')
57
+ shards.push(r.value);
58
+ else {
59
+ errors.push(r.reason);
60
+ reasons.push(r.reason instanceof Error ? r.reason.message : String(r.reason));
61
+ }
62
+ }
63
+ if (shards.length === 0) {
64
+ // Surface an AUTH failure as such: when every node rejected with 401/403
65
+ // (expired/denied/revoked JWT), the caller must re-claim - retrying the same
66
+ // token is futile, and a generic message reads as transient and gets
67
+ // retry-looped. Only when the failures are NOT auth (cold DKG, network) is
68
+ // it transient.
69
+ //
70
+ // Either way the per-node `reasons` ride along on the error rather than
71
+ // being discarded, so a caller can tell a DNS failure from a cold DKG.
72
+ const denied = errors.filter(isAuthDenied);
73
+ throw new ThresholdNotMetError({
74
+ got: 0,
75
+ need: cfg.urls.length ? 1 : 0,
76
+ reasons,
77
+ retryable: denied.length !== errors.length,
78
+ message: denied.length === errors.length && denied.length > 0
79
+ ? `fetchAndAssembleKey: every node denied the JWT (re-claim; retrying the same token will fail) — ${reasons.join('; ')}`
80
+ : `fetchAndAssembleKey: no shards collected from ${cfg.urls.length} node(s) — ${reasons.join('; ')}`,
81
+ });
82
+ }
83
+ return assembleKey(shards);
84
+ }
85
+ function b64ToBytes(b64) {
86
+ return Uint8Array.from(atob(b64), c => c.charCodeAt(0));
87
+ }
88
+ // There is no `triggerDkg` here, and no keeper endpoint that creates a slot: a
89
+ // slot created over HTTP would have no on-chain record - no creator, no
90
+ // contract-drawn committee, no `KeySlotCreated` - and a DCQL rule nothing could
91
+ // commitment-check.
92
+ //
93
+ // Create the slot ON CHAIN
94
+ // (`createTasraWriteClient(...).createSlot(...)`, or the operator CLI
95
+ // `tasra-cli slot create`); each drawn keeper then runs the ceremony itself
96
+ // from the event. Afterwards the clear-text rule must be provisioned to the
97
+ // committee WITH its salt.
@@ -0,0 +1,76 @@
1
+ /** Domain separator for binding chain, slot, action and payload digest. */
2
+ export declare const REQUEST_BINDING_DOMAIN = "keykeeper-committee/request-binding/v1";
3
+ /** Domain separator for deriving a wallet presentation nonce from the operation context. */
4
+ export declare const VP_NONCE_DOMAIN = "keykeeper/vp-nonce/v1";
5
+ /** Domain separator for the ciphertext digest used in decryption authorization. */
6
+ export declare const DECRYPT_DIGEST_DOMAIN = "keykeeper/decrypt-audit-ciphertext/v1";
7
+ /** Operation names accepted by the committee request-binding protocol. */
8
+ export type CommitteeAction = 'sign' | 'decrypt' | 'ibe-extract' | 'dual-approve';
9
+ /** Supported operation names accepted by request-binding validation. */
10
+ export declare const COMMITTEE_ACTIONS: readonly CommitteeAction[];
11
+ /**
12
+ * `keccak256(DOMAIN || chain_id u64 BE || slot_id || len(action) u32 BE || action || payload_digest)` -
13
+ * the ONE binding hash the verifier-agent, the JAR signer, every drawn verifier, the keeper, the
14
+ * accountant audit and this SDK compute. The wallet's request body is deliberately NOT in it.
15
+ *
16
+ * @param chainId - EVM chain identifier.
17
+ * @param slotId - 32-byte slot identifier.
18
+ * @param action - Operation name bound into the request.
19
+ * @param payloadDigest - 32-byte action-specific payload digest.
20
+ */
21
+ export declare function requestHash(chainId: number | bigint, slotId: Uint8Array, action: CommitteeAction, payloadDigest: Uint8Array): Uint8Array;
22
+ /**
23
+ * The authenticated context a wallet nonce binds beyond the request hash and the session
24
+ * random (the reference nonce context): the beacon epoch, the anchored verifier-set
25
+ * snapshot root and size, the slot's effective policy and the creator-signed operation's
26
+ * expiry. The verifier-agent, the JAR signer and every fan-out verifier rebuild it from their own reads;
27
+ * changing any field needs a new wallet proof. `snapshotRoot` is all-zero only where no
28
+ * verifier-set registry is configured (dev).
29
+ */
30
+ export interface NonceContext {
31
+ /** Beacon epoch used for the verifier committee draw. */
32
+ epoch: number | bigint;
33
+ /** 32-byte anchored verifier snapshot root. */
34
+ snapshotRoot: Uint8Array;
35
+ /** Number of entries in the verifier registry. */
36
+ registrySize: number;
37
+ /** Number of verifiers selected for the committee. */
38
+ committee: number;
39
+ /** Minimum required verifier signatures. */
40
+ quorum: number;
41
+ /** Creator-signed operation expiry in Unix seconds. */
42
+ operationExp: number | bigint;
43
+ }
44
+ /**
45
+ * `base64url(keccak256(NONCE_DOMAIN || request_hash || random || epoch u64 BE || snapshot_root ||
46
+ * registry_size u32 BE || committee u32 BE || quorum u32 BE || operation_exp i64 BE))` - the
47
+ * nonce a KB-JWT must carry (the reference vp-nonce derivation, domain v2).
48
+ *
49
+ * @param reqHash - 32-byte request-binding hash.
50
+ * @param random - 32 fresh random bytes.
51
+ * @param ctx - Beacon epoch, verifier snapshot, committee policy and operation expiry to bind.
52
+ */
53
+ export declare function derivedNonce(reqHash: Uint8Array, random: Uint8Array, ctx: NonceContext): string;
54
+ /**
55
+ * The per-action `payload_digest` the keeper recomputes at `enforce_request_binding`:
56
+ * `sign` = sha256(message), `ibe-extract` = sha256(identity), `decrypt` = the ciphertext
57
+ * digest ({@link decryptPayloadDigest}), `dual-approve` = the digest the caller already
58
+ * holds. Pass exactly one of the inputs the action needs.
59
+ *
60
+ * @param action - Operation whose payload will be bound.
61
+ * @param args - Message, identity or precomputed digest required by that operation.
62
+ */
63
+ export declare function payloadDigestFor(action: CommitteeAction, args: {
64
+ message?: Uint8Array;
65
+ identity?: string;
66
+ payloadDigest?: Uint8Array;
67
+ }): Uint8Array;
68
+ /**
69
+ * The `decrypt` action's digest, mirroring the reference decrypt digest:
70
+ * `sha256(DOMAIN || len(u) u64 LE || u || len(aead_ct) u64 LE || aead_ct)` - the AEAD nonce is
71
+ * deliberately excluded (it is not authorised content).
72
+ *
73
+ * @param u - Ephemeral public key bytes from the group ciphertext.
74
+ * @param aeadCt - Authenticated ciphertext bytes, including the tag.
75
+ */
76
+ export declare function decryptPayloadDigest(u: Uint8Array, aeadCt: Uint8Array): Uint8Array;
@@ -0,0 +1,118 @@
1
+ // The request-binding derivations - `request_hash`, `vp_nonce` and the decrypt payload
2
+ // digest - shared with the keepers and the Verifier Agent. These must stay
3
+ // byte-identical so every participant checks the same authorization context.
4
+ import { keccak_256 } from '@noble/hashes/sha3';
5
+ import { sha256 } from '@noble/hashes/sha256';
6
+ import { b64url, utf8 } from './jose.js';
7
+ /** Domain separator for binding chain, slot, action and payload digest. */
8
+ export const REQUEST_BINDING_DOMAIN = 'keykeeper-committee/request-binding/v1';
9
+ /** Domain separator for deriving a wallet presentation nonce from the operation context. */
10
+ export const VP_NONCE_DOMAIN = 'keykeeper/vp-nonce/v1';
11
+ /** Domain separator for the ciphertext digest used in decryption authorization. */
12
+ export const DECRYPT_DIGEST_DOMAIN = 'keykeeper/decrypt-audit-ciphertext/v1';
13
+ /** Supported operation names accepted by request-binding validation. */
14
+ export const COMMITTEE_ACTIONS = ['sign', 'decrypt', 'ibe-extract', 'dual-approve'];
15
+ function concat(...parts) {
16
+ const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
17
+ let o = 0;
18
+ for (const p of parts) {
19
+ out.set(p, o);
20
+ o += p.length;
21
+ }
22
+ return out;
23
+ }
24
+ const be32 = (n) => new Uint8Array([(n >>> 24) & 255, (n >>> 16) & 255, (n >>> 8) & 255, n & 255]);
25
+ function be64(n) {
26
+ let v = BigInt(n);
27
+ const out = new Uint8Array(8);
28
+ for (let i = 7; i >= 0; i--) {
29
+ out[i] = Number(v & 0xffn);
30
+ v >>= 8n;
31
+ }
32
+ return out;
33
+ }
34
+ /**
35
+ * `keccak256(DOMAIN || chain_id u64 BE || slot_id || len(action) u32 BE || action || payload_digest)` -
36
+ * the ONE binding hash the verifier-agent, the JAR signer, every drawn verifier, the keeper, the
37
+ * accountant audit and this SDK compute. The wallet's request body is deliberately NOT in it.
38
+ *
39
+ * @param chainId - EVM chain identifier.
40
+ * @param slotId - 32-byte slot identifier.
41
+ * @param action - Operation name bound into the request.
42
+ * @param payloadDigest - 32-byte action-specific payload digest.
43
+ */
44
+ export function requestHash(chainId, slotId, action, payloadDigest) {
45
+ if (slotId.length !== 32)
46
+ throw new Error('requestHash: slotId must be 32 bytes');
47
+ if (payloadDigest.length !== 32)
48
+ throw new Error('requestHash: payloadDigest must be 32 bytes');
49
+ return keccak_256(concat(utf8(REQUEST_BINDING_DOMAIN), be64(chainId), slotId, be32(action.length), utf8(action), payloadDigest));
50
+ }
51
+ /**
52
+ * `base64url(keccak256(NONCE_DOMAIN || request_hash || random || epoch u64 BE || snapshot_root ||
53
+ * registry_size u32 BE || committee u32 BE || quorum u32 BE || operation_exp i64 BE))` - the
54
+ * nonce a KB-JWT must carry (the reference vp-nonce derivation, domain v2).
55
+ *
56
+ * @param reqHash - 32-byte request-binding hash.
57
+ * @param random - 32 fresh random bytes.
58
+ * @param ctx - Beacon epoch, verifier snapshot, committee policy and operation expiry to bind.
59
+ */
60
+ export function derivedNonce(reqHash, random, ctx) {
61
+ if (reqHash.length !== 32)
62
+ throw new Error('derivedNonce: reqHash must be 32 bytes');
63
+ if (random.length !== 32)
64
+ throw new Error('derivedNonce: random must be 32 bytes');
65
+ if (ctx.snapshotRoot.length !== 32)
66
+ throw new Error('derivedNonce: snapshotRoot must be 32 bytes');
67
+ return b64url(keccak_256(concat(utf8(VP_NONCE_DOMAIN), reqHash, random, be64(ctx.epoch), ctx.snapshotRoot, be32(ctx.registrySize), be32(ctx.committee), be32(ctx.quorum), be64(BigInt.asUintN(64, BigInt(ctx.operationExp))))));
68
+ }
69
+ /**
70
+ * The per-action `payload_digest` the keeper recomputes at `enforce_request_binding`:
71
+ * `sign` = sha256(message), `ibe-extract` = sha256(identity), `decrypt` = the ciphertext
72
+ * digest ({@link decryptPayloadDigest}), `dual-approve` = the digest the caller already
73
+ * holds. Pass exactly one of the inputs the action needs.
74
+ *
75
+ * @param action - Operation whose payload will be bound.
76
+ * @param args - Message, identity or precomputed digest required by that operation.
77
+ */
78
+ export function payloadDigestFor(action, args) {
79
+ switch (action) {
80
+ case 'sign':
81
+ if (args.message)
82
+ return sha256(args.message);
83
+ break;
84
+ case 'ibe-extract':
85
+ if (args.identity !== undefined)
86
+ return sha256(utf8(args.identity));
87
+ break;
88
+ case 'decrypt':
89
+ case 'dual-approve':
90
+ break;
91
+ }
92
+ if (args.payloadDigest) {
93
+ if (args.payloadDigest.length !== 32)
94
+ throw new Error('payloadDigest must be 32 bytes');
95
+ return args.payloadDigest;
96
+ }
97
+ throw new Error(`payloadDigestFor(${action}): missing the input that action digests`);
98
+ }
99
+ /**
100
+ * The `decrypt` action's digest, mirroring the reference decrypt digest:
101
+ * `sha256(DOMAIN || len(u) u64 LE || u || len(aead_ct) u64 LE || aead_ct)` - the AEAD nonce is
102
+ * deliberately excluded (it is not authorised content).
103
+ *
104
+ * @param u - Ephemeral public key bytes from the group ciphertext.
105
+ * @param aeadCt - Authenticated ciphertext bytes, including the tag.
106
+ */
107
+ export function decryptPayloadDigest(u, aeadCt) {
108
+ const le64 = (n) => {
109
+ const out = new Uint8Array(8);
110
+ let v = BigInt(n);
111
+ for (let i = 0; i < 8; i++) {
112
+ out[i] = Number(v & 0xffn);
113
+ v >>= 8n;
114
+ }
115
+ return out;
116
+ };
117
+ return sha256(concat(utf8(DECRYPT_DIGEST_DOMAIN), le64(u.length), u, le64(aeadCt.length), aeadCt));
118
+ }
@@ -0,0 +1,49 @@
1
+ import { type Jwk } from './jose.js';
2
+ /** DID document fields used to resolve a public verification key. */
3
+ export interface DidDocument {
4
+ /** DID identified by this document. */
5
+ id: string;
6
+ /** Public keys and verification method identifiers. */
7
+ verificationMethod?: Array<{
8
+ id: string;
9
+ type?: string;
10
+ controller?: string;
11
+ publicKeyJwk?: Jwk;
12
+ publicKeyMultibase?: string;
13
+ }>;
14
+ /** Verification methods authorized for authentication. */
15
+ authentication?: Array<string | {
16
+ id: string;
17
+ }>;
18
+ /** Verification methods authorized for assertions. */
19
+ assertionMethod?: Array<string | {
20
+ id: string;
21
+ }>;
22
+ }
23
+ /**
24
+ * The HTTPS URL a `did:web` resolves from (W3C did:web method).
25
+ *
26
+ * @param did - did:web identifier, with an optional fragment.
27
+ */
28
+ export declare function didWebUrl(did: string): string;
29
+ /** Fetch implementation and optional loopback HTTP permission for did:web resolution. */
30
+ export interface ResolveOpts {
31
+ /** HTTP transport override; defaults to the global fetch implementation. */
32
+ fetchImpl?: typeof fetch;
33
+ /** Allow `http://` for a loopback host (tests, loopback services); never for a public host. */
34
+ allowInsecureLoopback?: boolean;
35
+ }
36
+ /**
37
+ * Fetch and minimally validate a `did:web` document.
38
+ *
39
+ * @param did - did:web identifier to resolve.
40
+ * @param opts - Fetch override and optional loopback HTTP permission.
41
+ */
42
+ export declare function resolveDidWeb(did: string, opts?: ResolveOpts): Promise<DidDocument>;
43
+ /**
44
+ * The JWK behind `kid` (a full DID URL or a `#fragment`) in `doc`.
45
+ *
46
+ * @param doc - Resolved DID document containing public verification methods.
47
+ * @param kid - Signing key identifier or fragment to locate.
48
+ */
49
+ export declare function verificationKey(doc: DidDocument, kid: string): Jwk;
@@ -0,0 +1,57 @@
1
+ // Resolve did:web verification methods by their identifiers.
2
+ import { b64url } from './jose.js';
3
+ import { base58Decode } from './jose.js';
4
+ /**
5
+ * The HTTPS URL a `did:web` resolves from (W3C did:web method).
6
+ *
7
+ * @param did - did:web identifier, with an optional fragment.
8
+ */
9
+ export function didWebUrl(did) {
10
+ const m = /^did:web:(.+)$/.exec(did.split('#')[0]);
11
+ if (!m)
12
+ throw new Error(`not a did:web: ${did}`);
13
+ const segments = m[1].split(':').map(s => decodeURIComponent(s));
14
+ const host = segments[0];
15
+ const path = segments.slice(1);
16
+ return path.length === 0 ? `https://${host}/.well-known/did.json` : `https://${host}/${path.join('/')}/did.json`;
17
+ }
18
+ /**
19
+ * Fetch and minimally validate a `did:web` document.
20
+ *
21
+ * @param did - did:web identifier to resolve.
22
+ * @param opts - Fetch override and optional loopback HTTP permission.
23
+ */
24
+ export async function resolveDidWeb(did, opts = {}) {
25
+ let url = didWebUrl(did);
26
+ if (opts.allowInsecureLoopback && /^https:\/\/(localhost|127\.0\.0\.1)(:\d+)?\//.test(url))
27
+ url = url.replace(/^https:/, 'http:');
28
+ const f = opts.fetchImpl ?? fetch;
29
+ const res = await f(url, { headers: { Accept: 'application/json' } });
30
+ if (!res.ok)
31
+ throw new Error(`did:web resolution ${url} → HTTP ${res.status}`);
32
+ const doc = (await res.json());
33
+ if (doc.id !== did.split('#')[0])
34
+ throw new Error(`did:web document id ${doc.id} != ${did}`);
35
+ return doc;
36
+ }
37
+ /**
38
+ * The JWK behind `kid` (a full DID URL or a `#fragment`) in `doc`.
39
+ *
40
+ * @param doc - Resolved DID document containing public verification methods.
41
+ * @param kid - Signing key identifier or fragment to locate.
42
+ */
43
+ export function verificationKey(doc, kid) {
44
+ const frag = kid.includes('#') ? kid.slice(kid.indexOf('#')) : kid;
45
+ const vm = (doc.verificationMethod ?? []).find(v => v.id === kid || v.id === frag || v.id.endsWith(frag));
46
+ if (!vm)
47
+ throw new Error(`did document ${doc.id} has no verification method ${kid}`);
48
+ if (vm.publicKeyJwk)
49
+ return vm.publicKeyJwk;
50
+ if (vm.publicKeyMultibase) {
51
+ const raw = base58Decode(vm.publicKeyMultibase.replace(/^z/, ''));
52
+ if (raw[0] === 0xed && raw[1] === 0x01)
53
+ return { kty: 'OKP', crv: 'Ed25519', x: b64url(raw.slice(2)) };
54
+ throw new Error('unsupported publicKeyMultibase codec');
55
+ }
56
+ throw new Error(`verification method ${vm.id} carries no key material`);
57
+ }
@@ -0,0 +1,9 @@
1
+ export * from './binding.js';
2
+ export * from './jose.js';
3
+ export * from './sd-jwt.js';
4
+ export * from './jwe.js';
5
+ export * from './did-web.js';
6
+ export * from './request-object.js';
7
+ export * from './wallet.js';
8
+ export * from './oid4vci.js';
9
+ export * from './verifier-agent.js';
@@ -0,0 +1,10 @@
1
+ // Wallet issuance, presentation, JOSE helpers and verifier-agent integration.
2
+ export * from './binding.js';
3
+ export * from './jose.js';
4
+ export * from './sd-jwt.js';
5
+ export * from './jwe.js';
6
+ export * from './did-web.js';
7
+ export * from './request-object.js';
8
+ export * from './wallet.js';
9
+ export * from './oid4vci.js';
10
+ export * from './verifier-agent.js';