Account Types
The examples below use the useWallet hook from @aptos-labs/wallet-adapter-react (version 4.0.0 or later).
See Connecting to Petra for setup instructions.
Petra supports several account types. Depending on the account type, the wallet returns different instances of Signature, PublicKey, and AccountAuthenticator when you sign transactions, request connections, or sign messages. Your dApp should handle these types gracefully.
Handling Account Types
Use the instanceof operator to differentiate between account types:
import { useWallet } from "@aptos-labs/wallet-adapter-react";
import {
Ed25519PublicKey,
AnyPublicKey,
KeylessPublicKey,
Secp256k1PublicKey,
} from "@aptos-labs/ts-sdk";
function AccountInfo() {
const { account } = useWallet();
if (!account?.publicKey) {
return null;
}
if (account.publicKey instanceof Ed25519PublicKey) {
console.log("Account is an Ed25519 account");
} else if (account.publicKey instanceof AnyPublicKey) {
const innerPublicKey = account.publicKey.publicKey;
if (innerPublicKey instanceof KeylessPublicKey) {
console.log("Account is a Keyless account");
} else if (innerPublicKey instanceof Secp256k1PublicKey) {
console.log("Account is a Secp256k1 account");
}
}
}Ed25519
The majority of Petra accounts are Ed25519. These are created using:
- A private key
- A secret recovery phrase
- A hardware wallet (e.g. Ledger, Arculus)
| Return Type | Instance Type |
|---|---|
Signature | Ed25519Signature |
PublicKey | Ed25519PublicKey |
AccountAuthenticator | AccountAuthenticatorEd25519 |
Keyless
Keyless accounts are created through social logins:
- Sign in with Google
- Sign in with Apple
These use the generalized authentication scheme (opens in a new tab) and are represented as single key accounts.
| Return Type | Instance Type |
|---|---|
Signature | AnySignature |
PublicKey | AnyPublicKey |
AccountAuthenticator | AccountAuthenticatorSingleKey |
Secp256k1
A small number of accounts use Secp256k1, created from a private key. Like Keyless, these use the generalized authentication scheme (opens in a new tab) and are represented as single key accounts.
| Return Type | Instance Type |
|---|---|
Signature | AnySignature |
PublicKey | AnyPublicKey |
AccountAuthenticator | AccountAuthenticatorSingleKey |