@xyo-network/diviner-address-chain-memory 4.2.1 → 5.0.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,"file":"MemoryDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryDiviner.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACjF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAA;AAEzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAIjE,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,kCAEf;cAEwB,aAAa,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"MemoryDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryDiviner.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACjF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAA;AAEzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAIjE,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,kCAEf;cAEwB,aAAa,CAAC,QAAQ,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;YA0BtE,iBAAiB;CAWhC"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -10,9 +10,9 @@ var MemoryAddressChainDiviner = class extends AddressChainDiviner {
|
|
|
10
10
|
get queryAddress() {
|
|
11
11
|
return assertEx(this.config.address, () => "Missing address");
|
|
12
12
|
}
|
|
13
|
-
async divineHandler(payloads) {
|
|
13
|
+
async divineHandler(payloads = []) {
|
|
14
14
|
const result = [];
|
|
15
|
-
assertEx(
|
|
15
|
+
assertEx(payloads.length === 0, () => "MemoryAddressChainDiviner.divine does not allow payloads to be sent");
|
|
16
16
|
try {
|
|
17
17
|
const archivistIn = await this.archivistInstance();
|
|
18
18
|
const archivist = assertEx(archivistIn, () => "Unable to resolve archivist");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/MemoryDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport type { Hash } from '@xylabs/hex'\nimport type { ArchivistInstance } from '@xyo-network/archivist-model'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { isBoundWitnessWithStorageMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport type { AddressChainDivinerConfig } from '@xyo-network/diviner-address-chain-model'\nimport { AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport type { DivinerParams } from '@xyo-network/diviner-model'\nimport type { AnyConfigSchema } from '@xyo-network/module-model'\nimport type { 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
|
|
1
|
+
{"version":3,"sources":["../../src/MemoryDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport type { Hash } from '@xylabs/hex'\nimport type { ArchivistInstance } from '@xyo-network/archivist-model'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { isBoundWitnessWithStorageMeta } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'\nimport { AddressChainDiviner } from '@xyo-network/diviner-address-chain-abstract'\nimport type { AddressChainDivinerConfig } from '@xyo-network/diviner-address-chain-model'\nimport { AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'\nimport type { DivinerParams } from '@xyo-network/diviner-model'\nimport type { AnyConfigSchema } from '@xyo-network/module-model'\nimport type { 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 === 0, () => '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(isBoundWitnessWithStorageMeta)\n if (result) {\n return result\n }\n index++\n }\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAIzB,SAAS,qCAAqC;AAC9C,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AAEpC,SAAS,uCAAuC;AASzC,IAAM,4BAAN,cAEG,oBAA6B;AAAA,EACrC,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,+BAA+B;AAAA,EAC3G,OAAyB,sBAA8B;AAAA,EAEvD,IAAI,eAAe;AACjB,WAAO,SAAS,KAAK,OAAO,SAAS,MAAM,iBAAiB;AAAA,EAC9D;AAAA,EAEA,MAAyB,cAAc,WAAsB,CAAC,GAAuB;AACnF,UAAM,SAAoB,CAAC;AAC3B,aAAS,SAAS,WAAW,GAAG,MAAM,qEAAqE;AAC3G,QAAI;AACF,YAAM,cAAc,MAAM,KAAK,kBAAkB;AACjD,YAAM,YAAY,SAAS,aAAa,MAAM,6BAA6B;AAC3E,UAAI,cAA2B,SAAS,KAAK,OAAO,WAAW,MAAM,mBAAmB;AACxF,aAAO,eAAe,OAAO,UAAU,KAAK,OAAO,cAAc,MAAO;AAEtE,cAAM,YAAsC,MAAM,KAAK,kBAAkB,CAAC,SAAS,GAAG,WAAW;AACjG,cAAM,YAA6C,oBAAoB,SAAS,SAAS;AACzF,YAAI,WAAW;AACb,iBAAO,KAAK,UAAU,OAAO;AAC7B,wBAAc,UAAU,KAAK,KAAK,YAAY;AAAA,QAChD,OAAO;AAEL,kBAAQ,IAAI,+BAA+B,WAAW,GAAG;AACzD,wBAAc;AAAA,QAChB;AAAA,MACF;AAAA,IACF,SAAS,IAAI;AACX,cAAQ,IAAI,EAAE;AAAA,IAChB;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,kBAAkB,YAAiC,MAA+C;AAE9G,QAAI,QAAQ;AACZ,QAAI,WAAW,KAAK,GAAG;AACrB,YAAM,UAAU,MAAM,WAAW,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,SAAS,6BAA6B;AAC3F,UAAI,QAAQ;AACV,eAAO;AAAA,MACT;AACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/diviner-address-chain-memory",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -28,31 +28,35 @@
|
|
|
28
28
|
},
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@xylabs/assert": "^
|
|
33
|
-
"@xyo-network/boundwitness-model": "^
|
|
34
|
-
"@xyo-network/boundwitness-wrapper": "^
|
|
35
|
-
"@xyo-network/diviner-address-chain-abstract": "^
|
|
36
|
-
"@xyo-network/diviner-address-chain-model": "^
|
|
37
|
-
"@xyo-network/diviner-model": "^
|
|
38
|
-
"@xyo-network/module-model": "^
|
|
39
|
-
"@xyo-network/payload-model": "^
|
|
36
|
+
"@xylabs/assert": "^5.0.0",
|
|
37
|
+
"@xyo-network/boundwitness-model": "^5.0.0",
|
|
38
|
+
"@xyo-network/boundwitness-wrapper": "^5.0.0",
|
|
39
|
+
"@xyo-network/diviner-address-chain-abstract": "^5.0.0",
|
|
40
|
+
"@xyo-network/diviner-address-chain-model": "^5.0.0",
|
|
41
|
+
"@xyo-network/diviner-model": "^5.0.0",
|
|
42
|
+
"@xyo-network/module-model": "^5.0.0",
|
|
43
|
+
"@xyo-network/payload-model": "^5.0.0"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
|
-
"@xylabs/array": "^
|
|
43
|
-
"@xylabs/delay": "^
|
|
44
|
-
"@xylabs/hex": "^
|
|
45
|
-
"@xylabs/ts-scripts-yarn3": "^7.0.
|
|
46
|
-
"@xylabs/tsconfig": "^7.0.
|
|
47
|
-
"@xylabs/vitest-extended": "^
|
|
48
|
-
"@xyo-network/account": "^
|
|
49
|
-
"@xyo-network/archivist-memory": "^
|
|
50
|
-
"@xyo-network/archivist-model": "^
|
|
51
|
-
"@xyo-network/archivist-wrapper": "^
|
|
52
|
-
"@xyo-network/node-memory": "^
|
|
53
|
-
"@xyo-network/node-model": "^
|
|
54
|
-
"@xyo-network/payload-builder": "^
|
|
55
|
-
"@xyo-network/payload-wrapper": "^
|
|
46
|
+
"@xylabs/array": "^5.0.0",
|
|
47
|
+
"@xylabs/delay": "^5.0.0",
|
|
48
|
+
"@xylabs/hex": "^5.0.0",
|
|
49
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.2",
|
|
50
|
+
"@xylabs/tsconfig": "^7.0.2",
|
|
51
|
+
"@xylabs/vitest-extended": "^5.0.0",
|
|
52
|
+
"@xyo-network/account": "^5.0.0",
|
|
53
|
+
"@xyo-network/archivist-memory": "^5.0.0",
|
|
54
|
+
"@xyo-network/archivist-model": "^5.0.0",
|
|
55
|
+
"@xyo-network/archivist-wrapper": "^5.0.0",
|
|
56
|
+
"@xyo-network/node-memory": "^5.0.0",
|
|
57
|
+
"@xyo-network/node-model": "^5.0.0",
|
|
58
|
+
"@xyo-network/payload-builder": "^5.0.0",
|
|
59
|
+
"@xyo-network/payload-wrapper": "^5.0.0",
|
|
56
60
|
"typescript": "^5.8.3",
|
|
57
61
|
"vitest": "^3.2.4"
|
|
58
62
|
},
|
package/src/MemoryDiviner.ts
CHANGED
|
@@ -25,9 +25,9 @@ export class MemoryAddressChainDiviner<
|
|
|
25
25
|
return assertEx(this.config.address, () => 'Missing address')
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
protected override async divineHandler(payloads
|
|
28
|
+
protected override async divineHandler(payloads: Payload[] = []): Promise<Payload[]> {
|
|
29
29
|
const result: Payload[] = []
|
|
30
|
-
assertEx(
|
|
30
|
+
assertEx(payloads.length === 0, () => 'MemoryAddressChainDiviner.divine does not allow payloads to be sent')
|
|
31
31
|
try {
|
|
32
32
|
const archivistIn = await this.archivistInstance()
|
|
33
33
|
const archivist = assertEx(archivistIn, () => 'Unable to resolve archivist')
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import '@xylabs/vitest-extended'
|
|
2
|
+
|
|
3
|
+
import { filterAs } from '@xylabs/array'
|
|
4
|
+
import { assertEx } from '@xylabs/assert'
|
|
5
|
+
import { delay } from '@xylabs/delay'
|
|
6
|
+
import { Account } from '@xyo-network/account'
|
|
7
|
+
import { MemoryArchivist } from '@xyo-network/archivist-memory'
|
|
8
|
+
import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
|
|
9
|
+
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
10
|
+
import { asOptionalBoundWitness, BoundWitnessSchema } from '@xyo-network/boundwitness-model'
|
|
11
|
+
import { AddressChainDivinerConfigSchema } from '@xyo-network/diviner-address-chain-model'
|
|
12
|
+
import { MemoryNode } from '@xyo-network/node-memory'
|
|
13
|
+
import { NodeConfigSchema } from '@xyo-network/node-model'
|
|
14
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
15
|
+
import { PayloadWrapper } from '@xyo-network/payload-wrapper'
|
|
16
|
+
import {
|
|
17
|
+
describe, expect, it,
|
|
18
|
+
} from 'vitest'
|
|
19
|
+
|
|
20
|
+
import { MemoryAddressChainDiviner } from '../MemoryDiviner.ts'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @group module
|
|
24
|
+
* @group diviner
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
describe('MemoryAddressHistoryDiviner', () => {
|
|
28
|
+
describe('divine', () => {
|
|
29
|
+
it('returns divined result', async () => {
|
|
30
|
+
const node = await MemoryNode.create({ account: 'random', config: { schema: NodeConfigSchema } })
|
|
31
|
+
const wrapperAccount = await Account.random()
|
|
32
|
+
const divinerAccount = await Account.random()
|
|
33
|
+
const archivist = await MemoryArchivist.create({
|
|
34
|
+
account: 'random',
|
|
35
|
+
config: { schema: MemoryArchivist.defaultConfigSchema, storeQueries: true },
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const archivistWrapper = ArchivistWrapper.wrap(archivist, wrapperAccount)
|
|
39
|
+
|
|
40
|
+
const wrapperAddress = wrapperAccount.address
|
|
41
|
+
|
|
42
|
+
const payload1 = PayloadWrapper.wrap({ index: 1, schema: 'network.xyo.test' })
|
|
43
|
+
const payload2 = PayloadWrapper.wrap({ index: 2, schema: 'network.xyo.test' })
|
|
44
|
+
const payload3 = PayloadWrapper.wrap({ index: 3, schema: 'network.xyo.test' })
|
|
45
|
+
|
|
46
|
+
for (const payload of [payload1, payload2, payload3]) {
|
|
47
|
+
await delay(2)
|
|
48
|
+
await archivistWrapper.insert([payload.payload])
|
|
49
|
+
}
|
|
50
|
+
const all = await archivist.all()
|
|
51
|
+
expect(all).toBeArrayOfSize(6)
|
|
52
|
+
|
|
53
|
+
const allBWs = filterAs(all, asOptionalBoundWitness)
|
|
54
|
+
const lastBw = allBWs.at(-1)
|
|
55
|
+
expect(lastBw).toBeDefined()
|
|
56
|
+
const startHash = await PayloadBuilder.dataHash(assertEx(lastBw))
|
|
57
|
+
|
|
58
|
+
await node.register(archivist)
|
|
59
|
+
await node.attach(archivist.address)
|
|
60
|
+
const diviner = await MemoryAddressChainDiviner.create({
|
|
61
|
+
account: divinerAccount,
|
|
62
|
+
config: {
|
|
63
|
+
address: wrapperAccount.address,
|
|
64
|
+
archivist: archivist.address,
|
|
65
|
+
schema: AddressChainDivinerConfigSchema,
|
|
66
|
+
startHash,
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
await node.register(diviner)
|
|
70
|
+
await node.attach(diviner.address)
|
|
71
|
+
|
|
72
|
+
const result = (await diviner.divine()) as BoundWitness[]
|
|
73
|
+
expect(result.length).toBe(3)
|
|
74
|
+
expect(result[0].schema).toBe(BoundWitnessSchema)
|
|
75
|
+
expect(result[0].addresses).toContain(wrapperAddress)
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
})
|