{"id":19767805,"url":"https://github.com/lighthouse-web3/encryption-sdk","last_synced_at":"2025-04-07T13:10:25.884Z","repository":{"id":64887904,"uuid":"578104680","full_name":"lighthouse-web3/encryption-sdk","owner":"lighthouse-web3","description":"Build your trustless, decentralized and fault tolerant Applications using distributed key shards with threshold cryptography","archived":false,"fork":false,"pushed_at":"2025-01-25T06:48:35.000Z","size":602,"stargazers_count":29,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T12:06:54.706Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lighthouse-web3.png","metadata":{"files":{"readme":"readme.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-14T09:14:10.000Z","updated_at":"2025-03-19T14:50:38.000Z","dependencies_parsed_at":"2023-12-28T19:28:54.260Z","dependency_job_id":"ef3ac794-f509-4e62-91b5-8992f6c5f59c","html_url":"https://github.com/lighthouse-web3/encryption-sdk","commit_stats":{"total_commits":108,"total_committers":5,"mean_commits":21.6,"dds":0.6296296296296297,"last_synced_commit":"7ca7d61662ffabc455b07bc50bb6ad2f7c377e6a"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lighthouse-web3%2Fencryption-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lighthouse-web3%2Fencryption-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lighthouse-web3%2Fencryption-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lighthouse-web3%2Fencryption-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lighthouse-web3","download_url":"https://codeload.github.com/lighthouse-web3/encryption-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657282,"owners_count":20974345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T04:32:29.205Z","updated_at":"2025-04-07T13:10:25.827Z","avatar_url":"https://github.com/lighthouse-web3.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kavach \u003cimg src=\"https://img.shields.io/badge/BETA-v0.2.0-green\"/\u003e\n\nKavach is an encryption SDK that allows you to build your trustless, decentralized and fault-tolerant Applications using distributed key shards with threshold cryptography\n\n## Features\n\n- Randomized key shard generation\n- Shard Key support for privateKey and other security keys\n- Key Reconstruction from shards\n- Fully typed, support in TypeScript\n- Lighthouse Encryption Key storage(Optional 5 nodes)\n\n## Install\n\nJust use your favorite package manager to add `lighthouse-kavach to your project:\n\n```sh\nyarn add @lighthouse-web3/kavach\n\nnpm i @lighthouse-web3/kavach\n\n```\n\n## Methods\n\n- ### _generate ( threshold?: number, keyCount?: number)_\n\nThis method generates randomized key shards\n\n#### Parameters\n\n| Name      | Type             | Default | Description                                                                               |\n| --------- | ---------------- | ------- | ----------------------------------------------------------------------------------------- |\n| threshold | number(optional) | 3       | minimum amount of key required to recover master key                                      |\n| keyCount  | number(optional) | 5       | number of shades to be generated (**Note**: _must be greater than or equal to threshold_) |\n\n#### returns\n\n| Name      | Type                        | Description           |\n| --------- | --------------------------- | --------------------- |\n| masterKey | string                      | 32 byte string or key |\n| keyShards | {key:string,index:string}[] | key shards            |\n\n#### Demo\n\n```javascript\nimport { generate } from \"@lighthouse-web3/kavach\";\n\nasync function main() {\n  const { masterKey, keyShards } = await generate();\n  console.log(`masterKey: ${masterKey}`);\n  console.log(`keyShards:`, keyShards);\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\n- ### _recoverKey (keyShards: keyShard[])_\n\nThis method recovers the master key from the shards generated\n\n#### Parameters\n\n| Name     | Type                        | Description                                          |\n| -------- | --------------------------- | ---------------------------------------------------- |\n| keyShard | {key:string,index:string}[] | minimum amount of key required to recover master key |\n\n#### returns\n\n| Name      | Type       | Description           |\n| --------- | ---------- | --------------------- |\n| masterKey | string     | 32 byte string or key |\n| error     | ErrorValue | null                  |\n\n#### Demo\n\n```javascript\nimport { generate, recoverKey } from \"@lighthouse-web3/kavach\";\n\nasync function main() {\n  const { masterKey, keyShards } = await generate();\n\n  const { masterKey: recoveredKey } = await recoverKey(keyShards);\n  console.log(masterKey === recoveredKey); //true\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\n- ### _shardKey (key: string,threshold?: number, keyCount?: number)_\n\nshard existing Key into shards\n\n#### Parameters\n\n| Name      | Type             | Default | Description                                                                               |\n| --------- | ---------------- | ------- | ----------------------------------------------------------------------------------------- |\n| key       | string           |         | 32 byte string or key                                                                     |\n| threshold | number(optional) | 3       | minimum amount of key required to recover master key                                      |\n| keyCount  | number(optional) | 5       | number of shades to be generated (**Note**: _must be greater than or equal to threshold_) |\n\n#### returns\n\n| Name        | Type       | Description                             |\n| ----------- | ---------- | --------------------------------------- |\n| isShardable | boolean    | return true is the key could be sharded |\n| keyShards   | keyShard[] | shards                                  |\n\n#### Demo\n\n```javascript\nimport { shardKey, recoverKey } from \"@lighthouse-web3/kavach\";\n\nasync function main() {\n  // known key customly generated or from ether random wallet privateKey\n  // Note: Not all keys are shardable\n  const knownKey =\n    \"554f886019b74852ab679258eb3cddf72f12f84dd6a946f8afc4283e48cc9467\";\n  const { isShardable, keyShards } = await shardKey(knownKey);\n  console.log(isShardable); // true\n\n  //recover keys from shards\n  const { masterKey } = await recoverKey(keyShards);\n\n  //check if the key recovered was recovered\n  console.log(masterKey === knownKey); //true\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\n- ### _saveShards( address: string, cid: string, auth_token: string, keyShards: keyShard[5] | any[5], shareTo : string[])_\n\nBackup key to lighthouse's Node\n\n#### Parameters\n\n| Name       | Type                              | Default | Description                                   |\n| ---------- | --------------------------------- | ------- | --------------------------------------------- |\n| address    | string                            |         | address of the owner of the key               |\n| cid        | string                            |         | unique id or file CID                         |\n| auth_token | string                            |         | signed Message gotten from getAuthMessage/JWT |\n| keyShards  | Array\u003c{key:string; index:string}\u003e |         | An array of 5 key shards/ element             |\n| shareTo    | Array\u003c address \u003e(Optional)        | []      | An array of address                           |\n\n#### returns\n\n| Name      | Type       | Description          |\n| --------- | ---------- | -------------------- |\n| isSuccess | boolean    | return true is saved |\n| error     | ErrorValue | Errors               |\n\n#### Demo\n\n```javascript\nimport { getAuthMessage, saveShards, generate } from \"@lighthouse-web3/kavach\";\nimport { ethers } from \"ethers\";\n\nasync function main() {\n  const signer = new ethers.Wallet(\n    \"0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c8b\"\n  );\n\n  const { masterKey, keyShards } = await generate();\n\n  const authMessage = await getAuthMessage(signer.address);\n  const signedMessage = await signer.signMessage(authMessage.message);\n\n  const { error, isSuccess } = await saveShards(\n    signer.address,\n    \"QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH\",\n    signedMessage,\n    keyShards\n  );\n\n  console.log(error === null); // true;\n  console.log(isSuccess === true); //true;\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\n- ### _recoverShards( address: string, cid: string, auth_token: string, dynamicData:{},)_\n\nrecover key shards to lighthouse's Node\n\n#### Parameters\n\n| Name        | Type                                                        | Default | Description                                                                                             |\n| ----------- | ----------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------- |\n| address     | string                                                      |         | address of the owner of the key                                                                         |\n| cid         | string                                                      |         | unique id or file CID                                                                                   |\n| auth_token  | string                                                      |         | signed Message gotten from getAuthMessage/JWT                                                           |\n| keyCount    | number(optional)                                            | 3       | number of nodes to ping for shards (**Note**: _must be less than or equal to 5_)                        |\n| dynamicData | object\u003c{[`conditionID`.`parameterName`]: value} \u003e(Optional) | {}      | This is used to pass additional or dynamic data like a signature during key recovery with AccessControl |\n\n#### returns\n\n| Name      | Type                              | Description                      |\n| --------- | --------------------------------- | -------------------------------- |\n| keyShards | Array\u003c{key:string; index:string}\u003e | key shards recovered fromm nodes |\n| error     | ErrorValue                        | Errors                           |\n\n#### Demo\n\n```javascript\nimport {\n  getAuthMessage,\n  saveShards,\n  generate,\n  recoverShards,\n} from \"@lighthouse-web3/kavach\";\nimport { ethers } from \"ethers\";\n\nasync function main() {\n  const signer = new ethers.Wallet(\n    \"0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c8b\"\n  );\n\n  const { masterKey, keyShards } = await generate();\n\n  let authMessage = await getAuthMessage(signer.address);\n  let signedMessage = await signer.signMessage(authMessage.message);\n\n  const { error, isSuccess } = await saveShards(\n    signer.address,\n    \"QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH\",\n    signedMessage,\n    keyShards\n  );\n\n  console.log(error === null); // true;\n  console.log(isSuccess === true); //true;\n\n  authMessage = await getAuthMessage(signer.address);\n  signedMessage = await signer.signMessage(authMessage.message);\n  //retrieve 3 keys\n  const { error, shards } = await recoverShards(\n    signer.address,\n    cid,\n    signedMessage,\n    3\n  );\n  console.log(error == null); //true;\n  console.log(shards.length === 3); // true;\n\n  const { masterKey: recoveredKey } = await recoverKey(shards);\n  console.log(masterKey === recoveredKey); //true\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\n- ### _shareToAddress(address: string, cid: string, auth_token: string, shareTo: Array\u003cstring\u003e )_\n\nShare file Key to address\n\n#### Parameters\n\n| Name       | Type                       | Default | Description                                     |\n| ---------- | -------------------------- | ------- | ----------------------------------------------- |\n| address    | string                     |         | address of the owner of the key                 |\n| cid        | string                     |         | unique id or file CID                           |\n| auth_token | string                     |         | signed Message gotten from getAuthMessage/ JWT  |\n| shareTo    | Array\u003c address \u003e(Optional) | []      | An array of address to share file key shards to |\n\n#### returns\n\n| Name      | Type       | Description               |\n| --------- | ---------- | ------------------------- |\n| isSuccess | boolean    | return true if successful |\n| error     | ErrorValue | Errors                    |\n\n#### Demo\n\n```javascript\nimport {\n  recoverShards,\n  getAuthMessage,\n  saveShards,\n  AuthMessage,\n  shareToAddress,\n  generate,\n} from \"@lighthouse-web3/kavach\";\nimport { ethers } from \"ethers\";\n\nasync function main() {\n  let signer = new ethers.Wallet(\n    \"0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c8b\"\n  );\n  let signer2 = new ethers.Wallet(\n    \"0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c99\"\n  );\n  const cid = \"QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwAV\";\n  const { masterKey, keyShards } = await generate();\n\n  //save file\n  {\n    const authMessage: AuthMessage = await getAuthMessage(signer.address);\n    const signedMessage = await signer.signMessage(authMessage.message);\n\n    const { error, isSuccess } = await saveShards(\n      signer.address,\n      cid,\n      signedMessage,\n      keyShards\n    );\n    console.log(error == null); //true;\n    console.log(isSuccess == true); //true;\n  }\n\n  //share file key to address address\n  {\n    const authMessage: AuthMessage = await getAuthMessage(signer.address);\n    const signedMessage = await signer.signMessage(authMessage.message);\n    const { error, isSuccess } = await shareToAddress(\n      signer.address,\n      cid,\n      signedMessage,\n      [signer2.address]\n    );\n\n    console.log(error == null); // true;\n    console.log(isSuccess == true); //true;\n  }\n\n  //recover shared from address shared to\n\n  {\n    const authMessage: AuthMessage = await getAuthMessage(signer2.address);\n    const signedMessage = await signer2.signMessage(authMessage.message);\n\n    //retrieve 3 keys\n    const { error, shards } = await recoverShards(\n      signer2.address,\n      cid,\n      signedMessage,\n      3\n    );\n    console.log(error == null); //true;\n    console.log(shards.length === 3); // true;\n  }\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\n- ### _revokeAccess(address: string, cid: string, auth_token: string, revokeTo: Array\u003cstring\u003e )_\n\nrevoke access to addresses with direct access\n\n#### Parameters\n\n| Name       | Type                       | Default | Description                                     |\n| ---------- | -------------------------- | ------- | ----------------------------------------------- |\n| address    | string                     |         | address of the owner of the key                 |\n| cid        | string                     |         | unique id or file CID                           |\n| auth_token | string                     |         | signed Message gotten from getAuthMessage /JWT  |\n| revokeTo   | Array\u003c address \u003e(Optional) | []      | An array of address to remove for Direct access |\n\n#### returns\n\n| Name      | Type       | Description               |\n| --------- | ---------- | ------------------------- |\n| isSuccess | boolean    | return true if successful |\n| error     | ErrorValue | Errors                    |\n\n#### Demo\n\n```javascript\nimport {\n  recoverShards,\n  getAuthMessage,\n  saveShards,\n  AuthMessage,\n  revokeAccess,\n  generate,\n} from \"@lighthouse-web3/kavach\";\nimport { ethers } from \"ethers\";\n\nasync function main() {\n  let signer = new ethers.Wallet(\n    \"0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c8b\"\n  );\n  let signer2 = new ethers.Wallet(\n    \"0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c99\"\n  );\n  const cid = \"QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwVV\";\n  const { masterKey, keyShards } = await generate();\n\n  //save file\n  {\n    const authMessage: AuthMessage = await getAuthMessage(signer.address);\n    const signedMessage = await signer.signMessage(authMessage.message);\n\n    const { error, isSuccess } = await saveShards(\n      signer.address,\n      cid,\n      signedMessage,\n      keyShards,\n      [\n        \"0x95CF5354519a6ad2bD7e53fe7763201dfB24bFE4\",\n        \"0xb46D27B3BfC07D27702EBddbe197Fc9276b70581\",\n        signer2.address,\n      ]\n    );\n    console.log(error == null); //true;\n    console.log(isSuccess == true); //true;\n  }\n\n  //recover shared from address shared to\n\n  {\n    const authMessage: AuthMessage = await getAuthMessage(signer2.address);\n    const signedMessage = await signer2.signMessage(authMessage.message);\n\n    //retrieve 3 keys\n    const { error, shards } = await recoverShards(\n      signer2.address,\n      cid,\n      signedMessage,\n      3\n    );\n    console.log(error == null); //true;\n    console.log(shards.length === 3); // true;\n  }\n\n  //revoke access to direct shared address\n  {\n    const authMessage: AuthMessage = await getAuthMessage(signer.address);\n    const signedMessage = await signer.signMessage(authMessage.message);\n    const { error, isSuccess } = await revokeAccess(\n      signer.address,\n      cid,\n      signedMessage,\n      [signer2.address]\n    );\n\n    console.log(error == null); // true;\n    console.log(isSuccess == true); //true;\n  }\n\n  //recover shared from address shared to\n\n  {\n    const authMessage: AuthMessage = await getAuthMessage(signer2.address);\n    const signedMessage = await signer2.signMessage(authMessage.message);\n\n    //retrieve 3 keys\n    const { error, shards } = await recoverShards(\n      signer2.address,\n      cid,\n      signedMessage,\n      3\n    );\n    console.log(error); // { message: \"you don't have access\", data: {} };\n    console.log(shards.length === 0); // true ;\n  }\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\n- ### _accessCondition( address: string, cid: string, auth_token: string, conditions: Condition[], aggregator?: string,chainType?: ChainType, keyShards? : Array\u003c{key:string; index:string}\u003e, decryptionType? : string )_\n\nAdd more granular access Conditions based on on-Chain Data, this supports custom EVM contracts, block timestamps and so on.\nwith support for over 15 Ethereum Virtual Machine (EVM) based networks and based Solana RPC calls\n\n- Ethereum\n- Rinkeby\n- Polygon\n- Fantom\n- FantomTest\n- AVAX\n- Fuji\n- BSC\n- BSCTest\n- Optimism\n- OptimismGoerli\n- OptimismKovan\n- Mumbai\n- FVM\n- Wallaby\n- Calibration\n- Shardeum\n- Goerli\n- Hyperspace\n- BTTC\n- BTTC_Testnet\n- Sepolia_PGN\n- Arbitrum_Sepolia\n- Sepolia:\n- BASE_Goerli\n\nSolana\n\n- DEVNET\n- TESTNET\n- MAINNET\n\n#### Parameters\n\n| Name            | Type                              | Description                                                                                                                                           |\n| --------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |\n| address         | string                            | Address of the owner of the key                                                                                                                       |\n| cid             | string                            | Unique id or file CID                                                                                                                                 |\n| auth_token      | string                            | Signed Message gotten from getAuthMessage /JWT                                                                                                        |\n| conditions      | Array\u003c Condition \u003e                | This Array contains a list of conditions to be tested on chain                                                                                        |\n| aggregator      | string                            | This is a template string that structures how the conditions should be computed                                                                       |\n| chainType       | string                            | This defaults to EVM and can be set to Solana for Solana conditions                                                                                   |\n| keyShards?      | Array\u003c{key:string; index:string}\u003e | This Field is optional, you can use it to set, overWrite or rotate key shards                                                                         |\n| decryptionType? | string                            | This value can be set to ACCESS_CONDITIONS to first time shard is added, **WARNING: This sets Owner to address zero(0x0000000000000000000000000000)** |\n\n#### returns\n\n| Name      | Type       | Description               |\n| --------- | ---------- | ------------------------- |\n| isSuccess | boolean    | return true if successful |\n| error     | ErrorValue | Errors                    |\n\n#### Demo\n\n```javascript\nimport {\n  recoverShards,\n  getAuthMessage,\n  saveShards,\n  AuthMessage,\n  accessControl,\n  generate,\n} from \"@lighthouse-web3/kavach\";\nimport { ethers } from \"ethers\";\n\nasync function main() {\n  let signer = new ethers.Wallet(\n    \"0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c8b\"\n  );\n  let signer2 = new ethers.Wallet(\n    \"0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c99\"\n  );\n  const cid = \"QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwVM\";\n\n  //save file\n  {\n    const authMessage: AuthMessage = await getAuthMessage(signer.address);\n    const signedMessage = await signer.signMessage(authMessage.message);\n    const { masterKey, keyShards } = await generate();\n\n    const { error, isSuccess } = await saveShards(\n      signer.address,\n      cid,\n      signedMessage,\n      keyShards\n    );\n    console.log(error == null); //true;\n    console.log(isSuccess == true); //true;\n  }\n\n  // add access control to cid direct shared address\n  {\n    const authMessage: AuthMessage = await getAuthMessage(signer.address);\n    const signedMessage = await signer.signMessage(authMessage.message);\n    const { error, isSuccess } = await accessControl(\n      signer.address,\n      cid,\n      signedMessage,\n      [\n        {\n          id: 3,\n          chain: \"Polygon\",\n          method: \"getBlockNumber\",\n          standardContractType: \"\",\n          returnValueTest: { comparator: \"\u003e=\", value: \"0\" },\n        },\n        {\n          id: 2,\n          chain: \"Optimism\",\n          method: \"getBalance\",\n          standardContractType: \"\",\n          returnValueTest: { comparator: \"\u003e=\", value: \"0\" },\n        },\n        {\n          id: 1,\n          chain: \"FantomTest\",\n          method: \"balanceOf\",\n          standardContractType: \"ERC20\",\n          contractAddress: \"0xF0Bc72fA04aea04d04b1fA80B359Adb566E1c8B1\",\n          returnValueTest: { comparator: \"\u003e=\", value: \"0\" },\n          parameters: [\":userAddress\"],\n        },\n      ],\n      \"([2] and [1]) or [3]\"\n    );\n    console.log(error == null);\n    console.log(isSuccess == true);\n  }\n\n  // recover shared from an address that matches the above condition\n  // that is\n  // has a balance equal to or greater than Zero on the Optimism mainnet and has a token balance greater than equal to zero of the token 0xF0Bc72fA04aea04d04b1fA80B359Adb566E1c8B1 on fantom's testnet\n  // or if block height is greater than zero\n\n  {\n    const authMessage: AuthMessage = await getAuthMessage(signer2.address);\n    const signedMessage = await signer2.signMessage(authMessage.message);\n    console.log(signer2.address);\n\n    //retrieve 3 keys\n    const { error, shards } = await recoverShards(\n      signer2.address,\n      cid,\n      signedMessage,\n      3,\n      dynamicData\n    );\n    console.log(error == null); //true;\n    console.log(shards.length === 3); // true;\n  }\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\n## Auth Methods\n\n- ### _getAuthMessage( address: string)_\n\nGet Consensus Message to Sign\n\n#### Parameters\n\n| Name    | Type   | Default | Description                     |\n| ------- | ------ | ------- | ------------------------------- |\n| address | string |         | address of the owner of the key |\n\n#### returns\n\n| Name    | Type       | Description              |\n| ------- | ---------- | ------------------------ |\n| message | string     | return consensus message |\n| error   | ErrorValue | Errors                   |\n\n```javascript\nimport { getAuthMessage, AuthMessage } from \"@lighthouse-web3/kavach\";\nimport { ethers } from \"ethers\";\n\nasync function main() {\n  let signer = new ethers.Wallet(\n    \"0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c8b\"\n  );\n\n  // get consensus message\n  const authMessage: AuthMessage = await getAuthMessage(signer.address);\n  const signedMessage = await signer.signMessage(authMessage.message);\n\n  console.log(typeof authMessage.message == \"string\"); //true;\n  console.log(authMessage.error == null); //true;\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\n- ### _getJWT(address:string,signedMessage: SignedMessage)_\n\nGet Consensus Message to Sign\n\n#### Parameters\n\n| Name              | Type    | Default | Description                                           |\n| ----------------- | ------- | ------- | ----------------------------------------------------- |\n| address           | string  |         | address of the owner of the key                       |\n| payload           | string  |         | signed consensus message or refresh Token             |\n| useAsRefreshToken | boolean | false   | If payload is refreshToken this should be set to true |\n\n#### returns\n\n| Name         | Type       | Description |\n| ------------ | ---------- | ----------- |\n| JWT          | string     | return JWT  |\n| refreshToken | string     |             |\n| error        | ErrorValue | Errors      |\n\n```javascript\nimport { getAuthMessage, AuthMessage, getJWT } from \"@lighthouse-web3/kavach\";\nimport { ethers } from \"ethers\";\n\nasync function main() {\n  let signer = new ethers.Wallet(\n    \"0x8218aa5dbf4dbec243142286b93e26af521b3e91219583595a06a7765abc9c8b\"\n  );\n\n  // get consensus message\n  const authMessage: AuthMessage = await getAuthMessage(signer.address);\n  const signedMessage = await signer.signMessage(authMessage.message);\n\n  const { JWT, error } = await getJWT(signer.address, signedMessage);\n  console.log(typeof JWT == \"string\"); //true;\n  console.log(error == null); //true;\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n\n- ### _transferOwnership(address: string, cid: string, newOwner: string, auth_token: string, resetSharedTo: boolean = true)_\n\nTransfer Ownership of a Resource\n\n#### Parameters\n\n| Name          | Type    | Default | Description                                     |\n| ------------- | ------- | ------- | ----------------------------------------------- |\n| address       | string  |         | Address of the current owner of the resource    |\n| cid           | string  |         | Content ID (CID) of the resource                |\n| newOwner      | string  |         | Address of the new owner for the resource       |\n| auth_token    | string  |         | Authentication payload or token                 |\n| resetSharedTo | boolean | true    | Reset shared permissions when ownership changes |\n\n#### Returns\n\n| Name   | Type   | Description                      |\n| ------ | ------ | -------------------------------- |\n| result | string | Result of the ownership transfer |\n| error  | Error  | Any error that occurs            |\n\n#### Example\n\n```javascript\nimport { transferOwnership } from \"@lighthouse-web3/kavach\";\n\n// Example usage of transferOwnership function\nasync function main() {\n  const currentOwner = \"0x1234567890abcdef\";\n  const resourceId = \"QmXyZAbCdEfGhIjK\";\n  const newOwner = \"0x9876543210fedcba\";\n  const authPayload = \"your-authentication-token\";\n\n  const { result, error } = await transferOwnership(\n    currentOwner,\n    resourceId,\n    newOwner,\n    authPayload\n  );\n\n  if (error) {\n    console.error(\"Error:\", error);\n  } else {\n    console.log(\"Ownership transfer result:\", result);\n  }\n}\n\nmain()\n  .then(() =\u003e process.exit(0))\n  .catch((error) =\u003e {\n    console.error(error);\n    process.exit(1);\n  });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flighthouse-web3%2Fencryption-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flighthouse-web3%2Fencryption-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flighthouse-web3%2Fencryption-sdk/lists"}