How to use @ethersproject/keccak256 - 9 common examples

To help you get started, we’ve selected a few @ethersproject/keccak256 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 / abi / lib.esm / interface.js View on Github external
values.forEach((value, index) => {
            let param = eventFragment.inputs[index];
            if (!param.indexed) {
                if (value != null) {
                    logger.throwArgumentError("cannot filter non-indexed parameters; must be null", ("contract." + param.name), value);
                }
                return;
            }
            if (value == null) {
                topics.push(null);
            }
            else if (param.type === "string") {
                topics.push(id(value));
            }
            else if (param.type === "bytes") {
                topics.push(keccak256(hexlify(value)));
            }
            else if (param.type.indexOf("[") !== -1 || param.type.substring(0, 5) === "tuple") {
                logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
            }
            else {
                // Check addresses are valid
                if (param.type === "address") {
                    this._abiCoder.encode(["address"], [value]);
                }
                topics.push(hexZeroPad(hexlify(value), 32));
            }
        });
        // Trim off trailing nulls
github ethers-io / ethers.js / packages / address / lib / index.js View on Github external
function getContractAddress(transaction) {
    var from = null;
    try {
        from = getAddress(transaction.from);
    }
    catch (error) {
        logger.throwArgumentError("missing from address", "transaction", transaction);
    }
    var nonce = bytes_1.stripZeros(bytes_1.arrayify(bignumber_1.BigNumber.from(transaction.nonce).toHexString()));
    return getAddress(bytes_1.hexDataSlice(keccak256_1.keccak256(rlp_1.encode([from, nonce])), 12));
}
exports.getContractAddress = getContractAddress;
github ethers-io / ethers.js / packages / hash / src.ts / index.ts View on Github external
export function namehash(name: string): string {
    if (typeof(name) !== "string") {
        logger.throwArgumentError("invalid address - " + String(name), "name", name);
    }

    let result: string | Uint8Array = Zeros;
    while (name.length) {
        const partition = name.match(Partition);
        const label = toUtf8Bytes(nameprep(partition[3]));
        result = keccak256(concat([result, keccak256(label)]));

        name = partition[2] || "";
    }

    return hexlify(result);
}
github ethers-io / ethers.js / packages / hash / index.js View on Github external
function id(text) {
    return keccak256_1.keccak256(strings_1.toUtf8Bytes(text));
}
exports.id = id;
github ethers-io / ethers.js / packages / transactions / lib / index.js View on Github external
function computeAddress(key) {
    var publicKey = signing_key_1.computePublicKey(key);
    return address_1.getAddress(bytes_1.hexDataSlice(keccak256_1.keccak256(bytes_1.hexDataSlice(publicKey, 1)), 12));
}
exports.computeAddress = computeAddress;
github ethers-io / ethers.js / packages / wallet / lib.esm / index.js View on Github external
static createRandom(options) {
        let entropy = randomBytes(16);
        if (!options) {
            options = {};
        }
        if (options.extraEntropy) {
            entropy = arrayify(hexDataSlice(keccak256(concat([entropy, options.extraEntropy])), 0, 16));
        }
        const mnemonic = entropyToMnemonic(entropy, options.locale);
        return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
    }
    static fromEncryptedJson(json, password, progressCallback) {
github ethers-io / ethers.js / packages / hash / lib.esm / index.js View on Github external
export function namehash(name) {
    if (typeof (name) !== "string") {
        logger.throwArgumentError("invalid address - " + String(name), "name", name);
    }
    let result = Zeros;
    while (name.length) {
        const partition = name.match(Partition);
        const label = toUtf8Bytes(nameprep(partition[3]));
        result = keccak256(concat([result, keccak256(label)]));
        name = partition[2] || "";
    }
    return hexlify(result);
}
export function id(text) {
github ethers-io / ethers.js / packages / wallet / lib.esm / index.js View on Github external
return resolveProperties(transaction).then((tx) => {
            if (tx.from != null) {
                if (getAddress(tx.from) !== this.address) {
                    throw new Error("transaction from address mismatch");
                }
                delete tx.from;
            }
            const signature = this._signingKey().signDigest(keccak256(serialize(tx)));
            return serialize(tx, signature);
        });
    }
github ethers-io / ethers.js / packages / hash / index.js View on Github external
function namehash(name) {
    if (typeof (name) !== "string") {
        logger.throwArgumentError("invalid address - " + String(name), "name", name);
    }
    var result = Zeros;
    while (name.length) {
        var partition = name.match(Partition);
        var label = strings_1.toUtf8Bytes(strings_1.nameprep(partition[3]));
        result = keccak256_1.keccak256(bytes_1.concat([result, keccak256_1.keccak256(label)]));
        name = partition[2] || "";
    }
    return bytes_1.hexlify(result);
}
exports.namehash = namehash;

@ethersproject/keccak256

The keccak256 hash function for ethers.

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis

Popular @ethersproject/keccak256 functions