@injectivelabs/wallet-core 1.16.24 → 1.16.25-alpha.1

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 (41) hide show
  1. package/dist/cjs/index.cjs +1007 -0
  2. package/dist/cjs/index.d.cts +281 -0
  3. package/dist/cjs/package.json +2 -2
  4. package/dist/esm/index.d.ts +281 -3
  5. package/dist/esm/index.js +1003 -3
  6. package/dist/esm/package.json +2 -2
  7. package/package.json +19 -19
  8. package/dist/cjs/broadcaster/MsgBroadcaster.d.ts +0 -137
  9. package/dist/cjs/broadcaster/MsgBroadcaster.js +0 -918
  10. package/dist/cjs/broadcaster/Web3Broadcaster.d.ts +0 -30
  11. package/dist/cjs/broadcaster/Web3Broadcaster.js +0 -32
  12. package/dist/cjs/broadcaster/index.d.ts +0 -3
  13. package/dist/cjs/broadcaster/index.js +0 -19
  14. package/dist/cjs/broadcaster/types.d.ts +0 -56
  15. package/dist/cjs/broadcaster/types.js +0 -13
  16. package/dist/cjs/index.d.ts +0 -3
  17. package/dist/cjs/index.js +0 -19
  18. package/dist/cjs/strategy/BaseWalletStrategy.d.ts +0 -58
  19. package/dist/cjs/strategy/BaseWalletStrategy.js +0 -176
  20. package/dist/cjs/strategy/index.d.ts +0 -2
  21. package/dist/cjs/strategy/index.js +0 -8
  22. package/dist/cjs/utils/index.d.ts +0 -1
  23. package/dist/cjs/utils/index.js +0 -17
  24. package/dist/cjs/utils/tx.d.ts +0 -1
  25. package/dist/cjs/utils/tx.js +0 -11
  26. package/dist/esm/broadcaster/MsgBroadcaster.d.ts +0 -137
  27. package/dist/esm/broadcaster/MsgBroadcaster.js +0 -914
  28. package/dist/esm/broadcaster/Web3Broadcaster.d.ts +0 -30
  29. package/dist/esm/broadcaster/Web3Broadcaster.js +0 -28
  30. package/dist/esm/broadcaster/index.d.ts +0 -3
  31. package/dist/esm/broadcaster/index.js +0 -3
  32. package/dist/esm/broadcaster/types.d.ts +0 -56
  33. package/dist/esm/broadcaster/types.js +0 -10
  34. package/dist/esm/strategy/BaseWalletStrategy.d.ts +0 -58
  35. package/dist/esm/strategy/BaseWalletStrategy.js +0 -173
  36. package/dist/esm/strategy/index.d.ts +0 -2
  37. package/dist/esm/strategy/index.js +0 -2
  38. package/dist/esm/utils/index.d.ts +0 -1
  39. package/dist/esm/utils/index.js +0 -1
  40. package/dist/esm/utils/tx.d.ts +0 -1
  41. package/dist/esm/utils/tx.js +0 -7
