Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions modules/sdk-coin-sol/src/sol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,13 +1267,8 @@ export class Sol extends BaseCoin {
const index = params.index || 0;
const currPath = params.seed ? getDerivationPath(params.seed) + `/${index}` : `m/${index}`;

let accountId: string;
if (isMpcV2) {
accountId = deriveUnhardenedMps(bitgoKey, currPath).slice(0, 64);
} else {
const MPC = await EDDSAMethods.getInitializedMpcInstance();
accountId = MPC.deriveUnhardened(bitgoKey, currPath).slice(0, 64);
}
const MPC = await EDDSAMethods.getInitializedMpcInstance();
const accountId = MPC.deriveUnhardened(bitgoKey, currPath).slice(0, 64);
const bs58EncodedPublicKey = new SolKeyPair({ pub: accountId }).getAddress();

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

let accountId: string;
if (isMpcV2) {
accountId = deriveUnhardenedMps(bitgoKey, currPath).slice(0, 64);
} else {
const MPC = await EDDSAMethods.getInitializedMpcInstance();
accountId = MPC.deriveUnhardened(bitgoKey, currPath).slice(0, 64);
}
const MPC = await EDDSAMethods.getInitializedMpcInstance();
const accountId = MPC.deriveUnhardened(bitgoKey, currPath).slice(0, 64);
const bs58EncodedPublicKey = new SolKeyPair({ pub: accountId }).getAddress();

const accountBalance = await this.getAccountBalance(bs58EncodedPublicKey);
Expand Down
18 changes: 10 additions & 8 deletions modules/sdk-coin-sol/test/unit/sol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3064,19 +3064,20 @@ describe('SOL:', function () {
mpcV2UserKey = encrypt(walletPassphrase, userDkg.getReducedKeyShare().toString('base64'));
mpcV2BackupKey = encrypt(walletPassphrase, backupDkg.getReducedKeyShare().toString('base64'));
mpcV2CommonKeyChain = userDkg.getCommonKeychain();
const mpc = await EDDSAMethods.getInitializedMpcInstance();
mpcV2WalletAddress = new KeyPair({
pub: deriveUnhardenedMps(mpcV2CommonKeyChain, 'm/0').slice(0, 64),
pub: mpc.deriveUnhardened(mpcV2CommonKeyChain, 'm/0').slice(0, 64),
}).getAddress();
mismatchedBitgoKey = otherUserDkg.getCommonKeychain();
mismatchedWalletAddress = new KeyPair({
pub: deriveUnhardenedMps(mismatchedBitgoKey, 'm/0').slice(0, 64),
pub: mpc.deriveUnhardened(mismatchedBitgoKey, 'm/0').slice(0, 64),
}).getAddress();

mpcV2TokenUserKey = encrypt(walletPassphrase, tokenUserDkg.getReducedKeyShare().toString('base64'));
mpcV2TokenBackupKey = encrypt(walletPassphrase, tokenBackupDkg.getReducedKeyShare().toString('base64'));
mpcV2TokenCommonKeyChain = tokenUserDkg.getCommonKeychain();
mpcV2TokenWalletAddress = new KeyPair({
pub: deriveUnhardenedMps(mpcV2TokenCommonKeyChain, 'm/0').slice(0, 64),
pub: mpc.deriveUnhardened(mpcV2TokenCommonKeyChain, 'm/0').slice(0, 64),
}).getAddress();

mpcV2RecoverParams = {
Expand Down Expand Up @@ -3959,10 +3960,11 @@ describe('SOL:', function () {
mpcV2UserKey = encrypt(walletPassphrase, userDkg.getReducedKeyShare().toString('base64'));
mpcV2BackupKey = encrypt(walletPassphrase, backupDkg.getReducedKeyShare().toString('base64'));
mpcV2CommonKeyChain = userDkg.getCommonKeychain();
const mpc = await EDDSAMethods.getInitializedMpcInstance();

mpcV2Address1 = new KeyPair({ pub: deriveUnhardenedMps(mpcV2CommonKeyChain, 'm/1').slice(0, 64) }).getAddress();
mpcV2Address2 = new KeyPair({ pub: deriveUnhardenedMps(mpcV2CommonKeyChain, 'm/2').slice(0, 64) }).getAddress();
mpcV2Address3 = new KeyPair({ pub: deriveUnhardenedMps(mpcV2CommonKeyChain, 'm/3').slice(0, 64) }).getAddress();
mpcV2Address1 = new KeyPair({ pub: mpc.deriveUnhardened(mpcV2CommonKeyChain, 'm/1').slice(0, 64) }).getAddress();
mpcV2Address2 = new KeyPair({ pub: mpc.deriveUnhardened(mpcV2CommonKeyChain, 'm/2').slice(0, 64) }).getAddress();
mpcV2Address3 = new KeyPair({ pub: mpc.deriveUnhardened(mpcV2CommonKeyChain, 'm/3').slice(0, 64) }).getAddress();

mpcV2TokenUserKey = encrypt(walletPassphrase, tokenUserDkg.getReducedKeyShare().toString('base64'));
mpcV2TokenBackupKey = encrypt(walletPassphrase, tokenBackupDkg.getReducedKeyShare().toString('base64'));
Expand All @@ -3972,7 +3974,7 @@ describe('SOL:', function () {
pub: deriveUnhardenedMps(mpcV2TokenCommonKeyChain, 'm/0').slice(0, 64),
}).getAddress();
mpcV2TokenAddress1 = new KeyPair({
pub: deriveUnhardenedMps(mpcV2TokenCommonKeyChain, 'm/1').slice(0, 64),
pub: mpc.deriveUnhardened(mpcV2TokenCommonKeyChain, 'm/1').slice(0, 64),
}).getAddress();
});

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