Open
Description
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 bothkey
andindex
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()
andshardKey()
. - 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()
andshardKey()
.
Metadata
Metadata
Assignees
Labels
No labels