carbon-js-sdk 0.2.16-dev.3 → 0.2.16-dev.4
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/clients/CarbonQueryClient.js +2 -2
- package/lib/clients/ETHClient.js +15 -15
- package/lib/clients/HydrogenClient.js +1 -1
- package/lib/clients/NEOClient.js +6 -6
- package/lib/clients/ZILClient.js +16 -16
- package/lib/codec/bank/tx.d.ts +64 -0
- package/lib/codec/bank/tx.js +236 -0
- 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/modules/cdp.js +52 -48
- 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/keplr/KeplrStore.js +1 -1
- 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.js +6 -6
- package/lib/websocket/connector.js +3 -3
- package/package.json +1 -1
|
@@ -145,27 +145,27 @@ const MsgSetCdpPaused = {
|
|
|
145
145
|
valueMap: {},
|
|
146
146
|
};
|
|
147
147
|
const CdpAmino = {
|
|
148
|
-
[CarbonTx.Types.MsgSupplyAsset]:
|
|
149
|
-
[CarbonTx.Types.MsgWithdrawAsset]:
|
|
150
|
-
[CarbonTx.Types.MsgLockCollateral]:
|
|
151
|
-
[CarbonTx.Types.MsgUnlockCollateral]:
|
|
152
|
-
[CarbonTx.Types.MsgBorrowAsset]:
|
|
153
|
-
[CarbonTx.Types.MsgRepayAsset]:
|
|
154
|
-
[CarbonTx.Types.MsgSupplyAssetAndLockCollateral]:
|
|
155
|
-
[CarbonTx.Types.MsgUnlockCollateralAndWithdrawAsset]:
|
|
156
|
-
[CarbonTx.Types.MsgLiquidateCollateral]:
|
|
157
|
-
[CarbonTx.Types.MsgRepayAssetWithCdpTokens]:
|
|
158
|
-
[CarbonTx.Types.MsgRepayAssetWithCollateral]:
|
|
159
|
-
[CarbonTx.Types.MsgMintStablecoin]:
|
|
160
|
-
[CarbonTx.Types.MsgReturnStablecoin]:
|
|
161
|
-
[CarbonTx.Types.MsgLiquidateCollateralWithCdpTokens]:
|
|
162
|
-
[CarbonTx.Types.MsgLiquidateCollateralWithCollateral]:
|
|
163
|
-
[CarbonTx.Types.MsgLiquidateCollateralWithStablecoin]:
|
|
164
|
-
[CarbonTx.Types.MsgCreateRewardScheme]:
|
|
165
|
-
[CarbonTx.Types.MsgUpdateRewardScheme]:
|
|
166
|
-
[CarbonTx.Types.MsgClaimRewards]:
|
|
167
|
-
[CarbonTx.Types.MsgSetStablecoinMintCap]:
|
|
168
|
-
[CarbonTx.Types.MsgSetStalePriceGracePeriod]:
|
|
169
|
-
[CarbonTx.Types.MsgSetCdpPaused]:
|
|
148
|
+
[CarbonTx.Types.MsgSupplyAsset]: utils_1.generateAminoType(MsgSupplyAsset),
|
|
149
|
+
[CarbonTx.Types.MsgWithdrawAsset]: utils_1.generateAminoType(MsgWithdrawAsset),
|
|
150
|
+
[CarbonTx.Types.MsgLockCollateral]: utils_1.generateAminoType(MsgLockCollateral),
|
|
151
|
+
[CarbonTx.Types.MsgUnlockCollateral]: utils_1.generateAminoType(MsgUnlockCollateral),
|
|
152
|
+
[CarbonTx.Types.MsgBorrowAsset]: utils_1.generateAminoType(MsgBorrowAsset),
|
|
153
|
+
[CarbonTx.Types.MsgRepayAsset]: utils_1.generateAminoType(MsgRepayAsset),
|
|
154
|
+
[CarbonTx.Types.MsgSupplyAssetAndLockCollateral]: utils_1.generateAminoType(MsgSupplyAssetAndLockCollateral),
|
|
155
|
+
[CarbonTx.Types.MsgUnlockCollateralAndWithdrawAsset]: utils_1.generateAminoType(MsgUnlockCollateralAndWithdrawAsset),
|
|
156
|
+
[CarbonTx.Types.MsgLiquidateCollateral]: utils_1.generateAminoType(MsgLiquidateCollateral),
|
|
157
|
+
[CarbonTx.Types.MsgRepayAssetWithCdpTokens]: utils_1.generateAminoType(MsgRepayAssetWithCdpTokens),
|
|
158
|
+
[CarbonTx.Types.MsgRepayAssetWithCollateral]: utils_1.generateAminoType(MsgRepayAssetWithCollateral),
|
|
159
|
+
[CarbonTx.Types.MsgMintStablecoin]: utils_1.generateAminoType(MsgMintStablecoin),
|
|
160
|
+
[CarbonTx.Types.MsgReturnStablecoin]: utils_1.generateAminoType(MsgReturnStablecoin),
|
|
161
|
+
[CarbonTx.Types.MsgLiquidateCollateralWithCdpTokens]: utils_1.generateAminoType(MsgLiquidateCollateralWithCdpTokens),
|
|
162
|
+
[CarbonTx.Types.MsgLiquidateCollateralWithCollateral]: utils_1.generateAminoType(MsgLiquidateCollateralWithCollateral),
|
|
163
|
+
[CarbonTx.Types.MsgLiquidateCollateralWithStablecoin]: utils_1.generateAminoType(MsgLiquidateCollateralWithStablecoin),
|
|
164
|
+
[CarbonTx.Types.MsgCreateRewardScheme]: utils_1.generateAminoType(MsgCreateRewardScheme),
|
|
165
|
+
[CarbonTx.Types.MsgUpdateRewardScheme]: utils_1.generateAminoType(MsgUpdateRewardScheme),
|
|
166
|
+
[CarbonTx.Types.MsgClaimRewards]: utils_1.generateAminoType(MsgClaimRewards),
|
|
167
|
+
[CarbonTx.Types.MsgSetStablecoinMintCap]: utils_1.generateAminoType(MsgSetStablecoinMintCap),
|
|
168
|
+
[CarbonTx.Types.MsgSetStalePriceGracePeriod]: utils_1.generateAminoType(MsgSetStalePriceGracePeriod),
|
|
169
|
+
[CarbonTx.Types.MsgSetCdpPaused]: utils_1.generateAminoType(MsgSetCdpPaused),
|
|
170
170
|
};
|
|
171
171
|
exports.default = CdpAmino;
|
|
@@ -34,7 +34,7 @@ const MsgMintToken = {
|
|
|
34
34
|
valueMap: {},
|
|
35
35
|
};
|
|
36
36
|
const CoinAmino = {
|
|
37
|
-
[CarbonTx.Types.MsgWithdraw]:
|
|
38
|
-
[CarbonTx.Types.MsgMintToken]:
|
|
37
|
+
[CarbonTx.Types.MsgWithdraw]: utils_1.generateAminoType(MsgWithdraw),
|
|
38
|
+
[CarbonTx.Types.MsgMintToken]: utils_1.generateAminoType(MsgMintToken),
|
|
39
39
|
};
|
|
40
40
|
exports.default = CoinAmino;
|
|
@@ -172,7 +172,7 @@ const SettlementPrice = {
|
|
|
172
172
|
};
|
|
173
173
|
;
|
|
174
174
|
const preProcessAmino = (value, valueMap) => {
|
|
175
|
-
return
|
|
175
|
+
return utils_1.mapEachIndiv(value, valueMap, false);
|
|
176
176
|
};
|
|
177
177
|
const checkDecodeProposal = (content, amino) => {
|
|
178
178
|
const decodedValue = util_1.GovUtils.decodeContent(content);
|
|
@@ -403,8 +403,8 @@ const proposalAminoProcess = {
|
|
|
403
403
|
},
|
|
404
404
|
};
|
|
405
405
|
const GovAmino = {
|
|
406
|
-
[CarbonTx.Types.MsgSubmitProposal]:
|
|
407
|
-
[CarbonTx.Types.MsgDeposit]:
|
|
408
|
-
[CarbonTx.Types.MsgVote]:
|
|
406
|
+
[CarbonTx.Types.MsgSubmitProposal]: utils_1.generateAminoType(SubmitProposalMsg, proposalAminoProcess),
|
|
407
|
+
[CarbonTx.Types.MsgDeposit]: utils_1.generateAminoType(MsgDeposit),
|
|
408
|
+
[CarbonTx.Types.MsgVote]: utils_1.generateAminoType(MsgVote),
|
|
409
409
|
};
|
|
410
410
|
exports.default = GovAmino;
|
|
@@ -55,6 +55,6 @@ const pruneTransferProcess = {
|
|
|
55
55
|
},
|
|
56
56
|
};
|
|
57
57
|
const IbcAmino = {
|
|
58
|
-
[CarbonTx.Types.MsgTransfer]:
|
|
58
|
+
[CarbonTx.Types.MsgTransfer]: utils_1.generateAminoType(MsgTransfer, pruneTransferProcess),
|
|
59
59
|
};
|
|
60
60
|
exports.default = IbcAmino;
|
|
@@ -31,6 +31,6 @@ const MsgSetLeverage = {
|
|
|
31
31
|
},
|
|
32
32
|
};
|
|
33
33
|
const LeverageAmino = {
|
|
34
|
-
[CarbonTx.Types.MsgSetLeverage]:
|
|
34
|
+
[CarbonTx.Types.MsgSetLeverage]: utils_1.generateAminoType(MsgSetLeverage),
|
|
35
35
|
};
|
|
36
36
|
exports.default = LeverageAmino;
|
|
@@ -95,12 +95,12 @@ const commitTokensProcess = {
|
|
|
95
95
|
},
|
|
96
96
|
};
|
|
97
97
|
const LiquidityPoolAmino = {
|
|
98
|
-
[CarbonTx.Types.MsgCreatePool]:
|
|
99
|
-
[CarbonTx.Types.MsgCreatePoolWithLiquidity]:
|
|
100
|
-
[CarbonTx.Types.MsgAddLiquidity]:
|
|
101
|
-
[CarbonTx.Types.MsgRemoveLiquidity]:
|
|
102
|
-
[CarbonTx.Types.MsgStakePoolToken]:
|
|
103
|
-
[CarbonTx.Types.MsgUnstakePoolToken]:
|
|
104
|
-
[CarbonTx.Types.MsgClaimPoolRewards]:
|
|
98
|
+
[CarbonTx.Types.MsgCreatePool]: utils_1.generateAminoType(MsgCreatePool),
|
|
99
|
+
[CarbonTx.Types.MsgCreatePoolWithLiquidity]: utils_1.generateAminoType(MsgCreatePoolWithLiquidity),
|
|
100
|
+
[CarbonTx.Types.MsgAddLiquidity]: utils_1.generateAminoType(MsgAddLiquidity),
|
|
101
|
+
[CarbonTx.Types.MsgRemoveLiquidity]: utils_1.generateAminoType(MsgRemoveLiquidity),
|
|
102
|
+
[CarbonTx.Types.MsgStakePoolToken]: utils_1.generateAminoType(MsgStakePoolToken, commitTokensProcess),
|
|
103
|
+
[CarbonTx.Types.MsgUnstakePoolToken]: utils_1.generateAminoType(MsgUnstakePoolToken),
|
|
104
|
+
[CarbonTx.Types.MsgClaimPoolRewards]: utils_1.generateAminoType(MsgClaimPoolRewards),
|
|
105
105
|
};
|
|
106
106
|
exports.default = LiquidityPoolAmino;
|
|
@@ -41,6 +41,6 @@ const MsgUpdateMarket = {
|
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
43
|
const MarketAmino = {
|
|
44
|
-
[CarbonTx.Types.MsgUpdateMarket]:
|
|
44
|
+
[CarbonTx.Types.MsgUpdateMarket]: utils_1.generateAminoType(MsgUpdateMarket),
|
|
45
45
|
};
|
|
46
46
|
exports.default = MarketAmino;
|
|
@@ -80,9 +80,9 @@ const createOrderProcess = {
|
|
|
80
80
|
},
|
|
81
81
|
};
|
|
82
82
|
const OrderAmino = {
|
|
83
|
-
[CarbonTx.Types.MsgCreateOrder]:
|
|
84
|
-
[CarbonTx.Types.MsgCancelOrder]:
|
|
85
|
-
[CarbonTx.Types.MsgEditOrder]:
|
|
86
|
-
[CarbonTx.Types.MsgCancelAll]:
|
|
83
|
+
[CarbonTx.Types.MsgCreateOrder]: utils_1.generateAminoType(MsgCreateOrder, createOrderProcess),
|
|
84
|
+
[CarbonTx.Types.MsgCancelOrder]: utils_1.generateAminoType(MsgCancelOrder),
|
|
85
|
+
[CarbonTx.Types.MsgEditOrder]: utils_1.generateAminoType(MsgEditOrder),
|
|
86
|
+
[CarbonTx.Types.MsgCancelAll]: utils_1.generateAminoType(MsgCancelAll),
|
|
87
87
|
};
|
|
88
88
|
exports.default = OrderAmino;
|
|
@@ -29,6 +29,6 @@ const MsgSetMargin = {
|
|
|
29
29
|
valueMap: {},
|
|
30
30
|
};
|
|
31
31
|
const PositionAmino = {
|
|
32
|
-
[CarbonTx.Types.MsgSetMargin]:
|
|
32
|
+
[CarbonTx.Types.MsgSetMargin]: utils_1.generateAminoType(MsgSetMargin),
|
|
33
33
|
};
|
|
34
34
|
exports.default = PositionAmino;
|
|
@@ -45,6 +45,6 @@ const updateProfileProcess = {
|
|
|
45
45
|
},
|
|
46
46
|
};
|
|
47
47
|
const ProfileAmino = {
|
|
48
|
-
[CarbonTx.Types.MsgUpdateProfile]:
|
|
48
|
+
[CarbonTx.Types.MsgUpdateProfile]: utils_1.generateAminoType(MsgUpdateProfile, updateProfileProcess),
|
|
49
49
|
};
|
|
50
50
|
exports.default = ProfileAmino;
|
|
@@ -44,9 +44,9 @@ const MsgWithdrawDelegatorReward = {
|
|
|
44
44
|
valueMap: {},
|
|
45
45
|
};
|
|
46
46
|
const StakingAmino = {
|
|
47
|
-
[CarbonTx.Types.MsgDelegate]:
|
|
48
|
-
[CarbonTx.Types.MsgUndelegate]:
|
|
49
|
-
[CarbonTx.Types.MsgBeginRedelegate]:
|
|
50
|
-
[CarbonTx.Types.MsgWithdrawDelegatorReward]:
|
|
47
|
+
[CarbonTx.Types.MsgDelegate]: utils_1.generateAminoType(MsgDelegate),
|
|
48
|
+
[CarbonTx.Types.MsgUndelegate]: utils_1.generateAminoType(MsgUndelegate),
|
|
49
|
+
[CarbonTx.Types.MsgBeginRedelegate]: utils_1.generateAminoType(MsgBeginRedelegate),
|
|
50
|
+
[CarbonTx.Types.MsgWithdrawDelegatorReward]: utils_1.generateAminoType(MsgWithdrawDelegatorReward),
|
|
51
51
|
};
|
|
52
52
|
exports.default = StakingAmino;
|
|
@@ -39,8 +39,8 @@ const MsgRemoveSubAccount = {
|
|
|
39
39
|
valueMap: {},
|
|
40
40
|
};
|
|
41
41
|
const SubAccountAmino = {
|
|
42
|
-
[CarbonTx.Types.MsgCreateSubAccount]:
|
|
43
|
-
[CarbonTx.Types.MsgActivateSubAccount]:
|
|
44
|
-
[CarbonTx.Types.MsgRemoveSubAccount]:
|
|
42
|
+
[CarbonTx.Types.MsgCreateSubAccount]: utils_1.generateAminoType(MsgCreateSubAccount),
|
|
43
|
+
[CarbonTx.Types.MsgActivateSubAccount]: utils_1.generateAminoType(MsgActivateSubAccount),
|
|
44
|
+
[CarbonTx.Types.MsgRemoveSubAccount]: utils_1.generateAminoType(MsgRemoveSubAccount),
|
|
45
45
|
};
|
|
46
46
|
exports.default = SubAccountAmino;
|
|
@@ -48,23 +48,23 @@ const mapEachIndiv = (mapItem, valueKey, toAmino = false) => {
|
|
|
48
48
|
if (typeof keyMap !== "object") {
|
|
49
49
|
// Check if this is a Long/BigNumber/Buffer/Date/Duration obj or a non-object/array
|
|
50
50
|
if (typeCheck(mapItem[key]) || typeof mapItem[key] !== "object") {
|
|
51
|
-
directMap[altKey] =
|
|
51
|
+
directMap[altKey] = exports.paramConverter(mapItem[key], keyMap, toAmino);
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
if (mapItem[key].length && typeof mapItem[key] === "object") {
|
|
56
56
|
// If value is an array of objects, iterate through objects and call mapToObj function
|
|
57
57
|
directMap[altKey] = mapItem[key].map((newMap) => {
|
|
58
|
-
return
|
|
58
|
+
return exports.mapEachIndiv(newMap, valueKey, toAmino);
|
|
59
59
|
});
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
63
|
if (util_1.TypeUtils.isDurationType(mapItem[key])) {
|
|
64
|
-
directMap[altKey] =
|
|
64
|
+
directMap[altKey] = exports.paramConverter(mapItem[key], keyMap, toAmino);
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
directMap[altKey] =
|
|
67
|
+
directMap[altKey] = exports.mapEachIndiv(mapItem[key], keyMap, toAmino);
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
return directMap;
|
|
@@ -147,18 +147,18 @@ const generateAminoType = (amino, aminoProcess = {}) => {
|
|
|
147
147
|
if (!newInput[key])
|
|
148
148
|
return;
|
|
149
149
|
if (typeCheck(newInput[key])) {
|
|
150
|
-
aminoObj[snakeKey] =
|
|
150
|
+
aminoObj[snakeKey] = exports.paramConverter(newInput[key], newAminoMap[key], true);
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
153
153
|
if (typeof newInput[key] !== "object" && typeof newAminoMap[key] !== "object") {
|
|
154
|
-
aminoObj[snakeKey] =
|
|
154
|
+
aminoObj[snakeKey] = exports.paramConverter(newInput[key], newAminoMap[key], true);
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
157
|
if (((_a = newInput[key]) === null || _a === void 0 ? void 0 : _a.length) && typeof newInput[key] === "object") {
|
|
158
|
-
aminoObj[snakeKey] = newInput[key].map((newItem) =>
|
|
158
|
+
aminoObj[snakeKey] = newInput[key].map((newItem) => exports.mapEachIndiv(newItem, newAminoMap[key], true));
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
|
-
aminoObj[snakeKey] =
|
|
161
|
+
aminoObj[snakeKey] = exports.mapEachIndiv(newInput[key], newAminoMap[key], true);
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
return aminoObj;
|
|
@@ -172,14 +172,14 @@ const generateAminoType = (amino, aminoProcess = {}) => {
|
|
|
172
172
|
var _a;
|
|
173
173
|
const camelKey = util_1.TypeUtils.snakeToCamel(key);
|
|
174
174
|
if (typeof newInput[key] !== "object" && typeof newAminoMap[key] !== "object") {
|
|
175
|
-
aminoObj[camelKey] =
|
|
175
|
+
aminoObj[camelKey] = exports.paramConverter(newInput[key], newAminoMap[camelKey], false);
|
|
176
176
|
}
|
|
177
177
|
else {
|
|
178
178
|
if (((_a = newInput[key]) === null || _a === void 0 ? void 0 : _a.length) && typeof newInput[key] === "object") {
|
|
179
|
-
aminoObj[camelKey] = newInput[key].map((newItem) =>
|
|
179
|
+
aminoObj[camelKey] = newInput[key].map((newItem) => exports.mapEachIndiv(newItem, newAminoMap[camelKey], false));
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
|
-
aminoObj[camelKey] =
|
|
182
|
+
aminoObj[camelKey] = exports.mapEachIndiv(newInput[key], newAminoMap[camelKey], false);
|
|
183
183
|
}
|
|
184
184
|
});
|
|
185
185
|
return aminoObj;
|
|
@@ -149,7 +149,7 @@ class CosmosLedger {
|
|
|
149
149
|
const response = yield this.cosmosApp.getVersion();
|
|
150
150
|
this.checkLedgerErrors(response);
|
|
151
151
|
const { major, minor, patch, test_mode } = response;
|
|
152
|
-
|
|
152
|
+
exports.checkAppMode(this.testModeAllowed, test_mode);
|
|
153
153
|
const version = versionString({ major, minor, patch });
|
|
154
154
|
return version;
|
|
155
155
|
});
|
|
@@ -218,7 +218,7 @@ class CosmosLedger {
|
|
|
218
218
|
const response = yield this.cosmosApp.sign(this.hdPath, signMessage);
|
|
219
219
|
this.checkLedgerErrors(response);
|
|
220
220
|
// we have to parse the signature from Ledger as it's in DER format
|
|
221
|
-
const parsedSignature =
|
|
221
|
+
const parsedSignature = secp256k1_1.signatureImport(response.signature);
|
|
222
222
|
return parsedSignature;
|
|
223
223
|
});
|
|
224
224
|
}
|
|
@@ -157,7 +157,7 @@ class MetaMask {
|
|
|
157
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
158
|
const chainIdHex = yield ((_a = this.getAPI()) === null || _a === void 0 ? void 0 : _a.request({ method: 'eth_chainId' }));
|
|
159
159
|
const chainId = !!chainIdHex ? parseInt(chainIdHex, 16) : undefined;
|
|
160
|
-
const blockchain =
|
|
160
|
+
const blockchain = blockchain_1.getBlockchainFromChain(chainId);
|
|
161
161
|
this.blockchain = blockchain;
|
|
162
162
|
return { chainId, blockchain };
|
|
163
163
|
});
|
|
@@ -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(
|
|
63
|
+
const msg = JSON.stringify(generic_1.sortObject(doc));
|
|
64
64
|
const signBytes = yield dapi.signMessage(msg);
|
|
65
|
-
const signature =
|
|
65
|
+
const signature = amino_1.encodeSecp256k1Signature(pubKey, signBytes);
|
|
66
66
|
return {
|
|
67
67
|
signed: doc,
|
|
68
68
|
signature,
|
package/lib/util/address.js
CHANGED
|
@@ -100,13 +100,13 @@ const randomMnemonic = () => {
|
|
|
100
100
|
};
|
|
101
101
|
exports.randomMnemonic = randomMnemonic;
|
|
102
102
|
const wifEncodePrivateKey = (privateKey, iter = 128) => {
|
|
103
|
-
const privateKeyBuf =
|
|
103
|
+
const privateKeyBuf = exports.stringOrBufferToBuffer(privateKey);
|
|
104
104
|
return wif.encode(iter, privateKeyBuf, true);
|
|
105
105
|
};
|
|
106
106
|
exports.wifEncodePrivateKey = wifEncodePrivateKey;
|
|
107
107
|
exports.SWTHAddress = {
|
|
108
108
|
newMnemonic: () => {
|
|
109
|
-
return
|
|
109
|
+
return exports.randomMnemonic();
|
|
110
110
|
},
|
|
111
111
|
coinType: () => {
|
|
112
112
|
return SWTH_COIN_TYPE;
|
|
@@ -116,10 +116,10 @@ exports.SWTHAddress = {
|
|
|
116
116
|
return new BIP44Path(BIP44_PURPOSE, coinType).update(index, change, account).toArray();
|
|
117
117
|
},
|
|
118
118
|
publicKeyToScriptHash: (publicKey) => {
|
|
119
|
-
const pubKeyBuffer =
|
|
119
|
+
const pubKeyBuffer = exports.stringOrBufferToBuffer(publicKey);
|
|
120
120
|
const sha256Hash = ethers_1.ethers.utils.sha256(pubKeyBuffer);
|
|
121
121
|
const ripemdHash = ethers_1.ethers.utils.ripemd160(sha256Hash);
|
|
122
|
-
return
|
|
122
|
+
return generic_1.stripHexPrefix(ripemdHash);
|
|
123
123
|
},
|
|
124
124
|
publicKeyToAddress: (publicKey, opts) => {
|
|
125
125
|
const scriptHash = exports.SWTHAddress.publicKeyToScriptHash(publicKey);
|
|
@@ -141,7 +141,7 @@ exports.SWTHAddress = {
|
|
|
141
141
|
return privateKey;
|
|
142
142
|
},
|
|
143
143
|
privateToPublicKey: (privateKey) => {
|
|
144
|
-
const privateKeyBuff =
|
|
144
|
+
const privateKeyBuff = exports.stringOrBufferToBuffer(privateKey);
|
|
145
145
|
const publicKeyUint8Array = secp256k1.publicKeyCreate(privateKeyBuff, true);
|
|
146
146
|
const publicKey = Buffer.from(publicKeyUint8Array);
|
|
147
147
|
return publicKey;
|
|
@@ -152,7 +152,7 @@ exports.SWTHAddress = {
|
|
|
152
152
|
return address;
|
|
153
153
|
},
|
|
154
154
|
encode: (hash, opts) => {
|
|
155
|
-
const hashBuff =
|
|
155
|
+
const hashBuff = exports.stringOrBufferToBuffer(hash, 'hex');
|
|
156
156
|
const words = bech32.toWords(hashBuff.slice(0, 20));
|
|
157
157
|
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);
|
|
158
158
|
const address = bech32.encode(addressPrefix, words);
|
|
@@ -211,7 +211,7 @@ exports.NEOAddress = {
|
|
|
211
211
|
]);
|
|
212
212
|
const sha256Hash = ethers_1.ethers.utils.sha256(addressScript);
|
|
213
213
|
const ripemdHash = ethers_1.ethers.utils.ripemd160(sha256Hash);
|
|
214
|
-
return
|
|
214
|
+
return generic_1.stripHexPrefix(ripemdHash);
|
|
215
215
|
},
|
|
216
216
|
publicKeyToAddress: (publicKey) => {
|
|
217
217
|
const addressScript = exports.NEOAddress.publicKeyToScriptHash(publicKey);
|
|
@@ -219,7 +219,7 @@ exports.NEOAddress = {
|
|
|
219
219
|
return address;
|
|
220
220
|
},
|
|
221
221
|
encodePublicKey: (unencodedPublicKey) => {
|
|
222
|
-
const unencPubKeyBuf =
|
|
222
|
+
const unencPubKeyBuf = exports.stringOrBufferToBuffer(unencodedPublicKey);
|
|
223
223
|
if (unencPubKeyBuf.length <= 33) {
|
|
224
224
|
// length indicates already encoded
|
|
225
225
|
return unencPubKeyBuf;
|
|
@@ -244,7 +244,7 @@ exports.NEOAddress = {
|
|
|
244
244
|
return privateKey;
|
|
245
245
|
},
|
|
246
246
|
privateToPublicKey: (privateKey) => {
|
|
247
|
-
const privateKeyBuff =
|
|
247
|
+
const privateKeyBuff = exports.stringOrBufferToBuffer(privateKey);
|
|
248
248
|
const publicKeyUint8Array = secp256r1.publicKeyCreate(privateKeyBuff, true);
|
|
249
249
|
return Buffer.from(publicKeyUint8Array);
|
|
250
250
|
},
|
|
@@ -262,7 +262,7 @@ exports.NEOAddress = {
|
|
|
262
262
|
},
|
|
263
263
|
};
|
|
264
264
|
exports.N3Address = Object.assign(Object.assign({}, exports.NEOAddress), { publicKeyToScriptHash: (publicKey) => {
|
|
265
|
-
const publicKeyHex =
|
|
265
|
+
const publicKeyHex = exports.stringOrBufferToBuffer(publicKey).toString("hex");
|
|
266
266
|
return neon_core_next_1.wallet.getScriptHashFromPublicKey(publicKeyHex);
|
|
267
267
|
}, publicKeyToAddress: (publicKey) => {
|
|
268
268
|
const addressScript = exports.N3Address.publicKeyToScriptHash(publicKey);
|
|
@@ -288,11 +288,11 @@ exports.ETHAddress = {
|
|
|
288
288
|
return ethers_1.ethers.utils.keccak256(encodedPublicKey);
|
|
289
289
|
},
|
|
290
290
|
publicKeyToAddress: (publicKey) => {
|
|
291
|
-
const publicKeyBuff =
|
|
291
|
+
const publicKeyBuff = exports.stringOrBufferToBuffer(publicKey);
|
|
292
292
|
return ethers_1.ethers.utils.computeAddress(publicKeyBuff);
|
|
293
293
|
},
|
|
294
294
|
encodePublicKey: (unencodedPublicKey) => {
|
|
295
|
-
const unencodedPublicKeyBuff =
|
|
295
|
+
const unencodedPublicKeyBuff = exports.stringOrBufferToBuffer(unencodedPublicKey);
|
|
296
296
|
const publicKey = ethers_1.ethers.utils.computePublicKey(unencodedPublicKeyBuff, true);
|
|
297
297
|
return Buffer.from(publicKey, "hex");
|
|
298
298
|
},
|
|
@@ -304,7 +304,7 @@ exports.ETHAddress = {
|
|
|
304
304
|
return Buffer.from((_a = wallet.privateKey) === null || _a === void 0 ? void 0 : _a.replace(/^0x/, ""), "hex");
|
|
305
305
|
},
|
|
306
306
|
privateToPublicKey: (privateKey) => {
|
|
307
|
-
const privateKeyBuff =
|
|
307
|
+
const privateKeyBuff = exports.stringOrBufferToBuffer(privateKey);
|
|
308
308
|
return Buffer.from(ethers_1.ethers.utils.computePublicKey(privateKeyBuff).replace(/^0x/, ""), "hex");
|
|
309
309
|
},
|
|
310
310
|
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
|
|
87
|
+
return 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
|
|
96
|
+
return 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
|
|
106
|
+
return 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
|
|
117
|
+
return fetch_1.fetch(url, otherOpts);
|
|
118
118
|
};
|
|
119
119
|
this.apiPrefix = apiPrefix;
|
|
120
120
|
this.apiEndpoints = apiEndpoints;
|
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] =
|
|
25
|
+
result[key] = 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] =
|
|
44
|
+
.forEach((key) => (output[key] = 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
|
|
59
|
+
return exports.toTxHash(crypto_1.sha256(bytes));
|
|
60
60
|
};
|
|
61
61
|
exports.computeTxHash = computeTxHash;
|
|
62
62
|
const toTxHash = (bytes) => {
|
package/lib/util/number.js
CHANGED
|
@@ -18,26 +18,26 @@ const parseBN = (input, defaultValue) => {
|
|
|
18
18
|
};
|
|
19
19
|
exports.parseBN = parseBN;
|
|
20
20
|
const bnOrZero = (input, defaultValue = exports.BN_ZERO) => {
|
|
21
|
-
return
|
|
21
|
+
return exports.parseBN(input, defaultValue);
|
|
22
22
|
};
|
|
23
23
|
exports.bnOrZero = bnOrZero;
|
|
24
24
|
const toHuman = (value, decimals) => {
|
|
25
25
|
if (value === undefined || value === null)
|
|
26
26
|
return undefined;
|
|
27
|
-
const valueBN =
|
|
27
|
+
const valueBN = exports.bnOrZero(value);
|
|
28
28
|
if (!decimals)
|
|
29
29
|
return valueBN; // decimals = 0 or nullish
|
|
30
|
-
const decimalsBN =
|
|
30
|
+
const decimalsBN = exports.bnOrZero(decimals);
|
|
31
31
|
return valueBN.shiftedBy(decimalsBN.negated().toNumber());
|
|
32
32
|
};
|
|
33
33
|
exports.toHuman = toHuman;
|
|
34
34
|
const toUnitless = (value, decimals) => {
|
|
35
35
|
if (value === undefined || value === null)
|
|
36
36
|
return undefined;
|
|
37
|
-
const valueBN =
|
|
37
|
+
const valueBN = exports.bnOrZero(value);
|
|
38
38
|
if (!decimals)
|
|
39
39
|
return valueBN; // decimals = 0 or nullish
|
|
40
|
-
const decimalsBN =
|
|
40
|
+
const decimalsBN = exports.bnOrZero(decimals);
|
|
41
41
|
return valueBN.shiftedBy(decimalsBN.toNumber());
|
|
42
42
|
};
|
|
43
43
|
exports.toUnitless = toUnitless;
|
|
@@ -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(
|
|
109
|
+
const msg = JSON.stringify(generic_1.sortObject(doc));
|
|
110
110
|
const signBytes = yield this.ledger.sign(msg);
|
|
111
|
-
const signature =
|
|
111
|
+
const signature = 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
|
|
90
|
+
return 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 =
|
|
102
|
+
const pubkey = proto_signing_1.encodePubkey(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 =
|
|
112
|
-
const signDoc =
|
|
111
|
+
const authInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey, sequence }], fee.amount, gasLimit);
|
|
112
|
+
const signDoc = 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: [
|
|
117
|
+
signatures: [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 =
|
|
128
|
+
const pubkey = proto_signing_1.encodePubkey(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 =
|
|
143
|
+
const signedAuthInfoBytes = 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: [
|
|
147
|
+
signatures: [encoding_1.fromBase64(signature.signature)],
|
|
148
148
|
});
|
|
149
149
|
});
|
|
150
150
|
}
|