cosmos-connect-core 0.1.0

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.
Files changed (54) hide show
  1. package/dist/adapters/CosmostationWallet.d.ts +40 -0
  2. package/dist/adapters/CosmostationWallet.js +68 -0
  3. package/dist/adapters/GalaxyStationWallet.d.ts +34 -0
  4. package/dist/adapters/GalaxyStationWallet.js +64 -0
  5. package/dist/adapters/KeplrWallet.d.ts +36 -0
  6. package/dist/adapters/KeplrWallet.js +85 -0
  7. package/dist/adapters/LUNCDashWallet.d.ts +6 -0
  8. package/dist/adapters/LUNCDashWallet.js +19 -0
  9. package/dist/adapters/LeapWallet.d.ts +33 -0
  10. package/dist/adapters/LeapWallet.js +64 -0
  11. package/dist/adapters/StationWallet.d.ts +34 -0
  12. package/dist/adapters/StationWallet.js +67 -0
  13. package/dist/adapters/WalletConnectWallet.d.ts +27 -0
  14. package/dist/adapters/WalletConnectWallet.js +89 -0
  15. package/dist/adapters/utils/QRCodeModal.d.ts +20 -0
  16. package/dist/adapters/utils/QRCodeModal.js +50 -0
  17. package/dist/adapters/utils/WalletConnectV2.d.ts +52 -0
  18. package/dist/adapters/utils/WalletConnectV2.js +284 -0
  19. package/dist/adapters/utils/os.d.ts +1 -0
  20. package/dist/adapters/utils/os.js +1 -0
  21. package/dist/core/account.d.ts +1 -0
  22. package/dist/core/account.js +7 -0
  23. package/dist/core/chain.d.ts +4 -0
  24. package/dist/core/chain.js +11 -0
  25. package/dist/core/createClient.d.ts +2 -0
  26. package/dist/core/createClient.js +157 -0
  27. package/dist/core/storage.d.ts +2 -0
  28. package/dist/core/storage.js +18 -0
  29. package/dist/core/types.d.ts +55 -0
  30. package/dist/core/types.js +1 -0
  31. package/dist/core/wallet.d.ts +2 -0
  32. package/dist/core/wallet.js +3 -0
  33. package/dist/index.d.ts +11 -0
  34. package/dist/index.js +11 -0
  35. package/package.json +18 -0
  36. package/src/adapters/CosmostationWallet.ts +113 -0
  37. package/src/adapters/GalaxyStationWallet.ts +100 -0
  38. package/src/adapters/KeplrWallet.ts +126 -0
  39. package/src/adapters/LUNCDashWallet.ts +20 -0
  40. package/src/adapters/LeapWallet.ts +95 -0
  41. package/src/adapters/StationWallet.ts +100 -0
  42. package/src/adapters/WalletConnectWallet.ts +125 -0
  43. package/src/adapters/utils/QRCodeModal.ts +73 -0
  44. package/src/adapters/utils/WalletConnectV2.ts +388 -0
  45. package/src/adapters/utils/os.ts +1 -0
  46. package/src/core/account.ts +7 -0
  47. package/src/core/chain.ts +15 -0
  48. package/src/core/createClient.ts +194 -0
  49. package/src/core/storage.ts +20 -0
  50. package/src/core/types.ts +72 -0
  51. package/src/core/wallet.ts +5 -0
  52. package/src/index.ts +11 -0
  53. package/src/types/modules.d.ts +6 -0
  54. package/tsconfig.json +15 -0
