1.0.7 • Published 5 months ago

easy-shamir-secret-sharing v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Secrets Library

這個庫提供了一些方法來生成隨機數、分割秘密和重建秘密。 This library provides methods to generate random numbers, split secrets, and reconstruct secrets.

此庫是基於 shamir-secret-sharing 進行改善,以逹到更好用。 This library is based on improvement of shamir-secret-sharing.

此庫提供了兩種編程風格:已實例化的物件風格和函數風格。 This library provides two programming styles: an instantiated object style and a functional style.

安裝 / Installation

首先,確保你已經安裝了必要的依賴項: First, make sure you have installed the necessary dependencies:

npm i easy-shamir-secret-sharing

使用方法 / Usage

初始化 class Secrets 在使用 Secrets 類之前,需要先導入並初始化它:

Before using the Secrets class, you need to import and initialize it:

import { Secrets } from 'easy-shamir-secret-sharing';
//or
import { secrets } from 'easy-shamir-secret-sharing';

分割秘密 / Split Secret

使用 share 方法將秘密分割成多個分享: Use the share method to split a secret into multiple shares:

const secret = "your-secret";
const numShares = 10;
const threshold = 5;
const shares = secrets.share(secret, numShares, threshold);
console.log(shares);

重建秘密 / Combine Secret

使用 combine 方法重建秘密: Use the combine method to reconstruct the secret:

const combinedSecret = secrets.combine(shares);
console.log(combinedSecret);

示例代碼 / Example Code

please run in async function

import { Secrets, secrets as secretsInstance } from 'easy-shamir-secret-sharing'
async function main()
{
    const message = "這是兩段重要的訊息";
    let secrets : any = new Secrets(message, 4, 3); //in real, no any type used
    await secrets.executeShares();
    console.log("分割後的訊息段:", secrets.getSharesResult());
    await secrets.executeCombine(secrets.getSharesResult());
    console.log("還原後的密文:", secrets.getCombinedResult());
    //or
    console.log("另一種風格");
    secrets = secretsInstance
    const arr = await secrets.share(message, 4, 3)
    console.log("分割後的訊息段:", arr);
    const combined = await secrets.combine(arr)
    console.log("還原後的密文:", combined);
}
main()

貢獻 / Contributing

歡迎提交問題和請求,或創建拉取請求來改進此庫。

Issues and requests are welcome, or create a pull request to improve this library

授權 / License

此項目基於 MIT 許可證,詳情請參閱 LICENSE 文件。 This project is licensed under the MIT License. See the LICENSE file for details.

額外 / Remain

reference: The MIT License (MIT)

Author of the original secrets.js library: Alexander Stetsyuk, Glenn Rempe

Author of this fork and modifications: xva001

@license MIT https://www.npmjs.com/package/secrets.js-grempe

The Library used @license Apache-2.0 shamir-secret-sharing

no warranty is given that this code is correct, and the author cannot be held responsible for any errors or omissions. rewrite by xva001 purpose: use typescript to rewrite the secrets.js-grempe library to use on other project (xva001 fogx -- nuxt) with no dependency on node crypto library.

repo npm

更新 / Update detail

2025-01-27 change reference to shamir-secret-sharing

First aims is making this work, and let other easy to use.

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago