@blockcerts/blockcerts-verifier 1.61.0 → 1.62.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/bundle-stats.html +1 -1
  2. package/dist/{EcdsaSecp256k1Signature2019-Z9cbZqwb-BZqYyWXC.js → EcdsaSecp256k1Signature2019-aV3C41Ue-_mP0Wq_n.js} +2 -2
  3. package/dist/{Ed25519Signature2020-gHlOabgN-BQNMKhh-.js → Ed25519Signature2020-CL2yKnJW-NRYSGvkI.js} +5 -5
  4. package/dist/{HashlinkVerifier-JKby3RuX-Bn4E9EeP.js → HashlinkVerifier-MEwSZe4T-BdYYAALa.js} +1 -1
  5. package/dist/{MerkleProof2017-qKpIAsVw-Diu6ftp6.js → MerkleProof2017-CNSx436a-FBaGRIN1.js} +1 -1
  6. package/dist/{MerkleProof2019-lYqSLW83-CdVVDNe8.js → MerkleProof2019-DnbP3r0f-Cp4GWjQh.js} +1 -1
  7. package/dist/{checkCredentialSchemaConformity-wYKX-T36-TKejNdGn.js → checkCredentialSchemaConformity-QPmIWPLG-De1kKyvF.js} +1 -1
  8. package/dist/{checkRevocationStatusList2021-Zs7RTfS8-B_SBTuUQ.js → checkRevocationStatusList2021-Cy-rWyh7-CVOeAbdp.js} +1 -1
  9. package/dist/controlVerificationMethod-CXzAI0QS-b45qIaR4.js +1 -0
  10. package/dist/{did-key-common.esm-pD02457t-BaQe2n2J.js → did-key-common.esm-CJj7pea6-Er8YwHoJ.js} +3 -3
  11. package/dist/{did-key-ed25519.esm-QkrYsBOv-KuYPtNeV.js → did-key-ed25519.esm-hEATvNhJ-CHAq7sf1.js} +1 -1
  12. package/dist/{did-key-secp256k1.esm-byA8GFc3-AosubhwX.js → did-key-secp256k1.esm-CIEM56eq-EQahxyFZ.js} +1 -1
  13. package/dist/{index-zUaES8qy-CMAhMZvu.js → index-DWAZG7Ja-CBt_boC3.js} +2 -2
  14. package/dist/{jsonld-signatures-Lb-laFSH-v4kRGxlk.js → jsonld-signatures-zDEkNjYR-D3vK8GYH.js} +7 -7
  15. package/dist/main.js +42 -32
  16. package/dist/{x25519-axOdeC_8-BeczdkXC.js → x25519-BzvT3haI-DcUk09rC.js} +1 -1
  17. package/package.json +2 -2
  18. package/dist/controlVerificationMethod-MnvnHDi1-BAzkUIZW.js +0 -1
  19. /package/dist/{Suite-Bhitn5l3-D1ucdMDB.js → Suite-B7Vy9AuU-D1ucdMDB.js} +0 -0
  20. /package/dist/{_commonjs-dynamic-modules-F7P8sER7-BHR_E30J.js → _commonjs-dynamic-modules-COweQ1RR-BHR_E30J.js} +0 -0
  21. /package/dist/{base64url-qi3FT6uz-vkTPfQOh.js → base64url-Cy03LJLt-vkTPfQOh.js} +0 -0
  22. /package/dist/{elliptic-ycTr8sXF-D-NH8siB.js → elliptic-DVE5q-l5-D-NH8siB.js} +0 -0
  23. /package/dist/{ensureNotRevoked-EDQJmT-v-DvMIgM4L.js → ensureNotRevoked-bD_ITwQb-DvMIgM4L.js} +0 -0
  24. /package/dist/{ensureValidIssuingKey-_gUzjB7e-frafTbMl.js → ensureValidIssuingKey-wRebznsK-frafTbMl.js} +0 -0
  25. /package/dist/{index-tKimblBp-Dgus2xdV.js → index-CcA_A5fd-Dgus2xdV.js} +0 -0
  26. /package/dist/{index-CZOUZnn4-ZifknGWx.js → index-DUjMpuQT-ZifknGWx.js} +0 -0
  27. /package/dist/{index-qAZ-fmOX-CHN5LgUq.js → index-yP42zfkJ-CHN5LgUq.js} +0 -0
  28. /package/dist/{jsonld-8ujMRGin-D_C9ciG_.js → jsonld-Pr6hPH-i-D_C9ciG_.js} +0 -0
  29. /package/dist/{pako.esm-jjCKMBM4-HambcU-w.js → pako.esm-DnD5dZGi-HambcU-w.js} +0 -0
  30. /package/dist/{sha256-OznnmV9J-BYFBxJ7m.js → sha256-wKiO0px2-BYFBxJ7m.js} +0 -0
  31. /package/dist/{tslib.es6-M1zqH4el-CmLYFWVC.js → tslib.es6-CNEFicEt-CmLYFWVC.js} +0 -0
@@ -1,8 +1,8 @@
1
- import{d as t,h as e,f as r,V as n,q as i,B as o,i as a}from"./main.js";import{j as c}from"./jsonld-signatures-Lb-laFSH-v4kRGxlk.js";import{j as s}from"./jsonld-8ujMRGin-D_C9ciG_.js";import{d as u,e as f}from"./index-CZOUZnn4-ZifknGWx.js";import{d as p,e as l}from"./base64url-qi3FT6uz-vkTPfQOh.js";import{_ as y}from"./tslib.es6-M1zqH4el-CmLYFWVC.js";import{x as h,e as d}from"./x25519-axOdeC_8-BeczdkXC.js";import{S as w}from"./Suite-Bhitn5l3-D1ucdMDB.js";import"./_commonjs-dynamic-modules-F7P8sER7-BHR_E30J.js";
1
+ import{d as t,h as e,f as r,V as n,q as i,B as o,i as a}from"./main.js";import{j as c}from"./jsonld-signatures-zDEkNjYR-D3vK8GYH.js";import{j as s}from"./jsonld-Pr6hPH-i-D_C9ciG_.js";import{d as u,e as f}from"./index-DUjMpuQT-ZifknGWx.js";import{d as p,e as l}from"./base64url-Cy03LJLt-vkTPfQOh.js";import{_ as y}from"./tslib.es6-CNEFicEt-CmLYFWVC.js";import{x as h,e as d}from"./x25519-BzvT3haI-DcUk09rC.js";import{S as w}from"./Suite-B7Vy9AuU-D1ucdMDB.js";import"./_commonjs-dynamic-modules-COweQ1RR-BHR_E30J.js";
2
2
  /*!
3
3
  * Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
4
4
  */function v({bytes:t,expectedLength:e=32,code:r}){if(!(t instanceof Uint8Array))throw new TypeError('"bytes" must be a Uint8Array.');if(t.length!==e){const t=new Error(`"bytes" must be a ${e}-byte Uint8Array.`);throw t.name="DataError",r&&(t.code=r),t}}
