@zerodev/wallet-react 0.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/_cjs/actions.js +193 -0
  3. package/dist/_cjs/connector.js +221 -0
  4. package/dist/_cjs/constants.js +4 -0
  5. package/dist/_cjs/hooks/useAuthenticateOAuth.js +18 -0
  6. package/dist/_cjs/hooks/useExportWallet.js +18 -0
  7. package/dist/_cjs/hooks/useLoginPasskey.js +18 -0
  8. package/dist/_cjs/hooks/useRefreshSession.js +18 -0
  9. package/dist/_cjs/hooks/useRegisterPasskey.js +18 -0
  10. package/dist/_cjs/hooks/useSendOTP.js +18 -0
  11. package/dist/_cjs/hooks/useVerifyOTP.js +18 -0
  12. package/dist/_cjs/index.js +23 -0
  13. package/dist/_cjs/oauth.js +84 -0
  14. package/dist/_cjs/package.json +1 -0
  15. package/dist/_cjs/provider.js +163 -0
  16. package/dist/_cjs/store.js +51 -0
  17. package/dist/_cjs/utils/aaUtils.js +7 -0
  18. package/dist/_cjs/utils/timers.js +50 -0
  19. package/dist/_esm/actions.js +225 -0
  20. package/dist/_esm/connector.js +248 -0
  21. package/dist/_esm/constants.js +1 -0
  22. package/dist/_esm/hooks/useAuthenticateOAuth.js +18 -0
  23. package/dist/_esm/hooks/useExportWallet.js +18 -0
  24. package/dist/_esm/hooks/useLoginPasskey.js +18 -0
  25. package/dist/_esm/hooks/useRefreshSession.js +18 -0
  26. package/dist/_esm/hooks/useRegisterPasskey.js +18 -0
  27. package/dist/_esm/hooks/useSendOTP.js +18 -0
  28. package/dist/_esm/hooks/useVerifyOTP.js +18 -0
  29. package/dist/_esm/index.js +10 -0
  30. package/dist/_esm/oauth.js +77 -0
  31. package/dist/_esm/package.json +1 -0
  32. package/dist/_esm/provider.js +169 -0
  33. package/dist/_esm/store.js +51 -0
  34. package/dist/_esm/utils/aaUtils.js +4 -0
  35. package/dist/_esm/utils/timers.js +55 -0
  36. package/dist/_types/actions.d.ts +124 -0
  37. package/dist/_types/actions.d.ts.map +1 -0
  38. package/dist/_types/connector.d.ts +18 -0
  39. package/dist/_types/connector.d.ts.map +1 -0
  40. package/dist/_types/constants.d.ts +2 -0
  41. package/dist/_types/constants.d.ts.map +1 -0
  42. package/dist/_types/hooks/useAuthenticateOAuth.d.ts +18 -0
  43. package/dist/_types/hooks/useAuthenticateOAuth.d.ts.map +1 -0
  44. package/dist/_types/hooks/useExportWallet.d.ts +18 -0
  45. package/dist/_types/hooks/useExportWallet.d.ts.map +1 -0
  46. package/dist/_types/hooks/useLoginPasskey.d.ts +18 -0
  47. package/dist/_types/hooks/useLoginPasskey.d.ts.map +1 -0
  48. package/dist/_types/hooks/useRefreshSession.d.ts +18 -0
  49. package/dist/_types/hooks/useRefreshSession.d.ts.map +1 -0
  50. package/dist/_types/hooks/useRegisterPasskey.d.ts +18 -0
  51. package/dist/_types/hooks/useRegisterPasskey.d.ts.map +1 -0
  52. package/dist/_types/hooks/useSendOTP.d.ts +18 -0
  53. package/dist/_types/hooks/useSendOTP.d.ts.map +1 -0
  54. package/dist/_types/hooks/useVerifyOTP.d.ts +18 -0
  55. package/dist/_types/hooks/useVerifyOTP.d.ts.map +1 -0
  56. package/dist/_types/index.d.ts +15 -0
  57. package/dist/_types/index.d.ts.map +1 -0
  58. package/dist/_types/oauth.d.ts +21 -0
  59. package/dist/_types/oauth.d.ts.map +1 -0
  60. package/dist/_types/provider.d.ts +19 -0
  61. package/dist/_types/provider.d.ts.map +1 -0
  62. package/dist/_types/store.d.ts +52 -0
  63. package/dist/_types/store.d.ts.map +1 -0
  64. package/dist/_types/utils/aaUtils.d.ts +2 -0
  65. package/dist/_types/utils/aaUtils.d.ts.map +1 -0
  66. package/dist/_types/utils/timers.d.ts +22 -0
  67. package/dist/_types/utils/timers.d.ts.map +1 -0
  68. package/dist/tsconfig.build.tsbuildinfo +1 -0
  69. package/package.json +48 -0
  70. package/package.json.type +1 -0
  71. package/src/actions.ts +402 -0
  72. package/src/connector.ts +336 -0
  73. package/src/constants.ts +1 -0
  74. package/src/hooks/useAuthenticateOAuth.ts +57 -0
  75. package/src/hooks/useExportWallet.ts +57 -0
  76. package/src/hooks/useLoginPasskey.ts +57 -0
  77. package/src/hooks/useRefreshSession.ts +57 -0
  78. package/src/hooks/useRegisterPasskey.ts +57 -0
  79. package/src/hooks/useSendOTP.ts +57 -0
  80. package/src/hooks/useVerifyOTP.ts +57 -0
  81. package/src/index.ts +14 -0
  82. package/src/oauth.ts +124 -0
  83. package/src/provider.ts +235 -0
  84. package/src/store.ts +113 -0
  85. package/src/utils/aaUtils.ts +5 -0
  86. package/src/utils/timers.ts +80 -0
  87. package/tsconfig.build.json +10 -0
  88. package/tsconfig.build.tsbuildinfo +1 -0
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createProvider = createProvider;
4
+ const wallet_core_1 = require("@zerodev/wallet-core");
5
+ const ox_1 = require("ox");
6
+ const SESSION_WARNING_THRESHOLD_MS = 60 * 1000;
7
+ function createProvider({ store, config, }) {
8
+ const emitter = ox_1.Provider.createEmitter();
9
+ let sessionRefreshTimer = null;
10
+ const scheduleSessionRefresh = () => {
11
+ if (config.autoRefreshSession === false)
12
+ return;
13
+ const state = store.getState();
14
+ if (!state.session || !state.wallet)
15
+ return;
16
+ const expiryMs = (0, wallet_core_1.normalizeTimestamp)(state.session.expiry);
17
+ const now = Date.now();
18
+ const timeUntilExpiry = expiryMs - now;
19
+ if (timeUntilExpiry <= 0) {
20
+ console.log('Session already expired');
21
+ return;
22
+ }
23
+ if (sessionRefreshTimer) {
24
+ clearTimeout(sessionRefreshTimer);
25
+ sessionRefreshTimer = null;
26
+ }
27
+ const threshold = config.sessionWarningThreshold || SESSION_WARNING_THRESHOLD_MS;
28
+ const refreshAt = expiryMs - threshold;
29
+ const timeUntilRefresh = refreshAt - now;
30
+ if (timeUntilRefresh <= 0) {
31
+ console.log('Session expiring soon, refreshing immediately...');
32
+ refreshSessionNow();
33
+ }
34
+ else {
35
+ console.log(`Scheduling session refresh in ${timeUntilRefresh}ms`);
36
+ sessionRefreshTimer = setTimeout(() => {
37
+ refreshSessionNow();
38
+ }, timeUntilRefresh);
39
+ }
40
+ };
41
+ const refreshSessionNow = async () => {
42
+ const state = store.getState();
43
+ if (!state.wallet || !state.session)
44
+ return;
45
+ console.log('Auto-refreshing session...');
46
+ store.getState().setIsExpiring(true);
47
+ try {
48
+ const newSession = await state.wallet.refreshSession(state.session.id);
49
+ console.log('Session refreshed successfully');
50
+ store.getState().setSession(newSession || null);
51
+ store.getState().setIsExpiring(false);
52
+ if (newSession) {
53
+ scheduleSessionRefresh();
54
+ }
55
+ }
56
+ catch (err) {
57
+ console.error('Session refresh failed:', err);
58
+ store.getState().setIsExpiring(false);
59
+ store.getState().clear();
60
+ }
61
+ };
62
+ const unsubscribe = store.subscribe((state) => state.session, () => {
63
+ scheduleSessionRefresh();
64
+ });
65
+ const initialSession = store.getState().session;
66
+ if (initialSession) {
67
+ scheduleSessionRefresh();
68
+ }
69
+ return {
70
+ ...emitter,
71
+ destroy() {
72
+ if (sessionRefreshTimer) {
73
+ clearTimeout(sessionRefreshTimer);
74
+ sessionRefreshTimer = null;
75
+ }
76
+ unsubscribe();
77
+ },
78
+ async request({ method, params }) {
79
+ const state = store.getState();
80
+ const activeChainId = state.chainIds[0];
81
+ switch (method) {
82
+ case 'eth_accounts': {
83
+ const account = state.kernelAccounts.get(activeChainId);
84
+ return account ? [account.address] : [];
85
+ }
86
+ case 'eth_requestAccounts': {
87
+ const account = state.kernelAccounts.get(activeChainId);
88
+ if (!account)
89
+ throw new Error('Not authenticated');
90
+ return [account.address];
91
+ }
92
+ case 'eth_chainId': {
93
+ return `0x${activeChainId.toString(16)}`;
94
+ }
95
+ case 'wallet_sendTransaction':
96
+ case 'eth_sendTransaction': {
97
+ if (!params || params.length === 0) {
98
+ throw new Error('Missing transaction parameters');
99
+ }
100
+ const [tx] = params;
101
+ const chainId = tx.chainId ? parseInt(tx.chainId, 16) : activeChainId;
102
+ const kernelClient = store.getState().kernelClients.get(chainId);
103
+ if (!kernelClient) {
104
+ throw new Error(`No kernel client for chain ${chainId}`);
105
+ }
106
+ const hash = await kernelClient.sendTransaction({
107
+ calls: [
108
+ {
109
+ to: tx.to,
110
+ value: tx.value ? BigInt(tx.value) : 0n,
111
+ data: tx.data || '0x',
112
+ },
113
+ ],
114
+ });
115
+ return hash;
116
+ }
117
+ case 'personal_sign': {
118
+ if (!params || params.length < 2) {
119
+ throw new Error('Missing sign parameters');
120
+ }
121
+ const [message] = params;
122
+ let account = state.kernelAccounts.get(activeChainId);
123
+ if (account &&
124
+ 'isDeployed' in account &&
125
+ !(await account.isDeployed())) {
126
+ account = state.eoaAccount;
127
+ }
128
+ if (!account)
129
+ throw new Error('Not authenticated');
130
+ return await account.signMessage({ message });
131
+ }
132
+ case 'eth_signTypedData_v4': {
133
+ if (!params || params.length < 2) {
134
+ throw new Error('Missing typed data parameters');
135
+ }
136
+ const [, typedDataJson] = params;
137
+ let account = state.kernelAccounts.get(activeChainId);
138
+ if (account &&
139
+ 'isDeployed' in account &&
140
+ !(await account.isDeployed())) {
141
+ account = state.eoaAccount;
142
+ }
143
+ if (!account)
144
+ throw new Error('Not authenticated');
145
+ const typedData = JSON.parse(typedDataJson);
146
+ return await account.signTypedData(typedData);
147
+ }
148
+ case 'wallet_switchEthereumChain': {
149
+ if (!params || params.length === 0) {
150
+ throw new Error('Missing chain parameter');
151
+ }
152
+ const [{ chainId }] = params;
153
+ const chainId_number = parseInt(chainId, 16);
154
+ store.getState().setActiveChain(chainId_number);
155
+ emitter.emit('chainChanged', chainId);
156
+ return null;
157
+ }
158
+ default:
159
+ throw new Error(`Method not supported: ${method}`);
160
+ }
161
+ },
162
+ };
163
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createZeroDevWalletStore = void 0;
4
+ const zustand_1 = require("zustand");
5
+ const middleware_1 = require("zustand/middleware");
6
+ const createZeroDevWalletStore = () => (0, zustand_1.create)()((0, middleware_1.subscribeWithSelector)((0, middleware_1.persist)((set, get) => ({
7
+ wallet: null,
8
+ eoaAccount: null,
9
+ session: null,
10
+ chainIds: [],
11
+ kernelAccounts: new Map(),
12
+ kernelClients: new Map(),
13
+ isExpiring: false,
14
+ oauthConfig: null,
15
+ setWallet: (wallet) => set({ wallet }),
16
+ setEoaAccount: (account) => set({ eoaAccount: account }),
17
+ setKernelAccount: (chainId, account) => {
18
+ const accounts = new Map(get().kernelAccounts);
19
+ accounts.set(chainId, account);
20
+ set({ kernelAccounts: accounts });
21
+ },
22
+ setKernelClient: (chainId, client) => {
23
+ const clients = new Map(get().kernelClients);
24
+ clients.set(chainId, client);
25
+ set({ kernelClients: clients });
26
+ },
27
+ setSession: (session) => set({ session }),
28
+ setActiveChain: (chainId) => {
29
+ const { chainIds } = get();
30
+ set({
31
+ chainIds: [chainId, ...chainIds.filter((id) => id !== chainId)],
32
+ });
33
+ },
34
+ setIsExpiring: (isExpiring) => set({ isExpiring }),
35
+ setOAuthConfig: (config) => set({ oauthConfig: config }),
36
+ clear: () => set({
37
+ eoaAccount: null,
38
+ session: null,
39
+ kernelAccounts: new Map(),
40
+ kernelClients: new Map(),
41
+ isExpiring: false,
42
+ chainIds: [],
43
+ }),
44
+ }), {
45
+ name: 'zerodev-wallet',
46
+ partialize: (state) => ({
47
+ session: state.session,
48
+ chainIds: state.chainIds,
49
+ }),
50
+ })));
51
+ exports.createZeroDevWalletStore = createZeroDevWalletStore;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAAUrl = getAAUrl;
4
+ const constants_js_1 = require("../constants.js");
5
+ function getAAUrl(chainId, aaUrl) {
6
+ return aaUrl || `${constants_js_1.ZERODEV_AA_URL}${chainId}/chain/${chainId}`;
7
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_DELAY_MS = void 0;
4
+ exports.setCappedTimeout = setCappedTimeout;
5
+ exports.putTimer = putTimer;
6
+ exports.clearKey = clearKey;
7
+ exports.clearAll = clearAll;
8
+ exports.setCappedTimeoutInMap = setCappedTimeoutInMap;
9
+ exports.MAX_DELAY_MS = 2_147_483_647;
10
+ function toIntMs(x) {
11
+ return Math.max(0, Math.floor(Number.isFinite(x) ? x : 0));
12
+ }
13
+ function setCappedTimeout(cb, delayMs) {
14
+ const target = Date.now() + toIntMs(delayMs);
15
+ let handle;
16
+ const tick = () => {
17
+ const remaining = target - Date.now();
18
+ if (remaining <= 0) {
19
+ cb();
20
+ return;
21
+ }
22
+ handle = setTimeout(tick, Math.min(exports.MAX_DELAY_MS, remaining));
23
+ };
24
+ tick();
25
+ return {
26
+ clear() {
27
+ if (handle !== undefined) {
28
+ clearTimeout(handle);
29
+ handle = undefined;
30
+ }
31
+ },
32
+ };
33
+ }
34
+ function putTimer(map, key, controller) {
35
+ map[key]?.clear?.();
36
+ map[key] = controller;
37
+ }
38
+ function clearKey(map, key) {
39
+ map[key]?.clear?.();
40
+ delete map[key];
41
+ }
42
+ function clearAll(map) {
43
+ for (const k of Object.keys(map)) {
44
+ map[k]?.clear?.();
45
+ delete map[k];
46
+ }
47
+ }
48
+ function setCappedTimeoutInMap(map, key, cb, delayMs) {
49
+ putTimer(map, key, setCappedTimeout(cb, delayMs));
50
+ }
@@ -0,0 +1,225 @@
1
+ import { connect as wagmiConnect } from '@wagmi/core/actions';
2
+ import { buildOAuthUrl, generateOAuthNonce, openOAuthPopup, pollOAuthPopup, } from './oauth.js';
3
+ /**
4
+ * Get ZeroDev connector from config
5
+ */
6
+ function getZeroDevConnector(config) {
7
+ const connector = config.connectors.find((c) => c.id === 'zerodev-wallet');
8
+ if (!connector) {
9
+ throw new Error('ZeroDev connector not found in Wagmi config');
10
+ }
11
+ return connector;
12
+ }
13
+ /**
14
+ * Register with passkey
15
+ */
16
+ export async function registerPasskey(config, parameters) {
17
+ const connector = parameters.connector ?? getZeroDevConnector(config);
18
+ // @ts-expect-error - getStore is a custom method
19
+ const store = await connector.getStore();
20
+ const wallet = store.getState().wallet;
21
+ if (!wallet)
22
+ throw new Error('Wallet not initialized');
23
+ await wallet.auth({
24
+ type: 'passkey',
25
+ email: parameters.email,
26
+ mode: 'register',
27
+ });
28
+ const [session, eoaAccount] = await Promise.all([
29
+ wallet.getSession(),
30
+ wallet.toAccount(),
31
+ ]);
32
+ store.getState().setEoaAccount(eoaAccount);
33
+ store.getState().setSession(session || null);
34
+ // Auto-connect to Wagmi
35
+ await wagmiConnect(config, { connector });
36
+ }
37
+ /**
38
+ * Login with passkey
39
+ */
40
+ export async function loginPasskey(config, parameters) {
41
+ const connector = parameters.connector ?? getZeroDevConnector(config);
42
+ // @ts-expect-error - getStore is a custom method
43
+ const store = await connector.getStore();
44
+ const wallet = store.getState().wallet;
45
+ if (!wallet)
46
+ throw new Error('Wallet not initialized');
47
+ await wallet.auth({
48
+ type: 'passkey',
49
+ email: parameters.email,
50
+ mode: 'login',
51
+ });
52
+ const [session, eoaAccount] = await Promise.all([
53
+ wallet.getSession(),
54
+ wallet.toAccount(),
55
+ ]);
56
+ store.getState().setEoaAccount(eoaAccount);
57
+ store.getState().setSession(session || null);
58
+ // Auto-connect to Wagmi
59
+ await wagmiConnect(config, { connector });
60
+ }
61
+ /**
62
+ * Authenticate with OAuth (opens popup)
63
+ */
64
+ export async function authenticateOAuth(config, parameters) {
65
+ const connector = parameters.connector ?? getZeroDevConnector(config);
66
+ // @ts-expect-error - getStore is a custom method
67
+ const store = await connector.getStore();
68
+ const wallet = store.getState().wallet;
69
+ const oauthConfig = store.getState().oauthConfig;
70
+ if (!wallet)
71
+ throw new Error('Wallet not initialized');
72
+ if (!oauthConfig) {
73
+ throw new Error('OAuth is not configured. Please provide oauthConfig to zeroDevWallet connector.');
74
+ }
75
+ // Get client ID for the provider
76
+ let clientId = parameters.clientId;
77
+ if (!clientId) {
78
+ clientId = oauthConfig.googleClientId;
79
+ }
80
+ if (!clientId) {
81
+ throw new Error(`Client ID not configured for ${parameters.provider}`);
82
+ }
83
+ if (!oauthConfig.redirectUri) {
84
+ throw new Error('OAuth redirect URI is not configured.');
85
+ }
86
+ // Generate nonce from wallet public key
87
+ const publicKey = await wallet.getPublicKey();
88
+ if (!publicKey) {
89
+ throw new Error('Failed to get wallet public key');
90
+ }
91
+ const nonce = generateOAuthNonce(publicKey);
92
+ // Build OAuth URL
93
+ const oauthUrl = buildOAuthUrl({
94
+ provider: parameters.provider,
95
+ clientId,
96
+ redirectUri: oauthConfig.redirectUri,
97
+ nonce,
98
+ });
99
+ // Open popup
100
+ const authWindow = openOAuthPopup(oauthUrl);
101
+ if (!authWindow) {
102
+ throw new Error(`Failed to open ${parameters.provider} login window.`);
103
+ }
104
+ // Poll for OAuth completion
105
+ return new Promise((resolve, reject) => {
106
+ pollOAuthPopup(authWindow, window.location.origin, async (idToken) => {
107
+ try {
108
+ // Complete OAuth authentication with wallet-core
109
+ await wallet.auth({
110
+ type: 'oauth',
111
+ provider: parameters.provider,
112
+ credential: idToken,
113
+ });
114
+ const [session, eoaAccount] = await Promise.all([
115
+ wallet.getSession(),
116
+ wallet.toAccount(),
117
+ ]);
118
+ store.getState().setEoaAccount(eoaAccount);
119
+ store.getState().setSession(session || null);
120
+ // Auto-connect to Wagmi
121
+ await wagmiConnect(config, { connector });
122
+ resolve();
123
+ }
124
+ catch (err) {
125
+ reject(err);
126
+ }
127
+ }, reject);
128
+ });
129
+ }
130
+ /**
131
+ * Send OTP via email
132
+ */
133
+ export async function sendOTP(config, parameters) {
134
+ const connector = parameters.connector ?? getZeroDevConnector(config);
135
+ // @ts-expect-error - getStore is a custom method
136
+ const store = await connector.getStore();
137
+ const wallet = store.getState().wallet;
138
+ if (!wallet)
139
+ throw new Error('Wallet not initialized');
140
+ const result = await wallet.auth({
141
+ type: 'otp',
142
+ mode: 'sendOtp',
143
+ email: parameters.email,
144
+ contact: { type: 'email', contact: parameters.email },
145
+ ...(parameters.emailCustomization && {
146
+ emailCustomization: parameters.emailCustomization,
147
+ }),
148
+ });
149
+ return {
150
+ otpId: result.otpId,
151
+ subOrganizationId: result.subOrganizationId,
152
+ };
153
+ }
154
+ /**
155
+ * Verify OTP code
156
+ */
157
+ export async function verifyOTP(config, parameters) {
158
+ const connector = parameters.connector ?? getZeroDevConnector(config);
159
+ // @ts-expect-error - getStore is a custom method
160
+ const store = await connector.getStore();
161
+ const wallet = store.getState().wallet;
162
+ if (!wallet)
163
+ throw new Error('Wallet not initialized');
164
+ await wallet.auth({
165
+ type: 'otp',
166
+ mode: 'verifyOtp',
167
+ otpId: parameters.otpId,
168
+ otpCode: parameters.code,
169
+ subOrganizationId: parameters.subOrganizationId,
170
+ });
171
+ const [session, eoaAccount] = await Promise.all([
172
+ wallet.getSession(),
173
+ wallet.toAccount(),
174
+ ]);
175
+ store.getState().setEoaAccount(eoaAccount);
176
+ store.getState().setSession(session || null);
177
+ // Auto-connect to Wagmi
178
+ await wagmiConnect(config, { connector });
179
+ }
180
+ /**
181
+ * Refresh session
182
+ */
183
+ export async function refreshSession(config, parameters = {}) {
184
+ const connector = parameters.connector ?? getZeroDevConnector(config);
185
+ // @ts-expect-error - getStore is a custom method
186
+ const store = await connector.getStore();
187
+ const wallet = store.getState().wallet;
188
+ const currentSession = store.getState().session;
189
+ if (!wallet || !currentSession) {
190
+ throw new Error('No active session to refresh');
191
+ }
192
+ const newSession = await wallet.refreshSession(currentSession.id);
193
+ store.getState().setSession(newSession || null);
194
+ return newSession;
195
+ }
196
+ /**
197
+ * Export wallet
198
+ */
199
+ export async function exportWallet(config, parameters) {
200
+ const connector = parameters.connector ?? getZeroDevConnector(config);
201
+ // @ts-expect-error - getStore is a custom method
202
+ const store = await connector.getStore();
203
+ const wallet = store.getState().wallet;
204
+ if (!wallet)
205
+ throw new Error('Wallet not initialized');
206
+ const { exportWallet: exportWalletSdk, createIframeStamper } = await import('@zerodev/wallet-core');
207
+ const iframeContainer = document.getElementById(parameters.iframeContainerId);
208
+ if (!iframeContainer) {
209
+ throw new Error('Iframe container not found');
210
+ }
211
+ const iframeStamper = await createIframeStamper({
212
+ iframeUrl: 'https://export.turnkey.com',
213
+ iframeContainer,
214
+ iframeElementId: 'export-wallet-iframe',
215
+ });
216
+ const publicKey = await iframeStamper.init();
217
+ const { exportBundle, organizationId } = await exportWalletSdk({
218
+ wallet,
219
+ targetPublicKey: publicKey,
220
+ });
221
+ const success = await iframeStamper.injectWalletExportBundle(exportBundle, organizationId);
222
+ if (success !== true) {
223
+ throw new Error('Failed to inject export bundle');
224
+ }
225
+ }