carbon-js-sdk 0.11.21 → 0.11.22
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/codec/Switcheo/carbon/cdp/asset_params.d.ts +11 -0
- package/lib/codec/Switcheo/carbon/cdp/asset_params.js +64 -1
- package/lib/codec/Switcheo/carbon/cdp/export.d.ts +1 -1
- package/lib/codec/Switcheo/carbon/cdp/export.js +5 -4
- package/lib/codec/Switcheo/carbon/cdp/query.d.ts +3 -3
- package/lib/codec/Switcheo/carbon/cdp/query.js +10 -10
- package/lib/codec/Switcheo/carbon/coin/export.d.ts +2 -2
- package/lib/codec/Switcheo/carbon/coin/export.js +2 -6
- package/lib/codec/Switcheo/carbon/coin/query.d.ts +0 -21
- package/lib/codec/Switcheo/carbon/coin/query.js +1 -88
- package/lib/codec/Switcheo/carbon/coin/tx.d.ts +0 -24
- package/lib/codec/Switcheo/carbon/coin/tx.js +1 -125
- package/lib/codec/Switcheo/carbon/subaccount/query.d.ts +1 -0
- package/lib/codec/Switcheo/carbon/subaccount/query.js +14 -1
- package/lib/codec/carbon-models.d.ts +1 -0
- package/lib/codec/carbon-models.js +2 -1
- package/lib/codec/cosmos/ics23/v1/proofs.d.ts +1 -0
- package/lib/codec/index.d.ts +10 -2
- package/lib/codec/index.js +395 -32
- package/lib/modules/cdp.js +26 -21
- package/lib/provider/metamask/MetaMask.d.ts +5 -1
- package/lib/provider/metamask/MetaMask.js +25 -9
- package/lib/provider/rainbowKit/RainbowKitAccount.d.ts +5 -2
- package/lib/provider/rainbowKit/RainbowKitAccount.js +28 -12
- package/lib/util/eip712.d.ts +1 -1
- package/lib/util/eip712.js +2 -2
- package/lib/util/tx.d.ts +10 -2
- package/package.json +1 -1
|
@@ -41,6 +41,7 @@ const build_1 = require("@cosmjs/amino/build");
|
|
|
41
41
|
const ethSignUtils = __importStar(require("eth-sig-util"));
|
|
42
42
|
const util_1 = require("../../util");
|
|
43
43
|
const wallet_1 = require("../../wallet");
|
|
44
|
+
const proto_signing_1 = require("@cosmjs/proto-signing");
|
|
44
45
|
const tx_1 = require("../../codec/cosmos/tx/v1beta1/tx");
|
|
45
46
|
const legacyEIP712_1 = require("../../util/legacyEIP712");
|
|
46
47
|
const index_1 = require("../../index");
|
|
@@ -152,10 +153,20 @@ class MetaMask extends eip6963Provider_1.Eip6963Provider {
|
|
|
152
153
|
gas: (_d = (_c = authInfo.fee) === null || _c === void 0 ? void 0 : _c.gasLimit.toString()) !== null && _d !== void 0 ? _d : "0",
|
|
153
154
|
};
|
|
154
155
|
const aminoMsgs = msgs.map(msg => index_1.AminoTypesMap.toAmino(msg));
|
|
155
|
-
const sig = yield metamask.signEip712(evmHexAddress, doc.accountNumber.toString(), evmChainId, aminoMsgs, fee, txBody.memo, authInfo.signerInfos[0].sequence.toString());
|
|
156
|
+
const { sig, signedDoc } = yield metamask.signEip712(evmHexAddress, doc.accountNumber.toString(), evmChainId, aminoMsgs, fee, txBody.memo, authInfo.signerInfos[0].sequence.toString());
|
|
157
|
+
const signedTxBody = {
|
|
158
|
+
messages: msgs,
|
|
159
|
+
memo: signedDoc.memo,
|
|
160
|
+
};
|
|
161
|
+
const signedTxBodyEncodeObject = {
|
|
162
|
+
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
163
|
+
value: signedTxBody,
|
|
164
|
+
};
|
|
165
|
+
const signedTxBodyBytes = codec_1.registry.encode(signedTxBodyEncodeObject);
|
|
166
|
+
const signDoc = proto_signing_1.makeSignDoc(signedTxBodyBytes, doc.authInfoBytes, signedDoc.chain_id, parseInt(signedDoc.account_number));
|
|
156
167
|
const sigBz = Uint8Array.from(Buffer.from(sig, 'hex'));
|
|
157
168
|
return {
|
|
158
|
-
signed:
|
|
169
|
+
signed: signDoc,
|
|
159
170
|
signature: {
|
|
160
171
|
pub_key: {
|
|
161
172
|
type: ethermint_1.ETH_SECP256K1_TYPE,
|
|
@@ -168,10 +179,10 @@ class MetaMask extends eip6963Provider_1.Eip6963Provider {
|
|
|
168
179
|
});
|
|
169
180
|
const signAmino = (_, doc) => __awaiter(this, void 0, void 0, function* () {
|
|
170
181
|
const { account_number, msgs, fee, memo, sequence } = doc;
|
|
171
|
-
const sig = yield metamask.signEip712(evmHexAddress, account_number, evmChainId, msgs, fee, memo, sequence);
|
|
182
|
+
const { sig, signedDoc } = yield metamask.signEip712(evmHexAddress, account_number, evmChainId, msgs, fee, memo, sequence);
|
|
172
183
|
const sigBz = Uint8Array.from(Buffer.from(sig, 'hex'));
|
|
173
184
|
return {
|
|
174
|
-
signed:
|
|
185
|
+
signed: signedDoc,
|
|
175
186
|
signature: {
|
|
176
187
|
pub_key: {
|
|
177
188
|
type: ethermint_1.ETH_SECP256K1_TYPE,
|
|
@@ -198,9 +209,9 @@ class MetaMask extends eip6963Provider_1.Eip6963Provider {
|
|
|
198
209
|
// Only MsgMergeAccount will have an Eth address signer, other generic transaction will be cosmos address signer
|
|
199
210
|
// FeePayer here is only used for legacy EIP-712
|
|
200
211
|
const feePayer = index_1.AminoTypesMap.fromAmino(msgs[0]).typeUrl === codec_1.TxTypes.MsgMergeAccount ? util_1.AddressUtils.ETHAddress.publicKeyToBech32Address(Buffer.from(pubKeyBase64, "base64"), addressOptions) : signerAddress;
|
|
201
|
-
const sig = yield metamask.signEip712(evmHexAddress, account_number, chain_id, msgs, fee, memo, sequence, feePayer);
|
|
212
|
+
const { sig, signedDoc } = yield metamask.signEip712(evmHexAddress, account_number, chain_id, msgs, fee, memo, sequence, feePayer);
|
|
202
213
|
return {
|
|
203
|
-
signed:
|
|
214
|
+
signed: signedDoc,
|
|
204
215
|
signature: {
|
|
205
216
|
pub_key: {
|
|
206
217
|
type: ethermint_1.ETH_SECP256K1_TYPE,
|
|
@@ -554,11 +565,15 @@ class MetaMask extends eip6963Provider_1.Eip6963Provider {
|
|
|
554
565
|
}
|
|
555
566
|
signEip712(evmHexAddress, accountNumber, evmChainId, msgs, fee, memo, sequence, feePayer = '') {
|
|
556
567
|
return __awaiter(this, void 0, void 0, function* () {
|
|
557
|
-
yield this.
|
|
568
|
+
const metamaskNetwork = yield this.syncBlockchain();
|
|
569
|
+
const metamaskChainId = metamaskNetwork.chainId ? `carbon_${metamaskNetwork.chainId.toString()}-1` : '';
|
|
558
570
|
const metamaskAPI = yield this.getConnectedAPI();
|
|
571
|
+
if (metamaskChainId !== evmChainId) {
|
|
572
|
+
memo += "|CROSSCHAIN-SIGNING|signed-chain-id:" + metamaskChainId + ";" + "carbon-chain-id:" + evmChainId;
|
|
573
|
+
}
|
|
559
574
|
const stdSignDoc = build_1.makeSignDoc(msgs, fee, evmChainId, memo, accountNumber, sequence);
|
|
560
|
-
const eip712Tx = this.legacyEip712SignMode ? legacyEIP712_1.legacyConstructEIP712Tx(Object.assign(Object.assign({}, stdSignDoc), { fee: Object.assign(Object.assign({}, fee), { feePayer }) })) : eip712_1.constructEIP712Tx(stdSignDoc);
|
|
561
|
-
|
|
575
|
+
const eip712Tx = this.legacyEip712SignMode ? legacyEIP712_1.legacyConstructEIP712Tx(Object.assign(Object.assign({}, stdSignDoc), { fee: Object.assign(Object.assign({}, fee), { feePayer }) })) : eip712_1.constructEIP712Tx(stdSignDoc, metamaskChainId);
|
|
576
|
+
const sig = yield provider_1.signTransactionWrapper(() => __awaiter(this, void 0, void 0, function* () {
|
|
562
577
|
const signature = (yield metamaskAPI.request({
|
|
563
578
|
method: 'eth_signTypedData_v4',
|
|
564
579
|
params: [
|
|
@@ -568,6 +583,7 @@ class MetaMask extends eip6963Provider_1.Eip6963Provider {
|
|
|
568
583
|
}));
|
|
569
584
|
return signature.split('0x')[1];
|
|
570
585
|
}));
|
|
586
|
+
return { sig, signedDoc: stdSignDoc };
|
|
571
587
|
});
|
|
572
588
|
}
|
|
573
589
|
sendEvmTransaction(req, metamaskAPI) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CarbonSDK, SupportedEip6963Provider } from "../../index";
|
|
1
|
+
import { CarbonSDK, CarbonTx, SupportedEip6963Provider } from "../../index";
|
|
2
2
|
import { CarbonSigner } from "../../wallet";
|
|
3
3
|
import { ethers } from "ethers";
|
|
4
4
|
import { StdFee } from "@cosmjs/stargate";
|
|
@@ -30,7 +30,10 @@ declare class RainbowKitAccount extends Eip6963Provider {
|
|
|
30
30
|
verifyNetworkAndConnectedAccount(evmHexAddress: string, evmChainId: string): Promise<void>;
|
|
31
31
|
verifyConnectedAccount(address: string): Promise<void>;
|
|
32
32
|
verifyNetwork(evmChainId: string): Promise<void>;
|
|
33
|
-
signEip712(evmHexAddress: string, accountNumber: string, evmChainId: string, msgs: readonly AminoMsg[], fee: StdFee, memo: string, sequence: string, feePayer?: string): Promise<
|
|
33
|
+
signEip712(evmHexAddress: string, accountNumber: string, evmChainId: string, msgs: readonly AminoMsg[], fee: StdFee, memo: string, sequence: string, feePayer?: string): Promise<{
|
|
34
|
+
sig: string;
|
|
35
|
+
signedDoc: CarbonTx.StdSignDoc;
|
|
36
|
+
}>;
|
|
34
37
|
personalSign(address: string, message: string): Promise<string>;
|
|
35
38
|
sendEvmTransaction(req: ethers.providers.TransactionRequest): Promise<string>;
|
|
36
39
|
}
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
const index_1 = require("../../index");
|
|
13
13
|
const ethermint_1 = require("../../util/ethermint");
|
|
14
14
|
const wallet_1 = require("../../wallet");
|
|
15
|
+
const proto_signing_1 = require("@cosmjs/proto-signing");
|
|
15
16
|
const ethers_1 = require("ethers");
|
|
16
17
|
const error_1 = require("../metamask/error");
|
|
17
18
|
const tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
@@ -51,10 +52,20 @@ class RainbowKitAccount extends eip6963Provider_1.Eip6963Provider {
|
|
|
51
52
|
gas: (_d = (_c = authInfo.fee) === null || _c === void 0 ? void 0 : _c.gasLimit.toString()) !== null && _d !== void 0 ? _d : "0",
|
|
52
53
|
};
|
|
53
54
|
const aminoMsgs = msgs.map(msg => index_1.AminoTypesMap.toAmino(msg));
|
|
54
|
-
const sig = yield rainbowKit.signEip712(evmHexAddress, doc.accountNumber.toString(), evmChainId, aminoMsgs, fee, txBody.memo, authInfo.signerInfos[0].sequence.toString());
|
|
55
|
+
const { sig, signedDoc } = yield rainbowKit.signEip712(evmHexAddress, doc.accountNumber.toString(), evmChainId, aminoMsgs, fee, txBody.memo, authInfo.signerInfos[0].sequence.toString());
|
|
56
|
+
const signedTxBody = {
|
|
57
|
+
messages: msgs,
|
|
58
|
+
memo: signedDoc.memo,
|
|
59
|
+
};
|
|
60
|
+
const signedTxBodyEncodeObject = {
|
|
61
|
+
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
62
|
+
value: signedTxBody,
|
|
63
|
+
};
|
|
64
|
+
const signedTxBodyBytes = codec_1.registry.encode(signedTxBodyEncodeObject);
|
|
65
|
+
const signDoc = proto_signing_1.makeSignDoc(signedTxBodyBytes, doc.authInfoBytes, signedDoc.chain_id, parseInt(signedDoc.account_number));
|
|
55
66
|
const sigBz = Uint8Array.from(Buffer.from(sig, 'hex'));
|
|
56
67
|
return {
|
|
57
|
-
signed:
|
|
68
|
+
signed: signDoc,
|
|
58
69
|
signature: {
|
|
59
70
|
pub_key: {
|
|
60
71
|
type: ethermint_1.ETH_SECP256K1_TYPE,
|
|
@@ -67,10 +78,10 @@ class RainbowKitAccount extends eip6963Provider_1.Eip6963Provider {
|
|
|
67
78
|
});
|
|
68
79
|
const signAmino = (_, doc) => __awaiter(this, void 0, void 0, function* () {
|
|
69
80
|
const { account_number, msgs, fee, memo, sequence } = doc;
|
|
70
|
-
const sig = yield rainbowKit.signEip712(evmHexAddress, account_number, evmChainId, msgs, fee, memo, sequence);
|
|
81
|
+
const { sig, signedDoc } = yield rainbowKit.signEip712(evmHexAddress, account_number, evmChainId, msgs, fee, memo, sequence);
|
|
71
82
|
const sigBz = Uint8Array.from(Buffer.from(sig, 'hex'));
|
|
72
83
|
return {
|
|
73
|
-
signed:
|
|
84
|
+
signed: signedDoc,
|
|
74
85
|
signature: {
|
|
75
86
|
pub_key: {
|
|
76
87
|
type: ethermint_1.ETH_SECP256K1_TYPE,
|
|
@@ -86,9 +97,9 @@ class RainbowKitAccount extends eip6963Provider_1.Eip6963Provider {
|
|
|
86
97
|
// Only MsgMergeAccount will have an Eth address signer, other generic transaction will be cosmos address signer
|
|
87
98
|
// FeePayer here is only used for legacy EIP-712
|
|
88
99
|
const feePayer = index_1.AminoTypesMap.fromAmino(msgs[0]).typeUrl === codec_1.TxTypes.MsgMergeAccount ? index_1.AddressUtils.ETHAddress.publicKeyToBech32Address(Buffer.from(pubKeyBase64, "base64"), addressOptions) : signerAddress;
|
|
89
|
-
const sig = yield rainbowKit.signEip712(evmHexAddress, account_number, chain_id, msgs, fee, memo, sequence, feePayer);
|
|
100
|
+
const { sig, signedDoc } = yield rainbowKit.signEip712(evmHexAddress, account_number, chain_id, msgs, fee, memo, sequence, feePayer);
|
|
90
101
|
return {
|
|
91
|
-
signed:
|
|
102
|
+
signed: signedDoc,
|
|
92
103
|
signature: {
|
|
93
104
|
pub_key: {
|
|
94
105
|
type: ethermint_1.ETH_SECP256K1_TYPE,
|
|
@@ -290,20 +301,25 @@ class RainbowKitAccount extends eip6963Provider_1.Eip6963Provider {
|
|
|
290
301
|
}
|
|
291
302
|
signEip712(evmHexAddress, accountNumber, evmChainId, msgs, fee, memo, sequence, feePayer = '') {
|
|
292
303
|
return __awaiter(this, void 0, void 0, function* () {
|
|
293
|
-
yield this.
|
|
304
|
+
const { chainId } = yield this.syncBlockchain();
|
|
305
|
+
const walletChainId = chainId ? `carbon_${chainId.toString()}-1` : '';
|
|
306
|
+
const api = this.getApi();
|
|
307
|
+
if (walletChainId !== evmChainId) {
|
|
308
|
+
memo += "|CROSSCHAIN-SIGNING|signed-chain-id:" + walletChainId + ";" + "carbon-chain-id:" + evmChainId;
|
|
309
|
+
}
|
|
294
310
|
const stdSignDoc = amino_1.makeSignDoc(msgs, fee, evmChainId, memo, accountNumber, sequence);
|
|
295
|
-
const eip712Tx = this.legacyEip712SignMode ? legacyEIP712_1.legacyConstructEIP712Tx(Object.assign(Object.assign({}, stdSignDoc), { fee: Object.assign(Object.assign({}, fee), { feePayer }) })) : eip712_1.constructEIP712Tx(stdSignDoc);
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
const signature = yield ethereum.request({
|
|
311
|
+
const eip712Tx = this.legacyEip712SignMode ? legacyEIP712_1.legacyConstructEIP712Tx(Object.assign(Object.assign({}, stdSignDoc), { fee: Object.assign(Object.assign({}, fee), { feePayer }) })) : eip712_1.constructEIP712Tx(stdSignDoc, walletChainId);
|
|
312
|
+
const sig = yield provider_1.signTransactionWrapper(() => __awaiter(this, void 0, void 0, function* () {
|
|
313
|
+
const signature = (yield api.request({
|
|
299
314
|
method: 'eth_signTypedData_v4',
|
|
300
315
|
params: [
|
|
301
316
|
evmHexAddress,
|
|
302
317
|
JSON.stringify(eip712Tx),
|
|
303
318
|
],
|
|
304
|
-
});
|
|
319
|
+
}));
|
|
305
320
|
return signature.split('0x')[1];
|
|
306
321
|
}));
|
|
322
|
+
return { sig, signedDoc: stdSignDoc };
|
|
307
323
|
});
|
|
308
324
|
}
|
|
309
325
|
personalSign(address, message) {
|
package/lib/util/eip712.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export interface EIP712Tx {
|
|
|
7
7
|
readonly domain: TypedDataDomain;
|
|
8
8
|
readonly message: any;
|
|
9
9
|
}
|
|
10
|
-
export declare function constructEIP712Tx(doc: CarbonTx.StdSignDoc): EIP712Tx;
|
|
10
|
+
export declare function constructEIP712Tx(doc: CarbonTx.StdSignDoc, chainId?: string): EIP712Tx;
|
package/lib/util/eip712.js
CHANGED
|
@@ -178,12 +178,12 @@ function isNonZeroField(fieldValue) {
|
|
|
178
178
|
}
|
|
179
179
|
return fieldValue;
|
|
180
180
|
}
|
|
181
|
-
function constructEIP712Tx(doc) {
|
|
181
|
+
function constructEIP712Tx(doc, chainId) {
|
|
182
182
|
const { account_number, chain_id, fee, memo, sequence } = doc;
|
|
183
183
|
const eip712Tx = {
|
|
184
184
|
types: getTypes(doc.msgs),
|
|
185
185
|
primaryType: "Tx",
|
|
186
|
-
domain: Object.assign(Object.assign({}, eip712_1.DEFAULT_CARBON_DOMAIN_FIELDS), { chainId: ethermint_1.parseChainId(
|
|
186
|
+
domain: Object.assign(Object.assign({}, eip712_1.DEFAULT_CARBON_DOMAIN_FIELDS), { chainId: ethermint_1.parseChainId(chainId || chain_id) }),
|
|
187
187
|
message: Object.assign({ account_number, chain_id, fee, memo, sequence }, convertMsgs(doc.msgs)),
|
|
188
188
|
};
|
|
189
189
|
return eip712Tx;
|
package/lib/util/tx.d.ts
CHANGED
|
@@ -263,6 +263,16 @@ export declare const Types: {
|
|
|
263
263
|
MsgDeployOracleContractResponse: string;
|
|
264
264
|
MsgCreateResult: string;
|
|
265
265
|
MsgCreateResultResponse: string;
|
|
266
|
+
MsgCreateRfq: string;
|
|
267
|
+
MsgCreateRfqResponse: string;
|
|
268
|
+
MsgCancelRfq: string;
|
|
269
|
+
MsgCancelRfqResponse: string;
|
|
270
|
+
MsgCreateQuote: string;
|
|
271
|
+
MsgCreateQuoteResponse: string;
|
|
272
|
+
MsgAcceptQuote: string;
|
|
273
|
+
MsgAcceptQuoteResponse: string;
|
|
274
|
+
MsgOtcUpdateParams: string;
|
|
275
|
+
MsgOtcUpdateParamsResponse: string;
|
|
266
276
|
MsgDeactivateContract: string;
|
|
267
277
|
MsgDeactivateContractResponse: string;
|
|
268
278
|
MsgActivateContract: string;
|
|
@@ -292,8 +302,6 @@ export declare const Types: {
|
|
|
292
302
|
MsgLinkTokenResponse: string;
|
|
293
303
|
MsgWithdraw: string;
|
|
294
304
|
MsgWithdrawResponse: string;
|
|
295
|
-
MsgAdminWithdraw: string;
|
|
296
|
-
MsgAdminWithdrawResponse: string;
|
|
297
305
|
MsgAuthorizeBridge: string;
|
|
298
306
|
MsgAuthorizeBridgeResponse: string;
|
|
299
307
|
MsgDeauthorizeBridge: string;
|