@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,146 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { BaseSignerClient } from "./base.js";
|
|
3
|
-
import type { CreateAccountParams, CredentialCreationOptionOverrides, EmailAuthParams, ExportWalletParams, User } from "./types.js";
|
|
4
|
-
export declare const AlchemySignerClientParamsSchema: z.ZodObject<{
|
|
5
|
-
connection: z.ZodUnion<[z.ZodObject<{
|
|
6
|
-
rpcUrl: z.ZodOptional<z.ZodNever>;
|
|
7
|
-
apiKey: z.ZodString;
|
|
8
|
-
jwt: z.ZodOptional<z.ZodNever>;
|
|
9
|
-
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
apiKey: string;
|
|
11
|
-
rpcUrl?: undefined;
|
|
12
|
-
jwt?: undefined;
|
|
13
|
-
}, {
|
|
14
|
-
apiKey: string;
|
|
15
|
-
rpcUrl?: undefined;
|
|
16
|
-
jwt?: undefined;
|
|
17
|
-
}>, z.ZodObject<{
|
|
18
|
-
rpcUrl: z.ZodOptional<z.ZodNever>;
|
|
19
|
-
apiKey: z.ZodOptional<z.ZodNever>;
|
|
20
|
-
jwt: z.ZodString;
|
|
21
|
-
}, "strip", z.ZodTypeAny, {
|
|
22
|
-
jwt: string;
|
|
23
|
-
rpcUrl?: undefined;
|
|
24
|
-
apiKey?: undefined;
|
|
25
|
-
}, {
|
|
26
|
-
jwt: string;
|
|
27
|
-
rpcUrl?: undefined;
|
|
28
|
-
apiKey?: undefined;
|
|
29
|
-
}>, z.ZodObject<{
|
|
30
|
-
rpcUrl: z.ZodString;
|
|
31
|
-
apiKey: z.ZodOptional<z.ZodNever>;
|
|
32
|
-
jwt: z.ZodOptional<z.ZodNever>;
|
|
33
|
-
}, "strip", z.ZodTypeAny, {
|
|
34
|
-
rpcUrl: string;
|
|
35
|
-
apiKey?: undefined;
|
|
36
|
-
jwt?: undefined;
|
|
37
|
-
}, {
|
|
38
|
-
rpcUrl: string;
|
|
39
|
-
apiKey?: undefined;
|
|
40
|
-
jwt?: undefined;
|
|
41
|
-
}>, z.ZodObject<{
|
|
42
|
-
rpcUrl: z.ZodString;
|
|
43
|
-
apiKey: z.ZodOptional<z.ZodNever>;
|
|
44
|
-
jwt: z.ZodString;
|
|
45
|
-
}, "strip", z.ZodTypeAny, {
|
|
46
|
-
rpcUrl: string;
|
|
47
|
-
jwt: string;
|
|
48
|
-
apiKey?: undefined;
|
|
49
|
-
}, {
|
|
50
|
-
rpcUrl: string;
|
|
51
|
-
jwt: string;
|
|
52
|
-
apiKey?: undefined;
|
|
53
|
-
}>]>;
|
|
54
|
-
iframeConfig: z.ZodObject<{
|
|
55
|
-
iframeElementId: z.ZodDefault<z.ZodString>;
|
|
56
|
-
iframeContainerId: z.ZodString;
|
|
57
|
-
}, "strip", z.ZodTypeAny, {
|
|
58
|
-
iframeElementId: string;
|
|
59
|
-
iframeContainerId: string;
|
|
60
|
-
}, {
|
|
61
|
-
iframeContainerId: string;
|
|
62
|
-
iframeElementId?: string | undefined;
|
|
63
|
-
}>;
|
|
64
|
-
rpId: z.ZodOptional<z.ZodString>;
|
|
65
|
-
rootOrgId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
66
|
-
}, "strip", z.ZodTypeAny, {
|
|
67
|
-
connection: {
|
|
68
|
-
apiKey: string;
|
|
69
|
-
rpcUrl?: undefined;
|
|
70
|
-
jwt?: undefined;
|
|
71
|
-
} | {
|
|
72
|
-
jwt: string;
|
|
73
|
-
rpcUrl?: undefined;
|
|
74
|
-
apiKey?: undefined;
|
|
75
|
-
} | {
|
|
76
|
-
rpcUrl: string;
|
|
77
|
-
apiKey?: undefined;
|
|
78
|
-
jwt?: undefined;
|
|
79
|
-
} | {
|
|
80
|
-
rpcUrl: string;
|
|
81
|
-
jwt: string;
|
|
82
|
-
apiKey?: undefined;
|
|
83
|
-
};
|
|
84
|
-
rootOrgId: string;
|
|
85
|
-
iframeConfig: {
|
|
86
|
-
iframeElementId: string;
|
|
87
|
-
iframeContainerId: string;
|
|
88
|
-
};
|
|
89
|
-
rpId?: string | undefined;
|
|
90
|
-
}, {
|
|
91
|
-
connection: {
|
|
92
|
-
apiKey: string;
|
|
93
|
-
rpcUrl?: undefined;
|
|
94
|
-
jwt?: undefined;
|
|
95
|
-
} | {
|
|
96
|
-
jwt: string;
|
|
97
|
-
rpcUrl?: undefined;
|
|
98
|
-
apiKey?: undefined;
|
|
99
|
-
} | {
|
|
100
|
-
rpcUrl: string;
|
|
101
|
-
apiKey?: undefined;
|
|
102
|
-
jwt?: undefined;
|
|
103
|
-
} | {
|
|
104
|
-
rpcUrl: string;
|
|
105
|
-
jwt: string;
|
|
106
|
-
apiKey?: undefined;
|
|
107
|
-
};
|
|
108
|
-
iframeConfig: {
|
|
109
|
-
iframeContainerId: string;
|
|
110
|
-
iframeElementId?: string | undefined;
|
|
111
|
-
};
|
|
112
|
-
rpId?: string | undefined;
|
|
113
|
-
rootOrgId?: string | undefined;
|
|
114
|
-
}>;
|
|
115
|
-
export type AlchemySignerClientParams = z.input<typeof AlchemySignerClientParamsSchema>;
|
|
116
|
-
export declare class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams> {
|
|
117
|
-
private iframeStamper;
|
|
118
|
-
private webauthnStamper;
|
|
119
|
-
iframeContainerId: string;
|
|
120
|
-
constructor(params: AlchemySignerClientParams);
|
|
121
|
-
createAccount: (params: CreateAccountParams) => Promise<import("./types.js").SignupResponse>;
|
|
122
|
-
initEmailAuth: (params: Omit<EmailAuthParams, "targetPublicKey">) => Promise<{
|
|
123
|
-
orgId: string;
|
|
124
|
-
}>;
|
|
125
|
-
completeEmailAuth: ({ bundle, orgId, }: {
|
|
126
|
-
bundle: string;
|
|
127
|
-
orgId: string;
|
|
128
|
-
}) => Promise<User>;
|
|
129
|
-
lookupUserWithPasskey: (user?: User | undefined) => Promise<User>;
|
|
130
|
-
exportWallet: ({ iframeContainerId, iframeElementId, }: ExportWalletParams) => Promise<boolean>;
|
|
131
|
-
disconnect: () => Promise<void>;
|
|
132
|
-
private initIframeStamper;
|
|
133
|
-
private initWebauthnStamper;
|
|
134
|
-
protected getWebAuthnAttestation: (options?: CredentialCreationOptionOverrides, userDetails?: {
|
|
135
|
-
username: string;
|
|
136
|
-
}) => Promise<{
|
|
137
|
-
challenge: ArrayBuffer;
|
|
138
|
-
authenticatorUserId: ArrayBuffer;
|
|
139
|
-
attestation: {
|
|
140
|
-
credentialId: string;
|
|
141
|
-
clientDataJson: string;
|
|
142
|
-
attestationObject: string;
|
|
143
|
-
transports: ("AUTHENTICATOR_TRANSPORT_BLE" | "AUTHENTICATOR_TRANSPORT_INTERNAL" | "AUTHENTICATOR_TRANSPORT_NFC" | "AUTHENTICATOR_TRANSPORT_USB" | "AUTHENTICATOR_TRANSPORT_HYBRID")[];
|
|
144
|
-
};
|
|
145
|
-
}>;
|
|
146
|
-
}
|
package/dist/cjs/client/index.js
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AlchemySignerWebClient = exports.AlchemySignerClientParamsSchema = void 0;
|
|
4
|
-
const core_1 = require("@aa-sdk/core");
|
|
5
|
-
const http_1 = require("@turnkey/http");
|
|
6
|
-
const iframe_stamper_1 = require("@turnkey/iframe-stamper");
|
|
7
|
-
const webauthn_stamper_1 = require("@turnkey/webauthn-stamper");
|
|
8
|
-
const zod_1 = require("zod");
|
|
9
|
-
const base64UrlEncode_js_1 = require("../utils/base64UrlEncode.js");
|
|
10
|
-
const generateRandomBuffer_js_1 = require("../utils/generateRandomBuffer.js");
|
|
11
|
-
const base_js_1 = require("./base.js");
|
|
12
|
-
exports.AlchemySignerClientParamsSchema = zod_1.z.object({
|
|
13
|
-
connection: core_1.ConnectionConfigSchema,
|
|
14
|
-
iframeConfig: zod_1.z.object({
|
|
15
|
-
iframeElementId: zod_1.z.string().default("turnkey-iframe"),
|
|
16
|
-
iframeContainerId: zod_1.z.string(),
|
|
17
|
-
}),
|
|
18
|
-
rpId: zod_1.z.string().optional(),
|
|
19
|
-
rootOrgId: zod_1.z
|
|
20
|
-
.string()
|
|
21
|
-
.optional()
|
|
22
|
-
.default("24c1acf5-810f-41e0-a503-d5d13fa8e830"),
|
|
23
|
-
});
|
|
24
|
-
class AlchemySignerWebClient extends base_js_1.BaseSignerClient {
|
|
25
|
-
constructor(params) {
|
|
26
|
-
const { connection, iframeConfig, rpId, rootOrgId } = exports.AlchemySignerClientParamsSchema.parse(params);
|
|
27
|
-
const iframeStamper = new iframe_stamper_1.IframeStamper({
|
|
28
|
-
iframeElementId: iframeConfig.iframeElementId,
|
|
29
|
-
iframeUrl: "https://auth.turnkey.com",
|
|
30
|
-
iframeContainer: document.getElementById(iframeConfig.iframeContainerId),
|
|
31
|
-
});
|
|
32
|
-
super({
|
|
33
|
-
connection,
|
|
34
|
-
rootOrgId,
|
|
35
|
-
stamper: iframeStamper,
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(this, "iframeStamper", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
configurable: true,
|
|
40
|
-
writable: true,
|
|
41
|
-
value: void 0
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(this, "webauthnStamper", {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
configurable: true,
|
|
46
|
-
writable: true,
|
|
47
|
-
value: void 0
|
|
48
|
-
});
|
|
49
|
-
Object.defineProperty(this, "iframeContainerId", {
|
|
50
|
-
enumerable: true,
|
|
51
|
-
configurable: true,
|
|
52
|
-
writable: true,
|
|
53
|
-
value: void 0
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(this, "createAccount", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
writable: true,
|
|
59
|
-
value: async (params) => {
|
|
60
|
-
this.eventEmitter.emit("authenticating");
|
|
61
|
-
if (params.type === "email") {
|
|
62
|
-
const { email, expirationSeconds } = params;
|
|
63
|
-
const publicKey = await this.initIframeStamper();
|
|
64
|
-
const response = await this.request("/v1/signup", {
|
|
65
|
-
email,
|
|
66
|
-
targetPublicKey: publicKey,
|
|
67
|
-
expirationSeconds,
|
|
68
|
-
redirectParams: params.redirectParams?.toString(),
|
|
69
|
-
});
|
|
70
|
-
return response;
|
|
71
|
-
}
|
|
72
|
-
const { attestation, challenge } = await this.getWebAuthnAttestation(params.creationOpts, { username: params.username });
|
|
73
|
-
const result = await this.request("/v1/signup", {
|
|
74
|
-
passkey: {
|
|
75
|
-
challenge: (0, base64UrlEncode_js_1.base64UrlEncode)(challenge),
|
|
76
|
-
attestation,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
this.user = {
|
|
80
|
-
orgId: result.orgId,
|
|
81
|
-
address: result.address,
|
|
82
|
-
userId: result.userId,
|
|
83
|
-
credentialId: attestation.credentialId,
|
|
84
|
-
};
|
|
85
|
-
this.initWebauthnStamper(this.user);
|
|
86
|
-
this.eventEmitter.emit("connectedPasskey", this.user);
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(this, "initEmailAuth", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
configurable: true,
|
|
93
|
-
writable: true,
|
|
94
|
-
value: async (params) => {
|
|
95
|
-
this.eventEmitter.emit("authenticating");
|
|
96
|
-
const { email, expirationSeconds } = params;
|
|
97
|
-
const publicKey = await this.initIframeStamper();
|
|
98
|
-
return this.request("/v1/auth", {
|
|
99
|
-
email,
|
|
100
|
-
targetPublicKey: publicKey,
|
|
101
|
-
expirationSeconds,
|
|
102
|
-
redirectParams: params.redirectParams?.toString(),
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
Object.defineProperty(this, "completeEmailAuth", {
|
|
107
|
-
enumerable: true,
|
|
108
|
-
configurable: true,
|
|
109
|
-
writable: true,
|
|
110
|
-
value: async ({ bundle, orgId, }) => {
|
|
111
|
-
this.eventEmitter.emit("authenticating");
|
|
112
|
-
await this.initIframeStamper();
|
|
113
|
-
const result = await this.iframeStamper.injectCredentialBundle(bundle);
|
|
114
|
-
if (!result) {
|
|
115
|
-
throw new Error("Failed to inject credential bundle");
|
|
116
|
-
}
|
|
117
|
-
const user = await this.whoami(orgId);
|
|
118
|
-
this.eventEmitter.emit("connectedEmail", user, bundle);
|
|
119
|
-
return user;
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
Object.defineProperty(this, "lookupUserWithPasskey", {
|
|
123
|
-
enumerable: true,
|
|
124
|
-
configurable: true,
|
|
125
|
-
writable: true,
|
|
126
|
-
value: async (user = undefined) => {
|
|
127
|
-
this.eventEmitter.emit("authenticating");
|
|
128
|
-
await this.initWebauthnStamper(user);
|
|
129
|
-
if (user) {
|
|
130
|
-
this.user = user;
|
|
131
|
-
return user;
|
|
132
|
-
}
|
|
133
|
-
const result = await this.whoami(this.rootOrg);
|
|
134
|
-
await this.initWebauthnStamper(result);
|
|
135
|
-
this.eventEmitter.emit("connectedPasskey", result);
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
Object.defineProperty(this, "exportWallet", {
|
|
140
|
-
enumerable: true,
|
|
141
|
-
configurable: true,
|
|
142
|
-
writable: true,
|
|
143
|
-
value: async ({ iframeContainerId, iframeElementId = "turnkey-export-iframe", }) => {
|
|
144
|
-
const exportWalletIframeStamper = new iframe_stamper_1.IframeStamper({
|
|
145
|
-
iframeContainer: document.getElementById(iframeContainerId),
|
|
146
|
-
iframeElementId: iframeElementId,
|
|
147
|
-
iframeUrl: "https://export.turnkey.com",
|
|
148
|
-
});
|
|
149
|
-
await exportWalletIframeStamper.init();
|
|
150
|
-
if (this.turnkeyClient.stamper === this.iframeStamper) {
|
|
151
|
-
return this.exportWalletInner({
|
|
152
|
-
exportStamper: exportWalletIframeStamper,
|
|
153
|
-
exportAs: "SEED_PHRASE",
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
return this.exportWalletInner({
|
|
157
|
-
exportStamper: exportWalletIframeStamper,
|
|
158
|
-
exportAs: "PRIVATE_KEY",
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
Object.defineProperty(this, "disconnect", {
|
|
163
|
-
enumerable: true,
|
|
164
|
-
configurable: true,
|
|
165
|
-
writable: true,
|
|
166
|
-
value: async () => {
|
|
167
|
-
this.user = undefined;
|
|
168
|
-
this.iframeStamper.clear();
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
Object.defineProperty(this, "initIframeStamper", {
|
|
172
|
-
enumerable: true,
|
|
173
|
-
configurable: true,
|
|
174
|
-
writable: true,
|
|
175
|
-
value: async () => {
|
|
176
|
-
if (!this.iframeStamper.publicKey()) {
|
|
177
|
-
await this.iframeStamper.init();
|
|
178
|
-
}
|
|
179
|
-
this.setStamper(this.iframeStamper);
|
|
180
|
-
return this.iframeStamper.publicKey();
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
Object.defineProperty(this, "initWebauthnStamper", {
|
|
184
|
-
enumerable: true,
|
|
185
|
-
configurable: true,
|
|
186
|
-
writable: true,
|
|
187
|
-
value: async (user = this.user) => {
|
|
188
|
-
this.setStamper(this.webauthnStamper);
|
|
189
|
-
if (user && user.credentialId) {
|
|
190
|
-
this.webauthnStamper.allowCredentials = [
|
|
191
|
-
{
|
|
192
|
-
id: Buffer.from(user.credentialId, "base64"),
|
|
193
|
-
type: "public-key",
|
|
194
|
-
transports: ["internal", "hybrid"],
|
|
195
|
-
},
|
|
196
|
-
];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
Object.defineProperty(this, "getWebAuthnAttestation", {
|
|
201
|
-
enumerable: true,
|
|
202
|
-
configurable: true,
|
|
203
|
-
writable: true,
|
|
204
|
-
value: async (options, userDetails = {
|
|
205
|
-
username: this.user?.email ?? "anonymous",
|
|
206
|
-
}) => {
|
|
207
|
-
const challenge = (0, generateRandomBuffer_js_1.generateRandomBuffer)();
|
|
208
|
-
const authenticatorUserId = (0, generateRandomBuffer_js_1.generateRandomBuffer)();
|
|
209
|
-
const attestation = await (0, http_1.getWebAuthnAttestation)({
|
|
210
|
-
publicKey: {
|
|
211
|
-
...options?.publicKey,
|
|
212
|
-
authenticatorSelection: {
|
|
213
|
-
residentKey: "preferred",
|
|
214
|
-
requireResidentKey: false,
|
|
215
|
-
userVerification: "preferred",
|
|
216
|
-
...options?.publicKey?.authenticatorSelection,
|
|
217
|
-
},
|
|
218
|
-
challenge,
|
|
219
|
-
rp: {
|
|
220
|
-
id: window.location.hostname,
|
|
221
|
-
name: window.location.hostname,
|
|
222
|
-
...options?.publicKey?.rp,
|
|
223
|
-
},
|
|
224
|
-
pubKeyCredParams: [
|
|
225
|
-
{
|
|
226
|
-
type: "public-key",
|
|
227
|
-
alg: -7,
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
type: "public-key",
|
|
231
|
-
alg: -257,
|
|
232
|
-
},
|
|
233
|
-
],
|
|
234
|
-
user: {
|
|
235
|
-
id: authenticatorUserId,
|
|
236
|
-
name: userDetails.username,
|
|
237
|
-
displayName: userDetails.username,
|
|
238
|
-
...options?.publicKey?.user,
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
signal: options?.signal,
|
|
242
|
-
});
|
|
243
|
-
if (attestation.transports == null || attestation.transports.length === 0) {
|
|
244
|
-
attestation.transports = [
|
|
245
|
-
"AUTHENTICATOR_TRANSPORT_INTERNAL",
|
|
246
|
-
"AUTHENTICATOR_TRANSPORT_HYBRID",
|
|
247
|
-
];
|
|
248
|
-
}
|
|
249
|
-
return { challenge, authenticatorUserId, attestation };
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
this.iframeStamper = iframeStamper;
|
|
253
|
-
this.iframeContainerId = iframeConfig.iframeContainerId;
|
|
254
|
-
this.webauthnStamper = new webauthn_stamper_1.WebauthnStamper({
|
|
255
|
-
rpId: rpId ?? window.location.hostname,
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
exports.AlchemySignerWebClient = AlchemySignerWebClient;
|
|
260
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":";;;AAAA,uCAAsD;AACtD,wCAAuD;AACvD,4DAAwD;AACxD,gEAA4D;AAC5D,6BAAwB;AACxB,oEAA8D;AAC9D,8EAAwE;AACxE,uCAA6C;AAShC,QAAA,+B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,IAAI,EAAE;4BACJ,EAAE,EAAE,mBAAmB;4BACvB,IAAI,EAAE,WAAW,CAAC,QAAQ;4BAC1B,WAAW,EAAE,WAAW,CAAC,QAAQ;4BACjC,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI;yBAC5B;qBACF;oBACD,MAAM,EAAE,OAAO,EAAE,MAAM;iBACxB,CAAC,CAAC;gBAGH,IAAI,WAAW,CAAC,UAAU,IAAI,IAAI,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAC1E,WAAW,CAAC,UAAU,GAAG;wBACvB,kCAAkC;wBAClC,gCAAgC;qBACjC,CAAC;gBACJ,CAAC;gBAED,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,WAAW,EAAE,CAAC;YACzD,CAAC;WAAC;QAtVA,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,iBAAiB,GAAG,YAAY,CAAC,iBAAiB,CAAC;QAExD,IAAI,CAAC,eAAe,GAAG,IAAI,kCAAe,CAAC;YACzC,IAAI,EAAE,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ;SACvC,CAAC,CAAC;IACL,CAAC;CAiVF;AAnYD,wDAmYC","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 /**\n * Initializes a new instance with the given parameters, setting up the connection, iframe configuration, and WebAuthn stamper.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n * ```\n *\n * @param {AlchemySignerClientParams} params the parameters required to initialize the client\n * @param {ConnectionConfig} params.connection The connection details needed to connect to the service\n * @param {{ iframeElementId?: string; iframeContainerId: string }} params.iframeConfig The configuration details for setting up the iframe stamper\n * @param {string} params.rpId The relying party ID, defaulting to the current hostname if not provided\n * @param {string} params.rootOrgId The root organization ID\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 /**\n * Authenticates the user by either email or passkey account creation flow. Emits events during the process.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.createAccount({ type: \"email\", email: \"you@mail.com\" });\n * ```\n *\n * @param {CreateAccountParams} params The parameters for creating an account, including the type (email or passkey) and additional details.\n * @returns {Promise<SignupResponse>} A promise that resolves with the response object containing the account creation result.\n */\n 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 /**\n * 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.\n * This method sends an email to the user to complete their login\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.initEmailAuth({ email: \"you@mail.com\" });\n * ```\n *\n * @param {Omit<EmailAuthParams, \"targetPublicKey\">} params The parameters for email authentication, excluding the target public key\n * @returns {Promise<any>} The response from the authentication request\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 /**\n * 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.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.completeEmailAuth({ orgId: \"user-org-id\", bundle: \"bundle-from-email\" });\n * ```\n *\n * @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\n * @returns {Promise<User>} A promise that resolves to the authenticated user information\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 /**\n * 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.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.lookupUserWithPasskey();\n * ```\n *\n * @param {User} [user] An optional user object to authenticate\n * @returns {Promise<User>} A promise that resolves to the authenticated user object\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 /**\n * Initiates the export of a wallet by creating an iframe stamper and calling the appropriate export function.\n * The export can be based on a seed phrase or a private key.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.exportWallet({\n * iframeContainerId: \"export-iframe-container\",\n * });\n * ```\n *\n * @param {ExportWalletParams} config The parameters for exporting the wallet\n * @param {string} config.iframeContainerId The ID of the container element that will hold the iframe stamper\n * @param {string} [config.iframeElementId] Optional ID for the iframe element\n * @returns {Promise<void>} A promise that resolves when the export process is complete\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 /**\n * Asynchronous function that clears the user and resets the iframe stamper.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.disconnect();\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"]}
|
|
@@ -1,106 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/cjs/client/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
package/dist/cjs/errors.d.ts
DELETED
package/dist/cjs/errors.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotAuthenticatedError = void 0;
|
|
4
|
-
const core_1 = require("@aa-sdk/core");
|
|
5
|
-
class NotAuthenticatedError extends core_1.BaseError {
|
|
6
|
-
constructor() {
|
|
7
|
-
super([
|
|
8
|
-
"Signer not authenticated",
|
|
9
|
-
"Please authenticate to use this signer",
|
|
10
|
-
].join("\n"), {
|
|
11
|
-
docsPath: "/signers/alchemy-signer/introduction.html",
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.NotAuthenticatedError = NotAuthenticatedError;
|
|
16
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/cjs/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,uCAAyC;AAEzC,MAAa,qBAAsB,SAAQ,gBAAS;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;AAZD,sDAYC","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"]}
|
package/dist/cjs/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { BaseAlchemySigner } from "./base.js";
|
|
2
|
-
export { BaseSignerClient } from "./client/base.js";
|
|
3
|
-
export { AlchemySignerWebClient } from "./client/index.js";
|
|
4
|
-
export type * from "./client/types.js";
|
|
5
|
-
export { DEFAULT_SESSION_MS } from "./session/manager.js";
|
|
6
|
-
export type * from "./signer.js";
|
|
7
|
-
export { AlchemyWebSigner } from "./signer.js";
|
|
8
|
-
export type * from "./types.js";
|
|
9
|
-
export { AlchemySignerStatus } from "./types.js";
|
package/dist/cjs/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AlchemySignerStatus = exports.AlchemyWebSigner = exports.DEFAULT_SESSION_MS = exports.AlchemySignerWebClient = exports.BaseSignerClient = exports.BaseAlchemySigner = void 0;
|
|
4
|
-
var base_js_1 = require("./base.js");
|
|
5
|
-
Object.defineProperty(exports, "BaseAlchemySigner", { enumerable: true, get: function () { return base_js_1.BaseAlchemySigner; } });
|
|
6
|
-
var base_js_2 = require("./client/base.js");
|
|
7
|
-
Object.defineProperty(exports, "BaseSignerClient", { enumerable: true, get: function () { return base_js_2.BaseSignerClient; } });
|
|
8
|
-
var index_js_1 = require("./client/index.js");
|
|
9
|
-
Object.defineProperty(exports, "AlchemySignerWebClient", { enumerable: true, get: function () { return index_js_1.AlchemySignerWebClient; } });
|
|
10
|
-
var manager_js_1 = require("./session/manager.js");
|
|
11
|
-
Object.defineProperty(exports, "DEFAULT_SESSION_MS", { enumerable: true, get: function () { return manager_js_1.DEFAULT_SESSION_MS; } });
|
|
12
|
-
var signer_js_1 = require("./signer.js");
|
|
13
|
-
Object.defineProperty(exports, "AlchemyWebSigner", { enumerable: true, get: function () { return signer_js_1.AlchemyWebSigner; } });
|
|
14
|
-
var types_js_1 = require("./types.js");
|
|
15
|
-
Object.defineProperty(exports, "AlchemySignerStatus", { enumerable: true, get: function () { return types_js_1.AlchemySignerStatus; } });
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAA8C;AAArC,4GAAA,iBAAiB,OAAA;AAC1B,4CAAoD;AAA3C,2GAAA,gBAAgB,OAAA;AACzB,8CAA2D;AAAlD,kHAAA,sBAAsB,OAAA;AAE/B,mDAA0D;AAAjD,gHAAA,kBAAkB,OAAA;AAE3B,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA;AAEzB,uCAAiD;AAAxC,+GAAA,mBAAmB,OAAA","sourcesContent":["export { BaseAlchemySigner } from \"./base.js\";\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\";\nexport type * from \"./signer.js\";\nexport { AlchemyWebSigner } from \"./signer.js\";\nexport type * from \"./types.js\";\nexport { AlchemySignerStatus } from \"./types.js\";\n"]}
|
package/dist/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|