Skip to content

Implement recoverKey Method (Key Reconstruction From Shards) #27

Open
@AkashJana18

Description

@AkashJana18

Overview

Implement the recoverKey method in Python SDK to reconstruct the original master key from a given set of key shards. This method should follow the exact behavior and response format of the JS SDK.

The reconstruction logic should correctly combine valid shards, provided the minimum threshold is satisfied.


Function Signature

async def recoverKey(keyShards: List[Dict[str, str]]) -> Dict[str, Any]:
    pass

Expected Response Format

{
  "masterKey": "<reconstructed 32-byte master key string>",
  "error": null
}
  • masterKey: Fully reconstructed key matching the original key that was sharded.
  • error: Null if successful; otherwise return proper error if reconstruction fails (future-proof).

Reference (encryption SDK)

  • File: /src/methods/recoverKey/index.ts
  • Method: recoverKey()

Key Requirements

  • Accept a list of keyShards (must include both key and index fields for each shard).
  • Validate that provided shards meet the minimum threshold for reconstruction.
  • Apply the same decoding logic for index and key as used in generate() and shardKey().
  • Handle corrupted, invalid, or insufficient shard sets gracefully.
  • Maintain exact output format matching JS SDK.

Suggested Python Libraries

  • secretsharing or equivalent to recombine shards.
  • Proper type checking for input validation (typing.List, typing.Dict).
  • Use strict hex decoding when dealing with shard content.

Deliverables

  • Fully functional recoverKey() implementation.

  • Unit tests for:

    • Valid recovery with threshold shards.
    • Invalid recovery with insufficient shards.
    • Corrupted or malformed shard input cases.
  • Consistent response object structure with JS SDK.


Notes

  • If error handling is required, return {"masterKey": None, "error": <error_message>} for consistency.
  • You may reuse internal shard encoding/decoding helpers that were implemented for generate() and shardKey().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions