Account Types
Petra supports a number of different account types, including: Secp256k1
, Ed25519
, and Keyless
. Depending on the account type, the wallet may return different information when you sign transactions, request connections, or
sign messages. This page will describe the different return types for each account type that the wallet may return. We recommend that all dApps should understand this behavior and handle it gracefully.
Ed25519
Majority of accounts that are created on Petra are Ed25519 accounts. These accounts are those that were created using:
- A private key
- A secret recovery phrase
- A hardware wallet (e.g. Ledger, Arculus, etc.)
When you sign a message, request a connection, or sign a transaction, the wallet will return Ed25519 instances of the Signature
, PublicKey
, and AccountAuthenticator
.
Return Type | Instance Type |
---|---|
Signature | Ed25519Signature |
PublicKey | Ed25519PublicKey |
AccountAuthenticator | AccountAuthenticatorEd25519 |
Keyless
Some accounts may be created as a Keyless account which are created using social logins:
- Sign in with Google
- Sign in with Apple
These accounts are represented as single key accounts which are use generalized authentication scheme (opens in a new tab) supporting functions schemes like Keyless.
When you sign a message, request a connection, or sign a transaction, the wallet will return single key instances of the Signature
, PublicKey
, and AccountAuthenticator
.
Return Type | Instance Type |
---|---|
Signature | AnySignature |
PublicKey | AnyPublicKey |
AccountAuthenticator | AccountAuthenticatorSingleKey |
Secp256k1
A small number of accounts are created as Secp256k1 accounts which are created using a private key.
Likewise to Keyless, Secp256k1 accounts are represented as single key accounts which are use generalized authentication scheme (opens in a new tab).
When you sign a message, request a connection, or sign a transaction, the wallet will return single key instances of the Signature
, PublicKey
, and AccountAuthenticator
.
Return Type | Instance Type |
---|---|
Signature | AnySignature |
PublicKey | AnyPublicKey |
AccountAuthenticator | AccountAuthenticatorSingleKey |
Wallet Adapter Supported
Given that you are on a versions >=4.0.0
of the @aptos-labs/wallet-adapter-react
package, calling functions such as signMessage
, signTransaction
, or connect
will return the appropriate instance of the Signature
, PublicKey
, and AccountAuthenticator
. You can handle these
different account instance types by using the instanceof
operator in your code.
const { account } = useWallet();
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');
}
}