@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,78 @@
1
+ export type AuthCredentials = {
2
+ accessToken: string;
3
+ refreshToken: string;
4
+ partnerAccessToken: string;
5
+ };
6
+ export type RealmDetailsV1 = {
7
+ name?: string;
8
+ node: string;
9
+ status: "not_minted" | "minting" | "minted";
10
+ tokenId?: string;
11
+ imageUrl?: string;
12
+ eoaAddress?: string;
13
+ abstractAccountAddress?: string;
14
+ partnerUserId?: string;
15
+ };
16
+ export type AirIdDetails = {
17
+ id: string;
18
+ name?: string;
19
+ node: string;
20
+ status: "not_minted" | "minting" | "minted";
21
+ tokenId?: string;
22
+ imageUrl?: string;
23
+ };
24
+ export type MintTransaction = {
25
+ id: string;
26
+ transactionHash: string;
27
+ };
28
+ export type GlobalId = {
29
+ id: string;
30
+ abstractAccountAddress: string;
31
+ };
32
+ export type RealmUserV1 = {
33
+ realmId: RealmDetailsV1;
34
+ mintTransaction?: MintTransaction;
35
+ };
36
+ export type LoggedInLoginResponse = {
37
+ status: "logged_in";
38
+ } & AuthCredentials & {
39
+ user: GlobalId;
40
+ };
41
+ type PartnerLinkageRequiredLoginResponse = {
42
+ status: "partner_linkage_required";
43
+ } & AuthCredentials & {
44
+ user: GlobalId;
45
+ };
46
+ export type LoggedInLoginV1Response = {
47
+ status: "logged_in";
48
+ } & AuthCredentials & RealmUserV1;
49
+ type PartnerLinkageRequiredLoginV1Response = {
50
+ status: "partner_linkage_required";
51
+ } & AuthCredentials & RealmUserV1;
52
+ type EmailRequiredLoginResponse = {
53
+ status: "email_required";
54
+ };
55
+ type EmailVerificationRequiredLoginResponse = {
56
+ status: "email_verification_required";
57
+ email: string;
58
+ };
59
+ type LoginRequiredLoginResponse = {
60
+ status: "login_required";
61
+ };
62
+ export type LoginResponse = LoggedInLoginResponse | PartnerLinkageRequiredLoginResponse | EmailRequiredLoginResponse | EmailVerificationRequiredLoginResponse | LoginRequiredLoginResponse;
63
+ export type LoginV1Response = LoggedInLoginV1Response | PartnerLinkageRequiredLoginV1Response | EmailRequiredLoginResponse | EmailVerificationRequiredLoginResponse | LoginRequiredLoginResponse;
64
+ export type MeResponseV1 = {
65
+ realmId: RealmDetailsV1;
66
+ };
67
+ export type MeResponse = {
68
+ user: GlobalId & {
69
+ email?: string;
70
+ airIds: Omit<AirIdDetails, "id">[];
71
+ };
72
+ };
73
+ export type PartnerUserResponse = {
74
+ partnerId: string;
75
+ partnerUserId: string;
76
+ airId?: Omit<AirIdDetails, "id">;
77
+ };
78
+ export {};
@@ -0,0 +1,2 @@
1
+ import { RealmLoginWallet } from "..";
2
+ export declare const BYBIT: RealmLoginWallet;
@@ -0,0 +1,2 @@
1
+ import { RealmLoginWallet } from "..";
2
+ export declare const COINBASE: RealmLoginWallet;
@@ -0,0 +1,2 @@
1
+ import { RealmLoginWallet } from "..";
2
+ export declare const CRYPTO_COM: RealmLoginWallet;
@@ -0,0 +1,22 @@
1
+ export interface RealmLoginWallet {
2
+ id: string;
3
+ rdns: string;
4
+ name: string;
5
+ displayName?: string;
6
+ icon?: string;
7
+ downloadUrls?: Record<string, string>;
8
+ mobile?: Record<string, string>;
9
+ supportRequestPermissions: boolean;
10
+ supportMobileWalletConnectDeeplink: boolean;
11
+ }
12
+ export declare const WALLET_MAP: Record<string, RealmLoginWallet>;
13
+ export declare const WALLET_RDNS_MAP: Record<string, RealmLoginWallet>;
14
+ export type RealmLoginWalletId = keyof typeof WALLET_MAP;
15
+ export declare const DEFAULT_LOGIN_METHODS: Array<RealmLoginWalletId>;
16
+ export declare const DEFAULT_SIGNUP_METHODS: Array<RealmLoginWalletId>;
17
+ export declare const DEFAULT_RECOMMENDED_WALLETS: Array<RealmLoginWalletId>;
18
+ export type WalletToken = {
19
+ type: "wallet" | string;
20
+ partnerId: string;
21
+ nonce: string;
22
+ };
@@ -0,0 +1,2 @@
1
+ import { RealmLoginWallet } from "..";
2
+ export declare const METAMASK: RealmLoginWallet;
@@ -0,0 +1,2 @@
1
+ import { RealmLoginWallet } from "..";
2
+ export declare const OKX: RealmLoginWallet;
@@ -0,0 +1,2 @@
1
+ import { RealmLoginWallet } from "..";
2
+ export declare const PHANTOM: RealmLoginWallet;
@@ -0,0 +1,2 @@
1
+ import { RealmLoginWallet } from "..";
2
+ export declare const RABBY: RealmLoginWallet;
@@ -0,0 +1,2 @@
1
+ import { RealmLoginWallet } from "..";
2
+ export declare const RAINBOW: RealmLoginWallet;
@@ -0,0 +1,2 @@
1
+ import { RealmLoginWallet } from "..";
2
+ export declare const TRUST: RealmLoginWallet;
@@ -0,0 +1,8 @@
1
+ export type Jsonable = string | number | boolean | null | undefined | readonly Jsonable[] | {
2
+ readonly [key: string]: Jsonable;
3
+ } | {
4
+ toJSON(): Jsonable;
5
+ };
6
+ export type Optional<T, K extends keyof T> = Omit<T, K> & {
7
+ [P in keyof T]?: T[P] | undefined;
8
+ };
@@ -0,0 +1,2 @@
1
+ import { AirIdDetails } from "./realm/user/types";
2
+ export declare const parseAirId: (airIdDetail?: Omit<AirIdDetails, "id">) => string | undefined;
@@ -0,0 +1,82 @@
1
+ import { ProviderEvents } from "@web3auth/auth";
2
+ import type { Duplex } from "readable-stream";
3
+ import BaseProvider from "./baseProvider";
4
+ import { CommunicationProviderState, ProviderOptions, UnValidatedJsonRpcRequest } from "./interfaces";
5
+ import PopupHandler from "./PopupHandler";
6
+ type CommunicationProviderEvents = ProviderEvents & {
7
+ connect: (payload: {
8
+ currentLoginProvider: string;
9
+ isLoggedIn: boolean;
10
+ }) => void;
11
+ disconnect: (err: Error) => void;
12
+ };
13
+ /**
14
+ * @param connectionStream - A Node.js duplex stream
15
+ * @param opts - An options bag
16
+ */
17
+ declare class CommunicationProvider extends BaseProvider<CommunicationProviderState, CommunicationProviderEvents> {
18
+ protected static defaultState: CommunicationProviderState;
19
+ tryWindowHandle: (payload: UnValidatedJsonRpcRequest | UnValidatedJsonRpcRequest[], cb: (...args: unknown[]) => void) => void;
20
+ onLoginStateHandle?: (isLoggedIn: boolean) => Promise<void>;
21
+ windowRefs: Map<string, PopupHandler>;
22
+ iframeUrl: string;
23
+ private iframeId;
24
+ constructor(connectionStream: Duplex, { maxEventListeners, jsonRpcStreamName }: ProviderOptions, state: Partial<CommunicationProviderState>);
25
+ get isLoggedIn(): boolean;
26
+ get isExternalWallet(): boolean;
27
+ get isIFrameFullScreen(): boolean;
28
+ /**
29
+ * Returns whether the inPage provider is connected to Torus.
30
+ */
31
+ isConnected(): boolean;
32
+ initializeState(params: Record<string, unknown>): Promise<void>;
33
+ hideTorusButton(): void;
34
+ showTorusButton(): void;
35
+ moveToBackground(): void;
36
+ moveToForeground(): void;
37
+ setIframeVisibility({ isVisible }: {
38
+ isVisible: boolean;
39
+ }): void;
40
+ displayIframe({ isFull, rid }?: {
41
+ isFull?: boolean;
42
+ rid?: string;
43
+ }, walletRequest?: boolean): void;
44
+ /**
45
+ * Scenarios:
46
+ * - Login request or pre-open confirmation windows
47
+ * We try to open here or send a rpc request to iframe that window is blocked.
48
+ */
49
+ handleWindow(windowId: string, { url, target, features, timeout }?: {
50
+ url?: string;
51
+ target?: string;
52
+ features?: string;
53
+ timeout?: number;
54
+ }): Promise<void>;
55
+ /**
56
+ * Internal RPC method. Forwards requests to background via the RPC engine.
57
+ * Also remap ids inbound and outbound
58
+ */
59
+ protected rpcRequest(payload: UnValidatedJsonRpcRequest | UnValidatedJsonRpcRequest[], callback: (...args: unknown[]) => void): void;
60
+ /**
61
+ * When the provider becomes connected, updates internal state and emits
62
+ * required events. Idempotent.
63
+ *
64
+ * @param currentLoginProvider - The login Provider
65
+ * emits TorusInpageProvider#connect
66
+ */
67
+ protected handleConnect(currentLoginProvider: string, isLoggedIn: boolean): void;
68
+ /**
69
+ * When the provider becomes disconnected, updates internal state and emits
70
+ * required events. Idempotent with respect to the isRecoverable parameter.
71
+ *
72
+ * Error codes per the CloseEvent status codes as required by EIP-1193:
73
+ * https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes
74
+ *
75
+ * @param isRecoverable - Whether the disconnection is recoverable.
76
+ * @param errorMessage - A custom error message.
77
+ * emits TorusInpageProvider#disconnect
78
+ */
79
+ protected handleDisconnect(isRecoverable: boolean, errorMessage?: string): void;
80
+ private handleCloseWindow;
81
+ }
82
+ export default CommunicationProvider;
@@ -0,0 +1,42 @@
1
+ import { COMMUNICATION_JRPC_METHODS } from "@toruslabs/base-controllers";
2
+ import { type METHOD_TYPES_TYPE } from "@toruslabs/ethereum-controllers";
3
+ import { TorusInPageProvider } from "./inPageProvider";
4
+ import { ClaimRealmIdOptions, CtorArgs, EMBED_BUILD_ENV_TYPE, EmbedEventListener, EmbedParams, RealmConnectResult, RealmLoginResult, RealmUserInfo } from "./interfaces";
5
+ export declare const COMMUNICATION_UNSAFE_METHODS: Set<Partial<(typeof COMMUNICATION_JRPC_METHODS)[keyof typeof COMMUNICATION_JRPC_METHODS]>>;
6
+ export declare const PROVIDER_UNSAFE_METHODS: Set<Partial<METHOD_TYPES_TYPE>>;
7
+ declare class RealmEmbed {
8
+ #private;
9
+ constructor({ modalZIndex, partnerId }: CtorArgs);
10
+ get isConnected(): boolean;
11
+ get isInitialized(): boolean;
12
+ get isLoggedIn(): boolean;
13
+ get getBuildEnv(): EMBED_BUILD_ENV_TYPE;
14
+ get walletAddresses(): {
15
+ eoa: string;
16
+ aa?: string;
17
+ } | null;
18
+ get sessionId(): string | null;
19
+ get realmId(): string | null;
20
+ get provider(): TorusInPageProvider | null;
21
+ init({ buildEnv, enableLogging, skipRehydration, }?: EmbedParams): Promise<void>;
22
+ moveToBackground(): void;
23
+ moveToForeground(): void;
24
+ getUserInfo(): Promise<RealmUserInfo | null>;
25
+ login<T extends boolean>(options?: {
26
+ skipClaiming: T;
27
+ token?: string;
28
+ authToken?: string;
29
+ legacy?: boolean;
30
+ }): Promise<T extends true ? RealmLoginResult | RealmConnectResult : RealmLoginResult>;
31
+ _deploySmartAccount(): Promise<void>;
32
+ private _loginWithSessionId;
33
+ private _showWalletWidget;
34
+ claimRealmId(options?: ClaimRealmIdOptions): Promise<RealmLoginResult>;
35
+ logout(): Promise<void>;
36
+ cleanUp(): Promise<void>;
37
+ clearInit(): Promise<void>;
38
+ on(listener: EmbedEventListener): void;
39
+ off(listener: EmbedEventListener): void;
40
+ clearEventListeners(): void;
41
+ }
42
+ export default RealmEmbed;
@@ -0,0 +1,9 @@
1
+ import { BaseError } from "./common/error";
2
+ import { AirErrorName } from "./common/realm/error/types";
3
+ type AirServiceErrorName = AirErrorName | "NOT_INITIALISED" | "ALREADY_INITIALISED" | "NOT_LOGGED_IN" | "NOT_CONNECTED";
4
+ export declare class AirServiceError extends BaseError<AirServiceErrorName> {
5
+ static from(error: unknown): AirServiceError;
6
+ }
7
+ export declare class RealmEmbedError extends AirServiceError {
8
+ }
9
+ export {};
@@ -0,0 +1,18 @@
1
+ interface IframeState {
2
+ isVisible: boolean;
3
+ }
4
+ export declare class IframeController {
5
+ private static defaultState;
6
+ private state;
7
+ private _iframeElement;
8
+ private iframeUrl;
9
+ private iframeId;
10
+ constructor(iframeUrl: string, iframeId: string, state?: Partial<IframeState>);
11
+ get iframeElement(): HTMLIFrameElement | null;
12
+ createIframe(): HTMLIFrameElement;
13
+ setIframeVisibility(isVisible: boolean): void;
14
+ updateIframeState(): void;
15
+ destroy(): void;
16
+ postMessage(message: unknown): void;
17
+ }
18
+ export {};
@@ -0,0 +1,106 @@
1
+ import { ProviderEvents, RequestArguments } from "@web3auth/auth";
2
+ import type { Duplex } from "readable-stream";
3
+ import BaseProvider from "./baseProvider";
4
+ import { InPageProviderState, ProviderOptions, UnValidatedJsonRpcRequest } from "./interfaces";
5
+ type AirInPageProviderEvents = ProviderEvents & {
6
+ connect: (payload: {
7
+ chainId: string;
8
+ }) => void;
9
+ disconnect: (err: Error) => void;
10
+ notification: (payload: unknown) => void;
11
+ message: (payload: {
12
+ type: string;
13
+ data: unknown;
14
+ }) => void;
15
+ accountsChanged: (payload: unknown[]) => void;
16
+ chainChanged: (chainId: string) => void;
17
+ data: (payload: RequestArguments<unknown>) => void;
18
+ };
19
+ /**
20
+ * @param connectionStream - A Node.js duplex stream
21
+ * @param opts - An options bag
22
+ */
23
+ declare class AirInPageProvider extends BaseProvider<InPageProviderState, AirInPageProviderEvents> {
24
+ protected static defaultState: InPageProviderState;
25
+ /**
26
+ * The chain ID of the currently connected EVM chain.
27
+ * See [chainId.network]{@link https://chainid.network} for more information.
28
+ */
29
+ chainId: string | null;
30
+ /**
31
+ * The user's currently selected EVM address.
32
+ * If null, Torus is either locked or the user has not permitted any
33
+ * addresses to be viewed.
34
+ */
35
+ selectedAddress: string | null;
36
+ tryWindowHandle: (payload: UnValidatedJsonRpcRequest | UnValidatedJsonRpcRequest[], cb: (...args: unknown[]) => void) => void;
37
+ constructor(connectionStream: Duplex, { maxEventListeners, jsonRpcStreamName }: ProviderOptions);
38
+ /**
39
+ * Returns whether the inpage provider is connected to Torus.
40
+ */
41
+ isConnected(): boolean;
42
+ /**
43
+ * Constructor helper.
44
+ * Populates initial state by calling 'wallet_getProviderState' and emits
45
+ * necessary events.
46
+ */
47
+ initializeState(): Promise<void>;
48
+ /**
49
+ * Internal RPC method. Forwards requests to background via the RPC engine.
50
+ * Also remap ids inbound and outbound
51
+ */
52
+ rpcRequest(payload: UnValidatedJsonRpcRequest | UnValidatedJsonRpcRequest[], callback: (...args: unknown[]) => void, isInternal?: boolean): void;
53
+ /**
54
+ * When the provider becomes connected, updates internal state and emits
55
+ * required events. Idempotent.
56
+ *
57
+ * @param chainId - The ID of the newly connected chain.
58
+ * emits TorusInpageProvider#connect
59
+ */
60
+ protected handleConnect(chainId: string): void;
61
+ /**
62
+ * When the provider becomes disconnected, updates internal state and emits
63
+ * required events. Idempotent with respect to the isRecoverable parameter.
64
+ *
65
+ * Error codes per the CloseEvent status codes as required by EIP-1193:
66
+ * https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes
67
+ *
68
+ * @param isRecoverable - Whether the disconnection is recoverable.
69
+ * @param errorMessage - A custom error message.
70
+ * emits TorusInpageProvider#disconnect
71
+ */
72
+ protected handleDisconnect(isRecoverable: boolean, errorMessage?: string): void;
73
+ /**
74
+ * Called when accounts may have changed.
75
+ */
76
+ protected handleAccountsChanged(accounts: unknown[], isEthAccounts?: boolean, isInternal?: boolean): void;
77
+ /**
78
+ * Upon receipt of a new chainId and networkVersion, emits corresponding
79
+ * events and sets relevant public state.
80
+ * Does nothing if neither the chainId nor the networkVersion are different
81
+ * from existing values.
82
+ *
83
+ * emits TorusInpageProvider#chainChanged
84
+ * @param networkInfo - An object with network info.
85
+ */
86
+ protected handleChainChanged({ chainId }?: {
87
+ chainId?: string;
88
+ }): void;
89
+ /**
90
+ * Upon receipt of a new isUnlocked state, sets relevant public state.
91
+ * Calls the accounts changed handler with the received accounts, or an empty
92
+ * array.
93
+ *
94
+ * Does nothing if the received value is equal to the existing value.
95
+ * There are no lock/unlock events.
96
+ *
97
+ * @param opts - Options bag.
98
+ */
99
+ protected handleUnlockStateChanged({ accounts, isUnlocked }?: {
100
+ accounts?: string[];
101
+ isUnlocked?: boolean;
102
+ }): void;
103
+ }
104
+ export default AirInPageProvider;
105
+ export declare class TorusInPageProvider extends AirInPageProvider {
106
+ }
@@ -0,0 +1,4 @@
1
+ export { default as AirService } from "./airService";
2
+ export { default as RealmEmbed } from "./embed";
3
+ export { default as AirInPageProvider } from "./inPageProvider";
4
+ export * from "./interfaces";
@@ -0,0 +1,261 @@
1
+ import { LOGIN_PROVIDER_TYPE } from "@toruslabs/base-controllers";
2
+ import { JRPCRequest } from "@web3auth/auth";
3
+ import { LogLevelDesc } from "loglevel";
4
+ import { AirRehydrationResult, RealmRehydrationResult } from "./common/realm/messaging/types";
5
+ import { REALM_LOGIN_PROVIDER_TYPE } from "./common/realm/partner/config";
6
+ import { AirIdDetails } from "./common/realm/user/types";
7
+ export { CONFIRMATION_STRATEGY, type CONFIRMATION_STRATEGY_TYPE } from "@toruslabs/base-controllers";
8
+ export type { AirRehydrationResult, RealmRehydrationResult };
9
+ export declare const EMBED_BUILD_ENV: {
10
+ readonly PRODUCTION: "production";
11
+ readonly STAGING: "staging";
12
+ readonly DEVELOPMENT: "development";
13
+ readonly TESTING: "testing";
14
+ };
15
+ export type EMBED_BUILD_ENV_TYPE = (typeof EMBED_BUILD_ENV)[keyof typeof EMBED_BUILD_ENV];
16
+ export declare const BUTTON_POSITION: {
17
+ readonly BOTTOM_LEFT: "bottom-left";
18
+ readonly TOP_LEFT: "top-left";
19
+ readonly BOTTOM_RIGHT: "bottom-right";
20
+ readonly TOP_RIGHT: "top-right";
21
+ };
22
+ export type BUTTON_POSITION_TYPE = (typeof BUTTON_POSITION)[keyof typeof BUTTON_POSITION];
23
+ export interface CtorArgs {
24
+ /**
25
+ * Z-index of the modal and iframe
26
+ * @defaultValue 99999
27
+ */
28
+ modalZIndex?: number;
29
+ partnerId: string;
30
+ }
31
+ export interface PaymentParams {
32
+ /**
33
+ * Address to send the funds to
34
+ */
35
+ selectedAddress?: string;
36
+ /**
37
+ * Default fiat currency for the user to make the payment in
38
+ */
39
+ selectedCurrency?: string;
40
+ /**
41
+ * Amount to buy in the selectedCurrency
42
+ */
43
+ fiatValue?: number;
44
+ /**
45
+ * Cryptocurrency to buy
46
+ */
47
+ selectedCryptoCurrency?: string;
48
+ }
49
+ export declare const EXTERNAL_LOGIN_PROVIDER: {
50
+ readonly METAMASK: "metamask";
51
+ readonly WALLET_CONNECT: "walletconnect";
52
+ readonly WAGMI: "wagmi";
53
+ };
54
+ export type EXTERNAL_LOGIN_PROVIDER_TYPE = (typeof EXTERNAL_LOGIN_PROVIDER)[keyof typeof EXTERNAL_LOGIN_PROVIDER];
55
+ export interface LoginParams {
56
+ loginProvider?: REALM_LOGIN_PROVIDER_TYPE | EXTERNAL_LOGIN_PROVIDER_TYPE;
57
+ login_hint?: string;
58
+ }
59
+ export interface LoginWithSessionIdParams {
60
+ sessionId: string;
61
+ }
62
+ export interface UserInfo {
63
+ /**
64
+ * Email of the logged in user
65
+ */
66
+ email: string;
67
+ /**
68
+ * Full name of the logged in user
69
+ */
70
+ name: string;
71
+ /**
72
+ * Profile image of the logged in user
73
+ */
74
+ profileImage: string;
75
+ /**
76
+ * verifier of the logged in user (google, facebook etc)
77
+ */
78
+ verifier: string;
79
+ /**
80
+ * Verifier Id of the logged in user
81
+ *
82
+ * email for google,
83
+ * id for facebook,
84
+ * username for reddit,
85
+ * id for twitch,
86
+ * id for discord
87
+ */
88
+ verifierId: string;
89
+ }
90
+ export interface AirUrlConfig {
91
+ authUrl?: string;
92
+ walletUrl?: string;
93
+ logLevel?: LogLevelDesc;
94
+ }
95
+ export interface EmbedParams {
96
+ /**
97
+ * Build Environment of WsEmbed.
98
+ *
99
+ * production uses https://wallet.web3auth.io,
100
+ *
101
+ * staging uses https://staging-wallet.web3auth.io,
102
+ *
103
+ * testing uses https://develop-wallet.web3auth.io (latest internal build)
104
+ *
105
+ * development uses https://localhost:4050 (expects wallet-services-frontend to be run locally),
106
+ *
107
+ * @defaultValue production
108
+ */
109
+ buildEnv?: EMBED_BUILD_ENV_TYPE;
110
+ /**
111
+ * Enables or disables logging.
112
+ *
113
+ * Defaults to false in prod and true in other environments
114
+ */
115
+ enableLogging?: boolean;
116
+ skipRehydration?: boolean;
117
+ }
118
+ export interface ProviderOptions {
119
+ /**
120
+ * The name of the stream used to connect to the wallet.
121
+ */
122
+ jsonRpcStreamName?: string;
123
+ /**
124
+ * The maximum number of event listeners.
125
+ */
126
+ maxEventListeners?: number;
127
+ }
128
+ export interface BaseProviderState {
129
+ isConnected: boolean;
130
+ initialized: boolean;
131
+ isPermanentlyDisconnected: boolean;
132
+ hasEmittedConnection: boolean;
133
+ }
134
+ export interface InPageProviderState extends BaseProviderState {
135
+ accounts: null | string[];
136
+ isUnlocked: boolean;
137
+ }
138
+ export interface CommunicationProviderState extends BaseProviderState {
139
+ buttonPosition: string;
140
+ isLoggedIn: boolean;
141
+ widgetVisibility: boolean;
142
+ currentLoginProvider: LOGIN_PROVIDER_TYPE | EXTERNAL_LOGIN_PROVIDER_TYPE;
143
+ isIFrameFullScreen: boolean;
144
+ isBackground: boolean;
145
+ }
146
+ export type Maybe<T> = Partial<T> | T | null | undefined;
147
+ export interface UnValidatedJsonRpcRequest extends JRPCRequest<unknown> {
148
+ windowId?: string;
149
+ }
150
+ export type AirWalletAddresses = {
151
+ eoa: string;
152
+ aa: string;
153
+ };
154
+ export type RealmWalletAddresses = {
155
+ eoa: string;
156
+ aa?: string;
157
+ };
158
+ export type AirInitializationResult = {
159
+ rehydration: AirRehydrationResult;
160
+ };
161
+ export type RealmInitializationResult = {
162
+ rehydration: RealmRehydrationResult;
163
+ };
164
+ export type RealmConnectResult = {
165
+ isLoggedIn: false;
166
+ addresses: RealmWalletAddresses;
167
+ token: string;
168
+ sessionId?: string;
169
+ };
170
+ export type RealmLoginResult = {
171
+ isLoggedIn: true;
172
+ realmId: string;
173
+ addresses: Required<RealmWalletAddresses>;
174
+ token: string;
175
+ sessionId?: string;
176
+ };
177
+ export type AirEmbedConnectResult = RealmConnectResult;
178
+ export type AirEmbedLoginResult = RealmLoginResult;
179
+ export type RealmUserInfo = UserInfo & {
180
+ realmId: string;
181
+ };
182
+ export type EmbedEventOnInitialized = {
183
+ event: "initialized";
184
+ result: RealmInitializationResult;
185
+ };
186
+ export type EmbedEventOnConnected = {
187
+ event: "connected";
188
+ result: RealmConnectResult;
189
+ };
190
+ export type EmbedEventOnLoggedIn = {
191
+ event: "logged_in";
192
+ result: RealmLoginResult;
193
+ };
194
+ export type EmbedEventOnLoggedOut = {
195
+ event: "logged_out";
196
+ };
197
+ export type EmbedEventOnReset = {
198
+ event: "reset";
199
+ };
200
+ export type EmbedEventOnMintingStarted = {
201
+ event: "minting_started";
202
+ };
203
+ export type EmbedEventOnMintingFailed = {
204
+ event: "minting_failed";
205
+ errorMessage?: string;
206
+ };
207
+ export type EmbedEventData = EmbedEventOnInitialized | EmbedEventOnConnected | EmbedEventOnLoggedIn | EmbedEventOnLoggedOut | EmbedEventOnReset | EmbedEventOnMintingStarted | EmbedEventOnMintingFailed;
208
+ export type AirUserDetails = {
209
+ id: string;
210
+ abstractAccountAddress: string;
211
+ email?: string;
212
+ airIds: AirIdDetails[];
213
+ };
214
+ export type AirPartnerUserDetails = {
215
+ partnerId: string;
216
+ partnerUserId: string;
217
+ airId?: AirIdDetails;
218
+ };
219
+ export type AirLoginResult = {
220
+ isLoggedIn: boolean;
221
+ id: string;
222
+ abstractAccountAddress: string;
223
+ token: string;
224
+ };
225
+ export type AirWalletLoadedResult = {
226
+ isLoggedIn: boolean;
227
+ airId?: string;
228
+ addresses: AirWalletAddresses;
229
+ };
230
+ export type AirEventOnInitialized = {
231
+ event: "initialized";
232
+ };
233
+ export type AirEventOnLoggedIn = {
234
+ event: "logged_in";
235
+ result: AirLoginResult;
236
+ };
237
+ export type AirEventWalletLoaded = {
238
+ event: "wallet_loaded";
239
+ result: AirWalletLoadedResult;
240
+ };
241
+ export type AirEventWalletMintingStarted = {
242
+ event: "minting_started";
243
+ };
244
+ export type AirEventWalletMintingFailed = {
245
+ event: "minting_failed";
246
+ errorMessage?: string;
247
+ };
248
+ export type AirEventOnLoggedOut = {
249
+ event: "logged_out";
250
+ };
251
+ export type AirEventData = AirEventOnInitialized | AirEventOnLoggedIn | AirEventWalletLoaded | AirEventWalletMintingStarted | AirEventWalletMintingFailed | AirEventOnLoggedOut;
252
+ export type EmbedEventListener = (data: EmbedEventData) => void;
253
+ export type AirEventListener = (data: AirEventData) => void;
254
+ export type ClaimAirIdOptions = {
255
+ token?: string;
256
+ background?: false;
257
+ } | {
258
+ token: string;
259
+ background: true;
260
+ };
261
+ export type ClaimRealmIdOptions = ClaimAirIdOptions;