Skip to content

Commit 520d70d

Browse files
Merge pull request #6563 from BitGo/WP-000000/pass-gpg-pubkey-verify-sigs
feat(core): enable hardcoded gpg keys for signature verification
2 parents 7862edf + 76eaa01 commit 520d70d

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,62 @@ describe('TSS MPC Pick BitGo GPG Pub Key Utils:', function () {
166166
);
167167
await assert.rejects(async () => await ecdsaMpcv2Util.testPickBitgoPubGpgKeyForSigning(true));
168168
});
169+
170+
it('should select the correct GPG key for verifyWalletSignatures with hardcoded options', async function () {
171+
// Test environment setup
172+
const env = 'test';
173+
const bitgoInstance = TestBitGo.decorate(BitGo, { env });
174+
bitgoInstance.initializeTestVars();
175+
const coinInstance = bitgoInstance.coin(eddsaCoinName);
176+
const eddsaMpcv1Util = new TestEddsaMpcv1Utils(
177+
bitgoInstance,
178+
coinInstance,
179+
new Wallet(bitgoInstance, coinInstance, eddsaWalletData)
180+
);
181+
182+
// Get the key that would be selected when using hardcoded BitGo keys
183+
// mpcv1 and nitro are passed as options
184+
const gpgKey = await eddsaMpcv1Util.testPickBitgoPubGpgKeyForSigning(false, undefined, undefined);
185+
186+
// Mock implementation of verifyWalletSignatures to capture the bitgoGpgKey that gets used
187+
let capturedKey;
188+
eddsaMpcv1Util.verifyWalletSignatures = async function (
189+
userGpgPub,
190+
backupGpgPub,
191+
bitgoKeychain,
192+
decryptedShare,
193+
verifierIndex,
194+
useHardcodedBitGoKeys
195+
) {
196+
// Save the key that would be used when specifying hardcoded options
197+
if (useHardcodedBitGoKeys) {
198+
const hardcodedKey = await openpgp.readKey({
199+
armoredKey: BitgoMpcGpgPubKeys.bitgoMpcGpgPubKeys['mpcv1']['nitro']['test'],
200+
});
201+
capturedKey = hardcodedKey.armor();
202+
}
203+
// Not actually verifying in this test
204+
return;
205+
};
206+
207+
// Call with hardcoded key options
208+
await eddsaMpcv1Util.verifyWalletSignatures(
209+
'mock-user-key',
210+
'mock-backup-key',
211+
{
212+
commonKeychain: 'mock-keychain',
213+
walletHSMGPGPublicKeySigs: '',
214+
id: '',
215+
type: 'tss',
216+
},
217+
'decrypted-share',
218+
1,
219+
{ env: 'test', pubKeyType: 'nitro' }
220+
);
221+
222+
// Verify the hardcoded key matches what we expect
223+
capturedKey.should.equal(BitgoMpcGpgPubKeys.bitgoMpcGpgPubKeys['mpcv1']['nitro']['test']);
224+
// Also verify it's the same as what's returned by testPickBitgoPubGpgKeyForSigning
225+
gpgKey.armor().should.equal(capturedKey);
226+
});
169227
});

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ import { KeychainsTriplet } from '../../../baseCoin';
4040
import { exchangeEddsaCommitments } from '../../../tss/common';
4141
import { Ed25519Bip32HdTree } from '@bitgo/sdk-lib-mpc';
4242
import { IRequestTracer } from '../../../../api';
43+
import { getBitgoMpcGpgPubKey } from '../../../tss/bitgoPubKeys';
44+
import { EnvironmentName } from '../../../environments';
45+
import { readKey } from 'openpgp';
4346

4447
/**
4548
* Utility functions for TSS work flows.
@@ -51,12 +54,20 @@ export class EddsaUtils extends baseTSSUtils<KeyShare> {
5154
backupGpgPub: string,
5255
bitgoKeychain: Keychain,
5356
decryptedShare: string,
54-
verifierIndex: 1 | 2
57+
verifierIndex: 1 | 2,
58+
useHardcodedBitGoKeys?: {
59+
env: EnvironmentName;
60+
pubKeyType: 'nitro' | 'onprem';
61+
}
5562
): Promise<void> {
5663
assert(bitgoKeychain.commonKeychain);
5764
assert(bitgoKeychain.walletHSMGPGPublicKeySigs);
5865

59-
const bitgoGpgKey = (await getBitgoGpgPubKey(this.bitgo)).mpcV1;
66+
const bitgoGpgKey = useHardcodedBitGoKeys
67+
? await readKey({
68+
armoredKey: getBitgoMpcGpgPubKey(useHardcodedBitGoKeys.env, useHardcodedBitGoKeys.pubKeyType, 'mpcv1'),
69+
})
70+
: (await getBitgoGpgPubKey(this.bitgo)).mpcV1;
6071

6172
const userKeyPub = await openpgp.readKey({ armoredKey: userGpgPub });
6273
const userKeyId = userKeyPub.keyPacket.getFingerprint();

0 commit comments

Comments
 (0)