Skip to content

TypeScript SDK Reference

Complete API reference for @a2p/sdk.


Installation

npm install @a2p/sdk

A2PClient

For agents accessing user profiles.

Constructor

const client = new A2PClient({
  agentDid: string,
  privateKey?: string,
  gatewayUrl?: string
});

Methods

getProfile

const profile = await client.getProfile({
  userDid: string,
  scopes: string[]
}): Promise<Profile>

requestAccess

const result = await client.requestAccess({
  userDid: string,
  scopes: string[],
  purpose: Purpose
}): Promise<AccessResult>

proposeMemory

const proposal = await client.proposeMemory({
  userDid: string,
  content: string,
  category: string,
  confidence: number,
  context?: string
}): Promise<Proposal>

A2PUserClient

For users managing their profiles.

Constructor

const client = new A2PUserClient({
  storage?: StorageAdapter
});

Methods

createProfile

const profile = await client.createProfile({
  displayName: string,
  preferences?: Preferences
}): Promise<Profile>

getPendingProposals

const proposals = await client.getPendingProposals(): Promise<Proposal[]>

reviewProposal

await client.reviewProposal(
  proposalId: string,
  decision: { action: 'approve' | 'reject', editedContent?: string }
): Promise<void>

setPolicy

await client.setPolicy({
  name: string,
  agentPattern: string,
  allow: string[],
  deny?: string[],
  permissions: Permission[]
}): Promise<Policy>

Types

Profile

interface Profile {
  id: DID;
  version: string;
  profileType: 'human' | 'agent' | 'entity';
  identity: Identity;
  common?: CommonData;
  memories?: Record<string, any>;
  accessPolicies?: Policy[];
}

Purpose

interface Purpose {
  type: PurposeType;
  description: string;
  legalBasis: LegalBasis;
  retention?: string;
  automated?: {
    decisionMaking: boolean;
    profiling: boolean;
  };
}

AccessResult

interface AccessResult {
  granted: boolean;
  grantedScopes: string[];
  deniedScopes: string[];
  consentReceipt?: ConsentReceipt;
  reason?: string;
}

Next Steps