// Step 1. Run backup by passing in the response from generate (the signing shares)
const backupResponse = await axios.post(
`https://mpc-client.portalhq.io/v1/backup`,
{
generateResponse: JSON.stringify(signingShares),
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${clientApiKey}`,
},
},
);
const { secp256k1Share, ed25519Share } = backupResponse.data;
// Step 2. Encrypt the client backup shares
const secp256k1Ciphertext = await YourEnvelopEncryptionService.encrypt(secp256k1Share)
const ed25519Ciphertext = await YourEnvelopEncryptionService.encrypt(ed25519Share)
// Step 3. Store the client ciphertexts with Portal or your backend [OPTIONAL]
await axios.post(
`https://api.portalhq.io/api/v3/clients/me/backup-share-pairs/${secp256k1Share.id}`,
{
clientCipherText: secp256k1Ciphertext,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${clientApiKey}`,
},
},
);
await axios.post(`https://api.portalhq.io/api/v3/clients/me/backup-share-pairs/${ed25519Share.id}`,
{
clientCipherText: ed25519Ciphertext,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${clientApiKey}`,
},
},
);
// Step 4. Mark the backup process as complete by updating the backup share pairs status
await axios.patch(
`https://api.portalhq.io/api/v3/clients/me/backup-share-pairs`,
{
status: 'STORED_CLIENT_BACKUP_SHARE',
backupSharePairIds: [secp256k1Share.id, ed25519Share.id],
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${clientApiKey}`,
},
},
);