@mocanetwork/airkit 0.5.0-beta.2

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.
Files changed (80) hide show
  1. package/README.md +177 -0
  2. package/dist/airkit.cjs.js +2662 -0
  3. package/dist/airkit.esm.js +2468 -0
  4. package/dist/airkit.umd.min.js +2 -0
  5. package/dist/airkit.umd.min.js.LICENSE.txt +12 -0
  6. package/dist/lib.cjs/common/src/error.js +25 -0
  7. package/dist/lib.cjs/common/src/realm/messaging/auth.js +28 -0
  8. package/dist/lib.cjs/common/src/realm/messaging/types.js +15 -0
  9. package/dist/lib.cjs/ws-embed/src/PopupHandler.js +64 -0
  10. package/dist/lib.cjs/ws-embed/src/airService.js +364 -0
  11. package/dist/lib.cjs/ws-embed/src/baseProvider.js +178 -0
  12. package/dist/lib.cjs/ws-embed/src/communicationProvider.js +346 -0
  13. package/dist/lib.cjs/ws-embed/src/embed.js +735 -0
  14. package/dist/lib.cjs/ws-embed/src/error.js +21 -0
  15. package/dist/lib.cjs/ws-embed/src/iframeController.js +68 -0
  16. package/dist/lib.cjs/ws-embed/src/inPageProvider.js +307 -0
  17. package/dist/lib.cjs/ws-embed/src/index.js +20 -0
  18. package/dist/lib.cjs/ws-embed/src/interfaces.js +29 -0
  19. package/dist/lib.cjs/ws-embed/src/isStream.js +20 -0
  20. package/dist/lib.cjs/ws-embed/src/loglevel.js +7 -0
  21. package/dist/lib.cjs/ws-embed/src/messageService.js +212 -0
  22. package/dist/lib.cjs/ws-embed/src/messages.js +22 -0
  23. package/dist/lib.cjs/ws-embed/src/siteMetadata.js +77 -0
  24. package/dist/lib.cjs/ws-embed/src/utils.js +95 -0
  25. package/dist/lib.esm/common/src/error.js +23 -0
  26. package/dist/lib.esm/common/src/realm/messaging/auth.js +26 -0
  27. package/dist/lib.esm/common/src/realm/messaging/types.js +13 -0
  28. package/dist/lib.esm/ws-embed/src/PopupHandler.js +62 -0
  29. package/dist/lib.esm/ws-embed/src/airService.js +362 -0
  30. package/dist/lib.esm/ws-embed/src/baseProvider.js +176 -0
  31. package/dist/lib.esm/ws-embed/src/communicationProvider.js +344 -0
  32. package/dist/lib.esm/ws-embed/src/embed.js +730 -0
  33. package/dist/lib.esm/ws-embed/src/error.js +18 -0
  34. package/dist/lib.esm/ws-embed/src/iframeController.js +66 -0
  35. package/dist/lib.esm/ws-embed/src/inPageProvider.js +302 -0
  36. package/dist/lib.esm/ws-embed/src/index.js +5 -0
  37. package/dist/lib.esm/ws-embed/src/interfaces.js +21 -0
  38. package/dist/lib.esm/ws-embed/src/isStream.js +15 -0
  39. package/dist/lib.esm/ws-embed/src/loglevel.js +5 -0
  40. package/dist/lib.esm/ws-embed/src/messageService.js +210 -0
  41. package/dist/lib.esm/ws-embed/src/messages.js +20 -0
  42. package/dist/lib.esm/ws-embed/src/siteMetadata.js +75 -0
  43. package/dist/lib.esm/ws-embed/src/utils.js +88 -0
  44. package/dist/types/PopupHandler.d.ts +24 -0
  45. package/dist/types/airService.d.ts +34 -0
  46. package/dist/types/baseProvider.d.ts +66 -0
  47. package/dist/types/common/custom.d.ts +4 -0
  48. package/dist/types/common/error.d.ts +17 -0
  49. package/dist/types/common/realm/error/auth.d.ts +1 -0
  50. package/dist/types/common/realm/error/types.d.ts +1 -0
  51. package/dist/types/common/realm/messaging/auth.d.ts +138 -0
  52. package/dist/types/common/realm/messaging/types.d.ts +95 -0
  53. package/dist/types/common/realm/partner/config.d.ts +68 -0
  54. package/dist/types/common/realm/user/types.d.ts +78 -0
  55. package/dist/types/common/realm/wallet/bybit/bybit.d.ts +2 -0
  56. package/dist/types/common/realm/wallet/coinbase/coinbase.d.ts +2 -0
  57. package/dist/types/common/realm/wallet/cryptoCom/cryptoCom.d.ts +2 -0
  58. package/dist/types/common/realm/wallet/index.d.ts +22 -0
  59. package/dist/types/common/realm/wallet/metamask/metamask.d.ts +2 -0
  60. package/dist/types/common/realm/wallet/okx/okx.d.ts +2 -0
  61. package/dist/types/common/realm/wallet/phantom/phantom.d.ts +2 -0
  62. package/dist/types/common/realm/wallet/rabby/rabby.d.ts +2 -0
  63. package/dist/types/common/realm/wallet/rainbow/rainbow.d.ts +2 -0
  64. package/dist/types/common/realm/wallet/trust/trust.d.ts +2 -0
  65. package/dist/types/common/types.d.ts +8 -0
  66. package/dist/types/common/utils.d.ts +2 -0
  67. package/dist/types/communicationProvider.d.ts +82 -0
  68. package/dist/types/embed.d.ts +42 -0
  69. package/dist/types/error.d.ts +9 -0
  70. package/dist/types/iframeController.d.ts +18 -0
  71. package/dist/types/inPageProvider.d.ts +106 -0
  72. package/dist/types/index.d.ts +4 -0
  73. package/dist/types/interfaces.d.ts +261 -0
  74. package/dist/types/isStream.d.ts +4 -0
  75. package/dist/types/loglevel.d.ts +3 -0
  76. package/dist/types/messageService.d.ts +51 -0
  77. package/dist/types/messages.d.ts +19 -0
  78. package/dist/types/siteMetadata.d.ts +9 -0
  79. package/dist/types/utils.d.ts +24 -0
  80. package/package.json +76 -0
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Returns whether the given image URL exists
3
+ * @param url - the url of the image
4
+ * @returns whether the image exists
5
+ */
6
+ function imgExists(url) {
7
+ return new Promise((resolve, reject) => {
8
+ try {
9
+ const img = document.createElement("img");
10
+ img.onload = () => resolve(true);
11
+ img.onerror = () => resolve(false);
12
+ img.src = url;
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ });
17
+ }
18
+
19
+ /**
20
+ * Extracts a name for the site from the DOM
21
+ */
22
+ const getSiteName = window => {
23
+ const {
24
+ document
25
+ } = window;
26
+ const siteName = document.querySelector('head > meta[property="og:site_name"]');
27
+ if (siteName) {
28
+ return siteName.content;
29
+ }
30
+ const metaTitle = document.querySelector('head > meta[name="title"]');
31
+ if (metaTitle) {
32
+ return metaTitle.content;
33
+ }
34
+ if (document.title && document.title.length > 0) {
35
+ return document.title;
36
+ }
37
+ return window.location.hostname;
38
+ };
39
+
40
+ /**
41
+ * Extracts an icon for the site from the DOM
42
+ */
43
+ async function getSiteIcon(window) {
44
+ try {
45
+ const {
46
+ document
47
+ } = window;
48
+
49
+ // Use the site's favicon if it exists
50
+ let icon = document.querySelector('head > link[rel="shortcut icon"]');
51
+ if (icon && (await imgExists(icon.href))) {
52
+ return icon.href;
53
+ }
54
+
55
+ // Search through available icons in no particular order
56
+ icon = Array.from(document.querySelectorAll('head > link[rel="icon"]')).find(_icon => Boolean(_icon.href));
57
+ if (icon && (await imgExists(icon.href))) {
58
+ return icon.href;
59
+ }
60
+ return "";
61
+ } catch (error) {
62
+ return "";
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Gets site metadata and returns it
68
+ *
69
+ */
70
+ const getSiteMetadata = async () => ({
71
+ name: getSiteName(window),
72
+ icon: await getSiteIcon(window)
73
+ });
74
+
75
+ export { getSiteMetadata as default };
@@ -0,0 +1,88 @@
1
+ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
+ import { rpcErrors } from '@web3auth/auth';
3
+ import { EMBED_BUILD_ENV } from './interfaces.js';
4
+ import log from './loglevel.js';
5
+
6
+ const AIR_URLS = {
7
+ [EMBED_BUILD_ENV.TESTING]: {
8
+ authUrl: "http://localhost:8100",
9
+ walletUrl: "https://lrc-mocaverse.web3auth.io",
10
+ logLevel: "debug"
11
+ },
12
+ [EMBED_BUILD_ENV.DEVELOPMENT]: {
13
+ authUrl: "http://localhost:8100",
14
+ walletUrl: "https://localhost:4050",
15
+ logLevel: "debug"
16
+ },
17
+ [EMBED_BUILD_ENV.STAGING]: {
18
+ authUrl: "https://login.staging.realmnetwork.io",
19
+ walletUrl: "https://account.staging.realmnetwork.io",
20
+ logLevel: "info"
21
+ },
22
+ [EMBED_BUILD_ENV.PRODUCTION]: {
23
+ authUrl: "https://login.realmnetwork.io",
24
+ walletUrl: "https://account.realmnetwork.io",
25
+ logLevel: "error"
26
+ }
27
+ };
28
+ const htmlToElement = html => {
29
+ const template = window.document.createElement("template");
30
+ const trimmedHtml = html.trim(); // Never return a text node of whitespace as the result
31
+ template.innerHTML = trimmedHtml;
32
+ return template.content.firstChild;
33
+ };
34
+ const isElement = element => element instanceof Element || element instanceof Document;
35
+
36
+ /**
37
+ * json-rpc-engine middleware that logs RPC errors and and validates req.method.
38
+ *
39
+ * @param log - The logging API to use.
40
+ * @returns json-rpc-engine middleware function
41
+ */
42
+ function createErrorMiddleware() {
43
+ return (req, res, next) => {
44
+ // json-rpc-engine will terminate the request when it notices this error
45
+ if (typeof req.method !== "string" || !req.method) {
46
+ res.error = rpcErrors.invalidRequest({
47
+ message: `The request 'method' must be a non-empty string.`,
48
+ data: _objectSpread(_objectSpread({}, req || {}), {}, {
49
+ cause: `The request 'method' must be a non-empty string.`
50
+ })
51
+ });
52
+ }
53
+ next(done => {
54
+ const {
55
+ error
56
+ } = res;
57
+ if (!error) {
58
+ return done();
59
+ }
60
+ log.error(`Ws-Embed - RPC Error: ${error.message}`, error);
61
+ return done();
62
+ });
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Logs a stream disconnection error. Emits an 'error' if given an
68
+ * EventEmitter that has listeners for the 'error' event.
69
+ *
70
+ * @param log - The logging API to use.
71
+ * @param remoteLabel - The label of the disconnected stream.
72
+ * @param error - The associated error to log.
73
+ * @param emitter - The logging API to use.
74
+ */
75
+ function logStreamDisconnectWarning(remoteLabel, error, emitter) {
76
+ let warningMsg = `Web3Auth: Lost connection to "${remoteLabel}".`;
77
+ if (error !== null && error !== void 0 && error.stack) {
78
+ warningMsg += `\n${error.stack}`;
79
+ }
80
+ log.warn(warningMsg);
81
+ if (emitter && emitter.listenerCount("error") > 0) {
82
+ emitter.emit("error", warningMsg);
83
+ }
84
+ }
85
+ const EMITTED_NOTIFICATIONS = ["eth_subscription" // per eth-json-rpc-filters/subscriptionManager
86
+ ];
87
+
88
+ export { AIR_URLS, EMITTED_NOTIFICATIONS, createErrorMiddleware, htmlToElement, isElement, logStreamDisconnectWarning };
@@ -0,0 +1,24 @@
1
+ import { SafeEventEmitter } from "@web3auth/auth";
2
+ type PopupHandlerEvents = {
3
+ close: () => void;
4
+ };
5
+ declare class PopupHandler extends SafeEventEmitter<PopupHandlerEvents> {
6
+ url: URL;
7
+ target: string;
8
+ features: string;
9
+ window: Window;
10
+ windowTimer: number;
11
+ iClosedWindow: boolean;
12
+ timeout: number;
13
+ constructor({ url, target, features, timeout }: {
14
+ url: URL;
15
+ target?: string;
16
+ features?: string;
17
+ timeout?: number;
18
+ });
19
+ _setupTimer(): void;
20
+ open(): void;
21
+ close(): void;
22
+ redirect(locationReplaceOnRedirect: boolean): void;
23
+ }
24
+ export default PopupHandler;
@@ -0,0 +1,34 @@
1
+ import AirInPageProvider from "./inPageProvider";
2
+ import { AirEmbedConnectResult, AirEmbedLoginResult, AirEventListener, AirLoginResult, AirPartnerUserDetails, AirUserDetails, ClaimAirIdOptions, EMBED_BUILD_ENV_TYPE } from "./interfaces";
3
+ declare class AirService {
4
+ #private;
5
+ constructor({ partnerId }: {
6
+ partnerId: string;
7
+ });
8
+ get buildEnv(): EMBED_BUILD_ENV_TYPE;
9
+ get isAirAuth(): boolean;
10
+ get isInitialized(): boolean;
11
+ get isLoggedIn(): boolean;
12
+ get isWalletLoaded(): boolean;
13
+ init({ buildEnv, enableLogging, skipRehydration, }: {
14
+ buildEnv: EMBED_BUILD_ENV_TYPE;
15
+ enableLogging: boolean;
16
+ skipRehydration: boolean;
17
+ }): Promise<AirLoginResult | null>;
18
+ cleanUp(): Promise<void>;
19
+ login(options?: {
20
+ authToken?: string;
21
+ }): Promise<AirLoginResult>;
22
+ deploySmartAccount(): Promise<void>;
23
+ logout(): Promise<void>;
24
+ getProvider(): Promise<AirInPageProvider>;
25
+ preloadWallet(): Promise<AirEmbedConnectResult | AirEmbedLoginResult>;
26
+ claimAirId(options?: ClaimAirIdOptions): Promise<AirEmbedLoginResult | AirEmbedConnectResult>;
27
+ getUserInfo(): Promise<AirUserDetails>;
28
+ getPartnerUserInfo(): Promise<AirPartnerUserDetails>;
29
+ on(listener: AirEventListener): void;
30
+ off(listener: AirEventListener): void;
31
+ clearEventListeners(): void;
32
+ private _showWalletWidget;
33
+ }
34
+ export default AirService;
@@ -0,0 +1,66 @@
1
+ import { JRPCEngine, JRPCRequest, ProviderEvents, RequestArguments, SafeEventEmitter, SafeEventEmitterProvider, SendCallBack } from "@web3auth/auth";
2
+ import type { Duplex } from "readable-stream";
3
+ import { BaseProviderState, Maybe, ProviderOptions, UnValidatedJsonRpcRequest } from "./interfaces";
4
+ /**
5
+ * @param connectionStream - A Node.js duplex stream
6
+ * @param opts - An options bag
7
+ */
8
+ declare abstract class BaseProvider<U extends BaseProviderState, E extends ProviderEvents = ProviderEvents> extends SafeEventEmitter<E> implements SafeEventEmitterProvider<E> {
9
+ rpcEngine: JRPCEngine;
10
+ jsonRpcConnectionEvents: SafeEventEmitter;
11
+ /**
12
+ * Indicating that this provider is a Web3Auth provider.
13
+ */
14
+ readonly isWeb3Auth: true;
15
+ protected state: U;
16
+ constructor(connectionStream: Duplex, { maxEventListeners, jsonRpcStreamName }: ProviderOptions);
17
+ /**
18
+ * Submits an RPC request for the given method, with the given params.
19
+ * Resolves with the result of the method call, or rejects on error.
20
+ *
21
+ * @param args - The RPC request arguments.
22
+ * @returns A Promise that resolves with the result of the RPC method,
23
+ * or rejects if an error is encountered.
24
+ */
25
+ request<T, P>(args: RequestArguments<T>): Promise<Maybe<P>>;
26
+ send<T, V>(req: JRPCRequest<T>, callback: SendCallBack<V>): void;
27
+ sendAsync<T, V>(req: JRPCRequest<T>): Promise<V>;
28
+ /**
29
+ * Called when connection is lost to critical streams.
30
+ *
31
+ * emits InpageProvider#disconnect
32
+ */
33
+ protected handleStreamDisconnect(streamName: string, error: Error): void;
34
+ /**
35
+ * Constructor helper.
36
+ * Populates initial state by calling 'wallet_getProviderState' and emits
37
+ * necessary events.
38
+ */
39
+ abstract initializeState(...args: unknown[]): Promise<void>;
40
+ /**
41
+ * Internal RPC method. Forwards requests to background via the RPC engine.
42
+ * Also remap ids inbound and outbound
43
+ */
44
+ protected abstract rpcRequest(payload: UnValidatedJsonRpcRequest | UnValidatedJsonRpcRequest[], callback: (...args: unknown[]) => void, isInternal?: boolean): void;
45
+ /**
46
+ * When the provider becomes connected, updates internal state and emits
47
+ * required events. Idempotent.
48
+ *
49
+ * @param chainId - The ID of the newly connected chain.
50
+ * emits InPageProvider#connect
51
+ */
52
+ protected abstract handleConnect(...args: unknown[]): void;
53
+ /**
54
+ * When the provider becomes disconnected, updates internal state and emits
55
+ * required events. Idempotent with respect to the isRecoverable parameter.
56
+ *
57
+ * Error codes per the CloseEvent status codes as required by EIP-1193:
58
+ * https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes
59
+ *
60
+ * @param isRecoverable - Whether the disconnection is recoverable.
61
+ * @param errorMessage - A custom error message.
62
+ * emits InpageProvider#disconnect
63
+ */
64
+ protected abstract handleDisconnect(isRecoverable: boolean, errorMessage?: string): void;
65
+ }
66
+ export default BaseProvider;
@@ -0,0 +1,4 @@
1
+ declare module "*.svg" {
2
+ const content: any;
3
+ export default content;
4
+ }
@@ -0,0 +1,17 @@
1
+ import { Jsonable } from "./types";
2
+ export declare class BaseError<TName extends string> extends Error {
3
+ readonly name: TName;
4
+ readonly cause?: Error;
5
+ readonly context?: Jsonable;
6
+ constructor(name: TName, message?: string, options?: {
7
+ cause?: Error;
8
+ context?: Jsonable;
9
+ });
10
+ toJSON(): {
11
+ name: TName;
12
+ message: string;
13
+ context: Jsonable;
14
+ cause: Error;
15
+ };
16
+ }
17
+ export declare function ensureError(value: unknown): Error;
@@ -0,0 +1 @@
1
+ export type AuthErrorName = "USER_CANCELLED" | "CLIENT_ERROR" | "CONFIG_ERROR" | "UNKNOWN_ERROR";
@@ -0,0 +1 @@
1
+ export type AirErrorName = "USER_CANCELLED" | "CONFIG_ERROR" | "SERVER_ERROR" | "CLIENT_ERROR" | "UNKNOWN_ERROR";
@@ -0,0 +1,138 @@
1
+ import { AuthErrorName } from "../error/auth";
2
+ import { AirErrorName } from "../error/types";
3
+ import { AirIdDetails, GlobalId } from "../user/types";
4
+ export declare const AirAuthMessageTypes: {
5
+ readonly SETUP_COMPLETED: "air_auth_setup_completed";
6
+ readonly LOGIN_REQUEST: "air_auth_login_request";
7
+ readonly LOGIN_RESPONSE: "air_auth_login_response";
8
+ readonly LOGIN_WALLET_RESPONSE: "air_auth_login_wallet_response";
9
+ readonly USER_INFO_REQUEST: "air_auth_user_info_request";
10
+ readonly USER_INFO_RESPONSE: "air_auth_user_info_response";
11
+ readonly PARTNER_USER_INFO_REQUEST: "air_auth_partner_user_info_request";
12
+ readonly PARTNER_USER_INFO_RESPONSE: "air_auth_partner_user_info_response";
13
+ readonly REFRESH_TOKEN_REQUEST: "air_auth_refresh_token_request";
14
+ readonly REFRESH_TOKEN_RESPONSE: "air_auth_refresh_token_response";
15
+ readonly WALLET_TOKEN_REQUEST: "air_auth_wallet_token_request";
16
+ readonly WALLET_TOKEN_RESPONSE: "air_auth_wallet_token_response";
17
+ readonly INITIALIZATION_REQUEST: "air_auth_initialization_request";
18
+ readonly INITIALIZATION_RESPONSE: "air_auth_initialization_response";
19
+ readonly INIT_WALLET_COMMUNICATION: "air_auth_init_wallet_communication";
20
+ readonly IFRAME_VISIBILITY_REQUEST: "air_auth_iframe_visibility_request";
21
+ readonly SETUP_WALLET_REQUEST: "air_auth_setup_wallet_request";
22
+ readonly SETUP_WALLET_RESPONSE: "air_auth_setup_wallet_response";
23
+ readonly SIGN_SIWE_MESSAGE_REQUEST: "air_auth_sign_siwe_message_request";
24
+ readonly SIGN_SIWE_MESSAGE_RESPONSE: "air_auth_sign_siwe_message_response";
25
+ readonly LOGOUT_REQUEST: "air_auth_logout_request";
26
+ readonly LOGOUT_RESPONSE: "air_auth_logout_response";
27
+ };
28
+ export type AirAuthMessageType = (typeof AirAuthMessageTypes)[keyof typeof AirAuthMessageTypes];
29
+ type AirAuthMessageBase<TType extends AirAuthMessageType, TPayload> = {
30
+ type: TType;
31
+ payload: TPayload;
32
+ };
33
+ type AirAuthMessageBaseWithoutPayload<TType extends AirAuthMessageType> = {
34
+ type: TType;
35
+ };
36
+ export type AirAuthError = {
37
+ success: false;
38
+ errorName: AuthErrorName;
39
+ errorMessage?: string;
40
+ };
41
+ export type AirAuthSuccess = {
42
+ success: true;
43
+ email?: string;
44
+ partnerAccessToken: string;
45
+ } & GlobalId;
46
+ export type AirAuthSuccessTokens = {
47
+ success: true;
48
+ accessToken: string;
49
+ partnerAccessToken: string;
50
+ };
51
+ export type AirAuthUserDetailsSuccess = {
52
+ success: true;
53
+ email?: string;
54
+ airIds: AirIdDetails[];
55
+ } & GlobalId;
56
+ export type AirAuthPartnerUserDetailsSuccess = {
57
+ success: true;
58
+ partnerId: string;
59
+ partnerUserId: string;
60
+ airId?: AirIdDetails;
61
+ };
62
+ export type AirAuthSuccessWithAirIdsAndTokens = AirAuthUserDetailsSuccess & AirAuthSuccessTokens;
63
+ type AirAuthLoginResponseToEmbedPayload = AirAuthSuccess | AirAuthError;
64
+ type AirAuthLoginResponseToWalletPayload = AirAuthSuccessWithAirIdsAndTokens | AirAuthError;
65
+ type AirAuthRefreshTokenResponsePayload = AirAuthSuccessTokens | AirAuthError;
66
+ type AirAuthUserInfoResponsePayload = AirAuthUserDetailsSuccess | AirAuthError;
67
+ type AirAuthPartnerUserInfoResponsePayload = AirAuthPartnerUserDetailsSuccess | AirAuthError;
68
+ type AirAuthWalletTokenRequestPayload = {
69
+ nonce: string;
70
+ partnerId: string;
71
+ };
72
+ type AirAuthWalletTokenResponsePayload = {
73
+ success: true;
74
+ accessToken: string;
75
+ walletToken: string;
76
+ } | AirAuthError;
77
+ type AirAuthInitializationResponsePayload = (AirAuthSuccess & {
78
+ rehydrated: true;
79
+ }) | (Pick<AirAuthSuccess, "success"> & {
80
+ rehydrated: false;
81
+ }) | AirAuthError;
82
+ type AirAuthLoginRequestPayload = {
83
+ partnerLoginToken?: string;
84
+ web3AuthJwt?: string;
85
+ };
86
+ type AirAuthSetupWalletSuccessPayload = {
87
+ success: true;
88
+ };
89
+ type AirAuthSetupWalletErrorPayload = {
90
+ success: false;
91
+ errorName: AuthErrorName;
92
+ errorMessage: string;
93
+ };
94
+ type AirAuthSetupWalletResponsePayload = AirAuthSetupWalletSuccessPayload | AirAuthSetupWalletErrorPayload;
95
+ type AirAuthSignSiweMessageRequestPayload = {
96
+ wallet: string;
97
+ };
98
+ export type AirAuthSignSiweMessageSuccessPayload = {
99
+ success: true;
100
+ address: string;
101
+ message: string;
102
+ signature: string;
103
+ };
104
+ type AirAuthSignSiweMessageErrorPayload = {
105
+ success: false;
106
+ errorName: AirErrorName;
107
+ errorMessage: string;
108
+ };
109
+ type AirAuthSignSiweMessageResponsePayload = AirAuthSignSiweMessageSuccessPayload | AirAuthSignSiweMessageErrorPayload;
110
+ export type AirAuthLoginRequestMessage = AirAuthMessageBase<"air_auth_login_request", AirAuthLoginRequestPayload>;
111
+ export type AirAuthLoginResponseToEmbedMessage = AirAuthMessageBase<"air_auth_login_response", AirAuthLoginResponseToEmbedPayload>;
112
+ export type AirAuthLoginResponseToWalletServiceMessage = AirAuthMessageBase<"air_auth_login_wallet_response", AirAuthLoginResponseToWalletPayload>;
113
+ export type AirAuthUserInfoRequestMessage = AirAuthMessageBaseWithoutPayload<"air_auth_user_info_request">;
114
+ export type AirAuthUserInfoResponseMessage = AirAuthMessageBase<"air_auth_user_info_response", AirAuthUserInfoResponsePayload>;
115
+ export type AirAuthPartnerUserInfoRequestMessage = AirAuthMessageBaseWithoutPayload<"air_auth_partner_user_info_request">;
116
+ export type AirAuthPartnerUserInfoResponseMessage = AirAuthMessageBase<"air_auth_partner_user_info_response", AirAuthPartnerUserInfoResponsePayload>;
117
+ export type AirAuthRefreshTokenRequestMessage = AirAuthMessageBaseWithoutPayload<"air_auth_refresh_token_request">;
118
+ export type AirAuthRefreshTokenResponseMessage = AirAuthMessageBase<"air_auth_refresh_token_response", AirAuthRefreshTokenResponsePayload>;
119
+ export type AirAuthWalletTokenRequestMessage = AirAuthMessageBase<"air_auth_wallet_token_request", AirAuthWalletTokenRequestPayload>;
120
+ export type AirAuthWalletTokenResponseMessage = AirAuthMessageBase<"air_auth_wallet_token_response", AirAuthWalletTokenResponsePayload>;
121
+ export type AirAuthInitializationResponseMessage = AirAuthMessageBase<"air_auth_initialization_response", AirAuthInitializationResponsePayload>;
122
+ export type AirAuthInitializationRequestMessage = AirAuthMessageBase<"air_auth_initialization_request", {
123
+ partnerId: string;
124
+ skipRehydration?: boolean;
125
+ }>;
126
+ export type AirAuthSetupCompletedMessage = AirAuthMessageBaseWithoutPayload<"air_auth_setup_completed">;
127
+ export type AirAuthInitWalletCommunicationMessage = AirAuthMessageBaseWithoutPayload<"air_auth_init_wallet_communication">;
128
+ export type AirAuthSetupWalletRequestMessage = AirAuthMessageBaseWithoutPayload<"air_auth_setup_wallet_request">;
129
+ export type AirAuthSetupWalletResponseMessage = AirAuthMessageBase<"air_auth_setup_wallet_response", AirAuthSetupWalletResponsePayload>;
130
+ export type AirAuthSignSiweMessageRequestMessage = AirAuthMessageBase<"air_auth_sign_siwe_message_request", AirAuthSignSiweMessageRequestPayload>;
131
+ export type AirAuthSignSiweMessageResponseMessage = AirAuthMessageBase<"air_auth_sign_siwe_message_response", AirAuthSignSiweMessageResponsePayload>;
132
+ export type AirAuthLogoutRequestMessage = AirAuthMessageBaseWithoutPayload<"air_auth_logout_request">;
133
+ export type AirAuthLogoutResponseMessage = AirAuthMessageBaseWithoutPayload<"air_auth_logout_response">;
134
+ export type AirAuthIframeVisibilityRequestMessage = AirAuthMessageBase<"air_auth_iframe_visibility_request", {
135
+ visible: boolean;
136
+ }>;
137
+ export type AirAuthMessage = AirAuthSetupCompletedMessage | AirAuthInitializationRequestMessage | AirAuthInitializationResponseMessage | AirAuthLoginRequestMessage | AirAuthLoginResponseToEmbedMessage | AirAuthLoginResponseToWalletServiceMessage | AirAuthUserInfoRequestMessage | AirAuthUserInfoResponseMessage | AirAuthPartnerUserInfoRequestMessage | AirAuthPartnerUserInfoResponseMessage | AirAuthRefreshTokenRequestMessage | AirAuthRefreshTokenResponseMessage | AirAuthWalletTokenRequestMessage | AirAuthWalletTokenResponseMessage | AirAuthInitWalletCommunicationMessage | AirAuthSetupWalletRequestMessage | AirAuthSetupWalletResponseMessage | AirAuthSignSiweMessageRequestMessage | AirAuthSignSiweMessageResponseMessage | AirAuthLogoutRequestMessage | AirAuthLogoutResponseMessage | AirAuthIframeVisibilityRequestMessage;
138
+ export {};
@@ -0,0 +1,95 @@
1
+ import { AirErrorName } from "../error/types";
2
+ export declare const AirMessageTypes: {
3
+ readonly SERVICE_INITIALIZED: "air_service_initialized";
4
+ readonly SERVICE_INITIALIZED_ERROR: "air_service_initialized_error";
5
+ readonly LOGIN_REQUEST: "air_login_request";
6
+ readonly CLAIM_REQUEST: "air_claim_request";
7
+ readonly LOGIN_CLAIM_STATE: "air_login_claim_state";
8
+ readonly CLOSE_MODAL: "air_close_modal";
9
+ readonly INIT_AUTH_COMMUNICATION: "air_init_auth_communication";
10
+ readonly DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request";
11
+ readonly DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response";
12
+ };
13
+ export declare const AirLoginClaimStates: {
14
+ readonly CONNECTED: "connected";
15
+ readonly LOGGED_IN: "logged_in";
16
+ readonly CLAIM_FLOW_STARTED: "claim_flow_started";
17
+ readonly CLAIM_FLOW_CANCELLED: "claim_flow_cancelled";
18
+ readonly MINTING_STARTED: "minting_started";
19
+ readonly MINTING_FAILED: "minting_failed";
20
+ };
21
+ export type AirRehydrationResult = "failed" | "connected" | "logged_in";
22
+ export type RealmRehydrationResult = AirRehydrationResult;
23
+ export type AirMessageType = (typeof AirMessageTypes)[keyof typeof AirMessageTypes];
24
+ type AirMessageBase<TType extends AirMessageType, TPayload> = {
25
+ type: TType;
26
+ payload: TPayload;
27
+ };
28
+ type AirMessageBaseWithoutPayload<TType extends AirMessageType> = {
29
+ type: TType;
30
+ };
31
+ export type AirServiceInitializedMessage = AirMessageBase<"air_service_initialized", {
32
+ rehydration: AirRehydrationResult;
33
+ isRehydrationSuccessful: boolean;
34
+ }>;
35
+ export type AirServiceInitializedErrorMessage = AirMessageBase<"air_service_initialized_error", {
36
+ errorName: AirErrorName;
37
+ errorMessage?: string;
38
+ }>;
39
+ export type AirLoginRequestMessage = AirMessageBase<"air_login_request", {
40
+ token?: string;
41
+ skipClaimFlow: boolean;
42
+ customAuthToken?: string;
43
+ isLegacyLogin: boolean;
44
+ }>;
45
+ export type AirClaimRequestMessage = AirMessageBase<"air_claim_request", {
46
+ token?: string;
47
+ claimInBackground?: boolean;
48
+ }>;
49
+ export type AirLoginClaimStateLoggedInMessage = {
50
+ state: typeof AirLoginClaimStates.LOGGED_IN;
51
+ addresses: {
52
+ eoa: string;
53
+ aa: string;
54
+ };
55
+ airId: string;
56
+ token: string;
57
+ sessionId?: string;
58
+ };
59
+ export type AirLoginClaimStateConnectedMessage = {
60
+ state: typeof AirLoginClaimStates.CONNECTED;
61
+ addresses?: {
62
+ eoa: string;
63
+ };
64
+ token?: string;
65
+ sessionId?: string;
66
+ };
67
+ export type AirLoginClaimStateClaimFlowStartedMessage = {
68
+ state: typeof AirLoginClaimStates.CLAIM_FLOW_STARTED;
69
+ };
70
+ export type AirLoginClaimStateClaimFlowCancelledMessage = {
71
+ state: typeof AirLoginClaimStates.CLAIM_FLOW_CANCELLED;
72
+ errorName: AirErrorName;
73
+ errorMessage?: string;
74
+ };
75
+ export type AirLoginClaimStateMintingStartedMessage = {
76
+ state: typeof AirLoginClaimStates.MINTING_STARTED;
77
+ };
78
+ export type AirLoginClaimStateMintingFailedMessage = {
79
+ state: typeof AirLoginClaimStates.MINTING_FAILED;
80
+ errorMessage?: string;
81
+ };
82
+ export type AirLoginClaimStateMessage = AirMessageBase<"air_login_claim_state", AirLoginClaimStateLoggedInMessage | AirLoginClaimStateConnectedMessage | AirLoginClaimStateClaimFlowStartedMessage | AirLoginClaimStateClaimFlowCancelledMessage | AirLoginClaimStateMintingStartedMessage | AirLoginClaimStateMintingFailedMessage>;
83
+ export type AirCloseModalMessage = AirMessageBaseWithoutPayload<"air_close_modal">;
84
+ export type AirInitAuthCommunicationMessage = AirMessageBaseWithoutPayload<"air_init_auth_communication">;
85
+ export type AirDeploySmartAccountRequestMessage = AirMessageBaseWithoutPayload<"air_deploy_smart_account_request">;
86
+ export type AirDeploySmartAccountResponseMessage = AirMessageBase<"air_deploy_smart_account_response", {
87
+ success: true;
88
+ txHash: string;
89
+ } | {
90
+ success: false;
91
+ errorMessage: string;
92
+ }>;
93
+ export type AirMessage = AirServiceInitializedMessage | AirServiceInitializedErrorMessage | AirLoginRequestMessage | AirClaimRequestMessage | AirLoginClaimStateMessage | AirCloseModalMessage | AirInitAuthCommunicationMessage | AirDeploySmartAccountRequestMessage | AirDeploySmartAccountResponseMessage;
94
+ export type AirLoginClaimStatePayload = AirLoginClaimStateMessage["payload"];
95
+ export {};
@@ -0,0 +1,68 @@
1
+ import { RealmLoginWalletId } from "../wallet";
2
+ export type RealmPartnerConfig = {
3
+ partnerId: string;
4
+ node: string;
5
+ gating: "none" | "jwt" | "invite";
6
+ apiUrl: string;
7
+ theme?: string;
8
+ chainId: string;
9
+ allowedDomains?: string[];
10
+ publicKey?: string;
11
+ jwksUrl?: string;
12
+ realmIdValidation: RealmIdValidation;
13
+ allowConnectOnly: boolean;
14
+ cyberConnectAppId?: string;
15
+ style?: RealmPartnerConfigStyle;
16
+ walletLoginMethods?: RealmLoginWalletId[];
17
+ walletSignupMethods?: RealmLoginWalletId[];
18
+ recommendedWallets?: RealmLoginWalletId[];
19
+ defaultLanguage?: string;
20
+ supportedLocales?: string[];
21
+ localeUrls?: Record<string, string>;
22
+ authLocaleUrls?: Record<string, string>;
23
+ sessionTime?: number;
24
+ customAuth?: RealmCustomAuthConfig;
25
+ allowSessionIdLogin?: boolean;
26
+ loginMethods?: RealmLoginMethod[];
27
+ };
28
+ export type RealmIdValidation = {
29
+ minLength: number;
30
+ maxLength: number;
31
+ };
32
+ export type RealmPartnerConfigStyle = {
33
+ hideCloseIcon?: boolean;
34
+ hideModalOverlay?: boolean;
35
+ };
36
+ export declare const REALM_LOGIN_PROVIDER: {
37
+ readonly REALM_CUSTOM_AUTH: "realm_custom_auth";
38
+ readonly DEMO_CUSTOM_AUTH: "demo_custom_auth";
39
+ readonly GOOGLE: "google";
40
+ readonly FACEBOOK: "facebook";
41
+ readonly REDDIT: "reddit";
42
+ readonly DISCORD: "discord";
43
+ readonly TWITCH: "twitch";
44
+ readonly APPLE: "apple";
45
+ readonly LINE: "line";
46
+ readonly GITHUB: "github";
47
+ readonly KAKAO: "kakao";
48
+ readonly LINKEDIN: "linkedin";
49
+ readonly TWITTER: "twitter";
50
+ readonly WEIBO: "weibo";
51
+ readonly WECHAT: "wechat";
52
+ readonly FARCASTER: "farcaster";
53
+ readonly EMAIL_PASSWORDLESS: "email_passwordless";
54
+ readonly SMS_PASSWORDLESS: "sms_passwordless";
55
+ readonly WEBAUTHN: "webauthn";
56
+ readonly JWT: "jwt";
57
+ readonly PASSKEYS: "passkeys";
58
+ readonly AUTHENTICATOR: "authenticator";
59
+ };
60
+ export type REALM_LOGIN_PROVIDER_TYPE = (typeof REALM_LOGIN_PROVIDER)[keyof typeof REALM_LOGIN_PROVIDER];
61
+ export type RealmCustomAuthConfig = {
62
+ name: REALM_LOGIN_PROVIDER_TYPE;
63
+ verifier: string;
64
+ verifierSubIdentifier: string;
65
+ verifierIdField: string;
66
+ };
67
+ export declare const REALM_LOGIN_METHODS: readonly ["passwordless", "passwordlessToggle", "google", "wallet", "passkey"];
68
+ export type RealmLoginMethod = (typeof REALM_LOGIN_METHODS)[number];