Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(addressOrName, contractInterface, signerOrProvider) {
logger.checkNew(new.target, Contract);
// @TODO: Maybe still check the addressOrName looks like a valid address or name?
//address = getAddress(address);
defineReadOnly(this, "interface", getStatic((new.target), "getInterface")(contractInterface));
if (Signer.isSigner(signerOrProvider)) {
defineReadOnly(this, "provider", signerOrProvider.provider || null);
defineReadOnly(this, "signer", signerOrProvider);
}
else if (Provider.isProvider(signerOrProvider)) {
defineReadOnly(this, "provider", signerOrProvider);
defineReadOnly(this, "signer", null);
}
else {
logger.throwArgumentError("invalid signer or provider", "signerOrProvider", signerOrProvider);
}
defineReadOnly(this, "callStatic", {});
defineReadOnly(this, "estimate", {});
defineReadOnly(this, "functions", {});
defineReadOnly(this, "populateTransaction", {});
defineReadOnly(this, "filters", {});
{
const uniqueFilters = {};
Object.keys(this.interface.events).forEach((eventSignature) => {
let event = this.interface.events[eventSignature];
defineReadOnly(this.filters, eventSignature, (...args) => {
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 {
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);
}
const checkSignerType = (signerOrProvider: Signer | Provider) => {
if (!signerOrProvider) {
throw Error('signerOrProvider argument is undefined')
}
if (
!Provider.isProvider(signerOrProvider) &&
!Signer.isSigner(signerOrProvider)
) {
throw Error('signerOrProvider argument is the wrong type')
}
}