forked from tornadocash/tornado-cli
Use 4 tab size
This commit is contained in:
parent
42e6b1713b
commit
b2f31b4e43
103
.eslintrc.js
103
.eslintrc.js
@ -1,65 +1,44 @@
|
||||
module.exports = {
|
||||
"env": {
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:import/recommended",
|
||||
"plugin:import/typescript",
|
||||
"prettier",
|
||||
"plugin:prettier/recommended",
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"files": [
|
||||
".eslintrc.{js,cjs}"
|
||||
],
|
||||
"parserOptions": {
|
||||
"sourceType": "script"
|
||||
}
|
||||
}
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint",
|
||||
"prettier"
|
||||
],
|
||||
"rules": {
|
||||
"prettier/prettier": [
|
||||
"error",
|
||||
{
|
||||
singleQuote: true,
|
||||
printWidth: 120
|
||||
}
|
||||
env: {
|
||||
es2021: true,
|
||||
node: true,
|
||||
},
|
||||
extends: [
|
||||
'prettier',
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:import/recommended',
|
||||
'plugin:import/typescript',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
"import/order": ["error"],
|
||||
/**
|
||||
"indent": [
|
||||
"error",
|
||||
2
|
||||
overrides: [
|
||||
{
|
||||
env: {
|
||||
node: true,
|
||||
},
|
||||
files: ['.eslintrc.{js,cjs}'],
|
||||
parserOptions: {
|
||||
sourceType: 'script',
|
||||
},
|
||||
},
|
||||
],
|
||||
**/
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"unix"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"@typescript-eslint/no-unused-vars": ["warn"]
|
||||
}
|
||||
}
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint', 'prettier'],
|
||||
rules: {
|
||||
'prettier/prettier': [
|
||||
'error',
|
||||
{
|
||||
tabWidth: 4,
|
||||
printWidth: 120,
|
||||
singleQuote: true,
|
||||
},
|
||||
],
|
||||
'import/order': ['error'],
|
||||
'@typescript-eslint/no-unused-vars': ['warn'],
|
||||
'@typescript-eslint/no-unused-expressions': ['off'],
|
||||
},
|
||||
};
|
||||
|
1562
dist/cli.js
vendored
1562
dist/cli.js
vendored
File diff suppressed because it is too large
Load Diff
164
package.json
164
package.json
@ -1,84 +1,84 @@
|
||||
{
|
||||
"name": "@tornado/cli",
|
||||
"version": "1.0.11-alpha",
|
||||
"description": "Modern Toolsets for Privacy Pools on Ethereum",
|
||||
"main": "./dist/cli.js",
|
||||
"types": "./dist/cli.d.ts",
|
||||
"bin": {
|
||||
"tornado-cli": "./dist/cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"typechain": "typechain --target ethers-v6 --out-dir src/typechain src/abi/*.json",
|
||||
"types": "tsc --declaration --emitDeclarationOnly",
|
||||
"lint": "eslint src/**/*.ts --ext .ts --ignore-pattern src/typechain",
|
||||
"copy:worker": "ts-node scripts/copyFile.ts node_modules/@tornado/core/dist/merkleTreeWorker.js static/merkleTreeWorker.js",
|
||||
"build:node": "webpack",
|
||||
"build": "yarn types && yarn build:node",
|
||||
"start": "ts-node src/cli.ts",
|
||||
"help": "ts-node src/cli.ts help",
|
||||
"create": "ts-node src/cli.ts create",
|
||||
"deposit": "ts-node src/cli.ts deposit",
|
||||
"depositInvoice": "ts-node src/cli.ts depositInvoice",
|
||||
"withdraw": "ts-node src/cli.ts withdraw",
|
||||
"compliance": "ts-node src/cli.ts compliance",
|
||||
"updateEvents": "ts-node src/cli.ts updateEvents",
|
||||
"relayers": "ts-node src/cli.ts relayers",
|
||||
"createAccount": "ts-node src/cli.ts createAccount",
|
||||
"decrypt": "ts-node src/cli.ts decrypt",
|
||||
"send": "ts-node src/cli.ts send",
|
||||
"balance": "ts-node src/cli.ts balance",
|
||||
"sign": "ts-node src/cli.ts sign",
|
||||
"broadcast": "ts-node src/cli.ts broadcast",
|
||||
"proposals": "ts-node src/cli.ts proposals",
|
||||
"delegates": "ts-node src/cli.ts delegates"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"dist",
|
||||
"scripts",
|
||||
"src",
|
||||
"static",
|
||||
".env.example",
|
||||
".eslintrc.js",
|
||||
".gitattributes",
|
||||
".gitignore",
|
||||
".npmrc",
|
||||
"logo.png",
|
||||
"logo2.png",
|
||||
"tsconfig.json",
|
||||
"yarn.lock"
|
||||
],
|
||||
"dependencies": {},
|
||||
"optionalDependencies": {},
|
||||
"devDependencies": {
|
||||
"@colors/colors": "^1.6.0",
|
||||
"@tornado/core": "git+https://git.tornado.ws/tornadocontrib/tornado-core.git#8041bd7f7801fd97a87d8c1945c0251b49032ec3",
|
||||
"@typechain/ethers-v6": "^0.5.1",
|
||||
"@types/figlet": "^1.7.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
||||
"@typescript-eslint/parser": "^8.11.0",
|
||||
"bloomfilter.js": "^1.0.2",
|
||||
"cli-table3": "^0.6.4",
|
||||
"commander": "^12.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"esbuild-loader": "^4.2.2",
|
||||
"eslint": "8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-import-resolver-typescript": "^3.6.3",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-prettier": "^5.2.1",
|
||||
"figlet": "^1.8.0",
|
||||
"http-proxy-agent": "^7.0.2",
|
||||
"https-proxy-agent": "^7.0.4",
|
||||
"moment": "^2.30.1",
|
||||
"prettier": "^3.2.5",
|
||||
"socks-proxy-agent": "^8.0.3",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsc": "^2.0.4",
|
||||
"typechain": "^8.3.2",
|
||||
"typescript": "^5.6.3",
|
||||
"webpack": "^5.95.0",
|
||||
"webpack-cli": "^5.1.4"
|
||||
}
|
||||
"name": "@tornado/cli",
|
||||
"version": "1.0.11-alpha",
|
||||
"description": "Modern Toolsets for Privacy Pools on Ethereum",
|
||||
"main": "./dist/cli.js",
|
||||
"types": "./dist/cli.d.ts",
|
||||
"bin": {
|
||||
"tornado-cli": "./dist/cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"typechain": "typechain --target ethers-v6 --out-dir src/typechain src/abi/*.json",
|
||||
"types": "tsc --declaration --emitDeclarationOnly",
|
||||
"lint": "eslint src/**/*.ts --ext .ts --ignore-pattern src/typechain",
|
||||
"copy:worker": "ts-node scripts/copyFile.ts node_modules/@tornado/core/dist/merkleTreeWorker.js static/merkleTreeWorker.js",
|
||||
"build:node": "webpack",
|
||||
"build": "yarn types && yarn build:node",
|
||||
"start": "ts-node src/cli.ts",
|
||||
"help": "ts-node src/cli.ts help",
|
||||
"create": "ts-node src/cli.ts create",
|
||||
"deposit": "ts-node src/cli.ts deposit",
|
||||
"depositInvoice": "ts-node src/cli.ts depositInvoice",
|
||||
"withdraw": "ts-node src/cli.ts withdraw",
|
||||
"compliance": "ts-node src/cli.ts compliance",
|
||||
"updateEvents": "ts-node src/cli.ts updateEvents",
|
||||
"relayers": "ts-node src/cli.ts relayers",
|
||||
"createAccount": "ts-node src/cli.ts createAccount",
|
||||
"decrypt": "ts-node src/cli.ts decrypt",
|
||||
"send": "ts-node src/cli.ts send",
|
||||
"balance": "ts-node src/cli.ts balance",
|
||||
"sign": "ts-node src/cli.ts sign",
|
||||
"broadcast": "ts-node src/cli.ts broadcast",
|
||||
"proposals": "ts-node src/cli.ts proposals",
|
||||
"delegates": "ts-node src/cli.ts delegates"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"dist",
|
||||
"scripts",
|
||||
"src",
|
||||
"static",
|
||||
".env.example",
|
||||
".eslintrc.js",
|
||||
".gitattributes",
|
||||
".gitignore",
|
||||
".npmrc",
|
||||
"logo.png",
|
||||
"logo2.png",
|
||||
"tsconfig.json",
|
||||
"yarn.lock"
|
||||
],
|
||||
"dependencies": {},
|
||||
"optionalDependencies": {},
|
||||
"devDependencies": {
|
||||
"@colors/colors": "^1.6.0",
|
||||
"@tornado/core": "git+https://git.tornado.ws/tornadocontrib/tornado-core.git#f411159f15566cb0cfe46d07b1c2c4eb23af2e1f",
|
||||
"@typechain/ethers-v6": "^0.5.1",
|
||||
"@types/figlet": "^1.7.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
||||
"@typescript-eslint/parser": "^8.11.0",
|
||||
"bloomfilter.js": "^1.0.2",
|
||||
"cli-table3": "^0.6.4",
|
||||
"commander": "^12.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"esbuild-loader": "^4.2.2",
|
||||
"eslint": "8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-import-resolver-typescript": "^3.6.3",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-prettier": "^5.2.1",
|
||||
"figlet": "^1.8.0",
|
||||
"http-proxy-agent": "^7.0.2",
|
||||
"https-proxy-agent": "^7.0.4",
|
||||
"moment": "^2.30.1",
|
||||
"prettier": "^3.2.5",
|
||||
"socks-proxy-agent": "^8.0.3",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsc": "^2.0.4",
|
||||
"typechain": "^8.3.2",
|
||||
"typescript": "^5.6.3",
|
||||
"webpack": "^5.95.0",
|
||||
"webpack-cli": "^5.1.4"
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,14 @@ import { argv } from 'process';
|
||||
import { copyFile } from 'fs';
|
||||
|
||||
function copyFiles() {
|
||||
const [, , inFile, outFile] = argv;
|
||||
const [, , inFile, outFile] = argv;
|
||||
|
||||
copyFile(inFile, outFile, function(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
copyFile(inFile, outFile, function(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
console.log(`Copied ${inFile} to ${outFile}`)
|
||||
})
|
||||
console.log(`Copied ${inFile} to ${outFile}`)
|
||||
})
|
||||
}
|
||||
copyFiles()
|
4501
src/program.ts
4501
src/program.ts
File diff suppressed because it is too large
Load Diff
@ -4,164 +4,164 @@ import { stat, mkdir, readFile, writeFile } from 'fs/promises';
|
||||
import { BaseEvents, CachedEvents, MinimalEvents, zipAsync, unzipAsync } from '@tornado/core';
|
||||
|
||||
export async function existsAsync(fileOrDir: string): Promise<boolean> {
|
||||
try {
|
||||
await stat(fileOrDir);
|
||||
try {
|
||||
await stat(fileOrDir);
|
||||
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports legacy gz format for legacy UI
|
||||
*/
|
||||
export function deflateAsync(data: Uint8Array): Promise<Buffer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
deflate(
|
||||
data,
|
||||
{
|
||||
level: constants.Z_BEST_COMPRESSION,
|
||||
strategy: constants.Z_FILTERED,
|
||||
},
|
||||
(err, buffer) => {
|
||||
if (!err) {
|
||||
resolve(buffer);
|
||||
} else {
|
||||
reject(err);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
deflate(
|
||||
data,
|
||||
{
|
||||
level: constants.Z_BEST_COMPRESSION,
|
||||
strategy: constants.Z_FILTERED,
|
||||
},
|
||||
(err, buffer) => {
|
||||
if (!err) {
|
||||
resolve(buffer);
|
||||
} else {
|
||||
reject(err);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveLegacyFile({
|
||||
fileName,
|
||||
userDirectory,
|
||||
dataString,
|
||||
fileName,
|
||||
userDirectory,
|
||||
dataString,
|
||||
}: {
|
||||
fileName: string;
|
||||
userDirectory: string;
|
||||
dataString: string;
|
||||
fileName: string;
|
||||
userDirectory: string;
|
||||
dataString: string;
|
||||
}) {
|
||||
fileName = fileName.toLowerCase();
|
||||
fileName = fileName.toLowerCase();
|
||||
|
||||
const filePath = path.join(userDirectory, fileName);
|
||||
const filePath = path.join(userDirectory, fileName);
|
||||
|
||||
const payload = await deflateAsync(new TextEncoder().encode(dataString));
|
||||
const payload = await deflateAsync(new TextEncoder().encode(dataString));
|
||||
|
||||
if (!(await existsAsync(userDirectory))) {
|
||||
await mkdir(userDirectory, { recursive: true });
|
||||
}
|
||||
if (!(await existsAsync(userDirectory))) {
|
||||
await mkdir(userDirectory, { recursive: true });
|
||||
}
|
||||
|
||||
await writeFile(filePath + '.gz', payload);
|
||||
await writeFile(filePath + '.gz', payload);
|
||||
}
|
||||
|
||||
export async function saveUserFile({
|
||||
fileName,
|
||||
userDirectory,
|
||||
dataString,
|
||||
fileName,
|
||||
userDirectory,
|
||||
dataString,
|
||||
}: {
|
||||
fileName: string;
|
||||
userDirectory: string;
|
||||
dataString: string;
|
||||
fileName: string;
|
||||
userDirectory: string;
|
||||
dataString: string;
|
||||
}) {
|
||||
fileName = fileName.toLowerCase();
|
||||
fileName = fileName.toLowerCase();
|
||||
|
||||
const filePath = path.join(userDirectory, fileName);
|
||||
const filePath = path.join(userDirectory, fileName);
|
||||
|
||||
const payload = await zipAsync({
|
||||
[fileName]: new TextEncoder().encode(dataString),
|
||||
});
|
||||
const payload = await zipAsync({
|
||||
[fileName]: new TextEncoder().encode(dataString),
|
||||
});
|
||||
|
||||
if (!(await existsAsync(userDirectory))) {
|
||||
await mkdir(userDirectory, { recursive: true });
|
||||
}
|
||||
if (!(await existsAsync(userDirectory))) {
|
||||
await mkdir(userDirectory, { recursive: true });
|
||||
}
|
||||
|
||||
await writeFile(filePath + '.zip', payload);
|
||||
await writeFile(filePath, dataString);
|
||||
await writeFile(filePath + '.zip', payload);
|
||||
await writeFile(filePath, dataString);
|
||||
}
|
||||
|
||||
export async function loadSavedEvents<T extends MinimalEvents>({
|
||||
name,
|
||||
userDirectory,
|
||||
name,
|
||||
userDirectory,
|
||||
}: {
|
||||
name: string;
|
||||
userDirectory: string;
|
||||
name: string;
|
||||
userDirectory: string;
|
||||
}): Promise<BaseEvents<T>> {
|
||||
const filePath = path.join(userDirectory, `${name}.json`.toLowerCase());
|
||||
const filePath = path.join(userDirectory, `${name}.json`.toLowerCase());
|
||||
|
||||
if (!(await existsAsync(filePath))) {
|
||||
return {
|
||||
events: [] as T[],
|
||||
lastBlock: 0,
|
||||
};
|
||||
}
|
||||
if (!(await existsAsync(filePath))) {
|
||||
return {
|
||||
events: [] as T[],
|
||||
lastBlock: 0,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const events = JSON.parse(await readFile(filePath, { encoding: 'utf8' })) as T[];
|
||||
try {
|
||||
const events = JSON.parse(await readFile(filePath, { encoding: 'utf8' })) as T[];
|
||||
|
||||
return {
|
||||
events,
|
||||
lastBlock: events[events.length - 1]?.blockNumber || 0,
|
||||
};
|
||||
} catch (err) {
|
||||
console.log('Method loadSavedEvents has error');
|
||||
console.log(err);
|
||||
return {
|
||||
events: [],
|
||||
lastBlock: 0,
|
||||
};
|
||||
}
|
||||
return {
|
||||
events,
|
||||
lastBlock: events[events.length - 1]?.blockNumber || 0,
|
||||
};
|
||||
} catch (err) {
|
||||
console.log('Method loadSavedEvents has error');
|
||||
console.log(err);
|
||||
return {
|
||||
events: [],
|
||||
lastBlock: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function download({ name, cacheDirectory }: { name: string; cacheDirectory: string }) {
|
||||
const fileName = `${name}.json`.toLowerCase();
|
||||
const zipName = `${fileName}.zip`;
|
||||
const zipPath = path.join(cacheDirectory, zipName);
|
||||
const fileName = `${name}.json`.toLowerCase();
|
||||
const zipName = `${fileName}.zip`;
|
||||
const zipPath = path.join(cacheDirectory, zipName);
|
||||
|
||||
const data = await readFile(zipPath);
|
||||
const { [fileName]: content } = await unzipAsync(data);
|
||||
const data = await readFile(zipPath);
|
||||
const { [fileName]: content } = await unzipAsync(data);
|
||||
|
||||
return new TextDecoder().decode(content);
|
||||
return new TextDecoder().decode(content);
|
||||
}
|
||||
|
||||
export async function loadCachedEvents<T extends MinimalEvents>({
|
||||
name,
|
||||
cacheDirectory,
|
||||
deployedBlock,
|
||||
name,
|
||||
cacheDirectory,
|
||||
deployedBlock,
|
||||
}: {
|
||||
name: string;
|
||||
cacheDirectory: string;
|
||||
deployedBlock: number;
|
||||
name: string;
|
||||
cacheDirectory: string;
|
||||
deployedBlock: number;
|
||||
}): Promise<CachedEvents<T>> {
|
||||
try {
|
||||
const module = await download({ cacheDirectory, name });
|
||||
try {
|
||||
const module = await download({ cacheDirectory, name });
|
||||
|
||||
if (module) {
|
||||
const events = JSON.parse(module);
|
||||
if (module) {
|
||||
const events = JSON.parse(module);
|
||||
|
||||
const lastBlock = events && events.length ? events[events.length - 1].blockNumber : deployedBlock;
|
||||
const lastBlock = events && events.length ? events[events.length - 1].blockNumber : deployedBlock;
|
||||
|
||||
return {
|
||||
events,
|
||||
lastBlock,
|
||||
fromCache: true,
|
||||
};
|
||||
return {
|
||||
events,
|
||||
lastBlock,
|
||||
fromCache: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
events: [],
|
||||
lastBlock: deployedBlock,
|
||||
fromCache: true,
|
||||
};
|
||||
} catch (err) {
|
||||
console.log('Method loadCachedEvents has error');
|
||||
console.log(err);
|
||||
return {
|
||||
events: [],
|
||||
lastBlock: deployedBlock,
|
||||
fromCache: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
events: [],
|
||||
lastBlock: deployedBlock,
|
||||
fromCache: true,
|
||||
};
|
||||
} catch (err) {
|
||||
console.log('Method loadCachedEvents has error');
|
||||
console.log(err);
|
||||
return {
|
||||
events: [],
|
||||
lastBlock: deployedBlock,
|
||||
fromCache: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,75 +3,75 @@ import { computeAddress, getAddress, Mnemonic } from 'ethers';
|
||||
import { validateUrl } from '@tornado/core';
|
||||
|
||||
export function parseNumber(value?: string | number): number {
|
||||
if (!value || isNaN(Number(value))) {
|
||||
throw new InvalidArgumentError('Invalid Number');
|
||||
}
|
||||
return Number(value);
|
||||
if (!value || isNaN(Number(value))) {
|
||||
throw new InvalidArgumentError('Invalid Number');
|
||||
}
|
||||
return Number(value);
|
||||
}
|
||||
|
||||
export function parseUrl(value?: string): string {
|
||||
if (!value || !validateUrl(value, ['http:', 'https:'])) {
|
||||
throw new InvalidArgumentError('Invalid URL');
|
||||
}
|
||||
return value;
|
||||
if (!value || !validateUrl(value, ['http:', 'https:'])) {
|
||||
throw new InvalidArgumentError('Invalid URL');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function parseRelayer(value?: string): string {
|
||||
if (!value || !(value.endsWith('.eth') || validateUrl(value, ['http:', 'https:']))) {
|
||||
throw new InvalidArgumentError('Invalid Relayer ETH address or URL');
|
||||
}
|
||||
return value;
|
||||
if (!value || !(value.endsWith('.eth') || validateUrl(value, ['http:', 'https:']))) {
|
||||
throw new InvalidArgumentError('Invalid Relayer ETH address or URL');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function parseAddress(value?: string): string {
|
||||
if (!value) {
|
||||
throw new InvalidArgumentError('Invalid Address');
|
||||
}
|
||||
try {
|
||||
return getAddress(value);
|
||||
} catch {
|
||||
throw new InvalidArgumentError('Invalid Address');
|
||||
}
|
||||
if (!value) {
|
||||
throw new InvalidArgumentError('Invalid Address');
|
||||
}
|
||||
try {
|
||||
return getAddress(value);
|
||||
} catch {
|
||||
throw new InvalidArgumentError('Invalid Address');
|
||||
}
|
||||
}
|
||||
|
||||
export function parseMnemonic(value?: string): string {
|
||||
if (!value) {
|
||||
throw new InvalidArgumentError('Invalid Mnemonic');
|
||||
}
|
||||
try {
|
||||
Mnemonic.fromPhrase(value);
|
||||
} catch {
|
||||
throw new InvalidArgumentError('Invalid Mnemonic');
|
||||
}
|
||||
return value;
|
||||
if (!value) {
|
||||
throw new InvalidArgumentError('Invalid Mnemonic');
|
||||
}
|
||||
try {
|
||||
Mnemonic.fromPhrase(value);
|
||||
} catch {
|
||||
throw new InvalidArgumentError('Invalid Mnemonic');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function parseKey(value?: string): string {
|
||||
if (!value) {
|
||||
throw new InvalidArgumentError('Invalid Private Key');
|
||||
}
|
||||
if (value.length === 64) {
|
||||
value = '0x' + value;
|
||||
}
|
||||
try {
|
||||
computeAddress(value);
|
||||
} catch {
|
||||
throw new InvalidArgumentError('Invalid Private Key');
|
||||
}
|
||||
return value;
|
||||
if (!value) {
|
||||
throw new InvalidArgumentError('Invalid Private Key');
|
||||
}
|
||||
if (value.length === 64) {
|
||||
value = '0x' + value;
|
||||
}
|
||||
try {
|
||||
computeAddress(value);
|
||||
} catch {
|
||||
throw new InvalidArgumentError('Invalid Private Key');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recovery key shouldn't have a 0x prefix (Also this is how the UI generates)
|
||||
*/
|
||||
export function parseRecoveryKey(value?: string): string {
|
||||
if (!value) {
|
||||
throw new InvalidArgumentError('Invalid Recovery Key');
|
||||
}
|
||||
try {
|
||||
computeAddress('0x' + value);
|
||||
} catch {
|
||||
throw new InvalidArgumentError('Invalid Recovery Key');
|
||||
}
|
||||
return value;
|
||||
if (!value) {
|
||||
throw new InvalidArgumentError('Invalid Recovery Key');
|
||||
}
|
||||
try {
|
||||
computeAddress('0x' + value);
|
||||
} catch {
|
||||
throw new InvalidArgumentError('Invalid Recovery Key');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
@ -10,104 +10,104 @@ import type { NetIdType } from '@tornado/core';
|
||||
import { saveUserFile } from './data';
|
||||
|
||||
export interface TreeCacheConstructor {
|
||||
netId: NetIdType;
|
||||
amount: string;
|
||||
currency: string;
|
||||
userDirectory: string;
|
||||
PARTS_COUNT?: number;
|
||||
LEAVES?: number;
|
||||
zeroElement?: string;
|
||||
netId: NetIdType;
|
||||
amount: string;
|
||||
currency: string;
|
||||
userDirectory: string;
|
||||
PARTS_COUNT?: number;
|
||||
LEAVES?: number;
|
||||
zeroElement?: string;
|
||||
}
|
||||
|
||||
export interface treeMetadata {
|
||||
blockNumber: number;
|
||||
logIndex: number;
|
||||
transactionHash: string;
|
||||
timestamp: number;
|
||||
from: string;
|
||||
leafIndex: number;
|
||||
blockNumber: number;
|
||||
logIndex: number;
|
||||
transactionHash: string;
|
||||
timestamp: number;
|
||||
from: string;
|
||||
leafIndex: number;
|
||||
}
|
||||
|
||||
export class TreeCache {
|
||||
netId: NetIdType;
|
||||
amount: string;
|
||||
currency: string;
|
||||
userDirectory: string;
|
||||
netId: NetIdType;
|
||||
amount: string;
|
||||
currency: string;
|
||||
userDirectory: string;
|
||||
|
||||
PARTS_COUNT: number;
|
||||
PARTS_COUNT: number;
|
||||
|
||||
constructor({ netId, amount, currency, userDirectory, PARTS_COUNT = 4 }: TreeCacheConstructor) {
|
||||
this.netId = netId;
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
this.userDirectory = userDirectory;
|
||||
constructor({ netId, amount, currency, userDirectory, PARTS_COUNT = 4 }: TreeCacheConstructor) {
|
||||
this.netId = netId;
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
this.userDirectory = userDirectory;
|
||||
|
||||
this.PARTS_COUNT = PARTS_COUNT;
|
||||
}
|
||||
this.PARTS_COUNT = PARTS_COUNT;
|
||||
}
|
||||
|
||||
getInstanceName(): string {
|
||||
return `deposits_${this.netId}_${this.currency}_${this.amount}`;
|
||||
}
|
||||
getInstanceName(): string {
|
||||
return `deposits_${this.netId}_${this.currency}_${this.amount}`;
|
||||
}
|
||||
|
||||
async createTree(events: DepositsEvents[], tree: MerkleTree) {
|
||||
const bloom = new BloomFilter(events.length);
|
||||
async createTree(events: DepositsEvents[], tree: MerkleTree) {
|
||||
const bloom = new BloomFilter(events.length);
|
||||
|
||||
console.log(`Creating cached tree for ${this.getInstanceName()}\n`);
|
||||
console.log(`Creating cached tree for ${this.getInstanceName()}\n`);
|
||||
|
||||
// events indexed by commitment
|
||||
const eventsData = events.reduce(
|
||||
(acc, { leafIndex, commitment, ...rest }, i) => {
|
||||
if (leafIndex !== i) {
|
||||
throw new Error(`leafIndex (${leafIndex}) !== i (${i})`);
|
||||
}
|
||||
// events indexed by commitment
|
||||
const eventsData = events.reduce(
|
||||
(acc, { leafIndex, commitment, ...rest }, i) => {
|
||||
if (leafIndex !== i) {
|
||||
throw new Error(`leafIndex (${leafIndex}) !== i (${i})`);
|
||||
}
|
||||
|
||||
acc[commitment] = { ...rest, leafIndex };
|
||||
acc[commitment] = { ...rest, leafIndex };
|
||||
|
||||
return acc;
|
||||
},
|
||||
{} as { [key in string]: treeMetadata },
|
||||
);
|
||||
|
||||
const slices = tree.getTreeSlices(this.PARTS_COUNT);
|
||||
|
||||
await Promise.all(
|
||||
slices.map(async (slice, index) => {
|
||||
const metadata = slice.elements.reduce((acc, curr) => {
|
||||
if (index < this.PARTS_COUNT - 1) {
|
||||
bloom.add(curr);
|
||||
}
|
||||
acc.push(eventsData[curr]);
|
||||
return acc;
|
||||
}, [] as treeMetadata[]);
|
||||
|
||||
const dataString =
|
||||
JSON.stringify(
|
||||
{
|
||||
...slice,
|
||||
metadata,
|
||||
return acc;
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + '\n';
|
||||
{} as { [key in string]: treeMetadata },
|
||||
);
|
||||
|
||||
const fileName = `${this.getInstanceName()}_slice${index + 1}.json`;
|
||||
const slices = tree.getTreeSlices(this.PARTS_COUNT);
|
||||
|
||||
await Promise.all(
|
||||
slices.map(async (slice, index) => {
|
||||
const metadata = slice.elements.reduce((acc, curr) => {
|
||||
if (index < this.PARTS_COUNT - 1) {
|
||||
bloom.add(curr);
|
||||
}
|
||||
acc.push(eventsData[curr]);
|
||||
return acc;
|
||||
}, [] as treeMetadata[]);
|
||||
|
||||
const dataString =
|
||||
JSON.stringify(
|
||||
{
|
||||
...slice,
|
||||
metadata,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + '\n';
|
||||
|
||||
const fileName = `${this.getInstanceName()}_slice${index + 1}.json`;
|
||||
|
||||
await saveUserFile({
|
||||
fileName,
|
||||
userDirectory: this.userDirectory,
|
||||
dataString,
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
const dataString = bloom.serialize() + '\n';
|
||||
|
||||
const fileName = `${this.getInstanceName()}_bloom.json`;
|
||||
|
||||
await saveUserFile({
|
||||
fileName,
|
||||
userDirectory: this.userDirectory,
|
||||
dataString,
|
||||
fileName,
|
||||
userDirectory: this.userDirectory,
|
||||
dataString,
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
const dataString = bloom.serialize() + '\n';
|
||||
|
||||
const fileName = `${this.getInstanceName()}_bloom.json`;
|
||||
|
||||
await saveUserFile({
|
||||
fileName,
|
||||
userDirectory: this.userDirectory,
|
||||
dataString,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
28
src/types/bloomfilter.js.d.ts
vendored
28
src/types/bloomfilter.js.d.ts
vendored
@ -1,25 +1,25 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
declare module 'bloomfilter.js' {
|
||||
export default class BloomFilter {
|
||||
m: number;
|
||||
k: number;
|
||||
size: number;
|
||||
bitview: any;
|
||||
export default class BloomFilter {
|
||||
m: number;
|
||||
k: number;
|
||||
size: number;
|
||||
bitview: any;
|
||||
|
||||
constructor(n: number, false_postive_tolerance?: number);
|
||||
constructor(n: number, false_postive_tolerance?: number);
|
||||
|
||||
calculateHash(x: number, m: number, i: number): number;
|
||||
calculateHash(x: number, m: number, i: number): number;
|
||||
|
||||
test(data: any): boolean;
|
||||
test(data: any): boolean;
|
||||
|
||||
add(data: any): void;
|
||||
add(data: any): void;
|
||||
|
||||
bytelength(): number;
|
||||
bytelength(): number;
|
||||
|
||||
view(): Uint8Array;
|
||||
view(): Uint8Array;
|
||||
|
||||
serialize(): string;
|
||||
serialize(): string;
|
||||
|
||||
deserialize(serialized: string): BloomFilter;
|
||||
}
|
||||
deserialize(serialized: string): BloomFilter;
|
||||
}
|
||||
}
|
||||
|
@ -2,44 +2,44 @@ const path = require('path');
|
||||
const { BannerPlugin } = require('webpack');
|
||||
|
||||
const esbuildLoader = {
|
||||
test: /\.ts?$/,
|
||||
loader: 'esbuild-loader',
|
||||
options: {
|
||||
loader: 'ts',
|
||||
target: 'es2022',
|
||||
}
|
||||
test: /\.ts?$/,
|
||||
loader: 'esbuild-loader',
|
||||
options: {
|
||||
loader: 'ts',
|
||||
target: 'es2022',
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
mode: 'production',
|
||||
module: {
|
||||
rules: [esbuildLoader]
|
||||
},
|
||||
entry: './src/cli.ts',
|
||||
output: {
|
||||
filename: 'cli.js',
|
||||
path: path.resolve(__dirname, './dist'),
|
||||
},
|
||||
target: 'node',
|
||||
plugins: [
|
||||
new BannerPlugin({
|
||||
banner: '#!/usr/bin/env node\n',
|
||||
raw: true
|
||||
})
|
||||
],
|
||||
resolve: {
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
alias: {
|
||||
'fflate': 'fflate/node'
|
||||
},
|
||||
fallback: {
|
||||
'@tornado/websnark/src/utils': '@tornado/websnark/src/utils.js',
|
||||
'@tornado/websnark/src/groth16': '@tornado/websnark/src/groth16.js',
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
{
|
||||
mode: 'production',
|
||||
module: {
|
||||
rules: [esbuildLoader]
|
||||
},
|
||||
entry: './src/cli.ts',
|
||||
output: {
|
||||
filename: 'cli.js',
|
||||
path: path.resolve(__dirname, './dist'),
|
||||
},
|
||||
target: 'node',
|
||||
plugins: [
|
||||
new BannerPlugin({
|
||||
banner: '#!/usr/bin/env node\n',
|
||||
raw: true
|
||||
})
|
||||
],
|
||||
resolve: {
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
alias: {
|
||||
'fflate': 'fflate/node'
|
||||
},
|
||||
fallback: {
|
||||
'@tornado/websnark/src/utils': '@tornado/websnark/src/utils.js',
|
||||
'@tornado/websnark/src/groth16': '@tornado/websnark/src/groth16.js',
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
@ -785,9 +785,9 @@
|
||||
"@openzeppelin/contracts-v3" "npm:@openzeppelin/contracts@3.2.0-rc.0"
|
||||
ethers "^6.13.4"
|
||||
|
||||
"@tornado/core@git+https://git.tornado.ws/tornadocontrib/tornado-core.git#8041bd7f7801fd97a87d8c1945c0251b49032ec3":
|
||||
"@tornado/core@git+https://git.tornado.ws/tornadocontrib/tornado-core.git#f411159f15566cb0cfe46d07b1c2c4eb23af2e1f":
|
||||
version "1.0.19"
|
||||
resolved "git+https://git.tornado.ws/tornadocontrib/tornado-core.git#8041bd7f7801fd97a87d8c1945c0251b49032ec3"
|
||||
resolved "git+https://git.tornado.ws/tornadocontrib/tornado-core.git#f411159f15566cb0cfe46d07b1c2c4eb23af2e1f"
|
||||
dependencies:
|
||||
"@metamask/eth-sig-util" "^8.0.0"
|
||||
"@tornado/contracts" "git+https://git.tornado.ws/tornadocontrib/tornado-contracts.git#1b1d707878c16a3dc60d295299d4f0e7ce6ba831"
|
||||
|
Loading…
Reference in New Issue
Block a user