@substrate-system/keys 0.2.44 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,4 +1,4 @@
1
- var rr=Object.defineProperty;var _t=(t,e,r)=>e in t?rr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var s=(t,e)=>rr(t,"name",{value:e,configurable:!0});var S=(t,e)=>{for(var r in e)rr(t,r,{get:e[r],enumerable:!0})};var c=(t,e,r)=>_t(t,typeof e!="symbol"?e+"":e,r);var Yr=(n=>(n[n.B1024=1024]="B1024",n[n.B2048=2048]="B2048",n[n.B4096=4096]="B4096",n))(Yr||{}),$r=(n=>(n[n.B128=128]="B128",n[n.B192=192]="B192",n[n.B256=256]="B256",n))($r||{}),Jr=(r=>(r.ECC="ecc",r.RSA="rsa",r))(Jr||{}),tr=(i=>(i.SHA_1="SHA-1",i.SHA_256="SHA-256",i.SHA_384="SHA-384",i.SHA_512="SHA-512",i))(tr||{}),nr=(i=>(i.P_256="P-256",i.P_384="P-384",i.P_521="P-521",i.X25519="X25519",i))(nr||{}),te=(n=>(n.Sign="signing",n.Exchange="exchange",n.Write="write",n))(te||{}),ir=(r=>(r[r.B8=8]="B8",r[r.B16=16]="B16",r))(ir||{});var Dt={};S(Dt,{AES_GCM:()=>z,BASE58_DID_PREFIX:()=>V,BLS_DID_PREFIX:()=>Xe,DEFAULT_CHAR_SIZE:()=>O,DEFAULT_ECC_EXCHANGE:()=>Lr,DEFAULT_ECC_EXCHANGE_CURVE:()=>Gn,DEFAULT_ECC_WRITE:()=>Mr,DEFAULT_HASH_ALGORITHM:()=>se,DEFAULT_RSA_EXCHANGE:()=>Nr,DEFAULT_RSA_SIZE:()=>We,DEFAULT_RSA_WRITE:()=>kr,DEFAULT_SYMM_ALGORITHM:()=>D,DEFAULT_SYMM_LENGTH:()=>H,ECC_EXCHANGE_ALGORITHM:()=>Ie,ECC_WRITE_ALGORITHM:()=>ie,EDWARDS_DID_PREFIX:()=>Ye,IV_LENGTH:()=>P,KEY_TYPE:()=>_e,KEY_USE:()=>Kt,RSA_ALGORITHM:()=>J,RSA_DID_PREFIX:()=>je,RSA_HASHING_ALGORITHM:()=>Ve,RSA_SIGN_ALGORITHM:()=>q,RsaKeys:()=>ce,SALT_LENGTH:()=>E,X25519_PUBLIC_KEY_LENGTH:()=>$,encrypt:()=>yi,encryptKeyTo:()=>Ue,encryptTo:()=>Tt,getPublicKeyAsArrayBuffer:()=>Q,getPublicKeyAsUint8Array:()=>zr,publicKeyToDid:()=>Me,verify:()=>ai});function Ce(t=0){return new Uint8Array(t)}s(Ce,"allocUnsafe");function sr(t,e){e==null&&(e=t.reduce((i,o)=>i+o.length,0));let r=Ce(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return r}s(sr,"concat");var gr={};S(gr,{base10:()=>zt});var Ti=new Uint8Array(0);function qr(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}s(qr,"equals");function G(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}s(G,"coerce");function Zr(t){return new TextEncoder().encode(t)}s(Zr,"fromString");function Qr(t){return new TextDecoder().decode(t)}s(Qr,"toString");function kt(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),a=o.charCodeAt(0);if(r[a]!==255)throw new TypeError(o+" is ambiguous");r[a]=i}var y=t.length,p=t.charAt(0),g=Math.log(y)/Math.log(256),l=Math.log(256)/Math.log(y);function b(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var m=0,T=0,C=0,_=u.length;C!==_&&u[C]===0;)C++,m++;for(var U=(_-C)*l+1>>>0,N=new Uint8Array(U);C!==_;){for(var M=u[C],X=0,L=U-1;(M!==0||X<T)&&L!==-1;L--,X++)M+=256*N[L]>>>0,N[L]=M%y>>>0,M=M/y>>>0;if(M!==0)throw new Error("Non-zero carry");T=X,C++}for(var F=U-T;F!==U&&N[F]===0;)F++;for(var ze=p.repeat(m);F<U;++F)ze+=t.charAt(N[F]);return ze}s(b,"encode");function v(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var m=0;if(u[m]!==" "){for(var T=0,C=0;u[m]===p;)T++,m++;for(var _=(u.length-m)*g+1>>>0,U=new Uint8Array(_);u[m];){var N=r[u.charCodeAt(m)];if(N===255)return;for(var M=0,X=_-1;(N!==0||M<C)&&X!==-1;X--,M++)N+=y*U[X]>>>0,U[X]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");C=M,m++}if(u[m]!==" "){for(var L=_-C;L!==_&&U[L]===0;)L++;for(var F=new Uint8Array(T+(_-L)),ze=T;L!==_;)F[ze++]=U[L++];return F}}}s(v,"decodeUnsafe");function fe(u){var m=v(u);if(m)return m;throw new Error(`Non-${e} character`)}return s(fe,"decode"),{encode:b,decodeUnsafe:v,decode:fe}}s(kt,"base");var Lt=kt,Mt=Lt,rt=Mt;var pr=class pr{constructor(e,r,n){c(this,"name");c(this,"prefix");c(this,"baseEncode");this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}};s(pr,"Encoder");var or=pr,ur=class ur{constructor(e,r,n){c(this,"name");c(this,"prefix");c(this,"baseDecode");c(this,"prefixCodePoint");this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return tt(this,e)}};s(ur,"Decoder");var ar=ur,fr=class fr{constructor(e){c(this,"decoders");this.decoders=e}or(e){return tt(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};s(fr,"ComposedDecoder");var yr=fr;function tt(t,e){return new yr({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}s(tt,"or");var lr=class lr{constructor(e,r,n,i){c(this,"name");c(this,"prefix");c(this,"baseEncode");c(this,"baseDecode");c(this,"encoder");c(this,"decoder");this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new or(e,r,n),this.decoder=new ar(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};s(lr,"Codec");var cr=lr;function le({name:t,prefix:e,encode:r,decode:n}){return new cr(t,e,r,n)}s(le,"from");function Y({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=rt(r,t);return le({prefix:e,name:t,encode:n,decode:s(o=>G(i(o)),"decode")})}s(Y,"baseX");function Rt(t,e,r,n){let i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let o=t.length;for(;t[o-1]==="=";)--o;let a=new Uint8Array(o*r/8|0),y=0,p=0,g=0;for(let l=0;l<o;++l){let b=i[t[l]];if(b===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<r|b,y+=r,y>=8&&(y-=8,a[g++]=255&p>>y)}if(y>=r||(255&p<<8-y)!==0)throw new SyntaxError("Unexpected end of data");return a}s(Rt,"decode");function Ot(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",a=0,y=0;for(let p=0;p<t.length;++p)for(y=y<<8|t[p],a+=8;a>r;)a-=r,o+=e[i&y>>a];if(a!==0&&(o+=e[i&y<<r-a]),n)for(;(o.length*r&7)!==0;)o+="=";return o}s(Ot,"encode");function h({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return le({prefix:e,name:t,encode(i){return Ot(i,n,r)},decode(i){return Rt(i,n,r,t)}})}s(h,"rfc4648");var zt=Y({prefix:"9",name:"base10",alphabet:"0123456789"});var mr={};S(mr,{base16:()=>Ht,base16upper:()=>Ft});var Ht=h({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ft=h({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var dr={};S(dr,{base2:()=>Gt});var Gt=h({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var hr={};S(hr,{base256emoji:()=>Yt});var nt=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Vt=nt.reduce((t,e,r)=>(t[r]=e,t),[]),jt=nt.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Wt(t){return t.reduce((e,r)=>(e+=Vt[r],e),"")}s(Wt,"encode");function Xt(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=jt[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}s(Xt,"decode");var Yt=le({prefix:"\u{1F680}",name:"base256emoji",encode:Wt,decode:Xt});var Ar={};S(Ar,{base32:()=>ge,base32hex:()=>Zt,base32hexpad:()=>en,base32hexpadupper:()=>rn,base32hexupper:()=>Qt,base32pad:()=>Jt,base32padupper:()=>qt,base32upper:()=>$t,base32z:()=>tn});var ge=h({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$t=h({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Jt=h({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),qt=h({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zt=h({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qt=h({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),en=h({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),rn=h({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),tn=h({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kr={};S(Kr,{base36:()=>Pe,base36upper:()=>nn});var Pe=Y({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nn=Y({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var br={};S(br,{base58btc:()=>R,base58flickr:()=>sn});var R=Y({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sn=Y({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wr={};S(wr,{base64:()=>on,base64pad:()=>an,base64url:()=>yn,base64urlpad:()=>cn});var on=h({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),an=h({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yn=h({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cn=h({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xr={};S(xr,{base8:()=>pn});var pn=h({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ur={};S(Ur,{identity:()=>un});var un=le({prefix:"\0",name:"identity",encode:s(t=>Qr(t),"encode"),decode:s(t=>Zr(t),"decode")});var qi=new TextEncoder,Zi=new TextDecoder;var Cr={};S(Cr,{identity:()=>Nn});var gn=ot,it=128,mn=127,dn=~mn,hn=Math.pow(2,31);function ot(t,e,r){e=e||[],r=r||0;for(var n=r;t>=hn;)e[r++]=t&255|it,t/=128;for(;t&dn;)e[r++]=t&255|it,t>>>=7;return e[r]=t|0,ot.bytes=r-n+1,e}s(ot,"encode");var An=Er,Kn=128,st=127;function Er(t,n){var r=0,n=n||0,i=0,o=n,a,y=t.length;do{if(o>=y)throw Er.bytes=0,new RangeError("Could not decode varint");a=t[o++],r+=i<28?(a&st)<<i:(a&st)*Math.pow(2,i),i+=7}while(a>=Kn);return Er.bytes=o-n,r}s(Er,"read");var bn=Math.pow(2,7),wn=Math.pow(2,14),xn=Math.pow(2,21),Un=Math.pow(2,28),En=Math.pow(2,35),Sn=Math.pow(2,42),Cn=Math.pow(2,49),Pn=Math.pow(2,56),Bn=Math.pow(2,63),vn=s(function(t){return t<bn?1:t<wn?2:t<xn?3:t<Un?4:t<En?5:t<Sn?6:t<Cn?7:t<Pn?8:t<Bn?9:10},"length"),Tn={encode:gn,decode:An,encodingLength:vn},Dn=Tn,Be=Dn;function ve(t,e=0){return[Be.decode(t,e),Be.decode.bytes]}s(ve,"decode");function me(t,e,r=0){return Be.encode(t,e,r),e}s(me,"encodeTo");function de(t){return Be.encodingLength(t)}s(de,"encodingLength");function ne(t,e){let r=e.byteLength,n=de(t),i=n+de(r),o=new Uint8Array(i+r);return me(t,o,0),me(r,o,n),o.set(e,i),new he(t,r,e,o)}s(ne,"create");function at(t){let e=G(t),[r,n]=ve(e),[i,o]=ve(e.subarray(n)),a=e.subarray(n+o);if(a.byteLength!==i)throw new Error("Incorrect length");return new he(r,i,a,e)}s(at,"decode");function yt(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&qr(t.bytes,r.bytes)}}s(yt,"equals");var Sr=class Sr{constructor(e,r,n,i){c(this,"code");c(this,"size");c(this,"digest");c(this,"bytes");this.code=e,this.size=r,this.digest=n,this.bytes=i}};s(Sr,"Digest");var he=Sr;var ct=0,In="identity",pt=G;function _n(t){return ne(ct,pt(t))}s(_n,"digest");var Nn={code:ct,name:In,encode:pt,digest:_n};var Tr={};S(Tr,{sha256:()=>kn,sha512:()=>Ln});function Br({name:t,code:e,encode:r}){return new Pr(t,e,r)}s(Br,"from");var vr=class vr{constructor(e,r,n){c(this,"name");c(this,"code");c(this,"encode");this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?ne(this.code,r):r.then(n=>ne(this.code,n))}else throw Error("Unknown type, must be binary type")}};s(vr,"Hasher");var Pr=vr;function ft(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}s(ft,"sha");var kn=Br({name:"sha2-256",code:18,encode:ft("SHA-256")}),Ln=Br({name:"sha2-512",code:19,encode:ft("SHA-512")});function lt(t,e){let{bytes:r,version:n}=t;return n===0?Rn(r,Dr(t),e??R.encoder):On(r,Dr(t),e??ge.encoder)}s(lt,"format");var gt=new WeakMap;function Dr(t){let e=gt.get(t);if(e==null){let r=new Map;return gt.set(t,r),r}return e}s(Dr,"baseCache");var dt,w=class w{constructor(e,r,n,i){c(this,"code");c(this,"version");c(this,"multihash");c(this,"bytes");c(this,"/");c(this,dt,"CID");this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==De)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==zn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return w.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=ne(e,r);return w.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return w.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&yt(e.multihash,n.multihash)}toString(e){return lt(this,e)}toJSON(){return{"/":lt(this)}}link(){return this}[(dt=Symbol.toStringTag,Symbol.for("nodejs.util.inspect.custom"))](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof w)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:a}=r;return new w(n,i,o,a??mt(n,i,o.bytes))}else if(r[Hn]===!0){let{version:n,multihash:i,code:o}=r,a=at(i);return w.create(n,o,a)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==De)throw new Error(`Version 0 CID must use dag-pb (code: ${De}) block encoding`);return new w(e,r,n,n.bytes)}case 1:{let i=mt(e,r,n.bytes);return new w(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return w.create(0,De,e)}static createV1(e,r){return w.create(1,e,r)}static decode(e){let[r,n]=w.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=w.inspectBytes(e),n=r.size-r.multihashSize,i=G(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),a=new he(r.multihashCode,r.digestSize,o,i);return[r.version===0?w.createV0(a):w.createV1(r.codec,a),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=s(()=>{let[b,v]=ve(e.subarray(r));return r+=v,b},"next"),i=n(),o=De;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let a=r,y=n(),p=n(),g=r+p,l=g-a;return{version:i,codec:o,multihashCode:y,digestSize:p,multihashSize:l,size:g}}static parse(e,r){let[n,i]=Mn(e,r),o=w.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Dr(o).set(n,e),o}};s(w,"CID");var Fe=w;function Mn(t,e){switch(t[0]){case"Q":{let r=e??R;return[R.prefix,r.decode(`${R.prefix}${t}`)]}case R.prefix:{let r=e??R;return[R.prefix,r.decode(t)]}case ge.prefix:{let r=e??ge;return[ge.prefix,r.decode(t)]}case Pe.prefix:{let r=e??Pe;return[Pe.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}s(Mn,"parseCIDtoBytes");function Rn(t,e,r){let{prefix:n}=r;if(n!==R.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}s(Rn,"toStringV0");function On(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}s(On,"toStringV1");var De=112,zn=18;function mt(t,e,r){let n=de(t),i=n+de(e),o=new Uint8Array(i+r.byteLength);return me(t,o,0),me(e,o,n),o.set(r,i),o}s(mt,"encodeCID");var Hn=Symbol.for("@ipld/js-cid/CID");var Ir={...Ur,...dr,...xr,...gr,...mr,...Ar,...Kr,...br,...wr,...hr},vs={...Tr,...Cr};function At(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}s(At,"createCodec");var ht=At("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),_r=At("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ce(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Fn={utf8:ht,"utf-8":ht,hex:Ir.base16,latin1:_r,ascii:_r,binary:_r,...Ir},Ge=Fn;function A(t,e="utf8"){let r=Ge[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}s(A,"fromString");function f(t,e="utf8"){let r=Ge[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}s(f,"toString");var Ct={};S(Ct,{AES:()=>K,decryptBytes:()=>St,importAesKey:()=>be});var V="did:key:z",ie="Ed25519",Ie="X25519",Gn="X25519",$=32,Kt={sign:["sign","verify"],encrypt:["deriveKey","deriveBits"]},J="RSA-OAEP",q="RSASSA-PKCS1-v1_5",Ve="SHA-256",je=new Uint8Array([0,245,2]),We=2048,se="SHA-256",O=8,z="AES-GCM",D=z,H=256,P=12,Xe=new Uint8Array([234,1]),Ye=new Uint8Array([237,1]),_e={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"},Nr="rsa-exchange-key",kr="rsa-write-key",Lr="ecc-exchange",Mr="ecc-write",E=16;var Ne=globalThis.crypto,bt=new Error("Invalid key use. Please use 'encryption' or 'signing"),Vn=new Error("Max must be less than 256 and greater than 0");function d(t){return new Uint8Array(t).buffer}s(d,"toArrayBuffer");async function wt(t){return new Uint8Array(await Ne.subtle.digest("sha-256",t.buffer))}s(wt,"sha256");function I(t){let e=A(t,"base64pad");return d(e)}s(I,"base64ToArrBuf");var oe=s((t,e)=>{if(typeof t=="string")return e(t);if(typeof t=="object"&&t.byteLength!==void 0)return new Uint8Array(t).buffer;throw new Error("Improper value. Must be a string, ArrayBuffer, Uint8Array")},"normalizeToBuf");function $e(t){return oe(t,I)}s($e,"normalizeBase64ToBuf");var jn=s(t=>oe(t,e=>xt(e,8)),"normalizeUtf8ToBuf");function xt(t,e){let r=e===8?new Uint8Array(t.length):new Uint16Array(t.length);for(let n=0,i=t.length;n<i;n++)r[n]=t.charCodeAt(n);return r.buffer}s(xt,"strToArrBuf");var Wn=s(t=>oe(t,e=>xt(e,16)),"normalizeUtf16ToBuf");function Z(t,e){return e===8?jn(t):Wn(t)}s(Z,"normalizeUnicodeToBuf");function Je(t){if(!t.startsWith(V))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+t.substring(V.length),r=A(e,"base58btc"),{keyBuffer:n,type:i}=Xn(d(r));return{publicKey:new Uint8Array(n),type:i}}s(Je,"didToPublicKey");function Xn(t){if(Ae(t,d(je)))return{keyBuffer:t.slice(je.byteLength),type:_e.RSA};if(Ae(t,d(Ye)))return{keyBuffer:t.slice(Ye.byteLength),type:_e.Edwards};if(Ae(t,d(Xe)))return{keyBuffer:t.slice(Xe.byteLength),type:_e.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}s(Xn,"parseMagicBytes");var Yn={equal:s((t,e)=>{let r=new Uint8Array(t),n=new Uint8Array(e);if(r.length!==n.length)return!1;for(let i=0;i<r.length;i++)if(r[i]!==n[i])return!1;return!0},"equal")};function Ae(t,e){return Yn.equal(e,t.slice(0,e.byteLength))}s(Ae,"hasPrefix");function x(t){return f(t instanceof ArrayBuffer?new Uint8Array(t):t,"base64pad")}s(x,"toBase64");async function ke(t,e){let r=typeof t=="string"?I(t):d(t);return Ne.subtle.importKey("raw",r,{name:e?.alg||D,length:e?.length||H},!0,["encrypt","decrypt"])}s(ke,"importKey");function qe(t,{max:e}={max:255}){if(e<1||e>255)throw Vn;let r=new Uint8Array(t);if(e===255)return Ne.getRandomValues(r),r.buffer;let n=0,i=e+1,o=Math.floor(256/i)*i,a=new Uint8Array(1);for(;n<r.length;)Ne.getRandomValues(a),a[0]<o&&(r[n]=a[0]%i,n++);return r.buffer}s(qe,"randomBuf");function j(t,e){let r=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(d(t)),n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(d(e)),i=new Uint8Array(r.length+n.length);return i.set(r),i.set(n,r.length),i.buffer}s(j,"joinBufs");async function Rr(t,e,r,n=!1){let i=n;if(!Object.values(te).includes(r))throw new Error("invalid key use");let o=r==="exchange"?J:q,a=r==="exchange"?["encrypt","decrypt"]:["sign","verify"];return Ne.subtle.generateKey({name:o,modulusLength:t,publicExponent:$n(),hash:{name:e}},i,a)}s(Rr,"makeRSAKeypair");function $n(){return new Uint8Array([1,0,1])}s($n,"publicExponent");var k=globalThis.crypto,Ze={keyTypes:{"bls12-381":{magicBytes:new Uint8Array([234,1]),verify:s(()=>{throw new Error("Not implemented")},"verify")},rsa:{magicBytes:new Uint8Array([0,245,2]),verify:Et},ed25519:{magicBytes:new Uint8Array([237,1]),verify:Ut}}};async function yo({message:t,did:e,signature:r}){let n=Jn(e),i=Qe(e).publicKey;if(n==="ed25519")return Ut({message:t,publicKey:i,signature:r});if(n==="rsa")return Et({message:t,publicKey:i,signature:r});throw new Error("Unknown key format")}s(yo,"verify");function Jn(t){try{let{type:e}=Qe(t);return e}catch{return"unknown"}}s(Jn,"getAlgorithm");async function Ut({message:t,publicKey:e,signature:r}){let n=t;typeof t=="string"&&(n=A(t,"utf8"));let i=r;typeof r=="string"&&(i=A(r,"base64pad"));let o=e;if(typeof e=="string"&&(o=Qe(e).publicKey),o.length!==32)throw new Error(`Invalid Ed25519 public key size: ${o.length} bytes, expected 32`);if(i.length!==64)throw new Error(`Invalid Ed25519 signature size: ${i.length} bytes, expected 64`);let a=await k.subtle.importKey("raw",d(o),{name:"Ed25519"},!1,["verify"]);return k.subtle.verify({name:"Ed25519"},a,d(i),d(n))}s(Ut,"ed25519Verify");async function Et({message:t,publicKey:e,signature:r}){let n=e;return typeof e=="string"&&(n=Qe(e).publicKey),W.verify(t,r,await k.subtle.importKey("spki",d(n),{name:q,hash:Ve},!1,["verify"]),8)}s(Et,"rsaVerify");var W={verify:s(async function(e,r,n,i=O,o=se){return k.subtle.verify({name:q,saltLength:E},typeof n=="string"?await Le(n,o,"signing"):n,$e(r),Z(e,i))},"rsaVerify"),sign:s(async function(e,r,n=O){return k.subtle.sign({name:q,saltLength:E},r,Z(e,n))},"sign"),encrypt:s(async function(e,r,n=O,i=se){let o;return typeof r=="string"?o=await Le(r,i,"exchange"):o=r instanceof Uint8Array?await Le(d(r),i,"exchange"):r,k.subtle.encrypt({name:J},o,Z(e,n))},"rsaEncrypt"),decrypt:s(async function(e,r){let n=Ke(r)?r:await ei(r,["decrypt"]),i;typeof e=="string"?i=A(e,"base64pad"):i=e;let o=await k.subtle.decrypt({name:J},n,i instanceof Uint8Array?d(i):i);return new Uint8Array(o)},"rsaDecrypt")};async function Le(t,e,r){qn(r);let n=r==="exchange"?J:q,i=r==="exchange"?["encrypt"]:["verify"],o=typeof t=="string"?I(Qn(t)):t;return k.subtle.importKey("spki",o,{name:n,hash:{name:e}},!0,i)}s(Le,"rsaImportPublicKey");function qn(t){Zn(t,["signing","exchange"],bt)}s(qn,"checkValidKeyUse");function Zn(t,e,r){if(!e.some(i=>i===t))throw r}s(Zn,"checkValid");function Qn(t){return t.replace(`-----BEGIN PUBLIC KEY-----
1
+ var rr=Object.defineProperty;var _t=(t,e,r)=>e in t?rr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var s=(t,e)=>rr(t,"name",{value:e,configurable:!0});var S=(t,e)=>{for(var r in e)rr(t,r,{get:e[r],enumerable:!0})};var c=(t,e,r)=>_t(t,typeof e!="symbol"?e+"":e,r);var Yr=(n=>(n[n.B1024=1024]="B1024",n[n.B2048=2048]="B2048",n[n.B4096=4096]="B4096",n))(Yr||{}),$r=(n=>(n[n.B128=128]="B128",n[n.B192=192]="B192",n[n.B256=256]="B256",n))($r||{}),Jr=(r=>(r.ECC="ecc",r.RSA="rsa",r))(Jr||{}),tr=(i=>(i.SHA_1="SHA-1",i.SHA_256="SHA-256",i.SHA_384="SHA-384",i.SHA_512="SHA-512",i))(tr||{}),nr=(i=>(i.P_256="P-256",i.P_384="P-384",i.P_521="P-521",i.X25519="X25519",i))(nr||{}),te=(n=>(n.Sign="signing",n.Exchange="exchange",n.Write="write",n))(te||{}),ir=(r=>(r[r.B8=8]="B8",r[r.B16=16]="B16",r))(ir||{});var Dt={};S(Dt,{AES_GCM:()=>z,BASE58_DID_PREFIX:()=>V,BLS_DID_PREFIX:()=>Xe,DEFAULT_CHAR_SIZE:()=>O,DEFAULT_ECC_EXCHANGE:()=>Lr,DEFAULT_ECC_EXCHANGE_CURVE:()=>Gn,DEFAULT_ECC_WRITE:()=>Mr,DEFAULT_HASH_ALGORITHM:()=>se,DEFAULT_RSA_EXCHANGE:()=>Nr,DEFAULT_RSA_SIZE:()=>We,DEFAULT_RSA_WRITE:()=>kr,DEFAULT_SYMM_ALGORITHM:()=>D,DEFAULT_SYMM_LENGTH:()=>H,ECC_EXCHANGE_ALGORITHM:()=>Ie,ECC_WRITE_ALGORITHM:()=>ie,EDWARDS_DID_PREFIX:()=>Ye,IV_LENGTH:()=>P,KEY_TYPE:()=>_e,KEY_USE:()=>Kt,RSA_ALGORITHM:()=>J,RSA_DID_PREFIX:()=>je,RSA_HASHING_ALGORITHM:()=>Ve,RSA_SIGN_ALGORITHM:()=>q,RsaKeys:()=>ce,SALT_LENGTH:()=>E,X25519_PUBLIC_KEY_LENGTH:()=>$,encrypt:()=>yi,encryptKeyTo:()=>Ue,encryptTo:()=>Tt,getPublicKeyAsArrayBuffer:()=>Q,getPublicKeyAsUint8Array:()=>zr,publicKeyToDid:()=>Me,verify:()=>ai});function Ce(t=0){return new Uint8Array(t)}s(Ce,"allocUnsafe");function sr(t,e){e==null&&(e=t.reduce((i,o)=>i+o.length,0));let r=Ce(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return r}s(sr,"concat");var gr={};S(gr,{base10:()=>zt});var Ti=new Uint8Array(0);function qr(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}s(qr,"equals");function G(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}s(G,"coerce");function Zr(t){return new TextEncoder().encode(t)}s(Zr,"fromString");function Qr(t){return new TextDecoder().decode(t)}s(Qr,"toString");function kt(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),a=o.charCodeAt(0);if(r[a]!==255)throw new TypeError(o+" is ambiguous");r[a]=i}var y=t.length,p=t.charAt(0),g=Math.log(y)/Math.log(256),l=Math.log(256)/Math.log(y);function d(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var m=0,T=0,C=0,_=u.length;C!==_&&u[C]===0;)C++,m++;for(var U=(_-C)*l+1>>>0,N=new Uint8Array(U);C!==_;){for(var M=u[C],X=0,L=U-1;(M!==0||X<T)&&L!==-1;L--,X++)M+=256*N[L]>>>0,N[L]=M%y>>>0,M=M/y>>>0;if(M!==0)throw new Error("Non-zero carry");T=X,C++}for(var F=U-T;F!==U&&N[F]===0;)F++;for(var ze=p.repeat(m);F<U;++F)ze+=t.charAt(N[F]);return ze}s(d,"encode");function v(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var m=0;if(u[m]!==" "){for(var T=0,C=0;u[m]===p;)T++,m++;for(var _=(u.length-m)*g+1>>>0,U=new Uint8Array(_);u[m];){var N=r[u.charCodeAt(m)];if(N===255)return;for(var M=0,X=_-1;(N!==0||M<C)&&X!==-1;X--,M++)N+=y*U[X]>>>0,U[X]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");C=M,m++}if(u[m]!==" "){for(var L=_-C;L!==_&&U[L]===0;)L++;for(var F=new Uint8Array(T+(_-L)),ze=T;L!==_;)F[ze++]=U[L++];return F}}}s(v,"decodeUnsafe");function fe(u){var m=v(u);if(m)return m;throw new Error(`Non-${e} character`)}return s(fe,"decode"),{encode:d,decodeUnsafe:v,decode:fe}}s(kt,"base");var Lt=kt,Mt=Lt,rt=Mt;var pr=class pr{constructor(e,r,n){c(this,"name");c(this,"prefix");c(this,"baseEncode");this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}};s(pr,"Encoder");var or=pr,ur=class ur{constructor(e,r,n){c(this,"name");c(this,"prefix");c(this,"baseDecode");c(this,"prefixCodePoint");this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return tt(this,e)}};s(ur,"Decoder");var ar=ur,fr=class fr{constructor(e){c(this,"decoders");this.decoders=e}or(e){return tt(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};s(fr,"ComposedDecoder");var yr=fr;function tt(t,e){return new yr({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}s(tt,"or");var lr=class lr{constructor(e,r,n,i){c(this,"name");c(this,"prefix");c(this,"baseEncode");c(this,"baseDecode");c(this,"encoder");c(this,"decoder");this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new or(e,r,n),this.decoder=new ar(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};s(lr,"Codec");var cr=lr;function le({name:t,prefix:e,encode:r,decode:n}){return new cr(t,e,r,n)}s(le,"from");function Y({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=rt(r,t);return le({prefix:e,name:t,encode:n,decode:s(o=>G(i(o)),"decode")})}s(Y,"baseX");function Rt(t,e,r,n){let i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let o=t.length;for(;t[o-1]==="=";)--o;let a=new Uint8Array(o*r/8|0),y=0,p=0,g=0;for(let l=0;l<o;++l){let d=i[t[l]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<r|d,y+=r,y>=8&&(y-=8,a[g++]=255&p>>y)}if(y>=r||(255&p<<8-y)!==0)throw new SyntaxError("Unexpected end of data");return a}s(Rt,"decode");function Ot(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",a=0,y=0;for(let p=0;p<t.length;++p)for(y=y<<8|t[p],a+=8;a>r;)a-=r,o+=e[i&y>>a];if(a!==0&&(o+=e[i&y<<r-a]),n)for(;(o.length*r&7)!==0;)o+="=";return o}s(Ot,"encode");function A({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return le({prefix:e,name:t,encode(i){return Ot(i,n,r)},decode(i){return Rt(i,n,r,t)}})}s(A,"rfc4648");var zt=Y({prefix:"9",name:"base10",alphabet:"0123456789"});var mr={};S(mr,{base16:()=>Ht,base16upper:()=>Ft});var Ht=A({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ft=A({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var dr={};S(dr,{base2:()=>Gt});var Gt=A({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var hr={};S(hr,{base256emoji:()=>Yt});var nt=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Vt=nt.reduce((t,e,r)=>(t[r]=e,t),[]),jt=nt.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Wt(t){return t.reduce((e,r)=>(e+=Vt[r],e),"")}s(Wt,"encode");function Xt(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=jt[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}s(Xt,"decode");var Yt=le({prefix:"\u{1F680}",name:"base256emoji",encode:Wt,decode:Xt});var Ar={};S(Ar,{base32:()=>ge,base32hex:()=>Zt,base32hexpad:()=>en,base32hexpadupper:()=>rn,base32hexupper:()=>Qt,base32pad:()=>Jt,base32padupper:()=>qt,base32upper:()=>$t,base32z:()=>tn});var ge=A({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$t=A({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Jt=A({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),qt=A({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zt=A({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qt=A({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),en=A({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),rn=A({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),tn=A({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kr={};S(Kr,{base36:()=>Pe,base36upper:()=>nn});var Pe=Y({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nn=Y({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var br={};S(br,{base58btc:()=>R,base58flickr:()=>sn});var R=Y({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sn=Y({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wr={};S(wr,{base64:()=>on,base64pad:()=>an,base64url:()=>yn,base64urlpad:()=>cn});var on=A({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),an=A({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yn=A({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cn=A({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xr={};S(xr,{base8:()=>pn});var pn=A({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ur={};S(Ur,{identity:()=>un});var un=le({prefix:"\0",name:"identity",encode:s(t=>Qr(t),"encode"),decode:s(t=>Zr(t),"decode")});var qi=new TextEncoder,Zi=new TextDecoder;var Cr={};S(Cr,{identity:()=>Nn});var gn=ot,it=128,mn=127,dn=~mn,hn=Math.pow(2,31);function ot(t,e,r){e=e||[],r=r||0;for(var n=r;t>=hn;)e[r++]=t&255|it,t/=128;for(;t&dn;)e[r++]=t&255|it,t>>>=7;return e[r]=t|0,ot.bytes=r-n+1,e}s(ot,"encode");var An=Er,Kn=128,st=127;function Er(t,n){var r=0,n=n||0,i=0,o=n,a,y=t.length;do{if(o>=y)throw Er.bytes=0,new RangeError("Could not decode varint");a=t[o++],r+=i<28?(a&st)<<i:(a&st)*Math.pow(2,i),i+=7}while(a>=Kn);return Er.bytes=o-n,r}s(Er,"read");var bn=Math.pow(2,7),wn=Math.pow(2,14),xn=Math.pow(2,21),Un=Math.pow(2,28),En=Math.pow(2,35),Sn=Math.pow(2,42),Cn=Math.pow(2,49),Pn=Math.pow(2,56),Bn=Math.pow(2,63),vn=s(function(t){return t<bn?1:t<wn?2:t<xn?3:t<Un?4:t<En?5:t<Sn?6:t<Cn?7:t<Pn?8:t<Bn?9:10},"length"),Tn={encode:gn,decode:An,encodingLength:vn},Dn=Tn,Be=Dn;function ve(t,e=0){return[Be.decode(t,e),Be.decode.bytes]}s(ve,"decode");function me(t,e,r=0){return Be.encode(t,e,r),e}s(me,"encodeTo");function de(t){return Be.encodingLength(t)}s(de,"encodingLength");function ne(t,e){let r=e.byteLength,n=de(t),i=n+de(r),o=new Uint8Array(i+r);return me(t,o,0),me(r,o,n),o.set(e,i),new he(t,r,e,o)}s(ne,"create");function at(t){let e=G(t),[r,n]=ve(e),[i,o]=ve(e.subarray(n)),a=e.subarray(n+o);if(a.byteLength!==i)throw new Error("Incorrect length");return new he(r,i,a,e)}s(at,"decode");function yt(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&qr(t.bytes,r.bytes)}}s(yt,"equals");var Sr=class Sr{constructor(e,r,n,i){c(this,"code");c(this,"size");c(this,"digest");c(this,"bytes");this.code=e,this.size=r,this.digest=n,this.bytes=i}};s(Sr,"Digest");var he=Sr;var ct=0,In="identity",pt=G;function _n(t){return ne(ct,pt(t))}s(_n,"digest");var Nn={code:ct,name:In,encode:pt,digest:_n};var Tr={};S(Tr,{sha256:()=>kn,sha512:()=>Ln});function Br({name:t,code:e,encode:r}){return new Pr(t,e,r)}s(Br,"from");var vr=class vr{constructor(e,r,n){c(this,"name");c(this,"code");c(this,"encode");this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?ne(this.code,r):r.then(n=>ne(this.code,n))}else throw Error("Unknown type, must be binary type")}};s(vr,"Hasher");var Pr=vr;function ft(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}s(ft,"sha");var kn=Br({name:"sha2-256",code:18,encode:ft("SHA-256")}),Ln=Br({name:"sha2-512",code:19,encode:ft("SHA-512")});function lt(t,e){let{bytes:r,version:n}=t;return n===0?Rn(r,Dr(t),e??R.encoder):On(r,Dr(t),e??ge.encoder)}s(lt,"format");var gt=new WeakMap;function Dr(t){let e=gt.get(t);if(e==null){let r=new Map;return gt.set(t,r),r}return e}s(Dr,"baseCache");var dt,w=class w{constructor(e,r,n,i){c(this,"code");c(this,"version");c(this,"multihash");c(this,"bytes");c(this,"/");c(this,dt,"CID");this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==De)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==zn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return w.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=ne(e,r);return w.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return w.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&yt(e.multihash,n.multihash)}toString(e){return lt(this,e)}toJSON(){return{"/":lt(this)}}link(){return this}[(dt=Symbol.toStringTag,Symbol.for("nodejs.util.inspect.custom"))](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof w)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:a}=r;return new w(n,i,o,a??mt(n,i,o.bytes))}else if(r[Hn]===!0){let{version:n,multihash:i,code:o}=r,a=at(i);return w.create(n,o,a)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==De)throw new Error(`Version 0 CID must use dag-pb (code: ${De}) block encoding`);return new w(e,r,n,n.bytes)}case 1:{let i=mt(e,r,n.bytes);return new w(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return w.create(0,De,e)}static createV1(e,r){return w.create(1,e,r)}static decode(e){let[r,n]=w.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=w.inspectBytes(e),n=r.size-r.multihashSize,i=G(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),a=new he(r.multihashCode,r.digestSize,o,i);return[r.version===0?w.createV0(a):w.createV1(r.codec,a),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=s(()=>{let[d,v]=ve(e.subarray(r));return r+=v,d},"next"),i=n(),o=De;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let a=r,y=n(),p=n(),g=r+p,l=g-a;return{version:i,codec:o,multihashCode:y,digestSize:p,multihashSize:l,size:g}}static parse(e,r){let[n,i]=Mn(e,r),o=w.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Dr(o).set(n,e),o}};s(w,"CID");var Fe=w;function Mn(t,e){switch(t[0]){case"Q":{let r=e??R;return[R.prefix,r.decode(`${R.prefix}${t}`)]}case R.prefix:{let r=e??R;return[R.prefix,r.decode(t)]}case ge.prefix:{let r=e??ge;return[ge.prefix,r.decode(t)]}case Pe.prefix:{let r=e??Pe;return[Pe.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}s(Mn,"parseCIDtoBytes");function Rn(t,e,r){let{prefix:n}=r;if(n!==R.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}s(Rn,"toStringV0");function On(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}s(On,"toStringV1");var De=112,zn=18;function mt(t,e,r){let n=de(t),i=n+de(e),o=new Uint8Array(i+r.byteLength);return me(t,o,0),me(e,o,n),o.set(r,i),o}s(mt,"encodeCID");var Hn=Symbol.for("@ipld/js-cid/CID");var Ir={...Ur,...dr,...xr,...gr,...mr,...Ar,...Kr,...br,...wr,...hr},vs={...Tr,...Cr};function At(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}s(At,"createCodec");var ht=At("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),_r=At("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ce(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Fn={utf8:ht,"utf-8":ht,hex:Ir.base16,latin1:_r,ascii:_r,binary:_r,...Ir},Ge=Fn;function K(t,e="utf8"){let r=Ge[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}s(K,"fromString");function f(t,e="utf8"){let r=Ge[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}s(f,"toString");var Ct={};S(Ct,{AES:()=>b,decryptBytes:()=>St,importAesKey:()=>be});var V="did:key:z",ie="Ed25519",Ie="X25519",Gn="X25519",$=32,Kt={sign:["sign","verify"],encrypt:["deriveKey","deriveBits"]},J="RSA-OAEP",q="RSASSA-PKCS1-v1_5",Ve="SHA-256",je=new Uint8Array([0,245,2]),We=2048,se="SHA-256",O=8,z="AES-GCM",D=z,H=256,P=12,Xe=new Uint8Array([234,1]),Ye=new Uint8Array([237,1]),_e={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"},Nr="rsa-exchange-key",kr="rsa-write-key",Lr="ecc-exchange",Mr="ecc-write",E=16;var Ne=globalThis.crypto,bt=new Error("Invalid key use. Please use 'encryption' or 'signing"),Vn=new Error("Max must be less than 256 and greater than 0");function h(t){return new Uint8Array(t).buffer}s(h,"toArrayBuffer");async function wt(t){return new Uint8Array(await Ne.subtle.digest("sha-256",t.buffer))}s(wt,"sha256");function I(t){let e=K(t,"base64pad");return h(e)}s(I,"base64ToArrBuf");var oe=s((t,e)=>{if(typeof t=="string")return e(t);if(typeof t=="object"&&t.byteLength!==void 0)return new Uint8Array(t).buffer;throw new Error("Improper value. Must be a string, ArrayBuffer, Uint8Array")},"normalizeToBuf");function $e(t){return oe(t,I)}s($e,"normalizeBase64ToBuf");var jn=s(t=>oe(t,e=>xt(e,8)),"normalizeUtf8ToBuf");function xt(t,e){let r=e===8?new Uint8Array(t.length):new Uint16Array(t.length);for(let n=0,i=t.length;n<i;n++)r[n]=t.charCodeAt(n);return r.buffer}s(xt,"strToArrBuf");var Wn=s(t=>oe(t,e=>xt(e,16)),"normalizeUtf16ToBuf");function Z(t,e){return e===8?jn(t):Wn(t)}s(Z,"normalizeUnicodeToBuf");function Je(t){if(!t.startsWith(V))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+t.substring(V.length),r=K(e,"base58btc"),{keyBuffer:n,type:i}=Xn(h(r));return{publicKey:new Uint8Array(n),type:i}}s(Je,"didToPublicKey");function Xn(t){if(Ae(t,h(je)))return{keyBuffer:t.slice(je.byteLength),type:_e.RSA};if(Ae(t,h(Ye)))return{keyBuffer:t.slice(Ye.byteLength),type:_e.Edwards};if(Ae(t,h(Xe)))return{keyBuffer:t.slice(Xe.byteLength),type:_e.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}s(Xn,"parseMagicBytes");var Yn={equal:s((t,e)=>{let r=new Uint8Array(t),n=new Uint8Array(e);if(r.length!==n.length)return!1;for(let i=0;i<r.length;i++)if(r[i]!==n[i])return!1;return!0},"equal")};function Ae(t,e){return Yn.equal(e,t.slice(0,e.byteLength))}s(Ae,"hasPrefix");function x(t){return f(t instanceof ArrayBuffer?new Uint8Array(t):t,"base64pad")}s(x,"toBase64");async function ke(t,e){let r=typeof t=="string"?I(t):h(t);return Ne.subtle.importKey("raw",r,{name:e?.alg||D,length:e?.length||H},!0,["encrypt","decrypt"])}s(ke,"importKey");function qe(t,{max:e}={max:255}){if(e<1||e>255)throw Vn;let r=new Uint8Array(t);if(e===255)return Ne.getRandomValues(r),r.buffer;let n=0,i=e+1,o=Math.floor(256/i)*i,a=new Uint8Array(1);for(;n<r.length;)Ne.getRandomValues(a),a[0]<o&&(r[n]=a[0]%i,n++);return r.buffer}s(qe,"randomBuf");function j(t,e){let r=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(h(t)),n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(h(e)),i=new Uint8Array(r.length+n.length);return i.set(r),i.set(n,r.length),i.buffer}s(j,"joinBufs");async function Rr(t,e,r,n=!1){let i=n;if(!Object.values(te).includes(r))throw new Error("invalid key use");let o=r==="exchange"?J:q,a=r==="exchange"?["encrypt","decrypt"]:["sign","verify"];return Ne.subtle.generateKey({name:o,modulusLength:t,publicExponent:$n(),hash:{name:e}},i,a)}s(Rr,"makeRSAKeypair");function $n(){return new Uint8Array([1,0,1])}s($n,"publicExponent");var k=globalThis.crypto,Ze={keyTypes:{"bls12-381":{magicBytes:new Uint8Array([234,1]),verify:s(()=>{throw new Error("Not implemented")},"verify")},rsa:{magicBytes:new Uint8Array([0,245,2]),verify:Et},ed25519:{magicBytes:new Uint8Array([237,1]),verify:Ut}}};async function yo({message:t,did:e,signature:r}){let n=Jn(e),i=Qe(e).publicKey;if(n==="ed25519")return Ut({message:t,publicKey:i,signature:r});if(n==="rsa")return Et({message:t,publicKey:i,signature:r});throw new Error("Unknown key format")}s(yo,"verify");function Jn(t){try{let{type:e}=Qe(t);return e}catch{return"unknown"}}s(Jn,"getAlgorithm");async function Ut({message:t,publicKey:e,signature:r}){let n=t;typeof t=="string"&&(n=K(t,"utf8"));let i=r;typeof r=="string"&&(i=K(r,"base64pad"));let o=e;if(typeof e=="string"&&(o=Qe(e).publicKey),o.length!==32)throw new Error(`Invalid Ed25519 public key size: ${o.length} bytes, expected 32`);if(i.length!==64)throw new Error(`Invalid Ed25519 signature size: ${i.length} bytes, expected 64`);let a=await k.subtle.importKey("raw",h(o),{name:"Ed25519"},!1,["verify"]);return k.subtle.verify({name:"Ed25519"},a,h(i),h(n))}s(Ut,"ed25519Verify");async function Et({message:t,publicKey:e,signature:r}){let n=e;return typeof e=="string"&&(n=Qe(e).publicKey),W.verify(t,r,await k.subtle.importKey("spki",h(n),{name:q,hash:Ve},!1,["verify"]),8)}s(Et,"rsaVerify");var W={verify:s(async function(e,r,n,i=O,o=se){return k.subtle.verify({name:q,saltLength:E},typeof n=="string"?await Le(n,o,"signing"):n,$e(r),Z(e,i))},"rsaVerify"),sign:s(async function(e,r,n=O){return k.subtle.sign({name:q,saltLength:E},r,Z(e,n))},"sign"),encrypt:s(async function(e,r,n=O,i=se){let o;return typeof r=="string"?o=await Le(r,i,"exchange"):o=r instanceof Uint8Array?await Le(h(r),i,"exchange"):r,k.subtle.encrypt({name:J},o,Z(e,n))},"rsaEncrypt"),decrypt:s(async function(e,r){let n=Ke(r)?r:await ei(r,["decrypt"]),i;typeof e=="string"?i=K(e,"base64pad"):i=e;let o=await k.subtle.decrypt({name:J},n,i instanceof Uint8Array?h(i):i);return new Uint8Array(o)},"rsaDecrypt")};async function Le(t,e,r){qn(r);let n=r==="exchange"?J:q,i=r==="exchange"?["encrypt"]:["verify"],o=typeof t=="string"?I(Qn(t)):t;return k.subtle.importKey("spki",o,{name:n,hash:{name:e}},!0,i)}s(Le,"rsaImportPublicKey");function qn(t){Zn(t,["signing","exchange"],bt)}s(qn,"checkValidKeyUse");function Zn(t,e,r){if(!e.some(i=>i===t))throw r}s(Zn,"checkValid");function Qn(t){return t.replace(`-----BEGIN PUBLIC KEY-----
2
2
  `,"").replace(`
3
- -----END PUBLIC KEY-----`,"")}s(Qn,"stripKeyHeader");function Ke(t){return Or(t,"algorithm")&&Or(t,"extractable")&&Or(t,"type")}s(Ke,"isCryptoKey");function Or(t,e){return typeof t=="object"&&t!=null&&e in t}s(Or,"hasProp");function ei(t,e){return k.subtle.importKey("spki",t instanceof Uint8Array?d(t):t,{name:J,hash:Ve},!1,e)}s(ei,"importRsaKey");async function Me(t,e="rsa"){let r;if(t instanceof CryptoKey){e=t.algorithm.name.includes("RSA")?"rsa":"ed25519";let o=e==="ed25519"?"raw":"spki",a=await k.subtle.exportKey(o,t);r=new Uint8Array(a)}else r=t;let n=Ze.keyTypes[e]?.magicBytes;if(!n)throw new Error(`Key type '${e}' not supported, available types: ${Object.keys(Ze.keyTypes).join(", ")}`);let i=sr([n,r]);return V+f(i,"base58btc")}s(Me,"publicKeyToDid");function co(t){let e=t.substring(V.length),r=A(e,"base58btc"),n=Object.entries(Ze.keyTypes).find(([o,a])=>Ae(r.buffer,a.magicBytes.buffer));if(!n)throw new Error("Invalid key type");let i=n[0];if(i!=="ed25519"&&i!=="rsa")throw new Error(`Unsupported key type: ${i}`);return i}s(co,"keyTypeFromDid");async function Q(t){return t instanceof CryptoKey?await k.subtle.exportKey("spki",t):await k.subtle.exportKey("spki",t.publicKey)}s(Q,"getPublicKeyAsArrayBuffer");async function zr(t){let e=await Q(t);return new Uint8Array(e)}s(zr,"getPublicKeyAsUint8Array");function Qe(t){if(!t.startsWith(V))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=t.substring(V.length),r=A(e,"base58btc"),n=Object.entries(Ze.keyTypes).find(([o,a])=>Ae(r.buffer,a.magicBytes.buffer));if(!n)throw new Error("Unsupported key algorithm.");let i=r.slice(n[1].magicBytes.length);return n[0]==="ed25519"&&i.length===44?{publicKey:i.slice(-32),type:n[0]}:{publicKey:i,type:n[0]}}s(Qe,"didToPublicKey");var ae=globalThis.crypto,K={create(t={alg:D,length:H}){let e=t.length||H,r=t.alg||D;return ae.subtle.generateKey({name:r,length:e},!0,["encrypt","decrypt"])},export:Object.assign(async t=>{let e=await ae.subtle.exportKey("raw",t);return new Uint8Array(e)},{asString:s(async(t,e)=>{let r=await K.export(t);return e?f(r,e):x(r)},"asString")}),import(t){return be(typeof t=="string"?I(t):t)},async exportAsString(t){let e=await K.export(t);return x(e)},encrypt:ri,async decrypt(t,e,r){let n=Ke(e)?e:await be(e),i=r?await ae.subtle.decrypt({name:z,iv:d(r)},n,typeof t=="string"?d(A(t)):t instanceof Uint8Array?d(t):t):await St(t,n);return new Uint8Array(i)}};function be(t,e){return ae.subtle.importKey("raw",t instanceof Uint8Array?d(t):t,{name:z,length:e||256},!0,["encrypt","decrypt"])}s(be,"importAesKey");async function ri(t,e,r,n){let i=Ke(e)?e:await be(e),o=n?await ae.subtle.encrypt({name:z,iv:d(n)},i,t instanceof ArrayBuffer?t:d(typeof t=="string"?A(t):t)):await ti(t,i);return r&&r==="arraybuffer"?o:new Uint8Array(o)}s(ri,"encrypt");async function ti(t,e,r){let n=Z(t,r?.charsize??O),i=typeof e=="string"?await ke(e,r):e,o=r?.iv||qe(P),a=await ae.subtle.encrypt({name:z,iv:o},i,n);return j(o,a)}s(ti,"encryptBytes");async function St(t,e,r){let n=$e(t),i=typeof e=="string"?await ke(e,r):e,o=n.slice(0,P),a=n.slice(P);return await ae.subtle.decrypt({name:D,iv:o},i,a)}s(St,"decryptBytes");function er(t){return new Promise((e,r)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>r(t.error)})}s(er,"promisifyRequest");function ni(t,e){let r,n=s(()=>{if(r)return r;let i=indexedDB.open(t);return i.onupgradeneeded=()=>i.result.createObjectStore(e),r=er(i),r.then(o=>{o.onclose=()=>r=void 0},()=>{}),r},"getDB");return(i,o)=>n().then(a=>o(a.transaction(e,i).objectStore(e)))}s(ni,"createStore");var Hr;function Fr(){return Hr||(Hr=ni("keyval-store","keyval")),Hr}s(Fr,"defaultGetStore");function Re(t,e=Fr()){return e("readonly",r=>er(r.get(t)))}s(Re,"get");function Gr(t,e,r=Fr()){return r("readwrite",n=>(n.put(e,t),er(n.transaction)))}s(Gr,"set");function Vr(t,e=Fr()){return e("readwrite",r=>(t.forEach(n=>r.delete(n)),er(r.transaction)))}s(Vr,"delMany");var xo=new Error("Key does not exist. Make sure you properly instantiated the keystore."),Uo=new Error("Retrieved a symmetric key when an asymmetric keypair was expected. Please use a different key name."),Eo=new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name."),So=new Error("ECC is not enabled for this browser. Please use RSA instead."),Co=new Error("Cryptosystem not supported. Please use ECC or RSA"),ii=new Error("Invalid key use. Please use 'exchange' or 'write'"),Po=new Error("Max must be less than 256 and greater than 0"),jr=class jr extends Error{constructor(e){super(e||"These keys were deleted"),this.name="KeysDeletedError"}};s(jr,"KeysDeletedError");var we=jr;function Pt(t){si(t,["exchange","write","signing"],ii)}s(Pt,"checkValidKeyUse");function si(t,e,r){if(!e.some(i=>i===t))throw r}s(si,"checkValid");var ee=class ee{constructor(e){c(this,"DID");c(this,"hasPersisted");c(this,"isSessionOnly");c(this,"destroyed");c(this,"exchangeKeyName");c(this,"writeKeyName");c(this,"_exchangeKey");c(this,"_writeKey");let{keys:r}=e,n=this.constructor;this.DID=e.did,this._exchangeKey=r.exchange,this._writeKey=r.write,this.hasPersisted=e.hasPersisted,this.isSessionOnly=!!e.isSessionOnly,this.destroyed=!1,this.exchangeKeyName=e.exchangeKeyName||n.EXCHANGE_KEY_NAME,this.writeKeyName=e.writeKeyName||n.WRITE_KEY_NAME}get exchangeKey(){if(this.destroyed||!this._exchangeKey)throw new we;return this._exchangeKey}get writeKey(){if(this.destroyed||!this._writeKey)throw new we;return this._writeKey}publicExchangeKeyAsString(e){return this.publicExchangeKey.asString(e)}publicWriteKeyAsString(e){return this.publicWriteKey.asString(e)}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:s(async r=>{let n=await Q(this.writeKey),i=new Uint8Array(n);return r?f(i,r):x(i)},"asString")})}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async r=>{let n=await Q(this.exchangeKey),i=new Uint8Array(n);return r?f(i,r):x(i)},"asString")})}get privateWriteKey(){return this.writeKey.privateKey}get privateExchangeKey(){return this.exchangeKey.privateKey}get deviceName(){return ee.deviceName(this.DID)}static deviceName(e){return oi(e)}async persist(){if(this.destroyed)throw new we;this.isSessionOnly||(await Promise.all([Gr(this.exchangeKeyName,this.exchangeKey),Gr(this.writeKeyName,this.writeKey)]),this.hasPersisted=!0)}async delete(){let e=this.exchangeKeyName,r=this.writeKeyName;await Vr([e,r]),this.constructor._invalidate(e,r),this._destroy()}_destroy(){this.destroyed=!0,this.hasPersisted=!1,this._exchangeKey=null,this._writeKey=null}static _invalidate(e,r){let n=this._instance;n&&n.exchangeKeyName===e&&n.writeKeyName===r&&(n._destroy(),this._instance=null)}static async delete(e={}){let r=e.encryptionKeyName||this.EXCHANGE_KEY_NAME,n=e.writeKeyName||this.WRITE_KEY_NAME;await Vr([r,n]),this._invalidate(r,n)}async getDeviceName(){return ee.deviceName(this.DID)}static _createExchangeKeys(e){throw new Error("The child should implement this")}static _createWriteKeys(e){throw new Error("The child should implement this")}static async create(e,r,n){let i=n?.exchangeKeys||await this._createExchangeKeys(r),o=n?.writeKeys||await this._createWriteKeys(r),a=await Q(o),y=await Me(new Uint8Array(a),this.TYPE==="ecc"?"ed25519":"rsa"),p=new this({keys:{exchange:i,write:o},did:y,hasPersisted:!1,isSessionOnly:!!e});return this._instance=p,p}static async exist(e={}){let r=await Re(e.writeKeyName||this.WRITE_KEY_NAME),n=await Re(e.encryptionKeyName||this.EXCHANGE_KEY_NAME);return!(!r||!n)}static async load(e={session:!1}){let r=e.encryptionKeyName||this.EXCHANGE_KEY_NAME,n=e.writeKeyName||this.WRITE_KEY_NAME,i=this._instance;if(i&&!i.destroyed&&i.exchangeKeyName===r&&i.writeKeyName===n)return i;let o=!0,a=await Re(r),y=await Re(n);a||(o=!1,a=await this._createExchangeKeys(e.extractable)),y||(o=!1,y=await this._createWriteKeys(e.extractable));let p=await Q(y),g=await Me(new Uint8Array(p),this.TYPE==="ecc"?"ed25519":"rsa"),l=new this({keys:{exchange:a,write:y},did:g,hasPersisted:o,isSessionOnly:!!e.session,exchangeKeyName:r,writeKeyName:n});return this._instance=l,l}};s(ee,"AbstractKeys"),c(ee,"EXCHANGE_KEY_NAME"),c(ee,"WRITE_KEY_NAME"),c(ee,"_instance");var xe=ee;async function Bt(t,e){let{content:r,publicKey:n}=t,i=e||await K.create(),o=await K.encrypt(typeof r=="string"?A(r):r,typeof i=="string"?await K.import(i):i),a=await Wr({key:i,publicKey:n});return j(a,o)}s(Bt,"encryptTo");Bt.asString=async function(t,e){let r=await Bt(t,e);return f(new Uint8Array(r),"base64pad")};async function Wr({key:t,publicKey:e},r){let n;t instanceof CryptoKey?n=await K.export(t):n=t;let i=await W.encrypt(n,e);return r&&r==="arraybuffer"?i:new Uint8Array(i)}s(Wr,"encryptKeyTo");Wr.asString=async function({key:t,publicKey:e},r){let n=await Wr({key:t,publicKey:e});return r?f(n,r):x(n)};async function oi(t){let e=await wt(new TextEncoder().encode(t.normalize("NFD")));return f(e,"base32").slice(0,32)}s(oi,"getDeviceName");var Xr=globalThis.crypto;function vt(t){return new Uint8Array(t).buffer}s(vt,"toArrayBuffer");var ye=class ye extends xe{static async create(e,r,n){return await super.create(e,r,n)}static async _createExchangeKeys(e=!1){return await Rr(We,se,"exchange",e)}static async _createWriteKeys(e=!1){return await Rr(We,se,"write",e)}async toJson(e){let r=this.publicExchangeKey,n=this.DID,i=await Xr.subtle.exportKey("spki",r);return{publicExchangeKey:e?f(new Uint8Array(i),e):x(i),DID:n}}async sign(e,r=O){let n=this.writeKey,i=await W.sign(e,n.privateKey,r);return new Uint8Array(i)}async signAsString(e,r){let n=await this.sign(e,r);return x(n)}async encrypt(e,r,n,i,o){let a=r||this.exchangeKey.publicKey,y=n,p=i,g=y||await K.create({length:p||o}),l=await K.encrypt(typeof e=="string"?A(e):e,typeof g=="string"?await K.import(g):g),b=await Ue({key:g,publicKey:a}),v=j(b,l);return new Uint8Array(v)}async encryptAsString(e,r,n,i,o){let a=await this.encrypt(e,r,n,i,o);return f(a,"base64pad")}async decrypt(e,r,n){let i=(typeof r=="number"?r:void 0)||H,o=oe(e,I),a=o.slice(0,i),y=o.slice(i),p=await this.decryptKey(a);return await K.decrypt(y,p)}async decryptAsString(e,r,n){let i=await this.decrypt(e,r,n);return f(i)}async decryptKey(e){return await W.decrypt(e,this.exchangeKey.privateKey)}async decryptKeyAsString(e,r){let n=await W.decrypt(e,this.exchangeKey.privateKey);return f(n,r)}async getAesKey(e,r){if(!e)throw new Error("RSA requires an encrypted AES key to decrypt");if(typeof e=="string"){let n=await this.decryptKey(e);return await K.import(n)}else return e}};s(ye,"RsaKeys"),c(ye,"TYPE","rsa"),c(ye,"INFO","keys"),c(ye,"EXCHANGE_KEY_NAME",Nr),c(ye,"WRITE_KEY_NAME",kr);var ce=ye;Object.assign(ce.prototype.sign,{asString:s(async function(t,e){return this.signAsString(t,e)},"asString")});Object.assign(ce.prototype.encrypt,{asString:s(async function(t,e,r,n){return this.encryptAsString(t,e,r,n)},"asString")});Object.assign(ce.prototype.decrypt,{asString:s(async function(t,e){return this.decryptAsString(t,e)},"asString")});async function ai(t,e,r){let n=Je(r),i=await Le(n.publicKey.buffer,"SHA-256","signing");try{return W.verify(t,e,i)}catch{return!1}}s(ai,"verify");Object.assign(ce.prototype.decryptKey,{asString:s(async function(t,e){return this.decryptKeyAsString(t,e)},"asString")});async function Tt(t,e){let{content:r,publicKey:n}=t,i=e||await K.create(),o=await K.encrypt(typeof r=="string"?A(r):r,typeof i=="string"?await K.import(i):i),a=await Ue({key:i,publicKey:n});return j(a,o)}s(Tt,"encryptTo");Tt.asString=async function(t,e){let{content:r,publicKey:n}=t,i=e||await K.create(),o=await K.encrypt(typeof r=="string"?A(r):r,typeof i=="string"?await K.import(i):i,"arraybuffer"),a=await Ue({key:i,publicKey:n}),y=j(a,o);return f(new Uint8Array(y),"base64pad")};async function Ue({key:t,publicKey:e},r){let n;t instanceof CryptoKey?n=await K.export(t):n=t;let i=await W.encrypt(n,e);return r&&r==="arraybuffer"?i:new Uint8Array(i)}s(Ue,"encryptKeyTo");Ue.asString=async function({key:t,publicKey:e},r){let n=await Ue({key:t,publicKey:e});return r?f(n,r):x(n)};async function yi(t,e,r,n){let i=Ke(e)?e:await be(e),o=n?await Xr.subtle.encrypt({name:z,iv:vt(n)},i,vt(t)):await ci(t,i);return r&&r==="arraybuffer"?o:new Uint8Array(o)}s(yi,"encrypt");async function ci(t,e,r){let n=Z(t,r?.charsize??O),i=typeof e=="string"?await ke(e,r):e,o=r?.iv||qe(P),a=await Xr.subtle.encrypt({name:z,iv:o},i,n);return j(o,a)}s(ci,"encryptBytes");var It={};S(It,{EccKeys:()=>re,default:()=>pi,exportPublicKey:()=>Se,importPublicKey:()=>Oe,verify:()=>ui});var pe=globalThis.crypto;function ue(t){return new Uint8Array(t).buffer}s(ue,"toArrayBuffer");var B=class B extends xe{static async create(e,r,n){return await super.create(e,r,n)}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async r=>{let n=await Se(this.exchangeKey),i=new Uint8Array(n);return r?f(i,r):x(n)},"asString")})}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:s(async r=>{let n=await Se(this.writeKey),i=new Uint8Array(n);return r?f(i,r):x(n)},"asString")})}static async _createExchangeKeys(e=!1){return await pe.subtle.generateKey({name:Ie},e,["deriveKey","deriveBits"])}static async _createWriteKeys(e=!1){return await pe.subtle.generateKey({name:ie},e,["sign","verify"])}static async load(e={session:!1}){return super.load(e)}async toJson(e){let r=this.DID,n=await Se(this.exchangeKey);return{publicExchangeKey:e?f(new Uint8Array(n),e):x(n),DID:r}}async wrap(e,r,n){let i=await B._createExchangeKeys(!0),o=crypto.getRandomValues(new Uint8Array(E)),a=await Ee(i.privateKey,r,o,n||"key-wrap"),y;if(e instanceof CryptoKey){let T=await crypto.subtle.exportKey("raw",e);y=new Uint8Array(T)}else typeof e=="string"?y=A(e,"base64pad"):y=e;let p=crypto.getRandomValues(new Uint8Array(P)),g=await crypto.subtle.encrypt({name:D,iv:p},a,ue(y)),l=await Se(i),b=new Uint8Array(o),v=new Uint8Array(p),fe=new Uint8Array(g),u=b.length+v.length+fe.length,m=new Uint8Array(u);return m.set(b,0),m.set(v,b.length),m.set(fe,b.length+v.length),{enc:x(new Uint8Array(l)),wrappedKey:x(m)}}async unwrap(e,r,n){let i=await Oe(e,"X25519","exchange"),o=new Uint8Array(I(r)),a=o.slice(0,E),y=o.slice(E,E+P),p=o.slice(E+P),g=await Ee(this.exchangeKey.privateKey,i,a,n||"key-wrap"),l=await crypto.subtle.decrypt({name:D,iv:y},g,ue(p));return await crypto.subtle.importKey("raw",l,{name:D},!0,["encrypt","decrypt"])}async encrypt(e,r,n,i,o){let a=crypto.getRandomValues(new Uint8Array(E)),y=r||this.exchangeKey.publicKey,p;typeof y=="string"?p=await Oe(y,"X25519","exchange"):p=y;let g=await B._createExchangeKeys(!0),l=i||await Ee(g.privateKey,p,a,n||B.INFO,o);l instanceof CryptoKey||(l=await Ee(g.privateKey,p,a,n||B.INFO));let b=crypto.getRandomValues(new Uint8Array(P)),v=typeof e=="string"?new TextEncoder().encode(e):e,fe=await crypto.subtle.encrypt({name:D,iv:b},l,ue(v)),u=new Uint8Array(await Se(g)),m=new Uint8Array(a),T=new Uint8Array(b),C=new Uint8Array(fe),_=u.length+m.length+T.length+C.length,U=new Uint8Array(_);return U.set(u,0),U.set(m,u.length),U.set(T,u.length+m.length),U.set(C,u.length+m.length+T.length),U}async encryptAsString(e,r,n,i,o){let a=await this.encrypt(e,r,n||B.INFO,i,o);return f(new Uint8Array(a),"base64pad")}async decrypt(e,r,n){let i=oe(e,I),o=i.slice(0,$),a=await pe.subtle.importKey("raw",o,{name:Ie},!0,[]),y=i.slice($,$+E),p=i.slice($+E,$+E+P),g=i.slice($+E+P),{privateKey:l}=this.exchangeKey,b=await Ee(l,a,y,n||B.INFO);return await crypto.subtle.decrypt({name:r||D,iv:p},b,g)}async decryptAsString(e,r,n){let i=await this.decrypt(e,r,n);return f(new Uint8Array(i))}async getAesKey(e,r){e||(e=this.publicExchangeKey);let n;typeof e=="string"?n=await Oe(e,"X25519","exchange"):n=e;let i=crypto.getRandomValues(new Uint8Array(E));return await Ee(this.exchangeKey.privateKey,n,i,r||B.INFO)}async sign(e,r){let n=new TextEncoder,i;typeof e=="string"?i=n.encode(e):e instanceof ArrayBuffer?i=new Uint8Array(e):i=e;let o=await pe.subtle.sign({name:ie},this.writeKey.privateKey,ue(i));return new Uint8Array(o)}async signAsString(e,r){let n=await this.sign(e,r);return f(n,"base64pad")}};s(B,"EccKeys"),c(B,"TYPE","ecc"),c(B,"EXCHANGE_KEY_NAME",Lr),c(B,"WRITE_KEY_NAME",Mr),c(B,"INFO","keys");var re=B;Object.assign(re.prototype.sign,{asString:s(async function(t,e){let r=await this.sign(t,e);return f(r,"base64pad")},"asString")});async function Se(t,e="raw"){return await crypto.subtle.exportKey(e,t.publicKey)}s(Se,"exportPublicKey");async function Oe(t,e,r){Pt(r);let n=r==="exchange"?Ie:ie,i=r==="exchange"?[]:["verify"],o=I(t),a=e==="X25519"?{name:n}:{name:n,namedCurve:e};return pe.subtle.importKey("raw",o,a,!0,i)}s(Oe,"importPublicKey");var pi={EccKeys:re,importPublicKey:Oe};Object.assign(re.prototype.encrypt,{asString:s(async function(t,e,r,n,i){return this.encryptAsString(t,e,r,n,i)},"asString")});Object.assign(re.prototype.decrypt,{asString:s(async function(t,e){return this.decryptAsString(t,e)},"asString")});Object.assign(re.prototype.sign,{asString:s(async function(t,e){return this.signAsString(t,e)},"asString")});async function ui(t,e,r){try{let n=Je(r);if(n.type!=="ed25519")throw new Error(`Expected Ed25519 key for ECC verification, got ${n.type}`);let i=n.publicKey.slice(-32),o=await pe.subtle.importKey("raw",i,{name:ie},!0,["verify"]),a=new TextEncoder,y;typeof t=="string"?y=a.encode(t):t instanceof ArrayBuffer?y=new Uint8Array(t):y=t;let p;return typeof e=="string"?p=new Uint8Array(I(e)):p=e,await pe.subtle.verify({name:ie},o,ue(p),ue(y))}catch{return!1}}s(ui,"verify");async function Ee(t,e,r,n,i){let o=new TextEncoder,a=await crypto.subtle.deriveBits({name:"X25519",public:e},t,256),y=await crypto.subtle.importKey("raw",a,"HKDF",!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:r instanceof Uint8Array?ue(r):r,info:o.encode(n)},y,{name:"AES-GCM",length:i||H},!1,["encrypt","decrypt"])}s(Ee,"deriveKey");export{z as AES_GCM,xe as AbstractKeys,V as BASE58_DID_PREFIX,Xe as BLS_DID_PREFIX,ir as CharSize,Jr as CryptoSystem,O as DEFAULT_CHAR_SIZE,Lr as DEFAULT_ECC_EXCHANGE,Gn as DEFAULT_ECC_EXCHANGE_CURVE,Mr as DEFAULT_ECC_WRITE,se as DEFAULT_HASH_ALGORITHM,Nr as DEFAULT_RSA_EXCHANGE,We as DEFAULT_RSA_SIZE,kr as DEFAULT_RSA_WRITE,D as DEFAULT_SYMM_ALGORITHM,H as DEFAULT_SYMM_LENGTH,Ie as ECC_EXCHANGE_ALGORITHM,ie as ECC_WRITE_ALGORITHM,Ye as EDWARDS_DID_PREFIX,nr as EccCurve,tr as HashAlg,P as IV_LENGTH,_e as KEY_TYPE,Kt as KEY_USE,te as KeyUse,we as KeysDeletedError,J as RSA_ALGORITHM,je as RSA_DID_PREFIX,Ve as RSA_HASHING_ALGORITHM,q as RSA_SIGN_ALGORITHM,Yr as RsaSize,E as SALT_LENGTH,$r as SymmKeyLength,$ as X25519_PUBLIC_KEY_LENGTH,Ct as aes,qn as checkValidKeyUse,Ze as did,Qe as didToPublicKey,It as ecc,Ut as ed25519Verify,Wr as encryptKeyTo,Bt as encryptTo,Jn as getAlgorithm,oi as getDeviceName,Q as getPublicKeyAsArrayBuffer,zr as getPublicKeyAsUint8Array,ei as importRsaKey,Ke as isCryptoKey,co as keyTypeFromDid,Me as publicKeyToDid,Dt as rsa,Le as rsaImportPublicKey,W as rsaOperations,Et as rsaVerify,yo as verify};
3
+ -----END PUBLIC KEY-----`,"")}s(Qn,"stripKeyHeader");function Ke(t){return Or(t,"algorithm")&&Or(t,"extractable")&&Or(t,"type")}s(Ke,"isCryptoKey");function Or(t,e){return typeof t=="object"&&t!=null&&e in t}s(Or,"hasProp");function ei(t,e){return k.subtle.importKey("spki",t instanceof Uint8Array?h(t):t,{name:J,hash:Ve},!1,e)}s(ei,"importRsaKey");async function Me(t,e="rsa"){let r;if(t instanceof CryptoKey){e=t.algorithm.name.includes("RSA")?"rsa":"ed25519";let o=e==="ed25519"?"raw":"spki",a=await k.subtle.exportKey(o,t);r=new Uint8Array(a)}else r=t;let n=Ze.keyTypes[e]?.magicBytes;if(!n)throw new Error(`Key type '${e}' not supported, available types: ${Object.keys(Ze.keyTypes).join(", ")}`);let i=sr([n,r]);return V+f(i,"base58btc")}s(Me,"publicKeyToDid");function co(t){let e=t.substring(V.length),r=K(e,"base58btc"),n=Object.entries(Ze.keyTypes).find(([o,a])=>Ae(r.buffer,a.magicBytes.buffer));if(!n)throw new Error("Invalid key type");let i=n[0];if(i!=="ed25519"&&i!=="rsa")throw new Error(`Unsupported key type: ${i}`);return i}s(co,"keyTypeFromDid");async function Q(t){return t instanceof CryptoKey?await k.subtle.exportKey("spki",t):await k.subtle.exportKey("spki",t.publicKey)}s(Q,"getPublicKeyAsArrayBuffer");async function zr(t){let e=await Q(t);return new Uint8Array(e)}s(zr,"getPublicKeyAsUint8Array");function Qe(t){if(!t.startsWith(V))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=t.substring(V.length),r=K(e,"base58btc"),n=Object.entries(Ze.keyTypes).find(([o,a])=>Ae(r.buffer,a.magicBytes.buffer));if(!n)throw new Error("Unsupported key algorithm.");let i=r.slice(n[1].magicBytes.length);return n[0]==="ed25519"&&i.length===44?{publicKey:i.slice(-32),type:n[0]}:{publicKey:i,type:n[0]}}s(Qe,"didToPublicKey");var ae=globalThis.crypto,b={create(t={alg:D,length:H}){let e=t.length||H,r=t.alg||D;return ae.subtle.generateKey({name:r,length:e},!0,["encrypt","decrypt"])},export:Object.assign(async t=>{let e=await ae.subtle.exportKey("raw",t);return new Uint8Array(e)},{asString:s(async(t,e)=>{let r=await b.export(t);return e?f(r,e):x(r)},"asString")}),import(t){return be(typeof t=="string"?I(t):t)},async exportAsString(t){let e=await b.export(t);return x(e)},encrypt:ri,async decrypt(t,e,r){let n=Ke(e)?e:await be(e),i=r?await ae.subtle.decrypt({name:z,iv:h(r)},n,typeof t=="string"?h(K(t)):t instanceof Uint8Array?h(t):t):await St(t,n);return new Uint8Array(i)}};function be(t,e){return ae.subtle.importKey("raw",t instanceof Uint8Array?h(t):t,{name:z,length:e||256},!0,["encrypt","decrypt"])}s(be,"importAesKey");async function ri(t,e,r,n){let i=Ke(e)?e:await be(e),o=n?await ae.subtle.encrypt({name:z,iv:h(n)},i,t instanceof ArrayBuffer?t:h(typeof t=="string"?K(t):t)):await ti(t,i);return r&&r==="arraybuffer"?o:new Uint8Array(o)}s(ri,"encrypt");async function ti(t,e,r){let n=Z(t,r?.charsize??O),i=typeof e=="string"?await ke(e,r):e,o=r?.iv||qe(P),a=await ae.subtle.encrypt({name:z,iv:o},i,n);return j(o,a)}s(ti,"encryptBytes");async function St(t,e,r){let n=$e(t),i=typeof e=="string"?await ke(e,r):e,o=n.slice(0,P),a=n.slice(P);return await ae.subtle.decrypt({name:D,iv:o},i,a)}s(St,"decryptBytes");function er(t){return new Promise((e,r)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>r(t.error)})}s(er,"promisifyRequest");function ni(t,e){let r,n=s(()=>{if(r)return r;let i=indexedDB.open(t);return i.onupgradeneeded=()=>i.result.createObjectStore(e),r=er(i),r.then(o=>{o.onclose=()=>r=void 0},()=>{}),r},"getDB");return(i,o)=>n().then(a=>o(a.transaction(e,i).objectStore(e)))}s(ni,"createStore");var Hr;function Fr(){return Hr||(Hr=ni("keyval-store","keyval")),Hr}s(Fr,"defaultGetStore");function Re(t,e=Fr()){return e("readonly",r=>er(r.get(t)))}s(Re,"get");function Gr(t,e,r=Fr()){return r("readwrite",n=>(n.put(e,t),er(n.transaction)))}s(Gr,"set");function Vr(t,e=Fr()){return e("readwrite",r=>(t.forEach(n=>r.delete(n)),er(r.transaction)))}s(Vr,"delMany");var xo=new Error("Key does not exist. Make sure you properly instantiated the keystore."),Uo=new Error("Retrieved a symmetric key when an asymmetric keypair was expected. Please use a different key name."),Eo=new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name."),So=new Error("ECC is not enabled for this browser. Please use RSA instead."),Co=new Error("Cryptosystem not supported. Please use ECC or RSA"),ii=new Error("Invalid key use. Please use 'exchange' or 'write'"),Po=new Error("Max must be less than 256 and greater than 0"),jr=class jr extends Error{constructor(e){super(e||"These keys were deleted"),this.name="KeysDeletedError"}};s(jr,"KeysDeletedError");var we=jr;function Pt(t){si(t,["exchange","write","signing"],ii)}s(Pt,"checkValidKeyUse");function si(t,e,r){if(!e.some(i=>i===t))throw r}s(si,"checkValid");var ee=class ee{constructor(e){c(this,"DID");c(this,"hasPersisted");c(this,"isSessionOnly");c(this,"destroyed");c(this,"exchangeKeyName");c(this,"writeKeyName");c(this,"_exchangeKey");c(this,"_writeKey");let{keys:r}=e,n=this.constructor;this.DID=e.did,this._exchangeKey=r.exchange,this._writeKey=r.write,this.hasPersisted=e.hasPersisted,this.isSessionOnly=!!e.isSessionOnly,this.destroyed=!1,this.exchangeKeyName=e.exchangeKeyName||n.EXCHANGE_KEY_NAME,this.writeKeyName=e.writeKeyName||n.WRITE_KEY_NAME}get exchangeKey(){if(this.destroyed||!this._exchangeKey)throw new we;return this._exchangeKey}get writeKey(){if(this.destroyed||!this._writeKey)throw new we;return this._writeKey}publicExchangeKeyAsString(e){return this.publicExchangeKey.asString(e)}publicWriteKeyAsString(e){return this.publicWriteKey.asString(e)}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:s(async r=>{let n=await Q(this.writeKey),i=new Uint8Array(n);return r?f(i,r):x(i)},"asString")})}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async r=>{let n=await Q(this.exchangeKey),i=new Uint8Array(n);return r?f(i,r):x(i)},"asString")})}get privateWriteKey(){return this.writeKey.privateKey}get privateExchangeKey(){return this.exchangeKey.privateKey}get deviceName(){return ee.deviceName(this.DID)}static deviceName(e){return oi(e)}async persist(){if(this.destroyed)throw new we;this.isSessionOnly||(await Promise.all([Gr(this.exchangeKeyName,this.exchangeKey),Gr(this.writeKeyName,this.writeKey)]),this.hasPersisted=!0)}async delete(){let e=this.exchangeKeyName,r=this.writeKeyName;await Vr([e,r]),this.constructor._invalidate(e,r),this._destroy()}_destroy(){this.destroyed=!0,this.hasPersisted=!1,this._exchangeKey=null,this._writeKey=null}static _invalidate(e,r){let n=this._instance;n&&n.exchangeKeyName===e&&n.writeKeyName===r&&(n._destroy(),this._instance=null)}static async delete(e={}){let r=e.encryptionKeyName||this.EXCHANGE_KEY_NAME,n=e.writeKeyName||this.WRITE_KEY_NAME;await Vr([r,n]),this._invalidate(r,n)}async getDeviceName(){return ee.deviceName(this.DID)}static _createExchangeKeys(e){throw new Error("The child should implement this")}static _createWriteKeys(e){throw new Error("The child should implement this")}static async create(e,r,n){let i=n?.exchangeKeys||await this._createExchangeKeys(r),o=n?.writeKeys||await this._createWriteKeys(r),a=await Q(o),y=await Me(new Uint8Array(a),this.TYPE==="ecc"?"ed25519":"rsa"),p=new this({keys:{exchange:i,write:o},did:y,hasPersisted:!1,isSessionOnly:!!e});return this._instance=p,p}static async exist(e={}){let r=await Re(e.writeKeyName||this.WRITE_KEY_NAME),n=await Re(e.encryptionKeyName||this.EXCHANGE_KEY_NAME);return!(!r||!n)}static async load(e={session:!1}){let r=e.persist!==!1,n=e.encryptionKeyName||this.EXCHANGE_KEY_NAME,i=e.writeKeyName||this.WRITE_KEY_NAME,o=this._instance;if(o&&!o.destroyed&&o.exchangeKeyName===n&&o.writeKeyName===i)return r&&!o.hasPersisted&&await o.persist(),o;let a=!0,y=await Re(n),p=await Re(i);y||(a=!1,y=await this._createExchangeKeys(e.extractable)),p||(a=!1,p=await this._createWriteKeys(e.extractable));let g=await Q(p),l=await Me(new Uint8Array(g),this.TYPE==="ecc"?"ed25519":"rsa"),d=new this({keys:{exchange:y,write:p},did:l,hasPersisted:a,isSessionOnly:!!e.session,exchangeKeyName:n,writeKeyName:i});return this._instance=d,r&&!a&&await d.persist(),d}};s(ee,"AbstractKeys"),c(ee,"EXCHANGE_KEY_NAME"),c(ee,"WRITE_KEY_NAME"),c(ee,"_instance");var xe=ee;async function Bt(t,e){let{content:r,publicKey:n}=t,i=e||await b.create(),o=await b.encrypt(typeof r=="string"?K(r):r,typeof i=="string"?await b.import(i):i),a=await Wr({key:i,publicKey:n});return j(a,o)}s(Bt,"encryptTo");Bt.asString=async function(t,e){let r=await Bt(t,e);return f(new Uint8Array(r),"base64pad")};async function Wr({key:t,publicKey:e},r){let n;t instanceof CryptoKey?n=await b.export(t):n=t;let i=await W.encrypt(n,e);return r&&r==="arraybuffer"?i:new Uint8Array(i)}s(Wr,"encryptKeyTo");Wr.asString=async function({key:t,publicKey:e},r){let n=await Wr({key:t,publicKey:e});return r?f(n,r):x(n)};async function oi(t){let e=await wt(new TextEncoder().encode(t.normalize("NFD")));return f(e,"base32").slice(0,32)}s(oi,"getDeviceName");var Xr=globalThis.crypto;function vt(t){return new Uint8Array(t).buffer}s(vt,"toArrayBuffer");var ye=class ye extends xe{static async create(e,r,n){return await super.create(e,r,n)}static async _createExchangeKeys(e=!1){return await Rr(We,se,"exchange",e)}static async _createWriteKeys(e=!1){return await Rr(We,se,"write",e)}async toJson(e){let r=this.publicExchangeKey,n=this.DID,i=await Xr.subtle.exportKey("spki",r);return{publicExchangeKey:e?f(new Uint8Array(i),e):x(i),DID:n}}async sign(e,r=O){let n=this.writeKey,i=await W.sign(e,n.privateKey,r);return new Uint8Array(i)}async signAsString(e,r){let n=await this.sign(e,r);return x(n)}async encrypt(e,r,n,i,o){let a=r||this.exchangeKey.publicKey,y=n,p=i,g=y||await b.create({length:p||o}),l=await b.encrypt(typeof e=="string"?K(e):e,typeof g=="string"?await b.import(g):g),d=await Ue({key:g,publicKey:a}),v=j(d,l);return new Uint8Array(v)}async encryptAsString(e,r,n,i,o){let a=await this.encrypt(e,r,n,i,o);return f(a,"base64pad")}async decrypt(e,r,n){let i=(typeof r=="number"?r:void 0)||H,o=oe(e,I),a=o.slice(0,i),y=o.slice(i),p=await this.decryptKey(a);return await b.decrypt(y,p)}async decryptAsString(e,r,n){let i=await this.decrypt(e,r,n);return f(i)}async decryptKey(e){return await W.decrypt(e,this.exchangeKey.privateKey)}async decryptKeyAsString(e,r){let n=await W.decrypt(e,this.exchangeKey.privateKey);return f(n,r)}async getAesKey(e,r){if(!e)throw new Error("RSA requires an encrypted AES key to decrypt");if(typeof e=="string"){let n=await this.decryptKey(e);return await b.import(n)}else return e}};s(ye,"RsaKeys"),c(ye,"TYPE","rsa"),c(ye,"INFO","keys"),c(ye,"EXCHANGE_KEY_NAME",Nr),c(ye,"WRITE_KEY_NAME",kr);var ce=ye;Object.assign(ce.prototype.sign,{asString:s(async function(t,e){return this.signAsString(t,e)},"asString")});Object.assign(ce.prototype.encrypt,{asString:s(async function(t,e,r,n){return this.encryptAsString(t,e,r,n)},"asString")});Object.assign(ce.prototype.decrypt,{asString:s(async function(t,e){return this.decryptAsString(t,e)},"asString")});async function ai(t,e,r){let n=Je(r),i=await Le(n.publicKey.buffer,"SHA-256","signing");try{return W.verify(t,e,i)}catch{return!1}}s(ai,"verify");Object.assign(ce.prototype.decryptKey,{asString:s(async function(t,e){return this.decryptKeyAsString(t,e)},"asString")});async function Tt(t,e){let{content:r,publicKey:n}=t,i=e||await b.create(),o=await b.encrypt(typeof r=="string"?K(r):r,typeof i=="string"?await b.import(i):i),a=await Ue({key:i,publicKey:n});return j(a,o)}s(Tt,"encryptTo");Tt.asString=async function(t,e){let{content:r,publicKey:n}=t,i=e||await b.create(),o=await b.encrypt(typeof r=="string"?K(r):r,typeof i=="string"?await b.import(i):i,"arraybuffer"),a=await Ue({key:i,publicKey:n}),y=j(a,o);return f(new Uint8Array(y),"base64pad")};async function Ue({key:t,publicKey:e},r){let n;t instanceof CryptoKey?n=await b.export(t):n=t;let i=await W.encrypt(n,e);return r&&r==="arraybuffer"?i:new Uint8Array(i)}s(Ue,"encryptKeyTo");Ue.asString=async function({key:t,publicKey:e},r){let n=await Ue({key:t,publicKey:e});return r?f(n,r):x(n)};async function yi(t,e,r,n){let i=Ke(e)?e:await be(e),o=n?await Xr.subtle.encrypt({name:z,iv:vt(n)},i,vt(t)):await ci(t,i);return r&&r==="arraybuffer"?o:new Uint8Array(o)}s(yi,"encrypt");async function ci(t,e,r){let n=Z(t,r?.charsize??O),i=typeof e=="string"?await ke(e,r):e,o=r?.iv||qe(P),a=await Xr.subtle.encrypt({name:z,iv:o},i,n);return j(o,a)}s(ci,"encryptBytes");var It={};S(It,{EccKeys:()=>re,default:()=>pi,exportPublicKey:()=>Se,importPublicKey:()=>Oe,verify:()=>ui});var pe=globalThis.crypto;function ue(t){return new Uint8Array(t).buffer}s(ue,"toArrayBuffer");var B=class B extends xe{static async create(e,r,n){return await super.create(e,r,n)}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async r=>{let n=await Se(this.exchangeKey),i=new Uint8Array(n);return r?f(i,r):x(n)},"asString")})}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:s(async r=>{let n=await Se(this.writeKey),i=new Uint8Array(n);return r?f(i,r):x(n)},"asString")})}static async _createExchangeKeys(e=!1){return await pe.subtle.generateKey({name:Ie},e,["deriveKey","deriveBits"])}static async _createWriteKeys(e=!1){return await pe.subtle.generateKey({name:ie},e,["sign","verify"])}static async load(e={session:!1}){return super.load(e)}async toJson(e){let r=this.DID,n=await Se(this.exchangeKey);return{publicExchangeKey:e?f(new Uint8Array(n),e):x(n),DID:r}}async wrap(e,r,n){let i=await B._createExchangeKeys(!0),o=crypto.getRandomValues(new Uint8Array(E)),a=await Ee(i.privateKey,r,o,n||"key-wrap"),y;if(e instanceof CryptoKey){let T=await crypto.subtle.exportKey("raw",e);y=new Uint8Array(T)}else typeof e=="string"?y=K(e,"base64pad"):y=e;let p=crypto.getRandomValues(new Uint8Array(P)),g=await crypto.subtle.encrypt({name:D,iv:p},a,ue(y)),l=await Se(i),d=new Uint8Array(o),v=new Uint8Array(p),fe=new Uint8Array(g),u=d.length+v.length+fe.length,m=new Uint8Array(u);return m.set(d,0),m.set(v,d.length),m.set(fe,d.length+v.length),{enc:x(new Uint8Array(l)),wrappedKey:x(m)}}async unwrap(e,r,n){let i=await Oe(e,"X25519","exchange"),o=new Uint8Array(I(r)),a=o.slice(0,E),y=o.slice(E,E+P),p=o.slice(E+P),g=await Ee(this.exchangeKey.privateKey,i,a,n||"key-wrap"),l=await crypto.subtle.decrypt({name:D,iv:y},g,ue(p));return await crypto.subtle.importKey("raw",l,{name:D},!0,["encrypt","decrypt"])}async encrypt(e,r,n,i,o){let a=crypto.getRandomValues(new Uint8Array(E)),y=r||this.exchangeKey.publicKey,p;typeof y=="string"?p=await Oe(y,"X25519","exchange"):p=y;let g=await B._createExchangeKeys(!0),l=i||await Ee(g.privateKey,p,a,n||B.INFO,o);l instanceof CryptoKey||(l=await Ee(g.privateKey,p,a,n||B.INFO));let d=crypto.getRandomValues(new Uint8Array(P)),v=typeof e=="string"?new TextEncoder().encode(e):e,fe=await crypto.subtle.encrypt({name:D,iv:d},l,ue(v)),u=new Uint8Array(await Se(g)),m=new Uint8Array(a),T=new Uint8Array(d),C=new Uint8Array(fe),_=u.length+m.length+T.length+C.length,U=new Uint8Array(_);return U.set(u,0),U.set(m,u.length),U.set(T,u.length+m.length),U.set(C,u.length+m.length+T.length),U}async encryptAsString(e,r,n,i,o){let a=await this.encrypt(e,r,n||B.INFO,i,o);return f(new Uint8Array(a),"base64pad")}async decrypt(e,r,n){let i=oe(e,I),o=i.slice(0,$),a=await pe.subtle.importKey("raw",o,{name:Ie},!0,[]),y=i.slice($,$+E),p=i.slice($+E,$+E+P),g=i.slice($+E+P),{privateKey:l}=this.exchangeKey,d=await Ee(l,a,y,n||B.INFO);return await crypto.subtle.decrypt({name:r||D,iv:p},d,g)}async decryptAsString(e,r,n){let i=await this.decrypt(e,r,n);return f(new Uint8Array(i))}async getAesKey(e,r){e||(e=this.publicExchangeKey);let n;typeof e=="string"?n=await Oe(e,"X25519","exchange"):n=e;let i=crypto.getRandomValues(new Uint8Array(E));return await Ee(this.exchangeKey.privateKey,n,i,r||B.INFO)}async sign(e,r){let n=new TextEncoder,i;typeof e=="string"?i=n.encode(e):e instanceof ArrayBuffer?i=new Uint8Array(e):i=e;let o=await pe.subtle.sign({name:ie},this.writeKey.privateKey,ue(i));return new Uint8Array(o)}async signAsString(e,r){let n=await this.sign(e,r);return f(n,"base64pad")}};s(B,"EccKeys"),c(B,"TYPE","ecc"),c(B,"EXCHANGE_KEY_NAME",Lr),c(B,"WRITE_KEY_NAME",Mr),c(B,"INFO","keys");var re=B;Object.assign(re.prototype.sign,{asString:s(async function(t,e){let r=await this.sign(t,e);return f(r,"base64pad")},"asString")});async function Se(t,e="raw"){return await crypto.subtle.exportKey(e,t.publicKey)}s(Se,"exportPublicKey");async function Oe(t,e,r){Pt(r);let n=r==="exchange"?Ie:ie,i=r==="exchange"?[]:["verify"],o=I(t),a=e==="X25519"?{name:n}:{name:n,namedCurve:e};return pe.subtle.importKey("raw",o,a,!0,i)}s(Oe,"importPublicKey");var pi={EccKeys:re,importPublicKey:Oe};Object.assign(re.prototype.encrypt,{asString:s(async function(t,e,r,n,i){return this.encryptAsString(t,e,r,n,i)},"asString")});Object.assign(re.prototype.decrypt,{asString:s(async function(t,e){return this.decryptAsString(t,e)},"asString")});Object.assign(re.prototype.sign,{asString:s(async function(t,e){return this.signAsString(t,e)},"asString")});async function ui(t,e,r){try{let n=Je(r);if(n.type!=="ed25519")throw new Error(`Expected Ed25519 key for ECC verification, got ${n.type}`);let i=n.publicKey.slice(-32),o=await pe.subtle.importKey("raw",i,{name:ie},!0,["verify"]),a=new TextEncoder,y;typeof t=="string"?y=a.encode(t):t instanceof ArrayBuffer?y=new Uint8Array(t):y=t;let p;return typeof e=="string"?p=new Uint8Array(I(e)):p=e,await pe.subtle.verify({name:ie},o,ue(p),ue(y))}catch{return!1}}s(ui,"verify");async function Ee(t,e,r,n,i){let o=new TextEncoder,a=await crypto.subtle.deriveBits({name:"X25519",public:e},t,256),y=await crypto.subtle.importKey("raw",a,"HKDF",!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:r instanceof Uint8Array?ue(r):r,info:o.encode(n)},y,{name:"AES-GCM",length:i||H},!1,["encrypt","decrypt"])}s(Ee,"deriveKey");export{z as AES_GCM,xe as AbstractKeys,V as BASE58_DID_PREFIX,Xe as BLS_DID_PREFIX,ir as CharSize,Jr as CryptoSystem,O as DEFAULT_CHAR_SIZE,Lr as DEFAULT_ECC_EXCHANGE,Gn as DEFAULT_ECC_EXCHANGE_CURVE,Mr as DEFAULT_ECC_WRITE,se as DEFAULT_HASH_ALGORITHM,Nr as DEFAULT_RSA_EXCHANGE,We as DEFAULT_RSA_SIZE,kr as DEFAULT_RSA_WRITE,D as DEFAULT_SYMM_ALGORITHM,H as DEFAULT_SYMM_LENGTH,Ie as ECC_EXCHANGE_ALGORITHM,ie as ECC_WRITE_ALGORITHM,Ye as EDWARDS_DID_PREFIX,nr as EccCurve,tr as HashAlg,P as IV_LENGTH,_e as KEY_TYPE,Kt as KEY_USE,te as KeyUse,we as KeysDeletedError,J as RSA_ALGORITHM,je as RSA_DID_PREFIX,Ve as RSA_HASHING_ALGORITHM,q as RSA_SIGN_ALGORITHM,Yr as RsaSize,E as SALT_LENGTH,$r as SymmKeyLength,$ as X25519_PUBLIC_KEY_LENGTH,Ct as aes,qn as checkValidKeyUse,Ze as did,Qe as didToPublicKey,It as ecc,Ut as ed25519Verify,Wr as encryptKeyTo,Bt as encryptTo,Jn as getAlgorithm,oi as getDeviceName,Q as getPublicKeyAsArrayBuffer,zr as getPublicKeyAsUint8Array,ei as importRsaKey,Ke as isCryptoKey,co as keyTypeFromDid,Me as publicKeyToDid,Dt as rsa,Le as rsaImportPublicKey,W as rsaOperations,Et as rsaVerify,yo as verify};
4
4
  //# sourceMappingURL=index.min.js.map