@dynamic-labs/cosmos 3.0.0-alpha.51 → 3.0.0-alpha.53

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 CHANGED
@@ -1,4 +1,55 @@
1
1
 
2
+ ## [3.0.0-alpha.53](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.52...v3.0.0-alpha.53) (2024-08-29)
3
+
4
+
5
+ ### ⚠ BREAKING CHANGES
6
+
7
+ * simplify solana wallet signer types (#6748)
8
+ * deprecate getEoaConnector (#6571)
9
+ * limit methods and props returned by wallet.connector (#6540)
10
+ * move generic solana code to solana-core package (#6701)
11
+ * revamp ether v6 interface (#6548)
12
+ * add ethereum wallet specific methods and intercept to sync when needed (#6662)
13
+ * add solana wallet specific methods and intercept to sync when needed (#6608)
14
+ * don't force primary wallet to be connected (#6128)
15
+
16
+ ### Features
17
+
18
+ * add bitcoin wallet specific methods and intercept to sync when needed ([#6663](https://github.com/dynamic-labs/DynamicAuth/issues/6663)) ([ed699b1](https://github.com/dynamic-labs/DynamicAuth/commit/ed699b1f8c264755779ec4840d105f89ade5500e))
19
+ * add ethereum wallet specific methods and intercept to sync when needed ([#6662](https://github.com/dynamic-labs/DynamicAuth/issues/6662)) ([372360e](https://github.com/dynamic-labs/DynamicAuth/commit/372360ed7ca395f88811fc62c94b2b494eb59971))
20
+ * add solana wallet specific methods and intercept to sync when needed ([#6608](https://github.com/dynamic-labs/DynamicAuth/issues/6608)) ([565f610](https://github.com/dynamic-labs/DynamicAuth/commit/565f6100340296c267e9706fd263e9bd3f7d3732))
21
+ * add useSmartWallets hook to manage aa wallets ([#6564](https://github.com/dynamic-labs/DynamicAuth/issues/6564)) ([a243d36](https://github.com/dynamic-labs/DynamicAuth/commit/a243d361ce7c368d0f1afda55f9c1fabefd75ba8))
22
+ * don't force primary wallet to be connected ([#6128](https://github.com/dynamic-labs/DynamicAuth/issues/6128)) ([018a6f6](https://github.com/dynamic-labs/DynamicAuth/commit/018a6f66f8725914ab97ea3e2e1c80626266e503))
23
+ * new prop to enable prompt for linking when account change is detected ([#6713](https://github.com/dynamic-labs/DynamicAuth/issues/6713)) ([b5a6321](https://github.com/dynamic-labs/DynamicAuth/commit/b5a63212ae33fae24401f141d5ca2356b446dcff))
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * always sync wagmi client with primary wallet ([#6577](https://github.com/dynamic-labs/DynamicAuth/issues/6577)) ([be22fde](https://github.com/dynamic-labs/DynamicAuth/commit/be22fdea3bb61db79b06ba56cb32da6cd8141b66))
29
+ * cosmos wallet intercepts ([#6720](https://github.com/dynamic-labs/DynamicAuth/issues/6720)) ([cfc9df4](https://github.com/dynamic-labs/DynamicAuth/commit/cfc9df48a8032f7348fec14f77b9e378d2e26a22))
30
+ * magiceden wallet events not working correctly on page refresh ([#6735](https://github.com/dynamic-labs/DynamicAuth/issues/6735)) ([6ed5964](https://github.com/dynamic-labs/DynamicAuth/commit/6ed5964134a2cafd392c19f18eb71e6ca2ce238d))
31
+ * use proxy to intercept solana signer methods ([#6743](https://github.com/dynamic-labs/DynamicAuth/issues/6743)) ([ecbe5ea](https://github.com/dynamic-labs/DynamicAuth/commit/ecbe5ea772592d2c693d8222d85b7642acd151a8))
32
+ * wallet.chain references ([525c1ca](https://github.com/dynamic-labs/DynamicAuth/commit/525c1ca9a8fe6402c06eabe6aebc30e310411d9b))
33
+
34
+
35
+ * deprecate getEoaConnector ([#6571](https://github.com/dynamic-labs/DynamicAuth/issues/6571)) ([0226ee5](https://github.com/dynamic-labs/DynamicAuth/commit/0226ee5a13f2418607076ee6f2ec0a579b06dd5d))
36
+ * limit methods and props returned by wallet.connector ([#6540](https://github.com/dynamic-labs/DynamicAuth/issues/6540)) ([9c86e35](https://github.com/dynamic-labs/DynamicAuth/commit/9c86e35c72cd40313bfd19254dd6171ee8f62213))
37
+ * move generic solana code to solana-core package ([#6701](https://github.com/dynamic-labs/DynamicAuth/issues/6701)) ([30815f5](https://github.com/dynamic-labs/DynamicAuth/commit/30815f5d46feeefb2413c1b7d30b43d5370ee032))
38
+ * revamp ether v6 interface ([#6548](https://github.com/dynamic-labs/DynamicAuth/issues/6548)) ([f3b2fb8](https://github.com/dynamic-labs/DynamicAuth/commit/f3b2fb8da7de21f9c58e67fa7f5580166195092a))
39
+ * simplify solana wallet signer types ([#6748](https://github.com/dynamic-labs/DynamicAuth/issues/6748)) ([01d1a42](https://github.com/dynamic-labs/DynamicAuth/commit/01d1a42bc916ab329580b741ba60d706bf6c5491))
40
+
41
+ ## [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)
42
+
43
+
44
+ ### Features
45
+
46
+ * add support for custom keplr chains ([#6635](https://github.com/dynamic-labs/DynamicAuth/issues/6635)) ([f0aa2da](https://github.com/dynamic-labs/DynamicAuth/commit/f0aa2dac2a2b259d145ff52174da7cc6ef963182))
47
+
48
+
49
+ ### Bug Fixes
50
+
51
+ * 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))
52
+
2
53
  ## [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
54
 
4
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/cosmos",
3
- "version": "3.0.0-alpha.51",
3
+ "version": "3.0.0-alpha.53",
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.51",
31
- "@dynamic-labs/utils": "3.0.0-alpha.51",
32
- "@dynamic-labs/wallet-book": "3.0.0-alpha.51",
33
- "@dynamic-labs/wallet-connector-core": "3.0.0-alpha.51"
30
+ "@dynamic-labs/types": "3.0.0-alpha.53",
31
+ "@dynamic-labs/utils": "3.0.0-alpha.53",
32
+ "@dynamic-labs/wallet-book": "3.0.0-alpha.53",
33
+ "@dynamic-labs/wallet-connector-core": "3.0.0-alpha.53"
34
34
  },
35
35
  "peerDependencies": {}
36
36
  }
@@ -6,31 +6,29 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var _tslib = require('../../_virtual/_tslib.cjs');
7
7
  var utils = require('@dynamic-labs/utils');
8
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
+ var CosmosWallet = require('../wallet/CosmosWallet.cjs');
9
10
 
10
11
  class CosmosWalletConnector extends walletConnectorCore.WalletConnectorBase {
11
12
  constructor(opts) {
12
13
  super(opts);
14
+ this.ChainWallet = CosmosWallet.CosmosWallet;
13
15
  this.connectedChain = 'COSMOS';
14
16
  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
17
  this.evmNetworks = utils.parseEvmNetworks(opts.cosmosNetworks);
18
+ this.chainIdMapping = this.evmNetworks.map((network) => ({
19
+ cosmosNetworkId: network.name,
20
+ dynamicChainId: utils.parseChainId(network.networkId),
21
+ evmNetwork: network,
22
+ }));
26
23
  }
27
24
  getSelectedNetwork() {
28
- const selectedNetwork = this.evmNetworks.find((network) => network.networkId === this.reverseChainIdMap[this.getChainId()]);
29
- return selectedNetwork;
25
+ const selectedNetwork = this.chainIdMapping.find((mapping) => mapping.cosmosNetworkId === this.getChainId());
26
+ return selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.evmNetwork;
30
27
  }
31
28
  getNetwork() {
32
29
  return _tslib.__awaiter(this, void 0, void 0, function* () {
33
- return this.reverseChainIdMap[this.getChainId()];
30
+ var _a;
31
+ return (_a = this.getSelectedNetwork()) === null || _a === void 0 ? void 0 : _a.chainId;
34
32
  });
35
33
  }
36
34
  getLcdUrl() {
@@ -1,7 +1,8 @@
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';
4
+ import { ICosmosOfflineSigner, ICosmosProvider } from '../types';
5
+ import { CosmosWallet } from '../wallet';
5
6
  export interface IFetchBalanceResponse {
6
7
  balances: IFetchBalanceBalance[];
7
8
  pagination: IFetchBalancePagination;
@@ -18,17 +19,24 @@ export type CosmosWalletConnectorOpts = {
18
19
  cosmosNetworks: GenericNetwork[];
19
20
  walletBook: WalletBookSchema;
20
21
  };
22
+ type CosmosChainIDMapObject = {
23
+ dynamicChainId: number;
24
+ cosmosNetworkId: string;
25
+ evmNetwork: EvmNetwork;
26
+ };
21
27
  export declare abstract class CosmosWalletConnector extends WalletConnectorBase {
22
28
  evmNetworks: EvmNetwork[];
29
+ ChainWallet: typeof CosmosWallet;
23
30
  connectedChain: Chain;
24
31
  supportedChains: Chain[];
25
- chainIdMap: Record<number, CosmoNetwork>;
26
- reverseChainIdMap: Record<CosmoNetwork, number>;
32
+ chainIdMapping: CosmosChainIDMapObject[];
27
33
  constructor(opts: CosmosWalletConnectorOpts);
28
- abstract getChainId(): CosmoNetwork;
29
- abstract setChainId(chainId: CosmoNetwork | null): void;
34
+ abstract getChainId(): string;
35
+ abstract setChainId(chainId: string | null): void;
36
+ abstract getProvider(): Promise<ICosmosProvider | undefined>;
37
+ abstract getOfflineSigner(): Promise<ICosmosOfflineSigner>;
30
38
  getSelectedNetwork(): EvmNetwork | undefined;
31
- getNetwork(): Promise<number>;
39
+ getNetwork(): Promise<number | undefined>;
32
40
  getLcdUrl(): string | undefined;
33
41
  getDenom(): string | undefined;
34
42
  getBalance(address: string): Promise<string | undefined>;
@@ -36,3 +44,4 @@ export declare abstract class CosmosWalletConnector extends WalletConnectorBase
36
44
  getConnectedAccounts(): Promise<string[]>;
37
45
  endSession(): Promise<void>;
38
46
  }
47
+ export {};
@@ -1,32 +1,30 @@
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
+ import { CosmosWallet } from '../wallet/CosmosWallet.js';
5
6
 
6
7
  class CosmosWalletConnector extends WalletConnectorBase {
7
8
  constructor(opts) {
8
9
  super(opts);
10
+ this.ChainWallet = CosmosWallet;
9
11
  this.connectedChain = 'COSMOS';
10
12
  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
13
  this.evmNetworks = parseEvmNetworks(opts.cosmosNetworks);
14
+ this.chainIdMapping = this.evmNetworks.map((network) => ({
15
+ cosmosNetworkId: network.name,
16
+ dynamicChainId: parseChainId(network.networkId),
17
+ evmNetwork: network,
18
+ }));
22
19
  }
23
20
  getSelectedNetwork() {
24
- const selectedNetwork = this.evmNetworks.find((network) => network.networkId === this.reverseChainIdMap[this.getChainId()]);
25
- return selectedNetwork;
21
+ const selectedNetwork = this.chainIdMapping.find((mapping) => mapping.cosmosNetworkId === this.getChainId());
22
+ return selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.evmNetwork;
26
23
  }
27
24
  getNetwork() {
28
25
  return __awaiter(this, void 0, void 0, function* () {
29
- return this.reverseChainIdMap[this.getChainId()];
26
+ var _a;
27
+ return (_a = this.getSelectedNetwork()) === null || _a === void 0 ? void 0 : _a.chainId;
30
28
  });
31
29
  }
32
30
  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 = 'cosmoshub-4';
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
  }
@@ -28,9 +39,6 @@ class KeplrWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
28
39
  localStorage.setItem(DYNAMIC_KEPLR_NETWORK_ID, chainId);
29
40
  }
30
41
  }
31
- getWalletClient() {
32
- return this.keplr;
33
- }
34
42
  getAccount() {
35
43
  return _tslib.__awaiter(this, void 0, void 0, function* () {
36
44
  const accountsList = yield this.keplr
@@ -50,9 +58,7 @@ class KeplrWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
50
58
  }
51
59
  connect() {
52
60
  return _tslib.__awaiter(this, void 0, void 0, function* () {
53
- const chainIdsToConnect = this.evmNetworks.map((network) => this.chainIdMap[network.chainId]);
54
- yield this.keplr.enable(chainIdsToConnect);
55
- this.setChainId(this.chainIdMap[this.evmNetworks[0].chainId]);
61
+ yield this.keplr.enable(this.chainIdMapping.map((mapping) => mapping.cosmosNetworkId));
56
62
  });
57
63
  }
58
64
  getAddress() {
@@ -62,7 +68,12 @@ class KeplrWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
62
68
  return account.address;
63
69
  });
64
70
  }
65
- getSigner() {
71
+ getProvider() {
72
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
73
+ return this.keplr;
74
+ });
75
+ }
76
+ getOfflineSigner() {
66
77
  return _tslib.__awaiter(this, void 0, void 0, function* () {
67
78
  return this.keplr.getOfflineSigner(this.getChainId());
68
79
  });
@@ -113,8 +124,12 @@ class KeplrWalletConnector extends CosmosWalletConnector.CosmosWalletConnector {
113
124
  return _tslib.__awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
114
125
  if (!networkChainId)
115
126
  return;
116
- this.setChainId(this.chainIdMap[networkChainId]);
117
- this.emit('chainChange', { chain: networkChainId.toString() });
127
+ this.chainIdMapping.forEach((mapping) => {
128
+ if (mapping.dynamicChainId === networkChainId) {
129
+ this.setChainId(mapping.cosmosNetworkId);
130
+ this.emit('chainChange', { chain: networkChainId.toString() });
131
+ }
132
+ });
118
133
  });
119
134
  }
120
135
  }
@@ -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,21 +10,22 @@ export declare class KeplrWalletConnector extends CosmosWalletConnector {
11
10
  name: string;
12
11
  overrideKey: string;
13
12
  constructor(opts: CosmosWalletConnectorOpts);
14
- getChainId(): CosmoNetwork;
15
- setChainId(chainId: CosmoNetwork | null): void;
16
- getWalletClient(): KeplrWallet;
13
+ getDefaultChainId(): string;
14
+ getChainId(): string;
15
+ setChainId(chainId: string | null): void;
17
16
  protected getAccount(): Promise<import("@keplr-wallet/types").AccountData>;
18
17
  get keplr(): KeplrWallet;
19
18
  connect(): Promise<void>;
20
19
  getAddress(): Promise<string>;
21
- getSigner(): Promise<import("@keplr-wallet/types").OfflineAminoSigner & import("@keplr-wallet/types").OfflineDirectSigner>;
20
+ getProvider(): Promise<KeplrWallet>;
21
+ getOfflineSigner(): Promise<import("@keplr-wallet/types").OfflineAminoSigner & import("@keplr-wallet/types").OfflineDirectSigner>;
22
22
  isInstalledOnBrowser(): boolean;
23
23
  _handleAccountChange(): Promise<void>;
24
24
  setupEventListeners(): void;
25
25
  teardownEventListeners(): void;
26
26
  protected getSignDoc(message: string): {
27
27
  account_number: string;
28
- chain_id: CosmoNetwork;
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 = 'cosmoshub-4';
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
  }
@@ -24,9 +35,6 @@ class KeplrWalletConnector extends CosmosWalletConnector {
24
35
  localStorage.setItem(DYNAMIC_KEPLR_NETWORK_ID, chainId);
25
36
  }
26
37
  }
27
- getWalletClient() {
28
- return this.keplr;
29
- }
30
38
  getAccount() {
31
39
  return __awaiter(this, void 0, void 0, function* () {
32
40
  const accountsList = yield this.keplr
@@ -46,9 +54,7 @@ class KeplrWalletConnector extends CosmosWalletConnector {
46
54
  }
47
55
  connect() {
48
56
  return __awaiter(this, void 0, void 0, function* () {
49
- const chainIdsToConnect = this.evmNetworks.map((network) => this.chainIdMap[network.chainId]);
50
- yield this.keplr.enable(chainIdsToConnect);
51
- this.setChainId(this.chainIdMap[this.evmNetworks[0].chainId]);
57
+ yield this.keplr.enable(this.chainIdMapping.map((mapping) => mapping.cosmosNetworkId));
52
58
  });
53
59
  }
54
60
  getAddress() {
@@ -58,7 +64,12 @@ class KeplrWalletConnector extends CosmosWalletConnector {
58
64
  return account.address;
59
65
  });
60
66
  }
61
- getSigner() {
67
+ getProvider() {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return this.keplr;
70
+ });
71
+ }
72
+ getOfflineSigner() {
62
73
  return __awaiter(this, void 0, void 0, function* () {
63
74
  return this.keplr.getOfflineSigner(this.getChainId());
64
75
  });
@@ -109,8 +120,12 @@ class KeplrWalletConnector extends CosmosWalletConnector {
109
120
  return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
110
121
  if (!networkChainId)
111
122
  return;
112
- this.setChainId(this.chainIdMap[networkChainId]);
113
- this.emit('chainChange', { chain: networkChainId.toString() });
123
+ this.chainIdMapping.forEach((mapping) => {
124
+ if (mapping.dynamicChainId === networkChainId) {
125
+ this.setChainId(mapping.cosmosNetworkId);
126
+ this.emit('chainChange', { chain: networkChainId.toString() });
127
+ }
128
+ });
114
129
  });
115
130
  }
116
131
  }
package/src/index.cjs CHANGED
@@ -7,7 +7,11 @@ var KeplrWalletConnector = require('./connectors/KeplrWalletConnector.cjs');
7
7
  require('../_virtual/_tslib.cjs');
8
8
  require('@dynamic-labs/utils');
9
9
  require('@dynamic-labs/wallet-connector-core');
10
+ var CosmosWallet = require('./wallet/CosmosWallet.cjs');
11
+ var isCosmosWallet = require('./wallet/isCosmosWallet/isCosmosWallet.cjs');
10
12
 
11
13
  const CosmosWalletConnectors = () => [KeplrWalletConnector.KeplrWalletConnector];
12
14
 
15
+ exports.CosmosWallet = CosmosWallet.CosmosWallet;
16
+ exports.isCosmosWallet = isCosmosWallet.isCosmosWallet;
13
17
  exports.CosmosWalletConnectors = CosmosWalletConnectors;
package/src/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  import { KeplrWalletConnector } from './connectors';
2
+ export * from './wallet';
3
+ export { type ICosmosOfflineSigner, type ICosmosProvider } from './types';
2
4
  export declare const CosmosWalletConnectors: () => (typeof KeplrWalletConnector)[];
package/src/index.js CHANGED
@@ -3,6 +3,8 @@ import { KeplrWalletConnector } from './connectors/KeplrWalletConnector.js';
3
3
  import '../_virtual/_tslib.js';
4
4
  import '@dynamic-labs/utils';
5
5
  import '@dynamic-labs/wallet-connector-core';
6
+ export { CosmosWallet } from './wallet/CosmosWallet.js';
7
+ export { isCosmosWallet } from './wallet/isCosmosWallet/isCosmosWallet.js';
6
8
 
7
9
  const CosmosWalletConnectors = () => [KeplrWalletConnector];
8
10
 
package/src/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Window as KeplrWindow } from '@keplr-wallet/types';
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
4
  }
5
5
  }
6
- export type CosmoNetwork = 'cosmoshub-4' | 'axelar-dojo-1' | 'osmosis-1';
6
+ export type ICosmosOfflineSigner = OfflineAminoSigner & OfflineDirectSigner;
7
+ export type ICosmosProvider = KeplrWallet;
@@ -0,0 +1,100 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
+
9
+ class CosmosWallet extends walletConnectorCore.Wallet {
10
+ getProvider() {
11
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
12
+ const provider = yield this._connector.getProvider();
13
+ if (!provider) {
14
+ throw new Error('unable to retrieve Cosmos provider');
15
+ }
16
+ const proxyProvider = new Proxy(provider, {
17
+ get: (target, prop) => {
18
+ if (prop === 'signAmino') {
19
+ return (chainId, signer, signerDoc, signerOperations) => _tslib.__awaiter(this, void 0, void 0, function* () {
20
+ yield this.sync();
21
+ return target.signAmino(chainId, signer, signerDoc, signerOperations);
22
+ });
23
+ }
24
+ if (prop === 'signDirect') {
25
+ return (chainId, signer, signDoc, signOptions) => _tslib.__awaiter(this, void 0, void 0, function* () {
26
+ yield this.sync();
27
+ return target.signDirect(chainId, signer, signDoc, signOptions);
28
+ });
29
+ }
30
+ if (prop === 'signDirectAux') {
31
+ return (chainId, signer, signDoc, signOptions) => _tslib.__awaiter(this, void 0, void 0, function* () {
32
+ yield this.sync();
33
+ return target.signDirectAux(chainId, signer, signDoc, signOptions);
34
+ });
35
+ }
36
+ if (prop === 'sendTx') {
37
+ return (chainId, tx, mode) => _tslib.__awaiter(this, void 0, void 0, function* () {
38
+ yield this.sync();
39
+ return target.sendTx(chainId, tx, mode);
40
+ });
41
+ }
42
+ if (prop === 'signICNSAdr36') {
43
+ return (chainId, contractAddress, owner, username, addressChainIds) => _tslib.__awaiter(this, void 0, void 0, function* () {
44
+ yield this.sync();
45
+ return target.signICNSAdr36(chainId, contractAddress, owner, username, addressChainIds);
46
+ });
47
+ }
48
+ if (prop === 'signArbitrary') {
49
+ return (chainId, signer, data) => _tslib.__awaiter(this, void 0, void 0, function* () {
50
+ yield this.sync();
51
+ return target.signArbitrary(chainId, signer, data);
52
+ });
53
+ }
54
+ if (prop === 'signEthereum') {
55
+ return (chainId, signer, data, type) => _tslib.__awaiter(this, void 0, void 0, function* () {
56
+ yield this.sync();
57
+ return target.signEthereum(chainId, signer, data, type);
58
+ });
59
+ }
60
+ if (prop === 'sendEthereumTx') {
61
+ return (chainId, tx) => _tslib.__awaiter(this, void 0, void 0, function* () {
62
+ yield this.sync();
63
+ return target.sendEthereumTx(chainId, tx);
64
+ });
65
+ }
66
+ return Reflect.get(target, prop);
67
+ },
68
+ });
69
+ return proxyProvider;
70
+ });
71
+ }
72
+ getOfflineSigner() {
73
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
74
+ const offlineSigner = yield this._connector.getOfflineSigner();
75
+ if (!offlineSigner) {
76
+ throw new Error('unable to retrieve Cosmos offline signer');
77
+ }
78
+ const proxyOfflineSigner = new Proxy(offlineSigner, {
79
+ get: (target, prop) => {
80
+ if (prop === 'signAmino') {
81
+ return (signerAddress, signerDoc) => _tslib.__awaiter(this, void 0, void 0, function* () {
82
+ yield this.sync();
83
+ return target.signAmino(signerAddress, signerDoc);
84
+ });
85
+ }
86
+ if (prop === 'signDirect') {
87
+ return (signerAddress, signerDoc) => _tslib.__awaiter(this, void 0, void 0, function* () {
88
+ yield this.sync();
89
+ return target.signDirect(signerAddress, signerDoc);
90
+ });
91
+ }
92
+ return Reflect.get(target, prop);
93
+ },
94
+ });
95
+ return proxyOfflineSigner;
96
+ });
97
+ }
98
+ }
99
+
100
+ exports.CosmosWallet = CosmosWallet;
@@ -0,0 +1,7 @@
1
+ import { Wallet } from '@dynamic-labs/wallet-connector-core';
2
+ import { CosmosWalletConnector } from '../connectors';
3
+ import { ICosmosOfflineSigner, ICosmosProvider } from '../types';
4
+ export declare class CosmosWallet extends Wallet<CosmosWalletConnector> {
5
+ getProvider(): Promise<ICosmosProvider>;
6
+ getOfflineSigner(): Promise<ICosmosOfflineSigner>;
7
+ }
@@ -0,0 +1,96 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { Wallet } from '@dynamic-labs/wallet-connector-core';
4
+
5
+ class CosmosWallet extends Wallet {
6
+ getProvider() {
7
+ return __awaiter(this, void 0, void 0, function* () {
8
+ const provider = yield this._connector.getProvider();
9
+ if (!provider) {
10
+ throw new Error('unable to retrieve Cosmos provider');
11
+ }
12
+ const proxyProvider = new Proxy(provider, {
13
+ get: (target, prop) => {
14
+ if (prop === 'signAmino') {
15
+ return (chainId, signer, signerDoc, signerOperations) => __awaiter(this, void 0, void 0, function* () {
16
+ yield this.sync();
17
+ return target.signAmino(chainId, signer, signerDoc, signerOperations);
18
+ });
19
+ }
20
+ if (prop === 'signDirect') {
21
+ return (chainId, signer, signDoc, signOptions) => __awaiter(this, void 0, void 0, function* () {
22
+ yield this.sync();
23
+ return target.signDirect(chainId, signer, signDoc, signOptions);
24
+ });
25
+ }
26
+ if (prop === 'signDirectAux') {
27
+ return (chainId, signer, signDoc, signOptions) => __awaiter(this, void 0, void 0, function* () {
28
+ yield this.sync();
29
+ return target.signDirectAux(chainId, signer, signDoc, signOptions);
30
+ });
31
+ }
32
+ if (prop === 'sendTx') {
33
+ return (chainId, tx, mode) => __awaiter(this, void 0, void 0, function* () {
34
+ yield this.sync();
35
+ return target.sendTx(chainId, tx, mode);
36
+ });
37
+ }
38
+ if (prop === 'signICNSAdr36') {
39
+ return (chainId, contractAddress, owner, username, addressChainIds) => __awaiter(this, void 0, void 0, function* () {
40
+ yield this.sync();
41
+ return target.signICNSAdr36(chainId, contractAddress, owner, username, addressChainIds);
42
+ });
43
+ }
44
+ if (prop === 'signArbitrary') {
45
+ return (chainId, signer, data) => __awaiter(this, void 0, void 0, function* () {
46
+ yield this.sync();
47
+ return target.signArbitrary(chainId, signer, data);
48
+ });
49
+ }
50
+ if (prop === 'signEthereum') {
51
+ return (chainId, signer, data, type) => __awaiter(this, void 0, void 0, function* () {
52
+ yield this.sync();
53
+ return target.signEthereum(chainId, signer, data, type);
54
+ });
55
+ }
56
+ if (prop === 'sendEthereumTx') {
57
+ return (chainId, tx) => __awaiter(this, void 0, void 0, function* () {
58
+ yield this.sync();
59
+ return target.sendEthereumTx(chainId, tx);
60
+ });
61
+ }
62
+ return Reflect.get(target, prop);
63
+ },
64
+ });
65
+ return proxyProvider;
66
+ });
67
+ }
68
+ getOfflineSigner() {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ const offlineSigner = yield this._connector.getOfflineSigner();
71
+ if (!offlineSigner) {
72
+ throw new Error('unable to retrieve Cosmos offline signer');
73
+ }
74
+ const proxyOfflineSigner = new Proxy(offlineSigner, {
75
+ get: (target, prop) => {
76
+ if (prop === 'signAmino') {
77
+ return (signerAddress, signerDoc) => __awaiter(this, void 0, void 0, function* () {
78
+ yield this.sync();
79
+ return target.signAmino(signerAddress, signerDoc);
80
+ });
81
+ }
82
+ if (prop === 'signDirect') {
83
+ return (signerAddress, signerDoc) => __awaiter(this, void 0, void 0, function* () {
84
+ yield this.sync();
85
+ return target.signDirect(signerAddress, signerDoc);
86
+ });
87
+ }
88
+ return Reflect.get(target, prop);
89
+ },
90
+ });
91
+ return proxyOfflineSigner;
92
+ });
93
+ }
94
+ }
95
+
96
+ export { CosmosWallet };
@@ -0,0 +1,2 @@
1
+ export * from './CosmosWallet';
2
+ export * from './isCosmosWallet';
@@ -0,0 +1 @@
1
+ export * from './isCosmosWallet';
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const isCosmosWallet = (wallet) => wallet.chain === 'COSMOS';
7
+
8
+ exports.isCosmosWallet = isCosmosWallet;
@@ -0,0 +1,3 @@
1
+ import { Wallet } from '@dynamic-labs/wallet-connector-core';
2
+ import { CosmosWallet } from '../CosmosWallet';
3
+ export declare const isCosmosWallet: (wallet: Wallet) => wallet is CosmosWallet;
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const isCosmosWallet = (wallet) => wallet.chain === 'COSMOS';
3
+
4
+ export { isCosmosWallet };