@account-kit/signer 4.0.0-alpha.9 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/esm/base.d.ts +286 -3
  2. package/dist/esm/base.js +307 -1
  3. package/dist/esm/base.js.map +1 -1
  4. package/dist/esm/client/base.d.ts +80 -1
  5. package/dist/esm/client/base.js +97 -0
  6. package/dist/esm/client/base.js.map +1 -1
  7. package/dist/esm/client/index.d.ts +162 -0
  8. package/dist/esm/client/index.js +167 -1
  9. package/dist/esm/client/index.js.map +1 -1
  10. package/dist/esm/client/types.d.ts +4 -0
  11. package/dist/esm/client/types.js.map +1 -1
  12. package/dist/esm/session/manager.js +18 -1
  13. package/dist/esm/session/manager.js.map +1 -1
  14. package/dist/esm/signer.d.ts +28 -0
  15. package/dist/esm/signer.js +24 -0
  16. package/dist/esm/signer.js.map +1 -1
  17. package/dist/esm/version.d.ts +1 -1
  18. package/dist/esm/version.js +3 -1
  19. package/dist/esm/version.js.map +1 -1
  20. package/dist/types/base.d.ts +1 -3
  21. package/dist/types/base.d.ts.map +1 -1
  22. package/dist/types/client/base.d.ts +11 -1
  23. package/dist/types/client/base.d.ts.map +1 -1
  24. package/dist/types/client/index.d.ts.map +1 -1
  25. package/dist/types/client/types.d.ts +4 -0
  26. package/dist/types/client/types.d.ts.map +1 -1
  27. package/dist/types/signer.d.ts +4 -3
  28. package/dist/types/signer.d.ts.map +1 -1
  29. package/dist/types/version.d.ts +1 -1
  30. package/dist/types/version.d.ts.map +1 -1
  31. package/package.json +10 -15
  32. package/src/base.ts +17 -3
  33. package/src/client/base.ts +21 -2
  34. package/src/client/index.ts +2 -1
  35. package/src/client/types.ts +5 -0
  36. package/src/signer.ts +5 -0
  37. package/src/version.ts +1 -1
  38. package/dist/cjs/base.d.ts +0 -37
  39. package/dist/cjs/base.js +0 -292
  40. package/dist/cjs/base.js.map +0 -1
  41. package/dist/cjs/client/base.d.ts +0 -230
  42. package/dist/cjs/client/base.js +0 -298
  43. package/dist/cjs/client/base.js.map +0 -1
  44. package/dist/cjs/client/index.d.ts +0 -146
  45. package/dist/cjs/client/index.js +0 -260
  46. package/dist/cjs/client/index.js.map +0 -1
  47. package/dist/cjs/client/types.d.ts +0 -106
  48. package/dist/cjs/client/types.js +0 -3
  49. package/dist/cjs/client/types.js.map +0 -1
  50. package/dist/cjs/errors.d.ts +0 -4
  51. package/dist/cjs/errors.js +0 -16
  52. package/dist/cjs/errors.js.map +0 -1
  53. package/dist/cjs/index.d.ts +0 -9
  54. package/dist/cjs/index.js +0 -16
  55. package/dist/cjs/index.js.map +0 -1
  56. package/dist/cjs/package.json +0 -1
  57. package/dist/cjs/session/manager.d.ts +0 -45
  58. package/dist/cjs/session/manager.js +0 -230
  59. package/dist/cjs/session/manager.js.map +0 -1
  60. package/dist/cjs/session/types.d.ts +0 -16
  61. package/dist/cjs/session/types.js +0 -3
  62. package/dist/cjs/session/types.js.map +0 -1
  63. package/dist/cjs/signer.d.ts +0 -262
  64. package/dist/cjs/signer.js +0 -34
  65. package/dist/cjs/signer.js.map +0 -1
  66. package/dist/cjs/types.d.ts +0 -14
  67. package/dist/cjs/types.js +0 -12
  68. package/dist/cjs/types.js.map +0 -1
  69. package/dist/cjs/utils/base64UrlEncode.d.ts +0 -1
  70. package/dist/cjs/utils/base64UrlEncode.js +0 -12
  71. package/dist/cjs/utils/base64UrlEncode.js.map +0 -1
  72. package/dist/cjs/utils/generateRandomBuffer.d.ts +0 -1
  73. package/dist/cjs/utils/generateRandomBuffer.js +0 -10
  74. package/dist/cjs/utils/generateRandomBuffer.js.map +0 -1
  75. package/dist/cjs/version.d.ts +0 -1
  76. package/dist/cjs/version.js +0 -5
  77. package/dist/cjs/version.js.map +0 -1
  78. package/dist/esm/package.json +0 -1
