carbon-js-sdk 0.4.2 → 0.4.3-dev.1
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/lib/CarbonSDK.js +1 -1
- package/lib/clients/CarbonQueryClient.js +2 -2
- package/lib/clients/ETHClient.d.ts +11 -4
- package/lib/clients/ETHClient.js +32 -18
- package/lib/clients/HydrogenClient.d.ts +16 -7
- package/lib/clients/HydrogenClient.js +56 -10
- package/lib/clients/NEOClient.d.ts +1 -1
- package/lib/clients/NEOClient.js +15 -10
- package/lib/clients/TokenClient.d.ts +29 -5
- package/lib/clients/TokenClient.js +258 -53
- package/lib/clients/ZILClient.d.ts +1 -1
- package/lib/clients/ZILClient.js +25 -20
- package/lib/codec/cosmos/gov/v1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1/tx.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
- package/lib/codec/cosmos/group/v1/events.js +2 -2
- package/lib/codec/cosmos/group/v1/tx.js +4 -4
- package/lib/codec/cosmos/tx/v1beta1/tx.js +4 -4
- package/lib/constant/generic.js +1 -1
- package/lib/constant/ibc.d.ts +7 -0
- package/lib/constant/ibc.js +4 -1
- package/lib/constant/network.d.ts +2 -0
- package/lib/constant/network.js +5 -1
- package/lib/hydrogen/transfer.d.ts +5 -5
- package/lib/modules/cdp.js +43 -43
- package/lib/modules/cosmwasm.js +1 -1
- package/lib/modules/gov.js +12 -12
- package/lib/modules/ibc.d.ts +5 -1
- package/lib/modules/ibc.js +78 -0
- package/lib/modules/liquiditypool.js +1 -1
- package/lib/provider/account/EthLedgerAccount/EthLedgerAccount.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/ErrorCode.js +1 -1
- package/lib/provider/account/NeoLedgerAccount/N3Ledger/main.js +8 -8
- package/lib/provider/account/NeoLedgerAccount/NeoLedgerAccount.js +3 -3
- package/lib/provider/account/NeoLedgerAccount/NeonLedger.js +1 -1
- package/lib/provider/amino/types/admin.js +27 -27
- package/lib/provider/amino/types/bank.js +1 -1
- package/lib/provider/amino/types/broker.js +1 -1
- package/lib/provider/amino/types/cdp.js +22 -22
- package/lib/provider/amino/types/coin.js +4 -4
- package/lib/provider/amino/types/gov.js +4 -4
- package/lib/provider/amino/types/ibc.js +1 -1
- package/lib/provider/amino/types/leverage.js +1 -1
- package/lib/provider/amino/types/liquidityPool.js +7 -7
- package/lib/provider/amino/types/market.js +1 -1
- package/lib/provider/amino/types/oracle.js +1 -1
- package/lib/provider/amino/types/order.js +4 -4
- package/lib/provider/amino/types/position.js +1 -1
- package/lib/provider/amino/types/profile.js +1 -1
- package/lib/provider/amino/types/staking.js +4 -4
- package/lib/provider/amino/types/subaccount.js +3 -3
- package/lib/provider/amino/utils.js +11 -11
- package/lib/provider/keplr/KeplrStore.d.ts +1 -1
- package/lib/provider/keplr/KeplrStore.js +2 -5
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.d.ts +5 -5
- package/lib/provider/metamask/MetaMask.js +37 -37
- package/lib/provider/o3/O3Wallet.js +2 -2
- package/lib/util/address.js +13 -13
- package/lib/util/api.js +4 -4
- package/lib/util/blockchain.d.ts +26 -0
- package/lib/util/blockchain.js +160 -1
- package/lib/util/fetch.js +1 -1
- package/lib/util/generic.js +3 -3
- package/lib/util/ibc.d.ts +4 -3
- package/lib/util/ibc.js +20 -1
- package/lib/util/number.js +5 -5
- package/lib/wallet/CarbonSigner.js +2 -2
- package/lib/wallet/CarbonSigningClient.js +8 -8
- package/lib/wallet/CarbonWallet.js +6 -6
- package/lib/websocket/connector.d.ts +2 -1
- package/lib/websocket/connector.js +7 -9
- package/package.json +1 -1
- package/lib/clients/EvmIbcClient.d.ts +0 -86
- package/lib/clients/EvmIbcClient.js +0 -90
- package/lib/codec/broker/incoming_pool_swap.d.ts +0 -23
- package/lib/codec/broker/incoming_pool_swap.js +0 -136
- package/lib/util/ethermint/evm-ibc.d.ts +0 -97
- package/lib/util/ethermint/evm-ibc.js +0 -134
- package/lib/util/ethermint/index.d.ts +0 -3
- package/lib/util/ethermint/index.js +0 -12
- package/lib/util/ethermint/keys.d.ts +0 -39
- package/lib/util/ethermint/keys.js +0 -138
- package/lib/util/ethermint/web3.d.ts +0 -36
- package/lib/util/ethermint/web3.js +0 -124
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Network } from "../../constant";
|
|
2
|
-
import { Blockchain } from "../../util/blockchain";
|
|
2
|
+
import { Blockchain, BlockchainV2, EVMChain as EVMChainV2 } from "../../util/blockchain";
|
|
3
3
|
import { ethers } from "ethers";
|
|
4
|
-
export declare type EVMChain =
|
|
4
|
+
export declare type EVMChain = EVMChainV2;
|
|
5
5
|
interface RequestArguments {
|
|
6
6
|
method: string;
|
|
7
7
|
params?: unknown[] | object;
|
|
@@ -28,7 +28,7 @@ export interface CallContractArgs {
|
|
|
28
28
|
data?: string;
|
|
29
29
|
}
|
|
30
30
|
export interface MetaMaskSyncResult {
|
|
31
|
-
blockchain?: Blockchain;
|
|
31
|
+
blockchain?: Blockchain | BlockchainV2;
|
|
32
32
|
chainId?: number;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -38,10 +38,10 @@ export declare class MetaMask {
|
|
|
38
38
|
readonly network: Network;
|
|
39
39
|
private blockchain;
|
|
40
40
|
static getNetworkParams(network: Network, blockchain?: EVMChain): MetaMaskChangeNetworkParam;
|
|
41
|
-
static getRequiredChainId(network: Network, blockchain?:
|
|
41
|
+
static getRequiredChainId(network: Network, blockchain?: BlockchainV2): 1 | 5 | 66 | 56 | 137 | 42161 | 97 | 65 | 80001 | 421611;
|
|
42
42
|
constructor(network: Network);
|
|
43
43
|
private checkProvider;
|
|
44
|
-
getBlockchain():
|
|
44
|
+
getBlockchain(): BlockchainV2;
|
|
45
45
|
syncBlockchain(): Promise<MetaMaskSyncResult>;
|
|
46
46
|
getSigner(): Promise<ethers.Signer>;
|
|
47
47
|
getAPI(): MetaMaskAPI | null;
|
|
@@ -35,35 +35,35 @@ const blockchain_1 = require("../../util/blockchain");
|
|
|
35
35
|
const ethers_1 = require("ethers");
|
|
36
36
|
const ethSignUtils = __importStar(require("eth-sig-util"));
|
|
37
37
|
const CONTRACT_HASH = {
|
|
38
|
-
|
|
38
|
+
Ethereum: {
|
|
39
39
|
// use same rinkeby contract for all non-mainnet uses
|
|
40
40
|
[constant_1.Network.TestNet]: "0x086e1b5f67c0f7ca8eb202d35553e27e964899e2",
|
|
41
41
|
[constant_1.Network.DevNet]: "0x086e1b5f67c0f7ca8eb202d35553e27e964899e2",
|
|
42
42
|
[constant_1.Network.LocalHost]: "0x086e1b5f67c0f7ca8eb202d35553e27e964899e2",
|
|
43
43
|
[constant_1.Network.MainNet]: "0xf4552877A40c1527D38970F170993660084D4541",
|
|
44
44
|
},
|
|
45
|
-
[
|
|
45
|
+
['Binance Smart Chain']: {
|
|
46
46
|
// use same testnet contract for all non-mainnet uses
|
|
47
47
|
[constant_1.Network.TestNet]: "0x06E949ec2d6737ff57859CdcE426C5b5CA2Fc085",
|
|
48
48
|
[constant_1.Network.DevNet]: "0x06E949ec2d6737ff57859CdcE426C5b5CA2Fc085",
|
|
49
49
|
[constant_1.Network.LocalHost]: "0x06E949ec2d6737ff57859CdcE426C5b5CA2Fc085",
|
|
50
50
|
[constant_1.Network.MainNet]: "0x3786d94AC6B15FE2eaC72c3CA78cB82578Fc66f4",
|
|
51
51
|
},
|
|
52
|
-
|
|
52
|
+
Arbitrum: {
|
|
53
53
|
// use same testnet contract for all non-mainnet uses
|
|
54
54
|
[constant_1.Network.TestNet]: "",
|
|
55
55
|
[constant_1.Network.DevNet]: "",
|
|
56
56
|
[constant_1.Network.LocalHost]: "",
|
|
57
57
|
[constant_1.Network.MainNet]: "0x43138036d1283413035b8eca403559737e8f7980",
|
|
58
58
|
},
|
|
59
|
-
|
|
59
|
+
Polygon: {
|
|
60
60
|
// use same testnet contract for all non-mainnet uses
|
|
61
61
|
[constant_1.Network.TestNet]: "",
|
|
62
62
|
[constant_1.Network.DevNet]: "",
|
|
63
63
|
[constant_1.Network.LocalHost]: "",
|
|
64
64
|
[constant_1.Network.MainNet]: "0x61B9503Fe023E1F1Dd0ab7417923cB0A41DD9E0c",
|
|
65
65
|
},
|
|
66
|
-
|
|
66
|
+
OKC: {
|
|
67
67
|
// use same testnet contract for all non-mainnet uses
|
|
68
68
|
[constant_1.Network.TestNet]: "",
|
|
69
69
|
[constant_1.Network.DevNet]: "",
|
|
@@ -207,18 +207,18 @@ const OKC_TESTNET = {
|
|
|
207
207
|
class MetaMask {
|
|
208
208
|
constructor(network) {
|
|
209
209
|
this.network = network;
|
|
210
|
-
this.blockchain =
|
|
210
|
+
this.blockchain = 'Ethereum';
|
|
211
211
|
}
|
|
212
|
-
static getNetworkParams(network, blockchain =
|
|
212
|
+
static getNetworkParams(network, blockchain = 'Ethereum') {
|
|
213
213
|
if (network === constant_1.Network.MainNet) {
|
|
214
214
|
switch (blockchain) {
|
|
215
|
-
case
|
|
215
|
+
case 'Binance Smart Chain':
|
|
216
216
|
return BSC_MAINNET;
|
|
217
|
-
case
|
|
217
|
+
case 'Arbitrum':
|
|
218
218
|
return ARBITRUM_MAINNET;
|
|
219
|
-
case
|
|
219
|
+
case 'Polygon':
|
|
220
220
|
return POLYGON_MAINNET;
|
|
221
|
-
case
|
|
221
|
+
case 'OKC':
|
|
222
222
|
return OKC_MAINNET;
|
|
223
223
|
default:
|
|
224
224
|
// metamask should come with Ethereum configs
|
|
@@ -226,42 +226,42 @@ class MetaMask {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
switch (blockchain) {
|
|
229
|
-
case
|
|
229
|
+
case 'Binance Smart Chain':
|
|
230
230
|
return BSC_TESTNET;
|
|
231
|
-
case
|
|
231
|
+
case 'Arbitrum':
|
|
232
232
|
return ARBITRUM_TESTNET;
|
|
233
|
-
case
|
|
233
|
+
case 'Polygon':
|
|
234
234
|
return POLYGON_TESTNET;
|
|
235
|
-
case
|
|
235
|
+
case 'OKC':
|
|
236
236
|
return OKC_TESTNET;
|
|
237
237
|
default:
|
|
238
238
|
// metamask should come with Ethereum configs
|
|
239
239
|
return ETH_TESTNET;
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
-
static getRequiredChainId(network, blockchain =
|
|
242
|
+
static getRequiredChainId(network, blockchain = 'Ethereum') {
|
|
243
243
|
if (network === constant_1.Network.MainNet) {
|
|
244
244
|
switch (blockchain) {
|
|
245
|
-
case
|
|
245
|
+
case 'Binance Smart Chain':
|
|
246
246
|
return 56;
|
|
247
|
-
case
|
|
247
|
+
case 'Arbitrum':
|
|
248
248
|
return 42161;
|
|
249
|
-
case
|
|
249
|
+
case 'Polygon':
|
|
250
250
|
return 137;
|
|
251
|
-
case
|
|
251
|
+
case 'OKC':
|
|
252
252
|
return 66;
|
|
253
253
|
default:
|
|
254
254
|
return 1;
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
switch (blockchain) {
|
|
258
|
-
case
|
|
258
|
+
case 'Binance Smart Chain':
|
|
259
259
|
return 97;
|
|
260
|
-
case
|
|
260
|
+
case 'Arbitrum':
|
|
261
261
|
return 421611;
|
|
262
|
-
case
|
|
262
|
+
case 'Polygon':
|
|
263
263
|
return 80001;
|
|
264
|
-
case
|
|
264
|
+
case 'OKC':
|
|
265
265
|
return 65;
|
|
266
266
|
default:
|
|
267
267
|
return 5;
|
|
@@ -269,10 +269,10 @@ class MetaMask {
|
|
|
269
269
|
}
|
|
270
270
|
checkProvider(blockchain = this.blockchain) {
|
|
271
271
|
const config = constant_1.NetworkConfigs[this.network];
|
|
272
|
-
if (!config[blockchain]) {
|
|
272
|
+
if (!config[blockchain_1.BLOCKCHAIN_V2_TO_V1_MAPPING[blockchain]]) {
|
|
273
273
|
throw new Error(`MetaMask login not supported for this network ${this.network}`);
|
|
274
274
|
}
|
|
275
|
-
const ethNetworkConfig = config[blockchain];
|
|
275
|
+
const ethNetworkConfig = config[blockchain_1.BLOCKCHAIN_V2_TO_V1_MAPPING[blockchain]];
|
|
276
276
|
const provider = new ethers_1.ethers.providers.JsonRpcProvider(ethNetworkConfig.rpcURL);
|
|
277
277
|
return provider;
|
|
278
278
|
}
|
|
@@ -284,7 +284,7 @@ class MetaMask {
|
|
|
284
284
|
return __awaiter(this, void 0, void 0, function* () {
|
|
285
285
|
const chainIdHex = (yield ((_a = this.getAPI()) === null || _a === void 0 ? void 0 : _a.request({ method: "eth_chainId" })));
|
|
286
286
|
const chainId = !!chainIdHex ? parseInt(chainIdHex, 16) : undefined;
|
|
287
|
-
const blockchain = blockchain_1.
|
|
287
|
+
const blockchain = (0, blockchain_1.getBlockchainFromChainV2)(chainId);
|
|
288
288
|
this.blockchain = blockchain;
|
|
289
289
|
return { chainId, blockchain };
|
|
290
290
|
});
|
|
@@ -426,45 +426,45 @@ class MetaMask {
|
|
|
426
426
|
// set correct blockchain given the chain ID
|
|
427
427
|
if (network === constant_1.Network.MainNet) {
|
|
428
428
|
if (currentChainId === 1) {
|
|
429
|
-
this.blockchain =
|
|
429
|
+
this.blockchain = 'Ethereum';
|
|
430
430
|
return currentChainId;
|
|
431
431
|
}
|
|
432
432
|
if (currentChainId === 56) {
|
|
433
|
-
this.blockchain =
|
|
433
|
+
this.blockchain = 'Binance Smart Chain';
|
|
434
434
|
return currentChainId;
|
|
435
435
|
}
|
|
436
436
|
if (currentChainId === 42161) {
|
|
437
|
-
this.blockchain =
|
|
437
|
+
this.blockchain = 'Arbitrum';
|
|
438
438
|
return currentChainId;
|
|
439
439
|
}
|
|
440
440
|
if (currentChainId === 137) {
|
|
441
|
-
this.blockchain =
|
|
441
|
+
this.blockchain = 'Polygon';
|
|
442
442
|
return currentChainId;
|
|
443
443
|
}
|
|
444
444
|
if (currentChainId === 66) {
|
|
445
|
-
this.blockchain =
|
|
445
|
+
this.blockchain = 'OKC';
|
|
446
446
|
return currentChainId;
|
|
447
447
|
}
|
|
448
448
|
return 1;
|
|
449
449
|
}
|
|
450
450
|
if (currentChainId === 5) {
|
|
451
|
-
this.blockchain =
|
|
451
|
+
this.blockchain = 'Ethereum';
|
|
452
452
|
return currentChainId;
|
|
453
453
|
}
|
|
454
454
|
if (currentChainId === 97) {
|
|
455
|
-
this.blockchain =
|
|
455
|
+
this.blockchain = 'Binance Smart Chain';
|
|
456
456
|
return currentChainId;
|
|
457
457
|
}
|
|
458
458
|
if (currentChainId === 421611) {
|
|
459
|
-
this.blockchain =
|
|
459
|
+
this.blockchain = 'Arbitrum';
|
|
460
460
|
return currentChainId;
|
|
461
461
|
}
|
|
462
462
|
if (currentChainId === 80001) {
|
|
463
|
-
this.blockchain =
|
|
463
|
+
this.blockchain = 'Polygon';
|
|
464
464
|
return currentChainId;
|
|
465
465
|
}
|
|
466
466
|
if (currentChainId === 65) {
|
|
467
|
-
this.blockchain =
|
|
467
|
+
this.blockchain = 'OKC';
|
|
468
468
|
return currentChainId;
|
|
469
469
|
}
|
|
470
470
|
// Deal with cases where users are logging in to devnet using mainnet chains
|
|
@@ -60,9 +60,9 @@ class O3Wallet {
|
|
|
60
60
|
return {
|
|
61
61
|
type: index_1.CarbonSignerTypes.BrowserInjected,
|
|
62
62
|
signAmino: (_, doc) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const msg = JSON.stringify(generic_1.sortObject(doc));
|
|
63
|
+
const msg = JSON.stringify((0, generic_1.sortObject)(doc));
|
|
64
64
|
const signBytes = yield dapi.signMessage(msg);
|
|
65
|
-
const signature = amino_1.encodeSecp256k1Signature(pubKey, signBytes);
|
|
65
|
+
const signature = (0, amino_1.encodeSecp256k1Signature)(pubKey, signBytes);
|
|
66
66
|
return {
|
|
67
67
|
signed: doc,
|
|
68
68
|
signature,
|
package/lib/util/address.js
CHANGED
|
@@ -94,13 +94,13 @@ const randomMnemonic = () => {
|
|
|
94
94
|
};
|
|
95
95
|
exports.randomMnemonic = randomMnemonic;
|
|
96
96
|
const wifEncodePrivateKey = (privateKey, iter = 128) => {
|
|
97
|
-
const privateKeyBuf = exports.stringOrBufferToBuffer(privateKey);
|
|
97
|
+
const privateKeyBuf = (0, exports.stringOrBufferToBuffer)(privateKey);
|
|
98
98
|
return wif.encode(iter, privateKeyBuf, true);
|
|
99
99
|
};
|
|
100
100
|
exports.wifEncodePrivateKey = wifEncodePrivateKey;
|
|
101
101
|
exports.SWTHAddress = {
|
|
102
102
|
newMnemonic: () => {
|
|
103
|
-
return exports.randomMnemonic();
|
|
103
|
+
return (0, exports.randomMnemonic)();
|
|
104
104
|
},
|
|
105
105
|
coinType: () => {
|
|
106
106
|
return SWTH_COIN_TYPE;
|
|
@@ -110,10 +110,10 @@ exports.SWTHAddress = {
|
|
|
110
110
|
return new BIP44Path(BIP44_PURPOSE, coinType).update(index, change, account).toArray();
|
|
111
111
|
},
|
|
112
112
|
publicKeyToScriptHash: (publicKey) => {
|
|
113
|
-
const pubKeyBuffer = exports.stringOrBufferToBuffer(publicKey);
|
|
113
|
+
const pubKeyBuffer = (0, exports.stringOrBufferToBuffer)(publicKey);
|
|
114
114
|
const sha256Hash = ethers_1.ethers.utils.sha256(pubKeyBuffer);
|
|
115
115
|
const ripemdHash = ethers_1.ethers.utils.ripemd160(sha256Hash);
|
|
116
|
-
return generic_1.stripHexPrefix(ripemdHash);
|
|
116
|
+
return (0, generic_1.stripHexPrefix)(ripemdHash);
|
|
117
117
|
},
|
|
118
118
|
publicKeyToAddress: (publicKey, opts) => {
|
|
119
119
|
const scriptHash = exports.SWTHAddress.publicKeyToScriptHash(publicKey);
|
|
@@ -135,7 +135,7 @@ exports.SWTHAddress = {
|
|
|
135
135
|
return privateKey;
|
|
136
136
|
},
|
|
137
137
|
privateToPublicKey: (privateKey) => {
|
|
138
|
-
const privateKeyBuff = exports.stringOrBufferToBuffer(privateKey);
|
|
138
|
+
const privateKeyBuff = (0, exports.stringOrBufferToBuffer)(privateKey);
|
|
139
139
|
const publicKeyUint8Array = secp256k1.publicKeyCreate(privateKeyBuff, true);
|
|
140
140
|
const publicKey = Buffer.from(publicKeyUint8Array);
|
|
141
141
|
return publicKey;
|
|
@@ -146,7 +146,7 @@ exports.SWTHAddress = {
|
|
|
146
146
|
return address;
|
|
147
147
|
},
|
|
148
148
|
encode: (hash, opts) => {
|
|
149
|
-
const hashBuff = exports.stringOrBufferToBuffer(hash, "hex");
|
|
149
|
+
const hashBuff = (0, exports.stringOrBufferToBuffer)(hash, "hex");
|
|
150
150
|
const words = bech32.toWords(hashBuff.slice(0, 20));
|
|
151
151
|
const addressPrefix = exports.SWTHAddress.getBech32Prefix(opts === null || opts === void 0 ? void 0 : opts.network, opts === null || opts === void 0 ? void 0 : opts.bech32Prefix, opts === null || opts === void 0 ? void 0 : opts.type);
|
|
152
152
|
const address = bech32.encode(addressPrefix, words);
|
|
@@ -205,7 +205,7 @@ exports.NEOAddress = {
|
|
|
205
205
|
]);
|
|
206
206
|
const sha256Hash = ethers_1.ethers.utils.sha256(addressScript);
|
|
207
207
|
const ripemdHash = ethers_1.ethers.utils.ripemd160(sha256Hash);
|
|
208
|
-
return generic_1.stripHexPrefix(ripemdHash);
|
|
208
|
+
return (0, generic_1.stripHexPrefix)(ripemdHash);
|
|
209
209
|
},
|
|
210
210
|
publicKeyToAddress: (publicKey) => {
|
|
211
211
|
const addressScript = exports.NEOAddress.publicKeyToScriptHash(publicKey);
|
|
@@ -213,7 +213,7 @@ exports.NEOAddress = {
|
|
|
213
213
|
return address;
|
|
214
214
|
},
|
|
215
215
|
encodePublicKey: (unencodedPublicKey) => {
|
|
216
|
-
const unencPubKeyBuf = exports.stringOrBufferToBuffer(unencodedPublicKey);
|
|
216
|
+
const unencPubKeyBuf = (0, exports.stringOrBufferToBuffer)(unencodedPublicKey);
|
|
217
217
|
if (unencPubKeyBuf.length <= 33) {
|
|
218
218
|
// length indicates already encoded
|
|
219
219
|
return unencPubKeyBuf;
|
|
@@ -238,7 +238,7 @@ exports.NEOAddress = {
|
|
|
238
238
|
return privateKey;
|
|
239
239
|
},
|
|
240
240
|
privateToPublicKey: (privateKey) => {
|
|
241
|
-
const privateKeyBuff = exports.stringOrBufferToBuffer(privateKey);
|
|
241
|
+
const privateKeyBuff = (0, exports.stringOrBufferToBuffer)(privateKey);
|
|
242
242
|
const publicKeyUint8Array = secp256r1.publicKeyCreate(privateKeyBuff, true);
|
|
243
243
|
return Buffer.from(publicKeyUint8Array);
|
|
244
244
|
},
|
|
@@ -256,7 +256,7 @@ exports.NEOAddress = {
|
|
|
256
256
|
},
|
|
257
257
|
};
|
|
258
258
|
exports.N3Address = Object.assign(Object.assign({}, exports.NEOAddress), { publicKeyToScriptHash: (publicKey) => {
|
|
259
|
-
const publicKeyHex = exports.stringOrBufferToBuffer(publicKey).toString("hex");
|
|
259
|
+
const publicKeyHex = (0, exports.stringOrBufferToBuffer)(publicKey).toString("hex");
|
|
260
260
|
return neon_core_next_1.wallet.getScriptHashFromPublicKey(publicKeyHex);
|
|
261
261
|
}, publicKeyToAddress: (publicKey) => {
|
|
262
262
|
const addressScript = exports.N3Address.publicKeyToScriptHash(publicKey);
|
|
@@ -282,11 +282,11 @@ exports.ETHAddress = {
|
|
|
282
282
|
return ethers_1.ethers.utils.keccak256(encodedPublicKey);
|
|
283
283
|
},
|
|
284
284
|
publicKeyToAddress: (publicKey) => {
|
|
285
|
-
const publicKeyBuff = exports.stringOrBufferToBuffer(publicKey);
|
|
285
|
+
const publicKeyBuff = (0, exports.stringOrBufferToBuffer)(publicKey);
|
|
286
286
|
return ethers_1.ethers.utils.computeAddress(publicKeyBuff);
|
|
287
287
|
},
|
|
288
288
|
encodePublicKey: (unencodedPublicKey) => {
|
|
289
|
-
const unencodedPublicKeyBuff = exports.stringOrBufferToBuffer(unencodedPublicKey);
|
|
289
|
+
const unencodedPublicKeyBuff = (0, exports.stringOrBufferToBuffer)(unencodedPublicKey);
|
|
290
290
|
const publicKey = ethers_1.ethers.utils.computePublicKey(unencodedPublicKeyBuff, true);
|
|
291
291
|
return Buffer.from(publicKey, "hex");
|
|
292
292
|
},
|
|
@@ -298,7 +298,7 @@ exports.ETHAddress = {
|
|
|
298
298
|
return Buffer.from((_a = wallet.privateKey) === null || _a === void 0 ? void 0 : _a.replace(/^0x/, ""), "hex");
|
|
299
299
|
},
|
|
300
300
|
privateToPublicKey: (privateKey) => {
|
|
301
|
-
const privateKeyBuff = exports.stringOrBufferToBuffer(privateKey);
|
|
301
|
+
const privateKeyBuff = (0, exports.stringOrBufferToBuffer)(privateKey);
|
|
302
302
|
return Buffer.from(ethers_1.ethers.utils.computePublicKey(privateKeyBuff).replace(/^0x/, ""), "hex");
|
|
303
303
|
},
|
|
304
304
|
privateKeyToAddress: (privateKey) => {
|
package/lib/util/api.js
CHANGED
|
@@ -84,7 +84,7 @@ class HTTP {
|
|
|
84
84
|
* Executes HTTP GET request with fetch
|
|
85
85
|
*/
|
|
86
86
|
this.get = ({ url, headers }) => {
|
|
87
|
-
return fetch_1.fetch(url, {
|
|
87
|
+
return (0, fetch_1.fetch)(url, {
|
|
88
88
|
method: "GET",
|
|
89
89
|
headers,
|
|
90
90
|
});
|
|
@@ -93,7 +93,7 @@ class HTTP {
|
|
|
93
93
|
* Executes HTTP POST request with fetch
|
|
94
94
|
*/
|
|
95
95
|
this.post = (options) => {
|
|
96
|
-
return fetch_1.fetch(options.url, {
|
|
96
|
+
return (0, fetch_1.fetch)(options.url, {
|
|
97
97
|
method: "POST",
|
|
98
98
|
headers: Object.assign({ "Content-Type": options.content_type || "application/json" }, options.headers),
|
|
99
99
|
body: JSON.stringify(options.body),
|
|
@@ -103,7 +103,7 @@ class HTTP {
|
|
|
103
103
|
* Executes HTTP DELETE request with fetch
|
|
104
104
|
*/
|
|
105
105
|
this.del = (options) => {
|
|
106
|
-
return fetch_1.fetch(options.url, {
|
|
106
|
+
return (0, fetch_1.fetch)(options.url, {
|
|
107
107
|
method: "DELETE",
|
|
108
108
|
headers: Object.assign({ "Content-Type": options.content_type || "application/json" }, options.headers),
|
|
109
109
|
body: JSON.stringify(options.body),
|
|
@@ -114,7 +114,7 @@ class HTTP {
|
|
|
114
114
|
*/
|
|
115
115
|
this.raw = (options) => {
|
|
116
116
|
const { url } = options, otherOpts = __rest(options, ["url"]);
|
|
117
|
-
return fetch_1.fetch(url, otherOpts);
|
|
117
|
+
return (0, fetch_1.fetch)(url, otherOpts);
|
|
118
118
|
};
|
|
119
119
|
this.apiPrefix = apiPrefix;
|
|
120
120
|
this.apiEndpoints = apiEndpoints;
|
package/lib/util/blockchain.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { TokenClient } from '../clients';
|
|
2
|
+
import { Bridge } from '../codec';
|
|
1
3
|
import { Network } from "../constant/network";
|
|
2
4
|
import { SimpleMap } from "./type";
|
|
3
5
|
export declare enum Blockchain {
|
|
@@ -35,10 +37,28 @@ export declare enum Blockchain {
|
|
|
35
37
|
Agoric = "agoric",
|
|
36
38
|
Sommelier = "sommelier"
|
|
37
39
|
}
|
|
40
|
+
export declare type BlockchainV2 = ReturnType<TokenClient['getAllBlockchainNames']>[number] | "Native" | "Carbon" | "Tradehub" | "Ibc" | "Polynetwork";
|
|
41
|
+
export declare const BLOCKCHAIN_V2_TO_V1_MAPPING: SimpleMap<Blockchain>;
|
|
38
42
|
export declare const BRIDGE_IDS: {
|
|
39
43
|
polynetwork: number;
|
|
40
44
|
ibc: number;
|
|
41
45
|
};
|
|
46
|
+
export interface PolyNetworkBridge extends Bridge {
|
|
47
|
+
isEvmChain: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface IbcBridge extends Bridge {
|
|
50
|
+
chain_id_name: string;
|
|
51
|
+
channels: {
|
|
52
|
+
src_channel: string;
|
|
53
|
+
dst_channel: string;
|
|
54
|
+
port_id: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export declare function isIbcBridge(object: Bridge): object is IbcBridge;
|
|
58
|
+
export interface BridgeMap {
|
|
59
|
+
polynetwork: PolyNetworkBridge[];
|
|
60
|
+
ibc: IbcBridge[];
|
|
61
|
+
}
|
|
42
62
|
export declare type ChainIds = SimpleMap<number>;
|
|
43
63
|
export declare const ChainNames: {
|
|
44
64
|
readonly 1: "MainNet";
|
|
@@ -64,3 +84,9 @@ export declare function parseBlockchain(value: string | null): Blockchain | null
|
|
|
64
84
|
export declare function getChainFromID(id: number): string | undefined;
|
|
65
85
|
export declare const getBlockchainFromChain: (chainId?: number | undefined) => Blockchain.Ethereum | Blockchain.BinanceSmartChain | Blockchain.Zilliqa | Blockchain.Arbitrum | Blockchain.Polygon | Blockchain.Okc | undefined;
|
|
66
86
|
export declare const blockchainForChainId: (chainId?: number | undefined, network?: Network) => Blockchain | undefined;
|
|
87
|
+
export declare const getBlockchainFromChainV2: (chainId?: number | undefined) => "Ethereum" | "Binance Smart Chain" | "Arbitrum" | "Polygon" | "Okc" | "Zilliqa" | undefined;
|
|
88
|
+
export declare const blockchainForChainIdV2: (chainId?: number | undefined, network?: Network) => Blockchain | BlockchainV2 | undefined;
|
|
89
|
+
declare const evmChains: readonly ["Ethereum", "Binance Smart Chain", "Arbitrum", "Polygon", "OKC"];
|
|
90
|
+
export declare type EVMChain = (typeof evmChains)[number];
|
|
91
|
+
export declare const isEvmChain: (chain: string) => chain is "Ethereum" | "Binance Smart Chain" | "Arbitrum" | "Polygon" | "OKC";
|
|
92
|
+
export {};
|
package/lib/util/blockchain.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.blockchainForChainId = exports.getBlockchainFromChain = exports.getChainFromID = exports.parseBlockchain = exports.chainIdsByBlockchain = exports.CHAIN_IDS_TEST = exports.CHAIN_IDS_DEV = exports.CHAIN_IDS = exports.ChainNames = exports.BRIDGE_IDS = exports.Blockchain = void 0;
|
|
3
|
+
exports.isEvmChain = exports.blockchainForChainIdV2 = exports.getBlockchainFromChainV2 = exports.blockchainForChainId = exports.getBlockchainFromChain = exports.getChainFromID = exports.parseBlockchain = exports.chainIdsByBlockchain = exports.CHAIN_IDS_TEST = exports.CHAIN_IDS_DEV = exports.CHAIN_IDS = exports.ChainNames = exports.isIbcBridge = exports.BRIDGE_IDS = exports.BLOCKCHAIN_V2_TO_V1_MAPPING = exports.Blockchain = void 0;
|
|
4
4
|
const network_1 = require("../constant/network");
|
|
5
5
|
var Blockchain;
|
|
6
6
|
(function (Blockchain) {
|
|
@@ -38,10 +38,24 @@ var Blockchain;
|
|
|
38
38
|
Blockchain["Agoric"] = "agoric";
|
|
39
39
|
Blockchain["Sommelier"] = "sommelier";
|
|
40
40
|
})(Blockchain = exports.Blockchain || (exports.Blockchain = {}));
|
|
41
|
+
exports.BLOCKCHAIN_V2_TO_V1_MAPPING = {
|
|
42
|
+
"Binance Smart Chain": Blockchain.BinanceSmartChain,
|
|
43
|
+
"Ethereum": Blockchain.Ethereum,
|
|
44
|
+
"Arbitrum": Blockchain.Arbitrum,
|
|
45
|
+
"Polygon": Blockchain.Polygon,
|
|
46
|
+
"OKC": Blockchain.Okc,
|
|
47
|
+
"Zilliqa": Blockchain.Zilliqa,
|
|
48
|
+
"Neo": Blockchain.Neo,
|
|
49
|
+
"Neo3": Blockchain.Neo3
|
|
50
|
+
};
|
|
41
51
|
exports.BRIDGE_IDS = {
|
|
42
52
|
polynetwork: 1,
|
|
43
53
|
ibc: 2,
|
|
44
54
|
};
|
|
55
|
+
function isIbcBridge(object) {
|
|
56
|
+
return Object.prototype.hasOwnProperty.call(object, "chain_id_name");
|
|
57
|
+
}
|
|
58
|
+
exports.isIbcBridge = isIbcBridge;
|
|
45
59
|
exports.ChainNames = {
|
|
46
60
|
1: "MainNet",
|
|
47
61
|
3: "Ropsten",
|
|
@@ -260,3 +274,148 @@ const blockchainForChainId = (chainId, network = network_1.Network.MainNet) => {
|
|
|
260
274
|
}
|
|
261
275
|
};
|
|
262
276
|
exports.blockchainForChainId = blockchainForChainId;
|
|
277
|
+
const getBlockchainFromChainV2 = (chainId) => {
|
|
278
|
+
switch (chainId) {
|
|
279
|
+
case 1:
|
|
280
|
+
case 3:
|
|
281
|
+
case 4:
|
|
282
|
+
case 5:
|
|
283
|
+
return 'Ethereum';
|
|
284
|
+
case 56:
|
|
285
|
+
case 97:
|
|
286
|
+
return 'Binance Smart Chain';
|
|
287
|
+
case 65:
|
|
288
|
+
case 66:
|
|
289
|
+
return 'Okc';
|
|
290
|
+
case 137:
|
|
291
|
+
case 80001:
|
|
292
|
+
return 'Polygon';
|
|
293
|
+
case 110:
|
|
294
|
+
case 111:
|
|
295
|
+
return 'Zilliqa';
|
|
296
|
+
case 42161:
|
|
297
|
+
case 421611:
|
|
298
|
+
return 'Arbitrum';
|
|
299
|
+
}
|
|
300
|
+
return undefined;
|
|
301
|
+
};
|
|
302
|
+
exports.getBlockchainFromChainV2 = getBlockchainFromChainV2;
|
|
303
|
+
const blockchainForChainIdV2 = (chainId, network = network_1.Network.MainNet) => {
|
|
304
|
+
switch (network) {
|
|
305
|
+
case network_1.Network.MainNet:
|
|
306
|
+
switch (chainId) {
|
|
307
|
+
case 0:
|
|
308
|
+
return "Native";
|
|
309
|
+
case 1:
|
|
310
|
+
return "Bitcoin";
|
|
311
|
+
case 2:
|
|
312
|
+
return "Ethereum";
|
|
313
|
+
case 4:
|
|
314
|
+
return "Neo";
|
|
315
|
+
case 6:
|
|
316
|
+
return "Binance Smart Chain";
|
|
317
|
+
case 14:
|
|
318
|
+
return "Neo3";
|
|
319
|
+
case 9: /* FALLTHROUGH */
|
|
320
|
+
case 18:
|
|
321
|
+
return "Zilliqa";
|
|
322
|
+
case 12: /* FALLTHROUGH */
|
|
323
|
+
case 66:
|
|
324
|
+
return 'Okc';
|
|
325
|
+
case 17: /* FALLTHROUGH */
|
|
326
|
+
case 137:
|
|
327
|
+
return 'Polygon';
|
|
328
|
+
case 244:
|
|
329
|
+
return "Osmosis";
|
|
330
|
+
case 13: /* FALLTHROUGH */
|
|
331
|
+
case 245:
|
|
332
|
+
return "Terra Classic";
|
|
333
|
+
case 246:
|
|
334
|
+
return "Cosmos Hub";
|
|
335
|
+
case 5: /* FALLTHROUGH */
|
|
336
|
+
case 247:
|
|
337
|
+
return "Juno";
|
|
338
|
+
case 7: /* FALLTHROUGH */
|
|
339
|
+
case 248:
|
|
340
|
+
return "Evmos";
|
|
341
|
+
case 8: /* FALLTHROUGH */
|
|
342
|
+
case 249:
|
|
343
|
+
return "Axelar";
|
|
344
|
+
case 313:
|
|
345
|
+
return "Stride";
|
|
346
|
+
case 314:
|
|
347
|
+
return "Kujira";
|
|
348
|
+
case 315:
|
|
349
|
+
return "Terra";
|
|
350
|
+
case 316:
|
|
351
|
+
return "Quicksilver";
|
|
352
|
+
case 12: /* FALLTHROUGH */
|
|
353
|
+
case 317:
|
|
354
|
+
return "Comdex";
|
|
355
|
+
case 318:
|
|
356
|
+
return "Stafihub";
|
|
357
|
+
case 15: /* FALLTHROUGH */
|
|
358
|
+
case 319:
|
|
359
|
+
return "Persistence Core";
|
|
360
|
+
case 16: /* FALLTHROUGH */
|
|
361
|
+
case 320:
|
|
362
|
+
return "Stargaze";
|
|
363
|
+
case 321:
|
|
364
|
+
return "Canto";
|
|
365
|
+
case 322:
|
|
366
|
+
return "OmniFlix Hub";
|
|
367
|
+
case 323:
|
|
368
|
+
return "Agoric";
|
|
369
|
+
case 19: /* FALLTHROUGH */
|
|
370
|
+
case 42161:
|
|
371
|
+
return "Arbitrum";
|
|
372
|
+
default:
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
case network_1.Network.TestNet:
|
|
376
|
+
switch (chainId) {
|
|
377
|
+
case 1:
|
|
378
|
+
return "Bitcoin";
|
|
379
|
+
case 0:
|
|
380
|
+
case 5:
|
|
381
|
+
return "Carbon";
|
|
382
|
+
case 79:
|
|
383
|
+
return "Binance Smart Chain";
|
|
384
|
+
case 88:
|
|
385
|
+
return "Neo3";
|
|
386
|
+
case 111:
|
|
387
|
+
return "Zilliqa";
|
|
388
|
+
case 2: /* FALLTHROUGH */
|
|
389
|
+
case 502:
|
|
390
|
+
return "Ethereum";
|
|
391
|
+
default:
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
case network_1.Network.DevNet:
|
|
395
|
+
switch (chainId) {
|
|
396
|
+
case 0:
|
|
397
|
+
return 'Carbon';
|
|
398
|
+
case 1:
|
|
399
|
+
return 'Bitcoin';
|
|
400
|
+
case 2:
|
|
401
|
+
case 350:
|
|
402
|
+
return "Ethereum";
|
|
403
|
+
case 5:
|
|
404
|
+
return "Neo";
|
|
405
|
+
case 79:
|
|
406
|
+
return "Binance Smart Chain";
|
|
407
|
+
case 111:
|
|
408
|
+
return 'Zilliqa';
|
|
409
|
+
default:
|
|
410
|
+
return undefined;
|
|
411
|
+
}
|
|
412
|
+
case network_1.Network.LocalHost:
|
|
413
|
+
return undefined;
|
|
414
|
+
default:
|
|
415
|
+
return undefined;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
exports.blockchainForChainIdV2 = blockchainForChainIdV2;
|
|
419
|
+
const evmChains = ['Ethereum', 'Binance Smart Chain', 'Arbitrum', 'Polygon', 'OKC'];
|
|
420
|
+
const isEvmChain = (chain) => evmChains.includes(chain);
|
|
421
|
+
exports.isEvmChain = isEvmChain;
|
package/lib/util/fetch.js
CHANGED
package/lib/util/generic.js
CHANGED
|
@@ -22,7 +22,7 @@ const overrideConfig = (defaults, override) => {
|
|
|
22
22
|
continue;
|
|
23
23
|
if (typeof member === "object") {
|
|
24
24
|
// @ts-ignore
|
|
25
|
-
result[key] = exports.overrideConfig(result[key], member);
|
|
25
|
+
result[key] = (0, exports.overrideConfig)(result[key], member);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
28
|
// @ts-ignore
|
|
@@ -41,7 +41,7 @@ const sortObject = (input) => {
|
|
|
41
41
|
Object.keys(input)
|
|
42
42
|
.sort()
|
|
43
43
|
// @ts-ignore noImplicitAny
|
|
44
|
-
.forEach((key) => (output[key] = exports.sortObject(input[key])));
|
|
44
|
+
.forEach((key) => (output[key] = (0, exports.sortObject)(input[key])));
|
|
45
45
|
return output;
|
|
46
46
|
};
|
|
47
47
|
exports.sortObject = sortObject;
|
|
@@ -56,7 +56,7 @@ exports.appendHexPrefix = appendHexPrefix;
|
|
|
56
56
|
const computeTxHash = (bytes) => {
|
|
57
57
|
if (!bytes)
|
|
58
58
|
return bytes;
|
|
59
|
-
return exports.toTxHash(crypto_1.sha256(bytes));
|
|
59
|
+
return (0, exports.toTxHash)((0, crypto_1.sha256)(bytes));
|
|
60
60
|
};
|
|
61
61
|
exports.computeTxHash = computeTxHash;
|
|
62
62
|
const toTxHash = (bytes) => {
|
package/lib/util/ibc.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ChainInfoExplorerTmRpc, ChainIds, GasPriceStep, AssetListObj } from "../constant";
|
|
2
2
|
import { AppCurrency } from "@keplr-wallet/types";
|
|
3
|
-
import { Blockchain } from "./blockchain";
|
|
3
|
+
import { Blockchain, BlockchainV2 } from "./blockchain";
|
|
4
4
|
import { SimpleMap } from "./type";
|
|
5
5
|
export declare function makeIBCMinimalDenom(sourceChannelId: string, coinMinimalDenom: string): string;
|
|
6
6
|
export declare const EmbedChainInfos: SimpleMap<ChainInfoExplorerTmRpc>;
|
|
7
7
|
export declare const totalAssetObj: AssetListObj;
|
|
8
|
+
export declare const ChainIdBlockchainMapV2: SimpleMap<BlockchainV2>;
|
|
8
9
|
export declare const ChainIdBlockchainMap: SimpleMap<Blockchain>;
|
|
9
|
-
export declare const getIbcChainFromBlockchain: (blockchain:
|
|
10
|
-
export declare const BlockchainMap: SimpleMap<
|
|
10
|
+
export declare const getIbcChainFromBlockchain: (blockchain: BlockchainV2 | undefined) => ChainIds | undefined;
|
|
11
|
+
export declare const BlockchainMap: SimpleMap<string | undefined>;
|
|
11
12
|
export interface ChainIdOutput {
|
|
12
13
|
identifier: string;
|
|
13
14
|
version: number;
|