quantumcoin 6.14.2 → 6.14.5
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/CHANGELOG.md +442 -442
- package/FUNDING.json +10 -10
- package/LICENSE.md +21 -21
- package/README.md +132 -142
- package/SECURITY.md +34 -34
- package/dist/README.md +22 -22
- package/dist/quantumcoin.js +1127 -1324
- package/dist/quantumcoin.js.map +1 -1
- package/dist/quantumcoin.min.js +1 -1
- package/dist/quantumcoin.umd.js +1128 -1327
- package/dist/quantumcoin.umd.js.map +1 -1
- package/dist/quantumcoin.umd.min.js +1 -1
- package/dist/wordlists-extra.js +1 -1
- package/dist/wordlists-extra.js.map +1 -1
- package/dist/wordlists-extra.min.js +1 -1
- package/lib.commonjs/README.md +16 -16
- package/lib.commonjs/_version.js +1 -1
- package/lib.commonjs/crypto/signature.d.ts +3 -76
- package/lib.commonjs/crypto/signature.d.ts.map +1 -1
- package/lib.commonjs/crypto/signature.js +15 -199
- package/lib.commonjs/crypto/signature.js.map +1 -1
- package/lib.commonjs/crypto/signing-key.d.ts +1 -1
- package/lib.commonjs/crypto/signing-key.d.ts.map +1 -1
- package/lib.commonjs/crypto/signing-key.js +19 -10
- package/lib.commonjs/crypto/signing-key.js.map +1 -1
- package/lib.commonjs/package.json +12 -12
- package/lib.commonjs/providers/provider-jsonrpc.d.ts +0 -1
- package/lib.commonjs/providers/provider-jsonrpc.d.ts.map +1 -1
- package/lib.commonjs/providers/provider-jsonrpc.js +0 -1
- package/lib.commonjs/providers/provider-jsonrpc.js.map +1 -1
- package/lib.commonjs/quantumcoin.d.ts +2 -0
- package/lib.commonjs/quantumcoin.d.ts.map +1 -1
- package/lib.commonjs/quantumcoin.js +11 -5
- package/lib.commonjs/quantumcoin.js.map +1 -1
- package/lib.commonjs/transaction/address.d.ts.map +1 -1
- package/lib.commonjs/transaction/address.js +8 -3
- package/lib.commonjs/transaction/address.js.map +1 -1
- package/lib.commonjs/transaction/transaction.d.ts.map +1 -1
- package/lib.commonjs/transaction/transaction.js +7 -40
- package/lib.commonjs/transaction/transaction.js.map +1 -1
- package/lib.commonjs/wallet/json-keystore.d.ts.map +1 -1
- package/lib.commonjs/wallet/json-keystore.js +7 -7
- package/lib.commonjs/wallet/json-keystore.js.map +1 -1
- package/lib.commonjs/wallet/wallet.d.ts.map +1 -1
- package/lib.commonjs/wallet/wallet.js +2 -2
- package/lib.commonjs/wallet/wallet.js.map +1 -1
- package/lib.esm/README.md +16 -16
- package/lib.esm/_version.js +1 -1
- package/lib.esm/crypto/signature.d.ts +3 -76
- package/lib.esm/crypto/signature.d.ts.map +1 -1
- package/lib.esm/crypto/signature.js +16 -202
- package/lib.esm/crypto/signature.js.map +1 -1
- package/lib.esm/crypto/signing-key.d.ts +1 -1
- package/lib.esm/crypto/signing-key.d.ts.map +1 -1
- package/lib.esm/crypto/signing-key.js +20 -9
- package/lib.esm/crypto/signing-key.js.map +1 -1
- package/lib.esm/package.json +12 -12
- package/lib.esm/providers/provider-jsonrpc.d.ts +0 -1
- package/lib.esm/providers/provider-jsonrpc.d.ts.map +1 -1
- package/lib.esm/providers/provider-jsonrpc.js +0 -1
- package/lib.esm/providers/provider-jsonrpc.js.map +1 -1
- package/lib.esm/quantumcoin.d.ts +2 -0
- package/lib.esm/quantumcoin.d.ts.map +1 -1
- package/lib.esm/quantumcoin.js +6 -0
- package/lib.esm/quantumcoin.js.map +1 -1
- package/lib.esm/transaction/address.d.ts.map +1 -1
- package/lib.esm/transaction/address.js +8 -2
- package/lib.esm/transaction/address.js.map +1 -1
- package/lib.esm/transaction/transaction.d.ts.map +1 -1
- package/lib.esm/transaction/transaction.js +7 -40
- package/lib.esm/transaction/transaction.js.map +1 -1
- package/lib.esm/wallet/json-keystore.d.ts.map +1 -1
- package/lib.esm/wallet/json-keystore.js +11 -5
- package/lib.esm/wallet/json-keystore.js.map +1 -1
- package/lib.esm/wallet/wallet.d.ts.map +1 -1
- package/lib.esm/wallet/wallet.js +3 -1
- package/lib.esm/wallet/wallet.js.map +1 -1
- package/package.json +6 -5
- package/rollup.config.mjs +50 -50
- package/src.ts/_version.ts +1 -1
- package/src.ts/abi/abi-coder.ts +237 -237
- package/src.ts/abi/bytes32.ts +45 -45
- package/src.ts/abi/coders/abstract-coder.ts +541 -541
- package/src.ts/abi/coders/address.ts +36 -36
- package/src.ts/abi/coders/anonymous.ts +29 -29
- package/src.ts/abi/coders/array.ts +199 -199
- package/src.ts/abi/coders/boolean.ts +27 -27
- package/src.ts/abi/coders/bytes.ts +43 -43
- package/src.ts/abi/coders/fixed-bytes.ts +37 -37
- package/src.ts/abi/coders/null.ts +28 -28
- package/src.ts/abi/coders/number.ts +63 -63
- package/src.ts/abi/coders/string.ts +29 -29
- package/src.ts/abi/coders/tuple.ts +69 -69
- package/src.ts/abi/fragments.ts +1617 -1617
- package/src.ts/abi/index.ts +41 -41
- package/src.ts/abi/interface.ts +1271 -1271
- package/src.ts/abi/typed.ts +796 -796
- package/src.ts/address/address.ts +148 -148
- package/src.ts/address/checks.ts +123 -123
- package/src.ts/address/contract-address.ts +80 -80
- package/src.ts/address/index.ts +57 -57
- package/src.ts/constants/addresses.ts +8 -8
- package/src.ts/constants/hashes.ts +7 -7
- package/src.ts/constants/index.ts +16 -16
- package/src.ts/constants/numbers.ts +35 -35
- package/src.ts/constants/strings.ts +16 -16
- package/src.ts/contract/contract.ts +1120 -1120
- package/src.ts/contract/factory.ts +143 -143
- package/src.ts/contract/index.ts +31 -31
- package/src.ts/contract/types.ts +236 -236
- package/src.ts/contract/wrappers.ts +225 -225
- package/src.ts/crypto/crypto-browser.ts +64 -64
- package/src.ts/crypto/crypto.ts +4 -4
- package/src.ts/crypto/hmac.ts +51 -51
- package/src.ts/crypto/index.ts +59 -59
- package/src.ts/crypto/keccak.ts +54 -54
- package/src.ts/crypto/pbkdf2.ts +55 -55
- package/src.ts/crypto/random.ts +36 -36
- package/src.ts/crypto/ripemd160.ts +43 -43
- package/src.ts/crypto/scrypt.ts +114 -114
- package/src.ts/crypto/sha2.ts +78 -78
- package/src.ts/crypto/signature.ts +145 -349
- package/src.ts/crypto/signing-key.ts +126 -118
- package/src.ts/hash/authorization.ts +38 -38
- package/src.ts/hash/id.ts +17 -17
- package/src.ts/hash/index.ts +18 -18
- package/src.ts/hash/message.ts +51 -51
- package/src.ts/hash/namehash.ts +101 -101
- package/src.ts/hash/solidity.ts +117 -117
- package/src.ts/hash/typed-data.ts +658 -658
- package/src.ts/index.ts +12 -12
- package/src.ts/providers/abstract-provider.ts +1761 -1761
- package/src.ts/providers/abstract-signer.ts +314 -314
- package/src.ts/providers/community.ts +49 -49
- package/src.ts/providers/contracts.ts +42 -42
- package/src.ts/providers/default-provider.ts +96 -96
- package/src.ts/providers/ens-resolver.ts +606 -606
- package/src.ts/providers/format.ts +320 -320
- package/src.ts/providers/formatting.ts +418 -418
- package/src.ts/providers/index.ts +125 -125
- package/src.ts/providers/network.ts +327 -327
- package/src.ts/providers/pagination.ts +8 -8
- package/src.ts/providers/plugin-fallback.ts +35 -35
- package/src.ts/providers/plugins-network.ts +281 -281
- package/src.ts/providers/provider-browser.ts +334 -334
- package/src.ts/providers/provider-fallback.ts +801 -801
- package/src.ts/providers/provider-ipcsocket-browser.ts +3 -3
- package/src.ts/providers/provider-ipcsocket.ts +81 -81
- package/src.ts/providers/provider-jsonrpc.ts +1334 -1335
- package/src.ts/providers/provider-socket.ts +352 -352
- package/src.ts/providers/provider-websocket.ts +103 -103
- package/src.ts/providers/provider.ts +2136 -2136
- package/src.ts/providers/signer-noncemanager.ts +98 -98
- package/src.ts/providers/signer.ts +166 -166
- package/src.ts/providers/subscriber-connection.ts +74 -74
- package/src.ts/providers/subscriber-filterid.ts +199 -199
- package/src.ts/providers/subscriber-polling.ts +321 -321
- package/src.ts/providers/ws-browser.ts +11 -11
- package/src.ts/providers/ws.ts +3 -3
- package/src.ts/quantumcoin.ts +219 -211
- package/src.ts/thirdparty.d.ts +16 -16
- package/src.ts/transaction/accesslist.ts +43 -43
- package/src.ts/transaction/address.ts +35 -31
- package/src.ts/transaction/authorization.ts +14 -14
- package/src.ts/transaction/index.ts +51 -51
- package/src.ts/transaction/transaction.ts +1349 -1379
- package/src.ts/utils/base58.ts +73 -73
- package/src.ts/utils/base64-browser.ts +25 -25
- package/src.ts/utils/base64.ts +56 -56
- package/src.ts/utils/data.ts +199 -199
- package/src.ts/utils/errors.ts +793 -793
- package/src.ts/utils/events.ts +105 -105
- package/src.ts/utils/fetch.ts +970 -970
- package/src.ts/utils/fixednumber.ts +643 -643
- package/src.ts/utils/geturl-browser.ts +81 -81
- package/src.ts/utils/geturl.ts +134 -134
- package/src.ts/utils/index.ts +95 -95
- package/src.ts/utils/maths.ts +240 -240
- package/src.ts/utils/properties.ts +60 -60
- package/src.ts/utils/rlp-decode.ts +104 -104
- package/src.ts/utils/rlp-encode.ts +64 -64
- package/src.ts/utils/rlp.ts +20 -20
- package/src.ts/utils/units.ts +91 -91
- package/src.ts/utils/utf8.ts +325 -325
- package/src.ts/utils/uuid.ts +36 -36
- package/src.ts/wallet/base-wallet.ts +160 -160
- package/src.ts/wallet/index.ts +32 -32
- package/src.ts/wallet/json-keystore.ts +108 -106
- package/src.ts/wallet/utils.ts +147 -147
- package/src.ts/wallet/wallet.ts +138 -139
- package/src.ts/wordlists/bit-reader.ts +35 -35
- package/src.ts/wordlists/decode-owl.ts +58 -58
- package/src.ts/wordlists/decode-owla.ts +33 -33
- package/src.ts/wordlists/generation/encode-latin.ts +370 -370
- package/src.ts/wordlists/index.ts +26 -26
- package/src.ts/wordlists/lang-cz.ts +33 -33
- package/src.ts/wordlists/lang-en.ts +33 -33
- package/src.ts/wordlists/lang-es.ts +35 -35
- package/src.ts/wordlists/lang-fr.ts +34 -34
- package/src.ts/wordlists/lang-it.ts +33 -33
- package/src.ts/wordlists/lang-ja.ts +181 -181
- package/src.ts/wordlists/lang-ko.ts +104 -104
- package/src.ts/wordlists/lang-pt.ts +34 -34
- package/src.ts/wordlists/lang-zh.ts +112 -112
- package/src.ts/wordlists/wordlist-owl.ts +77 -77
- package/src.ts/wordlists/wordlist-owla.ts +41 -41
- package/src.ts/wordlists/wordlist.ts +59 -59
- package/src.ts/wordlists/wordlists-browser.ts +8 -8
- package/src.ts/wordlists/wordlists-extra.ts +9 -9
- package/src.ts/wordlists/wordlists.ts +38 -38
- package/dist/quantumcoin.min.js'.gz' +0 -0
- package/dist/quantumcoin.umd.min.js'.gz' +0 -0
- package/dist/wordlists-extra.min.js'.gz' +0 -0
- package/lib.commonjs/providers/provider-alchemy.d.ts +0 -50
- package/lib.commonjs/providers/provider-alchemy.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-alchemy.js +0 -151
- package/lib.commonjs/providers/provider-alchemy.js.map +0 -1
- package/lib.commonjs/providers/provider-ankr.d.ts +0 -61
- package/lib.commonjs/providers/provider-ankr.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-ankr.js +0 -137
- package/lib.commonjs/providers/provider-ankr.js.map +0 -1
- package/lib.commonjs/providers/provider-blockscout.d.ts +0 -59
- package/lib.commonjs/providers/provider-blockscout.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-blockscout.js +0 -145
- package/lib.commonjs/providers/provider-blockscout.js.map +0 -1
- package/lib.commonjs/providers/provider-chainstack.d.ts +0 -46
- package/lib.commonjs/providers/provider-chainstack.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-chainstack.js +0 -102
- package/lib.commonjs/providers/provider-chainstack.js.map +0 -1
- package/lib.commonjs/providers/provider-cloudflare.d.ts +0 -14
- package/lib.commonjs/providers/provider-cloudflare.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-cloudflare.js +0 -26
- package/lib.commonjs/providers/provider-cloudflare.js.map +0 -1
- package/lib.commonjs/providers/provider-etherscan.d.ts +0 -147
- package/lib.commonjs/providers/provider-etherscan.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-etherscan.js +0 -587
- package/lib.commonjs/providers/provider-etherscan.js.map +0 -1
- package/lib.commonjs/providers/provider-infura.d.ts +0 -101
- package/lib.commonjs/providers/provider-infura.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-infura.js +0 -206
- package/lib.commonjs/providers/provider-infura.js.map +0 -1
- package/lib.commonjs/providers/provider-pocket.d.ts +0 -54
- package/lib.commonjs/providers/provider-pocket.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-pocket.js +0 -109
- package/lib.commonjs/providers/provider-pocket.js.map +0 -1
- package/lib.commonjs/providers/provider-quicknode.d.ts +0 -59
- package/lib.commonjs/providers/provider-quicknode.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-quicknode.js +0 -163
- package/lib.commonjs/providers/provider-quicknode.js.map +0 -1
- package/lib.commonjs/wallet/hdwallet.d.ts +0 -248
- package/lib.commonjs/wallet/hdwallet.d.ts.map +0 -1
- package/lib.commonjs/wallet/hdwallet.js +0 -505
- package/lib.commonjs/wallet/hdwallet.js.map +0 -1
- package/lib.commonjs/wallet/json-crowdsale.d.ts +0 -27
- package/lib.commonjs/wallet/json-crowdsale.d.ts.map +0 -1
- package/lib.commonjs/wallet/json-crowdsale.js +0 -60
- package/lib.commonjs/wallet/json-crowdsale.js.map +0 -1
- package/lib.commonjs/wallet/mnemonic.d.ts +0 -65
- package/lib.commonjs/wallet/mnemonic.d.ts.map +0 -1
- package/lib.commonjs/wallet/mnemonic.js +0 -169
- package/lib.commonjs/wallet/mnemonic.js.map +0 -1
- package/lib.commonjs/wallet/seedwallet.d.ts +0 -4
- package/lib.commonjs/wallet/seedwallet.d.ts.map +0 -1
- package/lib.commonjs/wallet/seedwallet.js +0 -8
- package/lib.commonjs/wallet/seedwallet.js.map +0 -1
- package/lib.esm/providers/provider-alchemy.d.ts +0 -50
- package/lib.esm/providers/provider-alchemy.d.ts.map +0 -1
- package/lib.esm/providers/provider-alchemy.js +0 -147
- package/lib.esm/providers/provider-alchemy.js.map +0 -1
- package/lib.esm/providers/provider-ankr.d.ts +0 -61
- package/lib.esm/providers/provider-ankr.d.ts.map +0 -1
- package/lib.esm/providers/provider-ankr.js +0 -133
- package/lib.esm/providers/provider-ankr.js.map +0 -1
- package/lib.esm/providers/provider-blockscout.d.ts +0 -59
- package/lib.esm/providers/provider-blockscout.d.ts.map +0 -1
- package/lib.esm/providers/provider-blockscout.js +0 -141
- package/lib.esm/providers/provider-blockscout.js.map +0 -1
- package/lib.esm/providers/provider-chainstack.d.ts +0 -46
- package/lib.esm/providers/provider-chainstack.d.ts.map +0 -1
- package/lib.esm/providers/provider-chainstack.js +0 -98
- package/lib.esm/providers/provider-chainstack.js.map +0 -1
- package/lib.esm/providers/provider-cloudflare.d.ts +0 -14
- package/lib.esm/providers/provider-cloudflare.d.ts.map +0 -1
- package/lib.esm/providers/provider-cloudflare.js +0 -22
- package/lib.esm/providers/provider-cloudflare.js.map +0 -1
- package/lib.esm/providers/provider-etherscan.d.ts +0 -147
- package/lib.esm/providers/provider-etherscan.d.ts.map +0 -1
- package/lib.esm/providers/provider-etherscan.js +0 -584
- package/lib.esm/providers/provider-etherscan.js.map +0 -1
- package/lib.esm/providers/provider-infura.d.ts +0 -101
- package/lib.esm/providers/provider-infura.d.ts.map +0 -1
- package/lib.esm/providers/provider-infura.js +0 -201
- package/lib.esm/providers/provider-infura.js.map +0 -1
- package/lib.esm/providers/provider-pocket.d.ts +0 -54
- package/lib.esm/providers/provider-pocket.d.ts.map +0 -1
- package/lib.esm/providers/provider-pocket.js +0 -105
- package/lib.esm/providers/provider-pocket.js.map +0 -1
- package/lib.esm/providers/provider-quicknode.d.ts +0 -59
- package/lib.esm/providers/provider-quicknode.d.ts.map +0 -1
- package/lib.esm/providers/provider-quicknode.js +0 -159
- package/lib.esm/providers/provider-quicknode.js.map +0 -1
- package/lib.esm/wallet/hdwallet.d.ts +0 -248
- package/lib.esm/wallet/hdwallet.d.ts.map +0 -1
- package/lib.esm/wallet/hdwallet.js +0 -498
- package/lib.esm/wallet/hdwallet.js.map +0 -1
- package/lib.esm/wallet/json-crowdsale.d.ts +0 -27
- package/lib.esm/wallet/json-crowdsale.d.ts.map +0 -1
- package/lib.esm/wallet/json-crowdsale.js +0 -55
- package/lib.esm/wallet/json-crowdsale.js.map +0 -1
- package/lib.esm/wallet/mnemonic.d.ts +0 -65
- package/lib.esm/wallet/mnemonic.d.ts.map +0 -1
- package/lib.esm/wallet/mnemonic.js +0 -165
- package/lib.esm/wallet/mnemonic.js.map +0 -1
- package/lib.esm/wallet/seedwallet.d.ts +0 -4
- package/lib.esm/wallet/seedwallet.d.ts.map +0 -1
- package/lib.esm/wallet/seedwallet.js +0 -4
- package/lib.esm/wallet/seedwallet.js.map +0 -1
|
@@ -1,314 +1,314 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generally the [[Wallet]] and [[JsonRpcSigner]] and their sub-classes
|
|
3
|
-
* are sufficent for most developers, but this is provided to
|
|
4
|
-
* fascilitate more complex Signers.
|
|
5
|
-
*
|
|
6
|
-
* @_section: api/providers/abstract-signer: Subclassing Signer [abstract-signer]
|
|
7
|
-
*/
|
|
8
|
-
import { resolveAddress } from "../address/index.js";
|
|
9
|
-
import { Transaction } from "../transaction/index.js";
|
|
10
|
-
import {
|
|
11
|
-
defineProperties, getBigInt, resolveProperties,
|
|
12
|
-
assert, assertArgument
|
|
13
|
-
} from "../utils/index.js";
|
|
14
|
-
|
|
15
|
-
import { copyRequest } from "./provider.js";
|
|
16
|
-
|
|
17
|
-
import type {
|
|
18
|
-
AuthorizationRequest, TypedDataDomain, TypedDataField
|
|
19
|
-
} from "../hash/index.js";
|
|
20
|
-
import type { Authorization, TransactionLike } from "../transaction/index.js";
|
|
21
|
-
|
|
22
|
-
import type {
|
|
23
|
-
BlockTag, Provider, TransactionRequest, TransactionResponse
|
|
24
|
-
} from "./provider.js";
|
|
25
|
-
import type { Signer } from "./signer.js";
|
|
26
|
-
|
|
27
|
-
function checkProvider(signer: AbstractSigner, operation: string): Provider {
|
|
28
|
-
if (signer.provider) { return signer.provider; }
|
|
29
|
-
assert(false, "missing provider", "UNSUPPORTED_OPERATION", { operation });
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function populate(signer: AbstractSigner, tx: TransactionRequest): Promise<TransactionLike<string>> {
|
|
33
|
-
let pop: any = copyRequest(tx);
|
|
34
|
-
|
|
35
|
-
if (pop.to != null) { pop.to = resolveAddress(pop.to, signer); }
|
|
36
|
-
|
|
37
|
-
if (pop.from != null) {
|
|
38
|
-
const from = pop.from;
|
|
39
|
-
pop.from = Promise.all([
|
|
40
|
-
signer.getAddress(),
|
|
41
|
-
resolveAddress(from, signer)
|
|
42
|
-
]).then(([ address, from ]) => {
|
|
43
|
-
assertArgument(address.toLowerCase() === from.toLowerCase(),
|
|
44
|
-
"transaction from mismatch", "tx.from", from);
|
|
45
|
-
return address;
|
|
46
|
-
});
|
|
47
|
-
} else {
|
|
48
|
-
pop.from = signer.getAddress();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return await resolveProperties(pop);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* An **AbstractSigner** includes most of teh functionality required
|
|
57
|
-
* to get a [[Signer]] working as expected, but requires a few
|
|
58
|
-
* Signer-specific methods be overridden.
|
|
59
|
-
*
|
|
60
|
-
*/
|
|
61
|
-
export abstract class AbstractSigner<P extends null | Provider = null | Provider> implements Signer {
|
|
62
|
-
/**
|
|
63
|
-
* The provider this signer is connected to.
|
|
64
|
-
*/
|
|
65
|
-
readonly provider!: P;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Creates a new Signer connected to %%provider%%.
|
|
69
|
-
*/
|
|
70
|
-
constructor(provider?: P) {
|
|
71
|
-
defineProperties<AbstractSigner>(this, { provider: (provider || null) });
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Resolves to the Signer address.
|
|
76
|
-
*/
|
|
77
|
-
abstract getAddress(): Promise<string>;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Returns the signer connected to %%provider%%.
|
|
81
|
-
*
|
|
82
|
-
* This may throw, for example, a Signer connected over a Socket or
|
|
83
|
-
* to a specific instance of a node may not be transferrable.
|
|
84
|
-
*/
|
|
85
|
-
abstract connect(provider: null | Provider): Signer;
|
|
86
|
-
|
|
87
|
-
async getNonce(blockTag?: BlockTag): Promise<number> {
|
|
88
|
-
return checkProvider(this, "getTransactionCount").getTransactionCount(await this.getAddress(), blockTag);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async populateCall(tx: TransactionRequest): Promise<TransactionLike<string>> {
|
|
92
|
-
const pop = await populate(this, tx);
|
|
93
|
-
return pop;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async populateTransaction(tx: TransactionRequest): Promise<TransactionLike<string>> {
|
|
97
|
-
const provider = checkProvider(this, "populateTransaction");
|
|
98
|
-
|
|
99
|
-
const pop = await populate(this, tx);
|
|
100
|
-
|
|
101
|
-
if (pop.nonce == null) {
|
|
102
|
-
pop.nonce = await this.getNonce("pending");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (pop.gasLimit == null) {
|
|
106
|
-
pop.gasLimit = await this.estimateGas(pop);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Populate the chain ID
|
|
110
|
-
const network = await (<Provider>(this.provider)).getNetwork();
|
|
111
|
-
if (pop.chainId != null) {
|
|
112
|
-
const chainId = getBigInt(pop.chainId);
|
|
113
|
-
assertArgument(chainId === network.chainId, "transaction chainId mismatch", "tx.chainId", tx.chainId);
|
|
114
|
-
} else {
|
|
115
|
-
pop.chainId = network.chainId;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Do not allow mixing pre-eip-1559 and eip-1559 properties
|
|
119
|
-
const hasEip1559 = (pop.maxFeePerGas != null || pop.maxPriorityFeePerGas != null);
|
|
120
|
-
if (pop.gasPrice != null && (pop.type === 2 || hasEip1559)) {
|
|
121
|
-
assertArgument(false, "eip-1559 transaction do not support gasPrice", "tx", tx);
|
|
122
|
-
} else if ((pop.type === 0 || pop.type === 1) && hasEip1559) {
|
|
123
|
-
assertArgument(false, "pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas", "tx", tx);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if ((pop.type === 2 || pop.type == null) && (pop.maxFeePerGas != null && pop.maxPriorityFeePerGas != null)) {
|
|
127
|
-
// Fully-formed EIP-1559 transaction (skip getFeeData)
|
|
128
|
-
pop.type = 2;
|
|
129
|
-
|
|
130
|
-
} else if (pop.type === 0 || pop.type === 1) {
|
|
131
|
-
// Explicit Legacy or EIP-2930 transaction
|
|
132
|
-
|
|
133
|
-
// We need to get fee data to determine things
|
|
134
|
-
const feeData = await provider.getFeeData();
|
|
135
|
-
|
|
136
|
-
assert(feeData.gasPrice != null, "network does not support gasPrice", "UNSUPPORTED_OPERATION", {
|
|
137
|
-
operation: "getGasPrice" });
|
|
138
|
-
|
|
139
|
-
// Populate missing gasPrice
|
|
140
|
-
if (pop.gasPrice == null) { pop.gasPrice = feeData.gasPrice; }
|
|
141
|
-
|
|
142
|
-
} else {
|
|
143
|
-
|
|
144
|
-
// We need to get fee data to determine things
|
|
145
|
-
const feeData = await provider.getFeeData();
|
|
146
|
-
|
|
147
|
-
if (pop.type == null) {
|
|
148
|
-
// We need to auto-detect the intended type of this transaction...
|
|
149
|
-
|
|
150
|
-
if (feeData.maxFeePerGas != null && feeData.maxPriorityFeePerGas != null) {
|
|
151
|
-
// The network supports EIP-1559!
|
|
152
|
-
|
|
153
|
-
// Upgrade transaction from null to eip-1559
|
|
154
|
-
if (pop.authorizationList && pop.authorizationList.length) {
|
|
155
|
-
pop.type = 4;
|
|
156
|
-
} else {
|
|
157
|
-
pop.type = 2;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (pop.gasPrice != null) {
|
|
161
|
-
// Using legacy gasPrice property on an eip-1559 network,
|
|
162
|
-
// so use gasPrice as both fee properties
|
|
163
|
-
const gasPrice = pop.gasPrice;
|
|
164
|
-
delete pop.gasPrice;
|
|
165
|
-
pop.maxFeePerGas = gasPrice;
|
|
166
|
-
pop.maxPriorityFeePerGas = gasPrice;
|
|
167
|
-
|
|
168
|
-
} else {
|
|
169
|
-
// Populate missing fee data
|
|
170
|
-
|
|
171
|
-
if (pop.maxFeePerGas == null) {
|
|
172
|
-
pop.maxFeePerGas = feeData.maxFeePerGas;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (pop.maxPriorityFeePerGas == null) {
|
|
176
|
-
pop.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
} else if (feeData.gasPrice != null) {
|
|
181
|
-
// Network doesn't support EIP-1559...
|
|
182
|
-
|
|
183
|
-
// ...but they are trying to use EIP-1559 properties
|
|
184
|
-
assert(!hasEip1559, "network does not support EIP-1559", "UNSUPPORTED_OPERATION", {
|
|
185
|
-
operation: "populateTransaction" });
|
|
186
|
-
|
|
187
|
-
// Populate missing fee data
|
|
188
|
-
if (pop.gasPrice == null) {
|
|
189
|
-
pop.gasPrice = feeData.gasPrice;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Explicitly set untyped transaction to legacy
|
|
193
|
-
// @TODO: Maybe this shold allow type 1?
|
|
194
|
-
pop.type = 0;
|
|
195
|
-
|
|
196
|
-
} else {
|
|
197
|
-
// getFeeData has failed us.
|
|
198
|
-
assert(false, "failed to get consistent fee data", "UNSUPPORTED_OPERATION", {
|
|
199
|
-
operation: "signer.getFeeData" });
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
} else if (pop.type === 2 || pop.type === 3 || pop.type === 4) {
|
|
203
|
-
// Explicitly using EIP-1559 or EIP-4844
|
|
204
|
-
|
|
205
|
-
// Populate missing fee data
|
|
206
|
-
if (pop.maxFeePerGas == null) {
|
|
207
|
-
pop.maxFeePerGas = feeData.maxFeePerGas;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (pop.maxPriorityFeePerGas == null) {
|
|
211
|
-
pop.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
//@TOOD: Don't await all over the place; save them up for
|
|
217
|
-
// the end for better batching
|
|
218
|
-
return await resolveProperties(pop);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
async populateAuthorization(_auth: AuthorizationRequest): Promise<AuthorizationRequest> {
|
|
222
|
-
const auth = Object.assign({ }, _auth);
|
|
223
|
-
|
|
224
|
-
// Add a chain ID if not explicitly set to 0
|
|
225
|
-
if (auth.chainId == null) {
|
|
226
|
-
auth.chainId = (await checkProvider(this, "getNetwork").getNetwork()).chainId;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// @TODO: Take chain ID into account when populating noce?
|
|
230
|
-
|
|
231
|
-
if (auth.nonce == null) { auth.nonce = await this.getNonce(); }
|
|
232
|
-
|
|
233
|
-
return auth;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
async estimateGas(tx: TransactionRequest): Promise<bigint> {
|
|
237
|
-
return checkProvider(this, "estimateGas").estimateGas(await this.populateCall(tx));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
async call(tx: TransactionRequest): Promise<string> {
|
|
241
|
-
return checkProvider(this, "call").call(await this.populateCall(tx));
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async resolveName(name: string): Promise<null | string> {
|
|
245
|
-
const provider = checkProvider(this, "resolveName");
|
|
246
|
-
return await provider.resolveName(name);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
async sendTransaction(tx: TransactionRequest): Promise<TransactionResponse> {
|
|
250
|
-
const provider = checkProvider(this, "sendTransaction");
|
|
251
|
-
|
|
252
|
-
const pop = await this.populateTransaction(tx);
|
|
253
|
-
delete pop.from;
|
|
254
|
-
const txObj = Transaction.from(pop);
|
|
255
|
-
return await provider.broadcastTransaction(await this.signTransaction(txObj));
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// @TODO: in v7 move this to be abstract
|
|
259
|
-
authorize(authorization: AuthorizationRequest): Promise<Authorization> {
|
|
260
|
-
assert(false, "authorization not implemented for this signer",
|
|
261
|
-
"UNSUPPORTED_OPERATION", { operation: "authorize" });
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
abstract signTransaction(tx: TransactionRequest): Promise<string>;
|
|
265
|
-
abstract signMessage(message: string | Uint8Array): Promise<string>;
|
|
266
|
-
abstract signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* A **VoidSigner** is a class deisgned to allow an address to be used
|
|
271
|
-
* in any API which accepts a Signer, but for which there are no
|
|
272
|
-
* credentials available to perform any actual signing.
|
|
273
|
-
*
|
|
274
|
-
* This for example allow impersonating an account for the purpose of
|
|
275
|
-
* static calls or estimating gas, but does not allow sending transactions.
|
|
276
|
-
*/
|
|
277
|
-
export class VoidSigner extends AbstractSigner {
|
|
278
|
-
/**
|
|
279
|
-
* The signer address.
|
|
280
|
-
*/
|
|
281
|
-
readonly address!: string;
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Creates a new **VoidSigner** with %%address%% attached to
|
|
285
|
-
* %%provider%%.
|
|
286
|
-
*/
|
|
287
|
-
constructor(address: string, provider?: null | Provider) {
|
|
288
|
-
super(provider);
|
|
289
|
-
defineProperties<VoidSigner>(this, { address });
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
async getAddress(): Promise<string> { return this.address; }
|
|
293
|
-
|
|
294
|
-
connect(provider: null | Provider): VoidSigner {
|
|
295
|
-
return new VoidSigner(this.address, provider);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
#throwUnsupported(suffix: string, operation: string): never {
|
|
299
|
-
assert(false, `VoidSigner cannot sign ${ suffix }`, "UNSUPPORTED_OPERATION", { operation });
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
async signTransaction(tx: TransactionRequest): Promise<string> {
|
|
303
|
-
this.#throwUnsupported("transactions", "signTransaction");
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
async signMessage(message: string | Uint8Array): Promise<string> {
|
|
307
|
-
this.#throwUnsupported("messages", "signMessage");
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
async signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string> {
|
|
311
|
-
this.#throwUnsupported("typed-data", "signTypedData");
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generally the [[Wallet]] and [[JsonRpcSigner]] and their sub-classes
|
|
3
|
+
* are sufficent for most developers, but this is provided to
|
|
4
|
+
* fascilitate more complex Signers.
|
|
5
|
+
*
|
|
6
|
+
* @_section: api/providers/abstract-signer: Subclassing Signer [abstract-signer]
|
|
7
|
+
*/
|
|
8
|
+
import { resolveAddress } from "../address/index.js";
|
|
9
|
+
import { Transaction } from "../transaction/index.js";
|
|
10
|
+
import {
|
|
11
|
+
defineProperties, getBigInt, resolveProperties,
|
|
12
|
+
assert, assertArgument
|
|
13
|
+
} from "../utils/index.js";
|
|
14
|
+
|
|
15
|
+
import { copyRequest } from "./provider.js";
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
AuthorizationRequest, TypedDataDomain, TypedDataField
|
|
19
|
+
} from "../hash/index.js";
|
|
20
|
+
import type { Authorization, TransactionLike } from "../transaction/index.js";
|
|
21
|
+
|
|
22
|
+
import type {
|
|
23
|
+
BlockTag, Provider, TransactionRequest, TransactionResponse
|
|
24
|
+
} from "./provider.js";
|
|
25
|
+
import type { Signer } from "./signer.js";
|
|
26
|
+
|
|
27
|
+
function checkProvider(signer: AbstractSigner, operation: string): Provider {
|
|
28
|
+
if (signer.provider) { return signer.provider; }
|
|
29
|
+
assert(false, "missing provider", "UNSUPPORTED_OPERATION", { operation });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function populate(signer: AbstractSigner, tx: TransactionRequest): Promise<TransactionLike<string>> {
|
|
33
|
+
let pop: any = copyRequest(tx);
|
|
34
|
+
|
|
35
|
+
if (pop.to != null) { pop.to = resolveAddress(pop.to, signer); }
|
|
36
|
+
|
|
37
|
+
if (pop.from != null) {
|
|
38
|
+
const from = pop.from;
|
|
39
|
+
pop.from = Promise.all([
|
|
40
|
+
signer.getAddress(),
|
|
41
|
+
resolveAddress(from, signer)
|
|
42
|
+
]).then(([ address, from ]) => {
|
|
43
|
+
assertArgument(address.toLowerCase() === from.toLowerCase(),
|
|
44
|
+
"transaction from mismatch", "tx.from", from);
|
|
45
|
+
return address;
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
pop.from = signer.getAddress();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return await resolveProperties(pop);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* An **AbstractSigner** includes most of teh functionality required
|
|
57
|
+
* to get a [[Signer]] working as expected, but requires a few
|
|
58
|
+
* Signer-specific methods be overridden.
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
export abstract class AbstractSigner<P extends null | Provider = null | Provider> implements Signer {
|
|
62
|
+
/**
|
|
63
|
+
* The provider this signer is connected to.
|
|
64
|
+
*/
|
|
65
|
+
readonly provider!: P;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new Signer connected to %%provider%%.
|
|
69
|
+
*/
|
|
70
|
+
constructor(provider?: P) {
|
|
71
|
+
defineProperties<AbstractSigner>(this, { provider: (provider || null) });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Resolves to the Signer address.
|
|
76
|
+
*/
|
|
77
|
+
abstract getAddress(): Promise<string>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns the signer connected to %%provider%%.
|
|
81
|
+
*
|
|
82
|
+
* This may throw, for example, a Signer connected over a Socket or
|
|
83
|
+
* to a specific instance of a node may not be transferrable.
|
|
84
|
+
*/
|
|
85
|
+
abstract connect(provider: null | Provider): Signer;
|
|
86
|
+
|
|
87
|
+
async getNonce(blockTag?: BlockTag): Promise<number> {
|
|
88
|
+
return checkProvider(this, "getTransactionCount").getTransactionCount(await this.getAddress(), blockTag);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async populateCall(tx: TransactionRequest): Promise<TransactionLike<string>> {
|
|
92
|
+
const pop = await populate(this, tx);
|
|
93
|
+
return pop;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async populateTransaction(tx: TransactionRequest): Promise<TransactionLike<string>> {
|
|
97
|
+
const provider = checkProvider(this, "populateTransaction");
|
|
98
|
+
|
|
99
|
+
const pop = await populate(this, tx);
|
|
100
|
+
|
|
101
|
+
if (pop.nonce == null) {
|
|
102
|
+
pop.nonce = await this.getNonce("pending");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (pop.gasLimit == null) {
|
|
106
|
+
pop.gasLimit = await this.estimateGas(pop);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Populate the chain ID
|
|
110
|
+
const network = await (<Provider>(this.provider)).getNetwork();
|
|
111
|
+
if (pop.chainId != null) {
|
|
112
|
+
const chainId = getBigInt(pop.chainId);
|
|
113
|
+
assertArgument(chainId === network.chainId, "transaction chainId mismatch", "tx.chainId", tx.chainId);
|
|
114
|
+
} else {
|
|
115
|
+
pop.chainId = network.chainId;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Do not allow mixing pre-eip-1559 and eip-1559 properties
|
|
119
|
+
const hasEip1559 = (pop.maxFeePerGas != null || pop.maxPriorityFeePerGas != null);
|
|
120
|
+
if (pop.gasPrice != null && (pop.type === 2 || hasEip1559)) {
|
|
121
|
+
assertArgument(false, "eip-1559 transaction do not support gasPrice", "tx", tx);
|
|
122
|
+
} else if ((pop.type === 0 || pop.type === 1) && hasEip1559) {
|
|
123
|
+
assertArgument(false, "pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas", "tx", tx);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if ((pop.type === 2 || pop.type == null) && (pop.maxFeePerGas != null && pop.maxPriorityFeePerGas != null)) {
|
|
127
|
+
// Fully-formed EIP-1559 transaction (skip getFeeData)
|
|
128
|
+
pop.type = 2;
|
|
129
|
+
|
|
130
|
+
} else if (pop.type === 0 || pop.type === 1) {
|
|
131
|
+
// Explicit Legacy or EIP-2930 transaction
|
|
132
|
+
|
|
133
|
+
// We need to get fee data to determine things
|
|
134
|
+
const feeData = await provider.getFeeData();
|
|
135
|
+
|
|
136
|
+
assert(feeData.gasPrice != null, "network does not support gasPrice", "UNSUPPORTED_OPERATION", {
|
|
137
|
+
operation: "getGasPrice" });
|
|
138
|
+
|
|
139
|
+
// Populate missing gasPrice
|
|
140
|
+
if (pop.gasPrice == null) { pop.gasPrice = feeData.gasPrice; }
|
|
141
|
+
|
|
142
|
+
} else {
|
|
143
|
+
|
|
144
|
+
// We need to get fee data to determine things
|
|
145
|
+
const feeData = await provider.getFeeData();
|
|
146
|
+
|
|
147
|
+
if (pop.type == null) {
|
|
148
|
+
// We need to auto-detect the intended type of this transaction...
|
|
149
|
+
|
|
150
|
+
if (feeData.maxFeePerGas != null && feeData.maxPriorityFeePerGas != null) {
|
|
151
|
+
// The network supports EIP-1559!
|
|
152
|
+
|
|
153
|
+
// Upgrade transaction from null to eip-1559
|
|
154
|
+
if (pop.authorizationList && pop.authorizationList.length) {
|
|
155
|
+
pop.type = 4;
|
|
156
|
+
} else {
|
|
157
|
+
pop.type = 2;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (pop.gasPrice != null) {
|
|
161
|
+
// Using legacy gasPrice property on an eip-1559 network,
|
|
162
|
+
// so use gasPrice as both fee properties
|
|
163
|
+
const gasPrice = pop.gasPrice;
|
|
164
|
+
delete pop.gasPrice;
|
|
165
|
+
pop.maxFeePerGas = gasPrice;
|
|
166
|
+
pop.maxPriorityFeePerGas = gasPrice;
|
|
167
|
+
|
|
168
|
+
} else {
|
|
169
|
+
// Populate missing fee data
|
|
170
|
+
|
|
171
|
+
if (pop.maxFeePerGas == null) {
|
|
172
|
+
pop.maxFeePerGas = feeData.maxFeePerGas;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (pop.maxPriorityFeePerGas == null) {
|
|
176
|
+
pop.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
} else if (feeData.gasPrice != null) {
|
|
181
|
+
// Network doesn't support EIP-1559...
|
|
182
|
+
|
|
183
|
+
// ...but they are trying to use EIP-1559 properties
|
|
184
|
+
assert(!hasEip1559, "network does not support EIP-1559", "UNSUPPORTED_OPERATION", {
|
|
185
|
+
operation: "populateTransaction" });
|
|
186
|
+
|
|
187
|
+
// Populate missing fee data
|
|
188
|
+
if (pop.gasPrice == null) {
|
|
189
|
+
pop.gasPrice = feeData.gasPrice;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Explicitly set untyped transaction to legacy
|
|
193
|
+
// @TODO: Maybe this shold allow type 1?
|
|
194
|
+
pop.type = 0;
|
|
195
|
+
|
|
196
|
+
} else {
|
|
197
|
+
// getFeeData has failed us.
|
|
198
|
+
assert(false, "failed to get consistent fee data", "UNSUPPORTED_OPERATION", {
|
|
199
|
+
operation: "signer.getFeeData" });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
} else if (pop.type === 2 || pop.type === 3 || pop.type === 4) {
|
|
203
|
+
// Explicitly using EIP-1559 or EIP-4844
|
|
204
|
+
|
|
205
|
+
// Populate missing fee data
|
|
206
|
+
if (pop.maxFeePerGas == null) {
|
|
207
|
+
pop.maxFeePerGas = feeData.maxFeePerGas;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (pop.maxPriorityFeePerGas == null) {
|
|
211
|
+
pop.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
//@TOOD: Don't await all over the place; save them up for
|
|
217
|
+
// the end for better batching
|
|
218
|
+
return await resolveProperties(pop);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async populateAuthorization(_auth: AuthorizationRequest): Promise<AuthorizationRequest> {
|
|
222
|
+
const auth = Object.assign({ }, _auth);
|
|
223
|
+
|
|
224
|
+
// Add a chain ID if not explicitly set to 0
|
|
225
|
+
if (auth.chainId == null) {
|
|
226
|
+
auth.chainId = (await checkProvider(this, "getNetwork").getNetwork()).chainId;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// @TODO: Take chain ID into account when populating noce?
|
|
230
|
+
|
|
231
|
+
if (auth.nonce == null) { auth.nonce = await this.getNonce(); }
|
|
232
|
+
|
|
233
|
+
return auth;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async estimateGas(tx: TransactionRequest): Promise<bigint> {
|
|
237
|
+
return checkProvider(this, "estimateGas").estimateGas(await this.populateCall(tx));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async call(tx: TransactionRequest): Promise<string> {
|
|
241
|
+
return checkProvider(this, "call").call(await this.populateCall(tx));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async resolveName(name: string): Promise<null | string> {
|
|
245
|
+
const provider = checkProvider(this, "resolveName");
|
|
246
|
+
return await provider.resolveName(name);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async sendTransaction(tx: TransactionRequest): Promise<TransactionResponse> {
|
|
250
|
+
const provider = checkProvider(this, "sendTransaction");
|
|
251
|
+
|
|
252
|
+
const pop = await this.populateTransaction(tx);
|
|
253
|
+
delete pop.from;
|
|
254
|
+
const txObj = Transaction.from(pop);
|
|
255
|
+
return await provider.broadcastTransaction(await this.signTransaction(txObj));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// @TODO: in v7 move this to be abstract
|
|
259
|
+
authorize(authorization: AuthorizationRequest): Promise<Authorization> {
|
|
260
|
+
assert(false, "authorization not implemented for this signer",
|
|
261
|
+
"UNSUPPORTED_OPERATION", { operation: "authorize" });
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
abstract signTransaction(tx: TransactionRequest): Promise<string>;
|
|
265
|
+
abstract signMessage(message: string | Uint8Array): Promise<string>;
|
|
266
|
+
abstract signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* A **VoidSigner** is a class deisgned to allow an address to be used
|
|
271
|
+
* in any API which accepts a Signer, but for which there are no
|
|
272
|
+
* credentials available to perform any actual signing.
|
|
273
|
+
*
|
|
274
|
+
* This for example allow impersonating an account for the purpose of
|
|
275
|
+
* static calls or estimating gas, but does not allow sending transactions.
|
|
276
|
+
*/
|
|
277
|
+
export class VoidSigner extends AbstractSigner {
|
|
278
|
+
/**
|
|
279
|
+
* The signer address.
|
|
280
|
+
*/
|
|
281
|
+
readonly address!: string;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Creates a new **VoidSigner** with %%address%% attached to
|
|
285
|
+
* %%provider%%.
|
|
286
|
+
*/
|
|
287
|
+
constructor(address: string, provider?: null | Provider) {
|
|
288
|
+
super(provider);
|
|
289
|
+
defineProperties<VoidSigner>(this, { address });
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async getAddress(): Promise<string> { return this.address; }
|
|
293
|
+
|
|
294
|
+
connect(provider: null | Provider): VoidSigner {
|
|
295
|
+
return new VoidSigner(this.address, provider);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
#throwUnsupported(suffix: string, operation: string): never {
|
|
299
|
+
assert(false, `VoidSigner cannot sign ${ suffix }`, "UNSUPPORTED_OPERATION", { operation });
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
async signTransaction(tx: TransactionRequest): Promise<string> {
|
|
303
|
+
this.#throwUnsupported("transactions", "signTransaction");
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async signMessage(message: string | Uint8Array): Promise<string> {
|
|
307
|
+
this.#throwUnsupported("messages", "signMessage");
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string> {
|
|
311
|
+
this.#throwUnsupported("typed-data", "signTypedData");
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|