Addresses, instruction builders, signing bytes and decoders for the Civitas program, checked against its IDL. Both SDKs and the CLI are built on it. Use it to build transactions yourself.
Version 0.2.0:
npm install ./civitas-contract-0.2.0.tgz ./civitas-program-0.2.0.tgzExports
PROGRAM_ID
const PROGRAM_ID: PublicKey;The Civitas program ID.
configPda
const configPda: () => PublicKey;The Config account’s address.
agentPda
const agentPda: (agentKey: PublicKey) => PublicKey;An agent account’s address, from the agent key.
vaultPda
const vaultPda: (agentAddress: PublicKey) => PublicKey;A vault’s address, from the agent account’s address.
servicePda
const servicePda: (agentAddress: PublicKey) => PublicKey;A listing’s address, from the agent account’s address.
eventAuthorityPda
const eventAuthorityPda: () => PublicKey;Anchor’s event authority address.
usdcAta
const usdcAta: (owner: PublicKey, usdcMint: PublicKey) => PublicKey;A wallet’s USDC associated token account.
createUsdcAtaInstruction
function createUsdcAtaInstruction(payer: PublicKey, owner: PublicKey, usdcMint: PublicKey): TransactionInstruction;Creates a USDC associated token account if it doesn’t exist yet.
createProgramClient
function createProgramClient(connection: Connection): {
charterInstructions(args: CharterArgs & {
consentSignature: Uint8Array;
}): Promise<TransactionInstruction[]>;
withdrawInstructions(args: WithdrawArgs): Promise<TransactionInstruction[]>;
revokeInstructions(args: RevokeArgs): Promise<TransactionInstruction[]>;
settleInstructions(args: SettleArgs & {
signature: Uint8Array;
}): Promise<[TransactionInstruction, TransactionInstruction]>;
initializeConfig({ admin, usdcMint }: {
admin: PublicKey;
usdcMint: PublicKey;
}): Promise<TransactionInstruction>;
updateConfig({ admin, feeBps, feeFloor, feeRecipient }: {
admin: PublicKey;
feeBps: number;
feeFloor: bigint;
feeRecipient: PublicKey;
}): Promise<TransactionInstruction>;
charter({ principal, agentKey, usdcMint, cardHash, cardUri, policy, firstDeposit, consentExpiresAt }: CharterArgs): Promise<TransactionInstruction>;
deposit({ funder, agentKey, usdcMint, amount }: {
funder: PublicKey;
agentKey: PublicKey;
usdcMint: PublicKey;
amount: bigint;
}): Promise<TransactionInstruction>;
withdraw({ principal, agentKey, usdcMint, amount }: WithdrawArgs): Promise<TransactionInstruction>;
setPolicy({ principal, agentKey, policy }: PrincipalAgent & {
policy: Policy;
}): Promise<TransactionInstruction>;
freeze({ principal, agentKey }: PrincipalAgent): Promise<TransactionInstruction>;
unfreeze({ principal, agentKey }: PrincipalAgent): Promise<TransactionInstruction>;
revoke({ principal, agentKey, usdcMint }: RevokeArgs): Promise<TransactionInstruction>;
listService({ principal, agentKey, endpoint, pricePerCall }: PrincipalAgent & {
endpoint: string;
pricePerCall: bigint;
}): Promise<TransactionInstruction>;
unlistService({ principal, agentKey }: PrincipalAgent): Promise<TransactionInstruction>;
settle({ submitter, feeRecipient, payeeIsChartered, authorization }: SettleArgs): Promise<TransactionInstruction>;
};One builder per instruction, each returning a TransactionInstruction, plus the …Instructions variants that put the instructions around it that it needs. See The client.
authorizationBytes
function authorizationBytes(authorization: Authorization): Uint8Array;The authorization bytes.
consentBytes
function consentBytes(consent: Consent): Uint8Array;The consent bytes.
receiptBytes
function receiptBytes(receipt: Receipt): Uint8Array;The receipt bytes.
signAuthorization
function signAuthorization(agentSecret: Uint8Array, authorization: Authorization): Uint8Array;Signs an authorization with the agent’s 64-byte secret key.
signConsent
function signConsent(agentSecret: Uint8Array, consent: Consent): Uint8Array;Signs a consent with the agent’s 64-byte secret key.
consentInstruction
function consentInstruction(consent: Consent, signature: Uint8Array): TransactionInstruction;The Ed25519 instruction that must sit just before charter.
authorizationInstruction
function authorizationInstruction(authorization: Authorization, signature: Uint8Array): TransactionInstruction;The Ed25519 instruction that must sit just before settle.
signReceipt
function signReceipt(payeeSecret: Uint8Array, receipt: Receipt): Uint8Array;Signs a receipt with the payee’s 64-byte secret key.
verifyReceipt
function verifyReceipt(receipt: Receipt, signature: Uint8Array): boolean;Checks a receipt’s signature against its payee key.
decodeConfig
function decodeConfig(data: Uint8Array): {
admin: PublicKey;
feeBps: number;
feeFloor: bigint;
feeRecipient: PublicKey;
usdcMint: PublicKey;
bump: number;
feeAtaBump: number;
};Decodes the Config account’s data.
decodeAgent
function decodeAgent(data: Uint8Array): {
agentKey: PublicKey;
principal: PublicKey;
cardHash: Uint8Array<ArrayBuffer>;
cardUri: string;
status: string;
policyVersion: number;
policy: Policy;
createdAt: bigint;
periodStart: bigint;
spentInPeriod: bigint;
highestNonce: bigint;
nonceBitmap: bigint[];
bump: number;
vaultBump: number;
};Decodes an Agent account’s data.
decodeService
function decodeService(data: Uint8Array): {
endpoint: string;
pricePerCall: bigint;
listed: boolean;
updatedAt: bigint;
};Decodes a Service account’s data.
decodeEventInstruction
function decodeEventInstruction(programId: PublicKey | string, data: Uint8Array | string): CivitasEvent | null;Decodes one Civitas event from an inner instruction’s data, raw or base58, or returns null for anything else.
PROGRAM_ERRORS
const PROGRAM_ERRORS: {
code: number;
name: string;
message: string;
}[];Every program error with its code, name and message.
programError
function programError(codeOrName: number | string): {
code: number;
name: string;
message: string;
} | undefined;Looks a program error up by code or by name.
feeFor
function feeFor(amount: bigint, feeBps: number, feeFloor: bigint): bigint;The protocol fee for an amount, as the program computes it.
IDL
const IDL: { address, metadata, instructions, accounts, events, errors, types }The program’s IDL.
Policy
interface Policy {
maxPerCall: bigint;
maxPerPeriod: bigint;
periodSeconds: number;
counterparties: readonly PublicKey[] | null;
expiresAt: bigint;
}A policy as the builders take it.
maxPerCallbigintrequired- Most per settlement, amount and fee together.
maxPerPeriodbigintrequired- Most per period, amount and fee together.
periodSecondsnumberrequired- Period length.
counterpartiesreadonly PublicKey[] | nullrequired- Payees allowed, or
nullfor open. expiresAtbigintrequired- Unix seconds;
0nfor none.
PrincipalAgent
interface PrincipalAgent {
principal: PublicKey;
agentKey: PublicKey;
}The principal and the agent key, which every lifecycle builder takes.
principalPublicKeyrequired- The principal wallet.
agentKeyPublicKeyrequired- The agent key.
CharterArgs
interface CharterArgs extends PrincipalAgent {
usdcMint: PublicKey;
cardHash: Uint8Array;
cardUri: string;
policy: Policy;
firstDeposit: bigint;
consentExpiresAt: bigint;
}What charter and charterInstructions take.
usdcMintPublicKeyrequired- The settlement mint.
cardHashUint8Arrayrequired- SHA-256 of the card JSON, 32 bytes.
cardUristringrequired- Where the card is served.
policyPolicyrequired- The first policy.
firstDepositbigintrequired- Base units to move into the vault.
consentExpiresAtbigintrequired- The expiry the agent key signed in its consent, Unix seconds.
WithdrawArgs
interface WithdrawArgs extends PrincipalAgent {
usdcMint: PublicKey;
amount: bigint;
}What withdraw and withdrawInstructions take.
usdcMintPublicKeyrequired- The settlement mint.
amountbigintrequired- Base units.
RevokeArgs
interface RevokeArgs extends PrincipalAgent {
usdcMint: PublicKey;
}What revoke and revokeInstructions take.
usdcMintPublicKeyrequired- The settlement mint.
SettleArgs
interface SettleArgs {
submitter: PublicKey;
feeRecipient: PublicKey;
payeeIsChartered: boolean;
authorization: Authorization;
}What settle and settleInstructions take.
submitterPublicKeyrequired- The key that signs and pays the transaction.
feeRecipientPublicKeyrequired- The fee recipient from Config.
payeeIsCharteredbooleanrequired- Whether the payee has a charter, which decides the destination account.
authorizationAuthorizationrequired- The signed authorization.
Authorization
interface Authorization {
mint: PublicKey;
agentKey: PublicKey;
payee: PublicKey;
amount: bigint;
fee: bigint;
nonce: bigint;
callId: Uint8Array;
expiresAt: bigint;
}The fields an agent signs for one call.
mintPublicKeyrequired- The settlement mint.
agentKeyPublicKeyrequired- The payer’s agent key.
payeePublicKeyrequired- The payee’s key.
amountbigintrequired- Base units.
feebigintrequired- The protocol fee, base units.
noncebigintrequired- The agent’s nonce.
callIdUint8Arrayrequired- The quote’s 32-byte call ID.
expiresAtbigintrequired- Unix seconds.
Consent
interface Consent {
principal: PublicKey;
agentKey: PublicKey;
cardHash: Uint8Array;
expiresAt: bigint;
}The fields an agent key signs to consent to its charter.
principalPublicKeyrequired- The principal that will charter the agent.
agentKeyPublicKeyrequired- The agent key.
cardHashUint8Arrayrequired- SHA-256 of the card JSON, 32 bytes.
expiresAtbigintrequired- Unix seconds.
Receipt
interface Receipt {
settlementSignature: Uint8Array;
callId: Uint8Array;
payer: PublicKey;
payee: PublicKey;
amount: bigint;
servedAt: bigint;
responseHash: Uint8Array;
}The fields a payee signs for one served call.
settlementSignatureUint8Arrayrequired- The settlement’s 64-byte signature.
callIdUint8Arrayrequired- The 32-byte call ID.
payerPublicKeyrequired- The payer’s agent key.
payeePublicKeyrequired- The payee’s key.
amountbigintrequired- Base units.
servedAtbigintrequired- Unix seconds.
responseHashUint8Arrayrequired- SHA-256 of the response body, 32 bytes.
ConfigAccount
type ConfigAccount = ReturnType<typeof decodeConfig>;A decoded Config.
AgentAccount
type AgentAccount = ReturnType<typeof decodeAgent>;A decoded Agent.
ServiceAccount
type ServiceAccount = ReturnType<typeof decodeService>;A decoded Service.
CivitasEvent
type CivitasEvent = {
[Name in keyof Events]: {
name: Name;
data: Events[Name];
};
}[keyof Events];A decoded event: its name and its fields under the IDL’s names.
Civitas
type Civitas = typeof IDL // as Anchor generates itThe IDL’s type, for Anchor clients.
The client
createProgramClient(connection) returns these builders. Every one resolves to instructions; none signs or sends. Amounts are bigint base units.
| Method | Builds |
|---|---|
charterInstructions | Creates the principal’s USDC account if needed, adds the Ed25519 instruction with the agent’s consentSignature, then charter. |
withdrawInstructions | Creates the principal’s USDC account if needed, then withdraw. |
revokeInstructions | Creates the principal’s USDC account if needed, then revoke. |
settleInstructions | The Ed25519 instruction for the signature, then settle, in the order the program needs. |
initializeConfig | The one-time Config creation, for the designated deployer. |
updateConfig | A fee change, for the admin. |
charter | The charter instruction. |
deposit | A deposit from funder’s USDC account. |
withdraw | A withdrawal to the principal. |
setPolicy | A new policy. |
freeze | A freeze. |
unfreeze | An unfreeze. |
revoke | A revoke. |
listService | A listing or a listing change. |
unlistService | An unlisting. |
settle | The settle instruction alone. |