@human.tech/waap-sdk 2.3.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/.agent/SKILL.md +28 -13
  2. package/CHANGELOG.md +152 -0
  3. package/README.md +16 -2
  4. package/dist/SolanaProvider-BdeBP_ro.js +1 -0
  5. package/dist/SolanaProvider-DP9J8JuJ.mjs +1 -0
  6. package/dist/UIMessageManager-4xqSTTBS.d.mts +11 -0
  7. package/dist/UIMessageManager-4xqSTTBS.d.ts +11 -0
  8. package/dist/UIMessageManager-CtnIZgIY.mjs +1 -0
  9. package/dist/UIMessageManager-D-OTya1E.js +1 -0
  10. package/dist/WaaPError-C2TOEGPx.d.mts +52 -0
  11. package/dist/WaaPError-C2TOEGPx.d.ts +52 -0
  12. package/dist/{WalletConnect-Dn40Omgo.js → WalletConnect-B21f4Vvh.js} +1 -1
  13. package/dist/{WalletConnect-UfxGn2M_.mjs → WalletConnect-DXiTxC-F.mjs} +1 -1
  14. package/dist/{WaaPError-CMOAWUlN.d.ts → WalletModalController-16mHsFv2.d.ts} +17 -55
  15. package/dist/{WaaPError-BjukImOz.d.mts → WalletModalController-DxiBiqDf.d.mts} +17 -55
  16. package/dist/bridge.d.mts +158 -0
  17. package/dist/bridge.d.ts +158 -0
  18. package/dist/bridge.js +1 -0
  19. package/dist/bridge.mjs +1 -0
  20. package/dist/evm-dDMLwSQe.mjs +2 -0
  21. package/dist/evm-rUSuf-iy.js +2 -0
  22. package/dist/evm.d.mts +3 -2
  23. package/dist/evm.d.ts +3 -2
  24. package/dist/evm.js +1 -1
  25. package/dist/evm.mjs +1 -1
  26. package/dist/{index-DOIss_GK.d.ts → index-BOExImk3.d.mts} +29 -192
  27. package/dist/{index-C0mLQs_a.d.mts → index-BkKBZpqc.d.ts} +29 -192
  28. package/dist/index.d.mts +33 -8
  29. package/dist/index.d.ts +33 -8
  30. package/dist/index.js +3 -3
  31. package/dist/index.mjs +3 -3
  32. package/dist/init-BkrqKNet.js +1 -0
  33. package/dist/init-C-52fEJS.d.ts +84 -0
  34. package/dist/init-C3zCj5Lc.d.mts +84 -0
  35. package/dist/init-CkYgm7Zu.mjs +1 -0
  36. package/dist/react.d.mts +1 -1
  37. package/dist/react.d.ts +1 -1
  38. package/dist/react.js +1 -1
  39. package/dist/react.mjs +1 -1
  40. package/dist/register-B2G1larb.mjs +1 -0
  41. package/dist/{register-9bEe9ATz.d.mts → register-BKCJXsHB.d.mts} +9 -6
  42. package/dist/register-BL_2Xqcc.js +1 -0
  43. package/dist/{register-XzDVa7r8.d.mts → register-C1hFwh4A.d.ts} +4 -3
  44. package/dist/register-CLpzYN7U.mjs +1 -0
  45. package/dist/{register-DgN7qh23.js → register-Diu5wxsG.js} +1 -1
  46. package/dist/{register-PWKDsSRv.d.ts → register-GiWQpcBY.d.ts} +9 -6
  47. package/dist/{register-Mb1D_xW4.d.ts → register-mq9fTaSt.d.mts} +4 -3
  48. package/dist/solana.d.mts +6 -4
  49. package/dist/solana.d.ts +6 -4
  50. package/dist/solana.js +1 -1
  51. package/dist/solana.mjs +1 -1
  52. package/dist/stellar.d.mts +6 -0
  53. package/dist/stellar.d.ts +6 -0
  54. package/dist/stellar.js +1 -0
  55. package/dist/stellar.mjs +1 -0
  56. package/dist/sui.d.mts +5 -4
  57. package/dist/sui.d.ts +5 -4
  58. package/dist/sui.js +1 -1
  59. package/dist/sui.mjs +1 -1
  60. package/dist/types-Bai14yLc.d.mts +95 -0
  61. package/dist/types-Bj5dDE-C.d.ts +198 -0
  62. package/dist/types-C7JDjWnt.d.mts +198 -0
  63. package/dist/{types-BmCqyQtu.d.mts → types-Cc6tc4ut.d.mts} +18 -1
  64. package/dist/{types-BmCqyQtu.d.ts → types-Cc6tc4ut.d.ts} +18 -1
  65. package/dist/types-DqdVfkaW.d.ts +95 -0
  66. package/dist/ui-CnG74RaM.js +1 -0
  67. package/dist/ui-lV9LVoom.mjs +1 -0
  68. package/dist/{useWaapAuth-vJAk2n_I.d.mts → useWaapAuth-Be1YJk-7.d.mts} +2 -2
  69. package/dist/useWaapAuth-C9Cwu4XG.js +1 -0
  70. package/dist/{useWaapAuth-DgYO5KxO.d.ts → useWaapAuth-DSFDwJtt.d.ts} +2 -2
  71. package/dist/useWaapAuth-Vh8gUs6Y.mjs +1 -0
  72. package/dist/walletconnect.js +1 -1
  73. package/dist/walletconnect.mjs +1 -1
  74. package/docs/solana-wallet-adapter.md +157 -0
  75. package/package.json +32 -4
  76. package/dist/esm-BUfmyWbN.mjs +0 -1
  77. package/dist/esm-DFwVZkjo.js +0 -1
  78. package/dist/evm-9r6LecIW.mjs +0 -2
  79. package/dist/evm-D_LHHo3z.js +0 -2
  80. package/dist/initializerContext-DIrqEE6B.d.ts +0 -20
  81. package/dist/initializerContext-_YjbVTiL.d.mts +0 -20
  82. package/dist/register-CEeLG7qz.mjs +0 -1
  83. package/dist/register-CodxV1XG.js +0 -1
  84. package/dist/register-I8d7v41B.mjs +0 -1
  85. package/dist/ui-BjcwM6px.js +0 -1
  86. package/dist/ui-CrnBoTQL.mjs +0 -1
  87. package/dist/useWaapAuth-BPvve-_3.js +0 -1
  88. package/dist/useWaapAuth-BcmVGb-D.mjs +0 -1
@@ -1,4 +1,4 @@
1
- import { D as SilkRequestCancellation, E as SilkRequest, M as SILK_METHOD, N as SilkNotificationData, O as SilkResponse } from "./types-BmCqyQtu.js";
1
+ import { D as SilkRequest, N as SILK_METHOD, O as SilkRequestCancellation, P as SilkNotificationData, k as SilkResponse } from "./types-Cc6tc4ut.js";
2
2
  //#region src/lib/WalletMessageManager.d.ts
