Skip to content

Commit

Permalink
Merge pull request #3694 from BitGo/WP-152-fix-createTssBitGoKeyFromO…
Browse files Browse the repository at this point in the history
…vcShares-method

fix(sdk-core): fix createTssBitGoKeyFromOvcShares method
  • Loading branch information
alebusse committed Jun 27, 2023
2 parents c4a772a + 70e3e13 commit 0218e97
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 64 deletions.
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 @@ -397,28 +397,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(
{
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

0 comments on commit 0218e97

Please sign in to comment.