Skip to content

Commit fef4a1a

Browse files
committed
fix(sdk-core): add chaincode to user->backup public shares
For the workflow where bitgo holds backup, when SDK sends the user->backup shares to WP, it was not adding the chaincode due to which the commonKeychain derivation was failing in WP. This also fixes the backup gpg public to be bitgo's GPG key when backup is held by third party. Ticket: BG-60552
1 parent af8ba9b commit fef4a1a

File tree

2 files changed

+16
-5
lines changed
  • modules
    • bitgo/test/v2/unit/internal/tssUtils
    • sdk-core/src/bitgo/utils/tss/ecdsa

2 files changed

+16
-5
lines changed

modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,15 @@ describe('TSS Ecdsa Utils:', async function () {
648648
const bitgoToBackupKeyShare = bitgoKeychain.keyShares.find((keyShare) => keyShare.from === 'bitgo' && keyShare.to === 'backup');
649649
assert(bitgoToBackupKeyShare);
650650

651+
const userPublicShare = Buffer.concat([
652+
Buffer.from(userKeyShare.nShares[2].y, 'hex'),
653+
Buffer.from(userKeyShare.nShares[2].chaincode, 'hex'),
654+
]).toString('hex');
655+
651656
const expectedKeyShares = [{
652657
from: 'user',
653658
to: 'backup',
654-
publicShare: userKeyShare.nShares[2].y,
659+
publicShare: userPublicShare,
655660
// Omitting the private share, the actual encryption happens inside the function where we make the matching call
656661
// to this nock. We cannot recreate the same encrypted value here because gpg encryption is not deterministic
657662
}, bitgoToBackupKeyShare];
@@ -664,7 +669,7 @@ describe('TSS Ecdsa Utils:', async function () {
664669
{
665670
from: 'user',
666671
to: 'backup',
667-
publicShare: userKeyShare.nShares[2].y,
672+
publicShare: userPublicShare,
668673
privateShare: encryptedUserToBackupKeyShare.encryptedPrivateShare,
669674
},
670675
bitgoToBackupKeyShare,

modules/sdk-core/src/bitgo/utils/tss/ecdsa/ecdsa.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export class EcdsaUtils extends baseTSSUtils<KeyShare> {
7070
const bitgoToBackupKeyShare = bitgoKeychain.keyShares?.find(
7171
(keyShare) => keyShare.from === 'bitgo' && keyShare.to === 'backup'
7272
);
73+
const userPublicShare = Buffer.concat([
74+
Buffer.from(userKeyShare.nShares[2].y, 'hex'),
75+
Buffer.from(userKeyShare.nShares[2].chaincode, 'hex'),
76+
]).toString('hex');
7377
assert(bitgoToBackupKeyShare);
7478
return await this.bitgo
7579
.put(this.baseCoin.url(`/krs/backupkeys/${keyId}`))
@@ -79,7 +83,7 @@ export class EcdsaUtils extends baseTSSUtils<KeyShare> {
7983
{
8084
from: 'user',
8185
to: 'backup',
82-
publicShare: userKeyShare.nShares[2].y,
86+
publicShare: userPublicShare,
8387
privateShare: encryptedUserToBackupShare.encryptedPrivateShare,
8488
},
8589
bitgoToBackupKeyShare,
@@ -212,7 +216,7 @@ export class EcdsaUtils extends baseTSSUtils<KeyShare> {
212216
bitgoKeychain
213217
);
214218
if (finalizedBackupKeyShare.commonKeychain !== bitgoKeychain.commonKeychain) {
215-
throw new Error('Failed to create backup keychain - commonKeychains do not match.');
219+
throw new Error('Failed to create backup keychain - commonKeychains do not match');
216220
}
217221
const backupKeyParams: CreateBackupOptions = {
218222
source: 'backup',
@@ -273,7 +277,9 @@ export class EcdsaUtils extends baseTSSUtils<KeyShare> {
273277
},
274278
],
275279
userGPGPublicKey: userGpgKey.publicKey,
276-
backupGPGPublicKey: userGpgKey.publicKey,
280+
// BitGo is the only supported third party backup as of now, so the
281+
// backup GPG key is the same as bitgo GPG key. Else user holds backup.
282+
backupGPGPublicKey: isThirdPartyBackup ? bitgoPublicGpgKey.armor() : userGpgKey.publicKey,
277283
enterprise: enterprise,
278284
};
279285

0 commit comments

Comments
 (0)