opensea-js icon indicating copy to clipboard operation
opensea-js copied to clipboard

Cannot read property 'EIP712Domain' error on Version 4.0.0

Open Racherin opened this issue 4 years ago • 17 comments

There was an error about signing data after migrating to V 2.0.0 based on issue #372 .

I'm facing with same issue again after trying to use 4.0.0-beta.1 version. @truffle/hdwallet-provider throws same error again.

/node_modules/@truffle/hdwallet-provider/node_modules/eth-sig-util/dist/index.js:172
        if (results.includes(primaryType) || types[primaryType] === undefined) {
                                                  ^
TypeError: Cannot read properties of undefined (reading 'EIP712Domain')

Using a eth_signTypedData fallback should fix this issue but I see that it's implemented already.

export async function signTypedDataAsync(
  web3: Web3,
  message: object,
  signerAddress: string
): Promise<ECSignature> {
  let signature: JsonRpcResponse | undefined;
  try {
    // Using sign typed data V4 works with a stringified message, used by browser providers i.e. Metamask
    signature = await promisify<JsonRpcResponse | undefined>((c) =>
      (web3.currentProvider as AbstractProvider).sendAsync(
        {
          method: "eth_signTypedData_v4",
          params: [signerAddress, JSON.stringify(message)],
          from: signerAddress,
          id: new Date().getTime(),
          // eslint-disable-next-line @typescript-eslint/no-explicit-any
        } as any,
        c
      )
    );
  } catch {
    // Fallback to normal sign typed data for node providers, without using stringified message
    // https://github.com/coinbase/coinbase-wallet-sdk/issues/60
    signature = await promisify<JsonRpcResponse | undefined>((c) =>
      (web3.currentProvider as AbstractProvider).sendAsync(
        {
          method: "eth_signTypedData",
          params: [signerAddress, message],
          from: signerAddress,
          id: new Date().getTime(),
          // eslint-disable-next-line @typescript-eslint/no-explicit-any
        } as any,
        c
      )
    );
  }

Racherin avatar Jun 10 '22 09:06 Racherin

Did you see this?

https://github.com/ProjectOpenSea/opensea-js/issues/372#issuecomment-1093117092

esteban-OpenSea avatar Jun 10 '22 22:06 esteban-OpenSea

@esteban-OpenSea Hey, I checked out mentioned comment but couldn't find any solution.

Racherin avatar Jun 11 '22 14:06 Racherin

@esteban-OpenSea Hey, I checked out mentioned comment but couldn't find any solution.

Hey did you end up finding a solution ? I can’t make any buy orders without this error ?

matthewklinko avatar Jun 15 '22 20:06 matthewklinko

same issue @4.0.1 downgrade to @3.0.4 solves this issue

perioh avatar Jun 16 '22 12:06 perioh

the new protocol isnt available on that version though, anyone got any other solutions?

gv1122 avatar Jun 17 '22 16:06 gv1122

Getting same error while trying to make bid on an asset using the sdk version 4.0.2

MetalGear-cmd avatar Jun 18 '22 17:06 MetalGear-cmd

I am also seeing the same error with the hardware wallet. 3.0.4 works still, but for how long?

andrewlwn77 avatar Jun 18 '22 23:06 andrewlwn77

Getting this error when I run createBuyOrder with 4.0.0-beta.2, @truffle/hdwallet-provider.

nextmove avatar Jun 19 '22 02:06 nextmove

The fallback function createSellOrderLegacyWyvern is still currently working, but when will the old contract be mothballed?

andrewlwn77 avatar Jun 19 '22 03:06 andrewlwn77

The fallback function createSellOrderLegacyWyvern is still currently working, but when will the old contract be mothballed?

On June 21, offers and listings can no longer be posted to the Wyvern 2.3 contract using OpenSea - and on July 13, offers and listings can no longer be fetched from the Wyvern 2.3 contract using OpenSea. https://twitter.com/apiopensea/status/1536822790354894848

nextmove avatar Jun 19 '22 13:06 nextmove

@esteban-OpenSea any update on this ? there's only 1 day left before endpoint deprecated.

Racherin avatar Jun 20 '22 09:06 Racherin

same issue @4.0.1

xiaoyannzbbb avatar Jun 21 '22 01:06 xiaoyannzbbb

The fallback function createSellOrderLegacyWyvern is still currently working, but when will the old contract be mothballed?

On June 21, offers and listings can no longer be posted to the Wyvern 2.3 contract using OpenSea - and on July 13, offers and listings can no longer be fetched from the Wyvern 2.3 contract using OpenSea. https://twitter.com/apiopensea/status/1536822790354894848

I really hope we can find a way forward on this. 1 day left before we can't make orders anymore.

andrewlewinphsa avatar Jun 21 '22 03:06 andrewlewinphsa

@esteban-OpenSea Hey, I checked out mentioned comment but couldn't find any solution.

Hey did you end up finding a solution ? I can’t make any buy orders without this error ?

Hey Matthew. Would you mind contacting me re graphql? Se my profile for email. Cheers, Mark

MarkMoranNZ avatar Jun 22 '22 10:06 MarkMoranNZ

I get the same issue with 4.0.3.

I used @3.0.4.

However, when I run the script, I get the following error.

Error: API Error 400: Invalid request: "['Wyvern orders posted to the API are deprecated, except for shared storefront orders']"

So I updated @4.0.3 and ran the script one more time. However, I got the following error.

TypeError: Cannot read properties of undefined (reading 'EIP712Domain')

The following is the actual script in which the error occurred.

import Web3 from "web3";
import { Network, OpenSeaSDK } from 'opensea-js'
import HDWalletProvider from "@truffle/hdwallet-provider";
import { Asset } from "opensea-js/lib/types";


async function main(): Promise<void> {
  const provider = new HDWalletProvider({privateKeys: ["0x0"], providerOrUrl: "https://rinkeby.infura.io/v3/hoge"})
  const openseaSDK = new OpenSeaSDK(provider, {networkName: Network.Rinkeby});

  const assets: Asset[] = [
    {
      tokenAddress: "0x0",
      tokenId: "2",
    },
    {
      tokenAddress: "0x0",
      tokenId: "1"
    }
  ]

  const expirationTime = new Date("2022-07-31 23:59:59").getTime() / 1000;

  await openseaSDK.createSellOrder({
    asset: assets[0],
    accountAddress: "0x0",
    startAmount: 5,
    endAmount: 0.1,
    expirationTime,
  })
  console.log("done");
}

main();

process.on("unhandledRejection", (reason) => {
  console.error(reason);
  process.exit(1);
});

k-fujiwara-19 avatar Jun 24 '22 10:06 k-fujiwara-19

I found a more minimal reproducible example.

import * as ethers from "ethers";

import HDWalletProvider from "@truffle/hdwallet-provider";
const RPC_URL = "";
const PRIVATE_KEY =
  "";

async function main() {
  const hdWalletProvider = new HDWalletProvider({
    privateKeys: [PRIVATE_KEY],
    providerOrUrl: RPC_URL,
  });

  hdWalletProvider.engine["stop"]();

  const provider = new ethers.providers.Web3Provider(hdWalletProvider);
  const signer = provider.getSigner();
  const domain = {
    name: "Ether Mail",
    version: "1",
    chainId: 1,
    verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
  };

  // The named list of all type definitions
  const types = {
    Person: [
      { name: "name", type: "string" },
      { name: "wallet", type: "address" },
    ],
    Mail: [
      { name: "from", type: "Person" },
      { name: "to", type: "Person" },
      { name: "contents", type: "string" },
    ],
  };

  // The data to sign
  const value = {
    from: {
      name: "Cow",
      wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
    },
    to: {
      name: "Bob",
      wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
    },
    contents: "Hello, Bob!",
  };

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

  console.log(signature);
}

main();

Error

TypeError: Cannot read properties of undefined (reading 'EIP712Domain')
    at Object.findTypeDependencies (/Users/odan/source/github.com/odan-sandbox/opensea-js-issues-550/node_modules/@truffle/hdwallet-provider/node_modules/eth-sig-util/src/index.ts:230:47)
    at Object.encodeType (/Users/odan/source/github.com/odan-sandbox/opensea-js-issues-550/node_modules/@truffle/hdwallet-provider/node_modules/eth-sig-util/src/index.ts:200:21)
    at Object.hashType (/Users/odan/source/github.com/odan-sandbox/opensea-js-issues-550/node_modules/@truffle/hdwallet-provider/node_modules/eth-sig-util/src/index.ts:267:32)
    at Object.encodeData (/Users/odan/source/github.com/odan-sandbox/opensea-js-issues-550/node_modules/@truffle/hdwallet-provider/node_modules/eth-sig-util/src/index.ts:96:33)
    at Object.hashStruct (/Users/odan/source/github.com/odan-sandbox/opensea-js-issues-550/node_modules/@truffle/hdwallet-provider/node_modules/eth-sig-util/src/index.ts:256:32)
    at Object.sign (/Users/odan/source/github.com/odan-sandbox/opensea-js-issues-550/node_modules/@truffle/hdwallet-provider/node_modules/eth-sig-util/src/index.ts:304:12)
    at Object.signTypedData (/Users/odan/source/github.com/odan-sandbox/opensea-js-issues-550/node_modules/@truffle/hdwallet-provider/node_modules/eth-sig-util/src/index.ts:600:34)
    at HookedWalletSubprovider.signTypedMessage (/Users/odan/source/github.com/odan-sandbox/opensea-js-issues-550/node_modules/@truffle/hdwallet-provider/src/index.ts:231:23)
    at /Users/odan/source/github.com/odan-sandbox/opensea-js-issues-550/node_modules/web3-provider-engine/subproviders/hooked-wallet.js:390:18
    at nextTask (/Users/odan/source/github.com/odan-sandbox/opensea-js-issues-550/node_modules/async/waterfall.js:16:14)

ethers is stringifying the eth_signTypedData_v4 payload with JSON.stringify. https://github.com/ethers-io/ethers.js/blob/6807a76b8ddfdd121f98b21e269de3b195a7673e/packages/providers/src.ts/json-rpc-provider.ts#L271-L274

@truffle/hdwallet-provider is calling eth-sig-util methods on received requests without doing anything. https://github.com/trufflesuite/truffle/blob/ea62e1f5b007dabefb98cf7eacd1cd193dbdd769/packages/hdwallet-provider/src/index.ts#L222-L233

On the other hand, the msgParams.data argument of the signTypedData function of eth-sig-util expects an object, so an error occurs. https://github.com/MetaMask/eth-sig-util/blob/8c6112f1dc831ba4ced675b5229274242328abe1/src/index.ts#L596-L603

Specifically, sanitizedData is {}. https://github.com/MetaMask/eth-sig-util/blob/8c6112f1dc831ba4ced675b5229274242328abe1/src/index.ts#L301

odanado avatar Jun 24 '22 16:06 odanado

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

github-actions[bot] avatar May 24 '23 04:05 github-actions[bot]