Validate fetched events from relayer

This commit is contained in:
Tornado Contrib 2024-09-30 10:55:24 +00:00
parent 61266bdb6e
commit 36b545d399
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1
14 changed files with 1408 additions and 167 deletions

0
dist/events/schema.d.ts vendored Normal file

342
dist/index.js vendored

@ -145,27 +145,27 @@ function digest(bytes, algo = "SHA-384") {
}); });
} }
var __defProp$5 = Object.defineProperty; var __defProp$7 = Object.defineProperty;
var __defProps$4 = Object.defineProperties; var __defProps$6 = Object.defineProperties;
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors; var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols; var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
var __getProtoOf$2 = Object.getPrototypeOf; var __getProtoOf$2 = Object.getPrototypeOf;
var __hasOwnProp$5 = Object.prototype.hasOwnProperty; var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable; var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
var __reflectGet$2 = Reflect.get; var __reflectGet$2 = Reflect.get;
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$5 = (a, b) => { var __spreadValues$7 = (a, b) => {
for (var prop in b || (b = {})) for (var prop in b || (b = {}))
if (__hasOwnProp$5.call(b, prop)) if (__hasOwnProp$7.call(b, prop))
__defNormalProp$5(a, prop, b[prop]); __defNormalProp$7(a, prop, b[prop]);
if (__getOwnPropSymbols$5) if (__getOwnPropSymbols$7)
for (var prop of __getOwnPropSymbols$5(b)) { for (var prop of __getOwnPropSymbols$7(b)) {
if (__propIsEnum$5.call(b, prop)) if (__propIsEnum$7.call(b, prop))
__defNormalProp$5(a, prop, b[prop]); __defNormalProp$7(a, prop, b[prop]);
} }
return a; return a;
}; };
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b)); var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
var __superGet$2 = (cls, obj, key) => __reflectGet$2(__getProtoOf$2(cls), key, obj); var __superGet$2 = (cls, obj, key) => __reflectGet$2(__getProtoOf$2(cls), key, obj);
var __async$d = (__this, __arguments, generator) => { var __async$d = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -317,7 +317,7 @@ const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$d(void 0, nu
controller.abort(); controller.abort();
}); });
} }
const init = __spreadProps$4(__spreadValues$5({}, options), { const init = __spreadProps$6(__spreadValues$7({}, options), {
method: req.method || "POST", method: req.method || "POST",
headers: req.headers, headers: req.headers,
body: req.body || void 0, body: req.body || void 0,
@ -683,25 +683,25 @@ const GET_GOVERNANCE_APY = `
} }
`; `;
var __defProp$4 = Object.defineProperty; var __defProp$6 = Object.defineProperty;
var __defProps$3 = Object.defineProperties; var __defProps$5 = Object.defineProperties;
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors; var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols; var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
var __hasOwnProp$4 = Object.prototype.hasOwnProperty; var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable; var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$4 = (a, b) => { var __spreadValues$6 = (a, b) => {
for (var prop in b || (b = {})) for (var prop in b || (b = {}))
if (__hasOwnProp$4.call(b, prop)) if (__hasOwnProp$6.call(b, prop))
__defNormalProp$4(a, prop, b[prop]); __defNormalProp$6(a, prop, b[prop]);
if (__getOwnPropSymbols$4) if (__getOwnPropSymbols$6)
for (var prop of __getOwnPropSymbols$4(b)) { for (var prop of __getOwnPropSymbols$6(b)) {
if (__propIsEnum$4.call(b, prop)) if (__propIsEnum$6.call(b, prop))
__defNormalProp$4(a, prop, b[prop]); __defNormalProp$6(a, prop, b[prop]);
} }
return a; return a;
}; };
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)); var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
var __async$c = (__this, __arguments, generator) => { var __async$c = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var fulfilled = (value) => { var fulfilled = (value) => {
@ -734,7 +734,7 @@ function queryGraph(_0) {
}) { }) {
var _a; var _a;
const graphUrl = `${graphApi}/subgraphs/name/${subgraphName}`; const graphUrl = `${graphApi}/subgraphs/name/${subgraphName}`;
const { data, errors } = yield fetchData(graphUrl, __spreadProps$3(__spreadValues$4({}, fetchDataOptions2), { const { data, errors } = yield fetchData(graphUrl, __spreadProps$5(__spreadValues$6({}, fetchDataOptions2), {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
@ -1722,19 +1722,19 @@ class BatchEventsService {
} }
} }
var __defProp$3 = Object.defineProperty; var __defProp$5 = Object.defineProperty;
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols; var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
var __hasOwnProp$3 = Object.prototype.hasOwnProperty; var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable; var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$3 = (a, b) => { var __spreadValues$5 = (a, b) => {
for (var prop in b || (b = {})) for (var prop in b || (b = {}))
if (__hasOwnProp$3.call(b, prop)) if (__hasOwnProp$5.call(b, prop))
__defNormalProp$3(a, prop, b[prop]); __defNormalProp$5(a, prop, b[prop]);
if (__getOwnPropSymbols$3) if (__getOwnPropSymbols$5)
for (var prop of __getOwnPropSymbols$3(b)) { for (var prop of __getOwnPropSymbols$5(b)) {
if (__propIsEnum$3.call(b, prop)) if (__propIsEnum$5.call(b, prop))
__defNormalProp$3(a, prop, b[prop]); __defNormalProp$5(a, prop, b[prop]);
} }
return a; return a;
}; };
@ -2318,10 +2318,10 @@ function addNetwork(newConfig) {
enabledChains.push( enabledChains.push(
...Object.keys(newConfig).map((netId) => Number(netId)).filter((netId) => !enabledChains.includes(netId)) ...Object.keys(newConfig).map((netId) => Number(netId)).filter((netId) => !enabledChains.includes(netId))
); );
exports.customConfig = __spreadValues$3(__spreadValues$3({}, exports.customConfig), newConfig); exports.customConfig = __spreadValues$5(__spreadValues$5({}, exports.customConfig), newConfig);
} }
function getNetworkConfig() { function getNetworkConfig() {
const allConfig = __spreadValues$3(__spreadValues$3({}, defaultConfig), exports.customConfig); const allConfig = __spreadValues$5(__spreadValues$5({}, defaultConfig), exports.customConfig);
return enabledChains.reduce((acc, curr) => { return enabledChains.reduce((acc, curr) => {
acc[curr] = allConfig[curr]; acc[curr] = allConfig[curr];
return acc; return acc;
@ -2373,12 +2373,188 @@ function getRelayerEnsSubdomains() {
}, {}); }, {});
} }
const addressType = { type: "string", pattern: "^0x[a-fA-F0-9]{40}$" }; var __defProp$4 = Object.defineProperty;
const bnType = { type: "string", BN: true }; var __defProps$4 = Object.defineProperties;
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$4 = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp$4.call(b, prop))
__defNormalProp$4(a, prop, b[prop]);
if (__getOwnPropSymbols$4)
for (var prop of __getOwnPropSymbols$4(b)) {
if (__propIsEnum$4.call(b, prop))
__defNormalProp$4(a, prop, b[prop]);
}
return a;
};
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
const baseEventsSchemaProperty = {
blockNumber: {
type: "number"
},
logIndex: {
type: "number"
},
transactionHash: bytes32SchemaType
};
const baseEventsSchemaRequired = Object.keys(baseEventsSchemaProperty);
const governanceEventsSchema = {
type: "array",
items: {
anyOf: [
{
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
event: { type: "string" },
id: { type: "number" },
proposer: addressSchemaType,
target: addressSchemaType,
startTime: { type: "number" },
endTime: { type: "number" },
description: { type: "string" }
}),
required: [
...baseEventsSchemaRequired,
"event",
"id",
"proposer",
"target",
"startTime",
"endTime",
"description"
],
additionalProperties: false
},
{
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
event: { type: "string" },
proposalId: { type: "number" },
voter: addressSchemaType,
support: { type: "boolean" },
votes: { type: "string" },
from: addressSchemaType,
input: { type: "string" }
}),
required: [...baseEventsSchemaRequired, "event", "proposalId", "voter", "support", "votes", "from", "input"],
additionalProperties: false
},
{
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
event: { type: "string" },
account: addressSchemaType,
delegateTo: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "account", "delegateTo"],
additionalProperties: false
},
{
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
event: { type: "string" },
account: addressSchemaType,
delegateFrom: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "account", "delegateFrom"],
additionalProperties: false
}
]
}
};
const registeredEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
ensName: { type: "string" },
relayerAddress: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "ensName", "relayerAddress"],
additionalProperties: false
}
};
const depositsEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
commitment: bytes32SchemaType,
leafIndex: { type: "number" },
timestamp: { type: "number" },
from: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "commitment", "leafIndex", "timestamp", "from"],
additionalProperties: false
}
};
const withdrawalsEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
nullifierHash: bytes32SchemaType,
to: addressSchemaType,
fee: bnSchemaType,
timestamp: { type: "number" }
}),
required: [...baseEventsSchemaRequired, "nullifierHash", "to", "fee", "timestamp"],
additionalProperties: false
}
};
const echoEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
address: addressSchemaType,
encryptedAccount: { type: "string" }
}),
required: [...baseEventsSchemaRequired, "address", "encryptedAccount"],
additionalProperties: false
}
};
const encryptedNotesSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
encryptedNote: { type: "string" }
}),
required: [...baseEventsSchemaRequired, "encryptedNote"],
additionalProperties: false
}
};
function getEventsSchemaValidator(type) {
if (type === DEPOSIT) {
return ajv.compile(depositsEventsSchema);
}
if (type === WITHDRAWAL) {
return ajv.compile(withdrawalsEventsSchema);
}
if (type === "governance") {
return ajv.compile(governanceEventsSchema);
}
if (type === "registered") {
return ajv.compile(registeredEventsSchema);
}
if (type === "echo") {
return ajv.compile(echoEventsSchema);
}
if (type === "encrypted_notes") {
return ajv.compile(encryptedNotesSchema);
}
throw new Error("Unsupported event type for schema validation");
}
const statusSchema = { const statusSchema = {
type: "object", type: "object",
properties: { properties: {
rewardAccount: addressType, rewardAccount: addressSchemaType,
gasPrices: { gasPrices: {
type: "object", type: "object",
properties: { properties: {
@ -2390,7 +2566,7 @@ const statusSchema = {
netId: { type: "integer" }, netId: { type: "integer" },
tornadoServiceFee: { type: "number", maximum: 20, minimum: 0 }, tornadoServiceFee: { type: "number", maximum: 20, minimum: 0 },
latestBlock: { type: "number" }, latestBlock: { type: "number" },
latestBalance: { type: "string", BN: true }, latestBalance: bnSchemaType,
version: { type: "string" }, version: { type: "string" },
health: { health: {
type: "object", type: "object",
@ -2427,7 +2603,7 @@ function getStatusSchema(netId, config, tovarish) {
instanceAddress: { instanceAddress: {
type: "object", type: "object",
properties: amounts.reduce((acc2, cur) => { properties: amounts.reduce((acc2, cur) => {
acc2[cur] = addressType; acc2[cur] = addressSchemaType;
return acc2; return acc2;
}, {}), }, {}),
required: amounts.filter((amount) => !optionalInstances.includes(amount)) required: amounts.filter((amount) => !optionalInstances.includes(amount))
@ -2440,7 +2616,7 @@ function getStatusSchema(netId, config, tovarish) {
) )
}; };
if (tokenAddress) { if (tokenAddress) {
instanceProperties.properties.tokenAddress = addressType; instanceProperties.properties.tokenAddress = addressSchemaType;
} }
if (symbol) { if (symbol) {
instanceProperties.properties.symbol = { enum: [symbol] }; instanceProperties.properties.symbol = { enum: [symbol] };
@ -2471,7 +2647,7 @@ function getStatusSchema(netId, config, tovarish) {
const ethPrices = { const ethPrices = {
type: "object", type: "object",
properties: _tokens.reduce((acc, token) => { properties: _tokens.reduce((acc, token) => {
acc[token] = bnType; acc[token] = bnSchemaType;
return acc; return acc;
}, {}), }, {}),
required: _tokens required: _tokens
@ -2505,6 +2681,25 @@ const jobsSchema = {
required: ["id", "status"] required: ["id", "status"]
}; };
var __defProp$3 = Object.defineProperty;
var __defProps$3 = Object.defineProperties;
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$3 = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp$3.call(b, prop))
__defNormalProp$3(a, prop, b[prop]);
if (__getOwnPropSymbols$3)
for (var prop of __getOwnPropSymbols$3(b)) {
if (__propIsEnum$3.call(b, prop))
__defNormalProp$3(a, prop, b[prop]);
}
return a;
};
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
const ajv = new Ajv({ allErrors: true }); const ajv = new Ajv({ allErrors: true });
ajv.addKeyword({ ajv.addKeyword({
keyword: "BN", keyword: "BN",
@ -2519,6 +2714,27 @@ ajv.addKeyword({
}, },
errors: true errors: true
}); });
ajv.addKeyword({
keyword: "isAddress",
// eslint-disable-next-line @typescript-eslint/no-explicit-any
validate: (schema, data) => {
try {
return ethers.isAddress(data);
} catch (e) {
return false;
}
},
errors: true
});
const addressSchemaType = {
type: "string",
pattern: "^0x[a-fA-F0-9]{40}$",
isAddress: true
};
const bnSchemaType = { type: "string", BN: true };
const proofSchemaType = { type: "string", pattern: "^0x[a-fA-F0-9]{512}$" };
const bytes32SchemaType = { type: "string", pattern: "^0x[a-fA-F0-9]{64}$" };
const bytes32BNSchemaType = __spreadProps$3(__spreadValues$3({}, bytes32SchemaType), { BN: true });
var __defProp$2 = Object.defineProperty; var __defProp$2 = Object.defineProperty;
var __defProps$2 = Object.defineProperties; var __defProps$2 = Object.defineProperties;
@ -3018,7 +3234,8 @@ class BaseEventsService {
}); });
const lastBlock = newEvents.lastBlock || ((_a = allEvents[allEvents.length - 1]) == null ? void 0 : _a.blockNumber); const lastBlock = newEvents.lastBlock || ((_a = allEvents[allEvents.length - 1]) == null ? void 0 : _a.blockNumber);
this.validateEvents({ events: allEvents, lastBlock }); this.validateEvents({ events: allEvents, lastBlock });
if (savedEvents.fromCache || newEvents.events.length) { const saveCache = Boolean(savedEvents.fromCache && savedEvents.events.length);
if (saveCache || newEvents.events.length) {
yield this.saveEvents({ events: allEvents, lastBlock }); yield this.saveEvents({ events: allEvents, lastBlock });
} }
return { return {
@ -6848,6 +7065,7 @@ class TovarishClient extends RelayerClient {
}) { }) {
var _a; var _a;
const url = `${(_a = this.selectedRelayer) == null ? void 0 : _a.url}events`; const url = `${(_a = this.selectedRelayer) == null ? void 0 : _a.url}events`;
const schemaValidator = getEventsSchemaValidator(type);
try { try {
const events = []; const events = [];
let lastSyncBlock = fromBlock; let lastSyncBlock = fromBlock;
@ -6865,6 +7083,10 @@ class TovarishClient extends RelayerClient {
recent recent
}) })
})); }));
if (!schemaValidator(fetchedEvents)) {
const errMsg = `Schema validation failed for ${type} events`;
throw new Error(errMsg);
}
lastSyncBlock = currentBlock; lastSyncBlock = currentBlock;
if (!Array.isArray(fetchedEvents) || !fetchedEvents.length) { if (!Array.isArray(fetchedEvents) || !fetchedEvents.length) {
break; break;
@ -7009,12 +7231,16 @@ exports.TovarishClient = TovarishClient;
exports.WITHDRAWAL = WITHDRAWAL; exports.WITHDRAWAL = WITHDRAWAL;
exports._META = _META; exports._META = _META;
exports.addNetwork = addNetwork; exports.addNetwork = addNetwork;
exports.addressSchemaType = addressSchemaType;
exports.ajv = ajv; exports.ajv = ajv;
exports.base64ToBytes = base64ToBytes; exports.base64ToBytes = base64ToBytes;
exports.bigIntReplacer = bigIntReplacer; exports.bigIntReplacer = bigIntReplacer;
exports.bnSchemaType = bnSchemaType;
exports.bnToBytes = bnToBytes; exports.bnToBytes = bnToBytes;
exports.buffPedersenHash = buffPedersenHash; exports.buffPedersenHash = buffPedersenHash;
exports.bufferToBytes = bufferToBytes; exports.bufferToBytes = bufferToBytes;
exports.bytes32BNSchemaType = bytes32BNSchemaType;
exports.bytes32SchemaType = bytes32SchemaType;
exports.bytesToBN = bytesToBN; exports.bytesToBN = bytesToBN;
exports.bytesToBase64 = bytesToBase64; exports.bytesToBase64 = bytesToBase64;
exports.bytesToHex = bytesToHex; exports.bytesToHex = bytesToHex;
@ -7027,8 +7253,11 @@ exports.createDeposit = createDeposit;
exports.crypto = crypto; exports.crypto = crypto;
exports.defaultConfig = defaultConfig; exports.defaultConfig = defaultConfig;
exports.defaultUserAgent = defaultUserAgent; exports.defaultUserAgent = defaultUserAgent;
exports.depositsEventsSchema = depositsEventsSchema;
exports.digest = digest; exports.digest = digest;
exports.echoEventsSchema = echoEventsSchema;
exports.enabledChains = enabledChains; exports.enabledChains = enabledChains;
exports.encryptedNotesSchema = encryptedNotesSchema;
exports.factories = index; exports.factories = index;
exports.fetch = fetch; exports.fetch = fetch;
exports.fetchData = fetchData; exports.fetchData = fetchData;
@ -7044,6 +7273,7 @@ exports.getAllWithdrawals = getAllWithdrawals;
exports.getConfig = getConfig; exports.getConfig = getConfig;
exports.getDeposits = getDeposits; exports.getDeposits = getDeposits;
exports.getEncryptedNotes = getEncryptedNotes; exports.getEncryptedNotes = getEncryptedNotes;
exports.getEventsSchemaValidator = getEventsSchemaValidator;
exports.getGovernanceEvents = getGovernanceEvents; exports.getGovernanceEvents = getGovernanceEvents;
exports.getGraphEchoEvents = getGraphEchoEvents; exports.getGraphEchoEvents = getGraphEchoEvents;
exports.getHttpAgent = getHttpAgent; exports.getHttpAgent = getHttpAgent;
@ -7062,6 +7292,7 @@ exports.getTokenBalances = getTokenBalances;
exports.getTovarishNetworks = getTovarishNetworks; exports.getTovarishNetworks = getTovarishNetworks;
exports.getWeightRandom = getWeightRandom; exports.getWeightRandom = getWeightRandom;
exports.getWithdrawals = getWithdrawals; exports.getWithdrawals = getWithdrawals;
exports.governanceEventsSchema = governanceEventsSchema;
exports.hexToBytes = hexToBytes; exports.hexToBytes = hexToBytes;
exports.initGroth16 = initGroth16; exports.initGroth16 = initGroth16;
exports.isNode = isNode; exports.isNode = isNode;
@ -7074,11 +7305,14 @@ exports.packEncryptedMessage = packEncryptedMessage;
exports.pedersen = pedersen; exports.pedersen = pedersen;
exports.pickWeightedRandomRelayer = pickWeightedRandomRelayer; exports.pickWeightedRandomRelayer = pickWeightedRandomRelayer;
exports.populateTransaction = populateTransaction; exports.populateTransaction = populateTransaction;
exports.proofSchemaType = proofSchemaType;
exports.queryGraph = queryGraph; exports.queryGraph = queryGraph;
exports.rBigInt = rBigInt; exports.rBigInt = rBigInt;
exports.registeredEventsSchema = registeredEventsSchema;
exports.sleep = sleep; exports.sleep = sleep;
exports.substring = substring; exports.substring = substring;
exports.toFixedHex = toFixedHex; exports.toFixedHex = toFixedHex;
exports.toFixedLength = toFixedLength; exports.toFixedLength = toFixedLength;
exports.unpackEncryptedMessage = unpackEncryptedMessage; exports.unpackEncryptedMessage = unpackEncryptedMessage;
exports.validateUrl = validateUrl; exports.validateUrl = validateUrl;
exports.withdrawalsEventsSchema = withdrawalsEventsSchema;

334
dist/index.mjs vendored

@ -1,4 +1,4 @@
import { FetchRequest, Network, EnsPlugin, GasCostPlugin, JsonRpcProvider, Wallet, HDNodeWallet, VoidSigner, JsonRpcSigner, BrowserProvider, getAddress, parseEther, namehash, formatEther, Interface, Contract, computeAddress, parseUnits, Transaction, ZeroAddress } from 'ethers'; import { FetchRequest, Network, EnsPlugin, GasCostPlugin, JsonRpcProvider, Wallet, HDNodeWallet, VoidSigner, JsonRpcSigner, BrowserProvider, getAddress, isAddress, parseEther, namehash, formatEther, Interface, Contract, computeAddress, parseUnits, Transaction, ZeroAddress } from 'ethers';
import crossFetch from 'cross-fetch'; import crossFetch from 'cross-fetch';
import { webcrypto } from 'crypto'; import { webcrypto } from 'crypto';
import BN from 'bn.js'; import BN from 'bn.js';
@ -124,27 +124,27 @@ function digest(bytes, algo = "SHA-384") {
}); });
} }
var __defProp$5 = Object.defineProperty; var __defProp$7 = Object.defineProperty;
var __defProps$4 = Object.defineProperties; var __defProps$6 = Object.defineProperties;
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors; var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols; var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
var __getProtoOf$2 = Object.getPrototypeOf; var __getProtoOf$2 = Object.getPrototypeOf;
var __hasOwnProp$5 = Object.prototype.hasOwnProperty; var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable; var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
var __reflectGet$2 = Reflect.get; var __reflectGet$2 = Reflect.get;
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$5 = (a, b) => { var __spreadValues$7 = (a, b) => {
for (var prop in b || (b = {})) for (var prop in b || (b = {}))
if (__hasOwnProp$5.call(b, prop)) if (__hasOwnProp$7.call(b, prop))
__defNormalProp$5(a, prop, b[prop]); __defNormalProp$7(a, prop, b[prop]);
if (__getOwnPropSymbols$5) if (__getOwnPropSymbols$7)
for (var prop of __getOwnPropSymbols$5(b)) { for (var prop of __getOwnPropSymbols$7(b)) {
if (__propIsEnum$5.call(b, prop)) if (__propIsEnum$7.call(b, prop))
__defNormalProp$5(a, prop, b[prop]); __defNormalProp$7(a, prop, b[prop]);
} }
return a; return a;
}; };
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b)); var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
var __superGet$2 = (cls, obj, key) => __reflectGet$2(__getProtoOf$2(cls), key, obj); var __superGet$2 = (cls, obj, key) => __reflectGet$2(__getProtoOf$2(cls), key, obj);
var __async$d = (__this, __arguments, generator) => { var __async$d = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -296,7 +296,7 @@ const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$d(void 0, nu
controller.abort(); controller.abort();
}); });
} }
const init = __spreadProps$4(__spreadValues$5({}, options), { const init = __spreadProps$6(__spreadValues$7({}, options), {
method: req.method || "POST", method: req.method || "POST",
headers: req.headers, headers: req.headers,
body: req.body || void 0, body: req.body || void 0,
@ -662,25 +662,25 @@ const GET_GOVERNANCE_APY = `
} }
`; `;
var __defProp$4 = Object.defineProperty; var __defProp$6 = Object.defineProperty;
var __defProps$3 = Object.defineProperties; var __defProps$5 = Object.defineProperties;
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors; var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols; var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
var __hasOwnProp$4 = Object.prototype.hasOwnProperty; var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable; var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$4 = (a, b) => { var __spreadValues$6 = (a, b) => {
for (var prop in b || (b = {})) for (var prop in b || (b = {}))
if (__hasOwnProp$4.call(b, prop)) if (__hasOwnProp$6.call(b, prop))
__defNormalProp$4(a, prop, b[prop]); __defNormalProp$6(a, prop, b[prop]);
if (__getOwnPropSymbols$4) if (__getOwnPropSymbols$6)
for (var prop of __getOwnPropSymbols$4(b)) { for (var prop of __getOwnPropSymbols$6(b)) {
if (__propIsEnum$4.call(b, prop)) if (__propIsEnum$6.call(b, prop))
__defNormalProp$4(a, prop, b[prop]); __defNormalProp$6(a, prop, b[prop]);
} }
return a; return a;
}; };
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)); var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
var __async$c = (__this, __arguments, generator) => { var __async$c = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var fulfilled = (value) => { var fulfilled = (value) => {
@ -713,7 +713,7 @@ function queryGraph(_0) {
}) { }) {
var _a; var _a;
const graphUrl = `${graphApi}/subgraphs/name/${subgraphName}`; const graphUrl = `${graphApi}/subgraphs/name/${subgraphName}`;
const { data, errors } = yield fetchData(graphUrl, __spreadProps$3(__spreadValues$4({}, fetchDataOptions2), { const { data, errors } = yield fetchData(graphUrl, __spreadProps$5(__spreadValues$6({}, fetchDataOptions2), {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
@ -1701,19 +1701,19 @@ class BatchEventsService {
} }
} }
var __defProp$3 = Object.defineProperty; var __defProp$5 = Object.defineProperty;
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols; var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
var __hasOwnProp$3 = Object.prototype.hasOwnProperty; var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable; var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$3 = (a, b) => { var __spreadValues$5 = (a, b) => {
for (var prop in b || (b = {})) for (var prop in b || (b = {}))
if (__hasOwnProp$3.call(b, prop)) if (__hasOwnProp$5.call(b, prop))
__defNormalProp$3(a, prop, b[prop]); __defNormalProp$5(a, prop, b[prop]);
if (__getOwnPropSymbols$3) if (__getOwnPropSymbols$5)
for (var prop of __getOwnPropSymbols$3(b)) { for (var prop of __getOwnPropSymbols$5(b)) {
if (__propIsEnum$3.call(b, prop)) if (__propIsEnum$5.call(b, prop))
__defNormalProp$3(a, prop, b[prop]); __defNormalProp$5(a, prop, b[prop]);
} }
return a; return a;
}; };
@ -2297,10 +2297,10 @@ function addNetwork(newConfig) {
enabledChains.push( enabledChains.push(
...Object.keys(newConfig).map((netId) => Number(netId)).filter((netId) => !enabledChains.includes(netId)) ...Object.keys(newConfig).map((netId) => Number(netId)).filter((netId) => !enabledChains.includes(netId))
); );
customConfig = __spreadValues$3(__spreadValues$3({}, customConfig), newConfig); customConfig = __spreadValues$5(__spreadValues$5({}, customConfig), newConfig);
} }
function getNetworkConfig() { function getNetworkConfig() {
const allConfig = __spreadValues$3(__spreadValues$3({}, defaultConfig), customConfig); const allConfig = __spreadValues$5(__spreadValues$5({}, defaultConfig), customConfig);
return enabledChains.reduce((acc, curr) => { return enabledChains.reduce((acc, curr) => {
acc[curr] = allConfig[curr]; acc[curr] = allConfig[curr];
return acc; return acc;
@ -2352,12 +2352,188 @@ function getRelayerEnsSubdomains() {
}, {}); }, {});
} }
const addressType = { type: "string", pattern: "^0x[a-fA-F0-9]{40}$" }; var __defProp$4 = Object.defineProperty;
const bnType = { type: "string", BN: true }; var __defProps$4 = Object.defineProperties;
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$4 = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp$4.call(b, prop))
__defNormalProp$4(a, prop, b[prop]);
if (__getOwnPropSymbols$4)
for (var prop of __getOwnPropSymbols$4(b)) {
if (__propIsEnum$4.call(b, prop))
__defNormalProp$4(a, prop, b[prop]);
}
return a;
};
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
const baseEventsSchemaProperty = {
blockNumber: {
type: "number"
},
logIndex: {
type: "number"
},
transactionHash: bytes32SchemaType
};
const baseEventsSchemaRequired = Object.keys(baseEventsSchemaProperty);
const governanceEventsSchema = {
type: "array",
items: {
anyOf: [
{
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
event: { type: "string" },
id: { type: "number" },
proposer: addressSchemaType,
target: addressSchemaType,
startTime: { type: "number" },
endTime: { type: "number" },
description: { type: "string" }
}),
required: [
...baseEventsSchemaRequired,
"event",
"id",
"proposer",
"target",
"startTime",
"endTime",
"description"
],
additionalProperties: false
},
{
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
event: { type: "string" },
proposalId: { type: "number" },
voter: addressSchemaType,
support: { type: "boolean" },
votes: { type: "string" },
from: addressSchemaType,
input: { type: "string" }
}),
required: [...baseEventsSchemaRequired, "event", "proposalId", "voter", "support", "votes", "from", "input"],
additionalProperties: false
},
{
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
event: { type: "string" },
account: addressSchemaType,
delegateTo: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "account", "delegateTo"],
additionalProperties: false
},
{
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
event: { type: "string" },
account: addressSchemaType,
delegateFrom: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "account", "delegateFrom"],
additionalProperties: false
}
]
}
};
const registeredEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
ensName: { type: "string" },
relayerAddress: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "ensName", "relayerAddress"],
additionalProperties: false
}
};
const depositsEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
commitment: bytes32SchemaType,
leafIndex: { type: "number" },
timestamp: { type: "number" },
from: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "commitment", "leafIndex", "timestamp", "from"],
additionalProperties: false
}
};
const withdrawalsEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
nullifierHash: bytes32SchemaType,
to: addressSchemaType,
fee: bnSchemaType,
timestamp: { type: "number" }
}),
required: [...baseEventsSchemaRequired, "nullifierHash", "to", "fee", "timestamp"],
additionalProperties: false
}
};
const echoEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
address: addressSchemaType,
encryptedAccount: { type: "string" }
}),
required: [...baseEventsSchemaRequired, "address", "encryptedAccount"],
additionalProperties: false
}
};
const encryptedNotesSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps$4(__spreadValues$4({}, baseEventsSchemaProperty), {
encryptedNote: { type: "string" }
}),
required: [...baseEventsSchemaRequired, "encryptedNote"],
additionalProperties: false
}
};
function getEventsSchemaValidator(type) {
if (type === DEPOSIT) {
return ajv.compile(depositsEventsSchema);
}
if (type === WITHDRAWAL) {
return ajv.compile(withdrawalsEventsSchema);
}
if (type === "governance") {
return ajv.compile(governanceEventsSchema);
}
if (type === "registered") {
return ajv.compile(registeredEventsSchema);
}
if (type === "echo") {
return ajv.compile(echoEventsSchema);
}
if (type === "encrypted_notes") {
return ajv.compile(encryptedNotesSchema);
}
throw new Error("Unsupported event type for schema validation");
}
const statusSchema = { const statusSchema = {
type: "object", type: "object",
properties: { properties: {
rewardAccount: addressType, rewardAccount: addressSchemaType,
gasPrices: { gasPrices: {
type: "object", type: "object",
properties: { properties: {
@ -2369,7 +2545,7 @@ const statusSchema = {
netId: { type: "integer" }, netId: { type: "integer" },
tornadoServiceFee: { type: "number", maximum: 20, minimum: 0 }, tornadoServiceFee: { type: "number", maximum: 20, minimum: 0 },
latestBlock: { type: "number" }, latestBlock: { type: "number" },
latestBalance: { type: "string", BN: true }, latestBalance: bnSchemaType,
version: { type: "string" }, version: { type: "string" },
health: { health: {
type: "object", type: "object",
@ -2406,7 +2582,7 @@ function getStatusSchema(netId, config, tovarish) {
instanceAddress: { instanceAddress: {
type: "object", type: "object",
properties: amounts.reduce((acc2, cur) => { properties: amounts.reduce((acc2, cur) => {
acc2[cur] = addressType; acc2[cur] = addressSchemaType;
return acc2; return acc2;
}, {}), }, {}),
required: amounts.filter((amount) => !optionalInstances.includes(amount)) required: amounts.filter((amount) => !optionalInstances.includes(amount))
@ -2419,7 +2595,7 @@ function getStatusSchema(netId, config, tovarish) {
) )
}; };
if (tokenAddress) { if (tokenAddress) {
instanceProperties.properties.tokenAddress = addressType; instanceProperties.properties.tokenAddress = addressSchemaType;
} }
if (symbol) { if (symbol) {
instanceProperties.properties.symbol = { enum: [symbol] }; instanceProperties.properties.symbol = { enum: [symbol] };
@ -2450,7 +2626,7 @@ function getStatusSchema(netId, config, tovarish) {
const ethPrices = { const ethPrices = {
type: "object", type: "object",
properties: _tokens.reduce((acc, token) => { properties: _tokens.reduce((acc, token) => {
acc[token] = bnType; acc[token] = bnSchemaType;
return acc; return acc;
}, {}), }, {}),
required: _tokens required: _tokens
@ -2484,6 +2660,25 @@ const jobsSchema = {
required: ["id", "status"] required: ["id", "status"]
}; };
var __defProp$3 = Object.defineProperty;
var __defProps$3 = Object.defineProperties;
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$3 = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp$3.call(b, prop))
__defNormalProp$3(a, prop, b[prop]);
if (__getOwnPropSymbols$3)
for (var prop of __getOwnPropSymbols$3(b)) {
if (__propIsEnum$3.call(b, prop))
__defNormalProp$3(a, prop, b[prop]);
}
return a;
};
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
const ajv = new Ajv({ allErrors: true }); const ajv = new Ajv({ allErrors: true });
ajv.addKeyword({ ajv.addKeyword({
keyword: "BN", keyword: "BN",
@ -2498,6 +2693,27 @@ ajv.addKeyword({
}, },
errors: true errors: true
}); });
ajv.addKeyword({
keyword: "isAddress",
// eslint-disable-next-line @typescript-eslint/no-explicit-any
validate: (schema, data) => {
try {
return isAddress(data);
} catch (e) {
return false;
}
},
errors: true
});
const addressSchemaType = {
type: "string",
pattern: "^0x[a-fA-F0-9]{40}$",
isAddress: true
};
const bnSchemaType = { type: "string", BN: true };
const proofSchemaType = { type: "string", pattern: "^0x[a-fA-F0-9]{512}$" };
const bytes32SchemaType = { type: "string", pattern: "^0x[a-fA-F0-9]{64}$" };
const bytes32BNSchemaType = __spreadProps$3(__spreadValues$3({}, bytes32SchemaType), { BN: true });
var __defProp$2 = Object.defineProperty; var __defProp$2 = Object.defineProperty;
var __defProps$2 = Object.defineProperties; var __defProps$2 = Object.defineProperties;
@ -2997,7 +3213,8 @@ class BaseEventsService {
}); });
const lastBlock = newEvents.lastBlock || ((_a = allEvents[allEvents.length - 1]) == null ? void 0 : _a.blockNumber); const lastBlock = newEvents.lastBlock || ((_a = allEvents[allEvents.length - 1]) == null ? void 0 : _a.blockNumber);
this.validateEvents({ events: allEvents, lastBlock }); this.validateEvents({ events: allEvents, lastBlock });
if (savedEvents.fromCache || newEvents.events.length) { const saveCache = Boolean(savedEvents.fromCache && savedEvents.events.length);
if (saveCache || newEvents.events.length) {
yield this.saveEvents({ events: allEvents, lastBlock }); yield this.saveEvents({ events: allEvents, lastBlock });
} }
return { return {
@ -6827,6 +7044,7 @@ class TovarishClient extends RelayerClient {
}) { }) {
var _a; var _a;
const url = `${(_a = this.selectedRelayer) == null ? void 0 : _a.url}events`; const url = `${(_a = this.selectedRelayer) == null ? void 0 : _a.url}events`;
const schemaValidator = getEventsSchemaValidator(type);
try { try {
const events = []; const events = [];
let lastSyncBlock = fromBlock; let lastSyncBlock = fromBlock;
@ -6844,6 +7062,10 @@ class TovarishClient extends RelayerClient {
recent recent
}) })
})); }));
if (!schemaValidator(fetchedEvents)) {
const errMsg = `Schema validation failed for ${type} events`;
throw new Error(errMsg);
}
lastSyncBlock = currentBlock; lastSyncBlock = currentBlock;
if (!Array.isArray(fetchedEvents) || !fetchedEvents.length) { if (!Array.isArray(fetchedEvents) || !fetchedEvents.length) {
break; break;
@ -6941,4 +7163,4 @@ function calculateSnarkProof(input, circuit, provingKey) {
}); });
} }
export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseRegistryService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DEPOSIT, Deposit, ENS__factory, ERC20__factory, GET_DEPOSITS, GET_ECHO_EVENTS, GET_ENCRYPTED_NOTES, GET_GOVERNANCE_APY, GET_GOVERNANCE_EVENTS, GET_NOTE_ACCOUNTS, GET_REGISTERED, GET_STATISTIC, GET_WITHDRAWALS, Invoice, MAX_FEE, MAX_TOVARISH_EVENTS, MIN_FEE, MIN_STAKE_BALANCE, MerkleTreeService, Mimc, Multicall__factory, NetId, NoteAccount, OffchainOracle__factory, OvmGasPriceOracle__factory, Pedersen, RelayerClient, ReverseRecords__factory, TokenPriceOracle, TornadoBrowserProvider, TornadoFeeOracle, TornadoRpcSigner, TornadoVoidSigner, TornadoWallet, TovarishClient, WITHDRAWAL, _META, addNetwork, ajv, base64ToBytes, bigIntReplacer, bnToBytes, buffPedersenHash, bufferToBytes, bytesToBN, bytesToBase64, bytesToHex, calculateScore, calculateSnarkProof, chunk, concatBytes, convertETHToTokenAmount, createDeposit, crypto, customConfig, defaultConfig, defaultUserAgent, digest, enabledChains, index as factories, fetch, fetchData, fetchGetUrlFunc, getActiveTokenInstances, getActiveTokens, getAllDeposits, getAllEncryptedNotes, getAllGovernanceEvents, getAllGraphEchoEvents, getAllRegisters, getAllWithdrawals, getConfig, getDeposits, getEncryptedNotes, getGovernanceEvents, getGraphEchoEvents, getHttpAgent, getInstanceByAddress, getMeta, getNetworkConfig, getNoteAccounts, getProvider, getProviderWithNetId, getRegisters, getRelayerEnsSubdomains, getStatistic, getStatusSchema, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, getWithdrawals, hexToBytes, initGroth16, isNode, jobsSchema, leBuff2Int, leInt2Buff, mimc, multicall, packEncryptedMessage, pedersen, pickWeightedRandomRelayer, populateTransaction, queryGraph, rBigInt, sleep, substring, toFixedHex, toFixedLength, unpackEncryptedMessage, validateUrl }; export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseRegistryService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DEPOSIT, Deposit, ENS__factory, ERC20__factory, GET_DEPOSITS, GET_ECHO_EVENTS, GET_ENCRYPTED_NOTES, GET_GOVERNANCE_APY, GET_GOVERNANCE_EVENTS, GET_NOTE_ACCOUNTS, GET_REGISTERED, GET_STATISTIC, GET_WITHDRAWALS, Invoice, MAX_FEE, MAX_TOVARISH_EVENTS, MIN_FEE, MIN_STAKE_BALANCE, MerkleTreeService, Mimc, Multicall__factory, NetId, NoteAccount, OffchainOracle__factory, OvmGasPriceOracle__factory, Pedersen, RelayerClient, ReverseRecords__factory, TokenPriceOracle, TornadoBrowserProvider, TornadoFeeOracle, TornadoRpcSigner, TornadoVoidSigner, TornadoWallet, TovarishClient, WITHDRAWAL, _META, addNetwork, addressSchemaType, ajv, base64ToBytes, bigIntReplacer, bnSchemaType, bnToBytes, buffPedersenHash, bufferToBytes, bytes32BNSchemaType, bytes32SchemaType, bytesToBN, bytesToBase64, bytesToHex, calculateScore, calculateSnarkProof, chunk, concatBytes, convertETHToTokenAmount, createDeposit, crypto, customConfig, defaultConfig, defaultUserAgent, depositsEventsSchema, digest, echoEventsSchema, enabledChains, encryptedNotesSchema, index as factories, fetch, fetchData, fetchGetUrlFunc, getActiveTokenInstances, getActiveTokens, getAllDeposits, getAllEncryptedNotes, getAllGovernanceEvents, getAllGraphEchoEvents, getAllRegisters, getAllWithdrawals, getConfig, getDeposits, getEncryptedNotes, getEventsSchemaValidator, getGovernanceEvents, getGraphEchoEvents, getHttpAgent, getInstanceByAddress, getMeta, getNetworkConfig, getNoteAccounts, getProvider, getProviderWithNetId, getRegisters, getRelayerEnsSubdomains, getStatistic, getStatusSchema, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, getWithdrawals, governanceEventsSchema, hexToBytes, initGroth16, isNode, jobsSchema, leBuff2Int, leInt2Buff, mimc, multicall, packEncryptedMessage, pedersen, pickWeightedRandomRelayer, populateTransaction, proofSchemaType, queryGraph, rBigInt, registeredEventsSchema, sleep, substring, toFixedHex, toFixedLength, unpackEncryptedMessage, validateUrl, withdrawalsEventsSchema };

