@mocanetwork/airkit-connector 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/airkitConnector.cjs.js +899 -634
- package/dist/airkitConnector.esm.js +899 -634
- package/dist/airkitConnector.umd.js +899 -634
- package/package.json +2 -2
- package/src/lib/connector.ts +1 -0
|
@@ -98,13 +98,19 @@
|
|
|
98
98
|
var e = new Error(message);
|
|
99
99
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
100
100
|
};
|
|
101
|
+
var version$2 = "1.4.0-beta.1";
|
|
102
|
+
var airkitPackage = {
|
|
103
|
+
version: version$2
|
|
104
|
+
};
|
|
101
105
|
const AirAuthMessageTypes = {
|
|
102
106
|
AUTH_SETUP_COMPLETED: "air_auth_setup_completed",
|
|
103
107
|
INITIALIZATION_REQUEST: "air_auth_initialization_request",
|
|
104
108
|
INITIALIZATION_RESPONSE: "air_auth_initialization_response",
|
|
105
109
|
LOGIN_REQUEST: "air_auth_login_request",
|
|
106
110
|
LOGIN_RESPONSE: "air_auth_login_response",
|
|
107
|
-
|
|
111
|
+
LOGIN_SERVICE_RESPONSE: "air_auth_login_service_response",
|
|
112
|
+
PASSKEY_LOGIN_REQUEST: "air_auth_passkey_login_request",
|
|
113
|
+
PASSKEY_LOGIN_RESPONSE: "air_auth_passkey_login_response",
|
|
108
114
|
USER_INFO_REQUEST: "air_auth_user_info_request",
|
|
109
115
|
USER_INFO_RESPONSE: "air_auth_user_info_response",
|
|
110
116
|
PARTNER_USER_INFO_REQUEST: "air_auth_partner_user_info_request",
|
|
@@ -117,17 +123,37 @@
|
|
|
117
123
|
IFRAME_VISIBILITY_REQUEST: "air_auth_iframe_visibility_request",
|
|
118
124
|
SETUP_WALLET_REQUEST: "air_auth_setup_wallet_request",
|
|
119
125
|
SETUP_WALLET_RESPONSE: "air_auth_setup_wallet_response",
|
|
126
|
+
SETUP_RECOVERY_REQUEST: "air_auth_setup_recovery_request",
|
|
127
|
+
SETUP_RECOVERY_RESPONSE: "air_auth_setup_recovery_response",
|
|
120
128
|
SIGN_SIWE_MESSAGE_REQUEST: "air_auth_sign_siwe_message_request",
|
|
121
129
|
SIGN_SIWE_MESSAGE_RESPONSE: "air_auth_sign_siwe_message_response",
|
|
122
130
|
CROSS_PARTNER_TOKEN_REQUEST: "air_auth_cross_partner_token_request",
|
|
123
131
|
CROSS_PARTNER_TOKEN_RESPONSE: "air_auth_cross_partner_token_response",
|
|
124
132
|
PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_partner_access_token_request",
|
|
125
133
|
PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_partner_access_token_response",
|
|
134
|
+
PRIVY_LOGIN_REQUEST: "air_auth_privy_login_request",
|
|
135
|
+
PRIVY_LOGIN_RESPONSE: "air_auth_privy_login_response",
|
|
126
136
|
CREDENTIAL_SALT_REQUEST: "air_auth_credential_salt_request",
|
|
127
137
|
CREDENTIAL_SALT_RESPONSE: "air_auth_credential_salt_response",
|
|
128
138
|
LOGOUT_REQUEST: "air_auth_logout_request",
|
|
129
139
|
LOGOUT_RESPONSE: "air_auth_logout_response",
|
|
130
|
-
RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication"
|
|
140
|
+
RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication",
|
|
141
|
+
INIT_RECOVERY_COMMUNICATION: "air_auth_init_recovery_communication",
|
|
142
|
+
RESET_RECOVERY_COMMUNICATION: "air_auth_reset_recovery_communication",
|
|
143
|
+
START_RECOVERY_REQUEST: "air_start_recovery_request",
|
|
144
|
+
START_RECOVERY_RESPONSE: "air_start_recovery_response",
|
|
145
|
+
OTP_REQUEST: "air_auth_otp_request",
|
|
146
|
+
OTP_RESPONSE: "air_auth_otp_response"
|
|
147
|
+
};
|
|
148
|
+
const AirRecoveryMessageTypes = {
|
|
149
|
+
SERVICE_STARTED: "air_recovery_service_started",
|
|
150
|
+
INITIALIZATION_REQUEST: "air_recovery_initialization_request",
|
|
151
|
+
INITIALIZATION_RESPONSE: "air_recovery_initialization_response",
|
|
152
|
+
INIT_AUTH_COMMUNICATION: "air_recovery_init_auth_communication",
|
|
153
|
+
RECOVERY_INITIALIZED: "air_recovery_initialized",
|
|
154
|
+
RECOVERY_IFRAME_VISIBILITY_REQUEST: "air_recovery_iframe_visibility_request",
|
|
155
|
+
LOGOUT_REQUEST: "air_recovery_logout_request",
|
|
156
|
+
LOGOUT_RESPONSE: "air_recovery_logout_response"
|
|
131
157
|
};
|
|
132
158
|
const AirWalletMessageTypes = {
|
|
133
159
|
SERVICE_STARTED: "air_service_started",
|
|
@@ -141,223 +167,23 @@
|
|
|
141
167
|
SETUP_OR_UPDATE_MFA_RESPONSE: "air_setup_mfa_response",
|
|
142
168
|
CLAIM_ID_REQUEST: "air_claim_id_request",
|
|
143
169
|
CLAIM_ID_RESPONSE: "air_claim_id_response",
|
|
170
|
+
SHOW_SWAP_UI_REQUEST: "air_show_swap_ui_request",
|
|
171
|
+
SHOW_SWAP_UI_RESPONSE: "air_show_swap_ui_response",
|
|
144
172
|
DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request",
|
|
145
173
|
DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response",
|
|
146
174
|
WALLET_IFRAME_VISIBILITY_REQUEST: "air_wallet_iframe_visibility_request",
|
|
147
|
-
OPEN_WINDOW_REQUEST: "air_open_window_request",
|
|
148
|
-
OPEN_WINDOW_RESPONSE: "air_open_window_response",
|
|
149
|
-
OPEN_WINDOW_RETRY_REQUEST: "air_open_window_retry_request",
|
|
150
|
-
OPEN_WINDOW_RETRY_RESPONSE: "air_open_window_retry_response",
|
|
151
|
-
WINDOW_CLOSED: "air_window_closed",
|
|
152
175
|
IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request",
|
|
153
176
|
IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
|
|
154
177
|
LOGOUT_REQUEST: "air_logout_request",
|
|
155
178
|
LOGOUT_RESPONSE: "air_logout_response"
|
|
156
179
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
super(message || name);
|
|
164
|
-
this.name = name;
|
|
165
|
-
this.stack = cause?.stack;
|
|
166
|
-
this.cause = cause;
|
|
167
|
-
this.context = context;
|
|
168
|
-
}
|
|
169
|
-
toJSON() {
|
|
170
|
-
return {
|
|
171
|
-
name: this.name,
|
|
172
|
-
message: this.message,
|
|
173
|
-
context: this.context,
|
|
174
|
-
cause: this.cause
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
function ensureError(value) {
|
|
179
|
-
if (value instanceof Error) return value;
|
|
180
|
-
let stringified = "[Unable to stringify the thrown value]";
|
|
181
|
-
try {
|
|
182
|
-
stringified = JSON.stringify(value);
|
|
183
|
-
} catch {
|
|
184
|
-
// ignoring failed stringify
|
|
185
|
-
}
|
|
186
|
-
return new Error(`This value was not thrown as type Error: ${stringified}`);
|
|
187
|
-
}
|
|
188
|
-
const BUILD_ENV = {
|
|
189
|
-
PRODUCTION: "production",
|
|
190
|
-
UAT: "uat",
|
|
191
|
-
STAGING: "staging",
|
|
192
|
-
DEVELOPMENT: "development"
|
|
193
|
-
};
|
|
194
|
-
const AIR_URLS = {
|
|
195
|
-
[BUILD_ENV.DEVELOPMENT]: {
|
|
196
|
-
authUrl: "http://localhost:8200/auth/",
|
|
197
|
-
walletUrl: "http://localhost:8200/wallet/"
|
|
198
|
-
},
|
|
199
|
-
[BUILD_ENV.UAT]: {
|
|
200
|
-
authUrl: "https://account.uat.air3.com/auth/",
|
|
201
|
-
walletUrl: "https://account.uat.air3.com/wallet/"
|
|
202
|
-
},
|
|
203
|
-
[BUILD_ENV.STAGING]: {
|
|
204
|
-
authUrl: "https://account.staging.air3.com/auth/",
|
|
205
|
-
walletUrl: "https://account.staging.air3.com/wallet/"
|
|
206
|
-
},
|
|
207
|
-
[BUILD_ENV.PRODUCTION]: {
|
|
208
|
-
authUrl: "https://account.air3.com/auth/",
|
|
209
|
-
walletUrl: "https://account.air3.com/wallet/"
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
const isElement = element => element instanceof Element || element instanceof Document;
|
|
213
|
-
const randomId = () => Math.random().toString(36).slice(2);
|
|
214
|
-
const extractErrorHash = message => {
|
|
215
|
-
if (!message) return "";
|
|
216
|
-
// Format: "reason: 0x..."
|
|
217
|
-
if (message.includes("reason:")) {
|
|
218
|
-
return message.split("reason:")[1].trim();
|
|
219
|
-
}
|
|
220
|
-
// Format: "UserOperation reverted during simulation with reason: 0x..."
|
|
221
|
-
if (message.includes("with reason:")) {
|
|
222
|
-
const match = message.match(/with reason: (0x[a-fA-F0-9]+)/);
|
|
223
|
-
return match ? match[1].trim() : "";
|
|
224
|
-
}
|
|
225
|
-
// Look for any 0x pattern that could be a hash
|
|
226
|
-
const hexMatch = message.match(/(0x[a-fA-F0-9]{8,})/);
|
|
227
|
-
return hexMatch ? hexMatch[1].trim() : "";
|
|
228
|
-
};
|
|
229
|
-
class AirServiceError extends BaseError$2 {
|
|
230
|
-
static from(error) {
|
|
231
|
-
if (error instanceof AirServiceError) {
|
|
232
|
-
return error;
|
|
233
|
-
} else if (error instanceof Object && "message" in error) {
|
|
234
|
-
if (error.message === "User cancelled login") {
|
|
235
|
-
return new AirServiceError("USER_CANCELLED", error.message);
|
|
236
|
-
}
|
|
237
|
-
return new AirServiceError("UNKNOWN_ERROR", error.message.toString());
|
|
238
|
-
}
|
|
239
|
-
return new AirServiceError("UNKNOWN_ERROR");
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
let ProviderRpcError$1 = class ProviderRpcError extends Error {
|
|
243
|
-
constructor(message) {
|
|
244
|
-
super(message);
|
|
245
|
-
this.metaMessages = [];
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
let UserRejectedRequestError$1 = class UserRejectedRequestError extends ProviderRpcError$1 {
|
|
249
|
-
constructor() {
|
|
250
|
-
super(...arguments);
|
|
251
|
-
this.code = 4001;
|
|
252
|
-
this.name = "UserRejectedRequestError";
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
class UnauthorizedProviderError extends ProviderRpcError$1 {
|
|
256
|
-
constructor() {
|
|
257
|
-
super(...arguments);
|
|
258
|
-
this.code = 4100;
|
|
259
|
-
this.name = "UnauthorizedProviderError";
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
class UnsupportedProviderMethodError extends ProviderRpcError$1 {
|
|
263
|
-
constructor() {
|
|
264
|
-
super(...arguments);
|
|
265
|
-
this.code = 4200;
|
|
266
|
-
this.name = "UnsupportedProviderMethodError";
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
class ProviderDisconnectedError extends ProviderRpcError$1 {
|
|
270
|
-
constructor() {
|
|
271
|
-
super(...arguments);
|
|
272
|
-
this.code = 4900;
|
|
273
|
-
this.name = "ProviderDisconnectedError";
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
class ChainDisconnectedError extends ProviderRpcError$1 {
|
|
277
|
-
constructor() {
|
|
278
|
-
super(...arguments);
|
|
279
|
-
this.code = 4901;
|
|
280
|
-
this.name = "ChainDisconnectedError";
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
let SwitchChainError$1 = class SwitchChainError extends ProviderRpcError$1 {
|
|
284
|
-
constructor() {
|
|
285
|
-
super(...arguments);
|
|
286
|
-
this.code = 4902;
|
|
287
|
-
this.name = "SwitchChainError";
|
|
288
|
-
}
|
|
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"
|
|
289
186
|
};
|
|
290
|
-
class TransactionRejectedRpcError extends ProviderRpcError$1 {
|
|
291
|
-
constructor(message) {
|
|
292
|
-
// Remove the "Version: viem@x.x.x" suffix if present
|
|
293
|
-
const cleanMessage = message.replace(/\nVersion:.*$/, '');
|
|
294
|
-
super(cleanMessage);
|
|
295
|
-
this.code = -32003;
|
|
296
|
-
this.name = "TransactionRejectedRpcError";
|
|
297
|
-
// Parse the error hash from the message
|
|
298
|
-
this.metaMessages.push(extractErrorHash(cleanMessage));
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
class InvalidRequestRpcError extends ProviderRpcError$1 {
|
|
302
|
-
constructor() {
|
|
303
|
-
super(...arguments);
|
|
304
|
-
this.code = -32600;
|
|
305
|
-
this.name = "InvalidRequestRpcError";
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
class MethodNotFoundRpcError extends ProviderRpcError$1 {
|
|
309
|
-
constructor() {
|
|
310
|
-
super(...arguments);
|
|
311
|
-
this.code = -32601;
|
|
312
|
-
this.name = "MethodNotFoundRpcError";
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
class InvalidParamsRpcError extends ProviderRpcError$1 {
|
|
316
|
-
constructor() {
|
|
317
|
-
super(...arguments);
|
|
318
|
-
this.code = -32602;
|
|
319
|
-
this.name = "InvalidParamsRpcError";
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
class InternalRpcError extends ProviderRpcError$1 {
|
|
323
|
-
constructor() {
|
|
324
|
-
super(...arguments);
|
|
325
|
-
this.code = -32603;
|
|
326
|
-
this.name = "InternalRpcError";
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
function ensureProviderRpcError(value) {
|
|
330
|
-
if (value instanceof ProviderRpcError$1) {
|
|
331
|
-
return value;
|
|
332
|
-
}
|
|
333
|
-
if (typeof value === "object" && value !== null && "errorCode" in value && "errorMessage" in value) {
|
|
334
|
-
if (typeof value.errorCode === "number" && typeof value.errorMessage === "string") {
|
|
335
|
-
switch (value.errorCode) {
|
|
336
|
-
case 4001:
|
|
337
|
-
return new UserRejectedRequestError$1(value.errorMessage);
|
|
338
|
-
case 4100:
|
|
339
|
-
return new UnauthorizedProviderError(value.errorMessage);
|
|
340
|
-
case 4200:
|
|
341
|
-
return new UnsupportedProviderMethodError(value.errorMessage);
|
|
342
|
-
case 4900:
|
|
343
|
-
return new ProviderDisconnectedError(value.errorMessage);
|
|
344
|
-
case 4901:
|
|
345
|
-
return new ChainDisconnectedError(value.errorMessage);
|
|
346
|
-
case 4902:
|
|
347
|
-
return new SwitchChainError$1(value.errorMessage);
|
|
348
|
-
case -32003:
|
|
349
|
-
return new TransactionRejectedRpcError(value.errorMessage);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
let stringified = "[Unable to stringify the thrown value]";
|
|
354
|
-
try {
|
|
355
|
-
stringified = JSON.stringify(value);
|
|
356
|
-
} catch {
|
|
357
|
-
// ignoring failed stringify
|
|
358
|
-
}
|
|
359
|
-
return new InternalRpcError(`Invalid value for ProviderRpcError: ${stringified}`);
|
|
360
|
-
}
|
|
361
187
|
function getDefaultExportFromCjs$1(x) {
|
|
362
188
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
363
189
|
}
|
|
@@ -686,44 +512,281 @@
|
|
|
686
512
|
}
|
|
687
513
|
var loglevelExports$1 = requireLoglevel$1();
|
|
688
514
|
var log$1 = /*@__PURE__*/getDefaultExportFromCjs$1(loglevelExports$1);
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
return ctorFunc;
|
|
701
|
-
}
|
|
702
|
-
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
703
|
-
return function UnsubscriptionErrorImpl(errors) {
|
|
704
|
-
_super(this);
|
|
705
|
-
this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) {
|
|
706
|
-
return i + 1 + ") " + err.toString();
|
|
707
|
-
}).join('\n ') : '';
|
|
708
|
-
this.name = 'UnsubscriptionError';
|
|
709
|
-
this.errors = errors;
|
|
710
|
-
};
|
|
711
|
-
});
|
|
712
|
-
function arrRemove(arr, item) {
|
|
713
|
-
if (arr) {
|
|
714
|
-
var index = arr.indexOf(item);
|
|
715
|
-
0 <= index && arr.splice(index, 1);
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
var Subscription = function () {
|
|
719
|
-
function Subscription(initialTeardown) {
|
|
720
|
-
this.initialTeardown = initialTeardown;
|
|
721
|
-
this.closed = false;
|
|
722
|
-
this._parentage = null;
|
|
723
|
-
this._finalizers = null;
|
|
515
|
+
let BaseError$2 = class BaseError extends Error {
|
|
516
|
+
constructor(name, message, options = {}) {
|
|
517
|
+
const {
|
|
518
|
+
cause,
|
|
519
|
+
context
|
|
520
|
+
} = options;
|
|
521
|
+
super(message || name);
|
|
522
|
+
this.name = name;
|
|
523
|
+
this.stack = cause?.stack;
|
|
524
|
+
this.cause = cause;
|
|
525
|
+
this.context = context;
|
|
724
526
|
}
|
|
725
|
-
|
|
726
|
-
|
|
527
|
+
toJSON() {
|
|
528
|
+
return {
|
|
529
|
+
name: this.name,
|
|
530
|
+
message: this.message,
|
|
531
|
+
context: this.context,
|
|
532
|
+
cause: this.cause
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
function ensureError(value) {
|
|
537
|
+
if (value instanceof Error) return value;
|
|
538
|
+
let stringified = "[Unable to stringify the thrown value]";
|
|
539
|
+
try {
|
|
540
|
+
stringified = JSON.stringify(value);
|
|
541
|
+
} catch {
|
|
542
|
+
// ignoring failed stringify
|
|
543
|
+
}
|
|
544
|
+
return new Error(`This value was not thrown as type Error: ${stringified}`);
|
|
545
|
+
}
|
|
546
|
+
const getLevelName = levelNum => {
|
|
547
|
+
const levelNames = Object.keys(log$1.levels);
|
|
548
|
+
if (levelNum >= 0 && levelNum < levelNames.length) {
|
|
549
|
+
return levelNames[levelNum];
|
|
550
|
+
}
|
|
551
|
+
return "UNKNOWN";
|
|
552
|
+
};
|
|
553
|
+
const configureLogLevel = (environment, enableLogging) => {
|
|
554
|
+
let level = log$1.levels.ERROR;
|
|
555
|
+
if (environment === "development") {
|
|
556
|
+
level = enableLogging ? log$1.levels.TRACE : log$1.levels.INFO;
|
|
557
|
+
} else if (environment === "staging") {
|
|
558
|
+
level = enableLogging ? log$1.levels.DEBUG : log$1.levels.INFO;
|
|
559
|
+
} else if (environment === "uat") {
|
|
560
|
+
level = enableLogging ? log$1.levels.INFO : log$1.levels.WARN;
|
|
561
|
+
} else if (environment === "production") {
|
|
562
|
+
// Be cautious with enabling more than WARN in prod
|
|
563
|
+
level = enableLogging ? log$1.levels.WARN : log$1.levels.ERROR;
|
|
564
|
+
}
|
|
565
|
+
log$1.setLevel(level);
|
|
566
|
+
log$1.info(`[${window?.location?.href}] LogLevel: ${getLevelName(log$1.getLevel())}`);
|
|
567
|
+
};
|
|
568
|
+
const BUILD_ENV = {
|
|
569
|
+
PRODUCTION: "production",
|
|
570
|
+
UAT: "uat",
|
|
571
|
+
STAGING: "staging",
|
|
572
|
+
DEVELOPMENT: "development",
|
|
573
|
+
SANDBOX: "sandbox"
|
|
574
|
+
};
|
|
575
|
+
const AIR_URLS = {
|
|
576
|
+
[BUILD_ENV.DEVELOPMENT]: {
|
|
577
|
+
authUrl: "http://localhost:8200/auth/",
|
|
578
|
+
walletUrl: "http://localhost:8200/wallet/",
|
|
579
|
+
recoveryUrl: "http://localhost:8200/recovery/"
|
|
580
|
+
},
|
|
581
|
+
[BUILD_ENV.STAGING]: {
|
|
582
|
+
authUrl: "https://account.staging.air3.com/auth/",
|
|
583
|
+
walletUrl: "https://account.staging.air3.com/wallet/",
|
|
584
|
+
recoveryUrl: "https://account.staging.air3.com/recovery/"
|
|
585
|
+
},
|
|
586
|
+
[BUILD_ENV.UAT]: {
|
|
587
|
+
authUrl: "https://account.uat.air3.com/auth/",
|
|
588
|
+
walletUrl: "https://account.uat.air3.com/wallet/",
|
|
589
|
+
recoveryUrl: "https://account.uat.air3.com/recovery/"
|
|
590
|
+
},
|
|
591
|
+
[BUILD_ENV.SANDBOX]: {
|
|
592
|
+
authUrl: "https://account.sandbox.air3.com/auth/",
|
|
593
|
+
walletUrl: "https://account.sandbox.air3.com/wallet/",
|
|
594
|
+
recoveryUrl: "https://account.sandbox.air3.com/recovery/"
|
|
595
|
+
},
|
|
596
|
+
[BUILD_ENV.PRODUCTION]: {
|
|
597
|
+
authUrl: "https://account.air3.com/auth/",
|
|
598
|
+
walletUrl: "https://account.air3.com/wallet/",
|
|
599
|
+
recoveryUrl: "https://account.air3.com/recovery/"
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
const isElement = element => element instanceof Element || element instanceof Document;
|
|
603
|
+
const randomId = () => Math.random().toString(36).slice(2);
|
|
604
|
+
const extractErrorHash = message => {
|
|
605
|
+
if (!message) return "";
|
|
606
|
+
// Format: "reason: 0x..."
|
|
607
|
+
if (message.includes("reason:")) {
|
|
608
|
+
const match = message.match(/reason:\s*(0x[a-fA-F0-9]+)/);
|
|
609
|
+
return match ? match[1].trim() : "";
|
|
610
|
+
}
|
|
611
|
+
// Format: "UserOperation reverted during simulation with reason: 0x..."
|
|
612
|
+
if (message.includes("with reason:")) {
|
|
613
|
+
const match = message.match(/with reason:\s*(0x[a-fA-F0-9]+)/);
|
|
614
|
+
return match ? match[1].trim() : "";
|
|
615
|
+
}
|
|
616
|
+
// Look for any 0x pattern that could be a hash
|
|
617
|
+
const hexMatch = message.match(/(0x[a-fA-F0-9]{8,})/);
|
|
618
|
+
return hexMatch ? hexMatch[1].trim() : "";
|
|
619
|
+
};
|
|
620
|
+
class AirServiceError extends BaseError$2 {
|
|
621
|
+
static from(error) {
|
|
622
|
+
if (error instanceof AirServiceError) {
|
|
623
|
+
return error;
|
|
624
|
+
} else if (error instanceof Object && "message" in error) {
|
|
625
|
+
if (error.message === "User cancelled login") {
|
|
626
|
+
return new AirServiceError("USER_CANCELLED", error.message);
|
|
627
|
+
}
|
|
628
|
+
return new AirServiceError("UNKNOWN_ERROR", error.message.toString());
|
|
629
|
+
}
|
|
630
|
+
return new AirServiceError("UNKNOWN_ERROR");
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
let ProviderRpcError$1 = class ProviderRpcError extends Error {
|
|
634
|
+
constructor(message) {
|
|
635
|
+
super(message);
|
|
636
|
+
this.metaMessages = [];
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
let UserRejectedRequestError$1 = class UserRejectedRequestError extends ProviderRpcError$1 {
|
|
640
|
+
constructor() {
|
|
641
|
+
super(...arguments);
|
|
642
|
+
this.code = 4001;
|
|
643
|
+
this.name = "UserRejectedRequestError";
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
class UnauthorizedProviderError extends ProviderRpcError$1 {
|
|
647
|
+
constructor() {
|
|
648
|
+
super(...arguments);
|
|
649
|
+
this.code = 4100;
|
|
650
|
+
this.name = "UnauthorizedProviderError";
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
class UnsupportedProviderMethodError extends ProviderRpcError$1 {
|
|
654
|
+
constructor() {
|
|
655
|
+
super(...arguments);
|
|
656
|
+
this.code = 4200;
|
|
657
|
+
this.name = "UnsupportedProviderMethodError";
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
class ProviderDisconnectedError extends ProviderRpcError$1 {
|
|
661
|
+
constructor() {
|
|
662
|
+
super(...arguments);
|
|
663
|
+
this.code = 4900;
|
|
664
|
+
this.name = "ProviderDisconnectedError";
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
class ChainDisconnectedError extends ProviderRpcError$1 {
|
|
668
|
+
constructor() {
|
|
669
|
+
super(...arguments);
|
|
670
|
+
this.code = 4901;
|
|
671
|
+
this.name = "ChainDisconnectedError";
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
let SwitchChainError$1 = class SwitchChainError extends ProviderRpcError$1 {
|
|
675
|
+
constructor() {
|
|
676
|
+
super(...arguments);
|
|
677
|
+
this.code = 4902;
|
|
678
|
+
this.name = "SwitchChainError";
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
class TransactionRejectedRpcError extends ProviderRpcError$1 {
|
|
682
|
+
constructor(message) {
|
|
683
|
+
// Remove the "Version: viem@x.x.x" suffix if present
|
|
684
|
+
const cleanMessage = message.replace(/\nVersion:.*$/, '');
|
|
685
|
+
super(cleanMessage);
|
|
686
|
+
this.code = -32003;
|
|
687
|
+
this.name = "TransactionRejectedRpcError";
|
|
688
|
+
// Parse the error hash from the message
|
|
689
|
+
this.metaMessages.push(extractErrorHash(cleanMessage));
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
class InvalidRequestRpcError extends ProviderRpcError$1 {
|
|
693
|
+
constructor() {
|
|
694
|
+
super(...arguments);
|
|
695
|
+
this.code = -32600;
|
|
696
|
+
this.name = "InvalidRequestRpcError";
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
class MethodNotFoundRpcError extends ProviderRpcError$1 {
|
|
700
|
+
constructor() {
|
|
701
|
+
super(...arguments);
|
|
702
|
+
this.code = -32601;
|
|
703
|
+
this.name = "MethodNotFoundRpcError";
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
class InvalidParamsRpcError extends ProviderRpcError$1 {
|
|
707
|
+
constructor() {
|
|
708
|
+
super(...arguments);
|
|
709
|
+
this.code = -32602;
|
|
710
|
+
this.name = "InvalidParamsRpcError";
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
class InternalRpcError extends ProviderRpcError$1 {
|
|
714
|
+
constructor() {
|
|
715
|
+
super(...arguments);
|
|
716
|
+
this.code = -32603;
|
|
717
|
+
this.name = "InternalRpcError";
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
function ensureProviderRpcError(value) {
|
|
721
|
+
if (value instanceof ProviderRpcError$1) {
|
|
722
|
+
return value;
|
|
723
|
+
}
|
|
724
|
+
if (typeof value === "object" && value !== null && "errorCode" in value && "errorMessage" in value) {
|
|
725
|
+
if (typeof value.errorCode === "number" && typeof value.errorMessage === "string") {
|
|
726
|
+
switch (value.errorCode) {
|
|
727
|
+
case 4001:
|
|
728
|
+
return new UserRejectedRequestError$1(value.errorMessage);
|
|
729
|
+
case 4100:
|
|
730
|
+
return new UnauthorizedProviderError(value.errorMessage);
|
|
731
|
+
case 4200:
|
|
732
|
+
return new UnsupportedProviderMethodError(value.errorMessage);
|
|
733
|
+
case 4900:
|
|
734
|
+
return new ProviderDisconnectedError(value.errorMessage);
|
|
735
|
+
case 4901:
|
|
736
|
+
return new ChainDisconnectedError(value.errorMessage);
|
|
737
|
+
case 4902:
|
|
738
|
+
return new SwitchChainError$1(value.errorMessage);
|
|
739
|
+
case -32003:
|
|
740
|
+
return new TransactionRejectedRpcError(value.errorMessage);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
let stringified = "[Unable to stringify the thrown value]";
|
|
745
|
+
try {
|
|
746
|
+
stringified = JSON.stringify(value);
|
|
747
|
+
} catch {
|
|
748
|
+
// ignoring failed stringify
|
|
749
|
+
}
|
|
750
|
+
return new InternalRpcError(`Invalid value for ProviderRpcError: ${stringified}`);
|
|
751
|
+
}
|
|
752
|
+
function isFunction(value) {
|
|
753
|
+
return typeof value === 'function';
|
|
754
|
+
}
|
|
755
|
+
function createErrorClass(createImpl) {
|
|
756
|
+
var _super = function (instance) {
|
|
757
|
+
Error.call(instance);
|
|
758
|
+
instance.stack = new Error().stack;
|
|
759
|
+
};
|
|
760
|
+
var ctorFunc = createImpl(_super);
|
|
761
|
+
ctorFunc.prototype = Object.create(Error.prototype);
|
|
762
|
+
ctorFunc.prototype.constructor = ctorFunc;
|
|
763
|
+
return ctorFunc;
|
|
764
|
+
}
|
|
765
|
+
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
766
|
+
return function UnsubscriptionErrorImpl(errors) {
|
|
767
|
+
_super(this);
|
|
768
|
+
this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) {
|
|
769
|
+
return i + 1 + ") " + err.toString();
|
|
770
|
+
}).join('\n ') : '';
|
|
771
|
+
this.name = 'UnsubscriptionError';
|
|
772
|
+
this.errors = errors;
|
|
773
|
+
};
|
|
774
|
+
});
|
|
775
|
+
function arrRemove(arr, item) {
|
|
776
|
+
if (arr) {
|
|
777
|
+
var index = arr.indexOf(item);
|
|
778
|
+
0 <= index && arr.splice(index, 1);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
var Subscription = function () {
|
|
782
|
+
function Subscription(initialTeardown) {
|
|
783
|
+
this.initialTeardown = initialTeardown;
|
|
784
|
+
this.closed = false;
|
|
785
|
+
this._parentage = null;
|
|
786
|
+
this._finalizers = null;
|
|
787
|
+
}
|
|
788
|
+
Subscription.prototype.unsubscribe = function () {
|
|
789
|
+
var e_1, _a, e_2, _b;
|
|
727
790
|
var errors;
|
|
728
791
|
if (!this.closed) {
|
|
729
792
|
this.closed = true;
|
|
@@ -1687,15 +1750,17 @@
|
|
|
1687
1750
|
_ProviderMessageService_instance = {
|
|
1688
1751
|
value: void 0
|
|
1689
1752
|
};
|
|
1690
|
-
var _AirWalletProvider_instances, _AirWalletProvider_providerMessageService,
|
|
1753
|
+
var _AirWalletProvider_instances, _AirWalletProvider_providerMessageService, _AirWalletProvider_isWalletInitialized, _AirWalletProvider_getLoginResult, _AirWalletProvider_ensureWallet, _AirWalletProvider_eventListeners, _AirWalletProvider_emit;
|
|
1691
1754
|
class AirWalletProvider {
|
|
1692
1755
|
constructor({
|
|
1693
|
-
|
|
1694
|
-
|
|
1756
|
+
ensureWallet,
|
|
1757
|
+
isWalletInitialized,
|
|
1758
|
+
getLoginResult
|
|
1695
1759
|
}) {
|
|
1696
1760
|
_AirWalletProvider_instances.add(this);
|
|
1697
1761
|
_AirWalletProvider_providerMessageService.set(this, void 0);
|
|
1698
|
-
|
|
1762
|
+
_AirWalletProvider_isWalletInitialized.set(this, void 0);
|
|
1763
|
+
_AirWalletProvider_getLoginResult.set(this, void 0);
|
|
1699
1764
|
_AirWalletProvider_ensureWallet.set(this, void 0);
|
|
1700
1765
|
_AirWalletProvider_eventListeners.set(this, void 0);
|
|
1701
1766
|
this.startEventMessageListening = async walletIframe => {
|
|
@@ -1705,7 +1770,6 @@
|
|
|
1705
1770
|
});
|
|
1706
1771
|
};
|
|
1707
1772
|
__classPrivateFieldSet(this, _AirWalletProvider_providerMessageService, ProviderMessageService.create());
|
|
1708
|
-
__classPrivateFieldSet(this, _AirWalletProvider_isLoggedIn, isLoggedIn);
|
|
1709
1773
|
__classPrivateFieldSet(this, _AirWalletProvider_ensureWallet, ensureWallet);
|
|
1710
1774
|
__classPrivateFieldSet(this, _AirWalletProvider_eventListeners, {
|
|
1711
1775
|
connect: [],
|
|
@@ -1714,6 +1778,8 @@
|
|
|
1714
1778
|
chainChanged: [],
|
|
1715
1779
|
message: []
|
|
1716
1780
|
});
|
|
1781
|
+
__classPrivateFieldSet(this, _AirWalletProvider_isWalletInitialized, isWalletInitialized);
|
|
1782
|
+
__classPrivateFieldSet(this, _AirWalletProvider_getLoginResult, getLoginResult);
|
|
1717
1783
|
}
|
|
1718
1784
|
async request(request) {
|
|
1719
1785
|
// Check if the request is valid
|
|
@@ -1732,11 +1798,14 @@
|
|
|
1732
1798
|
if (params !== undefined && !Array.isArray(params) && (typeof params !== "object" || params === null)) {
|
|
1733
1799
|
throw new InvalidParamsRpcError("Invalid params");
|
|
1734
1800
|
}
|
|
1735
|
-
|
|
1736
|
-
if (!
|
|
1801
|
+
const loginResult = __classPrivateFieldGet$1(this, _AirWalletProvider_getLoginResult, "f").call(this);
|
|
1802
|
+
if (!loginResult) {
|
|
1737
1803
|
throw new UnauthorizedProviderError("User is not logged in");
|
|
1738
1804
|
}
|
|
1739
|
-
|
|
1805
|
+
if (method === "eth_accounts" && !__classPrivateFieldGet$1(this, _AirWalletProvider_isWalletInitialized, "f").call(this) && loginResult?.abstractAccountAddress) {
|
|
1806
|
+
return [loginResult.abstractAccountAddress];
|
|
1807
|
+
}
|
|
1808
|
+
const skipWalletLoginMethods = ["eth_chainId"];
|
|
1740
1809
|
try {
|
|
1741
1810
|
if (skipWalletLoginMethods.includes(method)) {
|
|
1742
1811
|
await __classPrivateFieldGet$1(this, _AirWalletProvider_ensureWallet, "f").call(this, {
|
|
@@ -1779,7 +1848,7 @@
|
|
|
1779
1848
|
});
|
|
1780
1849
|
}
|
|
1781
1850
|
}
|
|
1782
|
-
_AirWalletProvider_providerMessageService = new WeakMap(),
|
|
1851
|
+
_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) {
|
|
1783
1852
|
(__classPrivateFieldGet$1(this, _AirWalletProvider_eventListeners, "f")[eventName] || []).forEach(listener => {
|
|
1784
1853
|
try {
|
|
1785
1854
|
return listener(...args);
|
|
@@ -1788,274 +1857,8 @@
|
|
|
1788
1857
|
}
|
|
1789
1858
|
});
|
|
1790
1859
|
};
|
|
1791
|
-
class IframeController {
|
|
1792
|
-
constructor(iframeUrl, iframeId, state) {
|
|
1793
|
-
this._iframeElement = null;
|
|
1794
|
-
this.state = {
|
|
1795
|
-
...IframeController.defaultState,
|
|
1796
|
-
...state
|
|
1797
|
-
};
|
|
1798
|
-
this.iframeUrl = iframeUrl;
|
|
1799
|
-
this.iframeId = iframeId;
|
|
1800
|
-
}
|
|
1801
|
-
get iframeElement() {
|
|
1802
|
-
return this._iframeElement;
|
|
1803
|
-
}
|
|
1804
|
-
createIframe() {
|
|
1805
|
-
if (this._iframeElement) return this._iframeElement;
|
|
1806
|
-
const iframe = document.createElement("iframe");
|
|
1807
|
-
iframe.id = this.iframeId;
|
|
1808
|
-
iframe.allow = "publickey-credentials-get *; publickey-credentials-create *";
|
|
1809
|
-
iframe.src = this.iframeUrl;
|
|
1810
|
-
iframe.style.position = "fixed";
|
|
1811
|
-
iframe.style.zIndex = "999999";
|
|
1812
|
-
iframe.style.border = "none";
|
|
1813
|
-
iframe.style.margin = "0";
|
|
1814
|
-
iframe.style.padding = "0";
|
|
1815
|
-
iframe.style.display = "none";
|
|
1816
|
-
iframe.style.colorScheme = "auto";
|
|
1817
|
-
document.body.appendChild(iframe);
|
|
1818
|
-
this._iframeElement = iframe;
|
|
1819
|
-
return iframe;
|
|
1820
|
-
}
|
|
1821
|
-
setIframeVisibility(isVisible) {
|
|
1822
|
-
this.state.isVisible = isVisible;
|
|
1823
|
-
}
|
|
1824
|
-
updateIframeState() {
|
|
1825
|
-
if (!this.iframeElement) return;
|
|
1826
|
-
const style = {};
|
|
1827
|
-
style.display = this.state.isVisible ? "block" : "none";
|
|
1828
|
-
style.width = "100%";
|
|
1829
|
-
style.height = "100%";
|
|
1830
|
-
style.top = "0px";
|
|
1831
|
-
style.right = "0px";
|
|
1832
|
-
style.left = "0px";
|
|
1833
|
-
style.bottom = "0px";
|
|
1834
|
-
Object.assign(this.iframeElement.style, style);
|
|
1835
|
-
}
|
|
1836
|
-
destroy() {
|
|
1837
|
-
if (this.iframeElement) {
|
|
1838
|
-
this.iframeElement.remove();
|
|
1839
|
-
this._iframeElement = null;
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
postMessage(message) {
|
|
1843
|
-
if (!this.iframeElement) return;
|
|
1844
|
-
const {
|
|
1845
|
-
origin
|
|
1846
|
-
} = new URL(this.iframeElement.src);
|
|
1847
|
-
this.iframeElement.contentWindow.postMessage(message, origin);
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
IframeController.defaultState = {
|
|
1851
|
-
isVisible: false
|
|
1852
|
-
};
|
|
1853
|
-
class WindowController {
|
|
1854
|
-
get messages$() {
|
|
1855
|
-
return this._messages$.asObservable();
|
|
1856
|
-
}
|
|
1857
|
-
constructor(windowId, windowUrl) {
|
|
1858
|
-
this._windowInstance = null;
|
|
1859
|
-
this._messageHandler = null;
|
|
1860
|
-
this._messages$ = new Subject();
|
|
1861
|
-
this.windowId = windowId;
|
|
1862
|
-
this.windowUrl = windowUrl;
|
|
1863
|
-
this.windowOrigin = new URL(windowUrl).origin;
|
|
1864
|
-
this._messageHandler = ev => {
|
|
1865
|
-
if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin || !ev.data || !(ev.data instanceof Object)) {
|
|
1866
|
-
return;
|
|
1867
|
-
}
|
|
1868
|
-
this._messages$.next(ev);
|
|
1869
|
-
};
|
|
1870
|
-
window.addEventListener("message", this._messageHandler);
|
|
1871
|
-
}
|
|
1872
|
-
get windowInstance() {
|
|
1873
|
-
return this._windowInstance;
|
|
1874
|
-
}
|
|
1875
|
-
async openWindow(onRetry) {
|
|
1876
|
-
let windowInstance = this.tryOpenWindow();
|
|
1877
|
-
if (!windowInstance) {
|
|
1878
|
-
await onRetry();
|
|
1879
|
-
windowInstance = this.tryOpenWindow();
|
|
1880
|
-
if (!windowInstance) {
|
|
1881
|
-
throw new AirError(WindowErrorName.WINDOW_BLOCKED);
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
const pendingWindowOpenCheck = new Promise((resolve, reject) => {
|
|
1885
|
-
setTimeout(() => {
|
|
1886
|
-
if (this.isWindowOpen(windowInstance)) {
|
|
1887
|
-
// only now are we scheduling the close event check since we're sure the window is open
|
|
1888
|
-
this.scheduleWindowClosedChecks(windowInstance);
|
|
1889
|
-
resolve("opened");
|
|
1890
|
-
} else {
|
|
1891
|
-
onRetry().then(() => {
|
|
1892
|
-
windowInstance = this.tryOpenWindow();
|
|
1893
|
-
if (windowInstance) {
|
|
1894
|
-
this._windowInstance = windowInstance;
|
|
1895
|
-
windowInstance.focus();
|
|
1896
|
-
this.scheduleWindowClosedChecks(windowInstance);
|
|
1897
|
-
resolve("retry");
|
|
1898
|
-
} else {
|
|
1899
|
-
reject(new AirError(WindowErrorName.WINDOW_BLOCKED));
|
|
1900
|
-
}
|
|
1901
|
-
}).catch(reject);
|
|
1902
|
-
}
|
|
1903
|
-
}, 1000);
|
|
1904
|
-
});
|
|
1905
|
-
this._windowInstance = windowInstance;
|
|
1906
|
-
windowInstance.focus();
|
|
1907
|
-
return {
|
|
1908
|
-
pendingWindowOpenCheck
|
|
1909
|
-
};
|
|
1910
|
-
}
|
|
1911
|
-
postMessage(message, transfer) {
|
|
1912
|
-
if (!this._windowInstance) return;
|
|
1913
|
-
this._windowInstance.postMessage(message, this.windowOrigin, transfer);
|
|
1914
|
-
}
|
|
1915
|
-
onMessage(callback) {
|
|
1916
|
-
const listener = ev => {
|
|
1917
|
-
if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin) return;
|
|
1918
|
-
callback(ev);
|
|
1919
|
-
};
|
|
1920
|
-
window.addEventListener("message", listener);
|
|
1921
|
-
const close = () => window.removeEventListener("message", listener);
|
|
1922
|
-
this.onClose(close);
|
|
1923
|
-
return {
|
|
1924
|
-
close
|
|
1925
|
-
};
|
|
1926
|
-
}
|
|
1927
|
-
cleanup() {
|
|
1928
|
-
if (this._windowInstance && !this._windowInstance.closed) {
|
|
1929
|
-
this._windowInstance.close();
|
|
1930
|
-
}
|
|
1931
|
-
this._windowInstance = null;
|
|
1932
|
-
if (this._messageHandler) {
|
|
1933
|
-
window.removeEventListener("message", this._messageHandler);
|
|
1934
|
-
this._messageHandler = null;
|
|
1935
|
-
}
|
|
1936
|
-
if (this._messages$ && !this._messages$.closed) {
|
|
1937
|
-
this._messages$.complete();
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
onClose(callback) {
|
|
1941
|
-
return this._messages$.subscribe({
|
|
1942
|
-
complete: callback
|
|
1943
|
-
});
|
|
1944
|
-
}
|
|
1945
|
-
isWindowOpen(windowInstance) {
|
|
1946
|
-
return !(!windowInstance || windowInstance.closed || typeof windowInstance.closed == "undefined");
|
|
1947
|
-
}
|
|
1948
|
-
tryOpenWindow() {
|
|
1949
|
-
const windowInstance = window.open(this.windowUrl, this.windowId, getWindowFeatures(425, 680));
|
|
1950
|
-
if (this.isWindowOpen(windowInstance)) {
|
|
1951
|
-
return windowInstance;
|
|
1952
|
-
}
|
|
1953
|
-
return null;
|
|
1954
|
-
}
|
|
1955
|
-
scheduleWindowClosedChecks(windowInstance) {
|
|
1956
|
-
const checkWindow = setInterval(() => {
|
|
1957
|
-
if (!windowInstance || windowInstance.closed) {
|
|
1958
|
-
clearInterval(checkWindow);
|
|
1959
|
-
if (windowInstance === this._windowInstance) {
|
|
1960
|
-
this.cleanup();
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
}, 500);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
class WindowService {
|
|
1967
|
-
constructor() {
|
|
1968
|
-
this.windowControllers = new Map();
|
|
1969
|
-
}
|
|
1970
|
-
static get instance() {
|
|
1971
|
-
return this._instance || (this._instance = new this());
|
|
1972
|
-
}
|
|
1973
|
-
async sendWindowInitializationRequest(windowId, payload, port) {
|
|
1974
|
-
const windowController = this.windowControllers.get(windowId);
|
|
1975
|
-
if (!windowController) {
|
|
1976
|
-
throw new Error("Window controller not found");
|
|
1977
|
-
}
|
|
1978
|
-
const windowInstance = windowController.windowInstance;
|
|
1979
|
-
if (!windowInstance) {
|
|
1980
|
-
throw new Error("Window instance not found");
|
|
1981
|
-
}
|
|
1982
|
-
const response = firstValueFrom(windowController.messages$.pipe(filter(event => event.data.type === AirWalletMessageTypes.INITIALIZATION_RESPONSE)));
|
|
1983
|
-
windowController.postMessage({
|
|
1984
|
-
type: AirWalletMessageTypes.INITIALIZATION_REQUEST,
|
|
1985
|
-
payload
|
|
1986
|
-
}, [port]);
|
|
1987
|
-
return (await response).data;
|
|
1988
|
-
}
|
|
1989
|
-
async openAndInitializeWalletServiceWindow({
|
|
1990
|
-
url,
|
|
1991
|
-
windowId,
|
|
1992
|
-
partnerId,
|
|
1993
|
-
enableLogging,
|
|
1994
|
-
onRetry,
|
|
1995
|
-
sdkVersion,
|
|
1996
|
-
enableAutomation
|
|
1997
|
-
}) {
|
|
1998
|
-
if (this.windowControllers.has(windowId)) {
|
|
1999
|
-
throw new Error("Window controller already exists");
|
|
2000
|
-
}
|
|
2001
|
-
const windowController = new WindowController(windowId, url);
|
|
2002
|
-
const {
|
|
2003
|
-
pendingWindowOpenCheck
|
|
2004
|
-
} = await windowController.openWindow(onRetry);
|
|
2005
|
-
windowController.onClose(() => {
|
|
2006
|
-
this.removeWindowController(windowId);
|
|
2007
|
-
});
|
|
2008
|
-
this.windowControllers.set(windowId, windowController);
|
|
2009
|
-
let channel = null;
|
|
2010
|
-
const initializeWindow = () => {
|
|
2011
|
-
return new Promise((resolve, reject) => {
|
|
2012
|
-
windowController.onMessage(async ev => {
|
|
2013
|
-
if (ev.data === AirWalletMessageTypes.SERVICE_STARTED) {
|
|
2014
|
-
try {
|
|
2015
|
-
channel = new MessageChannel();
|
|
2016
|
-
const {
|
|
2017
|
-
payload
|
|
2018
|
-
} = await this.sendWindowInitializationRequest(windowId, {
|
|
2019
|
-
partnerId,
|
|
2020
|
-
enableLogging,
|
|
2021
|
-
sdkVersion,
|
|
2022
|
-
enableAutomation
|
|
2023
|
-
}, channel.port1);
|
|
2024
|
-
if (payload.success === false) {
|
|
2025
|
-
reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
2026
|
-
} else {
|
|
2027
|
-
resolve();
|
|
2028
|
-
}
|
|
2029
|
-
} catch (e) {
|
|
2030
|
-
reject(e);
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
});
|
|
2034
|
-
});
|
|
2035
|
-
};
|
|
2036
|
-
const initializeWindowPromise = initializeWindow();
|
|
2037
|
-
const result = await pendingWindowOpenCheck;
|
|
2038
|
-
if (result === "retry") {
|
|
2039
|
-
// we can ignore previous initialization attempt since a new window was opened
|
|
2040
|
-
await initializeWindow();
|
|
2041
|
-
} else {
|
|
2042
|
-
await initializeWindowPromise;
|
|
2043
|
-
}
|
|
2044
|
-
return {
|
|
2045
|
-
windowController,
|
|
2046
|
-
port: channel.port2
|
|
2047
|
-
};
|
|
2048
|
-
}
|
|
2049
|
-
getWindowController(windowId) {
|
|
2050
|
-
return this.windowControllers.get(windowId);
|
|
2051
|
-
}
|
|
2052
|
-
removeWindowController(windowId) {
|
|
2053
|
-
this.windowControllers.delete(windowId);
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
var WindowService$1 = WindowService.instance;
|
|
2057
1860
|
var _a$1, _AuthMessageService_instance;
|
|
2058
|
-
const ALLOWED_AUTH_MESSAGES = [AirAuthMessageTypes.INITIALIZATION_RESPONSE, AirAuthMessageTypes.LOGIN_RESPONSE, AirAuthMessageTypes.SETUP_WALLET_REQUEST, AirAuthMessageTypes.LOGOUT_RESPONSE, AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE, AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE, AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE, AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST, AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE];
|
|
1861
|
+
const ALLOWED_AUTH_MESSAGES = [AirAuthMessageTypes.INITIALIZATION_RESPONSE, AirAuthMessageTypes.LOGIN_RESPONSE, AirAuthMessageTypes.SETUP_WALLET_REQUEST, AirAuthMessageTypes.SETUP_RECOVERY_REQUEST, AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION, AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION, AirAuthMessageTypes.LOGOUT_RESPONSE, AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE, AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE, AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE, AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST, AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE, AirAuthMessageTypes.START_RECOVERY_RESPONSE];
|
|
2059
1862
|
class AuthMessageService extends MessageServiceBase {
|
|
2060
1863
|
static create() {
|
|
2061
1864
|
if (__classPrivateFieldGet$1(this, _a$1, "f", _AuthMessageService_instance)) throw new Error("AuthMessageService already created");
|
|
@@ -2124,6 +1927,34 @@
|
|
|
2124
1927
|
async sendSetupWalletErrorResponse(error) {
|
|
2125
1928
|
await this.sendMessage(this.createErrorResponseMessage(AirAuthMessageTypes.SETUP_WALLET_RESPONSE, error));
|
|
2126
1929
|
}
|
|
1930
|
+
async initRecoveryCommunication() {
|
|
1931
|
+
await this.sendMessage({
|
|
1932
|
+
type: AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
async resetRecoveryCommunication() {
|
|
1936
|
+
await this.sendMessage({
|
|
1937
|
+
type: AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
async sendSetupRecoverySuccessResponse() {
|
|
1941
|
+
await this.sendMessage({
|
|
1942
|
+
type: AirAuthMessageTypes.SETUP_RECOVERY_RESPONSE,
|
|
1943
|
+
payload: {
|
|
1944
|
+
success: true
|
|
1945
|
+
}
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
async sendSetupRecoveryErrorResponse(error) {
|
|
1949
|
+
await this.sendMessage({
|
|
1950
|
+
type: AirAuthMessageTypes.SETUP_RECOVERY_RESPONSE,
|
|
1951
|
+
payload: {
|
|
1952
|
+
success: false,
|
|
1953
|
+
errorName: error instanceof AirError ? error.name : "UNKNOWN_ERROR",
|
|
1954
|
+
errorMessage: error.message
|
|
1955
|
+
}
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
2127
1958
|
async sendCrossPartnerTokenRequest(targetPartnerUrl) {
|
|
2128
1959
|
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE)));
|
|
2129
1960
|
await this.sendMessage({
|
|
@@ -2141,6 +1972,14 @@
|
|
|
2141
1972
|
});
|
|
2142
1973
|
return response;
|
|
2143
1974
|
}
|
|
1975
|
+
async sendAccountRecoveryRequest(payload) {
|
|
1976
|
+
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirAuthMessageTypes.START_RECOVERY_RESPONSE)));
|
|
1977
|
+
await this.sendMessage({
|
|
1978
|
+
type: AirAuthMessageTypes.START_RECOVERY_REQUEST,
|
|
1979
|
+
payload
|
|
1980
|
+
});
|
|
1981
|
+
return response;
|
|
1982
|
+
}
|
|
2144
1983
|
async sendCredentialSaltRequest() {
|
|
2145
1984
|
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE)));
|
|
2146
1985
|
await this.sendMessage({
|
|
@@ -2153,8 +1992,113 @@
|
|
|
2153
1992
|
_AuthMessageService_instance = {
|
|
2154
1993
|
value: void 0
|
|
2155
1994
|
};
|
|
1995
|
+
class IframeController {
|
|
1996
|
+
constructor(iframeUrl, iframeId, state) {
|
|
1997
|
+
this._iframeElement = null;
|
|
1998
|
+
this.AUTH_IFRAME_Z_INDEX = "9999999";
|
|
1999
|
+
this.DEFAULT_IFRAME_Z_INDEX = "999999";
|
|
2000
|
+
this.state = {
|
|
2001
|
+
...IframeController.defaultState,
|
|
2002
|
+
...state
|
|
2003
|
+
};
|
|
2004
|
+
this.iframeUrl = iframeUrl;
|
|
2005
|
+
this.iframeId = iframeId;
|
|
2006
|
+
}
|
|
2007
|
+
get iframeElement() {
|
|
2008
|
+
return this._iframeElement;
|
|
2009
|
+
}
|
|
2010
|
+
createIframe() {
|
|
2011
|
+
if (this._iframeElement) return this._iframeElement;
|
|
2012
|
+
const iframe = document.createElement("iframe");
|
|
2013
|
+
iframe.id = this.iframeId;
|
|
2014
|
+
iframe.allow = "publickey-credentials-get *; publickey-credentials-create *";
|
|
2015
|
+
iframe.src = this.iframeUrl;
|
|
2016
|
+
iframe.style.position = "fixed";
|
|
2017
|
+
iframe.style.zIndex = this.iframeUrl.includes("auth") ? this.AUTH_IFRAME_Z_INDEX : this.DEFAULT_IFRAME_Z_INDEX;
|
|
2018
|
+
iframe.style.border = "none";
|
|
2019
|
+
iframe.style.margin = "0";
|
|
2020
|
+
iframe.style.padding = "0";
|
|
2021
|
+
iframe.style.display = "none";
|
|
2022
|
+
iframe.style.colorScheme = "auto";
|
|
2023
|
+
document.body.appendChild(iframe);
|
|
2024
|
+
this._iframeElement = iframe;
|
|
2025
|
+
return iframe;
|
|
2026
|
+
}
|
|
2027
|
+
setIframeVisibility(isVisible) {
|
|
2028
|
+
this.state.isVisible = isVisible;
|
|
2029
|
+
}
|
|
2030
|
+
updateIframeState() {
|
|
2031
|
+
if (!this.iframeElement) return;
|
|
2032
|
+
const style = {};
|
|
2033
|
+
style.display = this.state.isVisible ? "block" : "none";
|
|
2034
|
+
style.width = "100%";
|
|
2035
|
+
style.height = "100%";
|
|
2036
|
+
style.top = "0px";
|
|
2037
|
+
style.right = "0px";
|
|
2038
|
+
style.left = "0px";
|
|
2039
|
+
style.bottom = "0px";
|
|
2040
|
+
Object.assign(this.iframeElement.style, style);
|
|
2041
|
+
}
|
|
2042
|
+
destroy() {
|
|
2043
|
+
if (this.iframeElement) {
|
|
2044
|
+
this.iframeElement.remove();
|
|
2045
|
+
this._iframeElement = null;
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
postMessage(message) {
|
|
2049
|
+
if (!this.iframeElement) return;
|
|
2050
|
+
const {
|
|
2051
|
+
origin
|
|
2052
|
+
} = new URL(this.iframeElement.src);
|
|
2053
|
+
this.iframeElement.contentWindow.postMessage(message, origin);
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
IframeController.defaultState = {
|
|
2057
|
+
isVisible: false
|
|
2058
|
+
};
|
|
2059
|
+
const ALLOWED_RECOVERY_MESSAGES = Object.values(AirRecoveryMessageTypes);
|
|
2060
|
+
class RecoveryMessageService extends MessageServiceBase {
|
|
2061
|
+
static create() {
|
|
2062
|
+
if (!RecoveryMessageService._instance) {
|
|
2063
|
+
RecoveryMessageService._instance = new RecoveryMessageService("Recovery Service", ALLOWED_RECOVERY_MESSAGES);
|
|
2064
|
+
}
|
|
2065
|
+
return RecoveryMessageService._instance;
|
|
2066
|
+
}
|
|
2067
|
+
async sendInitializationRequest(payload) {
|
|
2068
|
+
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirRecoveryMessageTypes.INITIALIZATION_RESPONSE)));
|
|
2069
|
+
await this.sendMessage({
|
|
2070
|
+
type: AirRecoveryMessageTypes.INITIALIZATION_REQUEST,
|
|
2071
|
+
payload
|
|
2072
|
+
});
|
|
2073
|
+
return response;
|
|
2074
|
+
}
|
|
2075
|
+
async initAuthCommunication() {
|
|
2076
|
+
await this.sendMessage({
|
|
2077
|
+
type: AirRecoveryMessageTypes.INIT_AUTH_COMMUNICATION
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
async onInitialized() {
|
|
2081
|
+
return firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirRecoveryMessageTypes.RECOVERY_INITIALIZED)));
|
|
2082
|
+
}
|
|
2083
|
+
async logout() {
|
|
2084
|
+
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirRecoveryMessageTypes.LOGOUT_RESPONSE)));
|
|
2085
|
+
await this.sendMessage({
|
|
2086
|
+
type: AirRecoveryMessageTypes.LOGOUT_REQUEST
|
|
2087
|
+
});
|
|
2088
|
+
return response;
|
|
2089
|
+
}
|
|
2090
|
+
async open(element) {
|
|
2091
|
+
await this._open({
|
|
2092
|
+
window: element.contentWindow,
|
|
2093
|
+
origin: new URL(element.src).origin
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
async close() {
|
|
2097
|
+
await super.close();
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2156
2100
|
var _a, _WalletMessageService_instance;
|
|
2157
|
-
const ALLOWED_WALLET_MESSAGES = [AirWalletMessageTypes.INITIALIZATION_RESPONSE, AirWalletMessageTypes.WALLET_INITIALIZED, AirWalletMessageTypes.WALLET_LOGIN_RESPONSE, AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_RESPONSE, AirWalletMessageTypes.CLAIM_ID_RESPONSE, AirWalletMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE, AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE, AirWalletMessageTypes.WALLET_INITIALIZED, AirWalletMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST, AirWalletMessageTypes.LOGOUT_RESPONSE,
|
|
2101
|
+
const ALLOWED_WALLET_MESSAGES = [AirWalletMessageTypes.INITIALIZATION_RESPONSE, AirWalletMessageTypes.WALLET_INITIALIZED, AirWalletMessageTypes.WALLET_LOGIN_RESPONSE, AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_RESPONSE, AirWalletMessageTypes.SHOW_SWAP_UI_RESPONSE, AirWalletMessageTypes.CLAIM_ID_RESPONSE, AirWalletMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE, AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE, AirWalletMessageTypes.WALLET_INITIALIZED, AirWalletMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST, AirWalletMessageTypes.LOGOUT_RESPONSE, AirWindowMessageTypes.OPEN_WINDOW_REQUEST, AirWindowMessageTypes.OPEN_WINDOW_RETRY_RESPONSE];
|
|
2158
2102
|
class WalletMessageService extends MessageServiceBase {
|
|
2159
2103
|
static create() {
|
|
2160
2104
|
if (__classPrivateFieldGet$1(this, _a, "f", _WalletMessageService_instance)) throw new Error("WalletMessageService already created");
|
|
@@ -2225,7 +2169,7 @@
|
|
|
2225
2169
|
}
|
|
2226
2170
|
async sendOpenWindowSuccessResponse(windowId, port) {
|
|
2227
2171
|
await this.sendMessage({
|
|
2228
|
-
type:
|
|
2172
|
+
type: AirWindowMessageTypes.OPEN_WINDOW_RESPONSE,
|
|
2229
2173
|
payload: {
|
|
2230
2174
|
success: true,
|
|
2231
2175
|
windowId
|
|
@@ -2233,7 +2177,7 @@
|
|
|
2233
2177
|
}, [port]);
|
|
2234
2178
|
}
|
|
2235
2179
|
async sendOpenWindowErrorResponse(windowId, error) {
|
|
2236
|
-
const errorResponse = this.createErrorResponseMessage(
|
|
2180
|
+
const errorResponse = this.createErrorResponseMessage(AirWindowMessageTypes.OPEN_WINDOW_RESPONSE, error);
|
|
2237
2181
|
await this.sendMessage({
|
|
2238
2182
|
...errorResponse,
|
|
2239
2183
|
payload: {
|
|
@@ -2243,9 +2187,9 @@
|
|
|
2243
2187
|
});
|
|
2244
2188
|
}
|
|
2245
2189
|
async sendOpenWindowRetryRequest(windowId) {
|
|
2246
|
-
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type ===
|
|
2190
|
+
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirWindowMessageTypes.OPEN_WINDOW_RETRY_RESPONSE), filter(msg => msg.payload.windowId === windowId)));
|
|
2247
2191
|
await this.sendMessage({
|
|
2248
|
-
type:
|
|
2192
|
+
type: AirWindowMessageTypes.OPEN_WINDOW_RETRY_REQUEST,
|
|
2249
2193
|
payload: {
|
|
2250
2194
|
windowId
|
|
2251
2195
|
}
|
|
@@ -2254,52 +2198,237 @@
|
|
|
2254
2198
|
}
|
|
2255
2199
|
async sendWindowClosed(windowId) {
|
|
2256
2200
|
await this.sendMessage({
|
|
2257
|
-
type:
|
|
2201
|
+
type: AirWindowMessageTypes.WINDOW_CLOSED,
|
|
2258
2202
|
payload: {
|
|
2259
2203
|
windowId
|
|
2260
2204
|
}
|
|
2261
|
-
});
|
|
2205
|
+
});
|
|
2206
|
+
}
|
|
2207
|
+
async sendClaimIdRequest(payload) {
|
|
2208
|
+
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirWalletMessageTypes.CLAIM_ID_RESPONSE)));
|
|
2209
|
+
await this.sendMessage({
|
|
2210
|
+
type: AirWalletMessageTypes.CLAIM_ID_REQUEST,
|
|
2211
|
+
payload
|
|
2212
|
+
});
|
|
2213
|
+
return response;
|
|
2214
|
+
}
|
|
2215
|
+
async sendShowSwapUIRequest() {
|
|
2216
|
+
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirWalletMessageTypes.SHOW_SWAP_UI_RESPONSE)));
|
|
2217
|
+
await this.sendMessage({
|
|
2218
|
+
type: AirWalletMessageTypes.SHOW_SWAP_UI_REQUEST
|
|
2219
|
+
});
|
|
2220
|
+
return response;
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
_a = WalletMessageService;
|
|
2224
|
+
_WalletMessageService_instance = {
|
|
2225
|
+
value: void 0
|
|
2226
|
+
};
|
|
2227
|
+
class WindowController {
|
|
2228
|
+
get messages$() {
|
|
2229
|
+
return this._messages$.asObservable();
|
|
2230
|
+
}
|
|
2231
|
+
constructor(windowId, windowUrl) {
|
|
2232
|
+
this._windowInstance = null;
|
|
2233
|
+
this._messageHandler = null;
|
|
2234
|
+
this._messages$ = new Subject();
|
|
2235
|
+
this.windowId = windowId;
|
|
2236
|
+
this.windowUrl = windowUrl;
|
|
2237
|
+
this.windowOrigin = new URL(windowUrl).origin;
|
|
2238
|
+
this._messageHandler = ev => {
|
|
2239
|
+
if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin || !ev.data || !(ev.data instanceof Object)) {
|
|
2240
|
+
return;
|
|
2241
|
+
}
|
|
2242
|
+
this._messages$.next(ev);
|
|
2243
|
+
};
|
|
2244
|
+
window.addEventListener("message", this._messageHandler);
|
|
2245
|
+
}
|
|
2246
|
+
get windowInstance() {
|
|
2247
|
+
return this._windowInstance;
|
|
2248
|
+
}
|
|
2249
|
+
async openWindow(onRetry) {
|
|
2250
|
+
let windowInstance = this.tryOpenWindow();
|
|
2251
|
+
if (!windowInstance) {
|
|
2252
|
+
await onRetry();
|
|
2253
|
+
windowInstance = this.tryOpenWindow();
|
|
2254
|
+
if (!windowInstance) {
|
|
2255
|
+
throw new AirError(WindowErrorName.WINDOW_BLOCKED);
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
const pendingWindowOpenCheck = new Promise((resolve, reject) => {
|
|
2259
|
+
setTimeout(() => {
|
|
2260
|
+
if (this.isWindowOpen(windowInstance)) {
|
|
2261
|
+
// only now are we scheduling the close event check since we're sure the window is open
|
|
2262
|
+
this.scheduleWindowClosedChecks(windowInstance);
|
|
2263
|
+
resolve("opened");
|
|
2264
|
+
} else {
|
|
2265
|
+
onRetry().then(() => {
|
|
2266
|
+
windowInstance = this.tryOpenWindow();
|
|
2267
|
+
if (windowInstance) {
|
|
2268
|
+
this._windowInstance = windowInstance;
|
|
2269
|
+
windowInstance.focus();
|
|
2270
|
+
this.scheduleWindowClosedChecks(windowInstance);
|
|
2271
|
+
resolve("retry");
|
|
2272
|
+
} else {
|
|
2273
|
+
reject(new AirError(WindowErrorName.WINDOW_BLOCKED));
|
|
2274
|
+
}
|
|
2275
|
+
}).catch(reject);
|
|
2276
|
+
}
|
|
2277
|
+
}, 1000);
|
|
2278
|
+
});
|
|
2279
|
+
this._windowInstance = windowInstance;
|
|
2280
|
+
windowInstance.focus();
|
|
2281
|
+
return {
|
|
2282
|
+
pendingWindowOpenCheck
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
postMessage(message, transfer) {
|
|
2286
|
+
if (!this._windowInstance) return;
|
|
2287
|
+
this._windowInstance.postMessage(message, this.windowOrigin, transfer);
|
|
2288
|
+
}
|
|
2289
|
+
onMessage(callback) {
|
|
2290
|
+
const listener = ev => {
|
|
2291
|
+
if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin) return;
|
|
2292
|
+
callback(ev);
|
|
2293
|
+
};
|
|
2294
|
+
window.addEventListener("message", listener);
|
|
2295
|
+
const close = () => window.removeEventListener("message", listener);
|
|
2296
|
+
this.onClose(close);
|
|
2297
|
+
return {
|
|
2298
|
+
close
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
cleanup() {
|
|
2302
|
+
if (this._windowInstance && !this._windowInstance.closed) {
|
|
2303
|
+
this._windowInstance.close();
|
|
2304
|
+
}
|
|
2305
|
+
this._windowInstance = null;
|
|
2306
|
+
if (this._messageHandler) {
|
|
2307
|
+
window.removeEventListener("message", this._messageHandler);
|
|
2308
|
+
this._messageHandler = null;
|
|
2309
|
+
}
|
|
2310
|
+
if (this._messages$ && !this._messages$.closed) {
|
|
2311
|
+
this._messages$.complete();
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
onClose(callback) {
|
|
2315
|
+
return this._messages$.subscribe({
|
|
2316
|
+
complete: callback
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2319
|
+
isWindowOpen(windowInstance) {
|
|
2320
|
+
return !(!windowInstance || windowInstance.closed || typeof windowInstance.closed == "undefined");
|
|
2321
|
+
}
|
|
2322
|
+
tryOpenWindow() {
|
|
2323
|
+
const windowInstance = window.open(this.windowUrl, this.windowId, getWindowFeatures(425, 680));
|
|
2324
|
+
if (this.isWindowOpen(windowInstance)) {
|
|
2325
|
+
return windowInstance;
|
|
2326
|
+
}
|
|
2327
|
+
return null;
|
|
2328
|
+
}
|
|
2329
|
+
scheduleWindowClosedChecks(windowInstance) {
|
|
2330
|
+
const checkWindow = setInterval(() => {
|
|
2331
|
+
if (!windowInstance || windowInstance.closed) {
|
|
2332
|
+
clearInterval(checkWindow);
|
|
2333
|
+
if (windowInstance === this._windowInstance) {
|
|
2334
|
+
this.cleanup();
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
}, 500);
|
|
2262
2338
|
}
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2339
|
+
}
|
|
2340
|
+
class WindowService {
|
|
2341
|
+
constructor() {
|
|
2342
|
+
this.windowControllers = new Map();
|
|
2343
|
+
}
|
|
2344
|
+
static get instance() {
|
|
2345
|
+
return this._instance || (this._instance = new this());
|
|
2346
|
+
}
|
|
2347
|
+
async sendWindowInitializationRequest(windowId, payload, port) {
|
|
2348
|
+
const windowController = this.windowControllers.get(windowId);
|
|
2349
|
+
if (!windowController) {
|
|
2350
|
+
throw new Error("Window controller not found");
|
|
2351
|
+
}
|
|
2352
|
+
const windowInstance = windowController.windowInstance;
|
|
2353
|
+
if (!windowInstance) {
|
|
2354
|
+
throw new Error("Window instance not found");
|
|
2355
|
+
}
|
|
2356
|
+
const response = firstValueFrom(windowController.messages$.pipe(filter(event => event.data.type === AirWalletMessageTypes.INITIALIZATION_RESPONSE)));
|
|
2357
|
+
windowController.postMessage({
|
|
2358
|
+
type: AirWalletMessageTypes.INITIALIZATION_REQUEST,
|
|
2267
2359
|
payload
|
|
2360
|
+
}, [port]);
|
|
2361
|
+
return (await response).data;
|
|
2362
|
+
}
|
|
2363
|
+
async openAndInitializeWalletServiceWindow({
|
|
2364
|
+
url,
|
|
2365
|
+
windowId,
|
|
2366
|
+
partnerId,
|
|
2367
|
+
enableLogging,
|
|
2368
|
+
onRetry,
|
|
2369
|
+
sdkVersion,
|
|
2370
|
+
enableAutomation
|
|
2371
|
+
}) {
|
|
2372
|
+
if (this.windowControllers.has(windowId)) {
|
|
2373
|
+
throw new Error("Window controller already exists");
|
|
2374
|
+
}
|
|
2375
|
+
const windowController = new WindowController(windowId, url);
|
|
2376
|
+
const {
|
|
2377
|
+
pendingWindowOpenCheck
|
|
2378
|
+
} = await windowController.openWindow(onRetry);
|
|
2379
|
+
windowController.onClose(() => {
|
|
2380
|
+
this.removeWindowController(windowId);
|
|
2268
2381
|
});
|
|
2269
|
-
|
|
2382
|
+
this.windowControllers.set(windowId, windowController);
|
|
2383
|
+
let channel = null;
|
|
2384
|
+
const initializeWindow = () => {
|
|
2385
|
+
return new Promise((resolve, reject) => {
|
|
2386
|
+
windowController.onMessage(async ev => {
|
|
2387
|
+
if (ev.data === AirWalletMessageTypes.SERVICE_STARTED) {
|
|
2388
|
+
try {
|
|
2389
|
+
channel = new MessageChannel();
|
|
2390
|
+
const {
|
|
2391
|
+
payload
|
|
2392
|
+
} = await this.sendWindowInitializationRequest(windowId, {
|
|
2393
|
+
partnerId,
|
|
2394
|
+
enableLogging,
|
|
2395
|
+
sdkVersion,
|
|
2396
|
+
enableAutomation
|
|
2397
|
+
}, channel.port1);
|
|
2398
|
+
if (payload.success === false) {
|
|
2399
|
+
reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
2400
|
+
} else {
|
|
2401
|
+
resolve();
|
|
2402
|
+
}
|
|
2403
|
+
} catch (e) {
|
|
2404
|
+
reject(e);
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
});
|
|
2408
|
+
});
|
|
2409
|
+
};
|
|
2410
|
+
const initializeWindowPromise = initializeWindow();
|
|
2411
|
+
const result = await pendingWindowOpenCheck;
|
|
2412
|
+
if (result === "retry") {
|
|
2413
|
+
// we can ignore previous initialization attempt since a new window was opened
|
|
2414
|
+
await initializeWindow();
|
|
2415
|
+
} else {
|
|
2416
|
+
await initializeWindowPromise;
|
|
2417
|
+
}
|
|
2418
|
+
return {
|
|
2419
|
+
windowController,
|
|
2420
|
+
port: channel.port2
|
|
2421
|
+
};
|
|
2270
2422
|
}
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
_WalletMessageService_instance = {
|
|
2274
|
-
value: void 0
|
|
2275
|
-
};
|
|
2276
|
-
const getLevelName = levelNum => {
|
|
2277
|
-
const levelNames = Object.keys(log$1.levels);
|
|
2278
|
-
if (levelNum >= 0 && levelNum < levelNames.length) {
|
|
2279
|
-
return levelNames[levelNum];
|
|
2423
|
+
getWindowController(windowId) {
|
|
2424
|
+
return this.windowControllers.get(windowId);
|
|
2280
2425
|
}
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
const configureLogLevel = (environment, enableLogging) => {
|
|
2284
|
-
let level = log$1.levels.ERROR;
|
|
2285
|
-
if (environment === "development") {
|
|
2286
|
-
level = enableLogging ? log$1.levels.TRACE : log$1.levels.INFO;
|
|
2287
|
-
} else if (environment === "staging") {
|
|
2288
|
-
level = enableLogging ? log$1.levels.DEBUG : log$1.levels.INFO;
|
|
2289
|
-
} else if (environment === "uat") {
|
|
2290
|
-
level = enableLogging ? log$1.levels.INFO : log$1.levels.WARN;
|
|
2291
|
-
} else if (environment === "production") {
|
|
2292
|
-
// Be cautious with enabling more than WARN in prod
|
|
2293
|
-
level = enableLogging ? log$1.levels.WARN : log$1.levels.ERROR;
|
|
2426
|
+
removeWindowController(windowId) {
|
|
2427
|
+
this.windowControllers.delete(windowId);
|
|
2294
2428
|
}
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
var version$2 = "1.3.0";
|
|
2299
|
-
var airkitPackage = {
|
|
2300
|
-
version: version$2
|
|
2301
|
-
};
|
|
2302
|
-
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;
|
|
2429
|
+
}
|
|
2430
|
+
var WindowService$1 = WindowService.instance;
|
|
2431
|
+
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;
|
|
2303
2432
|
const airKitVersion = airkitPackage.version;
|
|
2304
2433
|
class AirService {
|
|
2305
2434
|
constructor({
|
|
@@ -2320,12 +2449,17 @@
|
|
|
2320
2449
|
_AirService_walletInitialization.set(this, void 0);
|
|
2321
2450
|
_AirService_walletLoggedInResult.set(this, void 0);
|
|
2322
2451
|
_AirService_airWalletProvider.set(this, void 0);
|
|
2452
|
+
_AirService_recoveryInitialization.set(this, void 0);
|
|
2453
|
+
_AirService_recoveryMessagingService.set(this, void 0);
|
|
2454
|
+
_AirService_recoveryIframeController.set(this, void 0);
|
|
2323
2455
|
__classPrivateFieldSet(this, _AirService_partnerId, partnerId);
|
|
2324
2456
|
__classPrivateFieldSet(this, _AirService_authMessagingService, AuthMessageService.create());
|
|
2325
2457
|
__classPrivateFieldSet(this, _AirService_walletMessagingService, WalletMessageService.create());
|
|
2458
|
+
__classPrivateFieldSet(this, _AirService_recoveryMessagingService, RecoveryMessageService.create());
|
|
2326
2459
|
__classPrivateFieldSet(this, _AirService_airWalletProvider, new AirWalletProvider({
|
|
2327
|
-
|
|
2328
|
-
ensureWallet: __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_ensureWallet).bind(this)
|
|
2460
|
+
isWalletInitialized: () => this.isWalletInitialized,
|
|
2461
|
+
ensureWallet: __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_ensureWallet).bind(this),
|
|
2462
|
+
getLoginResult: () => __classPrivateFieldGet$1(this, _AirService_loginResult, "f")
|
|
2329
2463
|
}));
|
|
2330
2464
|
// this.#modalZIndex = modalZIndex ?? 99999;
|
|
2331
2465
|
}
|
|
@@ -2338,6 +2472,9 @@
|
|
|
2338
2472
|
get isLoggedIn() {
|
|
2339
2473
|
return !!__classPrivateFieldGet$1(this, _AirService_loginResult, "f");
|
|
2340
2474
|
}
|
|
2475
|
+
get loginResult() {
|
|
2476
|
+
return __classPrivateFieldGet$1(this, _AirService_loginResult, "f");
|
|
2477
|
+
}
|
|
2341
2478
|
get isWalletInitialized() {
|
|
2342
2479
|
return !!__classPrivateFieldGet$1(this, _AirService_walletLoggedInResult, "f");
|
|
2343
2480
|
}
|
|
@@ -2393,6 +2530,17 @@
|
|
|
2393
2530
|
}
|
|
2394
2531
|
break;
|
|
2395
2532
|
}
|
|
2533
|
+
case AirAuthMessageTypes.SETUP_RECOVERY_REQUEST:
|
|
2534
|
+
{
|
|
2535
|
+
try {
|
|
2536
|
+
await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_ensureRecovery).call(this);
|
|
2537
|
+
await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendSetupRecoverySuccessResponse();
|
|
2538
|
+
} catch (err) {
|
|
2539
|
+
const error = ensureError(err);
|
|
2540
|
+
await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendSetupRecoveryErrorResponse(error);
|
|
2541
|
+
}
|
|
2542
|
+
break;
|
|
2543
|
+
}
|
|
2396
2544
|
}
|
|
2397
2545
|
});
|
|
2398
2546
|
const result = await new Promise((resolve, reject) => {
|
|
@@ -2535,6 +2683,16 @@
|
|
|
2535
2683
|
}
|
|
2536
2684
|
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2537
2685
|
}
|
|
2686
|
+
async showSwapUI() {
|
|
2687
|
+
await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
2688
|
+
const result = await __classPrivateFieldGet$1(this, _AirService_walletMessagingService, "f").sendShowSwapUIRequest();
|
|
2689
|
+
if (result.payload.success === false) {
|
|
2690
|
+
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2691
|
+
}
|
|
2692
|
+
return {
|
|
2693
|
+
txHash: result.payload.txHash
|
|
2694
|
+
};
|
|
2695
|
+
}
|
|
2538
2696
|
async getUserInfo() {
|
|
2539
2697
|
if (!this.isLoggedIn) throw new Error("User not logged in");
|
|
2540
2698
|
const info = await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendPartnerUserInfoRequest();
|
|
@@ -2564,6 +2722,16 @@
|
|
|
2564
2722
|
urlWithToken: result.payload.urlWithToken
|
|
2565
2723
|
};
|
|
2566
2724
|
}
|
|
2725
|
+
async startRecovery(payload) {
|
|
2726
|
+
try {
|
|
2727
|
+
const result = await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendAccountRecoveryRequest(payload);
|
|
2728
|
+
if (result.payload.success === false) {
|
|
2729
|
+
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2730
|
+
}
|
|
2731
|
+
} catch (error) {
|
|
2732
|
+
throw AirServiceError.from(error);
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2567
2735
|
async getAccessToken() {
|
|
2568
2736
|
if (!__classPrivateFieldGet$1(this, _AirService_isAuthInitialized, "f")) throw new Error("Service is not initialized");
|
|
2569
2737
|
if (!this.isLoggedIn) throw new Error("No active session to get partner access token");
|
|
@@ -2590,6 +2758,7 @@
|
|
|
2590
2758
|
async cleanUp() {
|
|
2591
2759
|
await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
|
|
2592
2760
|
await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpAuth).call(this);
|
|
2761
|
+
await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
|
|
2593
2762
|
this.clearEventListeners();
|
|
2594
2763
|
}
|
|
2595
2764
|
on(listener) {
|
|
@@ -2602,7 +2771,7 @@
|
|
|
2602
2771
|
__classPrivateFieldSet(this, _AirService_airAuthListener, []);
|
|
2603
2772
|
}
|
|
2604
2773
|
}
|
|
2605
|
-
_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) {
|
|
2774
|
+
_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) {
|
|
2606
2775
|
if (!this.isInitialized) throw new Error("Service not initialized");
|
|
2607
2776
|
if (!this.isLoggedIn && !option?.skipWalletLogin) throw new Error("User not logged in");
|
|
2608
2777
|
if (!__classPrivateFieldGet$1(this, _AirService_walletInitialization, "f")) __classPrivateFieldSet(this, _AirService_walletInitialization, __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_initializeWallet).call(this, option));
|
|
@@ -2694,7 +2863,7 @@
|
|
|
2694
2863
|
}
|
|
2695
2864
|
break;
|
|
2696
2865
|
}
|
|
2697
|
-
case
|
|
2866
|
+
case AirWindowMessageTypes.OPEN_WINDOW_REQUEST:
|
|
2698
2867
|
{
|
|
2699
2868
|
try {
|
|
2700
2869
|
const onRetry = async () => {
|
|
@@ -2798,9 +2967,96 @@
|
|
|
2798
2967
|
await __classPrivateFieldGet$1(this, _AirService_walletMessagingService, "f").close();
|
|
2799
2968
|
__classPrivateFieldSet(this, _AirService_walletLoggedInResult, undefined);
|
|
2800
2969
|
__classPrivateFieldSet(this, _AirService_walletInitialization, undefined);
|
|
2970
|
+
}, _AirService_ensureRecovery = async function _AirService_ensureRecovery() {
|
|
2971
|
+
if (!this.isInitialized) throw new Error("Service not initialized");
|
|
2972
|
+
if (!__classPrivateFieldGet$1(this, _AirService_recoveryInitialization, "f")) {
|
|
2973
|
+
__classPrivateFieldSet(this, _AirService_recoveryInitialization, __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_initializeRecovery).call(this));
|
|
2974
|
+
}
|
|
2975
|
+
try {
|
|
2976
|
+
await __classPrivateFieldGet$1(this, _AirService_recoveryInitialization, "f");
|
|
2977
|
+
} catch (error) {
|
|
2978
|
+
__classPrivateFieldSet(this, _AirService_recoveryInitialization, null);
|
|
2979
|
+
log$1.error("Error initializing recovery", error);
|
|
2980
|
+
throw error;
|
|
2981
|
+
}
|
|
2982
|
+
}, _AirService_initializeRecovery = async function _AirService_initializeRecovery() {
|
|
2983
|
+
if (__classPrivateFieldGet$1(this, _AirService_recoveryInitialization, "f")) throw new Error("Already initializing");
|
|
2984
|
+
const {
|
|
2985
|
+
recoveryUrl
|
|
2986
|
+
} = AIR_URLS[__classPrivateFieldGet$1(this, _AirService_buildEnv, "f")];
|
|
2987
|
+
const recoveryIframeOrigin = new URL(recoveryUrl).origin;
|
|
2988
|
+
try {
|
|
2989
|
+
const recoveryInitRequestPromise = new Promise((resolve, reject) => {
|
|
2990
|
+
const handleRecoveryMessage = async ev => {
|
|
2991
|
+
if (ev.origin !== recoveryIframeOrigin) return;
|
|
2992
|
+
if (ev.data === AirRecoveryMessageTypes.SERVICE_STARTED) {
|
|
2993
|
+
window.removeEventListener("message", handleRecoveryMessage);
|
|
2994
|
+
const {
|
|
2995
|
+
payload
|
|
2996
|
+
} = await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").sendInitializationRequest({
|
|
2997
|
+
partnerId: __classPrivateFieldGet$1(this, _AirService_partnerId, "f"),
|
|
2998
|
+
enableLogging: __classPrivateFieldGet$1(this, _AirService_enableLogging, "f"),
|
|
2999
|
+
sdkVersion: airKitVersion,
|
|
3000
|
+
enableAutomation: this.shouldEnableAutomation()
|
|
3001
|
+
});
|
|
3002
|
+
if (payload.success === true) {
|
|
3003
|
+
resolve();
|
|
3004
|
+
} else {
|
|
3005
|
+
reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
};
|
|
3009
|
+
window.addEventListener("message", handleRecoveryMessage);
|
|
3010
|
+
});
|
|
3011
|
+
__classPrivateFieldSet(this, _AirService_recoveryIframeController, new IframeController(recoveryUrl, `air-recovery-${randomId()}`), "f");
|
|
3012
|
+
__classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f").createIframe();
|
|
3013
|
+
log$1.info(recoveryUrl, "url loaded");
|
|
3014
|
+
await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").open(__classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f").iframeElement);
|
|
3015
|
+
__classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_subscribeToRecoveryEvents).call(this);
|
|
3016
|
+
const recoveryInitPromise = __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").onInitialized();
|
|
3017
|
+
await recoveryInitRequestPromise;
|
|
3018
|
+
await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").initRecoveryCommunication();
|
|
3019
|
+
await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").initAuthCommunication();
|
|
3020
|
+
const recoveryInitResult = await recoveryInitPromise;
|
|
3021
|
+
if (recoveryInitResult.payload.success !== true) {
|
|
3022
|
+
throw new AirServiceError(recoveryInitResult.payload.errorName, recoveryInitResult.payload.errorMessage);
|
|
3023
|
+
}
|
|
3024
|
+
} catch (error) {
|
|
3025
|
+
log$1.error("Error initializing recovery", error);
|
|
3026
|
+
await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
|
|
3027
|
+
throw error;
|
|
3028
|
+
}
|
|
3029
|
+
}, _AirService_subscribeToRecoveryEvents = function _AirService_subscribeToRecoveryEvents() {
|
|
3030
|
+
__classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").messages$.subscribe(async message => {
|
|
3031
|
+
switch (message.type) {
|
|
3032
|
+
case AirRecoveryMessageTypes.RECOVERY_IFRAME_VISIBILITY_REQUEST:
|
|
3033
|
+
{
|
|
3034
|
+
const recoveryIframeController = __classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f");
|
|
3035
|
+
recoveryIframeController.setIframeVisibility(message.payload.visible);
|
|
3036
|
+
recoveryIframeController.updateIframeState();
|
|
3037
|
+
break;
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
});
|
|
3041
|
+
}, _AirService_cleanUpRecovery = async function _AirService_cleanUpRecovery() {
|
|
3042
|
+
if (!__classPrivateFieldGet$1(this, _AirService_isAuthInitialized, "f")) return;
|
|
3043
|
+
// Logout recovery and destroy the recovery iframe
|
|
3044
|
+
const recoveryIframeElement = __classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f")?.iframeElement;
|
|
3045
|
+
if (isElement(recoveryIframeElement) && window.document.body.contains(recoveryIframeElement)) {
|
|
3046
|
+
await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").logout();
|
|
3047
|
+
__classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f").destroy();
|
|
3048
|
+
__classPrivateFieldSet(this, _AirService_recoveryIframeController, undefined);
|
|
3049
|
+
}
|
|
3050
|
+
const authIframeElement = __classPrivateFieldGet$1(this, _AirService_authIframeController, "f")?.iframeElement;
|
|
3051
|
+
if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
|
|
3052
|
+
await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").resetRecoveryCommunication();
|
|
3053
|
+
}
|
|
3054
|
+
// Close the message service
|
|
3055
|
+
await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").close();
|
|
3056
|
+
__classPrivateFieldSet(this, _AirService_recoveryInitialization, undefined);
|
|
2801
3057
|
};
|
|
2802
3058
|
|
|
2803
|
-
const version$1 = '2.
|
|
3059
|
+
const version$1 = '2.31.0';
|
|
2804
3060
|
|
|
2805
3061
|
let errorConfig = {
|
|
2806
3062
|
getDocsUrl: ({
|
|
@@ -3265,37 +3521,6 @@
|
|
|
3265
3521
|
}
|
|
3266
3522
|
}
|
|
3267
3523
|
|
|
3268
|
-
/**
|
|
3269
|
-
* Internal assertion helpers.
|
|
3270
|
-
* @module
|
|
3271
|
-
*/
|
|
3272
|
-
/** Asserts something is positive integer. */
|
|
3273
|
-
function anumber(n) {
|
|
3274
|
-
if (!Number.isSafeInteger(n) || n < 0) throw new Error('positive integer expected, got ' + n);
|
|
3275
|
-
}
|
|
3276
|
-
/** Is number an Uint8Array? Copied from utils for perf. */
|
|
3277
|
-
function isBytes(a) {
|
|
3278
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array';
|
|
3279
|
-
}
|
|
3280
|
-
/** Asserts something is Uint8Array. */
|
|
3281
|
-
function abytes(b, ...lengths) {
|
|
3282
|
-
if (!isBytes(b)) throw new Error('Uint8Array expected');
|
|
3283
|
-
if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
|
|
3284
|
-
}
|
|
3285
|
-
/** Asserts a hash instance has not been destroyed / finished */
|
|
3286
|
-
function aexists(instance, checkFinished = true) {
|
|
3287
|
-
if (instance.destroyed) throw new Error('Hash instance has been destroyed');
|
|
3288
|
-
if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');
|
|
3289
|
-
}
|
|
3290
|
-
/** Asserts output is properly-sized byte array */
|
|
3291
|
-
function aoutput(out, instance) {
|
|
3292
|
-
abytes(out);
|
|
3293
|
-
const min = instance.outputLen;
|
|
3294
|
-
if (out.length < min) {
|
|
3295
|
-
throw new Error('digestInto() expects output buffer of length at least ' + min);
|
|
3296
|
-
}
|
|
3297
|
-
}
|
|
3298
|
-
|
|
3299
3524
|
/**
|
|
3300
3525
|
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
3301
3526
|
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
@@ -3314,9 +3539,10 @@
|
|
|
3314
3539
|
};
|
|
3315
3540
|
}
|
|
3316
3541
|
function split(lst, le = false) {
|
|
3317
|
-
|
|
3318
|
-
let
|
|
3319
|
-
|
|
3542
|
+
const len = lst.length;
|
|
3543
|
+
let Ah = new Uint32Array(len);
|
|
3544
|
+
let Al = new Uint32Array(len);
|
|
3545
|
+
for (let i = 0; i < len; i++) {
|
|
3320
3546
|
const {
|
|
3321
3547
|
h,
|
|
3322
3548
|
l
|
|
@@ -3343,12 +3569,45 @@
|
|
|
3343
3569
|
// from `crypto` to `cryptoNode`, which imports native module.
|
|
3344
3570
|
// Makes the utils un-importable in browsers without a bundler.
|
|
3345
3571
|
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
|
|
3572
|
+
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
3573
|
+
function isBytes(a) {
|
|
3574
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array';
|
|
3575
|
+
}
|
|
3576
|
+
/** Asserts something is positive integer. */
|
|
3577
|
+
function anumber(n) {
|
|
3578
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new Error('positive integer expected, got ' + n);
|
|
3579
|
+
}
|
|
3580
|
+
/** Asserts something is Uint8Array. */
|
|
3581
|
+
function abytes(b, ...lengths) {
|
|
3582
|
+
if (!isBytes(b)) throw new Error('Uint8Array expected');
|
|
3583
|
+
if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
|
|
3584
|
+
}
|
|
3585
|
+
/** Asserts a hash instance has not been destroyed / finished */
|
|
3586
|
+
function aexists(instance, checkFinished = true) {
|
|
3587
|
+
if (instance.destroyed) throw new Error('Hash instance has been destroyed');
|
|
3588
|
+
if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');
|
|
3589
|
+
}
|
|
3590
|
+
/** Asserts output is properly-sized byte array */
|
|
3591
|
+
function aoutput(out, instance) {
|
|
3592
|
+
abytes(out);
|
|
3593
|
+
const min = instance.outputLen;
|
|
3594
|
+
if (out.length < min) {
|
|
3595
|
+
throw new Error('digestInto() expects output buffer of length at least ' + min);
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
/** Cast u8 / u16 / u32 to u32. */
|
|
3346
3599
|
function u32(arr) {
|
|
3347
3600
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
3348
3601
|
}
|
|
3602
|
+
/** Zeroize a byte array. Warning: JS provides no guarantees. */
|
|
3603
|
+
function clean(...arrays) {
|
|
3604
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
3605
|
+
arrays[i].fill(0);
|
|
3606
|
+
}
|
|
3607
|
+
}
|
|
3349
3608
|
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
|
3350
3609
|
const isLE = /* @__PURE__ */(() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
|
|
3351
|
-
|
|
3610
|
+
/** The byte swap operation for uint32 */
|
|
3352
3611
|
function byteSwap(word) {
|
|
3353
3612
|
return word << 24 & 0xff000000 | word << 8 & 0xff0000 | word >>> 8 & 0xff00 | word >>> 24 & 0xff;
|
|
3354
3613
|
}
|
|
@@ -3357,13 +3616,15 @@
|
|
|
3357
3616
|
for (let i = 0; i < arr.length; i++) {
|
|
3358
3617
|
arr[i] = byteSwap(arr[i]);
|
|
3359
3618
|
}
|
|
3619
|
+
return arr;
|
|
3360
3620
|
}
|
|
3621
|
+
const swap32IfBE = isLE ? u => u : byteSwap32;
|
|
3361
3622
|
/**
|
|
3362
|
-
*
|
|
3363
|
-
* @example utf8ToBytes('abc') //
|
|
3623
|
+
* Converts string to bytes using UTF8 encoding.
|
|
3624
|
+
* @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
|
|
3364
3625
|
*/
|
|
3365
3626
|
function utf8ToBytes(str) {
|
|
3366
|
-
if (typeof str !== 'string') throw new Error('
|
|
3627
|
+
if (typeof str !== 'string') throw new Error('string expected');
|
|
3367
3628
|
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
|
3368
3629
|
}
|
|
3369
3630
|
/**
|
|
@@ -3377,14 +3638,9 @@
|
|
|
3377
3638
|
return data;
|
|
3378
3639
|
}
|
|
3379
3640
|
/** For runtime check if class implements interface */
|
|
3380
|
-
class Hash {
|
|
3381
|
-
// Safe version that clones internal state
|
|
3382
|
-
clone() {
|
|
3383
|
-
return this._cloneInto();
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3641
|
+
class Hash {}
|
|
3386
3642
|
/** Wraps hash function, creating an interface on top of it */
|
|
3387
|
-
function
|
|
3643
|
+
function createHasher(hashCons) {
|
|
3388
3644
|
const hashC = msg => hashCons().update(toBytes(msg)).digest();
|
|
3389
3645
|
const tmp = hashCons();
|
|
3390
3646
|
hashC.outputLen = tmp.outputLen;
|
|
@@ -3404,16 +3660,18 @@
|
|
|
3404
3660
|
* Check out `sha3-addons` module for cSHAKE, k12, and others.
|
|
3405
3661
|
* @module
|
|
3406
3662
|
*/
|
|
3663
|
+
// No __PURE__ annotations in sha3 header:
|
|
3664
|
+
// EVERYTHING is in fact used on every export.
|
|
3407
3665
|
// Various per round constants calculations
|
|
3666
|
+
const _0n = BigInt(0);
|
|
3667
|
+
const _1n = BigInt(1);
|
|
3668
|
+
const _2n = BigInt(2);
|
|
3669
|
+
const _7n = BigInt(7);
|
|
3670
|
+
const _256n = BigInt(256);
|
|
3671
|
+
const _0x71n = BigInt(0x71);
|
|
3408
3672
|
const SHA3_PI = [];
|
|
3409
3673
|
const SHA3_ROTL = [];
|
|
3410
3674
|
const _SHA3_IOTA = [];
|
|
3411
|
-
const _0n = /* @__PURE__ */BigInt(0);
|
|
3412
|
-
const _1n = /* @__PURE__ */BigInt(1);
|
|
3413
|
-
const _2n = /* @__PURE__ */BigInt(2);
|
|
3414
|
-
const _7n = /* @__PURE__ */BigInt(7);
|
|
3415
|
-
const _256n = /* @__PURE__ */BigInt(256);
|
|
3416
|
-
const _0x71n = /* @__PURE__ */BigInt(0x71);
|
|
3417
3675
|
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
3418
3676
|
// Pi
|
|
3419
3677
|
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
@@ -3428,7 +3686,9 @@
|
|
|
3428
3686
|
}
|
|
3429
3687
|
_SHA3_IOTA.push(t);
|
|
3430
3688
|
}
|
|
3431
|
-
const
|
|
3689
|
+
const IOTAS = split(_SHA3_IOTA, true);
|
|
3690
|
+
const SHA3_IOTA_H = IOTAS[0];
|
|
3691
|
+
const SHA3_IOTA_L = IOTAS[1];
|
|
3432
3692
|
// Left rotation (without 0, 32, 64)
|
|
3433
3693
|
const rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
3434
3694
|
const rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
@@ -3473,44 +3733,49 @@
|
|
|
3473
3733
|
s[0] ^= SHA3_IOTA_H[round];
|
|
3474
3734
|
s[1] ^= SHA3_IOTA_L[round];
|
|
3475
3735
|
}
|
|
3476
|
-
B
|
|
3736
|
+
clean(B);
|
|
3477
3737
|
}
|
|
3478
3738
|
/** Keccak sponge function. */
|
|
3479
3739
|
class Keccak extends Hash {
|
|
3480
3740
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
3481
3741
|
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
3482
3742
|
super();
|
|
3743
|
+
this.pos = 0;
|
|
3744
|
+
this.posOut = 0;
|
|
3745
|
+
this.finished = false;
|
|
3746
|
+
this.destroyed = false;
|
|
3747
|
+
this.enableXOF = false;
|
|
3483
3748
|
this.blockLen = blockLen;
|
|
3484
3749
|
this.suffix = suffix;
|
|
3485
3750
|
this.outputLen = outputLen;
|
|
3486
3751
|
this.enableXOF = enableXOF;
|
|
3487
3752
|
this.rounds = rounds;
|
|
3488
|
-
this.pos = 0;
|
|
3489
|
-
this.posOut = 0;
|
|
3490
|
-
this.finished = false;
|
|
3491
|
-
this.destroyed = false;
|
|
3492
3753
|
// Can be passed from user as dkLen
|
|
3493
3754
|
anumber(outputLen);
|
|
3494
3755
|
// 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
|
|
3495
3756
|
// 0 < blockLen < 200
|
|
3496
|
-
if (0
|
|
3757
|
+
if (!(0 < blockLen && blockLen < 200)) throw new Error('only keccak-f1600 function is supported');
|
|
3497
3758
|
this.state = new Uint8Array(200);
|
|
3498
3759
|
this.state32 = u32(this.state);
|
|
3499
3760
|
}
|
|
3761
|
+
clone() {
|
|
3762
|
+
return this._cloneInto();
|
|
3763
|
+
}
|
|
3500
3764
|
keccak() {
|
|
3501
|
-
|
|
3765
|
+
swap32IfBE(this.state32);
|
|
3502
3766
|
keccakP(this.state32, this.rounds);
|
|
3503
|
-
|
|
3767
|
+
swap32IfBE(this.state32);
|
|
3504
3768
|
this.posOut = 0;
|
|
3505
3769
|
this.pos = 0;
|
|
3506
3770
|
}
|
|
3507
3771
|
update(data) {
|
|
3508
3772
|
aexists(this);
|
|
3773
|
+
data = toBytes(data);
|
|
3774
|
+
abytes(data);
|
|
3509
3775
|
const {
|
|
3510
3776
|
blockLen,
|
|
3511
3777
|
state
|
|
3512
3778
|
} = this;
|
|
3513
|
-
data = toBytes(data);
|
|
3514
3779
|
const len = data.length;
|
|
3515
3780
|
for (let pos = 0; pos < len;) {
|
|
3516
3781
|
const take = Math.min(blockLen - this.pos, len - pos);
|
|
@@ -3572,7 +3837,7 @@
|
|
|
3572
3837
|
}
|
|
3573
3838
|
destroy() {
|
|
3574
3839
|
this.destroyed = true;
|
|
3575
|
-
this.state
|
|
3840
|
+
clean(this.state);
|
|
3576
3841
|
}
|
|
3577
3842
|
_cloneInto(to) {
|
|
3578
3843
|
const {
|
|
@@ -3596,9 +3861,9 @@
|
|
|
3596
3861
|
return to;
|
|
3597
3862
|
}
|
|
3598
3863
|
}
|
|
3599
|
-
const gen = (suffix, blockLen, outputLen) =>
|
|
3864
|
+
const gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
|
|
3600
3865
|
/** keccak-256 hash function. Different from SHA3-256. */
|
|
3601
|
-
const keccak_256 = /* @__PURE__ */gen(0x01, 136, 256 / 8);
|
|
3866
|
+
const keccak_256 = /* @__PURE__ */(() => gen(0x01, 136, 256 / 8))();
|
|
3602
3867
|
|
|
3603
3868
|
function keccak256(value, to_) {
|
|
3604
3869
|
const bytes = keccak_256(isHex(value, {
|