@substrate-system/keys 0.3.1 → 0.3.3

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