@lydianpay/lydianconnect 0.0.0-managed → 1.0.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/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/index.cjs +307 -217
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -163
- package/dist/index.d.ts +32 -163
- package/dist/index.js +308 -213
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/** Shared app identity passed to every connector; mapped to each SDK's own shape internally. */
|
|
2
|
+
interface AppConfig {
|
|
3
|
+
/** Display name shown in the wallet's connect prompt. */
|
|
4
|
+
appName: string;
|
|
5
|
+
/** Optional icon shown in the wallet's connect prompt. */
|
|
6
|
+
icon?: string;
|
|
7
|
+
/** Optional description; defaults to appName. */
|
|
8
|
+
description?: string;
|
|
9
|
+
}
|
|
3
10
|
|
|
4
|
-
|
|
5
|
-
/** A CAIP namespace request — pay already models this per-network today. */
|
|
11
|
+
/** A CAIP namespace request — the host app already models this per-network. */
|
|
6
12
|
interface CaipNamespace {
|
|
7
13
|
/** Namespace identifier, e.g. "eip155", "solana". */
|
|
8
14
|
name: string;
|
|
@@ -30,6 +36,22 @@ interface Connection {
|
|
|
30
36
|
}): Promise<T>;
|
|
31
37
|
disconnect(): Promise<void>;
|
|
32
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* The single config object the host app passes to `LydianConnect`.
|
|
41
|
+
* Extends {@link AppConfig} so the shared identity fields (appName/icon/description)
|
|
42
|
+
* are defined once and can't drift between the two shapes.
|
|
43
|
+
*/
|
|
44
|
+
interface LydianConnectConfig extends AppConfig {
|
|
45
|
+
/** WalletConnect Cloud project id — powers the fallback. */
|
|
46
|
+
walletConnectProjectId: string;
|
|
47
|
+
}
|
|
48
|
+
interface ConnectInput {
|
|
49
|
+
walletId: string;
|
|
50
|
+
/** Chain to connect on — a number (EVM, e.g. 137) or a CAIP-2 id ('eip155:137'). */
|
|
51
|
+
chainId: number | string;
|
|
52
|
+
/** Cancel a pending connection. */
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
}
|
|
33
55
|
type LydianConnectEvent =
|
|
34
56
|
/** WalletConnect only — the wc: URI. Deep-linking is fired internally; emitted for QR display. */
|
|
35
57
|
{
|
|
@@ -60,174 +82,21 @@ type LydianConnectEvent =
|
|
|
60
82
|
};
|
|
61
83
|
type LydianConnectEventHandler = (event: LydianConnectEvent) => void;
|
|
62
84
|
|
|
63
|
-
interface ConnectRequest {
|
|
64
|
-
walletId: string;
|
|
65
|
-
namespace: CaipNamespace;
|
|
66
|
-
/** Cancel a pending connection (replaces the host app's manual cancel plumbing). */
|
|
67
|
-
signal?: AbortSignal;
|
|
68
|
-
}
|
|
69
85
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
|
|
73
|
-
interface Connector {
|
|
74
|
-
readonly type: ConnectorType;
|
|
75
|
-
/**
|
|
76
|
-
* Wallet ids this connector natively serves. The WalletConnect fallback
|
|
77
|
-
* returns an empty list and claims any wallet not served by another connector.
|
|
78
|
-
*/
|
|
79
|
-
readonly walletIds: readonly string[];
|
|
80
|
-
isAvailable(walletId: string): boolean | Promise<boolean>;
|
|
81
|
-
connect(req: ConnectRequest): Promise<Connection>;
|
|
82
|
-
/** Rebuild Connections for still-live sessions — the reconnect-on-reload case. */
|
|
83
|
-
restore(): Promise<Connection[]>;
|
|
84
|
-
/** Tear down everything this connector owns. */
|
|
85
|
-
reset(): Promise<void>;
|
|
86
|
-
on(handler: LydianConnectEventHandler): () => void;
|
|
87
|
-
}
|
|
88
|
-
declare abstract class BaseConnector implements Connector {
|
|
89
|
-
abstract readonly type: ConnectorType;
|
|
90
|
-
readonly walletIds: readonly string[];
|
|
91
|
-
private handlers;
|
|
92
|
-
abstract isAvailable(walletId: string): boolean | Promise<boolean>;
|
|
93
|
-
abstract connect(req: ConnectRequest): Promise<Connection>;
|
|
94
|
-
restore(): Promise<Connection[]>;
|
|
95
|
-
reset(): Promise<void>;
|
|
96
|
-
on(handler: LydianConnectEventHandler): () => void;
|
|
97
|
-
protected emit(event: LydianConnectEvent): void;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
interface LydianConnectConfig {
|
|
101
|
-
/** SDK/injected connectors, each serving specific walletIds (MetaMask, Coinbase…). */
|
|
102
|
-
connectors?: Connector[];
|
|
103
|
-
/** Fallback for any wallet not served above — the WalletConnect connector. */
|
|
104
|
-
fallback: Connector;
|
|
105
|
-
}
|
|
106
|
-
interface ConnectInput {
|
|
107
|
-
walletId: string;
|
|
108
|
-
namespace: CaipNamespace;
|
|
109
|
-
signal?: AbortSignal;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* The single surface the host app touches. Routes each wallet to its native
|
|
113
|
-
* SDK connector when one is registered, otherwise to the WalletConnect
|
|
114
|
-
* fallback — and hands back a uniform {@link Connection} either way.
|
|
86
|
+
* The single surface the host app touches. Hand it a flat config; it owns the
|
|
87
|
+
* connectors and routes each wallet to its native SDK (or the WalletConnect
|
|
88
|
+
* fallback), returning a uniform {@link Connection} either way.
|
|
115
89
|
*/
|
|
116
90
|
declare class LydianConnect {
|
|
117
|
-
private
|
|
118
|
-
private fallback;
|
|
119
|
-
private all;
|
|
120
|
-
private connections;
|
|
121
|
-
private handlers;
|
|
122
|
-
private unsubs;
|
|
123
|
-
private started;
|
|
91
|
+
private manager;
|
|
124
92
|
constructor(config: LydianConnectConfig);
|
|
125
|
-
/** Wire connector event forwarding, once. Safe to call repeatedly. */
|
|
126
93
|
init(): Promise<void>;
|
|
127
|
-
/** SDK connector if one claims this walletId, else the WC fallback. The host app is oblivious. */
|
|
128
|
-
private resolve;
|
|
129
94
|
connect(input: ConnectInput): Promise<Connection>;
|
|
130
|
-
/** Resume any live sessions across all connectors (e.g. after a page reload). */
|
|
131
95
|
restore(): Promise<Connection[]>;
|
|
132
|
-
get(walletId: string): Connection | undefined;
|
|
133
96
|
disconnect(walletId?: string): Promise<void>;
|
|
134
|
-
/** Disconnect everything and clear all connector-held state. */
|
|
135
97
|
reset(): Promise<void>;
|
|
98
|
+
get(walletId: string): Connection | undefined;
|
|
136
99
|
on(handler: LydianConnectEventHandler): () => void;
|
|
137
|
-
private handle;
|
|
138
|
-
private emit;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
interface WalletLink {
|
|
142
|
-
/** Custom scheme deep link incl. the `wc` path; we append `?uri=`. e.g. "metamask://wc". */
|
|
143
|
-
scheme?: string;
|
|
144
|
-
/** Universal/applink incl. the `wc` path, preferred on mobile (OS falls back to the store). */
|
|
145
|
-
universal?: string;
|
|
146
|
-
/** App store links — used for the "wallet not installed" fallback. */
|
|
147
|
-
store?: {
|
|
148
|
-
ios?: string;
|
|
149
|
-
android?: string;
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
declare const DEFAULT_WALLET_LINKS: Record<string, WalletLink>;
|
|
153
|
-
|
|
154
|
-
interface WalletConnectConfig {
|
|
155
|
-
projectId: string;
|
|
156
|
-
metadata: SignClientTypes.Metadata;
|
|
157
|
-
relayUrl?: string;
|
|
158
|
-
walletLinks?: Record<string, WalletLink>;
|
|
159
|
-
openTimeoutMs?: number;
|
|
160
|
-
}
|
|
161
|
-
declare class WalletConnectConnector extends BaseConnector {
|
|
162
|
-
private config;
|
|
163
|
-
readonly type: "walletconnect";
|
|
164
|
-
readonly walletIds: readonly string[];
|
|
165
|
-
private client;
|
|
166
|
-
private links;
|
|
167
|
-
private topics;
|
|
168
|
-
private warm;
|
|
169
|
-
private warming;
|
|
170
|
-
constructor(config: WalletConnectConfig);
|
|
171
|
-
isAvailable(): boolean;
|
|
172
|
-
private getClient;
|
|
173
|
-
/** Pre-create a pairing so connect() can deep-link synchronously within the gesture. */
|
|
174
|
-
private warmup;
|
|
175
|
-
connect(req: ConnectRequest): Promise<Connection>;
|
|
176
|
-
restore(): Promise<Connection[]>;
|
|
177
|
-
reset(): Promise<void>;
|
|
178
|
-
private tryReuse;
|
|
179
|
-
private toConnection;
|
|
180
|
-
private liveSession;
|
|
181
|
-
private walletForTopic;
|
|
182
|
-
private persist;
|
|
183
|
-
private load;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
interface MetaMaskConfig {
|
|
187
|
-
dappMetadata: MetaMaskSDKOptions['dappMetadata'];
|
|
188
|
-
/** Extra options forwarded to MetaMaskSDK (infuraAPIKey, logging, …). */
|
|
189
|
-
sdkOptions?: Omit<MetaMaskSDKOptions, 'dappMetadata'>;
|
|
190
|
-
}
|
|
191
|
-
declare class MetaMaskConnector extends BaseConnector {
|
|
192
|
-
private config;
|
|
193
|
-
readonly type: "sdk";
|
|
194
|
-
readonly walletIds: readonly ["metamask"];
|
|
195
|
-
private sdk;
|
|
196
|
-
private provider;
|
|
197
|
-
private listenersBound;
|
|
198
|
-
constructor(config: MetaMaskConfig);
|
|
199
|
-
isAvailable(): boolean;
|
|
200
|
-
private getProvider;
|
|
201
|
-
private bindEvents;
|
|
202
|
-
connect(req: ConnectRequest): Promise<Connection>;
|
|
203
|
-
restore(): Promise<Connection[]>;
|
|
204
|
-
reset(): Promise<void>;
|
|
205
|
-
/** Best-effort switch to the requested chain; leaves the wallet as-is if it's unknown to it. */
|
|
206
|
-
private ensureChain;
|
|
207
|
-
private toConnection;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
interface CoinbaseConfig {
|
|
211
|
-
appName: string;
|
|
212
|
-
appLogoUrl?: string;
|
|
213
|
-
/** EVM chain ids the dapp supports, passed to the SDK. */
|
|
214
|
-
appChainIds?: number[];
|
|
215
|
-
}
|
|
216
|
-
declare class CoinbaseConnector extends BaseConnector {
|
|
217
|
-
private config;
|
|
218
|
-
readonly type: "sdk";
|
|
219
|
-
readonly walletIds: readonly ["coinbase"];
|
|
220
|
-
private provider;
|
|
221
|
-
private listenersBound;
|
|
222
|
-
constructor(config: CoinbaseConfig);
|
|
223
|
-
isAvailable(): boolean;
|
|
224
|
-
private getProvider;
|
|
225
|
-
private bindEvents;
|
|
226
|
-
connect(req: ConnectRequest): Promise<Connection>;
|
|
227
|
-
restore(): Promise<Connection[]>;
|
|
228
|
-
reset(): Promise<void>;
|
|
229
|
-
private ensureChain;
|
|
230
|
-
private toConnection;
|
|
231
100
|
}
|
|
232
101
|
|
|
233
|
-
export {
|
|
102
|
+
export { type CaipNamespace, type ConnectInput, type Connection, LydianConnect, type LydianConnectConfig, type LydianConnectEvent, type LydianConnectEventHandler };
|