@bsv/overlay-express 2.2.1 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/cjs/mod.js +10 -1
- package/dist/cjs/mod.js.map +1 -1
- package/dist/cjs/package.json +12 -11
- package/dist/cjs/src/BanAwareDiscoveryStorage.js +78 -0
- package/dist/cjs/src/BanAwareDiscoveryStorage.js.map +1 -0
- package/dist/cjs/src/BanAwareTopicManager.js +71 -0
- package/dist/cjs/src/BanAwareTopicManager.js.map +1 -0
- package/dist/cjs/src/OverlayExpress.js +375 -96
- package/dist/cjs/src/OverlayExpress.js.map +1 -1
- package/dist/cjs/src/OverlayMonitor.js +464 -0
- package/dist/cjs/src/OverlayMonitor.js.map +1 -0
- package/dist/cjs/src/ReorgStream.js +193 -0
- package/dist/cjs/src/ReorgStream.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/mod.js +3 -0
- package/dist/esm/mod.js.map +1 -1
- package/dist/esm/src/BanAwareDiscoveryStorage.js +79 -0
- package/dist/esm/src/BanAwareDiscoveryStorage.js.map +1 -0
- package/dist/esm/src/BanAwareTopicManager.js +71 -0
- package/dist/esm/src/BanAwareTopicManager.js.map +1 -0
- package/dist/esm/src/OverlayExpress.js +375 -94
- package/dist/esm/src/OverlayExpress.js.map +1 -1
- package/dist/esm/src/OverlayMonitor.js +458 -0
- package/dist/esm/src/OverlayMonitor.js.map +1 -0
- package/dist/esm/src/ReorgStream.js +190 -0
- package/dist/esm/src/ReorgStream.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +4 -1
- package/dist/types/mod.d.ts.map +1 -1
- package/dist/types/src/BanAwareDiscoveryStorage.d.ts +36 -0
- package/dist/types/src/BanAwareDiscoveryStorage.d.ts.map +1 -0
- package/dist/types/src/BanAwareTopicManager.d.ts +28 -0
- package/dist/types/src/BanAwareTopicManager.d.ts.map +1 -0
- package/dist/types/src/OverlayExpress.d.ts +82 -4
- package/dist/types/src/OverlayExpress.d.ts.map +1 -1
- package/dist/types/src/OverlayMonitor.d.ts +169 -0
- package/dist/types/src/OverlayMonitor.d.ts.map +1 -0
- package/dist/types/src/ReorgStream.d.ts +74 -0
- package/dist/types/src/ReorgStream.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/mod.ts +20 -1
- package/package.json +12 -11
- package/src/BanAwareDiscoveryStorage.ts +91 -0
- package/src/BanAwareTopicManager.ts +87 -0
- package/src/OverlayExpress.ts +461 -102
- package/src/OverlayMonitor.ts +657 -0
- package/src/ReorgStream.ts +221 -0
- package/src/__tests__/BanAwareDiscoveryStorage.test.ts +131 -0
- package/src/__tests__/BanAwareTopicManager.test.ts +132 -0
- package/src/__tests__/OverlayExpress.test.ts +86 -1
- package/src/__tests__/OverlayMonitor.test.ts +181 -0
- package/src/__tests__/ReorgStream.test.ts +66 -0
package/README.md
CHANGED
|
@@ -116,6 +116,39 @@ server.registerHealthCheck({
|
|
|
116
116
|
|
|
117
117
|
The janitor service also understands the richer `/health` response format, so existing SHIP/SLAP health validation remains compatible.
|
|
118
118
|
|
|
119
|
+
### Overlay Monitor
|
|
120
|
+
|
|
121
|
+
`OverlayMonitor` provides a reusable worker for monitoring Overlay Express lookup behavior. It posts configured `/lookup` probes to any Overlay Express deployment, measures response size, parses returned BEEF, and reports whether responsive output transactions have direct Merkle proofs or are being served with deeper proof ancestry.
|
|
122
|
+
|
|
123
|
+
This is intended to be run by deployments as a long-running monitor process or by cluster scheduling. It is not tied to a specific deployment platform.
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { OverlayMonitor } from '@bsv/overlay-express'
|
|
127
|
+
|
|
128
|
+
const monitor = new OverlayMonitor({
|
|
129
|
+
intervalMs: 24 * 60 * 60 * 1000,
|
|
130
|
+
targets: [
|
|
131
|
+
{
|
|
132
|
+
name: 'example-overlay',
|
|
133
|
+
baseUrl: 'https://overlay.example',
|
|
134
|
+
probes: [
|
|
135
|
+
{
|
|
136
|
+
name: 'example-topic',
|
|
137
|
+
service: 'ls_example',
|
|
138
|
+
query: { topic: 'tm_example' },
|
|
139
|
+
maxOutputs: 20
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
onReport: async report => {
|
|
145
|
+
console.log(JSON.stringify(report.summary))
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
monitor.start()
|
|
150
|
+
```
|
|
151
|
+
|
|
119
152
|
## License
|
|
120
153
|
|
|
121
154
|
The license for the code in this repository is the Open BSV License. Refer to [LICENSE.txt](./LICENSE.txt) for the license text.
|
package/dist/cjs/mod.js
CHANGED
|
@@ -3,13 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.JanitorService = exports.BanAwareLookupWrapper = exports.BanService = exports.default = void 0;
|
|
6
|
+
exports.analyzeOverlayLookupResponse = exports.analyzeOverlayAnchorTip = exports.OverlayMonitor = exports.JanitorService = exports.BanAwareSLAPStorage = exports.BanAwareSHIPStorage = exports.BanAwareTopicManager = exports.BanAwareLookupWrapper = exports.BanService = exports.default = void 0;
|
|
7
7
|
var OverlayExpress_js_1 = require("./src/OverlayExpress.js");
|
|
8
8
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(OverlayExpress_js_1).default; } });
|
|
9
9
|
var BanService_js_1 = require("./src/BanService.js");
|
|
10
10
|
Object.defineProperty(exports, "BanService", { enumerable: true, get: function () { return BanService_js_1.BanService; } });
|
|
11
11
|
var BanAwareLookupWrapper_js_1 = require("./src/BanAwareLookupWrapper.js");
|
|
12
12
|
Object.defineProperty(exports, "BanAwareLookupWrapper", { enumerable: true, get: function () { return BanAwareLookupWrapper_js_1.BanAwareLookupWrapper; } });
|
|
13
|
+
var BanAwareTopicManager_js_1 = require("./src/BanAwareTopicManager.js");
|
|
14
|
+
Object.defineProperty(exports, "BanAwareTopicManager", { enumerable: true, get: function () { return BanAwareTopicManager_js_1.BanAwareTopicManager; } });
|
|
15
|
+
var BanAwareDiscoveryStorage_js_1 = require("./src/BanAwareDiscoveryStorage.js");
|
|
16
|
+
Object.defineProperty(exports, "BanAwareSHIPStorage", { enumerable: true, get: function () { return BanAwareDiscoveryStorage_js_1.BanAwareSHIPStorage; } });
|
|
17
|
+
Object.defineProperty(exports, "BanAwareSLAPStorage", { enumerable: true, get: function () { return BanAwareDiscoveryStorage_js_1.BanAwareSLAPStorage; } });
|
|
13
18
|
var JanitorService_js_1 = require("./src/JanitorService.js");
|
|
14
19
|
Object.defineProperty(exports, "JanitorService", { enumerable: true, get: function () { return JanitorService_js_1.JanitorService; } });
|
|
20
|
+
var OverlayMonitor_js_1 = require("./src/OverlayMonitor.js");
|
|
21
|
+
Object.defineProperty(exports, "OverlayMonitor", { enumerable: true, get: function () { return OverlayMonitor_js_1.OverlayMonitor; } });
|
|
22
|
+
Object.defineProperty(exports, "analyzeOverlayAnchorTip", { enumerable: true, get: function () { return OverlayMonitor_js_1.analyzeOverlayAnchorTip; } });
|
|
23
|
+
Object.defineProperty(exports, "analyzeOverlayLookupResponse", { enumerable: true, get: function () { return OverlayMonitor_js_1.analyzeOverlayLookupResponse; } });
|
|
15
24
|
//# sourceMappingURL=mod.js.map
|
package/dist/cjs/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../mod.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../mod.ts"],"names":[],"mappings":";;;;;;AAAA,6DAUgC;AAT9B,6HAAA,OAAO,OAAA;AAUT,qDAAmE;AAA1D,2GAAA,UAAU,OAAA;AACnB,2EAAsE;AAA7D,iIAAA,qBAAqB,OAAA;AAC9B,yEAAoE;AAA3D,+HAAA,oBAAoB,OAAA;AAC7B,iFAA4F;AAAnF,kIAAA,mBAAmB,OAAA;AAAE,kIAAA,mBAAmB,OAAA;AACjD,6DAAuH;AAA9G,mHAAA,cAAc,OAAA;AACvB,6DAegC;AAd9B,mHAAA,cAAc,OAAA;AACd,4HAAA,uBAAuB,OAAA;AACvB,iIAAA,4BAA4B,OAAA"}
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/overlay-express",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "BSV Blockchain Overlay Express",
|
|
6
6
|
"files": [
|
|
@@ -41,28 +41,29 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://github.com/bsv-blockchain/ts-stack/tree/main/packages/overlays/overlay-express#readme",
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@jest/globals": "^30.
|
|
44
|
+
"@jest/globals": "^30.4.1",
|
|
45
45
|
"@types/body-parser": "^1.19.5",
|
|
46
46
|
"@types/express": "^5.0.0",
|
|
47
47
|
"@types/jest": "^30.0.0",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
48
|
+
"@types/node": "^25.9.3",
|
|
49
|
+
"jest": "^30.4.2",
|
|
50
|
+
"ts-jest": "^29.4.11",
|
|
50
51
|
"ts-standard": "^12.0.2",
|
|
51
52
|
"ts2md": "^0.2.0",
|
|
52
53
|
"tsconfig-to-dual-package": "^1.2.0",
|
|
53
|
-
"typescript": "^
|
|
54
|
+
"typescript": "^6.0.3"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
|
-
"@bsv/auth-express-middleware": "^2.0.
|
|
57
|
-
"@bsv/overlay": "^2.0.
|
|
57
|
+
"@bsv/auth-express-middleware": "^2.0.6",
|
|
58
|
+
"@bsv/overlay": "^2.0.3",
|
|
58
59
|
"@bsv/overlay-discovery-services": "^2.0.3",
|
|
59
|
-
"@bsv/sdk": "^2.1.
|
|
60
|
+
"@bsv/sdk": "^2.1.4",
|
|
60
61
|
"@bsv/wallet-toolbox-client": "^2.1.28",
|
|
61
62
|
"body-parser": "^2.2.2",
|
|
62
63
|
"chalk": "^5.6.2",
|
|
63
64
|
"express": "^5.2.1",
|
|
64
|
-
"knex": "^3.
|
|
65
|
-
"mongodb": "^7.
|
|
66
|
-
"uuid": "^
|
|
65
|
+
"knex": "^3.2.10",
|
|
66
|
+
"mongodb": "^7.3.0",
|
|
67
|
+
"uuid": "^14.0.0"
|
|
67
68
|
}
|
|
68
69
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BanAwareSLAPStorage = exports.BanAwareSHIPStorage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Prevents banned SHIP records from being written to discovery storage.
|
|
6
|
+
*/
|
|
7
|
+
class BanAwareSHIPStorage {
|
|
8
|
+
constructor(wrapped, banService, logger = console) {
|
|
9
|
+
this.wrapped = wrapped;
|
|
10
|
+
this.banService = banService;
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
}
|
|
13
|
+
async ensureIndexes() {
|
|
14
|
+
return await this.wrapped.ensureIndexes();
|
|
15
|
+
}
|
|
16
|
+
async hasDuplicateRecord(identityKey, domain, topic) {
|
|
17
|
+
return await this.wrapped.hasDuplicateRecord(identityKey, domain, topic);
|
|
18
|
+
}
|
|
19
|
+
async storeSHIPRecord(txid, outputIndex, identityKey, domain, topic) {
|
|
20
|
+
if (await this.banService.isOutpointBanned(txid, outputIndex)) {
|
|
21
|
+
this.logger.log(`[BAN] Blocked banned outpoint ${txid}.${outputIndex} from SHIP storage`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (await this.banService.isDomainBanned(domain)) {
|
|
25
|
+
this.logger.log(`[BAN] Blocked banned domain ${domain} from SHIP storage (${txid}.${outputIndex})`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
return await this.wrapped.storeSHIPRecord(txid, outputIndex, identityKey, domain, topic);
|
|
29
|
+
}
|
|
30
|
+
async deleteSHIPRecord(txid, outputIndex) {
|
|
31
|
+
return await this.wrapped.deleteSHIPRecord(txid, outputIndex);
|
|
32
|
+
}
|
|
33
|
+
async findRecord(...args) {
|
|
34
|
+
return await this.wrapped.findRecord(...args);
|
|
35
|
+
}
|
|
36
|
+
async findAll(...args) {
|
|
37
|
+
return await this.wrapped.findAll(...args);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.BanAwareSHIPStorage = BanAwareSHIPStorage;
|
|
41
|
+
/**
|
|
42
|
+
* Prevents banned SLAP records from being written to discovery storage.
|
|
43
|
+
*/
|
|
44
|
+
class BanAwareSLAPStorage {
|
|
45
|
+
constructor(wrapped, banService, logger = console) {
|
|
46
|
+
this.wrapped = wrapped;
|
|
47
|
+
this.banService = banService;
|
|
48
|
+
this.logger = logger;
|
|
49
|
+
}
|
|
50
|
+
async ensureIndexes() {
|
|
51
|
+
return await this.wrapped.ensureIndexes();
|
|
52
|
+
}
|
|
53
|
+
async hasDuplicateRecord(identityKey, domain, service) {
|
|
54
|
+
return await this.wrapped.hasDuplicateRecord(identityKey, domain, service);
|
|
55
|
+
}
|
|
56
|
+
async storeSLAPRecord(txid, outputIndex, identityKey, domain, service) {
|
|
57
|
+
if (await this.banService.isOutpointBanned(txid, outputIndex)) {
|
|
58
|
+
this.logger.log(`[BAN] Blocked banned outpoint ${txid}.${outputIndex} from SLAP storage`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (await this.banService.isDomainBanned(domain)) {
|
|
62
|
+
this.logger.log(`[BAN] Blocked banned domain ${domain} from SLAP storage (${txid}.${outputIndex})`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
return await this.wrapped.storeSLAPRecord(txid, outputIndex, identityKey, domain, service);
|
|
66
|
+
}
|
|
67
|
+
async deleteSLAPRecord(txid, outputIndex) {
|
|
68
|
+
return await this.wrapped.deleteSLAPRecord(txid, outputIndex);
|
|
69
|
+
}
|
|
70
|
+
async findRecord(...args) {
|
|
71
|
+
return await this.wrapped.findRecord(...args);
|
|
72
|
+
}
|
|
73
|
+
async findAll(...args) {
|
|
74
|
+
return await this.wrapped.findAll(...args);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.BanAwareSLAPStorage = BanAwareSLAPStorage;
|
|
78
|
+
//# sourceMappingURL=BanAwareDiscoveryStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BanAwareDiscoveryStorage.js","sourceRoot":"","sources":["../../../src/BanAwareDiscoveryStorage.ts"],"names":[],"mappings":";;;AAMA;;GAEG;AACH,MAAa,mBAAmB;IAC9B,YACmB,OAAoB,EACpB,UAAsB,EACtB,SAAyB,OAAO;QAFhC,YAAO,GAAP,OAAO,CAAa;QACpB,eAAU,GAAV,UAAU,CAAY;QACtB,WAAM,GAAN,MAAM,CAA0B;IAChD,CAAC;IAEJ,KAAK,CAAC,aAAa;QACjB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAE,WAAmB,EAAE,MAAc,EAAE,KAAa;QAC1E,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;IAC1E,CAAC;IAED,KAAK,CAAC,eAAe,CAAE,IAAY,EAAE,WAAmB,EAAE,WAAmB,EAAE,MAAc,EAAE,KAAa;QAC1G,IAAI,MAAM,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,CAAC;YAC9D,IAAI,CAAC,MAAM,CAAC,GAAG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});
|
|
3
|
+
exports.BanAwareTopicManager = void 0;
|
|
4
|
+
const sdk_1 = require("@bsv/sdk");
|
|
5
|
+
/**
|
|
6
|
+
* Filters banned SHIP or SLAP advertisement outputs before the overlay engine
|
|
7
|
+
* admits them into topic storage.
|
|
8
|
+
*/
|
|
9
|
+
class BanAwareTopicManager {
|
|
10
|
+
constructor(wrapped, banService, protocol, logger = console) {
|
|
11
|
+
this.wrapped = wrapped;
|
|
12
|
+
this.banService = banService;
|
|
13
|
+
this.protocol = protocol;
|
|
14
|
+
this.logger = logger;
|
|
15
|
+
}
|
|
16
|
+
async identifyAdmissibleOutputs(beef, previousCoins, offChainValues, mode) {
|
|
17
|
+
const instructions = await this.wrapped.identifyAdmissibleOutputs(beef, previousCoins, offChainValues, mode);
|
|
18
|
+
if (instructions.outputsToAdmit.length === 0)
|
|
19
|
+
return instructions;
|
|
20
|
+
let tx;
|
|
21
|
+
try {
|
|
22
|
+
tx = sdk_1.Transaction.fromBEEF(beef);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return instructions;
|
|
26
|
+
}
|
|
27
|
+
const txid = tx.id('hex');
|
|
28
|
+
const outputsToAdmit = [];
|
|
29
|
+
for (const outputIndex of instructions.outputsToAdmit) {
|
|
30
|
+
if (await this.banService.isOutpointBanned(txid, outputIndex)) {
|
|
31
|
+
this.logger.log(`[BAN] Blocked banned outpoint ${txid}.${outputIndex} from ${this.protocol} topic admittance`);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const output = tx.outputs[outputIndex];
|
|
35
|
+
if (output === undefined)
|
|
36
|
+
continue;
|
|
37
|
+
try {
|
|
38
|
+
const result = sdk_1.PushDrop.decode(output.lockingScript);
|
|
39
|
+
if (result.fields.length >= 3 && sdk_1.Utils.toUTF8(result.fields[0]) === this.protocol) {
|
|
40
|
+
const domain = sdk_1.Utils.toUTF8(result.fields[2]);
|
|
41
|
+
if (await this.banService.isDomainBanned(domain)) {
|
|
42
|
+
this.logger.log(`[BAN] Blocked banned domain ${domain} from ${this.protocol} topic admittance (${txid}.${outputIndex})`);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Non PushDrop outputs remain subject to the wrapped manager's decision.
|
|
49
|
+
}
|
|
50
|
+
outputsToAdmit.push(outputIndex);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
...instructions,
|
|
54
|
+
outputsToAdmit
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async identifyNeededInputs(beef, offChainValues) {
|
|
58
|
+
if (typeof this.wrapped.identifyNeededInputs === 'function') {
|
|
59
|
+
return await this.wrapped.identifyNeededInputs(beef, offChainValues);
|
|
60
|
+
}
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
async getDocumentation() {
|
|
64
|
+
return await this.wrapped.getDocumentation();
|
|
65
|
+
}
|
|
66
|
+
async getMetaData() {
|
|
67
|
+
return await this.wrapped.getMetaData();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.BanAwareTopicManager = BanAwareTopicManager;
|
|
71
|
+
//# sourceMappingURL=BanAwareTopicManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BanAwareTopicManager.js","sourceRoot":"","sources":["../../../src/BanAwareTopicManager.ts"],"names":[],"mappings":";;;AACA,kCAA+E;AAG/E;;;GAGG;AACH,MAAa,oBAAoB;IAC/B,YACmB,OAAqB,EACrB,UAAsB,EACtB,QAAyB,EACzB,SAAyB,OAAO;QAHhC,YAAO,GAAP,OAAO,CAAc;QACrB,eAAU,GAAV,UAAU,CAAY;QACtB,aAAQ,GAAR,QAAQ,CAAiB;QACzB,WAAM,GAAN,MAAM,CAA0B;IAChD,CAAC;IAEJ,KAAK,CAAC,yBAAyB,CAC7B,IAAc,EACd,aAAuB,EACvB,cAAyB,EACzB,IAA8D;QAE9D,MAAM,YAAY,GAAG,MAAM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