quantumcoin 6.14.1 → 6.14.2
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/README.md +2 -0
- package/dist/quantumcoin.js +2697 -7812
- package/dist/quantumcoin.js.map +1 -1
- package/dist/quantumcoin.min.js +1 -1
- package/dist/quantumcoin.min.js'.gz' +0 -0
- package/dist/quantumcoin.umd.js +2698 -7835
- package/dist/quantumcoin.umd.js.map +1 -1
- package/dist/quantumcoin.umd.min.js +1 -1
- package/dist/quantumcoin.umd.min.js'.gz' +0 -0
- package/dist/wordlists-extra.min.js'.gz' +0 -0
- package/lib.commonjs/address/address.d.ts +1 -21
- package/lib.commonjs/address/address.d.ts.map +1 -1
- package/lib.commonjs/address/address.js +2 -30
- package/lib.commonjs/address/address.js.map +1 -1
- package/lib.commonjs/address/index.d.ts +1 -1
- package/lib.commonjs/address/index.d.ts.map +1 -1
- package/lib.commonjs/address/index.js +1 -2
- package/lib.commonjs/address/index.js.map +1 -1
- package/lib.commonjs/crypto/signature.d.ts +4 -17
- package/lib.commonjs/crypto/signature.d.ts.map +1 -1
- package/lib.commonjs/crypto/signature.js +57 -60
- package/lib.commonjs/crypto/signature.js.map +1 -1
- package/lib.commonjs/crypto/signing-key.d.ts +5 -64
- package/lib.commonjs/crypto/signing-key.d.ts.map +1 -1
- package/lib.commonjs/crypto/signing-key.js +27 -101
- package/lib.commonjs/crypto/signing-key.js.map +1 -1
- package/lib.commonjs/providers/default-provider.d.ts +0 -8
- package/lib.commonjs/providers/default-provider.d.ts.map +1 -1
- package/lib.commonjs/providers/default-provider.js +0 -108
- package/lib.commonjs/providers/default-provider.js.map +1 -1
- package/lib.commonjs/providers/index.d.ts +0 -9
- package/lib.commonjs/providers/index.d.ts.map +1 -1
- package/lib.commonjs/providers/index.js +1 -21
- package/lib.commonjs/providers/index.js.map +1 -1
- package/lib.commonjs/providers/network.js +1 -99
- package/lib.commonjs/providers/network.js.map +1 -1
- package/lib.commonjs/quantumcoin.d.ts +4 -4
- package/lib.commonjs/quantumcoin.d.ts.map +1 -1
- package/lib.commonjs/quantumcoin.js +4 -26
- package/lib.commonjs/quantumcoin.js.map +1 -1
- package/lib.commonjs/transaction/address.d.ts +1 -1
- package/lib.commonjs/transaction/address.d.ts.map +1 -1
- package/lib.commonjs/transaction/address.js +9 -5
- package/lib.commonjs/transaction/address.js.map +1 -1
- package/lib.commonjs/wallet/hdwallet.d.ts.map +1 -1
- package/lib.commonjs/wallet/hdwallet.js +4 -5
- package/lib.commonjs/wallet/hdwallet.js.map +1 -1
- package/lib.commonjs/wallet/index.d.ts +2 -6
- package/lib.commonjs/wallet/index.d.ts.map +1 -1
- package/lib.commonjs/wallet/index.js +1 -14
- package/lib.commonjs/wallet/index.js.map +1 -1
- package/lib.commonjs/wallet/json-keystore.d.ts +3 -52
- package/lib.commonjs/wallet/json-keystore.d.ts.map +1 -1
- package/lib.commonjs/wallet/json-keystore.js +41 -246
- package/lib.commonjs/wallet/json-keystore.js.map +1 -1
- package/lib.commonjs/wallet/seedwallet.d.ts +4 -0
- package/lib.commonjs/wallet/seedwallet.d.ts.map +1 -0
- package/lib.commonjs/wallet/seedwallet.js +8 -0
- package/lib.commonjs/wallet/seedwallet.js.map +1 -0
- package/lib.commonjs/wallet/wallet.d.ts +5 -14
- package/lib.commonjs/wallet/wallet.d.ts.map +1 -1
- package/lib.commonjs/wallet/wallet.js +12 -51
- package/lib.commonjs/wallet/wallet.js.map +1 -1
- package/lib.esm/address/address.d.ts +1 -21
- package/lib.esm/address/address.d.ts.map +1 -1
- package/lib.esm/address/address.js +1 -28
- package/lib.esm/address/address.js.map +1 -1
- package/lib.esm/address/index.d.ts +1 -1
- package/lib.esm/address/index.d.ts.map +1 -1
- package/lib.esm/address/index.js +1 -1
- package/lib.esm/address/index.js.map +1 -1
- package/lib.esm/crypto/signature.d.ts +4 -17
- package/lib.esm/crypto/signature.d.ts.map +1 -1
- package/lib.esm/crypto/signature.js +45 -46
- package/lib.esm/crypto/signature.js.map +1 -1
- package/lib.esm/crypto/signing-key.d.ts +5 -64
- package/lib.esm/crypto/signing-key.d.ts.map +1 -1
- package/lib.esm/crypto/signing-key.js +26 -102
- package/lib.esm/crypto/signing-key.js.map +1 -1
- package/lib.esm/providers/default-provider.d.ts +0 -8
- package/lib.esm/providers/default-provider.d.ts.map +1 -1
- package/lib.esm/providers/default-provider.js +0 -108
- package/lib.esm/providers/default-provider.js.map +1 -1
- package/lib.esm/providers/index.d.ts +0 -9
- package/lib.esm/providers/index.d.ts.map +1 -1
- package/lib.esm/providers/index.js +0 -9
- package/lib.esm/providers/index.js.map +1 -1
- package/lib.esm/providers/network.js +3 -101
- package/lib.esm/providers/network.js.map +1 -1
- package/lib.esm/quantumcoin.d.ts +4 -4
- package/lib.esm/quantumcoin.d.ts.map +1 -1
- package/lib.esm/quantumcoin.js +3 -3
- package/lib.esm/quantumcoin.js.map +1 -1
- package/lib.esm/transaction/address.d.ts +1 -1
- package/lib.esm/transaction/address.d.ts.map +1 -1
- package/lib.esm/transaction/address.js +7 -4
- package/lib.esm/transaction/address.js.map +1 -1
- package/lib.esm/wallet/hdwallet.d.ts.map +1 -1
- package/lib.esm/wallet/hdwallet.js +4 -5
- package/lib.esm/wallet/hdwallet.js.map +1 -1
- package/lib.esm/wallet/index.d.ts +2 -6
- package/lib.esm/wallet/index.d.ts.map +1 -1
- package/lib.esm/wallet/index.js +1 -4
- package/lib.esm/wallet/index.js.map +1 -1
- package/lib.esm/wallet/json-keystore.d.ts +3 -52
- package/lib.esm/wallet/json-keystore.d.ts.map +1 -1
- package/lib.esm/wallet/json-keystore.js +32 -241
- package/lib.esm/wallet/json-keystore.js.map +1 -1
- package/lib.esm/wallet/seedwallet.d.ts +4 -0
- package/lib.esm/wallet/seedwallet.d.ts.map +1 -0
- package/lib.esm/wallet/seedwallet.js +4 -0
- package/lib.esm/wallet/seedwallet.js.map +1 -0
- package/lib.esm/wallet/wallet.d.ts +5 -14
- package/lib.esm/wallet/wallet.d.ts.map +1 -1
- package/lib.esm/wallet/wallet.js +12 -53
- package/lib.esm/wallet/wallet.js.map +1 -1
- package/package.json +5 -2
- package/src.ts/address/address.ts +2 -27
- package/src.ts/address/index.ts +1 -1
- package/src.ts/crypto/signature.ts +31 -45
- package/src.ts/crypto/signing-key.ts +31 -109
- package/src.ts/providers/default-provider.ts +0 -106
- package/src.ts/providers/index.ts +0 -10
- package/src.ts/providers/network.ts +3 -111
- package/src.ts/quantumcoin.ts +7 -17
- package/src.ts/transaction/address.ts +8 -5
- package/src.ts/wallet/index.ts +2 -17
- package/src.ts/wallet/json-keystore.ts +42 -325
- package/src.ts/wallet/wallet.ts +23 -47
- package/src.ts/providers/provider-alchemy.ts +0 -166
- package/src.ts/providers/provider-ankr.ts +0 -153
- package/src.ts/providers/provider-blockscout.ts +0 -167
- package/src.ts/providers/provider-chainstack.ts +0 -113
- package/src.ts/providers/provider-cloudflare.ts +0 -24
- package/src.ts/providers/provider-etherscan.ts +0 -671
- package/src.ts/providers/provider-infura.ts +0 -220
- package/src.ts/providers/provider-pocket.ts +0 -121
- package/src.ts/providers/provider-quicknode.ts +0 -177
- package/src.ts/wallet/hdwallet.ts +0 -586
- package/src.ts/wallet/json-crowdsale.ts +0 -74
- package/src.ts/wallet/mnemonic.ts +0 -203
package/src.ts/wallet/wallet.ts
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import { SigningKey } from "../crypto/index.js";
|
|
2
|
-
import { assertArgument } from "../utils/index.js";
|
|
2
|
+
import { assertArgument,hexlify } from "../utils/index.js";
|
|
3
3
|
|
|
4
4
|
import { BaseWallet } from "./base-wallet.js";
|
|
5
|
-
|
|
6
|
-
import { decryptCrowdsaleJson, isCrowdsaleJson } from "./json-crowdsale.js";
|
|
5
|
+
|
|
6
|
+
//import { decryptCrowdsaleJson, isCrowdsaleJson } from "./json-crowdsale.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
decryptKeystoreJsonSync,
|
|
9
|
+
encryptKeystoreJsonSync,
|
|
10
10
|
isKeystoreJson
|
|
11
11
|
} from "./json-keystore.js";
|
|
12
|
-
import { Mnemonic } from "./mnemonic.js";
|
|
12
|
+
//import { Mnemonic } from "./mnemonic.js";
|
|
13
|
+
import qcsdk = require('quantum-coin-js-sdk');
|
|
13
14
|
|
|
14
|
-
import type { ProgressCallback } from "../crypto/index.js";
|
|
15
15
|
import type { Provider } from "../providers/index.js";
|
|
16
16
|
|
|
17
|
-
import type { CrowdsaleAccount } from "./json-crowdsale.js";
|
|
18
17
|
import type { KeystoreAccount } from "./json-keystore.js";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function stall(duration: number): Promise<void> {
|
|
22
|
-
return new Promise((resolve) => { setTimeout(() => { resolve(); }, duration); });
|
|
23
|
-
}
|
|
18
|
+
//import {newWallet} from "quantum-coin-js-sdk";
|
|
24
19
|
|
|
25
20
|
/**
|
|
26
21
|
* A **Wallet** manages a single private key which is used to sign
|
|
@@ -58,9 +53,9 @@ export class Wallet extends BaseWallet {
|
|
|
58
53
|
* If %%progressCallback%% is specified, it will receive periodic
|
|
59
54
|
* updates as the encryption process progreses.
|
|
60
55
|
*/
|
|
61
|
-
async encrypt(password: Uint8Array | string
|
|
56
|
+
async encrypt(password: Uint8Array | string): Promise<string> {
|
|
62
57
|
const account = { address: this.address, privateKey: this.privateKey };
|
|
63
|
-
return
|
|
58
|
+
return encryptKeystoreJsonSync(account, password);
|
|
64
59
|
}
|
|
65
60
|
|
|
66
61
|
/**
|
|
@@ -78,18 +73,9 @@ export class Wallet extends BaseWallet {
|
|
|
78
73
|
return encryptKeystoreJsonSync(account, password);
|
|
79
74
|
}
|
|
80
75
|
|
|
81
|
-
static #fromAccount(account: null |
|
|
76
|
+
static #fromAccount(account: null | KeystoreAccount): Wallet {
|
|
82
77
|
assertArgument(account, "invalid JSON wallet", "json", "[ REDACTED ]");
|
|
83
78
|
|
|
84
|
-
if ("mnemonic" in account && account.mnemonic && account.mnemonic.locale === "en") {
|
|
85
|
-
const mnemonic = Mnemonic.fromEntropy(account.mnemonic.entropy);
|
|
86
|
-
const wallet = HDNodeWallet.fromMnemonic(mnemonic, account.mnemonic.path);
|
|
87
|
-
if (wallet.address === account.address && wallet.privateKey === account.privateKey) {
|
|
88
|
-
return wallet;
|
|
89
|
-
}
|
|
90
|
-
console.log("WARNING: JSON mismatch address/privateKey != mnemonic; fallback onto private key");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
79
|
const wallet = new Wallet(account.privateKey);
|
|
94
80
|
|
|
95
81
|
assertArgument(wallet.address === account.address,
|
|
@@ -101,19 +87,11 @@ export class Wallet extends BaseWallet {
|
|
|
101
87
|
/**
|
|
102
88
|
* Creates (asynchronously) a **Wallet** by decrypting the %%json%%
|
|
103
89
|
* with %%password%%.
|
|
104
|
-
*
|
|
105
|
-
* If %%progress%% is provided, it is called periodically during
|
|
106
|
-
* decryption so that any UI can be updated.
|
|
107
90
|
*/
|
|
108
|
-
static async fromEncryptedJson(json: string, password: Uint8Array | string
|
|
109
|
-
let account: null |
|
|
91
|
+
static async fromEncryptedJson(json: string, password: Uint8Array | string): Promise<Wallet> {
|
|
92
|
+
let account: null | KeystoreAccount = null;
|
|
110
93
|
if (isKeystoreJson(json)) {
|
|
111
|
-
account =
|
|
112
|
-
|
|
113
|
-
} else if (isCrowdsaleJson(json)) {
|
|
114
|
-
if (progress) { progress(0); await stall(0); }
|
|
115
|
-
account = decryptCrowdsaleJson(json, password);
|
|
116
|
-
if (progress) { progress(1); await stall(0); }
|
|
94
|
+
account = decryptKeystoreJsonSync(json, password);
|
|
117
95
|
|
|
118
96
|
}
|
|
119
97
|
|
|
@@ -127,12 +105,10 @@ export class Wallet extends BaseWallet {
|
|
|
127
105
|
* will lock up and freeze the UI during decryption, which may take
|
|
128
106
|
* some time.
|
|
129
107
|
*/
|
|
130
|
-
static fromEncryptedJsonSync(json: string, password: Uint8Array | string):
|
|
131
|
-
let account: null |
|
|
108
|
+
static fromEncryptedJsonSync(json: string, password: Uint8Array | string): Wallet {
|
|
109
|
+
let account: null | KeystoreAccount = null;
|
|
132
110
|
if (isKeystoreJson(json)) {
|
|
133
111
|
account = decryptKeystoreJsonSync(json, password);
|
|
134
|
-
} else if (isCrowdsaleJson(json)) {
|
|
135
|
-
account = decryptCrowdsaleJson(json, password);
|
|
136
112
|
} else {
|
|
137
113
|
assertArgument(false, "invalid JSON wallet", "json", "[ REDACTED ]");
|
|
138
114
|
}
|
|
@@ -141,23 +117,23 @@ export class Wallet extends BaseWallet {
|
|
|
141
117
|
}
|
|
142
118
|
|
|
143
119
|
/**
|
|
144
|
-
* Creates a new random [[
|
|
120
|
+
* Creates a new random [[Wallet]] using the available
|
|
145
121
|
* [cryptographic random source](randomBytes).
|
|
146
122
|
*
|
|
147
123
|
* If there is no crytographic random source, this will throw.
|
|
148
124
|
*/
|
|
149
|
-
static createRandom(provider?: null | Provider):
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return
|
|
125
|
+
static createRandom(provider?: null | Provider): Wallet {
|
|
126
|
+
let wal = qcsdk.newWallet();
|
|
127
|
+
let privKey: any = wal.privateKey;
|
|
128
|
+
return new Wallet(hexlify(privKey));
|
|
153
129
|
}
|
|
154
130
|
|
|
155
131
|
/**
|
|
156
132
|
* Creates a [[HDNodeWallet]] for %%phrase%%.
|
|
157
|
-
|
|
133
|
+
*//*
|
|
158
134
|
static fromPhrase(phrase: string, provider?: Provider): HDNodeWallet {
|
|
159
135
|
const wallet = HDNodeWallet.fromPhrase(phrase);
|
|
160
136
|
if (provider) { return wallet.connect(provider); }
|
|
161
137
|
return wallet;
|
|
162
|
-
}
|
|
138
|
+
}*/
|
|
163
139
|
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* [[link-alchemy]] provides a third-party service for connecting to
|
|
3
|
-
* various blockchains over JSON-RPC.
|
|
4
|
-
*
|
|
5
|
-
* **Supported Networks**
|
|
6
|
-
*
|
|
7
|
-
* - Ethereum Mainnet (``mainnet``)
|
|
8
|
-
* - Goerli Testnet (``goerli``)
|
|
9
|
-
* - Sepolia Testnet (``sepolia``)
|
|
10
|
-
* - Arbitrum (``arbitrum``)
|
|
11
|
-
* - Arbitrum Goerli Testnet (``arbitrum-goerli``)
|
|
12
|
-
* - Arbitrum Sepolia Testnet (``arbitrum-sepolia``)
|
|
13
|
-
* - Base (``base``)
|
|
14
|
-
* - Base Goerlia Testnet (``base-goerli``)
|
|
15
|
-
* - Base Sepolia Testnet (``base-sepolia``)
|
|
16
|
-
* - Optimism (``optimism``)
|
|
17
|
-
* - Optimism Goerli Testnet (``optimism-goerli``)
|
|
18
|
-
* - Optimism Sepolia Testnet (``optimism-sepolia``)
|
|
19
|
-
* - Polygon (``matic``)
|
|
20
|
-
* - Polygon Amoy Testnet (``matic-amoy``)
|
|
21
|
-
* - Polygon Mumbai Testnet (``matic-mumbai``)
|
|
22
|
-
*
|
|
23
|
-
* @_subsection: api/providers/thirdparty:Alchemy [providers-alchemy]
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import {
|
|
27
|
-
defineProperties, resolveProperties, assert, assertArgument,
|
|
28
|
-
FetchRequest
|
|
29
|
-
} from "../utils/index.js";
|
|
30
|
-
|
|
31
|
-
import { showThrottleMessage } from "./community.js";
|
|
32
|
-
import { Network } from "./network.js";
|
|
33
|
-
import { JsonRpcProvider } from "./provider-jsonrpc.js";
|
|
34
|
-
|
|
35
|
-
import type { AbstractProvider, PerformActionRequest } from "./abstract-provider.js";
|
|
36
|
-
import type { CommunityResourcable } from "./community.js";
|
|
37
|
-
import type { Networkish } from "./network.js";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const defaultApiKey = "_gg7wSSi0KMBsdKnGVfHDueq6xMB9EkC"
|
|
41
|
-
|
|
42
|
-
function getHost(name: string): string {
|
|
43
|
-
switch(name) {
|
|
44
|
-
case "mainnet":
|
|
45
|
-
return "eth-mainnet.alchemyapi.io";
|
|
46
|
-
case "goerli":
|
|
47
|
-
return "eth-goerli.g.alchemy.com";
|
|
48
|
-
case "sepolia":
|
|
49
|
-
return "eth-sepolia.g.alchemy.com";
|
|
50
|
-
|
|
51
|
-
case "arbitrum":
|
|
52
|
-
return "arb-mainnet.g.alchemy.com";
|
|
53
|
-
case "arbitrum-goerli":
|
|
54
|
-
return "arb-goerli.g.alchemy.com";
|
|
55
|
-
case "arbitrum-sepolia":
|
|
56
|
-
return "arb-sepolia.g.alchemy.com";
|
|
57
|
-
case "base":
|
|
58
|
-
return "base-mainnet.g.alchemy.com";
|
|
59
|
-
case "base-goerli":
|
|
60
|
-
return "base-goerli.g.alchemy.com";
|
|
61
|
-
case "base-sepolia":
|
|
62
|
-
return "base-sepolia.g.alchemy.com";
|
|
63
|
-
case "matic":
|
|
64
|
-
return "polygon-mainnet.g.alchemy.com";
|
|
65
|
-
case "matic-amoy":
|
|
66
|
-
return "polygon-amoy.g.alchemy.com";
|
|
67
|
-
case "matic-mumbai":
|
|
68
|
-
return "polygon-mumbai.g.alchemy.com";
|
|
69
|
-
case "optimism":
|
|
70
|
-
return "opt-mainnet.g.alchemy.com";
|
|
71
|
-
case "optimism-goerli":
|
|
72
|
-
return "opt-goerli.g.alchemy.com";
|
|
73
|
-
case "optimism-sepolia":
|
|
74
|
-
return "opt-sepolia.g.alchemy.com";
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
assertArgument(false, "unsupported network", "network", name);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* The **AlchemyProvider** connects to the [[link-alchemy]]
|
|
82
|
-
* JSON-RPC end-points.
|
|
83
|
-
*
|
|
84
|
-
* By default, a highly-throttled API key is used, which is
|
|
85
|
-
* appropriate for quick prototypes and simple scripts. To
|
|
86
|
-
* gain access to an increased rate-limit, it is highly
|
|
87
|
-
* recommended to [sign up here](link-alchemy-signup).
|
|
88
|
-
*
|
|
89
|
-
* @_docloc: api/providers/thirdparty
|
|
90
|
-
*/
|
|
91
|
-
export class AlchemyProvider extends JsonRpcProvider implements CommunityResourcable {
|
|
92
|
-
readonly apiKey!: string;
|
|
93
|
-
|
|
94
|
-
constructor(_network?: Networkish, apiKey?: null | string) {
|
|
95
|
-
if (_network == null) { _network = "mainnet"; }
|
|
96
|
-
const network = Network.from(_network);
|
|
97
|
-
if (apiKey == null) { apiKey = defaultApiKey; }
|
|
98
|
-
|
|
99
|
-
const request = AlchemyProvider.getRequest(network, apiKey);
|
|
100
|
-
super(request, network, { staticNetwork: network });
|
|
101
|
-
|
|
102
|
-
defineProperties<AlchemyProvider>(this, { apiKey });
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
_getProvider(chainId: number): AbstractProvider {
|
|
106
|
-
try {
|
|
107
|
-
return new AlchemyProvider(chainId, this.apiKey);
|
|
108
|
-
} catch (error) { }
|
|
109
|
-
return super._getProvider(chainId);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async _perform(req: PerformActionRequest): Promise<any> {
|
|
113
|
-
|
|
114
|
-
// https://docs.alchemy.com/reference/trace-transaction
|
|
115
|
-
if (req.method === "getTransactionResult") {
|
|
116
|
-
const { trace, tx } = await resolveProperties({
|
|
117
|
-
trace: this.send("trace_transaction", [ req.hash ]),
|
|
118
|
-
tx: this.getTransaction(req.hash)
|
|
119
|
-
});
|
|
120
|
-
if (trace == null || tx == null) { return null; }
|
|
121
|
-
|
|
122
|
-
let data: undefined | string;
|
|
123
|
-
let error = false;
|
|
124
|
-
try {
|
|
125
|
-
data = trace[0].result.output;
|
|
126
|
-
error = (trace[0].error === "Reverted");
|
|
127
|
-
} catch (error) { }
|
|
128
|
-
|
|
129
|
-
if (data) {
|
|
130
|
-
assert(!error, "an error occurred during transaction executions", "CALL_EXCEPTION", {
|
|
131
|
-
action: "getTransactionResult",
|
|
132
|
-
data,
|
|
133
|
-
reason: null,
|
|
134
|
-
transaction: tx,
|
|
135
|
-
invocation: null,
|
|
136
|
-
revert: null // @TODO
|
|
137
|
-
});
|
|
138
|
-
return data;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
assert(false, "could not parse trace result", "BAD_DATA", { value: trace });
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return await super._perform(req);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
isCommunityResource(): boolean {
|
|
148
|
-
return (this.apiKey === defaultApiKey);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
static getRequest(network: Network, apiKey?: string): FetchRequest {
|
|
152
|
-
if (apiKey == null) { apiKey = defaultApiKey; }
|
|
153
|
-
|
|
154
|
-
const request = new FetchRequest(`https:/\/${ getHost(network.name) }/v2/${ apiKey }`);
|
|
155
|
-
request.allowGzip = true;
|
|
156
|
-
|
|
157
|
-
if (apiKey === defaultApiKey) {
|
|
158
|
-
request.retryFunc = async (request, response, attempt) => {
|
|
159
|
-
showThrottleMessage("alchemy");
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return request;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* [[link-ankr]] provides a third-party service for connecting to
|
|
3
|
-
* various blockchains over JSON-RPC.
|
|
4
|
-
*
|
|
5
|
-
* **Supported Networks**
|
|
6
|
-
*
|
|
7
|
-
* - Ethereum Mainnet (``mainnet``)
|
|
8
|
-
* - Goerli Testnet (``goerli``)
|
|
9
|
-
* - Sepolia Testnet (``sepolia``)
|
|
10
|
-
* - Arbitrum (``arbitrum``)
|
|
11
|
-
* - Base (``base``)
|
|
12
|
-
* - Base Goerlia Testnet (``base-goerli``)
|
|
13
|
-
* - Base Sepolia Testnet (``base-sepolia``)
|
|
14
|
-
* - BNB (``bnb``)
|
|
15
|
-
* - BNB Testnet (``bnbt``)
|
|
16
|
-
* - Optimism (``optimism``)
|
|
17
|
-
* - Optimism Goerli Testnet (``optimism-goerli``)
|
|
18
|
-
* - Optimism Sepolia Testnet (``optimism-sepolia``)
|
|
19
|
-
* - Polygon (``matic``)
|
|
20
|
-
* - Polygon Mumbai Testnet (``matic-mumbai``)
|
|
21
|
-
*
|
|
22
|
-
* @_subsection: api/providers/thirdparty:Ankr [providers-ankr]
|
|
23
|
-
*/
|
|
24
|
-
import {
|
|
25
|
-
defineProperties, FetchRequest, assertArgument
|
|
26
|
-
} from "../utils/index.js";
|
|
27
|
-
|
|
28
|
-
import { AbstractProvider } from "./abstract-provider.js";
|
|
29
|
-
import { showThrottleMessage } from "./community.js";
|
|
30
|
-
import { Network } from "./network.js";
|
|
31
|
-
import { JsonRpcProvider } from "./provider-jsonrpc.js";
|
|
32
|
-
|
|
33
|
-
import type { CommunityResourcable } from "./community.js";
|
|
34
|
-
import type { Networkish } from "./network.js";
|
|
35
|
-
import type { JsonRpcError, JsonRpcPayload } from "./provider-jsonrpc.js";
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const defaultApiKey = "9f7d929b018cdffb338517efa06f58359e86ff1ffd350bc889738523659e7972";
|
|
39
|
-
|
|
40
|
-
function getHost(name: string): string {
|
|
41
|
-
switch (name) {
|
|
42
|
-
case "mainnet":
|
|
43
|
-
return "rpc.ankr.com/eth";
|
|
44
|
-
case "goerli":
|
|
45
|
-
return "rpc.ankr.com/eth_goerli";
|
|
46
|
-
case "sepolia":
|
|
47
|
-
return "rpc.ankr.com/eth_sepolia";
|
|
48
|
-
|
|
49
|
-
case "arbitrum":
|
|
50
|
-
return "rpc.ankr.com/arbitrum";
|
|
51
|
-
case "base":
|
|
52
|
-
return "rpc.ankr.com/base";
|
|
53
|
-
case "base-goerli":
|
|
54
|
-
return "rpc.ankr.com/base_goerli";
|
|
55
|
-
case "base-sepolia":
|
|
56
|
-
return "rpc.ankr.com/base_sepolia";
|
|
57
|
-
case "bnb":
|
|
58
|
-
return "rpc.ankr.com/bsc";
|
|
59
|
-
case "bnbt":
|
|
60
|
-
return "rpc.ankr.com/bsc_testnet_chapel";
|
|
61
|
-
case "matic":
|
|
62
|
-
return "rpc.ankr.com/polygon";
|
|
63
|
-
case "matic-mumbai":
|
|
64
|
-
return "rpc.ankr.com/polygon_mumbai";
|
|
65
|
-
case "optimism":
|
|
66
|
-
return "rpc.ankr.com/optimism";
|
|
67
|
-
case "optimism-goerli":
|
|
68
|
-
return "rpc.ankr.com/optimism_testnet";
|
|
69
|
-
case "optimism-sepolia":
|
|
70
|
-
return "rpc.ankr.com/optimism_sepolia";
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
assertArgument(false, "unsupported network", "network", name);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* The **AnkrProvider** connects to the [[link-ankr]]
|
|
79
|
-
* JSON-RPC end-points.
|
|
80
|
-
*
|
|
81
|
-
* By default, a highly-throttled API key is used, which is
|
|
82
|
-
* appropriate for quick prototypes and simple scripts. To
|
|
83
|
-
* gain access to an increased rate-limit, it is highly
|
|
84
|
-
* recommended to [sign up here](link-ankr-signup).
|
|
85
|
-
*/
|
|
86
|
-
export class AnkrProvider extends JsonRpcProvider implements CommunityResourcable {
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* The API key for the Ankr connection.
|
|
90
|
-
*/
|
|
91
|
-
readonly apiKey!: string;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Create a new **AnkrProvider**.
|
|
95
|
-
*
|
|
96
|
-
* By default connecting to ``mainnet`` with a highly throttled
|
|
97
|
-
* API key.
|
|
98
|
-
*/
|
|
99
|
-
constructor(_network?: Networkish, apiKey?: null | string) {
|
|
100
|
-
if (_network == null) { _network = "mainnet"; }
|
|
101
|
-
const network = Network.from(_network);
|
|
102
|
-
if (apiKey == null) { apiKey = defaultApiKey; }
|
|
103
|
-
|
|
104
|
-
// Ankr does not support filterId, so we force polling
|
|
105
|
-
const options = { polling: true, staticNetwork: network };
|
|
106
|
-
|
|
107
|
-
const request = AnkrProvider.getRequest(network, apiKey);
|
|
108
|
-
super(request, network, options);
|
|
109
|
-
|
|
110
|
-
defineProperties<AnkrProvider>(this, { apiKey });
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
_getProvider(chainId: number): AbstractProvider {
|
|
114
|
-
try {
|
|
115
|
-
return new AnkrProvider(chainId, this.apiKey);
|
|
116
|
-
} catch (error) { }
|
|
117
|
-
return super._getProvider(chainId);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Returns a prepared request for connecting to %%network%% with
|
|
122
|
-
* %%apiKey%%.
|
|
123
|
-
*/
|
|
124
|
-
static getRequest(network: Network, apiKey?: null | string): FetchRequest {
|
|
125
|
-
if (apiKey == null) { apiKey = defaultApiKey; }
|
|
126
|
-
|
|
127
|
-
const request = new FetchRequest(`https:/\/${ getHost(network.name) }/${ apiKey }`);
|
|
128
|
-
request.allowGzip = true;
|
|
129
|
-
|
|
130
|
-
if (apiKey === defaultApiKey) {
|
|
131
|
-
request.retryFunc = async (request, response, attempt) => {
|
|
132
|
-
showThrottleMessage("AnkrProvider");
|
|
133
|
-
return true;
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return request;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
getRpcError(payload: JsonRpcPayload, error: JsonRpcError): Error {
|
|
141
|
-
if (payload.method === "eth_sendRawTransaction") {
|
|
142
|
-
if (error && error.error && error.error.message === "INTERNAL_ERROR: could not replace existing tx") {
|
|
143
|
-
error.error.message = "replacement transaction underpriced";
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return super.getRpcError(payload, error);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
isCommunityResource(): boolean {
|
|
151
|
-
return (this.apiKey === defaultApiKey);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* [[link-blockscout]] provides a third-party service for connecting to
|
|
4
|
-
* various blockchains over JSON-RPC.
|
|
5
|
-
*
|
|
6
|
-
* **Supported Networks**
|
|
7
|
-
*
|
|
8
|
-
* - Ethereum Mainnet (``mainnet``)
|
|
9
|
-
* - Sepolia Testnet (``sepolia``)
|
|
10
|
-
* - Holesky Testnet (``holesky``)
|
|
11
|
-
* - Ethereum Classic (``classic``)
|
|
12
|
-
* - Arbitrum (``arbitrum``)
|
|
13
|
-
* - Base (``base``)
|
|
14
|
-
* - Base Sepolia Testnet (``base-sepolia``)
|
|
15
|
-
* - Gnosis (``xdai``)
|
|
16
|
-
* - Optimism (``optimism``)
|
|
17
|
-
* - Optimism Sepolia Testnet (``optimism-sepolia``)
|
|
18
|
-
* - Polygon (``matic``)
|
|
19
|
-
*
|
|
20
|
-
* @_subsection: api/providers/thirdparty:Blockscout [providers-blockscout]
|
|
21
|
-
*/
|
|
22
|
-
import {
|
|
23
|
-
assertArgument, defineProperties, FetchRequest, isHexString
|
|
24
|
-
} from "../utils/index.js";
|
|
25
|
-
|
|
26
|
-
import { Network } from "./network.js";
|
|
27
|
-
import { JsonRpcProvider } from "./provider-jsonrpc.js";
|
|
28
|
-
|
|
29
|
-
import type { AbstractProvider, PerformActionRequest } from "./abstract-provider.js";
|
|
30
|
-
import type { CommunityResourcable } from "./community.js";
|
|
31
|
-
import type { Networkish } from "./network.js";
|
|
32
|
-
import type { JsonRpcPayload, JsonRpcError } from "./provider-jsonrpc.js";
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function getUrl(name: string): string {
|
|
36
|
-
switch(name) {
|
|
37
|
-
case "mainnet":
|
|
38
|
-
return "https:/\/eth.blockscout.com/api/eth-rpc";
|
|
39
|
-
case "sepolia":
|
|
40
|
-
return "https:/\/eth-sepolia.blockscout.com/api/eth-rpc";
|
|
41
|
-
case "holesky":
|
|
42
|
-
return "https:/\/eth-holesky.blockscout.com/api/eth-rpc";
|
|
43
|
-
|
|
44
|
-
case "classic":
|
|
45
|
-
return "https:/\/etc.blockscout.com/api/eth-rpc";
|
|
46
|
-
|
|
47
|
-
case "arbitrum":
|
|
48
|
-
return "https:/\/arbitrum.blockscout.com/api/eth-rpc";
|
|
49
|
-
|
|
50
|
-
case "base":
|
|
51
|
-
return "https:/\/base.blockscout.com/api/eth-rpc";
|
|
52
|
-
case "base-sepolia":
|
|
53
|
-
return "https:/\/base-sepolia.blockscout.com/api/eth-rpc";
|
|
54
|
-
|
|
55
|
-
case "matic":
|
|
56
|
-
return "https:/\/polygon.blockscout.com/api/eth-rpc";
|
|
57
|
-
|
|
58
|
-
case "optimism":
|
|
59
|
-
return "https:/\/optimism.blockscout.com/api/eth-rpc";
|
|
60
|
-
case "optimism-sepolia":
|
|
61
|
-
return "https:/\/optimism-sepolia.blockscout.com/api/eth-rpc";
|
|
62
|
-
|
|
63
|
-
case "xdai":
|
|
64
|
-
return "https:/\/gnosis.blockscout.com/api/eth-rpc";
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
assertArgument(false, "unsupported network", "network", name);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* The **BlockscoutProvider** connects to the [[link-blockscout]]
|
|
73
|
-
* JSON-RPC end-points.
|
|
74
|
-
*
|
|
75
|
-
* By default, a highly-throttled API key is used, which is
|
|
76
|
-
* appropriate for quick prototypes and simple scripts. To
|
|
77
|
-
* gain access to an increased rate-limit, it is highly
|
|
78
|
-
* recommended to [sign up here](link-blockscout).
|
|
79
|
-
*/
|
|
80
|
-
export class BlockscoutProvider extends JsonRpcProvider implements CommunityResourcable {
|
|
81
|
-
/**
|
|
82
|
-
* The API key.
|
|
83
|
-
*/
|
|
84
|
-
readonly apiKey!: null | string;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Creates a new **BlockscoutProvider**.
|
|
88
|
-
*/
|
|
89
|
-
constructor(_network?: Networkish, apiKey?: null | string) {
|
|
90
|
-
if (_network == null) { _network = "mainnet"; }
|
|
91
|
-
const network = Network.from(_network);
|
|
92
|
-
|
|
93
|
-
if (apiKey == null) { apiKey = null; }
|
|
94
|
-
|
|
95
|
-
const request = BlockscoutProvider.getRequest(network);
|
|
96
|
-
super(request, network, { staticNetwork: network });
|
|
97
|
-
|
|
98
|
-
defineProperties<BlockscoutProvider>(this, { apiKey });
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
_getProvider(chainId: number): AbstractProvider {
|
|
102
|
-
try {
|
|
103
|
-
return new BlockscoutProvider(chainId, this.apiKey);
|
|
104
|
-
} catch (error) { }
|
|
105
|
-
return super._getProvider(chainId);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
isCommunityResource(): boolean {
|
|
109
|
-
return (this.apiKey === null);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
getRpcRequest(req: PerformActionRequest): null | { method: string, args: Array<any> } {
|
|
113
|
-
// Blockscout enforces the TAG argument for estimateGas
|
|
114
|
-
const resp = super.getRpcRequest(req);
|
|
115
|
-
if (resp && resp.method === "eth_estimateGas" && resp.args.length == 1) {
|
|
116
|
-
resp.args = resp.args.slice();
|
|
117
|
-
resp.args.push("latest");
|
|
118
|
-
}
|
|
119
|
-
return resp;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
getRpcError(payload: JsonRpcPayload, _error: JsonRpcError): Error {
|
|
123
|
-
const error = _error ? _error.error: null;
|
|
124
|
-
|
|
125
|
-
// Blockscout currently drops the VM result and replaces it with a
|
|
126
|
-
// human-readable string, so we need to make it machine-readable.
|
|
127
|
-
if (error && error.code === -32015 && !isHexString(error.data || "", true)) {
|
|
128
|
-
const panicCodes = <Record<string, string>>{
|
|
129
|
-
"assert(false)": "01",
|
|
130
|
-
"arithmetic underflow or overflow": "11",
|
|
131
|
-
"division or modulo by zero": "12",
|
|
132
|
-
"out-of-bounds array access; popping on an empty array": "31",
|
|
133
|
-
"out-of-bounds access of an array or bytesN": "32"
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
let panicCode = "";
|
|
137
|
-
if (error.message === "VM execution error.") {
|
|
138
|
-
// eth_call passes this message
|
|
139
|
-
panicCode = panicCodes[error.data] || "";
|
|
140
|
-
} else if (panicCodes[error.message || ""]) {
|
|
141
|
-
panicCode = panicCodes[error.message || ""];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (panicCode) {
|
|
145
|
-
error.message += ` (reverted: ${ error.data })`;
|
|
146
|
-
error.data = "0x4e487b7100000000000000000000000000000000000000000000000000000000000000" + panicCode;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
} else if (error && error.code === -32000) {
|
|
150
|
-
if (error.message === "wrong transaction nonce") {
|
|
151
|
-
error.message += " (nonce too low)";
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return super.getRpcError(payload, _error);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Returns a prepared request for connecting to %%network%%
|
|
160
|
-
* with %%apiKey%%.
|
|
161
|
-
*/
|
|
162
|
-
static getRequest(network: Network): FetchRequest {
|
|
163
|
-
const request = new FetchRequest(getUrl(network.name));
|
|
164
|
-
request.allowGzip = true;
|
|
165
|
-
return request;
|
|
166
|
-
}
|
|
167
|
-
}
|