Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Release SDK 1.0.2 (#35)
Browse files Browse the repository at this point in the history
Updated APIs and sample demos to enable better handling of operations:

- Improvements to the following APIs to return the resource name of the
resulting WaaS operation on successful initiation -
createSignatureFromTx, prepareDeviceArchive, prepareDeviceBackup.
- [Sample
Project](https://docs.cloud.coinbase.com/waas/docs/quickstart):
MPCSignatureDemo, MPCKeyExportDemo, DeviceBackupDemo and
DeviceAdditionDemo processes the operations that are created in the
operation initialization call, instead of the last operation manifested
in the result of ListMPCOperations.
  • Loading branch information
jazz-cb authored Jun 1, 2023
1 parent 9621393 commit 9ff2ffc
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 46 deletions.
36 changes: 22 additions & 14 deletions example/src/screens/DeviceAdditionDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,32 @@ export const DeviceAdditionDemo = () => {
await initMPCWalletService(apiKeyName, privateKey);

if (!showStep5) {
await addDevice(deviceGroupName, deviceName);
}
const operationName = await addDevice(deviceGroupName, deviceName);
setShowStep5(true);

// Process operation.
const pendingDeviceOperations = await pollForPendingDevices(
deviceGroupName
);

for (let i = pendingDeviceOperations.length - 1; i >= 0; i--) {
const pendingOperation = pendingDeviceOperations[i];

setShowStep5(true);
if (pendingOperation?.Operation === operationName) {
await computeAddDeviceMPCOperation(
pendingOperation!.MPCData,
passcode,
deviceBackup
);
setShowStep6(true);

// Process operation.
const pendingDeviceOperations = await pollForPendingDevices(
deviceGroupName
);
return;
}
}

for (let i = pendingDeviceOperations.length - 1; i >= 0; i--) {
const pendingOperation = pendingDeviceOperations[i];
await computeAddDeviceMPCOperation(
pendingOperation!.MPCData,
passcode,
deviceBackup
throw new Error(
`could not find operation with name ${operationName}`
);
setShowStep6(true);
}
} catch (error) {
setResultError(error as Error);
Expand Down
28 changes: 22 additions & 6 deletions example/src/screens/DeviceBackupDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
initMPCWalletService,
pollForPendingDeviceBackups,
prepareDeviceBackup,
PrepareDeviceBackupOperation,
} from '@coinbase/waas-sdk-react-native';
import { ContinueButton } from '../components/ContinueButton';
import { DemoStep } from '../components/DemoStep';
Expand Down Expand Up @@ -60,21 +61,36 @@ export const DeviceBackupDemo = () => {
await initMPCSdk(true);
await initMPCKeyService(apiKeyName, privateKey);
await initMPCWalletService(apiKeyName, privateKey);
await prepareDeviceBackup(deviceGroupName, deviceName);
let operationName = await prepareDeviceBackup(
deviceGroupName,
deviceName
);

// Process operation.
const pendingDeviceBackupOperations = await pollForPendingDeviceBackups(
deviceGroupName
);

let pendingOperation!: PrepareDeviceBackupOperation;
for (let i = pendingDeviceBackupOperations.length - 1; i >= 0; i--) {
const pendingOperation = pendingDeviceBackupOperations[i];
await computePrepareDeviceBackupMPCOperation(
pendingOperation!.MPCData,
passcode
if (pendingDeviceBackupOperations[i]?.Operation === operationName) {
pendingOperation = pendingDeviceBackupOperations[
i
] as PrepareDeviceBackupOperation;
}
}

if (!pendingOperation) {
throw new Error(
`could not find operation with name ${operationName}`
);
setShowStep5(true);
}

await computePrepareDeviceBackupMPCOperation(
pendingOperation!.MPCData,
passcode
);
setShowStep5(true);
} catch (error) {
setResultError(error as Error);
setShowError(true);
Expand Down
36 changes: 26 additions & 10 deletions example/src/screens/MPCKeyExportDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
computePrepareDeviceArchiveMPCOperation,
getDeviceGroup,
pollForPendingDeviceArchives,
PrepareDeviceArchiveOperation,
} from '@coinbase/waas-sdk-react-native';
import { ContinueButton } from '../components/ContinueButton';
import { DemoStep } from '../components/DemoStep';
Expand Down Expand Up @@ -62,7 +63,6 @@ export const MPCKeyExportDemo = () => {
apiKeyName === '' ||
privateKey === '' ||
!showStep2 ||
showStep4 ||
showStep7
) {
return;
Expand All @@ -75,22 +75,38 @@ export const MPCKeyExportDemo = () => {
await initMPCWalletService(apiKeyName, privateKey);

if (!showStep3) {
await prepareDeviceArchive(deviceGroupName, deviceName);
}

setShowStep3(true);
const operationName = (await prepareDeviceArchive(
deviceGroupName,
deviceName
)) as string;
setShowStep3(true);

if (showStep3 && !showStep4) {
const pendingDeviceArchiveOperations =
await pollForPendingDeviceArchives(deviceGroupName);

let pendingOperation!: PrepareDeviceArchiveOperation;

for (let i = pendingDeviceArchiveOperations.length - 1; i >= 0; i--) {
const pendingOperation = pendingDeviceArchiveOperations[i];
await computePrepareDeviceArchiveMPCOperation(
pendingOperation!.MPCData,
passcode
if (
pendingDeviceArchiveOperations[i]?.Operation === operationName
) {
pendingOperation = pendingDeviceArchiveOperations[
i
] as PrepareDeviceArchiveOperation;

break;
}
}

if (!pendingOperation) {
throw new Error(
`could not find operation with name ${operationName}`
);
}
await computePrepareDeviceArchiveMPCOperation(
pendingOperation!.MPCData,
passcode
);

const retrievedDeviceGroup = await getDeviceGroup(deviceGroupName);
setMpcKeyExportMetadata(retrievedDeviceGroup.MPCKeyExportMetadata);
Expand Down
Loading

0 comments on commit 9ff2ffc

Please sign in to comment.