@account-kit/signer 4.0.0-alpha.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.
- package/LICENSE +21 -0
- package/dist/cjs/base.d.ts +37 -0
- package/dist/cjs/base.js +292 -0
- package/dist/cjs/base.js.map +1 -0
- package/dist/cjs/client/base.d.ts +230 -0
- package/dist/cjs/client/base.js +298 -0
- package/dist/cjs/client/base.js.map +1 -0
- package/dist/cjs/client/index.d.ts +146 -0
- package/dist/cjs/client/index.js +260 -0
- package/dist/cjs/client/index.js.map +1 -0
- package/dist/cjs/client/types.d.ts +106 -0
- package/dist/cjs/client/types.js +3 -0
- package/dist/cjs/client/types.js.map +1 -0
- package/dist/cjs/errors.d.ts +4 -0
- package/dist/cjs/errors.js +16 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/session/manager.d.ts +45 -0
- package/dist/cjs/session/manager.js +230 -0
- package/dist/cjs/session/manager.js.map +1 -0
- package/dist/cjs/session/types.d.ts +16 -0
- package/dist/cjs/session/types.js +3 -0
- package/dist/cjs/session/types.js.map +1 -0
- package/dist/cjs/signer.d.ts +262 -0
- package/dist/cjs/signer.js +34 -0
- package/dist/cjs/signer.js.map +1 -0
- package/dist/cjs/types.d.ts +14 -0
- package/dist/cjs/types.js +12 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/base64UrlEncode.d.ts +1 -0
- package/dist/cjs/utils/base64UrlEncode.js +12 -0
- package/dist/cjs/utils/base64UrlEncode.js.map +1 -0
- package/dist/cjs/utils/generateRandomBuffer.d.ts +1 -0
- package/dist/cjs/utils/generateRandomBuffer.js +10 -0
- package/dist/cjs/utils/generateRandomBuffer.js.map +1 -0
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/base.d.ts +37 -0
- package/dist/esm/base.js +288 -0
- package/dist/esm/base.js.map +1 -0
- package/dist/esm/client/base.d.ts +230 -0
- package/dist/esm/client/base.js +291 -0
- package/dist/esm/client/base.js.map +1 -0
- package/dist/esm/client/index.d.ts +146 -0
- package/dist/esm/client/index.js +256 -0
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/client/types.d.ts +106 -0
- package/dist/esm/client/types.js +2 -0
- package/dist/esm/client/types.js.map +1 -0
- package/dist/esm/errors.d.ts +4 -0
- package/dist/esm/errors.js +12 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/session/manager.d.ts +45 -0
- package/dist/esm/session/manager.js +223 -0
- package/dist/esm/session/manager.js.map +1 -0
- package/dist/esm/session/types.d.ts +16 -0
- package/dist/esm/session/types.js +2 -0
- package/dist/esm/session/types.js.map +1 -0
- package/dist/esm/signer.d.ts +262 -0
- package/dist/esm/signer.js +30 -0
- package/dist/esm/signer.js.map +1 -0
- package/dist/esm/types.d.ts +14 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/base64UrlEncode.d.ts +1 -0
- package/dist/esm/utils/base64UrlEncode.js +8 -0
- package/dist/esm/utils/base64UrlEncode.js.map +1 -0
- package/dist/esm/utils/generateRandomBuffer.d.ts +1 -0
- package/dist/esm/utils/generateRandomBuffer.js +6 -0
- package/dist/esm/utils/generateRandomBuffer.js.map +1 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/base.d.ts +89 -0
- package/dist/types/base.d.ts.map +1 -0
- package/dist/types/client/base.d.ts +246 -0
- package/dist/types/client/base.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +151 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/types.d.ts +107 -0
- package/dist/types/client/types.d.ts.map +1 -0
- package/dist/types/errors.d.ts +5 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/session/manager.d.ts +46 -0
- package/dist/types/session/manager.d.ts.map +1 -0
- package/dist/types/session/types.d.ts +17 -0
- package/dist/types/session/types.d.ts.map +1 -0
- package/dist/types/signer.d.ts +269 -0
- package/dist/types/signer.d.ts.map +1 -0
- package/dist/types/types.d.ts +15 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/base64UrlEncode.d.ts +2 -0
- package/dist/types/utils/base64UrlEncode.d.ts.map +1 -0
- package/dist/types/utils/generateRandomBuffer.d.ts +2 -0
- package/dist/types/utils/generateRandomBuffer.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/package.json +79 -0
- package/src/base.ts +386 -0
- package/src/client/base.ts +399 -0
- package/src/client/index.ts +267 -0
- package/src/client/types.ts +121 -0
- package/src/errors.ts +15 -0
- package/src/index.ts +10 -0
- package/src/session/manager.ts +249 -0
- package/src/session/types.ts +16 -0
- package/src/signer.ts +55 -0
- package/src/types.ts +17 -0
- package/src/utils/base64UrlEncode.ts +7 -0
- package/src/utils/generateRandomBuffer.ts +5 -0
- package/src/version.ts +3 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { ConnectionConfigSchema } from "@aa-sdk/core";
|
|
2
|
+
import { getWebAuthnAttestation } from "@turnkey/http";
|
|
3
|
+
import { IframeStamper } from "@turnkey/iframe-stamper";
|
|
4
|
+
import { WebauthnStamper } from "@turnkey/webauthn-stamper";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { base64UrlEncode } from "../utils/base64UrlEncode.js";
|
|
7
|
+
import { generateRandomBuffer } from "../utils/generateRandomBuffer.js";
|
|
8
|
+
import { BaseSignerClient } from "./base.js";
|
|
9
|
+
export const AlchemySignerClientParamsSchema = z.object({
|
|
10
|
+
connection: ConnectionConfigSchema,
|
|
11
|
+
iframeConfig: z.object({
|
|
12
|
+
iframeElementId: z.string().default("turnkey-iframe"),
|
|
13
|
+
iframeContainerId: z.string(),
|
|
14
|
+
}),
|
|
15
|
+
rpId: z.string().optional(),
|
|
16
|
+
rootOrgId: z
|
|
17
|
+
.string()
|
|
18
|
+
.optional()
|
|
19
|
+
.default("24c1acf5-810f-41e0-a503-d5d13fa8e830"),
|
|
20
|
+
});
|
|
21
|
+
export class AlchemySignerWebClient extends BaseSignerClient {
|
|
22
|
+
constructor(params) {
|
|
23
|
+
const { connection, iframeConfig, rpId, rootOrgId } = AlchemySignerClientParamsSchema.parse(params);
|
|
24
|
+
const iframeStamper = new IframeStamper({
|
|
25
|
+
iframeElementId: iframeConfig.iframeElementId,
|
|
26
|
+
iframeUrl: "https://auth.turnkey.com",
|
|
27
|
+
iframeContainer: document.getElementById(iframeConfig.iframeContainerId),
|
|
28
|
+
});
|
|
29
|
+
super({
|
|
30
|
+
connection,
|
|
31
|
+
rootOrgId,
|
|
32
|
+
stamper: iframeStamper,
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "iframeStamper", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "webauthnStamper", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "iframeContainerId", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(this, "createAccount", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: async (params) => {
|
|
57
|
+
this.eventEmitter.emit("authenticating");
|
|
58
|
+
if (params.type === "email") {
|
|
59
|
+
const { email, expirationSeconds } = params;
|
|
60
|
+
const publicKey = await this.initIframeStamper();
|
|
61
|
+
const response = await this.request("/v1/signup", {
|
|
62
|
+
email,
|
|
63
|
+
targetPublicKey: publicKey,
|
|
64
|
+
expirationSeconds,
|
|
65
|
+
redirectParams: params.redirectParams?.toString(),
|
|
66
|
+
});
|
|
67
|
+
return response;
|
|
68
|
+
}
|
|
69
|
+
const { attestation, challenge } = await this.getWebAuthnAttestation(params.creationOpts, { username: params.username });
|
|
70
|
+
const result = await this.request("/v1/signup", {
|
|
71
|
+
passkey: {
|
|
72
|
+
challenge: base64UrlEncode(challenge),
|
|
73
|
+
attestation,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
this.user = {
|
|
77
|
+
orgId: result.orgId,
|
|
78
|
+
address: result.address,
|
|
79
|
+
userId: result.userId,
|
|
80
|
+
credentialId: attestation.credentialId,
|
|
81
|
+
};
|
|
82
|
+
this.initWebauthnStamper(this.user);
|
|
83
|
+
this.eventEmitter.emit("connectedPasskey", this.user);
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(this, "initEmailAuth", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: async (params) => {
|
|
92
|
+
this.eventEmitter.emit("authenticating");
|
|
93
|
+
const { email, expirationSeconds } = params;
|
|
94
|
+
const publicKey = await this.initIframeStamper();
|
|
95
|
+
return this.request("/v1/auth", {
|
|
96
|
+
email,
|
|
97
|
+
targetPublicKey: publicKey,
|
|
98
|
+
expirationSeconds,
|
|
99
|
+
redirectParams: params.redirectParams?.toString(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(this, "completeEmailAuth", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
configurable: true,
|
|
106
|
+
writable: true,
|
|
107
|
+
value: async ({ bundle, orgId, }) => {
|
|
108
|
+
this.eventEmitter.emit("authenticating");
|
|
109
|
+
await this.initIframeStamper();
|
|
110
|
+
const result = await this.iframeStamper.injectCredentialBundle(bundle);
|
|
111
|
+
if (!result) {
|
|
112
|
+
throw new Error("Failed to inject credential bundle");
|
|
113
|
+
}
|
|
114
|
+
const user = await this.whoami(orgId);
|
|
115
|
+
this.eventEmitter.emit("connectedEmail", user, bundle);
|
|
116
|
+
return user;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(this, "lookupUserWithPasskey", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
writable: true,
|
|
123
|
+
value: async (user = undefined) => {
|
|
124
|
+
this.eventEmitter.emit("authenticating");
|
|
125
|
+
await this.initWebauthnStamper(user);
|
|
126
|
+
if (user) {
|
|
127
|
+
this.user = user;
|
|
128
|
+
return user;
|
|
129
|
+
}
|
|
130
|
+
const result = await this.whoami(this.rootOrg);
|
|
131
|
+
await this.initWebauthnStamper(result);
|
|
132
|
+
this.eventEmitter.emit("connectedPasskey", result);
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
Object.defineProperty(this, "exportWallet", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
configurable: true,
|
|
139
|
+
writable: true,
|
|
140
|
+
value: async ({ iframeContainerId, iframeElementId = "turnkey-export-iframe", }) => {
|
|
141
|
+
const exportWalletIframeStamper = new IframeStamper({
|
|
142
|
+
iframeContainer: document.getElementById(iframeContainerId),
|
|
143
|
+
iframeElementId: iframeElementId,
|
|
144
|
+
iframeUrl: "https://export.turnkey.com",
|
|
145
|
+
});
|
|
146
|
+
await exportWalletIframeStamper.init();
|
|
147
|
+
if (this.turnkeyClient.stamper === this.iframeStamper) {
|
|
148
|
+
return this.exportWalletInner({
|
|
149
|
+
exportStamper: exportWalletIframeStamper,
|
|
150
|
+
exportAs: "SEED_PHRASE",
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return this.exportWalletInner({
|
|
154
|
+
exportStamper: exportWalletIframeStamper,
|
|
155
|
+
exportAs: "PRIVATE_KEY",
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(this, "disconnect", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
configurable: true,
|
|
162
|
+
writable: true,
|
|
163
|
+
value: async () => {
|
|
164
|
+
this.user = undefined;
|
|
165
|
+
this.iframeStamper.clear();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(this, "initIframeStamper", {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
configurable: true,
|
|
171
|
+
writable: true,
|
|
172
|
+
value: async () => {
|
|
173
|
+
if (!this.iframeStamper.publicKey()) {
|
|
174
|
+
await this.iframeStamper.init();
|
|
175
|
+
}
|
|
176
|
+
this.setStamper(this.iframeStamper);
|
|
177
|
+
return this.iframeStamper.publicKey();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
Object.defineProperty(this, "initWebauthnStamper", {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
configurable: true,
|
|
183
|
+
writable: true,
|
|
184
|
+
value: async (user = this.user) => {
|
|
185
|
+
this.setStamper(this.webauthnStamper);
|
|
186
|
+
if (user && user.credentialId) {
|
|
187
|
+
this.webauthnStamper.allowCredentials = [
|
|
188
|
+
{
|
|
189
|
+
id: Buffer.from(user.credentialId, "base64"),
|
|
190
|
+
type: "public-key",
|
|
191
|
+
transports: ["internal", "hybrid"],
|
|
192
|
+
},
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(this, "getWebAuthnAttestation", {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
configurable: true,
|
|
200
|
+
writable: true,
|
|
201
|
+
value: async (options, userDetails = {
|
|
202
|
+
username: this.user?.email ?? "anonymous",
|
|
203
|
+
}) => {
|
|
204
|
+
const challenge = generateRandomBuffer();
|
|
205
|
+
const authenticatorUserId = generateRandomBuffer();
|
|
206
|
+
const attestation = await getWebAuthnAttestation({
|
|
207
|
+
publicKey: {
|
|
208
|
+
...options?.publicKey,
|
|
209
|
+
authenticatorSelection: {
|
|
210
|
+
residentKey: "preferred",
|
|
211
|
+
requireResidentKey: false,
|
|
212
|
+
userVerification: "preferred",
|
|
213
|
+
...options?.publicKey?.authenticatorSelection,
|
|
214
|
+
},
|
|
215
|
+
challenge,
|
|
216
|
+
rp: {
|
|
217
|
+
id: window.location.hostname,
|
|
218
|
+
name: window.location.hostname,
|
|
219
|
+
...options?.publicKey?.rp,
|
|
220
|
+
},
|
|
221
|
+
pubKeyCredParams: [
|
|
222
|
+
{
|
|
223
|
+
type: "public-key",
|
|
224
|
+
alg: -7,
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
type: "public-key",
|
|
228
|
+
alg: -257,
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
user: {
|
|
232
|
+
id: authenticatorUserId,
|
|
233
|
+
name: userDetails.username,
|
|
234
|
+
displayName: userDetails.username,
|
|
235
|
+
...options?.publicKey?.user,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
signal: options?.signal,
|
|
239
|
+
});
|
|
240
|
+
if (attestation.transports == null || attestation.transports.length === 0) {
|
|
241
|
+
attestation.transports = [
|
|
242
|
+
"AUTHENTICATOR_TRANSPORT_INTERNAL",
|
|
243
|
+
"AUTHENTICATOR_TRANSPORT_HYBRID",
|
|
244
|
+
];
|
|
245
|
+
}
|
|
246
|
+
return { challenge, authenticatorUserId, attestation };
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
this.iframeStamper = iframeStamper;
|
|
250
|
+
this.iframeContainerId = iframeConfig.iframeContainerId;
|
|
251
|
+
this.webauthnStamper = new WebauthnStamper({
|
|
252
|
+
rpId: rpId ?? window.location.hostname,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAS7C,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC,MAAM,CAAC;IACtD,UAAU,EAAE,sBAAsB;IAClC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC;QACrB,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACrD,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE;KAC9B,CAAC;IACF,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,SAAS,EAAE,CAAC;SACT,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,OAAO,CAAC,sCAAsC,CAAC;CACnD,CAAC,CAAC;AAUH,MAAM,OAAO,sBAAuB,SAAQ,gBAAoC;IAK9E,YAAY,MAAiC;QAC3C,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,GACjD,+BAA+B,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAEhD,MAAM,aAAa,GAAG,I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AI,eAAe,CAAC;YACzC,IAAI,EAAE,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ;SACvC,CAAC,CAAC;IACL,CAAC;CA0MF","sourcesContent":["import { ConnectionConfigSchema } from \"@aa-sdk/core\";\nimport { getWebAuthnAttestation } from \"@turnkey/http\";\nimport { IframeStamper } from \"@turnkey/iframe-stamper\";\nimport { WebauthnStamper } from \"@turnkey/webauthn-stamper\";\nimport { z } from \"zod\";\nimport { base64UrlEncode } from \"../utils/base64UrlEncode.js\";\nimport { generateRandomBuffer } from \"../utils/generateRandomBuffer.js\";\nimport { BaseSignerClient } from \"./base.js\";\nimport type {\n CreateAccountParams,\n CredentialCreationOptionOverrides,\n EmailAuthParams,\n ExportWalletParams,\n User,\n} from \"./types.js\";\n\nexport const AlchemySignerClientParamsSchema = z.object({\n connection: ConnectionConfigSchema,\n iframeConfig: z.object({\n iframeElementId: z.string().default(\"turnkey-iframe\"),\n iframeContainerId: z.string(),\n }),\n rpId: z.string().optional(),\n rootOrgId: z\n .string()\n .optional()\n .default(\"24c1acf5-810f-41e0-a503-d5d13fa8e830\"),\n});\n\nexport type AlchemySignerClientParams = z.input<\n typeof AlchemySignerClientParamsSchema\n>;\n\n/**\n * A lower level client used by the AlchemySigner used to communicate with\n * Alchemy's signer service.\n */\nexport class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams> {\n private iframeStamper: IframeStamper;\n private webauthnStamper: WebauthnStamper;\n iframeContainerId: string;\n\n constructor(params: AlchemySignerClientParams) {\n const { connection, iframeConfig, rpId, rootOrgId } =\n AlchemySignerClientParamsSchema.parse(params);\n\n const iframeStamper = new IframeStamper({\n iframeElementId: iframeConfig.iframeElementId,\n iframeUrl: \"https://auth.turnkey.com\",\n iframeContainer: document.getElementById(iframeConfig.iframeContainerId),\n });\n\n super({\n connection,\n rootOrgId,\n stamper: iframeStamper,\n });\n\n this.iframeStamper = iframeStamper;\n this.iframeContainerId = iframeConfig.iframeContainerId;\n\n this.webauthnStamper = new WebauthnStamper({\n rpId: rpId ?? window.location.hostname,\n });\n }\n\n public createAccount = async (params: CreateAccountParams) => {\n this.eventEmitter.emit(\"authenticating\");\n if (params.type === \"email\") {\n const { email, expirationSeconds } = params;\n const publicKey = await this.initIframeStamper();\n\n const response = await this.request(\"/v1/signup\", {\n email,\n targetPublicKey: publicKey,\n expirationSeconds,\n redirectParams: params.redirectParams?.toString(),\n });\n\n return response;\n }\n\n // Passkey account creation flow\n const { attestation, challenge } = await this.getWebAuthnAttestation(\n params.creationOpts,\n { username: params.username }\n );\n\n const result = await this.request(\"/v1/signup\", {\n passkey: {\n challenge: base64UrlEncode(challenge),\n attestation,\n },\n });\n\n this.user = {\n orgId: result.orgId,\n address: result.address!,\n userId: result.userId!,\n credentialId: attestation.credentialId,\n };\n this.initWebauthnStamper(this.user);\n this.eventEmitter.emit(\"connectedPasskey\", this.user);\n\n return result;\n };\n\n public initEmailAuth = async (\n params: Omit<EmailAuthParams, \"targetPublicKey\">\n ) => {\n this.eventEmitter.emit(\"authenticating\");\n const { email, expirationSeconds } = params;\n const publicKey = await this.initIframeStamper();\n\n return this.request(\"/v1/auth\", {\n email,\n targetPublicKey: publicKey,\n expirationSeconds,\n redirectParams: params.redirectParams?.toString(),\n });\n };\n\n public completeEmailAuth = async ({\n bundle,\n orgId,\n }: {\n bundle: string;\n orgId: string;\n }) => {\n this.eventEmitter.emit(\"authenticating\");\n await this.initIframeStamper();\n\n const result = await this.iframeStamper.injectCredentialBundle(bundle);\n\n if (!result) {\n throw new Error(\"Failed to inject credential bundle\");\n }\n\n const user = await this.whoami(orgId);\n this.eventEmitter.emit(\"connectedEmail\", user, bundle);\n\n return user;\n };\n\n public lookupUserWithPasskey = async (user: User | undefined = undefined) => {\n this.eventEmitter.emit(\"authenticating\");\n await this.initWebauthnStamper(user);\n if (user) {\n this.user = user;\n return user;\n }\n\n const result = await this.whoami(this.rootOrg);\n await this.initWebauthnStamper(result);\n this.eventEmitter.emit(\"connectedPasskey\", result);\n\n return result;\n };\n\n public exportWallet = async ({\n iframeContainerId,\n iframeElementId = \"turnkey-export-iframe\",\n }: ExportWalletParams) => {\n const exportWalletIframeStamper = new IframeStamper({\n iframeContainer: document.getElementById(iframeContainerId),\n iframeElementId: iframeElementId,\n iframeUrl: \"https://export.turnkey.com\",\n });\n await exportWalletIframeStamper.init();\n\n if (this.turnkeyClient.stamper === this.iframeStamper) {\n return this.exportWalletInner({\n exportStamper: exportWalletIframeStamper,\n exportAs: \"SEED_PHRASE\",\n });\n }\n\n return this.exportWalletInner({\n exportStamper: exportWalletIframeStamper,\n exportAs: \"PRIVATE_KEY\",\n });\n };\n\n public disconnect = async () => {\n this.user = undefined;\n this.iframeStamper.clear();\n };\n\n private initIframeStamper = async () => {\n if (!this.iframeStamper.publicKey()) {\n await this.iframeStamper.init();\n }\n\n this.setStamper(this.iframeStamper);\n\n return this.iframeStamper.publicKey()!;\n };\n\n private initWebauthnStamper = async (user: User | undefined = this.user) => {\n this.setStamper(this.webauthnStamper);\n if (user && user.credentialId) {\n // The goal here is to allow us to cache the allowed credential, but this doesn't work with hybrid transport :(\n this.webauthnStamper.allowCredentials = [\n {\n id: Buffer.from(user.credentialId, \"base64\"),\n type: \"public-key\",\n transports: [\"internal\", \"hybrid\"],\n },\n ];\n }\n };\n\n protected getWebAuthnAttestation = async (\n options?: CredentialCreationOptionOverrides,\n userDetails: { username: string } = {\n username: this.user?.email ?? \"anonymous\",\n }\n ) => {\n const challenge = generateRandomBuffer();\n const authenticatorUserId = generateRandomBuffer();\n\n const attestation = await getWebAuthnAttestation({\n publicKey: {\n ...options?.publicKey,\n authenticatorSelection: {\n residentKey: \"preferred\",\n requireResidentKey: false,\n userVerification: \"preferred\",\n ...options?.publicKey?.authenticatorSelection,\n },\n challenge,\n rp: {\n id: window.location.hostname,\n name: window.location.hostname,\n ...options?.publicKey?.rp,\n },\n pubKeyCredParams: [\n {\n type: \"public-key\",\n alg: -7,\n },\n {\n type: \"public-key\",\n alg: -257,\n },\n ],\n user: {\n id: authenticatorUserId,\n name: userDetails.username,\n displayName: userDetails.username,\n ...options?.publicKey?.user,\n },\n },\n signal: options?.signal,\n });\n\n // on iOS sometimes this is returned as empty or null, so handling that here\n if (attestation.transports == null || attestation.transports.length === 0) {\n attestation.transports = [\n \"AUTHENTICATOR_TRANSPORT_INTERNAL\",\n \"AUTHENTICATOR_TRANSPORT_HYBRID\",\n ];\n }\n\n return { challenge, authenticatorUserId, attestation };\n };\n}\n"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Address } from "@aa-sdk/core";
|
|
2
|
+
import type { TSignedRequest, getWebAuthnAttestation } from "@turnkey/http";
|
|
3
|
+
import type { Hex } from "viem";
|
|
4
|
+
export type CredentialCreationOptionOverrides = {
|
|
5
|
+
publicKey?: Partial<CredentialCreationOptions["publicKey"]>;
|
|
6
|
+
} & Pick<CredentialCreationOptions, "signal">;
|
|
7
|
+
export type User = {
|
|
8
|
+
email?: string;
|
|
9
|
+
orgId: string;
|
|
10
|
+
userId: string;
|
|
11
|
+
address: Address;
|
|
12
|
+
credentialId?: string;
|
|
13
|
+
};
|
|
14
|
+
export type ExportWalletParams = {
|
|
15
|
+
iframeContainerId: string;
|
|
16
|
+
iframeElementId?: string;
|
|
17
|
+
};
|
|
18
|
+
export type CreateAccountParams = {
|
|
19
|
+
type: "email";
|
|
20
|
+
email: string;
|
|
21
|
+
expirationSeconds?: number;
|
|
22
|
+
redirectParams?: URLSearchParams;
|
|
23
|
+
} | {
|
|
24
|
+
type: "passkey";
|
|
25
|
+
username: string;
|
|
26
|
+
creationOpts?: CredentialCreationOptionOverrides;
|
|
27
|
+
};
|
|
28
|
+
export type EmailAuthParams = {
|
|
29
|
+
email: string;
|
|
30
|
+
expirationSeconds?: number;
|
|
31
|
+
targetPublicKey: string;
|
|
32
|
+
redirectParams?: URLSearchParams;
|
|
33
|
+
};
|
|
34
|
+
export type SignupResponse = {
|
|
35
|
+
orgId: string;
|
|
36
|
+
userId?: string;
|
|
37
|
+
address?: Address;
|
|
38
|
+
};
|
|
39
|
+
export type SignerRoutes = SignerEndpoints[number]["Route"];
|
|
40
|
+
export type SignerBody<T extends SignerRoutes> = Extract<SignerEndpoints[number], {
|
|
41
|
+
Route: T;
|
|
42
|
+
}>["Body"];
|
|
43
|
+
export type SignerResponse<T extends SignerRoutes> = Extract<SignerEndpoints[number], {
|
|
44
|
+
Route: T;
|
|
45
|
+
}>["Response"];
|
|
46
|
+
export type SignerEndpoints = [
|
|
47
|
+
{
|
|
48
|
+
Route: "/v1/signup";
|
|
49
|
+
Body: (Omit<EmailAuthParams, "redirectParams"> & {
|
|
50
|
+
redirectParams?: string;
|
|
51
|
+
}) | {
|
|
52
|
+
passkey: {
|
|
53
|
+
challenge: string;
|
|
54
|
+
attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
Response: SignupResponse;
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
Route: "/v1/whoami";
|
|
61
|
+
Body: {
|
|
62
|
+
stampedRequest: TSignedRequest;
|
|
63
|
+
};
|
|
64
|
+
Response: User;
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
Route: "/v1/auth";
|
|
68
|
+
Body: Omit<EmailAuthParams, "redirectParams"> & {
|
|
69
|
+
redirectParams?: string;
|
|
70
|
+
};
|
|
71
|
+
Response: {
|
|
72
|
+
orgId: string;
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
Route: "/v1/lookup";
|
|
77
|
+
Body: {
|
|
78
|
+
email: string;
|
|
79
|
+
};
|
|
80
|
+
Response: {
|
|
81
|
+
orgId: string | null;
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
Route: "/v1/sign-payload";
|
|
86
|
+
Body: {
|
|
87
|
+
stampedRequest: TSignedRequest;
|
|
88
|
+
};
|
|
89
|
+
Response: {
|
|
90
|
+
signature: Hex;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
];
|
|
94
|
+
export type AlchemySignerClientEvents = {
|
|
95
|
+
connected(user: User): void;
|
|
96
|
+
authenticating(): void;
|
|
97
|
+
connectedEmail(user: User, bundle: string): void;
|
|
98
|
+
connectedPasskey(user: User): void;
|
|
99
|
+
disconnected(): void;
|
|
100
|
+
};
|
|
101
|
+
export type AlchemySignerClientEvent = keyof AlchemySignerClientEvents;
|
|
102
|
+
export type GetWebAuthnAttestationResult = {
|
|
103
|
+
attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;
|
|
104
|
+
challenge: ArrayBuffer;
|
|
105
|
+
authenticatorUserId: ArrayBuffer;
|
|
106
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/client/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Address } from \"@aa-sdk/core\";\nimport type { TSignedRequest, getWebAuthnAttestation } from \"@turnkey/http\";\nimport type { Hex } from \"viem\";\n\nexport type CredentialCreationOptionOverrides = {\n publicKey?: Partial<CredentialCreationOptions[\"publicKey\"]>;\n} & Pick<CredentialCreationOptions, \"signal\">;\n\n// [!region User]\nexport type User = {\n email?: string;\n orgId: string;\n userId: string;\n address: Address;\n credentialId?: string;\n};\n// [!endregion User]\n\nexport type ExportWalletParams = {\n iframeContainerId: string;\n iframeElementId?: string;\n};\n\nexport type CreateAccountParams =\n | {\n type: \"email\";\n email: string;\n expirationSeconds?: number;\n redirectParams?: URLSearchParams;\n }\n | {\n type: \"passkey\";\n username: string;\n creationOpts?: CredentialCreationOptionOverrides;\n };\n\nexport type EmailAuthParams = {\n email: string;\n expirationSeconds?: number;\n targetPublicKey: string;\n redirectParams?: URLSearchParams;\n};\n\nexport type SignupResponse = {\n orgId: string;\n userId?: string;\n address?: Address;\n};\n\nexport type SignerRoutes = SignerEndpoints[number][\"Route\"];\nexport type SignerBody<T extends SignerRoutes> = Extract<\n SignerEndpoints[number],\n { Route: T }\n>[\"Body\"];\nexport type SignerResponse<T extends SignerRoutes> = Extract<\n SignerEndpoints[number],\n { Route: T }\n>[\"Response\"];\n\nexport type SignerEndpoints = [\n {\n Route: \"/v1/signup\";\n Body:\n | (Omit<EmailAuthParams, \"redirectParams\"> & { redirectParams?: string })\n | {\n passkey: {\n challenge: string;\n attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;\n };\n };\n Response: SignupResponse;\n },\n {\n Route: \"/v1/whoami\";\n Body: {\n stampedRequest: TSignedRequest;\n };\n Response: User;\n },\n {\n Route: \"/v1/auth\";\n Body: Omit<EmailAuthParams, \"redirectParams\"> & { redirectParams?: string };\n Response: {\n orgId: string;\n };\n },\n {\n Route: \"/v1/lookup\";\n Body: {\n email: string;\n };\n Response: {\n orgId: string | null;\n };\n },\n {\n Route: \"/v1/sign-payload\";\n Body: {\n stampedRequest: TSignedRequest;\n };\n Response: {\n signature: Hex;\n };\n }\n];\n\nexport type AlchemySignerClientEvents = {\n connected(user: User): void;\n authenticating(): void;\n connectedEmail(user: User, bundle: string): void;\n connectedPasskey(user: User): void;\n disconnected(): void;\n};\n\nexport type AlchemySignerClientEvent = keyof AlchemySignerClientEvents;\n\nexport type GetWebAuthnAttestationResult = {\n attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;\n challenge: ArrayBuffer;\n authenticatorUserId: ArrayBuffer;\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseError } from "@aa-sdk/core";
|
|
2
|
+
export class NotAuthenticatedError extends BaseError {
|
|
3
|
+
constructor() {
|
|
4
|
+
super([
|
|
5
|
+
"Signer not authenticated",
|
|
6
|
+
"Please authenticate to use this signer",
|
|
7
|
+
].join("\n"), {
|
|
8
|
+
docsPath: "/signers/alchemy-signer/introduction.html",
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAClD;QACE,KAAK,CACH;YACE,0BAA0B;YAC1B,wCAAwC;SACzC,CAAC,IAAI,CAAC,IAAI,CAAC,EACZ;YACE,QAAQ,EAAE,2CAA2C;SACtD,CACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { BaseError } from \"@aa-sdk/core\";\n\nexport class NotAuthenticatedError extends BaseError {\n constructor() {\n super(\n [\n \"Signer not authenticated\",\n \"Please authenticate to use this signer\",\n ].join(\"\\n\"),\n {\n docsPath: \"/signers/alchemy-signer/introduction.html\",\n }\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type * from "./signer.js";
|
|
2
|
+
export { AlchemyWebSigner } from "./signer.js";
|
|
3
|
+
export type * from "./types.js";
|
|
4
|
+
export { AlchemySignerStatus } from "./types.js";
|
|
5
|
+
export { BaseSignerClient } from "./client/base.js";
|
|
6
|
+
export { AlchemySignerWebClient } from "./client/index.js";
|
|
7
|
+
export type * from "./client/types.js";
|
|
8
|
+
export { DEFAULT_SESSION_MS } from "./session/manager.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { AlchemyWebSigner } from "./signer.js";
|
|
2
|
+
export { AlchemySignerStatus } from "./types.js";
|
|
3
|
+
export { BaseSignerClient } from "./client/base.js";
|
|
4
|
+
export { AlchemySignerWebClient } from "./client/index.js";
|
|
5
|
+
export { DEFAULT_SESSION_MS } from "./session/manager.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export type * from \"./signer.js\";\nexport { AlchemyWebSigner } from \"./signer.js\";\n\nexport type * from \"./types.js\";\nexport { AlchemySignerStatus } from \"./types.js\";\n\nexport { BaseSignerClient } from \"./client/base.js\";\nexport { AlchemySignerWebClient } from \"./client/index.js\";\nexport type * from \"./client/types.js\";\nexport { DEFAULT_SESSION_MS } from \"./session/manager.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import EventEmitter from "eventemitter3";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { BaseSignerClient } from "../client/base";
|
|
4
|
+
import type { User } from "../client/types";
|
|
5
|
+
import type { SessionManagerEvents } from "./types";
|
|
6
|
+
export declare const DEFAULT_SESSION_MS: number;
|
|
7
|
+
export declare const SessionManagerParamsSchema: z.ZodObject<{
|
|
8
|
+
sessionKey: z.ZodDefault<z.ZodString>;
|
|
9
|
+
storage: z.ZodUnion<[z.ZodDefault<z.ZodEnum<["localStorage", "sessionStorage"]>>, z.ZodType<Storage, z.ZodTypeDef, Storage>]>;
|
|
10
|
+
expirationTimeMs: z.ZodDefault<z.ZodNumber>;
|
|
11
|
+
client: z.ZodType<BaseSignerClient<unknown>, z.ZodTypeDef, BaseSignerClient<unknown>>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
sessionKey: string;
|
|
14
|
+
storage: ("localStorage" | "sessionStorage" | Storage) & ("localStorage" | "sessionStorage" | Storage | undefined);
|
|
15
|
+
expirationTimeMs: number;
|
|
16
|
+
client: BaseSignerClient<unknown>;
|
|
17
|
+
}, {
|
|
18
|
+
client: BaseSignerClient<unknown>;
|
|
19
|
+
sessionKey?: string | undefined;
|
|
20
|
+
storage?: "localStorage" | "sessionStorage" | Storage | undefined;
|
|
21
|
+
expirationTimeMs?: number | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
export type SessionManagerParams = z.input<typeof SessionManagerParamsSchema>;
|
|
24
|
+
export declare class SessionManager {
|
|
25
|
+
private sessionKey;
|
|
26
|
+
private client;
|
|
27
|
+
private eventEmitter;
|
|
28
|
+
readonly expirationTimeMs: number;
|
|
29
|
+
private store;
|
|
30
|
+
constructor(params: SessionManagerParams);
|
|
31
|
+
getSessionUser: () => Promise<User | null>;
|
|
32
|
+
clearSession: () => void;
|
|
33
|
+
setTemporarySession: (session: {
|
|
34
|
+
orgId: string;
|
|
35
|
+
}) => void;
|
|
36
|
+
getTemporarySession: () => {
|
|
37
|
+
orgId: string;
|
|
38
|
+
} | null;
|
|
39
|
+
on: <E extends keyof SessionManagerEvents>(event: E, listener: SessionManagerEvents[E]) => () => EventEmitter<SessionManagerEvents, any>;
|
|
40
|
+
private getSession;
|
|
41
|
+
private setSession;
|
|
42
|
+
initialize(): void;
|
|
43
|
+
private getInitialState;
|
|
44
|
+
private registerEventListeners;
|
|
45
|
+
}
|