@substrate-system/keys 0.5.0 → 0.5.1

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.
@@ -1,4 +1,4 @@
1
- var Me=Object.defineProperty;var lr=(r,e,t)=>e in r?Me(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var s=(r,e)=>Me(r,"name",{value:e,configurable:!0});var _=(r,e)=>{for(var t in e)Me(r,t,{get:e[t],enumerable:!0})};var y=(r,e,t)=>lr(r,typeof e!="symbol"?e+"":e,t);function fe(r=0){return new Uint8Array(r)}s(fe,"allocUnsafe");function ke(r,e){e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=fe(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return t}s(ke,"concat");var Xe={};_(Xe,{base10:()=>xr});var pi=new Uint8Array(0);function It(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}s(It,"equals");function F(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}s(F,"coerce");function _t(r){return new TextEncoder().encode(r)}s(_t,"fromString");function Nt(r){return new TextDecoder().decode(r)}s(Nt,"toString");function gr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),a=o.charCodeAt(0);if(t[a]!==255)throw new TypeError(o+" is ambiguous");t[a]=i}var c=r.length,u=r.charAt(0),f=Math.log(c)/Math.log(256),h=Math.log(256)/Math.log(c);function x(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,v=0,E=0,b=p.length;E!==b&&p[E]===0;)E++,g++;for(var w=(b-E)*h+1>>>0,C=new Uint8Array(w);E!==b;){for(var B=p[E],O=0,I=w-1;(B!==0||O<v)&&I!==-1;I--,O++)B+=256*C[I]>>>0,C[I]=B%c>>>0,B=B/c>>>0;if(B!==0)throw new Error("Non-zero carry");v=O,E++}for(var G=w-v;G!==w&&C[G]===0;)G++;for(var Ee=u.repeat(g);G<w;++G)Ee+=r.charAt(C[G]);return Ee}s(x,"encode");function K(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var v=0,E=0;p[g]===u;)v++,g++;for(var b=(p.length-g)*f+1>>>0,w=new Uint8Array(b);p[g];){var C=t[p.charCodeAt(g)];if(C===255)return;for(var B=0,O=b-1;(C!==0||B<E)&&O!==-1;O--,B++)C+=c*w[O]>>>0,w[O]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");E=B,g++}if(p[g]!==" "){for(var I=b-E;I!==b&&w[I]===0;)I++;for(var G=new Uint8Array(v+(b-I)),Ee=v;I!==b;)G[Ee++]=w[I++];return G}}}s(K,"decodeUnsafe");function R(p){var g=K(p);if(g)return g;throw new Error(`Non-${e} character`)}return s(R,"decode"),{encode:x,decodeUnsafe:K,decode:R}}s(gr,"base");var dr=gr,mr=dr,Mt=mr;var Ge=class Ge{constructor(e,t,n){y(this,"name");y(this,"prefix");y(this,"baseEncode");this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}};s(Ge,"Encoder");var Re=Ge,Fe=class Fe{constructor(e,t,n){y(this,"name");y(this,"prefix");y(this,"baseDecode");y(this,"prefixCodePoint");this.name=e,this.prefix=t;let i=t.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 kt(this,e)}};s(Fe,"Decoder");var Oe=Fe,Ve=class Ve{constructor(e){y(this,"decoders");this.decoders=e}or(e){return kt(this,e)}decode(e){let t=e[0],n=this.decoders[t];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(Ve,"ComposedDecoder");var ze=Ve;function kt(r,e){return new ze({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}s(kt,"or");var We=class We{constructor(e,t,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=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new Re(e,t,n),this.decoder=new Oe(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};s(We,"Codec");var He=We;function Z({name:r,prefix:e,encode:t,decode:n}){return new He(r,e,t,n)}s(Z,"from");function W({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Mt(t,r);return Z({prefix:e,name:r,encode:n,decode:s(o=>F(i(o)),"decode")})}s(W,"baseX");function Ar(r,e,t,n){let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),a=0,c=0,u=0;for(let f=0;f<i;++f){let h=e[r[f]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|h,a+=t,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=t||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return o}s(Ar,"decode");function br(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",a=0,c=0;for(let u=0;u<r.length;++u)for(c=c<<8|r[u],a+=8;a>t;)a-=t,o+=e[i&c>>a];if(a!==0&&(o+=e[i&c<<t-a]),n)for(;(o.length*t&7)!==0;)o+="=";return o}s(br,"encode");function wr(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}s(wr,"createAlphabetIdx");function m({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let i=wr(n);return Z({prefix:e,name:r,encode(o){return br(o,n,t)},decode(o){return Ar(o,i,t,r)}})}s(m,"rfc4648");var xr=W({prefix:"9",name:"base10",alphabet:"0123456789"});var je={};_(je,{base16:()=>Kr,base16upper:()=>Er});var Kr=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Er=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var $e={};_($e,{base2:()=>Ur});var Ur=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ye={};_(Ye,{base256emoji:()=>Br});var Rt=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}"),Sr=Rt.reduce((r,e,t)=>(r[t]=e,r),[]),Cr=Rt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Pr(r){return r.reduce((e,t)=>(e+=Sr[t],e),"")}s(Pr,"encode");function vr(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=Cr[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}s(vr,"decode");var Br=Z({prefix:"\u{1F680}",name:"base256emoji",encode:Pr,decode:vr});var qe={};_(qe,{base32:()=>Q,base32hex:()=>_r,base32hexpad:()=>Lr,base32hexpadupper:()=>Mr,base32hexupper:()=>Nr,base32pad:()=>Dr,base32padupper:()=>Ir,base32upper:()=>Tr,base32z:()=>kr});var Q=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Tr=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Dr=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ir=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_r=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Nr=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Lr=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Mr=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),kr=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Je={};_(Je,{base36:()=>le,base36upper:()=>Rr});var le=W({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Rr=W({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ze={};_(Ze,{base58btc:()=>z,base58flickr:()=>Or});var z=W({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Or=W({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Qe={};_(Qe,{base64:()=>zr,base64pad:()=>Hr,base64url:()=>Gr,base64urlpad:()=>Fr});var zr=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Hr=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Gr=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Fr=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var et={};_(et,{base8:()=>Vr});var Vr=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var tt={};_(tt,{identity:()=>Wr});var Wr=Z({prefix:"\0",name:"identity",encode:s(r=>Nt(r),"encode"),decode:s(r=>_t(r),"decode")});var Di=new TextEncoder,Ii=new TextDecoder;var it={};_(it,{identity:()=>gn});var $r=Ht,Ot=128,Yr=127,qr=~Yr,Jr=Math.pow(2,31);function Ht(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Jr;)e[t++]=r&255|Ot,r/=128;for(;r&qr;)e[t++]=r&255|Ot,r>>>=7;return e[t]=r|0,Ht.bytes=t-n+1,e}s(Ht,"encode");var Zr=rt,Qr=128,zt=127;function rt(r,n){var t=0,n=n||0,i=0,o=n,a,c=r.length;do{if(o>=c)throw rt.bytes=0,new RangeError("Could not decode varint");a=r[o++],t+=i<28?(a&zt)<<i:(a&zt)*Math.pow(2,i),i+=7}while(a>=Qr);return rt.bytes=o-n,t}s(rt,"read");var en=Math.pow(2,7),tn=Math.pow(2,14),rn=Math.pow(2,21),nn=Math.pow(2,28),sn=Math.pow(2,35),on=Math.pow(2,42),an=Math.pow(2,49),cn=Math.pow(2,56),yn=Math.pow(2,63),pn=s(function(r){return r<en?1:r<tn?2:r<rn?3:r<nn?4:r<sn?5:r<on?6:r<an?7:r<cn?8:r<yn?9:10},"length"),un={encode:$r,decode:Zr,encodingLength:pn},fn=un,he=fn;function ge(r,e=0){return[he.decode(r,e),he.decode.bytes]}s(ge,"decode");function ee(r,e,t=0){return he.encode(r,e,t),e}s(ee,"encodeTo");function te(r){return he.encodingLength(r)}s(te,"encodingLength");function ne(r,e){let t=e.byteLength,n=te(r),i=n+te(t),o=new Uint8Array(i+t);return ee(r,o,0),ee(t,o,n),o.set(e,i),new re(r,t,e,o)}s(ne,"create");function Gt(r){let e=F(r),[t,n]=ge(e),[i,o]=ge(e.subarray(n)),a=e.subarray(n+o);if(a.byteLength!==i)throw new Error("Incorrect length");return new re(t,i,a,e)}s(Gt,"decode");function Ft(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&It(r.bytes,t.bytes)}}s(Ft,"equals");var nt=class nt{constructor(e,t,n,i){y(this,"code");y(this,"size");y(this,"digest");y(this,"bytes");this.code=e,this.size=t,this.digest=n,this.bytes=i}};s(nt,"Digest");var re=nt;var Vt=0,ln="identity",Wt=F;function hn(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return ne(Vt,Wt(r))}s(hn,"digest");var gn={code:Vt,name:ln,encode:Wt,digest:hn};var ct={};_(ct,{sha256:()=>mn,sha512:()=>An});var dn=20;function ot({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:i}){return new st(r,e,t,n,i)}s(ot,"from");var at=class at{constructor(e,t,n,i,o){y(this,"name");y(this,"code");y(this,"encode");y(this,"minDigestLength");y(this,"maxDigestLength");this.name=e,this.code=t,this.encode=n,this.minDigestLength=i??dn,this.maxDigestLength=o}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.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?Xt(n,this.code,t?.truncate):n.then(i=>Xt(i,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};s(at,"Hasher");var st=at;function Xt(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return ne(e,r)}s(Xt,"createDigest");function $t(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}s($t,"sha");var mn=ot({name:"sha2-256",code:18,encode:$t("SHA-256")}),An=ot({name:"sha2-512",code:19,encode:$t("SHA-512")});function Yt(r,e){let{bytes:t,version:n}=r;return n===0?wn(t,yt(r),e??z.encoder):xn(t,yt(r),e??Q.encoder)}s(Yt,"format");var qt=new WeakMap;function yt(r){let e=qt.get(r);if(e==null){let t=new Map;return qt.set(r,t),t}return e}s(yt,"baseCache");var Zt,U=class U{constructor(e,t,n,i){y(this,"code");y(this,"version");y(this,"multihash");y(this,"bytes");y(this,"/");y(this,Zt,"CID");this.code=t,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:t}=this;if(e!==me)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Kn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return U.createV0(t)}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:t}=this.multihash,n=ne(e,t);return U.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 U.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Ft(e.multihash,n.multihash)}toString(e){return Yt(this,e)}toJSON(){return{"/":Yt(this)}}link(){return this}[(Zt=Symbol.toStringTag,Symbol.for("nodejs.util.inspect.custom"))](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof U)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:a}=t;return new U(n,i,o,a??Jt(n,i,o.bytes))}else if(t[En]===!0){let{version:n,multihash:i,code:o}=t,a=Gt(i);return U.create(n,o,a)}else return null}static create(e,t,n){if(typeof t!="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(t!==me)throw new Error(`Version 0 CID must use dag-pb (code: ${me}) block encoding`);return new U(e,t,n,n.bytes)}case 1:{let i=Jt(e,t,n.bytes);return new U(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return U.create(0,me,e)}static createV1(e,t){return U.create(1,e,t)}static decode(e){let[t,n]=U.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=U.inspectBytes(e),n=t.size-t.multihashSize,i=F(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),a=new re(t.multihashCode,t.digestSize,o,i);return[t.version===0?U.createV0(a):U.createV1(t.codec,a),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=s(()=>{let[x,K]=ge(e.subarray(t));return t+=K,x},"next"),i=n(),o=me;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let a=t,c=n(),u=n(),f=t+u,h=f-a;return{version:i,codec:o,multihashCode:c,digestSize:u,multihashSize:h,size:f}}static parse(e,t){let[n,i]=bn(e,t),o=U.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return yt(o).set(n,e),o}};s(U,"CID");var Se=U;function bn(r,e){switch(r[0]){case"Q":{let t=e??z;return[z.prefix,t.decode(`${z.prefix}${r}`)]}case z.prefix:{let t=e??z;return[z.prefix,t.decode(r)]}case Q.prefix:{let t=e??Q;return[Q.prefix,t.decode(r)]}case le.prefix:{let t=e??le;return[le.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}s(bn,"parseCIDtoBytes");function wn(r,e,t){let{prefix:n}=t;if(n!==z.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}s(wn,"toStringV0");function xn(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}s(xn,"toStringV1");var me=112,Kn=18;function Jt(r,e,t){let n=te(r),i=n+te(e),o=new Uint8Array(i+t.byteLength);return ee(r,o,0),ee(e,o,n),o.set(t,i),o}s(Jt,"encodeCID");var En=Symbol.for("@ipld/js-cid/CID");var pt={...tt,...$e,...et,...Xe,...je,...qe,...Je,...Ze,...Qe,...Ye},ys={...ct,...it};function er(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}s(er,"createCodec");var Qt=er("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ut=er("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=fe(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Un={utf8:Qt,"utf-8":Qt,hex:pt.base16,latin1:ut,ascii:ut,binary:ut,...pt},Ce=Un;function S(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}s(S,"fromString");function A(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}s(A,"toString");var $="did:key:z",ie="Ed25519",Pe="X25519",Ls="X25519",V=32;var se="RSA-OAEP",oe="RSASSA-PKCS1-v1_5",ft="SHA-256",lt=new Uint8Array([0,245,2]),Ms=2048,ht="SHA-256",ae=8,ce="AES-GCM",N=ce,Y=256,L=12,tr=16,gt=new Uint8Array([234,1]),dt=new Uint8Array([237,1]),ve={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"};var rr="ecc-exchange",nr="ecc-write",P=16,mt=1;var Be=globalThis.crypto,ir=new Error("Invalid key use. Please use 'encryption' or 'signing"),Pn=new Error("Max must be less than 256 and greater than 0");function l(r){return new Uint8Array(r).buffer}s(l,"toArrayBuffer");async function sr(r){let e=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);return new Uint8Array(await Be.subtle.digest("sha-256",e))}s(sr,"sha256");function M(r){let e=S(r,"base64pad");return l(e)}s(M,"base64ToArrBuf");var be=s((r,e)=>{if(typeof r=="string")return e(r);if(typeof r=="object"&&r.byteLength!==void 0)return new Uint8Array(r).buffer;throw new Error("Improper value. Must be a string, ArrayBuffer, Uint8Array")},"normalizeToBuf");function Te(r){return be(r,M)}s(Te,"normalizeBase64ToBuf");var vn=s(r=>be(r,e=>l(new TextEncoder().encode(e))),"normalizeUtf8ToBuf");function Bn(r,e){let t=e===8?new Uint8Array(r.length):new Uint16Array(r.length);for(let n=0,i=r.length;n<i;n++)t[n]=r.charCodeAt(n);return t.buffer}s(Bn,"strToArrBuf");var Tn=s(r=>be(r,e=>Bn(e,16)),"normalizeUtf16ToBuf");function ye(r,e){return e===8?vn(r):Tn(r)}s(ye,"normalizeUnicodeToBuf");function or(r){if(!r.startsWith($))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+r.substring($.length),t=S(e,"base58btc"),{keyBuffer:n,type:i}=Dn(l(t));return{publicKey:new Uint8Array(n),type:i}}s(or,"didToPublicKey");function Dn(r){if(Ae(r,l(lt)))return{keyBuffer:r.slice(lt.byteLength),type:ve.RSA};if(Ae(r,l(dt)))return{keyBuffer:r.slice(dt.byteLength),type:ve.Edwards};if(Ae(r,l(gt)))return{keyBuffer:r.slice(gt.byteLength),type:ve.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}s(Dn,"parseMagicBytes");var In={equal:s((r,e)=>{let t=new Uint8Array(r),n=new Uint8Array(e);if(t.length!==n.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!==n[i])return!1;return!0},"equal")};function Ae(r,e){return In.equal(e,r.slice(0,e.byteLength))}s(Ae,"hasPrefix");function T(r){return A(r instanceof ArrayBuffer?new Uint8Array(r):r,"base64pad")}s(T,"toBase64");async function bt(r,e){let t=typeof r=="string"?M(r):l(r);return Be.subtle.importKey("raw",t,{name:e?.alg||N,length:e?.length||Y},e?.extractable??!0,["encrypt","decrypt"])}s(bt,"importKey");function ar(r,{max:e}={max:255}){if(e<1||e>255)throw Pn;let t=new Uint8Array(r);if(e===255)return Be.getRandomValues(t),t.buffer;let n=0,i=e+1,o=Math.floor(256/i)*i,a=new Uint8Array(1);for(;n<t.length;)Be.getRandomValues(a),a[0]<o&&(t[n]=a[0]%i,n++);return t.buffer}s(ar,"randomBuf");function De(r,e){let t=r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(l(r)),n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(l(e)),i=new Uint8Array(t.length+n.length);return i.set(t),i.set(n,t.length),i.buffer}s(De,"joinBufs");var Xs=new Error("Key does not exist. Make sure you properly instantiated the keystore."),js=new Error("Retrieved a symmetric key when an asymmetric keypair was expected. Please use a different key name."),$s=new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name."),Ys=new Error("ECC is not enabled for this browser. Please use RSA instead."),qs=new Error("Cryptosystem not supported. Please use ECC or RSA"),_n=new Error("Invalid key use. Please use 'exchange' or 'write'"),Js=new Error("Max must be less than 256 and greater than 0"),wt=class wt extends Error{constructor(e){super(e||"These keys were deleted"),this.name="KeysDeletedError"}};s(wt,"KeysDeletedError");var pe=wt;function cr(r){Nn(r,["exchange","write","signing"],_n)}s(cr,"checkValidKeyUse");function Nn(r,e,t){if(!e.some(i=>i===r))throw t}s(Nn,"checkValid");function Ie(r){return new Promise((e,t)=>{r.oncomplete=r.onsuccess=()=>e(r.result),r.onabort=r.onerror=()=>t(r.error)})}s(Ie,"promisifyRequest");function Ln(r,e){let t,n=s(()=>{if(t)return t;let i=indexedDB.open(r);return i.onupgradeneeded=()=>i.result.createObjectStore(e),t=Ie(i),t.then(o=>{o.onclose=()=>t=void 0},()=>{t=void 0}),t},"getDB");return(i,o)=>n().then(a=>o(a.transaction(e,i).objectStore(e)))}s(Ln,"createStore");var xt;function Kt(){return xt||(xt=Ln("keyval-store","keyval")),xt}s(Kt,"defaultGetStore");function we(r,e=Kt()){return e("readonly",t=>Ie(t.get(r)))}s(we,"get");function Et(r,e,t=Kt()){return t("readwrite",n=>(n.put(e,r),Ie(n.transaction)))}s(Et,"set");function Ut(r,e=Kt()){return e("readwrite",t=>(r.forEach(n=>t.delete(n)),Ie(t.transaction)))}s(Ut,"delMany");var k=globalThis.crypto,Pt={keyTypes:{"bls12-381":{magicBytes:new Uint8Array([234,1]),verify:s(()=>{throw new Error("Not implemented")},"verify")},rsa:{magicBytes:new Uint8Array([0,245,2]),verify:kn},ed25519:{magicBytes:new Uint8Array([237,1]),verify:Mn}}};async function Mn({message:r,publicKey:e,signature:t}){let n=r;typeof r=="string"&&(n=S(r,"utf8"));let i=t;typeof t=="string"&&(i=S(t,"base64pad"));let o=e;if(typeof e=="string"&&(o=yr(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",l(o),{name:"Ed25519"},!1,["verify"]);return k.subtle.verify({name:"Ed25519"},a,l(i),l(n))}s(Mn,"ed25519Verify");async function kn({message:r,publicKey:e,signature:t}){let n=e;return typeof e=="string"&&(n=yr(e).publicKey),vt.verify(r,t,await k.subtle.importKey("spki",l(n),{name:oe,hash:ft},!1,["verify"]),8)}s(kn,"rsaVerify");var vt={verify:s(async function(e,t,n,i=ae,o=ht){return k.subtle.verify({name:oe},typeof n=="string"?await St(n,o,"signing"):n,Te(t),ye(e,i))},"rsaVerify"),sign:s(async function(e,t,n=ae){return k.subtle.sign({name:oe},t,ye(e,n))},"sign"),encrypt:s(async function(e,t,n=ae,i=ht){let o;return typeof t=="string"?o=await St(t,i,"exchange"):o=t instanceof Uint8Array?await St(l(t),i,"exchange"):t,k.subtle.encrypt({name:se},o,ye(e,n))},"rsaEncrypt"),decrypt:s(async function(e,t){let n=_e(t)?t:await Hn(t,["decrypt"]),i;typeof e=="string"?i=S(e,"base64pad"):i=e;let o=await k.subtle.decrypt({name:se},n,i instanceof Uint8Array?l(i):i);return new Uint8Array(o)},"rsaDecrypt")};async function St(r,e,t){Rn(t);let n=t==="exchange"?se:oe,i=t==="exchange"?["encrypt"]:["verify"],o=typeof r=="string"?M(zn(r)):r;return k.subtle.importKey("spki",o,{name:n,hash:{name:e}},!0,i)}s(St,"rsaImportPublicKey");function Rn(r){On(r,["signing","exchange"],ir)}s(Rn,"checkValidKeyUse");function On(r,e,t){if(!e.some(i=>i===r))throw t}s(On,"checkValid");function zn(r){return r.replace(`-----BEGIN PUBLIC KEY-----
1
+ var ze=Object.defineProperty;var bt=(r,e,t)=>e in r?ze(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var s=(r,e)=>ze(r,"name",{value:e,configurable:!0});var N=(r,e)=>{for(var t in e)ze(r,t,{get:e[t],enumerable:!0})};var y=(r,e,t)=>bt(r,typeof e!="symbol"?e+"":e,t);function te(r=0){return new Uint8Array(r)}s(te,"allocUnsafe");function xt(r){return r?.buffer instanceof ArrayBuffer}s(xt,"isByteArrayWithArrayBuffer");function He(r){if(xt(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}s(He,"asUint8Array");function Ge(r,e){e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=te(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return He(t)}s(Ge,"concat");var Je={};N(Je,{base10:()=>Bt});var Ki=new Uint8Array(0);function Rr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}s(Rr,"equals");function L(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return J(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return J(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}s(L,"coerce");function Or(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}s(Or,"fromString");var Mr=4096;function zr(r){let e=r.length;if(e<=Mr)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=Mr));return t}s(zr,"toString");function Kt(r){return r?.buffer instanceof ArrayBuffer}s(Kt,"isByteArrayWithArrayBuffer");function J(r){return Kt(r)?r:r.slice()}s(J,"toArrayBufferBackedArray");function Et(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var o=0;o<r.length;o++){var a=r.charAt(o),c=a.charCodeAt(0);if(n[c]!==255)throw new TypeError(a+" is ambiguous");if(n[c]=o,t){var f=a.toLowerCase().charCodeAt(0),p=a.toUpperCase().charCodeAt(0);f!==c&&(n[f]=o),p!==c&&(n[p]=o)}}var l=r.length,w=r.charAt(0),b=Math.log(l)/Math.log(256),z=Math.log(256)/Math.log(l);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 g=0,K=0,S=0,C=u.length;S!==C&&u[S]===0;)S++,g++;for(var _=(C-S)*z+1>>>0,X=new Uint8Array(_);S!==C;){for(var v=u[S],q=0,V=_-1;(v!==0||q<K)&&V!==-1;V--,q++)v+=256*X[V]>>>0,X[V]=v%l>>>0,v=v/l>>>0;if(v!==0)throw new Error("Non-zero carry");K=q,S++}for(var T=_-K;T!==_&&X[T]===0;)T++;for(var me=w.repeat(g);T<_;++T)me+=r.charAt(X[T]);return me}s(D,"encode");function B(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 K=0,S=0;u[g]===w;)K++,g++;for(var C=(u.length-g)*b+1>>>0,_=new Uint8Array(C);u[g];){var X=u.charCodeAt(g);if(X>255)return;var v=n[X];if(v===255)return;for(var q=0,V=C-1;(v!==0||q<S)&&V!==-1;V--,q++)v+=l*_[V]>>>0,_[V]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");S=q,g++}if(u[g]!==" "){for(var T=C-S;T!==C&&_[T]===0;)T++;for(var me=new Uint8Array(K+(C-T)),wt=K;T!==C;)me[wt++]=_[T++];return me}}}s(B,"decodeUnsafe");function F(u){var g=B(u);if(g)return g;throw new Error(`Non-${e} character`)}return s(F,"decode"),{encode:D,decodeUnsafe:B,decode:F}}s(Et,"base");var Ut=Et,St=Ut,Gr=St;var je=class je{constructor(e,t,n){y(this,"name");y(this,"prefix");y(this,"baseEncode");this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}};s(je,"Encoder");var Fe=je,$e=class $e{constructor(e,t,n){y(this,"name");y(this,"prefix");y(this,"baseDecode");y(this,"prefixCodePoint");this.name=e,this.prefix=t;let i=t.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 Fr(this,e)}};s($e,"Decoder");var Ve=$e,Ye=class Ye{constructor(e){y(this,"decoders");this.decoders=e}or(e){return Fr(this,e)}decode(e){let t=e[0],n=this.decoders[t];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(Ye,"ComposedDecoder");var We=Ye;function Fr(r,e){return new We({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}s(Fr,"or");var qe=class qe{constructor(e,t,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=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new Fe(e,t,n),this.decoder=new Ve(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};s(qe,"Codec");var Xe=qe;function ne({name:r,prefix:e,encode:t,decode:n}){return new Xe(r,e,t,n)}s(ne,"from");function j({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:i,decode:o}=Gr(t,r,n);return ne({prefix:e,name:r,encode:i,decode:s(a=>L(o(a)),"decode")})}s(j,"baseX");function Ct(r,e,t,n){let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),a=0,c=0,f=0;for(let p=0;p<i;++p){let l=e[r[p]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|l,a+=t,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=t||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return o}s(Ct,"decode");function vt(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",a=0,c=0;for(let f=0;f<r.length;++f)for(c=c<<8|r[f],a+=8;a>t;)a-=t,o+=e[i&c>>a];if(a!==0&&(o+=e[i&c<<t-a]),n)for(;(o.length*t&7)!==0;)o+="=";return o}s(vt,"encode");function Pt(r,e){let t={};for(let n=0;n<r.length;++n)if(r[n]!=="="&&(t[r[n]]=n,e)){let i=r[n].toLowerCase(),o=r[n].toUpperCase();i!==r[n]&&(t[i]=n),o!==r[n]&&(t[o]=n)}return t}s(Pt,"createAlphabetIdx");function m({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:i=!1}){let o=Pt(n,i);return ne({prefix:e,name:r,encode(a){return vt(a,n,t)},decode(a){return Ct(a,o,t,r)}})}s(m,"rfc4648");var Bt=j({prefix:"9",name:"base10",alphabet:"0123456789"});var Ze={};N(Ze,{base16:()=>Tt,base16upper:()=>It});var Tt=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),It=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Qe={};N(Qe,{base2:()=>Dt});var Dt=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var er={};N(er,{base256emoji:()=>Mt});var Vr=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}"),_t=Vr.reduce((r,e,t)=>(r[t]=e,r),[]),Nt=Vr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Lt(r){return r.reduce((e,t)=>(e+=_t[t],e),"")}s(Lt,"encode");function kt(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=Nt[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}s(kt,"decode");var Mt=ne({prefix:"\u{1F680}",name:"base256emoji",encode:Lt,decode:kt});var rr={};N(rr,{base32:()=>ie,base32hex:()=>Ht,base32hexpad:()=>Ft,base32hexpadupper:()=>Vt,base32hexupper:()=>Gt,base32pad:()=>Ot,base32padupper:()=>zt,base32upper:()=>Rt,base32z:()=>Wt});var ie=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Rt=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ot=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),zt=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Ht=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Gt=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Ft=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Vt=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Wt=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var tr={};N(tr,{base36:()=>Ae,base36upper:()=>Xt});var Ae=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Xt=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var nr={};N(nr,{base58btc:()=>H,base58flickr:()=>jt});var H=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jt=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ir={};N(ir,{base64:()=>$t,base64pad:()=>Yt,base64url:()=>qt,base64urlpad:()=>Jt});var $t=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Yt=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qt=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jt=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var sr={};N(sr,{base8:()=>Zt});var Zt=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var or={};N(or,{identity:()=>Qt});var Qt=ne({prefix:"\0",name:"identity",encode:s(r=>zr(L(r)),"encode"),decode:s(r=>L(Or(r)),"decode")});var Fi=new TextEncoder,Vi=new TextDecoder;var yr={};N(yr,{identity:()=>En});var tn=jr,Wr=128,nn=127,sn=~nn,on=Math.pow(2,31);function jr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=on;)e[t++]=r&255|Wr,r/=128;for(;r&sn;)e[t++]=r&255|Wr,r>>>=7;return e[t]=r|0,jr.bytes=t-n+1,e}s(jr,"encode");var an=ar,cn=128,Xr=127;function ar(r,n){var t=0,n=n||0,i=0,o=n,a,c=r.length;do{if(o>=c)throw ar.bytes=0,new RangeError("Could not decode varint");a=r[o++],t+=i<28?(a&Xr)<<i:(a&Xr)*Math.pow(2,i),i+=7}while(a>=cn);return ar.bytes=o-n,t}s(ar,"read");var yn=Math.pow(2,7),fn=Math.pow(2,14),un=Math.pow(2,21),pn=Math.pow(2,28),ln=Math.pow(2,35),hn=Math.pow(2,42),gn=Math.pow(2,49),dn=Math.pow(2,56),mn=Math.pow(2,63),An=s(function(r){return r<yn?1:r<fn?2:r<un?3:r<pn?4:r<ln?5:r<hn?6:r<gn?7:r<dn?8:r<mn?9:10},"length"),wn={encode:tn,decode:an,encodingLength:An},bn=wn,we=bn;function be(r,e=0){let t=we.decode(r,e),n=we.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}s(be,"decode");function se(r,e,t=0){return we.encode(r,e,t),e}s(se,"encodeTo");function oe(r){return we.encodingLength(r)}s(oe,"encodingLength");function ce(r,e){let t=e.byteLength,n=oe(r),i=n+oe(t),o=new Uint8Array(i+t);return se(r,o,0),se(t,o,n),o.set(e,i),new ae(r,t,e,o)}s(ce,"create");function $r(r){let e=L(r),[t,n]=be(e),[i,o]=be(e.subarray(n)),a=e.subarray(n+o);if(a.byteLength!==i)throw new Error("Incorrect length");return new ae(t,i,a,e)}s($r,"decode");function Yr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Rr(r.bytes,t.bytes)}}s(Yr,"equals");var cr=class cr{constructor(e,t,n,i){y(this,"code");y(this,"size");y(this,"digest");y(this,"bytes");this.code=e,this.size=t,this.digest=J(n),this.bytes=J(i)}};s(cr,"Digest");var ae=cr;var qr=0,xn="identity",Jr=L;function Kn(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return ce(qr,Jr(r))}s(Kn,"digest");var En={code:qr,name:xn,encode:Jr,digest:Kn};var lr={};N(lr,{sha256:()=>Sn,sha512:()=>Cn});var Un=20;function ur({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:i}){return new fr(r,e,t,n,i)}s(ur,"from");var pr=class pr{constructor(e,t,n,i,o){y(this,"name");y(this,"code");y(this,"encode");y(this,"minDigestLength");y(this,"maxDigestLength");this.name=e,this.code=t,this.encode=n,this.minDigestLength=i??Un,this.maxDigestLength=o}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.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?Zr(n,this.code,t?.truncate):n.then(i=>Zr(i,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};s(pr,"Hasher");var fr=pr;function Zr(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return ce(e,r)}s(Zr,"createDigest");function et(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}s(et,"sha");var Sn=ur({name:"sha2-256",code:18,encode:et("SHA-256")}),Cn=ur({name:"sha2-512",code:19,encode:et("SHA-512")});function rt(r,e){let{bytes:t,version:n}=r;return n===0?Pn(t,hr(r),e??H.encoder):Bn(t,hr(r),e??ie.encoder)}s(rt,"format");var tt=new WeakMap;function hr(r){let e=tt.get(r);if(e==null){let t=new Map;return tt.set(r,t),t}return e}s(hr,"baseCache");var it,x=class x{constructor(e,t,n,i){y(this,"code");y(this,"version");y(this,"multihash");y(this,"bytes");y(this,"/");y(this,it,"CID");this.code=t,this.version=e,this.multihash=n,this.bytes=J(i),this["/"]=this.bytes}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:t}=this;if(e!==Ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Tn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return x.createV0(t)}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:t}=this.multihash,n=ce(e,t);return x.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 x.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Yr(e.multihash,n.multihash)}toString(e){return rt(this,e)}toJSON(){return{"/":rt(this)}}link(){return this}[(it=Symbol.toStringTag,Symbol.for("nodejs.util.inspect.custom"))](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof x)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:a}=t;return new x(n,i,o,a??nt(n,i,o.bytes))}else if(t[In]===!0){let{version:n,multihash:i,code:o}=t,a=$r(i);return x.create(n,o,a)}else return null}static create(e,t,n){if(typeof t!="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(t!==Ke)throw new Error(`Version 0 CID must use dag-pb (code: ${Ke}) block encoding`);return new x(e,t,n,n.bytes)}case 1:{let i=nt(e,t,n.bytes);return new x(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return x.create(0,Ke,e)}static createV1(e,t){return x.create(1,e,t)}static decode(e){let[t,n]=x.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=x.inspectBytes(e),n=t.size-t.multihashSize,i=L(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),a=new ae(t.multihashCode,t.digestSize,o,i);return[t.version===0?x.createV0(a):x.createV1(t.codec,a),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=s(()=>{let[w,b]=be(e.subarray(t));return t+=b,w},"next"),i=n(),o=Ke;if(i===18)i=0,t=0;else if(i===1)o=n();else throw i===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${i}`);let a=t,c=n(),f=n(),p=t+f,l=p-a;return{version:i,codec:o,multihashCode:c,digestSize:f,multihashSize:l,size:p}}static parse(e,t){let[n,i]=vn(e,t),o=x.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return hr(o).set(n,e),o}};s(x,"CID");var Be=x;function vn(r,e){switch(r[0]){case"Q":{let t=e??H;return[H.prefix,t.decode(`${H.prefix}${r}`)]}case H.prefix:{let t=e??H;return[H.prefix,t.decode(r)]}case ie.prefix:{let t=e??ie;return[ie.prefix,t.decode(r)]}case Ae.prefix:{let t=e??Ae;return[Ae.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}s(vn,"parseCIDtoBytes");function Pn(r,e,t){let{prefix:n}=t;if(n!==H.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}s(Pn,"toStringV0");function Bn(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}s(Bn,"toStringV1");var Ke=112,Tn=18;function nt(r,e,t){let n=oe(r),i=n+oe(e),o=new Uint8Array(i+t.byteLength);return se(r,o,0),se(e,o,n),o.set(t,i),o}s(nt,"encodeCID");var In=Symbol.for("@ipld/js-cid/CID");var gr={...or,...Qe,...sr,...Je,...Ze,...rr,...tr,...nr,...ir,...er},xs={...lr,...yr};function ot(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}s(ot,"createCodec");var st=ot("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),dr=ot("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=te(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Dn={utf8:st,"utf-8":st,hex:gr.base16,latin1:dr,ascii:dr,binary:dr,...gr},Te=Dn;function E(r,e="utf8"){let t=Te[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}s(E,"fromString");function A(r,e="utf8"){let t=Te[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}s(A,"toString");var Z="did:key:z",ye="Ed25519",Ie="X25519",Qs="X25519",W=32;var fe="RSA-OAEP",ue="RSASSA-PKCS1-v1_5",mr="SHA-256",Ar=new Uint8Array([0,245,2]),eo=2048,wr="SHA-256",pe=8,le="AES-GCM",k=le,Q=256,M=12,at=16,br=new Uint8Array([234,1]),xr=new Uint8Array([237,1]),De={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"};var ct="ecc-exchange",yt="ecc-write",U=16,Kr=1;var _e=globalThis.crypto,ft=new Error("Invalid key use. Please use 'encryption' or 'signing"),Ln=new Error("Max must be less than 256 and greater than 0");function h(r){return new Uint8Array(r).buffer}s(h,"toArrayBuffer");async function ut(r){let e=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);return new Uint8Array(await _e.subtle.digest("sha-256",e))}s(ut,"sha256");function R(r){let e=E(r,"base64pad");return h(e)}s(R,"base64ToArrBuf");var Ue=s((r,e)=>{if(typeof r=="string")return e(r);if(typeof r=="object"&&r.byteLength!==void 0)return new Uint8Array(r).buffer;throw new Error("Improper value. Must be a string, ArrayBuffer, Uint8Array")},"normalizeToBuf");function Ne(r){return Ue(r,R)}s(Ne,"normalizeBase64ToBuf");var kn=s(r=>Ue(r,e=>h(new TextEncoder().encode(e))),"normalizeUtf8ToBuf");function Mn(r,e){let t=e===8?new Uint8Array(r.length):new Uint16Array(r.length);for(let n=0,i=r.length;n<i;n++)t[n]=r.charCodeAt(n);return t.buffer}s(Mn,"strToArrBuf");var Rn=s(r=>Ue(r,e=>Mn(e,16)),"normalizeUtf16ToBuf");function he(r,e){return e===8?kn(r):Rn(r)}s(he,"normalizeUnicodeToBuf");function pt(r){if(!r.startsWith(Z))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+r.substring(Z.length),t=E(e,"base58btc"),{keyBuffer:n,type:i}=On(h(t));return{publicKey:new Uint8Array(n),type:i}}s(pt,"didToPublicKey");function On(r){if(Ee(r,h(Ar)))return{keyBuffer:r.slice(Ar.byteLength),type:De.RSA};if(Ee(r,h(xr)))return{keyBuffer:r.slice(xr.byteLength),type:De.Edwards};if(Ee(r,h(br)))return{keyBuffer:r.slice(br.byteLength),type:De.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}s(On,"parseMagicBytes");var zn={equal:s((r,e)=>{let t=new Uint8Array(r),n=new Uint8Array(e);if(t.length!==n.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!==n[i])return!1;return!0},"equal")};function Ee(r,e){return zn.equal(e,r.slice(0,e.byteLength))}s(Ee,"hasPrefix");function P(r){return A(r instanceof ArrayBuffer?new Uint8Array(r):r,"base64pad")}s(P,"toBase64");async function Ur(r,e){let t=typeof r=="string"?R(r):h(r);return _e.subtle.importKey("raw",t,{name:e?.alg||k,length:e?.length||Q},e?.extractable??!0,["encrypt","decrypt"])}s(Ur,"importKey");function lt(r,{max:e}={max:255}){if(e<1||e>255)throw Ln;let t=new Uint8Array(r);if(e===255)return _e.getRandomValues(t),t.buffer;let n=0,i=e+1,o=Math.floor(256/i)*i,a=new Uint8Array(1);for(;n<t.length;)_e.getRandomValues(a),a[0]<o&&(t[n]=a[0]%i,n++);return t.buffer}s(lt,"randomBuf");function Le(r,e){let t=r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(h(r)),n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(h(e)),i=new Uint8Array(t.length+n.length);return i.set(t),i.set(n,t.length),i.buffer}s(Le,"joinBufs");var fo=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."),po=new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name."),lo=new Error("ECC is not enabled for this browser. Please use RSA instead."),ho=new Error("Cryptosystem not supported. Please use ECC or RSA"),Hn=new Error("Invalid key use. Please use 'exchange' or 'write'"),go=new Error("Max must be less than 256 and greater than 0"),Sr=class Sr extends Error{constructor(e){super(e||"These keys were deleted"),this.name="KeysDeletedError"}};s(Sr,"KeysDeletedError");var ge=Sr;function ht(r){Gn(r,["exchange","write","signing"],Hn)}s(ht,"checkValidKeyUse");function Gn(r,e,t){if(!e.some(i=>i===r))throw t}s(Gn,"checkValid");function ke(r){return new Promise((e,t)=>{r.oncomplete=r.onsuccess=()=>e(r.result),r.onabort=r.onerror=()=>t(r.error)})}s(ke,"promisifyRequest");function Fn(r,e){let t,n=s(()=>{if(t)return t;let i=indexedDB.open(r);return i.onupgradeneeded=()=>i.result.createObjectStore(e),t=ke(i),t.then(o=>{o.onclose=()=>t=void 0},()=>{t=void 0}),t},"getDB");return(i,o)=>n().then(a=>o(a.transaction(e,i).objectStore(e)))}s(Fn,"createStore");var Cr;function vr(){return Cr||(Cr=Fn("keyval-store","keyval")),Cr}s(vr,"defaultGetStore");function Se(r,e=vr()){return e("readonly",t=>ke(t.get(r)))}s(Se,"get");function Pr(r,e,t=vr()){return t("readwrite",n=>(n.put(e,r),ke(n.transaction)))}s(Pr,"set");function Br(r,e=vr()){return e("readwrite",t=>(r.forEach(n=>t.delete(n)),ke(t.transaction)))}s(Br,"delMany");var O=globalThis.crypto,Dr={keyTypes:{"bls12-381":{magicBytes:new Uint8Array([234,1]),verify:s(()=>{throw new Error("Not implemented")},"verify")},rsa:{magicBytes:new Uint8Array([0,245,2]),verify:Wn},ed25519:{magicBytes:new Uint8Array([237,1]),verify:Vn}}};async function Vn({message:r,publicKey:e,signature:t}){let n=r;typeof r=="string"&&(n=E(r,"utf8"));let i=t;typeof t=="string"&&(i=E(t,"base64pad"));let o=e;if(typeof e=="string"&&(o=gt(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 O.subtle.importKey("raw",h(o),{name:"Ed25519"},!1,["verify"]);return O.subtle.verify({name:"Ed25519"},a,h(i),h(n))}s(Vn,"ed25519Verify");async function Wn({message:r,publicKey:e,signature:t}){let n=e;return typeof e=="string"&&(n=gt(e).publicKey),_r.verify(r,t,await O.subtle.importKey("spki",h(n),{name:ue,hash:mr},!1,["verify"]),8)}s(Wn,"rsaVerify");var _r={verify:s(async function(e,t,n,i=pe,o=wr){return O.subtle.verify({name:ue},typeof n=="string"?await Tr(n,o,"signing"):n,Ne(t),he(e,i))},"rsaVerify"),sign:s(async function(e,t,n=pe){return O.subtle.sign({name:ue},t,he(e,n))},"sign"),encrypt:s(async function(e,t,n=pe,i=wr){let o;return typeof t=="string"?o=await Tr(t,i,"exchange"):o=t instanceof Uint8Array?await Tr(h(t),i,"exchange"):t,O.subtle.encrypt({name:fe},o,he(e,n))},"rsaEncrypt"),decrypt:s(async function(e,t){let n=Me(t)?t:await Yn(t,["decrypt"]),i;typeof e=="string"?i=E(e,"base64pad"):i=e;let o=await O.subtle.decrypt({name:fe},n,i instanceof Uint8Array?h(i):i);return new Uint8Array(o)},"rsaDecrypt")};async function Tr(r,e,t){Xn(t);let n=t==="exchange"?fe:ue,i=t==="exchange"?["encrypt"]:["verify"],o=typeof r=="string"?R($n(r)):r;return O.subtle.importKey("spki",o,{name:n,hash:{name:e}},!0,i)}s(Tr,"rsaImportPublicKey");function Xn(r){jn(r,["signing","exchange"],ft)}s(Xn,"checkValidKeyUse");function jn(r,e,t){if(!e.some(i=>i===r))throw t}s(jn,"checkValid");function $n(r){return r.replace(`-----BEGIN PUBLIC KEY-----
2
2
  `,"").replace(`
3
- -----END PUBLIC KEY-----`,"")}s(zn,"stripKeyHeader");function _e(r){return typeof CryptoKey<"u"?r instanceof CryptoKey:Ct(r,"algorithm")&&Ct(r,"extractable")&&Ct(r,"type")}s(_e,"isCryptoKey");function Ct(r,e){return typeof r=="object"&&r!=null&&e in r}s(Ct,"hasProp");function Hn(r,e){return k.subtle.importKey("spki",r instanceof Uint8Array?l(r):r,{name:se,hash:ft},!1,e)}s(Hn,"importRsaKey");async function Bt(r,e="rsa"){let t;if(r instanceof CryptoKey){e=r.algorithm.name.includes("RSA")?"rsa":"ed25519";let o=e==="ed25519"?"raw":"spki",a=await k.subtle.exportKey(o,r);t=new Uint8Array(a)}else t=r;let n=Pt.keyTypes[e]?.magicBytes;if(!n)throw new Error(`Key type '${e}' not supported, available types: ${Object.keys(Pt.keyTypes).join(", ")}`);let i=ke([n,t]);return $+A(i,"base58btc")}s(Bt,"publicKeyToDid");async function xe(r){return r instanceof CryptoKey?await k.subtle.exportKey("spki",r):await k.subtle.exportKey("spki",r.publicKey)}s(xe,"getPublicKeyAsArrayBuffer");function yr(r){if(!r.startsWith($))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=r.substring($.length),t=S(e,"base58btc"),n=Object.entries(Pt.keyTypes).find(([o,a])=>Ae(l(t),l(a.magicBytes)));if(!n)throw new Error("Unsupported key algorithm.");let i=t.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(yr,"didToPublicKey");var q=globalThis.crypto,H={create(r={alg:N,length:Y}){let e=r.length||Y,t=r.alg||N,n=r.extractable??!0;return q.subtle.generateKey({name:t,length:e},n,["encrypt","decrypt"])},export:Object.assign(async r=>{let e=await q.subtle.exportKey("raw",r);return new Uint8Array(e)},{asString:s(async(r,e)=>{let t=await H.export(r);return e?A(t,e):T(t)},"asString")}),import(r,e){return Tt(typeof r=="string"?M(r):r,void 0,e)},async exportAsString(r){let e=await H.export(r);return T(e)},encrypt:Gn,async decrypt(r,e,t){let n=_e(e)?e:await Tt(e),i=t?await q.subtle.decrypt({name:ce,iv:l(t)},n,typeof r=="string"?l(S(r,"base64pad")):r instanceof Uint8Array?l(r):r):await Vn(r,n);return new Uint8Array(i)}};function Tt(r,e,t=!0){return q.subtle.importKey("raw",r instanceof Uint8Array?l(r):r,{name:ce,length:e||256},t,["encrypt","decrypt"])}s(Tt,"importAesKey");async function Gn(r,e,t,n){let i=_e(e)?e:await Tt(e),o=n?await q.subtle.encrypt({name:ce,iv:l(n)},i,r instanceof ArrayBuffer?r:l(typeof r=="string"?S(r):r)):await Fn(r,i);return t&&t==="arraybuffer"?o:new Uint8Array(o)}s(Gn,"encrypt");async function Fn(r,e,t){let n=ye(r,t?.charsize??ae),i=typeof e=="string"?await bt(e,t):e,o=t?.iv||ar(L),a=await q.subtle.encrypt({name:ce,iv:o},i,n);return De(o,a)}s(Fn,"encryptBytes");async function Vn(r,e,t){let n=Te(r),i=typeof e=="string"?await bt(e,t):e,o=n.slice(0,L),a=n.slice(L);return await q.subtle.decrypt({name:N,iv:o},i,a)}s(Vn,"decryptBytes");var X=class X{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:t}=e,n=this.constructor;this.DID=e.did,this._exchangeKey=t.exchange,this._writeKey=t.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 pe;return this._exchangeKey}get writeKey(){if(this.destroyed||!this._writeKey)throw new pe;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 t=>{let n=await xe(this.writeKey),i=new Uint8Array(n);return t?A(i,t):T(i)},"asString")})}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await xe(this.exchangeKey),i=new Uint8Array(n);return t?A(i,t):T(i)},"asString")})}get privateWriteKey(){return this.writeKey.privateKey}get privateExchangeKey(){return this.exchangeKey.privateKey}get deviceName(){return X.deviceName(this.DID)}static deviceName(e){return Wn(e)}async persist(){if(this.destroyed)throw new pe;this.isSessionOnly||(await Promise.all([Et(this.exchangeKeyName,this.exchangeKey),Et(this.writeKeyName,this.writeKey)]),this.hasPersisted=!0)}async delete(){let e=this.exchangeKeyName,t=this.writeKeyName;await Ut([e,t]),this.constructor._invalidate(e,t),this._destroy()}_destroy(){this.destroyed=!0,this.hasPersisted=!1,this._exchangeKey=null,this._writeKey=null}static _invalidate(e,t){let n=this._instance;n&&n.exchangeKeyName===e&&n.writeKeyName===t&&(n._destroy(),this._instance=null)}static async delete(e={}){let t=e.encryptionKeyName||this.EXCHANGE_KEY_NAME,n=e.writeKeyName||this.WRITE_KEY_NAME;await Ut([t,n]),this._invalidate(t,n)}async getDeviceName(){return X.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 _keyNames(e){return e?{exchangeKeyName:`${e}.${this.EXCHANGE_KEY_NAME}`,writeKeyName:`${e}.${this.WRITE_KEY_NAME}`}:{exchangeKeyName:this.EXCHANGE_KEY_NAME,writeKeyName:this.WRITE_KEY_NAME}}static async create(e,t,n){let i=n?.exchangeKeys||await this._createExchangeKeys(t),o=n?.writeKeys||await this._createWriteKeys(t),a=await xe(o),c=await Bt(new Uint8Array(a),this.TYPE==="ecc"?"ed25519":"rsa"),{exchangeKeyName:u,writeKeyName:f}=this._keyNames(n?.dbKey),h=new this({keys:{exchange:i,write:o},did:c,hasPersisted:!1,isSessionOnly:!!e,exchangeKeyName:u,writeKeyName:f});return this._instance=h,h}static async exist(e={}){let t=await we(e.writeKeyName||this.WRITE_KEY_NAME),n=await we(e.encryptionKeyName||this.EXCHANGE_KEY_NAME);return!(!t||!n)}static async load(e={session:!1}){let t=e.persist!==!1,n=this._keyNames(e.dbKey),i=e.encryptionKeyName||n.exchangeKeyName,o=e.writeKeyName||n.writeKeyName,a=this._instance;if(a&&!a.destroyed&&a.exchangeKeyName===i&&a.writeKeyName===o)return t&&!a.hasPersisted&&await a.persist(),a;let c=!0,u=await we(i),f=await we(o);u||(c=!1,u=await this._createExchangeKeys(e.extractable)),f||(c=!1,f=await this._createWriteKeys(e.extractable));let h=await xe(f),x=await Bt(new Uint8Array(h),this.TYPE==="ecc"?"ed25519":"rsa"),K=new this({keys:{exchange:u,write:f},did:x,hasPersisted:c,isSessionOnly:!!e.session,exchangeKeyName:i,writeKeyName:o});return this._instance=K,t&&!c&&await K.persist(),K}};s(X,"AbstractKeys"),y(X,"EXCHANGE_KEY_NAME"),y(X,"WRITE_KEY_NAME"),y(X,"_instance");var Ne=X;async function pr(r,e){let{content:t,publicKey:n}=r,i=e||await H.create(),o=await H.encrypt(typeof t=="string"?S(t):t,typeof i=="string"?await H.import(i):i),a=await Dt({key:i,publicKey:n});return De(a,o)}s(pr,"encryptTo");pr.asString=async function(r,e){let t=await pr(r,e);return A(new Uint8Array(t),"base64pad")};async function Dt({key:r,publicKey:e},t){let n;r instanceof CryptoKey?n=await H.export(r):n=r;let i=await vt.encrypt(n,e);return t&&t==="arraybuffer"?i:new Uint8Array(i)}s(Dt,"encryptKeyTo");Dt.asString=async function({key:r,publicKey:e},t){let n=await Dt({key:r,publicKey:e});return t?A(n,t):T(n)};async function Wn(r){let e=await sr(new TextEncoder().encode(r.normalize("NFD")));return A(e,"base32").slice(0,32)}s(Wn,"getDeviceName");var d=globalThis.crypto;function j(r){return new Uint8Array(r).buffer}s(j,"toArrayBuffer");var D=class D extends Ne{static async create(e,t,n){return await super.create(e,t,n)}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await ue(this.exchangeKey),i=new Uint8Array(n);return t?A(i,t):T(n)},"asString")})}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await ue(this.writeKey),i=new Uint8Array(n);return t?A(i,t):T(n)},"asString")})}static async _createExchangeKeys(e=!1){return await d.subtle.generateKey({name:Pe},e,["deriveKey","deriveBits"])}static async _createWriteKeys(e=!1){return await d.subtle.generateKey({name:ie},e,["sign","verify"])}static async load(e={session:!1}){return super.load(e)}async toJson(e){let t=this.DID,n=await ue(this.exchangeKey);return{publicExchangeKey:e?A(new Uint8Array(n),e):T(n),DID:t}}async wrap(e,t,n){let i=await D._createExchangeKeys(!1),o=await ue(i),a=new Uint8Array(o),c=new Uint8Array(await d.subtle.exportKey("raw",t)),u=n||"key-wrap",f=d.getRandomValues(new Uint8Array(P)),h=await Ke(i.privateKey,t,f,ur(a,c,u)),x,K=!1;if(e instanceof CryptoKey){let B=await d.subtle.exportKey("raw",e);x=new Uint8Array(B),K=!0}else typeof e=="string"?(x=S(e,"base64pad"),K=!0):x=e;let R=d.getRandomValues(new Uint8Array(L)),p=await d.subtle.encrypt({name:N,iv:R},h,j(x));K&&x.fill(0);let g=new Uint8Array(R),v=new Uint8Array(p),E=1+P+g.length+v.length,b=new Uint8Array(E);b[0]=mt,b.set(f,1),b.set(g,1+P),b.set(v,1+P+g.length);let w=fr(a,c,b,u),C=await this.sign(w);return{enc:T(a),wrappedKey:T(b),signature:A(C,"base64pad")}}async unwrap(e,t,n={}){let{enc:i,wrappedKey:o,signature:a}=e,c=n.info,u=n.extractable??!0;if(!t)throw new Error("`unwrap` requires the DID of the sender");if(!a)throw new Error("The wrapped key is not signed");let f=S(i,"base64pad");if(f.length!==V)throw new Error(`\`enc\` must be a ${V}-byte X25519 public key, got ${f.length} bytes`);let h=new Uint8Array(M(o)),x=c||"key-wrap",K=1+P+L+tr;if(h.length<K)throw new Error(`Wrapped key must be at least ${K} bytes, got ${h.length} bytes`);let R=h[0];if(R!==mt)throw new Error(`Unsupported wrapped key format version: ${R}`);let p=new Uint8Array(await ue(this.exchangeKey)),g=fr(f,p,h,x);if(!await Xn(g,a,t))throw new Error("Invalid signature for the wrapped key");let E=await Le(i,"X25519","exchange"),b=h.slice(1,1+P),w=h.slice(1+P,1+P+L),C=h.slice(1+P+L),B=await Ke(this.exchangeKey.privateKey,E,b,ur(f,p,x)),O=await d.subtle.decrypt({name:N,iv:w},B,j(C));return await d.subtle.importKey("raw",O,{name:N},u,["encrypt","decrypt"])}async encrypt(e,t,n,i,o){let a=d.getRandomValues(new Uint8Array(P)),c=t||this.exchangeKey.publicKey,u;typeof c=="string"?u=await Le(c,"X25519","exchange"):u=c;let f=await D._createExchangeKeys(!1),h=i?i instanceof CryptoKey?i:await H.import(i):await Ke(f.privateKey,u,a,n||D.INFO,o),x=d.getRandomValues(new Uint8Array(L)),K=typeof e=="string"?new TextEncoder().encode(e):e,R=await d.subtle.encrypt({name:N,iv:x},h,j(K)),p=new Uint8Array(await ue(f)),g=new Uint8Array(a),v=new Uint8Array(x),E=new Uint8Array(R),b=p.length+g.length+v.length+E.length,w=new Uint8Array(b);return w.set(p,0),w.set(g,p.length),w.set(v,p.length+g.length),w.set(E,p.length+g.length+v.length),w}async encryptAsString(e,t,n,i,o){let a=await this.encrypt(e,t,n||D.INFO,i,o);return A(new Uint8Array(a),"base64pad")}async decrypt(e,t,n,i){let o=be(e,M),a=o.slice(0,V),c=await d.subtle.importKey("raw",a,{name:Pe},!0,[]),u=o.slice(V,V+P),f=o.slice(V+P,V+P+L),h=o.slice(V+P+L),{privateKey:x}=this.exchangeKey,K=i?i instanceof CryptoKey?i:await H.import(i):await Ke(x,c,u,n||D.INFO);return await d.subtle.decrypt({name:t||N,iv:f},K,h)}async decryptAsString(e,t,n,i){let o=await this.decrypt(e,t,n,i);return A(new Uint8Array(o))}async getAesKey(e,t,n){e||(e=this.publicExchangeKey);let i;typeof e=="string"?i=await Le(e,"X25519","exchange"):i=e;let o=n?new Uint8Array(typeof n=="string"?M(n):n):d.getRandomValues(new Uint8Array(P)),a=await Ke(this.exchangeKey.privateKey,i,o,t||D.INFO);return Object.assign(a,{salt:T(o)})}async sign(e,t){let n=new TextEncoder,i;typeof e=="string"?i=n.encode(e):e instanceof ArrayBuffer?i=new Uint8Array(e):i=e;let o=await d.subtle.sign({name:ie},this.writeKey.privateKey,j(i));return new Uint8Array(o)}async signAsString(e,t){let n=await this.sign(e,t);return A(n,"base64pad")}};s(D,"EccKeys"),y(D,"TYPE","ecc"),y(D,"EXCHANGE_KEY_NAME",rr),y(D,"WRITE_KEY_NAME",nr),y(D,"INFO","keys");var J=D;Object.assign(J.prototype.sign,{asString:s(async function(r,e){let t=await this.sign(r,e);return A(t,"base64pad")},"asString")});async function ue(r,e="raw"){return await d.subtle.exportKey(e,r.publicKey)}s(ue,"exportPublicKey");async function Le(r,e,t){cr(t);let n=t==="exchange"?Pe:ie,i=t==="exchange"?[]:["verify"],o=M(r),a=e==="X25519"?{name:n}:{name:n,namedCurve:e};return d.subtle.importKey("raw",o,a,!0,i)}s(Le,"importPublicKey");var Lo={EccKeys:J,importPublicKey:Le};Object.assign(J.prototype.encrypt,{asString:s(async function(r,e,t,n,i){return this.encryptAsString(r,e,t,n,i)},"asString")});Object.assign(J.prototype.decrypt,{asString:s(async function(r,e){return this.decryptAsString(r,e)},"asString")});Object.assign(J.prototype.sign,{asString:s(async function(r,e){return this.signAsString(r,e)},"asString")});async function Xn(r,e,t){try{let n=or(t);if(n.type!=="ed25519")throw new Error(`Expected Ed25519 key for ECC verification, got ${n.type}`);let i=n.publicKey.slice(-32),o=await d.subtle.importKey("raw",i,{name:ie},!0,["verify"]),a=new TextEncoder,c;typeof r=="string"?c=a.encode(r):r instanceof ArrayBuffer?c=new Uint8Array(r):c=r;let u;return typeof e=="string"?u=new Uint8Array(M(e)):u=e,await d.subtle.verify({name:ie},o,j(u),j(c))}catch{return!1}}s(Xn,"verify");function ur(r,e,t){let n=new TextEncoder().encode(t),i=new Uint8Array(r.length+e.length+n.length);return i.set(r,0),i.set(e,r.length),i.set(n,r.length+e.length),i}s(ur,"wrapKekInfo");function fr(r,e,t,n){let i=new TextEncoder().encode(n),o=new Uint8Array(4);new DataView(o.buffer).setUint32(0,t.length);let a=new Uint8Array(r.length+e.length+o.length+t.length+i.length),c=0;return a.set(r,c),c+=r.length,a.set(e,c),c+=e.length,a.set(o,c),c+=o.length,a.set(t,c),c+=t.length,a.set(i,c),a}s(fr,"wrapSignData");async function Ke(r,e,t,n,i){let o=new TextEncoder,a=typeof n=="string"?o.encode(n):n,c=await d.subtle.deriveBits({name:"X25519",public:e},r,256),u=await d.subtle.importKey("raw",c,"HKDF",!1,["deriveKey"]);return d.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:t instanceof Uint8Array?j(t):t,info:j(a)},u,{name:"AES-GCM",length:i||Y},!1,["encrypt","decrypt"])}s(Ke,"deriveKey");export{J as EccKeys,Lo as default,ue as exportPublicKey,Le as importPublicKey,Xn as verify};
3
+ -----END PUBLIC KEY-----`,"")}s($n,"stripKeyHeader");function Me(r){return typeof CryptoKey<"u"?r instanceof CryptoKey:Ir(r,"algorithm")&&Ir(r,"extractable")&&Ir(r,"type")}s(Me,"isCryptoKey");function Ir(r,e){return typeof r=="object"&&r!=null&&e in r}s(Ir,"hasProp");function Yn(r,e){return O.subtle.importKey("spki",r instanceof Uint8Array?h(r):r,{name:fe,hash:mr},!1,e)}s(Yn,"importRsaKey");async function Nr(r,e="rsa"){let t;if(r instanceof CryptoKey){e=r.algorithm.name.includes("RSA")?"rsa":"ed25519";let o=e==="ed25519"?"raw":"spki",a=await O.subtle.exportKey(o,r);t=new Uint8Array(a)}else t=r;let n=Dr.keyTypes[e]?.magicBytes;if(!n)throw new Error(`Key type '${e}' not supported, available types: ${Object.keys(Dr.keyTypes).join(", ")}`);let i=Ge([n,t]);return Z+A(i,"base58btc")}s(Nr,"publicKeyToDid");async function Ce(r){return r instanceof CryptoKey?await O.subtle.exportKey("spki",r):await O.subtle.exportKey("spki",r.publicKey)}s(Ce,"getPublicKeyAsArrayBuffer");function gt(r){if(!r.startsWith(Z))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=r.substring(Z.length),t=E(e,"base58btc"),n=Object.entries(Dr.keyTypes).find(([o,a])=>Ee(h(t),h(a.magicBytes)));if(!n)throw new Error("Unsupported key algorithm.");let i=t.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(gt,"didToPublicKey");var ee=globalThis.crypto,G={create(r={alg:k,length:Q}){let e=r.length||Q,t=r.alg||k,n=r.extractable??!0;return ee.subtle.generateKey({name:t,length:e},n,["encrypt","decrypt"])},export:Object.assign(async r=>{let e=await ee.subtle.exportKey("raw",r);return new Uint8Array(e)},{asString:s(async(r,e)=>{let t=await G.export(r);return e?A(t,e):P(t)},"asString")}),import(r,e){return Lr(typeof r=="string"?R(r):r,void 0,e)},async exportAsString(r){let e=await G.export(r);return P(e)},encrypt:qn,async decrypt(r,e,t){let n=Me(e)?e:await Lr(e),i=t?await ee.subtle.decrypt({name:le,iv:h(t)},n,typeof r=="string"?h(E(r,"base64pad")):r instanceof Uint8Array?h(r):r):await Zn(r,n);return new Uint8Array(i)}};function Lr(r,e,t=!0){return ee.subtle.importKey("raw",r instanceof Uint8Array?h(r):r,{name:le,length:e||256},t,["encrypt","decrypt"])}s(Lr,"importAesKey");async function qn(r,e,t,n){let i=Me(e)?e:await Lr(e),o=n?await ee.subtle.encrypt({name:le,iv:h(n)},i,r instanceof ArrayBuffer?r:h(typeof r=="string"?E(r):r)):await Jn(r,i);return t&&t==="arraybuffer"?o:new Uint8Array(o)}s(qn,"encrypt");async function Jn(r,e,t){let n=he(r,t?.charsize??pe),i=typeof e=="string"?await Ur(e,t):e,o=t?.iv||lt(M),a=await ee.subtle.encrypt({name:le,iv:o},i,n);return Le(o,a)}s(Jn,"encryptBytes");async function Zn(r,e,t){let n=Ne(r),i=typeof e=="string"?await Ur(e,t):e,o=n.slice(0,M),a=n.slice(M);return await ee.subtle.decrypt({name:k,iv:o},i,a)}s(Zn,"decryptBytes");var $=class ${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:t}=e,n=this.constructor;this.DID=e.did,this._exchangeKey=t.exchange,this._writeKey=t.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 ge;return this._exchangeKey}get writeKey(){if(this.destroyed||!this._writeKey)throw new ge;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 t=>{let n=await Ce(this.writeKey),i=new Uint8Array(n);return t?A(i,t):P(i)},"asString")})}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await Ce(this.exchangeKey),i=new Uint8Array(n);return t?A(i,t):P(i)},"asString")})}get privateWriteKey(){return this.writeKey.privateKey}get privateExchangeKey(){return this.exchangeKey.privateKey}get deviceName(){return $.deviceName(this.DID)}static deviceName(e){return Qn(e)}async persist(){if(this.destroyed)throw new ge;this.isSessionOnly||(await Promise.all([Pr(this.exchangeKeyName,this.exchangeKey),Pr(this.writeKeyName,this.writeKey)]),this.hasPersisted=!0)}async delete(){let e=this.exchangeKeyName,t=this.writeKeyName;await Br([e,t]),this.constructor._invalidate(e,t),this._destroy()}_destroy(){this.destroyed=!0,this.hasPersisted=!1,this._exchangeKey=null,this._writeKey=null}static _invalidate(e,t){let n=this._instance;n&&n.exchangeKeyName===e&&n.writeKeyName===t&&(n._destroy(),this._instance=null)}static async delete(e={}){let t=e.encryptionKeyName||this.EXCHANGE_KEY_NAME,n=e.writeKeyName||this.WRITE_KEY_NAME;await Br([t,n]),this._invalidate(t,n)}async getDeviceName(){return $.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 _keyNames(e){return e?{exchangeKeyName:`${e}.${this.EXCHANGE_KEY_NAME}`,writeKeyName:`${e}.${this.WRITE_KEY_NAME}`}:{exchangeKeyName:this.EXCHANGE_KEY_NAME,writeKeyName:this.WRITE_KEY_NAME}}static async create(e,t,n){let i=n?.exchangeKeys||await this._createExchangeKeys(t),o=n?.writeKeys||await this._createWriteKeys(t),a=await Ce(o),c=await Nr(new Uint8Array(a),this.TYPE==="ecc"?"ed25519":"rsa"),{exchangeKeyName:f,writeKeyName:p}=this._keyNames(n?.dbKey),l=new this({keys:{exchange:i,write:o},did:c,hasPersisted:!1,isSessionOnly:!!e,exchangeKeyName:f,writeKeyName:p});return this._instance=l,l}static async exist(e={}){let t=await Se(e.writeKeyName||this.WRITE_KEY_NAME),n=await Se(e.encryptionKeyName||this.EXCHANGE_KEY_NAME);return!(!t||!n)}static async load(e={session:!1}){let t=e.persist!==!1,n=this._keyNames(e.dbKey),i=e.encryptionKeyName||n.exchangeKeyName,o=e.writeKeyName||n.writeKeyName,a=this._instance;if(a&&!a.destroyed&&a.exchangeKeyName===i&&a.writeKeyName===o)return t&&!a.hasPersisted&&await a.persist(),a;let c=!0,f=await Se(i),p=await Se(o);f||(c=!1,f=await this._createExchangeKeys(e.extractable)),p||(c=!1,p=await this._createWriteKeys(e.extractable));let l=await Ce(p),w=await Nr(new Uint8Array(l),this.TYPE==="ecc"?"ed25519":"rsa"),b=new this({keys:{exchange:f,write:p},did:w,hasPersisted:c,isSessionOnly:!!e.session,exchangeKeyName:i,writeKeyName:o});return this._instance=b,t&&!c&&await b.persist(),b}};s($,"AbstractKeys"),y($,"EXCHANGE_KEY_NAME"),y($,"WRITE_KEY_NAME"),y($,"_instance");var Re=$;async function dt(r,e){let{content:t,publicKey:n}=r,i=e||await G.create(),o=await G.encrypt(typeof t=="string"?E(t):t,typeof i=="string"?await G.import(i):i),a=await kr({key:i,publicKey:n});return Le(a,o)}s(dt,"encryptTo");dt.asString=async function(r,e){let t=await dt(r,e);return A(new Uint8Array(t),"base64pad")};async function kr({key:r,publicKey:e},t){let n;r instanceof CryptoKey?n=await G.export(r):n=r;let i=await _r.encrypt(n,e);return t&&t==="arraybuffer"?i:new Uint8Array(i)}s(kr,"encryptKeyTo");kr.asString=async function({key:r,publicKey:e},t){let n=await kr({key:r,publicKey:e});return t?A(n,t):P(n)};async function Qn(r){let e=await ut(new TextEncoder().encode(r.normalize("NFD")));return A(e,"base32").slice(0,32)}s(Qn,"getDeviceName");var d=globalThis.crypto;function Y(r){return new Uint8Array(r).buffer}s(Y,"toArrayBuffer");var I=class I extends Re{static async create(e,t,n){return await super.create(e,t,n)}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await de(this.exchangeKey),i=new Uint8Array(n);return t?A(i,t):P(n)},"asString")})}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await de(this.writeKey),i=new Uint8Array(n);return t?A(i,t):P(n)},"asString")})}static async _createExchangeKeys(e=!1){return await d.subtle.generateKey({name:Ie},e,["deriveKey","deriveBits"])}static async _createWriteKeys(e=!1){return await d.subtle.generateKey({name:ye},e,["sign","verify"])}static async load(e={session:!1}){return super.load(e)}async toJson(e){let t=this.DID,n=await de(this.exchangeKey);return{publicExchangeKey:e?A(new Uint8Array(n),e):P(n),DID:t}}async wrap(e,t,n){let i=await I._createExchangeKeys(!1),o=await de(i),a=new Uint8Array(o),c=new Uint8Array(await d.subtle.exportKey("raw",t)),f=n||"key-wrap",p=d.getRandomValues(new Uint8Array(U)),l=await ve(i.privateKey,t,p,mt(a,c,f)),w,b=!1;if(e instanceof CryptoKey){let C=await d.subtle.exportKey("raw",e);w=new Uint8Array(C),b=!0}else typeof e=="string"?(w=E(e,"base64pad"),b=!0):w=e;let z=d.getRandomValues(new Uint8Array(M)),D=await d.subtle.encrypt({name:k,iv:z},l,Y(w));b&&w.fill(0);let B=new Uint8Array(z),F=new Uint8Array(D),u=1+U+B.length+F.length,g=new Uint8Array(u);g[0]=Kr,g.set(p,1),g.set(B,1+U),g.set(F,1+U+B.length);let K=At(a,c,g,f),S=await this.sign(K);return{enc:P(a),wrappedKey:P(g),signature:A(S,"base64pad")}}async unwrap(e,t,n={}){let{enc:i,wrappedKey:o,signature:a}=e,c=n.info,f=n.extractable??!0;if(!t)throw new Error("`unwrap` requires the DID of the sender");if(!a)throw new Error("The wrapped key is not signed");let p=E(i,"base64pad");if(p.length!==W)throw new Error(`\`enc\` must be a ${W}-byte X25519 public key, got ${p.length} bytes`);let l=new Uint8Array(R(o)),w=c||"key-wrap",b=1+U+M+at;if(l.length<b)throw new Error(`Wrapped key must be at least ${b} bytes, got ${l.length} bytes`);let z=l[0];if(z!==Kr)throw new Error(`Unsupported wrapped key format version: ${z}`);let D=new Uint8Array(await de(this.exchangeKey)),B=At(p,D,l,w);if(!await ei(B,a,t))throw new Error("Invalid signature for the wrapped key");let u=await Oe(i,"X25519","exchange"),g=l.slice(1,1+U),K=l.slice(1+U,1+U+M),S=l.slice(1+U+M),C=await ve(this.exchangeKey.privateKey,u,g,mt(p,D,w)),_=await d.subtle.decrypt({name:k,iv:K},C,Y(S));return await d.subtle.importKey("raw",_,{name:k},f,["encrypt","decrypt"])}async encrypt(e,t,n,i,o){let a=d.getRandomValues(new Uint8Array(U)),c=t||this.exchangeKey.publicKey,f;typeof c=="string"?f=await Oe(c,"X25519","exchange"):f=c;let p=await I._createExchangeKeys(!1),l=i?i instanceof CryptoKey?i:await G.import(i):await ve(p.privateKey,f,a,n||I.INFO,o),w=d.getRandomValues(new Uint8Array(M)),b=typeof e=="string"?new TextEncoder().encode(e):e,z=await d.subtle.encrypt({name:k,iv:w},l,Y(b)),D=new Uint8Array(await de(p)),B=new Uint8Array(a),F=new Uint8Array(w),u=new Uint8Array(z),g=D.length+B.length+F.length+u.length,K=new Uint8Array(g);return K.set(D,0),K.set(B,D.length),K.set(F,D.length+B.length),K.set(u,D.length+B.length+F.length),K}async encryptAsString(e,t,n,i,o){let a=await this.encrypt(e,t,n||I.INFO,i,o);return A(new Uint8Array(a),"base64pad")}async decrypt(e,t,n,i){let o=Ue(e,R),a=o.slice(0,W),c=await d.subtle.importKey("raw",a,{name:Ie},!0,[]),f=o.slice(W,W+U),p=o.slice(W+U,W+U+M),l=o.slice(W+U+M),{privateKey:w}=this.exchangeKey,b=i?i instanceof CryptoKey?i:await G.import(i):await ve(w,c,f,n||I.INFO);return await d.subtle.decrypt({name:t||k,iv:p},b,l)}async decryptAsString(e,t,n,i){let o=await this.decrypt(e,t,n,i);return A(new Uint8Array(o))}async getAesKey(e,t,n){e||(e=this.publicExchangeKey);let i;typeof e=="string"?i=await Oe(e,"X25519","exchange"):i=e;let o=n?new Uint8Array(typeof n=="string"?R(n):n):d.getRandomValues(new Uint8Array(U)),a=await ve(this.exchangeKey.privateKey,i,o,t||I.INFO);return Object.assign(a,{salt:P(o)})}async sign(e,t){let n=new TextEncoder,i;typeof e=="string"?i=n.encode(e):e instanceof ArrayBuffer?i=new Uint8Array(e):i=e;let o=await d.subtle.sign({name:ye},this.writeKey.privateKey,Y(i));return new Uint8Array(o)}async signAsString(e,t){let n=await this.sign(e,t);return A(n,"base64pad")}};s(I,"EccKeys"),y(I,"TYPE","ecc"),y(I,"EXCHANGE_KEY_NAME",ct),y(I,"WRITE_KEY_NAME",yt),y(I,"INFO","keys");var re=I;Object.assign(re.prototype.sign,{asString:s(async function(r,e){let t=await this.sign(r,e);return A(t,"base64pad")},"asString")});async function de(r,e="raw"){return await d.subtle.exportKey(e,r.publicKey)}s(de,"exportPublicKey");async function Oe(r,e,t){ht(t);let n=t==="exchange"?Ie:ye,i=t==="exchange"?[]:["verify"],o=R(r),a=e==="X25519"?{name:n}:{name:n,namedCurve:e};return d.subtle.importKey("raw",o,a,!0,i)}s(Oe,"importPublicKey");var Qo={EccKeys:re,importPublicKey:Oe};Object.assign(re.prototype.encrypt,{asString:s(async function(r,e,t,n,i){return this.encryptAsString(r,e,t,n,i)},"asString")});Object.assign(re.prototype.decrypt,{asString:s(async function(r,e){return this.decryptAsString(r,e)},"asString")});Object.assign(re.prototype.sign,{asString:s(async function(r,e){return this.signAsString(r,e)},"asString")});async function ei(r,e,t){try{let n=pt(t);if(n.type!=="ed25519")throw new Error(`Expected Ed25519 key for ECC verification, got ${n.type}`);let i=n.publicKey.slice(-32),o=await d.subtle.importKey("raw",i,{name:ye},!0,["verify"]),a=new TextEncoder,c;typeof r=="string"?c=a.encode(r):r instanceof ArrayBuffer?c=new Uint8Array(r):c=r;let f;return typeof e=="string"?f=new Uint8Array(R(e)):f=e,await d.subtle.verify({name:ye},o,Y(f),Y(c))}catch{return!1}}s(ei,"verify");function mt(r,e,t){let n=new TextEncoder().encode(t),i=new Uint8Array(r.length+e.length+n.length);return i.set(r,0),i.set(e,r.length),i.set(n,r.length+e.length),i}s(mt,"wrapKekInfo");function At(r,e,t,n){let i=new TextEncoder().encode(n),o=new Uint8Array(4);new DataView(o.buffer).setUint32(0,t.length);let a=new Uint8Array(r.length+e.length+o.length+t.length+i.length),c=0;return a.set(r,c),c+=r.length,a.set(e,c),c+=e.length,a.set(o,c),c+=o.length,a.set(t,c),c+=t.length,a.set(i,c),a}s(At,"wrapSignData");async function ve(r,e,t,n,i){let o=new TextEncoder,a=typeof n=="string"?o.encode(n):n,c=await d.subtle.deriveBits({name:"X25519",public:e},r,256),f=await d.subtle.importKey("raw",c,"HKDF",!1,["deriveKey"]);return d.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:t instanceof Uint8Array?Y(t):t,info:Y(a)},f,{name:"AES-GCM",length:i||Q},!1,["encrypt","decrypt"])}s(ve,"deriveKey");export{re as EccKeys,Qo as default,de as exportPublicKey,Oe as importPublicKey,ei as verify};
4
4
  //# sourceMappingURL=index.min.js.map