> ## Documentation Index
> Fetch the complete documentation index at: https://sava.software/llms.txt
> Use this file to discover all available pages before exploring further.

# Core

> Common Solana Cryptography & Serialization Utilities.

> [card] [GitHub Repository](https://github.com/sava-software/sava)

## [Dependencies](https://github.com/sava-software/sava/blob/main/sava-core/src/main/java/module-info.java)

* [org.bouncycastle.provider](https://www.bouncycastle.org/download/bouncy-castle-java/#latest)

## Features

* [Transaction construction and signing](https://sava.software/guides/transactions.md), plus [legacy, v0, and v1 deserialization](#transaction-deserialization)
* [Account Types:](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/accounts)
  * Token, Mint, [Token-2022 and all of its extensions](#token-2022-extensions)
  * Address Lookup Tables
* [Common collection of main-net addresses](#solana-accounts)
* Ed25519 [public](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/accounts/PublicKey.java) and [private](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/accounts/Signer.java) keys
* [Program derived addresses](#program-derived-addresses)
* [Encoding:](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/encoding)
  * [Base58](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/encoding/Base58.java)
  * [Hex](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/encoding/Jex.java)
  * [Little Endian Numbers](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/encoding/ByteUtil.java)
  * [Compact u16](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/encoding/CompactU16Encoding.java)

## Solana Accounts

[SolanaAccounts](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/accounts/SolanaAccounts.java)
provides the native/builtin program IDs, common SPL program IDs, and sysvar addresses,
each with pre-constructed read/invoked `AccountMeta` variants.

```java theme={null}
var accounts = SolanaAccounts.MAIN_NET;
var tokenProgram = accounts.invokedTokenProgram();
var clock = accounts.readClockSysVar();
```

For a fork or custom deployment, use
[SolanaAccountsBuilder](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/accounts/SolanaAccountsBuilder.java)
and override only the addresses which differ; every field defaults to its main-net value.

```java theme={null}
var accounts = SolanaAccountsBuilder.builder()
    .tokenProgram("<forkedTokenProgram>")
    .create();
```

## Token-2022 Extensions

[Token2022](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/accounts/token/Token2022.java)
and [Token2022Account](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/accounts/token/Token2022Account.java)
parse known [Token-2022 extensions](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/accounts/token/extensions)
into a sealed type hierarchy. Unrecognized type IDs in well-formed TLV data are retained
as `UnknownTokenExtension` with their on-chain type value and raw data. Truncated TLV
values, mismatched fixed-size extension lengths, and duplicate extension IDs are rejected.

`tokenExtensions()` returns the parsed extensions. Match their concrete types when
handling them; `ordinal()` exposes each extension's stable on-chain type ID.

```java theme={null}
var token2022 = Token2022.read(mintAddress, accountData);
for (var extension : token2022.tokenExtensions()) {
  switch (extension) {
    case TransferFeeConfig(_, _, _, _, TransferFee(_, long maxFee, int feeBasisPoints)) ->
        System.out.format("Transfer fee: %d bps, max %d%n", feeBasisPoints, maxFee);
    case TokenMetadata metadata -> System.out.println(metadata.name());
    case UnknownTokenExtension(int type, byte[] data) ->
        System.out.println("Unknown extension type " + type);
    default -> {
    }
  }
}
```

## Program Derived Addresses

```java theme={null}
var programId = PublicKey.fromBase58Encoded("<programId>");
var seeds = List.of("state".getBytes(US_ASCII), owner.toByteArray());
ProgramDerivedAddress pda = PublicKey.findProgramAddress(seeds, programId);
```

## Private Key Parsing

> [!NOTE]
>
> `PrivateKeyEncoding` is provided by `sava-rpc`. `JsonIterator` comes from its
> transitive [json-iterator](https://github.com/comodal/json-iterator) dependency.

### Usage

```java theme={null}
var jsonConfig = "";
var ji = JsonIterator.parse(jsonConfig);
var signer = PrivateKeyEncoding.fromJsonPrivateKey(ji);
```

### JSON Configuration

A JSON object requires `encoding` and `secret`; fields may appear in any order.
Unknown fields are skipped, including nested objects and arrays. If the base58
encoded public key is supplied as `pubKey`, it is checked against the public key
derived from the private key.

#### Solana CLI Key Pair JSON Array

By default, if only an array is configured, the assumption is that it is a key pair generated by the Solana CLI.

```
[1,2,3, ... ,42]
```

#### JSON Array

```json theme={null}
{
  "pubKey": "<BASE58_ENCODED_PUBLIC_KEY>",
  "encoding": "jsonKeyPairArray",
  "secret": []
}
```

#### Key Pair

Encoded 64 byte private/public key pair. Derived public key will be validated.

* base64KeyPair
* base58KeyPair

```json theme={null}
{
  "pubKey": "<BASE58_ENCODED_PUBLIC_KEY>",
  "encoding": "base64KeyPair",
  "secret": "asdf=="
}
```

#### Private Key Only

Encoded 32 byte private key.

* base64PrivateKey
* base58PrivateKey

```json theme={null}
{
  "pubKey": "<BASE58_ENCODED_PUBLIC_KEY>",
  "encoding": "base64PrivateKey",
  "secret": "asdf=="
}
```

## Transaction Deserialization

The [TransactionSkeleton](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/tx/TransactionSkeleton.java)
interface provides a lightweight view over transaction data. Allowing for partial introspection or complete reconstruction of
a [Transaction](https://github.com/sava-software/sava/tree/main/sava-core/src/main/java/software/sava/core/tx/Transaction.java).

### Legacy

```java theme={null}
byte[] legacyTransactionData = ...;
var skeleton = TransactionSkeleton.deserializeSkeleton(legacyTransactionData);
AccountMeta[] accounts = skeleton.parseAccounts();
Instruction[] instructions = skeleton.parseLegacyInstructions();
Transaction transaction = skeleton.createTransaction();
```

### v0

```java theme={null}
byte[] v0TransactionData = ...;
var skeleton = TransactionSkeleton.deserializeSkeleton(v0TransactionData);
var instructionsWithoutTableAccounts = skeleton.parseInstructionsWithoutTableAccounts();

PublicKey[] tableAccounts =  skeleton.lookupTableAccounts();
// ... Fetch table accounts (See RPC) ...
AddressLookupTable lookupTable = ...;
AccountMeta[] accounts = skeleton.parseAccounts(lookupTable);
Instruction[] instructions = skeleton.parseInstructions(accounts);
Transaction transaction = skeleton.createTransaction(instructions, lookupTable);
```

### v1

The same deserializer recognizes v1. All v1 accounts are carried directly in the
message, so no address lookup tables need to be fetched.

```java theme={null}
byte[] v1TransactionData = ...;
var skeleton = TransactionSkeleton.deserializeSkeleton(v1TransactionData);
int version = skeleton.version(); // 1
AccountMeta[] accounts = skeleton.parseAccounts();
Instruction[] instructions = skeleton.parseInstructions(accounts);
long priorityFeeLamports = skeleton.priorityFeeLamports();
int computeUnitLimit = skeleton.computeUnitLimit();
```

Deserialization reads the wire structure; it does not establish signature validity
or whether a transaction would execute successfully on a cluster.

## Creating Transactions

The [transaction guide](https://sava.software/guides/transactions.md) covers choosing a format, building v1
transactions with `TxBuilder`, simulating, signing, and submitting. It also covers
creating a v1 builder from a parsed `TransactionSkeleton` with `prototypeTransaction()`.

The [IDL client examples](https://sava.software/libraries/idl-clients.md#typical-transaction-flow) show a
supported legacy flow using generated program instructions.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.