@substrate-system/keys 0.2.44 → 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.
- package/README.md +27 -9
- package/dist/_base.cjs +11 -3
- package/dist/_base.cjs.map +2 -2
- package/dist/_base.d.ts +9 -3
- package/dist/_base.d.ts.map +1 -1
- package/dist/_base.js +11 -3
- package/dist/_base.js.map +2 -2
- package/dist/_base.min.cjs +1 -1
- package/dist/_base.min.cjs.map +3 -3
- package/dist/_base.min.js +2 -2
- package/dist/_base.min.js.map +3 -3
- package/dist/browser/index.js +14 -3
- package/dist/browser/index.min.js +2 -2
- package/dist/ecc/index.cjs +3 -0
- package/dist/ecc/index.cjs.map +2 -2
- package/dist/ecc/index.d.ts +4 -0
- package/dist/ecc/index.d.ts.map +1 -1
- package/dist/ecc/index.js +3 -0
- package/dist/ecc/index.js.map +2 -2
- package/dist/ecc/index.min.cjs.map +2 -2
- package/dist/ecc/index.min.js +2 -2
- package/dist/ecc/index.min.js.map +3 -3
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +3 -3
- package/dist/meta.json +8 -8
- package/dist/rsa/index.min.js +2 -2
- package/dist/rsa/index.min.js.map +3 -3
- package/package.json +1 -1
package/dist/meta.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"inputs": {
|
|
3
3
|
"src/_base.ts": {
|
|
4
|
-
"bytes":
|
|
4
|
+
"bytes": 19502,
|
|
5
5
|
"imports": [],
|
|
6
6
|
"format": "esm"
|
|
7
7
|
},
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"format": "esm"
|
|
42
42
|
},
|
|
43
43
|
"src/ecc/index.ts": {
|
|
44
|
-
"bytes":
|
|
44
|
+
"bytes": 25258,
|
|
45
45
|
"imports": [],
|
|
46
46
|
"format": "esm"
|
|
47
47
|
},
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"imports": [],
|
|
57
57
|
"exports": [],
|
|
58
58
|
"inputs": {},
|
|
59
|
-
"bytes":
|
|
59
|
+
"bytes": 25836
|
|
60
60
|
},
|
|
61
61
|
"dist/_base.js": {
|
|
62
62
|
"imports": [
|
|
@@ -114,10 +114,10 @@
|
|
|
114
114
|
"entryPoint": "src/_base.ts",
|
|
115
115
|
"inputs": {
|
|
116
116
|
"src/_base.ts": {
|
|
117
|
-
"bytesInOutput":
|
|
117
|
+
"bytesInOutput": 10581
|
|
118
118
|
}
|
|
119
119
|
},
|
|
120
|
-
"bytes":
|
|
120
|
+
"bytes": 11185
|
|
121
121
|
},
|
|
122
122
|
"dist/constants.js.map": {
|
|
123
123
|
"imports": [],
|
|
@@ -443,7 +443,7 @@
|
|
|
443
443
|
"imports": [],
|
|
444
444
|
"exports": [],
|
|
445
445
|
"inputs": {},
|
|
446
|
-
"bytes":
|
|
446
|
+
"bytes": 35310
|
|
447
447
|
},
|
|
448
448
|
"dist/ecc/index.js": {
|
|
449
449
|
"imports": [
|
|
@@ -488,10 +488,10 @@
|
|
|
488
488
|
"entryPoint": "src/ecc/index.ts",
|
|
489
489
|
"inputs": {
|
|
490
490
|
"src/ecc/index.ts": {
|
|
491
|
-
"bytesInOutput":
|
|
491
|
+
"bytesInOutput": 17934
|
|
492
492
|
}
|
|
493
493
|
},
|
|
494
|
-
"bytes":
|
|
494
|
+
"bytes": 18466
|
|
495
495
|
},
|
|
496
496
|
"dist/rsa/index.js.map": {
|
|
497
497
|
"imports": [],
|
package/dist/rsa/index.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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 w=(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={};w(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 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 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,f=t.charAt(0),b=Math.log(c)/Math.log(256),A=Math.log(256)/Math.log(c);function M(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 x=0,F=0,U=0,P=p.length;U!==P&&p[U]===0;)U++,x++;for(var B=(P-U)*A+1>>>0,K=new Uint8Array(B);U!==P;){for(var v=p[U],R=0,S=B-1;(v!==0||R<F)&&S!==-1;S--,R++)v+=256*K[S]>>>0,K[S]=v%c>>>0,v=v/c>>>0;if(v!==0)throw new Error("Non-zero carry");F=R,U++}for(var D=B-F;D!==B&&K[D]===0;)D++;for(var Se=f.repeat(x);D<B;++D)Se+=t.charAt(K[D]);return Se}o(M,"encode");function Z(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var x=0;if(p[x]!==" "){for(var F=0,U=0;p[x]===f;)F++,x++;for(var P=(p.length-x)*b+1>>>0,B=new Uint8Array(P);p[x];){var K=r[p.charCodeAt(x)];if(K===255)return;for(var v=0,R=P-1;(K!==0||v<U)&&R!==-1;R--,v++)K+=c*B[R]>>>0,B[R]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");U=v,x++}if(p[x]!==" "){for(var S=P-U;S!==P&&B[S]===0;)S++;for(var D=new Uint8Array(F+(P-S)),Se=F;S!==P;)D[Se++]=B[S++];return D}}}o(Z,"decodeUnsafe");function ot(p){var x=Z(p);if(x)return x;throw new Error(`Non-${e} character`)}return o(ot,"decode"),{encode:M,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(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,f=0,b=0;for(let A=0;A<s;++A){let M=i[t[A]];if(M===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|M,c+=r,c>=8&&(c-=8,a[b++]=255&f>>c)}if(c>=r||(255&f<<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 f=0;f<t.length;++f)for(c=c<<8|t[f],a+=8;a>r;)a-=r,s+=e[i&c>>a];if(a!==0&&(s+=e[i&c<<r-a]),n)for(;(s.length*r&7)!==0;)s+="=";return s}o(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={};w(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={};w(Ye,{base2:()=>gt});var gt=l({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Xe={};w(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={};w($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={};w(qe,{base36:()=>ue,base36upper:()=>Tt});var ue=z({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Tt=z({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Je={};w(Je,{base58btc:()=>T,base58flickr:()=>Dt});var T=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=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={};w(Qe,{base8:()=>kt});var kt=l({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var er={};w(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={};w(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≫)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=I(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=I;function sn(t){return V(zr,Or(t))}o(sn,"digest");var an={code:zr,name:on,encode:Or,digest:sn};var ar={};w(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??T.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=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[M,Z]=me(e.subarray(r));return r+=Z,M},"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(),f=n(),b=r+f,A=b-a;return{version:i,codec:s,multihashCode:c,digestSize:f,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??T;return[T.prefix,r.decode(`${T.prefix}${t}`)]}case T.prefix:{let r=e??T;return[T.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!==T.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return i}o(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",_=8,N="AES-GCM",se=N,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 C(t){return m(t instanceof ArrayBuffer?new Uint8Array(t):t,"base64pad")}o(C,"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 L(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(L,"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 E=globalThis.crypto,br={keyTypes:{"bls12-381":{magicBytes:new Uint8Array([234,1]),verify:o(()=>{throw new Error("Not implemented")},"verify")},rsa:{magicBytes:new Uint8Array([0,245,2]),verify: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 E.subtle.importKey("raw",u(s),{name:"Ed25519"},!1,["verify"]);return E.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),k.verify(t,r,await E.subtle.importKey("spki",u(n),{name:Y,hash:fr},!1,["verify"]),8)}o(Cn,"rsaVerify");var k={verify:o(async function(e,r,n,i=_,s=oe){return E.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=_){return E.subtle.sign({name:Y,saltLength:gr},r,H(e,n))},"sign"),encrypt:o(async function(e,r,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,E.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 E.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 E.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-----
|
|
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≫)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(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 E.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 E.subtle.exportKey(s,t);r=new Uint8Array(a)}else r=t;let n=br.keyTypes[e]?.magicBytes;if(!n)throw new Error(`Key type '${e}' not supported, available types: ${Object.keys(br.keyTypes).join(", ")}`);let i=ke([n,r]);return j+m(i,"base58btc")}o(Ie,"publicKeyToDid");async function $(t){return t instanceof CryptoKey?await E.subtle.exportKey("spki",t):await E.subtle.exportKey("spki",t.publicKey)}o($,"getPublicKeyAsArrayBuffer");async function 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):C(r)},"asString")}),import(t){return we(typeof t=="string"?O(t):t)},async exportAsString(t){let e=await d.export(t);return C(e)},encrypt:Dn,async decrypt(t,e,r){let n=ye(e)?e:await we(e),i=r?await q.subtle.decrypt({name:N,iv:u(r)},n,typeof t=="string"?u(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:N,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:N,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??_),i=typeof e=="string"?await xe(e,r):e,s=r?.iv||De(ae),a=await q.subtle.encrypt({name:N,iv:s},i,n);return L(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):C(i)},"asString")})}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:o(async r=>{let n=await $(this.exchangeKey),i=new Uint8Array(n);return r?m(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 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"),f=new this({keys:{exchange:i,write:s},did:c,hasPersisted:!1,isSessionOnly:!!e});return this._instance=f,f}static async exist(e={}){let r=await Ee(e.writeKeyName||this.WRITE_KEY_NAME),n=await Ee(e.encryptionKeyName||this.EXCHANGE_KEY_NAME);return!(!r||!n)}static async load(e={session:!1}){let r=e.encryptionKeyName||this.EXCHANGE_KEY_NAME,n=e.writeKeyName||this.WRITE_KEY_NAME,i=this._instance;if(i&&!i.destroyed&&i.exchangeKeyName===r&&i.writeKeyName===n)return i;let s=!0,a=await Ee(r),c=await Ee(n);a||(s=!1,a=await this._createExchangeKeys(e.extractable)),c||(s=!1,c=await this._createWriteKeys(e.extractable));let f=await $(c),b=await Ie(new Uint8Array(f),this.TYPE==="ecc"?"ed25519":"rsa"),A=new this({keys:{exchange:a,write:c},did:b,hasPersisted:s,isSessionOnly:!!e.session,exchangeKeyName:r,writeKeyName:n});return this._instance=A,A}};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 L(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 k.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):C(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):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,f=i,b=c||await d.create({length:f||s}),A=await d.encrypt(typeof e=="string"?h(e):e,typeof b=="string"?await d.import(b):b),M=await Ue({key:b,publicKey:a}),Z=L(M,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),f=await this.decryptKey(a);return await d.decrypt(c,f)}async decryptAsString(e,r,n){let i=await this.decrypt(e,r,n);return m(i)}async decryptKey(e){return await k.decrypt(e,this.exchangeKey.privateKey)}async decryptKeyAsString(e,r){let n=await k.decrypt(e,this.exchangeKey.privateKey);return m(n,r)}async getAesKey(e,r){if(!e)throw new Error("RSA requires an encrypted AES key to decrypt");if(typeof e=="string"){let n=await this.decryptKey(e);return await 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 k.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 L(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=L(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 k.encrypt(n,e);return r&&r==="arraybuffer"?i:new Uint8Array(i)}o(Ue,"encryptKeyTo");Ue.asString=async function({key:t,publicKey:e},r){let n=await Ue({key:t,publicKey:e});return r?m(n,r):C(n)};async function Ts(t,e,r,n){let i=ye(e)?e:await we(e),s=n?await Cr.subtle.encrypt({name:N,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??_),i=typeof e=="string"?await xe(e,r):e,s=r?.iv||De(ae),a=await Cr.subtle.encrypt({name:N,iv:s},i,n);return L(s,a)}o(Mn,"encryptBytes");export{N as AES_GCM,j as BASE58_DID_PREFIX,mr as BLS_DID_PREFIX,_ 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};
|
|
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
|