RNAlchemySignerSingleton

Defined in: account-kit/rn-signer/src/signer.ts:22

Extends

Properties

PropertyTypeDescription

addMfa

(params) => Promise<AddMfaResult>

Initiates the setup of a new MFA factor for the current user. The factor will need to be verified using verifyMfa before it becomes active.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.addMfa({ multiFactorType: "totp" });
15// Result contains multiFactorTotpUrl to display as QR code

Throws

If no user is authenticated

addOauthProvider

(args) => Promise<OauthProviderInfo>

Handles OAuth authentication by augmenting the provided arguments with a type and performing authentication based on the OAuth mode (either using redirect or popup).

addPasskey

(params?) => Promise<string[]>

Adds a passkey to the user’s account

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.addPasskey()

authenticate

(params) => Promise<User>

Authenticate a user with either an email or a passkey and create a session for that user

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.authenticate({
15 type: "email",
16 email: "[email protected]",
17});

disconnect

() => Promise<void>

Clear a user session and log them out

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14await signer.disconnect();

exportWallet

(params?) => Promise<string>

Used to export the wallet for a given user If the user is authenticated with an Email, this will return a seed phrase If the user is authenticated with a Passkey, this will return a private key

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14// the params passed to this are different based on the specific signer
15const result = signer.exportWallet()

Param

exportWallet parameters

fetchConfig

() => Promise<SignerConfig>

getAddress

() => Promise<`0x${string}`>

Retrieves the address of the current user by calling the whoami method on this.inner.

getAuthDetails

() => Promise<User>

Gets the current logged in user If a user has an ongoing session, it will use that session and try to authenticate

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14// throws if not logged in
15const user = await signer.getAuthDetails();

Throws

if there is no user logged in

getConfig

() => Promise<SignerConfig>

Returns the signer configuration while fetching it if it’s not already initialized.

getMfaFactors

() => Promise<{ multiFactors: MfaFactor[]; }>

Retrieves the list of MFA factors configured for the current user.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const { multiFactors } = await signer.getMfaFactors();

Throws

If no user is authenticated

getMfaStatus

() => object

Gets the current MFA status

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const mfaStatus = signer.getMfaStatus();
15if (mfaStatus === AlchemyMfaStatus.REQUIRED) {
16 // Handle MFA requirement
17}

getPasskeyStatus

() => Promise<{ isPasskeyAdded: boolean; }>

initConfig

() => Promise<SignerConfig>

inner

RNSignerClient

listAuthMethods

() => Promise<AuthMethods>

Retrieves a list of auth methods associated with the authenticated user.

Throws

Thrown if the user is not authenticated

on

<E>(event, listener) => () => void

Allows you to subscribe to events emitted by the signer

preparePopupOauth

() => Promise<OauthConfig>

Prepares the config needed to use popup-based OAuth login. This must be called before calling .authenticate with params { type: "oauth", mode: "popup" }, and is recommended to be called on page load.

This method exists because browsers may prevent popups from opening unless triggered by user interaction, and so the OAuth config must already have been fetched at the time a user clicks a social login button.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14await signer.preparePopupOauth();

removeEmail

() => Promise<void>

Removes the email for the authenticated user, disallowing them from login with that email.

Throws

If the user is not authenticated

removeMfa

(params) => Promise<{ multiFactors: MfaFactor[]; }>

Removes existing MFA factors by their IDs.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.removeMfa({
15 multiFactorIds: ["factor-id-1", "factor-id-2"]
16});

Throws

If no user is authenticated

removeOauthProvider

(providerId) => Promise<void>

Removes an OAuth provider by its ID if the user is authenticated.

Throws

Thrown if the user is not authenticated

removePasskey

(authenticatorId) => Promise<void>

Removes a passkey from a user’s account

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const authMethods = await signer.listAuthMethods();
15const passkey = authMethods.passkeys[0];
16
17const result = await signer.removePasskey(passkey.authenticatorId);

removePhoneNumber

() => Promise<void>

Removes the phone number for the authenticated user, disallowing them from login with that phone number.

Throws

If the user is not authenticated

sendVerificationCode

(type, contact) => Promise<{ otpId: string; }>

Initiates an OTP (One-Time Password) verification process for a user contact. Use this method before calling setEmail with verification code to verify ownership of the email address.

Throws

If the user is not authenticated

setPhoneNumber

(params) => Promise<void>

Sets the phone number for the authenticated user, allowing them to login with that phone number. sendVerificationCode should be called first to obtain the code.

Throws

If the user is not authenticated

signAuthorization

(unsignedAuthorization) => Promise<SignedAuthorization<number>>

Signs an EIP-7702 Authorization and then returns the authorization with the signature.

Example

import { 
class AlchemyWebSigner

A SmartAccountSigner that can be used with any SmartContractAccount

AlchemyWebSigner
} from "@account-kit/signer";
const
const signer: AlchemyWebSigner
signer
= new
new AlchemyWebSigner(params: AlchemySignerParams): AlchemyWebSigner

Initializes an instance with the provided Alchemy signer parameters after parsing them with a schema.

AlchemyWebSigner
({
client: { connection: ({ apiKey: string; rpcUrl?: undefined; jwt?: undefined; } | { jwt: string; rpcUrl?: undefined; apiKey?: undefined; } | { rpcUrl: string; apiKey?: undefined; jwt?: undefined; } | { rpcUrl: string; jwt: string; apiKey?: undefined; }) & { chainAgnosticUrl?: string | undefined; }; iframeConfig: { iframeContainerId: string; iframeElementId?: string | undefined; }; rpId?: string | undefined; rootOrgId?: string | undefined; oauthCallbackUrl?: string | undefined; enablePopupOauth?: boolean | undefined; } | AlchemySignerWebClient
client
: {
connection: ({ apiKey: string; rpcUrl?: undefined; jwt?: undefined; } | { jwt: string; rpcUrl?: undefined; apiKey?: undefined; } | { rpcUrl: string; apiKey?: undefined; jwt?: undefined; } | { rpcUrl: string; jwt: string; apiKey?: undefined; }) & { chainAgnosticUrl?: string | undefined; }
connection
: {
rpcUrl: string
rpcUrl
: "/api/rpc",
},
iframeConfig: { iframeContainerId: string; }
iframeConfig
: {
iframeContainerId: string
iframeContainerId
: "alchemy-signer-iframe-container",
}, }, }); const
const tx: SignedAuthorization<number>
tx
= await
const signer: AlchemyWebSigner
signer
.
BaseAlchemySigner<AlchemySignerWebClient>.signAuthorization: (unsignedAuthorization: AuthorizationRequest<number>) => Promise<SignedAuthorization<number>>

Signs an EIP-7702 Authorization and then returns the authorization with the signature.

signAuthorization
({
contractAddress: `0x${string}`
contractAddress
: "0x1234123412341234123412341234123412341234",
chainId: number

Chain ID.

chainId
: 1,
nonce: number

Nonce of the EOA to delegate to.

nonce
: 0,
});

signerType

"alchemy-signer" | "rn-alchemy-signer"

signMessage

(msg) => Promise<`0x${string}`>

Signs a raw message after hashing it.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const signature = await signer.signMessage("Hello, world!");

signTransaction

<serializer, transaction>(transaction, options?) => Promise<IsNarrowable<TransactionSerialized<GetTransactionType<transaction>>, `0x${string}`> extends true ? TransactionSerialized<GetTransactionType<transaction>> : `0x${string}`>

Serializes a transaction, signs it with a raw message, and then returns the serialized transaction with the signature.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const tx = await signer.signTransaction({
15 to: "0x1234",
16 value: "0x1234",
17 data: "0x1234",
18});

signTypedData

<TTypedData, TPrimaryType>(params) => Promise<`0x${string}`>

Signs a typed message by first hashing it and then signing the hashed message using the signRawMessage method.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const signature = await signer.signTypedData({
15 domain: {},
16 types: {},
17 primaryType: "",
18 message: {},
19});

toSolanaSigner

() => SolanaSigner

Creates a new instance of SolanaSigner using the provided inner value. This requires the signer to be authenticated first

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const solanaSigner = signer.toSolanaSigner();

toViemAccount

() => object

This method lets you adapt your AlchemySigner to a viem LocalAccount, which will let you use the signer as an EOA directly.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const account = signer.toViemAccount();

Throws

if your signer is not authenticated

verifyMfa

(params) => Promise<{ multiFactors: MfaFactor[]; }>

Verifies a newly created MFA factor to complete the setup process.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.verifyMfa({
15 multiFactorId: "factor-id",
16 multiFactorCode: "123456" // 6-digit code from authenticator app
17});

Throws

If no user is authenticated

Methods

getUser()

Call Signature

1getUser(email): Promise<
2 | null
3 | {
4 orgId: string;
5}>;

Defined in: account-kit/signer/dist/types/base.d.ts:350

Unauthenticated call to look up a user’s organizationId by email

Deprecated

Use getUser({ type: “email”, value: email }) instead

Example
1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.getUser("[email protected]");
Parameters
ParameterTypeDescription

email

string

the email to lookup

Returns

Promise< | null | { orgId: string; }>

the organization id for the user if they exist

Inherited from
1BaseAlchemySigner.getUser;

Call Signature

1getUser(params): Promise<
2 | null
3 | {
4 orgId: string;
5}>;

Defined in: account-kit/signer/dist/types/base.d.ts:377

Unauthenticated call to look up a user’s organizationId by email or phone

Example
1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.getUser({ type: "email", value: "[email protected]" });
Parameters
ParameterType

params

GetUserParams

Returns

Promise< | null | { orgId: string; }>

the organization id for the user if they exist

Inherited from
1BaseAlchemySigner.getUser;

setEmail()

Call Signature

1setEmail(email): Promise<string>;

Defined in: account-kit/signer/dist/types/base.d.ts:393

Sets the email for the authenticated user, allowing them to login with that email.

Deprecated

You must contact Alchemy to enable this feature for your team, as there are important security considerations. In particular, you must not call this without first validating that the user owns this email account. It is recommended to now use the email verification flow instead.

Parameters
ParameterTypeDescription

email

string

The email to set for the user

Returns

Promise<string>

A promise that resolves to the updated email address

Throws

If the user is not authenticated

Inherited from
1BaseAlchemySigner.setEmail;

Call Signature

1setEmail(params): Promise<string>;

Defined in: account-kit/signer/dist/types/base.d.ts:404

Uses a verification code to update a user’s email, allowing them to login with that email. sendVerificationCode should be called first to obtain the code.

Parameters
ParameterTypeDescription

params

VerificationParams

An object containing the verification code

Returns

Promise<string>

A promise that resolves to the updated email address

Throws

If the user is not authenticated

Inherited from
1BaseAlchemySigner.setEmail;

validateMultiFactors()

1validateMultiFactors(params): Promise<User>;

Defined in: account-kit/signer/dist/types/base.d.ts:763

Validates MFA factors that were required during authentication. This function should be called after MFA is required and the user has provided their MFA code. It completes the authentication process by validating the MFA factors and completing the auth bundle.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14// After MFA is required and user provides code
15const user = await signer.validateMultiFactors({
16 multiFactorCode: "123456", // 6-digit code from authenticator app
17 multiFactorId: "factor-id",
18});

Parameters

ParameterTypeDescription

params

ValidateMultiFactorsArgs

Parameters for validating MFA factors

Returns

Promise<User>

A promise that resolves to the authenticated user

Throws

If there is no pending MFA context or if orgId is not found

Inherited from

1BaseAlchemySigner.validateMultiFactors;

getInstance()

1static getInstance(params): RNAlchemySignerSingleton;

Defined in: account-kit/rn-signer/src/signer.ts:49

Parameters

ParameterType

params

{ client: | RNSignerClient | { connection: | { apiKey: string; jwt?: undefined; rpcUrl?: undefined; } | { apiKey?: undefined; jwt: string; rpcUrl?: undefined; } | { apiKey?: undefined; jwt?: undefined; rpcUrl: string; } | { apiKey?: undefined; jwt: string; rpcUrl: string; } & object; oauthCallbackUrl?: string; rootOrgId?: string; rpId?: string; }; sessionConfig?: { expirationTimeMs?: number; sessionKey?: string; }; }

params.client

| RNSignerClient | { connection: | { apiKey: string; jwt?: undefined; rpcUrl?: undefined; } | { apiKey?: undefined; jwt: string; rpcUrl?: undefined; } | { apiKey?: undefined; jwt?: undefined; rpcUrl: string; } | { apiKey?: undefined; jwt: string; rpcUrl: string; } & object; oauthCallbackUrl?: string; rootOrgId?: string; rpId?: string; }

params.sessionConfig?

{ expirationTimeMs?: number; sessionKey?: string; }

params.sessionConfig.expirationTimeMs?

number

params.sessionConfig.sessionKey?

string

Returns

RNAlchemySignerSingleton