How to use the eth-crypto.publicKeyByPrivateKey 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 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 ShipChain / engine / src / shipchain / AwsPrivateKeyDBFieldEncryption.ts View on Github external
static async getInstance(): Promise {
        if (!this._instance) {
            let instance = new AwsPrivateKeyDBFieldEncryption();

            instance.masterPrivateKey = await instance.getMasterPrivateKey();
            instance.masterPublicKey = EthCrypto.publicKeyByPrivateKey(instance.masterPrivateKey);

            this._instance = instance;
        }

        return this._instance;
    }
github ShipChain / engine / src / entity / encryption / PrivateKeyDBFieldEncryption.ts View on Github external
static async getInstance(): Promise {
        if (!this._instance) {
            let instance = new PrivateKeyDBFieldEncryption();

            instance.masterPrivateKey = await instance.getMasterPrivateKey();
            instance.masterPublicKey = EthCrypto.publicKeyByPrivateKey(instance.masterPrivateKey);

            this._instance = instance;
        }

        return this._instance;
    }
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;
  }
}