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