Skip to content

Implement shardKey - Shard an existing key #26

Open
@AkashJana18

Description

@AkashJana18

Overview

Implement the shardKey method in the Python SDK, allowing users to split an existing 32-byte private key into secure key shards. This mirrors the shardKey method in the JS SDK and should preserve the same function signature and response structure.

This function is particularly useful when users want to shard externally generated secrets such as Ethereum private keys or other static keys.


Function Signature

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

Expected Response Format

{
  "isShardable": true,
  "keyShards": [
    { "key": "<shard key string>", "index": "<index string>" }
  ]
}
  • isShardable: Boolean indicating whether the input key was valid and successfully sharded.
  • keyShards: List of threshold shards that can be used to recover the original key.

Reference (JS SDK)

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

Key Requirements

  • Accept only valid 32-byte (64 hex char) strings. Reject and return isShardable: false otherwise.
  • Use the same threshold secret sharing logic from generate.
  • Maintain shard format identical to JS SDK: key + index.
  • Ensure that keyCount >= threshold.
  • Add type validation and edge case checks.

Suggested Python Libraries

  • secretsharing, shamir, or cryptography for threshold sharing.
  • binascii, re, or built-in bytes.fromhex() to validate hex string length and format.

Deliverables

  • Working shardKey() function that supports threshold cryptography on externally supplied keys.

  • Unit tests for:

    • Valid 32-byte keys
    • Invalid keys (length < 32 bytes or malformed)
    • Various threshold and keyCount combinations
  • Return object should match JS SDK schema exactly.


Notes

  • If key is not suitable for sharding (e.g., invalid length), return isShardable: false with empty keyShards array.
  • Internally reuse core shard generation logic from generate() implementation to avoid duplication.

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