@learncard/helpers 1.4.0 → 1.5.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.
@@ -0,0 +1,58 @@
1
+ import { type SupportedCredentialRefreshService } from '@learncard/types';
2
+ /**
3
+ * Canonical helpers for credential refresh (LC-2117, LC-2135, LC-2136).
4
+ *
5
+ * These helpers are storage-independent: they select a supported refresh service,
6
+ * normalize issuer/effective-time identity, and provide deterministic canonicalization
7
+ * plus a proof-insensitive content comparison used by both the holder SDK and the
8
+ * brain-service publication pipeline.
9
+ */
10
+ type RefreshableCredential = Record<string, unknown> & {
11
+ refreshService?: unknown;
12
+ issuer?: string | {
13
+ id?: unknown;
14
+ } | null;
15
+ validFrom?: unknown;
16
+ issuanceDate?: unknown;
17
+ proof?: unknown;
18
+ };
19
+ /**
20
+ * Selects the first supported refresh service from a credential's `refreshService`.
21
+ *
22
+ * Accepts a single service object or an array. An array is treated as ordered: the
23
+ * first entry whose type is supported is selected. Supported types are
24
+ * `1EdTechCredentialRefresh` and `LearnCardCredentialRefresh2026`.
25
+ *
26
+ * @returns the supported service, or `undefined` when none is present/supported
27
+ */
28
+ export declare const getSupportedRefreshService: (vc: RefreshableCredential) => SupportedCredentialRefreshService | undefined;
29
+ /**
30
+ * Normalizes a credential's issuer to its identifier.
31
+ *
32
+ * Handles both the string form (`issuer: 'did:example:x'`) and the object form
33
+ * (`issuer: { id: 'did:example:x', ... }`).
34
+ */
35
+ export declare const getCredentialIssuerId: (vc: RefreshableCredential) => string | undefined;
36
+ /**
37
+ * Returns the credential's effective timestamp in milliseconds since the epoch.
38
+ *
39
+ * Prefers VCDM 2.0 `validFrom` and falls back to VCDM 1.1 `issuanceDate`. Returns
40
+ * `undefined` when no parseable timestamp exists.
41
+ */
42
+ export declare const getCredentialEffectiveTime: (vc: RefreshableCredential) => number | undefined;
43
+ /**
44
+ * Deterministically canonicalizes a JSON-like value: object keys are recursively
45
+ * sorted, array order is preserved, and primitives pass through unchanged.
46
+ */
47
+ export declare const canonicalizeCredentialContent: <T>(value: T) => T;
48
+ /** Serializes a value to a deterministic canonical JSON string */
49
+ export declare const canonicalizeCredentialJson: (value: unknown) => string;
50
+ /**
51
+ * Proof-insensitive content comparison for refresh changed-content detection.
52
+ *
53
+ * Only the top-level `proof` property is excluded; everything else (subject claims,
54
+ * identifiers, timestamps, services) participates in the comparison.
55
+ */
56
+ export declare const credentialContentsEqual: (first: RefreshableCredential, second: RefreshableCredential) => boolean;
57
+ export {};
58
+ //# sourceMappingURL=credential-refresh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-refresh.d.ts","sourceRoot":"","sources":["../src/credential-refresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,iCAAiC,EACzC,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;GAOG;AAEH,KAAK,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACnD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG;QAAE,EAAE,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,GACnC,IAAI,qBAAqB,KAC1B,iCAAiC,GAAG,SActC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,IAAI,qBAAqB,KAAG,MAAM,GAAG,SAO1E,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAI,IAAI,qBAAqB,KAAG,MAAM,GAAG,SAQ/E,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,6BAA6B,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,CAiB3D,CAAC;AAEF,kEAAkE;AAClE,eAAO,MAAM,0BAA0B,GAAI,OAAO,OAAO,KAAG,MACJ,CAAC;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAChC,OAAO,qBAAqB,EAC5B,QAAQ,qBAAqB,KAC9B,OAWF,CAAC"}