cosmos-connect-core 0.1.0 → 0.1.2

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/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # cosmos-connect-core
2
+
3
+ Core SDK for Cosmos wallet integration. Provides wallet adapters for Keplr, Leap, Cosmostation, Station, and more.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install cosmos-connect-core
9
+ ```
10
+
11
+ ## Wallet Adapters
12
+
13
+ - **KeplrWallet** - Browser extension and mobile app
14
+ - **LeapWallet** - Browser extension and mobile app
15
+ - **CosmostationWallet** - Browser extension and mobile app
16
+ - **StationWallet** - Terra's official wallet
17
+ - **GalaxyStationWallet** - Alternative Station wallet
18
+ - **LUNCDashWallet** - LUNC-focused wallet
19
+ - **WalletConnectWallet** - WalletConnect v2 support
20
+
21
+ ## Usage
22
+
23
+ ```typescript
24
+ import { KeplrWallet, LeapWallet } from 'cosmos-connect-core';
25
+
26
+ const keplr = new KeplrWallet();
27
+ const leap = new LeapWallet();
28
+
29
+ // Connect wallet
30
+ await keplr.connect({
31
+ chainId: 'columbus-5',
32
+ rpc: 'https://terra-classic-rpc.publicnode.com',
33
+ rest: 'https://terra-classic-lcd.publicnode.com',
34
+ });
35
+
36
+ // Get account
37
+ const account = await keplr.getAccount('columbus-5');
38
+ console.log(account.address); // terra1...
39
+ ```
40
+
41
+ ## Supported Chains
42
+
43
+ - Terra Classic (columbus-5)
44
+ - Terra 2.0 (phoenix-1)
45
+ - Cosmos Hub
46
+ - Osmosis
47
+ - And any other Cosmos SDK chain
48
+
49
+ ## License
50
+
51
+ BSD-2-Clause
52
+
53
+ ## Author
54
+
55
+ [@0xzahh](https://github.com/0xzahh)
@@ -1,5 +1,6 @@
1
1
  export interface Chain {
2
2
  chainId: string;
3
+ name?: string;
3
4
  rpc: string;
4
5
  rest?: string;
5
6
  bech32Prefix: string;
@@ -24,7 +25,7 @@ export interface WalletAdapter {
24
25
  getUri?(): string;
25
26
  onUpdate?(callback: () => void): void;
26
27
  }
27
- export type ClientStatus = "disconnected" | "connecting" | "connected";
28
+ export type ClientStatus = 'disconnected' | 'connecting' | 'connected';
28
29
  export interface ClientState {
29
30
  currentChain: Chain | null;
30
31
  currentWallet: WalletAdapter | null;
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "cosmos-connect-core",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Core SDK for Cosmos Connect",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "module",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
8
12
  "scripts": {
9
13
  "build": "tsc"
10
14
  },
@@ -1,113 +0,0 @@
1
- import { WalletAdapter, Chain, Account } from "../core/types.js";
2
- import { WalletConnectWallet } from "./WalletConnectWallet.js";
3
- import { WalletName } from "@goblinhunt/cosmes/wallet";
4
-
5
- // Basic Keplr-compatible provider structure in Cosmostation
6
- interface CosmostationProvider {
7
- providers: {
8
- keplr: {
9
- enable(chainId: string): Promise<void>;
10
- getKey(chainId: string): Promise<{
11
- name: string;
12
- algo: string;
13
- bech32Address: string;
14
- pubKey: Uint8Array;
15
- isNanoLedger: boolean;
16
- }>;
17
- getOfflineSigner(chainId: string): any;
18
- signDirect(chainId: string, signer: string, signDoc: any): Promise<any>;
19
- signArbitrary(
20
- chainId: string,
21
- signer: string,
22
- data: string,
23
- ): Promise<any>;
24
- };
25
- };
26
- }
27
-
28
- declare global {
29
- interface Window {
30
- cosmostation?: CosmostationProvider;
31
- }
32
- }
33
-
34
- export class CosmostationWallet implements WalletAdapter {
35
- id = WalletName.COSMOSTATION;
36
- name = "Cosmostation";
37
- icon =
38
- "https://raw.githubusercontent.com/cosmostation/cosmostation_token_resource/master/all_chains/cosmos/resource/cosmostation.png";
39
-
40
- private wc?: WalletConnectWallet;
41
-
42
- constructor(options?: { projectId?: string }) {
43
- if (options?.projectId) {
44
- this.wc = new WalletConnectWallet({
45
- projectId: options.projectId,
46
- id: this.id,
47
- name: this.name,
48
- icon: this.icon,
49
- mobileAppDetails: {
50
- name: "Cosmostation",
51
- description: "Cosmostation Wallet",
52
- android:
53
- "intent://wc#Intent;package=wannabit.io.cosmostaion;scheme=cosmostation;end;",
54
- ios: "cosmostation://wc",
55
- },
56
- });
57
- }
58
- }
59
-
60
- installed(): boolean {
61
- return typeof window !== "undefined" && !!window.cosmostation;
62
- }
63
-
64
- getUri(): string {
65
- return this.wc?.getUri() ?? "";
66
- }
67
-
68
- onUpdate(callback: () => void): void {
69
- this.wc?.onUpdate(callback);
70
- }
71
-
72
- async connect(chain: Chain): Promise<Account> {
73
- const cosmostation = window.cosmostation?.providers.keplr;
74
- if (!cosmostation) {
75
- if (this.wc) {
76
- return this.wc.connect(chain);
77
- }
78
- throw new Error("Cosmostation extension not found");
79
- }
80
-
81
- try {
82
- await cosmostation.enable(chain.chainId);
83
- const key = await cosmostation.getKey(chain.chainId);
84
-
85
- return {
86
- address: key.bech32Address,
87
- pubKey: key.pubKey,
88
- algo: key.algo,
89
- name: key.name,
90
- isNanoLedger: key.isNanoLedger,
91
- };
92
- } catch (error: any) {
93
- throw new Error(`Cosmostation connection failed: ${error.message}`);
94
- }
95
- }
96
-
97
- async disconnect(): Promise<void> {
98
- if (this.wc) {
99
- await this.wc.disconnect();
100
- }
101
- return Promise.resolve();
102
- }
103
-
104
- async signTx(_bytes: Uint8Array): Promise<Uint8Array> {
105
- throw new Error(
106
- "signTx not fully implemented for raw bytes in Cosmostation yet.",
107
- );
108
- }
109
-
110
- async signMsg(_msg: string): Promise<Uint8Array> {
111
- throw new Error("signMsg not implemented yet.");
112
- }
113
- }
@@ -1,100 +0,0 @@
1
- import { WalletAdapter, Chain, Account } from "../core/types.js";
2
- import { WalletConnectWallet } from "./WalletConnectWallet.js";
3
- import { WalletName } from "@goblinhunt/cosmes/wallet";
4
-
5
- // Basic Galaxy Station type definitions
6
- interface GalaxyStation {
7
- keplr: {
8
- enable(chainId: string | string[]): Promise<void>;
9
- getKey(chainId: string): Promise<{
10
- name: string;
11
- algo: string;
12
- bech32Address: string;
13
- pubKey: Uint8Array;
14
- isNanoLedger: boolean;
15
- }>;
16
- };
17
- }
18
-
19
- declare global {
20
- interface Window {
21
- galaxyStation?: GalaxyStation;
22
- }
23
- }
24
-
25
- export class GalaxyStationWallet implements WalletAdapter {
26
- id = "galaxy-station";
27
- name = "Galaxy Station";
28
- icon =
29
- "https://raw.githubusercontent.com/terra-money/station-assets/main/img/station.png";
30
-
31
- private wc?: WalletConnectWallet;
32
-
33
- constructor(options?: { projectId?: string }) {
34
- if (options?.projectId) {
35
- this.wc = new WalletConnectWallet({
36
- projectId: options.projectId,
37
- id: this.id,
38
- name: this.name,
39
- icon: this.icon,
40
- mobileAppDetails: {
41
- name: "Galaxy Station",
42
- description: "Galaxy Station Wallet (Terra Classic)",
43
- android:
44
- "https://station.hexxagon.io/wcV2#Intent;package=io.hexxagon.station;scheme=galaxystation;end;",
45
- ios: "https://station.hexxagon.io/wcV2",
46
- },
47
- });
48
- }
49
- }
50
-
51
- installed(): boolean {
52
- return typeof window !== "undefined" && !!window.galaxyStation;
53
- }
54
-
55
- getUri(): string {
56
- return this.wc?.getUri() ?? "";
57
- }
58
-
59
- onUpdate(callback: () => void): void {
60
- this.wc?.onUpdate(callback);
61
- }
62
-
63
- async connect(chain: Chain): Promise<Account> {
64
- const galaxyStation = window.galaxyStation;
65
- if (!galaxyStation) {
66
- if (this.wc) {
67
- return this.wc.connect(chain);
68
- }
69
- throw new Error("Galaxy Station Wallet extension not found");
70
- }
71
-
72
- try {
73
- const provider = galaxyStation.keplr;
74
- await provider.enable(chain.chainId);
75
- const key = await provider.getKey(chain.chainId);
76
-
77
- return {
78
- address: key.bech32Address,
79
- pubKey: key.pubKey,
80
- algo: key.algo,
81
- name: key.name,
82
- };
83
- } catch (error: any) {
84
- throw new Error(
85
- `Galaxy Station Wallet connection failed: ${error.message}`,
86
- );
87
- }
88
- }
89
-
90
- async disconnect(): Promise<void> {
91
- if (this.wc) {
92
- await this.wc.disconnect();
93
- }
94
- return Promise.resolve();
95
- }
96
-
97
- async signTx(_bytes: Uint8Array): Promise<Uint8Array> {
98
- throw new Error("signTx not implemented for Galaxy Station yet.");
99
- }
100
- }
@@ -1,126 +0,0 @@
1
- import { WalletAdapter, Chain, Account } from "../core/types.js";
2
- import { WalletConnectWallet } from "./WalletConnectWallet.js";
3
- import { WalletName } from "@goblinhunt/cosmes/wallet";
4
-
5
- // Basic Keplr type definitions to avoid errors without heavy deps
6
- interface Keplr {
7
- enable(chainId: string): Promise<void>;
8
- getKey(chainId: string): Promise<{
9
- name: string;
10
- algo: string;
11
- bech32Address: string;
12
- pubKey: Uint8Array;
13
- isNanoLedger: boolean;
14
- }>;
15
- getOfflineSigner(chainId: string): any;
16
- signDirect(chainId: string, signer: string, signDoc: any): Promise<any>;
17
- signArbitrary(chainId: string, signer: string, data: string): Promise<any>;
18
- }
19
-
20
- declare global {
21
- interface Window {
22
- keplr?: Keplr;
23
- }
24
- }
25
-
26
- export class KeplrWallet implements WalletAdapter {
27
- id = WalletName.KEPLR;
28
- name = "Keplr";
29
- icon =
30
- "https://raw.githubusercontent.com/chainapsis/keplr-wallet/master/packages/extension/src/public/assets/img/logo-256.png";
31
-
32
- private wc?: WalletConnectWallet;
33
-
34
- constructor(options?: { projectId?: string }) {
35
- if (options?.projectId) {
36
- this.wc = new WalletConnectWallet({
37
- projectId: options.projectId,
38
- id: this.id,
39
- name: this.name,
40
- icon: this.icon,
41
- mobileAppDetails: {
42
- name: "Keplr",
43
- description: "Keplr Wallet",
44
- android:
45
- "intent://wcV2#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;",
46
- ios: "keplrwallet://wcV2",
47
- },
48
- });
49
- }
50
- }
51
-
52
- installed(): boolean {
53
- return typeof window !== "undefined" && !!window.keplr;
54
- }
55
-
56
- getUri(): string {
57
- return this.wc?.getUri() ?? "";
58
- }
59
-
60
- onUpdate(callback: () => void): void {
61
- this.wc?.onUpdate(callback);
62
- }
63
-
64
- async connect(chain: Chain): Promise<Account> {
65
- const keplr = window.keplr;
66
- if (!keplr) {
67
- if (this.wc) {
68
- return this.wc.connect(chain);
69
- }
70
- throw new Error("Keplr extension not found");
71
- }
72
-
73
- try {
74
- await keplr.enable(chain.chainId);
75
- const key = await keplr.getKey(chain.chainId);
76
-
77
- return {
78
- address: key.bech32Address,
79
- pubKey: key.pubKey,
80
- algo: key.algo,
81
- name: key.name,
82
- isNanoLedger: key.isNanoLedger,
83
- };
84
- } catch (error: any) {
85
- throw new Error(`Keplr connection failed: ${error.message}`);
86
- }
87
- }
88
-
89
- async disconnect(): Promise<void> {
90
- if (this.wc) {
91
- await this.wc.disconnect();
92
- }
93
- return Promise.resolve();
94
- }
95
-
96
- async signTx(_bytes: Uint8Array): Promise<Uint8Array> {
97
- console.debug("Keplr signTx", _bytes.length);
98
- // In a real implementation, you'd decode bytes to SignDoc or use signDirect/Amino
99
- // Since the core SDK takes raw bytes, we assume the bytes ARE the signDoc or
100
- // the user wants to sign these specific bytes.
101
- // For Keplr, signDirect is common.
102
-
103
- // NOTE: This is a simplified implementation. Real-world usage requires
104
- // proper tx construction handling.
105
-
106
- // For now, let's assume we use signDirect if we can decode the bytes
107
- // or provide a helper for cosmes integrations.
108
-
109
- throw new Error(
110
- "signTx not fully implemented for raw bytes in Keplr yet. Use cosmes-compatible signers.",
111
- );
112
- }
113
-
114
- async signMsg(_msg: string): Promise<Uint8Array> {
115
- console.debug("Keplr signMsg", _msg.length);
116
- const keplr = window.keplr;
117
- if (!keplr) throw new Error("Keplr not found");
118
-
119
- // Find current address (assumes already connected or we need to connect)
120
- // For simplicity, we'll try to get the first address.
121
- // This is often used for Siwe etc.
122
- // return keplr.signArbitrary(...);
123
-
124
- throw new Error("signMsg not implemented yet.");
125
- }
126
- }
@@ -1,20 +0,0 @@
1
- import { WalletConnectWallet } from "./WalletConnectWallet.js";
2
-
3
- export class LUNCDashWallet extends WalletConnectWallet {
4
- constructor({ projectId }: { projectId: string }) {
5
- super({
6
- projectId,
7
- id: "luncdash",
8
- name: "LUNCDash",
9
- icon: "https://luncdash.com/assets/logo-dash-r8Nezm76.png",
10
- mobileAppDetails: {
11
- name: "LUNCDash",
12
- description: "Connect to LUNCDash",
13
- url: "https://luncdash.com",
14
- icons: ["https://luncdash.com/assets/logo-dash-r8Nezm76.png"],
15
- android: "luncdash://wc",
16
- ios: "luncdash://wc",
17
- },
18
- });
19
- }
20
- }
@@ -1,95 +0,0 @@
1
- import { WalletAdapter, Chain, Account } from "../core/types.js";
2
- import { WalletConnectWallet } from "./WalletConnectWallet.js";
3
- import { WalletName } from "@goblinhunt/cosmes/wallet";
4
-
5
- // Basic Leap type definitions
6
- interface Leap {
7
- enable(chainId: string): Promise<void>;
8
- getKey(chainId: string): Promise<{
9
- name: string;
10
- algo: string;
11
- bech32Address: string;
12
- pubKey: Uint8Array;
13
- isNanoLedger: boolean;
14
- }>;
15
- getOfflineSigner(chainId: string): any;
16
- }
17
-
18
- declare global {
19
- interface Window {
20
- leap?: Leap;
21
- }
22
- }
23
-
24
- export class LeapWallet implements WalletAdapter {
25
- id = WalletName.LEAP;
26
- name = "Leap";
27
- icon =
28
- "https://raw.githubusercontent.com/leapwallet/assets/master/images/leap-cosmos-logo.png";
29
-
30
- private wc?: WalletConnectWallet;
31
-
32
- constructor(options?: { projectId?: string }) {
33
- if (options?.projectId) {
34
- this.wc = new WalletConnectWallet({
35
- projectId: options.projectId,
36
- id: this.id,
37
- name: this.name,
38
- icon: this.icon,
39
- mobileAppDetails: {
40
- name: "Leap",
41
- description: "Leap Wallet",
42
- android: "leapcosmos://wcV2",
43
- ios: "leapcosmos://wcV2",
44
- },
45
- });
46
- }
47
- }
48
-
49
- installed(): boolean {
50
- return typeof window !== "undefined" && !!window.leap;
51
- }
52
-
53
- getUri(): string {
54
- return this.wc?.getUri() ?? "";
55
- }
56
-
57
- onUpdate(callback: () => void): void {
58
- this.wc?.onUpdate(callback);
59
- }
60
-
61
- async connect(chain: Chain): Promise<Account> {
62
- const leap = window.leap;
63
- if (!leap) {
64
- if (this.wc) {
65
- return this.wc.connect(chain);
66
- }
67
- throw new Error("Leap extension not found");
68
- }
69
-
70
- try {
71
- await leap.enable(chain.chainId);
72
- const key = await leap.getKey(chain.chainId);
73
-
74
- return {
75
- address: key.bech32Address,
76
- pubKey: key.pubKey,
77
- algo: key.algo,
78
- name: key.name,
79
- };
80
- } catch (error: any) {
81
- throw new Error(`Leap connection failed: ${error.message}`);
82
- }
83
- }
84
-
85
- async disconnect(): Promise<void> {
86
- if (this.wc) {
87
- await this.wc.disconnect();
88
- }
89
- return Promise.resolve();
90
- }
91
-
92
- async signTx(_bytes: Uint8Array): Promise<Uint8Array> {
93
- throw new Error("signTx not implemented for Leap yet.");
94
- }
95
- }
@@ -1,100 +0,0 @@
1
- import { WalletAdapter, Chain, Account } from "../core/types.js";
2
- import { WalletConnectWallet } from "./WalletConnectWallet.js";
3
- import { WalletName } from "@goblinhunt/cosmes/wallet";
4
-
5
- // Basic Station type definitions
6
- interface Station {
7
- keplr: {
8
- enable(chainId: string): Promise<void>;
9
- getKey(chainId: string): Promise<{
10
- name: string;
11
- algo: string;
12
- bech32Address: string;
13
- pubKey: Uint8Array;
14
- isNanoLedger: boolean;
15
- }>;
16
- };
17
- }
18
-
19
- declare global {
20
- interface Window {
21
- station?: Station;
22
- }
23
- }
24
-
25
- export class StationWallet implements WalletAdapter {
26
- id = "station";
27
- name = "Station Wallet";
28
- icon =
29
- "https://raw.githubusercontent.com/terra-money/station-assets/main/img/station.png";
30
-
31
- private wc?: WalletConnectWallet;
32
-
33
- constructor(options?: { projectId?: string }) {
34
- if (options?.projectId) {
35
- this.wc = new WalletConnectWallet({
36
- projectId: options.projectId,
37
- id: this.id,
38
- name: this.name,
39
- icon: this.icon,
40
- mobileAppDetails: {
41
- name: "Station Wallet",
42
- description: "Station Wallet (Interchain)",
43
- android: "terrastation://wc",
44
- ios: "terrastation://wc",
45
- isStation: true,
46
- },
47
- });
48
- }
49
- }
50
-
51
- installed(): boolean {
52
- // Note: Both Station and Galaxy Station might use window.station.
53
- // Usually one is installed at a time.
54
- return typeof window !== "undefined" && !!window.station;
55
- }
56
-
57
- getUri(): string {
58
- return this.wc?.getUri() ?? "";
59
- }
60
-
61
- onUpdate(callback: () => void): void {
62
- this.wc?.onUpdate(callback);
63
- }
64
-
65
- async connect(chain: Chain): Promise<Account> {
66
- const station = window.station;
67
- if (!station) {
68
- if (this.wc) {
69
- return this.wc.connect(chain);
70
- }
71
- throw new Error("Station Wallet extension not found");
72
- }
73
-
74
- try {
75
- const provider = station.keplr;
76
- await provider.enable(chain.chainId);
77
- const key = await provider.getKey(chain.chainId);
78
-
79
- return {
80
- address: key.bech32Address,
81
- pubKey: key.pubKey,
82
- algo: key.algo,
83
- name: key.name,
84
- };
85
- } catch (error: any) {
86
- throw new Error(`Station Wallet connection failed: ${error.message}`);
87
- }
88
- }
89
-
90
- async disconnect(): Promise<void> {
91
- if (this.wc) {
92
- await this.wc.disconnect();
93
- }
94
- return Promise.resolve();
95
- }
96
-
97
- async signTx(_bytes: Uint8Array): Promise<Uint8Array> {
98
- throw new Error("signTx not implemented for Station Wallet yet.");
99
- }
100
- }