@learncard/helpers 1.3.1 → 1.3.2

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.
@@ -143,6 +143,7 @@ var require_types_cjs_development = __commonJS({
143
143
  CredentialActivityStatsValidator: /* @__PURE__ */ __name(() => CredentialActivityStatsValidator, "CredentialActivityStatsValidator"),
144
144
  CredentialActivityValidator: /* @__PURE__ */ __name(() => CredentialActivityValidator, "CredentialActivityValidator"),
145
145
  CredentialActivityWithDetailsValidator: /* @__PURE__ */ __name(() => CredentialActivityWithDetailsValidator, "CredentialActivityWithDetailsValidator"),
146
+ CredentialFormatValidator: /* @__PURE__ */ __name(() => CredentialFormatValidator, "CredentialFormatValidator"),
146
147
  CredentialInfoValidator: /* @__PURE__ */ __name(() => CredentialInfoValidator, "CredentialInfoValidator"),
147
148
  CredentialNameRefValidator: /* @__PURE__ */ __name(() => CredentialNameRefValidator, "CredentialNameRefValidator"),
148
149
  CredentialRecordValidator: /* @__PURE__ */ __name(() => CredentialRecordValidator, "CredentialRecordValidator"),
@@ -171,6 +172,8 @@ var require_types_cjs_development = __commonJS({
171
172
  GetSkillPathResultValidator: /* @__PURE__ */ __name(() => GetSkillPathResultValidator, "GetSkillPathResultValidator"),
172
173
  GetTemplateRecipientsEventValidator: /* @__PURE__ */ __name(() => GetTemplateRecipientsEventValidator, "GetTemplateRecipientsEventValidator"),
173
174
  GuardianStatusValidator: /* @__PURE__ */ __name(() => GuardianStatusValidator, "GuardianStatusValidator"),
175
+ HolderExportConsentRecordValidator: /* @__PURE__ */ __name(() => HolderExportConsentRecordValidator, "HolderExportConsentRecordValidator"),
176
+ HolderExportMetadataValidator: /* @__PURE__ */ __name(() => HolderExportMetadataValidator, "HolderExportMetadataValidator"),
174
177
  IdentifierEntryValidator: /* @__PURE__ */ __name(() => IdentifierEntryValidator, "IdentifierEntryValidator"),
175
178
  IdentifierTypeValidator: /* @__PURE__ */ __name(() => IdentifierTypeValidator, "IdentifierTypeValidator"),
176
179
  IdentityObjectValidator: /* @__PURE__ */ __name(() => IdentityObjectValidator, "IdentityObjectValidator"),
@@ -14118,6 +14121,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14118
14121
  var ClrCredentialValidator = UnsignedClrCredentialValidator.extend({
14119
14122
  proof: ProofValidator.or(ProofValidator.array())
14120
14123
  });
14124
+ var CredentialFormatValidator = external_exports.enum([
14125
+ "w3c-vc-2.0",
14126
+ "w3c-vc-1.1",
14127
+ "jwt-vc-json",
14128
+ "dc+sd-jwt",
14129
+ "vc+sd-jwt",
14130
+ "mso_mdoc"
14131
+ ]);
14121
14132
  var StatusCheckEntryValidator = external_exports.object({
14122
14133
  /**
14123
14134
  * The `credentialStatus.type` as it appeared on the credential.
@@ -14173,7 +14184,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14173
14184
  issuee: ProfileValidator.optional(),
14174
14185
  credentialSubject: CredentialSubjectValidator.optional()
14175
14186
  });
14176
- var CredentialRecordValidator = external_exports.object({ id: external_exports.string(), uri: external_exports.string() }).catchall(external_exports.any());
14187
+ var CredentialRecordValidator = external_exports.object({
14188
+ id: external_exports.string(),
14189
+ uri: external_exports.string(),
14190
+ format: CredentialFormatValidator.optional(),
14191
+ semanticType: external_exports.string().optional(),
14192
+ rawWireForm: external_exports.string().optional()
14193
+ }).catchall(external_exports.any());
14177
14194
  var PaginationOptionsValidator = external_exports.object({
14178
14195
  limit: external_exports.number(),
14179
14196
  cursor: external_exports.string().optional(),
@@ -14741,6 +14758,22 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14741
14758
  date: external_exports.string(),
14742
14759
  uris: external_exports.string().array().optional()
14743
14760
  });
14761
+ var HolderExportConsentRecordValidator = external_exports.object({
14762
+ termsUri: external_exports.string(),
14763
+ status: ConsentFlowTermsStatusValidator,
14764
+ contract: ConsentFlowContractDetailsValidator,
14765
+ terms: ConsentFlowTermsValidator,
14766
+ transactions: ConsentFlowTransactionValidator.array()
14767
+ });
14768
+ var HolderExportMetadataValidator = external_exports.object({
14769
+ consentRecords: HolderExportConsentRecordValidator.array(),
14770
+ truncated: external_exports.boolean().optional(),
14771
+ warnings: external_exports.string().array().optional(),
14772
+ limits: external_exports.object({
14773
+ maxConsentRecords: external_exports.number(),
14774
+ maxTransactionsPerConsentRecord: external_exports.number()
14775
+ }).optional()
14776
+ });
14744
14777
  var PaginatedConsentFlowTransactionsValidator = PaginationResponseValidator.extend({
14745
14778
  records: ConsentFlowTransactionValidator.array()
14746
14779
  });
@@ -14827,10 +14860,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14827
14860
  var LCNNotificationValidator = external_exports.object({
14828
14861
  type: LCNNotificationTypeEnumValidator,
14829
14862
  to: LCNProfileValidator.partial().and(external_exports.object({ did: external_exports.string() })),
14830
- from: external_exports.union([
14831
- external_exports.string(),
14832
- LCNProfileValidator.partial().and(external_exports.object({ did: external_exports.string() }))
14833
- ]),
14863
+ from: external_exports.union([external_exports.string(), LCNProfileValidator.partial().and(external_exports.object({ did: external_exports.string() }))]),
14834
14864
  message: LCNNotificationMessageValidator.optional(),
14835
14865
  data: LCNNotificationDataValidator.optional(),
14836
14866
  sent: external_exports.iso.datetime().optional(),
@@ -15647,6 +15677,7 @@ __export(index_exports, {
15647
15677
  quantizeValue: () => quantizeValue,
15648
15678
  resizeAndChangeQuality: () => resizeAndChangeQuality4,
15649
15679
  setBitstringStatusListBit: () => setBitstringStatusListBit,
15680
+ toStoredCredential: () => toStoredCredential,
15650
15681
  unwrapBoostCredential: () => unwrapBoostCredential
15651
15682
  });
15652
15683
  module.exports = __toCommonJS(index_exports);
@@ -16587,6 +16618,78 @@ var calculateAgeFromDob = /* @__PURE__ */ __name((dob) => {
16587
16618
  return age;
16588
16619
  }, "calculateAgeFromDob");
16589
16620
 
16621
+ // src/credential-format.ts
16622
+ var toStoredCredential = /* @__PURE__ */ __name((record) => {
16623
+ if (record.format) {
16624
+ if (record.format === "dc+sd-jwt" || record.format === "vc+sd-jwt" || record.format === "jwt-vc-json" || record.format === "mso_mdoc") {
16625
+ const wireForm = record.rawWireForm ?? extractWireFormFromVc(record.vc);
16626
+ if (typeof wireForm === "string" && wireForm.length > 0) {
16627
+ return { format: record.format, data: wireForm };
16628
+ }
16629
+ }
16630
+ if (record.format === "w3c-vc-2.0" || record.format === "w3c-vc-1.1") {
16631
+ return { format: record.format, data: record.vc };
16632
+ }
16633
+ }
16634
+ const vc = record.vc;
16635
+ if (typeof vc === "string") {
16636
+ if (looksLikeSdJwtCompact(vc)) {
16637
+ return { format: "dc+sd-jwt", data: vc };
16638
+ }
16639
+ if (looksLikeJwsCompact(vc)) {
16640
+ return { format: "jwt-vc-json", data: vc };
16641
+ }
16642
+ }
16643
+ if (vc && typeof vc === "object") {
16644
+ const proof = getWireFormProof(vc, true);
16645
+ const wireFromProof = getWireFormFromProof(proof);
16646
+ if (wireFromProof) {
16647
+ const proofType = proof?.type;
16648
+ if (proofType === "SdJwtCompactProof") {
16649
+ return { format: "dc+sd-jwt", data: wireFromProof };
16650
+ }
16651
+ if (proofType === "JwtProof2020") {
16652
+ return { format: "jwt-vc-json", data: wireFromProof };
16653
+ }
16654
+ }
16655
+ const inferred = inferW3cVersionFromContext(vc);
16656
+ return { format: inferred, data: vc };
16657
+ }
16658
+ return { format: "w3c-vc-1.1", data: vc };
16659
+ }, "toStoredCredential");
16660
+ var SD_JWT_COMPACT_RE = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+~/;
16661
+ var JWS_COMPACT_RE = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
16662
+ var looksLikeSdJwtCompact = /* @__PURE__ */ __name((value) => SD_JWT_COMPACT_RE.test(value), "looksLikeSdJwtCompact");
16663
+ var looksLikeJwsCompact = /* @__PURE__ */ __name((value) => JWS_COMPACT_RE.test(value), "looksLikeJwsCompact");
16664
+ var getWireFormProof = /* @__PURE__ */ __name((vc, requireSupportedType = false) => {
16665
+ if (!vc || typeof vc !== "object") return void 0;
16666
+ const proof = vc.proof;
16667
+ if (Array.isArray(proof)) {
16668
+ for (const entry of proof) {
16669
+ const proofObject2 = asWireFormProof(entry);
16670
+ if (proofObject2 && isUsableWireFormProof(proofObject2, requireSupportedType)) {
16671
+ return proofObject2;
16672
+ }
16673
+ }
16674
+ return void 0;
16675
+ }
16676
+ const proofObject = asWireFormProof(proof);
16677
+ return proofObject && isUsableWireFormProof(proofObject, requireSupportedType) ? proofObject : void 0;
16678
+ }, "getWireFormProof");
16679
+ var asWireFormProof = /* @__PURE__ */ __name((proof) => proof && typeof proof === "object" ? proof : void 0, "asWireFormProof");
16680
+ var isUsableWireFormProof = /* @__PURE__ */ __name((proof, requireSupportedType) => typeof proof.jwt === "string" && proof.jwt.length > 0 && (!requireSupportedType || proof.type === "SdJwtCompactProof" || proof.type === "JwtProof2020"), "isUsableWireFormProof");
16681
+ var getWireFormFromProof = /* @__PURE__ */ __name((proof) => typeof proof?.jwt === "string" && proof.jwt.length > 0 ? proof.jwt : void 0, "getWireFormFromProof");
16682
+ var extractWireFormFromVc = /* @__PURE__ */ __name((vc) => getWireFormFromProof(getWireFormProof(vc)), "extractWireFormFromVc");
16683
+ var inferW3cVersionFromContext = /* @__PURE__ */ __name((vc) => {
16684
+ if (!vc || typeof vc !== "object") return "w3c-vc-1.1";
16685
+ const contextRaw = vc["@context"];
16686
+ const contexts = Array.isArray(contextRaw) ? contextRaw : contextRaw !== void 0 ? [contextRaw] : [];
16687
+ const isV2 = contexts.some(
16688
+ (c) => typeof c === "string" && c.includes("w3.org/ns/credentials/v2")
16689
+ );
16690
+ return isV2 ? "w3c-vc-2.0" : "w3c-vc-1.1";
16691
+ }, "inferW3cVersionFromContext");
16692
+
16590
16693
  // src/index.ts
16591
16694
  var isHex = /* @__PURE__ */ __name((str) => /^[0-9a-f]+$/i.test(str), "isHex");
16592
16695
  var isEncrypted = /* @__PURE__ */ __name((item) => {