@@ -0,0 +1,40 @@
1
+ import { WalletAdapter, Chain, Account } from "../core/types.js";
2
+ interface CosmostationProvider {
3
+ providers: {
4
+ keplr: {
5
+ enable(chainId: string): Promise<void>;
6
+ getKey(chainId: string): Promise<{
7
+ name: string;
8
+ algo: string;
9
+ bech32Address: string;
10
+ pubKey: Uint8Array;
11
+ isNanoLedger: boolean;
12
+ }>;
13
+ getOfflineSigner(chainId: string): any;
14
+ signDirect(chainId: string, signer: string, signDoc: any): Promise<any>;
15
+ signArbitrary(chainId: string, signer: string, data: string): Promise<any>;
16
+ };
17
+ };
18
+ }
19
+ declare global {
20
+ interface Window {
21
+ cosmostation?: CosmostationProvider;
22
+ }
23
+ }
24
+ export declare class CosmostationWallet implements WalletAdapter {
25
+ id: "cosmostation";
26
+ name: string;
27
+ icon: string;
28
+ private wc?;
29
+ constructor(options?: {
30
+ projectId?: string;
31
+ });
32
+ installed(): boolean;
33
+ getUri(): string;
34
+ onUpdate(callback: () => void): void;
35
+ connect(chain: Chain): Promise<Account>;
36
+ disconnect(): Promise<void>;
37
+ signTx(_bytes: Uint8Array): Promise<Uint8Array>;
38
+ signMsg(_msg: string): Promise<Uint8Array>;
39
+ }
40
+ export {};
@@ -0,0 +1,68 @@
1
+ import { WalletConnectWallet } from "./WalletConnectWallet.js";
2
+ import { WalletName } from "@goblinhunt/cosmes/wallet";
3
+ export class CosmostationWallet {
4
+ id = WalletName.COSMOSTATION;
5
+ name = "Cosmostation";
6
+ icon = "https://raw.githubusercontent.com/cosmostation/cosmostation_token_resource/master/all_chains/cosmos/resource/cosmostation.png";
7
+ wc;
8
+ constructor(options) {
9
+ if (options?.projectId) {
10
+ this.wc = new WalletConnectWallet({
11
+ projectId: options.projectId,
12
+ id: this.id,
13
+ name: this.name,
14
+ icon: this.icon,
15
+ mobileAppDetails: {
16
+ name: "Cosmostation",
17
+ description: "Cosmostation Wallet",
18
+ android: "intent://wc#Intent;package=wannabit.io.cosmostaion;scheme=cosmostation;end;",
19
+ ios: "cosmostation://wc",
20
+ },
21
+ });
22
+ }
23
+ }
24
+ installed() {
25
+ return typeof window !== "undefined" && !!window.cosmostation;
26
+ }
27
+ getUri() {
28
+ return this.wc?.getUri() ?? "";
29
+ }
30
+ onUpdate(callback) {
31
+ this.wc?.onUpdate(callback);
32
+ }
33
+ async connect(chain) {
34
+ const cosmostation = window.cosmostation?.providers.keplr;
35
+ if (!cosmostation) {
36
+ if (this.wc) {
37
+ return this.wc.connect(chain);
38
+ }
39
+ throw new Error("Cosmostation extension not found");
40
+ }
41
+ try {
42
+ await cosmostation.enable(chain.chainId);
43
+ const key = await cosmostation.getKey(chain.chainId);
44
+ return {
45
+ address: key.bech32Address,
46
+ pubKey: key.pubKey,
47
+ algo: key.algo,
48
+ name: key.name,
49
+ isNanoLedger: key.isNanoLedger,
50
+ };
51
+ }
52
+ catch (error) {
53
+ throw new Error(`Cosmostation connection failed: ${error.message}`);
54
+ }
55
+ }
56
+ async disconnect() {
57
+ if (this.wc) {
58
+ await this.wc.disconnect();
59
+ }
60
+ return Promise.resolve();
61
+ }
62
+ async signTx(_bytes) {
63
+ throw new Error("signTx not fully implemented for raw bytes in Cosmostation yet.");
64
+ }
65
+ async signMsg(_msg) {
66
+ throw new Error("signMsg not implemented yet.");
67
+ }
68
+ }
@@ -0,0 +1,34 @@
1
+ import { WalletAdapter, Chain, Account } from "../core/types.js";
2
+ interface GalaxyStation {
3
+ keplr: {
4
+ enable(chainId: string | string[]): Promise<void>;
5
+ getKey(chainId: string): Promise<{
6
+ name: string;
7
+ algo: string;
8
+ bech32Address: string;
9
+ pubKey: Uint8Array;
10
+ isNanoLedger: boolean;
11
+ }>;
12
+ };
13
+ }
14
+ declare global {
15
+ interface Window {
16
+ galaxyStation?: GalaxyStation;
17
+ }
18
+ }
19
+ export declare class GalaxyStationWallet implements WalletAdapter {
20
+ id: string;
21
+ name: string;
22
+ icon: string;
23
+ private wc?;
24
+ constructor(options?: {
25
+ projectId?: string;
26
+ });
27
+ installed(): boolean;
28
+ getUri(): string;
29
+ onUpdate(callback: () => void): void;
30
+ connect(chain: Chain): Promise<Account>;
31
+ disconnect(): Promise<void>;
32
+ signTx(_bytes: Uint8Array): Promise<Uint8Array>;
33
+ }
34
+ export {};
@@ -0,0 +1,64 @@
1
+ import { WalletConnectWallet } from "./WalletConnectWallet.js";
2
+ export class GalaxyStationWallet {
3
+ id = "galaxy-station";
4
+ name = "Galaxy Station";
5
+ icon = "https://raw.githubusercontent.com/terra-money/station-assets/main/img/station.png";
6
+ wc;
7
+ constructor(options) {
8
+ if (options?.projectId) {
9
+ this.wc = new WalletConnectWallet({
10
+ projectId: options.projectId,
11
+ id: this.id,
12
+ name: this.name,
13
+ icon: this.icon,
14
+ mobileAppDetails: {
15
+ name: "Galaxy Station",
16
+ description: "Galaxy Station Wallet (Terra Classic)",
17
+ android: "https://station.hexxagon.io/wcV2#Intent;package=io.hexxagon.station;scheme=galaxystation;end;",
18
+ ios: "https://station.hexxagon.io/wcV2",
19
+ },
20
+ });
21
+ }
22
+ }
23
+ installed() {
24
+ return typeof window !== "undefined" && !!window.galaxyStation;
25
+ }
26
+ getUri() {
27
+ return this.wc?.getUri() ?? "";
28
+ }
29
+ onUpdate(callback) {
30
+ this.wc?.onUpdate(callback);
31
+ }
32
+ async connect(chain) {
33
+ const galaxyStation = window.galaxyStation;
34
+ if (!galaxyStation) {
35
+ if (this.wc) {
36
+ return this.wc.connect(chain);
37
+ }
38
+ throw new Error("Galaxy Station Wallet extension not found");
39
+ }
40
+ try {
41
+ const provider = galaxyStation.keplr;
42
+ await provider.enable(chain.chainId);
43
+ const key = await provider.getKey(chain.chainId);
44
+ return {
45
+ address: key.bech32Address,
46
+ pubKey: key.pubKey,
47
+ algo: key.algo,
48
+ name: key.name,
49
+ };
50
+ }
51
+ catch (error) {
52
+ throw new Error(`Galaxy Station Wallet connection failed: ${error.message}`);
53
+ }
54
+ }
55
+ async disconnect() {
56
+ if (this.wc) {
57
+ await this.wc.disconnect();
58
+ }
59
+ return Promise.resolve();
60
+ }
61
+ async signTx(_bytes) {
62
+ throw new Error("signTx not implemented for Galaxy Station yet.");
63
+ }
64
+ }
@@ -0,0 +1,36 @@
1
+ import { WalletAdapter, Chain, Account } from "../core/types.js";
2
+ interface Keplr {
3
+ enable(chainId: string): Promise<void>;
4
+ getKey(chainId: string): Promise<{
5
+ name: string;
6
+ algo: string;
7
+ bech32Address: string;
8
+ pubKey: Uint8Array;
9
+ isNanoLedger: boolean;
10
+ }>;
11
+ getOfflineSigner(chainId: string): any;
12
+ signDirect(chainId: string, signer: string, signDoc: any): Promise<any>;
13
+ signArbitrary(chainId: string, signer: string, data: string): Promise<any>;
14
+ }
15
+ declare global {
16
+ interface Window {
17
+ keplr?: Keplr;
18
+ }
19
+ }
20
+ export declare class KeplrWallet implements WalletAdapter {
21
+ id: "keplr";
22
+ name: string;
23
+ icon: string;
24
+ private wc?;
25
+ constructor(options?: {
26
+ projectId?: string;
27
+ });
28
+ installed(): boolean;
29
+ getUri(): string;
30
+ onUpdate(callback: () => void): void;
31
+ connect(chain: Chain): Promise<Account>;
32
+ disconnect(): Promise<void>;
33
+ signTx(_bytes: Uint8Array): Promise<Uint8Array>;
34
+ signMsg(_msg: string): Promise<Uint8Array>;
35
+ }
36
+ export {};
@@ -0,0 +1,85 @@
1
+ import { WalletConnectWallet } from "./WalletConnectWallet.js";
2
+ import { WalletName } from "@goblinhunt/cosmes/wallet";
3
+ export class KeplrWallet {
4
+ id = WalletName.KEPLR;
5
+ name = "Keplr";
6
+ icon = "https://raw.githubusercontent.com/chainapsis/keplr-wallet/master/packages/extension/src/public/assets/img/logo-256.png";
7
+ wc;
8
+ constructor(options) {
9
+ if (options?.projectId) {
10
+ this.wc = new WalletConnectWallet({
11
+ projectId: options.projectId,
12
+ id: this.id,
13
+ name: this.name,
14
+ icon: this.icon,
15
+ mobileAppDetails: {
16
+ name: "Keplr",
17
+ description: "Keplr Wallet",
18
+ android: "intent://wcV2#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;",
19
+ ios: "keplrwallet://wcV2",
20
+ },
21
+ });
22
+ }
23
+ }
24
+ installed() {
25
+ return typeof window !== "undefined" && !!window.keplr;
26
+ }
27
+ getUri() {
28
+ return this.wc?.getUri() ?? "";
29
+ }
30
+ onUpdate(callback) {
31
+ this.wc?.onUpdate(callback);
32
+ }
33
+ async connect(chain) {
34
+ const keplr = window.keplr;
35
+ if (!keplr) {
36
+ if (this.wc) {
37
+ return this.wc.connect(chain);
38
+ }
39
+ throw new Error("Keplr extension not found");
40
+ }
41
+ try {
42
+ await keplr.enable(chain.chainId);
43
+ const key = await keplr.getKey(chain.chainId);
44
+ return {
45
+ address: key.bech32Address,
46
+ pubKey: key.pubKey,
47
+ algo: key.algo,
48
+ name: key.name,
49
+ isNanoLedger: key.isNanoLedger,
50
+ };
51
+ }
52
+ catch (error) {
53
+ throw new Error(`Keplr connection failed: ${error.message}`);
54
+ }
55
+ }
56
+ async disconnect() {
57
+ if (this.wc) {
58
+ await this.wc.disconnect();
59
+ }
60
+ return Promise.resolve();
61
+ }
62
+ async signTx(_bytes) {
63
+ console.debug("Keplr signTx", _bytes.length);
64
+ // In a real implementation, you'd decode bytes to SignDoc or use signDirect/Amino
65
+ // Since the core SDK takes raw bytes, we assume the bytes ARE the signDoc or
66
+ // the user wants to sign these specific bytes.
67
+ // For Keplr, signDirect is common.
68
+ // NOTE: This is a simplified implementation. Real-world usage requires
69
+ // proper tx construction handling.
70
+ // For now, let's assume we use signDirect if we can decode the bytes
71
+ // or provide a helper for cosmes integrations.
72
+ throw new Error("signTx not fully implemented for raw bytes in Keplr yet. Use cosmes-compatible signers.");
73
+ }
74
+ async signMsg(_msg) {
75
+ console.debug("Keplr signMsg", _msg.length);
76
+ const keplr = window.keplr;
77
+ if (!keplr)
78
+ throw new Error("Keplr not found");
79
+ // Find current address (assumes already connected or we need to connect)
80
+ // For simplicity, we'll try to get the first address.
81
+ // This is often used for Siwe etc.
82
+ // return keplr.signArbitrary(...);
83
+ throw new Error("signMsg not implemented yet.");
84
+ }
85
+ }
@@ -0,0 +1,6 @@
1
+ import { WalletConnectWallet } from "./WalletConnectWallet.js";
2
+ export declare class LUNCDashWallet extends WalletConnectWallet {
3
+ constructor({ projectId }: {
4
+ projectId: string;
5
+ });
6
+ }
@@ -0,0 +1,19 @@
1
+ import { WalletConnectWallet } from "./WalletConnectWallet.js";
2
+ export class LUNCDashWallet extends WalletConnectWallet {
3
+ constructor({ projectId }) {
4
+ super({
5
+ projectId,
6
+ id: "luncdash",
7
+ name: "LUNCDash",
8
+ icon: "https://luncdash.com/assets/logo-dash-r8Nezm76.png",
9
+ mobileAppDetails: {
10
+ name: "LUNCDash",
11
+ description: "Connect to LUNCDash",
12
+ url: "https://luncdash.com",
13
+ icons: ["https://luncdash.com/assets/logo-dash-r8Nezm76.png"],
14
+ android: "luncdash://wc",
15
+ ios: "luncdash://wc",
16
+ },
17
+ });
18
+ }
19
+ }
@@ -0,0 +1,33 @@
1
+ import { WalletAdapter, Chain, Account } from "../core/types.js";
2
+ interface Leap {
3
+ enable(chainId: string): Promise<void>;
4
+ getKey(chainId: string): Promise<{
5
+ name: string;
6
+ algo: string;
7
+ bech32Address: string;
8
+ pubKey: Uint8Array;
9
+ isNanoLedger: boolean;
10
+ }>;
11
+ getOfflineSigner(chainId: string): any;
12
+ }
13
+ declare global {
14
+ interface Window {
15
+ leap?: Leap;
16
+ }
17
+ }
18
+ export declare class LeapWallet implements WalletAdapter {
19
+ id: "leap";
20
+ name: string;
21
+ icon: string;
22
+ private wc?;
23
+ constructor(options?: {
24
+ projectId?: string;
25
+ });
26
+ installed(): boolean;
27
+ getUri(): string;
28
+ onUpdate(callback: () => void): void;
29
+ connect(chain: Chain): Promise<Account>;
30
+ disconnect(): Promise<void>;
31
+ signTx(_bytes: Uint8Array): Promise<Uint8Array>;
32
+ }
33
+ export {};
@@ -0,0 +1,64 @@
1
+ import { WalletConnectWallet } from "./WalletConnectWallet.js";
2
+ import { WalletName } from "@goblinhunt/cosmes/wallet";
3
+ export class LeapWallet {
4
+ id = WalletName.LEAP;
5
+ name = "Leap";
6
+ icon = "https://raw.githubusercontent.com/leapwallet/assets/master/images/leap-cosmos-logo.png";
7
+ wc;
8
+ constructor(options) {
9
+ if (options?.projectId) {
10
+ this.wc = new WalletConnectWallet({
11
+ projectId: options.projectId,
12
+ id: this.id,
13
+ name: this.name,
14
+ icon: this.icon,
15
+ mobileAppDetails: {
16
+ name: "Leap",
17
+ description: "Leap Wallet",
18
+ android: "leapcosmos://wcV2",
19
+ ios: "leapcosmos://wcV2",
20
+ },
21
+ });
22
+ }
23
+ }
24
+ installed() {
25
+ return typeof window !== "undefined" && !!window.leap;
26
+ }
27
+ getUri() {
28
+ return this.wc?.getUri() ?? "";
29
+ }
30
+ onUpdate(callback) {
31
+ this.wc?.onUpdate(callback);
32
+ }
33
+ async connect(chain) {
34
+ const leap = window.leap;
35
+ if (!leap) {
36
+ if (this.wc) {
37
+ return this.wc.connect(chain);
38
+ }
39
+ throw new Error("Leap extension not found");
40
+ }
41
+ try {
42
+ await leap.enable(chain.chainId);
43
+ const key = await leap.getKey(chain.chainId);
44
+ return {
45
+ address: key.bech32Address,
46
+ pubKey: key.pubKey,
47
+ algo: key.algo,
48
+ name: key.name,
49
+ };
50
+ }
51
+ catch (error) {
52
+ throw new Error(`Leap connection failed: ${error.message}`);
53
+ }
54
+ }
55
+ async disconnect() {
56
+ if (this.wc) {
57
+ await this.wc.disconnect();
58
+ }
59
+ return Promise.resolve();
60
+ }
61
+ async signTx(_bytes) {
62
+ throw new Error("signTx not implemented for Leap yet.");
63
+ }
64
+ }
@@ -0,0 +1,34 @@
1
+ import { WalletAdapter, Chain, Account } from "../core/types.js";
2
+ interface Station {
3
+ keplr: {
4
+ enable(chainId: string): Promise<void>;
5
+ getKey(chainId: string): Promise<{
6
+ name: string;
7
+ algo: string;
8
+ bech32Address: string;
9
+ pubKey: Uint8Array;
10
+ isNanoLedger: boolean;
11
+ }>;
12
+ };
13
+ }
14
+ declare global {
15
+ interface Window {
16
+ station?: Station;
17
+ }
18
+ }
19
+ export declare class StationWallet implements WalletAdapter {
20
+ id: string;
21
+ name: string;
22
+ icon: string;
23
+ private wc?;
24
+ constructor(options?: {
25
+ projectId?: string;
26
+ });
27
+ installed(): boolean;
28
+ getUri(): string;
29
+ onUpdate(callback: () => void): void;
30
+ connect(chain: Chain): Promise<Account>;
31
+ disconnect(): Promise<void>;
32
+ signTx(_bytes: Uint8Array): Promise<Uint8Array>;
33
+ }
34
+ export {};
@@ -0,0 +1,67 @@
1
+ import { WalletConnectWallet } from "./WalletConnectWallet.js";
2
+ export class StationWallet {
3
+ id = "station";
4
+ name = "Station Wallet";
5
+ icon = "https://raw.githubusercontent.com/terra-money/station-assets/main/img/station.png";
6
+ wc;
7
+ constructor(options) {
8
+ if (options?.projectId) {
9
+ this.wc = new WalletConnectWallet({
10
+ projectId: options.projectId,
11
+ id: this.id,
12
+ name: this.name,
13
+ icon: this.icon,
14
+ mobileAppDetails: {
15
+ name: "Station Wallet",
16
+ description: "Station Wallet (Interchain)",
17
+ android: "terrastation://wc",
18
+ ios: "terrastation://wc",
19
+ isStation: true,
20
+ },
21
+ });
22
+ }
23
+ }
24
+ installed() {
25
+ // Note: Both Station and Galaxy Station might use window.station.
26
+ // Usually one is installed at a time.
27
+ return typeof window !== "undefined" && !!window.station;
28
+ }
29
+ getUri() {
30
+ return this.wc?.getUri() ?? "";
31
+ }
32
+ onUpdate(callback) {
33
+ this.wc?.onUpdate(callback);
34
+ }
35
+ async connect(chain) {
36
+ const station = window.station;
37
+ if (!station) {
38
+ if (this.wc) {
39
+ return this.wc.connect(chain);
40
+ }
41
+ throw new Error("Station Wallet extension not found");
42
+ }
43
+ try {
44
+ const provider = station.keplr;
45
+ await provider.enable(chain.chainId);
46
+ const key = await provider.getKey(chain.chainId);
47
+ return {
48
+ address: key.bech32Address,
49
+ pubKey: key.pubKey,
50
+ algo: key.algo,
51
+ name: key.name,
52
+ };
53
+ }
54
+ catch (error) {
55
+ throw new Error(`Station Wallet connection failed: ${error.message}`);
56
+ }
57
+ }
58
+ async disconnect() {
59
+ if (this.wc) {
60
+ await this.wc.disconnect();
61
+ }
62
+ return Promise.resolve();
63
+ }
64
+ async signTx(_bytes) {
65
+ throw new Error("signTx not implemented for Station Wallet yet.");
66
+ }
67
+ }
@@ -0,0 +1,27 @@
1
+ import { WalletConnectV2 } from "./utils/WalletConnectV2.js";
2
+ import { WalletAdapter, Chain, Account } from "../core/types.js";
3
+ import { MobileAppDetails } from "./utils/QRCodeModal.js";
4
+ export declare class WalletConnectWallet implements WalletAdapter {
5
+ id: string;
6
+ name: string;
7
+ icon: string;
8
+ private wc;
9
+ private _uri;
10
+ private _connecting;
11
+ private _updateCallback?;
12
+ constructor({ projectId, id, name, icon, mobileAppDetails, }: {
13
+ projectId: string;
14
+ id?: string;
15
+ name?: string;
16
+ icon?: string;
17
+ mobileAppDetails?: MobileAppDetails;
18
+ });
19
+ installed(): boolean;
20
+ getUri(): string;
21
+ private _connectPromise;
22
+ connect(chain: Chain): Promise<Account>;
23
+ disconnect(): Promise<void>;
24
+ signTx(_bytes: Uint8Array): Promise<Uint8Array>;
25
+ onUpdate(callback: () => void): void;
26
+ get client(): WalletConnectV2;
27
+ }
@@ -0,0 +1,89 @@
1
+ import { WalletConnectV2 } from "./utils/WalletConnectV2.js";
2
+ import { base64 } from "@goblinhunt/cosmes/codec";
3
+ export class WalletConnectWallet {
4
+ id = "walletConnect";
5
+ name = "Other Wallets";
6
+ icon = "https://raw.githubusercontent.com/WalletConnect/walletconnect-assets/master/Logo/Blue%20(Default)/Logo.svg";
7
+ wc;
8
+ _uri = "";
9
+ _connecting = false;
10
+ _updateCallback;
11
+ constructor({ projectId, id, name, icon, mobileAppDetails, }) {
12
+ if (id)
13
+ this.id = id;
14
+ if (name)
15
+ this.name = name;
16
+ if (icon)
17
+ this.icon = icon;
18
+ const details = mobileAppDetails || {
19
+ name: "Cosmos Connect",
20
+ description: "Connect to Cosmos app",
21
+ url: typeof window !== "undefined" ? window.location.origin : "",
22
+ icons: [
23
+ "https://raw.githubusercontent.com/WalletConnect/walletconnect-assets/master/Logo/Blue%20(Default)/Logo.svg",
24
+ ],
25
+ android: "intent://wcV2#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;", // Default to Keplr for android
26
+ ios: "keplrwallet://wcV2", // Default to Keplr for ios
27
+ };
28
+ this.wc = new WalletConnectV2(projectId, details);
29
+ this.wc.onUri((uri) => {
30
+ this._uri = uri;
31
+ this._updateCallback?.();
32
+ });
33
+ }
34
+ installed() {
35
+ return false;
36
+ }
37
+ getUri() {
38
+ return this._uri;
39
+ }
40
+ _connectPromise = null;
41
+ async connect(chain) {
42
+ if (this._connectPromise) {
43
+ console.log("WalletConnectWallet: connect already in progress, returning existing promise...");
44
+ return this._connectPromise;
45
+ }
46
+ this._connectPromise = (async () => {
47
+ console.log("WalletConnectWallet: connect called for chain", chain.chainId);
48
+ this._connecting = true;
49
+ try {
50
+ // This will trigger our onUri callback
51
+ console.log("WalletConnectWallet: triggering wc.connect...");
52
+ await this.wc.connect([chain.chainId]);
53
+ console.log("WalletConnectWallet: wc.connect settled");
54
+ // After approval, keys are set
55
+ const accountRes = await this.wc.getAccount(chain.chainId);
56
+ return {
57
+ address: accountRes.address,
58
+ pubKey: base64.decode(accountRes.pubkey),
59
+ algo: accountRes.algo,
60
+ name: accountRes.name,
61
+ };
62
+ }
63
+ catch (e) {
64
+ console.error("WalletConnectWallet: Connection failed", e);
65
+ throw e;
66
+ }
67
+ finally {
68
+ this._connecting = false;
69
+ this._connectPromise = null;
70
+ }
71
+ })();
72
+ return this._connectPromise;
73
+ }
74
+ async disconnect() {
75
+ this.wc.disconnect();
76
+ this._uri = "";
77
+ this._connecting = false;
78
+ }
79
+ async signTx(_bytes) {
80
+ throw new Error("signTx not implemented directly on adapter. Use client.signAndBroadcast");
81
+ }
82
+ onUpdate(callback) {
83
+ this._updateCallback = callback;
84
+ }
85
+ // Helper for direct access if needed
86
+ get client() {
87
+ return this.wc;
88
+ }
89
+ }