@blockcerts/blockcerts-verifier 1.73.0 → 1.75.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/bundle-stats.html +1 -1
- package/coverage/lcov.info +104 -104
- package/dist/Bbs2023-Bp5cEh1R-CyaAsSfy.js +64 -0
- package/dist/{DataIntegrityProof-D8TnXEkl-CGiIg0kn.js → DataIntegrityProof-C6eNcfZD-DxdoQnVI.js} +2 -2
- package/dist/EcdsaSd2023-DZZuYYEc-CWUg-wCj.js +14 -0
- package/dist/EcdsaSecp256k1Signature2019-DhXTmkRz-BDI0F5k3.js +1 -0
- package/dist/{Ed25519Signature2020-D2tdrIA4-PSi5TCQH.js → Ed25519Signature2020-DQ74b0xi-mZPb25zD.js} +8 -8
- package/dist/{EddsaRdfc2022-CpZAUc7W-BJP0532C.js → EddsaRdfc2022-DoIsbQDP-CdTbCYWu.js} +4 -4
- package/dist/{HashlinkVerifier-BcdAFe02-DMjUYzMR.js → HashlinkVerifier-CLOBeWTC-A9htzw7A.js} +1 -1
- package/dist/MerkleProof2017-DjEiaTFN-DYmuOUac.js +1 -0
- package/dist/MerkleProof2019-eet_uSL0-DMgMKE-N.js +5 -0
- package/dist/checkBitStringStatusList-imqRJLbC-BxFzQ5zP.js +1 -0
- package/dist/checkCredentialSchemaConformity-drHrI5ZX-D8a64oBH.js +1 -0
- package/dist/controlVerificationMethod-yDdxMt7K-CmPWOLBp.js +1 -0
- package/dist/decode-BvGwOAqu-BaxzowN_.js +13 -0
- package/dist/{downloadPDF-BU6CfP-N.js → downloadPDF-C-y2U2YC.js} +2 -2
- package/dist/{ensureNotRevoked-BWp1jPEo-DSQMtjrj.js → ensureNotRevoked-DkeMWyFL-BheL-ZKZ.js} +1 -1
- package/dist/ensureValidIssuingKey-BBsblYif-DXO_G6MC.js +1 -0
- package/dist/{index-OtXtCWrq-CyttRwCk.js → index-B5gC_Ed--DC3Wd_3X.js} +5 -5
- package/dist/index-BALRZPPb-BXRdR9Sh.js +14 -0
- package/dist/index-D8xF_f-v-BlsVgJYJ.js +7 -0
- package/dist/index-Dab3X91f-dKXR6RU7.js +66 -0
- package/dist/index-cqs5icUJ-DWIE-ahU.js +23 -0
- package/dist/{index.es-C2GPR7m7.js → index.es-BmC2s_4v.js} +1 -1
- package/dist/jsonld-BHLXlZBJ-dtl20tiV.js +33 -0
- package/dist/jsonld-signatures-B0DqrrUT-B4B7KZ3F.js +56 -0
- package/dist/main.js +122 -122
- package/dist/retrieveVerificationMethodPublicKey-B-kSksW4-OGh7Cdla.js +1 -0
- package/dist/sha2-CJXzPerd-BVhQN7q7.js +1 -0
- package/dist/verifyIssuerProfile-Bn2qjtLO-CctriaZ1.js +1 -0
- package/dist/weierstrass-qx_4bPUU-BwaVz9Sr.js +5 -0
- package/package.json +2 -2
- package/dist/EcdsaSd2023-D2eJBmaY-mHNjbn8h.js +0 -26
- package/dist/EcdsaSecp256k1Signature2019-BRdQnZ0o-D_QN8KrS.js +0 -1
- package/dist/MerkleProof2017-DW_9FhLr-C0dPtifx.js +0 -1
- package/dist/MerkleProof2019-DJbo7uW--CHlhsnHk.js +0 -5
- package/dist/checkBitStringStatusList-BUPuVWy_-CYedocxJ.js +0 -13
- package/dist/checkCredentialSchemaConformity-CJdGwNcY-CaSak-bD.js +0 -1
- package/dist/controlVerificationMethod-C71lJp3H-n-AbzkO8.js +0 -1
- package/dist/ensureValidIssuingKey-BYAR3LEF-76kiqVKA.js +0 -1
- package/dist/index-CB7VaVsF-G_Mj6xql.js +0 -30
- package/dist/index-Jn9Q6fuB-uChPhl1c.js +0 -56
- package/dist/jsonld-DqC1oHcn-ruRlORc0.js +0 -88
- package/dist/retrieveVerificationMethodPublicKey-Dai7em0K-BqIH8qzD.js +0 -1
- package/dist/verifyIssuerProfile-zkczSLpC-CTHpISfH.js +0 -1
- /package/dist/{index-BCu3PGuw-Dh4-8Ruv.js → index-DBwScGKb-Dh4-8Ruv.js} +0 -0
- /package/dist/{index-KzSDgEl9-Dgus2xdV.js → index-DLhZKDC_-Dgus2xdV.js} +0 -0
- /package/dist/{webcrypto.es-9hytEjC6-gGk5JRJH.js → webcrypto.es-D4KX-5fg-gGk5JRJH.js} +0 -0
package/dist/{DataIntegrityProof-D8TnXEkl-CGiIg0kn.js → DataIntegrityProof-C6eNcfZD-DxdoQnVI.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{r as t}from"./jsonld-BHLXlZBJ-dtl20tiV.js";import{w as e,f as r,u as o}from"./main.js";import{j as i}from"./jsonld-signatures-B0DqrrUT-B4B7KZ3F.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))}
|
|
5
5
|
/*!
|
|
6
6
|
* Copyright (c) 2022-2024 Digital Bazaar, Inc. All rights reserved.
|
|
7
|
-
*/const{suites:{LinkedDataProof:d}}=
|
|
7
|
+
*/const{suites:{LinkedDataProof:d}}=i;class f extends d{constructor({signer:t,date:e,cryptosuite:r,legacyContext:o=!1}={}){super({type:"DataIntegrityProof"});const{canonize:i,createVerifier:n,name:a,requiredAlgorithm:s,derive:c,createProofValue:u,createVerifyData:d}=r;if(!n||"function"!=typeof n)throw new TypeError('"cryptosuite.createVerifier" must be a function.');if(c&&"function"!=typeof c)throw new TypeError('"cryptosuite.derive" must be a function.');if(u&&"function"!=typeof u)throw new TypeError('"cryptosuite.createProofValue" must be a function.');if(d&&"function"!=typeof d)throw new TypeError('"cryptosuite.createVerifyData" must be a function.');if(this.contextUrl="https://w3id.org/security/data-integrity/v2",o&&(this.contextUrl="https://w3id.org/security/data-integrity/v1"),this.canonize=i,this.createVerifier=n,this.cryptosuite=a,this._cryptosuite=r,this.requiredAlgorithm=s,e){if(this.date=new Date(e),isNaN(this.date))throw TypeError(`"date" "${e}" is not a valid date.`)}else null===e&&(this.date=null);const f=function({signer:t,requiredAlgorithm:e}){const r={verificationMethod:void 0,signer:void 0};if(!t)return r;if("function"!=typeof t.sign)throw new TypeError("A signer API has not been specified.");const o=Array.isArray(e)?e.includes(t.algorithm):e===t.algorithm;if(!o){const r=Array.isArray(e)?e.join(", "):e,o=Array.isArray(e)?`is not a supported algorithm for the cryptosuite. The supported algorithms are: "${r}".`:`does not match the required algorithm for the cryptosuite "${r}".`,i=`The signer's algorithm "${t.algorithm}" ${o}`;throw new Error(i)}return r.signer=t,r.verificationMethod=t.id,r}({signer:t,requiredAlgorithm:s});this.verificationMethod=f.verificationMethod,this.signer=f.signer}async sign({verifyData:t,proof:r}){if(!this.signer||"function"!=typeof this.signer.sign)throw new Error("A signer API has not been specified.");const o=await this.signer.sign({data:t});return r.proofValue="z"+e(o),r}async verifySignature({verifyData:t,verificationMethod:e,proof:i}){const n=await this.createVerifier({verificationMethod:e});if(!(Array.isArray(this.requiredAlgorithm)?this.requiredAlgorithm.includes(n.algorithm):this.requiredAlgorithm===n.algorithm)){const t=Array.isArray(this.requiredAlgorithm)?this.requiredAlgorithm.join(", "):this.requiredAlgorithm,e=Array.isArray(this.requiredAlgorithm)?`is not a supported algorithm for the cryptosuite. The supported algorithms are: "${t}".`:`does not match the required algorithm for the cryptosuite "${t}".`,r=`The verifier's algorithm "${n.algorithm}" ${e}`;throw new Error(r)}const{proofValue:a}=i;if(!a||"string"!=typeof a)throw new TypeError('The proof does not include a valid "proofValue" property.');const s=a[0];let c;if("z"===s)c=r(a.slice(1));else{if("u"!==s)throw new Error("Only base58btc or base64url multibase encoding is supported.");c=o(a.slice(1))}return n.verify({data:t,signature:c})}async createProof({document:t,purpose:e,proofSet:r,documentLoader:o}){let i;i=this.proof?{...this.proof}:{},i.type=this.type;let n,a=this.date;return void 0===i.created&&void 0===a&&(a=new Date),a&&"string"!=typeof a&&(a=(t=>(null==t?t=new Date:"number"!=typeof t&&"string"!=typeof t||(t=new Date(t)),t.toISOString().slice(0,-5)+"Z"))(a)),a&&(i.created=a),i.verificationMethod=this.verificationMethod,i.cryptosuite=this.cryptosuite,i=await this.updateProof({document:t,proof:i,purpose:e,proofSet:r,documentLoader:o}),i=await e.update(i,{document:t,suite:this,documentLoader:o}),n=this._cryptosuite.createVerifyData?await this._cryptosuite.createVerifyData({cryptosuite:this._cryptosuite,document:t,proof:i,proofSet:r,documentLoader:o,dataIntegrityProof:this}):await this.createVerifyData({document:t,proof:i,proofSet:r,documentLoader:o}),this._cryptosuite.createProofValue?i.proofValue=await this._cryptosuite.createProofValue({cryptosuite:this._cryptosuite,verifyData:n,document:t,proof:i,proofSet:r,documentLoader:o,dataIntegrityProof:this}):i=await this.sign({verifyData:n,document:t,proof:i,proofSet:r,documentLoader:o}),i}async derive({document:t,purpose:e,proofSet:r,documentLoader:o}){if(!this._cryptosuite.derive)throw new Error('"cryptosuite.derive" not provided.');return this._cryptosuite.derive({cryptosuite:this._cryptosuite,document:t,purpose:e,proofSet:r,documentLoader:o,dataIntegrityProof:this})}async updateProof({proof:t}){return t}async verifyProof({proof:t,proofSet:e,document:r,documentLoader:o}){try{const i=await this.getVerificationMethod({proof:t,documentLoader:o});let n;n=this._cryptosuite.createVerifyData?await this._cryptosuite.createVerifyData({cryptosuite:this._cryptosuite,document:r,proof:t,proofSet:e,documentLoader:o,dataIntegrityProof:this,verificationMethod:i}):await this.createVerifyData({document:r,proof:t,proofSet:e,documentLoader:o,verificationMethod:i});if(!await this.verifySignature({verifyData:n,verificationMethod:i,proof:t}))throw new Error("Invalid signature.");if(void 0!==t.created&&!s(t.created))throw new Error(`"proof.created" ("${t.created}") must be an XSD dateTimeStamp.`);if(void 0!==t.expires&&!s(t.expires))throw new Error(`"proof.expires" ("${t.expires}") must be an XSD dateTimeStamp.`);return{verified:!0,verificationMethod:i}}catch(t){return{verified:!1,error:t}}}async createVerifyData({document:t,proof:e,documentLoader:r}){let o;const{_hashCache:i}=this;i&&i.document===t?o=i.hash:this._hashCache={document:t,hash:o=this.canonize(t,{documentLoader:r,base:null,safe:!0}).then(t=>u({string:t}))};const[n,a]=await Promise.all([this.canonizeProof(e,{document:t,documentLoader:r}).then(t=>u({string:t})),o]);return((t,e)=>{const r=new Uint8Array(t.length+e.length);return r.set(t,0),r.set(e,t.length),r})(n,a)}async getVerificationMethod({proof:t,documentLoader:e}){let{verificationMethod:r}=t;if("object"==typeof r&&(r=r.id),!r)throw new Error('No "verificationMethod" found in proof.');const o=await e(r);if(!o)throw new Error(`Unable to load verification method "${r}".`);const{document:i}=o;return r="string"==typeof i?JSON.parse(i):i,r}async canonizeProof(t,{documentLoader:e,document:r}){return t={"@context":r["@context"],...t},this.ensureSuiteContext({document:t,addSuiteContext:!0}),delete t.proofValue,this.canonize(t,{documentLoader:e,safe:!0,base:null,skipExpansion:!1})}async matchProof({proof:t}){const{type:e,cryptosuite:r}=t;return e===this.type&&r===this.cryptosuite}ensureSuiteContext({document:t,addSuiteContext:e}){const{contextUrl:r}=this;if(h({document:t,contextUrl:r})||h({document:t,contextUrl:"https://www.w3.org/ns/credentials/v2"}))return;if(!e)throw new TypeError(`The document to be signed must contain this suite's @context, "${r}".`);const o=t["@context"]||[];t["@context"]=Array.isArray(o)?[...o,r]:[o,r]}}function h({document:t,contextUrl:e}){const r=t["@context"];return r===e||Array.isArray(r)&&r.includes(e)}export{f as D,n as r};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{d as e,p as t,V as r,P as i,u as o,w as n,v as a}from"./main.js";import{j as s}from"./jsonld-signatures-B0DqrrUT-B4B7KZ3F.js";import{j as c}from"./jsonld-BHLXlZBJ-dtl20tiV.js";import{D as u}from"./DataIntegrityProof-C6eNcfZD-DxdoQnVI.js";import{h as f,c as h,l as d,a as p,d as y,s as l}from"./decode-BvGwOAqu-BaxzowN_.js";import{f as m}from"./index-cqs5icUJ-DWIE-ahU.js";import{S as g}from"./Suite-BmP2Qu19-D1ucdMDB.js";import"./index-DLhZKDC_-Dgus2xdV.js";import{r as w}from"./retrieveVerificationMethodPublicKey-B-kSksW4-OGh7Cdla.js";import"./sha2-CJXzPerd-BVhQN7q7.js";import"./weierstrass-qx_4bPUU-BwaVz9Sr.js";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
|
|
4
|
+
*/const v=new Uint8Array([217,93,1]),b=[];function M({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 r=0;r<t.length;++r)if(e[r]!==t[r])return!1;return!0}(t,v))throw new TypeError('"proof.proofValue" must be a derived proof.');const r=t.subarray(v.length),[i,n,s,c,u]=y(r,{useMaps:!0,tags:b}),f=function(e){const t=new Map;for(const[r,i]of e.entries())t.set(`c14n${r}`,`u${a(i)}`);return t}(c),h={baseSignature:i,publicKey:n,signatures:s,labelMap:f,mandatoryIndexes:u};return function({baseSignature:e,publicKey:t,signatures:r,labelMap:i,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(r)||!r.every(e=>e instanceof Uint8Array))throw new TypeError('"signatures" must be an array of Uint8Arrays.');if(!(i instanceof Map&&[...i.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.')}(h),h}catch(e){const t=new TypeError('The proof does not include a valid "proofValue" property.');throw t.cause=e,t}}function P({proofHash:e,publicKey:t,mandatoryHash:r}={}){!function({proofHash:e,publicKey:t,mandatoryHash:r}){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(!(r instanceof Uint8Array&&32===r.length))throw new TypeError('"mandatoryHash" must be a Uint8Array of length 32.')}({proofHash:e,publicKey:t,mandatoryHash:r});return function(e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let r=0;for(const i of e)t.set(i,r),r+=i.length;return t}([e,t,r])}b[64]=function(e){return e}
|
|
5
|
+
/*!
|
|
6
|
+
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
|
|
7
|
+
*/;const V="ecdsa-sd-2023";
|
|
8
|
+
/*!
|
|
9
|
+
* Copyright (c) 2022-2023 Digital Bazaar, Inc. All rights reserved.
|
|
10
|
+
*/
|
|
11
|
+
/*!
|
|
12
|
+
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
|
|
13
|
+
*/
|
|
14
|
+
function T({requiredAlgorithm:e="P-256"}={}){return{name:V,requiredAlgorithm:e,createVerifier:E,createVerifyData:S}}async function E({verificationMethod:e}){const t=(await m(e)).verifier();return{algorithm:t.algorithm,id:t.id,verify:async({data:e})=>async function({verifier:e,data:t}={}){const{baseSignature:r,proofHash:i,publicKey:o,signatures:a,nonMandatory:s,mandatoryHash:c}=t,u="z"+n(o),f=await m({publicKeyMultibase:u});if(a.length!==s.length)throw new Error(`Signature count (${a.length}) does not match non-mandatory message count (${s.length}).`);const{verify:h}=f.verifier();if((await Promise.all(a.map((e,t)=>h({data:l(s[t]),signature:e})))).some(e=>!e))return!1;const d=await P({proofHash:i,publicKey:o,mandatoryHash:c});return e.verify({data:d,signature:r})}({verifier:t,data:e})}}async function S({cryptosuite:e,document:t,proof:r,documentLoader:i}){if(e?.name!==V)throw new TypeError(`"cryptosuite.name" must be "${V}".`);const o={documentLoader:i},n=f({document:t,proof:r,options:o}).catch(e=>e),{baseSignature:a,publicKey:s,signatures:c,labelMap:u,mandatoryIndexes:y}=await M({proof:r}),l=await h({labelMap:u}),m=await d({document:t,labelMapFactoryFunction:l,options:o}),g=[],w=[];for(const[e,t]of m.entries())y.includes(e)?g.push(t):w.push(t);const{mandatoryHash:v}=await p({mandatory:g}),b=await n;if(b instanceof Error)throw b;return{baseSignature:a,proofHash:b,publicKey:s,signatures:c,nonMandatory:w,mandatoryHash:v}}const{purposes:{AssertionProofPurpose:A,AuthenticationProofPurpose:R}}=s;var I;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.ensureVerificationMethodValidity="ensureVerificationMethodValidity",e.checkDocumentSignature="checkDocumentSignature"}(I||(I={}));class K extends g{verificationProcess=[I.retrieveVerificationMethodPublicKey,I.ensureVerificationMethodValidity,I.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:R,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(r=>e.verifier.convertToVerificationSubsteps(t,r))}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,r){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}:c.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(I.retrieveVerificationMethodPublicKey,async()=>{if(this.verificationMethod=w(this.getTargetVerificationMethodContainer(),this.proof.verificationMethod),!this.verificationMethod)throw new r(I.retrieveVerificationMethodPublicKey,"Could not derive the verification key",i.CRYPTOGRAPHIC_SECURITY_ERROR);if(this.verificationMethod.revoked)throw new r(I.retrieveVerificationMethodPublicKey,"The verification key has been revoked",i.CRYPTOGRAPHIC_SECURITY_ERROR);return this.verificationMethod},this.type)}async ensureVerificationMethodValidity(){await this.executeStep(I.ensureVerificationMethodValidity,async()=>{if(this.verificationMethod.expires){if(new Date(this.verificationMethod.expires).getTime()<Date.now())throw new r(I.ensureVerificationMethodValidity,"The verification key has expired",i.CRYPTOGRAPHIC_SECURITY_ERROR)}if(this.verificationMethod.revoked)throw new r(I.ensureVerificationMethodValidity,"The verification key has been revoked",i.CRYPTOGRAPHIC_SECURITY_ERROR)},this.type)}async checkDocumentSignature(){await this.executeStep(I.checkDocumentSignature,async()=>{const e=new u({cryptosuite:T({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 r(I.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed: ${this.getErrorMessage(o)}`,i.PROOF_VERIFICATION_ERROR);console.log(`Credential ${this.type} signature successfully verified`)},this.type)}}export{K 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-B0DqrrUT-B4B7KZ3F.js";import{j as d}from"./jsonld-BHLXlZBJ-dtl20tiV.js";import{S as h}from"./Suite-BmP2Qu19-D1ucdMDB.js";import"./index-DLhZKDC_-Dgus2xdV.js";import{r as u}from"./retrieveVerificationMethodPublicKey-B-kSksW4-OGh7Cdla.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 g=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}`}};g.CONTEXT_URL=p,g.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:w,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:w},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 g({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-D2tdrIA4-PSi5TCQH.js → Ed25519Signature2020-DQ74b0xi-mZPb25zD.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-B0DqrrUT-B4B7KZ3F.js";import{j as p}from"./jsonld-BHLXlZBJ-dtl20tiV.js";import{f as y,v as h,s as f,g as l}from"./index-B5gC_Ed--DC3Wd_3X.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
|
*/
|
|
@@ -23,12 +23,12 @@ e.exports={CONTEXT_FILENAME:"ed25519-signature-2020-v1.jsonld",CONTEXT_URL:"http
|
|
|
23
23
|
/*!
|
|
24
24
|
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
|
|
25
25
|
*/
|
|
26
|
-
const r=i(0),o=i(1),{documentLoader:n}=i(3),{CONTEXT_URL:s,CBORLD_CODEC_VALUE:
|
|
26
|
+
const r=i(0),o=i(1),{documentLoader:n}=i(3),{CONTEXT_URL:s,CBORLD_CODEC_VALUE:a}=o,c=new Map;c.set(o.CONTEXT_URL,r);const u=new Map;u.set(s,a),e.exports={constants:o,contexts:c,appContextMap:u,documentLoader:n,CONTEXT_URL:s,CONTEXT:r}},function(e,t,i){
|
|
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-C6eNcfZD-DxdoQnVI.js";import{j as a}from"./jsonld-BHLXlZBJ-dtl20tiV.js";import{f as c}from"./index-B5gC_Ed--DC3Wd_3X.js";import{j as h}from"./jsonld-signatures-B0DqrrUT-B4B7KZ3F.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 f={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:u,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:u},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:f}),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};
|