297
dist/schemas/events.d.ts vendored Normal file

@ -0,0 +1,297 @@
export declare const governanceEventsSchema: {
readonly type: "array";
readonly items: {
readonly anyOf: readonly [{
readonly type: "object";
readonly properties: {
readonly event: {
readonly type: "string";
};
readonly id: {
readonly type: "number";
};
readonly proposer: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly target: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly startTime: {
readonly type: "number";
};
readonly endTime: {
readonly type: "number";
};
readonly description: {
readonly type: "string";
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "event", "id", "proposer", "target", "startTime", "endTime", "description"];
readonly additionalProperties: false;
}, {
readonly type: "object";
readonly properties: {
readonly event: {
readonly type: "string";
};
readonly proposalId: {
readonly type: "number";
};
readonly voter: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly support: {
readonly type: "boolean";
};
readonly votes: {
readonly type: "string";
};
readonly from: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly input: {
readonly type: "string";
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "event", "proposalId", "voter", "support", "votes", "from", "input"];
readonly additionalProperties: false;
}, {
readonly type: "object";
readonly properties: {
readonly event: {
readonly type: "string";
};
readonly account: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly delegateTo: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "account", "delegateTo"];
readonly additionalProperties: false;
}, {
readonly type: "object";
readonly properties: {
readonly event: {
readonly type: "string";
};
readonly account: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly delegateFrom: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "account", "delegateFrom"];
readonly additionalProperties: false;
}];
};
};
export declare const registeredEventsSchema: {
readonly type: "array";
readonly items: {
readonly type: "object";
readonly properties: {
readonly ensName: {
readonly type: "string";
};
readonly relayerAddress: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "ensName", "relayerAddress"];
readonly additionalProperties: false;
};
};
export declare const depositsEventsSchema: {
readonly type: "array";
readonly items: {
readonly type: "object";
readonly properties: {
readonly commitment: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
readonly leafIndex: {
readonly type: "number";
};
readonly timestamp: {
readonly type: "number";
};
readonly from: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "commitment", "leafIndex", "timestamp", "from"];
readonly additionalProperties: false;
};
};
export declare const withdrawalsEventsSchema: {
readonly type: "array";
readonly items: {
readonly type: "object";
readonly properties: {
readonly nullifierHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
readonly to: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly fee: {
readonly type: "string";
readonly BN: true;
};
readonly timestamp: {
readonly type: "number";
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "nullifierHash", "to", "fee", "timestamp"];
readonly additionalProperties: false;
};
};
export declare const echoEventsSchema: {
readonly type: "array";
readonly items: {
readonly type: "object";
readonly properties: {
readonly address: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly encryptedAccount: {
readonly type: "string";
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "address", "encryptedAccount"];
readonly additionalProperties: false;
};
};
export declare const encryptedNotesSchema: {
readonly type: "array";
readonly items: {
readonly type: "object";
readonly properties: {
readonly encryptedNote: {
readonly type: "string";
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "encryptedNote"];
readonly additionalProperties: false;
};
};
export declare function getEventsSchemaValidator(type: string): import("ajv").ValidateFunction<unknown>;

@ -1,4 +1,27 @@
import Ajv from 'ajv'; import Ajv from 'ajv';
export declare const ajv: Ajv; export declare const ajv: Ajv;
export declare const addressSchemaType: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
export declare const bnSchemaType: {
readonly type: "string";
readonly BN: true;
};
export declare const proofSchemaType: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{512}$";
};
export declare const bytes32SchemaType: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
export declare const bytes32BNSchemaType: {
readonly BN: true;
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
export * from './events';
export * from './status'; export * from './status';
export * from './jobs'; export * from './jobs';

@ -1,15 +1,16 @@
import { Config, NetIdType } from '../networkConfig'; import { Config, NetIdType } from '../networkConfig';
import { addressSchemaType, bnSchemaType } from '.';
export type statusInstanceType = { export type statusInstanceType = {
type: string; type: string;
properties: { properties: {
instanceAddress: { instanceAddress: {
type: string; type: string;
properties: { properties: {
[key in string]: typeof addressType; [key in string]: typeof addressSchemaType;
}; };
required: string[]; required: string[];
}; };
tokenAddress?: typeof addressType; tokenAddress?: typeof addressSchemaType;
symbol?: { symbol?: {
enum: string[]; enum: string[];
}; };
@ -29,14 +30,14 @@ export type statusInstancesType = {
export type statusEthPricesType = { export type statusEthPricesType = {
type: string; type: string;
properties: { properties: {
[key in string]: typeof bnType; [key in string]: typeof bnSchemaType;
}; };
required?: string[]; required?: string[];
}; };
export type statusSchema = { export type statusSchema = {
type: string; type: string;
properties: { properties: {
rewardAccount: typeof addressType; rewardAccount: typeof addressSchemaType;
instances?: statusInstancesType; instances?: statusInstancesType;
gasPrices: { gasPrices: {
type: string; type: string;
@ -102,13 +103,4 @@ export type statusSchema = {
}; };
required: string[]; required: string[];
}; };
declare const addressType: {
type: string;
pattern: string;
};
declare const bnType: {
type: string;
BN: boolean;
};
export declare function getStatusSchema(netId: NetIdType, config: Config, tovarish: boolean): statusSchema; export declare function getStatusSchema(netId: NetIdType, config: Config, tovarish: boolean): statusSchema;
export {};

309
dist/tornado.umd.js vendored

@ -59335,7 +59335,8 @@ class BaseEventsService {
}); });
const lastBlock = newEvents.lastBlock || ((_a = allEvents[allEvents.length - 1]) == null ? void 0 : _a.blockNumber); const lastBlock = newEvents.lastBlock || ((_a = allEvents[allEvents.length - 1]) == null ? void 0 : _a.blockNumber);
this.validateEvents({ events: allEvents, lastBlock }); this.validateEvents({ events: allEvents, lastBlock });
if (savedEvents.fromCache || newEvents.events.length) { const saveCache = Boolean(savedEvents.fromCache && savedEvents.events.length);
if (saveCache || newEvents.events.length) {
yield this.saveEvents({ events: allEvents, lastBlock }); yield this.saveEvents({ events: allEvents, lastBlock });
} }
return { return {
@ -71542,7 +71543,7 @@ class TornadoBrowserProvider extends BrowserProvider {
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(67418); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(67418);
/* harmony import */ var _networkConfig__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(59499); /* harmony import */ var _networkConfig__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(59499);
/* harmony import */ var _providers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(68434); /* harmony import */ var _providers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(68434);
/* harmony import */ var _schemas__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(7613); /* harmony import */ var _schemas__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(79086);
var __defProp = Object.defineProperty; var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties; var __defProps = Object.defineProperties;
@ -71798,32 +71799,229 @@ class RelayerClient {
/***/ }), /***/ }),
/***/ 7613: /***/ 79086:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict"; "use strict";
// EXPORTS // EXPORTS
__webpack_require__.d(__webpack_exports__, { __webpack_require__.d(__webpack_exports__, {
SC: () => (/* binding */ addressSchemaType),
SS: () => (/* binding */ schemas_ajv), SS: () => (/* binding */ schemas_ajv),
iL: () => (/* binding */ bnSchemaType),
i1: () => (/* binding */ bytes32BNSchemaType),
yF: () => (/* binding */ bytes32SchemaType),
CI: () => (/* reexport */ depositsEventsSchema),
ME: () => (/* reexport */ echoEventsSchema),
XW: () => (/* reexport */ encryptedNotesSchema),
ZC: () => (/* reexport */ getEventsSchemaValidator),
c_: () => (/* reexport */ getStatusSchema), c_: () => (/* reexport */ getStatusSchema),
Us: () => (/* reexport */ jobsSchema) FR: () => (/* reexport */ governanceEventsSchema),
Us: () => (/* reexport */ jobsSchema),
Y6: () => (/* binding */ proofSchemaType),
dX: () => (/* reexport */ registeredEventsSchema),
$j: () => (/* reexport */ withdrawalsEventsSchema)
}); });
// EXTERNAL MODULE: ./node_modules/ajv/dist/ajv.js // EXTERNAL MODULE: ./node_modules/ajv/dist/ajv.js
var ajv = __webpack_require__(63282); var ajv = __webpack_require__(63282);
var ajv_default = /*#__PURE__*/__webpack_require__.n(ajv); var ajv_default = /*#__PURE__*/__webpack_require__.n(ajv);
// EXTERNAL MODULE: ./node_modules/ethers/lib.esm/address/checks.js
var checks = __webpack_require__(41442);
// EXTERNAL MODULE: ./src/events/index.ts
var events = __webpack_require__(94513);
;// CONCATENATED MODULE: ./src/schemas/events.ts
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
const baseEventsSchemaProperty = {
blockNumber: {
type: "number"
},
logIndex: {
type: "number"
},
transactionHash: bytes32SchemaType
};
const baseEventsSchemaRequired = Object.keys(baseEventsSchemaProperty);
const governanceEventsSchema = {
type: "array",
items: {
anyOf: [
{
type: "object",
properties: __spreadProps(__spreadValues({}, baseEventsSchemaProperty), {
event: { type: "string" },
id: { type: "number" },
proposer: addressSchemaType,
target: addressSchemaType,
startTime: { type: "number" },
endTime: { type: "number" },
description: { type: "string" }
}),
required: [
...baseEventsSchemaRequired,
"event",
"id",
"proposer",
"target",
"startTime",
"endTime",
"description"
],
additionalProperties: false
},
{
type: "object",
properties: __spreadProps(__spreadValues({}, baseEventsSchemaProperty), {
event: { type: "string" },
proposalId: { type: "number" },
voter: addressSchemaType,
support: { type: "boolean" },
votes: { type: "string" },
from: addressSchemaType,
input: { type: "string" }
}),
required: [...baseEventsSchemaRequired, "event", "proposalId", "voter", "support", "votes", "from", "input"],
additionalProperties: false
},
{
type: "object",
properties: __spreadProps(__spreadValues({}, baseEventsSchemaProperty), {
event: { type: "string" },
account: addressSchemaType,
delegateTo: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "account", "delegateTo"],
additionalProperties: false
},
{
type: "object",
properties: __spreadProps(__spreadValues({}, baseEventsSchemaProperty), {
event: { type: "string" },
account: addressSchemaType,
delegateFrom: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "account", "delegateFrom"],
additionalProperties: false
}
]
}
};
const registeredEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps(__spreadValues({}, baseEventsSchemaProperty), {
ensName: { type: "string" },
relayerAddress: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "ensName", "relayerAddress"],
additionalProperties: false
}
};
const depositsEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps(__spreadValues({}, baseEventsSchemaProperty), {
commitment: bytes32SchemaType,
leafIndex: { type: "number" },
timestamp: { type: "number" },
from: addressSchemaType
}),
required: [...baseEventsSchemaRequired, "commitment", "leafIndex", "timestamp", "from"],
additionalProperties: false
}
};
const withdrawalsEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps(__spreadValues({}, baseEventsSchemaProperty), {
nullifierHash: bytes32SchemaType,
to: addressSchemaType,
fee: bnSchemaType,
timestamp: { type: "number" }
}),
required: [...baseEventsSchemaRequired, "nullifierHash", "to", "fee", "timestamp"],
additionalProperties: false
}
};
const echoEventsSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps(__spreadValues({}, baseEventsSchemaProperty), {
address: addressSchemaType,
encryptedAccount: { type: "string" }
}),
required: [...baseEventsSchemaRequired, "address", "encryptedAccount"],
additionalProperties: false
}
};
const encryptedNotesSchema = {
type: "array",
items: {
type: "object",
properties: __spreadProps(__spreadValues({}, baseEventsSchemaProperty), {
encryptedNote: { type: "string" }
}),
required: [...baseEventsSchemaRequired, "encryptedNote"],
additionalProperties: false
}
};
function getEventsSchemaValidator(type) {
if (type === events.DEPOSIT) {
return schemas_ajv.compile(depositsEventsSchema);
}
if (type === events.WITHDRAWAL) {
return schemas_ajv.compile(withdrawalsEventsSchema);
}
if (type === "governance") {
return schemas_ajv.compile(governanceEventsSchema);
}
if (type === "registered") {
return schemas_ajv.compile(registeredEventsSchema);
}
if (type === "echo") {
return schemas_ajv.compile(echoEventsSchema);
}
if (type === "encrypted_notes") {
return schemas_ajv.compile(encryptedNotesSchema);
}
throw new Error("Unsupported event type for schema validation");
}
// EXTERNAL MODULE: ./src/networkConfig.ts // EXTERNAL MODULE: ./src/networkConfig.ts
var networkConfig = __webpack_require__(59499); var networkConfig = __webpack_require__(59499);
;// CONCATENATED MODULE: ./src/schemas/status.ts ;// CONCATENATED MODULE: ./src/schemas/status.ts
const addressType = { type: "string", pattern: "^0x[a-fA-F0-9]{40}$" };
const bnType = { type: "string", BN: true };
const statusSchema = { const statusSchema = {
type: "object", type: "object",
properties: { properties: {
rewardAccount: addressType, rewardAccount: addressSchemaType,
gasPrices: { gasPrices: {
type: "object", type: "object",
properties: { properties: {
@ -71835,7 +72033,7 @@ const statusSchema = {
netId: { type: "integer" }, netId: { type: "integer" },
tornadoServiceFee: { type: "number", maximum: 20, minimum: 0 }, tornadoServiceFee: { type: "number", maximum: 20, minimum: 0 },
latestBlock: { type: "number" }, latestBlock: { type: "number" },
latestBalance: { type: "string", BN: true }, latestBalance: bnSchemaType,
version: { type: "string" }, version: { type: "string" },
health: { health: {
type: "object", type: "object",
@ -71872,7 +72070,7 @@ function getStatusSchema(netId, config, tovarish) {
instanceAddress: { instanceAddress: {
type: "object", type: "object",
properties: amounts.reduce((acc2, cur) => { properties: amounts.reduce((acc2, cur) => {
acc2[cur] = addressType; acc2[cur] = addressSchemaType;
return acc2; return acc2;
}, {}), }, {}),
required: amounts.filter((amount) => !optionalInstances.includes(amount)) required: amounts.filter((amount) => !optionalInstances.includes(amount))
@ -71885,7 +72083,7 @@ function getStatusSchema(netId, config, tovarish) {
) )
}; };
if (tokenAddress) { if (tokenAddress) {
instanceProperties.properties.tokenAddress = addressType; instanceProperties.properties.tokenAddress = addressSchemaType;
} }
if (symbol) { if (symbol) {
instanceProperties.properties.symbol = { enum: [symbol] }; instanceProperties.properties.symbol = { enum: [symbol] };
@ -71916,7 +72114,7 @@ function getStatusSchema(netId, config, tovarish) {
const ethPrices = { const ethPrices = {
type: "object", type: "object",
properties: _tokens.reduce((acc, token) => { properties: _tokens.reduce((acc, token) => {
acc[token] = bnType; acc[token] = bnSchemaType;
return acc; return acc;
}, {}), }, {}),
required: _tokens required: _tokens
@ -71954,6 +72152,26 @@ const jobsSchema = {
;// CONCATENATED MODULE: ./src/schemas/index.ts ;// CONCATENATED MODULE: ./src/schemas/index.ts
var schemas_defProp = Object.defineProperty;
var schemas_defProps = Object.defineProperties;
var schemas_getOwnPropDescs = Object.getOwnPropertyDescriptors;
var schemas_getOwnPropSymbols = Object.getOwnPropertySymbols;
var schemas_hasOwnProp = Object.prototype.hasOwnProperty;
var schemas_propIsEnum = Object.prototype.propertyIsEnumerable;
var schemas_defNormalProp = (obj, key, value) => key in obj ? schemas_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var schemas_spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (schemas_hasOwnProp.call(b, prop))
schemas_defNormalProp(a, prop, b[prop]);
if (schemas_getOwnPropSymbols)
for (var prop of schemas_getOwnPropSymbols(b)) {
if (schemas_propIsEnum.call(b, prop))
schemas_defNormalProp(a, prop, b[prop]);
}
return a;
};
var schemas_spreadProps = (a, b) => schemas_defProps(a, schemas_getOwnPropDescs(b));
const schemas_ajv = new (ajv_default())({ allErrors: true }); const schemas_ajv = new (ajv_default())({ allErrors: true });
schemas_ajv.addKeyword({ schemas_ajv.addKeyword({
@ -71969,6 +72187,28 @@ schemas_ajv.addKeyword({
}, },
errors: true errors: true
}); });
schemas_ajv.addKeyword({
keyword: "isAddress",
// eslint-disable-next-line @typescript-eslint/no-explicit-any
validate: (schema, data) => {
try {
return (0,checks/* isAddress */.PW)(data);
} catch (e) {
return false;
}
},
errors: true
});
const addressSchemaType = {
type: "string",
pattern: "^0x[a-fA-F0-9]{40}$",
isAddress: true
};
const bnSchemaType = { type: "string", BN: true };
const proofSchemaType = { type: "string", pattern: "^0x[a-fA-F0-9]{512}$" };
const bytes32SchemaType = { type: "string", pattern: "^0x[a-fA-F0-9]{64}$" };
const bytes32BNSchemaType = schemas_spreadProps(schemas_spreadValues({}, bytes32SchemaType), { BN: true });
@ -72086,9 +72326,10 @@ function getTokenBalances(_0) {
/* harmony export */ E: () => (/* binding */ TovarishClient), /* harmony export */ E: () => (/* binding */ TovarishClient),
/* harmony export */ o: () => (/* binding */ MAX_TOVARISH_EVENTS) /* harmony export */ o: () => (/* binding */ MAX_TOVARISH_EVENTS)
/* harmony export */ }); /* harmony export */ });
/* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(30031); /* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(30031);
/* harmony import */ var _relayerClient__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(57194); /* harmony import */ var _relayerClient__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(57194);
/* harmony import */ var _providers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(68434); /* harmony import */ var _providers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(68434);
/* harmony import */ var _schemas__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(79086);
var __defProp = Object.defineProperty; var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties; var __defProps = Object.defineProperties;
@ -72135,6 +72376,7 @@ var __async = (__this, __arguments, generator) => {
const MAX_TOVARISH_EVENTS = 5e3; const MAX_TOVARISH_EVENTS = 5e3;
class TovarishClient extends _relayerClient__WEBPACK_IMPORTED_MODULE_0__/* .RelayerClient */ .OR { class TovarishClient extends _relayerClient__WEBPACK_IMPORTED_MODULE_0__/* .RelayerClient */ .OR {
constructor({ netId, config, fetchDataOptions }) { constructor({ netId, config, fetchDataOptions }) {
@ -72169,7 +72411,7 @@ class TovarishClient extends _relayerClient__WEBPACK_IMPORTED_MODULE_0__/* .Rela
hostname, hostname,
ensName, ensName,
relayerAddress, relayerAddress,
rewardAccount: (0,ethers__WEBPACK_IMPORTED_MODULE_2__/* .getAddress */ .b)(status.rewardAccount), rewardAccount: (0,ethers__WEBPACK_IMPORTED_MODULE_3__/* .getAddress */ .b)(status.rewardAccount),
instances: (0,_relayerClient__WEBPACK_IMPORTED_MODULE_0__/* .getSupportedInstances */ .XF)(status.instances), instances: (0,_relayerClient__WEBPACK_IMPORTED_MODULE_0__/* .getSupportedInstances */ .XF)(status.instances),
stakeBalance: relayer.stakeBalance, stakeBalance: relayer.stakeBalance,
gasPrice: (_a = status.gasPrices) == null ? void 0 : _a.fast, gasPrice: (_a = status.gasPrices) == null ? void 0 : _a.fast,
@ -72222,6 +72464,7 @@ class TovarishClient extends _relayerClient__WEBPACK_IMPORTED_MODULE_0__/* .Rela
}) { }) {
var _a; var _a;
const url = `${(_a = this.selectedRelayer) == null ? void 0 : _a.url}events`; const url = `${(_a = this.selectedRelayer) == null ? void 0 : _a.url}events`;
const schemaValidator = (0,_schemas__WEBPACK_IMPORTED_MODULE_2__/* .getEventsSchemaValidator */ .ZC)(type);
try { try {
const events = []; const events = [];
let lastSyncBlock = fromBlock; let lastSyncBlock = fromBlock;
@ -72239,6 +72482,10 @@ class TovarishClient extends _relayerClient__WEBPACK_IMPORTED_MODULE_0__/* .Rela
recent recent
}) })
})); }));
if (!schemaValidator(fetchedEvents)) {
const errMsg = `Schema validation failed for ${type} events`;
throw new Error(errMsg);
}
lastSyncBlock = currentBlock; lastSyncBlock = currentBlock;
if (!Array.isArray(fetchedEvents) || !fetchedEvents.length) { if (!Array.isArray(fetchedEvents) || !fetchedEvents.length) {
break; break;
@ -162074,11 +162321,11 @@ function getIcapAddress(address) {
"use strict"; "use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ $C: () => (/* binding */ isAddressable), /* harmony export */ $C: () => (/* binding */ isAddressable),
/* harmony export */ PW: () => (/* binding */ isAddress),
/* harmony export */ tG: () => (/* binding */ resolveAddress) /* harmony export */ tG: () => (/* binding */ resolveAddress)
/* harmony export */ }); /* harmony export */ });
/* unused harmony export isAddress */ /* harmony import */ var _utils_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(57339);
/* harmony import */ var _utils_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(57339); /* harmony import */ var _address_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(30031);
/* harmony import */ var _address_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(30031);
/** /**
@ -162125,7 +162372,7 @@ function isAddressable(value) {
*/ */
function isAddress(value) { function isAddress(value) {
try { try {
getAddress(value); (0,_address_js__WEBPACK_IMPORTED_MODULE_0__/* .getAddress */ .b)(value);
return true; return true;
} }
catch (error) { } catch (error) { }
@ -162134,10 +162381,10 @@ function isAddress(value) {
async function checkAddress(target, promise) { async function checkAddress(target, promise) {
const result = await promise; const result = await promise;
if (result == null || result === "0x0000000000000000000000000000000000000000") { if (result == null || result === "0x0000000000000000000000000000000000000000") {
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .vA)(typeof (target) !== "string", "unconfigured name", "UNCONFIGURED_NAME", { value: target }); (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__/* .assert */ .vA)(typeof (target) !== "string", "unconfigured name", "UNCONFIGURED_NAME", { value: target });
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__/* .assertArgument */ .MR)(false, "invalid AddressLike value; did not resolve to a value address", "target", target); (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__/* .assertArgument */ .MR)(false, "invalid AddressLike value; did not resolve to a value address", "target", target);
} }
return (0,_address_js__WEBPACK_IMPORTED_MODULE_1__/* .getAddress */ .b)(result); return (0,_address_js__WEBPACK_IMPORTED_MODULE_0__/* .getAddress */ .b)(result);
} }
/** /**
* Resolves to an address for the %%target%%, which may be any * Resolves to an address for the %%target%%, which may be any
@ -162179,9 +162426,9 @@ async function checkAddress(target, promise) {
function resolveAddress(target, resolver) { function resolveAddress(target, resolver) {
if (typeof (target) === "string") { if (typeof (target) === "string") {
if (target.match(/^0x[0-9a-f]{40}$/i)) { if (target.match(/^0x[0-9a-f]{40}$/i)) {
return (0,_address_js__WEBPACK_IMPORTED_MODULE_1__/* .getAddress */ .b)(target); return (0,_address_js__WEBPACK_IMPORTED_MODULE_0__/* .getAddress */ .b)(target);
} }
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .vA)(resolver != null, "ENS resolution requires a provider", "UNSUPPORTED_OPERATION", { operation: "resolveName" }); (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__/* .assert */ .vA)(resolver != null, "ENS resolution requires a provider", "UNSUPPORTED_OPERATION", { operation: "resolveName" });
return checkAddress(target, resolver.resolveName(target)); return checkAddress(target, resolver.resolveName(target));
} }
else if (isAddressable(target)) { else if (isAddressable(target)) {
@ -162190,7 +162437,7 @@ function resolveAddress(target, resolver) {
else if (target && typeof (target.then) === "function") { else if (target && typeof (target.then) === "function") {
return checkAddress(target, target); return checkAddress(target, target);
} }
(0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__/* .assertArgument */ .MR)(false, "unsupported addressable value", "target", target); (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__/* .assertArgument */ .MR)(false, "unsupported addressable value", "target", target);
} }
//# sourceMappingURL=checks.js.map //# sourceMappingURL=checks.js.map
@ -173348,12 +173595,16 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ TovarishClient: () => (/* reexport safe */ _tovarishClient__WEBPACK_IMPORTED_MODULE_17__.E), /* harmony export */ TovarishClient: () => (/* reexport safe */ _tovarishClient__WEBPACK_IMPORTED_MODULE_17__.E),
/* harmony export */ _META: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__._META), /* harmony export */ _META: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__._META),
/* harmony export */ addNetwork: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.AE), /* harmony export */ addNetwork: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.AE),
/* harmony export */ addressSchemaType: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.SC),
/* harmony export */ ajv: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.SS), /* harmony export */ ajv: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.SS),
/* harmony export */ base64ToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Kp), /* harmony export */ base64ToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Kp),
/* harmony export */ bigIntReplacer: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.gn), /* harmony export */ bigIntReplacer: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.gn),
/* harmony export */ bnSchemaType: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.iL),
/* harmony export */ bnToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.jm), /* harmony export */ bnToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.jm),
/* harmony export */ buffPedersenHash: () => (/* reexport safe */ _pedersen__WEBPACK_IMPORTED_MODULE_12__.UB), /* harmony export */ buffPedersenHash: () => (/* reexport safe */ _pedersen__WEBPACK_IMPORTED_MODULE_12__.UB),
/* harmony export */ bufferToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.lY), /* harmony export */ bufferToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.lY),
/* harmony export */ bytes32BNSchemaType: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.i1),
/* harmony export */ bytes32SchemaType: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.yF),
/* harmony export */ bytesToBN: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Ju), /* harmony export */ bytesToBN: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Ju),
/* harmony export */ bytesToBase64: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__["if"]), /* harmony export */ bytesToBase64: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__["if"]),
/* harmony export */ bytesToHex: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.My), /* harmony export */ bytesToHex: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.My),
@ -173367,8 +173618,11 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ customConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.cX), /* harmony export */ customConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.cX),
/* harmony export */ defaultConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.sb), /* harmony export */ defaultConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.sb),
/* harmony export */ defaultUserAgent: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.mJ), /* harmony export */ defaultUserAgent: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.mJ),
/* harmony export */ depositsEventsSchema: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.CI),
/* harmony export */ digest: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.br), /* harmony export */ digest: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.br),
/* harmony export */ echoEventsSchema: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.ME),
/* harmony export */ enabledChains: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.Af), /* harmony export */ enabledChains: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.Af),
/* harmony export */ encryptedNotesSchema: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.XW),
/* harmony export */ factories: () => (/* reexport safe */ _typechain__WEBPACK_IMPORTED_MODULE_3__.XB), /* harmony export */ factories: () => (/* reexport safe */ _typechain__WEBPACK_IMPORTED_MODULE_3__.XB),
/* harmony export */ fetch: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.hd), /* harmony export */ fetch: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.hd),
/* harmony export */ fetchData: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.Fd), /* harmony export */ fetchData: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.Fd),
@ -173384,6 +173638,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ getConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.zj), /* harmony export */ getConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.zj),
/* harmony export */ getDeposits: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getDeposits), /* harmony export */ getDeposits: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getDeposits),
/* harmony export */ getEncryptedNotes: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getEncryptedNotes), /* harmony export */ getEncryptedNotes: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getEncryptedNotes),
/* harmony export */ getEventsSchemaValidator: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.ZC),
/* harmony export */ getGovernanceEvents: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getGovernanceEvents), /* harmony export */ getGovernanceEvents: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getGovernanceEvents),
/* harmony export */ getGraphEchoEvents: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getGraphEchoEvents), /* harmony export */ getGraphEchoEvents: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getGraphEchoEvents),
/* harmony export */ getHttpAgent: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.WU), /* harmony export */ getHttpAgent: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.WU),
@ -173401,6 +173656,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ getTokenBalances: () => (/* reexport safe */ _tokens__WEBPACK_IMPORTED_MODULE_16__.H), /* harmony export */ getTokenBalances: () => (/* reexport safe */ _tokens__WEBPACK_IMPORTED_MODULE_16__.H),
/* harmony export */ getWeightRandom: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.c$), /* harmony export */ getWeightRandom: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.c$),
/* harmony export */ getWithdrawals: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getWithdrawals), /* harmony export */ getWithdrawals: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getWithdrawals),
/* harmony export */ governanceEventsSchema: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.FR),
/* harmony export */ hexToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.aT), /* harmony export */ hexToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.aT),
/* harmony export */ initGroth16: () => (/* reexport safe */ _websnark__WEBPACK_IMPORTED_MODULE_19__.O), /* harmony export */ initGroth16: () => (/* reexport safe */ _websnark__WEBPACK_IMPORTED_MODULE_19__.O),
/* harmony export */ isNode: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Ll), /* harmony export */ isNode: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Ll),
@ -173413,21 +173669,24 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ pedersen: () => (/* reexport safe */ _pedersen__WEBPACK_IMPORTED_MODULE_12__.NO), /* harmony export */ pedersen: () => (/* reexport safe */ _pedersen__WEBPACK_IMPORTED_MODULE_12__.NO),
/* harmony export */ pickWeightedRandomRelayer: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.sN), /* harmony export */ pickWeightedRandomRelayer: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.sN),
/* harmony export */ populateTransaction: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.zr), /* harmony export */ populateTransaction: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.zr),
/* harmony export */ proofSchemaType: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.Y6),
/* harmony export */ queryGraph: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.queryGraph), /* harmony export */ queryGraph: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.queryGraph),
/* harmony export */ rBigInt: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.ib), /* harmony export */ rBigInt: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.ib),
/* harmony export */ registeredEventsSchema: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.dX),
/* harmony export */ sleep: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.yy), /* harmony export */ sleep: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.yy),
/* harmony export */ substring: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.uU), /* harmony export */ substring: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.uU),
/* harmony export */ toFixedHex: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.$W), /* harmony export */ toFixedHex: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.$W),
/* harmony export */ toFixedLength: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.sY), /* harmony export */ toFixedLength: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.sY),
/* harmony export */ unpackEncryptedMessage: () => (/* reexport safe */ _encryptedNotes__WEBPACK_IMPORTED_MODULE_6__.ol), /* harmony export */ unpackEncryptedMessage: () => (/* reexport safe */ _encryptedNotes__WEBPACK_IMPORTED_MODULE_6__.ol),
/* harmony export */ validateUrl: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.wv) /* harmony export */ validateUrl: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.wv),
/* harmony export */ withdrawalsEventsSchema: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.$j)
/* harmony export */ }); /* harmony export */ });
/* harmony import */ var _events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(94513); /* harmony import */ var _events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(94513);
/* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {}; /* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
/* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in _events__WEBPACK_IMPORTED_MODULE_0__) if(__WEBPACK_IMPORT_KEY__ !== "default") __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = () => _events__WEBPACK_IMPORTED_MODULE_0__[__WEBPACK_IMPORT_KEY__] /* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in _events__WEBPACK_IMPORTED_MODULE_0__) if(__WEBPACK_IMPORT_KEY__ !== "default") __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = () => _events__WEBPACK_IMPORTED_MODULE_0__[__WEBPACK_IMPORT_KEY__]
/* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__); /* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
/* harmony import */ var _graphql__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(52049); /* harmony import */ var _graphql__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(52049);
/* harmony import */ var _schemas__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(7613); /* harmony import */ var _schemas__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(79086);
/* harmony import */ var _typechain__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(21278); /* harmony import */ var _typechain__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(21278);
/* harmony import */ var _batch__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(9723); /* harmony import */ var _batch__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(9723);
/* harmony import */ var _deposits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(7240); /* harmony import */ var _deposits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(7240);

