How to use the @ethersproject/signing-key.SigningKey function in @ethersproject/signing-key

To help you get started, we’ve selected a few @ethersproject/signing-key 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 / hdnode / src.ts / index.ts View on Github external
for (let i = 24; i >= 0; i -= 8) { data[33 + (i >> 3)] = ((index >> (24 - i)) & 0xff); }

        const I = arrayify(computeHmac(SupportedAlgorithms.sha512, this.chainCode, data));
        const IL = I.slice(0, 32);
        const IR = I.slice(32);

        // The private key
        let ki: string = null

        // The public key
        let Ki: string = null;

        if (this.privateKey) {
            ki = bytes32(BigNumber.from(IL).add(this.privateKey).mod(N));
        } else {
            const ek = new SigningKey(hexlify(IL));
            Ki = ek._addPoint(this.publicKey);
        }

        return new HDNode(_constructorGuard, ki, Ki, this.fingerprint, bytes32(IR), index, this.depth + 1, this.mnemonic, path);
    }
github ethers-io / ethers.js / packages / hdnode / lib.esm / index.js View on Github external
// Data += ser_32(i)
        for (let i = 24; i >= 0; i -= 8) {
            data[33 + (i >> 3)] = ((index >> (24 - i)) & 0xff);
        }
        const I = arrayify(computeHmac(SupportedAlgorithms.sha512, this.chainCode, data));
        const IL = I.slice(0, 32);
        const IR = I.slice(32);
        // The private key
        let ki = null;
        // The public key
        let Ki = null;
        if (this.privateKey) {
            ki = bytes32(BigNumber.from(IL).add(this.privateKey).mod(N));
        }
        else {
            const ek = new SigningKey(hexlify(IL));
            Ki = ek._addPoint(this.publicKey);
        }
        return new HDNode(_constructorGuard, ki, Ki, this.fingerprint, bytes32(IR), index, this.depth + 1, this.mnemonic, path);
    }
    derivePath(path) {
github ethers-io / ethers.js / packages / hdnode / lib / index.js View on Github external
// Data += ser_32(i)
        for (var i = 24; i >= 0; i -= 8) {
            data[33 + (i >> 3)] = ((index >> (24 - i)) & 0xff);
        }
        var I = bytes_1.arrayify(sha2_1.computeHmac(sha2_1.SupportedAlgorithms.sha512, this.chainCode, data));
        var IL = I.slice(0, 32);
        var IR = I.slice(32);
        // The private key
        var ki = null;
        // The public key
        var Ki = null;
        if (this.privateKey) {
            ki = bytes32(bignumber_1.BigNumber.from(IL).add(this.privateKey).mod(N));
        }
        else {
            var ek = new signing_key_1.SigningKey(bytes_1.hexlify(IL));
            Ki = ek._addPoint(this.publicKey);
        }
        return new HDNode(_constructorGuard, ki, Ki, this.fingerprint, bytes32(IR), index, this.depth + 1, this.mnemonic, path);
    };
    HDNode.prototype.derivePath = function (path) {
github ethers-io / ethers.js / packages / wallet / index.js View on Github external
function Wallet(privateKey, provider) {
        var _newTarget = this.constructor;
        var _this = this;
        logger.checkNew(_newTarget, Wallet);
        _this = _super.call(this) || this;
        if (isAccount(privateKey)) {
            var signingKey_1 = new signing_key_1.SigningKey(privateKey.privateKey);
            properties_1.defineReadOnly(_this, "_signingKey", function () { return signingKey_1; });
            properties_1.defineReadOnly(_this, "address", transactions_1.computeAddress(_this.publicKey));
            if (_this.address !== address_1.getAddress(privateKey.address)) {
                logger.throwArgumentError("privateKey/address mismatch", "privateKey", "[REDCACTED]");
            }
            if (privateKey.mnemonic != null) {
                var mnemonic_1 = privateKey.mnemonic;
                var path = privateKey.path || hdnode_1.defaultPath;
                properties_1.defineReadOnly(_this, "_mnemonic", function () { return mnemonic_1; });
                properties_1.defineReadOnly(_this, "path", privateKey.path);
                var node = hdnode_1.HDNode.fromMnemonic(mnemonic_1).derivePath(path);
                if (transactions_1.computeAddress(node.privateKey) !== _this.address) {
                    logger.throwArgumentError("mnemonic/address mismatch", "privateKey", "[REDCACTED]");
                }
            }
            else {
github ethers-io / ethers.js / packages / wallet / lib.esm / index.js View on Github external
}
            }
            else {
                defineReadOnly(this, "_mnemonic", () => null);
                defineReadOnly(this, "path", null);
            }
        }
        else {
            if (SigningKey.isSigningKey(privateKey)) {
                if (privateKey.curve !== "secp256k1") {
                    logger.throwArgumentError("unsupported curve; must be secp256k1", "privateKey", "[REDACTED]");
                }
                defineReadOnly(this, "_signingKey", () => privateKey);
            }
            else {
                const signingKey = new SigningKey(privateKey);
                defineReadOnly(this, "_signingKey", () => signingKey);
            }
            defineReadOnly(this, "_mnemonic", () => null);
            defineReadOnly(this, "path", null);
            defineReadOnly(this, "address", computeAddress(this.publicKey));
        }
        if (provider && !Provider.isProvider(provider)) {
            logger.throwArgumentError("invalid provider", "provider", provider);
        }
        defineReadOnly(this, "provider", provider || null);
    }
    get mnemonic() { return this._mnemonic(); }
