Skip to content

Implement generate Method Randomized Key Shard Generation #25

Open
@AkashJana18

Description

@AkashJana18

Overview

Implement the generate method in Python SDK to create randomized key shards using threshold cryptography. This will allow generation of a secure master key and its corresponding shards, following the same API structure as the existing JavaScript SDK.

Maintaining consistent function names and response formats with the JS SDK is important for cross-language compatibility.


Function Signature

async def generate(threshold: int = 3, keyCount: int = 5) -> Dict[str, Any]:
    pass

Expected Response

{
  "masterKey": "<32-byte master key string>",
  "keyShards": [
    { "key": "<shard key string>", "index": "<index string>" }
  ]
}
  • masterKey : Secure randomly generated 32-byte key.
  • keyShards : List of shards that can reconstruct the masterKey based on the threshold.

Reference (JS SDK)

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

Key Requirements

  • Use cryptographically secure random key generation for masterKey (Python’s secrets or os.urandom).
  • Implement threshold secret sharing (Shamir Secret Sharing preferred for first version).
  • Validate that keyCount >= threshold.
  • Use consistent shard serialization (key + index format) similar to JS SDK.
  • Ensure deterministic output for same seed (for testability).

Suggested Python Libraries

  • secretsharing or cryptography for Shamir secret sharing.
  • secrets or os.urandom for secure key generation.

Deliverables

  • Fully implemented generate() function.
  • Unit tests covering multiple threshold/keyCount combinations.
  • Return values matching JS SDK response schema.

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