@arcblock/jwt 1.30.26 → 1.31.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.
package/esm/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import { KeyRotationEvent } from "@arcblock/did";
1
2
  import { BytesType } from "@ocap/util";
2
3
 
3
4
  //#region src/index.d.ts
@@ -147,5 +148,159 @@ declare function checkDelegationTokenScope(scope: string, {
147
148
  ops: string[];
148
149
  deny?: string[];
149
150
  }): boolean;
151
+ declare const SD_JWT_HASH_ALG = "sha3-256";
152
+ declare const MAX_SD_DISCLOSURES = 128;
153
+ declare const MAX_DECOY_DIGESTS = 32;
154
+ interface SdJwtSignOptions {
155
+ /** Claim keys in `claims` that should be hidden behind salted `_sd` digests */
156
+ selectiveClaims: string[];
157
+ /** Optional subject / holder DID (`sub` and `cnf.did`) */
158
+ holderDid?: string;
159
+ /** Number of random decoy digests to insert into `_sd` to conceal total claim count */
160
+ decoyCount?: number;
161
+ /** Optional deterministic salts by claim key (for reproducible test vectors) */
162
+ customSalts?: Record<string, string>;
163
+ /** Optional BitstringStatusList index for O(1) revocation checking */
164
+ statusListIndex?: number;
165
+ /** Optional BitstringStatusList credential ID/URI */
166
+ statusListCredential?: string;
167
+ /** Optional expiration timestamp in seconds */
168
+ exp?: string | number;
169
+ /** Optional not-before timestamp in seconds */
170
+ nbf?: string | number;
171
+ /** Optional issued-at timestamp in seconds */
172
+ iat?: string | number;
173
+ }
174
+ interface SdJwtPresentOptions {
175
+ /** Subset of `selectiveClaims` keys that the holder chooses to reveal to the verifier */
176
+ discloseKeys: string[];
177
+ /** Optional holder DID for signing a Key-Binding JWT (`kb-jwt`) */
178
+ holderDid?: string;
179
+ /** Optional holder secret key for signing a Key-Binding JWT (`kb-jwt`) */
180
+ holderSk?: BytesType;
181
+ /** Target verifier audience (`aud` in `kb-jwt`) */
182
+ audience?: string;
183
+ /** Verifier challenge nonce (`nonce` in `kb-jwt`) */
184
+ nonce?: string;
185
+ /** Optional timestamp for `kb-jwt` */
186
+ iat?: number;
187
+ }
188
+ interface SdJwtVerifyOptions extends JwtVerifyOptions {
189
+ /** If true, requires a valid holder-signed Key-Binding JWT (`kb-jwt`) */
190
+ requireKeyBinding?: boolean;
191
+ /** Holder public key (required when verifying `kb-jwt`) */
192
+ holderPk?: BytesType;
193
+ /** Expected audience in `kb-jwt` */
194
+ expectedAudience?: string;
195
+ /** Expected challenge nonce in `kb-jwt` */
196
+ expectedNonce?: string;
197
+ /** Optional callback to check if `statusListIndex` is revoked/suspended in `BitstringStatusList` */
198
+ isStatusRevoked?: (statusListIndex: number, statusListCredential?: string) => boolean | Promise<boolean>;
199
+ }
200
+ interface SdJwtVerifyResult {
201
+ valid: boolean;
202
+ issuerDid?: string;
203
+ holderDid?: string;
204
+ /** Merged visible claims + verified selectively disclosed claims */
205
+ claims?: Record<string, any>;
206
+ /** Only the claims that were selectively disclosed in this presentation */
207
+ disclosedClaims?: Record<string, any>;
208
+ /** Raw decoded issuer JWT body */
209
+ issuerBody?: JwtBody;
210
+ reason?: string;
211
+ }
212
+ /**
213
+ * Compute the canonical `sha3-256` digest of a base64url-encoded SD-JWT disclosure `[salt, key, value]`.
214
+ */
215
+ declare function computeSdJwtDisclosureDigest(disclosureB64u: string): string;
216
+ /**
217
+ * Compute the `sd_hash` over `<issuerJwt>~<disclosure1>~...~` bound inside the Holder Key-Binding JWT (`kb-jwt`).
218
+ */
219
+ declare function computeSdJwtPresentationHash(issuerJwtAndDisclosuresPrefix: string): string;
220
+ /**
221
+ * Issue an `SD-JWT` (`<issuerJwt>~<disclosure1>~<disclosure2>~...~`) where sensitive claims
222
+ * listed in `options.selectiveClaims` are replaced by salted `sha3-256` digests in `_sd`.
223
+ */
224
+ declare function signSdJwt(issuerDid: string, issuerSk: BytesType, claims: Record<string, any>, options: SdJwtSignOptions): Promise<string>;
225
+ /**
226
+ * Create a selective presentation from an `SD-JWT` revealing ONLY `options.discloseKeys`,
227
+ * and optionally attaching a Holder Key-Binding JWT (`kb-jwt`) bound to `audience`, `nonce`, and `sd_hash`.
228
+ */
229
+ declare function presentSdJwt(sdJwtToken: string, options: SdJwtPresentOptions): Promise<string>;
230
+ /**
231
+ * Verify an `SD-JWT` presentation (`<issuerJwt>~<disclosure1>~...~[<kbJwt>]`).
232
+ *
233
+ * Enforces:
234
+ * 1. Valid issuer signature and timestamp on `<issuerJwt>`;
235
+ * 2. Every presented disclosure hashes to a unique entry in `_sd` (rejects duplicate disclosures or unanchored injections);
236
+ * 3. Disclosed claim keys never collide with reserved or existing top-level claims (prevents claim shadowing);
237
+ * 4. Optional `BitstringStatusList` revocation callback check (`options.isStatusRevoked`);
238
+ * 5. Optional Holder Key-Binding JWT (`kb-jwt`) verification (`sd_hash`, `aud`, `nonce`, and `cnf.did` match).
239
+ */
240
+ declare function verifySdJwt(presentation: string, issuerPk: BytesType, options?: SdJwtVerifyOptions): Promise<SdJwtVerifyResult>;
241
+ type ArcEnforcementMode = 'permissive' | 'hybrid' | 'strict';
242
+ interface ArcPrincipalEnvelope {
243
+ /** Claimed actor/principal DID (`did:abt:z1...`, `did:spaces:...`, `did:afs:...`, or legacy `did:agent:...`) */
244
+ principalDid: string;
245
+ /** Signer public key (hex) when authenticated by JWT or rotated key */
246
+ publicKey?: string;
247
+ /** Optional signed session/request JWT (`signV2` or `signArcRequestToken`) */
248
+ sessionJwt?: string;
249
+ /** Optional UCAN-style `DelegationToken` (`Human DID -> Agent DID -> Subagent DID`) */
250
+ delegationToken?: string;
251
+ /** Optional offline Key Rotation Event Log (`KeyRotationEvent[]`) if `principalDid` rotated keys */
252
+ keyRotationEvents?: KeyRotationEvent[];
253
+ /** Optional index in `BitstringStatusList` for O(1) session/agent key revocation check */
254
+ statusListIndex?: number;
255
+ }
256
+ interface VerifyArcPrincipalOptions {
257
+ /**
258
+ * Enforcement level:
259
+ * - `'permissive'`: Allows bare DID strings (and legacy `did:agent:...` if `allowLegacyAgentId !== false`),
260
+ * emitting a warning when no cryptographic proof is attached, while still rejecting forged signatures if a token IS present.
261
+ * - `'hybrid'`: Requires a checksum-valid cryptographic DID (`isValid(principalDid)`), verifies cryptographic proof when present.
262
+ * - `'strict'`: Requires cryptographic signature verification (`sessionJwt` or `delegationToken`), scope check, and revocation check.
263
+ */
264
+ mode?: ArcEnforcementMode;
265
+ /** Required action/resource capability scope (e.g. `'fg:afs:write'` or `'fg:channel:post'`) */
266
+ requiredScope?: string;
267
+ /** Expected audience (`aud`) in `sessionJwt` */
268
+ expectedAudience?: string;
269
+ /** Expected challenge nonce (`nonce`) in `sessionJwt` */
270
+ expectedNonce?: string;
271
+ /** Allow legacy non-checksum `did:agent:<id>` strings in `permissive` mode (default: true) */
272
+ allowLegacyAgentId?: boolean;
273
+ /** Optional callback to check `BitstringStatusList` revocation status */
274
+ isRevokedIndex?: (index: number) => boolean | Promise<boolean>;
275
+ }
276
+ interface ArcPrincipalVerifyResult {
277
+ valid: boolean;
278
+ mode: ArcEnforcementMode;
279
+ verificationLevel: 'cryptographic' | 'delegated_cryptographic' | 'checksum_only' | 'legacy_string' | 'rejected';
280
+ /** Canonical principal DID (if delegated, the root delegator or active subject) */
281
+ principalDid?: string;
282
+ /** Root authority DID when acting via `DelegationToken` (`Human -> Agent`) */
283
+ rootAuthorityDid?: string;
284
+ /** Warning message when accepted in `permissive` or `hybrid` mode without cryptographic signature */
285
+ warning?: string;
286
+ reason?: string;
287
+ }
288
+ /**
289
+ * Sign a short-lived `ARC` request/session token for `AFS`, `ArcSpace`, or multi-agent channel actions.
290
+ */
291
+ declare function signArcRequestToken(params: {
292
+ signerDid: string;
293
+ signerSk: BytesType;
294
+ audience?: string;
295
+ scope?: string | string[];
296
+ nonce?: string;
297
+ statusListIndex?: number;
298
+ ttlSeconds?: number;
299
+ }): Promise<string>;
300
+ /**
301
+ * Verify an `ARC` principal across progressive enforcement modes (`permissive` -> `hybrid` -> `strict`).
302
+ * Designed so `ARC` can seamlessly tighten from unverified DID strings to full cryptographic + delegation + bitmap revocation enforcement.
303
+ */
304
+ declare function verifyArcPrincipal(envelope: ArcPrincipalEnvelope, options?: VerifyArcPrincipalOptions): Promise<ArcPrincipalVerifyResult>;
150
305
  //#endregion
