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