@injectivelabs/wallet-cosmos 1.16.38 → 1.16.39-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.
- package/dist/cjs/index.cjs +468 -0
- package/dist/cjs/index.d.cts +139 -0
- package/dist/cjs/package.json +2 -2
- package/dist/esm/index.d.ts +139 -3
- package/dist/esm/index.js +465 -3
- package/dist/esm/package.json +2 -2
- package/package.json +45 -51
- package/dist/cjs/data/index.d.ts +0 -2
- package/dist/cjs/data/index.js +0 -10
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/strategy/strategy.d.ts +0 -48
- package/dist/cjs/strategy/strategy.js +0 -212
- package/dist/cjs/utils/index.d.ts +0 -8
- package/dist/cjs/utils/index.js +0 -38
- package/dist/cjs/wallet.d.ts +0 -62
- package/dist/cjs/wallet.js +0 -266
- package/dist/esm/data/index.d.ts +0 -2
- package/dist/esm/data/index.js +0 -7
- package/dist/esm/strategy/strategy.d.ts +0 -48
- package/dist/esm/strategy/strategy.js +0 -208
- package/dist/esm/utils/index.d.ts +0 -8
- package/dist/esm/utils/index.js +0 -33
- package/dist/esm/wallet.d.ts +0 -62
- package/dist/esm/wallet.js +0 -262
package/package.json
CHANGED
|
@@ -1,77 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-cosmos",
|
|
3
|
+
"version": "1.16.39-alpha.1",
|
|
3
4
|
"description": "Cosmos wallet strategies for use with @injectivelabs/wallet-core.",
|
|
4
|
-
"
|
|
5
|
-
"sideEffects": false,
|
|
6
|
-
"type": "module",
|
|
5
|
+
"license": "Apache-2.0",
|
|
7
6
|
"author": {
|
|
8
7
|
"name": "InjectiveLabs",
|
|
9
8
|
"email": "admin@injectivelabs.org"
|
|
10
9
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"main": "dist/cjs/index.js",
|
|
14
|
-
"module": "dist/esm/index.js",
|
|
15
|
-
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
],
|
|
18
|
-
"_moduleAliases": {
|
|
19
|
-
"~wallet-cosmos": "dist"
|
|
20
|
-
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
21
12
|
"exports": {
|
|
22
13
|
".": {
|
|
23
14
|
"react-native": {
|
|
24
15
|
"import": "./dist/esm/index.js",
|
|
25
|
-
"require": "./dist/cjs/index.
|
|
26
|
-
"types": "./dist/cjs/index.d.
|
|
27
|
-
"default": "./dist/cjs/index.
|
|
16
|
+
"require": "./dist/cjs/index.cjs",
|
|
17
|
+
"types": "./dist/cjs/index.d.cts",
|
|
18
|
+
"default": "./dist/cjs/index.cjs"
|
|
28
19
|
},
|
|
29
20
|
"require": {
|
|
30
|
-
"types": "./dist/cjs/index.d.
|
|
31
|
-
"default": "./dist/cjs/index.
|
|
21
|
+
"types": "./dist/cjs/index.d.cts",
|
|
22
|
+
"default": "./dist/cjs/index.cjs"
|
|
32
23
|
},
|
|
33
24
|
"import": {
|
|
34
25
|
"types": "./dist/esm/index.d.ts",
|
|
35
26
|
"default": "./dist/esm/index.js"
|
|
36
27
|
},
|
|
37
28
|
"default": {
|
|
38
|
-
"types": "./dist/cjs/index.d.
|
|
39
|
-
"default": "./dist/cjs/index.
|
|
29
|
+
"types": "./dist/cjs/index.d.cts",
|
|
30
|
+
"default": "./dist/cjs/index.cjs"
|
|
40
31
|
}
|
|
41
32
|
}
|
|
42
33
|
},
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
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",
|
|
54
|
-
"coverage:show": "live-server coverage",
|
|
55
|
-
"dev": "ts-node -r tsconfig-paths/register src/index.ts",
|
|
56
|
-
"start": "node dist/index.js"
|
|
57
|
-
},
|
|
34
|
+
"main": "dist/cjs/index.cjs",
|
|
35
|
+
"module": "dist/esm/index.js",
|
|
36
|
+
"types": "dist/cjs/index.d.cts",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
58
40
|
"dependencies": {
|
|
59
|
-
"@cosmjs/proto-signing": "
|
|
60
|
-
"@cosmjs/stargate": "
|
|
61
|
-
"@
|
|
62
|
-
"@injectivelabs/
|
|
63
|
-
"@injectivelabs/ts-types": "1.16.
|
|
64
|
-
"@injectivelabs/
|
|
65
|
-
"@injectivelabs/
|
|
66
|
-
"@
|
|
41
|
+
"@cosmjs/proto-signing": "0.33.0",
|
|
42
|
+
"@cosmjs/stargate": "0.33.0",
|
|
43
|
+
"@keplr-wallet/types": "^0.12.296",
|
|
44
|
+
"@injectivelabs/exceptions": "1.16.39-alpha.0",
|
|
45
|
+
"@injectivelabs/ts-types": "1.16.39-alpha.0",
|
|
46
|
+
"@injectivelabs/sdk-ts": "1.16.39-alpha.1",
|
|
47
|
+
"@injectivelabs/utils": "1.16.39-alpha.1",
|
|
48
|
+
"@injectivelabs/wallet-base": "1.16.39-alpha.1"
|
|
67
49
|
},
|
|
68
|
-
"
|
|
69
|
-
"
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
70
52
|
},
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"
|
|
53
|
+
"_moduleAliases": {
|
|
54
|
+
"~wallet-cosmos": "dist"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "pnpm type-check && tsdown",
|
|
58
|
+
"build:fast": "tsdown",
|
|
59
|
+
"build:watch": "tsdown --watch",
|
|
60
|
+
"clean": "shx rm -rf dist coverage *.log junit.xml && shx mkdir -p dist",
|
|
61
|
+
"type-check": "tsc --noEmit",
|
|
62
|
+
"test": "vitest",
|
|
63
|
+
"test:watch": "vitest --watch",
|
|
64
|
+
"test:ci": "vitest run --coverage --reporter=verbose",
|
|
65
|
+
"coverage": "vitest run --coverage",
|
|
66
|
+
"coverage:show": "live-server coverage",
|
|
67
|
+
"dev": "ts-node -r tsconfig-paths/register src/index.ts",
|
|
68
|
+
"start": "node dist/index.js",
|
|
69
|
+
"lint": "eslint . --ext .ts,.js"
|
|
76
70
|
}
|
|
77
|
-
}
|
|
71
|
+
}
|
package/dist/cjs/data/index.d.ts
DELETED
package/dist/cjs/data/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cosmosWallets = void 0;
|
|
4
|
-
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
5
|
-
exports.cosmosWallets = [
|
|
6
|
-
wallet_base_1.Wallet.Leap,
|
|
7
|
-
wallet_base_1.Wallet.Ninji,
|
|
8
|
-
wallet_base_1.Wallet.Keplr,
|
|
9
|
-
wallet_base_1.Wallet.OWallet,
|
|
10
|
-
];
|
package/dist/cjs/index.d.ts
DELETED
package/dist/cjs/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
exports.CosmosWalletStrategy = exports.CosmosWallet = void 0;
|
|
18
|
-
var wallet_js_1 = require("./wallet.js");
|
|
19
|
-
Object.defineProperty(exports, "CosmosWallet", { enumerable: true, get: function () { return wallet_js_1.CosmosWallet; } });
|
|
20
|
-
var strategy_js_1 = require("./strategy/strategy.js");
|
|
21
|
-
Object.defineProperty(exports, "CosmosWalletStrategy", { enumerable: true, get: function () { return strategy_js_1.CosmosWalletStrategy; } });
|
|
22
|
-
__exportStar(require("./utils/index.js"), exports);
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Wallet, WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
|
|
2
|
-
import { CosmosWallet } from './../wallet.js';
|
|
3
|
-
import type { OfflineSigner } from '@cosmjs/proto-signing';
|
|
4
|
-
import type { ChainId, EvmChainId, CosmosChainId, AccountAddress } from '@injectivelabs/ts-types';
|
|
5
|
-
import type { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
6
|
-
import type { StdSignDoc, ConcreteWalletStrategy, SendTransactionOptions } from '@injectivelabs/wallet-base';
|
|
7
|
-
export declare class CosmosWalletStrategy extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
8
|
-
wallet: Wallet;
|
|
9
|
-
private cosmosWallet;
|
|
10
|
-
constructor(args: {
|
|
11
|
-
chainId: ChainId | CosmosChainId;
|
|
12
|
-
endpoints?: {
|
|
13
|
-
rest: string;
|
|
14
|
-
rpc: string;
|
|
15
|
-
};
|
|
16
|
-
} & {
|
|
17
|
-
wallet: Wallet;
|
|
18
|
-
});
|
|
19
|
-
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
20
|
-
enable(): Promise<boolean>;
|
|
21
|
-
disconnect(): Promise<void>;
|
|
22
|
-
getAddresses(): Promise<string[]>;
|
|
23
|
-
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
24
|
-
sendEvmTransaction(_transaction: unknown, _options: {
|
|
25
|
-
address: AccountAddress;
|
|
26
|
-
evmChainId: EvmChainId;
|
|
27
|
-
}): Promise<string>;
|
|
28
|
-
sendTransaction(transaction: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
|
|
29
|
-
signAminoCosmosTransaction(transaction: {
|
|
30
|
-
address: string;
|
|
31
|
-
signDoc: StdSignDoc;
|
|
32
|
-
}): Promise<AminoSignResponse>;
|
|
33
|
-
signCosmosTransaction(transaction: {
|
|
34
|
-
txRaw: TxRaw;
|
|
35
|
-
accountNumber: number;
|
|
36
|
-
chainId: string;
|
|
37
|
-
address: AccountAddress;
|
|
38
|
-
}): Promise<DirectSignResponse>;
|
|
39
|
-
signEip712TypedData(_eip712TypedData: string, _address: AccountAddress): Promise<string>;
|
|
40
|
-
signArbitrary(signer: string, data: string | Uint8Array): Promise<string>;
|
|
41
|
-
getEthereumChainId(): Promise<string>;
|
|
42
|
-
getEvmTransactionReceipt(_txHash: string): Promise<string>;
|
|
43
|
-
getPubKey(): Promise<string>;
|
|
44
|
-
onAccountChange(callback: (account: AccountAddress | string[]) => void): Promise<void>;
|
|
45
|
-
getCosmosWallet(chainId: ChainId): CosmosWallet;
|
|
46
|
-
getOfflineSigner(chainId?: string): Promise<OfflineSigner>;
|
|
47
|
-
private getCurrentCosmosWallet;
|
|
48
|
-
}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CosmosWalletStrategy = void 0;
|
|
4
|
-
const utils_1 = require("@injectivelabs/utils");
|
|
5
|
-
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
6
|
-
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
7
|
-
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
8
|
-
const wallet_js_1 = require("./../wallet.js");
|
|
9
|
-
const cosmosWallets = [
|
|
10
|
-
wallet_base_1.Wallet.Leap,
|
|
11
|
-
wallet_base_1.Wallet.Ninji,
|
|
12
|
-
wallet_base_1.Wallet.Keplr,
|
|
13
|
-
wallet_base_1.Wallet.OWallet,
|
|
14
|
-
];
|
|
15
|
-
class CosmosWalletStrategy extends wallet_base_1.BaseConcreteStrategy {
|
|
16
|
-
wallet;
|
|
17
|
-
cosmosWallet;
|
|
18
|
-
constructor(args) {
|
|
19
|
-
super({ ...args, chainId: args.chainId });
|
|
20
|
-
if (!cosmosWallets.includes(args.wallet)) {
|
|
21
|
-
throw new exceptions_1.CosmosWalletException(new Error(`Cosmos Wallet for ${(0, utils_1.capitalize)(args.wallet)} is not supported.`));
|
|
22
|
-
}
|
|
23
|
-
this.wallet = args.wallet;
|
|
24
|
-
this.chainId = args.chainId;
|
|
25
|
-
this.cosmosWallet = new wallet_js_1.CosmosWallet({
|
|
26
|
-
wallet: args.wallet,
|
|
27
|
-
chainId: args.chainId,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async getWalletDeviceType() {
|
|
31
|
-
const cosmosWallet = this.getCurrentCosmosWallet();
|
|
32
|
-
const key = await cosmosWallet.getKey();
|
|
33
|
-
return key.isNanoLedger
|
|
34
|
-
? Promise.resolve(wallet_base_1.WalletDeviceType.Hardware)
|
|
35
|
-
: Promise.resolve(wallet_base_1.WalletDeviceType.Browser);
|
|
36
|
-
}
|
|
37
|
-
async enable() {
|
|
38
|
-
const cosmosWallet = this.getCurrentCosmosWallet();
|
|
39
|
-
return await cosmosWallet.checkChainIdSupport();
|
|
40
|
-
}
|
|
41
|
-
async disconnect() {
|
|
42
|
-
const { wallet } = this;
|
|
43
|
-
if (this.listeners[wallet_base_1.WalletEventListener.AccountChange]) {
|
|
44
|
-
if (wallet === wallet_base_1.Wallet.Ninji) {
|
|
45
|
-
window.ninji.off('accountsChanged', this.listeners[wallet_base_1.WalletEventListener.AccountChange]);
|
|
46
|
-
}
|
|
47
|
-
if ([wallet_base_1.Wallet.Keplr, wallet_base_1.Wallet.OWallet].includes(wallet)) {
|
|
48
|
-
window.removeEventListener('keplr_keystorechange', this.listeners[wallet_base_1.WalletEventListener.AccountChange]);
|
|
49
|
-
}
|
|
50
|
-
if (wallet === wallet_base_1.Wallet.Leap) {
|
|
51
|
-
window.removeEventListener('leap_keystorechange', this.listeners[wallet_base_1.WalletEventListener.AccountChange]);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
this.listeners = {};
|
|
55
|
-
}
|
|
56
|
-
async getAddresses() {
|
|
57
|
-
const cosmosWallet = this.getCurrentCosmosWallet();
|
|
58
|
-
try {
|
|
59
|
-
const accounts = await cosmosWallet.getAccounts();
|
|
60
|
-
return accounts.map((account) => account.address);
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
throw new exceptions_1.CosmosWalletException(new Error(e.message), {
|
|
64
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
65
|
-
context: wallet_base_1.WalletAction.GetAccounts,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async getSessionOrConfirm(address) {
|
|
70
|
-
return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
|
|
71
|
-
}
|
|
72
|
-
async sendEvmTransaction(_transaction, _options) {
|
|
73
|
-
const { wallet } = this;
|
|
74
|
-
throw new exceptions_1.CosmosWalletException(new Error(`sendEvmTransaction is not supported. ${(0, utils_1.capitalize)(wallet)} only supports sending cosmos transactions`), {
|
|
75
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
76
|
-
context: wallet_base_1.WalletAction.SendEvmTransaction,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
async sendTransaction(transaction, options) {
|
|
80
|
-
const cosmosWallet = this.getCurrentCosmosWallet();
|
|
81
|
-
const txRaw = (0, sdk_ts_1.createTxRawFromSigResponse)(transaction);
|
|
82
|
-
if (!options.endpoints) {
|
|
83
|
-
throw new exceptions_1.CosmosWalletException(new Error('You have to pass endpoints within the options to broadcast transaction'));
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
const txHash = await cosmosWallet.broadcastTx(txRaw);
|
|
87
|
-
return await (0, sdk_ts_1.waitTxBroadcasted)(txHash, options);
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
if (e instanceof exceptions_1.TransactionException) {
|
|
91
|
-
throw e;
|
|
92
|
-
}
|
|
93
|
-
throw new exceptions_1.TransactionException(new Error(e.message), {
|
|
94
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
95
|
-
context: wallet_base_1.WalletAction.SendTransaction,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async signAminoCosmosTransaction(transaction) {
|
|
100
|
-
const cosmosWallet = this.getCurrentCosmosWallet();
|
|
101
|
-
const signer = await cosmosWallet.getOfflineAminoSigner();
|
|
102
|
-
try {
|
|
103
|
-
return await signer.signAmino(transaction.address, transaction.signDoc);
|
|
104
|
-
}
|
|
105
|
-
catch (e) {
|
|
106
|
-
throw new exceptions_1.CosmosWalletException(new Error(e.message), {
|
|
107
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
108
|
-
context: wallet_base_1.WalletAction.SignTransaction,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async signCosmosTransaction(transaction) {
|
|
113
|
-
const cosmosWallet = this.getCurrentCosmosWallet();
|
|
114
|
-
const signer = await cosmosWallet.getOfflineSigner(this.chainId);
|
|
115
|
-
const signDoc = (0, sdk_ts_1.createSignDocFromTransaction)(transaction);
|
|
116
|
-
try {
|
|
117
|
-
if (!('signDirect' in signer)) {
|
|
118
|
-
throw new exceptions_1.CosmosWalletException(new Error('signDirect not available'), {
|
|
119
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
120
|
-
context: wallet_base_1.WalletAction.SendTransaction,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return await signer.signDirect(transaction.address, (0, wallet_base_1.createCosmosSignDocFromSignDoc)(signDoc));
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
throw new exceptions_1.CosmosWalletException(new Error(e.message), {
|
|
127
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
128
|
-
context: wallet_base_1.WalletAction.SendTransaction,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async signEip712TypedData(_eip712TypedData, _address) {
|
|
133
|
-
throw new exceptions_1.CosmosWalletException(new Error('This wallet does not support signing Evm transactions'), {
|
|
134
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
135
|
-
context: wallet_base_1.WalletAction.SendTransaction,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
async signArbitrary(signer, data) {
|
|
139
|
-
const cosmosWallet = this.getCurrentCosmosWallet();
|
|
140
|
-
try {
|
|
141
|
-
const signature = await cosmosWallet.signArbitrary({ data, signer });
|
|
142
|
-
return signature;
|
|
143
|
-
}
|
|
144
|
-
catch (e) {
|
|
145
|
-
throw new exceptions_1.CosmosWalletException(new Error(e.message), {
|
|
146
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
147
|
-
context: wallet_base_1.WalletAction.SignArbitrary,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async getEthereumChainId() {
|
|
152
|
-
const { wallet } = this;
|
|
153
|
-
throw new exceptions_1.CosmosWalletException(new Error(`getEthereumChainId is not supported on ${(0, utils_1.capitalize)(wallet)}`), {
|
|
154
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
155
|
-
context: wallet_base_1.WalletAction.GetChainId,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
async getEvmTransactionReceipt(_txHash) {
|
|
159
|
-
const { wallet } = this;
|
|
160
|
-
throw new exceptions_1.CosmosWalletException(new Error(`getEvmTransactionReceipt is not supported on ${(0, utils_1.capitalize)(wallet)}`), {
|
|
161
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
162
|
-
context: wallet_base_1.WalletAction.GetEvmTransactionReceipt,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
async getPubKey() {
|
|
166
|
-
const cosmosWallet = this.getCurrentCosmosWallet();
|
|
167
|
-
const key = await cosmosWallet.getKey();
|
|
168
|
-
return Buffer.from(key.pubKey).toString('base64');
|
|
169
|
-
}
|
|
170
|
-
async onAccountChange(callback) {
|
|
171
|
-
const { wallet } = this;
|
|
172
|
-
const listener = async () => {
|
|
173
|
-
const [account] = await this.getAddresses();
|
|
174
|
-
callback(account);
|
|
175
|
-
};
|
|
176
|
-
this.listeners = {
|
|
177
|
-
[wallet_base_1.WalletEventListener.AccountChange]: listener,
|
|
178
|
-
};
|
|
179
|
-
if (wallet === wallet_base_1.Wallet.Ninji) {
|
|
180
|
-
window.ninji.on('accountsChanged', listener);
|
|
181
|
-
}
|
|
182
|
-
if ([wallet_base_1.Wallet.Keplr, wallet_base_1.Wallet.OWallet].includes(wallet)) {
|
|
183
|
-
window.addEventListener('keplr_keystorechange', listener);
|
|
184
|
-
}
|
|
185
|
-
if (wallet === wallet_base_1.Wallet.Leap) {
|
|
186
|
-
window.addEventListener('leap_keystorechange', listener);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
getCosmosWallet(chainId) {
|
|
190
|
-
const { wallet, cosmosWallet } = this;
|
|
191
|
-
return !cosmosWallet ? new wallet_js_1.CosmosWallet({ chainId, wallet }) : cosmosWallet;
|
|
192
|
-
}
|
|
193
|
-
async getOfflineSigner(chainId) {
|
|
194
|
-
const cosmosWallet = await this.getCosmosWallet(chainId || this.chainId);
|
|
195
|
-
if (!cosmosWallet) {
|
|
196
|
-
throw new Error('no cosmos wallet');
|
|
197
|
-
}
|
|
198
|
-
return await cosmosWallet.getOfflineSigner(chainId || this.chainId);
|
|
199
|
-
}
|
|
200
|
-
getCurrentCosmosWallet() {
|
|
201
|
-
const { wallet, cosmosWallet } = this;
|
|
202
|
-
if (!cosmosWallet) {
|
|
203
|
-
throw new exceptions_1.CosmosWalletException(new Error(`Please install the ${(0, utils_1.capitalize)(wallet)} wallet extension`), {
|
|
204
|
-
code: exceptions_1.UnspecifiedErrorCode,
|
|
205
|
-
type: exceptions_1.ErrorType.WalletNotInstalledError,
|
|
206
|
-
context: wallet_base_1.WalletAction.SignTransaction,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return cosmosWallet;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
exports.CosmosWalletStrategy = CosmosWalletStrategy;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Wallet } from '@injectivelabs/wallet-base';
|
|
2
|
-
import type { ChainId } from '@injectivelabs/ts-types';
|
|
3
|
-
export declare const isCosmosWalletInstalled: (wallet: Wallet) => boolean;
|
|
4
|
-
export declare const confirmCosmosAddress: ({ wallet, chainId, injectiveAddress, }: {
|
|
5
|
-
wallet: Wallet;
|
|
6
|
-
chainId: ChainId;
|
|
7
|
-
injectiveAddress: string;
|
|
8
|
-
}) => Promise<void>;
|
package/dist/cjs/utils/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.confirmCosmosAddress = exports.isCosmosWalletInstalled = void 0;
|
|
4
|
-
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
5
|
-
const utils_1 = require("@injectivelabs/utils");
|
|
6
|
-
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
7
|
-
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
8
|
-
const wallet_js_1 = require("./../wallet.js");
|
|
9
|
-
const index_js_1 = require("./../data/index.js");
|
|
10
|
-
const isCosmosWalletInstalled = (wallet) => {
|
|
11
|
-
const $window = (typeof window !== 'undefined' ? window : {});
|
|
12
|
-
switch (wallet) {
|
|
13
|
-
case wallet_base_1.Wallet.Keplr:
|
|
14
|
-
return $window.keplr !== undefined;
|
|
15
|
-
case wallet_base_1.Wallet.Ninji:
|
|
16
|
-
return $window.ninji !== undefined;
|
|
17
|
-
case wallet_base_1.Wallet.Leap:
|
|
18
|
-
return $window.leap !== undefined;
|
|
19
|
-
case wallet_base_1.Wallet.OWallet:
|
|
20
|
-
return $window.oWallet !== undefined;
|
|
21
|
-
default:
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
exports.isCosmosWalletInstalled = isCosmosWalletInstalled;
|
|
26
|
-
const confirmCosmosAddress = async ({ wallet, chainId, injectiveAddress, }) => {
|
|
27
|
-
if (!index_js_1.cosmosWallets.includes(wallet)) {
|
|
28
|
-
throw new exceptions_1.CosmosWalletException(new Error(`Cosmos Wallet for ${(0, utils_1.capitalize)(wallet)} is not supported.`));
|
|
29
|
-
}
|
|
30
|
-
const cosmosWallet = new wallet_js_1.CosmosWallet({ chainId, wallet });
|
|
31
|
-
const key = await cosmosWallet.getKey();
|
|
32
|
-
const publicKey = sdk_ts_1.PublicKey.fromBase64(Buffer.from(key.pubKey).toString('base64'));
|
|
33
|
-
const { address: derivedAddress } = publicKey.toAddress();
|
|
34
|
-
if (derivedAddress !== injectiveAddress) {
|
|
35
|
-
throw new exceptions_1.CosmosWalletException(new Error(`Connected ${(0, utils_1.capitalize)(wallet)} address is wrong. Please update Injective on ${(0, utils_1.capitalize)(wallet)}.`));
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
exports.confirmCosmosAddress = confirmCosmosAddress;
|
package/dist/cjs/wallet.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { CosmosTxV1Beta1Tx } from '@injectivelabs/sdk-ts';
|
|
2
|
-
import { Wallet } from '@injectivelabs/wallet-base';
|
|
3
|
-
import type { StdFee } from '@cosmjs/stargate';
|
|
4
|
-
import type { EncodeObject } from '@cosmjs/proto-signing';
|
|
5
|
-
import type { OfflineSigner } from '@cosmjs/proto-signing';
|
|
6
|
-
import type { ChainId, CosmosChainId, TestnetCosmosChainId } from '@injectivelabs/ts-types';
|
|
7
|
-
import type { Keplr, StdSignDoc, AminoSignResponse, OfflineAminoSigner } from '@keplr-wallet/types';
|
|
8
|
-
export declare class CosmosWallet {
|
|
9
|
-
wallet: Wallet;
|
|
10
|
-
private chainId;
|
|
11
|
-
constructor({ wallet, chainId, }: {
|
|
12
|
-
wallet: Wallet;
|
|
13
|
-
chainId: CosmosChainId | TestnetCosmosChainId | ChainId;
|
|
14
|
-
});
|
|
15
|
-
isChainIdSupported(chainId: CosmosChainId): Promise<boolean>;
|
|
16
|
-
getCosmosWallet(): Promise<Keplr>;
|
|
17
|
-
chainNotSupported(): Promise<void>;
|
|
18
|
-
getAccounts(): Promise<readonly import("@keplr-wallet/types").AccountData[]>;
|
|
19
|
-
getKey(): Promise<{
|
|
20
|
-
name: string;
|
|
21
|
-
algo: string;
|
|
22
|
-
isNanoLedger: boolean;
|
|
23
|
-
pubKey: Uint8Array;
|
|
24
|
-
address: Uint8Array;
|
|
25
|
-
bech32Address: string;
|
|
26
|
-
}>;
|
|
27
|
-
getOfflineSigner(chainId?: string): Promise<OfflineSigner>;
|
|
28
|
-
getOfflineAminoSigner(): Promise<OfflineAminoSigner>;
|
|
29
|
-
/**
|
|
30
|
-
* This method is used to broadcast a transaction to the network.
|
|
31
|
-
* Since it uses the `Sync` mode, it will not wait for the transaction to be included in a block,
|
|
32
|
-
* so we have to make sure the transaction is included in a block after its broadcasted
|
|
33
|
-
*
|
|
34
|
-
* @param txRaw - raw transaction to broadcast
|
|
35
|
-
* @returns tx hash
|
|
36
|
-
*/
|
|
37
|
-
broadcastTx(txRaw: CosmosTxV1Beta1Tx.TxRaw): Promise<string>;
|
|
38
|
-
/**
|
|
39
|
-
* This method is used to broadcast a transaction to the network.
|
|
40
|
-
* Since it uses the `Block` mode, and it will wait for the transaction to be included in a block,
|
|
41
|
-
*
|
|
42
|
-
* @param txRaw - raw transaction to broadcast
|
|
43
|
-
* @returns tx hash
|
|
44
|
-
*/
|
|
45
|
-
broadcastTxBlock(txRaw: CosmosTxV1Beta1Tx.TxRaw): Promise<string>;
|
|
46
|
-
signAndBroadcastAminoUsingCosmjs(messages: EncodeObject[], stdFee: StdFee, endpoints: {
|
|
47
|
-
rest: string;
|
|
48
|
-
rpc: string;
|
|
49
|
-
}): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
50
|
-
signArbitrary({ data, signer, }: {
|
|
51
|
-
signer: string;
|
|
52
|
-
data: string | Uint8Array;
|
|
53
|
-
}): Promise<string>;
|
|
54
|
-
signEIP712CosmosTx({ eip712, signDoc, }: {
|
|
55
|
-
eip712: any;
|
|
56
|
-
signDoc: StdSignDoc;
|
|
57
|
-
}): Promise<AminoSignResponse>;
|
|
58
|
-
checkChainIdSupport(): Promise<boolean>;
|
|
59
|
-
private getCosmos;
|
|
60
|
-
disableGasCheck(): Promise<void>;
|
|
61
|
-
enableGasCheck(): Promise<void>;
|
|
62
|
-
}
|