@crossmint/client-sdk-smart-wallet 0.1.2 → 0.1.3
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/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +254 -119
- package/dist/index.d.ts +254 -119
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -12
- package/src/SmartWalletSDK.test.ts +12 -13
- package/src/SmartWalletSDK.ts +33 -26
- package/src/api/APIErrorService.ts +10 -7
- package/src/api/BaseCrossmintService.ts +3 -4
- package/src/api/CrossmintWalletService.test.ts +9 -9
- package/src/api/CrossmintWalletService.ts +39 -16
- package/src/blockchain/chains.ts +25 -2
- package/src/blockchain/transfer.ts +1 -1
- package/src/blockchain/wallets/EVMSmartWallet.ts +49 -42
- package/src/blockchain/wallets/account/config.ts +60 -0
- package/src/blockchain/wallets/account/creator.ts +36 -0
- package/src/blockchain/wallets/account/eoa.ts +50 -0
- package/src/blockchain/wallets/{passkey.ts → account/passkey.ts} +32 -32
- package/src/blockchain/wallets/account/signer.ts +44 -0
- package/src/blockchain/wallets/account/strategy.ts +5 -0
- package/src/blockchain/wallets/clientDecorator.ts +6 -6
- package/src/blockchain/wallets/paymaster.ts +12 -15
- package/src/blockchain/wallets/service.ts +38 -143
- package/src/error/index.ts +25 -117
- package/src/error/processor.ts +5 -6
- package/src/index.ts +16 -12
- package/src/services/logging/ConsoleProvider.ts +3 -12
- package/src/services/logging/DatadogProvider.ts +1 -1
- package/src/types/internal.ts +41 -20
- package/src/types/{Config.ts → params.ts} +0 -5
- package/src/types/schema.ts +63 -0
- package/src/types/service.ts +31 -0
- package/src/utils/api.ts +39 -0
- package/src/utils/constants.ts +2 -0
- package/src/utils/log.ts +1 -109
- package/src/utils/signer.ts +14 -16
- package/src/blockchain/wallets/eoa.ts +0 -49
- package/src/types/API.ts +0 -40
- package/src/utils/log.test.ts +0 -76
- /package/src/types/{Tokens.ts → token.ts} +0 -0
package/src/error/index.ts
CHANGED
|
@@ -1,192 +1,100 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export const SmartWalletErrors = {
|
|
4
|
-
NOT_AUTHORIZED: "smart-wallet:not-authorized",
|
|
5
|
-
TRANSFER: "smart-wallet:transfer.error",
|
|
6
|
-
CROSSMINT_SERVICE: "smart-wallet:crossmint-service.error",
|
|
7
|
-
ERROR_JWT_EXPIRED: "smart-wallet:not-authorized.jwt-expired",
|
|
8
|
-
ERROR_JWT_INVALID: "smart-wallet:not-authorized.jwt-invalid",
|
|
9
|
-
ERROR_JWT_DECRYPTION: "smart-wallet:not-authorized.jwt-decryption",
|
|
10
|
-
ERROR_JWT_IDENTIFIER: "smart-wallet:not-authorized.jwt-identifier",
|
|
11
|
-
ERROR_USER_WALLET_ALREADY_CREATED: "smart-wallet:user-wallet-already-created.error",
|
|
12
|
-
ERROR_OUT_OF_CREDITS: "smart-wallet:out-of-credits.error",
|
|
13
|
-
ERROR_WALLET_CONFIG: "smart-wallet:wallet-config.error",
|
|
14
|
-
ERROR_ADMIN_MISMATCH: "smart-wallet:wallet-config.admin-mismatch",
|
|
15
|
-
ERROR_PASSKEY_MISMATCH: "smart-wallet:wallet-config.passkey-mismatch",
|
|
16
|
-
ERROR_PASSKEY_PROMPT: "smart-wallet:passkey.prompt",
|
|
17
|
-
ERROR_PASSKEY_INCOMPATIBLE_AUTHENTICATOR: "smart-wallet.passkey.incompatible-authenticator",
|
|
18
|
-
ERROR_PASSKEY_REGISTRATION: "smart-wallet:passkey.registration",
|
|
19
|
-
ERROR_ADMIN_SIGNER_ALREADY_USED: "smart-wallet:wallet-config.admin-signer-already-used",
|
|
20
|
-
ERROR_PROJECT_NONCUSTODIAL_WALLETS_NOT_ENABLED: "smart-wallet:wallet-config.non-custodial-wallets-not-enabled",
|
|
21
|
-
UNCATEGORIZED: "smart-wallet:uncategorized", // catch-all error code
|
|
22
|
-
} as const;
|
|
23
|
-
export type SmartWalletErrorCode = (typeof SmartWalletErrors)[keyof typeof SmartWalletErrors];
|
|
24
|
-
|
|
25
|
-
export class SmartWalletSDKError extends Error {
|
|
26
|
-
public readonly code: SmartWalletErrorCode;
|
|
27
|
-
public readonly details?: string;
|
|
28
|
-
|
|
29
|
-
constructor(message: string, details?: string, code: SmartWalletErrorCode = SmartWalletErrors.UNCATEGORIZED) {
|
|
30
|
-
super(message);
|
|
31
|
-
this.details = details;
|
|
32
|
-
this.code = code;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
import { CrossmintSDKError, SmartWalletErrorCode } from "@crossmint/client-sdk-base";
|
|
35
2
|
|
|
36
|
-
|
|
37
|
-
constructor(message: string) {
|
|
38
|
-
super(message, undefined, SmartWalletErrors.TRANSFER);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
3
|
+
import { PasskeyDisplay, SignerDisplay } from "../types/service";
|
|
41
4
|
|
|
42
|
-
export class
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
constructor(message: string, status?: number) {
|
|
46
|
-
super(message, undefined, SmartWalletErrors.CROSSMINT_SERVICE);
|
|
47
|
-
this.status = status;
|
|
5
|
+
export class SmartWalletError extends CrossmintSDKError {
|
|
6
|
+
constructor(message: string, details?: string, code: SmartWalletErrorCode = SmartWalletErrorCode.UNCATEGORIZED) {
|
|
7
|
+
super(message, code, details);
|
|
48
8
|
}
|
|
49
9
|
}
|
|
50
10
|
|
|
51
|
-
export class AdminMismatchError extends
|
|
11
|
+
export class AdminMismatchError extends SmartWalletError {
|
|
52
12
|
public readonly required: SignerDisplay;
|
|
53
13
|
public readonly used?: SignerDisplay;
|
|
54
14
|
|
|
55
15
|
constructor(message: string, required: SignerDisplay, used?: SignerDisplay) {
|
|
56
|
-
super(message,
|
|
16
|
+
super(message, SmartWalletErrorCode.ADMIN_MISMATCH);
|
|
57
17
|
this.required = required;
|
|
58
18
|
this.used = used;
|
|
59
19
|
}
|
|
60
20
|
}
|
|
61
21
|
|
|
62
|
-
export class PasskeyMismatchError extends
|
|
22
|
+
export class PasskeyMismatchError extends SmartWalletError {
|
|
63
23
|
public readonly required: PasskeyDisplay;
|
|
64
24
|
public readonly used?: PasskeyDisplay;
|
|
65
25
|
|
|
66
26
|
constructor(message: string, required: PasskeyDisplay, used?: PasskeyDisplay) {
|
|
67
|
-
super(message,
|
|
27
|
+
super(message, SmartWalletErrorCode.PASSKEY_MISMATCH);
|
|
68
28
|
this.required = required;
|
|
69
29
|
this.used = used;
|
|
70
30
|
}
|
|
71
31
|
}
|
|
72
32
|
|
|
73
|
-
export class
|
|
74
|
-
|
|
75
|
-
super(message, undefined, SmartWalletErrors.NOT_AUTHORIZED);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export class JWTExpiredError extends NotAuthorizedError {
|
|
80
|
-
public readonly code = SmartWalletErrors.ERROR_JWT_EXPIRED;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* The expiry time of the JWT as an ISO 8601 timestamp.
|
|
84
|
-
*/
|
|
85
|
-
public readonly expiredAt: string;
|
|
86
|
-
|
|
87
|
-
constructor(expiredAt: Date) {
|
|
88
|
-
super(`JWT provided expired at timestamp ${expiredAt}`);
|
|
89
|
-
this.expiredAt = expiredAt.toISOString();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export class JWTInvalidError extends NotAuthorizedError {
|
|
94
|
-
public readonly code = SmartWalletErrors.ERROR_JWT_INVALID;
|
|
95
|
-
constructor() {
|
|
96
|
-
super("Invalid JWT provided");
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export class JWTDecryptionError extends NotAuthorizedError {
|
|
101
|
-
public readonly code = SmartWalletErrors.ERROR_JWT_DECRYPTION;
|
|
102
|
-
constructor() {
|
|
103
|
-
super("Error decrypting JWT");
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export class JWTIdentifierError extends NotAuthorizedError {
|
|
108
|
-
public readonly code = SmartWalletErrors.ERROR_JWT_IDENTIFIER;
|
|
109
|
-
public readonly identifierKey: string;
|
|
110
|
-
|
|
111
|
-
constructor(identifierKey: string) {
|
|
112
|
-
super(`Missing required identifier '${identifierKey}' in the JWT`);
|
|
113
|
-
this.identifierKey = identifierKey;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export class UserWalletAlreadyCreatedError extends SmartWalletSDKError {
|
|
118
|
-
public readonly code = SmartWalletErrors.ERROR_USER_WALLET_ALREADY_CREATED;
|
|
33
|
+
export class UserWalletAlreadyCreatedError extends SmartWalletError {
|
|
34
|
+
public readonly code = SmartWalletErrorCode.USER_WALLET_ALREADY_CREATED;
|
|
119
35
|
|
|
120
36
|
constructor(userId: string) {
|
|
121
37
|
super(`The user with userId ${userId.toString()} already has a wallet created for this project`);
|
|
122
38
|
}
|
|
123
39
|
}
|
|
124
40
|
|
|
125
|
-
export class PasskeyPromptError extends
|
|
41
|
+
export class PasskeyPromptError extends SmartWalletError {
|
|
126
42
|
public passkeyName: string;
|
|
127
43
|
|
|
128
44
|
constructor(passkeyName: string) {
|
|
129
45
|
super(
|
|
130
46
|
`Prompt was either cancelled or timed out for passkey ${passkeyName}`,
|
|
131
47
|
undefined,
|
|
132
|
-
|
|
48
|
+
SmartWalletErrorCode.PASSKEY_PROMPT
|
|
133
49
|
);
|
|
134
50
|
this.passkeyName = passkeyName;
|
|
135
51
|
}
|
|
136
52
|
}
|
|
137
53
|
|
|
138
|
-
export class PasskeyRegistrationError extends
|
|
54
|
+
export class PasskeyRegistrationError extends SmartWalletError {
|
|
139
55
|
public passkeyName: string;
|
|
140
56
|
|
|
141
57
|
constructor(passkeyName: string) {
|
|
142
58
|
super(
|
|
143
59
|
`Registration for passkey ${passkeyName} failed, either the registration took too long, or passkey signature vaildation failed.`,
|
|
144
60
|
undefined,
|
|
145
|
-
|
|
61
|
+
SmartWalletErrorCode.PASSKEY_REGISTRATION
|
|
146
62
|
);
|
|
147
63
|
this.passkeyName = passkeyName;
|
|
148
64
|
}
|
|
149
65
|
}
|
|
150
66
|
|
|
151
|
-
export class PasskeyIncompatibleAuthenticatorError extends
|
|
67
|
+
export class PasskeyIncompatibleAuthenticatorError extends SmartWalletError {
|
|
152
68
|
public passkeyName: string;
|
|
153
69
|
|
|
154
70
|
constructor(passkeyName: string) {
|
|
155
71
|
super(
|
|
156
72
|
`User selected authenticator for passkey ${passkeyName} is not compatible with Crossmint's Smart Wallets.`,
|
|
157
73
|
undefined,
|
|
158
|
-
|
|
74
|
+
SmartWalletErrorCode.PASSKEY_INCOMPATIBLE_AUTHENTICATOR
|
|
159
75
|
);
|
|
160
76
|
this.passkeyName = passkeyName;
|
|
161
77
|
}
|
|
162
78
|
}
|
|
163
79
|
|
|
164
|
-
export class
|
|
165
|
-
constructor(message?: string) {
|
|
166
|
-
super(
|
|
167
|
-
"You've run out of Crossmint API credits. Visit https://docs.crossmint.com/docs/errors for more information",
|
|
168
|
-
undefined,
|
|
169
|
-
SmartWalletErrors.ERROR_OUT_OF_CREDITS
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export class ConfigError extends SmartWalletSDKError {
|
|
80
|
+
export class ConfigError extends SmartWalletError {
|
|
175
81
|
constructor(message: string) {
|
|
176
|
-
super(message, undefined,
|
|
82
|
+
super(message, undefined, SmartWalletErrorCode.WALLET_CONFIG);
|
|
177
83
|
}
|
|
178
84
|
}
|
|
179
85
|
|
|
180
86
|
export class AdminAlreadyUsedError extends ConfigError {
|
|
181
|
-
public readonly code =
|
|
87
|
+
public readonly code = SmartWalletErrorCode.ADMIN_SIGNER_ALREADY_USED;
|
|
182
88
|
constructor() {
|
|
183
89
|
super("This signer was already used to create another wallet. Please use a different signer.");
|
|
184
90
|
}
|
|
185
91
|
}
|
|
186
92
|
|
|
187
|
-
export class
|
|
188
|
-
public readonly code =
|
|
93
|
+
export class SmartWalletsNotEnabledError extends ConfigError {
|
|
94
|
+
public readonly code = SmartWalletErrorCode.SMART_WALLETS_NOT_ENABLED;
|
|
189
95
|
constructor() {
|
|
190
|
-
super(
|
|
96
|
+
super(
|
|
97
|
+
"Smart wallets are not enabled for this project. They can be enabled on the project settings page in the developer console."
|
|
98
|
+
);
|
|
191
99
|
}
|
|
192
100
|
}
|
package/src/error/processor.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { logError } from "@/services/logging";
|
|
2
|
-
import { DatadogProvider } from "@/services/logging/DatadogProvider";
|
|
3
|
-
import { SDK_VERSION } from "@/utils/constants";
|
|
4
1
|
import { BaseError, stringify } from "viem";
|
|
5
2
|
|
|
6
|
-
import {
|
|
3
|
+
import { SmartWalletError } from ".";
|
|
4
|
+
import { DatadogProvider } from "../services/logging/DatadogProvider";
|
|
5
|
+
import { SDK_VERSION } from "../utils/constants";
|
|
7
6
|
|
|
8
7
|
export class ErrorProcessor {
|
|
9
8
|
constructor(private readonly logger: DatadogProvider) {}
|
|
10
9
|
|
|
11
|
-
public map(error: unknown, fallback:
|
|
10
|
+
public map(error: unknown, fallback: SmartWalletError): SmartWalletError | BaseError {
|
|
12
11
|
this.record(error);
|
|
13
12
|
|
|
14
|
-
if (error instanceof
|
|
13
|
+
if (error instanceof SmartWalletError) {
|
|
15
14
|
return error;
|
|
16
15
|
}
|
|
17
16
|
|
package/src/index.ts
CHANGED
|
@@ -9,21 +9,13 @@ export type {
|
|
|
9
9
|
PasskeySigner,
|
|
10
10
|
EOASigner,
|
|
11
11
|
WalletParams,
|
|
12
|
-
} from "./types/
|
|
12
|
+
} from "./types/params";
|
|
13
13
|
|
|
14
|
-
export type { TransferType, ERC20TransferType, NFTTransferType, SFTTransferType } from "./types/
|
|
14
|
+
export type { TransferType, ERC20TransferType, NFTTransferType, SFTTransferType } from "./types/token";
|
|
15
15
|
|
|
16
16
|
export {
|
|
17
|
-
|
|
18
|
-
CrossmintServiceError,
|
|
19
|
-
SmartWalletSDKError,
|
|
20
|
-
JWTDecryptionError,
|
|
21
|
-
JWTExpiredError,
|
|
22
|
-
JWTIdentifierError,
|
|
23
|
-
JWTInvalidError,
|
|
24
|
-
NotAuthorizedError,
|
|
17
|
+
SmartWalletError,
|
|
25
18
|
UserWalletAlreadyCreatedError,
|
|
26
|
-
OutOfCreditsError,
|
|
27
19
|
AdminAlreadyUsedError,
|
|
28
20
|
AdminMismatchError,
|
|
29
21
|
PasskeyMismatchError,
|
|
@@ -31,7 +23,19 @@ export {
|
|
|
31
23
|
PasskeyRegistrationError,
|
|
32
24
|
PasskeyIncompatibleAuthenticatorError,
|
|
33
25
|
ConfigError,
|
|
34
|
-
|
|
26
|
+
SmartWalletsNotEnabledError,
|
|
35
27
|
} from "./error";
|
|
36
28
|
|
|
29
|
+
export {
|
|
30
|
+
SmartWalletErrorCode,
|
|
31
|
+
CrossmintSDKError,
|
|
32
|
+
CrossmintServiceError,
|
|
33
|
+
TransferError,
|
|
34
|
+
JWTDecryptionError,
|
|
35
|
+
JWTExpiredError,
|
|
36
|
+
JWTIdentifierError,
|
|
37
|
+
JWTInvalidError,
|
|
38
|
+
NotAuthorizedError,
|
|
39
|
+
} from "@crossmint/client-sdk-base";
|
|
40
|
+
|
|
37
41
|
export { SmartWalletSDK } from "./SmartWalletSDK";
|
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
import { BrowserLoggerInterface } from "./BrowserLoggerInterface";
|
|
2
2
|
|
|
3
|
-
// Set to true to enable logging on local development
|
|
4
|
-
const LOG_IN_LOCALHOST = false;
|
|
5
|
-
|
|
6
3
|
export class ConsoleProvider implements BrowserLoggerInterface {
|
|
7
4
|
logInfo(message: string, context?: object) {
|
|
8
|
-
|
|
9
|
-
console.log(message, context);
|
|
10
|
-
}
|
|
5
|
+
console.log(message, context);
|
|
11
6
|
}
|
|
12
7
|
|
|
13
8
|
logError(message: string, context?: object) {
|
|
14
|
-
|
|
15
|
-
console.error(message, context);
|
|
16
|
-
}
|
|
9
|
+
console.error(message, context);
|
|
17
10
|
}
|
|
18
11
|
|
|
19
12
|
logWarn(message: string, context?: object) {
|
|
20
|
-
|
|
21
|
-
console.warn(message, context);
|
|
22
|
-
}
|
|
13
|
+
console.warn(message, context);
|
|
23
14
|
}
|
|
24
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DATADOG_CLIENT_TOKEN, SCW_SERVICE } from "@/utils/constants";
|
|
2
1
|
import { datadogLogs } from "@datadog/browser-logs";
|
|
3
2
|
|
|
3
|
+
import { DATADOG_CLIENT_TOKEN, SCW_SERVICE } from "../../utils/constants";
|
|
4
4
|
import { BrowserLoggerInterface } from "./BrowserLoggerInterface";
|
|
5
5
|
|
|
6
6
|
export class DatadogProvider implements BrowserLoggerInterface {
|
package/src/types/internal.ts
CHANGED
|
@@ -2,22 +2,19 @@ import type { KernelSmartAccount } from "@zerodev/sdk";
|
|
|
2
2
|
import type { SmartAccountClient } from "permissionless";
|
|
3
3
|
import type { SmartAccount } from "permissionless/accounts";
|
|
4
4
|
import type { EntryPoint } from "permissionless/types/entrypoint";
|
|
5
|
-
import type { Chain,
|
|
5
|
+
import type { Chain, HttpTransport, PublicClient } from "viem";
|
|
6
6
|
|
|
7
7
|
import type { SmartWalletChain } from "../blockchain/chains";
|
|
8
|
-
import type {
|
|
9
|
-
import
|
|
8
|
+
import type { EOASignerConfig, PasskeySignerConfig, SignerConfig } from "../blockchain/wallets/account/signer";
|
|
9
|
+
import { SUPPORTED_ENTRYPOINT_VERSIONS, SUPPORTED_KERNEL_VERSIONS } from "../utils/constants";
|
|
10
|
+
import type { EOASigner, PasskeySigner, UserParams, WalletParams } from "./params";
|
|
10
11
|
|
|
11
|
-
export const SUPPORTED_KERNEL_VERSIONS = ["0.3.1", "0.3.0", "0.2.4"] as const;
|
|
12
12
|
export type SupportedKernelVersion = (typeof SUPPORTED_KERNEL_VERSIONS)[number];
|
|
13
|
-
|
|
14
13
|
export function isSupportedKernelVersion(version: string): version is SupportedKernelVersion {
|
|
15
14
|
return SUPPORTED_KERNEL_VERSIONS.includes(version as any);
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
export const SUPPORTED_ENTRYPOINT_VERSIONS = ["v0.6", "v0.7"] as const;
|
|
19
17
|
export type SupportedEntryPointVersion = (typeof SUPPORTED_ENTRYPOINT_VERSIONS)[number];
|
|
20
|
-
|
|
21
18
|
export function isSupportedEntryPointVersion(version: string): version is SupportedEntryPointVersion {
|
|
22
19
|
return SUPPORTED_ENTRYPOINT_VERSIONS.includes(version as any);
|
|
23
20
|
}
|
|
@@ -27,23 +24,47 @@ export interface WalletCreationParams {
|
|
|
27
24
|
chain: SmartWalletChain;
|
|
28
25
|
publicClient: PublicClient<HttpTransport>;
|
|
29
26
|
walletParams: WalletParams;
|
|
30
|
-
entryPoint:
|
|
27
|
+
entryPoint: { version: SupportedEntryPointVersion; address: EntryPoint };
|
|
31
28
|
kernelVersion: SupportedKernelVersion;
|
|
29
|
+
existingSignerConfig?: SignerConfig;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface PasskeyCreationParams extends WalletCreationParams {
|
|
33
|
+
walletParams: WalletParams & { signer: PasskeySigner };
|
|
34
|
+
existingSignerConfig?: PasskeySignerConfig;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface EOACreationParams extends WalletCreationParams {
|
|
38
|
+
walletParams: WalletParams & { signer: EOASigner };
|
|
39
|
+
existingSignerConfig?: EOASignerConfig;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isPasskeyCreationParams(params: WalletCreationParams): params is PasskeyCreationParams {
|
|
43
|
+
const hasPasskeyWalletParams =
|
|
44
|
+
"signer" in params.walletParams &&
|
|
45
|
+
"type" in params.walletParams.signer &&
|
|
46
|
+
params.walletParams.signer.type === "PASSKEY";
|
|
47
|
+
|
|
48
|
+
const signerIsPasskeyOrUndefined =
|
|
49
|
+
params.existingSignerConfig == null || params.existingSignerConfig.type === "passkeys";
|
|
50
|
+
|
|
51
|
+
return hasPasskeyWalletParams && signerIsPasskeyOrUndefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isEOACreationParams(params: WalletCreationParams): params is EOACreationParams {
|
|
55
|
+
const hasEOAWalletParams =
|
|
56
|
+
"signer" in params.walletParams &&
|
|
57
|
+
(("type" in params.walletParams.signer && params.walletParams.signer.type === "VIEM_ACCOUNT") ||
|
|
58
|
+
("request" in params.walletParams.signer && typeof params.walletParams.signer.request === "function"));
|
|
59
|
+
|
|
60
|
+
const signerIsEOAOrUndefined = params.existingSignerConfig == null || params.existingSignerConfig.type === "eoa";
|
|
61
|
+
|
|
62
|
+
return hasEOAWalletParams && signerIsEOAOrUndefined;
|
|
32
63
|
}
|
|
33
64
|
|
|
34
65
|
export interface AccountAndSigner {
|
|
35
66
|
account: KernelSmartAccount<EntryPoint, HttpTransport>;
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type PasskeyValidatorSerializedData = {
|
|
40
|
-
passkeyServerUrl: string;
|
|
41
|
-
entryPoint: Hex;
|
|
42
|
-
validatorAddress: Hex;
|
|
43
|
-
pubKeyX: string;
|
|
44
|
-
pubKeyY: string;
|
|
45
|
-
authenticatorIdHash: Hex;
|
|
46
|
-
authenticatorId: string;
|
|
47
|
-
};
|
|
67
|
+
signerConfig: SignerConfig;
|
|
68
|
+
}
|
|
48
69
|
|
|
49
70
|
export type SmartWalletClient = SmartAccountClient<EntryPoint, HttpTransport, Chain, SmartAccount<EntryPoint>>;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type { EntryPoint } from "permissionless/types/entrypoint";
|
|
2
1
|
import type { EIP1193Provider, LocalAccount } from "viem";
|
|
3
2
|
|
|
4
|
-
import type { SupportedEntryPointVersion } from "./internal";
|
|
5
|
-
|
|
6
3
|
export type SmartWalletSDKInitParams = {
|
|
7
4
|
clientApiKey: string;
|
|
8
5
|
};
|
|
@@ -31,5 +28,3 @@ export type EOASigner = EIP1193Provider | ViemAccount;
|
|
|
31
28
|
export interface WalletParams {
|
|
32
29
|
signer: EOASigner | PasskeySigner;
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
export type EntryPointDetails = { version: SupportedEntryPointVersion; address: EntryPoint };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { PasskeyValidatorContractVersion } from "@zerodev/passkey-validator";
|
|
2
|
+
import { isAddress, isHex } from "viem";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
import { SUPPORTED_ENTRYPOINT_VERSIONS, SUPPORTED_KERNEL_VERSIONS } from "../utils/constants";
|
|
6
|
+
|
|
7
|
+
const HexSchema = z.custom<`0x${string}`>((val): val is `0x${string}` => isHex(val as string), {
|
|
8
|
+
message: "Invalid hex string",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const evmAddressSchema = z.custom<`0x${string}`>((val): val is `0x${string}` => isAddress(val as string), {
|
|
12
|
+
message: "Invalid evm address",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const EOASignerDataSchema = z.object({
|
|
16
|
+
eoaAddress: evmAddressSchema,
|
|
17
|
+
type: z.literal("eoa"),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const PasskeyValidatorSerializedDataSchema = z.object({
|
|
21
|
+
entryPoint: evmAddressSchema,
|
|
22
|
+
validatorAddress: evmAddressSchema,
|
|
23
|
+
pubKeyX: z.string(),
|
|
24
|
+
pubKeyY: z.string(),
|
|
25
|
+
authenticatorIdHash: HexSchema,
|
|
26
|
+
authenticatorId: z.string(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const PasskeySignerDataSchema = PasskeyValidatorSerializedDataSchema.extend({
|
|
30
|
+
passkeyName: z.string(),
|
|
31
|
+
validatorContractVersion: z.nativeEnum(PasskeyValidatorContractVersion),
|
|
32
|
+
domain: z.string(),
|
|
33
|
+
type: z.literal("passkeys"),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const SignerDataSchema = z.discriminatedUnion("type", [PasskeySignerDataSchema, EOASignerDataSchema]);
|
|
37
|
+
|
|
38
|
+
export const SmartWalletConfigSchema = z.object({
|
|
39
|
+
kernelVersion: z.enum(SUPPORTED_KERNEL_VERSIONS, {
|
|
40
|
+
errorMap: (_, ctx) => ({
|
|
41
|
+
message: `Unsupported kernel version. Supported versions: ${SUPPORTED_KERNEL_VERSIONS.join(
|
|
42
|
+
", "
|
|
43
|
+
)}. Version used: ${ctx.data}. Please contact support`,
|
|
44
|
+
}),
|
|
45
|
+
}),
|
|
46
|
+
entryPointVersion: z.enum(SUPPORTED_ENTRYPOINT_VERSIONS, {
|
|
47
|
+
errorMap: (_, ctx) => ({
|
|
48
|
+
message: `Unsupported entry point version. Supported versions: ${SUPPORTED_ENTRYPOINT_VERSIONS.join(
|
|
49
|
+
", "
|
|
50
|
+
)}. Version used: ${ctx.data}. Please contact support`,
|
|
51
|
+
}),
|
|
52
|
+
}),
|
|
53
|
+
userId: z.string().min(1),
|
|
54
|
+
signers: z
|
|
55
|
+
.array(
|
|
56
|
+
z.object({
|
|
57
|
+
signerData: SignerDataSchema,
|
|
58
|
+
})
|
|
59
|
+
)
|
|
60
|
+
.min(0)
|
|
61
|
+
.max(1, "Invalid wallet signer configuration. Please contact support"),
|
|
62
|
+
smartContractWalletAddress: evmAddressSchema.optional(),
|
|
63
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import type { SupportedEntryPointVersion, SupportedKernelVersion } from "./internal";
|
|
4
|
+
import type {
|
|
5
|
+
EOASignerDataSchema,
|
|
6
|
+
PasskeySignerDataSchema,
|
|
7
|
+
PasskeyValidatorSerializedDataSchema,
|
|
8
|
+
SignerDataSchema,
|
|
9
|
+
SmartWalletConfigSchema,
|
|
10
|
+
} from "./schema";
|
|
11
|
+
|
|
12
|
+
export type EOASignerData = z.infer<typeof EOASignerDataSchema>;
|
|
13
|
+
export type PasskeyValidatorSerializedData = z.infer<typeof PasskeyValidatorSerializedDataSchema>;
|
|
14
|
+
export type PasskeySignerData = z.infer<typeof PasskeySignerDataSchema>;
|
|
15
|
+
export type SmartWalletConfig = z.infer<typeof SmartWalletConfigSchema>;
|
|
16
|
+
export type SignerData = z.infer<typeof SignerDataSchema>;
|
|
17
|
+
|
|
18
|
+
export type PasskeyDisplay = Pick<PasskeySignerData, "type" | "passkeyName" | "pubKeyX" | "pubKeyY">;
|
|
19
|
+
export type SignerDisplay = EOASignerData | PasskeyDisplay;
|
|
20
|
+
|
|
21
|
+
export type StoreSmartWalletParams = {
|
|
22
|
+
type: string;
|
|
23
|
+
smartContractWalletAddress: string;
|
|
24
|
+
signerData: SignerData;
|
|
25
|
+
sessionKeySignerAddress?: string;
|
|
26
|
+
version: number;
|
|
27
|
+
baseLayer: string;
|
|
28
|
+
chainId: number;
|
|
29
|
+
entryPointVersion: SupportedEntryPointVersion;
|
|
30
|
+
kernelVersion: SupportedKernelVersion;
|
|
31
|
+
};
|
package/src/utils/api.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { toHex } from "viem";
|
|
2
|
+
|
|
3
|
+
function mapObject(data: any, fn: (value: unknown) => { value: unknown; replace: boolean }): any {
|
|
4
|
+
const result = fn(data);
|
|
5
|
+
if (result.replace) {
|
|
6
|
+
return result.value;
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(data)) {
|
|
9
|
+
return data.map((item) => mapObject(item, fn));
|
|
10
|
+
} else if (data !== null && typeof data === "object") {
|
|
11
|
+
return Object.fromEntries(Object.entries(data).map(([key, value]) => [key, mapObject(value, fn)]));
|
|
12
|
+
}
|
|
13
|
+
return result.value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function bigintsToHex(data: any): any {
|
|
17
|
+
return mapObject(data, (value) => {
|
|
18
|
+
if (typeof value === "bigint") {
|
|
19
|
+
return { value: toHex(value), replace: true };
|
|
20
|
+
}
|
|
21
|
+
return { value, replace: false };
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parseBigintAPIResponse(data: any): any {
|
|
26
|
+
return mapObject(data, (value) => {
|
|
27
|
+
if (
|
|
28
|
+
value != null &&
|
|
29
|
+
typeof value == "object" &&
|
|
30
|
+
"__xm_serializedType" in value &&
|
|
31
|
+
"value" in value &&
|
|
32
|
+
value.__xm_serializedType === "bigint" &&
|
|
33
|
+
typeof value.value === "string"
|
|
34
|
+
) {
|
|
35
|
+
return { value: BigInt(value.value), replace: true };
|
|
36
|
+
}
|
|
37
|
+
return { value, replace: false };
|
|
38
|
+
});
|
|
39
|
+
}
|
package/src/utils/constants.ts
CHANGED
|
@@ -9,3 +9,5 @@ export const SDK_VERSION = "0.1.0";
|
|
|
9
9
|
export const API_VERSION = "2024-06-09";
|
|
10
10
|
export const BUNDLER_RPC = "https://rpc.zerodev.app/api/v2/bundler/";
|
|
11
11
|
export const PAYMASTER_RPC = "https://rpc.zerodev.app/api/v2/paymaster/";
|
|
12
|
+
export const SUPPORTED_KERNEL_VERSIONS = ["0.3.1", "0.3.0", "0.2.4"] as const;
|
|
13
|
+
export const SUPPORTED_ENTRYPOINT_VERSIONS = ["v0.6", "v0.7"] as const;
|