example-js-sdk 0.0.5 → 0.0.7
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/README.md +134 -52
- package/lib/OrbixSDK.d.ts +145 -0
- package/lib/{CarbonSDK.js → OrbixSDK.js} +52 -52
- package/lib/clients/ETHClient.d.ts +10 -10
- package/lib/clients/ETHClient.js +4 -4
- package/lib/clients/{CarbonQueryClient.d.ts → OrbixQueryClient.d.ts} +4 -4
- package/lib/clients/{CarbonQueryClient.js → OrbixQueryClient.js} +2 -2
- package/lib/clients/TokenClient.d.ts +26 -26
- package/lib/clients/TokenClient.js +12 -12
- package/lib/clients/index.d.ts +1 -1
- package/lib/clients/index.js +3 -3
- package/lib/codec/index.d.ts +1 -1
- package/lib/codec/index.js +253 -253
- package/lib/constant/eip712.d.ts +1 -1
- package/lib/constant/eip712.js +3 -3
- package/lib/constant/generic.d.ts +1 -1
- package/lib/constant/generic.js +3 -4
- package/lib/constant/ibc.d.ts +0 -1
- package/lib/constant/ibc.js +0 -35
- package/lib/constant/network.d.ts +7 -7
- package/lib/constant/network.js +48 -403
- package/lib/constant/node.js +2 -74
- package/lib/constant/token.js +6 -6
- package/lib/constant/web3Config.d.ts +5 -5
- package/lib/constant/web3Config.js +20 -24
- package/lib/index.d.ts +3 -3
- package/lib/index.js +7 -7
- package/lib/insights/balance.d.ts +2 -2
- package/lib/modules/admin.d.ts +23 -23
- package/lib/modules/admin.js +43 -43
- package/lib/modules/alliance.d.ts +6 -6
- package/lib/modules/alliance.js +5 -5
- package/lib/modules/bank.d.ts +2 -2
- package/lib/modules/bank.js +1 -1
- package/lib/modules/base.d.ts +4 -4
- package/lib/modules/bridge.d.ts +3 -3
- package/lib/modules/bridge.js +5 -5
- package/lib/modules/broker.d.ts +3 -3
- package/lib/modules/broker.js +2 -2
- package/lib/modules/coin.d.ts +8 -8
- package/lib/modules/coin.js +7 -7
- package/lib/modules/evm.d.ts +2 -2
- package/lib/modules/evm.js +1 -1
- package/lib/modules/evmmerge.d.ts +2 -2
- package/lib/modules/evmmerge.js +3 -3
- package/lib/modules/gov.d.ts +4 -4
- package/lib/modules/gov.js +3 -3
- package/lib/modules/grant.d.ts +4 -4
- package/lib/modules/grant.js +6 -6
- package/lib/modules/ibc.d.ts +3 -3
- package/lib/modules/ibc.js +2 -2
- package/lib/modules/leverage.d.ts +3 -3
- package/lib/modules/leverage.js +2 -2
- package/lib/modules/market.d.ts +15 -15
- package/lib/modules/market.js +7 -7
- package/lib/modules/order.d.ts +8 -8
- package/lib/modules/order.js +7 -7
- package/lib/modules/perpspool.d.ts +14 -14
- package/lib/modules/perpspool.js +23 -23
- package/lib/modules/position.d.ts +3 -3
- package/lib/modules/position.js +2 -2
- package/lib/modules/staking.d.ts +6 -6
- package/lib/modules/staking.js +3 -3
- package/lib/modules/subaccount.d.ts +4 -4
- package/lib/modules/subaccount.js +3 -3
- package/lib/provider/amino/types/admin.js +12 -12
- package/lib/provider/amino/types/bank.js +2 -2
- package/lib/provider/amino/types/bridge.js +3 -3
- package/lib/provider/amino/types/broker.js +2 -2
- package/lib/provider/amino/types/coin.js +5 -5
- package/lib/provider/amino/types/evm.js +2 -2
- package/lib/provider/amino/types/evmmerge.js +2 -2
- package/lib/provider/amino/types/feemarket.js +2 -2
- package/lib/provider/amino/types/gov.js +17 -17
- package/lib/provider/amino/types/grant.js +6 -6
- package/lib/provider/amino/types/group.js +4 -4
- package/lib/provider/amino/types/ibc.js +2 -2
- package/lib/provider/amino/types/leverage.js +2 -2
- package/lib/provider/amino/types/market.js +7 -7
- package/lib/provider/amino/types/order.js +5 -5
- package/lib/provider/amino/types/perpspool.js +11 -11
- package/lib/provider/amino/types/position.js +2 -2
- package/lib/provider/amino/types/staking.js +5 -5
- package/lib/provider/amino/types/subaccount.js +4 -4
- package/lib/provider/keplr/KeplrAccount.d.ts +3 -3
- package/lib/provider/keplr/KeplrAccount.js +11 -11
- package/lib/provider/leap/LeapAccount.d.ts +3 -3
- package/lib/provider/leap/LeapAccount.js +10 -10
- package/lib/provider/metamask/MetaMask.d.ts +8 -8
- package/lib/provider/metamask/MetaMask.js +17 -17
- package/lib/provider/rainbowKit/RainbowKitAccount.d.ts +7 -7
- package/lib/provider/rainbowKit/RainbowKitAccount.js +12 -12
- package/lib/provider/sdk/SDKProvider.d.ts +4 -4
- package/lib/util/alliance.js +2 -2
- package/lib/util/blockchain.d.ts +5 -5
- package/lib/util/blockchain.js +11 -11
- package/lib/util/eip712.d.ts +2 -2
- package/lib/util/eip712.js +1 -1
- package/lib/util/ethermint.d.ts +4 -4
- package/lib/util/ethermint.js +1 -1
- package/lib/util/external.d.ts +2 -2
- package/lib/util/gov.js +16 -16
- package/lib/util/ibc.js +2 -2
- package/lib/util/index.d.ts +1 -1
- package/lib/util/index.js +2 -2
- package/lib/util/legacyEIP712.js +1 -1
- package/lib/util/network.d.ts +1 -1
- package/lib/util/network.js +7 -7
- package/lib/util/provider.js +1 -1
- package/lib/util/token.d.ts +1 -1
- package/lib/util/token.js +1 -1
- package/lib/util/tx.d.ts +4 -4
- package/lib/util/tx.js +10 -10
- package/lib/wallet/{CarbonSigner.d.ts → OrbixSigner.d.ts} +19 -19
- package/lib/wallet/{CarbonSigner.js → OrbixSigner.js} +19 -19
- package/lib/wallet/{CarbonSigningClient.d.ts → OrbixSigningClient.d.ts} +3 -3
- package/lib/wallet/{CarbonSigningClient.js → OrbixSigningClient.js} +9 -9
- package/lib/wallet/{CarbonWallet.d.ts → OrbixWallet.d.ts} +38 -38
- package/lib/wallet/{CarbonWallet.js → OrbixWallet.js} +39 -39
- package/lib/wallet/index.d.ts +2 -2
- package/lib/wallet/index.js +2 -2
- package/package.json +2 -2
- package/lib/CarbonSDK.d.ts +0 -145
- /package/lib/codec/{carbon-models.d.ts → orbix-models.d.ts} +0 -0
- /package/lib/codec/{carbon-models.js → orbix-models.js} +0 -0
package/lib/util/tx.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare enum BroadcastTxMode {
|
|
|
17
17
|
BroadcastTxAsync = "async",
|
|
18
18
|
BroadcastTxBlock = "block"
|
|
19
19
|
}
|
|
20
|
-
export interface
|
|
20
|
+
export interface OrbixSignerData extends SignerData {
|
|
21
21
|
timeoutHeight?: number;
|
|
22
22
|
evmChainId?: string;
|
|
23
23
|
}
|
|
@@ -28,7 +28,7 @@ export interface SignTxOpts {
|
|
|
28
28
|
memo?: string;
|
|
29
29
|
sequence?: number;
|
|
30
30
|
accountNumber?: number;
|
|
31
|
-
explicitSignerData?: Partial<
|
|
31
|
+
explicitSignerData?: Partial<OrbixSignerData>;
|
|
32
32
|
processMsgs?: ProcessMsgsCallback;
|
|
33
33
|
triggerMerge?: boolean;
|
|
34
34
|
}
|
|
@@ -58,7 +58,7 @@ export declare enum ErrorType {
|
|
|
58
58
|
BROADCAST_FAIL = "broadcast_fail",
|
|
59
59
|
BLOCK_FAIL = "block_fail"
|
|
60
60
|
}
|
|
61
|
-
export declare class
|
|
61
|
+
export declare class OrbixCustomError extends Error {
|
|
62
62
|
readonly type?: ErrorType;
|
|
63
63
|
readonly data?: any;
|
|
64
64
|
constructor(msg: string, type?: ErrorType, data?: any);
|
|
@@ -553,7 +553,7 @@ export declare const Types: {
|
|
|
553
553
|
};
|
|
554
554
|
export declare const DEFAULT_SIGN_OPTS: SignTxOpts;
|
|
555
555
|
export declare const TxGasCostTypeDefaultKey = "default_fee";
|
|
556
|
-
export declare const TxMinGasPriceTypeDefaultKey = "
|
|
556
|
+
export declare const TxMinGasPriceTypeDefaultKey = "fee";
|
|
557
557
|
export declare const TxGasCostTypeMap: {};
|
|
558
558
|
export declare const useSignDirectForMetamask: (messages: readonly EncodeObject[]) => boolean;
|
|
559
559
|
export declare const isLibMsg: (typeUrl: string) => boolean;
|
package/lib/util/tx.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.isLibMsg = exports.useSignDirectForMetamask = exports.TxGasCostTypeMap = exports.TxMinGasPriceTypeDefaultKey = exports.TxGasCostTypeDefaultKey = exports.DEFAULT_SIGN_OPTS = exports.Types = exports.
|
|
36
|
+
exports.isLibMsg = exports.useSignDirectForMetamask = exports.TxGasCostTypeMap = exports.TxMinGasPriceTypeDefaultKey = exports.TxGasCostTypeDefaultKey = exports.DEFAULT_SIGN_OPTS = exports.Types = exports.OrbixCustomError = exports.ErrorType = exports.BroadcastTxMode = exports.getSender = exports.decode = void 0;
|
|
37
37
|
const codec_1 = require("../codec");
|
|
38
38
|
const CosmosModels = __importStar(require("../codec/cosmos-models"));
|
|
39
39
|
const constant_1 = require("../constant");
|
|
@@ -81,12 +81,12 @@ const decode = (bytes) => {
|
|
|
81
81
|
if (!bytes)
|
|
82
82
|
return bytes;
|
|
83
83
|
const decodedTx = CosmosModels.Tx.Tx.decode((0, bytes_1.toUint8Array)(bytes));
|
|
84
|
-
const
|
|
84
|
+
const orbixTx = { ...decodedTx, body: undefined };
|
|
85
85
|
if (decodedTx.body) {
|
|
86
|
-
|
|
86
|
+
orbixTx.body = { ...decodedTx.body, messages: [] };
|
|
87
87
|
for (const message of decodedTx.body.messages) {
|
|
88
88
|
try {
|
|
89
|
-
|
|
89
|
+
orbixTx.body.messages.push({
|
|
90
90
|
typeUrl: message.typeUrl,
|
|
91
91
|
value: decodeNestedMsg(codec_1.registry.decode(message)),
|
|
92
92
|
});
|
|
@@ -94,14 +94,14 @@ const decode = (bytes) => {
|
|
|
94
94
|
catch (error) {
|
|
95
95
|
console.error(`failed to decode tx message: ${message?.typeUrl}`);
|
|
96
96
|
console.error(error);
|
|
97
|
-
|
|
97
|
+
orbixTx.body.messages.push(message);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
else {
|
|
102
|
-
delete
|
|
102
|
+
delete orbixTx.body;
|
|
103
103
|
}
|
|
104
|
-
return
|
|
104
|
+
return orbixTx;
|
|
105
105
|
};
|
|
106
106
|
exports.decode = decode;
|
|
107
107
|
const getSender = (decodedTx, opts) => {
|
|
@@ -125,21 +125,21 @@ var ErrorType;
|
|
|
125
125
|
ErrorType["BROADCAST_FAIL"] = "broadcast_fail";
|
|
126
126
|
ErrorType["BLOCK_FAIL"] = "block_fail";
|
|
127
127
|
})(ErrorType || (exports.ErrorType = ErrorType = {}));
|
|
128
|
-
class
|
|
128
|
+
class OrbixCustomError extends Error {
|
|
129
129
|
constructor(msg, type, data) {
|
|
130
130
|
super(msg);
|
|
131
131
|
this.type = type;
|
|
132
132
|
this.data = data;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
exports.
|
|
135
|
+
exports.OrbixCustomError = OrbixCustomError;
|
|
136
136
|
exports.Types = codec_1.TxTypes;
|
|
137
137
|
exports.DEFAULT_SIGN_OPTS = {
|
|
138
138
|
fee: constant_1.DEFAULT_FEE,
|
|
139
139
|
memo: "",
|
|
140
140
|
};
|
|
141
141
|
exports.TxGasCostTypeDefaultKey = "default_fee";
|
|
142
|
-
exports.TxMinGasPriceTypeDefaultKey = "
|
|
142
|
+
exports.TxMinGasPriceTypeDefaultKey = "fee";
|
|
143
143
|
exports.TxGasCostTypeMap = {};
|
|
144
144
|
const LibPackages = ['ibc', 'cosmos', 'alliance'];
|
|
145
145
|
const BacklistedMessages = [
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import OrbixSDK from "../OrbixSDK";
|
|
2
2
|
import { SignDoc } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
3
3
|
import { CosmosLedger } from "../provider";
|
|
4
4
|
import { AminoSignResponse, OfflineAminoSigner, Secp256k1Wallet, StdSignDoc } from "@cosmjs/amino";
|
|
5
5
|
import { AccountData, DirectSecp256k1Wallet, DirectSignResponse, OfflineDirectSigner, OfflineSigner } from "@cosmjs/proto-signing";
|
|
6
6
|
import { ethers } from "ethers";
|
|
7
|
-
export declare enum
|
|
7
|
+
export declare enum OrbixSignerTypes {
|
|
8
8
|
Ledger = 0,
|
|
9
9
|
PrivateKey = 1,
|
|
10
10
|
BrowserInjected = 2,
|
|
11
11
|
PublicKey = 3
|
|
12
12
|
}
|
|
13
13
|
export interface EvmSigner {
|
|
14
|
-
readonly sendEvmTransaction: (api:
|
|
14
|
+
readonly sendEvmTransaction: (api: OrbixSDK, req: ethers.providers.TransactionRequest) => Promise<string>;
|
|
15
15
|
}
|
|
16
16
|
export interface ArbitraryMessageSigner {
|
|
17
17
|
readonly signMessage: (address: string, message: string) => Promise<string>;
|
|
@@ -20,22 +20,22 @@ export interface EIP712Signer extends EvmSigner {
|
|
|
20
20
|
legacyEip712SignMode: boolean;
|
|
21
21
|
readonly signLegacyEip712: (signerAddress: string, signDoc: StdSignDoc) => Promise<LegacyEIP712AminoSignResponse>;
|
|
22
22
|
}
|
|
23
|
-
export type
|
|
24
|
-
export type
|
|
25
|
-
export type
|
|
26
|
-
type:
|
|
23
|
+
export type OrbixSigner = DirectOrbixSigner | AminoOrbixSigner | OrbixEIP712Signer;
|
|
24
|
+
export type OrbixEIP712Signer = (DirectOrbixSigner | AminoOrbixSigner) & EIP712Signer & ArbitraryMessageSigner;
|
|
25
|
+
export type DirectOrbixSigner = OfflineDirectSigner & EvmSigner & ArbitraryMessageSigner & {
|
|
26
|
+
type: OrbixSignerTypes;
|
|
27
27
|
};
|
|
28
|
-
export type
|
|
29
|
-
type:
|
|
28
|
+
export type AminoOrbixSigner = OfflineAminoSigner & EvmSigner & ArbitraryMessageSigner & {
|
|
29
|
+
type: OrbixSignerTypes;
|
|
30
30
|
};
|
|
31
31
|
export type LegacyEIP712AminoSignResponse = AminoSignResponse & {
|
|
32
32
|
feePayer: string;
|
|
33
33
|
};
|
|
34
|
-
export declare function
|
|
35
|
-
export declare class
|
|
34
|
+
export declare function isOrbixEIP712Signer(signer: OfflineSigner): boolean;
|
|
35
|
+
export declare class OrbixPrivateKeySigner implements DirectOrbixSigner, AminoOrbixSigner {
|
|
36
36
|
readonly privateKey: Uint8Array;
|
|
37
37
|
readonly prefix: string;
|
|
38
|
-
type:
|
|
38
|
+
type: OrbixSignerTypes;
|
|
39
39
|
wallet?: DirectSecp256k1Wallet;
|
|
40
40
|
aminoWallet?: Secp256k1Wallet;
|
|
41
41
|
constructor(privateKey: Uint8Array, prefix: string);
|
|
@@ -44,24 +44,24 @@ export declare class CarbonPrivateKeySigner implements DirectCarbonSigner, Amino
|
|
|
44
44
|
getAccounts(): Promise<readonly AccountData[]>;
|
|
45
45
|
signAmino(signerAddress: string, signDoc: StdSignDoc): Promise<AminoSignResponse>;
|
|
46
46
|
signDirect(signerAddress: string, signDoc: SignDoc): Promise<DirectSignResponse>;
|
|
47
|
-
sendEvmTransaction(api:
|
|
47
|
+
sendEvmTransaction(api: OrbixSDK, req: ethers.providers.TransactionRequest): Promise<string>;
|
|
48
48
|
signMessage(address: string, message: string): Promise<string>;
|
|
49
49
|
}
|
|
50
|
-
export declare class
|
|
51
|
-
type:
|
|
50
|
+
export declare class OrbixNonSigner implements DirectOrbixSigner {
|
|
51
|
+
type: OrbixSignerTypes;
|
|
52
52
|
getAccounts(): Promise<readonly AccountData[]>;
|
|
53
53
|
signDirect(): Promise<DirectSignResponse>;
|
|
54
|
-
sendEvmTransaction(api:
|
|
54
|
+
sendEvmTransaction(api: OrbixSDK, req: ethers.providers.TransactionRequest): Promise<string>;
|
|
55
55
|
signMessage(address: string, message: string): Promise<string>;
|
|
56
56
|
}
|
|
57
|
-
export declare class
|
|
57
|
+
export declare class OrbixLedgerSigner implements AminoOrbixSigner {
|
|
58
58
|
readonly ledger: CosmosLedger;
|
|
59
|
-
type:
|
|
59
|
+
type: OrbixSignerTypes;
|
|
60
60
|
account?: AccountData;
|
|
61
61
|
retrieveAccount(): Promise<AccountData>;
|
|
62
62
|
getAccounts(): Promise<readonly AccountData[]>;
|
|
63
63
|
signAmino(_: string, doc: StdSignDoc): Promise<AminoSignResponse>;
|
|
64
|
-
sendEvmTransaction(api:
|
|
64
|
+
sendEvmTransaction(api: OrbixSDK, req: ethers.providers.TransactionRequest): Promise<string>;
|
|
65
65
|
signMessage(_: string, message: string): Promise<string>;
|
|
66
66
|
constructor(ledger: CosmosLedger);
|
|
67
67
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.OrbixLedgerSigner = exports.OrbixNonSigner = exports.OrbixPrivateKeySigner = exports.OrbixSignerTypes = void 0;
|
|
4
|
+
exports.isOrbixEIP712Signer = isOrbixEIP712Signer;
|
|
5
5
|
const constant_1 = require("../constant");
|
|
6
6
|
const ethermint_1 = require("../util/ethermint");
|
|
7
7
|
const generic_1 = require("../util/generic");
|
|
@@ -9,21 +9,21 @@ const message_1 = require("../util/message");
|
|
|
9
9
|
const amino_1 = require("@cosmjs/amino");
|
|
10
10
|
const proto_signing_1 = require("@cosmjs/proto-signing");
|
|
11
11
|
const ethers_1 = require("ethers");
|
|
12
|
-
var
|
|
13
|
-
(function (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})(
|
|
19
|
-
function
|
|
12
|
+
var OrbixSignerTypes;
|
|
13
|
+
(function (OrbixSignerTypes) {
|
|
14
|
+
OrbixSignerTypes[OrbixSignerTypes["Ledger"] = 0] = "Ledger";
|
|
15
|
+
OrbixSignerTypes[OrbixSignerTypes["PrivateKey"] = 1] = "PrivateKey";
|
|
16
|
+
OrbixSignerTypes[OrbixSignerTypes["BrowserInjected"] = 2] = "BrowserInjected";
|
|
17
|
+
OrbixSignerTypes[OrbixSignerTypes["PublicKey"] = 3] = "PublicKey";
|
|
18
|
+
})(OrbixSignerTypes || (exports.OrbixSignerTypes = OrbixSignerTypes = {}));
|
|
19
|
+
function isOrbixEIP712Signer(signer) {
|
|
20
20
|
return signer.signLegacyEip712 !== undefined;
|
|
21
21
|
}
|
|
22
|
-
class
|
|
22
|
+
class OrbixPrivateKeySigner {
|
|
23
23
|
constructor(privateKey, prefix) {
|
|
24
24
|
this.privateKey = privateKey;
|
|
25
25
|
this.prefix = prefix;
|
|
26
|
-
this.type =
|
|
26
|
+
this.type = OrbixSignerTypes.PrivateKey;
|
|
27
27
|
}
|
|
28
28
|
async initWallet() {
|
|
29
29
|
if (!this.wallet)
|
|
@@ -63,10 +63,10 @@ class CarbonPrivateKeySigner {
|
|
|
63
63
|
return Buffer.from(signedDoc.signature.signature, 'base64').toString('hex');
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
exports.
|
|
67
|
-
class
|
|
66
|
+
exports.OrbixPrivateKeySigner = OrbixPrivateKeySigner;
|
|
67
|
+
class OrbixNonSigner {
|
|
68
68
|
constructor() {
|
|
69
|
-
this.type =
|
|
69
|
+
this.type = OrbixSignerTypes.PublicKey;
|
|
70
70
|
}
|
|
71
71
|
async getAccounts() {
|
|
72
72
|
throw new Error("signing not available");
|
|
@@ -81,9 +81,9 @@ class CarbonNonSigner {
|
|
|
81
81
|
throw new Error("signing not available");
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
exports.
|
|
84
|
+
exports.OrbixNonSigner = OrbixNonSigner;
|
|
85
85
|
// Uses amino because ledger does not work with protobuf yet
|
|
86
|
-
class
|
|
86
|
+
class OrbixLedgerSigner {
|
|
87
87
|
async retrieveAccount() {
|
|
88
88
|
if (!this.account) {
|
|
89
89
|
const address = await this.ledger.getCosmosAddress();
|
|
@@ -125,7 +125,7 @@ class CarbonLedgerSigner {
|
|
|
125
125
|
}
|
|
126
126
|
constructor(ledger) {
|
|
127
127
|
this.ledger = ledger;
|
|
128
|
-
this.type =
|
|
128
|
+
this.type = OrbixSignerTypes.Ledger;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
exports.
|
|
131
|
+
exports.OrbixLedgerSigner = OrbixLedgerSigner;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TxRaw } from "../codec/cosmos/tx/v1beta1/tx";
|
|
2
|
-
import {
|
|
2
|
+
import { OrbixSignerData } from "../util/tx";
|
|
3
3
|
import { AminoMsg } from "@cosmjs/amino";
|
|
4
4
|
import { EncodeObject, OfflineSigner, Registry } from "@cosmjs/proto-signing";
|
|
5
5
|
import { AminoTypes, GasPrice, SigningStargateClientOptions, StargateClient, StdFee } from "@cosmjs/stargate";
|
|
@@ -14,7 +14,7 @@ export interface StdSignDoc {
|
|
|
14
14
|
readonly timeout_height: string;
|
|
15
15
|
}
|
|
16
16
|
export declare function makeSignDocAmino(msgs: readonly AminoMsg[], fee: StdFee, chainId: string, memo: string | undefined, accountNumber: number | string, sequence: number | string, timeoutHeight?: number | string): StdSignDoc;
|
|
17
|
-
export declare class
|
|
17
|
+
export declare class OrbixSigningClient extends StargateClient {
|
|
18
18
|
readonly signer: OfflineSigner;
|
|
19
19
|
readonly options: SigningStargateClientOptions;
|
|
20
20
|
readonly registry: Registry;
|
|
@@ -34,7 +34,7 @@ export declare class CarbonSigningClient extends StargateClient {
|
|
|
34
34
|
* from the chain. This is needed when signing for a multisig account, but it also allows for offline signing
|
|
35
35
|
* (See the SigningStargateClient.offline constructor).
|
|
36
36
|
*/
|
|
37
|
-
sign(signerAddress: string, messages: readonly EncodeObject[], fee: StdFee, memo: string, signerData:
|
|
37
|
+
sign(signerAddress: string, messages: readonly EncodeObject[], fee: StdFee, memo: string, signerData: OrbixSignerData, granterAddress?: string): Promise<TxRaw>;
|
|
38
38
|
private signDirect;
|
|
39
39
|
private signAmino;
|
|
40
40
|
private signLegacyEip712;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.OrbixSigningClient = void 0;
|
|
7
7
|
exports.makeSignDocAmino = makeSignDocAmino;
|
|
8
8
|
const codec_1 = require("../codec");
|
|
9
9
|
const tx_1 = require("../codec/cosmos/tx/v1beta1/tx");
|
|
@@ -17,7 +17,7 @@ const proto_signing_1 = require("@cosmjs/proto-signing");
|
|
|
17
17
|
const stargate_1 = require("@cosmjs/stargate");
|
|
18
18
|
const long_1 = __importDefault(require("long"));
|
|
19
19
|
const provider_1 = require("../provider");
|
|
20
|
-
const
|
|
20
|
+
const OrbixSigner_1 = require("./OrbixSigner");
|
|
21
21
|
// Added SignMode enum from cosmjs-types to resolve build error
|
|
22
22
|
var SignMode;
|
|
23
23
|
(function (SignMode) {
|
|
@@ -56,7 +56,7 @@ function makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence, tim
|
|
|
56
56
|
timeout_height: timeoutHeightStr,
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
class
|
|
59
|
+
class OrbixSigningClient extends stargate_1.StargateClient {
|
|
60
60
|
constructor(tmClient, signer, options = {}) {
|
|
61
61
|
super(tmClient, options);
|
|
62
62
|
this.signer = signer;
|
|
@@ -81,7 +81,7 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
81
81
|
* (See the SigningStargateClient.offline constructor).
|
|
82
82
|
*/
|
|
83
83
|
async sign(signerAddress, messages, fee, memo, signerData, granterAddress) {
|
|
84
|
-
if ((0,
|
|
84
|
+
if ((0, OrbixSigner_1.isOrbixEIP712Signer)(this.signer)) {
|
|
85
85
|
if (this.signer.legacyEip712SignMode) {
|
|
86
86
|
return this.signLegacyEip712(signerAddress, messages, fee, memo, signerData);
|
|
87
87
|
}
|
|
@@ -100,11 +100,11 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
100
100
|
async signDirect(signerAddress, messages, fee, memo, { accountNumber, sequence, chainId, timeoutHeight }, granterAddress) {
|
|
101
101
|
const signer = this.signer;
|
|
102
102
|
const accountFromSigner = (await this.signer.getAccounts()).find((account) => account.address === signerAddress);
|
|
103
|
-
if (!(0,
|
|
103
|
+
if (!(0, OrbixSigner_1.isOrbixEIP712Signer)(this.signer) && !accountFromSigner) {
|
|
104
104
|
throw new Error("Failed to retrieve account from signer");
|
|
105
105
|
}
|
|
106
106
|
const pubKeyBz = accountFromSigner ? accountFromSigner.pubkey : (await this.signer.getAccounts())[0].pubkey;
|
|
107
|
-
const pubkey = (0,
|
|
107
|
+
const pubkey = (0, OrbixSigner_1.isOrbixEIP712Signer)(this.signer) ? (0, ethermint_1.encodeAnyEthSecp256k1PubKey)(pubKeyBz) : (0, proto_signing_1.encodePubkey)((0, amino_1.encodeSecp256k1Pubkey)(pubKeyBz));
|
|
108
108
|
const txBodyEncodeObject = {
|
|
109
109
|
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
110
110
|
value: {
|
|
@@ -129,11 +129,11 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
129
129
|
async signAmino(signerAddress, messages, fee, memo, { accountNumber, sequence, chainId, timeoutHeight }, granterAddress) {
|
|
130
130
|
const signer = this.signer;
|
|
131
131
|
const accountFromSigner = (await this.signer.getAccounts()).find((account) => account.address === signerAddress);
|
|
132
|
-
if (!(0,
|
|
132
|
+
if (!(0, OrbixSigner_1.isOrbixEIP712Signer)(this.signer) && !accountFromSigner) {
|
|
133
133
|
throw new Error("Failed to retrieve account from signer");
|
|
134
134
|
}
|
|
135
135
|
const pubKeyBz = accountFromSigner ? accountFromSigner.pubkey : (await this.signer.getAccounts())[0].pubkey;
|
|
136
|
-
const pubkey = (0,
|
|
136
|
+
const pubkey = (0, OrbixSigner_1.isOrbixEIP712Signer)(this.signer) ? (0, ethermint_1.encodeAnyEthSecp256k1PubKey)(pubKeyBz) : (0, proto_signing_1.encodePubkey)((0, amino_1.encodeSecp256k1Pubkey)(pubKeyBz));
|
|
137
137
|
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
|
|
138
138
|
const msgs = messages.map((msg) => this.aminoTypes.toAmino(msg));
|
|
139
139
|
const signDoc = makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence, timeoutHeight ?? 0);
|
|
@@ -198,4 +198,4 @@ class CarbonSigningClient extends stargate_1.StargateClient {
|
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
exports.
|
|
201
|
+
exports.OrbixSigningClient = OrbixSigningClient;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { OverrideConfig } from "../
|
|
2
|
-
import {
|
|
1
|
+
import { OverrideConfig } from "../OrbixSDK";
|
|
2
|
+
import { OrbixQueryClient } from "../clients";
|
|
3
3
|
import GasFee from "../clients/GasFee";
|
|
4
4
|
import { Network, NetworkConfig, SupportedEip6963Provider } from "../constant";
|
|
5
5
|
import { ProviderAgent } from "../constant/walletProvider";
|
|
6
|
-
import {
|
|
6
|
+
import { OrbixTx } from "../util";
|
|
7
7
|
import { AccessTokenResponse, GrantRequest } from "../util/auth";
|
|
8
8
|
import { SmartWalletBlockchain } from "../util/blockchain";
|
|
9
9
|
import { BroadcastTxMode } from "../util/tx";
|
|
@@ -13,9 +13,9 @@ import { Account, DeliverTxResponse } from "@cosmjs/stargate";
|
|
|
13
13
|
import { Tendermint37Client } from "@cosmjs/tendermint-rpc";
|
|
14
14
|
import { BroadcastTxAsyncResponse, BroadcastTxSyncResponse, TxResponse } from "@cosmjs/tendermint-rpc/build/tendermint37/responses";
|
|
15
15
|
import { TxRaw as StargateTxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
export interface
|
|
16
|
+
import { OrbixSigner, OrbixSignerTypes } from "./OrbixSigner";
|
|
17
|
+
import { OrbixSigningClient } from "./OrbixSigningClient";
|
|
18
|
+
export interface OrbixWalletGenericOpts {
|
|
19
19
|
tmClient?: Tendermint37Client;
|
|
20
20
|
txDefaultBroadcastMode?: BroadcastTxMode;
|
|
21
21
|
network?: Network;
|
|
@@ -33,27 +33,27 @@ export interface CarbonWalletGenericOpts {
|
|
|
33
33
|
/**
|
|
34
34
|
* Optional callback that will be called before signing is requested/executed.
|
|
35
35
|
*/
|
|
36
|
-
onRequestSign?:
|
|
36
|
+
onRequestSign?: OrbixWallet.OnRequestSignCallback;
|
|
37
37
|
/**
|
|
38
38
|
* Optional callback that will be called when signing is complete.
|
|
39
39
|
*/
|
|
40
|
-
onSignComplete?:
|
|
40
|
+
onSignComplete?: OrbixWallet.OnSignCompleteCallback;
|
|
41
41
|
/**
|
|
42
42
|
* Optional callback that will be called after tx is broadcast successful.
|
|
43
43
|
*/
|
|
44
|
-
onBroadcastTxSuccess?:
|
|
44
|
+
onBroadcastTxSuccess?: OrbixWallet.OnBroadcastTxSuccessCallback;
|
|
45
45
|
/**
|
|
46
46
|
* Optional callback that will be called if tx broadcast fails.
|
|
47
47
|
*/
|
|
48
|
-
onBroadcastTxFail?:
|
|
48
|
+
onBroadcastTxFail?: OrbixWallet.OnBroadcastTxFailCallback;
|
|
49
49
|
/**
|
|
50
50
|
* Optional callback that will be called before authentication is requested
|
|
51
51
|
*/
|
|
52
|
-
onRequestAuth?:
|
|
52
|
+
onRequestAuth?: OrbixWallet.OnRequestAuthCallback;
|
|
53
53
|
/**
|
|
54
54
|
* Optional callback that will be called after authentication is complete
|
|
55
55
|
*/
|
|
56
|
-
onAuthComplete?:
|
|
56
|
+
onAuthComplete?: OrbixWallet.OnAuthComplete;
|
|
57
57
|
}
|
|
58
58
|
export interface AuthInfo {
|
|
59
59
|
message: string;
|
|
@@ -75,7 +75,7 @@ type PrivateKeyOpts = {
|
|
|
75
75
|
};
|
|
76
76
|
type CustomSignerOpts = {
|
|
77
77
|
mode: "customSigner";
|
|
78
|
-
signer:
|
|
78
|
+
signer: OrbixSigner;
|
|
79
79
|
publicKeyBase64: string;
|
|
80
80
|
};
|
|
81
81
|
type ViewOnlyOpts = {
|
|
@@ -88,7 +88,7 @@ type QROpts = {
|
|
|
88
88
|
granter: string;
|
|
89
89
|
expiry: Date;
|
|
90
90
|
};
|
|
91
|
-
export type
|
|
91
|
+
export type OrbixWalletInitOpts = OrbixWalletGenericOpts & (MnemonicOpts | PrivateKeyOpts | CustomSignerOpts | ViewOnlyOpts | QROpts);
|
|
92
92
|
export interface AccountInfo extends Account {
|
|
93
93
|
chainId: string;
|
|
94
94
|
}
|
|
@@ -96,20 +96,20 @@ export interface Grantee {
|
|
|
96
96
|
expiry: Date;
|
|
97
97
|
signer: OfflineDirectSigner;
|
|
98
98
|
}
|
|
99
|
-
export declare class
|
|
99
|
+
export declare class OrbixWallet {
|
|
100
100
|
network: Network;
|
|
101
101
|
configOverride: Partial<NetworkConfig>;
|
|
102
102
|
networkConfig: NetworkConfig;
|
|
103
|
-
onRequestSign?:
|
|
104
|
-
onSignComplete?:
|
|
105
|
-
onBroadcastTxSuccess?:
|
|
106
|
-
onBroadcastTxFail?:
|
|
107
|
-
onRequestAuth?:
|
|
108
|
-
onAuthComplete?:
|
|
103
|
+
onRequestSign?: OrbixWallet.OnRequestSignCallback;
|
|
104
|
+
onSignComplete?: OrbixWallet.OnSignCompleteCallback;
|
|
105
|
+
onBroadcastTxSuccess?: OrbixWallet.OnBroadcastTxSuccessCallback;
|
|
106
|
+
onBroadcastTxFail?: OrbixWallet.OnBroadcastTxFailCallback;
|
|
107
|
+
onRequestAuth?: OrbixWallet.OnRequestAuthCallback;
|
|
108
|
+
onAuthComplete?: OrbixWallet.OnAuthComplete;
|
|
109
109
|
defaultTimeoutBlocks: number;
|
|
110
110
|
mnemonic?: string;
|
|
111
111
|
privateKey?: Buffer;
|
|
112
|
-
signer:
|
|
112
|
+
signer: OrbixSigner;
|
|
113
113
|
bech32Address: string;
|
|
114
114
|
evmBech32Address: string;
|
|
115
115
|
hexAddress: string;
|
|
@@ -117,7 +117,7 @@ export declare class CarbonWallet {
|
|
|
117
117
|
accountMerged?: boolean;
|
|
118
118
|
triggerMerge?: boolean;
|
|
119
119
|
publicKey: Buffer;
|
|
120
|
-
query?:
|
|
120
|
+
query?: OrbixQueryClient;
|
|
121
121
|
txDefaultBroadCastMode?: BroadcastTxMode;
|
|
122
122
|
initialized: boolean;
|
|
123
123
|
accountInfo?: AccountInfo;
|
|
@@ -135,8 +135,8 @@ export declare class CarbonWallet {
|
|
|
135
135
|
private sequenceInvalidated;
|
|
136
136
|
private txSignManager;
|
|
137
137
|
private txDispatchManager;
|
|
138
|
-
constructor(opts:
|
|
139
|
-
initialize(queryClient:
|
|
138
|
+
constructor(opts: OrbixWalletInitOpts);
|
|
139
|
+
initialize(queryClient: OrbixQueryClient, gasFee: GasFee, fallbackConfig?: OverrideConfig | null, opts?: OrbixWalletGenericOpts): Promise<OrbixWallet>;
|
|
140
140
|
reloadJwtToken(request?: GrantRequest, authMessage?: string): Promise<void>;
|
|
141
141
|
queryViewOnlyEvmHexAddress(): Promise<void>;
|
|
142
142
|
private refreshJwtToken;
|
|
@@ -144,40 +144,40 @@ export declare class CarbonWallet {
|
|
|
144
144
|
private constructGrantRequest;
|
|
145
145
|
setGrantee(grantee?: Grantee): void;
|
|
146
146
|
isGranteeValid(): boolean;
|
|
147
|
-
updateNetwork(network: Network):
|
|
147
|
+
updateNetwork(network: Network): OrbixWallet;
|
|
148
148
|
setAuthorizedMsgs(msgs?: string[]): void;
|
|
149
|
-
getSignedTx(signerAddress: string, messages: readonly EncodeObject[], sequence: number, opts: Omit<
|
|
149
|
+
getSignedTx(signerAddress: string, messages: readonly EncodeObject[], sequence: number, opts: Omit<OrbixTx.SignTxOpts, "sequence">, granterAddress?: string): Promise<OrbixWallet.TxRaw>;
|
|
150
150
|
/**
|
|
151
151
|
* broadcast TX and wait for block confirmation
|
|
152
152
|
*
|
|
153
153
|
*/
|
|
154
|
-
broadcastTx(txRaw:
|
|
154
|
+
broadcastTx(txRaw: OrbixWallet.TxRaw, opts?: OrbixTx.BroadcastTxOpts): Promise<OrbixWallet.SendTxResponse>;
|
|
155
155
|
/**
|
|
156
156
|
* broadcast TX to mempool but doesnt wait for block confirmation
|
|
157
157
|
*
|
|
158
158
|
*/
|
|
159
|
-
broadcastTxToMempoolWithoutConfirm(txRaw:
|
|
159
|
+
broadcastTxToMempoolWithoutConfirm(txRaw: OrbixWallet.TxRaw): Promise<OrbixWallet.SendTxToMempoolWithoutConfirmResponse>;
|
|
160
160
|
/**
|
|
161
161
|
* broadcast TX but doesnt wait for block confirmation nor submission to mempool
|
|
162
162
|
*
|
|
163
163
|
*/
|
|
164
|
-
broadcastTxWithoutConfirm(txRaw:
|
|
165
|
-
signAndBroadcast(messages: EncodeObject[], signOpts?:
|
|
164
|
+
broadcastTxWithoutConfirm(txRaw: OrbixWallet.TxRaw): Promise<OrbixWallet.SendTxWithoutConfirmResponse>;
|
|
165
|
+
signAndBroadcast(messages: EncodeObject[], signOpts?: OrbixTx.SignTxOpts, broadcastOpts?: OrbixTx.BroadcastTxOpts): Promise<DeliverTxResponse | BroadcastTxSyncResponse | BroadcastTxAsyncResponse>;
|
|
166
166
|
private signTx;
|
|
167
167
|
private signWithGrantee;
|
|
168
168
|
private getBroadcastFunc;
|
|
169
169
|
private dispatchTx;
|
|
170
|
-
sendTxs(msgs: EncodeObject[], opts?:
|
|
171
|
-
sendInitialMergeAccountTx(msgs: EncodeObject[], opts?:
|
|
172
|
-
sendTxsWithoutConfirm(msgs: EncodeObject[], opts?:
|
|
173
|
-
sendTx(msg: EncodeObject, opts?:
|
|
170
|
+
sendTxs(msgs: EncodeObject[], opts?: OrbixTx.SignTxOpts): Promise<OrbixWallet.SendTxResponse>;
|
|
171
|
+
sendInitialMergeAccountTx(msgs: EncodeObject[], opts?: OrbixTx.SignTxOpts): Promise<void>;
|
|
172
|
+
sendTxsWithoutConfirm(msgs: EncodeObject[], opts?: OrbixTx.SignTxOpts): Promise<OrbixWallet.SendTxToMempoolWithoutConfirmResponse>;
|
|
173
|
+
sendTx(msg: EncodeObject, opts?: OrbixTx.SignTxOpts): Promise<OrbixWallet.SendTxResponse>;
|
|
174
174
|
waitForTx(txHash: string, throwIfNotIncludedInBlock?: boolean, timeoutMs?: number, pollIntervalMs?: number): Promise<TxResponse>;
|
|
175
|
-
getSigningClient(): Promise<
|
|
175
|
+
getSigningClient(): Promise<OrbixSigningClient>;
|
|
176
176
|
getTimeoutHeight(): Promise<number | undefined>;
|
|
177
177
|
getTmClient(reconnect?: boolean): Promise<Tendermint37Client>;
|
|
178
178
|
getChainId(): string;
|
|
179
179
|
getEvmChainId(): string;
|
|
180
|
-
isSigner(signerType:
|
|
180
|
+
isSigner(signerType: OrbixSignerTypes): boolean;
|
|
181
181
|
isLedgerSigner(): boolean;
|
|
182
182
|
isLedgerViaBrowserExtension(): boolean;
|
|
183
183
|
isPrivateKeySigner(): boolean;
|
|
@@ -203,7 +203,7 @@ export declare class CarbonWallet {
|
|
|
203
203
|
private isNonceMismatchError;
|
|
204
204
|
private getQueryClient;
|
|
205
205
|
}
|
|
206
|
-
export declare namespace
|
|
206
|
+
export declare namespace OrbixWallet {
|
|
207
207
|
type SendTxResponse = DeliverTxResponse | BroadcastTxSyncResponse | BroadcastTxAsyncResponse;
|
|
208
208
|
type SendTxToMempoolWithoutConfirmResponse = BroadcastTxSyncResponse;
|
|
209
209
|
type SendTxWithoutConfirmResponse = BroadcastTxAsyncResponse;
|