@grantex/sdk 0.6.0 → 0.7.0

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 (181) hide show
  1. package/LICENSE +185 -185
  2. package/NOTICE +16 -16
  3. package/README.md +974 -947
  4. package/dist/authorization-details.d.ts +86 -0
  5. package/dist/authorization-details.d.ts.map +1 -0
  6. package/dist/authorization-details.js +209 -0
  7. package/dist/authorization-details.js.map +1 -0
  8. package/dist/canonical.d.ts +47 -0
  9. package/dist/canonical.d.ts.map +1 -0
  10. package/dist/canonical.js +163 -0
  11. package/dist/canonical.js.map +1 -0
  12. package/dist/caps/index.d.ts +19 -0
  13. package/dist/caps/index.d.ts.map +1 -0
  14. package/dist/caps/index.js +19 -0
  15. package/dist/caps/index.js.map +1 -0
  16. package/dist/caps/limits.d.ts +40 -0
  17. package/dist/caps/limits.d.ts.map +1 -0
  18. package/dist/caps/limits.js +109 -0
  19. package/dist/caps/limits.js.map +1 -0
  20. package/dist/caps/memory.d.ts +15 -0
  21. package/dist/caps/memory.d.ts.map +1 -0
  22. package/dist/caps/memory.js +57 -0
  23. package/dist/caps/memory.js.map +1 -0
  24. package/dist/caps/meter.d.ts +107 -0
  25. package/dist/caps/meter.d.ts.map +1 -0
  26. package/dist/caps/meter.js +200 -0
  27. package/dist/caps/meter.js.map +1 -0
  28. package/dist/caps/postgres.d.ts +64 -0
  29. package/dist/caps/postgres.d.ts.map +1 -0
  30. package/dist/caps/postgres.js +221 -0
  31. package/dist/caps/postgres.js.map +1 -0
  32. package/dist/caps/redis.d.ts +45 -0
  33. package/dist/caps/redis.d.ts.map +1 -0
  34. package/dist/caps/redis.js +173 -0
  35. package/dist/caps/redis.js.map +1 -0
  36. package/dist/client.d.ts +12 -0
  37. package/dist/client.d.ts.map +1 -1
  38. package/dist/client.js +517 -57
  39. package/dist/client.js.map +1 -1
  40. package/dist/decisions/action.d.ts +51 -0
  41. package/dist/decisions/action.d.ts.map +1 -0
  42. package/dist/decisions/action.js +237 -0
  43. package/dist/decisions/action.js.map +1 -0
  44. package/dist/decisions/index.d.ts +11 -0
  45. package/dist/decisions/index.d.ts.map +1 -0
  46. package/dist/decisions/index.js +8 -0
  47. package/dist/decisions/index.js.map +1 -0
  48. package/dist/decisions/verify.d.ts +103 -0
  49. package/dist/decisions/verify.d.ts.map +1 -0
  50. package/dist/decisions/verify.js +277 -0
  51. package/dist/decisions/verify.js.map +1 -0
  52. package/dist/denials.d.ts +132 -0
  53. package/dist/denials.d.ts.map +1 -0
  54. package/dist/denials.js +129 -0
  55. package/dist/denials.js.map +1 -0
  56. package/dist/evidence/build.d.ts +63 -0
  57. package/dist/evidence/build.d.ts.map +1 -0
  58. package/dist/evidence/build.js +201 -0
  59. package/dist/evidence/build.js.map +1 -0
  60. package/dist/evidence/canonical.d.ts +3 -0
  61. package/dist/evidence/canonical.d.ts.map +1 -0
  62. package/dist/evidence/canonical.js +3 -0
  63. package/dist/evidence/canonical.js.map +1 -0
  64. package/dist/evidence/checks.d.ts +13 -0
  65. package/dist/evidence/checks.d.ts.map +1 -0
  66. package/dist/evidence/checks.js +406 -0
  67. package/dist/evidence/checks.js.map +1 -0
  68. package/dist/evidence/document.d.ts +8 -0
  69. package/dist/evidence/document.d.ts.map +1 -0
  70. package/dist/evidence/document.js +298 -0
  71. package/dist/evidence/document.js.map +1 -0
  72. package/dist/evidence/hashing.d.ts +37 -0
  73. package/dist/evidence/hashing.d.ts.map +1 -0
  74. package/dist/evidence/hashing.js +106 -0
  75. package/dist/evidence/hashing.js.map +1 -0
  76. package/dist/evidence/index.d.ts +24 -0
  77. package/dist/evidence/index.d.ts.map +1 -0
  78. package/dist/evidence/index.js +24 -0
  79. package/dist/evidence/index.js.map +1 -0
  80. package/dist/evidence/result.d.ts +88 -0
  81. package/dist/evidence/result.d.ts.map +1 -0
  82. package/dist/evidence/result.js +88 -0
  83. package/dist/evidence/result.js.map +1 -0
  84. package/dist/evidence/schema-1.0.d.ts +2 -0
  85. package/dist/evidence/schema-1.0.d.ts.map +1 -0
  86. package/dist/evidence/schema-1.0.js +1398 -0
  87. package/dist/evidence/schema-1.0.js.map +1 -0
  88. package/dist/evidence/schema.d.ts +13 -0
  89. package/dist/evidence/schema.d.ts.map +1 -0
  90. package/dist/evidence/schema.js +264 -0
  91. package/dist/evidence/schema.js.map +1 -0
  92. package/dist/evidence/signature.d.ts +23 -0
  93. package/dist/evidence/signature.d.ts.map +1 -0
  94. package/dist/evidence/signature.js +136 -0
  95. package/dist/evidence/signature.js.map +1 -0
  96. package/dist/evidence/trace.d.ts +23 -0
  97. package/dist/evidence/trace.d.ts.map +1 -0
  98. package/dist/evidence/trace.js +69 -0
  99. package/dist/evidence/trace.js.map +1 -0
  100. package/dist/evidence/verify.d.ts +29 -0
  101. package/dist/evidence/verify.d.ts.map +1 -0
  102. package/dist/evidence/verify.js +163 -0
  103. package/dist/evidence/verify.js.map +1 -0
  104. package/dist/http.d.ts +12 -1
  105. package/dist/http.d.ts.map +1 -1
  106. package/dist/http.js +11 -5
  107. package/dist/http.js.map +1 -1
  108. package/dist/index.d.ts +16 -3
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +16 -2
  111. package/dist/index.js.map +1 -1
  112. package/dist/manifest.d.ts +178 -9
  113. package/dist/manifest.d.ts.map +1 -1
  114. package/dist/manifest.js +379 -16
  115. package/dist/manifest.js.map +1 -1
  116. package/dist/purpose.d.ts +29 -0
  117. package/dist/purpose.d.ts.map +1 -0
  118. package/dist/purpose.js +60 -0
  119. package/dist/purpose.js.map +1 -0
  120. package/dist/resources/agents.js +3 -3
  121. package/dist/resources/agents.js.map +1 -1
  122. package/dist/resources/anomalies.d.ts +3 -1
  123. package/dist/resources/anomalies.d.ts.map +1 -1
  124. package/dist/resources/anomalies.js +7 -1
  125. package/dist/resources/anomalies.js.map +1 -1
  126. package/dist/resources/audit.js +1 -1
  127. package/dist/resources/audit.js.map +1 -1
  128. package/dist/resources/budgets.js +2 -2
  129. package/dist/resources/budgets.js.map +1 -1
  130. package/dist/resources/credentials.js +1 -1
  131. package/dist/resources/credentials.js.map +1 -1
  132. package/dist/resources/decisions.d.ts +69 -0
  133. package/dist/resources/decisions.d.ts.map +1 -0
  134. package/dist/resources/decisions.js +115 -0
  135. package/dist/resources/decisions.js.map +1 -0
  136. package/dist/resources/domains.js +2 -2
  137. package/dist/resources/domains.js.map +1 -1
  138. package/dist/resources/dpdp.js +4 -4
  139. package/dist/resources/dpdp.js.map +1 -1
  140. package/dist/resources/grants.js +2 -2
  141. package/dist/resources/grants.js.map +1 -1
  142. package/dist/resources/policies.js +3 -3
  143. package/dist/resources/policies.js.map +1 -1
  144. package/dist/resources/scim.js +5 -5
  145. package/dist/resources/scim.js.map +1 -1
  146. package/dist/resources/tokens.d.ts.map +1 -1
  147. package/dist/resources/tokens.js +5 -1
  148. package/dist/resources/tokens.js.map +1 -1
  149. package/dist/resources/vault.js +2 -2
  150. package/dist/resources/vault.js.map +1 -1
  151. package/dist/resources/webauthn.d.ts +6 -1
  152. package/dist/resources/webauthn.d.ts.map +1 -1
  153. package/dist/resources/webauthn.js +5 -1
  154. package/dist/resources/webauthn.js.map +1 -1
  155. package/dist/resources/webhooks.js +1 -1
  156. package/dist/resources/webhooks.js.map +1 -1
  157. package/dist/revocations/feed.d.ts +61 -0
  158. package/dist/revocations/feed.d.ts.map +1 -0
  159. package/dist/revocations/feed.js +282 -0
  160. package/dist/revocations/feed.js.map +1 -0
  161. package/dist/revocations/index.d.ts +20 -0
  162. package/dist/revocations/index.d.ts.map +1 -0
  163. package/dist/revocations/index.js +19 -0
  164. package/dist/revocations/index.js.map +1 -0
  165. package/dist/revocations/set.d.ts +59 -0
  166. package/dist/revocations/set.d.ts.map +1 -0
  167. package/dist/revocations/set.js +87 -0
  168. package/dist/revocations/set.js.map +1 -0
  169. package/dist/scopes.d.ts +26 -0
  170. package/dist/scopes.d.ts.map +1 -0
  171. package/dist/scopes.js +37 -0
  172. package/dist/scopes.js.map +1 -0
  173. package/dist/types.d.ts +121 -4
  174. package/dist/types.d.ts.map +1 -1
  175. package/dist/types.js +0 -1
  176. package/dist/types.js.map +1 -1
  177. package/dist/verify.d.ts +31 -2
  178. package/dist/verify.d.ts.map +1 -1
  179. package/dist/verify.js +236 -29
  180. package/dist/verify.js.map +1 -1
  181. package/package.json +92 -84
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Offline verification of decision grants (PRD G-3).
3
+ *
4
+ * Verification proves that a decision grant is authentic, unexpired and
5
+ * approves exactly the action about to be performed on the current case
6
+ * version, and, for four eyes, that two different people approved it. It does
7
+ * not prove that the grant has not been used: that needs the issuer's atomic
8
+ * consumption (`grantex.decisions.consume()`), which `enforce()` performs
9
+ * before it allows the call. The Python SDK implements the same rules
10
+ * (`grantex.decisions`); the token profile is `spec/decision-grant.md`.
11
+ */
12
+ import { createRemoteJWKSet, decodeProtectedHeader, jwtVerify } from 'jose';
13
+ import { DecisionSubReason } from '../denials.js';
14
+ import { ActionValidationError, computeActionHash, isActionHash, parseDecisionAction } from './action.js';
15
+ export const DECISION_GRANT_TYP = 'decision+jwt';
16
+ export const DECISION_GRANT_AUDIENCE = 'urn:grantex:decision';
17
+ const JTI_RE = /^dgnt_[0-9A-HJKMNP-TV-Z]{26}$/;
18
+ const MAX_TOKEN_LENGTH = 16_384;
19
+ /** A decision grant is absent, unusable or does not match the call. */
20
+ export class DecisionGrantError extends Error {
21
+ subReason;
22
+ constructor(subReason, message) {
23
+ super(message);
24
+ this.name = 'DecisionGrantError';
25
+ this.subReason = subReason;
26
+ }
27
+ }
28
+ const MAX_JWKS_RESOLVERS = 64;
29
+ const jwksResolvers = new Map();
30
+ function remoteKey(jwksUri) {
31
+ const url = new URL(jwksUri);
32
+ url.hash = '';
33
+ const cached = jwksResolvers.get(url.href);
34
+ if (cached)
35
+ return cached;
36
+ const resolver = createRemoteJWKSet(url);
37
+ if (jwksResolvers.size >= MAX_JWKS_RESOLVERS) {
38
+ const oldest = jwksResolvers.keys().next().value;
39
+ if (oldest !== undefined)
40
+ jwksResolvers.delete(oldest);
41
+ }
42
+ jwksResolvers.set(url.href, resolver);
43
+ return resolver;
44
+ }
45
+ function toAction(value) {
46
+ try {
47
+ return parseDecisionAction(value);
48
+ }
49
+ catch (err) {
50
+ if (err instanceof ActionValidationError) {
51
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, `expected action is invalid: ${err.message}`);
52
+ }
53
+ throw err;
54
+ }
55
+ }
56
+ function claimString(payload, key) {
57
+ const value = payload[key];
58
+ if (typeof value !== 'string' || value.length === 0) {
59
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, `decision grant claim ${key} is missing`);
60
+ }
61
+ return value;
62
+ }
63
+ function claimInt(payload, key) {
64
+ const value = payload[key];
65
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0) {
66
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, `decision grant claim ${key} is invalid`);
67
+ }
68
+ return value;
69
+ }
70
+ function parseFourEyes(value) {
71
+ if (value === undefined)
72
+ return undefined;
73
+ const v = value;
74
+ if (typeof value !== 'object' || value === null || Array.isArray(value) || v['approvals_required'] !== 2 || (v['position'] !== 1 && v['position'] !== 2)) {
75
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant four_eyes is invalid');
76
+ }
77
+ const firstJti = v['first_jti'];
78
+ const firstSub = v['first_sub'];
79
+ if (v['position'] === 2 && (typeof firstJti !== 'string' || typeof firstSub !== 'string')) {
80
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'the second approval must name the first');
81
+ }
82
+ return {
83
+ approvalsRequired: 2,
84
+ position: v['position'],
85
+ ...(typeof firstJti === 'string' ? { firstJti } : {}),
86
+ ...(typeof firstSub === 'string' ? { firstSub } : {}),
87
+ };
88
+ }
89
+ /**
90
+ * Verifies one decision grant against the action about to be performed.
91
+ * Refusals (`DecisionGrantError.subReason`): `malformed` (type, signature,
92
+ * issuer, audience, claims, or an `action_hash` that is not the hash of the
93
+ * `action` claim), `unknown_grant` (another developer), `wrong_case`,
94
+ * `action_mismatch` (another action or connector), `case_changed`, `expired`.
95
+ * Single use is not checked here.
96
+ */
97
+ export async function verifyDecisionGrant(token, expectedAction, caseVersion, options) {
98
+ if (typeof token !== 'string' || token.length === 0 || token.length > MAX_TOKEN_LENGTH) {
99
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant must be a compact JWT');
100
+ }
101
+ const expected = toAction(expectedAction);
102
+ if (typeof caseVersion !== 'string' || caseVersion.length === 0) {
103
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'caseVersion is required');
104
+ }
105
+ const algorithms = (options.algorithms ?? ['RS256', 'ES256']).filter((a) => a === 'RS256' || a === 'ES256');
106
+ let header;
107
+ try {
108
+ header = decodeProtectedHeader(token);
109
+ }
110
+ catch {
111
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant is not a JWT');
112
+ }
113
+ if (header.typ !== DECISION_GRANT_TYP) {
114
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, `decision grant typ must be ${DECISION_GRANT_TYP}`);
115
+ }
116
+ if (typeof header.kid !== 'string' || header.kid.length === 0) {
117
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant has no kid');
118
+ }
119
+ if (typeof header.alg !== 'string' || !algorithms.includes(header.alg)) {
120
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, `decision grant algorithm ${String(header.alg)} is not allowed`);
121
+ }
122
+ const key = options.key ?? (options.jwksUri !== undefined ? remoteKey(options.jwksUri) : undefined);
123
+ if (key === undefined)
124
+ throw new Error('verifyDecisionGrant needs jwksUri or key');
125
+ let payload;
126
+ try {
127
+ const verifyOptions = {
128
+ issuer: options.issuer,
129
+ audience: DECISION_GRANT_AUDIENCE,
130
+ algorithms,
131
+ typ: DECISION_GRANT_TYP,
132
+ requiredClaims: ['iss', 'aud', 'sub', 'jti', 'iat', 'exp'],
133
+ // Time is checked below against `now`, after the signature.
134
+ currentDate: new Date(0),
135
+ };
136
+ ({ payload } = typeof key === 'function'
137
+ ? await jwtVerify(token, key, verifyOptions)
138
+ : await jwtVerify(token, key, verifyOptions));
139
+ }
140
+ catch (err) {
141
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, `decision grant signature, issuer or audience is invalid: ${err instanceof Error ? err.message : 'verification failed'}`);
142
+ }
143
+ const jti = claimString(payload, 'jti');
144
+ if (!JTI_RE.test(jti))
145
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant jti is malformed');
146
+ let action;
147
+ try {
148
+ action = parseDecisionAction(payload['action']);
149
+ }
150
+ catch {
151
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant action is malformed');
152
+ }
153
+ const actionHash = claimString(payload, 'action_hash');
154
+ if (!isActionHash(actionHash) || computeActionHash(action) !== actionHash) {
155
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant action_hash does not match its action');
156
+ }
157
+ const amr = payload['amr'];
158
+ if (!Array.isArray(amr) || !amr.every((v) => typeof v === 'string')) {
159
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant amr is invalid');
160
+ }
161
+ const acr = payload['acr'];
162
+ if (acr !== undefined && typeof acr !== 'string') {
163
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant acr is invalid');
164
+ }
165
+ if (payload['dwell_source'] !== 'server') {
166
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant dwell time was not measured by the issuer');
167
+ }
168
+ const memoHash = claimString(payload, 'memo_hash');
169
+ const policyScoreHash = claimString(payload, 'policy_score_hash');
170
+ if (!isActionHash(memoHash) || !isActionHash(policyScoreHash)) {
171
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant memo or policy score hash is malformed');
172
+ }
173
+ const iat = claimInt(payload, 'iat');
174
+ const exp = claimInt(payload, 'exp');
175
+ if (exp <= iat || exp - iat > 86_400) {
176
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant lifetime exceeds 24 hours');
177
+ }
178
+ const memoRef = payload['memo_ref'];
179
+ const policyScoreRef = payload['policy_score_ref'];
180
+ const fourEyes = parseFourEyes(payload['four_eyes']);
181
+ const grant = {
182
+ token,
183
+ jti,
184
+ iss: claimString(payload, 'iss'),
185
+ sub: claimString(payload, 'sub'),
186
+ dev: claimString(payload, 'dev'),
187
+ idp: claimString(payload, 'idp'),
188
+ approverAuth: claimString(payload, 'approver_auth'),
189
+ ...(typeof acr === 'string' ? { acr } : {}),
190
+ amr: amr,
191
+ authTime: claimInt(payload, 'auth_time'),
192
+ action,
193
+ actionHash,
194
+ connector: claimString(payload, 'connector'),
195
+ caseVersion: claimString(payload, 'case_version'),
196
+ dwellMs: claimInt(payload, 'dwell_ms'),
197
+ dwellSource: 'server',
198
+ decisionRequest: claimString(payload, 'decision_request'),
199
+ memoHash,
200
+ policyScoreHash,
201
+ iat,
202
+ exp,
203
+ ...(typeof memoRef === 'string' ? { memoRef } : {}),
204
+ ...(typeof policyScoreRef === 'string' ? { policyScoreRef } : {}),
205
+ ...(fourEyes !== undefined ? { fourEyes } : {}),
206
+ };
207
+ if (options.developerId !== undefined && grant.dev !== options.developerId) {
208
+ throw new DecisionGrantError(DecisionSubReason.UNKNOWN_GRANT, 'decision grant was issued to another developer');
209
+ }
210
+ if (grant.action.case_id !== expected.case_id) {
211
+ throw new DecisionGrantError(DecisionSubReason.WRONG_CASE, 'decision grant is for another case');
212
+ }
213
+ if (grant.actionHash !== computeActionHash(expected)) {
214
+ throw new DecisionGrantError(DecisionSubReason.ACTION_MISMATCH, 'decision grant approves a different action');
215
+ }
216
+ if (options.connector !== undefined && grant.connector !== options.connector) {
217
+ throw new DecisionGrantError(DecisionSubReason.ACTION_MISMATCH, 'decision grant approves an action on another connector');
218
+ }
219
+ if (grant.caseVersion !== caseVersion) {
220
+ throw new DecisionGrantError(DecisionSubReason.CASE_CHANGED, 'decision grant was approved for another case version');
221
+ }
222
+ const now = options.now ?? Math.floor(Date.now() / 1000);
223
+ const tolerance = options.clockTolerance ?? 0;
224
+ if (grant.iat > now + tolerance + 60) {
225
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grant is issued in the future');
226
+ }
227
+ if (now >= grant.exp + tolerance) {
228
+ throw new DecisionGrantError(DecisionSubReason.EXPIRED, 'decision grant has expired');
229
+ }
230
+ return grant;
231
+ }
232
+ /**
233
+ * Verifies the decision grants for one action, including four eyes: with two
234
+ * approvals required (from the manifest, or because a grant says so) exactly
235
+ * two grants with different `sub` are needed, the second naming the first.
236
+ */
237
+ export async function verifyDecisionGrants(tokens, expectedAction, caseVersion, options) {
238
+ const approvalsRequired = options.approvalsRequired ?? 1;
239
+ if (approvalsRequired !== 1 && approvalsRequired !== 2)
240
+ throw new Error('approvalsRequired must be 1 or 2');
241
+ if (!Array.isArray(tokens)) {
242
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'decision grants must be an array of tokens');
243
+ }
244
+ if (tokens.length === 0)
245
+ throw new DecisionGrantError(DecisionSubReason.ABSENT, 'no decision grant was presented');
246
+ if (tokens.length > 2)
247
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'at most two decision grants can be presented');
248
+ const expected = toAction(expectedAction);
249
+ const grants = [];
250
+ for (const token of tokens)
251
+ grants.push(await verifyDecisionGrant(token, expected, caseVersion, options));
252
+ const required = grants.some((g) => g.fourEyes !== undefined) ? 2 : approvalsRequired;
253
+ if (new Set(grants.map((g) => g.jti)).size !== grants.length) {
254
+ throw new DecisionGrantError(DecisionSubReason.SAME_APPROVER, 'the same decision grant was presented twice');
255
+ }
256
+ if (grants.length < required) {
257
+ throw new DecisionGrantError(DecisionSubReason.FOUR_EYES_INCOMPLETE, 'this decision needs two approvals from different people');
258
+ }
259
+ if (grants.length > required) {
260
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'more decision grants than this decision needs');
261
+ }
262
+ let ordered = grants;
263
+ if (required === 2) {
264
+ const [first, second] = [...grants].sort((a, b) => (a.fourEyes?.position ?? 0) - (b.fourEyes?.position ?? 0));
265
+ if (first.sub === second.sub) {
266
+ throw new DecisionGrantError(DecisionSubReason.SAME_APPROVER, 'both decision grants were approved by the same person');
267
+ }
268
+ if (first.fourEyes?.position !== 1 || second.fourEyes?.position !== 2
269
+ || second.fourEyes.firstJti !== first.jti || second.fourEyes.firstSub !== first.sub
270
+ || first.decisionRequest !== second.decisionRequest) {
271
+ throw new DecisionGrantError(DecisionSubReason.MALFORMED, 'the second approval does not reference the first');
272
+ }
273
+ ordered = [first, second];
274
+ }
275
+ return { grants: ordered, action: expected, actionHash: computeActionHash(expected), caseVersion, approvalsRequired: required };
276
+ }
277
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/decisions/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,SAAS,EAAyC,MAAM,MAAM,CAAC;AACnH,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,EAAE,mBAAmB,EAAuB,MAAM,aAAa,CAAC;AAE/H,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AACjD,MAAM,CAAC,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;AAE9D,MAAM,MAAM,GAAG,+BAA+B,CAAC;AAC/C,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,uEAAuE;AACvE,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,SAAS,CAAoB;IACtC,YAAY,SAA4B,EAAE,OAAe;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AA0ED,MAAM,kBAAkB,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M,IAAI,kBAAkB,CAAC,iBAAiB,CAAC,aAAa,EAAE,uDAAuD,CAAC,CAAC;QACzH,CAAC;QACD,IAAI,KAAK,CAAC,QAAQ,EAAE,QAAQ,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,QAAQ,KAAK,CAAC;eAC9D,MAAM,CAAC,QAAQ,CAAC,QAAQ,KAAK,KAAK,CAAC,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,KAAK,KAAK,CAAC,GAAG;eAChF,KAAK,CAAC,eAAe,KAAK,MAAM,CAAC,eAAe,EAAE,CAAC;YACxD,MAAM,IAAI,kBAAkB,CAAC,iBAAiB,CAAC,SAAS,EAAE,kDAAkD,CAAC,CAAC;QAChH,CAAC;QACD,OAAO,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC;AAClI,CAAC"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Denial taxonomy for `enforce()` (PRD Appendix B).
3
+ *
4
+ * Every denied `EnforceResult` carries a `reasonCode` and, where one applies,
5
+ * a `subReason`. `reason` stays a human-readable sentence; code against
6
+ * `reasonCode`. The codes are stable, low-cardinality strings suitable for
7
+ * metric labels and audit records, identical to the Python SDK's.
8
+ */
9
+ export declare const DenialReason: {
10
+ /** The grant's purpose matches none of the tool's `allowed_purposes`, or it has none. */
11
+ readonly PURPOSE_NOT_ALLOWED: 'purpose_not_allowed';
12
+ /** No scope in the grant covers the connector or tool. */
13
+ readonly TOOL_NOT_GRANTED: 'tool_not_granted';
14
+ /** A scope covers the connector but at a lower permission level. */
15
+ readonly PERMISSION_INSUFFICIENT: 'permission_insufficient';
16
+ /** A call cap, cost-unit budget or amount cap would be exceeded, or cannot be evaluated. */
17
+ readonly CAP_EXCEEDED: 'cap_exceeded';
18
+ /** The tool declares `requires_decision` and no decision grant was given. */
19
+ readonly DECISION_REQUIRED: 'decision_required';
20
+ /** A decision grant was given but is not valid for this action. */
21
+ readonly DECISION_INVALID: 'decision_invalid';
22
+ /** The grant has been revoked. */
23
+ readonly GRANT_REVOKED: 'grant_revoked';
24
+ /** The grant's data region does not permit this call. */
25
+ readonly REGION_MISMATCH: 'region_mismatch';
26
+ /** No manifest is loaded for the connector, or it does not declare the tool. */
27
+ readonly MANIFEST_UNKNOWN_TOOL: 'manifest_unknown_tool';
28
+ /** The grant token failed verification. Not part of Appendix B, which assumes a verified grant. */
29
+ readonly TOKEN_INVALID: 'token_invalid';
30
+ };
31
+ export type DenialReason = (typeof DenialReason)[keyof typeof DenialReason];
32
+ /** Sub-reasons for `manifest_unknown_tool`. */
33
+ export declare const ManifestSubReason: {
34
+ readonly UNKNOWN_CONNECTOR: 'unknown_connector';
35
+ readonly UNKNOWN_TOOL: 'unknown_tool';
36
+ readonly INVALID_DECLARATION: 'invalid_declaration';
37
+ };
38
+ /** Sub-reasons for `cap_exceeded`. */
39
+ export declare const CapSubReason: {
40
+ /** `amount` is above a `capped:N` scope. */
41
+ readonly AMOUNT_CAP: 'amount_cap';
42
+ /** `amount` is not a finite number. */
43
+ readonly INVALID_AMOUNT: 'invalid_amount';
44
+ /** A `capped:N` scope carries a malformed cap. */
45
+ readonly MALFORMED_CAP: 'malformed_cap';
46
+ /** The tool declares caps or cost units and they cannot be metered: no meter, or its backend is unavailable. */
47
+ readonly METER_UNAVAILABLE: 'meter_unavailable';
48
+ /**
49
+ * A call cap or cost-unit budget would be exceeded (error code E1008). `details`
50
+ * carries `code`, `limit`, `window`, `used`, `requested`, `scope` and `kind`.
51
+ */
52
+ readonly LIMIT_REACHED: 'limit_reached';
53
+ /** A per-case cap applies and no `caseId` was given. */
54
+ readonly CASE_REQUIRED: 'case_required';
55
+ readonly INVALID_CASE_ID: 'invalid_case_id';
56
+ /** `costComponents` names a unit the tool does not declare. */
57
+ readonly INVALID_COST_COMPONENT: 'invalid_cost_component';
58
+ };
59
+ /** Sub-reasons for `purpose_not_allowed`. */
60
+ export declare const PurposeSubReason: {
61
+ /** The grant carries no purpose. */
62
+ readonly MISSING: 'missing';
63
+ /** The grant's purpose matches none of the tool's patterns. */
64
+ readonly NOT_MATCHED: 'not_matched';
65
+ /** The grant's purpose is malformed or not in the purpose vocabulary. */
66
+ readonly UNKNOWN_PURPOSE: 'unknown_purpose';
67
+ };
68
+ /** Sub-reasons for `tool_not_granted`. */
69
+ export declare const ToolSubReason: {
70
+ /** The grant's tools entry for the connector does not list the tool. */
71
+ readonly NOT_IN_AUTHORIZATION_DETAILS: 'not_in_authorization_details';
72
+ };
73
+ /**
74
+ * Sub-reasons for `grant_revoked` (PRD G-6). A call is denied both when the
75
+ * grant is known to be revoked and when the client cannot tell: an SDK that
76
+ * has lost the revocation feed must not keep authorising calls.
77
+ */
78
+ export declare const RevocationSubReason: {
79
+ /** The auth service says this grant or token is revoked. */
80
+ readonly REVOKED: 'revoked';
81
+ /** The grant is suspended: revoked reversibly, pending a decision. */
82
+ readonly SUSPENDED: 'suspended';
83
+ /** A grant above this one in the delegation chain is revoked or suspended. */
84
+ readonly PARENT_REVOKED: 'parent_revoked';
85
+ /** The revocation feed has not heard from the auth service inside its staleness bound. */
86
+ readonly FEED_STALE: 'feed_stale';
87
+ /** The deployment does not serve the revocation feed, or it is not ready. */
88
+ readonly FEED_UNAVAILABLE: 'feed_unavailable';
89
+ /** An online revocation check could not be completed. */
90
+ readonly STATUS_UNAVAILABLE: 'status_unavailable';
91
+ };
92
+ export type RevocationSubReason = (typeof RevocationSubReason)[keyof typeof RevocationSubReason];
93
+ /** Sub-reasons for `token_invalid`. */
94
+ export declare const TokenSubReason: {
95
+ /** The `authorization_details` claim cannot be read unambiguously. */
96
+ readonly MALFORMED_AUTHORIZATION_DETAILS: 'malformed_authorization_details';
97
+ };
98
+ /**
99
+ * Sub-reasons for `decision_required` and `decision_invalid` (PRD G-3;
100
+ * `spec/decision-grant.md`). The first four are PRD Appendix B's; the auth
101
+ * service and the Python SDK use the same values.
102
+ */
103
+ export declare const DecisionSubReason: {
104
+ /** The grant approves a different action (tool, decision, subject, amount or connector). */
105
+ readonly ACTION_MISMATCH: 'action_mismatch';
106
+ /** The grant is past its expiry. */
107
+ readonly EXPIRED: 'expired';
108
+ /** The grant has already been used. */
109
+ readonly CONSUMED: 'consumed';
110
+ /** Both grants of a four-eyes decision name the same approver. */
111
+ readonly SAME_APPROVER: 'same_approver';
112
+ /** The case changed (new case version) after the decision was approved. */
113
+ readonly CASE_CHANGED: 'case_changed';
114
+ /** The grant approves an action on another case. */
115
+ readonly WRONG_CASE: 'wrong_case';
116
+ /** The approver's authentication was not step-up (auth service only). */
117
+ readonly STEP_UP_REQUIRED: 'step_up_required';
118
+ /** The decision request was cancelled and its grants revoked. */
119
+ readonly REVOKED: 'revoked';
120
+ /** The issuer does not know the grant, or it belongs to another developer. */
121
+ readonly UNKNOWN_GRANT: 'unknown_grant';
122
+ /** The grant, or the action to compare it with, cannot be read. */
123
+ readonly MALFORMED: 'malformed';
124
+ /** The decision needs two approvals and fewer were presented. */
125
+ readonly FOUR_EYES_INCOMPLETE: 'four_eyes_incomplete';
126
+ /** The grant could not be consumed at the issuer (network, server or configuration). */
127
+ readonly CONSUME_UNAVAILABLE: 'consume_unavailable';
128
+ /** No decision grant was presented (reported as `decision_required`). */
129
+ readonly ABSENT: 'absent';
130
+ };
131
+ export type DecisionSubReason = (typeof DecisionSubReason)[keyof typeof DecisionSubReason];
132
+ //# sourceMappingURL=denials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"denials.d.ts","sourceRoot":"","sources":["../src/denials.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,YAAY;IACvB,yFAAyF;aACzF,mBAAmB,EAAE,qBAAqB;IAC1C,0DAA0D;aAC1D,gBAAgB,EAAE,k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+ *
4
+ * Every denied `EnforceResult` carries a `reasonCode` and, where one applies,
5
+ * a `subReason`. `reason` stays a human-readable sentence; code against
6
+ * `reasonCode`. The codes are stable, low-cardinality strings suitable for
7
+ * metric labels and audit records, identical to the Python SDK's.
8
+ */
9
+ export const DenialReason = {
10
+ /** The grant's purpose matches none of the tool's `allowed_purposes`, or it has none. */
11
+ PURPOSE_NOT_ALLOWED: 'purpose_not_allowed',
12
+ /** No scope in the grant covers the connector or tool. */
13
+ TOOL_NOT_GRANTED: 'tool_not_granted',
14
+ /** A scope covers the connector but at a lower permission level. */
15
+ PERMISSION_INSUFFICIENT: 'permission_insufficient',
16
+ /** A call cap, cost-unit budget or amount cap would be exceeded, or cannot be evaluated. */
17
+ CAP_EXCEEDED: 'cap_exceeded',
18
+ /** The tool declares `requires_decision` and no decision grant was given. */
19
+ DECISION_REQUIRED: 'decision_required',
20
+ /** A decision grant was given but is not valid for this action. */
21
+ DECISION_INVALID: 'decision_invalid',
22
+ /** The grant has been revoked. */
23
+ GRANT_REVOKED: 'grant_revoked',
24
+ /** The grant's data region does not permit this call. */
25
+ REGION_MISMATCH: 'region_mismatch',
26
+ /** No manifest is loaded for the connector, or it does not declare the tool. */
27
+ MANIFEST_UNKNOWN_TOOL: 'manifest_unknown_tool',
28
+ /** The grant token failed verification. Not part of Appendix B, which assumes a verified grant. */
29
+ TOKEN_INVALID: 'token_invalid',
30
+ };
31
+ /** Sub-reasons for `manifest_unknown_tool`. */
32
+ export const ManifestSubReason = {
33
+ UNKNOWN_CONNECTOR: 'unknown_connector',
34
+ UNKNOWN_TOOL: 'unknown_tool',
35
+ INVALID_DECLARATION: 'invalid_declaration',
36
+ };
37
+ /** Sub-reasons for `cap_exceeded`. */
38
+ export const CapSubReason = {
39
+ /** `amount` is above a `capped:N` scope. */
40
+ AMOUNT_CAP: 'amount_cap',
41
+ /** `amount` is not a finite number. */
42
+ INVALID_AMOUNT: 'invalid_amount',
43
+ /** A `capped:N` scope carries a malformed cap. */
44
+ MALFORMED_CAP: 'malformed_cap',
45
+ /** The tool declares caps or cost units and they cannot be metered: no meter, or its backend is unavailable. */
46
+ METER_UNAVAILABLE: 'meter_unavailable',
47
+ /**
48
+ * A call cap or cost-unit budget would be exceeded (error code E1008). `details`
49
+ * carries `code`, `limit`, `window`, `used`, `requested`, `scope` and `kind`.
50
+ */
51
+ LIMIT_REACHED: 'limit_reached',
52
+ /** A per-case cap applies and no `caseId` was given. */
53
+ CASE_REQUIRED: 'case_required',
54
+ INVALID_CASE_ID: 'invalid_case_id',
55
+ /** `costComponents` names a unit the tool does not declare. */
56
+ INVALID_COST_COMPONENT: 'invalid_cost_component',
57
+ };
58
+ /** Sub-reasons for `purpose_not_allowed`. */
59
+ export const PurposeSubReason = {
60
+ /** The grant carries no purpose. */
61
+ MISSING: 'missing',
62
+ /** The grant's purpose matches none of the tool's patterns. */
63
+ NOT_MATCHED: 'not_matched',
64
+ /** The grant's purpose is malformed or not in the purpose vocabulary. */
65
+ UNKNOWN_PURPOSE: 'unknown_purpose',
66
+ };
67
+ /** Sub-reasons for `tool_not_granted`. */
68
+ export const ToolSubReason = {
69
+ /** The grant's tools entry for the connector does not list the tool. */
70
+ NOT_IN_AUTHORIZATION_DETAILS: 'not_in_authorization_details',
71
+ };
72
+ /**
73
+ * Sub-reasons for `grant_revoked` (PRD G-6). A call is denied both when the
74
+ * grant is known to be revoked and when the client cannot tell: an SDK that
75
+ * has lost the revocation feed must not keep authorising calls.
76
+ */
77
+ export const RevocationSubReason = {
78
+ /** The auth service says this grant or token is revoked. */
79
+ REVOKED: 'revoked',
80
+ /** The grant is suspended: revoked reversibly, pending a decision. */
81
+ SUSPENDED: 'suspended',
82
+ /** A grant above this one in the delegation chain is revoked or suspended. */
83
+ PARENT_REVOKED: 'parent_revoked',
84
+ /** The revocation feed has not heard from the auth service inside its staleness bound. */
85
+ FEED_STALE: 'feed_stale',
86
+ /** The deployment does not serve the revocation feed, or it is not ready. */
87
+ FEED_UNAVAILABLE: 'feed_unavailable',
88
+ /** An online revocation check could not be completed. */
89
+ STATUS_UNAVAILABLE: 'status_unavailable',
90
+ };
91
+ /** Sub-reasons for `token_invalid`. */
92
+ export const TokenSubReason = {
93
+ /** The `authorization_details` claim cannot be read unambiguously. */
94
+ MALFORMED_AUTHORIZATION_DETAILS: 'malformed_authorization_details',
95
+ };
96
+ /**
97
+ * Sub-reasons for `decision_required` and `decision_invalid` (PRD G-3;
98
+ * `spec/decision-grant.md`). The first four are PRD Appendix B's; the auth
99
+ * service and the Python SDK use the same values.
100
+ */
101
+ export const DecisionSubReason = {
102
+ /** The grant approves a different action (tool, decision, subject, amount or connector). */
103
+ ACTION_MISMATCH: 'action_mismatch',
104
+ /** The grant is past its expiry. */
105
+ EXPIRED: 'expired',
106
+ /** The grant has already been used. */
107
+ CONSUMED: 'consumed',
108
+ /** Both grants of a four-eyes decision name the same approver. */
109
+ SAME_APPROVER: 'same_approver',
110
+ /** The case changed (new case version) after the decision was approved. */
111
+ CASE_CHANGED: 'case_changed',
112
+ /** The grant approves an action on another case. */
113
+ WRONG_CASE: 'wrong_case',
114
+ /** The approver's authentication was not step-up (auth service only). */
115
+ STEP_UP_REQUIRED: 'step_up_required',
116
+ /** The decision request was cancelled and its grants revoked. */
117
+ REVOKED: 'revoked',
118
+ /** The issuer does not know the grant, or it belongs to another developer. */
119
+ UNKNOWN_GRANT: 'unknown_grant',
120
+ /** The grant, or the action to compare it with, cannot be read. */
121
+ MALFORMED: 'malformed',
122
+ /** The decision needs two approvals and fewer were presented. */
123
+ FOUR_EYES_INCOMPLETE: 'four_eyes_incomplete',
124
+ /** The grant could not be consumed at the issuer (network, server or configuration). */
125
+ CONSUME_UNAVAILABLE: 'consume_unavailable',
126
+ /** No decision grant was presented (reported as `decision_required`). */
127
+ ABSENT: 'absent',
128
+ };
129
+ //# sourceMappingURL=denials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"denials.js","sourceRoot":"","sources":["../src/denials.ts"],"names":[],"mappings":"AAAA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CAAC,MAAM,aAAa,GAAG;IAC3B,wEAAwE;IACxE,4BAA4B,EAAE,8BAA8B;CACpD,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,4DAA4D;IAC5D,OAAO,EAAE,SAAS;IAClB,sEAAsE;IACtE,SAAS,EAAE,WAAW;IACtB,8EAA8E;IAC9E,cAAc,EAAE,gBAAgB;IAChC,0FAA0F;IAC1F,UAAU,EAAE,YAAY;IACxB,6EAA6E;IAC7E,gBAAgB,EAAE,kBAAkB;IACpC,yDAAyD;IACzD,kBAAkB,EAAE,oBAAoB;CAChC,CAAC;AAIX,uCAAuC;AACvC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,sEAAsE;IACtE,+BAA+B,EAAE,iCAAiC;CAC1D,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,4FAA4F;IAC5F,eAAe,EAAE,iBAAiB;IAClC,oCAAoC;IACpC,OAAO,EAAE,SAAS;IAClB,uCAAuC;IACvC,QAAQ,EAAE,UAAU;IACpB,kEAAkE;IAClE,aAAa,EAAE,eAAe;IAC9B,2EAA2E;IAC3E,YAAY,EAAE,cAAc;IAC5B,oDAAoD;IACpD,UAAU,EAAE,YAAY;IACxB,yEAAyE;IACzE,gBAAgB,EAAE,kBAAkB;IACpC,iEAAiE;IACjE,OAAO,EAAE,SAAS;IAClB,8EAA8E;IAC9E,aAAa,EAAE,eAAe;IAC9B,mEAAmE;IACnE,SAAS,EAAE,WAAW;IACtB,iEAAiE;IACjE,oBAAoB,EAAE,sBAAsB;IAC5C,wFAAwF;IACxF,mBAAmB,EAAE,qBAAqB;IAC1C,yEAAyE;IACzE,MAAM,EAAE,QAAQ;CACR,CAAC"}
@@ -0,0 +1,63 @@
1
+ type Json = Record<string, any>;
2
+ /**
3
+ * How identifiers and content digests appear in a package. Every class not in
4
+ * `disclosed` (`approver`, `content`, `principal`, `record`, `subject`) is keyed
5
+ * per case with `key` (at least 32 bytes, never written to the package; `keyId`
6
+ * names it). Disclosing every class needs no key and produces scheme `none`.
7
+ */
8
+ export interface PrivacySettings {
9
+ key?: Uint8Array;
10
+ keyId?: string;
11
+ disclosed?: readonly string[];
12
+ }
13
+ export interface BuiltPackage {
14
+ document: Json;
15
+ data: Uint8Array;
16
+ root: string;
17
+ }
18
+ export interface EvidenceRecord {
19
+ type: string;
20
+ at: string;
21
+ data: Json;
22
+ source: {
23
+ authority: 'platform' | 'tenant';
24
+ recorded_at: string;
25
+ audit_entry_id?: string;
26
+ audit_hash?: string;
27
+ late?: true;
28
+ };
29
+ ext?: Json;
30
+ }
31
+ /** The canonical bytes of a package document. */
32
+ export declare function serializePackage(document: Json): Uint8Array;
33
+ /**
34
+ * Build a package from a case header and entry records. Values are given in the
35
+ * clear (decisions carry the token's `action_hash`) and keyed here according to
36
+ * `privacy`. The result is checked with the verification rules, so an invalid
37
+ * package is refused with `EvidenceBuildError`.
38
+ */
39
+ export declare function buildPackage(input: {
40
+ case: Json;
41
+ entries: readonly EvidenceRecord[] | readonly Json[];
42
+ privacy: PrivacySettings;
43
+ }): BuiltPackage;
44
+ /**
45
+ * The platform audit entry that records a package's root. Its agent, DID and
46
+ * grant are empty, its principal is `platform` and its metadata carries the
47
+ * platform marker, none of which a tenant can write through `/v1/audit/log`.
48
+ */
49
+ export declare function anchorAuditEntry(document: Json, options: {
50
+ auditEntryId: string;
51
+ timestamp: string;
52
+ prevHash: string | null;
53
+ }): Json;
54
+ /** A copy of `document` with `anchor` set; the root is unchanged. */
55
+ export declare function attachAnchor(document: Json, auditEntry: Json): Json;
56
+ /** A copy of `document` with `signature` set; the root is unchanged. */
57
+ export declare function attachSignature(document: Json, signature: Json | {
58
+ alg: string;
59
+ jws: string;
60
+ kid: string;
61
+ }): Json;
62
+ export {};
63
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/evidence/build.ts"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