github ethers-io / ethers.js / packages / wallet / index.js View on Github external
}
            }
            else {
                properties_1.defineReadOnly(_this, "_mnemonic", function () { return null; });
                properties_1.defineReadOnly(_this, "path", null);
            }
        }
        else {
            if (signing_key_1.SigningKey.isSigningKey(privateKey)) {
                if (privateKey.curve !== "secp256k1") {
                    logger.throwArgumentError("unsupported curve; must be secp256k1", "privateKey", "[REDACTED]");
                }
                properties_1.defineReadOnly(_this, "_signingKey", function () { return privateKey; });
            }
            else {
                var signingKey_2 = new signing_key_1.SigningKey(privateKey);
                properties_1.defineReadOnly(_this, "_signingKey", function () { return signingKey_2; });
            }
            properties_1.defineReadOnly(_this, "_mnemonic", function () { return null; });
            properties_1.defineReadOnly(_this, "path", null);
            properties_1.defineReadOnly(_this, "address", transactions_1.computeAddress(_this.publicKey));
        }
        if (provider && !abstract_provider_1.Provider.isProvider(provider)) {
            logger.throwArgumentError("invalid provider", "provider", provider);
        }
        properties_1.defineReadOnly(_this, "provider", provider || null);
        return _this;
    }
    Object.defineProperty(Wallet.prototype, "mnemonic", {
github ethers-io / ethers.js / packages / wallet / src.ts / index.ts View on Github external
logger.throwArgumentError("mnemonic/address mismatch", "privateKey", "[REDCACTED]");
                }
            } else {
                defineReadOnly(this, "_mnemonic", (): string => null);
                defineReadOnly(this, "path", null);
            }


        } else {
            if (SigningKey.isSigningKey(privateKey)) {
                if (privateKey.curve !== "secp256k1") {
                    logger.throwArgumentError("unsupported curve; must be secp256k1", "privateKey", "[REDACTED]");
                }
                defineReadOnly(this, "_signingKey", () => privateKey);
            } else {
                const signingKey = new SigningKey(privateKey);
                defineReadOnly(this, "_signingKey", () => signingKey);
            }
            defineReadOnly(this, "_mnemonic", (): string => null);
            defineReadOnly(this, "path", null);
            defineReadOnly(this, "address", computeAddress(this.publicKey));
        }

        if (provider && !Provider.isProvider(provider)) {
            logger.throwArgumentError("invalid provider", "provider", provider);
        }

        defineReadOnly(this, "provider", provider || null);
    }
