Minor updates #1

Closed
tornadocontrib wants to merge 67 commits from tornadocontrib/tornado-core:main into main
13 changed files with 4014 additions and 1164 deletions
Showing only changes of commit 55d62f7973 - Show all commits

1
dist/index.d.ts vendored
View File

@ -14,6 +14,7 @@ export * from './mimc';
export * from './multicall';
export * from './networkConfig';
export * from './pedersen';
export * from './permit';
export * from './prices';
export * from './providers';
export * from './relayerClient';

100
dist/index.js vendored
View File

@ -10037,9 +10037,9 @@ async function getIndexedDB(netId) {
}
];
const config = getConfig(netId);
const { tokens, nativeCurrency } = config;
const { tokens, nativeCurrency, registryContract, governanceContract } = config;
const stores = [...defaultState];
if (netId === NetId.MAINNET) {
if (registryContract) {
stores.push({
name: `registered_${netId}`,
keyPath: "ensName",
@ -10051,6 +10051,8 @@ async function getIndexedDB(netId) {
}
]
});
}
if (governanceContract) {
stores.push({
name: `governance_${netId}`,
keyPath: "eid",
@ -10311,6 +10313,97 @@ async function multicall(Multicall2, calls) {
return res;
}
const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
const signer = Token.runner;
const provider = signer.provider;
const [name, lastNonce, { chainId }] = await Promise.all([
Token.name(),
Token.nonces(signer.address),
provider.getNetwork()
]);
const DOMAIN_SEPARATOR = {
name,
version: "1",
chainId,
verifyingContract: Token.target
};
const PERMIT_TYPE = {
Permit: [
{ name: "owner", type: "address" },
{ name: "spender", type: "address" },
{ name: "value", type: "uint256" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" }
]
};
return ethers.Signature.from(
await signer.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
owner: signer.address,
spender,
value,
nonce: nonce || lastNonce,
deadline: deadline || ethers.MaxUint256
})
);
}
async function getPermit2Signature(Token, { spender, value: amount, nonce, deadline }, witness) {
const signer = Token.runner;
const provider = signer.provider;
const domain = {
name: "Permit2",
chainId: (await provider.getNetwork()).chainId,
verifyingContract: permit2Address
};
const types = !witness ? {
PermitTransferFrom: [
{ name: "permitted", type: "TokenPermissions" },
{ name: "spender", type: "address" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" }
],
TokenPermissions: [
{ name: "token", type: "address" },
{ name: "amount", type: "uint256" }
]
} : {
PermitWitnessTransferFrom: [
{ name: "permitted", type: "TokenPermissions" },
{ name: "spender", type: "address" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" },
{ name: "witness", type: witness.witnessTypeName }
],
TokenPermissions: [
{ name: "token", type: "address" },
{ name: "amount", type: "uint256" }
],
...witness.witnessType
};
const values = {
permitted: {
token: Token.target,
amount
},
spender,
// Sorted nonce are not required for Permit2
nonce: nonce || rBigInt(16),
deadline: deadline || ethers.MaxUint256
};
if (witness) {
values.witness = witness.witness;
}
const hash = new ethers.TypedDataEncoder(types).hash(values);
const signature = ethers.Signature.from(await signer.signTypedData(domain, types, values));
return {
domain,
types,
values,
hash,
signature
};
}
class TokenPriceOracle {
oracle;
multicall;
@ -10837,6 +10930,8 @@ exports.getInstanceByAddress = getInstanceByAddress;
exports.getMeta = getMeta;
exports.getNetworkConfig = getNetworkConfig;
exports.getNoteAccounts = getNoteAccounts;
exports.getPermit2Signature = getPermit2Signature;
exports.getPermitSignature = getPermitSignature;
exports.getProvider = getProvider;
exports.getProviderWithNetId = getProviderWithNetId;
exports.getRegisters = getRegisters;
@ -10866,6 +10961,7 @@ exports.multicall = multicall;
exports.numberFormatter = numberFormatter;
exports.packEncryptedMessage = packEncryptedMessage;
exports.pedersen = pedersen;
exports.permit2Address = permit2Address;
exports.pickWeightedRandomRelayer = pickWeightedRandomRelayer;
exports.populateTransaction = populateTransaction;
exports.proofSchemaType = proofSchemaType;

101
dist/index.mjs vendored
View File

@ -1,4 +1,4 @@
import { FetchRequest, JsonRpcProvider, Network, EnsPlugin, GasCostPlugin, Wallet, HDNodeWallet, VoidSigner, JsonRpcSigner, BrowserProvider, getAddress, isAddress, parseEther, AbiCoder, namehash, formatEther, dataSlice, dataLength, Interface, Contract, computeAddress, keccak256, EnsResolver, parseUnits, Transaction, ZeroAddress } from 'ethers';
import { FetchRequest, JsonRpcProvider, Network, EnsPlugin, GasCostPlugin, Wallet, HDNodeWallet, VoidSigner, JsonRpcSigner, BrowserProvider, getAddress, isAddress, parseEther, AbiCoder, namehash, formatEther, dataSlice, dataLength, Interface, Contract, computeAddress, keccak256, EnsResolver, parseUnits, Transaction, Signature, MaxUint256, TypedDataEncoder, ZeroAddress } from 'ethers';
import crossFetch from 'cross-fetch';
import { webcrypto } from 'crypto';
import BN from 'bn.js';
@ -10016,9 +10016,9 @@ async function getIndexedDB(netId) {
}
];
const config = getConfig(netId);
const { tokens, nativeCurrency } = config;
const { tokens, nativeCurrency, registryContract, governanceContract } = config;
const stores = [...defaultState];
if (netId === NetId.MAINNET) {
if (registryContract) {
stores.push({
name: `registered_${netId}`,
keyPath: "ensName",
@ -10030,6 +10030,8 @@ async function getIndexedDB(netId) {
}
]
});
}
if (governanceContract) {
stores.push({
name: `governance_${netId}`,
keyPath: "eid",
@ -10290,6 +10292,97 @@ async function multicall(Multicall2, calls) {
return res;
}
const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
const signer = Token.runner;
const provider = signer.provider;
const [name, lastNonce, { chainId }] = await Promise.all([
Token.name(),
Token.nonces(signer.address),
provider.getNetwork()
]);
const DOMAIN_SEPARATOR = {
name,
version: "1",
chainId,
verifyingContract: Token.target
};
const PERMIT_TYPE = {
Permit: [
{ name: "owner", type: "address" },
{ name: "spender", type: "address" },
{ name: "value", type: "uint256" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" }
]
};
return Signature.from(
await signer.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
owner: signer.address,
spender,
value,
nonce: nonce || lastNonce,
deadline: deadline || MaxUint256
})
);
}
async function getPermit2Signature(Token, { spender, value: amount, nonce, deadline }, witness) {
const signer = Token.runner;
const provider = signer.provider;
const domain = {
name: "Permit2",
chainId: (await provider.getNetwork()).chainId,
verifyingContract: permit2Address
};
const types = !witness ? {
PermitTransferFrom: [
{ name: "permitted", type: "TokenPermissions" },
{ name: "spender", type: "address" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" }
],
TokenPermissions: [
{ name: "token", type: "address" },
{ name: "amount", type: "uint256" }
]
} : {
PermitWitnessTransferFrom: [
{ name: "permitted", type: "TokenPermissions" },
{ name: "spender", type: "address" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" },
{ name: "witness", type: witness.witnessTypeName }
],
TokenPermissions: [
{ name: "token", type: "address" },
{ name: "amount", type: "uint256" }
],
...witness.witnessType
};
const values = {
permitted: {
token: Token.target,
amount
},
spender,
// Sorted nonce are not required for Permit2
nonce: nonce || rBigInt(16),
deadline: deadline || MaxUint256
};
if (witness) {
values.witness = witness.witness;
}
const hash = new TypedDataEncoder(types).hash(values);
const signature = Signature.from(await signer.signTypedData(domain, types, values));
return {
domain,
types,
values,
hash,
signature
};
}
class TokenPriceOracle {
oracle;
multicall;
@ -10700,4 +10793,4 @@ async function calculateSnarkProof(input, circuit, provingKey) {
return { proof, args };
}
export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseRegistryService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DBEchoService, DBEncryptedNotesService, DBGovernanceService, DBRegistryService, DBTornadoService, DEPOSIT, Deposit, ENSNameWrapper__factory, ENSRegistry__factory, ENSResolver__factory, ENSUtils, ENS__factory, ERC20__factory, EnsContracts, GET_DEPOSITS, GET_ECHO_EVENTS, GET_ENCRYPTED_NOTES, GET_GOVERNANCE_APY, GET_GOVERNANCE_EVENTS, GET_NOTE_ACCOUNTS, GET_REGISTERED, GET_STATISTIC, GET_WITHDRAWALS, INDEX_DB_ERROR, IndexedDB, 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, downloadZip, echoEventsSchema, enabledChains, encodedLabelToLabelhash, encryptedNotesSchema, index as factories, fetch, fetchData, fetchGetUrlFunc, gasZipID, gasZipInbounds, gasZipInput, gasZipMinMax, getActiveTokenInstances, getActiveTokens, getAllDeposits, getAllEncryptedNotes, getAllGovernanceEvents, getAllGraphEchoEvents, getAllRegisters, getAllWithdrawals, getConfig, getDeposits, getEncryptedNotes, getEventsSchemaValidator, getGovernanceEvents, getGraphEchoEvents, getHttpAgent, getIndexedDB, getInstanceByAddress, getMeta, getNetworkConfig, getNoteAccounts, getProvider, getProviderWithNetId, getRegisters, getRelayerEnsSubdomains, getStatistic, getStatusSchema, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, getWithdrawals, governanceEventsSchema, hexToBytes, initGroth16, isHex, isNode, jobRequestSchema, jobsSchema, labelhash, leBuff2Int, leInt2Buff, loadDBEvents, loadRemoteEvents, makeLabelNodeAndParent, mimc, multicall, numberFormatter, packEncryptedMessage, pedersen, pickWeightedRandomRelayer, populateTransaction, proofSchemaType, proposalState, queryGraph, rBigInt, registeredEventsSchema, saveDBEvents, sleep, substring, toFixedHex, toFixedLength, unpackEncryptedMessage, unzipAsync, validateUrl, withdrawalsEventsSchema, zipAsync };
export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseRegistryService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DBEchoService, DBEncryptedNotesService, DBGovernanceService, DBRegistryService, DBTornadoService, DEPOSIT, Deposit, ENSNameWrapper__factory, ENSRegistry__factory, ENSResolver__factory, ENSUtils, ENS__factory, ERC20__factory, EnsContracts, GET_DEPOSITS, GET_ECHO_EVENTS, GET_ENCRYPTED_NOTES, GET_GOVERNANCE_APY, GET_GOVERNANCE_EVENTS, GET_NOTE_ACCOUNTS, GET_REGISTERED, GET_STATISTIC, GET_WITHDRAWALS, INDEX_DB_ERROR, IndexedDB, 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, downloadZip, echoEventsSchema, enabledChains, encodedLabelToLabelhash, encryptedNotesSchema, index as factories, fetch, fetchData, fetchGetUrlFunc, gasZipID, gasZipInbounds, gasZipInput, gasZipMinMax, getActiveTokenInstances, getActiveTokens, getAllDeposits, getAllEncryptedNotes, getAllGovernanceEvents, getAllGraphEchoEvents, getAllRegisters, getAllWithdrawals, getConfig, getDeposits, getEncryptedNotes, getEventsSchemaValidator, getGovernanceEvents, getGraphEchoEvents, getHttpAgent, getIndexedDB, getInstanceByAddress, getMeta, getNetworkConfig, getNoteAccounts, getPermit2Signature, getPermitSignature, getProvider, getProviderWithNetId, getRegisters, getRelayerEnsSubdomains, getStatistic, getStatusSchema, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, getWithdrawals, governanceEventsSchema, hexToBytes, initGroth16, isHex, isNode, jobRequestSchema, jobsSchema, labelhash, leBuff2Int, leInt2Buff, loadDBEvents, loadRemoteEvents, makeLabelNodeAndParent, mimc, multicall, numberFormatter, packEncryptedMessage, pedersen, permit2Address, pickWeightedRandomRelayer, populateTransaction, proofSchemaType, proposalState, queryGraph, rBigInt, registeredEventsSchema, saveDBEvents, sleep, substring, toFixedHex, toFixedLength, unpackEncryptedMessage, unzipAsync, validateUrl, withdrawalsEventsSchema, zipAsync };

42
dist/permit.d.ts vendored Normal file
View File

@ -0,0 +1,42 @@
import { ERC20Permit, ERC20Mock, TORN } from '@tornado/contracts';
import { BaseContract, Signature, TypedDataField } from 'ethers';
export interface PermitValue {
spender: string;
value: bigint;
nonce?: bigint;
deadline?: bigint;
}
export declare const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
/**
* From @uniswap/permit2-sdk ported for ethers.js v6
*/
export interface Witness {
witnessTypeName: string;
witnessType: {
[key: string]: TypedDataField[];
};
witness: any;
}
export declare function getPermitSignature(Token: ERC20Permit | ERC20Mock | TORN, { spender, value, nonce, deadline }: PermitValue): Promise<Signature>;
export declare function getPermit2Signature(Token: BaseContract, { spender, value: amount, nonce, deadline }: PermitValue, witness?: Witness): Promise<{
domain: {
name: string;
chainId: bigint;
verifyingContract: string;
};
types: {
[key: string]: TypedDataField[];
};
values: {
permitted: {
token: string;
amount: bigint;
};
spender: string;
nonce: bigint;
deadline: bigint;
witness?: any;
};
hash: string;
signature: Signature;
}>;

1392
dist/tornado.umd.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -32,7 +32,7 @@
],
"dependencies": {
"@metamask/eth-sig-util": "^7.0.3",
"@tornado/contracts": "git+https://codeberg.org/tornadocash/tornado-contracts.git#ece511f424dc811c3aec149a4bf0e3731c0598a4",
"@tornado/contracts": "git+https://codeberg.org/tornadocash/tornado-contracts.git#1b1d707878c16a3dc60d295299d4f0e7ce6ba831",
"@tornado/fixed-merkle-tree": "git+https://codeberg.org/tornadocash/fixed-merkle-tree.git#5c3fca4cb11255760ad5f4fd95d7c6eb45c1fc99",
"@tornado/snarkjs": "git+https://codeberg.org/tornadocash/snarkjs.git#d3915a760c437cde7bd317f9ea2c627954900656",
"@tornado/websnark": "git+https://codeberg.org/tornadocash/websnark.git#b0c9fce5359ceba55167a2ad01a29d1e137843ec",

View File

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { openDB, deleteDB, OpenDBCallbacks, IDBPDatabase } from 'idb';
import { getConfig, NetId, NetIdType } from './networkConfig';
import { getConfig, NetIdType } from './networkConfig';
export const INDEX_DB_ERROR = 'A mutation operation was attempted on a database that did not allow mutations.';
@ -364,11 +364,11 @@ export async function getIndexedDB(netId?: NetIdType) {
const config = getConfig(netId);
const { tokens, nativeCurrency } = config;
const { tokens, nativeCurrency, registryContract, governanceContract } = config;
const stores = [...defaultState];
if (netId === NetId.MAINNET) {
if (registryContract) {
stores.push({
name: `registered_${netId}`,
keyPath: 'ensName',
@ -380,7 +380,9 @@ export async function getIndexedDB(netId?: NetIdType) {
},
],
});
}
if (governanceContract) {
stores.push({
name: `governance_${netId}`,
keyPath: 'eid',

View File

@ -14,6 +14,7 @@ export * from './mimc';
export * from './multicall';
export * from './networkConfig';
export * from './pedersen';
export * from './permit';
export * from './prices';
export * from './providers';
export * from './relayerClient';

147
src/permit.ts Normal file
View File

@ -0,0 +1,147 @@
import { ERC20Permit, ERC20Mock, TORN } from '@tornado/contracts';
import { BaseContract, MaxUint256, Provider, Signature, Signer, TypedDataEncoder, TypedDataField } from 'ethers';
import { rBigInt } from './utils';
export interface PermitValue {
spender: string;
value: bigint;
nonce?: bigint;
deadline?: bigint;
}
export const permit2Address = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
/**
* From @uniswap/permit2-sdk ported for ethers.js v6
*/
export interface Witness {
witnessTypeName: string;
witnessType: {
[key: string]: TypedDataField[];
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
witness: any;
}
export async function getPermitSignature(
Token: ERC20Permit | ERC20Mock | TORN,
{ spender, value, nonce, deadline }: PermitValue,
) {
const signer = Token.runner as Signer & { address: string };
const provider = signer.provider as Provider;
const [name, lastNonce, { chainId }] = await Promise.all([
Token.name(),
Token.nonces(signer.address),
provider.getNetwork(),
]);
const DOMAIN_SEPARATOR = {
name,
version: '1',
chainId,
verifyingContract: Token.target as string,
};
const PERMIT_TYPE = {
Permit: [
{ name: 'owner', type: 'address' },
{ name: 'spender', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'uint256' },
],
};
return Signature.from(
await signer.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
owner: signer.address,
spender,
value,
nonce: nonce || lastNonce,
deadline: deadline || MaxUint256,
}),
);
}
export async function getPermit2Signature(
Token: BaseContract,
{ spender, value: amount, nonce, deadline }: PermitValue,
witness?: Witness,
) {
const signer = Token.runner as Signer & { address: string };
const provider = signer.provider as Provider;
const domain = {
name: 'Permit2',
chainId: (await provider.getNetwork()).chainId,
verifyingContract: permit2Address,
};
const types: {
[key: string]: TypedDataField[];
} = !witness
? {
PermitTransferFrom: [
{ name: 'permitted', type: 'TokenPermissions' },
{ name: 'spender', type: 'address' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'uint256' },
],
TokenPermissions: [
{ name: 'token', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
}
: {
PermitWitnessTransferFrom: [
{ name: 'permitted', type: 'TokenPermissions' },
{ name: 'spender', type: 'address' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'uint256' },
{ name: 'witness', type: witness.witnessTypeName },
],
TokenPermissions: [
{ name: 'token', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
...witness.witnessType,
};
const values: {
permitted: {
token: string;
amount: bigint;
};
spender: string;
nonce: bigint;
deadline: bigint;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
witness?: any;
} = {
permitted: {
token: Token.target as string,
amount,
},
spender,
// Sorted nonce are not required for Permit2
nonce: nonce || rBigInt(16),
deadline: deadline || MaxUint256,
};
if (witness) {
values.witness = witness.witness;
}
const hash = new TypedDataEncoder(types).hash(values);
const signature = Signature.from(await signer.signTypedData(domain, types, values));
return {
domain,
types,
values,
hash,
signature,
};
}

View File

@ -872,9 +872,9 @@
"@noble/hashes" "~1.4.0"
"@scure/base" "~1.1.6"
"@tornado/contracts@git+https://codeberg.org/tornadocash/tornado-contracts.git#ece511f424dc811c3aec149a4bf0e3731c0598a4":
"@tornado/contracts@git+https://codeberg.org/tornadocash/tornado-contracts.git#1b1d707878c16a3dc60d295299d4f0e7ce6ba831":
version "1.0.2"
resolved "git+https://codeberg.org/tornadocash/tornado-contracts.git#ece511f424dc811c3aec149a4bf0e3731c0598a4"
resolved "git+https://codeberg.org/tornadocash/tornado-contracts.git#1b1d707878c16a3dc60d295299d4f0e7ce6ba831"
dependencies:
"@openzeppelin/contracts" "5.0.2"
"@openzeppelin/contracts-v3" "npm:@openzeppelin/contracts@3.2.0-rc.0"