5
- /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */const g=BigInt(0),m=BigInt(1),b=BigInt(2),x=BigInt(8),E=BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),K=Object.freeze({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),P:BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),l:E,n:E,h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960")}),T=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000"),A=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt("6853475219497561581579357271197624642482790079785650197046958215289687604742");const k=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),O=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),S=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),L=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");class P{constructor(t,e,r,n){this.x=t,this.y=e,this.z=r,this.t=n}static fromAffine(t){if(!(t instanceof R))throw new TypeError("ExtendedPoint#fromAffine: expected Point");return t.equals(R.ZERO)?P.ZERO:new P(t.x,t.y,m,Z(t.x*t.y))}static toAffineBatch(t){const e=function(t,e=K.P){const r=new Array(t.length),n=H(t.reduce(((t,n,i)=>n===g?t:(r[i]=t,Z(t*n,e))),m),e);return t.reduceRight(((t,n,i)=>n===g?t:(r[i]=Z(t*r[i],e),Z(t*n,e))),n),r}(t.map((t=>t.z)));return t.map(((t,r)=>t.toAffine(e[r])))}static normalizeZ(t){return this.toAffineBatch(t).map(this.fromAffine)}equals(t){_(t);const{x:e,y:r,z:n}=this,{x:i,y:o,z:a}=t,c=Z(e*a),s=Z(i*n),u=Z(r*a),f=Z(o*n);return c===s&&u===f}negate(){return new P(Z(-this.x),this.y,this.z,Z(-this.t))}double(){const{x:t,y:e,z:r}=this,{a:n}=K,i=Z(t*t),o=Z(e*e),a=Z(b*Z(r*r)),c=Z(n*i),s=t+e,u=Z(Z(s*s)-i-o),f=c+o,p=f-a,l=c-o,y=Z(u*p),h=Z(f*l),d=Z(u*l),w=Z(p*f);return new P(y,h,w,d)}add(t){_(t);const{x:e,y:r,z:n,t:i}=this,{x:o,y:a,z:c,t:s}=t,u=Z((r-e)*(a+o)),f=Z((r+e)*(a-o)),p=Z(f-u);if(p===g)return this.double();const l=Z(n*b*s),y=Z(i*b*c),h=y+l,d=f+u,w=y-l,v=Z(h*p),m=Z(d*w),x=Z(h*w),E=Z(p*d);return new P(v,m,E,x)}subtract(t){return this.add(t.negate())}precomputeWindow(t){const e=1+256/t,r=[];let n=this,i=n;for(let o=0;o<e;o++){i=n,r.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(n),r.push(i);n=i.double()}return r}wNAF(t,e){!e&&this.equals(P.BASE)&&(e=R.BASE);const r=e&&e._WINDOW_SIZE||1;if(256%r)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let n=e&&I.get(e);n||(n=this.precomputeWindow(r),e&&1!==r&&(n=P.normalizeZ(n),I.set(e,n)));let i=P.ZERO,o=P.BASE;const a=1+256/r,c=2**(r-1),s=BigInt(2**r-1),u=2**r,f=BigInt(r);for(let e=0;e<a;e++){const r=e*c;let a=Number(t&s);t>>=f,a>c&&(a-=u,t+=m);const p=r,l=r+Math.abs(a)-1,y=e%2!=0,h=a<0;0===a?o=o.add(B(y,n[p])):i=i.add(B(h,n[l]))}return P.normalizeZ([i,o])[0]}multiply(t,e){return this.wNAF(rt(t,K.l),e)}multiplyUnsafe(t){let e=rt(t,K.l,!1);const r=P.BASE,n=P.ZERO;if(e===g)return n;if(this.equals(n)||e===m)return this;if(this.equals(r))return this.wNAF(e);let i=n,o=this;for(;e>g;)e&m&&(i=i.add(o)),o=o.double(),e>>=m;return i}isSmallOrder(){return this.multiplyUnsafe(K.h).equals(P.ZERO)}isTorsionFree(){let t=this.multiplyUnsafe(K.l/b).double();return K.l%b&&(t=t.add(this)),t.equals(P.ZERO)}toAffine(t){const{x:e,y:r,z:n}=this,i=this.equals(P.ZERO);null==t&&(t=i?x:H(n));const o=Z(e*t),a=Z(r*t),c=Z(n*t);if(i)return R.ZERO;if(c!==m)throw new Error("invZ was invalid");return new R(o,a)}fromRistrettoBytes(){U()}toRistrettoBytes(){U()}fromRistrettoHash(){U()}}function B(t,e){const r=e.negate();return t?r:e}function _(t){if(!(t instanceof P))throw new TypeError("ExtendedPoint expected")}function M(t){if(!(t instanceof N))throw new TypeError("RistrettoPoint expected")}function U(){throw new Error("Legacy method: switch to RistrettoPoint")}P.BASE=new P(K.Gx,K.Gy,m,Z(K.Gx*K.Gy)),P.ZERO=new P(g,m,m,g);class N{constructor(t){this.ep=t}static calcElligatorRistrettoMap(t){const{d:e}=K,r=Z(A*t*t),n=Z((r+m)*S);let i=BigInt(-1);const o=Z((i-e*r)*Z(r+e));let{isValid:a,value:c}=Y(n,o),s=Z(c*t);z(s)||(s=Z(-s)),a||(c=s),a||(i=r);const u=Z(i*(r-m)*L-o),f=c*c,p=Z((c+c)*o),l=Z(u*k),y=Z(m-f),h=Z(m+f);return new P(Z(p*h),Z(y*l),Z(l*h),Z(p*y))}static hashToCurve(t){const e=q((t=et(t,64)).slice(0,32)),r=this.calcElligatorRistrettoMap(e),n=q(t.slice(32,64)),i=this.calcElligatorRistrettoMap(n);return new N(r.add(i))}static fromHex(t){t=et(t,32);const{a:e,d:r}=K,n="RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint",i=q(t);if(!function(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}(F(i),t)||z(i))throw new Error(n);const o=Z(i*i),a=Z(m+e*o),c=Z(m-e*o),s=Z(a*a),u=Z(c*c),f=Z(e*r*s-u),{isValid:p,value:l}=Q(Z(f*u)),y=Z(l*c),h=Z(l*y*f);let d=Z((i+i)*y);z(d)&&(d=Z(-d));const w=Z(a*h),v=Z(d*w);if(!p||z(v)||w===g)throw new Error(n);return new N(new P(d,w,m,v))}toRawBytes(){let{x:t,y:e,z:r,t:n}=this.ep;const i=Z(Z(r+e)*Z(r-e)),o=Z(t*e),a=Z(o*o),{value:c}=Q(Z(i*a)),s=Z(c*i),u=Z(c*o),f=Z(s*u*n);let p;if(z(n*f)){let r=Z(e*A),n=Z(t*A);t=r,e=n,p=Z(s*O)}else p=u;z(t*f)&&(e=Z(-e));let l=Z((r-e)*p);return z(l)&&(l=Z(-l)),F(l)}toHex(){return X(this.toRawBytes())}toString(){return this.toHex()}equals(t){M(t);const e=this.ep,r=t.ep,n=Z(e.x*r.y)===Z(e.y*r.x),i=Z(e.y*r.y)===Z(e.x*r.x);return n||i}add(t){return M(t),new N(this.ep.add(t.ep))}subtract(t){return M(t),new N(this.ep.subtract(t.ep))}multiply(t){return new N(this.ep.multiply(t))}multiplyUnsafe(t){return new N(this.ep.multiplyUnsafe(t))}}N.BASE=new N(P.BASE),N.ZERO=new N(P.ZERO);const I=new WeakMap;class R{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,I.delete(this)}static fromHex(t,e=!0){const{d:r,P:n}=K,i=(t=et(t,32)).slice();i[31]=-129&t[31];const o=W(i);if(e&&o>=n)throw new Error("Expected 0 < hex < P");if(!e&&o>=T)throw new Error("Expected 0 < hex < 2**256");const a=Z(o*o),c=Z(a-m),s=Z(r*a+m);let{isValid:u,value:f}=Y(c,s);if(!u)throw new Error("Point.fromHex: invalid y coordinate");const p=(f&m)===m;return 0!=(128&t[31])!==p&&(f=Z(-f)),new R(f,o)}static async fromPrivateKey(t){return(await it(t)).point}toRawBytes(){const t=F(this.y);return t[31]|=this.x&m?128:0,t}toHex(){return X(this.toRawBytes())}toX25519(){const{y:t}=this;return F(Z((m+t)*H(m-t)))}isTorsionFree(){return P.fromAffine(this).isTorsionFree()}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new R(Z(-this.x),this.y)}add(t){return P.fromAffine(this).add(P.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return P.fromAffine(this).multiply(t,this).toAffine()}}R.BASE=new R(K.Gx,K.Gy),R.ZERO=new R(g,m);class j{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromHex(t){const e=et(t,64),r=R.fromHex(e.slice(0,32),!1),n=W(e.slice(32,64));return new j(r,n)}assertValidity(){const{r:t,s:e}=this;if(!(t instanceof R))throw new Error("Expected Point instance");return rt(e,K.l,!1),this}toRawBytes(){const t=new Uint8Array(64);return t.set(this.r.toRawBytes()),t.set(F(this.s),32),t}toHex(){return X(this.toRawBytes())}}function C(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Expected Uint8Array list");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const i=t[e];r.set(i,n),n+=i.length}return r}const V=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function X(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=V[t[r]];return e}function D(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const e=new Uint8Array(t.length/2);for(let r=0;r<e.length;r++){const n=2*r,i=t.slice(n,n+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[r]=o}return e}function J(t){return D(t.toString(16).padStart(64,"0"))}function F(t){return J(t).reverse()}function z(t){return(Z(t)&m)===m}function W(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");return BigInt("0x"+X(Uint8Array.from(t).reverse()))}const G=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function q(t){return Z(W(t)&G)}function Z(t,e=K.P){const r=t%e;return r>=g?r:e+r}function H(t,e=K.P){if(t===g||e<=g)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=Z(t,e),n=e,i=g,o=m;for(;r!==g;){const t=n%r,e=i-o*(n/r);n=r,r=t,i=o,o=e}if(n!==m)throw new Error("invert: does not exist");return Z(i,e)}function $(t,e){const{P:r}=K;let n=t;for(;e-- >g;)n*=n,n%=r;return n}function Y(t,e){const r=Z(e*e*e),n=function(t){const{P:e}=K,r=BigInt(5),n=BigInt(10),i=BigInt(20),o=BigInt(40),a=BigInt(80),c=t*t%e*t%e,s=$(c,b)*c%e,u=$(s,m)*t%e,f=$(u,r)*u%e,p=$(f,n)*f%e,l=$(p,i)*p%e,y=$(l,o)*l%e,h=$(y,a)*y%e,d=$(h,a)*y%e,w=$(d,n)*f%e;return{pow_p_5_8:$(w,b)*t%e,b2:c}}(t*Z(r*r*e)).pow_p_5_8;let i=Z(t*r*n);const o=Z(e*i*i),a=i,c=Z(i*A),s=o===t,u=o===Z(-t),f=o===Z(-t*A);return s&&(i=a),(u||f)&&(i=c),z(i)&&(i=Z(-i)),{isValid:s||u,value:i}}function Q(t){return Y(m,t)}function tt(t){return Z(W(t),K.l)}function et(t,e){const r=t instanceof Uint8Array?Uint8Array.from(t):D(t);if("number"==typeof e&&r.length!==e)throw new Error(`Expected ${e} bytes`);return r}function rt(t,e,r=!0){if(!e)throw new TypeError("Specify max value");if("number"==typeof t&&Number.isSafeInteger(t)&&(t=BigInt(t)),"bigint"==typeof t&&t<e)if(r){if(g<t)return t}else if(g<=t)return t;throw new TypeError("Expected valid scalar: 0 < scalar < max")}let nt;async function it(t){return function(t){const e=((r=t.slice(0,32))[0]&=248,r[31]&=127,r[31]|=64,r);var r;const n=t.slice(32,64),i=tt(e),o=R.BASE.multiply(i),a=o.toRawBytes();return{head:e,prefix:n,scalar:i,point:o,pointBytes:a}}(await ct.sha512(function(t){if(32!==(t="bigint"==typeof t||"number"==typeof t?J(rt(t,T)):et(t)).length)throw new Error("Expected 32 bytes");return t}(t)))}async function ot(t,e,r){const{r:n,SB:i,msg:o,pub:a}=function(t,e,r){e=et(e),r instanceof R||(r=R.fromHex(r,!1));const{r:n,s:i}=t instanceof j?t.assertValidity():j.fromHex(t);return{r:n,s:i,SB:P.BASE.multiplyUnsafe(i),pub:r,msg:e}}(t,e,r),c=await ct.sha512(n.toRawBytes(),a.toRawBytes(),o);return function(t,e,r,n){const i=tt(n),o=P.fromAffine(t).multiplyUnsafe(i);return P.fromAffine(e).add(o).subtract(r).multiplyUnsafe(K.h).equals(P.ZERO)}(a,n,i,c)}R.BASE._setWindowSize(8);const at={node:i,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},ct={bytesToHex:X,hexToBytes:D,concatBytes:C,getExtendedPublicKey:it,mod:Z,invert:H,TORSION_SUBGROUP:["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"],hashToPrivateScalar:t=>{if((t=et(t)).length<40||t.length>1024)throw new Error("Expected 40-1024 bytes of private key as per FIPS 186");return Z(W(t),K.l-m)+m},randomBytes:(t=32)=>{if(at.web)return at.web.getRandomValues(new Uint8Array(t));if(at.node){const{randomBytes:e}=at.node;return new Uint8Array(e(t).buffer)}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>ct.randomBytes(32),sha512:async(...t)=>{const e=C(...t);if(at.web){const t=await at.web.subtle.digest("SHA-512",e.buffer);return new Uint8Array(t)}if(at.node)return Uint8Array.from(at.node.createHash("sha512").update(e).digest());throw new Error("The environment doesn't have sha512 function")},precompute(t=8,e=R.BASE){const r=e.equals(R.BASE)?e:new R(e.x,e.y);return r._setWindowSize(t),r.multiply(b),r},sha512Sync:void 0};Object.defineProperties(ct,{sha512Sync:{configurable:!1,get:()=>nt,set(t){nt||(nt=t)}}});
5
+ /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */const g=BigInt(0),m=BigInt(1),b=BigInt(2),E=BigInt(8),x=BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),K=Object.freeze({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),P:BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),l:x,n:x,h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960")}),T=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000"),A=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt("6853475219497561581579357271197624642482790079785650197046958215289687604742");const k=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),O=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),L=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),S=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");class P{constructor(t,e,r,n){this.x=t,this.y=e,this.z=r,this.t=n}static fromAffine(t){if(!(t instanceof R))throw new TypeError("ExtendedPoint#fromAffine: expected Point");return t.equals(R.ZERO)?P.ZERO:new P(t.x,t.y,m,Z(t.x*t.y))}static toAffineBatch(t){const e=function(t,e=K.P){const r=new Array(t.length),n=H(t.reduce(((t,n,i)=>n===g?t:(r[i]=t,Z(t*n,e))),m),e);return t.reduceRight(((t,n,i)=>n===g?t:(r[i]=Z(t*r[i],e),Z(t*n,e))),n),r}(t.map((t=>t.z)));return t.map(((t,r)=>t.toAffine(e[r])))}static normalizeZ(t){return this.toAffineBatch(t).map(this.fromAffine)}equals(t){_(t);const{x:e,y:r,z:n}=this,{x:i,y:o,z:a}=t,c=Z(e*a),s=Z(i*n),u=Z(r*a),f=Z(o*n);return c===s&&u===f}negate(){return new P(Z(-this.x),this.y,this.z,Z(-this.t))}double(){const{x:t,y:e,z:r}=this,{a:n}=K,i=Z(t*t),o=Z(e*e),a=Z(b*Z(r*r)),c=Z(n*i),s=t+e,u=Z(Z(s*s)-i-o),f=c+o,p=f-a,l=c-o,y=Z(u*p),h=Z(f*l),d=Z(u*l),w=Z(p*f);return new P(y,h,w,d)}add(t){_(t);const{x:e,y:r,z:n,t:i}=this,{x:o,y:a,z:c,t:s}=t,u=Z((r-e)*(a+o)),f=Z((r+e)*(a-o)),p=Z(f-u);if(p===g)return this.double();const l=Z(n*b*s),y=Z(i*b*c),h=y+l,d=f+u,w=y-l,v=Z(h*p),m=Z(d*w),E=Z(h*w),x=Z(p*d);return new P(v,m,x,E)}subtract(t){return this.add(t.negate())}precomputeWindow(t){const e=1+256/t,r=[];let n=this,i=n;for(let o=0;o<e;o++){i=n,r.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(n),r.push(i);n=i.double()}return r}wNAF(t,e){!e&&this.equals(P.BASE)&&(e=R.BASE);const r=e&&e._WINDOW_SIZE||1;if(256%r)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let n=e&&I.get(e);n||(n=this.precomputeWindow(r),e&&1!==r&&(n=P.normalizeZ(n),I.set(e,n)));let i=P.ZERO,o=P.BASE;const a=1+256/r,c=2**(r-1),s=BigInt(2**r-1),u=2**r,f=BigInt(r);for(let e=0;e<a;e++){const r=e*c;let a=Number(t&s);t>>=f,a>c&&(a-=u,t+=m);const p=r,l=r+Math.abs(a)-1,y=e%2!=0,h=a<0;0===a?o=o.add(B(y,n[p])):i=i.add(B(h,n[l]))}return P.normalizeZ([i,o])[0]}multiply(t,e){return this.wNAF(rt(t,K.l),e)}multiplyUnsafe(t){let e=rt(t,K.l,!1);const r=P.BASE,n=P.ZERO;if(e===g)return n;if(this.equals(n)||e===m)return this;if(this.equals(r))return this.wNAF(e);let i=n,o=this;for(;e>g;)e&m&&(i=i.add(o)),o=o.double(),e>>=m;return i}isSmallOrder(){return this.multiplyUnsafe(K.h).equals(P.ZERO)}isTorsionFree(){let t=this.multiplyUnsafe(K.l/b).double();return K.l%b&&(t=t.add(this)),t.equals(P.ZERO)}toAffine(t){const{x:e,y:r,z:n}=this,i=this.equals(P.ZERO);null==t&&(t=i?E:H(n));const o=Z(e*t),a=Z(r*t),c=Z(n*t);if(i)return R.ZERO;if(c!==m)throw new Error("invZ was invalid");return new R(o,a)}fromRistrettoBytes(){U()}toRistrettoBytes(){U()}fromRistrettoHash(){U()}}function B(t,e){const r=e.negate();return t?r:e}function _(t){if(!(t instanceof P))throw new TypeError("ExtendedPoint expected")}function M(t){if(!(t instanceof N))throw new TypeError("RistrettoPoint expected")}function U(){throw new Error("Legacy method: switch to RistrettoPoint")}P.BASE=new P(K.Gx,K.Gy,m,Z(K.Gx*K.Gy)),P.ZERO=new P(g,m,m,g);class N{constructor(t){this.ep=t}static calcElligatorRistrettoMap(t){const{d:e}=K,r=Z(A*t*t),n=Z((r+m)*L);let i=BigInt(-1);const o=Z((i-e*r)*Z(r+e));let{isValid:a,value:c}=Y(n,o),s=Z(c*t);F(s)||(s=Z(-s)),a||(c=s),a||(i=r);const u=Z(i*(r-m)*S-o),f=c*c,p=Z((c+c)*o),l=Z(u*k),y=Z(m-f),h=Z(m+f);return new P(Z(p*h),Z(y*l),Z(l*h),Z(p*y))}static hashToCurve(t){const e=q((t=et(t,64)).slice(0,32)),r=this.calcElligatorRistrettoMap(e),n=q(t.slice(32,64)),i=this.calcElligatorRistrettoMap(n);return new N(r.add(i))}static fromHex(t){t=et(t,32);const{a:e,d:r}=K,n="RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint",i=q(t);if(!function(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}(z(i),t)||F(i))throw new Error(n);const o=Z(i*i),a=Z(m+e*o),c=Z(m-e*o),s=Z(a*a),u=Z(c*c),f=Z(e*r*s-u),{isValid:p,value:l}=Q(Z(f*u)),y=Z(l*c),h=Z(l*y*f);let d=Z((i+i)*y);F(d)&&(d=Z(-d));const w=Z(a*h),v=Z(d*w);if(!p||F(v)||w===g)throw new Error(n);return new N(new P(d,w,m,v))}toRawBytes(){let{x:t,y:e,z:r,t:n}=this.ep;const i=Z(Z(r+e)*Z(r-e)),o=Z(t*e),a=Z(o*o),{value:c}=Q(Z(i*a)),s=Z(c*i),u=Z(c*o),f=Z(s*u*n);let p;if(F(n*f)){let r=Z(e*A),n=Z(t*A);t=r,e=n,p=Z(s*O)}else p=u;F(t*f)&&(e=Z(-e));let l=Z((r-e)*p);return F(l)&&(l=Z(-l)),z(l)}toHex(){return D(this.toRawBytes())}toString(){return this.toHex()}equals(t){M(t);const e=this.ep,r=t.ep,n=Z(e.x*r.y)===Z(e.y*r.x),i=Z(e.y*r.y)===Z(e.x*r.x);return n||i}add(t){return M(t),new N(this.ep.add(t.ep))}subtract(t){return M(t),new N(this.ep.subtract(t.ep))}multiply(t){return new N(this.ep.multiply(t))}multiplyUnsafe(t){return new N(this.ep.multiplyUnsafe(t))}}N.BASE=new N(P.BASE),N.ZERO=new N(P.ZERO);const I=new WeakMap;class R{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,I.delete(this)}static fromHex(t,e=!0){const{d:r,P:n}=K,i=(t=et(t,32)).slice();i[31]=-129&t[31];const o=W(i);if(e&&o>=n)throw new Error("Expected 0 < hex < P");if(!e&&o>=T)throw new Error("Expected 0 < hex < 2**256");const a=Z(o*o),c=Z(a-m),s=Z(r*a+m);let{isValid:u,value:f}=Y(c,s);if(!u)throw new Error("Point.fromHex: invalid y coordinate");const p=(f&m)===m;return 0!=(128&t[31])!==p&&(f=Z(-f)),new R(f,o)}static async fromPrivateKey(t){return(await it(t)).point}toRawBytes(){const t=z(this.y);return t[31]|=this.x&m?128:0,t}toHex(){return D(this.toRawBytes())}toX25519(){const{y:t}=this;return z(Z((m+t)*H(m-t)))}isTorsionFree(){return P.fromAffine(this).isTorsionFree()}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new R(Z(-this.x),this.y)}add(t){return P.fromAffine(this).add(P.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return P.fromAffine(this).multiply(t,this).toAffine()}}R.BASE=new R(K.Gx,K.Gy),R.ZERO=new R(g,m);class j{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromHex(t){const e=et(t,64),r=R.fromHex(e.slice(0,32),!1),n=W(e.slice(32,64));return new j(r,n)}assertValidity(){const{r:t,s:e}=this;if(!(t instanceof R))throw new Error("Expected Point instance");return rt(e,K.l,!1),this}toRawBytes(){const t=new Uint8Array(64);return t.set(this.r.toRawBytes()),t.set(z(this.s),32),t}toHex(){return D(this.toRawBytes())}}function C(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Expected Uint8Array list");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const i=t[e];r.set(i,n),n+=i.length}return r}const V=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function D(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=V[t[r]];return e}function J(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const e=new Uint8Array(t.length/2);for(let r=0;r<e.length;r++){const n=2*r,i=t.slice(n,n+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[r]=o}return e}function X(t){return J(t.toString(16).padStart(64,"0"))}function z(t){return X(t).reverse()}function F(t){return(Z(t)&m)===m}function W(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");return BigInt("0x"+D(Uint8Array.from(t).reverse()))}const G=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function q(t){return Z(W(t)&G)}function Z(t,e=K.P){const r=t%e;return r>=g?r:e+r}function H(t,e=K.P){if(t===g||e<=g)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=Z(t,e),n=e,i=g,o=m;for(;r!==g;){const t=n%r,e=i-o*(n/r);n=r,r=t,i=o,o=e}if(n!==m)throw new Error("invert: does not exist");return Z(i,e)}function $(t,e){const{P:r}=K;let n=t;for(;e-- >g;)n*=n,n%=r;return n}function Y(t,e){const r=Z(e*e*e),n=function(t){const{P:e}=K,r=BigInt(5),n=BigInt(10),i=BigInt(20),o=BigInt(40),a=BigInt(80),c=t*t%e*t%e,s=$(c,b)*c%e,u=$(s,m)*t%e,f=$(u,r)*u%e,p=$(f,n)*f%e,l=$(p,i)*p%e,y=$(l,o)*l%e,h=$(y,a)*y%e,d=$(h,a)*y%e,w=$(d,n)*f%e;return{pow_p_5_8:$(w,b)*t%e,b2:c}}(t*Z(r*r*e)).pow_p_5_8;let i=Z(t*r*n);const o=Z(e*i*i),a=i,c=Z(i*A),s=o===t,u=o===Z(-t),f=o===Z(-t*A);return s&&(i=a),(u||f)&&(i=c),F(i)&&(i=Z(-i)),{isValid:s||u,value:i}}function Q(t){return Y(m,t)}function tt(t){return Z(W(t),K.l)}function et(t,e){const r=t instanceof Uint8Array?Uint8Array.from(t):J(t);if("number"==typeof e&&r.length!==e)throw new Error(`Expected ${e} bytes`);return r}function rt(t,e,r=!0){if(!e)throw new TypeError("Specify max value");if("number"==typeof t&&Number.isSafeInteger(t)&&(t=BigInt(t)),"bigint"==typeof t&&t<e)if(r){if(g<t)return t}else if(g<=t)return t;throw new TypeError("Expected valid scalar: 0 < scalar < max")}let nt;async function it(t){return function(t){const e=((r=t.slice(0,32))[0]&=248,r[31]&=127,r[31]|=64,r);var r;const n=t.slice(32,64),i=tt(e),o=R.BASE.multiply(i),a=o.toRawBytes();return{head:e,prefix:n,scalar:i,point:o,pointBytes:a}}(await ct.sha512(function(t){if(32!==(t="bigint"==typeof t||"number"==typeof t?X(rt(t,T)):et(t)).length)throw new Error("Expected 32 bytes");return t}(t)))}async function ot(t,e,r){const{r:n,SB:i,msg:o,pub:a}=function(t,e,r){e=et(e),r instanceof R||(r=R.fromHex(r,!1));const{r:n,s:i}=t instanceof j?t.assertValidity():j.fromHex(t);return{r:n,s:i,SB:P.BASE.multiplyUnsafe(i),pub:r,msg:e}}(t,e,r),c=await ct.sha512(n.toRawBytes(),a.toRawBytes(),o);return function(t,e,r,n){const i=tt(n),o=P.fromAffine(t).multiplyUnsafe(i);return P.fromAffine(e).add(o).subtract(r).multiplyUnsafe(K.h).equals(P.ZERO)}(a,n,i,c)}R.BASE._setWindowSize(8);const at={node:i,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},ct={bytesToHex:D,hexToBytes:J,concatBytes:C,getExtendedPublicKey:it,mod:Z,invert:H,TORSION_SUBGROUP:["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"],hashToPrivateScalar:t=>{if((t=et(t)).length<40||t.length>1024)throw new Error("Expected 40-1024 bytes of private key as per FIPS 186");return Z(W(t),K.l-m)+m},randomBytes:(t=32)=>{if(at.web)return at.web.getRandomValues(new Uint8Array(t));if(at.node){const{randomBytes:e}=at.node;return new Uint8Array(e(t).buffer)}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>ct.randomBytes(32),sha512:async(...t)=>{const e=C(...t);if(at.web){const t=await at.web.subtle.digest("SHA-512",e.buffer);return new Uint8Array(t)}if(at.node)return Uint8Array.from(at.node.createHash("sha512").update(e).digest());throw new Error("The environment doesn't have sha512 function")},precompute(t=8,e=R.BASE){const r=e.equals(R.BASE)?e:new R(e.x,e.y);return r._setWindowSize(t),r.multiply(b),r},sha512Sync:void 0};Object.defineProperties(ct,{sha512Sync:{configurable:!1,get:()=>nt,set(t){nt||(nt=t)}}});
6
6
  /*!
7
7
  * Copyright (c) 2020-2022 Digital Bazaar, Inc. All rights reserved.
8
8
  */
