Skip to content

Commit 4ead1e3

Browse files
Marzooqaclaude
andcommitted
fix(sdk-coin-sol): migrate recover() and recoverCloseATA() to BIP32-Ed25519
Replace Silence Labs single-HMAC formula (deriveUnhardenedMps) with Eddsa.deriveUnhardened for MPCv2 account ID derivation in recover() and recoverCloseATA(). Update consolidation test fixtures that exercise recover() via recoverConsolidations(). Ticket: WCI-644 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0a81a68 commit 4ead1e3

2 files changed

Lines changed: 16 additions & 24 deletions

File tree

modules/sdk-coin-sol/src/sol.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,13 +1267,8 @@ export class Sol extends BaseCoin {
12671267
const index = params.index || 0;
12681268
const currPath = params.seed ? getDerivationPath(params.seed) + `/${index}` : `m/${index}`;
12691269

1270-
let accountId: string;
1271-
if (isMpcV2) {
1272-
accountId = deriveUnhardenedMps(bitgoKey, currPath).slice(0, 64);
1273-
} else {
1274-
const MPC = await EDDSAMethods.getInitializedMpcInstance();
1275-
accountId = MPC.deriveUnhardened(bitgoKey, currPath).slice(0, 64);
1276-
}
1270+
const MPC = await EDDSAMethods.getInitializedMpcInstance();
1271+
const accountId = MPC.deriveUnhardened(bitgoKey, currPath).slice(0, 64);
12771272
const bs58EncodedPublicKey = new SolKeyPair({ pub: accountId }).getAddress();
12781273

12791274
balance = await this.getAccountBalance(bs58EncodedPublicKey, params.apiKey);
@@ -1559,13 +1554,8 @@ export class Sol extends BaseCoin {
15591554
const index = params.index || 0;
15601555
const currPath = params.seed ? getDerivationPath(params.seed) + `/${index}` : `m/${index}`;
15611556

1562-
let accountId: string;
1563-
if (isMpcV2) {
1564-
accountId = deriveUnhardenedMps(bitgoKey, currPath).slice(0, 64);
1565-
} else {
1566-
const MPC = await EDDSAMethods.getInitializedMpcInstance();
1567-
accountId = MPC.deriveUnhardened(bitgoKey, currPath).slice(0, 64);
1568-
}
1557+
const MPC = await EDDSAMethods.getInitializedMpcInstance();
1558+
const accountId = MPC.deriveUnhardened(bitgoKey, currPath).slice(0, 64);
15691559
const bs58EncodedPublicKey = new SolKeyPair({ pub: accountId }).getAddress();
15701560

15711561
const accountBalance = await this.getAccountBalance(bs58EncodedPublicKey);

modules/sdk-coin-sol/test/unit/sol.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
Wallet,
2424
WalletCoinSpecific,
2525
} from '@bitgo/sdk-core';
26-
import { deriveUnhardenedMps, MPSUtil } from '@bitgo/sdk-lib-mpc';
26+
import { MPSUtil } from '@bitgo/sdk-lib-mpc';
2727
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
2828
import { coins } from '@bitgo/statics';
2929
import {
@@ -3064,19 +3064,20 @@ describe('SOL:', function () {
30643064
mpcV2UserKey = encrypt(walletPassphrase, userDkg.getReducedKeyShare().toString('base64'));
30653065
mpcV2BackupKey = encrypt(walletPassphrase, backupDkg.getReducedKeyShare().toString('base64'));
30663066
mpcV2CommonKeyChain = userDkg.getCommonKeychain();
3067+
const mpc = await EDDSAMethods.getInitializedMpcInstance();
30673068
mpcV2WalletAddress = new KeyPair({
3068-
pub: deriveUnhardenedMps(mpcV2CommonKeyChain, 'm/0').slice(0, 64),
3069+
pub: mpc.deriveUnhardened(mpcV2CommonKeyChain, 'm/0').slice(0, 64),
30693070
}).getAddress();
30703071
mismatchedBitgoKey = otherUserDkg.getCommonKeychain();
30713072
mismatchedWalletAddress = new KeyPair({
3072-
pub: deriveUnhardenedMps(mismatchedBitgoKey, 'm/0').slice(0, 64),
3073+
pub: mpc.deriveUnhardened(mismatchedBitgoKey, 'm/0').slice(0, 64),
30733074
}).getAddress();
30743075

30753076
mpcV2TokenUserKey = encrypt(walletPassphrase, tokenUserDkg.getReducedKeyShare().toString('base64'));
30763077
mpcV2TokenBackupKey = encrypt(walletPassphrase, tokenBackupDkg.getReducedKeyShare().toString('base64'));
30773078
mpcV2TokenCommonKeyChain = tokenUserDkg.getCommonKeychain();
30783079
mpcV2TokenWalletAddress = new KeyPair({
3079-
pub: deriveUnhardenedMps(mpcV2TokenCommonKeyChain, 'm/0').slice(0, 64),
3080+
pub: mpc.deriveUnhardened(mpcV2TokenCommonKeyChain, 'm/0').slice(0, 64),
30803081
}).getAddress();
30813082

30823083
mpcV2RecoverParams = {
@@ -3959,20 +3960,21 @@ describe('SOL:', function () {
39593960
mpcV2UserKey = encrypt(walletPassphrase, userDkg.getReducedKeyShare().toString('base64'));
39603961
mpcV2BackupKey = encrypt(walletPassphrase, backupDkg.getReducedKeyShare().toString('base64'));
39613962
mpcV2CommonKeyChain = userDkg.getCommonKeychain();
3963+
const mpc = await EDDSAMethods.getInitializedMpcInstance();
39623964

3963-
mpcV2Address1 = new KeyPair({ pub: deriveUnhardenedMps(mpcV2CommonKeyChain, 'm/1').slice(0, 64) }).getAddress();
3964-
mpcV2Address2 = new KeyPair({ pub: deriveUnhardenedMps(mpcV2CommonKeyChain, 'm/2').slice(0, 64) }).getAddress();
3965-
mpcV2Address3 = new KeyPair({ pub: deriveUnhardenedMps(mpcV2CommonKeyChain, 'm/3').slice(0, 64) }).getAddress();
3965+
mpcV2Address1 = new KeyPair({ pub: mpc.deriveUnhardened(mpcV2CommonKeyChain, 'm/1').slice(0, 64) }).getAddress();
3966+
mpcV2Address2 = new KeyPair({ pub: mpc.deriveUnhardened(mpcV2CommonKeyChain, 'm/2').slice(0, 64) }).getAddress();
3967+
mpcV2Address3 = new KeyPair({ pub: mpc.deriveUnhardened(mpcV2CommonKeyChain, 'm/3').slice(0, 64) }).getAddress();
39663968

39673969
mpcV2TokenUserKey = encrypt(walletPassphrase, tokenUserDkg.getReducedKeyShare().toString('base64'));
39683970
mpcV2TokenBackupKey = encrypt(walletPassphrase, tokenBackupDkg.getReducedKeyShare().toString('base64'));
39693971
mpcV2TokenCommonKeyChain = tokenUserDkg.getCommonKeychain();
39703972

39713973
mpcV2TokenBaseAddress = new KeyPair({
3972-
pub: deriveUnhardenedMps(mpcV2TokenCommonKeyChain, 'm/0').slice(0, 64),
3974+
pub: mpc.deriveUnhardened(mpcV2TokenCommonKeyChain, 'm/0').slice(0, 64),
39733975
}).getAddress();
39743976
mpcV2TokenAddress1 = new KeyPair({
3975-
pub: deriveUnhardenedMps(mpcV2TokenCommonKeyChain, 'm/1').slice(0, 64),
3977+
pub: mpc.deriveUnhardened(mpcV2TokenCommonKeyChain, 'm/1').slice(0, 64),
39763978
}).getAddress();
39773979
});
39783980

@@ -4105,7 +4107,7 @@ describe('SOL:', function () {
41054107
.resolves(testData.SolResponses.getAccountBalanceResponseNoFunds);
41064108
}
41074109
const mpcV2Address4 = new KeyPair({
4108-
pub: deriveUnhardenedMps(mpcV2CommonKeyChain, 'm/4').slice(0, 64),
4110+
pub: (await EDDSAMethods.getInitializedMpcInstance()).deriveUnhardened(mpcV2CommonKeyChain, 'm/4').slice(0, 64),
41094111
}).getAddress();
41104112
callBack
41114113
.withArgs({ payload: { id: '1', jsonrpc: '2.0', method: 'getBalance', params: [mpcV2Address4] } })

0 commit comments

Comments
 (0)