@shadow-corp/nearconnect 1.0.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 +546 -0
- package/build/InjectedWallet.d.ts +22 -0
- package/build/InjectedWallet.js +58 -0
- package/build/InjectedWallet.js.map +1 -0
- package/build/NearConnector.d.ts +151 -0
- package/build/NearConnector.js +536 -0
- package/build/NearConnector.js.map +1 -0
- package/build/ParentFrameWallet.d.ts +22 -0
- package/build/ParentFrameWallet.js +66 -0
- package/build/ParentFrameWallet.js.map +1 -0
- package/build/SandboxedWallet/code.d.ts +7 -0
- package/build/SandboxedWallet/code.js +324 -0
- package/build/SandboxedWallet/code.js.map +1 -0
- package/build/SandboxedWallet/executor.d.ts +23 -0
- package/build/SandboxedWallet/executor.js +338 -0
- package/build/SandboxedWallet/executor.js.map +1 -0
- package/build/SandboxedWallet/iframe.d.ts +18 -0
- package/build/SandboxedWallet/iframe.js +78 -0
- package/build/SandboxedWallet/iframe.js.map +1 -0
- package/build/SandboxedWallet/index.d.ts +24 -0
- package/build/SandboxedWallet/index.js +54 -0
- package/build/SandboxedWallet/index.js.map +1 -0
- package/build/actions/index.d.ts +3 -0
- package/build/actions/index.js +105 -0
- package/build/actions/index.js.map +1 -0
- package/build/actions/types.d.ts +76 -0
- package/build/actions/types.js +3 -0
- package/build/actions/types.js.map +1 -0
- package/build/connection/health.d.ts +213 -0
- package/build/connection/health.js +391 -0
- package/build/connection/health.js.map +1 -0
- package/build/connection/index.d.ts +4 -0
- package/build/connection/index.js +48 -0
- package/build/connection/index.js.map +1 -0
- package/build/connection/reconnect.d.ts +261 -0
- package/build/connection/reconnect.js +454 -0
- package/build/connection/reconnect.js.map +1 -0
- package/build/connection/retry.d.ts +187 -0
- package/build/connection/retry.js +427 -0
- package/build/connection/retry.js.map +1 -0
- package/build/connection/state.d.ts +222 -0
- package/build/connection/state.js +431 -0
- package/build/connection/state.js.map +1 -0
- package/build/errors.d.ts +177 -0
- package/build/errors.js +546 -0
- package/build/errors.js.map +1 -0
- package/build/hardware/errors.d.ts +36 -0
- package/build/hardware/errors.js +127 -0
- package/build/hardware/errors.js.map +1 -0
- package/build/hardware/index.d.ts +7 -0
- package/build/hardware/index.js +39 -0
- package/build/hardware/index.js.map +1 -0
- package/build/hardware/near-app.d.ts +95 -0
- package/build/hardware/near-app.js +291 -0
- package/build/hardware/near-app.js.map +1 -0
- package/build/hardware/transport.d.ts +94 -0
- package/build/hardware/transport.js +267 -0
- package/build/hardware/transport.js.map +1 -0
- package/build/hardware/types.d.ts +98 -0
- package/build/hardware/types.js +72 -0
- package/build/hardware/types.js.map +1 -0
- package/build/helpers/analytics.d.ts +191 -0
- package/build/helpers/analytics.js +304 -0
- package/build/helpers/analytics.js.map +1 -0
- package/build/helpers/base58.d.ts +6 -0
- package/build/helpers/base58.js +47 -0
- package/build/helpers/base58.js.map +1 -0
- package/build/helpers/events.d.ts +42 -0
- package/build/helpers/events.js +68 -0
- package/build/helpers/events.js.map +1 -0
- package/build/helpers/html.d.ts +8 -0
- package/build/helpers/html.js +30 -0
- package/build/helpers/html.js.map +1 -0
- package/build/helpers/indexdb.d.ts +14 -0
- package/build/helpers/indexdb.js +166 -0
- package/build/helpers/indexdb.js.map +1 -0
- package/build/helpers/manifest.d.ts +147 -0
- package/build/helpers/manifest.js +329 -0
- package/build/helpers/manifest.js.map +1 -0
- package/build/helpers/queue.d.ts +11 -0
- package/build/helpers/queue.js +48 -0
- package/build/helpers/queue.js.map +1 -0
- package/build/helpers/session.d.ts +119 -0
- package/build/helpers/session.js +289 -0
- package/build/helpers/session.js.map +1 -0
- package/build/helpers/simulation.d.ts +128 -0
- package/build/helpers/simulation.js +441 -0
- package/build/helpers/simulation.js.map +1 -0
- package/build/helpers/storage.d.ts +58 -0
- package/build/helpers/storage.js +190 -0
- package/build/helpers/storage.js.map +1 -0
- package/build/helpers/trust.d.ts +157 -0
- package/build/helpers/trust.js +340 -0
- package/build/helpers/trust.js.map +1 -0
- package/build/helpers/url.d.ts +1 -0
- package/build/helpers/url.js +13 -0
- package/build/helpers/url.js.map +1 -0
- package/build/helpers/uuid.d.ts +1 -0
- package/build/helpers/uuid.js +14 -0
- package/build/helpers/uuid.js.map +1 -0
- package/build/index.d.ts +21 -0
- package/build/index.js +167 -0
- package/build/index.js.map +1 -0
- package/build/popups/IframeWalletPopup.d.ts +16 -0
- package/build/popups/IframeWalletPopup.js +38 -0
- package/build/popups/IframeWalletPopup.js.map +1 -0
- package/build/popups/NearWalletsPopup.d.ts +25 -0
- package/build/popups/NearWalletsPopup.js +153 -0
- package/build/popups/NearWalletsPopup.js.map +1 -0
- package/build/popups/Popup.d.ts +22 -0
- package/build/popups/Popup.js +94 -0
- package/build/popups/Popup.js.map +1 -0
- package/build/popups/styles.d.ts +1 -0
- package/build/popups/styles.js +257 -0
- package/build/popups/styles.js.map +1 -0
- package/build/security/audit-log.d.ts +123 -0
- package/build/security/audit-log.js +268 -0
- package/build/security/audit-log.js.map +1 -0
- package/build/security/csp.d.ts +68 -0
- package/build/security/csp.js +328 -0
- package/build/security/csp.js.map +1 -0
- package/build/security/index.d.ts +10 -0
- package/build/security/index.js +42 -0
- package/build/security/index.js.map +1 -0
- package/build/security/origin-guard.d.ts +90 -0
- package/build/security/origin-guard.js +244 -0
- package/build/security/origin-guard.js.map +1 -0
- package/build/security/rate-limiter.d.ts +84 -0
- package/build/security/rate-limiter.js +212 -0
- package/build/security/rate-limiter.js.map +1 -0
- package/build/security/secure-storage.d.ts +77 -0
- package/build/security/secure-storage.js +242 -0
- package/build/security/secure-storage.js.map +1 -0
- package/build/security/transaction-guard.d.ts +71 -0
- package/build/security/transaction-guard.js +239 -0
- package/build/security/transaction-guard.js.map +1 -0
- package/build/types.d.ts +508 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/build/ui/AccountSwitcherModal.d.ts +53 -0
- package/build/ui/AccountSwitcherModal.js +239 -0
- package/build/ui/AccountSwitcherModal.js.map +1 -0
- package/build/ui/Modal.d.ts +84 -0
- package/build/ui/Modal.js +278 -0
- package/build/ui/Modal.js.map +1 -0
- package/build/ui/TransactionModal.d.ts +84 -0
- package/build/ui/TransactionModal.js +406 -0
- package/build/ui/TransactionModal.js.map +1 -0
- package/build/ui/WalletSelectorModal.d.ts +97 -0
- package/build/ui/WalletSelectorModal.js +481 -0
- package/build/ui/WalletSelectorModal.js.map +1 -0
- package/build/ui/icons.d.ts +19 -0
- package/build/ui/icons.js +65 -0
- package/build/ui/icons.js.map +1 -0
- package/build/ui/index.d.ts +10 -0
- package/build/ui/index.js +31 -0
- package/build/ui/index.js.map +1 -0
- package/build/ui/styles.d.ts +5 -0
- package/build/ui/styles.js +973 -0
- package/build/ui/styles.js.map +1 -0
- package/build/ui/theme.d.ts +133 -0
- package/build/ui/theme.js +204 -0
- package/build/ui/theme.js.map +1 -0
- package/build/wallets/external/index.d.ts +4 -0
- package/build/wallets/external/index.js +9 -0
- package/build/wallets/external/index.js.map +1 -0
- package/build/wallets/external/manager.d.ts +152 -0
- package/build/wallets/external/manager.js +586 -0
- package/build/wallets/external/manager.js.map +1 -0
- package/build/wallets/privileged/index.d.ts +5 -0
- package/build/wallets/privileged/index.js +12 -0
- package/build/wallets/privileged/index.js.map +1 -0
- package/build/wallets/privileged/ledger.d.ts +132 -0
- package/build/wallets/privileged/ledger.js +563 -0
- package/build/wallets/privileged/ledger.js.map +1 -0
- package/build/wallets/privileged/manager.d.ts +54 -0
- package/build/wallets/privileged/manager.js +174 -0
- package/build/wallets/privileged/manager.js.map +1 -0
- package/package.json +33 -0
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import type { FinalExecutionOutcome } from "@near-js/types";
|
|
2
|
+
import type { Action } from "@near-js/transactions";
|
|
3
|
+
import type { ConnectorAction } from "./actions/types";
|
|
4
|
+
export type { FinalExecutionOutcome, Action };
|
|
5
|
+
/**
|
|
6
|
+
* Make specific keys optional in a type
|
|
7
|
+
*/
|
|
8
|
+
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
9
|
+
/**
|
|
10
|
+
* Make specific keys required in a type
|
|
11
|
+
*/
|
|
12
|
+
export type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
13
|
+
/**
|
|
14
|
+
* Deep partial - makes all nested properties optional
|
|
15
|
+
*/
|
|
16
|
+
export type DeepPartial<T> = {
|
|
17
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Extract the resolved type from a Promise
|
|
21
|
+
*/
|
|
22
|
+
export type Awaited<T> = T extends Promise<infer U> ? U : T;
|
|
23
|
+
/**
|
|
24
|
+
* NEAR network identifier
|
|
25
|
+
*/
|
|
26
|
+
export type Network = "mainnet" | "testnet";
|
|
27
|
+
/**
|
|
28
|
+
* Logger interface for debugging
|
|
29
|
+
*/
|
|
30
|
+
export interface Logger {
|
|
31
|
+
log: (...args: unknown[]) => void;
|
|
32
|
+
warn?: (...args: unknown[]) => void;
|
|
33
|
+
error?: (...args: unknown[]) => void;
|
|
34
|
+
debug?: (...args: unknown[]) => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* NEAR account with optional public key
|
|
38
|
+
*/
|
|
39
|
+
export interface Account {
|
|
40
|
+
/** The account ID (e.g., "alice.near") */
|
|
41
|
+
accountId: string;
|
|
42
|
+
/** The public key associated with this account (base58 encoded) */
|
|
43
|
+
publicKey?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Extended account info with additional metadata
|
|
47
|
+
*/
|
|
48
|
+
export interface AccountInfo extends Account {
|
|
49
|
+
/** Account balance in yoctoNEAR */
|
|
50
|
+
balance?: string;
|
|
51
|
+
/** Whether this is a named account */
|
|
52
|
+
isNamed?: boolean;
|
|
53
|
+
/** Contract deployed on this account */
|
|
54
|
+
contractId?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Parameters for signing a message (NEP-413)
|
|
58
|
+
* @see https://github.com/near/NEPs/blob/master/neps/nep-0413.md
|
|
59
|
+
*/
|
|
60
|
+
export interface SignMessageParams {
|
|
61
|
+
/** The message to sign (will be prefixed per NEP-413) */
|
|
62
|
+
message: string;
|
|
63
|
+
/** The intended recipient of the signed message */
|
|
64
|
+
recipient: string;
|
|
65
|
+
/** A unique nonce to prevent replay attacks (32 bytes) */
|
|
66
|
+
nonce: Uint8Array;
|
|
67
|
+
/** Network to use for signing */
|
|
68
|
+
network?: Network;
|
|
69
|
+
/** Account to sign with (if wallet supports multiple accounts) */
|
|
70
|
+
signerId?: string;
|
|
71
|
+
/** Optional callback URL for redirect-based wallets */
|
|
72
|
+
callbackUrl?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Result of signing a message
|
|
76
|
+
*/
|
|
77
|
+
export interface SignedMessage {
|
|
78
|
+
/** The account that signed the message */
|
|
79
|
+
accountId: string;
|
|
80
|
+
/** The public key used for signing (base58 encoded) */
|
|
81
|
+
publicKey: string;
|
|
82
|
+
/** The signature (base64 encoded) */
|
|
83
|
+
signature: string;
|
|
84
|
+
/** The original message that was signed */
|
|
85
|
+
message?: string;
|
|
86
|
+
/** The nonce used */
|
|
87
|
+
nonce?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Transaction to be signed and sent
|
|
91
|
+
*/
|
|
92
|
+
export interface Transaction {
|
|
93
|
+
/** The account receiving the transaction */
|
|
94
|
+
receiverId: string;
|
|
95
|
+
/** Actions to execute */
|
|
96
|
+
actions: Array<Action | ConnectorAction>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parameters for signing and sending a single transaction
|
|
100
|
+
*/
|
|
101
|
+
export interface SignAndSendTransactionParams {
|
|
102
|
+
/** Network to send transaction on */
|
|
103
|
+
network?: Network;
|
|
104
|
+
/** Account to sign with (if wallet supports multiple accounts) */
|
|
105
|
+
signerId?: string;
|
|
106
|
+
/** The account receiving the transaction */
|
|
107
|
+
receiverId: string;
|
|
108
|
+
/** Actions to execute */
|
|
109
|
+
actions: Array<Action | ConnectorAction>;
|
|
110
|
+
/** Optional callback URL for redirect-based wallets */
|
|
111
|
+
callbackUrl?: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Parameters for signing and sending multiple transactions
|
|
115
|
+
*/
|
|
116
|
+
export interface SignAndSendTransactionsParams {
|
|
117
|
+
/** Network to send transactions on */
|
|
118
|
+
network?: Network;
|
|
119
|
+
/** Account to sign with (if wallet supports multiple accounts) */
|
|
120
|
+
signerId?: string;
|
|
121
|
+
/** Transactions to sign and send */
|
|
122
|
+
transactions: Array<Transaction>;
|
|
123
|
+
/** Optional callback URL for redirect-based wallets */
|
|
124
|
+
callbackUrl?: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Parameters for signing in to a wallet
|
|
128
|
+
*/
|
|
129
|
+
export interface SignInParams {
|
|
130
|
+
/** Network to sign in on */
|
|
131
|
+
network?: Network;
|
|
132
|
+
/** Contract to request access key for (optional) */
|
|
133
|
+
contractId?: string;
|
|
134
|
+
/** Methods to allow access key to call (requires contractId) */
|
|
135
|
+
methodNames?: string[];
|
|
136
|
+
/** Optional callback URL for redirect-based wallets */
|
|
137
|
+
callbackUrl?: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Parameters for signing out
|
|
141
|
+
*/
|
|
142
|
+
export interface SignOutParams {
|
|
143
|
+
/** Network to sign out from */
|
|
144
|
+
network?: Network;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Parameters for getting accounts
|
|
148
|
+
*/
|
|
149
|
+
export interface GetAccountsParams {
|
|
150
|
+
/** Network to get accounts for */
|
|
151
|
+
network?: Network;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Wallet permissions for sandboxed execution
|
|
155
|
+
*/
|
|
156
|
+
export interface WalletPermissions {
|
|
157
|
+
/** Allow access to localStorage-like storage */
|
|
158
|
+
storage?: boolean;
|
|
159
|
+
/** External window.near objects the wallet can access */
|
|
160
|
+
external?: string[];
|
|
161
|
+
/** Allow WalletConnect integration */
|
|
162
|
+
walletConnect?: boolean;
|
|
163
|
+
/** URLs the wallet is allowed to open */
|
|
164
|
+
allowsOpen?: string[];
|
|
165
|
+
/** Allow reading from clipboard */
|
|
166
|
+
clipboardRead?: boolean;
|
|
167
|
+
/** Allow writing to clipboard */
|
|
168
|
+
clipboardWrite?: boolean;
|
|
169
|
+
/** Allow WebUSB access (for hardware wallets) */
|
|
170
|
+
usb?: boolean;
|
|
171
|
+
/** Allow WebHID access (for hardware wallets) */
|
|
172
|
+
hid?: boolean;
|
|
173
|
+
/** Allow access to current page location */
|
|
174
|
+
location?: boolean;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Wallet feature flags
|
|
178
|
+
*/
|
|
179
|
+
export interface WalletFeatures {
|
|
180
|
+
/** Supports NEP-413 message signing */
|
|
181
|
+
signMessage: boolean;
|
|
182
|
+
/** Supports signing transactions without sending */
|
|
183
|
+
signTransaction: boolean;
|
|
184
|
+
/** Supports signing and sending a single transaction */
|
|
185
|
+
signAndSendTransaction: boolean;
|
|
186
|
+
/** Supports signing and sending multiple transactions */
|
|
187
|
+
signAndSendTransactions: boolean;
|
|
188
|
+
/** Can sign in without adding an access key */
|
|
189
|
+
signInWithoutAddKey: boolean;
|
|
190
|
+
/** Supports mainnet */
|
|
191
|
+
mainnet: boolean;
|
|
192
|
+
/** Supports testnet */
|
|
193
|
+
testnet: boolean;
|
|
194
|
+
/** Supports verifyOwner (deprecated) */
|
|
195
|
+
verifyOwner?: boolean;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Platform availability for a wallet
|
|
199
|
+
*/
|
|
200
|
+
export interface WalletPlatform {
|
|
201
|
+
/** Web app URL */
|
|
202
|
+
web?: string;
|
|
203
|
+
/** Chrome extension URL */
|
|
204
|
+
chrome?: string;
|
|
205
|
+
/** Firefox extension URL */
|
|
206
|
+
firefox?: string;
|
|
207
|
+
/** Edge extension URL */
|
|
208
|
+
edge?: string;
|
|
209
|
+
/** iOS app URL */
|
|
210
|
+
ios?: string;
|
|
211
|
+
/** Android app URL */
|
|
212
|
+
android?: string;
|
|
213
|
+
/** Telegram app URL */
|
|
214
|
+
tga?: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Wallet manifest describing a wallet's capabilities
|
|
218
|
+
*/
|
|
219
|
+
export interface WalletManifest {
|
|
220
|
+
/** Unique wallet identifier */
|
|
221
|
+
id: string;
|
|
222
|
+
/** Human-readable wallet name */
|
|
223
|
+
name: string;
|
|
224
|
+
/** Wallet icon URL */
|
|
225
|
+
icon: string;
|
|
226
|
+
/** Short description of the wallet */
|
|
227
|
+
description: string;
|
|
228
|
+
/** Wallet website */
|
|
229
|
+
website: string;
|
|
230
|
+
/** Manifest version */
|
|
231
|
+
version: string;
|
|
232
|
+
/** URL to the wallet executor script */
|
|
233
|
+
executor: string;
|
|
234
|
+
/** Wallet type */
|
|
235
|
+
type: "sandbox" | "injected" | "privileged";
|
|
236
|
+
/** Required permissions */
|
|
237
|
+
permissions: WalletPermissions;
|
|
238
|
+
/** Supported features */
|
|
239
|
+
features: WalletFeatures;
|
|
240
|
+
/** Platform availability */
|
|
241
|
+
platform?: WalletPlatform;
|
|
242
|
+
/** Whether this is a debug wallet */
|
|
243
|
+
debug?: boolean;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Wallet manifest from repository
|
|
247
|
+
*/
|
|
248
|
+
export interface WalletManifestRepository {
|
|
249
|
+
/** Manifest schema version */
|
|
250
|
+
version: string;
|
|
251
|
+
/** Available wallets */
|
|
252
|
+
wallets: WalletManifest[];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Base interface that all wallet implementations must satisfy
|
|
256
|
+
*/
|
|
257
|
+
export interface NearWalletBase {
|
|
258
|
+
/** The wallet's manifest */
|
|
259
|
+
manifest: WalletManifest;
|
|
260
|
+
/**
|
|
261
|
+
* Sign in to the wallet
|
|
262
|
+
* @param data - Optional sign in parameters
|
|
263
|
+
* @returns Array of connected accounts
|
|
264
|
+
*/
|
|
265
|
+
signIn(data?: SignInParams): Promise<Account[]>;
|
|
266
|
+
/**
|
|
267
|
+
* Sign out from the wallet
|
|
268
|
+
* @param data - Optional sign out parameters
|
|
269
|
+
*/
|
|
270
|
+
signOut(data?: SignOutParams): Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Get connected accounts
|
|
273
|
+
* @param data - Optional parameters
|
|
274
|
+
* @returns Array of connected accounts
|
|
275
|
+
*/
|
|
276
|
+
getAccounts(data?: GetAccountsParams): Promise<Account[]>;
|
|
277
|
+
/**
|
|
278
|
+
* Sign and send a single transaction
|
|
279
|
+
* @param params - Transaction parameters
|
|
280
|
+
* @returns Transaction execution outcome
|
|
281
|
+
*/
|
|
282
|
+
signAndSendTransaction(params: SignAndSendTransactionParams): Promise<FinalExecutionOutcome>;
|
|
283
|
+
/**
|
|
284
|
+
* Sign and send multiple transactions
|
|
285
|
+
* @param params - Transactions parameters
|
|
286
|
+
* @returns Array of transaction execution outcomes
|
|
287
|
+
*/
|
|
288
|
+
signAndSendTransactions(params: SignAndSendTransactionsParams): Promise<FinalExecutionOutcome[]>;
|
|
289
|
+
/**
|
|
290
|
+
* Sign a message (NEP-413)
|
|
291
|
+
* @param params - Message signing parameters
|
|
292
|
+
* @returns Signed message
|
|
293
|
+
*/
|
|
294
|
+
signMessage(params: SignMessageParams): Promise<SignedMessage>;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Persisted session data
|
|
298
|
+
*/
|
|
299
|
+
export interface Session {
|
|
300
|
+
/** ID of the connected wallet */
|
|
301
|
+
walletId: string;
|
|
302
|
+
/** Connected accounts */
|
|
303
|
+
accounts: Account[];
|
|
304
|
+
/** Network the session is on */
|
|
305
|
+
network: Network;
|
|
306
|
+
/** Timestamp when session was created */
|
|
307
|
+
connectedAt: number;
|
|
308
|
+
/** Timestamp of last activity */
|
|
309
|
+
lastActiveAt: number;
|
|
310
|
+
/** Optional metadata */
|
|
311
|
+
metadata?: Record<string, unknown>;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Event emitted when wallet injection occurs
|
|
315
|
+
*/
|
|
316
|
+
export type EventNearWalletInjected = CustomEvent<NearWalletBase>;
|
|
317
|
+
/**
|
|
318
|
+
* Wallet event payloads for internal wallet communication
|
|
319
|
+
*/
|
|
320
|
+
export interface WalletEvents {
|
|
321
|
+
signedIn: {
|
|
322
|
+
contractId: string;
|
|
323
|
+
methodNames: string[];
|
|
324
|
+
accounts: Account[];
|
|
325
|
+
};
|
|
326
|
+
accountsChanged: {
|
|
327
|
+
accounts: Account[];
|
|
328
|
+
};
|
|
329
|
+
networkChanged: {
|
|
330
|
+
networkId: string;
|
|
331
|
+
};
|
|
332
|
+
signedOut: null;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Map of event names to their payload types
|
|
336
|
+
*/
|
|
337
|
+
export interface EventMap {
|
|
338
|
+
/** Emitted when wallet sign in completes */
|
|
339
|
+
"wallet:signIn": {
|
|
340
|
+
wallet: NearWalletBase;
|
|
341
|
+
accounts: Account[];
|
|
342
|
+
success: boolean;
|
|
343
|
+
};
|
|
344
|
+
/** Emitted when wallet sign out completes */
|
|
345
|
+
"wallet:signOut": {
|
|
346
|
+
success: boolean;
|
|
347
|
+
};
|
|
348
|
+
/** Emitted when a wallet error occurs */
|
|
349
|
+
"wallet:error": {
|
|
350
|
+
error: Error;
|
|
351
|
+
walletId?: string;
|
|
352
|
+
action?: string;
|
|
353
|
+
};
|
|
354
|
+
/** Emitted when wallet accounts change */
|
|
355
|
+
"wallet:accountsChanged": {
|
|
356
|
+
wallet: NearWalletBase;
|
|
357
|
+
accounts: Account[];
|
|
358
|
+
};
|
|
359
|
+
/** Emitted when manifest is updated */
|
|
360
|
+
"selector:manifestUpdated": {
|
|
361
|
+
version: string;
|
|
362
|
+
walletCount: number;
|
|
363
|
+
};
|
|
364
|
+
/** Emitted when available wallets change */
|
|
365
|
+
"selector:walletsChanged": {
|
|
366
|
+
wallets?: NearWalletBase[];
|
|
367
|
+
};
|
|
368
|
+
/** Emitted when a session is restored */
|
|
369
|
+
"session:restored": {
|
|
370
|
+
session: Session;
|
|
371
|
+
};
|
|
372
|
+
/** Emitted when a session expires */
|
|
373
|
+
"session:expired": {
|
|
374
|
+
session: Session;
|
|
375
|
+
};
|
|
376
|
+
/** Emitted when active account is switched */
|
|
377
|
+
"account:switched": {
|
|
378
|
+
account: Account;
|
|
379
|
+
previousAccountId: string | null;
|
|
380
|
+
};
|
|
381
|
+
/** Emitted when new account(s) are added */
|
|
382
|
+
"account:added": {
|
|
383
|
+
accounts: Account[];
|
|
384
|
+
};
|
|
385
|
+
/** Emitted when an account is removed */
|
|
386
|
+
"account:removed": {
|
|
387
|
+
account: Account;
|
|
388
|
+
};
|
|
389
|
+
/** Emitted when all accounts are cleared */
|
|
390
|
+
"account:cleared": Record<string, never>;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Event type names
|
|
394
|
+
*/
|
|
395
|
+
export type EventType = keyof EventMap;
|
|
396
|
+
/**
|
|
397
|
+
* Callback type for a specific event
|
|
398
|
+
*/
|
|
399
|
+
export type EventCallback<K extends EventType> = (payload: EventMap[K]) => void;
|
|
400
|
+
/**
|
|
401
|
+
* Abstract WalletConnect client interface
|
|
402
|
+
*/
|
|
403
|
+
export interface AbstractWalletConnect {
|
|
404
|
+
connect: (params: {
|
|
405
|
+
requiredNamespaces?: Record<string, {
|
|
406
|
+
chains: string[];
|
|
407
|
+
methods: string[];
|
|
408
|
+
events: string[];
|
|
409
|
+
}>;
|
|
410
|
+
optionalNamespaces?: Record<string, {
|
|
411
|
+
chains: string[];
|
|
412
|
+
methods: string[];
|
|
413
|
+
events: string[];
|
|
414
|
+
}>;
|
|
415
|
+
}) => Promise<{
|
|
416
|
+
uri?: string;
|
|
417
|
+
approval: () => Promise<unknown>;
|
|
418
|
+
}>;
|
|
419
|
+
disconnect: (params: {
|
|
420
|
+
topic: string;
|
|
421
|
+
}) => Promise<void>;
|
|
422
|
+
request: <T = unknown>(params: {
|
|
423
|
+
topic: string;
|
|
424
|
+
chainId: string;
|
|
425
|
+
request: {
|
|
426
|
+
method: string;
|
|
427
|
+
params: unknown[];
|
|
428
|
+
};
|
|
429
|
+
}) => Promise<T>;
|
|
430
|
+
session: {
|
|
431
|
+
keys: string[];
|
|
432
|
+
get: (key: string) => {
|
|
433
|
+
topic: string;
|
|
434
|
+
namespaces: Record<string, unknown>;
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
core: {
|
|
438
|
+
projectId?: string;
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* WalletConnect metadata
|
|
443
|
+
*/
|
|
444
|
+
export interface WalletConnectMetadata {
|
|
445
|
+
name: string;
|
|
446
|
+
description: string;
|
|
447
|
+
url: string;
|
|
448
|
+
icons: string[];
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Options for session persistence
|
|
452
|
+
*/
|
|
453
|
+
export interface PersistenceOptions {
|
|
454
|
+
/** Enable session persistence (default: true) */
|
|
455
|
+
enabled?: boolean;
|
|
456
|
+
/** Custom storage implementation */
|
|
457
|
+
storage?: DataStorage;
|
|
458
|
+
/** Storage key for session data */
|
|
459
|
+
storageKey?: string;
|
|
460
|
+
/** Session max age in milliseconds (default: 7 days) */
|
|
461
|
+
maxAge?: number;
|
|
462
|
+
/** Auto-reconnect on page load (default: true) */
|
|
463
|
+
autoReconnect?: boolean;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Data storage interface for persistence
|
|
467
|
+
*/
|
|
468
|
+
export interface DataStorage {
|
|
469
|
+
get(key: string): Promise<string | null>;
|
|
470
|
+
set(key: string, value: string): Promise<void>;
|
|
471
|
+
remove(key: string): Promise<void>;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Options for NearConnector
|
|
475
|
+
*/
|
|
476
|
+
export interface NearConnectorOptions {
|
|
477
|
+
/** RPC providers by network */
|
|
478
|
+
providers?: {
|
|
479
|
+
mainnet?: string[];
|
|
480
|
+
testnet?: string[];
|
|
481
|
+
};
|
|
482
|
+
/** Filter wallets by features */
|
|
483
|
+
features?: Partial<WalletFeatures>;
|
|
484
|
+
/** Wallet IDs to exclude */
|
|
485
|
+
excludedWallets?: string[];
|
|
486
|
+
/** Auto-connect to injected wallets (default: true) */
|
|
487
|
+
autoConnect?: boolean;
|
|
488
|
+
/** Initial network (default: "mainnet") */
|
|
489
|
+
network?: Network;
|
|
490
|
+
/** Custom manifest URL or object */
|
|
491
|
+
manifest?: string | WalletManifestRepository;
|
|
492
|
+
/** WalletConnect client */
|
|
493
|
+
walletConnect?: Promise<AbstractWalletConnect> | AbstractWalletConnect;
|
|
494
|
+
/** Custom storage implementation */
|
|
495
|
+
storage?: DataStorage;
|
|
496
|
+
/** Logger for debugging */
|
|
497
|
+
logger?: Logger;
|
|
498
|
+
/** Session persistence options */
|
|
499
|
+
persistence?: PersistenceOptions;
|
|
500
|
+
/**
|
|
501
|
+
* @deprecated Use persistence options instead
|
|
502
|
+
* Sign in data for initial connection
|
|
503
|
+
*/
|
|
504
|
+
signIn?: {
|
|
505
|
+
contractId?: string;
|
|
506
|
+
methodNames?: string[];
|
|
507
|
+
};
|
|
508
|
+
}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Modal, ModalOptions } from "./Modal";
|
|
2
|
+
import { Account } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Account with additional UI metadata
|
|
5
|
+
*/
|
|
6
|
+
export interface AccountUIInfo extends Account {
|
|
7
|
+
balance?: string;
|
|
8
|
+
isActive?: boolean;
|
|
9
|
+
walletId?: string;
|
|
10
|
+
walletIcon?: string;
|
|
11
|
+
walletName?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Account switcher modal options
|
|
15
|
+
*/
|
|
16
|
+
export interface AccountSwitcherOptions extends ModalOptions {
|
|
17
|
+
accounts: AccountUIInfo[];
|
|
18
|
+
activeAccountId?: string;
|
|
19
|
+
onSelect: (accountId: string) => void;
|
|
20
|
+
onDisconnect?: (accountId: string) => void;
|
|
21
|
+
onAddAccount?: () => void;
|
|
22
|
+
showBalances?: boolean;
|
|
23
|
+
showDisconnect?: boolean;
|
|
24
|
+
showAddAccount?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Modal state
|
|
28
|
+
*/
|
|
29
|
+
interface ModalState {
|
|
30
|
+
accounts: AccountUIInfo[];
|
|
31
|
+
confirmDisconnect: string | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Account switcher modal for multi-account support
|
|
35
|
+
*/
|
|
36
|
+
export declare class AccountSwitcherModal extends Modal {
|
|
37
|
+
protected readonly switcherOptions: Required<AccountSwitcherOptions>;
|
|
38
|
+
protected state: ModalState;
|
|
39
|
+
constructor(options: AccountSwitcherOptions);
|
|
40
|
+
protected render(): string;
|
|
41
|
+
private renderHeader;
|
|
42
|
+
private renderBody;
|
|
43
|
+
private renderAccount;
|
|
44
|
+
private truncateAccountId;
|
|
45
|
+
private generateAvatar;
|
|
46
|
+
private renderFooter;
|
|
47
|
+
protected setupHandlers(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Update accounts list
|
|
50
|
+
*/
|
|
51
|
+
updateAccounts(accounts: AccountUIInfo[]): void;
|
|
52
|
+
}
|
|
53
|
+
export {};
|