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