How to use the eth-sig-util.signTypedDataLegacy 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 MetaMask / eth-simple-keyring / index.js View on Github external
signTypedData_v1 (withAccount, typedData, opts = {}) {
    const privKey = this.getPrivateKeyFor(withAccount, opts);
    const sig = sigUtil.signTypedDataLegacy(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);
		}
	}