@waku/rln 0.1.5-1d384f2.0 → 0.1.5-1e590d7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/_virtual/utils.js +2 -2
- package/bundle/_virtual/utils2.js +2 -2
- package/bundle/index.js +2 -1
- package/bundle/packages/rln/dist/contract/constants.js +1 -0
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +66 -61
- package/bundle/packages/rln/dist/contract/rln_contract.js +1 -1
- package/bundle/packages/rln/dist/utils/bytes.js +8 -2
- package/bundle/packages/rln/dist/utils/metamask.js +2 -2
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/index.d.ts +1 -0
- package/dist/contract/index.js +1 -0
- package/dist/contract/index.js.map +1 -1
- package/dist/contract/rln_base_contract.d.ts +5 -11
- package/dist/contract/rln_base_contract.js +64 -59
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/contract/types.d.ts +5 -0
- package/dist/contract/types.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +2 -2
- package/dist/utils/bytes.js +8 -2
- package/dist/utils/bytes.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/index.ts +1 -0
- package/src/contract/rln_base_contract.ts +96 -89
- package/src/contract/types.ts +5 -0
- package/src/index.ts +3 -1
- package/src/keystore/keystore.ts +4 -2
- package/src/keystore/types.ts +2 -2
- package/src/utils/bytes.ts +10 -2
- package/bundle/_virtual/__node-resolve_empty.js +0 -6
- package/bundle/_virtual/_node-resolve_empty.js +0 -3
- package/bundle/_virtual/bn.js +0 -3
- package/bundle/_virtual/common.js +0 -3
- package/bundle/_virtual/common2.js +0 -3
- package/bundle/_virtual/hash.js +0 -3
- package/bundle/_virtual/inherits_browser.js +0 -3
- package/bundle/_virtual/ripemd.js +0 -3
- package/bundle/_virtual/sha.js +0 -3
- package/bundle/_virtual/sha3.js +0 -3
- package/bundle/_virtual/utils3.js +0 -3
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +0 -96
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +0 -148
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +0 -26
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +0 -20
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +0 -210
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +0 -18
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +0 -30
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +0 -26
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +0 -22
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +0 -43
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +0 -19
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +0 -58
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +0 -854
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +0 -609
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +0 -66
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +0 -302
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +0 -110
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +0 -20
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +0 -120
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +0 -287
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +0 -402
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +0 -3
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +0 -8
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +0 -3
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +0 -893
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +0 -256
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +0 -36
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +0 -135
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +0 -8
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +0 -64
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +0 -443
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +0 -8
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +0 -660
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +0 -352
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +0 -248
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +0 -127
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +0 -2007
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +0 -422
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +0 -674
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +0 -132
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +0 -120
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +0 -8
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +0 -2430
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +0 -76
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +0 -219
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +0 -279
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +0 -3
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +0 -69
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +0 -404
- package/bundle/node_modules/bech32/index.js +0 -187
- package/bundle/node_modules/bn.js/lib/bn.js +0 -3361
- package/bundle/node_modules/hash.js/lib/hash/common.js +0 -97
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +0 -51
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +0 -152
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +0 -81
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +0 -33
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +0 -113
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +0 -39
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +0 -336
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +0 -53
- package/bundle/node_modules/hash.js/lib/hash/sha.js +0 -14
- package/bundle/node_modules/hash.js/lib/hash/utils.js +0 -282
- package/bundle/node_modules/hash.js/lib/hash.js +0 -33
- package/bundle/node_modules/inherits/inherits_browser.js +0 -33
- package/bundle/node_modules/minimalistic-assert/index.js +0 -13
@@ -1,674 +0,0 @@
|
|
1
|
-
import { Signer } from '../../abstract-signer/lib.esm/index.js';
|
2
|
-
import { hexZeroPad, hexValue, hexlify, isHexString } from '../../bytes/lib.esm/index.js';
|
3
|
-
import { TypedDataEncoder } from '../../hash/lib.esm/typed-data.js';
|
4
|
-
import { getStatic, defineReadOnly, shallowCopy, deepCopy, checkProperties, resolveProperties } from '../../properties/lib.esm/index.js';
|
5
|
-
import { toUtf8Bytes } from '../../strings/lib.esm/utf8.js';
|
6
|
-
import { accessListify } from '../../transactions/lib.esm/index.js';
|
7
|
-
import { fetchJson, poll } from '../../web/lib.esm/index.js';
|
8
|
-
import { Logger } from '../../logger/lib.esm/index.js';
|
9
|
-
import { version } from './_version.js';
|
10
|
-
import { BaseProvider } from './base-provider.js';
|
11
|
-
import { BigNumber } from '../../bignumber/lib.esm/bignumber.js';
|
12
|
-
|
13
|
-
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
20
|
-
});
|
21
|
-
};
|
22
|
-
const logger = new Logger(version);
|
23
|
-
const errorGas = ["call", "estimateGas"];
|
24
|
-
function spelunk(value, requireData) {
|
25
|
-
if (value == null) {
|
26
|
-
return null;
|
27
|
-
}
|
28
|
-
// These *are* the droids we're looking for.
|
29
|
-
if (typeof (value.message) === "string" && value.message.match("reverted")) {
|
30
|
-
const data = isHexString(value.data) ? value.data : null;
|
31
|
-
if (!requireData || data) {
|
32
|
-
return { message: value.message, data };
|
33
|
-
}
|
34
|
-
}
|
35
|
-
// Spelunk further...
|
36
|
-
if (typeof (value) === "object") {
|
37
|
-
for (const key in value) {
|
38
|
-
const result = spelunk(value[key], requireData);
|
39
|
-
if (result) {
|
40
|
-
return result;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
return null;
|
44
|
-
}
|
45
|
-
// Might be a JSON string we can further descend...
|
46
|
-
if (typeof (value) === "string") {
|
47
|
-
try {
|
48
|
-
return spelunk(JSON.parse(value), requireData);
|
49
|
-
}
|
50
|
-
catch (error) { }
|
51
|
-
}
|
52
|
-
return null;
|
53
|
-
}
|
54
|
-
function checkError(method, error, params) {
|
55
|
-
const transaction = params.transaction || params.signedTransaction;
|
56
|
-
// Undo the "convenience" some nodes are attempting to prevent backwards
|
57
|
-
// incompatibility; maybe for v6 consider forwarding reverts as errors
|
58
|
-
if (method === "call") {
|
59
|
-
const result = spelunk(error, true);
|
60
|
-
if (result) {
|
61
|
-
return result.data;
|
62
|
-
}
|
63
|
-
// Nothing descriptive..
|
64
|
-
logger.throwError("missing revert data in call exception; Transaction reverted without a reason string", Logger.errors.CALL_EXCEPTION, {
|
65
|
-
data: "0x", transaction, error
|
66
|
-
});
|
67
|
-
}
|
68
|
-
if (method === "estimateGas") {
|
69
|
-
// Try to find something, with a preference on SERVER_ERROR body
|
70
|
-
let result = spelunk(error.body, false);
|
71
|
-
if (result == null) {
|
72
|
-
result = spelunk(error, false);
|
73
|
-
}
|
74
|
-
// Found "reverted", this is a CALL_EXCEPTION
|
75
|
-
if (result) {
|
76
|
-
logger.throwError("cannot estimate gas; transaction may fail or may require manual gas limit", Logger.errors.UNPREDICTABLE_GAS_LIMIT, {
|
77
|
-
reason: result.message, method, transaction, error
|
78
|
-
});
|
79
|
-
}
|
80
|
-
}
|
81
|
-
// @TODO: Should we spelunk for message too?
|
82
|
-
let message = error.message;
|
83
|
-
if (error.code === Logger.errors.SERVER_ERROR && error.error && typeof (error.error.message) === "string") {
|
84
|
-
message = error.error.message;
|
85
|
-
}
|
86
|
-
else if (typeof (error.body) === "string") {
|
87
|
-
message = error.body;
|
88
|
-
}
|
89
|
-
else if (typeof (error.responseText) === "string") {
|
90
|
-
message = error.responseText;
|
91
|
-
}
|
92
|
-
message = (message || "").toLowerCase();
|
93
|
-
// "insufficient funds for gas * price + value + cost(data)"
|
94
|
-
if (message.match(/insufficient funds|base fee exceeds gas limit|InsufficientFunds/i)) {
|
95
|
-
logger.throwError("insufficient funds for intrinsic transaction cost", Logger.errors.INSUFFICIENT_FUNDS, {
|
96
|
-
error, method, transaction
|
97
|
-
});
|
98
|
-
}
|
99
|
-
// "nonce too low"
|
100
|
-
if (message.match(/nonce (is )?too low/i)) {
|
101
|
-
logger.throwError("nonce has already been used", Logger.errors.NONCE_EXPIRED, {
|
102
|
-
error, method, transaction
|
103
|
-
});
|
104
|
-
}
|
105
|
-
// "replacement transaction underpriced"
|
106
|
-
if (message.match(/replacement transaction underpriced|transaction gas price.*too low/i)) {
|
107
|
-
logger.throwError("replacement fee too low", Logger.errors.REPLACEMENT_UNDERPRICED, {
|
108
|
-
error, method, transaction
|
109
|
-
});
|
110
|
-
}
|
111
|
-
// "replacement transaction underpriced"
|
112
|
-
if (message.match(/only replay-protected/i)) {
|
113
|
-
logger.throwError("legacy pre-eip-155 transactions not supported", Logger.errors.UNSUPPORTED_OPERATION, {
|
114
|
-
error, method, transaction
|
115
|
-
});
|
116
|
-
}
|
117
|
-
if (errorGas.indexOf(method) >= 0 && message.match(/gas required exceeds allowance|always failing transaction|execution reverted|revert/)) {
|
118
|
-
logger.throwError("cannot estimate gas; transaction may fail or may require manual gas limit", Logger.errors.UNPREDICTABLE_GAS_LIMIT, {
|
119
|
-
error, method, transaction
|
120
|
-
});
|
121
|
-
}
|
122
|
-
throw error;
|
123
|
-
}
|
124
|
-
function timer(timeout) {
|
125
|
-
return new Promise(function (resolve) {
|
126
|
-
setTimeout(resolve, timeout);
|
127
|
-
});
|
128
|
-
}
|
129
|
-
function getResult(payload) {
|
130
|
-
if (payload.error) {
|
131
|
-
// @TODO: not any
|
132
|
-
const error = new Error(payload.error.message);
|
133
|
-
error.code = payload.error.code;
|
134
|
-
error.data = payload.error.data;
|
135
|
-
throw error;
|
136
|
-
}
|
137
|
-
return payload.result;
|
138
|
-
}
|
139
|
-
function getLowerCase(value) {
|
140
|
-
if (value) {
|
141
|
-
return value.toLowerCase();
|
142
|
-
}
|
143
|
-
return value;
|
144
|
-
}
|
145
|
-
const _constructorGuard = {};
|
146
|
-
class JsonRpcSigner extends Signer {
|
147
|
-
constructor(constructorGuard, provider, addressOrIndex) {
|
148
|
-
super();
|
149
|
-
if (constructorGuard !== _constructorGuard) {
|
150
|
-
throw new Error("do not call the JsonRpcSigner constructor directly; use provider.getSigner");
|
151
|
-
}
|
152
|
-
defineReadOnly(this, "provider", provider);
|
153
|
-
if (addressOrIndex == null) {
|
154
|
-
addressOrIndex = 0;
|
155
|
-
}
|
156
|
-
if (typeof (addressOrIndex) === "string") {
|
157
|
-
defineReadOnly(this, "_address", this.provider.formatter.address(addressOrIndex));
|
158
|
-
defineReadOnly(this, "_index", null);
|
159
|
-
}
|
160
|
-
else if (typeof (addressOrIndex) === "number") {
|
161
|
-
defineReadOnly(this, "_index", addressOrIndex);
|
162
|
-
defineReadOnly(this, "_address", null);
|
163
|
-
}
|
164
|
-
else {
|
165
|
-
logger.throwArgumentError("invalid address or index", "addressOrIndex", addressOrIndex);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
connect(provider) {
|
169
|
-
return logger.throwError("cannot alter JSON-RPC Signer connection", Logger.errors.UNSUPPORTED_OPERATION, {
|
170
|
-
operation: "connect"
|
171
|
-
});
|
172
|
-
}
|
173
|
-
connectUnchecked() {
|
174
|
-
return new UncheckedJsonRpcSigner(_constructorGuard, this.provider, this._address || this._index);
|
175
|
-
}
|
176
|
-
getAddress() {
|
177
|
-
if (this._address) {
|
178
|
-
return Promise.resolve(this._address);
|
179
|
-
}
|
180
|
-
return this.provider.send("eth_accounts", []).then((accounts) => {
|
181
|
-
if (accounts.length <= this._index) {
|
182
|
-
logger.throwError("unknown account #" + this._index, Logger.errors.UNSUPPORTED_OPERATION, {
|
183
|
-
operation: "getAddress"
|
184
|
-
});
|
185
|
-
}
|
186
|
-
return this.provider.formatter.address(accounts[this._index]);
|
187
|
-
});
|
188
|
-
}
|
189
|
-
sendUncheckedTransaction(transaction) {
|
190
|
-
transaction = shallowCopy(transaction);
|
191
|
-
const fromAddress = this.getAddress().then((address) => {
|
192
|
-
if (address) {
|
193
|
-
address = address.toLowerCase();
|
194
|
-
}
|
195
|
-
return address;
|
196
|
-
});
|
197
|
-
// The JSON-RPC for eth_sendTransaction uses 90000 gas; if the user
|
198
|
-
// wishes to use this, it is easy to specify explicitly, otherwise
|
199
|
-
// we look it up for them.
|
200
|
-
if (transaction.gasLimit == null) {
|
201
|
-
const estimate = shallowCopy(transaction);
|
202
|
-
estimate.from = fromAddress;
|
203
|
-
transaction.gasLimit = this.provider.estimateGas(estimate);
|
204
|
-
}
|
205
|
-
if (transaction.to != null) {
|
206
|
-
transaction.to = Promise.resolve(transaction.to).then((to) => __awaiter(this, void 0, void 0, function* () {
|
207
|
-
if (to == null) {
|
208
|
-
return null;
|
209
|
-
}
|
210
|
-
const address = yield this.provider.resolveName(to);
|
211
|
-
if (address == null) {
|
212
|
-
logger.throwArgumentError("provided ENS name resolves to null", "tx.to", to);
|
213
|
-
}
|
214
|
-
return address;
|
215
|
-
}));
|
216
|
-
}
|
217
|
-
return resolveProperties({
|
218
|
-
tx: resolveProperties(transaction),
|
219
|
-
sender: fromAddress
|
220
|
-
}).then(({ tx, sender }) => {
|
221
|
-
if (tx.from != null) {
|
222
|
-
if (tx.from.toLowerCase() !== sender) {
|
223
|
-
logger.throwArgumentError("from address mismatch", "transaction", transaction);
|
224
|
-
}
|
225
|
-
}
|
226
|
-
else {
|
227
|
-
tx.from = sender;
|
228
|
-
}
|
229
|
-
const hexTx = this.provider.constructor.hexlifyTransaction(tx, { from: true });
|
230
|
-
return this.provider.send("eth_sendTransaction", [hexTx]).then((hash) => {
|
231
|
-
return hash;
|
232
|
-
}, (error) => {
|
233
|
-
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
234
|
-
logger.throwError("user rejected transaction", Logger.errors.ACTION_REJECTED, {
|
235
|
-
action: "sendTransaction",
|
236
|
-
transaction: tx
|
237
|
-
});
|
238
|
-
}
|
239
|
-
return checkError("sendTransaction", error, hexTx);
|
240
|
-
});
|
241
|
-
});
|
242
|
-
}
|
243
|
-
signTransaction(transaction) {
|
244
|
-
return logger.throwError("signing transactions is unsupported", Logger.errors.UNSUPPORTED_OPERATION, {
|
245
|
-
operation: "signTransaction"
|
246
|
-
});
|
247
|
-
}
|
248
|
-
sendTransaction(transaction) {
|
249
|
-
return __awaiter(this, void 0, void 0, function* () {
|
250
|
-
// This cannot be mined any earlier than any recent block
|
251
|
-
const blockNumber = yield this.provider._getInternalBlockNumber(100 + 2 * this.provider.pollingInterval);
|
252
|
-
// Send the transaction
|
253
|
-
const hash = yield this.sendUncheckedTransaction(transaction);
|
254
|
-
try {
|
255
|
-
// Unfortunately, JSON-RPC only provides and opaque transaction hash
|
256
|
-
// for a response, and we need the actual transaction, so we poll
|
257
|
-
// for it; it should show up very quickly
|
258
|
-
return yield poll(() => __awaiter(this, void 0, void 0, function* () {
|
259
|
-
const tx = yield this.provider.getTransaction(hash);
|
260
|
-
if (tx === null) {
|
261
|
-
return undefined;
|
262
|
-
}
|
263
|
-
return this.provider._wrapTransaction(tx, hash, blockNumber);
|
264
|
-
}), { oncePoll: this.provider });
|
265
|
-
}
|
266
|
-
catch (error) {
|
267
|
-
error.transactionHash = hash;
|
268
|
-
throw error;
|
269
|
-
}
|
270
|
-
});
|
271
|
-
}
|
272
|
-
signMessage(message) {
|
273
|
-
return __awaiter(this, void 0, void 0, function* () {
|
274
|
-
const data = ((typeof (message) === "string") ? toUtf8Bytes(message) : message);
|
275
|
-
const address = yield this.getAddress();
|
276
|
-
try {
|
277
|
-
return yield this.provider.send("personal_sign", [hexlify(data), address.toLowerCase()]);
|
278
|
-
}
|
279
|
-
catch (error) {
|
280
|
-
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
281
|
-
logger.throwError("user rejected signing", Logger.errors.ACTION_REJECTED, {
|
282
|
-
action: "signMessage",
|
283
|
-
from: address,
|
284
|
-
messageData: message
|
285
|
-
});
|
286
|
-
}
|
287
|
-
throw error;
|
288
|
-
}
|
289
|
-
});
|
290
|
-
}
|
291
|
-
_legacySignMessage(message) {
|
292
|
-
return __awaiter(this, void 0, void 0, function* () {
|
293
|
-
const data = ((typeof (message) === "string") ? toUtf8Bytes(message) : message);
|
294
|
-
const address = yield this.getAddress();
|
295
|
-
try {
|
296
|
-
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
|
297
|
-
return yield this.provider.send("eth_sign", [address.toLowerCase(), hexlify(data)]);
|
298
|
-
}
|
299
|
-
catch (error) {
|
300
|
-
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
301
|
-
logger.throwError("user rejected signing", Logger.errors.ACTION_REJECTED, {
|
302
|
-
action: "_legacySignMessage",
|
303
|
-
from: address,
|
304
|
-
messageData: message
|
305
|
-
});
|
306
|
-
}
|
307
|
-
throw error;
|
308
|
-
}
|
309
|
-
});
|
310
|
-
}
|
311
|
-
_signTypedData(domain, types, value) {
|
312
|
-
return __awaiter(this, void 0, void 0, function* () {
|
313
|
-
// Populate any ENS names (in-place)
|
314
|
-
const populated = yield TypedDataEncoder.resolveNames(domain, types, value, (name) => {
|
315
|
-
return this.provider.resolveName(name);
|
316
|
-
});
|
317
|
-
const address = yield this.getAddress();
|
318
|
-
try {
|
319
|
-
return yield this.provider.send("eth_signTypedData_v4", [
|
320
|
-
address.toLowerCase(),
|
321
|
-
JSON.stringify(TypedDataEncoder.getPayload(populated.domain, types, populated.value))
|
322
|
-
]);
|
323
|
-
}
|
324
|
-
catch (error) {
|
325
|
-
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
326
|
-
logger.throwError("user rejected signing", Logger.errors.ACTION_REJECTED, {
|
327
|
-
action: "_signTypedData",
|
328
|
-
from: address,
|
329
|
-
messageData: { domain: populated.domain, types, value: populated.value }
|
330
|
-
});
|
331
|
-
}
|
332
|
-
throw error;
|
333
|
-
}
|
334
|
-
});
|
335
|
-
}
|
336
|
-
unlock(password) {
|
337
|
-
return __awaiter(this, void 0, void 0, function* () {
|
338
|
-
const provider = this.provider;
|
339
|
-
const address = yield this.getAddress();
|
340
|
-
return provider.send("personal_unlockAccount", [address.toLowerCase(), password, null]);
|
341
|
-
});
|
342
|
-
}
|
343
|
-
}
|
344
|
-
class UncheckedJsonRpcSigner extends JsonRpcSigner {
|
345
|
-
sendTransaction(transaction) {
|
346
|
-
return this.sendUncheckedTransaction(transaction).then((hash) => {
|
347
|
-
return {
|
348
|
-
hash: hash,
|
349
|
-
nonce: null,
|
350
|
-
gasLimit: null,
|
351
|
-
gasPrice: null,
|
352
|
-
data: null,
|
353
|
-
value: null,
|
354
|
-
chainId: null,
|
355
|
-
confirmations: 0,
|
356
|
-
from: null,
|
357
|
-
wait: (confirmations) => { return this.provider.waitForTransaction(hash, confirmations); }
|
358
|
-
};
|
359
|
-
});
|
360
|
-
}
|
361
|
-
}
|
362
|
-
const allowedTransactionKeys = {
|
363
|
-
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true,
|
364
|
-
type: true, accessList: true,
|
365
|
-
maxFeePerGas: true, maxPriorityFeePerGas: true
|
366
|
-
};
|
367
|
-
class JsonRpcProvider extends BaseProvider {
|
368
|
-
constructor(url, network) {
|
369
|
-
let networkOrReady = network;
|
370
|
-
// The network is unknown, query the JSON-RPC for it
|
371
|
-
if (networkOrReady == null) {
|
372
|
-
networkOrReady = new Promise((resolve, reject) => {
|
373
|
-
setTimeout(() => {
|
374
|
-
this.detectNetwork().then((network) => {
|
375
|
-
resolve(network);
|
376
|
-
}, (error) => {
|
377
|
-
reject(error);
|
378
|
-
});
|
379
|
-
}, 0);
|
380
|
-
});
|
381
|
-
}
|
382
|
-
super(networkOrReady);
|
383
|
-
// Default URL
|
384
|
-
if (!url) {
|
385
|
-
url = getStatic(this.constructor, "defaultUrl")();
|
386
|
-
}
|
387
|
-
if (typeof (url) === "string") {
|
388
|
-
defineReadOnly(this, "connection", Object.freeze({
|
389
|
-
url: url
|
390
|
-
}));
|
391
|
-
}
|
392
|
-
else {
|
393
|
-
defineReadOnly(this, "connection", Object.freeze(shallowCopy(url)));
|
394
|
-
}
|
395
|
-
this._nextId = 42;
|
396
|
-
}
|
397
|
-
get _cache() {
|
398
|
-
if (this._eventLoopCache == null) {
|
399
|
-
this._eventLoopCache = {};
|
400
|
-
}
|
401
|
-
return this._eventLoopCache;
|
402
|
-
}
|
403
|
-
static defaultUrl() {
|
404
|
-
return "http:/\/localhost:8545";
|
405
|
-
}
|
406
|
-
detectNetwork() {
|
407
|
-
if (!this._cache["detectNetwork"]) {
|
408
|
-
this._cache["detectNetwork"] = this._uncachedDetectNetwork();
|
409
|
-
// Clear this cache at the beginning of the next event loop
|
410
|
-
setTimeout(() => {
|
411
|
-
this._cache["detectNetwork"] = null;
|
412
|
-
}, 0);
|
413
|
-
}
|
414
|
-
return this._cache["detectNetwork"];
|
415
|
-
}
|
416
|
-
_uncachedDetectNetwork() {
|
417
|
-
return __awaiter(this, void 0, void 0, function* () {
|
418
|
-
yield timer(0);
|
419
|
-
let chainId = null;
|
420
|
-
try {
|
421
|
-
chainId = yield this.send("eth_chainId", []);
|
422
|
-
}
|
423
|
-
catch (error) {
|
424
|
-
try {
|
425
|
-
chainId = yield this.send("net_version", []);
|
426
|
-
}
|
427
|
-
catch (error) { }
|
428
|
-
}
|
429
|
-
if (chainId != null) {
|
430
|
-
const getNetwork = getStatic(this.constructor, "getNetwork");
|
431
|
-
try {
|
432
|
-
return getNetwork(BigNumber.from(chainId).toNumber());
|
433
|
-
}
|
434
|
-
catch (error) {
|
435
|
-
return logger.throwError("could not detect network", Logger.errors.NETWORK_ERROR, {
|
436
|
-
chainId: chainId,
|
437
|
-
event: "invalidNetwork",
|
438
|
-
serverError: error
|
439
|
-
});
|
440
|
-
}
|
441
|
-
}
|
442
|
-
return logger.throwError("could not detect network", Logger.errors.NETWORK_ERROR, {
|
443
|
-
event: "noNetwork"
|
444
|
-
});
|
445
|
-
});
|
446
|
-
}
|
447
|
-
getSigner(addressOrIndex) {
|
448
|
-
return new JsonRpcSigner(_constructorGuard, this, addressOrIndex);
|
449
|
-
}
|
450
|
-
getUncheckedSigner(addressOrIndex) {
|
451
|
-
return this.getSigner(addressOrIndex).connectUnchecked();
|
452
|
-
}
|
453
|
-
listAccounts() {
|
454
|
-
return this.send("eth_accounts", []).then((accounts) => {
|
455
|
-
return accounts.map((a) => this.formatter.address(a));
|
456
|
-
});
|
457
|
-
}
|
458
|
-
send(method, params) {
|
459
|
-
const request = {
|
460
|
-
method: method,
|
461
|
-
params: params,
|
462
|
-
id: (this._nextId++),
|
463
|
-
jsonrpc: "2.0"
|
464
|
-
};
|
465
|
-
this.emit("debug", {
|
466
|
-
action: "request",
|
467
|
-
request: deepCopy(request),
|
468
|
-
provider: this
|
469
|
-
});
|
470
|
-
// We can expand this in the future to any call, but for now these
|
471
|
-
// are the biggest wins and do not require any serializing parameters.
|
472
|
-
const cache = (["eth_chainId", "eth_blockNumber"].indexOf(method) >= 0);
|
473
|
-
if (cache && this._cache[method]) {
|
474
|
-
return this._cache[method];
|
475
|
-
}
|
476
|
-
const result = fetchJson(this.connection, JSON.stringify(request), getResult).then((result) => {
|
477
|
-
this.emit("debug", {
|
478
|
-
action: "response",
|
479
|
-
request: request,
|
480
|
-
response: result,
|
481
|
-
provider: this
|
482
|
-
});
|
483
|
-
return result;
|
484
|
-
}, (error) => {
|
485
|
-
this.emit("debug", {
|
486
|
-
action: "response",
|
487
|
-
error: error,
|
488
|
-
request: request,
|
489
|
-
provider: this
|
490
|
-
});
|
491
|
-
throw error;
|
492
|
-
});
|
493
|
-
// Cache the fetch, but clear it on the next event loop
|
494
|
-
if (cache) {
|
495
|
-
this._cache[method] = result;
|
496
|
-
setTimeout(() => {
|
497
|
-
this._cache[method] = null;
|
498
|
-
}, 0);
|
499
|
-
}
|
500
|
-
return result;
|
501
|
-
}
|
502
|
-
prepareRequest(method, params) {
|
503
|
-
switch (method) {
|
504
|
-
case "getBlockNumber":
|
505
|
-
return ["eth_blockNumber", []];
|
506
|
-
case "getGasPrice":
|
507
|
-
return ["eth_gasPrice", []];
|
508
|
-
case "getBalance":
|
509
|
-
return ["eth_getBalance", [getLowerCase(params.address), params.blockTag]];
|
510
|
-
case "getTransactionCount":
|
511
|
-
return ["eth_getTransactionCount", [getLowerCase(params.address), params.blockTag]];
|
512
|
-
case "getCode":
|
513
|
-
return ["eth_getCode", [getLowerCase(params.address), params.blockTag]];
|
514
|
-
case "getStorageAt":
|
515
|
-
return ["eth_getStorageAt", [getLowerCase(params.address), hexZeroPad(params.position, 32), params.blockTag]];
|
516
|
-
case "sendTransaction":
|
517
|
-
return ["eth_sendRawTransaction", [params.signedTransaction]];
|
518
|
-
case "getBlock":
|
519
|
-
if (params.blockTag) {
|
520
|
-
return ["eth_getBlockByNumber", [params.blockTag, !!params.includeTransactions]];
|
521
|
-
}
|
522
|
-
else if (params.blockHash) {
|
523
|
-
return ["eth_getBlockByHash", [params.blockHash, !!params.includeTransactions]];
|
524
|
-
}
|
525
|
-
return null;
|
526
|
-
case "getTransaction":
|
527
|
-
return ["eth_getTransactionByHash", [params.transactionHash]];
|
528
|
-
case "getTransactionReceipt":
|
529
|
-
return ["eth_getTransactionReceipt", [params.transactionHash]];
|
530
|
-
case "call": {
|
531
|
-
const hexlifyTransaction = getStatic(this.constructor, "hexlifyTransaction");
|
532
|
-
return ["eth_call", [hexlifyTransaction(params.transaction, { from: true }), params.blockTag]];
|
533
|
-
}
|
534
|
-
case "estimateGas": {
|
535
|
-
const hexlifyTransaction = getStatic(this.constructor, "hexlifyTransaction");
|
536
|
-
return ["eth_estimateGas", [hexlifyTransaction(params.transaction, { from: true })]];
|
537
|
-
}
|
538
|
-
case "getLogs":
|
539
|
-
if (params.filter && params.filter.address != null) {
|
540
|
-
params.filter.address = getLowerCase(params.filter.address);
|
541
|
-
}
|
542
|
-
return ["eth_getLogs", [params.filter]];
|
543
|
-
}
|
544
|
-
return null;
|
545
|
-
}
|
546
|
-
perform(method, params) {
|
547
|
-
return __awaiter(this, void 0, void 0, function* () {
|
548
|
-
// Legacy networks do not like the type field being passed along (which
|
549
|
-
// is fair), so we delete type if it is 0 and a non-EIP-1559 network
|
550
|
-
if (method === "call" || method === "estimateGas") {
|
551
|
-
const tx = params.transaction;
|
552
|
-
if (tx && tx.type != null && BigNumber.from(tx.type).isZero()) {
|
553
|
-
// If there are no EIP-1559 properties, it might be non-EIP-1559
|
554
|
-
if (tx.maxFeePerGas == null && tx.maxPriorityFeePerGas == null) {
|
555
|
-
const feeData = yield this.getFeeData();
|
556
|
-
if (feeData.maxFeePerGas == null && feeData.maxPriorityFeePerGas == null) {
|
557
|
-
// Network doesn't know about EIP-1559 (and hence type)
|
558
|
-
params = shallowCopy(params);
|
559
|
-
params.transaction = shallowCopy(tx);
|
560
|
-
delete params.transaction.type;
|
561
|
-
}
|
562
|
-
}
|
563
|
-
}
|
564
|
-
}
|
565
|
-
const args = this.prepareRequest(method, params);
|
566
|
-
if (args == null) {
|
567
|
-
logger.throwError(method + " not implemented", Logger.errors.NOT_IMPLEMENTED, { operation: method });
|
568
|
-
}
|
569
|
-
try {
|
570
|
-
return yield this.send(args[0], args[1]);
|
571
|
-
}
|
572
|
-
catch (error) {
|
573
|
-
return checkError(method, error, params);
|
574
|
-
}
|
575
|
-
});
|
576
|
-
}
|
577
|
-
_startEvent(event) {
|
578
|
-
if (event.tag === "pending") {
|
579
|
-
this._startPending();
|
580
|
-
}
|
581
|
-
super._startEvent(event);
|
582
|
-
}
|
583
|
-
_startPending() {
|
584
|
-
if (this._pendingFilter != null) {
|
585
|
-
return;
|
586
|
-
}
|
587
|
-
const self = this;
|
588
|
-
const pendingFilter = this.send("eth_newPendingTransactionFilter", []);
|
589
|
-
this._pendingFilter = pendingFilter;
|
590
|
-
pendingFilter.then(function (filterId) {
|
591
|
-
function poll() {
|
592
|
-
self.send("eth_getFilterChanges", [filterId]).then(function (hashes) {
|
593
|
-
if (self._pendingFilter != pendingFilter) {
|
594
|
-
return null;
|
595
|
-
}
|
596
|
-
let seq = Promise.resolve();
|
597
|
-
hashes.forEach(function (hash) {
|
598
|
-
// @TODO: This should be garbage collected at some point... How? When?
|
599
|
-
self._emitted["t:" + hash.toLowerCase()] = "pending";
|
600
|
-
seq = seq.then(function () {
|
601
|
-
return self.getTransaction(hash).then(function (tx) {
|
602
|
-
self.emit("pending", tx);
|
603
|
-
return null;
|
604
|
-
});
|
605
|
-
});
|
606
|
-
});
|
607
|
-
return seq.then(function () {
|
608
|
-
return timer(1000);
|
609
|
-
});
|
610
|
-
}).then(function () {
|
611
|
-
if (self._pendingFilter != pendingFilter) {
|
612
|
-
self.send("eth_uninstallFilter", [filterId]);
|
613
|
-
return;
|
614
|
-
}
|
615
|
-
setTimeout(function () { poll(); }, 0);
|
616
|
-
return null;
|
617
|
-
}).catch((error) => { });
|
618
|
-
}
|
619
|
-
poll();
|
620
|
-
return filterId;
|
621
|
-
}).catch((error) => { });
|
622
|
-
}
|
623
|
-
_stopEvent(event) {
|
624
|
-
if (event.tag === "pending" && this.listenerCount("pending") === 0) {
|
625
|
-
this._pendingFilter = null;
|
626
|
-
}
|
627
|
-
super._stopEvent(event);
|
628
|
-
}
|
629
|
-
// Convert an ethers.js transaction into a JSON-RPC transaction
|
630
|
-
// - gasLimit => gas
|
631
|
-
// - All values hexlified
|
632
|
-
// - All numeric values zero-striped
|
633
|
-
// - All addresses are lowercased
|
634
|
-
// NOTE: This allows a TransactionRequest, but all values should be resolved
|
635
|
-
// before this is called
|
636
|
-
// @TODO: This will likely be removed in future versions and prepareRequest
|
637
|
-
// will be the preferred method for this.
|
638
|
-
static hexlifyTransaction(transaction, allowExtra) {
|
639
|
-
// Check only allowed properties are given
|
640
|
-
const allowed = shallowCopy(allowedTransactionKeys);
|
641
|
-
if (allowExtra) {
|
642
|
-
for (const key in allowExtra) {
|
643
|
-
if (allowExtra[key]) {
|
644
|
-
allowed[key] = true;
|
645
|
-
}
|
646
|
-
}
|
647
|
-
}
|
648
|
-
checkProperties(transaction, allowed);
|
649
|
-
const result = {};
|
650
|
-
// JSON-RPC now requires numeric values to be "quantity" values
|
651
|
-
["chainId", "gasLimit", "gasPrice", "type", "maxFeePerGas", "maxPriorityFeePerGas", "nonce", "value"].forEach(function (key) {
|
652
|
-
if (transaction[key] == null) {
|
653
|
-
return;
|
654
|
-
}
|
655
|
-
const value = hexValue(BigNumber.from(transaction[key]));
|
656
|
-
if (key === "gasLimit") {
|
657
|
-
key = "gas";
|
658
|
-
}
|
659
|
-
result[key] = value;
|
660
|
-
});
|
661
|
-
["from", "to", "data"].forEach(function (key) {
|
662
|
-
if (transaction[key] == null) {
|
663
|
-
return;
|
664
|
-
}
|
665
|
-
result[key] = hexlify(transaction[key]);
|
666
|
-
});
|
667
|
-
if (transaction.accessList) {
|
668
|
-
result["accessList"] = accessListify(transaction.accessList);
|
669
|
-
}
|
670
|
-
return result;
|
671
|
-
}
|
672
|
-
}
|
673
|
-
|
674
|
-
export { JsonRpcProvider, JsonRpcSigner };
|