@dynamic-labs/cosmos 3.0.0-alpha.51 → 3.0.0-alpha.52
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 +12 -0
- package/package.json +5 -5
- package/src/connectors/CosmosWalletConnector.cjs +9 -13
- package/src/connectors/CosmosWalletConnector.d.ts +10 -6
- package/src/connectors/CosmosWalletConnector.js +10 -14
- package/src/connectors/KeplrWalletConnector.cjs +19 -6
- package/src/connectors/KeplrWalletConnector.d.ts +4 -4
- package/src/connectors/KeplrWalletConnector.js +19 -6
- package/src/types.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.0.0-alpha.52](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.51...v3.0.0-alpha.52) (2024-08-28)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add support for custom keplr chains ([#6635](https://github.com/dynamic-labs/DynamicAuth/issues/6635)) ([f0aa2da](https://github.com/dynamic-labs/DynamicAuth/commit/f0aa2dac2a2b259d145ff52174da7cc6ef963182))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* better error handling on solana transaction decoding ([#6731](https://github.com/dynamic-labs/DynamicAuth/issues/6731)) ([a71af86](https://github.com/dynamic-labs/DynamicAuth/commit/a71af869395c9b99c04f0cac78a73e1b2b17bafe))
|
|
13
|
+
|
|
2
14
|
## [3.0.0-alpha.51](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.50...v3.0.0-alpha.51) (2024-08-23)
|
|
3
15
|
|
|
4
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/cosmos",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.52",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@keplr-wallet/types": "0.12.121",
|
|
30
|
-
"@dynamic-labs/types": "3.0.0-alpha.
|
|
31
|
-
"@dynamic-labs/utils": "3.0.0-alpha.
|
|
32
|
-
"@dynamic-labs/wallet-book": "3.0.0-alpha.
|
|
33
|
-
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.
|
|
30
|
+
"@dynamic-labs/types": "3.0.0-alpha.52",
|
|
31
|
+
"@dynamic-labs/utils": "3.0.0-alpha.52",
|
|
32
|
+
"@dynamic-labs/wallet-book": "3.0.0-alpha.52",
|
|
33
|
+
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.52"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {}
|
|
36
36
|
}
|
|
@@ -12,25 +12,21 @@ class CosmosWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
12
12
|
super(opts);
|
|
13
13
|
this.connectedChain = 'COSMOS';
|
|
14
14
|
this.supportedChains = ['COSMOS'];
|
|
15
|
-
this.chainIdMap = {
|
|
16
|
-
401: 'cosmoshub-4',
|
|
17
|
-
402: 'axelar-dojo-1',
|
|
18
|
-
403: 'osmosis-1',
|
|
19
|
-
};
|
|
20
|
-
this.reverseChainIdMap = {
|
|
21
|
-
'axelar-dojo-1': 402,
|
|
22
|
-
'cosmoshub-4': 401,
|
|
23
|
-
'osmosis-1': 403,
|
|
24
|
-
};
|
|
25
15
|
this.evmNetworks = utils.parseEvmNetworks(opts.cosmosNetworks);
|
|
16
|
+
this.chainIdMapping = this.evmNetworks.map((network) => ({
|
|
17
|
+
cosmosNetworkId: network.name,
|
|
18
|
+
dynamicChainId: utils.parseChainId(network.networkId),
|
|
19
|
+
evmNetwork: network,
|
|
20
|
+
}));
|
|
26
21
|
}
|
|
27
22
|
getSelectedNetwork() {
|
|
28
|
-
const selectedNetwork = this.
|
|
29
|
-
return selectedNetwork;
|
|
23
|
+
const selectedNetwork = this.chainIdMapping.find((mapping) => mapping.cosmosNetworkId === this.getChainId());
|
|
24
|
+
return selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.evmNetwork;
|
|
30
25
|
}
|
|
31
26
|
getNetwork() {
|
|
32
27
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
|
|
28
|
+
var _a;
|
|
29
|
+
return (_a = this.getSelectedNetwork()) === null || _a === void 0 ? void 0 : _a.chainId;
|
|
34
30
|
});
|
|
35
31
|
}
|
|
36
32
|
getLcdUrl() {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { EvmNetwork, GenericNetwork } from '@dynamic-labs/types';
|
|
2
2
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
3
3
|
import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
-
import { CosmoNetwork } from '../types';
|
|
5
4
|
export interface IFetchBalanceResponse {
|
|
6
5
|
balances: IFetchBalanceBalance[];
|
|
7
6
|
pagination: IFetchBalancePagination;
|
|
@@ -18,17 +17,21 @@ export type CosmosWalletConnectorOpts = {
|
|
|
18
17
|
cosmosNetworks: GenericNetwork[];
|
|
19
18
|
walletBook: WalletBookSchema;
|
|
20
19
|
};
|
|
20
|
+
type CosmosChainIDMapObject = {
|
|
21
|
+
dynamicChainId: number;
|
|
22
|
+
cosmosNetworkId: string;
|
|
23
|
+
evmNetwork: EvmNetwork;
|
|
24
|
+
};
|
|
21
25
|
export declare abstract class CosmosWalletConnector extends WalletConnectorBase {
|
|
22
26
|
evmNetworks: EvmNetwork[];
|
|
23
27
|
connectedChain: Chain;
|
|
24
28
|
supportedChains: Chain[];
|
|
25
|
-
|
|
26
|
-
reverseChainIdMap: Record<CosmoNetwork, number>;
|
|
29
|
+
chainIdMapping: CosmosChainIDMapObject[];
|
|
27
30
|
constructor(opts: CosmosWalletConnectorOpts);
|
|
28
|
-
abstract getChainId():
|
|
29
|
-
abstract setChainId(chainId:
|
|
31
|
+
abstract getChainId(): string;
|
|
32
|
+
abstract setChainId(chainId: string | null): void;
|
|
30
33
|
getSelectedNetwork(): EvmNetwork | undefined;
|
|
31
|
-
getNetwork(): Promise<number>;
|
|
34
|
+
getNetwork(): Promise<number | undefined>;
|
|
32
35
|
getLcdUrl(): string | undefined;
|
|
33
36
|
getDenom(): string | undefined;
|
|
34
37
|
getBalance(address: string): Promise<string | undefined>;
|
|
@@ -36,3 +39,4 @@ export declare abstract class CosmosWalletConnector extends WalletConnectorBase
|
|
|
36
39
|
getConnectedAccounts(): Promise<string[]>;
|
|
37
40
|
endSession(): Promise<void>;
|
|
38
41
|
}
|
|
42
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
-
import { parseEvmNetworks } from '@dynamic-labs/utils';
|
|
3
|
+
import { parseEvmNetworks, parseChainId } from '@dynamic-labs/utils';
|
|
4
4
|
import { WalletConnectorBase, logger } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
|
|
6
6
|
class CosmosWalletConnector extends WalletConnectorBase {
|
|
@@ -8,25 +8,21 @@ class CosmosWalletConnector extends WalletConnectorBase {
|
|
|
8
8
|
super(opts);
|
|
9
9
|
this.connectedChain = 'COSMOS';
|
|
10
10
|
this.supportedChains = ['COSMOS'];
|
|
11
|
-
this.chainIdMap = {
|
|
12
|
-
401: 'cosmoshub-4',
|
|
13
|
-
402: 'axelar-dojo-1',
|
|
14
|
-
403: 'osmosis-1',
|
|
15
|
-
};
|
|
16
|
-
this.reverseChainIdMap = {
|
|
17
|
-
'axelar-dojo-1': 402,
|
|
18
|
-
'cosmoshub-4': 401,
|
|
19
|
-
'osmosis-1': 403,
|
|
20
|
-
};
|
|
21
11
|
this.evmNetworks = parseEvmNetworks(opts.cosmosNetworks);
|
|
12
|
+
this.chainIdMapping = this.evmNetworks.map((network) => ({
|
|
13
|
+
cosmosNetworkId: network.name,
|
|
14
|
+
dynamicChainId: parseChainId(network.networkId),
|
|
15
|
+
evmNetwork: network,
|
|
16
|
+
}));
|
|
22
17
|
}
|
|
23
18
|
getSelectedNetwork() {
|
|
24
|
-
const selectedNetwork = this.
|
|
25
|
-
return selectedNetwork;
|
|
19
|
+
const selectedNetwork = this.chainIdMapping.find((mapping) => mapping.cosmosNetworkId === this.getChainId());
|
|
20
|
+
return selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.evmNetwork;
|
|
26
21
|
}
|
|
27
22
|
getNetwork() {
|
|
28
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = this.getSelectedNetwork()) === null || _a === void 0 ? void 0 : _a.chainId;
|
|
30
26
|
});
|
|
31
27
|
}
|
|
32
28
|
getLcdUrl() {
|
|
@@ -15,8 +15,19 @@ class KeplrWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
|
|
|
15
15
|
this.overrideKey = 'keplr';
|
|
16
16
|
this._handleAccountChange = this._handleAccountChange.bind(this);
|
|
17
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
|
+
}
|
|
18
29
|
getChainId() {
|
|
19
|
-
const defaultChainId =
|
|
30
|
+
const defaultChainId = this.getDefaultChainId();
|
|
20
31
|
const storedChainId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
21
32
|
return storedChainId !== null && storedChainId !== void 0 ? storedChainId : defaultChainId;
|
|
22
33
|
}
|
|
@@ -50,9 +61,7 @@ class KeplrWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
|
|
|
50
61
|
}
|
|
51
62
|
connect() {
|
|
52
63
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
|
|
54
|
-
yield this.keplr.enable(chainIdsToConnect);
|
|
55
|
-
this.setChainId(this.chainIdMap[this.evmNetworks[0].chainId]);
|
|
64
|
+
yield this.keplr.enable(this.chainIdMapping.map((mapping) => mapping.cosmosNetworkId));
|
|
56
65
|
});
|
|
57
66
|
}
|
|
58
67
|
getAddress() {
|
|
@@ -113,8 +122,12 @@ class KeplrWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
|
|
|
113
122
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
114
123
|
if (!networkChainId)
|
|
115
124
|
return;
|
|
116
|
-
this.
|
|
117
|
-
|
|
125
|
+
this.chainIdMapping.forEach((mapping) => {
|
|
126
|
+
if (mapping.dynamicChainId === networkChainId) {
|
|
127
|
+
this.setChainId(mapping.cosmosNetworkId);
|
|
128
|
+
this.emit('chainChange', { chain: networkChainId.toString() });
|
|
129
|
+
}
|
|
130
|
+
});
|
|
118
131
|
});
|
|
119
132
|
}
|
|
120
133
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Keplr as KeplrWallet } from '@keplr-wallet/types';
|
|
2
|
-
import { CosmoNetwork } from '../types';
|
|
3
2
|
import { CosmosWalletConnector, CosmosWalletConnectorOpts } from './CosmosWalletConnector';
|
|
4
3
|
export type SwitchNetworkOps = {
|
|
5
4
|
networkChainId?: number;
|
|
@@ -11,8 +10,9 @@ export declare class KeplrWalletConnector extends CosmosWalletConnector {
|
|
|
11
10
|
name: string;
|
|
12
11
|
overrideKey: string;
|
|
13
12
|
constructor(opts: CosmosWalletConnectorOpts);
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
getDefaultChainId(): string;
|
|
14
|
+
getChainId(): string;
|
|
15
|
+
setChainId(chainId: string | null): void;
|
|
16
16
|
getWalletClient(): KeplrWallet;
|
|
17
17
|
protected getAccount(): Promise<import("@keplr-wallet/types").AccountData>;
|
|
18
18
|
get keplr(): KeplrWallet;
|
|
@@ -25,7 +25,7 @@ export declare class KeplrWalletConnector extends CosmosWalletConnector {
|
|
|
25
25
|
teardownEventListeners(): void;
|
|
26
26
|
protected getSignDoc(message: string): {
|
|
27
27
|
account_number: string;
|
|
28
|
-
chain_id:
|
|
28
|
+
chain_id: string;
|
|
29
29
|
fee: {
|
|
30
30
|
amount: never[];
|
|
31
31
|
gas: string;
|
|
@@ -11,8 +11,19 @@ class KeplrWalletConnector extends CosmosWalletConnector {
|
|
|
11
11
|
this.overrideKey = 'keplr';
|
|
12
12
|
this._handleAccountChange = this._handleAccountChange.bind(this);
|
|
13
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
|
+
}
|
|
14
25
|
getChainId() {
|
|
15
|
-
const defaultChainId =
|
|
26
|
+
const defaultChainId = this.getDefaultChainId();
|
|
16
27
|
const storedChainId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
17
28
|
return storedChainId !== null && storedChainId !== void 0 ? storedChainId : defaultChainId;
|
|
18
29
|
}
|
|
@@ -46,9 +57,7 @@ class KeplrWalletConnector extends CosmosWalletConnector {
|
|
|
46
57
|
}
|
|
47
58
|
connect() {
|
|
48
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
|
|
50
|
-
yield this.keplr.enable(chainIdsToConnect);
|
|
51
|
-
this.setChainId(this.chainIdMap[this.evmNetworks[0].chainId]);
|
|
60
|
+
yield this.keplr.enable(this.chainIdMapping.map((mapping) => mapping.cosmosNetworkId));
|
|
52
61
|
});
|
|
53
62
|
}
|
|
54
63
|
getAddress() {
|
|
@@ -109,8 +118,12 @@ class KeplrWalletConnector extends CosmosWalletConnector {
|
|
|
109
118
|
return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
110
119
|
if (!networkChainId)
|
|
111
120
|
return;
|
|
112
|
-
this.
|
|
113
|
-
|
|
121
|
+
this.chainIdMapping.forEach((mapping) => {
|
|
122
|
+
if (mapping.dynamicChainId === networkChainId) {
|
|
123
|
+
this.setChainId(mapping.cosmosNetworkId);
|
|
124
|
+
this.emit('chainChange', { chain: networkChainId.toString() });
|
|
125
|
+
}
|
|
126
|
+
});
|
|
114
127
|
});
|
|
115
128
|
}
|
|
116
129
|
}
|
package/src/types.d.ts
CHANGED