@@ -9,27 +9,310 @@ export interface BaseAlchemySignerParams<TClient extends BaseSignerClient> {
9
9
  client: TClient;
10
10
  sessionConfig?: Omit<SessionManagerParams, "client">;
11
11
  }
12
+ /**
13
+ * Base abstract class for Alchemy Signer, providing authentication and session management for smart accounts.
14
+ * Implements the `SmartAccountAuthenticator` interface and handles various signer events.
15
+ */
12
16
  export declare abstract class BaseAlchemySigner<TClient extends BaseSignerClient> implements SmartAccountAuthenticator<AuthParams, User, TClient> {
13
17
  signerType: string;
14
18
  inner: TClient;
15
19
  private sessionManager;
16
20
  private store;
21
+ /**
22
+ * Initializes an instance with the provided client and session configuration.
23
+ * This function sets up the internal store, initializes the session manager,
24
+ * registers listeners and initializes the session manager to manage session state.
25
+ *
26
+ * @param {BaseAlchemySignerParams<TClient>} param0 Object containing the client and session configuration
27
+ * @param {TClient} param0.client The client instance to be used internally
28
+ * @param {SessionConfig} param0.sessionConfig Configuration for managing sessions
29
+ */
17
30
  constructor({ client, sessionConfig }: BaseAlchemySignerParams<TClient>);
31
+ /**
32
+ * Allows you to subscribe to events emitted by the signer
33
+ *
34
+ * @param {AlchemySignerEvent} event the event to subscribe to
35
+ * @param {AlchemySignerEvents[AlchemySignerEvent]} listener the function to run when the event is emitted
36
+ * @returns {() => void} a function to remove the listener
37
+ */
18
38
  on: <E extends keyof AlchemySignerEvents>(event: E, listener: AlchemySignerEvents[E]) => () => void;
39
+ /**
40
+ * Authenticate a user with either an email or a passkey and create a session for that user
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { AlchemyWebSigner } from "@account-kit/signer";
45
+ *
46
+ * const signer = new AlchemyWebSigner({
47
+ * client: {
48
+ * connection: {
49
+ * rpcUrl: "/api/rpc",
50
+ * },
51
+ * iframeConfig: {
52
+ * iframeContainerId: "alchemy-signer-iframe-container",
53
+ * },
54
+ * },
55
+ * });
56
+ *
57
+ * const result = await signer.authenticate({
58
+ * type: "email",
59
+ * email: "foo@mail.com",
60
+ * });
61
+ * ```
62
+ *
63
+ * @param {AuthParams} params - undefined if passkey login, otherwise an object with email and bundle to resolve
64
+ * @returns {Promise<User>} the user that was authenticated
65
+ */
19
66
  authenticate: (params: AuthParams) => Promise<User>;
67
+ /**
68
+ * Clear a user session and log them out
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { AlchemyWebSigner } from "@account-kit/signer";
73
+ *
74
+ * const signer = new AlchemyWebSigner({
75
+ * client: {
76
+ * connection: {
77
+ * rpcUrl: "/api/rpc",
78
+ * },
79
+ * iframeConfig: {
80
+ * iframeContainerId: "alchemy-signer-iframe-container",
81
+ * },
82
+ * },
83
+ * });
84
+ *
85
+ * await signer.disconnect();
86
+ * ```
87
+ *
88
+ * @returns {Promise<void>} a promise that resolves when the user is logged out
89
+ */
20
90
  disconnect: () => Promise<void>;
91
+ /**
92
+ * Gets the current logged in user
93
+ * If a user has an ongoing session, it will use that session and
94
+ * try to authenticate
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * import { AlchemyWebSigner } from "@account-kit/signer";
99
+ *
100
+ * const signer = new AlchemyWebSigner({
101
+ * client: {
102
+ * connection: {
103
+ * rpcUrl: "/api/rpc",
104
+ * },
105
+ * iframeConfig: {
106
+ * iframeContainerId: "alchemy-signer-iframe-container",
107
+ * },
108
+ * },
109
+ * });
110
+ *
111
+ * // throws if not logged in
112
+ * const user = await signer.getAuthDetails();
113
+ * ```
114
+ *
115
+ * @throws if there is no user logged in
116
+ * @returns {Promise<User>} the current user
117
+ */
21
118
  getAuthDetails: () => Promise<User>;
119
+ /**
120
+ * Retrieves the address of the current user by calling the `whoami` method on `this.inner`.
121
+ *
122
+ * @returns {Promise<string>} A promise that resolves to the address of the current user.
123
+ */
22
124
  getAddress: () => Promise<`0x${string}`>;
125
+ /**
126
+ * Signs a raw message after hashing it.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * import { AlchemyWebSigner } from "@account-kit/signer";
131
+ *
132
+ * const signer = new AlchemyWebSigner({
133
+ * client: {
134
+ * connection: {
135
+ * rpcUrl: "/api/rpc",
136
+ * },
137
+ * iframeConfig: {
138
+ * iframeContainerId: "alchemy-signer-iframe-container",
139
+ * },
140
+ * },
141
+ * });
142
+ *
143
+ * const signature = await signer.signMessage("Hello, world!");
144
+ * ```
145
+ *
146
+ * @param {string} msg the message to be hashed and then signed
147
+ * @returns {Promise<string>} a promise that resolves to the signed message
148
+ */
23
149
  signMessage: (msg: SignableMessage) => Promise<`0x${string}`>;
24
- signTypedData: <const TTypedData extends TypedData | {
25
- [key: string]: unknown;
26
- }, TPrimaryType extends keyof TTypedData | "EIP712Domain" = keyof TTypedData>(params: TypedDataDefinition<TTypedData, TPrimaryType>) => Promise<Hex>;
150
+ /**
151
+ * Signs a typed message by first hashing it and then signing the hashed message using the `signRawMessage` method.
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * import { AlchemyWebSigner } from "@account-kit/signer";
156
+ *
157
+ * const signer = new AlchemyWebSigner({
158
+ * client: {
159
+ * connection: {
160
+ * rpcUrl: "/api/rpc",
161
+ * },
162
+ * iframeConfig: {
163
+ * iframeContainerId: "alchemy-signer-iframe-container",
164
+ * },
165
+ * },
166
+ * });
167
+ *
168
+ * const signature = await signer.signTypedData({
169
+ * domain: {},
170
+ * types: {},
171
+ * primaryType: "",
172
+ * message: {},
173
+ * });
174
+ * ```
175
+ *
176
+ * @param {TypedDataDefinition<TTypedData, TPrimaryType>} params The parameters for the typed message to be hashed and signed
177
+ * @returns {Promise<any>} A promise that resolves to the signed message
178
+ */
179
+ signTypedData: <const TTypedData extends TypedData | Record<string, unknown>, TPrimaryType extends keyof TTypedData | "EIP712Domain" = keyof TTypedData>(params: TypedDataDefinition<TTypedData, TPrimaryType>) => Promise<Hex>;
180
+ /**
181
+ * Serializes a transaction, signs it with a raw message, and then returns the serialized transaction with the signature.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * import { AlchemyWebSigner } from "@account-kit/signer";
186
+ *
187
+ * const signer = new AlchemyWebSigner({
188
+ * client: {
189
+ * connection: {
190
+ * rpcUrl: "/api/rpc",
191
+ * },
192
+ * iframeConfig: {
193
+ * iframeContainerId: "alchemy-signer-iframe-container",
194
+ * },
195
+ * },
196
+ * });
197
+ *
198
+ * const tx = await signer.signTransaction({
199
+ * to: "0x1234",
200
+ * value: "0x1234",
201
+ * data: "0x1234",
202
+ * });
203
+ * ```
204
+ *
205
+ * @param {Transaction} tx the transaction to be serialized and signed
206
+ * @param {{serializer?: SerializeTransactionFn}} args options for serialization
207
+ * @param {() => Hex} [args.serializer] an optional serializer function. If not provided, the default `serializeTransaction` function will be used
208
+ * @returns {Promise<string>} a promise that resolves to the serialized transaction with the signature
209
+ */
27
210
  signTransaction: CustomSource["signTransaction"];
211
+ /**
212
+ * Unauthenticated call to look up a user's organizationId by email
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * import { AlchemyWebSigner } from "@account-kit/signer";
217
+ *
218
+ * const signer = new AlchemyWebSigner({
219
+ * client: {
220
+ * connection: {
221
+ * rpcUrl: "/api/rpc",
222
+ * },
223
+ * iframeConfig: {
224
+ * iframeContainerId: "alchemy-signer-iframe-container",
225
+ * },
226
+ * },
227
+ * });
228
+ *
229
+ * const result = await signer.getUser("foo@mail.com");
230
+ * ```
231
+ *
232
+ * @param {string} email the email to lookup
233
+ * @returns {Promise<{orgId: string}>} the organization id for the user if they exist
234
+ */
28
235
  getUser: (email: string) => Promise<{
29
236
  orgId: string;
30
237
  } | null>;
238
+ /**
239
+ * Adds a passkey to the user's account
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * import { AlchemyWebSigner } from "@account-kit/signer";
244
+ *
245
+ * const signer = new AlchemyWebSigner({
246
+ * client: {
247
+ * connection: {
248
+ * rpcUrl: "/api/rpc",
249
+ * },
250
+ * iframeConfig: {
251
+ * iframeContainerId: "alchemy-signer-iframe-container",
252
+ * },
253
+ * },
254
+ * });
255
+ *
256
+ * const result = await signer.addPasskey()
257
+ * ```
258
+ *
259
+ * @param {CredentialCreationOptions | undefined} params optional parameters for the passkey creation
260
+ * @returns {Promise<string[]>} an array of the authenticator ids added to the user
261
+ */
31
262
  addPasskey: (params?: CredentialCreationOptions) => Promise<string[]>;
263
+ /**
264
+ * Used to export the wallet for a given user
265
+ * If the user is authenticated with an Email, this will return a seed phrase
266
+ * If the user is authenticated with a Passkey, this will return a private key
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * import { AlchemyWebSigner } from "@account-kit/signer";
271
+ *
272
+ * const signer = new AlchemyWebSigner({
273
+ * client: {
274
+ * connection: {
275
+ * rpcUrl: "/api/rpc",
276
+ * },
277
+ * iframeConfig: {
278
+ * iframeContainerId: "alchemy-signer-iframe-container",
279
+ * },
280
+ * },
281
+ * });
282
+ *
283
+ * // the params passed to this are different based on the specific signer
284
+ * const result = signer.exportWallet()
285
+ * ```
286
+ *
287
+ * @param {unknown} params export wallet parameters
288
+ * @returns {boolean} true if the wallet was exported successfully
289
+ */
32
290
  exportWallet: (params: Parameters<(typeof this.inner)["exportWallet"]>[0]) => Promise<boolean>;
291
+ /**
292
+ * This method lets you adapt your AlchemySigner to a viem LocalAccount, which
293
+ * will let you use the signer as an EOA directly.
294
+ *
295
+ * @example
296
+ * ```ts
297
+ * import { AlchemyWebSigner } from "@account-kit/signer";
298
+ *
299
+ * const signer = new AlchemyWebSigner({
300
+ * client: {
301
+ * connection: {
302
+ * rpcUrl: "/api/rpc",
303
+ * },
304
+ * iframeConfig: {
305
+ * iframeContainerId: "alchemy-signer-iframe-container",
306
+ * },
307
+ * },
308
+ * });
309
+ *
310
+ * const account = signer.toViemAccount();
311
+ * ```
312
+ *
313
+ * @throws if your signer is not authenticated
314
+ * @returns {LocalAccount} a LocalAccount object that can be used with viem's wallet client
315
+ */
33
316
  toViemAccount: () => LocalAccount;
34
317
  private authenticateWithEmail;
35
318
  private authenticateWithPasskey;