@@ -13,7 +13,7 @@ const st=globalThis.crypto;if(!st.getRandomValues)throw new Error('Browser does
13
13
  /*!
14
14
  * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
15
15
  */
16
- const lt="Ed25519VerificationKey2020",yt=new Uint8Array([237,1]),ht=new Uint8Array([128,38]);class dt extends pt{constructor(t={}){super(t),this.type=lt;const{publicKeyMultibase:e,privateKeyMultibase:r}=t;if(!e)throw new TypeError('The "publicKeyMultibase" property is required.');if(!e||!wt(e,yt))throw new Error(`"publicKeyMultibase" has invalid header bytes: "${e}".`);if(r&&!wt(r,ht))throw new Error('"privateKeyMultibase" has invalid header bytes.');this.publicKeyMultibase=e,this.privateKeyMultibase=r,this.controller&&!this.id&&(this.id=`${this.controller}#${this.fingerprint()}`),v({bytes:this._publicKeyBuffer,code:"invalidPublicKeyLength",expectedLength:32})}static async from(t){return"Ed25519VerificationKey2018"===t.type?dt.fromEd25519VerificationKey2018(t):"JsonWebKey2020"===t.type?dt.fromJsonWebKey2020(t):new dt(t)}static fromEd25519VerificationKey2018({keyPair:t}={}){const e=vt(yt,u(t.publicKeyBase58)),r=new dt({id:t.id,controller:t.controller,publicKeyMultibase:e});return t.privateKeyBase58&&(r.privateKeyMultibase=vt(ht,u(t.privateKeyBase58))),r}static fromJsonWebKey2020({id:t,type:e,controller:r,publicKeyJwk:n}={}){if("JsonWebKey2020"!==e)throw new TypeError(`Invalid key type: "${e}".`);if(!n)throw new TypeError('"publicKeyJwk" property is required.');const{kty:i,crv:o}=n;if("OKP"!==i)throw new TypeError('"kty" is required to be "OKP".');if("Ed25519"!==o)throw new TypeError('"crv" is required to be "Ed25519".');const{x:a}=n,c=vt(yt,p(a));return dt.from({id:t,controller:r,publicKeyMultibase:c})}static async generate({seed:t,...e}={}){let r;r=t?await ut.generateKeyPairFromSeed(t):await ut.generateKeyPair();const n=vt(yt,r.publicKey),i=vt(ht,r.secretKey);return new dt({publicKeyMultibase:n,privateKeyMultibase:i,...e})}static fromFingerprint({fingerprint:t}={}){return new dt({publicKeyMultibase:t})}get _publicKeyBuffer(){if(!this.publicKeyMultibase)return;return u(this.publicKeyMultibase.substr(1)).slice(yt.length)}get _privateKeyBuffer(){if(!this.privateKeyMultibase)return;return u(this.privateKeyMultibase.substr(1)).slice(ht.length)}fingerprint(){return this.publicKeyMultibase}export({publicKey:t=!1,privateKey:e=!1,includeContext:r=!1}={}){if(!t&&!e)throw new TypeError('Export requires specifying either "publicKey" or "privateKey".');const n={id:this.id,type:this.type};return r&&(n["@context"]=dt.SUITE_CONTEXT),this.controller&&(n.controller=this.controller),t&&(n.publicKeyMultibase=this.publicKeyMultibase),e&&(n.privateKeyMultibase=this.privateKeyMultibase),this.revoked&&(n.revoked=this.revoked),n}toJwk({publicKey:t=!0,privateKey:e=!1}={}){if(!t&&!e)throw TypeError('Either a "publicKey" or a "privateKey" is required.');const r={crv:"Ed25519",kty:"OKP"};return t&&(r.x=l(this._publicKeyBuffer)),e&&(r.d=l(this._privateKeyBuffer)),r}async jwkThumbprint(){const t=`{"crv":"Ed25519","kty":"OKP","x":"${l(this._publicKeyBuffer)}"}`,e=(new TextEncoder).encode(t);return l(new Uint8Array(await ut.sha256digest({data:e})))}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:t}={}){if("string"!=typeof t||"z"!==t[0])return{error:new Error('"fingerprint" must be a multibase encoded string.'),valid:!1};let e;try{if(e=u(t.substr(1)),!e)throw new TypeError("Invalid encoding of fingerprint.")}catch(t){return{error:t,valid:!1}}const r=function(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}(this._publicKeyBuffer,e.slice(2)),n=e[0]===yt[0]&&e[1]===yt[1]&&r;return n?{valid:n}:{error:new Error("The fingerprint does not match the public key."),valid:!1}}signer(){const t=this._privateKeyBuffer;return{async sign({data:e}){if(!t)throw new Error("A private key is not available for signing.");return ut.sign(t,e)},id:this.id}}verifier(){const t=this._publicKeyBuffer;return{async verify({data:e,signature:r}){if(!t)throw new Error("A public key is not available for verifying.");return ut.verify(t,e,r)},id:this.id}}}function wt(t,e){if("string"!=typeof t||"z"!==t[0])return!1;const r=u(t.slice(1));return e.every(((t,e)=>r[e]===t))}function vt(t,e){const r=new Uint8Array(t.length+e.length);return r.set(t),r.set(e,t.length),"z"+f(r)}dt.suite=lt,dt.SUITE_CONTEXT="https://w3id.org/security/suites/ed25519-2020/v1";var gt,mt,bt,xt=(gt=function(t,e){!function(t,e){for(var r in e)t[r]=e[r]}(e,function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){
16
+ const lt="Ed25519VerificationKey2020",yt=new Uint8Array([237,1]),ht=new Uint8Array([128,38]);class dt extends pt{constructor(t={}){super(t),this.type=lt;const{publicKeyMultibase:e,privateKeyMultibase:r}=t;if(!e)throw new TypeError('The "publicKeyMultibase" property is required.');if(!e||!wt(e,yt))throw new Error(`"publicKeyMultibase" has invalid header bytes: "${e}".`);if(r&&!wt(r,ht))throw new Error('"privateKeyMultibase" has invalid header bytes.');this.publicKeyMultibase=e,this.privateKeyMultibase=r,this.controller&&!this.id&&(this.id=`${this.controller}#${this.fingerprint()}`),v({bytes:this._publicKeyBuffer,code:"invalidPublicKeyLength",expectedLength:32})}static async from(t){return"Ed25519VerificationKey2018"===t.type?dt.fromEd25519VerificationKey2018(t):"JsonWebKey2020"===t.type?dt.fromJsonWebKey2020(t):new dt(t)}static fromEd25519VerificationKey2018({keyPair:t}={}){const e=vt(yt,u(t.publicKeyBase58)),r=new dt({id:t.id,controller:t.controller,publicKeyMultibase:e});return t.privateKeyBase58&&(r.privateKeyMultibase=vt(ht,u(t.privateKeyBase58))),r}static fromJsonWebKey2020({id:t,type:e,controller:r,publicKeyJwk:n}={}){if("JsonWebKey2020"!==e)throw new TypeError(`Invalid key type: "${e}".`);if(!n)throw new TypeError('"publicKeyJwk" property is required.');const{kty:i,crv:o}=n;if("OKP"!==i)throw new TypeError('"kty" is required to be "OKP".');if("Ed25519"!==o)throw new TypeError('"crv" is required to be "Ed25519".');const{x:a}=n,c=vt(yt,p(a));return dt.from({id:t,controller:r,publicKeyMultibase:c})}static async generate({seed:t,...e}={}){let r;r=t?await ut.generateKeyPairFromSeed(t):await ut.generateKeyPair();const n=vt(yt,r.publicKey),i=vt(ht,r.secretKey);return new dt({publicKeyMultibase:n,privateKeyMultibase:i,...e})}static fromFingerprint({fingerprint:t}={}){return new dt({publicKeyMultibase:t})}get _publicKeyBuffer(){if(!this.publicKeyMultibase)return;return u(this.publicKeyMultibase.substr(1)).slice(yt.length)}get _privateKeyBuffer(){if(!this.privateKeyMultibase)return;return u(this.privateKeyMultibase.substr(1)).slice(ht.length)}fingerprint(){return this.publicKeyMultibase}export({publicKey:t=!1,privateKey:e=!1,includeContext:r=!1}={}){if(!t&&!e)throw new TypeError('Export requires specifying either "publicKey" or "privateKey".');const n={id:this.id,type:this.type};return r&&(n["@context"]=dt.SUITE_CONTEXT),this.controller&&(n.controller=this.controller),t&&(n.publicKeyMultibase=this.publicKeyMultibase),e&&(n.privateKeyMultibase=this.privateKeyMultibase),this.revoked&&(n.revoked=this.revoked),n}toJwk({publicKey:t=!0,privateKey:e=!1}={}){if(!t&&!e)throw TypeError('Either a "publicKey" or a "privateKey" is required.');const r={crv:"Ed25519",kty:"OKP"};return t&&(r.x=l(this._publicKeyBuffer)),e&&(r.d=l(this._privateKeyBuffer)),r}async jwkThumbprint(){const t=`{"crv":"Ed25519","kty":"OKP","x":"${l(this._publicKeyBuffer)}"}`,e=(new TextEncoder).encode(t);return l(new Uint8Array(await ut.sha256digest({data:e})))}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:t}={}){if("string"!=typeof t||"z"!==t[0])return{error:new Error('"fingerprint" must be a multibase encoded string.'),valid:!1};let e;try{if(e=u(t.substr(1)),!e)throw new TypeError("Invalid encoding of fingerprint.")}catch(t){return{error:t,valid:!1}}const r=function(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}(this._publicKeyBuffer,e.slice(2)),n=e[0]===yt[0]&&e[1]===yt[1]&&r;return n?{valid:n}:{error:new Error("The fingerprint does not match the public key."),valid:!1}}signer(){const t=this._privateKeyBuffer;return{async sign({data:e}){if(!t)throw new Error("A private key is not available for signing.");return ut.sign(t,e)},id:this.id}}verifier(){const t=this._publicKeyBuffer;return{async verify({data:e,signature:r}){if(!t)throw new Error("A public key is not available for verifying.");return ut.verify(t,e,r)},id:this.id}}}function wt(t,e){if("string"!=typeof t||"z"!==t[0])return!1;const r=u(t.slice(1));return e.every(((t,e)=>r[e]===t))}function vt(t,e){const r=new Uint8Array(t.length+e.length);return r.set(t),r.set(e,t.length),"z"+f(r)}dt.suite=lt,dt.SUITE_CONTEXT="https://w3id.org/security/suites/ed25519-2020/v1";var gt,mt,bt,Et=(gt=function(t,e){!function(t,e){for(var r in e)t[r]=e[r]}(e,function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){
17
17
  /*!
18
18
  * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
19
19
  */
@@ -29,7 +29,7 @@ const n=r(0),i=r(1),{documentLoader:o}=r(3),{CONTEXT_URL:a,CBORLD_CODEC_VALUE:c}
29
29
  /*!
30
30
  * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
31
31
  */
32
- const{CONTEXT_URL:n}=r(1),i=r(0);t.exports={documentLoader(t){if(t!==n)throw new Error(`Loading document "${t}" is not allowed.`);return{contextUrl:null,document:i,documentUrl:t}}}}]))},gt(mt={exports:{}},mt.exports),mt.exports),Et=(bt=xt)&&bt.__esModule&&Object.prototype.hasOwnProperty.call(bt,"default")?bt.default:bt;xt.contexts,xt.constants,xt.CONTEXT,xt.CONTEXT_URL,xt.appContextMap,xt.documentLoader;var Kt=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t,e){!function(t,e){for(var r in e)t[r]=e[r]}(e,function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){
32
+ const{CONTEXT_URL:n}=r(1),i=r(0);t.exports={documentLoader(t){if(t!==n)throw new Error(`Loading document "${t}" is not allowed.`);return{contextUrl:null,document:i,documentUrl:t}}}}]))},gt(mt={exports:{}},mt.exports),mt.exports),xt=(bt=Et)&&bt.__esModule&&Object.prototype.hasOwnProperty.call(bt,"default")?bt.default:bt;Et.contexts,Et.constants,Et.CONTEXT,Et.CONTEXT_URL,Et.appContextMap,Et.documentLoader;var Kt=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t,e){!function(t,e){for(var r in e)t[r]=e[r]}(e,function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){
33
33
  /*!
34
34
  * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
35
35
  */
@@ -49,4 +49,4 @@ const{CONTEXT_URL:n}=r(1),i=r(0);t.exports={documentLoader(t){if(t!==n)throw new
49
49
  /*!
50
50
  * Copyright (c) 2020-2021 Digital Bazaar, Inc. All rights reserved.
51
51
  */
52
- const{suites:{LinkedDataSignature:At}}=c,kt=Et.constants.CONTEXT_URL,Ot=Tt.constants.CONTEXT_URL;let St=class extends At{constructor({key:t,signer:e,verifier:r,proof:n,date:i,useNativeCanonize:o,canonizeOptions:a}={}){super({type:"Ed25519Signature2020",LDKeyClass:dt,contextUrl:kt,key:t,signer:e,verifier:r,proof:n,date:i,useNativeCanonize:o,canonizeOptions:a}),this.requiredKeyType="Ed25519VerificationKey2020"}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 r=await this.signer.sign({data:t});return e.proofValue="z"+f(r),e}async verifySignature({verifyData:t,verificationMethod:e,proof:r}){const{proofValue:n}=r;if(!n||"string"!=typeof n)throw new TypeError('The proof does not include a valid "proofValue" property.');if("z"!==n[0])throw new Error("Only base58btc multibase encoding is supported.");const i=u(n.substr(1));let{verifier:o}=this;if(!o){o=(await this.LDKeyClass.from(e)).verifier()}return o.verify({data:t,signature:i})}async assertVerificationMethod({verificationMethod:t}){let e;if("Ed25519VerificationKey2020"===t.type)e=kt;else{if("Ed25519VerificationKey2018"!==t.type)throw new Error(`Unsupported key type "${t.type}".`);e=Ot}if(!Lt({document:t,contextUrl:e}))throw new TypeError(`The verification method (key) must contain "${e}" context.`);if(void 0!==t.revoked)throw new Error("The verification method has been revoked.")}async getVerificationMethod({proof:t,documentLoader:e}){if(this.key)return this.key.export({publicKey:!0});let{verificationMethod:r}=t;if("object"==typeof r&&(r=r.id),!r)throw new Error('No "verificationMethod" found in proof.');const{document:n}=await e(r);return r="string"==typeof n?JSON.parse(n):n,await this.assertVerificationMethod({verificationMethod:r}),"Ed25519VerificationKey2018"===r.type&&(r=(await dt.fromEd25519VerificationKey2018({keyPair:r})).export({publicKey:!0,includeContext:!0})),r}async matchProof({proof:t,document:e,purpose:r,documentLoader:n}){if(!Lt({document:e,contextUrl:kt}))return!1;if(!await super.matchProof({proof:t,document:e,purpose:r,documentLoader:n}))return!1;if(!this.key)return!0;const{verificationMethod:i}=t;return"object"==typeof i?i.id===this.key.id:i===this.key.id}};function Lt({document:t,contextUrl:e}){const r=t["@context"];return r===e||Array.isArray(r)&&r.includes(e)}St.CONTEXT_URL=kt,St.CONTEXT=Et.contexts.get(kt);var Pt,Bt,_t={exports:{}},Mt={};_t.exports=(Pt||(Pt=1,Bt=Mt,Object.defineProperty(Bt,"__esModule",{value:!0}),Bt.staticImplements=function(){return function(t){}}),Mt);var Ut,Nt=_t.exports,It={exports:{}},Rt={};It.exports=(Ut||(Ut=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.staticImplements=function(){return function(t){}}}(Rt)),Rt);var jt=It.exports;function Ct(t,e,r,n,i,o,a){try{var c=t[o](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,i)}function Vt(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(t){Ct(o,n,i,a,c,"next",t)}function c(t){Ct(o,n,i,a,c,"throw",t)}a(void 0)}))}}function Xt(){return Xt=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},Xt.apply(this,arguments)}var Dt=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var i=e&&e.prototype instanceof w?e:w,o=Object.create(i.prototype),a=new S(n||[]);return o._invoke=function(t,e,r){var n=p;return function(i,o){if(n===y)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw o;return P()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=A(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=y;var s=f(t,e,r);if("normal"===s.type){if(n=r.done?h:l,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=h,r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var p="suspendedStart",l="suspendedYield",y="executing",h="completed",d={};function w(){}function v(){}function g(){}var m={};m[o]=function(){return this};var b=Object.getPrototypeOf,x=b&&b(b(L([])));x&&x!==r&&n.call(x,o)&&(m=x);var E=g.prototype=w.prototype=Object.create(m);function K(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function T(t,e){function r(i,o,a,c){var s=f(t[i],t,o);if("throw"!==s.type){var u=s.arg,p=u.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(p).then((function(t){u.value=t,a(u)}),(function(t){return r("throw",t,a,c)}))}c(s.arg)}var i;this._invoke=function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}}function A(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var i=f(n,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function L(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,a=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:P}}function P(){return{value:e,done:!0}}return v.prototype=E.constructor=g,g.constructor=v,v.displayName=s(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(E),t},t.awrap=function(t){return{__await:t}},K(T.prototype),T.prototype[a]=function(){return this},t.AsyncIterator=T,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new T(u(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},K(E),s(E,c,"Generator"),E[o]=function(){return this},E.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=L,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return c.type="throw",c.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;O(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function Jt(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r<e.length;r++)e[r]=255;for(var n=0;n<t.length;n++){var i=t.charAt(n),c=i.charCodeAt(0);if(255!==e[c])throw new TypeError(i+" is ambiguous");e[c]=n}var s=t.length,u=t.charAt(0),f=Math.log(s)/Math.log(256),p=Math.log(256)/Math.log(s);function l(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return o.alloc(0);var r=0;if(" "!==t[r]){for(var n=0,i=0;t[r]===u;)n++,r++;for(var a=(t.length-r)*f+1>>>0,c=new Uint8Array(a);t[r];){var p=e[t.charCodeAt(r)];if(255===p)return;for(var l=0,y=a-1;(0!==p||l<i)&&-1!==y;y--,l++)p+=s*c[y]>>>0,c[y]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");i=l,r++}if(" "!==t[r]){for(var h=a-i;h!==a&&0===c[h];)h++;var d=o.allocUnsafe(n+(a-h));d.fill(0,0,n);for(var w=n;h!==a;)d[w++]=c[h++];return d}}}return{encode:function(e){if((Array.isArray(e)||e instanceof Uint8Array)&&(e=o.from(e)),!a(e))throw new TypeError("Expected Buffer");if(0===e.length)return"";for(var r=0,n=0,i=0,c=e.length;i!==c&&0===e[i];)i++,r++;for(var f=(c-i)*p+1>>>0,l=new Uint8Array(f);i!==c;){for(var y=e[i],h=0,d=f-1;(0!==y||h<n)&&-1!==d;d--,h++)y+=256*l[d]>>>0,l[d]=y%s>>>0,y=y/s>>>0;if(0!==y)throw new Error("Non-zero carry");n=h,i++}for(var w=f-n;w!==f&&0===l[w];)w++;for(var v=u.repeat(r);w<f;++w)v+=t.charAt(l[w]);return v},decodeUnsafe:l,decode:function(t){var e=l(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}var Ft,zt=Jt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Wt=function(t){return o.from(t||"").toString("base64")},Gt=function(t){return Wt(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},qt=function(t,e){void 0===e&&(e="base58btc");var r=new Uint8Array(2+t.length);if(r[0]=236,r[1]=1,r.set(t,2),"base58btc"===e)return"z"+zt.encode(r);if("base64url"===e)return"u"+Gt(r);throw new Error("Unsupported encoding: "+e)},Zt=function(t){return Uint8Array.from(o.from(t.x,"base64"))},Ht={JsonWebKey2020:function(t){var e,r=Zt(t.publicKeyJwk),n=void 0;t.privateKeyJwk&&(n=(e=t.privateKeyJwk,{publicKey:Zt(e),privateKey:Uint8Array.from(o.from(e.d,"base64"))}).privateKey);return{publicKey:r,privateKey:n}},X25519KeyAgreementKey2019:function(t){var e=zt.decode(t.publicKeyBase58),r=void 0;return t.privateKeyBase58&&(r=Uint8Array.from(zt.decode(t.privateKeyBase58))),{publicKey:e,privateKey:r}}},$t={JsonWebKey2020:function(t,e,r,n){var i={kty:"OKP",crv:"X25519",x:Gt(r)},o={id:t,type:"JsonWebKey2020",controller:e,publicKeyJwk:i};return n&&(o.privateKeyJwk=Xt({},i,{d:Gt(n)})),o},X25519KeyAgreementKey2019:function(t,e,r,n){var i={id:t,type:"X25519KeyAgreementKey2019",controller:e,publicKeyBase58:zt.encode(r)};return n&&(i.privateKeyBase58=zt.encode(n)),i}},Yt=Ft=function(){function t(t){this.type="JsonWebKey2020",this.id=t.id,this.type=t.type||"JsonWebKey2020",this.controller=t.controller,this.publicKey=t.publicKey,this.privateKey=t.privateKey}t.fingerprintFromPublicKey=function(){var t=Vt(Dt.mark((function t(e){var r,n;return Dt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Ft.from(e);case 2:return r=t.sent,n=r.publicKey,t.abrupt("return",qt(n));case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.fromFingerprint=function(){var t=Vt(Dt.mark((function t(e){var r,n,i,o;return Dt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.fingerprint,236!==(n=zt.decode(r.substring(1)))[0]||1!==n[1]){t.next=12;break}return t.next=5,Ft.from({id:"",controller:"",type:"X25519KeyAgreementKey2019",publicKeyBase58:zt.encode(n.slice(2))});case 5:return i=t.sent,t.next=8,i.fingerprint();case 8:return o=t.sent,i.id="did:key:"+o+"#"+o,i.controller="did:key:"+o,t.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+r);case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();var e=t.prototype;return e.fingerprint=function(){var t=Vt(Dt.mark((function t(){return Dt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",qt(this.publicKey));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.export=function(){var t=Vt(Dt.mark((function t(e){return Dt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!$t[e.type]){t.next=3;break}return t.abrupt("return",$t[e.type](this.id,this.controller,this.publicKey,e.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(e));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.deriveSecret=function(){var t=Vt(Dt.mark((function t(e){var r,n,i;return Dt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.publicKey,t.next=3,Ft.from(r);case 3:if(n=t.sent,this.privateKey){t.next=6;break}throw new Error("No private key available for deriveSecret");case 6:return i=h.sharedKey(this.privateKey,n.publicKey,!0),t.abrupt("return",i);case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}();function Qt(t,e,r,n,i,o,a){try{var c=t[o](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,i)}function te(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(t){Qt(o,n,i,a,c,"next",t)}function c(t){Qt(o,n,i,a,c,"throw",t)}a(void 0)}))}}function ee(){return ee=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},ee.apply(this,arguments)}Yt.generate=function(){var t=Vt(Dt.mark((function t(e){var r,n,i,o,a;return Dt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.secureRandom,n=h.generateKeyPair({isAvailable:!0,randomBytes:r}),i=qt(n.publicKey),a=(o="did:key:"+i)+"#"+i,t.abrupt("return",new Ft({id:a,type:"JsonWebKey2020",controller:o,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Yt.from=function(){var t=Vt(Dt.mark((function t(e){var r,n,i;return Dt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=Ht[e.type](e),n=r.publicKey,i=r.privateKey,t.abrupt("return",new Ft({id:e.id,type:e.type,controller:e.controller,publicKey:n,privateKey:i}));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Yt=Ft=y([jt.staticImplements()],Yt);var re=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var i=e&&e.prototype instanceof w?e:w,o=Object.create(i.prototype),a=new S(n||[]);return o._invoke=function(t,e,r){var n=p;return function(i,o){if(n===y)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw o;return P()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=A(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=y;var s=f(t,e,r);if("normal"===s.type){if(n=r.done?h:l,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=h,r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var p="suspendedStart",l="suspendedYield",y="executing",h="completed",d={};function w(){}function v(){}function g(){}var m={};m[o]=function(){return this};var b=Object.getPrototypeOf,x=b&&b(b(L([])));x&&x!==r&&n.call(x,o)&&(m=x);var E=g.prototype=w.prototype=Object.create(m);function K(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function T(t,e){function r(i,o,a,c){var s=f(t[i],t,o);if("throw"!==s.type){var u=s.arg,p=u.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(p).then((function(t){u.value=t,a(u)}),(function(t){return r("throw",t,a,c)}))}c(s.arg)}var i;this._invoke=function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}}function A(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var i=f(n,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function L(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,a=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:P}}function P(){return{value:e,done:!0}}return v.prototype=E.constructor=g,g.constructor=v,v.displayName=s(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(E),t},t.awrap=function(t){return{__await:t}},K(T.prototype),T.prototype[a]=function(){return this},t.AsyncIterator=T,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new T(u(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},K(E),s(E,c,"Generator"),E[o]=function(){return this},E.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=L,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return c.type="throw",c.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;O(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function ne(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r<e.length;r++)e[r]=255;for(var n=0;n<t.length;n++){var i=t.charAt(n),c=i.charCodeAt(0);if(255!==e[c])throw new TypeError(i+" is ambiguous");e[c]=n}var s=t.length,u=t.charAt(0),f=Math.log(s)/Math.log(256),p=Math.log(256)/Math.log(s);function l(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return o.alloc(0);var r=0;if(" "!==t[r]){for(var n=0,i=0;t[r]===u;)n++,r++;for(var a=(t.length-r)*f+1>>>0,c=new Uint8Array(a);t[r];){var p=e[t.charCodeAt(r)];if(255===p)return;for(var l=0,y=a-1;(0!==p||l<i)&&-1!==y;y--,l++)p+=s*c[y]>>>0,c[y]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");i=l,r++}if(" "!==t[r]){for(var h=a-i;h!==a&&0===c[h];)h++;var d=o.allocUnsafe(n+(a-h));d.fill(0,0,n);for(var w=n;h!==a;)d[w++]=c[h++];return d}}}return{encode:function(e){if((Array.isArray(e)||e instanceof Uint8Array)&&(e=o.from(e)),!a(e))throw new TypeError("Expected Buffer");if(0===e.length)return"";for(var r=0,n=0,i=0,c=e.length;i!==c&&0===e[i];)i++,r++;for(var f=(c-i)*p+1>>>0,l=new Uint8Array(f);i!==c;){for(var y=e[i],h=0,d=f-1;(0!==y||h<n)&&-1!==d;d--,h++)y+=256*l[d]>>>0,l[d]=y%s>>>0,y=y/s>>>0;if(0!==y)throw new Error("Non-zero carry");n=h,i++}for(var w=f-n;w!==f&&0===l[w];)w++;for(var v=u.repeat(r);w<f;++w)v+=t.charAt(l[w]);return v},decodeUnsafe:l,decode:function(t){var e=l(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}var ie,oe=ne("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),ae=function(t){return o.from(t||"").toString("base64")},ce=function(t){return ae(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},se=function(t,e){void 0===e&&(e="base58btc");var r=new Uint8Array(2+t.length);if(r[0]=237,r[1]=1,r.set(t,2),"base58btc"===e)return"z"+oe.encode(r);if("base64url"===e)return"u"+ce(r);throw new Error("Unsupported encoding: "+e)},ue=function(t){return Uint8Array.from(o.from(t.x,"base64"))},fe={JsonWebKey2020:function(t){var e,r=ue(t.publicKeyJwk),n=void 0;t.privateKeyJwk&&(n=(e=t.privateKeyJwk,{publicKey:ue(e),privateKey:Uint8Array.from(o.concat([o.from(e.d,"base64"),o.from(e.x,"base64")]))}).privateKey);return{publicKey:r,privateKey:n}},Ed25519VerificationKey2018:function(t){var e=oe.decode(t.publicKeyBase58),r=void 0;return t.privateKeyBase58&&(r=Uint8Array.from(oe.decode(t.privateKeyBase58))),{publicKey:e,privateKey:r}}},pe=function(t){if(!fe[t.type])throw new Error("Cannot import from unsupported type: "+JSON.stringify(t,null,2));return fe[t.type](t)},le={JsonWebKey2020:function(t,e,r,n){var i={kty:"OKP",crv:"Ed25519",x:ce(r)},o={id:t,type:"JsonWebKey2020",controller:e,publicKeyJwk:i};return n&&(o.privateKeyJwk=ee({},i,{d:ce(n.slice(0,n.length/2))})),o},Ed25519VerificationKey2018:function(t,e,r,n){var i={id:t,type:"Ed25519VerificationKey2018",controller:e,publicKeyBase58:oe.encode(r)};return n&&(i.privateKeyBase58=oe.encode(n)),i}},ye={EdDsa:{__proto__:null,signer:function(t){return{sign:function(e){return te(re.mark((function r(){var n;return re.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.data,r.abrupt("return",d.sign(t,n));case 2:case"end":return r.stop()}}),r)})))()}}},verifier:function(t){return{verify:function(e){return te(re.mark((function r(){var n,i,o;return re.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:n=e.data,i=e.signature,o=!1;try{o=d.verify(t,n,i)}catch(t){}return r.abrupt("return",o);case 4:case"end":return r.stop()}}),r)})))()}}}}},he=ie=function(){function t(t){this.type="JsonWebKey2020",this.id=t.id,this.type=t.type||"JsonWebKey2020",this.controller=t.controller,this.publicKey=t.publicKey,this.privateKey=t.privateKey}t.fingerprintFromPublicKey=function(){var t=te(re.mark((function t(e){var r,n;return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,ie.from(e);case 2:return r=t.sent,n=r.publicKey,t.abrupt("return",se(n));case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.toX25519KeyPair=function(){var t=te(re.mark((function t(e){var r,n,i;return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=d.convertPublicKeyToX25519(e.publicKey),n=void 0,e.privateKey&&(n=d.convertSecretKeyToX25519(e.privateKey)),i=new Yt({id:"",type:"X25519KeyAgreementKey2019",controller:e.controller,publicKey:r,privateKey:n}),t.t0=e.controller+"#",t.next=7,i.fingerprint();case 7:return t.t1=t.sent,i.id=t.t0+t.t1,t.abrupt("return",i);case 10:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.fromFingerprint=function(){var t=te(re.mark((function t(e){var r,n,i,o;return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.fingerprint,237!==(n=oe.decode(r.substring(1)))[0]||1!==n[1]){t.next=12;break}return t.next=5,ie.from({id:"",controller:"",type:"Ed25519VerificationKey2018",publicKeyBase58:oe.encode(n.slice(2))});case 5:return i=t.sent,t.next=8,i.fingerprint();case 8:return o=t.sent,i.id="did:key:"+o+"#"+o,i.controller="did:key:"+o,t.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+r);case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();var e=t.prototype;return e.fingerprint=function(){var t=te(re.mark((function t(){return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",se(this.publicKey));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.export=function(){var t=te(re.mark((function t(e){return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!le[e.type]){t.next=3;break}return t.abrupt("return",le[e.type](this.id,this.controller,this.publicKey,e.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(e));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.signer=function(t){if(void 0===t&&(t="EdDsa"),!this.privateKey)throw new Error("No private key to sign with.");if(ye[t])return ye[t].signer(this.privateKey);throw new Error("Unsupported suite type "+t)},e.verifier=function(t){if(void 0===t&&(t="EdDsa"),!this.publicKey)throw new Error("No public key to verify with.");if(ye[t])return ye[t].verifier(this.publicKey);throw new Error("Unsupported suite type "+t)},e.getDerivedKeyPairs=function(){var t=te(re.mark((function t(){return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=this,t.next=3,ie.toX25519KeyPair(this);case 3:return t.t1=t.sent,t.abrupt("return",[t.t0,t.t1]);case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),t}();he.generate=function(){var t=te(re.mark((function t(e){var r,n,i,o,a;return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.secureRandom,n=d.generateKeyPair({isAvailable:!0,randomBytes:r}),i=se(n.publicKey),a=(o="did:key:"+i)+"#"+i,t.abrupt("return",new ie({id:a,type:"JsonWebKey2020",controller:o,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),he.from=function(){var t=te(re.mark((function t(e){var r,n,i;return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=pe(e),n=r.publicKey,i=r.privateKey,t.abrupt("return",new ie({id:e.id,type:e.type,controller:e.controller,publicKey:n,privateKey:i}));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),he=ie=y([Nt.staticImplements()],he);const{purposes:{AssertionProofPurpose:de}}=c;var we;!function(t){t.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",t.checkDocumentSignature="checkDocumentSignature"}(we||(we={}));class ve extends w{verificationProcess=[we.retrieveVerificationMethodPublicKey,we.checkDocumentSignature];documentToVerify;issuer;proof;type="Ed25519Signature2020";verificationKey;publicKey;constructor(t){super(t),t.executeStep&&(this.executeStep=t.executeStep),this.documentToVerify=t.document,this.issuer=t.issuer,this.proof=t.proof,this.validateProofType()}async init(){}async verifyProof(){for(const t of this.verificationProcess){if(!this[t])return void console.error("verification logic for",t,"not implemented");await this[t]()}}async verifyIdentity(){}getProofVerificationSteps(e){return this.verificationProcess.map((r=>t.verifier.convertToVerificationSubsteps(e,r)))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return this.publicKey}getIssuerName(){return this.issuer.name??""}getIssuerProfileDomain(){try{return new URL(this.getIssuerProfileUrl()).hostname??""}catch(t){return""}}getIssuerProfileUrl(){return this.issuer.id??""}getSigningDate(){return this.proof.created}async executeStep(t,e,r){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}async publicKeyJwkToString(t){return await he.fingerprintFromPublicKey(t)}validateProofType(){const t=this.isProofChain()?this.proof.chainedProofType:this.proof.type;if(t!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${t}`)}isProofChain(){return"ChainedProof2021"===this.proof.type}generateDocumentLoader(){e[this.documentToVerify.issuer]=this.issuer.didDocument;return function(t){return t in e?{contextUrl:null,document:e[t],documentUrl:t}:s.documentLoader(t)}}retrieveInitialDocument(){const t=r(this.documentToVerify);if(Array.isArray(t.proof)){const e=t.proof.find((t=>t.type===this.type));delete t.proof,t.proof=e}return t}async retrieveVerificationMethodPublicKey(){this.verificationKey=await this.executeStep(we.retrieveVerificationMethodPublicKey,(async()=>{const t=this.issuer.didDocument.verificationMethod.find((t=>t.id===this.proof.verificationMethod));if(!t)throw new n(we.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.");try{this.publicKey=t.publicKeyMultibase??await this.publicKeyJwkToString(t)}catch(t){console.error("ERROR retrieving Ed25519Signature2020 public key",t)}const e=await dt.from({...t});if(!e)throw new n(we.retrieveVerificationMethodPublicKey,"Could not derive the verification key");if(e.revoked)throw new n(we.retrieveVerificationMethodPublicKey,"The verification key has been revoked");return e}),this.type)}async checkDocumentSignature(){await this.executeStep(we.checkDocumentSignature,(async()=>{const t=new St({key:this.verificationKey});t.date=new Date(Date.now()).toISOString();const e=await c.verify(this.retrieveInitialDocument(),{suite:t,purpose:new de,documentLoader:this.generateDocumentLoader()});if(!e.verified)throw console.error(JSON.stringify(e,null,2)),new n(we.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed`);console.log("Credential Ed25519 signature successfully verified")}),this.type)}}export{ve as default};
52
+ const{suites:{LinkedDataSignature:At}}=c,kt=xt.constants.CONTEXT_URL,Ot=Tt.constants.CONTEXT_URL;let Lt=class extends At{constructor({key:t,signer:e,verifier:r,proof:n,date:i,useNativeCanonize:o,canonizeOptions:a}={}){super({type:"Ed25519Signature2020",LDKeyClass:dt,contextUrl:kt,key:t,signer:e,verifier:r,proof:n,date:i,useNativeCanonize:o,canonizeOptions:a}),this.requiredKeyType="Ed25519VerificationKey2020"}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 r=await this.signer.sign({data:t});return e.proofValue="z"+f(r),e}async verifySignature({verifyData:t,verificationMethod:e,proof:r}){const{proofValue:n}=r;if(!n||"string"!=typeof n)throw new TypeError('The proof does not include a valid "proofValue" property.');if("z"!==n[0])throw new Error("Only base58btc multibase encoding is supported.");const i=u(n.substr(1));let{verifier:o}=this;if(!o){o=(await this.LDKeyClass.from(e)).verifier()}return o.verify({data:t,signature:i})}async assertVerificationMethod({verificationMethod:t}){let e;if("Ed25519VerificationKey2020"===t.type)e=kt;else{if("Ed25519VerificationKey2018"!==t.type)throw new Error(`Unsupported key type "${t.type}".`);e=Ot}if(!St({document:t,contextUrl:e}))throw new TypeError(`The verification method (key) must contain "${e}" context.`);if(void 0!==t.revoked)throw new Error("The verification method has been revoked.")}async getVerificationMethod({proof:t,documentLoader:e}){if(this.key)return this.key.export({publicKey:!0});let{verificationMethod:r}=t;if("object"==typeof r&&(r=r.id),!r)throw new Error('No "verificationMethod" found in proof.');const{document:n}=await e(r);return r="string"==typeof n?JSON.parse(n):n,await this.assertVerificationMethod({verificationMethod:r}),"Ed25519VerificationKey2018"===r.type&&(r=(await dt.fromEd25519VerificationKey2018({keyPair:r})).export({publicKey:!0,includeContext:!0})),r}async matchProof({proof:t,document:e,purpose:r,documentLoader:n}){if(!St({document:e,contextUrl:kt}))return!1;if(!await super.matchProof({proof:t,document:e,purpose:r,documentLoader:n}))return!1;if(!this.key)return!0;const{verificationMethod:i}=t;return"object"==typeof i?i.id===this.key.id:i===this.key.id}};function St({document:t,contextUrl:e}){const r=t["@context"];return r===e||Array.isArray(r)&&r.includes(e)}Lt.CONTEXT_URL=kt,Lt.CONTEXT=xt.contexts.get(kt);var Pt,Bt,_t={exports:{}},Mt={};_t.exports=(Pt||(Pt=1,Bt=Mt,Object.defineProperty(Bt,"__esModule",{value:!0}),Bt.staticImplements=function(){return function(t){}}),Mt);var Ut,Nt=_t.exports,It={exports:{}},Rt={};It.exports=(Ut||(Ut=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.staticImplements=function(){return function(t){}}}(Rt)),Rt);var jt=It.exports;function Ct(t,e,r,n,i,o,a){try{var c=t[o](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,i)}function Vt(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(t){Ct(o,n,i,a,c,"next",t)}function c(t){Ct(o,n,i,a,c,"throw",t)}a(void 0)}))}}function Dt(){return Dt=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},Dt.apply(this,arguments)}var Jt=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var i=e&&e.prototype instanceof w?e:w,o=Object.create(i.prototype),a=new L(n||[]);return o._invoke=function(t,e,r){var n=p;return function(i,o){if(n===y)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw o;return P()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=A(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=y;var s=f(t,e,r);if("normal"===s.type){if(n=r.done?h:l,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=h,r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var p="suspendedStart",l="suspendedYield",y="executing",h="completed",d={};function w(){}function v(){}function g(){}var m={};m[o]=function(){return this};var b=Object.getPrototypeOf,E=b&&b(b(S([])));E&&E!==r&&n.call(E,o)&&(m=E);var x=g.prototype=w.prototype=Object.create(m);function K(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function T(t,e){function r(i,o,a,c){var s=f(t[i],t,o);if("throw"!==s.type){var u=s.arg,p=u.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(p).then((function(t){u.value=t,a(u)}),(function(t){return r("throw",t,a,c)}))}c(s.arg)}var i;this._invoke=function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}}function A(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var i=f(n,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function S(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,a=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:P}}function P(){return{value:e,done:!0}}return v.prototype=x.constructor=g,g.constructor=v,v.displayName=s(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(x),t},t.awrap=function(t){return{__await:t}},K(T.prototype),T.prototype[a]=function(){return this},t.AsyncIterator=T,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new T(u(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},K(x),s(x,c,"Generator"),x[o]=function(){return this},x.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=S,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return c.type="throw",c.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;O(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:S(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function Xt(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r<e.length;r++)e[r]=255;for(var n=0;n<t.length;n++){var i=t.charAt(n),c=i.charCodeAt(0);if(255!==e[c])throw new TypeError(i+" is ambiguous");e[c]=n}var s=t.length,u=t.charAt(0),f=Math.log(s)/Math.log(256),p=Math.log(256)/Math.log(s);function l(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return o.alloc(0);var r=0;if(" "!==t[r]){for(var n=0,i=0;t[r]===u;)n++,r++;for(var a=(t.length-r)*f+1>>>0,c=new Uint8Array(a);t[r];){var p=e[t.charCodeAt(r)];if(255===p)return;for(var l=0,y=a-1;(0!==p||l<i)&&-1!==y;y--,l++)p+=s*c[y]>>>0,c[y]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");i=l,r++}if(" "!==t[r]){for(var h=a-i;h!==a&&0===c[h];)h++;var d=o.allocUnsafe(n+(a-h));d.fill(0,0,n);for(var w=n;h!==a;)d[w++]=c[h++];return d}}}return{encode:function(e){if((Array.isArray(e)||e instanceof Uint8Array)&&(e=o.from(e)),!a(e))throw new TypeError("Expected Buffer");if(0===e.length)return"";for(var r=0,n=0,i=0,c=e.length;i!==c&&0===e[i];)i++,r++;for(var f=(c-i)*p+1>>>0,l=new Uint8Array(f);i!==c;){for(var y=e[i],h=0,d=f-1;(0!==y||h<n)&&-1!==d;d--,h++)y+=256*l[d]>>>0,l[d]=y%s>>>0,y=y/s>>>0;if(0!==y)throw new Error("Non-zero carry");n=h,i++}for(var w=f-n;w!==f&&0===l[w];)w++;for(var v=u.repeat(r);w<f;++w)v+=t.charAt(l[w]);return v},decodeUnsafe:l,decode:function(t){var e=l(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}var zt,Ft=Xt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Wt=function(t){return o.from(t||"").toString("base64")},Gt=function(t){return Wt(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},qt=function(t,e){void 0===e&&(e="base58btc");var r=new Uint8Array(2+t.length);if(r[0]=236,r[1]=1,r.set(t,2),"base58btc"===e)return"z"+Ft.encode(r);if("base64url"===e)return"u"+Gt(r);throw new Error("Unsupported encoding: "+e)},Zt=function(t){return Uint8Array.from(o.from(t.x,"base64"))},Ht={JsonWebKey2020:function(t){var e,r=Zt(t.publicKeyJwk),n=void 0;t.privateKeyJwk&&(n=(e=t.privateKeyJwk,{publicKey:Zt(e),privateKey:Uint8Array.from(o.from(e.d,"base64"))}).privateKey);return{publicKey:r,privateKey:n}},X25519KeyAgreementKey2019:function(t){var e=Ft.decode(t.publicKeyBase58),r=void 0;return t.privateKeyBase58&&(r=Uint8Array.from(Ft.decode(t.privateKeyBase58))),{publicKey:e,privateKey:r}}},$t={JsonWebKey2020:function(t,e,r,n){var i={kty:"OKP",crv:"X25519",x:Gt(r)},o={id:t,type:"JsonWebKey2020",controller:e,publicKeyJwk:i};return n&&(o.privateKeyJwk=Dt({},i,{d:Gt(n)})),o},X25519KeyAgreementKey2019:function(t,e,r,n){var i={id:t,type:"X25519KeyAgreementKey2019",controller:e,publicKeyBase58:Ft.encode(r)};return n&&(i.privateKeyBase58=Ft.encode(n)),i}},Yt=zt=function(){function t(t){this.type="JsonWebKey2020",this.id=t.id,this.type=t.type||"JsonWebKey2020",this.controller=t.controller,this.publicKey=t.publicKey,this.privateKey=t.privateKey}t.fingerprintFromPublicKey=function(){var t=Vt(Jt.mark((function t(e){var r,n;return Jt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,zt.from(e);case 2:return r=t.sent,n=r.publicKey,t.abrupt("return",qt(n));case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.fromFingerprint=function(){var t=Vt(Jt.mark((function t(e){var r,n,i,o;return Jt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.fingerprint,236!==(n=Ft.decode(r.substring(1)))[0]||1!==n[1]){t.next=12;break}return t.next=5,zt.from({id:"",controller:"",type:"X25519KeyAgreementKey2019",publicKeyBase58:Ft.encode(n.slice(2))});case 5:return i=t.sent,t.next=8,i.fingerprint();case 8:return o=t.sent,i.id="did:key:"+o+"#"+o,i.controller="did:key:"+o,t.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+r);case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();var e=t.prototype;return e.fingerprint=function(){var t=Vt(Jt.mark((function t(){return Jt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",qt(this.publicKey));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.export=function(){var t=Vt(Jt.mark((function t(e){return Jt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!$t[e.type]){t.next=3;break}return t.abrupt("return",$t[e.type](this.id,this.controller,this.publicKey,e.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(e));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.deriveSecret=function(){var t=Vt(Jt.mark((function t(e){var r,n,i;return Jt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.publicKey,t.next=3,zt.from(r);case 3:if(n=t.sent,this.privateKey){t.next=6;break}throw new Error("No private key available for deriveSecret");case 6:return i=h.sharedKey(this.privateKey,n.publicKey,!0),t.abrupt("return",i);case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}();function Qt(t,e,r,n,i,o,a){try{var c=t[o](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,i)}function te(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(t){Qt(o,n,i,a,c,"next",t)}function c(t){Qt(o,n,i,a,c,"throw",t)}a(void 0)}))}}function ee(){return ee=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},ee.apply(this,arguments)}Yt.generate=function(){var t=Vt(Jt.mark((function t(e){var r,n,i,o,a;return Jt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.secureRandom,n=h.generateKeyPair({isAvailable:!0,randomBytes:r}),i=qt(n.publicKey),a=(o="did:key:"+i)+"#"+i,t.abrupt("return",new zt({id:a,type:"JsonWebKey2020",controller:o,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Yt.from=function(){var t=Vt(Jt.mark((function t(e){var r,n,i;return Jt.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=Ht[e.type](e),n=r.publicKey,i=r.privateKey,t.abrupt("return",new zt({id:e.id,type:e.type,controller:e.controller,publicKey:n,privateKey:i}));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Yt=zt=y([jt.staticImplements()],Yt);var re=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var i=e&&e.prototype instanceof w?e:w,o=Object.create(i.prototype),a=new L(n||[]);return o._invoke=function(t,e,r){var n=p;return function(i,o){if(n===y)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw o;return P()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=A(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=y;var s=f(t,e,r);if("normal"===s.type){if(n=r.done?h:l,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=h,r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var p="suspendedStart",l="suspendedYield",y="executing",h="completed",d={};function w(){}function v(){}function g(){}var m={};m[o]=function(){return this};var b=Object.getPrototypeOf,E=b&&b(b(S([])));E&&E!==r&&n.call(E,o)&&(m=E);var x=g.prototype=w.prototype=Object.create(m);function K(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function T(t,e){function r(i,o,a,c){var s=f(t[i],t,o);if("throw"!==s.type){var u=s.arg,p=u.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(p).then((function(t){u.value=t,a(u)}),(function(t){return r("throw",t,a,c)}))}c(s.arg)}var i;this._invoke=function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}}function A(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var i=f(n,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function S(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,a=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:P}}function P(){return{value:e,done:!0}}return v.prototype=x.constructor=g,g.constructor=v,v.displayName=s(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(x),t},t.awrap=function(t){return{__await:t}},K(T.prototype),T.prototype[a]=function(){return this},t.AsyncIterator=T,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new T(u(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},K(x),s(x,c,"Generator"),x[o]=function(){return this},x.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=S,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return c.type="throw",c.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;O(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:S(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function ne(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r<e.length;r++)e[r]=255;for(var n=0;n<t.length;n++){var i=t.charAt(n),c=i.charCodeAt(0);if(255!==e[c])throw new TypeError(i+" is ambiguous");e[c]=n}var s=t.length,u=t.charAt(0),f=Math.log(s)/Math.log(256),p=Math.log(256)/Math.log(s);function l(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return o.alloc(0);var r=0;if(" "!==t[r]){for(var n=0,i=0;t[r]===u;)n++,r++;for(var a=(t.length-r)*f+1>>>0,c=new Uint8Array(a);t[r];){var p=e[t.charCodeAt(r)];if(255===p)return;for(var l=0,y=a-1;(0!==p||l<i)&&-1!==y;y--,l++)p+=s*c[y]>>>0,c[y]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");i=l,r++}if(" "!==t[r]){for(var h=a-i;h!==a&&0===c[h];)h++;var d=o.allocUnsafe(n+(a-h));d.fill(0,0,n);for(var w=n;h!==a;)d[w++]=c[h++];return d}}}return{encode:function(e){if((Array.isArray(e)||e instanceof Uint8Array)&&(e=o.from(e)),!a(e))throw new TypeError("Expected Buffer");if(0===e.length)return"";for(var r=0,n=0,i=0,c=e.length;i!==c&&0===e[i];)i++,r++;for(var f=(c-i)*p+1>>>0,l=new Uint8Array(f);i!==c;){for(var y=e[i],h=0,d=f-1;(0!==y||h<n)&&-1!==d;d--,h++)y+=256*l[d]>>>0,l[d]=y%s>>>0,y=y/s>>>0;if(0!==y)throw new Error("Non-zero carry");n=h,i++}for(var w=f-n;w!==f&&0===l[w];)w++;for(var v=u.repeat(r);w<f;++w)v+=t.charAt(l[w]);return v},decodeUnsafe:l,decode:function(t){var e=l(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}var ie,oe=ne("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),ae=function(t){return o.from(t||"").toString("base64")},ce=function(t){return ae(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},se=function(t,e){void 0===e&&(e="base58btc");var r=new Uint8Array(2+t.length);if(r[0]=237,r[1]=1,r.set(t,2),"base58btc"===e)return"z"+oe.encode(r);if("base64url"===e)return"u"+ce(r);throw new Error("Unsupported encoding: "+e)},ue=function(t){return Uint8Array.from(o.from(t.x,"base64"))},fe={JsonWebKey2020:function(t){var e,r=ue(t.publicKeyJwk),n=void 0;t.privateKeyJwk&&(n=(e=t.privateKeyJwk,{publicKey:ue(e),privateKey:Uint8Array.from(o.concat([o.from(e.d,"base64"),o.from(e.x,"base64")]))}).privateKey);return{publicKey:r,privateKey:n}},Ed25519VerificationKey2018:function(t){var e=oe.decode(t.publicKeyBase58),r=void 0;return t.privateKeyBase58&&(r=Uint8Array.from(oe.decode(t.privateKeyBase58))),{publicKey:e,privateKey:r}}},pe=function(t){if(!fe[t.type])throw new Error("Cannot import from unsupported type: "+JSON.stringify(t,null,2));return fe[t.type](t)},le={JsonWebKey2020:function(t,e,r,n){var i={kty:"OKP",crv:"Ed25519",x:ce(r)},o={id:t,type:"JsonWebKey2020",controller:e,publicKeyJwk:i};return n&&(o.privateKeyJwk=ee({},i,{d:ce(n.slice(0,n.length/2))})),o},Ed25519VerificationKey2018:function(t,e,r,n){var i={id:t,type:"Ed25519VerificationKey2018",controller:e,publicKeyBase58:oe.encode(r)};return n&&(i.privateKeyBase58=oe.encode(n)),i}},ye={EdDsa:{__proto__:null,signer:function(t){return{sign:function(e){return te(re.mark((function r(){var n;return re.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.data,r.abrupt("return",d.sign(t,n));case 2:case"end":return r.stop()}}),r)})))()}}},verifier:function(t){return{verify:function(e){return te(re.mark((function r(){var n,i,o;return re.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:n=e.data,i=e.signature,o=!1;try{o=d.verify(t,n,i)}catch(t){}return r.abrupt("return",o);case 4:case"end":return r.stop()}}),r)})))()}}}}},he=ie=function(){function t(t){this.type="JsonWebKey2020",this.id=t.id,this.type=t.type||"JsonWebKey2020",this.controller=t.controller,this.publicKey=t.publicKey,this.privateKey=t.privateKey}t.fingerprintFromPublicKey=function(){var t=te(re.mark((function t(e){var r,n;return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,ie.from(e);case 2:return r=t.sent,n=r.publicKey,t.abrupt("return",se(n));case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.toX25519KeyPair=function(){var t=te(re.mark((function t(e){var r,n,i;return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=d.convertPublicKeyToX25519(e.publicKey),n=void 0,e.privateKey&&(n=d.convertSecretKeyToX25519(e.privateKey)),i=new Yt({id:"",type:"X25519KeyAgreementKey2019",controller:e.controller,publicKey:r,privateKey:n}),t.t0=e.controller+"#",t.next=7,i.fingerprint();case 7:return t.t1=t.sent,i.id=t.t0+t.t1,t.abrupt("return",i);case 10:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.fromFingerprint=function(){var t=te(re.mark((function t(e){var r,n,i,o;return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.fingerprint,237!==(n=oe.decode(r.substring(1)))[0]||1!==n[1]){t.next=12;break}return t.next=5,ie.from({id:"",controller:"",type:"Ed25519VerificationKey2018",publicKeyBase58:oe.encode(n.slice(2))});case 5:return i=t.sent,t.next=8,i.fingerprint();case 8:return o=t.sent,i.id="did:key:"+o+"#"+o,i.controller="did:key:"+o,t.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+r);case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();var e=t.prototype;return e.fingerprint=function(){var t=te(re.mark((function t(){return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",se(this.publicKey));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.export=function(){var t=te(re.mark((function t(e){return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!le[e.type]){t.next=3;break}return t.abrupt("return",le[e.type](this.id,this.controller,this.publicKey,e.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(e));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.signer=function(t){if(void 0===t&&(t="EdDsa"),!this.privateKey)throw new Error("No private key to sign with.");if(ye[t])return ye[t].signer(this.privateKey);throw new Error("Unsupported suite type "+t)},e.verifier=function(t){if(void 0===t&&(t="EdDsa"),!this.publicKey)throw new Error("No public key to verify with.");if(ye[t])return ye[t].verifier(this.publicKey);throw new Error("Unsupported suite type "+t)},e.getDerivedKeyPairs=function(){var t=te(re.mark((function t(){return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=this,t.next=3,ie.toX25519KeyPair(this);case 3:return t.t1=t.sent,t.abrupt("return",[t.t0,t.t1]);case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),t}();he.generate=function(){var t=te(re.mark((function t(e){var r,n,i,o,a;return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.secureRandom,n=d.generateKeyPair({isAvailable:!0,randomBytes:r}),i=se(n.publicKey),a=(o="did:key:"+i)+"#"+i,t.abrupt("return",new ie({id:a,type:"JsonWebKey2020",controller:o,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),he.from=function(){var t=te(re.mark((function t(e){var r,n,i;return re.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=pe(e),n=r.publicKey,i=r.privateKey,t.abrupt("return",new ie({id:e.id,type:e.type,controller:e.controller,publicKey:n,privateKey:i}));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),he=ie=y([Nt.staticImplements()],he);const{purposes:{AssertionProofPurpose:de}}=c;var we;!function(t){t.retrieveVerificationMethodPublicKey="retrieveVerificationMethodPublicKey",t.checkDocumentSignature="checkDocumentSignature"}(we||(we={}));class ve extends w{verificationProcess=[we.retrieveVerificationMethodPublicKey,we.checkDocumentSignature];documentToVerify;issuer;proof;type="Ed25519Signature2020";verificationKey;publicKey;constructor(t){super(t),t.executeStep&&(this.executeStep=t.executeStep),this.documentToVerify=t.document,this.issuer=t.issuer,this.proof=t.proof,this.validateProofType()}async init(){}async verifyProof(){for(const t of this.verificationProcess){if(!this[t])return void console.error("verification logic for",t,"not implemented");await this[t]()}}async verifyIdentity(){}getProofVerificationSteps(e){return this.verificationProcess.map((r=>t.verifier.convertToVerificationSubsteps(e,r)))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return this.publicKey}getIssuerName(){return this.issuer.name??""}getIssuerProfileDomain(){try{return new URL(this.getIssuerProfileUrl()).hostname??""}catch(t){return""}}getIssuerProfileUrl(){return this.issuer.id??""}getSigningDate(){return this.proof.created}async executeStep(t,e,r){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}async publicKeyJwkToString(t){return await he.fingerprintFromPublicKey(t)}validateProofType(){const t=this.isProofChain()?this.proof.chainedProofType:this.proof.type;if(t!==this.type)throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${t}`)}isProofChain(){return"ChainedProof2021"===this.proof.type}generateDocumentLoader(){e[this.documentToVerify.issuer]=this.issuer.didDocument;return function(t){return t in e?{contextUrl:null,document:e[t],documentUrl:t}:s.documentLoader(t)}}retrieveInitialDocument(){const t=r(this.documentToVerify);if(Array.isArray(t.proof)){const e=t.proof.find((t=>t.type===this.type));delete t.proof,t.proof=e}return t}async retrieveVerificationMethodPublicKey(){this.verificationKey=await this.executeStep(we.retrieveVerificationMethodPublicKey,(async()=>{const t=this.issuer.didDocument.verificationMethod.find((t=>t.id===this.proof.verificationMethod));if(!t)throw new n(we.retrieveVerificationMethodPublicKey,"The verification method of the document does not match the provided issuer.");try{this.publicKey=t.publicKeyMultibase??await this.publicKeyJwkToString(t)}catch(t){console.error("ERROR retrieving Ed25519Signature2020 public key",t)}const e=await dt.from({...t});if(!e)throw new n(we.retrieveVerificationMethodPublicKey,"Could not derive the verification key");if(e.revoked)throw new n(we.retrieveVerificationMethodPublicKey,"The verification key has been revoked");return e}),this.type)}async checkDocumentSignature(){await this.executeStep(we.checkDocumentSignature,(async()=>{const t=new Lt({key:this.verificationKey});t.date=new Date(Date.now()).toISOString();const e=await c.verify(this.retrieveInitialDocument(),{suite:t,purpose:new de,documentLoader:this.generateDocumentLoader()});if(!e.verified)throw console.error(JSON.stringify(e,null,2)),new n(we.checkDocumentSignature,`The document's ${this.type} signature could not be confirmed`);console.log("Credential Ed25519 signature successfully verified")}),this.type)}}export{ve as default};