@learncard/helpers 1.3.2 → 1.3.4

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/dist/helpers.d.ts CHANGED
@@ -444,6 +444,11 @@ declare const CredentialFormatValidator: z.ZodEnum<{
444
444
  mso_mdoc: "mso_mdoc";
445
445
  }>;
446
446
  export type CredentialFormat = z.infer<typeof CredentialFormatValidator>;
447
+ export type StoredCredentialEnvelope = {
448
+ format: CredentialFormat;
449
+ data: string | Uint8Array;
450
+ [key: string]: unknown;
451
+ };
447
452
  /**
448
453
  * Format-discriminated read view over a stored credential. Returned
449
454
  * by `toStoredCredential(record)` in `@learncard/helpers`.
@@ -854,7 +859,7 @@ export declare const calculateAgeFromDob: (dob?: string | null) => number | null
854
859
  * trusts it. This is the path new format-aware writers take.
855
860
  *
856
861
  * 2. **Inferred from shape** (legacy fallback): for records that
857
- * pre-date ADR-0001 Phase 1, the projector inspects `record.vc` and
862
+ * pre-date format-tagging, the projector inspects `record.vc` and
858
863
  * infers the format. W3C VCs → `w3c-vc-2.0` / `w3c-vc-1.1` based
859
864
  * on `@context`; transitional SD-JWT wrappers (which never shipped
860
865
  * but exist on branch `lc-1796-3`) → `dc+sd-jwt` with the compact
@@ -865,11 +870,79 @@ export declare const calculateAgeFromDob: (dob?: string | null) => number | null
865
870
  * `w3c-vc-1.1` with `data = record.vc` so legacy consumers keep
866
871
  * something they can read.
867
872
  *
868
- * This projector is the SAFETY NET that makes the ADR-0001 migration
869
- * non-breaking: writers can adopt format-tagging at their own pace;
870
- * readers using this projector see the right discriminator either way.
873
+ * This projector is the SAFETY NET that makes the format-tagging
874
+ * migration non-breaking: writers can adopt format-tagging at their
875
+ * own pace; readers using this projector see the right discriminator
876
+ * either way.
871
877
  */
872
878
  export declare const toStoredCredential: (record: CredentialRecord) => StoredCredential;
879
+ /**
880
+ * Extract the meaningful identifying segment from an SD-JWT-VC `vct` claim
881
+ * so it can be projected onto the W3C-VC `type` array and `name` field.
882
+ *
883
+ * Returns `undefined` for vct values where no meaningful name can be
884
+ * derived (numeric-only URN tails, empty string). Shared between the
885
+ * receipt-time wrapper synthesizer and the read-time display projector
886
+ * so SD-JWT credentials produce the same wrapper shape on both paths.
887
+ */
888
+ export declare const extractVctSegment: (vct: string) => string | undefined;
889
+ /**
890
+ * PascalCase identifier suitable for the W3C-VC `type` array. Picks acronyms
891
+ * for short single-word lowercase segments ("pid" → "PID") and otherwise
892
+ * concatenates capitalized words ("playground-credential" → "PlaygroundCredential").
893
+ */
894
+ export declare const deriveTypeFromVct: (vct: string | undefined) => string | undefined;
895
+ /**
896
+ * Human-readable display name for the `name` field. Same input handling
897
+ * as {@link deriveTypeFromVct} but keeps spaces between words so it reads
898
+ * naturally in UIs ("Playground Credential" not "PlaygroundCredential").
899
+ */
900
+ export declare const deriveNameFromVct: (vct: string | undefined) => string | undefined;
901
+ export declare const stripSdJwtReservedClaims: (claims: Record<string, unknown>) => Record<string, unknown>;
902
+ export declare const synthesizeDidJwk: (jwk: Record<string, unknown>) => string | undefined;
903
+ export declare const deriveSdJwtIssuedAtIso: (options: {
904
+ issuedAt?: Date;
905
+ notBefore?: Date;
906
+ iat?: number;
907
+ nbf?: number;
908
+ }) => string;
909
+ /**
910
+ * Read-path shim: when a storage plugin returns a `StoredCredentialEnvelope` (because we
911
+ * wrote a native non-W3C format like SD-JWT-VC), legacy UI components
912
+ * that read `.credentialSubject` / `.issuer` / `.proof` need a VC-shaped
913
+ * object. This projector synthesizes a minimal display-only VC from the
914
+ * envelope so existing consumers keep working without per-component
915
+ * format awareness.
916
+ *
917
+ * For SD-JWT-VC: decodes the unsigned JWS payload (signature is NOT
918
+ * verified here — verification belongs to the dedicated verify chain),
919
+ * surfaces the disclosed claims under `credentialSubject`, preserves
920
+ * the compact form under `proof.jwt` and `proof.type = 'SdJwtCompactProof'`
921
+ * so anything that already understands the SD-JWT-Compact-Proof shape
922
+ * keeps working.
923
+ *
924
+ * For JWT-VC: decodes the JWS payload, returns its `vc` claim.
925
+ *
926
+ * For mDoc / unknown formats: returns `undefined` — the caller MUST
927
+ * branch on format (`record.format === 'mso_mdoc'`) and use a
928
+ * format-specific display path. We don't fabricate a fake VC for
929
+ * binary credentials.
930
+ *
931
+ * This projector is intentionally LOSSY for SD-JWT — it produces a
932
+ * display-only view, NOT a re-issuable credential. Egress paths
933
+ * (sharing, presenting, re-uploading) MUST go through
934
+ * `serializeForWire(stored)` (Phase 3) to recover the canonical
935
+ * compact form from `envelope.data`. NEVER re-serialize from the
936
+ * projected VC.
937
+ */
938
+ export declare const projectEnvelopeToDisplayVc: (envelope: StoredCredentialEnvelope) => VC | undefined;
939
+ /**
940
+ * Convenience: detect an envelope on the wire and return a legacy VC
941
+ * shape suitable for downstream W3C-only consumers. Returns the input
942
+ * unchanged if it's not an envelope (so callers can wrap any
943
+ * `read.get` result without branching themselves).
944
+ */
945
+ export declare const resolveStorageReadResult: (value: VC | StoredCredentialEnvelope | undefined) => VC | StoredCredentialEnvelope | undefined;
873
946
  /**
874
947
  * Determines whether or not a string is a valid hexadecimal string
875
948
  *