151
- export { DelegationToken, DelegationTokenBody, DelegationTokenHeader, DelegationVerifyOptions, JwtBody, JwtHeader, JwtToken, JwtVerifyOptions, PasskeyAssertion, assemble, assembleDelegationToken, checkDelegationTokenScope, decode, decodeDelegationToken, getChallenge, sign, signDelegationToken, signDelegationTokenUnsigned, signV2, verify, verifyDelegationToken };
306
+ export { ArcEnforcementMode, ArcPrincipalEnvelope, ArcPrincipalVerifyResult, DelegationToken, DelegationTokenBody, DelegationTokenHeader, DelegationVerifyOptions, JwtBody, JwtHeader, JwtToken, JwtVerifyOptions, MAX_DECOY_DIGESTS, MAX_SD_DISCLOSURES, PasskeyAssertion, SD_JWT_HASH_ALG, SdJwtPresentOptions, SdJwtSignOptions, SdJwtVerifyOptions, SdJwtVerifyResult, VerifyArcPrincipalOptions, assemble, assembleDelegationToken, checkDelegationTokenScope, computeSdJwtDisclosureDigest, computeSdJwtPresentationHash, decode, decodeDelegationToken, getChallenge, presentSdJwt, sign, signArcRequestToken, signDelegationToken, signDelegationTokenUnsigned, signSdJwt, signV2, verify, verifyArcPrincipal, verifyDelegationToken, verifySdJwt };