How to use the eth-sig-util.signTypedData_v4 function in eth-sig-util

To help you get started, we’ve selected a few eth-sig-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nomiclabs / buidler / packages / buidler-core / src / internal / buidler-evm / provider / node.ts View on Github external
public async signTypedData(address: Buffer, typedData: any): Promise {
    const privateKey = await this._getLocalAccountPrivateKey(address);

    return ethSigUtil.signTypedData_v4(privateKey, {
      data: typedData
    });
  }
github MetaMask / eth-simple-keyring / index.js View on Github external
signTypedData_v4 (withAccount, typedData, opts = {}) {
    const privKey = this.getPrivateKeyFor(withAccount, opts);
    const sig = sigUtil.signTypedData_v4(privKey, { data: typedData })
    return Promise.resolve(sig)
  }
github MetaMask / gaba / src / keyring / KeyringController.ts View on Github external
async signTypedMessage(messageParams: TypedMessageParams, version: string) {
		try {
			const address = sigUtil.normalize(messageParams.from);
			const password = privates.get(this).keyring.password;
			const privateKey = await this.exportAccount(password, address);
			const privateKeyBuffer = ethUtil.toBuffer(ethUtil.addHexPrefix(privateKey));
			switch (version) {
				case 'V1':
					return sigUtil.signTypedDataLegacy(privateKeyBuffer, { data: messageParams.data });
				case 'V3':
					return sigUtil.signTypedData(privateKeyBuffer, { data: JSON.parse(messageParams.data as string) });
				case 'V4':
					return sigUtil.signTypedData_v4(privateKeyBuffer, {
						data: JSON.parse(messageParams.data as string)
					});
			}
		} catch (error) {
			throw new Error('Keyring Controller signTypedMessage: ' + error);
		}
	}
github nomiclabs / buidler / packages / buidler-core / src / internal / core / providers / accounts.ts View on Github external
const [address, data] = params;

      if (address !== undefined) {
        if (data === undefined) {
          throw new BuidlerError(ERRORS.NETWORK.ETHSIGN_MISSING_DATA_PARAM);
        }

        const privateKey = getPrivateKey(address);

        if (privateKey === undefined) {
          throw new BuidlerError(ERRORS.NETWORK.NOT_LOCAL_ACCOUNT, {
            account: address
          });
        }

        return ethSigUtil.signTypedData_v4(privateKey, {
          data
        });
      }
    }

    if (method === "eth_sendTransaction" && params.length > 0) {
      const tx: JsonRpcTransactionData = params[0];

      if (tx.gas === undefined) {
        throw new BuidlerError(
          ERRORS.NETWORK.MISSING_TX_PARAM_TO_SIGN_LOCALLY,
          { param: "gas" }
        );
      }

      if (tx.gasPrice === undefined) {