@learncard/learn-card-plugin 1.2.21 → 1.2.22
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.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/learn-card-plugin.cjs.development.cjs +105 -1
- package/dist/learn-card-plugin.cjs.development.cjs.map +4 -4
- package/dist/learn-card-plugin.cjs.production.min.cjs +1 -1
- package/dist/learn-card-plugin.cjs.production.min.cjs.map +4 -4
- package/dist/learn-card-plugin.esm.js +105 -1
- package/dist/learn-card-plugin.esm.js.map +4 -4
- package/dist/test/verificationPrettifier.test.d.ts +2 -0
- package/dist/test/verificationPrettifier.test.d.ts.map +1 -0
- package/dist/verificationPrettifier.d.ts +4 -0
- package/dist/verificationPrettifier.d.ts.map +1 -0
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,+BAA+B,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG3E,cAAc,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,+BAA+B,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG3E,cAAc,SAAS,CAAC;AACxB,cAAc,0BAA0B,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,kBAAkB,cAChB,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,+BAA+B,CAAC,KAChE,eAOD,CAAC"}
|
|
@@ -21,7 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
-
getLearnCardPlugin: () => getLearnCardPlugin
|
|
24
|
+
getLearnCardPlugin: () => getLearnCardPlugin,
|
|
25
|
+
prettifyVerificationItem: () => prettifyVerificationItem,
|
|
26
|
+
prettifyVerificationItems: () => prettifyVerificationItems
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(index_exports);
|
|
27
29
|
|
|
@@ -1828,6 +1830,108 @@ var verifyCredential = /* @__PURE__ */ __name((learnCard) => {
|
|
|
1828
1830
|
};
|
|
1829
1831
|
}, "verifyCredential");
|
|
1830
1832
|
|
|
1833
|
+
// src/verificationPrettifier.ts
|
|
1834
|
+
var import_types2 = require("@learncard/types");
|
|
1835
|
+
var SUCCESS_LABELS = {
|
|
1836
|
+
parse: { check: "Format", message: "Valid" },
|
|
1837
|
+
disclosure_hash_integrity: { check: "Selective Disclosure", message: "Claims verified" },
|
|
1838
|
+
issuer_resolved: { check: "Issuer", message: "Identified" },
|
|
1839
|
+
issuer_signature: { check: "Signature", message: "Valid" },
|
|
1840
|
+
expiration: { check: "Expiration", message: "Does Not Expire" },
|
|
1841
|
+
vct: { check: "Credential Type", message: "Verified" },
|
|
1842
|
+
proof: { check: "Proof", message: "Valid" },
|
|
1843
|
+
credentialStatus: { check: "Status", message: "Active" },
|
|
1844
|
+
// The W3C verifier (learn-card/verify.ts) normalizes both `status` and
|
|
1845
|
+
// `credentialStatus` success rows to check: 'status' (lowercase), so the
|
|
1846
|
+
// bare `status` alias is required or those rows render unprettified.
|
|
1847
|
+
status: { check: "Status", message: "Active" },
|
|
1848
|
+
credentialSchema: { check: "Schema", message: "Valid" }
|
|
1849
|
+
};
|
|
1850
|
+
var ERROR_LABELS = {
|
|
1851
|
+
invalid_compact_form: { check: "Format", message: "Invalid" },
|
|
1852
|
+
invalid_jwt: { check: "Format", message: "Invalid" },
|
|
1853
|
+
invalid_typ: { check: "Format", message: "Invalid type" },
|
|
1854
|
+
missing_iss: { check: "Issuer", message: "Missing" },
|
|
1855
|
+
missing_vct: { check: "Credential Type", message: "Missing" },
|
|
1856
|
+
missing_alg: { check: "Signature", message: "Algorithm missing" },
|
|
1857
|
+
unsupported_alg: { check: "Signature", message: "Unsupported algorithm" },
|
|
1858
|
+
unsupported_sd_alg: { check: "Selective Disclosure", message: "Unsupported algorithm" },
|
|
1859
|
+
invalid_disclosure: { check: "Selective Disclosure", message: "Invalid" },
|
|
1860
|
+
disclosure_hash_mismatch: { check: "Selective Disclosure", message: "Tampered" },
|
|
1861
|
+
issuer_resolution_failed: { check: "Issuer", message: "Could not be found" },
|
|
1862
|
+
verification_method_not_found: { check: "Issuer", message: "Key not found" },
|
|
1863
|
+
verification_method_not_authorized: { check: "Issuer", message: "Key not authorized" },
|
|
1864
|
+
signature_invalid: { check: "Signature", message: "Invalid" },
|
|
1865
|
+
expired: { check: "Expiration", message: "Expired" },
|
|
1866
|
+
not_yet_valid: { check: "Expiration", message: "Not yet valid" },
|
|
1867
|
+
vct_mismatch: { check: "Credential Type", message: "Mismatch" },
|
|
1868
|
+
status_check_failed: { check: "Status", message: "Revoked or suspended" },
|
|
1869
|
+
kb_jwt_invalid: { check: "Key Binding", message: "Invalid" },
|
|
1870
|
+
presentation_verification_failed: { check: "Presentation", message: "Invalid" },
|
|
1871
|
+
key_binding_mismatch: { check: "Holder Key", message: "Mismatch" },
|
|
1872
|
+
unsupported_cnf_confirmation_type: { check: "Holder Key", message: "Unsupported type" },
|
|
1873
|
+
internal_error: { check: "Verification", message: "Something went wrong" }
|
|
1874
|
+
};
|
|
1875
|
+
var isAlreadyPrettified = /* @__PURE__ */ __name((check) => {
|
|
1876
|
+
if (!check) return true;
|
|
1877
|
+
return /^[A-Z]/.test(check) || /\s/.test(check);
|
|
1878
|
+
}, "isAlreadyPrettified");
|
|
1879
|
+
var extractErrorCode = /* @__PURE__ */ __name((message) => {
|
|
1880
|
+
if (!message) return void 0;
|
|
1881
|
+
const match2 = message.match(/^([a-z][a-z0-9_]*):/);
|
|
1882
|
+
return match2?.[1];
|
|
1883
|
+
}, "extractErrorCode");
|
|
1884
|
+
var codeFromCheck = /* @__PURE__ */ __name((check) => {
|
|
1885
|
+
if (!check) return void 0;
|
|
1886
|
+
const token = check.split(/[:\s]/)[0];
|
|
1887
|
+
return /^[a-z][a-z0-9_]*$/.test(token) ? token : void 0;
|
|
1888
|
+
}, "codeFromCheck");
|
|
1889
|
+
var resolveErrorCode = /* @__PURE__ */ __name((item) => {
|
|
1890
|
+
const candidates = [
|
|
1891
|
+
extractErrorCode(item.message),
|
|
1892
|
+
extractErrorCode(item.details),
|
|
1893
|
+
codeFromCheck(item.check)
|
|
1894
|
+
];
|
|
1895
|
+
return candidates.find((code) => code !== void 0 && code in ERROR_LABELS);
|
|
1896
|
+
}, "resolveErrorCode");
|
|
1897
|
+
var isMessageRaw = /* @__PURE__ */ __name((message, check) => {
|
|
1898
|
+
if (!message) return true;
|
|
1899
|
+
if (message === check) return true;
|
|
1900
|
+
if (/^[a-z][a-z0-9_]*$/.test(message)) return true;
|
|
1901
|
+
if (message.startsWith(`${check}:`)) return true;
|
|
1902
|
+
return false;
|
|
1903
|
+
}, "isMessageRaw");
|
|
1904
|
+
var prettifyVerificationItem = /* @__PURE__ */ __name((item) => {
|
|
1905
|
+
const isFailed = item.status === import_types2.VerificationStatusEnum.Failed;
|
|
1906
|
+
if (isFailed) {
|
|
1907
|
+
const code = resolveErrorCode(item);
|
|
1908
|
+
if (!code) return item;
|
|
1909
|
+
const label2 = ERROR_LABELS[code];
|
|
1910
|
+
const detailsHumanized = Boolean(item.details) && !isMessageRaw(item.details, item.check);
|
|
1911
|
+
const messageHumanized = Boolean(item.message) && !isMessageRaw(item.message, item.check);
|
|
1912
|
+
let message;
|
|
1913
|
+
if (messageHumanized) message = item.message;
|
|
1914
|
+
else if (detailsHumanized) message = void 0;
|
|
1915
|
+
else message = label2.message;
|
|
1916
|
+
return {
|
|
1917
|
+
...item,
|
|
1918
|
+
check: label2.check,
|
|
1919
|
+
message
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
if (isAlreadyPrettified(item.check)) return item;
|
|
1923
|
+
const label = SUCCESS_LABELS[item.check];
|
|
1924
|
+
if (label) {
|
|
1925
|
+
return {
|
|
1926
|
+
...item,
|
|
1927
|
+
check: label.check,
|
|
1928
|
+
message: isMessageRaw(item.message, item.check) ? label.message : item.message
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
return item;
|
|
1932
|
+
}, "prettifyVerificationItem");
|
|
1933
|
+
var prettifyVerificationItems = /* @__PURE__ */ __name((items) => items.map(prettifyVerificationItem), "prettifyVerificationItems");
|
|
1934
|
+
|
|
1831
1935
|
// src/index.ts
|
|
1832
1936
|
var getLearnCardPlugin = /* @__PURE__ */ __name((learnCard) => ({
|
|
1833
1937
|
name: "LearnCard",
|