npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xapt/common

v1.2.0

Published

Shared types, constants, and utilities for xAPT SDK

Readme

@xapt/common

Shared types, interfaces, constants, and utility functions for the xAPT SDK - enabling instant, automated stablecoin payments over HTTP using Aptos Testnet USDC.

📦 Installation

npm install @xapt/common

🚀 Features

  • TypeScript Types: Complete type definitions for Aptos transactions and payments
  • Constants: Aptos network configurations and USDC settings
  • Error Codes: Standardized error codes for payment processing
  • HTTP Headers: Custom headers for HTTP 402 payment integration
  • Validation Utils: Input validation and formatting utilities
  • Aptos Integration: Native Aptos blockchain support

📚 API Reference

Constants

Aptos Networks

import { APTOS_NETWORKS } from '@xapt/common';

console.log(APTOS_NETWORKS.TESTNET); // 'testnet'
console.log(APTOS_NETWORKS.MAINNET); // 'mainnet'
console.log(APTOS_NETWORKS.DEVNET);  // 'devnet'

USDC Configuration

import { USDC_CONFIG, APTOS_TESTNET_USDC_ADDRESS } from '@xapt/common';

console.log(USDC_CONFIG.DECIMALS); // 6
console.log(USDC_CONFIG.SYMBOL);   // 'USDC'
console.log(USDC_CONFIG.NAME);     // 'USD Coin'
console.log(APTOS_TESTNET_USDC_ADDRESS); // '0x...'

Error Codes

import { ERROR_CODES } from '@xapt/common';

// Payment-related errors
console.log(ERROR_CODES.PAYMENT_REQUIRED);     // 'PAYMENT_REQUIRED'
console.log(ERROR_CODES.INSUFFICIENT_FUNDS);   // 'INSUFFICIENT_FUNDS'
console.log(ERROR_CODES.PAYMENT_FAILED);       // 'PAYMENT_FAILED'
console.log(ERROR_CODES.INVALID_PAYMENT);      // 'INVALID_PAYMENT'

// Wallet-related errors
console.log(ERROR_CODES.WALLET_NOT_CONNECTED); // 'WALLET_NOT_CONNECTED'
console.log(ERROR_CODES.TRANSACTION_FAILED);   // 'TRANSACTION_FAILED'
console.log(ERROR_CODES.INVALID_ADDRESS);      // 'INVALID_ADDRESS'

// Network-related errors
console.log(ERROR_CODES.NETWORK_ERROR);        // 'NETWORK_ERROR'
console.log(ERROR_CODES.TIMEOUT);              // 'TIMEOUT'
console.log(ERROR_CODES.RATE_LIMITED);         // 'RATE_LIMITED'

HTTP Headers

import { HTTP_HEADERS } from '@xapt/common';

// Payment request headers
console.log(HTTP_HEADERS.X_PAYMENT_AMOUNT);      // 'x-payment-amount'
console.log(HTTP_HEADERS.X_PAYMENT_RECIPIENT);   // 'x-payment-recipient'
console.log(HTTP_HEADERS.X_PAYMENT_ID);          // 'x-payment-id'
console.log(HTTP_HEADERS.X_PAYMENT_CURRENCY);    // 'x-payment-currency'

// Payment response headers
console.log(HTTP_HEADERS.X_PAYMENT_STATUS);      // 'x-payment-status'
console.log(HTTP_HEADERS.X_PAYMENT_TRANSACTION); // 'x-payment-transaction'
console.log(HTTP_HEADERS.X_PAYMENT_VERIFIED);    // 'x-payment-verified'

Types

Aptos Types

import { 
  AptosAddress, 
  AptosTransactionPayload, 
  SignedTransaction, 
  AptosTransactionHash 
} from '@xapt/common';

// Aptos address type (string with validation)
const address: AptosAddress = '0x1234567890abcdef...';

// Transaction payload for coin transfer
const payload: AptosTransactionPayload = {
  type: 'coin::transfer',
  function: '0x1::coin::transfer',
  type_arguments: ['0x1::aptos_coin::AptosCoin'],
  arguments: [recipient, amount]
};

// Signed transaction
const signedTx: SignedTransaction = {
  transaction: payload,
  signature: '0x...',
  public_key: '0x...'
};

// Transaction hash
const txHash: AptosTransactionHash = '0x1234567890abcdef...';

Payment Types

import { 
  PaymentRequest, 
  PaymentResponse, 
  PaymentVerificationRequest,
  PaymentVerificationResponse 
} from '@xapt/common';

// Payment request
const paymentRequest: PaymentRequest = {
  amount: '0.01',
  recipientAddress: '0x1234567890abcdef...',
  currency: 'USDC',
  paymentId: 'uuid-here'
};

// Payment response
const paymentResponse: PaymentResponse = {
  success: true,
  transactionHash: '0x1234567890abcdef...',
  amount: '0.01',
  recipientAddress: '0x1234567890abcdef...',
  timestamp: new Date().toISOString()
};

// Payment verification request
const verificationRequest: PaymentVerificationRequest = {
  paymentId: 'uuid-here',
  transactionHash: '0x1234567890abcdef...',
  amount: '0.01',
  recipientAddress: '0x1234567890abcdef...'
};

// Payment verification response
const verificationResponse: PaymentVerificationResponse = {
  verified: true,
  paymentId: 'uuid-here',
  transactionHash: '0x1234567890abcdef...',
  amount: '0.01',
  timestamp: new Date().toISOString()
};

Wallet Adapter Interface

import { WalletAdapter } from '@xapt/common';

// Implement this interface for your wallet
class MyWalletAdapter implements WalletAdapter {
  async connect(): Promise<AptosAddress> {
    // Connect to wallet and return address
    return '0x1234567890abcdef...';
  }

  async signTransaction(payload: AptosTransactionPayload): Promise<SignedTransaction> {
    // Sign transaction and return signed transaction
    return {
      transaction: payload,
      signature: '0x...',
      public_key: '0x...'
    };
  }

  async getAddress(): Promise<AptosAddress> {
    // Get current wallet address
    return '0x1234567890abcdef...';
  }

  async isConnected(): Promise<boolean> {
    // Check if wallet is connected
    return true;
  }
}

Utilities

Validation Functions

import { 
  isValidAptosAddress, 
  isValidAmount, 
  formatAmount,
  generatePaymentId 
} from '@xapt/common';

// Validate Aptos address
const isValid = isValidAptosAddress('0x1234567890abcdef...'); // true/false

// Validate payment amount
const isValidAmount = isValidAmount('0.01'); // true/false

// Format amount for display
const formatted = formatAmount('0.01'); // '0.01 USDC'

// Generate unique payment ID
const paymentId = generatePaymentId(); // 'uuid-string'

🔧 Usage Examples

Basic Setup

import { 
  APTOS_NETWORKS, 
  USDC_CONFIG, 
  ERROR_CODES,
  isValidAptosAddress 
} from '@xapt/common';

// Configure for testnet
const network = APTOS_NETWORKS.TESTNET;

// Check USDC configuration
console.log(`USDC has ${USDC_CONFIG.DECIMALS} decimals`);

// Validate address
if (isValidAptosAddress(userAddress)) {
  console.log('Valid Aptos address');
}

Payment Processing

import { 
  PaymentRequest, 
  PaymentResponse,
  generatePaymentId,
  isValidAmount 
} from '@xapt/common';

// Create payment request
const createPaymentRequest = (amount: string, recipient: string): PaymentRequest => {
  if (!isValidAmount(amount)) {
    throw new Error('Invalid amount');
  }

  return {
    amount,
    recipientAddress: recipient,
    currency: 'USDC',
    paymentId: generatePaymentId()
  };
};

// Process payment response
const processPaymentResponse = (response: PaymentResponse): boolean => {
  if (response.success) {
    console.log(`Payment successful: ${response.transactionHash}`);
    return true;
  }
  return false;
};

Error Handling

import { ERROR_CODES } from '@xapt/common';

const handlePaymentError = (error: any) => {
  switch (error.code) {
    case ERROR_CODES.PAYMENT_REQUIRED:
      console.log('Payment is required for this request');
      break;
    case ERROR_CODES.INSUFFICIENT_FUNDS:
      console.log('Insufficient funds in wallet');
      break;
    case ERROR_CODES.WALLET_NOT_CONNECTED:
      console.log('Please connect your wallet');
      break;
    default:
      console.log('Unknown error occurred');
  }
};

🧪 Testing

import { 
  APTOS_TESTNET_USDC_ADDRESS,
  isValidAptosAddress,
  isValidAmount 
} from '@xapt/common';

// Test constants
console.log(APTOS_TESTNET_USDC_ADDRESS); // Should be valid address

// Test validation
console.log(isValidAptosAddress('0x123')); // false
console.log(isValidAptosAddress('0x1234567890abcdef...')); // true

console.log(isValidAmount('0.01')); // true
console.log(isValidAmount('-0.01')); // false
console.log(isValidAmount('abc')); // false

📋 Requirements

  • Node.js 16+
  • TypeScript 4.5+
  • Aptos blockchain access

🔗 Related Packages

📄 License

MIT License - see LICENSE file for details.

🤝 Contributing

We welcome contributions! Please see our contributing guidelines for more details.

🔗 Links