diff --git a/plugins/secure-storage/Cargo.toml b/plugins/secure-storage/Cargo.toml index 6c1ab766..a62d02ac 100644 --- a/plugins/secure-storage/Cargo.toml +++ b/plugins/secure-storage/Cargo.toml @@ -6,6 +6,7 @@ authors = { workspace = true } license = { workspace = true } repository = { workspace = true } links = "tauri-plugin-secure-storage" +description = "Store data in the platforms' keychains." [package.metadata.docs.rs] rustc-args = ["--cfg", "docsrs"] diff --git a/plugins/secure-storage/README.md b/plugins/secure-storage/README.md index 3268fe65..bc92206c 100644 --- a/plugins/secure-storage/README.md +++ b/plugins/secure-storage/README.md @@ -1,6 +1,8 @@ ![secure-storage](https://github.com/tauri-apps/plugins-workspace/raw/v2/plugins/secure-storage/banner.png) - +Store data in the platforms' keychains. + + | Platform | Supported | | -------- | --------- | @@ -12,6 +14,8 @@ ## Install + + _This plugin requires a Rust version of at least **1.77.2**_ There are three general methods of installation that we can recommend. @@ -33,23 +37,12 @@ tauri-plugin-secure-storage = { git = "https://github.com/tauri-apps/plugins-wor You can install the JavaScript Guest bindings using your preferred JavaScript package manager: -> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use. - - - ```sh pnpm add @tauri-apps/plugin-secure-storage # or npm add @tauri-apps/plugin-secure-storage # or yarn add @tauri-apps/plugin-secure-storage - -# alternatively with Git: -pnpm add https://github.com/tauri-apps/tauri-plugin-secure-storage#v2 -# or -npm add https://github.com/tauri-apps/tauri-plugin-secure-storage#v2 -# or -yarn add https://github.com/tauri-apps/tauri-plugin-secure-storage#v2 ``` ## Usage @@ -69,8 +62,24 @@ fn main() { Afterwards all the plugin's APIs are available through the JavaScript guest bindings: -```javascript +```typescript +import { setString, getString } from '@tauri-apps/plugin-secure-storage' +await setString('some-key', 'some-secret-value') + +const storedData = getString('some-key') + +console.log(storedData) // Should return `some-secret-value` +``` + +Similarily, the plugin also has Rust APIs: + +```rs +use tauri_plugin_secure_storage::SecureStorageExt; + +app.secure_storage().set_string("some-key", "some-secret-value"); + +let stored_data = app.secure_storage().get_string("some-key"); ``` ## Contributing diff --git a/plugins/secure-storage/guest-js/index.ts b/plugins/secure-storage/guest-js/index.ts index ced77e58..24ca858b 100644 --- a/plugins/secure-storage/guest-js/index.ts +++ b/plugins/secure-storage/guest-js/index.ts @@ -7,20 +7,20 @@ import { invoke } from '@tauri-apps/api/core' // TODO: functions to delete entries? export async function setString(key: string, value: string) { - return invoke('plugin:secure-storage|set_string', { key, value }) + return await invoke('plugin:secure-storage|set_string', { key, value }) } export async function getString(key: string): Promise { - return invoke('plugin:secure-storage|get_string', { key }) + return await invoke('plugin:secure-storage|get_string', { key }) } export async function setBinary( key: string, value: number[] | Uint8Array | ArrayBuffer ) { - return invoke('plugin:secure-storage|set_binary', { key, value }) + return await invoke('plugin:secure-storage|set_binary', { key, value }) } export async function getBinary(key: string): Promise { - return invoke('plugin:secure-storage|set_string', { key }) + return await invoke('plugin:secure-storage|set_string', { key }) }