Stronghold(堅牢化)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
「IOTA Stronghold」秘密管理エンジンを使用して、秘密情報と秘密鍵を保存します。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | ||
| ios |
はじめに、「stronghold」プラグインをインストールしてください。
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
npm run tauri add strongholdyarn run tauri add strongholdpnpm tauri add strongholddeno task tauri add strongholdbun tauri add strongholdcargo tauri add stronghold-
src-tauriフォルダで次のコマンドを実行して、このプラグインをCargo.toml内のプロジェクトの依存関係に追加します:cargo add tauri-plugin-stronghold -
追加したプラグインを初期化するために
lib.rsを修正します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_stronghold::Builder::new(|password| {}).build()).run(tauri::generate_context!()).expect("error while running tauri application");} -
お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします:
npm install @tauri-apps/plugin-strongholdyarn add @tauri-apps/plugin-strongholdpnpm add @tauri-apps/plugin-strongholddeno add npm:@tauri-apps/plugin-strongholdbun add @tauri-apps/plugin-stronghold
このプラグインは、「パスワード・ハッシュ」関数を使用して初期化する必要があります。この関数は、パスワード文字列を受け取り、その文字列に基づく 32 バイトのハッシュを返します。
ハッシュ hash: データから算出した「ちいさな値」。《参考: Wikipedia》
「Stronghold」プラグインでは、argon2 アルゴリズムを使用するデフォルトのハッシュ関数が使われています。
use tauri::Manager;
pub fn run() { tauri::Builder::default() .setup(|app| { let salt_path = app .path() .app_local_data_dir() .expect("could not resolve app local data path") .join("salt.txt"); app.handle().plugin(tauri_plugin_stronghold::Builder::with_argon2(&salt_path).build())?; Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}あるいは、tauri_plugin_stronghold::Builder::new コンストラクターを使用すれば、別のハッシュ・アルゴリズムを利用することもできます。
pub fn run() { tauri::Builder::default() .plugin( tauri_plugin_stronghold::Builder::new(|password| { // ここで argon2、blake2b、またはその他の安全なアルゴリズムを用いてパスワードのハッシュ値を生成します。 // 以下は、「`rust-argon2`」クレートを使用してパスワードのハッシュ値を生成するための実装例です。 use argon2::{hash_raw, Config, Variant, Version};
let config = Config { lanes: 4, mem_cost: 10_000, time_cost: 10, variant: Variant::Argon2id, version: Version::Version13, ..Default::default() }; let salt = "your-salt".as_bytes(); let key = hash_raw(password.as_ref(), salt, &config).expect("failed to hash password");
key.to_vec() }) .build(), ) .run(tauri::generate_context!()) .expect("error while running tauri application");}「Stronghold」プラグインは JavaScript で利用できます。
import { Client, Stronghold } from '@tauri-apps/plugin-stronghold';// `"withGlobalTauri": true` を使用する場合は、// const { Client, Stronghold } = window.__TAURI__.stronghold; を使用できますimport { appDataDir } from '@tauri-apps/api/path';// `"withGlobalTauri": true` を使用する場合は、// const { appDataDir } = window.__TAURI__.path; を使用できます
const initStronghold = async () => { const vaultPath = `${await appDataDir()}/vault.hold`; const vaultPassword = 'vault password'; const stronghold = await Stronghold.load(vaultPath, vaultPassword);
let client: Client; const clientName = 'name your client'; try { client = await stronghold.loadClient(clientName); } catch { client = await stronghold.createClient(clientName); }
return { stronghold, client, };};
// 「store」にレコードを挿入async function insertRecord(store: any, key: string, value: string) { const data = Array.from(new TextEncoder().encode(value)); await store.insert(key, data);}
// 「ストア」からレコードを読み取りasync function getRecord(store: any, key: string): Promise<string> { const data = await store.get(key); return new TextDecoder().decode(new Uint8Array(data));}
const { stronghold, client } = await initStronghold();
const store = client.getStore();const key = 'my_key';
// 「store」にレコードを挿入insertRecord(store, key, 'secret value');
// 「ストア」からレコードを読み取りconst value = await getRecord(store, key);console.log(value); // 'secret value'
// 更新内容を保存await stronghold.save();
// 「ストア」からレコードを削除await store.remove(key);デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。
詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。
{ ..., "permissions": [ "stronghold:default", ]}Default Permission
This permission set configures what kind of operations are available from the stronghold plugin.
Granted Permissions
All non-destructive operations are enabled by default.
This default permission set includes the following:
allow-create-clientallow-get-store-recordallow-initializeallow-execute-procedureallow-load-clientallow-save-secretallow-save-store-recordallow-save
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the create_client command without any pre-configured scope. |
|
|
Denies the create_client command without any pre-configured scope. |
|
|
Enables the destroy command without any pre-configured scope. |
|
|
Denies the destroy command without any pre-configured scope. |
|
|
Enables the execute_procedure command without any pre-configured scope. |
|
|
Denies the execute_procedure command without any pre-configured scope. |
|
|
Enables the get_store_record command without any pre-configured scope. |
|
|
Denies the get_store_record command without any pre-configured scope. |
|
|
Enables the initialize command without any pre-configured scope. |
|
|
Denies the initialize command without any pre-configured scope. |
|
|
Enables the load_client command without any pre-configured scope. |
|
|
Denies the load_client command without any pre-configured scope. |
|
|
Enables the remove_secret command without any pre-configured scope. |
|
|
Denies the remove_secret command without any pre-configured scope. |
|
|
Enables the remove_store_record command without any pre-configured scope. |
|
|
Denies the remove_store_record command without any pre-configured scope. |
|
|
Enables the save command without any pre-configured scope. |
|
|
Denies the save command without any pre-configured scope. |
|
|
Enables the save_secret command without any pre-configured scope. |
|
|
Denies the save_secret command without any pre-configured scope. |
|
|
Enables the save_store_record command without any pre-configured scope. |
|
|
Denies the save_store_record command without any pre-configured scope. |
【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】
© 2025 Tauri Contributors. CC-BY / MIT