@account-kit/signer 4.0.0-alpha.8 → 4.0.0-beta.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.
Files changed (77) hide show
  1. package/dist/esm/base.d.ts +285 -0
  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.map +1 -1
  21. package/dist/types/client/base.d.ts +11 -1
  22. package/dist/types/client/base.d.ts.map +1 -1
  23. package/dist/types/client/index.d.ts.map +1 -1
  24. package/dist/types/client/types.d.ts +4 -0
  25. package/dist/types/client/types.d.ts.map +1 -1
  26. package/dist/types/signer.d.ts +4 -3
  27. package/dist/types/signer.d.ts.map +1 -1
  28. package/dist/types/version.d.ts +1 -1
  29. package/dist/types/version.d.ts.map +1 -1
  30. package/package.json +13 -14
  31. package/src/base.ts +16 -2
  32. package/src/client/base.ts +21 -2
  33. package/src/client/index.ts +2 -1
  34. package/src/client/types.ts +5 -0
  35. package/src/signer.ts +5 -0
  36. package/src/version.ts +1 -1
  37. package/dist/cjs/base.d.ts +0 -37
  38. package/dist/cjs/base.js +0 -292
  39. package/dist/cjs/base.js.map +0 -1
  40. package/dist/cjs/client/base.d.ts +0 -230
  41. package/dist/cjs/client/base.js +0 -298
  42. package/dist/cjs/client/base.js.map +0 -1
  43. package/dist/cjs/client/index.d.ts +0 -146
  44. package/dist/cjs/client/index.js +0 -260
  45. package/dist/cjs/client/index.js.map +0 -1
  46. package/dist/cjs/client/types.d.ts +0 -106
  47. package/dist/cjs/client/types.js +0 -3
  48. package/dist/cjs/client/types.js.map +0 -1
  49. package/dist/cjs/errors.d.ts +0 -4
  50. package/dist/cjs/errors.js +0 -16
  51. package/dist/cjs/errors.js.map +0 -1
  52. package/dist/cjs/index.d.ts +0 -9
  53. package/dist/cjs/index.js +0 -16
  54. package/dist/cjs/index.js.map +0 -1
  55. package/dist/cjs/package.json +0 -1
  56. package/dist/cjs/session/manager.d.ts +0 -45
  57. package/dist/cjs/session/manager.js +0 -230
  58. package/dist/cjs/session/manager.js.map +0 -1
  59. package/dist/cjs/session/types.d.ts +0 -16
  60. package/dist/cjs/session/types.js +0 -3
  61. package/dist/cjs/session/types.js.map +0 -1
  62. package/dist/cjs/signer.d.ts +0 -262
  63. package/dist/cjs/signer.js +0 -34
  64. package/dist/cjs/signer.js.map +0 -1
  65. package/dist/cjs/types.d.ts +0 -14
  66. package/dist/cjs/types.js +0 -12
  67. package/dist/cjs/types.js.map +0 -1
  68. package/dist/cjs/utils/base64UrlEncode.d.ts +0 -1
  69. package/dist/cjs/utils/base64UrlEncode.js +0 -12
  70. package/dist/cjs/utils/base64UrlEncode.js.map +0 -1
  71. package/dist/cjs/utils/generateRandomBuffer.d.ts +0 -1
  72. package/dist/cjs/utils/generateRandomBuffer.js +0 -10
  73. package/dist/cjs/utils/generateRandomBuffer.js.map +0 -1
  74. package/dist/cjs/version.d.ts +0 -1
  75. package/dist/cjs/version.js +0 -5
  76. package/dist/cjs/version.js.map +0 -1
  77. package/dist/esm/package.json +0 -1
@@ -9,27 +9,312 @@ 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}`>;
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
+ */
24
179
  signTypedData: <const TTypedData extends TypedData | {
25
180
  [key: string]: unknown;
26
181
  }, TPrimaryType extends keyof TTypedData | "EIP712Domain" = keyof TTypedData>(params: TypedDataDefinition<TTypedData, TPrimaryType>) => Promise<Hex>;
182
+ /**
183
+ * Serializes a transaction, signs it with a raw message, and then returns the serialized transaction with the signature.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * import { AlchemyWebSigner } from "@account-kit/signer";
188
+ *
189
+ * const signer = new AlchemyWebSigner({
190
+ * client: {
191
+ * connection: {
192
+ * rpcUrl: "/api/rpc",
193
+ * },
194
+ * iframeConfig: {
195
+ * iframeContainerId: "alchemy-signer-iframe-container",
196
+ * },
197
+ * },
198
+ * });
199
+ *
200
+ * const tx = await signer.signTransaction({
201
+ * to: "0x1234",
202
+ * value: "0x1234",
203
+ * data: "0x1234",
204
+ * });
205
+ * ```
206
+ *
207
+ * @param {Transaction} tx the transaction to be serialized and signed
208
+ * @param {{serializer?: SerializeTransactionFn}} args options for serialization
209
+ * @param {() => Hex} [args.serializer] an optional serializer function. If not provided, the default `serializeTransaction` function will be used
210
+ * @returns {Promise<string>} a promise that resolves to the serialized transaction with the signature
211
+ */
27
212
  signTransaction: CustomSource["signTransaction"];
