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
package/lib.esm/wallet/wallet.js
CHANGED
|
@@ -3,6 +3,8 @@ import { assertArgument, hexlify } from "../utils/index.js";
|
|
|
3
3
|
import { BaseWallet } from "./base-wallet.js";
|
|
4
4
|
//import { decryptCrowdsaleJson, isCrowdsaleJson } from "./json-crowdsale.js";
|
|
5
5
|
import { decryptKeystoreJsonSync, encryptKeystoreJsonSync, isKeystoreJson } from "./json-keystore.js";
|
|
6
|
+
//import { Mnemonic } from "./mnemonic.js";
|
|
7
|
+
import { newWallet } from "quantum-coin-js-sdk";
|
|
6
8
|
//import {newWallet} from "quantum-coin-js-sdk";
|
|
7
9
|
/**
|
|
8
10
|
* A **Wallet** manages a single private key which is used to sign
|
|
@@ -95,7 +97,7 @@ export class Wallet extends BaseWallet {
|
|
|
95
97
|
* If there is no crytographic random source, this will throw.
|
|
96
98
|
*/
|
|
97
99
|
static createRandom(provider) {
|
|
98
|
-
let wal =
|
|
100
|
+
let wal = newWallet();
|
|
99
101
|
let privKey = wal.privateKey;
|
|
100
102
|
return new Wallet(hexlify(privKey));
|
|
101
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src.ts/wallet/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAC,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,+EAA+E;AAC/E,OAAO,EACH,uBAAuB,EACvB,uBAAuB,EACvB,cAAc,EACjB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src.ts/wallet/wallet.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@types/semver": "7.5.8",
|
|
26
26
|
"c8": "7.12.0",
|
|
27
27
|
"mocha": "10.7.3",
|
|
28
|
+
"quantum-coin-js-sdk": "1.0.23",
|
|
28
29
|
"quantum-coin-pqc-js-sdk": "^1.0.5",
|
|
29
|
-
"quantum-coin-js-sdk": "^1.0.20",
|
|
30
30
|
"rollup": "4.24.0",
|
|
31
31
|
"semver": "7.6.3",
|
|
32
32
|
"typescript": "5.0.4",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"default": "./lib.commonjs/wordlists/index.js"
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "ede6a5a650a591b064e783c828fd5297e4e186dc",
|
|
89
89
|
"homepage": "https://QuantumCoin.org",
|
|
90
90
|
"keywords": [
|
|
91
91
|
"ethereum",
|
|
@@ -108,13 +108,14 @@
|
|
|
108
108
|
},
|
|
109
109
|
"scripts": {
|
|
110
110
|
"_build-dist": "rollup -c && uglifyjs ./dist/quantumcoin.js -o ./dist/quantumcoin.min.js && uglifyjs ./dist/quantumcoin.umd.js -o ./dist/quantumcoin.umd.min.js && uglifyjs ./dist/wordlists-extra.js -o ./dist/wordlists-extra.min.js",
|
|
111
|
-
"_dist-stats": "gzip -k9f -S
|
|
111
|
+
"_dist-stats": "gzip -k9f -S .gz ./dist/quantumcoin.min.js && gzip -k9f -S .gz ./dist/quantumcoin.umd.min.js && gzip -k9f -S .gz ./dist/wordlists-extra.min.js",
|
|
112
112
|
"auto-build": "npm run build -- -w",
|
|
113
113
|
"build": "tsc --project tsconfig.esm.json",
|
|
114
114
|
"build-all": "npm run build && npm run build-commonjs",
|
|
115
|
-
"build-clean": "npm run clean && npm run build &&
|
|
115
|
+
"build-clean": "npm run clean && npm run build && npm run build-all && npm run _build-dist && npm run _dist-stats",
|
|
116
116
|
"build-commonjs": "tsc --project tsconfig.commonjs.json",
|
|
117
117
|
"build-dist": "npm run build && npm run _build-dist && npm run _dist-stats",
|
|
118
|
+
"build-new": "npm run build && npm run build-all && npm run _build-dist && npm run _dist-stats",
|
|
118
119
|
"clean": "rm -rf dist lib.esm lib.commonjs && cp -r misc/basedirs/* .",
|
|
119
120
|
"postpublish": "node lib.esm/_admin/create-release.js",
|
|
120
121
|
"stats": "echo 'Dependencies' && npm ls --all --omit=dev",
|
|
@@ -125,5 +126,5 @@
|
|
|
125
126
|
"test-esm": "mocha --trace-warnings --reporter ./reporter.cjs ./lib.esm/_tests/test-*.js"
|
|
126
127
|
},
|
|
127
128
|
"sideEffects": false,
|
|
128
|
-
"version": "6.14.
|
|
129
|
+
"version": "6.14.5"
|
|
129
130
|
}
|
package/rollup.config.mjs
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
3
|
-
|
|
4
|
-
function getConfig(opts) {
|
|
5
|
-
if (opts == null) { opts = { }; }
|
|
6
|
-
|
|
7
|
-
const file = `./dist/quantumcoin${ (opts.suffix || "") }.js`;
|
|
8
|
-
const exportConditions = [ "import", "default" ];
|
|
9
|
-
const mainFields = [ "module", "main" ];
|
|
10
|
-
if (opts.browser) { mainFields.unshift("browser"); }
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
input: "./lib.esm/index.js",
|
|
14
|
-
output: {
|
|
15
|
-
file,
|
|
16
|
-
banner: "const __$G = (typeof globalThis !== 'undefined' ? globalThis: typeof window !== 'undefined' ? window: typeof global !== 'undefined' ? global: typeof self !== 'undefined' ? self: {});",
|
|
17
|
-
name: (opts.name || undefined),
|
|
18
|
-
format: (opts.format || "esm"),
|
|
19
|
-
sourcemap: true
|
|
20
|
-
},
|
|
21
|
-
context: "__$G",
|
|
22
|
-
treeshake: true,
|
|
23
|
-
plugins: [ nodeResolve({
|
|
24
|
-
exportConditions,
|
|
25
|
-
mainFields,
|
|
26
|
-
modulesOnly: true,
|
|
27
|
-
preferBuiltins: false
|
|
28
|
-
}) ],
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default [
|
|
33
|
-
getConfig({ browser: true }),
|
|
34
|
-
getConfig({ browser: true, suffix: ".umd", format: "umd", name: "ethers" }),
|
|
35
|
-
{
|
|
36
|
-
input: "./lib.esm/wordlists/wordlists-extra.js",
|
|
37
|
-
output: {
|
|
38
|
-
file: "./dist/wordlists-extra.js",
|
|
39
|
-
format: "esm",
|
|
40
|
-
sourcemap: true
|
|
41
|
-
},
|
|
42
|
-
treeshake: true,
|
|
43
|
-
plugins: [ nodeResolve({
|
|
44
|
-
exportConditions: [ "default", "module", "import" ],
|
|
45
|
-
mainFields: [ "browser", "module", "main" ],
|
|
46
|
-
modulesOnly: true,
|
|
47
|
-
preferBuiltins: false
|
|
48
|
-
}) ],
|
|
49
|
-
}
|
|
50
|
-
];
|
|
1
|
+
|
|
2
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
3
|
+
|
|
4
|
+
function getConfig(opts) {
|
|
5
|
+
if (opts == null) { opts = { }; }
|
|
6
|
+
|
|
7
|
+
const file = `./dist/quantumcoin${ (opts.suffix || "") }.js`;
|
|
8
|
+
const exportConditions = [ "import", "default" ];
|
|
9
|
+
const mainFields = [ "module", "main" ];
|
|
10
|
+
if (opts.browser) { mainFields.unshift("browser"); }
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
input: "./lib.esm/index.js",
|
|
14
|
+
output: {
|
|
15
|
+
file,
|
|
16
|
+
banner: "const __$G = (typeof globalThis !== 'undefined' ? globalThis: typeof window !== 'undefined' ? window: typeof global !== 'undefined' ? global: typeof self !== 'undefined' ? self: {});",
|
|
17
|
+
name: (opts.name || undefined),
|
|
18
|
+
format: (opts.format || "esm"),
|
|
19
|
+
sourcemap: true
|
|
20
|
+
},
|
|
21
|
+
context: "__$G",
|
|
22
|
+
treeshake: true,
|
|
23
|
+
plugins: [ nodeResolve({
|
|
24
|
+
exportConditions,
|
|
25
|
+
mainFields,
|
|
26
|
+
modulesOnly: true,
|
|
27
|
+
preferBuiltins: false
|
|
28
|
+
}) ],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default [
|
|
33
|
+
getConfig({ browser: true }),
|
|
34
|
+
getConfig({ browser: true, suffix: ".umd", format: "umd", name: "ethers" }),
|
|
35
|
+
{
|
|
36
|
+
input: "./lib.esm/wordlists/wordlists-extra.js",
|
|
37
|
+
output: {
|
|
38
|
+
file: "./dist/wordlists-extra.js",
|
|
39
|
+
format: "esm",
|
|
40
|
+
sourcemap: true
|
|
41
|
+
},
|
|
42
|
+
treeshake: true,
|
|
43
|
+
plugins: [ nodeResolve({
|
|
44
|
+
exportConditions: [ "default", "module", "import" ],
|
|
45
|
+
mainFields: [ "browser", "module", "main" ],
|
|
46
|
+
modulesOnly: true,
|
|
47
|
+
preferBuiltins: false
|
|
48
|
+
}) ],
|
|
49
|
+
}
|
|
50
|
+
];
|
package/src.ts/_version.ts
CHANGED
package/src.ts/abi/abi-coder.ts
CHANGED
|
@@ -1,237 +1,237 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* When sending values to or receiving values from a [[Contract]], the
|
|
3
|
-
* data is generally encoded using the [ABI standard](link-solc-abi).
|
|
4
|
-
*
|
|
5
|
-
* The AbiCoder provides a utility to encode values to ABI data and
|
|
6
|
-
* decode values from ABI data.
|
|
7
|
-
*
|
|
8
|
-
* Most of the time, developers should favour the [[Contract]] class,
|
|
9
|
-
* which further abstracts a lot of the finer details of ABI data.
|
|
10
|
-
*
|
|
11
|
-
* @_section api/abi/abi-coder:ABI Encoding
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
|
|
15
|
-
|
|
16
|
-
import { assertArgumentCount, assertArgument } from "../utils/index.js";
|
|
17
|
-
|
|
18
|
-
import { Coder, Reader, Result, Writer } from "./coders/abstract-coder.js";
|
|
19
|
-
import { AddressCoder } from "./coders/address.js";
|
|
20
|
-
import { ArrayCoder } from "./coders/array.js";
|
|
21
|
-
import { BooleanCoder } from "./coders/boolean.js";
|
|
22
|
-
import { BytesCoder } from "./coders/bytes.js";
|
|
23
|
-
import { FixedBytesCoder } from "./coders/fixed-bytes.js";
|
|
24
|
-
import { NullCoder } from "./coders/null.js";
|
|
25
|
-
import { NumberCoder } from "./coders/number.js";
|
|
26
|
-
import { StringCoder } from "./coders/string.js";
|
|
27
|
-
import { TupleCoder } from "./coders/tuple.js";
|
|
28
|
-
import { ParamType } from "./fragments.js";
|
|
29
|
-
|
|
30
|
-
import { getAddress } from "../address/index.js";
|
|
31
|
-
import { getBytes, hexlify, makeError } from "../utils/index.js";
|
|
32
|
-
|
|
33
|
-
import type {
|
|
34
|
-
BytesLike,
|
|
35
|
-
CallExceptionAction, CallExceptionError, CallExceptionTransaction
|
|
36
|
-
} from "../utils/index.js";
|
|
37
|
-
|
|
38
|
-
// https://docs.soliditylang.org/en/v0.8.17/control-structures.html
|
|
39
|
-
const PanicReasons: Map<number, string> = new Map();
|
|
40
|
-
PanicReasons.set(0x00, "GENERIC_PANIC");
|
|
41
|
-
PanicReasons.set(0x01, "ASSERT_FALSE");
|
|
42
|
-
PanicReasons.set(0x11, "OVERFLOW");
|
|
43
|
-
PanicReasons.set(0x12, "DIVIDE_BY_ZERO");
|
|
44
|
-
PanicReasons.set(0x21, "ENUM_RANGE_ERROR");
|
|
45
|
-
PanicReasons.set(0x22, "BAD_STORAGE_DATA");
|
|
46
|
-
PanicReasons.set(0x31, "STACK_UNDERFLOW");
|
|
47
|
-
PanicReasons.set(0x32, "ARRAY_RANGE_ERROR");
|
|
48
|
-
PanicReasons.set(0x41, "OUT_OF_MEMORY");
|
|
49
|
-
PanicReasons.set(0x51, "UNINITIALIZED_FUNCTION_CALL");
|
|
50
|
-
|
|
51
|
-
const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
|
|
52
|
-
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
let defaultCoder: null | AbiCoder = null;
|
|
56
|
-
let defaultMaxInflation = 1024;
|
|
57
|
-
|
|
58
|
-
function getBuiltinCallException(action: CallExceptionAction, tx: { to?: null | string, from?: null | string, data?: string }, data: null | BytesLike, abiCoder: AbiCoder): CallExceptionError {
|
|
59
|
-
let message = "missing revert data";
|
|
60
|
-
|
|
61
|
-
let reason: null | string = null;
|
|
62
|
-
const invocation = null;
|
|
63
|
-
let revert: null | { signature: string, name: string, args: Array<any> } = null;
|
|
64
|
-
|
|
65
|
-
if (data) {
|
|
66
|
-
message = "execution reverted";
|
|
67
|
-
|
|
68
|
-
const bytes = getBytes(data);
|
|
69
|
-
data = hexlify(data);
|
|
70
|
-
|
|
71
|
-
if (bytes.length === 0) {
|
|
72
|
-
message += " (no data present; likely require(false) occurred";
|
|
73
|
-
reason = "require(false)";
|
|
74
|
-
|
|
75
|
-
} else if (bytes.length % 32 !== 4) {
|
|
76
|
-
message += " (could not decode reason; invalid data length)";
|
|
77
|
-
|
|
78
|
-
} else if (hexlify(bytes.slice(0, 4)) === "0x08c379a0") {
|
|
79
|
-
// Error(string)
|
|
80
|
-
try {
|
|
81
|
-
reason = abiCoder.decode([ "string" ], bytes.slice(4))[0]
|
|
82
|
-
revert = {
|
|
83
|
-
signature: "Error(string)",
|
|
84
|
-
name: "Error",
|
|
85
|
-
args: [ reason ]
|
|
86
|
-
};
|
|
87
|
-
message += `: ${ JSON.stringify(reason) }`;
|
|
88
|
-
|
|
89
|
-
} catch (error) {
|
|
90
|
-
message += " (could not decode reason; invalid string data)";
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
} else if (hexlify(bytes.slice(0, 4)) === "0x4e487b71") {
|
|
94
|
-
// Panic(uint256)
|
|
95
|
-
try {
|
|
96
|
-
const code = Number(abiCoder.decode([ "uint256" ], bytes.slice(4))[0]);
|
|
97
|
-
revert = {
|
|
98
|
-
signature: "Panic(uint256)",
|
|
99
|
-
name: "Panic",
|
|
100
|
-
args: [ code ]
|
|
101
|
-
};
|
|
102
|
-
reason = `Panic due to ${ PanicReasons.get(code) || "UNKNOWN" }(${ code })`;
|
|
103
|
-
message += `: ${ reason }`;
|
|
104
|
-
} catch (error) {
|
|
105
|
-
message += " (could not decode panic code)";
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
message += " (unknown custom error)";
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const transaction: CallExceptionTransaction = {
|
|
113
|
-
to: (tx.to ? getAddress(tx.to): null),
|
|
114
|
-
data: (tx.data || "0x")
|
|
115
|
-
};
|
|
116
|
-
if (tx.from) { transaction.from = getAddress(tx.from); }
|
|
117
|
-
|
|
118
|
-
return makeError(message, "CALL_EXCEPTION", {
|
|
119
|
-
action, data, reason, transaction, invocation, revert
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* The **AbiCoder** is a low-level class responsible for encoding JavaScript
|
|
125
|
-
* values into binary data and decoding binary data into JavaScript values.
|
|
126
|
-
*/
|
|
127
|
-
export class AbiCoder {
|
|
128
|
-
|
|
129
|
-
#getCoder(param: ParamType): Coder {
|
|
130
|
-
if (param.isArray()) {
|
|
131
|
-
return new ArrayCoder(this.#getCoder(param.arrayChildren), param.arrayLength, param.name);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (param.isTuple()) {
|
|
135
|
-
return new TupleCoder(param.components.map((c) => this.#getCoder(c)), param.name);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
switch (param.baseType) {
|
|
139
|
-
case "address":
|
|
140
|
-
return new AddressCoder(param.name);
|
|
141
|
-
case "bool":
|
|
142
|
-
return new BooleanCoder(param.name);
|
|
143
|
-
case "string":
|
|
144
|
-
return new StringCoder(param.name);
|
|
145
|
-
case "bytes":
|
|
146
|
-
return new BytesCoder(param.name);
|
|
147
|
-
case "":
|
|
148
|
-
return new NullCoder(param.name);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// u?int[0-9]*
|
|
152
|
-
let match = param.type.match(paramTypeNumber);
|
|
153
|
-
if (match) {
|
|
154
|
-
let size = parseInt(match[2] || "256");
|
|
155
|
-
assertArgument(size !== 0 && size <= 256 && (size % 8) === 0,
|
|
156
|
-
"invalid " + match[1] + " bit length", "param", param);
|
|
157
|
-
return new NumberCoder(size / 8, (match[1] === "int"), param.name);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// bytes[0-9]+
|
|
161
|
-
match = param.type.match(paramTypeBytes);
|
|
162
|
-
if (match) {
|
|
163
|
-
let size = parseInt(match[1]);
|
|
164
|
-
assertArgument(size !== 0 && size <= 32, "invalid bytes length", "param", param);
|
|
165
|
-
return new FixedBytesCoder(size, param.name);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
assertArgument(false, "invalid type", "type", param.type);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Get the default values for the given %%types%%.
|
|
173
|
-
*
|
|
174
|
-
* For example, a ``uint`` is by default ``0`` and ``bool``
|
|
175
|
-
* is by default ``false``.
|
|
176
|
-
*/
|
|
177
|
-
getDefaultValue(types: ReadonlyArray<string | ParamType>): Result {
|
|
178
|
-
const coders: Array<Coder> = types.map((type) => this.#getCoder(ParamType.from(type)));
|
|
179
|
-
const coder = new TupleCoder(coders, "_");
|
|
180
|
-
return coder.defaultValue();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Encode the %%values%% as the %%types%% into ABI data.
|
|
185
|
-
*
|
|
186
|
-
* @returns DataHexstring
|
|
187
|
-
*/
|
|
188
|
-
encode(types: ReadonlyArray<string | ParamType>, values: ReadonlyArray<any>): string {
|
|
189
|
-
assertArgumentCount(values.length, types.length, "types/values length mismatch");
|
|
190
|
-
|
|
191
|
-
const coders = types.map((type) => this.#getCoder(ParamType.from(type)));
|
|
192
|
-
const coder = (new TupleCoder(coders, "_"));
|
|
193
|
-
|
|
194
|
-
const writer = new Writer();
|
|
195
|
-
coder.encode(writer, values);
|
|
196
|
-
return writer.data;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Decode the ABI %%data%% as the %%types%% into values.
|
|
201
|
-
*
|
|
202
|
-
* If %%loose%% decoding is enabled, then strict padding is
|
|
203
|
-
* not enforced. Some older versions of Solidity incorrectly
|
|
204
|
-
* padded event data emitted from ``external`` functions.
|
|
205
|
-
*/
|
|
206
|
-
decode(types: ReadonlyArray<string | ParamType>, data: BytesLike, loose?: boolean): Result {
|
|
207
|
-
const coders: Array<Coder> = types.map((type) => this.#getCoder(ParamType.from(type)));
|
|
208
|
-
const coder = new TupleCoder(coders, "_");
|
|
209
|
-
return coder.decode(new Reader(data, loose, defaultMaxInflation));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
static _setDefaultMaxInflation(value: number): void {
|
|
213
|
-
assertArgument(typeof(value) === "number" && Number.isInteger(value), "invalid defaultMaxInflation factor", "value", value);
|
|
214
|
-
defaultMaxInflation = value;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Returns the shared singleton instance of a default [[AbiCoder]].
|
|
219
|
-
*
|
|
220
|
-
* On the first call, the instance is created internally.
|
|
221
|
-
*/
|
|
222
|
-
static defaultAbiCoder(): AbiCoder {
|
|
223
|
-
if (defaultCoder == null) {
|
|
224
|
-
defaultCoder = new AbiCoder();
|
|
225
|
-
}
|
|
226
|
-
return defaultCoder;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Returns an ethers-compatible [[CallExceptionError]] Error for the given
|
|
231
|
-
* result %%data%% for the [[CallExceptionAction]] %%action%% against
|
|
232
|
-
* the Transaction %%tx%%.
|
|
233
|
-
*/
|
|
234
|
-
static getBuiltinCallException(action: CallExceptionAction, tx: { to?: null | string, from?: null | string, data?: string }, data: null | BytesLike): CallExceptionError {
|
|
235
|
-
return getBuiltinCallException(action, tx, data, AbiCoder.defaultAbiCoder());
|
|
236
|
-
}
|
|
237
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* When sending values to or receiving values from a [[Contract]], the
|
|
3
|
+
* data is generally encoded using the [ABI standard](link-solc-abi).
|
|
4
|
+
*
|
|
5
|
+
* The AbiCoder provides a utility to encode values to ABI data and
|
|
6
|
+
* decode values from ABI data.
|
|
7
|
+
*
|
|
8
|
+
* Most of the time, developers should favour the [[Contract]] class,
|
|
9
|
+
* which further abstracts a lot of the finer details of ABI data.
|
|
10
|
+
*
|
|
11
|
+
* @_section api/abi/abi-coder:ABI Encoding
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
|
|
15
|
+
|
|
16
|
+
import { assertArgumentCount, assertArgument } from "../utils/index.js";
|
|
17
|
+
|
|
18
|
+
import { Coder, Reader, Result, Writer } from "./coders/abstract-coder.js";
|
|
19
|
+
import { AddressCoder } from "./coders/address.js";
|
|
20
|
+
import { ArrayCoder } from "./coders/array.js";
|
|
21
|
+
import { BooleanCoder } from "./coders/boolean.js";
|
|
22
|
+
import { BytesCoder } from "./coders/bytes.js";
|
|
23
|
+
import { FixedBytesCoder } from "./coders/fixed-bytes.js";
|
|
24
|
+
import { NullCoder } from "./coders/null.js";
|
|
25
|
+
import { NumberCoder } from "./coders/number.js";
|
|
26
|
+
import { StringCoder } from "./coders/string.js";
|
|
27
|
+
import { TupleCoder } from "./coders/tuple.js";
|
|
28
|
+
import { ParamType } from "./fragments.js";
|
|
29
|
+
|
|
30
|
+
import { getAddress } from "../address/index.js";
|
|
31
|
+
import { getBytes, hexlify, makeError } from "../utils/index.js";
|
|
32
|
+
|
|
33
|
+
import type {
|
|
34
|
+
BytesLike,
|
|
35
|
+
CallExceptionAction, CallExceptionError, CallExceptionTransaction
|
|
36
|
+
} from "../utils/index.js";
|
|
37
|
+
|
|
38
|
+
// https://docs.soliditylang.org/en/v0.8.17/control-structures.html
|
|
39
|
+
const PanicReasons: Map<number, string> = new Map();
|
|
40
|
+
PanicReasons.set(0x00, "GENERIC_PANIC");
|
|
41
|
+
PanicReasons.set(0x01, "ASSERT_FALSE");
|
|
42
|
+
PanicReasons.set(0x11, "OVERFLOW");
|
|
43
|
+
PanicReasons.set(0x12, "DIVIDE_BY_ZERO");
|
|
44
|
+
PanicReasons.set(0x21, "ENUM_RANGE_ERROR");
|
|
45
|
+
PanicReasons.set(0x22, "BAD_STORAGE_DATA");
|
|
46
|
+
PanicReasons.set(0x31, "STACK_UNDERFLOW");
|
|
47
|
+
PanicReasons.set(0x32, "ARRAY_RANGE_ERROR");
|
|
48
|
+
PanicReasons.set(0x41, "OUT_OF_MEMORY");
|
|
49
|
+
PanicReasons.set(0x51, "UNINITIALIZED_FUNCTION_CALL");
|
|
50
|
+
|
|
51
|
+
const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
|
|
52
|
+
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
let defaultCoder: null | AbiCoder = null;
|
|
56
|
+
let defaultMaxInflation = 1024;
|
|
57
|
+
|
|
58
|
+
function getBuiltinCallException(action: CallExceptionAction, tx: { to?: null | string, from?: null | string, data?: string }, data: null | BytesLike, abiCoder: AbiCoder): CallExceptionError {
|
|
59
|
+
let message = "missing revert data";
|
|
60
|
+
|
|
61
|
+
let reason: null | string = null;
|
|
62
|
+
const invocation = null;
|
|
63
|
+
let revert: null | { signature: string, name: string, args: Array<any> } = null;
|
|
64
|
+
|
|
65
|
+
if (data) {
|
|
66
|
+
message = "execution reverted";
|
|
67
|
+
|
|
68
|
+
const bytes = getBytes(data);
|
|
69
|
+
data = hexlify(data);
|
|
70
|
+
|
|
71
|
+
if (bytes.length === 0) {
|
|
72
|
+
message += " (no data present; likely require(false) occurred";
|
|
73
|
+
reason = "require(false)";
|
|
74
|
+
|
|
75
|
+
} else if (bytes.length % 32 !== 4) {
|
|
76
|
+
message += " (could not decode reason; invalid data length)";
|
|
77
|
+
|
|
78
|
+
} else if (hexlify(bytes.slice(0, 4)) === "0x08c379a0") {
|
|
79
|
+
// Error(string)
|
|
80
|
+
try {
|
|
81
|
+
reason = abiCoder.decode([ "string" ], bytes.slice(4))[0]
|
|
82
|
+
revert = {
|
|
83
|
+
signature: "Error(string)",
|
|
84
|
+
name: "Error",
|
|
85
|
+
args: [ reason ]
|
|
86
|
+
};
|
|
87
|
+
message += `: ${ JSON.stringify(reason) }`;
|
|
88
|
+
|
|
89
|
+
} catch (error) {
|
|
90
|
+
message += " (could not decode reason; invalid string data)";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
} else if (hexlify(bytes.slice(0, 4)) === "0x4e487b71") {
|
|
94
|
+
// Panic(uint256)
|
|
95
|
+
try {
|
|
96
|
+
const code = Number(abiCoder.decode([ "uint256" ], bytes.slice(4))[0]);
|
|
97
|
+
revert = {
|
|
98
|
+
signature: "Panic(uint256)",
|
|
99
|
+
name: "Panic",
|
|
100
|
+
args: [ code ]
|
|
101
|
+
};
|
|
102
|
+
reason = `Panic due to ${ PanicReasons.get(code) || "UNKNOWN" }(${ code })`;
|
|
103
|
+
message += `: ${ reason }`;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
message += " (could not decode panic code)";
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
message += " (unknown custom error)";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const transaction: CallExceptionTransaction = {
|
|
113
|
+
to: (tx.to ? getAddress(tx.to): null),
|
|
114
|
+
data: (tx.data || "0x")
|
|
115
|
+
};
|
|
116
|
+
if (tx.from) { transaction.from = getAddress(tx.from); }
|
|
117
|
+
|
|
118
|
+
return makeError(message, "CALL_EXCEPTION", {
|
|
119
|
+
action, data, reason, transaction, invocation, revert
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The **AbiCoder** is a low-level class responsible for encoding JavaScript
|
|
125
|
+
* values into binary data and decoding binary data into JavaScript values.
|
|
126
|
+
*/
|
|
127
|
+
export class AbiCoder {
|
|
128
|
+
|
|
129
|
+
#getCoder(param: ParamType): Coder {
|
|
130
|
+
if (param.isArray()) {
|
|
131
|
+
return new ArrayCoder(this.#getCoder(param.arrayChildren), param.arrayLength, param.name);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (param.isTuple()) {
|
|
135
|
+
return new TupleCoder(param.components.map((c) => this.#getCoder(c)), param.name);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
switch (param.baseType) {
|
|
139
|
+
case "address":
|
|
140
|
+
return new AddressCoder(param.name);
|
|
141
|
+
case "bool":
|
|
142
|
+
return new BooleanCoder(param.name);
|
|
143
|
+
case "string":
|
|
144
|
+
return new StringCoder(param.name);
|
|
145
|
+
case "bytes":
|
|
146
|
+
return new BytesCoder(param.name);
|
|
147
|
+
case "":
|
|
148
|
+
return new NullCoder(param.name);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// u?int[0-9]*
|
|
152
|
+
let match = param.type.match(paramTypeNumber);
|
|
153
|
+
if (match) {
|
|
154
|
+
let size = parseInt(match[2] || "256");
|
|
155
|
+
assertArgument(size !== 0 && size <= 256 && (size % 8) === 0,
|
|
156
|
+
"invalid " + match[1] + " bit length", "param", param);
|
|
157
|
+
return new NumberCoder(size / 8, (match[1] === "int"), param.name);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// bytes[0-9]+
|
|
161
|
+
match = param.type.match(paramTypeBytes);
|
|
162
|
+
if (match) {
|
|
163
|
+
let size = parseInt(match[1]);
|
|
164
|
+
assertArgument(size !== 0 && size <= 32, "invalid bytes length", "param", param);
|
|
165
|
+
return new FixedBytesCoder(size, param.name);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
assertArgument(false, "invalid type", "type", param.type);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get the default values for the given %%types%%.
|
|
173
|
+
*
|
|
174
|
+
* For example, a ``uint`` is by default ``0`` and ``bool``
|
|
175
|
+
* is by default ``false``.
|
|
176
|
+
*/
|
|
177
|
+
getDefaultValue(types: ReadonlyArray<string | ParamType>): Result {
|
|
178
|
+
const coders: Array<Coder> = types.map((type) => this.#getCoder(ParamType.from(type)));
|
|
179
|
+
const coder = new TupleCoder(coders, "_");
|
|
180
|
+
return coder.defaultValue();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Encode the %%values%% as the %%types%% into ABI data.
|
|
185
|
+
*
|
|
186
|
+
* @returns DataHexstring
|
|
187
|
+
*/
|
|
188
|
+
encode(types: ReadonlyArray<string | ParamType>, values: ReadonlyArray<any>): string {
|
|
189
|
+
assertArgumentCount(values.length, types.length, "types/values length mismatch");
|
|
190
|
+
|
|
191
|
+
const coders = types.map((type) => this.#getCoder(ParamType.from(type)));
|
|
192
|
+
const coder = (new TupleCoder(coders, "_"));
|
|
193
|
+
|
|
194
|
+
const writer = new Writer();
|
|
195
|
+
coder.encode(writer, values);
|
|
196
|
+
return writer.data;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Decode the ABI %%data%% as the %%types%% into values.
|
|
201
|
+
*
|
|
202
|
+
* If %%loose%% decoding is enabled, then strict padding is
|
|
203
|
+
* not enforced. Some older versions of Solidity incorrectly
|
|
204
|
+
* padded event data emitted from ``external`` functions.
|
|
205
|
+
*/
|
|
206
|
+
decode(types: ReadonlyArray<string | ParamType>, data: BytesLike, loose?: boolean): Result {
|
|
207
|
+
const coders: Array<Coder> = types.map((type) => this.#getCoder(ParamType.from(type)));
|
|
208
|
+
const coder = new TupleCoder(coders, "_");
|
|
209
|
+
return coder.decode(new Reader(data, loose, defaultMaxInflation));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
static _setDefaultMaxInflation(value: number): void {
|
|
213
|
+
assertArgument(typeof(value) === "number" && Number.isInteger(value), "invalid defaultMaxInflation factor", "value", value);
|
|
214
|
+
defaultMaxInflation = value;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Returns the shared singleton instance of a default [[AbiCoder]].
|
|
219
|
+
*
|
|
220
|
+
* On the first call, the instance is created internally.
|
|
221
|
+
*/
|
|
222
|
+
static defaultAbiCoder(): AbiCoder {
|
|
223
|
+
if (defaultCoder == null) {
|
|
224
|
+
defaultCoder = new AbiCoder();
|
|
225
|
+
}
|
|
226
|
+
return defaultCoder;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Returns an ethers-compatible [[CallExceptionError]] Error for the given
|
|
231
|
+
* result %%data%% for the [[CallExceptionAction]] %%action%% against
|
|
232
|
+
* the Transaction %%tx%%.
|
|
233
|
+
*/
|
|
234
|
+
static getBuiltinCallException(action: CallExceptionAction, tx: { to?: null | string, from?: null | string, data?: string }, data: null | BytesLike): CallExceptionError {
|
|
235
|
+
return getBuiltinCallException(action, tx, data, AbiCoder.defaultAbiCoder());
|
|
236
|
+
}
|
|
237
|
+
}
|