- Add GETTING_STARTED.md with quick start guide and development modes - Add INSTALL.sh automated installation script - Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md - Add QUICK_REFERENCE.md for common commands - Add SETUP_GUIDE.md with detailed setup instructions - Update README.md with improved project overview - Add did-wallet app dependencies and node_modules
4 lines
25 KiB
JavaScript
4 lines
25 KiB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HamtSharding = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
"use strict";var HamtSharding=(()=>{var Yt=Object.create;var j=Object.defineProperty;var Qt=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Ht=Object.getPrototypeOf,Wt=Object.prototype.hasOwnProperty;var Zt=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),d=(r,t)=>{for(var e in t)j(r,e,{get:t[e],enumerable:!0})},mt=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Gt(t))!Wt.call(r,s)&&s!==e&&j(r,s,{get:()=>t[s],enumerable:!(n=Qt(t,s))||n.enumerable});return r};var te=(r,t,e)=>(e=r!=null?Yt(Ht(r)):{},mt(t||!r||!r.__esModule?j(e,"default",{value:r,enumerable:!0}):e,r)),ee=r=>mt(j({},"__esModule",{value:!0}),r);var yt=Zt((Ar,xt)=>{"use strict";xt.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(t,e){let n=this._internalPositionFor(t,!1);if(e===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(t),this._changedLength=!0,this._changedData=!0);else{let s=!1;n===-1?(n=this._data.length,this._setBit(t),this._changedData=!0):s=!0,this._setInternalPos(n,t,e,s),this._changedLength=!0}}unset(t){this.set(t,void 0)}get(t){this._sortData();let e=this._internalPositionFor(t,!0);if(e!==-1)return this._data[e][1]}push(t){return this.set(this.length,t),this.length}get length(){if(this._sortData(),this._changedLength){let t=this._data[this._data.length-1];this._length=t?t[0]+1:0,this._changedLength=!1}return this._length}forEach(t){let e=0;for(;e<this.length;)t(this.get(e),e,this),e++}map(t){let e=0,n=new Array(this.length);for(;e<this.length;)n[e]=t(this.get(e),e,this),e++;return n}reduce(t,e){let n=0,s=e;for(;n<this.length;){let o=this.get(n);s=t(s,o,n),n++}return s}find(t){let e=0,n,s;for(;e<this.length&&!n;)s=this.get(e),n=t(s),e++;return n?s:void 0}_internalPositionFor(t,e){let n=this._bytePosFor(t,e);if(n>=this._bitArrays.length)return-1;let s=this._bitArrays[n],o=t-n*7;if(!((s&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(re,0),h=~(4294967295<<o+1),g=gt(s&h);return a+g-1}_bytePosFor(t,e){let n=Math.floor(t/7),s=n+1;for(;!e&&this._bitArrays.length<s;)this._bitArrays.push(0);return n}_setBit(t){let e=this._bytePosFor(t,!1);this._bitArrays[e]|=1<<t-e*7}_unsetBit(t){let e=this._bytePosFor(t,!1);this._bitArrays[e]&=~(1<<t-e*7)}_setInternalPos(t,e,n,s){let o=this._data,i=[e,n];if(s)this._sortData(),o[t]=i;else{if(o.length)if(o[o.length-1][0]>=e)o.push(i);else if(o[0][0]<=e)o.unshift(i);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(i).concat(o.slice(a))}else this._data.push(i);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(t){this._data.splice(t,1)}_sortData(){this._changedData&&this._data.sort(ne),this._changedData=!1}bitField(){let t=[],e=8,n=0,s=0,o,i=this._bitArrays.slice();for(;i.length||n;){n===0&&(o=i.shift(),n=7);let h=Math.min(n,e),g=~(255<<h),u=o&g;s|=u<<8-e,o=o>>>h,n-=h,e-=h,(!e||!n&&!i.length)&&(t.push(s),s=0,e=8)}for(var a=t.length-1;a>0&&t[a]===0;a--)t.pop();return t}compactArray(){return this._sortData(),this._data.map(se)}};function re(r,t){return r+gt(t)}function gt(r){let t=r;return t=t-(t>>1&1431655765),t=(t&858993459)+(t>>2&858993459),(t+(t>>4)&252645135)*16843009>>24}function ne(r,t){return r[0]-t[0]}function se(r){return r[1]}});var _r={};d(_r,{Bucket:()=>M,createHAMT:()=>wr});var $t=te(yt(),1);function S(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var W={};d(W,{base10:()=>fe});var Pr=new Uint8Array(0);function wt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function B(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")}function _t(r){return new TextEncoder().encode(r)}function vt(r){return new TextDecoder().decode(r)}function oe(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(e[i]!==255)throw new TypeError(o+" is ambiguous");e[i]=s}var a=r.length,h=r.charAt(0),g=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function U(c){if(c instanceof Uint8Array||(ArrayBuffer.isView(c)?c=new Uint8Array(c.buffer,c.byteOffset,c.byteLength):Array.isArray(c)&&(c=Uint8Array.from(c))),!(c instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(c.length===0)return"";for(var l=0,P=0,b=0,x=c.length;b!==x&&c[b]===0;)b++,l++;for(var y=(x-b)*u+1>>>0,p=new Uint8Array(y);b!==x;){for(var w=c[b],A=0,m=y-1;(w!==0||A<P)&&m!==-1;m--,A++)w+=256*p[m]>>>0,p[m]=w%a>>>0,w=w/a>>>0;if(w!==0)throw new Error("Non-zero carry");P=A,b++}for(var v=y-P;v!==y&&p[v]===0;)v++;for(var R=h.repeat(l);v<y;++v)R+=r.charAt(p[v]);return R}function V(c){if(typeof c!="string")throw new TypeError("Expected String");if(c.length===0)return new Uint8Array;var l=0;if(c[l]!==" "){for(var P=0,b=0;c[l]===h;)P++,l++;for(var x=(c.length-l)*g+1>>>0,y=new Uint8Array(x);c[l];){var p=e[c.charCodeAt(l)];if(p===255)return;for(var w=0,A=x-1;(p!==0||w<b)&&A!==-1;A--,w++)p+=a*y[A]>>>0,y[A]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");b=w,l++}if(c[l]!==" "){for(var m=x-b;m!==x&&y[m]===0;)m++;for(var v=new Uint8Array(P+(x-m)),R=P;m!==x;)v[R++]=y[m++];return v}}}function Xt(c){var l=V(c);if(l)return l;throw new Error(`Non-${t} character`)}return{encode:U,decodeUnsafe:V,decode:Xt}}var ie=oe,ae=ie,At=ae;var Y=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Q=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ct(this,t)}},G=class{decoders;constructor(t){this.decoders=t}or(t){return Ct(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ct(r,t){return new G({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var H=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new Y(t,e,n),this.decoder=new Q(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function D({name:r,prefix:t,encode:e,decode:n}){return new H(r,t,e,n)}function C({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=At(e,r);return D({prefix:t,name:r,encode:n,decode:o=>B(s(o))})}function ce(r,t,e,n){let s={};for(let u=0;u<t.length;++u)s[t[u]]=u;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*e/8|0),a=0,h=0,g=0;for(let u=0;u<o;++u){let U=s[r[u]];if(U===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<e|U,a+=e,a>=8&&(a-=8,i[g++]=255&h>>a)}if(a>=e||255&h<<8-a)throw new SyntaxError("Unexpected end of data");return i}function he(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,o="",i=0,a=0;for(let h=0;h<r.length;++h)for(a=a<<8|r[h],i+=8;i>e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<e-i]),n)for(;o.length*e&7;)o+="=";return o}function f({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return D({prefix:t,name:r,encode(s){return he(s,n,e)},decode(s){return ce(s,n,e,r)}})}var fe=C({prefix:"9",name:"base10",alphabet:"0123456789"});var Z={};d(Z,{base16:()=>ue,base16upper:()=>le});var ue=f({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),le=f({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var tt={};d(tt,{base2:()=>de});var de=f({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var et={};d(et,{base256emoji:()=>xe});var Pt=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}"),pe=Pt.reduce((r,t,e)=>(r[e]=t,r),[]),be=Pt.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function me(r){return r.reduce((t,e)=>(t+=pe[e],t),"")}function ge(r){let t=[];for(let e of r){let n=be[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var xe=D({prefix:"\u{1F680}",name:"base256emoji",encode:me,decode:ge});var rt={};d(rt,{base32:()=>T,base32hex:()=>ve,base32hexpad:()=>Ae,base32hexpadupper:()=>Ce,base32hexupper:()=>Be,base32pad:()=>we,base32padupper:()=>_e,base32upper:()=>ye,base32z:()=>Pe});var T=f({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ye=f({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),we=f({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_e=f({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ve=f({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Be=f({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ae=f({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ce=f({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Pe=f({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var nt={};d(nt,{base36:()=>Se,base36upper:()=>Ee});var Se=C({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ee=C({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var st={};d(st,{base58btc:()=>_,base58flickr:()=>Ue});var _=C({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ue=C({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ot={};d(ot,{base64:()=>De,base64pad:()=>Te,base64url:()=>Ie,base64urlpad:()=>ke});var De=f({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Te=f({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ie=f({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ke=f({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var it={};d(it,{base8:()=>Fe});var Fe=f({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var at={};d(at,{identity:()=>Me});var Me=D({prefix:"\0",name:"identity",encode:r=>vt(r),decode:r=>_t(r)});var jr=new TextEncoder,$r=new TextDecoder;var ht={};d(ht,{identity:()=>sr});var Oe=Ut,St=128,Le=127,Ve=~Le,Re=Math.pow(2,31);function Ut(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Re;)t[e++]=r&255|St,r/=128;for(;r&Ve;)t[e++]=r&255|St,r>>>=7;return t[e]=r|0,Ut.bytes=e-n+1,t}var je=ct,$e=128,Et=127;function ct(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw ct.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&Et)<<s:(i&Et)*Math.pow(2,s),s+=7}while(i>=$e);return ct.bytes=o-n,e}var Je=Math.pow(2,7),qe=Math.pow(2,14),Ke=Math.pow(2,21),Xe=Math.pow(2,28),Ye=Math.pow(2,35),Qe=Math.pow(2,42),Ge=Math.pow(2,49),He=Math.pow(2,56),We=Math.pow(2,63),Ze=function(r){return r<Je?1:r<qe?2:r<Ke?3:r<Xe?4:r<Ye?5:r<Qe?6:r<Ge?7:r<He?8:r<We?9:10},tr={encode:Oe,decode:je,encodingLength:Ze},er=tr,z=er;function N(r,t=0){return[z.decode(r,t),z.decode.bytes]}function I(r,t,e=0){return z.encode(r,t,e),t}function k(r){return z.encodingLength(r)}function E(r,t){let e=t.byteLength,n=k(r),s=n+k(e),o=new Uint8Array(s+e);return I(r,o,0),I(e,o,n),o.set(t,s),new F(r,e,t,o)}function Dt(r){let t=B(r),[e,n]=N(t),[s,o]=N(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new F(e,s,i,t)}function Tt(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&wt(r.bytes,e.bytes)}}var F=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};var It=0,rr="identity",kt=B;function nr(r){return E(It,kt(r))}var sr={code:It,name:rr,encode:kt,digest:nr};var lt={};d(lt,{sha256:()=>or,sha512:()=>ir});function ut({name:r,code:t,encode:e}){return new ft(r,t,e)}var ft=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?E(this.code,e):e.then(n=>E(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Mt(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var or=ut({name:"sha2-256",code:18,encode:Mt("SHA-256")}),ir=ut({name:"sha2-512",code:19,encode:Mt("SHA-512")});function zt(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return cr(e,dt(r),t??_.encoder);default:return hr(e,dt(r),t??T.encoder)}}var Nt=new WeakMap;function dt(r){let t=Nt.get(r);if(t==null){let e=new Map;return Nt.set(r,e),e}return t}var J=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}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:t,multihash:e}=this;if(t!==L)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==fr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=E(t,e);return r.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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Tt(t.multihash,n.multihash)}toString(t){return zt(this,t)}toJSON(){return{"/":zt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:o,bytes:i}=e;return new r(n,s,o,i??Ot(n,s,o.bytes))}else if(e[ur]===!0){let{version:n,multihash:s,code:o}=e,i=Dt(s);return r.create(n,o,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==L)throw new Error(`Version 0 CID must use dag-pb (code: ${L}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=Ot(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,L,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=B(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=s.subarray(e.multihashSize-e.digestSize),i=new F(e.multihashCode,e.digestSize,o,s);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[U,V]=N(t.subarray(e));return e+=V,U},s=n(),o=L;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),h=n(),g=e+h,u=g-i;return{version:s,codec:o,multihashCode:a,digestSize:h,multihashSize:u,size:g}}static parse(t,e){let[n,s]=ar(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return dt(o).set(n,t),o}};function ar(r,t){switch(r[0]){case"Q":{let e=t??_;return[_.prefix,e.decode(`${_.prefix}${r}`)]}case _.prefix:{let e=t??_;return[_.prefix,e.decode(r)]}case T.prefix:{let e=t??T;return[T.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function cr(r,t,e){let{prefix:n}=e;if(n!==_.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function hr(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var L=112,fr=18;function Ot(r,t,e){let n=k(r),s=n+k(t),o=new Uint8Array(s+e.byteLength);return I(r,o,0),I(t,o,n),o.set(e,s),o}var ur=Symbol.for("@ipld/js-cid/CID");var pt={...at,...tt,...it,...W,...Z,...rt,...nt,...st,...ot,...et},un={...lt,...ht};function q(r=0){return globalThis.Buffer?.allocUnsafe!=null?S(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Vt(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Lt=Vt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),bt=Vt("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=q(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),lr={utf8:Lt,"utf-8":Lt,hex:pt.base16,latin1:bt,ascii:bt,binary:bt,...pt},Rt=lr;function jt(r,t="utf8"){let e=Rt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?S(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}var M=class r{_options;_popCount;_parent;_posAtParent;_children;key;constructor(t,e,n=0){this._options=t,this._popCount=0,this._parent=e,this._posAtParent=n,this._children=new $t.default,this.key=null}async put(t,e){let n=await this._findNewBucketAndPos(t);n.bucket._putAt(n,t,e)}async get(t){let e=await this._findChild(t);if(e!=null)return e.value}async del(t){let e=await this._findPlace(t),n=e.bucket._at(e.pos);n!=null&&n.key===t&&e.bucket._delAt(e.pos)}leafCount(){return this._children.compactArray().reduce((e,n)=>n instanceof r?e+n.leafCount():e+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let t=this._children.compactArray();for(let e of t)e instanceof r?yield*e.eachLeafSeries():yield e}serialize(t,e){let n=[];return e(this._children.reduce((s,o,i)=>(o!=null&&(o instanceof r?s.push(o.serialize(t,e)):s.push(t(o,i))),s),n))}async asyncTransform(t,e){return Jt(this,t,e)}toJSON(){return this.serialize(pr,br)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(t){let e=await this._findPlace(t),n=e.bucket._at(e.pos);if(!(n instanceof r)&&n!=null&&n.key===t)return n}async _findPlace(t){let e=this._options.hash(typeof t=="string"?jt(t):t),n=await e.take(this._options.bits),s=this._children.get(n);return s instanceof r?s._findPlace(e):{bucket:this,pos:n,hash:e,existingChild:s}}async _findNewBucketAndPos(t){let e=await this._findPlace(t);if(e.existingChild!=null&&e.existingChild.key!==t){let n=new r(this._options,e.bucket,e.pos);e.bucket._putObjectAt(e.pos,n);let s=await n._findPlace(e.existingChild.hash);return s.bucket._putAt(s,e.existingChild.key,e.existingChild.value),n._findNewBucketAndPos(e.hash)}return e}_putAt(t,e,n){this._putObjectAt(t.pos,{key:e,value:n,hash:t.hash})}_putObjectAt(t,e){this._children.get(t)==null&&this._popCount++,this._children.set(t,e)}_delAt(t){if(t===-1)throw new Error("Invalid position");this._children.get(t)!=null&&this._popCount--,this._children.unset(t),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let t=this._children.find(dr);if(t!=null&&!(t instanceof r)){let e=t.hash;e.untake(this._options.bits);let n={pos:this._posAtParent,hash:e,bucket:this._parent};this._parent._putAt(n,t.key,t.value)}}else this._parent._delAt(this._posAtParent)}_at(t){return this._children.get(t)}};function dr(r){return!!r}function pr(r,t){return r.key}function br(r){return r}async function Jt(r,t,e){let n=[];for(let s of r._children.compactArray())if(s instanceof M)await Jt(s,t,e);else{let o=await t(s);n.push({bitField:r._children.bitField(),children:o})}return e(n)}function qt(r,t){if(globalThis.Buffer!=null)return S(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=q(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return S(e)}var mr=[255,254,252,248,240,224,192,128],gr=[1,3,7,15,31,63,127,255],K=class{_value;_currentBytePos;_currentBitPos;constructor(t){this._value=t,this._currentBytePos=t.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(t){let e=t,n=0;for(;e>0&&this._haveBits();){let s=this._value[this._currentBytePos],o=this._currentBitPos+1,i=Math.min(o,e),a=xr(s,o-i,i);n=(n<<i)+a,e-=i,this._currentBitPos-=i,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(t){for(this._currentBitPos+=t;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function xr(r,t,e){let n=yr(t,e);return(r&n)>>>t}function yr(r,t){return mr[r]&gr[Math.min(t+r-1,7)]}function Kt(r){function t(e){return e instanceof X?e:new X(e,r)}return t}var X=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(t,e){if(!(t instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=t,this._hashFn=e,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(t){let e=t;for(;this._availableBits<e;)await this._produceMoreBits();let n=0;for(;e>0;){let s=this._buffers[this._currentBufferIndex],o=Math.min(s.availableBits(),e),i=s.take(o);n=(n<<o)+i,e-=o,this._availableBits-=o,s.availableBits()===0&&this._currentBufferIndex++}return n}untake(t){let e=t;for(;e>0;){let n=this._buffers[this._currentBufferIndex],s=Math.min(n.totalBits()-n.availableBits(),e);n.untake(s),e-=s,this._availableBits+=s,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let t=this._depth>0?qt([this._value,Uint8Array.from([this._depth])]):this._value,e=await this._hashFn(t),n=new K(e);this._buffers.push(n),this._availableBits+=n.availableBits()}};function wr(r){if(r==null||r.hashFn==null)throw new Error("please define an options.hashFn");let t={bits:r.bits??8,hash:Kt(r.hashFn)};return new M(t)}return ee(_r);})();
|
|
return HamtSharding}));
|