> ## Documentation Index
> Fetch the complete documentation index at: https://privacycash.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Frontend Integration

## Demo Project

A complete example project demonstrating how to use PrivacyCash SDK:

[https://github.com/Privacy-Cash/solana-sdk-demo-interface](https://github.com/Privacy-Cash/solana-sdk-demo-interface)

## Installation

```bash theme={null}
npm install privacycash --save
```

<Info>
  Requires **Node.js 24+**. The SDK is written in TypeScript and includes type definitions.
</Info>

## Deriving Encryption Key

Client need to ask user to sign an offchain message, before the user can interact with Privacy Cash.

```typescript theme={null}
async function getSignedSignature(signed: Signed) {
    if (signed.signature) {
        return
    }
    const encodedMessage = new TextEncoder().encode(`Privacy Money account sign in`)
    const cacheKey = `zkcash-signature-${signed.publicKey.toBase58()}`

    // ask for sign
    let signature: Uint8Array
    try {
        signature = await signed.provider.signMessage(encodedMessage)
    } catch (err: any) {
        if (err instanceof Error && err.message?.toLowerCase().includes('user rejected')) {
            throw new Error('User rejected the signature request')
        }
        throw new Error('Failed to sign message: ' + err.message)
    }
    
    if (currentSigned.pubKeyStr != signed.publicKey.toString()) {
        throw new Error(`Don't switch account when signing in. Refresh the page and try again.`)
    }

    // If wallet.signMessage returned an object, extract `signature`
    // @ts-ignore
    if (signature.signature) {
        // @ts-ignore
        signature = signature.signature
    }

    if (!(signature instanceof Uint8Array)) {
        throw new Error('signature is not an Uint8Array type')
    }
    signed.signature = signature
}

export type Signed = {
    publicKey: PublicKey,
    signature?: Uint8Array,
    provider: any
}
```

Once the user signed the message, pass the resulting signature to EncryptionService of the SDK:

```typescript theme={null}
export * from "privacycash/utils"

let encryptionService = new EncryptionService();
encryptionService.deriveEncryptionKeyFromSignature(signed.signature);
```

## Get hasher

```typescript theme={null}
const { WasmFactory } = await import('@lightprotocol/hasher.rs');
const hasher = await WasmFactory.getInstance();
```

## Common Issues

1. Next.js project needs to update the postinstall build scripts:
   ```text theme={null}
   "scripts": {
       "postinstall": "cp node_modules/@lightprotocol/hasher.rs/dist/hasher_wasm_simd_bg.wasm node_modules/@lightprotocol/hasher.rs/dist/browser-fat/es/ && cp node_modules/@lightprotocol/hasher.rs/dist/light_wasm_hasher_bg.wasm node_modules/@lightprotocol/hasher.rs/dist/browser-fat/es/",
   },..}
   ```
