Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
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,
});
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;
}
}
function toAddress (publicKey) {
const address = EthCrypto.publicKey.toAddress (publicKey);
return address;
}