@coffre/core 0.4.5 → 0.4.6

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.
@@ -475,6 +475,11 @@ export type CredentialKind = 'browser' | 'cli' | 'service';
475
475
  export declare function generateToken(kind: CredentialKind): string;
476
476
  /** Whether a string has the shape of a coffre token, before any lookup. */
477
477
  export declare function isCoffreToken(value: string): boolean;
478
+ /**
479
+ * The kind a token's prefix says, before any lookup. Its hash covers the
480
+ * prefix, so a token found under its hash is the kind it says.
481
+ */
482
+ export declare function tokenKind(token: string): CredentialKind | null;
478
483
  export declare function hashToken(token: string): Buffer;
479
484
  /**
480
485
  * Enough of a token to recognize it in a list, never enough to use it: the
package/dist/identity.js CHANGED
@@ -630,6 +630,14 @@ function generateToken(kind) {
630
630
  function isCoffreToken(value) {
631
631
  return TOKEN.test(value);
632
632
  }
633
+ /**
634
+ * The kind a token's prefix says, before any lookup. Its hash covers the
635
+ * prefix, so a token found under its hash is the kind it says.
636
+ */
637
+ function tokenKind(token) {
638
+ if (!TOKEN.test(token)) return null;
639
+ return Object.keys(PREFIX).find((kind) => token.startsWith(PREFIX[kind])) ?? null;
640
+ }
633
641
  function hashToken(token) {
634
642
  return createHash("sha256").update(token, "utf8").digest();
635
643
  }
@@ -822,4 +830,4 @@ function refusalOf(error) {
822
830
  return new WorkloadTokenRefused("signature", "the token does not verify");
823
831
  }
824
832
  //#endregion
825
- export { ACCESS_JWT_HEADER, AccessIdentityVerifier, BindingInvalid, CLOCK_TOLERANCE_SECONDS, GITHUB_EVENTS, GITHUB_ISSUER, GITLAB_ISSUER, GITLAB_PIPELINE_SOURCES, GitHubSigninProvider, MAX_BINDINGS, MAX_CLAIMS, MAX_CLAIM_BYTES, MAX_TOKEN_AGE_SECONDS, MAX_TOKEN_BYTES, OidcSigninProvider, REQUIRED_CLAIMS, SigninError, WORKLOAD_ALGORITHMS, WORKLOAD_PROFILES, WorkloadTokenRefused, canonicalClaims, checkBinding, checkFetchUrl, cloudflareAccess, decodeWorkloadToken, defaultIssuer, defineSignin, deriveKey, fullRef, generateToken, github, githubReusable, githubWorkflow, gitlabProject, google, hashToken, isCoffreToken, issuedRefusal, microsoft, oidc, publicOrigin, seal, signin, toPrincipal, tokenHint, unseal, verifyWorkloadToken, workflowRef };
833
+ export { ACCESS_JWT_HEADER, AccessIdentityVerifier, BindingInvalid, CLOCK_TOLERANCE_SECONDS, GITHUB_EVENTS, GITHUB_ISSUER, GITLAB_ISSUER, GITLAB_PIPELINE_SOURCES, GitHubSigninProvider, MAX_BINDINGS, MAX_CLAIMS, MAX_CLAIM_BYTES, MAX_TOKEN_AGE_SECONDS, MAX_TOKEN_BYTES, OidcSigninProvider, REQUIRED_CLAIMS, SigninError, WORKLOAD_ALGORITHMS, WORKLOAD_PROFILES, WorkloadTokenRefused, canonicalClaims, checkBinding, checkFetchUrl, cloudflareAccess, decodeWorkloadToken, defaultIssuer, defineSignin, deriveKey, fullRef, generateToken, github, githubReusable, githubWorkflow, gitlabProject, google, hashToken, isCoffreToken, issuedRefusal, microsoft, oidc, publicOrigin, seal, signin, toPrincipal, tokenHint, tokenKind, unseal, verifyWorkloadToken, workflowRef };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffre/core",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "What coffre's packages share: roles, envelopes, identity, the audit chain and the vault's contract.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -84,7 +84,7 @@
84
84
  "@types/node": "26.1.1",
85
85
  "tsdown": "0.23.0",
86
86
  "typescript": "5.9.3",
87
- "@coffre/conformance": "0.4.5"
87
+ "@coffre/conformance": "0.4.6"
88
88
  },
89
89
  "scripts": {
90
90
  "build": "tsdown",
@@ -30,6 +30,15 @@ export function isCoffreToken(value: string): boolean {
30
30
  return TOKEN.test(value);
31
31
  }
32
32
 
33
+ /**
34
+ * The kind a token's prefix says, before any lookup. Its hash covers the
35
+ * prefix, so a token found under its hash is the kind it says.
36
+ */
37
+ export function tokenKind(token: string): CredentialKind | null {
38
+ if (!TOKEN.test(token)) return null;
39
+ return (Object.keys(PREFIX) as CredentialKind[]).find((kind) => token.startsWith(PREFIX[kind])) ?? null;
40
+ }
41
+
33
42
  export function hashToken(token: string): Buffer {
34
43
  return createHash('sha256').update(token, 'utf8').digest();
35
44
  }