aimarket_agent library

AI Market Protocol v2 Consumer SDK for Dart/Flutter.

Use this to embed marketplace economy into Flutter desktop apps (macOS/Windows/Linux), Dart servers, and any Dart application.

Quick Start

import 'package:aimarket_agent/aimarket_agent.dart';

void main() async {
  final agent = AimarketAgent(
    hubUrl: 'https://modelmarket.dev',
    walletKey: 'your-wallet-private-key-hex',
  );

  // Phase 1: Discover career capabilities
  final plan = await agent.discover(
    intent: 'ATS scoring rules for fintech roles',
    budget: 1.00,
    category: 'career',
  );

  // Phase 2: Open a $5 channel on Base. A production hub opens one only
  // against your on-chain deposit and the paying wallet's proof
  // (signChannelOpenProof). With `apiKey: myCreditAccountKey` in the
  // constructor the credit account pays instead: skip phases 2 and 4 and
  // leave out `channelId`.
  final channel = await agent.openChannel(5.00,
      token: 'USDC', txHash: depositTxHash, payerSignature: payerProof);

  // Phase 3: Invoke the top result
  final result = await agent.invoke(
    capabilityId: plan.first.capability.id,
    input: {'target_role': 'Senior PM', 'industry': 'fintech'},
    channelId: channel.id,
  );

  // Phase 4: Settle the channel
  await agent.closeChannel(channel.id);

  // Phase 5: Verify TEE receipt (optional)
  if (result.teeReceipt != null) {
    final ok = agent.verifyTeeReceipt(
      result.teeReceipt!,
      jsonEncode({'target_role': 'Senior PM'}),
      jsonEncode(result.result),
    );
    print('TEE verified: $ok');
  }

  print('Spent: \$${result.priceUsd}');
  agent.dispose();
}

Exports

This library re-exports all public types from its modules:

Core Agent

Data Models

Signing & Crypto

TEE Verification

Dependencies

  • http for HTTP/HTTPS transport
  • crypto for SHA-256 hashing and HMAC

Platform Support

Platform Status
Flutter macOS Full
Flutter Windows Full
Flutter Linux Full
Dart CLI Full
Flutter Web Partial (CORS dependent)
Flutter iOS/Android Untested

Classes

AimarketAgent
AI Market Protocol v2 consumer.
AimarketAgentConfig
Configuration for AimarketAgent behavior.
BillOfMaterials
Bill of Materials — full trace of a marketplace interaction.
Capability
A discoverable capability from the marketplace.
Channel
A pre-funded payment channel.
Eip712Domain
InvokeResult
Result of a capability invocation.
MarketSigner
PlanStep
A plan step from discovery — capability matched to an intent.
SearchResponse
A hub search/discovery response — the typed shape returned by GET /ai-market/v2/search.
Settlement
Settlement returned after closing a payment channel.
TeeAttestation
TEE attestation proving code runs in a secure enclave.
TeePlatform
Recognized TEE platform identifiers.
TeeReceipt
Receipt proving execution happened inside a TEE.
TeeVerificationResult
Result of a TEE attestation verification with detailed failure reasons.
TeeVerifier
Verifies TEE attestations and receipts client-side.
TrustedHashCache
Caches trusted code hashes fetched from the hub, with TTL expiry.
TypedData

Functions

canonicalProofAmountCents(num amountUsd) → int
Deposit amount as the integer cents both ledgers bill in.
canonicalProofChain(String chain) → String
Canonical chain id: chain names are ASCII and case-free.
canonicalProofPayer(String payer) → String
Canonical payer: EIP-55 mixed case is a checksum, not identity, so an address lowercases.
canonicalProofTxHash(String txHash) → String
Canonical transaction id.
channelOpenProofHash({required String chain, required String txHash, required String payer, required num amountUsd}) → Uint8List
The EIP-191 digest: keccak256("\x19Ethereum Signed Message:\n" + len + message).
channelOpenProofMessage({required String chain, required String txHash, required String payer, required num amountUsd}) → String
The exact text the paying wallet signs.
computeDebitDigest({required String channelId, required String hub, required String token, required BigInt amount, required String receiptId, required BigInt nonce, required int deadline, int chainId = 8453, String verifyingContract = '0x0000000000000000000000000000000000000000'}) → Uint8List
Compute EIP-712 digest for a debit authorization.
ed25519HasSmallOrder(List<int> point) → bool
Is this 32-byte Ed25519 encoding a point of small order?
jsonRoundTrip<T>(JsonFactory<T> fromJson, Map<String, dynamic> input) → bool
Verify that a model round-trips through JSON without field loss.
signChannelOpenProof({required String privateKeyHex, required String chain, required String txHash, required String payer, required num amountUsd}) → String
Sign the challenge with the paying wallet's key. Returns 0x-prefixed r‖s‖v (65 bytes).

Typedefs

JsonFactory<T> = T Function(Map<String, dynamic>)
JSON serialization round-trip helper for models.

Exceptions / Errors

AimarketException
Base exception for AI Market Protocol errors.
AimarketNetworkException
Network-level error: timeout, connection refused, DNS failure, etc.
AimarketPaymentException
Payment failure: depleted channel, insufficient funds, or expired credit.
AimarketSafetyException
Safety gate blocked the invocation.