@mocanetwork/airkit 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/airkit.cjs.js +295 -122
- package/dist/airkit.esm.js +295 -123
- package/dist/airkit.umd.js +295 -122
- package/dist/types/airService.d.ts +14 -22
- package/dist/types/authMessageService.d.ts +3 -5
- package/dist/types/common/air/error/types.d.ts +1 -1
- package/dist/types/common/air/messaging/auth.d.ts +10 -45
- package/dist/types/common/air/messaging/const.d.ts +4 -4
- package/dist/types/common/air/messaging/credential.d.ts +73 -0
- package/dist/types/common/air/messaging/messageServiceBase.d.ts +1 -1
- package/dist/types/common/air/messaging/wallet.d.ts +16 -1
- package/dist/types/credentialMessageService.d.ts +45 -0
- package/dist/types/iframeController.d.ts +7 -8
- package/dist/types/interfaces.d.ts +28 -2
- package/dist/types/walletMessageService.d.ts +3 -1
- package/package.json +1 -1
- package/dist/types/common/air/credentials/types.d.ts +0 -19
package/dist/airkit.umd.js
CHANGED
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
var version = "1.5.
|
|
104
|
+
var version = "1.5.1";
|
|
105
105
|
var airkitPackage = {
|
|
106
106
|
version: version};
|
|
107
107
|
|
|
@@ -132,8 +132,6 @@
|
|
|
132
132
|
CROSS_PARTNER_TOKEN_RESPONSE: "air_auth_cross_partner_token_response",
|
|
133
133
|
PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_partner_access_token_request",
|
|
134
134
|
PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_partner_access_token_response",
|
|
135
|
-
CREDENTIAL_SALT_REQUEST: "air_auth_credential_salt_request",
|
|
136
|
-
CREDENTIAL_SALT_RESPONSE: "air_auth_credential_salt_response",
|
|
137
135
|
LOGOUT_REQUEST: "air_auth_logout_request",
|
|
138
136
|
LOGOUT_RESPONSE: "air_auth_logout_response",
|
|
139
137
|
RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication",
|
|
@@ -143,12 +141,9 @@
|
|
|
143
141
|
START_RECOVERY_RESPONSE: "air_start_recovery_response",
|
|
144
142
|
RECOVERY_REQUEST: "air_auth_recovery_request",
|
|
145
143
|
RECOVERY_RESPONSE: "air_auth_recovery_response",
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
LINKAGE_NONCE_RESPONSE: "air_auth_linkage_nonce_response",
|
|
150
|
-
CREDENTIAL_SIGNERS_REQUEST: "air_auth_credential_signers_request",
|
|
151
|
-
CREDENTIAL_SIGNERS_RESPONSE: "air_auth_credential_signers_response"
|
|
144
|
+
INIT_CREDENTIAL_COMMUNICATION: "air_auth_init_credential_communication",
|
|
145
|
+
RESET_CREDENTIAL_COMMUNICATION: "air_auth_reset_credential_communication",
|
|
146
|
+
EXPIRED_LOGOUT_REQUEST: "air_auth_expired_logout_request"
|
|
152
147
|
};
|
|
153
148
|
|
|
154
149
|
const AirRecoveryMessageTypes = {
|
|
@@ -186,7 +181,11 @@
|
|
|
186
181
|
IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request",
|
|
187
182
|
IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
|
|
188
183
|
LOGOUT_REQUEST: "air_logout_request",
|
|
189
|
-
LOGOUT_RESPONSE: "air_logout_response"
|
|
184
|
+
LOGOUT_RESPONSE: "air_logout_response",
|
|
185
|
+
INIT_CREDENTIAL_COMMUNICATION: "air_init_credential_communication",
|
|
186
|
+
RESET_CREDENTIAL_COMMUNICATION: "air_reset_credential_communication",
|
|
187
|
+
INTERNAL_PROVIDER_REQUEST: "air_internal_provider_request",
|
|
188
|
+
INTERNAL_PROVIDER_RESPONSE: "air_internal_provider_response"
|
|
190
189
|
};
|
|
191
190
|
|
|
192
191
|
const AirWindowMessageTypes = {
|
|
@@ -575,8 +574,6 @@
|
|
|
575
574
|
level = enableLogging ? log.levels.DEBUG : log.levels.INFO;
|
|
576
575
|
} else if (environment === "uat" || environment === "sandbox") {
|
|
577
576
|
level = enableLogging ? log.levels.INFO : log.levels.WARN;
|
|
578
|
-
} else if (environment === "sandbox") {
|
|
579
|
-
level = enableLogging ? log.levels.WARN : log.levels.ERROR;
|
|
580
577
|
} else if (environment === "production") {
|
|
581
578
|
// Be cautious with enabling more than WARN in prod
|
|
582
579
|
level = enableLogging ? log.levels.WARN : log.levels.ERROR;
|
|
@@ -592,32 +589,43 @@
|
|
|
592
589
|
DEVELOPMENT: "development",
|
|
593
590
|
SANDBOX: "sandbox",
|
|
594
591
|
};
|
|
592
|
+
const IFRAME_NAME_PREFIX_SET = [
|
|
593
|
+
"air-wallet",
|
|
594
|
+
"air-recovery",
|
|
595
|
+
"air-credential",
|
|
596
|
+
"air-auth",
|
|
597
|
+
]; // order defines the z-index from highest to lowest
|
|
595
598
|
|
|
596
599
|
const AIR_URLS = {
|
|
597
600
|
[BUILD_ENV.DEVELOPMENT]: {
|
|
598
601
|
authUrl: "http://localhost:8200/auth/",
|
|
599
602
|
walletUrl: "http://localhost:8200/wallet/",
|
|
600
603
|
recoveryUrl: "http://localhost:8200/recovery/",
|
|
604
|
+
credentialUrl: "http://localhost:8200/credential/",
|
|
601
605
|
},
|
|
602
606
|
[BUILD_ENV.STAGING]: {
|
|
603
607
|
authUrl: "https://account.staging.air3.com/auth/",
|
|
604
608
|
walletUrl: "https://account.staging.air3.com/wallet/",
|
|
605
609
|
recoveryUrl: "https://account.staging.air3.com/recovery/",
|
|
610
|
+
credentialUrl: "https://account.staging.air3.com/credential/",
|
|
606
611
|
},
|
|
607
612
|
[BUILD_ENV.UAT]: {
|
|
608
613
|
authUrl: "https://account.uat.air3.com/auth/",
|
|
609
614
|
walletUrl: "https://account.uat.air3.com/wallet/",
|
|
610
615
|
recoveryUrl: "https://account.uat.air3.com/recovery/",
|
|
616
|
+
credentialUrl: "https://account.uat.air3.com/credential/",
|
|
611
617
|
},
|
|
612
618
|
[BUILD_ENV.SANDBOX]: {
|
|
613
619
|
authUrl: "https://account.sandbox.air3.com/auth/",
|
|
614
620
|
walletUrl: "https://account.sandbox.air3.com/wallet/",
|
|
615
621
|
recoveryUrl: "https://account.sandbox.air3.com/recovery/",
|
|
622
|
+
credentialUrl: "https://account.sandbox.air3.com/credential/",
|
|
616
623
|
},
|
|
617
624
|
[BUILD_ENV.PRODUCTION]: {
|
|
618
625
|
authUrl: "https://account.air3.com/auth/",
|
|
619
626
|
walletUrl: "https://account.air3.com/wallet/",
|
|
620
627
|
recoveryUrl: "https://account.air3.com/recovery/",
|
|
628
|
+
credentialUrl: "https://account.air3.com/credential/",
|
|
621
629
|
},
|
|
622
630
|
};
|
|
623
631
|
const isElement = (element) => element instanceof Element || element instanceof Document;
|
|
@@ -1656,7 +1664,7 @@
|
|
|
1656
1664
|
...WindowErrorName
|
|
1657
1665
|
};
|
|
1658
1666
|
|
|
1659
|
-
const AirClientUserErrors = ["USER_CANCELLED", "CONFIG_ERROR", "CLIENT_ERROR", "UNKNOWN_ERROR", "PERMISSION_NOT_ENABLED", "SMART_ACCOUNT_NOT_DEPLOYED"];
|
|
1667
|
+
const AirClientUserErrors = ["USER_CANCELLED", "CONFIG_ERROR", "CLIENT_ERROR", "UNKNOWN_ERROR", "PERMISSION_NOT_ENABLED", "SMART_ACCOUNT_NOT_DEPLOYED", "ACCOUNT_DELETION_PENDING"];
|
|
1660
1668
|
|
|
1661
1669
|
class AirError extends BaseError {}
|
|
1662
1670
|
new Set(AirClientUserErrors);
|
|
@@ -1927,11 +1935,8 @@
|
|
|
1927
1935
|
AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE,
|
|
1928
1936
|
AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE,
|
|
1929
1937
|
AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST,
|
|
1930
|
-
AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE,
|
|
1931
1938
|
AirAuthMessageTypes.START_RECOVERY_RESPONSE,
|
|
1932
|
-
AirAuthMessageTypes.
|
|
1933
|
-
AirAuthMessageTypes.LINKAGE_NONCE_RESPONSE,
|
|
1934
|
-
AirAuthMessageTypes.CREDENTIAL_SIGNERS_RESPONSE,
|
|
1939
|
+
AirAuthMessageTypes.EXPIRED_LOGOUT_REQUEST,
|
|
1935
1940
|
];
|
|
1936
1941
|
class AuthMessageService extends MessageServiceBase {
|
|
1937
1942
|
static create() {
|
|
@@ -2033,28 +2038,18 @@
|
|
|
2033
2038
|
await this.sendMessage({ type: AirAuthMessageTypes.START_RECOVERY_REQUEST, payload });
|
|
2034
2039
|
return response;
|
|
2035
2040
|
}
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
}
|
|
2041
|
-
async sendLinkEoaCredentialRequest(payload) {
|
|
2042
|
-
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LINK_EOA_CREDENTIAL_RESPONSE)));
|
|
2043
|
-
await this.sendMessage({ type: AirAuthMessageTypes.LINK_EOA_CREDENTIAL_REQUEST, payload });
|
|
2044
|
-
return response;
|
|
2045
|
-
}
|
|
2046
|
-
async sendCredentialSignersRequest(payload) {
|
|
2047
|
-
const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.CREDENTIAL_SIGNERS_RESPONSE)));
|
|
2041
|
+
/*
|
|
2042
|
+
* Initialize credential communication
|
|
2043
|
+
*/
|
|
2044
|
+
async initCredentialCommunication() {
|
|
2048
2045
|
await this.sendMessage({
|
|
2049
|
-
type: AirAuthMessageTypes.
|
|
2050
|
-
payload,
|
|
2046
|
+
type: AirAuthMessageTypes.INIT_CREDENTIAL_COMMUNICATION,
|
|
2051
2047
|
});
|
|
2052
|
-
return response;
|
|
2053
2048
|
}
|
|
2054
|
-
async
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2049
|
+
async resetCredentialCommunication() {
|
|
2050
|
+
await this.sendMessage({
|
|
2051
|
+
type: AirAuthMessageTypes.RESET_CREDENTIAL_COMMUNICATION,
|
|
2052
|
+
});
|
|
2058
2053
|
}
|
|
2059
2054
|
}
|
|
2060
2055
|
_a$2 = AuthMessageService;
|
|
@@ -2062,25 +2057,21 @@
|
|
|
2062
2057
|
|
|
2063
2058
|
class IframeController {
|
|
2064
2059
|
getZIndex() {
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
constructor(iframeUrl, iframeId, state) {
|
|
2060
|
+
for (let i = 0; i < IFRAME_NAME_PREFIX_SET.length; i++) {
|
|
2061
|
+
if (this.iframeId.includes(IFRAME_NAME_PREFIX_SET[i])) {
|
|
2062
|
+
return IframeController.HIGHEST_Z_INDEX - i;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
return IframeController.HIGHEST_Z_INDEX - IFRAME_NAME_PREFIX_SET.length; // Lowest z-index if no match
|
|
2066
|
+
}
|
|
2067
|
+
constructor(iframePrefix, iframeUrl, state) {
|
|
2074
2068
|
this._iframeElement = null;
|
|
2075
|
-
this.AUTH_IFRAME_Z_INDEX = "9999998";
|
|
2076
|
-
this.WALLET_IFRAME_Z_INDEX = "9999999";
|
|
2077
|
-
this.RECOVERY_IFRAME_Z_INDEX = "999999";
|
|
2078
2069
|
this.state = {
|
|
2079
|
-
...IframeController.
|
|
2070
|
+
...IframeController.DEFAULT_STATE,
|
|
2080
2071
|
...state,
|
|
2081
2072
|
};
|
|
2082
2073
|
this.iframeUrl = iframeUrl;
|
|
2083
|
-
this.iframeId =
|
|
2074
|
+
this.iframeId = `${iframePrefix}-${randomId()}`;
|
|
2084
2075
|
}
|
|
2085
2076
|
get iframeElement() {
|
|
2086
2077
|
return this._iframeElement;
|
|
@@ -2093,7 +2084,7 @@
|
|
|
2093
2084
|
iframe.allow = "publickey-credentials-get *; publickey-credentials-create *";
|
|
2094
2085
|
iframe.src = this.iframeUrl;
|
|
2095
2086
|
iframe.style.position = "fixed";
|
|
2096
|
-
iframe.style.zIndex = this.getZIndex()
|
|
2087
|
+
iframe.style.zIndex = `${this.getZIndex()}`;
|
|
2097
2088
|
iframe.style.border = "none";
|
|
2098
2089
|
iframe.style.margin = "0";
|
|
2099
2090
|
iframe.style.padding = "0";
|
|
@@ -2132,9 +2123,10 @@
|
|
|
2132
2123
|
this.iframeElement.contentWindow.postMessage(message, origin);
|
|
2133
2124
|
}
|
|
2134
2125
|
}
|
|
2135
|
-
IframeController.
|
|
2126
|
+
IframeController.DEFAULT_STATE = {
|
|
2136
2127
|
isVisible: false,
|
|
2137
2128
|
};
|
|
2129
|
+
IframeController.HIGHEST_Z_INDEX = 2147483647;
|
|
2138
2130
|
|
|
2139
2131
|
var _a$1, _RecoveryMessageService_instance;
|
|
2140
2132
|
const ALLOWED_RECOVERY_MESSAGES = Object.values(AirRecoveryMessageTypes);
|
|
@@ -2187,7 +2179,6 @@
|
|
|
2187
2179
|
AirWalletMessageTypes.CLAIM_ID_RESPONSE,
|
|
2188
2180
|
AirWalletMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE,
|
|
2189
2181
|
AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE,
|
|
2190
|
-
AirWalletMessageTypes.WALLET_INITIALIZED,
|
|
2191
2182
|
AirWalletMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST,
|
|
2192
2183
|
AirWalletMessageTypes.LOGOUT_RESPONSE,
|
|
2193
2184
|
AirWindowMessageTypes.OPEN_WINDOW_REQUEST,
|
|
@@ -2195,9 +2186,9 @@
|
|
|
2195
2186
|
];
|
|
2196
2187
|
class WalletMessageService extends MessageServiceBase {
|
|
2197
2188
|
static create() {
|
|
2198
|
-
if (__classPrivateFieldGet(this, _a, "f", _WalletMessageService_instance))
|
|
2199
|
-
|
|
2200
|
-
|
|
2189
|
+
if (!__classPrivateFieldGet(this, _a, "f", _WalletMessageService_instance)) {
|
|
2190
|
+
__classPrivateFieldSet(this, _a, new _a("Embed Service: Wallet Channel", ALLOWED_WALLET_MESSAGES), "f", _WalletMessageService_instance);
|
|
2191
|
+
}
|
|
2201
2192
|
return __classPrivateFieldGet(this, _a, "f", _WalletMessageService_instance);
|
|
2202
2193
|
}
|
|
2203
2194
|
async open(walletIframe) {
|
|
@@ -2306,6 +2297,16 @@
|
|
|
2306
2297
|
});
|
|
2307
2298
|
return response;
|
|
2308
2299
|
}
|
|
2300
|
+
async initCredentialCommunication() {
|
|
2301
|
+
await this.sendMessage({
|
|
2302
|
+
type: AirWalletMessageTypes.INIT_CREDENTIAL_COMMUNICATION,
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
async resetCredentialCommunication() {
|
|
2306
|
+
await this.sendMessage({
|
|
2307
|
+
type: AirWalletMessageTypes.RESET_CREDENTIAL_COMMUNICATION,
|
|
2308
|
+
});
|
|
2309
|
+
}
|
|
2309
2310
|
}
|
|
2310
2311
|
_a = WalletMessageService;
|
|
2311
2312
|
_WalletMessageService_instance = { value: void 0 };
|
|
@@ -2507,6 +2508,9 @@
|
|
|
2507
2508
|
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;
|
|
2508
2509
|
const airKitVersion = airkitPackage.version;
|
|
2509
2510
|
class AirService {
|
|
2511
|
+
// #credentialsInitialization?: Promise<void>;
|
|
2512
|
+
// #credentialMessagingService: CredentialMessageService;
|
|
2513
|
+
// #credentialIframeController: IframeController;
|
|
2510
2514
|
constructor({ partnerId }) {
|
|
2511
2515
|
_AirService_instances.add(this);
|
|
2512
2516
|
_AirService_loginResult.set(this, void 0);
|
|
@@ -2530,6 +2534,7 @@
|
|
|
2530
2534
|
__classPrivateFieldSet(this, _AirService_authMessagingService, AuthMessageService.create(), "f");
|
|
2531
2535
|
__classPrivateFieldSet(this, _AirService_walletMessagingService, WalletMessageService.create(), "f");
|
|
2532
2536
|
__classPrivateFieldSet(this, _AirService_recoveryMessagingService, RecoveryMessageService.create(), "f");
|
|
2537
|
+
// this.#credentialMessagingService = CredentialMessageService.create();
|
|
2533
2538
|
__classPrivateFieldSet(this, _AirService_airWalletProvider, new AirWalletProvider({
|
|
2534
2539
|
isWalletInitialized: () => this.isWalletInitialized,
|
|
2535
2540
|
ensureWallet: __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).bind(this),
|
|
@@ -2573,7 +2578,7 @@
|
|
|
2573
2578
|
const { authUrl } = AIR_URLS[buildEnv];
|
|
2574
2579
|
configureLogLevel(buildEnv, enableLogging);
|
|
2575
2580
|
const authIframeOrigin = new URL(authUrl).origin;
|
|
2576
|
-
__classPrivateFieldSet(this, _AirService_authIframeController, new IframeController(
|
|
2581
|
+
__classPrivateFieldSet(this, _AirService_authIframeController, new IframeController("air-auth", authUrl), "f");
|
|
2577
2582
|
try {
|
|
2578
2583
|
__classPrivateFieldGet(this, _AirService_authIframeController, "f").createIframe();
|
|
2579
2584
|
log.info(authUrl, "url loaded");
|
|
@@ -2608,6 +2613,10 @@
|
|
|
2608
2613
|
}
|
|
2609
2614
|
break;
|
|
2610
2615
|
}
|
|
2616
|
+
case AirAuthMessageTypes.EXPIRED_LOGOUT_REQUEST: {
|
|
2617
|
+
await this.logout();
|
|
2618
|
+
break;
|
|
2619
|
+
}
|
|
2611
2620
|
}
|
|
2612
2621
|
});
|
|
2613
2622
|
const result = await new Promise((resolve, reject) => {
|
|
@@ -2704,65 +2713,6 @@
|
|
|
2704
2713
|
throw AirServiceError.from(error);
|
|
2705
2714
|
}
|
|
2706
2715
|
}
|
|
2707
|
-
/**
|
|
2708
|
-
* @experimental This method is experimental and will change in the future.
|
|
2709
|
-
*/
|
|
2710
|
-
async getCredentialSalt() {
|
|
2711
|
-
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2712
|
-
throw new Error("Service is not initialized");
|
|
2713
|
-
if (!this.isLoggedIn)
|
|
2714
|
-
throw new Error("No active session to get partner access token");
|
|
2715
|
-
const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendCredentialSaltRequest();
|
|
2716
|
-
if (result.payload.success === false) {
|
|
2717
|
-
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2718
|
-
}
|
|
2719
|
-
return {
|
|
2720
|
-
credentialSalt: result.payload.credentialSalt,
|
|
2721
|
-
};
|
|
2722
|
-
}
|
|
2723
|
-
/**
|
|
2724
|
-
* @experimental This method is experimental and will change in the future.
|
|
2725
|
-
*/
|
|
2726
|
-
async getLinkageNonce(payload) {
|
|
2727
|
-
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2728
|
-
throw new Error("Service is not initialized");
|
|
2729
|
-
if (!this.isLoggedIn)
|
|
2730
|
-
throw new Error("No active session to get nonce");
|
|
2731
|
-
const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendLinkageNonceRequest(payload);
|
|
2732
|
-
if (result.payload.success === false) {
|
|
2733
|
-
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2734
|
-
}
|
|
2735
|
-
return {
|
|
2736
|
-
nonce: result.payload.nonce,
|
|
2737
|
-
};
|
|
2738
|
-
}
|
|
2739
|
-
/**
|
|
2740
|
-
* @experimental This method is experimental and will change in the future.
|
|
2741
|
-
*/
|
|
2742
|
-
async retrieveCredentialSigners(payload) {
|
|
2743
|
-
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2744
|
-
throw new Error("Service is not initialized");
|
|
2745
|
-
if (!this.isLoggedIn)
|
|
2746
|
-
throw new Error("No active session to retrieve EOA credential");
|
|
2747
|
-
const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendCredentialSignersRequest(payload);
|
|
2748
|
-
if (result.payload.success === false) {
|
|
2749
|
-
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2750
|
-
}
|
|
2751
|
-
return result.payload.credentials;
|
|
2752
|
-
}
|
|
2753
|
-
/**
|
|
2754
|
-
* @experimental This method is experimental and will change in the future.
|
|
2755
|
-
*/
|
|
2756
|
-
async linkEoaCredential(payload) {
|
|
2757
|
-
if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
|
|
2758
|
-
throw new Error("Service is not initialized");
|
|
2759
|
-
if (!this.isLoggedIn)
|
|
2760
|
-
throw new Error("No active session to link EOA credential");
|
|
2761
|
-
const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendLinkEoaCredentialRequest(payload);
|
|
2762
|
-
if (result.payload.success === false) {
|
|
2763
|
-
throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2766
2716
|
getProvider() {
|
|
2767
2717
|
return this.provider;
|
|
2768
2718
|
}
|
|
@@ -2874,9 +2824,13 @@
|
|
|
2874
2824
|
throw new Error("Service is not initialized");
|
|
2875
2825
|
if (!this.isLoggedIn)
|
|
2876
2826
|
throw new Error("No active session to logout");
|
|
2877
|
-
// Clear up wallet
|
|
2878
|
-
await
|
|
2879
|
-
await
|
|
2827
|
+
// Clear up credentials first to avoid issues with wallet and auth messaging services
|
|
2828
|
+
// await this.#cleanUpCredential();
|
|
2829
|
+
await Promise.all([
|
|
2830
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this),
|
|
2831
|
+
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this),
|
|
2832
|
+
__classPrivateFieldGet(this, _AirService_authMessagingService, "f").logout(),
|
|
2833
|
+
]);
|
|
2880
2834
|
__classPrivateFieldSet(this, _AirService_loginResult, undefined, "f");
|
|
2881
2835
|
__classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthLoggedOut).call(this);
|
|
2882
2836
|
}
|
|
@@ -2884,8 +2838,22 @@
|
|
|
2884
2838
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
|
|
2885
2839
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpAuth).call(this);
|
|
2886
2840
|
await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
|
|
2841
|
+
// await this.#cleanUpCredential();
|
|
2887
2842
|
this.clearEventListeners();
|
|
2888
2843
|
}
|
|
2844
|
+
/**
|
|
2845
|
+
* Register an event listener for Air service events.
|
|
2846
|
+
*
|
|
2847
|
+
* Available events:
|
|
2848
|
+
* - "initialized": Service initialization completed
|
|
2849
|
+
* - "logged_in": User successfully logged in
|
|
2850
|
+
* - "logged_out": User logged out
|
|
2851
|
+
* - "wallet_initialized": Wallet initialization completed
|
|
2852
|
+
* - "credential_issuance_finished": Credential issuance finished (success or failure)
|
|
2853
|
+
* - "credential_verification_finished": Credential verification finished (success or failure)
|
|
2854
|
+
*
|
|
2855
|
+
* @param listener The event listener function
|
|
2856
|
+
*/
|
|
2889
2857
|
on(listener) {
|
|
2890
2858
|
if (__classPrivateFieldGet(this, _AirService_airAuthListener, "f").indexOf(listener) < 0)
|
|
2891
2859
|
__classPrivateFieldGet(this, _AirService_airAuthListener, "f").push(listener);
|
|
@@ -2898,7 +2866,211 @@
|
|
|
2898
2866
|
__classPrivateFieldSet(this, _AirService_airAuthListener, [], "f");
|
|
2899
2867
|
}
|
|
2900
2868
|
}
|
|
2901
|
-
_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 =
|
|
2869
|
+
_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 =
|
|
2870
|
+
// /**
|
|
2871
|
+
// * Issue a credential using the credential SDK
|
|
2872
|
+
// * @param claimRequest The claim request containing credential details
|
|
2873
|
+
// * @param projectName The name of the project
|
|
2874
|
+
// * @param options Optional configuration for the credential widget
|
|
2875
|
+
// */
|
|
2876
|
+
// public async issueCredential(
|
|
2877
|
+
// claimRequest: {
|
|
2878
|
+
// process: "Issue";
|
|
2879
|
+
// issuerDid: string;
|
|
2880
|
+
// issuerAuth: string;
|
|
2881
|
+
// credentialId: string;
|
|
2882
|
+
// credentialSubject: Record<string, unknown>;
|
|
2883
|
+
// },
|
|
2884
|
+
// projectName: string,
|
|
2885
|
+
// options?: {
|
|
2886
|
+
// endpoint?: string;
|
|
2887
|
+
// theme?: "auto" | "light" | "dark";
|
|
2888
|
+
// locale?: "en" | "zh-hk";
|
|
2889
|
+
// }
|
|
2890
|
+
// ): Promise<Record<string, never>> {
|
|
2891
|
+
// await this.#ensureCredentials();
|
|
2892
|
+
// try {
|
|
2893
|
+
// const { payload } = await this.#credentialMessagingService.sendIssueCredentialRequest({
|
|
2894
|
+
// claimRequest,
|
|
2895
|
+
// projectName,
|
|
2896
|
+
// options: options || {},
|
|
2897
|
+
// });
|
|
2898
|
+
//
|
|
2899
|
+
// return payload;
|
|
2900
|
+
// } catch (error) {
|
|
2901
|
+
// throw AirServiceError.from(error);
|
|
2902
|
+
// }
|
|
2903
|
+
// }
|
|
2904
|
+
//
|
|
2905
|
+
// /**
|
|
2906
|
+
// * Verify a credential using the credential SDK
|
|
2907
|
+
// * @param queryRequest The query request containing verification details
|
|
2908
|
+
// * @param projectName The name of the project
|
|
2909
|
+
// * @param options Optional configuration for the credential widget
|
|
2910
|
+
// */
|
|
2911
|
+
// public async verifyCredential(
|
|
2912
|
+
// queryRequest: {
|
|
2913
|
+
// process: "Verify";
|
|
2914
|
+
// verifierAuth: string;
|
|
2915
|
+
// programId: string;
|
|
2916
|
+
// },
|
|
2917
|
+
// projectName: string,
|
|
2918
|
+
// options?: {
|
|
2919
|
+
// endpoint?: string;
|
|
2920
|
+
// theme?: "auto" | "light" | "dark";
|
|
2921
|
+
// locale?: "en" | "zh-hk";
|
|
2922
|
+
// }
|
|
2923
|
+
// ): Promise<{
|
|
2924
|
+
// verificationResults: {
|
|
2925
|
+
// status:
|
|
2926
|
+
// | "Compliant"
|
|
2927
|
+
// | "Non-Compliant"
|
|
2928
|
+
// | "Pending"
|
|
2929
|
+
// | "Revoking"
|
|
2930
|
+
// | "Revoked"
|
|
2931
|
+
// | "Expired"
|
|
2932
|
+
// | "NotFound";
|
|
2933
|
+
// };
|
|
2934
|
+
// }> {
|
|
2935
|
+
// await this.#ensureCredentials();
|
|
2936
|
+
//
|
|
2937
|
+
// try {
|
|
2938
|
+
// const { payload } = await this.#credentialMessagingService.sendVerifyCredentialRequest({
|
|
2939
|
+
// queryRequest,
|
|
2940
|
+
// projectName,
|
|
2941
|
+
// options: options || {},
|
|
2942
|
+
// });
|
|
2943
|
+
//
|
|
2944
|
+
// return payload;
|
|
2945
|
+
// } catch (error) {
|
|
2946
|
+
// throw AirServiceError.from(error);
|
|
2947
|
+
// }
|
|
2948
|
+
// }
|
|
2949
|
+
// async #ensureCredentials(): Promise<void> {
|
|
2950
|
+
// if (!this.isInitialized) throw new Error("Service not initialized");
|
|
2951
|
+
// if (!this.isLoggedIn) throw new Error("User not logged in");
|
|
2952
|
+
// void this.#ensureWallet();
|
|
2953
|
+
//
|
|
2954
|
+
// try {
|
|
2955
|
+
// if (!this.#credentialsInitialization)
|
|
2956
|
+
// this.#credentialsInitialization = this.#initializeCredentials();
|
|
2957
|
+
// await this.#credentialsInitialization;
|
|
2958
|
+
// } catch (error) {
|
|
2959
|
+
// this.#credentialsInitialization = null;
|
|
2960
|
+
// log.error("Error ensuring credentials", error);
|
|
2961
|
+
// throw error;
|
|
2962
|
+
// }
|
|
2963
|
+
// }
|
|
2964
|
+
// async #initializeCredentials(): Promise<void> {
|
|
2965
|
+
// if (this.#credentialsInitialization) {
|
|
2966
|
+
// throw new Error("Already initializing credentials");
|
|
2967
|
+
// }
|
|
2968
|
+
// const { credentialUrl } = AIR_URLS[this.#buildEnv];
|
|
2969
|
+
// const credentailIframeOrigin = new URL(credentialUrl).origin;
|
|
2970
|
+
// try {
|
|
2971
|
+
// const credentialInitRequestPromise = new Promise<void>((resolve, reject) => {
|
|
2972
|
+
// const handleCredentialMessage = async (ev: MessageEvent) => {
|
|
2973
|
+
// if (ev.origin !== credentailIframeOrigin) return;
|
|
2974
|
+
// if (ev.data === AirCredentialMessageTypes.SERVICE_STARTED) {
|
|
2975
|
+
// window.removeEventListener("message", handleCredentialMessage);
|
|
2976
|
+
// const { payload } = await this.#credentialMessagingService.sendInitializationRequest({
|
|
2977
|
+
// partnerId: this.#partnerId,
|
|
2978
|
+
// enableLogging: this.#enableLogging,
|
|
2979
|
+
// sdkVersion: airKitVersion,
|
|
2980
|
+
// enableAutomation: this.shouldEnableAutomation(),
|
|
2981
|
+
// });
|
|
2982
|
+
// if (payload.success === true) {
|
|
2983
|
+
// resolve();
|
|
2984
|
+
// } else {
|
|
2985
|
+
// reject(new AirServiceError(payload.errorName, payload.errorMessage));
|
|
2986
|
+
// }
|
|
2987
|
+
// }
|
|
2988
|
+
// };
|
|
2989
|
+
// window.addEventListener("message", handleCredentialMessage);
|
|
2990
|
+
// });
|
|
2991
|
+
// this.#credentialIframeController = new IframeController("air-credential", credentialUrl);
|
|
2992
|
+
// this.#credentialIframeController.createIframe();
|
|
2993
|
+
// log.info(credentialUrl, "url loaded");
|
|
2994
|
+
//
|
|
2995
|
+
// await this.#credentialMessagingService.open(this.#credentialIframeController.iframeElement);
|
|
2996
|
+
// this.#subscribeToCredentialEvents();
|
|
2997
|
+
// await credentialInitRequestPromise;
|
|
2998
|
+
//
|
|
2999
|
+
// await this.#authMessagingService.initCredentialCommunication();
|
|
3000
|
+
// await this.#credentialMessagingService.initAuthCommunication();
|
|
3001
|
+
// log.info("[Embed] Credential auth channel initialized");
|
|
3002
|
+
//
|
|
3003
|
+
// await this.#ensureWallet();
|
|
3004
|
+
// await this.#walletMessagingService.initCredentialCommunication();
|
|
3005
|
+
// await this.#credentialMessagingService.initWalletCommunication();
|
|
3006
|
+
// log.info("[Embed] Credential wallet channel initialized");
|
|
3007
|
+
//
|
|
3008
|
+
// log.info("Credential service initialized successfully");
|
|
3009
|
+
// } catch (error) {
|
|
3010
|
+
// log.error("Error initializing credentials", error);
|
|
3011
|
+
// await this.#cleanUpCredential();
|
|
3012
|
+
// throw error;
|
|
3013
|
+
// }
|
|
3014
|
+
// }
|
|
3015
|
+
// #subscribeToCredentialEvents() {
|
|
3016
|
+
// this.#credentialMessagingService.messages$.subscribe(async (message: AirCredentialMessage) => {
|
|
3017
|
+
// switch (message.type) {
|
|
3018
|
+
// case AirCredentialMessageTypes.CREDENTIAL_IFRAME_VISIBILITY_REQUEST: {
|
|
3019
|
+
// this.#credentialIframeController.setIframeVisibility(message.payload.visible);
|
|
3020
|
+
// this.#credentialIframeController.updateIframeState();
|
|
3021
|
+
// break;
|
|
3022
|
+
// }
|
|
3023
|
+
// case AirCredentialMessageTypes.ISSUE_CREDENTIAL_RESPONSE: {
|
|
3024
|
+
// // Trigger general event for issue credential completion
|
|
3025
|
+
// this.#triggerEventListeners({
|
|
3026
|
+
// event: "credential_issuance_finished",
|
|
3027
|
+
// data: {
|
|
3028
|
+
// success: true,
|
|
3029
|
+
// },
|
|
3030
|
+
// });
|
|
3031
|
+
// break;
|
|
3032
|
+
// }
|
|
3033
|
+
// case AirCredentialMessageTypes.VERIFY_CREDENTIAL_RESPONSE: {
|
|
3034
|
+
// // Trigger general event for verify credential completion
|
|
3035
|
+
// this.#triggerEventListeners({
|
|
3036
|
+
// event: "credential_verification_finished",
|
|
3037
|
+
// data: {
|
|
3038
|
+
// success: true,
|
|
3039
|
+
// verificationResults: message.payload.verificationResults,
|
|
3040
|
+
// },
|
|
3041
|
+
// });
|
|
3042
|
+
// break;
|
|
3043
|
+
// }
|
|
3044
|
+
// }
|
|
3045
|
+
// });
|
|
3046
|
+
// }
|
|
3047
|
+
// async #cleanUpCredential(): Promise<void> {
|
|
3048
|
+
// if (!this.#isAuthInitialized) return;
|
|
3049
|
+
//
|
|
3050
|
+
// const credentialIframeElement = this.#credentialIframeController?.iframeElement;
|
|
3051
|
+
// if (
|
|
3052
|
+
// isElement(credentialIframeElement) &&
|
|
3053
|
+
// window.document.body.contains(credentialIframeElement)
|
|
3054
|
+
// ) {
|
|
3055
|
+
// await this.#credentialMessagingService.logout();
|
|
3056
|
+
// this.#credentialIframeController.destroy();
|
|
3057
|
+
// this.#credentialIframeController = undefined;
|
|
3058
|
+
// }
|
|
3059
|
+
//
|
|
3060
|
+
// const walletIframeElement = this.#walletIframeController?.iframeElement;
|
|
3061
|
+
// if (isElement(walletIframeElement) && window.document.body.contains(walletIframeElement)) {
|
|
3062
|
+
// await this.#walletMessagingService.resetCredentialCommunication();
|
|
3063
|
+
// }
|
|
3064
|
+
//
|
|
3065
|
+
// const authIframeElement = this.#authIframeController?.iframeElement;
|
|
3066
|
+
// if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
|
|
3067
|
+
// await this.#authMessagingService.resetCredentialCommunication();
|
|
3068
|
+
// }
|
|
3069
|
+
//
|
|
3070
|
+
// await this.#credentialMessagingService.close();
|
|
3071
|
+
// this.#credentialsInitialization = undefined;
|
|
3072
|
+
// }
|
|
3073
|
+
async function _AirService_ensureWallet(option) {
|
|
2902
3074
|
if (!this.isInitialized)
|
|
2903
3075
|
throw new Error("Service not initialized");
|
|
2904
3076
|
if (!this.isLoggedIn && !option?.skipWalletLogin)
|
|
@@ -2953,7 +3125,7 @@
|
|
|
2953
3125
|
};
|
|
2954
3126
|
window.addEventListener("message", handleWalletMessage);
|
|
2955
3127
|
});
|
|
2956
|
-
__classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController(
|
|
3128
|
+
__classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController("air-wallet", walletUrl), "f");
|
|
2957
3129
|
__classPrivateFieldGet(this, _AirService_walletIframeController, "f").createIframe();
|
|
2958
3130
|
log.info(walletUrl, "url loaded");
|
|
2959
3131
|
await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").open(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
|
|
@@ -3131,7 +3303,7 @@
|
|
|
3131
3303
|
};
|
|
3132
3304
|
window.addEventListener("message", handleRecoveryMessage);
|
|
3133
3305
|
});
|
|
3134
|
-
__classPrivateFieldSet(this, _AirService_recoveryIframeController, new IframeController(
|
|
3306
|
+
__classPrivateFieldSet(this, _AirService_recoveryIframeController, new IframeController("air-recovery", recoveryUrl), "f");
|
|
3135
3307
|
__classPrivateFieldGet(this, _AirService_recoveryIframeController, "f").createIframe();
|
|
3136
3308
|
log.info(recoveryUrl, "url loaded");
|
|
3137
3309
|
await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").open(__classPrivateFieldGet(this, _AirService_recoveryIframeController, "f").iframeElement);
|
|
@@ -3184,6 +3356,7 @@
|
|
|
3184
3356
|
exports.AirServiceError = AirServiceError;
|
|
3185
3357
|
exports.BUILD_ENV = BUILD_ENV;
|
|
3186
3358
|
exports.ChainDisconnectedError = ChainDisconnectedError;
|
|
3359
|
+
exports.IFRAME_NAME_PREFIX_SET = IFRAME_NAME_PREFIX_SET;
|
|
3187
3360
|
exports.InternalRpcError = InternalRpcError;
|
|
3188
3361
|
exports.InvalidParamsRpcError = InvalidParamsRpcError;
|
|
3189
3362
|
exports.InvalidRequestRpcError = InvalidRequestRpcError;
|