<!--
Sitemap:
- [MBGA · Reactive Primitives for Spark](/index)
- [Acknowledgments](/acknowledgments)
- [API Reference](/api/)
- [Connectors](/connectors/)
- [Examples](/examples/)
- [Flashnet](/flashnet/)
- [Getting Started](/getting-started)
- [Installation](/installation)
- [Kit](/kit/)
- [Configuration](/api/configuration)
- [Core Actions](/api/core-actions)
- [React Hooks](/api/hooks)
- [Types & Errors](/api/types)
- [Custom Connectors](/connectors/custom)
- [Sats Connect (Xverse)](/connectors/sats-connect)
- [Spark SDK](/connectors/spark-sdk)
- [Wallet Standard](/connectors/wallet-standard)
- [Flashnet Authentication](/flashnet/authentication)
- [Next.js](/frameworks/nextjs)
- [Vite](/frameworks/vite)
- [AccountModal](/kit/account-modal)
- [ConnectButton](/kit/connect-button)
- [ConnectModal](/kit/connect-modal)
-->

# Flashnet

[Flashnet](https://flashnet.xyz/) is a cross-chain orchestration layer that enables atomic swaps between BTC, Lightning, Spark, and other assets. The `@mbga/flashnet` package provides challenge-response authentication and intent signing for the Flashnet API.

## Installation

:::code-group

```bash [pnpm]
pnpm add @mbga/flashnet
```

```bash [npm]
npm install @mbga/flashnet
```

```bash [yarn]
yarn add @mbga/flashnet
```

:::

For React hooks, also install the optional peer dependencies:

```bash
pnpm add react @tanstack/react-query
```

## How It Works

Flashnet uses **wallet-based authentication**, not API keys. The flow is:

1. **Challenge** -- your app requests a challenge from `POST /v1/auth/challenge`
2. **Sign** -- the connected wallet signs the challenge with its identity key (SHA256 + secp256k1)
3. **Verify** -- the signature is sent to `POST /v1/auth/verify` to get an access token
4. **Use** -- all subsequent requests include the access token as a Bearer header

Operations like swaps use **intent-based signing** -- each action generates a JSON intent, SHA256 hashes it, and signs with the wallet key.

## Architecture

`@mbga/flashnet` uses an **extension pattern** that integrates with MBGA's config system:

```ts
const flashnet = createFlashnetExtension()

const config = createConfig({
  extensions: { flashnet }, // auto-runs plugin, captures config, fully typed
})

// config.extensions.flashnet is typed as FlashnetExtension
await flashnet.authenticate() // no config arg needed
```

The extension is a standalone object that:

* Registers via `createConfig({ extensions: { ... } })` for seamless integration
* Manages its own auth state (tokens, status)
* Auto-clears auth when the wallet disconnects
* Provides `request()` for authenticated API calls
* Provides `signIntent()` for operation signing

| Entrypoint | Import path | Requires React |
|------------|-------------|---------------|
| Root | `@mbga/flashnet` | No |
| Actions | `@mbga/flashnet/actions` | No |
| React | `@mbga/flashnet/react` | Yes |

## Quick Example

```ts
import { createFlashnetExtension } from '@mbga/flashnet'
import { createConfig, sparkMainnet } from '@mbga/core'
import { sparkSdk } from '@mbga/connectors'

const flashnet = createFlashnetExtension()

const config = createConfig({
  network: sparkMainnet,
  connectors: [sparkSdk({ mnemonic: '...' })],
  extensions: { flashnet },
})

// After wallet connection:
await flashnet.authenticate()
const routes = await flashnet.request('/v1/routes')
```

## Next Steps

* [Authentication](/flashnet/authentication) -- detailed auth setup with wallet or custom signer
