@blockcerts/blockcerts-verifier 1.72.1 → 1.72.3

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 +2161 -1489
  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 +143 -134
  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 +11 -11
  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
@@ -1,7 +1,7 @@
1
- import{r as t,j as e}from"./jsonld-signatures-BbHr1fSN-BSospRuX.js";import{e as r,d as o}from"./index-DZLKRa_V-D_IQzjvG.js";import{d as i}from"./base64url-Cy03LJLt-vkTPfQOh.js";var n=t();
1
+ import{r as t}from"./Suite-Bu3gszvt-Dmvbh142.js";import{u as e,f as r,s as o}from"./main.js";import{j as i}from"./jsonld-signatures-D4X_Irzi-D_wBqxSl.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}}=e;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:e}){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 e.proofValue="z"+r(o),e}async verifySignature({verifyData:t,verificationMethod:e,proof:r}){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}=r;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=o(a.slice(1));else{if("u"!==s)throw new Error("Only base58btc or base64url multibase encoding is supported.");c=i(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};
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,30 @@
1
+ import{d as e,p as t,V as n,s as r,u as o,t as i}from"./main.js";import{j as a}from"./jsonld-signatures-D4X_Irzi-D_wBqxSl.js";import{S as s,j as u}from"./Suite-Bu3gszvt-Dmvbh142.js";import{D as c,r as f}from"./DataIntegrityProof-BhL7Kkhm-affsdujn.js";import{f as l}from"./index-DZ7aUhT_-D0G2DVsh.js";import"./pako.esm-BGRKTPxS-Bodm4Eha.js";import"./index-CyNtT_1q-Dgus2xdV.js";import{r as d}from"./retrieveVerificationMethodPublicKey-D_autuwE-DGbK-RPm.js";import"./sha2-JcCWfgvE-By1_saxP.js";
2
+ /*!
3
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
4
+ */
5
+ const h=globalThis.crypto;
6
+ /*!
7
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
8
+ */function p({algorithm:e="sha256"}={}){if("sha256"!==e)throw new Error(`Unsupported algorithm "${e}".`);return{hash:async e=>new Uint8Array(await h.subtle.digest("SHA-256",e))}}
9
+ /*!
10
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
11
+ */const y=new TextEncoder;function w(e){return y.encode(e)}
12
+ /*!
13
+ * Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
14
+ */async function g({document:e,labelMapFactoryFunction:t,options:n}={}){const{nquads:r}=await async function({document:e,nquads:t,labelMapFactoryFunction:n,options:r}={}){let o,i=new Map;o=e?await m(e,{...r,canonicalIdMap:i}):await m(t.join(""),{...r,inputFormat:"application/n-quads",canonicalIdMap:i});i=function(e){let t=!1,n=!1,r=!1;const o=new Map;for(const[i,a]of e){if(!t&&(t=!0,n=i.startsWith("_:"),r=a.startsWith("_:"),!n&&!r))return e;o.set(n?i.slice(2):i,r?a.slice(2):a)}return o}(i);const a=await n({canonicalIdMap:i}),s=new Map;for(const[e,t]of a)s.set(i.get(e),t);const u=(e,t,n)=>"_:"+s.get(n);return{nquads:o.split("\n").slice(0,-1).map(e=>e.replace(/(_:([^\s]+))/g,u)+"\n").sort(),labelMap:a}}
15
+ /*!
16
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
17
+ */({document:e,labelMapFactoryFunction:t,options:n});return r}async function m(e,t){if(!t||"object"!=typeof t)throw new TypeError('"options" must be an object.');if(t={algorithm:"RDFC-1.0",format:"application/n-quads",base:null,safe:!0,...t},"string"!=typeof e){const n={rdfDirection:"i18n-datatype",...t,produceGeneralizedRdf:!1};delete n.format,e=await u.toRDF(e,n)}return f.canonize(e,t)}async function b({document:e,proof:t,options:n,hasher:r}={}){r||(r=p());const o=await async function({document:e,proof:t,options:n}={}){return delete(t={"@context":e["@context"],...t}).proofValue,m(t,n)}({document:e,proof:t,options:n});return r.hash(w(o))}const v=["string","number","bigint","symbol"],E=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function M(e){if(null===e)return"null";if(void 0===e)return"undefined";if(!0===e||!1===e)return"boolean";const t=typeof e;if(v.includes(t))return t;if("function"===t)return"Function";if(Array.isArray(e))return"Array";if(function(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}(e))return"Buffer";const n=function(e){const t=Object.prototype.toString.call(e).slice(8,-1);if(E.includes(t))return t;return}(e);return n||"Object"}class ${constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}}$.uint=new $(0,"uint",!0),$.negint=new $(1,"negint",!0),$.bytes=new $(2,"bytes",!0),$.string=new $(3,"string",!0),$.array=new $(4,"array",!1),$.map=new $(5,"map",!1),$.tag=new $(6,"tag",!1),$.float=new $(7,"float",!0),$.false=new $(7,"false",!0),$.true=new $(7,"true",!0),$.null=new $(7,"null",!0),$.undefined=new $(7,"undefined",!0),$.break=new $(7,"break",!0);class A{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}}const T=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&"function"==typeof globalThis.Buffer.isBuffer,S=new TextDecoder,k=new TextEncoder;function I(e){return T&&globalThis.Buffer.isBuffer(e)}const j=T?(e,t,n)=>n-t>64?globalThis.Buffer.from(e.subarray(t,n)).toString("utf8"):N(e,t,n):(e,t,n)=>n-t>64?S.decode(e.subarray(t,n)):N(e,t,n),V=T?e=>e.length>64?globalThis.Buffer.from(e):B(e):e=>e.length>64?k.encode(e):B(e),U=T?(e,t,n)=>I(e)?new Uint8Array(e.subarray(t,n)):e.slice(t,n):(e,t,n)=>e.slice(t,n);function B(e){const t=[];let n=0;for(let r=0;r<e.length;r++){let o=e.charCodeAt(r);o<128?t[n++]=o:o<2048?(t[n++]=o>>6|192,t[n++]=63&o|128):55296==(64512&o)&&r+1<e.length&&56320==(64512&e.charCodeAt(r+1))?(o=65536+((1023&o)<<10)+(1023&e.charCodeAt(++r)),t[n++]=o>>18|240,t[n++]=o>>12&63|128,t[n++]=o>>6&63|128,t[n++]=63&o|128):(t[n++]=o>>12|224,t[n++]=o>>6&63|128,t[n++]=63&o|128)}return t}function N(e,t,n){const r=[];for(;t<n;){const o=e[t];let i=null,a=o>239?4:o>223?3:o>191?2:1;if(t+a<=n){let n,r,s,u;switch(a){case 1:o<128&&(i=o);break;case 2:n=e[t+1],128==(192&n)&&(u=(31&o)<<6|63&n,u>127&&(i=u));break;case 3:n=e[t+1],r=e[t+2],128==(192&n)&&128==(192&r)&&(u=(15&o)<<12|(63&n)<<6|63&r,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:n=e[t+1],r=e[t+2],s=e[t+3],128==(192&n)&&128==(192&r)&&128==(192&s)&&(u=(15&o)<<18|(63&n)<<12|(63&r)<<6|63&s,u>65535&&u<1114112&&(i=u))}}null===i?(i=65533,a=1):i>65535&&(i-=65536,r.push(i>>>10&1023|55296),i=56320|1023&i),r.push(i),t+=a}return function(e){const t=e.length;if(t<=D)return String.fromCharCode.apply(String,e);let n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=D));return n}(r)}const D=4096;const x="CBOR decode error:",P="CBOR encode error:";function K(e,t,n){if(e.length-t<n)throw new Error(`${x} not enough data for type`)}const F=[24,256,65536,4294967296,BigInt("18446744073709551616")];function C(e,t,n){K(e,t,1);const r=e[t];if(!0===n.strict&&r<F[0])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return r}function z(e,t,n){K(e,t,2);const r=e[t]<<8|e[t+1];if(!0===n.strict&&r<F[1])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return r}function H(e,t,n){K(e,t,4);const r=16777216*e[t]+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(!0===n.strict&&r<F[2])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);return r}function _(e,t,n){K(e,t,8);const r=16777216*e[t]+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=16777216*e[t+4]+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(r)<<BigInt(32))+BigInt(o);if(!0===n.strict&&i<F[3])throw new Error(`${x} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(!0===n.allowBigInt)return i;throw new Error(`${x} integers outside of the safe integer range are not supported`)}function O(e,t){return L(e,0,t.value)}function L(e,t,n){if(n<F[0]){const r=Number(n);e.push([t|r])}else if(n<F[1]){const r=Number(n);e.push([24|t,r])}else if(n<F[2]){const r=Number(n);e.push([25|t,r>>>8,255&r])}else if(n<F[3]){const r=Number(n);e.push([26|t,r>>>24&255,r>>>16&255,r>>>8&255,255&r])}else{const r=BigInt(n);if(!(r<F[4]))throw new Error(`${x} encountered BigInt larger than allowable range`);{const n=[27|t,0,0,0,0,0,0,0];let o=Number(r&BigInt(4294967295)),i=Number(r>>BigInt(32)&BigInt(4294967295));n[8]=255&o,o>>=8,n[7]=255&o,o>>=8,n[6]=255&o,o>>=8,n[5]=255&o,n[4]=255&i,i>>=8,n[3]=255&i,i>>=8,n[2]=255&i,i>>=8,n[1]=255&i,e.push(n)}}}O.encodedSize=function(e){return L.encodedSize(e.value)},L.encodedSize=function(e){return e<F[0]?1:e<F[1]?2:e<F[2]?3:e<F[3]?5:9},O.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};const R=BigInt(-1),G=BigInt(1);function q(e,t){const n=t.value,r="bigint"==typeof n?n*R-G:-1*n-1;L(e,t.type.majorEncoded,r)}function W(e,t,n,r){K(e,t,n+r);const o=U(e,t+n,t+n+r);return new A($.bytes,o,n+r)}function J(e,t,n,r){return W(e,t,1,n)}function X(e){return void 0===e.encodedBytes&&(e.encodedBytes=e.type===$.string?V(e.value):e.value),e.encodedBytes}function Z(e,t){const n=X(t);L(e,t.type.majorEncoded,n.length),e.push(n)}function Q(e,t,n,r,o){const i=n+r;K(e,t,i);const a=new A($.string,j(e,t+n,t+i),i);return!0===o.retainStringBytes&&(a.byteValue=U(e,t+n,t+i)),a}function Y(e,t,n,r){return Q(e,t,1,n,r)}q.encodedSize=function(e){const t=e.value,n="bigint"==typeof t?t*R-G:-1*t-1;return n<F[0]?1:n<F[1]?2:n<F[2]?3:n<F[3]?5:9},q.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0},Z.encodedSize=function(e){const t=X(e);return L.encodedSize(t.length)+t.length},Z.compareTokens=function(e,t){return n=X(e),r=X(t),n.length<r.length?-1:n.length>r.length?1:function(e,t){if(I(e)&&I(t))return e.compare(t);for(let n=0;n<e.length;n++)if(e[n]!==t[n])return e[n]<t[n]?-1:1;return 0}(n,r);var n,r};const ee=Z;function te(e,t,n,r){return new A($.array,r,n)}function ne(e,t,n,r){return te(0,0,1,n)}function re(e,t){L(e,$.array.majorEncoded,t.value)}function oe(e,t,n,r){return new A($.map,r,n)}function ie(e,t,n,r){return oe(0,0,1,n)}function ae(e,t){L(e,$.map.majorEncoded,t.value)}function se(e,t,n,r){return new A($.tag,n,1)}function ue(e,t){L(e,$.tag.majorEncoded,t.value)}re.compareTokens=O.compareTokens,re.encodedSize=function(e){return L.encodedSize(e.value)},ae.compareTokens=O.compareTokens,ae.encodedSize=function(e){return L.encodedSize(e.value)},ue.compareTokens=O.compareTokens,ue.encodedSize=function(e){return L.encodedSize(e.value)};function ce(e,t,n){if(n){if(!1===n.allowNaN&&Number.isNaN(e))throw new Error(`${x} NaN values are not supported`);if(!1===n.allowInfinity&&(e===1/0||e===-1/0))throw new Error(`${x} Infinity values are not supported`)}return new A($.float,e,t)}function fe(e,t,n){const r=t.value;if(!1===r)e.push([20|$.float.majorEncoded]);else if(!0===r)e.push([21|$.float.majorEncoded]);else if(null===r)e.push([22|$.float.majorEncoded]);else if(void 0===r)e.push([23|$.float.majorEncoded]);else{let t,i=!1;n&&!0===n.float64||(pe(r),t=ye(he,1),r===t||Number.isNaN(r)?(he[0]=249,e.push(he.slice(0,3)),i=!0):(we(r),t=ge(he,1),r===t&&(he[0]=250,e.push(he.slice(0,5)),i=!0))),i||(o=r,de.setFloat64(0,o,!1),t=me(he,1),he[0]=251,e.push(he.slice(0,9)))}var o}fe.encodedSize=function(e,t){const n=e.value;if(!1===n||!0===n||null==n)return 1;if(!t||!0!==t.float64){pe(n);let e=ye(he,1);if(n===e||Number.isNaN(n))return 3;if(we(n),e=ge(he,1),n===e)return 5}return 9};const le=new ArrayBuffer(9),de=new DataView(le,1),he=new Uint8Array(le,0);function pe(e){if(e===1/0)de.setUint16(0,31744,!1);else if(e===-1/0)de.setUint16(0,64512,!1);else if(Number.isNaN(e))de.setUint16(0,32256,!1);else{de.setFloat32(0,e);const t=de.getUint32(0),n=(2139095040&t)>>23,r=8388607&t;if(255===n)de.setUint16(0,31744,!1);else if(0===n)de.setUint16(0,(2147483648&e)>>16|r>>13,!1);else{const e=n-127;e<-24?de.setUint16(0,0):e<-14?de.setUint16(0,(2147483648&t)>>16|1<<24+e,!1):de.setUint16(0,(2147483648&t)>>16|e+15<<10|r>>13,!1)}}}function ye(e,t){if(e.length-t<2)throw new Error(`${x} not enough data for float16`);const n=(e[t]<<8)+e[t+1];if(31744===n)return 1/0;if(64512===n)return-1/0;if(32256===n)return NaN;const r=n>>10&31,o=1023&n;let i;return i=0===r?o*2**-24:31!==r?(o+1024)*2**(r-25):0===o?1/0:NaN,32768&n?-i:i}function we(e){de.setFloat32(0,e,!1)}function ge(e,t){if(e.length-t<4)throw new Error(`${x} not enough data for float32`);const n=(e.byteOffset||0)+t;return new DataView(e.buffer,n,4).getFloat32(0,!1)}function me(e,t){if(e.length-t<8)throw new Error(`${x} not enough data for float64`);const n=(e.byteOffset||0)+t;return new DataView(e.buffer,n,8).getFloat64(0,!1)}function be(e,t,n){throw new Error(`${x} encountered invalid minor (${n}) for major ${e[t]>>>5}`)}function ve(e){return()=>{throw new Error(`${x} ${e}`)}}fe.compareTokens=O.compareTokens;const Ee=[];for(let e=0;e<=23;e++)Ee[e]=be;Ee[24]=function(e,t,n,r){return new A($.uint,C(e,t+1,r),2)},Ee[25]=function(e,t,n,r){return new A($.uint,z(e,t+1,r),3)},Ee[26]=function(e,t,n,r){return new A($.uint,H(e,t+1,r),5)},Ee[27]=function(e,t,n,r){return new A($.uint,_(e,t+1,r),9)},Ee[28]=be,Ee[29]=be,Ee[30]=be,Ee[31]=be;for(let e=32;e<=55;e++)Ee[e]=be;Ee[56]=function(e,t,n,r){return new A($.negint,-1-C(e,t+1,r),2)},Ee[57]=function(e,t,n,r){return new A($.negint,-1-z(e,t+1,r),3)},Ee[58]=function(e,t,n,r){return new A($.negint,-1-H(e,t+1,r),5)},Ee[59]=function(e,t,n,r){const o=_(e,t+1,r);if("bigint"!=typeof o){const e=-1-o;if(e>=Number.MIN_SAFE_INTEGER)return new A($.negint,e,9)}if(!0!==r.allowBigInt)throw new Error(`${x} integers outside of the safe integer range are not supported`);return new A($.negint,R-BigInt(o),9)},Ee[60]=be,Ee[61]=be,Ee[62]=be,Ee[63]=be;for(let e=64;e<=87;e++)Ee[e]=J;Ee[88]=function(e,t,n,r){return W(e,t,2,C(e,t+1,r))},Ee[89]=function(e,t,n,r){return W(e,t,3,z(e,t+1,r))},Ee[90]=function(e,t,n,r){return W(e,t,5,H(e,t+1,r))},Ee[91]=function(e,t,n,r){const o=_(e,t+1,r);if("bigint"==typeof o)throw new Error(`${x} 64-bit integer bytes lengths not supported`);return W(e,t,9,o)},Ee[92]=be,Ee[93]=be,Ee[94]=be,Ee[95]=ve("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)Ee[e]=Y;Ee[120]=function(e,t,n,r){return Q(e,t,2,C(e,t+1,r),r)},Ee[121]=function(e,t,n,r){return Q(e,t,3,z(e,t+1,r),r)},Ee[122]=function(e,t,n,r){return Q(e,t,5,H(e,t+1,r),r)},Ee[123]=function(e,t,n,r){const o=_(e,t+1,r);if("bigint"==typeof o)throw new Error(`${x} 64-bit integer string lengths not supported`);return Q(e,t,9,o,r)},Ee[124]=be,Ee[125]=be,Ee[126]=be,Ee[127]=ve("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)Ee[e]=ne;Ee[152]=function(e,t,n,r){return te(0,0,2,C(e,t+1,r))},Ee[153]=function(e,t,n,r){return te(0,0,3,z(e,t+1,r))},Ee[154]=function(e,t,n,r){return te(0,0,5,H(e,t+1,r))},Ee[155]=function(e,t,n,r){const o=_(e,t+1,r);if("bigint"==typeof o)throw new Error(`${x} 64-bit integer array lengths not supported`);return te(0,0,9,o)},Ee[156]=be,Ee[157]=be,Ee[158]=be,Ee[159]=function(e,t,n,r){if(!1===r.allowIndefinite)throw new Error(`${x} indefinite length items not allowed`);return te(0,0,1,1/0)};for(let e=160;e<=183;e++)Ee[e]=ie;Ee[184]=function(e,t,n,r){return oe(0,0,2,C(e,t+1,r))},Ee[185]=function(e,t,n,r){return oe(0,0,3,z(e,t+1,r))},Ee[186]=function(e,t,n,r){return oe(0,0,5,H(e,t+1,r))},Ee[187]=function(e,t,n,r){const o=_(e,t+1,r);if("bigint"==typeof o)throw new Error(`${x} 64-bit integer map lengths not supported`);return oe(0,0,9,o)},Ee[188]=be,Ee[189]=be,Ee[190]=be,Ee[191]=function(e,t,n,r){if(!1===r.allowIndefinite)throw new Error(`${x} indefinite length items not allowed`);return oe(0,0,1,1/0)};for(let e=192;e<=215;e++)Ee[e]=se;Ee[216]=function(e,t,n,r){return new A($.tag,C(e,t+1,r),2)},Ee[217]=function(e,t,n,r){return new A($.tag,z(e,t+1,r),3)},Ee[218]=function(e,t,n,r){return new A($.tag,H(e,t+1,r),5)},Ee[219]=function(e,t,n,r){return new A($.tag,_(e,t+1,r),9)},Ee[220]=be,Ee[221]=be,Ee[222]=be,Ee[223]=be;for(let e=224;e<=243;e++)Ee[e]=ve("simple values are not supported");Ee[244]=be,Ee[245]=be,Ee[246]=be,Ee[247]=function(e,t,n,r){if(!1===r.allowUndefined)throw new Error(`${x} undefined values are not supported`);return!0===r.coerceUndefinedToNull?new A($.null,null,1):new A($.undefined,void 0,1)},Ee[248]=ve("simple values are not supported"),Ee[249]=function(e,t,n,r){return ce(ye(e,t+1),3,r)},Ee[250]=function(e,t,n,r){return ce(ge(e,t+1),5,r)},Ee[251]=function(e,t,n,r){return ce(me(e,t+1),9,r)},Ee[252]=be,Ee[253]=be,Ee[254]=be,Ee[255]=function(e,t,n,r){if(!1===r.allowIndefinite)throw new Error(`${x} indefinite length items not allowed`);return new A($.break,void 0,1)};const Me=[];for(let e=0;e<24;e++)Me[e]=new A($.uint,e,1);for(let e=-1;e>=-24;e--)Me[31-e]=new A($.negint,e,1);Me[64]=new A($.bytes,new Uint8Array(0),1),Me[96]=new A($.string,"",1),Me[128]=new A($.array,0,1),Me[160]=new A($.map,0,1),Me[244]=new A($.false,!1,1),Me[245]=new A($.true,!0,1),Me[246]=new A($.null,null,1),function(){const e=[];e[$.uint.major]=O,e[$.negint.major]=q,e[$.bytes.major]=Z,e[$.string.major]=ee,e[$.array.major]=re,e[$.map.major]=ae,e[$.tag.major]=ue,e[$.float.major]=fe}();class $e{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do{if(t.obj===e)return!0}while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${P} object contains circular references`);return new $e(t,e)}}const Ae={null:new A($.null,null),undefined:new A($.undefined,void 0),true:new A($.true,!0),false:new A($.false,!1),emptyArray:new A($.array,0),emptyMap:new A($.map,0)},Te={number:(e,t,n,r)=>Number.isInteger(e)&&Number.isSafeInteger(e)?new A(e>=0?$.uint:$.negint,e):new A($.float,e),bigint:(e,t,n,r)=>e>=BigInt(0)?new A($.uint,e):new A($.negint,e),Uint8Array:(e,t,n,r)=>new A($.bytes,e),string:(e,t,n,r)=>new A($.string,e),boolean:(e,t,n,r)=>e?Ae.true:Ae.false,null:(e,t,n,r)=>Ae.null,undefined:(e,t,n,r)=>Ae.undefined,ArrayBuffer:(e,t,n,r)=>new A($.bytes,new Uint8Array(e)),DataView:(e,t,n,r)=>new A($.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),Array(e,t,n,r){if(!e.length)return!0===n.addBreakTokens?[Ae.emptyArray,new A($.break)]:Ae.emptyArray;r=$e.createCheck(r,e);const o=[];let i=0;for(const t of e)o[i++]=Se(t,n,r);return n.addBreakTokens?[new A($.array,e.length),o,new A($.break)]:[new A($.array,e.length),o]},Object(e,t,n,r){const o="Object"!==t,i=o?e.keys():Object.keys(e),a=o?e.size:i.length;if(!a)return!0===n.addBreakTokens?[Ae.emptyMap,new A($.break)]:Ae.emptyMap;r=$e.createCheck(r,e);const s=[];let u=0;for(const t of i)s[u++]=[Se(t,n,r),Se(o?e.get(t):e[t],n,r)];return function(e,t){t.mapSorter&&e.sort(t.mapSorter)}(s,n),n.addBreakTokens?[new A($.map,a),s,new A($.break)]:[new A($.map,a),s]}};Te.Map=Te.Object,Te.Buffer=Te.Uint8Array;for(const e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Te[`${e}Array`]=Te.DataView;function Se(e,t={},n){const r=M(e),o=t&&t.typeEncoders&&t.typeEncoders[r]||Te[r];if("function"==typeof o){const i=o(e,r,t,n);if(null!=i)return i}const i=Te[r];if(!i)throw new Error(`${P} unsupported type: ${r}`);return i(e,r,t,n)}const ke={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0};class Ie{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){const e=this.data[this._pos];let t=Me[e];if(void 0===t){const n=Ee[e];if(!n)throw new Error(`${x} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);const r=31&e;t=n(this.data,this._pos,r,this.options)}return this._pos+=t.encodedLength,t}}const je=Symbol.for("DONE"),Ve=Symbol.for("BREAK");function Ue(e,t){if(e.done())return je;const n=e.next();if(n.type===$.break)return Ve;if(n.type.terminal)return n.value;if(n.type===$.array)return function(e,t,n){const r=[];for(let o=0;o<e.value;o++){const i=Ue(t,n);if(i===Ve){if(e.value===1/0)break;throw new Error(`${x} got unexpected break to lengthed array`)}if(i===je)throw new Error(`${x} found array but not enough entries (got ${o}, expected ${e.value})`);r[o]=i}return r}(n,e,t);if(n.type===$.map)return function(e,t,n){const r=!0===n.useMaps,o=r?void 0:{},i=r?new Map:void 0;for(let a=0;a<e.value;a++){const s=Ue(t,n);if(s===Ve){if(e.value===1/0)break;throw new Error(`${x} got unexpected break to lengthed map`)}if(s===je)throw new Error(`${x} found map but not enough entries (got ${a} [no key], expected ${e.value})`);if(!0!==r&&"string"!=typeof s)throw new Error(`${x} non-string keys not supported (got ${typeof s})`);if(!0===n.rejectDuplicateMapKeys&&(r&&i.has(s)||!r&&s in o))throw new Error(`${x} found repeat map key "${s}"`);const u=Ue(t,n);if(u===je)throw new Error(`${x} found map but not enough entries (got ${a} [no value], expected ${e.value})`);r?i.set(s,u):o[s]=u}return r?i:o}(n,e,t);if(n.type===$.tag){if(t.tags&&"function"==typeof t.tags[n.value]){const r=Ue(e,t);return t.tags[n.value](r)}throw new Error(`${x} tag not supported (${n.value})`)}throw new Error("unsupported")}function Be(e,t){const[n,r]=function(e,t){if(!(e instanceof Uint8Array))throw new Error(`${x} data to decode must be a Uint8Array`);const n=(t=Object.assign({},ke,t)).tokenizer||new Ie(e,t),r=Ue(n,t);if(r===je)throw new Error(`${x} did not find any content to decode`);if(r===Ve)throw new Error(`${x} got unexpected break`);return[r,e.subarray(n.pos())]}(e,t);if(r.length>0)throw new Error(`${x} too many terminals, data makes no sense`);return n}
18
+ /*!
19
+ * Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
20
+ */const Ne=new Uint8Array([217,93,1]),De=[];function xe({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=r(e.proofValue.slice(1));if(!function(e,t){for(let n=0;n<t.length;++n)if(e[n]!==t[n])return!1;return!0}(t,Ne))throw new TypeError('"proof.proofValue" must be a derived proof.');const n=t.subarray(Ne.length),[o,a,s,u,c]=Be(n,{useMaps:!0,tags:De}),f=function(e){const t=new Map;for(const[n,r]of e.entries())t.set(`c14n${n}`,`u${i(r)}`);return t}(u),l={baseSignature:o,publicKey:a,signatures:s,labelMap:f,mandatoryIndexes:c};return function({baseSignature:e,publicKey:t,signatures:n,labelMap:r,mandatoryIndexes:o}){if(!(e instanceof Uint8Array&&64===e.length))throw new TypeError('"baseSignature" must be a Uint8Array of length 64.');if(!(t instanceof Uint8Array&&35===t.length))throw new TypeError('"publicKey" must be a Uint8Array of length 35.');if(!Array.isArray(n)||!n.every(e=>e instanceof Uint8Array))throw new TypeError('"signatures" must be an array of Uint8Arrays.');if(!(r instanceof Map&&[...r.entries()].every(([e,t])=>"string"==typeof e&&"string"==typeof t)))throw new TypeError('"labelMap" must be a Map of strings to strings.');if(!Array.isArray(o)||!o.every(Number.isInteger))throw new TypeError('"mandatoryIndexes" must be an array of integers.')}(l),l}catch(e){const t=new TypeError('The proof does not include a valid "proofValue" property.');throw t.cause=e,t}}function Pe({proofHash:e,publicKey:t,mandatoryHash:n}={}){!function({proofHash:e,publicKey:t,mandatoryHash:n}){if(!(e instanceof Uint8Array&&32===e.length))throw new TypeError('"proofHash" must be a Uint8Array of length 32.');if(!(t instanceof Uint8Array&&35===t.length))throw new TypeError('"publicKey" must be a Uint8Array of length 35.');if(!(n instanceof Uint8Array&&32===n.length))throw new TypeError('"mandatoryHash" must be a Uint8Array of length 32.')}({proofHash:e,publicKey:t,mandatoryHash:n});return function(e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;for(const r of e)t.set(r,n),n+=r.length;return t}([e,t,n])}De[64]=function(e){return e}
21
+ /*!
22
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
23
+ */;const Ke="ecdsa-sd-2023";
24
+ /*!
25
+ * Copyright (c) 2022-2023 Digital Bazaar, Inc. All rights reserved.
26
+ */
27
+ /*!
28
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
29
+ */
30
+ function Fe({requiredAlgorithm:e="P-256"}={}){return{name:Ke,requiredAlgorithm:e,createVerifier:Ce,createVerifyData:ze}}async function Ce({verificationMethod:e}){const t=(await l(e)).verifier();return{algorithm:t.algorithm,id:t.id,verify:async({data:e})=>async function({verifier:e,data:t}={}){const{baseSignature:n,proofHash:r,publicKey:i,signatures:a,nonMandatory:s,mandatoryHash:u}=t,c="z"+o(i),f=await l({publicKeyMultibase:c});if(a.length!==s.length)throw new Error(`Signature count (${a.length}) does not match non-mandatory message count (${s.length}).`);const{verify:d}=f.verifier();if((await Promise.all(a.map((e,t)=>d({data:w(s[t]),signature:e})))).some(e=>!e))return!1;const h=await Pe({proofHash:r,publicKey:i,mandatoryHash:u});return e.verify({data:h,signature:n})}({verifier:t,data:e})}}async function ze({cryptosuite:e,document:t,proof:n,documentLoader:r}){if(e?.name!==Ke)throw new TypeError(`"cryptosuite.name" must be "${Ke}".`);const o={documentLoader:r},i=b({document:t,proof:n,options:o}).catch(e=>e),{baseSignature:a,publicKey:s,signatures:u,labelMap:c,mandatoryIndexes:f}=await xe({proof:n}),l=await function({labelMap:e}={}){return async({canonicalIdMap:t})=>{const n=new Map;for(const[r,o]of t)n.set(r,e.get(o));return n}}({labelMap:c}),d=await g({document:t,labelMapFactoryFunction:l,options:o}),h=[],y=[];for(const[e,t]of d.entries())f.includes(e)?h.push(t):y.push(t);const{mandatoryHash:m}=await async function({mandatory:e,hasher:t}={}){return t||(t=p()),{mandatoryHash:await t.hash(w(e.join("")))}}({mandatory:h}),v=await i;if(v instanceof Error)throw v;return{baseSignature:a,proofHash:v,publicKey:s,signatures:u,nonMandatory:y,mandatoryHash:m}}const{purposes:{AssertionProofPurpose:He,AuthenticationProofPurpose:_e}}=a;var Oe;!function(e){e.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",e.ensureVerificationMethodValidity="ensureVerificationMethodValidity",e.checkDocumentSignature="checkDocumentSignature"}(Oe||(Oe={}));class Le extends s{verificationProcess=[Oe.retrieveVerificationMethodPublicKey,Oe.ensureVerificationMethodValidity,Oe.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:_e,assertionMethod:He},this.validateProofType()}async init(){}async verifyProof(){for(const e of this.verificationProcess){if(!this[e])return void console.error("verification logic for",e,"not implemented");await this[e]()}}async verifyIdentity(){}getProofVerificationSteps(t){return this.verificationProcess.map(n=>e.verifier.convertToVerificationSubsteps(t,n))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return this.publicKey}getIssuerName(){return this.issuer.name??""}getIssuerProfileDomain(){try{return new URL(this.getIssuerProfileUrl()).hostname??""}catch(e){return""}}getIssuerProfileUrl(){return this.issuer.id??""}getSigningDate(){return this.proof.created}async executeStep(e,t,n){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}validateProofType(){const e=this.proof.type;if("DataIntegrityProof"===e){const e=this.proof.cryptosuite;if(!e)throw new Error(`Malformed proof passed. With DataIntegrityProof a cryptosuite must be defined. Expected: ${this.cryptosuite}`);if(e!==this.cryptosuite)throw new Error(`Incompatible proof cryptosuite passed. Expected: ${this.cryptosuite}, Got: ${e}`);return}if(e!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${e}`)}generateDocumentLoader(e=[]){e.forEach(e=>{t[e.url]=e.value}),t[this.documentToVerify.issuer]=this.getTargetVerificationMethodContainer();return function(e){return e in t?{contextUrl:null,document:t[e],documentUrl:e}:u.documentLoader(e)}}getErrorMessage(e){return e.error.errors[0].message}getTargetVerificationMethodContainer(){if(this.issuer.didDocument){if(this.findVerificationMethod(this.issuer.didDocument.verificationMethod,this.issuer.didDocument.id))return this.issuer.didDocument}const e={...this.issuer};return delete e.didDocument,e}findVerificationMethod(e,t){return e.find(e=>e.id===this.proof.verificationMethod||t+e.id===this.proof.verificationMethod)??null}async retrieveVerificationMethodPublicKey(){this.verificationKey=await this.executeStep(Oe.retrieveVerificationMethodPublicKey,async()=>{if(this.verificationMethod=d(this.getTargetVerificationMethodContainer(),this.proof.verificationMethod),!this.verificationMethod)throw new n(Oe.retrieveVerificationMethodPublicKey,"Could not derive the verification key");if(this.verificationMethod.revoked)throw new n(Oe.retrieveVerificationMethodPublicKey,"The verification key has been revoked");return this.verificationMethod},this.type)}async ensureVerificationMethodValidity(){await this.executeStep(Oe.ensureVerificationMethodValidity,async()=>{if(this.verificationMethod.expires){if(new Date(this.verificationMethod.expires).getTime()<Date.now())throw new n(Oe.ensureVerificationMethodValidity,"The verification key has expired")}if(this.verificationMethod.revoked)throw new n(Oe.ensureVerificationMethodValidity,"The verification key has been revoked")},this.type)}async checkDocumentSignature(){await this.executeStep(Oe.checkDocumentSignature,async()=>{const e=new c({cryptosuite:Fe({requiredAlgorithm:"K-256"})}),t=this.documentToVerify.proof.verificationMethod;"authentication"!==this.proofPurpose||this.proof.challenge||(this.proof.challenge="");const r=await a.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(!r.verified)throw console.error(JSON.stringify(r,null,2)),new n(Oe.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed: ${this.getErrorMessage(r)}`);console.log(`Credential ${this.type} signature successfully verified`)},this.type)}}export{Le as default};
@@ -0,0 +1 @@
1
+ import{d as e,p as t,a as i,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};