@xyo-network/diviner-address-chain-memory 2.99.2 → 2.99.3
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/neutral/MemoryDiviner.d.cts +14 -0
- package/dist/neutral/MemoryDiviner.d.cts.map +1 -0
- package/dist/neutral/MemoryDiviner.d.mts +14 -0
- package/dist/neutral/MemoryDiviner.d.mts.map +1 -0
- package/dist/neutral/MemoryDiviner.d.ts +14 -0
- package/dist/neutral/MemoryDiviner.d.ts.map +1 -0
- package/dist/neutral/index.cjs +86 -0
- package/dist/neutral/index.cjs.map +1 -0
- package/dist/neutral/index.d.cts +2 -0
- package/dist/neutral/index.d.cts.map +1 -0
- package/dist/neutral/index.d.mts +2 -0
- package/dist/neutral/index.d.mts.map +1 -0
- package/dist/neutral/index.d.ts +2 -0
- package/dist/neutral/index.d.ts.map +1 -0
- package/dist/neutral/index.js +65 -0
- package/dist/neutral/index.js.map +1 -0
- package/package.json +20 -20
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract';
|
|
2
|
+
import { AddressChainDivinerConfig } from '@xyo-network/diviner-address-chain-model';
|
|
3
|
+
import { DivinerParams } from '@xyo-network/diviner-model';
|
|
4
|
+
import { AnyConfigSchema } from '@xyo-network/module-model';
|
|
5
|
+
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
6
|
+
export type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>;
|
|
7
|
+
export declare class MemoryAddressChainDiviner<TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams> extends AddressChainDiviner<TParams> {
|
|
8
|
+
static readonly configSchemas: Schema[];
|
|
9
|
+
static readonly defaultConfigSchema: Schema;
|
|
10
|
+
get queryAddress(): Lowercase<string>;
|
|
11
|
+
protected divineHandler(payloads?: Payload[]): Promise<Payload[]>;
|
|
12
|
+
private archivistFindHash;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=MemoryDiviner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACjF,OAAO,EAAE,yBAAyB,EAAmC,MAAM,0CAA0C,CAAA;AACrH,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAI5D,MAAM,MAAM,+BAA+B,GAAG,aAAa,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC,CAAA;AAEvG,qBAAa,yBAAyB,CACpC,OAAO,SAAS,+BAA+B,GAAG,+BAA+B,CACjF,SAAQ,mBAAmB,CAAC,OAAO,CAAC;IACpC,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA4D;IAC5G,gBAAyB,mBAAmB,EAAE,MAAM,CAAkC;IAEtF,IAAI,YAAY,sBAEf;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;YA0BlE,iBAAiB;CAWhC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract';
|
|
2
|
+
import { AddressChainDivinerConfig } from '@xyo-network/diviner-address-chain-model';
|
|
3
|
+
import { DivinerParams } from '@xyo-network/diviner-model';
|
|
4
|
+
import { AnyConfigSchema } from '@xyo-network/module-model';
|
|
5
|
+
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
6
|
+
export type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>;
|
|
7
|
+
export declare class MemoryAddressChainDiviner<TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams> extends AddressChainDiviner<TParams> {
|
|
8
|
+
static readonly configSchemas: Schema[];
|
|
9
|
+
static readonly defaultConfigSchema: Schema;
|
|
10
|
+
get queryAddress(): Lowercase<string>;
|
|
11
|
+
protected divineHandler(payloads?: Payload[]): Promise<Payload[]>;
|
|
12
|
+
private archivistFindHash;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=MemoryDiviner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACjF,OAAO,EAAE,yBAAyB,EAAmC,MAAM,0CAA0C,CAAA;AACrH,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAI5D,MAAM,MAAM,+BAA+B,GAAG,aAAa,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC,CAAA;AAEvG,qBAAa,yBAAyB,CACpC,OAAO,SAAS,+BAA+B,GAAG,+BAA+B,CACjF,SAAQ,mBAAmB,CAAC,OAAO,CAAC;IACpC,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA4D;IAC5G,gBAAyB,mBAAmB,EAAE,MAAM,CAAkC;IAEtF,IAAI,YAAY,sBAEf;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;YA0BlE,iBAAiB;CAWhC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract';
|
|
2
|
+
import { AddressChainDivinerConfig } from '@xyo-network/diviner-address-chain-model';
|
|
3
|
+
import { DivinerParams } from '@xyo-network/diviner-model';
|
|
4
|
+
import { AnyConfigSchema } from '@xyo-network/module-model';
|
|
5
|
+
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
6
|
+
export type MemoryAddressChainDivinerParams = DivinerParams<AnyConfigSchema<AddressChainDivinerConfig>>;
|
|
7
|
+
export declare class MemoryAddressChainDiviner<TParams extends MemoryAddressChainDivinerParams = MemoryAddressChainDivinerParams> extends AddressChainDiviner<TParams> {
|
|
8
|
+
static readonly configSchemas: Schema[];
|
|
9
|
+
static readonly defaultConfigSchema: Schema;
|
|
10
|
+
get queryAddress(): Lowercase<string>;
|
|
11
|
+
protected divineHandler(payloads?: Payload[]): Promise<Payload[]>;
|
|
12
|
+
private archivistFindHash;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=MemoryDiviner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACjF,OAAO,EAAE,yBAAyB,EAAmC,MAAM,0CAA0C,CAAA;AACrH,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAI5D,MAAM,MAAM,+BAA+B,GAAG,aAAa,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC,CAAA;AAEvG,qBAAa,yBAAyB,CACpC,OAAO,SAAS,+BAA+B,GAAG,+BAA+B,CACjF,SAAQ,mBAAmB,CAAC,OAAO,CAAC;IACpC,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA4D;IAC5G,gBAAyB,mBAAmB,EAAE,MAAM,CAAkC;IAEtF,IAAI,YAAY,sBAEf;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;YA0BlE,iBAAiB;CAWhC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
MemoryAddressChainDiviner: () => MemoryAddressChainDiviner
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
28
|
+
// src/MemoryDiviner.ts
|
|
29
|
+
var import_assert = require("@xylabs/assert");
|
|
30
|
+
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
31
|
+
var import_boundwitness_wrapper = require("@xyo-network/boundwitness-wrapper");
|
|
32
|
+
var import_diviner_address_chain_abstract = require("@xyo-network/diviner-address-chain-abstract");
|
|
33
|
+
var import_diviner_address_chain_model = require("@xyo-network/diviner-address-chain-model");
|
|
34
|
+
var MemoryAddressChainDiviner = class extends import_diviner_address_chain_abstract.AddressChainDiviner {
|
|
35
|
+
static {
|
|
36
|
+
__name(this, "MemoryAddressChainDiviner");
|
|
37
|
+
}
|
|
38
|
+
static configSchemas = [
|
|
39
|
+
...super.configSchemas,
|
|
40
|
+
import_diviner_address_chain_model.AddressChainDivinerConfigSchema
|
|
41
|
+
];
|
|
42
|
+
static defaultConfigSchema = import_diviner_address_chain_model.AddressChainDivinerConfigSchema;
|
|
43
|
+
get queryAddress() {
|
|
44
|
+
return (0, import_assert.assertEx)(this.config.address, () => "Missing address");
|
|
45
|
+
}
|
|
46
|
+
async divineHandler(payloads) {
|
|
47
|
+
const result = [];
|
|
48
|
+
(0, import_assert.assertEx)(!payloads?.length, () => "MemoryAddressChainDiviner.divine does not allow payloads to be sent");
|
|
49
|
+
try {
|
|
50
|
+
const archivistIn = await this.archivistInstance();
|
|
51
|
+
const archivist = (0, import_assert.assertEx)(archivistIn, () => "Unable to resolve archivist");
|
|
52
|
+
let currentHash = (0, import_assert.assertEx)(this.config.startHash, () => "Missing startHash");
|
|
53
|
+
while (currentHash && result.length < (this.config.maxResults ?? 1e3)) {
|
|
54
|
+
console.log(`currentHash: ${currentHash}`);
|
|
55
|
+
const bwPayload = await this.archivistFindHash([
|
|
56
|
+
archivist
|
|
57
|
+
], currentHash);
|
|
58
|
+
const bwWrapper = import_boundwitness_wrapper.BoundWitnessWrapper.tryParse(bwPayload);
|
|
59
|
+
if (bwWrapper) {
|
|
60
|
+
result.push(bwWrapper.payload);
|
|
61
|
+
currentHash = bwWrapper.prev(this.queryAddress);
|
|
62
|
+
} else {
|
|
63
|
+
console.log(`Hash is not a BoundWitness [${currentHash}]`);
|
|
64
|
+
currentHash = null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} catch (ex) {
|
|
68
|
+
console.log(ex);
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
async archivistFindHash(archivists, hash) {
|
|
73
|
+
console.log("archivistFindHash");
|
|
74
|
+
let index = 0;
|
|
75
|
+
if (archivists[index]) {
|
|
76
|
+
const result = (await archivists[index].get([
|
|
77
|
+
hash
|
|
78
|
+
])).filter(import_boundwitness_model.isBoundWitnessWithMeta).pop();
|
|
79
|
+
if (result) {
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
index++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/MemoryDiviner.ts"],"sourcesContent":["export * from './MemoryDiviner'\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])).filter(isBoundWitnessWithMeta).pop()\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,OAAOC,gDAAAA,EAAwBC,IAAG;AACvF,UAAIzB,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","filter","isBoundWitnessWithMeta","pop"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/MemoryDiviner.ts
|
|
5
|
+
import { assertEx } from "@xylabs/assert";
|
|
6
|
+
import { isBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
|
|
7
|
+
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
8
|
+
import { AddressChainDiviner } from "@xyo-network/diviner-address-chain-abstract";
|
|
9
|
+
import { AddressChainDivinerConfigSchema } from "@xyo-network/diviner-address-chain-model";
|
|
10
|
+
var MemoryAddressChainDiviner = class extends AddressChainDiviner {
|
|
11
|
+
static {
|
|
12
|
+
__name(this, "MemoryAddressChainDiviner");
|
|
13
|
+
}
|
|
14
|
+
static configSchemas = [
|
|
15
|
+
...super.configSchemas,
|
|
16
|
+
AddressChainDivinerConfigSchema
|
|
17
|
+
];
|
|
18
|
+
static defaultConfigSchema = AddressChainDivinerConfigSchema;
|
|
19
|
+
get queryAddress() {
|
|
20
|
+
return assertEx(this.config.address, () => "Missing address");
|
|
21
|
+
}
|
|
22
|
+
async divineHandler(payloads) {
|
|
23
|
+
const result = [];
|
|
24
|
+
assertEx(!payloads?.length, () => "MemoryAddressChainDiviner.divine does not allow payloads to be sent");
|
|
25
|
+
try {
|
|
26
|
+
const archivistIn = await this.archivistInstance();
|
|
27
|
+
const archivist = assertEx(archivistIn, () => "Unable to resolve archivist");
|
|
28
|
+
let currentHash = assertEx(this.config.startHash, () => "Missing startHash");
|
|
29
|
+
while (currentHash && result.length < (this.config.maxResults ?? 1e3)) {
|
|
30
|
+
console.log(`currentHash: ${currentHash}`);
|
|
31
|
+
const bwPayload = await this.archivistFindHash([
|
|
32
|
+
archivist
|
|
33
|
+
], currentHash);
|
|
34
|
+
const bwWrapper = BoundWitnessWrapper.tryParse(bwPayload);
|
|
35
|
+
if (bwWrapper) {
|
|
36
|
+
result.push(bwWrapper.payload);
|
|
37
|
+
currentHash = bwWrapper.prev(this.queryAddress);
|
|
38
|
+
} else {
|
|
39
|
+
console.log(`Hash is not a BoundWitness [${currentHash}]`);
|
|
40
|
+
currentHash = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (ex) {
|
|
44
|
+
console.log(ex);
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
async archivistFindHash(archivists, hash) {
|
|
49
|
+
console.log("archivistFindHash");
|
|
50
|
+
let index = 0;
|
|
51
|
+
if (archivists[index]) {
|
|
52
|
+
const result = (await archivists[index].get([
|
|
53
|
+
hash
|
|
54
|
+
])).filter(isBoundWitnessWithMeta).pop();
|
|
55
|
+
if (result) {
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
index++;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export {
|
|
63
|
+
MemoryAddressChainDiviner
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=index.js.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])).filter(isBoundWitnessWithMeta).pop()\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,OAAOC,sBAAAA,EAAwBC,IAAG;AACvF,UAAIzB,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","filter","isBoundWitnessWithMeta","pop"]}
|
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.
|
|
14
|
-
"@xylabs/hex": "^3.
|
|
15
|
-
"@xyo-network/archivist-model": "~2.99.
|
|
16
|
-
"@xyo-network/boundwitness-model": "~2.99.
|
|
17
|
-
"@xyo-network/boundwitness-wrapper": "~2.99.
|
|
18
|
-
"@xyo-network/diviner-address-chain-abstract": "~2.99.
|
|
19
|
-
"@xyo-network/diviner-address-chain-model": "~2.99.
|
|
20
|
-
"@xyo-network/diviner-model": "~2.99.
|
|
21
|
-
"@xyo-network/module-model": "~2.99.
|
|
22
|
-
"@xyo-network/payload-model": "~2.99.
|
|
13
|
+
"@xylabs/assert": "^3.3.2",
|
|
14
|
+
"@xylabs/hex": "^3.3.2",
|
|
15
|
+
"@xyo-network/archivist-model": "~2.99.3",
|
|
16
|
+
"@xyo-network/boundwitness-model": "~2.99.3",
|
|
17
|
+
"@xyo-network/boundwitness-wrapper": "~2.99.3",
|
|
18
|
+
"@xyo-network/diviner-address-chain-abstract": "~2.99.3",
|
|
19
|
+
"@xyo-network/diviner-address-chain-model": "~2.99.3",
|
|
20
|
+
"@xyo-network/diviner-model": "~2.99.3",
|
|
21
|
+
"@xyo-network/module-model": "~2.99.3",
|
|
22
|
+
"@xyo-network/payload-model": "~2.99.3"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@xylabs/ts-scripts-yarn3": "^3.
|
|
26
|
-
"@xylabs/tsconfig": "^3.
|
|
27
|
-
"@xyo-network/account": "~2.99.
|
|
28
|
-
"@xyo-network/archivist-memory": "~2.99.
|
|
29
|
-
"@xyo-network/archivist-wrapper": "~2.99.
|
|
30
|
-
"@xyo-network/node-memory": "~2.99.
|
|
31
|
-
"@xyo-network/node-model": "~2.99.
|
|
32
|
-
"@xyo-network/payload-builder": "~2.99.
|
|
33
|
-
"@xyo-network/payload-wrapper": "~2.99.
|
|
25
|
+
"@xylabs/ts-scripts-yarn3": "^3.10.0",
|
|
26
|
+
"@xylabs/tsconfig": "^3.10.0",
|
|
27
|
+
"@xyo-network/account": "~2.99.3",
|
|
28
|
+
"@xyo-network/archivist-memory": "~2.99.3",
|
|
29
|
+
"@xyo-network/archivist-wrapper": "~2.99.3",
|
|
30
|
+
"@xyo-network/node-memory": "~2.99.3",
|
|
31
|
+
"@xyo-network/node-model": "~2.99.3",
|
|
32
|
+
"@xyo-network/payload-builder": "~2.99.3",
|
|
33
|
+
"@xyo-network/payload-wrapper": "~2.99.3",
|
|
34
34
|
"typescript": "^5.4.5"
|
|
35
35
|
},
|
|
36
36
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
@@ -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.99.
|
|
75
|
+
"version": "2.99.3",
|
|
76
76
|
"type": "module"
|
|
77
77
|
}
|