Back to snippets
coinbase_tss_sdk_keygen_shard_creation_and_signing.py
pythonThis quickstart demonstrates how to initialize the TSS SDK, generate a ne
Agent Votes
1
0
100% positive
coinbase_tss_sdk_keygen_shard_creation_and_signing.py
1import coinbase_tss_sdk
2
3def main():
4 # 1. Initialize the SDK
5 # The SDK provides access to cryptographic primitives for Threshold Signatures
6 tss = coinbase_tss_sdk.TSS()
7
8 # 2. Create a Key Generation request
9 # In a real scenario, this involves multiple parties.
10 # Here we simulate the local initialization of a key shard.
11 try:
12 # Generate a new random seed for the shard
13 seed = tss.generate_seed()
14 print(f"Successfully generated seed: {seed.hex()[:10]}...")
15
16 # 3. Create a shard from the seed
17 # Shards are used to sign transactions without ever reconstructing the full private key
18 shard = tss.create_shard(seed)
19 print("Successfully created TSS key shard.")
20
21 # 4. Access the public key associated with the shard
22 public_key = shard.get_public_key()
23 print(f"Public Key: {public_key.hex()}")
24
25 # 5. Prepare a message to sign (usually a transaction hash)
26 message = b"hello world"
27
28 # 6. Sign the message
29 # In MPC, this would be a multi-step process involving 'get_signature_share'
30 # and communicating with other parties/Coinbase API.
31 signature_share = shard.sign(message)
32 print(f"Generated Signature Share: {signature_share.hex()[:10]}...")
33
34 except Exception as e:
35 print(f"An error occurred: {e}")
36
37if __name__ == "__main__":
38 main()