@human.tech/waap-sdk 2.0.0 → 2.1.0-staging-fb27bb
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/CHANGELOG.md +23 -0
- package/README.md +167 -216
- package/dist/WaaPError-C5nPcaKk.d.mts +168 -0
- package/dist/WaaPError-XLgIXUgh.d.ts +168 -0
- package/dist/WalletConnect-BTT6LtUu.d.mts +33 -0
- package/dist/WalletConnect-BTT6LtUu.d.ts +33 -0
- package/dist/WalletConnect-Deg7_JmH.mjs +4 -0
- package/dist/WalletConnect-G-lbqknM.js +4 -0
- package/dist/asyncSigning-B0KrmKk7.js +1 -0
- package/dist/asyncSigning-CzqBbYDP.mjs +1 -0
- package/dist/esm-B4jz8Emb.mjs +1 -0
- package/dist/esm-D5fDQenf.js +1 -0
- package/dist/evm-Ch-aWWat.js +1 -0
- package/dist/evm-DHVrAmEw.mjs +1 -0
- package/dist/evm.d.mts +7 -0
- package/dist/evm.d.ts +7 -0
- package/dist/evm.js +1 -0
- package/dist/evm.mjs +1 -0
- package/dist/index-CMSufeMa.d.ts +775 -0
- package/dist/index-CdKntlzX.d.mts +775 -0
- package/dist/index.d.mts +239 -933
- package/dist/index.d.ts +239 -933
- package/dist/index.js +1 -2191
- package/dist/index.mjs +1 -2162
- package/dist/initializerContext-0oKHzvQG.d.ts +21 -0
- package/dist/initializerContext-C39PUnGi.d.mts +21 -0
- package/dist/react.d.mts +2 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +1 -0
- package/dist/react.mjs +1 -0
- package/dist/register-4Afr2Jx8.js +1 -0
- package/dist/register-CBlzg5ln.d.ts +107 -0
- package/dist/register-CNgjA0yl.mjs +1 -0
- package/dist/register-CxsUwgKJ.d.ts +282 -0
- package/dist/register-DIZnKDHF.mjs +1 -0
- package/dist/register-LmdJdvzn.d.mts +282 -0
- package/dist/register-QjrsOe7r.d.mts +107 -0
- package/dist/register-ozKwGWOb.js +1 -0
- package/dist/solana.d.mts +5 -0
- package/dist/solana.d.ts +5 -0
- package/dist/solana.js +1 -0
- package/dist/solana.mjs +1 -0
- package/dist/sui.d.mts +5 -0
- package/dist/sui.d.ts +5 -0
- package/dist/sui.js +1 -0
- package/dist/sui.mjs +1 -0
- package/dist/types-DexmJNke.d.mts +397 -0
- package/dist/types-DexmJNke.d.ts +397 -0
- package/dist/ui-16QpbEyG.js +1 -0
- package/dist/ui-BAYRtDQg.mjs +1 -0
- package/dist/useWaapAuth-BrqAhAn2.d.ts +246 -0
- package/dist/useWaapAuth-C5I7QqyW.d.mts +246 -0
- package/dist/useWaapAuth-DHIeb4yc.mjs +1 -0
- package/dist/useWaapAuth-Z_ONicYr.js +1 -0
- package/dist/walletconnect.d.mts +2 -0
- package/dist/walletconnect.d.ts +2 -0
- package/dist/walletconnect.js +1 -0
- package/dist/walletconnect.mjs +1 -0
- package/package.json +53 -18
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
//#region ../silk-interface-core/dist/esm/messages/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Method names for request and response messages
|
|
4
|
+
*/
|
|
5
|
+
declare enum SILK_METHOD {
|
|
6
|
+
eth_requestAccounts = "eth_requestAccounts" // https://eips.ethereum.org/EIPS/eip-1102
|
|
7
|
+
,
|
|
8
|
+
eth_accounts = "eth_accounts",
|
|
9
|
+
eth_sendTransaction = "eth_sendTransaction",
|
|
10
|
+
eth_signTransaction = "eth_signTransaction",
|
|
11
|
+
eth_getBalance = "eth_getBalance",
|
|
12
|
+
personal_sign = "personal_sign",
|
|
13
|
+
eth_signTypedData_v4 = "eth_signTypedData_v4",
|
|
14
|
+
eth_chainId = "eth_chainId",
|
|
15
|
+
net_version = "net_version",
|
|
16
|
+
wallet_switchEthereumChain = "wallet_switchEthereumChain",
|
|
17
|
+
wallet_addEthereumChain = "wallet_addEthereumChain",
|
|
18
|
+
eth_estimateGas = "eth_estimateGas",
|
|
19
|
+
eth_blockNumber = "eth_blockNumber",
|
|
20
|
+
eth_getCode = "eth_getCode",
|
|
21
|
+
eth_call = "eth_call",
|
|
22
|
+
eth_getTransactionReceipt = "eth_getTransactionReceipt",
|
|
23
|
+
eth_getTransactionByHash = "eth_getTransactionByHash",
|
|
24
|
+
eth_accountsChanged = "eth_accountsChanged",
|
|
25
|
+
sui_connect = "sui_connect",
|
|
26
|
+
sui_disconnect = "sui_disconnect",
|
|
27
|
+
sui_getAccounts = "sui_getAccounts",
|
|
28
|
+
sui_signPersonalMessage = "sui_signPersonalMessage",
|
|
29
|
+
sui_signTransaction = "sui_signTransaction",
|
|
30
|
+
sui_signAndExecuteTransaction = "sui_signAndExecuteTransaction",
|
|
31
|
+
sui_switchChain = "sui_switchChain",
|
|
32
|
+
show_modal = "show_modal",
|
|
33
|
+
hide_modal = "hide_modal",
|
|
34
|
+
login = "login",
|
|
35
|
+
auto_conn = "auto_conn",
|
|
36
|
+
logout = "logout",
|
|
37
|
+
set_points_referral_code = "set_points_referral_code",
|
|
38
|
+
set_project = "set_project",
|
|
39
|
+
silk_requestEmail = "silk_requestEmail",
|
|
40
|
+
silk_requestSbt = "silk_requestSbt",
|
|
41
|
+
set_custom_config = "set_custom_config",
|
|
42
|
+
safe = "safe",
|
|
43
|
+
set_is_mobile = "set_is_mobile",
|
|
44
|
+
project_init = "project_init",
|
|
45
|
+
gastank_get_settings = "gastank_get_settings",
|
|
46
|
+
gastank_update_settings = "gastank_update_settings",
|
|
47
|
+
gastank_topup = "gastank_topup",
|
|
48
|
+
customization_get = "customization_get",
|
|
49
|
+
customization_update = "customization_update",
|
|
50
|
+
orcid = "orcid",
|
|
51
|
+
waap_requestPermissionToken = "waap_requestPermissionToken",
|
|
52
|
+
waap_getAccountStatus = "waap_getAccountStatus",
|
|
53
|
+
waap_getPermissionTokenStatus = "waap_getPermissionTokenStatus",
|
|
54
|
+
waap_clearPermissionToken = "waap_clearPermissionToken",
|
|
55
|
+
solana_connect = "solana_connect",
|
|
56
|
+
solana_disconnect = "solana_disconnect",
|
|
57
|
+
solana_signMessage = "solana_signMessage",
|
|
58
|
+
solana_signTransaction = "solana_signTransaction",
|
|
59
|
+
solana_signAllTransactions = "solana_signAllTransactions",
|
|
60
|
+
solana_signAndSendTransaction = "solana_signAndSendTransaction",
|
|
61
|
+
set_signing_mode = "set_signing_mode",
|
|
62
|
+
enter_lite_mode = "enter_lite_mode"
|
|
63
|
+
}
|
|
64
|
+
/** Portable-session protection selected by a current WaaP SDK integration. */
|
|
65
|
+
type WaaPSessionProtection = 'bearer' | 'dpop';
|
|
66
|
+
declare enum JSON_RPC_METHOD {
|
|
67
|
+
eth_requestAccounts = "eth_requestAccounts",
|
|
68
|
+
eth_accounts = "eth_accounts",
|
|
69
|
+
eth_sendTransaction = "eth_sendTransaction",
|
|
70
|
+
eth_signTransaction = "eth_signTransaction",
|
|
71
|
+
eth_getBalance = "eth_getBalance",
|
|
72
|
+
personal_sign = "personal_sign",
|
|
73
|
+
eth_signTypedData_v4 = "eth_signTypedData_v4",
|
|
74
|
+
eth_chainId = "eth_chainId",
|
|
75
|
+
net_version = "net_version",
|
|
76
|
+
wallet_switchEthereumChain = "wallet_switchEthereumChain",
|
|
77
|
+
wallet_addEthereumChain = "wallet_addEthereumChain",
|
|
78
|
+
eth_estimateGas = "eth_estimateGas",
|
|
79
|
+
eth_blockNumber = "eth_blockNumber",
|
|
80
|
+
eth_getCode = "eth_getCode",
|
|
81
|
+
eth_call = "eth_call",
|
|
82
|
+
eth_getTransactionReceipt = "eth_getTransactionReceipt",
|
|
83
|
+
eth_getTransactionByHash = "eth_getTransactionByHash"
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Notification names
|
|
87
|
+
*/
|
|
88
|
+
declare enum SILK_NOTIFICATION {
|
|
89
|
+
ready = "ready",
|
|
90
|
+
connect = "connect",
|
|
91
|
+
account_changed = "account_changed",
|
|
92
|
+
mobile_oauth_success = "mobile_oauth_success",
|
|
93
|
+
mobile_oauth_error = "mobile_oauth_error",
|
|
94
|
+
tx_pending = "waap_txPending",
|
|
95
|
+
tx_2fa_required = "waap_tx2faRequired",
|
|
96
|
+
tx_signed = "waap_txSigned",
|
|
97
|
+
tx_confirmed = "waap_txConfirmed",
|
|
98
|
+
tx_failed = "waap_txFailed",
|
|
99
|
+
squid_pending = "waap_squid_pending",
|
|
100
|
+
squid_ready = "waap_squid_ready",
|
|
101
|
+
squid_failed = "waap_squid_failed",
|
|
102
|
+
request_cancel = "waap_requestCancel"
|
|
103
|
+
}
|
|
104
|
+
type SilkNotificationData = keyof typeof SILK_NOTIFICATION;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region ../silk-interface-core/dist/esm/index.d.ts
|
|
107
|
+
type SilkMessage = {
|
|
108
|
+
target: 'silk';
|
|
109
|
+
};
|
|
110
|
+
type SilkRequest = SilkMessage & {
|
|
111
|
+
id: string;
|
|
112
|
+
messageType: 'request';
|
|
113
|
+
method: keyof typeof SILK_METHOD;
|
|
114
|
+
params: any[];
|
|
115
|
+
interactionRequired?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Transaction behavior options.
|
|
118
|
+
* `async` enables async transaction mode for eth_sendTransaction.
|
|
119
|
+
*/
|
|
120
|
+
silkOptions?: {
|
|
121
|
+
async?: boolean;
|
|
122
|
+
/** @deprecated Use `async` instead. Kept for v1 SDK backward compatibility. */
|
|
123
|
+
asyncSigning?: boolean;
|
|
124
|
+
is2FARequest?: boolean;
|
|
125
|
+
withPT?: boolean;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
type AuthenticationMethod = 'email' | 'phone' | 'social' | 'biometrics' | 'wallet';
|
|
129
|
+
type SocialProvider = 'discord' | 'github' | 'google' | 'twitter' | 'bluesky' | 'telegram';
|
|
130
|
+
interface ProjectConfig {
|
|
131
|
+
name?: string;
|
|
132
|
+
entryTitle?: string;
|
|
133
|
+
logo?: string;
|
|
134
|
+
projectId?: string;
|
|
135
|
+
termsOfServiceUrl?: string;
|
|
136
|
+
privacyPolicyUrl?: string;
|
|
137
|
+
authSuccessUrl?: string;
|
|
138
|
+
authErrorUrl?: string;
|
|
139
|
+
emailLogoCid?: string;
|
|
140
|
+
appId?: string;
|
|
141
|
+
nativeRedirect?: string;
|
|
142
|
+
universalRedirect?: string;
|
|
143
|
+
}
|
|
144
|
+
interface StylesConfig {
|
|
145
|
+
darkMode?: boolean;
|
|
146
|
+
}
|
|
147
|
+
interface CustomConfig {
|
|
148
|
+
authenticationMethods?: AuthenticationMethod[];
|
|
149
|
+
allowedSocials?: SocialProvider[];
|
|
150
|
+
styles?: StylesConfig;
|
|
151
|
+
showSecured?: boolean;
|
|
152
|
+
}
|
|
153
|
+
type BaseSilkResponse = SilkMessage & {
|
|
154
|
+
id: string;
|
|
155
|
+
messageType: 'response';
|
|
156
|
+
method: string;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Versioned terminal-operation metadata. This is additive: SDK consumers keep
|
|
160
|
+
* reading `data` / `error`, while observability-aware consumers can correlate
|
|
161
|
+
* a terminal wallet result to the original iframe request without parsing
|
|
162
|
+
* method-specific payloads.
|
|
163
|
+
*/
|
|
164
|
+
interface SilkOperationResult {
|
|
165
|
+
version: 1;
|
|
166
|
+
requestId: string;
|
|
167
|
+
status: 'succeeded' | 'failed' | 'cancelled';
|
|
168
|
+
phase: 'complete';
|
|
169
|
+
error?: {
|
|
170
|
+
code: string;
|
|
171
|
+
message: string;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** Additive cancellation notification sent from the SDK host to the iframe. */
|
|
175
|
+
interface SilkRequestCancellation {
|
|
176
|
+
type: typeof SILK_NOTIFICATION.request_cancel;
|
|
177
|
+
requestId: string;
|
|
178
|
+
method: string;
|
|
179
|
+
}
|
|
180
|
+
type SilkResponse = BaseSilkResponse & {
|
|
181
|
+
data?: any;
|
|
182
|
+
error?: any;
|
|
183
|
+
operation?: SilkOperationResult;
|
|
184
|
+
} & ({
|
|
185
|
+
data: any;
|
|
186
|
+
error?: never;
|
|
187
|
+
} | {
|
|
188
|
+
data?: never;
|
|
189
|
+
error: any;
|
|
190
|
+
});
|
|
191
|
+
type CredentialType = 'kyc' | 'phone';
|
|
192
|
+
/**
|
|
193
|
+
* Parameters for waap_requestPermissionToken RPC method.
|
|
194
|
+
* Apps use this to request a Permission Token from the user.
|
|
195
|
+
*/
|
|
196
|
+
interface RequestPermissionTokenParams {
|
|
197
|
+
/** Canonical `evm:<id>`, `sui:<network>`, or `solana:<network>` chain. */
|
|
198
|
+
chain: `evm:${number}` | `sui:${string}` | `solana:${string}`;
|
|
199
|
+
/** Optional only on request; the wallet signs an explicit `tap` default. */
|
|
200
|
+
walletMode?: 'tap' | 'squid';
|
|
201
|
+
/** Contract addresses that the PT should allow transactions to */
|
|
202
|
+
allowedAddresses: string[];
|
|
203
|
+
/** Optional USD spend limit; omit or use null for address-only scope. */
|
|
204
|
+
requestedAmountUsd?: number | string | null;
|
|
205
|
+
/** Requested expiry duration in seconds (max 7200 = 2 hours) */
|
|
206
|
+
requestedExpirySeconds: number;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Result of waap_requestPermissionToken RPC method.
|
|
210
|
+
*/
|
|
211
|
+
interface RequestPermissionTokenResult {
|
|
212
|
+
/** Whether the user approved and signed the PT */
|
|
213
|
+
success: boolean;
|
|
214
|
+
/** Error message if the request failed */
|
|
215
|
+
error?: string;
|
|
216
|
+
}
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/lib/walletTarget.d.ts
|
|
219
|
+
/** Named wallet deployments understood by the browser SDK. */
|
|
220
|
+
type WaaPEnvironment = 'development' | 'staging' | 'production';
|
|
221
|
+
/**
|
|
222
|
+
* Select the wallet iframe deployment explicitly. `walletOrigin` is intended
|
|
223
|
+
* for a local wallet build or a partner-owned preview environment; it must be
|
|
224
|
+
* an origin, not a URL path.
|
|
225
|
+
*/
|
|
226
|
+
interface WaaPWalletTargetOptions {
|
|
227
|
+
environment?: WaaPEnvironment;
|
|
228
|
+
walletOrigin?: string;
|
|
229
|
+
/** @deprecated Use `environment: 'staging'` instead. */
|
|
230
|
+
useStaging?: boolean;
|
|
231
|
+
}
|
|
232
|
+
/** Validate and normalize an iframe target origin before it becomes security state. */
|
|
233
|
+
declare function validateWalletOrigin(value: string): string;
|
|
234
|
+
/**
|
|
235
|
+
* Resolve the one origin used for iframe creation, all postMessage calls, and
|
|
236
|
+
* incoming message checks. Explicit origins win over named environments, which
|
|
237
|
+
* win over the legacy staging flag and the existing compiled SDK default.
|
|
238
|
+
*/
|
|
239
|
+
declare function resolveWalletOrigin(options?: WaaPWalletTargetOptions): string;
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/lib/provider/types.d.ts
|
|
242
|
+
interface RequestArguments {
|
|
243
|
+
method: string;
|
|
244
|
+
params?: unknown[] | object;
|
|
245
|
+
async?: boolean;
|
|
246
|
+
withPT?: boolean;
|
|
247
|
+
/** Abort this wallet request and remove it from the iframe queue. */
|
|
248
|
+
signal?: AbortSignal;
|
|
249
|
+
/** SDK-side timeout for this request; not forwarded to the iframe. */
|
|
250
|
+
timeoutMs?: number;
|
|
251
|
+
}
|
|
252
|
+
interface EthereumProviderInterface {
|
|
253
|
+
enable(): Promise<unknown>;
|
|
254
|
+
isConnected(): boolean;
|
|
255
|
+
request(args: RequestArguments): Promise<unknown>;
|
|
256
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
257
|
+
removeListener(event: string, listener: (...args: any[]) => void): this;
|
|
258
|
+
}
|
|
259
|
+
type LoginResponse = 'waap' | 'human' | 'injected' | 'walletconnect' | null;
|
|
260
|
+
/** The explicit signing family selected by an initializer. */
|
|
261
|
+
type WaaPAccountMode = 'tap' | 'squid';
|
|
262
|
+
type WaaPConversionState = 'not_required' | 'required' | 'pending' | 'complete' | 'failed' |
|
|
263
|
+
/**
|
|
264
|
+
* The wallet holds a signing key that does not derive its own address, so it
|
|
265
|
+
* cannot sign for it. Distinct from `failed`: retrying achieves nothing, the
|
|
266
|
+
* user's original key is intact, and resolving it needs operator action.
|
|
267
|
+
*/
|
|
268
|
+
'mismatched';
|
|
269
|
+
/**
|
|
270
|
+
* Public-safe local session information. It never includes authentication
|
|
271
|
+
* material, key shares, policy tokens, policies, or profile data.
|
|
272
|
+
*/
|
|
273
|
+
interface WaaPAccountStatus {
|
|
274
|
+
authenticated: boolean;
|
|
275
|
+
loginMethod: LoginResponse;
|
|
276
|
+
/** Preferred name for `mode`; retained alongside it for readability. */
|
|
277
|
+
activeMode: WaaPAccountMode | null;
|
|
278
|
+
mode: WaaPAccountMode;
|
|
279
|
+
conversion: WaaPConversionState;
|
|
280
|
+
tap: null | {
|
|
281
|
+
t1: {
|
|
282
|
+
evm: string;
|
|
283
|
+
sui: string;
|
|
284
|
+
};
|
|
285
|
+
t2: {
|
|
286
|
+
solana: string;
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
squid: null | {
|
|
290
|
+
sqd1: {
|
|
291
|
+
evm: string;
|
|
292
|
+
};
|
|
293
|
+
sqd2: {
|
|
294
|
+
sui: string;
|
|
295
|
+
solana: string;
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
/** Convenience view of connected public facade accounts. */
|
|
299
|
+
accounts: {
|
|
300
|
+
evm?: string;
|
|
301
|
+
sui?: string;
|
|
302
|
+
solana?: string;
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Options form of `login()`. Passed instead of a custom provider, which is
|
|
307
|
+
* distinguished at runtime by its EIP-1193 `request` method.
|
|
308
|
+
*/
|
|
309
|
+
interface WaaPLoginOptions {
|
|
310
|
+
/**
|
|
311
|
+
* Open the login UI even when the wallet could restore an existing session.
|
|
312
|
+
* Use it for an explicit "switch account" affordance; the default resolves
|
|
313
|
+
* a valid session without presenting UI.
|
|
314
|
+
*/
|
|
315
|
+
force?: boolean;
|
|
316
|
+
customProvider?: EthereumProviderInterface;
|
|
317
|
+
}
|
|
318
|
+
/** Common WaaP lifecycle extension beside chain-standard interfaces. */
|
|
319
|
+
interface WaaPSessionExtension {
|
|
320
|
+
login(customProvider?: unknown): Promise<LoginResponse>;
|
|
321
|
+
logout(): Promise<void>;
|
|
322
|
+
getLoginMethod(): LoginResponse;
|
|
323
|
+
/** Redacted canonical TAP/Squid snapshot from the wallet iframe. */
|
|
324
|
+
getAccountStatus(): Promise<WaaPAccountStatus>;
|
|
325
|
+
}
|
|
326
|
+
/** The dapp-visible scope of a wallet-owned Permission Token. */
|
|
327
|
+
interface PermissionTokenQuery {
|
|
328
|
+
chainId: number | string;
|
|
329
|
+
sender: string;
|
|
330
|
+
}
|
|
331
|
+
/** Redacted Permission Token metadata; never includes the signed token. */
|
|
332
|
+
interface PermissionTokenStatus {
|
|
333
|
+
present: boolean;
|
|
334
|
+
applicable: boolean;
|
|
335
|
+
chainId?: number | string;
|
|
336
|
+
sender?: string;
|
|
337
|
+
allowedAddresses?: string[];
|
|
338
|
+
amountUsd?: string;
|
|
339
|
+
expiresAt?: string;
|
|
340
|
+
reason?: 'missing' | 'expired' | 'chain_mismatch' | 'sender_mismatch';
|
|
341
|
+
}
|
|
342
|
+
interface PermissionTokenClearResult {
|
|
343
|
+
cleared: boolean;
|
|
344
|
+
}
|
|
345
|
+
interface SilkEthereumProviderInterface extends EthereumProviderInterface {
|
|
346
|
+
isSilk: boolean;
|
|
347
|
+
connected: boolean;
|
|
348
|
+
login(customProviderOrOptions?: any): Promise<LoginResponse>;
|
|
349
|
+
logout(): Promise<unknown>;
|
|
350
|
+
getLoginMethod(): LoginResponse;
|
|
351
|
+
getAccountStatus(): WaaPAccountStatus;
|
|
352
|
+
session: WaaPSessionExtension;
|
|
353
|
+
requestEmail(): Promise<unknown>;
|
|
354
|
+
requestSBT(type: CredentialType): Promise<unknown>;
|
|
355
|
+
requestPermissionToken(params: RequestPermissionTokenParams): Promise<unknown>;
|
|
356
|
+
getPermissionTokenStatus(query: PermissionTokenQuery): Promise<PermissionTokenStatus>;
|
|
357
|
+
clearPermissionToken(query: PermissionTokenQuery): Promise<PermissionTokenClearResult>;
|
|
358
|
+
toggleDarkMode(): Promise<void>;
|
|
359
|
+
/** Mount (if deferred) and complete the wallet handshake ahead of use. */
|
|
360
|
+
preload(): Promise<void>;
|
|
361
|
+
/** Release SDK message listeners and the shared wallet iframe. */
|
|
362
|
+
destroy(): void;
|
|
363
|
+
}
|
|
364
|
+
interface InitSilkOptions extends WaaPWalletTargetOptions {
|
|
365
|
+
referralCode?: string;
|
|
366
|
+
project?: ProjectConfig;
|
|
367
|
+
config?: CustomConfig;
|
|
368
|
+
walletConnectProjectId?: string;
|
|
369
|
+
/**
|
|
370
|
+
* Wallet session transport. Defaults to fail-closed DPoP. Select `bearer`
|
|
371
|
+
* only for an integration that cannot use the iframe's WebCrypto/IndexedDB
|
|
372
|
+
* DPoP key.
|
|
373
|
+
*/
|
|
374
|
+
sessionProtection?: WaaPSessionProtection;
|
|
375
|
+
/**
|
|
376
|
+
* When true, the wallet iframe is mounted only by `preload()` or the first
|
|
377
|
+
* wallet operation. The default warms it after the browser becomes idle;
|
|
378
|
+
* pass `false` to mount eagerly during initialization.
|
|
379
|
+
*/
|
|
380
|
+
deferIframe?: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* When true, eth_sendTransaction resolves with `{ pendingTxId, status:
|
|
383
|
+
* 'pending' }` immediately after signing. Broadcasting and confirmation
|
|
384
|
+
* continue in the background with waap lifecycle events; the canonical
|
|
385
|
+
* transaction hash is available after node acceptance.
|
|
386
|
+
* Other signing methods (personal_sign, eth_signTypedData_v4, eth_signTransaction)
|
|
387
|
+
* are unaffected — they always resolve with the signature directly.
|
|
388
|
+
* Applies to ALL eth_sendTransaction calls for this SDK instance.
|
|
389
|
+
* Default: false
|
|
390
|
+
*/
|
|
391
|
+
asyncTxs?: boolean;
|
|
392
|
+
/** @deprecated Use `asyncTxs` instead. */
|
|
393
|
+
asyncSigning?: boolean;
|
|
394
|
+
}
|
|
395
|
+
type SilkProvider = SilkEthereumProviderInterface;
|
|
396
|
+
//#endregion
|
|
397
|
+
export { SILK_METHOD as A, RequestPermissionTokenResult as C, SocialProvider as D, SilkResponse as E, WaaPSessionProtection as M, StylesConfig as O, RequestPermissionTokenParams as S, SilkRequestCancellation as T, validateWalletOrigin as _, PermissionTokenQuery as a, CustomConfig as b, SilkEthereumProviderInterface as c, WaaPAccountStatus as d, WaaPLoginOptions as f, resolveWalletOrigin as g, WaaPWalletTargetOptions as h, PermissionTokenClearResult as i, SilkNotificationData as j, JSON_RPC_METHOD as k, SilkProvider as l, WaaPEnvironment as m, InitSilkOptions as n, PermissionTokenStatus as o, WaaPSessionExtension as p, LoginResponse as r, RequestArguments as s, EthereumProviderInterface as t, WaaPAccountMode as u, AuthenticationMethod as v, SilkRequest as w, ProjectConfig as x, CredentialType as y };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./esm-D5fDQenf.js"),t=require("./asyncSigning-B0KrmKk7.js"),n=require("./evm-Ch-aWWat.js");let r=require("events");const i={"sui:mainnet":`https://sui-rpc.publicnode.com`,"sui:testnet":`https://sui-testnet-rpc.publicnode.com`,"sui:devnet":`https://fullnode.devnet.sui.io`,"sui:localnet":`http://127.0.0.1:9000`},a=e=>i[e],o=e=>e.slice(4);var s=class{constructor(t,i={},a,o=i){this.lastKnownConversion=`pending`,this.name=`WaaP`,this.version=`1.0.0`,this.icon=`data:image/webp;base64,UklGRpoDAABXRUJQVlA4WAoAAAAQAAAAYwAAYwAAQUxQSDMDAAABJyAQSOFmFxERA8TatqpGoimANbEAxlBAPhSgQP9FyXv3vkcFEf134EZS5DREhGvTM8z0ki8stMRvK4cm8bk5rIu3xNbvkgPk4K6ti5IHquRQnLi6KrdBb81hdyF1jTLM1CW425943iba38/djOcG+dg85p/KXGd/g7+xAzJ2VPWTS8R+q65uA1ZcwG3iZ4urjw9Lh4xn83n3gZmQQ3VMVGEO6D403jdr81Ml1OISAAf7RGImBHISwQ5zCJonTuEyOyP7Sga4cDcjMPgXuiK9cUpaGrIDJtH4iAB25utB8O0DDztOKTr8u9hpX0jrx6k8UM5eAlqsynNxlX9tPRLQEtySKwcDOIDnMqEcek1UnylVNac4r0mlypNvhmCNODlhUXuT4fxTQyrDKY0uyV+gi0iiLLpY76A08C/IX8GQoYb8PcVxK7HkZkT5IjAF4gZicOfJW1ovJjyAlYVPlM6BkkHGI0fniAIZIXC0CbAM92BB8SBznU0ITYLr9XkfnKlDgV8170HGMWwitY51+zxcgkftLD4RLh4HSTIa3QzRWKxlaHZTz21s6GLxnBmjogkVilW4kuaMMMGUfgkZ1JhrBSEANrEDMwucAXgbTqIExY3FYRMdtkQRDFjD6BKtJ2GWTopGRY4P9DBkdE4rp9LJHuYhju45oeVZVv3zNmVdZiIOffHDppOz0Q34p0e/+nXy7JmF1846lmF2ZombLt8pgZpbPNeqpJSVJ0bGd4cH8dUNflNPfdQVXUkC95UQS0ZGfDmOJgjs3IyVOExZBEsxONd080gYK/ftQ2nbYaqGW89Hu7M6avmzXEjhO4G8O8ae8gwWtwZsyp8v8j/ys5H7bM+unOfurO4bbbL4v865Nb8s98Ld2X9yg6tLBQanMP8fhplOMMN8fiNDzTvNOMXGuYzejo12vY7s3clhXwgDPuBIcxi9QZftbKVxAjLCcVQdRxGR1QknhCs3GuieMLzfrrC9RhfJgVpcXRn71nZfEjsiYy/Ca1J7ch0clK64ReH3G/s2cekpP+BIx2YteMvSoLy6G9FCgd1nvF/VoVRtJoNJNLQ0RM3BXY9WgPbcHF78swAAVlA4IEAAAACwBQCdASpkAGQAPpFIoUylpCMiIKgAsBIJaW7hc+AAY2upvcReWAa6m9xF5YBrqb3EXlgGngAA/v81aVcAAAAA`,this._accounts=[],this.accountMode=`tap`,this.loginMethod=null,this._chains=[`sui:mainnet`,`sui:testnet`,`sui:devnet`],this.internalEventEmitter=new r.EventEmitter,this.changeListeners=new Set,this.initializerPromise=null,this.initializedIframeWindow=null,this.walletMessageManager=new n.h(t,n.x(i)),this.ensureIframe=a,this.iframeMounted=!a,this.initializerOptions=o,this.uiMessageManager=new n.a,this.walletMessageManager.addListener({handleResponse:e=>{this.internalEventEmitter.emit(e.id,e)},handleRequest:t=>{t.method===e.r.show_modal?this.uiMessageManager.emit(`show_modal`):t.method===e.r.hide_modal&&this.uiMessageManager.emit(`hide_modal`)},onAccountChanged:async e=>{try{let e=await this.refreshAccounts();this.notifyChange({accounts:e.accounts})}catch(e){console.error(`Failed to refresh Sui accounts:`,e),this._accounts=[],this.notifyChange({accounts:[]})}}})}destroy(){this.walletMessageManager.dispose(),this.internalEventEmitter.removeAllListeners(),this.uiMessageManager.removeAllListeners(),this.changeListeners.clear(),this._accounts=[]}ensureIframeMounted(){if(this.iframeMounted||!this.ensureIframe)return;let e=this.ensureIframe();if(!e)throw Error(`Failed to create WaaP iframe`);this.iframeMounted=!0,this.walletMessageManager.setIframeWindow(e)}async preload(){if(!this.ensureIframe)return;this.ensureIframeMounted();let e=this.walletMessageManager.getIframeWindow();if(!e)throw Error(`WaaP iframe is not mounted`);if(this.initializedIframeWindow===e&&this.initializerPromise)return this.initializerPromise;this.initializedIframeWindow=e,this.initializerPromise=n._(e,()=>this.selectAccountMode(this.accountMode,this.initializerOptions));try{await this.initializerPromise}catch(e){throw this.initializerPromise=null,this.initializedIframeWindow=null,e}}async ensureInitialized(){await this.preload()}async refreshAccounts(){try{await this.ensureInitialized();let e=await this.postRequestAndWait({method:`sui_connect`,params:[{silent:!0}],interactionRequired:!1});if(e.error)return this._accounts=[],{accounts:[]};let t=e.data?.accounts||[];return this._accounts=t,{accounts:this._accounts}}catch{return this._accounts=[],{accounts:[]}}}get chains(){return this._chains}get accounts(){return this._accounts}get ui(){return this.uiMessageManager}getAccountStatus(){return{authenticated:this.loginMethod!==null,loginMethod:this.loginMethod,activeMode:this.loginMethod?this.accountMode:null,mode:this.accountMode,conversion:this.loginMethod?this.lastKnownConversion:`not_required`,tap:null,squid:null,accounts:this._accounts[0]?{sui:this._accounts[0].address}:{}}}get session(){return{login:()=>this.login(),logout:()=>this.logout(),getLoginMethod:()=>this.getLoginMethod(),getAccountStatus:()=>this.getCanonicalAccountStatus()}}async getCanonicalAccountStatus(){await this.ensureInitialized();let t=await this.postRequestAndWait({method:e.r.waap_getAccountStatus,params:[],interactionRequired:!1});if(t.error)throw Error(t.error.message||`Failed to read WaaP status`);let n=t.data;return this.syncLoginMethodFromCanonicalStatus(n),n?.conversion&&(this.lastKnownConversion=n.conversion),n}setAccountMode(e){this.accountMode=e,this.initializerPromise=null,this.initializedIframeWindow=null}async selectAccountMode(t,r={}){await this.walletMessageManager.pingIframe(),await this.postRequestAndWait({method:e.r.set_signing_mode,params:[n.g(t,r)],interactionRequired:!1})}setLoginMethod(e){this.loginMethod=e,e===null&&(this._accounts=[],this.notifyChange({accounts:[]}))}getLoginMethod(){return this.loginMethod}async login(){await this.ensureInitialized();let t=await this.restoreSession();if(t)return t;let n=(await this.postRequestAndWait({method:e.r.login,params:[],interactionRequired:!0})).data;return n!==`waap`&&n!==`human`&&n!==`injected`&&n!==`walletconnect`?(this.loginMethod=null,null):(this.loginMethod=n,n)}async logout(){this.lastKnownConversion=`pending`,await this.ensureInitialized(),await this.postRequestAndWait({method:e.r.logout,params:[],interactionRequired:!1}),this.loginMethod=null,this._accounts=[],this.notifyChange({accounts:[]})}async connect(e){if(!this.loginMethod){if(e?.silent)throw new n.w(`not_authenticated`,`Not authenticated: a silent connect cannot open login.`,{operation:{chain:`sui`,method:`sui_connect`}});if(!await this.login())throw new n.w(`user_rejected`,`User rejected WaaP login during connect().`,{operation:{chain:`sui`,method:`sui_connect`}})}await this.ensureInitialized();let t=await this.postRequestAndWait({method:`sui_connect`,params:[e||{}],interactionRequired:!e?.silent,signal:e?.signal,timeoutMs:e?.timeoutMs});if(t.error)throw Error(t.error.message||`Failed to connect`);let r=t.data?.accounts||[];return this._accounts=r,this.notifyChange({accounts:this._accounts}),e?.silent||this.internalEventEmitter.emit(`connect`),this.internalEventEmitter.emit(`accountsChanged`,this._accounts.map(e=>e.address)),{accounts:this._accounts}}async restoreSession(){try{let e=await this.getCanonicalAccountStatus();if(e.authenticated&&(e.loginMethod===`waap`||e.loginMethod===`human`||e.loginMethod===`injected`||e.loginMethod===`walletconnect`))return this.loginMethod=e.loginMethod,e.loginMethod}catch{}return null}syncLoginMethodFromCanonicalStatus(e){let t=e.authenticated&&(e.loginMethod===`waap`||e.loginMethod===`human`||e.loginMethod===`injected`||e.loginMethod===`walletconnect`)?e.loginMethod:null;t!==this.loginMethod&&this.setLoginMethod(t)}async disconnect(){await this.ensureInitialized(),await this.postRequestAndWait({method:`sui_disconnect`,params:[],interactionRequired:!1}),this._accounts=[],this.notifyChange({accounts:[]})}async signPersonalMessage(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=await this.postRequestAndWait({method:`sui_signPersonalMessage`,params:[{message:Array.from(e.message),account:t,chain:e.chain}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(n.error)throw Error(n.error.message||`Failed to sign message`);return{bytes:n.data.bytes,signature:n.data.signature}}async extractTransferAddresses(e,t=!1){try{let{Transaction:n}=await import(`@mysten/sui/transactions`),r=(t?n.fromKind(e):n.from(e)).getData(),i=[];for(let e of r.commands){if(e.$kind!==`TransferObjects`)continue;let t=e.TransferObjects.address;if(t.$kind!==`Input`)continue;let n=t.Input,a=r.inputs[n];if(!a||a.$kind!==`Pure`)continue;let o=Uint8Array.from(atob(a.Pure.bytes),e=>e.charCodeAt(0));if(o.length!==32)continue;let s=`0x`+Array.from(o).map(e=>e.toString(16).padStart(2,`0`)).join(``);i.push(s)}return i}catch{return[]}}async resolveTransactionBytes(e,t=`sui:mainnet`){if(e instanceof Uint8Array)return{bytes:e,kind:`transaction-data`};if(Array.isArray(e))return{bytes:new Uint8Array(e),kind:`transaction-data`};if(typeof e==`string`)try{return{bytes:Uint8Array.from(atob(e),e=>e.charCodeAt(0)),kind:`transaction-data`}}catch{throw Error(`Transaction string must be base64 encoded bytes. If you have a serialized transaction JSON, please build it to bytes first.`)}else if(e&&typeof e==`object`){if(typeof e.build==`function`)try{let{SuiJsonRpcClient:n}=await import(`@mysten/sui/jsonRpc`),r=o(t),i=new n({url:a(t),network:r});return{bytes:await e.build({client:i,onlyTransactionKind:!0}),kind:`transaction-kind`}}catch(e){throw console.warn(`[SuiWallet] Failed to build transaction object:`,e),Error(`Failed to build transaction: ${e instanceof Error?e.message:String(e)}`)}if(typeof e.serialize==`function`)try{let t=await e.serialize();if(typeof t==`string`)return{bytes:Uint8Array.from(atob(t),e=>e.charCodeAt(0)),kind:`transaction-data`};if(t instanceof Uint8Array)return{bytes:t,kind:`transaction-data`}}catch(e){console.warn(`[SuiWallet] serialize() failed:`,e)}if(typeof e.toJSON==`function`)try{let t=await e.toJSON();if(typeof t==`string`)try{return{bytes:Uint8Array.from(atob(t),e=>e.charCodeAt(0)),kind:`transaction-data`}}catch{try{let e=JSON.parse(t);if(e.bytes&&typeof e.bytes==`string`)return{bytes:Uint8Array.from(atob(e.bytes),e=>e.charCodeAt(0)),kind:`transaction-data`}}catch{}}}catch(e){console.warn(`[SuiWallet] toJSON() failed:`,e)}if(typeof e.getData==`function`)try{let t=e.getData();if(t instanceof Uint8Array)return{bytes:t,kind:`transaction-data`}}catch(e){console.warn(`[SuiWallet] getData() failed:`,e)}throw Error(`Unsupported transaction format. Keys: ${Object.keys(e).join(`, `)}`)}else throw Error(`Unsupported transaction format: ${typeof e}. Please pass Uint8Array bytes or a Transaction object.`)}async signTransaction(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=await this.resolveTransactionBytes(e.transaction,e.chain),r=await this.postRequestAndWait({method:`sui_signTransaction`,params:[{...n.kind===`transaction-kind`?{transactionKind:Array.from(n.bytes)}:{transaction:Array.from(n.bytes)},account:t,chain:e.chain}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(r.error)throw Error(r.error.message||`Failed to sign transaction`);return{bytes:r.data.bytes,signature:r.data.signature}}async signAndExecuteTransaction(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=await this.resolveTransactionBytes(e.transaction,e.chain),r=await this.extractTransferAddresses(n.bytes,n.kind===`transaction-kind`),i=await this.postRequestAndWait({method:`sui_signAndExecuteTransaction`,params:[{...n.kind===`transaction-kind`?{transactionKind:Array.from(n.bytes)}:{transaction:Array.from(n.bytes)},account:t,chain:e.chain,options:e.options,requestType:e.requestType,toAddresses:r.length>0?r:void 0}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(i.error)throw Error(i.error.message||`Failed to sign and execute transaction`);return i.data}async switchChain(e){if(await this.ensureInitialized(),!this._chains.includes(e.chain))throw Error(`Chain ${e.chain} is not supported`);let t=await this.postRequestAndWait({method:`sui_switchChain`,params:[e],interactionRequired:!1});if(t.error)throw Error(t.error.message||`Failed to switch chain`);this.notifyChange({chains:this._chains,accounts:this._accounts})}on(e,t){return e===`change`?(this.changeListeners.add(t),()=>{this.changeListeners.delete(t)}):(this.internalEventEmitter.on(e,t),()=>{this.internalEventEmitter.removeListener(e,t)})}removeListener(e,t){if(e===`change`){this.changeListeners.delete(t);return}this.internalEventEmitter.removeListener(e,t)}get features(){return{"standard:connect":{version:`1.0.0`,connect:this.connect.bind(this)},"standard:disconnect":{version:`1.0.0`,disconnect:this.disconnect.bind(this)},"standard:events":{version:`1.0.0`,on:this.on.bind(this)},"sui:signPersonalMessage":{version:`1.1.0`,signPersonalMessage:this.signPersonalMessage.bind(this)},"sui:signTransaction":{version:`2.0.0`,signTransaction:this.signTransaction.bind(this)},"sui:signAndExecuteTransaction":{version:`1.0.0`,signAndExecuteTransaction:this.signAndExecuteTransaction.bind(this)},"sui:signTransactionBlock":{version:`2.0.0`,signTransactionBlock:this.signTransactionBlock.bind(this)},"sui:signAndExecuteTransactionBlock":{version:`1.0.0`,signAndExecuteTransactionBlock:this.signAndExecuteTransactionBlock.bind(this)},"sui:switchChain":{version:`1.0.0`,switchChain:this.switchChain.bind(this)}}}async signTransactionBlock(e){return this.signTransaction({transaction:e.transactionBlock,account:e.account,chain:e.chain})}async signAndExecuteTransactionBlock(e){return this.signAndExecuteTransaction({transaction:e.transactionBlock,account:e.account,chain:e.chain,options:e.options,requestType:e.requestType})}async requestPermissionToken(t){await this.ensureInitialized();let n=await this.postRequestAndWait({method:e.r.waap_requestPermissionToken,params:[t],interactionRequired:!0});if(n.error)throw Error(n.error.message||`Failed to request permission token`);return n.data}async getPermissionTokenStatus(t){return await this.ensureInitialized(),(await this.postRequestAndWait({method:e.r.waap_getPermissionTokenStatus,params:[t],interactionRequired:!1})).data}async clearPermissionToken(t){return await this.ensureInitialized(),(await this.postRequestAndWait({method:e.r.waap_clearPermissionToken,params:[t],interactionRequired:!1})).data}async requestEmail(){await this.ensureInitialized();let t=await this.postRequestAndWait({method:e.r.silk_requestEmail,params:[],interactionRequired:!0});if(t.error)throw Error(t.error.message||`Failed to request email`);return t.data}async postRequestAndWait(t){let r;try{t.interactionRequired&&n.p({layout:t.method===e.r.login?`auth`:`signing`}),r=await this.walletMessageManager.postSilkRequest({method:t.method,params:t.params,interactionRequired:t.interactionRequired});let i=await n.u({eventEmitter:this.internalEventEmitter,id:r,method:t.method,interactionRequired:t.interactionRequired,signal:t.signal,timeoutMs:t.timeoutMs,onCancel:()=>{this.walletMessageManager.cancelSilkRequest(r,t.method),t.interactionRequired&&n.f()}});if(i.error)throw Error(i.error.message);return i}catch(e){throw t.interactionRequired&&r===void 0&&n.f(),n.T(e,{chain:`sui`,method:String(t.method),requestId:r})}}notifyChange(e){Array.from(this.changeListeners).forEach(t=>{t(e)})}};function c(e,t,r=!0){let i=()=>(n.y(e),n.v(t).contentWindow),a=e.deferIframe===!1,o=e.deferIframe===void 0,c=a?i():null;if(a&&!c)throw Error(`Failed to create WaaP iframe`);let l=new s(c,e,i,{...e,chains:[`sui`]});l.setAccountMode(t),r&&a&&l.preload().catch(()=>void 0);let u=l.destroy.bind(l);if(l.destroy=()=>{u(),n.b()},r&&o){let e=n.s(l),t=l.destroy.bind(l);l.destroy=()=>{e(),t()}}return l.ui.on(`show_modal`,()=>{n.p(),document.querySelectorAll(`[data-dapp-kit][class*="overlay"]`).forEach(e=>{e.style.display=`none`})}),l.ui.on(`hide_modal`,()=>{n.f(),document.querySelectorAll(`[data-dapp-kit][class*="overlay"]`).forEach(e=>{e.style.display=``})}),l}var l=class{constructor(t,i={},a,o=i){this.lastKnownConversion=`pending`,this.name=`WaaP`,this.version=`1.0.0`,this.icon=`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2NCA2NCI+PHJlY3Qgd2lkdGg9IjY0IiBoZWlnaHQ9IjY0IiByeD0iMTYiIGZpbGw9IiMxMTE4MmMiLz48cGF0aCBkPSJNMTYgNDhoMzJMMzIgMTZ6IiBmaWxsPSIjN2NkNGZmIi8+PC9zdmc+`,this._accounts=[],this.accountMode=`tap`,this.loginMethod=null,this._chains=[`solana:mainnet`,`solana:devnet`,`solana:testnet`],this.internalEventEmitter=new r.EventEmitter,this.changeListeners=new Set,this.initializerPromise=null,this.initializedIframeWindow=null,this.walletMessageManager=new n.h(t,n.x(i)),this.ensureIframe=a,this.iframeMounted=!a,this.initializerOptions=o,this.uiMessageManager=new n.a,this.walletMessageManager.addListener({handleResponse:e=>{this.internalEventEmitter.emit(e.id,e)},handleRequest:t=>{t.method===e.r.show_modal?this.uiMessageManager.emit(`show_modal`):t.method===e.r.hide_modal&&this.uiMessageManager.emit(`hide_modal`)},onAccountChanged:async()=>{try{let e=await this.refreshAccounts();this.notifyChange({accounts:e.accounts})}catch(e){console.error(`Failed to refresh Solana accounts:`,e),this._accounts=[],this.notifyChange({accounts:[]})}}})}destroy(){this.walletMessageManager.dispose(),this.internalEventEmitter.removeAllListeners(),this.uiMessageManager.removeAllListeners(),this.changeListeners.clear(),this._accounts=[]}ensureIframeMounted(){if(this.iframeMounted||!this.ensureIframe)return;let e=this.ensureIframe();if(!e)throw Error(`Failed to create WaaP iframe`);this.iframeMounted=!0,this.walletMessageManager.setIframeWindow(e)}async preload(){if(!this.ensureIframe)return;this.ensureIframeMounted();let e=this.walletMessageManager.getIframeWindow();if(!e)throw Error(`WaaP iframe is not mounted`);if(this.initializedIframeWindow===e&&this.initializerPromise)return this.initializerPromise;this.initializedIframeWindow=e,this.initializerPromise=n._(e,()=>this.selectAccountMode(this.accountMode,this.initializerOptions));try{await this.initializerPromise}catch(e){throw this.initializerPromise=null,this.initializedIframeWindow=null,e}}async ensureInitialized(){await this.preload()}get chains(){return this._chains}get accounts(){return this._accounts}get features(){return{"standard:connect":{version:`1.0.0`,connect:this.connect.bind(this)},"standard:disconnect":{version:`1.0.0`,disconnect:this.disconnect.bind(this)},"standard:events":{version:`1.0.0`,on:this.on.bind(this)},"solana:signMessage":{version:`1.1.0`,signMessage:this.signStandardMessages.bind(this)},"solana:signTransaction":{version:`1.0.0`,supportedTransactionVersions:[`legacy`,0],signTransaction:this.signStandardTransactions.bind(this)},"solana:signAndSendTransaction":{version:`1.0.0`,supportedTransactionVersions:[`legacy`,0],signAndSendTransaction:this.signAndSendStandardTransactions.bind(this)}}}get ui(){return this.uiMessageManager}getAccountStatus(){return{authenticated:this.loginMethod!==null,loginMethod:this.loginMethod,activeMode:this.loginMethod?this.accountMode:null,mode:this.accountMode,conversion:this.loginMethod?this.lastKnownConversion:`not_required`,tap:null,squid:null,accounts:this._accounts[0]?{solana:this._accounts[0].address}:{}}}get session(){return{login:()=>this.login(),logout:()=>this.logout(),getLoginMethod:()=>this.getLoginMethod(),getAccountStatus:()=>this.getCanonicalAccountStatus()}}async getCanonicalAccountStatus(){await this.ensureInitialized();let t=await this.postRequestAndWait({method:e.r.waap_getAccountStatus,params:[],interactionRequired:!1});if(t.error)throw Error(t.error.message||`Failed to read WaaP status`);let n=t.data;return this.syncLoginMethodFromCanonicalStatus(n),n?.conversion&&(this.lastKnownConversion=n.conversion),n}setAccountMode(e){this.accountMode=e,this.initializerPromise=null,this.initializedIframeWindow=null}async selectAccountMode(t,r={}){await this.walletMessageManager.pingIframe(),await this.postRequestAndWait({method:e.r.set_signing_mode,params:[n.g(t,r)],interactionRequired:!1})}setLoginMethod(e){this.loginMethod=e,e===null&&(this._accounts=[],this.notifyChange({accounts:[]}))}getLoginMethod(){return this.loginMethod}async login(){await this.ensureInitialized();let t=await this.restoreSession();if(t)return t;let n=(await this.postRequestAndWait({method:e.r.login,params:[],interactionRequired:!0})).data;return n!==`waap`&&n!==`human`&&n!==`injected`&&n!==`walletconnect`?(this.loginMethod=null,null):(this.loginMethod=n,n)}async logout(){this.lastKnownConversion=`pending`,await this.ensureInitialized(),await this.postRequestAndWait({method:e.r.logout,params:[],interactionRequired:!1}),this.loginMethod=null,this._accounts=[],this.notifyChange({accounts:[]})}async refreshAccounts(){try{await this.ensureInitialized();let e=await this.postRequestAndWait({method:`solana_connect`,params:[{silent:!0}],interactionRequired:!1});if(e.error)return this._accounts=[],{accounts:[]};let t=this.normalizeAccounts(e.data?.accounts||[]);return this._accounts=t,{accounts:this._accounts}}catch{return this._accounts=[],{accounts:[]}}}normalizeAccounts(e){return e.map(e=>({address:e.address,publicKey:e.publicKey instanceof Uint8Array?e.publicKey:new Uint8Array(e.publicKey??[]),chains:e.chains??this._chains,features:e.features??[]}))}async connect(e){if(!this.loginMethod)throw new n.w(`not_authenticated`,`Not authenticated: call login() before connect().`,{operation:{chain:`solana`,method:`solana_connect`}});await this.ensureInitialized();let t=await this.postRequestAndWait({method:`solana_connect`,params:[e||{}],interactionRequired:!e?.silent,signal:e?.signal,timeoutMs:e?.timeoutMs});if(t.error)throw Error(t.error.message||`Failed to connect`);let r=this.normalizeAccounts(t.data?.accounts||[]);return this._accounts=r,this.notifyChange({accounts:this._accounts}),e?.silent||this.internalEventEmitter.emit(`connect`),this.internalEventEmitter.emit(`accountsChanged`,this._accounts.map(e=>e.address)),{accounts:this._accounts}}async restoreSession(){try{let e=await this.getCanonicalAccountStatus();if(e.authenticated&&(e.loginMethod===`waap`||e.loginMethod===`human`||e.loginMethod===`injected`||e.loginMethod===`walletconnect`))return this.loginMethod=e.loginMethod,e.loginMethod}catch{}return null}syncLoginMethodFromCanonicalStatus(e){let t=e.authenticated&&(e.loginMethod===`waap`||e.loginMethod===`human`||e.loginMethod===`injected`||e.loginMethod===`walletconnect`)?e.loginMethod:null;t!==this.loginMethod&&this.setLoginMethod(t)}async disconnect(){await this.ensureInitialized(),await this.postRequestAndWait({method:`solana_disconnect`,params:[],interactionRequired:!1}),this._accounts=[],this.notifyChange({accounts:[]})}async signMessage(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=await this.postRequestAndWait({method:`solana_signMessage`,params:[{message:Array.from(e.message),account:t}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(n.error)throw Error(n.error.message||`Failed to sign message`);return{signedMessage:new Uint8Array(n.data.signedMessage),signature:new Uint8Array(n.data.signature)}}async signTransaction(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=this.resolveTransactionBytes(e.transaction),r=await this.postRequestAndWait({method:`solana_signTransaction`,params:[{transaction:Array.from(n),account:t,chain:e.chain,withPT:e.withPT}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(r.error)throw Error(r.error.message||`Failed to sign transaction`);return{signedTransaction:new Uint8Array(r.data.signedTransaction),signature:new Uint8Array(r.data.signature)}}async signAndSendTransaction(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=this.resolveTransactionBytes(e.transaction),r=await this.postRequestAndWait({method:`solana_signAndSendTransaction`,params:[{transaction:Array.from(n),account:t,chain:e.chain,options:e.options,withPT:e.withPT}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(r.error)throw Error(r.error.message||`Failed to sign and send transaction`);return{signature:r.data.signature}}async signStandardMessages(...e){let t=[];for(let n of e){let e=await this.signMessage({account:n.account,message:n.message});t.push({...e,signatureType:`ed25519`})}return t}async signStandardTransactions(...e){let t=[];for(let n of e){let e=await this.signTransaction({account:n.account,transaction:n.transaction,chain:this.asSupportedChain(n.chain)});t.push({signedTransaction:e.signedTransaction})}return t}async signAndSendStandardTransactions(...e){let t=[];for(let n of e){let e=await this.signAndSendTransaction({account:n.account,transaction:n.transaction,chain:this.asSupportedChain(n.chain),options:this.broadcastOptions(n.options)});t.push({signature:u(e.signature)})}return t}asSupportedChain(e){if(e!==void 0){if(this._chains.includes(e))return e;throw new n.w(`unsupported_input`,`Unsupported Solana Wallet Standard chain: ${e}`,{operation:{chain:`solana`,method:`wallet_standard`}})}}broadcastOptions(e){if(e?.preflightCommitment!==void 0||e?.minContextSlot!==void 0||e?.commitment!==void 0)throw new n.w(`unsupported_input`,`WaaP does not support Wallet Standard RPC commitment options; configure the dapp RPC instead.`,{operation:{chain:`solana`,method:`wallet_standard`}});return e?{skipPreflight:e.skipPreflight,maxRetries:e.maxRetries}:void 0}async requestPermissionToken(t){await this.ensureInitialized();let n=await this.postRequestAndWait({method:e.r.waap_requestPermissionToken,params:[t],interactionRequired:!0});if(n.error)throw Error(n.error.message||`Failed to request permission token`);return n.data}async getPermissionTokenStatus(t){return await this.ensureInitialized(),(await this.postRequestAndWait({method:e.r.waap_getPermissionTokenStatus,params:[t],interactionRequired:!1})).data}async clearPermissionToken(t){return await this.ensureInitialized(),(await this.postRequestAndWait({method:e.r.waap_clearPermissionToken,params:[t],interactionRequired:!1})).data}resolveTransactionBytes(e){if(e instanceof Uint8Array)return e;if(Array.isArray(e))return new Uint8Array(e);if(e&&typeof e.serialize==`function`){let t=e.serialize();return t instanceof Uint8Array?t:new Uint8Array(t)}throw Error(`Unsupported transaction format. Pass serialized bytes or a @solana/web3.js Transaction.`)}on(e,t){return e===`change`?(this.changeListeners.add(t),()=>{this.changeListeners.delete(t)}):(this.internalEventEmitter.on(e,t),()=>{this.internalEventEmitter.removeListener(e,t)})}removeListener(e,t){if(e===`change`){this.changeListeners.delete(t);return}this.internalEventEmitter.removeListener(e,t)}async postRequestAndWait(t){let r;try{t.interactionRequired&&n.p({layout:t.method===e.r.login?`auth`:`signing`}),r=await this.walletMessageManager.postSilkRequest({method:t.method,params:t.params,interactionRequired:t.interactionRequired});let i=await n.u({eventEmitter:this.internalEventEmitter,id:r,method:t.method,interactionRequired:t.interactionRequired,signal:t.signal,timeoutMs:t.timeoutMs,onCancel:()=>{this.walletMessageManager.cancelSilkRequest(r,t.method),t.interactionRequired&&n.f()}});if(i.error)throw Error(i.error.message);return i}catch(e){throw t.interactionRequired&&r===void 0&&n.f(),n.T(e,{chain:`solana`,method:String(t.method),requestId:r})}}notifyChange(e){Array.from(this.changeListeners).forEach(t=>{t(e)})}};function u(e){let t=[];for(let n of e){let e=`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`.indexOf(n);if(e<0)throw Error(`Invalid base58 transaction signature`);for(let n=0;n<t.length;n+=1)e+=t[n]*58,t[n]=e&255,e>>=8;for(;e>0;)t.push(e&255),e>>=8}let n=0;for(;n<e.length&&e[n]===`1`;)n+=1;return new Uint8Array([...Array(n).fill(0),...t.reverse()])}function d(e={}){let t=()=>(n.y(e),n.v(`tap`).contentWindow),r=e.deferIframe===!1,i=e.deferIframe===void 0,a=r?t():null;if(r&&!a)throw Error(`Failed to create WaaP iframe`);let o=new l(a,e,t,{...e,chains:[`solana`]});r&&o.preload().catch(()=>void 0);let s=o.destroy.bind(o);if(o.destroy=()=>{s(),n.b()},i){let e=n.s(o),t=o.destroy.bind(o);o.destroy=()=>{e(),t()}}return o.ui.on(`show_modal`,()=>{n.p()}),o.ui.on(`hide_modal`,()=>{n.f()}),o}function f(e={}){if(`chains`in e)throw Error("initWaaP accepts one `chain`; use initWaaPMulti({ chains }) for TAP.");switch(e.chain){case`sui`:return c(e,`tap`);case`solana`:return d(e);default:return n.t(e)}}const p=[`evm`,`sui`,`solana`],m=[`evm`,`sui`,`solana`];function h(r={}){let i=Array.from(new Set(r.chains??p));if(i.length===0)throw Error(`initWaaPSquid requires at least one chain facade`);if(i.some(e=>!p.includes(e)))throw Error(`initWaaPSquid received an unsupported chain facade`);let a=i.includes(`evm`),o=i.includes(`sui`),s=i.includes(`solana`),u=n.n({referralCode:r.referralCode,config:r.config,project:r.project,environment:r.environment,walletOrigin:r.walletOrigin,useStaging:r.useStaging,walletConnectProjectId:r.walletConnectProjectId,asyncTxs:r.asyncTxs,deferIframe:r.deferIframe,sessionProtection:r.sessionProtection},`squid`,!1,i,a),d=o?c(r,`squid`,!1):void 0,f=()=>(n.y(r),n.v(`squid`).contentWindow),m=s?new l(r.deferIframe===!1?f():null,{useStaging:r.useStaging,environment:r.environment,walletOrigin:r.walletOrigin,referralCode:r.referralCode,project:r.project,config:r.config,deferIframe:r.deferIframe,sessionProtection:r.sessionProtection},f,{...r,chains:[`solana`]}):void 0;m?.setAccountMode(`squid`);let h;r.deferIframe===!1?u.preload().catch(()=>void 0):r.deferIframe===void 0&&(h=n.s(u));let g={state:`absent`},_=null,v=0,y=()=>{_=null,g={state:`absent`}},b=e=>!e.lifecycleId||e.lifecycleId===_,x=()=>g.state===`active`;u.on(t.t.squidPending,e=>{if(!b(e))return;let t=e?.transactionDigest;g={state:t?`awaiting-network`:`provisioning`,...t?{operationId:t,transactionDigest:t}:{},...e?.message?{message:e.message}:{}}}),u.on(t.t.squidReady,e=>{b(e)&&(g={state:`active`})}),u.on(t.t.squidFailed,e=>{b(e)&&(g={state:`failed`,...e?.error?{message:e.error}:{}},_=null)});let S=e=>{if(u.getLoginMethod()===null)throw new n.w(`not_authenticated`,`Not authenticated: call login() before connecting or signing.`,{operation:{chain:e,method:`connect`}});if(!x())throw new n.w(`not_connected`,`Squid is not ready: call onboard() after login before connecting or signing.`)},C=u.request.bind(u);if(u.request=async e=>([`eth_requestAccounts`,`eth_accounts`,`eth_sendTransaction`,`eth_signTransaction`,`personal_sign`,`eth_signTypedData_v4`].includes(e.method)&&S(`evm`),C(e)),d){let e=d.connect.bind(d);d.connect=async t=>(S(`sui`),e(t))}if(m){let e=m.connect.bind(m);m.connect=async t=>(S(`solana`),e(t))}let w=async()=>{if(u.getLoginMethod()===null)throw new n.w(`not_authenticated`,`Not authenticated: call login() before onboarding Squid.`);if(x()||_)return;let t=`squid-${++v}`;_=t,g={state:`provisioning`};try{await u.walletMessageManager.pingIframe(),await n.c({method:e.r.enter_lite_mode,params:[window.location.origin,t]},!1,u.walletMessageManager,u.internalEventEmitter)}catch(e){throw _===t&&(_=null,g={state:`failed`,message:e instanceof Error?e.message:String(e)}),e}},T=()=>({...g}),E=e=>{if(g.state===`active`||!e.authenticated||e.activeMode!==`squid`||!e.squid)return;let n={..._?{lifecycleId:_}:{},evm:e.squid.sqd1.evm,sui:e.squid.sqd2.sui,solana:e.squid.sqd2.solana};g={state:`active`},_=null,u.emit(t.t.squidReady,n)},D=async()=>(await w(),T()),O=u.login.bind(u),k=async e=>{let t=await O(e);return d?.setLoginMethod(t),m?.setLoginMethod(t),(t?await u.session.getAccountStatus().catch(()=>null):null)?.squid&&(await u.reassertIframeAccountMode().catch(()=>void 0),await w()),t&&u.emit(`connect`),t},A=u.logout.bind(u),j=async()=>{await A(),d?.setLoginMethod(null),m?.setLoginMethod(null),y()},M;M={login:k,logout:j,getLoginMethod:()=>u.getLoginMethod(),getAccountStatus:async()=>{let e=await u.session.getAccountStatus();return E(e),e},getSquidStatus:T,on:(e,t)=>(u.on(e,t),M),removeListener:(e,t)=>(u.removeListener(e,t),M)},u.login=M.login,u.logout=M.logout,d&&(d.login=()=>M.login(),d.logout=()=>M.logout()),m&&(m.login=()=>M.login(),m.logout=()=>M.logout());let N={onboard:w,squid:{onboard:w,getStatus:T,onboardWithStatus:D},getSquidStatus:T,session:M,getAccountStatus:()=>{let e=u.getAccountStatus(),t=d?.getAccountStatus(),n=m?.getAccountStatus();return{authenticated:e.authenticated||!!t?.authenticated||!!n?.authenticated,loginMethod:e.loginMethod??t?.loginMethod??n?.loginMethod??null,activeMode:e.authenticated||t?.authenticated||n?.authenticated?`squid`:null,mode:`squid`,conversion:e.conversion,tap:e.tap,squid:e.squid,accounts:{...e.accounts,...t?.accounts,...n?.accounts}}},preload:()=>u.preload(),destroy:()=>{h?.(),y(),u.destroy(),d?.destroy(),m?.destroy(),n.b()}};return a&&Object.assign(N,{evm:u,ethereum:u}),d&&Object.assign(N,{sui:d}),m&&Object.assign(N,{solana:m}),p.every(e=>i.includes(e))&&Object.assign(N,{auth:u}),N}function g(e){let t=Array.from(new Set(e.chains));if(t.length===0)throw Error(`initWaaPMulti requires at least one chain facade`);if(t.some(e=>!m.includes(e)))throw Error(`initWaaPMulti received an unsupported chain facade`);let r=t.includes(`evm`),i=t.includes(`sui`),a=t.includes(`solana`),o=n.n({referralCode:e.referralCode,config:e.config,project:e.project,environment:e.environment,walletOrigin:e.walletOrigin,useStaging:e.useStaging,walletConnectProjectId:e.walletConnectProjectId,asyncTxs:e.asyncTxs,deferIframe:e.deferIframe,sessionProtection:e.sessionProtection},`tap`,!1,t,r),s=i?c({...e,config:e.config},`tap`,!1):void 0,u=()=>(n.y(e),n.v(`tap`).contentWindow),d=a?new l(e.deferIframe===!1?u():null,{useStaging:e.useStaging,environment:e.environment,walletOrigin:e.walletOrigin,referralCode:e.referralCode,project:e.project,config:e.config,deferIframe:e.deferIframe,sessionProtection:e.sessionProtection},u,{...e,chains:[`solana`]}):void 0;d?.setAccountMode(`tap`);let f;e.deferIframe===!1?o.preload().catch(()=>void 0):e.deferIframe===void 0&&(f=n.s(o));let p=o.login.bind(o),h=async e=>{let t=await p(e);return s?.setLoginMethod(t),d?.setLoginMethod(t),t&&o.emit(`connect`),t},g=o.logout.bind(o),_=async()=>{await g(),s?.setLoginMethod(null),d?.setLoginMethod(null)},v;v={login:h,logout:_,getLoginMethod:()=>o.getLoginMethod(),getAccountStatus:()=>o.session.getAccountStatus(),on:(e,t)=>(o.on(e,t),v),removeListener:(e,t)=>(o.removeListener(e,t),v)},o.login=v.login,o.logout=v.logout,s&&(s.login=()=>v.login(),s.logout=()=>v.logout()),d&&(d.login=()=>v.login(),d.logout=()=>v.logout());let y=()=>{let e=o.getAccountStatus(),t=s?.getAccountStatus(),n=d?.getAccountStatus();return{authenticated:e.authenticated||!!t?.authenticated||!!n?.authenticated,loginMethod:e.loginMethod??t?.loginMethod??n?.loginMethod??null,activeMode:e.authenticated||t?.authenticated||n?.authenticated?`tap`:null,mode:`tap`,conversion:e.conversion,tap:e.tap,squid:e.squid,accounts:{...e.accounts,...t?.accounts,...n?.accounts}}},b=o.destroy.bind(o),x=s?.destroy.bind(s),S=d?.destroy.bind(d),C=()=>{f?.(),b(),x?.(),S?.(),n.b()},w={session:v,getAccountStatus:y,preload:()=>o.preload(),destroy:C};return r&&(o.destroy=C,Object.assign(w,{evm:o,ethereum:o})),s&&(s.destroy=C,Object.assign(w,{sui:s})),d&&(d.destroy=C,Object.assign(w,{solana:d})),w}function _(e={}){return console.warn("[WaaP SDK] `initWaaPSui()` is deprecated. Use `initWaaP({ chain: 'sui' })` instead."),f({...e,chain:`sui`})}function v(e={}){return f({...e,chain:`solana`})}function y(e={}){return g({...e,chains:e.chains??m})}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return f}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./esm-B4jz8Emb.mjs";import{t}from"./asyncSigning-CzqBbYDP.mjs";import{T as n,_ as r,a as i,b as a,c as o,f as s,g as c,h as l,n as u,p as d,s as f,t as p,u as m,v as h,w as g,x as _,y as v}from"./evm-DHVrAmEw.mjs";import{EventEmitter as y}from"events";const b={"sui:mainnet":`https://sui-rpc.publicnode.com`,"sui:testnet":`https://sui-testnet-rpc.publicnode.com`,"sui:devnet":`https://fullnode.devnet.sui.io`,"sui:localnet":`http://127.0.0.1:9000`},x=e=>b[e],S=e=>e.slice(4);var C=class{constructor(t,n={},r,a=n){this.lastKnownConversion=`pending`,this.name=`WaaP`,this.version=`1.0.0`,this.icon=`data:image/webp;base64,UklGRpoDAABXRUJQVlA4WAoAAAAQAAAAYwAAYwAAQUxQSDMDAAABJyAQSOFmFxERA8TatqpGoimANbEAxlBAPhSgQP9FyXv3vkcFEf134EZS5DREhGvTM8z0ki8stMRvK4cm8bk5rIu3xNbvkgPk4K6ti5IHquRQnLi6KrdBb81hdyF1jTLM1CW425943iba38/djOcG+dg85p/KXGd/g7+xAzJ2VPWTS8R+q65uA1ZcwG3iZ4urjw9Lh4xn83n3gZmQQ3VMVGEO6D403jdr81Ml1OISAAf7RGImBHISwQ5zCJonTuEyOyP7Sga4cDcjMPgXuiK9cUpaGrIDJtH4iAB25utB8O0DDztOKTr8u9hpX0jrx6k8UM5eAlqsynNxlX9tPRLQEtySKwcDOIDnMqEcek1UnylVNac4r0mlypNvhmCNODlhUXuT4fxTQyrDKY0uyV+gi0iiLLpY76A08C/IX8GQoYb8PcVxK7HkZkT5IjAF4gZicOfJW1ovJjyAlYVPlM6BkkHGI0fniAIZIXC0CbAM92BB8SBznU0ITYLr9XkfnKlDgV8170HGMWwitY51+zxcgkftLD4RLh4HSTIa3QzRWKxlaHZTz21s6GLxnBmjogkVilW4kuaMMMGUfgkZ1JhrBSEANrEDMwucAXgbTqIExY3FYRMdtkQRDFjD6BKtJ2GWTopGRY4P9DBkdE4rp9LJHuYhju45oeVZVv3zNmVdZiIOffHDppOz0Q34p0e/+nXy7JmF1846lmF2ZombLt8pgZpbPNeqpJSVJ0bGd4cH8dUNflNPfdQVXUkC95UQS0ZGfDmOJgjs3IyVOExZBEsxONd080gYK/ftQ2nbYaqGW89Hu7M6avmzXEjhO4G8O8ae8gwWtwZsyp8v8j/ys5H7bM+unOfurO4bbbL4v865Nb8s98Ld2X9yg6tLBQanMP8fhplOMMN8fiNDzTvNOMXGuYzejo12vY7s3clhXwgDPuBIcxi9QZftbKVxAjLCcVQdRxGR1QknhCs3GuieMLzfrrC9RhfJgVpcXRn71nZfEjsiYy/Ca1J7ch0clK64ReH3G/s2cekpP+BIx2YteMvSoLy6G9FCgd1nvF/VoVRtJoNJNLQ0RM3BXY9WgPbcHF78swAAVlA4IEAAAACwBQCdASpkAGQAPpFIoUylpCMiIKgAsBIJaW7hc+AAY2upvcReWAa6m9xF5YBrqb3EXlgGngAA/v81aVcAAAAA`,this._accounts=[],this.accountMode=`tap`,this.loginMethod=null,this._chains=[`sui:mainnet`,`sui:testnet`,`sui:devnet`],this.internalEventEmitter=new y,this.changeListeners=new Set,this.initializerPromise=null,this.initializedIframeWindow=null,this.walletMessageManager=new l(t,_(n)),this.ensureIframe=r,this.iframeMounted=!r,this.initializerOptions=a,this.uiMessageManager=new i,this.walletMessageManager.addListener({handleResponse:e=>{this.internalEventEmitter.emit(e.id,e)},handleRequest:t=>{t.method===e.show_modal?this.uiMessageManager.emit(`show_modal`):t.method===e.hide_modal&&this.uiMessageManager.emit(`hide_modal`)},onAccountChanged:async e=>{try{let e=await this.refreshAccounts();this.notifyChange({accounts:e.accounts})}catch(e){console.error(`Failed to refresh Sui accounts:`,e),this._accounts=[],this.notifyChange({accounts:[]})}}})}destroy(){this.walletMessageManager.dispose(),this.internalEventEmitter.removeAllListeners(),this.uiMessageManager.removeAllListeners(),this.changeListeners.clear(),this._accounts=[]}ensureIframeMounted(){if(this.iframeMounted||!this.ensureIframe)return;let e=this.ensureIframe();if(!e)throw Error(`Failed to create WaaP iframe`);this.iframeMounted=!0,this.walletMessageManager.setIframeWindow(e)}async preload(){if(!this.ensureIframe)return;this.ensureIframeMounted();let e=this.walletMessageManager.getIframeWindow();if(!e)throw Error(`WaaP iframe is not mounted`);if(this.initializedIframeWindow===e&&this.initializerPromise)return this.initializerPromise;this.initializedIframeWindow=e,this.initializerPromise=r(e,()=>this.selectAccountMode(this.accountMode,this.initializerOptions));try{await this.initializerPromise}catch(e){throw this.initializerPromise=null,this.initializedIframeWindow=null,e}}async ensureInitialized(){await this.preload()}async refreshAccounts(){try{await this.ensureInitialized();let e=await this.postRequestAndWait({method:`sui_connect`,params:[{silent:!0}],interactionRequired:!1});if(e.error)return this._accounts=[],{accounts:[]};let t=e.data?.accounts||[];return this._accounts=t,{accounts:this._accounts}}catch{return this._accounts=[],{accounts:[]}}}get chains(){return this._chains}get accounts(){return this._accounts}get ui(){return this.uiMessageManager}getAccountStatus(){return{authenticated:this.loginMethod!==null,loginMethod:this.loginMethod,activeMode:this.loginMethod?this.accountMode:null,mode:this.accountMode,conversion:this.loginMethod?this.lastKnownConversion:`not_required`,tap:null,squid:null,accounts:this._accounts[0]?{sui:this._accounts[0].address}:{}}}get session(){return{login:()=>this.login(),logout:()=>this.logout(),getLoginMethod:()=>this.getLoginMethod(),getAccountStatus:()=>this.getCanonicalAccountStatus()}}async getCanonicalAccountStatus(){await this.ensureInitialized();let t=await this.postRequestAndWait({method:e.waap_getAccountStatus,params:[],interactionRequired:!1});if(t.error)throw Error(t.error.message||`Failed to read WaaP status`);let n=t.data;return this.syncLoginMethodFromCanonicalStatus(n),n?.conversion&&(this.lastKnownConversion=n.conversion),n}setAccountMode(e){this.accountMode=e,this.initializerPromise=null,this.initializedIframeWindow=null}async selectAccountMode(t,n={}){await this.walletMessageManager.pingIframe(),await this.postRequestAndWait({method:e.set_signing_mode,params:[c(t,n)],interactionRequired:!1})}setLoginMethod(e){this.loginMethod=e,e===null&&(this._accounts=[],this.notifyChange({accounts:[]}))}getLoginMethod(){return this.loginMethod}async login(){await this.ensureInitialized();let t=await this.restoreSession();if(t)return t;let n=(await this.postRequestAndWait({method:e.login,params:[],interactionRequired:!0})).data;return n!==`waap`&&n!==`human`&&n!==`injected`&&n!==`walletconnect`?(this.loginMethod=null,null):(this.loginMethod=n,n)}async logout(){this.lastKnownConversion=`pending`,await this.ensureInitialized(),await this.postRequestAndWait({method:e.logout,params:[],interactionRequired:!1}),this.loginMethod=null,this._accounts=[],this.notifyChange({accounts:[]})}async connect(e){if(!this.loginMethod){if(e?.silent)throw new g(`not_authenticated`,`Not authenticated: a silent connect cannot open login.`,{operation:{chain:`sui`,method:`sui_connect`}});if(!await this.login())throw new g(`user_rejected`,`User rejected WaaP login during connect().`,{operation:{chain:`sui`,method:`sui_connect`}})}await this.ensureInitialized();let t=await this.postRequestAndWait({method:`sui_connect`,params:[e||{}],interactionRequired:!e?.silent,signal:e?.signal,timeoutMs:e?.timeoutMs});if(t.error)throw Error(t.error.message||`Failed to connect`);let n=t.data?.accounts||[];return this._accounts=n,this.notifyChange({accounts:this._accounts}),e?.silent||this.internalEventEmitter.emit(`connect`),this.internalEventEmitter.emit(`accountsChanged`,this._accounts.map(e=>e.address)),{accounts:this._accounts}}async restoreSession(){try{let e=await this.getCanonicalAccountStatus();if(e.authenticated&&(e.loginMethod===`waap`||e.loginMethod===`human`||e.loginMethod===`injected`||e.loginMethod===`walletconnect`))return this.loginMethod=e.loginMethod,e.loginMethod}catch{}return null}syncLoginMethodFromCanonicalStatus(e){let t=e.authenticated&&(e.loginMethod===`waap`||e.loginMethod===`human`||e.loginMethod===`injected`||e.loginMethod===`walletconnect`)?e.loginMethod:null;t!==this.loginMethod&&this.setLoginMethod(t)}async disconnect(){await this.ensureInitialized(),await this.postRequestAndWait({method:`sui_disconnect`,params:[],interactionRequired:!1}),this._accounts=[],this.notifyChange({accounts:[]})}async signPersonalMessage(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=await this.postRequestAndWait({method:`sui_signPersonalMessage`,params:[{message:Array.from(e.message),account:t,chain:e.chain}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(n.error)throw Error(n.error.message||`Failed to sign message`);return{bytes:n.data.bytes,signature:n.data.signature}}async extractTransferAddresses(e,t=!1){try{let{Transaction:n}=await import(`@mysten/sui/transactions`),r=(t?n.fromKind(e):n.from(e)).getData(),i=[];for(let e of r.commands){if(e.$kind!==`TransferObjects`)continue;let t=e.TransferObjects.address;if(t.$kind!==`Input`)continue;let n=t.Input,a=r.inputs[n];if(!a||a.$kind!==`Pure`)continue;let o=Uint8Array.from(atob(a.Pure.bytes),e=>e.charCodeAt(0));if(o.length!==32)continue;let s=`0x`+Array.from(o).map(e=>e.toString(16).padStart(2,`0`)).join(``);i.push(s)}return i}catch{return[]}}async resolveTransactionBytes(e,t=`sui:mainnet`){if(e instanceof Uint8Array)return{bytes:e,kind:`transaction-data`};if(Array.isArray(e))return{bytes:new Uint8Array(e),kind:`transaction-data`};if(typeof e==`string`)try{return{bytes:Uint8Array.from(atob(e),e=>e.charCodeAt(0)),kind:`transaction-data`}}catch{throw Error(`Transaction string must be base64 encoded bytes. If you have a serialized transaction JSON, please build it to bytes first.`)}else if(e&&typeof e==`object`){if(typeof e.build==`function`)try{let{SuiJsonRpcClient:n}=await import(`@mysten/sui/jsonRpc`),r=S(t),i=new n({url:x(t),network:r});return{bytes:await e.build({client:i,onlyTransactionKind:!0}),kind:`transaction-kind`}}catch(e){throw console.warn(`[SuiWallet] Failed to build transaction object:`,e),Error(`Failed to build transaction: ${e instanceof Error?e.message:String(e)}`)}if(typeof e.serialize==`function`)try{let t=await e.serialize();if(typeof t==`string`)return{bytes:Uint8Array.from(atob(t),e=>e.charCodeAt(0)),kind:`transaction-data`};if(t instanceof Uint8Array)return{bytes:t,kind:`transaction-data`}}catch(e){console.warn(`[SuiWallet] serialize() failed:`,e)}if(typeof e.toJSON==`function`)try{let t=await e.toJSON();if(typeof t==`string`)try{return{bytes:Uint8Array.from(atob(t),e=>e.charCodeAt(0)),kind:`transaction-data`}}catch{try{let e=JSON.parse(t);if(e.bytes&&typeof e.bytes==`string`)return{bytes:Uint8Array.from(atob(e.bytes),e=>e.charCodeAt(0)),kind:`transaction-data`}}catch{}}}catch(e){console.warn(`[SuiWallet] toJSON() failed:`,e)}if(typeof e.getData==`function`)try{let t=e.getData();if(t instanceof Uint8Array)return{bytes:t,kind:`transaction-data`}}catch(e){console.warn(`[SuiWallet] getData() failed:`,e)}throw Error(`Unsupported transaction format. Keys: ${Object.keys(e).join(`, `)}`)}else throw Error(`Unsupported transaction format: ${typeof e}. Please pass Uint8Array bytes or a Transaction object.`)}async signTransaction(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=await this.resolveTransactionBytes(e.transaction,e.chain),r=await this.postRequestAndWait({method:`sui_signTransaction`,params:[{...n.kind===`transaction-kind`?{transactionKind:Array.from(n.bytes)}:{transaction:Array.from(n.bytes)},account:t,chain:e.chain}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(r.error)throw Error(r.error.message||`Failed to sign transaction`);return{bytes:r.data.bytes,signature:r.data.signature}}async signAndExecuteTransaction(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=await this.resolveTransactionBytes(e.transaction,e.chain),r=await this.extractTransferAddresses(n.bytes,n.kind===`transaction-kind`),i=await this.postRequestAndWait({method:`sui_signAndExecuteTransaction`,params:[{...n.kind===`transaction-kind`?{transactionKind:Array.from(n.bytes)}:{transaction:Array.from(n.bytes)},account:t,chain:e.chain,options:e.options,requestType:e.requestType,toAddresses:r.length>0?r:void 0}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(i.error)throw Error(i.error.message||`Failed to sign and execute transaction`);return i.data}async switchChain(e){if(await this.ensureInitialized(),!this._chains.includes(e.chain))throw Error(`Chain ${e.chain} is not supported`);let t=await this.postRequestAndWait({method:`sui_switchChain`,params:[e],interactionRequired:!1});if(t.error)throw Error(t.error.message||`Failed to switch chain`);this.notifyChange({chains:this._chains,accounts:this._accounts})}on(e,t){return e===`change`?(this.changeListeners.add(t),()=>{this.changeListeners.delete(t)}):(this.internalEventEmitter.on(e,t),()=>{this.internalEventEmitter.removeListener(e,t)})}removeListener(e,t){if(e===`change`){this.changeListeners.delete(t);return}this.internalEventEmitter.removeListener(e,t)}get features(){return{"standard:connect":{version:`1.0.0`,connect:this.connect.bind(this)},"standard:disconnect":{version:`1.0.0`,disconnect:this.disconnect.bind(this)},"standard:events":{version:`1.0.0`,on:this.on.bind(this)},"sui:signPersonalMessage":{version:`1.1.0`,signPersonalMessage:this.signPersonalMessage.bind(this)},"sui:signTransaction":{version:`2.0.0`,signTransaction:this.signTransaction.bind(this)},"sui:signAndExecuteTransaction":{version:`1.0.0`,signAndExecuteTransaction:this.signAndExecuteTransaction.bind(this)},"sui:signTransactionBlock":{version:`2.0.0`,signTransactionBlock:this.signTransactionBlock.bind(this)},"sui:signAndExecuteTransactionBlock":{version:`1.0.0`,signAndExecuteTransactionBlock:this.signAndExecuteTransactionBlock.bind(this)},"sui:switchChain":{version:`1.0.0`,switchChain:this.switchChain.bind(this)}}}async signTransactionBlock(e){return this.signTransaction({transaction:e.transactionBlock,account:e.account,chain:e.chain})}async signAndExecuteTransactionBlock(e){return this.signAndExecuteTransaction({transaction:e.transactionBlock,account:e.account,chain:e.chain,options:e.options,requestType:e.requestType})}async requestPermissionToken(t){await this.ensureInitialized();let n=await this.postRequestAndWait({method:e.waap_requestPermissionToken,params:[t],interactionRequired:!0});if(n.error)throw Error(n.error.message||`Failed to request permission token`);return n.data}async getPermissionTokenStatus(t){return await this.ensureInitialized(),(await this.postRequestAndWait({method:e.waap_getPermissionTokenStatus,params:[t],interactionRequired:!1})).data}async clearPermissionToken(t){return await this.ensureInitialized(),(await this.postRequestAndWait({method:e.waap_clearPermissionToken,params:[t],interactionRequired:!1})).data}async requestEmail(){await this.ensureInitialized();let t=await this.postRequestAndWait({method:e.silk_requestEmail,params:[],interactionRequired:!0});if(t.error)throw Error(t.error.message||`Failed to request email`);return t.data}async postRequestAndWait(t){let r;try{t.interactionRequired&&d({layout:t.method===e.login?`auth`:`signing`}),r=await this.walletMessageManager.postSilkRequest({method:t.method,params:t.params,interactionRequired:t.interactionRequired});let n=await m({eventEmitter:this.internalEventEmitter,id:r,method:t.method,interactionRequired:t.interactionRequired,signal:t.signal,timeoutMs:t.timeoutMs,onCancel:()=>{this.walletMessageManager.cancelSilkRequest(r,t.method),t.interactionRequired&&s()}});if(n.error)throw Error(n.error.message);return n}catch(e){throw t.interactionRequired&&r===void 0&&s(),n(e,{chain:`sui`,method:String(t.method),requestId:r})}}notifyChange(e){Array.from(this.changeListeners).forEach(t=>{t(e)})}};function w(e,t,n=!0){let r=()=>(v(e),h(t).contentWindow),i=e.deferIframe===!1,o=e.deferIframe===void 0,c=i?r():null;if(i&&!c)throw Error(`Failed to create WaaP iframe`);let l=new C(c,e,r,{...e,chains:[`sui`]});l.setAccountMode(t),n&&i&&l.preload().catch(()=>void 0);let u=l.destroy.bind(l);if(l.destroy=()=>{u(),a()},n&&o){let e=f(l),t=l.destroy.bind(l);l.destroy=()=>{e(),t()}}return l.ui.on(`show_modal`,()=>{d(),document.querySelectorAll(`[data-dapp-kit][class*="overlay"]`).forEach(e=>{e.style.display=`none`})}),l.ui.on(`hide_modal`,()=>{s(),document.querySelectorAll(`[data-dapp-kit][class*="overlay"]`).forEach(e=>{e.style.display=``})}),l}var T=class{constructor(t,n={},r,a=n){this.lastKnownConversion=`pending`,this.name=`WaaP`,this.version=`1.0.0`,this.icon=`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2NCA2NCI+PHJlY3Qgd2lkdGg9IjY0IiBoZWlnaHQ9IjY0IiByeD0iMTYiIGZpbGw9IiMxMTE4MmMiLz48cGF0aCBkPSJNMTYgNDhoMzJMMzIgMTZ6IiBmaWxsPSIjN2NkNGZmIi8+PC9zdmc+`,this._accounts=[],this.accountMode=`tap`,this.loginMethod=null,this._chains=[`solana:mainnet`,`solana:devnet`,`solana:testnet`],this.internalEventEmitter=new y,this.changeListeners=new Set,this.initializerPromise=null,this.initializedIframeWindow=null,this.walletMessageManager=new l(t,_(n)),this.ensureIframe=r,this.iframeMounted=!r,this.initializerOptions=a,this.uiMessageManager=new i,this.walletMessageManager.addListener({handleResponse:e=>{this.internalEventEmitter.emit(e.id,e)},handleRequest:t=>{t.method===e.show_modal?this.uiMessageManager.emit(`show_modal`):t.method===e.hide_modal&&this.uiMessageManager.emit(`hide_modal`)},onAccountChanged:async()=>{try{let e=await this.refreshAccounts();this.notifyChange({accounts:e.accounts})}catch(e){console.error(`Failed to refresh Solana accounts:`,e),this._accounts=[],this.notifyChange({accounts:[]})}}})}destroy(){this.walletMessageManager.dispose(),this.internalEventEmitter.removeAllListeners(),this.uiMessageManager.removeAllListeners(),this.changeListeners.clear(),this._accounts=[]}ensureIframeMounted(){if(this.iframeMounted||!this.ensureIframe)return;let e=this.ensureIframe();if(!e)throw Error(`Failed to create WaaP iframe`);this.iframeMounted=!0,this.walletMessageManager.setIframeWindow(e)}async preload(){if(!this.ensureIframe)return;this.ensureIframeMounted();let e=this.walletMessageManager.getIframeWindow();if(!e)throw Error(`WaaP iframe is not mounted`);if(this.initializedIframeWindow===e&&this.initializerPromise)return this.initializerPromise;this.initializedIframeWindow=e,this.initializerPromise=r(e,()=>this.selectAccountMode(this.accountMode,this.initializerOptions));try{await this.initializerPromise}catch(e){throw this.initializerPromise=null,this.initializedIframeWindow=null,e}}async ensureInitialized(){await this.preload()}get chains(){return this._chains}get accounts(){return this._accounts}get features(){return{"standard:connect":{version:`1.0.0`,connect:this.connect.bind(this)},"standard:disconnect":{version:`1.0.0`,disconnect:this.disconnect.bind(this)},"standard:events":{version:`1.0.0`,on:this.on.bind(this)},"solana:signMessage":{version:`1.1.0`,signMessage:this.signStandardMessages.bind(this)},"solana:signTransaction":{version:`1.0.0`,supportedTransactionVersions:[`legacy`,0],signTransaction:this.signStandardTransactions.bind(this)},"solana:signAndSendTransaction":{version:`1.0.0`,supportedTransactionVersions:[`legacy`,0],signAndSendTransaction:this.signAndSendStandardTransactions.bind(this)}}}get ui(){return this.uiMessageManager}getAccountStatus(){return{authenticated:this.loginMethod!==null,loginMethod:this.loginMethod,activeMode:this.loginMethod?this.accountMode:null,mode:this.accountMode,conversion:this.loginMethod?this.lastKnownConversion:`not_required`,tap:null,squid:null,accounts:this._accounts[0]?{solana:this._accounts[0].address}:{}}}get session(){return{login:()=>this.login(),logout:()=>this.logout(),getLoginMethod:()=>this.getLoginMethod(),getAccountStatus:()=>this.getCanonicalAccountStatus()}}async getCanonicalAccountStatus(){await this.ensureInitialized();let t=await this.postRequestAndWait({method:e.waap_getAccountStatus,params:[],interactionRequired:!1});if(t.error)throw Error(t.error.message||`Failed to read WaaP status`);let n=t.data;return this.syncLoginMethodFromCanonicalStatus(n),n?.conversion&&(this.lastKnownConversion=n.conversion),n}setAccountMode(e){this.accountMode=e,this.initializerPromise=null,this.initializedIframeWindow=null}async selectAccountMode(t,n={}){await this.walletMessageManager.pingIframe(),await this.postRequestAndWait({method:e.set_signing_mode,params:[c(t,n)],interactionRequired:!1})}setLoginMethod(e){this.loginMethod=e,e===null&&(this._accounts=[],this.notifyChange({accounts:[]}))}getLoginMethod(){return this.loginMethod}async login(){await this.ensureInitialized();let t=await this.restoreSession();if(t)return t;let n=(await this.postRequestAndWait({method:e.login,params:[],interactionRequired:!0})).data;return n!==`waap`&&n!==`human`&&n!==`injected`&&n!==`walletconnect`?(this.loginMethod=null,null):(this.loginMethod=n,n)}async logout(){this.lastKnownConversion=`pending`,await this.ensureInitialized(),await this.postRequestAndWait({method:e.logout,params:[],interactionRequired:!1}),this.loginMethod=null,this._accounts=[],this.notifyChange({accounts:[]})}async refreshAccounts(){try{await this.ensureInitialized();let e=await this.postRequestAndWait({method:`solana_connect`,params:[{silent:!0}],interactionRequired:!1});if(e.error)return this._accounts=[],{accounts:[]};let t=this.normalizeAccounts(e.data?.accounts||[]);return this._accounts=t,{accounts:this._accounts}}catch{return this._accounts=[],{accounts:[]}}}normalizeAccounts(e){return e.map(e=>({address:e.address,publicKey:e.publicKey instanceof Uint8Array?e.publicKey:new Uint8Array(e.publicKey??[]),chains:e.chains??this._chains,features:e.features??[]}))}async connect(e){if(!this.loginMethod)throw new g(`not_authenticated`,`Not authenticated: call login() before connect().`,{operation:{chain:`solana`,method:`solana_connect`}});await this.ensureInitialized();let t=await this.postRequestAndWait({method:`solana_connect`,params:[e||{}],interactionRequired:!e?.silent,signal:e?.signal,timeoutMs:e?.timeoutMs});if(t.error)throw Error(t.error.message||`Failed to connect`);let n=this.normalizeAccounts(t.data?.accounts||[]);return this._accounts=n,this.notifyChange({accounts:this._accounts}),e?.silent||this.internalEventEmitter.emit(`connect`),this.internalEventEmitter.emit(`accountsChanged`,this._accounts.map(e=>e.address)),{accounts:this._accounts}}async restoreSession(){try{let e=await this.getCanonicalAccountStatus();if(e.authenticated&&(e.loginMethod===`waap`||e.loginMethod===`human`||e.loginMethod===`injected`||e.loginMethod===`walletconnect`))return this.loginMethod=e.loginMethod,e.loginMethod}catch{}return null}syncLoginMethodFromCanonicalStatus(e){let t=e.authenticated&&(e.loginMethod===`waap`||e.loginMethod===`human`||e.loginMethod===`injected`||e.loginMethod===`walletconnect`)?e.loginMethod:null;t!==this.loginMethod&&this.setLoginMethod(t)}async disconnect(){await this.ensureInitialized(),await this.postRequestAndWait({method:`solana_disconnect`,params:[],interactionRequired:!1}),this._accounts=[],this.notifyChange({accounts:[]})}async signMessage(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=await this.postRequestAndWait({method:`solana_signMessage`,params:[{message:Array.from(e.message),account:t}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(n.error)throw Error(n.error.message||`Failed to sign message`);return{signedMessage:new Uint8Array(n.data.signedMessage),signature:new Uint8Array(n.data.signature)}}async signTransaction(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=this.resolveTransactionBytes(e.transaction),r=await this.postRequestAndWait({method:`solana_signTransaction`,params:[{transaction:Array.from(n),account:t,chain:e.chain,withPT:e.withPT}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(r.error)throw Error(r.error.message||`Failed to sign transaction`);return{signedTransaction:new Uint8Array(r.data.signedTransaction),signature:new Uint8Array(r.data.signature)}}async signAndSendTransaction(e){await this.ensureInitialized();let t=e.account.address;if(!this._accounts.some(e=>e.address===t))throw Error(`Account ${t} is not connected`);let n=this.resolveTransactionBytes(e.transaction),r=await this.postRequestAndWait({method:`solana_signAndSendTransaction`,params:[{transaction:Array.from(n),account:t,chain:e.chain,options:e.options,withPT:e.withPT}],interactionRequired:!0,signal:e.signal,timeoutMs:e.timeoutMs});if(r.error)throw Error(r.error.message||`Failed to sign and send transaction`);return{signature:r.data.signature}}async signStandardMessages(...e){let t=[];for(let n of e){let e=await this.signMessage({account:n.account,message:n.message});t.push({...e,signatureType:`ed25519`})}return t}async signStandardTransactions(...e){let t=[];for(let n of e){let e=await this.signTransaction({account:n.account,transaction:n.transaction,chain:this.asSupportedChain(n.chain)});t.push({signedTransaction:e.signedTransaction})}return t}async signAndSendStandardTransactions(...e){let t=[];for(let n of e){let e=await this.signAndSendTransaction({account:n.account,transaction:n.transaction,chain:this.asSupportedChain(n.chain),options:this.broadcastOptions(n.options)});t.push({signature:E(e.signature)})}return t}asSupportedChain(e){if(e!==void 0){if(this._chains.includes(e))return e;throw new g(`unsupported_input`,`Unsupported Solana Wallet Standard chain: ${e}`,{operation:{chain:`solana`,method:`wallet_standard`}})}}broadcastOptions(e){if(e?.preflightCommitment!==void 0||e?.minContextSlot!==void 0||e?.commitment!==void 0)throw new g(`unsupported_input`,`WaaP does not support Wallet Standard RPC commitment options; configure the dapp RPC instead.`,{operation:{chain:`solana`,method:`wallet_standard`}});return e?{skipPreflight:e.skipPreflight,maxRetries:e.maxRetries}:void 0}async requestPermissionToken(t){await this.ensureInitialized();let n=await this.postRequestAndWait({method:e.waap_requestPermissionToken,params:[t],interactionRequired:!0});if(n.error)throw Error(n.error.message||`Failed to request permission token`);return n.data}async getPermissionTokenStatus(t){return await this.ensureInitialized(),(await this.postRequestAndWait({method:e.waap_getPermissionTokenStatus,params:[t],interactionRequired:!1})).data}async clearPermissionToken(t){return await this.ensureInitialized(),(await this.postRequestAndWait({method:e.waap_clearPermissionToken,params:[t],interactionRequired:!1})).data}resolveTransactionBytes(e){if(e instanceof Uint8Array)return e;if(Array.isArray(e))return new Uint8Array(e);if(e&&typeof e.serialize==`function`){let t=e.serialize();return t instanceof Uint8Array?t:new Uint8Array(t)}throw Error(`Unsupported transaction format. Pass serialized bytes or a @solana/web3.js Transaction.`)}on(e,t){return e===`change`?(this.changeListeners.add(t),()=>{this.changeListeners.delete(t)}):(this.internalEventEmitter.on(e,t),()=>{this.internalEventEmitter.removeListener(e,t)})}removeListener(e,t){if(e===`change`){this.changeListeners.delete(t);return}this.internalEventEmitter.removeListener(e,t)}async postRequestAndWait(t){let r;try{t.interactionRequired&&d({layout:t.method===e.login?`auth`:`signing`}),r=await this.walletMessageManager.postSilkRequest({method:t.method,params:t.params,interactionRequired:t.interactionRequired});let n=await m({eventEmitter:this.internalEventEmitter,id:r,method:t.method,interactionRequired:t.interactionRequired,signal:t.signal,timeoutMs:t.timeoutMs,onCancel:()=>{this.walletMessageManager.cancelSilkRequest(r,t.method),t.interactionRequired&&s()}});if(n.error)throw Error(n.error.message);return n}catch(e){throw t.interactionRequired&&r===void 0&&s(),n(e,{chain:`solana`,method:String(t.method),requestId:r})}}notifyChange(e){Array.from(this.changeListeners).forEach(t=>{t(e)})}};function E(e){let t=[];for(let n of e){let e=`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`.indexOf(n);if(e<0)throw Error(`Invalid base58 transaction signature`);for(let n=0;n<t.length;n+=1)e+=t[n]*58,t[n]=e&255,e>>=8;for(;e>0;)t.push(e&255),e>>=8}let n=0;for(;n<e.length&&e[n]===`1`;)n+=1;return new Uint8Array([...Array(n).fill(0),...t.reverse()])}function D(e={}){let t=()=>(v(e),h(`tap`).contentWindow),n=e.deferIframe===!1,r=e.deferIframe===void 0,i=n?t():null;if(n&&!i)throw Error(`Failed to create WaaP iframe`);let o=new T(i,e,t,{...e,chains:[`solana`]});n&&o.preload().catch(()=>void 0);let c=o.destroy.bind(o);if(o.destroy=()=>{c(),a()},r){let e=f(o),t=o.destroy.bind(o);o.destroy=()=>{e(),t()}}return o.ui.on(`show_modal`,()=>{d()}),o.ui.on(`hide_modal`,()=>{s()}),o}function O(e={}){if(`chains`in e)throw Error("initWaaP accepts one `chain`; use initWaaPMulti({ chains }) for TAP.");switch(e.chain){case`sui`:return w(e,`tap`);case`solana`:return D(e);default:return p(e)}}const k=[`evm`,`sui`,`solana`],A=[`evm`,`sui`,`solana`];function j(n={}){let r=Array.from(new Set(n.chains??k));if(r.length===0)throw Error(`initWaaPSquid requires at least one chain facade`);if(r.some(e=>!k.includes(e)))throw Error(`initWaaPSquid received an unsupported chain facade`);let i=r.includes(`evm`),s=r.includes(`sui`),c=r.includes(`solana`),l=u({referralCode:n.referralCode,config:n.config,project:n.project,environment:n.environment,walletOrigin:n.walletOrigin,useStaging:n.useStaging,walletConnectProjectId:n.walletConnectProjectId,asyncTxs:n.asyncTxs,deferIframe:n.deferIframe,sessionProtection:n.sessionProtection},`squid`,!1,r,i),d=s?w(n,`squid`,!1):void 0,p=()=>(v(n),h(`squid`).contentWindow),m=c?new T(n.deferIframe===!1?p():null,{useStaging:n.useStaging,environment:n.environment,walletOrigin:n.walletOrigin,referralCode:n.referralCode,project:n.project,config:n.config,deferIframe:n.deferIframe,sessionProtection:n.sessionProtection},p,{...n,chains:[`solana`]}):void 0;m?.setAccountMode(`squid`);let _;n.deferIframe===!1?l.preload().catch(()=>void 0):n.deferIframe===void 0&&(_=f(l));let y={state:`absent`},b=null,x=0,S=()=>{b=null,y={state:`absent`}},C=e=>!e.lifecycleId||e.lifecycleId===b,E=()=>y.state===`active`;l.on(t.squidPending,e=>{if(!C(e))return;let t=e?.transactionDigest;y={state:t?`awaiting-network`:`provisioning`,...t?{operationId:t,transactionDigest:t}:{},...e?.message?{message:e.message}:{}}}),l.on(t.squidReady,e=>{C(e)&&(y={state:`active`})}),l.on(t.squidFailed,e=>{C(e)&&(y={state:`failed`,...e?.error?{message:e.error}:{}},b=null)});let D=e=>{if(l.getLoginMethod()===null)throw new g(`not_authenticated`,`Not authenticated: call login() before connecting or signing.`,{operation:{chain:e,method:`connect`}});if(!E())throw new g(`not_connected`,`Squid is not ready: call onboard() after login before connecting or signing.`)},O=l.request.bind(l);if(l.request=async e=>([`eth_requestAccounts`,`eth_accounts`,`eth_sendTransaction`,`eth_signTransaction`,`personal_sign`,`eth_signTypedData_v4`].includes(e.method)&&D(`evm`),O(e)),d){let e=d.connect.bind(d);d.connect=async t=>(D(`sui`),e(t))}if(m){let e=m.connect.bind(m);m.connect=async t=>(D(`solana`),e(t))}let A=async()=>{if(l.getLoginMethod()===null)throw new g(`not_authenticated`,`Not authenticated: call login() before onboarding Squid.`);if(E()||b)return;let t=`squid-${++x}`;b=t,y={state:`provisioning`};try{await l.walletMessageManager.pingIframe(),await o({method:e.enter_lite_mode,params:[window.location.origin,t]},!1,l.walletMessageManager,l.internalEventEmitter)}catch(e){throw b===t&&(b=null,y={state:`failed`,message:e instanceof Error?e.message:String(e)}),e}},j=()=>({...y}),M=e=>{if(y.state===`active`||!e.authenticated||e.activeMode!==`squid`||!e.squid)return;let n={...b?{lifecycleId:b}:{},evm:e.squid.sqd1.evm,sui:e.squid.sqd2.sui,solana:e.squid.sqd2.solana};y={state:`active`},b=null,l.emit(t.squidReady,n)},N=async()=>(await A(),j()),P=l.login.bind(l),F=async e=>{let t=await P(e);return d?.setLoginMethod(t),m?.setLoginMethod(t),(t?await l.session.getAccountStatus().catch(()=>null):null)?.squid&&(await l.reassertIframeAccountMode().catch(()=>void 0),await A()),t&&l.emit(`connect`),t},I=l.logout.bind(l),L=async()=>{await I(),d?.setLoginMethod(null),m?.setLoginMethod(null),S()},R;R={login:F,logout:L,getLoginMethod:()=>l.getLoginMethod(),getAccountStatus:async()=>{let e=await l.session.getAccountStatus();return M(e),e},getSquidStatus:j,on:(e,t)=>(l.on(e,t),R),removeListener:(e,t)=>(l.removeListener(e,t),R)},l.login=R.login,l.logout=R.logout,d&&(d.login=()=>R.login(),d.logout=()=>R.logout()),m&&(m.login=()=>R.login(),m.logout=()=>R.logout());let z={onboard:A,squid:{onboard:A,getStatus:j,onboardWithStatus:N},getSquidStatus:j,session:R,getAccountStatus:()=>{let e=l.getAccountStatus(),t=d?.getAccountStatus(),n=m?.getAccountStatus();return{authenticated:e.authenticated||!!t?.authenticated||!!n?.authenticated,loginMethod:e.loginMethod??t?.loginMethod??n?.loginMethod??null,activeMode:e.authenticated||t?.authenticated||n?.authenticated?`squid`:null,mode:`squid`,conversion:e.conversion,tap:e.tap,squid:e.squid,accounts:{...e.accounts,...t?.accounts,...n?.accounts}}},preload:()=>l.preload(),destroy:()=>{_?.(),S(),l.destroy(),d?.destroy(),m?.destroy(),a()}};return i&&Object.assign(z,{evm:l,ethereum:l}),d&&Object.assign(z,{sui:d}),m&&Object.assign(z,{solana:m}),k.every(e=>r.includes(e))&&Object.assign(z,{auth:l}),z}function M(e){let t=Array.from(new Set(e.chains));if(t.length===0)throw Error(`initWaaPMulti requires at least one chain facade`);if(t.some(e=>!A.includes(e)))throw Error(`initWaaPMulti received an unsupported chain facade`);let n=t.includes(`evm`),r=t.includes(`sui`),i=t.includes(`solana`),o=u({referralCode:e.referralCode,config:e.config,project:e.project,environment:e.environment,walletOrigin:e.walletOrigin,useStaging:e.useStaging,walletConnectProjectId:e.walletConnectProjectId,asyncTxs:e.asyncTxs,deferIframe:e.deferIframe,sessionProtection:e.sessionProtection},`tap`,!1,t,n),s=r?w({...e,config:e.config},`tap`,!1):void 0,c=()=>(v(e),h(`tap`).contentWindow),l=i?new T(e.deferIframe===!1?c():null,{useStaging:e.useStaging,environment:e.environment,walletOrigin:e.walletOrigin,referralCode:e.referralCode,project:e.project,config:e.config,deferIframe:e.deferIframe,sessionProtection:e.sessionProtection},c,{...e,chains:[`solana`]}):void 0;l?.setAccountMode(`tap`);let d;e.deferIframe===!1?o.preload().catch(()=>void 0):e.deferIframe===void 0&&(d=f(o));let p=o.login.bind(o),m=async e=>{let t=await p(e);return s?.setLoginMethod(t),l?.setLoginMethod(t),t&&o.emit(`connect`),t},g=o.logout.bind(o),_=async()=>{await g(),s?.setLoginMethod(null),l?.setLoginMethod(null)},y;y={login:m,logout:_,getLoginMethod:()=>o.getLoginMethod(),getAccountStatus:()=>o.session.getAccountStatus(),on:(e,t)=>(o.on(e,t),y),removeListener:(e,t)=>(o.removeListener(e,t),y)},o.login=y.login,o.logout=y.logout,s&&(s.login=()=>y.login(),s.logout=()=>y.logout()),l&&(l.login=()=>y.login(),l.logout=()=>y.logout());let b=()=>{let e=o.getAccountStatus(),t=s?.getAccountStatus(),n=l?.getAccountStatus();return{authenticated:e.authenticated||!!t?.authenticated||!!n?.authenticated,loginMethod:e.loginMethod??t?.loginMethod??n?.loginMethod??null,activeMode:e.authenticated||t?.authenticated||n?.authenticated?`tap`:null,mode:`tap`,conversion:e.conversion,tap:e.tap,squid:e.squid,accounts:{...e.accounts,...t?.accounts,...n?.accounts}}},x=o.destroy.bind(o),S=s?.destroy.bind(s),C=l?.destroy.bind(l),E=()=>{d?.(),x(),S?.(),C?.(),a()},D={session:y,getAccountStatus:b,preload:()=>o.preload(),destroy:E};return n&&(o.destroy=E,Object.assign(D,{evm:o,ethereum:o})),s&&(s.destroy=E,Object.assign(D,{sui:s})),l&&(l.destroy=E,Object.assign(D,{solana:l})),D}function N(e={}){return console.warn("[WaaP SDK] `initWaaPSui()` is deprecated. Use `initWaaP({ chain: 'sui' })` instead."),O({...e,chain:`sui`})}function P(e={}){return O({...e,chain:`solana`})}function F(e={}){return M({...e,chains:e.chains??A})}export{N as a,C as c,j as i,M as n,F as o,P as r,T as s,O as t};
|