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
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.
Overview
Implement the
shardKeymethod in the Python SDK, allowing users to split an existing 32-byte private key into secure key shards. This mirrors theshardKeymethod 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
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)
/src/methods/shardKey/index.tsshardKey()Key Requirements
isShardable: falseotherwise.generate.keyCount >= threshold.Suggested Python Libraries
secretsharing,shamir, orcryptographyfor 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:
thresholdandkeyCountcombinationsReturn object should match JS SDK schema exactly.
Notes
isShardable: falsewith emptykeyShardsarray.generate()implementation to avoid duplication.