@substrate-system/keys 0.2.43 → 0.3.0

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