agon-cmt-v5 (unilateral commitment) and agon-clr-v4 (cooperative clearing round) — and verifies them on-chain through the Ed25519 native program and the instructions sysvar. The SDK gives you:
- Builders that produce the exact byte layout the program expects.
- Pre-instruction helpers that wrap one or more signatures into
Ed25519Programinstructions, ready to be attached to the same transaction as the settlement call.
Amountish
Most builders accept Amountish for any unsigned integer (participant IDs, token amounts). Four types are supported:
| Type | Example |
|---|---|
bigint | 1_000_000n |
number | 1_000_000 |
string | "1000000" |
{ toString(): string } | new BN(1_000_000) |
toBigIntAmount(); negative numbers throw. For Anchor instruction arguments, use toAnchorBn() (also exported) to convert to anchor.BN.
createCommitmentMessage(params)
Builds a raw agon-cmt-v5 message body. You then feed it to one of the Ed25519 helpers below.
| Param | Type | Required | Notes |
|---|---|---|---|
messageDomain | Buffer | Uint8Array (16 bytes) | yes | From deriveMessageDomain. |
payerId | Amountish | yes | Payer’s participant_id. |
payeeId | Amountish | yes | Payee’s participant_id. |
tokenId | number | yes | 0–65535, registered in TokenRegistry. |
committedAmount | Amountish | yes | Cumulative amount, not a delta. |
authorizedSettler | PublicKey | null | no | If set, only this key (or the payee) can submit on-chain. |
Buffer starts with [0x01, 0x05] (kind + version) so you can visually confirm a message is a v5 commitment. See on-chain layout.
createClearingRoundMessage(params)
Builds a raw agon-clr-v4 message body for clearing rounds. Each participant in the round signs this same message with their own key, and all signatures are submitted together via createMultiSigEd25519Instruction.
| Param | Type | Required | Notes |
|---|---|---|---|
messageDomain | Buffer | Uint8Array | yes | Same domain as commitments. |
tokenId | number | yes | The token the whole round settles. |
blocks | ClearingRoundBlock[] | yes | One block per signer, in canonical order. |
ClearingRoundBlock is:
payeeRef semantics match Reference → Messages → agon-clr-v4.
Ed25519 helpers
Agon’s on-chain verification reads the Ed25519 native program’s instruction data directly. The SDK ships four builders covering the common shapes. All four return a standardTransactionInstruction targeting Ed25519Program.programId, ready to drop into .preInstructions([ix]) on any Anchor methods builder.
createEd25519Instruction(signer, message)
Simple single-signer Ed25519 instruction. Use this for direct settlement of a single commitment.
| Arg | Type | Notes |
|---|---|---|
signer | Keypair | The payer’s keypair (or their authorized_signer). |
message | Buffer | Output of createCommitmentMessage or createClearingRoundMessage. |
Ed25519Program.createInstructionWithPrivateKey, so it is compatible with any existing web3.js tooling.
createMultiSigEd25519Instruction(signers, message)
One Ed25519 instruction that carries multiple signatures over the same message. Used by clearing rounds where every participant signs the identical agon-clr-v4 body.
signers array. That order is observable on-chain and must match the order the program expects for that round.
createMultiMessageEd25519Instruction(entries)
One Ed25519 instruction that carries N signatures over N different messages. Used by bundle settlement, where the payee is settling multiple commitments from the same (or different) payer(s) in one transaction.
count passed to settleCommitmentBundle must match the number of entries in the pre-instruction.
createCrossInstructionMessageEd25519Instruction(signer, message, messageInstructionIndex)
Rare, advanced layout where the Ed25519 instruction references the message bytes stored in another instruction within the same transaction (instead of inlining them). messageInstructionIndex is the zero-based index of that other instruction.
This is used when you want to deduplicate a large message across multiple verifications or place it in a CPI instruction. Most integrations don’t need this.
Low-level encoding helpers
Two functions are exported for rare cases where you want to hand-build a message:encodeCompactU64(value)
agon-cmt-v5 and agon-clr-v4. Returns a number[].
sha256Bytes(data)
number[] of length 32. Uses Node’s built-in crypto.createHash, so it works in any Node-compatible runtime (Node ≥ 18, Bun, Deno with the Node compat layer, or Next.js server components). Bundlers targeting the browser will need to shim node:crypto.
Putting it together
@agonx402/sdk. See Recipes for the full lifecycle including participant registration, channel creation, and withdrawals.
