@injectivelabs/wallet-base 1.15.0 → 1.15.2

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.
Files changed (55) hide show
  1. package/dist/cjs/base.d.ts +8 -0
  2. package/dist/cjs/base.js +14 -0
  3. package/dist/cjs/index.d.ts +3 -0
  4. package/dist/cjs/index.js +24 -0
  5. package/dist/cjs/package.json +3 -0
  6. package/dist/cjs/types/enums.d.ts +52 -0
  7. package/dist/cjs/types/enums.js +49 -0
  8. package/dist/cjs/types/index.d.ts +3 -0
  9. package/dist/cjs/types/index.js +19 -0
  10. package/dist/cjs/types/provider.d.ts +21 -0
  11. package/dist/cjs/types/provider.js +2 -0
  12. package/dist/cjs/types/strategy.d.ts +202 -0
  13. package/dist/cjs/types/strategy.js +2 -0
  14. package/dist/cjs/utils/address.d.ts +2 -0
  15. package/dist/cjs/utils/address.js +30 -0
  16. package/dist/cjs/utils/alchemy.d.ts +1 -0
  17. package/dist/cjs/utils/alchemy.js +11 -0
  18. package/dist/cjs/utils/constants.d.ts +6 -0
  19. package/dist/cjs/utils/constants.js +9 -0
  20. package/dist/cjs/utils/cosmos.d.ts +2 -0
  21. package/dist/cjs/utils/cosmos.js +13 -0
  22. package/dist/cjs/utils/index.d.ts +6 -0
  23. package/dist/cjs/utils/index.js +22 -0
  24. package/dist/cjs/utils/tx.d.ts +31 -0
  25. package/dist/cjs/utils/tx.js +14 -0
  26. package/dist/cjs/utils/wallet.d.ts +7 -0
  27. package/dist/cjs/utils/wallet.js +47 -0
  28. package/dist/esm/base.d.ts +8 -0
  29. package/dist/esm/base.js +11 -0
  30. package/dist/esm/index.d.ts +3 -0
  31. package/dist/esm/index.js +3 -0
  32. package/dist/esm/package.json +3 -0
  33. package/dist/esm/types/enums.d.ts +52 -0
  34. package/dist/esm/types/enums.js +46 -0
  35. package/dist/esm/types/index.d.ts +3 -0
  36. package/dist/esm/types/index.js +3 -0
  37. package/dist/esm/types/provider.d.ts +21 -0
  38. package/dist/esm/types/provider.js +1 -0
  39. package/dist/esm/types/strategy.d.ts +202 -0
  40. package/dist/esm/types/strategy.js +1 -0
  41. package/dist/esm/utils/address.d.ts +2 -0
  42. package/dist/esm/utils/address.js +25 -0
  43. package/dist/esm/utils/alchemy.d.ts +1 -0
  44. package/dist/esm/utils/alchemy.js +7 -0
  45. package/dist/esm/utils/constants.d.ts +6 -0
  46. package/dist/esm/utils/constants.js +6 -0
  47. package/dist/esm/utils/cosmos.d.ts +2 -0
  48. package/dist/esm/utils/cosmos.js +9 -0
  49. package/dist/esm/utils/index.d.ts +6 -0
  50. package/dist/esm/utils/index.js +6 -0
  51. package/dist/esm/utils/tx.d.ts +31 -0
  52. package/dist/esm/utils/tx.js +10 -0
  53. package/dist/esm/utils/wallet.d.ts +7 -0
  54. package/dist/esm/utils/wallet.js +38 -0
  55. package/package.json +6 -6
