@account-kit/signer 4.15.3 → 4.16.1-alpha.3
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 +59 -1
- package/dist/esm/base.js +159 -55
- package/dist/esm/base.js.map +1 -1
- package/dist/esm/client/base.d.ts +38 -3
- package/dist/esm/client/base.js +10 -3
- package/dist/esm/client/base.js.map +1 -1
- package/dist/esm/client/index.d.ts +40 -1
- package/dist/esm/client/index.js +164 -7
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/client/types.d.ts +69 -1
- package/dist/esm/client/types.js.map +1 -1
- package/dist/esm/errors.d.ts +6 -0
- package/dist/esm/errors.js +18 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/session/manager.d.ts +1 -0
- package/dist/esm/session/manager.js.map +1 -1
- package/dist/esm/signer.d.ts +3 -1
- package/dist/esm/signer.js.map +1 -1
- package/dist/esm/solanaSigner.d.ts +12 -0
- package/dist/esm/solanaSigner.js +67 -0
- package/dist/esm/solanaSigner.js.map +1 -0
- package/dist/esm/types.d.ts +8 -0
- package/dist/esm/types.js +5 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/parseMfaError.d.ts +2 -0
- package/dist/esm/utils/parseMfaError.js +15 -0
- package/dist/esm/utils/parseMfaError.js.map +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/base.d.ts +59 -1
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/client/base.d.ts +38 -3
- package/dist/types/client/base.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +40 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/types.d.ts +69 -1
- package/dist/types/client/types.d.ts.map +1 -1
- package/dist/types/errors.d.ts +6 -0
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/session/manager.d.ts +1 -0
- package/dist/types/session/manager.d.ts.map +1 -1
- package/dist/types/signer.d.ts +3 -1
- package/dist/types/signer.d.ts.map +1 -1
- package/dist/types/solanaSigner.d.ts +13 -0
- package/dist/types/solanaSigner.d.ts.map +1 -0
- package/dist/types/types.d.ts +8 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/parseMfaError.d.ts +3 -0
- package/dist/types/utils/parseMfaError.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/base.ts +206 -62
- package/src/client/base.ts +59 -4
- package/src/client/index.ts +174 -7
- package/src/client/types.ts +79 -1
- package/src/errors.ts +11 -1
- package/src/index.ts +6 -1
- package/src/session/manager.ts +5 -1
- package/src/signer.ts +6 -1
- package/src/solanaSigner.ts +83 -0
- package/src/types.ts +9 -0
- package/src/utils/parseMfaError.ts +15 -0
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/session/manager.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAGV,IAAI,EACL,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAW,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE7D,eAAO,MAAM,kBAAkB,QAAiB,CAAC;AAEjD,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;EAarC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAW9E,KAAK,gBAAg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CA6E5B;IAEF,OAAO,CAAC,gCAAgC,CAStC;IAEF,OAAO,CAAC,2BAA2B,CAsBjC;CACH"}
|
package/dist/types/signer.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BaseAlchemySigner } from "./base.js";
|
|
3
3
|
import { AlchemySignerWebClient } from "./client/index.js";
|
|
4
|
-
import type { CredentialCreationOptionOverrides } from "./client/types.js";
|
|
4
|
+
import type { CredentialCreationOptionOverrides, VerifyMfaParams } from "./client/types.js";
|
|
5
5
|
export type AuthParams = {
|
|
6
6
|
type: "email";
|
|
7
7
|
email: string;
|
|
8
8
|
emailMode?: "magicLink" | "otp";
|
|
9
9
|
redirectParams?: URLSearchParams;
|
|
10
|
+
multiFactors?: VerifyMfaParams[];
|
|
10
11
|
} | {
|
|
11
12
|
type: "email";
|
|
12
13
|
bundle: string;
|
|
@@ -37,6 +38,7 @@ export type AuthParams = {
|
|
|
37
38
|
} | {
|
|
38
39
|
type: "otp";
|
|
39
40
|
otpCode: string;
|
|
41
|
+
multiFactors?: VerifyMfaParams[];
|
|
40
42
|
};
|
|
41
43
|
export type OauthProviderConfig = {
|
|
42
44
|
authProviderId: "auth0";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAEL,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAEL,sBAAsB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AmB;CAuDxC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Transaction, type VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import { type ByteArray } from "viem";
|
|
3
|
+
import type { BaseSignerClient } from "./client/base";
|
|
4
|
+
export declare class SolanaSigner {
|
|
5
|
+
private alchemyClient;
|
|
6
|
+
address: string;
|
|
7
|
+
constructor(client: BaseSignerClient);
|
|
8
|
+
addSignature(tx: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
9
|
+
signMessage(message: Uint8Array): Promise<ByteArray>;
|
|
10
|
+
private formatSignatureForSolana;
|
|
11
|
+
private getMessageToSign;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=solanaSigner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solanaSigner.d.ts","sourceRoot":"","sources":["../../src/solanaSigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAA+B,KAAK,SAAS,EAAY,MAAM,MAAM,CAAC;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,qBAAa,YAAY;IACvB,OAAO,CAAC,aAAa,CAAmB;IACjC,OAAO,EAAE,MAAM,CAAC;gBAEX,MAAM,EAAE,gBAAgB;IAQ9B,YAAY,CAChB,EAAE,EAAE,WAAW,GAAG,oBAAoB,GACrC,OAAO,CAAC,WAAW,GAAG,oBAAoB,CAAC;IAwBxC,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IAmB1D,OAAO,CAAC,wBAAwB;IAMhC,OAAO,CAAC,gBAAgB;CASzB"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export type AlchemySignerEvents = {
|
|
|
5
5
|
disconnected(): void;
|
|
6
6
|
statusChanged(status: AlchemySignerStatus): void;
|
|
7
7
|
errorChanged(error: ErrorInfo | undefined): void;
|
|
8
|
+
mfaStatusChanged(mfaStatus: {
|
|
9
|
+
mfaRequired: boolean;
|
|
10
|
+
mfaFactorId?: string;
|
|
11
|
+
}): void;
|
|
8
12
|
};
|
|
9
13
|
export type AlchemySignerEvent = keyof AlchemySignerEvents;
|
|
10
14
|
export declare enum AlchemySignerStatus {
|
|
@@ -17,6 +21,10 @@ export declare enum AlchemySignerStatus {
|
|
|
17
21
|
AWAITING_EMAIL_AUTH = "AWAITING_EMAIL_AUTH",
|
|
18
22
|
AWAITING_OTP_AUTH = "AWAITING_OTP_AUTH"
|
|
19
23
|
}
|
|
24
|
+
export declare enum AlchemyMfaStatus {
|
|
25
|
+
NOT_REQUIRED = "not_required",
|
|
26
|
+
REQUIRED = "required"
|
|
27
|
+
}
|
|
20
28
|
export interface ErrorInfo {
|
|
21
29
|
name: string;
|
|
22
30
|
message: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAC5B,aAAa,IAAI,IAAI,CAAC;IACtB,YAAY,IAAI,IAAI,CAAC;IACrB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACjD,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAC5B,aAAa,IAAI,IAAI,CAAC;IACtB,YAAY,IAAI,IAAI,CAAC;IACrB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACjD,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;IACjD,gBAAgB,CAAC,SAAS,EAAE;QAC1B,WAAW,EAAE,OAAO,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,IAAI,CAAC;CACV,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,MAAM,mBAAmB,CAAC;AAE3D,oBAAY,mBAAmB;IAC7B,YAAY,iBAAiB;IAC7B,SAAS,cAAc;IACvB,YAAY,iBAAiB;IAC7B,sBAAsB,2BAA2B;IACjD,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;IAC7C,mBAAmB,wBAAwB;IAC3C,iBAAiB,sBAAsB;CACxC;AAED,oBAAY,gBAAgB;IAC1B,YAAY,iBAAiB;IAC7B,QAAQ,aAAa;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseMfaError.d.ts","sourceRoot":"","sources":["../../../src/utils/parseMfaError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,EAAE,GAAG,IAAI,CAYhE"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.16.1-alpha.3";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/signer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.16.1-alpha.3",
|
|
4
4
|
"description": "Core interfaces and clients for interfacing with the Alchemy Signer API",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,8 +49,9 @@
|
|
|
49
49
|
"vitest": "^2.0.4"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@aa-sdk/core": "^4.
|
|
53
|
-
"@account-kit/logging": "^4.
|
|
52
|
+
"@aa-sdk/core": "^4.16.1-alpha.3",
|
|
53
|
+
"@account-kit/logging": "^4.16.1-alpha.3",
|
|
54
|
+
"@solana/web3.js": "^1.98.0",
|
|
54
55
|
"@turnkey/http": "^2.6.2",
|
|
55
56
|
"@turnkey/iframe-stamper": "^1.0.0",
|
|
56
57
|
"@turnkey/viem": "^0.4.8",
|
|
@@ -73,5 +74,5 @@
|
|
|
73
74
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
74
75
|
},
|
|
75
76
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
76
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "156dbc81d12e9f120f8123df6b4fec8a41f41e7a"
|
|
77
78
|
}
|
package/src/base.ts
CHANGED
|
@@ -16,18 +16,28 @@ import {
|
|
|
16
16
|
type TypedDataDefinition,
|
|
17
17
|
} from "viem";
|
|
18
18
|
import { toAccount } from "viem/accounts";
|
|
19
|
+
import { hashAuthorization, type Authorization } from "viem/experimental";
|
|
19
20
|
import type { Mutate, StoreApi } from "zustand";
|
|
20
21
|
import { subscribeWithSelector } from "zustand/middleware";
|
|
21
22
|
import { createStore } from "zustand/vanilla";
|
|
22
23
|
import type { BaseSignerClient } from "./client/base";
|
|
23
|
-
import type {
|
|
24
|
+
import type {
|
|
25
|
+
EmailType,
|
|
26
|
+
MfaFactor,
|
|
27
|
+
OauthConfig,
|
|
28
|
+
OauthParams,
|
|
29
|
+
User,
|
|
30
|
+
VerifyMfaParams,
|
|
31
|
+
} from "./client/types";
|
|
24
32
|
import { NotAuthenticatedError } from "./errors.js";
|
|
25
33
|
import { SignerLogger } from "./metrics.js";
|
|
26
34
|
import {
|
|
27
35
|
SessionManager,
|
|
28
36
|
type SessionManagerParams,
|
|
29
37
|
} from "./session/manager.js";
|
|
38
|
+
import type { SessionManagerEvents } from "./session/types";
|
|
30
39
|
import type { AuthParams } from "./signer";
|
|
40
|
+
import { SolanaSigner } from "./solanaSigner.js";
|
|
31
41
|
import {
|
|
32
42
|
AlchemySignerStatus,
|
|
33
43
|
type AlchemySignerEvent,
|
|
@@ -35,8 +45,6 @@ import {
|
|
|
35
45
|
type ErrorInfo,
|
|
36
46
|
} from "./types.js";
|
|
37
47
|
import { assertNever } from "./utils/typeAssertions.js";
|
|
38
|
-
import type { SessionManagerEvents } from "./session/types";
|
|
39
|
-
import { hashAuthorization, type Authorization } from "viem/experimental";
|
|
40
48
|
|
|
41
49
|
export interface BaseAlchemySignerParams<TClient extends BaseSignerClient> {
|
|
42
50
|
client: TClient;
|
|
@@ -50,6 +58,10 @@ type AlchemySignerStore = {
|
|
|
50
58
|
error: ErrorInfo | null;
|
|
51
59
|
otpId?: string;
|
|
52
60
|
isNewUser?: boolean;
|
|
61
|
+
mfaStatus: {
|
|
62
|
+
mfaRequired: boolean;
|
|
63
|
+
mfaFactorId?: string;
|
|
64
|
+
};
|
|
53
65
|
};
|
|
54
66
|
|
|
55
67
|
type UnpackedSignature = {
|
|
@@ -98,6 +110,10 @@ export abstract class BaseAlchemySigner<TClient extends BaseSignerClient>
|
|
|
98
110
|
user: null,
|
|
99
111
|
status: AlchemySignerStatus.INITIALIZING,
|
|
100
112
|
error: initialError ?? null,
|
|
113
|
+
mfaStatus: {
|
|
114
|
+
mfaRequired: false,
|
|
115
|
+
mfaFactorId: undefined,
|
|
116
|
+
},
|
|
101
117
|
} satisfies AlchemySignerStore)
|
|
102
118
|
)
|
|
103
119
|
);
|
|
@@ -170,6 +186,13 @@ export abstract class BaseAlchemySigner<TClient extends BaseSignerClient>
|
|
|
170
186
|
},
|
|
171
187
|
{ fireImmediately: true }
|
|
172
188
|
);
|
|
189
|
+
case "mfaStatusChanged":
|
|
190
|
+
return this.store.subscribe(
|
|
191
|
+
({ mfaStatus }) => mfaStatus,
|
|
192
|
+
(mfaStatus) =>
|
|
193
|
+
(listener as AlchemySignerEvents["mfaStatusChanged"])(mfaStatus),
|
|
194
|
+
{ fireImmediately: true }
|
|
195
|
+
);
|
|
173
196
|
default:
|
|
174
197
|
assertNever(event, `Unknown event type ${event}`);
|
|
175
198
|
}
|
|
@@ -579,6 +602,39 @@ export abstract class BaseAlchemySigner<TClient extends BaseSignerClient>
|
|
|
579
602
|
}
|
|
580
603
|
);
|
|
581
604
|
|
|
605
|
+
/**
|
|
606
|
+
* Gets the current MFA status
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```ts
|
|
610
|
+
* import { AlchemyWebSigner } from "@account-kit/signer";
|
|
611
|
+
*
|
|
612
|
+
* const signer = new AlchemyWebSigner({
|
|
613
|
+
* client: {
|
|
614
|
+
* connection: {
|
|
615
|
+
* rpcUrl: "/api/rpc",
|
|
616
|
+
* },
|
|
617
|
+
* iframeConfig: {
|
|
618
|
+
* iframeContainerId: "alchemy-signer-iframe-container",
|
|
619
|
+
* },
|
|
620
|
+
* },
|
|
621
|
+
* });
|
|
622
|
+
*
|
|
623
|
+
* const mfaStatus = signer.getMfaStatus();
|
|
624
|
+
* if (mfaStatus === AlchemyMfaStatus.REQUIRED) {
|
|
625
|
+
* // Handle MFA requirement
|
|
626
|
+
* }
|
|
627
|
+
* ```
|
|
628
|
+
*
|
|
629
|
+
* @returns {{ mfaRequired: boolean; mfaFactorId?: string }} The current MFA status
|
|
630
|
+
*/
|
|
631
|
+
getMfaStatus = (): {
|
|
632
|
+
mfaRequired: boolean;
|
|
633
|
+
mfaFactorId?: string;
|
|
634
|
+
} => {
|
|
635
|
+
return this.store.getState().mfaStatus;
|
|
636
|
+
};
|
|
637
|
+
|
|
582
638
|
private unpackSignRawMessageBytes = (
|
|
583
639
|
hex: `0x${string}`
|
|
584
640
|
): UnpackedSignature => {
|
|
@@ -733,73 +789,83 @@ export abstract class BaseAlchemySigner<TClient extends BaseSignerClient>
|
|
|
733
789
|
});
|
|
734
790
|
};
|
|
735
791
|
|
|
792
|
+
/**
|
|
793
|
+
* Creates a new instance of `SolanaSigner` using the provided inner value.
|
|
794
|
+
* This requires the signer to be authenticated first
|
|
795
|
+
*
|
|
796
|
+
* @example
|
|
797
|
+
* ```ts
|
|
798
|
+
* import { AlchemyWebSigner } from "@account-kit/signer";
|
|
799
|
+
*
|
|
800
|
+
* const signer = new AlchemyWebSigner({
|
|
801
|
+
* client: {
|
|
802
|
+
* connection: {
|
|
803
|
+
* rpcUrl: "/api/rpc",
|
|
804
|
+
* },
|
|
805
|
+
* iframeConfig: {
|
|
806
|
+
* iframeContainerId: "alchemy-signer-iframe-container",
|
|
807
|
+
* },
|
|
808
|
+
* },
|
|
809
|
+
* });
|
|
810
|
+
*
|
|
811
|
+
* const solanaSigner = signer.toSolanaSigner();
|
|
812
|
+
* ```
|
|
813
|
+
*
|
|
814
|
+
* @returns {SolanaSigner} A new instance of `SolanaSigner`
|
|
815
|
+
*/
|
|
816
|
+
experimental_toSolanaSigner = (): SolanaSigner => {
|
|
817
|
+
if (!this.inner.getUser()) {
|
|
818
|
+
throw new NotAuthenticatedError();
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
return new SolanaSigner(this.inner);
|
|
822
|
+
};
|
|
823
|
+
|
|
736
824
|
private authenticateWithEmail = async (
|
|
737
825
|
params: Extract<AuthParams, { type: "email" }>
|
|
738
826
|
): Promise<User> => {
|
|
739
|
-
if ("
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
const { orgId, otpId } = existingUser
|
|
744
|
-
? await this.inner.initEmailAuth({
|
|
745
|
-
email: params.email,
|
|
746
|
-
emailMode: params.emailMode,
|
|
747
|
-
expirationSeconds,
|
|
748
|
-
redirectParams: params.redirectParams,
|
|
749
|
-
})
|
|
750
|
-
: await this.inner.createAccount({
|
|
751
|
-
type: "email",
|
|
752
|
-
email: params.email,
|
|
753
|
-
emailMode: params.emailMode,
|
|
754
|
-
expirationSeconds,
|
|
755
|
-
redirectParams: params.redirectParams,
|
|
756
|
-
});
|
|
827
|
+
if ("bundle" in params) {
|
|
828
|
+
return this.completeEmailAuth(params);
|
|
829
|
+
}
|
|
757
830
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
});
|
|
762
|
-
this.store.setState({
|
|
763
|
-
status: AlchemySignerStatus.AWAITING_EMAIL_AUTH,
|
|
764
|
-
otpId,
|
|
765
|
-
error: null,
|
|
766
|
-
});
|
|
831
|
+
if (!("email" in params)) {
|
|
832
|
+
throw new Error("Email is required");
|
|
833
|
+
}
|
|
767
834
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
removeListener();
|
|
776
|
-
}
|
|
777
|
-
);
|
|
778
|
-
});
|
|
779
|
-
} else {
|
|
780
|
-
const temporarySession = params.orgId
|
|
781
|
-
? { orgId: params.orgId }
|
|
782
|
-
: this.sessionManager.getTemporarySession();
|
|
835
|
+
const { orgId, otpId, multiFactors, isNewUser } =
|
|
836
|
+
await this.initOrCreateEmailUser(
|
|
837
|
+
params.email,
|
|
838
|
+
params.emailMode ?? "otp",
|
|
839
|
+
params.multiFactors,
|
|
840
|
+
params.redirectParams
|
|
841
|
+
);
|
|
783
842
|
|
|
784
|
-
|
|
785
|
-
this.store.setState({
|
|
786
|
-
status: AlchemySignerStatus.DISCONNECTED,
|
|
787
|
-
});
|
|
788
|
-
throw new Error("Could not find email auth init session!");
|
|
789
|
-
}
|
|
843
|
+
const isMfaRequired = multiFactors ? multiFactors?.length > 0 : false;
|
|
790
844
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
});
|
|
845
|
+
this.sessionManager.setTemporarySession({
|
|
846
|
+
orgId,
|
|
847
|
+
isNewUser,
|
|
848
|
+
isMfaRequired,
|
|
849
|
+
});
|
|
797
850
|
|
|
798
|
-
|
|
799
|
-
|
|
851
|
+
this.store.setState({
|
|
852
|
+
status: AlchemySignerStatus.AWAITING_EMAIL_AUTH,
|
|
853
|
+
otpId,
|
|
854
|
+
error: null,
|
|
855
|
+
mfaStatus: {
|
|
856
|
+
mfaRequired: isMfaRequired,
|
|
857
|
+
mfaFactorId: multiFactors?.[0]?.multiFactorId,
|
|
858
|
+
},
|
|
859
|
+
});
|
|
800
860
|
|
|
801
|
-
|
|
802
|
-
|
|
861
|
+
// We wait for the session manager to emit a connected event if
|
|
862
|
+
// cross tab sessions are permitted
|
|
863
|
+
return new Promise<User>((resolve) => {
|
|
864
|
+
const removeListener = this.sessionManager.on("connected", (session) => {
|
|
865
|
+
resolve(session.user);
|
|
866
|
+
removeListener();
|
|
867
|
+
});
|
|
868
|
+
});
|
|
803
869
|
};
|
|
804
870
|
|
|
805
871
|
private authenticateWithPasskey = async (
|
|
@@ -860,7 +926,7 @@ export abstract class BaseAlchemySigner<TClient extends BaseSignerClient>
|
|
|
860
926
|
args: Extract<AuthParams, { type: "otp" }>
|
|
861
927
|
): Promise<User> => {
|
|
862
928
|
const tempSession = this.sessionManager.getTemporarySession();
|
|
863
|
-
const { orgId, isNewUser } = tempSession ?? {};
|
|
929
|
+
const { orgId, isNewUser, isMfaRequired } = tempSession ?? {};
|
|
864
930
|
const { otpId } = this.store.getState();
|
|
865
931
|
if (!orgId) {
|
|
866
932
|
throw new Error("orgId not found in session");
|
|
@@ -868,11 +934,16 @@ export abstract class BaseAlchemySigner<TClient extends BaseSignerClient>
|
|
|
868
934
|
if (!otpId) {
|
|
869
935
|
throw new Error("otpId not found in session");
|
|
870
936
|
}
|
|
937
|
+
if (isMfaRequired && !args.multiFactors) {
|
|
938
|
+
throw new Error(`MFA is required.`);
|
|
939
|
+
}
|
|
940
|
+
|
|
871
941
|
const { bundle } = await this.inner.submitOtpCode({
|
|
872
942
|
orgId,
|
|
873
943
|
otpId,
|
|
874
944
|
otpCode: args.otpCode,
|
|
875
945
|
expirationSeconds: this.getExpirationSeconds(),
|
|
946
|
+
multiFactors: args.multiFactors,
|
|
876
947
|
});
|
|
877
948
|
const user = await this.inner.completeAuthWithBundle({
|
|
878
949
|
bundle,
|
|
@@ -978,6 +1049,79 @@ export abstract class BaseAlchemySigner<TClient extends BaseSignerClient>
|
|
|
978
1049
|
// assumes that if isNewUser is undefined it is a returning user
|
|
979
1050
|
if (isNewUser) this.store.setState({ isNewUser });
|
|
980
1051
|
};
|
|
1052
|
+
|
|
1053
|
+
private async initOrCreateEmailUser(
|
|
1054
|
+
email: string,
|
|
1055
|
+
emailMode: EmailType,
|
|
1056
|
+
multiFactors?: VerifyMfaParams[],
|
|
1057
|
+
redirectParams?: URLSearchParams
|
|
1058
|
+
): Promise<{
|
|
1059
|
+
orgId: string;
|
|
1060
|
+
otpId?: string;
|
|
1061
|
+
multiFactors?: MfaFactor[];
|
|
1062
|
+
isNewUser: boolean;
|
|
1063
|
+
}> {
|
|
1064
|
+
const existingUser = await this.getUser(email);
|
|
1065
|
+
const expirationSeconds = this.getExpirationSeconds();
|
|
1066
|
+
|
|
1067
|
+
if (existingUser) {
|
|
1068
|
+
const {
|
|
1069
|
+
orgId,
|
|
1070
|
+
otpId,
|
|
1071
|
+
multiFactors: mfaFactors,
|
|
1072
|
+
} = await this.inner.initEmailAuth({
|
|
1073
|
+
email: email,
|
|
1074
|
+
emailMode: emailMode,
|
|
1075
|
+
expirationSeconds,
|
|
1076
|
+
redirectParams: redirectParams,
|
|
1077
|
+
multiFactors,
|
|
1078
|
+
});
|
|
1079
|
+
return {
|
|
1080
|
+
orgId,
|
|
1081
|
+
otpId,
|
|
1082
|
+
multiFactors: mfaFactors,
|
|
1083
|
+
isNewUser: false,
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
const { orgId, otpId } = await this.inner.createAccount({
|
|
1088
|
+
type: "email",
|
|
1089
|
+
email,
|
|
1090
|
+
emailMode,
|
|
1091
|
+
expirationSeconds,
|
|
1092
|
+
redirectParams,
|
|
1093
|
+
});
|
|
1094
|
+
return {
|
|
1095
|
+
orgId,
|
|
1096
|
+
otpId,
|
|
1097
|
+
isNewUser: true,
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
private async completeEmailAuth(
|
|
1102
|
+
params: Extract<AuthParams, { type: "email"; bundle: string }>
|
|
1103
|
+
): Promise<User> {
|
|
1104
|
+
const temporarySession = params.orgId
|
|
1105
|
+
? { orgId: params.orgId }
|
|
1106
|
+
: this.sessionManager.getTemporarySession();
|
|
1107
|
+
|
|
1108
|
+
if (!temporarySession) {
|
|
1109
|
+
this.store.setState({ status: AlchemySignerStatus.DISCONNECTED });
|
|
1110
|
+
throw new Error("Could not find email auth init session!");
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
const user = await this.inner.completeAuthWithBundle({
|
|
1114
|
+
bundle: params.bundle,
|
|
1115
|
+
orgId: temporarySession.orgId,
|
|
1116
|
+
connectedEventName: "connectedEmail",
|
|
1117
|
+
authenticatingType: "email",
|
|
1118
|
+
});
|
|
1119
|
+
|
|
1120
|
+
// fire new user event
|
|
1121
|
+
this.emitNewUserEvent(params.isNewUser);
|
|
1122
|
+
|
|
1123
|
+
return user;
|
|
1124
|
+
}
|
|
981
1125
|
}
|
|
982
1126
|
|
|
983
1127
|
function toErrorInfo(error: unknown): ErrorInfo {
|
package/src/client/base.ts
CHANGED
|
@@ -14,9 +14,13 @@ import type {
|
|
|
14
14
|
AlchemySignerClientEvents,
|
|
15
15
|
AuthenticatingEventMetadata,
|
|
16
16
|
CreateAccountParams,
|
|
17
|
+
RemoveMfaParams,
|
|
17
18
|
EmailAuthParams,
|
|
19
|
+
EnableMfaParams,
|
|
20
|
+
EnableMfaResult,
|
|
18
21
|
GetOauthProviderUrlArgs,
|
|
19
22
|
GetWebAuthnAttestationResult,
|
|
23
|
+
MfaFactor,
|
|
20
24
|
OauthConfig,
|
|
21
25
|
OauthParams,
|
|
22
26
|
OauthState,
|
|
@@ -26,6 +30,7 @@ import type {
|
|
|
26
30
|
SignerRoutes,
|
|
27
31
|
SignupResponse,
|
|
28
32
|
User,
|
|
33
|
+
VerifyMfaParams,
|
|
29
34
|
} from "./types.js";
|
|
30
35
|
|
|
31
36
|
export interface BaseSignerClientParams {
|
|
@@ -131,7 +136,44 @@ export abstract class BaseSignerClient<TExportWalletParams = unknown> {
|
|
|
131
136
|
|
|
132
137
|
public abstract initEmailAuth(
|
|
133
138
|
params: Omit<EmailAuthParams, "targetPublicKey">
|
|
134
|
-
): Promise<{ orgId: string; otpId?: string }>;
|
|
139
|
+
): Promise<{ orgId: string; otpId?: string; multiFactors?: MfaFactor[] }>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves the list of MFA factors configured for the current user.
|
|
143
|
+
*
|
|
144
|
+
* @returns {Promise<{ multiFactors: Array<MfaFactor> }>} A promise that resolves to an array of configured MFA factors
|
|
145
|
+
*/
|
|
146
|
+
public abstract getMfaFactors(): Promise<{
|
|
147
|
+
multiFactors: MfaFactor[];
|
|
148
|
+
}>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Initiates the setup of a new MFA factor for the current user. Mfa will need to be verified before it is active.
|
|
152
|
+
*
|
|
153
|
+
* @param {EnableMfaParams} params The parameters required to enable a new MFA factor
|
|
154
|
+
* @returns {Promise<EnableMfaResult>} A promise that resolves to the factor setup information
|
|
155
|
+
*/
|
|
156
|
+
public abstract addMfa(params: EnableMfaParams): Promise<EnableMfaResult>;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Verifies a newly created MFA factor to complete the setup process.
|
|
160
|
+
*
|
|
161
|
+
* @param {VerifyMfaParams} params The parameters required to verify the MFA factor
|
|
162
|
+
* @returns {Promise<{ multiFactors: MfaFactor[] }>} A promise that resolves to the updated list of MFA factors
|
|
163
|
+
*/
|
|
164
|
+
public abstract verifyMfa(params: VerifyMfaParams): Promise<{
|
|
165
|
+
multiFactors: MfaFactor[];
|
|
166
|
+
}>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Removes existing MFA factors by ID or factor type.
|
|
170
|
+
*
|
|
171
|
+
* @param {RemoveMfaParams} params The parameters specifying which factors to disable
|
|
172
|
+
* @returns {Promise<{ multiFactors: MfaFactor[] }>} A promise that resolves to the updated list of MFA factors
|
|
173
|
+
*/
|
|
174
|
+
public abstract removeMfa(params: RemoveMfaParams): Promise<{
|
|
175
|
+
multiFactors: MfaFactor[];
|
|
176
|
+
}>;
|
|
135
177
|
|
|
136
178
|
public abstract completeAuthWithBundle(params: {
|
|
137
179
|
bundle: string;
|
|
@@ -317,22 +359,35 @@ export abstract class BaseSignerClient<TExportWalletParams = unknown> {
|
|
|
317
359
|
* that result here.
|
|
318
360
|
*
|
|
319
361
|
* @param {Hex} msg the hex representation of the bytes to sign
|
|
362
|
+
* @param {string} mode specify if signing should happen for solana or ethereum
|
|
320
363
|
* @returns {Promise<Hex>} the signature over the raw hex
|
|
321
364
|
*/
|
|
322
|
-
public signRawMessage = async (
|
|
365
|
+
public signRawMessage = async (
|
|
366
|
+
msg: Hex,
|
|
367
|
+
mode: "SOLANA" | "ETHEREUM" = "ETHEREUM"
|
|
368
|
+
): Promise<Hex> => {
|
|
323
369
|
if (!this.user) {
|
|
324
370
|
throw new NotAuthenticatedError();
|
|
325
371
|
}
|
|
326
372
|
|
|
373
|
+
if (!this.user.solanaAddress && mode === "SOLANA") {
|
|
374
|
+
// TODO: we need to add backwards compatibility for users who signed up before we added Solana support
|
|
375
|
+
throw new Error("No Solana address available for the user");
|
|
376
|
+
}
|
|
377
|
+
|
|
327
378
|
const stampedRequest = await this.turnkeyClient.stampSignRawPayload({
|
|
328
379
|
organizationId: this.user.orgId,
|
|
329
380
|
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
330
381
|
timestampMs: Date.now().toString(),
|
|
331
382
|
parameters: {
|
|
332
383
|
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
333
|
-
hashFunction:
|
|
384
|
+
hashFunction:
|
|
385
|
+
mode === "ETHEREUM"
|
|
386
|
+
? "HASH_FUNCTION_NO_OP"
|
|
387
|
+
: "HASH_FUNCTION_NOT_APPLICABLE",
|
|
334
388
|
payload: msg,
|
|
335
|
-
signWith:
|
|
389
|
+
signWith:
|
|
390
|
+
mode === "ETHEREUM" ? this.user.address : this.user.solanaAddress!,
|
|
336
391
|
},
|
|
337
392
|
});
|
|
338
393
|
|