@xyo-network/diviner-address-chain-memory 2.110.18 → 2.111.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryDiviner.ts"],"sourcesContent":["export * from './MemoryDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n //was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AAGzB,gCAAqD;AACrD,kCAAoC;AACpC,4CAAoC;AACpC,yCAA2E;AASpE,IAAMA,4BAAN,cAEGC,0DAAAA;EAjBV,OAiBUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,IAAIE,eAAe;AACjB,eAAOC,wBAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,gCAAS,CAACI,UAAUE,QAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,gBAAYT,wBAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,kBAA2BV,wBAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,gDAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,gDAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;","names":["MemoryAddressChainDiviner","AddressChainDiviner","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/MemoryDiviner.ts"],"sourcesContent":["export * from './MemoryDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n // was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AAGzB,gCAAqD;AACrD,kCAAoC;AACpC,4CAAoC;AACpC,yCAA2E;AASpE,IAAMA,4BAAN,cAEGC,0DAAAA;EAjBV,OAiBUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,IAAIE,eAAe;AACjB,eAAOC,wBAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,gCAAS,CAACI,UAAUE,QAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,gBAAYT,wBAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,kBAA2BV,wBAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,gDAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,gDAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;","names":["MemoryAddressChainDiviner","AddressChainDiviner","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta"]}
@@ -62,4 +62,4 @@ var MemoryAddressChainDiviner = class extends AddressChainDiviner {
62
62
  export {
63
63
  MemoryAddressChainDiviner
64
64
  };
65
- //# sourceMappingURL=index.js.map
65
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/MemoryDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n //was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AAGzB,SAAuBC,8BAA8B;AACrD,SAASC,2BAA2B;AACpC,SAASC,2BAA2B;AACpC,SAAoCC,uCAAuC;AASpE,IAAMC,4BAAN,cAEGC,oBAAAA;EAjBV,OAiBUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,IAAIE,eAAe;AACjB,WAAOC,SAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,aAAS,CAACI,UAAUE,QAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,YAAYT,SAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,cAA2BV,SAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,oBAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,sBAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;","names":["assertEx","isBoundWitnessWithMeta","BoundWitnessWrapper","AddressChainDiviner","AddressChainDivinerConfigSchema","MemoryAddressChainDiviner","AddressChainDiviner","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta"]}
1
+ {"version":3,"sources":["../../src/MemoryDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n // was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AAGzB,SAAuBC,8BAA8B;AACrD,SAASC,2BAA2B;AACpC,SAASC,2BAA2B;AACpC,SAAoCC,uCAAuC;AASpE,IAAMC,4BAAN,cAEGC,oBAAAA;EAjBV,OAiBUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,IAAIE,eAAe;AACjB,WAAOC,SAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,aAAS,CAACI,UAAUE,QAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,YAAYT,SAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,cAA2BV,SAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,oBAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,sBAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;","names":["assertEx","isBoundWitnessWithMeta","BoundWitnessWrapper","AddressChainDiviner","AddressChainDivinerConfigSchema","MemoryAddressChainDiviner","AddressChainDiviner","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryDiviner.ts"],"sourcesContent":["export * from './MemoryDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n //was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AAGzB,gCAAqD;AACrD,kCAAoC;AACpC,4CAAoC;AACpC,yCAA2E;AASpE,IAAMA,4BAAN,cAEGC,0DAAAA;EAjBV,OAiBUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,IAAIE,eAAe;AACjB,eAAOC,wBAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,gCAAS,CAACI,UAAUE,QAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,gBAAYT,wBAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,kBAA2BV,wBAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,gDAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,gDAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;","names":["MemoryAddressChainDiviner","AddressChainDiviner","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/MemoryDiviner.ts"],"sourcesContent":["export * from './MemoryDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n // was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AAGzB,gCAAqD;AACrD,kCAAoC;AACpC,4CAAoC;AACpC,yCAA2E;AASpE,IAAMA,4BAAN,cAEGC,0DAAAA;EAjBV,OAiBUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,IAAIE,eAAe;AACjB,eAAOC,wBAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,gCAAS,CAACI,UAAUE,QAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,gBAAYT,wBAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,kBAA2BV,wBAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,gDAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,gDAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;","names":["MemoryAddressChainDiviner","AddressChainDiviner","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta"]}
@@ -62,4 +62,4 @@ var MemoryAddressChainDiviner = class extends AddressChainDiviner {
62
62
  export {
63
63
  MemoryAddressChainDiviner
64
64
  };
65
- //# sourceMappingURL=index.js.map
65
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/MemoryDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n //was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AAGzB,SAAuBC,8BAA8B;AACrD,SAASC,2BAA2B;AACpC,SAASC,2BAA2B;AACpC,SAAoCC,uCAAuC;AASpE,IAAMC,4BAAN,cAEGC,oBAAAA;EAjBV,OAiBUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,IAAIE,eAAe;AACjB,WAAOC,SAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,aAAS,CAACI,UAAUE,QAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,YAAYT,SAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,cAA2BV,SAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,oBAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,sBAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;","names":["assertEx","isBoundWitnessWithMeta","BoundWitnessWrapper","AddressChainDiviner","AddressChainDivinerConfigSchema","MemoryAddressChainDiviner","AddressChainDiviner","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta"]}
1
+ {"version":3,"sources":["../../src/MemoryDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n // was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AAGzB,SAAuBC,8BAA8B;AACrD,SAASC,2BAA2B;AACpC,SAASC,2BAA2B;AACpC,SAAoCC,uCAAuC;AASpE,IAAMC,4BAAN,cAEGC,oBAAAA;EAjBV,OAiBUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,IAAIE,eAAe;AACjB,WAAOC,SAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,aAAS,CAACI,UAAUE,QAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,YAAYT,SAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,cAA2BV,SAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,oBAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,sBAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;","names":["assertEx","isBoundWitnessWithMeta","BoundWitnessWrapper","AddressChainDiviner","AddressChainDivinerConfigSchema","MemoryAddressChainDiviner","AddressChainDiviner","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryDiviner.ts"],"sourcesContent":["export * from './MemoryDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n //was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AAGzB,gCAAqD;AACrD,kCAAoC;AACpC,4CAAoC;AACpC,yCAA2E;AASpE,IAAMA,6BAAN,MAAMA,mCAEHC,0DAAAA;EAIR,IAAIC,eAAe;AACjB,eAAOC,wBAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,gCAAS,EAACI,qCAAUE,SAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,gBAAYT,wBAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,kBAA2BV,wBAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,gDAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,gDAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;AA7CU5B;AACR,cAHWD,4BAGciC,iBAA0B;KAAI,mEAAMA;EAAeC;;AAC5E,cAJWlC,4BAIcmC,uBAA8BD;AAJlD,IAAMlC,4BAAN;","names":["MemoryAddressChainDiviner","AddressChainDiviner","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/MemoryDiviner.ts"],"sourcesContent":["export * from './MemoryDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n // was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AAGzB,gCAAqD;AACrD,kCAAoC;AACpC,4CAAoC;AACpC,yCAA2E;AASpE,IAAMA,6BAAN,MAAMA,mCAEHC,0DAAAA;EAIR,IAAIC,eAAe;AACjB,eAAOC,wBAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,gCAAS,EAACI,qCAAUE,SAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,gBAAYT,wBAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,kBAA2BV,wBAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,gDAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,gDAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;AA7CU5B;AACR,cAHWD,4BAGciC,iBAA0B;KAAI,mEAAMA;EAAeC;;AAC5E,cAJWlC,4BAIcmC,uBAA8BD;AAJlD,IAAMlC,4BAAN;","names":["MemoryAddressChainDiviner","AddressChainDiviner","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema"]}
@@ -66,4 +66,4 @@ var MemoryAddressChainDiviner = _MemoryAddressChainDiviner;
66
66
  export {
67
67
  MemoryAddressChainDiviner
68
68
  };
69
- //# sourceMappingURL=index.js.map
69
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/MemoryDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n // was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AAGzB,SAAuBC,8BAA8B;AACrD,SAASC,2BAA2B;AACpC,SAASC,2BAA2B;AACpC,SAAoCC,uCAAuC;AASpE,IAAMC,6BAAN,MAAMA,mCAEHC,oBAAAA;EAIR,IAAIC,eAAe;AACjB,WAAOC,SAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,aAAS,EAACI,qCAAUE,SAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,YAAYT,SAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,cAA2BV,SAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,oBAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,sBAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;AA7CU5B;AACR,cAHWD,4BAGciC,iBAA0B;KAAI,mEAAMA;EAAeC;;AAC5E,cAJWlC,4BAIcmC,uBAA8BD;AAJlD,IAAMlC,4BAAN;","names":["assertEx","isBoundWitnessWithMeta","BoundWitnessWrapper","AddressChainDiviner","AddressChainDivinerConfigSchema","MemoryAddressChainDiviner","AddressChainDiviner","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema"]}
package/package.json CHANGED
@@ -10,27 +10,27 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^3.6.6",
14
- "@xylabs/hex": "^3.6.6",
15
- "@xyo-network/archivist-model": "^2.110.18",
16
- "@xyo-network/boundwitness-model": "^2.110.18",
17
- "@xyo-network/boundwitness-wrapper": "^2.110.18",
18
- "@xyo-network/diviner-address-chain-abstract": "^2.110.18",
19
- "@xyo-network/diviner-address-chain-model": "^2.110.18",
20
- "@xyo-network/diviner-model": "^2.110.18",
21
- "@xyo-network/module-model": "^2.110.18",
22
- "@xyo-network/payload-model": "^2.110.18"
13
+ "@xylabs/assert": "^3.6.8",
14
+ "@xylabs/hex": "^3.6.8",
15
+ "@xyo-network/archivist-model": "^2.111.0",
16
+ "@xyo-network/boundwitness-model": "^2.111.0",
17
+ "@xyo-network/boundwitness-wrapper": "^2.111.0",
18
+ "@xyo-network/diviner-address-chain-abstract": "^2.111.0",
19
+ "@xyo-network/diviner-address-chain-model": "^2.111.0",
20
+ "@xyo-network/diviner-model": "^2.111.0",
21
+ "@xyo-network/module-model": "^2.111.0",
22
+ "@xyo-network/payload-model": "^2.111.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@xylabs/ts-scripts-yarn3": "^3.14.1",
26
- "@xylabs/tsconfig": "^3.14.1",
27
- "@xyo-network/account": "^2.110.18",
28
- "@xyo-network/archivist-memory": "^2.110.18",
29
- "@xyo-network/archivist-wrapper": "^2.110.18",
30
- "@xyo-network/node-memory": "^2.110.18",
31
- "@xyo-network/node-model": "^2.110.18",
32
- "@xyo-network/payload-builder": "^2.110.18",
33
- "@xyo-network/payload-wrapper": "^2.110.18",
25
+ "@xylabs/ts-scripts-yarn3": "^3.15.5",
26
+ "@xylabs/tsconfig": "^3.15.5",
27
+ "@xyo-network/account": "^2.111.0",
28
+ "@xyo-network/archivist-memory": "^2.111.0",
29
+ "@xyo-network/archivist-wrapper": "^2.111.0",
30
+ "@xyo-network/node-memory": "^2.111.0",
31
+ "@xyo-network/node-model": "^2.111.0",
32
+ "@xyo-network/payload-builder": "^2.111.0",
33
+ "@xyo-network/payload-wrapper": "^2.111.0",
34
34
  "typescript": "^5.5.4"
35
35
  },
36
36
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "import": {
46
46
  "types": "./dist/browser/index.d.mts",
47
- "default": "./dist/browser/index.js"
47
+ "default": "./dist/browser/index.mjs"
48
48
  }
49
49
  },
50
50
  "node": {
@@ -54,14 +54,14 @@
54
54
  },
55
55
  "import": {
56
56
  "types": "./dist/node/index.d.mts",
57
- "default": "./dist/node/index.js"
57
+ "default": "./dist/node/index.mjs"
58
58
  }
59
59
  }
60
60
  },
61
61
  "./package.json": "./package.json"
62
62
  },
63
63
  "main": "dist/node/index.cjs",
64
- "module": "dist/node/index.js",
64
+ "module": "dist/node/index.mjs",
65
65
  "homepage": "https://xyo.network",
66
66
  "license": "LGPL-3.0-only",
67
67
  "publishConfig": {
@@ -72,6 +72,6 @@
72
72
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
73
73
  },
74
74
  "sideEffects": false,
75
- "version": "2.110.18",
75
+ "version": "2.111.0",
76
76
  "type": "module"
77
77
  }
@@ -38,7 +38,7 @@ export class MemoryAddressChainDiviner<
38
38
  result.push(bwWrapper.payload)
39
39
  currentHash = bwWrapper.prev(this.queryAddress)
40
40
  } else {
41
- //was not a bound witness - bail
41
+ // was not a bound witness - bail
42
42
  console.log(`Hash is not a BoundWitness [${currentHash}]`)
43
43
  currentHash = null
44
44
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/MemoryDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness, isBoundWitnessWithMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport { AddressChainDivinerConfig, AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport { DivinerParams } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\n// This diviner returns the most recent boundwitness signed by the address that can be found\n// if multiple broken chains are found, all the heads are returned\nexport type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>\n\nexport class MemoryAddressChainDiviner<\n TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams,\n> extends AddressChainDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, AddressChainDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = AddressChainDivinerConfigSchema\n\n get queryAddress() {\n return assertEx(this.config.address, () => 'Missing address')\n }\n\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const result: Payload[] = []\n assertEx(!payloads?.length, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')\n try {\n const archivistIn = await this.archivistInstance()\n const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')\n let currentHash: Hash | null = assertEx(this.config.startHash, () => 'Missing startHash')\n while (currentHash && result.length < (this.config.maxResults ?? 1000)) {\n console.log(`currentHash: ${currentHash}`)\n const bwPayload: BoundWitness | undefined = await this.archivistFindHash([archivist], currentHash)\n const bwWrapper: BoundWitnessWrapper | undefined = BoundWitnessWrapper.tryParse(bwPayload)\n if (bwWrapper) {\n result.push(bwWrapper.payload)\n currentHash = bwWrapper.prev(this.queryAddress)\n } else {\n //was not a bound witness - bail\n console.log(`Hash is not a BoundWitness [${currentHash}]`)\n currentHash = null\n }\n }\n } catch (ex) {\n console.log(ex)\n }\n return result\n }\n\n private async archivistFindHash(archivists: ArchivistInstance[], hash: Hash): Promise<BoundWitness | undefined> {\n console.log('archivistFindHash')\n let index = 0\n if (archivists[index]) {\n const result = (await archivists[index].get([hash])).findLast(isBoundWitnessWithMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AAGzB,SAAuBC,8BAA8B;AACrD,SAASC,2BAA2B;AACpC,SAASC,2BAA2B;AACpC,SAAoCC,uCAAuC;AASpE,IAAMC,6BAAN,MAAMA,mCAEHC,oBAAAA;EAIR,IAAIC,eAAe;AACjB,WAAOC,SAAS,KAAKC,OAAOC,SAAS,MAAM,iBAAA;EAC7C;EAEA,MAAyBC,cAAcC,UAA0C;AAC/E,UAAMC,SAAoB,CAAA;AAC1BL,aAAS,EAACI,qCAAUE,SAAQ,MAAM,qEAAA;AAClC,QAAI;AACF,YAAMC,cAAc,MAAM,KAAKC,kBAAiB;AAChD,YAAMC,YAAYT,SAASO,aAAa,MAAM,6BAAA;AAC9C,UAAIG,cAA2BV,SAAS,KAAKC,OAAOU,WAAW,MAAM,mBAAA;AACrE,aAAOD,eAAeL,OAAOC,UAAU,KAAKL,OAAOW,cAAc,MAAO;AACtEC,gBAAQC,IAAI,gBAAgBJ,WAAAA,EAAa;AACzC,cAAMK,YAAsC,MAAM,KAAKC,kBAAkB;UAACP;WAAYC,WAAAA;AACtF,cAAMO,YAA6CC,oBAAoBC,SAASJ,SAAAA;AAChF,YAAIE,WAAW;AACbZ,iBAAOe,KAAKH,UAAUI,OAAO;AAC7BX,wBAAcO,UAAUK,KAAK,KAAKvB,YAAY;QAChD,OAAO;AAELc,kBAAQC,IAAI,+BAA+BJ,WAAAA,GAAc;AACzDA,wBAAc;QAChB;MACF;IACF,SAASa,IAAI;AACXV,cAAQC,IAAIS,EAAAA;IACd;AACA,WAAOlB;EACT;EAEA,MAAcW,kBAAkBQ,YAAiCC,MAA+C;AAC9GZ,YAAQC,IAAI,mBAAA;AACZ,QAAIY,QAAQ;AACZ,QAAIF,WAAWE,KAAAA,GAAQ;AACrB,YAAMrB,UAAU,MAAMmB,WAAWE,KAAAA,EAAOC,IAAI;QAACF;OAAK,GAAGG,SAASC,sBAAAA;AAC9D,UAAIxB,QAAQ;AACV,eAAOA;MACT;AACAqB;IACF;EACF;AACF;AA7CU5B;AACR,cAHWD,4BAGciC,iBAA0B;KAAI,mEAAMA;EAAeC;;AAC5E,cAJWlC,4BAIcmC,uBAA8BD;AAJlD,IAAMlC,4BAAN;","names":["assertEx","isBoundWitnessWithMeta","BoundWitnessWrapper","AddressChainDiviner","AddressChainDivinerConfigSchema","MemoryAddressChainDiviner","AddressChainDiviner","queryAddress","assertEx","config","address","divineHandler","payloads","result","length","archivistIn","archivistInstance","archivist","currentHash","startHash","maxResults","console","log","bwPayload","archivistFindHash","bwWrapper","BoundWitnessWrapper","tryParse","push","payload","prev","ex","archivists","hash","index","get","findLast","isBoundWitnessWithMeta","configSchemas","AddressChainDivinerConfigSchema","defaultConfigSchema"]}