@@ -0,0 +1,8 @@
1
+ import { ChainId, CosmosChainId, EthereumChainId } from '@injectivelabs/ts-types';
2
+ import { WalletEventListener, ConcreteWalletStrategyArgs, ConcreteCosmosWalletStrategyArgs, ConcreteEthereumWalletStrategyArgs } from './types/index.js';
3
+ export default abstract class BaseConcreteStrategy {
4
+ protected chainId: ChainId | CosmosChainId;
5
+ protected ethereumChainId?: EthereumChainId;
6
+ protected listeners: Partial<Record<WalletEventListener, any>>;
7
+ protected constructor(args: ConcreteWalletStrategyArgs | ConcreteEthereumWalletStrategyArgs | ConcreteCosmosWalletStrategyArgs);
8
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class BaseConcreteStrategy {
4
+ chainId;
5
+ ethereumChainId;
6
+ listeners = {};
7
+ constructor(args) {
8
+ this.ethereumChainId = 'ethereumOptions' in args && args.ethereumOptions
9
+ ? args.ethereumOptions.ethereumChainId
10
+ : undefined;
11
+ this.chainId = args.chainId;
12
+ }
13
+ }
14
+ exports.default = BaseConcreteStrategy;
@@ -0,0 +1,3 @@
1
+ export * from './types/index.js';
2
+ export * from './utils/index.js';
3
+ export { default as BaseConcreteStrategy } from './base.js';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.BaseConcreteStrategy = void 0;
21
+ __exportStar(require("./types/index.js"), exports);
22
+ __exportStar(require("./utils/index.js"), exports);
23
+ var base_js_1 = require("./base.js");
24
+ Object.defineProperty(exports, "BaseConcreteStrategy", { enumerable: true, get: function () { return __importDefault(base_js_1).default; } });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,52 @@
1
+ import { WalletErrorActionModule } from '@injectivelabs/exceptions';
2
+ export declare enum Wallet {
3
+ Leap = "leap",
4
+ Keplr = "keplr",
5
+ Ninji = "ninji",
6
+ Magic = "magic",
7
+ Ledger = "ledger",
8
+ BitGet = "BitGet",
9
+ OWallet = "owallet",
10
+ Phantom = "phantom",
11
+ Metamask = "metamask",
12
+ OkxWallet = "okx-wallet",
13
+ TrustWallet = "trust-wallet",
14
+ PrivateKey = "private-key",
15
+ TrezorBip32 = "trezor-bip32",
16
+ TrezorBip44 = "trezor-bip44",
17
+ Cosmostation = "cosmostation",
18
+ LedgerCosmos = "ledger-cosmos",
19
+ LedgerLegacy = "ledger-legacy",
20
+ WalletConnect = "wallet-connect",
21
+ CosmostationEth = "cosmostation-eth"
22
+ }
23
+ export declare enum MagicProvider {
24
+ Email = "email",
25
+ Apple = "apple",
26
+ Github = "github",
27
+ Google = "google",
28
+ Discord = "discord",
29
+ Twitter = "twitter",
30
+ Facebook = "facebook"
31
+ }
32
+ export declare enum WalletDeviceType {
33
+ Mobile = "mobile",
34
+ Other = "other",
35
+ Browser = "browser",
36
+ Hardware = "hardware"
37
+ }
38
+ export declare enum WalletEventListener {
39
+ AccountChange = "account-change",
40
+ ChainIdChange = "chain-id-change"
41
+ }
42
+ export declare const WalletAction: {
43
+ SignTransaction: WalletErrorActionModule.SignTransaction;
44
+ SignEthereumTransaction: WalletErrorActionModule.SignEthereumTransaction;
45
+ SendTransaction: WalletErrorActionModule.SendTransaction;
46
+ SendEthereumTransaction: WalletErrorActionModule.SendEthereumTransaction;
47
+ SignArbitrary: WalletErrorActionModule.SignArbitrary;
48
+ GetAccounts: WalletErrorActionModule.GetAccounts;
49
+ GetNetworkId: WalletErrorActionModule.GetNetworkId;
50
+ GetChainId: WalletErrorActionModule.GetChainId;
51
+ GetEthereumTransactionReceipt: WalletErrorActionModule.GetEthereumTransactionReceipt;
52
+ };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WalletAction = exports.WalletEventListener = exports.WalletDeviceType = exports.MagicProvider = exports.Wallet = void 0;
4
+ const exceptions_1 = require("@injectivelabs/exceptions");
5
+ var Wallet;
6
+ (function (Wallet) {
7
+ Wallet["Leap"] = "leap";
8
+ Wallet["Keplr"] = "keplr";
9
+ Wallet["Ninji"] = "ninji";
10
+ Wallet["Magic"] = "magic";
11
+ Wallet["Ledger"] = "ledger";
12
+ Wallet["BitGet"] = "BitGet";
13
+ Wallet["OWallet"] = "owallet";
14
+ Wallet["Phantom"] = "phantom";
15
+ Wallet["Metamask"] = "metamask";
16
+ Wallet["OkxWallet"] = "okx-wallet";
17
+ Wallet["TrustWallet"] = "trust-wallet";
18
+ Wallet["PrivateKey"] = "private-key";
19
+ Wallet["TrezorBip32"] = "trezor-bip32";
20
+ Wallet["TrezorBip44"] = "trezor-bip44";
21
+ Wallet["Cosmostation"] = "cosmostation";
22
+ Wallet["LedgerCosmos"] = "ledger-cosmos";
23
+ Wallet["LedgerLegacy"] = "ledger-legacy";
24
+ Wallet["WalletConnect"] = "wallet-connect";
25
+ Wallet["CosmostationEth"] = "cosmostation-eth";
26
+ })(Wallet || (exports.Wallet = Wallet = {}));
27
+ var MagicProvider;
28
+ (function (MagicProvider) {
29
+ MagicProvider["Email"] = "email";
30
+ MagicProvider["Apple"] = "apple";
31
+ MagicProvider["Github"] = "github";
32
+ MagicProvider["Google"] = "google";
33
+ MagicProvider["Discord"] = "discord";
34
+ MagicProvider["Twitter"] = "twitter";
35
+ MagicProvider["Facebook"] = "facebook";
36
+ })(MagicProvider || (exports.MagicProvider = MagicProvider = {}));
37
+ var WalletDeviceType;
38
+ (function (WalletDeviceType) {
39
+ WalletDeviceType["Mobile"] = "mobile";
40
+ WalletDeviceType["Other"] = "other";
41
+ WalletDeviceType["Browser"] = "browser";
42
+ WalletDeviceType["Hardware"] = "hardware";
43
+ })(WalletDeviceType || (exports.WalletDeviceType = WalletDeviceType = {}));
44
+ var WalletEventListener;
45
+ (function (WalletEventListener) {
46
+ WalletEventListener["AccountChange"] = "account-change";
47
+ WalletEventListener["ChainIdChange"] = "chain-id-change";
48
+ })(WalletEventListener || (exports.WalletEventListener = WalletEventListener = {}));
49
+ exports.WalletAction = { ...exceptions_1.WalletErrorActionModule };
@@ -0,0 +1,3 @@
1
+ export * from './enums.js';
2
+ export * from './strategy.js';
3
+ export * from './provider.js';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./enums.js"), exports);
18
+ __exportStar(require("./strategy.js"), exports);
19
+ __exportStar(require("./provider.js"), exports);
@@ -0,0 +1,21 @@
1
+ import { type EIP1193Provider } from 'eip1193-provider';
2
+ export interface BrowserEip1993Provider extends EIP1193Provider {
3
+ removeAllListeners(): void;
4
+ isMetaMask: boolean;
5
+ isTrustWallet: boolean;
6
+ isTrust: boolean;
7
+ isOkxWallet: boolean;
8
+ isPhantom: boolean;
9
+ }
10
+ export interface WindowWithEip1193Provider extends Window {
11
+ ethereum: BrowserEip1993Provider;
12
+ okxwallet: BrowserEip1993Provider;
13
+ bitkeep: {
14
+ ethereum: BrowserEip1993Provider;
15
+ };
16
+ providers: BrowserEip1993Provider[];
17
+ trustWallet?: BrowserEip1993Provider;
18
+ phantom?: {
19
+ ethereum?: BrowserEip1993Provider;
20
+ };
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,202 @@
1
+ import { ChainId, CosmosChainId, AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
2
+ import type { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
3
+ import { StdSignDoc } from '@keplr-wallet/types';
4
+ import { WalletDeviceType, Wallet } from './enums.js';
5
+ export type onAccountChangeCallback = (account: string | string[]) => void;
6
+ export type onChainIdChangeCallback = () => void;
7
+ export type CosmosWalletAbstraction = {
8
+ enableGasCheck?(chainId: ChainId): Promise<void> | void;
9
+ disableGasCheck?(chainId: ChainId): Promise<void> | void;
10
+ signEIP712CosmosTx(args: {
11
+ signDoc: StdSignDoc;
12
+ eip712: any;
13
+ }): Promise<AminoSignResponse>;
14
+ };
15
+ export type MagicMetadata = {
16
+ apiKey?: string;
17
+ rpcEndpoint?: string;
18
+ };
19
+ export type WalletConnectMetadata = Record<string, string | Record<string, string> | Record<string, string[]>>;
20
+ export interface WalletStrategyEthereumOptions {
21
+ ethereumChainId: EthereumChainId;
22
+ rpcUrl?: string;
23
+ }
24
+ export interface SendTransactionOptions {
25
+ address: string;
26
+ chainId: ChainId;
27
+ txTimeout?: number;
28
+ endpoints: {
29
+ rest: string;
30
+ grpc: string;
31
+ tm?: string;
32
+ };
33
+ }
34
+ export interface ConcreteWalletStrategyOptions {
35
+ privateKey?: string;
36
+ metadata?: Record<string, string | Record<string, string>>;
37
+ }
38
+ export interface ConcreteWalletStrategyArgs {
39
+ chainId: ChainId;
40
+ options?: ConcreteWalletStrategyOptions;
41
+ }
42
+ export interface ConcreteCosmosWalletStrategyArgs {
43
+ chainId: CosmosChainId | ChainId;
44
+ wallet?: Wallet;
45
+ options?: ConcreteWalletStrategyOptions;
46
+ }
47
+ export interface ConcreteEthereumWalletStrategyArgs extends ConcreteWalletStrategyArgs {
48
+ ethereumOptions: WalletStrategyEthereumOptions;
49
+ }
50
+ export interface ConcreteCosmosWalletStrategy {
51
+ /**
52
+ * The accounts from the wallet (addresses)
53
+ */
54
+ getAddresses(args?: unknown): Promise<string[]>;
55
+ /**
56
+ * Return the WalletDeviceType connected on the
57
+ * wallet provider (extension, mobile, hardware wallet)
58
+ */
59
+ getWalletDeviceType(): Promise<WalletDeviceType>;
60
+ /**
61
+ * Get the PubKey from the wallet
62
+ * in base64 for Cosmos native wallets
63
+ */
64
+ getPubKey(address?: string): Promise<string>;
65
+ /**
66
+ * Perform validations and checks
67
+ * for the wallet (if the chain is supported, etc)
68
+ */
69
+ enable(args?: unknown): Promise<boolean>;
70
+ /**
71
+ * Sends Cosmos transaction. Returns a transaction hash
72
+ * @param transaction should implement TransactionConfig
73
+ * @param options
74
+ */
75
+ sendTransaction(transaction: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
76
+ signCosmosTransaction(transaction: {
77
+ txRaw: TxRaw;
78
+ chainId: string;
79
+ accountNumber: number;
80
+ address: string;
81
+ }): Promise<DirectSignResponse>;
82
+ signAminoTransaction(transaction: {
83
+ stdSignDoc: StdSignDoc;
84
+ address: string;
85
+ }): Promise<AminoSignResponse>;
86
+ }
87
+ export type ConcreteStrategiesArg = {
88
+ [key in Wallet]?: ConcreteWalletStrategy;
89
+ };
90
+ export interface WalletStrategyArguments {
91
+ chainId: ChainId;
92
+ options?: ConcreteWalletStrategyOptions;
93
+ ethereumOptions?: WalletStrategyEthereumOptions;
94
+ disabledWallets?: Wallet[];
95
+ wallet?: Wallet;
96
+ strategies: ConcreteStrategiesArg;
97
+ }
98
+ export interface ConcreteWalletStrategy extends Omit<ConcreteCosmosWalletStrategy, 'sendTransaction' | 'isChainIdSupported' | 'signAminoTransaction'> {
99
+ /**
100
+ * Sends Cosmos transaction. Returns a transaction hash
101
+ * @param transaction should implement TransactionConfig
102
+ * @param options
103
+ */
104
+ sendTransaction(transaction: DirectSignResponse | TxRaw, options: {
105
+ address: string;
106
+ chainId: ChainId;
107
+ txTimeout?: number;
108
+ endpoints?: {
109
+ rest: string;
110
+ grpc: string;
111
+ tm?: string;
112
+ };
113
+ }): Promise<TxResponse>;
114
+ /**
115
+ * Confirm the address on the wallet
116
+ * @param address address
117
+ */
118
+ getSessionOrConfirm(address?: string): Promise<string>;
119
+ /**
120
+ * Sends Ethereum transaction. Returns a transaction hash
121
+ * @param transaction should implement TransactionConfig
122
+ * @param options
123
+ */
124
+ sendEthereumTransaction(transaction: unknown, options: {
125
+ address: string;
126
+ ethereumChainId: EthereumChainId;
127
+ }): Promise<string>;
128
+ /**
129
+ * Sign a cosmos transaction using the wallet provider
130
+ *
131
+ * @param transaction
132
+ * @param address - injective address
133
+ */
134
+ signCosmosTransaction(transaction: {
135
+ txRaw: TxRaw;
136
+ accountNumber: number;
137
+ chainId: string;
138
+ address: string;
139
+ }): Promise<DirectSignResponse>;
140
+ /**
141
+ * Sign an amino sign doc using the wallet provider
142
+ *
143
+ * @param transaction
144
+ * @param address - injective address
145
+ */
146
+ signAminoCosmosTransaction(transaction: {
147
+ signDoc: StdSignDoc;
148
+ address: string;
149
+ }): Promise<AminoSignResponse>;
150
+ /**
151
+ * Sign EIP712 TypedData using the wallet provider
152
+ * @param eip712TypedData
153
+ * @param address - ethereum address
154
+ */
155
+ signEip712TypedData(eip712TypedData: string, address: string): Promise<string>;
156
+ signArbitrary(signer: string, data: string | Uint8Array): Promise<string>;
157
+ getEthereumChainId(): Promise<string>;
158
+ getEthereumTransactionReceipt(txHash: string): void;
159
+ onAccountChange?(callback: onAccountChangeCallback): Promise<void> | void;
160
+ onChainIdChange?(callback: onChainIdChangeCallback): Promise<void> | void;
161
+ disconnect?(): Promise<void> | void;
162
+ getCosmosWallet?(chainId: ChainId): CosmosWalletAbstraction;
163
+ }
164
+ export interface WalletStrategy {
165
+ strategies: ConcreteStrategiesArg;
166
+ wallet: Wallet;
167
+ args: WalletStrategyArguments;
168
+ getWallet(): Wallet;
169
+ setWallet(wallet: Wallet): void;
170
+ setOptions(options?: ConcreteWalletStrategyOptions): void;
171
+ getStrategy(): ConcreteWalletStrategy;
172
+ getAddresses(args?: unknown): Promise<AccountAddress[]>;
173
+ getWalletDeviceType(): Promise<WalletDeviceType>;
174
+ getPubKey(address?: string): Promise<string>;
175
+ enable(args?: unknown): Promise<boolean>;
176
+ enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]>;
177
+ getEthereumChainId(): Promise<string>;
178
+ getEthereumTransactionReceipt(txHash: string): Promise<void>;
179
+ getSessionOrConfirm(address?: AccountAddress): Promise<string>;
180
+ sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
181
+ sendEthereumTransaction(tx: any, options: {
182
+ address: AccountAddress;
183
+ ethereumChainId: EthereumChainId;
184
+ }): Promise<string>;
185
+ signEip712TypedData(eip712TypedData: string, address: AccountAddress): Promise<string>;
186
+ signAminoCosmosTransaction(transaction: {
187
+ signDoc: StdSignDoc;
188
+ address: string;
189
+ }): Promise<AminoSignResponse>;
190
+ signCosmosTransaction(transaction: {
191
+ txRaw: TxRaw;
192
+ accountNumber: number;
193
+ chainId: string;
194
+ address: string;
195
+ }): Promise<DirectSignResponse>;
196
+ signArbitrary(signer: string, data: string | Uint8Array): Promise<string | void>;
197
+ onAccountChange(callback: onAccountChangeCallback): Promise<void>;
198
+ onChainIdChange(callback: onChainIdChangeCallback): Promise<void>;
199
+ disconnect(): Promise<void>;
200
+ getCosmosWallet?(chainId: ChainId): CosmosWalletAbstraction;
201
+ }
202
+ export { StdSignDoc };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare const getInjectiveSignerAddress: (address: string | undefined) => string;
2
+ export declare const getEthereumSignerAddress: (address: string | undefined) => string;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEthereumSignerAddress = exports.getInjectiveSignerAddress = void 0;
4
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
5
+ const getInjectiveSignerAddress = (address) => {
6
+ if (!address) {
7
+ return '';
8
+ }
9
+ if (address.startsWith('inj')) {
10
+ return address;
11
+ }
12
+ if (address.startsWith('0x')) {
13
+ return (0, sdk_ts_1.getInjectiveAddress)(address);
14
+ }
15
+ return '';
16
+ };
17
+ exports.getInjectiveSignerAddress = getInjectiveSignerAddress;
18
+ const getEthereumSignerAddress = (address) => {
19
+ if (!address) {
20
+ return '';
21
+ }
22
+ if (address.startsWith('0x')) {
23
+ return address;
24
+ }
25
+ if (address.startsWith('inj')) {
26
+ return (0, sdk_ts_1.getEthereumAddress)(address);
27
+ }
28
+ return '';
29
+ };
30
+ exports.getEthereumSignerAddress = getEthereumSignerAddress;
@@ -0,0 +1 @@
1
+ export declare const getKeyFromRpcUrl: (rpcUrl: string) => string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getKeyFromRpcUrl = void 0;
4
+ const getKeyFromRpcUrl = (rpcUrl) => {
5
+ if (!rpcUrl.includes('alchemyapi.io') && !rpcUrl.includes('alchemy.com')) {
6
+ return rpcUrl;
7
+ }
8
+ const [key] = rpcUrl.split('/').reverse();
9
+ return key;
10
+ };
11
+ exports.getKeyFromRpcUrl = getKeyFromRpcUrl;
@@ -0,0 +1,6 @@
1
+ import { BigNumber, BigNumberInBase } from '@injectivelabs/utils';
2
+ export declare const GWEI_IN_WEI: BigNumber;
3
+ export declare const TIP_IN_GWEI: BigNumberInBase;
4
+ export declare const DEFAULT_BASE_DERIVATION_PATH = "m/44'/60'";
5
+ export declare const DEFAULT_NUM_ADDRESSES_TO_FETCH = 5;
6
+ export declare const DEFAULT_ADDRESS_SEARCH_LIMIT = 100;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_ADDRESS_SEARCH_LIMIT = exports.DEFAULT_NUM_ADDRESSES_TO_FETCH = exports.DEFAULT_BASE_DERIVATION_PATH = exports.TIP_IN_GWEI = exports.GWEI_IN_WEI = void 0;
4
+ const utils_1 = require("@injectivelabs/utils");
5
+ exports.GWEI_IN_WEI = new utils_1.BigNumber(1000000000);
6
+ exports.TIP_IN_GWEI = new utils_1.BigNumberInBase(2).times(exports.GWEI_IN_WEI);
7
+ exports.DEFAULT_BASE_DERIVATION_PATH = "m/44'/60'";
8
+ exports.DEFAULT_NUM_ADDRESSES_TO_FETCH = 5;
9
+ exports.DEFAULT_ADDRESS_SEARCH_LIMIT = 100;
@@ -0,0 +1,2 @@
1
+ import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts';
2
+ export declare const createCosmosSignDocFromSignDoc: (signDoc: CosmosTxV1Beta1Tx.SignDoc) => any;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCosmosSignDocFromSignDoc = void 0;
4
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
5
+ const createCosmosSignDocFromSignDoc = (signDoc) => {
6
+ return sdk_ts_1.CosmosTxV1Beta1Tx.SignDoc.fromPartial({
7
+ bodyBytes: signDoc.bodyBytes,
8
+ authInfoBytes: signDoc.authInfoBytes,
9
+ accountNumber: BigInt(signDoc.accountNumber).toString(),
10
+ chainId: signDoc.chainId,
11
+ });
12
+ };
13
+ exports.createCosmosSignDocFromSignDoc = createCosmosSignDocFromSignDoc;
@@ -0,0 +1,6 @@
1
+ export * from './address.js';
2
+ export * from './tx.js';
3
+ export * from './wallet.js';
4
+ export * from './constants.js';
5
+ export * from './alchemy.js';
6
+ export * from './cosmos.js';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./address.js"), exports);
18
+ __exportStar(require("./tx.js"), exports);
19
+ __exportStar(require("./wallet.js"), exports);
20
+ __exportStar(require("./constants.js"), exports);
21
+ __exportStar(require("./alchemy.js"), exports);
22
+ __exportStar(require("./cosmos.js"), exports);
@@ -0,0 +1,31 @@
1
+ import { ChainId } from '@injectivelabs/ts-types';
2
+ import { Msgs } from '@injectivelabs/sdk-ts';
3
+ export declare const createEip712StdSignDoc: ({ memo, chainId, accountNumber, timeoutHeight, sequence, gas, msgs, }: {
4
+ memo?: string;
5
+ chainId: ChainId;
6
+ timeoutHeight?: string;
7
+ accountNumber: number;
8
+ sequence: number;
9
+ gas?: string;
10
+ msgs: Msgs[];
11
+ }) => {
12
+ chain_id: ChainId;
13
+ timeout_height: string;
14
+ account_number: string;
15
+ sequence: string;
16
+ fee: {
17
+ amount: {
18
+ denom: string;
19
+ amount: string;
20
+ }[];
21
+ gas: string;
22
+ payer: string | undefined;
23
+ granter: string | undefined;
24
+ feePayer: string | undefined;
25
+ };
26
+ msgs: {
27
+ type: string;
28
+ value: any;
29
+ }[];
30
+ memo: string;
31
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createEip712StdSignDoc = void 0;
4
+ const utils_1 = require("@injectivelabs/utils");
5
+ const createEip712StdSignDoc = ({ memo, chainId, accountNumber, timeoutHeight, sequence, gas, msgs, }) => ({
6
+ chain_id: chainId,
7
+ timeout_height: timeoutHeight || '',
8
+ account_number: accountNumber.toString(),
9
+ sequence: sequence.toString(),
10
+ fee: (0, utils_1.getStdFee)({ gas }),
11
+ msgs: msgs.map((m) => m.toEip712()),
12
+ memo: memo || '',
13
+ });
14
+ exports.createEip712StdSignDoc = createEip712StdSignDoc;
@@ -0,0 +1,7 @@
1
+ import { Wallet } from './../types/enums.js';
2
+ export declare const isEvmWallet: (wallet: Wallet) => boolean;
3
+ export declare const isCosmosWallet: (wallet: Wallet) => boolean;
4
+ export declare const isEvmBrowserWallet: (wallet: Wallet) => boolean;
5
+ export declare const isCosmosBrowserWallet: (wallet: Wallet) => boolean;
6
+ export declare const isEip712V2OnlyWallet: (wallet: Wallet) => boolean;
7
+ export declare const isCosmosAminoOnlyWallet: (wallet: Wallet) => boolean;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCosmosAminoOnlyWallet = exports.isEip712V2OnlyWallet = exports.isCosmosBrowserWallet = exports.isEvmBrowserWallet = exports.isCosmosWallet = exports.isEvmWallet = void 0;
4
+ const enums_js_1 = require("./../types/enums.js");
5
+ const isEvmWallet = (wallet) => [
6
+ enums_js_1.Wallet.Magic,
7
+ enums_js_1.Wallet.BitGet,
8
+ enums_js_1.Wallet.Ledger,
9
+ enums_js_1.Wallet.TrezorBip32,
10
+ enums_js_1.Wallet.TrezorBip44,
11
+ enums_js_1.Wallet.Phantom,
12
+ enums_js_1.Wallet.Metamask,
13
+ enums_js_1.Wallet.OkxWallet,
14
+ enums_js_1.Wallet.PrivateKey,
15
+ enums_js_1.Wallet.TrustWallet,
16
+ enums_js_1.Wallet.LedgerLegacy,
17
+ enums_js_1.Wallet.WalletConnect,
18
+ enums_js_1.Wallet.CosmostationEth,
19
+ ].includes(wallet);
20
+ exports.isEvmWallet = isEvmWallet;
21
+ const isCosmosWallet = (wallet) => !(0, exports.isEvmWallet)(wallet);
22
+ exports.isCosmosWallet = isCosmosWallet;
23
+ const isEvmBrowserWallet = (wallet) => [
24
+ enums_js_1.Wallet.BitGet,
25
+ enums_js_1.Wallet.Phantom,
26
+ enums_js_1.Wallet.Metamask,
27
+ enums_js_1.Wallet.OkxWallet,
28
+ enums_js_1.Wallet.TrustWallet,
29
+ ].includes(wallet);
30
+ exports.isEvmBrowserWallet = isEvmBrowserWallet;
31
+ const isCosmosBrowserWallet = (wallet) => [
32
+ enums_js_1.Wallet.Leap,
33
+ enums_js_1.Wallet.Ninji,
34
+ enums_js_1.Wallet.Keplr,
35
+ enums_js_1.Wallet.OWallet,
36
+ enums_js_1.Wallet.Cosmostation,
37
+ ].includes(wallet);
38
+ exports.isCosmosBrowserWallet = isCosmosBrowserWallet;
39
+ const isEip712V2OnlyWallet = (wallet) => [
40
+ enums_js_1.Wallet.Magic,
41
+ enums_js_1.Wallet.Metamask,
42
+ enums_js_1.Wallet.Phantom,
43
+ enums_js_1.Wallet.WalletConnect,
44
+ ].includes(wallet);
45
+ exports.isEip712V2OnlyWallet = isEip712V2OnlyWallet;
46
+ const isCosmosAminoOnlyWallet = (wallet) => [enums_js_1.Wallet.LedgerCosmos].includes(wallet);
47
+ exports.isCosmosAminoOnlyWallet = isCosmosAminoOnlyWallet;
@@ -0,0 +1,8 @@
1
+ import { ChainId, CosmosChainId, EthereumChainId } from '@injectivelabs/ts-types';
2
+ import { WalletEventListener, ConcreteWalletStrategyArgs, ConcreteCosmosWalletStrategyArgs, ConcreteEthereumWalletStrategyArgs } from './types/index.js';
3
+ export default abstract class BaseConcreteStrategy {
4
+ protected chainId: ChainId | CosmosChainId;
5
+ protected ethereumChainId?: EthereumChainId;
6
+ protected listeners: Partial<Record<WalletEventListener, any>>;
7
+ protected constructor(args: ConcreteWalletStrategyArgs | ConcreteEthereumWalletStrategyArgs | ConcreteCosmosWalletStrategyArgs);
8
+ }
@@ -0,0 +1,11 @@
1
+ export default class BaseConcreteStrategy {
2
+ chainId;
3
+ ethereumChainId;
4
+ listeners = {};
5
+ constructor(args) {
6
+ this.ethereumChainId = 'ethereumOptions' in args && args.ethereumOptions
7
+ ? args.ethereumOptions.ethereumChainId
8
+ : undefined;
9
+ this.chainId = args.chainId;
10
+ }
11
+ }
@@ -0,0 +1,3 @@
1
+ export * from './types/index.js';
2
+ export * from './utils/index.js';
3
+ export { default as BaseConcreteStrategy } from './base.js';
@@ -0,0 +1,3 @@
1
+ export * from './types/index.js';
2
+ export * from './utils/index.js';
3
+ export { default as BaseConcreteStrategy } from './base.js';
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,52 @@
1
+ import { WalletErrorActionModule } from '@injectivelabs/exceptions';
2
+ export declare enum Wallet {
3
+ Leap = "leap",
4
+ Keplr = "keplr",
5
+ Ninji = "ninji",
6
+ Magic = "magic",
7
+ Ledger = "ledger",
8
+ BitGet = "BitGet",
9
+ OWallet = "owallet",
10
+ Phantom = "phantom",
11
+ Metamask = "metamask",
12
+ OkxWallet = "okx-wallet",
13
+ TrustWallet = "trust-wallet",
14
+ PrivateKey = "private-key",
15
+ TrezorBip32 = "trezor-bip32",
16
+ TrezorBip44 = "trezor-bip44",
17
+ Cosmostation = "cosmostation",
18
+ LedgerCosmos = "ledger-cosmos",
19
+ LedgerLegacy = "ledger-legacy",
20
+ WalletConnect = "wallet-connect",
21
+ CosmostationEth = "cosmostation-eth"
22
+ }
23
+ export declare enum MagicProvider {
24
+ Email = "email",
25
+ Apple = "apple",
26
+ Github = "github",
27
+ Google = "google",
28
+ Discord = "discord",
29
+ Twitter = "twitter",
30
+ Facebook = "facebook"
31
+ }
32
+ export declare enum WalletDeviceType {
33
+ Mobile = "mobile",
34
+ Other = "other",
35
+ Browser = "browser",
36
+ Hardware = "hardware"
37
+ }
38
+ export declare enum WalletEventListener {
39
+ AccountChange = "account-change",
40
+ ChainIdChange = "chain-id-change"
41
+ }
42
+ export declare const WalletAction: {
43
+ SignTransaction: WalletErrorActionModule.SignTransaction;
44
+ SignEthereumTransaction: WalletErrorActionModule.SignEthereumTransaction;
45
+ SendTransaction: WalletErrorActionModule.SendTransaction;
46
+ SendEthereumTransaction: WalletErrorActionModule.SendEthereumTransaction;
47
+ SignArbitrary: WalletErrorActionModule.SignArbitrary;
48
+ GetAccounts: WalletErrorActionModule.GetAccounts;
49
+ GetNetworkId: WalletErrorActionModule.GetNetworkId;
50
+ GetChainId: WalletErrorActionModule.GetChainId;
51
+ GetEthereumTransactionReceipt: WalletErrorActionModule.GetEthereumTransactionReceipt;
52
+ };
@@ -0,0 +1,46 @@
1
+ import { WalletErrorActionModule } from '@injectivelabs/exceptions';
2
+ export var Wallet;
3
+ (function (Wallet) {
4
+ Wallet["Leap"] = "leap";
5
+ Wallet["Keplr"] = "keplr";
6
+ Wallet["Ninji"] = "ninji";
7
+ Wallet["Magic"] = "magic";
8
+ Wallet["Ledger"] = "ledger";
9
+ Wallet["BitGet"] = "BitGet";
10
+ Wallet["OWallet"] = "owallet";
11
+ Wallet["Phantom"] = "phantom";
12
+ Wallet["Metamask"] = "metamask";
13
+ Wallet["OkxWallet"] = "okx-wallet";
14
+ Wallet["TrustWallet"] = "trust-wallet";
15
+ Wallet["PrivateKey"] = "private-key";
16
+ Wallet["TrezorBip32"] = "trezor-bip32";
17
+ Wallet["TrezorBip44"] = "trezor-bip44";
18
+ Wallet["Cosmostation"] = "cosmostation";
19
+ Wallet["LedgerCosmos"] = "ledger-cosmos";
20
+ Wallet["LedgerLegacy"] = "ledger-legacy";
21
+ Wallet["WalletConnect"] = "wallet-connect";
22
+ Wallet["CosmostationEth"] = "cosmostation-eth";
23
+ })(Wallet || (Wallet = {}));
24
+ export var MagicProvider;
25
+ (function (MagicProvider) {
26
+ MagicProvider["Email"] = "email";
27
+ MagicProvider["Apple"] = "apple";
28
+ MagicProvider["Github"] = "github";
29
+ MagicProvider["Google"] = "google";
30
+ MagicProvider["Discord"] = "discord";
31
+ MagicProvider["Twitter"] = "twitter";
32
+ MagicProvider["Facebook"] = "facebook";
33
+ })(MagicProvider || (MagicProvider = {}));
34
+ export var WalletDeviceType;
35
+ (function (WalletDeviceType) {
36
+ WalletDeviceType["Mobile"] = "mobile";
37
+ WalletDeviceType["Other"] = "other";
38
+ WalletDeviceType["Browser"] = "browser";
39
+ WalletDeviceType["Hardware"] = "hardware";
40
+ })(WalletDeviceType || (WalletDeviceType = {}));
41
+ export var WalletEventListener;
42
+ (function (WalletEventListener) {
43
+ WalletEventListener["AccountChange"] = "account-change";
44
+ WalletEventListener["ChainIdChange"] = "chain-id-change";
45
+ })(WalletEventListener || (WalletEventListener = {}));
46
+ export const WalletAction = { ...WalletErrorActionModule };
@@ -0,0 +1,3 @@
1
+ export * from './enums.js';
2
+ export * from './strategy.js';
3
+ export * from './provider.js';
@@ -0,0 +1,3 @@
1
+ export * from './enums.js';
2
+ export * from './strategy.js';
3
+ export * from './provider.js';
@@ -0,0 +1,21 @@
1
+ import { type EIP1193Provider } from 'eip1193-provider';
2
+ export interface BrowserEip1993Provider extends EIP1193Provider {
3
+ removeAllListeners(): void;
4
+ isMetaMask: boolean;
5
+ isTrustWallet: boolean;
6
+ isTrust: boolean;
7
+ isOkxWallet: boolean;
8
+ isPhantom: boolean;
9
+ }
10
+ export interface WindowWithEip1193Provider extends Window {
11
+ ethereum: BrowserEip1993Provider;
12
+ okxwallet: BrowserEip1993Provider;
13
+ bitkeep: {
14
+ ethereum: BrowserEip1993Provider;
15
+ };
16
+ providers: BrowserEip1993Provider[];
17
+ trustWallet?: BrowserEip1993Provider;
18
+ phantom?: {
19
+ ethereum?: BrowserEip1993Provider;
20
+ };
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,202 @@
1
+ import { ChainId, CosmosChainId, AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
2
+ import type { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
3
+ import { StdSignDoc } from '@keplr-wallet/types';
4
+ import { WalletDeviceType, Wallet } from './enums.js';
5
+ export type onAccountChangeCallback = (account: string | string[]) => void;
6
+ export type onChainIdChangeCallback = () => void;
7
+ export type CosmosWalletAbstraction = {
8
+ enableGasCheck?(chainId: ChainId): Promise<void> | void;
9
+ disableGasCheck?(chainId: ChainId): Promise<void> | void;
10
+ signEIP712CosmosTx(args: {
11
+ signDoc: StdSignDoc;
12
+ eip712: any;
13
+ }): Promise<AminoSignResponse>;
14
+ };
15
+ export type MagicMetadata = {
16
+ apiKey?: string;
17
+ rpcEndpoint?: string;
18
+ };
19
+ export type WalletConnectMetadata = Record<string, string | Record<string, string> | Record<string, string[]>>;
20
+ export interface WalletStrategyEthereumOptions {
21
+ ethereumChainId: EthereumChainId;
22
+ rpcUrl?: string;
23
+ }
24
+ export interface SendTransactionOptions {
25
+ address: string;
26
+ chainId: ChainId;
27
+ txTimeout?: number;
28
+ endpoints: {
29
+ rest: string;
30
+ grpc: string;
31
+ tm?: string;
32
+ };
33
+ }
34
+ export interface ConcreteWalletStrategyOptions {
35
+ privateKey?: string;
36
+ metadata?: Record<string, string | Record<string, string>>;
37
+ }
38
+ export interface ConcreteWalletStrategyArgs {
39
+ chainId: ChainId;
40
+ options?: ConcreteWalletStrategyOptions;
41
+ }
42
+ export interface ConcreteCosmosWalletStrategyArgs {
43
+ chainId: CosmosChainId | ChainId;
44
+ wallet?: Wallet;
45
+ options?: ConcreteWalletStrategyOptions;
46
+ }
47
+ export interface ConcreteEthereumWalletStrategyArgs extends ConcreteWalletStrategyArgs {
48
+ ethereumOptions: WalletStrategyEthereumOptions;
49
+ }
50
+ export interface ConcreteCosmosWalletStrategy {
51
+ /**
52
+ * The accounts from the wallet (addresses)
53
+ */
54
+ getAddresses(args?: unknown): Promise<string[]>;
55
+ /**
56
+ * Return the WalletDeviceType connected on the
57
+ * wallet provider (extension, mobile, hardware wallet)
58
+ */
59
+ getWalletDeviceType(): Promise<WalletDeviceType>;
60
+ /**
61
+ * Get the PubKey from the wallet
62
+ * in base64 for Cosmos native wallets
63
+ */
64
+ getPubKey(address?: string): Promise<string>;
65
+ /**
66
+ * Perform validations and checks
67
+ * for the wallet (if the chain is supported, etc)
68
+ */
69
+ enable(args?: unknown): Promise<boolean>;
70
+ /**
71
+ * Sends Cosmos transaction. Returns a transaction hash
72
+ * @param transaction should implement TransactionConfig
73
+ * @param options
74
+ */
75
+ sendTransaction(transaction: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
76
+ signCosmosTransaction(transaction: {
77
+ txRaw: TxRaw;
78
+ chainId: string;
79
+ accountNumber: number;
80
+ address: string;
81
+ }): Promise<DirectSignResponse>;
82
+ signAminoTransaction(transaction: {
83
+ stdSignDoc: StdSignDoc;
84
+ address: string;
85
+ }): Promise<AminoSignResponse>;
86
+ }
87
+ export type ConcreteStrategiesArg = {
88
+ [key in Wallet]?: ConcreteWalletStrategy;
89
+ };
90
+ export interface WalletStrategyArguments {
91
+ chainId: ChainId;
92
+ options?: ConcreteWalletStrategyOptions;
93
+ ethereumOptions?: WalletStrategyEthereumOptions;
94
+ disabledWallets?: Wallet[];
95
+ wallet?: Wallet;
96
+ strategies: ConcreteStrategiesArg;
97
+ }
98
+ export interface ConcreteWalletStrategy extends Omit<ConcreteCosmosWalletStrategy, 'sendTransaction' | 'isChainIdSupported' | 'signAminoTransaction'> {
99
+ /**
100
+ * Sends Cosmos transaction. Returns a transaction hash
101
+ * @param transaction should implement TransactionConfig
102
+ * @param options
103
+ */
104
+ sendTransaction(transaction: DirectSignResponse | TxRaw, options: {
105
+ address: string;
106
+ chainId: ChainId;
107
+ txTimeout?: number;
108
+ endpoints?: {
109
+ rest: string;
110
+ grpc: string;
111
+ tm?: string;
112
+ };
113
+ }): Promise<TxResponse>;
114
+ /**
115
+ * Confirm the address on the wallet
116
+ * @param address address
117
+ */
118
+ getSessionOrConfirm(address?: string): Promise<string>;
119
+ /**
120
+ * Sends Ethereum transaction. Returns a transaction hash
121
+ * @param transaction should implement TransactionConfig
122
+ * @param options
123
+ */
124
+ sendEthereumTransaction(transaction: unknown, options: {
125
+ address: string;
126
+ ethereumChainId: EthereumChainId;
127
+ }): Promise<string>;
128
+ /**
129
+ * Sign a cosmos transaction using the wallet provider
130
+ *
131
+ * @param transaction
132
+ * @param address - injective address
133
+ */
134
+ signCosmosTransaction(transaction: {
135
+ txRaw: TxRaw;
136
+ accountNumber: number;
137
+ chainId: string;
138
+ address: string;
139
+ }): Promise<DirectSignResponse>;
140
+ /**
141
+ * Sign an amino sign doc using the wallet provider
142
+ *
143
+ * @param transaction
144
+ * @param address - injective address
145
+ */
146
+ signAminoCosmosTransaction(transaction: {
147
+ signDoc: StdSignDoc;
148
+ address: string;
149
+ }): Promise<AminoSignResponse>;
150
+ /**
151
+ * Sign EIP712 TypedData using the wallet provider
152
+ * @param eip712TypedData
153
+ * @param address - ethereum address
154
+ */
155
+ signEip712TypedData(eip712TypedData: string, address: string): Promise<string>;
156
+ signArbitrary(signer: string, data: string | Uint8Array): Promise<string>;
157
+ getEthereumChainId(): Promise<string>;
158
+ getEthereumTransactionReceipt(txHash: string): void;
159
+ onAccountChange?(callback: onAccountChangeCallback): Promise<void> | void;
160
+ onChainIdChange?(callback: onChainIdChangeCallback): Promise<void> | void;
161
+ disconnect?(): Promise<void> | void;
162
+ getCosmosWallet?(chainId: ChainId): CosmosWalletAbstraction;
163
+ }
164
+ export interface WalletStrategy {
165
+ strategies: ConcreteStrategiesArg;
166
+ wallet: Wallet;
167
+ args: WalletStrategyArguments;
168
+ getWallet(): Wallet;
169
+ setWallet(wallet: Wallet): void;
170
+ setOptions(options?: ConcreteWalletStrategyOptions): void;
171
+ getStrategy(): ConcreteWalletStrategy;
172
+ getAddresses(args?: unknown): Promise<AccountAddress[]>;
173
+ getWalletDeviceType(): Promise<WalletDeviceType>;
174
+ getPubKey(address?: string): Promise<string>;
175
+ enable(args?: unknown): Promise<boolean>;
176
+ enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]>;
177
+ getEthereumChainId(): Promise<string>;
178
+ getEthereumTransactionReceipt(txHash: string): Promise<void>;
179
+ getSessionOrConfirm(address?: AccountAddress): Promise<string>;
180
+ sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
181
+ sendEthereumTransaction(tx: any, options: {
182
+ address: AccountAddress;
183
+ ethereumChainId: EthereumChainId;
184
+ }): Promise<string>;
185
+ signEip712TypedData(eip712TypedData: string, address: AccountAddress): Promise<string>;
186
+ signAminoCosmosTransaction(transaction: {
187
+ signDoc: StdSignDoc;
188
+ address: string;
189
+ }): Promise<AminoSignResponse>;
190
+ signCosmosTransaction(transaction: {
191
+ txRaw: TxRaw;
192
+ accountNumber: number;
193
+ chainId: string;
194
+ address: string;
195
+ }): Promise<DirectSignResponse>;
196
+ signArbitrary(signer: string, data: string | Uint8Array): Promise<string | void>;
197
+ onAccountChange(callback: onAccountChangeCallback): Promise<void>;
198
+ onChainIdChange(callback: onChainIdChangeCallback): Promise<void>;
199
+ disconnect(): Promise<void>;
200
+ getCosmosWallet?(chainId: ChainId): CosmosWalletAbstraction;
201
+ }
202
+ export { StdSignDoc };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const getInjectiveSignerAddress: (address: string | undefined) => string;
2
+ export declare const getEthereumSignerAddress: (address: string | undefined) => string;
@@ -0,0 +1,25 @@
1
+ import { getEthereumAddress, getInjectiveAddress } from '@injectivelabs/sdk-ts';
2
+ export const getInjectiveSignerAddress = (address) => {
3
+ if (!address) {
4
+ return '';
5
+ }
6
+ if (address.startsWith('inj')) {
7
+ return address;
8
+ }
9
+ if (address.startsWith('0x')) {
10
+ return getInjectiveAddress(address);
11
+ }
12
+ return '';
13
+ };
14
+ export const getEthereumSignerAddress = (address) => {
15
+ if (!address) {
16
+ return '';
17
+ }
18
+ if (address.startsWith('0x')) {
19
+ return address;
20
+ }
21
+ if (address.startsWith('inj')) {
22
+ return getEthereumAddress(address);
23
+ }
24
+ return '';
25
+ };
@@ -0,0 +1 @@
1
+ export declare const getKeyFromRpcUrl: (rpcUrl: string) => string;
@@ -0,0 +1,7 @@
1
+ export const getKeyFromRpcUrl = (rpcUrl) => {
2
+ if (!rpcUrl.includes('alchemyapi.io') && !rpcUrl.includes('alchemy.com')) {
3
+ return rpcUrl;
4
+ }
5
+ const [key] = rpcUrl.split('/').reverse();
6
+ return key;
7
+ };
@@ -0,0 +1,6 @@
1
+ import { BigNumber, BigNumberInBase } from '@injectivelabs/utils';
2
+ export declare const GWEI_IN_WEI: BigNumber;
3
+ export declare const TIP_IN_GWEI: BigNumberInBase;
4
+ export declare const DEFAULT_BASE_DERIVATION_PATH = "m/44'/60'";
5
+ export declare const DEFAULT_NUM_ADDRESSES_TO_FETCH = 5;
6
+ export declare const DEFAULT_ADDRESS_SEARCH_LIMIT = 100;
@@ -0,0 +1,6 @@
1
+ import { BigNumber, BigNumberInBase } from '@injectivelabs/utils';
2
+ export const GWEI_IN_WEI = new BigNumber(1000000000);
3
+ export const TIP_IN_GWEI = new BigNumberInBase(2).times(GWEI_IN_WEI);
4
+ export const DEFAULT_BASE_DERIVATION_PATH = "m/44'/60'";
5
+ export const DEFAULT_NUM_ADDRESSES_TO_FETCH = 5;
6
+ export const DEFAULT_ADDRESS_SEARCH_LIMIT = 100;
@@ -0,0 +1,2 @@
1
+ import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts';
2
+ export declare const createCosmosSignDocFromSignDoc: (signDoc: CosmosTxV1Beta1Tx.SignDoc) => any;
@@ -0,0 +1,9 @@
1
+ import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts';
2
+ export const createCosmosSignDocFromSignDoc = (signDoc) => {
3
+ return CosmosTxV1Beta1Tx.SignDoc.fromPartial({
4
+ bodyBytes: signDoc.bodyBytes,
5
+ authInfoBytes: signDoc.authInfoBytes,
6
+ accountNumber: BigInt(signDoc.accountNumber).toString(),
7
+ chainId: signDoc.chainId,
8
+ });
9
+ };
@@ -0,0 +1,6 @@
1
+ export * from './address.js';
2
+ export * from './tx.js';
3
+ export * from './wallet.js';
4
+ export * from './constants.js';
5
+ export * from './alchemy.js';
6
+ export * from './cosmos.js';
@@ -0,0 +1,6 @@
1
+ export * from './address.js';
2
+ export * from './tx.js';
3
+ export * from './wallet.js';
4
+ export * from './constants.js';
5
+ export * from './alchemy.js';
6
+ export * from './cosmos.js';
@@ -0,0 +1,31 @@
1
+ import { ChainId } from '@injectivelabs/ts-types';
2
+ import { Msgs } from '@injectivelabs/sdk-ts';
3
+ export declare const createEip712StdSignDoc: ({ memo, chainId, accountNumber, timeoutHeight, sequence, gas, msgs, }: {
4
+ memo?: string;
5
+ chainId: ChainId;
6
+ timeoutHeight?: string;
7
+ accountNumber: number;
8
+ sequence: number;
9
+ gas?: string;
10
+ msgs: Msgs[];
11
+ }) => {
12
+ chain_id: ChainId;
13
+ timeout_height: string;
14
+ account_number: string;
15
+ sequence: string;
16
+ fee: {
17
+ amount: {
18
+ denom: string;
19
+ amount: string;
20
+ }[];
21
+ gas: string;
22
+ payer: string | undefined;
23
+ granter: string | undefined;
24
+ feePayer: string | undefined;
25
+ };
26
+ msgs: {
27
+ type: string;
28
+ value: any;
29
+ }[];
30
+ memo: string;
31
+ };
@@ -0,0 +1,10 @@
1
+ import { getStdFee } from '@injectivelabs/utils';
2
+ export const createEip712StdSignDoc = ({ memo, chainId, accountNumber, timeoutHeight, sequence, gas, msgs, }) => ({
3
+ chain_id: chainId,
4
+ timeout_height: timeoutHeight || '',
5
+ account_number: accountNumber.toString(),
6
+ sequence: sequence.toString(),
7
+ fee: getStdFee({ gas }),
8
+ msgs: msgs.map((m) => m.toEip712()),
9
+ memo: memo || '',
10
+ });
@@ -0,0 +1,7 @@
1
+ import { Wallet } from './../types/enums.js';
2
+ export declare const isEvmWallet: (wallet: Wallet) => boolean;
3
+ export declare const isCosmosWallet: (wallet: Wallet) => boolean;
4
+ export declare const isEvmBrowserWallet: (wallet: Wallet) => boolean;
5
+ export declare const isCosmosBrowserWallet: (wallet: Wallet) => boolean;
6
+ export declare const isEip712V2OnlyWallet: (wallet: Wallet) => boolean;
7
+ export declare const isCosmosAminoOnlyWallet: (wallet: Wallet) => boolean;
@@ -0,0 +1,38 @@
1
+ import { Wallet } from './../types/enums.js';
2
+ export const isEvmWallet = (wallet) => [
3
+ Wallet.Magic,
4
+ Wallet.BitGet,
5
+ Wallet.Ledger,
6
+ Wallet.TrezorBip32,
7
+ Wallet.TrezorBip44,
8
+ Wallet.Phantom,
9
+ Wallet.Metamask,
10
+ Wallet.OkxWallet,
11
+ Wallet.PrivateKey,
12
+ Wallet.TrustWallet,
13
+ Wallet.LedgerLegacy,
14
+ Wallet.WalletConnect,
15
+ Wallet.CosmostationEth,
16
+ ].includes(wallet);
17
+ export const isCosmosWallet = (wallet) => !isEvmWallet(wallet);
18
+ export const isEvmBrowserWallet = (wallet) => [
19
+ Wallet.BitGet,
20
+ Wallet.Phantom,
21
+ Wallet.Metamask,
22
+ Wallet.OkxWallet,
23
+ Wallet.TrustWallet,
24
+ ].includes(wallet);
25
+ export const isCosmosBrowserWallet = (wallet) => [
26
+ Wallet.Leap,
27
+ Wallet.Ninji,
28
+ Wallet.Keplr,
29
+ Wallet.OWallet,
30
+ Wallet.Cosmostation,
31
+ ].includes(wallet);
32
+ export const isEip712V2OnlyWallet = (wallet) => [
33
+ Wallet.Magic,
34
+ Wallet.Metamask,
35
+ Wallet.Phantom,
36
+ Wallet.WalletConnect,
37
+ ].includes(wallet);
38
+ export const isCosmosAminoOnlyWallet = (wallet) => [Wallet.LedgerCosmos].includes(wallet);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-base",
3
3
  "description": "Base wallet strategy for use with @injectivelabs/wallet-core.",
4
- "version": "1.15.0",
4
+ "version": "1.15.2",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -56,14 +56,14 @@
56
56
  "start": "node dist/index.js"
57
57
  },
58
58
  "dependencies": {
59
- "@injectivelabs/exceptions": "^1.15.0",
60
- "@injectivelabs/networks": "^1.15.0",
61
- "@injectivelabs/sdk-ts": "^1.15.0",
62
- "@injectivelabs/ts-types": "^1.15.0",
59
+ "@injectivelabs/exceptions": "^1.15.1",
60
+ "@injectivelabs/networks": "^1.15.2",
61
+ "@injectivelabs/sdk-ts": "^1.15.2",
62
+ "@injectivelabs/ts-types": "^1.15.2",
63
63
  "eip1193-provider": "^1.0.1"
64
64
  },
65
65
  "devDependencies": {
66
66
  "shx": "^0.3.3"
67
67
  },
68
- "gitHead": "acae5b41a4c8a0ac4f137cce434b9db81800a1c5"
68
+ "gitHead": "64a57f3115b63114124d0d1fb61f75e520905499"
69
69
  }