How to use the eth-crypto.publicKey function in eth-crypto

To help you get started, we’ve selected a few eth-crypto 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 AztecProtocol / AZTEC / packages / extension / src / client / services / MetaMaskService / index.js View on Github external
break;
        }
        case 'metamask.register.extension': {
            const eip712Data = registerExtension(params);
            const method = 'eth_signTypedData_v3';
            const { result } = await Web3Service.sendAsync({
                method,
                params: [address, eip712Data],
                from: address,
            });

            const publicKey = ethSigUtil.extractPublicKey({
                data: eip712Data,
                sig: result,
            });
            const compressedPublicKey = EthCrypto.publicKey.compress(
                publicKey.slice(2),
            );

            response = {
                signature: result,
                publicKey: `0x${compressedPublicKey}`,
            };
            break;
        }
        case 'metamask.ace.publicApprove': {
            // we only need to do this if the proof sender is the user
            // TODO the wallet contract or any contract will be responsible for this
            const {
                assetAddress,
                amount,
                proofHash,
github ShipChain / engine / src / entity / Wallet.ts View on Github external
static async import_entity(private_key) {
        // Validate private_key format, this throws if private_key format is not valid
        const public_key = EthCrypto.publicKeyByPrivateKey(private_key);
        const address = EthCrypto.publicKey.toAddress(public_key);

        // Try to get existing wallet by address.
        // Errors indicate Wallet does not exist and needs to be created
        try {
            return await Wallet.getByAddress(address);
        } catch (_err) {
            const wallet = new Wallet();

            const encryptedPrivateKey = await EncryptorContainer.defaultEncryptor.encrypt(private_key);

            Object.assign(wallet, {
                public_key: public_key,
                private_key: encryptedPrivateKey,
                address: address,
                unlocked_private_key: private_key,
            });
github RequestNetwork / requestNetwork / packages / utils / src / crypto / ec-utils.ts View on Github external
function getAddressFromPrivateKey(privateKey: string): string {
  try {
    const publicKey = EthCrypto.publicKeyByPrivateKey(privateKey);
    return EthCrypto.publicKey.toAddress(publicKey);
  } catch (e) {
    if (e.message === 'private key length is invalid') {
      throw new Error('The private key must be a string representing 32 bytes');
    }
    throw e;
  }
}
github enigmampc / secret-contracts / enigma-lib / enigma-utils.js View on Github external
function toAddress (publicKey) {
    const address = EthCrypto.publicKey.toAddress (publicKey);
    return address;
}