diff --git a/modules/bitgo/test/v2/unit/keychains.ts b/modules/bitgo/test/v2/unit/keychains.ts index 8bf5f5a34a..15ac82e266 100644 --- a/modules/bitgo/test/v2/unit/keychains.ts +++ b/modules/bitgo/test/v2/unit/keychains.ts @@ -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, + }, }, }, }, diff --git a/modules/sdk-core/src/bitgo/keychain/keychains.ts b/modules/sdk-core/src/bitgo/keychain/keychains.ts index 14c9915809..dfcdd6b627 100644 --- a/modules/sdk-core/src/bitgo/keychain/keychains.ts +++ b/modules/sdk-core/src/bitgo/keychain/keychains.ts @@ -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; @@ -373,30 +373,32 @@ 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, + }, }, }, }, @@ -404,9 +406,9 @@ export class Keychains implements IKeychains { }; // 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, }; diff --git a/modules/sdk-core/src/bitgo/keychain/ovcJsonCodec.ts b/modules/sdk-core/src/bitgo/keychain/ovcJsonCodec.ts index 45a5ef2bd6..417dc40755 100644 --- a/modules/sdk-core/src/bitgo/keychain/ovcJsonCodec.ts +++ b/modules/sdk-core/src/bitgo/keychain/ovcJsonCodec.ts @@ -45,29 +45,33 @@ export const OvcToBitGoJSON = t.strict( export type OvcToBitGoJSON = t.TypeOf; -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; + export const BitGoKeyFromOvcShares = t.strict( { bitGoOutputJsonForOvc: BitGoToOvcJSON,