@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.
- package/dist/esm/base.d.ts +286 -3
- package/dist/esm/base.js +307 -1
- package/dist/esm/base.js.map +1 -1
- package/dist/esm/client/base.d.ts +80 -1
- package/dist/esm/client/base.js +97 -0
- package/dist/esm/client/base.js.map +1 -1
- package/dist/esm/client/index.d.ts +162 -0
- package/dist/esm/client/index.js +167 -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/session/manager.js +18 -1
- package/dist/esm/session/manager.js.map +1 -1
- package/dist/esm/signer.d.ts +28 -0
- package/dist/esm/signer.js +24 -0
- package/dist/esm/signer.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +3 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/base.d.ts +1 -3
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/client/base.d.ts +11 -1
- package/dist/types/client/base.d.ts.map +1 -1
- 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/signer.d.ts +4 -3
- 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 +10 -15
- package/src/base.ts +17 -3
- package/src/client/base.ts +21 -2
- package/src/client/index.ts +2 -1
- package/src/client/types.ts +5 -0
- package/src/signer.ts +5 -0
- package/src/version.ts +1 -1
- package/dist/cjs/base.d.ts +0 -37
- package/dist/cjs/base.js +0 -292
- package/dist/cjs/base.js.map +0 -1
- package/dist/cjs/client/base.d.ts +0 -230
- package/dist/cjs/client/base.js +0 -298
- package/dist/cjs/client/base.js.map +0 -1
- package/dist/cjs/client/index.d.ts +0 -146
- package/dist/cjs/client/index.js +0 -260
- package/dist/cjs/client/index.js.map +0 -1
- package/dist/cjs/client/types.d.ts +0 -106
- package/dist/cjs/client/types.js +0 -3
- package/dist/cjs/client/types.js.map +0 -1
- package/dist/cjs/errors.d.ts +0 -4
- package/dist/cjs/errors.js +0 -16
- package/dist/cjs/errors.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -9
- package/dist/cjs/index.js +0 -16
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/session/manager.d.ts +0 -45
- package/dist/cjs/session/manager.js +0 -230
- package/dist/cjs/session/manager.js.map +0 -1
- package/dist/cjs/session/types.d.ts +0 -16
- package/dist/cjs/session/types.js +0 -3
- package/dist/cjs/session/types.js.map +0 -1
- package/dist/cjs/signer.d.ts +0 -262
- package/dist/cjs/signer.js +0 -34
- package/dist/cjs/signer.js.map +0 -1
- package/dist/cjs/types.d.ts +0 -14
- package/dist/cjs/types.js +0 -12
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/utils/base64UrlEncode.d.ts +0 -1
- package/dist/cjs/utils/base64UrlEncode.js +0 -12
- package/dist/cjs/utils/base64UrlEncode.js.map +0 -1
- package/dist/cjs/utils/generateRandomBuffer.d.ts +0 -1
- package/dist/cjs/utils/generateRandomBuffer.js +0 -10
- package/dist/cjs/utils/generateRandomBuffer.js.map +0 -1
- package/dist/cjs/version.d.ts +0 -1
- package/dist/cjs/version.js +0 -5
- package/dist/cjs/version.js.map +0 -1
- package/dist/esm/package.json +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ConnectionConfig } from "@aa-sdk/core";
|
|
2
|
-
import { TurnkeyClient } from "@turnkey/http";
|
|
2
|
+
import { TurnkeyClient, type TSignedRequest } from "@turnkey/http";
|
|
3
3
|
import EventEmitter from "eventemitter3";
|
|
4
4
|
import type { Hex } from "viem";
|
|
5
5
|
import type { AlchemySignerClientEvents, CreateAccountParams, EmailAuthParams, GetWebAuthnAttestationResult, SignerBody, SignerResponse, SignupResponse, User } from "./types.js";
|
|
@@ -14,16 +14,37 @@ export type ExportWalletStamper = TurnkeyClient["stamper"] & {
|
|
|
14
14
|
injectKeyExportBundle(bundle: string): Promise<boolean>;
|
|
15
15
|
publicKey(): string | null;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Base class for all Alchemy Signer clients
|
|
19
|
+
*/
|
|
17
20
|
export declare abstract class BaseSignerClient<TExportWalletParams = unknown> {
|
|
18
21
|
private _user;
|
|
19
22
|
private connectionConfig;
|
|
20
23
|
protected turnkeyClient: TurnkeyClient;
|
|
21
24
|
protected rootOrg: string;
|
|
22
25
|
protected eventEmitter: EventEmitter<AlchemySignerClientEvents>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a new instance of the Alchemy Signer client
|
|
28
|
+
*
|
|
29
|
+
* @param {BaseSignerClientParams} params the parameters required to create the client
|
|
30
|
+
*/
|
|
23
31
|
constructor(params: BaseSignerClientParams);
|
|
24
32
|
protected get user(): User | undefined;
|
|
25
33
|
protected set user(user: User | undefined);
|
|
34
|
+
/**
|
|
35
|
+
* Sets the stamper of the TurnkeyClient.
|
|
36
|
+
*
|
|
37
|
+
* @param {TurnkeyClient["stamper"]} stamper the stamper function to set for the TurnkeyClient
|
|
38
|
+
*/
|
|
26
39
|
protected setStamper(stamper: TurnkeyClient["stamper"]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Exports wallet credentials based on the specified type, either as a SEED_PHRASE or PRIVATE_KEY.
|
|
42
|
+
*
|
|
43
|
+
* @param {object} params The parameters for exporting the wallet
|
|
44
|
+
* @param {ExportWalletStamper} params.exportStamper The stamper used for exporting the wallet
|
|
45
|
+
* @param {"SEED_PHRASE" | "PRIVATE_KEY"} params.exportAs Specifies the format for exporting the wallet, either as a SEED_PHRASE or PRIVATE_KEY
|
|
46
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the export is successful
|
|
47
|
+
*/
|
|
27
48
|
protected exportWalletInner(params: {
|
|
28
49
|
exportStamper: ExportWalletStamper;
|
|
29
50
|
exportAs: "SEED_PHRASE" | "PRIVATE_KEY";
|
|
@@ -42,14 +63,72 @@ export declare abstract class BaseSignerClient<TExportWalletParams = unknown> {
|
|
|
42
63
|
protected abstract getWebAuthnAttestation(options: CredentialCreationOptions, userDetails?: {
|
|
43
64
|
username: string;
|
|
44
65
|
}): Promise<GetWebAuthnAttestationResult>;
|
|
66
|
+
/**
|
|
67
|
+
* Listen to events emitted by the client
|
|
68
|
+
*
|
|
69
|
+
* @param {AlchemySignerClientEvent} event the event you want to listen to
|
|
70
|
+
* @param {AlchemySignerClientEvents[AlchemySignerClientEvent]} listener the callback function to execute when an event is fired
|
|
71
|
+
* @returns {() => void} a function that will remove the listener when called
|
|
72
|
+
*/
|
|
45
73
|
on: <E extends keyof AlchemySignerClientEvents>(event: E, listener: AlchemySignerClientEvents[E]) => () => EventEmitter<AlchemySignerClientEvents, any>;
|
|
74
|
+
/**
|
|
75
|
+
* Handles the creation of authenticators using WebAuthn attestation and the provided options. Requires the user to be authenticated.
|
|
76
|
+
*
|
|
77
|
+
* @param {CredentialCreationOptions} options The options used to create the WebAuthn attestation
|
|
78
|
+
* @returns {Promise<string[]>} A promise that resolves to an array of authenticator IDs
|
|
79
|
+
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
80
|
+
*/
|
|
46
81
|
addPasskey: (options: CredentialCreationOptions) => Promise<string[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves the current user or fetches the user information if not already available.
|
|
84
|
+
*
|
|
85
|
+
* @param {string} [orgId] optional organization ID, defaults to the user's organization ID
|
|
86
|
+
* @returns {Promise<User>} A promise that resolves to the user object
|
|
87
|
+
* @throws {Error} if no organization ID is provided when there is no current user
|
|
88
|
+
*/
|
|
47
89
|
whoami: (orgId?: string | undefined) => Promise<User>;
|
|
90
|
+
/**
|
|
91
|
+
* Generates a stamped whoami request for the current user. This request can then be used to call /signer/v1/whoami to get the user information.
|
|
92
|
+
* This is useful if you want to get the user information in a different context like a server. You can pass the stamped request to the server
|
|
93
|
+
* and then call our API to get the user information. Using this stamp is the most trusted way to get the user information since a stamp can only
|
|
94
|
+
* belong to the user who created it.
|
|
95
|
+
*
|
|
96
|
+
* @returns {Promise<TSignedRequest>} a promise that resolves to the "whoami" information for the logged in user
|
|
97
|
+
* @throws {Error} if no organization ID is provided
|
|
98
|
+
*/
|
|
99
|
+
stampWhoami: () => Promise<TSignedRequest>;
|
|
100
|
+
/**
|
|
101
|
+
* Looks up information based on an email address.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} email the email address to look up
|
|
104
|
+
* @returns {Promise<any>} the result of the lookup request
|
|
105
|
+
*/
|
|
48
106
|
lookupUserByEmail: (email: string) => Promise<{
|
|
49
107
|
orgId: string | null;
|
|
50
108
|
}>;
|
|
109
|
+
/**
|
|
110
|
+
* This will sign a message with the user's private key, without doing any transformations on the message.
|
|
111
|
+
* For SignMessage or SignTypedData, the caller should hash the message before calling this method and pass
|
|
112
|
+
* that result here.
|
|
113
|
+
*
|
|
114
|
+
* @param {Hex} msg the hex representation of the bytes to sign
|
|
115
|
+
* @returns {Promise<Hex>} the signature over the raw hex
|
|
116
|
+
*/
|
|
51
117
|
signRawMessage: (msg: Hex) => Promise<Hex>;
|
|
118
|
+
/**
|
|
119
|
+
* Returns the current user or null if no user is set.
|
|
120
|
+
*
|
|
121
|
+
* @returns {User | null} the current user object or null if no user is available
|
|
122
|
+
*/
|
|
52
123
|
getUser: () => User | null;
|
|
124
|
+
/**
|
|
125
|
+
* Sends a POST request to the given signer route with the specified body and returns the response.
|
|
126
|
+
* Not intended to be used directly, use the specific methods instead on the client instead.
|
|
127
|
+
*
|
|
128
|
+
* @param {SignerRoutes} route The route to which the request should be sent
|
|
129
|
+
* @param {SignerBody<R>} body The request body containing the data to be sent
|
|
130
|
+
* @returns {Promise<SignerResponse<R>>} A promise that resolves to the response from the signer
|
|
131
|
+
*/
|
|
53
132
|
request: <R extends "/v1/signup" | "/v1/whoami" | "/v1/auth" | "/v1/lookup" | "/v1/sign-payload">(route: R, body: SignerBody<R>) => Promise<SignerResponse<R>>;
|
|
54
133
|
private exportAsSeedPhrase;
|
|
55
134
|
private exportAsPrivateKey;
|
package/dist/esm/client/base.js
CHANGED
|
@@ -3,7 +3,15 @@ import { TurnkeyClient } from "@turnkey/http";
|
|
|
3
3
|
import EventEmitter from "eventemitter3";
|
|
4
4
|
import { NotAuthenticatedError } from "../errors.js";
|
|
5
5
|
import { base64UrlEncode } from "../utils/base64UrlEncode.js";
|
|
6
|
+
/**
|
|
7
|
+
* Base class for all Alchemy Signer clients
|
|
8
|
+
*/
|
|
6
9
|
export class BaseSignerClient {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of the Alchemy Signer client
|
|
12
|
+
*
|
|
13
|
+
* @param {BaseSignerClientParams} params the parameters required to create the client
|
|
14
|
+
*/
|
|
7
15
|
constructor(params) {
|
|
8
16
|
Object.defineProperty(this, "_user", {
|
|
9
17
|
enumerable: true,
|
|
@@ -35,6 +43,15 @@ export class BaseSignerClient {
|
|
|
35
43
|
writable: true,
|
|
36
44
|
value: void 0
|
|
37
45
|
});
|
|
46
|
+
// #endregion
|
|
47
|
+
// #region PUBLIC METHODS
|
|
48
|
+
/**
|
|
49
|
+
* Listen to events emitted by the client
|
|
50
|
+
*
|
|
51
|
+
* @param {AlchemySignerClientEvent} event the event you want to listen to
|
|
52
|
+
* @param {AlchemySignerClientEvents[AlchemySignerClientEvent]} listener the callback function to execute when an event is fired
|
|
53
|
+
* @returns {() => void} a function that will remove the listener when called
|
|
54
|
+
*/
|
|
38
55
|
Object.defineProperty(this, "on", {
|
|
39
56
|
enumerable: true,
|
|
40
57
|
configurable: true,
|
|
@@ -44,6 +61,13 @@ export class BaseSignerClient {
|
|
|
44
61
|
return () => this.eventEmitter.removeListener(event, listener);
|
|
45
62
|
}
|
|
46
63
|
});
|
|
64
|
+
/**
|
|
65
|
+
* Handles the creation of authenticators using WebAuthn attestation and the provided options. Requires the user to be authenticated.
|
|
66
|
+
*
|
|
67
|
+
* @param {CredentialCreationOptions} options The options used to create the WebAuthn attestation
|
|
68
|
+
* @returns {Promise<string[]>} A promise that resolves to an array of authenticator IDs
|
|
69
|
+
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
70
|
+
*/
|
|
47
71
|
Object.defineProperty(this, "addPasskey", {
|
|
48
72
|
enumerable: true,
|
|
49
73
|
configurable: true,
|
|
@@ -72,6 +96,13 @@ export class BaseSignerClient {
|
|
|
72
96
|
return authenticatorIds;
|
|
73
97
|
}
|
|
74
98
|
});
|
|
99
|
+
/**
|
|
100
|
+
* Retrieves the current user or fetches the user information if not already available.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} [orgId] optional organization ID, defaults to the user's organization ID
|
|
103
|
+
* @returns {Promise<User>} A promise that resolves to the user object
|
|
104
|
+
* @throws {Error} if no organization ID is provided when there is no current user
|
|
105
|
+
*/
|
|
75
106
|
Object.defineProperty(this, "whoami", {
|
|
76
107
|
enumerable: true,
|
|
77
108
|
configurable: true,
|
|
@@ -105,6 +136,34 @@ export class BaseSignerClient {
|
|
|
105
136
|
return this.user;
|
|
106
137
|
}
|
|
107
138
|
});
|
|
139
|
+
/**
|
|
140
|
+
* Generates a stamped whoami request for the current user. This request can then be used to call /signer/v1/whoami to get the user information.
|
|
141
|
+
* This is useful if you want to get the user information in a different context like a server. You can pass the stamped request to the server
|
|
142
|
+
* and then call our API to get the user information. Using this stamp is the most trusted way to get the user information since a stamp can only
|
|
143
|
+
* belong to the user who created it.
|
|
144
|
+
*
|
|
145
|
+
* @returns {Promise<TSignedRequest>} a promise that resolves to the "whoami" information for the logged in user
|
|
146
|
+
* @throws {Error} if no organization ID is provided
|
|
147
|
+
*/
|
|
148
|
+
Object.defineProperty(this, "stampWhoami", {
|
|
149
|
+
enumerable: true,
|
|
150
|
+
configurable: true,
|
|
151
|
+
writable: true,
|
|
152
|
+
value: async () => {
|
|
153
|
+
if (!this.user) {
|
|
154
|
+
throw new Error("User must be authenticated to stamp a whoami request");
|
|
155
|
+
}
|
|
156
|
+
return await this.turnkeyClient.stampGetWhoami({
|
|
157
|
+
organizationId: this.user.orgId,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
/**
|
|
162
|
+
* Looks up information based on an email address.
|
|
163
|
+
*
|
|
164
|
+
* @param {string} email the email address to look up
|
|
165
|
+
* @returns {Promise<any>} the result of the lookup request
|
|
166
|
+
*/
|
|
108
167
|
Object.defineProperty(this, "lookupUserByEmail", {
|
|
109
168
|
enumerable: true,
|
|
110
169
|
configurable: true,
|
|
@@ -113,6 +172,14 @@ export class BaseSignerClient {
|
|
|
113
172
|
return this.request("/v1/lookup", { email });
|
|
114
173
|
}
|
|
115
174
|
});
|
|
175
|
+
/**
|
|
176
|
+
* This will sign a message with the user's private key, without doing any transformations on the message.
|
|
177
|
+
* For SignMessage or SignTypedData, the caller should hash the message before calling this method and pass
|
|
178
|
+
* that result here.
|
|
179
|
+
*
|
|
180
|
+
* @param {Hex} msg the hex representation of the bytes to sign
|
|
181
|
+
* @returns {Promise<Hex>} the signature over the raw hex
|
|
182
|
+
*/
|
|
116
183
|
Object.defineProperty(this, "signRawMessage", {
|
|
117
184
|
enumerable: true,
|
|
118
185
|
configurable: true,
|
|
@@ -138,6 +205,11 @@ export class BaseSignerClient {
|
|
|
138
205
|
return signature;
|
|
139
206
|
}
|
|
140
207
|
});
|
|
208
|
+
/**
|
|
209
|
+
* Returns the current user or null if no user is set.
|
|
210
|
+
*
|
|
211
|
+
* @returns {User | null} the current user object or null if no user is available
|
|
212
|
+
*/
|
|
141
213
|
Object.defineProperty(this, "getUser", {
|
|
142
214
|
enumerable: true,
|
|
143
215
|
configurable: true,
|
|
@@ -146,6 +218,14 @@ export class BaseSignerClient {
|
|
|
146
218
|
return this.user ?? null;
|
|
147
219
|
}
|
|
148
220
|
});
|
|
221
|
+
/**
|
|
222
|
+
* Sends a POST request to the given signer route with the specified body and returns the response.
|
|
223
|
+
* Not intended to be used directly, use the specific methods instead on the client instead.
|
|
224
|
+
*
|
|
225
|
+
* @param {SignerRoutes} route The route to which the request should be sent
|
|
226
|
+
* @param {SignerBody<R>} body The request body containing the data to be sent
|
|
227
|
+
* @returns {Promise<SignerResponse<R>>} A promise that resolves to the response from the signer
|
|
228
|
+
*/
|
|
149
229
|
Object.defineProperty(this, "request", {
|
|
150
230
|
enumerable: true,
|
|
151
231
|
configurable: true,
|
|
@@ -173,6 +253,8 @@ export class BaseSignerClient {
|
|
|
173
253
|
return json;
|
|
174
254
|
}
|
|
175
255
|
});
|
|
256
|
+
// #endregion
|
|
257
|
+
// #region PRIVATE METHODS
|
|
176
258
|
Object.defineProperty(this, "exportAsSeedPhrase", {
|
|
177
259
|
enumerable: true,
|
|
178
260
|
configurable: true,
|
|
@@ -234,6 +316,7 @@ export class BaseSignerClient {
|
|
|
234
316
|
return result;
|
|
235
317
|
}
|
|
236
318
|
});
|
|
319
|
+
// eslint-disable-next-line eslint-rules/require-jsdoc-on-reexported-functions
|
|
237
320
|
Object.defineProperty(this, "pollActivityCompletion", {
|
|
238
321
|
enumerable: true,
|
|
239
322
|
configurable: true,
|
|
@@ -254,6 +337,7 @@ export class BaseSignerClient {
|
|
|
254
337
|
status === "ACTIVITY_STATUS_CONSENSUS_NEEDED") {
|
|
255
338
|
throw new Error(`Failed to get activity with with id ${id} (status: ${status})`);
|
|
256
339
|
}
|
|
340
|
+
// TODO: add ability to configure this + add exponential backoff
|
|
257
341
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
258
342
|
return this.pollActivityCompletion(activity, organizationId, resultKey);
|
|
259
343
|
}
|
|
@@ -276,9 +360,22 @@ export class BaseSignerClient {
|
|
|
276
360
|
}
|
|
277
361
|
this._user = user;
|
|
278
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* Sets the stamper of the TurnkeyClient.
|
|
365
|
+
*
|
|
366
|
+
* @param {TurnkeyClient["stamper"]} stamper the stamper function to set for the TurnkeyClient
|
|
367
|
+
*/
|
|
279
368
|
setStamper(stamper) {
|
|
280
369
|
this.turnkeyClient.stamper = stamper;
|
|
281
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Exports wallet credentials based on the specified type, either as a SEED_PHRASE or PRIVATE_KEY.
|
|
373
|
+
*
|
|
374
|
+
* @param {object} params The parameters for exporting the wallet
|
|
375
|
+
* @param {ExportWalletStamper} params.exportStamper The stamper used for exporting the wallet
|
|
376
|
+
* @param {"SEED_PHRASE" | "PRIVATE_KEY"} params.exportAs Specifies the format for exporting the wallet, either as a SEED_PHRASE or PRIVATE_KEY
|
|
377
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the export is successful
|
|
378
|
+
*/
|
|
282
379
|
exportWalletInner(params) {
|
|
283
380
|
switch (params.exportAs) {
|
|
284
381
|
case "PRIVATE_KEY":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/client/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AA8B9D,MAAM,OAAgB,gBAAgB;IAYpC,YAAY,MAA8B;QAXlC;;;;;WAAwB;QACxB;;;;;WAAmC;QACjC;;;;;WAA6B;QAC7B;;;;;WAAgB;QAChB;;;;;WAAsD;QAmGzD;;;;mBAAK,CACV,KAAQ,EACR,QAAsC,EACtC,EAAE;gBACF,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,QAAe,CAAC,CAAC;gBAE7C,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,KAAK,EAAE,QAAe,CAAC,CAAC;YACxE,CAAC;WA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G,SAAS,IAAI,sCAAsC,CAAC;QACnE,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,EAA6B,CAAC;QAClE,IAAI,CAAC,gBAAgB,GAAG,sBAAsB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACjE,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CACpC,EAAE,OAAO,EAAE,yBAAyB,EAAE,EACtC,OAAO,CACR,CAAC;IACJ,CAAC;IAED,IAAc,IAAI;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAc,IAAI,CAAC,IAAsB;QACvC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACxB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;aAAM,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC/B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACzC,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAOS,UAAU,CAAC,OAAiC;QACpD,IAAI,CAAC,aAAa,CAAC,OAAO,GAAG,OAAO,CAAC;IACvC,CAAC;IAUS,iBAAiB,CAAC,MAG3B;QACC,QAAQ,MAAM,CAAC,QAAQ,EAAE,CAAC;YACxB,KAAK,aAAa;gBAChB,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YACvD,KAAK,aAAa;gBAChB,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;CAiWF","sourcesContent":["import { type ConnectionConfig, ConnectionConfigSchema } from \"@aa-sdk/core\";\nimport { TurnkeyClient } from \"@turnkey/http\";\nimport EventEmitter from \"eventemitter3\";\nimport type { Hex } from \"viem\";\nimport { NotAuthenticatedError } from \"../errors.js\";\nimport { base64UrlEncode } from \"../utils/base64UrlEncode.js\";\nimport type {\n AlchemySignerClientEvent,\n AlchemySignerClientEvents,\n CreateAccountParams,\n EmailAuthParams,\n GetWebAuthnAttestationResult,\n SignerBody,\n SignerResponse,\n SignerRoutes,\n SignupResponse,\n User,\n} from \"./types.js\";\n\nexport interface BaseSignerClientParams {\n stamper: TurnkeyClient[\"stamper\"];\n connection: ConnectionConfig;\n rootOrgId?: string;\n rpId?: string;\n}\n\nexport type ExportWalletStamper = TurnkeyClient[\"stamper\"] & {\n injectWalletExportBundle(bundle: string): Promise<boolean>;\n injectKeyExportBundle(bundle: string): Promise<boolean>;\n publicKey(): string | null;\n};\n\n/**\n * Base class for all Alchemy Signer clients\n */\nexport abstract class BaseSignerClient<TExportWalletParams = unknown> {\n private _user: User | undefined;\n private connectionConfig: ConnectionConfig;\n protected turnkeyClient: TurnkeyClient;\n protected rootOrg: string;\n protected eventEmitter: EventEmitter<AlchemySignerClientEvents>;\n\n /**\n * Create a new instance of the Alchemy Signer client\n *\n * @param {BaseSignerClientParams} params the parameters required to create the client\n */\n constructor(params: BaseSignerClientParams) {\n const { stamper, connection, rootOrgId } = params;\n\n this.rootOrg = rootOrgId ?? \"24c1acf5-810f-41e0-a503-d5d13fa8e830\";\n this.eventEmitter = new EventEmitter<AlchemySignerClientEvents>();\n this.connectionConfig = ConnectionConfigSchema.parse(connection);\n this.turnkeyClient = new TurnkeyClient(\n { baseUrl: \"https://api.turnkey.com\" },\n stamper\n );\n }\n\n protected get user() {\n return this._user;\n }\n\n protected set user(user: User | undefined) {\n if (user && !this._user) {\n this.eventEmitter.emit(\"connected\", user);\n } else if (!user && this._user) {\n this.eventEmitter.emit(\"disconnected\");\n }\n\n this._user = user;\n }\n\n /**\n * Sets the stamper of the TurnkeyClient.\n *\n * @param {TurnkeyClient[\"stamper\"]} stamper the stamper function to set for the TurnkeyClient\n */\n protected setStamper(stamper: TurnkeyClient[\"stamper\"]) {\n this.turnkeyClient.stamper = stamper;\n }\n\n /**\n * Exports wallet credentials based on the specified type, either as a SEED_PHRASE or PRIVATE_KEY.\n *\n * @param {object} params The parameters for exporting the wallet\n * @param {ExportWalletStamper} params.exportStamper The stamper used for exporting the wallet\n * @param {\"SEED_PHRASE\" | \"PRIVATE_KEY\"} params.exportAs Specifies the format for exporting the wallet, either as a SEED_PHRASE or PRIVATE_KEY\n * @returns {Promise<boolean>} A promise that resolves to true if the export is successful\n */\n protected exportWalletInner(params: {\n exportStamper: ExportWalletStamper;\n exportAs: \"SEED_PHRASE\" | \"PRIVATE_KEY\";\n }): Promise<boolean> {\n switch (params.exportAs) {\n case \"PRIVATE_KEY\":\n return this.exportAsPrivateKey(params.exportStamper);\n case \"SEED_PHRASE\":\n return this.exportAsSeedPhrase(params.exportStamper);\n }\n }\n\n // #region ABSTRACT METHODS\n\n public abstract createAccount(\n params: CreateAccountParams\n ): Promise<SignupResponse>;\n\n public abstract initEmailAuth(\n params: Omit<EmailAuthParams, \"targetPublicKey\">\n ): Promise<{ orgId: string }>;\n\n public abstract completeEmailAuth(params: {\n bundle: string;\n orgId: string;\n }): Promise<User>;\n\n public abstract disconnect(): Promise<void>;\n\n public abstract exportWallet(params: TExportWalletParams): Promise<boolean>;\n\n public abstract lookupUserWithPasskey(user?: User): Promise<User>;\n\n protected abstract getWebAuthnAttestation(\n options: CredentialCreationOptions,\n userDetails?: { username: string }\n ): Promise<GetWebAuthnAttestationResult>;\n\n // #endregion\n\n // #region PUBLIC METHODS\n\n /**\n * Listen to events emitted by the client\n *\n * @param {AlchemySignerClientEvent} event the event you want to listen to\n * @param {AlchemySignerClientEvents[AlchemySignerClientEvent]} listener the callback function to execute when an event is fired\n * @returns {() => void} a function that will remove the listener when called\n */\n public on = <E extends AlchemySignerClientEvent>(\n event: E,\n listener: AlchemySignerClientEvents[E]\n ) => {\n this.eventEmitter.on(event, listener as any);\n\n return () => this.eventEmitter.removeListener(event, listener as any);\n };\n\n /**\n * Handles the creation of authenticators using WebAuthn attestation and the provided options. Requires the user to be authenticated.\n *\n * @param {CredentialCreationOptions} options The options used to create the WebAuthn attestation\n * @returns {Promise<string[]>} A promise that resolves to an array of authenticator IDs\n * @throws {NotAuthenticatedError} If the user is not authenticated\n */\n public addPasskey = async (options: CredentialCreationOptions) => {\n if (!this.user) {\n throw new NotAuthenticatedError();\n }\n const { attestation, challenge } = await this.getWebAuthnAttestation(\n options\n );\n\n const { activity } = await this.turnkeyClient.createAuthenticators({\n type: \"ACTIVITY_TYPE_CREATE_AUTHENTICATORS_V2\",\n timestampMs: Date.now().toString(),\n organizationId: this.user.orgId,\n parameters: {\n userId: this.user.userId,\n authenticators: [\n {\n attestation,\n authenticatorName: `passkey-${Date.now().toString()}`,\n challenge: base64UrlEncode(challenge),\n },\n ],\n },\n });\n\n const { authenticatorIds } = await this.pollActivityCompletion(\n activity,\n this.user.orgId,\n \"createAuthenticatorsResult\"\n );\n\n return authenticatorIds;\n };\n\n /**\n * Retrieves the current user or fetches the user information if not already available.\n *\n * @param {string} [orgId] optional organization ID, defaults to the user's organization ID\n * @returns {Promise<User>} A promise that resolves to the user object\n * @throws {Error} if no organization ID is provided when there is no current user\n */\n public whoami = async (orgId = this.user?.orgId): Promise<User> => {\n if (this.user) {\n return this.user;\n }\n\n if (!orgId) {\n throw new Error(\"No orgId provided\");\n }\n\n const stampedRequest = await this.turnkeyClient.stampGetWhoami({\n organizationId: orgId,\n });\n\n const user = await this.request(\"/v1/whoami\", {\n stampedRequest,\n });\n\n const credentialId = (() => {\n try {\n return JSON.parse(stampedRequest?.stamp.stampHeaderValue)\n .credentialId as string;\n } catch (e) {\n return undefined;\n }\n })();\n\n this.user = {\n ...user,\n credentialId,\n };\n\n return this.user;\n };\n\n /**\n * Looks up information based on an email address.\n *\n * @param {string} email the email address to look up\n * @returns {Promise<any>} the result of the lookup request\n */\n public lookupUserByEmail = async (email: string) => {\n return this.request(\"/v1/lookup\", { email });\n };\n\n /**\n * This will sign a message with the user's private key, without doing any transformations on the message.\n * For SignMessage or SignTypedData, the caller should hash the message before calling this method and pass\n * that result here.\n *\n * @param {Hex} msg the hex representation of the bytes to sign\n * @returns {Promise<Hex>} the signature over the raw hex\n */\n public signRawMessage = async (msg: Hex): Promise<Hex> => {\n if (!this.user) {\n throw new NotAuthenticatedError();\n }\n\n const stampedRequest = await this.turnkeyClient.stampSignRawPayload({\n organizationId: this.user.orgId,\n type: \"ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2\",\n timestampMs: Date.now().toString(),\n parameters: {\n encoding: \"PAYLOAD_ENCODING_HEXADECIMAL\",\n hashFunction: \"HASH_FUNCTION_NO_OP\",\n payload: msg,\n signWith: this.user.address,\n },\n });\n\n const { signature } = await this.request(\"/v1/sign-payload\", {\n stampedRequest,\n });\n\n return signature;\n };\n\n /**\n * Returns the current user or null if no user is set.\n *\n * @returns {User | null} the current user object or null if no user is available\n */\n public getUser = (): User | null => {\n return this.user ?? null;\n };\n\n /**\n * Sends a POST request to the given signer route with the specified body and returns the response.\n * Not intended to be used directly, use the specific methods instead on the client instead.\n *\n * @param {SignerRoutes} route The route to which the request should be sent\n * @param {SignerBody<R>} body The request body containing the data to be sent\n * @returns {Promise<SignerResponse<R>>} A promise that resolves to the response from the signer\n */\n public request = async <R extends SignerRoutes>(\n route: R,\n body: SignerBody<R>\n ): Promise<SignerResponse<R>> => {\n const url = this.connectionConfig.rpcUrl ?? \"https://api.g.alchemy.com\";\n const basePath = \"/signer\";\n\n const headers = new Headers();\n headers.append(\"Content-Type\", \"application/json\");\n if (this.connectionConfig.apiKey) {\n headers.append(\"Authorization\", `Bearer ${this.connectionConfig.apiKey}`);\n } else if (this.connectionConfig.jwt) {\n headers.append(\"Authorization\", `Bearer ${this.connectionConfig.jwt}`);\n }\n\n const response = await fetch(`${url}${basePath}${route}`, {\n method: \"POST\",\n body: JSON.stringify(body),\n headers,\n });\n\n if (!response.ok) {\n throw new Error(await response.text());\n }\n\n const json = await response.json();\n\n return json as SignerResponse<R>;\n };\n\n // #endregion\n\n // #region PRIVATE METHODS\n private exportAsSeedPhrase = async (stamper: ExportWalletStamper) => {\n if (!this.user) {\n throw new NotAuthenticatedError();\n }\n\n const { wallets } = await this.turnkeyClient.getWallets({\n organizationId: this.user.orgId,\n });\n\n const walletAccounts = await Promise.all(\n wallets.map(({ walletId }) =>\n this.turnkeyClient.getWalletAccounts({\n organizationId: this.user!.orgId,\n walletId,\n })\n )\n ).then((x) => x.flatMap((x) => x.accounts));\n\n const walletAccount = walletAccounts.find(\n (x) => x.address === this.user!.address\n );\n\n if (!walletAccount) {\n throw new Error(\n `Could not find wallet associated with ${this.user.address}`\n );\n }\n\n const { activity } = await this.turnkeyClient.exportWallet({\n organizationId: this.user.orgId,\n type: \"ACTIVITY_TYPE_EXPORT_WALLET\",\n timestampMs: Date.now().toString(),\n parameters: {\n walletId: walletAccount!.walletId,\n targetPublicKey: stamper.publicKey()!,\n },\n });\n\n const { exportBundle } = await this.pollActivityCompletion(\n activity,\n this.user.orgId,\n \"exportWalletResult\"\n );\n\n const result = await stamper.injectWalletExportBundle(exportBundle);\n\n if (!result) {\n throw new Error(\"Failed to inject wallet export bundle\");\n }\n\n return result;\n };\n\n private exportAsPrivateKey = async (stamper: ExportWalletStamper) => {\n if (!this.user) {\n throw new NotAuthenticatedError();\n }\n\n const { activity } = await this.turnkeyClient.exportWalletAccount({\n organizationId: this.user.orgId,\n type: \"ACTIVITY_TYPE_EXPORT_WALLET_ACCOUNT\",\n timestampMs: Date.now().toString(),\n parameters: {\n address: this.user.address,\n targetPublicKey: stamper.publicKey()!,\n },\n });\n\n const { exportBundle } = await this.pollActivityCompletion(\n activity,\n this.user.orgId,\n \"exportWalletAccountResult\"\n );\n\n const result = await stamper.injectKeyExportBundle(exportBundle);\n\n if (!result) {\n throw new Error(\"Failed to inject wallet export bundle\");\n }\n\n return result;\n };\n\n // eslint-disable-next-line eslint-rules/require-jsdoc-on-reexported-functions\n protected pollActivityCompletion = async <\n T extends keyof Awaited<\n ReturnType<(typeof this.turnkeyClient)[\"getActivity\"]>\n >[\"activity\"][\"result\"]\n >(\n activity: Awaited<\n ReturnType<(typeof this.turnkeyClient)[\"getActivity\"]>\n >[\"activity\"],\n organizationId: string,\n resultKey: T\n ): Promise<\n NonNullable<\n Awaited<\n ReturnType<(typeof this.turnkeyClient)[\"getActivity\"]>\n >[\"activity\"][\"result\"][T]\n >\n > => {\n if (activity.status === \"ACTIVITY_STATUS_COMPLETED\") {\n return activity.result[resultKey]!;\n }\n\n const {\n activity: { status, id, result },\n } = await this.turnkeyClient.getActivity({\n activityId: activity.id,\n organizationId,\n });\n\n if (status === \"ACTIVITY_STATUS_COMPLETED\") {\n return result[resultKey]!;\n }\n\n if (\n status === \"ACTIVITY_STATUS_FAILED\" ||\n status === \"ACTIVITY_STATUS_REJECTED\" ||\n status === \"ACTIVITY_STATUS_CONSENSUS_NEEDED\"\n ) {\n throw new Error(\n `Failed to get activity with with id ${id} (status: ${status})`\n );\n }\n\n // TODO: add ability to configure this + add exponential backoff\n await new Promise((resolve) => setTimeout(resolve, 500));\n\n return this.pollActivityCompletion(activity, organizationId, resultKey);\n };\n // #endregion\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/client/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAyB,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAuB,MAAM,eAAe,CAAC;AACnE,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AA2B9D;;GAEG;AACH,MAAM,OAAgB,gBAAgB;IAOpC;;;;OAIG;IACH,YAAY,MAA8B;QAXlC;;;;;WAAwB;QACxB;;;;;WAAmC;QACjC;;;;;WAA6B;QAC7B;;;;;WAAgB;QAChB;;;;;WAAsD;QAwFhE,aAAa;QAEb,yBAAyB;QAEzB;;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aAAM,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC/B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACzC,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACO,UAAU,CAAC,OAAiC;QACpD,IAAI,CAAC,aAAa,CAAC,OAAO,GAAG,OAAO,CAAC;IACvC,CAAC;IAED;;;;;;;OAOG;IACO,iBAAiB,CAAC,MAG3B;QACC,QAAQ,MAAM,CAAC,QAAQ,EAAE,CAAC;YACxB,KAAK,aAAa;gBAChB,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YACvD,KAAK,aAAa;gBAChB,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;CAoXF","sourcesContent":["import { ConnectionConfigSchema, type ConnectionConfig } from \"@aa-sdk/core\";\nimport { TurnkeyClient, type TSignedRequest } from \"@turnkey/http\";\nimport EventEmitter from \"eventemitter3\";\nimport type { Hex } from \"viem\";\nimport { NotAuthenticatedError } from \"../errors.js\";\nimport { base64UrlEncode } from \"../utils/base64UrlEncode.js\";\nimport type {\n AlchemySignerClientEvent,\n AlchemySignerClientEvents,\n CreateAccountParams,\n EmailAuthParams,\n GetWebAuthnAttestationResult,\n SignerBody,\n SignerResponse,\n SignerRoutes,\n SignupResponse,\n User,\n} from \"./types.js\";\n\nexport interface BaseSignerClientParams {\n stamper: TurnkeyClient[\"stamper\"];\n connection: ConnectionConfig;\n rootOrgId?: string;\n rpId?: string;\n}\n\nexport type ExportWalletStamper = TurnkeyClient[\"stamper\"] & {\n injectWalletExportBundle(bundle: string): Promise<boolean>;\n injectKeyExportBundle(bundle: string): Promise<boolean>;\n publicKey(): string | null;\n};\n\n/**\n * Base class for all Alchemy Signer clients\n */\nexport abstract class BaseSignerClient<TExportWalletParams = unknown> {\n private _user: User | undefined;\n private connectionConfig: ConnectionConfig;\n protected turnkeyClient: TurnkeyClient;\n protected rootOrg: string;\n protected eventEmitter: EventEmitter<AlchemySignerClientEvents>;\n\n /**\n * Create a new instance of the Alchemy Signer client\n *\n * @param {BaseSignerClientParams} params the parameters required to create the client\n */\n constructor(params: BaseSignerClientParams) {\n const { stamper, connection, rootOrgId } = params;\n\n this.rootOrg = rootOrgId ?? \"24c1acf5-810f-41e0-a503-d5d13fa8e830\";\n this.eventEmitter = new EventEmitter<AlchemySignerClientEvents>();\n this.connectionConfig = ConnectionConfigSchema.parse(connection);\n this.turnkeyClient = new TurnkeyClient(\n { baseUrl: \"https://api.turnkey.com\" },\n stamper\n );\n }\n\n protected get user() {\n return this._user;\n }\n\n protected set user(user: User | undefined) {\n if (user && !this._user) {\n this.eventEmitter.emit(\"connected\", user);\n } else if (!user && this._user) {\n this.eventEmitter.emit(\"disconnected\");\n }\n\n this._user = user;\n }\n\n /**\n * Sets the stamper of the TurnkeyClient.\n *\n * @param {TurnkeyClient[\"stamper\"]} stamper the stamper function to set for the TurnkeyClient\n */\n protected setStamper(stamper: TurnkeyClient[\"stamper\"]) {\n this.turnkeyClient.stamper = stamper;\n }\n\n /**\n * Exports wallet credentials based on the specified type, either as a SEED_PHRASE or PRIVATE_KEY.\n *\n * @param {object} params The parameters for exporting the wallet\n * @param {ExportWalletStamper} params.exportStamper The stamper used for exporting the wallet\n * @param {\"SEED_PHRASE\" | \"PRIVATE_KEY\"} params.exportAs Specifies the format for exporting the wallet, either as a SEED_PHRASE or PRIVATE_KEY\n * @returns {Promise<boolean>} A promise that resolves to true if the export is successful\n */\n protected exportWalletInner(params: {\n exportStamper: ExportWalletStamper;\n exportAs: \"SEED_PHRASE\" | \"PRIVATE_KEY\";\n }): Promise<boolean> {\n switch (params.exportAs) {\n case \"PRIVATE_KEY\":\n return this.exportAsPrivateKey(params.exportStamper);\n case \"SEED_PHRASE\":\n return this.exportAsSeedPhrase(params.exportStamper);\n }\n }\n\n // #region ABSTRACT METHODS\n\n public abstract createAccount(\n params: CreateAccountParams\n ): Promise<SignupResponse>;\n\n public abstract initEmailAuth(\n params: Omit<EmailAuthParams, \"targetPublicKey\">\n ): Promise<{ orgId: string }>;\n\n public abstract completeEmailAuth(params: {\n bundle: string;\n orgId: string;\n }): Promise<User>;\n\n public abstract disconnect(): Promise<void>;\n\n public abstract exportWallet(params: TExportWalletParams): Promise<boolean>;\n\n public abstract lookupUserWithPasskey(user?: User): Promise<User>;\n\n protected abstract getWebAuthnAttestation(\n options: CredentialCreationOptions,\n userDetails?: { username: string }\n ): Promise<GetWebAuthnAttestationResult>;\n\n // #endregion\n\n // #region PUBLIC METHODS\n\n /**\n * Listen to events emitted by the client\n *\n * @param {AlchemySignerClientEvent} event the event you want to listen to\n * @param {AlchemySignerClientEvents[AlchemySignerClientEvent]} listener the callback function to execute when an event is fired\n * @returns {() => void} a function that will remove the listener when called\n */\n public on = <E extends AlchemySignerClientEvent>(\n event: E,\n listener: AlchemySignerClientEvents[E]\n ) => {\n this.eventEmitter.on(event, listener as any);\n\n return () => this.eventEmitter.removeListener(event, listener as any);\n };\n\n /**\n * Handles the creation of authenticators using WebAuthn attestation and the provided options. Requires the user to be authenticated.\n *\n * @param {CredentialCreationOptions} options The options used to create the WebAuthn attestation\n * @returns {Promise<string[]>} A promise that resolves to an array of authenticator IDs\n * @throws {NotAuthenticatedError} If the user is not authenticated\n */\n public addPasskey = async (options: CredentialCreationOptions) => {\n if (!this.user) {\n throw new NotAuthenticatedError();\n }\n const { attestation, challenge } = await this.getWebAuthnAttestation(\n options\n );\n\n const { activity } = await this.turnkeyClient.createAuthenticators({\n type: \"ACTIVITY_TYPE_CREATE_AUTHENTICATORS_V2\",\n timestampMs: Date.now().toString(),\n organizationId: this.user.orgId,\n parameters: {\n userId: this.user.userId,\n authenticators: [\n {\n attestation,\n authenticatorName: `passkey-${Date.now().toString()}`,\n challenge: base64UrlEncode(challenge),\n },\n ],\n },\n });\n\n const { authenticatorIds } = await this.pollActivityCompletion(\n activity,\n this.user.orgId,\n \"createAuthenticatorsResult\"\n );\n\n return authenticatorIds;\n };\n\n /**\n * Retrieves the current user or fetches the user information if not already available.\n *\n * @param {string} [orgId] optional organization ID, defaults to the user's organization ID\n * @returns {Promise<User>} A promise that resolves to the user object\n * @throws {Error} if no organization ID is provided when there is no current user\n */\n public whoami = async (orgId = this.user?.orgId): Promise<User> => {\n if (this.user) {\n return this.user;\n }\n\n if (!orgId) {\n throw new Error(\"No orgId provided\");\n }\n\n const stampedRequest = await this.turnkeyClient.stampGetWhoami({\n organizationId: orgId,\n });\n\n const user = await this.request(\"/v1/whoami\", {\n stampedRequest,\n });\n\n const credentialId = (() => {\n try {\n return JSON.parse(stampedRequest?.stamp.stampHeaderValue)\n .credentialId as string;\n } catch (e) {\n return undefined;\n }\n })();\n\n this.user = {\n ...user,\n credentialId,\n };\n\n return this.user;\n };\n\n /**\n * Generates a stamped whoami request for the current user. This request can then be used to call /signer/v1/whoami to get the user information.\n * This is useful if you want to get the user information in a different context like a server. You can pass the stamped request to the server\n * and then call our API to get the user information. Using this stamp is the most trusted way to get the user information since a stamp can only\n * belong to the user who created it.\n *\n * @returns {Promise<TSignedRequest>} a promise that resolves to the \"whoami\" information for the logged in user\n * @throws {Error} if no organization ID is provided\n */\n public stampWhoami = async (): Promise<TSignedRequest> => {\n if (!this.user) {\n throw new Error(\"User must be authenticated to stamp a whoami request\");\n }\n\n return await this.turnkeyClient.stampGetWhoami({\n organizationId: this.user.orgId,\n });\n };\n\n /**\n * Looks up information based on an email address.\n *\n * @param {string} email the email address to look up\n * @returns {Promise<any>} the result of the lookup request\n */\n public lookupUserByEmail = async (email: string) => {\n return this.request(\"/v1/lookup\", { email });\n };\n\n /**\n * This will sign a message with the user's private key, without doing any transformations on the message.\n * For SignMessage or SignTypedData, the caller should hash the message before calling this method and pass\n * that result here.\n *\n * @param {Hex} msg the hex representation of the bytes to sign\n * @returns {Promise<Hex>} the signature over the raw hex\n */\n public signRawMessage = async (msg: Hex): Promise<Hex> => {\n if (!this.user) {\n throw new NotAuthenticatedError();\n }\n\n const stampedRequest = await this.turnkeyClient.stampSignRawPayload({\n organizationId: this.user.orgId,\n type: \"ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2\",\n timestampMs: Date.now().toString(),\n parameters: {\n encoding: \"PAYLOAD_ENCODING_HEXADECIMAL\",\n hashFunction: \"HASH_FUNCTION_NO_OP\",\n payload: msg,\n signWith: this.user.address,\n },\n });\n\n const { signature } = await this.request(\"/v1/sign-payload\", {\n stampedRequest,\n });\n\n return signature;\n };\n\n /**\n * Returns the current user or null if no user is set.\n *\n * @returns {User | null} the current user object or null if no user is available\n */\n public getUser = (): User | null => {\n return this.user ?? null;\n };\n\n /**\n * Sends a POST request to the given signer route with the specified body and returns the response.\n * Not intended to be used directly, use the specific methods instead on the client instead.\n *\n * @param {SignerRoutes} route The route to which the request should be sent\n * @param {SignerBody<R>} body The request body containing the data to be sent\n * @returns {Promise<SignerResponse<R>>} A promise that resolves to the response from the signer\n */\n public request = async <R extends SignerRoutes>(\n route: R,\n body: SignerBody<R>\n ): Promise<SignerResponse<R>> => {\n const url = this.connectionConfig.rpcUrl ?? \"https://api.g.alchemy.com\";\n const basePath = \"/signer\";\n\n const headers = new Headers();\n headers.append(\"Content-Type\", \"application/json\");\n if (this.connectionConfig.apiKey) {\n headers.append(\"Authorization\", `Bearer ${this.connectionConfig.apiKey}`);\n } else if (this.connectionConfig.jwt) {\n headers.append(\"Authorization\", `Bearer ${this.connectionConfig.jwt}`);\n }\n\n const response = await fetch(`${url}${basePath}${route}`, {\n method: \"POST\",\n body: JSON.stringify(body),\n headers,\n });\n\n if (!response.ok) {\n throw new Error(await response.text());\n }\n\n const json = await response.json();\n\n return json as SignerResponse<R>;\n };\n\n // #endregion\n\n // #region PRIVATE METHODS\n private exportAsSeedPhrase = async (stamper: ExportWalletStamper) => {\n if (!this.user) {\n throw new NotAuthenticatedError();\n }\n\n const { wallets } = await this.turnkeyClient.getWallets({\n organizationId: this.user.orgId,\n });\n\n const walletAccounts = await Promise.all(\n wallets.map(({ walletId }) =>\n this.turnkeyClient.getWalletAccounts({\n organizationId: this.user!.orgId,\n walletId,\n })\n )\n ).then((x) => x.flatMap((x) => x.accounts));\n\n const walletAccount = walletAccounts.find(\n (x) => x.address === this.user!.address\n );\n\n if (!walletAccount) {\n throw new Error(\n `Could not find wallet associated with ${this.user.address}`\n );\n }\n\n const { activity } = await this.turnkeyClient.exportWallet({\n organizationId: this.user.orgId,\n type: \"ACTIVITY_TYPE_EXPORT_WALLET\",\n timestampMs: Date.now().toString(),\n parameters: {\n walletId: walletAccount!.walletId,\n targetPublicKey: stamper.publicKey()!,\n },\n });\n\n const { exportBundle } = await this.pollActivityCompletion(\n activity,\n this.user.orgId,\n \"exportWalletResult\"\n );\n\n const result = await stamper.injectWalletExportBundle(exportBundle);\n\n if (!result) {\n throw new Error(\"Failed to inject wallet export bundle\");\n }\n\n return result;\n };\n\n private exportAsPrivateKey = async (stamper: ExportWalletStamper) => {\n if (!this.user) {\n throw new NotAuthenticatedError();\n }\n\n const { activity } = await this.turnkeyClient.exportWalletAccount({\n organizationId: this.user.orgId,\n type: \"ACTIVITY_TYPE_EXPORT_WALLET_ACCOUNT\",\n timestampMs: Date.now().toString(),\n parameters: {\n address: this.user.address,\n targetPublicKey: stamper.publicKey()!,\n },\n });\n\n const { exportBundle } = await this.pollActivityCompletion(\n activity,\n this.user.orgId,\n \"exportWalletAccountResult\"\n );\n\n const result = await stamper.injectKeyExportBundle(exportBundle);\n\n if (!result) {\n throw new Error(\"Failed to inject wallet export bundle\");\n }\n\n return result;\n };\n\n // eslint-disable-next-line eslint-rules/require-jsdoc-on-reexported-functions\n protected pollActivityCompletion = async <\n T extends keyof Awaited<\n ReturnType<(typeof this.turnkeyClient)[\"getActivity\"]>\n >[\"activity\"][\"result\"]\n >(\n activity: Awaited<\n ReturnType<(typeof this.turnkeyClient)[\"getActivity\"]>\n >[\"activity\"],\n organizationId: string,\n resultKey: T\n ): Promise<\n NonNullable<\n Awaited<\n ReturnType<(typeof this.turnkeyClient)[\"getActivity\"]>\n >[\"activity\"][\"result\"][T]\n >\n > => {\n if (activity.status === \"ACTIVITY_STATUS_COMPLETED\") {\n return activity.result[resultKey]!;\n }\n\n const {\n activity: { status, id, result },\n } = await this.turnkeyClient.getActivity({\n activityId: activity.id,\n organizationId,\n });\n\n if (status === \"ACTIVITY_STATUS_COMPLETED\") {\n return result[resultKey]!;\n }\n\n if (\n status === \"ACTIVITY_STATUS_FAILED\" ||\n status === \"ACTIVITY_STATUS_REJECTED\" ||\n status === \"ACTIVITY_STATUS_CONSENSUS_NEEDED\"\n ) {\n throw new Error(\n `Failed to get activity with with id ${id} (status: ${status})`\n );\n }\n\n // TODO: add ability to configure this + add exponential backoff\n await new Promise((resolve) => setTimeout(resolve, 500));\n\n return this.pollActivityCompletion(activity, organizationId, resultKey);\n };\n // #endregion\n}\n"]}
|
|
@@ -113,21 +113,183 @@ export declare const AlchemySignerClientParamsSchema: z.ZodObject<{
|
|
|
113
113
|
rootOrgId?: string | undefined;
|
|
114
114
|
}>;
|
|
115
115
|
export type AlchemySignerClientParams = z.input<typeof AlchemySignerClientParamsSchema>;
|
|
116
|
+
/**
|
|
117
|
+
* A lower level client used by the AlchemySigner used to communicate with
|
|
118
|
+
* Alchemy's signer service.
|
|
119
|
+
*/
|
|
116
120
|
export declare class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams> {
|
|
117
121
|
private iframeStamper;
|
|
118
122
|
private webauthnStamper;
|
|
119
123
|
iframeContainerId: string;
|
|
124
|
+
/**
|
|
125
|
+
* Initializes a new instance with the given parameters, setting up the connection, iframe configuration, and WebAuthn stamper.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
130
|
+
*
|
|
131
|
+
* const client = new AlchemySignerWebClient({
|
|
132
|
+
* connection: {
|
|
133
|
+
* apiKey: "your-api-key",
|
|
134
|
+
* },
|
|
135
|
+
* iframeConfig: {
|
|
136
|
+
* iframeContainerId: "signer-iframe-container",
|
|
137
|
+
* },
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @param {AlchemySignerClientParams} params the parameters required to initialize the client
|
|
142
|
+
* @param {ConnectionConfig} params.connection The connection details needed to connect to the service
|
|
143
|
+
* @param {{ iframeElementId?: string; iframeContainerId: string }} params.iframeConfig The configuration details for setting up the iframe stamper
|
|
144
|
+
* @param {string} params.rpId The relying party ID, defaulting to the current hostname if not provided
|
|
145
|
+
* @param {string} params.rootOrgId The root organization ID
|
|
146
|
+
*/
|
|
120
147
|
constructor(params: AlchemySignerClientParams);
|
|
148
|
+
/**
|
|
149
|
+
* Authenticates the user by either email or passkey account creation flow. Emits events during the process.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
154
|
+
*
|
|
155
|
+
* const client = new AlchemySignerWebClient({
|
|
156
|
+
* connection: {
|
|
157
|
+
* apiKey: "your-api-key",
|
|
158
|
+
* },
|
|
159
|
+
* iframeConfig: {
|
|
160
|
+
* iframeContainerId: "signer-iframe-container",
|
|
161
|
+
* },
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* const account = await client.createAccount({ type: "email", email: "you@mail.com" });
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* @param {CreateAccountParams} params The parameters for creating an account, including the type (email or passkey) and additional details.
|
|
168
|
+
* @returns {Promise<SignupResponse>} A promise that resolves with the response object containing the account creation result.
|
|
169
|
+
*/
|
|
121
170
|
createAccount: (params: CreateAccountParams) => Promise<import("./types.js").SignupResponse>;
|
|
171
|
+
/**
|
|
172
|
+
* 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.
|
|
173
|
+
* This method sends an email to the user to complete their login
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
178
|
+
*
|
|
179
|
+
* const client = new AlchemySignerWebClient({
|
|
180
|
+
* connection: {
|
|
181
|
+
* apiKey: "your-api-key",
|
|
182
|
+
* },
|
|
183
|
+
* iframeConfig: {
|
|
184
|
+
* iframeContainerId: "signer-iframe-container",
|
|
185
|
+
* },
|
|
186
|
+
* });
|
|
187
|
+
*
|
|
188
|
+
* const account = await client.initEmailAuth({ email: "you@mail.com" });
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* @param {Omit<EmailAuthParams, "targetPublicKey">} params The parameters for email authentication, excluding the target public key
|
|
192
|
+
* @returns {Promise<any>} The response from the authentication request
|
|
193
|
+
*/
|
|
122
194
|
initEmailAuth: (params: Omit<EmailAuthParams, "targetPublicKey">) => Promise<{
|
|
123
195
|
orgId: string;
|
|
124
196
|
}>;
|
|
197
|
+
/**
|
|
198
|
+
* 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.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
203
|
+
*
|
|
204
|
+
* const client = new AlchemySignerWebClient({
|
|
205
|
+
* connection: {
|
|
206
|
+
* apiKey: "your-api-key",
|
|
207
|
+
* },
|
|
208
|
+
* iframeConfig: {
|
|
209
|
+
* iframeContainerId: "signer-iframe-container",
|
|
210
|
+
* },
|
|
211
|
+
* });
|
|
212
|
+
*
|
|
213
|
+
* const account = await client.completeEmailAuth({ orgId: "user-org-id", bundle: "bundle-from-email" });
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @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
|
|
217
|
+
* @returns {Promise<User>} A promise that resolves to the authenticated user information
|
|
218
|
+
*/
|
|
125
219
|
completeEmailAuth: ({ bundle, orgId, }: {
|
|
126
220
|
bundle: string;
|
|
127
221
|
orgId: string;
|
|
128
222
|
}) => Promise<User>;
|
|
223
|
+
/**
|
|
224
|
+
* 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.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
229
|
+
*
|
|
230
|
+
* const client = new AlchemySignerWebClient({
|
|
231
|
+
* connection: {
|
|
232
|
+
* apiKey: "your-api-key",
|
|
233
|
+
* },
|
|
234
|
+
* iframeConfig: {
|
|
235
|
+
* iframeContainerId: "signer-iframe-container",
|
|
236
|
+
* },
|
|
237
|
+
* });
|
|
238
|
+
*
|
|
239
|
+
* const account = await client.lookupUserWithPasskey();
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* @param {User} [user] An optional user object to authenticate
|
|
243
|
+
* @returns {Promise<User>} A promise that resolves to the authenticated user object
|
|
244
|
+
*/
|
|
129
245
|
lookupUserWithPasskey: (user?: User | undefined) => Promise<User>;
|
|
246
|
+
/**
|
|
247
|
+
* Initiates the export of a wallet by creating an iframe stamper and calling the appropriate export function.
|
|
248
|
+
* The export can be based on a seed phrase or a private key.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* import { AlchemySignerWebClient } from "@account-kit/signer";
|
|
253
|
+
*
|
|
254
|
+
* const client = new AlchemySignerWebClient({
|
|
255
|
+
* connection: {
|
|
256
|
+
* apiKey: "your-api-key",
|
|
257
|
+
* },
|
|
258
|
+
* iframeConfig: {
|
|
259
|
+
* iframeContainerId: "signer-iframe-container",
|
|
260
|
+
* },
|
|
261
|
+
* });
|
|
262
|
+
*
|
|
263
|
+
* const account = await client.exportWallet({
|
|
264
|
+
* iframeContainerId: "export-iframe-container",
|
|
265
|
+
* });
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @param {ExportWalletParams} config The parameters for exporting the wallet
|
|
269
|
+
* @param {string} config.iframeContainerId The ID of the container element that will hold the iframe stamper
|
|
270
|
+
* @param {string} [config.iframeElementId] Optional ID for the iframe element
|
|
271
|
+
* @returns {Promise<void>} A promise that resolves when the export process is complete
|
|
272
|
+
*/
|
|
130
273
|
exportWallet: ({ iframeContainerId, iframeElementId, }: ExportWalletParams) => Promise<boolean>;
|
|
274
|
+
/**
|
|
275
|
+
* Asynchronous function that clears the user and resets the iframe stamper.
|
|
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.disconnect();
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
131
293
|
disconnect: () => Promise<void>;
|
|
132
294
|
private initIframeStamper;
|
|
133
295
|
private initWebauthnStamper;
|