@lydianpay/lydianconnect 1.0.0 → 1.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.
- package/README.md +23 -56
- package/dist/index.cjs +345 -245
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -163
- package/dist/index.d.ts +38 -163
- package/dist/index.js +346 -241
- package/dist/index.js.map +1 -1
- package/package.json +1 -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;
|
|
@@ -28,8 +34,30 @@ interface Connection {
|
|
|
28
34
|
method: string;
|
|
29
35
|
params?: unknown;
|
|
30
36
|
}): Promise<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Bring the wallet app to the foreground (mobile) — call right before a request
|
|
39
|
+
* the user must approve. No-op for native-SDK wallets (their SDK foregrounds the
|
|
40
|
+
* wallet itself) and on desktop.
|
|
41
|
+
*/
|
|
42
|
+
openWallet(): void;
|
|
31
43
|
disconnect(): Promise<void>;
|
|
32
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The single config object the host app passes to `LydianConnect`.
|
|
47
|
+
* Extends {@link AppConfig} so the shared identity fields (appName/icon/description)
|
|
48
|
+
* are defined once and can't drift between the two shapes.
|
|
49
|
+
*/
|
|
50
|
+
interface LydianConnectConfig extends AppConfig {
|
|
51
|
+
/** WalletConnect Cloud project id — powers the fallback. */
|
|
52
|
+
walletConnectProjectId: string;
|
|
53
|
+
}
|
|
54
|
+
interface ConnectInput {
|
|
55
|
+
walletId: string;
|
|
56
|
+
/** Chain to connect on — a number (EVM, e.g. 137) or a CAIP-2 id ('eip155:137'). */
|
|
57
|
+
chainId: number | string;
|
|
58
|
+
/** Cancel a pending connection. */
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
}
|
|
33
61
|
type LydianConnectEvent =
|
|
34
62
|
/** WalletConnect only — the wc: URI. Deep-linking is fired internally; emitted for QR display. */
|
|
35
63
|
{
|
|
@@ -60,174 +88,21 @@ type LydianConnectEvent =
|
|
|
60
88
|
};
|
|
61
89
|
type LydianConnectEventHandler = (event: LydianConnectEvent) => void;
|
|
62
90
|
|
|
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
91
|
/**
|
|
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.
|
|
92
|
+
* The single surface the host app touches. Hand it a flat config; it owns the
|
|
93
|
+
* connectors and routes each wallet to its native SDK (or the WalletConnect
|
|
94
|
+
* fallback), returning a uniform {@link Connection} either way.
|
|
115
95
|
*/
|
|
116
96
|
declare class LydianConnect {
|
|
117
|
-
private
|
|
118
|
-
private fallback;
|
|
119
|
-
private all;
|
|
120
|
-
private connections;
|
|
121
|
-
private handlers;
|
|
122
|
-
private unsubs;
|
|
123
|
-
private started;
|
|
97
|
+
private manager;
|
|
124
98
|
constructor(config: LydianConnectConfig);
|
|
125
|
-
/** Wire connector event forwarding, once. Safe to call repeatedly. */
|
|
126
99
|
init(): Promise<void>;
|
|
127
|
-
/** SDK connector if one claims this walletId, else the WC fallback. The host app is oblivious. */
|
|
128
|
-
private resolve;
|
|
129
100
|
connect(input: ConnectInput): Promise<Connection>;
|
|
130
|
-
/** Resume any live sessions across all connectors (e.g. after a page reload). */
|
|
131
101
|
restore(): Promise<Connection[]>;
|
|
132
|
-
get(walletId: string): Connection | undefined;
|
|
133
102
|
disconnect(walletId?: string): Promise<void>;
|
|
134
|
-
/** Disconnect everything and clear all connector-held state. */
|
|
135
103
|
reset(): Promise<void>;
|
|
104
|
+
get(walletId: string): Connection | undefined;
|
|
136
105
|
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
106
|
}
|
|
232
107
|
|
|
233
|
-
export {
|
|
108
|
+
export { type CaipNamespace, type ConnectInput, type Connection, LydianConnect, type LydianConnectConfig, type LydianConnectEvent, type LydianConnectEventHandler };
|