From ec475d2dd815378ee3f5dc46b375c60506e806f3 Mon Sep 17 00:00:00 2001 From: Marco Martinez Date: Thu, 29 Feb 2024 17:25:05 -0700 Subject: [PATCH 1/2] Update README.md --- js/packages/seed-vault/README.md | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/js/packages/seed-vault/README.md b/js/packages/seed-vault/README.md index 850092f..827e02c 100644 --- a/js/packages/seed-vault/README.md +++ b/js/packages/seed-vault/README.md @@ -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 + +var seedVaultEventListener = (event) => { + // event is SeedVaultEvent type + // handle event here +}; + +var 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); +``` + From 19a972bdd5a99533cbb08a96ed291d13f6250148 Mon Sep 17 00:00:00 2001 From: Marco Martinez Date: Fri, 1 Mar 2024 13:35:09 -0700 Subject: [PATCH 2/2] pr feedback --- js/packages/seed-vault/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/packages/seed-vault/README.md b/js/packages/seed-vault/README.md index 827e02c..792afc6 100644 --- a/js/packages/seed-vault/README.md +++ b/js/packages/seed-vault/README.md @@ -19,12 +19,12 @@ if (!seedVaultAvailable) { Before interacting with Seed Vault, you should first register callbacks from the Seed Vault service using the `useSeedVault` hook. ```javascript -var seedVaultEventListener = (event) => { +const seedVaultEventListener = (event) => { // event is SeedVaultEvent type // handle event here }; -var seedVaultContentChangeListener = (contentChangeEvent) => { +const seedVaultContentChangeListener = (contentChangeEvent) => { // contentChangeEvent is SeedVaultContentChange type // handle content change here };