@account-kit/signer 4.0.0-alpha.0 → 4.0.0-alpha.10
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/base.js.map +1 -1
- package/dist/cjs/client/base.d.ts +1 -1
- package/dist/cjs/client/base.js.map +1 -1
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/index.d.ts +5 -4
- package/dist/cjs/index.js +9 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/signer.d.ts +1 -1
- package/dist/cjs/signer.js +5 -5
- package/dist/cjs/signer.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/base.js.map +1 -1
- package/dist/esm/client/base.d.ts +1 -1
- package/dist/esm/client/base.js.map +1 -1
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/index.d.ts +5 -4
- package/dist/esm/index.js +3 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/signer.d.ts +1 -1
- package/dist/esm/signer.js +5 -5
- package/dist/esm/signer.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/base.d.ts +248 -14
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/client/base.d.ts +60 -6
- package/dist/types/client/base.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +158 -0
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/signer.d.ts +22 -1
- package/dist/types/signer.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/base.ts +250 -16
- package/src/client/base.ts +61 -6
- package/src/client/index.ts +159 -1
- package/src/index.ts +5 -6
- package/src/signer.ts +27 -6
- package/src/version.ts +1 -1
package/src/client/index.ts
CHANGED
|
@@ -40,6 +40,29 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
40
40
|
private webauthnStamper: WebauthnStamper;
|
|
41
41
|
iframeContainerId: string;
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Initializes a new instance with the given parameters, setting up the connection, iframe configuration, and WebAuthn stamper.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
49
|
+
*
|
|
50
|
+
* const client = new AlchemySignerWebClient({
|
|
51
|
+
* connection: {
|
|
52
|
+
* apiKey: "your-api-key",
|
|
53
|
+
* },
|
|
54
|
+
* iframeConfig: {
|
|
55
|
+
* iframeContainerId: "signer-iframe-container",
|
|
56
|
+
* },
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param {AlchemySignerClientParams} params the parameters required to initialize the client
|
|
61
|
+
* @param {ConnectionConfig} params.connection The connection details needed to connect to the service
|
|
62
|
+
* @param {{ iframeElementId?: string; iframeContainerId: string }} params.iframeConfig The configuration details for setting up the iframe stamper
|
|
63
|
+
* @param {string} params.rpId The relying party ID, defaulting to the current hostname if not provided
|
|
64
|
+
* @param {string} params.rootOrgId The root organization ID
|
|
65
|
+
*/
|
|
43
66
|
constructor(params: AlchemySignerClientParams) {
|
|
44
67
|
const { connection, iframeConfig, rpId, rootOrgId } =
|
|
45
68
|
AlchemySignerClientParamsSchema.parse(params);
|
|
@@ -64,7 +87,29 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
64
87
|
});
|
|
65
88
|
}
|
|
66
89
|
|
|
67
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Authenticates the user by either email or passkey account creation flow. Emits events during the process.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
96
|
+
*
|
|
97
|
+
* const client = new AlchemySignerWebClient({
|
|
98
|
+
* connection: {
|
|
99
|
+
* apiKey: "your-api-key",
|
|
100
|
+
* },
|
|
101
|
+
* iframeConfig: {
|
|
102
|
+
* iframeContainerId: "signer-iframe-container",
|
|
103
|
+
* },
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* const account = await client.createAccount({ type: "email", email: "you@mail.com" });
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @param {CreateAccountParams} params The parameters for creating an account, including the type (email or passkey) and additional details.
|
|
110
|
+
* @returns {Promise<SignupResponse>} A promise that resolves with the response object containing the account creation result.
|
|
111
|
+
*/
|
|
112
|
+
createAccount = async (params: CreateAccountParams) => {
|
|
68
113
|
this.eventEmitter.emit("authenticating");
|
|
69
114
|
if (params.type === "email") {
|
|
70
115
|
const { email, expirationSeconds } = params;
|
|
@@ -105,6 +150,29 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
105
150
|
return result;
|
|
106
151
|
};
|
|
107
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Begin authenticating a user with their email and an expiration time for the authentication request. Initializes the iframe stamper to get the target public key.
|
|
155
|
+
* This method sends an email to the user to complete their login
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
160
|
+
*
|
|
161
|
+
* const client = new AlchemySignerWebClient({
|
|
162
|
+
* connection: {
|
|
163
|
+
* apiKey: "your-api-key",
|
|
164
|
+
* },
|
|
165
|
+
* iframeConfig: {
|
|
166
|
+
* iframeContainerId: "signer-iframe-container",
|
|
167
|
+
* },
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* const account = await client.initEmailAuth({ email: "you@mail.com" });
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @param {Omit<EmailAuthParams, "targetPublicKey">} params The parameters for email authentication, excluding the target public key
|
|
174
|
+
* @returns {Promise<any>} The response from the authentication request
|
|
175
|
+
*/
|
|
108
176
|
public initEmailAuth = async (
|
|
109
177
|
params: Omit<EmailAuthParams, "targetPublicKey">
|
|
110
178
|
) => {
|
|
@@ -120,6 +188,28 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
120
188
|
});
|
|
121
189
|
};
|
|
122
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Completes email auth for the user by injecting a credential bundle and retrieving the user information based on the provided organization ID. Emits events during the process.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
197
|
+
*
|
|
198
|
+
* const client = new AlchemySignerWebClient({
|
|
199
|
+
* connection: {
|
|
200
|
+
* apiKey: "your-api-key",
|
|
201
|
+
* },
|
|
202
|
+
* iframeConfig: {
|
|
203
|
+
* iframeContainerId: "signer-iframe-container",
|
|
204
|
+
* },
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* const account = await client.completeEmailAuth({ orgId: "user-org-id", bundle: "bundle-from-email" });
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @param {{ bundle: string; orgId: string }} config The configuration object for the authentication function containing the credential bundle to inject and the organization id associated with the user
|
|
211
|
+
* @returns {Promise<User>} A promise that resolves to the authenticated user information
|
|
212
|
+
*/
|
|
123
213
|
public completeEmailAuth = async ({
|
|
124
214
|
bundle,
|
|
125
215
|
orgId,
|
|
@@ -142,6 +232,28 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
142
232
|
return user;
|
|
143
233
|
};
|
|
144
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Asynchronously handles the authentication process using WebAuthn Stamper. If a user is provided, sets the user and returns it. Otherwise, retrieves the current user and initializes the WebAuthn stamper.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
241
|
+
*
|
|
242
|
+
* const client = new AlchemySignerWebClient({
|
|
243
|
+
* connection: {
|
|
244
|
+
* apiKey: "your-api-key",
|
|
245
|
+
* },
|
|
246
|
+
* iframeConfig: {
|
|
247
|
+
* iframeContainerId: "signer-iframe-container",
|
|
248
|
+
* },
|
|
249
|
+
* });
|
|
250
|
+
*
|
|
251
|
+
* const account = await client.lookupUserWithPasskey();
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @param {User} [user] An optional user object to authenticate
|
|
255
|
+
* @returns {Promise<User>} A promise that resolves to the authenticated user object
|
|
256
|
+
*/
|
|
145
257
|
public lookupUserWithPasskey = async (user: User | undefined = undefined) => {
|
|
146
258
|
this.eventEmitter.emit("authenticating");
|
|
147
259
|
await this.initWebauthnStamper(user);
|
|
@@ -157,6 +269,33 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
157
269
|
return result;
|
|
158
270
|
};
|
|
159
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Initiates the export of a wallet by creating an iframe stamper and calling the appropriate export function.
|
|
274
|
+
* The export can be based on a seed phrase or a private key.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
279
|
+
*
|
|
280
|
+
* const client = new AlchemySignerWebClient({
|
|
281
|
+
* connection: {
|
|
282
|
+
* apiKey: "your-api-key",
|
|
283
|
+
* },
|
|
284
|
+
* iframeConfig: {
|
|
285
|
+
* iframeContainerId: "signer-iframe-container",
|
|
286
|
+
* },
|
|
287
|
+
* });
|
|
288
|
+
*
|
|
289
|
+
* const account = await client.exportWallet({
|
|
290
|
+
* iframeContainerId: "export-iframe-container",
|
|
291
|
+
* });
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* @param {ExportWalletParams} config The parameters for exporting the wallet
|
|
295
|
+
* @param {string} config.iframeContainerId The ID of the container element that will hold the iframe stamper
|
|
296
|
+
* @param {string} [config.iframeElementId] Optional ID for the iframe element
|
|
297
|
+
* @returns {Promise<void>} A promise that resolves when the export process is complete
|
|
298
|
+
*/
|
|
160
299
|
public exportWallet = async ({
|
|
161
300
|
iframeContainerId,
|
|
162
301
|
iframeElementId = "turnkey-export-iframe",
|
|
@@ -181,6 +320,25 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
181
320
|
});
|
|
182
321
|
};
|
|
183
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Asynchronous function that clears the user and resets the iframe stamper.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
329
|
+
*
|
|
330
|
+
* const client = new AlchemySignerWebClient({
|
|
331
|
+
* connection: {
|
|
332
|
+
* apiKey: "your-api-key",
|
|
333
|
+
* },
|
|
334
|
+
* iframeConfig: {
|
|
335
|
+
* iframeContainerId: "signer-iframe-container",
|
|
336
|
+
* },
|
|
337
|
+
* });
|
|
338
|
+
*
|
|
339
|
+
* const account = await client.disconnect();
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
184
342
|
public disconnect = async () => {
|
|
185
343
|
this.user = undefined;
|
|
186
344
|
this.iframeStamper.clear();
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { AlchemyWebSigner } from "./signer.js";
|
|
3
|
-
|
|
4
|
-
export type * from "./types.js";
|
|
5
|
-
export { AlchemySignerStatus } from "./types.js";
|
|
6
|
-
|
|
1
|
+
export { BaseAlchemySigner } from "./base.js";
|
|
7
2
|
export { BaseSignerClient } from "./client/base.js";
|
|
8
3
|
export { AlchemySignerWebClient } from "./client/index.js";
|
|
9
4
|
export type * from "./client/types.js";
|
|
10
5
|
export { DEFAULT_SESSION_MS } from "./session/manager.js";
|
|
6
|
+
export type * from "./signer.js";
|
|
7
|
+
export { AlchemyWebSigner } from "./signer.js";
|
|
8
|
+
export type * from "./types.js";
|
|
9
|
+
export { AlchemySignerStatus } from "./types.js";
|
package/src/signer.ts
CHANGED
|
@@ -37,15 +37,36 @@ export type AlchemySignerParams = z.input<typeof AlchemySignerParamsSchema>;
|
|
|
37
37
|
* A SmartAccountSigner that can be used with any SmartContractAccount
|
|
38
38
|
*/
|
|
39
39
|
export class AlchemyWebSigner extends BaseAlchemySigner<AlchemySignerWebClient> {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Initializes an instance with the provided Alchemy signer parameters after parsing them with a schema.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { AlchemyWebSigner } from "@account-kit/signer";
|
|
46
|
+
*
|
|
47
|
+
* const signer = new AlchemyWebSigner({
|
|
48
|
+
* client: {
|
|
49
|
+
* connection: {
|
|
50
|
+
* rpcUrl: "/api/rpc",
|
|
51
|
+
* },
|
|
52
|
+
* iframeConfig: {
|
|
53
|
+
* iframeContainerId: "alchemy-signer-iframe-container",
|
|
54
|
+
* },
|
|
55
|
+
* },
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @param {AlchemySignerParams} params The parameters for the Alchemy signer, including the client and session configuration
|
|
60
|
+
*/
|
|
61
|
+
constructor(params: AlchemySignerParams) {
|
|
62
|
+
const { sessionConfig, ...params_ } =
|
|
63
|
+
AlchemySignerParamsSchema.parse(params);
|
|
43
64
|
|
|
44
65
|
let client: AlchemySignerWebClient;
|
|
45
|
-
if ("connection" in
|
|
46
|
-
client = new AlchemySignerWebClient(
|
|
66
|
+
if ("connection" in params_.client) {
|
|
67
|
+
client = new AlchemySignerWebClient(params_.client);
|
|
47
68
|
} else {
|
|
48
|
-
client =
|
|
69
|
+
client = params_.client;
|
|
49
70
|
}
|
|
50
71
|
super({
|
|
51
72
|
client,
|
package/src/version.ts
CHANGED