@ethersproject/abstract-signer#TypedDataSigner TypeScript Examples

The following examples show how to use @ethersproject/abstract-signer#TypedDataSigner. 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: signatures.ts    From balancer-v2-monorepo with GNU General Public License v3.0 6 votes vote down vote up
static signJoinAuthorization = (
    validator: Contract,
    user: Signer & TypedDataSigner,
    allowedSender: Account,
    allowedCalldata: string,
    deadline?: BigNumberish,
    nonce?: BigNumberish
  ): Promise<string> =>
    RelayerAuthorization.signAuthorizationFor(
      RelayerAction.JoinPool,
      validator,
      user,
      allowedSender,
      allowedCalldata,
      deadline,
      nonce
    );
Example #2
Source File: signatures.ts    From balancer-v2-monorepo with GNU General Public License v3.0 6 votes vote down vote up
static signExitAuthorization = (
    validator: Contract,
    user: Signer & TypedDataSigner,
    allowedSender: Account,
    allowedCalldata: string,
    deadline?: BigNumberish,
    nonce?: BigNumberish
  ): Promise<string> =>
    RelayerAuthorization.signAuthorizationFor(
      RelayerAction.ExitPool,
      validator,
      user,
      allowedSender,
      allowedCalldata,
      deadline,
      nonce
    );
Example #3
Source File: signatures.ts    From balancer-v2-monorepo with GNU General Public License v3.0 6 votes vote down vote up
static signSwapAuthorization = (
    validator: Contract,
    user: Signer & TypedDataSigner,
    allowedSender: Account,
    allowedCalldata: string,
    deadline?: BigNumberish,
    nonce?: BigNumberish
  ): Promise<string> =>
    RelayerAuthorization.signAuthorizationFor(
      RelayerAction.Swap,
      validator,
      user,
      allowedSender,
      allowedCalldata,
      deadline,
      nonce
    );
Example #4
Source File: signatures.ts    From balancer-v2-monorepo with GNU General Public License v3.0 6 votes vote down vote up
static signBatchSwapAuthorization = (
    validator: Contract,
    user: Signer & TypedDataSigner,
    allowedSender: Account,
    allowedCalldata: string,
    deadline?: BigNumberish,
    nonce?: BigNumberish
  ): Promise<string> =>
    RelayerAuthorization.signAuthorizationFor(
      RelayerAction.BatchSwap,
      validator,
      user,
      allowedSender,
      allowedCalldata,
      deadline,
      nonce
    );
Example #5
Source File: signatures.ts    From balancer-v2-monorepo with GNU General Public License v3.0 6 votes vote down vote up
static signSetRelayerApprovalAuthorization = (
    validator: Contract,
    user: Signer & TypedDataSigner,
    allowedSender: Account,
    allowedCalldata: string,
    deadline?: BigNumberish,
    nonce?: BigNumberish
  ): Promise<string> =>
    RelayerAuthorization.signAuthorizationFor(
      RelayerAction.SetRelayerApproval,
      validator,
      user,
      allowedSender,
      allowedCalldata,
      deadline,
      nonce
    );
Example #6
Source File: permit.ts    From balancer-v2-monorepo with GNU General Public License v3.0 5 votes vote down vote up
signPermit = async (
  token: Contract,
  owner: Signer & TypedDataSigner,
  spender: Account,
  amount: BigNumberish,
  deadline: BigNumberish = MAX_DEADLINE,
  nonce?: BigNumberish
): Promise<{ v: number; r: string; s: string; deadline: BigNumber; nonce: BigNumber }> => {
  const { chainId } = await token.provider.getNetwork();
  const ownerAddress = await owner.getAddress();

  if (!nonce) nonce = (await token.nonces(ownerAddress)) as BigNumberish;

  // Hack around some tokens not exposing a `version()` function.
  // If they do then use it, otherwise assume that their version is "1".
  let version = '1';
  try {
    if (token.version) {
      version = await token.version();
    }
  } catch {
    // eslint-disable-prev-line no-empty
  }

  const domain = {
    name: await token.name(),
    version,
    chainId,
    verifyingContract: token.address,
  };

  const types = {
    Permit: [
      { name: 'owner', type: 'address' },
      { name: 'spender', type: 'address' },
      { name: 'value', type: 'uint256' },
      { name: 'nonce', type: 'uint256' },
      { name: 'deadline', type: 'uint256' },
    ],
  };

  const value = {
    owner: ownerAddress,
    spender: await accountToAddress(spender),
    value: amount,
    nonce,
    deadline,
  };

  const signature = await owner._signTypedData(domain, types, value);
  return { ...splitSignature(signature), deadline: BigNumber.from(deadline), nonce: BigNumber.from(nonce) };
}
Example #7
Source File: signatures.ts    From balancer-v2-monorepo with GNU General Public License v3.0 5 votes vote down vote up
static signAuthorizationFor = async (
    type: RelayerAction,
    validator: Contract,
    user: Signer & TypedDataSigner,
    allowedSender: Account,
    allowedCalldata: string,
    deadline: BigNumberish = MAX_DEADLINE,
    nonce?: BigNumberish
  ): Promise<string> => {
    const { chainId } = await validator.provider.getNetwork();
    if (!nonce) {
      const userAddress = await user.getAddress();
      nonce = (await validator.getNextNonce(userAddress)) as BigNumberish;
    }

    const domain = {
      name: 'Balancer V2 Vault',
      version: '1',
      chainId,
      verifyingContract: validator.address,
    };

    const types = {
      [type]: [
        { name: 'calldata', type: 'bytes' },
        { name: 'sender', type: 'address' },
        { name: 'nonce', type: 'uint256' },
        { name: 'deadline', type: 'uint256' },
      ],
    };

    const value = {
      calldata: allowedCalldata,
      sender: await accountToAddress(allowedSender),
      nonce: nonce.toString(),
      deadline: deadline.toString(),
    };

    return user._signTypedData(domain, types, value);
  };
Example #8
Source File: signatures.ts    From balancer-v2-monorepo with GNU General Public License v3.0 5 votes vote down vote up
static signSetMinterApproval = async (
    minterContract: Contract,
    minter: Account,
    approval: boolean,
    user: Signer & TypedDataSigner,
    deadline: BigNumberish = MAX_DEADLINE,
    nonce?: BigNumberish
  ): Promise<{ v: number; r: string; s: string; deadline: BigNumber }> => {
    const { chainId } = await minterContract.provider.getNetwork();
    if (!nonce) {
      const userAddress = await user.getAddress();
      nonce = (await minterContract.getNextNonce(userAddress)) as BigNumberish;
    }

    const domain = {
      name: 'Balancer Minter',
      version: '1',
      chainId,
      verifyingContract: minterContract.address,
    };

    const types = {
      SetMinterApproval: [
        { name: 'minter', type: 'address' },
        { name: 'approval', type: 'bool' },
        { name: 'nonce', type: 'uint256' },
        { name: 'deadline', type: 'uint256' },
      ],
    };

    const value = {
      minter: await accountToAddress(minter),
      approval,
      nonce: nonce.toString(),
      deadline: deadline.toString(),
    };

    const signature = await user._signTypedData(domain, types, value);

    return { ...splitSignature(signature), deadline: BigNumber.from(deadline) };
  };
Example #9
Source File: index.ts    From ethereum-sdk with MIT License 5 votes vote down vote up
constructor(readonly signer: TypedDataSigner & ethers.Signer) {}