github ethers-io / ethers.js / packages / wallet / src.ts / index.ts View on Github external
constructor(privateKey: BytesLike | ExternallyOwnedAccount | SigningKey, provider?: Provider) {
        logger.checkNew(new.target, Wallet);

        super();

        if (isAccount(privateKey)) {
            const signingKey = new SigningKey(privateKey.privateKey);
            defineReadOnly(this, "_signingKey", () => signingKey);
            defineReadOnly(this, "address", computeAddress(this.publicKey));

            if (this.address !== getAddress(privateKey.address)) {
                logger.throwArgumentError("privateKey/address mismatch", "privateKey", "[REDCACTED]");
            }

            if (privateKey.mnemonic != null) {
                const mnemonic = privateKey.mnemonic;
                const path = privateKey.path || defaultPath;
                defineReadOnly(this, "_mnemonic", () => mnemonic);
                defineReadOnly(this, "path", privateKey.path);
                const node = HDNode.fromMnemonic(mnemonic).derivePath(path);
                if (computeAddress(node.privateKey) !== this.address) {
                    logger.throwArgumentError("mnemonic/address mismatch", "privateKey", "[REDCACTED]");
                }
github ethers-io / ethers.js / packages / hdnode / lib / index.js View on Github external
function HDNode(constructorGuard, privateKey, publicKey, parentFingerprint, chainCode, index, depth, mnemonic, path) {
        var _newTarget = this.constructor;
        logger.checkNew(_newTarget, HDNode);
        if (constructorGuard !== _constructorGuard) {
            throw new Error("HDNode constructor cannot be called directly");
        }
        if (privateKey) {
            var signingKey = new signing_key_1.SigningKey(privateKey);
            properties_1.defineReadOnly(this, "privateKey", signingKey.privateKey);
            properties_1.defineReadOnly(this, "publicKey", signingKey.compressedPublicKey);
        }
        else {
            properties_1.defineReadOnly(this, "privateKey", null);
            properties_1.defineReadOnly(this, "publicKey", bytes_1.hexlify(publicKey));
        }
        properties_1.defineReadOnly(this, "parentFingerprint", parentFingerprint);
        properties_1.defineReadOnly(this, "fingerprint", bytes_1.hexDataSlice(sha2_1.ripemd160(sha2_1.sha256(this.publicKey)), 0, 4));
        properties_1.defineReadOnly(this, "address", transactions_1.computeAddress(this.publicKey));
        properties_1.defineReadOnly(this, "chainCode", chainCode);
        properties_1.defineReadOnly(this, "index", index);
        properties_1.defineReadOnly(this, "depth", depth);
        properties_1.defineReadOnly(this, "mnemonic", mnemonic);
        properties_1.defineReadOnly(this, "path", path);
    }
github ethers-io / ethers.js / packages / wallet / lib.esm / index.js View on Github external
constructor(privateKey, provider) {
        logger.checkNew(new.target, Wallet);
        super();
        if (isAccount(privateKey)) {
            const signingKey = new SigningKey(privateKey.privateKey);
            defineReadOnly(this, "_signingKey", () => signingKey);
            defineReadOnly(this, "address", computeAddress(this.publicKey));
            if (this.address !== getAddress(privateKey.address)) {
                logger.throwArgumentError("privateKey/address mismatch", "privateKey", "[REDCACTED]");
            }
            if (privateKey.mnemonic != null) {
                const mnemonic = privateKey.mnemonic;
                const path = privateKey.path || defaultPath;
                defineReadOnly(this, "_mnemonic", () => mnemonic);
                defineReadOnly(this, "path", privateKey.path);
                const node = HDNode.fromMnemonic(mnemonic).derivePath(path);
                if (computeAddress(node.privateKey) !== this.address) {
                    logger.throwArgumentError("mnemonic/address mismatch", "privateKey", "[REDCACTED]");
                }
            }
            else {

@ethersproject/signing-key

Elliptic curve library functions for the secp256k1 curve.

MIT
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis