Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
// 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) {
// 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) {
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 {
}
}
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(); }
}
}
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", {
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);
}
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]");
}
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);
}
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 {