webpeerjs 0.1.9 → 0.1.10
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 +12 -7
- package/dist/esm/webpeerjs.js +1 -1
- package/dist/umd/webpeerjs.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
# WebPEER
|
|
2
|
-
> Decentralized P2P
|
|
1
|
+
# WebPEER
|
|
2
|
+
> Decentralized P2P network overlay inside browser
|
|
3
3
|
|
|
4
4
|
[WebPEER.js](https://github.com/nuzulul/webpeerjs) enables browser to browser connectivity without a central server. Build completely peer-to-peer web applications, no trackers or relay servers required. Connecting projects safely, privately, and reliably in WebPEER Network.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Basic Connection Demo available at : [https://nuzulul.github.io/webpeerjs/demo/](https://nuzulul.github.io/webpeerjs/demo/)
|
|
7
|
+
|
|
8
|
+
Basic Chat App Demo available at : [https://nuzulul.github.io/webpeerjs/demo/chat.html](https://nuzulul.github.io/webpeerjs/demo/chat.html)
|
|
7
9
|
|
|
8
10
|
## Security
|
|
9
11
|
|
|
@@ -57,13 +59,13 @@ void async function main() {
|
|
|
57
59
|
|
|
58
60
|
console.log(`My node id : ${node.id}`)
|
|
59
61
|
|
|
60
|
-
const [broadcast,listen,
|
|
62
|
+
const [broadcast,listen,onmembersupdate] = node.joinRoom('globalroom')
|
|
61
63
|
|
|
62
64
|
listen((message,id) => {
|
|
63
65
|
console.log(`Message from ${id} : ${message}`)
|
|
64
66
|
})
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
onmembersupdate((data) => {
|
|
67
69
|
console.log(`Members : ${data}`)
|
|
68
70
|
broadcast('hello')
|
|
69
71
|
})
|
|
@@ -75,11 +77,14 @@ void async function main() {
|
|
|
75
77
|
|
|
76
78
|
- `createWebpeer(config)` - Create a new node.
|
|
77
79
|
- `config` - Configuration object contain:
|
|
78
|
-
- `rtcConfiguration` - **(optional)** Custom [rtcConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection) for WebRTC transport, the only transport available for direct peer-to-peer connectivity between browser.
|
|
79
|
-
- `id` -
|
|
80
|
+
- `rtcConfiguration` - **(optional)** Custom [rtcConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection) for WebRTC transport, currently the only transport available for direct peer-to-peer connectivity between browser.
|
|
81
|
+
- `id` - Get the unique ID of the node as an identity in the global network.
|
|
80
82
|
- `status` - Get the node status, returns `connected` or `unconnected`.
|
|
81
83
|
- `peers` - Get all connected peers.
|
|
82
84
|
- `joinRoom(namespace)` - Join to the room, returns an array of three functions (Broadcaster, onListenBroadcast, onMembersUpdate).
|
|
85
|
+
- `Broadcaster` - Function to broadcast message to room members (limited to 1 message/second).
|
|
86
|
+
- `onListenBroadcast` - Callback function that listen on incoming broadcast message.
|
|
87
|
+
- `onMembersUpdate` - Callback function that listen on room members update.
|
|
83
88
|
|
|
84
89
|
## API Docs
|
|
85
90
|
|
package/dist/esm/webpeerjs.js
CHANGED
|
@@ -3,7 +3,7 @@ const e="webpeerjs",t=e,n="/"+e+"/1.0.0",r=e+"-dbstore",s=["universal-connectivi
|
|
|
3
3
|
//! WebPEER.js -- https://github.com/nuzulul/webpeerjs
|
|
4
4
|
var Gt;function Yt(e,t="utf8"){const n=Tt[t];if(null==n)throw new Error(`Unsupported encoding "${t}"`);return n.encoder.encode(e).substring(1)}!function(e){let t;e.codec=()=>(null==t&&(t=Wt(((e,t,n={})=>{if(!1!==n.lengthDelimited&&t.fork(),null!=e.publicKey&&e.publicKey.byteLength>0&&(t.uint32(10),t.bytes(e.publicKey)),null!=e.addrs)for(const n of e.addrs)t.uint32(18),t.bytes(n);!1!==n.lengthDelimited&&t.ldelim()}),((e,t)=>{const n={publicKey:m(0),addrs:[]},r=null==t?e.len:e.pos+t;for(;e.pos<r;){const t=e.uint32();switch(t>>>3){case 1:n.publicKey=e.bytes();break;case 2:n.addrs.push(e.bytes());break;default:e.skipType(7&t)}}return n}))),t),e.encode=t=>$t(t,e.codec()),e.decode=t=>j(t,e.codec())}(Gt||(Gt={}));const Qt="/",Jt=(new TextEncoder).encode(Qt),Zt=Jt[0];class Xt{_buf;constructor(e,t){if("string"==typeof e)this._buf=kt(e);else{if(!(e instanceof Uint8Array))throw new Error("Invalid key, should be String of Uint8Array");this._buf=e}if(null==t&&(t=!0),t&&this.clean(),0===this._buf.byteLength||this._buf[0]!==Zt)throw new Error("Invalid key")}toString(e="utf8"){return Yt(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new Xt(e.join(Qt))}static random(){return new Xt(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||"string"==typeof e?new Xt(e):"function"==typeof e.uint8Array?new Xt(e.uint8Array()):null}clean(){if(null!=this._buf&&0!==this._buf.byteLength||(this._buf=Jt),this._buf[0]!==Zt){const e=new Uint8Array(this._buf.byteLength+1);e.fill(Zt,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Zt;)this._buf=this._buf.subarray(0,-1)}less(e){const t=this.list(),n=e.list();for(let e=0;e<t.length;e++){if(n.length<e+1)return!1;const r=t[e],s=n[e];if(r<s)return!0;if(r>s)return!1}return t.length<n.length}reverse(){return Xt.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){const e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Qt).slice(1)}type(){return function(e){const t=e.split(":");if(t.length<2)return"";return t.slice(0,-1).join(":")}(this.baseNamespace())}name(){return function(e){const t=e.split(":");return t[t.length-1]}(this.baseNamespace())}instance(e){return new Xt(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Qt)||(e+=Qt),e+=this.type(),new Xt(e)}parent(){const e=this.list();return 1===e.length?new Xt(Qt):new Xt(e.slice(0,-1).join(Qt))}child(e){return this.toString()===Qt?e:e.toString()===Qt?this:new Xt(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()!==this.toString()&&e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()!==this.toString()&&this.toString().startsWith(e.toString())}isTopLevel(){return 1===this.list().length}concat(...e){return Xt.withNamespaces([...this.namespaces(),...(t=e.map((e=>e.namespaces())),[].concat(...t))]);var t}}const en=Symbol.for("@libp2p/connection"),tn=Symbol.for("@libp2p/content-routing"),nn=Symbol.for("@libp2p/peer-discovery"),rn=Symbol.for("@libp2p/peer-id");function sn(e){return null!=e&&Boolean(e[rn])}const on=Symbol.for("@libp2p/peer-routing"),an="StrictSign",cn="StrictNoSign";var ln;!function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"}(ln||(ln={}));const un=Symbol.for("@libp2p/transport");var hn;!function(e){e[e.FATAL_ALL=0]="FATAL_ALL",e[e.NO_FATAL=1]="NO_FATAL"}(hn||(hn={}));let dn=class e extends Error{code;type;constructor(t="The operation was aborted"){super(t),this.name="AbortError",this.code=e.code,this.type=e.type}static code="ABORT_ERR";static type="aborted"},pn=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};class fn extends AggregateError{code;props;constructor(e,t,n,r){super(e,t),this.code=n,this.name=r?.name??"AggregateCodeError",this.props=r??{}}}const gn="ERR_TIMEOUT",mn="ERR_INVALID_MESSAGE";class yn extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){const t=this.#e.get(e);return null==t?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let r=this.#e.get(e);null==r&&(r=[],this.#e.set(e,r)),r.push({callback:t,once:(!0!==n&&!1!==n&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let r=this.#e.get(e);null!=r&&(r=r.filter((({callback:e})=>e!==t)),this.#e.set(e,r))}dispatchEvent(e){const t=super.dispatchEvent(e);let n=this.#e.get(e.type);return null==n||(n=n.filter((({once:e})=>!e)),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new bn(e,t))}}class wn extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}}const bn=globalThis.CustomEvent??wn;function vn(e){return null!=e&&"function"==typeof e.start&&"function"==typeof e.stop}const En=Symbol.for("@libp2p/service-capabilities"),Sn=Symbol.for("@libp2p/service-dependencies");function _n(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}function In(e,t){null==t&&(t=e.reduce(((e,t)=>e+t.length),0));const n=y(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}const Rn=45,An=15,Tn=new class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){const t=this.index,n=e();return void 0===n&&(this.index=t),n}parseWith(e){const t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically((()=>{const t=this.readChar();if(t===e)return t}))}readSeparator(e,t,n){return this.readAtomically((()=>{if(!(t>0&&void 0===this.readGivenChar(e)))return n()}))}readNumber(e,t,n,r){return this.readAtomically((()=>{let s=0,i=0;const o=this.peekChar();if(void 0===o)return;const a="0"===o,c=2**(8*r)-1;for(;;){const n=this.readAtomically((()=>{const t=this.readChar();if(void 0===t)return;const n=Number.parseInt(t,e);return Number.isNaN(n)?void 0:n}));if(void 0===n)break;if(s*=e,s+=n,s>c)return;if(i+=1,void 0!==t&&i>t)return}return 0===i||!n&&a&&i>1?void 0:s}))}readIPv4Addr(){return this.readAtomically((()=>{const e=new Uint8Array(4);for(let t=0;t<e.length;t++){const n=this.readSeparator(".",t,(()=>this.readNumber(10,3,!1,1)));if(void 0===n)return;e[t]=n}return e}))}readIPv6Addr(){const e=e=>{for(let t=0;t<e.length/2;t++){const n=2*t;if(t<e.length-3){const r=this.readSeparator(":",t,(()=>this.readIPv4Addr()));if(void 0!==r)return e[n]=r[0],e[n+1]=r[1],e[n+2]=r[2],e[n+3]=r[3],[n+4,!0]}const r=this.readSeparator(":",t,(()=>this.readNumber(16,4,!0,2)));if(void 0===r)return[n,!1];e[n]=r>>8,e[n+1]=255&r}return[e.length,!1]};return this.readAtomically((()=>{const t=new Uint8Array(16),[n,r]=e(t);if(16===n)return t;if(r)return;if(void 0===this.readGivenChar(":"))return;if(void 0===this.readGivenChar(":"))return;const s=new Uint8Array(14),i=16-(n+2),[o]=e(s.subarray(0,i));return t.set(s.subarray(0,o),16-o),t}))}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};function kn(e){return Boolean(function(e){if(!(e.length>An))return Tn.new(e).parseWith((()=>Tn.readIPv4Addr()))}(e))}function Dn(e){return Boolean(function(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Rn))return Tn.new(e).parseWith((()=>Tn.readIPv6Addr()))}(e))}function Pn(e){return Boolean(function(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Rn))return Tn.new(e).parseWith((()=>Tn.readIPAddr()))}(e))}const Cn=kn,xn=Dn,Nn=function(e){let t=0;if(e=e.toString().trim(),Cn(e)){const n=new Uint8Array(t+4);return e.split(/\./g).forEach((e=>{n[t++]=255&parseInt(e,10)})),n}if(xn(e)){const n=e.split(":",8);let r;for(r=0;r<n.length;r++){let e;Cn(n[r])&&(e=Nn(n[r]),n[r]=Yt(e.slice(0,2),"base16")),null!=e&&++r<8&&n.splice(r,0,Yt(e.slice(2,4),"base16"))}if(""===n[0])for(;n.length<8;)n.unshift("0");else if(""===n[n.length-1])for(;n.length<8;)n.push("0");else if(n.length<8){for(r=0;r<n.length&&""!==n[r];r++);const e=[r,1];for(r=9-n.length;r>0;r--)e.push("0");n.splice.apply(n,e)}const s=new Uint8Array(t+16);for(r=0;r<n.length;r++){const e=parseInt(n[r],16);s[t++]=e>>8&255,s[t++]=255&e}return s}throw new Error("invalid ip address")},Mn=function(e,t=0,n){t=~~t,n=n??e.length-t;const r=new DataView(e.buffer);if(4===n){const r=[];for(let s=0;s<n;s++)r.push(e[t+s]);return r.join(".")}if(16===n){const e=[];for(let s=0;s<n;s+=2)e.push(r.getUint16(t+s).toString(16));return e.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""},On=-1,Ln={},Bn={};function Un(e){if("number"==typeof e){if(null!=Bn[e])return Bn[e];throw new Error(`no protocol with code: ${e}`)}if("string"==typeof e){if(null!=Ln[e])return Ln[e];throw new Error(`no protocol with name: ${e}`)}throw new Error("invalid protocol id type: "+typeof e)}function Fn(e,t){switch(Un(e).code){case 4:case 41:return function(e){const t=Mn(e,0,e.length);if(null==t)throw new Error("ipBuff is required");if(!Pn(t))throw new Error("invalid ip address");return t}(t);case 42:case 53:case 54:case 55:case 56:case 400:case 449:case 777:return jn(t);case 6:case 273:case 33:case 132:return zn(t).toString();case 421:return function(e){const t=C(e),n=e.slice(T(t));if(n.length!==t)throw new Error("inconsistent lengths");return Yt(n,"base58btc")}(t);case 444:case 445:return Gn(t);case 466:return function(e){const t=C(e),n=e.slice(T(t));if(n.length!==t)throw new Error("inconsistent lengths");return"u"+Yt(n,"base64url")}(t);case 481:return globalThis.encodeURIComponent(jn(t));default:return Yt(t,"base16")}}function Vn(e,t){switch(Un(e).code){case 4:case 41:return qn(t);case 42:case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Wn(t);case 6:case 273:case 33:case 132:return Hn(parseInt(t,10));case 421:return function(e){let t;t="Q"===e[0]||"1"===e[0]?lt(Pe.decode(`z${e}`)).bytes:wt.parse(e).multihash.bytes;const n=Uint8Array.from(P(t.length));return In([n,t],n.length+t.length)}(t);case 444:return function(e){const t=e.split(":");if(2!==t.length)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(16!==t[0].length)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);const n=ye.decode("b"+t[0]),r=parseInt(t[1],10);if(r<1||r>65536)throw new Error("Port number is not in range(1, 65536)");const s=Hn(r);return In([n,s],n.length+s.length)}(t);case 445:return function(e){const t=e.split(":");if(2!==t.length)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(56!==t[0].length)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);const n=ye.decode(`b${t[0]}`),r=parseInt(t[1],10);if(r<1||r>65536)throw new Error("Port number is not in range(1, 65536)");const s=Hn(r);return In([n,s],n.length+s.length)}(t);case 466:return function(e){const t=$n.decode(e),n=Uint8Array.from(P(t.length));return In([n,t],n.length+t.length)}(t);case 481:return Wn(globalThis.decodeURIComponent(t));default:return kt(t,"base16")}}[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,On,"ip6zone"],[43,8,"ipcidr"],[53,On,"dns",!0],[54,On,"dns4",!0],[55,On,"dns6",!0],[56,On,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,On,"unix",!1,!0],[421,On,"ipfs"],[421,On,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,On,"garlic64"],[448,0,"tls"],[449,On,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,On,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,On,"http-path"],[777,On,"memory"]].forEach((e=>{const t=function(e,t,n,r,s){return{code:e,size:t,name:n,resolvable:Boolean(r),path:Boolean(s)}}(...e);Bn[t.code]=t,Ln[t.name]=t})),Un("ip4"),Un("ip6"),Un("ipcidr");const Kn=Object.values(_t).map((e=>e.decoder)),$n=function(){let e=Kn[0].or(Kn[1]);return Kn.slice(2).forEach((t=>e=e.or(t))),e}();function qn(e){if(!Pn(e))throw new Error("invalid ip address");return Nn(e)}function Hn(e){const t=new ArrayBuffer(2);return new DataView(t).setUint16(0,e),new Uint8Array(t)}function zn(e){return new DataView(e.buffer).getUint16(e.byteOffset)}function Wn(e){const t=kt(e),n=Uint8Array.from(P(t.length));return In([n,t],n.length+t.length)}function jn(e){const t=C(e);if((e=e.slice(T(t))).length!==t)throw new Error("inconsistent lengths");return Yt(e)}function Gn(e){const t=e.slice(0,e.length-2),n=e.slice(e.length-2);return`${Yt(t,"base32")}:${zn(n)}`}function Yn(e){const t=[],n=[];let r=null,s=0;for(;s<e.length;){const i=C(e,s),o=T(i),a=Un(i),c=Zn(a,e.slice(s+o));if(0===c){t.push([i]),n.push([i]),s+=o;continue}const l=e.slice(s+o,s+o+c);if(s+=c+o,s>e.length)throw er("Invalid address Uint8Array: "+Yt(e,"base16"));t.push([i,l]);const u=Fn(i,l);if(n.push([i,u]),!0===a.path){r=u;break}}return{bytes:Uint8Array.from(e),string:Qn(n),tuples:t,stringTuples:n,path:r}}function Qn(e){const t=[];return e.map((e=>{const n=Un(e[0]);return t.push(n.name),e.length>1&&null!=e[1]&&t.push(e[1]),null})),Xn(t.join("/"))}function Jn(e){return In(e.map((e=>{const t=Un(e[0]);let n=Uint8Array.from(P(t.code));return e.length>1&&null!=e[1]&&(n=In([n,e[1]])),n})))}function Zn(e,t){if(e.size>0)return e.size/8;if(0===e.size)return 0;{const e=C(t instanceof Uint8Array?t:Uint8Array.from(t));return e+T(e)}}function Xn(e){return"/"+e.trim().split("/").filter((e=>e)).join("/")}function er(e){return new Error("Error parsing address: "+e)}const tr=Symbol.for("nodejs.util.inspect.custom"),nr=Symbol.for("@multiformats/js-multiaddr/multiaddr"),rr=[Un("dns").code,Un("dns4").code,Un("dns6").code,Un("dnsaddr").code];class sr{bytes;#t;#n;#r;#s;[nr]=!0;constructor(e){let t;if(null==e&&(e=""),e instanceof Uint8Array)t=Yn(e);else if("string"==typeof e){if(e.length>0&&"/"!==e.charAt(0))throw new Error(`multiaddr "${e}" must start with a "/"`);t=function(e){const t=[],n=[];let r=null;const s=(e=Xn(e)).split("/").slice(1);if(1===s.length&&""===s[0])return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<s.length;i++){const o=Un(s[i]);if(0===o.size){t.push([o.code]),n.push([o.code]);continue}if(i++,i>=s.length)throw er("invalid address: "+e);if(!0===o.path){r=Xn(s.slice(i).join("/")),t.push([o.code,Vn(o.code,r)]),n.push([o.code,r]);break}const a=Vn(o.code,s[i]);t.push([o.code,a]),n.push([o.code,Fn(o.code,a)])}return{string:Qn(n),bytes:Jn(t),tuples:t,stringTuples:n,path:r}}(e)}else{if(!or(e))throw new Error("addr must be a string, Buffer, or another Multiaddr");t=Yn(e.bytes)}this.bytes=t.bytes,this.#t=t.string,this.#n=t.tuples,this.#r=t.stringTuples,this.#s=t.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,r,s="";const i=Un("tcp"),o=Un("udp"),a=Un("ip4"),c=Un("ip6"),l=Un("dns6"),u=Un("ip6zone");for(const[h,d]of this.stringTuples())h===u.code&&(s=`%${d??""}`),rr.includes(h)&&(t=i.name,r=443,n=`${d??""}${s}`,e=h===l.code?6:4),h!==i.code&&h!==o.code||(t=Un(h).name,r=parseInt(d??"")),h!==a.code&&h!==c.code||(t=Un(h).name,n=`${d??""}${s}`,e=h===c.code?6:4);if(null==e||null==t||null==n||null==r)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:r}}protos(){return this.#n.map((([e])=>Object.assign({},Un(e))))}protoCodes(){return this.#n.map((([e])=>e))}protoNames(){return this.#n.map((([e])=>Un(e).name))}tuples(){return this.#n}stringTuples(){return this.#r}encapsulate(e){return e=new sr(e),new sr(this.toString()+e.toString())}decapsulate(e){const t=e.toString(),n=this.toString(),r=n.lastIndexOf(t);if(r<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new sr(n.slice(0,r))}decapsulateCode(e){const t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new sr(Jn(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach((([t,n])=>{t===Ln.p2p.code&&e.push([t,n]),t===Ln["p2p-circuit"].code&&(e=[])}));const t=e.pop();if(null!=t?.[1]){const e=t[1];return"Q"===e[0]||"1"===e[0]?Yt(Pe.decode(`z${e}`),"base58btc"):Yt(wt.parse(e).multihash.bytes,"base58btc")}return null}catch(e){return null}}getPath(){return this.#s}equals(e){return _n(this.bytes,e.bytes)}async resolve(e){const t=this.protos().find((e=>e.resolvable));if(null==t)return[this];const n=ir.get(t.name);if(null==n)throw new pn(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map((e=>ar(e)))}nodeAddress(){const e=this.toOptions();if("tcp"!==e.transport&&"udp"!==e.transport)throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){const t=(e??this).protos();return 2===t.length&&((4===t[0].code||41===t[0].code)&&(6===t[1].code||273===t[1].code))}[tr](){return`Multiaddr(${this.#t})`}}const ir=new Map;function or(e){return Boolean(e?.[nr])}function ar(e){return new sr(e)}function cr(){const e={};return e.promise=new Promise(((t,n)=>{e.resolve=t,e.reject=n})),e}class lr{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return void 0===this.buffer[this.top]&&(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){const e=this.buffer[this.btm];if(void 0!==e)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return void 0===this.buffer[this.btm]}}class ur{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new lr(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return null!=e?.byteLength?e.byteLength:1}push(e){if(null!=e?.value&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){const t=this.head;this.head=t.next=new lr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(void 0===e&&null!=this.tail.next){const t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return null!=e?.value&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}}let hr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function dr(e={}){return function(e,t){t=t??{};let n,r,s,i=t.onEnd,o=new ur,a=cr();const c=async()=>{try{return o.isEmpty()?s?{done:!0}:await new Promise(((t,s)=>{r=i=>{r=null,o.push(i);try{t(e(o))}catch(e){s(e)}return n}})):e(o)}finally{o.isEmpty()&&queueMicrotask((()=>{a.resolve(),a=cr()}))}},l=e=>null!=r?r(e):(o.push(e),n),u=e=>(o=new ur,null!=r?r({error:e}):(o.push({error:e}),n)),h=e=>{if(s)return n;if(!0!==t?.objectMode&&null==e?.byteLength)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:e})},d=e=>s?n:(s=!0,null!=e?u(e):l({done:!0})),p=()=>(o=new ur,d(),{done:!0}),f=e=>(d(e),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:c,return:p,throw:f,push:h,end:d,get readableLength(){return o.size},onEmpty:async e=>{const t=e?.signal;if(t?.throwIfAborted(),o.isEmpty())return;let n,r;null!=t&&(n=new Promise(((e,n)=>{r=()=>{n(new hr)},t.addEventListener("abort",r)})));try{await Promise.race([a.promise,n])}finally{null!=r&&null!=t&&t?.removeEventListener("abort",r)}}},null==i)return n;const g=n;return n={[Symbol.asyncIterator](){return this},next:()=>g.next(),throw:e=>(g.throw(e),null!=i&&(i(e),i=void 0),{done:!0}),return:()=>(g.return(),null!=i&&(i(),i=void 0),{done:!0}),push:h,end:e=>(g.end(e),null!=i&&(i(e),i=void 0),n),get readableLength(){return g.readableLength},onEmpty:e=>g.onEmpty(e)},n}((e=>{const t=e.shift();if(null==t)return{done:!0};if(null!=t.error)throw t.error;return{done:!0===t.done,value:t.value}}),e)}function pr(...e){const t=[];for(const n of e)null==n[Symbol.asyncIterator]&&t.push(n);return t.length===e.length?function*(){for(const e of t)yield*e}():async function*(){const t=dr({objectMode:!0});Promise.resolve().then((async()=>{try{await Promise.all(e.map((async e=>{for await(const n of e)t.push(n)}))),t.end()}catch(e){t.end(e)}})),yield*t}()}function fr(e,...t){if(null==e)throw new Error("Empty pipeline");if(wr(e)){const t=e;e=()=>t.source}else if(yr(e)||mr(e)){const t=e;e=()=>t}const n=[e,...t];if(n.length>1&&wr(n[n.length-1])&&(n[n.length-1]=n[n.length-1].sink),n.length>2)for(let e=1;e<n.length-1;e++)wr(n[e])&&(n[e]=br(n[e]));return gr(...n)}const gr=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},mr=e=>null!=e?.[Symbol.asyncIterator],yr=e=>null!=e?.[Symbol.iterator],wr=e=>null!=e&&(null!=e.sink&&null!=e.source),br=e=>t=>{const n=e.sink(t);if(null!=n?.then){const t=dr({objectMode:!0});let r;n.then((()=>{t.end()}),(e=>{t.end(e)}));const s=e.source;if(mr(s))r=async function*(){yield*s,t.end()};else{if(!yr(s))throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");r=function*(){yield*s,t.end()}}return pr(t,r())}return e.source},vr=Symbol.for("@achingbrain/uint8arraylist");function Er(e,t){if(null==t||t<0)throw new RangeError("index is out of bounds");let n=0;for(const r of e){const e=n+r.byteLength;if(t<e)return{buf:r,index:t-n};n=e}throw new RangeError("index is out of bounds")}function Sr(e){return Boolean(e?.[vr])}class _r{bufs;length;[vr]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(const n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else{if(!Sr(n))throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");t+=n.byteLength,this.bufs.push(...n.bufs)}this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(const n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else{if(!Sr(n))throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");t+=n.byteLength,this.bufs.unshift(...n.bufs)}this.length+=t}get(e){const t=Er(this.bufs,e);return t.buf[t.index]}set(e,t){const n=Er(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else{if(!Sr(e))throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList");for(let n=0;n<e.length;n++)this.set(t+n,e.get(n))}}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength)return this.bufs=[],void(this.length=0);for(;this.bufs.length>0;){if(!(e>=this.bufs[0].byteLength)){this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift()}}}slice(e,t){const{bufs:n,length:r}=this._subList(e,t);return In(n,r)}subarray(e,t){const{bufs:n,length:r}=this._subList(e,t);return 1===n.length?n[0]:In(n,r)}sublist(e,t){const{bufs:n,length:r}=this._subList(e,t),s=new _r;return s.length=r,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(0===e&&t===this.length)return{bufs:this.bufs,length:this.length};const n=[];let r=0;for(let s=0;s<this.bufs.length;s++){const i=this.bufs[s],o=r,a=o+i.byteLength;if(r=a,e>=a)continue;const c=e>=o&&e<a,l=t>o&&t<=a;if(c&&l){if(e===o&&t===a){n.push(i);break}const r=e-o;n.push(i.subarray(r,r+(t-e)));break}if(c){if(0===e){n.push(i);continue}n.push(i.subarray(e-o))}else{if(l){if(t===a){n.push(i);break}n.push(i.subarray(0,t-o));break}n.push(i)}}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!(Sr(e)||e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');const n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),0===e.length)return t>this.length?this.length:t;const r=n.byteLength;if(0===r)throw new TypeError("search must be at least 1 byte long");const s=new Int32Array(256);for(let e=0;e<256;e++)s[e]=-1;for(let e=0;e<r;e++)s[n[e]]=e;const i=s,o=this.byteLength-n.byteLength,a=n.byteLength-1;let c;for(let e=t;e<=o;e+=c){c=0;for(let t=a;t>=0;t--){const r=this.get(e+t);if(n[t]!==r){c=Math.max(1,t-i[r]);break}}if(0===c)return e}return-1}getInt8(e){const t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){const n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){const n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){const r=m(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt16(0,t,n),this.write(r,e)}getInt32(e,t){const n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){const r=m(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt32(0,t,n),this.write(r,e)}getBigInt64(e,t){const n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){const r=m(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigInt64(0,t,n),this.write(r,e)}getUint8(e){const t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){const n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){const n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){const r=m(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint16(0,t,n),this.write(r,e)}getUint32(e,t){const n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){const r=m(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint32(0,t,n),this.write(r,e)}getBigUint64(e,t){const n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){const r=m(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigUint64(0,t,n),this.write(r,e)}getFloat32(e,t){const n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){const r=m(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat32(0,t,n),this.write(r,e)}getFloat64(e,t){const n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){const r=m(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat64(0,t,n),this.write(r,e)}equals(e){if(null==e)return!1;if(!(e instanceof _r))return!1;if(e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!_n(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){const n=new _r;return n.bufs=e,null==t&&(t=e.reduce(((e,t)=>e+t.byteLength),0)),n.length=t,n}}let Ir=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Rr(e,t,n){if(null==t)return e;if(t.aborted)return Promise.reject(new Ir(n?.errorMessage,n?.errorCode));let r;const s=new Ir(n?.errorMessage,n?.errorCode);try{return await Promise.race([e,new Promise(((e,n)=>{r=()=>{n(s)},t.addEventListener("abort",r)}))])}finally{null!=r&&t.removeEventListener("abort",r)}}class Ar{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=cr(),this.haveNext=cr()}[Symbol.asyncIterator](){return this}async next(){if(null==this.nextResult&&await this.haveNext.promise,null==this.nextResult)throw new Error("HaveNext promise resolved but nextResult was undefined");const e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=cr(),e}async throw(e){this.ended=!0,null!=e&&this.haveNext.reject(e);return{done:!0,value:void 0}}async return(){const e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,t){await this._push(e,t)}async end(e,t){null!=e?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(null!=e&&this.ended)throw new Error("Cannot push value onto an ended pushable");if(null!=this.nextResult&&(await this.readNext.promise,null!=this.nextResult))throw new Error("NeedNext promise resolved but nextResult was not consumed");null!=e?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=cr(),await Rr(this.readNext.promise,t?.signal,t)}}let Tr=class extends Error{code;constructor(e,t){super(e),this.code=t}},kr=class extends Tr{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function Dr(e,t){const n=new Ar;e.sink(n).catch((async e=>{await n.end(e)})),e.sink=async e=>{for await(const t of e)await n.push(t);await n.end()};let r=e.source;null!=e.source[Symbol.iterator]?r=e.source[Symbol.iterator]():null!=e.source[Symbol.asyncIterator]&&(r=e.source[Symbol.asyncIterator]());const s=new _r,i={read:async(e,t)=>{let n;t?.signal?.throwIfAborted();const i=new Promise(((e,r)=>{n=()=>{r(new kr("Read aborted"))},t?.signal?.addEventListener("abort",n)}));try{if(null==e){const{done:e,value:t}=await Promise.race([r.next(),i]);return!0===e?new _r:t}for(;s.byteLength<e;){const{value:e,done:t}=await Promise.race([r.next(),i]);if(!0===t)throw new Tr("unexpected end of input","ERR_UNEXPECTED_EOF");s.append(e)}const t=s.sublist(0,e);return s.consume(e),t}finally{null!=n&&t?.signal?.removeEventListener("abort",n)}},write:async(e,t)=>{t?.signal?.throwIfAborted(),e instanceof Uint8Array?await n.push(e,t):await n.push(e.subarray(),t)},unwrap:()=>{if(s.byteLength>0){const n=e.source;e.source=async function*(){!1===t?.yieldBytes?yield s:yield*s,yield*n}()}return e}};return i}class Pr extends Error{code;constructor(e,t){super(e),this.code=t}}function Cr(e,t={}){const n=Dr(e,t);null!=t.maxDataLength&&null==t.maxLengthLength&&(t.maxLengthLength=T(t.maxDataLength));const r=t?.lengthDecoder??C,s=t?.lengthEncoder??P;return{read:async e=>{let s=-1;const i=new _r;for(;;){i.append(await n.read(1,e));try{s=r(i)}catch(e){if(e instanceof RangeError)continue;throw e}if(null!=t?.maxLengthLength&&i.byteLength>t.maxLengthLength)throw new Pr("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(s>-1)break}if(null!=t?.maxDataLength&&s>t.maxDataLength)throw new Pr("message length too long","ERR_MSG_DATA_TOO_LONG");return n.read(s,e)},write:async(e,t)=>{await n.write(new _r(s(e.byteLength),e),t)},writeV:async(e,t)=>{const r=new _r(...e.flatMap((e=>[s(e.byteLength),e])));await n.write(r,t)},unwrap:()=>n.unwrap()}}function xr(e){return null!=e[Symbol.asyncIterator]}const Nr=e=>{const t=T(e),n=y(t);return P(e,n),Nr.bytes=t,n};function Mr(e,t){const n=(t=t??{}).lengthEncoder??Nr;function*r(e){const t=n(e.byteLength);t instanceof Uint8Array?yield t:yield*t,e instanceof Uint8Array?yield e:yield*e}return xr(e)?async function*(){for await(const t of e)yield*r(t)}():function*(){for(const t of e)yield*r(t)}()}Nr.bytes=0,Mr.single=(e,t)=>{const n=(t=t??{}).lengthEncoder??Nr;return new _r(n(e.byteLength),e)};var Or="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Lr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Br(e,t){for(const n in t)Object.defineProperty(e,n,{value:t[n],enumerable:!0,configurable:!0});return e}var Ur=function(e,t,n){if(!e||"string"==typeof e)throw new TypeError("Please pass an Error to err-code");n||(n={}),"object"==typeof t&&(n=t,t=""),t&&(n.code=t);try{return Br(e,n)}catch(t){n.message=e.message,n.stack=e.stack;const r=function(){};r.prototype=Object.create(Object.getPrototypeOf(e));return Br(new r,n)}},Fr=Lr(Ur);var Vr;!function(e){e[e.LENGTH=0]="LENGTH",e[e.DATA=1]="DATA"}(Vr||(Vr={}));const Kr=e=>{const t=C(e);return Kr.bytes=T(t),t};function $r(e,t){const n=new _r;let r=Vr.LENGTH,s=-1;const i=t?.lengthDecoder??Kr,o=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;n.byteLength>0;){if(r===Vr.LENGTH)try{if(s=i(n),s<0)throw Fr(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw Fr(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");const e=i.bytes;n.consume(e),null!=t?.onLength&&t.onLength(s),r=Vr.DATA}catch(e){if(e instanceof RangeError){if(n.byteLength>o)throw Fr(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw e}if(r===Vr.DATA){if(n.byteLength<s)break;const e=n.sublist(0,s);n.consume(s),null!=t?.onData&&t.onData(e),yield e,r=Vr.LENGTH}}}return xr(e)?async function*(){for await(const t of e)n.append(t),yield*c();if(n.byteLength>0)throw Fr(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(const t of e)n.append(t),yield*c();if(n.byteLength>0)throw Fr(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}function qr(e){const[t,n]=null!=e[Symbol.asyncIterator]?[e[Symbol.asyncIterator](),Symbol.asyncIterator]:[e[Symbol.iterator](),Symbol.iterator],r=[];return{peek:()=>t.next(),push:e=>{r.push(e)},next:()=>r.length>0?{done:!1,value:r.shift()}:t.next(),[n](){return this}}}function Hr(e,t){let n=0;if(null!=e[Symbol.asyncIterator])return async function*(){for await(const r of e)yield t(r,n++)}();const r=qr(e),{value:s,done:i}=r.next();if(!0===i)return function*(){}();const o=t(s,n++);if("function"==typeof o.then)return async function*(){yield await o;for await(const e of r)yield t(e,n++)}();const a=t;return function*(){yield o;for(const e of r)yield a(e,n++)}()}
|
|
5
5
|
//! WebPEER.js -- https://github.com/nuzulul/webpeerjs
|
|
6
|
-
Kr.bytes=0,$r.fromReader=(e,t)=>{let n=1;return $r(async function*(){for(;;)try{const{done:t,value:r}=await e.next(n);if(!0===t)return;null!=r&&(yield r)}catch(e){if("ERR_UNDER_READ"===e.code)return{done:!0,value:null};throw e}finally{n=1}}(),{...t??{},onLength:e=>{n=e}})};const zr=t,Wr=e=>new Error(`${zr}: ${e}`);function jr(e){return(new TextDecoder).decode(e)}function Gr(e){return(new TextEncoder).encode(e)}async function Yr(e){for await(const t of e)return t}window.opr&&window.opr.addons||window.opera||navigator.userAgent.indexOf(" OPR/");const Qr="undefined"!=typeof InstallTrigger;/constructor/i.test(window.HTMLElement)||(!window.safari||"undefined"!=typeof safari&&window.safari.pushNotification).toString();async function Jr(e){const t=e,n=(new TextEncoder).encode(t.sequenceNumber.toString());return await ft.encode(n)}!(!window.chrome||!window.chrome.webstore&&!window.chrome.runtime)&&navigator.userAgent.indexOf("Edg");let Zr={readyErrored:0,noiseErrored:0,upgradeErrored:0,readyTimedout:0,noiseTimedout:0,success:0},Xr={pending:0,open:0,ready_error:0,noise_error:0,upgrade_error:0,ready_timeout:0,noise_timeout:0,close:0,abort:0,remote_close:0},es={pending:0,ready_error:0,noise_error:0,upgrade_error:0,close:0,remote_close:0,ready:0,abort:0,ready_timeout:0,noise_timeout:0,open:0},ts=0,ns=0,rs=!0,ss=0,is=!0,os=0;if(!WebTransport)throw Wr("It seems that your browser does not support the required WebTransport feature");var as,cs,ls={exports:{}};function us(){if(cs)return as;cs=1;var e=1e3,t=60*e,n=60*t,r=24*n,s=7*r,i=365.25*r;function o(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"s":"")}return as=function(a,c){c=c||{};var l=typeof a;if("string"===l&&a.length>0)return function(o){if((o=String(o)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(o);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*i;case"weeks":case"week":case"w":return c*s;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===l&&isFinite(a))return c.long?function(s){var i=Math.abs(s);if(i>=r)return o(s,i,r,"day");if(i>=n)return o(s,i,n,"hour");if(i>=t)return o(s,i,t,"minute");if(i>=e)return o(s,i,e,"second");return s+" ms"}(a):function(s){var i=Math.abs(s);if(i>=r)return Math.round(s/r)+"d";if(i>=n)return Math.round(s/n)+"h";if(i>=t)return Math.round(s/t)+"m";if(i>=e)return Math.round(s/e)+"s";return s+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}var hs=function(e){function t(e){let r,s,i,o=null;function a(...e){if(!a.enabled)return;const n=a,s=Number(new Date),i=s-(r||s);n.diff=i,n.prev=r,n.curr=s,r=s,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let o=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((r,s)=>{if("%%"===r)return"%";o++;const i=t.formatters[s];if("function"==typeof i){const t=e[o];r=i.call(n,t),e.splice(o,1),o--}return r})),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=n,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==o?o:(s!==t.namespaces&&(s=t.namespaces,i=t.enabled(e)),i),set:e=>{o=e}}),"function"==typeof t.init&&t.init(a),a}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(r),...t.skips.map(r).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(n=0;n<s;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=us(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t};!function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,s=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))})),t.splice(s,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=hs(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(ls,ls.exports);var ds=Lr(ls.exports);function ps(){return{forComponent:e=>fs(e)}}function fs(e){let t=function(e){const t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}(`${e}:trace`);return ds.enabled(`${e}:trace`)&&null!=ds.names.map((e=>e.toString())).find((e=>e.includes(":trace")))&&(t=ds(`${e}:trace`)),Object.assign(ds(e),{error:ds(`${e}:error`),trace:t})}ds.formatters.b=e=>null==e?"undefined":Pe.baseEncode(e),ds.formatters.t=e=>null==e?"undefined":ye.baseEncode(e),ds.formatters.m=e=>null==e?"undefined":Ne.baseEncode(e),ds.formatters.p=e=>null==e?"undefined":e.toString(),ds.formatters.c=e=>null==e?"undefined":e.toString(),ds.formatters.k=e=>null==e?"undefined":e.toString(),ds.formatters.a=e=>null==e?"undefined":e.toString();const gs=Symbol.for("nodejs.util.inspect.custom"),ms=Object.values(_t).map((e=>e.decoder)).reduce(((e,t)=>e.or(t)),_t.identity.decoder),ys=114,ws=36,bs=37;class vs{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[rn]=!0;toString(){return null==this.string&&(this.string=Pe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return wt.createV1(ys,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(null==e)return!1;if(e instanceof Uint8Array)return _n(this.multihash.bytes,e);if("string"==typeof e)return Is(e).equals(this);if(null!=e?.multihash?.bytes)return _n(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[gs](){return`PeerId(${this.toString()})`}}class Es extends vs{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}}class Ss extends vs{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}}class _s extends vs{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}}function Is(e,t){if(t=t??ms,"1"===e.charAt(0)||"Q"===e.charAt(0)){const t=lt(Pe.decode(`z${e}`));return e.startsWith("12D")?new Ss({multihash:t}):e.startsWith("16U")?new _s({multihash:t}):new Es({multihash:t})}return Rs(ms.decode(e))}function Rs(e){try{const t=lt(e);if(t.code===dt.code){if(t.digest.length===ws)return new Ss({multihash:t});if(t.digest.length===bs)return new _s({multihash:t})}if(t.code===ft.code)return new Es({multihash:t})}catch{return function(e){if(null==e||null==e.multihash||null==e.version||1===e.version&&e.code!==ys)throw new Error("Supplied PeerID CID is invalid");const t=e.multihash;if(t.code===ft.code)return new Es({multihash:e.multihash});if(t.code===dt.code){if(t.digest.length===ws)return new Ss({multihash:e.multihash});if(t.digest.length===bs)return new _s({multihash:e.multihash})}throw new Error("Supplied PeerID CID is invalid")}(wt.decode(e))}throw new Error("Supplied PeerID CID is invalid")}async function As(e,t){return e.length===ws?new Ss({multihash:ct(dt.code,e),privateKey:t}):e.length===bs?new _s({multihash:ct(dt.code,e),privateKey:t}):new Es({multihash:await ft.digest(e),publicKey:e,privateKey:t})}function Ts(e){const t=new globalThis.AbortController;function n(){t.abort();for(const t of e)null!=t?.removeEventListener&&t.removeEventListener("abort",n)}for(const t of e){if(!0===t?.aborted){n();break}null!=t?.addEventListener&&t.addEventListener("abort",n)}const r=t.signal;return r.clear=function(){for(const t of e)null!=t?.removeEventListener&&t.removeEventListener("abort",n)},r}async function*ks(e,t={}){const n=e.getReader();try{for(;;){const e=await n.read();if(e.done)return;yield e.value}}finally{!0!==t.preventCancel&&await n.cancel(),n.releaseLock()}}function Ds(e){return null!=e&&("function"==typeof e.then&&"function"==typeof e.catch&&"function"==typeof e.finally)}function Ps(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Cs(e,...t){if(!((n=e)instanceof Uint8Array||null!=n&&"object"==typeof n&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function xs(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Ps(e.outputLen),Ps(e.blockLen)}function Ns(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const Ms="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,Os=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Ls=(e,t)=>e<<32-t|e>>>t;
|
|
6
|
+
Kr.bytes=0,$r.fromReader=(e,t)=>{let n=1;return $r(async function*(){for(;;)try{const{done:t,value:r}=await e.next(n);if(!0===t)return;null!=r&&(yield r)}catch(e){if("ERR_UNDER_READ"===e.code)return{done:!0,value:null};throw e}finally{n=1}}(),{...t??{},onLength:e=>{n=e}})};const zr=t,Wr=e=>new Error(`${zr}: ${e}`);function jr(e){return(new TextDecoder).decode(e)}function Gr(e){return(new TextEncoder).encode(e)}async function Yr(e){for await(const t of e)return t}window.opr&&window.opr.addons||window.opera||navigator.userAgent.indexOf(" OPR/");const Qr="undefined"!=typeof InstallTrigger;/constructor/i.test(window.HTMLElement)||(!window.safari||"undefined"!=typeof safari&&window.safari.pushNotification).toString();async function Jr(e){const t=e,n=(new TextEncoder).encode(t.sequenceNumber.toString());return await ft.encode(n)}!(!window.chrome||!window.chrome.webstore&&!window.chrome.runtime)&&navigator.userAgent.indexOf("Edg");let Zr={readyErrored:0,noiseErrored:0,upgradeErrored:0,readyTimedout:0,noiseTimedout:0,success:0},Xr={pending:0,open:0,ready_error:0,noise_error:0,upgrade_error:0,ready_timeout:0,noise_timeout:0,close:0,abort:0,remote_close:0},es={pending:0,ready_error:0,noise_error:0,upgrade_error:0,close:0,remote_close:0,ready:0,abort:0,ready_timeout:0,noise_timeout:0,open:0},ts=0,ns=0,rs=!0,ss=0,is=!0,os=0;if(!WebTransport)throw Wr("It seems that your browser does not support the required WebTransport feature");var as,cs,ls={exports:{}};function us(){if(cs)return as;cs=1;var e=1e3,t=60*e,n=60*t,r=24*n,s=7*r,i=365.25*r;function o(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"s":"")}return as=function(a,c){c=c||{};var l=typeof a;if("string"===l&&a.length>0)return function(o){if((o=String(o)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(o);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*i;case"weeks":case"week":case"w":return c*s;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===l&&isFinite(a))return c.long?function(s){var i=Math.abs(s);if(i>=r)return o(s,i,r,"day");if(i>=n)return o(s,i,n,"hour");if(i>=t)return o(s,i,t,"minute");if(i>=e)return o(s,i,e,"second");return s+" ms"}(a):function(s){var i=Math.abs(s);if(i>=r)return Math.round(s/r)+"d";if(i>=n)return Math.round(s/n)+"h";if(i>=t)return Math.round(s/t)+"m";if(i>=e)return Math.round(s/e)+"s";return s+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}var hs=function(e){function t(e){let r,s,i,o=null;function a(...e){if(!a.enabled)return;const n=a,s=Number(new Date),i=s-(r||s);n.diff=i,n.prev=r,n.curr=s,r=s,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let o=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((r,s)=>{if("%%"===r)return"%";o++;const i=t.formatters[s];if("function"==typeof i){const t=e[o];r=i.call(n,t),e.splice(o,1),o--}return r})),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=n,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==o?o:(s!==t.namespaces&&(s=t.namespaces,i=t.enabled(e)),i),set:e=>{o=e}}),"function"==typeof t.init&&t.init(a),a}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(r),...t.skips.map(r).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(n=0;n<s;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=us(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t};!function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,s=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))})),t.splice(s,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=hs(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(ls,ls.exports);var ds=Lr(ls.exports);function ps(){return{forComponent:e=>fs(e)}}function fs(e){let t=function(e){const t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}(`${e}:trace`);return ds.enabled(`${e}:trace`)&&null!=ds.names.map((e=>e.toString())).find((e=>e.includes(":trace")))&&(t=ds(`${e}:trace`)),Object.assign(ds(e),{error:ds(`${e}:error`),trace:t})}ds.formatters.b=e=>null==e?"undefined":Pe.baseEncode(e),ds.formatters.t=e=>null==e?"undefined":ye.baseEncode(e),ds.formatters.m=e=>null==e?"undefined":Ne.baseEncode(e),ds.formatters.p=e=>null==e?"undefined":e.toString(),ds.formatters.c=e=>null==e?"undefined":e.toString(),ds.formatters.k=e=>null==e?"undefined":e.toString(),ds.formatters.a=e=>null==e?"undefined":e.toString();const gs=Symbol.for("nodejs.util.inspect.custom"),ms=Object.values(_t).map((e=>e.decoder)).reduce(((e,t)=>e.or(t)),_t.identity.decoder),ys=114,ws=36,bs=37;class vs{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[rn]=!0;toString(){return null==this.string&&(this.string=Pe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return wt.createV1(ys,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(null==e)return!1;if(e instanceof Uint8Array)return _n(this.multihash.bytes,e);if("string"==typeof e)return Is(e).equals(this);if(null!=e?.multihash?.bytes)return _n(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[gs](){return`PeerId(${this.toString()})`}}class Es extends vs{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}}class Ss extends vs{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}}class _s extends vs{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}}function Is(e,t){if("1"===e.charAt(0)||"Q"===e.charAt(0)){const t=lt(Pe.decode(`z${e}`));return e.startsWith("12D")?new Ss({multihash:t}):e.startsWith("16U")?new _s({multihash:t}):new Es({multihash:t})}return Rs(ms.decode(e))}function Rs(e){try{const t=lt(e);if(t.code===dt.code){if(t.digest.length===ws)return new Ss({multihash:t});if(t.digest.length===bs)return new _s({multihash:t})}if(t.code===ft.code)return new Es({multihash:t})}catch{return function(e){if(null==e||null==e.multihash||null==e.version||1===e.version&&e.code!==ys)throw new Error("Supplied PeerID CID is invalid");const t=e.multihash;if(t.code===ft.code)return new Es({multihash:e.multihash});if(t.code===dt.code){if(t.digest.length===ws)return new Ss({multihash:e.multihash});if(t.digest.length===bs)return new _s({multihash:e.multihash})}throw new Error("Supplied PeerID CID is invalid")}(wt.decode(e))}throw new Error("Supplied PeerID CID is invalid")}async function As(e,t){return e.length===ws?new Ss({multihash:ct(dt.code,e),privateKey:t}):e.length===bs?new _s({multihash:ct(dt.code,e),privateKey:t}):new Es({multihash:await ft.digest(e),publicKey:e,privateKey:t})}function Ts(e){const t=new globalThis.AbortController;function n(){t.abort();for(const t of e)null!=t?.removeEventListener&&t.removeEventListener("abort",n)}for(const t of e){if(!0===t?.aborted){n();break}null!=t?.addEventListener&&t.addEventListener("abort",n)}const r=t.signal;return r.clear=function(){for(const t of e)null!=t?.removeEventListener&&t.removeEventListener("abort",n)},r}async function*ks(e,t={}){const n=e.getReader();try{for(;;){const e=await n.read();if(e.done)return;yield e.value}}finally{!0!==t.preventCancel&&await n.cancel(),n.releaseLock()}}function Ds(e){return null!=e&&("function"==typeof e.then&&"function"==typeof e.catch&&"function"==typeof e.finally)}function Ps(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Cs(e,...t){if(!((n=e)instanceof Uint8Array||null!=n&&"object"==typeof n&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function xs(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Ps(e.outputLen),Ps(e.blockLen)}function Ns(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const Ms="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,Os=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Ls=(e,t)=>e<<32-t|e>>>t;
|
|
7
7
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */new Uint8Array(new Uint32Array([287454020]).buffer)[0];const Bs=async()=>{};async function Us(e,t,n){let r=Date.now();for(let s=0;s<e;s++){n(s);const e=Date.now()-r;e>=0&&e<t||(await Bs(),r+=e)}}function Fs(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}function Vs(e){return"string"==typeof e&&(e=Fs(e)),Cs(e),e}function Ks(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];Cs(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const s=e[t];n.set(s,r),r+=s.length}return n}class $s{clone(){return this._cloneInto()}}const qs={}.toString;function Hs(e){const t=t=>e().update(Vs(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function zs(e=32){if(Ms&&"function"==typeof Ms.getRandomValues)return Ms.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}const Ws=(e,t,n)=>e&t^e&n^t&n;class js extends $s{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Os(this.buffer)}update(e){Ns(this);const{view:t,buffer:n,blockLen:r}=this,s=(e=Vs(e)).length;for(let i=0;i<s;){const o=Math.min(r-this.pos,s-i);if(o!==r)n.set(e.subarray(i,i+o),this.pos),this.pos+=o,i+=o,this.pos===r&&(this.process(t,0),this.pos=0);else{const t=Os(e);for(;r<=s-i;i+=r)this.process(t,i)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ns(this),function(e,t){Cs(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:s}=this;let{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const s=BigInt(32),i=BigInt(4294967295),o=Number(n>>s&i),a=Number(n&i),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,a,r)}(n,r-8,BigInt(8*this.length),s),this.process(n,0);const o=Os(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,l=this.get();if(c>l.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)o.setUint32(4*e,l[e],s)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:s,destroyed:i,pos:o}=this;return e.length=r,e.pos=o,e.finished=s,e.destroyed=i,r%t&&e.buffer.set(n),e}}const Gs=BigInt(2**32-1),Ys=BigInt(32);function Qs(e,t=!1){return t?{h:Number(e&Gs),l:Number(e>>Ys&Gs)}:{h:0|Number(e>>Ys&Gs),l:0|Number(e&Gs)}}const Js={fromBig:Qs,split:function(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let s=0;s<e.length;s++){const{h:i,l:o}=Qs(e[s],t);[n[s],r[s]]=[i,o]}return[n,r]},toBig:(e,t)=>BigInt(e>>>0)<<Ys|BigInt(t>>>0),shrSH:(e,t,n)=>e>>>n,shrSL:(e,t,n)=>e<<32-n|t>>>n,rotrSH:(e,t,n)=>e>>>n|t<<32-n,rotrSL:(e,t,n)=>e<<32-n|t>>>n,rotrBH:(e,t,n)=>e<<64-n|t>>>n-32,rotrBL:(e,t,n)=>e>>>n-32|t<<64-n,rotr32H:(e,t)=>t,rotr32L:(e,t)=>e,rotlSH:(e,t,n)=>e<<n|t>>>32-n,rotlSL:(e,t,n)=>t<<n|e>>>32-n,rotlBH:(e,t,n)=>t<<n-32|e>>>64-n,rotlBL:(e,t,n)=>e<<n-32|t>>>64-n,add:function(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:0|s}},add3L:(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),add3H:(e,t,n,r)=>t+n+r+(e/2**32|0)|0,add4L:(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),add4H:(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,add5H:(e,t,n,r,s,i)=>t+n+r+s+i+(e/2**32|0)|0,add5L:(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0)},[Zs,Xs]=(()=>Js.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((e=>BigInt(e)))))(),ei=new Uint32Array(80),ti=new Uint32Array(80);class ni extends js{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:s,Cl:i,Dh:o,Dl:a,Eh:c,El:l,Fh:u,Fl:h,Gh:d,Gl:p,Hh:f,Hl:g}=this;return[e,t,n,r,s,i,o,a,c,l,u,h,d,p,f,g]}set(e,t,n,r,s,i,o,a,c,l,u,h,d,p,f,g){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|s,this.Cl=0|i,this.Dh=0|o,this.Dl=0|a,this.Eh=0|c,this.El=0|l,this.Fh=0|u,this.Fl=0|h,this.Gh=0|d,this.Gl=0|p,this.Hh=0|f,this.Hl=0|g}process(e,t){for(let n=0;n<16;n++,t+=4)ei[n]=e.getUint32(t),ti[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|ei[e-15],n=0|ti[e-15],r=Js.rotrSH(t,n,1)^Js.rotrSH(t,n,8)^Js.shrSH(t,n,7),s=Js.rotrSL(t,n,1)^Js.rotrSL(t,n,8)^Js.shrSL(t,n,7),i=0|ei[e-2],o=0|ti[e-2],a=Js.rotrSH(i,o,19)^Js.rotrBH(i,o,61)^Js.shrSH(i,o,6),c=Js.rotrSL(i,o,19)^Js.rotrBL(i,o,61)^Js.shrSL(i,o,6),l=Js.add4L(s,c,ti[e-7],ti[e-16]),u=Js.add4H(l,r,a,ei[e-7],ei[e-16]);ei[e]=0|u,ti[e]=0|l}let{Ah:n,Al:r,Bh:s,Bl:i,Ch:o,Cl:a,Dh:c,Dl:l,Eh:u,El:h,Fh:d,Fl:p,Gh:f,Gl:g,Hh:m,Hl:y}=this;for(let e=0;e<80;e++){const t=Js.rotrSH(u,h,14)^Js.rotrSH(u,h,18)^Js.rotrBH(u,h,41),w=Js.rotrSL(u,h,14)^Js.rotrSL(u,h,18)^Js.rotrBL(u,h,41),b=u&d^~u&f,v=h&p^~h&g,E=Js.add5L(y,w,v,Xs[e],ti[e]),S=Js.add5H(E,m,t,b,Zs[e],ei[e]),_=0|E,I=Js.rotrSH(n,r,28)^Js.rotrBH(n,r,34)^Js.rotrBH(n,r,39),R=Js.rotrSL(n,r,28)^Js.rotrBL(n,r,34)^Js.rotrBL(n,r,39),A=n&s^n&o^s&o,T=r&i^r&a^i&a;m=0|f,y=0|g,f=0|d,g=0|p,d=0|u,p=0|h,({h:u,l:h}=Js.add(0|c,0|l,0|S,0|_)),c=0|o,l=0|a,o=0|s,a=0|i,s=0|n,i=0|r;const k=Js.add3L(_,R,T);n=Js.add3H(k,S,I,A),r=0|k}({h:n,l:r}=Js.add(0|this.Ah,0|this.Al,0|n,0|r)),({h:s,l:i}=Js.add(0|this.Bh,0|this.Bl,0|s,0|i)),({h:o,l:a}=Js.add(0|this.Ch,0|this.Cl,0|o,0|a)),({h:c,l:l}=Js.add(0|this.Dh,0|this.Dl,0|c,0|l)),({h:u,l:h}=Js.add(0|this.Eh,0|this.El,0|u,0|h)),({h:d,l:p}=Js.add(0|this.Fh,0|this.Fl,0|d,0|p)),({h:f,l:g}=Js.add(0|this.Gh,0|this.Gl,0|f,0|g)),({h:m,l:y}=Js.add(0|this.Hh,0|this.Hl,0|m,0|y)),this.set(n,r,s,i,o,a,c,l,u,h,d,p,f,g,m,y)}roundClean(){ei.fill(0),ti.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const ri=Hs((()=>new ni)),si=BigInt(0),ii=BigInt(1),oi=BigInt(2);
|
|
8
8
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ai(e){return e instanceof Uint8Array||null!=e&&"object"==typeof e&&"Uint8Array"===e.constructor.name}function ci(e){if(!ai(e))throw new Error("Uint8Array expected")}const li=Array.from({length:256},((e,t)=>t.toString(16).padStart(2,"0")));function ui(e){ci(e);let t="";for(let n=0;n<e.length;n++)t+=li[e[n]];return t}function hi(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function di(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}const pi={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function fi(e){return e>=pi._0&&e<=pi._9?e-pi._0:e>=pi._A&&e<=pi._F?e-(pi._A-10):e>=pi._a&&e<=pi._f?e-(pi._a-10):void 0}function gi(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length,n=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,s=0;t<n;t++,s+=2){const n=fi(e.charCodeAt(s)),i=fi(e.charCodeAt(s+1));if(void 0===n||void 0===i){const t=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+s)}r[t]=16*n+i}return r}function mi(e){return di(ui(e))}function yi(e){return ci(e),di(ui(Uint8Array.from(e).reverse()))}function wi(e,t){return gi(e.toString(16).padStart(2*t,"0"))}function bi(e,t){return wi(e,t).reverse()}function vi(e,t,n){let r;if("string"==typeof t)try{r=gi(t)}catch(n){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${n}`)}else{if(!ai(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const s=r.length;if("number"==typeof n&&s!==n)throw new Error(`${e} expected ${n} bytes, got ${s}`);return r}function Ei(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];ci(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const s=e[t];n.set(s,r),r+=s.length}return n}const Si=e=>(oi<<BigInt(e-1))-ii,_i=e=>new Uint8Array(e),Ii=e=>Uint8Array.from(e);function Ri(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=_i(e),s=_i(e),i=0;const o=()=>{r.fill(1),s.fill(0),i=0},a=(...e)=>n(s,r,...e),c=(e=_i())=>{s=a(Ii([0]),e),r=a(),0!==e.length&&(s=a(Ii([1]),e),r=a())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=a();const t=r.slice();n.push(t),e+=r.length}return Ei(...n)};return(e,t)=>{let n;for(o(),c(e);!(n=t(l()));)c();return o(),n}}const Ai={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||ai(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function Ti(e,t,n={}){const r=(t,n,r)=>{const s=Ai[n];if("function"!=typeof s)throw new Error(`Invalid validator "${n}", expected function`);const i=e[t];if(!(r&&void 0===i||s(i,e)))throw new Error(`Invalid param ${String(t)}=${i} (${typeof i}), expected ${n}`)};for(const[e,n]of Object.entries(t))r(e,n,!1);for(const[e,t]of Object.entries(n))r(e,t,!0);return e}var ki=Object.freeze({__proto__:null,abytes:ci,bitGet:function(e,t){return e>>BigInt(t)&ii},bitLen:function(e){let t;for(t=0;e>si;e>>=ii,t+=1);return t},bitMask:Si,bitSet:function(e,t,n){return e|(n?ii:si)<<BigInt(t)},bytesToHex:ui,bytesToNumberBE:mi,bytesToNumberLE:yi,concatBytes:Ei,createHmacDrbg:Ri,ensureBytes:vi,equalBytes:function(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return 0===n},hexToBytes:gi,hexToNumber:di,isBytes:ai,numberToBytesBE:wi,numberToBytesLE:bi,numberToHexUnpadded:hi,numberToVarBytesBE:function(e){return gi(hi(e))},utf8ToBytes:function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))},validateObject:Ti});
|
|
9
9
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Di=BigInt(0),Pi=BigInt(1),Ci=BigInt(2),xi=BigInt(3),Ni=BigInt(4),Mi=BigInt(5),Oi=BigInt(8);function Li(e,t){const n=e%t;return n>=Di?n:t+n}function Bi(e,t,n){if(n<=Di||t<Di)throw new Error("Expected power/modulo > 0");if(n===Pi)return Di;let r=Pi;for(;t>Di;)t&Pi&&(r=r*e%n),e=e*e%n,t>>=Pi;return r}function Ui(e,t,n){let r=e;for(;t-- >Di;)r*=r,r%=n;return r}function Fi(e,t){if(e===Di||t<=Di)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Li(e,t),r=t,s=Di,i=Pi;for(;n!==Di;){const e=r%n,t=s-i*(r/n);r=n,n=e,s=i,i=t}if(r!==Pi)throw new Error("invert: does not exist");return Li(s,t)}function Vi(e){if(e%Ni===xi){const t=(e+Pi)/Ni;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%Oi===Mi){const t=(e-Mi)/Oi;return function(e,n){const r=e.mul(n,Ci),s=e.pow(r,t),i=e.mul(n,s),o=e.mul(e.mul(i,Ci),s),a=e.mul(i,e.sub(o,e.ONE));if(!e.eql(e.sqr(a),n))throw new Error("Cannot find square root");return a}}return function(e){const t=(e-Pi)/Ci;let n,r,s;for(n=e-Pi,r=0;n%Ci===Di;n/=Ci,r++);for(s=Ci;s<e&&Bi(s,t,e)!==e-Pi;s++);if(1===r){const t=(e+Pi)/Ni;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const i=(n+Pi)/Ci;return function(e,o){if(e.pow(o,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=r,c=e.pow(e.mul(e.ONE,s),n),l=e.pow(o,i),u=e.pow(o,n);for(;!e.eql(u,e.ONE);){if(e.eql(u,e.ZERO))return e.ZERO;let t=1;for(let n=e.sqr(u);t<a&&!e.eql(n,e.ONE);t++)n=e.sqr(n);const n=e.pow(c,Pi<<BigInt(a-t-1));c=e.sqr(n),l=e.mul(l,n),u=e.mul(u,c),a=t}return l}}(e)}BigInt(9),BigInt(16);const Ki=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $i(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function qi(e,t,n=!1,r={}){if(e<=Di)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:s,nByteLength:i}=$i(e,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=Vi(e),a=Object.freeze({ORDER:e,BITS:s,BYTES:i,MASK:Si(s),ZERO:Di,ONE:Pi,create:t=>Li(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return Di<=t&&t<e},is0:e=>e===Di,isOdd:e=>(e&Pi)===Pi,neg:t=>Li(-t,e),eql:(e,t)=>e===t,sqr:t=>Li(t*t,e),add:(t,n)=>Li(t+n,e),sub:(t,n)=>Li(t-n,e),mul:(t,n)=>Li(t*n,e),pow:(e,t)=>function(e,t,n){if(n<Di)throw new Error("Expected power > 0");if(n===Di)return e.ONE;if(n===Pi)return t;let r=e.ONE,s=t;for(;n>Di;)n&Pi&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Pi;return r}(a,e,t),div:(t,n)=>Li(t*Fi(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Fi(t,e),sqrt:r.sqrt||(e=>o(a,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce(((t,r,s)=>e.is0(r)?t:(n[s]=t,e.mul(t,r))),e.ONE),s=e.inv(r);return t.reduceRight(((t,r,s)=>e.is0(r)?t:(n[s]=e.mul(t,n[s]),e.mul(t,r))),s),n}(a,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?bi(e,i):wi(e,i),fromBytes:e=>{if(e.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${e.length}`);return n?yi(e):mi(e)}});return Object.freeze(a)}function Hi(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function zi(e){const t=Hi(e);return t+Math.ceil(t/2)}
|
package/dist/umd/webpeerjs.js
CHANGED
|
@@ -4,7 +4,7 @@ const e="webpeerjs",t=e,n="/"+e+"/1.0.0",r=e+"-dbstore",s=["universal-connectivi
|
|
|
4
4
|
//! WebPEER.js -- https://github.com/nuzulul/webpeerjs
|
|
5
5
|
var Gt;function Yt(e,t="utf8"){const n=Tt[t];if(null==n)throw new Error(`Unsupported encoding "${t}"`);return n.encoder.encode(e).substring(1)}!function(e){let t;e.codec=()=>(null==t&&(t=Wt(((e,t,n={})=>{if(!1!==n.lengthDelimited&&t.fork(),null!=e.publicKey&&e.publicKey.byteLength>0&&(t.uint32(10),t.bytes(e.publicKey)),null!=e.addrs)for(const n of e.addrs)t.uint32(18),t.bytes(n);!1!==n.lengthDelimited&&t.ldelim()}),((e,t)=>{const n={publicKey:m(0),addrs:[]},r=null==t?e.len:e.pos+t;for(;e.pos<r;){const t=e.uint32();switch(t>>>3){case 1:n.publicKey=e.bytes();break;case 2:n.addrs.push(e.bytes());break;default:e.skipType(7&t)}}return n}))),t),e.encode=t=>$t(t,e.codec()),e.decode=t=>j(t,e.codec())}(Gt||(Gt={}));const Qt="/",Jt=(new TextEncoder).encode(Qt),Zt=Jt[0];class Xt{_buf;constructor(e,t){if("string"==typeof e)this._buf=kt(e);else{if(!(e instanceof Uint8Array))throw new Error("Invalid key, should be String of Uint8Array");this._buf=e}if(null==t&&(t=!0),t&&this.clean(),0===this._buf.byteLength||this._buf[0]!==Zt)throw new Error("Invalid key")}toString(e="utf8"){return Yt(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new Xt(e.join(Qt))}static random(){return new Xt(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||"string"==typeof e?new Xt(e):"function"==typeof e.uint8Array?new Xt(e.uint8Array()):null}clean(){if(null!=this._buf&&0!==this._buf.byteLength||(this._buf=Jt),this._buf[0]!==Zt){const e=new Uint8Array(this._buf.byteLength+1);e.fill(Zt,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Zt;)this._buf=this._buf.subarray(0,-1)}less(e){const t=this.list(),n=e.list();for(let e=0;e<t.length;e++){if(n.length<e+1)return!1;const r=t[e],s=n[e];if(r<s)return!0;if(r>s)return!1}return t.length<n.length}reverse(){return Xt.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){const e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Qt).slice(1)}type(){return function(e){const t=e.split(":");if(t.length<2)return"";return t.slice(0,-1).join(":")}(this.baseNamespace())}name(){return function(e){const t=e.split(":");return t[t.length-1]}(this.baseNamespace())}instance(e){return new Xt(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Qt)||(e+=Qt),e+=this.type(),new Xt(e)}parent(){const e=this.list();return 1===e.length?new Xt(Qt):new Xt(e.slice(0,-1).join(Qt))}child(e){return this.toString()===Qt?e:e.toString()===Qt?this:new Xt(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()!==this.toString()&&e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()!==this.toString()&&this.toString().startsWith(e.toString())}isTopLevel(){return 1===this.list().length}concat(...e){return Xt.withNamespaces([...this.namespaces(),...(t=e.map((e=>e.namespaces())),[].concat(...t))]);var t}}const en=Symbol.for("@libp2p/connection"),tn=Symbol.for("@libp2p/content-routing"),nn=Symbol.for("@libp2p/peer-discovery"),rn=Symbol.for("@libp2p/peer-id");function sn(e){return null!=e&&Boolean(e[rn])}const on=Symbol.for("@libp2p/peer-routing"),an="StrictSign",cn="StrictNoSign";var ln;!function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"}(ln||(ln={}));const un=Symbol.for("@libp2p/transport");var hn;!function(e){e[e.FATAL_ALL=0]="FATAL_ALL",e[e.NO_FATAL=1]="NO_FATAL"}(hn||(hn={}));let dn=class e extends Error{code;type;constructor(t="The operation was aborted"){super(t),this.name="AbortError",this.code=e.code,this.type=e.type}static code="ABORT_ERR";static type="aborted"},pn=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};class fn extends AggregateError{code;props;constructor(e,t,n,r){super(e,t),this.code=n,this.name=r?.name??"AggregateCodeError",this.props=r??{}}}const gn="ERR_TIMEOUT",mn="ERR_INVALID_MESSAGE";class yn extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){const t=this.#e.get(e);return null==t?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let r=this.#e.get(e);null==r&&(r=[],this.#e.set(e,r)),r.push({callback:t,once:(!0!==n&&!1!==n&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let r=this.#e.get(e);null!=r&&(r=r.filter((({callback:e})=>e!==t)),this.#e.set(e,r))}dispatchEvent(e){const t=super.dispatchEvent(e);let n=this.#e.get(e.type);return null==n||(n=n.filter((({once:e})=>!e)),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new bn(e,t))}}class wn extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}}const bn=globalThis.CustomEvent??wn;function vn(e){return null!=e&&"function"==typeof e.start&&"function"==typeof e.stop}const En=Symbol.for("@libp2p/service-capabilities"),Sn=Symbol.for("@libp2p/service-dependencies");function _n(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}function In(e,t){null==t&&(t=e.reduce(((e,t)=>e+t.length),0));const n=y(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}const Rn=45,An=15,Tn=new class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){const t=this.index,n=e();return void 0===n&&(this.index=t),n}parseWith(e){const t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically((()=>{const t=this.readChar();if(t===e)return t}))}readSeparator(e,t,n){return this.readAtomically((()=>{if(!(t>0&&void 0===this.readGivenChar(e)))return n()}))}readNumber(e,t,n,r){return this.readAtomically((()=>{let s=0,i=0;const o=this.peekChar();if(void 0===o)return;const a="0"===o,c=2**(8*r)-1;for(;;){const n=this.readAtomically((()=>{const t=this.readChar();if(void 0===t)return;const n=Number.parseInt(t,e);return Number.isNaN(n)?void 0:n}));if(void 0===n)break;if(s*=e,s+=n,s>c)return;if(i+=1,void 0!==t&&i>t)return}return 0===i||!n&&a&&i>1?void 0:s}))}readIPv4Addr(){return this.readAtomically((()=>{const e=new Uint8Array(4);for(let t=0;t<e.length;t++){const n=this.readSeparator(".",t,(()=>this.readNumber(10,3,!1,1)));if(void 0===n)return;e[t]=n}return e}))}readIPv6Addr(){const e=e=>{for(let t=0;t<e.length/2;t++){const n=2*t;if(t<e.length-3){const r=this.readSeparator(":",t,(()=>this.readIPv4Addr()));if(void 0!==r)return e[n]=r[0],e[n+1]=r[1],e[n+2]=r[2],e[n+3]=r[3],[n+4,!0]}const r=this.readSeparator(":",t,(()=>this.readNumber(16,4,!0,2)));if(void 0===r)return[n,!1];e[n]=r>>8,e[n+1]=255&r}return[e.length,!1]};return this.readAtomically((()=>{const t=new Uint8Array(16),[n,r]=e(t);if(16===n)return t;if(r)return;if(void 0===this.readGivenChar(":"))return;if(void 0===this.readGivenChar(":"))return;const s=new Uint8Array(14),i=16-(n+2),[o]=e(s.subarray(0,i));return t.set(s.subarray(0,o),16-o),t}))}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};function kn(e){return Boolean(function(e){if(!(e.length>An))return Tn.new(e).parseWith((()=>Tn.readIPv4Addr()))}(e))}function Dn(e){return Boolean(function(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Rn))return Tn.new(e).parseWith((()=>Tn.readIPv6Addr()))}(e))}function Pn(e){return Boolean(function(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Rn))return Tn.new(e).parseWith((()=>Tn.readIPAddr()))}(e))}const Cn=kn,xn=Dn,Nn=function(e){let t=0;if(e=e.toString().trim(),Cn(e)){const n=new Uint8Array(t+4);return e.split(/\./g).forEach((e=>{n[t++]=255&parseInt(e,10)})),n}if(xn(e)){const n=e.split(":",8);let r;for(r=0;r<n.length;r++){let e;Cn(n[r])&&(e=Nn(n[r]),n[r]=Yt(e.slice(0,2),"base16")),null!=e&&++r<8&&n.splice(r,0,Yt(e.slice(2,4),"base16"))}if(""===n[0])for(;n.length<8;)n.unshift("0");else if(""===n[n.length-1])for(;n.length<8;)n.push("0");else if(n.length<8){for(r=0;r<n.length&&""!==n[r];r++);const e=[r,1];for(r=9-n.length;r>0;r--)e.push("0");n.splice.apply(n,e)}const s=new Uint8Array(t+16);for(r=0;r<n.length;r++){const e=parseInt(n[r],16);s[t++]=e>>8&255,s[t++]=255&e}return s}throw new Error("invalid ip address")},Mn=function(e,t=0,n){t=~~t,n=n??e.length-t;const r=new DataView(e.buffer);if(4===n){const r=[];for(let s=0;s<n;s++)r.push(e[t+s]);return r.join(".")}if(16===n){const e=[];for(let s=0;s<n;s+=2)e.push(r.getUint16(t+s).toString(16));return e.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""},On=-1,Ln={},Bn={};function Un(e){if("number"==typeof e){if(null!=Bn[e])return Bn[e];throw new Error(`no protocol with code: ${e}`)}if("string"==typeof e){if(null!=Ln[e])return Ln[e];throw new Error(`no protocol with name: ${e}`)}throw new Error("invalid protocol id type: "+typeof e)}function Fn(e,t){switch(Un(e).code){case 4:case 41:return function(e){const t=Mn(e,0,e.length);if(null==t)throw new Error("ipBuff is required");if(!Pn(t))throw new Error("invalid ip address");return t}(t);case 42:case 53:case 54:case 55:case 56:case 400:case 449:case 777:return jn(t);case 6:case 273:case 33:case 132:return zn(t).toString();case 421:return function(e){const t=C(e),n=e.slice(T(t));if(n.length!==t)throw new Error("inconsistent lengths");return Yt(n,"base58btc")}(t);case 444:case 445:return Gn(t);case 466:return function(e){const t=C(e),n=e.slice(T(t));if(n.length!==t)throw new Error("inconsistent lengths");return"u"+Yt(n,"base64url")}(t);case 481:return globalThis.encodeURIComponent(jn(t));default:return Yt(t,"base16")}}function Vn(e,t){switch(Un(e).code){case 4:case 41:return qn(t);case 42:case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Wn(t);case 6:case 273:case 33:case 132:return Hn(parseInt(t,10));case 421:return function(e){let t;t="Q"===e[0]||"1"===e[0]?lt(Pe.decode(`z${e}`)).bytes:wt.parse(e).multihash.bytes;const n=Uint8Array.from(P(t.length));return In([n,t],n.length+t.length)}(t);case 444:return function(e){const t=e.split(":");if(2!==t.length)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(16!==t[0].length)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);const n=ye.decode("b"+t[0]),r=parseInt(t[1],10);if(r<1||r>65536)throw new Error("Port number is not in range(1, 65536)");const s=Hn(r);return In([n,s],n.length+s.length)}(t);case 445:return function(e){const t=e.split(":");if(2!==t.length)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(56!==t[0].length)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);const n=ye.decode(`b${t[0]}`),r=parseInt(t[1],10);if(r<1||r>65536)throw new Error("Port number is not in range(1, 65536)");const s=Hn(r);return In([n,s],n.length+s.length)}(t);case 466:return function(e){const t=$n.decode(e),n=Uint8Array.from(P(t.length));return In([n,t],n.length+t.length)}(t);case 481:return Wn(globalThis.decodeURIComponent(t));default:return kt(t,"base16")}}[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,On,"ip6zone"],[43,8,"ipcidr"],[53,On,"dns",!0],[54,On,"dns4",!0],[55,On,"dns6",!0],[56,On,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,On,"unix",!1,!0],[421,On,"ipfs"],[421,On,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,On,"garlic64"],[448,0,"tls"],[449,On,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,On,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,On,"http-path"],[777,On,"memory"]].forEach((e=>{const t=function(e,t,n,r,s){return{code:e,size:t,name:n,resolvable:Boolean(r),path:Boolean(s)}}(...e);Bn[t.code]=t,Ln[t.name]=t})),Un("ip4"),Un("ip6"),Un("ipcidr");const Kn=Object.values(_t).map((e=>e.decoder)),$n=function(){let e=Kn[0].or(Kn[1]);return Kn.slice(2).forEach((t=>e=e.or(t))),e}();function qn(e){if(!Pn(e))throw new Error("invalid ip address");return Nn(e)}function Hn(e){const t=new ArrayBuffer(2);return new DataView(t).setUint16(0,e),new Uint8Array(t)}function zn(e){return new DataView(e.buffer).getUint16(e.byteOffset)}function Wn(e){const t=kt(e),n=Uint8Array.from(P(t.length));return In([n,t],n.length+t.length)}function jn(e){const t=C(e);if((e=e.slice(T(t))).length!==t)throw new Error("inconsistent lengths");return Yt(e)}function Gn(e){const t=e.slice(0,e.length-2),n=e.slice(e.length-2);return`${Yt(t,"base32")}:${zn(n)}`}function Yn(e){const t=[],n=[];let r=null,s=0;for(;s<e.length;){const i=C(e,s),o=T(i),a=Un(i),c=Zn(a,e.slice(s+o));if(0===c){t.push([i]),n.push([i]),s+=o;continue}const l=e.slice(s+o,s+o+c);if(s+=c+o,s>e.length)throw er("Invalid address Uint8Array: "+Yt(e,"base16"));t.push([i,l]);const u=Fn(i,l);if(n.push([i,u]),!0===a.path){r=u;break}}return{bytes:Uint8Array.from(e),string:Qn(n),tuples:t,stringTuples:n,path:r}}function Qn(e){const t=[];return e.map((e=>{const n=Un(e[0]);return t.push(n.name),e.length>1&&null!=e[1]&&t.push(e[1]),null})),Xn(t.join("/"))}function Jn(e){return In(e.map((e=>{const t=Un(e[0]);let n=Uint8Array.from(P(t.code));return e.length>1&&null!=e[1]&&(n=In([n,e[1]])),n})))}function Zn(e,t){if(e.size>0)return e.size/8;if(0===e.size)return 0;{const e=C(t instanceof Uint8Array?t:Uint8Array.from(t));return e+T(e)}}function Xn(e){return"/"+e.trim().split("/").filter((e=>e)).join("/")}function er(e){return new Error("Error parsing address: "+e)}const tr=Symbol.for("nodejs.util.inspect.custom"),nr=Symbol.for("@multiformats/js-multiaddr/multiaddr"),rr=[Un("dns").code,Un("dns4").code,Un("dns6").code,Un("dnsaddr").code];class sr{bytes;#t;#n;#r;#s;[nr]=!0;constructor(e){let t;if(null==e&&(e=""),e instanceof Uint8Array)t=Yn(e);else if("string"==typeof e){if(e.length>0&&"/"!==e.charAt(0))throw new Error(`multiaddr "${e}" must start with a "/"`);t=function(e){const t=[],n=[];let r=null;const s=(e=Xn(e)).split("/").slice(1);if(1===s.length&&""===s[0])return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<s.length;i++){const o=Un(s[i]);if(0===o.size){t.push([o.code]),n.push([o.code]);continue}if(i++,i>=s.length)throw er("invalid address: "+e);if(!0===o.path){r=Xn(s.slice(i).join("/")),t.push([o.code,Vn(o.code,r)]),n.push([o.code,r]);break}const a=Vn(o.code,s[i]);t.push([o.code,a]),n.push([o.code,Fn(o.code,a)])}return{string:Qn(n),bytes:Jn(t),tuples:t,stringTuples:n,path:r}}(e)}else{if(!or(e))throw new Error("addr must be a string, Buffer, or another Multiaddr");t=Yn(e.bytes)}this.bytes=t.bytes,this.#t=t.string,this.#n=t.tuples,this.#r=t.stringTuples,this.#s=t.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,r,s="";const i=Un("tcp"),o=Un("udp"),a=Un("ip4"),c=Un("ip6"),l=Un("dns6"),u=Un("ip6zone");for(const[h,d]of this.stringTuples())h===u.code&&(s=`%${d??""}`),rr.includes(h)&&(t=i.name,r=443,n=`${d??""}${s}`,e=h===l.code?6:4),h!==i.code&&h!==o.code||(t=Un(h).name,r=parseInt(d??"")),h!==a.code&&h!==c.code||(t=Un(h).name,n=`${d??""}${s}`,e=h===c.code?6:4);if(null==e||null==t||null==n||null==r)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:r}}protos(){return this.#n.map((([e])=>Object.assign({},Un(e))))}protoCodes(){return this.#n.map((([e])=>e))}protoNames(){return this.#n.map((([e])=>Un(e).name))}tuples(){return this.#n}stringTuples(){return this.#r}encapsulate(e){return e=new sr(e),new sr(this.toString()+e.toString())}decapsulate(e){const t=e.toString(),n=this.toString(),r=n.lastIndexOf(t);if(r<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new sr(n.slice(0,r))}decapsulateCode(e){const t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new sr(Jn(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach((([t,n])=>{t===Ln.p2p.code&&e.push([t,n]),t===Ln["p2p-circuit"].code&&(e=[])}));const t=e.pop();if(null!=t?.[1]){const e=t[1];return"Q"===e[0]||"1"===e[0]?Yt(Pe.decode(`z${e}`),"base58btc"):Yt(wt.parse(e).multihash.bytes,"base58btc")}return null}catch(e){return null}}getPath(){return this.#s}equals(e){return _n(this.bytes,e.bytes)}async resolve(e){const t=this.protos().find((e=>e.resolvable));if(null==t)return[this];const n=ir.get(t.name);if(null==n)throw new pn(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map((e=>ar(e)))}nodeAddress(){const e=this.toOptions();if("tcp"!==e.transport&&"udp"!==e.transport)throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){const t=(e??this).protos();return 2===t.length&&((4===t[0].code||41===t[0].code)&&(6===t[1].code||273===t[1].code))}[tr](){return`Multiaddr(${this.#t})`}}const ir=new Map;function or(e){return Boolean(e?.[nr])}function ar(e){return new sr(e)}function cr(){const e={};return e.promise=new Promise(((t,n)=>{e.resolve=t,e.reject=n})),e}class lr{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return void 0===this.buffer[this.top]&&(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){const e=this.buffer[this.btm];if(void 0!==e)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return void 0===this.buffer[this.btm]}}class ur{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new lr(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return null!=e?.byteLength?e.byteLength:1}push(e){if(null!=e?.value&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){const t=this.head;this.head=t.next=new lr(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(void 0===e&&null!=this.tail.next){const t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return null!=e?.value&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}}let hr=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function dr(e={}){return function(e,t){t=t??{};let n,r,s,i=t.onEnd,o=new ur,a=cr();const c=async()=>{try{return o.isEmpty()?s?{done:!0}:await new Promise(((t,s)=>{r=i=>{r=null,o.push(i);try{t(e(o))}catch(e){s(e)}return n}})):e(o)}finally{o.isEmpty()&&queueMicrotask((()=>{a.resolve(),a=cr()}))}},l=e=>null!=r?r(e):(o.push(e),n),u=e=>(o=new ur,null!=r?r({error:e}):(o.push({error:e}),n)),h=e=>{if(s)return n;if(!0!==t?.objectMode&&null==e?.byteLength)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:e})},d=e=>s?n:(s=!0,null!=e?u(e):l({done:!0})),p=()=>(o=new ur,d(),{done:!0}),f=e=>(d(e),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:c,return:p,throw:f,push:h,end:d,get readableLength(){return o.size},onEmpty:async e=>{const t=e?.signal;if(t?.throwIfAborted(),o.isEmpty())return;let n,r;null!=t&&(n=new Promise(((e,n)=>{r=()=>{n(new hr)},t.addEventListener("abort",r)})));try{await Promise.race([a.promise,n])}finally{null!=r&&null!=t&&t?.removeEventListener("abort",r)}}},null==i)return n;const g=n;return n={[Symbol.asyncIterator](){return this},next:()=>g.next(),throw:e=>(g.throw(e),null!=i&&(i(e),i=void 0),{done:!0}),return:()=>(g.return(),null!=i&&(i(),i=void 0),{done:!0}),push:h,end:e=>(g.end(e),null!=i&&(i(e),i=void 0),n),get readableLength(){return g.readableLength},onEmpty:e=>g.onEmpty(e)},n}((e=>{const t=e.shift();if(null==t)return{done:!0};if(null!=t.error)throw t.error;return{done:!0===t.done,value:t.value}}),e)}function pr(...e){const t=[];for(const n of e)null==n[Symbol.asyncIterator]&&t.push(n);return t.length===e.length?function*(){for(const e of t)yield*e}():async function*(){const t=dr({objectMode:!0});Promise.resolve().then((async()=>{try{await Promise.all(e.map((async e=>{for await(const n of e)t.push(n)}))),t.end()}catch(e){t.end(e)}})),yield*t}()}function fr(e,...t){if(null==e)throw new Error("Empty pipeline");if(wr(e)){const t=e;e=()=>t.source}else if(yr(e)||mr(e)){const t=e;e=()=>t}const n=[e,...t];if(n.length>1&&wr(n[n.length-1])&&(n[n.length-1]=n[n.length-1].sink),n.length>2)for(let e=1;e<n.length-1;e++)wr(n[e])&&(n[e]=br(n[e]));return gr(...n)}const gr=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},mr=e=>null!=e?.[Symbol.asyncIterator],yr=e=>null!=e?.[Symbol.iterator],wr=e=>null!=e&&(null!=e.sink&&null!=e.source),br=e=>t=>{const n=e.sink(t);if(null!=n?.then){const t=dr({objectMode:!0});let r;n.then((()=>{t.end()}),(e=>{t.end(e)}));const s=e.source;if(mr(s))r=async function*(){yield*s,t.end()};else{if(!yr(s))throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");r=function*(){yield*s,t.end()}}return pr(t,r())}return e.source},vr=Symbol.for("@achingbrain/uint8arraylist");function Er(e,t){if(null==t||t<0)throw new RangeError("index is out of bounds");let n=0;for(const r of e){const e=n+r.byteLength;if(t<e)return{buf:r,index:t-n};n=e}throw new RangeError("index is out of bounds")}function Sr(e){return Boolean(e?.[vr])}class _r{bufs;length;[vr]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(const n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else{if(!Sr(n))throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");t+=n.byteLength,this.bufs.push(...n.bufs)}this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(const n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else{if(!Sr(n))throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");t+=n.byteLength,this.bufs.unshift(...n.bufs)}this.length+=t}get(e){const t=Er(this.bufs,e);return t.buf[t.index]}set(e,t){const n=Er(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else{if(!Sr(e))throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList");for(let n=0;n<e.length;n++)this.set(t+n,e.get(n))}}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength)return this.bufs=[],void(this.length=0);for(;this.bufs.length>0;){if(!(e>=this.bufs[0].byteLength)){this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift()}}}slice(e,t){const{bufs:n,length:r}=this._subList(e,t);return In(n,r)}subarray(e,t){const{bufs:n,length:r}=this._subList(e,t);return 1===n.length?n[0]:In(n,r)}sublist(e,t){const{bufs:n,length:r}=this._subList(e,t),s=new _r;return s.length=r,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(0===e&&t===this.length)return{bufs:this.bufs,length:this.length};const n=[];let r=0;for(let s=0;s<this.bufs.length;s++){const i=this.bufs[s],o=r,a=o+i.byteLength;if(r=a,e>=a)continue;const c=e>=o&&e<a,l=t>o&&t<=a;if(c&&l){if(e===o&&t===a){n.push(i);break}const r=e-o;n.push(i.subarray(r,r+(t-e)));break}if(c){if(0===e){n.push(i);continue}n.push(i.subarray(e-o))}else{if(l){if(t===a){n.push(i);break}n.push(i.subarray(0,t-o));break}n.push(i)}}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!(Sr(e)||e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');const n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),0===e.length)return t>this.length?this.length:t;const r=n.byteLength;if(0===r)throw new TypeError("search must be at least 1 byte long");const s=new Int32Array(256);for(let e=0;e<256;e++)s[e]=-1;for(let e=0;e<r;e++)s[n[e]]=e;const i=s,o=this.byteLength-n.byteLength,a=n.byteLength-1;let c;for(let e=t;e<=o;e+=c){c=0;for(let t=a;t>=0;t--){const r=this.get(e+t);if(n[t]!==r){c=Math.max(1,t-i[r]);break}}if(0===c)return e}return-1}getInt8(e){const t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){const n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){const n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){const r=m(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt16(0,t,n),this.write(r,e)}getInt32(e,t){const n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){const r=m(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt32(0,t,n),this.write(r,e)}getBigInt64(e,t){const n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){const r=m(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigInt64(0,t,n),this.write(r,e)}getUint8(e){const t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){const n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){const n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){const r=m(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint16(0,t,n),this.write(r,e)}getUint32(e,t){const n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){const r=m(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint32(0,t,n),this.write(r,e)}getBigUint64(e,t){const n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){const r=m(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigUint64(0,t,n),this.write(r,e)}getFloat32(e,t){const n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){const r=m(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat32(0,t,n),this.write(r,e)}getFloat64(e,t){const n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){const r=m(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat64(0,t,n),this.write(r,e)}equals(e){if(null==e)return!1;if(!(e instanceof _r))return!1;if(e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!_n(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){const n=new _r;return n.bufs=e,null==t&&(t=e.reduce(((e,t)=>e+t.byteLength),0)),n.length=t,n}}let Ir=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Rr(e,t,n){if(null==t)return e;if(t.aborted)return Promise.reject(new Ir(n?.errorMessage,n?.errorCode));let r;const s=new Ir(n?.errorMessage,n?.errorCode);try{return await Promise.race([e,new Promise(((e,n)=>{r=()=>{n(s)},t.addEventListener("abort",r)}))])}finally{null!=r&&t.removeEventListener("abort",r)}}class Ar{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=cr(),this.haveNext=cr()}[Symbol.asyncIterator](){return this}async next(){if(null==this.nextResult&&await this.haveNext.promise,null==this.nextResult)throw new Error("HaveNext promise resolved but nextResult was undefined");const e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=cr(),e}async throw(e){this.ended=!0,null!=e&&this.haveNext.reject(e);return{done:!0,value:void 0}}async return(){const e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,t){await this._push(e,t)}async end(e,t){null!=e?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(null!=e&&this.ended)throw new Error("Cannot push value onto an ended pushable");if(null!=this.nextResult&&(await this.readNext.promise,null!=this.nextResult))throw new Error("NeedNext promise resolved but nextResult was not consumed");null!=e?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=cr(),await Rr(this.readNext.promise,t?.signal,t)}}let Tr=class extends Error{code;constructor(e,t){super(e),this.code=t}},kr=class extends Tr{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function Dr(e,t){const n=new Ar;e.sink(n).catch((async e=>{await n.end(e)})),e.sink=async e=>{for await(const t of e)await n.push(t);await n.end()};let r=e.source;null!=e.source[Symbol.iterator]?r=e.source[Symbol.iterator]():null!=e.source[Symbol.asyncIterator]&&(r=e.source[Symbol.asyncIterator]());const s=new _r,i={read:async(e,t)=>{let n;t?.signal?.throwIfAborted();const i=new Promise(((e,r)=>{n=()=>{r(new kr("Read aborted"))},t?.signal?.addEventListener("abort",n)}));try{if(null==e){const{done:e,value:t}=await Promise.race([r.next(),i]);return!0===e?new _r:t}for(;s.byteLength<e;){const{value:e,done:t}=await Promise.race([r.next(),i]);if(!0===t)throw new Tr("unexpected end of input","ERR_UNEXPECTED_EOF");s.append(e)}const t=s.sublist(0,e);return s.consume(e),t}finally{null!=n&&t?.signal?.removeEventListener("abort",n)}},write:async(e,t)=>{t?.signal?.throwIfAborted(),e instanceof Uint8Array?await n.push(e,t):await n.push(e.subarray(),t)},unwrap:()=>{if(s.byteLength>0){const n=e.source;e.source=async function*(){!1===t?.yieldBytes?yield s:yield*s,yield*n}()}return e}};return i}class Pr extends Error{code;constructor(e,t){super(e),this.code=t}}function Cr(e,t={}){const n=Dr(e,t);null!=t.maxDataLength&&null==t.maxLengthLength&&(t.maxLengthLength=T(t.maxDataLength));const r=t?.lengthDecoder??C,s=t?.lengthEncoder??P;return{read:async e=>{let s=-1;const i=new _r;for(;;){i.append(await n.read(1,e));try{s=r(i)}catch(e){if(e instanceof RangeError)continue;throw e}if(null!=t?.maxLengthLength&&i.byteLength>t.maxLengthLength)throw new Pr("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(s>-1)break}if(null!=t?.maxDataLength&&s>t.maxDataLength)throw new Pr("message length too long","ERR_MSG_DATA_TOO_LONG");return n.read(s,e)},write:async(e,t)=>{await n.write(new _r(s(e.byteLength),e),t)},writeV:async(e,t)=>{const r=new _r(...e.flatMap((e=>[s(e.byteLength),e])));await n.write(r,t)},unwrap:()=>n.unwrap()}}function xr(e){return null!=e[Symbol.asyncIterator]}const Nr=e=>{const t=T(e),n=y(t);return P(e,n),Nr.bytes=t,n};function Mr(e,t){const n=(t=t??{}).lengthEncoder??Nr;function*r(e){const t=n(e.byteLength);t instanceof Uint8Array?yield t:yield*t,e instanceof Uint8Array?yield e:yield*e}return xr(e)?async function*(){for await(const t of e)yield*r(t)}():function*(){for(const t of e)yield*r(t)}()}Nr.bytes=0,Mr.single=(e,t)=>{const n=(t=t??{}).lengthEncoder??Nr;return new _r(n(e.byteLength),e)};var Or="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Lr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Br(e,t){for(const n in t)Object.defineProperty(e,n,{value:t[n],enumerable:!0,configurable:!0});return e}var Ur=function(e,t,n){if(!e||"string"==typeof e)throw new TypeError("Please pass an Error to err-code");n||(n={}),"object"==typeof t&&(n=t,t=""),t&&(n.code=t);try{return Br(e,n)}catch(t){n.message=e.message,n.stack=e.stack;const r=function(){};r.prototype=Object.create(Object.getPrototypeOf(e));return Br(new r,n)}},Fr=Lr(Ur);var Vr;!function(e){e[e.LENGTH=0]="LENGTH",e[e.DATA=1]="DATA"}(Vr||(Vr={}));const Kr=e=>{const t=C(e);return Kr.bytes=T(t),t};function $r(e,t){const n=new _r;let r=Vr.LENGTH,s=-1;const i=t?.lengthDecoder??Kr,o=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;n.byteLength>0;){if(r===Vr.LENGTH)try{if(s=i(n),s<0)throw Fr(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw Fr(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");const e=i.bytes;n.consume(e),null!=t?.onLength&&t.onLength(s),r=Vr.DATA}catch(e){if(e instanceof RangeError){if(n.byteLength>o)throw Fr(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw e}if(r===Vr.DATA){if(n.byteLength<s)break;const e=n.sublist(0,s);n.consume(s),null!=t?.onData&&t.onData(e),yield e,r=Vr.LENGTH}}}return xr(e)?async function*(){for await(const t of e)n.append(t),yield*c();if(n.byteLength>0)throw Fr(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(const t of e)n.append(t),yield*c();if(n.byteLength>0)throw Fr(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}function qr(e){const[t,n]=null!=e[Symbol.asyncIterator]?[e[Symbol.asyncIterator](),Symbol.asyncIterator]:[e[Symbol.iterator](),Symbol.iterator],r=[];return{peek:()=>t.next(),push:e=>{r.push(e)},next:()=>r.length>0?{done:!1,value:r.shift()}:t.next(),[n](){return this}}}function Hr(e,t){let n=0;if(null!=e[Symbol.asyncIterator])return async function*(){for await(const r of e)yield t(r,n++)}();const r=qr(e),{value:s,done:i}=r.next();if(!0===i)return function*(){}();const o=t(s,n++);if("function"==typeof o.then)return async function*(){yield await o;for await(const e of r)yield t(e,n++)}();const a=t;return function*(){yield o;for(const e of r)yield a(e,n++)}()}
|
|
6
6
|
//! WebPEER.js -- https://github.com/nuzulul/webpeerjs
|
|
7
|
-
Kr.bytes=0,$r.fromReader=(e,t)=>{let n=1;return $r(async function*(){for(;;)try{const{done:t,value:r}=await e.next(n);if(!0===t)return;null!=r&&(yield r)}catch(e){if("ERR_UNDER_READ"===e.code)return{done:!0,value:null};throw e}finally{n=1}}(),{...t??{},onLength:e=>{n=e}})};const zr=t,Wr=e=>new Error(`${zr}: ${e}`);function jr(e){return(new TextDecoder).decode(e)}function Gr(e){return(new TextEncoder).encode(e)}async function Yr(e){for await(const t of e)return t}window.opr&&window.opr.addons||window.opera||navigator.userAgent.indexOf(" OPR/");const Qr="undefined"!=typeof InstallTrigger;/constructor/i.test(window.HTMLElement)||(!window.safari||"undefined"!=typeof safari&&window.safari.pushNotification).toString();async function Jr(e){const t=e,n=(new TextEncoder).encode(t.sequenceNumber.toString());return await ft.encode(n)}!(!window.chrome||!window.chrome.webstore&&!window.chrome.runtime)&&navigator.userAgent.indexOf("Edg");let Zr={readyErrored:0,noiseErrored:0,upgradeErrored:0,readyTimedout:0,noiseTimedout:0,success:0},Xr={pending:0,open:0,ready_error:0,noise_error:0,upgrade_error:0,ready_timeout:0,noise_timeout:0,close:0,abort:0,remote_close:0},es={pending:0,ready_error:0,noise_error:0,upgrade_error:0,close:0,remote_close:0,ready:0,abort:0,ready_timeout:0,noise_timeout:0,open:0},ts=0,ns=0,rs=!0,ss=0,is=!0,os=0;if(!WebTransport)throw Wr("It seems that your browser does not support the required WebTransport feature");var as,cs,ls={exports:{}};function us(){if(cs)return as;cs=1;var e=1e3,t=60*e,n=60*t,r=24*n,s=7*r,i=365.25*r;function o(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"s":"")}return as=function(a,c){c=c||{};var l=typeof a;if("string"===l&&a.length>0)return function(o){if((o=String(o)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(o);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*i;case"weeks":case"week":case"w":return c*s;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===l&&isFinite(a))return c.long?function(s){var i=Math.abs(s);if(i>=r)return o(s,i,r,"day");if(i>=n)return o(s,i,n,"hour");if(i>=t)return o(s,i,t,"minute");if(i>=e)return o(s,i,e,"second");return s+" ms"}(a):function(s){var i=Math.abs(s);if(i>=r)return Math.round(s/r)+"d";if(i>=n)return Math.round(s/n)+"h";if(i>=t)return Math.round(s/t)+"m";if(i>=e)return Math.round(s/e)+"s";return s+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}var hs=function(e){function t(e){let r,s,i,o=null;function a(...e){if(!a.enabled)return;const n=a,s=Number(new Date),i=s-(r||s);n.diff=i,n.prev=r,n.curr=s,r=s,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let o=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((r,s)=>{if("%%"===r)return"%";o++;const i=t.formatters[s];if("function"==typeof i){const t=e[o];r=i.call(n,t),e.splice(o,1),o--}return r})),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=n,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==o?o:(s!==t.namespaces&&(s=t.namespaces,i=t.enabled(e)),i),set:e=>{o=e}}),"function"==typeof t.init&&t.init(a),a}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(r),...t.skips.map(r).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(n=0;n<s;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=us(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t};!function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,s=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))})),t.splice(s,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=hs(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(ls,ls.exports);var ds=Lr(ls.exports);function ps(){return{forComponent:e=>fs(e)}}function fs(e){let t=function(e){const t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}(`${e}:trace`);return ds.enabled(`${e}:trace`)&&null!=ds.names.map((e=>e.toString())).find((e=>e.includes(":trace")))&&(t=ds(`${e}:trace`)),Object.assign(ds(e),{error:ds(`${e}:error`),trace:t})}ds.formatters.b=e=>null==e?"undefined":Pe.baseEncode(e),ds.formatters.t=e=>null==e?"undefined":ye.baseEncode(e),ds.formatters.m=e=>null==e?"undefined":Ne.baseEncode(e),ds.formatters.p=e=>null==e?"undefined":e.toString(),ds.formatters.c=e=>null==e?"undefined":e.toString(),ds.formatters.k=e=>null==e?"undefined":e.toString(),ds.formatters.a=e=>null==e?"undefined":e.toString();const gs=Symbol.for("nodejs.util.inspect.custom"),ms=Object.values(_t).map((e=>e.decoder)).reduce(((e,t)=>e.or(t)),_t.identity.decoder),ys=114,ws=36,bs=37;class vs{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[rn]=!0;toString(){return null==this.string&&(this.string=Pe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return wt.createV1(ys,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(null==e)return!1;if(e instanceof Uint8Array)return _n(this.multihash.bytes,e);if("string"==typeof e)return Is(e).equals(this);if(null!=e?.multihash?.bytes)return _n(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[gs](){return`PeerId(${this.toString()})`}}class Es extends vs{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}}class Ss extends vs{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}}class _s extends vs{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}}function Is(e,t){if(t=t??ms,"1"===e.charAt(0)||"Q"===e.charAt(0)){const t=lt(Pe.decode(`z${e}`));return e.startsWith("12D")?new Ss({multihash:t}):e.startsWith("16U")?new _s({multihash:t}):new Es({multihash:t})}return Rs(ms.decode(e))}function Rs(e){try{const t=lt(e);if(t.code===dt.code){if(t.digest.length===ws)return new Ss({multihash:t});if(t.digest.length===bs)return new _s({multihash:t})}if(t.code===ft.code)return new Es({multihash:t})}catch{return function(e){if(null==e||null==e.multihash||null==e.version||1===e.version&&e.code!==ys)throw new Error("Supplied PeerID CID is invalid");const t=e.multihash;if(t.code===ft.code)return new Es({multihash:e.multihash});if(t.code===dt.code){if(t.digest.length===ws)return new Ss({multihash:e.multihash});if(t.digest.length===bs)return new _s({multihash:e.multihash})}throw new Error("Supplied PeerID CID is invalid")}(wt.decode(e))}throw new Error("Supplied PeerID CID is invalid")}async function As(e,t){return e.length===ws?new Ss({multihash:ct(dt.code,e),privateKey:t}):e.length===bs?new _s({multihash:ct(dt.code,e),privateKey:t}):new Es({multihash:await ft.digest(e),publicKey:e,privateKey:t})}function Ts(e){const t=new globalThis.AbortController;function n(){t.abort();for(const t of e)null!=t?.removeEventListener&&t.removeEventListener("abort",n)}for(const t of e){if(!0===t?.aborted){n();break}null!=t?.addEventListener&&t.addEventListener("abort",n)}const r=t.signal;return r.clear=function(){for(const t of e)null!=t?.removeEventListener&&t.removeEventListener("abort",n)},r}async function*ks(e,t={}){const n=e.getReader();try{for(;;){const e=await n.read();if(e.done)return;yield e.value}}finally{!0!==t.preventCancel&&await n.cancel(),n.releaseLock()}}function Ds(e){return null!=e&&("function"==typeof e.then&&"function"==typeof e.catch&&"function"==typeof e.finally)}function Ps(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Cs(e,...t){if(!((n=e)instanceof Uint8Array||null!=n&&"object"==typeof n&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function xs(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Ps(e.outputLen),Ps(e.blockLen)}function Ns(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const Ms="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,Os=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Ls=(e,t)=>e<<32-t|e>>>t;
|
|
7
|
+
Kr.bytes=0,$r.fromReader=(e,t)=>{let n=1;return $r(async function*(){for(;;)try{const{done:t,value:r}=await e.next(n);if(!0===t)return;null!=r&&(yield r)}catch(e){if("ERR_UNDER_READ"===e.code)return{done:!0,value:null};throw e}finally{n=1}}(),{...t??{},onLength:e=>{n=e}})};const zr=t,Wr=e=>new Error(`${zr}: ${e}`);function jr(e){return(new TextDecoder).decode(e)}function Gr(e){return(new TextEncoder).encode(e)}async function Yr(e){for await(const t of e)return t}window.opr&&window.opr.addons||window.opera||navigator.userAgent.indexOf(" OPR/");const Qr="undefined"!=typeof InstallTrigger;/constructor/i.test(window.HTMLElement)||(!window.safari||"undefined"!=typeof safari&&window.safari.pushNotification).toString();async function Jr(e){const t=e,n=(new TextEncoder).encode(t.sequenceNumber.toString());return await ft.encode(n)}!(!window.chrome||!window.chrome.webstore&&!window.chrome.runtime)&&navigator.userAgent.indexOf("Edg");let Zr={readyErrored:0,noiseErrored:0,upgradeErrored:0,readyTimedout:0,noiseTimedout:0,success:0},Xr={pending:0,open:0,ready_error:0,noise_error:0,upgrade_error:0,ready_timeout:0,noise_timeout:0,close:0,abort:0,remote_close:0},es={pending:0,ready_error:0,noise_error:0,upgrade_error:0,close:0,remote_close:0,ready:0,abort:0,ready_timeout:0,noise_timeout:0,open:0},ts=0,ns=0,rs=!0,ss=0,is=!0,os=0;if(!WebTransport)throw Wr("It seems that your browser does not support the required WebTransport feature");var as,cs,ls={exports:{}};function us(){if(cs)return as;cs=1;var e=1e3,t=60*e,n=60*t,r=24*n,s=7*r,i=365.25*r;function o(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"s":"")}return as=function(a,c){c=c||{};var l=typeof a;if("string"===l&&a.length>0)return function(o){if((o=String(o)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(o);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*i;case"weeks":case"week":case"w":return c*s;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===l&&isFinite(a))return c.long?function(s){var i=Math.abs(s);if(i>=r)return o(s,i,r,"day");if(i>=n)return o(s,i,n,"hour");if(i>=t)return o(s,i,t,"minute");if(i>=e)return o(s,i,e,"second");return s+" ms"}(a):function(s){var i=Math.abs(s);if(i>=r)return Math.round(s/r)+"d";if(i>=n)return Math.round(s/n)+"h";if(i>=t)return Math.round(s/t)+"m";if(i>=e)return Math.round(s/e)+"s";return s+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}var hs=function(e){function t(e){let r,s,i,o=null;function a(...e){if(!a.enabled)return;const n=a,s=Number(new Date),i=s-(r||s);n.diff=i,n.prev=r,n.curr=s,r=s,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let o=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((r,s)=>{if("%%"===r)return"%";o++;const i=t.formatters[s];if("function"==typeof i){const t=e[o];r=i.call(n,t),e.splice(o,1),o--}return r})),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=n,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==o?o:(s!==t.namespaces&&(s=t.namespaces,i=t.enabled(e)),i),set:e=>{o=e}}),"function"==typeof t.init&&t.init(a),a}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(r),...t.skips.map(r).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(n=0;n<s;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=us(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t};!function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,s=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))})),t.splice(s,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=hs(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(ls,ls.exports);var ds=Lr(ls.exports);function ps(){return{forComponent:e=>fs(e)}}function fs(e){let t=function(e){const t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}(`${e}:trace`);return ds.enabled(`${e}:trace`)&&null!=ds.names.map((e=>e.toString())).find((e=>e.includes(":trace")))&&(t=ds(`${e}:trace`)),Object.assign(ds(e),{error:ds(`${e}:error`),trace:t})}ds.formatters.b=e=>null==e?"undefined":Pe.baseEncode(e),ds.formatters.t=e=>null==e?"undefined":ye.baseEncode(e),ds.formatters.m=e=>null==e?"undefined":Ne.baseEncode(e),ds.formatters.p=e=>null==e?"undefined":e.toString(),ds.formatters.c=e=>null==e?"undefined":e.toString(),ds.formatters.k=e=>null==e?"undefined":e.toString(),ds.formatters.a=e=>null==e?"undefined":e.toString();const gs=Symbol.for("nodejs.util.inspect.custom"),ms=Object.values(_t).map((e=>e.decoder)).reduce(((e,t)=>e.or(t)),_t.identity.decoder),ys=114,ws=36,bs=37;class vs{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[rn]=!0;toString(){return null==this.string&&(this.string=Pe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return wt.createV1(ys,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(null==e)return!1;if(e instanceof Uint8Array)return _n(this.multihash.bytes,e);if("string"==typeof e)return Is(e).equals(this);if(null!=e?.multihash?.bytes)return _n(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[gs](){return`PeerId(${this.toString()})`}}class Es extends vs{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}}class Ss extends vs{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}}class _s extends vs{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}}function Is(e,t){if("1"===e.charAt(0)||"Q"===e.charAt(0)){const t=lt(Pe.decode(`z${e}`));return e.startsWith("12D")?new Ss({multihash:t}):e.startsWith("16U")?new _s({multihash:t}):new Es({multihash:t})}return Rs(ms.decode(e))}function Rs(e){try{const t=lt(e);if(t.code===dt.code){if(t.digest.length===ws)return new Ss({multihash:t});if(t.digest.length===bs)return new _s({multihash:t})}if(t.code===ft.code)return new Es({multihash:t})}catch{return function(e){if(null==e||null==e.multihash||null==e.version||1===e.version&&e.code!==ys)throw new Error("Supplied PeerID CID is invalid");const t=e.multihash;if(t.code===ft.code)return new Es({multihash:e.multihash});if(t.code===dt.code){if(t.digest.length===ws)return new Ss({multihash:e.multihash});if(t.digest.length===bs)return new _s({multihash:e.multihash})}throw new Error("Supplied PeerID CID is invalid")}(wt.decode(e))}throw new Error("Supplied PeerID CID is invalid")}async function As(e,t){return e.length===ws?new Ss({multihash:ct(dt.code,e),privateKey:t}):e.length===bs?new _s({multihash:ct(dt.code,e),privateKey:t}):new Es({multihash:await ft.digest(e),publicKey:e,privateKey:t})}function Ts(e){const t=new globalThis.AbortController;function n(){t.abort();for(const t of e)null!=t?.removeEventListener&&t.removeEventListener("abort",n)}for(const t of e){if(!0===t?.aborted){n();break}null!=t?.addEventListener&&t.addEventListener("abort",n)}const r=t.signal;return r.clear=function(){for(const t of e)null!=t?.removeEventListener&&t.removeEventListener("abort",n)},r}async function*ks(e,t={}){const n=e.getReader();try{for(;;){const e=await n.read();if(e.done)return;yield e.value}}finally{!0!==t.preventCancel&&await n.cancel(),n.releaseLock()}}function Ds(e){return null!=e&&("function"==typeof e.then&&"function"==typeof e.catch&&"function"==typeof e.finally)}function Ps(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function Cs(e,...t){if(!((n=e)instanceof Uint8Array||null!=n&&"object"==typeof n&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function xs(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Ps(e.outputLen),Ps(e.blockLen)}function Ns(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const Ms="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,Os=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Ls=(e,t)=>e<<32-t|e>>>t;
|
|
8
8
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */new Uint8Array(new Uint32Array([287454020]).buffer)[0];const Bs=async()=>{};async function Us(e,t,n){let r=Date.now();for(let s=0;s<e;s++){n(s);const e=Date.now()-r;e>=0&&e<t||(await Bs(),r+=e)}}function Fs(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}function Vs(e){return"string"==typeof e&&(e=Fs(e)),Cs(e),e}function Ks(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];Cs(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const s=e[t];n.set(s,r),r+=s.length}return n}class $s{clone(){return this._cloneInto()}}const qs={}.toString;function Hs(e){const t=t=>e().update(Vs(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function zs(e=32){if(Ms&&"function"==typeof Ms.getRandomValues)return Ms.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}const Ws=(e,t,n)=>e&t^e&n^t&n;class js extends $s{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Os(this.buffer)}update(e){Ns(this);const{view:t,buffer:n,blockLen:r}=this,s=(e=Vs(e)).length;for(let i=0;i<s;){const o=Math.min(r-this.pos,s-i);if(o!==r)n.set(e.subarray(i,i+o),this.pos),this.pos+=o,i+=o,this.pos===r&&(this.process(t,0),this.pos=0);else{const t=Os(e);for(;r<=s-i;i+=r)this.process(t,i)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ns(this),function(e,t){Cs(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:s}=this;let{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const s=BigInt(32),i=BigInt(4294967295),o=Number(n>>s&i),a=Number(n&i),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,a,r)}(n,r-8,BigInt(8*this.length),s),this.process(n,0);const o=Os(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,l=this.get();if(c>l.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)o.setUint32(4*e,l[e],s)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:s,destroyed:i,pos:o}=this;return e.length=r,e.pos=o,e.finished=s,e.destroyed=i,r%t&&e.buffer.set(n),e}}const Gs=BigInt(2**32-1),Ys=BigInt(32);function Qs(e,t=!1){return t?{h:Number(e&Gs),l:Number(e>>Ys&Gs)}:{h:0|Number(e>>Ys&Gs),l:0|Number(e&Gs)}}const Js={fromBig:Qs,split:function(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let s=0;s<e.length;s++){const{h:i,l:o}=Qs(e[s],t);[n[s],r[s]]=[i,o]}return[n,r]},toBig:(e,t)=>BigInt(e>>>0)<<Ys|BigInt(t>>>0),shrSH:(e,t,n)=>e>>>n,shrSL:(e,t,n)=>e<<32-n|t>>>n,rotrSH:(e,t,n)=>e>>>n|t<<32-n,rotrSL:(e,t,n)=>e<<32-n|t>>>n,rotrBH:(e,t,n)=>e<<64-n|t>>>n-32,rotrBL:(e,t,n)=>e>>>n-32|t<<64-n,rotr32H:(e,t)=>t,rotr32L:(e,t)=>e,rotlSH:(e,t,n)=>e<<n|t>>>32-n,rotlSL:(e,t,n)=>t<<n|e>>>32-n,rotlBH:(e,t,n)=>t<<n-32|e>>>64-n,rotlBL:(e,t,n)=>e<<n-32|t>>>64-n,add:function(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:0|s}},add3L:(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),add3H:(e,t,n,r)=>t+n+r+(e/2**32|0)|0,add4L:(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),add4H:(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,add5H:(e,t,n,r,s,i)=>t+n+r+s+i+(e/2**32|0)|0,add5L:(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0)},[Zs,Xs]=(()=>Js.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((e=>BigInt(e)))))(),ei=new Uint32Array(80),ti=new Uint32Array(80);class ni extends js{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:s,Cl:i,Dh:o,Dl:a,Eh:c,El:l,Fh:u,Fl:h,Gh:d,Gl:p,Hh:f,Hl:g}=this;return[e,t,n,r,s,i,o,a,c,l,u,h,d,p,f,g]}set(e,t,n,r,s,i,o,a,c,l,u,h,d,p,f,g){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|s,this.Cl=0|i,this.Dh=0|o,this.Dl=0|a,this.Eh=0|c,this.El=0|l,this.Fh=0|u,this.Fl=0|h,this.Gh=0|d,this.Gl=0|p,this.Hh=0|f,this.Hl=0|g}process(e,t){for(let n=0;n<16;n++,t+=4)ei[n]=e.getUint32(t),ti[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|ei[e-15],n=0|ti[e-15],r=Js.rotrSH(t,n,1)^Js.rotrSH(t,n,8)^Js.shrSH(t,n,7),s=Js.rotrSL(t,n,1)^Js.rotrSL(t,n,8)^Js.shrSL(t,n,7),i=0|ei[e-2],o=0|ti[e-2],a=Js.rotrSH(i,o,19)^Js.rotrBH(i,o,61)^Js.shrSH(i,o,6),c=Js.rotrSL(i,o,19)^Js.rotrBL(i,o,61)^Js.shrSL(i,o,6),l=Js.add4L(s,c,ti[e-7],ti[e-16]),u=Js.add4H(l,r,a,ei[e-7],ei[e-16]);ei[e]=0|u,ti[e]=0|l}let{Ah:n,Al:r,Bh:s,Bl:i,Ch:o,Cl:a,Dh:c,Dl:l,Eh:u,El:h,Fh:d,Fl:p,Gh:f,Gl:g,Hh:m,Hl:y}=this;for(let e=0;e<80;e++){const t=Js.rotrSH(u,h,14)^Js.rotrSH(u,h,18)^Js.rotrBH(u,h,41),w=Js.rotrSL(u,h,14)^Js.rotrSL(u,h,18)^Js.rotrBL(u,h,41),b=u&d^~u&f,v=h&p^~h&g,E=Js.add5L(y,w,v,Xs[e],ti[e]),S=Js.add5H(E,m,t,b,Zs[e],ei[e]),_=0|E,I=Js.rotrSH(n,r,28)^Js.rotrBH(n,r,34)^Js.rotrBH(n,r,39),R=Js.rotrSL(n,r,28)^Js.rotrBL(n,r,34)^Js.rotrBL(n,r,39),A=n&s^n&o^s&o,T=r&i^r&a^i&a;m=0|f,y=0|g,f=0|d,g=0|p,d=0|u,p=0|h,({h:u,l:h}=Js.add(0|c,0|l,0|S,0|_)),c=0|o,l=0|a,o=0|s,a=0|i,s=0|n,i=0|r;const k=Js.add3L(_,R,T);n=Js.add3H(k,S,I,A),r=0|k}({h:n,l:r}=Js.add(0|this.Ah,0|this.Al,0|n,0|r)),({h:s,l:i}=Js.add(0|this.Bh,0|this.Bl,0|s,0|i)),({h:o,l:a}=Js.add(0|this.Ch,0|this.Cl,0|o,0|a)),({h:c,l:l}=Js.add(0|this.Dh,0|this.Dl,0|c,0|l)),({h:u,l:h}=Js.add(0|this.Eh,0|this.El,0|u,0|h)),({h:d,l:p}=Js.add(0|this.Fh,0|this.Fl,0|d,0|p)),({h:f,l:g}=Js.add(0|this.Gh,0|this.Gl,0|f,0|g)),({h:m,l:y}=Js.add(0|this.Hh,0|this.Hl,0|m,0|y)),this.set(n,r,s,i,o,a,c,l,u,h,d,p,f,g,m,y)}roundClean(){ei.fill(0),ti.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const ri=Hs((()=>new ni)),si=BigInt(0),ii=BigInt(1),oi=BigInt(2);
|
|
9
9
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ai(e){return e instanceof Uint8Array||null!=e&&"object"==typeof e&&"Uint8Array"===e.constructor.name}function ci(e){if(!ai(e))throw new Error("Uint8Array expected")}const li=Array.from({length:256},((e,t)=>t.toString(16).padStart(2,"0")));function ui(e){ci(e);let t="";for(let n=0;n<e.length;n++)t+=li[e[n]];return t}function hi(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function di(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}const pi={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function fi(e){return e>=pi._0&&e<=pi._9?e-pi._0:e>=pi._A&&e<=pi._F?e-(pi._A-10):e>=pi._a&&e<=pi._f?e-(pi._a-10):void 0}function gi(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length,n=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,s=0;t<n;t++,s+=2){const n=fi(e.charCodeAt(s)),i=fi(e.charCodeAt(s+1));if(void 0===n||void 0===i){const t=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+s)}r[t]=16*n+i}return r}function mi(e){return di(ui(e))}function yi(e){return ci(e),di(ui(Uint8Array.from(e).reverse()))}function wi(e,t){return gi(e.toString(16).padStart(2*t,"0"))}function bi(e,t){return wi(e,t).reverse()}function vi(e,t,n){let r;if("string"==typeof t)try{r=gi(t)}catch(n){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${n}`)}else{if(!ai(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const s=r.length;if("number"==typeof n&&s!==n)throw new Error(`${e} expected ${n} bytes, got ${s}`);return r}function Ei(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];ci(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const s=e[t];n.set(s,r),r+=s.length}return n}const Si=e=>(oi<<BigInt(e-1))-ii,_i=e=>new Uint8Array(e),Ii=e=>Uint8Array.from(e);function Ri(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=_i(e),s=_i(e),i=0;const o=()=>{r.fill(1),s.fill(0),i=0},a=(...e)=>n(s,r,...e),c=(e=_i())=>{s=a(Ii([0]),e),r=a(),0!==e.length&&(s=a(Ii([1]),e),r=a())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=a();const t=r.slice();n.push(t),e+=r.length}return Ei(...n)};return(e,t)=>{let n;for(o(),c(e);!(n=t(l()));)c();return o(),n}}const Ai={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||ai(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function Ti(e,t,n={}){const r=(t,n,r)=>{const s=Ai[n];if("function"!=typeof s)throw new Error(`Invalid validator "${n}", expected function`);const i=e[t];if(!(r&&void 0===i||s(i,e)))throw new Error(`Invalid param ${String(t)}=${i} (${typeof i}), expected ${n}`)};for(const[e,n]of Object.entries(t))r(e,n,!1);for(const[e,t]of Object.entries(n))r(e,t,!0);return e}var ki=Object.freeze({__proto__:null,abytes:ci,bitGet:function(e,t){return e>>BigInt(t)&ii},bitLen:function(e){let t;for(t=0;e>si;e>>=ii,t+=1);return t},bitMask:Si,bitSet:function(e,t,n){return e|(n?ii:si)<<BigInt(t)},bytesToHex:ui,bytesToNumberBE:mi,bytesToNumberLE:yi,concatBytes:Ei,createHmacDrbg:Ri,ensureBytes:vi,equalBytes:function(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return 0===n},hexToBytes:gi,hexToNumber:di,isBytes:ai,numberToBytesBE:wi,numberToBytesLE:bi,numberToHexUnpadded:hi,numberToVarBytesBE:function(e){return gi(hi(e))},utf8ToBytes:function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))},validateObject:Ti});
|
|
10
10
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Di=BigInt(0),Pi=BigInt(1),Ci=BigInt(2),xi=BigInt(3),Ni=BigInt(4),Mi=BigInt(5),Oi=BigInt(8);function Li(e,t){const n=e%t;return n>=Di?n:t+n}function Bi(e,t,n){if(n<=Di||t<Di)throw new Error("Expected power/modulo > 0");if(n===Pi)return Di;let r=Pi;for(;t>Di;)t&Pi&&(r=r*e%n),e=e*e%n,t>>=Pi;return r}function Ui(e,t,n){let r=e;for(;t-- >Di;)r*=r,r%=n;return r}function Fi(e,t){if(e===Di||t<=Di)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Li(e,t),r=t,s=Di,i=Pi;for(;n!==Di;){const e=r%n,t=s-i*(r/n);r=n,n=e,s=i,i=t}if(r!==Pi)throw new Error("invert: does not exist");return Li(s,t)}function Vi(e){if(e%Ni===xi){const t=(e+Pi)/Ni;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%Oi===Mi){const t=(e-Mi)/Oi;return function(e,n){const r=e.mul(n,Ci),s=e.pow(r,t),i=e.mul(n,s),o=e.mul(e.mul(i,Ci),s),a=e.mul(i,e.sub(o,e.ONE));if(!e.eql(e.sqr(a),n))throw new Error("Cannot find square root");return a}}return function(e){const t=(e-Pi)/Ci;let n,r,s;for(n=e-Pi,r=0;n%Ci===Di;n/=Ci,r++);for(s=Ci;s<e&&Bi(s,t,e)!==e-Pi;s++);if(1===r){const t=(e+Pi)/Ni;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const i=(n+Pi)/Ci;return function(e,o){if(e.pow(o,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=r,c=e.pow(e.mul(e.ONE,s),n),l=e.pow(o,i),u=e.pow(o,n);for(;!e.eql(u,e.ONE);){if(e.eql(u,e.ZERO))return e.ZERO;let t=1;for(let n=e.sqr(u);t<a&&!e.eql(n,e.ONE);t++)n=e.sqr(n);const n=e.pow(c,Pi<<BigInt(a-t-1));c=e.sqr(n),l=e.mul(l,n),u=e.mul(u,c),a=t}return l}}(e)}BigInt(9),BigInt(16);const Ki=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $i(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function qi(e,t,n=!1,r={}){if(e<=Di)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:s,nByteLength:i}=$i(e,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=Vi(e),a=Object.freeze({ORDER:e,BITS:s,BYTES:i,MASK:Si(s),ZERO:Di,ONE:Pi,create:t=>Li(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return Di<=t&&t<e},is0:e=>e===Di,isOdd:e=>(e&Pi)===Pi,neg:t=>Li(-t,e),eql:(e,t)=>e===t,sqr:t=>Li(t*t,e),add:(t,n)=>Li(t+n,e),sub:(t,n)=>Li(t-n,e),mul:(t,n)=>Li(t*n,e),pow:(e,t)=>function(e,t,n){if(n<Di)throw new Error("Expected power > 0");if(n===Di)return e.ONE;if(n===Pi)return t;let r=e.ONE,s=t;for(;n>Di;)n&Pi&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Pi;return r}(a,e,t),div:(t,n)=>Li(t*Fi(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Fi(t,e),sqrt:r.sqrt||(e=>o(a,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce(((t,r,s)=>e.is0(r)?t:(n[s]=t,e.mul(t,r))),e.ONE),s=e.inv(r);return t.reduceRight(((t,r,s)=>e.is0(r)?t:(n[s]=e.mul(t,n[s]),e.mul(t,r))),s),n}(a,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?bi(e,i):wi(e,i),fromBytes:e=>{if(e.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${e.length}`);return n?yi(e):mi(e)}});return Object.freeze(a)}function Hi(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function zi(e){const t=Hi(e);return t+Math.ceil(t/2)}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpeerjs",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "WebPEER.js is
|
|
3
|
+
"version": "0.1.10",
|
|
4
|
+
"description": "WebPEER.js is Decentralized P2P network overlay inside browser.",
|
|
5
5
|
"main": "./dist/umd/webpeerjs.js",
|
|
6
6
|
"module": "./src/webpeerjs.js",
|
|
7
7
|
"exports": {
|