Open
Description
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
, orcryptography
for threshold sharing.binascii
,re
, or built-inbytes.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
andkeyCount
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 emptykeyShards
array. - Internally reuse core shard generation logic from
generate()
implementation to avoid duplication.
Metadata
Metadata
Assignees
Labels
No labels