Skip to main content
The ActionCodesProtocol class is the main entry point for the One-Time Action Code Protocol. It provides a unified interface for generating, validating, and managing action codes.

ProtocolConfig Interface

interface ProtocolConfig {
  version: string;
  defaultPrefix: string;
  codeTTL: number;
  codeLength: number;
  maxPrefixLength: number;
  minPrefixLength: number;
}
Defines the configuration options for the protocol instance.

ActionCodesProtocol

constructor

new ActionCodesProtocol(config?: Partial<ProtocolConfig>)
Creates a new protocol instance with optional custom configuration.

registerAdapter

registerAdapter<T>(adapter: BaseChainAdapter<T>): void
Registers a chain adapter implementation.

getRegisteredChains

getRegisteredChains(): string[]
Returns an array of registered chain identifiers.

isChainSupported

isChainSupported(chain: string): boolean
Checks if a chain is supported.

getChainAdapter

getChainAdapter<T = any>(chain: string): BaseChainAdapter<T> | undefined
Returns the chain adapter for a given chain, or undefined if not registered.

validateActionCode

validateActionCode(actionCode: ActionCode): boolean
Validates an action code, checking intent type and required fields.

createActionCode

async createActionCode(
  pubkey: string,
  signFn: (message: string) => Promise<string>,
  chain: SupportedChain,
  prefix?: string,
  timestamp?: number
): Promise<ActionCode>
Creates a new action code for a given public key, signing function, and chain.

attachTransaction

attachTransaction(
  actionCode: ActionCode,
  transaction: string,
  issuer: string,
  params?: string,
  txType?: string
): ActionCode
Attaches a transaction to an action code with protocol meta injection.

attachMessage

attachMessage(
  actionCode: ActionCode,
  message: string,
  params?: string,
  messageType?: string
): ActionCode
Attaches a message to an action code (sign-only mode).

finalizeActionCode

finalizeActionCode(actionCode: ActionCode, signature: string): ActionCode
Finalizes an action code based on its intent type.

createProtocolMeta

createProtocolMeta(
  actionCode: ActionCode,
  issuer?: string,
  params?: string,
  timestamp?: number
): ProtocolMetaV1
Creates protocol meta for a transaction.

encodeProtocolMeta

encodeProtocolMeta(meta: ProtocolMetaV1, chain: string): any
Encodes protocol meta for a specific chain.

decodeProtocolMeta

decodeProtocolMeta(transaction: any, chain: string): ProtocolMetaV1 | null
Decodes protocol meta from a transaction.

validateTransaction

validateTransaction(
  transaction: any,
  chain: string,
  authorities: string[],
  expectedPrefix?: string
): boolean
Validates a transaction with protocol meta.

validateTransactionTyped

validateTransactionTyped<T>(
  transaction: T,
  chain: string,
  authorities: string[],
  expectedPrefix?: string
): boolean
Type-safe transaction validation for specific chains.

detectTampering

detectTampering<T>(
  transaction: T,
  chain: string,
  authorities: string[],
  expectedPrefix?: string
): boolean
Detects tampered transactions with type safety.

decodeProtocolMetaTyped

decodeProtocolMetaTyped<T>(transaction: T, chain: string): ProtocolMetaV1 | null
Type-safe protocol meta decoding.

getConfig

getConfig(): ProtocolConfig
Returns the current protocol configuration.

updateConfig

updateConfig(updates: Partial<ProtocolConfig>): void
Updates the protocol configuration.

static create

static create(): ActionCodesProtocol
Creates a new protocol instance with default configuration.

static createWithConfig

static createWithConfig(config: Partial<ProtocolConfig>): ActionCodesProtocol
Creates a new protocol instance with custom configuration.

Example

import { ActionCodesProtocol } from "@actioncodes/protocol";

const protocol = ActionCodesProtocol.create();
protocol.registerAdapter(myChainAdapter);

const actionCode = await protocol.createActionCode(pubkey, signFn, "solana");