Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk-core): fix createTssBitGoKeyFromOvcShares method #3694

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions modules/bitgo/test/v2/unit/keychains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,28 +402,30 @@ describe('V2 Keychains', function () {
},
};
const expectedBitGoOutput = {
...ovcOutputJson,
state: 2,
platform: {
commonKeychain: bitGoKeyResult.commonKeychain,
walletHSMGPGPublicKeySigs: bitGoKeyResult.walletHSMGPGPublicKeySigs,
ovc: {
1: {
bitgoToOvcShare: {
i: 1,
j: 3,
publicShare: bitGoKeyResult.keyShares[0].publicShare,
privateShare: bitGoKeyResult.keyShares[0].privateShare,
vssProof: bitGoKeyResult.keyShares[0].vssProof,
wallet: {
...ovcOutputJson,
state: 2,
platform: {
commonKeychain: bitGoKeyResult.commonKeychain,
walletGpgPubKeySigs: bitGoKeyResult.walletHSMGPGPublicKeySigs,
ovc: {
1: {
bitgoToOvcShare: {
i: 1,
j: 3,
publicShare: bitGoKeyResult.keyShares[0].publicShare,
privateShare: bitGoKeyResult.keyShares[0].privateShare,
vssProof: bitGoKeyResult.keyShares[0].vssProof,
},
},
},
2: {
bitgoToOvcShare: {
i: 2,
j: 3,
publicShare: bitGoKeyResult.keyShares[1].publicShare,
privateShare: bitGoKeyResult.keyShares[1].privateShare,
vssProof: bitGoKeyResult.keyShares[1].vssProof,
2: {
bitgoToOvcShare: {
i: 2,
j: 3,
publicShare: bitGoKeyResult.keyShares[1].publicShare,
privateShare: bitGoKeyResult.keyShares[1].privateShare,
vssProof: bitGoKeyResult.keyShares[1].vssProof,
},
},
},
},
Expand Down
54 changes: 28 additions & 26 deletions modules/sdk-core/src/bitgo/keychain/keychains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
UpdateSingleKeychainPasswordOptions,
} from './iKeychains';
import { decodeOrElse } from '../utils/decode';
import { BitGoKeyFromOvcShares, OvcToBitGoJSON } from './ovcJsonCodec';
import { BitGoKeyFromOvcShares, BitGoToOvcJSON, OvcToBitGoJSON } from './ovcJsonCodec';

export class Keychains implements IKeychains {
private readonly bitgo: BitGoBase;
Expand Down Expand Up @@ -373,40 +373,42 @@ export class Keychains implements IKeychains {
assert(bitgoToBackupShare.vssProof);

// Create JSON data with platform shares for OVC-1 and OVC-2
const bitgoToOvcOutput = {
...decodedOvcOutput,
platform: {
commonKeychain: key.commonKeychain,
walletHSMGPGPublicKeySigs: key.walletHSMGPGPublicKeySigs,
ovc: {
// BitGo to User (OVC-1)
1: {
bitgoToOvcShare: {
i: 1,
j: 3,
publicShare: bitgoToUserShare.publicShare,
privateShare: bitgoToUserShare.privateShare,
vssProof: bitgoToUserShare.vssProof,
const bitgoToOvcOutput: BitGoToOvcJSON = {
wallet: {
...decodedOvcOutput,
platform: {
commonKeychain: key.commonKeychain,
walletGpgPubKeySigs: key.walletHSMGPGPublicKeySigs,
ovc: {
// BitGo to User (OVC-1)
1: {
bitgoToOvcShare: {
i: 1,
j: 3,
publicShare: bitgoToUserShare.publicShare,
privateShare: bitgoToUserShare.privateShare,
vssProof: bitgoToUserShare.vssProof,
},
},
},
// BitGo to Backup (OVC-2)
2: {
bitgoToOvcShare: {
i: 2,
j: 3,
publicShare: bitgoToBackupShare.publicShare,
privateShare: bitgoToBackupShare.privateShare,
vssProof: bitgoToBackupShare.vssProof,
// BitGo to Backup (OVC-2)
2: {
bitgoToOvcShare: {
i: 2,
j: 3,
publicShare: bitgoToBackupShare.publicShare,
privateShare: bitgoToBackupShare.privateShare,
vssProof: bitgoToBackupShare.vssProof,
},
},
},
},
},
};

// Mark it ready for next operation, should be 2
bitgoToOvcOutput.state += 1;
bitgoToOvcOutput.wallet.state += 1;

const output = {
const output: BitGoKeyFromOvcShares = {
bitGoKeyId: key.id,
bitGoOutputJsonForOvc: bitgoToOvcOutput,
};
Expand Down
38 changes: 21 additions & 17 deletions modules/sdk-core/src/bitgo/keychain/ovcJsonCodec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,33 @@ export const OvcToBitGoJSON = t.strict(

export type OvcToBitGoJSON = t.TypeOf<typeof OvcToBitGoJSON>;

export const BitGoToOvcJSON = t.intersection(
[
OvcToBitGoJSON,
t.type({
platform: t.type({
commonKeychain: t.string,
walletHSMGPGPublicKeySigs: t.string,
ovc: t.type({
// BitGo to User (OVC-1)
1: t.type({
bitgoToOvcShare: OvcShare,
}),
// BitGo to Backup (OVC-2)
2: t.type({
bitgoToOvcShare: OvcShare,
export const BitGoToOvcJSON = t.strict(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can create a type from this.

{
wallet: t.intersection([
OvcToBitGoJSON,
t.type({
platform: t.type({
commonKeychain: t.string,
walletGpgPubKeySigs: t.string,
ovc: t.type({
// BitGo to User (OVC-1)
1: t.type({
bitgoToOvcShare: OvcShare,
}),
// BitGo to Backup (OVC-2)
2: t.type({
bitgoToOvcShare: OvcShare,
}),
}),
}),
}),
}),
],
]),
},
'BitgoToOvcJson'
);

export type BitGoToOvcJSON = t.TypeOf<typeof BitGoToOvcJSON>;

export const BitGoKeyFromOvcShares = t.strict(
{
bitGoOutputJsonForOvc: BitGoToOvcJSON,
Expand Down