@blockcerts/blockcerts-verifier 1.72.4 → 1.74.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.
- package/README.md +8 -0
- package/bundle-stats.html +1 -1
- package/codecov +0 -0
- package/codecov.SHA256SUM +1 -0
- package/codecov.SHA256SUM.sig +16 -0
- package/coverage/lcov.info +469 -466
- package/dist/{DataIntegrityProof-x-pKdBCc-B_YUlE0Z.js → DataIntegrityProof-DRK-bLb_-CItV0ZXY.js} +1 -1
- package/dist/EcdsaSd2023-CdilbQE4-BlaeM9K_.js +26 -0
- package/dist/EcdsaSecp256k1Signature2019-rfxWS2XE-C73WHAtH.js +1 -0
- package/dist/{Ed25519Signature2020-B6yblwC5-BRlzT2Yc.js → Ed25519Signature2020-CDbX0d2Z-Dc1L-exZ.js} +7 -7
- package/dist/{EddsaRdfc2022-Csk9U_qt-B798omlR.js → EddsaRdfc2022-Do0HFpDb-BcV_n8Fk.js} +4 -4
- package/dist/{HashlinkVerifier-Bi7nn19S-DMjUYzMR.js → HashlinkVerifier-Cdnza1Dw-A9htzw7A.js} +1 -1
- package/dist/MerkleProof2017-5uQFQKSe-dtmePIpg.js +1 -0
- package/dist/MerkleProof2019-DraC60XD-B9XV8wNx.js +5 -0
- package/dist/Suite-BmP2Qu19-D1ucdMDB.js +1 -0
- package/dist/_polyfill-node.path-hKwMKLNw-B7aPtphV.js +1 -0
- package/dist/checkBitStringStatusList-CKk6xxUL-D99R7EXK.js +1 -0
- package/dist/checkCredentialSchemaConformity-U2NlIuJZ-swOY09NS.js +1 -0
- package/dist/controlVerificationMethod-Blm4pE1t-BYBRLxNP.js +1 -0
- package/dist/{downloadPDF-UAsY-nU_.js → downloadPDF-C-y2U2YC.js} +3 -3
- package/dist/ensureValidIssuingKey-D7OT4D35--HN0afRq.js +1 -0
- package/dist/index-BNsIYV4r-BnYxKy2f.js +14 -0
- package/dist/{index-D7PA_QcD-CyttRwCk.js → index-C4ZZHHRx-BOdwDnYa.js} +1 -1
- package/dist/index-CVS5Gn9h-DNgvq6Wk.js +7 -0
- package/dist/index-D2bS6rRi-D_ppNIsb.js +66 -0
- package/dist/index-Dr7MpiEc-D5LHgMik.js +30 -0
- package/dist/{index-DNlz8u7B-CYTlxhyY.js → index-uKBVup0_-Dh4-8Ruv.js} +1 -1
- package/dist/{index.es-CnYWLNZV.js → index.es-BmC2s_4v.js} +1 -1
- package/dist/{Suite-CBLHluYK-Dmvbh142.js → jsonld-DOUjwF6J-dtl20tiV.js} +1 -1
- package/dist/{jsonld-signatures-BtZPa7MV-DTekMXP5.js → jsonld-signatures-BJXipuab-CB799Kkm.js} +7 -7
- package/dist/main.js +122 -122
- package/dist/purify.es-C6IIzwyE.js +2 -0
- package/dist/retrieveVerificationMethodPublicKey-CT9YA_Wr-Djl8Ri41.js +1 -0
- package/dist/verifyIssuerProfile-BG-odQrl-0JjZhiiC.js +1 -0
- package/package.json +9 -9
- package/dist/EcdsaSd2023-CU35O_1w-CISk0lEt.js +0 -30
- package/dist/EcdsaSecp256k1Signature2019-DiXIv8yq-B2kEN_Qo.js +0 -1
- package/dist/MerkleProof2017-BIJKwMk5-CLYAJK4G.js +0 -1
- package/dist/MerkleProof2019-CeAt2OGM-DOuISx_E.js +0 -5
- package/dist/checkCredentialSchemaConformity-CECtM4WI-C1vg05zb.js +0 -1
- package/dist/checkRevocationStatusList2021-B7NFlV-5-C3Zng1tA.js +0 -13
- package/dist/controlVerificationMethod-Cuyek_Vk-C_Uq2iA5.js +0 -1
- package/dist/ensureValidIssuingKey-DN2kpCwj-DY8BTObG.js +0 -1
- package/dist/index-DFOHyoZq-BCuOIg2Z.js +0 -29
- package/dist/pako.esm-BGRKTPxS-Bodm4Eha.js +0 -2
- package/dist/purify.es-Om653OSQ.js +0 -2
- package/dist/retrieveVerificationMethodPublicKey-DcEGtx_h-D1zuvtQB.js +0 -1
- package/dist/sha2-JcCWfgvE-By1_saxP.js +0 -2
- package/dist/verifyIssuerProfile-DQji41Fc-l31-7imR.js +0 -1
- /package/dist/{ensureNotRevoked-CNUfpW4F-BheL-ZKZ.js → ensureNotRevoked-DrQAPfcJ-BheL-ZKZ.js} +0 -0
- /package/dist/{index-6G1g4ypj-Dgus2xdV.js → index-yOIIz7AL-Dgus2xdV.js} +0 -0
- /package/dist/{webcrypto.es-aoUxIxUm-gGk5JRJH.js → webcrypto.es-FKUHCUj--gGk5JRJH.js} +0 -0
package/dist/{DataIntegrityProof-x-pKdBCc-B_YUlE0Z.js → DataIntegrityProof-DRK-bLb_-CItV0ZXY.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as t}from"./
|
|
1
|
+
import{r as t}from"./jsonld-DOUjwF6J-dtl20tiV.js";import{w as e,f as r,u as o}from"./main.js";import{j as i}from"./jsonld-signatures-BJXipuab-CB799Kkm.js";var n=t();
|
|
2
2
|
/*!
|
|
3
3
|
* Copyright (c) 2022-2023 Digital Bazaar, Inc. All rights reserved.
|
|
4
4
|
*/const a=new RegExp("-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](.[0-9]+)?|(24:00:00(.0+)?))(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?"),s=t=>a.test(t),c=self&&(self.crypto||self.msCrypto);async function u({string:t}){const e=(new TextEncoder).encode(t);return new Uint8Array(await c.subtle.digest("SHA-256",e))}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import{d as e,p as t,V as n,P as r,u as o,w as i,v as a}from"./main.js";import{j as s}from"./jsonld-signatures-BJXipuab-CB799Kkm.js";import{j as u}from"./jsonld-DOUjwF6J-dtl20tiV.js";import{D as c,r as f}from"./DataIntegrityProof-DRK-bLb_-CItV0ZXY.js";import{f as l}from"./index-Dr7MpiEc-D5LHgMik.js";import{S as d}from"./Suite-BmP2Qu19-D1ucdMDB.js";import"./index-yOIIz7AL-Dgus2xdV.js";import{r as h}from"./retrieveVerificationMethodPublicKey-CT9YA_Wr-Djl8Ri41.js";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) 2023-2026 Digital Bazaar, Inc.
|
|
4
|
+
*/const p=globalThis.crypto;function y({algorithm:e="sha256"}={}){if("sha256"!==e)throw new Error(`Unsupported algorithm "${e}".`);return{hash:async e=>new Uint8Array(await p.subtle.digest("SHA-256",e))}}
|
|
5
|
+
/*!
|
|
6
|
+
* Copyright (c) 2023-2026 Digital Bazaar, Inc.
|
|
7
|
+
*/const w=new TextEncoder;function g(e){return w.encode(e)}
|
|
8
|
+
/*!
|
|
9
|
+
* Copyright (c) 2023-2026 Digital Bazaar, Inc.
|
|
10
|
+
*/async function m({document:e,labelMapFactoryFunction:t,options:n}={}){const{nquads:r}=await async function({document:e,nquads:t,labelMapFactoryFunction:n,options:r}={}){let o,i=new Map;o=e?await b(e,{...r,canonicalIdMap:i}):await b(t.join(""),{...r,inputFormat:"application/n-quads",canonicalIdMap:i});i=function(e){let t=!1,n=!1,r=!1;const o=new Map;for(const[i,a]of e){if(!t&&(t=!0,n=i.startsWith("_:"),r=a.startsWith("_:"),!n&&!r))return e;o.set(n?i.slice(2):i,r?a.slice(2):a)}return o}(i);const a=await n({canonicalIdMap:i}),s=new Map;for(const[e,t]of a)s.set(i.get(e),t);const u=(e,t,n)=>"_:"+s.get(n);return{nquads:o.split("\n").slice(0,-1).map(e=>e.replace(/(_:([^\s]+))/g,u)+"\n").sort(),labelMap:a}}
|
|
11
|
+
/*!
|
|
12
|
+
* Copyright (c) 2023-2026 Digital Bazaar, Inc.
|
|
13
|
+
*/({document:e,labelMapFactoryFunction:t,options:n});return r}async function b(e,t){if(!t||"object"!=typeof t)throw new TypeError('"options" must be an object.');if(t={algorithm:"RDFC-1.0",format:"application/n-quads",base:null,safe:!0,...t},"string"!=typeof e){const n={rdfDirection:"i18n-datatype",...t,produceGeneralizedRdf:!1};delete n.format,e=await u.toRDF(e,n)}return f.canonize(e,t)}async function v({document:e,proof:t,options:n,hasher:r}={}){r||(r=y());const o=await async function({document:e,proof:t,options:n}={}){return delete(t={"@context":e["@context"],...t}).proofValue,b(t,n)}({document:e,proof:t,options:n});return r.hash(g(o))}const E=["string","number","bigint","symbol"],M=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function A(e){if(null===e)return"null";if(void 0===e)return"undefined";if(!0===e||!1===e)return"boolean";const t=typeof e;if(E.includes(t))return t;if("function"===t)return"Function";if(Array.isArray(e))return"Array";if(function(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}(e))return"Buffer";const n=function(e){const t=Object.prototype.toString.call(e).slice(8,-1);if(M.includes(t))return t;return}(e);return n||"Object"}class T{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}}T.uint=new T(0,"uint",!0),T.negint=new T(1,"negint",!0),T.bytes=new T(2,"bytes",!0),T.string=new T(3,"string",!0),T.array=new T(4,"array",!1),T.map=new T(5,"map",!1),T.tag=new T(6,"tag",!1),T.float=new T(7,"float",!0),T.false=new T(7,"false",!0),T.true=new T(7,"true",!0),T.null=new T(7,"null",!0),T.undefined=new T(7,"undefined",!0),T.break=new T(7,"break",!0);class ${constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}}const I=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&"function"==typeof globalThis.Buffer.isBuffer,S=new TextDecoder,k=new TextEncoder;function U(e){return I&&globalThis.Buffer.isBuffer(e)}const j=I?(e,t,n)=>n-t>64?globalThis.Buffer.from(e.subarray(t,n)).toString("utf8"):R(e,t,n):(e,t,n)=>n-t>64?S.decode(e.subarray(t,n)):R(e,t,n),V=I?e=>e.length>64?globalThis.Buffer.from(e):P(e):e=>e.length>64?k.encode(e):P(e),B=I?(e,t,n)=>U(e)?new Uint8Array(e.subarray(t,n)):e.slice(t,n):(e,t,n)=>e.slice(t,n);function P(e){const t=[];let n=0;for(let r=0;r<e.length;r++){let o=e.charCodeAt(r);o<128?t[n++]=o:o<2048?(t[n++]=o>>6|192,t[n++]=63&o|128):55296==(64512&o)&&r+1<e.length&&56320==(64512&e.charCodeAt(r+1))?(o=65536+((1023&o)<<10)+(1023&e.charCodeAt(++r)),t[n++]=o>>18|240,t[n++]=o>>12&63|128,t[n++]=o>>6&63|128,t[n++]=63&o|128):(t[n++]=o>>12|224,t[n++]=o>>6&63|128,t[n++]=63&o|128)}return t}function R(e,t,n){const r=[];for(;t<n;){const o=e[t];let i=null,a=o>239?4:o>223?3:o>191?2:1;if(t+a<=n){let n,r,s,u;switch(a){case 1:o<128&&(i=o);break;case 2:n=e[t+1],128==(192&n)&&(u=(31&o)<<6|63&n,u>127&&(i=u));break;case 3:n=e[t+1],r=e[t+2],128==(192&n)&&128==(192&r)&&(u=(15&o)<<12|(63&n)<<6|63&r,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:n=e[t+1],r=e[t+2],s=e[t+3],128==(192&n)&&128==(192&r)&&128==(192&s)&&(u=(15&o)<<18|(63&n)<<12|(63&r)<<6|63&s,u>65535&&u<1114112&&(i=u))}}null===i?(i=65533,a=1):i>65535&&(i-=65536,r.push(i>>>10&1023|55296),i=56320|1023&i),r.push(i),t+=a}return function(e){const t=e.length;if(t<=N)return String.fromCharCode.apply(String,e);let n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=N));return n}(r)}const N=4096;const D="CBOR decode error:",x="CBOR encode error:";function C(e,t,n){if(e.length-t<n)throw new Error(`${D} not enough data for type`)}const O=[24,256,65536,4294967296,BigInt("18446744073709551616")];function F(e,t,n){C(e,t,1);const r=e[t];if(!0===n.strict&&r<O[0])throw new Error(`${D} integer encoded in more bytes than necessary (strict decode)`);return r}function K(e,t,n){C(e,t,2);const r=e[t]<<8|e[t+1];if(!0===n.strict&&r<O[1])throw new Error(`${D} integer encoded in more bytes than necessary (strict decode)`);return r}function _(e,t,n){C(e,t,4);const r=16777216*e[t]+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(!0===n.strict&&r<O[2])throw new Error(`${D} integer encoded in more bytes than necessary (strict decode)`);return r}function H(e,t,n){C(e,t,8);const r=16777216*e[t]+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=16777216*e[t+4]+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(r)<<BigInt(32))+BigInt(o);if(!0===n.strict&&i<O[3])throw new Error(`${D} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(!0===n.allowBigInt)return i;throw new Error(`${D} integers outside of the safe integer range are not supported`)}function z(e,t){return L(e,0,t.value)}function L(e,t,n){if(n<O[0]){const r=Number(n);e.push([t|r])}else if(n<O[1]){const r=Number(n);e.push([24|t,r])}else if(n<O[2]){const r=Number(n);e.push([25|t,r>>>8,255&r])}else if(n<O[3]){const r=Number(n);e.push([26|t,r>>>24&255,r>>>16&255,r>>>8&255,255&r])}else{const r=BigInt(n);if(!(r<O[4]))throw new Error(`${D} encountered BigInt larger than allowable range`);{const n=[27|t,0,0,0,0,0,0,0];let o=Number(r&BigInt(4294967295)),i=Number(r>>BigInt(32)&BigInt(4294967295));n[8]=255&o,o>>=8,n[7]=255&o,o>>=8,n[6]=255&o,o>>=8,n[5]=255&o,n[4]=255&i,i>>=8,n[3]=255&i,i>>=8,n[2]=255&i,i>>=8,n[1]=255&i,e.push(n)}}}z.encodedSize=function(e){return L.encodedSize(e.value)},L.encodedSize=function(e){return e<O[0]?1:e<O[1]?2:e<O[2]?3:e<O[3]?5:9},z.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};const G=BigInt(-1),Y=BigInt(1);function q(e,t){const n=t.value,r="bigint"==typeof n?n*G-Y:-1*n-1;L(e,t.type.majorEncoded,r)}function W(e,t,n,r){C(e,t,n+r);const o=B(e,t+n,t+n+r);return new $(T.bytes,o,n+r)}function J(e,t,n,r){return W(e,t,1,n)}function X(e){return void 0===e.encodedBytes&&(e.encodedBytes=e.type===T.string?V(e.value):e.value),e.encodedBytes}function Q(e,t){const n=X(t);L(e,t.type.majorEncoded,n.length),e.push(n)}function Z(e,t,n,r,o){const i=n+r;C(e,t,i);const a=new $(T.string,j(e,t+n,t+i),i);return!0===o.retainStringBytes&&(a.byteValue=B(e,t+n,t+i)),a}function ee(e,t,n,r){return Z(e,t,1,n,r)}q.encodedSize=function(e){const t=e.value,n="bigint"==typeof t?t*G-Y:-1*t-1;return n<O[0]?1:n<O[1]?2:n<O[2]?3:n<O[3]?5:9},q.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0},Q.encodedSize=function(e){const t=X(e);return L.encodedSize(t.length)+t.length},Q.compareTokens=function(e,t){return n=X(e),r=X(t),n.length<r.length?-1:n.length>r.length?1:function(e,t){if(U(e)&&U(t))return e.compare(t);for(let n=0;n<e.length;n++)if(e[n]!==t[n])return e[n]<t[n]?-1:1;return 0}(n,r);var n,r};const te=Q;function ne(e,t,n,r){return new $(T.array,r,n)}function re(e,t,n,r){return ne(0,0,1,n)}function oe(e,t){L(e,T.array.majorEncoded,t.value)}function ie(e,t,n,r){return new $(T.map,r,n)}function ae(e,t,n,r){return ie(0,0,1,n)}function se(e,t){L(e,T.map.majorEncoded,t.value)}function ue(e,t,n,r){return new $(T.tag,n,1)}function ce(e,t){L(e,T.tag.majorEncoded,t.value)}oe.compareTokens=z.compareTokens,oe.encodedSize=function(e){return L.encodedSize(e.value)},se.compareTokens=z.compareTokens,se.encodedSize=function(e){return L.encodedSize(e.value)},ce.compareTokens=z.compareTokens,ce.encodedSize=function(e){return L.encodedSize(e.value)};function fe(e,t,n){if(n){if(!1===n.allowNaN&&Number.isNaN(e))throw new Error(`${D} NaN values are not supported`);if(!1===n.allowInfinity&&(e===1/0||e===-1/0))throw new Error(`${D} Infinity values are not supported`)}return new $(T.float,e,t)}function le(e,t,n){const r=t.value;if(!1===r)e.push([20|T.float.majorEncoded]);else if(!0===r)e.push([21|T.float.majorEncoded]);else if(null===r)e.push([22|T.float.majorEncoded]);else if(void 0===r)e.push([23|T.float.majorEncoded]);else{let t,i=!1;n&&!0===n.float64||(ye(r),t=we(pe,1),r===t||Number.isNaN(r)?(pe[0]=249,e.push(pe.slice(0,3)),i=!0):(ge(r),t=me(pe,1),r===t&&(pe[0]=250,e.push(pe.slice(0,5)),i=!0))),i||(o=r,he.setFloat64(0,o,!1),t=be(pe,1),pe[0]=251,e.push(pe.slice(0,9)))}var o}le.encodedSize=function(e,t){const n=e.value;if(!1===n||!0===n||null==n)return 1;if(!t||!0!==t.float64){ye(n);let e=we(pe,1);if(n===e||Number.isNaN(n))return 3;if(ge(n),e=me(pe,1),n===e)return 5}return 9};const de=new ArrayBuffer(9),he=new DataView(de,1),pe=new Uint8Array(de,0);function ye(e){if(e===1/0)he.setUint16(0,31744,!1);else if(e===-1/0)he.setUint16(0,64512,!1);else if(Number.isNaN(e))he.setUint16(0,32256,!1);else{he.setFloat32(0,e);const t=he.getUint32(0),n=(2139095040&t)>>23,r=8388607&t;if(255===n)he.setUint16(0,31744,!1);else if(0===n)he.setUint16(0,(2147483648&e)>>16|r>>13,!1);else{const e=n-127;e<-24?he.setUint16(0,0):e<-14?he.setUint16(0,(2147483648&t)>>16|1<<24+e,!1):he.setUint16(0,(2147483648&t)>>16|e+15<<10|r>>13,!1)}}}function we(e,t){if(e.length-t<2)throw new Error(`${D} not enough data for float16`);const n=(e[t]<<8)+e[t+1];if(31744===n)return 1/0;if(64512===n)return-1/0;if(32256===n)return NaN;const r=n>>10&31,o=1023&n;let i;return i=0===r?o*2**-24:31!==r?(o+1024)*2**(r-25):0===o?1/0:NaN,32768&n?-i:i}function ge(e){he.setFloat32(0,e,!1)}function me(e,t){if(e.length-t<4)throw new Error(`${D} not enough data for float32`);const n=(e.byteOffset||0)+t;return new DataView(e.buffer,n,4).getFloat32(0,!1)}function be(e,t){if(e.length-t<8)throw new Error(`${D} not enough data for float64`);const n=(e.byteOffset||0)+t;return new DataView(e.buffer,n,8).getFloat64(0,!1)}function ve(e,t,n){throw new Error(`${D} encountered invalid minor (${n}) for major ${e[t]>>>5}`)}function Ee(e){return()=>{throw new Error(`${D} ${e}`)}}le.compareTokens=z.compareTokens;const Me=[];for(let e=0;e<=23;e++)Me[e]=ve;Me[24]=function(e,t,n,r){return new $(T.uint,F(e,t+1,r),2)},Me[25]=function(e,t,n,r){return new $(T.uint,K(e,t+1,r),3)},Me[26]=function(e,t,n,r){return new $(T.uint,_(e,t+1,r),5)},Me[27]=function(e,t,n,r){return new $(T.uint,H(e,t+1,r),9)},Me[28]=ve,Me[29]=ve,Me[30]=ve,Me[31]=ve;for(let e=32;e<=55;e++)Me[e]=ve;Me[56]=function(e,t,n,r){return new $(T.negint,-1-F(e,t+1,r),2)},Me[57]=function(e,t,n,r){return new $(T.negint,-1-K(e,t+1,r),3)},Me[58]=function(e,t,n,r){return new $(T.negint,-1-_(e,t+1,r),5)},Me[59]=function(e,t,n,r){const o=H(e,t+1,r);if("bigint"!=typeof o){const e=-1-o;if(e>=Number.MIN_SAFE_INTEGER)return new $(T.negint,e,9)}if(!0!==r.allowBigInt)throw new Error(`${D} integers outside of the safe integer range are not supported`);return new $(T.negint,G-BigInt(o),9)},Me[60]=ve,Me[61]=ve,Me[62]=ve,Me[63]=ve;for(let e=64;e<=87;e++)Me[e]=J;Me[88]=function(e,t,n,r){return W(e,t,2,F(e,t+1,r))},Me[89]=function(e,t,n,r){return W(e,t,3,K(e,t+1,r))},Me[90]=function(e,t,n,r){return W(e,t,5,_(e,t+1,r))},Me[91]=function(e,t,n,r){const o=H(e,t+1,r);if("bigint"==typeof o)throw new Error(`${D} 64-bit integer bytes lengths not supported`);return W(e,t,9,o)},Me[92]=ve,Me[93]=ve,Me[94]=ve,Me[95]=Ee("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)Me[e]=ee;Me[120]=function(e,t,n,r){return Z(e,t,2,F(e,t+1,r),r)},Me[121]=function(e,t,n,r){return Z(e,t,3,K(e,t+1,r),r)},Me[122]=function(e,t,n,r){return Z(e,t,5,_(e,t+1,r),r)},Me[123]=function(e,t,n,r){const o=H(e,t+1,r);if("bigint"==typeof o)throw new Error(`${D} 64-bit integer string lengths not supported`);return Z(e,t,9,o,r)},Me[124]=ve,Me[125]=ve,Me[126]=ve,Me[127]=Ee("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)Me[e]=re;Me[152]=function(e,t,n,r){return ne(0,0,2,F(e,t+1,r))},Me[153]=function(e,t,n,r){return ne(0,0,3,K(e,t+1,r))},Me[154]=function(e,t,n,r){return ne(0,0,5,_(e,t+1,r))},Me[155]=function(e,t,n,r){const o=H(e,t+1,r);if("bigint"==typeof o)throw new Error(`${D} 64-bit integer array lengths not supported`);return ne(0,0,9,o)},Me[156]=ve,Me[157]=ve,Me[158]=ve,Me[159]=function(e,t,n,r){if(!1===r.allowIndefinite)throw new Error(`${D} indefinite length items not allowed`);return ne(0,0,1,1/0)};for(let e=160;e<=183;e++)Me[e]=ae;Me[184]=function(e,t,n,r){return ie(0,0,2,F(e,t+1,r))},Me[185]=function(e,t,n,r){return ie(0,0,3,K(e,t+1,r))},Me[186]=function(e,t,n,r){return ie(0,0,5,_(e,t+1,r))},Me[187]=function(e,t,n,r){const o=H(e,t+1,r);if("bigint"==typeof o)throw new Error(`${D} 64-bit integer map lengths not supported`);return ie(0,0,9,o)},Me[188]=ve,Me[189]=ve,Me[190]=ve,Me[191]=function(e,t,n,r){if(!1===r.allowIndefinite)throw new Error(`${D} indefinite length items not allowed`);return ie(0,0,1,1/0)};for(let e=192;e<=215;e++)Me[e]=ue;Me[216]=function(e,t,n,r){return new $(T.tag,F(e,t+1,r),2)},Me[217]=function(e,t,n,r){return new $(T.tag,K(e,t+1,r),3)},Me[218]=function(e,t,n,r){return new $(T.tag,_(e,t+1,r),5)},Me[219]=function(e,t,n,r){return new $(T.tag,H(e,t+1,r),9)},Me[220]=ve,Me[221]=ve,Me[222]=ve,Me[223]=ve;for(let e=224;e<=243;e++)Me[e]=Ee("simple values are not supported");Me[244]=ve,Me[245]=ve,Me[246]=ve,Me[247]=function(e,t,n,r){if(!1===r.allowUndefined)throw new Error(`${D} undefined values are not supported`);return!0===r.coerceUndefinedToNull?new $(T.null,null,1):new $(T.undefined,void 0,1)},Me[248]=Ee("simple values are not supported"),Me[249]=function(e,t,n,r){return fe(we(e,t+1),3,r)},Me[250]=function(e,t,n,r){return fe(me(e,t+1),5,r)},Me[251]=function(e,t,n,r){return fe(be(e,t+1),9,r)},Me[252]=ve,Me[253]=ve,Me[254]=ve,Me[255]=function(e,t,n,r){if(!1===r.allowIndefinite)throw new Error(`${D} indefinite length items not allowed`);return new $(T.break,void 0,1)};const Ae=[];for(let e=0;e<24;e++)Ae[e]=new $(T.uint,e,1);for(let e=-1;e>=-24;e--)Ae[31-e]=new $(T.negint,e,1);Ae[64]=new $(T.bytes,new Uint8Array(0),1),Ae[96]=new $(T.string,"",1),Ae[128]=new $(T.array,0,1),Ae[160]=new $(T.map,0,1),Ae[244]=new $(T.false,!1,1),Ae[245]=new $(T.true,!0,1),Ae[246]=new $(T.null,null,1),function(){const e=[];e[T.uint.major]=z,e[T.negint.major]=q,e[T.bytes.major]=Q,e[T.string.major]=te,e[T.array.major]=oe,e[T.map.major]=se,e[T.tag.major]=ce,e[T.float.major]=le}();class Te{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do{if(t.obj===e)return!0}while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${x} object contains circular references`);return new Te(t,e)}}const $e={null:new $(T.null,null),undefined:new $(T.undefined,void 0),true:new $(T.true,!0),false:new $(T.false,!1),emptyArray:new $(T.array,0),emptyMap:new $(T.map,0)},Ie={number:(e,t,n,r)=>Number.isInteger(e)&&Number.isSafeInteger(e)?new $(e>=0?T.uint:T.negint,e):new $(T.float,e),bigint:(e,t,n,r)=>e>=BigInt(0)?new $(T.uint,e):new $(T.negint,e),Uint8Array:(e,t,n,r)=>new $(T.bytes,e),string:(e,t,n,r)=>new $(T.string,e),boolean:(e,t,n,r)=>e?$e.true:$e.false,null:(e,t,n,r)=>$e.null,undefined:(e,t,n,r)=>$e.undefined,ArrayBuffer:(e,t,n,r)=>new $(T.bytes,new Uint8Array(e)),DataView:(e,t,n,r)=>new $(T.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),Array(e,t,n,r){if(!e.length)return!0===n.addBreakTokens?[$e.emptyArray,new $(T.break)]:$e.emptyArray;r=Te.createCheck(r,e);const o=[];let i=0;for(const t of e)o[i++]=Se(t,n,r);return n.addBreakTokens?[new $(T.array,e.length),o,new $(T.break)]:[new $(T.array,e.length),o]},Object(e,t,n,r){const o="Object"!==t,i=o?e.keys():Object.keys(e),a=o?e.size:i.length;if(!a)return!0===n.addBreakTokens?[$e.emptyMap,new $(T.break)]:$e.emptyMap;r=Te.createCheck(r,e);const s=[];let u=0;for(const t of i)s[u++]=[Se(t,n,r),Se(o?e.get(t):e[t],n,r)];return function(e,t){t.mapSorter&&e.sort(t.mapSorter)}(s,n),n.addBreakTokens?[new $(T.map,a),s,new $(T.break)]:[new $(T.map,a),s]}};Ie.Map=Ie.Object,Ie.Buffer=Ie.Uint8Array;for(const e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ie[`${e}Array`]=Ie.DataView;function Se(e,t={},n){const r=A(e),o=t&&t.typeEncoders&&t.typeEncoders[r]||Ie[r];if("function"==typeof o){const i=o(e,r,t,n);if(null!=i)return i}const i=Ie[r];if(!i)throw new Error(`${x} unsupported type: ${r}`);return i(e,r,t,n)}const ke={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0};class Ue{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){const e=this.data[this._pos];let t=Ae[e];if(void 0===t){const n=Me[e];if(!n)throw new Error(`${D} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);const r=31&e;t=n(this.data,this._pos,r,this.options)}return this._pos+=t.encodedLength,t}}const je=Symbol.for("DONE"),Ve=Symbol.for("BREAK");function Be(e,t){if(e.done())return je;const n=e.next();if(n.type===T.break)return Ve;if(n.type.terminal)return n.value;if(n.type===T.array)return function(e,t,n){const r=[];for(let o=0;o<e.value;o++){const i=Be(t,n);if(i===Ve){if(e.value===1/0)break;throw new Error(`${D} got unexpected break to lengthed array`)}if(i===je)throw new Error(`${D} found array but not enough entries (got ${o}, expected ${e.value})`);r[o]=i}return r}(n,e,t);if(n.type===T.map)return function(e,t,n){const r=!0===n.useMaps,o=r?void 0:{},i=r?new Map:void 0;for(let a=0;a<e.value;a++){const s=Be(t,n);if(s===Ve){if(e.value===1/0)break;throw new Error(`${D} got unexpected break to lengthed map`)}if(s===je)throw new Error(`${D} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(!0!==r&&"string"!=typeof s)throw new Error(`${D} non-string keys not supported (got ${typeof s})`);if(!0===n.rejectDuplicateMapKeys&&(r&&i.has(s)||!r&&s in o))throw new Error(`${D} found repeat map key "${s}"`);const u=Be(t,n);if(u===je)throw new Error(`${D} found map but not enough entries (got ${a} [no value], expected ${e.value})`);r?i.set(s,u):o[s]=u}return r?i:o}(n,e,t);if(n.type===T.tag){if(t.tags&&"function"==typeof t.tags[n.value]){const r=Be(e,t);return t.tags[n.value](r)}throw new Error(`${D} tag not supported (${n.value})`)}throw new Error("unsupported")}function Pe(e,t){const[n,r]=function(e,t){if(!(e instanceof Uint8Array))throw new Error(`${D} data to decode must be a Uint8Array`);const n=(t=Object.assign({},ke,t)).tokenizer||new Ue(e,t),r=Be(n,t);if(r===je)throw new Error(`${D} did not find any content to decode`);if(r===Ve)throw new Error(`${D} got unexpected break`);return[r,e.subarray(n.pos())]}(e,t);if(r.length>0)throw new Error(`${D} too many terminals, data makes no sense`);return n}
|
|
14
|
+
/*!
|
|
15
|
+
* Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
|
|
16
|
+
*/const Re=new Uint8Array([217,93,1]),Ne=[];function De({proof:e}={}){try{if("string"!=typeof e?.proofValue)throw new TypeError('"proof.proofValue" must be a string.');if("u"!==e.proofValue[0])throw new Error("Only base64url multibase encoding is supported.");const t=o(e.proofValue.slice(1));if(!function(e,t){for(let n=0;n<t.length;++n)if(e[n]!==t[n])return!1;return!0}(t,Re))throw new TypeError('"proof.proofValue" must be a derived proof.');const n=t.subarray(Re.length),[r,i,s,u,c]=Pe(n,{useMaps:!0,tags:Ne}),f=function(e){const t=new Map;for(const[n,r]of e.entries())t.set(`c14n${n}`,`u${a(r)}`);return t}(u),l={baseSignature:r,publicKey:i,signatures:s,labelMap:f,mandatoryIndexes:c};return function({baseSignature:e,publicKey:t,signatures:n,labelMap:r,mandatoryIndexes:o}){if(!(e instanceof Uint8Array&&64===e.length))throw new TypeError('"baseSignature" must be a Uint8Array of length 64.');if(!(t instanceof Uint8Array&&35===t.length))throw new TypeError('"publicKey" must be a Uint8Array of length 35.');if(!Array.isArray(n)||!n.every(e=>e instanceof Uint8Array))throw new TypeError('"signatures" must be an array of Uint8Arrays.');if(!(r instanceof Map&&[...r.entries()].every(([e,t])=>"string"==typeof e&&"string"==typeof t)))throw new TypeError('"labelMap" must be a Map of strings to strings.');if(!Array.isArray(o)||!o.every(Number.isInteger))throw new TypeError('"mandatoryIndexes" must be an array of integers.')}(l),l}catch(e){const t=new TypeError('The proof does not include a valid "proofValue" property.');throw t.cause=e,t}}function xe({proofHash:e,publicKey:t,mandatoryHash:n}={}){!function({proofHash:e,publicKey:t,mandatoryHash:n}){if(!(e instanceof Uint8Array&&32===e.length))throw new TypeError('"proofHash" must be a Uint8Array of length 32.');if(!(t instanceof Uint8Array&&35===t.length))throw new TypeError('"publicKey" must be a Uint8Array of length 35.');if(!(n instanceof Uint8Array&&32===n.length))throw new TypeError('"mandatoryHash" must be a Uint8Array of length 32.')}({proofHash:e,publicKey:t,mandatoryHash:n});return function(e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;for(const r of e)t.set(r,n),n+=r.length;return t}([e,t,n])}Ne[64]=function(e){return e}
|
|
17
|
+
/*!
|
|
18
|
+
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
|
|
19
|
+
*/;const Ce="ecdsa-sd-2023";
|
|
20
|
+
/*!
|
|
21
|
+
* Copyright (c) 2022-2023 Digital Bazaar, Inc. All rights reserved.
|
|
22
|
+
*/
|
|
23
|
+
/*!
|
|
24
|
+
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
|
|
25
|
+
*/
|
|
26
|
+
function Oe({requiredAlgorithm:e="P-256"}={}){return{name:Ce,requiredAlgorithm:e,createVerifier:Fe,createVerifyData:Ke}}async function Fe({verificationMethod:e}){const t=(await l(e)).verifier();return{algorithm:t.algorithm,id:t.id,verify:async({data:e})=>async function({verifier:e,data:t}={}){const{baseSignature:n,proofHash:r,publicKey:o,signatures:a,nonMandatory:s,mandatoryHash:u}=t,c="z"+i(o),f=await l({publicKeyMultibase:c});if(a.length!==s.length)throw new Error(`Signature count (${a.length}) does not match non-mandatory message count (${s.length}).`);const{verify:d}=f.verifier();if((await Promise.all(a.map((e,t)=>d({data:g(s[t]),signature:e})))).some(e=>!e))return!1;const h=await xe({proofHash:r,publicKey:o,mandatoryHash:u});return e.verify({data:h,signature:n})}({verifier:t,data:e})}}async function Ke({cryptosuite:e,document:t,proof:n,documentLoader:r}){if(e?.name!==Ce)throw new TypeError(`"cryptosuite.name" must be "${Ce}".`);const o={documentLoader:r},i=v({document:t,proof:n,options:o}).catch(e=>e),{baseSignature:a,publicKey:s,signatures:u,labelMap:c,mandatoryIndexes:f}=await De({proof:n}),l=await function({labelMap:e}={}){return async({canonicalIdMap:t})=>{const n=new Map;for(const[r,o]of t)n.set(r,e.get(o));return n}}({labelMap:c}),d=await m({document:t,labelMapFactoryFunction:l,options:o}),h=[],p=[];for(const[e,t]of d.entries())f.includes(e)?h.push(t):p.push(t);const{mandatoryHash:w}=await async function({mandatory:e,hasher:t}={}){return t||(t=y()),{mandatoryHash:await t.hash(g(e.join("")))}}({mandatory:h}),b=await i;if(b instanceof Error)throw b;return{baseSignature:a,proofHash:b,publicKey:s,signatures:u,nonMandatory:p,mandatoryHash:w}}const{purposes:{AssertionProofPurpose:_e,AuthenticationProofPurpose:He}}=s;var ze;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.ensureVerificationMethodValidity="ensureVerificationMethodValidity",e.checkDocumentSignature="checkDocumentSignature"}(ze||(ze={}));class Le extends d{verificationProcess=[ze.retrieveVerificationMethodPublicKey,ze.ensureVerificationMethodValidity,ze.checkDocumentSignature];documentToVerify;issuer;proof;type="EcdsaSd2023";cryptosuite="ecdsa-sd-2023";publicKey;verificationKey;verificationMethod;proofPurpose;challenge;domain;proofPurposeMap;constructor(e){super(e),e.executeStep&&(this.executeStep=e.executeStep),this.documentToVerify=e.document,this.issuer=e.issuer,this.proof=e.proof,this.proofPurpose=e.proofPurpose??"assertionMethod",this.challenge=e.proofChallenge??"",this.domain=e.proofDomain,this.proofPurposeMap={authentication:He,assertionMethod:_e},this.validateProofType()}async init(){}async verifyProof(){for(const e of this.verificationProcess){if(!this[e])return void console.error("verification logic for",e,"not implemented");await this[e]()}}async verifyIdentity(){}getProofVerificationSteps(t){return this.verificationProcess.map(n=>e.verifier.convertToVerificationSubsteps(t,n))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return this.publicKey}getIssuerName(){return this.issuer.name??""}getIssuerProfileDomain(){try{return new URL(this.getIssuerProfileUrl()).hostname??""}catch(e){return""}}getIssuerProfileUrl(){return this.issuer.id??""}getSigningDate(){return this.proof.created}async executeStep(e,t,n){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}validateProofType(){const e=this.proof.type;if("DataIntegrityProof"===e){const e=this.proof.cryptosuite;if(!e)throw new Error(`Malformed proof passed. With DataIntegrityProof a cryptosuite must be defined. Expected: ${this.cryptosuite}`);if(e!==this.cryptosuite)throw new Error(`Incompatible proof cryptosuite passed. Expected: ${this.cryptosuite}, Got: ${e}`);return}if(e!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${e}`)}generateDocumentLoader(e=[]){e.forEach(e=>{t[e.url]=e.value}),t[this.documentToVerify.issuer]=this.getTargetVerificationMethodContainer();return function(e){return e in t?{contextUrl:null,document:t[e],documentUrl:e}:u.documentLoader(e)}}getErrorMessage(e){return e.error.errors[0].message}getTargetVerificationMethodContainer(){if(this.issuer.didDocument){if(this.findVerificationMethod(this.issuer.didDocument.verificationMethod,this.issuer.didDocument.id))return this.issuer.didDocument}const e={...this.issuer};return delete e.didDocument,e}findVerificationMethod(e,t){return e.find(e=>e.id===this.proof.verificationMethod||t+e.id===this.proof.verificationMethod)??null}async retrieveVerificationMethodPublicKey(){this.verificationKey=await this.executeStep(ze.retrieveVerificationMethodPublicKey,async()=>{if(this.verificationMethod=h(this.getTargetVerificationMethodContainer(),this.proof.verificationMethod),!this.verificationMethod)throw new n(ze.retrieveVerificationMethodPublicKey,"Could not derive the verification key",r.CRYPTOGRAPHIC_SECURITY_ERROR);if(this.verificationMethod.revoked)throw new n(ze.retrieveVerificationMethodPublicKey,"The verification key has been revoked",r.CRYPTOGRAPHIC_SECURITY_ERROR);return this.verificationMethod},this.type)}async ensureVerificationMethodValidity(){await this.executeStep(ze.ensureVerificationMethodValidity,async()=>{if(this.verificationMethod.expires){if(new Date(this.verificationMethod.expires).getTime()<Date.now())throw new n(ze.ensureVerificationMethodValidity,"The verification key has expired",r.CRYPTOGRAPHIC_SECURITY_ERROR)}if(this.verificationMethod.revoked)throw new n(ze.ensureVerificationMethodValidity,"The verification key has been revoked",r.CRYPTOGRAPHIC_SECURITY_ERROR)},this.type)}async checkDocumentSignature(){await this.executeStep(ze.checkDocumentSignature,async()=>{const e=new c({cryptosuite:Oe({requiredAlgorithm:"K-256"})}),t=this.documentToVerify.proof.verificationMethod;"authentication"!==this.proofPurpose||this.proof.challenge||(this.proof.challenge="");const o=await s.verify(this.documentToVerify,{suite:e,purpose:new this.proofPurposeMap[this.proofPurpose]({controller:this.getTargetVerificationMethodContainer(),challenge:this.challenge,domain:this.domain}),documentLoader:this.generateDocumentLoader([{url:t,value:this.verificationKey}])});if(!o.verified)throw console.error(JSON.stringify(o,null,2)),new n(ze.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed: ${this.getErrorMessage(o)}`,r.PROOF_VERIFICATION_ERROR);console.log(`Credential ${this.type} signature successfully verified`)},this.type)}}export{Le as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as e,p as t,a as i,x as o,y as r,E as n,V as s,P as c}from"./main.js";import{j as a}from"./jsonld-signatures-BJXipuab-CB799Kkm.js";import{j as d}from"./jsonld-DOUjwF6J-dtl20tiV.js";import{S as h}from"./Suite-BmP2Qu19-D1ucdMDB.js";import"./index-yOIIz7AL-Dgus2xdV.js";import{r as u}from"./retrieveVerificationMethodPublicKey-CT9YA_Wr-Djl8Ri41.js";const p="https://ns.did.ai/suites/secp256k1-2019/v1",f="https://www.w3.org/ns/credentials/v2",y=({document:e,contextUrl:t})=>{const i=e["@context"];return Array.isArray(i)?t.some(e=>i.includes(e)):t.includes(i)},l=({document:e})=>{const t=y({document:e,contextUrl:[p,"https://w3id.org/security/suites/secp256k1-2019/v1"]}),i=y({document:e,contextUrl:["https://www.w3.org/2018/credentials/v1"]}),o=y({document:e,contextUrl:[f]}),r=y({document:e,contextUrl:["https://w3id.org/security/v2"]});return t&&i?(console.warn("Warning: The secp256k1-2019/v1 and credentials/v1 contexts are incompatible."),console.warn("For VCs using EcdsaSecp256k1Signature2019 suite, using the credentials/v1 context is sufficient."),!1):!t&&o?(console.warn("This library does not (yet) follow the Data Integrity Proof format."),console.warn("When using the credentials/v2 context, consumers need to specify the secp256k1-2019/v1 context."),!1):t&&r?(console.warn("Warning: The secp256k1-2019/v1 and security/v2 contexts are incompatible."),console.warn("For VCs using EcdsaSecp256k1Signature2019 suite, using the security/v2 context is sufficient."),!1):t||i||r};let w=class extends a.suites.LinkedDataSignature{requiredKeyType;constructor(e={}){super({type:"EcdsaSecp256k1Signature2019",LDKeyClass:n,contextUrl:p,...e}),this.requiredKeyType="EcdsaSecp256k1VerificationKey2019"}async sign({verifyData:e,proof:t}){if(!this.signer||"function"!=typeof this.signer.sign)throw new Error("A signer API has not been specified.");return{...t,jws:await this.signer.sign({data:e})}}async verifySignature({verifyData:e,verificationMethod:t,proof:i}){const{jws:o}=i;if(!o||"string"!=typeof o)throw new TypeError('The proof does not include a valid "jws" property.');let{verifier:r}=this;if(!r){r=(await this.LDKeyClass.from(t)).verifier()}return r.verify({data:e,signature:o})}async assertVerificationMethod({verificationMethod:e}){if(!l({document:e}))throw new TypeError(`The verification method (key) must contain "${this.contextUrl}".`);if(!d.hasValue(e,"type",this.requiredKeyType))throw new Error(`Invalid key type. Key type must be "${this.requiredKeyType}".`);if(void 0!==e.revoked)throw new Error("The verification method has been revoked.")}async getVerificationMethod({proof:e,documentLoader:t}){if(this.key)return this.key.export({publicKey:!0});const i="object"==typeof e.verificationMethod?e.verificationMethod.id:e.verificationMethod;if(!i)throw new Error('No "verificationMethod" found in proof.');const o=await d.frame(i,{"@context":this.contextUrl,"@embed":"@always",id:i},{documentLoader:t,compactToRelative:!1});if(!o)throw new Error(`Verification method ${i} not found.`);if(void 0!==o.revoked)throw new Error("The verification method has been revoked.");return await this.assertVerificationMethod({verificationMethod:o}),o}async matchProof({proof:e,document:t,purpose:i,documentLoader:o,expansionMap:r}){if(!l({document:t}))return!1;if(!await super.matchProof({proof:e,document:t,purpose:i,documentLoader:o,expansionMap:r}))return!1;if(!this.key)return!0;const{verificationMethod:n}=e,s="object"==typeof n?n.id:n;return this.isVerificationMethodMatchingKeyId(s)}ensureSuiteContext({document:e,addSuiteContext:t}){l({document:e})&&!y({document:e,contextUrl:[f]})||super.ensureSuiteContext({document:e,addSuiteContext:t})}isVerificationMethodMatchingKeyId(e){return e===this.key.id||e===`${this.key.controller}${this.key.id}`}};w.CONTEXT_URL=p,w.CONTEXT={"@context":{id:"@id",type:"@type","@protected":!0,proof:{"@id":"https://w3id.org/security#proof","@type":"@id","@container":"@graph"},EcdsaSecp256k1VerificationKey2019:{"@id":"https://w3id.org/security#EcdsaSecp256k1VerificationKey2019","@context":{"@protected":!0,id:"@id",type:"@type",controller:{"@id":"https://w3id.org/security#controller","@type":"@id"},revoked:{"@id":"https://w3id.org/security#revoked","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},blockchainAccountId:{"@id":"https://w3id.org/security#blockchainAccountId"},publicKeyJwk:{"@id":"https://w3id.org/security#publicKeyJwk","@type":"@json"},publicKeyBase58:{"@id":"https://w3id.org/security#publicKeyBase58"},publicKeyMultibase:{"@id":"https://w3id.org/security#publicKeyMultibase","@type":"https://w3id.org/security#multibase"}}},EcdsaSecp256k1Signature2019:{"@id":"https://w3id.org/security#EcdsaSecp256k1Signature2019","@context":{"@protected":!0,id:"@id",type:"@type",challenge:"https://w3id.org/security#challenge",created:{"@id":"http://purl.org/dc/terms/created","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},domain:"https://w3id.org/security#domain",expires:{"@id":"https://w3id.org/security#expiration","@type":"http://www.w3.org/2001/XMLSchema#dateTime"},nonce:"https://w3id.org/security#nonce",proofPurpose:{"@id":"https://w3id.org/security#proofPurpose","@type":"@vocab","@context":{"@protected":!0,id:"@id",type:"@type",assertionMethod:{"@id":"https://w3id.org/security#assertionMethod","@type":"@id","@container":"@set"},authentication:{"@id":"https://w3id.org/security#authenticationMethod","@type":"@id","@container":"@set"},capabilityInvocation:{"@id":"https://w3id.org/security#capabilityInvocationMethod","@type":"@id","@container":"@set"},capabilityDelegation:{"@id":"https://w3id.org/security#capabilityDelegationMethod","@type":"@id","@container":"@set"},keyAgreement:{"@id":"https://w3id.org/security#keyAgreementMethod","@type":"@id","@container":"@set"}}},jws:{"@id":"https://w3id.org/security#jws"},verificationMethod:{"@id":"https://w3id.org/security#verificationMethod","@type":"@id"}}}}};const{purposes:{AssertionProofPurpose:g,AuthenticationProofPurpose:m}}=a;var v;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.ensureVerificationMethodValidity="ensureVerificationMethodValidity",e.checkDocumentSignature="checkDocumentSignature"}(v||(v={}));class M extends h{verificationProcess=[v.retrieveVerificationMethodPublicKey,v.ensureVerificationMethodValidity,v.checkDocumentSignature];documentToVerify;issuer;proof;type="EcdsaSecp256k1Signature2019";verificationKey;verificationMethod;publicKey;proofPurpose;challenge;domain;proofPurposeMap;constructor(e){super(e),e.executeStep&&(this.executeStep=e.executeStep),this.documentToVerify=e.document,this.issuer=e.issuer,this.proof=e.proof,this.proofPurpose=e.proofPurpose??"assertionMethod",this.challenge=e.proofChallenge??"",this.domain=e.proofDomain,this.proofPurposeMap={authentication:m,assertionMethod:g},this.validateProofType()}async init(){}async verifyProof(){for(const e of this.verificationProcess){if(!this[e])return void console.error("verification logic for",e,"not implemented");await this[e]()}}async verifyIdentity(){}getProofVerificationSteps(t){return this.verificationProcess.map(i=>e.verifier.convertToVerificationSubsteps(t,i))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return this.publicKey}getIssuerName(){return this.issuer.name??""}getIssuerProfileDomain(){try{return new URL(this.getIssuerProfileUrl()).hostname??""}catch(e){return""}}getIssuerProfileUrl(){return this.issuer.id??""}getSigningDate(){return this.proof.created}async executeStep(e,t,i){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}validateProofType(){const e=this.isProofChain()?this.proof.chainedProofType:this.proof.type;if(e!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${e}`)}isProofChain(){return"ChainedProof2021"===this.proof.type}generateDocumentLoader(){t[this.documentToVerify.issuer]=this.getTargetVerificationMethodContainer();return function(e){return e in t?{contextUrl:null,document:t[e],documentUrl:e}:d.documentLoader(e)}}retrieveInitialDocument(){const e=i(this.documentToVerify);if(Array.isArray(e.proof)){const t=e.proof.find(e=>e.type===this.type);delete e.proof,e.proof=t}return e}getTargetVerificationMethodContainer(){if(this.issuer.didDocument){if(this.findVerificationMethod(this.issuer.didDocument.verificationMethod,this.issuer.didDocument.id))return this.issuer.didDocument}const e={...this.issuer};return delete e.didDocument,e}findVerificationMethod(e,t){return e.find(e=>e.id===this.proof.verificationMethod||t+e.id===this.proof.verificationMethod)??null}getErrorMessage(e){return e.error.errors[0].message}async retrieveVerificationMethodPublicKey(){this.verificationKey=await this.executeStep(v.retrieveVerificationMethodPublicKey,async()=>{if(this.verificationMethod=u(this.getTargetVerificationMethodContainer(),this.proof.verificationMethod),this.verificationMethod.publicKeyJwk&&!this.verificationMethod.publicKeyBase58){const e=o(this.verificationMethod.publicKeyJwk);this.verificationMethod.publicKeyBase58=r(e),this.documentToVerify["@context"].includes("https://www.w3.org/ns/credentials/v2")&&!this.documentToVerify["@context"].includes("https://w3id.org/security/suites/secp256k1-2019/v1")&&this.documentToVerify["@context"].push("https://w3id.org/security/suites/secp256k1-2019/v1")}this.publicKey=this.verificationMethod.publicKeyBase58;const e=n.from({...this.verificationMethod});if(!e)throw new s(v.retrieveVerificationMethodPublicKey,"Could not derive the verification key",c.CRYPTOGRAPHIC_SECURITY_ERROR);if(e.revoked)throw new s(v.retrieveVerificationMethodPublicKey,"The verification key has been revoked",c.CRYPTOGRAPHIC_SECURITY_ERROR);return e},this.type)}async ensureVerificationMethodValidity(){await this.executeStep(v.ensureVerificationMethodValidity,async()=>{if(this.verificationMethod.expires){if(new Date(this.verificationMethod.expires).getTime()<Date.now())throw new s(v.ensureVerificationMethodValidity,"The verification key has expired",c.CRYPTOGRAPHIC_SECURITY_ERROR)}if(this.verificationMethod.revoked)throw new s(v.ensureVerificationMethodValidity,"The verification key has been revoked",c.CRYPTOGRAPHIC_SECURITY_ERROR)},this.type)}async checkDocumentSignature(){await this.executeStep(v.checkDocumentSignature,async()=>{const e=new w({key:this.verificationKey});e.date=new Date(Date.now()).toISOString(),"authentication"!==this.proofPurpose||this.proof.challenge||(this.proof.challenge="");const t=await a.verify(this.retrieveInitialDocument(),{suite:e,purpose:new this.proofPurposeMap[this.proofPurpose]({controller:this.getTargetVerificationMethodContainer(),challenge:this.challenge,domain:this.domain}),documentLoader:this.generateDocumentLoader()});if(!t.verified)throw console.error(JSON.stringify(t,null,2)),new s(v.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed: ${this.getErrorMessage(t)}`,c.PROOF_VERIFICATION_ERROR);console.log("Credential Secp256k1 signature successfully verified")},this.type)}}export{M as default};
|
package/dist/{Ed25519Signature2020-B6yblwC5-BRlzT2Yc.js → Ed25519Signature2020-CDbX0d2Z-Dc1L-exZ.js}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import{d as e,
|
|
1
|
+
import{d as e,t,p as i,a as r,V as o,P as n,f as s,u as a,v as c,w as u}from"./main.js";import{j as d}from"./jsonld-signatures-BJXipuab-CB799Kkm.js";import{j as p}from"./jsonld-DOUjwF6J-dtl20tiV.js";import{f as y,v as h,s as f,g as l}from"./index-C4ZZHHRx-BOdwDnYa.js";import{S as w}from"./Suite-BmP2Qu19-D1ucdMDB.js";import"./_polyfill-node.crypto-MVmI5M_M-exGcp6nW.js";
|
|
2
2
|
/*!
|
|
3
3
|
* Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
|
|
4
|
-
*/function
|
|
4
|
+
*/function b({bytes:e,expectedLength:t=32,code:i}){if(!(e instanceof Uint8Array))throw new TypeError('"bytes" must be a Uint8Array.');if(e.length!==t){const e=new Error(`"bytes" must be a ${t}-byte Uint8Array.`);throw e.name="DataError",i&&(e.code=i),e}}
|
|
5
5
|
/*!
|
|
6
6
|
* Copyright (c) 2020-2022 Digital Bazaar, Inc. All rights reserved.
|
|
7
|
-
*/const
|
|
7
|
+
*/const g=globalThis.crypto;if(!g.getRandomValues)throw new Error('Browser does not provide "crypto.getRandomValues".');var v={async generateKeyPair(){const e=new Uint8Array(32);g.getRandomValues(e);const t=await m(e);return e.fill(0),t},generateKeyPairFromSeed:m,sign:async(e,t)=>f(t,e.slice(0,32)),verify:async(e,t,i)=>h(i,t,e),sha256digest:async({data:e})=>g.subtle.digest("SHA-256",e)};async function m(e){b({bytes:e,expectedLength:32});const t=await l(e),i=new Uint8Array(64);return i.set(e),i.set(t,e.length),{publicKey:t,secretKey:i}}
|
|
8
8
|
/*!
|
|
9
9
|
* Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved.
|
|
10
|
-
*/class
|
|
10
|
+
*/class K{constructor({id:e,controller:t,revoked:i}={}){this.id=e,this.controller=t,this.revoked=i}static async generate(){throw new Error("Abstract method, must be implemented in subclass.")}static async fromKeyDocument({document:e,checkContext:t=!0,checkRevoked:i=!0}={}){if(!e)throw new TypeError('The "document" parameter is required.');if(t){if(![].concat(e["@context"]).includes(this.SUITE_CONTEXT))throw new Error('Key document does not contain required context "'+this.SUITE_CONTEXT+'".')}if(i&&e.revoked)throw new Error(`Key has been revoked since: "${e.revoked}".`);return this.from(e)}static async from(){throw new Error("Abstract method from() must be implemented in subclass.")}export({publicKey:e=!1,privateKey:t=!1}={}){if(!e&&!t)throw new Error('Export requires specifying either "publicKey" or "privateKey".');const i={id:this.id,type:this.type,controller:this.controller};return this.revoked&&(i.revoked=this.revoked),i}fingerprint(){throw new Error("Abstract method, must be implemented in subclass.")}verifyFingerprint(){throw new Error("Abstract method, must be implemented in subclass.")}signer(){return{async sign({}){throw new Error("Abstract method, must be implemented in subclass.")}}}verifier(){return{async verify({}){throw new Error("Abstract method, must be implemented in subclass.")}}}}K.SUITE_CONTEXT="INVALID LDKeyPair CONTEXT";
|
|
11
11
|
/*!
|
|
12
12
|
* Copyright (c) 2021-2024 Digital Bazaar, Inc. All rights reserved.
|
|
13
13
|
*/
|
|
14
|
-
const
|
|
14
|
+
const E="Ed25519VerificationKey2020",T=new Uint8Array([237,1]),M=new Uint8Array([128,38]);class P extends K{constructor(e={}){super(e),this.type=E;const{publicKeyMultibase:t,privateKeyMultibase:i}=e;if(!t)throw new TypeError('The "publicKeyMultibase" property is required.');if(!t||!k(t,T))throw new Error(`"publicKeyMultibase" has invalid header bytes: "${t}".`);if(i&&!k(i,M))throw new Error('"privateKeyMultibase" has invalid header bytes.');this.publicKeyMultibase=t,this.privateKeyMultibase=i,this.controller&&!this.id&&(this.id=`${this.controller}#${this.fingerprint()}`),b({bytes:this._publicKeyBuffer,code:"invalidPublicKeyLength",expectedLength:32})}static async from(e){return"Ed25519VerificationKey2018"===e.type?P.fromEd25519VerificationKey2018(e):"JsonWebKey"===e.type||"JsonWebKey2020"===e.type?P.fromJsonWebKey(e):new P(e)}static fromEd25519VerificationKey2018({keyPair:e}={}){const t=x(T,s(e.publicKeyBase58)),i=new P({id:e.id,controller:e.controller,publicKeyMultibase:t});return e.privateKeyBase58&&(i.privateKeyMultibase=x(M,s(e.privateKeyBase58))),i}static fromJsonWebKey2020({id:e,type:t,controller:i,publicKeyJwk:r}={}){if("JsonWebKey2020"!==t)throw new TypeError(`Invalid key type: "${t}".`);return P.fromJsonWebKey({id:e,type:t,controller:i,publicKeyJwk:r})}static fromJsonWebKey({id:e,type:t,controller:i,publicKeyJwk:r}={}){if("JsonWebKey"!==t&&"JsonWebKey2020"!==t)throw new TypeError(`Invalid key type: "${t}".`);if(!r)throw new TypeError('"publicKeyJwk" property is required.');const{kty:o,crv:n}=r;if("OKP"!==o)throw new TypeError('"kty" is required to be "OKP".');if("Ed25519"!==n)throw new TypeError('"crv" is required to be "Ed25519".');const{x:s}=r,c=x(T,a(s));return P.from({id:e,controller:i,publicKeyMultibase:c})}static async generate({seed:e,...t}={}){let i;i=e?await v.generateKeyPairFromSeed(e):await v.generateKeyPair();const r=x(T,i.publicKey),o=x(M,i.secretKey);return new P({publicKeyMultibase:r,privateKeyMultibase:o,...t})}static fromFingerprint({fingerprint:e}={}){return new P({publicKeyMultibase:e})}get _publicKeyBuffer(){if(!this.publicKeyMultibase)return;return s(this.publicKeyMultibase.substr(1)).slice(T.length)}get _privateKeyBuffer(){if(!this.privateKeyMultibase)return;return s(this.privateKeyMultibase.substr(1)).slice(M.length)}fingerprint(){return this.publicKeyMultibase}export({publicKey:e=!1,privateKey:t=!1,includeContext:i=!1}={}){if(!e&&!t)throw new TypeError('Export requires specifying either "publicKey" or "privateKey".');const r={id:this.id,type:this.type};return i&&(r["@context"]=P.SUITE_CONTEXT),this.controller&&(r.controller=this.controller),e&&(r.publicKeyMultibase=this.publicKeyMultibase),t&&(r.privateKeyMultibase=this.privateKeyMultibase),this.revoked&&(r.revoked=this.revoked),r}toJwk({publicKey:e=!0,privateKey:t=!1}={}){if(!e&&!t)throw TypeError('Either a "publicKey" or a "privateKey" is required.');const i={crv:"Ed25519",kty:"OKP"};return e&&(i.x=c(this._publicKeyBuffer)),t&&(i.d=c(this._privateKeyBuffer)),i}async jwkThumbprint(){const e=`{"crv":"Ed25519","kty":"OKP","x":"${c(this._publicKeyBuffer)}"}`,t=(new TextEncoder).encode(e);return c(new Uint8Array(await v.sha256digest({data:t})))}async toJsonWebKey(){return{"@context":"https://w3id.org/security/jwk/v1",id:this.controller+"#"+await this.jwkThumbprint(),type:"JsonWebKey",controller:this.controller,publicKeyJwk:this.toJwk({publicKey:!0})}}async toJsonWebKey2020(){return{"@context":"https://w3id.org/security/jws/v1",id:this.controller+"#"+await this.jwkThumbprint(),type:"JsonWebKey2020",controller:this.controller,publicKeyJwk:this.toJwk({publicKey:!0})}}verifyFingerprint({fingerprint:e}={}){if("string"!=typeof e||"z"!==e[0])return{error:new Error('"fingerprint" must be a multibase encoded string.'),valid:!1};let t;try{if(t=s(e.substr(1)),!t)throw new TypeError("Invalid encoding of fingerprint.")}catch(e){return{error:e,valid:!1}}const i=function(e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(e[i]!==t[i])return!1;return!0}(this._publicKeyBuffer,t.slice(2)),r=t[0]===T[0]&&t[1]===T[1]&&i;return r?{valid:r}:{error:new Error("The fingerprint does not match the public key."),valid:!1}}signer(){const e=this._privateKeyBuffer;return{async sign({data:t}){if(!e)throw new Error("A private key is not available for signing.");return v.sign(e,t)},id:this.id}}verifier(){const e=this._publicKeyBuffer;return{async verify({data:t,signature:i}){if(!e)throw new Error("A public key is not available for verifying.");return v.verify(e,t,i)},id:this.id}}}function k(e,t){if("string"!=typeof e||"z"!==e[0])return!1;const i=s(e.slice(1));return t.every((e,t)=>i[t]===e)}function x(e,t){const i=new Uint8Array(e.length+t.length);return i.set(e),i.set(t,e.length),"z"+u(i)}P.suite=E,P.SUITE_CONTEXT="https://w3id.org/security/suites/ed25519-2020/v1";var V,C,R=(function(e,t){!function(e,t){for(var i in t)e[i]=t[i]}(t,function(e){var t={};function i(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=e,i.c=t,i.d=function(e,t,r){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)i.d(r,o,function(t){return e[t]}.bind(null,o));return r},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=2)}([function(e,t,i){
|
|
15
15
|
/*!
|
|
16
16
|
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
17
17
|
*/
|
|
@@ -27,8 +27,8 @@ const r=i(0),o=i(1),{documentLoader:n}=i(3),{CONTEXT_URL:s,CBORLD_CODEC_VALUE:a}
|
|
|
27
27
|
/*!
|
|
28
28
|
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
29
29
|
*/
|
|
30
|
-
const{CONTEXT_URL:r}=i(1),o=i(0);e.exports={documentLoader(e){if(e!==r)throw new Error(`Loading document "${e}" is not allowed.`);return{contextUrl:null,document:o,documentUrl:e}}}}]))}(V={exports:{}},V.exports),V.exports),
|
|
30
|
+
const{CONTEXT_URL:r}=i(1),o=i(0);e.exports={documentLoader(e){if(e!==r)throw new Error(`Loading document "${e}" is not allowed.`);return{contextUrl:null,document:o,documentUrl:e}}}}]))}(V={exports:{}},V.exports),V.exports),O=(C=R)&&C.__esModule&&Object.prototype.hasOwnProperty.call(C,"default")?C.default:C;R.contexts,R.constants,R.CONTEXT,R.CONTEXT_URL,R.appContextMap,R.documentLoader;
|
|
31
31
|
/*!
|
|
32
32
|
* Copyright (c) 2020-2024 Digital Bazaar, Inc. All rights reserved.
|
|
33
33
|
*/
|
|
34
|
-
const{suites:{LinkedDataSignature:
|
|
34
|
+
const{suites:{LinkedDataSignature:S}}=d,_=O.constants.CONTEXT_URL;let U=class extends S{constructor({key:e,signer:t,verifier:i,proof:r,date:o,useNativeCanonize:n,canonizeOptions:s}={}){super({type:"Ed25519Signature2020",LDKeyClass:P,contextUrl:_,key:e,signer:t,verifier:i,proof:r,date:o,useNativeCanonize:n,canonizeOptions:s}),this.requiredKeyType="Ed25519VerificationKey2020"}async sign({verifyData:e,proof:t}){if(!this.signer||"function"!=typeof this.signer.sign)throw new Error("A signer API has not been specified.");const i=await this.signer.sign({data:e});return t.proofValue="z"+u(i),t}async verifySignature({verifyData:e,verificationMethod:t,proof:i}){const{proofValue:r}=i;if(!r||"string"!=typeof r)throw new TypeError('The proof does not include a valid "proofValue" property.');if("z"!==r[0])throw new Error("Only base58btc multibase encoding is supported.");const o=s(r.substr(1));let{verifier:n}=this;if(!n){n=(await y(t)).verifier()}return n.verify({data:e,signature:o})}async assertVerificationMethod({verificationMethod:e}){let t;if("Ed25519VerificationKey2020"!==e.type)throw new Error(`Unsupported key type "${e.type}".`);if(t=_,!I({document:e,contextUrl:t}))throw new TypeError(`The verification method (key) must contain "${t}" context.`);if(void 0!==e.revoked)throw new Error("The verification method has been revoked.")}async getVerificationMethod({proof:e,documentLoader:t}){if(this.key)return this.key.export({publicKey:!0});let{verificationMethod:i}=e;if("object"==typeof i&&(i=i.id),!i)throw new Error('No "verificationMethod" found in proof.');const{document:r}=await t(i);i="string"==typeof r?JSON.parse(r):r;const o=await y(i);return i={...await o.export({publicKey:!0,includeContext:!0}),"@context":_,type:"Ed25519VerificationKey2020"},await this.assertVerificationMethod({verificationMethod:i}),i}async matchProof({proof:e,document:t,purpose:i,documentLoader:r}){if(!I({document:t,contextUrl:_}))return!1;if(!await super.matchProof({proof:e,document:t,purpose:i,documentLoader:r}))return!1;if(!this.key)return!0;const{verificationMethod:o}=e;return"object"==typeof o?o.id===this.key.id:o===this.key.id}};function I({document:e,contextUrl:t}){const i=e["@context"];return i===t||Array.isArray(i)&&i.includes(t)}U.CONTEXT_URL=_,U.CONTEXT=O.contexts.get(_);const{purposes:{AssertionProofPurpose:A,AuthenticationProofPurpose:D}}=d;var L;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.ensureVerificationMethodValidity="ensureVerificationMethodValidity",e.checkDocumentSignature="checkDocumentSignature"}(L||(L={}));class J extends w{verificationProcess=[L.retrieveVerificationMethodPublicKey,L.ensureVerificationMethodValidity,L.checkDocumentSignature];documentToVerify;issuer;proof;type="Ed25519Signature2020";verificationKey;verificationMethod;publicKey;proofPurpose;challenge;domain;proofPurposeMap;constructor(e){super(e),e.executeStep&&(this.executeStep=e.executeStep),this.documentToVerify=e.document,this.issuer=e.issuer,this.proof=e.proof,this.proofPurpose=e.proofPurpose??"assertionMethod",this.challenge=e.proofChallenge??"",this.domain=e.proofDomain,this.proofPurposeMap={authentication:D,assertionMethod:A},this.validateProofType()}async init(){}async verifyProof(){for(const e of this.verificationProcess){if(!this[e])return void console.error("verification logic for",e,"not implemented");await this[e]()}}async verifyIdentity(){}getProofVerificationSteps(t){return this.verificationProcess.map(i=>e.verifier.convertToVerificationSubsteps(t,i))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return this.publicKey}getIssuerName(){return this.issuer.name??""}getIssuerProfileDomain(){try{return new URL(this.getIssuerProfileUrl()).hostname??""}catch(e){return""}}getIssuerProfileUrl(){return this.issuer.id??""}getSigningDate(){return this.proof.created}async executeStep(e,t,i){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}publicKeyJwkToString(e){return t(e.publicKeyJwk)}validateProofType(){const e=this.isProofChain()?this.proof.chainedProofType:this.proof.type;if(e!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${e}`)}isProofChain(){return"ChainedProof2021"===this.proof.type}generateDocumentLoader(){i[this.documentToVerify.issuer]=this.issuer.didDocument;return function(e){return e in i?{contextUrl:null,document:i[e],documentUrl:e}:p.documentLoader(e)}}retrieveInitialDocument(){const e=r(this.documentToVerify);if(Array.isArray(e.proof)){const t=e.proof.find(e=>e.type===this.type);delete e.proof,e.proof=t}return delete e.didDocument,e}getTargetVerificationMethodContainer(){if(this.issuer.didDocument){if(this.findVerificationMethod(this.issuer.didDocument.verificationMethod,this.issuer.didDocument.id))return this.issuer.didDocument}const e={...this.issuer};return delete e.didDocument,e}findVerificationMethod(e,t){return e.find(e=>e.id===this.proof.verificationMethod||t+e.id===this.proof.verificationMethod)??null}getErrorMessage(e){return e.error.errors[0].message}async retrieveVerificationMethodPublicKey(){this.verificationKey=await this.executeStep(L.retrieveVerificationMethodPublicKey,async()=>{const e=this.getTargetVerificationMethodContainer();if(!e)throw new o(L.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.",n.CRYPTOGRAPHIC_SECURITY_ERROR);if(this.verificationMethod=this.findVerificationMethod(e.verificationMethod,e.id),!this.verificationMethod)throw new o(L.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.",n.CRYPTOGRAPHIC_SECURITY_ERROR);try{this.publicKey=this.verificationMethod.publicKeyMultibase??this.publicKeyJwkToString(this.verificationMethod)}catch(e){console.error("ERROR retrieving Ed25519Signature2020 public key",e)}const t=await P.from({...this.verificationMethod});if(!t)throw new o(L.retrieveVerificationMethodPublicKey,"Could not derive the verification key",n.CRYPTOGRAPHIC_SECURITY_ERROR);if(t.revoked)throw new o(L.retrieveVerificationMethodPublicKey,"The verification key has been revoked",n.CRYPTOGRAPHIC_SECURITY_ERROR);return t},this.type)}async ensureVerificationMethodValidity(){await this.executeStep(L.ensureVerificationMethodValidity,async()=>{if(this.verificationMethod.expires){if(new Date(this.verificationMethod.expires).getTime()<Date.now())throw new o(L.ensureVerificationMethodValidity,"The verification key has expired",n.CRYPTOGRAPHIC_SECURITY_ERROR)}if(this.verificationMethod.revoked)throw new o(L.ensureVerificationMethodValidity,"The verification key has been revoked",n.CRYPTOGRAPHIC_SECURITY_ERROR)},this.type)}async checkDocumentSignature(){await this.executeStep(L.checkDocumentSignature,async()=>{const e=new U({key:this.verificationKey});e.date=new Date(Date.now()).toISOString(),"authentication"!==this.proofPurpose||this.proof.challenge||(this.proof.challenge="");const t=await d.verify(this.retrieveInitialDocument(),{suite:e,purpose:new this.proofPurposeMap[this.proofPurpose]({controller:this.getTargetVerificationMethodContainer(),challenge:this.challenge,domain:this.domain}),documentLoader:this.generateDocumentLoader()});if(!t.verified)throw console.error(JSON.stringify(t,null,2)),new o(L.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed: ${this.getErrorMessage(t)}`,n.PROOF_VERIFICATION_ERROR);console.log("Credential Ed25519 signature successfully verified")},this.type)}}export{J as default};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import{d as e,
|
|
1
|
+
import{d as e,t as i,p as t,V as o,P as r}from"./main.js";import{D as n,r as s}from"./DataIntegrityProof-DRK-bLb_-CItV0ZXY.js";import{j as a}from"./jsonld-DOUjwF6J-dtl20tiV.js";import{f as c}from"./index-C4ZZHHRx-BOdwDnYa.js";import{j as h}from"./jsonld-signatures-BJXipuab-CB799Kkm.js";import{S as d}from"./Suite-BmP2Qu19-D1ucdMDB.js";import"./_polyfill-node.crypto-MVmI5M_M-exGcp6nW.js";
|
|
2
2
|
/*!
|
|
3
3
|
* Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
/*!
|
|
6
6
|
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
8
|
+
const u={canonize:async function(e,i){i={algorithm:"RDFC-1.0",format:"application/n-quads",base:null,safe:!0,...i};const t={rdfDirection:"i18n-datatype",...i,produceGeneralizedRdf:!1};delete t.format;const o=await a.toRDF(e,t);return s.canonize(o,i)}
|
|
9
9
|
/*!
|
|
10
10
|
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
|
|
11
|
-
*/,createVerifier:async function({verificationMethod:e}){return(await c(e)).verifier()},name:"eddsa-rdfc-2022",requiredAlgorithm:"Ed25519"},{purposes:{AssertionProofPurpose:
|
|
11
|
+
*/,createVerifier:async function({verificationMethod:e}){return(await c(e)).verifier()},name:"eddsa-rdfc-2022",requiredAlgorithm:"Ed25519"},{purposes:{AssertionProofPurpose:f,AuthenticationProofPurpose:p}}=h;
|
|
12
12
|
/*!
|
|
13
13
|
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
|
|
14
|
-
*/var
|
|
14
|
+
*/var l;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.ensureVerificationMethodValidity="ensureVerificationMethodValidity",e.checkDocumentSignature="checkDocumentSignature"}(l||(l={}));class y extends d{verificationProcess=[l.retrieveVerificationMethodPublicKey,l.ensureVerificationMethodValidity,l.checkDocumentSignature];documentToVerify;issuer;proof;type="EddsaRdfc2022";cryptosuite="eddsa-rdfc-2022";verificationKey;verificationMethod;publicKey;proofPurpose;challenge;domain;proofPurposeMap;constructor(e){super(e),e.executeStep&&(this.executeStep=e.executeStep),this.documentToVerify=e.document,this.issuer=e.issuer,this.proof=e.proof,this.proofPurpose=e.proofPurpose??"assertionMethod",this.challenge=e.proofChallenge??"",this.domain=e.proofDomain,this.proofPurposeMap={authentication:p,assertionMethod:f},this.validateProofType()}async init(){}async verifyProof(){for(const e of this.verificationProcess){if(!this[e])return void console.error("verification logic for",e,"not implemented");await this[e]()}}async verifyIdentity(){}getProofVerificationSteps(i){return this.verificationProcess.map(t=>e.verifier.convertToVerificationSubsteps(i,t))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return this.publicKey}getIssuerName(){return this.issuer.name??""}getIssuerProfileDomain(){try{return new URL(this.getIssuerProfileUrl()).hostname??""}catch(e){return""}}getIssuerProfileUrl(){return this.issuer.id??""}getSigningDate(){return this.proof.created}async executeStep(e,i,t){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}async publicKeyJwkToString(e){return i(e.publicKeyJwk)}validateProofType(){const e=this.isProofChain()?this.proof.chainedProofType:this.proof.type;if("DataIntegrityProof"===e){const e=this.proof.cryptosuite;if(!e)throw new Error(`Malformed proof passed. With DataIntegrityProof a cryptosuite must be defined. Expected: ${this.cryptosuite}`);if(e!==this.cryptosuite)throw new Error(`Incompatible proof cryptosuite passed. Expected: ${this.cryptosuite}, Got: ${e}`);return}if(e!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${e}`)}isProofChain(){return"ChainedProof2021"===this.proof.type}generateDocumentLoader(){t[this.documentToVerify.issuer]=this.issuer.didDocument,t[this.proof.verificationMethod]=this.getMultikeyRepresentation();return function(e){return e in t?{contextUrl:null,document:t[e],documentUrl:e}:a.documentLoader(e)}}getErrorMessage(e){return e.error.errors[0].message}getTargetVerificationMethodContainer(){if(this.issuer.didDocument){if(this.findVerificationMethod(this.issuer.didDocument.verificationMethod,this.issuer.didDocument.id))return this.issuer.didDocument}const e={...this.issuer};return delete e.didDocument,e}findVerificationMethod(e,i){return e.find(e=>e.id===this.proof.verificationMethod||i+e.id===this.proof.verificationMethod)??null}getMultikeyRepresentation(){return{"@context":"https://w3id.org/security/multikey/v1",type:"Multikey",publicKeyMultibase:i(this.verificationMethod.publicKeyJwk),id:"string"==typeof this.verificationMethod.id?this.verificationMethod.id:void 0,controller:"string"==typeof this.verificationMethod.controller?this.verificationMethod.controller:void 0}}async retrieveVerificationMethodPublicKey(){this.verificationKey=await this.executeStep(l.retrieveVerificationMethodPublicKey,async()=>{const e=this.getTargetVerificationMethodContainer();if(!e)throw new o(l.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.",r.CRYPTOGRAPHIC_SECURITY_ERROR);if(this.verificationMethod=this.findVerificationMethod(e.verificationMethod,e.id),!this.verificationMethod)throw new o(l.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.",r.CRYPTOGRAPHIC_SECURITY_ERROR);try{this.publicKey=this.verificationMethod.publicKeyMultibase??await this.publicKeyJwkToString(this.verificationMethod)}catch(e){console.error("ERROR retrieving Ed25519Signature2020 public key",e)}const i=await c({...this.verificationMethod});if(!i)throw new o(l.retrieveVerificationMethodPublicKey,"Could not derive the verification key",r.CRYPTOGRAPHIC_SECURITY_ERROR);if(i.revoked)throw new o(l.retrieveVerificationMethodPublicKey,"The verification key has been revoked",r.CRYPTOGRAPHIC_SECURITY_ERROR);return i},this.type)}async ensureVerificationMethodValidity(){await this.executeStep(l.ensureVerificationMethodValidity,async()=>{if(this.verificationMethod.expires){if(new Date(this.verificationMethod.expires).getTime()<Date.now())throw new o(l.ensureVerificationMethodValidity,"The verification key has expired",r.CRYPTOGRAPHIC_SECURITY_ERROR)}if(this.verificationMethod.revoked)throw new o(l.ensureVerificationMethodValidity,"The verification key has been revoked",r.CRYPTOGRAPHIC_SECURITY_ERROR)},this.type)}async checkDocumentSignature(){await this.executeStep(l.checkDocumentSignature,async()=>{const e=new n({cryptosuite:u}),i=await h.verify(this.documentToVerify,{suite:e,purpose:new this.proofPurposeMap[this.proofPurpose]({controller:this.getTargetVerificationMethodContainer(),challenge:this.challenge,domain:this.domain}),documentLoader:this.generateDocumentLoader()});if(!i.verified)throw console.error(JSON.stringify(i,null,2)),new o(l.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed: ${this.getErrorMessage(i)}`,r.PROOF_VERIFICATION_ERROR);console.log("Credential EddsaRdfc2022 signature successfully verified")},this.type)}}export{y as default};
|