File diff suppressed because one or more lines are too long

@ -336,7 +336,8 @@ export class BaseEventsService<EventType extends MinimalEvents> {
this.validateEvents({ events: allEvents, lastBlock }); this.validateEvents({ events: allEvents, lastBlock });
// If the events are loaded from cache or we have found new events, save them // If the events are loaded from cache or we have found new events, save them
if ((savedEvents as CachedEvents<EventType>).fromCache || newEvents.events.length) { const saveCache = Boolean((savedEvents as CachedEvents<EventType>).fromCache && savedEvents.events.length);
if (saveCache || newEvents.events.length) {
await this.saveEvents({ events: allEvents, lastBlock }); await this.saveEvents({ events: allEvents, lastBlock });
} }

0
src/events/schema.ts Normal file

184
src/schemas/events.ts Normal file

@ -0,0 +1,184 @@
import { DEPOSIT, WITHDRAWAL } from '../events';
import { addressSchemaType, ajv, bnSchemaType, bytes32SchemaType } from '.';
const baseEventsSchemaProperty = {
blockNumber: {
type: 'number',
},
logIndex: {
type: 'number',
},
transactionHash: bytes32SchemaType,
} as const;
const baseEventsSchemaRequired = Object.keys(baseEventsSchemaProperty) as string[];
export const governanceEventsSchema = {
type: 'array',
items: {
anyOf: [
{
type: 'object',
properties: {
...baseEventsSchemaProperty,
event: { type: 'string' },
id: { type: 'number' },
proposer: addressSchemaType,
target: addressSchemaType,
startTime: { type: 'number' },
endTime: { type: 'number' },
description: { type: 'string' },
},
required: [
...baseEventsSchemaRequired,
'event',
'id',
'proposer',
'target',
'startTime',
'endTime',
'description',
],
additionalProperties: false,
},
{
type: 'object',
properties: {
...baseEventsSchemaProperty,
event: { type: 'string' },
proposalId: { type: 'number' },
voter: addressSchemaType,
support: { type: 'boolean' },
votes: { type: 'string' },
from: addressSchemaType,
input: { type: 'string' },
},
required: [...baseEventsSchemaRequired, 'event', 'proposalId', 'voter', 'support', 'votes', 'from', 'input'],
additionalProperties: false,
},
{
type: 'object',
properties: {
...baseEventsSchemaProperty,
event: { type: 'string' },
account: addressSchemaType,
delegateTo: addressSchemaType,
},
required: [...baseEventsSchemaRequired, 'account', 'delegateTo'],
additionalProperties: false,
},
{
type: 'object',
properties: {
...baseEventsSchemaProperty,
event: { type: 'string' },
account: addressSchemaType,
delegateFrom: addressSchemaType,
},
required: [...baseEventsSchemaRequired, 'account', 'delegateFrom'],
additionalProperties: false,
},
],
},
} as const;
export const registeredEventsSchema = {
type: 'array',
items: {
type: 'object',
properties: {
...baseEventsSchemaProperty,
ensName: { type: 'string' },
relayerAddress: addressSchemaType,
},
required: [...baseEventsSchemaRequired, 'ensName', 'relayerAddress'],
additionalProperties: false,
},
} as const;
export const depositsEventsSchema = {
type: 'array',
items: {
type: 'object',
properties: {
...baseEventsSchemaProperty,
commitment: bytes32SchemaType,
leafIndex: { type: 'number' },
timestamp: { type: 'number' },
from: addressSchemaType,
},
required: [...baseEventsSchemaRequired, 'commitment', 'leafIndex', 'timestamp', 'from'],
additionalProperties: false,
},
} as const;
export const withdrawalsEventsSchema = {
type: 'array',
items: {
type: 'object',
properties: {
...baseEventsSchemaProperty,
nullifierHash: bytes32SchemaType,
to: addressSchemaType,
fee: bnSchemaType,
timestamp: { type: 'number' },
},
required: [...baseEventsSchemaRequired, 'nullifierHash', 'to', 'fee', 'timestamp'],
additionalProperties: false,
},
} as const;
export const echoEventsSchema = {
type: 'array',
items: {
type: 'object',
properties: {
...baseEventsSchemaProperty,
address: addressSchemaType,
encryptedAccount: { type: 'string' },
},
required: [...baseEventsSchemaRequired, 'address', 'encryptedAccount'],
additionalProperties: false,
},
} as const;
export const encryptedNotesSchema = {
type: 'array',
items: {
type: 'object',
properties: {
...baseEventsSchemaProperty,
encryptedNote: { type: 'string' },
},
required: [...baseEventsSchemaRequired, 'encryptedNote'],
additionalProperties: false,
},
} as const;
export function getEventsSchemaValidator(type: string) {
if (type === DEPOSIT) {
return ajv.compile(depositsEventsSchema);
}
if (type === WITHDRAWAL) {
return ajv.compile(withdrawalsEventsSchema);
}
if (type === 'governance') {
return ajv.compile(governanceEventsSchema);
}
if (type === 'registered') {
return ajv.compile(registeredEventsSchema);
}
if (type === 'echo') {
return ajv.compile(echoEventsSchema);
}
if (type === 'encrypted_notes') {
return ajv.compile(encryptedNotesSchema);
}
throw new Error('Unsupported event type for schema validation');
}

@ -1,5 +1,5 @@
import Ajv from 'ajv'; import Ajv from 'ajv';
import type { BigNumberish } from 'ethers'; import { BigNumberish, isAddress } from 'ethers';
export const ajv = new Ajv({ allErrors: true }); export const ajv = new Ajv({ allErrors: true });
@ -17,5 +17,29 @@ ajv.addKeyword({
errors: true, errors: true,
}); });
ajv.addKeyword({
keyword: 'isAddress',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
validate: (schema: any, data: string) => {
try {
return isAddress(data);
} catch {
return false;
}
},
errors: true,
});
export const addressSchemaType = {
type: 'string',
pattern: '^0x[a-fA-F0-9]{40}$',
isAddress: true,
} as const;
export const bnSchemaType = { type: 'string', BN: true } as const;
export const proofSchemaType = { type: 'string', pattern: '^0x[a-fA-F0-9]{512}$' } as const;
export const bytes32SchemaType = { type: 'string', pattern: '^0x[a-fA-F0-9]{64}$' } as const;
export const bytes32BNSchemaType = { ...bytes32SchemaType, BN: true } as const;
export * from './events';
export * from './status'; export * from './status';
export * from './jobs'; export * from './jobs';

