@sphereon/ssi-types 0.37.2-feature.oid4vc.1.0.29 → 0.37.2-fix.24

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/index.cjs CHANGED
@@ -692,63 +692,27 @@ function decodeMdocDeviceResponse(vpToken) {
692
692
  return deviceResponse;
693
693
  }
694
694
  __name(decodeMdocDeviceResponse, "decodeMdocDeviceResponse");
695
- function bytesToImageDataUri(value, mimeType = "image/jpeg") {
696
- if (typeof value === "string") {
697
- if (value.startsWith("data:image/")) return value;
698
- let b64 = value.replace(/-/g, "+").replace(/_/g, "/");
699
- const pad = b64.length % 4;
700
- if (pad) b64 += "=".repeat(4 - pad);
701
- return `data:${mimeType};base64,${b64}`;
702
- }
703
- if (value && typeof value === "object" && ("length" in value || Symbol.iterator in Object(value))) {
704
- try {
705
- const int8 = value instanceof Int8Array ? value : new Int8Array(value);
706
- const base64 = com.sphereon.kmp.encodeTo(int8, com.sphereon.kmp.Encoding.BASE64);
707
- return `data:${mimeType};base64,${base64}`;
708
- } catch {
709
- const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
710
- let binary = "";
711
- for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
712
- const base64 = typeof btoa === "function" ? btoa(binary) : com.sphereon.kmp.encodeTo(new Int8Array(bytes), com.sphereon.kmp.Encoding.BASE64);
713
- return `data:${mimeType};base64,${base64}`;
714
- }
715
- }
716
- return String(value);
717
- }
718
- __name(bytesToImageDataUri, "bytesToImageDataUri");
719
695
  var mdocDecodedCredentialToUniformCredential = /* @__PURE__ */ __name((decoded, opts) => {
720
696
  const document = decoded.toJson();
721
697
  const json = document.toJsonDTO();
698
+ const type = "Personal Identification Data";
722
699
  const MSO = document.MSO;
723
700
  if (!MSO || !json.issuerSigned?.nameSpaces) {
724
701
  throw Error(`Cannot access Mobile Security Object or Issuer Signed items from the Mdoc`);
725
702
  }
726
703
  const nameSpaces = json.issuerSigned.nameSpaces;
727
- const nameSpaceKeys = Object.keys(nameSpaces);
728
- if (nameSpaceKeys.length === 0) {
729
- throw Error(`No namespaces found in issuer signed items`);
704
+ if (!("eu.europa.ec.eudi.pid.1" in nameSpaces)) {
705
+ throw Error(`Only PID supported at present`);
730
706
  }
731
- const items = [];
732
- for (const ns of nameSpaceKeys) {
733
- items.push(...nameSpaces[ns] || []);
734
- }
735
- if (items.length === 0) {
707
+ const items = nameSpaces["eu.europa.ec.eudi.pid.1"];
708
+ if (!items || items.length === 0) {
736
709
  throw Error(`No issuer signed items were found`);
737
710
  }
738
- const IMAGE_CLAIMS = /* @__PURE__ */ new Set([
739
- "portrait",
740
- "signature_usual_mark"
741
- ]);
742
711
  const credentialSubject = items.reduce((acc, item) => {
743
712
  if (Array.isArray(item.value)) {
744
713
  acc[item.key] = item.value.map((val) => val.value).join(", ");
745
714
  } else {
746
- const value = item.value.value;
747
- if (IMAGE_CLAIMS.has(item.key) && value != null) {
748
- acc[item.key] = bytesToImageDataUri(value);
749
- } else {
750
- acc[item.key] = value;
751
- }
715
+ acc[item.key] = item.value.value;
752
716
  }
753
717
  return acc;
754
718
  }, {});
@@ -761,50 +725,13 @@ var mdocDecodedCredentialToUniformCredential = /* @__PURE__ */ __name((decoded,
761
725
  if (!issuanceDate) {
762
726
  throw Error(`JWT issuance date is required but was not present`);
763
727
  }
764
- let issuer = opts?.issuer ?? docType;
765
- if (credentialSubject.issuing_authority) {
766
- issuer = credentialSubject.issuing_authority;
767
- }
768
- try {
769
- const x5chain = json.issuerSigned?.issuerAuth?.unprotectedHeader?.x5chain ?? json.issuerSigned?.issuerAuth?.protectedHeader?.x5chain;
770
- if (x5chain && x5chain.length > 0) {
771
- const b64 = x5chain[0];
772
- let bytes;
773
- if (typeof atob === "function") {
774
- const binaryStr = atob(b64);
775
- bytes = new Uint8Array(binaryStr.length);
776
- for (let i = 0; i < binaryStr.length; i++) bytes[i] = binaryStr.charCodeAt(i);
777
- } else {
778
- const int8 = com.sphereon.kmp.decodeFrom(b64, com.sphereon.kmp.Encoding.BASE64);
779
- bytes = new Uint8Array(int8);
780
- }
781
- let lastCn;
782
- for (let i = 0; i < bytes.length - 5; i++) {
783
- if (bytes[i] === 85 && bytes[i + 1] === 4 && bytes[i + 2] === 3) {
784
- const tag = bytes[i + 3];
785
- if (tag === 12 || tag === 19) {
786
- const len = bytes[i + 4];
787
- if (i + 5 + len <= bytes.length) {
788
- const cn = String.fromCharCode(...bytes.slice(i + 5, i + 5 + len));
789
- lastCn = cn;
790
- }
791
- }
792
- }
793
- }
794
- if (lastCn) {
795
- issuer = lastCn;
796
- }
797
- }
798
- } catch {
799
- }
800
728
  const credential = {
801
729
  type: [
802
730
  docType
803
731
  ],
804
732
  "@context": [],
805
- issuer,
806
733
  credentialSubject: {
807
- type: docType,
734
+ type,
808
735
  ...credentialSubject
809
736
  },
810
737
  issuanceDate,