@candypoets/nipworker 0.91.0 → 0.91.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index2.js CHANGED
@@ -1 +1,2614 @@
1
- import*as b from"flatbuffers";import{ByteBuffer as $t}from"flatbuffers";import{a0 as ht,N as Ht,P as Dt,W as ut,S as Wt,a1 as Xt,a2 as pt}from"./worker-message.js";import"./signer-response.js";import{nip19 as dt}from"nostr-tools";class _{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCacheRequest(t,e){return(e||new _).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCacheRequest(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new _).__init(t.readInt32(t.position())+t.position(),t)}subId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}requests(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?(e||new ht).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}requestsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}event(t){const e=this.bb.__offset(this.bb_pos,8);return e?(t||new Ht).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}parsedEvent(t){const e=this.bb.__offset(this.bb_pos,10);return e?(t||new Dt).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}relays(t,e){const s=this.bb.__offset(this.bb_pos,12);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}relaysLength(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}static startCacheRequest(t){t.startObject(5)}static addSubId(t,e){t.addFieldOffset(0,e,0)}static addRequests(t,e){t.addFieldOffset(1,e,0)}static createRequestsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRequestsVector(t,e){t.startVector(4,e,4)}static addEvent(t,e){t.addFieldOffset(2,e,0)}static addParsedEvent(t,e){t.addFieldOffset(3,e,0)}static addRelays(t,e){t.addFieldOffset(4,e,0)}static createRelaysVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRelaysVector(t,e){t.startVector(4,e,4)}static endCacheRequest(t){const e=t.endObject();return t.requiredField(e,4),e}unpack(){return new lt(this.subId(),this.bb.createObjList(this.requests.bind(this),this.requestsLength()),this.event()!==null?this.event().unpack():null,this.parsedEvent()!==null?this.parsedEvent().unpack():null,this.bb.createScalarList(this.relays.bind(this),this.relaysLength()))}unpackTo(t){t.subId=this.subId(),t.requests=this.bb.createObjList(this.requests.bind(this),this.requestsLength()),t.event=this.event()!==null?this.event().unpack():null,t.parsedEvent=this.parsedEvent()!==null?this.parsedEvent().unpack():null,t.relays=this.bb.createScalarList(this.relays.bind(this),this.relaysLength())}}class lt{constructor(t=null,e=[],s=null,n=null,r=[]){this.subId=t,this.requests=e,this.event=s,this.parsedEvent=n,this.relays=r}pack(t){const e=this.subId!==null?t.createString(this.subId):0,s=_.createRequestsVector(t,t.createObjectOffsetList(this.requests)),n=this.event!==null?this.event.pack(t):0,r=this.parsedEvent!==null?this.parsedEvent.pack(t):0,o=_.createRelaysVector(t,t.createObjectOffsetList(this.relays));return _.startCacheRequest(t),_.addSubId(t,e),_.addRequests(t,s),_.addEvent(t,n),_.addParsedEvent(t,r),_.addRelays(t,o),_.endCacheRequest(t)}}var $=(i=>(i[i.NONE=0]="NONE",i[i.WorkerMessage=1]="WorkerMessage",i[i.CacheRequest=2]="CacheRequest",i))($||{});function ft(i,t){switch($[i]){case"NONE":return null;case"WorkerMessage":return t(new ut);case"CacheRequest":return t(new _);default:return null}}class R{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCacheInputMessage(t,e){return(e||new R).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCacheInputMessage(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new R).__init(t.readInt32(t.position())+t.position(),t)}contentType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):$.NONE}content(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startCacheInputMessage(t){t.startObject(2)}static addContentType(t,e){t.addFieldInt8(0,e,$.NONE)}static addContent(t,e){t.addFieldOffset(1,e,0)}static endCacheInputMessage(t){const e=t.endObject();return t.requiredField(e,6),e}static createCacheInputMessage(t,e,s){return R.startCacheInputMessage(t),R.addContentType(t,e),R.addContent(t,s),R.endCacheInputMessage(t)}unpack(){return new gt(this.contentType(),(()=>{const t=ft(this.contentType(),this.content.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.contentType=this.contentType(),t.content=(()=>{const e=ft(this.contentType(),this.content.bind(this));return e===null?null:e.unpack()})()}}class gt{constructor(t=$.NONE,e=null){this.contentType=t,this.content=e}pack(t){const e=t.createObjectOffset(this.content);return R.createCacheInputMessage(t,this.contentType,e)}}class m{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCacheResponse(t,e){return(e||new m).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCacheResponse(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new m).__init(t.readInt32(t.position())+t.position(),t)}subId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}payload(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint8(this.bb.__vector(this.bb_pos+e)+t):0}payloadLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}payloadArray(){const t=this.bb.__offset(this.bb_pos,6);return t?new Uint8Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}static startCacheResponse(t){t.startObject(2)}static addSubId(t,e){t.addFieldOffset(0,e,0)}static addPayload(t,e){t.addFieldOffset(1,e,0)}static createPayloadVector(t,e){t.startVector(1,e.length,1);for(let s=e.length-1;s>=0;s--)t.addInt8(e[s]);return t.endVector()}static startPayloadVector(t,e){t.startVector(1,e,1)}static endCacheResponse(t){const e=t.endObject();return t.requiredField(e,4),e}static createCacheResponse(t,e,s){return m.startCacheResponse(t),m.addSubId(t,e),m.addPayload(t,s),m.endCacheResponse(t)}unpack(){return new _t(this.subId(),this.bb.createScalarList(this.payload.bind(this),this.payloadLength()))}unpackTo(t){t.subId=this.subId(),t.payload=this.bb.createScalarList(this.payload.bind(this),this.payloadLength())}}class _t{constructor(t=null,e=[]){this.subId=t,this.payload=e}pack(t){const e=this.subId!==null?t.createString(this.subId):0,s=m.createPayloadVector(t,this.payload);return m.createCacheResponse(t,e,s)}}class I{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCounterPipeConfig(t,e){return(e||new I).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCounterPipeConfig(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new I).__init(t.readInt32(t.position())+t.position(),t)}kinds(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint16(this.bb.__vector(this.bb_pos+e)+t*2):0}kindsLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}kindsArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint16Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}pubkey(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,t):null}static startCounterPipeConfig(t){t.startObject(2)}static addKinds(t,e){t.addFieldOffset(0,e,0)}static createKindsVector(t,e){t.startVector(2,e.length,2);for(let s=e.length-1;s>=0;s--)t.addInt16(e[s]);return t.endVector()}static startKindsVector(t,e){t.startVector(2,e,2)}static addPubkey(t,e){t.addFieldOffset(1,e,0)}static endCounterPipeConfig(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),e}static createCounterPipeConfig(t,e,s){return I.startCounterPipeConfig(t),I.addKinds(t,e),I.addPubkey(t,s),I.endCounterPipeConfig(t)}unpack(){return new yt(this.bb.createScalarList(this.kinds.bind(this),this.kindsLength()),this.pubkey())}unpackTo(t){t.kinds=this.bb.createScalarList(this.kinds.bind(this),this.kindsLength()),t.pubkey=this.pubkey()}}class yt{constructor(t=[],e=null){this.kinds=t,this.pubkey=e}pack(t){const e=I.createKindsVector(t,this.kinds),s=this.pubkey!==null?t.createString(this.pubkey):0;return I.createCounterPipeConfig(t,e,s)}}class j{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsGetPublicKey(t,e){return(e||new j).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsGetPublicKey(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new j).__init(t.readInt32(t.position())+t.position(),t)}static startGetPublicKey(t){t.startObject(0)}static endGetPublicKey(t){return t.endObject()}static createGetPublicKey(t){return j.startGetPublicKey(t),j.endGetPublicKey(t)}unpack(){return new Y}unpackTo(t){}}class Y{constructor(){}pack(t){return j.createGetPublicKey(t)}}class F{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsKindFilterPipeConfig(t,e){return(e||new F).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsKindFilterPipeConfig(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new F).__init(t.readInt32(t.position())+t.position(),t)}kinds(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint16(this.bb.__vector(this.bb_pos+e)+t*2):0}kindsLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}kindsArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint16Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}static startKindFilterPipeConfig(t){t.startObject(1)}static addKinds(t,e){t.addFieldOffset(0,e,0)}static createKindsVector(t,e){t.startVector(2,e.length,2);for(let s=e.length-1;s>=0;s--)t.addInt16(e[s]);return t.endVector()}static startKindsVector(t,e){t.startVector(2,e,2)}static endKindFilterPipeConfig(t){const e=t.endObject();return t.requiredField(e,4),e}static createKindFilterPipeConfig(t,e){return F.startKindFilterPipeConfig(t),F.addKinds(t,e),F.endKindFilterPipeConfig(t)}unpack(){return new Pt(this.bb.createScalarList(this.kinds.bind(this),this.kindsLength()))}unpackTo(t){t.kinds=this.bb.createScalarList(this.kinds.bind(this),this.kindsLength())}}class Pt{constructor(t=[]){this.kinds=t}pack(t){const e=F.createKindsVector(t,this.kinds);return F.createKindFilterPipeConfig(t,e)}}class y{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsTemplate(t,e){return(e||new y).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsTemplate(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new y).__init(t.readInt32(t.position())+t.position(),t)}kind(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint16(this.bb_pos+t):0}createdAt(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readInt32(this.bb_pos+t):0}content(t){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__string(this.bb_pos+e,t):null}tags(t,e){const s=this.bb.__offset(this.bb_pos,10);return s?(e||new Wt).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}tagsLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}static startTemplate(t){t.startObject(4)}static addKind(t,e){t.addFieldInt16(0,e,0)}static addCreatedAt(t,e){t.addFieldInt32(1,e,0)}static addContent(t,e){t.addFieldOffset(2,e,0)}static addTags(t,e){t.addFieldOffset(3,e,0)}static createTagsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startTagsVector(t,e){t.startVector(4,e,4)}static endTemplate(t){const e=t.endObject();return t.requiredField(e,8),t.requiredField(e,10),e}static createTemplate(t,e,s,n,r){return y.startTemplate(t),y.addKind(t,e),y.addCreatedAt(t,s),y.addContent(t,n),y.addTags(t,r),y.endTemplate(t)}unpack(){return new tt(this.kind(),this.createdAt(),this.content(),this.bb.createObjList(this.tags.bind(this),this.tagsLength()))}unpackTo(t){t.kind=this.kind(),t.createdAt=this.createdAt(),t.content=this.content(),t.tags=this.bb.createObjList(this.tags.bind(this),this.tagsLength())}}class tt{constructor(t=0,e=0,s=null,n=[]){this.kind=t,this.createdAt=e,this.content=s,this.tags=n}pack(t){const e=this.content!==null?t.createString(this.content):0,s=y.createTagsVector(t,t.createObjectOffsetList(this.tags));return y.createTemplate(t,this.kind,this.createdAt,e,s)}}class k{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPublish(t,e){return(e||new k).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPublish(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new k).__init(t.readInt32(t.position())+t.position(),t)}publishId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}template(t){const e=this.bb.__offset(this.bb_pos,6);return e?(t||new y).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}relays(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}relaysLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}static startPublish(t){t.startObject(3)}static addPublishId(t,e){t.addFieldOffset(0,e,0)}static addTemplate(t,e){t.addFieldOffset(1,e,0)}static addRelays(t,e){t.addFieldOffset(2,e,0)}static createRelaysVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRelaysVector(t,e){t.startVector(4,e,4)}static endPublish(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),t.requiredField(e,8),e}unpack(){return new et(this.publishId(),this.template()!==null?this.template().unpack():null,this.bb.createScalarList(this.relays.bind(this),this.relaysLength()))}unpackTo(t){t.publishId=this.publishId(),t.template=this.template()!==null?this.template().unpack():null,t.relays=this.bb.createScalarList(this.relays.bind(this),this.relaysLength())}}class et{constructor(t=null,e=null,s=[]){this.publishId=t,this.template=e,this.relays=s}pack(t){const e=this.publishId!==null?t.createString(this.publishId):0,s=this.template!==null?this.template.pack(t):0,n=k.createRelaysVector(t,t.createObjectOffsetList(this.relays));return k.startPublish(t),k.addPublishId(t,e),k.addTemplate(t,s),k.addRelays(t,n),k.endPublish(t)}}class M{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPrivateKey(t,e){return(e||new M).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPrivateKey(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new M).__init(t.readInt32(t.position())+t.position(),t)}privateKey(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}static startPrivateKey(t){t.startObject(1)}static addPrivateKey(t,e){t.addFieldOffset(0,e,0)}static endPrivateKey(t){const e=t.endObject();return t.requiredField(e,4),e}static createPrivateKey(t,e){return M.startPrivateKey(t),M.addPrivateKey(t,e),M.endPrivateKey(t)}unpack(){return new kt(this.privateKey())}unpackTo(t){t.privateKey=this.privateKey()}}class kt{constructor(t=null){this.privateKey=t}pack(t){const e=this.privateKey!==null?t.createString(this.privateKey):0;return M.createPrivateKey(t,e)}}var H=(i=>(i[i.NONE=0]="NONE",i[i.PrivateKey=1]="PrivateKey",i))(H||{});function wt(i,t){switch(H[i]){case"NONE":return null;case"PrivateKey":return t(new M);default:return null}}class O{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSetSigner(t,e){return(e||new O).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSetSigner(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new O).__init(t.readInt32(t.position())+t.position(),t)}signerTypeType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):H.NONE}signerType(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startSetSigner(t){t.startObject(2)}static addSignerTypeType(t,e){t.addFieldInt8(0,e,H.NONE)}static addSignerType(t,e){t.addFieldOffset(1,e,0)}static endSetSigner(t){const e=t.endObject();return t.requiredField(e,6),e}static createSetSigner(t,e,s){return O.startSetSigner(t),O.addSignerTypeType(t,e),O.addSignerType(t,s),O.endSetSigner(t)}unpack(){return new St(this.signerTypeType(),(()=>{const t=wt(this.signerTypeType(),this.signerType.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.signerTypeType=this.signerTypeType(),t.signerType=(()=>{const e=wt(this.signerTypeType(),this.signerType.bind(this));return e===null?null:e.unpack()})()}}class St{constructor(t=H.NONE,e=null){this.signerTypeType=t,this.signerType=e}pack(t){const e=t.createObjectOffset(this.signerType);return O.createSetSigner(t,this.signerTypeType,e)}}class K{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSignEvent(t,e){return(e||new K).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSignEvent(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new K).__init(t.readInt32(t.position())+t.position(),t)}template(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new y).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}static startSignEvent(t){t.startObject(1)}static addTemplate(t,e){t.addFieldOffset(0,e,0)}static endSignEvent(t){const e=t.endObject();return t.requiredField(e,4),e}static createSignEvent(t,e){return K.startSignEvent(t),K.addTemplate(t,e),K.endSignEvent(t)}unpack(){return new It(this.template()!==null?this.template().unpack():null)}unpackTo(t){t.template=this.template()!==null?this.template().unpack():null}}class It{constructor(t=null){this.template=t}pack(t){const e=this.template!==null?this.template.pack(t):0;return K.createSignEvent(t,e)}}class f{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsMuteFilterPipeConfig(t,e){return(e||new f).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMuteFilterPipeConfig(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new f).__init(t.readInt32(t.position())+t.position(),t)}pubkeys(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}pubkeysLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}hashtags(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}hashtagsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}words(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}wordsLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}eventIds(t,e){const s=this.bb.__offset(this.bb_pos,10);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}eventIdsLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}static startMuteFilterPipeConfig(t){t.startObject(4)}static addPubkeys(t,e){t.addFieldOffset(0,e,0)}static createPubkeysVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startPubkeysVector(t,e){t.startVector(4,e,4)}static addHashtags(t,e){t.addFieldOffset(1,e,0)}static createHashtagsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startHashtagsVector(t,e){t.startVector(4,e,4)}static addWords(t,e){t.addFieldOffset(2,e,0)}static createWordsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startWordsVector(t,e){t.startVector(4,e,4)}static addEventIds(t,e){t.addFieldOffset(3,e,0)}static createEventIdsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startEventIdsVector(t,e){t.startVector(4,e,4)}static endMuteFilterPipeConfig(t){return t.endObject()}static createMuteFilterPipeConfig(t,e,s,n,r){return f.startMuteFilterPipeConfig(t),f.addPubkeys(t,e),f.addHashtags(t,s),f.addWords(t,n),f.addEventIds(t,r),f.endMuteFilterPipeConfig(t)}unpack(){return new vt(this.bb.createScalarList(this.pubkeys.bind(this),this.pubkeysLength()),this.bb.createScalarList(this.hashtags.bind(this),this.hashtagsLength()),this.bb.createScalarList(this.words.bind(this),this.wordsLength()),this.bb.createScalarList(this.eventIds.bind(this),this.eventIdsLength()))}unpackTo(t){t.pubkeys=this.bb.createScalarList(this.pubkeys.bind(this),this.pubkeysLength()),t.hashtags=this.bb.createScalarList(this.hashtags.bind(this),this.hashtagsLength()),t.words=this.bb.createScalarList(this.words.bind(this),this.wordsLength()),t.eventIds=this.bb.createScalarList(this.eventIds.bind(this),this.eventIdsLength())}}class vt{constructor(t=[],e=[],s=[],n=[]){this.pubkeys=t,this.hashtags=e,this.words=s,this.eventIds=n}pack(t){const e=f.createPubkeysVector(t,t.createObjectOffsetList(this.pubkeys)),s=f.createHashtagsVector(t,t.createObjectOffsetList(this.hashtags)),n=f.createWordsVector(t,t.createObjectOffsetList(this.words)),r=f.createEventIdsVector(t,t.createObjectOffsetList(this.eventIds));return f.createMuteFilterPipeConfig(t,e,s,n,r)}}class S{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsNpubLimiterPipeConfig(t,e){return(e||new S).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsNpubLimiterPipeConfig(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new S).__init(t.readInt32(t.position())+t.position(),t)}kind(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint16(this.bb_pos+t):0}limitPerNpub(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readUint32(this.bb_pos+t):0}maxTotalNpubs(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.readUint32(this.bb_pos+t):0}static startNpubLimiterPipeConfig(t){t.startObject(3)}static addKind(t,e){t.addFieldInt16(0,e,0)}static addLimitPerNpub(t,e){t.addFieldInt32(1,e,0)}static addMaxTotalNpubs(t,e){t.addFieldInt32(2,e,0)}static endNpubLimiterPipeConfig(t){return t.endObject()}static createNpubLimiterPipeConfig(t,e,s,n){return S.startNpubLimiterPipeConfig(t),S.addKind(t,e),S.addLimitPerNpub(t,s),S.addMaxTotalNpubs(t,n),S.endNpubLimiterPipeConfig(t)}unpack(){return new Et(this.kind(),this.limitPerNpub(),this.maxTotalNpubs())}unpackTo(t){t.kind=this.kind(),t.limitPerNpub=this.limitPerNpub(),t.maxTotalNpubs=this.maxTotalNpubs()}}class Et{constructor(t=0,e=0,s=0){this.kind=t,this.limitPerNpub=e,this.maxTotalNpubs=s}pack(t){return S.createNpubLimiterPipeConfig(t,this.kind,this.limitPerNpub,this.maxTotalNpubs)}}class U{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsParsePipeConfig(t,e){return(e||new U).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsParsePipeConfig(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new U).__init(t.readInt32(t.position())+t.position(),t)}static startParsePipeConfig(t){t.startObject(0)}static endParsePipeConfig(t){return t.endObject()}static createParsePipeConfig(t){return U.startParsePipeConfig(t),U.endParsePipeConfig(t)}unpack(){return new Ct}unpackTo(t){}}class Ct{constructor(){}pack(t){return U.createParsePipeConfig(t)}}class A{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsProofVerificationPipeConfig(t,e){return(e||new A).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsProofVerificationPipeConfig(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new A).__init(t.readInt32(t.position())+t.position(),t)}maxProofs(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint32(this.bb_pos+t):0}static startProofVerificationPipeConfig(t){t.startObject(1)}static addMaxProofs(t,e){t.addFieldInt32(0,e,0)}static endProofVerificationPipeConfig(t){return t.endObject()}static createProofVerificationPipeConfig(t,e){return A.startProofVerificationPipeConfig(t),A.addMaxProofs(t,e),A.endProofVerificationPipeConfig(t)}unpack(){return new mt(this.maxProofs())}unpackTo(t){t.maxProofs=this.maxProofs()}}class mt{constructor(t=0){this.maxProofs=t}pack(t){return A.createProofVerificationPipeConfig(t,this.maxProofs)}}class q{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSaveToDbPipeConfig(t,e){return(e||new q).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSaveToDbPipeConfig(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new q).__init(t.readInt32(t.position())+t.position(),t)}static startSaveToDbPipeConfig(t){t.startObject(0)}static endSaveToDbPipeConfig(t){return t.endObject()}static createSaveToDbPipeConfig(t){return q.startSaveToDbPipeConfig(t),q.endSaveToDbPipeConfig(t)}unpack(){return new Ot}unpackTo(t){}}class Ot{constructor(){}pack(t){return q.createSaveToDbPipeConfig(t)}}class V{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSerializeEventsPipeConfig(t,e){return(e||new V).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSerializeEventsPipeConfig(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new V).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}static startSerializeEventsPipeConfig(t){t.startObject(1)}static addSubscriptionId(t,e){t.addFieldOffset(0,e,0)}static endSerializeEventsPipeConfig(t){const e=t.endObject();return t.requiredField(e,4),e}static createSerializeEventsPipeConfig(t,e){return V.startSerializeEventsPipeConfig(t),V.addSubscriptionId(t,e),V.endSerializeEventsPipeConfig(t)}unpack(){return new Tt(this.subscriptionId())}unpackTo(t){t.subscriptionId=this.subscriptionId()}}class Tt{constructor(t=null){this.subscriptionId=t}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0;return V.createSerializeEventsPipeConfig(t,e)}}var D=(i=>(i[i.NONE=0]="NONE",i[i.ParsePipeConfig=1]="ParsePipeConfig",i[i.KindFilterPipeConfig=2]="KindFilterPipeConfig",i[i.CounterPipeConfig=3]="CounterPipeConfig",i[i.NpubLimiterPipeConfig=4]="NpubLimiterPipeConfig",i[i.SaveToDbPipeConfig=5]="SaveToDbPipeConfig",i[i.SerializeEventsPipeConfig=6]="SerializeEventsPipeConfig",i[i.ProofVerificationPipeConfig=7]="ProofVerificationPipeConfig",i[i.MuteFilterPipeConfig=8]="MuteFilterPipeConfig",i))(D||{});function Ft(i,t){switch(D[i]){case"NONE":return null;case"ParsePipeConfig":return t(new U);case"KindFilterPipeConfig":return t(new F);case"CounterPipeConfig":return t(new I);case"NpubLimiterPipeConfig":return t(new S);case"SaveToDbPipeConfig":return t(new q);case"SerializeEventsPipeConfig":return t(new V);case"ProofVerificationPipeConfig":return t(new A);case"MuteFilterPipeConfig":return t(new f);default:return null}}class T{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPipe(t,e){return(e||new T).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPipe(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new T).__init(t.readInt32(t.position())+t.position(),t)}configType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):D.NONE}config(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startPipe(t){t.startObject(2)}static addConfigType(t,e){t.addFieldInt8(0,e,D.NONE)}static addConfig(t,e){t.addFieldOffset(1,e,0)}static endPipe(t){const e=t.endObject();return t.requiredField(e,6),e}static createPipe(t,e,s){return T.startPipe(t),T.addConfigType(t,e),T.addConfig(t,s),T.endPipe(t)}unpack(){return new Lt(this.configType(),(()=>{const t=Ft(this.configType(),this.config.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.configType=this.configType(),t.config=(()=>{const e=Ft(this.configType(),this.config.bind(this));return e===null?null:e.unpack()})()}}class Lt{constructor(t=D.NONE,e=null){this.configType=t,this.config=e}pack(t){const e=t.createObjectOffset(this.config);return T.createPipe(t,this.configType,e)}}class L{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPipelineConfig(t,e){return(e||new L).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPipelineConfig(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new L).__init(t.readInt32(t.position())+t.position(),t)}pipes(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?(e||new T).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}pipesLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}static startPipelineConfig(t){t.startObject(1)}static addPipes(t,e){t.addFieldOffset(0,e,0)}static createPipesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startPipesVector(t,e){t.startVector(4,e,4)}static endPipelineConfig(t){const e=t.endObject();return t.requiredField(e,4),e}static createPipelineConfig(t,e){return L.startPipelineConfig(t),L.addPipes(t,e),L.endPipelineConfig(t)}unpack(){return new st(this.bb.createObjList(this.pipes.bind(this),this.pipesLength()))}unpackTo(t){t.pipes=this.bb.createObjList(this.pipes.bind(this),this.pipesLength())}}class st{constructor(t=[]){this.pipes=t}pack(t){const e=L.createPipesVector(t,t.createObjectOffsetList(this.pipes));return L.createPipelineConfig(t,e)}}class d{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSubscriptionConfig(t,e){return(e||new d).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubscriptionConfig(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new d).__init(t.readInt32(t.position())+t.position(),t)}pipeline(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new L).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}closeOnEose(){const t=this.bb.__offset(this.bb_pos,6);return t?!!this.bb.readInt8(this.bb_pos+t):!1}cacheFirst(){const t=this.bb.__offset(this.bb_pos,8);return t?!!this.bb.readInt8(this.bb_pos+t):!0}timeoutMs(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.readUint64(this.bb_pos+t):BigInt("0")}maxEvents(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.readUint32(this.bb_pos+t):0}skipCache(){const t=this.bb.__offset(this.bb_pos,14);return t?!!this.bb.readInt8(this.bb_pos+t):!1}force(){const t=this.bb.__offset(this.bb_pos,16);return t?!!this.bb.readInt8(this.bb_pos+t):!1}bytesPerEvent(){const t=this.bb.__offset(this.bb_pos,18);return t?this.bb.readUint32(this.bb_pos+t):0}isSlow(){const t=this.bb.__offset(this.bb_pos,20);return t?!!this.bb.readInt8(this.bb_pos+t):!1}pagination(t){const e=this.bb.__offset(this.bb_pos,22);return e?this.bb.__string(this.bb_pos+e,t):null}static startSubscriptionConfig(t){t.startObject(10)}static addPipeline(t,e){t.addFieldOffset(0,e,0)}static addCloseOnEose(t,e){t.addFieldInt8(1,+e,0)}static addCacheFirst(t,e){t.addFieldInt8(2,+e,1)}static addTimeoutMs(t,e){t.addFieldInt64(3,e,BigInt("0"))}static addMaxEvents(t,e){t.addFieldInt32(4,e,0)}static addSkipCache(t,e){t.addFieldInt8(5,+e,0)}static addForce(t,e){t.addFieldInt8(6,+e,0)}static addBytesPerEvent(t,e){t.addFieldInt32(7,e,0)}static addIsSlow(t,e){t.addFieldInt8(8,+e,0)}static addPagination(t,e){t.addFieldOffset(9,e,0)}static endSubscriptionConfig(t){return t.endObject()}static createSubscriptionConfig(t,e,s,n,r,o,a,c,u,l,P){return d.startSubscriptionConfig(t),d.addPipeline(t,e),d.addCloseOnEose(t,s),d.addCacheFirst(t,n),d.addTimeoutMs(t,r),d.addMaxEvents(t,o),d.addSkipCache(t,a),d.addForce(t,c),d.addBytesPerEvent(t,u),d.addIsSlow(t,l),d.addPagination(t,P),d.endSubscriptionConfig(t)}unpack(){return new it(this.pipeline()!==null?this.pipeline().unpack():null,this.closeOnEose(),this.cacheFirst(),this.timeoutMs(),this.maxEvents(),this.skipCache(),this.force(),this.bytesPerEvent(),this.isSlow(),this.pagination())}unpackTo(t){t.pipeline=this.pipeline()!==null?this.pipeline().unpack():null,t.closeOnEose=this.closeOnEose(),t.cacheFirst=this.cacheFirst(),t.timeoutMs=this.timeoutMs(),t.maxEvents=this.maxEvents(),t.skipCache=this.skipCache(),t.force=this.force(),t.bytesPerEvent=this.bytesPerEvent(),t.isSlow=this.isSlow(),t.pagination=this.pagination()}}class it{constructor(t=null,e=!1,s=!0,n=BigInt("0"),r=0,o=!1,a=!1,c=0,u=!1,l=null){this.pipeline=t,this.closeOnEose=e,this.cacheFirst=s,this.timeoutMs=n,this.maxEvents=r,this.skipCache=o,this.force=a,this.bytesPerEvent=c,this.isSlow=u,this.pagination=l}pack(t){const e=this.pipeline!==null?this.pipeline.pack(t):0,s=this.pagination!==null?t.createString(this.pagination):0;return d.createSubscriptionConfig(t,e,this.closeOnEose,this.cacheFirst,this.timeoutMs,this.maxEvents,this.skipCache,this.force,this.bytesPerEvent,this.isSlow,s)}}class w{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSubscribe(t,e){return(e||new w).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubscribe(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new w).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}requests(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?(e||new ht).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}requestsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}config(t){const e=this.bb.__offset(this.bb_pos,8);return e?(t||new d).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}static startSubscribe(t){t.startObject(3)}static addSubscriptionId(t,e){t.addFieldOffset(0,e,0)}static addRequests(t,e){t.addFieldOffset(1,e,0)}static createRequestsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRequestsVector(t,e){t.startVector(4,e,4)}static addConfig(t,e){t.addFieldOffset(2,e,0)}static endSubscribe(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),t.requiredField(e,8),e}unpack(){return new nt(this.subscriptionId(),this.bb.createObjList(this.requests.bind(this),this.requestsLength()),this.config()!==null?this.config().unpack():null)}unpackTo(t){t.subscriptionId=this.subscriptionId(),t.requests=this.bb.createObjList(this.requests.bind(this),this.requestsLength()),t.config=this.config()!==null?this.config().unpack():null}}class nt{constructor(t=null,e=[],s=null){this.subscriptionId=t,this.requests=e,this.config=s}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0,s=w.createRequestsVector(t,t.createObjectOffsetList(this.requests)),n=this.config!==null?this.config.pack(t):0;return w.startSubscribe(t),w.addSubscriptionId(t,e),w.addRequests(t,s),w.addConfig(t,n),w.endSubscribe(t)}}class x{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsUnsubscribe(t,e){return(e||new x).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsUnsubscribe(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new x).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}static startUnsubscribe(t){t.startObject(1)}static addSubscriptionId(t,e){t.addFieldOffset(0,e,0)}static endUnsubscribe(t){const e=t.endObject();return t.requiredField(e,4),e}static createUnsubscribe(t,e){return x.startUnsubscribe(t),x.addSubscriptionId(t,e),x.endUnsubscribe(t)}unpack(){return new rt(this.subscriptionId())}unpackTo(t){t.subscriptionId=this.subscriptionId()}}class rt{constructor(t=null){this.subscriptionId=t}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0;return x.createUnsubscribe(t,e)}}var C=(i=>(i[i.NONE=0]="NONE",i[i.Subscribe=1]="Subscribe",i[i.Unsubscribe=2]="Unsubscribe",i[i.Publish=3]="Publish",i[i.SignEvent=4]="SignEvent",i[i.SetSigner=5]="SetSigner",i[i.GetPublicKey=6]="GetPublicKey",i))(C||{});function Rt(i,t){switch(C[i]){case"NONE":return null;case"Subscribe":return t(new w);case"Unsubscribe":return t(new x);case"Publish":return t(new k);case"SignEvent":return t(new K);case"SetSigner":return t(new O);case"GetPublicKey":return t(new j);default:return null}}class N{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsMainMessage(t,e){return(e||new N).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMainMessage(t,e){return t.setPosition(t.position()+b.SIZE_PREFIX_LENGTH),(e||new N).__init(t.readInt32(t.position())+t.position(),t)}contentType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):C.NONE}content(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startMainMessage(t){t.startObject(2)}static addContentType(t,e){t.addFieldInt8(0,e,C.NONE)}static addContent(t,e){t.addFieldOffset(1,e,0)}static endMainMessage(t){const e=t.endObject();return t.requiredField(e,6),e}static createMainMessage(t,e,s){return N.startMainMessage(t),N.addContentType(t,e),N.addContent(t,s),N.endMainMessage(t)}unpack(){return new W(this.contentType(),(()=>{const t=Rt(this.contentType(),this.content.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.contentType=this.contentType(),t.content=(()=>{const e=Rt(this.contentType(),this.content.bind(this));return e===null?null:e.unpack()})()}}class W{constructor(t=C.NONE,e=null){this.contentType=t,this.content=e}pack(t){const e=t.createObjectOffset(this.content);return N.createMainMessage(t,this.contentType,e)}}var Nt=(i=>(i[i.Kind0Parsed=0]="Kind0Parsed",i[i.Kind1Parsed=1]="Kind1Parsed",i[i.Kind3Parsed=3]="Kind3Parsed",i[i.Kind4Parsed=4]="Kind4Parsed",i[i.Kind6Parsed=6]="Kind6Parsed",i[i.Kind7Parsed=7]="Kind7Parsed",i[i.Kind17Parsed=17]="Kind17Parsed",i[i.Kind20Parsed=20]="Kind20Parsed",i[i.Kind22Parsed=22]="Kind22Parsed",i[i.Kind1111Parsed=1111]="Kind1111Parsed",i[i.Kind1311Parsed=1311]="Kind1311Parsed",i[i.Kind7374Parsed=7374]="Kind7374Parsed",i[i.Kind7375Parsed=7375]="Kind7375Parsed",i[i.Kind7376Parsed=7376]="Kind7376Parsed",i[i.Kind9321Parsed=9321]="Kind9321Parsed",i[i.Kind9735Parsed=9735]="Kind9735Parsed",i[i.Kind10002Parsed=10002]="Kind10002Parsed",i[i.Kind10019Parsed=10019]="Kind10019Parsed",i[i.Kind17375Parsed=17375]="Kind17375Parsed",i[i.Kind30023Parsed=30023]="Kind30023Parsed",i[i.Kind39089Parsed=39089]="Kind39089Parsed",i[i.ListParsed=51e3]="ListParsed",i[i.PreGenericParsed=52e3]="PreGenericParsed",i))(Nt||{}),Mt=(i=>(i[i.CachedEvent=0]="CachedEvent",i[i.FetchedEvent=1]="FetchedEvent",i[i.Count=2]="Count",i[i.ConnectionStatus=3]="ConnectionStatus",i[i.Eoce=4]="Eoce",i[i.BufferFull=5]="BufferFull",i))(Mt||{});class X{static initializeBuffer(t){new DataView(t).setUint32(0,4,!0)}static writeMessage(t,e){const s=new DataView(t),n=new Uint8Array(t),r=s.getUint32(0,!0),o=4+e.length;if(r+o>t.byteLength)return console.warn("Buffer full, cannot write message"),!1;s.setUint32(r,e.length,!0),n.set(e,r+4);const a=r+o;return s.setUint32(0,a,!0),!0}static writeBatchedData(t,e,s){const n=new DataView(t),r=new Uint8Array(t),o=n.getUint32(0,!0);if(o+e.length>t.byteLength)return console.warn(`[ArrayBufferReader] Dropping ${s?`event for subscription '${s}'`:"event"}: buffer full (${o}/${t.byteLength} bytes used, need ${e.length} more bytes). Consider increasing 'bytesPerEvent' or reducing subscription limits.`),!1;r.set(e,o);const a=o+e.length;return n.setUint32(0,a,!0),!0}static readMessages(t,e=0,s){const n=new DataView(t),r=new Uint8Array(t),o=n.getUint32(0,!0),a=4;let c=e<a?a:e;if(o<=c)return{messages:[],newReadPosition:c,hasNewData:!1};const u=128,l=new Array(u);let P=0;try{for(;c<o&&!(P>=u||c+4>o);){const v=c,B=n.getUint32(v,!0),p=v+4,g=p+B;if(g>o)break;const h=new $t(r.subarray(p,g)),E=ut.getRootAsWorkerMessage(h);l[P++]=E,c=g}return l.length=P,{messages:l,newReadPosition:c,hasNewData:P>0}}catch(v){return console.error("Failed to decode FlatBuffer data from ArrayBuffer:",v),l.length=P,{messages:l,newReadPosition:e<a?a:e,hasNewData:!1}}}static readAllMessages(t){const e=this.readMessages(t,0);return{messages:e.messages,totalMessages:e.messages.length}}static getCurrentWritePosition(t){return new DataView(t).getUint32(0,!0)}static hasNewData(t,e){const s=this.getCurrentWritePosition(t),n=Math.max(e,4);return s>n}static calculateBufferSize(t=100,e=3072){const s=t*e,n=Math.floor(s*.25);return 4+s+n}}const Zt=new TextDecoder;function Kt(i){if(typeof i=="string")return i;if(i instanceof Uint8Array)return Zt.decode(i)}function G(i){if(Array.isArray(i))return i.filter(t=>typeof t=="string");if("itemsLength"in i&&typeof i.itemsLength=="function"){const t=[];for(let e=0;e<i.itemsLength();e++){const s=Kt(i.items(e));s!==void 0&&t.push(s)}return t}return"items"in i?i.items.flatMap(t=>{const e=Kt(t);return e?[e]:[]}):[]}function Z(i,t,e){return i[0]!==t?!1:e?.where?e.where(i):!0}function At(i,t,e){if(Array.isArray(i)){for(const s of i){const n=G(s);if(Z(n,t,e))return n}return}for(let s=0;s<i.tagsLength();s++){const n=i.tags(s);if(!n)continue;const r=G(n);if(Z(r,t,e))return r}}function Jt(i,t,e=1,s){const n=typeof e=="number"?e:1;return At(i,t,typeof e=="number"?s:e)?.[n]}function Qt(i,t,e=1,s){const n=typeof e=="number"?e:1,r=typeof e=="number"?s:e,o=[];if(Array.isArray(i)){for(const a of i){const c=G(a);Z(c,t,r)&&c[n]!==void 0&&o.push(c[n])}return o}for(let a=0;a<i.tagsLength();a++){const c=i.tags(a);if(!c)continue;const u=G(c);Z(u,t,r)&&u[n]!==void 0&&o.push(u[n])}return o}function Yt(i,t){const e=new Map;if(Array.isArray(i))for(const s of i){const n=G(s);if(n.length<2)continue;const r=n[0];if(!Z(n,r,t))continue;const o=e.get(r)||[];o.push(...n.slice(1)),e.set(r,o)}else for(let s=0;s<i.tagsLength();s++){const n=i.tags(s);if(!n)continue;const r=G(n);if(r.length<2)continue;const o=r[0];if(!Z(r,o,t))continue;const a=e.get(o)||[];a.push(...r.slice(1)),e.set(o,a)}return Object.fromEntries(e)}function Vt(i,t,e,s){if(!Number.isInteger(i)||i<0||i>65535)throw new Error(`Invalid kind: ${i}`);if(!Q(t))throw new Error(`Invalid pubkey hex (expected 64 lowercase hex chars): ${t}`);if(!e||typeof e!="string")throw new Error(`Invalid d tag: ${e}`);return dt.naddrEncode({identifier:e,kind:i,pubkey:t,relays:s&&s.length?s:void 0})}function te(i,t){const e=J(i.tags);if(!e)throw new Error(`Missing "d" tag for PRE event of kind ${i.kind}`);return Vt(i.kind,i.pubkey,e,t)}function ee(i){const t=dt.decode(i);if(t.type!=="naddr")throw new Error(`Invalid naddr type: ${t.type}`);const{identifier:e,kind:s,pubkey:n,relays:r}=t.data;return{kind:s,pubkey:n,d:e,relays:r}}function Q(i){return/^[0-9a-f]{64}$/.test(i)}function xt(i){return i.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")}function ot(i=9){const t=Math.max(1,Math.min(i,64));let e;if(typeof globalThis<"u"&&globalThis.crypto?.getRandomValues)e=new Uint8Array(t),globalThis.crypto.getRandomValues(e);else{e=new Uint8Array(t);for(let s=0;s<t;s++)e[s]=Math.floor(Math.random()*256)}return(typeof Buffer<"u"?Buffer.from(e).toString("base64"):btoa(String.fromCharCode(...e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function J(i){for(const t of i)if(t[0]==="d"&&typeof t[1]=="string"&&t[1].length>0)return t[1]}function jt(i,t,e){const s=J(i);if(s)return s;if(t&&t.trim().length>0){const n=xt(t.trim());return n.length>0?n:ot(e?.randomBytes??9)}return ot(e?.randomBytes??9)}function at(i,t,e){if(!Number.isInteger(i)||i<0||i>65535)throw new Error(`Invalid kind: ${i}`);if(!Q(t))throw new Error(`Invalid pubkey hex (expected 64 lowercase hex chars): ${t}`);if(!e||typeof e!="string")throw new Error(`Invalid d tag: ${e}`);return`${i}:${t}:${e}`}function Ut(i){const t=i.split(":");if(t.length!==3)throw new Error(`Invalid a-pointer format: ${i}`);const e=Number(t[0]),s=t[1],n=t[2];if(!Number.isInteger(e))throw new Error(`Invalid kind in a-pointer: ${t[0]}`);if(!Q(s))throw new Error(`Invalid pubkey in a-pointer: ${s}`);if(!n)throw new Error(`Invalid d in a-pointer: ${n}`);return{kind:e,pubkey:s,d:n}}function se(i){const t=J(i.tags);if(!t)throw new Error(`Missing "d" tag for PRE event of kind ${i.kind}`);return at(i.kind,i.pubkey,t)}function qt(i,t,e,s){const n=at(i,t,e);if(s&&s.length>0){const r=s.map(o=>encodeURIComponent(o)).join(",");return`naddr-like:${n}?relays=${r}`}return`naddr-like:${n}`}function ie(i,t){const e=J(i.tags);if(!e)throw new Error(`Missing "d" tag for PRE event of kind ${i.kind}`);return qt(i.kind,i.pubkey,e,t)}function ne(i){if(!i.startsWith("naddr-like:"))throw new Error(`Invalid naddr-like prefix: ${i}`);const t=i.slice(11),[e,s]=t.split("?",2),n=Ut(e);if(!s)return{a:n};const r=new URLSearchParams(s).get("relays"),o=r?r.split(",").map(decodeURIComponent):void 0;return{a:n,relays:o}}function re(i){return Number.isInteger(i)&&i>=3e4&&i<4e4}function zt(i,t){const e=[];let s=!1;for(const n of i)!s&&n[0]==="d"?(e.push(["d",t]),s=!0):e.push(n);return s||e.push(["d",t]),e}function oe(i,t,e){if(J(i))return i.slice();const s=jt(i,t,e);return zt(i,s)}class Gt{constructor(t={}){this.textEncoder=new TextEncoder,this.subscriptions=new Map,this.publishes=new Map,this.activePubkey=null,this._pendingSession=null,this.signCB=g=>{},this.eventTarget=new EventTarget,this.relayStatuses=new Map,this.PERPETUAL_SUBSCRIPTIONS=["notifications","starterpack"];const e=new MessageChannel,s=new MessageChannel,n=new MessageChannel,r=new MessageChannel,o=new MessageChannel,a=new MessageChannel,c=new MessageChannel,u=new MessageChannel,l=!!t.proxy,P=l?new URL("./connections/proxy.js",import.meta.url):new URL("./connections/index.js",import.meta.url),v=new URL("./cache/index.js",import.meta.url),B=new URL("./parser/index.js",import.meta.url),p=new URL("./crypto/index.js",import.meta.url);console.log("constructing crates"),this.connections=new Worker(P,{type:"module"}),this.cache=new Worker(v,{type:"module"}),this.parser=new Worker(B,{type:"module"}),this.crypto=new Worker(p,{type:"module"}),console.log("connectionMode",l?"proxy":"rust"),console.log(this.connections,this.cache,this.parser,this.crypto),this.connections.postMessage({type:"init",payload:{mainPort:u.port2,cachePort:r.port1,parserPort:s.port1,cryptoPort:o.port1,...t.proxy?{proxy:t.proxy}:{}}},[u.port2,r.port1,s.port1,o.port1]),this.cache.postMessage({type:"init",payload:{parserPort:e.port1,connectionsPort:r.port2}},[e.port1,r.port2]),this.parserMainPort=c.port1,this.parserMainPort.onmessage=g=>{const{subId:h,data:E}=g.data;if(!h||!E){console.log("[main] ignoring message - missing subId or data");return}const z=this.subscriptions.get(h);if(z){X.writeBatchedData(z.buffer,E,h)&&this.dispatch(`subscription:${h}`,h);return}const bt=this.publishes.get(h);if(bt){X.writeBatchedData(bt.buffer,E,h)&&this.dispatch(`publish:${h}`,h);return}console.log("[main] no subscription or publish found for subId:",h)},this.connectionsMainPort=u.port1,this.connectionsMainPort.onmessage=g=>{const{type:h,status:E,url:z}=JSON.parse(g.data);h==="relay:status"&&z&&E?(this.relayStatuses.set(z,{status:E,timestamp:Date.now()}),this.dispatch("relay:status",{status:E,url:z})):console.log("[main] ignoring message - type:",h,"url:",z,"status:",E)},this.parser.postMessage({type:"init",payload:{connectionsPort:s.port2,cachePort:e.port2,cryptoPort:n.port1,mainPort:c.port2}},[s.port2,e.port2,n.port1,c.port2]),this.crypto.postMessage({type:"init",payload:{parserPort:n.port2,connectionsPort:o.port2,mainPort:a.port1}},[n.port2,o.port2,a.port1]),a.port2.onmessage=g=>{const h=g.data;h.type==="response"&&this.handleCryptoResponse(h)},this.setupWorkerListener(),queueMicrotask(()=>this.restoreSession())}postToWorker(t,e){e&&e.length?this.parser.postMessage(t,e):this.parser.postMessage(t)}handleCryptoResponse(t){if(t.op==="get_pubkey"){console.log("[main] get_pubkey:",t.ok?"success":"failed",t.result),t.ok&&(this.activePubkey=t.result,this._discoveredBunkerUrl&&this._pendingSession?.type==="nip46_qr"&&this._pendingSession?.payload?.clientSecret?(console.log("[main] Converting QR to bunker for pubkey:",this.activePubkey),this.saveSession(this.activePubkey,"nip46_bunker",{url:this._discoveredBunkerUrl,clientSecret:this._pendingSession.payload.clientSecret}),this._pendingSession=null,this._discoveredBunkerUrl=null):this._pendingSession&&(this.saveSession(this.activePubkey,this._pendingSession.type,this._pendingSession.payload),this._pendingSession=null));const e=t.ok&&!!this._pendingSession,s=this._pendingSession?.type==="privkey"?this._pendingSession.payload:void 0;this.dispatch("auth",{pubkey:this.activePubkey,hasSigner:e,secretKey:s})}else if(t.op==="sign_event"&&t.ok){const e=JSON.parse(t.result);this.signCB(e)}}setupWorkerListener(){this.parser.onmessage=async t=>{const e=typeof t.data=="string"?t.data:void 0;if(e){if(this.subscriptions.has(e)){this.dispatch(`subscription:${e}`,e);return}if(this.publishes.has(e)){this.dispatch(`publish:${e}`,e);return}}},this.crypto.onmessage=async t=>{const e=t.data;if(console.log("[main] crypto.onmessage:",e?.type,e),e?.type==="signer_ready"){console.log("[main] signer_ready:",e.signer_type,e.pubkey),this.activePubkey=e.pubkey,e.signer_type==="nip46"&&e.bunker_url&&this._pendingSession?.payload?.clientSecret&&(console.log("[main] NIP-46 session saved for:",e.pubkey),this.saveSession(e.pubkey,"nip46",{url:e.bunker_url,clientSecret:this._pendingSession.payload.clientSecret}),this._pendingSession=null);const s=this._pendingSession?.type==="privkey"?this._pendingSession.payload:void 0;this._pendingSession&&(this.saveSession(e.pubkey,e.signer_type,this._pendingSession.payload),this._pendingSession=null),this.dispatch("auth",{pubkey:e.pubkey,hasSigner:!0,secretKey:s});return}if(e?.type==="response"){this.handleCryptoResponse(e);return}if(e?.type==="extension_request"){const{id:s,op:n,payload:r}=e;try{const o=window.nostr;if(!o)throw new Error("NIP-07 extension (window.nostr) not found");let a;switch(n){case"getPublicKey":a=await o.getPublicKey();break;case"signEvent":a=await o.signEvent(JSON.parse(r));break;case"nip04Encrypt":a=await o.nip04.encrypt(r.pubkey,r.plaintext);break;case"nip04Decrypt":a=await o.nip04.decrypt(r.pubkey,r.ciphertext);break;case"nip44Encrypt":a=await o.nip44.encrypt(r.pubkey,r.plaintext);break;case"nip44Decrypt":a=await o.nip44.decrypt(r.pubkey,r.ciphertext);break;default:throw new Error(`Unknown extension operation: ${n}`)}this.crypto.postMessage({type:"extension_response",id:s,ok:!0,result:a})}catch(o){this.crypto.postMessage({type:"extension_response",id:s,ok:!1,error:o.message||String(o)})}return}}}createShortId(t){if(t.length<64)return t;let e=0;for(let s=0;s<t.length;s++){const n=t.charCodeAt(s);e=(e<<5)-e+n,e=e&e}return Math.abs(e).toString(36).substring(0,63)}addEventListener(t,e,s){this.eventTarget.addEventListener(t,e,s)}removeEventListener(t,e,s){this.eventTarget.removeEventListener(t,e,s)}dispatch(t,e){this.eventTarget.dispatchEvent(new CustomEvent(t,{detail:e}))}subscribe(t,e,s){const n=this.createShortId(t),r=this.subscriptions.get(n);if(r)return r.refCount++,r.buffer;const o=e.reduce((p,g)=>p+(g.limit||100),0),a=X.calculateBufferSize(o,s.bytesPerEvent),c=new ArrayBuffer(a);X.initializeBuffer(c),this.subscriptions.set(n,{buffer:c,options:s,refCount:1});const u=new it(new st(s.pipeline||[]),s.closeOnEose,s.cacheFirst,s.timeoutMs?BigInt(s.timeoutMs):void 0,s.maxEvents,s.skipCache,s.force,s.bytesPerEvent,s.isSlow,s.pagination?this.textEncoder.encode(s.pagination):null),l=new nt(this.textEncoder.encode(n),e.map(p=>new Xt(p.ids,p.authors,p.kinds,Object.entries(p.tags||{}).flatMap(([g,h])=>new pt([g,...h])),p.limit,p.since,p.until,this.textEncoder.encode(p.search),p.relays,p.closeOnEOSE,p.cacheFirst,p.noCache)),u),P=new W(C.Subscribe,l),v=new b.Builder(2048);v.finish(P.pack(v));const B=v.asUint8Array();return this.postToWorker({serializedMessage:B},[B.buffer]),c}getBuffer(t){const e=this.subscriptions.get(t);if(e)return e.refCount++,e.buffer}getRelayStatuses(){return new Map(this.relayStatuses)}unsubscribe(t){const e=t.length<64?t:this.createShortId(t),s=this.subscriptions.get(e);s&&s.refCount--}publish(t,e,s=[]){const n=new ArrayBuffer(3072);X.initializeBuffer(n);const r=new tt(e.kind,e.created_at,this.textEncoder.encode(e.content),e.tags.map(l=>new pt(l))||[]),o=new et(this.textEncoder.encode(t),r,s),a=new W(C.Publish,o),c=new b.Builder(2048);c.finish(a.pack(c));const u=c.asUint8Array();return this.postToWorker({serializedMessage:u},[u.buffer]),this.publishes.set(t,{buffer:n}),n}setSigner(t,e){switch(this._pendingSession={type:t,payload:e},console.log("[main] set pending session:",t),t){case"pubkey":this.activePubkey=e,this.saveSession(this.activePubkey,"pubkey",e),this._pendingSession=null,this.dispatch("auth",{pubkey:this.activePubkey,hasSigner:!1});break;case"privkey":this.crypto.postMessage({type:"set_private_key",payload:e});break;case"nip07":this.crypto.postMessage({type:"set_nip07"});break;case"nip46":e?.url?.startsWith("bunker://")?this.crypto.postMessage({type:"set_nip46_bunker",payload:e}):e?.url?.startsWith("nostrconnect://")?this.crypto.postMessage({type:"set_nip46_qr",payload:e}):console.error("[main] Unknown NIP-46 URL format:",e?.url);break}}signEvent(t,e){this.signCB=e,this.crypto.postMessage({type:"sign_event",payload:JSON.stringify(t)})}getPublicKey(){const t=new W(C.GetPublicKey,new Y),e=new b.Builder(2048);e.finish(t.pack(e));const s=e.asUint8Array();this.parser.postMessage({serializedMessage:s},[s.buffer])}generateClientSecret(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}setNip46Bunker(t,e){const s=e||this.generateClientSecret();console.log("[main] NIP-46 bunker:",t.slice(0,50)+"..."),this.setSigner("nip46",{url:t,clientSecret:s})}setNip46QR(t,e){const s=e||this.generateClientSecret();console.log("[main] NIP-46 QR:",t.slice(0,50)+"..."),this.setSigner("nip46",{url:t,clientSecret:s})}setNip07(){this.setSigner("nip07","")}setPubkey(t){this.setSigner("pubkey",t)}getActivePubkey(){return this.activePubkey}getSubscriptionCount(){return this.subscriptions.size}getAccounts(){const t=localStorage.getItem("nostr_signer_accounts")||"{}";try{return JSON.parse(t)}catch{return{}}}switchAccount(t){const e=this.getAccounts()[t];e&&this.setSigner(e.type,e.payload)}saveSession(t,e,s){console.log("[main] saveSession:",{pubkey:t.slice(0,16)+"...",type:e,hasClientSecret:!!s?.clientSecret});const n=this.getAccounts();n[t]={type:e,payload:s},localStorage.setItem("nostr_signer_accounts",JSON.stringify(n)),localStorage.setItem("nostr_active_pubkey",t),console.log("[main] Session saved to localStorage")}restoreSession(){const t=localStorage.getItem("nostr_active_pubkey");t?this.switchAccount(t):this.dispatch("auth",{pubkey:null,hasSigner:!1})}logout(){this._pendingSession=null,this.activePubkey=null,this.crypto.postMessage({type:"clear_signer"}),localStorage.removeItem("nostr_active_pubkey"),this.dispatch("logout")}removeAccount(){const t=this.activePubkey;if(!t)return;const e=this.getAccounts();delete e[t],localStorage.setItem("nostr_signer_accounts",JSON.stringify(e));const s=Object.keys(e);if(s.length>0){const n=s[0];n&&this.switchAccount(n)}else this.logout()}cleanup(){const t=[];for(const[e,s]of this.subscriptions.entries())s.refCount<=0&&!this.PERPETUAL_SUBSCRIPTIONS.includes(e)&&t.push(e);for(const e of t){const s=new rt(this.textEncoder.encode(e)),n=new W(C.Unsubscribe,s),r=new b.Builder(256);r.finish(n.pack(r));const o=r.asUint8Array();this.postToWorker({serializedMessage:o},[o.buffer]),this.connections.postMessage(e),this.subscriptions.delete(e)}}}function ae(i){return new Gt(i)}let ct=null;function ce(){if(!ct)throw new Error("[nipworker] Global manager is not set. Call setManager(createNostrManager(...)) before using hooks.");return ct}function Bt(i){ct=i}function be(i){Bt(i)}export{D as $,X as A,R as B,$ as C,gt as D,_ as E,lt as F,m as G,_t as H,I,yt as J,j as K,Y as L,F as M,Gt as N,Pt as O,C as P,N as Q,W as R,f as S,vt as T,S as U,Et as V,U as W,Ct as X,Nt as Y,T as Z,Lt as _,be as a,L as a0,st as a1,M as a2,kt as a3,A as a4,mt as a5,k as a6,et as a7,q as a8,Ot as a9,V as aa,Tt as ab,O as ac,St as ad,K as ae,It as af,H as ag,w as ah,nt as ai,Mt as aj,d as ak,it as al,y as am,tt as an,x as ao,rt as ap,Jt as b,ae as c,Qt as d,At as e,Yt as f,ce as g,te as h,Q as i,ot as j,J as k,jt as l,Vt as m,xt as n,at as o,ee as p,Ut as q,G as r,Bt as s,se as t,qt as u,ie as v,ne as w,re as x,zt as y,oe as z};
1
+ import * as h from "flatbuffers";
2
+ import { ByteBuffer as St } from "flatbuffers";
3
+ import { a0 as ut, N as Et, P as vt, W as dt, S as mt, a1 as Tt, a2 as nt } from "./worker-message.js";
4
+ import { nip19 as ft } from "nostr-tools";
5
+ class g {
6
+ constructor() {
7
+ this.bb = null, this.bb_pos = 0;
8
+ }
9
+ __init(t, s) {
10
+ return this.bb_pos = t, this.bb = s, this;
11
+ }
12
+ static getRootAsCacheRequest(t, s) {
13
+ return (s || new g()).__init(t.readInt32(t.position()) + t.position(), t);
14
+ }
15
+ static getSizePrefixedRootAsCacheRequest(t, s) {
16
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new g()).__init(t.readInt32(t.position()) + t.position(), t);
17
+ }
18
+ subId(t) {
19
+ const s = this.bb.__offset(this.bb_pos, 4);
20
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
21
+ }
22
+ requests(t, s) {
23
+ const i = this.bb.__offset(this.bb_pos, 6);
24
+ return i ? (s || new ut()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + i) + t * 4), this.bb) : null;
25
+ }
26
+ requestsLength() {
27
+ const t = this.bb.__offset(this.bb_pos, 6);
28
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
29
+ }
30
+ event(t) {
31
+ const s = this.bb.__offset(this.bb_pos, 8);
32
+ return s ? (t || new Et()).__init(this.bb.__indirect(this.bb_pos + s), this.bb) : null;
33
+ }
34
+ parsedEvent(t) {
35
+ const s = this.bb.__offset(this.bb_pos, 10);
36
+ return s ? (t || new vt()).__init(this.bb.__indirect(this.bb_pos + s), this.bb) : null;
37
+ }
38
+ relays(t, s) {
39
+ const i = this.bb.__offset(this.bb_pos, 12);
40
+ return i ? this.bb.__string(this.bb.__vector(this.bb_pos + i) + t * 4, s) : null;
41
+ }
42
+ relaysLength() {
43
+ const t = this.bb.__offset(this.bb_pos, 12);
44
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
45
+ }
46
+ static startCacheRequest(t) {
47
+ t.startObject(5);
48
+ }
49
+ static addSubId(t, s) {
50
+ t.addFieldOffset(0, s, 0);
51
+ }
52
+ static addRequests(t, s) {
53
+ t.addFieldOffset(1, s, 0);
54
+ }
55
+ static createRequestsVector(t, s) {
56
+ t.startVector(4, s.length, 4);
57
+ for (let i = s.length - 1; i >= 0; i--)
58
+ t.addOffset(s[i]);
59
+ return t.endVector();
60
+ }
61
+ static startRequestsVector(t, s) {
62
+ t.startVector(4, s, 4);
63
+ }
64
+ static addEvent(t, s) {
65
+ t.addFieldOffset(2, s, 0);
66
+ }
67
+ static addParsedEvent(t, s) {
68
+ t.addFieldOffset(3, s, 0);
69
+ }
70
+ static addRelays(t, s) {
71
+ t.addFieldOffset(4, s, 0);
72
+ }
73
+ static createRelaysVector(t, s) {
74
+ t.startVector(4, s.length, 4);
75
+ for (let i = s.length - 1; i >= 0; i--)
76
+ t.addOffset(s[i]);
77
+ return t.endVector();
78
+ }
79
+ static startRelaysVector(t, s) {
80
+ t.startVector(4, s, 4);
81
+ }
82
+ static endCacheRequest(t) {
83
+ const s = t.endObject();
84
+ return t.requiredField(s, 4), s;
85
+ }
86
+ unpack() {
87
+ return new Ot(
88
+ this.subId(),
89
+ this.bb.createObjList(this.requests.bind(this), this.requestsLength()),
90
+ this.event() !== null ? this.event().unpack() : null,
91
+ this.parsedEvent() !== null ? this.parsedEvent().unpack() : null,
92
+ this.bb.createScalarList(this.relays.bind(this), this.relaysLength())
93
+ );
94
+ }
95
+ unpackTo(t) {
96
+ t.subId = this.subId(), t.requests = this.bb.createObjList(this.requests.bind(this), this.requestsLength()), t.event = this.event() !== null ? this.event().unpack() : null, t.parsedEvent = this.parsedEvent() !== null ? this.parsedEvent().unpack() : null, t.relays = this.bb.createScalarList(this.relays.bind(this), this.relaysLength());
97
+ }
98
+ }
99
+ class Ot {
100
+ constructor(t = null, s = [], i = null, n = null, r = []) {
101
+ this.subId = t, this.requests = s, this.event = i, this.parsedEvent = n, this.relays = r;
102
+ }
103
+ pack(t) {
104
+ const s = this.subId !== null ? t.createString(this.subId) : 0, i = g.createRequestsVector(t, t.createObjectOffsetList(this.requests)), n = this.event !== null ? this.event.pack(t) : 0, r = this.parsedEvent !== null ? this.parsedEvent.pack(t) : 0, o = g.createRelaysVector(t, t.createObjectOffsetList(this.relays));
105
+ return g.startCacheRequest(t), g.addSubId(t, s), g.addRequests(t, i), g.addEvent(t, n), g.addParsedEvent(t, r), g.addRelays(t, o), g.endCacheRequest(t);
106
+ }
107
+ }
108
+ var J = /* @__PURE__ */ ((e) => (e[e.NONE = 0] = "NONE", e[e.WorkerMessage = 1] = "WorkerMessage", e[e.CacheRequest = 2] = "CacheRequest", e))(J || {});
109
+ function rt(e, t) {
110
+ switch (J[e]) {
111
+ case "NONE":
112
+ return null;
113
+ case "WorkerMessage":
114
+ return t(new dt());
115
+ case "CacheRequest":
116
+ return t(new g());
117
+ default:
118
+ return null;
119
+ }
120
+ }
121
+ class A {
122
+ constructor() {
123
+ this.bb = null, this.bb_pos = 0;
124
+ }
125
+ __init(t, s) {
126
+ return this.bb_pos = t, this.bb = s, this;
127
+ }
128
+ static getRootAsCacheInputMessage(t, s) {
129
+ return (s || new A()).__init(t.readInt32(t.position()) + t.position(), t);
130
+ }
131
+ static getSizePrefixedRootAsCacheInputMessage(t, s) {
132
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new A()).__init(t.readInt32(t.position()) + t.position(), t);
133
+ }
134
+ contentType() {
135
+ const t = this.bb.__offset(this.bb_pos, 4);
136
+ return t ? this.bb.readUint8(this.bb_pos + t) : J.NONE;
137
+ }
138
+ content(t) {
139
+ const s = this.bb.__offset(this.bb_pos, 6);
140
+ return s ? this.bb.__union(t, this.bb_pos + s) : null;
141
+ }
142
+ static startCacheInputMessage(t) {
143
+ t.startObject(2);
144
+ }
145
+ static addContentType(t, s) {
146
+ t.addFieldInt8(0, s, J.NONE);
147
+ }
148
+ static addContent(t, s) {
149
+ t.addFieldOffset(1, s, 0);
150
+ }
151
+ static endCacheInputMessage(t) {
152
+ const s = t.endObject();
153
+ return t.requiredField(s, 6), s;
154
+ }
155
+ static createCacheInputMessage(t, s, i) {
156
+ return A.startCacheInputMessage(t), A.addContentType(t, s), A.addContent(t, i), A.endCacheInputMessage(t);
157
+ }
158
+ unpack() {
159
+ return new Rt(
160
+ this.contentType(),
161
+ (() => {
162
+ const t = rt(this.contentType(), this.content.bind(this));
163
+ return t === null ? null : t.unpack();
164
+ })()
165
+ );
166
+ }
167
+ unpackTo(t) {
168
+ t.contentType = this.contentType(), t.content = (() => {
169
+ const s = rt(this.contentType(), this.content.bind(this));
170
+ return s === null ? null : s.unpack();
171
+ })();
172
+ }
173
+ }
174
+ class Rt {
175
+ constructor(t = J.NONE, s = null) {
176
+ this.contentType = t, this.content = s;
177
+ }
178
+ pack(t) {
179
+ const s = t.createObjectOffset(this.content);
180
+ return A.createCacheInputMessage(
181
+ t,
182
+ this.contentType,
183
+ s
184
+ );
185
+ }
186
+ }
187
+ class O {
188
+ constructor() {
189
+ this.bb = null, this.bb_pos = 0;
190
+ }
191
+ __init(t, s) {
192
+ return this.bb_pos = t, this.bb = s, this;
193
+ }
194
+ static getRootAsCacheResponse(t, s) {
195
+ return (s || new O()).__init(t.readInt32(t.position()) + t.position(), t);
196
+ }
197
+ static getSizePrefixedRootAsCacheResponse(t, s) {
198
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new O()).__init(t.readInt32(t.position()) + t.position(), t);
199
+ }
200
+ subId(t) {
201
+ const s = this.bb.__offset(this.bb_pos, 4);
202
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
203
+ }
204
+ payload(t) {
205
+ const s = this.bb.__offset(this.bb_pos, 6);
206
+ return s ? this.bb.readUint8(this.bb.__vector(this.bb_pos + s) + t) : 0;
207
+ }
208
+ payloadLength() {
209
+ const t = this.bb.__offset(this.bb_pos, 6);
210
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
211
+ }
212
+ payloadArray() {
213
+ const t = this.bb.__offset(this.bb_pos, 6);
214
+ return t ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + t), this.bb.__vector_len(this.bb_pos + t)) : null;
215
+ }
216
+ static startCacheResponse(t) {
217
+ t.startObject(2);
218
+ }
219
+ static addSubId(t, s) {
220
+ t.addFieldOffset(0, s, 0);
221
+ }
222
+ static addPayload(t, s) {
223
+ t.addFieldOffset(1, s, 0);
224
+ }
225
+ static createPayloadVector(t, s) {
226
+ t.startVector(1, s.length, 1);
227
+ for (let i = s.length - 1; i >= 0; i--)
228
+ t.addInt8(s[i]);
229
+ return t.endVector();
230
+ }
231
+ static startPayloadVector(t, s) {
232
+ t.startVector(1, s, 1);
233
+ }
234
+ static endCacheResponse(t) {
235
+ const s = t.endObject();
236
+ return t.requiredField(s, 4), s;
237
+ }
238
+ static createCacheResponse(t, s, i) {
239
+ return O.startCacheResponse(t), O.addSubId(t, s), O.addPayload(t, i), O.endCacheResponse(t);
240
+ }
241
+ unpack() {
242
+ return new Nt(
243
+ this.subId(),
244
+ this.bb.createScalarList(this.payload.bind(this), this.payloadLength())
245
+ );
246
+ }
247
+ unpackTo(t) {
248
+ t.subId = this.subId(), t.payload = this.bb.createScalarList(this.payload.bind(this), this.payloadLength());
249
+ }
250
+ }
251
+ class Nt {
252
+ constructor(t = null, s = []) {
253
+ this.subId = t, this.payload = s;
254
+ }
255
+ pack(t) {
256
+ const s = this.subId !== null ? t.createString(this.subId) : 0, i = O.createPayloadVector(t, this.payload);
257
+ return O.createCacheResponse(
258
+ t,
259
+ s,
260
+ i
261
+ );
262
+ }
263
+ }
264
+ class E {
265
+ constructor() {
266
+ this.bb = null, this.bb_pos = 0;
267
+ }
268
+ __init(t, s) {
269
+ return this.bb_pos = t, this.bb = s, this;
270
+ }
271
+ static getRootAsCounterPipeConfig(t, s) {
272
+ return (s || new E()).__init(t.readInt32(t.position()) + t.position(), t);
273
+ }
274
+ static getSizePrefixedRootAsCounterPipeConfig(t, s) {
275
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new E()).__init(t.readInt32(t.position()) + t.position(), t);
276
+ }
277
+ kinds(t) {
278
+ const s = this.bb.__offset(this.bb_pos, 4);
279
+ return s ? this.bb.readUint16(this.bb.__vector(this.bb_pos + s) + t * 2) : 0;
280
+ }
281
+ kindsLength() {
282
+ const t = this.bb.__offset(this.bb_pos, 4);
283
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
284
+ }
285
+ kindsArray() {
286
+ const t = this.bb.__offset(this.bb_pos, 4);
287
+ return t ? new Uint16Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + t), this.bb.__vector_len(this.bb_pos + t)) : null;
288
+ }
289
+ pubkey(t) {
290
+ const s = this.bb.__offset(this.bb_pos, 6);
291
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
292
+ }
293
+ static startCounterPipeConfig(t) {
294
+ t.startObject(2);
295
+ }
296
+ static addKinds(t, s) {
297
+ t.addFieldOffset(0, s, 0);
298
+ }
299
+ static createKindsVector(t, s) {
300
+ t.startVector(2, s.length, 2);
301
+ for (let i = s.length - 1; i >= 0; i--)
302
+ t.addInt16(s[i]);
303
+ return t.endVector();
304
+ }
305
+ static startKindsVector(t, s) {
306
+ t.startVector(2, s, 2);
307
+ }
308
+ static addPubkey(t, s) {
309
+ t.addFieldOffset(1, s, 0);
310
+ }
311
+ static endCounterPipeConfig(t) {
312
+ const s = t.endObject();
313
+ return t.requiredField(s, 4), t.requiredField(s, 6), s;
314
+ }
315
+ static createCounterPipeConfig(t, s, i) {
316
+ return E.startCounterPipeConfig(t), E.addKinds(t, s), E.addPubkey(t, i), E.endCounterPipeConfig(t);
317
+ }
318
+ unpack() {
319
+ return new Ft(
320
+ this.bb.createScalarList(this.kinds.bind(this), this.kindsLength()),
321
+ this.pubkey()
322
+ );
323
+ }
324
+ unpackTo(t) {
325
+ t.kinds = this.bb.createScalarList(this.kinds.bind(this), this.kindsLength()), t.pubkey = this.pubkey();
326
+ }
327
+ }
328
+ class Ft {
329
+ constructor(t = [], s = null) {
330
+ this.kinds = t, this.pubkey = s;
331
+ }
332
+ pack(t) {
333
+ const s = E.createKindsVector(t, this.kinds), i = this.pubkey !== null ? t.createString(this.pubkey) : 0;
334
+ return E.createCounterPipeConfig(
335
+ t,
336
+ s,
337
+ i
338
+ );
339
+ }
340
+ }
341
+ class z {
342
+ constructor() {
343
+ this.bb = null, this.bb_pos = 0;
344
+ }
345
+ __init(t, s) {
346
+ return this.bb_pos = t, this.bb = s, this;
347
+ }
348
+ static getRootAsGetPublicKey(t, s) {
349
+ return (s || new z()).__init(t.readInt32(t.position()) + t.position(), t);
350
+ }
351
+ static getSizePrefixedRootAsGetPublicKey(t, s) {
352
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new z()).__init(t.readInt32(t.position()) + t.position(), t);
353
+ }
354
+ static startGetPublicKey(t) {
355
+ t.startObject(0);
356
+ }
357
+ static endGetPublicKey(t) {
358
+ return t.endObject();
359
+ }
360
+ static createGetPublicKey(t) {
361
+ return z.startGetPublicKey(t), z.endGetPublicKey(t);
362
+ }
363
+ unpack() {
364
+ return new lt();
365
+ }
366
+ unpackTo(t) {
367
+ }
368
+ }
369
+ class lt {
370
+ constructor() {
371
+ }
372
+ pack(t) {
373
+ return z.createGetPublicKey(t);
374
+ }
375
+ }
376
+ class F {
377
+ constructor() {
378
+ this.bb = null, this.bb_pos = 0;
379
+ }
380
+ __init(t, s) {
381
+ return this.bb_pos = t, this.bb = s, this;
382
+ }
383
+ static getRootAsKindFilterPipeConfig(t, s) {
384
+ return (s || new F()).__init(t.readInt32(t.position()) + t.position(), t);
385
+ }
386
+ static getSizePrefixedRootAsKindFilterPipeConfig(t, s) {
387
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new F()).__init(t.readInt32(t.position()) + t.position(), t);
388
+ }
389
+ kinds(t) {
390
+ const s = this.bb.__offset(this.bb_pos, 4);
391
+ return s ? this.bb.readUint16(this.bb.__vector(this.bb_pos + s) + t * 2) : 0;
392
+ }
393
+ kindsLength() {
394
+ const t = this.bb.__offset(this.bb_pos, 4);
395
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
396
+ }
397
+ kindsArray() {
398
+ const t = this.bb.__offset(this.bb_pos, 4);
399
+ return t ? new Uint16Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + t), this.bb.__vector_len(this.bb_pos + t)) : null;
400
+ }
401
+ static startKindFilterPipeConfig(t) {
402
+ t.startObject(1);
403
+ }
404
+ static addKinds(t, s) {
405
+ t.addFieldOffset(0, s, 0);
406
+ }
407
+ static createKindsVector(t, s) {
408
+ t.startVector(2, s.length, 2);
409
+ for (let i = s.length - 1; i >= 0; i--)
410
+ t.addInt16(s[i]);
411
+ return t.endVector();
412
+ }
413
+ static startKindsVector(t, s) {
414
+ t.startVector(2, s, 2);
415
+ }
416
+ static endKindFilterPipeConfig(t) {
417
+ const s = t.endObject();
418
+ return t.requiredField(s, 4), s;
419
+ }
420
+ static createKindFilterPipeConfig(t, s) {
421
+ return F.startKindFilterPipeConfig(t), F.addKinds(t, s), F.endKindFilterPipeConfig(t);
422
+ }
423
+ unpack() {
424
+ return new Lt(
425
+ this.bb.createScalarList(this.kinds.bind(this), this.kindsLength())
426
+ );
427
+ }
428
+ unpackTo(t) {
429
+ t.kinds = this.bb.createScalarList(this.kinds.bind(this), this.kindsLength());
430
+ }
431
+ }
432
+ class Lt {
433
+ constructor(t = []) {
434
+ this.kinds = t;
435
+ }
436
+ pack(t) {
437
+ const s = F.createKindsVector(t, this.kinds);
438
+ return F.createKindFilterPipeConfig(
439
+ t,
440
+ s
441
+ );
442
+ }
443
+ }
444
+ class y {
445
+ constructor() {
446
+ this.bb = null, this.bb_pos = 0;
447
+ }
448
+ __init(t, s) {
449
+ return this.bb_pos = t, this.bb = s, this;
450
+ }
451
+ static getRootAsTemplate(t, s) {
452
+ return (s || new y()).__init(t.readInt32(t.position()) + t.position(), t);
453
+ }
454
+ static getSizePrefixedRootAsTemplate(t, s) {
455
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new y()).__init(t.readInt32(t.position()) + t.position(), t);
456
+ }
457
+ kind() {
458
+ const t = this.bb.__offset(this.bb_pos, 4);
459
+ return t ? this.bb.readUint16(this.bb_pos + t) : 0;
460
+ }
461
+ createdAt() {
462
+ const t = this.bb.__offset(this.bb_pos, 6);
463
+ return t ? this.bb.readInt32(this.bb_pos + t) : 0;
464
+ }
465
+ content(t) {
466
+ const s = this.bb.__offset(this.bb_pos, 8);
467
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
468
+ }
469
+ tags(t, s) {
470
+ const i = this.bb.__offset(this.bb_pos, 10);
471
+ return i ? (s || new mt()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + i) + t * 4), this.bb) : null;
472
+ }
473
+ tagsLength() {
474
+ const t = this.bb.__offset(this.bb_pos, 10);
475
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
476
+ }
477
+ static startTemplate(t) {
478
+ t.startObject(4);
479
+ }
480
+ static addKind(t, s) {
481
+ t.addFieldInt16(0, s, 0);
482
+ }
483
+ static addCreatedAt(t, s) {
484
+ t.addFieldInt32(1, s, 0);
485
+ }
486
+ static addContent(t, s) {
487
+ t.addFieldOffset(2, s, 0);
488
+ }
489
+ static addTags(t, s) {
490
+ t.addFieldOffset(3, s, 0);
491
+ }
492
+ static createTagsVector(t, s) {
493
+ t.startVector(4, s.length, 4);
494
+ for (let i = s.length - 1; i >= 0; i--)
495
+ t.addOffset(s[i]);
496
+ return t.endVector();
497
+ }
498
+ static startTagsVector(t, s) {
499
+ t.startVector(4, s, 4);
500
+ }
501
+ static endTemplate(t) {
502
+ const s = t.endObject();
503
+ return t.requiredField(s, 8), t.requiredField(s, 10), s;
504
+ }
505
+ static createTemplate(t, s, i, n, r) {
506
+ return y.startTemplate(t), y.addKind(t, s), y.addCreatedAt(t, i), y.addContent(t, n), y.addTags(t, r), y.endTemplate(t);
507
+ }
508
+ unpack() {
509
+ return new bt(
510
+ this.kind(),
511
+ this.createdAt(),
512
+ this.content(),
513
+ this.bb.createObjList(this.tags.bind(this), this.tagsLength())
514
+ );
515
+ }
516
+ unpackTo(t) {
517
+ t.kind = this.kind(), t.createdAt = this.createdAt(), t.content = this.content(), t.tags = this.bb.createObjList(this.tags.bind(this), this.tagsLength());
518
+ }
519
+ }
520
+ class bt {
521
+ constructor(t = 0, s = 0, i = null, n = []) {
522
+ this.kind = t, this.createdAt = s, this.content = i, this.tags = n;
523
+ }
524
+ pack(t) {
525
+ const s = this.content !== null ? t.createString(this.content) : 0, i = y.createTagsVector(t, t.createObjectOffsetList(this.tags));
526
+ return y.createTemplate(
527
+ t,
528
+ this.kind,
529
+ this.createdAt,
530
+ s,
531
+ i
532
+ );
533
+ }
534
+ }
535
+ class v {
536
+ constructor() {
537
+ this.bb = null, this.bb_pos = 0;
538
+ }
539
+ __init(t, s) {
540
+ return this.bb_pos = t, this.bb = s, this;
541
+ }
542
+ static getRootAsPublish(t, s) {
543
+ return (s || new v()).__init(t.readInt32(t.position()) + t.position(), t);
544
+ }
545
+ static getSizePrefixedRootAsPublish(t, s) {
546
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new v()).__init(t.readInt32(t.position()) + t.position(), t);
547
+ }
548
+ publishId(t) {
549
+ const s = this.bb.__offset(this.bb_pos, 4);
550
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
551
+ }
552
+ template(t) {
553
+ const s = this.bb.__offset(this.bb_pos, 6);
554
+ return s ? (t || new y()).__init(this.bb.__indirect(this.bb_pos + s), this.bb) : null;
555
+ }
556
+ relays(t, s) {
557
+ const i = this.bb.__offset(this.bb_pos, 8);
558
+ return i ? this.bb.__string(this.bb.__vector(this.bb_pos + i) + t * 4, s) : null;
559
+ }
560
+ relaysLength() {
561
+ const t = this.bb.__offset(this.bb_pos, 8);
562
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
563
+ }
564
+ static startPublish(t) {
565
+ t.startObject(3);
566
+ }
567
+ static addPublishId(t, s) {
568
+ t.addFieldOffset(0, s, 0);
569
+ }
570
+ static addTemplate(t, s) {
571
+ t.addFieldOffset(1, s, 0);
572
+ }
573
+ static addRelays(t, s) {
574
+ t.addFieldOffset(2, s, 0);
575
+ }
576
+ static createRelaysVector(t, s) {
577
+ t.startVector(4, s.length, 4);
578
+ for (let i = s.length - 1; i >= 0; i--)
579
+ t.addOffset(s[i]);
580
+ return t.endVector();
581
+ }
582
+ static startRelaysVector(t, s) {
583
+ t.startVector(4, s, 4);
584
+ }
585
+ static endPublish(t) {
586
+ const s = t.endObject();
587
+ return t.requiredField(s, 4), t.requiredField(s, 6), t.requiredField(s, 8), s;
588
+ }
589
+ unpack() {
590
+ return new _t(
591
+ this.publishId(),
592
+ this.template() !== null ? this.template().unpack() : null,
593
+ this.bb.createScalarList(this.relays.bind(this), this.relaysLength())
594
+ );
595
+ }
596
+ unpackTo(t) {
597
+ t.publishId = this.publishId(), t.template = this.template() !== null ? this.template().unpack() : null, t.relays = this.bb.createScalarList(this.relays.bind(this), this.relaysLength());
598
+ }
599
+ }
600
+ class _t {
601
+ constructor(t = null, s = null, i = []) {
602
+ this.publishId = t, this.template = s, this.relays = i;
603
+ }
604
+ pack(t) {
605
+ const s = this.publishId !== null ? t.createString(this.publishId) : 0, i = this.template !== null ? this.template.pack(t) : 0, n = v.createRelaysVector(t, t.createObjectOffsetList(this.relays));
606
+ return v.startPublish(t), v.addPublishId(t, s), v.addTemplate(t, i), v.addRelays(t, n), v.endPublish(t);
607
+ }
608
+ }
609
+ class x {
610
+ constructor() {
611
+ this.bb = null, this.bb_pos = 0;
612
+ }
613
+ __init(t, s) {
614
+ return this.bb_pos = t, this.bb = s, this;
615
+ }
616
+ static getRootAsPrivateKey(t, s) {
617
+ return (s || new x()).__init(t.readInt32(t.position()) + t.position(), t);
618
+ }
619
+ static getSizePrefixedRootAsPrivateKey(t, s) {
620
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new x()).__init(t.readInt32(t.position()) + t.position(), t);
621
+ }
622
+ privateKey(t) {
623
+ const s = this.bb.__offset(this.bb_pos, 4);
624
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
625
+ }
626
+ static startPrivateKey(t) {
627
+ t.startObject(1);
628
+ }
629
+ static addPrivateKey(t, s) {
630
+ t.addFieldOffset(0, s, 0);
631
+ }
632
+ static endPrivateKey(t) {
633
+ const s = t.endObject();
634
+ return t.requiredField(s, 4), s;
635
+ }
636
+ static createPrivateKey(t, s) {
637
+ return x.startPrivateKey(t), x.addPrivateKey(t, s), x.endPrivateKey(t);
638
+ }
639
+ unpack() {
640
+ return new Ct(
641
+ this.privateKey()
642
+ );
643
+ }
644
+ unpackTo(t) {
645
+ t.privateKey = this.privateKey();
646
+ }
647
+ }
648
+ class Ct {
649
+ constructor(t = null) {
650
+ this.privateKey = t;
651
+ }
652
+ pack(t) {
653
+ const s = this.privateKey !== null ? t.createString(this.privateKey) : 0;
654
+ return x.createPrivateKey(
655
+ t,
656
+ s
657
+ );
658
+ }
659
+ }
660
+ var Q = /* @__PURE__ */ ((e) => (e[e.NONE = 0] = "NONE", e[e.PrivateKey = 1] = "PrivateKey", e))(Q || {});
661
+ function ot(e, t) {
662
+ switch (Q[e]) {
663
+ case "NONE":
664
+ return null;
665
+ case "PrivateKey":
666
+ return t(new x());
667
+ default:
668
+ return null;
669
+ }
670
+ }
671
+ class R {
672
+ constructor() {
673
+ this.bb = null, this.bb_pos = 0;
674
+ }
675
+ __init(t, s) {
676
+ return this.bb_pos = t, this.bb = s, this;
677
+ }
678
+ static getRootAsSetSigner(t, s) {
679
+ return (s || new R()).__init(t.readInt32(t.position()) + t.position(), t);
680
+ }
681
+ static getSizePrefixedRootAsSetSigner(t, s) {
682
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new R()).__init(t.readInt32(t.position()) + t.position(), t);
683
+ }
684
+ signerTypeType() {
685
+ const t = this.bb.__offset(this.bb_pos, 4);
686
+ return t ? this.bb.readUint8(this.bb_pos + t) : Q.NONE;
687
+ }
688
+ signerType(t) {
689
+ const s = this.bb.__offset(this.bb_pos, 6);
690
+ return s ? this.bb.__union(t, this.bb_pos + s) : null;
691
+ }
692
+ static startSetSigner(t) {
693
+ t.startObject(2);
694
+ }
695
+ static addSignerTypeType(t, s) {
696
+ t.addFieldInt8(0, s, Q.NONE);
697
+ }
698
+ static addSignerType(t, s) {
699
+ t.addFieldOffset(1, s, 0);
700
+ }
701
+ static endSetSigner(t) {
702
+ const s = t.endObject();
703
+ return t.requiredField(s, 6), s;
704
+ }
705
+ static createSetSigner(t, s, i) {
706
+ return R.startSetSigner(t), R.addSignerTypeType(t, s), R.addSignerType(t, i), R.endSetSigner(t);
707
+ }
708
+ unpack() {
709
+ return new At(
710
+ this.signerTypeType(),
711
+ (() => {
712
+ const t = ot(this.signerTypeType(), this.signerType.bind(this));
713
+ return t === null ? null : t.unpack();
714
+ })()
715
+ );
716
+ }
717
+ unpackTo(t) {
718
+ t.signerTypeType = this.signerTypeType(), t.signerType = (() => {
719
+ const s = ot(this.signerTypeType(), this.signerType.bind(this));
720
+ return s === null ? null : s.unpack();
721
+ })();
722
+ }
723
+ }
724
+ class At {
725
+ constructor(t = Q.NONE, s = null) {
726
+ this.signerTypeType = t, this.signerType = s;
727
+ }
728
+ pack(t) {
729
+ const s = t.createObjectOffset(this.signerType);
730
+ return R.createSetSigner(
731
+ t,
732
+ this.signerTypeType,
733
+ s
734
+ );
735
+ }
736
+ }
737
+ class M {
738
+ constructor() {
739
+ this.bb = null, this.bb_pos = 0;
740
+ }
741
+ __init(t, s) {
742
+ return this.bb_pos = t, this.bb = s, this;
743
+ }
744
+ static getRootAsSignEvent(t, s) {
745
+ return (s || new M()).__init(t.readInt32(t.position()) + t.position(), t);
746
+ }
747
+ static getSizePrefixedRootAsSignEvent(t, s) {
748
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new M()).__init(t.readInt32(t.position()) + t.position(), t);
749
+ }
750
+ template(t) {
751
+ const s = this.bb.__offset(this.bb_pos, 4);
752
+ return s ? (t || new y()).__init(this.bb.__indirect(this.bb_pos + s), this.bb) : null;
753
+ }
754
+ static startSignEvent(t) {
755
+ t.startObject(1);
756
+ }
757
+ static addTemplate(t, s) {
758
+ t.addFieldOffset(0, s, 0);
759
+ }
760
+ static endSignEvent(t) {
761
+ const s = t.endObject();
762
+ return t.requiredField(s, 4), s;
763
+ }
764
+ static createSignEvent(t, s) {
765
+ return M.startSignEvent(t), M.addTemplate(t, s), M.endSignEvent(t);
766
+ }
767
+ unpack() {
768
+ return new Vt(
769
+ this.template() !== null ? this.template().unpack() : null
770
+ );
771
+ }
772
+ unpackTo(t) {
773
+ t.template = this.template() !== null ? this.template().unpack() : null;
774
+ }
775
+ }
776
+ class Vt {
777
+ constructor(t = null) {
778
+ this.template = t;
779
+ }
780
+ pack(t) {
781
+ const s = this.template !== null ? this.template.pack(t) : 0;
782
+ return M.createSignEvent(
783
+ t,
784
+ s
785
+ );
786
+ }
787
+ }
788
+ class b {
789
+ constructor() {
790
+ this.bb = null, this.bb_pos = 0;
791
+ }
792
+ __init(t, s) {
793
+ return this.bb_pos = t, this.bb = s, this;
794
+ }
795
+ static getRootAsMuteFilterPipeConfig(t, s) {
796
+ return (s || new b()).__init(t.readInt32(t.position()) + t.position(), t);
797
+ }
798
+ static getSizePrefixedRootAsMuteFilterPipeConfig(t, s) {
799
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new b()).__init(t.readInt32(t.position()) + t.position(), t);
800
+ }
801
+ pubkeys(t, s) {
802
+ const i = this.bb.__offset(this.bb_pos, 4);
803
+ return i ? this.bb.__string(this.bb.__vector(this.bb_pos + i) + t * 4, s) : null;
804
+ }
805
+ pubkeysLength() {
806
+ const t = this.bb.__offset(this.bb_pos, 4);
807
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
808
+ }
809
+ hashtags(t, s) {
810
+ const i = this.bb.__offset(this.bb_pos, 6);
811
+ return i ? this.bb.__string(this.bb.__vector(this.bb_pos + i) + t * 4, s) : null;
812
+ }
813
+ hashtagsLength() {
814
+ const t = this.bb.__offset(this.bb_pos, 6);
815
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
816
+ }
817
+ words(t, s) {
818
+ const i = this.bb.__offset(this.bb_pos, 8);
819
+ return i ? this.bb.__string(this.bb.__vector(this.bb_pos + i) + t * 4, s) : null;
820
+ }
821
+ wordsLength() {
822
+ const t = this.bb.__offset(this.bb_pos, 8);
823
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
824
+ }
825
+ eventIds(t, s) {
826
+ const i = this.bb.__offset(this.bb_pos, 10);
827
+ return i ? this.bb.__string(this.bb.__vector(this.bb_pos + i) + t * 4, s) : null;
828
+ }
829
+ eventIdsLength() {
830
+ const t = this.bb.__offset(this.bb_pos, 10);
831
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
832
+ }
833
+ static startMuteFilterPipeConfig(t) {
834
+ t.startObject(4);
835
+ }
836
+ static addPubkeys(t, s) {
837
+ t.addFieldOffset(0, s, 0);
838
+ }
839
+ static createPubkeysVector(t, s) {
840
+ t.startVector(4, s.length, 4);
841
+ for (let i = s.length - 1; i >= 0; i--)
842
+ t.addOffset(s[i]);
843
+ return t.endVector();
844
+ }
845
+ static startPubkeysVector(t, s) {
846
+ t.startVector(4, s, 4);
847
+ }
848
+ static addHashtags(t, s) {
849
+ t.addFieldOffset(1, s, 0);
850
+ }
851
+ static createHashtagsVector(t, s) {
852
+ t.startVector(4, s.length, 4);
853
+ for (let i = s.length - 1; i >= 0; i--)
854
+ t.addOffset(s[i]);
855
+ return t.endVector();
856
+ }
857
+ static startHashtagsVector(t, s) {
858
+ t.startVector(4, s, 4);
859
+ }
860
+ static addWords(t, s) {
861
+ t.addFieldOffset(2, s, 0);
862
+ }
863
+ static createWordsVector(t, s) {
864
+ t.startVector(4, s.length, 4);
865
+ for (let i = s.length - 1; i >= 0; i--)
866
+ t.addOffset(s[i]);
867
+ return t.endVector();
868
+ }
869
+ static startWordsVector(t, s) {
870
+ t.startVector(4, s, 4);
871
+ }
872
+ static addEventIds(t, s) {
873
+ t.addFieldOffset(3, s, 0);
874
+ }
875
+ static createEventIdsVector(t, s) {
876
+ t.startVector(4, s.length, 4);
877
+ for (let i = s.length - 1; i >= 0; i--)
878
+ t.addOffset(s[i]);
879
+ return t.endVector();
880
+ }
881
+ static startEventIdsVector(t, s) {
882
+ t.startVector(4, s, 4);
883
+ }
884
+ static endMuteFilterPipeConfig(t) {
885
+ return t.endObject();
886
+ }
887
+ static createMuteFilterPipeConfig(t, s, i, n, r) {
888
+ return b.startMuteFilterPipeConfig(t), b.addPubkeys(t, s), b.addHashtags(t, i), b.addWords(t, n), b.addEventIds(t, r), b.endMuteFilterPipeConfig(t);
889
+ }
890
+ unpack() {
891
+ return new xt(
892
+ this.bb.createScalarList(this.pubkeys.bind(this), this.pubkeysLength()),
893
+ this.bb.createScalarList(this.hashtags.bind(this), this.hashtagsLength()),
894
+ this.bb.createScalarList(this.words.bind(this), this.wordsLength()),
895
+ this.bb.createScalarList(this.eventIds.bind(this), this.eventIdsLength())
896
+ );
897
+ }
898
+ unpackTo(t) {
899
+ t.pubkeys = this.bb.createScalarList(this.pubkeys.bind(this), this.pubkeysLength()), t.hashtags = this.bb.createScalarList(this.hashtags.bind(this), this.hashtagsLength()), t.words = this.bb.createScalarList(this.words.bind(this), this.wordsLength()), t.eventIds = this.bb.createScalarList(this.eventIds.bind(this), this.eventIdsLength());
900
+ }
901
+ }
902
+ class xt {
903
+ constructor(t = [], s = [], i = [], n = []) {
904
+ this.pubkeys = t, this.hashtags = s, this.words = i, this.eventIds = n;
905
+ }
906
+ pack(t) {
907
+ const s = b.createPubkeysVector(t, t.createObjectOffsetList(this.pubkeys)), i = b.createHashtagsVector(t, t.createObjectOffsetList(this.hashtags)), n = b.createWordsVector(t, t.createObjectOffsetList(this.words)), r = b.createEventIdsVector(t, t.createObjectOffsetList(this.eventIds));
908
+ return b.createMuteFilterPipeConfig(
909
+ t,
910
+ s,
911
+ i,
912
+ n,
913
+ r
914
+ );
915
+ }
916
+ }
917
+ class S {
918
+ constructor() {
919
+ this.bb = null, this.bb_pos = 0;
920
+ }
921
+ __init(t, s) {
922
+ return this.bb_pos = t, this.bb = s, this;
923
+ }
924
+ static getRootAsNpubLimiterPipeConfig(t, s) {
925
+ return (s || new S()).__init(t.readInt32(t.position()) + t.position(), t);
926
+ }
927
+ static getSizePrefixedRootAsNpubLimiterPipeConfig(t, s) {
928
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new S()).__init(t.readInt32(t.position()) + t.position(), t);
929
+ }
930
+ kind() {
931
+ const t = this.bb.__offset(this.bb_pos, 4);
932
+ return t ? this.bb.readUint16(this.bb_pos + t) : 0;
933
+ }
934
+ limitPerNpub() {
935
+ const t = this.bb.__offset(this.bb_pos, 6);
936
+ return t ? this.bb.readUint32(this.bb_pos + t) : 0;
937
+ }
938
+ maxTotalNpubs() {
939
+ const t = this.bb.__offset(this.bb_pos, 8);
940
+ return t ? this.bb.readUint32(this.bb_pos + t) : 0;
941
+ }
942
+ static startNpubLimiterPipeConfig(t) {
943
+ t.startObject(3);
944
+ }
945
+ static addKind(t, s) {
946
+ t.addFieldInt16(0, s, 0);
947
+ }
948
+ static addLimitPerNpub(t, s) {
949
+ t.addFieldInt32(1, s, 0);
950
+ }
951
+ static addMaxTotalNpubs(t, s) {
952
+ t.addFieldInt32(2, s, 0);
953
+ }
954
+ static endNpubLimiterPipeConfig(t) {
955
+ return t.endObject();
956
+ }
957
+ static createNpubLimiterPipeConfig(t, s, i, n) {
958
+ return S.startNpubLimiterPipeConfig(t), S.addKind(t, s), S.addLimitPerNpub(t, i), S.addMaxTotalNpubs(t, n), S.endNpubLimiterPipeConfig(t);
959
+ }
960
+ unpack() {
961
+ return new Mt(
962
+ this.kind(),
963
+ this.limitPerNpub(),
964
+ this.maxTotalNpubs()
965
+ );
966
+ }
967
+ unpackTo(t) {
968
+ t.kind = this.kind(), t.limitPerNpub = this.limitPerNpub(), t.maxTotalNpubs = this.maxTotalNpubs();
969
+ }
970
+ }
971
+ class Mt {
972
+ constructor(t = 0, s = 0, i = 0) {
973
+ this.kind = t, this.limitPerNpub = s, this.maxTotalNpubs = i;
974
+ }
975
+ pack(t) {
976
+ return S.createNpubLimiterPipeConfig(
977
+ t,
978
+ this.kind,
979
+ this.limitPerNpub,
980
+ this.maxTotalNpubs
981
+ );
982
+ }
983
+ }
984
+ class G {
985
+ constructor() {
986
+ this.bb = null, this.bb_pos = 0;
987
+ }
988
+ __init(t, s) {
989
+ return this.bb_pos = t, this.bb = s, this;
990
+ }
991
+ static getRootAsParsePipeConfig(t, s) {
992
+ return (s || new G()).__init(t.readInt32(t.position()) + t.position(), t);
993
+ }
994
+ static getSizePrefixedRootAsParsePipeConfig(t, s) {
995
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new G()).__init(t.readInt32(t.position()) + t.position(), t);
996
+ }
997
+ static startParsePipeConfig(t) {
998
+ t.startObject(0);
999
+ }
1000
+ static endParsePipeConfig(t) {
1001
+ return t.endObject();
1002
+ }
1003
+ static createParsePipeConfig(t) {
1004
+ return G.startParsePipeConfig(t), G.endParsePipeConfig(t);
1005
+ }
1006
+ unpack() {
1007
+ return new Kt();
1008
+ }
1009
+ unpackTo(t) {
1010
+ }
1011
+ }
1012
+ class Kt {
1013
+ constructor() {
1014
+ }
1015
+ pack(t) {
1016
+ return G.createParsePipeConfig(t);
1017
+ }
1018
+ }
1019
+ class K {
1020
+ constructor() {
1021
+ this.bb = null, this.bb_pos = 0;
1022
+ }
1023
+ __init(t, s) {
1024
+ return this.bb_pos = t, this.bb = s, this;
1025
+ }
1026
+ static getRootAsProofVerificationPipeConfig(t, s) {
1027
+ return (s || new K()).__init(t.readInt32(t.position()) + t.position(), t);
1028
+ }
1029
+ static getSizePrefixedRootAsProofVerificationPipeConfig(t, s) {
1030
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new K()).__init(t.readInt32(t.position()) + t.position(), t);
1031
+ }
1032
+ maxProofs() {
1033
+ const t = this.bb.__offset(this.bb_pos, 4);
1034
+ return t ? this.bb.readUint32(this.bb_pos + t) : 0;
1035
+ }
1036
+ static startProofVerificationPipeConfig(t) {
1037
+ t.startObject(1);
1038
+ }
1039
+ static addMaxProofs(t, s) {
1040
+ t.addFieldInt32(0, s, 0);
1041
+ }
1042
+ static endProofVerificationPipeConfig(t) {
1043
+ return t.endObject();
1044
+ }
1045
+ static createProofVerificationPipeConfig(t, s) {
1046
+ return K.startProofVerificationPipeConfig(t), K.addMaxProofs(t, s), K.endProofVerificationPipeConfig(t);
1047
+ }
1048
+ unpack() {
1049
+ return new qt(
1050
+ this.maxProofs()
1051
+ );
1052
+ }
1053
+ unpackTo(t) {
1054
+ t.maxProofs = this.maxProofs();
1055
+ }
1056
+ }
1057
+ class qt {
1058
+ constructor(t = 0) {
1059
+ this.maxProofs = t;
1060
+ }
1061
+ pack(t) {
1062
+ return K.createProofVerificationPipeConfig(
1063
+ t,
1064
+ this.maxProofs
1065
+ );
1066
+ }
1067
+ }
1068
+ class $ {
1069
+ constructor() {
1070
+ this.bb = null, this.bb_pos = 0;
1071
+ }
1072
+ __init(t, s) {
1073
+ return this.bb_pos = t, this.bb = s, this;
1074
+ }
1075
+ static getRootAsSaveToDbPipeConfig(t, s) {
1076
+ return (s || new $()).__init(t.readInt32(t.position()) + t.position(), t);
1077
+ }
1078
+ static getSizePrefixedRootAsSaveToDbPipeConfig(t, s) {
1079
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new $()).__init(t.readInt32(t.position()) + t.position(), t);
1080
+ }
1081
+ static startSaveToDbPipeConfig(t) {
1082
+ t.startObject(0);
1083
+ }
1084
+ static endSaveToDbPipeConfig(t) {
1085
+ return t.endObject();
1086
+ }
1087
+ static createSaveToDbPipeConfig(t) {
1088
+ return $.startSaveToDbPipeConfig(t), $.endSaveToDbPipeConfig(t);
1089
+ }
1090
+ unpack() {
1091
+ return new jt();
1092
+ }
1093
+ unpackTo(t) {
1094
+ }
1095
+ }
1096
+ class jt {
1097
+ constructor() {
1098
+ }
1099
+ pack(t) {
1100
+ return $.createSaveToDbPipeConfig(t);
1101
+ }
1102
+ }
1103
+ class q {
1104
+ constructor() {
1105
+ this.bb = null, this.bb_pos = 0;
1106
+ }
1107
+ __init(t, s) {
1108
+ return this.bb_pos = t, this.bb = s, this;
1109
+ }
1110
+ static getRootAsSerializeEventsPipeConfig(t, s) {
1111
+ return (s || new q()).__init(t.readInt32(t.position()) + t.position(), t);
1112
+ }
1113
+ static getSizePrefixedRootAsSerializeEventsPipeConfig(t, s) {
1114
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new q()).__init(t.readInt32(t.position()) + t.position(), t);
1115
+ }
1116
+ subscriptionId(t) {
1117
+ const s = this.bb.__offset(this.bb_pos, 4);
1118
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
1119
+ }
1120
+ static startSerializeEventsPipeConfig(t) {
1121
+ t.startObject(1);
1122
+ }
1123
+ static addSubscriptionId(t, s) {
1124
+ t.addFieldOffset(0, s, 0);
1125
+ }
1126
+ static endSerializeEventsPipeConfig(t) {
1127
+ const s = t.endObject();
1128
+ return t.requiredField(s, 4), s;
1129
+ }
1130
+ static createSerializeEventsPipeConfig(t, s) {
1131
+ return q.startSerializeEventsPipeConfig(t), q.addSubscriptionId(t, s), q.endSerializeEventsPipeConfig(t);
1132
+ }
1133
+ unpack() {
1134
+ return new Bt(
1135
+ this.subscriptionId()
1136
+ );
1137
+ }
1138
+ unpackTo(t) {
1139
+ t.subscriptionId = this.subscriptionId();
1140
+ }
1141
+ }
1142
+ class Bt {
1143
+ constructor(t = null) {
1144
+ this.subscriptionId = t;
1145
+ }
1146
+ pack(t) {
1147
+ const s = this.subscriptionId !== null ? t.createString(this.subscriptionId) : 0;
1148
+ return q.createSerializeEventsPipeConfig(
1149
+ t,
1150
+ s
1151
+ );
1152
+ }
1153
+ }
1154
+ var Y = /* @__PURE__ */ ((e) => (e[e.NONE = 0] = "NONE", e[e.ParsePipeConfig = 1] = "ParsePipeConfig", e[e.KindFilterPipeConfig = 2] = "KindFilterPipeConfig", e[e.CounterPipeConfig = 3] = "CounterPipeConfig", e[e.NpubLimiterPipeConfig = 4] = "NpubLimiterPipeConfig", e[e.SaveToDbPipeConfig = 5] = "SaveToDbPipeConfig", e[e.SerializeEventsPipeConfig = 6] = "SerializeEventsPipeConfig", e[e.ProofVerificationPipeConfig = 7] = "ProofVerificationPipeConfig", e[e.MuteFilterPipeConfig = 8] = "MuteFilterPipeConfig", e))(Y || {});
1155
+ function at(e, t) {
1156
+ switch (Y[e]) {
1157
+ case "NONE":
1158
+ return null;
1159
+ case "ParsePipeConfig":
1160
+ return t(new G());
1161
+ case "KindFilterPipeConfig":
1162
+ return t(new F());
1163
+ case "CounterPipeConfig":
1164
+ return t(new E());
1165
+ case "NpubLimiterPipeConfig":
1166
+ return t(new S());
1167
+ case "SaveToDbPipeConfig":
1168
+ return t(new $());
1169
+ case "SerializeEventsPipeConfig":
1170
+ return t(new q());
1171
+ case "ProofVerificationPipeConfig":
1172
+ return t(new K());
1173
+ case "MuteFilterPipeConfig":
1174
+ return t(new b());
1175
+ default:
1176
+ return null;
1177
+ }
1178
+ }
1179
+ class N {
1180
+ constructor() {
1181
+ this.bb = null, this.bb_pos = 0;
1182
+ }
1183
+ __init(t, s) {
1184
+ return this.bb_pos = t, this.bb = s, this;
1185
+ }
1186
+ static getRootAsPipe(t, s) {
1187
+ return (s || new N()).__init(t.readInt32(t.position()) + t.position(), t);
1188
+ }
1189
+ static getSizePrefixedRootAsPipe(t, s) {
1190
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new N()).__init(t.readInt32(t.position()) + t.position(), t);
1191
+ }
1192
+ configType() {
1193
+ const t = this.bb.__offset(this.bb_pos, 4);
1194
+ return t ? this.bb.readUint8(this.bb_pos + t) : Y.NONE;
1195
+ }
1196
+ config(t) {
1197
+ const s = this.bb.__offset(this.bb_pos, 6);
1198
+ return s ? this.bb.__union(t, this.bb_pos + s) : null;
1199
+ }
1200
+ static startPipe(t) {
1201
+ t.startObject(2);
1202
+ }
1203
+ static addConfigType(t, s) {
1204
+ t.addFieldInt8(0, s, Y.NONE);
1205
+ }
1206
+ static addConfig(t, s) {
1207
+ t.addFieldOffset(1, s, 0);
1208
+ }
1209
+ static endPipe(t) {
1210
+ const s = t.endObject();
1211
+ return t.requiredField(s, 6), s;
1212
+ }
1213
+ static createPipe(t, s, i) {
1214
+ return N.startPipe(t), N.addConfigType(t, s), N.addConfig(t, i), N.endPipe(t);
1215
+ }
1216
+ unpack() {
1217
+ return new zt(
1218
+ this.configType(),
1219
+ (() => {
1220
+ const t = at(this.configType(), this.config.bind(this));
1221
+ return t === null ? null : t.unpack();
1222
+ })()
1223
+ );
1224
+ }
1225
+ unpackTo(t) {
1226
+ t.configType = this.configType(), t.config = (() => {
1227
+ const s = at(this.configType(), this.config.bind(this));
1228
+ return s === null ? null : s.unpack();
1229
+ })();
1230
+ }
1231
+ }
1232
+ class zt {
1233
+ constructor(t = Y.NONE, s = null) {
1234
+ this.configType = t, this.config = s;
1235
+ }
1236
+ pack(t) {
1237
+ const s = t.createObjectOffset(this.config);
1238
+ return N.createPipe(
1239
+ t,
1240
+ this.configType,
1241
+ s
1242
+ );
1243
+ }
1244
+ }
1245
+ class L {
1246
+ constructor() {
1247
+ this.bb = null, this.bb_pos = 0;
1248
+ }
1249
+ __init(t, s) {
1250
+ return this.bb_pos = t, this.bb = s, this;
1251
+ }
1252
+ static getRootAsPipelineConfig(t, s) {
1253
+ return (s || new L()).__init(t.readInt32(t.position()) + t.position(), t);
1254
+ }
1255
+ static getSizePrefixedRootAsPipelineConfig(t, s) {
1256
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new L()).__init(t.readInt32(t.position()) + t.position(), t);
1257
+ }
1258
+ pipes(t, s) {
1259
+ const i = this.bb.__offset(this.bb_pos, 4);
1260
+ return i ? (s || new N()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + i) + t * 4), this.bb) : null;
1261
+ }
1262
+ pipesLength() {
1263
+ const t = this.bb.__offset(this.bb_pos, 4);
1264
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
1265
+ }
1266
+ static startPipelineConfig(t) {
1267
+ t.startObject(1);
1268
+ }
1269
+ static addPipes(t, s) {
1270
+ t.addFieldOffset(0, s, 0);
1271
+ }
1272
+ static createPipesVector(t, s) {
1273
+ t.startVector(4, s.length, 4);
1274
+ for (let i = s.length - 1; i >= 0; i--)
1275
+ t.addOffset(s[i]);
1276
+ return t.endVector();
1277
+ }
1278
+ static startPipesVector(t, s) {
1279
+ t.startVector(4, s, 4);
1280
+ }
1281
+ static endPipelineConfig(t) {
1282
+ const s = t.endObject();
1283
+ return t.requiredField(s, 4), s;
1284
+ }
1285
+ static createPipelineConfig(t, s) {
1286
+ return L.startPipelineConfig(t), L.addPipes(t, s), L.endPipelineConfig(t);
1287
+ }
1288
+ unpack() {
1289
+ return new gt(
1290
+ this.bb.createObjList(this.pipes.bind(this), this.pipesLength())
1291
+ );
1292
+ }
1293
+ unpackTo(t) {
1294
+ t.pipes = this.bb.createObjList(this.pipes.bind(this), this.pipesLength());
1295
+ }
1296
+ }
1297
+ class gt {
1298
+ constructor(t = []) {
1299
+ this.pipes = t;
1300
+ }
1301
+ pack(t) {
1302
+ const s = L.createPipesVector(t, t.createObjectOffsetList(this.pipes));
1303
+ return L.createPipelineConfig(
1304
+ t,
1305
+ s
1306
+ );
1307
+ }
1308
+ }
1309
+ class f {
1310
+ constructor() {
1311
+ this.bb = null, this.bb_pos = 0;
1312
+ }
1313
+ __init(t, s) {
1314
+ return this.bb_pos = t, this.bb = s, this;
1315
+ }
1316
+ static getRootAsSubscriptionConfig(t, s) {
1317
+ return (s || new f()).__init(t.readInt32(t.position()) + t.position(), t);
1318
+ }
1319
+ static getSizePrefixedRootAsSubscriptionConfig(t, s) {
1320
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new f()).__init(t.readInt32(t.position()) + t.position(), t);
1321
+ }
1322
+ pipeline(t) {
1323
+ const s = this.bb.__offset(this.bb_pos, 4);
1324
+ return s ? (t || new L()).__init(this.bb.__indirect(this.bb_pos + s), this.bb) : null;
1325
+ }
1326
+ closeOnEose() {
1327
+ const t = this.bb.__offset(this.bb_pos, 6);
1328
+ return t ? !!this.bb.readInt8(this.bb_pos + t) : false;
1329
+ }
1330
+ cacheFirst() {
1331
+ const t = this.bb.__offset(this.bb_pos, 8);
1332
+ return t ? !!this.bb.readInt8(this.bb_pos + t) : true;
1333
+ }
1334
+ timeoutMs() {
1335
+ const t = this.bb.__offset(this.bb_pos, 10);
1336
+ return t ? this.bb.readUint64(this.bb_pos + t) : BigInt("0");
1337
+ }
1338
+ maxEvents() {
1339
+ const t = this.bb.__offset(this.bb_pos, 12);
1340
+ return t ? this.bb.readUint32(this.bb_pos + t) : 0;
1341
+ }
1342
+ skipCache() {
1343
+ const t = this.bb.__offset(this.bb_pos, 14);
1344
+ return t ? !!this.bb.readInt8(this.bb_pos + t) : false;
1345
+ }
1346
+ force() {
1347
+ const t = this.bb.__offset(this.bb_pos, 16);
1348
+ return t ? !!this.bb.readInt8(this.bb_pos + t) : false;
1349
+ }
1350
+ bytesPerEvent() {
1351
+ const t = this.bb.__offset(this.bb_pos, 18);
1352
+ return t ? this.bb.readUint32(this.bb_pos + t) : 0;
1353
+ }
1354
+ isSlow() {
1355
+ const t = this.bb.__offset(this.bb_pos, 20);
1356
+ return t ? !!this.bb.readInt8(this.bb_pos + t) : false;
1357
+ }
1358
+ pagination(t) {
1359
+ const s = this.bb.__offset(this.bb_pos, 22);
1360
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
1361
+ }
1362
+ static startSubscriptionConfig(t) {
1363
+ t.startObject(10);
1364
+ }
1365
+ static addPipeline(t, s) {
1366
+ t.addFieldOffset(0, s, 0);
1367
+ }
1368
+ static addCloseOnEose(t, s) {
1369
+ t.addFieldInt8(1, +s, 0);
1370
+ }
1371
+ static addCacheFirst(t, s) {
1372
+ t.addFieldInt8(2, +s, 1);
1373
+ }
1374
+ static addTimeoutMs(t, s) {
1375
+ t.addFieldInt64(3, s, BigInt("0"));
1376
+ }
1377
+ static addMaxEvents(t, s) {
1378
+ t.addFieldInt32(4, s, 0);
1379
+ }
1380
+ static addSkipCache(t, s) {
1381
+ t.addFieldInt8(5, +s, 0);
1382
+ }
1383
+ static addForce(t, s) {
1384
+ t.addFieldInt8(6, +s, 0);
1385
+ }
1386
+ static addBytesPerEvent(t, s) {
1387
+ t.addFieldInt32(7, s, 0);
1388
+ }
1389
+ static addIsSlow(t, s) {
1390
+ t.addFieldInt8(8, +s, 0);
1391
+ }
1392
+ static addPagination(t, s) {
1393
+ t.addFieldOffset(9, s, 0);
1394
+ }
1395
+ static endSubscriptionConfig(t) {
1396
+ return t.endObject();
1397
+ }
1398
+ static createSubscriptionConfig(t, s, i, n, r, o, a, c, u, l, k) {
1399
+ return f.startSubscriptionConfig(t), f.addPipeline(t, s), f.addCloseOnEose(t, i), f.addCacheFirst(t, n), f.addTimeoutMs(t, r), f.addMaxEvents(t, o), f.addSkipCache(t, a), f.addForce(t, c), f.addBytesPerEvent(t, u), f.addIsSlow(t, l), f.addPagination(t, k), f.endSubscriptionConfig(t);
1400
+ }
1401
+ unpack() {
1402
+ return new yt(
1403
+ this.pipeline() !== null ? this.pipeline().unpack() : null,
1404
+ this.closeOnEose(),
1405
+ this.cacheFirst(),
1406
+ this.timeoutMs(),
1407
+ this.maxEvents(),
1408
+ this.skipCache(),
1409
+ this.force(),
1410
+ this.bytesPerEvent(),
1411
+ this.isSlow(),
1412
+ this.pagination()
1413
+ );
1414
+ }
1415
+ unpackTo(t) {
1416
+ t.pipeline = this.pipeline() !== null ? this.pipeline().unpack() : null, t.closeOnEose = this.closeOnEose(), t.cacheFirst = this.cacheFirst(), t.timeoutMs = this.timeoutMs(), t.maxEvents = this.maxEvents(), t.skipCache = this.skipCache(), t.force = this.force(), t.bytesPerEvent = this.bytesPerEvent(), t.isSlow = this.isSlow(), t.pagination = this.pagination();
1417
+ }
1418
+ }
1419
+ class yt {
1420
+ constructor(t = null, s = false, i = true, n = BigInt("0"), r = 0, o = false, a = false, c = 0, u = false, l = null) {
1421
+ this.pipeline = t, this.closeOnEose = s, this.cacheFirst = i, this.timeoutMs = n, this.maxEvents = r, this.skipCache = o, this.force = a, this.bytesPerEvent = c, this.isSlow = u, this.pagination = l;
1422
+ }
1423
+ pack(t) {
1424
+ const s = this.pipeline !== null ? this.pipeline.pack(t) : 0, i = this.pagination !== null ? t.createString(this.pagination) : 0;
1425
+ return f.createSubscriptionConfig(
1426
+ t,
1427
+ s,
1428
+ this.closeOnEose,
1429
+ this.cacheFirst,
1430
+ this.timeoutMs,
1431
+ this.maxEvents,
1432
+ this.skipCache,
1433
+ this.force,
1434
+ this.bytesPerEvent,
1435
+ this.isSlow,
1436
+ i
1437
+ );
1438
+ }
1439
+ }
1440
+ class m {
1441
+ constructor() {
1442
+ this.bb = null, this.bb_pos = 0;
1443
+ }
1444
+ __init(t, s) {
1445
+ return this.bb_pos = t, this.bb = s, this;
1446
+ }
1447
+ static getRootAsSubscribe(t, s) {
1448
+ return (s || new m()).__init(t.readInt32(t.position()) + t.position(), t);
1449
+ }
1450
+ static getSizePrefixedRootAsSubscribe(t, s) {
1451
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new m()).__init(t.readInt32(t.position()) + t.position(), t);
1452
+ }
1453
+ subscriptionId(t) {
1454
+ const s = this.bb.__offset(this.bb_pos, 4);
1455
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
1456
+ }
1457
+ requests(t, s) {
1458
+ const i = this.bb.__offset(this.bb_pos, 6);
1459
+ return i ? (s || new ut()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + i) + t * 4), this.bb) : null;
1460
+ }
1461
+ requestsLength() {
1462
+ const t = this.bb.__offset(this.bb_pos, 6);
1463
+ return t ? this.bb.__vector_len(this.bb_pos + t) : 0;
1464
+ }
1465
+ config(t) {
1466
+ const s = this.bb.__offset(this.bb_pos, 8);
1467
+ return s ? (t || new f()).__init(this.bb.__indirect(this.bb_pos + s), this.bb) : null;
1468
+ }
1469
+ static startSubscribe(t) {
1470
+ t.startObject(3);
1471
+ }
1472
+ static addSubscriptionId(t, s) {
1473
+ t.addFieldOffset(0, s, 0);
1474
+ }
1475
+ static addRequests(t, s) {
1476
+ t.addFieldOffset(1, s, 0);
1477
+ }
1478
+ static createRequestsVector(t, s) {
1479
+ t.startVector(4, s.length, 4);
1480
+ for (let i = s.length - 1; i >= 0; i--)
1481
+ t.addOffset(s[i]);
1482
+ return t.endVector();
1483
+ }
1484
+ static startRequestsVector(t, s) {
1485
+ t.startVector(4, s, 4);
1486
+ }
1487
+ static addConfig(t, s) {
1488
+ t.addFieldOffset(2, s, 0);
1489
+ }
1490
+ static endSubscribe(t) {
1491
+ const s = t.endObject();
1492
+ return t.requiredField(s, 4), t.requiredField(s, 6), t.requiredField(s, 8), s;
1493
+ }
1494
+ unpack() {
1495
+ return new Pt(
1496
+ this.subscriptionId(),
1497
+ this.bb.createObjList(this.requests.bind(this), this.requestsLength()),
1498
+ this.config() !== null ? this.config().unpack() : null
1499
+ );
1500
+ }
1501
+ unpackTo(t) {
1502
+ t.subscriptionId = this.subscriptionId(), t.requests = this.bb.createObjList(this.requests.bind(this), this.requestsLength()), t.config = this.config() !== null ? this.config().unpack() : null;
1503
+ }
1504
+ }
1505
+ class Pt {
1506
+ constructor(t = null, s = [], i = null) {
1507
+ this.subscriptionId = t, this.requests = s, this.config = i;
1508
+ }
1509
+ pack(t) {
1510
+ const s = this.subscriptionId !== null ? t.createString(this.subscriptionId) : 0, i = m.createRequestsVector(t, t.createObjectOffsetList(this.requests)), n = this.config !== null ? this.config.pack(t) : 0;
1511
+ return m.startSubscribe(t), m.addSubscriptionId(t, s), m.addRequests(t, i), m.addConfig(t, n), m.endSubscribe(t);
1512
+ }
1513
+ }
1514
+ class j {
1515
+ constructor() {
1516
+ this.bb = null, this.bb_pos = 0;
1517
+ }
1518
+ __init(t, s) {
1519
+ return this.bb_pos = t, this.bb = s, this;
1520
+ }
1521
+ static getRootAsUnsubscribe(t, s) {
1522
+ return (s || new j()).__init(t.readInt32(t.position()) + t.position(), t);
1523
+ }
1524
+ static getSizePrefixedRootAsUnsubscribe(t, s) {
1525
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new j()).__init(t.readInt32(t.position()) + t.position(), t);
1526
+ }
1527
+ subscriptionId(t) {
1528
+ const s = this.bb.__offset(this.bb_pos, 4);
1529
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
1530
+ }
1531
+ static startUnsubscribe(t) {
1532
+ t.startObject(1);
1533
+ }
1534
+ static addSubscriptionId(t, s) {
1535
+ t.addFieldOffset(0, s, 0);
1536
+ }
1537
+ static endUnsubscribe(t) {
1538
+ const s = t.endObject();
1539
+ return t.requiredField(s, 4), s;
1540
+ }
1541
+ static createUnsubscribe(t, s) {
1542
+ return j.startUnsubscribe(t), j.addSubscriptionId(t, s), j.endUnsubscribe(t);
1543
+ }
1544
+ unpack() {
1545
+ return new kt(
1546
+ this.subscriptionId()
1547
+ );
1548
+ }
1549
+ unpackTo(t) {
1550
+ t.subscriptionId = this.subscriptionId();
1551
+ }
1552
+ }
1553
+ class kt {
1554
+ constructor(t = null) {
1555
+ this.subscriptionId = t;
1556
+ }
1557
+ pack(t) {
1558
+ const s = this.subscriptionId !== null ? t.createString(this.subscriptionId) : 0;
1559
+ return j.createUnsubscribe(
1560
+ t,
1561
+ s
1562
+ );
1563
+ }
1564
+ }
1565
+ var C = /* @__PURE__ */ ((e) => (e[e.NONE = 0] = "NONE", e[e.Subscribe = 1] = "Subscribe", e[e.Unsubscribe = 2] = "Unsubscribe", e[e.Publish = 3] = "Publish", e[e.SignEvent = 4] = "SignEvent", e[e.SetSigner = 5] = "SetSigner", e[e.GetPublicKey = 6] = "GetPublicKey", e))(C || {});
1566
+ function ct(e, t) {
1567
+ switch (C[e]) {
1568
+ case "NONE":
1569
+ return null;
1570
+ case "Subscribe":
1571
+ return t(new m());
1572
+ case "Unsubscribe":
1573
+ return t(new j());
1574
+ case "Publish":
1575
+ return t(new v());
1576
+ case "SignEvent":
1577
+ return t(new M());
1578
+ case "SetSigner":
1579
+ return t(new R());
1580
+ case "GetPublicKey":
1581
+ return t(new z());
1582
+ default:
1583
+ return null;
1584
+ }
1585
+ }
1586
+ class V {
1587
+ constructor() {
1588
+ this.bb = null, this.bb_pos = 0;
1589
+ }
1590
+ __init(t, s) {
1591
+ return this.bb_pos = t, this.bb = s, this;
1592
+ }
1593
+ static getRootAsMainMessage(t, s) {
1594
+ return (s || new V()).__init(t.readInt32(t.position()) + t.position(), t);
1595
+ }
1596
+ static getSizePrefixedRootAsMainMessage(t, s) {
1597
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new V()).__init(t.readInt32(t.position()) + t.position(), t);
1598
+ }
1599
+ contentType() {
1600
+ const t = this.bb.__offset(this.bb_pos, 4);
1601
+ return t ? this.bb.readUint8(this.bb_pos + t) : C.NONE;
1602
+ }
1603
+ content(t) {
1604
+ const s = this.bb.__offset(this.bb_pos, 6);
1605
+ return s ? this.bb.__union(t, this.bb_pos + s) : null;
1606
+ }
1607
+ static startMainMessage(t) {
1608
+ t.startObject(2);
1609
+ }
1610
+ static addContentType(t, s) {
1611
+ t.addFieldInt8(0, s, C.NONE);
1612
+ }
1613
+ static addContent(t, s) {
1614
+ t.addFieldOffset(1, s, 0);
1615
+ }
1616
+ static endMainMessage(t) {
1617
+ const s = t.endObject();
1618
+ return t.requiredField(s, 6), s;
1619
+ }
1620
+ static createMainMessage(t, s, i) {
1621
+ return V.startMainMessage(t), V.addContentType(t, s), V.addContent(t, i), V.endMainMessage(t);
1622
+ }
1623
+ unpack() {
1624
+ return new Z(
1625
+ this.contentType(),
1626
+ (() => {
1627
+ const t = ct(this.contentType(), this.content.bind(this));
1628
+ return t === null ? null : t.unpack();
1629
+ })()
1630
+ );
1631
+ }
1632
+ unpackTo(t) {
1633
+ t.contentType = this.contentType(), t.content = (() => {
1634
+ const s = ct(this.contentType(), this.content.bind(this));
1635
+ return s === null ? null : s.unpack();
1636
+ })();
1637
+ }
1638
+ }
1639
+ class Z {
1640
+ constructor(t = C.NONE, s = null) {
1641
+ this.contentType = t, this.content = s;
1642
+ }
1643
+ pack(t) {
1644
+ const s = t.createObjectOffset(this.content);
1645
+ return V.createMainMessage(
1646
+ t,
1647
+ this.contentType,
1648
+ s
1649
+ );
1650
+ }
1651
+ }
1652
+ var Gt = /* @__PURE__ */ ((e) => (e[e.Kind0Parsed = 0] = "Kind0Parsed", e[e.Kind1Parsed = 1] = "Kind1Parsed", e[e.Kind3Parsed = 3] = "Kind3Parsed", e[e.Kind4Parsed = 4] = "Kind4Parsed", e[e.Kind6Parsed = 6] = "Kind6Parsed", e[e.Kind7Parsed = 7] = "Kind7Parsed", e[e.Kind17Parsed = 17] = "Kind17Parsed", e[e.Kind20Parsed = 20] = "Kind20Parsed", e[e.Kind22Parsed = 22] = "Kind22Parsed", e[e.Kind1111Parsed = 1111] = "Kind1111Parsed", e[e.Kind1311Parsed = 1311] = "Kind1311Parsed", e[e.Kind7374Parsed = 7374] = "Kind7374Parsed", e[e.Kind7375Parsed = 7375] = "Kind7375Parsed", e[e.Kind7376Parsed = 7376] = "Kind7376Parsed", e[e.Kind9321Parsed = 9321] = "Kind9321Parsed", e[e.Kind9735Parsed = 9735] = "Kind9735Parsed", e[e.Kind10002Parsed = 10002] = "Kind10002Parsed", e[e.Kind10019Parsed = 10019] = "Kind10019Parsed", e[e.Kind17375Parsed = 17375] = "Kind17375Parsed", e[e.Kind30023Parsed = 30023] = "Kind30023Parsed", e[e.Kind39089Parsed = 39089] = "Kind39089Parsed", e[e.ListParsed = 51e3] = "ListParsed", e[e.PreGenericParsed = 52e3] = "PreGenericParsed", e))(Gt || {}), tt = /* @__PURE__ */ ((e) => (e[e.GetPubkey = 0] = "GetPubkey", e[e.SignEvent = 1] = "SignEvent", e[e.Nip04Encrypt = 2] = "Nip04Encrypt", e[e.Nip04Decrypt = 3] = "Nip04Decrypt", e[e.Nip44Encrypt = 4] = "Nip44Encrypt", e[e.Nip44Decrypt = 5] = "Nip44Decrypt", e[e.Nip04DecryptBetween = 6] = "Nip04DecryptBetween", e[e.Nip44DecryptBetween = 7] = "Nip44DecryptBetween", e[e.VerifyProof = 8] = "VerifyProof", e[e.AuthEvent = 9] = "AuthEvent", e))(tt || {});
1653
+ class P {
1654
+ constructor() {
1655
+ this.bb = null, this.bb_pos = 0;
1656
+ }
1657
+ __init(t, s) {
1658
+ return this.bb_pos = t, this.bb = s, this;
1659
+ }
1660
+ static getRootAsSignerRequest(t, s) {
1661
+ return (s || new P()).__init(t.readInt32(t.position()) + t.position(), t);
1662
+ }
1663
+ static getSizePrefixedRootAsSignerRequest(t, s) {
1664
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new P()).__init(t.readInt32(t.position()) + t.position(), t);
1665
+ }
1666
+ requestId() {
1667
+ const t = this.bb.__offset(this.bb_pos, 4);
1668
+ return t ? this.bb.readUint64(this.bb_pos + t) : BigInt("0");
1669
+ }
1670
+ op() {
1671
+ const t = this.bb.__offset(this.bb_pos, 6);
1672
+ return t ? this.bb.readUint32(this.bb_pos + t) : tt.GetPubkey;
1673
+ }
1674
+ payload(t) {
1675
+ const s = this.bb.__offset(this.bb_pos, 8);
1676
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
1677
+ }
1678
+ pubkey(t) {
1679
+ const s = this.bb.__offset(this.bb_pos, 10);
1680
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
1681
+ }
1682
+ senderPubkey(t) {
1683
+ const s = this.bb.__offset(this.bb_pos, 12);
1684
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
1685
+ }
1686
+ recipientPubkey(t) {
1687
+ const s = this.bb.__offset(this.bb_pos, 14);
1688
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
1689
+ }
1690
+ static startSignerRequest(t) {
1691
+ t.startObject(6);
1692
+ }
1693
+ static addRequestId(t, s) {
1694
+ t.addFieldInt64(0, s, BigInt("0"));
1695
+ }
1696
+ static addOp(t, s) {
1697
+ t.addFieldInt32(1, s, tt.GetPubkey);
1698
+ }
1699
+ static addPayload(t, s) {
1700
+ t.addFieldOffset(2, s, 0);
1701
+ }
1702
+ static addPubkey(t, s) {
1703
+ t.addFieldOffset(3, s, 0);
1704
+ }
1705
+ static addSenderPubkey(t, s) {
1706
+ t.addFieldOffset(4, s, 0);
1707
+ }
1708
+ static addRecipientPubkey(t, s) {
1709
+ t.addFieldOffset(5, s, 0);
1710
+ }
1711
+ static endSignerRequest(t) {
1712
+ return t.endObject();
1713
+ }
1714
+ static createSignerRequest(t, s, i, n, r, o, a) {
1715
+ return P.startSignerRequest(t), P.addRequestId(t, s), P.addOp(t, i), P.addPayload(t, n), P.addPubkey(t, r), P.addSenderPubkey(t, o), P.addRecipientPubkey(t, a), P.endSignerRequest(t);
1716
+ }
1717
+ unpack() {
1718
+ return new $t(
1719
+ this.requestId(),
1720
+ this.op(),
1721
+ this.payload(),
1722
+ this.pubkey(),
1723
+ this.senderPubkey(),
1724
+ this.recipientPubkey()
1725
+ );
1726
+ }
1727
+ unpackTo(t) {
1728
+ t.requestId = this.requestId(), t.op = this.op(), t.payload = this.payload(), t.pubkey = this.pubkey(), t.senderPubkey = this.senderPubkey(), t.recipientPubkey = this.recipientPubkey();
1729
+ }
1730
+ }
1731
+ class $t {
1732
+ constructor(t = BigInt("0"), s = tt.GetPubkey, i = null, n = null, r = null, o = null) {
1733
+ this.requestId = t, this.op = s, this.payload = i, this.pubkey = n, this.senderPubkey = r, this.recipientPubkey = o;
1734
+ }
1735
+ pack(t) {
1736
+ const s = this.payload !== null ? t.createString(this.payload) : 0, i = this.pubkey !== null ? t.createString(this.pubkey) : 0, n = this.senderPubkey !== null ? t.createString(this.senderPubkey) : 0, r = this.recipientPubkey !== null ? t.createString(this.recipientPubkey) : 0;
1737
+ return P.createSignerRequest(
1738
+ t,
1739
+ this.requestId,
1740
+ this.op,
1741
+ s,
1742
+ i,
1743
+ n,
1744
+ r
1745
+ );
1746
+ }
1747
+ }
1748
+ class T {
1749
+ constructor() {
1750
+ this.bb = null, this.bb_pos = 0;
1751
+ }
1752
+ __init(t, s) {
1753
+ return this.bb_pos = t, this.bb = s, this;
1754
+ }
1755
+ static getRootAsSignerResponse(t, s) {
1756
+ return (s || new T()).__init(t.readInt32(t.position()) + t.position(), t);
1757
+ }
1758
+ static getSizePrefixedRootAsSignerResponse(t, s) {
1759
+ return t.setPosition(t.position() + h.SIZE_PREFIX_LENGTH), (s || new T()).__init(t.readInt32(t.position()) + t.position(), t);
1760
+ }
1761
+ requestId() {
1762
+ const t = this.bb.__offset(this.bb_pos, 4);
1763
+ return t ? this.bb.readUint64(this.bb_pos + t) : BigInt("0");
1764
+ }
1765
+ result(t) {
1766
+ const s = this.bb.__offset(this.bb_pos, 6);
1767
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
1768
+ }
1769
+ error(t) {
1770
+ const s = this.bb.__offset(this.bb_pos, 8);
1771
+ return s ? this.bb.__string(this.bb_pos + s, t) : null;
1772
+ }
1773
+ static startSignerResponse(t) {
1774
+ t.startObject(3);
1775
+ }
1776
+ static addRequestId(t, s) {
1777
+ t.addFieldInt64(0, s, BigInt("0"));
1778
+ }
1779
+ static addResult(t, s) {
1780
+ t.addFieldOffset(1, s, 0);
1781
+ }
1782
+ static addError(t, s) {
1783
+ t.addFieldOffset(2, s, 0);
1784
+ }
1785
+ static endSignerResponse(t) {
1786
+ return t.endObject();
1787
+ }
1788
+ static createSignerResponse(t, s, i, n) {
1789
+ return T.startSignerResponse(t), T.addRequestId(t, s), T.addResult(t, i), T.addError(t, n), T.endSignerResponse(t);
1790
+ }
1791
+ unpack() {
1792
+ return new Wt(
1793
+ this.requestId(),
1794
+ this.result(),
1795
+ this.error()
1796
+ );
1797
+ }
1798
+ unpackTo(t) {
1799
+ t.requestId = this.requestId(), t.result = this.result(), t.error = this.error();
1800
+ }
1801
+ }
1802
+ class Wt {
1803
+ constructor(t = BigInt("0"), s = null, i = null) {
1804
+ this.requestId = t, this.result = s, this.error = i;
1805
+ }
1806
+ pack(t) {
1807
+ const s = this.result !== null ? t.createString(this.result) : 0, i = this.error !== null ? t.createString(this.error) : 0;
1808
+ return T.createSignerResponse(
1809
+ t,
1810
+ this.requestId,
1811
+ s,
1812
+ i
1813
+ );
1814
+ }
1815
+ }
1816
+ var Ht = /* @__PURE__ */ ((e) => (e[e.CachedEvent = 0] = "CachedEvent", e[e.FetchedEvent = 1] = "FetchedEvent", e[e.Count = 2] = "Count", e[e.ConnectionStatus = 3] = "ConnectionStatus", e[e.Eoce = 4] = "Eoce", e[e.BufferFull = 5] = "BufferFull", e))(Ht || {});
1817
+ class X {
1818
+ /**
1819
+ * Initialize a buffer for writing - sets the write position header to 4
1820
+ * @param buffer The ArrayBuffer to initialize
1821
+ */
1822
+ static initializeBuffer(t) {
1823
+ new DataView(t).setUint32(0, 4, true);
1824
+ }
1825
+ /**
1826
+ * Write a message to the ArrayBuffer
1827
+ * @param buffer The ArrayBuffer to write to
1828
+ * @param data The data to write (already encoded as Uint8Array)
1829
+ * @returns True if written successfully, false if buffer is full
1830
+ */
1831
+ static writeMessage(t, s) {
1832
+ const i = new DataView(t), n = new Uint8Array(t), r = i.getUint32(0, true), o = 4 + s.length;
1833
+ if (r + o > t.byteLength)
1834
+ return console.warn("Buffer full, cannot write message"), false;
1835
+ i.setUint32(r, s.length, true), n.set(s, r + 4);
1836
+ const a = r + o;
1837
+ return i.setUint32(0, a, true), true;
1838
+ }
1839
+ /**
1840
+ * Write raw batched data (already length-prefixed) to the ArrayBuffer.
1841
+ * Use this when the data already contains [4-byte len][payload] format.
1842
+ * @param buffer The ArrayBuffer to write to
1843
+ * @param data The batched data (already with length prefixes)
1844
+ * @returns True if written successfully, false if buffer is full
1845
+ */
1846
+ static writeBatchedData(t, s, i) {
1847
+ const n = new DataView(t), r = new Uint8Array(t), o = n.getUint32(0, true);
1848
+ if (o + s.length > t.byteLength)
1849
+ return console.warn(
1850
+ `[ArrayBufferReader] Dropping ${i ? `event for subscription '${i}'` : "event"}: buffer full (${o}/${t.byteLength} bytes used, need ${s.length} more bytes). Consider increasing 'bytesPerEvent' or reducing subscription limits.`
1851
+ ), false;
1852
+ r.set(s, o);
1853
+ const a = o + s.length;
1854
+ return n.setUint32(0, a, true), true;
1855
+ }
1856
+ /**
1857
+ * Read new messages from ArrayBuffer since last read position
1858
+ * @param buffer The ArrayBuffer to read from
1859
+ * @param lastReadPosition Last position read (default: 0, meaning read from beginning)
1860
+ * @returns Object containing new messages and updated read position
1861
+ */
1862
+ static readMessages(t, s = 0, i) {
1863
+ const n = new DataView(t), r = new Uint8Array(t), o = n.getUint32(0, true), a = 4;
1864
+ let c = s < a ? a : s;
1865
+ if (o <= c)
1866
+ return { messages: [], newReadPosition: c, hasNewData: false };
1867
+ const u = 128, l = new Array(u);
1868
+ let k = 0;
1869
+ try {
1870
+ for (; c < o && !(k >= u || c + 4 > o); ) {
1871
+ const w = c, W = n.getUint32(w, true), d = w + 4, _ = d + W;
1872
+ if (_ > o) break;
1873
+ const p = new St(r.subarray(d, _)), I = dt.getRootAsWorkerMessage(p);
1874
+ l[k++] = I, c = _;
1875
+ }
1876
+ return l.length = k, {
1877
+ messages: l,
1878
+ newReadPosition: c,
1879
+ hasNewData: k > 0
1880
+ };
1881
+ } catch (w) {
1882
+ return console.error("Failed to decode FlatBuffer data from ArrayBuffer:", w), l.length = k, {
1883
+ messages: l,
1884
+ newReadPosition: s < a ? a : s,
1885
+ hasNewData: false
1886
+ };
1887
+ }
1888
+ }
1889
+ /**
1890
+ * Read all messages from ArrayBuffer from the beginning (ignores lastReadPosition)
1891
+ * @param buffer The ArrayBuffer to read from
1892
+ * @returns Object containing all messages in the buffer
1893
+ */
1894
+ static readAllMessages(t) {
1895
+ const s = this.readMessages(t, 0);
1896
+ return {
1897
+ messages: s.messages,
1898
+ totalMessages: s.messages.length
1899
+ };
1900
+ }
1901
+ /**
1902
+ * Get current write position from buffer header
1903
+ * @param buffer The ArrayBuffer to read from
1904
+ * @returns Current write position
1905
+ */
1906
+ static getCurrentWritePosition(t) {
1907
+ return new DataView(t).getUint32(0, true);
1908
+ }
1909
+ /**
1910
+ * Check if buffer has new data since last read
1911
+ * @param buffer The ArrayBuffer to check
1912
+ * @param lastReadPosition Last position read
1913
+ * @returns True if there's new data to read
1914
+ */
1915
+ static hasNewData(t, s) {
1916
+ const i = this.getCurrentWritePosition(t), r = Math.max(s, 4);
1917
+ return i > r;
1918
+ }
1919
+ /**
1920
+ * Calculate recommended buffer size based on request limits
1921
+ * @param totalEventLimit Total expected events across all requests
1922
+ * @param bytesPerEvent Estimated bytes per event (default: 3072)
1923
+ * @returns Recommended buffer size in bytes
1924
+ */
1925
+ static calculateBufferSize(t = 100, s = 3072) {
1926
+ const n = t * s, r = Math.floor(n * 0.25);
1927
+ return 4 + n + r;
1928
+ }
1929
+ }
1930
+ const Ut = new TextDecoder();
1931
+ function ht(e) {
1932
+ if (typeof e == "string") return e;
1933
+ if (e instanceof Uint8Array) return Ut.decode(e);
1934
+ }
1935
+ function H(e) {
1936
+ if (Array.isArray(e))
1937
+ return e.filter((t) => typeof t == "string");
1938
+ if ("itemsLength" in e && typeof e.itemsLength == "function") {
1939
+ const t = [];
1940
+ for (let s = 0; s < e.itemsLength(); s++) {
1941
+ const i = ht(e.items(s));
1942
+ i !== void 0 && t.push(i);
1943
+ }
1944
+ return t;
1945
+ }
1946
+ return "items" in e ? e.items.flatMap((t) => {
1947
+ const s = ht(t);
1948
+ return s ? [s] : [];
1949
+ }) : [];
1950
+ }
1951
+ function U(e, t, s) {
1952
+ return e[0] !== t ? false : (s == null ? void 0 : s.where) ? s.where(e) : true;
1953
+ }
1954
+ function Xt(e, t, s) {
1955
+ if (Array.isArray(e)) {
1956
+ for (const i of e) {
1957
+ const n = H(i);
1958
+ if (U(n, t, s))
1959
+ return n;
1960
+ }
1961
+ return;
1962
+ }
1963
+ for (let i = 0; i < e.tagsLength(); i++) {
1964
+ const n = e.tags(i);
1965
+ if (!n) continue;
1966
+ const r = H(n);
1967
+ if (U(r, t, s))
1968
+ return r;
1969
+ }
1970
+ }
1971
+ function os(e, t, s = 1, i) {
1972
+ var _a;
1973
+ const n = typeof s == "number" ? s : 1;
1974
+ return (_a = Xt(e, t, typeof s == "number" ? i : s)) == null ? void 0 : _a[n];
1975
+ }
1976
+ function as(e, t, s = 1, i) {
1977
+ const n = typeof s == "number" ? s : 1, r = typeof s == "number" ? i : s, o = [];
1978
+ if (Array.isArray(e)) {
1979
+ for (const a of e) {
1980
+ const c = H(a);
1981
+ U(c, t, r) && c[n] !== void 0 && o.push(c[n]);
1982
+ }
1983
+ return o;
1984
+ }
1985
+ for (let a = 0; a < e.tagsLength(); a++) {
1986
+ const c = e.tags(a);
1987
+ if (!c) continue;
1988
+ const u = H(c);
1989
+ U(u, t, r) && u[n] !== void 0 && o.push(u[n]);
1990
+ }
1991
+ return o;
1992
+ }
1993
+ function cs(e, t) {
1994
+ const s = /* @__PURE__ */ new Map();
1995
+ if (Array.isArray(e))
1996
+ for (const i of e) {
1997
+ const n = H(i);
1998
+ if (n.length < 2) continue;
1999
+ const r = n[0];
2000
+ if (!U(n, r, t)) continue;
2001
+ const o = s.get(r) || [];
2002
+ o.push(...n.slice(1)), s.set(r, o);
2003
+ }
2004
+ else
2005
+ for (let i = 0; i < e.tagsLength(); i++) {
2006
+ const n = e.tags(i);
2007
+ if (!n) continue;
2008
+ const r = H(n);
2009
+ if (r.length < 2) continue;
2010
+ const o = r[0];
2011
+ if (!U(r, o, t)) continue;
2012
+ const a = s.get(o) || [];
2013
+ a.push(...r.slice(1)), s.set(o, a);
2014
+ }
2015
+ return Object.fromEntries(s);
2016
+ }
2017
+ function Zt(e, t, s, i) {
2018
+ if (!Number.isInteger(e) || e < 0 || e > 65535)
2019
+ throw new Error(`Invalid kind: ${e}`);
2020
+ if (!et(t))
2021
+ throw new Error(`Invalid pubkey hex (expected 64 lowercase hex chars): ${t}`);
2022
+ if (!s || typeof s != "string")
2023
+ throw new Error(`Invalid d tag: ${s}`);
2024
+ return ft.naddrEncode({
2025
+ identifier: s,
2026
+ kind: e,
2027
+ pubkey: t,
2028
+ relays: i && i.length ? i : void 0
2029
+ });
2030
+ }
2031
+ function hs(e, t) {
2032
+ const s = D(e.tags);
2033
+ if (!s)
2034
+ throw new Error(`Missing "d" tag for PRE event of kind ${e.kind}`);
2035
+ return Zt(e.kind, e.pubkey, s, t);
2036
+ }
2037
+ function ps(e) {
2038
+ const t = ft.decode(e);
2039
+ if (t.type !== "naddr")
2040
+ throw new Error(`Invalid naddr type: ${t.type}`);
2041
+ const { identifier: s, kind: i, pubkey: n, relays: r } = t.data;
2042
+ return {
2043
+ kind: i,
2044
+ pubkey: n,
2045
+ d: s,
2046
+ relays: r
2047
+ };
2048
+ }
2049
+ function et(e) {
2050
+ return /^[0-9a-f]{64}$/.test(e);
2051
+ }
2052
+ function Jt(e) {
2053
+ return e.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
2054
+ }
2055
+ function pt(e = 9) {
2056
+ var _a;
2057
+ const t = Math.max(1, Math.min(e, 64));
2058
+ let s;
2059
+ if (typeof globalThis < "u" && ((_a = globalThis.crypto) == null ? void 0 : _a.getRandomValues))
2060
+ s = new Uint8Array(t), globalThis.crypto.getRandomValues(s);
2061
+ else {
2062
+ s = new Uint8Array(t);
2063
+ for (let n = 0; n < t; n++)
2064
+ s[n] = Math.floor(Math.random() * 256);
2065
+ }
2066
+ return (typeof Buffer < "u" ? Buffer.from(s).toString("base64") : btoa(String.fromCharCode(...s))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
2067
+ }
2068
+ function D(e) {
2069
+ for (const t of e)
2070
+ if (t[0] === "d" && typeof t[1] == "string" && t[1].length > 0)
2071
+ return t[1];
2072
+ }
2073
+ function Qt(e, t, s) {
2074
+ const i = D(e);
2075
+ if (i) return i;
2076
+ if (t && t.trim().length > 0) {
2077
+ const n = Jt(t.trim());
2078
+ return n.length > 0 ? n : pt((s == null ? void 0 : s.randomBytes) ?? 9);
2079
+ }
2080
+ return pt((s == null ? void 0 : s.randomBytes) ?? 9);
2081
+ }
2082
+ function wt(e, t, s) {
2083
+ if (!Number.isInteger(e) || e < 0 || e > 65535)
2084
+ throw new Error(`Invalid kind: ${e}`);
2085
+ if (!et(t))
2086
+ throw new Error(`Invalid pubkey hex (expected 64 lowercase hex chars): ${t}`);
2087
+ if (!s || typeof s != "string")
2088
+ throw new Error(`Invalid d tag: ${s}`);
2089
+ return `${e}:${t}:${s}`;
2090
+ }
2091
+ function Yt(e) {
2092
+ const t = e.split(":");
2093
+ if (t.length !== 3)
2094
+ throw new Error(`Invalid a-pointer format: ${e}`);
2095
+ const s = Number(t[0]), i = t[1], n = t[2];
2096
+ if (!Number.isInteger(s))
2097
+ throw new Error(`Invalid kind in a-pointer: ${t[0]}`);
2098
+ if (!et(i))
2099
+ throw new Error(`Invalid pubkey in a-pointer: ${i}`);
2100
+ if (!n)
2101
+ throw new Error(`Invalid d in a-pointer: ${n}`);
2102
+ return { kind: s, pubkey: i, d: n };
2103
+ }
2104
+ function us(e) {
2105
+ const t = D(e.tags);
2106
+ if (!t)
2107
+ throw new Error(`Missing "d" tag for PRE event of kind ${e.kind}`);
2108
+ return wt(e.kind, e.pubkey, t);
2109
+ }
2110
+ function Dt(e, t, s, i) {
2111
+ const n = wt(e, t, s);
2112
+ if (i && i.length > 0) {
2113
+ const r = i.map((o) => encodeURIComponent(o)).join(",");
2114
+ return `naddr-like:${n}?relays=${r}`;
2115
+ }
2116
+ return `naddr-like:${n}`;
2117
+ }
2118
+ function ds(e, t) {
2119
+ const s = D(e.tags);
2120
+ if (!s)
2121
+ throw new Error(`Missing "d" tag for PRE event of kind ${e.kind}`);
2122
+ return Dt(e.kind, e.pubkey, s, t);
2123
+ }
2124
+ function fs(e) {
2125
+ if (!e.startsWith("naddr-like:"))
2126
+ throw new Error(`Invalid naddr-like prefix: ${e}`);
2127
+ const t = e.slice(11), [s, i] = t.split("?", 2), n = Yt(s);
2128
+ if (!i) return { a: n };
2129
+ const o = new URLSearchParams(i).get("relays"), a = o ? o.split(",").map(decodeURIComponent) : void 0;
2130
+ return { a: n, relays: a };
2131
+ }
2132
+ function ls(e) {
2133
+ return Number.isInteger(e) && e >= 3e4 && e < 4e4;
2134
+ }
2135
+ function ts(e, t) {
2136
+ const s = [];
2137
+ let i = false;
2138
+ for (const n of e)
2139
+ !i && n[0] === "d" ? (s.push(["d", t]), i = true) : s.push(n);
2140
+ return i || s.push(["d", t]), s;
2141
+ }
2142
+ function bs(e, t, s) {
2143
+ if (D(e)) return e.slice();
2144
+ const n = Qt(e, t, s);
2145
+ return ts(e, n);
2146
+ }
2147
+ class ss {
2148
+ constructor(t = {}) {
2149
+ this.textEncoder = new TextEncoder(), this.subscriptions = /* @__PURE__ */ new Map(), this.publishes = /* @__PURE__ */ new Map(), this.activePubkey = null, this._pendingSession = null, this.signCB = (_) => {
2150
+ }, this.eventTarget = new EventTarget(), this.relayStatuses = /* @__PURE__ */ new Map(), this.PERPETUAL_SUBSCRIPTIONS = ["notifications", "starterpack"];
2151
+ const s = new MessageChannel(), i = new MessageChannel(), n = new MessageChannel(), r = new MessageChannel(), o = new MessageChannel(), a = new MessageChannel(), c = new MessageChannel(), u = new MessageChannel(), l = !!t.proxy, k = l ? new URL("./connections/proxy.js", import.meta.url) : new URL("./connections/index.js", import.meta.url), w = new URL("./cache/index.js", import.meta.url), W = new URL("./parser/index.js", import.meta.url), d = new URL("./crypto/index.js", import.meta.url);
2152
+ console.log("constructing crates"), this.connections = new Worker(k, { type: "module" }), this.cache = new Worker(w, { type: "module" }), this.parser = new Worker(W, { type: "module" }), this.crypto = new Worker(d, { type: "module" }), console.log("connectionMode", l ? "proxy" : "rust"), console.log(this.connections, this.cache, this.parser, this.crypto), this.connections.postMessage(
2153
+ {
2154
+ type: "init",
2155
+ payload: {
2156
+ mainPort: u.port2,
2157
+ cachePort: r.port1,
2158
+ parserPort: i.port1,
2159
+ cryptoPort: o.port1,
2160
+ ...t.proxy ? { proxy: t.proxy } : {}
2161
+ }
2162
+ },
2163
+ [
2164
+ u.port2,
2165
+ r.port1,
2166
+ i.port1,
2167
+ o.port1
2168
+ ]
2169
+ ), this.cache.postMessage(
2170
+ {
2171
+ type: "init",
2172
+ payload: {
2173
+ parserPort: s.port1,
2174
+ connectionsPort: r.port2
2175
+ }
2176
+ },
2177
+ [s.port1, r.port2]
2178
+ ), this.parserMainPort = c.port1, this.parserMainPort.onmessage = (_) => {
2179
+ const { subId: p, data: I } = _.data;
2180
+ if (!p || !I) {
2181
+ console.log("[main] ignoring message - missing subId or data");
2182
+ return;
2183
+ }
2184
+ const B = this.subscriptions.get(p);
2185
+ if (B) {
2186
+ X.writeBatchedData(B.buffer, I, p) && this.dispatch(`subscription:${p}`, p);
2187
+ return;
2188
+ }
2189
+ const it = this.publishes.get(p);
2190
+ if (it) {
2191
+ X.writeBatchedData(it.buffer, I, p) && this.dispatch(`publish:${p}`, p);
2192
+ return;
2193
+ }
2194
+ console.log("[main] no subscription or publish found for subId:", p);
2195
+ }, this.connectionsMainPort = u.port1, this.connectionsMainPort.onmessage = (_) => {
2196
+ const { type: p, status: I, url: B } = JSON.parse(_.data);
2197
+ p === "relay:status" && B && I ? (this.relayStatuses.set(B, { status: I, timestamp: Date.now() }), this.dispatch("relay:status", { status: I, url: B })) : console.log("[main] ignoring message - type:", p, "url:", B, "status:", I);
2198
+ }, this.parser.postMessage(
2199
+ {
2200
+ type: "init",
2201
+ payload: {
2202
+ connectionsPort: i.port2,
2203
+ cachePort: s.port2,
2204
+ cryptoPort: n.port1,
2205
+ mainPort: c.port2
2206
+ }
2207
+ },
2208
+ [i.port2, s.port2, n.port1, c.port2]
2209
+ ), this.crypto.postMessage(
2210
+ {
2211
+ type: "init",
2212
+ payload: {
2213
+ parserPort: n.port2,
2214
+ connectionsPort: o.port2,
2215
+ mainPort: a.port1
2216
+ }
2217
+ },
2218
+ [n.port2, o.port2, a.port1]
2219
+ ), a.port2.onmessage = (_) => {
2220
+ const p = _.data;
2221
+ p.type === "response" && this.handleCryptoResponse(p);
2222
+ }, this.setupWorkerListener(), queueMicrotask(() => this.restoreSession());
2223
+ }
2224
+ postToWorker(t, s) {
2225
+ s && s.length ? this.parser.postMessage(t, s) : this.parser.postMessage(t);
2226
+ }
2227
+ handleCryptoResponse(t) {
2228
+ var _a, _b, _c, _d;
2229
+ if (t.op === "get_pubkey") {
2230
+ console.log("[main] get_pubkey:", t.ok ? "success" : "failed", t.result), t.ok && (this.activePubkey = t.result, this._discoveredBunkerUrl && ((_a = this._pendingSession) == null ? void 0 : _a.type) === "nip46_qr" && ((_c = (_b = this._pendingSession) == null ? void 0 : _b.payload) == null ? void 0 : _c.clientSecret) ? (console.log("[main] Converting QR to bunker for pubkey:", this.activePubkey), this.saveSession(this.activePubkey, "nip46_bunker", {
2231
+ url: this._discoveredBunkerUrl,
2232
+ clientSecret: this._pendingSession.payload.clientSecret
2233
+ }), this._pendingSession = null, this._discoveredBunkerUrl = null) : this._pendingSession && (this.saveSession(
2234
+ this.activePubkey,
2235
+ this._pendingSession.type,
2236
+ this._pendingSession.payload
2237
+ ), this._pendingSession = null));
2238
+ const s = t.ok && !!this._pendingSession, i = ((_d = this._pendingSession) == null ? void 0 : _d.type) === "privkey" ? this._pendingSession.payload : void 0;
2239
+ this.dispatch("auth", { pubkey: this.activePubkey, hasSigner: s, secretKey: i });
2240
+ } else if (t.op === "sign_event" && t.ok) {
2241
+ const s = JSON.parse(t.result);
2242
+ this.signCB(s);
2243
+ }
2244
+ }
2245
+ setupWorkerListener() {
2246
+ this.parser.onmessage = async (t) => {
2247
+ const s = typeof t.data == "string" ? t.data : void 0;
2248
+ if (s) {
2249
+ if (this.subscriptions.has(s)) {
2250
+ this.dispatch(`subscription:${s}`, s);
2251
+ return;
2252
+ }
2253
+ if (this.publishes.has(s)) {
2254
+ this.dispatch(`publish:${s}`, s);
2255
+ return;
2256
+ }
2257
+ }
2258
+ }, this.crypto.onmessage = async (t) => {
2259
+ var _a, _b, _c;
2260
+ const s = t.data;
2261
+ if (console.log("[main] crypto.onmessage:", s == null ? void 0 : s.type, s), (s == null ? void 0 : s.type) === "signer_ready") {
2262
+ console.log("[main] signer_ready:", s.signer_type, s.pubkey), this.activePubkey = s.pubkey, s.signer_type === "nip46" && s.bunker_url && ((_b = (_a = this._pendingSession) == null ? void 0 : _a.payload) == null ? void 0 : _b.clientSecret) && (console.log("[main] NIP-46 session saved for:", s.pubkey), this.saveSession(s.pubkey, "nip46", {
2263
+ url: s.bunker_url,
2264
+ clientSecret: this._pendingSession.payload.clientSecret
2265
+ }), this._pendingSession = null);
2266
+ const i = ((_c = this._pendingSession) == null ? void 0 : _c.type) === "privkey" ? this._pendingSession.payload : void 0;
2267
+ this._pendingSession && (this.saveSession(s.pubkey, s.signer_type, this._pendingSession.payload), this._pendingSession = null), this.dispatch("auth", { pubkey: s.pubkey, hasSigner: true, secretKey: i });
2268
+ return;
2269
+ }
2270
+ if ((s == null ? void 0 : s.type) === "response") {
2271
+ this.handleCryptoResponse(s);
2272
+ return;
2273
+ }
2274
+ if ((s == null ? void 0 : s.type) === "extension_request") {
2275
+ const { id: i, op: n, payload: r } = s;
2276
+ try {
2277
+ const o = window.nostr;
2278
+ if (!o) throw new Error("NIP-07 extension (window.nostr) not found");
2279
+ let a;
2280
+ switch (n) {
2281
+ case "getPublicKey":
2282
+ a = await o.getPublicKey();
2283
+ break;
2284
+ case "signEvent":
2285
+ a = await o.signEvent(JSON.parse(r));
2286
+ break;
2287
+ case "nip04Encrypt":
2288
+ a = await o.nip04.encrypt(r.pubkey, r.plaintext);
2289
+ break;
2290
+ case "nip04Decrypt":
2291
+ a = await o.nip04.decrypt(r.pubkey, r.ciphertext);
2292
+ break;
2293
+ case "nip44Encrypt":
2294
+ a = await o.nip44.encrypt(r.pubkey, r.plaintext);
2295
+ break;
2296
+ case "nip44Decrypt":
2297
+ a = await o.nip44.decrypt(r.pubkey, r.ciphertext);
2298
+ break;
2299
+ default:
2300
+ throw new Error(`Unknown extension operation: ${n}`);
2301
+ }
2302
+ this.crypto.postMessage({ type: "extension_response", id: i, ok: true, result: a });
2303
+ } catch (o) {
2304
+ this.crypto.postMessage({
2305
+ type: "extension_response",
2306
+ id: i,
2307
+ ok: false,
2308
+ error: o.message || String(o)
2309
+ });
2310
+ }
2311
+ return;
2312
+ }
2313
+ };
2314
+ }
2315
+ createShortId(t) {
2316
+ if (t.length < 64) return t;
2317
+ let s = 0;
2318
+ for (let n = 0; n < t.length; n++) {
2319
+ const r = t.charCodeAt(n);
2320
+ s = (s << 5) - s + r, s = s & s;
2321
+ }
2322
+ return Math.abs(s).toString(36).substring(0, 63);
2323
+ }
2324
+ addEventListener(t, s, i) {
2325
+ this.eventTarget.addEventListener(t, s, i);
2326
+ }
2327
+ removeEventListener(t, s, i) {
2328
+ this.eventTarget.removeEventListener(t, s, i);
2329
+ }
2330
+ dispatch(t, s) {
2331
+ this.eventTarget.dispatchEvent(new CustomEvent(t, { detail: s }));
2332
+ }
2333
+ subscribe(t, s, i) {
2334
+ const n = this.createShortId(t), r = this.subscriptions.get(n);
2335
+ if (r)
2336
+ return r.refCount++, r.buffer;
2337
+ const o = s.reduce((d, _) => d + (_.limit || 100), 0), a = X.calculateBufferSize(o, i.bytesPerEvent), c = new ArrayBuffer(a);
2338
+ X.initializeBuffer(c), this.subscriptions.set(n, { buffer: c, options: i, refCount: 1 });
2339
+ const u = new yt(
2340
+ new gt(i.pipeline || []),
2341
+ i.closeOnEose,
2342
+ i.cacheFirst,
2343
+ i.timeoutMs ? BigInt(i.timeoutMs) : void 0,
2344
+ i.maxEvents,
2345
+ i.skipCache,
2346
+ i.force,
2347
+ i.bytesPerEvent,
2348
+ i.isSlow,
2349
+ i.pagination ? this.textEncoder.encode(i.pagination) : null
2350
+ ), l = new Pt(
2351
+ this.textEncoder.encode(n),
2352
+ s.map(
2353
+ (d) => new Tt(
2354
+ d.ids,
2355
+ d.authors,
2356
+ d.kinds,
2357
+ Object.entries(d.tags || {}).flatMap(
2358
+ ([_, p]) => new nt([_, ...p])
2359
+ ),
2360
+ d.limit,
2361
+ d.since,
2362
+ d.until,
2363
+ this.textEncoder.encode(d.search),
2364
+ d.relays,
2365
+ d.closeOnEOSE,
2366
+ d.cacheFirst,
2367
+ d.noCache
2368
+ )
2369
+ ),
2370
+ u
2371
+ ), k = new Z(C.Subscribe, l), w = new h.Builder(2048);
2372
+ w.finish(k.pack(w));
2373
+ const W = w.asUint8Array();
2374
+ return this.postToWorker({ serializedMessage: W }, [W.buffer]), c;
2375
+ }
2376
+ getBuffer(t) {
2377
+ const s = this.subscriptions.get(t);
2378
+ if (s)
2379
+ return s.refCount++, s.buffer;
2380
+ }
2381
+ /**
2382
+ * Get current relay statuses. Returns a Map of relay URL to status.
2383
+ * Use this for initial state when mounting useRelayStatus.
2384
+ */
2385
+ getRelayStatuses() {
2386
+ return new Map(this.relayStatuses);
2387
+ }
2388
+ unsubscribe(t) {
2389
+ const s = t.length < 64 ? t : this.createShortId(t), i = this.subscriptions.get(s);
2390
+ i && i.refCount--;
2391
+ }
2392
+ publish(t, s, i = []) {
2393
+ const n = new ArrayBuffer(3072);
2394
+ X.initializeBuffer(n);
2395
+ const r = new bt(
2396
+ s.kind,
2397
+ s.created_at,
2398
+ this.textEncoder.encode(s.content),
2399
+ s.tags.map((l) => new nt(l)) || []
2400
+ ), o = new _t(this.textEncoder.encode(t), r, i), a = new Z(C.Publish, o), c = new h.Builder(2048);
2401
+ c.finish(a.pack(c));
2402
+ const u = c.asUint8Array();
2403
+ return this.postToWorker({ serializedMessage: u }, [u.buffer]), this.publishes.set(t, { buffer: n }), n;
2404
+ }
2405
+ setSigner(t, s) {
2406
+ var _a, _b;
2407
+ switch (this._pendingSession = { type: t, payload: s }, console.log("[main] set pending session:", t), t) {
2408
+ case "pubkey":
2409
+ this.activePubkey = s, this.saveSession(this.activePubkey, "pubkey", s), this._pendingSession = null, this.dispatch("auth", { pubkey: this.activePubkey, hasSigner: false });
2410
+ break;
2411
+ case "privkey":
2412
+ this.crypto.postMessage({ type: "set_private_key", payload: s });
2413
+ break;
2414
+ case "nip07":
2415
+ this.crypto.postMessage({ type: "set_nip07" });
2416
+ break;
2417
+ case "nip46":
2418
+ ((_a = s == null ? void 0 : s.url) == null ? void 0 : _a.startsWith("bunker://")) ? this.crypto.postMessage({ type: "set_nip46_bunker", payload: s }) : ((_b = s == null ? void 0 : s.url) == null ? void 0 : _b.startsWith("nostrconnect://")) ? this.crypto.postMessage({ type: "set_nip46_qr", payload: s }) : console.error("[main] Unknown NIP-46 URL format:", s == null ? void 0 : s.url);
2419
+ break;
2420
+ }
2421
+ }
2422
+ signEvent(t, s) {
2423
+ this.signCB = s, this.crypto.postMessage({ type: "sign_event", payload: JSON.stringify(t) });
2424
+ }
2425
+ getPublicKey() {
2426
+ const t = new Z(C.GetPublicKey, new lt()), s = new h.Builder(2048);
2427
+ s.finish(t.pack(s));
2428
+ const i = s.asUint8Array();
2429
+ this.parser.postMessage({ serializedMessage: i }, [i.buffer]);
2430
+ }
2431
+ /**
2432
+ * Generate a cryptographically secure random client secret for NIP-46
2433
+ * Returns a hex-encoded 32-byte private key
2434
+ */
2435
+ generateClientSecret() {
2436
+ const t = new Uint8Array(32);
2437
+ return crypto.getRandomValues(t), Array.from(t, (s) => s.toString(16).padStart(2, "0")).join("");
2438
+ }
2439
+ setNip46Bunker(t, s) {
2440
+ const i = s || this.generateClientSecret();
2441
+ console.log("[main] NIP-46 bunker:", t.slice(0, 50) + "..."), this.setSigner("nip46", { url: t, clientSecret: i });
2442
+ }
2443
+ setNip46QR(t, s) {
2444
+ const i = s || this.generateClientSecret();
2445
+ console.log("[main] NIP-46 QR:", t.slice(0, 50) + "..."), this.setSigner("nip46", { url: t, clientSecret: i });
2446
+ }
2447
+ setNip07() {
2448
+ this.setSigner("nip07", "");
2449
+ }
2450
+ setPubkey(t) {
2451
+ this.setSigner("pubkey", t);
2452
+ }
2453
+ getActivePubkey() {
2454
+ return this.activePubkey;
2455
+ }
2456
+ getSubscriptionCount() {
2457
+ return this.subscriptions.size;
2458
+ }
2459
+ getAccounts() {
2460
+ const t = localStorage.getItem("nostr_signer_accounts") || "{}";
2461
+ try {
2462
+ return JSON.parse(t);
2463
+ } catch {
2464
+ return {};
2465
+ }
2466
+ }
2467
+ switchAccount(t) {
2468
+ const i = this.getAccounts()[t];
2469
+ i && this.setSigner(i.type, i.payload);
2470
+ }
2471
+ saveSession(t, s, i) {
2472
+ console.log("[main] saveSession:", {
2473
+ pubkey: t.slice(0, 16) + "...",
2474
+ type: s,
2475
+ hasClientSecret: !!(i == null ? void 0 : i.clientSecret)
2476
+ });
2477
+ const n = this.getAccounts();
2478
+ n[t] = { type: s, payload: i }, localStorage.setItem("nostr_signer_accounts", JSON.stringify(n)), localStorage.setItem("nostr_active_pubkey", t), console.log("[main] Session saved to localStorage");
2479
+ }
2480
+ restoreSession() {
2481
+ const t = localStorage.getItem("nostr_active_pubkey");
2482
+ t ? this.switchAccount(t) : this.dispatch("auth", { pubkey: null, hasSigner: false });
2483
+ }
2484
+ logout() {
2485
+ this._pendingSession = null, this.activePubkey = null, this.crypto.postMessage({ type: "clear_signer" }), localStorage.removeItem("nostr_active_pubkey"), this.dispatch("logout");
2486
+ }
2487
+ removeAccount() {
2488
+ const t = this.activePubkey;
2489
+ if (!t) return;
2490
+ const s = this.getAccounts();
2491
+ delete s[t], localStorage.setItem("nostr_signer_accounts", JSON.stringify(s));
2492
+ const i = Object.keys(s);
2493
+ if (i.length > 0) {
2494
+ const n = i[0];
2495
+ n && this.switchAccount(n);
2496
+ } else
2497
+ this.logout();
2498
+ }
2499
+ cleanup() {
2500
+ const t = [];
2501
+ for (const [s, i] of this.subscriptions.entries())
2502
+ i.refCount <= 0 && !this.PERPETUAL_SUBSCRIPTIONS.includes(s) && t.push(s);
2503
+ for (const s of t) {
2504
+ const i = new kt(this.textEncoder.encode(s)), n = new Z(C.Unsubscribe, i), r = new h.Builder(256);
2505
+ r.finish(n.pack(r));
2506
+ const o = r.asUint8Array();
2507
+ this.postToWorker({ serializedMessage: o }, [o.buffer]), this.connections.postMessage(s), this.subscriptions.delete(s);
2508
+ }
2509
+ }
2510
+ }
2511
+ function _s(e) {
2512
+ return new ss(e);
2513
+ }
2514
+ let st = null;
2515
+ function gs() {
2516
+ if (!st)
2517
+ throw new Error(
2518
+ "[nipworker] Global manager is not set. Call setManager(createNostrManager(...)) before using hooks."
2519
+ );
2520
+ return st;
2521
+ }
2522
+ function es(e) {
2523
+ st = e;
2524
+ }
2525
+ function ys(e) {
2526
+ es(e);
2527
+ }
2528
+ export {
2529
+ Y as $,
2530
+ X as A,
2531
+ A as B,
2532
+ J as C,
2533
+ Rt as D,
2534
+ g as E,
2535
+ Ot as F,
2536
+ O as G,
2537
+ Nt as H,
2538
+ E as I,
2539
+ Ft as J,
2540
+ z as K,
2541
+ lt as L,
2542
+ F as M,
2543
+ ss as N,
2544
+ Lt as O,
2545
+ C as P,
2546
+ V as Q,
2547
+ Z as R,
2548
+ b as S,
2549
+ xt as T,
2550
+ S as U,
2551
+ Mt as V,
2552
+ G as W,
2553
+ Kt as X,
2554
+ Gt as Y,
2555
+ N as Z,
2556
+ zt as _,
2557
+ ys as a,
2558
+ L as a0,
2559
+ gt as a1,
2560
+ x as a2,
2561
+ Ct as a3,
2562
+ K as a4,
2563
+ qt as a5,
2564
+ v as a6,
2565
+ _t as a7,
2566
+ $ as a8,
2567
+ jt as a9,
2568
+ q as aa,
2569
+ Bt as ab,
2570
+ R as ac,
2571
+ At as ad,
2572
+ M as ae,
2573
+ Vt as af,
2574
+ tt as ag,
2575
+ P as ah,
2576
+ $t as ai,
2577
+ T as aj,
2578
+ Wt as ak,
2579
+ Q as al,
2580
+ m as am,
2581
+ Pt as an,
2582
+ Ht as ao,
2583
+ f as ap,
2584
+ yt as aq,
2585
+ y as ar,
2586
+ bt as as,
2587
+ j as at,
2588
+ kt as au,
2589
+ os as b,
2590
+ _s as c,
2591
+ as as d,
2592
+ Xt as e,
2593
+ cs as f,
2594
+ gs as g,
2595
+ hs as h,
2596
+ et as i,
2597
+ pt as j,
2598
+ D as k,
2599
+ Qt as l,
2600
+ Zt as m,
2601
+ Jt as n,
2602
+ wt as o,
2603
+ ps as p,
2604
+ Yt as q,
2605
+ H as r,
2606
+ es as s,
2607
+ us as t,
2608
+ Dt as u,
2609
+ ds as v,
2610
+ fs as w,
2611
+ ls as x,
2612
+ ts as y,
2613
+ bs as z
2614
+ };