@chipi-stack/starknet-connector 0.3.0 → 0.5.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 +203 -51
- package/dist/index.cjs +309 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +157 -10
- package/dist/index.d.ts +157 -10
- package/dist/index.js +308 -25
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connector } from '@starknet-react/core';
|
|
2
2
|
import { ProviderInterface, AccountInterface } from 'starknet';
|
|
3
|
-
import { StarknetWindowObject, RpcMessage, RequestFnCall, RpcTypeToMessageMap } from '@starknet-io/types-js';
|
|
3
|
+
import { StarknetWindowObject, RpcMessage, RequestFnCall, RpcTypeToMessageMap, RequestFn } from '@starknet-io/types-js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Wire protocol between the "Connect with Chipi" connector (running in the dApp)
|
|
@@ -68,7 +68,9 @@ declare function isChipiDappMessage(data: unknown): data is ChipiDappMessage;
|
|
|
68
68
|
* Client-side (dApp) transport: opens the Chipi hosted wallet in a popup,
|
|
69
69
|
* performs the ready handshake, and forwards get-starknet `wallet_*` RPC calls
|
|
70
70
|
* over `postMessage`, correlating responses by id. The popup is reused across
|
|
71
|
-
* requests
|
|
71
|
+
* requests. If the user closes it, later requests reject with `POPUP_CLOSED`
|
|
72
|
+
* instead of reopening it: `window.open` outside a click is blocked by
|
|
73
|
+
* browsers, so the dApp must call `connect()` (or `open()`) again from a click.
|
|
72
74
|
*/
|
|
73
75
|
|
|
74
76
|
interface ChipiTransportOptions {
|
|
@@ -89,9 +91,19 @@ interface ChipiTransportOptions {
|
|
|
89
91
|
windowName?: string;
|
|
90
92
|
/** Popup window features. */
|
|
91
93
|
windowFeatures?: string;
|
|
92
|
-
/** Ready-handshake timeout (ms).
|
|
94
|
+
/** Ready-handshake timeout (ms). Defaults to 180_000. On timeout the popup is
|
|
95
|
+
* closed and the transport resets, so the next `open()` starts clean. */
|
|
93
96
|
openTimeoutMs?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Per-request timeout (ms), counted from when the request is posted to the
|
|
99
|
+
* wallet. Defaults to 120_000. A request that gets no answer in time rejects
|
|
100
|
+
* with an Error whose `code` (and `name`) is `"REQUEST_TIMEOUT"`. Pass `0` to
|
|
101
|
+
* disable.
|
|
102
|
+
*/
|
|
103
|
+
requestTimeoutMs?: number;
|
|
94
104
|
}
|
|
105
|
+
/** Error codes the transport attaches to `Error.code` (besides wallet codes). */
|
|
106
|
+
type ChipiTransportErrorCode = "REQUEST_TIMEOUT" | "POPUP_CLOSED";
|
|
95
107
|
type EventName = "accountsChanged" | "networkChanged";
|
|
96
108
|
type EventHandler = (data: unknown) => void;
|
|
97
109
|
declare class ChipiPopupTransport {
|
|
@@ -107,6 +119,9 @@ declare class ChipiPopupTransport {
|
|
|
107
119
|
private readyDeferred;
|
|
108
120
|
private openPromise;
|
|
109
121
|
private closeWatch;
|
|
122
|
+
/** True once this transport opened a popup. A later request with no live
|
|
123
|
+
* popup means the user closed it: reject instead of reopening off-gesture. */
|
|
124
|
+
private hadPopup;
|
|
110
125
|
constructor(opts: ChipiTransportOptions);
|
|
111
126
|
on(event: EventName, handler: EventHandler): void;
|
|
112
127
|
off(event: EventName, handler: EventHandler): void;
|
|
@@ -118,6 +133,8 @@ declare class ChipiPopupTransport {
|
|
|
118
133
|
* its ready handshake. Concurrent calls share ONE handshake. */
|
|
119
134
|
open(): Promise<void>;
|
|
120
135
|
private doOpen;
|
|
136
|
+
/** Close the popup (if we own one) and forget the target + ready state. */
|
|
137
|
+
private resetTarget;
|
|
121
138
|
private awaitReady;
|
|
122
139
|
/** Reject every in-flight request (popup closed / disconnected). */
|
|
123
140
|
private rejectAllPending;
|
|
@@ -125,7 +142,19 @@ declare class ChipiPopupTransport {
|
|
|
125
142
|
* reject them: otherwise the dApp's promise would hang forever. */
|
|
126
143
|
private startCloseWatch;
|
|
127
144
|
private stopCloseWatch;
|
|
128
|
-
/**
|
|
145
|
+
/**
|
|
146
|
+
* Forward a get-starknet RPC call to the wallet, awaiting its response.
|
|
147
|
+
*
|
|
148
|
+
* With no wallet window open, passive calls are answered locally and never
|
|
149
|
+
* open it: `wallet_getPermissions` → `[]`, `wallet_requestAccounts` with
|
|
150
|
+
* `silent_mode: true` → `[]`, `wallet_requestChainId` → SN_MAIN.
|
|
151
|
+
*
|
|
152
|
+
* The first request may open the popup. Once a popup has been opened, a
|
|
153
|
+
* request made after it was closed rejects with `code: "POPUP_CLOSED"`
|
|
154
|
+
* instead of calling `window.open` again: requests usually run outside a
|
|
155
|
+
* click, where browsers block popups. Reopen via `connect()` / `open()`
|
|
156
|
+
* from a click.
|
|
157
|
+
*/
|
|
129
158
|
request(call: ChipiRpcCall): Promise<unknown>;
|
|
130
159
|
/** Close the popup (if we own one) + reject in-flight requests. */
|
|
131
160
|
close(): void;
|
|
@@ -147,6 +176,10 @@ type ConnectorData = {
|
|
|
147
176
|
account?: string;
|
|
148
177
|
chainId?: bigint;
|
|
149
178
|
};
|
|
179
|
+
/** Mirrors starknet-react's `ConnectArgs` (not exported by every version). */
|
|
180
|
+
type ConnectArgs = {
|
|
181
|
+
chainIdHint?: bigint;
|
|
182
|
+
};
|
|
150
183
|
interface ChipiConnectorOptions {
|
|
151
184
|
/** Hosted wallet base URL. Defaults to `https://wallet.chipipay.com`. */
|
|
152
185
|
walletUrl?: string;
|
|
@@ -154,12 +187,19 @@ interface ChipiConnectorOptions {
|
|
|
154
187
|
id?: string;
|
|
155
188
|
name?: string;
|
|
156
189
|
icon?: ConnectorIcons;
|
|
157
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Popup transport tuning: `windowName`, `windowFeatures`, `openTimeoutMs`,
|
|
192
|
+
* `requestTimeoutMs`. `walletUrl` is optional here (the top-level
|
|
193
|
+
* `walletUrl` wins) and `mode` is always `"popup"`.
|
|
194
|
+
*/
|
|
195
|
+
transport?: Omit<ChipiTransportOptions, "walletUrl"> & {
|
|
196
|
+
walletUrl?: string;
|
|
197
|
+
};
|
|
158
198
|
/**
|
|
159
199
|
* Self-register the wallet on `window` (set `window.starknet_chipi` + announce
|
|
160
|
-
* via `starknet:announceWallet`) so dApps that *scan*
|
|
161
|
-
* get-starknet
|
|
162
|
-
* also discover "Connect with Chipi". Defaults to `true` in a browser; pass
|
|
200
|
+
* via `starknet:announceWallet`) so dApps that *scan* `window.starknet*`
|
|
201
|
+
* (get-starknet v4, get-starknet-discovery's injected scan) and don't import
|
|
202
|
+
* this connector also discover "Connect with Chipi". Defaults to `true` in a browser; pass
|
|
163
203
|
* `false` to opt out (e.g. to avoid a double entry in a picker that already
|
|
164
204
|
* lists the connector explicitly). No-op during SSR.
|
|
165
205
|
*/
|
|
@@ -173,6 +213,7 @@ declare class ChipiConnector extends Connector {
|
|
|
173
213
|
private _account;
|
|
174
214
|
private _swo;
|
|
175
215
|
private _registration;
|
|
216
|
+
private readonly _autoRegister;
|
|
176
217
|
constructor(options?: ChipiConnectorOptions);
|
|
177
218
|
/**
|
|
178
219
|
* Announce this wallet to scanning dApps (`window.starknet_chipi` +
|
|
@@ -191,8 +232,18 @@ declare class ChipiConnector extends Connector {
|
|
|
191
232
|
ready(): Promise<boolean>;
|
|
192
233
|
/** Lazily build the postMessage-backed get-starknet window object. */
|
|
193
234
|
private swo;
|
|
194
|
-
|
|
235
|
+
/**
|
|
236
|
+
* Open the hosted wallet (call from a click: it opens a popup) and request
|
|
237
|
+
* the account. Chipi is mainnet-only: a `chainIdHint` other than SN_MAIN
|
|
238
|
+
* rejects before any popup opens.
|
|
239
|
+
*/
|
|
240
|
+
connect(args?: ConnectArgs): Promise<ConnectorData>;
|
|
195
241
|
disconnect(): Promise<void>;
|
|
242
|
+
/** Forward the wallet's account/network events as starknet-react events. */
|
|
243
|
+
private subscribe;
|
|
244
|
+
private unsubscribe;
|
|
245
|
+
private onAccountsChanged;
|
|
246
|
+
private onNetworkChanged;
|
|
196
247
|
private emitEvent;
|
|
197
248
|
account(provider: ProviderInterface): Promise<AccountInterface>;
|
|
198
249
|
chainId(): Promise<bigint>;
|
|
@@ -233,4 +284,100 @@ interface ChipiRegistration {
|
|
|
233
284
|
*/
|
|
234
285
|
declare function registerChipiWallet(wallet: StarknetWindowObject, target?: (Window & typeof globalThis) | undefined): ChipiRegistration;
|
|
235
286
|
|
|
236
|
-
|
|
287
|
+
/**
|
|
288
|
+
* Chipi as a Wallet Standard wallet with Starknet features
|
|
289
|
+
* (`WalletWithStarknetFeatures` from `@starknet-io/get-starknet-wallet-standard`),
|
|
290
|
+
* so dApps on get-starknet v5+/v6 discovery (`@starknet-io/get-starknet-discovery`,
|
|
291
|
+
* `@starknet-start/react`, anything that listens for
|
|
292
|
+
* `wallet-standard:register-wallet`) list "Chipi" without importing this
|
|
293
|
+
* package's connector.
|
|
294
|
+
*
|
|
295
|
+
* Backed by the same popup transport as {@link ChipiConnector}. The types
|
|
296
|
+
* below mirror the upstream interfaces structurally so this package keeps no
|
|
297
|
+
* runtime (or type) dependency on `@wallet-standard/*`.
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
/** Wallet Standard chain id for Starknet mainnet: `starknet:` + hex of "SN_MAIN"
|
|
301
|
+
* (same as `WELL_KNOWN_STARKNET_CHAINS[0]` in get-starknet-wallet-standard). */
|
|
302
|
+
declare const CHIPI_STARKNET_MAINNET_CHAIN: "starknet:0x534e5f4d41494e";
|
|
303
|
+
/** `starknet:0x...` chain identifier. */
|
|
304
|
+
type ChipiStarknetChain = `starknet:0x${string}`;
|
|
305
|
+
/** Data-URI icon, as Wallet Standard requires. */
|
|
306
|
+
type ChipiWalletIcon = `data:image/${"svg+xml" | "webp" | "png" | "gif"};base64,${string}`;
|
|
307
|
+
/** Mirrors `@wallet-standard/base` `WalletAccount`. */
|
|
308
|
+
interface ChipiStandardWalletAccount {
|
|
309
|
+
readonly address: string;
|
|
310
|
+
readonly publicKey: Uint8Array;
|
|
311
|
+
readonly chains: readonly ChipiStarknetChain[];
|
|
312
|
+
readonly features: readonly `${string}:${string}`[];
|
|
313
|
+
}
|
|
314
|
+
/** Mirrors `@wallet-standard/features` `StandardEventsChangeProperties`. */
|
|
315
|
+
interface ChipiStandardChangeProperties {
|
|
316
|
+
readonly chains?: readonly ChipiStarknetChain[];
|
|
317
|
+
readonly accounts?: readonly ChipiStandardWalletAccount[];
|
|
318
|
+
}
|
|
319
|
+
/** Mirrors `StarknetFeatures` from `@starknet-io/get-starknet-wallet-standard`.
|
|
320
|
+
* (A type alias, not an interface, so it satisfies Wallet Standard's
|
|
321
|
+
* `IdentifierRecord` index signature.) */
|
|
322
|
+
type ChipiStandardWalletFeatures = {
|
|
323
|
+
readonly "starknet:walletApi": {
|
|
324
|
+
readonly version: "1.0.0";
|
|
325
|
+
readonly request: RequestFn;
|
|
326
|
+
readonly walletVersion: string;
|
|
327
|
+
readonly id: string;
|
|
328
|
+
};
|
|
329
|
+
readonly "standard:connect": {
|
|
330
|
+
readonly version: "1.0.0";
|
|
331
|
+
readonly connect: (input?: {
|
|
332
|
+
readonly silent?: boolean;
|
|
333
|
+
}) => Promise<{
|
|
334
|
+
readonly accounts: readonly ChipiStandardWalletAccount[];
|
|
335
|
+
}>;
|
|
336
|
+
};
|
|
337
|
+
readonly "standard:disconnect": {
|
|
338
|
+
readonly version: "1.0.0";
|
|
339
|
+
readonly disconnect: () => Promise<void>;
|
|
340
|
+
};
|
|
341
|
+
readonly "standard:events": {
|
|
342
|
+
readonly version: "1.0.0";
|
|
343
|
+
readonly on: <E extends "change">(event: E, listener: (properties: ChipiStandardChangeProperties) => void) => () => void;
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
/** Structurally a `WalletWithStarknetFeatures`. */
|
|
347
|
+
interface ChipiStandardWallet {
|
|
348
|
+
readonly version: "1.0.0";
|
|
349
|
+
readonly name: string;
|
|
350
|
+
readonly icon: ChipiWalletIcon;
|
|
351
|
+
readonly chains: readonly ChipiStarknetChain[];
|
|
352
|
+
readonly accounts: readonly ChipiStandardWalletAccount[];
|
|
353
|
+
readonly features: ChipiStandardWalletFeatures;
|
|
354
|
+
}
|
|
355
|
+
interface ChipiStandardWalletOptions {
|
|
356
|
+
/** Hosted wallet base URL. Defaults to `https://wallet.chipipay.com`. */
|
|
357
|
+
walletUrl?: string;
|
|
358
|
+
/** Display name. Defaults to `"Chipi"`. */
|
|
359
|
+
name?: string;
|
|
360
|
+
/** Data-URI icon. Defaults to the Chipi icon. */
|
|
361
|
+
icon?: ChipiWalletIcon;
|
|
362
|
+
/** Popup transport tuning (window name/features, timeouts). */
|
|
363
|
+
transport?: Omit<ChipiTransportOptions, "walletUrl" | "mode">;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Build the Chipi Wallet Standard wallet (without registering it). `connect`
|
|
367
|
+
* opens the popup, so dApps call it from a click; `connect({ silent: true })`
|
|
368
|
+
* never opens a popup and returns the current accounts (empty if not
|
|
369
|
+
* connected).
|
|
370
|
+
*/
|
|
371
|
+
declare function createChipiStandardWallet(options?: ChipiStandardWalletOptions): ChipiStandardWallet;
|
|
372
|
+
/**
|
|
373
|
+
* Register Chipi with every Wallet Standard app on the page: dispatches
|
|
374
|
+
* `wallet-standard:register-wallet` now and answers later
|
|
375
|
+
* `wallet-standard:app-ready` events (the `@wallet-standard/wallet`
|
|
376
|
+
* `registerWallet` protocol, implemented here without the dependency).
|
|
377
|
+
*
|
|
378
|
+
* Returns an unregister function that removes the listener and unregisters
|
|
379
|
+
* from every app that accepted the wallet. SSR-safe: a no-op without `window`.
|
|
380
|
+
*/
|
|
381
|
+
declare function registerChipiStandardWallet(options?: ChipiStandardWalletOptions, target?: (Window & typeof globalThis) | undefined): () => void;
|
|
382
|
+
|
|
383
|
+
export { CHIPI_STARKNET_MAINNET_CHAIN, CHIPI_WC, CHIPI_WINDOW_KEY, ChipiConnector, type ChipiConnectorOptions, type ChipiDappMessage, type ChipiEventMessage, ChipiPopupTransport, type ChipiReadyMessage, type ChipiRegistration, type ChipiRpcCall, type ChipiRpcRequestMessage, type ChipiRpcResultMessage, type ChipiStandardChangeProperties, type ChipiStandardWallet, type ChipiStandardWalletAccount, type ChipiStandardWalletFeatures, type ChipiStandardWalletOptions, type ChipiStarknetChain, type ChipiTransportErrorCode, type ChipiTransportOptions, type ChipiWalletIcon, type ChipiWalletMessage, chipi, createChipiStandardWallet, isChipiDappMessage, isChipiWalletMessage, registerChipiStandardWallet, registerChipiWallet };
|