How to Sign a Message
This guide assumes you have completed Create an MPCWallet.
1. Get MPCKey
To sign a message, use the MPCKey underlying the Address that you generated in Create an MPCWallet.
// Go code in your Proxy server
mpcKeyName, _ := address.GetMpcKeys()[0]
2. Initiate Signature Creation
Creating a Signature is like creating an MPCWallet in that you initiate, poll, and compute. Initiate with [CreateSignature], poll with ListMPCOperations
, and compute the operation with the SDK to complete the process.
Messages must be signed within 30 minutes or they expire.
The operation’s metadata will contain the DeviceGroup you can use to poll with ListMPCOperations.
// Go code in your Proxy server
req := &mpcKeys.CreateSignatureRequest{
Parent: mpcKeyName,
// The payload you want to sign
Payload: payload,
}
op, err := mpcKeyServiceClient.CreateSignature(ctx, req)
if err != nil {
log.Fatalf("error initiating signature creation: %v", err)
}
metadata, _ := op.Metadata()
deviceGroupName := metadata.GetDeviceGroup()
3. Poll and Compute MPC Operation
Signature creation is now underway, and will require MPC participation from your device. Poll for your pending DeviceGroup via your proxy server using ListMPCOperations.
Alternatively, you can use the SDK method pollPendingSignatureAPI
, but the proxy server is more secure.
// Go code in your Proxy server
mpcData, err := pollMPCOperations(deviceGroupName, pollChan, 500 * time.Millisecond)
Now use the MPC data in the MPC operation to compute the MPC operation in the WaaS SDK.
// React Native code in your app
computeMPCOperation(mpcData)
4. Get Signature
Shortly after you compute the MPC operation, the original operation returned from CreateSignature should complete.
// Go code in your Proxy server
signature, _ := op.Wait(ctx)
signedPayload := signature.GetSignature().GetEcdsaSignature()