@dynamic-labs/cosmos 3.4.4 → 3.4.6
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/CHANGELOG.md +26 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +6 -6
- package/src/connectors/CompassWalletConnector.cjs +39 -0
- package/src/connectors/CompassWalletConnector.d.ts +10 -0
- package/src/connectors/CompassWalletConnector.js +35 -0
- package/src/connectors/CosmosWalletConnector.cjs +107 -8
- package/src/connectors/CosmosWalletConnector.d.ts +21 -11
- package/src/connectors/CosmosWalletConnector.js +108 -10
- package/src/connectors/KeplrWalletConnector.cjs +8 -100
- package/src/connectors/KeplrWalletConnector.d.ts +4 -33
- package/src/connectors/KeplrWalletConnector.js +9 -100
- package/src/connectors/LeapWalletConnector.cjs +28 -0
- package/src/connectors/LeapWalletConnector.d.ts +9 -0
- package/src/connectors/LeapWalletConnector.js +24 -0
- package/src/connectors/index.d.ts +2 -0
- package/src/index.cjs +7 -1
- package/src/index.d.ts +3 -2
- package/src/index.js +7 -1
- package/src/types.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
|
|
2
|
+
### [3.4.6](https://github.com/dynamic-labs/DynamicAuth/compare/v3.4.5...v3.4.6) (2024-10-31)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add support for compass and leap wallets ([ab170c9](https://github.com/dynamic-labs/DynamicAuth/commit/ab170c962099ed6356d2f31c947b122f1aa7ec73))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* prevent use-wallet-options from reading empty wallet-book ([#7320](https://github.com/dynamic-labs/DynamicAuth/issues/7320)) ([24c6cb1](https://github.com/dynamic-labs/DynamicAuth/commit/24c6cb14ce324925b120d363e029e29b72560895))
|
|
13
|
+
* sats-connect wallets not prompting correctly to sync account when making a transaction ([#7311](https://github.com/dynamic-labs/DynamicAuth/issues/7311)) ([#7312](https://github.com/dynamic-labs/DynamicAuth/issues/7312)) ([2026be4](https://github.com/dynamic-labs/DynamicAuth/commit/2026be412edcbb7e98341a5a5b2a3bd75ffdb83f))
|
|
14
|
+
* update check for wallet provider event listeners support ([#7303](https://github.com/dynamic-labs/DynamicAuth/issues/7303)) ([#7304](https://github.com/dynamic-labs/DynamicAuth/issues/7304)) ([1e91c76](https://github.com/dynamic-labs/DynamicAuth/commit/1e91c767ebe078f63c27884e4a8e7729d49b2114))
|
|
15
|
+
|
|
16
|
+
### [3.4.5](https://github.com/dynamic-labs/DynamicAuth/compare/v3.4.4...v3.4.5) (2024-10-30)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* add support for epicgames social ([#7222](https://github.com/dynamic-labs/DynamicAuth/issues/7222)) ([f34f027](https://github.com/dynamic-labs/DynamicAuth/commit/f34f02738a4d163792ff457dfe053335a4d57328))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* show connect view when user selects a wallet to connect with ([#7211](https://github.com/dynamic-labs/DynamicAuth/issues/7211)) ([c7d3ab0](https://github.com/dynamic-labs/DynamicAuth/commit/c7d3ab00d4ced00128e0e7bde908165707a15a5c))
|
|
27
|
+
|
|
2
28
|
### [3.4.4](https://github.com/dynamic-labs/DynamicAuth/compare/v3.4.3...v3.4.4) (2024-10-24)
|
|
3
29
|
|
|
4
30
|
### [3.4.3](https://github.com/dynamic-labs/DynamicAuth/compare/v3.4.2...v3.4.3) (2024-10-23)
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/cosmos",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@keplr-wallet/types": "0.12.121",
|
|
30
|
-
"@dynamic-labs/assert-package-version": "3.4.
|
|
31
|
-
"@dynamic-labs/types": "3.4.
|
|
32
|
-
"@dynamic-labs/utils": "3.4.
|
|
33
|
-
"@dynamic-labs/wallet-book": "3.4.
|
|
34
|
-
"@dynamic-labs/wallet-connector-core": "3.4.
|
|
30
|
+
"@dynamic-labs/assert-package-version": "3.4.6",
|
|
31
|
+
"@dynamic-labs/types": "3.4.6",
|
|
32
|
+
"@dynamic-labs/utils": "3.4.6",
|
|
33
|
+
"@dynamic-labs/wallet-book": "3.4.6",
|
|
34
|
+
"@dynamic-labs/wallet-connector-core": "3.4.6"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {}
|
|
37
37
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var CosmosWalletConnector = require('./CosmosWalletConnector.cjs');
|
|
7
|
+
|
|
8
|
+
class CompassWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.name = 'compasscosmos';
|
|
12
|
+
this.overrideKey = 'compasscosmos';
|
|
13
|
+
}
|
|
14
|
+
getWallet() {
|
|
15
|
+
if (typeof window === 'undefined') {
|
|
16
|
+
throw new Error('Compass is not available');
|
|
17
|
+
}
|
|
18
|
+
return window.compass;
|
|
19
|
+
}
|
|
20
|
+
getChainId() {
|
|
21
|
+
const hasSei = this.chainIdMapping.find((chain) => chain.cosmosNetworkId === 'pacific-1');
|
|
22
|
+
// Compass wallet only supports Sei
|
|
23
|
+
if (!hasSei) {
|
|
24
|
+
throw new Error('Sei is not available on this site');
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return 'pacific-1';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
setupEventListeners() {
|
|
31
|
+
window.addEventListener('leap_keystorechange', this._handleAccountChange);
|
|
32
|
+
}
|
|
33
|
+
teardownEventListeners() {
|
|
34
|
+
window.removeEventListener('leap_keystorechange', this._handleAccountChange);
|
|
35
|
+
this.setChainId(null);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.CompassWalletConnector = CompassWalletConnector;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Keplr as KeplrWallet } from '@keplr-wallet/types';
|
|
2
|
+
import { CosmosWalletConnector } from './CosmosWalletConnector';
|
|
3
|
+
export declare class CompassWalletConnector extends CosmosWalletConnector {
|
|
4
|
+
name: string;
|
|
5
|
+
overrideKey: string;
|
|
6
|
+
protected getWallet(): KeplrWallet | undefined;
|
|
7
|
+
getChainId(): string;
|
|
8
|
+
setupEventListeners(): void;
|
|
9
|
+
teardownEventListeners(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { CosmosWalletConnector } from './CosmosWalletConnector.js';
|
|
3
|
+
|
|
4
|
+
class CompassWalletConnector extends CosmosWalletConnector {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.name = 'compasscosmos';
|
|
8
|
+
this.overrideKey = 'compasscosmos';
|
|
9
|
+
}
|
|
10
|
+
getWallet() {
|
|
11
|
+
if (typeof window === 'undefined') {
|
|
12
|
+
throw new Error('Compass is not available');
|
|
13
|
+
}
|
|
14
|
+
return window.compass;
|
|
15
|
+
}
|
|
16
|
+
getChainId() {
|
|
17
|
+
const hasSei = this.chainIdMapping.find((chain) => chain.cosmosNetworkId === 'pacific-1');
|
|
18
|
+
// Compass wallet only supports Sei
|
|
19
|
+
if (!hasSei) {
|
|
20
|
+
throw new Error('Sei is not available on this site');
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return 'pacific-1';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
setupEventListeners() {
|
|
27
|
+
window.addEventListener('leap_keystorechange', this._handleAccountChange);
|
|
28
|
+
}
|
|
29
|
+
teardownEventListeners() {
|
|
30
|
+
window.removeEventListener('leap_keystorechange', this._handleAccountChange);
|
|
31
|
+
this.setChainId(null);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { CompassWalletConnector };
|
|
@@ -8,36 +8,39 @@ var utils = require('@dynamic-labs/utils');
|
|
|
8
8
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
9
|
var CosmosWallet = require('../wallet/CosmosWallet.cjs');
|
|
10
10
|
|
|
11
|
+
const DYNAMIC_COSMOS_NETWORK_ID = 'dynamic_cosmos_network_id';
|
|
11
12
|
class CosmosWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
12
13
|
constructor(opts) {
|
|
13
14
|
super(opts);
|
|
14
15
|
this.ChainWallet = CosmosWallet.CosmosWallet;
|
|
15
16
|
this.connectedChain = 'COSMOS';
|
|
16
17
|
this.supportedChains = ['COSMOS'];
|
|
17
|
-
this.evmNetworks = utils.
|
|
18
|
+
this.evmNetworks = utils.parseCosmosNetworks(opts.cosmosNetworks);
|
|
18
19
|
this.chainIdMapping = this.evmNetworks.map((network) => ({
|
|
20
|
+
bech32Prefix: network.bech32Prefix,
|
|
21
|
+
cosmosNetwork: network,
|
|
19
22
|
cosmosNetworkId: network.name,
|
|
20
23
|
dynamicChainId: utils.parseChainId(network.networkId),
|
|
21
|
-
evmNetwork: network,
|
|
22
24
|
}));
|
|
25
|
+
this._handleAccountChange = this._handleAccountChange.bind(this);
|
|
23
26
|
}
|
|
24
|
-
|
|
27
|
+
getSelectedChain() {
|
|
25
28
|
const selectedNetwork = this.chainIdMapping.find((mapping) => mapping.cosmosNetworkId === this.getChainId());
|
|
26
|
-
return selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.
|
|
29
|
+
return selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.cosmosNetwork;
|
|
27
30
|
}
|
|
28
31
|
getNetwork() {
|
|
29
32
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
30
33
|
var _a;
|
|
31
|
-
return (_a = this.
|
|
34
|
+
return (_a = this.getSelectedChain()) === null || _a === void 0 ? void 0 : _a.chainId;
|
|
32
35
|
});
|
|
33
36
|
}
|
|
34
37
|
getLcdUrl() {
|
|
35
38
|
var _a;
|
|
36
|
-
return (_a = this.
|
|
39
|
+
return (_a = this.getSelectedChain()) === null || _a === void 0 ? void 0 : _a.lcdUrl;
|
|
37
40
|
}
|
|
38
41
|
getDenom() {
|
|
39
42
|
var _a;
|
|
40
|
-
return (_a = this.
|
|
43
|
+
return (_a = this.getSelectedChain()) === null || _a === void 0 ? void 0 : _a.nativeCurrency.denom;
|
|
41
44
|
}
|
|
42
45
|
getBalance(address) {
|
|
43
46
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -60,7 +63,7 @@ class CosmosWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
60
63
|
getConnectedAccounts() {
|
|
61
64
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
62
65
|
const address = yield this.getAddress();
|
|
63
|
-
return [address];
|
|
66
|
+
return address ? [address] : [];
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
69
|
endSession() {
|
|
@@ -68,6 +71,102 @@ class CosmosWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
68
71
|
this.setChainId(null);
|
|
69
72
|
});
|
|
70
73
|
}
|
|
74
|
+
getDefaultChainId() {
|
|
75
|
+
if (this.chainIdMapping.length === 0) {
|
|
76
|
+
return 'cosmoshub-4';
|
|
77
|
+
}
|
|
78
|
+
if (this.chainIdMapping.find((chain) => chain.cosmosNetworkId === 'cosmoshub-4')) {
|
|
79
|
+
return 'cosmoshub-4';
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return this.chainIdMapping[0].cosmosNetworkId;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
getChainId() {
|
|
86
|
+
const defaultChainId = this.getDefaultChainId();
|
|
87
|
+
const storedChainId = localStorage.getItem(DYNAMIC_COSMOS_NETWORK_ID);
|
|
88
|
+
return storedChainId !== null && storedChainId !== void 0 ? storedChainId : defaultChainId;
|
|
89
|
+
}
|
|
90
|
+
setChainId(chainId) {
|
|
91
|
+
if (!chainId) {
|
|
92
|
+
localStorage.removeItem(DYNAMIC_COSMOS_NETWORK_ID);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
localStorage.setItem(DYNAMIC_COSMOS_NETWORK_ID, chainId);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
getAccount() {
|
|
99
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
var _a;
|
|
101
|
+
const wallet = this.getWallet();
|
|
102
|
+
if (!wallet) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const accountsList = yield ((_a = (yield this.getOfflineSigner())) === null || _a === void 0 ? void 0 : _a.getAccounts());
|
|
107
|
+
if (!accountsList || accountsList.length === 0) {
|
|
108
|
+
walletConnectorCore.logger.warn('No accounts found for chain', this.getChainId());
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const [account] = accountsList;
|
|
112
|
+
return account;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
connect() {
|
|
117
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
var _a;
|
|
119
|
+
yield ((_a = this.getWallet()) === null || _a === void 0 ? void 0 : _a.enable(this.chainIdMapping.map((mapping) => mapping.cosmosNetworkId)));
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
getAddress() {
|
|
123
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
yield this.connect();
|
|
125
|
+
const account = yield this.getAccount();
|
|
126
|
+
return account === null || account === void 0 ? void 0 : account.address;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
getProvider() {
|
|
130
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
return this.getWallet();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
getOfflineSigner() {
|
|
135
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
var _a;
|
|
137
|
+
return (_a = this.getWallet()) === null || _a === void 0 ? void 0 : _a.getOfflineSigner(this.getChainId());
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
isInstalledOnBrowser() {
|
|
141
|
+
return typeof this.getWallet() !== 'undefined';
|
|
142
|
+
}
|
|
143
|
+
_handleAccountChange() {
|
|
144
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const address = yield this.getAddress();
|
|
146
|
+
if (address) {
|
|
147
|
+
this.emit('accountChange', { accounts: [address] });
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
signMessage(messageToSign) {
|
|
152
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
var _a;
|
|
154
|
+
const address = yield this.getAddress();
|
|
155
|
+
if (!address)
|
|
156
|
+
throw new Error('No address found');
|
|
157
|
+
const signatureResponse = yield ((_a = this.getWallet()) === null || _a === void 0 ? void 0 : _a.signArbitrary(this.getChainId(), address, messageToSign));
|
|
158
|
+
if (!signatureResponse) {
|
|
159
|
+
throw new Error('Could not sign message');
|
|
160
|
+
}
|
|
161
|
+
const chain = this.getSelectedChain();
|
|
162
|
+
if (!chain || !chain.bech32Prefix) {
|
|
163
|
+
throw new Error('Could not get bech32Prefix for chain');
|
|
164
|
+
}
|
|
165
|
+
const signatureWithPrefix = Object.assign(Object.assign({}, signatureResponse), { bech32Prefix: chain.bech32Prefix });
|
|
166
|
+
return JSON.stringify(signatureWithPrefix);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
71
169
|
}
|
|
72
170
|
|
|
73
171
|
exports.CosmosWalletConnector = CosmosWalletConnector;
|
|
172
|
+
exports.DYNAMIC_COSMOS_NETWORK_ID = DYNAMIC_COSMOS_NETWORK_ID;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Keplr as KeplrWallet, OfflineAminoSigner, OfflineDirectSigner } from '@keplr-wallet/types';
|
|
2
|
+
import { CosmosNetwork, GenericNetwork } from '@dynamic-labs/types';
|
|
2
3
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
3
|
-
import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
-
import { ICosmosOfflineSigner, ICosmosProvider } from '../types';
|
|
4
|
+
import { Chain, WalletConnectorBase, WalletMetadata } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { CosmosWallet } from '../wallet';
|
|
6
6
|
export interface IFetchBalanceResponse {
|
|
7
7
|
balances: IFetchBalanceBalance[];
|
|
@@ -18,30 +18,40 @@ export interface IFetchBalancePagination {
|
|
|
18
18
|
export type CosmosWalletConnectorOpts = {
|
|
19
19
|
cosmosNetworks: GenericNetwork[];
|
|
20
20
|
walletBook: WalletBookSchema;
|
|
21
|
+
metadata?: WalletMetadata;
|
|
21
22
|
};
|
|
22
23
|
type CosmosChainIDMapObject = {
|
|
23
24
|
dynamicChainId: number;
|
|
24
25
|
cosmosNetworkId: string;
|
|
25
|
-
|
|
26
|
+
bech32Prefix: string | undefined;
|
|
27
|
+
cosmosNetwork: CosmosNetwork;
|
|
26
28
|
};
|
|
29
|
+
export declare const DYNAMIC_COSMOS_NETWORK_ID = "dynamic_cosmos_network_id";
|
|
27
30
|
export declare abstract class CosmosWalletConnector extends WalletConnectorBase {
|
|
28
|
-
evmNetworks:
|
|
31
|
+
evmNetworks: CosmosNetwork[];
|
|
29
32
|
ChainWallet: typeof CosmosWallet;
|
|
30
33
|
connectedChain: Chain;
|
|
31
34
|
supportedChains: Chain[];
|
|
32
35
|
chainIdMapping: CosmosChainIDMapObject[];
|
|
33
36
|
constructor(opts: CosmosWalletConnectorOpts);
|
|
34
|
-
abstract
|
|
35
|
-
|
|
36
|
-
abstract getProvider(): Promise<ICosmosProvider | undefined>;
|
|
37
|
-
abstract getOfflineSigner(): Promise<ICosmosOfflineSigner>;
|
|
38
|
-
getSelectedNetwork(): EvmNetwork | undefined;
|
|
37
|
+
protected abstract getWallet(): KeplrWallet | undefined;
|
|
38
|
+
getSelectedChain(): CosmosNetwork | undefined;
|
|
39
39
|
getNetwork(): Promise<number | undefined>;
|
|
40
40
|
getLcdUrl(): string | undefined;
|
|
41
41
|
getDenom(): string | undefined;
|
|
42
42
|
getBalance(address: string): Promise<string | undefined>;
|
|
43
|
-
abstract getAddress(): Promise<string>;
|
|
44
43
|
getConnectedAccounts(): Promise<string[]>;
|
|
45
44
|
endSession(): Promise<void>;
|
|
45
|
+
getDefaultChainId(): string;
|
|
46
|
+
getChainId(): string;
|
|
47
|
+
setChainId(chainId: string | null): void;
|
|
48
|
+
protected getAccount(): Promise<import("@keplr-wallet/types").AccountData | undefined>;
|
|
49
|
+
connect(): Promise<void>;
|
|
50
|
+
getAddress(): Promise<string | undefined>;
|
|
51
|
+
getProvider(): Promise<KeplrWallet | undefined>;
|
|
52
|
+
getOfflineSigner(): Promise<(OfflineAminoSigner & OfflineDirectSigner) | undefined>;
|
|
53
|
+
isInstalledOnBrowser(): boolean;
|
|
54
|
+
_handleAccountChange(): Promise<void>;
|
|
55
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
46
56
|
}
|
|
47
57
|
export {};
|
|
@@ -1,39 +1,42 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
-
import {
|
|
3
|
+
import { parseCosmosNetworks, parseChainId } from '@dynamic-labs/utils';
|
|
4
4
|
import { WalletConnectorBase, logger } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { CosmosWallet } from '../wallet/CosmosWallet.js';
|
|
6
6
|
|
|
7
|
+
const DYNAMIC_COSMOS_NETWORK_ID = 'dynamic_cosmos_network_id';
|
|
7
8
|
class CosmosWalletConnector extends WalletConnectorBase {
|
|
8
9
|
constructor(opts) {
|
|
9
10
|
super(opts);
|
|
10
11
|
this.ChainWallet = CosmosWallet;
|
|
11
12
|
this.connectedChain = 'COSMOS';
|
|
12
13
|
this.supportedChains = ['COSMOS'];
|
|
13
|
-
this.evmNetworks =
|
|
14
|
+
this.evmNetworks = parseCosmosNetworks(opts.cosmosNetworks);
|
|
14
15
|
this.chainIdMapping = this.evmNetworks.map((network) => ({
|
|
16
|
+
bech32Prefix: network.bech32Prefix,
|
|
17
|
+
cosmosNetwork: network,
|
|
15
18
|
cosmosNetworkId: network.name,
|
|
16
19
|
dynamicChainId: parseChainId(network.networkId),
|
|
17
|
-
evmNetwork: network,
|
|
18
20
|
}));
|
|
21
|
+
this._handleAccountChange = this._handleAccountChange.bind(this);
|
|
19
22
|
}
|
|
20
|
-
|
|
23
|
+
getSelectedChain() {
|
|
21
24
|
const selectedNetwork = this.chainIdMapping.find((mapping) => mapping.cosmosNetworkId === this.getChainId());
|
|
22
|
-
return selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.
|
|
25
|
+
return selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.cosmosNetwork;
|
|
23
26
|
}
|
|
24
27
|
getNetwork() {
|
|
25
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
29
|
var _a;
|
|
27
|
-
return (_a = this.
|
|
30
|
+
return (_a = this.getSelectedChain()) === null || _a === void 0 ? void 0 : _a.chainId;
|
|
28
31
|
});
|
|
29
32
|
}
|
|
30
33
|
getLcdUrl() {
|
|
31
34
|
var _a;
|
|
32
|
-
return (_a = this.
|
|
35
|
+
return (_a = this.getSelectedChain()) === null || _a === void 0 ? void 0 : _a.lcdUrl;
|
|
33
36
|
}
|
|
34
37
|
getDenom() {
|
|
35
38
|
var _a;
|
|
36
|
-
return (_a = this.
|
|
39
|
+
return (_a = this.getSelectedChain()) === null || _a === void 0 ? void 0 : _a.nativeCurrency.denom;
|
|
37
40
|
}
|
|
38
41
|
getBalance(address) {
|
|
39
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -56,7 +59,7 @@ class CosmosWalletConnector extends WalletConnectorBase {
|
|
|
56
59
|
getConnectedAccounts() {
|
|
57
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
61
|
const address = yield this.getAddress();
|
|
59
|
-
return [address];
|
|
62
|
+
return address ? [address] : [];
|
|
60
63
|
});
|
|
61
64
|
}
|
|
62
65
|
endSession() {
|
|
@@ -64,6 +67,101 @@ class CosmosWalletConnector extends WalletConnectorBase {
|
|
|
64
67
|
this.setChainId(null);
|
|
65
68
|
});
|
|
66
69
|
}
|
|
70
|
+
getDefaultChainId() {
|
|
71
|
+
if (this.chainIdMapping.length === 0) {
|
|
72
|
+
return 'cosmoshub-4';
|
|
73
|
+
}
|
|
74
|
+
if (this.chainIdMapping.find((chain) => chain.cosmosNetworkId === 'cosmoshub-4')) {
|
|
75
|
+
return 'cosmoshub-4';
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return this.chainIdMapping[0].cosmosNetworkId;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
getChainId() {
|
|
82
|
+
const defaultChainId = this.getDefaultChainId();
|
|
83
|
+
const storedChainId = localStorage.getItem(DYNAMIC_COSMOS_NETWORK_ID);
|
|
84
|
+
return storedChainId !== null && storedChainId !== void 0 ? storedChainId : defaultChainId;
|
|
85
|
+
}
|
|
86
|
+
setChainId(chainId) {
|
|
87
|
+
if (!chainId) {
|
|
88
|
+
localStorage.removeItem(DYNAMIC_COSMOS_NETWORK_ID);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
localStorage.setItem(DYNAMIC_COSMOS_NETWORK_ID, chainId);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
getAccount() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
var _a;
|
|
97
|
+
const wallet = this.getWallet();
|
|
98
|
+
if (!wallet) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const accountsList = yield ((_a = (yield this.getOfflineSigner())) === null || _a === void 0 ? void 0 : _a.getAccounts());
|
|
103
|
+
if (!accountsList || accountsList.length === 0) {
|
|
104
|
+
logger.warn('No accounts found for chain', this.getChainId());
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
const [account] = accountsList;
|
|
108
|
+
return account;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
connect() {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
var _a;
|
|
115
|
+
yield ((_a = this.getWallet()) === null || _a === void 0 ? void 0 : _a.enable(this.chainIdMapping.map((mapping) => mapping.cosmosNetworkId)));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
getAddress() {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
yield this.connect();
|
|
121
|
+
const account = yield this.getAccount();
|
|
122
|
+
return account === null || account === void 0 ? void 0 : account.address;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
getProvider() {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
return this.getWallet();
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
getOfflineSigner() {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
var _a;
|
|
133
|
+
return (_a = this.getWallet()) === null || _a === void 0 ? void 0 : _a.getOfflineSigner(this.getChainId());
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
isInstalledOnBrowser() {
|
|
137
|
+
return typeof this.getWallet() !== 'undefined';
|
|
138
|
+
}
|
|
139
|
+
_handleAccountChange() {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
const address = yield this.getAddress();
|
|
142
|
+
if (address) {
|
|
143
|
+
this.emit('accountChange', { accounts: [address] });
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
signMessage(messageToSign) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
var _a;
|
|
150
|
+
const address = yield this.getAddress();
|
|
151
|
+
if (!address)
|
|
152
|
+
throw new Error('No address found');
|
|
153
|
+
const signatureResponse = yield ((_a = this.getWallet()) === null || _a === void 0 ? void 0 : _a.signArbitrary(this.getChainId(), address, messageToSign));
|
|
154
|
+
if (!signatureResponse) {
|
|
155
|
+
throw new Error('Could not sign message');
|
|
156
|
+
}
|
|
157
|
+
const chain = this.getSelectedChain();
|
|
158
|
+
if (!chain || !chain.bech32Prefix) {
|
|
159
|
+
throw new Error('Could not get bech32Prefix for chain');
|
|
160
|
+
}
|
|
161
|
+
const signatureWithPrefix = Object.assign(Object.assign({}, signatureResponse), { bech32Prefix: chain.bech32Prefix });
|
|
162
|
+
return JSON.stringify(signatureWithPrefix);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
67
165
|
}
|
|
68
166
|
|
|
69
|
-
export { CosmosWalletConnector };
|
|
167
|
+
export { CosmosWalletConnector, DYNAMIC_COSMOS_NETWORK_ID };
|
|
@@ -6,89 +6,22 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
7
|
var CosmosWalletConnector = require('./CosmosWalletConnector.cjs');
|
|
8
8
|
|
|
9
|
-
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_network_id';
|
|
10
9
|
class KeplrWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
|
|
11
|
-
constructor(
|
|
12
|
-
super(
|
|
13
|
-
this.switchNetworkOnlyFromWallet = true;
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
14
12
|
this.name = 'Keplr';
|
|
15
13
|
this.overrideKey = 'keplr';
|
|
16
|
-
this.
|
|
17
|
-
}
|
|
18
|
-
getDefaultChainId() {
|
|
19
|
-
if (this.chainIdMapping.length === 0) {
|
|
20
|
-
return 'cosmoshub-4';
|
|
21
|
-
}
|
|
22
|
-
if (this.chainIdMapping.find((chain) => chain.cosmosNetworkId === 'cosmoshub-4')) {
|
|
23
|
-
return 'cosmoshub-4';
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
return this.chainIdMapping[0].cosmosNetworkId;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
getChainId() {
|
|
30
|
-
const defaultChainId = this.getDefaultChainId();
|
|
31
|
-
const storedChainId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
32
|
-
return storedChainId !== null && storedChainId !== void 0 ? storedChainId : defaultChainId;
|
|
33
|
-
}
|
|
34
|
-
setChainId(chainId) {
|
|
35
|
-
if (!chainId) {
|
|
36
|
-
localStorage.removeItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
localStorage.setItem(DYNAMIC_KEPLR_NETWORK_ID, chainId);
|
|
40
|
-
}
|
|
14
|
+
this.switchNetworkOnlyFromWallet = true;
|
|
41
15
|
}
|
|
42
|
-
|
|
43
|
-
return
|
|
44
|
-
const accountsList = yield this.keplr
|
|
45
|
-
.getOfflineSigner(this.getChainId())
|
|
46
|
-
.getAccounts();
|
|
47
|
-
if (!accountsList)
|
|
48
|
-
throw new Error('No accounts found');
|
|
49
|
-
const [account] = accountsList;
|
|
50
|
-
return account;
|
|
51
|
-
});
|
|
16
|
+
supportsNetworkSwitching() {
|
|
17
|
+
return true;
|
|
52
18
|
}
|
|
53
|
-
|
|
54
|
-
if (typeof window === 'undefined')
|
|
19
|
+
getWallet() {
|
|
20
|
+
if (typeof window === 'undefined') {
|
|
55
21
|
throw new Error('Keplr is not available');
|
|
56
|
-
|
|
22
|
+
}
|
|
57
23
|
return window.keplr;
|
|
58
24
|
}
|
|
59
|
-
connect() {
|
|
60
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
yield this.keplr.enable(this.chainIdMapping.map((mapping) => mapping.cosmosNetworkId));
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
getAddress() {
|
|
65
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
yield this.connect();
|
|
67
|
-
const account = yield this.getAccount();
|
|
68
|
-
return account.address;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
getProvider() {
|
|
72
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
return this.keplr;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
getOfflineSigner() {
|
|
77
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
return this.keplr.getOfflineSigner(this.getChainId());
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
isInstalledOnBrowser() {
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
83
|
-
// @ts-ignore window.keplr is provided by extension
|
|
84
|
-
return typeof window.keplr !== 'undefined';
|
|
85
|
-
}
|
|
86
|
-
_handleAccountChange() {
|
|
87
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
const address = yield this.getAddress();
|
|
89
|
-
this.emit('accountChange', { accounts: [address] });
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
25
|
setupEventListeners() {
|
|
93
26
|
window.addEventListener('keplr_keystorechange', this._handleAccountChange);
|
|
94
27
|
}
|
|
@@ -96,30 +29,6 @@ class KeplrWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
|
|
|
96
29
|
window.removeEventListener('keplr_keystorechange', this._handleAccountChange);
|
|
97
30
|
this.setChainId(null);
|
|
98
31
|
}
|
|
99
|
-
// SignDoc used for signAmin method;
|
|
100
|
-
getSignDoc(message) {
|
|
101
|
-
return {
|
|
102
|
-
account_number: '0',
|
|
103
|
-
chain_id: this.getChainId(),
|
|
104
|
-
fee: { amount: [], gas: '0' },
|
|
105
|
-
memo: '',
|
|
106
|
-
msgs: [{ type: 'custom/MsgSignText', value: { text: message } }],
|
|
107
|
-
sequence: '0',
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
signMessage(messageToSign) {
|
|
111
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
const signDoc = this.getSignDoc(messageToSign);
|
|
113
|
-
const address = yield this.getAddress();
|
|
114
|
-
const signatureResponse = yield this.keplr.signAmino(this.getChainId(), address, signDoc);
|
|
115
|
-
if (!signatureResponse)
|
|
116
|
-
throw new Error('Could not sign message');
|
|
117
|
-
return JSON.stringify(signatureResponse);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
supportsNetworkSwitching() {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
32
|
switchNetwork(_a) {
|
|
124
33
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
125
34
|
if (!networkChainId)
|
|
@@ -134,5 +43,4 @@ class KeplrWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
|
|
|
134
43
|
}
|
|
135
44
|
}
|
|
136
45
|
|
|
137
|
-
exports.DYNAMIC_KEPLR_NETWORK_ID = DYNAMIC_KEPLR_NETWORK_ID;
|
|
138
46
|
exports.KeplrWalletConnector = KeplrWalletConnector;
|
|
@@ -1,45 +1,16 @@
|
|
|
1
1
|
import { Keplr as KeplrWallet } from '@keplr-wallet/types';
|
|
2
|
-
import { CosmosWalletConnector
|
|
2
|
+
import { CosmosWalletConnector } from './CosmosWalletConnector';
|
|
3
3
|
export type SwitchNetworkOps = {
|
|
4
4
|
networkChainId?: number;
|
|
5
5
|
networkName?: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const DYNAMIC_KEPLR_NETWORK_ID = "dynamic_keplr_network_id";
|
|
8
7
|
export declare class KeplrWalletConnector extends CosmosWalletConnector {
|
|
9
|
-
switchNetworkOnlyFromWallet: boolean;
|
|
10
8
|
name: string;
|
|
11
9
|
overrideKey: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
setChainId(chainId: string | null): void;
|
|
16
|
-
protected getAccount(): Promise<import("@keplr-wallet/types").AccountData>;
|
|
17
|
-
get keplr(): KeplrWallet;
|
|
18
|
-
connect(): Promise<void>;
|
|
19
|
-
getAddress(): Promise<string>;
|
|
20
|
-
getProvider(): Promise<KeplrWallet>;
|
|
21
|
-
getOfflineSigner(): Promise<import("@keplr-wallet/types").OfflineAminoSigner & import("@keplr-wallet/types").OfflineDirectSigner>;
|
|
22
|
-
isInstalledOnBrowser(): boolean;
|
|
23
|
-
_handleAccountChange(): Promise<void>;
|
|
10
|
+
switchNetworkOnlyFromWallet: boolean;
|
|
11
|
+
supportsNetworkSwitching(): boolean;
|
|
12
|
+
getWallet(): KeplrWallet | undefined;
|
|
24
13
|
setupEventListeners(): void;
|
|
25
14
|
teardownEventListeners(): void;
|
|
26
|
-
protected getSignDoc(message: string): {
|
|
27
|
-
account_number: string;
|
|
28
|
-
chain_id: string;
|
|
29
|
-
fee: {
|
|
30
|
-
amount: never[];
|
|
31
|
-
gas: string;
|
|
32
|
-
};
|
|
33
|
-
memo: string;
|
|
34
|
-
msgs: {
|
|
35
|
-
type: string;
|
|
36
|
-
value: {
|
|
37
|
-
text: string;
|
|
38
|
-
};
|
|
39
|
-
}[];
|
|
40
|
-
sequence: string;
|
|
41
|
-
};
|
|
42
|
-
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
43
|
-
supportsNetworkSwitching(): boolean;
|
|
44
15
|
switchNetwork({ networkChainId, }: SwitchNetworkOps): Promise<void>;
|
|
45
16
|
}
|
|
@@ -2,89 +2,22 @@
|
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
3
|
import { CosmosWalletConnector } from './CosmosWalletConnector.js';
|
|
4
4
|
|
|
5
|
-
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_network_id';
|
|
6
5
|
class KeplrWalletConnector extends CosmosWalletConnector {
|
|
7
|
-
constructor(
|
|
8
|
-
super(
|
|
9
|
-
this.switchNetworkOnlyFromWallet = true;
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
10
8
|
this.name = 'Keplr';
|
|
11
9
|
this.overrideKey = 'keplr';
|
|
12
|
-
this.
|
|
13
|
-
}
|
|
14
|
-
getDefaultChainId() {
|
|
15
|
-
if (this.chainIdMapping.length === 0) {
|
|
16
|
-
return 'cosmoshub-4';
|
|
17
|
-
}
|
|
18
|
-
if (this.chainIdMapping.find((chain) => chain.cosmosNetworkId === 'cosmoshub-4')) {
|
|
19
|
-
return 'cosmoshub-4';
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return this.chainIdMapping[0].cosmosNetworkId;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
getChainId() {
|
|
26
|
-
const defaultChainId = this.getDefaultChainId();
|
|
27
|
-
const storedChainId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
28
|
-
return storedChainId !== null && storedChainId !== void 0 ? storedChainId : defaultChainId;
|
|
29
|
-
}
|
|
30
|
-
setChainId(chainId) {
|
|
31
|
-
if (!chainId) {
|
|
32
|
-
localStorage.removeItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
localStorage.setItem(DYNAMIC_KEPLR_NETWORK_ID, chainId);
|
|
36
|
-
}
|
|
10
|
+
this.switchNetworkOnlyFromWallet = true;
|
|
37
11
|
}
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
const accountsList = yield this.keplr
|
|
41
|
-
.getOfflineSigner(this.getChainId())
|
|
42
|
-
.getAccounts();
|
|
43
|
-
if (!accountsList)
|
|
44
|
-
throw new Error('No accounts found');
|
|
45
|
-
const [account] = accountsList;
|
|
46
|
-
return account;
|
|
47
|
-
});
|
|
12
|
+
supportsNetworkSwitching() {
|
|
13
|
+
return true;
|
|
48
14
|
}
|
|
49
|
-
|
|
50
|
-
if (typeof window === 'undefined')
|
|
15
|
+
getWallet() {
|
|
16
|
+
if (typeof window === 'undefined') {
|
|
51
17
|
throw new Error('Keplr is not available');
|
|
52
|
-
|
|
18
|
+
}
|
|
53
19
|
return window.keplr;
|
|
54
20
|
}
|
|
55
|
-
connect() {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
yield this.keplr.enable(this.chainIdMapping.map((mapping) => mapping.cosmosNetworkId));
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
getAddress() {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
yield this.connect();
|
|
63
|
-
const account = yield this.getAccount();
|
|
64
|
-
return account.address;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
getProvider() {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
return this.keplr;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
getOfflineSigner() {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
return this.keplr.getOfflineSigner(this.getChainId());
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
isInstalledOnBrowser() {
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
79
|
-
// @ts-ignore window.keplr is provided by extension
|
|
80
|
-
return typeof window.keplr !== 'undefined';
|
|
81
|
-
}
|
|
82
|
-
_handleAccountChange() {
|
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
const address = yield this.getAddress();
|
|
85
|
-
this.emit('accountChange', { accounts: [address] });
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
21
|
setupEventListeners() {
|
|
89
22
|
window.addEventListener('keplr_keystorechange', this._handleAccountChange);
|
|
90
23
|
}
|
|
@@ -92,30 +25,6 @@ class KeplrWalletConnector extends CosmosWalletConnector {
|
|
|
92
25
|
window.removeEventListener('keplr_keystorechange', this._handleAccountChange);
|
|
93
26
|
this.setChainId(null);
|
|
94
27
|
}
|
|
95
|
-
// SignDoc used for signAmin method;
|
|
96
|
-
getSignDoc(message) {
|
|
97
|
-
return {
|
|
98
|
-
account_number: '0',
|
|
99
|
-
chain_id: this.getChainId(),
|
|
100
|
-
fee: { amount: [], gas: '0' },
|
|
101
|
-
memo: '',
|
|
102
|
-
msgs: [{ type: 'custom/MsgSignText', value: { text: message } }],
|
|
103
|
-
sequence: '0',
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
signMessage(messageToSign) {
|
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
const signDoc = this.getSignDoc(messageToSign);
|
|
109
|
-
const address = yield this.getAddress();
|
|
110
|
-
const signatureResponse = yield this.keplr.signAmino(this.getChainId(), address, signDoc);
|
|
111
|
-
if (!signatureResponse)
|
|
112
|
-
throw new Error('Could not sign message');
|
|
113
|
-
return JSON.stringify(signatureResponse);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
supportsNetworkSwitching() {
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
28
|
switchNetwork(_a) {
|
|
120
29
|
return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
121
30
|
if (!networkChainId)
|
|
@@ -130,4 +39,4 @@ class KeplrWalletConnector extends CosmosWalletConnector {
|
|
|
130
39
|
}
|
|
131
40
|
}
|
|
132
41
|
|
|
133
|
-
export {
|
|
42
|
+
export { KeplrWalletConnector };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var CosmosWalletConnector = require('./CosmosWalletConnector.cjs');
|
|
7
|
+
|
|
8
|
+
class LeapWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.name = 'leapcosmos';
|
|
12
|
+
this.overrideKey = 'leapcosmos';
|
|
13
|
+
}
|
|
14
|
+
getWallet() {
|
|
15
|
+
if (typeof window === 'undefined')
|
|
16
|
+
throw new Error('Leap is not available');
|
|
17
|
+
return window.leap;
|
|
18
|
+
}
|
|
19
|
+
setupEventListeners() {
|
|
20
|
+
window.addEventListener('leap_keystorechange', this._handleAccountChange);
|
|
21
|
+
}
|
|
22
|
+
teardownEventListeners() {
|
|
23
|
+
window.removeEventListener('leap_keystorechange', this._handleAccountChange);
|
|
24
|
+
this.setChainId(null);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.LeapWalletConnector = LeapWalletConnector;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Keplr as KeplrWallet } from '@keplr-wallet/types';
|
|
2
|
+
import { CosmosWalletConnector } from './CosmosWalletConnector';
|
|
3
|
+
export declare class LeapWalletConnector extends CosmosWalletConnector {
|
|
4
|
+
name: string;
|
|
5
|
+
overrideKey: string;
|
|
6
|
+
protected getWallet(): KeplrWallet | undefined;
|
|
7
|
+
setupEventListeners(): void;
|
|
8
|
+
teardownEventListeners(): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { CosmosWalletConnector } from './CosmosWalletConnector.js';
|
|
3
|
+
|
|
4
|
+
class LeapWalletConnector extends CosmosWalletConnector {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.name = 'leapcosmos';
|
|
8
|
+
this.overrideKey = 'leapcosmos';
|
|
9
|
+
}
|
|
10
|
+
getWallet() {
|
|
11
|
+
if (typeof window === 'undefined')
|
|
12
|
+
throw new Error('Leap is not available');
|
|
13
|
+
return window.leap;
|
|
14
|
+
}
|
|
15
|
+
setupEventListeners() {
|
|
16
|
+
window.addEventListener('leap_keystorechange', this._handleAccountChange);
|
|
17
|
+
}
|
|
18
|
+
teardownEventListeners() {
|
|
19
|
+
window.removeEventListener('leap_keystorechange', this._handleAccountChange);
|
|
20
|
+
this.setChainId(null);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { LeapWalletConnector };
|
package/src/index.cjs
CHANGED
|
@@ -11,9 +11,15 @@ require('@dynamic-labs/utils');
|
|
|
11
11
|
require('@dynamic-labs/wallet-connector-core');
|
|
12
12
|
var CosmosWallet = require('./wallet/CosmosWallet.cjs');
|
|
13
13
|
var isCosmosWallet = require('./wallet/isCosmosWallet/isCosmosWallet.cjs');
|
|
14
|
+
var LeapWalletConnector = require('./connectors/LeapWalletConnector.cjs');
|
|
15
|
+
var CompassWalletConnector = require('./connectors/CompassWalletConnector.cjs');
|
|
14
16
|
|
|
15
17
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/cosmos', _package.version);
|
|
16
|
-
const CosmosWalletConnectors = () => [
|
|
18
|
+
const CosmosWalletConnectors = () => [
|
|
19
|
+
KeplrWalletConnector.KeplrWalletConnector,
|
|
20
|
+
LeapWalletConnector.LeapWalletConnector,
|
|
21
|
+
CompassWalletConnector.CompassWalletConnector,
|
|
22
|
+
];
|
|
17
23
|
|
|
18
24
|
exports.CosmosWallet = CosmosWallet.CosmosWallet;
|
|
19
25
|
exports.isCosmosWallet = isCosmosWallet.isCosmosWallet;
|
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { KeplrWalletConnector } from './connectors';
|
|
1
|
+
import { CompassWalletConnector, KeplrWalletConnector } from './connectors';
|
|
2
|
+
import { LeapWalletConnector } from './connectors/LeapWalletConnector';
|
|
2
3
|
export * from './wallet';
|
|
3
4
|
export { type ICosmosOfflineSigner, type ICosmosProvider } from './types';
|
|
4
5
|
export { type CosmosWalletConnector } from './connectors/CosmosWalletConnector';
|
|
5
|
-
export declare const CosmosWalletConnectors: () => (typeof KeplrWalletConnector)[];
|
|
6
|
+
export declare const CosmosWalletConnectors: () => (typeof KeplrWalletConnector | typeof LeapWalletConnector | typeof CompassWalletConnector)[];
|
package/src/index.js
CHANGED
|
@@ -7,8 +7,14 @@ import '@dynamic-labs/utils';
|
|
|
7
7
|
import '@dynamic-labs/wallet-connector-core';
|
|
8
8
|
export { CosmosWallet } from './wallet/CosmosWallet.js';
|
|
9
9
|
export { isCosmosWallet } from './wallet/isCosmosWallet/isCosmosWallet.js';
|
|
10
|
+
import { LeapWalletConnector } from './connectors/LeapWalletConnector.js';
|
|
11
|
+
import { CompassWalletConnector } from './connectors/CompassWalletConnector.js';
|
|
10
12
|
|
|
11
13
|
assertPackageVersion('@dynamic-labs/cosmos', version);
|
|
12
|
-
const CosmosWalletConnectors = () => [
|
|
14
|
+
const CosmosWalletConnectors = () => [
|
|
15
|
+
KeplrWalletConnector,
|
|
16
|
+
LeapWalletConnector,
|
|
17
|
+
CompassWalletConnector,
|
|
18
|
+
];
|
|
13
19
|
|
|
14
20
|
export { CosmosWalletConnectors };
|
package/src/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type Window as KeplrWindow, type Keplr as KeplrWallet, type OfflineAminoSigner, type OfflineDirectSigner } from '@keplr-wallet/types';
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window extends KeplrWindow {
|
|
4
|
+
leap?: KeplrWallet;
|
|
5
|
+
compass?: KeplrWallet;
|
|
4
6
|
}
|
|
5
7
|
}
|
|
6
8
|
export type ICosmosOfflineSigner = OfflineAminoSigner & OfflineDirectSigner;
|