@magic-sdk/provider 29.4.3-canary.934.17056365555.0 → 29.4.3-canary.934.17056583985.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/es/index.js +6 -0
- package/dist/es/index.js.map +7 -0
- package/dist/es/index.mjs +6 -0
- package/dist/es/index.mjs.map +7 -0
- package/dist/types/core/json-rpc.d.ts +32 -0
- package/dist/types/core/sdk-environment.d.ts +29 -0
- package/dist/types/core/sdk-exceptions.d.ts +87 -0
- package/dist/types/core/sdk.d.ts +75 -0
- package/dist/types/core/view-controller.d.ts +61 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/modules/auth.d.ts +129 -0
- package/dist/types/modules/base-extension.d.ts +113 -0
- package/dist/types/modules/base-module.d.ts +27 -0
- package/dist/types/modules/nft.d.ts +22 -0
- package/dist/types/modules/rpc-provider.d.ts +50 -0
- package/dist/types/modules/third-party-wallets.d.ts +26 -0
- package/dist/types/modules/user.d.ts +93 -0
- package/dist/types/modules/wallet.d.ts +66 -0
- package/dist/types/util/base64-json.d.ts +8 -0
- package/dist/types/util/device-share-web-crypto.d.ts +7 -0
- package/dist/types/util/events.d.ts +23 -0
- package/dist/types/util/get-payload-id.d.ts +4 -0
- package/dist/types/util/index.d.ts +10 -0
- package/dist/types/util/promise-tools.d.ts +48 -0
- package/dist/types/util/semver.d.ts +23 -0
- package/dist/types/util/storage.d.ts +8 -0
- package/dist/types/util/type-guards.d.ts +30 -0
- package/dist/types/util/url.d.ts +4 -0
- package/dist/types/util/uuid.d.ts +1 -0
- package/dist/types/util/version-check.d.ts +1 -0
- package/dist/types/util/view-controller-utils.d.ts +26 -0
- package/dist/types/util/web-crypto.d.ts +5 -0
- package/package.json +2 -2
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { JsonRpcError, RPCErrorCode, SDKErrorCode, SDKWarningCode } from '@magic-sdk/types';
|
|
2
|
+
import { BaseExtension } from '../modules/base-extension';
|
|
3
|
+
/**
|
|
4
|
+
* This error type represents internal SDK errors. This could be developer
|
|
5
|
+
* mistakes (or Magic's mistakes), or execution errors unrelated to standard
|
|
6
|
+
* JavaScript exceptions.
|
|
7
|
+
*/
|
|
8
|
+
export declare class MagicSDKError extends Error {
|
|
9
|
+
code: SDKErrorCode;
|
|
10
|
+
rawMessage: string;
|
|
11
|
+
__proto__: ErrorConstructor;
|
|
12
|
+
constructor(code: SDKErrorCode, rawMessage: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* This error type communicates exceptions that occur during execution in the
|
|
16
|
+
* Magic `<iframe>` context.
|
|
17
|
+
*/
|
|
18
|
+
export declare class MagicRPCError extends Error {
|
|
19
|
+
__proto__: ErrorConstructor;
|
|
20
|
+
code: RPCErrorCode | number;
|
|
21
|
+
rawMessage: string;
|
|
22
|
+
data: any;
|
|
23
|
+
constructor(sourceError?: JsonRpcError | null);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* In contrast to `SDKError` objects, this "warning" type communicates important
|
|
27
|
+
* context that does not rise to the level of an exception. These should be
|
|
28
|
+
* logged rather than thrown.
|
|
29
|
+
*/
|
|
30
|
+
export declare class MagicSDKWarning {
|
|
31
|
+
code: SDKWarningCode;
|
|
32
|
+
rawMessage: string;
|
|
33
|
+
message: string;
|
|
34
|
+
constructor(code: SDKWarningCode, rawMessage: string);
|
|
35
|
+
/**
|
|
36
|
+
* Logs this warning to the console.
|
|
37
|
+
*/
|
|
38
|
+
log(): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* This error type is reserved for communicating errors that arise during
|
|
42
|
+
* execution of Magic SDK Extension methods. Compare this to the `SDKError`
|
|
43
|
+
* type, specifically in context of Extensions.
|
|
44
|
+
*/
|
|
45
|
+
export declare class MagicExtensionError<TData = any> extends Error {
|
|
46
|
+
code: string | number;
|
|
47
|
+
rawMessage: string;
|
|
48
|
+
data: TData;
|
|
49
|
+
__proto__: ErrorConstructor;
|
|
50
|
+
constructor(ext: BaseExtension<string>, code: string | number, rawMessage: string, data: TData);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* In contrast to `MagicExtensionError` objects, this "warning" type
|
|
54
|
+
* communicates important context that does not rise to the level of an
|
|
55
|
+
* exception. These should be logged rather than thrown.
|
|
56
|
+
*/
|
|
57
|
+
export declare class MagicExtensionWarning {
|
|
58
|
+
code: string | number;
|
|
59
|
+
rawMessage: string;
|
|
60
|
+
message: string;
|
|
61
|
+
constructor(ext: BaseExtension<string>, code: string | number, rawMessage: string);
|
|
62
|
+
/**
|
|
63
|
+
* Logs this warning to the console.
|
|
64
|
+
*/
|
|
65
|
+
log(): void;
|
|
66
|
+
}
|
|
67
|
+
export declare function createMissingApiKeyError(): MagicSDKError;
|
|
68
|
+
export declare function createModalNotReadyError(): MagicSDKError;
|
|
69
|
+
export declare function createMalformedResponseError(): MagicSDKError;
|
|
70
|
+
export declare function createExtensionNotInitializedError(member: string): MagicSDKError;
|
|
71
|
+
export declare function createIncompatibleExtensionsError(extensions: BaseExtension<string>[]): MagicSDKError;
|
|
72
|
+
export declare function createInvalidArgumentError(options: {
|
|
73
|
+
procedure: string;
|
|
74
|
+
argument: number;
|
|
75
|
+
expected: string;
|
|
76
|
+
received: string;
|
|
77
|
+
}): MagicSDKError;
|
|
78
|
+
export declare function createDuplicateIframeWarning(): MagicSDKWarning;
|
|
79
|
+
export declare function createSynchronousWeb3MethodWarning(): MagicSDKWarning;
|
|
80
|
+
export declare function createReactNativeEndpointConfigurationWarning(): MagicSDKWarning;
|
|
81
|
+
export declare function createDeprecationWarning(options: {
|
|
82
|
+
method: string;
|
|
83
|
+
removalVersions: {
|
|
84
|
+
[P in 'magic-sdk' | '@magic-sdk/react-native' | '@magic-sdk/react-native-bare' | '@magic-sdk/react-native-expo']: string;
|
|
85
|
+
};
|
|
86
|
+
useInstead?: string;
|
|
87
|
+
}): MagicSDKWarning;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { EthNetworkConfiguration, SupportedLocale } from '@magic-sdk/types';
|
|
2
|
+
import { AuthModule } from '../modules/auth';
|
|
3
|
+
import { UserModule } from '../modules/user';
|
|
4
|
+
import { WalletModule } from '../modules/wallet';
|
|
5
|
+
import { ThirdPartyWalletsModule } from '../modules/third-party-wallets';
|
|
6
|
+
import { RPCProviderModule } from '../modules/rpc-provider';
|
|
7
|
+
import { ViewController } from './view-controller';
|
|
8
|
+
import { BaseExtension } from '../modules/base-extension';
|
|
9
|
+
import { NFTModule } from '../modules/nft';
|
|
10
|
+
export type MagicSDKExtensionsOption<TCustomExtName extends string = string> = BaseExtension<string>[] | {
|
|
11
|
+
[P in TCustomExtName]: BaseExtension<string>;
|
|
12
|
+
};
|
|
13
|
+
export interface MagicSDKAdditionalConfiguration<TCustomExtName extends string = string, TExt extends MagicSDKExtensionsOption<TCustomExtName> = any> {
|
|
14
|
+
endpoint?: string;
|
|
15
|
+
locale?: SupportedLocale;
|
|
16
|
+
network?: EthNetworkConfiguration;
|
|
17
|
+
extensions?: TExt;
|
|
18
|
+
testMode?: boolean;
|
|
19
|
+
deferPreload?: boolean;
|
|
20
|
+
useStorageCache?: boolean;
|
|
21
|
+
meta?: any;
|
|
22
|
+
authConfig?: {
|
|
23
|
+
skipDIDToken: boolean;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare class SDKBase {
|
|
27
|
+
readonly apiKey: string;
|
|
28
|
+
private static readonly __overlays__;
|
|
29
|
+
protected readonly endpoint: string;
|
|
30
|
+
protected readonly parameters: string;
|
|
31
|
+
protected readonly networkHash: string;
|
|
32
|
+
readonly testMode: boolean;
|
|
33
|
+
readonly useStorageCache: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Contains methods for starting a Magic SDK authentication flow.
|
|
36
|
+
*/
|
|
37
|
+
readonly auth: AuthModule;
|
|
38
|
+
/**
|
|
39
|
+
* Contains methods for interacting with user data, checking login
|
|
40
|
+
* status, generating cryptographically-secure ID tokens, and more.
|
|
41
|
+
*/
|
|
42
|
+
readonly user: UserModule;
|
|
43
|
+
/**
|
|
44
|
+
* Contains methods previously under the `ConnectExtension`, including
|
|
45
|
+
* login, show wallet UI, request user info, and more.
|
|
46
|
+
*/
|
|
47
|
+
readonly wallet: WalletModule;
|
|
48
|
+
/**
|
|
49
|
+
* Contains methods for interacting with NFTs, including purchase.
|
|
50
|
+
*/
|
|
51
|
+
readonly nft: NFTModule;
|
|
52
|
+
/**
|
|
53
|
+
* Contains internal methods for third-party wallets.
|
|
54
|
+
*/
|
|
55
|
+
thirdPartyWallets: ThirdPartyWalletsModule;
|
|
56
|
+
/**
|
|
57
|
+
* Contains a Web3-compliant provider. Pass this module to your Web3/Ethers
|
|
58
|
+
* instance for automatic compatibility with Ethereum methods.
|
|
59
|
+
*/
|
|
60
|
+
readonly rpcProvider: RPCProviderModule;
|
|
61
|
+
/**
|
|
62
|
+
* Creates an instance of Magic SDK.
|
|
63
|
+
*/
|
|
64
|
+
constructor(apiKey: string, options?: MagicSDKAdditionalConfiguration);
|
|
65
|
+
/**
|
|
66
|
+
* Represents the view controller associated with this `MagicSDK` instance.
|
|
67
|
+
*/
|
|
68
|
+
protected get overlay(): ViewController;
|
|
69
|
+
/**
|
|
70
|
+
* Preloads the Magic view, allowing for faster initial requests in browser
|
|
71
|
+
* environments. Awaiting the returned promise will signal when the Magic view
|
|
72
|
+
* has completed loading and is ready for requests.
|
|
73
|
+
*/
|
|
74
|
+
preload(): Promise<void>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { MagicIncomingWindowMessage, MagicOutgoingWindowMessage, JsonRpcRequestPayload, MagicMessageEvent, MagicMessageRequest } from '@magic-sdk/types';
|
|
2
|
+
import { JsonRpcResponse } from './json-rpc';
|
|
3
|
+
interface RemoveEventListenerFunction {
|
|
4
|
+
(): void;
|
|
5
|
+
}
|
|
6
|
+
export declare abstract class ViewController {
|
|
7
|
+
protected readonly endpoint: string;
|
|
8
|
+
protected readonly parameters: string;
|
|
9
|
+
protected readonly networkHash: string;
|
|
10
|
+
isReadyForRequest: boolean;
|
|
11
|
+
protected readonly messageHandlers: Set<(event: MagicMessageEvent) => any>;
|
|
12
|
+
protected isConnectedToInternet: boolean;
|
|
13
|
+
protected lastPongTime: null | number;
|
|
14
|
+
protected heartbeatIntervalTimer: ReturnType<typeof setInterval> | null;
|
|
15
|
+
protected heartbeatDebounce: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Create an instance of `ViewController`
|
|
18
|
+
*
|
|
19
|
+
* @param endpoint - The URL for the relevant iframe context.
|
|
20
|
+
* @param parameters - The unique, encoded query parameters for the
|
|
21
|
+
* relevant iframe context.
|
|
22
|
+
* @param networkHash - The hash of the network that this sdk instance is connected to
|
|
23
|
+
* for multi-chain scenarios
|
|
24
|
+
*/
|
|
25
|
+
constructor(endpoint: string, parameters: string, networkHash: string);
|
|
26
|
+
protected abstract init(): void;
|
|
27
|
+
protected abstract _post(data: MagicMessageRequest): Promise<void>;
|
|
28
|
+
protected abstract hideOverlay(): void;
|
|
29
|
+
protected abstract showOverlay(): void;
|
|
30
|
+
protected abstract checkRelayerExistsInDOM(): Promise<boolean>;
|
|
31
|
+
protected abstract reloadRelayer(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Send a payload to the Magic `<iframe>` for processing and automatically
|
|
34
|
+
* handle the acknowledging follow-up event(s).
|
|
35
|
+
*
|
|
36
|
+
* @param msgType - The type of message to encode with the data.
|
|
37
|
+
* @param payload - The JSON RPC payload to emit via `window.postMessage`.
|
|
38
|
+
*/
|
|
39
|
+
post<ResultType = any>(msgType: MagicOutgoingWindowMessage, payload: JsonRpcRequestPayload[]): Promise<JsonRpcResponse<ResultType>[]>;
|
|
40
|
+
post<ResultType = any>(msgType: MagicOutgoingWindowMessage, payload: JsonRpcRequestPayload): Promise<JsonRpcResponse<ResultType>>;
|
|
41
|
+
/**
|
|
42
|
+
* Listen for events received with the given `msgType`.
|
|
43
|
+
*
|
|
44
|
+
* @param msgType - The `msgType` encoded with the event data.
|
|
45
|
+
* @param handler - A handler function to execute on each event received.
|
|
46
|
+
* @return A `void` function to remove the attached event.
|
|
47
|
+
*/
|
|
48
|
+
on(msgType: MagicIncomingWindowMessage, handler: (this: Window, event: MagicMessageEvent) => any): RemoveEventListenerFunction;
|
|
49
|
+
waitForReady(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Listen for messages sent from the underlying Magic `<WebView>`.
|
|
52
|
+
*/
|
|
53
|
+
private listen;
|
|
54
|
+
/**
|
|
55
|
+
* Sends periodic pings to check the connection.
|
|
56
|
+
* If no pong is received or it’s stale, the iframe is reloaded.
|
|
57
|
+
*/
|
|
58
|
+
private heartBeatCheck;
|
|
59
|
+
protected stopHeartBeat(): void;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { SDKBase } from './core/sdk';
|
|
2
|
+
export type { MagicSDKAdditionalConfiguration, MagicSDKExtensionsOption } from './core/sdk';
|
|
3
|
+
export { createSDK } from './core/sdk-environment';
|
|
4
|
+
export { ViewController } from './core/view-controller';
|
|
5
|
+
export * from './core/sdk-exceptions';
|
|
6
|
+
export { Extension } from './modules/base-extension';
|
|
7
|
+
export type { WithExtensions, InstanceWithExtensions } from './modules/base-extension';
|
|
8
|
+
export * from './util';
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { LoginWithMagicLinkConfiguration, LoginWithSmsConfiguration, LoginWithEmailOTPConfiguration, UpdateEmailConfiguration, LoginWithCredentialConfiguration } from '@magic-sdk/types';
|
|
2
|
+
import { BaseModule } from './base-module';
|
|
3
|
+
export declare const ProductConsolidationMethodRemovalVersions: {
|
|
4
|
+
'magic-sdk': string;
|
|
5
|
+
'@magic-sdk/react-native': string;
|
|
6
|
+
'@magic-sdk/react-native-bare': string;
|
|
7
|
+
'@magic-sdk/react-native-expo': string;
|
|
8
|
+
};
|
|
9
|
+
export declare class AuthModule extends BaseModule {
|
|
10
|
+
/**
|
|
11
|
+
* Initiate the "magic link" login flow for a user. If the flow is successful,
|
|
12
|
+
* this method will return a Decentralized ID token (with a default lifespan
|
|
13
|
+
* of 15 minutes).
|
|
14
|
+
*/
|
|
15
|
+
loginWithMagicLink(configuration: LoginWithMagicLinkConfiguration): import("..").PromiEvent<string | null, {
|
|
16
|
+
"email-sent": () => void;
|
|
17
|
+
"email-not-deliverable": () => void;
|
|
18
|
+
retry: () => void;
|
|
19
|
+
} & {
|
|
20
|
+
"device-needs-approval": () => void;
|
|
21
|
+
"device-verification-email-sent": () => void;
|
|
22
|
+
"device-verification-link-expired": () => void;
|
|
23
|
+
"device-approved": () => void;
|
|
24
|
+
"device-retry": () => void;
|
|
25
|
+
} & {
|
|
26
|
+
done: (result: string | null) => void;
|
|
27
|
+
error: (reason: any) => void;
|
|
28
|
+
settled: () => void;
|
|
29
|
+
"closed-by-user": () => void;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Initiate an SMS login flow for a user. If successful,
|
|
33
|
+
* this method will return a Decenteralized ID token (with a default lifespan
|
|
34
|
+
* of 15 minutes)
|
|
35
|
+
*/
|
|
36
|
+
loginWithSMS(configuration: LoginWithSmsConfiguration): import("..").PromiEvent<string | null, {
|
|
37
|
+
"verify-sms-otp": (otp: string) => void;
|
|
38
|
+
cancel: () => void;
|
|
39
|
+
retry: () => void;
|
|
40
|
+
"sms-otp-sent": () => void;
|
|
41
|
+
"invalid-sms-otp": () => void;
|
|
42
|
+
"expired-sms-otp": () => void;
|
|
43
|
+
} & {
|
|
44
|
+
"device-needs-approval": () => void;
|
|
45
|
+
"device-verification-email-sent": () => void;
|
|
46
|
+
"device-verification-link-expired": () => void;
|
|
47
|
+
"device-approved": () => void;
|
|
48
|
+
"device-retry": () => void;
|
|
49
|
+
} & {
|
|
50
|
+
done: (result: string | null) => void;
|
|
51
|
+
error: (reason: any) => void;
|
|
52
|
+
settled: () => void;
|
|
53
|
+
"closed-by-user": () => void;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Initiate an Email with OTP login flow for a user. If successful,
|
|
57
|
+
* this method will return a Decenteralized ID token (with a default lifespan
|
|
58
|
+
* of 15 minutes)
|
|
59
|
+
*/
|
|
60
|
+
loginWithEmailOTP(configuration: LoginWithEmailOTPConfiguration): import("..").PromiEvent<string | null, {
|
|
61
|
+
"email-otp-sent": () => void;
|
|
62
|
+
"login-throttled": () => void;
|
|
63
|
+
"invalid-email-otp": () => void;
|
|
64
|
+
"invalid-mfa-otp": () => void;
|
|
65
|
+
"expired-email-otp": () => void;
|
|
66
|
+
"mfa-sent-handle": () => void;
|
|
67
|
+
"recovery-code-sent-handle": () => void;
|
|
68
|
+
"invalid-recovery-code": () => void;
|
|
69
|
+
"recovery-code-success": () => void;
|
|
70
|
+
"Auth/id-token-created": (idToken: string) => void;
|
|
71
|
+
"Wallet/wallet-info-fetched": () => void;
|
|
72
|
+
"verify-email-otp": (otp: string) => void;
|
|
73
|
+
"verify-mfa-code": (mfa: string) => void;
|
|
74
|
+
"lost-device": () => void;
|
|
75
|
+
"verify-recovery-code": (recoveryCode: string) => void;
|
|
76
|
+
cancel: () => void;
|
|
77
|
+
} & {
|
|
78
|
+
"device-needs-approval": () => void;
|
|
79
|
+
"device-verification-email-sent": () => void;
|
|
80
|
+
"device-verification-link-expired": () => void;
|
|
81
|
+
"device-approved": () => void;
|
|
82
|
+
"device-retry": () => void;
|
|
83
|
+
} & {
|
|
84
|
+
done: (result: string | null) => void;
|
|
85
|
+
error: (reason: any) => void;
|
|
86
|
+
settled: () => void;
|
|
87
|
+
"closed-by-user": () => void;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Log a user in with a special one-time-use credential token. This is
|
|
91
|
+
* currently used during magic link flows with a configured redirect to
|
|
92
|
+
* hydrate the user session at the end of the flow. If the flow is successful,
|
|
93
|
+
* this method will return a Decentralized ID token (with a default lifespan
|
|
94
|
+
* of 15 minutes).
|
|
95
|
+
*
|
|
96
|
+
* If no argument is provided, a credential is automatically parsed from
|
|
97
|
+
* `window.location.search`.
|
|
98
|
+
*/
|
|
99
|
+
loginWithCredential(configuration?: LoginWithCredentialConfiguration): import("..").PromiEvent<string | null, {
|
|
100
|
+
done: (result: string | null) => void;
|
|
101
|
+
error: (reason: any) => void;
|
|
102
|
+
settled: () => void;
|
|
103
|
+
"closed-by-user": () => void;
|
|
104
|
+
}>;
|
|
105
|
+
setAuthorizationToken(jwt: string): import("..").PromiEvent<boolean, {
|
|
106
|
+
done: (result: boolean) => void;
|
|
107
|
+
error: (reason: any) => void;
|
|
108
|
+
settled: () => void;
|
|
109
|
+
"closed-by-user": () => void;
|
|
110
|
+
}>;
|
|
111
|
+
updateEmailWithUI(configuration: UpdateEmailConfiguration): import("..").PromiEvent<string | null, {
|
|
112
|
+
"UpdateEmail/new-email-needs-verification": () => void;
|
|
113
|
+
"UpdateEmail/email-updated": () => void;
|
|
114
|
+
"UpdateEmail/new-email-invalid-email-otp": () => void;
|
|
115
|
+
"UpdateEmail/new-email-verification-email-not-deliverable": () => void;
|
|
116
|
+
"UpdateEmail/new-email-verification-email-expired": () => void;
|
|
117
|
+
"UpdateEmail/new-email-verification-email-sent": () => void;
|
|
118
|
+
"UpdateEmail/new-email-invalid": () => void;
|
|
119
|
+
"UpdateEmail/new-email-already-exists": () => void;
|
|
120
|
+
"UpdateEmail/new-email-verification-cancel": () => void;
|
|
121
|
+
"UpdateEmail/retry-with-new-email": (email?: string) => void;
|
|
122
|
+
"UpdateEmail/new-email-verify-otp": (otp: string) => void;
|
|
123
|
+
} & import("@magic-sdk/types").RecencyCheckEventHandlers & {
|
|
124
|
+
done: (result: string | null) => void;
|
|
125
|
+
error: (reason: any) => void;
|
|
126
|
+
settled: () => void;
|
|
127
|
+
"closed-by-user": () => void;
|
|
128
|
+
}>;
|
|
129
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { createJsonRpcRequestPayload, standardizeJsonRpcRequestPayload } from '../core/json-rpc';
|
|
2
|
+
import { BaseModule } from './base-module';
|
|
3
|
+
import { SDKBase, MagicSDKAdditionalConfiguration, MagicSDKExtensionsOption } from '../core/sdk';
|
|
4
|
+
import { MagicExtensionError, MagicExtensionWarning } from '../core/sdk-exceptions';
|
|
5
|
+
import { createPromiEvent, encodeJSON, decodeJSON, storage, isPromiEvent } from '../util';
|
|
6
|
+
export declare abstract class BaseExtension<TName extends string, TConfig extends any = any> extends BaseModule {
|
|
7
|
+
/**
|
|
8
|
+
* A structure describing the platform and version compatibility of this
|
|
9
|
+
* extension.
|
|
10
|
+
*/
|
|
11
|
+
compat?: {
|
|
12
|
+
'magic-sdk': boolean | string;
|
|
13
|
+
'@magic-sdk/react-native': boolean | string;
|
|
14
|
+
'@magic-sdk/react-native-bare': boolean | string;
|
|
15
|
+
'@magic-sdk/react-native-expo': boolean | string;
|
|
16
|
+
};
|
|
17
|
+
abstract readonly name: TName;
|
|
18
|
+
abstract readonly config: TConfig;
|
|
19
|
+
private __sdk_access_field_descriptors__;
|
|
20
|
+
private __is_initialized__;
|
|
21
|
+
protected utils: {
|
|
22
|
+
createPromiEvent: typeof createPromiEvent;
|
|
23
|
+
isPromiEvent: typeof isPromiEvent;
|
|
24
|
+
encodeJSON: typeof encodeJSON;
|
|
25
|
+
decodeJSON: typeof decodeJSON;
|
|
26
|
+
createJsonRpcRequestPayload: typeof createJsonRpcRequestPayload;
|
|
27
|
+
standardizeJsonRpcRequestPayload: typeof standardizeJsonRpcRequestPayload;
|
|
28
|
+
storage: typeof storage;
|
|
29
|
+
};
|
|
30
|
+
constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Registers a Magic SDK instance with this Extension.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
init(sdk: SDKBase): void;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a deprecation warning wrapped with a native Magic SDK warning type.
|
|
39
|
+
* Best practice is to warn users of upcoming deprecations at least one major
|
|
40
|
+
* version before the change is implemented. You can use this method to
|
|
41
|
+
* communicate deprecations in a manner consistent with Magic SDK core code.
|
|
42
|
+
*/
|
|
43
|
+
protected createDeprecationWarning(options: {
|
|
44
|
+
method: string;
|
|
45
|
+
removalVersion: string;
|
|
46
|
+
useInstead?: string;
|
|
47
|
+
}): MagicExtensionWarning;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a warning wrapped with a native Magic SDK warning type. This
|
|
50
|
+
* maintains consistency in warning messaging for consumers of Magic SDK and
|
|
51
|
+
* this Extension.
|
|
52
|
+
*/
|
|
53
|
+
protected createWarning(code: string | number, message: string): MagicExtensionWarning;
|
|
54
|
+
/**
|
|
55
|
+
* Creates an error wrapped with a native Magic SDK error type. This maintains
|
|
56
|
+
* consistency in error handling for consumers of Magic SDK and this
|
|
57
|
+
* Extension.
|
|
58
|
+
*/
|
|
59
|
+
protected createError<TData = any>(code: string | number, message: string, data: TData): MagicExtensionError<TData>;
|
|
60
|
+
}
|
|
61
|
+
declare abstract class InternalExtension<TName extends string, TConfig extends any = any> extends BaseExtension<TName> {
|
|
62
|
+
abstract readonly config: TConfig;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A base class representing "extensions" to the core Magic JS APIs. Extensions
|
|
66
|
+
* enable new functionality by composing Magic endpoints methods together.
|
|
67
|
+
*/
|
|
68
|
+
export declare class Extension {
|
|
69
|
+
/**
|
|
70
|
+
* This is a special constructor used to mark "official" extensions. These
|
|
71
|
+
* extensions are designed for special interaction with the Magic iframe using
|
|
72
|
+
* custom JSON RPC methods, business logic, and global configurations. This is
|
|
73
|
+
* intended for internal-use only (and provides no useful advantage to
|
|
74
|
+
* open-source extension developers over the regular `Extension` class).
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
static Internal: typeof InternalExtension;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* These fields are exposed on the `Extension` type,
|
|
82
|
+
* but should be hidden from the public interface.
|
|
83
|
+
*/
|
|
84
|
+
type HiddenExtensionFields = 'name' | 'init' | 'config' | 'compat';
|
|
85
|
+
/**
|
|
86
|
+
* Gets the type contained in an array type.
|
|
87
|
+
*/
|
|
88
|
+
type UnwrapArray<T extends any[]> = T extends Array<infer P> ? P : never;
|
|
89
|
+
/**
|
|
90
|
+
* Create a union type of Extension names from an
|
|
91
|
+
* array of Extension types given by `TExt`.
|
|
92
|
+
*/
|
|
93
|
+
type ExtensionNames<TExt extends BaseExtension<string>[]> = UnwrapArray<TExt> extends BaseExtension<infer R> ? R : never;
|
|
94
|
+
/**
|
|
95
|
+
* From the literal Extension name type given by `TExtName`,
|
|
96
|
+
* extract a dictionary of Extension types.
|
|
97
|
+
*/
|
|
98
|
+
type GetExtensionFromName<TExt extends BaseExtension<string>[], TExtName extends string> = {
|
|
99
|
+
[P in TExtName]: Extract<UnwrapArray<TExt>, BaseExtension<TExtName>>;
|
|
100
|
+
}[TExtName];
|
|
101
|
+
/**
|
|
102
|
+
* Wraps a Magic SDK constructor with the necessary type
|
|
103
|
+
* information to support a strongly-typed `Extension` interface.
|
|
104
|
+
*/
|
|
105
|
+
export type WithExtensions<SDK extends SDKBase> = {
|
|
106
|
+
new <TCustomExtName extends string, TExt extends MagicSDKExtensionsOption<TCustomExtName>>(apiKey: string, options?: MagicSDKAdditionalConfiguration<TCustomExtName, TExt>): InstanceWithExtensions<SDK, TExt>;
|
|
107
|
+
};
|
|
108
|
+
export type InstanceWithExtensions<SDK extends SDKBase, TExt extends MagicSDKExtensionsOption> = SDK & {
|
|
109
|
+
[P in Exclude<TExt extends BaseExtension<string>[] ? ExtensionNames<TExt> : keyof TExt, number>]: TExt extends BaseExtension<string>[] ? Omit<GetExtensionFromName<TExt, P>, HiddenExtensionFields> : TExt extends {
|
|
110
|
+
[P in Exclude<TExt extends BaseExtension<string>[] ? ExtensionNames<TExt> : keyof TExt, number>]: BaseExtension<string>;
|
|
111
|
+
} ? Omit<TExt[P], HiddenExtensionFields> : never;
|
|
112
|
+
};
|
|
113
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { JsonRpcRequestPayload, IntermediaryEvents } from '@magic-sdk/types';
|
|
2
|
+
import type { SDKBase } from '../core/sdk';
|
|
3
|
+
import type { ViewController } from '../core/view-controller';
|
|
4
|
+
import type { EventsDefinition } from '../util/events';
|
|
5
|
+
export declare class BaseModule {
|
|
6
|
+
protected sdk: SDKBase;
|
|
7
|
+
constructor(sdk: SDKBase);
|
|
8
|
+
/**
|
|
9
|
+
* The `ViewController` for the SDK instance registered to this module.
|
|
10
|
+
*/
|
|
11
|
+
protected get overlay(): ViewController;
|
|
12
|
+
/**
|
|
13
|
+
* Emits promisified requests to the Magic `<iframe>` context.
|
|
14
|
+
*/
|
|
15
|
+
protected request<ResultType = any, Events extends EventsDefinition = void>(payload: Partial<JsonRpcRequestPayload>): import("../util/promise-tools").PromiEvent<ResultType, Events extends void ? {
|
|
16
|
+
done: (result: ResultType) => void;
|
|
17
|
+
error: (reason: any) => void;
|
|
18
|
+
settled: () => void;
|
|
19
|
+
"closed-by-user": () => void;
|
|
20
|
+
} : Events & {
|
|
21
|
+
done: (result: ResultType) => void;
|
|
22
|
+
error: (reason: any) => void;
|
|
23
|
+
settled: () => void;
|
|
24
|
+
"closed-by-user": () => void;
|
|
25
|
+
}>;
|
|
26
|
+
protected createIntermediaryEvent<T = Function>(eventType: IntermediaryEvents, payloadId: string): T;
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NFTCheckoutRequest, NFTCheckoutEvents, NFTPurchaseRequest, NFTPurchaseResponse, NFTTransferRequest } from '@magic-sdk/types';
|
|
2
|
+
import { BaseModule } from './base-module';
|
|
3
|
+
export declare class NFTModule extends BaseModule {
|
|
4
|
+
purchase(options: NFTPurchaseRequest): import("..").PromiEvent<NFTPurchaseResponse, {
|
|
5
|
+
done: (result: NFTPurchaseResponse) => void;
|
|
6
|
+
error: (reason: any) => void;
|
|
7
|
+
settled: () => void;
|
|
8
|
+
"closed-by-user": () => void;
|
|
9
|
+
}>;
|
|
10
|
+
checkout(options: NFTCheckoutRequest): import("..").PromiEvent<import("@magic-sdk/types").NFTResponse, NFTCheckoutEvents & {
|
|
11
|
+
done: (result: import("@magic-sdk/types").NFTResponse) => void;
|
|
12
|
+
error: (reason: any) => void;
|
|
13
|
+
settled: () => void;
|
|
14
|
+
"closed-by-user": () => void;
|
|
15
|
+
}>;
|
|
16
|
+
transfer(options: NFTTransferRequest): import("..").PromiEvent<import("@magic-sdk/types").NFTResponse, {
|
|
17
|
+
done: (result: import("@magic-sdk/types").NFTResponse) => void;
|
|
18
|
+
error: (reason: any) => void;
|
|
19
|
+
settled: () => void;
|
|
20
|
+
"closed-by-user": () => void;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { JsonRpcRequestPayload, JsonRpcRequestCallback, JsonRpcBatchRequestCallback, JsonRpcResponsePayload, ProviderEnableEvents } from '@magic-sdk/types';
|
|
2
|
+
import { BaseModule } from './base-module';
|
|
3
|
+
import { PromiEvent } from '../util/promise-tools';
|
|
4
|
+
import { EventsDefinition, TypedEmitter } from '../util/events';
|
|
5
|
+
/** */
|
|
6
|
+
export declare class RPCProviderModule extends BaseModule implements TypedEmitter {
|
|
7
|
+
readonly isMagic = true;
|
|
8
|
+
sendAsync(payload: Partial<JsonRpcRequestPayload>, onRequestComplete: JsonRpcRequestCallback): void;
|
|
9
|
+
sendAsync(payload: Partial<JsonRpcRequestPayload>[], onRequestComplete: JsonRpcBatchRequestCallback): void;
|
|
10
|
+
sendAsync(payload: Partial<JsonRpcRequestPayload> | Partial<JsonRpcRequestPayload>[], onRequestComplete: JsonRpcRequestCallback | JsonRpcBatchRequestCallback): void;
|
|
11
|
+
send<ResultType = any>(method: string, params?: any[]): PromiEvent<ResultType>;
|
|
12
|
+
send(payload: JsonRpcRequestPayload | JsonRpcRequestPayload[], onRequestComplete: JsonRpcRequestCallback): void;
|
|
13
|
+
send<ResultType>(payload: JsonRpcRequestPayload, none: void): JsonRpcResponsePayload<ResultType>;
|
|
14
|
+
enable(): PromiEvent<string[], ProviderEnableEvents & {
|
|
15
|
+
done: (result: string[]) => void;
|
|
16
|
+
error: (reason: any) => void;
|
|
17
|
+
settled: () => void;
|
|
18
|
+
"closed-by-user": () => void;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Here, we wrap `BaseModule.request` with an additional check
|
|
22
|
+
* to determine if the RPC method requires a test-mode prefix.
|
|
23
|
+
*/
|
|
24
|
+
protected request<ResultType = any, Events extends EventsDefinition = void>(payload: Partial<JsonRpcRequestPayload>): PromiEvent<ResultType, Events extends void ? {
|
|
25
|
+
done: (result: ResultType) => void;
|
|
26
|
+
error: (reason: any) => void;
|
|
27
|
+
settled: () => void;
|
|
28
|
+
"closed-by-user": () => void;
|
|
29
|
+
} : Events & {
|
|
30
|
+
done: (result: ResultType) => void;
|
|
31
|
+
error: (reason: any) => void;
|
|
32
|
+
settled: () => void;
|
|
33
|
+
"closed-by-user": () => void;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Prefixes Ethereum RPC methods with a `testMode` identifier. This is done so
|
|
37
|
+
* that Magic's <iframe> can handle signing methods using test-specific keys.
|
|
38
|
+
*/
|
|
39
|
+
private prefixPayloadMethodForTestMode;
|
|
40
|
+
on: (event: string | symbol, fn: (...args: any[]) => void, context?: any) => this;
|
|
41
|
+
once: (event: string | symbol, fn: (...args: any[]) => void, context?: any) => this;
|
|
42
|
+
addListener: (event: string | symbol, fn: (...args: any[]) => void, context?: any) => this;
|
|
43
|
+
off: (event: string | symbol, fn?: ((...args: any[]) => void) | undefined, context?: any, once?: boolean | undefined) => this;
|
|
44
|
+
removeListener: (event: string | symbol, fn?: ((...args: any[]) => void) | undefined, context?: any, once?: boolean | undefined) => this;
|
|
45
|
+
removeAllListeners: (event?: string | symbol | undefined) => this;
|
|
46
|
+
emit: <T extends string | symbol>(event: T, ...args: any[]) => boolean;
|
|
47
|
+
eventNames: () => (string | symbol)[];
|
|
48
|
+
listeners: <T extends string | symbol>(event: T) => ((...args: any[]) => void)[];
|
|
49
|
+
listenerCount: (event: string | symbol) => number;
|
|
50
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { JsonRpcRequestPayload, ThirdPartyWalletEvents } from '@magic-sdk/types';
|
|
2
|
+
import { BaseModule } from './base-module';
|
|
3
|
+
import { PromiEvent } from '../util';
|
|
4
|
+
export declare class ThirdPartyWalletsModule extends BaseModule {
|
|
5
|
+
eventListeners: {
|
|
6
|
+
event: ThirdPartyWalletEvents;
|
|
7
|
+
callback: (payloadId: string) => Promise<void>;
|
|
8
|
+
}[];
|
|
9
|
+
enabledWallets: Record<string, boolean>;
|
|
10
|
+
isConnected: boolean;
|
|
11
|
+
resetThirdPartyWalletState(): void;
|
|
12
|
+
requestOverride(payload: Partial<JsonRpcRequestPayload>): PromiEvent<any, {
|
|
13
|
+
done: (result: any) => void;
|
|
14
|
+
error: (reason: any) => void;
|
|
15
|
+
settled: () => void;
|
|
16
|
+
"closed-by-user": () => void;
|
|
17
|
+
}>;
|
|
18
|
+
private isLoggedIn;
|
|
19
|
+
private getInfo;
|
|
20
|
+
private logout;
|
|
21
|
+
private web3modalRequest;
|
|
22
|
+
private web3modalIsLoggedIn;
|
|
23
|
+
private formatWeb3modalGetInfoResponse;
|
|
24
|
+
private web3modalGetInfo;
|
|
25
|
+
private web3modalLogout;
|
|
26
|
+
}
|