carbon-js-sdk 0.3.20 → 0.3.21
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.d.ts +5 -1
- package/lib/CarbonSDK.js +24 -4
- package/lib/clients/CarbonQueryClient.js +2 -2
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/NEOClient.js +7 -7
- package/lib/clients/ZILClient.js +16 -16
- package/lib/codec/cosmos/gov/v1beta1/query.js +2 -2
- package/lib/codec/cosmos/gov/v1beta1/tx.js +2 -2
- package/lib/codec/cosmos/tx/v1beta1/tx.js +2 -2
- package/lib/constant/generic.js +1 -1
- package/lib/constant/ibc.js +41 -41
- package/lib/constant/network.d.ts +6 -0
- package/lib/constant/network.js +7 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/modules/cdp.js +43 -43
- package/lib/modules/gov.js +14 -14
- 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 +30 -30
- 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 +2 -2
- 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/index.d.ts +1 -0
- package/lib/provider/index.js +3 -1
- package/lib/provider/keplr/KeplrStore.d.ts +9 -3
- package/lib/provider/keplr/KeplrStore.js +69 -18
- package/lib/provider/ledger/ledger.js +2 -2
- package/lib/provider/metamask/MetaMask.js +1 -1
- 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/fetch.js +1 -1
- package/lib/util/generic.js +3 -3
- 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.d.ts +3 -0
- package/lib/wallet/CarbonWallet.js +12 -6
- package/lib/websocket/connector.js +3 -3
- package/package.json +8 -4
|
@@ -106,9 +106,9 @@ class CarbonLedgerSigner {
|
|
|
106
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
107
|
const account = yield this.retrieveAccount();
|
|
108
108
|
const { pubkey } = account;
|
|
109
|
-
const msg = JSON.stringify(generic_1.sortObject(doc));
|
|
109
|
+
const msg = JSON.stringify((0, generic_1.sortObject)(doc));
|
|
110
110
|
const signBytes = yield this.ledger.sign(msg);
|
|
111
|
-
const signature = amino_1.encodeSecp256k1Signature(pubkey, signBytes);
|
|
111
|
+
const signature = (0, amino_1.encodeSecp256k1Signature)(pubkey, signBytes);
|
|
112
112
|
return {
|
|
113
113
|
signed: doc,
|
|
114
114
|
signature,
|
|
@@ -87,7 +87,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
87
87
|
*/
|
|
88
88
|
sign(signerAddress, messages, fee, memo, signerData) {
|
|
89
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
return proto_signing_1.isOfflineDirectSigner(this.signer)
|
|
90
|
+
return (0, proto_signing_1.isOfflineDirectSigner)(this.signer)
|
|
91
91
|
? this.signDirect(signerAddress, messages, fee, memo, signerData)
|
|
92
92
|
: this.signAmino(signerAddress, messages, fee, memo, signerData);
|
|
93
93
|
});
|
|
@@ -99,7 +99,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
99
99
|
if (!accountFromSigner) {
|
|
100
100
|
throw new Error("Failed to retrieve account from signer");
|
|
101
101
|
}
|
|
102
|
-
const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
|
|
102
|
+
const pubkey = (0, proto_signing_1.encodePubkey)((0, amino_1.encodeSecp256k1Pubkey)(accountFromSigner.pubkey));
|
|
103
103
|
const txBodyEncodeObject = {
|
|
104
104
|
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
105
105
|
value: Object.assign({ messages: messages, memo: memo }, timeoutHeight && {
|
|
@@ -108,13 +108,13 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
108
108
|
};
|
|
109
109
|
const txBodyBytes = this.registry.encode(txBodyEncodeObject);
|
|
110
110
|
const gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
|
|
111
|
-
const authInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey, sequence }], fee.amount, gasLimit);
|
|
112
|
-
const signDoc = proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
|
111
|
+
const authInfoBytes = (0, proto_signing_1.makeAuthInfoBytes)([{ pubkey, sequence }], fee.amount, gasLimit);
|
|
112
|
+
const signDoc = (0, proto_signing_1.makeSignDoc)(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
|
113
113
|
const { signature, signed } = yield signer.signDirect(signerAddress, signDoc);
|
|
114
114
|
return tx_1.TxRaw.fromPartial({
|
|
115
115
|
bodyBytes: signed.bodyBytes,
|
|
116
116
|
authInfoBytes: signed.authInfoBytes,
|
|
117
|
-
signatures: [encoding_1.fromBase64(signature.signature)],
|
|
117
|
+
signatures: [(0, encoding_1.fromBase64)(signature.signature)],
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
}
|
|
@@ -125,7 +125,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
125
125
|
if (!accountFromSigner) {
|
|
126
126
|
throw new Error("Failed to retrieve account from signer");
|
|
127
127
|
}
|
|
128
|
-
const pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
|
|
128
|
+
const pubkey = (0, proto_signing_1.encodePubkey)((0, amino_1.encodeSecp256k1Pubkey)(accountFromSigner.pubkey));
|
|
129
129
|
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
|
|
130
130
|
const msgs = messages.map((msg) => this.aminoTypes.toAmino(msg));
|
|
131
131
|
const signDoc = makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence, timeoutHeight !== null && timeoutHeight !== void 0 ? timeoutHeight : 0);
|
|
@@ -140,11 +140,11 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
140
140
|
const signedTxBodyBytes = this.registry.encode(signedTxBodyEncodeObject);
|
|
141
141
|
const signedGasLimit = math_1.Int53.fromString(signed.fee.gas).toNumber();
|
|
142
142
|
const signedSequence = math_1.Int53.fromString(signed.sequence).toNumber();
|
|
143
|
-
const signedAuthInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey, sequence: signedSequence }], signed.fee.amount, signedGasLimit, signMode);
|
|
143
|
+
const signedAuthInfoBytes = (0, proto_signing_1.makeAuthInfoBytes)([{ pubkey, sequence: signedSequence }], signed.fee.amount, signedGasLimit, signMode);
|
|
144
144
|
return tx_1.TxRaw.fromPartial({
|
|
145
145
|
bodyBytes: signedTxBodyBytes,
|
|
146
146
|
authInfoBytes: signedAuthInfoBytes,
|
|
147
|
-
signatures: [encoding_1.fromBase64(signature.signature)],
|
|
147
|
+
signatures: [(0, encoding_1.fromBase64)(signature.signature)],
|
|
148
148
|
});
|
|
149
149
|
});
|
|
150
150
|
}
|
|
@@ -10,7 +10,9 @@ import { EncodeObject, OfflineDirectSigner, OfflineSigner } from "@cosmjs/proto-
|
|
|
10
10
|
import { Account, DeliverTxResponse } from "@cosmjs/stargate";
|
|
11
11
|
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
|
12
12
|
import { BroadcastTxSyncResponse } from "@cosmjs/tendermint-rpc/build/tendermint34/responses";
|
|
13
|
+
import { Leap } from "@cosmos-kit/leap";
|
|
13
14
|
import { Key } from "@keplr-wallet/types";
|
|
15
|
+
import { Key as LeapKey } from "@cosmos-kit/core";
|
|
14
16
|
import BigNumber from "bignumber.js";
|
|
15
17
|
import { TxRaw as StargateTxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
16
18
|
import { CarbonSigner, CarbonSignerTypes } from "./CarbonSigner";
|
|
@@ -101,6 +103,7 @@ export declare class CarbonWallet {
|
|
|
101
103
|
static withLedger(cosmosLedger: CosmosLedger, publicKeyBase64: string, opts?: Omit<CarbonWalletInitOpts, "signer">): CarbonWallet;
|
|
102
104
|
static withSigner(signer: CarbonSigner, publicKeyBase64: string, opts?: Omit<CarbonWalletInitOpts, "signer">): CarbonWallet;
|
|
103
105
|
static withKeplr(keplr: Keplr, chainInfo: ChainInfo, keplrKey: Key, opts?: Omit<CarbonWalletInitOpts, "signer">): CarbonWallet;
|
|
106
|
+
static withLeap(leap: Leap, chainId: string, leapKey: LeapKey, opts?: Omit<CarbonWalletInitOpts, "signer">): CarbonWallet;
|
|
104
107
|
static withAddress(bech32Address: string, opts?: Partial<CarbonWalletInitOpts>): CarbonWallet;
|
|
105
108
|
initialize(queryClient: CarbonQueryClient): Promise<CarbonWallet>;
|
|
106
109
|
updateNetwork(network: Network): CarbonWallet;
|
|
@@ -115,6 +115,12 @@ class CarbonWallet {
|
|
|
115
115
|
const wallet = CarbonWallet.withSigner(signer, publicKeyBase64, opts);
|
|
116
116
|
return wallet;
|
|
117
117
|
}
|
|
118
|
+
static withLeap(leap, chainId, leapKey, opts = {}) {
|
|
119
|
+
const signer = provider_1.LeapAccount.createLeapSigner(leap, chainId);
|
|
120
|
+
const publicKeyBase64 = Buffer.from(leapKey.pubKey).toString("base64");
|
|
121
|
+
const wallet = CarbonWallet.withSigner(signer, publicKeyBase64, opts);
|
|
122
|
+
return wallet;
|
|
123
|
+
}
|
|
118
124
|
static withAddress(bech32Address, opts = {}) {
|
|
119
125
|
return new CarbonWallet(Object.assign(Object.assign({}, opts), { bech32Address }));
|
|
120
126
|
}
|
|
@@ -148,7 +154,7 @@ class CarbonWallet {
|
|
|
148
154
|
const signerData = Object.assign({ accountNumber: this.accountInfo.accountNumber, chainId: this.getChainId(), sequence }, explicitSignerData);
|
|
149
155
|
const fee = (_a = opts === null || opts === void 0 ? void 0 : opts.fee) !== null && _a !== void 0 ? _a : this.estimateTxFee(messages, feeDenom);
|
|
150
156
|
const txRaw = yield signingClient.sign(signerAddress, messages, fee, memo, signerData);
|
|
151
|
-
signature = amino_1.encodeSecp256k1Signature(account.pubkey, txRaw.signatures[0]);
|
|
157
|
+
signature = (0, amino_1.encodeSecp256k1Signature)(account.pubkey, txRaw.signatures[0]);
|
|
152
158
|
return txRaw;
|
|
153
159
|
}
|
|
154
160
|
finally {
|
|
@@ -166,7 +172,7 @@ class CarbonWallet {
|
|
|
166
172
|
const tx = CarbonWallet.TxRaw.encode(txRaw).finish();
|
|
167
173
|
const carbonClient = this.getSigningClient();
|
|
168
174
|
const response = yield carbonClient.broadcastTx(tx, timeoutMs, pollIntervalMs);
|
|
169
|
-
if (stargate_1.isDeliverTxFailure(response)) {
|
|
175
|
+
if ((0, stargate_1.isDeliverTxFailure)(response)) {
|
|
170
176
|
// tx failed
|
|
171
177
|
throw new tx_1.CarbonTxError(`[${response.code}] ${response.rawLog}`, response);
|
|
172
178
|
}
|
|
@@ -205,9 +211,9 @@ class CarbonWallet {
|
|
|
205
211
|
try {
|
|
206
212
|
if (!this.accountInfo || this.sequenceInvalidated)
|
|
207
213
|
yield this.reloadAccountSequence();
|
|
208
|
-
const heightResponse = yield fetch_1.fetch(`${this.networkConfig.tmRpcUrl}/blockchain?cache=${new Date().getTime()}`);
|
|
214
|
+
const heightResponse = yield (0, fetch_1.fetch)(`${this.networkConfig.tmRpcUrl}/blockchain?cache=${new Date().getTime()}`);
|
|
209
215
|
const heightRes = yield heightResponse.json();
|
|
210
|
-
const height = number_1.bnOrZero((_a = heightRes.result) === null || _a === void 0 ? void 0 : _a.last_height);
|
|
216
|
+
const height = (0, number_1.bnOrZero)((_a = heightRes.result) === null || _a === void 0 ? void 0 : _a.last_height);
|
|
211
217
|
const timeoutHeight = height.isZero() ? undefined : height.toNumber() + this.defaultTimeoutBlocks;
|
|
212
218
|
const sequence = this.accountInfo.sequence;
|
|
213
219
|
this.accountInfo = Object.assign(Object.assign({}, this.accountInfo), { sequence: sequence + 1 });
|
|
@@ -341,12 +347,12 @@ class CarbonWallet {
|
|
|
341
347
|
const queryClient = this.getQueryClient();
|
|
342
348
|
const { msgGasCosts } = yield queryClient.fee.MsgGasCostAll({});
|
|
343
349
|
this.txGasCosts = msgGasCosts.reduce((result, item) => {
|
|
344
|
-
result[item.msgType] = number_1.bnOrZero(item.gasCost);
|
|
350
|
+
result[item.msgType] = (0, number_1.bnOrZero)(item.gasCost);
|
|
345
351
|
return result;
|
|
346
352
|
}, {});
|
|
347
353
|
const { minGasPrices } = yield queryClient.fee.MinGasPriceAll({});
|
|
348
354
|
this.txGasPrices = minGasPrices.reduce((result, item) => {
|
|
349
|
-
result[item.denom] = number_1.bnOrZero(item.gasPrice).shiftedBy(-18); // sdk.Dec shifting
|
|
355
|
+
result[item.denom] = (0, number_1.bnOrZero)(item.gasPrice).shiftedBy(-18); // sdk.Dec shifting
|
|
350
356
|
return result;
|
|
351
357
|
}, {});
|
|
352
358
|
if (!this.txGasPrices[this.defaultFeeDenom]) {
|
|
@@ -171,7 +171,7 @@ class WSConnector {
|
|
|
171
171
|
params = [params]; // eslint-disable-line no-param-reassign
|
|
172
172
|
}
|
|
173
173
|
for (const param of params) {
|
|
174
|
-
const channelId = channel_1.generateChannelId(param);
|
|
174
|
+
const channelId = (0, channel_1.generateChannelId)(param);
|
|
175
175
|
const shouldSubscribe = this.channelHandlers[channelId] === undefined;
|
|
176
176
|
this.channelHandlers[channelId] = handler;
|
|
177
177
|
if (shouldSubscribe) {
|
|
@@ -193,7 +193,7 @@ class WSConnector {
|
|
|
193
193
|
}
|
|
194
194
|
const channelIds = [];
|
|
195
195
|
for (const param of params) {
|
|
196
|
-
const channelId = channel_1.generateChannelId(param);
|
|
196
|
+
const channelId = (0, channel_1.generateChannelId)(param);
|
|
197
197
|
const shouldUnsubscribe = this.channelHandlers[channelId] !== undefined;
|
|
198
198
|
delete this.channelHandlers[channelId];
|
|
199
199
|
if (shouldUnsubscribe) {
|
|
@@ -283,7 +283,7 @@ class WSConnector {
|
|
|
283
283
|
if (!channelHandler) {
|
|
284
284
|
this.debugLog(`handler not found for channel: ${message.channel}`);
|
|
285
285
|
try {
|
|
286
|
-
const params = channel_1.parseChannelId(message.channel);
|
|
286
|
+
const params = (0, channel_1.parseChannelId)(message.channel);
|
|
287
287
|
this.unsubscribe({ channel: params.channel });
|
|
288
288
|
}
|
|
289
289
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-js-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.21",
|
|
4
4
|
"description": "TypeScript SDK for Carbon blockchain",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -38,13 +38,14 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@cityofzion/neon-api": "^4.9.0",
|
|
40
40
|
"@cityofzion/neon-core": "^4.9.0",
|
|
41
|
-
"@cityofzion/neon-js": "^4.9.0",
|
|
42
41
|
"@cityofzion/neon-core-next": "npm:@cityofzion/neon-core@^5.0.0",
|
|
42
|
+
"@cityofzion/neon-js": "^4.9.0",
|
|
43
43
|
"@cosmjs/proto-signing": "^0.28.10",
|
|
44
44
|
"@cosmjs/stargate": "^0.28.10",
|
|
45
|
+
"@cosmos-kit/leap": "^0.13.14",
|
|
45
46
|
"@grpc/grpc-js": "^1.3.2",
|
|
46
|
-
"@keplr-wallet/stores": "
|
|
47
|
-
"@keplr-wallet/types": "
|
|
47
|
+
"@keplr-wallet/stores": "^0.10.24",
|
|
48
|
+
"@keplr-wallet/types": "^0.10.24",
|
|
48
49
|
"@ledgerhq/hw-app-eth": "^6.11.2",
|
|
49
50
|
"@ledgerhq/hw-transport": "^6.3.0",
|
|
50
51
|
"@ledgerhq/hw-transport-webhid": "^6.4.1",
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
"dayjs": "^1.10.5",
|
|
59
60
|
"eth-sig-util": "^3.0.0",
|
|
60
61
|
"ethers": "^5.5.1",
|
|
62
|
+
"eventemitter3": "^5.0.0",
|
|
61
63
|
"ledger-cosmos-js": "^2.1.8",
|
|
62
64
|
"lodash": "^4.17.21",
|
|
63
65
|
"neo-dapi": "^2.0.4",
|
|
@@ -67,6 +69,7 @@
|
|
|
67
69
|
"ripemd160": "^2.0.2",
|
|
68
70
|
"secp256k1": "^4.0.2",
|
|
69
71
|
"secp256r1": "^0.0.3",
|
|
72
|
+
"semver": "^7.3.7",
|
|
70
73
|
"tsc-alias": "^1.2.11",
|
|
71
74
|
"typescript": "^4.3.5",
|
|
72
75
|
"wif": "^2.0.6"
|
|
@@ -80,6 +83,7 @@
|
|
|
80
83
|
"@types/node-fetch": "^2.5.12",
|
|
81
84
|
"@types/ripemd160": "^2.0.0",
|
|
82
85
|
"@types/secp256k1": "^4.0.2",
|
|
86
|
+
"@types/semver": "^7.3.13",
|
|
83
87
|
"@types/w3c-web-hid": "^1.0.2",
|
|
84
88
|
"@types/w3c-web-usb": "^1.0.5",
|
|
85
89
|
"@types/websocket": "^1.0.4",
|