@substrate-system/keys 0.3.0 → 0.3.2
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 +54 -18
- package/dist/_base.cjs +4 -4
- package/dist/_base.cjs.map +2 -2
- package/dist/_base.d.ts +6 -3
- package/dist/_base.d.ts.map +1 -1
- package/dist/_base.js +4 -4
- package/dist/_base.js.map +2 -2
- package/dist/_base.min.cjs.map +2 -2
- package/dist/_base.min.js +2 -2
- package/dist/_base.min.js.map +3 -3
- package/dist/aes/index.min.js +2 -2
- package/dist/aes/index.min.js.map +3 -3
- package/dist/browser/index.js +102 -23
- package/dist/browser/index.min.js +2 -2
- package/dist/crypto.min.js +2 -2
- package/dist/crypto.min.js.map +3 -3
- package/dist/ecc/index.cjs +16 -1
- package/dist/ecc/index.cjs.map +2 -2
- package/dist/ecc/index.d.ts +6 -1
- package/dist/ecc/index.d.ts.map +1 -1
- package/dist/ecc/index.js +16 -1
- package/dist/ecc/index.js.map +2 -2
- package/dist/ecc/index.min.cjs +1 -1
- package/dist/ecc/index.min.cjs.map +3 -3
- 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 +12 -12
- package/dist/rsa/index.cjs +24 -1
- package/dist/rsa/index.cjs.map +2 -2
- package/dist/rsa/index.d.ts +16 -1
- package/dist/rsa/index.d.ts.map +1 -1
- package/dist/rsa/index.js +24 -1
- package/dist/rsa/index.js.map +2 -2
- package/dist/rsa/index.min.cjs +1 -1
- package/dist/rsa/index.min.cjs.map +3 -3
- package/dist/rsa/index.min.js +2 -2
- package/dist/rsa/index.min.js.map +3 -3
- package/dist/util.min.js +1 -1
- package/dist/util.min.js.map +3 -3
- package/package.json +2 -1
package/dist/util.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Z=Object.defineProperty;var dr=(r,e,t)=>e in r?Z(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var o=(r,e)=>Z(r,"name",{value:e,configurable:!0});var x=(r,e)=>{for(var t in e)Z(r,t,{get:e[t],enumerable:!0})};var c=(r,e,t)=>dr(r,typeof e!="symbol"?e+"":e,t);function q(r=0){return new Uint8Array(r)}o(q,"allocUnsafe");var ce={};x(ce,{base10:()=>gr});var $t=new Uint8Array(0);function Re(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(Re,"equals");function U(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}o(U,"coerce");function ze(r){return new TextEncoder().encode(r)}o(ze,"fromString");function Ne(r){return new TextDecoder().decode(r)}o(Ne,"toString");function lr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var s=r.charAt(i),a=s.charCodeAt(0);if(t[a]!==255)throw new TypeError(s+" is ambiguous");t[a]=i}var p=r.length,h=r.charAt(0),L=Math.log(p)/Math.log(256),m=Math.log(256)/Math.log(p);function M(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 l=0,I=0,b=0,w=f.length;b!==w&&f[b]===0;)b++,l++;for(var A=(w-b)*m+1>>>0,y=new Uint8Array(A);b!==w;){for(var E=f[b],B=0,g=A-1;(E!==0||B<I)&&g!==-1;g--,B++)E+=256*y[g]>>>0,y[g]=E%p>>>0,E=E/p>>>0;if(E!==0)throw new Error("Non-zero carry");I=B,b++}for(var S=A-I;S!==A&&y[S]===0;)S++;for(var j=h.repeat(l);S<A;++S)j+=r.charAt(y[S]);return j}o(M,"encode");function $(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var l=0;if(f[l]!==" "){for(var I=0,b=0;f[l]===h;)I++,l++;for(var w=(f.length-l)*L+1>>>0,A=new Uint8Array(w);f[l];){var y=t[f.charCodeAt(l)];if(y===255)return;for(var E=0,B=w-1;(y!==0||E<b)&&B!==-1;B--,E++)y+=p*A[B]>>>0,A[B]=y%256>>>0,y=y/256>>>0;if(y!==0)throw new Error("Non-zero carry");b=E,l++}if(f[l]!==" "){for(var g=w-b;g!==w&&A[g]===0;)g++;for(var S=new Uint8Array(I+(w-g)),j=I;g!==w;)S[j++]=A[g++];return S}}}o($,"decodeUnsafe");function ur(f){var l=$(f);if(l)return l;throw new Error(`Non-${e} character`)}return o(ur,"decode"),{encode:M,decodeUnsafe:$,decode:ur}}o(lr,"base");var mr=lr,yr=mr,Fe=yr;var oe=class oe{constructor(e,t,n){c(this,"name");c(this,"prefix");c(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(oe,"Encoder");var ee=oe,ie=class ie{constructor(e,t,n){c(this,"name");c(this,"prefix");c(this,"baseDecode");c(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 He(this,e)}};o(ie,"Decoder");var re=ie,se=class se{constructor(e){c(this,"decoders");this.decoders=e}or(e){return He(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(se,"ComposedDecoder");var te=se;function He(r,e){return new te({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}o(He,"or");var ae=class ae{constructor(e,t,n,i){c(this,"name");c(this,"prefix");c(this,"baseEncode");c(this,"baseDecode");c(this,"encoder");c(this,"decoder");this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new ee(e,t,n),this.decoder=new re(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};o(ae,"Codec");var ne=ae;function _({name:r,prefix:e,encode:t,decode:n}){return new ne(r,e,t,n)}o(_,"from");function C({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Fe(t,r);return _({prefix:e,name:r,encode:n,decode:o(s=>U(i(s)),"decode")})}o(C,"baseX");function xr(r,e,t,n){let i={};for(let m=0;m<e.length;++m)i[e[m]]=m;let s=r.length;for(;r[s-1]==="=";)--s;let a=new Uint8Array(s*t/8|0),p=0,h=0,L=0;for(let m=0;m<s;++m){let M=i[r[m]];if(M===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<t|M,p+=t,p>=8&&(p-=8,a[L++]=255&h>>p)}if(p>=t||(255&h<<8-p)!==0)throw new SyntaxError("Unexpected end of data");return a}o(xr,"decode");function br(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,s="",a=0,p=0;for(let h=0;h<r.length;++h)for(p=p<<8|r[h],a+=8;a>t;)a-=t,s+=e[i&p>>a];if(a!==0&&(s+=e[i&p<<t-a]),n)for(;(s.length*t&7)!==0;)s+="=";return s}o(br,"encode");function u({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return _({prefix:e,name:r,encode(i){return br(i,n,t)},decode(i){return xr(i,n,t,r)}})}o(u,"rfc4648");var gr=C({prefix:"9",name:"base10",alphabet:"0123456789"});var fe={};x(fe,{base16:()=>wr,base16upper:()=>Ar});var wr=u({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ar=u({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var pe={};x(pe,{base2:()=>Er});var Er=u({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ue={};x(ue,{base256emoji:()=>Cr});var Ge=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}"),vr=Ge.reduce((r,e,t)=>(r[t]=e,r),[]),Sr=Ge.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Ur(r){return r.reduce((e,t)=>(e+=vr[t],e),"")}o(Ur,"encode");function Br(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=Sr[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}o(Br,"decode");var Cr=_({prefix:"\u{1F680}",name:"base256emoji",encode:Ur,decode:Br});var de={};x(de,{base32:()=>P,base32hex:()=>Lr,base32hexpad:()=>_r,base32hexpadupper:()=>Pr,base32hexupper:()=>Mr,base32pad:()=>Ir,base32padupper:()=>Tr,base32upper:()=>Dr,base32z:()=>Rr});var P=u({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Dr=u({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ir=u({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Tr=u({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Lr=u({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mr=u({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),_r=u({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Pr=u({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Rr=u({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var he={};x(he,{base36:()=>F,base36upper:()=>zr});var F=C({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zr=C({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var le={};x(le,{base58btc:()=>v,base58flickr:()=>Nr});var v=C({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nr=C({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var me={};x(me,{base64:()=>Or,base64pad:()=>Fr,base64url:()=>Hr,base64urlpad:()=>Gr});var Or=u({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Fr=u({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Hr=u({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gr=u({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ye={};x(ye,{base8:()=>kr});var kr=u({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var xe={};x(xe,{identity:()=>Kr});var Kr=_({prefix:"\0",name:"identity",encode:o(r=>Ne(r),"encode"),decode:o(r=>ze(r),"decode")});var ln=new TextEncoder,mn=new TextDecoder;var we={};x(we,{identity:()=>dt});var $r=Ve,ke=128,jr=127,qr=~jr,Yr=Math.pow(2,31);function Ve(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Yr;)e[t++]=r&255|ke,r/=128;for(;r&qr;)e[t++]=r&255|ke,r>>>=7;return e[t]=r|0,Ve.bytes=t-n+1,e}o(Ve,"encode");var Wr=be,Jr=128,Ke=127;function be(r,n){var t=0,n=n||0,i=0,s=n,a,p=r.length;do{if(s>=p)throw be.bytes=0,new RangeError("Could not decode varint");a=r[s++],t+=i<28?(a&Ke)<<i:(a&Ke)*Math.pow(2,i),i+=7}while(a>=Jr);return be.bytes=s-n,t}o(be,"read");var Qr=Math.pow(2,7),Zr=Math.pow(2,14),et=Math.pow(2,21),rt=Math.pow(2,28),tt=Math.pow(2,35),nt=Math.pow(2,42),ot=Math.pow(2,49),it=Math.pow(2,56),st=Math.pow(2,63),at=o(function(r){return r<Qr?1:r<Zr?2:r<et?3:r<rt?4:r<tt?5:r<nt?6:r<ot?7:r<it?8:r<st?9:10},"length"),ct={encode:$r,decode:Wr,encodingLength:at},ft=ct,H=ft;function G(r,e=0){return[H.decode(r,e),H.decode.bytes]}o(G,"decode");function R(r,e,t=0){return H.encode(r,e,t),e}o(R,"encodeTo");function z(r){return H.encodingLength(r)}o(z,"encodingLength");function T(r,e){let t=e.byteLength,n=z(r),i=n+z(t),s=new Uint8Array(i+t);return R(r,s,0),R(t,s,n),s.set(e,i),new N(r,t,e,s)}o(T,"create");function Xe(r){let e=U(r),[t,n]=G(e),[i,s]=G(e.subarray(n)),a=e.subarray(n+s);if(a.byteLength!==i)throw new Error("Incorrect length");return new N(t,i,a,e)}o(Xe,"decode");function $e(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Re(r.bytes,t.bytes)}}o($e,"equals");var ge=class ge{constructor(e,t,n,i){c(this,"code");c(this,"size");c(this,"digest");c(this,"bytes");this.code=e,this.size=t,this.digest=n,this.bytes=i}};o(ge,"Digest");var N=ge;var je=0,pt="identity",qe=U;function ut(r){return T(je,qe(r))}o(ut,"digest");var dt={code:je,name:pt,encode:qe,digest:ut};var Se={};x(Se,{sha256:()=>ht,sha512:()=>lt});function Ee({name:r,code:e,encode:t}){return new Ae(r,e,t)}o(Ee,"from");var ve=class ve{constructor(e,t,n){c(this,"name");c(this,"code");c(this,"encode");this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?T(this.code,t):t.then(n=>T(this.code,n))}else throw Error("Unknown type, must be binary type")}};o(ve,"Hasher");var Ae=ve;function We(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}o(We,"sha");var ht=Ee({name:"sha2-256",code:18,encode:We("SHA-256")}),lt=Ee({name:"sha2-512",code:19,encode:We("SHA-512")});function Je(r,e){let{bytes:t,version:n}=r;return n===0?yt(t,Ue(r),e??v.encoder):xt(t,Ue(r),e??P.encoder)}o(Je,"format");var Qe=new WeakMap;function Ue(r){let e=Qe.get(r);if(e==null){let t=new Map;return Qe.set(r,t),t}return e}o(Ue,"baseCache");var er,d=class d{constructor(e,t,n,i){c(this,"code");c(this,"version");c(this,"multihash");c(this,"bytes");c(this,"/");c(this,er,"CID");this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==K)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==bt)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=T(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&&$e(e.multihash,n.multihash)}toString(e){return Je(this,e)}toJSON(){return{"/":Je(this)}}link(){return this}[(er=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??Ze(n,i,s.bytes))}else if(t[gt]===!0){let{version:n,multihash:i,code:s}=t,a=Xe(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!==K)throw new Error(`Version 0 CID must use dag-pb (code: ${K}) block encoding`);return new d(e,t,n,n.bytes)}case 1:{let i=Ze(e,t,n.bytes);return new d(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return d.create(0,K,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 N(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,$]=G(e.subarray(t));return t+=$,M},"next"),i=n(),s=K;if(i===18?(i=0,t=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let a=t,p=n(),h=n(),L=t+h,m=L-a;return{version:i,codec:s,multihashCode:p,digestSize:h,multihashSize:m,size:L}}static parse(e,t){let[n,i]=mt(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 Ue(s).set(n,e),s}};o(d,"CID");var W=d;function mt(r,e){switch(r[0]){case"Q":{let t=e??v;return[v.prefix,t.decode(`${v.prefix}${r}`)]}case v.prefix:{let t=e??v;return[v.prefix,t.decode(r)]}case P.prefix:{let t=e??P;return[P.prefix,t.decode(r)]}case F.prefix:{let t=e??F;return[F.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(mt,"parseCIDtoBytes");function yt(r,e,t){let{prefix:n}=t;if(n!==v.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(yt,"toStringV0");function xt(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(xt,"toStringV1");var K=112,bt=18;function Ze(r,e,t){let n=z(r),i=n+z(e),s=new Uint8Array(i+t.byteLength);return R(r,s,0),R(e,s,n),s.set(t,i),s}o(Ze,"encodeCID");var gt=Symbol.for("@ipld/js-cid/CID");var Be={...xe,...pe,...ye,...ce,...fe,...de,...he,...le,...me,...ue},$n={...Se,...we};function tr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}o(tr,"createCodec");var rr=tr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ce=tr("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=q(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),wt={utf8:rr,"utf-8":rr,hex:Be.base16,latin1:Ce,ascii:Ce,binary:Ce,...Be},J=wt;function V(r,e="utf8"){let t=J[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}o(V,"fromString");function X(r,e="utf8"){let t=J[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}o(X,"toString");var De=(n=>(n.Sign="signing",n.Exchange="exchange",n.Write="write",n))(De||{});var Ie="did:key:z";var Ao="X25519";var nr={sign:["sign","verify"],encrypt:["deriveKey","deriveBits"]},or="RSA-OAEP",ir="RSASSA-PKCS1-v1_5";var Te=new Uint8Array([0,245,2]),Eo=2048,vo="SHA-256",So=8,Et="AES-GCM",sr=Et,ar=256;var Le=new Uint8Array([234,1]),Me=new Uint8Array([237,1]),Q={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"};var O=globalThis.crypto,Io=new Error("Invalid key use. Please use 'encryption' or 'signing"),vt=new Error("Max must be less than 256 and greater than 0");function D(r){return new Uint8Array(r).buffer}o(D,"toArrayBuffer");async function To(r){let e=r.normalize("NFD"),t=await cr(new TextEncoder().encode(e));return X(t,"base32").slice(0,32)}o(To,"createDeviceName");async function cr(r){return new Uint8Array(await O.subtle.digest("sha-256",r.buffer))}o(cr,"sha256");function fr(r){let e=V(r,"base64pad");return D(e)}o(fr,"base64ToArrBuf");var Pe=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 Lo(r){return Pe(r,fr)}o(Lo,"normalizeBase64ToBuf");var St=o(r=>Pe(r,e=>pr(e,8)),"normalizeUtf8ToBuf");function pr(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(pr,"strToArrBuf");var Ut=o(r=>Pe(r,e=>pr(e,16)),"normalizeUtf16ToBuf");function Mo(r,e){return e===8?St(r):Ut(r)}o(Mo,"normalizeUnicodeToBuf");function _o(r){if(!r.startsWith(Ie))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+r.substring(Ie.length),t=V(e,"base58btc"),{keyBuffer:n,type:i}=Bt(D(t));return{publicKey:new Uint8Array(n),type:i}}o(_o,"didToPublicKey");function Bt(r){if(_e(r,D(Te)))return{keyBuffer:r.slice(Te.byteLength),type:Q.RSA};if(_e(r,D(Me)))return{keyBuffer:r.slice(Me.byteLength),type:Q.Edwards};if(_e(r,D(Le)))return{keyBuffer:r.slice(Le.byteLength),type:Q.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}o(Bt,"parseMagicBytes");var Ct={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 _e(r,e){return Ct.equal(e,r.slice(0,e.byteLength))}o(_e,"hasPrefix");function Po(r){return X(r instanceof ArrayBuffer?new Uint8Array(r):r,"base64pad")}o(Po,"toBase64");function Ro(r){return V(r,"base64pad")}o(Ro,"fromBase64");async function zo(r,e){let t=typeof r=="string"?fr(r):D(r);return O.subtle.importKey("raw",t,{name:e?.alg||sr,length:e?.length||ar},!0,["encrypt","decrypt"])}o(zo,"importKey");function No(r,{max:e}={max:255}){if(e<1||e>255)throw vt;let t=new Uint8Array(r);if(e===255)return O.getRandomValues(t),t.buffer;let n=0,i=e+1,s=Math.floor(256/i)*i,a=new Uint8Array(1);for(;n<t.length;)O.getRandomValues(a),a[0]<s&&(t[n]=a[0]%i,n++);return t.buffer}o(No,"randomBuf");function Oo(r,e){let t=r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(D(r)),n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(D(e)),i=new Uint8Array(t.length+n.length);return i.set(t),i.set(n,t.length),i.buffer}o(Oo,"joinBufs");async function Fo(r,e,t=!1){return await O.subtle.generateKey({name:r},t,nr[e])}o(Fo,"makeEccKeypair");async function Ho(r,e,t,n=!1){let i=n;if(!Object.values(De).includes(t))throw new Error("invalid key use");let s=t==="exchange"?or:ir,a=t==="exchange"?["encrypt","decrypt"]:["sign","verify"];return O.subtle.generateKey({name:s,modulusLength:r,publicExponent:Dt(),hash:{name:e}},i,a)}o(Ho,"makeRSAKeypair");function Dt(){return new Uint8Array([1,0,1])}o(Dt,"publicExponent");async function Go(r){let e=await cr(new TextEncoder().encode(r.normalize("NFD")));return X(e,"base32").slice(0,32)}o(Go,"getDeviceName");export{Io as InvalidKeyUse,vt as InvalidMaxValue,fr as base64ToArrBuf,To as createDeviceName,_o as didToPublicKey,Ro as fromBase64,Go as getDeviceName,_e as hasPrefix,zo as importKey,Oo as joinBufs,Fo as makeEccKeypair,Ho as makeRSAKeypair,Lo as normalizeBase64ToBuf,Pe as normalizeToBuf,Mo as normalizeUnicodeToBuf,Ut as normalizeUtf16ToBuf,St as normalizeUtf8ToBuf,No as randomBuf,cr as sha256,pr as strToArrBuf,D as toArrayBuffer,Po as toBase64};
|
|
1
|
+
var Z=Object.defineProperty;var dr=(r,e,t)=>e in r?Z(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var o=(r,e)=>Z(r,"name",{value:e,configurable:!0});var m=(r,e)=>{for(var t in e)Z(r,t,{get:e[t],enumerable:!0})};var c=(r,e,t)=>dr(r,typeof e!="symbol"?e+"":e,t);function q(r=0){return new Uint8Array(r)}o(q,"allocUnsafe");var ce={};m(ce,{base10:()=>Ar});var Yt=new Uint8Array(0);function Re(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(Re,"equals");function S(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}o(S,"coerce");function Ne(r){return new TextEncoder().encode(r)}o(Ne,"fromString");function ze(r){return new TextDecoder().decode(r)}o(ze,"toString");function mr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var s=r.charAt(i),a=s.charCodeAt(0);if(t[a]!==255)throw new TypeError(s+" is ambiguous");t[a]=i}var u=r.length,y=r.charAt(0),U=Math.log(u)/Math.log(256),L=Math.log(256)/Math.log(u);function Q(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 d=0,I=0,x=0,g=f.length;x!==g&&f[x]===0;)x++,d++;for(var w=(g-x)*L+1>>>0,l=new Uint8Array(w);x!==g;){for(var A=f[x],D=0,b=w-1;(A!==0||D<I)&&b!==-1;b--,D++)A+=256*l[b]>>>0,l[b]=A%u>>>0,A=A/u>>>0;if(A!==0)throw new Error("Non-zero carry");I=D,x++}for(var v=w-I;v!==w&&l[v]===0;)v++;for(var $=y.repeat(d);v<w;++v)$+=r.charAt(l[v]);return $}o(Q,"encode");function X(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var d=0;if(f[d]!==" "){for(var I=0,x=0;f[d]===y;)I++,d++;for(var g=(f.length-d)*U+1>>>0,w=new Uint8Array(g);f[d];){var l=t[f.charCodeAt(d)];if(l===255)return;for(var A=0,D=g-1;(l!==0||A<x)&&D!==-1;D--,A++)l+=u*w[D]>>>0,w[D]=l%256>>>0,l=l/256>>>0;if(l!==0)throw new Error("Non-zero carry");x=A,d++}if(f[d]!==" "){for(var b=g-x;b!==g&&w[b]===0;)b++;for(var v=new Uint8Array(I+(g-b)),$=I;b!==g;)v[$++]=w[b++];return v}}}o(X,"decodeUnsafe");function hr(f){var d=X(f);if(d)return d;throw new Error(`Non-${e} character`)}return o(hr,"decode"),{encode:Q,decodeUnsafe:X,decode:hr}}o(mr,"base");var yr=mr,xr=yr,Fe=xr;var oe=class oe{constructor(e,t,n){c(this,"name");c(this,"prefix");c(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(oe,"Encoder");var ee=oe,ie=class ie{constructor(e,t,n){c(this,"name");c(this,"prefix");c(this,"baseDecode");c(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 He(this,e)}};o(ie,"Decoder");var re=ie,se=class se{constructor(e){c(this,"decoders");this.decoders=e}or(e){return He(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(se,"ComposedDecoder");var te=se;function He(r,e){return new te({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}o(He,"or");var ae=class ae{constructor(e,t,n,i){c(this,"name");c(this,"prefix");c(this,"baseEncode");c(this,"baseDecode");c(this,"encoder");c(this,"decoder");this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new ee(e,t,n),this.decoder=new re(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};o(ae,"Codec");var ne=ae;function T({name:r,prefix:e,encode:t,decode:n}){return new ne(r,e,t,n)}o(T,"from");function B({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Fe(t,r);return T({prefix:e,name:r,encode:n,decode:o(s=>S(i(s)),"decode")})}o(B,"baseX");function br(r,e,t,n){let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,u=0,y=0;for(let U=0;U<i;++U){let L=e[r[U]];if(L===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|L,a+=t,a>=8&&(a-=8,s[y++]=255&u>>a)}if(a>=t||(255&u<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return s}o(br,"decode");function gr(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,s="",a=0,u=0;for(let y=0;y<r.length;++y)for(u=u<<8|r[y],a+=8;a>t;)a-=t,s+=e[i&u>>a];if(a!==0&&(s+=e[i&u<<t-a]),n)for(;(s.length*t&7)!==0;)s+="=";return s}o(gr,"encode");function wr(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}o(wr,"createAlphabetIdx");function p({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let i=wr(n);return T({prefix:e,name:r,encode(s){return gr(s,n,t)},decode(s){return br(s,i,t,r)}})}o(p,"rfc4648");var Ar=B({prefix:"9",name:"base10",alphabet:"0123456789"});var fe={};m(fe,{base16:()=>Er,base16upper:()=>vr});var Er=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),vr=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var pe={};m(pe,{base2:()=>Sr});var Sr=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ue={};m(ue,{base256emoji:()=>Ir});var Ge=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}"),Ur=Ge.reduce((r,e,t)=>(r[t]=e,r),[]),Dr=Ge.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Br(r){return r.reduce((e,t)=>(e+=Ur[t],e),"")}o(Br,"encode");function Cr(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=Dr[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}o(Cr,"decode");var Ir=T({prefix:"\u{1F680}",name:"base256emoji",encode:Br,decode:Cr});var he={};m(he,{base32:()=>M,base32hex:()=>_r,base32hexpad:()=>Rr,base32hexpadupper:()=>Nr,base32hexupper:()=>Pr,base32pad:()=>Tr,base32padupper:()=>Mr,base32upper:()=>Lr,base32z:()=>zr});var M=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Lr=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Tr=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Mr=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_r=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pr=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Rr=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nr=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zr=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var de={};m(de,{base36:()=>O,base36upper:()=>Or});var O=B({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Or=B({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var le={};m(le,{base58btc:()=>E,base58flickr:()=>Fr});var E=B({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Fr=B({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var me={};m(me,{base64:()=>Hr,base64pad:()=>Gr,base64url:()=>kr,base64urlpad:()=>Kr});var Hr=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Gr=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),kr=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Kr=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ye={};m(ye,{base8:()=>Vr});var Vr=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var xe={};m(xe,{identity:()=>Xr});var Xr=T({prefix:"\0",name:"identity",encode:o(r=>ze(r),"encode"),decode:o(r=>Ne(r),"decode")});var xn=new TextEncoder,bn=new TextDecoder;var we={};m(we,{identity:()=>lt});var jr=Ve,ke=128,Yr=127,Wr=~Yr,Jr=Math.pow(2,31);function Ve(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Jr;)e[t++]=r&255|ke,r/=128;for(;r&Wr;)e[t++]=r&255|ke,r>>>=7;return e[t]=r|0,Ve.bytes=t-n+1,e}o(Ve,"encode");var Qr=be,Zr=128,Ke=127;function be(r,n){var t=0,n=n||0,i=0,s=n,a,u=r.length;do{if(s>=u)throw be.bytes=0,new RangeError("Could not decode varint");a=r[s++],t+=i<28?(a&Ke)<<i:(a&Ke)*Math.pow(2,i),i+=7}while(a>=Zr);return be.bytes=s-n,t}o(be,"read");var et=Math.pow(2,7),rt=Math.pow(2,14),tt=Math.pow(2,21),nt=Math.pow(2,28),ot=Math.pow(2,35),it=Math.pow(2,42),st=Math.pow(2,49),at=Math.pow(2,56),ct=Math.pow(2,63),ft=o(function(r){return r<et?1:r<rt?2:r<tt?3:r<nt?4:r<ot?5:r<it?6:r<st?7:r<at?8:r<ct?9:10},"length"),pt={encode:jr,decode:Qr,encodingLength:ft},ut=pt,F=ut;function H(r,e=0){return[F.decode(r,e),F.decode.bytes]}o(H,"decode");function _(r,e,t=0){return F.encode(r,e,t),e}o(_,"encodeTo");function P(r){return F.encodingLength(r)}o(P,"encodingLength");function N(r,e){let t=e.byteLength,n=P(r),i=n+P(t),s=new Uint8Array(i+t);return _(r,s,0),_(t,s,n),s.set(e,i),new R(r,t,e,s)}o(N,"create");function Xe(r){let e=S(r),[t,n]=H(e),[i,s]=H(e.subarray(n)),a=e.subarray(n+s);if(a.byteLength!==i)throw new Error("Incorrect length");return new R(t,i,a,e)}o(Xe,"decode");function $e(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Re(r.bytes,t.bytes)}}o($e,"equals");var ge=class ge{constructor(e,t,n,i){c(this,"code");c(this,"size");c(this,"digest");c(this,"bytes");this.code=e,this.size=t,this.digest=n,this.bytes=i}};o(ge,"Digest");var R=ge;var qe=0,ht="identity",je=S;function dt(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 N(qe,je(r))}o(dt,"digest");var lt={code:qe,name:ht,encode:je,digest:dt};var Se={};m(Se,{sha256:()=>yt,sha512:()=>xt});var mt=20;function Ee({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:i}){return new Ae(r,e,t,n,i)}o(Ee,"from");var ve=class ve{constructor(e,t,n,i,s){c(this,"name");c(this,"code");c(this,"encode");c(this,"minDigestLength");c(this,"maxDigestLength");this.name=e,this.code=t,this.encode=n,this.minDigestLength=i??mt,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?Ye(n,this.code,t?.truncate):n.then(i=>Ye(i,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};o(ve,"Hasher");var Ae=ve;function Ye(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 N(e,r)}o(Ye,"createDigest");function Je(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}o(Je,"sha");var yt=Ee({name:"sha2-256",code:18,encode:Je("SHA-256")}),xt=Ee({name:"sha2-512",code:19,encode:Je("SHA-512")});function Qe(r,e){let{bytes:t,version:n}=r;return n===0?gt(t,Ue(r),e??E.encoder):wt(t,Ue(r),e??M.encoder)}o(Qe,"format");var Ze=new WeakMap;function Ue(r){let e=Ze.get(r);if(e==null){let t=new Map;return Ze.set(r,t),t}return e}o(Ue,"baseCache");var rr,h=class h{constructor(e,t,n,i){c(this,"code");c(this,"version");c(this,"multihash");c(this,"bytes");c(this,"/");c(this,rr,"CID");this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==k)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==At)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return h.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=N(e,t);return h.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return h.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&$e(e.multihash,n.multihash)}toString(e){return Qe(this,e)}toJSON(){return{"/":Qe(this)}}link(){return this}[(rr=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 h)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:s,bytes:a}=t;return new h(n,i,s,a??er(n,i,s.bytes))}else if(t[Et]===!0){let{version:n,multihash:i,code:s}=t,a=Xe(i);return h.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!==k)throw new Error(`Version 0 CID must use dag-pb (code: ${k}) block encoding`);return new h(e,t,n,n.bytes)}case 1:{let i=er(e,t,n.bytes);return new h(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return h.create(0,k,e)}static createV1(e,t){return h.create(1,e,t)}static decode(e){let[t,n]=h.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=h.inspectBytes(e),n=t.size-t.multihashSize,i=S(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 R(t.multihashCode,t.digestSize,s,i);return[t.version===0?h.createV0(a):h.createV1(t.codec,a),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=o(()=>{let[Q,X]=H(e.subarray(t));return t+=X,Q},"next"),i=n(),s=k;if(i===18?(i=0,t=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let a=t,u=n(),y=n(),U=t+y,L=U-a;return{version:i,codec:s,multihashCode:u,digestSize:y,multihashSize:L,size:U}}static parse(e,t){let[n,i]=bt(e,t),s=h.decode(i);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ue(s).set(n,e),s}};o(h,"CID");var Y=h;function bt(r,e){switch(r[0]){case"Q":{let t=e??E;return[E.prefix,t.decode(`${E.prefix}${r}`)]}case E.prefix:{let t=e??E;return[E.prefix,t.decode(r)]}case M.prefix:{let t=e??M;return[M.prefix,t.decode(r)]}case O.prefix:{let t=e??O;return[O.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(bt,"parseCIDtoBytes");function gt(r,e,t){let{prefix:n}=t;if(n!==E.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(gt,"toStringV0");function wt(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(wt,"toStringV1");var k=112,At=18;function er(r,e,t){let n=P(r),i=n+P(e),s=new Uint8Array(i+t.byteLength);return _(r,s,0),_(e,s,n),s.set(t,i),s}o(er,"encodeCID");var Et=Symbol.for("@ipld/js-cid/CID");var De={...xe,...pe,...ye,...ce,...fe,...he,...de,...le,...me,...ue},Yn={...Se,...we};function nr(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}o(nr,"createCodec");var tr=nr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Be=nr("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=q(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),vt={utf8:tr,"utf-8":tr,hex:De.base16,latin1:Be,ascii:Be,binary:Be,...De},W=vt;function K(r,e="utf8"){let t=W[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}o(K,"fromString");function V(r,e="utf8"){let t=W[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}o(V,"toString");var Ce=(n=>(n.Sign="signing",n.Exchange="exchange",n.Write="write",n))(Ce||{});var Ie="did:key:z";var So="X25519";var or={sign:["sign","verify"],encrypt:["deriveKey","deriveBits"]},ir="RSA-OAEP",sr="RSASSA-PKCS1-v1_5";var Le=new Uint8Array([0,245,2]),Uo=2048,Do="SHA-256",Bo=8,Ut="AES-GCM",ar=Ut,cr=256;var Te=new Uint8Array([234,1]),Me=new Uint8Array([237,1]),J={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"};var z=globalThis.crypto,Mo=new Error("Invalid key use. Please use 'encryption' or 'signing"),Dt=new Error("Max must be less than 256 and greater than 0");function C(r){return new Uint8Array(r).buffer}o(C,"toArrayBuffer");async function _o(r){let e=r.normalize("NFD"),t=await fr(new TextEncoder().encode(e));return V(t,"base32").slice(0,32)}o(_o,"createDeviceName");async function fr(r){return new Uint8Array(await z.subtle.digest("sha-256",r.buffer))}o(fr,"sha256");function pr(r){let e=K(r,"base64pad");return C(e)}o(pr,"base64ToArrBuf");var Pe=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 Po(r){return Pe(r,pr)}o(Po,"normalizeBase64ToBuf");var Bt=o(r=>Pe(r,e=>ur(e,8)),"normalizeUtf8ToBuf");function ur(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(ur,"strToArrBuf");var Ct=o(r=>Pe(r,e=>ur(e,16)),"normalizeUtf16ToBuf");function Ro(r,e){return e===8?Bt(r):Ct(r)}o(Ro,"normalizeUnicodeToBuf");function No(r){if(!r.startsWith(Ie))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+r.substring(Ie.length),t=K(e,"base58btc"),{keyBuffer:n,type:i}=It(C(t));return{publicKey:new Uint8Array(n),type:i}}o(No,"didToPublicKey");function It(r){if(_e(r,C(Le)))return{keyBuffer:r.slice(Le.byteLength),type:J.RSA};if(_e(r,C(Me)))return{keyBuffer:r.slice(Me.byteLength),type:J.Edwards};if(_e(r,C(Te)))return{keyBuffer:r.slice(Te.byteLength),type:J.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}o(It,"parseMagicBytes");var Lt={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 _e(r,e){return Lt.equal(e,r.slice(0,e.byteLength))}o(_e,"hasPrefix");function zo(r){return V(r instanceof ArrayBuffer?new Uint8Array(r):r,"base64pad")}o(zo,"toBase64");function Oo(r){return K(r,"base64pad")}o(Oo,"fromBase64");async function Fo(r,e){let t=typeof r=="string"?pr(r):C(r);return z.subtle.importKey("raw",t,{name:e?.alg||ar,length:e?.length||cr},!0,["encrypt","decrypt"])}o(Fo,"importKey");function Ho(r,{max:e}={max:255}){if(e<1||e>255)throw Dt;let t=new Uint8Array(r);if(e===255)return z.getRandomValues(t),t.buffer;let n=0,i=e+1,s=Math.floor(256/i)*i,a=new Uint8Array(1);for(;n<t.length;)z.getRandomValues(a),a[0]<s&&(t[n]=a[0]%i,n++);return t.buffer}o(Ho,"randomBuf");function Go(r,e){let t=r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(C(r)),n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(C(e)),i=new Uint8Array(t.length+n.length);return i.set(t),i.set(n,t.length),i.buffer}o(Go,"joinBufs");async function ko(r,e,t=!1){return await z.subtle.generateKey({name:r},t,or[e])}o(ko,"makeEccKeypair");async function Ko(r,e,t,n=!1){let i=n;if(!Object.values(Ce).includes(t))throw new Error("invalid key use");let s=t==="exchange"?ir:sr,a=t==="exchange"?["encrypt","decrypt"]:["sign","verify"];return z.subtle.generateKey({name:s,modulusLength:r,publicExponent:Tt(),hash:{name:e}},i,a)}o(Ko,"makeRSAKeypair");function Tt(){return new Uint8Array([1,0,1])}o(Tt,"publicExponent");async function Vo(r){let e=await fr(new TextEncoder().encode(r.normalize("NFD")));return V(e,"base32").slice(0,32)}o(Vo,"getDeviceName");export{Mo as InvalidKeyUse,Dt as InvalidMaxValue,pr as base64ToArrBuf,_o as createDeviceName,No as didToPublicKey,Oo as fromBase64,Vo as getDeviceName,_e as hasPrefix,Fo as importKey,Go as joinBufs,ko as makeEccKeypair,Ko as makeRSAKeypair,Po as normalizeBase64ToBuf,Pe as normalizeToBuf,Ro as normalizeUnicodeToBuf,Ct as normalizeUtf16ToBuf,Bt as normalizeUtf8ToBuf,Ho as randomBuf,fr as sha256,ur as strToArrBuf,C as toArrayBuffer,zo as toBase64};
|
|
2
2
|
//# sourceMappingURL=util.min.js.map
|