How to use @ethersproject/address - 10 common examples

To help you get started, we’ve selected a few @ethersproject/address 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 ethers-io / ethers.js / packages / json-wallets / lib.esm / crowdsale.js View on Github external
export function decrypt(json, password) {
    const data = JSON.parse(json);
    password = getPassword(password);
    // Ethereum Address
    const ethaddr = getAddress(searchPath(data, "ethaddr"));
    // Encrypted Seed
    const encseed = looseArrayify(searchPath(data, "encseed"));
    if (!encseed || (encseed.length % 16) !== 0) {
        logger.throwArgumentError("invalid encseed", "json", json);
    }
    const key = arrayify(pbkdf2(password, password, 2000, 32, "sha256")).slice(0, 16);
    const iv = encseed.slice(0, 16);
    const encryptedSeed = encseed.slice(16);
    // Decrypt the seed
    const aesCbc = new aes.ModeOfOperation.cbc(key, iv);
    const seed = aes.padding.pkcs7.strip(arrayify(aesCbc.decrypt(encryptedSeed)));
    // This wallet format is weird... Convert the binary encoded hex to a string.
    let seedHex = "";
    for (let i = 0; i < seed.length; i++) {
        seedHex += String.fromCharCode(seed[i]);
    }
github ethers-io / ethers.js / packages / json-wallets / lib.esm / keystore.js View on Github external
const computedMAC = hexlify(computeMAC(key.slice(16, 32), ciphertext)).substring(2);
                if (computedMAC !== searchPath(data, "crypto/mac").toLowerCase()) {
                    throw new Error("invalid password");
                }
                const privateKey = decrypt(key.slice(0, 16), ciphertext);
                const mnemonicKey = key.slice(32, 64);
                if (!privateKey) {
                    throw new Error("unsupported cipher");
                }
                const address = computeAddress(privateKey);
                if (data.address) {
                    let check = data.address.toLowerCase();
                    if (check.substring(0, 2) !== "0x") {
                        check = "0x" + check;
                    }
                    if (getAddress(check) !== address) {
                        throw new Error("address mismatch");
                    }
                }
                const account = {
                    _isKeystoreAccount: true,
                    address: address,
                    privateKey: hexlify(privateKey)
                };
                // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
                if (searchPath(data, "x-ethers/version") === "0.1") {
                    const mnemonicCiphertext = looseArrayify(searchPath(data, "x-ethers/mnemonicCiphertext"));
                    const mnemonicIv = looseArrayify(searchPath(data, "x-ethers/mnemonicCounter"));
                    const mnemonicCounter = new aes.Counter(mnemonicIv);
                    const mnemonicAesCtr = new aes.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter);
                    const path = searchPath(data, "x-ethers/path") || defaultPath;
                    const entropy = arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext));
github ethers-io / ethers.js / packages / json-wallets / src.ts / keystore.ts View on Github external
throw new Error("invalid password");
        }

        const privateKey = decrypt(key.slice(0, 16), ciphertext);
        const mnemonicKey = key.slice(32, 64);

        if (!privateKey) {
            throw new Error("unsupported cipher");
        }

        const address = computeAddress(privateKey);
        if (data.address) {
            let check = data.address.toLowerCase();
            if (check.substring(0, 2) !== "0x") { check = "0x" + check; }

            if (getAddress(check) !== address) {
                throw new Error("address mismatch");
            }
        }

        const account: any = {
            _isKeystoreAccount: true,
            address: address,
            privateKey: hexlify(privateKey)
        };

        // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
        if (searchPath(data, "x-ethers/version") === "0.1") {
            const mnemonicCiphertext = looseArrayify(searchPath(data, "x-ethers/mnemonicCiphertext"));
            const mnemonicIv = looseArrayify(searchPath(data, "x-ethers/mnemonicCounter"));

            const mnemonicCounter = new aes.Counter(mnemonicIv);
github ethers-io / ethers.js / packages / providers / lib.esm / formatter.js View on Github external
contractAddress(value) {
        return getContractAddress(value);
    }
    // Strict! Used on input.
github ethers-io / ethers.js / packages / providers / lib / formatter.js View on Github external
Formatter.prototype.contractAddress = function (value) {
        return address_1.getContractAddress(value);
    };
    // Strict! Used on input.
github ethers-io / ethers.js / packages / abi / lib / interface.js View on Github external
Interface.getAddress = function (address) {
        return address_1.getAddress(address);
    };
    Interface.prototype._sighashify = function (functionFragment) {
github ethers-io / ethers.js / packages / providers / lib.esm / formatter.js View on Github external
callAddress(value) {
        if (!isHexString(value, 32)) {
            return null;
        }
        let address = getAddress(hexDataSlice(value, 12));
        return (address === AddressZero) ? null : address;
    }
    contractAddress(value) {
github ethers-io / ethers.js / packages / transactions / lib.esm / index.js View on Github external
function handleAddress(value) {
    if (value === "0x") {
        return null;
    }
    return getAddress(value);
}
function handleNumber(value) {
github ethers-io / ethers.js / packages / abi / lib.esm / interface.js View on Github external
static getAddress(address) {
        return getAddress(address);
    }
    _sighashify(functionFragment) {
github ethers-io / ethers.js / packages / transactions / lib / index.js View on Github external
function handleAddress(value) {
    if (value === "0x") {
        return null;
    }
    return address_1.getAddress(value);
}
function handleNumber(value) {

@ethersproject/address

Utilities for handling Ethereum Addresses for ethers.

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis