npm package: @solana-mobile/seed-vault-lib
Description: A React Native wrapper of the Solana Mobile, Seed Vault SDK. Apps can use this to interact with seed vault implementations on Android
Author: Marco Martinez
Latest version: 0.4.1

# `@solana-mobile/seed-vault-lib`

A React Native wrapper of the Seed Vault SDK.

## Community Maintained

This React Native library is a community-maintained wrapper around the [Seed Vault SDK](../../../README.md). It is not actively maintained or production-tested by Solana Mobile.

Contributions are welcome and encouraged! If you encounter bugs or need new features, please open a PR — this library improves when the community that depends on it helps build it.

If you need a production-grade integration, we recommend using the native Java/Kotlin Seed Vault SDK directly.

# Usage

### Check if Seed Vault is Available
We first need to check if the seed vault service is available on the device. Currently only devices from Solana Mobile implement a seed vault. 
```javascript
const allowSimulated = false; // use true to allow simulated seed vault (for dev/testing)
const seedVaultAvailable = await SolanaMobileSeedVaultLib.isSeedVaultAvailable(allowSimulated);
if (!seedVaultAvailable) {
  // seed vault is not available, we cant use it
}
```

### Request Seed Vault Permission
Before we can interact with Seed vault, we must request permission for our app to use Seed Vault. 
```javascript
import { PermissionsAndroid } from 'react-native';
import { SeedVaultPermissionAndroid } from '@solana-mobile/seed-vault-lib';

const permissionResult = await PermissionsAndroid.request(
  SeedVaultPermissionAndroid,
  { // customize verbage here to your liking 
    title: 'Seed Vault Permission',
    message: 
      'This app needs your permission to access Seed Vault',
    buttonNeutral: 'Ask Me Later',
    buttonNegative: 'Cancel',
    buttonPositive: 'OK',
  },
);

if (permissionResult === PermissionsAndroid.RESULTS.GRANTED) {
  // we can use seed vault, continue
} else {
  // permission was denied, fallback
}
```

Read more about requesting Android Permission in React Native [here](https://reactnative.dev/docs/permissionsandroid).

### Authorize a Seed
Before our app can access any seeds in the seed vault, we must first request authorization for our app to use a seed from the user.
```javascript
import { SeedVault } from "@solana-mobile/seed-vault-lib";

const result = await SeedVault.authorizeNewSeed();
console.log(`New seed authorized! auth token: ${result.authToken}`);
```

### Retreive a list of Authorized Seeds
To retreive a list of all the seeds our app has been authorized to use, call `getAuthorizedSeeds()`.
```javascript
const authorizedSeeds = await SeedVault.getAuthorizedSeeds()
```

This will return a list of `Seed` objects with the following structure 
```
{
  authToken: number;
  name: string;
  purpose: int;
} 
```

### Get Accounts for a given seed
Once we have obtained an authorized seed, we can get a list of all the accounts (public keys) assocaited with that seed
```javascript
const seed = authorizedSeeds[0]
const accounts = await SeedVault.getAccounts(seed.authToken)
```

### Retreive the PublicKey of an Account
Once we have obtained an authorized seed, we can get a list of all the accounts (public keys) assocaited with that seed
```javascript
const account = account[0]
const publicKey = await SeedVault.getPublicKey(seed.authToken, account.derivationPath);
// can now build transaction using the public key
```

This will return a `SeedPublicKey` object with the following structure 
```
{
  publicKey: Uint8Array;
  publicKeyEncoded: string;
  resolvedDerivationPath: string;
}
```

### Sign a Payload
Once we have obtained an account, we can request signatures from seed vault for that account: 
```javascript
SeedVault.signMessage(seed.authToken, account.derivationPath, messageBytes);
SeedVault.signTransaction(seed.authToken, account.derivationPath, transactionByteArray);
```