@substrate-system/keys 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 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-----
1
+ var sr=Object.defineProperty;var Nt=(t,e,r)=>e in t?sr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var s=(t,e)=>sr(t,"name",{value:e,configurable:!0});var C=(t,e)=>{for(var r in e)sr(t,r,{get:e[r],enumerable:!0})};var y=(t,e,r)=>Nt(t,typeof e!="symbol"?e+"":e,r);var $r=(n=>(n[n.B1024=1024]="B1024",n[n.B2048=2048]="B2048",n[n.B4096=4096]="B4096",n))($r||{}),jr=(n=>(n[n.B128=128]="B128",n[n.B192=192]="B192",n[n.B256=256]="B256",n))(jr||{}),qr=(r=>(r.ECC="ecc",r.RSA="rsa",r))(qr||{}),or=(i=>(i.SHA_1="SHA-1",i.SHA_256="SHA-256",i.SHA_384="SHA-384",i.SHA_512="SHA-512",i))(or||{}),ar=(i=>(i.P_256="P-256",i.P_384="P-384",i.P_521="P-521",i.X25519="X25519",i))(ar||{}),ne=(n=>(n.Sign="signing",n.Exchange="exchange",n.Write="write",n))(ne||{}),yr=(r=>(r[r.B8=8]="B8",r[r.B16=16]="B16",r))(yr||{});var It={};C(It,{AES_GCM:()=>H,BASE58_DID_PREFIX:()=>Y,BLS_DID_PREFIX:()=>Je,DEFAULT_CHAR_SIZE:()=>z,DEFAULT_ECC_EXCHANGE:()=>Me,DEFAULT_ECC_EXCHANGE_CURVE:()=>Wn,DEFAULT_ECC_WRITE:()=>ke,DEFAULT_HASH_ALGORITHM:()=>se,DEFAULT_RSA_EXCHANGE:()=>Ne,DEFAULT_RSA_SIZE:()=>qe,DEFAULT_RSA_WRITE:()=>Le,DEFAULT_SYMM_ALGORITHM:()=>D,DEFAULT_SYMM_LENGTH:()=>G,ECC_EXCHANGE_ALGORITHM:()=>Ie,ECC_WRITE_ALGORITHM:()=>ie,EDWARDS_DID_PREFIX:()=>Ze,IV_LENGTH:()=>B,KEY_TYPE:()=>_e,KEY_USE:()=>bt,RSA_ALGORITHM:()=>J,RSA_DID_PREFIX:()=>je,RSA_HASHING_ALGORITHM:()=>$e,RSA_SIGN_ALGORITHM:()=>Z,RsaKeys:()=>ye,SALT_LENGTH:()=>S,X25519_PUBLIC_KEY_LENGTH:()=>q,encrypt:()=>ui,encryptKeyTo:()=>Ee,encryptTo:()=>Dt,getPublicKeyAsArrayBuffer:()=>ee,getPublicKeyAsUint8Array:()=>zr,publicKeyToDid:()=>He,verify:()=>pi});function Ce(t=0){return new Uint8Array(t)}s(Ce,"allocUnsafe");function cr(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(cr,"concat");var Ar={};C(Ar,{base10:()=>Gt});var _i=new Uint8Array(0);function Jr(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(Jr,"equals");function V(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(V,"coerce");function Zr(t){return new TextEncoder().encode(t)}s(Zr,"fromString");function Qr(t){return new TextDecoder().decode(t)}s(Qr,"toString");function Mt(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 c=t.length,p=t.charAt(0),l=Math.log(c)/Math.log(256),K=Math.log(256)/Math.log(c);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 g=0,T=0,P=0,_=u.length;P!==_&&u[P]===0;)P++,g++;for(var U=(_-P)*K+1>>>0,N=new Uint8Array(U);P!==_;){for(var R=u[P],$=0,M=U-1;(R!==0||$<T)&&M!==-1;M--,$++)R+=256*N[M]>>>0,N[M]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");T=$,P++}for(var F=U-T;F!==U&&N[F]===0;)F++;for(var Ve=p.repeat(g);F<U;++F)Ve+=t.charAt(N[F]);return Ve}s(b,"encode");function v(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var g=0;if(u[g]!==" "){for(var T=0,P=0;u[g]===p;)T++,g++;for(var _=(u.length-g)*l+1>>>0,U=new Uint8Array(_);u[g];){var N=r[u.charCodeAt(g)];if(N===255)return;for(var R=0,$=_-1;(N!==0||R<P)&&$!==-1;$--,R++)N+=c*U[$]>>>0,U[$]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");P=R,g++}if(u[g]!==" "){for(var M=_-P;M!==_&&U[M]===0;)M++;for(var F=new Uint8Array(T+(_-M)),Ve=T;M!==_;)F[Ve++]=U[M++];return F}}}s(v,"decodeUnsafe");function ue(u){var g=v(u);if(g)return g;throw new Error(`Non-${e} character`)}return s(ue,"decode"),{encode:b,decodeUnsafe:v,decode:ue}}s(Mt,"base");var kt=Mt,Rt=kt,rt=Rt;var gr=class gr{constructor(e,r,n){y(this,"name");y(this,"prefix");y(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(gr,"Encoder");var pr=gr,mr=class mr{constructor(e,r,n){y(this,"name");y(this,"prefix");y(this,"baseDecode");y(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(mr,"Decoder");var ur=mr,hr=class hr{constructor(e){y(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(hr,"ComposedDecoder");var fr=hr;function tt(t,e){return new fr({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}s(tt,"or");var dr=class dr{constructor(e,r,n,i){y(this,"name");y(this,"prefix");y(this,"baseEncode");y(this,"baseDecode");y(this,"encoder");y(this,"decoder");this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new pr(e,r,n),this.decoder=new ur(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};s(dr,"Codec");var lr=dr;function fe({name:t,prefix:e,encode:r,decode:n}){return new lr(t,e,r,n)}s(fe,"from");function j({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=rt(r,t);return fe({prefix:e,name:t,encode:n,decode:s(o=>V(i(o)),"decode")})}s(j,"baseX");function Ot(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let o=new Uint8Array(i*r/8|0),a=0,c=0,p=0;for(let l=0;l<i;++l){let K=e[t[l]];if(K===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|K,a+=r,a>=8&&(a-=8,o[p++]=255&c>>a)}if(a>=r||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return o}s(Ot,"decode");function zt(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",a=0,c=0;for(let p=0;p<t.length;++p)for(c=c<<8|t[p],a+=8;a>r;)a-=r,o+=e[i&c>>a];if(a!==0&&(o+=e[i&c<<r-a]),n)for(;(o.length*r&7)!==0;)o+="=";return o}s(zt,"encode");function Ht(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}s(Ht,"createAlphabetIdx");function h({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let i=Ht(n);return fe({prefix:e,name:t,encode(o){return zt(o,n,r)},decode(o){return Ot(o,i,r,t)}})}s(h,"rfc4648");var Gt=j({prefix:"9",name:"base10",alphabet:"0123456789"});var Kr={};C(Kr,{base16:()=>Ft,base16upper:()=>Vt});var Ft=h({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Vt=h({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var br={};C(br,{base2:()=>Yt});var Yt=h({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var wr={};C(wr,{base256emoji:()=>qt});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}"),Wt=nt.reduce((t,e,r)=>(t[r]=e,t),[]),Xt=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 $t(t){return t.reduce((e,r)=>(e+=Wt[r],e),"")}s($t,"encode");function jt(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=Xt[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}s(jt,"decode");var qt=fe({prefix:"\u{1F680}",name:"base256emoji",encode:$t,decode:jt});var xr={};C(xr,{base32:()=>le,base32hex:()=>en,base32hexpad:()=>tn,base32hexpadupper:()=>nn,base32hexupper:()=>rn,base32pad:()=>Zt,base32padupper:()=>Qt,base32upper:()=>Jt,base32z:()=>sn});var le=h({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Jt=h({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Zt=h({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Qt=h({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),en=h({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),rn=h({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tn=h({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),nn=h({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),sn=h({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Er={};C(Er,{base36:()=>Pe,base36upper:()=>on});var Pe=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),on=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ur={};C(Ur,{base58btc:()=>O,base58flickr:()=>an});var O=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),an=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Sr={};C(Sr,{base64:()=>yn,base64pad:()=>cn,base64url:()=>pn,base64urlpad:()=>un});var yn=h({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),cn=h({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),pn=h({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),un=h({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Cr={};C(Cr,{base8:()=>fn});var fn=h({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Pr={};C(Pr,{identity:()=>ln});var ln=fe({prefix:"\0",name:"identity",encode:s(t=>Qr(t),"encode"),decode:s(t=>Zr(t),"decode")});var es=new TextEncoder,rs=new TextDecoder;var Tr={};C(Tr,{identity:()=>Mn});var hn=ot,it=128,dn=127,An=~dn,Kn=Math.pow(2,31);function ot(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Kn;)e[r++]=t&255|it,t/=128;for(;t&An;)e[r++]=t&255|it,t>>>=7;return e[r]=t|0,ot.bytes=r-n+1,e}s(ot,"encode");var bn=Br,wn=128,st=127;function Br(t,n){var r=0,n=n||0,i=0,o=n,a,c=t.length;do{if(o>=c)throw Br.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>=wn);return Br.bytes=o-n,r}s(Br,"read");var xn=Math.pow(2,7),En=Math.pow(2,14),Un=Math.pow(2,21),Sn=Math.pow(2,28),Cn=Math.pow(2,35),Pn=Math.pow(2,42),Bn=Math.pow(2,49),vn=Math.pow(2,56),Tn=Math.pow(2,63),Dn=s(function(t){return t<xn?1:t<En?2:t<Un?3:t<Sn?4:t<Cn?5:t<Pn?6:t<Bn?7:t<vn?8:t<Tn?9:10},"length"),In={encode:hn,decode:bn,encodingLength:Dn},_n=In,Be=_n;function ve(t,e=0){return[Be.decode(t,e),Be.decode.bytes]}s(ve,"decode");function ge(t,e,r=0){return Be.encode(t,e,r),e}s(ge,"encodeTo");function me(t){return Be.encodingLength(t)}s(me,"encodingLength");function de(t,e){let r=e.byteLength,n=me(t),i=n+me(r),o=new Uint8Array(i+r);return ge(t,o,0),ge(r,o,n),o.set(e,i),new he(t,r,e,o)}s(de,"create");function at(t){let e=V(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&&Jr(t.bytes,r.bytes)}}s(yt,"equals");var vr=class vr{constructor(e,r,n,i){y(this,"code");y(this,"size");y(this,"digest");y(this,"bytes");this.code=e,this.size=r,this.digest=n,this.bytes=i}};s(vr,"Digest");var he=vr;var ct=0,Nn="identity",pt=V;function Ln(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return de(ct,pt(t))}s(Ln,"digest");var Mn={code:ct,name:Nn,encode:pt,digest:Ln};var Nr={};C(Nr,{sha256:()=>Rn,sha512:()=>On});var kn=20;function Ir({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:i}){return new Dr(t,e,r,n,i)}s(Ir,"from");var _r=class _r{constructor(e,r,n,i,o){y(this,"name");y(this,"code");y(this,"encode");y(this,"minDigestLength");y(this,"maxDigestLength");this.name=e,this.code=r,this.encode=n,this.minDigestLength=i??kn,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ut(n,this.code,r?.truncate):n.then(i=>ut(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};s(_r,"Hasher");var Dr=_r;function ut(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return de(e,t)}s(ut,"createDigest");function lt(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}s(lt,"sha");var Rn=Ir({name:"sha2-256",code:18,encode:lt("SHA-256")}),On=Ir({name:"sha2-512",code:19,encode:lt("SHA-512")});function gt(t,e){let{bytes:r,version:n}=t;return n===0?Hn(r,Lr(t),e??O.encoder):Gn(r,Lr(t),e??le.encoder)}s(gt,"format");var mt=new WeakMap;function Lr(t){let e=mt.get(t);if(e==null){let r=new Map;return mt.set(t,r),r}return e}s(Lr,"baseCache");var dt,w=class w{constructor(e,r,n,i){y(this,"code");y(this,"version");y(this,"multihash");y(this,"bytes");y(this,"/");y(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!==Fn)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=de(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 gt(this,e)}toJSON(){return{"/":gt(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??ht(n,i,o.bytes))}else if(r[Vn]===!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=ht(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=V(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,c=n(),p=n(),l=r+p,K=l-a;return{version:i,codec:o,multihashCode:c,digestSize:p,multihashSize:K,size:l}}static parse(e,r){let[n,i]=zn(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 Lr(o).set(n,e),o}};s(w,"CID");var We=w;function zn(t,e){switch(t[0]){case"Q":{let r=e??O;return[O.prefix,r.decode(`${O.prefix}${t}`)]}case O.prefix:{let r=e??O;return[O.prefix,r.decode(t)]}case le.prefix:{let r=e??le;return[le.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(zn,"parseCIDtoBytes");function Hn(t,e,r){let{prefix:n}=r;if(n!==O.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(Hn,"toStringV0");function Gn(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(Gn,"toStringV1");var De=112,Fn=18;function ht(t,e,r){let n=me(t),i=n+me(e),o=new Uint8Array(i+r.byteLength);return ge(t,o,0),ge(e,o,n),o.set(r,i),o}s(ht,"encodeCID");var Vn=Symbol.for("@ipld/js-cid/CID");var Mr={...Pr,...br,...Cr,...Ar,...Kr,...xr,...Er,...Ur,...Sr,...wr},Is={...Nr,...Tr};function Kt(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}s(Kt,"createCodec");var At=Kt("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),kr=Kt("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}),Yn={utf8:At,"utf-8":At,hex:Mr.base16,latin1:kr,ascii:kr,binary:kr,...Mr},Xe=Yn;function d(t,e="utf8"){let r=Xe[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}s(d,"fromString");function f(t,e="utf8"){let r=Xe[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}s(f,"toString");var Pt={};C(Pt,{AES:()=>A,decryptBytes:()=>Ct,importAesKey:()=>be});var Y="did:key:z",ie="Ed25519",Ie="X25519",Wn="X25519",q=32,bt={sign:["sign","verify"],encrypt:["deriveKey","deriveBits"]},J="RSA-OAEP",Z="RSASSA-PKCS1-v1_5",$e="SHA-256",je=new Uint8Array([0,245,2]),qe=2048,se="SHA-256",z=8,H="AES-GCM",D=H,G=256,B=12,Je=new Uint8Array([234,1]),Ze=new Uint8Array([237,1]),_e={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"},Ne="rsa-exchange-key",Le="rsa-write-key",Me="ecc-exchange",ke="ecc-write",S=16;var Re=globalThis.crypto,wt=new Error("Invalid key use. Please use 'encryption' or 'signing"),Xn=new Error("Max must be less than 256 and greater than 0");function m(t){return new Uint8Array(t).buffer}s(m,"toArrayBuffer");async function xt(t){return new Uint8Array(await Re.subtle.digest("sha-256",t.buffer))}s(xt,"sha256");function I(t){let e=d(t,"base64pad");return m(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 Qe(t){return oe(t,I)}s(Qe,"normalizeBase64ToBuf");var $n=s(t=>oe(t,e=>Et(e,8)),"normalizeUtf8ToBuf");function Et(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(Et,"strToArrBuf");var jn=s(t=>oe(t,e=>Et(e,16)),"normalizeUtf16ToBuf");function Q(t,e){return e===8?$n(t):jn(t)}s(Q,"normalizeUnicodeToBuf");function er(t){if(!t.startsWith(Y))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+t.substring(Y.length),r=d(e,"base58btc"),{keyBuffer:n,type:i}=qn(m(r));return{publicKey:new Uint8Array(n),type:i}}s(er,"didToPublicKey");function qn(t){if(Ae(t,m(je)))return{keyBuffer:t.slice(je.byteLength),type:_e.RSA};if(Ae(t,m(Ze)))return{keyBuffer:t.slice(Ze.byteLength),type:_e.Edwards};if(Ae(t,m(Je)))return{keyBuffer:t.slice(Je.byteLength),type:_e.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}s(qn,"parseMagicBytes");var Jn={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 Jn.equal(e,t.slice(0,e.byteLength))}s(Ae,"hasPrefix");function E(t){return f(t instanceof ArrayBuffer?new Uint8Array(t):t,"base64pad")}s(E,"toBase64");async function Oe(t,e){let r=typeof t=="string"?I(t):m(t);return Re.subtle.importKey("raw",r,{name:e?.alg||D,length:e?.length||G},!0,["encrypt","decrypt"])}s(Oe,"importKey");function rr(t,{max:e}={max:255}){if(e<1||e>255)throw Xn;let r=new Uint8Array(t);if(e===255)return Re.getRandomValues(r),r.buffer;let n=0,i=e+1,o=Math.floor(256/i)*i,a=new Uint8Array(1);for(;n<r.length;)Re.getRandomValues(a),a[0]<o&&(r[n]=a[0]%i,n++);return r.buffer}s(rr,"randomBuf");function W(t,e){let r=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(m(t)),n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(m(e)),i=new Uint8Array(r.length+n.length);return i.set(r),i.set(n,r.length),i.buffer}s(W,"joinBufs");async function Rr(t,e,r,n=!1){let i=n;if(!Object.values(ne).includes(r))throw new Error("invalid key use");let o=r==="exchange"?J:Z,a=r==="exchange"?["encrypt","decrypt"]:["sign","verify"];return Re.subtle.generateKey({name:o,modulusLength:t,publicExponent:Zn(),hash:{name:e}},i,a)}s(Rr,"makeRSAKeypair");function Zn(){return new Uint8Array([1,0,1])}s(Zn,"publicExponent");var L=globalThis.crypto,tr={keyTypes:{"bls12-381":{magicBytes:new Uint8Array([234,1]),verify:s(()=>{throw new Error("Not implemented")},"verify")},rsa:{magicBytes:new Uint8Array([0,245,2]),verify:St},ed25519:{magicBytes:new Uint8Array([237,1]),verify:Ut}}};async function uo({message:t,did:e,signature:r}){let n=Qn(e),i=nr(e).publicKey;if(n==="ed25519")return Ut({message:t,publicKey:i,signature:r});if(n==="rsa")return St({message:t,publicKey:i,signature:r});throw new Error("Unknown key format")}s(uo,"verify");function Qn(t){try{let{type:e}=nr(t);return e}catch{return"unknown"}}s(Qn,"getAlgorithm");async function Ut({message:t,publicKey:e,signature:r}){let n=t;typeof t=="string"&&(n=d(t,"utf8"));let i=r;typeof r=="string"&&(i=d(r,"base64pad"));let o=e;if(typeof e=="string"&&(o=nr(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 L.subtle.importKey("raw",m(o),{name:"Ed25519"},!1,["verify"]);return L.subtle.verify({name:"Ed25519"},a,m(i),m(n))}s(Ut,"ed25519Verify");async function St({message:t,publicKey:e,signature:r}){let n=e;return typeof e=="string"&&(n=nr(e).publicKey),X.verify(t,r,await L.subtle.importKey("spki",m(n),{name:Z,hash:$e},!1,["verify"]),8)}s(St,"rsaVerify");var X={verify:s(async function(e,r,n,i=z,o=se){return L.subtle.verify({name:Z,saltLength:S},typeof n=="string"?await ze(n,o,"signing"):n,Qe(r),Q(e,i))},"rsaVerify"),sign:s(async function(e,r,n=z){return L.subtle.sign({name:Z,saltLength:S},r,Q(e,n))},"sign"),encrypt:s(async function(e,r,n=z,i=se){let o;return typeof r=="string"?o=await ze(r,i,"exchange"):o=r instanceof Uint8Array?await ze(m(r),i,"exchange"):r,L.subtle.encrypt({name:J},o,Q(e,n))},"rsaEncrypt"),decrypt:s(async function(e,r){let n=Ke(r)?r:await ni(r,["decrypt"]),i;typeof e=="string"?i=d(e,"base64pad"):i=e;let o=await L.subtle.decrypt({name:J},n,i instanceof Uint8Array?m(i):i);return new Uint8Array(o)},"rsaDecrypt")};async function ze(t,e,r){ei(r);let n=r==="exchange"?J:Z,i=r==="exchange"?["encrypt"]:["verify"],o=typeof t=="string"?I(ti(t)):t;return L.subtle.importKey("spki",o,{name:n,hash:{name:e}},!0,i)}s(ze,"rsaImportPublicKey");function ei(t){ri(t,["signing","exchange"],wt)}s(ei,"checkValidKeyUse");function ri(t,e,r){if(!e.some(i=>i===t))throw r}s(ri,"checkValid");function ti(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?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};
3
+ -----END PUBLIC KEY-----`,"")}s(ti,"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 ni(t,e){return L.subtle.importKey("spki",t instanceof Uint8Array?m(t):t,{name:J,hash:$e},!1,e)}s(ni,"importRsaKey");async function He(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 L.subtle.exportKey(o,t);r=new Uint8Array(a)}else r=t;let n=tr.keyTypes[e]?.magicBytes;if(!n)throw new Error(`Key type '${e}' not supported, available types: ${Object.keys(tr.keyTypes).join(", ")}`);let i=cr([n,r]);return Y+f(i,"base58btc")}s(He,"publicKeyToDid");function fo(t){let e=t.substring(Y.length),r=d(e,"base58btc"),n=Object.entries(tr.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(fo,"keyTypeFromDid");async function ee(t){return t instanceof CryptoKey?await L.subtle.exportKey("spki",t):await L.subtle.exportKey("spki",t.publicKey)}s(ee,"getPublicKeyAsArrayBuffer");async function zr(t){let e=await ee(t);return new Uint8Array(e)}s(zr,"getPublicKeyAsUint8Array");function nr(t){if(!t.startsWith(Y))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=t.substring(Y.length),r=d(e,"base58btc"),n=Object.entries(tr.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(nr,"didToPublicKey");var ae=globalThis.crypto,A={create(t={alg:D,length:G}){let e=t.length||G,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 A.export(t);return e?f(r,e):E(r)},"asString")}),import(t){return be(typeof t=="string"?I(t):t)},async exportAsString(t){let e=await A.export(t);return E(e)},encrypt:ii,async decrypt(t,e,r){let n=Ke(e)?e:await be(e),i=r?await ae.subtle.decrypt({name:H,iv:m(r)},n,typeof t=="string"?m(d(t)):t instanceof Uint8Array?m(t):t):await Ct(t,n);return new Uint8Array(i)}};function be(t,e){return ae.subtle.importKey("raw",t instanceof Uint8Array?m(t):t,{name:H,length:e||256},!0,["encrypt","decrypt"])}s(be,"importAesKey");async function ii(t,e,r,n){let i=Ke(e)?e:await be(e),o=n?await ae.subtle.encrypt({name:H,iv:m(n)},i,t instanceof ArrayBuffer?t:m(typeof t=="string"?d(t):t)):await si(t,i);return r&&r==="arraybuffer"?o:new Uint8Array(o)}s(ii,"encrypt");async function si(t,e,r){let n=Q(t,r?.charsize??z),i=typeof e=="string"?await Oe(e,r):e,o=r?.iv||rr(B),a=await ae.subtle.encrypt({name:H,iv:o},i,n);return W(o,a)}s(si,"encryptBytes");async function Ct(t,e,r){let n=Qe(t),i=typeof e=="string"?await Oe(e,r):e,o=n.slice(0,B),a=n.slice(B);return await ae.subtle.decrypt({name:D,iv:o},i,a)}s(Ct,"decryptBytes");function ir(t){return new Promise((e,r)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>r(t.error)})}s(ir,"promisifyRequest");function oi(t,e){let r,n=s(()=>{if(r)return r;let i=indexedDB.open(t);return i.onupgradeneeded=()=>i.result.createObjectStore(e),r=ir(i),r.then(o=>{o.onclose=()=>r=void 0},()=>{r=void 0}),r},"getDB");return(i,o)=>n().then(a=>o(a.transaction(e,i).objectStore(e)))}s(oi,"createStore");var Hr;function Gr(){return Hr||(Hr=oi("keyval-store","keyval")),Hr}s(Gr,"defaultGetStore");function Ge(t,e=Gr()){return e("readonly",r=>ir(r.get(t)))}s(Ge,"get");function Fr(t,e,r=Gr()){return r("readwrite",n=>(n.put(e,t),ir(n.transaction)))}s(Fr,"set");function Vr(t,e=Gr()){return e("readwrite",r=>(t.forEach(n=>r.delete(n)),ir(r.transaction)))}s(Vr,"delMany");var So=new Error("Key does not exist. Make sure you properly instantiated the keystore."),Co=new Error("Retrieved a symmetric key when an asymmetric keypair was expected. Please use a different key name."),Po=new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name."),Bo=new Error("ECC is not enabled for this browser. Please use RSA instead."),vo=new Error("Cryptosystem not supported. Please use ECC or RSA"),ai=new Error("Invalid key use. Please use 'exchange' or 'write'"),To=new Error("Max must be less than 256 and greater than 0"),Yr=class Yr extends Error{constructor(e){super(e||"These keys were deleted"),this.name="KeysDeletedError"}};s(Yr,"KeysDeletedError");var we=Yr;function Bt(t){yi(t,["exchange","write","signing"],ai)}s(Bt,"checkValidKeyUse");function yi(t,e,r){if(!e.some(i=>i===t))throw r}s(yi,"checkValid");var re=class re{constructor(e){y(this,"DID");y(this,"hasPersisted");y(this,"isSessionOnly");y(this,"destroyed");y(this,"exchangeKeyName");y(this,"writeKeyName");y(this,"_exchangeKey");y(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 ee(this.writeKey),i=new Uint8Array(n);return r?f(i,r):E(i)},"asString")})}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async r=>{let n=await ee(this.exchangeKey),i=new Uint8Array(n);return r?f(i,r):E(i)},"asString")})}get privateWriteKey(){return this.writeKey.privateKey}get privateExchangeKey(){return this.exchangeKey.privateKey}get deviceName(){return re.deviceName(this.DID)}static deviceName(e){return ci(e)}async persist(){if(this.destroyed)throw new we;this.isSessionOnly||(await Promise.all([Fr(this.exchangeKeyName,this.exchangeKey),Fr(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 re.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 ee(o),c=await He(new Uint8Array(a),this.TYPE==="ecc"?"ed25519":"rsa"),p=new this({keys:{exchange:i,write:o},did:c,hasPersisted:!1,isSessionOnly:!!e});return this._instance=p,p}static async exist(e={}){let r=await Ge(e.writeKeyName||this.WRITE_KEY_NAME),n=await Ge(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,c=await Ge(n),p=await Ge(i);c||(a=!1,c=await this._createExchangeKeys(e.extractable)),p||(a=!1,p=await this._createWriteKeys(e.extractable));let l=await ee(p),K=await He(new Uint8Array(l),this.TYPE==="ecc"?"ed25519":"rsa"),b=new this({keys:{exchange:c,write:p},did:K,hasPersisted:a,isSessionOnly:!!e.session,exchangeKeyName:n,writeKeyName:i});return this._instance=b,r&&!a&&await b.persist(),b}};s(re,"AbstractKeys"),y(re,"EXCHANGE_KEY_NAME"),y(re,"WRITE_KEY_NAME"),y(re,"_instance");var xe=re;async function vt(t,e){let{content:r,publicKey:n}=t,i=e||await A.create(),o=await A.encrypt(typeof r=="string"?d(r):r,typeof i=="string"?await A.import(i):i),a=await Wr({key:i,publicKey:n});return W(a,o)}s(vt,"encryptTo");vt.asString=async function(t,e){let r=await vt(t,e);return f(new Uint8Array(r),"base64pad")};async function Wr({key:t,publicKey:e},r){let n;t instanceof CryptoKey?n=await A.export(t):n=t;let i=await X.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):E(n)};async function ci(t){let e=await xt(new TextEncoder().encode(t.normalize("NFD")));return f(e,"base32").slice(0,32)}s(ci,"getDeviceName");var Xr=globalThis.crypto;function Tt(t){return new Uint8Array(t).buffer}s(Tt,"toArrayBuffer");var k=class k extends xe{static async create(e,r,n){if(n?.dbKey){let i=`${n.dbKey}.${Ne}`,o=`${n.dbKey}.${Le}`;k.EXCHANGE_KEY_NAME=i,k.WRITE_KEY_NAME=o}return await super.create(e,r,n)}static async load(e={session:!1}){if(e.dbKey){let r=`${e.dbKey}.${Ne}`,n=`${e.dbKey}.${Le}`;k.EXCHANGE_KEY_NAME=r,k.WRITE_KEY_NAME=n}return super.load(e)}static async _createExchangeKeys(e=!1){return await Rr(qe,se,"exchange",e)}static async _createWriteKeys(e=!1){return await Rr(qe,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):E(i),DID:n}}async sign(e,r=z){let n=this.writeKey,i=await X.sign(e,n.privateKey,r);return new Uint8Array(i)}async signAsString(e,r){let n=await this.sign(e,r);return E(n)}async encrypt(e,r,n,i,o){let a=r||this.exchangeKey.publicKey,c=n,p=i,l=c||await A.create({length:p||o}),K=await A.encrypt(typeof e=="string"?d(e):e,typeof l=="string"?await A.import(l):l),b=await Ee({key:l,publicKey:a}),v=W(b,K);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)||G,o=oe(e,I),a=o.slice(0,i),c=o.slice(i),p=await this.decryptKey(a);return await A.decrypt(c,p)}async decryptAsString(e,r,n){let i=await this.decrypt(e,r,n);return f(i)}async decryptKey(e){return await X.decrypt(e,this.exchangeKey.privateKey)}async decryptKeyAsString(e,r){let n=await X.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 A.import(n)}else return e}};s(k,"RsaKeys"),y(k,"TYPE","rsa"),y(k,"INFO","keys"),y(k,"EXCHANGE_KEY_NAME",Ne),y(k,"WRITE_KEY_NAME",Le);var ye=k;Object.assign(ye.prototype.sign,{asString:s(async function(t,e){return this.signAsString(t,e)},"asString")});Object.assign(ye.prototype.encrypt,{asString:s(async function(t,e,r,n){return this.encryptAsString(t,e,r,n)},"asString")});Object.assign(ye.prototype.decrypt,{asString:s(async function(t,e){return this.decryptAsString(t,e)},"asString")});async function pi(t,e,r){let n=er(r),i=await ze(n.publicKey.buffer,"SHA-256","signing");try{return X.verify(t,e,i)}catch{return!1}}s(pi,"verify");Object.assign(ye.prototype.decryptKey,{asString:s(async function(t,e){return this.decryptKeyAsString(t,e)},"asString")});async function Dt(t,e){let{content:r,publicKey:n}=t,i=e||await A.create(),o=await A.encrypt(typeof r=="string"?d(r):r,typeof i=="string"?await A.import(i):i),a=await Ee({key:i,publicKey:n});return W(a,o)}s(Dt,"encryptTo");Dt.asString=async function(t,e){let{content:r,publicKey:n}=t,i=e||await A.create(),o=await A.encrypt(typeof r=="string"?d(r):r,typeof i=="string"?await A.import(i):i,"arraybuffer"),a=await Ee({key:i,publicKey:n}),c=W(a,o);return f(new Uint8Array(c),"base64pad")};async function Ee({key:t,publicKey:e},r){let n;t instanceof CryptoKey?n=await A.export(t):n=t;let i=await X.encrypt(n,e);return r&&r==="arraybuffer"?i:new Uint8Array(i)}s(Ee,"encryptKeyTo");Ee.asString=async function({key:t,publicKey:e},r){let n=await Ee({key:t,publicKey:e});return r?f(n,r):E(n)};async function ui(t,e,r,n){let i=Ke(e)?e:await be(e),o=n?await Xr.subtle.encrypt({name:H,iv:Tt(n)},i,Tt(t)):await fi(t,i);return r&&r==="arraybuffer"?o:new Uint8Array(o)}s(ui,"encrypt");async function fi(t,e,r){let n=Q(t,r?.charsize??z),i=typeof e=="string"?await Oe(e,r):e,o=r?.iv||rr(B),a=await Xr.subtle.encrypt({name:H,iv:o},i,n);return W(o,a)}s(fi,"encryptBytes");var _t={};C(_t,{EccKeys:()=>te,default:()=>li,exportPublicKey:()=>Se,importPublicKey:()=>Fe,verify:()=>gi});var ce=globalThis.crypto;function pe(t){return new Uint8Array(t).buffer}s(pe,"toArrayBuffer");var x=class x extends xe{static async create(e,r,n){if(n?.dbKey){let i=`${n.dbKey}.${Me}`,o=`${n.dbKey}.${ke}`;x.EXCHANGE_KEY_NAME=i,x.WRITE_KEY_NAME=o}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):E(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):E(n)},"asString")})}static async _createExchangeKeys(e=!1){return await ce.subtle.generateKey({name:Ie},e,["deriveKey","deriveBits"])}static async _createWriteKeys(e=!1){return await ce.subtle.generateKey({name:ie},e,["sign","verify"])}static async load(e={session:!1}){if(e.dbKey){let r=`${e.dbKey}.${Me}`,n=`${e.dbKey}.${ke}`;x.EXCHANGE_KEY_NAME=r,x.WRITE_KEY_NAME=n}return super.load(e)}async toJson(e){let r=this.DID,n=await Se(this.exchangeKey);return{publicExchangeKey:e?f(new Uint8Array(n),e):E(n),DID:r}}async wrap(e,r,n){let i=await x._createExchangeKeys(!0),o=crypto.getRandomValues(new Uint8Array(S)),a=await Ue(i.privateKey,r,o,n||"key-wrap"),c;if(e instanceof CryptoKey){let T=await crypto.subtle.exportKey("raw",e);c=new Uint8Array(T)}else typeof e=="string"?c=d(e,"base64pad"):c=e;let p=crypto.getRandomValues(new Uint8Array(B)),l=await crypto.subtle.encrypt({name:D,iv:p},a,pe(c)),K=await Se(i),b=new Uint8Array(o),v=new Uint8Array(p),ue=new Uint8Array(l),u=b.length+v.length+ue.length,g=new Uint8Array(u);return g.set(b,0),g.set(v,b.length),g.set(ue,b.length+v.length),{enc:E(new Uint8Array(K)),wrappedKey:E(g)}}async unwrap(e,r,n){let i=await Fe(e,"X25519","exchange"),o=new Uint8Array(I(r)),a=o.slice(0,S),c=o.slice(S,S+B),p=o.slice(S+B),l=await Ue(this.exchangeKey.privateKey,i,a,n||"key-wrap"),K=await crypto.subtle.decrypt({name:D,iv:c},l,pe(p));return await crypto.subtle.importKey("raw",K,{name:D},!0,["encrypt","decrypt"])}async encrypt(e,r,n,i,o){let a=crypto.getRandomValues(new Uint8Array(S)),c=r||this.exchangeKey.publicKey,p;typeof c=="string"?p=await Fe(c,"X25519","exchange"):p=c;let l=await x._createExchangeKeys(!0),K=i||await Ue(l.privateKey,p,a,n||x.INFO,o);K instanceof CryptoKey||(K=await Ue(l.privateKey,p,a,n||x.INFO));let b=crypto.getRandomValues(new Uint8Array(B)),v=typeof e=="string"?new TextEncoder().encode(e):e,ue=await crypto.subtle.encrypt({name:D,iv:b},K,pe(v)),u=new Uint8Array(await Se(l)),g=new Uint8Array(a),T=new Uint8Array(b),P=new Uint8Array(ue),_=u.length+g.length+T.length+P.length,U=new Uint8Array(_);return U.set(u,0),U.set(g,u.length),U.set(T,u.length+g.length),U.set(P,u.length+g.length+T.length),U}async encryptAsString(e,r,n,i,o){let a=await this.encrypt(e,r,n||x.INFO,i,o);return f(new Uint8Array(a),"base64pad")}async decrypt(e,r,n){let i=oe(e,I),o=i.slice(0,q),a=await ce.subtle.importKey("raw",o,{name:Ie},!0,[]),c=i.slice(q,q+S),p=i.slice(q+S,q+S+B),l=i.slice(q+S+B),{privateKey:K}=this.exchangeKey,b=await Ue(K,a,c,n||x.INFO);return await crypto.subtle.decrypt({name:r||D,iv:p},b,l)}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 Fe(e,"X25519","exchange"):n=e;let i=crypto.getRandomValues(new Uint8Array(S));return await Ue(this.exchangeKey.privateKey,n,i,r||x.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 ce.subtle.sign({name:ie},this.writeKey.privateKey,pe(i));return new Uint8Array(o)}async signAsString(e,r){let n=await this.sign(e,r);return f(n,"base64pad")}};s(x,"EccKeys"),y(x,"TYPE","ecc"),y(x,"EXCHANGE_KEY_NAME",Me),y(x,"WRITE_KEY_NAME",ke),y(x,"INFO","keys");var te=x;Object.assign(te.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 Fe(t,e,r){Bt(r);let n=r==="exchange"?Ie:ie,i=r==="exchange"?[]:["verify"],o=I(t),a=e==="X25519"?{name:n}:{name:n,namedCurve:e};return ce.subtle.importKey("raw",o,a,!0,i)}s(Fe,"importPublicKey");var li={EccKeys:te,importPublicKey:Fe};Object.assign(te.prototype.encrypt,{asString:s(async function(t,e,r,n,i){return this.encryptAsString(t,e,r,n,i)},"asString")});Object.assign(te.prototype.decrypt,{asString:s(async function(t,e){return this.decryptAsString(t,e)},"asString")});Object.assign(te.prototype.sign,{asString:s(async function(t,e){return this.signAsString(t,e)},"asString")});async function gi(t,e,r){try{let n=er(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 ce.subtle.importKey("raw",i,{name:ie},!0,["verify"]),a=new TextEncoder,c;typeof t=="string"?c=a.encode(t):t instanceof ArrayBuffer?c=new Uint8Array(t):c=t;let p;return typeof e=="string"?p=new Uint8Array(I(e)):p=e,await ce.subtle.verify({name:ie},o,pe(p),pe(c))}catch{return!1}}s(gi,"verify");async function Ue(t,e,r,n,i){let o=new TextEncoder,a=await crypto.subtle.deriveBits({name:"X25519",public:e},t,256),c=await crypto.subtle.importKey("raw",a,"HKDF",!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:r instanceof Uint8Array?pe(r):r,info:o.encode(n)},c,{name:"AES-GCM",length:i||G},!1,["encrypt","decrypt"])}s(Ue,"deriveKey");export{H as AES_GCM,xe as AbstractKeys,Y as BASE58_DID_PREFIX,Je as BLS_DID_PREFIX,yr as CharSize,qr as CryptoSystem,z as DEFAULT_CHAR_SIZE,Me as DEFAULT_ECC_EXCHANGE,Wn as DEFAULT_ECC_EXCHANGE_CURVE,ke as DEFAULT_ECC_WRITE,se as DEFAULT_HASH_ALGORITHM,Ne as DEFAULT_RSA_EXCHANGE,qe as DEFAULT_RSA_SIZE,Le as DEFAULT_RSA_WRITE,D as DEFAULT_SYMM_ALGORITHM,G as DEFAULT_SYMM_LENGTH,Ie as ECC_EXCHANGE_ALGORITHM,ie as ECC_WRITE_ALGORITHM,Ze as EDWARDS_DID_PREFIX,ar as EccCurve,or as HashAlg,B as IV_LENGTH,_e as KEY_TYPE,bt as KEY_USE,ne as KeyUse,we as KeysDeletedError,J as RSA_ALGORITHM,je as RSA_DID_PREFIX,$e as RSA_HASHING_ALGORITHM,Z as RSA_SIGN_ALGORITHM,$r as RsaSize,S as SALT_LENGTH,jr as SymmKeyLength,q as X25519_PUBLIC_KEY_LENGTH,Pt as aes,ei as checkValidKeyUse,tr as did,nr as didToPublicKey,_t as ecc,Ut as ed25519Verify,Wr as encryptKeyTo,vt as encryptTo,Qn as getAlgorithm,ci as getDeviceName,ee as getPublicKeyAsArrayBuffer,zr as getPublicKeyAsUint8Array,ni as importRsaKey,Ke as isCryptoKey,fo as keyTypeFromDid,He as publicKeyToDid,It as rsa,ze as rsaImportPublicKey,X as rsaOperations,St as rsaVerify,uo as verify};
4
4
  //# sourceMappingURL=index.min.js.map