forked from tornado-packages/tornado-core
Improve parsing notes
This commit is contained in:
parent
55d62f7973
commit
34d687c319
12
dist/deposits.d.ts
vendored
12
dist/deposits.d.ts
vendored
@ -22,7 +22,14 @@ export interface createNoteParams extends DepositType {
|
||||
}
|
||||
export interface parsedNoteExec extends DepositType {
|
||||
note: string;
|
||||
noteHex: string;
|
||||
}
|
||||
export interface parsedInvoiceExec extends DepositType {
|
||||
invoice: string;
|
||||
commitmentHex: string;
|
||||
}
|
||||
export declare function parseNote(noteString: string): parsedNoteExec | undefined;
|
||||
export declare function parseInvoice(invoiceString: string): parsedInvoiceExec | undefined;
|
||||
export declare function createDeposit({ nullifier, secret }: createDepositParams): Promise<createDepositObject>;
|
||||
export interface DepositConstructor {
|
||||
currency: string;
|
||||
@ -52,14 +59,11 @@ export declare class Deposit {
|
||||
static createNote({ currency, amount, netId, nullifier, secret }: createNoteParams): Promise<Deposit>;
|
||||
static parseNote(noteString: string): Promise<Deposit>;
|
||||
}
|
||||
export interface parsedInvoiceExec extends DepositType {
|
||||
commitment: string;
|
||||
}
|
||||
export declare class Invoice {
|
||||
currency: string;
|
||||
amount: string;
|
||||
netId: NetIdType;
|
||||
commitment: string;
|
||||
commitmentHex: string;
|
||||
invoice: string;
|
||||
constructor(invoiceString: string);
|
||||
toString(): string;
|
||||
|
165
dist/index.js
vendored
165
dist/index.js
vendored
@ -9238,6 +9238,36 @@ async function buffPedersenHash(buffer) {
|
||||
return pedersen.toStringBuffer(hash);
|
||||
}
|
||||
|
||||
function parseNote(noteString) {
|
||||
const noteRegex = /tornado-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<noteHex>[0-9a-fA-F]{124})/g;
|
||||
const match = noteRegex.exec(noteString);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
const { currency, amount, netId, noteHex } = match.groups;
|
||||
return {
|
||||
currency: currency.toLowerCase(),
|
||||
amount,
|
||||
netId: Number(netId),
|
||||
noteHex: "0x" + noteHex,
|
||||
note: noteString
|
||||
};
|
||||
}
|
||||
function parseInvoice(invoiceString) {
|
||||
const invoiceRegex = /tornadoInvoice-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<commitmentHex>[0-9a-fA-F]{64})/g;
|
||||
const match = invoiceRegex.exec(invoiceString);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
const { currency, amount, netId, commitmentHex } = match.groups;
|
||||
return {
|
||||
currency: currency.toLowerCase(),
|
||||
amount,
|
||||
netId: Number(netId),
|
||||
commitmentHex: "0x" + commitmentHex,
|
||||
invoice: invoiceString
|
||||
};
|
||||
}
|
||||
async function createDeposit({ nullifier, secret }) {
|
||||
const preimage = new Uint8Array([...leInt2Buff(nullifier), ...leInt2Buff(secret)]);
|
||||
const noteHex = toFixedHex(bytesToBN(preimage), 62);
|
||||
@ -9332,31 +9362,27 @@ class Deposit {
|
||||
return newDeposit;
|
||||
}
|
||||
static async parseNote(noteString) {
|
||||
const noteRegex = /tornado-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<note>[0-9a-fA-F]{124})/g;
|
||||
const match = noteRegex.exec(noteString);
|
||||
if (!match) {
|
||||
const parsedNote = parseNote(noteString);
|
||||
if (!parsedNote) {
|
||||
throw new Error("The note has invalid format");
|
||||
}
|
||||
const matchGroup = match?.groups;
|
||||
const currency = matchGroup.currency.toLowerCase();
|
||||
const amount = matchGroup.amount;
|
||||
const netId = Number(matchGroup.netId);
|
||||
const bytes = bnToBytes("0x" + matchGroup.note);
|
||||
const { currency, amount, netId, note, noteHex: parsedNoteHex } = parsedNote;
|
||||
const bytes = bnToBytes(parsedNoteHex);
|
||||
const nullifier = BigInt(leBuff2Int(bytes.slice(0, 31)).toString());
|
||||
const secret = BigInt(leBuff2Int(bytes.slice(31, 62)).toString());
|
||||
const depositObject = await createDeposit({ nullifier, secret });
|
||||
const invoice = `tornadoInvoice-${currency}-${amount}-${netId}-${depositObject.commitmentHex}`;
|
||||
const { noteHex, commitmentHex, nullifierHex } = await createDeposit({ nullifier, secret });
|
||||
const invoice = `tornadoInvoice-${currency}-${amount}-${netId}-${commitmentHex}`;
|
||||
const newDeposit = new Deposit({
|
||||
currency,
|
||||
amount,
|
||||
netId,
|
||||
note: noteString,
|
||||
noteHex: depositObject.noteHex,
|
||||
note,
|
||||
noteHex,
|
||||
invoice,
|
||||
nullifier,
|
||||
secret,
|
||||
commitmentHex: depositObject.commitmentHex,
|
||||
nullifierHex: depositObject.nullifierHex
|
||||
commitmentHex,
|
||||
nullifierHex
|
||||
});
|
||||
return newDeposit;
|
||||
}
|
||||
@ -9365,23 +9391,19 @@ class Invoice {
|
||||
currency;
|
||||
amount;
|
||||
netId;
|
||||
commitment;
|
||||
commitmentHex;
|
||||
invoice;
|
||||
constructor(invoiceString) {
|
||||
const invoiceRegex = /tornadoInvoice-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<commitment>[0-9a-fA-F]{64})/g;
|
||||
const match = invoiceRegex.exec(invoiceString);
|
||||
if (!match) {
|
||||
throw new Error("The note has invalid format");
|
||||
const parsedInvoice = parseInvoice(invoiceString);
|
||||
if (!parsedInvoice) {
|
||||
throw new Error("The invoice has invalid format");
|
||||
}
|
||||
const matchGroup = match?.groups;
|
||||
const currency = matchGroup.currency.toLowerCase();
|
||||
const amount = matchGroup.amount;
|
||||
const netId = Number(matchGroup.netId);
|
||||
const { currency, amount, netId, invoice, commitmentHex } = parsedInvoice;
|
||||
this.currency = currency;
|
||||
this.amount = amount;
|
||||
this.netId = netId;
|
||||
this.commitment = "0x" + matchGroup.commitment;
|
||||
this.invoice = invoiceString;
|
||||
this.commitmentHex = commitmentHex;
|
||||
this.invoice = invoice;
|
||||
}
|
||||
toString() {
|
||||
return JSON.stringify(
|
||||
@ -9389,7 +9411,7 @@ class Invoice {
|
||||
currency: this.currency,
|
||||
amount: this.amount,
|
||||
netId: this.netId,
|
||||
commitment: this.commitment,
|
||||
commitmentHex: this.commitmentHex,
|
||||
invoice: this.invoice
|
||||
},
|
||||
null,
|
||||
@ -10314,12 +10336,19 @@ async function multicall(Multicall2, calls) {
|
||||
}
|
||||
|
||||
const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
||||
async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
|
||||
const signer = Token.runner;
|
||||
const provider = signer.provider;
|
||||
async function getPermitSignature({
|
||||
Token,
|
||||
signer,
|
||||
spender,
|
||||
value,
|
||||
nonce,
|
||||
deadline
|
||||
}) {
|
||||
const sigSigner = signer || Token.runner;
|
||||
const provider = sigSigner.provider;
|
||||
const [name, lastNonce, { chainId }] = await Promise.all([
|
||||
Token.name(),
|
||||
Token.nonces(signer.address),
|
||||
Token.nonces(sigSigner.address),
|
||||
provider.getNetwork()
|
||||
]);
|
||||
const DOMAIN_SEPARATOR = {
|
||||
@ -10338,8 +10367,8 @@ async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
|
||||
]
|
||||
};
|
||||
return ethers.Signature.from(
|
||||
await signer.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
|
||||
owner: signer.address,
|
||||
await sigSigner.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
|
||||
owner: sigSigner.address,
|
||||
spender,
|
||||
value,
|
||||
nonce: nonce || lastNonce,
|
||||
@ -10347,9 +10376,36 @@ async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
|
||||
})
|
||||
);
|
||||
}
|
||||
async function getPermit2Signature(Token, { spender, value: amount, nonce, deadline }, witness) {
|
||||
const signer = Token.runner;
|
||||
const provider = signer.provider;
|
||||
async function getPermitCommitmentsSignature({
|
||||
PermitTornado: PermitTornado2,
|
||||
Token,
|
||||
signer,
|
||||
denomination,
|
||||
commitments,
|
||||
nonce
|
||||
}) {
|
||||
const value = BigInt(commitments.length) * denomination;
|
||||
const commitmentsHash = ethers.solidityPackedKeccak256(["bytes32[]"], [commitments]);
|
||||
return await getPermitSignature({
|
||||
Token,
|
||||
signer,
|
||||
spender: PermitTornado2.target,
|
||||
value,
|
||||
nonce,
|
||||
deadline: BigInt(commitmentsHash)
|
||||
});
|
||||
}
|
||||
async function getPermit2Signature({
|
||||
Token,
|
||||
signer,
|
||||
spender,
|
||||
value: amount,
|
||||
nonce,
|
||||
deadline,
|
||||
witness
|
||||
}) {
|
||||
const sigSigner = signer || Token.runner;
|
||||
const provider = sigSigner.provider;
|
||||
const domain = {
|
||||
name: "Permit2",
|
||||
chainId: (await provider.getNetwork()).chainId,
|
||||
@ -10394,7 +10450,7 @@ async function getPermit2Signature(Token, { spender, value: amount, nonce, deadl
|
||||
values.witness = witness.witness;
|
||||
}
|
||||
const hash = new ethers.TypedDataEncoder(types).hash(values);
|
||||
const signature = ethers.Signature.from(await signer.signTypedData(domain, types, values));
|
||||
const signature = ethers.Signature.from(await sigSigner.signTypedData(domain, types, values));
|
||||
return {
|
||||
domain,
|
||||
types,
|
||||
@ -10403,6 +10459,39 @@ async function getPermit2Signature(Token, { spender, value: amount, nonce, deadl
|
||||
signature
|
||||
};
|
||||
}
|
||||
async function getPermit2CommitmentsSignature({
|
||||
PermitTornado: PermitTornado2,
|
||||
Token,
|
||||
signer,
|
||||
denomination,
|
||||
commitments,
|
||||
nonce,
|
||||
deadline
|
||||
}) {
|
||||
const value = BigInt(commitments.length) * denomination;
|
||||
const commitmentsHash = ethers.solidityPackedKeccak256(["bytes32[]"], [commitments]);
|
||||
return await getPermit2Signature({
|
||||
Token,
|
||||
signer,
|
||||
spender: PermitTornado2.target,
|
||||
value,
|
||||
nonce,
|
||||
deadline,
|
||||
witness: {
|
||||
witnessTypeName: "PermitCommitments",
|
||||
witnessType: {
|
||||
PermitCommitments: [
|
||||
{ name: "instance", type: "address" },
|
||||
{ name: "commitmentsHash", type: "bytes32" }
|
||||
]
|
||||
},
|
||||
witness: {
|
||||
instance: PermitTornado2.target,
|
||||
commitmentsHash
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class TokenPriceOracle {
|
||||
oracle;
|
||||
@ -10930,7 +11019,9 @@ exports.getInstanceByAddress = getInstanceByAddress;
|
||||
exports.getMeta = getMeta;
|
||||
exports.getNetworkConfig = getNetworkConfig;
|
||||
exports.getNoteAccounts = getNoteAccounts;
|
||||
exports.getPermit2CommitmentsSignature = getPermit2CommitmentsSignature;
|
||||
exports.getPermit2Signature = getPermit2Signature;
|
||||
exports.getPermitCommitmentsSignature = getPermitCommitmentsSignature;
|
||||
exports.getPermitSignature = getPermitSignature;
|
||||
exports.getProvider = getProvider;
|
||||
exports.getProviderWithNetId = getProviderWithNetId;
|
||||
@ -10960,6 +11051,8 @@ exports.mimc = mimc;
|
||||
exports.multicall = multicall;
|
||||
exports.numberFormatter = numberFormatter;
|
||||
exports.packEncryptedMessage = packEncryptedMessage;
|
||||
exports.parseInvoice = parseInvoice;
|
||||
exports.parseNote = parseNote;
|
||||
exports.pedersen = pedersen;
|
||||
exports.permit2Address = permit2Address;
|
||||
exports.pickWeightedRandomRelayer = pickWeightedRandomRelayer;
|
||||
|
165
dist/index.mjs
vendored
165
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, Signature, MaxUint256, TypedDataEncoder, 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, solidityPackedKeccak256, TypedDataEncoder, ZeroAddress } from 'ethers';
|
||||
import crossFetch from 'cross-fetch';
|
||||
import { webcrypto } from 'crypto';
|
||||
import BN from 'bn.js';
|
||||
@ -9217,6 +9217,36 @@ async function buffPedersenHash(buffer) {
|
||||
return pedersen.toStringBuffer(hash);
|
||||
}
|
||||
|
||||
function parseNote(noteString) {
|
||||
const noteRegex = /tornado-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<noteHex>[0-9a-fA-F]{124})/g;
|
||||
const match = noteRegex.exec(noteString);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
const { currency, amount, netId, noteHex } = match.groups;
|
||||
return {
|
||||
currency: currency.toLowerCase(),
|
||||
amount,
|
||||
netId: Number(netId),
|
||||
noteHex: "0x" + noteHex,
|
||||
note: noteString
|
||||
};
|
||||
}
|
||||
function parseInvoice(invoiceString) {
|
||||
const invoiceRegex = /tornadoInvoice-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<commitmentHex>[0-9a-fA-F]{64})/g;
|
||||
const match = invoiceRegex.exec(invoiceString);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
const { currency, amount, netId, commitmentHex } = match.groups;
|
||||
return {
|
||||
currency: currency.toLowerCase(),
|
||||
amount,
|
||||
netId: Number(netId),
|
||||
commitmentHex: "0x" + commitmentHex,
|
||||
invoice: invoiceString
|
||||
};
|
||||
}
|
||||
async function createDeposit({ nullifier, secret }) {
|
||||
const preimage = new Uint8Array([...leInt2Buff(nullifier), ...leInt2Buff(secret)]);
|
||||
const noteHex = toFixedHex(bytesToBN(preimage), 62);
|
||||
@ -9311,31 +9341,27 @@ class Deposit {
|
||||
return newDeposit;
|
||||
}
|
||||
static async parseNote(noteString) {
|
||||
const noteRegex = /tornado-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<note>[0-9a-fA-F]{124})/g;
|
||||
const match = noteRegex.exec(noteString);
|
||||
if (!match) {
|
||||
const parsedNote = parseNote(noteString);
|
||||
if (!parsedNote) {
|
||||
throw new Error("The note has invalid format");
|
||||
}
|
||||
const matchGroup = match?.groups;
|
||||
const currency = matchGroup.currency.toLowerCase();
|
||||
const amount = matchGroup.amount;
|
||||
const netId = Number(matchGroup.netId);
|
||||
const bytes = bnToBytes("0x" + matchGroup.note);
|
||||
const { currency, amount, netId, note, noteHex: parsedNoteHex } = parsedNote;
|
||||
const bytes = bnToBytes(parsedNoteHex);
|
||||
const nullifier = BigInt(leBuff2Int(bytes.slice(0, 31)).toString());
|
||||
const secret = BigInt(leBuff2Int(bytes.slice(31, 62)).toString());
|
||||
const depositObject = await createDeposit({ nullifier, secret });
|
||||
const invoice = `tornadoInvoice-${currency}-${amount}-${netId}-${depositObject.commitmentHex}`;
|
||||
const { noteHex, commitmentHex, nullifierHex } = await createDeposit({ nullifier, secret });
|
||||
const invoice = `tornadoInvoice-${currency}-${amount}-${netId}-${commitmentHex}`;
|
||||
const newDeposit = new Deposit({
|
||||
currency,
|
||||
amount,
|
||||
netId,
|
||||
note: noteString,
|
||||
noteHex: depositObject.noteHex,
|
||||
note,
|
||||
noteHex,
|
||||
invoice,
|
||||
nullifier,
|
||||
secret,
|
||||
commitmentHex: depositObject.commitmentHex,
|
||||
nullifierHex: depositObject.nullifierHex
|
||||
commitmentHex,
|
||||
nullifierHex
|
||||
});
|
||||
return newDeposit;
|
||||
}
|
||||
@ -9344,23 +9370,19 @@ class Invoice {
|
||||
currency;
|
||||
amount;
|
||||
netId;
|
||||
commitment;
|
||||
commitmentHex;
|
||||
invoice;
|
||||
constructor(invoiceString) {
|
||||
const invoiceRegex = /tornadoInvoice-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<commitment>[0-9a-fA-F]{64})/g;
|
||||
const match = invoiceRegex.exec(invoiceString);
|
||||
if (!match) {
|
||||
throw new Error("The note has invalid format");
|
||||
const parsedInvoice = parseInvoice(invoiceString);
|
||||
if (!parsedInvoice) {
|
||||
throw new Error("The invoice has invalid format");
|
||||
}
|
||||
const matchGroup = match?.groups;
|
||||
const currency = matchGroup.currency.toLowerCase();
|
||||
const amount = matchGroup.amount;
|
||||
const netId = Number(matchGroup.netId);
|
||||
const { currency, amount, netId, invoice, commitmentHex } = parsedInvoice;
|
||||
this.currency = currency;
|
||||
this.amount = amount;
|
||||
this.netId = netId;
|
||||
this.commitment = "0x" + matchGroup.commitment;
|
||||
this.invoice = invoiceString;
|
||||
this.commitmentHex = commitmentHex;
|
||||
this.invoice = invoice;
|
||||
}
|
||||
toString() {
|
||||
return JSON.stringify(
|
||||
@ -9368,7 +9390,7 @@ class Invoice {
|
||||
currency: this.currency,
|
||||
amount: this.amount,
|
||||
netId: this.netId,
|
||||
commitment: this.commitment,
|
||||
commitmentHex: this.commitmentHex,
|
||||
invoice: this.invoice
|
||||
},
|
||||
null,
|
||||
@ -10293,12 +10315,19 @@ async function multicall(Multicall2, calls) {
|
||||
}
|
||||
|
||||
const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
||||
async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
|
||||
const signer = Token.runner;
|
||||
const provider = signer.provider;
|
||||
async function getPermitSignature({
|
||||
Token,
|
||||
signer,
|
||||
spender,
|
||||
value,
|
||||
nonce,
|
||||
deadline
|
||||
}) {
|
||||
const sigSigner = signer || Token.runner;
|
||||
const provider = sigSigner.provider;
|
||||
const [name, lastNonce, { chainId }] = await Promise.all([
|
||||
Token.name(),
|
||||
Token.nonces(signer.address),
|
||||
Token.nonces(sigSigner.address),
|
||||
provider.getNetwork()
|
||||
]);
|
||||
const DOMAIN_SEPARATOR = {
|
||||
@ -10317,8 +10346,8 @@ async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
|
||||
]
|
||||
};
|
||||
return Signature.from(
|
||||
await signer.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
|
||||
owner: signer.address,
|
||||
await sigSigner.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
|
||||
owner: sigSigner.address,
|
||||
spender,
|
||||
value,
|
||||
nonce: nonce || lastNonce,
|
||||
@ -10326,9 +10355,36 @@ async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
|
||||
})
|
||||
);
|
||||
}
|
||||
async function getPermit2Signature(Token, { spender, value: amount, nonce, deadline }, witness) {
|
||||
const signer = Token.runner;
|
||||
const provider = signer.provider;
|
||||
async function getPermitCommitmentsSignature({
|
||||
PermitTornado: PermitTornado2,
|
||||
Token,
|
||||
signer,
|
||||
denomination,
|
||||
commitments,
|
||||
nonce
|
||||
}) {
|
||||
const value = BigInt(commitments.length) * denomination;
|
||||
const commitmentsHash = solidityPackedKeccak256(["bytes32[]"], [commitments]);
|
||||
return await getPermitSignature({
|
||||
Token,
|
||||
signer,
|
||||
spender: PermitTornado2.target,
|
||||
value,
|
||||
nonce,
|
||||
deadline: BigInt(commitmentsHash)
|
||||
});
|
||||
}
|
||||
async function getPermit2Signature({
|
||||
Token,
|
||||
signer,
|
||||
spender,
|
||||
value: amount,
|
||||
nonce,
|
||||
deadline,
|
||||
witness
|
||||
}) {
|
||||
const sigSigner = signer || Token.runner;
|
||||
const provider = sigSigner.provider;
|
||||
const domain = {
|
||||
name: "Permit2",
|
||||
chainId: (await provider.getNetwork()).chainId,
|
||||
@ -10373,7 +10429,7 @@ async function getPermit2Signature(Token, { spender, value: amount, nonce, deadl
|
||||
values.witness = witness.witness;
|
||||
}
|
||||
const hash = new TypedDataEncoder(types).hash(values);
|
||||
const signature = Signature.from(await signer.signTypedData(domain, types, values));
|
||||
const signature = Signature.from(await sigSigner.signTypedData(domain, types, values));
|
||||
return {
|
||||
domain,
|
||||
types,
|
||||
@ -10382,6 +10438,39 @@ async function getPermit2Signature(Token, { spender, value: amount, nonce, deadl
|
||||
signature
|
||||
};
|
||||
}
|
||||
async function getPermit2CommitmentsSignature({
|
||||
PermitTornado: PermitTornado2,
|
||||
Token,
|
||||
signer,
|
||||
denomination,
|
||||
commitments,
|
||||
nonce,
|
||||
deadline
|
||||
}) {
|
||||
const value = BigInt(commitments.length) * denomination;
|
||||
const commitmentsHash = solidityPackedKeccak256(["bytes32[]"], [commitments]);
|
||||
return await getPermit2Signature({
|
||||
Token,
|
||||
signer,
|
||||
spender: PermitTornado2.target,
|
||||
value,
|
||||
nonce,
|
||||
deadline,
|
||||
witness: {
|
||||
witnessTypeName: "PermitCommitments",
|
||||
witnessType: {
|
||||
PermitCommitments: [
|
||||
{ name: "instance", type: "address" },
|
||||
{ name: "commitmentsHash", type: "bytes32" }
|
||||
]
|
||||
},
|
||||
witness: {
|
||||
instance: PermitTornado2.target,
|
||||
commitmentsHash
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class TokenPriceOracle {
|
||||
oracle;
|
||||
@ -10793,4 +10882,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, 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 };
|
||||
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, getPermit2CommitmentsSignature, getPermit2Signature, getPermitCommitmentsSignature, 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, parseInvoice, parseNote, pedersen, permit2Address, pickWeightedRandomRelayer, populateTransaction, proofSchemaType, proposalState, queryGraph, rBigInt, registeredEventsSchema, saveDBEvents, sleep, substring, toFixedHex, toFixedLength, unpackEncryptedMessage, unzipAsync, validateUrl, withdrawalsEventsSchema, zipAsync };
|
||||
|
52
dist/permit.d.ts
vendored
52
dist/permit.d.ts
vendored
@ -1,11 +1,17 @@
|
||||
import { ERC20Permit, ERC20Mock, TORN } from '@tornado/contracts';
|
||||
import { BaseContract, Signature, TypedDataField } from 'ethers';
|
||||
import { ERC20Permit, ERC20Mock, TORN, PermitTornado } from '@tornado/contracts';
|
||||
import { BaseContract, Signature, Signer, TypedDataField } from 'ethers';
|
||||
export interface PermitValue {
|
||||
spender: string;
|
||||
value: bigint;
|
||||
nonce?: bigint;
|
||||
deadline?: bigint;
|
||||
}
|
||||
export interface PermitCommitments {
|
||||
denomination: bigint;
|
||||
commitments: string[];
|
||||
nonce?: bigint;
|
||||
deadline?: bigint;
|
||||
}
|
||||
export declare const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
||||
/**
|
||||
* From @uniswap/permit2-sdk ported for ethers.js v6
|
||||
@ -17,8 +23,46 @@ export interface Witness {
|
||||
};
|
||||
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<{
|
||||
export declare function getPermitSignature({ Token, signer, spender, value, nonce, deadline, }: PermitValue & {
|
||||
Token: ERC20Permit | ERC20Mock | TORN;
|
||||
signer?: Signer;
|
||||
}): Promise<Signature>;
|
||||
export declare function getPermitCommitmentsSignature({ PermitTornado, Token, signer, denomination, commitments, nonce, }: PermitCommitments & {
|
||||
PermitTornado: PermitTornado;
|
||||
Token: ERC20Permit | ERC20Mock | TORN;
|
||||
signer?: Signer;
|
||||
}): Promise<Signature>;
|
||||
export declare function getPermit2Signature({ Token, signer, spender, value: amount, nonce, deadline, witness, }: PermitValue & {
|
||||
Token: BaseContract;
|
||||
signer?: Signer;
|
||||
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;
|
||||
}>;
|
||||
export declare function getPermit2CommitmentsSignature({ PermitTornado, Token, signer, denomination, commitments, nonce, deadline, }: PermitCommitments & {
|
||||
PermitTornado: PermitTornado;
|
||||
Token: BaseContract;
|
||||
signer?: Signer;
|
||||
}): Promise<{
|
||||
domain: {
|
||||
name: string;
|
||||
chainId: bigint;
|
||||
|
294
dist/tornado.umd.js
vendored
294
dist/tornado.umd.js
vendored
@ -4613,9 +4613,6 @@ function normalizeValue(type, value) {
|
||||
return value.map((item) => normalizeValue(innerType, item));
|
||||
}
|
||||
if (type === 'address') {
|
||||
if (typeof value === 'number') {
|
||||
return (0, utils_1.padStart)((0, utils_2.numberToBytes)(value), 20);
|
||||
}
|
||||
if ((0, utils_2.isStrictHexString)(value)) {
|
||||
return (0, utils_1.padStart)((0, utils_2.hexToBytes)(value).subarray(0, 20), 20);
|
||||
}
|
||||
@ -58720,14 +58717,46 @@ class BatchEventsService {
|
||||
"use strict";
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ Hr: () => (/* binding */ createDeposit),
|
||||
/* harmony export */ Ps: () => (/* binding */ parseInvoice),
|
||||
/* harmony export */ dA: () => (/* binding */ Deposit),
|
||||
/* harmony export */ qO: () => (/* binding */ Invoice)
|
||||
/* harmony export */ qO: () => (/* binding */ Invoice),
|
||||
/* harmony export */ wd: () => (/* binding */ parseNote)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(67418);
|
||||
/* harmony import */ var _pedersen__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(85111);
|
||||
|
||||
|
||||
|
||||
function parseNote(noteString) {
|
||||
const noteRegex = /tornado-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<noteHex>[0-9a-fA-F]{124})/g;
|
||||
const match = noteRegex.exec(noteString);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
const { currency, amount, netId, noteHex } = match.groups;
|
||||
return {
|
||||
currency: currency.toLowerCase(),
|
||||
amount,
|
||||
netId: Number(netId),
|
||||
noteHex: "0x" + noteHex,
|
||||
note: noteString
|
||||
};
|
||||
}
|
||||
function parseInvoice(invoiceString) {
|
||||
const invoiceRegex = /tornadoInvoice-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<commitmentHex>[0-9a-fA-F]{64})/g;
|
||||
const match = invoiceRegex.exec(invoiceString);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
const { currency, amount, netId, commitmentHex } = match.groups;
|
||||
return {
|
||||
currency: currency.toLowerCase(),
|
||||
amount,
|
||||
netId: Number(netId),
|
||||
commitmentHex: "0x" + commitmentHex,
|
||||
invoice: invoiceString
|
||||
};
|
||||
}
|
||||
async function createDeposit({ nullifier, secret }) {
|
||||
const preimage = new Uint8Array([...(0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .leInt2Buff */ .EI)(nullifier), ...(0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .leInt2Buff */ .EI)(secret)]);
|
||||
const noteHex = (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .toFixedHex */ .$W)((0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .bytesToBN */ .Ju)(preimage), 62);
|
||||
@ -58822,31 +58851,27 @@ class Deposit {
|
||||
return newDeposit;
|
||||
}
|
||||
static async parseNote(noteString) {
|
||||
const noteRegex = /tornado-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<note>[0-9a-fA-F]{124})/g;
|
||||
const match = noteRegex.exec(noteString);
|
||||
if (!match) {
|
||||
const parsedNote = parseNote(noteString);
|
||||
if (!parsedNote) {
|
||||
throw new Error("The note has invalid format");
|
||||
}
|
||||
const matchGroup = match?.groups;
|
||||
const currency = matchGroup.currency.toLowerCase();
|
||||
const amount = matchGroup.amount;
|
||||
const netId = Number(matchGroup.netId);
|
||||
const bytes = (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .bnToBytes */ .jm)("0x" + matchGroup.note);
|
||||
const { currency, amount, netId, note, noteHex: parsedNoteHex } = parsedNote;
|
||||
const bytes = (0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .bnToBytes */ .jm)(parsedNoteHex);
|
||||
const nullifier = BigInt((0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .leBuff2Int */ .ae)(bytes.slice(0, 31)).toString());
|
||||
const secret = BigInt((0,_utils__WEBPACK_IMPORTED_MODULE_0__/* .leBuff2Int */ .ae)(bytes.slice(31, 62)).toString());
|
||||
const depositObject = await createDeposit({ nullifier, secret });
|
||||
const invoice = `tornadoInvoice-${currency}-${amount}-${netId}-${depositObject.commitmentHex}`;
|
||||
const { noteHex, commitmentHex, nullifierHex } = await createDeposit({ nullifier, secret });
|
||||
const invoice = `tornadoInvoice-${currency}-${amount}-${netId}-${commitmentHex}`;
|
||||
const newDeposit = new Deposit({
|
||||
currency,
|
||||
amount,
|
||||
netId,
|
||||
note: noteString,
|
||||
noteHex: depositObject.noteHex,
|
||||
note,
|
||||
noteHex,
|
||||
invoice,
|
||||
nullifier,
|
||||
secret,
|
||||
commitmentHex: depositObject.commitmentHex,
|
||||
nullifierHex: depositObject.nullifierHex
|
||||
commitmentHex,
|
||||
nullifierHex
|
||||
});
|
||||
return newDeposit;
|
||||
}
|
||||
@ -58855,23 +58880,19 @@ class Invoice {
|
||||
currency;
|
||||
amount;
|
||||
netId;
|
||||
commitment;
|
||||
commitmentHex;
|
||||
invoice;
|
||||
constructor(invoiceString) {
|
||||
const invoiceRegex = /tornadoInvoice-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<commitment>[0-9a-fA-F]{64})/g;
|
||||
const match = invoiceRegex.exec(invoiceString);
|
||||
if (!match) {
|
||||
throw new Error("The note has invalid format");
|
||||
const parsedInvoice = parseInvoice(invoiceString);
|
||||
if (!parsedInvoice) {
|
||||
throw new Error("The invoice has invalid format");
|
||||
}
|
||||
const matchGroup = match?.groups;
|
||||
const currency = matchGroup.currency.toLowerCase();
|
||||
const amount = matchGroup.amount;
|
||||
const netId = Number(matchGroup.netId);
|
||||
const { currency, amount, netId, invoice, commitmentHex } = parsedInvoice;
|
||||
this.currency = currency;
|
||||
this.amount = amount;
|
||||
this.netId = netId;
|
||||
this.commitment = "0x" + matchGroup.commitment;
|
||||
this.invoice = invoiceString;
|
||||
this.commitmentHex = commitmentHex;
|
||||
this.invoice = invoice;
|
||||
}
|
||||
toString() {
|
||||
return JSON.stringify(
|
||||
@ -58879,7 +58900,7 @@ class Invoice {
|
||||
currency: this.currency,
|
||||
amount: this.amount,
|
||||
netId: this.netId,
|
||||
commitment: this.commitment,
|
||||
commitmentHex: this.commitmentHex,
|
||||
invoice: this.invoice
|
||||
},
|
||||
null,
|
||||
@ -63133,14 +63154,16 @@ async function buffPedersenHash(buffer) {
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 84947:
|
||||
/***/ 1180:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
// EXPORTS
|
||||
__webpack_require__.d(__webpack_exports__, {
|
||||
Sl: () => (/* binding */ getPermit2CommitmentsSignature),
|
||||
KM: () => (/* binding */ getPermit2Signature),
|
||||
sx: () => (/* binding */ getPermitCommitmentsSignature),
|
||||
id: () => (/* binding */ getPermitSignature),
|
||||
CS: () => (/* binding */ permit2Address)
|
||||
});
|
||||
@ -63179,6 +63202,122 @@ const MinInt256 = BigInt("0x8000000000000000000000000000000000000000000000000000
|
||||
*/
|
||||
const MaxInt256 = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
//# sourceMappingURL=numbers.js.map
|
||||
// EXTERNAL MODULE: ./node_modules/ethers/lib.esm/address/address.js
|
||||
var address = __webpack_require__(30031);
|
||||
// EXTERNAL MODULE: ./node_modules/ethers/lib.esm/crypto/keccak.js + 1 modules
|
||||
var keccak = __webpack_require__(15539);
|
||||
// EXTERNAL MODULE: ./node_modules/ethers/lib.esm/utils/data.js
|
||||
var data = __webpack_require__(36212);
|
||||
// EXTERNAL MODULE: ./node_modules/ethers/lib.esm/utils/utf8.js
|
||||
var utf8 = __webpack_require__(87303);
|
||||
// EXTERNAL MODULE: ./node_modules/ethers/lib.esm/utils/errors.js
|
||||
var errors = __webpack_require__(57339);
|
||||
// EXTERNAL MODULE: ./node_modules/ethers/lib.esm/utils/maths.js
|
||||
var maths = __webpack_require__(27033);
|
||||
;// ./node_modules/ethers/lib.esm/hash/solidity.js
|
||||
|
||||
|
||||
|
||||
const regexBytes = new RegExp("^bytes([0-9]+)$");
|
||||
const regexNumber = new RegExp("^(u?int)([0-9]*)$");
|
||||
const regexArray = new RegExp("^(.*)\\[([0-9]*)\\]$");
|
||||
function _pack(type, value, isArray) {
|
||||
switch (type) {
|
||||
case "address":
|
||||
if (isArray) {
|
||||
return (0,data/* getBytes */.q5)((0,data/* zeroPadValue */.nx)(value, 32));
|
||||
}
|
||||
return (0,data/* getBytes */.q5)((0,address/* getAddress */.b)(value));
|
||||
case "string":
|
||||
return (0,utf8/* toUtf8Bytes */.YW)(value);
|
||||
case "bytes":
|
||||
return (0,data/* getBytes */.q5)(value);
|
||||
case "bool":
|
||||
value = (!!value ? "0x01" : "0x00");
|
||||
if (isArray) {
|
||||
return (0,data/* getBytes */.q5)((0,data/* zeroPadValue */.nx)(value, 32));
|
||||
}
|
||||
return (0,data/* getBytes */.q5)(value);
|
||||
}
|
||||
let match = type.match(regexNumber);
|
||||
if (match) {
|
||||
let signed = (match[1] === "int");
|
||||
let size = parseInt(match[2] || "256");
|
||||
(0,errors/* assertArgument */.MR)((!match[2] || match[2] === String(size)) && (size % 8 === 0) && size !== 0 && size <= 256, "invalid number type", "type", type);
|
||||
if (isArray) {
|
||||
size = 256;
|
||||
}
|
||||
if (signed) {
|
||||
value = (0,maths/* toTwos */.JJ)(value, size);
|
||||
}
|
||||
return (0,data/* getBytes */.q5)((0,data/* zeroPadValue */.nx)((0,maths/* toBeArray */.c4)(value), size / 8));
|
||||
}
|
||||
match = type.match(regexBytes);
|
||||
if (match) {
|
||||
const size = parseInt(match[1]);
|
||||
(0,errors/* assertArgument */.MR)(String(size) === match[1] && size !== 0 && size <= 32, "invalid bytes type", "type", type);
|
||||
(0,errors/* assertArgument */.MR)((0,data/* dataLength */.pO)(value) === size, `invalid value for ${type}`, "value", value);
|
||||
if (isArray) {
|
||||
return (0,data/* getBytes */.q5)((0,data/* zeroPadBytes */.X_)(value, 32));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
match = type.match(regexArray);
|
||||
if (match && Array.isArray(value)) {
|
||||
const baseType = match[1];
|
||||
const count = parseInt(match[2] || String(value.length));
|
||||
(0,errors/* assertArgument */.MR)(count === value.length, `invalid array length for ${type}`, "value", value);
|
||||
const result = [];
|
||||
value.forEach(function (value) {
|
||||
result.push(_pack(baseType, value, true));
|
||||
});
|
||||
return (0,data/* getBytes */.q5)((0,data/* concat */.xW)(result));
|
||||
}
|
||||
(0,errors/* assertArgument */.MR)(false, "invalid type", "type", type);
|
||||
}
|
||||
// @TODO: Array Enum
|
||||
/**
|
||||
* Computes the [[link-solc-packed]] representation of %%values%%
|
||||
* respectively to their %%types%%.
|
||||
*
|
||||
* @example:
|
||||
* addr = "0x8ba1f109551bd432803012645ac136ddd64dba72"
|
||||
* solidityPacked([ "address", "uint" ], [ addr, 45 ]);
|
||||
* //_result:
|
||||
*/
|
||||
function solidityPacked(types, values) {
|
||||
(0,errors/* assertArgument */.MR)(types.length === values.length, "wrong number of values; expected ${ types.length }", "values", values);
|
||||
const tight = [];
|
||||
types.forEach(function (type, index) {
|
||||
tight.push(_pack(type, values[index]));
|
||||
});
|
||||
return (0,data/* hexlify */.c$)((0,data/* concat */.xW)(tight));
|
||||
}
|
||||
/**
|
||||
* Computes the [[link-solc-packed]] [[keccak256]] hash of %%values%%
|
||||
* respectively to their %%types%%.
|
||||
*
|
||||
* @example:
|
||||
* addr = "0x8ba1f109551bd432803012645ac136ddd64dba72"
|
||||
* solidityPackedKeccak256([ "address", "uint" ], [ addr, 45 ]);
|
||||
* //_result:
|
||||
*/
|
||||
function solidityPackedKeccak256(types, values) {
|
||||
return (0,keccak/* keccak256 */.S)(solidityPacked(types, values));
|
||||
}
|
||||
/**
|
||||
* Computes the [[link-solc-packed]] [[sha256]] hash of %%values%%
|
||||
* respectively to their %%types%%.
|
||||
*
|
||||
* @example:
|
||||
* addr = "0x8ba1f109551bd432803012645ac136ddd64dba72"
|
||||
* solidityPackedSha256([ "address", "uint" ], [ addr, 45 ]);
|
||||
* //_result:
|
||||
*/
|
||||
function solidityPackedSha256(types, values) {
|
||||
return _sha256(solidityPacked(types, values));
|
||||
}
|
||||
//# sourceMappingURL=solidity.js.map
|
||||
// EXTERNAL MODULE: ./node_modules/ethers/lib.esm/hash/typed-data.js
|
||||
var typed_data = __webpack_require__(82314);
|
||||
// EXTERNAL MODULE: ./src/utils.ts
|
||||
@ -63188,12 +63327,19 @@ var utils = __webpack_require__(67418);
|
||||
|
||||
|
||||
const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
||||
async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
|
||||
const signer = Token.runner;
|
||||
const provider = signer.provider;
|
||||
async function getPermitSignature({
|
||||
Token,
|
||||
signer,
|
||||
spender,
|
||||
value,
|
||||
nonce,
|
||||
deadline
|
||||
}) {
|
||||
const sigSigner = signer || Token.runner;
|
||||
const provider = sigSigner.provider;
|
||||
const [name, lastNonce, { chainId }] = await Promise.all([
|
||||
Token.name(),
|
||||
Token.nonces(signer.address),
|
||||
Token.nonces(sigSigner.address),
|
||||
provider.getNetwork()
|
||||
]);
|
||||
const DOMAIN_SEPARATOR = {
|
||||
@ -63212,8 +63358,8 @@ async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
|
||||
]
|
||||
};
|
||||
return crypto_signature/* Signature */.t.from(
|
||||
await signer.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
|
||||
owner: signer.address,
|
||||
await sigSigner.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
|
||||
owner: sigSigner.address,
|
||||
spender,
|
||||
value,
|
||||
nonce: nonce || lastNonce,
|
||||
@ -63221,9 +63367,36 @@ async function getPermitSignature(Token, { spender, value, nonce, deadline }) {
|
||||
})
|
||||
);
|
||||
}
|
||||
async function getPermit2Signature(Token, { spender, value: amount, nonce, deadline }, witness) {
|
||||
const signer = Token.runner;
|
||||
const provider = signer.provider;
|
||||
async function getPermitCommitmentsSignature({
|
||||
PermitTornado: PermitTornado2,
|
||||
Token,
|
||||
signer,
|
||||
denomination,
|
||||
commitments,
|
||||
nonce
|
||||
}) {
|
||||
const value = BigInt(commitments.length) * denomination;
|
||||
const commitmentsHash = solidityPackedKeccak256(["bytes32[]"], [commitments]);
|
||||
return await getPermitSignature({
|
||||
Token,
|
||||
signer,
|
||||
spender: PermitTornado2.target,
|
||||
value,
|
||||
nonce,
|
||||
deadline: BigInt(commitmentsHash)
|
||||
});
|
||||
}
|
||||
async function getPermit2Signature({
|
||||
Token,
|
||||
signer,
|
||||
spender,
|
||||
value: amount,
|
||||
nonce,
|
||||
deadline,
|
||||
witness
|
||||
}) {
|
||||
const sigSigner = signer || Token.runner;
|
||||
const provider = sigSigner.provider;
|
||||
const domain = {
|
||||
name: "Permit2",
|
||||
chainId: (await provider.getNetwork()).chainId,
|
||||
@ -63268,7 +63441,7 @@ async function getPermit2Signature(Token, { spender, value: amount, nonce, deadl
|
||||
values.witness = witness.witness;
|
||||
}
|
||||
const hash = new typed_data/* TypedDataEncoder */.z(types).hash(values);
|
||||
const signature = crypto_signature/* Signature */.t.from(await signer.signTypedData(domain, types, values));
|
||||
const signature = crypto_signature/* Signature */.t.from(await sigSigner.signTypedData(domain, types, values));
|
||||
return {
|
||||
domain,
|
||||
types,
|
||||
@ -63277,6 +63450,39 @@ async function getPermit2Signature(Token, { spender, value: amount, nonce, deadl
|
||||
signature
|
||||
};
|
||||
}
|
||||
async function getPermit2CommitmentsSignature({
|
||||
PermitTornado: PermitTornado2,
|
||||
Token,
|
||||
signer,
|
||||
denomination,
|
||||
commitments,
|
||||
nonce,
|
||||
deadline
|
||||
}) {
|
||||
const value = BigInt(commitments.length) * denomination;
|
||||
const commitmentsHash = solidityPackedKeccak256(["bytes32[]"], [commitments]);
|
||||
return await getPermit2Signature({
|
||||
Token,
|
||||
signer,
|
||||
spender: PermitTornado2.target,
|
||||
value,
|
||||
nonce,
|
||||
deadline,
|
||||
witness: {
|
||||
witnessTypeName: "PermitCommitments",
|
||||
witnessType: {
|
||||
PermitCommitments: [
|
||||
{ name: "instance", type: "address" },
|
||||
{ name: "commitmentsHash", type: "bytes32" }
|
||||
]
|
||||
},
|
||||
witness: {
|
||||
instance: PermitTornado2.target,
|
||||
commitmentsHash
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
@ -180569,7 +180775,9 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ getMeta: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getMeta),
|
||||
/* harmony export */ getNetworkConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_14__.RY),
|
||||
/* harmony export */ getNoteAccounts: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getNoteAccounts),
|
||||
/* harmony export */ getPermit2CommitmentsSignature: () => (/* reexport safe */ _permit__WEBPACK_IMPORTED_MODULE_16__.Sl),
|
||||
/* harmony export */ getPermit2Signature: () => (/* reexport safe */ _permit__WEBPACK_IMPORTED_MODULE_16__.KM),
|
||||
/* harmony export */ getPermitCommitmentsSignature: () => (/* reexport safe */ _permit__WEBPACK_IMPORTED_MODULE_16__.sx),
|
||||
/* harmony export */ getPermitSignature: () => (/* reexport safe */ _permit__WEBPACK_IMPORTED_MODULE_16__.id),
|
||||
/* harmony export */ getProvider: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_18__.sO),
|
||||
/* harmony export */ getProviderWithNetId: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_18__.MF),
|
||||
@ -180596,6 +180804,8 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ multicall: () => (/* reexport safe */ _multicall__WEBPACK_IMPORTED_MODULE_13__.C),
|
||||
/* harmony export */ numberFormatter: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_22__.Eg),
|
||||
/* harmony export */ packEncryptedMessage: () => (/* reexport safe */ _encryptedNotes__WEBPACK_IMPORTED_MODULE_6__.Fr),
|
||||
/* harmony export */ parseInvoice: () => (/* reexport safe */ _deposits__WEBPACK_IMPORTED_MODULE_5__.Ps),
|
||||
/* harmony export */ parseNote: () => (/* reexport safe */ _deposits__WEBPACK_IMPORTED_MODULE_5__.wd),
|
||||
/* harmony export */ pedersen: () => (/* reexport safe */ _pedersen__WEBPACK_IMPORTED_MODULE_15__.NO),
|
||||
/* harmony export */ permit2Address: () => (/* reexport safe */ _permit__WEBPACK_IMPORTED_MODULE_16__.CS),
|
||||
/* harmony export */ pickWeightedRandomRelayer: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_19__.sN),
|
||||
@ -180633,7 +180843,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _multicall__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(48486);
|
||||
/* harmony import */ var _networkConfig__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(59499);
|
||||
/* harmony import */ var _pedersen__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(85111);
|
||||
/* harmony import */ var _permit__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(84947);
|
||||
/* harmony import */ var _permit__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(1180);
|
||||
/* harmony import */ var _prices__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(34525);
|
||||
/* harmony import */ var _providers__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(5330);
|
||||
/* harmony import */ var _relayerClient__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(57194);
|
||||
|
4
dist/tornado.umd.min.js
vendored
4
dist/tornado.umd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -31,7 +31,7 @@
|
||||
"yarn.lock"
|
||||
],
|
||||
"dependencies": {
|
||||
"@metamask/eth-sig-util": "^7.0.3",
|
||||
"@metamask/eth-sig-util": "^8.0.0",
|
||||
"@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",
|
||||
@ -52,10 +52,10 @@
|
||||
"@typechain/ethers-v6": "^0.5.1",
|
||||
"@types/bn.js": "^5.1.6",
|
||||
"@types/circomlibjs": "^0.1.6",
|
||||
"@types/node": "^22.7.5",
|
||||
"@types/node": "^22.7.9",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"@typescript-eslint/eslint-plugin": "^8.9.0",
|
||||
"@typescript-eslint/parser": "^8.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
||||
"@typescript-eslint/parser": "^8.11.0",
|
||||
"esbuild-loader": "^4.2.2",
|
||||
"eslint": "8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
|
@ -29,6 +29,49 @@ export interface createNoteParams extends DepositType {
|
||||
|
||||
export interface parsedNoteExec extends DepositType {
|
||||
note: string;
|
||||
noteHex: string;
|
||||
}
|
||||
|
||||
export interface parsedInvoiceExec extends DepositType {
|
||||
invoice: string;
|
||||
commitmentHex: string;
|
||||
}
|
||||
|
||||
export function parseNote(noteString: string): parsedNoteExec | undefined {
|
||||
const noteRegex = /tornado-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<noteHex>[0-9a-fA-F]{124})/g;
|
||||
const match = noteRegex.exec(noteString);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { currency, amount, netId, noteHex } = match.groups as unknown as parsedNoteExec;
|
||||
|
||||
return {
|
||||
currency: currency.toLowerCase(),
|
||||
amount,
|
||||
netId: Number(netId),
|
||||
noteHex: '0x' + noteHex,
|
||||
note: noteString,
|
||||
};
|
||||
}
|
||||
|
||||
export function parseInvoice(invoiceString: string): parsedInvoiceExec | undefined {
|
||||
const invoiceRegex =
|
||||
/tornadoInvoice-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<commitmentHex>[0-9a-fA-F]{64})/g;
|
||||
const match = invoiceRegex.exec(invoiceString);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { currency, amount, netId, commitmentHex } = match.groups as unknown as parsedInvoiceExec;
|
||||
|
||||
return {
|
||||
currency: currency.toLowerCase(),
|
||||
amount,
|
||||
netId: Number(netId),
|
||||
commitmentHex: '0x' + commitmentHex,
|
||||
invoice: invoiceString,
|
||||
};
|
||||
}
|
||||
|
||||
export async function createDeposit({ nullifier, secret }: createDepositParams): Promise<createDepositObject> {
|
||||
@ -153,72 +196,61 @@ export class Deposit {
|
||||
}
|
||||
|
||||
static async parseNote(noteString: string): Promise<Deposit> {
|
||||
const noteRegex = /tornado-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<note>[0-9a-fA-F]{124})/g;
|
||||
const match = noteRegex.exec(noteString);
|
||||
if (!match) {
|
||||
const parsedNote = parseNote(noteString);
|
||||
|
||||
if (!parsedNote) {
|
||||
throw new Error('The note has invalid format');
|
||||
}
|
||||
const matchGroup = match?.groups as unknown as parsedNoteExec;
|
||||
|
||||
const currency = matchGroup.currency.toLowerCase();
|
||||
const amount = matchGroup.amount;
|
||||
const netId = Number(matchGroup.netId);
|
||||
const { currency, amount, netId, note, noteHex: parsedNoteHex } = parsedNote;
|
||||
|
||||
const bytes = bnToBytes('0x' + matchGroup.note);
|
||||
const bytes = bnToBytes(parsedNoteHex);
|
||||
const nullifier = BigInt(leBuff2Int(bytes.slice(0, 31)).toString());
|
||||
const secret = BigInt(leBuff2Int(bytes.slice(31, 62)).toString());
|
||||
|
||||
const depositObject = await createDeposit({ nullifier, secret });
|
||||
const { noteHex, commitmentHex, nullifierHex } = await createDeposit({ nullifier, secret });
|
||||
|
||||
const invoice = `tornadoInvoice-${currency}-${amount}-${netId}-${depositObject.commitmentHex}`;
|
||||
const invoice = `tornadoInvoice-${currency}-${amount}-${netId}-${commitmentHex}`;
|
||||
|
||||
const newDeposit = new Deposit({
|
||||
currency,
|
||||
amount,
|
||||
netId,
|
||||
note: noteString,
|
||||
noteHex: depositObject.noteHex,
|
||||
note,
|
||||
noteHex,
|
||||
invoice,
|
||||
nullifier,
|
||||
secret,
|
||||
commitmentHex: depositObject.commitmentHex,
|
||||
nullifierHex: depositObject.nullifierHex,
|
||||
commitmentHex,
|
||||
nullifierHex,
|
||||
});
|
||||
|
||||
return newDeposit;
|
||||
}
|
||||
}
|
||||
|
||||
export interface parsedInvoiceExec extends DepositType {
|
||||
commitment: string;
|
||||
}
|
||||
|
||||
export class Invoice {
|
||||
currency: string;
|
||||
amount: string;
|
||||
netId: NetIdType;
|
||||
commitment: string;
|
||||
commitmentHex: string;
|
||||
invoice: string;
|
||||
|
||||
constructor(invoiceString: string) {
|
||||
const invoiceRegex =
|
||||
/tornadoInvoice-(?<currency>\w+)-(?<amount>[\d.]+)-(?<netId>\d+)-0x(?<commitment>[0-9a-fA-F]{64})/g;
|
||||
const match = invoiceRegex.exec(invoiceString);
|
||||
if (!match) {
|
||||
throw new Error('The note has invalid format');
|
||||
}
|
||||
const matchGroup = match?.groups as unknown as parsedInvoiceExec;
|
||||
const parsedInvoice = parseInvoice(invoiceString);
|
||||
|
||||
const currency = matchGroup.currency.toLowerCase();
|
||||
const amount = matchGroup.amount;
|
||||
const netId = Number(matchGroup.netId);
|
||||
if (!parsedInvoice) {
|
||||
throw new Error('The invoice has invalid format');
|
||||
}
|
||||
|
||||
const { currency, amount, netId, invoice, commitmentHex } = parsedInvoice;
|
||||
|
||||
this.currency = currency;
|
||||
this.amount = amount;
|
||||
this.netId = netId;
|
||||
|
||||
this.commitment = '0x' + matchGroup.commitment;
|
||||
this.invoice = invoiceString;
|
||||
this.commitmentHex = commitmentHex;
|
||||
this.invoice = invoice;
|
||||
}
|
||||
|
||||
toString() {
|
||||
@ -227,7 +259,7 @@ export class Invoice {
|
||||
currency: this.currency,
|
||||
amount: this.amount,
|
||||
netId: this.netId,
|
||||
commitment: this.commitment,
|
||||
commitmentHex: this.commitmentHex,
|
||||
invoice: this.invoice,
|
||||
},
|
||||
null,
|
||||
|
133
src/permit.ts
133
src/permit.ts
@ -1,5 +1,14 @@
|
||||
import { ERC20Permit, ERC20Mock, TORN } from '@tornado/contracts';
|
||||
import { BaseContract, MaxUint256, Provider, Signature, Signer, TypedDataEncoder, TypedDataField } from 'ethers';
|
||||
import { ERC20Permit, ERC20Mock, TORN, PermitTornado } from '@tornado/contracts';
|
||||
import {
|
||||
BaseContract,
|
||||
MaxUint256,
|
||||
Provider,
|
||||
Signature,
|
||||
Signer,
|
||||
solidityPackedKeccak256,
|
||||
TypedDataEncoder,
|
||||
TypedDataField,
|
||||
} from 'ethers';
|
||||
import { rBigInt } from './utils';
|
||||
|
||||
export interface PermitValue {
|
||||
@ -9,6 +18,13 @@ export interface PermitValue {
|
||||
deadline?: bigint;
|
||||
}
|
||||
|
||||
export interface PermitCommitments {
|
||||
denomination: bigint;
|
||||
commitments: string[];
|
||||
nonce?: bigint;
|
||||
deadline?: bigint;
|
||||
}
|
||||
|
||||
export const permit2Address = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
|
||||
|
||||
/**
|
||||
@ -23,16 +39,23 @@ export interface Witness {
|
||||
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;
|
||||
export async function getPermitSignature({
|
||||
Token,
|
||||
signer,
|
||||
spender,
|
||||
value,
|
||||
nonce,
|
||||
deadline,
|
||||
}: PermitValue & {
|
||||
Token: ERC20Permit | ERC20Mock | TORN;
|
||||
signer?: Signer;
|
||||
}) {
|
||||
const sigSigner = (signer || Token.runner) as Signer & { address: string };
|
||||
const provider = sigSigner.provider as Provider;
|
||||
|
||||
const [name, lastNonce, { chainId }] = await Promise.all([
|
||||
Token.name(),
|
||||
Token.nonces(signer.address),
|
||||
Token.nonces(sigSigner.address),
|
||||
provider.getNetwork(),
|
||||
]);
|
||||
|
||||
@ -54,8 +77,8 @@ export async function getPermitSignature(
|
||||
};
|
||||
|
||||
return Signature.from(
|
||||
await signer.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
|
||||
owner: signer.address,
|
||||
await sigSigner.signTypedData(DOMAIN_SEPARATOR, PERMIT_TYPE, {
|
||||
owner: sigSigner.address,
|
||||
spender,
|
||||
value,
|
||||
nonce: nonce || lastNonce,
|
||||
@ -64,13 +87,46 @@ export async function getPermitSignature(
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
export async function getPermitCommitmentsSignature({
|
||||
PermitTornado,
|
||||
Token,
|
||||
signer,
|
||||
denomination,
|
||||
commitments,
|
||||
nonce,
|
||||
}: PermitCommitments & {
|
||||
PermitTornado: PermitTornado;
|
||||
Token: ERC20Permit | ERC20Mock | TORN;
|
||||
signer?: Signer;
|
||||
}) {
|
||||
const value = BigInt(commitments.length) * denomination;
|
||||
const commitmentsHash = solidityPackedKeccak256(['bytes32[]'], [commitments]);
|
||||
|
||||
return await getPermitSignature({
|
||||
Token,
|
||||
signer,
|
||||
spender: PermitTornado.target as string,
|
||||
value,
|
||||
nonce,
|
||||
deadline: BigInt(commitmentsHash),
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPermit2Signature({
|
||||
Token,
|
||||
signer,
|
||||
spender,
|
||||
value: amount,
|
||||
nonce,
|
||||
deadline,
|
||||
witness,
|
||||
}: PermitValue & {
|
||||
Token: BaseContract;
|
||||
signer?: Signer;
|
||||
witness?: Witness;
|
||||
}) {
|
||||
const sigSigner = (signer || Token.runner) as Signer & { address: string };
|
||||
const provider = sigSigner.provider as Provider;
|
||||
|
||||
const domain = {
|
||||
name: 'Permit2',
|
||||
@ -135,7 +191,7 @@ export async function getPermit2Signature(
|
||||
|
||||
const hash = new TypedDataEncoder(types).hash(values);
|
||||
|
||||
const signature = Signature.from(await signer.signTypedData(domain, types, values));
|
||||
const signature = Signature.from(await sigSigner.signTypedData(domain, types, values));
|
||||
|
||||
return {
|
||||
domain,
|
||||
@ -145,3 +201,42 @@ export async function getPermit2Signature(
|
||||
signature,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getPermit2CommitmentsSignature({
|
||||
PermitTornado,
|
||||
Token,
|
||||
signer,
|
||||
denomination,
|
||||
commitments,
|
||||
nonce,
|
||||
deadline,
|
||||
}: PermitCommitments & {
|
||||
PermitTornado: PermitTornado;
|
||||
Token: BaseContract;
|
||||
signer?: Signer;
|
||||
}) {
|
||||
const value = BigInt(commitments.length) * denomination;
|
||||
const commitmentsHash = solidityPackedKeccak256(['bytes32[]'], [commitments]);
|
||||
|
||||
return await getPermit2Signature({
|
||||
Token,
|
||||
signer,
|
||||
spender: PermitTornado.target as string,
|
||||
value,
|
||||
nonce,
|
||||
deadline,
|
||||
witness: {
|
||||
witnessTypeName: 'PermitCommitments',
|
||||
witnessType: {
|
||||
PermitCommitments: [
|
||||
{ name: 'instance', type: 'address' },
|
||||
{ name: 'commitmentsHash', type: 'bytes32' },
|
||||
],
|
||||
},
|
||||
witness: {
|
||||
instance: PermitTornado.target,
|
||||
commitmentsHash,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
117
yarn.lock
117
yarn.lock
@ -623,10 +623,10 @@
|
||||
"@metamask/superstruct" "^3.1.0"
|
||||
"@metamask/utils" "^9.0.0"
|
||||
|
||||
"@metamask/eth-sig-util@^7.0.3":
|
||||
version "7.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@metamask/eth-sig-util/-/eth-sig-util-7.0.3.tgz#be9e444fe0b8474c04e2ff42fd983173767f6ac0"
|
||||
integrity sha512-PAtGnOkYvh90k2lEZldq/FK7GTLF6WxE+2bV85PoA3pqlJnmJCAY62tuvxHSwnVngSKlc4mcNvjnUg2eYO6JGg==
|
||||
"@metamask/eth-sig-util@^8.0.0":
|
||||
version "8.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@metamask/eth-sig-util/-/eth-sig-util-8.0.0.tgz#6310d93cd1101cab3cc6bc2a1ff526290ed2695b"
|
||||
integrity sha512-IwE6aoxUL39IhmsAgE4nk+OZbNo+ThFZRNsUjE1pjdEa4MFpWzm1Rue4zJ5DMy1oUyZBi/aiCLMhdMnjl2bh2Q==
|
||||
dependencies:
|
||||
"@ethereumjs/util" "^8.1.0"
|
||||
"@metamask/abi-utils" "^2.0.4"
|
||||
@ -964,13 +964,20 @@
|
||||
dependencies:
|
||||
undici-types "~6.19.2"
|
||||
|
||||
"@types/node@22.7.5", "@types/node@^22.7.5":
|
||||
"@types/node@22.7.5":
|
||||
version "22.7.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.7.5.tgz#cfde981727a7ab3611a481510b473ae54442b92b"
|
||||
integrity sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==
|
||||
dependencies:
|
||||
undici-types "~6.19.2"
|
||||
|
||||
"@types/node@^22.7.9":
|
||||
version "22.7.9"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.7.9.tgz#2bf2797b5e84702d8262ea2cf843c3c3c880d0e9"
|
||||
integrity sha512-jrTfRC7FM6nChvU7X2KqcrgquofrWLFDeYC1hKfwNWomVvrn7JIksqf344WN2X/y8xrgqBd2dJATZV4GbatBfg==
|
||||
dependencies:
|
||||
undici-types "~6.19.2"
|
||||
|
||||
"@types/prettier@^2.1.1":
|
||||
version "2.7.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.3.tgz#3e51a17e291d01d17d3fc61422015a933af7a08f"
|
||||
@ -981,62 +988,62 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975"
|
||||
integrity sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==
|
||||
|
||||
"@typescript-eslint/eslint-plugin@^8.9.0":
|
||||
version "8.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.9.0.tgz#bf0b25305b0bf014b4b194a6919103d7ac2a7907"
|
||||
integrity sha512-Y1n621OCy4m7/vTXNlCbMVp87zSd7NH0L9cXD8aIpOaNlzeWxIK4+Q19A68gSmTNRZn92UjocVUWDthGxtqHFg==
|
||||
"@typescript-eslint/eslint-plugin@^8.11.0":
|
||||
version "8.11.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.11.0.tgz#c3f087d20715fa94310b30666c08b3349e0ab084"
|
||||
integrity sha512-KhGn2LjW1PJT2A/GfDpiyOfS4a8xHQv2myUagTM5+zsormOmBlYsnQ6pobJ8XxJmh6hnHwa2Mbe3fPrDJoDhbA==
|
||||
dependencies:
|
||||
"@eslint-community/regexpp" "^4.10.0"
|
||||
"@typescript-eslint/scope-manager" "8.9.0"
|
||||
"@typescript-eslint/type-utils" "8.9.0"
|
||||
"@typescript-eslint/utils" "8.9.0"
|
||||
"@typescript-eslint/visitor-keys" "8.9.0"
|
||||
"@typescript-eslint/scope-manager" "8.11.0"
|
||||
"@typescript-eslint/type-utils" "8.11.0"
|
||||
"@typescript-eslint/utils" "8.11.0"
|
||||
"@typescript-eslint/visitor-keys" "8.11.0"
|
||||
graphemer "^1.4.0"
|
||||
ignore "^5.3.1"
|
||||
natural-compare "^1.4.0"
|
||||
ts-api-utils "^1.3.0"
|
||||
|
||||
"@typescript-eslint/parser@^8.9.0":
|
||||
version "8.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-8.9.0.tgz#0cecda6def8aef95d7c7098359c0fda5a362d6ad"
|
||||
integrity sha512-U+BLn2rqTTHnc4FL3FJjxaXptTxmf9sNftJK62XLz4+GxG3hLHm/SUNaaXP5Y4uTiuYoL5YLy4JBCJe3+t8awQ==
|
||||
"@typescript-eslint/parser@^8.11.0":
|
||||
version "8.11.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-8.11.0.tgz#2ad1481388dc1c937f50b2d138c9ca57cc6c5cce"
|
||||
integrity sha512-lmt73NeHdy1Q/2ul295Qy3uninSqi6wQI18XwSpm8w0ZbQXUpjCAWP1Vlv/obudoBiIjJVjlztjQ+d/Md98Yxg==
|
||||
dependencies:
|
||||
"@typescript-eslint/scope-manager" "8.9.0"
|
||||
"@typescript-eslint/types" "8.9.0"
|
||||
"@typescript-eslint/typescript-estree" "8.9.0"
|
||||
"@typescript-eslint/visitor-keys" "8.9.0"
|
||||
"@typescript-eslint/scope-manager" "8.11.0"
|
||||
"@typescript-eslint/types" "8.11.0"
|
||||
"@typescript-eslint/typescript-estree" "8.11.0"
|
||||
"@typescript-eslint/visitor-keys" "8.11.0"
|
||||
debug "^4.3.4"
|
||||
|
||||
"@typescript-eslint/scope-manager@8.9.0":
|
||||
version "8.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-8.9.0.tgz#c98fef0c4a82a484e6a1eb610a55b154d14d46f3"
|
||||
integrity sha512-bZu9bUud9ym1cabmOYH9S6TnbWRzpklVmwqICeOulTCZ9ue2/pczWzQvt/cGj2r2o1RdKoZbuEMalJJSYw3pHQ==
|
||||
"@typescript-eslint/scope-manager@8.11.0":
|
||||
version "8.11.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-8.11.0.tgz#9d399ce624118966732824878bc9a83593a30405"
|
||||
integrity sha512-Uholz7tWhXmA4r6epo+vaeV7yjdKy5QFCERMjs1kMVsLRKIrSdM6o21W2He9ftp5PP6aWOVpD5zvrvuHZC0bMQ==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "8.9.0"
|
||||
"@typescript-eslint/visitor-keys" "8.9.0"
|
||||
"@typescript-eslint/types" "8.11.0"
|
||||
"@typescript-eslint/visitor-keys" "8.11.0"
|
||||
|
||||
"@typescript-eslint/type-utils@8.9.0":
|
||||
version "8.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-8.9.0.tgz#aa86da3e4555fe7c8b42ab75e13561c4b5a8dfeb"
|
||||
integrity sha512-JD+/pCqlKqAk5961vxCluK+clkppHY07IbV3vett97KOV+8C6l+CPEPwpUuiMwgbOz/qrN3Ke4zzjqbT+ls+1Q==
|
||||
"@typescript-eslint/type-utils@8.11.0":
|
||||
version "8.11.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-8.11.0.tgz#b7f9e6120c1ddee8a1a07615646642ad85fc91b5"
|
||||
integrity sha512-ItiMfJS6pQU0NIKAaybBKkuVzo6IdnAhPFZA/2Mba/uBjuPQPet/8+zh5GtLHwmuFRShZx+8lhIs7/QeDHflOg==
|
||||
dependencies:
|
||||
"@typescript-eslint/typescript-estree" "8.9.0"
|
||||
"@typescript-eslint/utils" "8.9.0"
|
||||
"@typescript-eslint/typescript-estree" "8.11.0"
|
||||
"@typescript-eslint/utils" "8.11.0"
|
||||
debug "^4.3.4"
|
||||
ts-api-utils "^1.3.0"
|
||||
|
||||
"@typescript-eslint/types@8.9.0":
|
||||
version "8.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.9.0.tgz#b733af07fb340b32e962c6c63b1062aec2dc0fe6"
|
||||
integrity sha512-SjgkvdYyt1FAPhU9c6FiYCXrldwYYlIQLkuc+LfAhCna6ggp96ACncdtlbn8FmnG72tUkXclrDExOpEYf1nfJQ==
|
||||
"@typescript-eslint/types@8.11.0":
|
||||
version "8.11.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.11.0.tgz#7c766250502097f49bbc2e651132e6bf489e20b8"
|
||||
integrity sha512-tn6sNMHf6EBAYMvmPUaKaVeYvhUsrE6x+bXQTxjQRp360h1giATU0WvgeEys1spbvb5R+VpNOZ+XJmjD8wOUHw==
|
||||
|
||||
"@typescript-eslint/typescript-estree@8.9.0":
|
||||
version "8.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-8.9.0.tgz#1714f167e9063062dc0df49c1d25afcbc7a96199"
|
||||
integrity sha512-9iJYTgKLDG6+iqegehc5+EqE6sqaee7kb8vWpmHZ86EqwDjmlqNNHeqDVqb9duh+BY6WCNHfIGvuVU3Tf9Db0g==
|
||||
"@typescript-eslint/typescript-estree@8.11.0":
|
||||
version "8.11.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-8.11.0.tgz#35fe5d3636fc5727c52429393415412e552e222b"
|
||||
integrity sha512-yHC3s1z1RCHoCz5t06gf7jH24rr3vns08XXhfEqzYpd6Hll3z/3g23JRi0jM8A47UFKNc3u/y5KIMx8Ynbjohg==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "8.9.0"
|
||||
"@typescript-eslint/visitor-keys" "8.9.0"
|
||||
"@typescript-eslint/types" "8.11.0"
|
||||
"@typescript-eslint/visitor-keys" "8.11.0"
|
||||
debug "^4.3.4"
|
||||
fast-glob "^3.3.2"
|
||||
is-glob "^4.0.3"
|
||||
@ -1044,22 +1051,22 @@
|
||||
semver "^7.6.0"
|
||||
ts-api-utils "^1.3.0"
|
||||
|
||||
"@typescript-eslint/utils@8.9.0":
|
||||
version "8.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.9.0.tgz#748bbe3ea5bee526d9786d9405cf1b0df081c299"
|
||||
integrity sha512-PKgMmaSo/Yg/F7kIZvrgrWa1+Vwn036CdNUvYFEkYbPwOH4i8xvkaRlu148W3vtheWK9ckKRIz7PBP5oUlkrvQ==
|
||||
"@typescript-eslint/utils@8.11.0":
|
||||
version "8.11.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.11.0.tgz#4480d1e9f2bb18ea3510c79f870a1aefc118103d"
|
||||
integrity sha512-CYiX6WZcbXNJV7UNB4PLDIBtSdRmRI/nb0FMyqHPTQD1rMjA0foPLaPUV39C/MxkTd/QKSeX+Gb34PPsDVC35g==
|
||||
dependencies:
|
||||
"@eslint-community/eslint-utils" "^4.4.0"
|
||||
"@typescript-eslint/scope-manager" "8.9.0"
|
||||
"@typescript-eslint/types" "8.9.0"
|
||||
"@typescript-eslint/typescript-estree" "8.9.0"
|
||||
"@typescript-eslint/scope-manager" "8.11.0"
|
||||
"@typescript-eslint/types" "8.11.0"
|
||||
"@typescript-eslint/typescript-estree" "8.11.0"
|
||||
|
||||
"@typescript-eslint/visitor-keys@8.9.0":
|
||||
version "8.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-8.9.0.tgz#5f11f4d9db913f37da42776893ffe0dd1ae78f78"
|
||||
integrity sha512-Ht4y38ubk4L5/U8xKUBfKNYGmvKvA1CANoxiTRMM+tOLk3lbF3DvzZCxJCRSE+2GdCMSh6zq9VZJc3asc1XuAA==
|
||||
"@typescript-eslint/visitor-keys@8.11.0":
|
||||
version "8.11.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-8.11.0.tgz#273de1cbffe63d9f9cd7dfc20b5a5af66310cb92"
|
||||
integrity sha512-EaewX6lxSjRJnc+99+dqzTeoDZUfyrA52d2/HRrkI830kgovWsmIiTfmr0NZorzqic7ga+1bS60lRBUgR3n/Bw==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "8.9.0"
|
||||
"@typescript-eslint/types" "8.11.0"
|
||||
eslint-visitor-keys "^3.4.3"
|
||||
|
||||
"@ungap/structured-clone@^1.2.0":
|
||||
|
Loading…
Reference in New Issue
Block a user