carbon-js-sdk 0.11.2 → 0.11.3-beta.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/constant/ibc.js
CHANGED
|
@@ -204,7 +204,6 @@ exports.EmbedChainInfosInit = {
|
|
|
204
204
|
coinGeckoId: "cosmos",
|
|
205
205
|
},
|
|
206
206
|
],
|
|
207
|
-
coinType: 118,
|
|
208
207
|
features: ["ibc-transfer", "ibc-go"],
|
|
209
208
|
explorerUrlToTx: "https://www.mintscan.io/cosmos/txs/{txHash}",
|
|
210
209
|
tmRpc: "https://rpc.cosmos.network/",
|
|
@@ -303,7 +302,6 @@ exports.EmbedChainInfosInit = {
|
|
|
303
302
|
coinGeckoId: "secret",
|
|
304
303
|
},
|
|
305
304
|
],
|
|
306
|
-
coinType: 118,
|
|
307
305
|
features: ["ibc-transfer", "ibc-go"],
|
|
308
306
|
explorerUrlToTx: "https://secretnodes.com/secret/chains/secret-4/transactions/{txHash}",
|
|
309
307
|
},
|
|
@@ -338,7 +336,6 @@ exports.EmbedChainInfosInit = {
|
|
|
338
336
|
coinGeckoId: "akash-network",
|
|
339
337
|
},
|
|
340
338
|
],
|
|
341
|
-
coinType: 118,
|
|
342
339
|
features: ["ibc-transfer", "ibc-go"],
|
|
343
340
|
explorerUrlToTx: "https://www.mintscan.io/akash/txs/{txHash}",
|
|
344
341
|
},
|
|
@@ -1138,7 +1135,6 @@ exports.EmbedChainInfosInit = {
|
|
|
1138
1135
|
coinGeckoId: "pool:ulum",
|
|
1139
1136
|
},
|
|
1140
1137
|
],
|
|
1141
|
-
coinType: 118,
|
|
1142
1138
|
features: ["ibc-transfer", "ibc-go"],
|
|
1143
1139
|
explorerUrlToTx: "https://www.mintscan.io/lum/txs/{txHash}",
|
|
1144
1140
|
tmRpc: "https://node0.mainnet.lum.network/rpc/",
|
|
@@ -1174,7 +1170,6 @@ exports.EmbedChainInfosInit = {
|
|
|
1174
1170
|
coinGeckoId: "vidulum",
|
|
1175
1171
|
},
|
|
1176
1172
|
],
|
|
1177
|
-
coinType: 370,
|
|
1178
1173
|
features: ["ibc-transfer", "ibc-go"],
|
|
1179
1174
|
explorerUrlToTx: "https://explorers.vidulum.app/vidulum/tx/{txHash}",
|
|
1180
1175
|
tmRpc: "https://mainnet-rpc.vidulum.app/",
|
|
@@ -1889,7 +1884,6 @@ exports.EmbedChainInfosInit = {
|
|
|
1889
1884
|
coinType: 60,
|
|
1890
1885
|
},
|
|
1891
1886
|
bech32Config: exports.IBCAddress.defaultBech32Config("canto"),
|
|
1892
|
-
coinType: 60,
|
|
1893
1887
|
currencies: [
|
|
1894
1888
|
{
|
|
1895
1889
|
coinDenom: "CANTO",
|
|
@@ -50,13 +50,13 @@ class KeplrAccount {
|
|
|
50
50
|
const sendEvmTransaction = (api, req) => __awaiter(this, void 0, void 0, function* () {
|
|
51
51
|
var _a, _b, _c, _d;
|
|
52
52
|
try {
|
|
53
|
-
const
|
|
53
|
+
const unsignedTx = yield ethermint_1.populateUnsignedEvmTranscation(api, req);
|
|
54
54
|
const signedTx = yield keplr.signEthereum(
|
|
55
55
|
// carbon chain id
|
|
56
56
|
(_b = (_a = api.wallet) === null || _a === void 0 ? void 0 : _a.getChainId()) !== null && _b !== void 0 ? _b : '',
|
|
57
57
|
// cosmos address
|
|
58
|
-
(_d = (_c = api.wallet) === null || _c === void 0 ? void 0 : _c.bech32Address) !== null && _d !== void 0 ? _d : '', JSON.stringify(
|
|
59
|
-
const rlpEncodedHex =
|
|
58
|
+
(_d = (_c = api.wallet) === null || _c === void 0 ? void 0 : _c.bech32Address) !== null && _d !== void 0 ? _d : '', JSON.stringify(unsignedTx), types_1.EthSignType.TRANSACTION);
|
|
59
|
+
const rlpEncodedHex = ethers_1.ethers.utils.serializeTransaction(unsignedTx, signedTx);
|
|
60
60
|
const provider = new ethers_1.ethers.providers.JsonRpcProvider(constant_1.NetworkConfigs[api.network].evmJsonRpcUrl);
|
|
61
61
|
return (yield provider.sendTransaction(rlpEncodedHex)).hash;
|
|
62
62
|
}
|
|
@@ -96,13 +96,14 @@ class KeplrAccount {
|
|
|
96
96
|
const sendEvmTransaction = (api, req) => __awaiter(this, void 0, void 0, function* () {
|
|
97
97
|
var _a, _b, _c, _d;
|
|
98
98
|
try {
|
|
99
|
-
const
|
|
99
|
+
const unsignedTx = yield ethermint_1.populateUnsignedEvmTranscation(api, req);
|
|
100
100
|
const signedTx = yield keplr.signEthereum(
|
|
101
101
|
// carbon chain id
|
|
102
102
|
(_b = (_a = api.wallet) === null || _a === void 0 ? void 0 : _a.getChainId()) !== null && _b !== void 0 ? _b : '',
|
|
103
103
|
// cosmos address
|
|
104
|
-
(_d = (_c = api.wallet) === null || _c === void 0 ? void 0 : _c.bech32Address) !== null && _d !== void 0 ? _d : '', JSON.stringify(
|
|
105
|
-
const rlpEncodedHex = `0x${Buffer.from(signedTx).toString('hex')}
|
|
104
|
+
(_d = (_c = api.wallet) === null || _c === void 0 ? void 0 : _c.bech32Address) !== null && _d !== void 0 ? _d : '', JSON.stringify(unsignedTx), types_1.EthSignType.TRANSACTION);
|
|
105
|
+
// const rlpEncodedHex = `0x${Buffer.from(signedTx).toString('hex')}`
|
|
106
|
+
const rlpEncodedHex = ethers_1.ethers.utils.serializeTransaction(unsignedTx, signedTx);
|
|
106
107
|
const provider = new ethers_1.ethers.providers.JsonRpcProvider(constant_1.NetworkConfigs[api.network].evmJsonRpcUrl);
|
|
107
108
|
return (yield provider.sendTransaction(rlpEncodedHex)).hash;
|
|
108
109
|
}
|
|
@@ -199,6 +200,10 @@ class KeplrAccount {
|
|
|
199
200
|
rpc: config.tmRpcUrl,
|
|
200
201
|
chainName: `Carbon (${config.network})`,
|
|
201
202
|
chainId: chainId,
|
|
203
|
+
evm: {
|
|
204
|
+
chainId: Number(ethermint_1.parseChainId(constant_1.CarbonEvmChainIDs[config.network])),
|
|
205
|
+
rpc: config.evmJsonRpcUrl,
|
|
206
|
+
},
|
|
202
207
|
bech32Config: {
|
|
203
208
|
bech32PrefixAccAddr: `${bech32Prefix}`,
|
|
204
209
|
bech32PrefixAccPub: `${bech32Prefix}pub`,
|
|
@@ -12,7 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
const constant_1 = require("../../constant");
|
|
13
13
|
const util_1 = require("../../util");
|
|
14
14
|
const wallet_1 = require("../../wallet");
|
|
15
|
+
const types_1 = require("@keplr-wallet/types");
|
|
16
|
+
const ethers_1 = require("ethers");
|
|
15
17
|
const provider_1 = require("../../util/provider");
|
|
18
|
+
const ethermint_1 = require("../../util/ethermint");
|
|
19
|
+
const error_1 = require("../metamask/error");
|
|
16
20
|
const SWTH = {
|
|
17
21
|
coinDenom: "SWTH",
|
|
18
22
|
coinMinimalDenom: "swth",
|
|
@@ -45,7 +49,29 @@ class LeapAccount {
|
|
|
45
49
|
];
|
|
46
50
|
});
|
|
47
51
|
const sendEvmTransaction = (api, req) => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
|
|
52
|
+
var _a, _b, _c, _d;
|
|
53
|
+
try {
|
|
54
|
+
// workaround for version mismatch in cosmos-kit/leap and leap-extension
|
|
55
|
+
const leapInterface = leap;
|
|
56
|
+
if (typeof leapInterface.signEthereum === 'function') {
|
|
57
|
+
const unsignedTx = yield ethermint_1.populateUnsignedEvmTranscation(api, req);
|
|
58
|
+
const signedTx = yield leapInterface.signEthereum(
|
|
59
|
+
// carbon chain id
|
|
60
|
+
(_b = (_a = api.wallet) === null || _a === void 0 ? void 0 : _a.getChainId()) !== null && _b !== void 0 ? _b : '',
|
|
61
|
+
// cosmos address
|
|
62
|
+
(_d = (_c = api.wallet) === null || _c === void 0 ? void 0 : _c.bech32Address) !== null && _d !== void 0 ? _d : '', JSON.stringify(unsignedTx), types_1.EthSignType.TRANSACTION);
|
|
63
|
+
const rlpEncodedHex = ethers_1.ethers.utils.serializeTransaction(unsignedTx, signedTx);
|
|
64
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(constant_1.NetworkConfigs[api.network].evmJsonRpcUrl);
|
|
65
|
+
return (yield provider.sendTransaction(rlpEncodedHex)).hash;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new Error("signing not available");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error(error);
|
|
73
|
+
throw (error_1.parseEvmError(error));
|
|
74
|
+
}
|
|
49
75
|
});
|
|
50
76
|
const signMessage = (address, message) => __awaiter(this, void 0, void 0, function* () {
|
|
51
77
|
const { signature } = yield leap.signArbitrary(chainId, address, message);
|
|
@@ -78,7 +104,29 @@ class LeapAccount {
|
|
|
78
104
|
];
|
|
79
105
|
});
|
|
80
106
|
const sendEvmTransaction = (api, req) => __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
|
|
107
|
+
var _a, _b, _c, _d;
|
|
108
|
+
try {
|
|
109
|
+
const leapInterface = leap;
|
|
110
|
+
if (typeof leapInterface.signEthereum === 'function') {
|
|
111
|
+
const unsignedTx = yield ethermint_1.populateUnsignedEvmTranscation(api, req);
|
|
112
|
+
console.log('xx unsignedTx', unsignedTx);
|
|
113
|
+
const signedTx = yield leapInterface.signEthereum(
|
|
114
|
+
// carbon chain id
|
|
115
|
+
(_b = (_a = api.wallet) === null || _a === void 0 ? void 0 : _a.getChainId()) !== null && _b !== void 0 ? _b : '',
|
|
116
|
+
// cosmos address
|
|
117
|
+
(_d = (_c = api.wallet) === null || _c === void 0 ? void 0 : _c.bech32Address) !== null && _d !== void 0 ? _d : '', JSON.stringify(unsignedTx), types_1.EthSignType.TRANSACTION);
|
|
118
|
+
const rlpEncodedHex = ethers_1.ethers.utils.serializeTransaction(unsignedTx, signedTx);
|
|
119
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(constant_1.NetworkConfigs[api.network].evmJsonRpcUrl);
|
|
120
|
+
return (yield provider.sendTransaction(rlpEncodedHex)).hash;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
throw new Error("signing not available");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error(error);
|
|
128
|
+
throw (error_1.parseEvmError(error));
|
|
129
|
+
}
|
|
82
130
|
});
|
|
83
131
|
const signMessage = (address, message) => __awaiter(this, void 0, void 0, function* () {
|
|
84
132
|
const { signature } = yield leap.signArbitrary(chainId, address, message);
|
package/lib/util/ethermint.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare const PUBLIC_KEY_SIGNING_TEXT = "Sign your public key to merge yo
|
|
|
6
6
|
export declare function encodeAnyEthSecp256k1PubKey(pubkey: Uint8Array): Any;
|
|
7
7
|
export declare function parseChainId(evmChainId?: string): string;
|
|
8
8
|
export declare function populateEvmTransactionDetails(api: CarbonSDK, req: ethers.providers.TransactionRequest): Promise<ethers.providers.TransactionRequest>;
|
|
9
|
+
export declare function populateUnsignedEvmTranscation(api: CarbonSDK, req: ethers.providers.TransactionRequest): Promise<ethers.utils.UnsignedTransaction>;
|
package/lib/util/ethermint.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.populateEvmTransactionDetails = exports.parseChainId = exports.encodeAnyEthSecp256k1PubKey = exports.PUBLIC_KEY_SIGNING_TEXT = exports.ETH_SECP256K1_TYPE = void 0;
|
|
12
|
+
exports.populateUnsignedEvmTranscation = exports.populateEvmTransactionDetails = exports.parseChainId = exports.encodeAnyEthSecp256k1PubKey = exports.PUBLIC_KEY_SIGNING_TEXT = exports.ETH_SECP256K1_TYPE = void 0;
|
|
13
13
|
const codec_1 = require("../codec");
|
|
14
14
|
const keys_1 = require("../codec/ethermint/crypto/v1/ethsecp256k1/keys");
|
|
15
15
|
const constant_1 = require("../constant");
|
|
@@ -72,3 +72,47 @@ function populateEvmTransactionDetails(api, req) {
|
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
exports.populateEvmTransactionDetails = populateEvmTransactionDetails;
|
|
75
|
+
function populateUnsignedEvmTranscation(api, req) {
|
|
76
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(constant_1.NetworkConfigs[api.network].evmJsonRpcUrl);
|
|
79
|
+
const evmHexAddress = (_b = (_a = api.wallet) === null || _a === void 0 ? void 0 : _a.evmHexAddress) !== null && _b !== void 0 ? _b : '';
|
|
80
|
+
const nonce = (_c = req.nonce) !== null && _c !== void 0 ? _c : (yield provider.getTransactionCount(evmHexAddress));
|
|
81
|
+
const chainId = (_d = req.chainId) !== null && _d !== void 0 ? _d : Number(parseChainId((_f = yield ((_e = api.wallet) === null || _e === void 0 ? void 0 : _e.getEvmChainId())) !== null && _f !== void 0 ? _f : ''));
|
|
82
|
+
const value = req.value ? `0x${Number(req.value).toString(16)}` : undefined;
|
|
83
|
+
const baseTx = {
|
|
84
|
+
to: (_g = req.to) !== null && _g !== void 0 ? _g : '',
|
|
85
|
+
from: (_h = req.from) !== null && _h !== void 0 ? _h : (_j = api.wallet) === null || _j === void 0 ? void 0 : _j.evmHexAddress,
|
|
86
|
+
nonce,
|
|
87
|
+
data: req.data,
|
|
88
|
+
value,
|
|
89
|
+
chainId,
|
|
90
|
+
// type = 0, 1 or 2 where 0 = legacyTx, 1 = AccessListTx, 2 = DynamicTx. Defaults to DynamicTx
|
|
91
|
+
type: (_k = req.type) !== null && _k !== void 0 ? _k : 2,
|
|
92
|
+
accessList: req.accessList,
|
|
93
|
+
};
|
|
94
|
+
const gasLimit = (yield provider.estimateGas(baseTx)).toHexString();
|
|
95
|
+
const gasFee = yield provider.getFeeData();
|
|
96
|
+
const unsignedTx = {
|
|
97
|
+
to: (_l = req.to) !== null && _l !== void 0 ? _l : '',
|
|
98
|
+
nonce: parseInt(nonce.toString()),
|
|
99
|
+
data: req.data,
|
|
100
|
+
value,
|
|
101
|
+
chainId,
|
|
102
|
+
// type = 0, 1 or 2 where 0 = legacyTx, 1 = AccessListTx, 2 = DynamicTx. Defaults to DynamicTx
|
|
103
|
+
type: (_m = req.type) !== null && _m !== void 0 ? _m : 2,
|
|
104
|
+
accessList: req.accessList,
|
|
105
|
+
};
|
|
106
|
+
if (!req.gasPrice) {
|
|
107
|
+
// Dynamic Tx
|
|
108
|
+
return Object.assign(Object.assign({}, unsignedTx), { maxPriorityFeePerGas: (_o = req.maxPriorityFeePerGas) !== null && _o !== void 0 ? _o : (_p = gasFee.maxPriorityFeePerGas) === null || _p === void 0 ? void 0 : _p.toHexString(), maxFeePerGas: (_q = req.maxFeePerGas) !== null && _q !== void 0 ? _q : (_r = gasFee.maxFeePerGas) === null || _r === void 0 ? void 0 : _r.toHexString(), gasLimit, type: 2 });
|
|
109
|
+
}
|
|
110
|
+
if (req.accessList) {
|
|
111
|
+
// AccessList Tx
|
|
112
|
+
return Object.assign(Object.assign({}, unsignedTx), { gasLimit, type: 1 });
|
|
113
|
+
}
|
|
114
|
+
// LegacyTx
|
|
115
|
+
return Object.assign(Object.assign({}, unsignedTx), { gasLimit, type: 0 });
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.populateUnsignedEvmTranscation = populateUnsignedEvmTranscation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-js-sdk",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3-beta.1",
|
|
4
4
|
"description": "TypeScript SDK for Carbon blockchain",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@cosmos-kit/leap": "^0.15.12",
|
|
45
45
|
"@improbable-eng/grpc-web": "^0.15.0",
|
|
46
46
|
"@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
|
|
47
|
-
"@keplr-wallet/types": "^0.
|
|
47
|
+
"@keplr-wallet/types": "^0.12.107",
|
|
48
48
|
"@ledgerhq/hw-transport-webhid": "^6.20.0",
|
|
49
49
|
"@ledgerhq/hw-transport-webusb": "^6.20.0",
|
|
50
50
|
"@metamask/detect-provider": "^2.0.0",
|