Accounts and identity primitives
The account model gives node-facing and transaction-facing code a shared way to identify accounts, use signer capabilities, and work with account records and data. It keeps readable account state separate from signing authority, so callers can inspect accounts without holding secret key material. For the identity and signer model, see Keys and signatures. For byte-level account state, see Account state and layouts.
Account identity
An account identity is a 32-byte public key that can move between byte form, base-58 address form, and the address type used by the Kit APIs. The identity value names an account, but it does not by itself grant permission to sign or change that account.
Public-key values
PublicKey is the common value for account addresses and program IDs. It accepts address, byte, and numeric forms, compares identities by their bytes, and exposes both base-58 and byte forms for node calls, program clients, and account-data codecs. Its address view also lets the same identity pass to Kit APIs and generated clients that use Kit address values.
The type also provides the fixed-width encoding needed by account layouts. Its checked decoder consumes one complete public-key value, while its unchecked decoder reads the first value from a larger byte buffer. This lets account-data readers decode an address without taking ownership of the surrounding layout. A public key can also verify a signature without exposing private signing material.
References: packages/…/publickey.ts• L23-58 packages/…/publickey.ts• L89-161 packages/…/publickey.ts• L164-194
Derived program addresses
Some accounts use identities derived from a program ID and seed values rather than from a private key. A program-derived address is owned and controlled through program rules, so callers must not treat every PublicKey as a signer-backed identity.
The identity API supports two derived-address patterns. A seed address combines a base public key with one seed and a program ID. A program address combines bounded seed input with a program ID and finds an address outside the Ed25519 curve. The resulting address identifies program state; it does not expose signing authority.
This diagram shows how account identity can come from a keypair or from program-controlled derivation.
flowchart LR
A[Keypair] --> B[PublicKey identity]
C[Base key, seed, program ID] --> B
D[Seeds, program ID] --> E[Program-derived address]
E --> B
B --> F[Account or program state]
References: packages/…/publickey.ts• L207-231 packages/…/publickey.ts• L232-315 packages/…/publickey.ts• L317-323
Signer capabilities
A signer capability is the authority to prove control of an account identity. The keypair model keeps this authority separate from the public identity and exposes it through message-signing and transaction-signing capabilities.
Keypair signers
Keypair represents an account identity together with its private signing material. It can be created from fresh random bytes, a seed, or a secret-key byte sequence. Its public address is available as both a PublicKey and a Kit-compatible address, while its signing methods can serve transaction APIs and generated program clients.
The same signer can sign arbitrary messages or transactions. It can also sign raw bytes and verify a signature with its public key. Callers that only need to name or inspect an account should use PublicKey instead of retaining a Keypair.
References: packages/…/keypair.ts• L16-42 packages/…/keypair.ts• L44-71 packages/…/keypair.ts• L74-111 packages/…/keypair.ts• L113-157
Account state model
An on-chain account combines ownership, balance, executable status, and program-defined data. The connection layer exposes this state in a common form so callers can read one account, read many accounts, query accounts owned by a program, or subscribe to account changes without knowing the data layout in advance.
Account records
home/…/connection.ts defines the shared account record used at the node boundary. AccountInfo<T> carries the program owner, balance, executable flag, account data, and optional rent information. KeyedAccountInfo adds the account address when a response must keep the identifier beside the state.
These records let the same account model support direct reads and collections of accounts. Program-account queries and account-change notifications use the keyed form because the address is needed to relate each state value to its source.
References: src/connection.ts• L2918-2937 src/connection.ts• L2885-2916
Account data forms
Account data can remain as raw bytes or arrive as data parsed by the node. Raw data preserves the original bytes for a client-side layout decoder. Parsed data carries a program name, a program-specific value, and the reported data space.
The selected form changes what a caller can read from data. A parsed-data request can fall back to base64 when the node has no matching parser, so consumers must inspect the returned form before they read program-specific fields. The byte layouts used to interpret raw data are described in Account state and layouts.
References: src/connection.ts• L69-80 src/connection.ts• L2715-2725 src/connection.ts• L3614-3643 src/connection.ts• L3824-3839
Account access
The connection API is the access point for account state. It supports single-account reads, multi-account reads, program-owned account queries, and change subscriptions. Query options control the requested data encoding, while filters limit which program-owned accounts the node returns.
The account read path turns a request into a node response and then exposes the selected account record to the caller. Optional response context lets callers relate the result to the node slot that produced it.
This diagram shows the shared path from an account request to usable account state.
flowchart LR
A[Account request] --> B[Connection API]
B --> C[Node response]
C --> D{Data form}
D --> E[Raw account bytes]
D --> F[Parsed account value]
E --> G[Caller]
F --> G
References: src/connection.ts• L3585-3643 src/connection.ts• L3665-3727 src/connection.ts• L3763-3817
Change checklist
When these files or sections are changed, remember to consider these:
- Keep public-key address and byte forms aligned with Kit address inputs and account-data codecs. A change in either representation can break program clients or layout decoding.
- Keep derived-address seed limits and curve checks aligned with callers that persist or use derived account identities.
- Keep the
Keypairaddress and public-key views aligned with its signer capabilities. A mismatch can attach a valid signature to the wrong account identity. - Keep the raw and parsed account response forms aligned with connection methods and subscriptions. A change in one form can change the meaning of the shared account record.
- Keep query filters and requested encodings aligned with the data form returned by the node. A mismatch can change which accounts callers receive or how they read the result.
- Keep transaction-facing identity and signer contracts aligned with Keys and signatures when account identity inputs change.
- Keep raw account responses aligned with the byte layouts described in Account state and layouts.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A public key is passed in a form that is not a valid address or byte value | Account identity construction fails before the account can be read or used | Use the supported address, byte, number, or public-key forms and validate external input |
| A program-derived address uses too many seeds, an overlong seed, or produces an on-curve point | Address derivation fails and no usable program identity is returned | Apply the derivation limits and handle the reported derivation error |
| A program-derived address is treated as if it had a private signer | A caller attempts an operation that the derived account cannot authorize directly | Keep program-controlled identity separate from keypair-backed signer authority |
| Parsed data is treated as raw bytes, or raw data as parsed state | Consumers read the wrong data shape and can fail at runtime | Check the account data form selected by the query or subscription before reading data |
| A node has no parser for a requested parsed account response | The response can fall back to base64 and no longer contain parsed fields | Detect the returned data form before reading program-specific values |
| An account response omits its address in a collection or change event | A caller cannot relate the state to the account that produced it | Use the keyed account form for program-account results and account notifications |
Key files
| File | Why to read it |
|---|---|
| packages/…/publickey.ts | Defines account identity values, address conversion, signature verification, layout encoding, and derived program addresses. |
| packages/…/keypair.ts | Defines keypair-backed signer authority and its public identity views. |
| src/connection.ts | Defines the node-facing account records, data forms, reads, queries, and subscriptions. |
| src/…/legacy.ts | Shows how transaction flows consume account identities and signer inputs. |
| src/layout.ts | Shows the shared byte-layout primitives used when callers interpret raw account data. |