@injectivelabs/wallet-core 1.16.25-alpha.1 → 1.16.26
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/dist/cjs/broadcaster/MsgBroadcaster.d.ts +137 -0
- package/dist/cjs/broadcaster/MsgBroadcaster.js +918 -0
- package/dist/cjs/broadcaster/Web3Broadcaster.d.ts +30 -0
- package/dist/cjs/broadcaster/Web3Broadcaster.js +32 -0
- package/dist/cjs/broadcaster/index.d.ts +3 -0
- package/dist/cjs/broadcaster/index.js +19 -0
- package/dist/cjs/broadcaster/types.d.ts +56 -0
- package/dist/cjs/broadcaster/types.js +13 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/package.json +2 -2
- package/dist/cjs/strategy/BaseWalletStrategy.d.ts +58 -0
- package/dist/cjs/strategy/BaseWalletStrategy.js +176 -0
- package/dist/cjs/strategy/index.d.ts +2 -0
- package/dist/cjs/strategy/index.js +8 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +17 -0
- package/dist/cjs/utils/tx.d.ts +1 -0
- package/dist/cjs/utils/tx.js +11 -0
- package/dist/esm/broadcaster/MsgBroadcaster.d.ts +137 -0
- package/dist/esm/broadcaster/MsgBroadcaster.js +914 -0
- package/dist/esm/broadcaster/Web3Broadcaster.d.ts +30 -0
- package/dist/esm/broadcaster/Web3Broadcaster.js +28 -0
- package/dist/esm/broadcaster/index.d.ts +3 -0
- package/dist/esm/broadcaster/index.js +3 -0
- package/dist/esm/broadcaster/types.d.ts +56 -0
- package/dist/esm/broadcaster/types.js +10 -0
- package/dist/esm/index.d.ts +3 -281
- package/dist/esm/index.js +3 -1003
- package/dist/esm/package.json +2 -2
- package/dist/esm/strategy/BaseWalletStrategy.d.ts +58 -0
- package/dist/esm/strategy/BaseWalletStrategy.js +173 -0
- package/dist/esm/strategy/index.d.ts +2 -0
- package/dist/esm/strategy/index.js +2 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/tx.d.ts +1 -0
- package/dist/esm/utils/tx.js +7 -0
- package/package.json +19 -19
- package/dist/cjs/index.cjs +0 -1007
- package/dist/cjs/index.d.cts +0 -281
package/dist/esm/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"type": "module"
|
|
3
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tx.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tx.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const checkIfTxRunOutOfGas: (e: unknown) => boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-core",
|
|
3
3
|
"description": "Core wallet strategy",
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.26",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
@@ -41,32 +41,32 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "pnpm
|
|
45
|
-
"build:
|
|
46
|
-
"build:
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"test
|
|
51
|
-
"test:
|
|
52
|
-
"
|
|
44
|
+
"build": "pnpm build:cjs && pnpm build:esm && pnpm build:post",
|
|
45
|
+
"build:cjs": "tsc --build --force tsconfig.build.json",
|
|
46
|
+
"build:esm": "tsc --build --force tsconfig.build.esm.json",
|
|
47
|
+
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && pnpm build:post",
|
|
48
|
+
"build:post": "shx cp ../../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../../etc/stub/package.esm.json.stub dist/esm/package.json",
|
|
49
|
+
"clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
|
|
50
|
+
"test": "jest",
|
|
51
|
+
"test:watch": "jest --watch",
|
|
52
|
+
"test:ci": "jest --coverage --ci --reporters='jest-junit'",
|
|
53
|
+
"coverage": "jest --coverage",
|
|
53
54
|
"coverage:show": "live-server coverage",
|
|
54
55
|
"dev": "ts-node -r tsconfig-paths/register src/index.ts",
|
|
55
|
-
"start": "node dist/index.js"
|
|
56
|
-
"lint": "eslint . --ext .ts,.js"
|
|
56
|
+
"start": "node dist/index.js"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@injectivelabs/exceptions": "1.16.
|
|
60
|
-
"@injectivelabs/networks": "1.16.
|
|
61
|
-
"@injectivelabs/sdk-ts": "1.16.
|
|
62
|
-
"@injectivelabs/ts-types": "1.16.
|
|
63
|
-
"@injectivelabs/utils": "1.16.
|
|
64
|
-
"@injectivelabs/wallet-base": "1.16.
|
|
59
|
+
"@injectivelabs/exceptions": "1.16.26",
|
|
60
|
+
"@injectivelabs/networks": "1.16.26",
|
|
61
|
+
"@injectivelabs/sdk-ts": "1.16.26",
|
|
62
|
+
"@injectivelabs/ts-types": "1.16.26",
|
|
63
|
+
"@injectivelabs/utils": "1.16.26",
|
|
64
|
+
"@injectivelabs/wallet-base": "1.16.26",
|
|
65
65
|
"@keplr-wallet/types": "^0.12.159",
|
|
66
66
|
"eventemitter3": "^5.0.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"shx": "^0.3.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "cc507916c46b41e6bc70a01744e23d43b12ebc65"
|
|
72
72
|
}
|