> For the complete documentation index, see [llms.txt](https://docs.veilnyx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.veilnyx.com/veilnyx-sdk/shielded-account.md).

# Shielded Account

`ShieldedAccount` defines a shielded account of a user that holds private assets. Only the holder of the account can spend assets attached to it and view balances and transaction history. Unlike Ethereum wallets, which contain a single public-private key pair, the shielded accounts have two such key pairs.

* **Sign Key**: This is the most sensitive key used to sign transactions and must not be revealed under any circumstances. This is analogous to the private key of an Ethereum wallet. Not your keys, not your assets.
* **View Key**: The purpose of the view key is to reveal your transaction history or balances. It cannot be used to spend assets in the account. It only gives view access. This may be requested by websites to display data or create new transactions.

For security and recoverability, the shielded account keys are derived from your public wallet itself. So as long as you have access to your Ethereum wallet, you have access to the shielded account. But that also means losing your wallet keys also compromises your shielded account.

### API

```typescript
interface ShieldedAccount {
    signer: ISigner;
    viewer: Viewer;
    async sign(message: BytesLike): Promise<SchnorrSignature>;
    async signTransaction(tx: ITransaction): Promise<ITransaction>;
    encrypt(data: Uint8Array, entropy: bigint): Uint8Array;
    decrypt(encryptedData: Uint8Array): Uint8Array;
}
```

## Signer

`ISigner` It is an interface for the signer class. An `Account` requires an instance of such a signer for signing transactions, which authorizes the spending of assets in the user's shielded account.

```typescript
export interface ISigner {
  readonly privateKey?: bigint;
  readonly publicKey: IPoint;

  sign(message: BigIntLike): Promise<SchnorrSignature>;
  verifySign(message: BigIntLike, sign: SchnorrSignature): Promise<boolean>;
}
```

Although `ISigner` can be implemented for different environments like wallets, currently SDK already provides two implementations.

### `Signer`

This is a simple signer that holds  `privateKey` in memory. Using this is more suitable for CLI applications using the SDK for private transactions.

```typescript
import { Signer } from '@veilnyx-sdk/account';

const privateKey = '0x...';

const signer = new Signer(privateKey);
```

### `MetamaskSigner`

*(Soon)*\
This class is more suitable for browser apps. This acts as an interface to the \[Veilnyx Snap] instead of storing a shielded private key. Invoking the sign methods, i.e. `sign(...)` and `signTransaction(...)` On it will open up the Metamask pop-up requesting a signature from the user. This is recommended for web apps.

```typescript
import { MetamaskSigner } from '@veilnyx-sdk/account';

const publicKey = '0x...'; // packed point

const mmSigner = new MetamaskSigner(publicKey);
```

### Other Implementations

Other environments for getting signatures can be seamlessly integrated by all kinds of crypto wallets/environments, e.g. Ledge, by implementing `ISigner` an interface. More ready-made implementations will be coming soon:wink:.

## Viewer

`Viewer` It is a class with the ability to decrypt and view users' balances and transactions. An instance of a viewer is created using a view private key.

```typescript
import { Viewer } from '@veilnyx-sdk/account';

const privateKey = '0x...';

const viewer = new Viewer(privateKey);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.veilnyx.com/veilnyx-sdk/shielded-account.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
