Added Permit Func

This commit is contained in:
Tornado Contrib 2024-10-24 00:25:44 +00:00
parent e3dc748020
commit 55d62f7973
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1
13 changed files with 4014 additions and 1164 deletions

1
dist/index.d.ts vendored

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

100
dist/index.js vendored

@ -10037,9 +10037,9 @@ async function getIndexedDB(netId) {
} }
]; ];
const config = getConfig(netId); const config = getConfig(netId);
const { tokens, nativeCurrency } = config; const { tokens, nativeCurrency, registryContract, governanceContract } = config;
const stores = [...defaultState]; const stores = [...defaultState];
if (netId === NetId.MAINNET) { if (registryContract) {
stores.push({ stores.push({
name: `registered_${netId}`, name: `registered_${netId}`,
keyPath: "ensName", keyPath: "ensName",
@ -10051,6 +10051,8 @@ async function getIndexedDB(netId) {
} }
] ]
}); });
}
if (governanceContract) {
stores.push({ stores.push({
name: `governance_${netId}`, name: `governance_${netId}`,
keyPath: "eid", keyPath: "eid",
@ -10311,6 +10313,97 @@ async function multicall(Multicall2, calls) {
return res; 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 { class TokenPriceOracle {
oracle; oracle;
multicall; multicall;
@ -10837,6 +10930,8 @@ exports.getInstanceByAddress = getInstanceByAddress;
exports.getMeta = getMeta; exports.getMeta = getMeta;
exports.getNetworkConfig = getNetworkConfig; exports.getNetworkConfig = getNetworkConfig;
exports.getNoteAccounts = getNoteAccounts; exports.getNoteAccounts = getNoteAccounts;
exports.getPermit2Signature = getPermit2Signature;
exports.getPermitSignature = getPermitSignature;
exports.getProvider = getProvider; exports.getProvider = getProvider;
exports.getProviderWithNetId = getProviderWithNetId; exports.getProviderWithNetId = getProviderWithNetId;
exports.getRegisters = getRegisters; exports.getRegisters = getRegisters;
@ -10866,6 +10961,7 @@ exports.multicall = multicall;
exports.numberFormatter = numberFormatter; exports.numberFormatter = numberFormatter;
exports.packEncryptedMessage = packEncryptedMessage; exports.packEncryptedMessage = packEncryptedMessage;
exports.pedersen = pedersen; exports.pedersen = pedersen;
exports.permit2Address = permit2Address;
exports.pickWeightedRandomRelayer = pickWeightedRandomRelayer; exports.pickWeightedRandomRelayer = pickWeightedRandomRelayer;
exports.populateTransaction = populateTransaction; exports.populateTransaction = populateTransaction;
exports.proofSchemaType = proofSchemaType; exports.proofSchemaType = proofSchemaType;

101
dist/index.mjs vendored

@ -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 crossFetch from 'cross-fetch';
import { webcrypto } from 'crypto'; import { webcrypto } from 'crypto';
import BN from 'bn.js'; import BN from 'bn.js';
@ -10016,9 +10016,9 @@ async function getIndexedDB(netId) {
} }
]; ];
const config = getConfig(netId); const config = getConfig(netId);
const { tokens, nativeCurrency } = config; const { tokens, nativeCurrency, registryContract, governanceContract } = config;
const stores = [...defaultState]; const stores = [...defaultState];
if (netId === NetId.MAINNET) { if (registryContract) {
stores.push({ stores.push({
name: `registered_${netId}`, name: `registered_${netId}`,
keyPath: "ensName", keyPath: "ensName",
@ -10030,6 +10030,8 @@ async function getIndexedDB(netId) {
} }
] ]
}); });
}
if (governanceContract) {
stores.push({ stores.push({
name: `governance_${netId}`, name: `governance_${netId}`,
keyPath: "eid", keyPath: "eid",
@ -10290,6 +10292,97 @@ async function multicall(Multicall2, calls) {
return res; 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 { class TokenPriceOracle {
oracle; oracle;
multicall; multicall;
@ -10700,4 +10793,4 @@ async function calculateSnarkProof(input, circuit, provingKey) {
return { proof, args }; 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

@ -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

@ -32,7 +32,7 @@
], ],
"dependencies": { "dependencies": {
"@metamask/eth-sig-util": "^7.0.3", "@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/fixed-merkle-tree": "git+https://codeberg.org/tornadocash/fixed-merkle-tree.git#5c3fca4cb11255760ad5f4fd95d7c6eb45c1fc99",
"@tornado/snarkjs": "git+https://codeberg.org/tornadocash/snarkjs.git#d3915a760c437cde7bd317f9ea2c627954900656", "@tornado/snarkjs": "git+https://codeberg.org/tornadocash/snarkjs.git#d3915a760c437cde7bd317f9ea2c627954900656",
"@tornado/websnark": "git+https://codeberg.org/tornadocash/websnark.git#b0c9fce5359ceba55167a2ad01a29d1e137843ec", "@tornado/websnark": "git+https://codeberg.org/tornadocash/websnark.git#b0c9fce5359ceba55167a2ad01a29d1e137843ec",

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
import { openDB, deleteDB, OpenDBCallbacks, IDBPDatabase } from 'idb'; 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.'; 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 config = getConfig(netId);
const { tokens, nativeCurrency } = config; const { tokens, nativeCurrency, registryContract, governanceContract } = config;
const stores = [...defaultState]; const stores = [...defaultState];
if (netId === NetId.MAINNET) { if (registryContract) {
stores.push({ stores.push({
name: `registered_${netId}`, name: `registered_${netId}`,
keyPath: 'ensName', keyPath: 'ensName',
@ -380,7 +380,9 @@ export async function getIndexedDB(netId?: NetIdType) {
}, },
], ],
}); });
}
if (governanceContract) {
stores.push({ stores.push({
name: `governance_${netId}`, name: `governance_${netId}`,
keyPath: 'eid', keyPath: 'eid',

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

147
src/permit.ts Normal 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,
};
}

@ -872,9 +872,9 @@
"@noble/hashes" "~1.4.0" "@noble/hashes" "~1.4.0"
"@scure/base" "~1.1.6" "@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" 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: dependencies:
"@openzeppelin/contracts" "5.0.2" "@openzeppelin/contracts" "5.0.2"
"@openzeppelin/contracts-v3" "npm:@openzeppelin/contracts@3.2.0-rc.0" "@openzeppelin/contracts-v3" "npm:@openzeppelin/contracts@3.2.0-rc.0"