@@ -1,30 +0,0 @@
1
- import type { Network } from '@injectivelabs/networks';
2
- import type { EvmChainId } from '@injectivelabs/ts-types';
3
- import type BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
4
- interface SendTransactionOptions {
5
- tx: {
6
- from: string;
7
- to: string;
8
- gas: string;
9
- maxFeePerGas: string;
10
- maxPriorityFeePerGas: string | null;
11
- data: any;
12
- };
13
- address: string;
14
- evmChainId?: EvmChainId;
15
- }
16
- /**
17
- * Preparing and broadcasting
18
- * Ethereum transactions
19
- */
20
- export declare class Web3Broadcaster {
21
- private walletStrategy;
22
- private evmChainId;
23
- constructor({ walletStrategy, evmChainId, }: {
24
- walletStrategy: BaseWalletStrategy;
25
- evmChainId: EvmChainId;
26
- network: Network;
27
- });
28
- sendTransaction(args: SendTransactionOptions): Promise<string>;
29
- }
30
- export {};
@@ -1,28 +0,0 @@
1
- import { Web3Exception } from '@injectivelabs/exceptions';
2
- /**
3
- * Preparing and broadcasting
4
- * Ethereum transactions
5
- */
6
- export class Web3Broadcaster {
7
- walletStrategy;
8
- evmChainId;
9
- constructor({ walletStrategy, evmChainId, }) {
10
- this.evmChainId = evmChainId;
11
- this.walletStrategy = walletStrategy;
12
- }
13
- async sendTransaction(args) {
14
- const { evmChainId, walletStrategy } = this;
15
- try {
16
- const chainId = args.evmChainId || evmChainId;
17
- const txHash = await walletStrategy.sendEvmTransaction(args.tx, {
18
- evmChainId: chainId,
19
- address: args.address,
20
- });
21
- await walletStrategy.getEvmTransactionReceipt(txHash, chainId);
22
- return txHash;
23
- }
24
- catch (e) {
25
- throw new Web3Exception(new Error(e.message));
26
- }
27
- }
28
- }
@@ -1,3 +0,0 @@
1
- export * from './MsgBroadcaster.js';
2
- export * from './Web3Broadcaster.js';
3
- export * from './types.js';
@@ -1,3 +0,0 @@
1
- export * from './MsgBroadcaster.js';
2
- export * from './Web3Broadcaster.js';
3
- export * from './types.js';
@@ -1,56 +0,0 @@
1
- import type { EventEmitter } from 'eventemitter3';
2
- import type { Msgs } from '@injectivelabs/sdk-ts';
3
- import type { ChainId, EvmChainId } from '@injectivelabs/ts-types';
4
- import type BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
5
- import type { Network, NetworkEndpoints } from '@injectivelabs/networks';
6
- export interface MsgBroadcasterTxOptions {
7
- memo?: string;
8
- ethereumAddress?: string;
9
- injectiveAddress?: string;
10
- msgs: Msgs | Msgs[];
11
- gas?: {
12
- gasPrice?: string;
13
- gas?: number; /** gas limit */
14
- feePayer?: string;
15
- granter?: string;
16
- };
17
- }
18
- export interface MsgBroadcasterTxOptionsWithAddresses extends MsgBroadcasterTxOptions {
19
- ethereumAddress: string;
20
- injectiveAddress: string;
21
- }
22
- export interface MsgBroadcasterOptions {
23
- network: Network;
24
- endpoints?: NetworkEndpoints;
25
- chainId?: ChainId;
26
- evmChainId?: EvmChainId;
27
- feePayerPubKey?: string;
28
- simulateTx?: boolean;
29
- txTimeoutOnFeeDelegation?: boolean;
30
- txTimeout?: number;
31
- walletStrategy: BaseWalletStrategy;
32
- gasBufferCoefficient?: number;
33
- httpHeaders?: Record<string, string>;
34
- }
35
- export declare const WalletStrategyEmitterEventType: {
36
- readonly TransactionFail: "transaction-fail";
37
- readonly TransactionSigned: "transaction-signed";
38
- readonly TransactionSignStart: "transaction-sign-start";
39
- readonly TransactionBroadcastEnd: "transaction-broadcast-end";
40
- readonly WalletStrategyDisconnect: "wallet-strategy-disconnect";
41
- readonly TransactionBroadcastStart: "transaction-broadcast-start";
42
- readonly TransactionPreparationEnd: "transaction-preparation-end";
43
- readonly TransactionPreparationStart: "transaction-preparation-start";
44
- };
45
- export type WalletStrategyEmitterEventType = (typeof WalletStrategyEmitterEventType)[keyof typeof WalletStrategyEmitterEventType];
46
- export type WalletStrategyEmitterEvents = {
47
- [WalletStrategyEmitterEventType.TransactionFail]: Record<string, any>;
48
- [WalletStrategyEmitterEventType.TransactionSigned]: Record<string, any>;
49
- [WalletStrategyEmitterEventType.TransactionSignStart]: Record<string, any>;
50
- [WalletStrategyEmitterEventType.TransactionBroadcastEnd]: Record<string, any>;
51
- [WalletStrategyEmitterEventType.WalletStrategyDisconnect]: Record<string, any>;
52
- [WalletStrategyEmitterEventType.TransactionBroadcastStart]: Record<string, any>;
53
- [WalletStrategyEmitterEventType.TransactionPreparationEnd]: Record<string, any>;
54
- [WalletStrategyEmitterEventType.TransactionPreparationStart]: Record<string, any>;
55
- };
56
- export type WalletStrategyEmitter = EventEmitter<WalletStrategyEmitterEvents>;
@@ -1,10 +0,0 @@
1
- export const WalletStrategyEmitterEventType = {
2
- TransactionFail: 'transaction-fail',
3
- TransactionSigned: 'transaction-signed',
4
- TransactionSignStart: 'transaction-sign-start',
5
- TransactionBroadcastEnd: 'transaction-broadcast-end',
6
- WalletStrategyDisconnect: 'wallet-strategy-disconnect',
7
- TransactionBroadcastStart: 'transaction-broadcast-start',
8
- TransactionPreparationEnd: 'transaction-preparation-end',
9
- TransactionPreparationStart: 'transaction-preparation-start',
10
- };
@@ -1,58 +0,0 @@
1
- import { Wallet, type WalletMetadata } from '@injectivelabs/wallet-base';
2
- import type { StdSignDoc } from '@keplr-wallet/types';
3
- import type { OfflineSigner } from '@cosmjs/proto-signing';
4
- import type { AccountAddress } from '@injectivelabs/ts-types';
5
- import type { ChainId, EvmChainId } from '@injectivelabs/ts-types';
6
- import type { WalletStrategyEmitter } from '../broadcaster/types.js';
7
- import type { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
8
- import type { Eip1193Provider, WalletDeviceType, ConcreteStrategiesArg, SendTransactionOptions, ConcreteWalletStrategy, onAccountChangeCallback, onChainIdChangeCallback, WalletStrategyArguments, CosmosWalletAbstraction, WalletStrategy as WalletStrategyInterface } from '@injectivelabs/wallet-base';
9
- export default class BaseWalletStrategy implements WalletStrategyInterface {
10
- strategies: ConcreteStrategiesArg;
11
- wallet: Wallet;
12
- args: WalletStrategyArguments;
13
- metadata?: WalletMetadata;
14
- wallets?: Wallet[];
15
- private emitter;
16
- on: WalletStrategyEmitter['on'];
17
- off: WalletStrategyEmitter['off'];
18
- emit: WalletStrategyEmitter['emit'];
19
- constructor(args: WalletStrategyArguments);
20
- getWallet(): Wallet;
21
- setWallet(wallet: Wallet): void;
22
- setMetadata(metadata?: WalletMetadata): void;
23
- getStrategy(): ConcreteWalletStrategy;
24
- getAddresses(args?: unknown): Promise<AccountAddress[]>;
25
- getWalletDeviceType(): Promise<WalletDeviceType>;
26
- getPubKey(address?: string): Promise<string>;
27
- enable(args?: unknown): Promise<boolean>;
28
- enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]>;
29
- getEthereumChainId(): Promise<string>;
30
- getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<void>;
31
- getSessionOrConfirm(address?: AccountAddress): Promise<string>;
32
- getWalletClient<T>(): Promise<T>;
33
- sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
34
- sendEvmTransaction(tx: any, options: {
35
- evmChainId: EvmChainId;
36
- address: AccountAddress;
37
- }): Promise<string>;
38
- signEip712TypedData(eip712TypedData: string, address: AccountAddress, options?: {
39
- txTimeout?: number;
40
- }): Promise<string>;
41
- signAminoCosmosTransaction(transaction: {
42
- signDoc: StdSignDoc;
43
- address: string;
44
- }): Promise<AminoSignResponse>;
45
- signCosmosTransaction(transaction: {
46
- txRaw: TxRaw;
47
- accountNumber: number;
48
- chainId: string;
49
- address: string;
50
- }): Promise<DirectSignResponse>;
51
- signArbitrary(signer: string, data: string | Uint8Array): Promise<string | void>;
52
- onAccountChange(callback: onAccountChangeCallback): Promise<void>;
53
- onChainIdChange(callback: onChainIdChangeCallback): Promise<void>;
54
- disconnect(): Promise<void>;
55
- getCosmosWallet(chainId: ChainId): CosmosWalletAbstraction;
56
- getEip1193Provider(): Promise<Eip1193Provider>;
57
- getOfflineSigner(chainId: string): Promise<OfflineSigner>;
58
- }
@@ -1,173 +0,0 @@
1
- import { EventEmitter } from 'eventemitter3';
2
- import { GeneralException, WalletException } from '@injectivelabs/exceptions';
3
- import { Wallet, isEvmWallet, isCosmosWallet, } from '@injectivelabs/wallet-base';
4
- import { WalletStrategyEmitterEventType } from '../broadcaster/types.js';
5
- const getInitialWallet = (args) => {
6
- if (args.wallet) {
7
- return args.wallet;
8
- }
9
- const keys = Object.keys(args.strategies || {});
10
- if (keys.length === 0) {
11
- return Wallet.Metamask;
12
- }
13
- if (keys.includes(Wallet.Metamask) && args.evmOptions) {
14
- return Wallet.Metamask;
15
- }
16
- if (keys.includes(Wallet.Keplr) && !args.evmOptions) {
17
- return Wallet.Keplr;
18
- }
19
- return keys[0];
20
- };
21
- export default class BaseWalletStrategy {
22
- strategies;
23
- wallet;
24
- args;
25
- metadata;
26
- wallets;
27
- emitter;
28
- on;
29
- off;
30
- emit;
31
- constructor(args) {
32
- this.args = args;
33
- this.strategies = args.strategies;
34
- this.wallet = getInitialWallet(args);
35
- this.metadata = args.metadata;
36
- this.emitter = new EventEmitter();
37
- this.on = this.emitter.on.bind(this.emitter);
38
- this.off = this.emitter.off.bind(this.emitter);
39
- this.emit = this.emitter.emit.bind(this.emitter);
40
- }
41
- getWallet() {
42
- return this.wallet;
43
- }
44
- setWallet(wallet) {
45
- this.wallet = wallet;
46
- this.getStrategy();
47
- }
48
- setMetadata(metadata) {
49
- console.log('Setting metadata', metadata);
50
- this.metadata = metadata;
51
- this.getStrategy().setMetadata?.(metadata);
52
- }
53
- getStrategy() {
54
- if (!this.strategies[this.wallet]) {
55
- throw new GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
56
- }
57
- return this.strategies[this.wallet];
58
- }
59
- getAddresses(args) {
60
- return this.getStrategy().getAddresses(args);
61
- }
62
- getWalletDeviceType() {
63
- return this.getStrategy().getWalletDeviceType();
64
- }
65
- getPubKey(address) {
66
- return this.getStrategy().getPubKey(address);
67
- }
68
- enable(args) {
69
- return this.getStrategy().enable(args);
70
- }
71
- async enableAndGetAddresses(args) {
72
- await this.getStrategy().enable(args);
73
- return this.getStrategy().getAddresses(args);
74
- }
75
- getEthereumChainId() {
76
- return this.getStrategy().getEthereumChainId();
77
- }
78
- async getEvmTransactionReceipt(txHash, evmChainId) {
79
- return this.getStrategy().getEvmTransactionReceipt(txHash, evmChainId);
80
- }
81
- async getSessionOrConfirm(address) {
82
- return this.getStrategy().getSessionOrConfirm(address);
83
- }
84
- async getWalletClient() {
85
- if (this.getStrategy()?.getWalletClient) {
86
- const result = (this.getStrategy()?.getWalletClient)?.();
87
- if (result) {
88
- return result;
89
- }
90
- }
91
- throw new WalletException(new Error('Wallet client not found. Please check your wallet strategy.'));
92
- }
93
- async sendTransaction(tx, options) {
94
- return this.getStrategy().sendTransaction(tx, options);
95
- }
96
- async sendEvmTransaction(tx /* TODO */, options) {
97
- return this.getStrategy().sendEvmTransaction(tx, options);
98
- }
99
- async signEip712TypedData(eip712TypedData, address, options = {}) {
100
- if (isCosmosWallet(this.wallet)) {
101
- throw new WalletException(new Error(`You can't sign Ethereum Transaction using ${this.wallet}`));
102
- }
103
- /** Phantom wallet needs enabling before signing */
104
- if (this.wallet === Wallet.Phantom) {
105
- await this.enable();
106
- }
107
- this.emit(WalletStrategyEmitterEventType.TransactionSignStart);
108
- const response = await this.getStrategy().signEip712TypedData(eip712TypedData, address, options);
109
- this.emit(WalletStrategyEmitterEventType.TransactionSigned);
110
- return response;
111
- }
112
- async signAminoCosmosTransaction(transaction) {
113
- if (isEvmWallet(this.wallet)) {
114
- throw new WalletException(new Error(`You can't sign Cosmos Transaction using ${this.wallet}`));
115
- }
116
- this.emit(WalletStrategyEmitterEventType.TransactionSignStart);
117
- const response = await this.getStrategy().signAminoCosmosTransaction(transaction);
118
- this.emit(WalletStrategyEmitterEventType.TransactionSigned);
119
- return response;
120
- }
121
- async signCosmosTransaction(transaction) {
122
- if (isEvmWallet(this.wallet)) {
123
- throw new WalletException(new Error(`You can't sign Cosmos Transaction using ${this.wallet}`));
124
- }
125
- this.emit(WalletStrategyEmitterEventType.TransactionSignStart);
126
- const response = await this.getStrategy().signCosmosTransaction(transaction);
127
- this.emit(WalletStrategyEmitterEventType.TransactionSigned);
128
- return response;
129
- }
130
- async signArbitrary(signer, data) {
131
- if (this.getStrategy().signArbitrary) {
132
- this.emit(WalletStrategyEmitterEventType.TransactionSignStart);
133
- const response = await this.getStrategy().signArbitrary(signer, data);
134
- this.emit(WalletStrategyEmitterEventType.TransactionSigned);
135
- return response;
136
- }
137
- }
138
- async onAccountChange(callback) {
139
- if (this.getStrategy().onAccountChange) {
140
- return this.getStrategy().onAccountChange(callback);
141
- }
142
- }
143
- async onChainIdChange(callback) {
144
- if (this.getStrategy().onChainIdChange) {
145
- return this.getStrategy().onChainIdChange(callback);
146
- }
147
- }
148
- async disconnect() {
149
- if (this.getStrategy().disconnect) {
150
- await this.getStrategy().disconnect();
151
- this.emit(WalletStrategyEmitterEventType.WalletStrategyDisconnect);
152
- }
153
- }
154
- getCosmosWallet(chainId) {
155
- const strategy = this.getStrategy();
156
- if (strategy.getCosmosWallet == undefined) {
157
- throw new WalletException(new Error(`This method is not available for ${this.getWallet()} wallet`));
158
- }
159
- return strategy.getCosmosWallet(chainId);
160
- }
161
- async getEip1193Provider() {
162
- if (this.getStrategy().getEip1193Provider) {
163
- return this.getStrategy().getEip1193Provider();
164
- }
165
- throw new WalletException(new Error('EIP1193 provider not found. Please check your wallet strategy.'));
166
- }
167
- async getOfflineSigner(chainId) {
168
- if (this.getStrategy().getOfflineSigner) {
169
- return this.getStrategy().getOfflineSigner(chainId);
170
- }
171
- throw new WalletException(new Error('Offline signer not found. Please check your wallet strategy.'));
172
- }
173
- }
@@ -1,2 +0,0 @@
1
- import BaseWalletStrategy from './BaseWalletStrategy.js';
2
- export { BaseWalletStrategy };
@@ -1,2 +0,0 @@
1
- import BaseWalletStrategy from './BaseWalletStrategy.js';
2
- export { BaseWalletStrategy };
@@ -1 +0,0 @@
1
- export * from './tx.js';
@@ -1 +0,0 @@
1
- export * from './tx.js';
@@ -1 +0,0 @@
1
- export declare const checkIfTxRunOutOfGas: (e: unknown) => boolean;
@@ -1,7 +0,0 @@
1
- import { TransactionException, ChainCosmosErrorCode, TransactionChainErrorModule, } from '@injectivelabs/exceptions';
2
- export const checkIfTxRunOutOfGas = (e) => {
3
- return (e instanceof TransactionException &&
4
- e.contextCode === ChainCosmosErrorCode.ErrOutOfGas &&
5
- e.contextModule === TransactionChainErrorModule.CosmosSdk &&
6
- e.originalMessage.includes('out of gas'));
7
- };