@blockcerts/blockcerts-verifier 1.72.1 → 1.72.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/bundle-stats.html +33 -32
  2. package/coverage/lcov.info +154 -158
  3. package/dist/{DataIntegrityProof-CsicZNrL-BkSRjzkI.js → DataIntegrityProof-BhL7Kkhm-affsdujn.js} +2 -2
  4. package/dist/EcdsaSd2023-CUjrjGzC-Cx7ejHu-.js +30 -0
  5. package/dist/EcdsaSecp256k1Signature2019-D90cAynb-Bf5kILPF.js +1 -0
  6. package/dist/{Ed25519Signature2020-CglkQLKN-CQ6lMzyG.js → Ed25519Signature2020-fJGvlbIp-B6XhFwr4.js} +4 -4
  7. package/dist/EddsaRdfc2022-XufziFi3-D5IoKiRE.js +14 -0
  8. package/dist/HashlinkVerifier-udsj5z09-BTqOkVoD.js +8 -0
  9. package/dist/MerkleProof2017-C0RhRNNx-zjQMRSQY.js +1 -0
  10. package/dist/MerkleProof2017-C499XBV8-l50m9izr.js +74 -0
  11. package/dist/MerkleProof2019-B7f1hhem-CjLDyx6Q.js +5 -0
  12. package/dist/Suite-Bu3gszvt-Dmvbh142.js +33 -0
  13. package/dist/_polyfill-node.crypto-DGISCHrB-C5-OOGc0.js +1 -0
  14. package/dist/checkCredentialSchemaConformity-CgpOS3eC-AjSPoJub.js +1 -0
  15. package/dist/{checkRevocationStatusList2021-BDBFhnz6-BEBD8TO8.js → checkRevocationStatusList2021-D4VNDRlW-DgNfOAoI.js} +2 -2
  16. package/dist/controlVerificationMethod-CSwPoUL8-CvUADmjg.js +1 -0
  17. package/dist/downloadPDF-UAsY-nU_.js +297 -0
  18. package/dist/ed25519-key-pair.esm-DxoBwwVJ-D8j8wFfG.js +1 -0
  19. package/dist/ensureNotRevoked-ByWaYoog-BheL-ZKZ.js +1 -0
  20. package/dist/ensureNotRevoked-C1kT3A6R-oFUZltl3.js +1 -0
  21. package/dist/{ensureValidIssuingKey-wTUvNuDH-BdV46XBb.js → ensureValidIssuingKey-DEV9E0Ph-DY8BTObG.js} +1 -1
  22. package/dist/index-DZ7aUhT_-D0G2DVsh.js +29 -0
  23. package/dist/index-DjD0A6uJ-BdFUkPCF.js +33 -0
  24. package/dist/index-RfFwckcH.js +1 -0
  25. package/dist/index-tlZQQ_rg-CYTlxhyY.js +1 -0
  26. package/dist/index.es-CnYWLNZV.js +56 -0
  27. package/dist/jsonld-signatures-D4X_Irzi-D_wBqxSl.js +56 -0
  28. package/dist/main.js +142 -133
  29. package/dist/pako.esm-BGRKTPxS-Bodm4Eha.js +2 -0
  30. package/dist/purify.es-Om653OSQ.js +2 -0
  31. package/dist/retrieveVerificationMethodPublicKey-D_autuwE-DGbK-RPm.js +1 -0
  32. package/dist/sha2-JcCWfgvE-By1_saxP.js +2 -0
  33. package/dist/verifyIssuerProfile-2PhdMtQZ-CfqcAkBL.js +1 -0
  34. package/dist/webcrypto.es-BOyMRPOj-CAxP3jJR.js +40 -0
  35. package/package.json +10 -10
  36. package/dist/EcdsaSd2023-DN9HBdgh-Bc0hVwTd.js +0 -30
  37. package/dist/EcdsaSecp256k1Signature2019-C3F03t_M-DAJeMTpu.js +0 -1
  38. package/dist/EddsaRdfc2022-CfoLi-PP-l7ITLQQT.js +0 -14
  39. package/dist/HashlinkVerifier-CTG-OS14-B4Niv2-b.js +0 -8
  40. package/dist/MerkleProof2017-B_EJmYja-CYd4dJc1.js +0 -1
  41. package/dist/MerkleProof2017-k2qjvxCH-DrRpsLHG.js +0 -75
  42. package/dist/MerkleProof2019-B7t13hOo-D8n9YrUw.js +0 -13
  43. package/dist/Suite-BmP2Qu19-D1ucdMDB.js +0 -1
  44. package/dist/_commonjs-dynamic-modules-COweQ1RR-BHR_E30J.js +0 -1
  45. package/dist/base64url-Cy03LJLt-vkTPfQOh.js +0 -4
  46. package/dist/checkCredentialSchemaConformity-BiggGGMP-Dx992E4t.js +0 -1
  47. package/dist/controlVerificationMethod-Bh_-e0Fd-BUCC8ctY.js +0 -1
  48. package/dist/did-key-common.esm-BELyYVSE-Cqrpf7cy.js +0 -9
  49. package/dist/did-key-ed25519.esm-C3GUddDp-BJdBgNDg.js +0 -1
  50. package/dist/did-key-secp256k1.esm-D-R266jM-BTxlD5VW.js +0 -1
  51. package/dist/downloadPDF-D2qwT_DJ.js +0 -297
  52. package/dist/ed25519-key-pair.esm-DQF2kkXh-XX5BXBcl.js +0 -25
  53. package/dist/elliptic-6I21PEnR-CsYseRX1.js +0 -1
  54. package/dist/elliptic-mDX7fQQx-BpaNaVm0.js +0 -1
  55. package/dist/ensureNotRevoked-DGZuNktg-B4uNuqLX.js +0 -1
  56. package/dist/ensureNotRevoked-Dc6VA2bO-DvMIgM4L.js +0 -1
  57. package/dist/index-BrurC4Vt-C0eXpZGn.js +0 -1
  58. package/dist/index-CK9Z4pAC.js +0 -2
  59. package/dist/index-DXh-XAic-B2gT500V.js +0 -22
  60. package/dist/index-DZLKRa_V-D_IQzjvG.js +0 -5
  61. package/dist/index-fQcSLZgh-DpptYyN8.js +0 -1
  62. package/dist/index.es-BIiEi3w5.js +0 -56
  63. package/dist/jsonld-BAMY2WqE-BJ5uVeOU.js +0 -36
  64. package/dist/jsonld-signatures-BbHr1fSN-BSospRuX.js +0 -74
  65. package/dist/keyUtils-ue8EY3Op-DoHdKWgN.js +0 -1
  66. package/dist/pako.esm-BGRKTPxS-UdHShO7y.js +0 -2
  67. package/dist/purify.es-CkKsfeyH.js +0 -2
  68. package/dist/retrieveVerificationMethodPublicKey-CLBY4G8P-CagFGnNt.js +0 -1
  69. package/dist/sha256-Bwge_vjI-C1PUWFZm.js +0 -1
  70. package/dist/verifyIssuerProfile-BaiZaU2c-Zcu1X0PY.js +0 -1
  71. package/dist/webcrypto.es-DptGOl2T-BnVhHKeM.js +0 -40
  72. package/dist/x25519-hG3WOzPe-Dh8L0KYb.js +0 -1
  73. /package/dist/{index-Gr4i_Ned-Dgus2xdV.js → index-CyNtT_1q-Dgus2xdV.js} +0 -0
@@ -0,0 +1 @@
1
+ import{d as e,p as t,a as i,v as o,w as r,E as n,V as s}from"./main.js";import{j as c}from"./jsonld-signatures-D4X_Irzi-D_wBqxSl.js";import{S as a,j as d}from"./Suite-Bu3gszvt-Dmvbh142.js";import"./pako.esm-BGRKTPxS-Bodm4Eha.js";import"./index-CyNtT_1q-Dgus2xdV.js";import{r as h}from"./retrieveVerificationMethodPublicKey-D_autuwE-DGbK-RPm.js";const u="https://ns.did.ai/suites/secp256k1-2019/v1",p="https://www.w3.org/ns/credentials/v2",f=({document:e,contextUrl:t})=>{const i=e["@context"];return Array.isArray(i)?t.some(e=>i.includes(e)):t.includes(i)},y=({document:e})=>{const t=f({document:e,contextUrl:[u,"https://w3id.org/security/suites/secp256k1-2019/v1"]}),i=f({document:e,contextUrl:["https://www.w3.org/2018/credentials/v1"]}),o=f({document:e,contextUrl:[p]}),r=f({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 l=class extends c.suites.LinkedDataSignature{requiredKeyType;constructor(e={}){super({type:"EcdsaSecp256k1Signature2019",LDKeyClass:n,contextUrl:u,...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(!y({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(!y({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}){y({document:e})&&!f({document:e,contextUrl:[p]})||super.ensureSuiteContext({document:e,addSuiteContext:t})}isVerificationMethodMatchingKeyId(e){return e===this.key.id||e===`${this.key.controller}${this.key.id}`}};l.CONTEXT_URL=u,l.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:g}}=c;var m;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.ensureVerificationMethodValidity="ensureVerificationMethodValidity",e.checkDocumentSignature="checkDocumentSignature"}(m||(m={}));class v extends a{verificationProcess=[m.retrieveVerificationMethodPublicKey,m.ensureVerificationMethodValidity,m.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:g,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(m.retrieveVerificationMethodPublicKey,async()=>{if(this.verificationMethod=h(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(m.retrieveVerificationMethodPublicKey,"Could not derive the verification key");if(e.revoked)throw new s(m.retrieveVerificationMethodPublicKey,"The verification key has been revoked");return e},this.type)}async ensureVerificationMethodValidity(){await this.executeStep(m.ensureVerificationMethodValidity,async()=>{if(this.verificationMethod.expires){if(new Date(this.verificationMethod.expires).getTime()<Date.now())throw new s(m.ensureVerificationMethodValidity,"The verification key has expired")}if(this.verificationMethod.revoked)throw new s(m.ensureVerificationMethodValidity,"The verification key has been revoked")},this.type)}async checkDocumentSignature(){await this.executeStep(m.checkDocumentSignature,async()=>{const e=new l({key:this.verificationKey});e.date=new Date(Date.now()).toISOString(),"authentication"!==this.proofPurpose||this.proof.challenge||(this.proof.challenge="");const t=await c.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(m.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed: ${this.getErrorMessage(t)}`);console.log("Credential Secp256k1 signature successfully verified")},this.type)}}export{v as default};
@@ -1,17 +1,17 @@
1
- import{d as e,f as t,e as i,V as r}from"./main.js";import{j as o}from"./jsonld-signatures-BbHr1fSN-BSospRuX.js";import{j as n}from"./jsonld-BAMY2WqE-BJ5uVeOU.js";import{d as s,e as a}from"./index-DZLKRa_V-D_IQzjvG.js";import{d as c,e as u}from"./base64url-Cy03LJLt-vkTPfQOh.js";import{E as d,f as p,v as y,s as h,g as f}from"./ed25519-key-pair.esm-DQF2kkXh-XX5BXBcl.js";import{S as l}from"./Suite-BmP2Qu19-D1ucdMDB.js";import"./tslib.es6--gQC4x5c-CmLYFWVC.js";import"./x25519-hG3WOzPe-Dh8L0KYb.js";import"./_commonjs-dynamic-modules-COweQ1RR-BHR_E30J.js";
1
+ import{d as e,p as t,a as i,V as r,f as o,s as n,t as s,u as a}from"./main.js";import{j as c}from"./jsonld-signatures-D4X_Irzi-D_wBqxSl.js";import{S as u,j as d}from"./Suite-Bu3gszvt-Dmvbh142.js";import{f as p,v as y,s as h,g as f}from"./index-DjD0A6uJ-BdFUkPCF.js";import{E as l}from"./ed25519-key-pair.esm-DxoBwwVJ-D8j8wFfG.js";import"./tslib.es6--gQC4x5c-CmLYFWVC.js";import"./_polyfill-node.crypto-DGISCHrB-C5-OOGc0.js";
2
2
  /*!
3
3
  * Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
4
4
  */function w({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 b=globalThis.crypto;if(!b.getRandomValues)throw new Error('Browser does not provide "crypto.getRandomValues".');var m={async generateKeyPair(){const e=new Uint8Array(32);b.getRandomValues(e);const t=await g(e);return e.fill(0),t},generateKeyPairFromSeed:g,sign:async(e,t)=>h(t,e.slice(0,32)),verify:async(e,t,i)=>y(i,t,e),sha256digest:async({data:e})=>b.subtle.digest("SHA-256",e)};async function g(e){w({bytes:e,expectedLength:32});const t=await f(e),i=new Uint8Array(64);return i.set(e),i.set(t,e.length),{publicKey:t,secretKey:i}}
7
+ */const b=globalThis.crypto;if(!b.getRandomValues)throw new Error('Browser does not provide "crypto.getRandomValues".');var g={async generateKeyPair(){const e=new Uint8Array(32);b.getRandomValues(e);const t=await m(e);return e.fill(0),t},generateKeyPairFromSeed:m,sign:async(e,t)=>h(t,e.slice(0,32)),verify:async(e,t,i)=>y(i,t,e),sha256digest:async({data:e})=>b.subtle.digest("SHA-256",e)};async function m(e){w({bytes:e,expectedLength:32});const t=await f(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
10
  */class v{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.")}}}}v.SUITE_CONTEXT="INVALID LDKeyPair CONTEXT";
11
11
  /*!
12
12
  * Copyright (c) 2021-2024 Digital Bazaar, Inc. All rights reserved.
13
13
  */
14
- const K="Ed25519VerificationKey2020",M=new Uint8Array([237,1]),E=new Uint8Array([128,38]);class T extends v{constructor(e={}){super(e),this.type=K;const{publicKeyMultibase:t,privateKeyMultibase:i}=e;if(!t)throw new TypeError('The "publicKeyMultibase" property is required.');if(!t||!k(t,M))throw new Error(`"publicKeyMultibase" has invalid header bytes: "${t}".`);if(i&&!k(i,E))throw new Error('"privateKeyMultibase" has invalid header bytes.');this.publicKeyMultibase=t,this.privateKeyMultibase=i,this.controller&&!this.id&&(this.id=`${this.controller}#${this.fingerprint()}`),w({bytes:this._publicKeyBuffer,code:"invalidPublicKeyLength",expectedLength:32})}static async from(e){return"Ed25519VerificationKey2018"===e.type?T.fromEd25519VerificationKey2018(e):"JsonWebKey"===e.type||"JsonWebKey2020"===e.type?T.fromJsonWebKey(e):new T(e)}static fromEd25519VerificationKey2018({keyPair:e}={}){const t=x(M,s(e.publicKeyBase58)),i=new T({id:e.id,controller:e.controller,publicKeyMultibase:t});return e.privateKeyBase58&&(i.privateKeyMultibase=x(E,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 T.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,a=x(M,c(s));return T.from({id:e,controller:i,publicKeyMultibase:a})}static async generate({seed:e,...t}={}){let i;i=e?await m.generateKeyPairFromSeed(e):await m.generateKeyPair();const r=x(M,i.publicKey),o=x(E,i.secretKey);return new T({publicKeyMultibase:r,privateKeyMultibase:o,...t})}static fromFingerprint({fingerprint:e}={}){return new T({publicKeyMultibase:e})}get _publicKeyBuffer(){if(!this.publicKeyMultibase)return;return s(this.publicKeyMultibase.substr(1)).slice(M.length)}get _privateKeyBuffer(){if(!this.privateKeyMultibase)return;return s(this.privateKeyMultibase.substr(1)).slice(E.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"]=T.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=u(this._publicKeyBuffer)),t&&(i.d=u(this._privateKeyBuffer)),i}async jwkThumbprint(){const e=`{"crv":"Ed25519","kty":"OKP","x":"${u(this._publicKeyBuffer)}"}`,t=(new TextEncoder).encode(e);return u(new Uint8Array(await m.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]===M[0]&&t[1]===M[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 m.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 m.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"+a(i)}T.suite=K,T.SUITE_CONTEXT="https://w3id.org/security/suites/ed25519-2020/v1";var V,P,S=(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){
14
+ const K="Ed25519VerificationKey2020",M=new Uint8Array([237,1]),E=new Uint8Array([128,38]);class T extends v{constructor(e={}){super(e),this.type=K;const{publicKeyMultibase:t,privateKeyMultibase:i}=e;if(!t)throw new TypeError('The "publicKeyMultibase" property is required.');if(!t||!k(t,M))throw new Error(`"publicKeyMultibase" has invalid header bytes: "${t}".`);if(i&&!k(i,E))throw new Error('"privateKeyMultibase" has invalid header bytes.');this.publicKeyMultibase=t,this.privateKeyMultibase=i,this.controller&&!this.id&&(this.id=`${this.controller}#${this.fingerprint()}`),w({bytes:this._publicKeyBuffer,code:"invalidPublicKeyLength",expectedLength:32})}static async from(e){return"Ed25519VerificationKey2018"===e.type?T.fromEd25519VerificationKey2018(e):"JsonWebKey"===e.type||"JsonWebKey2020"===e.type?T.fromJsonWebKey(e):new T(e)}static fromEd25519VerificationKey2018({keyPair:e}={}){const t=x(M,o(e.publicKeyBase58)),i=new T({id:e.id,controller:e.controller,publicKeyMultibase:t});return e.privateKeyBase58&&(i.privateKeyMultibase=x(E,o(e.privateKeyBase58))),i}static fromJsonWebKey2020({id:e,type:t,controller:i,publicKeyJwk:r}={}){if("JsonWebKey2020"!==t)throw new TypeError(`Invalid key type: "${t}".`);return T.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:s}=r;if("OKP"!==o)throw new TypeError('"kty" is required to be "OKP".');if("Ed25519"!==s)throw new TypeError('"crv" is required to be "Ed25519".');const{x:a}=r,c=x(M,n(a));return T.from({id:e,controller:i,publicKeyMultibase:c})}static async generate({seed:e,...t}={}){let i;i=e?await g.generateKeyPairFromSeed(e):await g.generateKeyPair();const r=x(M,i.publicKey),o=x(E,i.secretKey);return new T({publicKeyMultibase:r,privateKeyMultibase:o,...t})}static fromFingerprint({fingerprint:e}={}){return new T({publicKeyMultibase:e})}get _publicKeyBuffer(){if(!this.publicKeyMultibase)return;return o(this.publicKeyMultibase.substr(1)).slice(M.length)}get _privateKeyBuffer(){if(!this.privateKeyMultibase)return;return o(this.privateKeyMultibase.substr(1)).slice(E.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"]=T.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=s(this._publicKeyBuffer)),t&&(i.d=s(this._privateKeyBuffer)),i}async jwkThumbprint(){const e=`{"crv":"Ed25519","kty":"OKP","x":"${s(this._publicKeyBuffer)}"}`,t=(new TextEncoder).encode(e);return s(new Uint8Array(await g.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=o(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]===M[0]&&t[1]===M[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 g.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 g.verify(e,t,i)},id:this.id}}}function k(e,t){if("string"!=typeof e||"z"!==e[0])return!1;const i=o(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"+a(i)}T.suite=K,T.SUITE_CONTEXT="https://w3id.org/security/suites/ed25519-2020/v1";var V,P,S=(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
  */
@@ -31,4 +31,4 @@ const{CONTEXT_URL:r}=i(1),o=i(0);e.exports={documentLoader(e){if(e!==r)throw new
31
31
  /*!
32
32
  * Copyright (c) 2020-2024 Digital Bazaar, Inc. All rights reserved.
33
33
  */
34
- const{suites:{LinkedDataSignature:O}}=o,D=C.constants.CONTEXT_URL;let L=class extends O{constructor({key:e,signer:t,verifier:i,proof:r,date:o,useNativeCanonize:n,canonizeOptions:s}={}){super({type:"Ed25519Signature2020",LDKeyClass:T,contextUrl:D,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"+a(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 p(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=D,!_({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 p(i);return i={...await o.export({publicKey:!0,includeContext:!0}),"@context":D,type:"Ed25519VerificationKey2020"},await this.assertVerificationMethod({verificationMethod:i}),i}async matchProof({proof:e,document:t,purpose:i,documentLoader:r}){if(!_({document:t,contextUrl:D}))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 _({document:e,contextUrl:t}){const i=e["@context"];return i===t||Array.isArray(i)&&i.includes(t)}L.CONTEXT_URL=D,L.CONTEXT=C.contexts.get(D);const{purposes:{AssertionProofPurpose:U,AuthenticationProofPurpose:A}}=o;var j;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.ensureVerificationMethodValidity="ensureVerificationMethodValidity",e.checkDocumentSignature="checkDocumentSignature"}(j||(j={}));class J extends l{verificationProcess=[j.retrieveVerificationMethodPublicKey,j.ensureVerificationMethodValidity,j.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:A,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(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")}async publicKeyJwkToString(e){return await d.fingerprintFromPublicKey(e)}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.issuer.didDocument;return function(e){return e in t?{contextUrl:null,document:t[e],documentUrl:e}:n.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 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(j.retrieveVerificationMethodPublicKey,(async()=>{const e=this.getTargetVerificationMethodContainer();if(!e)throw new r(j.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.");if(this.verificationMethod=this.findVerificationMethod(e.verificationMethod,e.id),!this.verificationMethod)throw new r(j.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.");try{this.publicKey=this.verificationMethod.publicKeyMultibase??await this.publicKeyJwkToString(this.verificationMethod)}catch(e){console.error("ERROR retrieving Ed25519Signature2020 public key",e)}const t=await T.from({...this.verificationMethod});if(!t)throw new r(j.retrieveVerificationMethodPublicKey,"Could not derive the verification key");if(t.revoked)throw new r(j.retrieveVerificationMethodPublicKey,"The verification key has been revoked");return t}),this.type)}async ensureVerificationMethodValidity(){await this.executeStep(j.ensureVerificationMethodValidity,(async()=>{if(this.verificationMethod.expires){if(new Date(this.verificationMethod.expires).getTime()<Date.now())throw new r(j.ensureVerificationMethodValidity,"The verification key has expired")}if(this.verificationMethod.revoked)throw new r(j.ensureVerificationMethodValidity,"The verification key has been revoked")}),this.type)}async checkDocumentSignature(){await this.executeStep(j.checkDocumentSignature,(async()=>{const e=new L({key:this.verificationKey});e.date=new Date(Date.now()).toISOString(),"authentication"!==this.proofPurpose||this.proof.challenge||(this.proof.challenge="");const t=await o.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 r(j.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed: ${this.getErrorMessage(t)}`);console.log("Credential Ed25519 signature successfully verified")}),this.type)}}export{J as default};
34
+ const{suites:{LinkedDataSignature:D}}=c,O=C.constants.CONTEXT_URL;let L=class extends D{constructor({key:e,signer:t,verifier:i,proof:r,date:o,useNativeCanonize:n,canonizeOptions:s}={}){super({type:"Ed25519Signature2020",LDKeyClass:T,contextUrl:O,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"+a(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 n=o(r.substr(1));let{verifier:s}=this;if(!s){s=(await p(t)).verifier()}return s.verify({data:e,signature:n})}async assertVerificationMethod({verificationMethod:e}){let t;if("Ed25519VerificationKey2020"!==e.type)throw new Error(`Unsupported key type "${e.type}".`);if(t=O,!_({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 p(i);return i={...await o.export({publicKey:!0,includeContext:!0}),"@context":O,type:"Ed25519VerificationKey2020"},await this.assertVerificationMethod({verificationMethod:i}),i}async matchProof({proof:e,document:t,purpose:i,documentLoader:r}){if(!_({document:t,contextUrl:O}))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 _({document:e,contextUrl:t}){const i=e["@context"];return i===t||Array.isArray(i)&&i.includes(t)}L.CONTEXT_URL=O,L.CONTEXT=C.contexts.get(O);const{purposes:{AssertionProofPurpose:U,AuthenticationProofPurpose:A}}=c;var J;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.ensureVerificationMethodValidity="ensureVerificationMethodValidity",e.checkDocumentSignature="checkDocumentSignature"}(J||(J={}));class j extends u{verificationProcess=[J.retrieveVerificationMethodPublicKey,J.ensureVerificationMethodValidity,J.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:A,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(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")}async publicKeyJwkToString(e){return await l.fingerprintFromPublicKey(e)}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.issuer.didDocument;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 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(J.retrieveVerificationMethodPublicKey,async()=>{const e=this.getTargetVerificationMethodContainer();if(!e)throw new r(J.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.");if(this.verificationMethod=this.findVerificationMethod(e.verificationMethod,e.id),!this.verificationMethod)throw new r(J.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.");try{this.publicKey=this.verificationMethod.publicKeyMultibase??await this.publicKeyJwkToString(this.verificationMethod)}catch(e){console.error("ERROR retrieving Ed25519Signature2020 public key",e)}const t=await T.from({...this.verificationMethod});if(!t)throw new r(J.retrieveVerificationMethodPublicKey,"Could not derive the verification key");if(t.revoked)throw new r(J.retrieveVerificationMethodPublicKey,"The verification key has been revoked");return t},this.type)}async ensureVerificationMethodValidity(){await this.executeStep(J.ensureVerificationMethodValidity,async()=>{if(this.verificationMethod.expires){if(new Date(this.verificationMethod.expires).getTime()<Date.now())throw new r(J.ensureVerificationMethodValidity,"The verification key has expired")}if(this.verificationMethod.revoked)throw new r(J.ensureVerificationMethodValidity,"The verification key has been revoked")},this.type)}async checkDocumentSignature(){await this.executeStep(J.checkDocumentSignature,async()=>{const e=new L({key:this.verificationKey});e.date=new Date(Date.now()).toISOString(),"authentication"!==this.proofPurpose||this.proof.challenge||(this.proof.challenge="");const t=await c.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 r(J.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed: ${this.getErrorMessage(t)}`);console.log("Credential Ed25519 signature successfully verified")},this.type)}}export{j as default};
@@ -0,0 +1,14 @@
1
+ import{d as e,p as i,x as t,V as o}from"./main.js";import{D as r,r as n}from"./DataIntegrityProof-BhL7Kkhm-affsdujn.js";import{S as s,j as a}from"./Suite-Bu3gszvt-Dmvbh142.js";import{f as c}from"./index-DjD0A6uJ-BdFUkPCF.js";import{j as h}from"./jsonld-signatures-D4X_Irzi-D_wBqxSl.js";import{E as d}from"./ed25519-key-pair.esm-DxoBwwVJ-D8j8wFfG.js";import"./tslib.es6--gQC4x5c-CmLYFWVC.js";import"./_polyfill-node.crypto-DGISCHrB-C5-OOGc0.js";
2
+ /*!
3
+ * Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
4
+ */
5
+ /*!
6
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
7
+ */
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 n.canonize(o,i)}
9
+ /*!
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:u,AuthenticationProofPurpose:p}}=h;
12
+ /*!
13
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
14
+ */var l;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.ensureVerificationMethodValidity="ensureVerificationMethodValidity",e.checkDocumentSignature="checkDocumentSignature"}(l||(l={}));class y extends s{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 await d.fingerprintFromPublicKey(e)}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(){i[this.documentToVerify.issuer]=this.issuer.didDocument,i[this.proof.verificationMethod]=this.getMultikeyRepresentation();return function(e){return e in i?{contextUrl:null,document:i[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:t(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.");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.");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");if(i.revoked)throw new o(l.retrieveVerificationMethodPublicKey,"The verification key has been revoked");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")}if(this.verificationMethod.revoked)throw new o(l.ensureVerificationMethodValidity,"The verification key has been revoked")},this.type)}async checkDocumentSignature(){await this.executeStep(l.checkDocumentSignature,async()=>{const e=new r({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)}`);console.log("Credential EddsaRdfc2022 signature successfully verified")},this.type)}}export{y as default};