@ethersproject/abstract-signer#TypedDataField TypeScript Examples
The following examples show how to use
@ethersproject/abstract-signer#TypedDataField.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From hypervisor with The Unlicense | 7 votes |
signPermission = async (
method: string,
vault: Contract,
owner: Wallet,
delegateAddress: string,
tokenAddress: string,
amount: BigNumberish,
vaultNonce: BigNumberish,
chainId?: BigNumberish,
) => {
// get chainId
chainId = chainId || (await vault.provider.getNetwork()).chainId
// craft permission
const domain = {
name: 'UniversalVault',
version: '1.0.0',
chainId: chainId,
verifyingContract: vault.address,
}
const types = {} as Record<string, TypedDataField[]>
types[method] = [
{ name: 'delegate', type: 'address' },
{ name: 'token', type: 'address' },
{ name: 'amount', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
]
const value = {
delegate: delegateAddress,
token: tokenAddress,
amount: amount,
nonce: vaultNonce,
}
// sign permission
// todo: add fallback if wallet does not support eip 712 rpc
const signedPermission = await owner._signTypedData(domain, types, value)
// return
return signedPermission
}
Example #2
Source File: Signer.ts From bodhi.js with Apache License 2.0 | 6 votes |
async _signTypedData(
domain: TypedDataDomain,
types: Record<string, Array<TypedDataField>>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: Record<string, any>
): Promise<string> {
return logger.throwError('_signTypedData is unsupported', Logger.errors.UNSUPPORTED_OPERATION, {
operation: '_signTypedData'
});
}
Example #3
Source File: utils.ts From hypervisor with The Unlicense | 6 votes |
signPermitEIP2612 = async (
owner: Wallet,
token: Contract,
spenderAddress: string,
value: BigNumberish,
deadline: BigNumberish,
nonce?: BigNumberish,
) => {
// get nonce
nonce = nonce || (await token.nonces(owner.address))
// get chainId
const chainId = (await token.provider.getNetwork()).chainId
// get domain
const domain = {
name: 'Uniswap V2',
version: '1',
chainId: chainId,
verifyingContract: token.address,
}
// get types
const types = {} as Record<string, TypedDataField[]>
types['Permit'] = [
{ name: 'owner', type: 'address' },
{ name: 'spender', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'uint256' },
]
// get values
const values = {
owner: owner.address,
spender: spenderAddress,
value: value,
nonce: nonce,
deadline: deadline,
}
// sign permission
// todo: add fallback if wallet does not support eip 712 rpc
const signedPermission = await owner._signTypedData(domain, types, values)
// split signature
const sig = splitSignature(signedPermission)
// return
return [
values.owner,
values.spender,
values.value,
values.deadline,
sig.v,
sig.r,
sig.s,
]
}
Example #4
Source File: Signer.ts From evm-provider.js with Apache License 2.0 | 6 votes |
async _signTypedData(
domain: TypedDataDomain,
types: Record<string, Array<TypedDataField>>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: Record<string, any>
): Promise<string> {
return logger.throwError(
'_signTypedData is unsupported',
Logger.errors.UNSUPPORTED_OPERATION,
{
operation: '_signTypedData'
}
);
}