npm package: @sahilw/dust-sdk
Description: Dust Protocol unified SDK — stealth addresses, ZK privacy pools, HTTP 402 payments
Author: Dust Protocol
Latest version: 0.1.0
Deprecated: Moved to dust-sdk (unscoped). Install: npm i dust-sdk

# @dust/sdk

[![npm version](https://img.shields.io/npm/v/@dust/sdk)](https://www.npmjs.com/package/@dust/sdk)

Unified entry point for the Dust Protocol SDK. Re-exports everything from `@dust/core`, `@dust/stealth`, and `@dust/pool` from a single import, plus the `DustSDK` class for constructing a configured SDK instance.

If you only need one capability, install the focused package instead (`@dust/stealth`, `@dust/pool`, `@dust/http402`). Use `@dust/sdk` when you need multiple features together.

## Installation

```bash
npm install @dust/sdk
```

## Quick Start

```typescript
import {
  DustSDK,
  fromRpcUrl,
  deriveV2Keys,
  deposit,
  withdraw,
  transfer,
  split,
  InMemoryStorage,
  NodeProofEngine,
  createPoolRelayer,
  generateStealthAddress,
  parseStealthMetaAddress,
  scanAnnouncements,
} from '@dust/sdk'

// Build a provider
const provider = fromRpcUrl('https://sepolia.drpc.org')

// Derive ZK keys
const keys = await deriveV2Keys(walletSignature, '123456')

// Create SDK instance
const sdk = DustSDK.create({
  provider,
  chainId: 11155111,
  storage: new InMemoryStorage(),
})

// Send to a stealth address
const meta = parseStealthMetaAddress('st:eth:0x...')
const { stealthAddress } = generateStealthAddress(meta, 11155111)

// Deposit into the privacy pool
const relayer = createPoolRelayer({ baseUrl: 'https://relayer.example.com' })
const result = await deposit(
  {
    provider,
    storage: sdk.storage,
    proofEngine: new NodeProofEngine(),
    relayer,
    keys,
    walletAddress: '0xYourAddress',
    chainId: 11155111,
    wasmPath: './circuits/DustV2Transaction.wasm',
    zkeyPath: './circuits/DustV2Transaction.zkey',
  },
  { amount: 100000000000000000n },
)

console.log('Deposited:', result.txHash)
```

## API Reference

### `DustSDK` class

A lightweight container that holds a configured provider, chain ID, and storage backend together. It does not orchestrate operations — use the standalone `deposit`, `withdraw`, `transfer`, and `split` functions from `@dust/pool`.

#### `DustSDK.create(config: DustSDKConfig): DustSDK`

```typescript
interface DustSDKConfig {
  provider: DustProvider
  chainId: number
  storage?: IStorageBackend   // defaults to InMemoryStorage
  proofEngine?: IProofEngine  // null if not provided
}
```

```typescript
const sdk = DustSDK.create({
  provider: fromRpcUrl('https://sepolia.drpc.org'),
  chainId: 11155111,
})

// sdk.provider   — DustProvider
// sdk.chainId    — number
// sdk.storage    — IStorageBackend (InMemoryStorage by default)
// sdk.proofEngine — IProofEngine | null
```

#### Static provider factory methods

These are aliases for the same functions from `@dust/core`:

```typescript
const provider = DustSDK.fromRpcUrl('https://sepolia.drpc.org')
const provider = DustSDK.fromViem(publicClient, walletClient)
const provider = DustSDK.fromEthers(ethersProvider, signer)
```

---

### Namespace exports

`@dust/sdk` also exports `core`, `stealth`, and `pool` as namespace objects for cases where you need to disambiguate conflicting exports:

```typescript
import { core, stealth, pool } from '@dust/sdk'

// core.deriveV2Keys — ZK key derivation (BN254)
// stealth.deriveSpendingSeed — PIN-based seed for secp256k1 stealth keys
// Both exist but have different signatures and purposes

const zkKeys = await core.deriveV2Keys(signature, pin)
const stealthSeed = await stealth.deriveSpendingSeed(signature, pin)
```

---

### All Re-exported APIs

`@dust/sdk` re-exports the complete public API of `@dust/core`, `@dust/stealth`, and `@dust/pool`. See their individual README files for full documentation:

**From `@dust/core`:**
- [`fromRpcUrl`, `fromEthers`, `fromViem`](../core/README.md#provider-adapters) — provider factory functions
- [`deriveV2Keys`, `deriveSpendingSeed`, `deriveViewingSeed`](../core/README.md#key-derivation) — key derivation
- [`poseidonHash`](../core/README.md#poseidon-hashing) — Poseidon hash
- [`createNote`, `createDummyNote`, `isDummyNote`, `generateBlinding`](../core/README.md#note-operations) — note creation
- [`computeNoteCommitment`, `computeNullifier`, `computeAssetId`, `computeOwnerPubKey`](../core/README.md#commitment-and-nullifier) — ZK commitments
- [`registerChain`, `getChainConfig`, `getSupportedChains`, `isChainSupported`, `getCanonicalNamingChain`, `getMinClaimableBalance`, `DEFAULT_CHAIN_ID`](../core/README.md#chain-configuration) — chain registry
- [`DustError`, `ProviderError`, `ProofError`, `StorageError`, `RelayerError`, `KeyDerivationError`, `ComplianceError`, `extractRelayerError`, `errorToUserMessage`](../core/README.md#error-classes) — errors
- [`BN254_FIELD_SIZE`, `TREE_DEPTH`, `MAX_AMOUNT`, `ZERO_VALUE`, `COMPLIANCE_COOLDOWN_THRESHOLD_USD`, `SCHEME_ID`, `ETH_ADDRESS`](../core/README.md#constants) — constants

**From `@dust/stealth`** (excludes `deriveSpendingSeed`/`deriveViewingSeed` which conflict with core):
- [`generateStealthAddress`, `computeStealthPrivateKey`, `verifyStealthAddress`, `computeViewTag`](../stealth/README.md#address-generation-erc-5564)
- [`computeStealthWalletAddress`, `computeStealthAccountAddress`](../stealth/README.md#address-generation-erc-5564)
- [`signWalletDrain`, `signWalletExecute`, `signUserOp`](../stealth/README.md#transaction-signing)
- [`generateStealthKeyPair`, `deriveStealthKeyPairFromSignature`, `deriveStealthKeyPairFromSignatureAndPin`](../stealth/README.md#key-management)
- [`formatStealthMetaAddress`, `parseStealthMetaAddress`, `isValidCompressedPublicKey`, `getPublicKeyFromPrivate`, `decompressPublicKey`](../stealth/README.md#key-management)
- [`validatePin`, `encryptPin`, `decryptPin`, `deriveClaimSeed`](../stealth/README.md#pin-functions)
- [`scanAnnouncements`, `scanAnnouncementsViewOnly`, `getAnnouncementCount`](../stealth/README.md#announcement-scanner)
- [`registerStealthMetaAddress`, `lookupStealthMetaAddress`, `isRegistered`, `signRegistration`, `getRegistryNonce`](../stealth/README.md#erc-6538-registry)
- [`registerStealthName`, `resolveStealthName`, `isNameAvailable`, `getNameOwner`, `getNamesOwnedBy`](../stealth/README.md#dust-name-registry)
- [`updateNameMetaAddress`, `transferStealthName`, `discoverNameByMetaAddress`](../stealth/README.md#dust-name-registry)
- [`deriveClaimAddresses`, `deriveClaimAddressesWithPin`, `getNextClaimAddress`, `verifyClaimAddressDerivation`](../stealth/README.md#hd-claim-addresses)
- [`signDrain7702`, `signInitialize7702`, `buildSignedAuthorization`](../stealth/README.md#eip-7702-delegation)
- [`createRelayerClient`](../stealth/README.md#relayer-client)
- ABIs: `STEALTH_WALLET_FACTORY_ABI`, `STEALTH_ACCOUNT_FACTORY_ABI`, `ENTRY_POINT_ABI`, `DUST_PAYMASTER_ABI`, `STEALTH_SUB_ACCOUNT_7702_ABI`

**From `@dust/pool`:**
- [`deposit`, `withdraw`, `transfer`, `split`](../pool/README.md#pool-operations) — pool operations
- [`InMemoryStorage`, `JsonFileStorage`](../pool/README.md#storage) — storage backends
- [`NodeProofEngine`](../pool/README.md#proof-engine) — FFLONK proof generation
- [`createPoolRelayer`](../pool/README.md#pool-relayer) — relayer client
- [`deriveViewKey`, `serializeViewKey`, `deserializeViewKey`](../pool/README.md#view-keys) — view keys
- [`checkDepositorCompliance`, `checkCooldownStatus`](../pool/README.md#compliance) — compliance
- [`ETH_DENOMINATIONS`, `USDC_DENOMINATIONS`, `decompose`, `decomposeForToken`, `decomposeForSplit`](../pool/README.md#denominations) — denominations
- [`DUST_POOL_V2_ABI`, `getDustPoolV2Address`, `getDustPoolV2Config`](../pool/README.md#contract-utilities) — contracts
- Storage utilities: `bigintToHex`, `hexToBigint`, `storedToNoteCommitment`, `noteToStored`, `getBalance`, `getAllBalances`
- Encryption: `deriveStorageKey`, `encryptNotePayload`, `decryptNotePayload`
- Proof inputs: `buildDepositInputs`, `buildWithdrawInputs`, `buildTransferInputs`, `buildSplitInputs`, `buildSwapInputs`

---

## Supported Chains

Built-in chain configurations (registered automatically on import):

| Chain | ID | DustPool V2 |
|-------|----|-------------|
| Ethereum Sepolia | 11155111 | `0x3cbf3459e7E0E9Fd2fd86a28c426CED2a60f023f` |
| Arbitrum Sepolia | 421614 | `0x07E961c0d881c1439be55e5157a3d92a3efE305d` |
| Base Sepolia | 84532 | `0x17f52f01ffcB6d3C376b2b789314808981cebb16` |

Register additional chains with `registerChain()`.

## License

MIT