npm package: @fusion-wallet/wallet-app
Description: Wallet app WASM package for Flutter Fusion Wallet
Author: Fusion Wallet Team
Latest version: 1.1.0

# @fusion-wallet/wallet-app

A WebAssembly package for Flutter Fusion Wallet that provides notification delegate and payment functionality.

## Installation

```bash
npm install @fusion-wallet/wallet-app
```

## Usage

### Basic Usage

```javascript
import createNotificationDelegate from '@fusion-wallet/wallet-app';

// Create a notification delegate request
const requestData = await createNotificationDelegate(
    'canister-id-here',
    'delegate-principal-here', 
    'example.com',
    'My App'
);

console.log('Request data:', requestData); // Uint8Array
```

### Payment Delegation

```javascript
import { createDelegatePayment } from '@fusion-wallet/wallet-app';

// Create a delegate payment request
const paymentData = await createDelegatePayment(
    'token-id-here',
    '1000000', // amount in smallest unit
    'delegate-principal-here'
);

console.log('Payment data:', paymentData); // Uint8Array
```

### Fusion Wallet URL Generation

```javascript
import { createFusionWalletUrl } from '@fusion-wallet/wallet-app';

// Create a Fusion Wallet connection URL
const walletUrl = createFusionWalletUrl(
    'p2p-address-here',
    'example.com'
);

console.log('Wallet URL:', walletUrl); // wd://app.fusionwallet.me/connect/...
```

### Advanced Usage

```javascript
import { create_notification_delegate, create_delegate_payment, WalletRequest, initializeWalletApp } from '@fusion-wallet/wallet-app';

// Initialize manually if needed
const walletApp = await initializeWalletApp();

// Use the direct functions
const requestData = walletApp.createNotificationDelegate(
    'canister-id-here',
    'delegate-principal-here',
    'example.com', 
    'My App'
);

const paymentData = walletApp.createDelegatePayment(
    'token-id-here',
    '1000000',
    'delegate-principal-here'
);

// Access the WalletRequest enum
console.log(WalletRequest.SignNotificationDelegate); // 0
console.log(WalletRequest.CustomRequest); // 1
```

## API Reference

### `createNotificationDelegate(canister_id, delegate_principal, domain, app_name)`

Creates a notification delegate request.

**Parameters:**
- `canister_id` (string): The canister ID
- `delegate_principal` (string): The delegate principal
- `domain` (string): The domain
- `app_name` (string): The application name

**Returns:** Promise<Uint8Array> - The serialized request data

### `createDelegatePayment(token_id, amount, delegate_principal)`

Creates a delegate payment request.

**Parameters:**
- `token_id` (string): The token ID
- `amount` (string): The amount in smallest unit (e.g., e8s for ICP)
- `delegate_principal` (string): The delegate principal

**Returns:** Promise<Uint8Array> - The serialized payment request data

### `createFusionWalletUrl(p2pAddr, domain)`

Creates a Fusion Wallet connection URL.

**Parameters:**
- `p2pAddr` (string): The P2P address
- `domain` (string): The domain

**Returns:** string - The Fusion Wallet connection URL

### `WalletRequest` Enum

```javascript
enum WalletRequest {
    SignNotificationDelegate = 0,
    CustomRequest = 1
}
```

### `initializeWalletApp()`

Manually initializes the WASM module and returns the raw functions.

**Returns:** Promise<Object> - Object containing the raw functions

## Package Exports

The package provides multiple export patterns:

```javascript
// Default export (recommended for most use cases)
import createNotificationDelegate from '@fusion-wallet/wallet-app';

// Named exports for advanced usage
import { createDelegatePayment, createFusionWalletUrl, WalletRequest } from '@fusion-wallet/wallet-app';

// Direct WASM functions (for advanced users)
import { create_notification_delegate, create_delegate_payment } from '@fusion-wallet/wallet-app';
```

## Building

To build the package:

```bash
npm run build
```

For different targets:

```bash
npm run build:node      # Node.js target
npm run build:bundler   # Bundler target
```

## Development

```bash
npm run clean          # Clean build artifacts
npm run prepublishOnly # Build before publishing
```

## Examples

See `example.js` for complete usage examples.

## License

MIT