@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,110 @@
1
+ import { TasraError } from '../errors.js';
2
+ import type { FrostSignResult } from '../signing/frost.js';
3
+ import type { CompoundTokenWire } from './token.js';
4
+ import type { VerifierProof } from './client.js';
5
+ /** A signing request may have been accepted despite a transport or response failure. Reconcile before resubmitting. */
6
+ export declare class OperationOutcomeUnknownError extends TasraError {
7
+ /** Request phase whose submission outcome must be reconciled. */
8
+ readonly operation: 'dual-create' | 'dual-approve';
9
+ /** Existing native signing request identifier, when known. */
10
+ readonly requestId?: string | undefined;
11
+ constructor(
12
+ /** Request phase whose submission outcome must be reconciled. */
13
+ operation: 'dual-create' | 'dual-approve',
14
+ /** Existing native signing request identifier, when known. */
15
+ requestId?: string | undefined, cause?: unknown);
16
+ }
17
+ /**
18
+ * Exact existing Rust canonical_dual_sig_payload, including little-endian lengths.
19
+ *
20
+ * @param slotId - 32-byte slot identifier as hexadecimal text.
21
+ * @param message - Original message bytes to authorize.
22
+ * @param requestId - Existing native signing request identifier.
23
+ */
24
+ export declare function dualSignApprovalPayload(slotId: string, message: Uint8Array, requestId: string): Uint8Array;
25
+ /** Trusted slot key, keeper endpoint and approver policy for a native signing request. */
26
+ export interface DualSignConfig {
27
+ /** EVM chain identifier. */
28
+ chainId: number;
29
+ /** Keeper HTTP base URL. */
30
+ nodeUrl: string;
31
+ /** 32-byte slot identifier. */
32
+ slotId: string;
33
+ /** Expected 32-byte FROST group public key. */
34
+ groupPublicKey: Uint8Array;
35
+ /** Expected approver quorum, read from the slot policy. Not the keeper threshold. */
36
+ quorum: number;
37
+ /** Whether every approval requires a request-bound credential authorization. */
38
+ credentialGated: boolean;
39
+ /** HTTP transport override; defaults to the global fetch implementation. */
40
+ fetchImpl?: typeof fetch;
41
+ /** Timeout for an individual HTTP request in milliseconds. */
42
+ timeoutMs?: number;
43
+ }
44
+ /** Native signing request progress, verified completed signature or terminal failure. */
45
+ export type DualSignStatus = {
46
+ /** Lifecycle state: pending or signing until the request is signed or fails. */
47
+ status: 'pending' | 'signing';
48
+ /** Number of accepted approvals collected for the request. */
49
+ have: number;
50
+ /** Approval quorum required before signing can finish. */
51
+ need: number;
52
+ } | {
53
+ /** Lifecycle state: pending or signing until the request is signed or fails. */
54
+ status: 'signed';
55
+ /** Verified signature and its slot-key context. */
56
+ result: FrostSignResult;
57
+ } | {
58
+ /** Lifecycle state: pending or signing until the request is signed or fails. */
59
+ status: 'failed';
60
+ };
61
+ /** Ed25519 approver public key and callback that signs canonical approval bytes. */
62
+ export interface DualSignApprover {
63
+ /** 32-byte Ed25519 approver public key. */
64
+ publicKey: Uint8Array;
65
+ /** Sign the exact supplied canonical bytes; the SDK verifies the result locally. */
66
+ sign: (payload: Uint8Array) => Promise<Uint8Array>;
67
+ }
68
+ /** Handle for checking, approving and waiting for one native multi-approver signing request. */
69
+ export interface DualSignRequest {
70
+ /** Request identifier used to correlate or resume the operation. */
71
+ readonly requestId: string;
72
+ /** 32-byte slot identifier. */
73
+ readonly slotId: string;
74
+ /** Keeper HTTP base URL. */
75
+ readonly nodeUrl: string;
76
+ /** Fetch and validate the current request state. */
77
+ status(options?: {
78
+ signal?: AbortSignal;
79
+ }): Promise<DualSignStatus>;
80
+ /** Sign and submit one approval, with credential authorization when required. */
81
+ approve(options: {
82
+ signer: DualSignApprover;
83
+ /** Each credentialed approval needs its own request-bound wallet presentation. */
84
+ authorization?: {
85
+ token: CompoundTokenWire;
86
+ verifierProofs: VerifierProof[];
87
+ };
88
+ signal?: AbortSignal;
89
+ }): Promise<DualSignStatus>;
90
+ /** Poll until a verified signature is available or the request fails or times out. */
91
+ wait(options?: {
92
+ signal?: AbortSignal;
93
+ timeoutMs?: number;
94
+ intervalMs?: number;
95
+ onStatus?: (status: DualSignStatus) => void;
96
+ }): Promise<FrostSignResult>;
97
+ }
98
+ /**
99
+ * Native multi-approver FROST lifecycle. Never falls back to a JWT route or creates
100
+ * a new request after an ambiguous POST. All approval and result checks use the
101
+ * original expected message, slot, public key and quorum, not server-selected values.
102
+ *
103
+ * @param input - Trusted slot key, keeper endpoint and required approver policy.
104
+ */
105
+ export declare function createDualSignClient(input: DualSignConfig): {
106
+ create(message: Uint8Array, options?: {
107
+ signal?: AbortSignal;
108
+ }): Promise<DualSignRequest>;
109
+ resume(requestId: string, expectedMessage: Uint8Array): DualSignRequest;
110
+ };
@@ -0,0 +1,202 @@
1
+ import { equalBytes } from '@noble/curves/utils.js';
2
+ import { ed25519 } from '@noble/curves/ed25519';
3
+ import { sha256 } from '@noble/hashes/sha256';
4
+ import { bytesToHex, concatBytes, utf8ToBytes } from '@noble/hashes/utils';
5
+ import { verify } from '../crypto/frost.js';
6
+ import { TasraError, httpError } from '../errors.js';
7
+ import { decodeOperationReceipt, protocolHex } from './receipts.js';
8
+ import { requestHash } from '../oid4vp/binding.js';
9
+ /** A signing request may have been accepted despite a transport or response failure. Reconcile before resubmitting. */
10
+ export class OperationOutcomeUnknownError extends TasraError {
11
+ operation;
12
+ requestId;
13
+ constructor(
14
+ /** Request phase whose submission outcome must be reconciled. */
15
+ operation,
16
+ /** Existing native signing request identifier, when known. */
17
+ requestId, cause) {
18
+ super(`${operation}: outcome unknown; reconcile before submitting again`, { cause });
19
+ this.operation = operation;
20
+ this.requestId = requestId;
21
+ }
22
+ }
23
+ function requestIdentifier(id) {
24
+ if (!/^[A-Za-z0-9_-]{1,128}$/.test(id))
25
+ throw new TasraError('Invalid dual-sign request ID');
26
+ }
27
+ /**
28
+ * Exact existing Rust canonical_dual_sig_payload, including little-endian lengths.
29
+ *
30
+ * @param slotId - 32-byte slot identifier as hexadecimal text.
31
+ * @param message - Original message bytes to authorize.
32
+ * @param requestId - Existing native signing request identifier.
33
+ */
34
+ export function dualSignApprovalPayload(slotId, message, requestId) {
35
+ requestIdentifier(requestId);
36
+ const fields = [protocolHex(slotId, 32, 'slot id'), sha256(message), utf8ToBytes(requestId)];
37
+ return concatBytes(utf8ToBytes('keykeeper:dual-sig:v1'), ...fields.flatMap(value => {
38
+ const size = new Uint8Array(8);
39
+ new DataView(size.buffer).setBigUint64(0, BigInt(value.length), true);
40
+ return [size, value];
41
+ }));
42
+ }
43
+ /**
44
+ * Native multi-approver FROST lifecycle. Never falls back to a JWT route or creates
45
+ * a new request after an ambiguous POST. All approval and result checks use the
46
+ * original expected message, slot, public key and quorum, not server-selected values.
47
+ *
48
+ * @param input - Trusted slot key, keeper endpoint and required approver policy.
49
+ */
50
+ export function createDualSignClient(input) {
51
+ const slot = protocolHex(input.slotId, 32, 'slot id'), key = input.groupPublicKey.slice();
52
+ if (key.length !== 32 || !Number.isSafeInteger(input.quorum) || input.quorum < 1 || !Number.isSafeInteger(input.chainId) || input.chainId <= 0)
53
+ throw new TasraError('Invalid dual-sign chain, key or quorum');
54
+ const nodeUrl = input.nodeUrl.replace(/\/$/, ''), slotId = '0x' + bytesToHex(slot);
55
+ const quorum = input.quorum, chainId = input.chainId, credentialed = input.credentialGated, fetchImpl = input.fetchImpl ?? fetch;
56
+ const timeoutMs = input.timeoutMs ?? 30_000;
57
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0)
58
+ throw new TasraError('Invalid request timeout');
59
+ async function http(path, signal, body, requestId) {
60
+ signal?.throwIfAborted();
61
+ const deadline = AbortSignal.timeout(timeoutMs);
62
+ let response;
63
+ try {
64
+ response = await fetchImpl(nodeUrl + path, { method: body === undefined ? 'GET' : 'POST',
65
+ signal: signal ? AbortSignal.any([signal, deadline]) : deadline,
66
+ headers: { 'Content-Type': 'application/json' }, body: body === undefined ? undefined : JSON.stringify(body) });
67
+ }
68
+ catch (cause) {
69
+ if (body !== undefined)
70
+ throw new OperationOutcomeUnknownError(requestId ? 'dual-approve' : 'dual-create', requestId, cause);
71
+ throw cause;
72
+ }
73
+ if (!response.ok) {
74
+ if (body !== undefined && response.status >= 500)
75
+ throw new OperationOutcomeUnknownError(requestId ? 'dual-approve' : 'dual-create', requestId);
76
+ throw await httpError(response, nodeUrl + path, 'dual-sign');
77
+ }
78
+ try {
79
+ const data = await response.json();
80
+ if (!data || typeof data !== 'object' || Array.isArray(data))
81
+ throw new TasraError('Malformed dual-sign response');
82
+ return data;
83
+ }
84
+ catch (cause) {
85
+ if (body !== undefined)
86
+ throw new OperationOutcomeUnknownError(requestId ? 'dual-approve' : 'dual-create', requestId, cause);
87
+ throw cause;
88
+ }
89
+ }
90
+ function bound(data, message) {
91
+ if (!equalBytes(protocolHex(data.key_slot_id, 32, 'reply slot'), slot) ||
92
+ !equalBytes(protocolHex(data.message_sha256, 32, 'reply message hash'), sha256(message)))
93
+ throw new TasraError('Dual-sign response differs from the approved message or slot');
94
+ }
95
+ function counts(data) {
96
+ if (data.need !== quorum || !Number.isSafeInteger(data.have) || Number(data.have) < 0 || Number(data.have) > quorum)
97
+ throw new TasraError('Invalid dual-sign approval quorum');
98
+ return { have: Number(data.have), need: quorum };
99
+ }
100
+ function signed(value, message) {
101
+ if (!value || typeof value !== 'object')
102
+ throw new TasraError('Missing dual-sign signature');
103
+ const d = value;
104
+ bound(d, message);
105
+ const publicKey = protocolHex(d.group_public_key, 32, 'group public key');
106
+ const signature = { r: protocolHex(d.signature_r, 32, 'signature R'), z: protocolHex(d.signature_z, 32, 'signature z') };
107
+ if (!equalBytes(publicKey, key) || !verify(key, message, signature) || !Number.isSafeInteger(d.epoch) || Number(d.epoch) < 0)
108
+ throw new TasraError('Invalid dual-sign result');
109
+ const receipt = decodeOperationReceipt(d);
110
+ return { keySlotId: slotId, groupPublicKey: publicKey, signature, messageSha256: sha256(message), epoch: Number(d.epoch), ...(receipt ? { receipt } : {}) };
111
+ }
112
+ function handle(requestId, message) {
113
+ requestIdentifier(requestId);
114
+ const original = message.slice(), path = '/v1/dual-sign/' + requestId;
115
+ const status = async (options = {}) => {
116
+ const d = await http(path, options.signal);
117
+ if (d.status === 'signed')
118
+ return { status: 'signed', result: signed(d.reply, original) };
119
+ if (d.status === 'failed')
120
+ return { status: 'failed' };
121
+ if (d.status !== 'pending' && d.status !== 'signing')
122
+ throw new TasraError('Invalid dual-sign status');
123
+ bound(d, original);
124
+ return { status: d.status, ...counts(d) };
125
+ };
126
+ return Object.freeze({ requestId, slotId, nodeUrl, status,
127
+ async approve(options) {
128
+ const before = await status({ signal: options.signal });
129
+ if (before.status !== 'pending')
130
+ return before;
131
+ if (credentialed !== Boolean(options.authorization))
132
+ throw new TasraError('Dual-sign approval authorization does not match the slot policy');
133
+ const publicKey = options.signer.publicKey.slice();
134
+ const payload = dualSignApprovalPayload(slotId, original, requestId);
135
+ const grant = options.authorization && structuredClone(options.authorization);
136
+ if (grant && (!equalBytes(protocolHex(grant.token.slot_id, 32, 'grant slot'), slot) || !grant.verifierProofs.length ||
137
+ grant.token.binding !== 'holder_key' || !Number.isSafeInteger(grant.token.exp) || grant.token.exp * 1000 <= Date.now() ||
138
+ !equalBytes(protocolHex(grant.token.request_hash, 32, 'approval request hash'), requestHash(chainId, slot, 'dual-approve', sha256(payload))))) {
139
+ throw new TasraError('Approval grant must bind this request and holder and include verifier proofs');
140
+ }
141
+ const signature = await options.signer.sign(payload.slice());
142
+ options.signal?.throwIfAborted();
143
+ if (publicKey.length !== 32 || signature.length !== 64 || !ed25519.verify(signature, payload, publicKey, { zip215: false }))
144
+ throw new TasraError('Invalid local approval signature');
145
+ const d = await http(path + '/approve', options.signal, { approver_pubkey: bytesToHex(publicKey), signature: bytesToHex(signature),
146
+ ...(grant ? { committee_token: grant.token, verifier_proofs: grant.verifierProofs.map(p => ({ verifier_index: p.verifierIndex,
147
+ operator: p.operator.replace(/^0x/, ''), pubkey: p.pubkey.replace(/^0x/, ''), proof: p.proof.map(x => x.replace(/^0x/, '')) })) } : {}) }, requestId);
148
+ try {
149
+ const count = counts(d);
150
+ if (d.signed === true && count.have === count.need)
151
+ return { status: 'signed', result: signed(d.reply, original) };
152
+ if (d.signed !== false || d.reply != null)
153
+ throw new TasraError('Invalid dual-sign approval response');
154
+ return { status: 'pending', ...count };
155
+ }
156
+ catch (cause) {
157
+ throw new OperationOutcomeUnknownError('dual-approve', requestId, cause);
158
+ }
159
+ },
160
+ async wait(options = {}) {
161
+ const interval = options.intervalMs ?? 1000, timeout = options.timeoutMs ?? 300_000;
162
+ if (!Number.isSafeInteger(interval) || interval <= 0 || !Number.isSafeInteger(timeout) || timeout <= 0)
163
+ throw new TasraError('Invalid polling interval or timeout');
164
+ const deadline = AbortSignal.timeout(timeout), signal = options.signal ? AbortSignal.any([deadline, options.signal]) : deadline;
165
+ for (;;) {
166
+ signal.throwIfAborted();
167
+ const current = await status({ signal });
168
+ options.onStatus?.(current);
169
+ if (current.status === 'signed')
170
+ return current.result;
171
+ if (current.status === 'failed')
172
+ throw new TasraError('Native dual-sign request failed');
173
+ await new Promise((resolve, reject) => {
174
+ const done = () => { signal.removeEventListener('abort', abort); resolve(); };
175
+ const timer = setTimeout(done, interval);
176
+ const abort = () => { clearTimeout(timer); signal.removeEventListener('abort', abort); reject(signal.reason); };
177
+ signal.addEventListener('abort', abort, { once: true });
178
+ if (signal.aborted)
179
+ abort();
180
+ });
181
+ }
182
+ },
183
+ });
184
+ }
185
+ return {
186
+ async create(message, options = {}) {
187
+ const original = message.slice();
188
+ const d = await http('/v1/dual-sign', options.signal, { key_slot_id: slotId, message_hex: bytesToHex(original) });
189
+ try {
190
+ bound(d, original);
191
+ counts(d);
192
+ if (d.have !== 0 || d.credential_gated !== credentialed || typeof d.request_id !== 'string')
193
+ throw new TasraError('Invalid dual-sign creation reply');
194
+ return handle(d.request_id, original);
195
+ }
196
+ catch (cause) {
197
+ throw new OperationOutcomeUnknownError('dual-create', typeof d.request_id === 'string' ? d.request_id : undefined, cause);
198
+ }
199
+ },
200
+ resume: handle,
201
+ };
202
+ }
@@ -0,0 +1,36 @@
1
+ import type { EoaSignature } from '../signing/ecdsa.js';
2
+ import type { CompoundTokenWire } from './token.js';
3
+ import type { VerifierProof } from './client.js';
4
+ /** Compound authorization, keeper endpoint and digest for threshold ECDSA signing. */
5
+ export interface CommitteeEoaSignOpts {
6
+ /** HTTP transport override; defaults to the global fetch implementation. */
7
+ fetchImpl?: typeof fetch;
8
+ /** Keeper HTTP base URL. */
9
+ nodeUrl: string;
10
+ /** Authorization from awaitVerifierAgentResult; its slot selects the signing key. */
11
+ committeeToken: CompoundTokenWire;
12
+ /** Exactly 32 bytes: the transaction signing hash, not a serialized transaction. */
13
+ digest: Uint8Array;
14
+ /** Membership proofs returned with the authorization. */
15
+ verifierProofs?: VerifierProof[];
16
+ /** Request identifier used to correlate or resume the operation. */
17
+ requestId?: string;
18
+ /** Required only by slots configured with an additional owner-signature gate. */
19
+ userSignature?: Uint8Array;
20
+ /** Optional 20-byte operator address to pin the intended keeper. */
21
+ targetKeykeeper?: string;
22
+ /** Optional signal that cancels the request. */
23
+ signal?: AbortSignal;
24
+ }
25
+ /**
26
+ * Sign an Ethereum digest using credential-based committee authorization.
27
+ * Open the verifier-agent session with action `sign` and message equal to `digest`.
28
+ * The keeper checks the token's request binding against SHA-256(digest), then
29
+ * threshold-signs the original digest. This never falls back to JWT authorization.
30
+ * @returns Ethereum signature components and the secp256k1 group public key.
31
+ * @throws On malformed input/response, network failure, or keeper rejection.
32
+ * HTTP 401/403 is an authorization denial; do not retry it as a network failure.
33
+ *
34
+ * @param opts - Compound authorization, keeper endpoint and 32-byte ECDSA digest.
35
+ */
36
+ export declare function committeeSignEoaDigest(opts: CommitteeEoaSignOpts): Promise<EoaSignature>;
@@ -0,0 +1,45 @@
1
+ import { hexToBytes, bytesToHex } from '../crypto/hex.js';
2
+ import { httpError } from '../errors.js';
3
+ /**
4
+ * Sign an Ethereum digest using credential-based committee authorization.
5
+ * Open the verifier-agent session with action `sign` and message equal to `digest`.
6
+ * The keeper checks the token's request binding against SHA-256(digest), then
7
+ * threshold-signs the original digest. This never falls back to JWT authorization.
8
+ * @returns Ethereum signature components and the secp256k1 group public key.
9
+ * @throws On malformed input/response, network failure, or keeper rejection.
10
+ * HTTP 401/403 is an authorization denial; do not retry it as a network failure.
11
+ *
12
+ * @param opts - Compound authorization, keeper endpoint and 32-byte ECDSA digest.
13
+ */
14
+ export async function committeeSignEoaDigest(opts) {
15
+ if (opts.digest.length !== 32)
16
+ throw new Error('committeeSignEoaDigest: digest must be 32 bytes');
17
+ if (opts.userSignature && opts.userSignature.length !== 64)
18
+ throw new Error('userSignature must be 64 bytes');
19
+ const bare = (hex) => hex.replace(/^0x/, '');
20
+ const body = {
21
+ committee_token: opts.committeeToken,
22
+ digest: bare(bytesToHex(opts.digest)),
23
+ verifier_proofs: opts.verifierProofs?.map(p => ({
24
+ verifier_index: p.verifierIndex, operator: bare(p.operator), pubkey: bare(p.pubkey), proof: p.proof.map(bare),
25
+ })),
26
+ target_keykeeper: opts.targetKeykeeper && bare(opts.targetKeykeeper),
27
+ user_signature: opts.userSignature && bare(bytesToHex(opts.userSignature)),
28
+ };
29
+ const url = `${opts.nodeUrl.replace(/\/$/, '')}/v1/committee/sign/eoa-digest`;
30
+ const response = await (opts.fetchImpl ?? fetch)(url, {
31
+ method: 'POST', headers: { 'Content-Type': 'application/json', ...(opts.requestId ? { 'x-request-id': opts.requestId } : {}) },
32
+ body: JSON.stringify(body), signal: opts.signal,
33
+ });
34
+ if (!response.ok)
35
+ throw await httpError(response, url, 'committee/sign/eoa-digest');
36
+ const data = await response.json();
37
+ const scalar = (value) => typeof value === 'string' && /^(?:0x)?[a-fA-F0-9]{64}$/.test(value);
38
+ if (!data || data.mode !== 'tecdsa' || (data.signature_v !== 0 && data.signature_v !== 1) ||
39
+ !scalar(data.signature_r) || !scalar(data.signature_s) ||
40
+ typeof data.group_public_key !== 'string' || !/^(?:0x)?0[23][a-fA-F0-9]{64}$/.test(data.group_public_key)) {
41
+ throw new Error('committeeSignEoaDigest: invalid secp256k1 signature response');
42
+ }
43
+ return { groupPublicKey: hexToBytes(data.group_public_key), r: hexToBytes(data.signature_r),
44
+ s: hexToBytes(data.signature_s), yParity: data.signature_v };
45
+ }
@@ -0,0 +1,82 @@
1
+ import { type IbeCiphertext } from '../crypto/ibe.js';
2
+ import { type IbeExtractOpts } from './client.js';
3
+ import { type OperationReceipt } from './receipts.js';
4
+ /** Assigned keeper endpoint with independently established operator, key and optional share metadata. */
5
+ export interface ExtractionKeeper {
6
+ /** On-chain assigned operator address. Two URLs cannot count as two operators. */
7
+ operator: string;
8
+ /** Keeper HTTP base URL. */
9
+ nodeUrl: string;
10
+ /** Group share identifier from trusted deployment/slot metadata, when known. */
11
+ identifier?: number;
12
+ /** Authenticated Ed25519 keeper key used to verify operation receipts. */
13
+ publicKey?: Uint8Array;
14
+ /** Independently authenticated G2 verifying share, not copied from the HTTP reply. */
15
+ verifyingShareG2?: Uint8Array;
16
+ }
17
+ /** Expected slot epoch, threshold, chain key and keeper trust requirements for identity-key extraction. */
18
+ export interface StrictExtractionOptions extends Omit<IbeExtractOpts, 'nodeUrls' | 'ciphertextEpoch'> {
19
+ /** EVM chain identifier. */
20
+ chainId: number | bigint;
21
+ /** 32-byte slot identifier. */
22
+ slotId: string;
23
+ /** Minimum number of distinct assigned keeper shares. */
24
+ threshold: number;
25
+ /** Slot key epoch used to match the extraction shares. */
26
+ epoch: number;
27
+ /** Group key pinned to this slot/epoch on chain (96-byte G2). */
28
+ groupPublicKey: Uint8Array;
29
+ /** Assigned keepers with independently established identity and key metadata. */
30
+ keepers: readonly ExtractionKeeper[];
31
+ /**
32
+ * pinned-shares requires an independently authenticated verifying share and identifier
33
+ * for EVERY keeper. anchored-group verifies the final key against chain, but does not
34
+ * claim independent provenance of each returned verifying share.
35
+ */
36
+ shareTrust: 'pinned-shares' | 'anchored-group';
37
+ /** Require a valid operation attestation from every share used. Default false. */
38
+ requireReceipts?: boolean;
39
+ }
40
+ /** Keeper identity, share identifier and receipt verification status for an accepted extraction share. */
41
+ export interface ExtractionEvidence {
42
+ /** Keeper operator address. */
43
+ operator: string;
44
+ /** Nonzero threshold participant identifier. */
45
+ identifier: number;
46
+ /** Keeper HTTP base URL. */
47
+ nodeUrl: string;
48
+ /** Optional keeper attestation; presence alone does not establish validity. */
49
+ receipt?: OperationReceipt;
50
+ /** Whether the receipt is absent, present but unchecked, or verified. */
51
+ receiptStatus: 'absent' | 'unverified' | 'verified';
52
+ }
53
+ /** Extracted identity key and provenance evidence. The caller must clear the returned key when finished. */
54
+ export interface StrictExtractionResult {
55
+ /** Durable identity capability. Caller owns and must clear this buffer when finished. */
56
+ key: Uint8Array;
57
+ /** Slot key epoch used to match the extraction shares. */
58
+ epoch: number;
59
+ /** Trust model used for validating the returned shares. */
60
+ shareTrust: StrictExtractionOptions['shareTrust'];
61
+ /** Provenance and receipt status for every accepted share. */
62
+ evidence: ExtractionEvidence[];
63
+ }
64
+ /**
65
+ * Extract using a distinct assigned quorum, one epoch and the chain-anchored group key.
66
+ * Read slot metadata before calling; this helper deliberately cannot authenticate caller
67
+ * configuration. Never populate pinned shares from the extraction response itself.
68
+ * All temporary partials are cleared even on rejection. No master key is reconstructed.
69
+ *
70
+ * @param input - Expected slot key, epoch, quorum, keepers and authorized identity.
71
+ */
72
+ export declare function extractIdentityStrict(input: StrictExtractionOptions): Promise<StrictExtractionResult>;
73
+ /**
74
+ * Decrypt an IBE ciphertext and clear the intermediate identity key on every exit.
75
+ *
76
+ * @param opts - Strict extraction requirements plus the IBE ciphertext to decrypt.
77
+ */
78
+ export declare function decryptIdentityStrict(opts: StrictExtractionOptions & {
79
+ ciphertext: IbeCiphertext;
80
+ }): Promise<Omit<StrictExtractionResult, 'key'> & {
81
+ plaintext: Uint8Array;
82
+ }>;
@@ -0,0 +1,96 @@
1
+ import { equalBytes } from '@noble/curves/utils.js';
2
+ import { utf8ToBytes } from '@noble/hashes/utils';
3
+ import { sha256 } from '@noble/hashes/sha256';
4
+ import { ibeCombineExtract, ibeDecryptWithKey, ibeVerifyShare } from '../crypto/ibe.js';
5
+ import { TasraError, ThresholdNotMetError } from '../errors.js';
6
+ import { requestIbeExtractionPartials } from './client.js';
7
+ import { compoundTokenHash, decodeCompoundToken } from './token.js';
8
+ import { auditOperationId, protocolHex, verifyOperationReceipt } from './receipts.js';
9
+ /**
10
+ * Extract using a distinct assigned quorum, one epoch and the chain-anchored group key.
11
+ * Read slot metadata before calling; this helper deliberately cannot authenticate caller
12
+ * configuration. Never populate pinned shares from the extraction response itself.
13
+ * All temporary partials are cleared even on rejection. No master key is reconstructed.
14
+ *
15
+ * @param input - Expected slot key, epoch, quorum, keepers and authorized identity.
16
+ */
17
+ export async function extractIdentityStrict(input) {
18
+ input = { ...input, committeeToken: structuredClone(input.committeeToken), verifierProofs: input.verifierProofs && structuredClone(input.verifierProofs), userSignature: input.userSignature?.slice() };
19
+ const slot = protocolHex(input.slotId, 32, 'slot id');
20
+ if (!equalBytes(slot, protocolHex(input.committeeToken.slot_id, 32, 'token slot')))
21
+ throw new TasraError('Extraction token selects another slot');
22
+ if (!Number.isSafeInteger(input.threshold) || input.threshold < 1 || input.threshold > input.keepers.length ||
23
+ !Number.isSafeInteger(input.epoch) || input.epoch < 0 || input.groupPublicKey.length !== 96 ||
24
+ !['pinned-shares', 'anchored-group'].includes(input.shareTrust))
25
+ throw new TasraError('Invalid extraction threshold, epoch, group key or trust mode');
26
+ const group = input.groupPublicKey.slice(), identity = utf8ToBytes(input.identity);
27
+ const keepers = input.keepers.map(k => ({ ...k, operator: k.operator.toLowerCase(),
28
+ publicKey: k.publicKey?.slice(), verifyingShareG2: k.verifyingShareG2?.slice() }));
29
+ for (const k of keepers) {
30
+ protocolHex(k.operator, 20, 'keeper operator');
31
+ if (!k.nodeUrl || k.identifier !== undefined && (!Number.isSafeInteger(k.identifier) || k.identifier < 1 || k.identifier > 65535) ||
32
+ input.shareTrust === 'pinned-shares' && (k.identifier === undefined || k.verifyingShareG2?.length !== 96) ||
33
+ input.requireReceipts && k.publicKey?.length !== 32)
34
+ throw new TasraError('Missing trusted keeper identity, share or receipt key');
35
+ }
36
+ if (new Set(keepers.map(k => k.operator)).size !== keepers.length || new Set(keepers.map(k => k.nodeUrl.replace(/\/$/, ''))).size !== keepers.length) {
37
+ throw new TasraError('Duplicate extraction keeper or endpoint');
38
+ }
39
+ const byUrl = new Map(keepers.map(k => [k.nodeUrl, k]));
40
+ const threshold = input.threshold, epoch = input.epoch, shareTrust = input.shareTrust, required = input.requireReceipts;
41
+ const tokenHash = compoundTokenHash(decodeCompoundToken(input.committeeToken));
42
+ const opId = auditOperationId(slot, 'ibe-extract', tokenHash, sha256(identity));
43
+ const partials = await requestIbeExtractionPartials({ ...input, nodeUrls: keepers.map(k => k.nodeUrl), ciphertextEpoch: epoch });
44
+ let key;
45
+ try {
46
+ input.signal?.throwIfAborted();
47
+ if (partials.length < threshold)
48
+ throw new ThresholdNotMetError({ got: partials.length, need: threshold });
49
+ const ids = new Set(), evidence = [];
50
+ for (const p of partials) {
51
+ const k = byUrl.get(p.nodeUrl);
52
+ if (!k || !Number.isSafeInteger(p.identifier) || p.identifier < 1 || p.identifier > 65535 || ids.has(p.identifier) ||
53
+ p.epoch !== epoch || !equalBytes(protocolHex(p.keySlotId, 32, 'extraction slot'), slot) || p.value.length !== 48 || p.verifyingShareG2.length !== 96 ||
54
+ k.identifier !== undefined && k.identifier !== p.identifier || k.verifyingShareG2 && !equalBytes(k.verifyingShareG2, p.verifyingShareG2)) {
55
+ throw new TasraError('Extraction share has inconsistent slot, epoch, keeper or key provenance');
56
+ }
57
+ ids.add(p.identifier);
58
+ let receiptStatus = p.receipt ? 'unverified' : 'absent';
59
+ if (p.receipt && k.publicKey) {
60
+ if (!verifyOperationReceipt(p.receipt, { chainId: input.chainId, slotId: slot, tokenHash, opId, keeperPublicKey: k.publicKey })) {
61
+ throw new TasraError('Invalid extraction operation receipt');
62
+ }
63
+ receiptStatus = 'verified';
64
+ }
65
+ if (required && receiptStatus !== 'verified')
66
+ throw new TasraError('Verified extraction receipt required');
67
+ evidence.push({ operator: k.operator, identifier: p.identifier, nodeUrl: p.nodeUrl, ...(p.receipt ? { receipt: p.receipt } : {}), receiptStatus });
68
+ }
69
+ key = ibeCombineExtract(new Map(partials.map(p => [p.identifier, p.verifyingShareG2])), partials, identity);
70
+ // Returned shares must combine to the slot's independently anchored master public key.
71
+ ibeVerifyShare(new Map([[1, group]]), identity, { identifier: 1, value: key });
72
+ return { key, epoch, shareTrust, evidence };
73
+ }
74
+ catch (error) {
75
+ key?.fill(0);
76
+ throw error;
77
+ }
78
+ finally {
79
+ for (const p of partials)
80
+ p.value.fill(0);
81
+ }
82
+ }
83
+ /**
84
+ * Decrypt an IBE ciphertext and clear the intermediate identity key on every exit.
85
+ *
86
+ * @param opts - Strict extraction requirements plus the IBE ciphertext to decrypt.
87
+ */
88
+ export async function decryptIdentityStrict(opts) {
89
+ const { key, ...evidence } = await extractIdentityStrict(opts);
90
+ try {
91
+ return { ...evidence, plaintext: ibeDecryptWithKey(key, opts.ciphertext, utf8ToBytes(opts.identity)) };
92
+ }
93
+ finally {
94
+ key.fill(0);
95
+ }
96
+ }
@@ -0,0 +1,19 @@
1
+ export { auditOperationId, decodeOperationReceipt, verifyOperationReceipt } from './receipts.js';
2
+ export type { OperationReceipt, ReceiptExpectation } from './receipts.js';
3
+ export { extractIdentityStrict, decryptIdentityStrict } from './extraction.js';
4
+ export type { StrictExtractionOptions, StrictExtractionResult, ExtractionKeeper, ExtractionEvidence } from './extraction.js';
5
+ export { createDualSignClient, dualSignApprovalPayload, OperationOutcomeUnknownError } from './dual-sign.js';
6
+ export type { DualSignConfig, DualSignApprover, DualSignRequest, DualSignStatus } from './dual-sign.js';
7
+ export { committeeSignEoaDigest } from './ecdsa.js';
8
+ export type { CommitteeEoaSignOpts } from './ecdsa.js';
9
+ export { selectVerifierCommittee, compoundTokenCanonicalBytes, compoundTokenHash, opAttestationHash, clientBindingHash, verifierLeaf, verifyMerkleProof, merkleRoot, merkleProof, verifyCompoundToken, assembleCompoundToken, decodeCompoundToken, evidenceBindingMessage, verifyEvidenceBinding, } from './token.js';
10
+ export type { TokenType, CompoundTokenPayload, CommitteeSignature, VerifierSet, VerifiedToken, VerifyCompoundTokenOptions, CompoundTokenWire, CommitteeSignatureWire, VerifyEvidenceBindingOptions, } from './token.js';
11
+ export { committeeAuthorize, gatherCommitteeToken, committeeSign, committeeDecrypt, CommitteeAuthorizeError, } from './client.js';
12
+ export type { CommitteeAuthorizeBody, CommitteeAuthorizeReply, GatherCommitteeTokenOpts, CommitteeSignOpts, CommitteeDecryptOpts, VerifierProof, } from './client.js';
13
+ export { requestCommitteeToken, committeeSignRequest, committeeDecryptRequest, buildVerifierProofs, committeeChainReadsFromClient, ed25519ClientSigner, holderProofPerVerifier, } from './request.js';
14
+ export type { CommitteeVerifier, CommitteeChainReads, HolderProofPerVerifier, RequestCommitteeTokenOpts, CommitteeTokenResult, CommitteeSignRequestOpts, CommitteeDecryptRequestOpts, ClientSigner, } from './request.js';
15
+ export { requestIbeExtractionPartials } from './client.js';
16
+ export type { IbeExtractOpts, IbeExtractionPartial } from './client.js';
17
+ export { ibeExtractRequest, ibeDecryptRequest } from './request.js';
18
+ export type { IbeExtractRequestOpts } from './request.js';
19
+ export { platformAudience, dpopHtu, normalizeOrigin, isValidSessionId, OAUTH_RESPONSE_PATH_PREFIX, OAUTH_RESPONSE_PATH_SUFFIX, MAX_SESSION_ID_LEN, } from './oauth.js';
@@ -0,0 +1,13 @@
1
+ // compound committee authorization - token crypto + HTTP orchestration.
2
+ export { auditOperationId, decodeOperationReceipt, verifyOperationReceipt } from './receipts.js';
3
+ export { extractIdentityStrict, decryptIdentityStrict } from './extraction.js';
4
+ export { createDualSignClient, dualSignApprovalPayload, OperationOutcomeUnknownError } from './dual-sign.js';
5
+ export { committeeSignEoaDigest } from './ecdsa.js';
6
+ export { selectVerifierCommittee, compoundTokenCanonicalBytes, compoundTokenHash, opAttestationHash, clientBindingHash, verifierLeaf, verifyMerkleProof, merkleRoot, merkleProof, verifyCompoundToken, assembleCompoundToken, decodeCompoundToken, evidenceBindingMessage, verifyEvidenceBinding, } from './token.js';
7
+ export { committeeAuthorize, gatherCommitteeToken, committeeSign, committeeDecrypt, CommitteeAuthorizeError, } from './client.js';
8
+ export { requestCommitteeToken, committeeSignRequest, committeeDecryptRequest, buildVerifierProofs, committeeChainReadsFromClient, ed25519ClientSigner, holderProofPerVerifier, } from './request.js';
9
+ // identity-key extraction
10
+ export { requestIbeExtractionPartials } from './client.js';
11
+ export { ibeExtractRequest, ibeDecryptRequest } from './request.js';
12
+ // Derived OAuth audience + DPoP htu
13
+ export { platformAudience, dpopHtu, normalizeOrigin, isValidSessionId, OAUTH_RESPONSE_PATH_PREFIX, OAUTH_RESPONSE_PATH_SUFFIX, MAX_SESSION_ID_LEN, } from './oauth.js';