Skip to content

Commit b504d95

Browse files
committed
fix(sdk): change password should work with ofc multi-user key
TICKET: WP-7461
1 parent 13d2e09 commit b504d95

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

modules/bitgo/test/v2/unit/keychains.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,37 @@ describe('V2 Keychains', function () {
341341
const keys = await keychains.updatePassword({ oldPassword: oldPassword, newPassword: newPassword });
342342
validateKeys(keys, newPassword, 1);
343343
});
344+
345+
it('should update multi-user-ofc keys', async function () {
346+
nock(bgUrl)
347+
.get('/api/v2/tltc/key')
348+
.query(true)
349+
.reply(200, {
350+
keys: [
351+
{
352+
id: 'randomid1',
353+
encryptedPrv: bitgo.encrypt({ input: 'xprv1', password: oldPassword }),
354+
coinSpecific: {
355+
ofc: {
356+
features: ['multi-user-key'],
357+
},
358+
},
359+
},
360+
{
361+
id: 'randomid2',
362+
encryptedPrv: bitgo.encrypt({ input: 'xprv2', password: otherPassword }),
363+
coinSpecific: {
364+
ofc: {
365+
features: ['multi-user-key'],
366+
},
367+
},
368+
},
369+
],
370+
});
371+
372+
const keys = await keychains.updatePassword({ oldPassword: oldPassword, newPassword: newPassword });
373+
validateKeys(keys, newPassword, 1);
374+
});
344375
});
345376

346377
describe('Create TSS Keychains', function () {

modules/sdk-core/src/bitgo/keychain/keychains.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ export class Keychains implements IKeychains {
119119
newPassword: params.newPassword,
120120
});
121121
if (updatedKeychain.encryptedPrv) {
122-
const changedKeyIdentifier = updatedKeychain.type === 'tss' ? updatedKeychain.id : updatedKeychain.pub;
122+
// Both TSS and multi-user-ofc keys have multiple public keys in their key document and thus need to use objectID
123+
const changedKeyIdentifier =
124+
updatedKeychain.type === 'tss' || Keychains.isMultiUserKey(updatedKeychain)
125+
? updatedKeychain.id
126+
: updatedKeychain.pub;
123127
if (changedKeyIdentifier) {
124128
changedKeys[changedKeyIdentifier] = updatedKeychain.encryptedPrv;
125129
}

0 commit comments

Comments
 (0)