Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Native Lib Readme Init #210

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions js/packages/seed-vault/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
# `@solana-mobile/seedvaultlib`

A React Native wrapper of the Seed Vault SDK.

# Usage

### Check if Seed Vault is Available
We first need to check if the seed vault service is available on the device. Currently only Saga implementes a seed vault.
```javascript
cosnt 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
}
```

### Add Listeners

Before interacting with Seed Vault, you should first register callbacks from the Seed Vault service using the `useSeedVault` hook.
```javascript

const seedVaultEventListener = (event) => {
// event is SeedVaultEvent type
// handle event here
};

const seedVaultContentChangeListener = (contentChangeEvent) => {
// contentChangeEvent is SeedVaultContentChange type
// handle content change here
};

useSeedVault(seedVaultEventListener, seedVaultContentChangeListener);
```

### Authorize a Seed
Before our app can urequest signatures form seed vault, we must first request authorization for our app to use a seed from the user.
```javascript
NativeModules.SeedVaultLib.authorizeNewSeed();
```

### 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 NativeModules.SolanaMobileSeedVaultLib.getAuthorizedSeeds();
```

### 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 NativeModules.SolanaMobileSeedVaultLib.getAccounts(seed.authToken);
```

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