@mocanetwork/airkit 1.3.0 → 1.4.0-beta.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.
- package/dist/airkit.cjs.js +850 -594
- package/dist/airkit.esm.js +850 -594
- package/dist/airkit.umd.js +850 -594
- package/dist/types/airService.d.ts +6 -0
- package/dist/types/airWalletProvider.d.ts +4 -3
- package/dist/types/authMessageService.d.ts +6 -1
- package/dist/types/common/air/messaging/auth.d.ts +48 -4
- package/dist/types/common/air/messaging/messageServiceBase.d.ts +1 -1
- package/dist/types/common/air/messaging/messageServiceWindowHandlingBase.d.ts +11 -0
- package/dist/types/common/air/messaging/recovery.d.ts +31 -0
- package/dist/types/common/air/messaging/wallet.d.ts +8 -22
- package/dist/types/common/air/messaging/window.d.ts +28 -0
- package/dist/types/common/provider/types.d.ts +17 -12
- package/dist/types/common/realm/partner/config.d.ts +1 -0
- package/dist/types/iframeController.d.ts +2 -0
- package/dist/types/interfaces.d.ts +2 -0
- package/dist/types/recoveryMessageService.d.ts +17 -0
- package/dist/types/walletMessageService.d.ts +5 -3
- package/package.json +1 -1
package/dist/airkit.umd.js
CHANGED
|
@@ -101,13 +101,19 @@
|
|
|
101
101
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
+
var version = "1.4.0-beta.1";
|
|
105
|
+
var airkitPackage = {
|
|
106
|
+
version: version};
|
|
107
|
+
|
|
104
108
|
const AirAuthMessageTypes = {
|
|
105
109
|
AUTH_SETUP_COMPLETED: "air_auth_setup_completed",
|
|
106
110
|
INITIALIZATION_REQUEST: "air_auth_initialization_request",
|
|
107
111
|
INITIALIZATION_RESPONSE: "air_auth_initialization_response",
|
|
108
112
|
LOGIN_REQUEST: "air_auth_login_request",
|
|
109
113
|
LOGIN_RESPONSE: "air_auth_login_response",
|
|
110
|
-
|
|
114
|
+
LOGIN_SERVICE_RESPONSE: "air_auth_login_service_response",
|
|
115
|
+
PASSKEY_LOGIN_REQUEST: "air_auth_passkey_login_request",
|
|
116
|
+
PASSKEY_LOGIN_RESPONSE: "air_auth_passkey_login_response",
|
|
111
117
|
USER_INFO_REQUEST: "air_auth_user_info_request",
|
|
112
118
|
USER_INFO_RESPONSE: "air_auth_user_info_response",
|
|
113
119
|
PARTNER_USER_INFO_REQUEST: "air_auth_partner_user_info_request",
|
|
@@ -120,17 +126,38 @@
|
|
|
120
126
|
IFRAME_VISIBILITY_REQUEST: "air_auth_iframe_visibility_request",
|
|
121
127
|
SETUP_WALLET_REQUEST: "air_auth_setup_wallet_request",
|
|
122
128
|
SETUP_WALLET_RESPONSE: "air_auth_setup_wallet_response",
|
|
129
|
+
SETUP_RECOVERY_REQUEST: "air_auth_setup_recovery_request",
|
|
130
|
+
SETUP_RECOVERY_RESPONSE: "air_auth_setup_recovery_response",
|
|
123
131
|
SIGN_SIWE_MESSAGE_REQUEST: "air_auth_sign_siwe_message_request",
|
|
124
132
|
SIGN_SIWE_MESSAGE_RESPONSE: "air_auth_sign_siwe_message_response",
|
|
125
133
|
CROSS_PARTNER_TOKEN_REQUEST: "air_auth_cross_partner_token_request",
|
|
126
134
|
CROSS_PARTNER_TOKEN_RESPONSE: "air_auth_cross_partner_token_response",
|
|
127
135
|
PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_partner_access_token_request",
|
|
128
136
|
PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_partner_access_token_response",
|
|
137
|
+
PRIVY_LOGIN_REQUEST: "air_auth_privy_login_request",
|
|
138
|
+
PRIVY_LOGIN_RESPONSE: "air_auth_privy_login_response",
|
|
129
139
|
CREDENTIAL_SALT_REQUEST: "air_auth_credential_salt_request",
|
|
130
140
|
CREDENTIAL_SALT_RESPONSE: "air_auth_credential_salt_response",
|
|
131
141
|
LOGOUT_REQUEST: "air_auth_logout_request",
|
|
132
142
|
LOGOUT_RESPONSE: "air_auth_logout_response",
|
|
133
|
-
RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication"
|
|
143
|
+
RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication",
|
|
144
|
+
INIT_RECOVERY_COMMUNICATION: "air_auth_init_recovery_communication",
|
|
145
|
+
RESET_RECOVERY_COMMUNICATION: "air_auth_reset_recovery_communication",
|
|
146
|
+
START_RECOVERY_REQUEST: "air_start_recovery_request",
|
|
147
|
+
START_RECOVERY_RESPONSE: "air_start_recovery_response",
|
|
148
|
+
OTP_REQUEST: "air_auth_otp_request",
|
|
149
|
+
OTP_RESPONSE: "air_auth_otp_response"
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const AirRecoveryMessageTypes = {
|
|
153
|
+
SERVICE_STARTED: "air_recovery_service_started",
|
|
154
|
+
INITIALIZATION_REQUEST: "air_recovery_initialization_request",
|
|
155
|
+
INITIALIZATION_RESPONSE: "air_recovery_initialization_response",
|
|
156
|
+
INIT_AUTH_COMMUNICATION: "air_recovery_init_auth_communication",
|
|
157
|
+
RECOVERY_INITIALIZED: "air_recovery_initialized",
|
|
158
|
+
RECOVERY_IFRAME_VISIBILITY_REQUEST: "air_recovery_iframe_visibility_request",
|
|
159
|
+
LOGOUT_REQUEST: "air_recovery_logout_request",
|
|
160
|
+
LOGOUT_RESPONSE: "air_recovery_logout_response"
|
|
134
161
|
};
|
|
135
162
|
|
|
136
163
|
const AirWalletMessageTypes = {
|
|
@@ -145,234 +172,25 @@
|
|
|
145
172
|
SETUP_OR_UPDATE_MFA_RESPONSE: "air_setup_mfa_response",
|
|
146
173
|
CLAIM_ID_REQUEST: "air_claim_id_request",
|
|
147
174
|
CLAIM_ID_RESPONSE: "air_claim_id_response",
|
|
175
|
+
SHOW_SWAP_UI_REQUEST: "air_show_swap_ui_request",
|
|
176
|
+
SHOW_SWAP_UI_RESPONSE: "air_show_swap_ui_response",
|
|
148
177
|
DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request",
|
|
149
178
|
DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response",
|
|
150
179
|
WALLET_IFRAME_VISIBILITY_REQUEST: "air_wallet_iframe_visibility_request",
|
|
151
|
-
OPEN_WINDOW_REQUEST: "air_open_window_request",
|
|
152
|
-
OPEN_WINDOW_RESPONSE: "air_open_window_response",
|
|
153
|
-
OPEN_WINDOW_RETRY_REQUEST: "air_open_window_retry_request",
|
|
154
|
-
OPEN_WINDOW_RETRY_RESPONSE: "air_open_window_retry_response",
|
|
155
|
-
WINDOW_CLOSED: "air_window_closed",
|
|
156
180
|
IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request",
|
|
157
181
|
IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
|
|
158
182
|
LOGOUT_REQUEST: "air_logout_request",
|
|
159
183
|
LOGOUT_RESPONSE: "air_logout_response"
|
|
160
184
|
};
|
|
161
185
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
super(message || name);
|
|
169
|
-
this.name = name;
|
|
170
|
-
this.stack = cause?.stack;
|
|
171
|
-
this.cause = cause;
|
|
172
|
-
this.context = context;
|
|
173
|
-
}
|
|
174
|
-
toJSON() {
|
|
175
|
-
return {
|
|
176
|
-
name: this.name,
|
|
177
|
-
message: this.message,
|
|
178
|
-
context: this.context,
|
|
179
|
-
cause: this.cause
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
function ensureError(value) {
|
|
184
|
-
if (value instanceof Error) return value;
|
|
185
|
-
let stringified = "[Unable to stringify the thrown value]";
|
|
186
|
-
try {
|
|
187
|
-
stringified = JSON.stringify(value);
|
|
188
|
-
} catch {
|
|
189
|
-
// ignoring failed stringify
|
|
190
|
-
}
|
|
191
|
-
return new Error(`This value was not thrown as type Error: ${stringified}`);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const BUILD_ENV = {
|
|
195
|
-
PRODUCTION: "production",
|
|
196
|
-
UAT: "uat",
|
|
197
|
-
STAGING: "staging",
|
|
198
|
-
DEVELOPMENT: "development",
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const AIR_URLS = {
|
|
202
|
-
[BUILD_ENV.DEVELOPMENT]: {
|
|
203
|
-
authUrl: "http://localhost:8200/auth/",
|
|
204
|
-
walletUrl: "http://localhost:8200/wallet/",
|
|
205
|
-
},
|
|
206
|
-
[BUILD_ENV.UAT]: {
|
|
207
|
-
authUrl: "https://account.uat.air3.com/auth/",
|
|
208
|
-
walletUrl: "https://account.uat.air3.com/wallet/",
|
|
209
|
-
},
|
|
210
|
-
[BUILD_ENV.STAGING]: {
|
|
211
|
-
authUrl: "https://account.staging.air3.com/auth/",
|
|
212
|
-
walletUrl: "https://account.staging.air3.com/wallet/",
|
|
213
|
-
},
|
|
214
|
-
[BUILD_ENV.PRODUCTION]: {
|
|
215
|
-
authUrl: "https://account.air3.com/auth/",
|
|
216
|
-
walletUrl: "https://account.air3.com/wallet/",
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
const isElement = (element) => element instanceof Element || element instanceof Document;
|
|
220
|
-
const randomId = () => Math.random().toString(36).slice(2);
|
|
221
|
-
const extractErrorHash = (message) => {
|
|
222
|
-
if (!message)
|
|
223
|
-
return "";
|
|
224
|
-
// Format: "reason: 0x..."
|
|
225
|
-
if (message.includes("reason:")) {
|
|
226
|
-
return message.split("reason:")[1].trim();
|
|
227
|
-
}
|
|
228
|
-
// Format: "UserOperation reverted during simulation with reason: 0x..."
|
|
229
|
-
if (message.includes("with reason:")) {
|
|
230
|
-
const match = message.match(/with reason: (0x[a-fA-F0-9]+)/);
|
|
231
|
-
return match ? match[1].trim() : "";
|
|
232
|
-
}
|
|
233
|
-
// Look for any 0x pattern that could be a hash
|
|
234
|
-
const hexMatch = message.match(/(0x[a-fA-F0-9]{8,})/);
|
|
235
|
-
return hexMatch ? hexMatch[1].trim() : "";
|
|
186
|
+
const AirWindowMessageTypes = {
|
|
187
|
+
OPEN_WINDOW_REQUEST: "air_open_window_request",
|
|
188
|
+
OPEN_WINDOW_RESPONSE: "air_open_window_response",
|
|
189
|
+
OPEN_WINDOW_RETRY_REQUEST: "air_open_window_retry_request",
|
|
190
|
+
OPEN_WINDOW_RETRY_RESPONSE: "air_open_window_retry_response",
|
|
191
|
+
WINDOW_CLOSED: "air_window_closed"
|
|
236
192
|
};
|
|
237
193
|
|
|
238
|
-
class AirServiceError extends BaseError {
|
|
239
|
-
static from(error) {
|
|
240
|
-
if (error instanceof AirServiceError) {
|
|
241
|
-
return error;
|
|
242
|
-
}
|
|
243
|
-
else if (error instanceof Object && "message" in error) {
|
|
244
|
-
if (error.message === "User cancelled login") {
|
|
245
|
-
return new AirServiceError("USER_CANCELLED", error.message);
|
|
246
|
-
}
|
|
247
|
-
return new AirServiceError("UNKNOWN_ERROR", error.message.toString());
|
|
248
|
-
}
|
|
249
|
-
return new AirServiceError("UNKNOWN_ERROR");
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
class ProviderRpcError extends Error {
|
|
253
|
-
constructor(message) {
|
|
254
|
-
super(message);
|
|
255
|
-
this.metaMessages = [];
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
class UserRejectedRequestError extends ProviderRpcError {
|
|
259
|
-
constructor() {
|
|
260
|
-
super(...arguments);
|
|
261
|
-
this.code = 4001;
|
|
262
|
-
this.name = "UserRejectedRequestError";
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
class UnauthorizedProviderError extends ProviderRpcError {
|
|
266
|
-
constructor() {
|
|
267
|
-
super(...arguments);
|
|
268
|
-
this.code = 4100;
|
|
269
|
-
this.name = "UnauthorizedProviderError";
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
class UnsupportedProviderMethodError extends ProviderRpcError {
|
|
273
|
-
constructor() {
|
|
274
|
-
super(...arguments);
|
|
275
|
-
this.code = 4200;
|
|
276
|
-
this.name = "UnsupportedProviderMethodError";
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
class ProviderDisconnectedError extends ProviderRpcError {
|
|
280
|
-
constructor() {
|
|
281
|
-
super(...arguments);
|
|
282
|
-
this.code = 4900;
|
|
283
|
-
this.name = "ProviderDisconnectedError";
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
class ChainDisconnectedError extends ProviderRpcError {
|
|
287
|
-
constructor() {
|
|
288
|
-
super(...arguments);
|
|
289
|
-
this.code = 4901;
|
|
290
|
-
this.name = "ChainDisconnectedError";
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
class SwitchChainError extends ProviderRpcError {
|
|
294
|
-
constructor() {
|
|
295
|
-
super(...arguments);
|
|
296
|
-
this.code = 4902;
|
|
297
|
-
this.name = "SwitchChainError";
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
class TransactionRejectedRpcError extends ProviderRpcError {
|
|
301
|
-
constructor(message) {
|
|
302
|
-
// Remove the "Version: viem@x.x.x" suffix if present
|
|
303
|
-
const cleanMessage = message.replace(/\nVersion:.*$/, '');
|
|
304
|
-
super(cleanMessage);
|
|
305
|
-
this.code = -32003;
|
|
306
|
-
this.name = "TransactionRejectedRpcError";
|
|
307
|
-
// Parse the error hash from the message
|
|
308
|
-
this.metaMessages.push(extractErrorHash(cleanMessage));
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
class InvalidRequestRpcError extends ProviderRpcError {
|
|
312
|
-
constructor() {
|
|
313
|
-
super(...arguments);
|
|
314
|
-
this.code = -32600;
|
|
315
|
-
this.name = "InvalidRequestRpcError";
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
class MethodNotFoundRpcError extends ProviderRpcError {
|
|
319
|
-
constructor() {
|
|
320
|
-
super(...arguments);
|
|
321
|
-
this.code = -32601;
|
|
322
|
-
this.name = "MethodNotFoundRpcError";
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
class InvalidParamsRpcError extends ProviderRpcError {
|
|
326
|
-
constructor() {
|
|
327
|
-
super(...arguments);
|
|
328
|
-
this.code = -32602;
|
|
329
|
-
this.name = "InvalidParamsRpcError";
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
class InternalRpcError extends ProviderRpcError {
|
|
333
|
-
constructor() {
|
|
334
|
-
super(...arguments);
|
|
335
|
-
this.code = -32603;
|
|
336
|
-
this.name = "InternalRpcError";
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
function ensureProviderRpcError(value) {
|
|
340
|
-
if (value instanceof ProviderRpcError) {
|
|
341
|
-
return value;
|
|
342
|
-
}
|
|
343
|
-
if (typeof value === "object" &&
|
|
344
|
-
value !== null &&
|
|
345
|
-
"errorCode" in value &&
|
|
346
|
-
"errorMessage" in value) {
|
|
347
|
-
if (typeof value.errorCode === "number" && typeof value.errorMessage === "string") {
|
|
348
|
-
switch (value.errorCode) {
|
|
349
|
-
case 4001:
|
|
350
|
-
return new UserRejectedRequestError(value.errorMessage);
|
|
351
|
-
case 4100:
|
|
352
|
-
return new UnauthorizedProviderError(value.errorMessage);
|
|
353
|
-
case 4200:
|
|
354
|
-
return new UnsupportedProviderMethodError(value.errorMessage);
|
|
355
|
-
case 4900:
|
|
356
|
-
return new ProviderDisconnectedError(value.errorMessage);
|
|
357
|
-
case 4901:
|
|
358
|
-
return new ChainDisconnectedError(value.errorMessage);
|
|
359
|
-
case 4902:
|
|
360
|
-
return new SwitchChainError(value.errorMessage);
|
|
361
|
-
case -32003:
|
|
362
|
-
return new TransactionRejectedRpcError(value.errorMessage);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
let stringified = "[Unable to stringify the thrown value]";
|
|
367
|
-
try {
|
|
368
|
-
stringified = JSON.stringify(value);
|
|
369
|
-
}
|
|
370
|
-
catch {
|
|
371
|
-
// ignoring failed stringify
|
|
372
|
-
}
|
|
373
|
-
return new InternalRpcError(`Invalid value for ProviderRpcError: ${stringified}`);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
194
|
function getDefaultExportFromCjs (x) {
|
|
377
195
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
378
196
|
}
|
|
@@ -704,11 +522,259 @@
|
|
|
704
522
|
var loglevelExports = requireLoglevel();
|
|
705
523
|
var log = /*@__PURE__*/getDefaultExportFromCjs(loglevelExports);
|
|
706
524
|
|
|
707
|
-
|
|
708
|
-
|
|
525
|
+
class BaseError extends Error {
|
|
526
|
+
constructor(name, message, options = {}) {
|
|
527
|
+
const {
|
|
528
|
+
cause,
|
|
529
|
+
context
|
|
530
|
+
} = options;
|
|
531
|
+
super(message || name);
|
|
532
|
+
this.name = name;
|
|
533
|
+
this.stack = cause?.stack;
|
|
534
|
+
this.cause = cause;
|
|
535
|
+
this.context = context;
|
|
536
|
+
}
|
|
537
|
+
toJSON() {
|
|
538
|
+
return {
|
|
539
|
+
name: this.name,
|
|
540
|
+
message: this.message,
|
|
541
|
+
context: this.context,
|
|
542
|
+
cause: this.cause
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function ensureError(value) {
|
|
547
|
+
if (value instanceof Error) return value;
|
|
548
|
+
let stringified = "[Unable to stringify the thrown value]";
|
|
549
|
+
try {
|
|
550
|
+
stringified = JSON.stringify(value);
|
|
551
|
+
} catch {
|
|
552
|
+
// ignoring failed stringify
|
|
553
|
+
}
|
|
554
|
+
return new Error(`This value was not thrown as type Error: ${stringified}`);
|
|
709
555
|
}
|
|
710
556
|
|
|
711
|
-
|
|
557
|
+
const getLevelName = levelNum => {
|
|
558
|
+
const levelNames = Object.keys(log.levels);
|
|
559
|
+
if (levelNum >= 0 && levelNum < levelNames.length) {
|
|
560
|
+
return levelNames[levelNum];
|
|
561
|
+
}
|
|
562
|
+
return "UNKNOWN";
|
|
563
|
+
};
|
|
564
|
+
const configureLogLevel = (environment, enableLogging) => {
|
|
565
|
+
let level = log.levels.ERROR;
|
|
566
|
+
if (environment === "development") {
|
|
567
|
+
level = enableLogging ? log.levels.TRACE : log.levels.INFO;
|
|
568
|
+
} else if (environment === "staging") {
|
|
569
|
+
level = enableLogging ? log.levels.DEBUG : log.levels.INFO;
|
|
570
|
+
} else if (environment === "uat") {
|
|
571
|
+
level = enableLogging ? log.levels.INFO : log.levels.WARN;
|
|
572
|
+
} else if (environment === "production") {
|
|
573
|
+
// Be cautious with enabling more than WARN in prod
|
|
574
|
+
level = enableLogging ? log.levels.WARN : log.levels.ERROR;
|
|
575
|
+
}
|
|
576
|
+
log.setLevel(level);
|
|
577
|
+
log.info(`[${window?.location?.href}] LogLevel: ${getLevelName(log.getLevel())}`);
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
const BUILD_ENV = {
|
|
581
|
+
PRODUCTION: "production",
|
|
582
|
+
UAT: "uat",
|
|
583
|
+
STAGING: "staging",
|
|
584
|
+
DEVELOPMENT: "development",
|
|
585
|
+
SANDBOX: "sandbox",
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
const AIR_URLS = {
|
|
589
|
+
[BUILD_ENV.DEVELOPMENT]: {
|
|
590
|
+
authUrl: "http://localhost:8200/auth/",
|
|
591
|
+
walletUrl: "http://localhost:8200/wallet/",
|
|
592
|
+
recoveryUrl: "http://localhost:8200/recovery/",
|
|
593
|
+
},
|
|
594
|
+
[BUILD_ENV.STAGING]: {
|
|
595
|
+
authUrl: "https://account.staging.air3.com/auth/",
|
|
596
|
+
walletUrl: "https://account.staging.air3.com/wallet/",
|
|
597
|
+
recoveryUrl: "https://account.staging.air3.com/recovery/",
|
|
598
|
+
},
|
|
599
|
+
[BUILD_ENV.UAT]: {
|
|
600
|
+
authUrl: "https://account.uat.air3.com/auth/",
|
|
601
|
+
walletUrl: "https://account.uat.air3.com/wallet/",
|
|
602
|
+
recoveryUrl: "https://account.uat.air3.com/recovery/",
|
|
603
|
+
},
|
|
604
|
+
[BUILD_ENV.SANDBOX]: {
|
|
605
|
+
authUrl: "https://account.sandbox.air3.com/auth/",
|
|
606
|
+
walletUrl: "https://account.sandbox.air3.com/wallet/",
|
|
607
|
+
recoveryUrl: "https://account.sandbox.air3.com/recovery/",
|
|
608
|
+
},
|
|
609
|
+
[BUILD_ENV.PRODUCTION]: {
|
|
610
|
+
authUrl: "https://account.air3.com/auth/",
|
|
611
|
+
walletUrl: "https://account.air3.com/wallet/",
|
|
612
|
+
recoveryUrl: "https://account.air3.com/recovery/",
|
|
613
|
+
},
|
|
614
|
+
};
|
|
615
|
+
const isElement = (element) => element instanceof Element || element instanceof Document;
|
|
616
|
+
const randomId = () => Math.random().toString(36).slice(2);
|
|
617
|
+
const extractErrorHash = (message) => {
|
|
618
|
+
if (!message)
|
|
619
|
+
return "";
|
|
620
|
+
// Format: "reason: 0x..."
|
|
621
|
+
if (message.includes("reason:")) {
|
|
622
|
+
const match = message.match(/reason:\s*(0x[a-fA-F0-9]+)/);
|
|
623
|
+
return match ? match[1].trim() : "";
|
|
624
|
+
}
|
|
625
|
+
// Format: "UserOperation reverted during simulation with reason: 0x..."
|
|
626
|
+
if (message.includes("with reason:")) {
|
|
627
|
+
const match = message.match(/with reason:\s*(0x[a-fA-F0-9]+)/);
|
|
628
|
+
return match ? match[1].trim() : "";
|
|
629
|
+
}
|
|
630
|
+
// Look for any 0x pattern that could be a hash
|
|
631
|
+
const hexMatch = message.match(/(0x[a-fA-F0-9]{8,})/);
|
|
632
|
+
return hexMatch ? hexMatch[1].trim() : "";
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
class AirServiceError extends BaseError {
|
|
636
|
+
static from(error) {
|
|
637
|
+
if (error instanceof AirServiceError) {
|
|
638
|
+
return error;
|
|
639
|
+
}
|
|
640
|
+
else if (error instanceof Object && "message" in error) {
|
|
641
|
+
if (error.message === "User cancelled login") {
|
|
642
|
+
return new AirServiceError("USER_CANCELLED", error.message);
|
|
643
|
+
}
|
|
644
|
+
return new AirServiceError("UNKNOWN_ERROR", error.message.toString());
|
|
645
|
+
}
|
|
646
|
+
return new AirServiceError("UNKNOWN_ERROR");
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
class ProviderRpcError extends Error {
|
|
650
|
+
constructor(message) {
|
|
651
|
+
super(message);
|
|
652
|
+
this.metaMessages = [];
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
class UserRejectedRequestError extends ProviderRpcError {
|
|
656
|
+
constructor() {
|
|
657
|
+
super(...arguments);
|
|
658
|
+
this.code = 4001;
|
|
659
|
+
this.name = "UserRejectedRequestError";
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
class UnauthorizedProviderError extends ProviderRpcError {
|
|
663
|
+
constructor() {
|
|
664
|
+
super(...arguments);
|
|
665
|
+
this.code = 4100;
|
|
666
|
+
this.name = "UnauthorizedProviderError";
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
class UnsupportedProviderMethodError extends ProviderRpcError {
|
|
670
|
+
constructor() {
|
|
671
|
+
super(...arguments);
|
|
672
|
+
this.code = 4200;
|
|
673
|
+
this.name = "UnsupportedProviderMethodError";
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
class ProviderDisconnectedError extends ProviderRpcError {
|
|
677
|
+
constructor() {
|
|
678
|
+
super(...arguments);
|
|
679
|
+
this.code = 4900;
|
|
680
|
+
this.name = "ProviderDisconnectedError";
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
class ChainDisconnectedError extends ProviderRpcError {
|
|
684
|
+
constructor() {
|
|
685
|
+
super(...arguments);
|
|
686
|
+
this.code = 4901;
|
|
687
|
+
this.name = "ChainDisconnectedError";
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
class SwitchChainError extends ProviderRpcError {
|
|
691
|
+
constructor() {
|
|
692
|
+
super(...arguments);
|
|
693
|
+
this.code = 4902;
|
|
694
|
+
this.name = "SwitchChainError";
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
class TransactionRejectedRpcError extends ProviderRpcError {
|
|
698
|
+
constructor(message) {
|
|
699
|
+
// Remove the "Version: viem@x.x.x" suffix if present
|
|
700
|
+
const cleanMessage = message.replace(/\nVersion:.*$/, '');
|
|
701
|
+
super(cleanMessage);
|
|
702
|
+
this.code = -32003;
|
|
703
|
+
this.name = "TransactionRejectedRpcError";
|
|
704
|
+
// Parse the error hash from the message
|
|
705
|
+
this.metaMessages.push(extractErrorHash(cleanMessage));
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
class InvalidRequestRpcError extends ProviderRpcError {
|
|
709
|
+
constructor() {
|
|
710
|
+
super(...arguments);
|
|
711
|
+
this.code = -32600;
|
|
712
|
+
this.name = "InvalidRequestRpcError";
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
class MethodNotFoundRpcError extends ProviderRpcError {
|
|
716
|
+
constructor() {
|
|
717
|
+
super(...arguments);
|
|
718
|
+
this.code = -32601;
|
|
719
|
+
this.name = "MethodNotFoundRpcError";
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
class InvalidParamsRpcError extends ProviderRpcError {
|
|
723
|
+
constructor() {
|
|
724
|
+
super(...arguments);
|
|
725
|
+
this.code = -32602;
|
|
726
|
+
this.name = "InvalidParamsRpcError";
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
class InternalRpcError extends ProviderRpcError {
|
|
730
|
+
constructor() {
|
|
731
|
+
super(...arguments);
|
|
732
|
+
this.code = -32603;
|
|
733
|
+
this.name = "InternalRpcError";
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function ensureProviderRpcError(value) {
|
|
737
|
+
if (value instanceof ProviderRpcError) {
|
|
738
|
+
return value;
|
|
739
|
+
}
|
|
740
|
+
if (typeof value === "object" &&
|
|
741
|
+
value !== null &&
|
|
742
|
+
"errorCode" in value &&
|
|
743
|
+
"errorMessage" in value) {
|
|
744
|
+
if (typeof value.errorCode === "number" && typeof value.errorMessage === "string") {
|
|
745
|
+
switch (value.errorCode) {
|
|
746
|
+
case 4001:
|
|
747
|
+
return new UserRejectedRequestError(value.errorMessage);
|
|
748
|
+
case 4100:
|
|
749
|
+
return new UnauthorizedProviderError(value.errorMessage);
|
|
750
|
+
case 4200:
|
|
751
|
+
return new UnsupportedProviderMethodError(value.errorMessage);
|
|
752
|
+
case 4900:
|
|
753
|
+
return new ProviderDisconnectedError(value.errorMessage);
|
|
754
|
+
case 4901:
|
|
755
|
+
return new ChainDisconnectedError(value.errorMessage);
|
|
756
|
+
case 4902:
|
|
757
|
+
return new SwitchChainError(value.errorMessage);
|
|
758
|
+
case -32003:
|
|
759
|
+
return new TransactionRejectedRpcError(value.errorMessage);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
let stringified = "[Unable to stringify the thrown value]";
|
|
764
|
+
try {
|
|
765
|
+
stringified = JSON.stringify(value);
|
|
766
|
+
}
|
|
767
|
+
catch {
|
|
768
|
+
// ignoring failed stringify
|
|
769
|
+
}
|
|
770
|
+
return new InternalRpcError(`Invalid value for ProviderRpcError: ${stringified}`);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function isFunction(value) {
|
|
774
|
+
return typeof value === 'function';
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function createErrorClass(createImpl) {
|
|
712
778
|
var _super = function (instance) {
|
|
713
779
|
Error.call(instance);
|
|
714
780
|
instance.stack = new Error().stack;
|
|
@@ -1732,12 +1798,13 @@
|
|
|
1732
1798
|
_a$2 = ProviderMessageService;
|
|
1733
1799
|
_ProviderMessageService_instance = { value: void 0 };
|
|
1734
1800
|
|
|
1735
|
-
var _AirWalletProvider_instances, _AirWalletProvider_providerMessageService,
|
|
1801
|
+
var _AirWalletProvider_instances, _AirWalletProvider_providerMessageService, _AirWalletProvider_isWalletInitialized, _AirWalletProvider_getLoginResult, _AirWalletProvider_ensureWallet, _AirWalletProvider_eventListeners, _AirWalletProvider_emit;
|
|
1736
1802
|
class AirWalletProvider {
|
|
1737
|
-
constructor({
|
|
1803
|
+
constructor({ ensureWallet, isWalletInitialized, getLoginResult, }) {
|
|
1738
1804
|
_AirWalletProvider_instances.add(this);
|
|
1739
1805
|
_AirWalletProvider_providerMessageService.set(this, void 0);
|
|
1740
|
-
|
|
1806
|
+
_AirWalletProvider_isWalletInitialized.set(this, void 0);
|
|
1807
|
+
_AirWalletProvider_getLoginResult.set(this, void 0);
|
|
1741
1808
|
_AirWalletProvider_ensureWallet.set(this, void 0);
|
|
1742
1809
|
_AirWalletProvider_eventListeners.set(this, void 0);
|
|
1743
1810
|
this.startEventMessageListening = async (walletIframe) => {
|
|
@@ -1749,7 +1816,6 @@
|
|
|
1749
1816
|
});
|
|
1750
1817
|
};
|
|
1751
1818
|
__classPrivateFieldSet(this, _AirWalletProvider_providerMessageService, ProviderMessageService.create(), "f");
|
|
1752
|
-
__classPrivateFieldSet(this, _AirWalletProvider_isLoggedIn, isLoggedIn, "f");
|
|
1753
1819
|
__classPrivateFieldSet(this, _AirWalletProvider_ensureWallet, ensureWallet, "f");
|
|
1754
1820
|
__classPrivateFieldSet(this, _AirWalletProvider_eventListeners, {
|
|
1755
1821
|
connect: [],
|
|
@@ -1758,6 +1824,8 @@
|
|
|
1758
1824
|
chainChanged: [],
|
|
1759
1825
|
message: [],
|
|
1760
1826
|
}, "f");
|
|
1827
|
+
__classPrivateFieldSet(this, _AirWalletProvider_isWalletInitialized, isWalletInitialized, "f");
|
|
1828
|
+
__classPrivateFieldSet(this, _AirWalletProvider_getLoginResult, getLoginResult, "f");
|
|
1761
1829
|
}
|
|
1762
1830
|
async request(request) {
|
|
1763
1831
|
// Check if the request is valid
|
|
@@ -1775,11 +1843,16 @@
|
|
|
1775
1843
|
(typeof params !== "object" || params === null)) {
|
|
1776
1844
|
throw new InvalidParamsRpcError("Invalid params");
|
|
1777
1845
|
}
|
|
1778
|
-
|
|
1779
|
-
if (!
|
|
1846
|
+
const loginResult = __classPrivateFieldGet(this, _AirWalletProvider_getLoginResult, "f").call(this);
|
|
1847
|
+
if (!loginResult) {
|
|
1780
1848
|
throw new UnauthorizedProviderError("User is not logged in");
|
|
1781
1849
|
}
|
|
1782
|
-
|
|
1850
|
+
if (method === "eth_accounts" &&
|
|
1851
|
+
!__classPrivateFieldGet(this, _AirWalletProvider_isWalletInitialized, "f").call(this) &&
|
|
1852
|
+
loginResult?.abstractAccountAddress) {
|
|
1853
|
+
return [loginResult.abstractAccountAddress];
|
|
1854
|
+
}
|
|
1855
|
+
const skipWalletLoginMethods = ["eth_chainId"];
|
|
1783
1856
|
try {
|
|
1784
1857
|
if (skipWalletLoginMethods.includes(method)) {
|
|
1785
1858
|
await __classPrivateFieldGet(this, _AirWalletProvider_ensureWallet, "f").call(this, { skipWalletLogin: true });
|
|
@@ -1822,7 +1895,7 @@
|
|
|
1822
1895
|
}, "f");
|
|
1823
1896
|
}
|
|
1824
1897
|
}
|
|
1825
|
-
_AirWalletProvider_providerMessageService = new WeakMap(),
|
|
1898
|
+
_AirWalletProvider_providerMessageService = new WeakMap(), _AirWalletProvider_isWalletInitialized = new WeakMap(), _AirWalletProvider_getLoginResult = new WeakMap(), _AirWalletProvider_ensureWallet = new WeakMap(), _AirWalletProvider_eventListeners = new WeakMap(), _AirWalletProvider_instances = new WeakSet(), _AirWalletProvider_emit = function _AirWalletProvider_emit(eventName, ...args) {
|
|
1826
1899
|
(__classPrivateFieldGet(this, _AirWalletProvider_eventListeners, "f")[eventName] || []).forEach((listener) => {
|
|
1827
1900
|
try {
|
|
1828
1901
|
return listener(...args);
|
|
@@ -1833,287 +1906,33 @@
|
|
|
1833
1906
|
});
|
|
1834
1907
|
};
|
|
1835
1908
|
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1909
|
+
var _a$1, _AuthMessageService_instance;
|
|
1910
|
+
const ALLOWED_AUTH_MESSAGES = [
|
|
1911
|
+
AirAuthMessageTypes.INITIALIZATION_RESPONSE,
|
|
1912
|
+
AirAuthMessageTypes.LOGIN_RESPONSE,
|
|
1913
|
+
AirAuthMessageTypes.SETUP_WALLET_REQUEST,
|
|
1914
|
+
AirAuthMessageTypes.SETUP_RECOVERY_REQUEST,
|
|
1915
|
+
AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION,
|
|
1916
|
+
AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION,
|
|
1917
|
+
AirAuthMessageTypes.LOGOUT_RESPONSE,
|
|
1918
|
+
AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE,
|
|
1919
|
+
AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE,
|
|
1920
|
+
AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE,
|
|
1921
|
+
AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST,
|
|
1922
|
+
AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE,
|
|
1923
|
+
AirAuthMessageTypes.START_RECOVERY_RESPONSE,
|
|
1924
|
+
];
|
|
1925
|
+
class AuthMessageService extends MessageServiceBase {
|
|
1926
|
+
static create() {
|
|
1927
|
+
if (__classPrivateFieldGet(this, _a$1, "f", _AuthMessageService_instance))
|
|
1928
|
+
throw new Error("AuthMessageService already created");
|
|
1929
|
+
__classPrivateFieldSet(this, _a$1, new _a$1("Embed Service: Auth Channel", ALLOWED_AUTH_MESSAGES), "f", _AuthMessageService_instance);
|
|
1930
|
+
return __classPrivateFieldGet(this, _a$1, "f", _AuthMessageService_instance);
|
|
1845
1931
|
}
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
if (this._iframeElement)
|
|
1851
|
-
return this._iframeElement;
|
|
1852
|
-
const iframe = document.createElement("iframe");
|
|
1853
|
-
iframe.id = this.iframeId;
|
|
1854
|
-
iframe.allow = "publickey-credentials-get *; publickey-credentials-create *";
|
|
1855
|
-
iframe.src = this.iframeUrl;
|
|
1856
|
-
iframe.style.position = "fixed";
|
|
1857
|
-
iframe.style.zIndex = "999999";
|
|
1858
|
-
iframe.style.border = "none";
|
|
1859
|
-
iframe.style.margin = "0";
|
|
1860
|
-
iframe.style.padding = "0";
|
|
1861
|
-
iframe.style.display = "none";
|
|
1862
|
-
iframe.style.colorScheme = "auto";
|
|
1863
|
-
document.body.appendChild(iframe);
|
|
1864
|
-
this._iframeElement = iframe;
|
|
1865
|
-
return iframe;
|
|
1866
|
-
}
|
|
1867
|
-
setIframeVisibility(isVisible) {
|
|
1868
|
-
this.state.isVisible = isVisible;
|
|
1869
|
-
}
|
|
1870
|
-
updateIframeState() {
|
|
1871
|
-
if (!this.iframeElement)
|
|
1872
|
-
return;
|
|
1873
|
-
const style = {};
|
|
1874
|
-
style.display = this.state.isVisible ? "block" : "none";
|
|
1875
|
-
style.width = "100%";
|
|
1876
|
-
style.height = "100%";
|
|
1877
|
-
style.top = "0px";
|
|
1878
|
-
style.right = "0px";
|
|
1879
|
-
style.left = "0px";
|
|
1880
|
-
style.bottom = "0px";
|
|
1881
|
-
Object.assign(this.iframeElement.style, style);
|
|
1882
|
-
}
|
|
1883
|
-
destroy() {
|
|
1884
|
-
if (this.iframeElement) {
|
|
1885
|
-
this.iframeElement.remove();
|
|
1886
|
-
this._iframeElement = null;
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
postMessage(message) {
|
|
1890
|
-
if (!this.iframeElement)
|
|
1891
|
-
return;
|
|
1892
|
-
const { origin } = new URL(this.iframeElement.src);
|
|
1893
|
-
this.iframeElement.contentWindow.postMessage(message, origin);
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
IframeController.defaultState = {
|
|
1897
|
-
isVisible: false,
|
|
1898
|
-
};
|
|
1899
|
-
|
|
1900
|
-
class WindowController {
|
|
1901
|
-
get messages$() {
|
|
1902
|
-
return this._messages$.asObservable();
|
|
1903
|
-
}
|
|
1904
|
-
constructor(windowId, windowUrl) {
|
|
1905
|
-
this._windowInstance = null;
|
|
1906
|
-
this._messageHandler = null;
|
|
1907
|
-
this._messages$ = new Subject();
|
|
1908
|
-
this.windowId = windowId;
|
|
1909
|
-
this.windowUrl = windowUrl;
|
|
1910
|
-
this.windowOrigin = new URL(windowUrl).origin;
|
|
1911
|
-
this._messageHandler = ev => {
|
|
1912
|
-
if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin || !ev.data || !(ev.data instanceof Object)) {
|
|
1913
|
-
return;
|
|
1914
|
-
}
|
|
1915
|
-
this._messages$.next(ev);
|
|
1916
|
-
};
|
|
1917
|
-
window.addEventListener("message", this._messageHandler);
|
|
1918
|
-
}
|
|
1919
|
-
get windowInstance() {
|
|
1920
|
-
return this._windowInstance;
|
|
1921
|
-
}
|
|
1922
|
-
async openWindow(onRetry) {
|
|
1923
|
-
let windowInstance = this.tryOpenWindow();
|
|
1924
|
-
if (!windowInstance) {
|
|
1925
|
-
await onRetry();
|
|
1926
|
-
windowInstance = this.tryOpenWindow();
|
|
1927
|
-
if (!windowInstance) {
|
|
1928
|
-
throw new AirError(WindowErrorName.WINDOW_BLOCKED);
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
const pendingWindowOpenCheck = new Promise((resolve, reject) => {
|
|
1932
|
-
setTimeout(() => {
|
|
1933
|
-
if (this.isWindowOpen(windowInstance)) {
|
|
1934
|
-
// only now are we scheduling the close event check since we're sure the window is open
|
|
1935
|
-
this.scheduleWindowClosedChecks(windowInstance);
|
|
1936
|
-
resolve("opened");
|
|
1937
|
-
} else {
|
|
1938
|
-
onRetry().then(() => {
|
|
1939
|
-
windowInstance = this.tryOpenWindow();
|
|
1940
|
-
if (windowInstance) {
|
|
1941
|
-
this._windowInstance = windowInstance;
|
|
1942
|
-
windowInstance.focus();
|
|
1943
|
-
this.scheduleWindowClosedChecks(windowInstance);
|
|
1944
|
-
resolve("retry");
|
|
1945
|
-
} else {
|
|
1946
|
-
reject(new AirError(WindowErrorName.WINDOW_BLOCKED));
|
|
1947
|
-
}
|
|
1948
|
-
}).catch(reject);
|
|
1949
|
-
}
|
|
1950
|
-
}, 1000);
|
|
1951
|
-
});
|
|
1952
|
-
this._windowInstance = windowInstance;
|
|
1953
|
-
windowInstance.focus();
|
|
1954
|
-
return {
|
|
1955
|
-
pendingWindowOpenCheck
|
|
1956
|
-
};
|
|
1957
|
-
}
|
|
1958
|
-
postMessage(message, transfer) {
|
|
1959
|
-
if (!this._windowInstance) return;
|
|
1960
|
-
this._windowInstance.postMessage(message, this.windowOrigin, transfer);
|
|
1961
|
-
}
|
|
1962
|
-
onMessage(callback) {
|
|
1963
|
-
const listener = ev => {
|
|
1964
|
-
if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin) return;
|
|
1965
|
-
callback(ev);
|
|
1966
|
-
};
|
|
1967
|
-
window.addEventListener("message", listener);
|
|
1968
|
-
const close = () => window.removeEventListener("message", listener);
|
|
1969
|
-
this.onClose(close);
|
|
1970
|
-
return {
|
|
1971
|
-
close
|
|
1972
|
-
};
|
|
1973
|
-
}
|
|
1974
|
-
cleanup() {
|
|
1975
|
-
if (this._windowInstance && !this._windowInstance.closed) {
|
|
1976
|
-
this._windowInstance.close();
|
|
1977
|
-
}
|
|
1978
|
-
this._windowInstance = null;
|
|
1979
|
-
if (this._messageHandler) {
|
|
1980
|
-
window.removeEventListener("message", this._messageHandler);
|
|
1981
|
-
this._messageHandler = null;
|
|
1982
|
-
}
|
|
1983
|
-
if (this._messages$ && !this._messages$.closed) {
|
|
1984
|
-
this._messages$.complete();
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
onClose(callback) {
|
|
1988
|
-
return this._messages$.subscribe({
|
|
1989
|
-
complete: callback
|
|
1990
|
-
});
|
|
1991
|
-
}
|
|
1992
|
-
isWindowOpen(windowInstance) {
|
|
1993
|
-
return !(!windowInstance || windowInstance.closed || typeof windowInstance.closed == "undefined");
|
|
1994
|
-
}
|
|
1995
|
-
tryOpenWindow() {
|
|
1996
|
-
const windowInstance = window.open(this.windowUrl, this.windowId, getWindowFeatures(425, 680));
|
|
1997
|
-
if (this.isWindowOpen(windowInstance)) {
|
|
1998
|
-
return windowInstance;
|
|
1999
|
-
}
|
|
2000
|
-
return null;
|
|
2001
|
-
}
|
|
2002
|
-
scheduleWindowClosedChecks(windowInstance) {
|
|
2003
|
-
const checkWindow = setInterval(() => {
|
|
2004
|
-
if (!windowInstance || windowInstance.closed) {
|
|
2005
|
-
clearInterval(checkWindow);
|
|
2006
|
-
if (windowInstance === this._windowInstance) {
|
|
2007
|
-
this.cleanup();
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
}, 500);
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
|
-
|
|
2014
|
-
class WindowService {
|
|
2015
|
-
constructor() {
|
|
2016
|
-
this.windowControllers = new Map();
|
|
2017
|
-
}
|
|
2018
|
-
static get instance() {
|
|
2019
|
-
return this._instance || (this._instance = new this());
|
|
2020
|
-
}
|
|
2021
|
-
async sendWindowInitializationRequest(windowId, payload, port) {
|
|
2022
|
-
const windowController = this.windowControllers.get(windowId);
|
|
2023
|
-
if (!windowController) {
|
|
2024
|
-
throw new Error("Window controller not found");
|
|
2025
|
-
}
|
|
2026
|
-
const windowInstance = windowController.windowInstance;
|
|
2027
|
-
if (!windowInstance) {
|
|
2028
|
-
throw new Error("Window instance not found");
|
|
2029
|
-
}
|
|
2030
|
-
const response = firstValueFrom(windowController.messages$.pipe(filter((event) => event.data.type ===
|
|
2031
|
-
AirWalletMessageTypes.INITIALIZATION_RESPONSE)));
|
|
2032
|
-
windowController.postMessage({ type: AirWalletMessageTypes.INITIALIZATION_REQUEST, payload }, [
|
|
2033
|
-
port,
|
|
2034
|
-
]);
|
|
2035
|
-
return (await response).data;
|
|
2036
|
-
}
|
|
2037
|
-
async openAndInitializeWalletServiceWindow({ url, windowId, partnerId, enableLogging, onRetry, sdkVersion, enableAutomation, }) {
|
|
2038
|
-
if (this.windowControllers.has(windowId)) {
|
|
2039
|
-
throw new Error("Window controller already exists");
|
|
2040
|
-
}
|
|
2041
|
-
const windowController = new WindowController(windowId, url);
|
|
2042
|
-
const { pendingWindowOpenCheck } = await windowController.openWindow(onRetry);
|
|
2043
|
-
windowController.onClose(() => {
|
|
2044
|
-
this.removeWindowController(windowId);
|
|
2045
|
-
});
|
|
2046
|
-
this.windowControllers.set(windowId, windowController);
|
|
2047
|
-
let channel = null;
|
|
2048
|
-
const initializeWindow = () => {
|
|
2049
|
-
return new Promise((resolve, reject) => {
|
|
2050
|
-
windowController.onMessage(async (ev) => {
|
|
2051
|
-
if (ev.data === AirWalletMessageTypes.SERVICE_STARTED) {
|
|
2052
|
-
try {
|
|
2053
|
-
channel = new MessageChannel();
|
|
2054
|
-
const { payload } = await this.sendWindowInitializationRequest(windowId, {
|
|
2055
|
-
partnerId,
|
|
2056
|
-
enableLogging,
|
|
2057
|
-
sdkVersion,
|
|
2058
|
-
enableAutomation,
|
|
2059
|
-
}, channel.port1);
|
|
2060
|
-
if (payload.success === false) {
|
|
2061
|
-
reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
2062
|
-
}
|
|
2063
|
-
else {
|
|
2064
|
-
resolve();
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
catch (e) {
|
|
2068
|
-
reject(e);
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
});
|
|
2072
|
-
});
|
|
2073
|
-
};
|
|
2074
|
-
const initializeWindowPromise = initializeWindow();
|
|
2075
|
-
const result = await pendingWindowOpenCheck;
|
|
2076
|
-
if (result === "retry") {
|
|
2077
|
-
// we can ignore previous initialization attempt since a new window was opened
|
|
2078
|
-
await initializeWindow();
|
|
2079
|
-
}
|
|
2080
|
-
else {
|
|
2081
|
-
await initializeWindowPromise;
|
|
2082
|
-
}
|
|
2083
|
-
return { windowController, port: channel.port2 };
|
|
2084
|
-
}
|
|
2085
|
-
getWindowController(windowId) {
|
|
2086
|
-
return this.windowControllers.get(windowId);
|
|
2087
|
-
}
|
|
2088
|
-
removeWindowController(windowId) {
|
|
2089
|
-
this.windowControllers.delete(windowId);
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
var WindowService$1 = WindowService.instance;
|
|
2093
|
-
|
|
2094
|
-
var _a$1, _AuthMessageService_instance;
|
|
2095
|
-
const ALLOWED_AUTH_MESSAGES = [
|
|
2096
|
-
AirAuthMessageTypes.INITIALIZATION_RESPONSE,
|
|
2097
|
-
AirAuthMessageTypes.LOGIN_RESPONSE,
|
|
2098
|
-
AirAuthMessageTypes.SETUP_WALLET_REQUEST,
|
|
2099
|
-
AirAuthMessageTypes.LOGOUT_RESPONSE,
|
|
2100
|
-
AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE,
|
|
2101
|
-
AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE,
|
|
2102
|
-
AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE,
|
|
2103
|
-
AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST,
|
|
2104
|
-
AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE,
|
|
2105
|
-
];
|
|
2106
|
-
class AuthMessageService extends MessageServiceBase {
|
|
2107
|
-
static create() {
|
|
2108
|
-
if (__classPrivateFieldGet(this, _a$1, "f", _AuthMessageService_instance))
|
|
2109
|
-
throw new Error("AuthMessageService already created");
|
|
2110
|
-
__classPrivateFieldSet(this, _a$1, new _a$1("Embed Service: Auth Channel", ALLOWED_AUTH_MESSAGES), "f", _AuthMessageService_instance);
|
|
2111
|
-
return __classPrivateFieldGet(this, _a$1, "f", _AuthMessageService_instance);
|
|
2112
|
-
}
|
|
2113
|
-
async open(authIframe) {
|
|
2114
|
-
const origin = new URL(authIframe.src).origin;
|
|
2115
|
-
const window = authIframe.contentWindow;
|
|
2116
|
-
await super._open({ window, origin });
|
|
1932
|
+
async open(authIframe) {
|
|
1933
|
+
const origin = new URL(authIframe.src).origin;
|
|
1934
|
+
const window = authIframe.contentWindow;
|
|
1935
|
+
await super._open({ window, origin });
|
|
2117
1936
|
}
|
|
2118
1937
|
async initWalletCommunication() {
|
|
2119
1938
|
await this.sendMessage({
|
|
@@ -2157,6 +1976,32 @@
|
|
|
2157
1976
|
async sendSetupWalletErrorResponse(error) {
|
|
2158
1977
|
await this.sendMessage(this.createErrorResponseMessage(AirAuthMessageTypes.SETUP_WALLET_RESPONSE, error));
|
|
2159
1978
|
}
|
|
1979
|
+
async initRecoveryCommunication() {
|
|
1980
|
+
await this.sendMessage({
|
|
1981
|
+
type: AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION,
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1984
|
+
async resetRecoveryCommunication() {
|
|
1985
|
+
await this.sendMessage({
|
|
1986
|
+
type: AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION,
|
|
1987
|
+
});
|
|
1988
|
+
}
|
|
1989
|
+
async sendSetupRecoverySuccessResponse() {
|
|
1990
|
+
await this.sendMessage({
|
|
1991
|
+
type: AirAuthMessageTypes.SETUP_RECOVERY_RESPONSE,
|
|
1992
|
+
payload: { success: true },
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
async sendSetupRecoveryErrorResponse(error) {
|
|
1996
|
+
await this.sendMessage({
|
|
1997
|
+
type: AirAuthMessageTypes.SETUP_RECOVERY_RESPONSE,
|
|
1998
|
+
payload: {
|
|
1999
|
+
success: false,
|
|
2000
|
+
errorName: error instanceof AirError ? error.name : "UNKNOWN_ERROR",
|
|
2001
|
+
errorMessage: error.message,
|
|
2002
|
+
},
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2160
2005
|
async sendCrossPartnerTokenRequest(targetPartnerUrl) {
|
|
2161
2006
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE)));
|
|
2162
2007
|
await this.sendMessage({
|
|
@@ -2172,6 +2017,11 @@
|
|
|
2172
2017
|
await this.sendMessage({ type: AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_REQUEST });
|
|
2173
2018
|
return response;
|
|
2174
2019
|
}
|
|
2020
|
+
async sendAccountRecoveryRequest(payload) {
|
|
2021
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.START_RECOVERY_RESPONSE)));
|
|
2022
|
+
await this.sendMessage({ type: AirAuthMessageTypes.START_RECOVERY_REQUEST, payload });
|
|
2023
|
+
return response;
|
|
2024
|
+
}
|
|
2175
2025
|
async sendCredentialSaltRequest() {
|
|
2176
2026
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE)));
|
|
2177
2027
|
await this.sendMessage({ type: AirAuthMessageTypes.CREDENTIAL_SALT_REQUEST });
|
|
@@ -2181,20 +2031,124 @@
|
|
|
2181
2031
|
_a$1 = AuthMessageService;
|
|
2182
2032
|
_AuthMessageService_instance = { value: void 0 };
|
|
2183
2033
|
|
|
2034
|
+
class IframeController {
|
|
2035
|
+
constructor(iframeUrl, iframeId, state) {
|
|
2036
|
+
this._iframeElement = null;
|
|
2037
|
+
this.AUTH_IFRAME_Z_INDEX = "9999999";
|
|
2038
|
+
this.DEFAULT_IFRAME_Z_INDEX = "999999";
|
|
2039
|
+
this.state = {
|
|
2040
|
+
...IframeController.defaultState,
|
|
2041
|
+
...state,
|
|
2042
|
+
};
|
|
2043
|
+
this.iframeUrl = iframeUrl;
|
|
2044
|
+
this.iframeId = iframeId;
|
|
2045
|
+
}
|
|
2046
|
+
get iframeElement() {
|
|
2047
|
+
return this._iframeElement;
|
|
2048
|
+
}
|
|
2049
|
+
createIframe() {
|
|
2050
|
+
if (this._iframeElement)
|
|
2051
|
+
return this._iframeElement;
|
|
2052
|
+
const iframe = document.createElement("iframe");
|
|
2053
|
+
iframe.id = this.iframeId;
|
|
2054
|
+
iframe.allow = "publickey-credentials-get *; publickey-credentials-create *";
|
|
2055
|
+
iframe.src = this.iframeUrl;
|
|
2056
|
+
iframe.style.position = "fixed";
|
|
2057
|
+
iframe.style.zIndex = this.iframeUrl.includes("auth") ? this.AUTH_IFRAME_Z_INDEX : this.DEFAULT_IFRAME_Z_INDEX;
|
|
2058
|
+
iframe.style.border = "none";
|
|
2059
|
+
iframe.style.margin = "0";
|
|
2060
|
+
iframe.style.padding = "0";
|
|
2061
|
+
iframe.style.display = "none";
|
|
2062
|
+
iframe.style.colorScheme = "auto";
|
|
2063
|
+
document.body.appendChild(iframe);
|
|
2064
|
+
this._iframeElement = iframe;
|
|
2065
|
+
return iframe;
|
|
2066
|
+
}
|
|
2067
|
+
setIframeVisibility(isVisible) {
|
|
2068
|
+
this.state.isVisible = isVisible;
|
|
2069
|
+
}
|
|
2070
|
+
updateIframeState() {
|
|
2071
|
+
if (!this.iframeElement)
|
|
2072
|
+
return;
|
|
2073
|
+
const style = {};
|
|
2074
|
+
style.display = this.state.isVisible ? "block" : "none";
|
|
2075
|
+
style.width = "100%";
|
|
2076
|
+
style.height = "100%";
|
|
2077
|
+
style.top = "0px";
|
|
2078
|
+
style.right = "0px";
|
|
2079
|
+
style.left = "0px";
|
|
2080
|
+
style.bottom = "0px";
|
|
2081
|
+
Object.assign(this.iframeElement.style, style);
|
|
2082
|
+
}
|
|
2083
|
+
destroy() {
|
|
2084
|
+
if (this.iframeElement) {
|
|
2085
|
+
this.iframeElement.remove();
|
|
2086
|
+
this._iframeElement = null;
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
postMessage(message) {
|
|
2090
|
+
if (!this.iframeElement)
|
|
2091
|
+
return;
|
|
2092
|
+
const { origin } = new URL(this.iframeElement.src);
|
|
2093
|
+
this.iframeElement.contentWindow.postMessage(message, origin);
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
IframeController.defaultState = {
|
|
2097
|
+
isVisible: false,
|
|
2098
|
+
};
|
|
2099
|
+
|
|
2100
|
+
const ALLOWED_RECOVERY_MESSAGES = Object.values(AirRecoveryMessageTypes);
|
|
2101
|
+
class RecoveryMessageService extends MessageServiceBase {
|
|
2102
|
+
static create() {
|
|
2103
|
+
if (!RecoveryMessageService._instance) {
|
|
2104
|
+
RecoveryMessageService._instance = new RecoveryMessageService("Recovery Service", ALLOWED_RECOVERY_MESSAGES);
|
|
2105
|
+
}
|
|
2106
|
+
return RecoveryMessageService._instance;
|
|
2107
|
+
}
|
|
2108
|
+
async sendInitializationRequest(payload) {
|
|
2109
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirRecoveryMessageTypes.INITIALIZATION_RESPONSE)));
|
|
2110
|
+
await this.sendMessage({
|
|
2111
|
+
type: AirRecoveryMessageTypes.INITIALIZATION_REQUEST,
|
|
2112
|
+
payload,
|
|
2113
|
+
});
|
|
2114
|
+
return response;
|
|
2115
|
+
}
|
|
2116
|
+
async initAuthCommunication() {
|
|
2117
|
+
await this.sendMessage({
|
|
2118
|
+
type: AirRecoveryMessageTypes.INIT_AUTH_COMMUNICATION,
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
async onInitialized() {
|
|
2122
|
+
return firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirRecoveryMessageTypes.RECOVERY_INITIALIZED)));
|
|
2123
|
+
}
|
|
2124
|
+
async logout() {
|
|
2125
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirRecoveryMessageTypes.LOGOUT_RESPONSE)));
|
|
2126
|
+
await this.sendMessage({ type: AirRecoveryMessageTypes.LOGOUT_REQUEST });
|
|
2127
|
+
return response;
|
|
2128
|
+
}
|
|
2129
|
+
async open(element) {
|
|
2130
|
+
await this._open({ window: element.contentWindow, origin: new URL(element.src).origin });
|
|
2131
|
+
}
|
|
2132
|
+
async close() {
|
|
2133
|
+
await super.close();
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2184
2137
|
var _a, _WalletMessageService_instance;
|
|
2185
2138
|
const ALLOWED_WALLET_MESSAGES = [
|
|
2186
2139
|
AirWalletMessageTypes.INITIALIZATION_RESPONSE,
|
|
2187
2140
|
AirWalletMessageTypes.WALLET_INITIALIZED,
|
|
2188
2141
|
AirWalletMessageTypes.WALLET_LOGIN_RESPONSE,
|
|
2189
2142
|
AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_RESPONSE,
|
|
2143
|
+
AirWalletMessageTypes.SHOW_SWAP_UI_RESPONSE,
|
|
2190
2144
|
AirWalletMessageTypes.CLAIM_ID_RESPONSE,
|
|
2191
2145
|
AirWalletMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE,
|
|
2192
2146
|
AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE,
|
|
2193
2147
|
AirWalletMessageTypes.WALLET_INITIALIZED,
|
|
2194
2148
|
AirWalletMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST,
|
|
2195
2149
|
AirWalletMessageTypes.LOGOUT_RESPONSE,
|
|
2196
|
-
|
|
2197
|
-
|
|
2150
|
+
AirWindowMessageTypes.OPEN_WINDOW_REQUEST,
|
|
2151
|
+
AirWindowMessageTypes.OPEN_WINDOW_RETRY_RESPONSE,
|
|
2198
2152
|
];
|
|
2199
2153
|
class WalletMessageService extends MessageServiceBase {
|
|
2200
2154
|
static create() {
|
|
@@ -2235,97 +2189,271 @@
|
|
|
2235
2189
|
await this.sendMessage({ type: AirWalletMessageTypes.LOGOUT_REQUEST });
|
|
2236
2190
|
return response;
|
|
2237
2191
|
}
|
|
2238
|
-
async sendInitializationRequest(payload) {
|
|
2239
|
-
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.INITIALIZATION_RESPONSE)));
|
|
2240
|
-
await this.sendMessage({ type: AirWalletMessageTypes.INITIALIZATION_REQUEST, payload });
|
|
2241
|
-
return response;
|
|
2192
|
+
async sendInitializationRequest(payload) {
|
|
2193
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.INITIALIZATION_RESPONSE)));
|
|
2194
|
+
await this.sendMessage({ type: AirWalletMessageTypes.INITIALIZATION_REQUEST, payload });
|
|
2195
|
+
return response;
|
|
2196
|
+
}
|
|
2197
|
+
onInitialized() {
|
|
2198
|
+
return firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.WALLET_INITIALIZED)));
|
|
2199
|
+
}
|
|
2200
|
+
async sendLoginRequest() {
|
|
2201
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.WALLET_LOGIN_RESPONSE)));
|
|
2202
|
+
await this.sendMessage({
|
|
2203
|
+
type: AirWalletMessageTypes.WALLET_LOGIN_REQUEST,
|
|
2204
|
+
});
|
|
2205
|
+
return response;
|
|
2206
|
+
}
|
|
2207
|
+
async sendSetupMfaRequest() {
|
|
2208
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_RESPONSE)));
|
|
2209
|
+
await this.sendMessage({
|
|
2210
|
+
type: AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_REQUEST,
|
|
2211
|
+
});
|
|
2212
|
+
return response;
|
|
2213
|
+
}
|
|
2214
|
+
async sendOpenWindowSuccessResponse(windowId, port) {
|
|
2215
|
+
await this.sendMessage({
|
|
2216
|
+
type: AirWindowMessageTypes.OPEN_WINDOW_RESPONSE,
|
|
2217
|
+
payload: {
|
|
2218
|
+
success: true,
|
|
2219
|
+
windowId,
|
|
2220
|
+
},
|
|
2221
|
+
}, [port]);
|
|
2222
|
+
}
|
|
2223
|
+
async sendOpenWindowErrorResponse(windowId, error) {
|
|
2224
|
+
const errorResponse = this.createErrorResponseMessage(AirWindowMessageTypes.OPEN_WINDOW_RESPONSE, error);
|
|
2225
|
+
await this.sendMessage({
|
|
2226
|
+
...errorResponse,
|
|
2227
|
+
payload: { ...errorResponse.payload, windowId },
|
|
2228
|
+
});
|
|
2229
|
+
}
|
|
2230
|
+
async sendOpenWindowRetryRequest(windowId) {
|
|
2231
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWindowMessageTypes.OPEN_WINDOW_RETRY_RESPONSE), filter((msg) => msg.payload.windowId === windowId)));
|
|
2232
|
+
await this.sendMessage({
|
|
2233
|
+
type: AirWindowMessageTypes.OPEN_WINDOW_RETRY_REQUEST,
|
|
2234
|
+
payload: { windowId },
|
|
2235
|
+
});
|
|
2236
|
+
return response;
|
|
2237
|
+
}
|
|
2238
|
+
async sendWindowClosed(windowId) {
|
|
2239
|
+
await this.sendMessage({
|
|
2240
|
+
type: AirWindowMessageTypes.WINDOW_CLOSED,
|
|
2241
|
+
payload: {
|
|
2242
|
+
windowId,
|
|
2243
|
+
},
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
async sendClaimIdRequest(payload) {
|
|
2247
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.CLAIM_ID_RESPONSE)));
|
|
2248
|
+
await this.sendMessage({ type: AirWalletMessageTypes.CLAIM_ID_REQUEST, payload });
|
|
2249
|
+
return response;
|
|
2250
|
+
}
|
|
2251
|
+
async sendShowSwapUIRequest() {
|
|
2252
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.SHOW_SWAP_UI_RESPONSE)));
|
|
2253
|
+
await this.sendMessage({
|
|
2254
|
+
type: AirWalletMessageTypes.SHOW_SWAP_UI_REQUEST,
|
|
2255
|
+
});
|
|
2256
|
+
return response;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
_a = WalletMessageService;
|
|
2260
|
+
_WalletMessageService_instance = { value: void 0 };
|
|
2261
|
+
|
|
2262
|
+
class WindowController {
|
|
2263
|
+
get messages$() {
|
|
2264
|
+
return this._messages$.asObservable();
|
|
2265
|
+
}
|
|
2266
|
+
constructor(windowId, windowUrl) {
|
|
2267
|
+
this._windowInstance = null;
|
|
2268
|
+
this._messageHandler = null;
|
|
2269
|
+
this._messages$ = new Subject();
|
|
2270
|
+
this.windowId = windowId;
|
|
2271
|
+
this.windowUrl = windowUrl;
|
|
2272
|
+
this.windowOrigin = new URL(windowUrl).origin;
|
|
2273
|
+
this._messageHandler = ev => {
|
|
2274
|
+
if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin || !ev.data || !(ev.data instanceof Object)) {
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2277
|
+
this._messages$.next(ev);
|
|
2278
|
+
};
|
|
2279
|
+
window.addEventListener("message", this._messageHandler);
|
|
2280
|
+
}
|
|
2281
|
+
get windowInstance() {
|
|
2282
|
+
return this._windowInstance;
|
|
2283
|
+
}
|
|
2284
|
+
async openWindow(onRetry) {
|
|
2285
|
+
let windowInstance = this.tryOpenWindow();
|
|
2286
|
+
if (!windowInstance) {
|
|
2287
|
+
await onRetry();
|
|
2288
|
+
windowInstance = this.tryOpenWindow();
|
|
2289
|
+
if (!windowInstance) {
|
|
2290
|
+
throw new AirError(WindowErrorName.WINDOW_BLOCKED);
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
const pendingWindowOpenCheck = new Promise((resolve, reject) => {
|
|
2294
|
+
setTimeout(() => {
|
|
2295
|
+
if (this.isWindowOpen(windowInstance)) {
|
|
2296
|
+
// only now are we scheduling the close event check since we're sure the window is open
|
|
2297
|
+
this.scheduleWindowClosedChecks(windowInstance);
|
|
2298
|
+
resolve("opened");
|
|
2299
|
+
} else {
|
|
2300
|
+
onRetry().then(() => {
|
|
2301
|
+
windowInstance = this.tryOpenWindow();
|
|
2302
|
+
if (windowInstance) {
|
|
2303
|
+
this._windowInstance = windowInstance;
|
|
2304
|
+
windowInstance.focus();
|
|
2305
|
+
this.scheduleWindowClosedChecks(windowInstance);
|
|
2306
|
+
resolve("retry");
|
|
2307
|
+
} else {
|
|
2308
|
+
reject(new AirError(WindowErrorName.WINDOW_BLOCKED));
|
|
2309
|
+
}
|
|
2310
|
+
}).catch(reject);
|
|
2311
|
+
}
|
|
2312
|
+
}, 1000);
|
|
2313
|
+
});
|
|
2314
|
+
this._windowInstance = windowInstance;
|
|
2315
|
+
windowInstance.focus();
|
|
2316
|
+
return {
|
|
2317
|
+
pendingWindowOpenCheck
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
postMessage(message, transfer) {
|
|
2321
|
+
if (!this._windowInstance) return;
|
|
2322
|
+
this._windowInstance.postMessage(message, this.windowOrigin, transfer);
|
|
2323
|
+
}
|
|
2324
|
+
onMessage(callback) {
|
|
2325
|
+
const listener = ev => {
|
|
2326
|
+
if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin) return;
|
|
2327
|
+
callback(ev);
|
|
2328
|
+
};
|
|
2329
|
+
window.addEventListener("message", listener);
|
|
2330
|
+
const close = () => window.removeEventListener("message", listener);
|
|
2331
|
+
this.onClose(close);
|
|
2332
|
+
return {
|
|
2333
|
+
close
|
|
2334
|
+
};
|
|
2335
|
+
}
|
|
2336
|
+
cleanup() {
|
|
2337
|
+
if (this._windowInstance && !this._windowInstance.closed) {
|
|
2338
|
+
this._windowInstance.close();
|
|
2339
|
+
}
|
|
2340
|
+
this._windowInstance = null;
|
|
2341
|
+
if (this._messageHandler) {
|
|
2342
|
+
window.removeEventListener("message", this._messageHandler);
|
|
2343
|
+
this._messageHandler = null;
|
|
2242
2344
|
}
|
|
2243
|
-
|
|
2244
|
-
|
|
2345
|
+
if (this._messages$ && !this._messages$.closed) {
|
|
2346
|
+
this._messages$.complete();
|
|
2245
2347
|
}
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2348
|
+
}
|
|
2349
|
+
onClose(callback) {
|
|
2350
|
+
return this._messages$.subscribe({
|
|
2351
|
+
complete: callback
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
isWindowOpen(windowInstance) {
|
|
2355
|
+
return !(!windowInstance || windowInstance.closed || typeof windowInstance.closed == "undefined");
|
|
2356
|
+
}
|
|
2357
|
+
tryOpenWindow() {
|
|
2358
|
+
const windowInstance = window.open(this.windowUrl, this.windowId, getWindowFeatures(425, 680));
|
|
2359
|
+
if (this.isWindowOpen(windowInstance)) {
|
|
2360
|
+
return windowInstance;
|
|
2252
2361
|
}
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2362
|
+
return null;
|
|
2363
|
+
}
|
|
2364
|
+
scheduleWindowClosedChecks(windowInstance) {
|
|
2365
|
+
const checkWindow = setInterval(() => {
|
|
2366
|
+
if (!windowInstance || windowInstance.closed) {
|
|
2367
|
+
clearInterval(checkWindow);
|
|
2368
|
+
if (windowInstance === this._windowInstance) {
|
|
2369
|
+
this.cleanup();
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
}, 500);
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
class WindowService {
|
|
2377
|
+
constructor() {
|
|
2378
|
+
this.windowControllers = new Map();
|
|
2259
2379
|
}
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
type: AirWalletMessageTypes.OPEN_WINDOW_RESPONSE,
|
|
2263
|
-
payload: {
|
|
2264
|
-
success: true,
|
|
2265
|
-
windowId,
|
|
2266
|
-
},
|
|
2267
|
-
}, [port]);
|
|
2380
|
+
static get instance() {
|
|
2381
|
+
return this._instance || (this._instance = new this());
|
|
2268
2382
|
}
|
|
2269
|
-
async
|
|
2270
|
-
const
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2383
|
+
async sendWindowInitializationRequest(windowId, payload, port) {
|
|
2384
|
+
const windowController = this.windowControllers.get(windowId);
|
|
2385
|
+
if (!windowController) {
|
|
2386
|
+
throw new Error("Window controller not found");
|
|
2387
|
+
}
|
|
2388
|
+
const windowInstance = windowController.windowInstance;
|
|
2389
|
+
if (!windowInstance) {
|
|
2390
|
+
throw new Error("Window instance not found");
|
|
2391
|
+
}
|
|
2392
|
+
const response = firstValueFrom(windowController.messages$.pipe(filter((event) => event.data.type ===
|
|
2393
|
+
AirWalletMessageTypes.INITIALIZATION_RESPONSE)));
|
|
2394
|
+
windowController.postMessage({ type: AirWalletMessageTypes.INITIALIZATION_REQUEST, payload }, [
|
|
2395
|
+
port,
|
|
2396
|
+
]);
|
|
2397
|
+
return (await response).data;
|
|
2275
2398
|
}
|
|
2276
|
-
async
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2399
|
+
async openAndInitializeWalletServiceWindow({ url, windowId, partnerId, enableLogging, onRetry, sdkVersion, enableAutomation, }) {
|
|
2400
|
+
if (this.windowControllers.has(windowId)) {
|
|
2401
|
+
throw new Error("Window controller already exists");
|
|
2402
|
+
}
|
|
2403
|
+
const windowController = new WindowController(windowId, url);
|
|
2404
|
+
const { pendingWindowOpenCheck } = await windowController.openWindow(onRetry);
|
|
2405
|
+
windowController.onClose(() => {
|
|
2406
|
+
this.removeWindowController(windowId);
|
|
2281
2407
|
});
|
|
2282
|
-
|
|
2408
|
+
this.windowControllers.set(windowId, windowController);
|
|
2409
|
+
let channel = null;
|
|
2410
|
+
const initializeWindow = () => {
|
|
2411
|
+
return new Promise((resolve, reject) => {
|
|
2412
|
+
windowController.onMessage(async (ev) => {
|
|
2413
|
+
if (ev.data === AirWalletMessageTypes.SERVICE_STARTED) {
|
|
2414
|
+
try {
|
|
2415
|
+
channel = new MessageChannel();
|
|
2416
|
+
const { payload } = await this.sendWindowInitializationRequest(windowId, {
|
|
2417
|
+
partnerId,
|
|
2418
|
+
enableLogging,
|
|
2419
|
+
sdkVersion,
|
|
2420
|
+
enableAutomation,
|
|
2421
|
+
}, channel.port1);
|
|
2422
|
+
if (payload.success === false) {
|
|
2423
|
+
reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
2424
|
+
}
|
|
2425
|
+
else {
|
|
2426
|
+
resolve();
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
catch (e) {
|
|
2430
|
+
reject(e);
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
});
|
|
2434
|
+
});
|
|
2435
|
+
};
|
|
2436
|
+
const initializeWindowPromise = initializeWindow();
|
|
2437
|
+
const result = await pendingWindowOpenCheck;
|
|
2438
|
+
if (result === "retry") {
|
|
2439
|
+
// we can ignore previous initialization attempt since a new window was opened
|
|
2440
|
+
await initializeWindow();
|
|
2441
|
+
}
|
|
2442
|
+
else {
|
|
2443
|
+
await initializeWindowPromise;
|
|
2444
|
+
}
|
|
2445
|
+
return { windowController, port: channel.port2 };
|
|
2283
2446
|
}
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
type: AirWalletMessageTypes.WINDOW_CLOSED,
|
|
2287
|
-
payload: {
|
|
2288
|
-
windowId,
|
|
2289
|
-
},
|
|
2290
|
-
});
|
|
2447
|
+
getWindowController(windowId) {
|
|
2448
|
+
return this.windowControllers.get(windowId);
|
|
2291
2449
|
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
await this.sendMessage({ type: AirWalletMessageTypes.CLAIM_ID_REQUEST, payload });
|
|
2295
|
-
return response;
|
|
2450
|
+
removeWindowController(windowId) {
|
|
2451
|
+
this.windowControllers.delete(windowId);
|
|
2296
2452
|
}
|
|
2297
2453
|
}
|
|
2298
|
-
|
|
2299
|
-
_WalletMessageService_instance = { value: void 0 };
|
|
2300
|
-
|
|
2301
|
-
const getLevelName = levelNum => {
|
|
2302
|
-
const levelNames = Object.keys(log.levels);
|
|
2303
|
-
if (levelNum >= 0 && levelNum < levelNames.length) {
|
|
2304
|
-
return levelNames[levelNum];
|
|
2305
|
-
}
|
|
2306
|
-
return "UNKNOWN";
|
|
2307
|
-
};
|
|
2308
|
-
const configureLogLevel = (environment, enableLogging) => {
|
|
2309
|
-
let level = log.levels.ERROR;
|
|
2310
|
-
if (environment === "development") {
|
|
2311
|
-
level = enableLogging ? log.levels.TRACE : log.levels.INFO;
|
|
2312
|
-
} else if (environment === "staging") {
|
|
2313
|
-
level = enableLogging ? log.levels.DEBUG : log.levels.INFO;
|
|
2314
|
-
} else if (environment === "uat") {
|
|
2315
|
-
level = enableLogging ? log.levels.INFO : log.levels.WARN;
|
|
2316
|
-
} else if (environment === "production") {
|
|
2317
|
-
// Be cautious with enabling more than WARN in prod
|
|
2318
|
-
level = enableLogging ? log.levels.WARN : log.levels.ERROR;
|
|
2319
|
-
}
|
|
2320
|
-
log.setLevel(level);
|
|
2321
|
-
log.info(`[${window?.location?.href}] LogLevel: ${getLevelName(log.getLevel())}`);
|
|
2322
|
-
};
|
|
2323
|
-
|
|
2324
|
-
var version = "1.3.0";
|
|
2325
|
-
var airkitPackage = {
|
|
2326
|
-
version: version};
|
|
2454
|
+
var WindowService$1 = WindowService.instance;
|
|
2327
2455
|
|
|
2328
|
-
var _AirService_instances, _AirService_loginResult, _AirService_buildEnv, _AirService_enableLogging, _AirService_partnerId, _AirService_authMessagingService, _AirService_authIframeController, _AirService_isAuthInitialized, _AirService_airAuthListener, _AirService_walletMessagingService, _AirService_walletIframeController, _AirService_walletInitialization, _AirService_walletLoggedInResult, _AirService_airWalletProvider, _AirService_ensureWallet, _AirService_initializeWallet, _AirService_subscribeToWalletEvents, _AirService_triggerEventListeners, _AirService_triggerAirAuthInitialized, _AirService_triggerAirAuthLoggedIn, _AirService_triggerAirAuthLoggedOut, _AirService_triggerWalletInitialized, _AirService_createLoginResult, _AirService_createWalletInitializedResult, _AirService_cleanUpAuth, _AirService_cleanUpWallet;
|
|
2456
|
+
var _AirService_instances, _AirService_loginResult, _AirService_buildEnv, _AirService_enableLogging, _AirService_partnerId, _AirService_authMessagingService, _AirService_authIframeController, _AirService_isAuthInitialized, _AirService_airAuthListener, _AirService_walletMessagingService, _AirService_walletIframeController, _AirService_walletInitialization, _AirService_walletLoggedInResult, _AirService_airWalletProvider, _AirService_recoveryInitialization, _AirService_recoveryMessagingService, _AirService_recoveryIframeController, _AirService_ensureWallet, _AirService_initializeWallet, _AirService_subscribeToWalletEvents, _AirService_triggerEventListeners, _AirService_triggerAirAuthInitialized, _AirService_triggerAirAuthLoggedIn, _AirService_triggerAirAuthLoggedOut, _AirService_triggerWalletInitialized, _AirService_createLoginResult, _AirService_createWalletInitializedResult, _AirService_cleanUpAuth, _AirService_cleanUpWallet, _AirService_ensureRecovery, _AirService_initializeRecovery, _AirService_subscribeToRecoveryEvents, _AirService_cleanUpRecovery;
|
|
2329
2457
|
const airKitVersion = airkitPackage.version;
|
|
2330
2458
|
class AirService {
|
|
2331
2459
|
constructor({ partnerId }) {
|
|
@@ -2344,12 +2472,17 @@
|
|
|
2344
2472
|
_AirService_walletInitialization.set(this, void 0);
|
|
2345
2473
|
_AirService_walletLoggedInResult.set(this, void 0);
|
|
2346
2474
|
_AirService_airWalletProvider.set(this, void 0);
|
|
2475
|
+
_AirService_recoveryInitialization.set(this, void 0);
|
|
2476
|
+
_AirService_recoveryMessagingService.set(this, void 0);
|
|
2477
|
+
_AirService_recoveryIframeController.set(this, void 0);
|
|
2347
2478
|
__classPrivateFieldSet(this, _AirService_partnerId, partnerId, "f");
|
|
2348
2479
|
__classPrivateFieldSet(this, _AirService_authMessagingService, AuthMessageService.create(), "f");
|
|
2349
2480
|
__classPrivateFieldSet(this, _AirService_walletMessagingService, WalletMessageService.create(), "f");
|
|
2481
|
+
__classPrivateFieldSet(this, _AirService_recoveryMessagingService, RecoveryMessageService.create(), "f");
|
|
2350
2482
|
__classPrivateFieldSet(this, _AirService_airWalletProvider, new AirWalletProvider({
|
|
2351
|
-
|
|
2483
|
+
isWalletInitialized: () => this.isWalletInitialized,
|
|
2352
2484
|
ensureWallet: __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).bind(this),
|
|
2485
|
+
getLoginResult: () => __classPrivateFieldGet(this, _AirService_loginResult, "f"),
|
|
2353
2486
|
}), "f");
|
|
2354
2487
|
// this.#modalZIndex = modalZIndex ?? 99999;
|
|
2355
2488
|
}
|
|
@@ -2362,6 +2495,9 @@
|
|
|
2362
2495
|
get isLoggedIn() {
|
|
2363
2496
|
return !!__classPrivateFieldGet(this, _AirService_loginResult, "f");
|
|
2364
2497
|
}
|
|
2498
|
+
get loginResult() {
|
|
2499
|
+
return __classPrivateFieldGet(this, _AirService_loginResult, "f");
|
|
2500
|
+
}
|
|
2365
2501
|
get isWalletInitialized() {
|
|
2366
2502
|
return !!__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f");
|
|
2367
2503
|
}
|
|
@@ -2410,6 +2546,17 @@
|
|
|
2410
2546
|
}
|
|
2411
2547
|
break;
|
|
2412
2548
|
}
|
|
2549
|
+
case AirAuthMessageTypes.SETUP_RECOVERY_REQUEST: {
|
|
2550
|
+
try {
|
|
2551
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureRecovery).call(this);
|
|
2552
|
+
await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendSetupRecoverySuccessResponse();
|
|
2553
|
+
}
|
|
2554
|
+
catch (err) {
|
|
2555
|
+
const error = ensureError(err);
|
|
2556
|
+
await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendSetupRecoveryErrorResponse(error);
|
|
2557
|
+
}
|
|
2558
|
+
break;
|
|
2559
|
+
}
|
|
2413
2560
|
}
|
|
2414
2561
|
});
|
|
2415
2562
|
const result = await new Promise((resolve, reject) => {
|
|
@@ -2545,6 +2692,14 @@
|
|
|
2545
2692
|
}
|
|
2546
2693
|
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2547
2694
|
}
|
|
2695
|
+
async showSwapUI() {
|
|
2696
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
2697
|
+
const result = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendShowSwapUIRequest();
|
|
2698
|
+
if (result.payload.success === false) {
|
|
2699
|
+
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2700
|
+
}
|
|
2701
|
+
return { txHash: result.payload.txHash };
|
|
2702
|
+
}
|
|
2548
2703
|
async getUserInfo() {
|
|
2549
2704
|
if (!this.isLoggedIn)
|
|
2550
2705
|
throw new Error("User not logged in");
|
|
@@ -2577,6 +2732,17 @@
|
|
|
2577
2732
|
urlWithToken: result.payload.urlWithToken,
|
|
2578
2733
|
};
|
|
2579
2734
|
}
|
|
2735
|
+
async startRecovery(payload) {
|
|
2736
|
+
try {
|
|
2737
|
+
const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendAccountRecoveryRequest(payload);
|
|
2738
|
+
if (result.payload.success === false) {
|
|
2739
|
+
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
catch (error) {
|
|
2743
|
+
throw AirServiceError.from(error);
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2580
2746
|
async getAccessToken() {
|
|
2581
2747
|
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2582
2748
|
throw new Error("Service is not initialized");
|
|
@@ -2605,6 +2771,7 @@
|
|
|
2605
2771
|
async cleanUp() {
|
|
2606
2772
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
|
|
2607
2773
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpAuth).call(this);
|
|
2774
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
|
|
2608
2775
|
this.clearEventListeners();
|
|
2609
2776
|
}
|
|
2610
2777
|
on(listener) {
|
|
@@ -2619,7 +2786,7 @@
|
|
|
2619
2786
|
__classPrivateFieldSet(this, _AirService_airAuthListener, [], "f");
|
|
2620
2787
|
}
|
|
2621
2788
|
}
|
|
2622
|
-
_AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _AirService_enableLogging = new WeakMap(), _AirService_partnerId = new WeakMap(), _AirService_authMessagingService = new WeakMap(), _AirService_authIframeController = new WeakMap(), _AirService_isAuthInitialized = new WeakMap(), _AirService_airAuthListener = new WeakMap(), _AirService_walletMessagingService = new WeakMap(), _AirService_walletIframeController = new WeakMap(), _AirService_walletInitialization = new WeakMap(), _AirService_walletLoggedInResult = new WeakMap(), _AirService_airWalletProvider = new WeakMap(), _AirService_instances = new WeakSet(), _AirService_ensureWallet = async function _AirService_ensureWallet(option) {
|
|
2789
|
+
_AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _AirService_enableLogging = new WeakMap(), _AirService_partnerId = new WeakMap(), _AirService_authMessagingService = new WeakMap(), _AirService_authIframeController = new WeakMap(), _AirService_isAuthInitialized = new WeakMap(), _AirService_airAuthListener = new WeakMap(), _AirService_walletMessagingService = new WeakMap(), _AirService_walletIframeController = new WeakMap(), _AirService_walletInitialization = new WeakMap(), _AirService_walletLoggedInResult = new WeakMap(), _AirService_airWalletProvider = new WeakMap(), _AirService_recoveryInitialization = new WeakMap(), _AirService_recoveryMessagingService = new WeakMap(), _AirService_recoveryIframeController = new WeakMap(), _AirService_instances = new WeakSet(), _AirService_ensureWallet = async function _AirService_ensureWallet(option) {
|
|
2623
2790
|
if (!this.isInitialized)
|
|
2624
2791
|
throw new Error("Service not initialized");
|
|
2625
2792
|
if (!this.isLoggedIn && !option?.skipWalletLogin)
|
|
@@ -2715,7 +2882,7 @@
|
|
|
2715
2882
|
}
|
|
2716
2883
|
break;
|
|
2717
2884
|
}
|
|
2718
|
-
case
|
|
2885
|
+
case AirWindowMessageTypes.OPEN_WINDOW_REQUEST: {
|
|
2719
2886
|
try {
|
|
2720
2887
|
const onRetry = async () => {
|
|
2721
2888
|
const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendOpenWindowRetryRequest(msg.payload.windowId);
|
|
@@ -2810,6 +2977,95 @@
|
|
|
2810
2977
|
await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").close();
|
|
2811
2978
|
__classPrivateFieldSet(this, _AirService_walletLoggedInResult, undefined, "f");
|
|
2812
2979
|
__classPrivateFieldSet(this, _AirService_walletInitialization, undefined, "f");
|
|
2980
|
+
}, _AirService_ensureRecovery = async function _AirService_ensureRecovery() {
|
|
2981
|
+
if (!this.isInitialized)
|
|
2982
|
+
throw new Error("Service not initialized");
|
|
2983
|
+
if (!__classPrivateFieldGet(this, _AirService_recoveryInitialization, "f")) {
|
|
2984
|
+
__classPrivateFieldSet(this, _AirService_recoveryInitialization, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_initializeRecovery).call(this), "f");
|
|
2985
|
+
}
|
|
2986
|
+
try {
|
|
2987
|
+
await __classPrivateFieldGet(this, _AirService_recoveryInitialization, "f");
|
|
2988
|
+
}
|
|
2989
|
+
catch (error) {
|
|
2990
|
+
__classPrivateFieldSet(this, _AirService_recoveryInitialization, null, "f");
|
|
2991
|
+
log.error("Error initializing recovery", error);
|
|
2992
|
+
throw error;
|
|
2993
|
+
}
|
|
2994
|
+
}, _AirService_initializeRecovery = async function _AirService_initializeRecovery() {
|
|
2995
|
+
if (__classPrivateFieldGet(this, _AirService_recoveryInitialization, "f"))
|
|
2996
|
+
throw new Error("Already initializing");
|
|
2997
|
+
const { recoveryUrl } = AIR_URLS[__classPrivateFieldGet(this, _AirService_buildEnv, "f")];
|
|
2998
|
+
const recoveryIframeOrigin = new URL(recoveryUrl).origin;
|
|
2999
|
+
try {
|
|
3000
|
+
const recoveryInitRequestPromise = new Promise((resolve, reject) => {
|
|
3001
|
+
const handleRecoveryMessage = async (ev) => {
|
|
3002
|
+
if (ev.origin !== recoveryIframeOrigin)
|
|
3003
|
+
return;
|
|
3004
|
+
if (ev.data === AirRecoveryMessageTypes.SERVICE_STARTED) {
|
|
3005
|
+
window.removeEventListener("message", handleRecoveryMessage);
|
|
3006
|
+
const { payload } = await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").sendInitializationRequest({
|
|
3007
|
+
partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
|
|
3008
|
+
enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
|
|
3009
|
+
sdkVersion: airKitVersion,
|
|
3010
|
+
enableAutomation: this.shouldEnableAutomation(),
|
|
3011
|
+
});
|
|
3012
|
+
if (payload.success === true) {
|
|
3013
|
+
resolve();
|
|
3014
|
+
}
|
|
3015
|
+
else {
|
|
3016
|
+
reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
};
|
|
3020
|
+
window.addEventListener("message", handleRecoveryMessage);
|
|
3021
|
+
});
|
|
3022
|
+
__classPrivateFieldSet(this, _AirService_recoveryIframeController, new IframeController(recoveryUrl, `air-recovery-${randomId()}`), "f");
|
|
3023
|
+
__classPrivateFieldGet(this, _AirService_recoveryIframeController, "f").createIframe();
|
|
3024
|
+
log.info(recoveryUrl, "url loaded");
|
|
3025
|
+
await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").open(__classPrivateFieldGet(this, _AirService_recoveryIframeController, "f").iframeElement);
|
|
3026
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_subscribeToRecoveryEvents).call(this);
|
|
3027
|
+
const recoveryInitPromise = __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").onInitialized();
|
|
3028
|
+
await recoveryInitRequestPromise;
|
|
3029
|
+
await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").initRecoveryCommunication();
|
|
3030
|
+
await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").initAuthCommunication();
|
|
3031
|
+
const recoveryInitResult = await recoveryInitPromise;
|
|
3032
|
+
if (recoveryInitResult.payload.success !== true) {
|
|
3033
|
+
throw new AirServiceError(recoveryInitResult.payload.errorName, recoveryInitResult.payload.errorMessage);
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
catch (error) {
|
|
3037
|
+
log.error("Error initializing recovery", error);
|
|
3038
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
|
|
3039
|
+
throw error;
|
|
3040
|
+
}
|
|
3041
|
+
}, _AirService_subscribeToRecoveryEvents = function _AirService_subscribeToRecoveryEvents() {
|
|
3042
|
+
__classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").messages$.subscribe(async (message) => {
|
|
3043
|
+
switch (message.type) {
|
|
3044
|
+
case AirRecoveryMessageTypes.RECOVERY_IFRAME_VISIBILITY_REQUEST: {
|
|
3045
|
+
const recoveryIframeController = __classPrivateFieldGet(this, _AirService_recoveryIframeController, "f");
|
|
3046
|
+
recoveryIframeController.setIframeVisibility(message.payload.visible);
|
|
3047
|
+
recoveryIframeController.updateIframeState();
|
|
3048
|
+
break;
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
});
|
|
3052
|
+
}, _AirService_cleanUpRecovery = async function _AirService_cleanUpRecovery() {
|
|
3053
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
3054
|
+
return;
|
|
3055
|
+
// Logout recovery and destroy the recovery iframe
|
|
3056
|
+
const recoveryIframeElement = __classPrivateFieldGet(this, _AirService_recoveryIframeController, "f")?.iframeElement;
|
|
3057
|
+
if (isElement(recoveryIframeElement) && window.document.body.contains(recoveryIframeElement)) {
|
|
3058
|
+
await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").logout();
|
|
3059
|
+
__classPrivateFieldGet(this, _AirService_recoveryIframeController, "f").destroy();
|
|
3060
|
+
__classPrivateFieldSet(this, _AirService_recoveryIframeController, undefined, "f");
|
|
3061
|
+
}
|
|
3062
|
+
const authIframeElement = __classPrivateFieldGet(this, _AirService_authIframeController, "f")?.iframeElement;
|
|
3063
|
+
if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
|
|
3064
|
+
await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").resetRecoveryCommunication();
|
|
3065
|
+
}
|
|
3066
|
+
// Close the message service
|
|
3067
|
+
await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").close();
|
|
3068
|
+
__classPrivateFieldSet(this, _AirService_recoveryInitialization, undefined, "f");
|
|
2813
3069
|
};
|
|
2814
3070
|
|
|
2815
3071
|
exports.AirService = AirService;
|