213
+ /**
214
+ * Unauthenticated call to look up a user's organizationId by email
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * import { AlchemyWebSigner } from "@account-kit/signer";
219
+ *
220
+ * const signer = new AlchemyWebSigner({
221
+ * client: {
222
+ * connection: {
223
+ * rpcUrl: "/api/rpc",
224
+ * },
225
+ * iframeConfig: {
226
+ * iframeContainerId: "alchemy-signer-iframe-container",
227
+ * },
228
+ * },
229
+ * });
230
+ *
231
+ * const result = await signer.getUser("foo@mail.com");
232
+ * ```
233
+ *
234
+ * @param {string} email the email to lookup
235
+ * @returns {Promise<{orgId: string}>} the organization id for the user if they exist
236
+ */
28
237
  getUser: (email: string) => Promise<{
29
238
  orgId: string;
30
239
  } | null>;
240
+ /**
241
+ * Adds a passkey to the user's account
242
+ *
243
+ * @example
244
+ * ```ts
245
+ * import { AlchemyWebSigner } from "@account-kit/signer";
246
+ *
247
+ * const signer = new AlchemyWebSigner({
248
+ * client: {
249
+ * connection: {
250
+ * rpcUrl: "/api/rpc",
251
+ * },
252
+ * iframeConfig: {
253
+ * iframeContainerId: "alchemy-signer-iframe-container",
254
+ * },
255
+ * },
256
+ * });
257
+ *
258
+ * const result = await signer.addPasskey()
259
+ * ```
260
+ *
261
+ * @param {CredentialCreationOptions | undefined} params optional parameters for the passkey creation
262
+ * @returns {Promise<string[]>} an array of the authenticator ids added to the user
263
+ */
31
264
  addPasskey: (params?: CredentialCreationOptions) => Promise<string[]>;
265
+ /**
266
+ * Used to export the wallet for a given user
267
+ * If the user is authenticated with an Email, this will return a seed phrase
268
+ * If the user is authenticated with a Passkey, this will return a private key
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * import { AlchemyWebSigner } from "@account-kit/signer";
273
+ *
274
+ * const signer = new AlchemyWebSigner({
275
+ * client: {
276
+ * connection: {
277
+ * rpcUrl: "/api/rpc",
278
+ * },
279
+ * iframeConfig: {
280
+ * iframeContainerId: "alchemy-signer-iframe-container",
281
+ * },
282
+ * },
283
+ * });
284
+ *
285
+ * // the params passed to this are different based on the specific signer
286
+ * const result = signer.exportWallet()
287
+ * ```
288
+ *
289
+ * @param {unknown} params export wallet parameters
290
+ * @returns {boolean} true if the wallet was exported successfully
291
+ */
32
292
  exportWallet: (params: Parameters<(typeof this.inner)["exportWallet"]>[0]) => Promise<boolean>;
293
+ /**
294
+ * This method lets you adapt your AlchemySigner to a viem LocalAccount, which
295
+ * will let you use the signer as an EOA directly.
296
+ *
297
+ * @example
298
+ * ```ts
299
+ * import { AlchemyWebSigner } from "@account-kit/signer";
300
+ *
301
+ * const signer = new AlchemyWebSigner({
302
+ * client: {
303
+ * connection: {
304
+ * rpcUrl: "/api/rpc",
305
+ * },
306
+ * iframeConfig: {
307
+ * iframeContainerId: "alchemy-signer-iframe-container",
308
+ * },
309
+ * },
310
+ * });
311
+ *
312
+ * const account = signer.toViemAccount();
313
+ * ```
314
+ *
315
+ * @throws if your signer is not authenticated
316
+ * @returns {LocalAccount} a LocalAccount object that can be used with viem's wallet client
317
+ */
33
318
  toViemAccount: () => LocalAccount;
34
319
  private authenticateWithEmail;
35
320
  private authenticateWithPasskey;