@mocanetwork/airkit 1.6.0-beta.5 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/airkit.cjs.js +276 -222
- package/dist/airkit.esm.js +275 -223
- package/dist/airkit.umd.js +276 -222
- package/dist/types/airService.d.ts +10 -16
- package/dist/types/authMessageService.d.ts +2 -7
- package/dist/types/common/air/messaging/auth.d.ts +26 -21
- package/dist/types/common/air/messaging/const.d.ts +2 -1
- package/dist/types/common/air/messaging/credential.d.ts +13 -11
- package/dist/types/common/air/messaging/messageServiceBase.d.ts +2 -1
- package/dist/types/common/air/messaging/recovery.d.ts +9 -6
- package/dist/types/common/air/messaging/types.d.ts +3 -0
- package/dist/types/common/air/messaging/wallet.d.ts +14 -12
- package/dist/types/common/const.d.ts +29 -2
- package/dist/types/common/provider/types.d.ts +1 -1
- package/dist/types/common/realm/smart-session/rule.d.ts +12 -0
- package/dist/types/common/realm/smart-session/types.d.ts +3 -3
- package/dist/types/common/realm/user/types.d.ts +2 -2
- package/dist/types/common/types.d.ts +1 -0
- package/dist/types/common/utils.d.ts +2 -1
- package/dist/types/credentialMessageService.d.ts +3 -10
- package/dist/types/error.d.ts +1 -1
- package/dist/types/interfaces.d.ts +7 -2
- package/dist/types/recoveryMessageService.d.ts +3 -8
- package/dist/types/utils.d.ts +14 -0
- package/dist/types/walletMessageService.d.ts +7 -5
- package/dist/types/windowService.d.ts +2 -1
- package/package.json +1 -1
package/dist/airkit.cjs.js
CHANGED
|
@@ -97,7 +97,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
97
97
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
-
var version = "1.
|
|
100
|
+
var version = "1.7.0";
|
|
101
101
|
var airkitPackage = {
|
|
102
102
|
version: version};
|
|
103
103
|
|
|
@@ -107,7 +107,11 @@ const AirAuthMessageTypes = {
|
|
|
107
107
|
INITIALIZATION_RESPONSE: "air_auth_initialization_response",
|
|
108
108
|
LOGIN_REQUEST: "air_auth_login_request",
|
|
109
109
|
LOGIN_RESPONSE: "air_auth_login_response",
|
|
110
|
+
LOGIN_SERVICE_STATUS_REQUEST: "air_auth_login_service_status_request",
|
|
111
|
+
LOGIN_SERVICE_STATUS_RESPONSE: "air_auth_login_service_status_response",
|
|
110
112
|
LOGIN_SERVICE_RESPONSE: "air_auth_login_service_response",
|
|
113
|
+
UPDATE_SESSION_CONFIG_REQUEST: "air_auth_update_session_config_request",
|
|
114
|
+
UPDATE_SESSION_CONFIG_RESPONSE: "air_auth_update_session_config_response",
|
|
111
115
|
USER_INFO_REQUEST: "air_auth_user_info_request",
|
|
112
116
|
USER_INFO_RESPONSE: "air_auth_user_info_response",
|
|
113
117
|
PARTNER_USER_INFO_REQUEST: "air_auth_partner_user_info_request",
|
|
@@ -116,7 +120,6 @@ const AirAuthMessageTypes = {
|
|
|
116
120
|
REFRESH_TOKEN_RESPONSE: "air_auth_refresh_token_response",
|
|
117
121
|
WALLET_TOKEN_REQUEST: "air_auth_wallet_token_request",
|
|
118
122
|
WALLET_TOKEN_RESPONSE: "air_auth_wallet_token_response",
|
|
119
|
-
INIT_WALLET_COMMUNICATION: "air_auth_init_wallet_communication",
|
|
120
123
|
IFRAME_VISIBILITY_REQUEST: "air_auth_iframe_visibility_request",
|
|
121
124
|
SETUP_WALLET_REQUEST: "air_auth_setup_wallet_request",
|
|
122
125
|
SETUP_WALLET_RESPONSE: "air_auth_setup_wallet_response",
|
|
@@ -130,15 +133,10 @@ const AirAuthMessageTypes = {
|
|
|
130
133
|
PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_partner_access_token_response",
|
|
131
134
|
LOGOUT_REQUEST: "air_auth_logout_request",
|
|
132
135
|
LOGOUT_RESPONSE: "air_auth_logout_response",
|
|
133
|
-
RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication",
|
|
134
|
-
INIT_RECOVERY_COMMUNICATION: "air_auth_init_recovery_communication",
|
|
135
|
-
RESET_RECOVERY_COMMUNICATION: "air_auth_reset_recovery_communication",
|
|
136
136
|
START_RECOVERY_REQUEST: "air_start_recovery_request",
|
|
137
137
|
START_RECOVERY_RESPONSE: "air_start_recovery_response",
|
|
138
138
|
RECOVERY_REQUEST: "air_auth_recovery_request",
|
|
139
139
|
RECOVERY_RESPONSE: "air_auth_recovery_response",
|
|
140
|
-
INIT_CREDENTIAL_COMMUNICATION: "air_auth_init_credential_communication",
|
|
141
|
-
RESET_CREDENTIAL_COMMUNICATION: "air_auth_reset_credential_communication",
|
|
142
140
|
EXPIRED_LOGOUT_REQUEST: "air_auth_expired_logout_request"
|
|
143
141
|
};
|
|
144
142
|
|
|
@@ -146,11 +144,9 @@ const AirCredentialMessageTypes = {
|
|
|
146
144
|
SERVICE_STARTED: "air_credential_service_started",
|
|
147
145
|
INITIALIZATION_REQUEST: "air_credential_initialization_request",
|
|
148
146
|
INITIALIZATION_RESPONSE: "air_credential_initialization_response",
|
|
149
|
-
INIT_AUTH_COMMUNICATION: "air_credential_init_auth_communication",
|
|
150
|
-
CREDENTIAL_AUTH_INITIALIZED: "air_credential_auth_initialized",
|
|
151
|
-
INIT_WALLET_COMMUNICATION: "air_credential_init_wallet_communication",
|
|
152
|
-
CREDENTIAL_WALLET_INITIALIZED: "air_credential_wallet_initialized",
|
|
153
147
|
CREDENTIAL_IFRAME_VISIBILITY_REQUEST: "air_credential_iframe_visibility_request",
|
|
148
|
+
UPDATE_SESSION_CONFIG_REQUEST: "air_credential_update_session_config_request",
|
|
149
|
+
UPDATE_SESSION_CONFIG_RESPONSE: "air_credential_update_session_config_response",
|
|
154
150
|
LOGOUT_REQUEST: "air_credential_logout_request",
|
|
155
151
|
LOGOUT_RESPONSE: "air_credential_logout_response",
|
|
156
152
|
// New credential operation message types
|
|
@@ -165,9 +161,10 @@ const AirRecoveryMessageTypes = {
|
|
|
165
161
|
SERVICE_STARTED: "air_recovery_service_started",
|
|
166
162
|
INITIALIZATION_REQUEST: "air_recovery_initialization_request",
|
|
167
163
|
INITIALIZATION_RESPONSE: "air_recovery_initialization_response",
|
|
168
|
-
INIT_AUTH_COMMUNICATION: "air_recovery_init_auth_communication",
|
|
169
164
|
RECOVERY_INITIALIZED: "air_recovery_initialized",
|
|
170
165
|
RECOVERY_IFRAME_VISIBILITY_REQUEST: "air_recovery_iframe_visibility_request",
|
|
166
|
+
UPDATE_SESSION_CONFIG_REQUEST: "air_recovery_update_session_config_request",
|
|
167
|
+
UPDATE_SESSION_CONFIG_RESPONSE: "air_recovery_update_session_config_response",
|
|
171
168
|
LOGOUT_REQUEST: "air_recovery_logout_request",
|
|
172
169
|
LOGOUT_RESPONSE: "air_recovery_logout_response"
|
|
173
170
|
};
|
|
@@ -178,8 +175,9 @@ const AirWalletMessageTypes = {
|
|
|
178
175
|
INITIALIZATION_RESPONSE: "air_initialization_response",
|
|
179
176
|
CLOSE_MODAL_REQUEST: "air_close_modal_request",
|
|
180
177
|
CLOSE_MODAL_RESPONSE: "air_close_modal_response",
|
|
181
|
-
INIT_AUTH_COMMUNICATION: "air_init_auth_communication",
|
|
182
178
|
WALLET_INITIALIZED: "air_wallet_initialized",
|
|
179
|
+
UPDATE_SESSION_CONFIG_REQUEST: "air_wallet_update_session_config_request",
|
|
180
|
+
UPDATE_SESSION_CONFIG_RESPONSE: "air_wallet_update_session_config_response",
|
|
183
181
|
WALLET_LOGIN_REQUEST: "air_wallet_login_request",
|
|
184
182
|
WALLET_LOGIN_RESPONSE: "air_wallet_login_response",
|
|
185
183
|
SETUP_OR_UPDATE_MFA_REQUEST: "air_setup_mfa_request",
|
|
@@ -197,8 +195,6 @@ const AirWalletMessageTypes = {
|
|
|
197
195
|
IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
|
|
198
196
|
LOGOUT_REQUEST: "air_logout_request",
|
|
199
197
|
LOGOUT_RESPONSE: "air_logout_response",
|
|
200
|
-
INIT_CREDENTIAL_COMMUNICATION: "air_init_credential_communication",
|
|
201
|
-
RESET_CREDENTIAL_COMMUNICATION: "air_reset_credential_communication",
|
|
202
198
|
INTERNAL_PROVIDER_REQUEST: "air_internal_provider_request",
|
|
203
199
|
INTERNAL_PROVIDER_RESPONSE: "air_internal_provider_response"
|
|
204
200
|
};
|
|
@@ -597,6 +593,61 @@ const configureLogLevel = (environment, enableLogging) => {
|
|
|
597
593
|
log.info(`[${window?.location?.href}] LogLevel: ${getLevelName(log.getLevel())}`);
|
|
598
594
|
};
|
|
599
595
|
|
|
596
|
+
const mocaDevnet = {
|
|
597
|
+
id: 5151,
|
|
598
|
+
name: "Moca Devnet",
|
|
599
|
+
nativeCurrency: {
|
|
600
|
+
decimals: 18,
|
|
601
|
+
name: "Moca Network",
|
|
602
|
+
symbol: "MOCA"
|
|
603
|
+
},
|
|
604
|
+
rpcUrls: {
|
|
605
|
+
default: {
|
|
606
|
+
http: ["https://devnet-rpc.mocachain.org"],
|
|
607
|
+
webSocket: ["wss://devnet-rpc.mocachain.org"]
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
blockExplorers: {
|
|
611
|
+
default: {
|
|
612
|
+
name: "Moca Devnet",
|
|
613
|
+
url: "https://devnet-scan.mocachain.org"
|
|
614
|
+
}
|
|
615
|
+
},
|
|
616
|
+
contracts: {
|
|
617
|
+
multicall3: {
|
|
618
|
+
address: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
619
|
+
blockCreated: 3837540
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
const mocaTestnet = {
|
|
624
|
+
id: 222888,
|
|
625
|
+
name: "Moca Testnet",
|
|
626
|
+
nativeCurrency: {
|
|
627
|
+
decimals: 18,
|
|
628
|
+
name: "Moca Network",
|
|
629
|
+
symbol: "MOCA"
|
|
630
|
+
},
|
|
631
|
+
rpcUrls: {
|
|
632
|
+
default: {
|
|
633
|
+
http: ["https://testnet-rpc.mocachain.org"],
|
|
634
|
+
webSocket: ["wss://testnet-rpc.mocachain.org"]
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
blockExplorers: {
|
|
638
|
+
default: {
|
|
639
|
+
name: "Moca Testnet",
|
|
640
|
+
url: "https://testnet-scan.mocachain.org"
|
|
641
|
+
}
|
|
642
|
+
},
|
|
643
|
+
contracts: {
|
|
644
|
+
multicall3: {
|
|
645
|
+
address: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
646
|
+
blockCreated: 1330259
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
|
|
600
651
|
const BUILD_ENV = {
|
|
601
652
|
PRODUCTION: "production",
|
|
602
653
|
UAT: "uat",
|
|
@@ -611,12 +662,13 @@ const IFRAME_NAME_PREFIX_SET = [
|
|
|
611
662
|
"air-recovery",
|
|
612
663
|
]; // order defines the z-index from highest to lowest
|
|
613
664
|
|
|
665
|
+
const FONT_CDNS = ["https://fonts.googleapis.com", "https://fonts.gstatic.com"];
|
|
614
666
|
const AIR_URLS = {
|
|
615
667
|
[BUILD_ENV.DEVELOPMENT]: {
|
|
616
|
-
authUrl: "
|
|
617
|
-
walletUrl: "
|
|
618
|
-
recoveryUrl: "
|
|
619
|
-
credentialUrl: "
|
|
668
|
+
authUrl: "https://localhost:8200/auth/",
|
|
669
|
+
walletUrl: "https://localhost:8200/wallet/",
|
|
670
|
+
recoveryUrl: "https://localhost:8200/recovery/",
|
|
671
|
+
credentialUrl: "https://localhost:8200/credential/",
|
|
620
672
|
},
|
|
621
673
|
[BUILD_ENV.STAGING]: {
|
|
622
674
|
authUrl: "https://account.staging.air3.com/auth/",
|
|
@@ -643,6 +695,47 @@ const AIR_URLS = {
|
|
|
643
695
|
credentialUrl: "https://account.air3.com/credential/",
|
|
644
696
|
},
|
|
645
697
|
};
|
|
698
|
+
/**
|
|
699
|
+
* Injects dns-prefetch, preconnect, and prefetch link tags
|
|
700
|
+
* for a given resource or page URL.
|
|
701
|
+
*
|
|
702
|
+
* @param url - Full resource URL (e.g. "https://cdn.example.com/app.js")
|
|
703
|
+
* @param options - Optional configuration
|
|
704
|
+
* prefetch?: boolean — disable if you only want connection warm-up
|
|
705
|
+
* as?: string — specify resource type for prefetch ("document", "script", "style", "font", etc.)
|
|
706
|
+
*/
|
|
707
|
+
const addResourceHints = (url, options) => {
|
|
708
|
+
try {
|
|
709
|
+
const parsed = new URL(url, window.location.href);
|
|
710
|
+
const isCrossOrigin = parsed.origin !== window.location.origin;
|
|
711
|
+
const head = document.head;
|
|
712
|
+
const addLink = (rel, href, as, crossOrigin) => {
|
|
713
|
+
// Skip if a matching link already exists
|
|
714
|
+
if (head.querySelector(`link[rel="${rel}"][href="${href}"]`))
|
|
715
|
+
return;
|
|
716
|
+
const link = document.createElement("link");
|
|
717
|
+
link.rel = rel;
|
|
718
|
+
link.href = href;
|
|
719
|
+
if (as)
|
|
720
|
+
link.as = as;
|
|
721
|
+
if (crossOrigin)
|
|
722
|
+
link.crossOrigin = "anonymous";
|
|
723
|
+
head.appendChild(link);
|
|
724
|
+
};
|
|
725
|
+
const hostname = parsed.hostname;
|
|
726
|
+
// DNS Prefetch (scheme-less, safe for any protocol)
|
|
727
|
+
addLink("dns-prefetch", `//${hostname}`);
|
|
728
|
+
// Preconnect (TCP + TLS warm-up)
|
|
729
|
+
addLink("preconnect", parsed.origin, undefined, isCrossOrigin);
|
|
730
|
+
// Prefetch (optional — caches the resource or HTML document)
|
|
731
|
+
if (options?.prefetch !== false) {
|
|
732
|
+
addLink("prefetch", parsed.href, options?.as ?? "document", isCrossOrigin);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
catch (err) {
|
|
736
|
+
log.warn("[addResourceHints] Invalid URL:", url, err);
|
|
737
|
+
}
|
|
738
|
+
};
|
|
646
739
|
const isElement = (element) => element instanceof Element || element instanceof Document;
|
|
647
740
|
const randomId = () => Math.random().toString(36).slice(2);
|
|
648
741
|
const extractErrorHash = (message) => {
|
|
@@ -728,7 +821,7 @@ class SwitchChainError extends ProviderRpcError {
|
|
|
728
821
|
class TransactionRejectedRpcError extends ProviderRpcError {
|
|
729
822
|
constructor(message) {
|
|
730
823
|
// Remove the "Version: viem@x.x.x" suffix if present
|
|
731
|
-
const cleanMessage = message.replace(/\nVersion:.*$/,
|
|
824
|
+
const cleanMessage = message.replace(/\nVersion:.*$/, "");
|
|
732
825
|
super(cleanMessage);
|
|
733
826
|
this.code = -32003;
|
|
734
827
|
this.name = "TransactionRejectedRpcError";
|
|
@@ -1685,6 +1778,7 @@ class AirError extends BaseError {}
|
|
|
1685
1778
|
new Set(AirClientUserErrors);
|
|
1686
1779
|
new Set(Object.values(Codes));
|
|
1687
1780
|
|
|
1781
|
+
class OutgoingMessageEvent extends MessageEvent {}
|
|
1688
1782
|
class MessageServiceBase {
|
|
1689
1783
|
get events$() {
|
|
1690
1784
|
return this._events$;
|
|
@@ -1700,13 +1794,16 @@ class MessageServiceBase {
|
|
|
1700
1794
|
this.allowedMessageTypes = allowedMessageTypes;
|
|
1701
1795
|
this.closeListener = null;
|
|
1702
1796
|
}
|
|
1797
|
+
static _getName(name, targetName) {
|
|
1798
|
+
return `${name} Service: ${targetName} Channel`;
|
|
1799
|
+
}
|
|
1703
1800
|
async _open(target) {
|
|
1704
1801
|
await this.close();
|
|
1705
1802
|
this.eventSubject = new Subject();
|
|
1706
1803
|
this._events$ = this.eventSubject.asObservable();
|
|
1707
1804
|
this._messages$ = this.eventSubject.pipe(map(ev => ev.data));
|
|
1708
1805
|
this._events$.subscribe(event => {
|
|
1709
|
-
const sentOrReceived = event
|
|
1806
|
+
const sentOrReceived = event instanceof OutgoingMessageEvent ? "sent" : "received";
|
|
1710
1807
|
log.debug(`[${this.name}] Message ${sentOrReceived}:`, JSON.stringify(event.data, bigIntReplacer));
|
|
1711
1808
|
});
|
|
1712
1809
|
const handleMessage = async ev => {
|
|
@@ -1778,7 +1875,7 @@ class MessageServiceBase {
|
|
|
1778
1875
|
log.debug(`[${this.name}] Not opened yet`);
|
|
1779
1876
|
return;
|
|
1780
1877
|
}
|
|
1781
|
-
this.eventSubject.next(new
|
|
1878
|
+
this.eventSubject.next(new OutgoingMessageEvent("message", {
|
|
1782
1879
|
data: clonedMessage,
|
|
1783
1880
|
origin: window.origin
|
|
1784
1881
|
}));
|
|
@@ -1878,7 +1975,7 @@ class AirWalletProvider {
|
|
|
1878
1975
|
if (!loginResult) {
|
|
1879
1976
|
throw new UnauthorizedProviderError("User is not logged in");
|
|
1880
1977
|
}
|
|
1881
|
-
if (method === "eth_accounts" &&
|
|
1978
|
+
if ((method === "eth_accounts" || method === "eth_requestAccounts") &&
|
|
1882
1979
|
!__classPrivateFieldGet(this, _AirWalletProvider_isWalletInitialized, "f").call(this) &&
|
|
1883
1980
|
loginResult?.abstractAccountAddress) {
|
|
1884
1981
|
return [loginResult.abstractAccountAddress];
|
|
@@ -1943,9 +2040,8 @@ const ALLOWED_AUTH_MESSAGES = [
|
|
|
1943
2040
|
AirAuthMessageTypes.LOGIN_RESPONSE,
|
|
1944
2041
|
AirAuthMessageTypes.SETUP_WALLET_REQUEST,
|
|
1945
2042
|
AirAuthMessageTypes.SETUP_RECOVERY_REQUEST,
|
|
1946
|
-
AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION,
|
|
1947
|
-
AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION,
|
|
1948
2043
|
AirAuthMessageTypes.LOGOUT_RESPONSE,
|
|
2044
|
+
AirAuthMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE,
|
|
1949
2045
|
AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE,
|
|
1950
2046
|
AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE,
|
|
1951
2047
|
AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE,
|
|
@@ -1965,11 +2061,6 @@ class AuthMessageService extends MessageServiceBase {
|
|
|
1965
2061
|
const window = authIframe.contentWindow;
|
|
1966
2062
|
await super._open({ window, origin });
|
|
1967
2063
|
}
|
|
1968
|
-
async initWalletCommunication() {
|
|
1969
|
-
await this.sendMessage({
|
|
1970
|
-
type: AirAuthMessageTypes.INIT_WALLET_COMMUNICATION,
|
|
1971
|
-
});
|
|
1972
|
-
}
|
|
1973
2064
|
async sendPartnerUserInfoRequest() {
|
|
1974
2065
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE)));
|
|
1975
2066
|
await this.sendMessage({
|
|
@@ -1978,6 +2069,11 @@ class AuthMessageService extends MessageServiceBase {
|
|
|
1978
2069
|
});
|
|
1979
2070
|
return response;
|
|
1980
2071
|
}
|
|
2072
|
+
async sendUpdateSessionConfigRequest(payload) {
|
|
2073
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE)));
|
|
2074
|
+
await this.sendMessage({ type: AirAuthMessageTypes.UPDATE_SESSION_CONFIG_REQUEST, payload });
|
|
2075
|
+
return response;
|
|
2076
|
+
}
|
|
1981
2077
|
async sendLoginRequest(payload) {
|
|
1982
2078
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LOGIN_RESPONSE)));
|
|
1983
2079
|
await this.sendMessage({ type: AirAuthMessageTypes.LOGIN_REQUEST, payload });
|
|
@@ -1991,9 +2087,6 @@ class AuthMessageService extends MessageServiceBase {
|
|
|
1991
2087
|
await this.sendMessage({ type: AirAuthMessageTypes.LOGOUT_REQUEST });
|
|
1992
2088
|
return response;
|
|
1993
2089
|
}
|
|
1994
|
-
async resetWalletCommunication() {
|
|
1995
|
-
await this.sendMessage({ type: AirAuthMessageTypes.RESET_WALLET_COMMUNICATION });
|
|
1996
|
-
}
|
|
1997
2090
|
async sendInitializationRequest(payload) {
|
|
1998
2091
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.INITIALIZATION_RESPONSE)));
|
|
1999
2092
|
await this.sendMessage({ type: AirAuthMessageTypes.INITIALIZATION_REQUEST, payload });
|
|
@@ -2010,16 +2103,6 @@ class AuthMessageService extends MessageServiceBase {
|
|
|
2010
2103
|
async sendSetupWalletErrorResponse(error) {
|
|
2011
2104
|
await this.sendMessage(this.createErrorResponseMessage(AirAuthMessageTypes.SETUP_WALLET_RESPONSE, error));
|
|
2012
2105
|
}
|
|
2013
|
-
async initRecoveryCommunication() {
|
|
2014
|
-
await this.sendMessage({
|
|
2015
|
-
type: AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION,
|
|
2016
|
-
});
|
|
2017
|
-
}
|
|
2018
|
-
async resetRecoveryCommunication() {
|
|
2019
|
-
await this.sendMessage({
|
|
2020
|
-
type: AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION,
|
|
2021
|
-
});
|
|
2022
|
-
}
|
|
2023
2106
|
async sendSetupRecoverySuccessResponse() {
|
|
2024
2107
|
await this.sendMessage({
|
|
2025
2108
|
type: AirAuthMessageTypes.SETUP_RECOVERY_RESPONSE,
|
|
@@ -2056,19 +2139,6 @@ class AuthMessageService extends MessageServiceBase {
|
|
|
2056
2139
|
await this.sendMessage({ type: AirAuthMessageTypes.START_RECOVERY_REQUEST, payload });
|
|
2057
2140
|
return response;
|
|
2058
2141
|
}
|
|
2059
|
-
/*
|
|
2060
|
-
* Initialize credential communication
|
|
2061
|
-
*/
|
|
2062
|
-
async initCredentialCommunication() {
|
|
2063
|
-
await this.sendMessage({
|
|
2064
|
-
type: AirAuthMessageTypes.INIT_CREDENTIAL_COMMUNICATION,
|
|
2065
|
-
});
|
|
2066
|
-
}
|
|
2067
|
-
async resetCredentialCommunication() {
|
|
2068
|
-
await this.sendMessage({
|
|
2069
|
-
type: AirAuthMessageTypes.RESET_CREDENTIAL_COMMUNICATION,
|
|
2070
|
-
});
|
|
2071
|
-
}
|
|
2072
2142
|
}
|
|
2073
2143
|
_a$3 = AuthMessageService;
|
|
2074
2144
|
_AuthMessageService_instance = { value: void 0 };
|
|
@@ -2077,8 +2147,7 @@ var _a$2, _CredentialMessageService_instance;
|
|
|
2077
2147
|
const ALLOWED_CREDENTIAL_MESSAGES = [
|
|
2078
2148
|
AirCredentialMessageTypes.INITIALIZATION_RESPONSE,
|
|
2079
2149
|
AirCredentialMessageTypes.CREDENTIAL_IFRAME_VISIBILITY_REQUEST,
|
|
2080
|
-
AirCredentialMessageTypes.
|
|
2081
|
-
AirCredentialMessageTypes.CREDENTIAL_WALLET_INITIALIZED,
|
|
2150
|
+
AirCredentialMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE,
|
|
2082
2151
|
AirCredentialMessageTypes.LOGOUT_RESPONSE,
|
|
2083
2152
|
AirCredentialMessageTypes.ISSUE_CREDENTIAL_RESPONSE,
|
|
2084
2153
|
AirCredentialMessageTypes.VERIFY_CREDENTIAL_RESPONSE,
|
|
@@ -2104,17 +2173,11 @@ class CredentialMessageService extends MessageServiceBase {
|
|
|
2104
2173
|
});
|
|
2105
2174
|
return response;
|
|
2106
2175
|
}
|
|
2107
|
-
async
|
|
2108
|
-
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirCredentialMessageTypes.
|
|
2176
|
+
async sendUpdateSessionConfigRequest(payload) {
|
|
2177
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirCredentialMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE)));
|
|
2109
2178
|
await this.sendMessage({
|
|
2110
|
-
type: AirCredentialMessageTypes.
|
|
2111
|
-
|
|
2112
|
-
return response;
|
|
2113
|
-
}
|
|
2114
|
-
async initWalletCommunication() {
|
|
2115
|
-
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirCredentialMessageTypes.CREDENTIAL_WALLET_INITIALIZED)));
|
|
2116
|
-
await this.sendMessage({
|
|
2117
|
-
type: AirCredentialMessageTypes.INIT_WALLET_COMMUNICATION,
|
|
2179
|
+
type: AirCredentialMessageTypes.UPDATE_SESSION_CONFIG_REQUEST,
|
|
2180
|
+
payload,
|
|
2118
2181
|
});
|
|
2119
2182
|
return response;
|
|
2120
2183
|
}
|
|
@@ -2183,6 +2246,17 @@ class IframeController {
|
|
|
2183
2246
|
iframe.style.padding = "0";
|
|
2184
2247
|
iframe.style.display = "none";
|
|
2185
2248
|
iframe.style.colorScheme = "auto";
|
|
2249
|
+
iframe.setAttribute("sandbox", [
|
|
2250
|
+
"allow-scripts",
|
|
2251
|
+
"allow-same-origin",
|
|
2252
|
+
"allow-storage-access-by-user-activation",
|
|
2253
|
+
"allow-modals",
|
|
2254
|
+
"allow-popups",
|
|
2255
|
+
"allow-popups-to-escape-sandbox", // for google login
|
|
2256
|
+
"allow-forms", // for google login
|
|
2257
|
+
"allow-downloads", // for recovery export
|
|
2258
|
+
"allow-top-navigation-by-user-activation",
|
|
2259
|
+
].join(" "));
|
|
2186
2260
|
document.body.appendChild(iframe);
|
|
2187
2261
|
this._iframeElement = iframe;
|
|
2188
2262
|
return iframe;
|
|
@@ -2238,14 +2312,17 @@ class RecoveryMessageService extends MessageServiceBase {
|
|
|
2238
2312
|
});
|
|
2239
2313
|
return response;
|
|
2240
2314
|
}
|
|
2241
|
-
async initAuthCommunication() {
|
|
2242
|
-
await this.sendMessage({
|
|
2243
|
-
type: AirRecoveryMessageTypes.INIT_AUTH_COMMUNICATION,
|
|
2244
|
-
});
|
|
2245
|
-
}
|
|
2246
2315
|
async onInitialized() {
|
|
2247
2316
|
return firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirRecoveryMessageTypes.RECOVERY_INITIALIZED)));
|
|
2248
2317
|
}
|
|
2318
|
+
async sendUpdateSessionConfigRequest(payload) {
|
|
2319
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirRecoveryMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE)));
|
|
2320
|
+
await this.sendMessage({
|
|
2321
|
+
type: AirRecoveryMessageTypes.UPDATE_SESSION_CONFIG_REQUEST,
|
|
2322
|
+
payload,
|
|
2323
|
+
});
|
|
2324
|
+
return response;
|
|
2325
|
+
}
|
|
2249
2326
|
async logout() {
|
|
2250
2327
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirRecoveryMessageTypes.LOGOUT_RESPONSE)));
|
|
2251
2328
|
await this.sendMessage({ type: AirRecoveryMessageTypes.LOGOUT_REQUEST });
|
|
@@ -2265,6 +2342,7 @@ var _a, _WalletMessageService_instance;
|
|
|
2265
2342
|
const ALLOWED_WALLET_MESSAGES = [
|
|
2266
2343
|
AirWalletMessageTypes.INITIALIZATION_RESPONSE,
|
|
2267
2344
|
AirWalletMessageTypes.WALLET_INITIALIZED,
|
|
2345
|
+
AirWalletMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE,
|
|
2268
2346
|
AirWalletMessageTypes.WALLET_LOGIN_RESPONSE,
|
|
2269
2347
|
AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_RESPONSE,
|
|
2270
2348
|
AirWalletMessageTypes.SHOW_SWAP_UI_RESPONSE,
|
|
@@ -2289,14 +2367,6 @@ class WalletMessageService extends MessageServiceBase {
|
|
|
2289
2367
|
const window = walletIframe.contentWindow;
|
|
2290
2368
|
await super._open({ window, origin });
|
|
2291
2369
|
}
|
|
2292
|
-
async initAuthCommunication(skipWalletLogin) {
|
|
2293
|
-
await this.sendMessage({
|
|
2294
|
-
type: AirWalletMessageTypes.INIT_AUTH_COMMUNICATION,
|
|
2295
|
-
payload: {
|
|
2296
|
-
skipWalletLogin,
|
|
2297
|
-
},
|
|
2298
|
-
});
|
|
2299
|
-
}
|
|
2300
2370
|
async sendDeploySmartAccountRequest() {
|
|
2301
2371
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE)));
|
|
2302
2372
|
await this.sendMessage({
|
|
@@ -2324,6 +2394,11 @@ class WalletMessageService extends MessageServiceBase {
|
|
|
2324
2394
|
onInitialized() {
|
|
2325
2395
|
return firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.WALLET_INITIALIZED)));
|
|
2326
2396
|
}
|
|
2397
|
+
async sendUpdateSessionConfigRequest(payload) {
|
|
2398
|
+
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE)));
|
|
2399
|
+
await this.sendMessage({ type: AirWalletMessageTypes.UPDATE_SESSION_CONFIG_REQUEST, payload });
|
|
2400
|
+
return response;
|
|
2401
|
+
}
|
|
2327
2402
|
async sendLoginRequest() {
|
|
2328
2403
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.WALLET_LOGIN_RESPONSE)));
|
|
2329
2404
|
await this.sendMessage({
|
|
@@ -2375,10 +2450,11 @@ class WalletMessageService extends MessageServiceBase {
|
|
|
2375
2450
|
await this.sendMessage({ type: AirWalletMessageTypes.CLAIM_ID_REQUEST, payload });
|
|
2376
2451
|
return response;
|
|
2377
2452
|
}
|
|
2378
|
-
async sendShowSwapUIRequest() {
|
|
2453
|
+
async sendShowSwapUIRequest(payload) {
|
|
2379
2454
|
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.SHOW_SWAP_UI_RESPONSE)));
|
|
2380
2455
|
await this.sendMessage({
|
|
2381
2456
|
type: AirWalletMessageTypes.SHOW_SWAP_UI_REQUEST,
|
|
2457
|
+
payload
|
|
2382
2458
|
});
|
|
2383
2459
|
return response;
|
|
2384
2460
|
}
|
|
@@ -2390,16 +2466,6 @@ class WalletMessageService extends MessageServiceBase {
|
|
|
2390
2466
|
});
|
|
2391
2467
|
return response;
|
|
2392
2468
|
}
|
|
2393
|
-
async initCredentialCommunication() {
|
|
2394
|
-
await this.sendMessage({
|
|
2395
|
-
type: AirWalletMessageTypes.INIT_CREDENTIAL_COMMUNICATION,
|
|
2396
|
-
});
|
|
2397
|
-
}
|
|
2398
|
-
async resetCredentialCommunication() {
|
|
2399
|
-
await this.sendMessage({
|
|
2400
|
-
type: AirWalletMessageTypes.RESET_CREDENTIAL_COMMUNICATION,
|
|
2401
|
-
});
|
|
2402
|
-
}
|
|
2403
2469
|
}
|
|
2404
2470
|
_a = WalletMessageService;
|
|
2405
2471
|
_WalletMessageService_instance = { value: void 0 };
|
|
@@ -2541,7 +2607,7 @@ class WindowService {
|
|
|
2541
2607
|
]);
|
|
2542
2608
|
return (await response).data;
|
|
2543
2609
|
}
|
|
2544
|
-
async openAndInitializeWalletServiceWindow({ url, windowId, partnerId, enableLogging, onRetry, sdkVersion, enableAutomation, }) {
|
|
2610
|
+
async openAndInitializeWalletServiceWindow({ url, windowId, sessionId, partnerId, enableLogging, onRetry, sdkVersion, enableAutomation, }) {
|
|
2545
2611
|
if (this.windowControllers.has(windowId)) {
|
|
2546
2612
|
throw new Error("Window controller already exists");
|
|
2547
2613
|
}
|
|
@@ -2559,6 +2625,7 @@ class WindowService {
|
|
|
2559
2625
|
try {
|
|
2560
2626
|
channel = new MessageChannel();
|
|
2561
2627
|
const { payload } = await this.sendWindowInitializationRequest(windowId, {
|
|
2628
|
+
sessionId,
|
|
2562
2629
|
partnerId,
|
|
2563
2630
|
enableLogging,
|
|
2564
2631
|
sdkVersion,
|
|
@@ -2598,7 +2665,7 @@ class WindowService {
|
|
|
2598
2665
|
}
|
|
2599
2666
|
var WindowService$1 = WindowService.instance;
|
|
2600
2667
|
|
|
2601
|
-
var _AirService_instances, _AirService_loginResult, _AirService_buildEnv, _AirService_enableLogging, _AirService_partnerId, _AirService_authMessagingService, _AirService_authIframeController, _AirService_isAuthInitialized,
|
|
2668
|
+
var _AirService_instances, _AirService_loginResult, _AirService_buildEnv, _AirService_enableLogging, _AirService_partnerId, _AirService_sessionId, _AirService_sessionConfig, _AirService_authMessagingService, _AirService_authIframeController, _AirService_isAuthInitialized, _AirService_airEventListener, _AirService_walletMessagingService, _AirService_walletIframeController, _AirService_walletInitialization, _AirService_walletLoggedInResult, _AirService_airWalletProvider, _AirService_recoveryInitialization, _AirService_recoveryMessagingService, _AirService_recoveryIframeController, _AirService_credentialsInitialization, _AirService_credentialMessagingService, _AirService_credentialIframeController, _AirService_assertInitialized, _AirService_assertLoggedIn, _AirService_ensureCredential, _AirService_initializeCredentials, _AirService_subscribeToCredentialEvents, _AirService_cleanUpCredential, _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;
|
|
2602
2669
|
const airKitVersion = airkitPackage.version;
|
|
2603
2670
|
class AirService {
|
|
2604
2671
|
constructor({ partnerId }) {
|
|
@@ -2607,11 +2674,13 @@ class AirService {
|
|
|
2607
2674
|
_AirService_buildEnv.set(this, void 0);
|
|
2608
2675
|
_AirService_enableLogging.set(this, false);
|
|
2609
2676
|
_AirService_partnerId.set(this, void 0);
|
|
2677
|
+
_AirService_sessionId.set(this, void 0);
|
|
2678
|
+
_AirService_sessionConfig.set(this, void 0);
|
|
2610
2679
|
//#modalZIndex: number; TODO implement z index overwrite
|
|
2611
2680
|
_AirService_authMessagingService.set(this, void 0);
|
|
2612
2681
|
_AirService_authIframeController.set(this, void 0);
|
|
2613
2682
|
_AirService_isAuthInitialized.set(this, false);
|
|
2614
|
-
|
|
2683
|
+
_AirService_airEventListener.set(this, []);
|
|
2615
2684
|
_AirService_walletMessagingService.set(this, void 0);
|
|
2616
2685
|
_AirService_walletIframeController.set(this, void 0);
|
|
2617
2686
|
_AirService_walletInitialization.set(this, void 0);
|
|
@@ -2633,7 +2702,7 @@ class AirService {
|
|
|
2633
2702
|
ensureWallet: __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).bind(this),
|
|
2634
2703
|
getLoginResult: () => __classPrivateFieldGet(this, _AirService_loginResult, "f"),
|
|
2635
2704
|
}), "f");
|
|
2636
|
-
|
|
2705
|
+
FONT_CDNS.forEach((cdn) => addResourceHints(cdn, { prefetch: false }));
|
|
2637
2706
|
}
|
|
2638
2707
|
get buildEnv() {
|
|
2639
2708
|
return __classPrivateFieldGet(this, _AirService_buildEnv, "f");
|
|
@@ -2661,15 +2730,24 @@ class AirService {
|
|
|
2661
2730
|
shouldEnableAutomation() {
|
|
2662
2731
|
return localStorage.getItem("automation") === "true" && __classPrivateFieldGet(this, _AirService_buildEnv, "f") !== BUILD_ENV.PRODUCTION;
|
|
2663
2732
|
}
|
|
2664
|
-
async init({ buildEnv = BUILD_ENV.PRODUCTION, enableLogging = false, skipRehydration = false, }) {
|
|
2733
|
+
async init({ buildEnv = BUILD_ENV.PRODUCTION, enableLogging = false, skipRehydration = false, sessionConfig = undefined, preloadWallet = false, preloadCredential = false, }) {
|
|
2665
2734
|
if (!__classPrivateFieldGet(this, _AirService_partnerId, "f"))
|
|
2666
|
-
throw new
|
|
2735
|
+
throw new AirServiceError("CLIENT_ERROR", "Partner ID is required to initialize the service");
|
|
2667
2736
|
if (__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2668
|
-
return;
|
|
2737
|
+
return __classPrivateFieldGet(this, _AirService_loginResult, "f") ?? null;
|
|
2738
|
+
configureLogLevel(buildEnv, enableLogging);
|
|
2739
|
+
const { authUrl, walletUrl, credentialUrl } = AIR_URLS[buildEnv];
|
|
2740
|
+
addResourceHints(authUrl);
|
|
2741
|
+
if (preloadWallet) {
|
|
2742
|
+
addResourceHints(walletUrl);
|
|
2743
|
+
}
|
|
2744
|
+
if (preloadCredential) {
|
|
2745
|
+
addResourceHints(credentialUrl);
|
|
2746
|
+
}
|
|
2669
2747
|
__classPrivateFieldSet(this, _AirService_buildEnv, buildEnv, "f");
|
|
2670
2748
|
__classPrivateFieldSet(this, _AirService_enableLogging, enableLogging, "f");
|
|
2671
|
-
|
|
2672
|
-
|
|
2749
|
+
__classPrivateFieldSet(this, _AirService_sessionConfig, sessionConfig, "f");
|
|
2750
|
+
__classPrivateFieldSet(this, _AirService_sessionId, randomId(), "f");
|
|
2673
2751
|
const authIframeOrigin = new URL(authUrl).origin;
|
|
2674
2752
|
__classPrivateFieldSet(this, _AirService_authIframeController, new IframeController("air-auth", authUrl), "f");
|
|
2675
2753
|
try {
|
|
@@ -2719,12 +2797,14 @@ class AirService {
|
|
|
2719
2797
|
if (ev.data === AirAuthMessageTypes.AUTH_SETUP_COMPLETED) {
|
|
2720
2798
|
window.removeEventListener("message", handleAuthMessage);
|
|
2721
2799
|
const { payload } = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendInitializationRequest({
|
|
2800
|
+
sessionId: __classPrivateFieldGet(this, _AirService_sessionId, "f"),
|
|
2722
2801
|
partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
|
|
2723
2802
|
skipRehydration,
|
|
2724
2803
|
partnerDAppUrl: window.location.href,
|
|
2725
2804
|
sdkVersion: airKitVersion,
|
|
2726
2805
|
enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
|
|
2727
2806
|
enableAutomation: this.shouldEnableAutomation(),
|
|
2807
|
+
sessionConfig,
|
|
2728
2808
|
});
|
|
2729
2809
|
if (payload.success === true) {
|
|
2730
2810
|
resolve(payload);
|
|
@@ -2738,8 +2818,10 @@ class AirService {
|
|
|
2738
2818
|
});
|
|
2739
2819
|
__classPrivateFieldSet(this, _AirService_isAuthInitialized, true, "f");
|
|
2740
2820
|
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthInitialized).call(this, { rehydrated: result.rehydrated });
|
|
2741
|
-
if (result.preloadWallet)
|
|
2821
|
+
if (result.preloadWallet || preloadWallet)
|
|
2742
2822
|
void this.preloadWallet();
|
|
2823
|
+
if (preloadCredential)
|
|
2824
|
+
void this.preloadCredential();
|
|
2743
2825
|
// rehydrated auth session
|
|
2744
2826
|
if (result.rehydrated) {
|
|
2745
2827
|
__classPrivateFieldSet(this, _AirService_loginResult, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_createLoginResult).call(this, result), "f");
|
|
@@ -2750,13 +2832,12 @@ class AirService {
|
|
|
2750
2832
|
catch (error) {
|
|
2751
2833
|
log.debug("Error initializing auth service", error);
|
|
2752
2834
|
await this.cleanUp();
|
|
2753
|
-
throw error;
|
|
2835
|
+
throw AirServiceError.from(error);
|
|
2754
2836
|
}
|
|
2755
2837
|
return null;
|
|
2756
2838
|
}
|
|
2757
2839
|
async login(options) {
|
|
2758
|
-
|
|
2759
|
-
throw new Error("Service is not initialized");
|
|
2840
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
|
|
2760
2841
|
if (__classPrivateFieldGet(this, _AirService_loginResult, "f"))
|
|
2761
2842
|
return __classPrivateFieldGet(this, _AirService_loginResult, "f");
|
|
2762
2843
|
const { payload } = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendLoginRequest({
|
|
@@ -2773,38 +2854,24 @@ class AirService {
|
|
|
2773
2854
|
* @experimental This method is experimental and will change in the future.
|
|
2774
2855
|
*/
|
|
2775
2856
|
async deploySmartAccount() {
|
|
2776
|
-
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2777
|
-
throw new Error("Service is not initialized");
|
|
2778
2857
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
throw new AirServiceError(payload.errorName, payload.errorMessage);
|
|
2784
|
-
}
|
|
2785
|
-
return { txHash: payload.txHash };
|
|
2786
|
-
}
|
|
2787
|
-
catch (error) {
|
|
2788
|
-
throw AirServiceError.from(error);
|
|
2858
|
+
log.info("deploySmartAccount");
|
|
2859
|
+
const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendDeploySmartAccountRequest();
|
|
2860
|
+
if (payload.success === false) {
|
|
2861
|
+
throw new AirServiceError(payload.errorName, payload.errorMessage);
|
|
2789
2862
|
}
|
|
2863
|
+
return { txHash: payload.txHash };
|
|
2790
2864
|
}
|
|
2791
2865
|
/**
|
|
2792
2866
|
* @experimental This method is experimental and will change in the future.
|
|
2793
2867
|
*/
|
|
2794
2868
|
async isSmartAccountDeployed() {
|
|
2795
|
-
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2796
|
-
throw new Error("Service is not initialized");
|
|
2797
2869
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
throw new AirServiceError(payload.errorName, payload.errorMessage);
|
|
2802
|
-
}
|
|
2803
|
-
return payload.isDeployed;
|
|
2804
|
-
}
|
|
2805
|
-
catch (error) {
|
|
2806
|
-
throw AirServiceError.from(error);
|
|
2870
|
+
const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendIsSmartAccountDeployedRequest();
|
|
2871
|
+
if (payload.success === false) {
|
|
2872
|
+
throw new AirServiceError(payload.errorName, payload.errorMessage);
|
|
2807
2873
|
}
|
|
2874
|
+
return payload.isDeployed;
|
|
2808
2875
|
}
|
|
2809
2876
|
getProvider() {
|
|
2810
2877
|
return this.provider;
|
|
@@ -2837,9 +2904,9 @@ class AirService {
|
|
|
2837
2904
|
/**
|
|
2838
2905
|
* @experimental This feature has not been officially released and might change in the future.
|
|
2839
2906
|
*/
|
|
2840
|
-
async showSwapUI() {
|
|
2907
|
+
async showSwapUI(options) {
|
|
2841
2908
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
2842
|
-
const result = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendShowSwapUIRequest();
|
|
2909
|
+
const result = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendShowSwapUIRequest(options);
|
|
2843
2910
|
if (result.payload.success === false) {
|
|
2844
2911
|
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2845
2912
|
}
|
|
@@ -2856,8 +2923,7 @@ class AirService {
|
|
|
2856
2923
|
}
|
|
2857
2924
|
}
|
|
2858
2925
|
async getUserInfo() {
|
|
2859
|
-
|
|
2860
|
-
throw new Error("User not logged in");
|
|
2926
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertLoggedIn).call(this);
|
|
2861
2927
|
const info = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendPartnerUserInfoRequest();
|
|
2862
2928
|
if (info.payload.success === false) {
|
|
2863
2929
|
throw new AirServiceError(info.payload.errorName, info.payload.errorMessage);
|
|
@@ -2874,11 +2940,37 @@ class AirService {
|
|
|
2874
2940
|
},
|
|
2875
2941
|
};
|
|
2876
2942
|
}
|
|
2943
|
+
async updateSessionConfig(config) {
|
|
2944
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
|
|
2945
|
+
__classPrivateFieldSet(this, _AirService_sessionConfig, config, "f");
|
|
2946
|
+
const resultsPromise = [__classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendUpdateSessionConfigRequest(config)];
|
|
2947
|
+
if (__classPrivateFieldGet(this, _AirService_walletInitialization, "f")) {
|
|
2948
|
+
resultsPromise.push(__classPrivateFieldGet(this, _AirService_walletInitialization, "f")
|
|
2949
|
+
.then(() => __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendUpdateSessionConfigRequest(config))
|
|
2950
|
+
.catch(() => null));
|
|
2951
|
+
}
|
|
2952
|
+
if (__classPrivateFieldGet(this, _AirService_recoveryInitialization, "f")) {
|
|
2953
|
+
resultsPromise.push(__classPrivateFieldGet(this, _AirService_recoveryInitialization, "f")
|
|
2954
|
+
.then(() => __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").sendUpdateSessionConfigRequest(config))
|
|
2955
|
+
.catch(() => null));
|
|
2956
|
+
}
|
|
2957
|
+
if (__classPrivateFieldGet(this, _AirService_credentialsInitialization, "f")) {
|
|
2958
|
+
resultsPromise.push(__classPrivateFieldGet(this, _AirService_credentialsInitialization, "f")
|
|
2959
|
+
.then(() => __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").sendUpdateSessionConfigRequest(config))
|
|
2960
|
+
.catch(() => null));
|
|
2961
|
+
}
|
|
2962
|
+
const results = await Promise.all(resultsPromise);
|
|
2963
|
+
for (const result of results) {
|
|
2964
|
+
if (result && result.payload.success === false) {
|
|
2965
|
+
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
const sessionConfig = { locale: results[0].payload.locale };
|
|
2969
|
+
__classPrivateFieldSet(this, _AirService_sessionConfig, sessionConfig, "f");
|
|
2970
|
+
return sessionConfig;
|
|
2971
|
+
}
|
|
2877
2972
|
async goToPartner(partnerUrl) {
|
|
2878
|
-
|
|
2879
|
-
throw new Error("Service is not initialized");
|
|
2880
|
-
if (!this.isLoggedIn)
|
|
2881
|
-
throw new Error("No active session to generate token");
|
|
2973
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertLoggedIn).call(this);
|
|
2882
2974
|
const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendCrossPartnerTokenRequest(partnerUrl);
|
|
2883
2975
|
if (result.payload.success === false) {
|
|
2884
2976
|
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
@@ -2888,35 +2980,24 @@ class AirService {
|
|
|
2888
2980
|
};
|
|
2889
2981
|
}
|
|
2890
2982
|
async startRecovery(payload) {
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2895
|
-
}
|
|
2896
|
-
}
|
|
2897
|
-
catch (error) {
|
|
2898
|
-
throw AirServiceError.from(error);
|
|
2983
|
+
const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendAccountRecoveryRequest(payload);
|
|
2984
|
+
if (result.payload.success === false) {
|
|
2985
|
+
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2899
2986
|
}
|
|
2900
2987
|
}
|
|
2901
2988
|
async getAccessToken() {
|
|
2902
|
-
|
|
2903
|
-
throw new Error("Service is not initialized");
|
|
2904
|
-
if (!this.isLoggedIn)
|
|
2905
|
-
throw new Error("No active session to get partner access token");
|
|
2989
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertLoggedIn).call(this);
|
|
2906
2990
|
const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendPartnerAccessTokenRequest();
|
|
2907
2991
|
if (result.payload.success !== true) {
|
|
2908
2992
|
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2909
2993
|
}
|
|
2910
2994
|
if (!result.payload.partnerAccessToken) {
|
|
2911
|
-
throw new
|
|
2995
|
+
throw new AirServiceError("UNAUTHORIZED", "Partner access token not found in response");
|
|
2912
2996
|
}
|
|
2913
2997
|
return { token: result.payload.partnerAccessToken };
|
|
2914
2998
|
}
|
|
2915
2999
|
async logout() {
|
|
2916
|
-
|
|
2917
|
-
throw new Error("Service is not initialized");
|
|
2918
|
-
if (!this.isLoggedIn)
|
|
2919
|
-
throw new Error("No active session to logout");
|
|
3000
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertLoggedIn).call(this);
|
|
2920
3001
|
// Clear up credentials first to avoid issues with wallet and auth messaging services
|
|
2921
3002
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpCredential).call(this);
|
|
2922
3003
|
await Promise.all([
|
|
@@ -2928,33 +3009,21 @@ class AirService {
|
|
|
2928
3009
|
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthLoggedOut).call(this);
|
|
2929
3010
|
}
|
|
2930
3011
|
async cleanUp() {
|
|
3012
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpCredential).call(this);
|
|
3013
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
|
|
2931
3014
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
|
|
2932
3015
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpAuth).call(this);
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
this
|
|
3016
|
+
__classPrivateFieldSet(this, _AirService_airEventListener, [], "f");
|
|
3017
|
+
__classPrivateFieldSet(this, _AirService_sessionId, undefined, "f");
|
|
3018
|
+
__classPrivateFieldSet(this, _AirService_buildEnv, undefined, "f");
|
|
2936
3019
|
}
|
|
2937
|
-
/**
|
|
2938
|
-
* Register an event listener for Air service events.
|
|
2939
|
-
*
|
|
2940
|
-
* Available events:
|
|
2941
|
-
* - "initialized": Service initialization completed
|
|
2942
|
-
* - "logged_in": User successfully logged in
|
|
2943
|
-
* - "logged_out": User logged out
|
|
2944
|
-
* - "wallet_initialized": Wallet initialization completed
|
|
2945
|
-
*
|
|
2946
|
-
* @param listener The event listener function
|
|
2947
|
-
*/
|
|
2948
3020
|
on(listener) {
|
|
2949
|
-
if (__classPrivateFieldGet(this,
|
|
2950
|
-
__classPrivateFieldGet(this,
|
|
3021
|
+
if (__classPrivateFieldGet(this, _AirService_airEventListener, "f").indexOf(listener) < 0)
|
|
3022
|
+
__classPrivateFieldGet(this, _AirService_airEventListener, "f").push(listener);
|
|
2951
3023
|
}
|
|
2952
3024
|
off(listener) {
|
|
2953
|
-
if (__classPrivateFieldGet(this,
|
|
2954
|
-
__classPrivateFieldGet(this,
|
|
2955
|
-
}
|
|
2956
|
-
clearEventListeners() {
|
|
2957
|
-
__classPrivateFieldSet(this, _AirService_airAuthListener, [], "f");
|
|
3025
|
+
if (__classPrivateFieldGet(this, _AirService_airEventListener, "f").indexOf(listener) >= 0)
|
|
3026
|
+
__classPrivateFieldGet(this, _AirService_airEventListener, "f").splice(__classPrivateFieldGet(this, _AirService_airEventListener, "f").indexOf(listener), 1);
|
|
2958
3027
|
}
|
|
2959
3028
|
async preloadCredential() {
|
|
2960
3029
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureCredential).call(this);
|
|
@@ -2987,9 +3056,15 @@ class AirService {
|
|
|
2987
3056
|
return payload.verificationResult;
|
|
2988
3057
|
}
|
|
2989
3058
|
}
|
|
2990
|
-
_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(),
|
|
2991
|
-
if (!this
|
|
2992
|
-
throw new
|
|
3059
|
+
_AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _AirService_enableLogging = new WeakMap(), _AirService_partnerId = new WeakMap(), _AirService_sessionId = new WeakMap(), _AirService_sessionConfig = new WeakMap(), _AirService_authMessagingService = new WeakMap(), _AirService_authIframeController = new WeakMap(), _AirService_isAuthInitialized = new WeakMap(), _AirService_airEventListener = 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_credentialsInitialization = new WeakMap(), _AirService_credentialMessagingService = new WeakMap(), _AirService_credentialIframeController = new WeakMap(), _AirService_instances = new WeakSet(), _AirService_assertInitialized = function _AirService_assertInitialized() {
|
|
3060
|
+
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
3061
|
+
throw new AirServiceError("NOT_INITIALIZED", "Service is not initialized");
|
|
3062
|
+
}, _AirService_assertLoggedIn = function _AirService_assertLoggedIn() {
|
|
3063
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
|
|
3064
|
+
if (!this.isLoggedIn)
|
|
3065
|
+
throw new AirServiceError("NOT_LOGGED_IN", "User not logged in");
|
|
3066
|
+
}, _AirService_ensureCredential = async function _AirService_ensureCredential() {
|
|
3067
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
|
|
2993
3068
|
void __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
2994
3069
|
try {
|
|
2995
3070
|
if (!__classPrivateFieldGet(this, _AirService_credentialsInitialization, "f"))
|
|
@@ -2999,11 +3074,11 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
2999
3074
|
catch (error) {
|
|
3000
3075
|
__classPrivateFieldSet(this, _AirService_credentialsInitialization, null, "f");
|
|
3001
3076
|
log.error("Error ensuring credentials", error);
|
|
3002
|
-
throw error;
|
|
3077
|
+
throw AirServiceError.from(error);
|
|
3003
3078
|
}
|
|
3004
3079
|
}, _AirService_initializeCredentials = async function _AirService_initializeCredentials() {
|
|
3005
3080
|
if (__classPrivateFieldGet(this, _AirService_credentialsInitialization, "f")) {
|
|
3006
|
-
throw new
|
|
3081
|
+
throw new AirServiceError("ALREADY_INITIALIZING", "Already initializing credentials");
|
|
3007
3082
|
}
|
|
3008
3083
|
const { credentialUrl } = AIR_URLS[__classPrivateFieldGet(this, _AirService_buildEnv, "f")];
|
|
3009
3084
|
const credentialIframeOrigin = new URL(credentialUrl).origin;
|
|
@@ -3016,11 +3091,13 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3016
3091
|
if (ev.data === AirCredentialMessageTypes.SERVICE_STARTED) {
|
|
3017
3092
|
window.removeEventListener("message", handleCredentialMessage);
|
|
3018
3093
|
const { payload } = await __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").sendInitializationRequest({
|
|
3094
|
+
sessionId: __classPrivateFieldGet(this, _AirService_sessionId, "f"),
|
|
3019
3095
|
partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
|
|
3020
3096
|
enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
|
|
3021
3097
|
sdkVersion: airKitVersion,
|
|
3022
3098
|
partnerDAppUrl: window.location.href,
|
|
3023
3099
|
enableAutomation: this.shouldEnableAutomation(),
|
|
3100
|
+
sessionConfig: __classPrivateFieldGet(this, _AirService_sessionConfig, "f"),
|
|
3024
3101
|
});
|
|
3025
3102
|
if (payload.success === true) {
|
|
3026
3103
|
resolve();
|
|
@@ -3039,13 +3116,8 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3039
3116
|
await __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").open(__classPrivateFieldGet(this, _AirService_credentialIframeController, "f").iframeElement);
|
|
3040
3117
|
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_subscribeToCredentialEvents).call(this);
|
|
3041
3118
|
await credentialInitRequestPromise;
|
|
3042
|
-
await __classPrivateFieldGet(this,
|
|
3043
|
-
|
|
3044
|
-
log.info("[Embed] Credential auth channel initialized");
|
|
3045
|
-
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
|
|
3046
|
-
await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").initCredentialCommunication();
|
|
3047
|
-
await __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").initWalletCommunication();
|
|
3048
|
-
log.info("[Embed] Credential wallet channel initialized");
|
|
3119
|
+
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this, { skipWalletLogin: true });
|
|
3120
|
+
void __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this); // this call triggers wallet login for later usage
|
|
3049
3121
|
log.info("Credential service initialized successfully");
|
|
3050
3122
|
}
|
|
3051
3123
|
catch (error) {
|
|
@@ -3054,7 +3126,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3054
3126
|
if (closeDApp) {
|
|
3055
3127
|
window.close();
|
|
3056
3128
|
}
|
|
3057
|
-
throw error;
|
|
3129
|
+
throw AirServiceError.from(error);
|
|
3058
3130
|
}
|
|
3059
3131
|
}, _AirService_subscribeToCredentialEvents = function _AirService_subscribeToCredentialEvents() {
|
|
3060
3132
|
__classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").messages$.subscribe(async (message) => {
|
|
@@ -3076,19 +3148,10 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3076
3148
|
__classPrivateFieldGet(this, _AirService_credentialIframeController, "f").destroy();
|
|
3077
3149
|
__classPrivateFieldSet(this, _AirService_credentialIframeController, undefined, "f");
|
|
3078
3150
|
}
|
|
3079
|
-
const walletIframeElement = __classPrivateFieldGet(this, _AirService_walletIframeController, "f")?.iframeElement;
|
|
3080
|
-
if (isElement(walletIframeElement) && window.document.body.contains(walletIframeElement)) {
|
|
3081
|
-
await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").resetCredentialCommunication();
|
|
3082
|
-
}
|
|
3083
|
-
const authIframeElement = __classPrivateFieldGet(this, _AirService_authIframeController, "f")?.iframeElement;
|
|
3084
|
-
if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
|
|
3085
|
-
await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").resetCredentialCommunication();
|
|
3086
|
-
}
|
|
3087
3151
|
await __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").close();
|
|
3088
3152
|
__classPrivateFieldSet(this, _AirService_credentialsInitialization, undefined, "f");
|
|
3089
3153
|
}, _AirService_ensureWallet = async function _AirService_ensureWallet(option) {
|
|
3090
|
-
|
|
3091
|
-
throw new Error("Service not initialized");
|
|
3154
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
|
|
3092
3155
|
if (!__classPrivateFieldGet(this, _AirService_walletInitialization, "f"))
|
|
3093
3156
|
__classPrivateFieldSet(this, _AirService_walletInitialization, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_initializeWallet).call(this, option), "f");
|
|
3094
3157
|
if (__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f"))
|
|
@@ -3102,7 +3165,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3102
3165
|
catch (error) {
|
|
3103
3166
|
__classPrivateFieldSet(this, _AirService_walletInitialization, null, "f");
|
|
3104
3167
|
log.error("Error initializing wallet", error);
|
|
3105
|
-
throw error;
|
|
3168
|
+
throw AirServiceError.from(error);
|
|
3106
3169
|
}
|
|
3107
3170
|
if (__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f"))
|
|
3108
3171
|
return __classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f");
|
|
@@ -3113,7 +3176,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3113
3176
|
return __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_createWalletInitializedResult).call(this, walletLoginResult.payload);
|
|
3114
3177
|
}, _AirService_initializeWallet = async function _AirService_initializeWallet(option) {
|
|
3115
3178
|
if (__classPrivateFieldGet(this, _AirService_walletInitialization, "f"))
|
|
3116
|
-
throw new
|
|
3179
|
+
throw new AirServiceError("ALREADY_INITIALIZING", "Already initializing");
|
|
3117
3180
|
const { walletUrl } = AIR_URLS[__classPrivateFieldGet(this, _AirService_buildEnv, "f")];
|
|
3118
3181
|
const walletIframeOrigin = new URL(walletUrl).origin;
|
|
3119
3182
|
try {
|
|
@@ -3124,10 +3187,12 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3124
3187
|
if (ev.data === AirWalletMessageTypes.SERVICE_STARTED) {
|
|
3125
3188
|
window.removeEventListener("message", handleWalletMessage);
|
|
3126
3189
|
const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendInitializationRequest({
|
|
3190
|
+
sessionId: __classPrivateFieldGet(this, _AirService_sessionId, "f"),
|
|
3127
3191
|
partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
|
|
3128
3192
|
enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
|
|
3129
3193
|
sdkVersion: airKitVersion,
|
|
3130
3194
|
enableAutomation: this.shouldEnableAutomation(),
|
|
3195
|
+
sessionConfig: __classPrivateFieldGet(this, _AirService_sessionConfig, "f"),
|
|
3131
3196
|
});
|
|
3132
3197
|
if (payload.success === true) {
|
|
3133
3198
|
resolve();
|
|
@@ -3150,8 +3215,6 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3150
3215
|
if (!this.isLoggedIn && !option?.skipWalletLogin) {
|
|
3151
3216
|
await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").onLoggedIn();
|
|
3152
3217
|
}
|
|
3153
|
-
await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").initWalletCommunication();
|
|
3154
|
-
await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").initAuthCommunication(option?.skipWalletLogin ?? false);
|
|
3155
3218
|
const walletInitResult = await walletInitPromise;
|
|
3156
3219
|
if (walletInitResult.payload.success !== true) {
|
|
3157
3220
|
throw new AirServiceError(walletInitResult.payload.errorName, walletInitResult.payload.errorMessage);
|
|
@@ -3165,7 +3228,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3165
3228
|
catch (error) {
|
|
3166
3229
|
log.error("Error initializing wallet", error);
|
|
3167
3230
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
|
|
3168
|
-
throw error;
|
|
3231
|
+
throw AirServiceError.from(error);
|
|
3169
3232
|
}
|
|
3170
3233
|
}, _AirService_subscribeToWalletEvents = function _AirService_subscribeToWalletEvents() {
|
|
3171
3234
|
__classPrivateFieldGet(this, _AirService_walletMessagingService, "f").messages$.subscribe(async (msg) => {
|
|
@@ -3194,6 +3257,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3194
3257
|
const { windowController, port } = await WindowService$1.openAndInitializeWalletServiceWindow({
|
|
3195
3258
|
url: msg.payload.url,
|
|
3196
3259
|
windowId: msg.payload.windowId,
|
|
3260
|
+
sessionId: __classPrivateFieldGet(this, _AirService_sessionId, "f"),
|
|
3197
3261
|
partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
|
|
3198
3262
|
enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
|
|
3199
3263
|
sdkVersion: airKitVersion,
|
|
@@ -3212,7 +3276,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3212
3276
|
}
|
|
3213
3277
|
});
|
|
3214
3278
|
}, _AirService_triggerEventListeners = function _AirService_triggerEventListeners(data) {
|
|
3215
|
-
__classPrivateFieldGet(this,
|
|
3279
|
+
__classPrivateFieldGet(this, _AirService_airEventListener, "f").forEach((listener) => {
|
|
3216
3280
|
listener(data);
|
|
3217
3281
|
});
|
|
3218
3282
|
}, _AirService_triggerAirAuthInitialized = function _AirService_triggerAirAuthInitialized(result) {
|
|
@@ -3270,17 +3334,12 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3270
3334
|
__classPrivateFieldGet(this, _AirService_walletIframeController, "f").destroy();
|
|
3271
3335
|
__classPrivateFieldSet(this, _AirService_walletIframeController, undefined, "f");
|
|
3272
3336
|
}
|
|
3273
|
-
const authIframeElement = __classPrivateFieldGet(this, _AirService_authIframeController, "f")?.iframeElement;
|
|
3274
|
-
if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
|
|
3275
|
-
await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").resetWalletCommunication();
|
|
3276
|
-
}
|
|
3277
3337
|
// Close the message service
|
|
3278
3338
|
await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").close();
|
|
3279
3339
|
__classPrivateFieldSet(this, _AirService_walletLoggedInResult, undefined, "f");
|
|
3280
3340
|
__classPrivateFieldSet(this, _AirService_walletInitialization, undefined, "f");
|
|
3281
3341
|
}, _AirService_ensureRecovery = async function _AirService_ensureRecovery() {
|
|
3282
|
-
|
|
3283
|
-
throw new Error("Service not initialized");
|
|
3342
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
|
|
3284
3343
|
if (!__classPrivateFieldGet(this, _AirService_recoveryInitialization, "f")) {
|
|
3285
3344
|
__classPrivateFieldSet(this, _AirService_recoveryInitialization, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_initializeRecovery).call(this), "f");
|
|
3286
3345
|
}
|
|
@@ -3290,11 +3349,11 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3290
3349
|
catch (error) {
|
|
3291
3350
|
__classPrivateFieldSet(this, _AirService_recoveryInitialization, null, "f");
|
|
3292
3351
|
log.error("Error initializing recovery", error);
|
|
3293
|
-
throw error;
|
|
3352
|
+
throw AirServiceError.from(error);
|
|
3294
3353
|
}
|
|
3295
3354
|
}, _AirService_initializeRecovery = async function _AirService_initializeRecovery() {
|
|
3296
3355
|
if (__classPrivateFieldGet(this, _AirService_recoveryInitialization, "f"))
|
|
3297
|
-
throw new
|
|
3356
|
+
throw new AirServiceError("ALREADY_INITIALIZING", "Already initializing");
|
|
3298
3357
|
const { recoveryUrl } = AIR_URLS[__classPrivateFieldGet(this, _AirService_buildEnv, "f")];
|
|
3299
3358
|
const recoveryIframeOrigin = new URL(recoveryUrl).origin;
|
|
3300
3359
|
try {
|
|
@@ -3305,10 +3364,12 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3305
3364
|
if (ev.data === AirRecoveryMessageTypes.SERVICE_STARTED) {
|
|
3306
3365
|
window.removeEventListener("message", handleRecoveryMessage);
|
|
3307
3366
|
const { payload } = await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").sendInitializationRequest({
|
|
3367
|
+
sessionId: __classPrivateFieldGet(this, _AirService_sessionId, "f"),
|
|
3308
3368
|
partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
|
|
3309
3369
|
enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
|
|
3310
3370
|
sdkVersion: airKitVersion,
|
|
3311
3371
|
enableAutomation: this.shouldEnableAutomation(),
|
|
3372
|
+
sessionConfig: __classPrivateFieldGet(this, _AirService_sessionConfig, "f"),
|
|
3312
3373
|
});
|
|
3313
3374
|
if (payload.success === true) {
|
|
3314
3375
|
resolve();
|
|
@@ -3327,17 +3388,12 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3327
3388
|
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_subscribeToRecoveryEvents).call(this);
|
|
3328
3389
|
const recoveryInitPromise = __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").onInitialized();
|
|
3329
3390
|
await recoveryInitRequestPromise;
|
|
3330
|
-
await
|
|
3331
|
-
await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").initAuthCommunication();
|
|
3332
|
-
const recoveryInitResult = await recoveryInitPromise;
|
|
3333
|
-
if (recoveryInitResult.payload.success !== true) {
|
|
3334
|
-
throw new AirServiceError(recoveryInitResult.payload.errorName, recoveryInitResult.payload.errorMessage);
|
|
3335
|
-
}
|
|
3391
|
+
await recoveryInitPromise;
|
|
3336
3392
|
}
|
|
3337
3393
|
catch (error) {
|
|
3338
3394
|
log.error("Error initializing recovery", error);
|
|
3339
3395
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
|
|
3340
|
-
throw error;
|
|
3396
|
+
throw AirServiceError.from(error);
|
|
3341
3397
|
}
|
|
3342
3398
|
}, _AirService_subscribeToRecoveryEvents = function _AirService_subscribeToRecoveryEvents() {
|
|
3343
3399
|
__classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").messages$.subscribe(async (message) => {
|
|
@@ -3360,10 +3416,6 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
|
|
|
3360
3416
|
__classPrivateFieldGet(this, _AirService_recoveryIframeController, "f").destroy();
|
|
3361
3417
|
__classPrivateFieldSet(this, _AirService_recoveryIframeController, undefined, "f");
|
|
3362
3418
|
}
|
|
3363
|
-
const authIframeElement = __classPrivateFieldGet(this, _AirService_authIframeController, "f")?.iframeElement;
|
|
3364
|
-
if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
|
|
3365
|
-
await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").resetRecoveryCommunication();
|
|
3366
|
-
}
|
|
3367
3419
|
// Close the message service
|
|
3368
3420
|
await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").close();
|
|
3369
3421
|
__classPrivateFieldSet(this, _AirService_recoveryInitialization, undefined, "f");
|
|
@@ -3386,3 +3438,5 @@ exports.UnauthorizedProviderError = UnauthorizedProviderError;
|
|
|
3386
3438
|
exports.UnsupportedProviderMethodError = UnsupportedProviderMethodError;
|
|
3387
3439
|
exports.UserRejectedRequestError = UserRejectedRequestError;
|
|
3388
3440
|
exports.ensureProviderRpcError = ensureProviderRpcError;
|
|
3441
|
+
exports.mocaDevnet = mocaDevnet;
|
|
3442
|
+
exports.mocaTestnet = mocaTestnet;
|