npm package: @safer-sh/common
Description: Common utilities and configuration for SAFER wallet
Author: zhixian@unipass
Latest version: 0.1.2

# @safer-sh/common

Common utilities and configuration module for Safer - a minimal Ethereum Safe multi-signature wallet client.

> ---
> #### ⚠️ Disclaimer ⚠️
> This tool is NOT intended for production environments or for managing significant funds.
> 
> - Only use this tool on trusted machines in a secure environment
> - Do not use this tool to manage large amounts of funds
> - Do not share data generated by this tool with untrusted third parties
> ---

## Overview

The `@safer-sh/common` package provides shared utilities and configuration management for the Safer wallet ecosystem. It includes essential functionality for transaction handling, configuration management, and IPFS integration, all with minimal dependencies to reduce supply chain attack risks.

## Installation

```bash
npm install @safer-sh/common
```

## Key Components

### SaferTransaction Class

The `SaferTransaction` class is the core data structure used throughout the Safer ecosystem to represent and manage transactions:

```javascript
const { SaferTransaction } = require('@safer-sh/common');

// Create a new transaction object
const tx = new SaferTransaction({
  hash: '0x123...',
  safeAddress: '0xYourSafeAddress',
  to: '0xRecipientAddress',
  value: '1500000000000000000', // 1.5 ETH in wei
  data: '0x',
  operation: 0,
  nonce: 1
});

// Add metadata
tx.addMetadata({
  type: 'transfer',
  description: 'ETH transfer',
  createdAt: Date.now()
});

// Add a signature
tx.addSignature({
  owner: '0xOwnerAddress',
  signature: '0xSignatureData'
});
```

### Configuration Management

The common package includes configuration providers for managing Safer settings:

```javascript
const { configManager } = require('@safer-sh/common/config');

// Read configuration
const config = configManager.readConfig();

// Update configuration
configManager.updateConfig({
  rpcUrl: 'https://your-rpc-endpoint',
  chainId: 1,
  defaultSafe: '0xYourSafeAddress'
});

// Get configured wallets
const wallets = configManager.getWallets();
```

### Transaction Management

The package provides transaction management with both file-based and IPFS storage options:

```javascript
const { transactionManager } = require('@safer-sh/common/config');

// Save a transaction
await transactionManager.saveTransaction(txObject);

// Get a transaction by hash
const tx = await transactionManager.getTransaction(txHash);

// List all transactions
const allTxs = await transactionManager.listTransactions();

// Export to IPFS
const ipfsUri = await transactionManager.exportTransactionToIPFS(txHash);

// Import from IPFS
const importedTx = await transactionManager.importTransactionFromIPFS(ipfsUri);
```

### Utilities

The package includes various utility functions for working with Ethereum addresses, transactions, and more:

```javascript
const { utils } = require('@safer-sh/common/config/utils');

// Resolve owner from identifier (address, name, address tail, or index)
const ownerAddress = await utils.resolveOwnerFromIdentifier(identifier);

// Initialize a signer
const signer = await utils.initializeSigner(ownerConfig, provider);

// Parse chain ID or name
const chainId = utils.parseChain('sepolia');
```

## Security Considerations

This package is designed with security in mind:
- Minimal dependencies (primarily `ethers.js`)
- File-based configuration with clear permissions
- Support for secure transaction sharing via IPFS

## License

MIT License

## Related Packages

- [@safer-sh/core](https://www.npmjs.com/package/@safer-sh/core) - Core functionality
- [@safer-sh/cli](https://www.npmjs.com/package/@safer-sh/cli) - Command line interface
- [@safer-sh/mcp](https://www.npmjs.com/package/@safer-sh/mcp) - AI agent integration
- [@safer-sh/ledger-signer](https://www.npmjs.com/package/@safer-sh/ledger-signer) - Ledger hardware wallet integration