@account-kit/signer 4.0.0-alpha.1 → 4.0.0-alpha.11
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 +8 -1
- package/dist/cjs/base.js.map +1 -1
- package/dist/cjs/client/base.d.ts +3 -2
- package/dist/cjs/client/base.js +13 -0
- package/dist/cjs/client/base.js.map +1 -1
- package/dist/cjs/client/index.js +2 -1
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/client/types.d.ts +4 -0
- package/dist/cjs/client/types.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 +5 -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 +8 -1
- package/dist/esm/base.js.map +1 -1
- package/dist/esm/client/base.d.ts +3 -2
- package/dist/esm/client/base.js +13 -0
- package/dist/esm/client/base.js.map +1 -1
- package/dist/esm/client/index.js +2 -1
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/client/types.d.ts +4 -0
- package/dist/esm/client/types.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 +5 -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 +63 -7
- 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/client/types.d.ts +4 -0
- package/dist/types/client/types.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 +26 -4
- 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 +266 -18
- package/src/client/base.ts +74 -8
- package/src/client/index.ts +161 -2
- package/src/client/types.ts +5 -0
- package/src/index.ts +5 -6
- package/src/signer.ts +32 -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;
|
|
@@ -83,7 +128,7 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
83
128
|
// Passkey account creation flow
|
|
84
129
|
const { attestation, challenge } = await this.getWebAuthnAttestation(
|
|
85
130
|
params.creationOpts,
|
|
86
|
-
{ username: params.username }
|
|
131
|
+
{ username: "email" in params ? params.email : params.username }
|
|
87
132
|
);
|
|
88
133
|
|
|
89
134
|
const result = await this.request("/v1/signup", {
|
|
@@ -91,6 +136,7 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
91
136
|
challenge: base64UrlEncode(challenge),
|
|
92
137
|
attestation,
|
|
93
138
|
},
|
|
139
|
+
email: "email" in params ? params.email : undefined,
|
|
94
140
|
});
|
|
95
141
|
|
|
96
142
|
this.user = {
|
|
@@ -105,6 +151,29 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
105
151
|
return result;
|
|
106
152
|
};
|
|
107
153
|
|
|
154
|
+
/**
|
|
155
|
+
* 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.
|
|
156
|
+
* This method sends an email to the user to complete their login
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
161
|
+
*
|
|
162
|
+
* const client = new AlchemySignerWebClient({
|
|
163
|
+
* connection: {
|
|
164
|
+
* apiKey: "your-api-key",
|
|
165
|
+
* },
|
|
166
|
+
* iframeConfig: {
|
|
167
|
+
* iframeContainerId: "signer-iframe-container",
|
|
168
|
+
* },
|
|
169
|
+
* });
|
|
170
|
+
*
|
|
171
|
+
* const account = await client.initEmailAuth({ email: "you@mail.com" });
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @param {Omit<EmailAuthParams, "targetPublicKey">} params The parameters for email authentication, excluding the target public key
|
|
175
|
+
* @returns {Promise<any>} The response from the authentication request
|
|
176
|
+
*/
|
|
108
177
|
public initEmailAuth = async (
|
|
109
178
|
params: Omit<EmailAuthParams, "targetPublicKey">
|
|
110
179
|
) => {
|
|
@@ -120,6 +189,28 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
120
189
|
});
|
|
121
190
|
};
|
|
122
191
|
|
|
192
|
+
/**
|
|
193
|
+
* 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.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
198
|
+
*
|
|
199
|
+
* const client = new AlchemySignerWebClient({
|
|
200
|
+
* connection: {
|
|
201
|
+
* apiKey: "your-api-key",
|
|
202
|
+
* },
|
|
203
|
+
* iframeConfig: {
|
|
204
|
+
* iframeContainerId: "signer-iframe-container",
|
|
205
|
+
* },
|
|
206
|
+
* });
|
|
207
|
+
*
|
|
208
|
+
* const account = await client.completeEmailAuth({ orgId: "user-org-id", bundle: "bundle-from-email" });
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @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
|
|
212
|
+
* @returns {Promise<User>} A promise that resolves to the authenticated user information
|
|
213
|
+
*/
|
|
123
214
|
public completeEmailAuth = async ({
|
|
124
215
|
bundle,
|
|
125
216
|
orgId,
|
|
@@ -142,6 +233,28 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
142
233
|
return user;
|
|
143
234
|
};
|
|
144
235
|
|
|
236
|
+
/**
|
|
237
|
+
* 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.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```ts
|
|
241
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
242
|
+
*
|
|
243
|
+
* const client = new AlchemySignerWebClient({
|
|
244
|
+
* connection: {
|
|
245
|
+
* apiKey: "your-api-key",
|
|
246
|
+
* },
|
|
247
|
+
* iframeConfig: {
|
|
248
|
+
* iframeContainerId: "signer-iframe-container",
|
|
249
|
+
* },
|
|
250
|
+
* });
|
|
251
|
+
*
|
|
252
|
+
* const account = await client.lookupUserWithPasskey();
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* @param {User} [user] An optional user object to authenticate
|
|
256
|
+
* @returns {Promise<User>} A promise that resolves to the authenticated user object
|
|
257
|
+
*/
|
|
145
258
|
public lookupUserWithPasskey = async (user: User | undefined = undefined) => {
|
|
146
259
|
this.eventEmitter.emit("authenticating");
|
|
147
260
|
await this.initWebauthnStamper(user);
|
|
@@ -157,6 +270,33 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
157
270
|
return result;
|
|
158
271
|
};
|
|
159
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Initiates the export of a wallet by creating an iframe stamper and calling the appropriate export function.
|
|
275
|
+
* The export can be based on a seed phrase or a private key.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
280
|
+
*
|
|
281
|
+
* const client = new AlchemySignerWebClient({
|
|
282
|
+
* connection: {
|
|
283
|
+
* apiKey: "your-api-key",
|
|
284
|
+
* },
|
|
285
|
+
* iframeConfig: {
|
|
286
|
+
* iframeContainerId: "signer-iframe-container",
|
|
287
|
+
* },
|
|
288
|
+
* });
|
|
289
|
+
*
|
|
290
|
+
* const account = await client.exportWallet({
|
|
291
|
+
* iframeContainerId: "export-iframe-container",
|
|
292
|
+
* });
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* @param {ExportWalletParams} config The parameters for exporting the wallet
|
|
296
|
+
* @param {string} config.iframeContainerId The ID of the container element that will hold the iframe stamper
|
|
297
|
+
* @param {string} [config.iframeElementId] Optional ID for the iframe element
|
|
298
|
+
* @returns {Promise<void>} A promise that resolves when the export process is complete
|
|
299
|
+
*/
|
|
160
300
|
public exportWallet = async ({
|
|
161
301
|
iframeContainerId,
|
|
162
302
|
iframeElementId = "turnkey-export-iframe",
|
|
@@ -181,6 +321,25 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
181
321
|
});
|
|
182
322
|
};
|
|
183
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Asynchronous function that clears the user and resets the iframe stamper.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```ts
|
|
329
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
330
|
+
*
|
|
331
|
+
* const client = new AlchemySignerWebClient({
|
|
332
|
+
* connection: {
|
|
333
|
+
* apiKey: "your-api-key",
|
|
334
|
+
* },
|
|
335
|
+
* iframeConfig: {
|
|
336
|
+
* iframeContainerId: "signer-iframe-container",
|
|
337
|
+
* },
|
|
338
|
+
* });
|
|
339
|
+
*
|
|
340
|
+
* const account = await client.disconnect();
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
184
343
|
public disconnect = async () => {
|
|
185
344
|
this.user = undefined;
|
|
186
345
|
this.iframeStamper.clear();
|
package/src/client/types.ts
CHANGED
|
@@ -28,6 +28,11 @@ export type CreateAccountParams =
|
|
|
28
28
|
expirationSeconds?: number;
|
|
29
29
|
redirectParams?: URLSearchParams;
|
|
30
30
|
}
|
|
31
|
+
| {
|
|
32
|
+
type: "passkey";
|
|
33
|
+
email: string;
|
|
34
|
+
creationOpts?: CredentialCreationOptionOverrides;
|
|
35
|
+
}
|
|
31
36
|
| {
|
|
32
37
|
type: "passkey";
|
|
33
38
|
username: string;
|
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
|
@@ -10,6 +10,11 @@ import { SessionManagerParamsSchema } from "./session/manager.js";
|
|
|
10
10
|
export type AuthParams =
|
|
11
11
|
| { type: "email"; email: string; redirectParams?: URLSearchParams }
|
|
12
12
|
| { type: "email"; bundle: string; orgId?: string }
|
|
13
|
+
| {
|
|
14
|
+
type: "passkey";
|
|
15
|
+
email: string;
|
|
16
|
+
creationOpts?: CredentialCreationOptionOverrides;
|
|
17
|
+
}
|
|
13
18
|
| {
|
|
14
19
|
type: "passkey";
|
|
15
20
|
createNew: false;
|
|
@@ -37,15 +42,36 @@ export type AlchemySignerParams = z.input<typeof AlchemySignerParamsSchema>;
|
|
|
37
42
|
* A SmartAccountSigner that can be used with any SmartContractAccount
|
|
38
43
|
*/
|
|
39
44
|
export class AlchemyWebSigner extends BaseAlchemySigner<AlchemySignerWebClient> {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Initializes an instance with the provided Alchemy signer parameters after parsing them with a schema.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { AlchemyWebSigner } from "@account-kit/signer";
|
|
51
|
+
*
|
|
52
|
+
* const signer = new AlchemyWebSigner({
|
|
53
|
+
* client: {
|
|
54
|
+
* connection: {
|
|
55
|
+
* rpcUrl: "/api/rpc",
|
|
56
|
+
* },
|
|
57
|
+
* iframeConfig: {
|
|
58
|
+
* iframeContainerId: "alchemy-signer-iframe-container",
|
|
59
|
+
* },
|
|
60
|
+
* },
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @param {AlchemySignerParams} params The parameters for the Alchemy signer, including the client and session configuration
|
|
65
|
+
*/
|
|
66
|
+
constructor(params: AlchemySignerParams) {
|
|
67
|
+
const { sessionConfig, ...params_ } =
|
|
68
|
+
AlchemySignerParamsSchema.parse(params);
|
|
43
69
|
|
|
44
70
|
let client: AlchemySignerWebClient;
|
|
45
|
-
if ("connection" in
|
|
46
|
-
client = new AlchemySignerWebClient(
|
|
71
|
+
if ("connection" in params_.client) {
|
|
72
|
+
client = new AlchemySignerWebClient(params_.client);
|
|
47
73
|
} else {
|
|
48
|
-
client =
|
|
74
|
+
client = params_.client;
|
|
49
75
|
}
|
|
50
76
|
super({
|
|
51
77
|
client,
|
package/src/version.ts
CHANGED