@karn_lat/protocol-sdk 0.1.0-alpha.1
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 +68 -0
- package/dist/__tests__/setup.d.ts +14 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +44 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/clients/GovernorClient.d.ts +9 -0
- package/dist/clients/GovernorClient.d.ts.map +1 -0
- package/dist/clients/GovernorClient.js +18 -0
- package/dist/clients/GovernorClient.js.map +1 -0
- package/dist/clients/TreasuryClient.d.ts +9 -0
- package/dist/clients/TreasuryClient.d.ts.map +1 -0
- package/dist/clients/TreasuryClient.js +18 -0
- package/dist/clients/TreasuryClient.js.map +1 -0
- package/dist/clients/ValocracyClient.d.ts +13 -0
- package/dist/clients/ValocracyClient.d.ts.map +1 -0
- package/dist/clients/ValocracyClient.js +32 -0
- package/dist/clients/ValocracyClient.js.map +1 -0
- package/dist/clients/index.d.ts +4 -0
- package/dist/clients/index.d.ts.map +1 -0
- package/dist/clients/index.js +4 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/generated/governor/src/index.d.ts +400 -0
- package/dist/generated/governor/src/index.d.ts.map +1 -0
- package/dist/generated/governor/src/index.js +63 -0
- package/dist/generated/governor/src/index.js.map +1 -0
- package/dist/generated/treasury/src/index.d.ts +474 -0
- package/dist/generated/treasury/src/index.d.ts.map +1 -0
- package/dist/generated/treasury/src/index.js +54 -0
- package/dist/generated/treasury/src/index.js.map +1 -0
- package/dist/generated/valocracy/src/index.d.ts +807 -0
- package/dist/generated/valocracy/src/index.d.ts.map +1 -0
- package/dist/generated/valocracy/src/index.js +114 -0
- package/dist/generated/valocracy/src/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/react/hooks/useGovernor.d.ts +24 -0
- package/dist/react/hooks/useGovernor.d.ts.map +1 -0
- package/dist/react/hooks/useGovernor.js +45 -0
- package/dist/react/hooks/useGovernor.js.map +1 -0
- package/dist/react/hooks/useMultiWallet.d.ts +35 -0
- package/dist/react/hooks/useMultiWallet.d.ts.map +1 -0
- package/dist/react/hooks/useMultiWallet.js +87 -0
- package/dist/react/hooks/useMultiWallet.js.map +1 -0
- package/dist/react/hooks/useTreasury.d.ts +14 -0
- package/dist/react/hooks/useTreasury.d.ts.map +1 -0
- package/dist/react/hooks/useTreasury.js +45 -0
- package/dist/react/hooks/useTreasury.js.map +1 -0
- package/dist/react/hooks/useValocracy.d.ts +16 -0
- package/dist/react/hooks/useValocracy.d.ts.map +1 -0
- package/dist/react/hooks/useValocracy.js +54 -0
- package/dist/react/hooks/useValocracy.js.map +1 -0
- package/dist/react/hooks/useWallet.d.ts +13 -0
- package/dist/react/hooks/useWallet.d.ts.map +1 -0
- package/dist/react/hooks/useWallet.js +51 -0
- package/dist/react/hooks/useWallet.js.map +1 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +7 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/providers/KarnProvider.d.ts +25 -0
- package/dist/react/providers/KarnProvider.d.ts.map +1 -0
- package/dist/react/providers/KarnProvider.js +25 -0
- package/dist/react/providers/KarnProvider.js.map +1 -0
- package/dist/utils/decay.d.ts +19 -0
- package/dist/utils/decay.d.ts.map +1 -0
- package/dist/utils/decay.js +33 -0
- package/dist/utils/decay.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/polling.d.ts +75 -0
- package/dist/utils/polling.d.ts.map +1 -0
- package/dist/utils/polling.js +104 -0
- package/dist/utils/polling.js.map +1 -0
- package/dist/utils/simulation.d.ts +67 -0
- package/dist/utils/simulation.d.ts.map +1 -0
- package/dist/utils/simulation.js +88 -0
- package/dist/utils/simulation.js.map +1 -0
- package/dist/wallet/WalletManager.d.ts +77 -0
- package/dist/wallet/WalletManager.d.ts.map +1 -0
- package/dist/wallet/WalletManager.js +268 -0
- package/dist/wallet/WalletManager.js.map +1 -0
- package/dist/wallet/adapters/AlbedoAdapter.d.ts +47 -0
- package/dist/wallet/adapters/AlbedoAdapter.d.ts.map +1 -0
- package/dist/wallet/adapters/AlbedoAdapter.js +84 -0
- package/dist/wallet/adapters/AlbedoAdapter.js.map +1 -0
- package/dist/wallet/adapters/FreighterAdapter.d.ts +42 -0
- package/dist/wallet/adapters/FreighterAdapter.d.ts.map +1 -0
- package/dist/wallet/adapters/FreighterAdapter.js +107 -0
- package/dist/wallet/adapters/FreighterAdapter.js.map +1 -0
- package/dist/wallet/adapters/LobstrAdapter.d.ts +34 -0
- package/dist/wallet/adapters/LobstrAdapter.d.ts.map +1 -0
- package/dist/wallet/adapters/LobstrAdapter.js +89 -0
- package/dist/wallet/adapters/LobstrAdapter.js.map +1 -0
- package/dist/wallet/adapters/RabetAdapter.d.ts +39 -0
- package/dist/wallet/adapters/RabetAdapter.d.ts.map +1 -0
- package/dist/wallet/adapters/RabetAdapter.js +104 -0
- package/dist/wallet/adapters/RabetAdapter.js.map +1 -0
- package/dist/wallet/adapters/xBullAdapter.d.ts +41 -0
- package/dist/wallet/adapters/xBullAdapter.d.ts.map +1 -0
- package/dist/wallet/adapters/xBullAdapter.js +72 -0
- package/dist/wallet/adapters/xBullAdapter.js.map +1 -0
- package/dist/wallet/index.d.ts +20 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +23 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/wallet/types.d.ts +165 -0
- package/dist/wallet/types.d.ts.map +1 -0
- package/dist/wallet/types.js +50 -0
- package/dist/wallet/types.js.map +1 -0
- package/examples/basic-usage.ts +28 -0
- package/jest.config.js +37 -0
- package/package.json +58 -0
- package/src/__tests__/README.md +364 -0
- package/src/__tests__/setup.ts +57 -0
- package/src/__tests__/utils/decay.test.ts +331 -0
- package/src/__tests__/wallet/WalletManager.test.ts +410 -0
- package/src/clients/GovernorClient.ts +23 -0
- package/src/clients/TreasuryClient.ts +23 -0
- package/src/clients/ValocracyClient.ts +48 -0
- package/src/clients/index.ts +3 -0
- package/src/generated/governor/README.md +54 -0
- package/src/generated/governor/package.json +17 -0
- package/src/generated/governor/src/index.ts +428 -0
- package/src/generated/governor/tsconfig.json +98 -0
- package/src/generated/treasury/README.md +54 -0
- package/src/generated/treasury/package.json +17 -0
- package/src/generated/treasury/src/index.ts +495 -0
- package/src/generated/treasury/tsconfig.json +98 -0
- package/src/generated/valocracy/README.md +54 -0
- package/src/generated/valocracy/package.json +17 -0
- package/src/generated/valocracy/src/index.ts +831 -0
- package/src/generated/valocracy/tsconfig.json +98 -0
- package/src/index.ts +4 -0
- package/src/react/hooks/useGovernor.ts +69 -0
- package/src/react/hooks/useMultiWallet.ts +169 -0
- package/src/react/hooks/useTreasury.ts +57 -0
- package/src/react/hooks/useValocracy.ts +66 -0
- package/src/react/hooks/useWallet.ts +60 -0
- package/src/react/index.ts +6 -0
- package/src/react/providers/KarnProvider.tsx +63 -0
- package/src/utils/decay.ts +44 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/polling.ts +193 -0
- package/src/utils/simulation.ts +136 -0
- package/src/wallet/WalletManager.ts +360 -0
- package/src/wallet/adapters/AlbedoAdapter.ts +140 -0
- package/src/wallet/adapters/FreighterAdapter.ts +179 -0
- package/src/wallet/adapters/LobstrAdapter.ts +142 -0
- package/src/wallet/adapters/RabetAdapter.ts +162 -0
- package/src/wallet/adapters/xBullAdapter.ts +123 -0
- package/src/wallet/index.ts +37 -0
- package/src/wallet/types.ts +204 -0
- package/tsconfig.json +40 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Albedo Wallet Adapter
|
|
3
|
+
*
|
|
4
|
+
* Web-based Stellar wallet (no extension required)
|
|
5
|
+
* https://albedo.link
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
WalletAdapter,
|
|
10
|
+
WalletType,
|
|
11
|
+
WalletMetadata,
|
|
12
|
+
SignTransactionOptions,
|
|
13
|
+
WalletError,
|
|
14
|
+
WalletErrorCode,
|
|
15
|
+
} from '../types.js';
|
|
16
|
+
|
|
17
|
+
// Albedo API types
|
|
18
|
+
interface AlbedoAPI {
|
|
19
|
+
publicKey(options?: { require_existing?: boolean }): Promise<{ pubkey: string }>;
|
|
20
|
+
tx(options: {
|
|
21
|
+
xdr: string;
|
|
22
|
+
network?: string;
|
|
23
|
+
pubkey?: string;
|
|
24
|
+
submit?: boolean;
|
|
25
|
+
}): Promise<{ signed_envelope_xdr: string; tx_hash?: string; network?: string }>;
|
|
26
|
+
trust(options: { asset_code: string; asset_issuer: string }): Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare global {
|
|
30
|
+
interface Window {
|
|
31
|
+
albedo?: AlbedoAPI;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class AlbedoAdapter implements WalletAdapter {
|
|
36
|
+
type = WalletType.ALBEDO;
|
|
37
|
+
|
|
38
|
+
metadata: WalletMetadata = {
|
|
39
|
+
type: WalletType.ALBEDO,
|
|
40
|
+
name: 'Albedo',
|
|
41
|
+
url: 'https://albedo.link',
|
|
42
|
+
description: 'Web-based Stellar wallet with seamless browser integration',
|
|
43
|
+
isAvailable: true, // Albedo is always available (web-based)
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
private currentAddress: string | null = null;
|
|
47
|
+
|
|
48
|
+
async isAvailable(): Promise<boolean> {
|
|
49
|
+
// Albedo is web-based, always available
|
|
50
|
+
// Load script if not present
|
|
51
|
+
if (typeof window !== 'undefined' && !window.albedo) {
|
|
52
|
+
await this.loadAlbedoScript();
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private async loadAlbedoScript(): Promise<void> {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
if (window.albedo) {
|
|
60
|
+
resolve();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const script = document.createElement('script');
|
|
65
|
+
script.src = 'https://cdn.jsdelivr.net/npm/@albedo-link/intent@latest/lib/albedo.intent.js';
|
|
66
|
+
script.async = true;
|
|
67
|
+
script.onload = () => resolve();
|
|
68
|
+
script.onerror = () => reject(new Error('Failed to load Albedo'));
|
|
69
|
+
document.head.appendChild(script);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async connect(): Promise<string> {
|
|
74
|
+
await this.isAvailable();
|
|
75
|
+
|
|
76
|
+
if (!window.albedo) {
|
|
77
|
+
throw new WalletError(
|
|
78
|
+
'Albedo failed to load',
|
|
79
|
+
WalletErrorCode.NOT_INSTALLED,
|
|
80
|
+
WalletType.ALBEDO
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const result = await window.albedo.publicKey({ require_existing: false });
|
|
86
|
+
this.currentAddress = result.pubkey;
|
|
87
|
+
return result.pubkey;
|
|
88
|
+
} catch (error: any) {
|
|
89
|
+
throw new WalletError(
|
|
90
|
+
`Failed to connect to Albedo: ${error.message}`,
|
|
91
|
+
WalletErrorCode.USER_REJECTED,
|
|
92
|
+
WalletType.ALBEDO
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async disconnect(): Promise<void> {
|
|
98
|
+
this.currentAddress = null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async getAddress(): Promise<string | null> {
|
|
102
|
+
return this.currentAddress;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async isConnected(): Promise<boolean> {
|
|
106
|
+
return this.currentAddress !== null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async signTransaction(
|
|
110
|
+
xdr: string,
|
|
111
|
+
options?: SignTransactionOptions
|
|
112
|
+
): Promise<string> {
|
|
113
|
+
await this.isAvailable();
|
|
114
|
+
|
|
115
|
+
if (!window.albedo) {
|
|
116
|
+
throw new WalletError(
|
|
117
|
+
'Albedo is not available',
|
|
118
|
+
WalletErrorCode.NOT_CONNECTED,
|
|
119
|
+
WalletType.ALBEDO
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
const result = await window.albedo.tx({
|
|
125
|
+
xdr,
|
|
126
|
+
network: options?.networkPassphrase || 'testnet',
|
|
127
|
+
pubkey: this.currentAddress || undefined,
|
|
128
|
+
submit: false, // Don't auto-submit
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return result.signed_envelope_xdr;
|
|
132
|
+
} catch (error: any) {
|
|
133
|
+
throw new WalletError(
|
|
134
|
+
`Failed to sign transaction: ${error.message}`,
|
|
135
|
+
WalletErrorCode.SIGNING_FAILED,
|
|
136
|
+
WalletType.ALBEDO
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Freighter Wallet Adapter
|
|
3
|
+
*
|
|
4
|
+
* Official Stellar wallet extension
|
|
5
|
+
* https://freighter.app
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
WalletAdapter,
|
|
10
|
+
WalletType,
|
|
11
|
+
WalletMetadata,
|
|
12
|
+
SignTransactionOptions,
|
|
13
|
+
WalletError,
|
|
14
|
+
WalletErrorCode,
|
|
15
|
+
} from '../types.js';
|
|
16
|
+
|
|
17
|
+
// Freighter API types (from @stellar/freighter-api)
|
|
18
|
+
interface FreighterAPI {
|
|
19
|
+
isConnected(): Promise<boolean>;
|
|
20
|
+
getPublicKey(): Promise<string>;
|
|
21
|
+
signTransaction(
|
|
22
|
+
xdr: string,
|
|
23
|
+
opts?: { network?: string; networkPassphrase?: string; accountToSign?: string }
|
|
24
|
+
): Promise<string>;
|
|
25
|
+
getNetwork(): Promise<string>;
|
|
26
|
+
getNetworkDetails(): Promise<{ network: string; networkPassphrase: string }>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare global {
|
|
30
|
+
interface Window {
|
|
31
|
+
freighter?: FreighterAPI;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class FreighterAdapter implements WalletAdapter {
|
|
36
|
+
type = WalletType.FREIGHTER;
|
|
37
|
+
|
|
38
|
+
metadata: WalletMetadata = {
|
|
39
|
+
type: WalletType.FREIGHTER,
|
|
40
|
+
name: 'Freighter',
|
|
41
|
+
url: 'https://freighter.app',
|
|
42
|
+
chromeUrl: 'https://chrome.google.com/webstore/detail/freighter/bcacfldlkkdogcmkkibnjlakofdplcbk',
|
|
43
|
+
firefoxUrl: 'https://addons.mozilla.org/en-US/firefox/addon/freighter/',
|
|
44
|
+
description: 'Official Stellar wallet extension with Soroban support',
|
|
45
|
+
isAvailable: false,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
private api: FreighterAPI | null = null;
|
|
49
|
+
|
|
50
|
+
constructor() {
|
|
51
|
+
this.init();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private init() {
|
|
55
|
+
if (typeof window !== 'undefined' && window.freighter) {
|
|
56
|
+
this.api = window.freighter;
|
|
57
|
+
this.metadata.isAvailable = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async isAvailable(): Promise<boolean> {
|
|
62
|
+
return this.metadata.isAvailable;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async connect(): Promise<string> {
|
|
66
|
+
if (!this.api) {
|
|
67
|
+
throw new WalletError(
|
|
68
|
+
'Freighter is not installed. Please install from https://freighter.app',
|
|
69
|
+
WalletErrorCode.NOT_INSTALLED,
|
|
70
|
+
WalletType.FREIGHTER
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const publicKey = await this.api.getPublicKey();
|
|
76
|
+
if (!publicKey) {
|
|
77
|
+
throw new WalletError(
|
|
78
|
+
'User rejected connection request',
|
|
79
|
+
WalletErrorCode.USER_REJECTED,
|
|
80
|
+
WalletType.FREIGHTER
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return publicKey;
|
|
84
|
+
} catch (error: any) {
|
|
85
|
+
if (error instanceof WalletError) throw error;
|
|
86
|
+
|
|
87
|
+
throw new WalletError(
|
|
88
|
+
`Failed to connect to Freighter: ${error.message}`,
|
|
89
|
+
WalletErrorCode.UNKNOWN_ERROR,
|
|
90
|
+
WalletType.FREIGHTER
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async disconnect(): Promise<void> {
|
|
96
|
+
// Freighter doesn't have explicit disconnect
|
|
97
|
+
// Connection state is managed by extension
|
|
98
|
+
this.api = null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async getAddress(): Promise<string | null> {
|
|
102
|
+
if (!this.api) return null;
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
const connected = await this.api.isConnected();
|
|
106
|
+
if (!connected) return null;
|
|
107
|
+
|
|
108
|
+
return await this.api.getPublicKey();
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async isConnected(): Promise<boolean> {
|
|
115
|
+
if (!this.api) return false;
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
return await this.api.isConnected();
|
|
119
|
+
} catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async signTransaction(
|
|
125
|
+
xdr: string,
|
|
126
|
+
options?: SignTransactionOptions
|
|
127
|
+
): Promise<string> {
|
|
128
|
+
if (!this.api) {
|
|
129
|
+
throw new WalletError(
|
|
130
|
+
'Freighter is not connected',
|
|
131
|
+
WalletErrorCode.NOT_CONNECTED,
|
|
132
|
+
WalletType.FREIGHTER
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
const signedXdr = await this.api.signTransaction(xdr, {
|
|
138
|
+
networkPassphrase: options?.networkPassphrase,
|
|
139
|
+
accountToSign: options?.accountToSign,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return signedXdr;
|
|
143
|
+
} catch (error: any) {
|
|
144
|
+
if (error.message?.includes('User declined')) {
|
|
145
|
+
throw new WalletError(
|
|
146
|
+
'User rejected signature request',
|
|
147
|
+
WalletErrorCode.USER_REJECTED,
|
|
148
|
+
WalletType.FREIGHTER
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
throw new WalletError(
|
|
153
|
+
`Failed to sign transaction: ${error.message}`,
|
|
154
|
+
WalletErrorCode.SIGNING_FAILED,
|
|
155
|
+
WalletType.FREIGHTER
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async getNetwork(): Promise<string> {
|
|
161
|
+
if (!this.api) {
|
|
162
|
+
throw new WalletError(
|
|
163
|
+
'Freighter is not connected',
|
|
164
|
+
WalletErrorCode.NOT_CONNECTED,
|
|
165
|
+
WalletType.FREIGHTER
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
return await this.api.getNetwork();
|
|
171
|
+
} catch (error: any) {
|
|
172
|
+
throw new WalletError(
|
|
173
|
+
`Failed to get network: ${error.message}`,
|
|
174
|
+
WalletErrorCode.NETWORK_ERROR,
|
|
175
|
+
WalletType.FREIGHTER
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lobstr Wallet Adapter
|
|
3
|
+
*
|
|
4
|
+
* Popular Stellar mobile wallet with extension support
|
|
5
|
+
* https://lobstr.co
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
WalletAdapter,
|
|
10
|
+
WalletType,
|
|
11
|
+
WalletMetadata,
|
|
12
|
+
SignTransactionOptions,
|
|
13
|
+
WalletError,
|
|
14
|
+
WalletErrorCode,
|
|
15
|
+
} from '../types.js';
|
|
16
|
+
|
|
17
|
+
// Lobstr Extension API (similar to Freighter)
|
|
18
|
+
interface LobstrAPI {
|
|
19
|
+
isConnected(): Promise<boolean>;
|
|
20
|
+
getPublicKey(): Promise<string>;
|
|
21
|
+
signTransaction(xdr: string, opts?: { network?: string }): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare global {
|
|
25
|
+
interface Window {
|
|
26
|
+
lobstrExtension?: LobstrAPI;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class LobstrAdapter implements WalletAdapter {
|
|
31
|
+
type = WalletType.LOBSTR;
|
|
32
|
+
|
|
33
|
+
metadata: WalletMetadata = {
|
|
34
|
+
type: WalletType.LOBSTR,
|
|
35
|
+
name: 'Lobstr',
|
|
36
|
+
url: 'https://lobstr.co',
|
|
37
|
+
chromeUrl: 'https://chrome.google.com/webstore/detail/lobstr-extension/cmgchfbiagidgmjmfjkhldngnmlfpnog',
|
|
38
|
+
description: 'Popular Stellar wallet with mobile and extension support',
|
|
39
|
+
isAvailable: false,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
private api: LobstrAPI | null = null;
|
|
43
|
+
|
|
44
|
+
constructor() {
|
|
45
|
+
this.init();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private init() {
|
|
49
|
+
if (typeof window !== 'undefined' && window.lobstrExtension) {
|
|
50
|
+
this.api = window.lobstrExtension;
|
|
51
|
+
this.metadata.isAvailable = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async isAvailable(): Promise<boolean> {
|
|
56
|
+
return this.metadata.isAvailable;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async connect(): Promise<string> {
|
|
60
|
+
if (!this.api) {
|
|
61
|
+
throw new WalletError(
|
|
62
|
+
'Lobstr Extension is not installed',
|
|
63
|
+
WalletErrorCode.NOT_INSTALLED,
|
|
64
|
+
WalletType.LOBSTR
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const publicKey = await this.api.getPublicKey();
|
|
70
|
+
if (!publicKey) {
|
|
71
|
+
throw new WalletError(
|
|
72
|
+
'User rejected connection request',
|
|
73
|
+
WalletErrorCode.USER_REJECTED,
|
|
74
|
+
WalletType.LOBSTR
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return publicKey;
|
|
78
|
+
} catch (error: any) {
|
|
79
|
+
if (error instanceof WalletError) throw error;
|
|
80
|
+
|
|
81
|
+
throw new WalletError(
|
|
82
|
+
`Failed to connect to Lobstr: ${error.message}`,
|
|
83
|
+
WalletErrorCode.UNKNOWN_ERROR,
|
|
84
|
+
WalletType.LOBSTR
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async disconnect(): Promise<void> {
|
|
90
|
+
this.api = null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async getAddress(): Promise<string | null> {
|
|
94
|
+
if (!this.api) return null;
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
const connected = await this.api.isConnected();
|
|
98
|
+
if (!connected) return null;
|
|
99
|
+
|
|
100
|
+
return await this.api.getPublicKey();
|
|
101
|
+
} catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async isConnected(): Promise<boolean> {
|
|
107
|
+
if (!this.api) return false;
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
return await this.api.isConnected();
|
|
111
|
+
} catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async signTransaction(
|
|
117
|
+
xdr: string,
|
|
118
|
+
options?: SignTransactionOptions
|
|
119
|
+
): Promise<string> {
|
|
120
|
+
if (!this.api) {
|
|
121
|
+
throw new WalletError(
|
|
122
|
+
'Lobstr is not connected',
|
|
123
|
+
WalletErrorCode.NOT_CONNECTED,
|
|
124
|
+
WalletType.LOBSTR
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
const signedXdr = await this.api.signTransaction(xdr, {
|
|
130
|
+
network: options?.networkPassphrase,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return signedXdr;
|
|
134
|
+
} catch (error: any) {
|
|
135
|
+
throw new WalletError(
|
|
136
|
+
`Failed to sign transaction: ${error.message}`,
|
|
137
|
+
WalletErrorCode.SIGNING_FAILED,
|
|
138
|
+
WalletType.LOBSTR
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rabet Wallet Adapter
|
|
3
|
+
*
|
|
4
|
+
* Modern Stellar wallet with built-in swap features
|
|
5
|
+
* https://rabet.io
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
WalletAdapter,
|
|
10
|
+
WalletType,
|
|
11
|
+
WalletMetadata,
|
|
12
|
+
SignTransactionOptions,
|
|
13
|
+
WalletError,
|
|
14
|
+
WalletErrorCode,
|
|
15
|
+
} from '../types.js';
|
|
16
|
+
|
|
17
|
+
// Rabet API types
|
|
18
|
+
interface RabetAPI {
|
|
19
|
+
connect(): Promise<{ publicKey: string }>;
|
|
20
|
+
sign(xdr: string, opts?: { network?: string }): Promise<{ xdr: string }>;
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
isConnected(): Promise<boolean>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare global {
|
|
26
|
+
interface Window {
|
|
27
|
+
rabet?: RabetAPI;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class RabetAdapter implements WalletAdapter {
|
|
32
|
+
type = WalletType.RABET;
|
|
33
|
+
|
|
34
|
+
metadata: WalletMetadata = {
|
|
35
|
+
type: WalletType.RABET,
|
|
36
|
+
name: 'Rabet',
|
|
37
|
+
url: 'https://rabet.io',
|
|
38
|
+
chromeUrl: 'https://chrome.google.com/webstore/detail/rabet/aapjbdekemjjmldlfinkhcmkbcfikkde',
|
|
39
|
+
firefoxUrl: 'https://addons.mozilla.org/en-US/firefox/addon/rabet/',
|
|
40
|
+
description: 'Modern Stellar wallet with built-in swap and DeFi features',
|
|
41
|
+
isAvailable: false,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
private api: RabetAPI | null = null;
|
|
45
|
+
|
|
46
|
+
constructor() {
|
|
47
|
+
this.init();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private init() {
|
|
51
|
+
if (typeof window !== 'undefined' && window.rabet) {
|
|
52
|
+
this.api = window.rabet;
|
|
53
|
+
this.metadata.isAvailable = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async isAvailable(): Promise<boolean> {
|
|
58
|
+
return this.metadata.isAvailable;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async connect(): Promise<string> {
|
|
62
|
+
if (!this.api) {
|
|
63
|
+
throw new WalletError(
|
|
64
|
+
'Rabet is not installed',
|
|
65
|
+
WalletErrorCode.NOT_INSTALLED,
|
|
66
|
+
WalletType.RABET
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const result = await this.api.connect();
|
|
72
|
+
if (!result.publicKey) {
|
|
73
|
+
throw new WalletError(
|
|
74
|
+
'User rejected connection request',
|
|
75
|
+
WalletErrorCode.USER_REJECTED,
|
|
76
|
+
WalletType.RABET
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return result.publicKey;
|
|
80
|
+
} catch (error: any) {
|
|
81
|
+
if (error instanceof WalletError) throw error;
|
|
82
|
+
|
|
83
|
+
throw new WalletError(
|
|
84
|
+
`Failed to connect to Rabet: ${error.message}`,
|
|
85
|
+
WalletErrorCode.UNKNOWN_ERROR,
|
|
86
|
+
WalletType.RABET
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async disconnect(): Promise<void> {
|
|
92
|
+
if (this.api) {
|
|
93
|
+
try {
|
|
94
|
+
await this.api.disconnect();
|
|
95
|
+
} catch {
|
|
96
|
+
// Ignore disconnect errors
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.api = null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async getAddress(): Promise<string | null> {
|
|
103
|
+
if (!this.api) return null;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const connected = await this.api.isConnected();
|
|
107
|
+
if (!connected) return null;
|
|
108
|
+
|
|
109
|
+
// Rabet doesn't expose getPublicKey directly
|
|
110
|
+
// Need to reconnect to get address
|
|
111
|
+
const result = await this.api.connect();
|
|
112
|
+
return result.publicKey;
|
|
113
|
+
} catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async isConnected(): Promise<boolean> {
|
|
119
|
+
if (!this.api) return false;
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
return await this.api.isConnected();
|
|
123
|
+
} catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async signTransaction(
|
|
129
|
+
xdr: string,
|
|
130
|
+
options?: SignTransactionOptions
|
|
131
|
+
): Promise<string> {
|
|
132
|
+
if (!this.api) {
|
|
133
|
+
throw new WalletError(
|
|
134
|
+
'Rabet is not connected',
|
|
135
|
+
WalletErrorCode.NOT_CONNECTED,
|
|
136
|
+
WalletType.RABET
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
const result = await this.api.sign(xdr, {
|
|
142
|
+
network: options?.networkPassphrase,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return result.xdr;
|
|
146
|
+
} catch (error: any) {
|
|
147
|
+
if (error.message?.includes('User cancelled')) {
|
|
148
|
+
throw new WalletError(
|
|
149
|
+
'User rejected signature request',
|
|
150
|
+
WalletErrorCode.USER_REJECTED,
|
|
151
|
+
WalletType.RABET
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
throw new WalletError(
|
|
156
|
+
`Failed to sign transaction: ${error.message}`,
|
|
157
|
+
WalletErrorCode.SIGNING_FAILED,
|
|
158
|
+
WalletType.RABET
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|