@ -1,4 +1,5 @@
import { Config, NetId, NetIdType } from '../networkConfig'; import { Config, NetId, NetIdType } from '../networkConfig';
import { addressSchemaType, bnSchemaType } from '.';
export type statusInstanceType = { export type statusInstanceType = {
type: string; type: string;
@ -6,11 +7,11 @@ export type statusInstanceType = {
instanceAddress: { instanceAddress: {
type: string; type: string;
properties: { properties: {
[key in string]: typeof addressType; [key in string]: typeof addressSchemaType;
}; };
required: string[]; required: string[];
}; };
tokenAddress?: typeof addressType; tokenAddress?: typeof addressSchemaType;
symbol?: { enum: string[] }; symbol?: { enum: string[] };
decimals: { enum: number[] }; decimals: { enum: number[] };
}; };
@ -28,7 +29,7 @@ export type statusInstancesType = {
export type statusEthPricesType = { export type statusEthPricesType = {
type: string; type: string;
properties: { properties: {
[key in string]: typeof bnType; [key in string]: typeof bnSchemaType;
}; };
required?: string[]; required?: string[];
}; };
@ -36,7 +37,7 @@ export type statusEthPricesType = {
export type statusSchema = { export type statusSchema = {
type: string; type: string;
properties: { properties: {
rewardAccount: typeof addressType; rewardAccount: typeof addressSchemaType;
instances?: statusInstancesType; instances?: statusInstancesType;
gasPrices: { gasPrices: {
type: string; type: string;
@ -91,14 +92,10 @@ export type statusSchema = {
required: string[]; required: string[];
}; };
const addressType = { type: 'string', pattern: '^0x[a-fA-F0-9]{40}$' };
const bnType = { type: 'string', BN: true };
const statusSchema: statusSchema = { const statusSchema: statusSchema = {
type: 'object', type: 'object',
properties: { properties: {
rewardAccount: addressType, rewardAccount: addressSchemaType,
gasPrices: { gasPrices: {
type: 'object', type: 'object',
properties: { properties: {
@ -110,7 +107,7 @@ const statusSchema: statusSchema = {
netId: { type: 'integer' }, netId: { type: 'integer' },
tornadoServiceFee: { type: 'number', maximum: 20, minimum: 0 }, tornadoServiceFee: { type: 'number', maximum: 20, minimum: 0 },
latestBlock: { type: 'number' }, latestBlock: { type: 'number' },
latestBalance: { type: 'string', BN: true }, latestBalance: bnSchemaType,
version: { type: 'string' }, version: { type: 'string' },
health: { health: {
type: 'object', type: 'object',
@ -151,8 +148,8 @@ export function getStatusSchema(netId: NetIdType, config: Config, tovarish: bool
properties: { properties: {
instanceAddress: { instanceAddress: {
type: 'object', type: 'object',
properties: amounts.reduce((acc: { [key in string]: typeof addressType }, cur) => { properties: amounts.reduce((acc: { [key in string]: typeof addressSchemaType }, cur) => {
acc[cur] = addressType; acc[cur] = addressSchemaType;
return acc; return acc;
}, {}), }, {}),
required: amounts.filter((amount) => !optionalInstances.includes(amount)), required: amounts.filter((amount) => !optionalInstances.includes(amount)),
@ -166,7 +163,7 @@ export function getStatusSchema(netId: NetIdType, config: Config, tovarish: bool
}; };
if (tokenAddress) { if (tokenAddress) {
instanceProperties.properties.tokenAddress = addressType; instanceProperties.properties.tokenAddress = addressSchemaType;
} }
if (symbol) { if (symbol) {
instanceProperties.properties.symbol = { enum: [symbol] }; instanceProperties.properties.symbol = { enum: [symbol] };
@ -198,8 +195,8 @@ export function getStatusSchema(netId: NetIdType, config: Config, tovarish: bool
if (_tokens.length) { if (_tokens.length) {
const ethPrices: statusEthPricesType = { const ethPrices: statusEthPricesType = {
type: 'object', type: 'object',
properties: _tokens.reduce((acc: { [key in string]: typeof bnType }, token: string) => { properties: _tokens.reduce((acc: { [key in string]: typeof bnSchemaType }, token: string) => {
acc[token] = bnType; acc[token] = bnSchemaType;
return acc; return acc;
}, {}), }, {}),
required: _tokens, required: _tokens,

@ -10,6 +10,7 @@ import {
} from './relayerClient'; } from './relayerClient';
import { fetchData } from './providers'; import { fetchData } from './providers';
import { CachedRelayerInfo, MinimalEvents } from './events'; import { CachedRelayerInfo, MinimalEvents } from './events';
import { getEventsSchemaValidator } from './schemas';
// Return no more than 5K events per query // Return no more than 5K events per query
export const MAX_TOVARISH_EVENTS = 5000; export const MAX_TOVARISH_EVENTS = 5000;
@ -181,6 +182,8 @@ export class TovarishClient extends RelayerClient {
}: TovarishEventsQuery): Promise<BaseTovarishEvents<T>> { }: TovarishEventsQuery): Promise<BaseTovarishEvents<T>> {
const url = `${this.selectedRelayer?.url}events`; const url = `${this.selectedRelayer?.url}events`;
const schemaValidator = getEventsSchemaValidator(type);
try { try {
const events = []; const events = [];
let lastSyncBlock = fromBlock; let lastSyncBlock = fromBlock;
@ -203,6 +206,11 @@ export class TovarishClient extends RelayerClient {
}), }),
})) as BaseTovarishEvents<T>; })) as BaseTovarishEvents<T>;
if (!schemaValidator(fetchedEvents)) {
const errMsg = `Schema validation failed for ${type} events`;
throw new Error(errMsg);
}
lastSyncBlock = currentBlock; lastSyncBlock = currentBlock;
if (!Array.isArray(fetchedEvents) || !fetchedEvents.length) { if (!Array.isArray(fetchedEvents) || !fetchedEvents.length) {