@ethersproject/abstract-signer
Advanced tools
Comparing version 5.0.0-beta.121 to 5.0.0-beta.122
import { BlockTag, Provider, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider"; | ||
import { BigNumber } from "@ethersproject/bignumber"; | ||
import { Bytes } from "@ethersproject/bytes"; | ||
export interface ExternallyOwnedAccount { | ||
readonly address: string; | ||
readonly privateKey: string; | ||
readonly mnemonic?: string; | ||
readonly path?: string; | ||
} | ||
export declare abstract class Signer { | ||
@@ -18,4 +24,13 @@ readonly provider?: Provider; | ||
populateTransaction(transaction: TransactionRequest): Promise<TransactionRequest>; | ||
_checkProvider(): void; | ||
_checkProvider(operation?: string): void; | ||
static isSigner(value: any): value is Signer; | ||
} | ||
export declare class VoidSigner extends Signer { | ||
readonly address: string; | ||
constructor(address: string, provider: Provider); | ||
getAddress(): Promise<string>; | ||
_fail(message: string, operation: string): Promise<any>; | ||
signMessage(message: Bytes | string): Promise<string>; | ||
signTransaction(transaction: TransactionRequest): Promise<string>; | ||
connect(provider: Provider): VoidSigner; | ||
} |
71
index.js
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var errors = __importStar(require("@ethersproject/errors")); | ||
var properties_1 = require("@ethersproject/properties"); | ||
@@ -16,7 +37,7 @@ var allowedTransactionKeys = [ | ||
Signer.prototype.getBalance = function (blockTag) { | ||
this._checkProvider(); | ||
this._checkProvider("getBalance"); | ||
return this.provider.getBalance(this.getAddress(), blockTag); | ||
}; | ||
Signer.prototype.getTransactionCount = function (blockTag) { | ||
this._checkProvider(); | ||
this._checkProvider("getTransactionCount"); | ||
return this.provider.getTransactionCount(this.getAddress(), blockTag); | ||
@@ -27,3 +48,3 @@ }; | ||
var _this = this; | ||
this._checkProvider(); | ||
this._checkProvider("estimateGas"); | ||
return this.checkTransaction(transaction).then(function (tx) { | ||
@@ -36,3 +57,3 @@ return _this.provider.estimateGas(tx); | ||
var _this = this; | ||
this._checkProvider(); | ||
this._checkProvider("call"); | ||
return this.checkTransaction(transaction).then(function (tx) { | ||
@@ -45,3 +66,3 @@ return _this.provider.call(tx); | ||
var _this = this; | ||
this._checkProvider(); | ||
this._checkProvider("sendTransaction"); | ||
return this.populateTransaction(transaction).then(function (tx) { | ||
@@ -61,3 +82,3 @@ return _this.signTransaction(tx).then(function (signedTx) { | ||
if (allowedTransactionKeys.indexOf(key) === -1) { | ||
throw new Error("invlaid transaction key: " + key); | ||
errors.throwArgumentError("invlaid transaction key: " + key, "transaction", transaction); | ||
} | ||
@@ -76,3 +97,3 @@ } | ||
var _this = this; | ||
this._checkProvider(); | ||
this._checkProvider("populateTransaction"); | ||
return this.checkTransaction(transaction).then(function (tx) { | ||
@@ -98,3 +119,3 @@ if (tx.to != null) { | ||
if (results[0] !== results[1]) { | ||
throw new Error("from address mismatch"); | ||
errors.throwArgumentError("from address mismatch", "transaction", transaction); | ||
} | ||
@@ -115,6 +136,8 @@ return results[0]; | ||
// Sub-classes SHOULD leave these alone | ||
Signer.prototype._checkProvider = function () { | ||
Signer.prototype._checkProvider = function (operation) { | ||
// @TODO: errors.throwError | ||
if (!this.provider) { | ||
throw new Error("missing provider"); | ||
errors.throwError("missing provider", errors.UNSUPPORTED_OPERATION, { | ||
operation: (operation || "_checkProvider") | ||
}); | ||
} | ||
@@ -128,1 +151,29 @@ }; | ||
exports.Signer = Signer; | ||
var VoidSigner = /** @class */ (function (_super) { | ||
__extends(VoidSigner, _super); | ||
function VoidSigner(address, provider) { | ||
var _this = _super.call(this) || this; | ||
properties_1.defineReadOnly(_this, "address", address); | ||
properties_1.defineReadOnly(_this, "provider", provider); | ||
return _this; | ||
} | ||
VoidSigner.prototype.getAddress = function () { | ||
return Promise.resolve(this.address); | ||
}; | ||
VoidSigner.prototype._fail = function (message, operation) { | ||
return Promise.resolve().then(function () { | ||
errors.throwError(message, errors.UNSUPPORTED_OPERATION, { operation: operation }); | ||
}); | ||
}; | ||
VoidSigner.prototype.signMessage = function (message) { | ||
return this._fail("VoidSigner cannot sign messages", "signMessage"); | ||
}; | ||
VoidSigner.prototype.signTransaction = function (transaction) { | ||
return this._fail("VoidSigner cannot sign transactions", "signTransaction"); | ||
}; | ||
VoidSigner.prototype.connect = function (provider) { | ||
return new VoidSigner(this.address, provider); | ||
}; | ||
return VoidSigner; | ||
}(Signer)); | ||
exports.VoidSigner = VoidSigner; |
{ | ||
"name": "@ethersproject/abstract-signer", | ||
"version": "5.0.0-beta.121", | ||
"version": "5.0.0-beta.122", | ||
"description": "Error utility functions for ethers.", | ||
@@ -13,2 +13,3 @@ "main": "index.js", | ||
"@ethersproject/bytes": "^5.0.0-beta.119", | ||
"@ethersproject/errors": "^5.0.0-beta.119", | ||
"@ethersproject/properties": "^5.0.0-beta.119" | ||
@@ -25,3 +26,3 @@ }, | ||
}, | ||
"tarballHash": "0x1e071bc4c087cf50b60949b6276ce42c676042eedebaa1ec0e98e266e8116fe3" | ||
"tarballHash": "0x293d3a2e12de210ba6f31017a59fd4fbb9e9aafd2a9068f9116703323614e666" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10740
205
5
+ Added@ethersproject/errors@5.0.1(transitive)