SubAccount
A sub-account: a smart account owned by a wallet’s main account, for wallet_addSubAccount
(ERC-7895, a draft). The module types the account an app asks the wallet to add, and the one
the wallet tracks.
import { Effect } from "effect";import { type SubAccount, Wallet } from "@ethect/core/rpc";
const account: SubAccount.Payload = { type: "create", keys: [{ type: "webauthn-p256", publicKey: `0x${"04".repeat(64)}` }],};
const added = Wallet.addSubAccount({ version: "1", account }).pipe( // subAccount: SubAccount.SubAccount Effect.map((subAccount) => subAccount.address),);Schemas
Section titled “Schemas”| Schema | Type | Describes | Used by |
|---|---|---|---|
SubAccount.payloadSchema |
SubAccount.Payload |
the account to add, in one of three shapes | passed to Wallet.addSubAccount |
SubAccount.schema |
SubAccount.SubAccount |
a sub-account the wallet tracks | returned by Wallet.addSubAccount |
SubAccount.keySchema |
SubAccount.Key |
a key that signs for a sub-account | the keys of a "create" payload |
Payload fields
Section titled “Payload fields”SubAccount.Payload is a union of three shapes, told apart by type.
type |
Field | Type | Notes |
|---|---|---|---|
"create" |
keys |
ReadonlyArray<SubAccount.Key> (optional) |
the app’s keys, to be signers of the new account |
"deployed" |
address |
Address |
an account already deployed |
"deployed" |
chainId |
number (optional) |
|
"undeployed" |
address |
Address |
an account not deployed yet |
"undeployed" |
chainId |
number (optional) |
|
"undeployed" |
factory |
Address |
the contract that deploys the account |
"undeployed" |
factoryData |
Hex |
the calldata for factory |
Key fields
Section titled “Key fields”SubAccount.Key, a key that signs for a sub-account.
| Field | Type | Notes |
|---|---|---|
publicKey |
Hex |
what it holds depends on type |
type |
"address" | "p256" | "webcrypto-p256" | "webauthn-p256" |
the kind of key |
import type { SubAccount } from "@ethect/core/rpc";
const key: SubAccount.Key = { type: "p256", publicKey: `0x${"04".repeat(32)}` };const payload: SubAccount.Payload = { type: "create", keys: [key] };SubAccount fields
Section titled “SubAccount fields”SubAccount.SubAccount.
| Field | Type | Notes |
|---|---|---|
address |
Address |
the sub-account |
factory |
Address (optional) |
present where the wallet knows how to deploy the account |
factoryData |
Hex (optional) |
the calldata for factory |
Behavior
Section titled “Behavior”typenarrows the payload. TypeScript acceptsfactoryonly withtype: "undeployed", andkeysonly withtype: "create".- Keys are optional. By the ERC, a wallet that gets no
keyscreates and manages the signing key of the new account itself. - The chain id is a
number.chainId: 8453is sent as"0x2105". - A draft. ERC-7895 is not final: the shapes can change, and a wallet may not serve the method.