3
3
  type PostSilkRequestArgs = {
4
4
  method: keyof typeof SILK_METHOD;
@@ -26,12 +26,25 @@ interface SquidLifecycleNotification {
26
26
  * Listener interface for WalletMessageManager
27
27
  */
28
28
  interface MessageListenerConfig {
29
- handleResponse: (response: SilkResponse) => void;
30
- handleRequest: (request: SilkRequest) => void;
29
+ /**
30
+ * Optional so a listener interested only in notifications does not have to
31
+ * pass stubs. `shouldHandleTerminalResponse` consumes the id, so a second
32
+ * registration with a no-op `handleResponse` would swallow the response for
33
+ * whichever entry the dispatcher reached first -- correct only by
34
+ * registration order, and silently wrong if that order ever changed.
35
+ */
36
+ handleResponse?: (response: SilkResponse) => void;
37
+ handleRequest?: (request: SilkRequest) => void;
31
38
  onReceiveConnectNotif?: () => void;
32
39
  onAccountChanged?: (newAccount: string) => void;
33
40
  onAsyncTxNotification?: (notification: AsyncTxNotification) => void;
34
41
  onSquidLifecycleNotification?: (notification: SquidLifecycleNotification) => void;
42
+ /**
43
+ * A native social login finished in the system browser. The wallet keeps the
44
+ * originating `login` request open across that hand-off, so this is the only
45
+ * signal that it is over.
46
+ */
47
+ onAuthComplete?: (result: 'success' | 'error') => void;
35
48
  }
36
49
  type WalletHandshakeDiagnostics = {
37
50
  walletOrigin: string;
@@ -121,55 +134,4 @@ declare const subscribeWaaPIframeLifecycle: (listener: (event: WaaPIframeLifecyc
121
134
  */
122
135
  declare const getWaaPIframeDiagnostics: () => WaaPIframeDiagnostics;
123
136
  //#endregion
124
- //#region src/lib/preload.d.ts
125
- /** Any public WaaP facade that can warm the shared wallet iframe. */
126
- interface WaaPPreloadTarget {
127
- preload(): Promise<void>;
128
- }
129
- interface WaaPIdlePreloadOptions {
130
- /** Browser deadline for an idle callback. Default: 2 seconds. */
131
- timeoutMs?: number;
132
- /** Observes a best-effort warmup failure without making page startup fail. */
133
- onError?: (error: unknown) => void;
134
- }
135
- type CancelWaaPPreload = () => void;
136
- /**
137
- * Warm an already-created WaaP facade when the browser is idle. It never opens
138
- * wallet UI, and cancellation is useful when the embedding route unmounts.
139
- *
140
- * Use this after the host page's LCP. For a likely immediate action (for
141
- * example Connect button hover/focus), call `target.preload()` directly.
142
- */
143
- declare const preloadWaaPOnIdle: (target: WaaPPreloadTarget, options?: WaaPIdlePreloadOptions) => CancelWaaPPreload;
144
- //#endregion
145
- //#region src/lib/WaaPError.d.ts
146
- /** Stable, safe error vocabulary for non-EIP-1193 SDK facades. */
147
- type WaaPErrorCode = 'cancelled' | 'timeout' | 'user_rejected' | 'policy_rejected' |
148
- /**
149
- * The user's gas tank cannot cover a fee the operation is billed. Distinct
150
- * from `wallet_error` because it is the user's to fix and retrying changes
151
- * nothing until they top up — the same split the server draws between a 402
152
- * and a 502.
153
- */
154
- 'insufficient_balance' | 'not_authenticated' | 'not_connected' | 'unsupported_input' | 'wallet_error' | 'maintenance' | 'unknown';
155
- type WaaPOperationMetadata = {
156
- /**
157
- * The chain the failed operation targeted. Declared structurally rather than
158
- * as `WaaPChain` so the error vocabulary stays free of the initializer graph.
159
- */
160
- chain?: 'evm' | 'sui' | 'solana';
161
- method?: string;
162
- requestId?: string;
163
- };
164
- declare class WaaPError extends Error {
165
- readonly code: WaaPErrorCode;
166
- readonly operation?: WaaPOperationMetadata;
167
- readonly cause?: unknown;
168
- constructor(code: WaaPErrorCode, message: string, options?: {
169
- cause?: unknown;
170
- operation?: WaaPOperationMetadata;
171
- });
172
- }
173
- declare function normalizeWaaPError(error: unknown, operation?: WaaPOperationMetadata): WaaPError;
174
- //#endregion
175
- export { CancelWaaPPreload as a, preloadWaaPOnIdle as c, WaaPIframeLifecyclePhase as d, getWaaPIframeDiagnostics as f, WalletMessageManager as h, normalizeWaaPError as i, WaaPIframeDiagnostics as l, PostSilkRequestArgs as m, WaaPErrorCode as n, WaaPIdlePreloadOptions as o, subscribeWaaPIframeLifecycle as p, WaaPOperationMetadata as r, WaaPPreloadTarget as s, WaaPError as t, WaaPIframeLifecycleEvent as u };
137
+ export { subscribeWaaPIframeLifecycle as a, getWaaPIframeDiagnostics as i, WaaPIframeLifecycleEvent as n, PostSilkRequestArgs as o, WaaPIframeLifecyclePhase as r, WalletMessageManager as s, WaaPIframeDiagnostics as t };
@@ -1,4 +1,4 @@
1
- import { D as SilkRequestCancellation, E as SilkRequest, M as SILK_METHOD, N as SilkNotificationData, O as SilkResponse } from "./types-BmCqyQtu.mjs";
1
+ import { D as SilkRequest, N as SILK_METHOD, O as SilkRequestCancellation, P as SilkNotificationData, k as SilkResponse } from "./types-Cc6tc4ut.mjs";
2
2
  //#region src/lib/WalletMessageManager.d.ts
3
3
  type PostSilkRequestArgs = {
4
4
  method: keyof typeof SILK_METHOD;
@@ -26,12 +26,25 @@ interface SquidLifecycleNotification {
26
26
  * Listener interface for WalletMessageManager
27
27
  */
28
28
  interface MessageListenerConfig {
29
- handleResponse: (response: SilkResponse) => void;
30
- handleRequest: (request: SilkRequest) => void;
29
+ /**
30
+ * Optional so a listener interested only in notifications does not have to
31
+ * pass stubs. `shouldHandleTerminalResponse` consumes the id, so a second
32
+ * registration with a no-op `handleResponse` would swallow the response for
33
+ * whichever entry the dispatcher reached first -- correct only by
34
+ * registration order, and silently wrong if that order ever changed.
35
+ */
36
+ handleResponse?: (response: SilkResponse) => void;
37
+ handleRequest?: (request: SilkRequest) => void;
31
38
  onReceiveConnectNotif?: () => void;
32
39
  onAccountChanged?: (newAccount: string) => void;
33
40
  onAsyncTxNotification?: (notification: AsyncTxNotification) => void;
34
41
  onSquidLifecycleNotification?: (notification: SquidLifecycleNotification) => void;
42
+ /**
43
+ * A native social login finished in the system browser. The wallet keeps the
44
+ * originating `login` request open across that hand-off, so this is the only
45
+ * signal that it is over.
46
+ */
47
+ onAuthComplete?: (result: 'success' | 'error') => void;
35
48
  }
36
49
  type WalletHandshakeDiagnostics = {
37
50
  walletOrigin: string;
@@ -121,55 +134,4 @@ declare const subscribeWaaPIframeLifecycle: (listener: (event: WaaPIframeLifecyc
121
134
  */
122
135
  declare const getWaaPIframeDiagnostics: () => WaaPIframeDiagnostics;
123
136
  //#endregion
124
- //#region src/lib/preload.d.ts
125
- /** Any public WaaP facade that can warm the shared wallet iframe. */
126
- interface WaaPPreloadTarget {
127
- preload(): Promise<void>;
128
- }
129
- interface WaaPIdlePreloadOptions {
130
- /** Browser deadline for an idle callback. Default: 2 seconds. */
131
- timeoutMs?: number;
132
- /** Observes a best-effort warmup failure without making page startup fail. */
133
- onError?: (error: unknown) => void;
134
- }
135
- type CancelWaaPPreload = () => void;
136
- /**
137
- * Warm an already-created WaaP facade when the browser is idle. It never opens
138
- * wallet UI, and cancellation is useful when the embedding route unmounts.
139
- *
140
- * Use this after the host page's LCP. For a likely immediate action (for
141
- * example Connect button hover/focus), call `target.preload()` directly.
142
- */
143
- declare const preloadWaaPOnIdle: (target: WaaPPreloadTarget, options?: WaaPIdlePreloadOptions) => CancelWaaPPreload;
144
- //#endregion
145
- //#region src/lib/WaaPError.d.ts
146
- /** Stable, safe error vocabulary for non-EIP-1193 SDK facades. */
147
- type WaaPErrorCode = 'cancelled' | 'timeout' | 'user_rejected' | 'policy_rejected' |
148
- /**
149
- * The user's gas tank cannot cover a fee the operation is billed. Distinct
150
- * from `wallet_error` because it is the user's to fix and retrying changes
151
- * nothing until they top up — the same split the server draws between a 402
152
- * and a 502.
153
- */
154
- 'insufficient_balance' | 'not_authenticated' | 'not_connected' | 'unsupported_input' | 'wallet_error' | 'maintenance' | 'unknown';
155
- type WaaPOperationMetadata = {
156
- /**
157
- * The chain the failed operation targeted. Declared structurally rather than
158
- * as `WaaPChain` so the error vocabulary stays free of the initializer graph.
159
- */
160
- chain?: 'evm' | 'sui' | 'solana';
161
- method?: string;
162
- requestId?: string;
163
- };
164
- declare class WaaPError extends Error {
165
- readonly code: WaaPErrorCode;
166
- readonly operation?: WaaPOperationMetadata;
167
- readonly cause?: unknown;
168
- constructor(code: WaaPErrorCode, message: string, options?: {
169
- cause?: unknown;
170
- operation?: WaaPOperationMetadata;
171
- });
172
- }
173
- declare function normalizeWaaPError(error: unknown, operation?: WaaPOperationMetadata): WaaPError;
174
- //#endregion
175
- export { CancelWaaPPreload as a, preloadWaaPOnIdle as c, WaaPIframeLifecyclePhase as d, getWaaPIframeDiagnostics as f, WalletMessageManager as h, normalizeWaaPError as i, WaaPIframeDiagnostics as l, PostSilkRequestArgs as m, WaaPErrorCode as n, WaaPIdlePreloadOptions as o, subscribeWaaPIframeLifecycle as p, WaaPOperationMetadata as r, WaaPPreloadTarget as s, WaaPError as t, WaaPIframeLifecycleEvent as u };
137
+ export { subscribeWaaPIframeLifecycle as a, getWaaPIframeDiagnostics as i, WaaPIframeLifecycleEvent as n, PostSilkRequestArgs as o, WaaPIframeLifecyclePhase as r, WalletMessageManager as s, WaaPIframeDiagnostics as t };
@@ -0,0 +1,158 @@
1
+ import { F as WaaPSdkPlatform, l as SilkEthereumProviderInterface, n as InitSilkOptions } from "./types-Cc6tc4ut.mjs";
2
+ import { i as getWaaPIframeDiagnostics } from "./WalletModalController-DxiBiqDf.mjs";
3
+ import { y as WaaPSolanaProviderInterface } from "./types-C7JDjWnt.mjs";
4
+ //#region src/lib/bridge/mobileBridge.d.ts
5
+ type MobileBridgeOptions = {
6
+ /** Serialized outbound envelopes, host-bound. */
7
+ post: (message: string) => void;
8
+ /**
9
+ * Deferred so the WebView can load the bridge page before the wallet iframe
10
+ * is mounted, and so tests can drive a stub provider.
11
+ */
12
+ createProvider: () => SilkEthereumProviderInterface;
13
+ /**
14
+ * The Solana facade over the same wallet iframe. Optional so a host that only
15
+ * needs EVM -- and every existing test -- keeps working unchanged.
16
+ */
17
+ createSolanaProvider?: () => WaaPSolanaProviderInterface;
18
+ /**
19
+ * Stamped on every outbound message so the host can tell this frame apart
20
+ * from the cross-origin frames that share its JavaScript channel. See
21
+ * `BridgeResponse['token']`.
22
+ */
23
+ token?: string;
24
+ };
25
+ type MobileBridge = {
26
+ handleMessage: (raw: unknown) => void;
27
+ dispose: () => void;
28
+ };
29
+ declare const createMobileBridge: (options: MobileBridgeOptions) => MobileBridge;
30
+ //#endregion
31
+ //#region src/lib/bridge/evmMethods.d.ts
32
+ /**
33
+ * The EIP-1193 methods `evm.request` may forward.
34
+ *
35
+ * `SILK_METHOD` is not usable as the allowlist: it also carries portal-admin
36
+ * and wallet-configuration methods (`project_init`, `gastank_topup`,
37
+ * `customization_update`, `set_project`, `set_custom_config`) that a native
38
+ * application must never be able to reach through the escape hatch. The list is
39
+ * enumerated rather than derived from an `eth_`/`wallet_` prefix so adding a
40
+ * method to the enum cannot silently widen the native surface.
41
+ */
42
+ declare const BRIDGE_EVM_METHODS: readonly string[];
43
+ //#endregion
44
+ //#region src/lib/bridge/protocol.d.ts
45
+ /**
46
+ * Wire protocol between a native host (Flutter/Dart) and the browser SDK
47
+ * running in a WebView bridge page.
48
+ *
49
+ * The host is untrusted input. Every inbound message is parsed defensively and
50
+ * anything that is not a well-formed request for a known method is refused
51
+ * without reaching the SDK.
52
+ */
53
+ declare const BRIDGE_PROTOCOL_VERSION = 1;
54
+ type BridgeMethod = 'session.login' | 'session.logout' | 'session.status' | 'evm.connect' | 'evm.request' | 'solana.connect' | 'solana.disconnect' | 'solana.accounts' | 'solana.signMessage' | 'solana.signTransaction' | 'solana.signAndSendTransaction' | 'sdk.preload' | 'sdk.destroy';
55
+ /**
56
+ * Codes the Dart layer switches on. They are deliberately not the SDK's
57
+ * `WaaPErrorCode` values: the native surface owns its own stable vocabulary and
58
+ * must not break when the SDK's internal codes are extended.
59
+ */
60
+ type BridgeErrorCode = 'cancelled' | 'timeout' | 'userRejected' | 'policyRejected' | 'insufficientBalance' | 'notAuthenticated' | 'notConnected' | 'unsupportedInput' | 'unsupportedMethod' | 'walletError' | 'maintenance' | 'protocolError' | 'bridgeUnavailable' | 'serializationFailed' | 'unknown';
61
+ type BridgeError = {
62
+ code: BridgeErrorCode;
63
+ message: string;
64
+ /** Present only when the wallet supplied an EIP-1193 numeric code. */
65
+ eip1193Code?: number;
66
+ method?: string;
67
+ };
68
+ type BridgeRequest = {
69
+ version: number;
70
+ kind: 'request';
71
+ id: string;
72
+ method: BridgeMethod;
73
+ params?: unknown;
74
+ };
75
+ /**
76
+ * `token` authenticates the sender as the bridge page's main frame.
77
+ *
78
+ * A WebView JavaScript channel is not origin-scoped. On Android it is backed by
79
+ * `addJavascriptInterface`, which injects the object into *every* frame and
80
+ * tells the host nothing about which one called — and this page deliberately
81
+ * contains the wallet, cross-origin, which in turn loads third-party login
82
+ * frames. Any of them could otherwise post a forged `accountsChanged` or a
83
+ * forged `session.status` response straight to the native layer.
84
+ *
85
+ * The host mints a secret per page load and hands it to the main frame only.
86
+ * A cross-origin subframe cannot read a main-frame variable, so it cannot
87
+ * produce this value, and the host drops anything that arrives without it.
88
+ */
89
+ type BridgeResponse = {
90
+ version: number;
91
+ kind: 'response';
92
+ id: string;
93
+ result?: unknown;
94
+ error?: BridgeError;
95
+ token?: string;
96
+ };
97
+ type BridgeEvent = {
98
+ version: number;
99
+ kind: 'event';
100
+ event: string;
101
+ data?: unknown;
102
+ token?: string;
103
+ };
104
+ type ParsedHostMessage = {
105
+ ok: true;
106
+ request: BridgeRequest;
107
+ } | {
108
+ ok: false;
109
+ id: string | null;
110
+ error: BridgeError;
111
+ };
112
+ declare const parseHostMessage: (raw: unknown) => ParsedHostMessage;
113
+ //#endregion
114
+ //#region src/bridge.d.ts
115
+ type NativeHostWindow = Window & {
116
+ ReactNativeWebView?: {
117
+ postMessage: (message: string) => void;
118
+ };
119
+ webkit?: {
120
+ messageHandlers?: Record<string, {
121
+ postMessage: (message: string) => void;
122
+ }>;
123
+ };
124
+ [channel: string]: unknown;
125
+ };
126
+ /**
127
+ * Resolve the host channel this WebView exposes. `channel` names the JavaScript
128
+ * interface on Android and the message handler on iOS; both are installed by
129
+ * the native layer before the page loads.
130
+ */
131
+ declare const resolveNativeHostPost: (channel?: string, scope?: NativeHostWindow) => ((message: string) => void) | null;
132
+ type StartMobileBridgeOptions = {
133
+ init?: InitSilkOptions;
134
+ channel?: string;
135
+ post?: (message: string) => void;
136
+ /**
137
+ * Secret the host minted for this page load, echoed on every outbound
138
+ * message. The channel is shared with every frame in the WebView, including
139
+ * the cross-origin wallet; this is what distinguishes this frame from them.
140
+ */
141
+ token?: string;
142
+ /**
143
+ * The SDK actually facing the integrator. This bundle is compiled into
144
+ * `waap-sdk-flutter`, so a Flutter session would otherwise report itself as
145
+ * the web SDK, at the web SDK's version. Attribution only.
146
+ */
147
+ sdkPlatform?: WaaPSdkPlatform;
148
+ sdkVersion?: string;
149
+ };
150
+ /**
151
+ * Wire the bridge to the WebView host and begin accepting host messages.
152
+ *
153
+ * Throws when no host channel is present rather than falling back to a no-op:
154
+ * a silently deaf bridge would leave every native call pending forever.
155
+ */
156
+ declare const startMobileBridge: (options?: StartMobileBridgeOptions) => MobileBridge;
157
+ //#endregion
158
+ export { BRIDGE_EVM_METHODS, BRIDGE_PROTOCOL_VERSION, type BridgeError, type BridgeErrorCode, type BridgeEvent, type BridgeMethod, type BridgeRequest, type BridgeResponse, type MobileBridge, type MobileBridgeOptions, StartMobileBridgeOptions, createMobileBridge, getWaaPIframeDiagnostics, parseHostMessage, resolveNativeHostPost, startMobileBridge };
@@ -0,0 +1,158 @@
1
+ import { F as WaaPSdkPlatform, l as SilkEthereumProviderInterface, n as InitSilkOptions } from "./types-Cc6tc4ut.js";
2
+ import { i as getWaaPIframeDiagnostics } from "./WalletModalController-16mHsFv2.js";
3
+ import { y as WaaPSolanaProviderInterface } from "./types-Bj5dDE-C.js";
4
+ //#region src/lib/bridge/mobileBridge.d.ts
5
+ type MobileBridgeOptions = {
6
+ /** Serialized outbound envelopes, host-bound. */
7
+ post: (message: string) => void;
8
+ /**
9
+ * Deferred so the WebView can load the bridge page before the wallet iframe
10
+ * is mounted, and so tests can drive a stub provider.
11
+ */
12
+ createProvider: () => SilkEthereumProviderInterface;
13
+ /**
14
+ * The Solana facade over the same wallet iframe. Optional so a host that only
15
+ * needs EVM -- and every existing test -- keeps working unchanged.
16
+ */
17
+ createSolanaProvider?: () => WaaPSolanaProviderInterface;
18
+ /**
19
+ * Stamped on every outbound message so the host can tell this frame apart
20
+ * from the cross-origin frames that share its JavaScript channel. See
21
+ * `BridgeResponse['token']`.
22
+ */
23
+ token?: string;
24
+ };
25
+ type MobileBridge = {
26
+ handleMessage: (raw: unknown) => void;
27
+ dispose: () => void;
28
+ };
29
+ declare const createMobileBridge: (options: MobileBridgeOptions) => MobileBridge;
30
+ //#endregion
31
+ //#region src/lib/bridge/evmMethods.d.ts
32
+ /**
33
+ * The EIP-1193 methods `evm.request` may forward.
34
+ *
35
+ * `SILK_METHOD` is not usable as the allowlist: it also carries portal-admin
36
+ * and wallet-configuration methods (`project_init`, `gastank_topup`,
37
+ * `customization_update`, `set_project`, `set_custom_config`) that a native
38
+ * application must never be able to reach through the escape hatch. The list is
39
+ * enumerated rather than derived from an `eth_`/`wallet_` prefix so adding a
40
+ * method to the enum cannot silently widen the native surface.
41
+ */
42
+ declare const BRIDGE_EVM_METHODS: readonly string[];
43
+ //#endregion
44
+ //#region src/lib/bridge/protocol.d.ts
45
+ /**
46
+ * Wire protocol between a native host (Flutter/Dart) and the browser SDK
47
+ * running in a WebView bridge page.
48
+ *
49
+ * The host is untrusted input. Every inbound message is parsed defensively and
50
+ * anything that is not a well-formed request for a known method is refused
51
+ * without reaching the SDK.
52
+ */
53
+ declare const BRIDGE_PROTOCOL_VERSION = 1;
54
+ type BridgeMethod = 'session.login' | 'session.logout' | 'session.status' | 'evm.connect' | 'evm.request' | 'solana.connect' | 'solana.disconnect' | 'solana.accounts' | 'solana.signMessage' | 'solana.signTransaction' | 'solana.signAndSendTransaction' | 'sdk.preload' | 'sdk.destroy';
55
+ /**
56
+ * Codes the Dart layer switches on. They are deliberately not the SDK's
57
+ * `WaaPErrorCode` values: the native surface owns its own stable vocabulary and
58
+ * must not break when the SDK's internal codes are extended.
59
+ */
60
+ type BridgeErrorCode = 'cancelled' | 'timeout' | 'userRejected' | 'policyRejected' | 'insufficientBalance' | 'notAuthenticated' | 'notConnected' | 'unsupportedInput' | 'unsupportedMethod' | 'walletError' | 'maintenance' | 'protocolError' | 'bridgeUnavailable' | 'serializationFailed' | 'unknown';
61
+ type BridgeError = {
62
+ code: BridgeErrorCode;
63
+ message: string;
64
+ /** Present only when the wallet supplied an EIP-1193 numeric code. */
65
+ eip1193Code?: number;
66
+ method?: string;
67
+ };
68
+ type BridgeRequest = {
69
+ version: number;
70
+ kind: 'request';
71
+ id: string;
72
+ method: BridgeMethod;
73
+ params?: unknown;
74
+ };
75
+ /**
76
+ * `token` authenticates the sender as the bridge page's main frame.
77
+ *
78
+ * A WebView JavaScript channel is not origin-scoped. On Android it is backed by
79
+ * `addJavascriptInterface`, which injects the object into *every* frame and
80
+ * tells the host nothing about which one called — and this page deliberately
81
+ * contains the wallet, cross-origin, which in turn loads third-party login
82
+ * frames. Any of them could otherwise post a forged `accountsChanged` or a
83
+ * forged `session.status` response straight to the native layer.
84
+ *
85
+ * The host mints a secret per page load and hands it to the main frame only.
86
+ * A cross-origin subframe cannot read a main-frame variable, so it cannot
87
+ * produce this value, and the host drops anything that arrives without it.
88
+ */
89
+ type BridgeResponse = {
90
+ version: number;
91
+ kind: 'response';
92
+ id: string;
93
+ result?: unknown;
94
+ error?: BridgeError;
95
+ token?: string;
96
+ };
97
+ type BridgeEvent = {
98
+ version: number;
99
+ kind: 'event';
100
+ event: string;
101
+ data?: unknown;
102
+ token?: string;
103
+ };
104
+ type ParsedHostMessage = {
105
+ ok: true;
106
+ request: BridgeRequest;
107
+ } | {
108
+ ok: false;
109
+ id: string | null;
110
+ error: BridgeError;
111
+ };
112
+ declare const parseHostMessage: (raw: unknown) => ParsedHostMessage;
113
+ //#endregion
114
+ //#region src/bridge.d.ts
115
+ type NativeHostWindow = Window & {
116
+ ReactNativeWebView?: {
117
+ postMessage: (message: string) => void;
118
+ };
119
+ webkit?: {
120
+ messageHandlers?: Record<string, {
121
+ postMessage: (message: string) => void;
122
+ }>;
123
+ };
124
+ [channel: string]: unknown;
125
+ };
126
+ /**
127
+ * Resolve the host channel this WebView exposes. `channel` names the JavaScript
128
+ * interface on Android and the message handler on iOS; both are installed by
129
+ * the native layer before the page loads.
130
+ */
131
+ declare const resolveNativeHostPost: (channel?: string, scope?: NativeHostWindow) => ((message: string) => void) | null;
132
+ type StartMobileBridgeOptions = {
133
+ init?: InitSilkOptions;
134
+ channel?: string;
135
+ post?: (message: string) => void;
136
+ /**
137
+ * Secret the host minted for this page load, echoed on every outbound
138
+ * message. The channel is shared with every frame in the WebView, including
139
+ * the cross-origin wallet; this is what distinguishes this frame from them.
140
+ */
141
+ token?: string;
142
+ /**
143
+ * The SDK actually facing the integrator. This bundle is compiled into
144
+ * `waap-sdk-flutter`, so a Flutter session would otherwise report itself as
145
+ * the web SDK, at the web SDK's version. Attribution only.
146
+ */
147
+ sdkPlatform?: WaaPSdkPlatform;
148
+ sdkVersion?: string;
149
+ };
150
+ /**
151
+ * Wire the bridge to the WebView host and begin accepting host messages.
152
+ *
153
+ * Throws when no host channel is present rather than falling back to a no-op:
154
+ * a silently deaf bridge would leave every native call pending forever.
155
+ */
156
+ declare const startMobileBridge: (options?: StartMobileBridgeOptions) => MobileBridge;
157
+ //#endregion
158
+ export { BRIDGE_EVM_METHODS, BRIDGE_PROTOCOL_VERSION, type BridgeError, type BridgeErrorCode, type BridgeEvent, type BridgeMethod, type BridgeRequest, type BridgeResponse, type MobileBridge, type MobileBridgeOptions, StartMobileBridgeOptions, createMobileBridge, getWaaPIframeDiagnostics, parseHostMessage, resolveNativeHostPost, startMobileBridge };
package/dist/bridge.js ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./UIMessageManager-D-OTya1E.js"),t=require("./asyncSigning-B0KrmKk7.js"),n=require("./SolanaProvider-BdeBP_ro.js"),r=require("./evm-rUSuf-iy.js"),i=[e.w.eth_requestAccounts,e.w.eth_accounts,e.w.eth_sendTransaction,e.w.eth_signTransaction,e.w.eth_getBalance,e.w.personal_sign,e.w.eth_signTypedData_v4,e.w.eth_chainId,e.w.net_version,e.w.wallet_switchEthereumChain,e.w.wallet_addEthereumChain,e.w.eth_estimateGas,e.w.eth_blockNumber,e.w.eth_getCode,e.w.eth_call,e.w.eth_getTransactionReceipt,e.w.eth_getTransactionByHash],a=new Set(i),o=e=>typeof e==`string`&&a.has(e),s=[`session.login`,`session.logout`,`session.status`,`evm.connect`,`evm.request`,`solana.connect`,`solana.disconnect`,`solana.accounts`,`solana.signMessage`,`solana.signTransaction`,`solana.signAndSendTransaction`,`sdk.preload`,`sdk.destroy`],c=e=>typeof e==`string`&&s.includes(e),l=(e,t,n=`protocolError`)=>({ok:!1,id:e,error:{code:n,message:t}}),u=e=>typeof e==`object`&&!!e&&!Array.isArray(e),d=e=>u(e)&&typeof e.id==`string`&&e.id.length>0?e.id:null,f=e=>{let t=e;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return l(null,`Message is not valid JSON`)}if(!u(t))return l(null,`Message must be a JSON object`);let n=d(t);return t.version===1?t.kind===`request`?n?c(t.method)?{ok:!0,request:{version:1,kind:`request`,id:n,method:t.method,params:t.params}}:{ok:!1,id:n,error:{code:`unsupportedMethod`,message:`Unsupported bridge method: ${String(t.method)}`,method:typeof t.method==`string`?t.method:void 0}}:l(null,`Request id must be a non-empty string`):l(n,`Unsupported message kind: ${String(t.kind)}`):l(n,`Unsupported protocol version: ${String(t.version)}`)},p=(e,t)=>({version:1,kind:`response`,id:e,result:t}),m=(e,t)=>({version:1,kind:`response`,id:e,error:t}),h=(e,t)=>({version:1,kind:`event`,event:e,data:t}),g=e=>JSON.stringify(e,(e,t)=>typeof t==`bigint`?t.toString():t),_={cancelled:`cancelled`,timeout:`timeout`,user_rejected:`userRejected`,policy_rejected:`policyRejected`,insufficient_balance:`insufficientBalance`,not_authenticated:`notAuthenticated`,not_connected:`notConnected`,unsupported_input:`unsupportedInput`,wallet_error:`walletError`,maintenance:`maintenance`,unknown:`unknown`},v=[`connect`,`disconnect`,`accountsChanged`,`chainChanged`,...Object.values(t.t)],y=e=>{if(typeof e!=`object`||!e)return;let t=e.code;return typeof t==`number`?t:void 0},b=(t,n)=>{let r=e.S(t),i=y(r.cause??t);return{code:_[r.code]??`unknown`,message:r.message,...i===void 0?{}:{eip1193Code:i},...n?{method:n}:{}}},x=e=>{let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t)},S=(e,t)=>{if(typeof e!=`string`)throw{bridgeError:{code:`unsupportedInput`,message:`${t} must be a base64 string`}};let n=atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e+=1)r[e]=n.charCodeAt(e);return r},C=e=>({address:e.address,publicKey:x(e.publicKey),chains:[...e.chains]}),w=[`solana:mainnet`,`solana:devnet`,`solana:testnet`,`solana:localnet`],T=e=>{if(e!=null){if(typeof e==`string`&&w.includes(e))return e;throw{bridgeError:{code:`unsupportedInput`,message:`Not a supported Solana chain: ${String(e)}`}}}},E=t=>{let{post:n,createProvider:r,createSolanaProvider:i,token:a}=t,s=null,c=!1,l=new Set,u=[],d=e=>{try{n(e)}catch{}},_=e=>a?{...e,token:a}:e,y=e=>{let t;try{t=g(_(e))}catch(n){let r=n instanceof Error?n.message:String(n);t=g(_(e.kind===`response`?m(e.id,{code:`serializationFailed`,message:`Result could not be serialized for the host: ${r}`}):h(`bridgeSerializationError`,{event:e.event,message:r})))}d(t)},w=e=>{for(let t of v){let n=(...e)=>y(h(t,e.length<=1?e[0]:e));e.on(t,n),u.push([t,n])}},E=e=>{let t=e.uiMessageManager;typeof t?.on==`function`&&(t.on(`show_modal`,()=>y(h(`walletVisibilityChanged`,{visible:!0}))),t.on(`hide_modal`,()=>y(h(`walletVisibilityChanged`,{visible:!1}))))},D=null,O=null,k=t=>{let n=t.walletMessageManager;if(n){if(typeof n.pingIframe!=`function`||typeof n.postSilkRequest!=`function`){y(h(`bridgeProtocolError`,{code:`walletError`,message:`Cannot announce mobile: the wallet message manager is missing pingIframe or postSilkRequest`}));return}O=n.pingIframe().then(()=>n.postSilkRequest?.({method:e.w.set_is_mobile,params:[!0],interactionRequired:!1})).then(()=>void 0).catch(e=>{y(h(`bridgeProtocolError`,{code:`walletError`,message:`Could not tell the wallet it is on mobile: ${String(e)}`}))})}},A=e=>{let t=e.walletMessageManager;typeof t?.addListener==`function`&&t.addListener({onAuthComplete:async e=>{let t=D;if(t){if(D=null,e===`success`){try{await F().request({method:`eth_requestAccounts`})}catch(e){y(h(`bridgeProtocolError`,{code:`walletError`,message:`Login completed but accounts could not be read: ${String(e)}`}))}M(`waap`)}t(e===`success`?`waap`:null)}}})},j=null,M=e=>{j?.setLoginMethod(e)},N=()=>{if(!i)throw{bridgeError:{code:`unsupportedMethod`,message:`This bridge was built without a Solana facade`}};if(!j){let e=F();j=i(),M(e.getLoginMethod())}return j},P=e=>{let t=N().accounts;if(t.length===0)throw{bridgeError:{code:`notConnected`,message:`Connect the Solana facade before signing`}};if(typeof e!=`string`||e.length===0)return t[0];let n=t.find(t=>t.address===e);if(!n)throw{bridgeError:{code:`unsupportedInput`,message:`Not a connected Solana account: ${e}`}};return n},F=()=>(s||(s=r(),w(s),E(s),A(s),k(s)),s),I=async e=>{let t=typeof e.params==`object`&&e.params!==null?e.params:{};switch(e.method){case`sdk.preload`:return await F().preload(),null;case`sdk.destroy`:return R(e.id),null;case`session.login`:{F(),await O;let e=F(),n=e.loginWithNativeHandoff;if(typeof n!=`function`)throw{bridgeError:{code:`walletError`,message:`This provider cannot report a native auth hand-off; social login would silently do nothing`,method:`session.login`}};let r=await n.call(e,{force:t.force===!0});if(typeof r==`object`&&r&&r.isComplete===!1&&typeof r.authUrl==`string`)return y(h(`nativeAuthRequested`,{authUrl:r.authUrl})),await new Promise((e,t)=>{D?.(null);let n=setTimeout(()=>{D=null,t({bridgeError:{code:`timeout`,message:`The social login was not completed. The browser may have been dismissed before it finished.`,method:`session.login`}})},18e4);D=t=>{clearTimeout(n),e(t)}});let i=typeof r==`object`&&r?r.loginMethod??null:r;return M(i),i}case`session.logout`:return await F().logout(),M(null),null;case`session.status`:return F().session.getAccountStatus();case`evm.connect`:return F().request({method:`eth_requestAccounts`});case`solana.connect`:return{accounts:(await N().connect(t.silent===!0?{silent:!0}:void 0)).accounts.map(C)};case`solana.disconnect`:return await N().disconnect(),null;case`solana.accounts`:return{accounts:N().accounts.map(C)};case`solana.signMessage`:{let e=P(t.address),n=await N().signMessage({message:S(t.message,`message`),account:e});return{signedMessage:x(n.signedMessage),signature:x(n.signature)}}case`solana.signTransaction`:{let e=P(t.address),n=T(t.chain),r=await N().signTransaction({transaction:S(t.transaction,`transaction`),account:e,...n===void 0?{}:{chain:n}});return{signedTransaction:x(r.signedTransaction),signature:x(r.signature)}}case`solana.signAndSendTransaction`:{let e=P(t.address),n=T(t.chain);return{signature:(await N().signAndSendTransaction({transaction:S(t.transaction,`transaction`),account:e,...n===void 0?{}:{chain:n}})).signature}}case`evm.request`:if(!o(t.method))throw{bridgeError:{code:`unsupportedMethod`,message:`Method is not available to native callers: ${String(t.method)}`,method:typeof t.method==`string`?t.method:void 0}};return F().request({method:t.method,params:t.params})}},L=(e,t)=>{l.delete(e)&&y(t)},R=e=>{D?.(null),D=null;for(let t of[...l])t!==e&&L(t,m(t,{code:`bridgeUnavailable`,message:`Bridge was destroyed while this request was in flight`}));if(s){for(let[e,t]of u)s.removeListener(e,t);u.length=0;let e=s.destroy;typeof e==`function`&&e.call(s),s=null}j&&=(j.destroy(),null),c=!0};return{handleMessage:e=>{let t=f(e);if(!t.ok){t.id?y(m(t.id,t.error)):y(h(`bridgeProtocolError`,t.error));return}let{request:n}=t;if(c){y(m(n.id,{code:`bridgeUnavailable`,message:`Bridge has been destroyed`}));return}if(l.has(n.id)){y(h(`bridgeProtocolError`,{code:`protocolError`,message:`Request id is already in flight: ${n.id}`,id:n.id,method:n.method}));return}l.add(n.id),(async()=>{try{L(n.id,p(n.id,await I(n)))}catch(e){let t=e?.bridgeError;L(n.id,m(n.id,t??b(e,n.method)))}})()},dispose:()=>R()}},D=(e=`WaaPBridge`,t=window)=>{let n=t[e];if(typeof n?.postMessage==`function`)return e=>n.postMessage(e);let r=t.webkit?.messageHandlers?.[e];return typeof r?.postMessage==`function`?e=>r.postMessage(e):typeof t.ReactNativeWebView?.postMessage==`function`?e=>t.ReactNativeWebView.postMessage(e):null},O=(t={})=>{t.sdkPlatform&&e.p(t.sdkPlatform,t.sdkVersion??`unknown`);let i=t.post??D(t.channel);if(!i)throw Error(`[WaaP bridge] No native host channel found. The WebView must install one before loading the bridge page.`);let a={...t.init??{},deferIframe:!1},o=()=>(e.g(a),e.h(`tap`).contentWindow),s=null,c=E({post:i,token:t.token,createProvider:()=>r.n(a,`tap`,!0,[`evm`,`solana`],!1),createSolanaProvider:()=>(s??=new n.t(o(),a,o,{...a,chains:[`solana`]},!1),s.setAccountMode?.(`tap`),s)});return window.__waapBridgeReceive=e=>c.handleMessage(e),c};exports.BRIDGE_EVM_METHODS=i,exports.BRIDGE_PROTOCOL_VERSION=1,exports.createMobileBridge=E,exports.getWaaPIframeDiagnostics=e.s,exports.parseHostMessage=f,exports.resolveNativeHostPost=D,exports.startMobileBridge=O;
@@ -0,0 +1 @@
1
+ import{S as e,g as t,h as n,p as r,s as i,w as a}from"./UIMessageManager-CtnIZgIY.mjs";import{t as o}from"./asyncSigning-CzqBbYDP.mjs";import{t as s}from"./SolanaProvider-DP9J8JuJ.mjs";import{n as c}from"./evm-dDMLwSQe.mjs";const l=[a.eth_requestAccounts,a.eth_accounts,a.eth_sendTransaction,a.eth_signTransaction,a.eth_getBalance,a.personal_sign,a.eth_signTypedData_v4,a.eth_chainId,a.net_version,a.wallet_switchEthereumChain,a.wallet_addEthereumChain,a.eth_estimateGas,a.eth_blockNumber,a.eth_getCode,a.eth_call,a.eth_getTransactionReceipt,a.eth_getTransactionByHash],u=new Set(l),d=e=>typeof e==`string`&&u.has(e),f=1,p=[`session.login`,`session.logout`,`session.status`,`evm.connect`,`evm.request`,`solana.connect`,`solana.disconnect`,`solana.accounts`,`solana.signMessage`,`solana.signTransaction`,`solana.signAndSendTransaction`,`sdk.preload`,`sdk.destroy`],m=e=>typeof e==`string`&&p.includes(e),h=(e,t,n=`protocolError`)=>({ok:!1,id:e,error:{code:n,message:t}}),g=e=>typeof e==`object`&&!!e&&!Array.isArray(e),_=e=>g(e)&&typeof e.id==`string`&&e.id.length>0?e.id:null,v=e=>{let t=e;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return h(null,`Message is not valid JSON`)}if(!g(t))return h(null,`Message must be a JSON object`);let n=_(t);return t.version===1?t.kind===`request`?n?m(t.method)?{ok:!0,request:{version:1,kind:`request`,id:n,method:t.method,params:t.params}}:{ok:!1,id:n,error:{code:`unsupportedMethod`,message:`Unsupported bridge method: ${String(t.method)}`,method:typeof t.method==`string`?t.method:void 0}}:h(null,`Request id must be a non-empty string`):h(n,`Unsupported message kind: ${String(t.kind)}`):h(n,`Unsupported protocol version: ${String(t.version)}`)},y=(e,t)=>({version:1,kind:`response`,id:e,result:t}),b=(e,t)=>({version:1,kind:`response`,id:e,error:t}),x=(e,t)=>({version:1,kind:`event`,event:e,data:t}),S=e=>JSON.stringify(e,(e,t)=>typeof t==`bigint`?t.toString():t),C={cancelled:`cancelled`,timeout:`timeout`,user_rejected:`userRejected`,policy_rejected:`policyRejected`,insufficient_balance:`insufficientBalance`,not_authenticated:`notAuthenticated`,not_connected:`notConnected`,unsupported_input:`unsupportedInput`,wallet_error:`walletError`,maintenance:`maintenance`,unknown:`unknown`},w=[`connect`,`disconnect`,`accountsChanged`,`chainChanged`,...Object.values(o)],T=e=>{if(typeof e!=`object`||!e)return;let t=e.code;return typeof t==`number`?t:void 0},E=(t,n)=>{let r=e(t),i=T(r.cause??t);return{code:C[r.code]??`unknown`,message:r.message,...i===void 0?{}:{eip1193Code:i},...n?{method:n}:{}}},D=e=>{let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t)},O=(e,t)=>{if(typeof e!=`string`)throw{bridgeError:{code:`unsupportedInput`,message:`${t} must be a base64 string`}};let n=atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e+=1)r[e]=n.charCodeAt(e);return r},k=e=>({address:e.address,publicKey:D(e.publicKey),chains:[...e.chains]}),A=[`solana:mainnet`,`solana:devnet`,`solana:testnet`,`solana:localnet`],j=e=>{if(e!=null){if(typeof e==`string`&&A.includes(e))return e;throw{bridgeError:{code:`unsupportedInput`,message:`Not a supported Solana chain: ${String(e)}`}}}},M=e=>{let{post:t,createProvider:n,createSolanaProvider:r,token:i}=e,o=null,s=!1,c=new Set,l=[],u=e=>{try{t(e)}catch{}},f=e=>i?{...e,token:i}:e,p=e=>{let t;try{t=S(f(e))}catch(n){let r=n instanceof Error?n.message:String(n);t=S(f(e.kind===`response`?b(e.id,{code:`serializationFailed`,message:`Result could not be serialized for the host: ${r}`}):x(`bridgeSerializationError`,{event:e.event,message:r})))}u(t)},m=e=>{for(let t of w){let n=(...e)=>p(x(t,e.length<=1?e[0]:e));e.on(t,n),l.push([t,n])}},h=e=>{let t=e.uiMessageManager;typeof t?.on==`function`&&(t.on(`show_modal`,()=>p(x(`walletVisibilityChanged`,{visible:!0}))),t.on(`hide_modal`,()=>p(x(`walletVisibilityChanged`,{visible:!1}))))},g=null,_=null,C=e=>{let t=e.walletMessageManager;if(t){if(typeof t.pingIframe!=`function`||typeof t.postSilkRequest!=`function`){p(x(`bridgeProtocolError`,{code:`walletError`,message:`Cannot announce mobile: the wallet message manager is missing pingIframe or postSilkRequest`}));return}_=t.pingIframe().then(()=>t.postSilkRequest?.({method:a.set_is_mobile,params:[!0],interactionRequired:!1})).then(()=>void 0).catch(e=>{p(x(`bridgeProtocolError`,{code:`walletError`,message:`Could not tell the wallet it is on mobile: ${String(e)}`}))})}},T=e=>{let t=e.walletMessageManager;typeof t?.addListener==`function`&&t.addListener({onAuthComplete:async e=>{let t=g;if(t){if(g=null,e===`success`){try{await F().request({method:`eth_requestAccounts`})}catch(e){p(x(`bridgeProtocolError`,{code:`walletError`,message:`Login completed but accounts could not be read: ${String(e)}`}))}M(`waap`)}t(e===`success`?`waap`:null)}}})},A=null,M=e=>{A?.setLoginMethod(e)},N=()=>{if(!r)throw{bridgeError:{code:`unsupportedMethod`,message:`This bridge was built without a Solana facade`}};if(!A){let e=F();A=r(),M(e.getLoginMethod())}return A},P=e=>{let t=N().accounts;if(t.length===0)throw{bridgeError:{code:`notConnected`,message:`Connect the Solana facade before signing`}};if(typeof e!=`string`||e.length===0)return t[0];let n=t.find(t=>t.address===e);if(!n)throw{bridgeError:{code:`unsupportedInput`,message:`Not a connected Solana account: ${e}`}};return n},F=()=>(o||(o=n(),m(o),h(o),T(o),C(o)),o),I=async e=>{let t=typeof e.params==`object`&&e.params!==null?e.params:{};switch(e.method){case`sdk.preload`:return await F().preload(),null;case`sdk.destroy`:return R(e.id),null;case`session.login`:{F(),await _;let e=F(),n=e.loginWithNativeHandoff;if(typeof n!=`function`)throw{bridgeError:{code:`walletError`,message:`This provider cannot report a native auth hand-off; social login would silently do nothing`,method:`session.login`}};let r=await n.call(e,{force:t.force===!0});if(typeof r==`object`&&r&&r.isComplete===!1&&typeof r.authUrl==`string`)return p(x(`nativeAuthRequested`,{authUrl:r.authUrl})),await new Promise((e,t)=>{g?.(null);let n=setTimeout(()=>{g=null,t({bridgeError:{code:`timeout`,message:`The social login was not completed. The browser may have been dismissed before it finished.`,method:`session.login`}})},18e4);g=t=>{clearTimeout(n),e(t)}});let i=typeof r==`object`&&r?r.loginMethod??null:r;return M(i),i}case`session.logout`:return await F().logout(),M(null),null;case`session.status`:return F().session.getAccountStatus();case`evm.connect`:return F().request({method:`eth_requestAccounts`});case`solana.connect`:return{accounts:(await N().connect(t.silent===!0?{silent:!0}:void 0)).accounts.map(k)};case`solana.disconnect`:return await N().disconnect(),null;case`solana.accounts`:return{accounts:N().accounts.map(k)};case`solana.signMessage`:{let e=P(t.address),n=await N().signMessage({message:O(t.message,`message`),account:e});return{signedMessage:D(n.signedMessage),signature:D(n.signature)}}case`solana.signTransaction`:{let e=P(t.address),n=j(t.chain),r=await N().signTransaction({transaction:O(t.transaction,`transaction`),account:e,...n===void 0?{}:{chain:n}});return{signedTransaction:D(r.signedTransaction),signature:D(r.signature)}}case`solana.signAndSendTransaction`:{let e=P(t.address),n=j(t.chain);return{signature:(await N().signAndSendTransaction({transaction:O(t.transaction,`transaction`),account:e,...n===void 0?{}:{chain:n}})).signature}}case`evm.request`:if(!d(t.method))throw{bridgeError:{code:`unsupportedMethod`,message:`Method is not available to native callers: ${String(t.method)}`,method:typeof t.method==`string`?t.method:void 0}};return F().request({method:t.method,params:t.params})}},L=(e,t)=>{c.delete(e)&&p(t)},R=e=>{g?.(null),g=null;for(let t of[...c])t!==e&&L(t,b(t,{code:`bridgeUnavailable`,message:`Bridge was destroyed while this request was in flight`}));if(o){for(let[e,t]of l)o.removeListener(e,t);l.length=0;let e=o.destroy;typeof e==`function`&&e.call(o),o=null}A&&=(A.destroy(),null),s=!0};return{handleMessage:e=>{let t=v(e);if(!t.ok){t.id?p(b(t.id,t.error)):p(x(`bridgeProtocolError`,t.error));return}let{request:n}=t;if(s){p(b(n.id,{code:`bridgeUnavailable`,message:`Bridge has been destroyed`}));return}if(c.has(n.id)){p(x(`bridgeProtocolError`,{code:`protocolError`,message:`Request id is already in flight: ${n.id}`,id:n.id,method:n.method}));return}c.add(n.id),(async()=>{try{L(n.id,y(n.id,await I(n)))}catch(e){let t=e?.bridgeError;L(n.id,b(n.id,t??E(e,n.method)))}})()},dispose:()=>R()}},N=(e=`WaaPBridge`,t=window)=>{let n=t[e];if(typeof n?.postMessage==`function`)return e=>n.postMessage(e);let r=t.webkit?.messageHandlers?.[e];return typeof r?.postMessage==`function`?e=>r.postMessage(e):typeof t.ReactNativeWebView?.postMessage==`function`?e=>t.ReactNativeWebView.postMessage(e):null},P=(e={})=>{e.sdkPlatform&&r(e.sdkPlatform,e.sdkVersion??`unknown`);let i=e.post??N(e.channel);if(!i)throw Error(`[WaaP bridge] No native host channel found. The WebView must install one before loading the bridge page.`);let a={...e.init??{},deferIframe:!1},o=()=>(t(a),n(`tap`).contentWindow),l=null,u=M({post:i,token:e.token,createProvider:()=>c(a,`tap`,!0,[`evm`,`solana`],!1),createSolanaProvider:()=>(l??=new s(o(),a,o,{...a,chains:[`solana`]},!1),l.setAccountMode?.(`tap`),l)});return window.__waapBridgeReceive=e=>u.handleMessage(e),u};export{l as BRIDGE_EVM_METHODS,f as BRIDGE_PROTOCOL_VERSION,M as createMobileBridge,i as getWaaPIframeDiagnostics,v as parseHostMessage,N as resolveNativeHostPost,P as startMobileBridge};
@@ -0,0 +1,2 @@
1
+ import{C as e,_ as t,a as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as u,r as d,t as f,v as p,w as m,x as h}from"./UIMessageManager-CtnIZgIY.mjs";import{t as g}from"./WalletConnect-DXiTxC-F.mjs";import{EventEmitter as _}from"events";import{getAddress as v}from"ethers";const y=e=>typeof e==`object`&&!!e&&e.isComplete===!1&&typeof e.authUrl==`string`;function b(e){return!(!e?.isMetaMask||e.isApexWallet||e.isAvalanche||e.isBitKeep||e.isBlockWallet||e.isMathWallet||e.isOkxWallet||e.isOKExWallet||e.isOneInchIOSWallet||e.isOneInchAndroidWallet||e.isOpera||e.isPortal||e.isRabby||e.isDefiant||e.isTokenPocket||e.isTokenary||e.isZerion)}function x(e){try{if(!e||!Array.isArray(e))return!1;let t=JSON.parse(typeof e[1]==`string`?e[1]:JSON.stringify(e[1]));return t.primaryType===`SafeTx`&&t.domain?.verifyingContract!==void 0&&t.message&&`to`in t.message&&`value`in t.message&&`safeTxGas`in t.message&&`baseGas`in t.message&&`gasPrice`in t.message&&`nonce`in t.message}catch{return!1}}const S={styles:{darkMode:!1}},C=[`waap`,`human`,`injected`,`walletconnect`],w=[e.eth_sendTransaction,e.eth_signTransaction,e.eth_signTypedData_v4,e.personal_sign];function T(e){if(e==null)return null;if(typeof e==`string`){if(C.includes(e))return e;throw Error(`[EthereumProvider] Unexpected login method: "${e}". Expected one of: ${C.join(`, `)}`)}if(typeof e==`object`&&`loginMethod`in e&&typeof e.loginMethod==`string`){let t=e.loginMethod;if(console.warn(`[EthereumProvider] Received object login response. Normalizing "${t}" to string. This is unexpected for the web SDK.`),C.includes(t))return t;throw Error(`[EthereumProvider] Unknown loginMethod in object: "${t}". Expected one of: ${C.join(`, `)}`)}throw Error(`[EthereumProvider] Unexpected login response: ${JSON.stringify(e)} (type: ${typeof e})`)}var E=class extends _{setExposeOnWindow(e){this.exposeOnWindow=e}constructor(e,t,n,r,a,o=!1,s=!1,c,l=[`evm`]){super(),this.lastKnownConversion=`pending`,this.isSilk=!0,this.isWaaP=!0,this.connected=!1,this.exposeOnWindow=!0,this.currentAccount=null,this.accountMode=`tap`,this.walletConnectProvider=null,this.asyncTxs=!1,this.legacyAsyncSigning=!1,this.internalEventEmitter=new _,this.iframeMounted=!0,this.initializerPromise=null,this.sessionProbe=null,this.initializedIframeWindow=null,this.waapRestoreRetryAt=0,this.asyncTxs=o,this.legacyAsyncSigning=s,this.ensureIframe=c,this.iframeMounted=!c,this.referralCode=t,this.project=r,this.customConfig=n,this.initializerChains=l,this.uiMessageManager=new f,this.walletMessageManager=new i(e,a),this.config={...S,...n||{}},this.persistedMethods={login:this.login.bind(this),logout:this.logout.bind(this),getLoginMethod:this.getLoginMethod.bind(this),walletMessageManager:this.walletMessageManager,internalEventEmitter:this.internalEventEmitter,uiMessageManager:this.uiMessageManager,portal:this.portal.bind(this),requestEmail:this.requestEmail.bind(this),requestSBT:this.requestSBT.bind(this),requestPermissionToken:this.requestPermissionToken.bind(this),getLinkedAddresses:this.getLinkedAddresses.bind(this),linkAddress:this.linkAddress.bind(this),unlinkAddress:this.unlinkAddress.bind(this),orcid:this.orcid.bind(this),enable:this.enable.bind(this),isConnected:this.isConnected.bind(this),toggleDarkMode:this.toggleDarkMode.bind(this),destroy:this.destroy.bind(this),silkRequest:this.request.bind(this),waaPRequest:this.request.bind(this)},this.walletMessageManager.addListener({onReceiveConnectNotif:()=>{this.connected=!0,this.emit(`connect`)},handleResponse:e=>this.internalEventEmitter.emit(e.id,e),handleRequest:e=>{e.method===m.show_modal?this.uiMessageManager.emit(`show_modal`):e.method===m.hide_modal&&this.uiMessageManager.emit(`hide_modal`)},onAccountChanged:e=>{this.currentAccount!==e&&(this.currentAccount=e,this.emit(`accountsChanged`,e?[e]:[]))},onAsyncTxNotification:e=>{this.emit(e.type,e.payload)},onSquidLifecycleNotification:e=>{this.emit(e.type,e.payload)}})}async initializeWalletConnect(){try{this.walletConnectProvider=await g.getInstance()}catch(e){console.error(`Failed to initialize WalletConnect provider:`,e),this.walletConnectProvider=null}}async initializeIframeContext(){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=u(e,async()=>{await this.walletMessageManager.pingIframe(),await c({method:m.set_signing_mode,params:[a(this.accountMode,{referralCode:this.referralCode,project:this.project,config:this.customConfig,chains:this.initializerChains})]},!1,this.walletMessageManager,this.internalEventEmitter)});try{await this.initializerPromise}catch(e){throw this.initializerPromise=null,this.initializedIframeWindow=null,e}}async reassertIframeAccountMode(){this.ensureIframeMounted(),await this.walletMessageManager.pingIframe(),await c({method:m.set_signing_mode,params:[a(this.accountMode,{referralCode:this.referralCode,project:this.project,config:this.customConfig,chains:this.initializerChains})]},!1,this.walletMessageManager,this.internalEventEmitter)}ensureIframeMounted(){if(this.iframeMounted||!this.ensureIframe)return;let e=this.ensureIframe();e&&(this.iframeMounted=!0,this.walletMessageManager.setIframeWindow(e))}async ensureInitialized(){this.ensureIframeMounted(),await this.initializeIframeContext()}async preload(){await this.ensureInitialized()}async enable(){return this.request({method:`eth_requestAccounts`})}isConnected(){return this.connected}getAccountStatus(){let e=this.getLoginMethod();return{authenticated:e!==null,loginMethod:e,activeMode:e?this.accountMode:null,mode:this.accountMode,conversion:e?this.lastKnownConversion:`not_required`,tap:null,squid:null,accounts:this.currentAccount?{evm:this.currentAccount}:{}}}get session(){return{login:e=>this.login(e),logout:async()=>{await this.logout()},getLoginMethod:()=>this.getLoginMethod(),getAccountStatus:()=>this.getCanonicalAccountStatus()}}async getCanonicalAccountStatus(){await this.ensureInitialized();let e=await c({method:m.waap_getAccountStatus,params:[]},!1,this.walletMessageManager,this.internalEventEmitter);return e?.conversion&&(this.lastKnownConversion=e.conversion),e}setAccountMode(e){this.accountMode=e,this.initializerPromise=null,this.initializedIframeWindow=null}async request(t){if(!Object.keys(e).includes(t.method))return Promise.reject({error:`Not implemented (${t.method})`});let r=await this.attemptAutoConnect(t.method);if(r!==null)return r;if(w.includes(t.method)&&!(this.getLoginMethod()!==null||await this.restorePersistedWaaPSession()!==null))return Promise.reject(new h(`not_authenticated`,`Not authenticated: call login() before signing.`,{operation:{chain:`evm`,method:t.method}}));if(x(t.params)&&t.method!==e.eth_signTypedData_v4)return Promise.reject({error:`Safe transactions must be signed using eth_signTypedData_v4`});await this.ensureInitialized();let i=(t.method===e.eth_sendTransaction||t.method===e.eth_signTransaction||t.method===e.eth_signTypedData_v4||t.method===e.personal_sign)&&this.asyncTxs||t.async,a=i||t.withPT||t.timeoutMs!==void 0||t.signal?this.legacyAsyncSigning?{asyncSigning:i||void 0,withPT:t.withPT,timeoutMs:t.timeoutMs,signal:t.signal}:{async:i,withPT:t.withPT,timeoutMs:t.timeoutMs,signal:t.signal}:void 0,o=await c(t,n(t.method),this.walletMessageManager,this.internalEventEmitter,a);if((t.method===e.wallet_switchEthereumChain||t.method===e.wallet_addEthereumChain)&&o===null){this.emit(`chainChanged`,t.params?.[0]?.chainId);try{let e=await this.request({method:`eth_accounts`});e&&e.length>0&&(this.currentAccount=e[0],this.emit(`accountsChanged`,e),this.emit(`connect`,{chainId:t.params?.[0]?.chainId}))}catch(e){console.warn(`[EthereumProvider] Failed to get accounts after chain switch:`,e),this.currentAccount&&(this.emit(`accountsChanged`,[this.currentAccount]),this.emit(`connect`,{chainId:t.params?.[0]?.chainId}))}}return t.method===e.eth_requestAccounts&&Array.isArray(o)&&typeof o[0]==`string`&&(this.currentAccount=o[0],this.connected=!0,typeof window<`u`&&typeof localStorage<`u`&&localStorage.setItem(`${window.location.origin}-connected`,`waap`),this.emit(`accountsChanged`,o),this.emit(`connect`)),o}async login(e){let t=await this.loginWithNativeHandoff(e);if(y(t))throw Error(`[WaaP SDK] The wallet returned a native auth hand-off. Use loginWithNativeHandoff() from a native host.`);return t}async loginWithNativeHandoff(e){if(this.waapRestoreRetryAt=0,typeof window>`u`||typeof document>`u`)return null;let t=e&&!(`request`in e)?e:void 0,n=t?t.customProvider:e;if(await this.ensureInitialized(),!t?.force&&await this.restorePersistedWaaPSession())return this.getLoginMethod()??`waap`;let r=n||window.ethereum,i=r&&b(r)?`MetaMask`:`Browser Wallet`,a=await c({method:m.login,params:[i]},!0,this.walletMessageManager,this.internalEventEmitter);if(y(a))return a;let o=T(a);if(o===null)return null;switch(o){case`waap`:case`human`:localStorage.setItem(`${window.location.origin}-connected`,`waap`),this.setupWaaP();break;case`injected`:r&&(localStorage.setItem(`${window.location.origin}-connected`,`injected`),this.setupInjectedWallet(r));break;case`walletconnect`:{localStorage.setItem(`${window.location.origin}-connected`,`walletconnect`),this.walletConnectProvider||await this.initializeWalletConnect(),g.isConnected()||(await this.walletConnectProvider.open({view:`Connect`}),await g.listenToAccountChangeEvent());let e=g.getWalletProvider();this.setupWalletConnect(e);break}}return o}async logout(){await this.ensureInitialized(),this.cleanupInvalidLoginState(),this.waapRestoreRetryAt=0,this.lastKnownConversion=`pending`,this.currentAccount=null,this.connected=!1,this.emit(`accountsChanged`,[]),this.emit(`disconnect`);try{this.walletConnectProvider&&await this.walletConnectProvider.disconnect()}catch(e){console.error(`Error disconnecting from WalletConnect:`,e)}return c({method:m.logout},!1,this.walletMessageManager,this.internalEventEmitter)}destroy(){if(this.walletMessageManager.dispose(),this.internalEventEmitter.removeAllListeners(),this.uiMessageManager.removeAllListeners(),this.removeAllListeners(),this.connected=!1,this.walletConnectProvider&&=(this.walletConnectProvider.disconnect().catch(()=>void 0),null),typeof window<`u`){let e=window;(e.silk===this||e.silk?.walletMessageManager===this.walletMessageManager)&&delete e.silk,(e.waap===this||e.waap?.walletMessageManager===this.walletMessageManager)&&delete e.waap}t()}cleanupInvalidLoginState(){try{localStorage.removeItem(`${window.location.origin}-connected`)}catch(e){console.warn(`Could not clean up login state:`,e)}}setupWaaP(){if(!this.exposeOnWindow)return;let e={...this.persistedMethods,isWaaP:!0,on:this.on.bind(this),removeListener:this.removeListener.bind(this),request:this.request.bind(this)};window.silk=e,window.waap=e}setupInjectedWallet(e){if(!this.exposeOnWindow)return;let t={...this.persistedMethods,...e,isSilk:!0,connected:e.connected??!1,on:e.on?.bind(e)??(()=>{}),removeListener:e.removeListener?.bind(e)??(()=>{}),request:e.request.bind(e)};window.silk=t,window.waap=t}setupWalletConnect(e){if(!this.exposeOnWindow)return;let t={...this.persistedMethods,...e,isSilk:!0,connected:!0,on:e.on?.bind(e)??(()=>{}),removeListener:e.removeListener?.bind(e)??(()=>{}),request:e.request.bind(e)};window.silk=t,window.waap=t}setupAutoConnectInjected(e){if(!this.exposeOnWindow)return;let t={...this.persistedMethods,...e,isSilk:!1,connected:e.isConnected?.()??!1,on:e.on?.bind(e)??(()=>{}),removeListener:e.removeListener?.bind(e)??(()=>{}),request:e.request.bind(e)};window.silk=t,window.waap=t}setupAutoConnectWalletConnect(e){if(!this.exposeOnWindow)return;let t={...this.persistedMethods,...e,isSilk:!1,connected:!0,on:e.on?.bind(e)??(()=>{}),removeListener:e.removeListener?.bind(e)??(()=>{}),request:e.request.bind(e)};window.silk=t,window.waap=t}async attemptAutoConnect(e){if(e!==`eth_requestAccounts`&&e!==`eth_accounts`)return null;let t=this.getLoginMethod();if(t===`waap`||t===`human`||t===null&&e===`eth_accounts`&&Date.now()>=this.waapRestoreRetryAt){let e=await this.restorePersistedWaaPSession();if(e)return e;t===null&&(this.waapRestoreRetryAt=Date.now()+5e3)}if(t===`injected`&&window.ethereum)try{return this.setupAutoConnectInjected(window.ethereum),window.ethereum.request({method:`eth_requestAccounts`})}catch(e){return console.warn(`Injected wallet auto-connect failed:`,e),this.cleanupInvalidLoginState(),null}else if(t===`walletconnect`)try{if(this.walletConnectProvider||=await g.getInstance(),await g.waitForReadyAndCheckConnection()){let e=g.getWalletProvider();return this.setupAutoConnectWalletConnect(e),e.request({method:`eth_requestAccounts`})}else return this.cleanupInvalidLoginState(),null}catch(e){return console.warn(`WalletConnect auto-connect failed:`,e),this.cleanupInvalidLoginState(),null}return null}restorePersistedWaaPSession(){return this.sessionProbe??=this.probeWaaPSession().finally(()=>{this.sessionProbe=null}),this.sessionProbe}async probeWaaPSession(){try{if(await this.ensureInitialized(),!(await this.getCanonicalAccountStatus()).authenticated)return this.cleanupInvalidLoginState(),null;let e=await c({method:m.auto_conn,params:[window.location.origin]},!1,this.walletMessageManager,this.internalEventEmitter);if(Array.isArray(e)&&e.length>0)return this.currentAccount=e[0],this.connected=!0,localStorage.setItem(`${window.location.origin}-connected`,`waap`),this.setupWaaP(),e}catch(e){console.warn(`WaaP session probe failed:`,e)}return this.cleanupInvalidLoginState(),null}getLoginMethod(){if(typeof window>`u`||typeof localStorage>`u`)return null;try{let e=localStorage.getItem(`${window.location.origin}-connected`);if(!e)return null;if(![`waap`,`human`,`injected`,`walletconnect`].includes(e))return this.cleanupInvalidLoginState(),null;switch(e){case`injected`:return window.ethereum?`injected`:(this.cleanupInvalidLoginState(),null);case`walletconnect`:try{return g.isConnected()?`walletconnect`:(this.cleanupInvalidLoginState(),null)}catch{return this.cleanupInvalidLoginState(),null}case`waap`:return`waap`;case`human`:return`human`;default:return this.cleanupInvalidLoginState(),null}}catch(e){return console.warn(`Error checking login method:`,e),this.cleanupInvalidLoginState(),null}}async toggleDarkMode(){this.config.styles.darkMode=!this.config.styles.darkMode,await this.ensureInitialized();try{await c({method:m.set_custom_config,params:[this.config]},!1,this.walletMessageManager,this.internalEventEmitter)}catch(e){console.error(`Error setting custom config in Silk iframe:`,e)}}async safe(){await this.ensureInitialized(),await c({method:m.safe},!0,this.walletMessageManager,this.internalEventEmitter)}async orcid(){await this.ensureInitialized(),await c({method:m.orcid},!0,this.walletMessageManager,this.internalEventEmitter)}async portal(e,t,n){await this.ensureInitialized();let r;switch(t){case`get`:r=e===`gastank`?m.gastank_get_settings:m.customization_get;break;case`update`:r=e===`gastank`?m.gastank_update_settings:m.customization_update;break;case`topup`:r=m.gastank_topup;break;case`init`:r=m.project_init;break}let i=t!==`get`&&e!==`customization`;return c({method:r,params:[n,window.location.origin]},i,this.walletMessageManager,this.internalEventEmitter)}async requestEmail(){return await this.ensureInitialized(),c({method:m.silk_requestEmail},!0,this.walletMessageManager,this.internalEventEmitter)}async requestPermissionToken(e){await this.ensureInitialized();let t={...e,walletMode:this.accountMode};return c({method:m.waap_requestPermissionToken,params:[t]},!0,this.walletMessageManager,this.internalEventEmitter)}async getPermissionTokenStatus(e){return await this.ensureInitialized(),await c({method:m.waap_getPermissionTokenStatus,params:[e]},!1,this.walletMessageManager,this.internalEventEmitter)}async clearPermissionToken(e){return await this.ensureInitialized(),await c({method:m.waap_clearPermissionToken,params:[e]},!1,this.walletMessageManager,this.internalEventEmitter)}async requestSBT(e){return await this.ensureInitialized(),c({method:m.silk_requestSbt,params:[e]},!0,this.walletMessageManager,this.internalEventEmitter)}async getLinkedAddresses(){return await this.walletMessageManager.pingIframe(),(await c({method:m.waap_getLinkedAddresses,params:[]},!1,this.walletMessageManager,this.internalEventEmitter,D)).addresses}async linkAddress(e){if(typeof window>`u`)throw Error(`linkAddress requires a browser environment`);this.walletConnectProvider||await this.initializeWalletConnect(),g.isConnected()||(await this.walletConnectProvider.open({view:`Connect`}),await g.listenToAccountChangeEvent());let t=g.getWalletProvider();if(!t)throw Error(`No wallet provider available after connection`);let n=(await t.request({method:`eth_accounts`}))[0];if(!n||n.toLowerCase()!==e.toLowerCase())throw Error(`Connected wallet account ${n??`(none)`} does not match requested address ${e}`);await this.walletMessageManager.pingIframe();let r=await c({method:m.waap_getLinkAddressNonce,params:[]},!1,this.walletMessageManager,this.internalEventEmitter,D),i=O({domain:window.location.host,address:e,uri:window.location.origin,nonce:r.nonce,issuedAt:new Date().toISOString()}),a=await t.request({method:`personal_sign`,params:[i,e]});return(await c({method:m.waap_linkAddress,params:[{message:i,signature:a}]},!1,this.walletMessageManager,this.internalEventEmitter,D)).addresses}async unlinkAddress(e){return await this.walletMessageManager.pingIframe(),(await c({method:m.waap_unlinkAddress,params:[{address:e}]},!1,this.walletMessageManager,this.internalEventEmitter,D)).addresses}};const D={timeoutMs:10*6e4};function O(e){let t=v(e.address);return`${`${e.domain} wants you to sign in with your Ethereum account:\n${t}`}\n\nLink this wallet to your Human Wallet account.\n\n${[`URI: ${e.uri}`,`Version: 1`,`Chain ID: 1`,`Nonce: ${e.nonce}`,`Issued At: ${e.issuedAt}`].join(`
2
+ `)}`}const k=(e,t,n=!0,i=[`evm`],a=!0)=>{let{referralCode:c,config:u,project:f,asyncTxs:m,asyncSigning:h,deferIframe:_}=e,v=p(e),y=!!h&&!m;e.walletConnectProjectId&&g.setProjectId(e.walletConnectProjectId),h&&!m&&console.warn("[WaaP SDK] `asyncSigning` is deprecated. Use `asyncTxs` instead.");let b=typeof window>`u`||typeof document>`u`,x=()=>typeof window>`u`||typeof document>`u`?null:(o(e),s(t).contentWindow),S=_===!1&&!b,C=_===void 0&&!b,w=S?x():null;if(S&&!w)throw Error(`WaaP iframe does not exist on page`);let T=new E(w,c,u||{},f||{},v,m||h||!1,y,S?void 0:x,i);if(T.setAccountMode(t),T.setExposeOnWindow(a),!b&&n&&S&&T.initializeIframeContext().catch(()=>void 0),T.uiMessageManager.on(`show_modal`,()=>{l()}),T.uiMessageManager.on(`hide_modal`,()=>{r()}),!b&&a&&(window.silk=T,window.waap=T),n&&C){let e=d(T),t=T.destroy.bind(T);T.destroy=()=>{e(),t()}}return T},A=(e={})=>k(e,`tap`);export{S as i,k as n,E as r,A as t};
@@ -0,0 +1,2 @@
1
+ const e=require("./UIMessageManager-D-OTya1E.js"),t=require("./WalletConnect-B21f4Vvh.js");let n=require("events"),r=require("ethers");const i=e=>typeof e==`object`&&!!e&&e.isComplete===!1&&typeof e.authUrl==`string`;function a(e){return!(!e?.isMetaMask||e.isApexWallet||e.isAvalanche||e.isBitKeep||e.isBlockWallet||e.isMathWallet||e.isOkxWallet||e.isOKExWallet||e.isOneInchIOSWallet||e.isOneInchAndroidWallet||e.isOpera||e.isPortal||e.isRabby||e.isDefiant||e.isTokenPocket||e.isTokenary||e.isZerion)}function o(e){try{if(!e||!Array.isArray(e))return!1;let t=JSON.parse(typeof e[1]==`string`?e[1]:JSON.stringify(e[1]));return t.primaryType===`SafeTx`&&t.domain?.verifyingContract!==void 0&&t.message&&`to`in t.message&&`value`in t.message&&`safeTxGas`in t.message&&`baseGas`in t.message&&`gasPrice`in t.message&&`nonce`in t.message}catch{return!1}}const s={styles:{darkMode:!1}},c=[`waap`,`human`,`injected`,`walletconnect`],l=[e.C.eth_sendTransaction,e.C.eth_signTransaction,e.C.eth_signTypedData_v4,e.C.personal_sign];function u(e){if(e==null)return null;if(typeof e==`string`){if(c.includes(e))return e;throw Error(`[EthereumProvider] Unexpected login method: "${e}". Expected one of: ${c.join(`, `)}`)}if(typeof e==`object`&&`loginMethod`in e&&typeof e.loginMethod==`string`){let t=e.loginMethod;if(console.warn(`[EthereumProvider] Received object login response. Normalizing "${t}" to string. This is unexpected for the web SDK.`),c.includes(t))return t;throw Error(`[EthereumProvider] Unknown loginMethod in object: "${t}". Expected one of: ${c.join(`, `)}`)}throw Error(`[EthereumProvider] Unexpected login response: ${JSON.stringify(e)} (type: ${typeof e})`)}var d=class extends n.EventEmitter{setExposeOnWindow(e){this.exposeOnWindow=e}constructor(t,r,i,a,o,c=!1,l=!1,u,d=[`evm`]){super(),this.lastKnownConversion=`pending`,this.isSilk=!0,this.isWaaP=!0,this.connected=!1,this.exposeOnWindow=!0,this.currentAccount=null,this.accountMode=`tap`,this.walletConnectProvider=null,this.asyncTxs=!1,this.legacyAsyncSigning=!1,this.internalEventEmitter=new n.EventEmitter,this.iframeMounted=!0,this.initializerPromise=null,this.sessionProbe=null,this.initializedIframeWindow=null,this.waapRestoreRetryAt=0,this.asyncTxs=c,this.legacyAsyncSigning=l,this.ensureIframe=u,this.iframeMounted=!u,this.referralCode=r,this.project=a,this.customConfig=i,this.initializerChains=d,this.uiMessageManager=new e.t,this.walletMessageManager=new e.d(t,o),this.config={...s,...i||{}},this.persistedMethods={login:this.login.bind(this),logout:this.logout.bind(this),getLoginMethod:this.getLoginMethod.bind(this),walletMessageManager:this.walletMessageManager,internalEventEmitter:this.internalEventEmitter,uiMessageManager:this.uiMessageManager,portal:this.portal.bind(this),requestEmail:this.requestEmail.bind(this),requestSBT:this.requestSBT.bind(this),requestPermissionToken:this.requestPermissionToken.bind(this),getLinkedAddresses:this.getLinkedAddresses.bind(this),linkAddress:this.linkAddress.bind(this),unlinkAddress:this.unlinkAddress.bind(this),orcid:this.orcid.bind(this),enable:this.enable.bind(this),isConnected:this.isConnected.bind(this),toggleDarkMode:this.toggleDarkMode.bind(this),destroy:this.destroy.bind(this),silkRequest:this.request.bind(this),waaPRequest:this.request.bind(this)},this.walletMessageManager.addListener({onReceiveConnectNotif:()=>{this.connected=!0,this.emit(`connect`)},handleResponse:e=>this.internalEventEmitter.emit(e.id,e),handleRequest:t=>{t.method===e.w.show_modal?this.uiMessageManager.emit(`show_modal`):t.method===e.w.hide_modal&&this.uiMessageManager.emit(`hide_modal`)},onAccountChanged:e=>{this.currentAccount!==e&&(this.currentAccount=e,this.emit(`accountsChanged`,e?[e]:[]))},onAsyncTxNotification:e=>{this.emit(e.type,e.payload)},onSquidLifecycleNotification:e=>{this.emit(e.type,e.payload)}})}async initializeWalletConnect(){try{this.walletConnectProvider=await t.t.getInstance()}catch(e){console.error(`Failed to initialize WalletConnect provider:`,e),this.walletConnectProvider=null}}async initializeIframeContext(){let t=this.walletMessageManager.getIframeWindow();if(!t)throw Error(`WaaP iframe is not mounted`);if(this.initializedIframeWindow===t&&this.initializerPromise)return this.initializerPromise;this.initializedIframeWindow=t,this.initializerPromise=e.m(t,async()=>{await this.walletMessageManager.pingIframe(),await e.i({method:e.w.set_signing_mode,params:[e.f(this.accountMode,{referralCode:this.referralCode,project:this.project,config:this.customConfig,chains:this.initializerChains})]},!1,this.walletMessageManager,this.internalEventEmitter)});try{await this.initializerPromise}catch(e){throw this.initializerPromise=null,this.initializedIframeWindow=null,e}}async reassertIframeAccountMode(){this.ensureIframeMounted(),await this.walletMessageManager.pingIframe(),await e.i({method:e.w.set_signing_mode,params:[e.f(this.accountMode,{referralCode:this.referralCode,project:this.project,config:this.customConfig,chains:this.initializerChains})]},!1,this.walletMessageManager,this.internalEventEmitter)}ensureIframeMounted(){if(this.iframeMounted||!this.ensureIframe)return;let e=this.ensureIframe();e&&(this.iframeMounted=!0,this.walletMessageManager.setIframeWindow(e))}async ensureInitialized(){this.ensureIframeMounted(),await this.initializeIframeContext()}async preload(){await this.ensureInitialized()}async enable(){return this.request({method:`eth_requestAccounts`})}isConnected(){return this.connected}getAccountStatus(){let e=this.getLoginMethod();return{authenticated:e!==null,loginMethod:e,activeMode:e?this.accountMode:null,mode:this.accountMode,conversion:e?this.lastKnownConversion:`not_required`,tap:null,squid:null,accounts:this.currentAccount?{evm:this.currentAccount}:{}}}get session(){return{login:e=>this.login(e),logout:async()=>{await this.logout()},getLoginMethod:()=>this.getLoginMethod(),getAccountStatus:()=>this.getCanonicalAccountStatus()}}async getCanonicalAccountStatus(){await this.ensureInitialized();let t=await e.i({method:e.w.waap_getAccountStatus,params:[]},!1,this.walletMessageManager,this.internalEventEmitter);return t?.conversion&&(this.lastKnownConversion=t.conversion),t}setAccountMode(e){this.accountMode=e,this.initializerPromise=null,this.initializedIframeWindow=null}async request(t){if(!Object.keys(e.C).includes(t.method))return Promise.reject({error:`Not implemented (${t.method})`});let n=await this.attemptAutoConnect(t.method);if(n!==null)return n;if(l.includes(t.method)&&!(this.getLoginMethod()!==null||await this.restorePersistedWaaPSession()!==null))return Promise.reject(new e.x(`not_authenticated`,`Not authenticated: call login() before signing.`,{operation:{chain:`evm`,method:t.method}}));if(o(t.params)&&t.method!==e.C.eth_signTypedData_v4)return Promise.reject({error:`Safe transactions must be signed using eth_signTypedData_v4`});await this.ensureInitialized();let r=(t.method===e.C.eth_sendTransaction||t.method===e.C.eth_signTransaction||t.method===e.C.eth_signTypedData_v4||t.method===e.C.personal_sign)&&this.asyncTxs||t.async,i=r||t.withPT||t.timeoutMs!==void 0||t.signal?this.legacyAsyncSigning?{asyncSigning:r||void 0,withPT:t.withPT,timeoutMs:t.timeoutMs,signal:t.signal}:{async:r,withPT:t.withPT,timeoutMs:t.timeoutMs,signal:t.signal}:void 0,a=await e.i(t,e.a(t.method),this.walletMessageManager,this.internalEventEmitter,i);if((t.method===e.C.wallet_switchEthereumChain||t.method===e.C.wallet_addEthereumChain)&&a===null){this.emit(`chainChanged`,t.params?.[0]?.chainId);try{let e=await this.request({method:`eth_accounts`});e&&e.length>0&&(this.currentAccount=e[0],this.emit(`accountsChanged`,e),this.emit(`connect`,{chainId:t.params?.[0]?.chainId}))}catch(e){console.warn(`[EthereumProvider] Failed to get accounts after chain switch:`,e),this.currentAccount&&(this.emit(`accountsChanged`,[this.currentAccount]),this.emit(`connect`,{chainId:t.params?.[0]?.chainId}))}}return t.method===e.C.eth_requestAccounts&&Array.isArray(a)&&typeof a[0]==`string`&&(this.currentAccount=a[0],this.connected=!0,typeof window<`u`&&typeof localStorage<`u`&&localStorage.setItem(`${window.location.origin}-connected`,`waap`),this.emit(`accountsChanged`,a),this.emit(`connect`)),a}async login(e){let t=await this.loginWithNativeHandoff(e);if(i(t))throw Error(`[WaaP SDK] The wallet returned a native auth hand-off. Use loginWithNativeHandoff() from a native host.`);return t}async loginWithNativeHandoff(n){if(this.waapRestoreRetryAt=0,typeof window>`u`||typeof document>`u`)return null;let r=n&&!(`request`in n)?n:void 0,o=r?r.customProvider:n;if(await this.ensureInitialized(),!r?.force&&await this.restorePersistedWaaPSession())return this.getLoginMethod()??`waap`;let s=o||window.ethereum,c=s&&a(s)?`MetaMask`:`Browser Wallet`,l=await e.i({method:e.w.login,params:[c]},!0,this.walletMessageManager,this.internalEventEmitter);if(i(l))return l;let d=u(l);if(d===null)return null;switch(d){case`waap`:case`human`:localStorage.setItem(`${window.location.origin}-connected`,`waap`),this.setupWaaP();break;case`injected`:s&&(localStorage.setItem(`${window.location.origin}-connected`,`injected`),this.setupInjectedWallet(s));break;case`walletconnect`:{localStorage.setItem(`${window.location.origin}-connected`,`walletconnect`),this.walletConnectProvider||await this.initializeWalletConnect(),t.t.isConnected()||(await this.walletConnectProvider.open({view:`Connect`}),await t.t.listenToAccountChangeEvent());let e=t.t.getWalletProvider();this.setupWalletConnect(e);break}}return d}async logout(){await this.ensureInitialized(),this.cleanupInvalidLoginState(),this.waapRestoreRetryAt=0,this.lastKnownConversion=`pending`,this.currentAccount=null,this.connected=!1,this.emit(`accountsChanged`,[]),this.emit(`disconnect`);try{this.walletConnectProvider&&await this.walletConnectProvider.disconnect()}catch(e){console.error(`Error disconnecting from WalletConnect:`,e)}return e.i({method:e.w.logout},!1,this.walletMessageManager,this.internalEventEmitter)}destroy(){if(this.walletMessageManager.dispose(),this.internalEventEmitter.removeAllListeners(),this.uiMessageManager.removeAllListeners(),this.removeAllListeners(),this.connected=!1,this.walletConnectProvider&&=(this.walletConnectProvider.disconnect().catch(()=>void 0),null),typeof window<`u`){let e=window;(e.silk===this||e.silk?.walletMessageManager===this.walletMessageManager)&&delete e.silk,(e.waap===this||e.waap?.walletMessageManager===this.walletMessageManager)&&delete e.waap}e._()}cleanupInvalidLoginState(){try{localStorage.removeItem(`${window.location.origin}-connected`)}catch(e){console.warn(`Could not clean up login state:`,e)}}setupWaaP(){if(!this.exposeOnWindow)return;let e={...this.persistedMethods,isWaaP:!0,on:this.on.bind(this),removeListener:this.removeListener.bind(this),request:this.request.bind(this)};window.silk=e,window.waap=e}setupInjectedWallet(e){if(!this.exposeOnWindow)return;let t={...this.persistedMethods,...e,isSilk:!0,connected:e.connected??!1,on:e.on?.bind(e)??(()=>{}),removeListener:e.removeListener?.bind(e)??(()=>{}),request:e.request.bind(e)};window.silk=t,window.waap=t}setupWalletConnect(e){if(!this.exposeOnWindow)return;let t={...this.persistedMethods,...e,isSilk:!0,connected:!0,on:e.on?.bind(e)??(()=>{}),removeListener:e.removeListener?.bind(e)??(()=>{}),request:e.request.bind(e)};window.silk=t,window.waap=t}setupAutoConnectInjected(e){if(!this.exposeOnWindow)return;let t={...this.persistedMethods,...e,isSilk:!1,connected:e.isConnected?.()??!1,on:e.on?.bind(e)??(()=>{}),removeListener:e.removeListener?.bind(e)??(()=>{}),request:e.request.bind(e)};window.silk=t,window.waap=t}setupAutoConnectWalletConnect(e){if(!this.exposeOnWindow)return;let t={...this.persistedMethods,...e,isSilk:!1,connected:!0,on:e.on?.bind(e)??(()=>{}),removeListener:e.removeListener?.bind(e)??(()=>{}),request:e.request.bind(e)};window.silk=t,window.waap=t}async attemptAutoConnect(e){if(e!==`eth_requestAccounts`&&e!==`eth_accounts`)return null;let n=this.getLoginMethod();if(n===`waap`||n===`human`||n===null&&e===`eth_accounts`&&Date.now()>=this.waapRestoreRetryAt){let e=await this.restorePersistedWaaPSession();if(e)return e;n===null&&(this.waapRestoreRetryAt=Date.now()+5e3)}if(n===`injected`&&window.ethereum)try{return this.setupAutoConnectInjected(window.ethereum),window.ethereum.request({method:`eth_requestAccounts`})}catch(e){return console.warn(`Injected wallet auto-connect failed:`,e),this.cleanupInvalidLoginState(),null}else if(n===`walletconnect`)try{if(this.walletConnectProvider||=await t.t.getInstance(),await t.t.waitForReadyAndCheckConnection()){let e=t.t.getWalletProvider();return this.setupAutoConnectWalletConnect(e),e.request({method:`eth_requestAccounts`})}else return this.cleanupInvalidLoginState(),null}catch(e){return console.warn(`WalletConnect auto-connect failed:`,e),this.cleanupInvalidLoginState(),null}return null}restorePersistedWaaPSession(){return this.sessionProbe??=this.probeWaaPSession().finally(()=>{this.sessionProbe=null}),this.sessionProbe}async probeWaaPSession(){try{if(await this.ensureInitialized(),!(await this.getCanonicalAccountStatus()).authenticated)return this.cleanupInvalidLoginState(),null;let t=await e.i({method:e.w.auto_conn,params:[window.location.origin]},!1,this.walletMessageManager,this.internalEventEmitter);if(Array.isArray(t)&&t.length>0)return this.currentAccount=t[0],this.connected=!0,localStorage.setItem(`${window.location.origin}-connected`,`waap`),this.setupWaaP(),t}catch(e){console.warn(`WaaP session probe failed:`,e)}return this.cleanupInvalidLoginState(),null}getLoginMethod(){if(typeof window>`u`||typeof localStorage>`u`)return null;try{let e=localStorage.getItem(`${window.location.origin}-connected`);if(!e)return null;if(![`waap`,`human`,`injected`,`walletconnect`].includes(e))return this.cleanupInvalidLoginState(),null;switch(e){case`injected`:return window.ethereum?`injected`:(this.cleanupInvalidLoginState(),null);case`walletconnect`:try{return t.t.isConnected()?`walletconnect`:(this.cleanupInvalidLoginState(),null)}catch{return this.cleanupInvalidLoginState(),null}case`waap`:return`waap`;case`human`:return`human`;default:return this.cleanupInvalidLoginState(),null}}catch(e){return console.warn(`Error checking login method:`,e),this.cleanupInvalidLoginState(),null}}async toggleDarkMode(){this.config.styles.darkMode=!this.config.styles.darkMode,await this.ensureInitialized();try{await e.i({method:e.w.set_custom_config,params:[this.config]},!1,this.walletMessageManager,this.internalEventEmitter)}catch(e){console.error(`Error setting custom config in Silk iframe:`,e)}}async safe(){await this.ensureInitialized(),await e.i({method:e.w.safe},!0,this.walletMessageManager,this.internalEventEmitter)}async orcid(){await this.ensureInitialized(),await e.i({method:e.w.orcid},!0,this.walletMessageManager,this.internalEventEmitter)}async portal(t,n,r){await this.ensureInitialized();let i;switch(n){case`get`:i=t===`gastank`?e.w.gastank_get_settings:e.w.customization_get;break;case`update`:i=t===`gastank`?e.w.gastank_update_settings:e.w.customization_update;break;case`topup`:i=e.w.gastank_topup;break;case`init`:i=e.w.project_init;break}let a=n!==`get`&&t!==`customization`;return e.i({method:i,params:[r,window.location.origin]},a,this.walletMessageManager,this.internalEventEmitter)}async requestEmail(){return await this.ensureInitialized(),e.i({method:e.w.silk_requestEmail},!0,this.walletMessageManager,this.internalEventEmitter)}async requestPermissionToken(t){await this.ensureInitialized();let n={...t,walletMode:this.accountMode};return e.i({method:e.w.waap_requestPermissionToken,params:[n]},!0,this.walletMessageManager,this.internalEventEmitter)}async getPermissionTokenStatus(t){return await this.ensureInitialized(),await e.i({method:e.w.waap_getPermissionTokenStatus,params:[t]},!1,this.walletMessageManager,this.internalEventEmitter)}async clearPermissionToken(t){return await this.ensureInitialized(),await e.i({method:e.w.waap_clearPermissionToken,params:[t]},!1,this.walletMessageManager,this.internalEventEmitter)}async requestSBT(t){return await this.ensureInitialized(),e.i({method:e.w.silk_requestSbt,params:[t]},!0,this.walletMessageManager,this.internalEventEmitter)}async getLinkedAddresses(){return await this.walletMessageManager.pingIframe(),(await e.i({method:e.w.waap_getLinkedAddresses,params:[]},!1,this.walletMessageManager,this.internalEventEmitter,f)).addresses}async linkAddress(n){if(typeof window>`u`)throw Error(`linkAddress requires a browser environment`);this.walletConnectProvider||await this.initializeWalletConnect(),t.t.isConnected()||(await this.walletConnectProvider.open({view:`Connect`}),await t.t.listenToAccountChangeEvent());let r=t.t.getWalletProvider();if(!r)throw Error(`No wallet provider available after connection`);let i=(await r.request({method:`eth_accounts`}))[0];if(!i||i.toLowerCase()!==n.toLowerCase())throw Error(`Connected wallet account ${i??`(none)`} does not match requested address ${n}`);await this.walletMessageManager.pingIframe();let a=await e.i({method:e.w.waap_getLinkAddressNonce,params:[]},!1,this.walletMessageManager,this.internalEventEmitter,f),o=p({domain:window.location.host,address:n,uri:window.location.origin,nonce:a.nonce,issuedAt:new Date().toISOString()}),s=await r.request({method:`personal_sign`,params:[o,n]});return(await e.i({method:e.w.waap_linkAddress,params:[{message:o,signature:s}]},!1,this.walletMessageManager,this.internalEventEmitter,f)).addresses}async unlinkAddress(t){return await this.walletMessageManager.pingIframe(),(await e.i({method:e.w.waap_unlinkAddress,params:[{address:t}]},!1,this.walletMessageManager,this.internalEventEmitter,f)).addresses}};const f={timeoutMs:10*6e4};function p(e){let t=(0,r.getAddress)(e.address);return`${`${e.domain} wants you to sign in with your Ethereum account:\n${t}`}\n\nLink this wallet to your Human Wallet account.\n\n${[`URI: ${e.uri}`,`Version: 1`,`Chain ID: 1`,`Nonce: ${e.nonce}`,`Issued At: ${e.issuedAt}`].join(`
2
+ `)}`}const m=(n,r,i=!0,a=[`evm`],o=!0)=>{let{referralCode:s,config:c,project:l,asyncTxs:u,asyncSigning:f,deferIframe:p}=n,m=e.v(n),h=!!f&&!u;n.walletConnectProjectId&&t.t.setProjectId(n.walletConnectProjectId),f&&!u&&console.warn("[WaaP SDK] `asyncSigning` is deprecated. Use `asyncTxs` instead.");let g=typeof window>`u`||typeof document>`u`,_=()=>typeof window>`u`||typeof document>`u`?null:(e.g(n),e.h(r).contentWindow),v=p===!1&&!g,y=p===void 0&&!g,b=v?_():null;if(v&&!b)throw Error(`WaaP iframe does not exist on page`);let x=new d(b,s,c||{},l||{},m,u||f||!1,h,v?void 0:_,a);if(x.setAccountMode(r),x.setExposeOnWindow(o),!g&&i&&v&&x.initializeIframeContext().catch(()=>void 0),x.uiMessageManager.on(`show_modal`,()=>{e.l()}),x.uiMessageManager.on(`hide_modal`,()=>{e.c()}),!g&&o&&(window.silk=x,window.waap=x),i&&y){let t=e.r(x),n=x.destroy.bind(x);x.destroy=()=>{t(),n()}}return x},h=(e={})=>m(e,`tap`);Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return h}});