@account-kit/signer 4.61.0 → 4.62.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 +57 -1
- package/dist/esm/base.js +76 -16
- package/dist/esm/base.js.map +1 -1
- package/dist/esm/client/base.d.ts +45 -7
- package/dist/esm/client/base.js +128 -29
- package/dist/esm/client/base.js.map +1 -1
- package/dist/esm/client/types.d.ts +35 -0
- package/dist/esm/client/types.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 +57 -1
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/client/base.d.ts +45 -7
- package/dist/types/client/base.d.ts.map +1 -1
- package/dist/types/client/types.d.ts +35 -0
- package/dist/types/client/types.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -6
- package/src/base.ts +109 -12
- package/src/client/base.ts +153 -24
- package/src/client/types.ts +38 -0
- package/src/version.ts +1 -1
package/dist/esm/base.d.ts
CHANGED
|
@@ -25,6 +25,9 @@ type GetUserParams = {
|
|
|
25
25
|
type: "phone";
|
|
26
26
|
value: string;
|
|
27
27
|
};
|
|
28
|
+
type VerificationParams = {
|
|
29
|
+
verificationCode: string;
|
|
30
|
+
};
|
|
28
31
|
/**
|
|
29
32
|
* Base abstract class for Alchemy Signer, providing authentication and session management for smart accounts.
|
|
30
33
|
* Implements the `SmartAccountAuthenticator` interface and handles various signer events.
|
|
@@ -375,7 +378,31 @@ export declare abstract class BaseAlchemySigner<TClient extends BaseSignerClient
|
|
|
375
378
|
getUser(params: GetUserParams): Promise<{
|
|
376
379
|
orgId: string;
|
|
377
380
|
} | null>;
|
|
378
|
-
|
|
381
|
+
/**
|
|
382
|
+
* Sets the email for the authenticated user, allowing them to login with that
|
|
383
|
+
* email.
|
|
384
|
+
*
|
|
385
|
+
* @deprecated You must contact Alchemy to enable this feature for your team,
|
|
386
|
+
* as there are important security considerations. In particular, you must not
|
|
387
|
+
* call this without first validating that the user owns this email account.
|
|
388
|
+
* It is recommended to now use the email verification flow instead.
|
|
389
|
+
*
|
|
390
|
+
* @param {string} email The email to set for the user
|
|
391
|
+
* @returns {Promise<string>} A promise that resolves to the updated email address
|
|
392
|
+
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
393
|
+
*/
|
|
394
|
+
setEmail(email: string): Promise<string>;
|
|
395
|
+
/**
|
|
396
|
+
* Uses a verification code to update a user's email, allowing them to login
|
|
397
|
+
* with that email. `sendVerificationCode` should be called first to obtain
|
|
398
|
+
* the code.
|
|
399
|
+
*
|
|
400
|
+
* @param {VerificationParams} params An object containing the verification code
|
|
401
|
+
* @param {string} params.verificationCode The OTP verification code
|
|
402
|
+
* @returns {Promise<string>} A promise that resolves to the updated email address
|
|
403
|
+
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
404
|
+
*/
|
|
405
|
+
setEmail(params: VerificationParams): Promise<string>;
|
|
379
406
|
/**
|
|
380
407
|
* Removes the email for the authenticated user, disallowing them from login with that email.
|
|
381
408
|
*
|
|
@@ -383,6 +410,35 @@ export declare abstract class BaseAlchemySigner<TClient extends BaseSignerClient
|
|
|
383
410
|
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
384
411
|
*/
|
|
385
412
|
removeEmail: () => Promise<void>;
|
|
413
|
+
/**
|
|
414
|
+
* Sets the phone number for the authenticated user, allowing them to login with that
|
|
415
|
+
* phone number. `sendVerificationCode` should be called first to obtain the code.
|
|
416
|
+
*
|
|
417
|
+
* @param {VerificationParams} params An object containing the verification code
|
|
418
|
+
* @param {string} params.verificationCode The OTP verification code
|
|
419
|
+
* @returns {Promise<void>} A promise that resolves when the phone number is set
|
|
420
|
+
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
421
|
+
*/
|
|
422
|
+
setPhoneNumber: (params: VerificationParams) => Promise<void>;
|
|
423
|
+
/**
|
|
424
|
+
* Removes the phone number for the authenticated user, disallowing them from login with that phone number.
|
|
425
|
+
*
|
|
426
|
+
* @returns {Promise<void>} A promise that resolves when the phone number is removed
|
|
427
|
+
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
428
|
+
*/
|
|
429
|
+
removePhoneNumber: () => Promise<void>;
|
|
430
|
+
/**
|
|
431
|
+
* Initiates an OTP (One-Time Password) verification process for a user contact.
|
|
432
|
+
* Use this method before calling `setEmail` with verification code to verify ownership of the email address.
|
|
433
|
+
*
|
|
434
|
+
* @param {"email" | "sms"} type The type of OTP to send, either "email" or "sms"
|
|
435
|
+
* @param {string} contact The email address or phone number to send the OTP to
|
|
436
|
+
* @returns {Promise<{ otpId: string }>} A promise that resolves to an object containing the OTP ID
|
|
437
|
+
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
438
|
+
*/
|
|
439
|
+
sendVerificationCode: (type: "email" | "sms", contact: string) => Promise<{
|
|
440
|
+
otpId: string;
|
|
441
|
+
}>;
|
|
386
442
|
/**
|
|
387
443
|
* Adds a passkey to the user's account
|
|
388
444
|
*
|
package/dist/esm/base.js
CHANGED
|
@@ -565,38 +565,75 @@ export class BaseAlchemySigner {
|
|
|
565
565
|
};
|
|
566
566
|
}
|
|
567
567
|
});
|
|
568
|
-
|
|
569
|
-
*
|
|
570
|
-
* email.
|
|
568
|
+
/**
|
|
569
|
+
* Removes the email for the authenticated user, disallowing them from login with that email.
|
|
571
570
|
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
|
|
571
|
+
* @returns {Promise<void>} A promise that resolves when the email is removed
|
|
572
|
+
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
573
|
+
*/
|
|
574
|
+
Object.defineProperty(this, "removeEmail", {
|
|
575
|
+
enumerable: true,
|
|
576
|
+
configurable: true,
|
|
577
|
+
writable: true,
|
|
578
|
+
value: SignerLogger.profiled("BaseAlchemySigner.removeEmail", async () => {
|
|
579
|
+
await this.inner.removeEmail();
|
|
580
|
+
})
|
|
581
|
+
});
|
|
582
|
+
/**
|
|
583
|
+
* Sets the phone number for the authenticated user, allowing them to login with that
|
|
584
|
+
* phone number. `sendVerificationCode` should be called first to obtain the code.
|
|
575
585
|
*
|
|
576
|
-
* @param {
|
|
577
|
-
* @
|
|
586
|
+
* @param {VerificationParams} params An object containing the verification code
|
|
587
|
+
* @param {string} params.verificationCode The OTP verification code
|
|
588
|
+
* @returns {Promise<void>} A promise that resolves when the phone number is set
|
|
578
589
|
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
579
590
|
*/
|
|
580
|
-
Object.defineProperty(this, "
|
|
591
|
+
Object.defineProperty(this, "setPhoneNumber", {
|
|
581
592
|
enumerable: true,
|
|
582
593
|
configurable: true,
|
|
583
594
|
writable: true,
|
|
584
|
-
value: SignerLogger.profiled("BaseAlchemySigner.
|
|
585
|
-
|
|
595
|
+
value: SignerLogger.profiled("BaseAlchemySigner.setPhoneNumber", async ({ verificationCode }) => {
|
|
596
|
+
const { otpId } = this.store.getState();
|
|
597
|
+
if (!otpId) {
|
|
598
|
+
throw new Error("Missing OTP ID");
|
|
599
|
+
}
|
|
600
|
+
await this.inner.setPhoneNumber({
|
|
601
|
+
id: otpId,
|
|
602
|
+
code: verificationCode,
|
|
603
|
+
});
|
|
586
604
|
})
|
|
587
605
|
});
|
|
588
606
|
/**
|
|
589
|
-
* Removes the
|
|
607
|
+
* Removes the phone number for the authenticated user, disallowing them from login with that phone number.
|
|
590
608
|
*
|
|
591
|
-
* @returns {Promise<void>} A promise that resolves when the
|
|
609
|
+
* @returns {Promise<void>} A promise that resolves when the phone number is removed
|
|
592
610
|
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
593
611
|
*/
|
|
594
|
-
Object.defineProperty(this, "
|
|
612
|
+
Object.defineProperty(this, "removePhoneNumber", {
|
|
595
613
|
enumerable: true,
|
|
596
614
|
configurable: true,
|
|
597
615
|
writable: true,
|
|
598
|
-
value: SignerLogger.profiled("BaseAlchemySigner.
|
|
599
|
-
|
|
616
|
+
value: SignerLogger.profiled("BaseAlchemySigner.removePhoneNumber", async () => {
|
|
617
|
+
await this.inner.removePhoneNumber();
|
|
618
|
+
})
|
|
619
|
+
});
|
|
620
|
+
/**
|
|
621
|
+
* Initiates an OTP (One-Time Password) verification process for a user contact.
|
|
622
|
+
* Use this method before calling `setEmail` with verification code to verify ownership of the email address.
|
|
623
|
+
*
|
|
624
|
+
* @param {"email" | "sms"} type The type of OTP to send, either "email" or "sms"
|
|
625
|
+
* @param {string} contact The email address or phone number to send the OTP to
|
|
626
|
+
* @returns {Promise<{ otpId: string }>} A promise that resolves to an object containing the OTP ID
|
|
627
|
+
* @throws {NotAuthenticatedError} If the user is not authenticated
|
|
628
|
+
*/
|
|
629
|
+
Object.defineProperty(this, "sendVerificationCode", {
|
|
630
|
+
enumerable: true,
|
|
631
|
+
configurable: true,
|
|
632
|
+
writable: true,
|
|
633
|
+
value: SignerLogger.profiled("BaseAlchemySigner.sendVerificationCode", async (type, contact) => {
|
|
634
|
+
const { otpId } = await this.inner.initOtp(type, contact);
|
|
635
|
+
this.store.setState({ otpId });
|
|
636
|
+
return { otpId };
|
|
600
637
|
})
|
|
601
638
|
});
|
|
602
639
|
/**
|
|
@@ -1431,6 +1468,29 @@ export class BaseAlchemySigner {
|
|
|
1431
1468
|
};
|
|
1432
1469
|
})(params);
|
|
1433
1470
|
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Implementation for setEmail method.
|
|
1473
|
+
*
|
|
1474
|
+
* @param {string | VerificationParams} params An object containing the verificationCode (or simply an email for legacy usage)
|
|
1475
|
+
* @returns {Promise<void>} A promise that resolves when the email is set
|
|
1476
|
+
*/
|
|
1477
|
+
async setEmail(params) {
|
|
1478
|
+
return SignerLogger.profiled("BaseAlchemySigner.setEmail", async (params) => {
|
|
1479
|
+
if (typeof params === "string") {
|
|
1480
|
+
// Deprecated usage for backwards compatibility.
|
|
1481
|
+
const email = params;
|
|
1482
|
+
return await this.inner.setEmail(email);
|
|
1483
|
+
}
|
|
1484
|
+
const { otpId } = this.store.getState();
|
|
1485
|
+
if (!otpId) {
|
|
1486
|
+
throw new Error("Missing OTP ID");
|
|
1487
|
+
}
|
|
1488
|
+
return await this.inner.setEmail({
|
|
1489
|
+
id: otpId,
|
|
1490
|
+
code: params.verificationCode,
|
|
1491
|
+
});
|
|
1492
|
+
})(params);
|
|
1493
|
+
}
|
|
1434
1494
|
handleMfaRequired(encryptedPayload, multiFactors) {
|
|
1435
1495
|
// Store complete MFA context in the temporary session
|
|
1436
1496
|
const tempSession = this.sessionManager.getTemporarySession();
|