@account-kit/signer 4.26.0 → 4.28.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/dist/esm/base.d.ts +4 -4
- package/dist/esm/base.js +2 -2
- package/dist/esm/base.js.map +1 -1
- package/dist/esm/client/base.d.ts +49 -43
- package/dist/esm/client/base.js +166 -0
- package/dist/esm/client/base.js.map +1 -1
- package/dist/esm/client/index.d.ts +2 -50
- package/dist/esm/client/index.js +1 -162
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/client/types.d.ts +4 -7
- package/dist/esm/client/types.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solanaSigner.d.ts +37 -4
- package/dist/esm/solanaSigner.js +107 -6
- package/dist/esm/solanaSigner.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/base.d.ts +4 -4
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/client/base.d.ts +49 -43
- package/dist/types/client/base.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +2 -50
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/types.d.ts +4 -7
- package/dist/types/client/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/solanaSigner.d.ts +37 -4
- package/dist/types/solanaSigner.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -4
- package/src/base.ts +5 -5
- package/src/client/base.ts +171 -49
- package/src/client/index.ts +1 -177
- package/src/client/types.ts +4 -7
- package/src/index.ts +1 -0
- package/src/solanaSigner.ts +155 -8
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/signer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.28.0",
|
|
4
4
|
"description": "Core interfaces and clients for interfacing with the Alchemy Signer API",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@tanstack/react-query": "^5.28.9",
|
|
45
|
+
"@types/bs58": "^4.0.4",
|
|
45
46
|
"react": "^18.2.0",
|
|
46
47
|
"react-dom": "^18.2.0",
|
|
47
48
|
"tailwindcss": "^3.4.3",
|
|
@@ -50,13 +51,14 @@
|
|
|
50
51
|
"vitest": "^2.0.4"
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
|
-
"@aa-sdk/core": "^4.
|
|
54
|
-
"@account-kit/logging": "^4.
|
|
54
|
+
"@aa-sdk/core": "^4.28.0",
|
|
55
|
+
"@account-kit/logging": "^4.28.0",
|
|
55
56
|
"@solana/web3.js": "^1.98.0",
|
|
56
57
|
"@turnkey/http": "^2.6.2",
|
|
57
58
|
"@turnkey/iframe-stamper": "^1.0.0",
|
|
58
59
|
"@turnkey/viem": "^0.4.8",
|
|
59
60
|
"@turnkey/webauthn-stamper": "^0.4.3",
|
|
61
|
+
"bs58": "^6.0.0",
|
|
60
62
|
"jwt-decode": "^4.0.0",
|
|
61
63
|
"zod": "^3.22.4",
|
|
62
64
|
"zustand": "^5.0.0-rc.2"
|
|
@@ -76,5 +78,5 @@
|
|
|
76
78
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
77
79
|
},
|
|
78
80
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
79
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "fd15569ef554b4ff19c72d864e1031aad8bdf8b3"
|
|
80
82
|
}
|
package/src/base.ts
CHANGED
|
@@ -28,8 +28,8 @@ import type {
|
|
|
28
28
|
OauthParams,
|
|
29
29
|
User,
|
|
30
30
|
VerifyMfaParams,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
AddMfaParams,
|
|
32
|
+
AddMfaResult,
|
|
33
33
|
RemoveMfaParams,
|
|
34
34
|
} from "./client/types";
|
|
35
35
|
import { NotAuthenticatedError } from "./errors.js";
|
|
@@ -1214,11 +1214,11 @@ export abstract class BaseAlchemySigner<TClient extends BaseSignerClient>
|
|
|
1214
1214
|
* // Result contains multiFactorTotpUrl to display as QR code
|
|
1215
1215
|
* ```
|
|
1216
1216
|
*
|
|
1217
|
-
* @param {
|
|
1217
|
+
* @param {AddMfaParams} params The parameters required to enable a new MFA factor
|
|
1218
1218
|
* @throws {NotAuthenticatedError} If no user is authenticated
|
|
1219
|
-
* @returns {Promise<
|
|
1219
|
+
* @returns {Promise<AddMfaResult>} A promise that resolves to the factor setup information
|
|
1220
1220
|
*/
|
|
1221
|
-
addMfa: (params:
|
|
1221
|
+
addMfa: (params: AddMfaParams) => Promise<AddMfaResult> =
|
|
1222
1222
|
SignerLogger.profiled("BaseAlchemySigner.addMfa", async (params) => {
|
|
1223
1223
|
return this.inner.addMfa(params);
|
|
1224
1224
|
});
|
package/src/client/base.ts
CHANGED
|
@@ -16,8 +16,8 @@ import type {
|
|
|
16
16
|
CreateAccountParams,
|
|
17
17
|
RemoveMfaParams,
|
|
18
18
|
EmailAuthParams,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
AddMfaParams,
|
|
20
|
+
AddMfaResult,
|
|
21
21
|
experimental_CreateApiKeyParams,
|
|
22
22
|
GetOauthProviderUrlArgs,
|
|
23
23
|
GetWebAuthnAttestationResult,
|
|
@@ -50,6 +50,14 @@ export type ExportWalletStamper = TurnkeyClient["stamper"] & {
|
|
|
50
50
|
publicKey(): string | null;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
const MFA_PAYLOAD = {
|
|
54
|
+
GET: "get_mfa",
|
|
55
|
+
ADD: "add_mfa",
|
|
56
|
+
DELETE: "delete_mfas",
|
|
57
|
+
VERIFY: "verify_mfa",
|
|
58
|
+
LIST: "list_mfas",
|
|
59
|
+
} as const;
|
|
60
|
+
|
|
53
61
|
/**
|
|
54
62
|
* Base class for all Alchemy Signer clients
|
|
55
63
|
*/
|
|
@@ -142,53 +150,6 @@ export abstract class BaseSignerClient<TExportWalletParams = unknown> {
|
|
|
142
150
|
params: Omit<EmailAuthParams, "targetPublicKey">
|
|
143
151
|
): Promise<{ orgId: string; otpId?: string; multiFactors?: MfaFactor[] }>;
|
|
144
152
|
|
|
145
|
-
/**
|
|
146
|
-
* Retrieves the list of MFA factors configured for the current user.
|
|
147
|
-
*
|
|
148
|
-
* @returns {Promise<{ multiFactors: Array<MfaFactor> }>} A promise that resolves to an array of configured MFA factors
|
|
149
|
-
*/
|
|
150
|
-
public abstract getMfaFactors(): Promise<{
|
|
151
|
-
multiFactors: MfaFactor[];
|
|
152
|
-
}>;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Initiates the setup of a new MFA factor for the current user. Mfa will need to be verified before it is active.
|
|
156
|
-
*
|
|
157
|
-
* @param {EnableMfaParams} params The parameters required to enable a new MFA factor
|
|
158
|
-
* @returns {Promise<EnableMfaResult>} A promise that resolves to the factor setup information
|
|
159
|
-
*/
|
|
160
|
-
public abstract addMfa(params: EnableMfaParams): Promise<EnableMfaResult>;
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Verifies a newly created MFA factor to complete the setup process.
|
|
164
|
-
*
|
|
165
|
-
* @param {VerifyMfaParams} params The parameters required to verify the MFA factor
|
|
166
|
-
* @returns {Promise<{ multiFactors: MfaFactor[] }>} A promise that resolves to the updated list of MFA factors
|
|
167
|
-
*/
|
|
168
|
-
public abstract verifyMfa(params: VerifyMfaParams): Promise<{
|
|
169
|
-
multiFactors: MfaFactor[];
|
|
170
|
-
}>;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Removes existing MFA factors by ID or factor type.
|
|
174
|
-
*
|
|
175
|
-
* @param {RemoveMfaParams} params The parameters specifying which factors to disable
|
|
176
|
-
* @returns {Promise<{ multiFactors: MfaFactor[] }>} A promise that resolves to the updated list of MFA factors
|
|
177
|
-
*/
|
|
178
|
-
public abstract removeMfa(params: RemoveMfaParams): Promise<{
|
|
179
|
-
multiFactors: MfaFactor[];
|
|
180
|
-
}>;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Validates multiple MFA factors using the provided encrypted payload and MFA codes.
|
|
184
|
-
*
|
|
185
|
-
* @param {ValidateMultiFactorsParams} params The validation parameters
|
|
186
|
-
* @returns {Promise<{ bundle: string }>} A promise that resolves to an object containing the credential bundle
|
|
187
|
-
*/
|
|
188
|
-
public abstract validateMultiFactors(
|
|
189
|
-
params: ValidateMultiFactorsParams
|
|
190
|
-
): Promise<{ bundle: string }>;
|
|
191
|
-
|
|
192
153
|
public abstract completeAuthWithBundle(params: {
|
|
193
154
|
bundle: string;
|
|
194
155
|
orgId: string;
|
|
@@ -536,6 +497,167 @@ export abstract class BaseSignerClient<TExportWalletParams = unknown> {
|
|
|
536
497
|
return json as SignerResponse<R>;
|
|
537
498
|
};
|
|
538
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Retrieves the list of MFA factors configured for the current user.
|
|
502
|
+
*
|
|
503
|
+
* @returns {Promise<{ multiFactors: MfaFactor[] }>} A promise that resolves to an array of configured MFA factors
|
|
504
|
+
* @throws {NotAuthenticatedError} If no user is authenticated
|
|
505
|
+
*/
|
|
506
|
+
public getMfaFactors = async (): Promise<{
|
|
507
|
+
multiFactors: MfaFactor[];
|
|
508
|
+
}> => {
|
|
509
|
+
if (!this.user) {
|
|
510
|
+
throw new NotAuthenticatedError();
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const stampedRequest = await this.turnkeyClient.stampSignRawPayload({
|
|
514
|
+
organizationId: this.user.orgId,
|
|
515
|
+
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
516
|
+
timestampMs: Date.now().toString(),
|
|
517
|
+
parameters: {
|
|
518
|
+
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
519
|
+
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
520
|
+
payload: MFA_PAYLOAD.LIST,
|
|
521
|
+
signWith: this.user.address,
|
|
522
|
+
},
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
return this.request("/v1/auth-list-multi-factors", {
|
|
526
|
+
stampedRequest,
|
|
527
|
+
});
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Initiates the setup of a new MFA factor for the current user. Mfa will need to be verified before it is active.
|
|
532
|
+
*
|
|
533
|
+
* @param {AddMfaParams} params The parameters required to enable a new MFA factor
|
|
534
|
+
* @returns {Promise<AddMfaResult>} A promise that resolves to the factor setup information
|
|
535
|
+
* @throws {NotAuthenticatedError} If no user is authenticated
|
|
536
|
+
* @throws {Error} If an unsupported factor type is provided
|
|
537
|
+
*/
|
|
538
|
+
public addMfa = async (params: AddMfaParams): Promise<AddMfaResult> => {
|
|
539
|
+
if (!this.user) {
|
|
540
|
+
throw new NotAuthenticatedError();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
const stampedRequest = await this.turnkeyClient.stampSignRawPayload({
|
|
544
|
+
organizationId: this.user.orgId,
|
|
545
|
+
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
546
|
+
timestampMs: Date.now().toString(),
|
|
547
|
+
parameters: {
|
|
548
|
+
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
549
|
+
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
550
|
+
payload: MFA_PAYLOAD.ADD,
|
|
551
|
+
signWith: this.user.address,
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
switch (params.multiFactorType) {
|
|
556
|
+
case "totp":
|
|
557
|
+
return this.request("/v1/auth-request-multi-factor", {
|
|
558
|
+
stampedRequest,
|
|
559
|
+
multiFactorType: params.multiFactorType,
|
|
560
|
+
});
|
|
561
|
+
default:
|
|
562
|
+
throw new Error(
|
|
563
|
+
`Unsupported MFA factor type: ${params.multiFactorType}`
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Verifies a newly created MFA factor to complete the setup process.
|
|
570
|
+
*
|
|
571
|
+
* @param {VerifyMfaParams} params The parameters required to verify the MFA factor
|
|
572
|
+
* @returns {Promise<{ multiFactors: MfaFactor[] }>} A promise that resolves to the updated list of MFA factors
|
|
573
|
+
* @throws {NotAuthenticatedError} If no user is authenticated
|
|
574
|
+
*/
|
|
575
|
+
public verifyMfa = async (
|
|
576
|
+
params: VerifyMfaParams
|
|
577
|
+
): Promise<{ multiFactors: MfaFactor[] }> => {
|
|
578
|
+
if (!this.user) {
|
|
579
|
+
throw new NotAuthenticatedError();
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
const stampedRequest = await this.turnkeyClient.stampSignRawPayload({
|
|
583
|
+
organizationId: this.user.orgId,
|
|
584
|
+
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
585
|
+
timestampMs: Date.now().toString(),
|
|
586
|
+
parameters: {
|
|
587
|
+
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
588
|
+
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
589
|
+
payload: MFA_PAYLOAD.VERIFY,
|
|
590
|
+
signWith: this.user.address,
|
|
591
|
+
},
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
return this.request("/v1/auth-verify-multi-factor", {
|
|
595
|
+
stampedRequest,
|
|
596
|
+
multiFactorId: params.multiFactorId,
|
|
597
|
+
multiFactorCode: params.multiFactorCode,
|
|
598
|
+
});
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Removes existing MFA factors by ID.
|
|
603
|
+
*
|
|
604
|
+
* @param {RemoveMfaParams} params The parameters specifying which factors to disable
|
|
605
|
+
* @returns {Promise<{ multiFactors: MfaFactor[] }>} A promise that resolves to the updated list of MFA factors
|
|
606
|
+
* @throws {NotAuthenticatedError} If no user is authenticated
|
|
607
|
+
*/
|
|
608
|
+
public removeMfa = async (
|
|
609
|
+
params: RemoveMfaParams
|
|
610
|
+
): Promise<{ multiFactors: MfaFactor[] }> => {
|
|
611
|
+
if (!this.user) {
|
|
612
|
+
throw new NotAuthenticatedError();
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const stampedRequest = await this.turnkeyClient.stampSignRawPayload({
|
|
616
|
+
organizationId: this.user.orgId,
|
|
617
|
+
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
618
|
+
timestampMs: Date.now().toString(),
|
|
619
|
+
parameters: {
|
|
620
|
+
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
621
|
+
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
622
|
+
payload: MFA_PAYLOAD.DELETE,
|
|
623
|
+
signWith: this.user.address,
|
|
624
|
+
},
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
return this.request("/v1/auth-delete-multi-factors", {
|
|
628
|
+
stampedRequest,
|
|
629
|
+
multiFactorIds: params.multiFactorIds,
|
|
630
|
+
});
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Validates multiple MFA factors using the provided encrypted payload and MFA codes.
|
|
635
|
+
*
|
|
636
|
+
* @param {ValidateMultiFactorsParams} params The validation parameters
|
|
637
|
+
* @returns {Promise<{ bundle: string }>} A promise that resolves to an object containing the credential bundle
|
|
638
|
+
* @throws {Error} If no credential bundle is returned from the server
|
|
639
|
+
*/
|
|
640
|
+
public validateMultiFactors = async (
|
|
641
|
+
params: ValidateMultiFactorsParams
|
|
642
|
+
): Promise<{ bundle: string }> => {
|
|
643
|
+
// Send the encryptedPayload plus TOTP codes, etc:
|
|
644
|
+
const response = await this.request("/v1/auth-validate-multi-factors", {
|
|
645
|
+
encryptedPayload: params.encryptedPayload,
|
|
646
|
+
multiFactors: params.multiFactors,
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
// The server is expected to return the *decrypted* payload in `response.payload.credentialBundle`
|
|
650
|
+
if (!response.payload || !response.payload.credentialBundle) {
|
|
651
|
+
throw new Error(
|
|
652
|
+
"Request to validateMultiFactors did not return a credential bundle"
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
return {
|
|
657
|
+
bundle: response.payload.credentialBundle,
|
|
658
|
+
};
|
|
659
|
+
};
|
|
660
|
+
|
|
539
661
|
// #endregion
|
|
540
662
|
|
|
541
663
|
// #region PRIVATE METHODS
|
package/src/client/index.ts
CHANGED
|
@@ -17,25 +17,12 @@ import type {
|
|
|
17
17
|
OauthConfig,
|
|
18
18
|
OtpParams,
|
|
19
19
|
User,
|
|
20
|
-
MfaFactor,
|
|
21
|
-
EnableMfaParams,
|
|
22
|
-
EnableMfaResult,
|
|
23
|
-
VerifyMfaParams,
|
|
24
|
-
RemoveMfaParams,
|
|
25
20
|
SubmitOtpCodeResponse,
|
|
26
|
-
ValidateMultiFactorsParams,
|
|
27
21
|
} from "./types.js";
|
|
28
|
-
import { MfaRequiredError
|
|
22
|
+
import { MfaRequiredError } from "../errors.js";
|
|
29
23
|
import { parseMfaError } from "../utils/parseMfaError.js";
|
|
30
24
|
|
|
31
25
|
const CHECK_CLOSE_INTERVAL = 500;
|
|
32
|
-
const MFA_PAYLOAD = {
|
|
33
|
-
GET: "get_mfa",
|
|
34
|
-
ADD: "add_mfa",
|
|
35
|
-
DELETE: "delete_mfas",
|
|
36
|
-
VERIFY: "verify_mfa",
|
|
37
|
-
LIST: "list_mfas",
|
|
38
|
-
};
|
|
39
26
|
|
|
40
27
|
export const AlchemySignerClientParamsSchema = z.object({
|
|
41
28
|
connection: ConnectionConfigSchema,
|
|
@@ -722,169 +709,6 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
|
|
|
722
709
|
const nonce = this.getOauthNonce(publicKey);
|
|
723
710
|
return this.request("/v1/prepare-oauth", { nonce });
|
|
724
711
|
};
|
|
725
|
-
|
|
726
|
-
/**
|
|
727
|
-
* Retrieves the list of MFA factors configured for the current user.
|
|
728
|
-
*
|
|
729
|
-
* @returns {Promise<{ multiFactors: MfaFactor[] }>} A promise that resolves to an array of configured MFA factors
|
|
730
|
-
* @throws {NotAuthenticatedError} If no user is authenticated
|
|
731
|
-
*/
|
|
732
|
-
public override getMfaFactors = async (): Promise<{
|
|
733
|
-
multiFactors: MfaFactor[];
|
|
734
|
-
}> => {
|
|
735
|
-
if (!this.user) {
|
|
736
|
-
throw new NotAuthenticatedError();
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
const stampedRequest = await this.turnkeyClient.stampSignRawPayload({
|
|
740
|
-
organizationId: this.user.orgId,
|
|
741
|
-
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
742
|
-
timestampMs: Date.now().toString(),
|
|
743
|
-
parameters: {
|
|
744
|
-
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
745
|
-
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
746
|
-
payload: MFA_PAYLOAD.LIST,
|
|
747
|
-
signWith: this.user.address,
|
|
748
|
-
},
|
|
749
|
-
});
|
|
750
|
-
|
|
751
|
-
return this.request("/v1/auth-list-multi-factors", {
|
|
752
|
-
stampedRequest,
|
|
753
|
-
});
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
/**
|
|
757
|
-
* Initiates the setup of a new MFA factor for the current user. Mfa will need to be verified before it is active.
|
|
758
|
-
*
|
|
759
|
-
* @param {EnableMfaParams} params The parameters required to enable a new MFA factor
|
|
760
|
-
* @returns {Promise<EnableMfaResult>} A promise that resolves to the factor setup information
|
|
761
|
-
* @throws {NotAuthenticatedError} If no user is authenticated
|
|
762
|
-
* @throws {Error} If an unsupported factor type is provided
|
|
763
|
-
*/
|
|
764
|
-
public override addMfa = async (
|
|
765
|
-
params: EnableMfaParams
|
|
766
|
-
): Promise<EnableMfaResult> => {
|
|
767
|
-
if (!this.user) {
|
|
768
|
-
throw new NotAuthenticatedError();
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
const stampedRequest = await this.turnkeyClient.stampSignRawPayload({
|
|
772
|
-
organizationId: this.user.orgId,
|
|
773
|
-
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
774
|
-
timestampMs: Date.now().toString(),
|
|
775
|
-
parameters: {
|
|
776
|
-
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
777
|
-
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
778
|
-
payload: MFA_PAYLOAD.ADD,
|
|
779
|
-
signWith: this.user.address,
|
|
780
|
-
},
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
switch (params.multiFactorType) {
|
|
784
|
-
case "totp":
|
|
785
|
-
return this.request("/v1/auth-request-multi-factor", {
|
|
786
|
-
stampedRequest,
|
|
787
|
-
multiFactorType: params.multiFactorType,
|
|
788
|
-
});
|
|
789
|
-
default:
|
|
790
|
-
throw new Error(
|
|
791
|
-
`Unsupported MFA factor type: ${params.multiFactorType}`
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
|
-
};
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Verifies a newly created MFA factor to complete the setup process.
|
|
798
|
-
*
|
|
799
|
-
* @param {VerifyMfaParams} params The parameters required to verify the MFA factor
|
|
800
|
-
* @returns {Promise<{ multiFactors: MfaFactor[] }>} A promise that resolves to the updated list of MFA factors
|
|
801
|
-
* @throws {NotAuthenticatedError} If no user is authenticated
|
|
802
|
-
*/
|
|
803
|
-
public override verifyMfa = async (
|
|
804
|
-
params: VerifyMfaParams
|
|
805
|
-
): Promise<{ multiFactors: MfaFactor[] }> => {
|
|
806
|
-
if (!this.user) {
|
|
807
|
-
throw new NotAuthenticatedError();
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
const stampedRequest = await this.turnkeyClient.stampSignRawPayload({
|
|
811
|
-
organizationId: this.user.orgId,
|
|
812
|
-
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
813
|
-
timestampMs: Date.now().toString(),
|
|
814
|
-
parameters: {
|
|
815
|
-
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
816
|
-
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
817
|
-
payload: MFA_PAYLOAD.VERIFY,
|
|
818
|
-
signWith: this.user.address,
|
|
819
|
-
},
|
|
820
|
-
});
|
|
821
|
-
|
|
822
|
-
return this.request("/v1/auth-verify-multi-factor", {
|
|
823
|
-
stampedRequest,
|
|
824
|
-
multiFactorId: params.multiFactorId,
|
|
825
|
-
multiFactorCode: params.multiFactorCode,
|
|
826
|
-
});
|
|
827
|
-
};
|
|
828
|
-
|
|
829
|
-
/**
|
|
830
|
-
* Removes existing MFA factors by ID.
|
|
831
|
-
*
|
|
832
|
-
* @param {RemoveMfaParams} params The parameters specifying which factors to disable
|
|
833
|
-
* @returns {Promise<{ multiFactors: MfaFactor[] }>} A promise that resolves to the updated list of MFA factors
|
|
834
|
-
* @throws {NotAuthenticatedError} If no user is authenticated
|
|
835
|
-
*/
|
|
836
|
-
public override removeMfa = async (
|
|
837
|
-
params: RemoveMfaParams
|
|
838
|
-
): Promise<{ multiFactors: MfaFactor[] }> => {
|
|
839
|
-
if (!this.user) {
|
|
840
|
-
throw new NotAuthenticatedError();
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
const stampedRequest = await this.turnkeyClient.stampSignRawPayload({
|
|
844
|
-
organizationId: this.user.orgId,
|
|
845
|
-
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
846
|
-
timestampMs: Date.now().toString(),
|
|
847
|
-
parameters: {
|
|
848
|
-
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
|
|
849
|
-
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
850
|
-
payload: MFA_PAYLOAD.DELETE,
|
|
851
|
-
signWith: this.user.address,
|
|
852
|
-
},
|
|
853
|
-
});
|
|
854
|
-
|
|
855
|
-
return this.request("/v1/auth-delete-multi-factors", {
|
|
856
|
-
stampedRequest,
|
|
857
|
-
multiFactorIds: params.multiFactorIds,
|
|
858
|
-
});
|
|
859
|
-
};
|
|
860
|
-
|
|
861
|
-
/**
|
|
862
|
-
* Validates multiple MFA factors using the provided encrypted payload and MFA codes.
|
|
863
|
-
*
|
|
864
|
-
* @param {ValidateMultiFactorsParams} params The validation parameters
|
|
865
|
-
* @returns {Promise<{ bundle: string }>} A promise that resolves to an object containing the credential bundle
|
|
866
|
-
* @throws {Error} If no credential bundle is returned from the server
|
|
867
|
-
*/
|
|
868
|
-
public override async validateMultiFactors(
|
|
869
|
-
params: ValidateMultiFactorsParams
|
|
870
|
-
): Promise<{ bundle: string }> {
|
|
871
|
-
// Send the encryptedPayload plus TOTP codes, etc:
|
|
872
|
-
const response = await this.request("/v1/auth-validate-multi-factors", {
|
|
873
|
-
encryptedPayload: params.encryptedPayload,
|
|
874
|
-
multiFactors: params.multiFactors,
|
|
875
|
-
});
|
|
876
|
-
|
|
877
|
-
// The server is expected to return the *decrypted* payload in `response.payload.credentialBundle`
|
|
878
|
-
if (!response.payload || !response.payload.credentialBundle) {
|
|
879
|
-
throw new Error(
|
|
880
|
-
"Request to validateMultiFactors did not return a credential bundle"
|
|
881
|
-
);
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
return {
|
|
885
|
-
bundle: response.payload.credentialBundle,
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
712
|
}
|
|
889
713
|
|
|
890
714
|
/**
|
package/src/client/types.ts
CHANGED
|
@@ -208,7 +208,7 @@ export type SignerEndpoints = [
|
|
|
208
208
|
stampedRequest: TSignedRequest;
|
|
209
209
|
multiFactorType: MultiFactorType;
|
|
210
210
|
};
|
|
211
|
-
Response:
|
|
211
|
+
Response: AddMfaResult;
|
|
212
212
|
},
|
|
213
213
|
{
|
|
214
214
|
Route: "/v1/auth-verify-multi-factor";
|
|
@@ -287,11 +287,11 @@ export type MfaFactor = {
|
|
|
287
287
|
|
|
288
288
|
type MultiFactorType = "totp";
|
|
289
289
|
|
|
290
|
-
export type
|
|
290
|
+
export type AddMfaParams = {
|
|
291
291
|
multiFactorType: MultiFactorType;
|
|
292
292
|
};
|
|
293
293
|
|
|
294
|
-
export type
|
|
294
|
+
export type AddMfaResult = {
|
|
295
295
|
multiFactorType: MultiFactorType;
|
|
296
296
|
multiFactorId: string;
|
|
297
297
|
multiFactorTotpUrl: string;
|
|
@@ -308,10 +308,7 @@ export type RemoveMfaParams = {
|
|
|
308
308
|
|
|
309
309
|
export type ValidateMultiFactorsParams = {
|
|
310
310
|
encryptedPayload: string;
|
|
311
|
-
multiFactors:
|
|
312
|
-
multiFactorId: string;
|
|
313
|
-
multiFactorCode: string;
|
|
314
|
-
}>;
|
|
311
|
+
multiFactors: VerifyMfaParams[];
|
|
315
312
|
};
|
|
316
313
|
|
|
317
314
|
export type MfaChallenge = {
|
package/src/index.ts
CHANGED