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
11 changes: 4 additions & 7 deletions src/__tests__/api/advancedWalletManager/recoveryMpcV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ describe('recoveryMpcV2', async () => {
// nocks for KMS responses
const userKmsNock = nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'user', useLocalEncipherment: false })
.query({ source: 'user' })
.reply(200, mockKmsUserResponse)
.persist();
const backupKmsNock = nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'backup', useLocalEncipherment: false })
.query({ source: 'backup' })
.reply(200, mockKmsBackupResponse)
.persist();

Expand Down Expand Up @@ -139,13 +139,10 @@ describe('recoveryMpcV2', async () => {
};

// nocks for KMS responses
nock(kmsUrl).get(`/key/${input.pub}`).query({ source: 'user' }).reply(200, mockKmsUserResponse);
nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'user', useLocalEncipherment: false })
.reply(200, mockKmsUserResponse);
nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'backup', useLocalEncipherment: false })
.query({ source: 'backup' })
.reply(200, mockKmsBackupResponse);

const signatureResponse = await agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ describe('recoveryMultisigTransaction', () => {

const kmsNockUser = nock(kmsUrl)
.get(`/key/${userPub}`)
.query({ source: 'user', useLocalEncipherment: false })
.query({ source: 'user' })
.reply(200, mockKmsUserResponse);

const kmsNockBackup = nock(kmsUrl)
.get(`/key/${backupPub}`)
.query({ source: 'backup', useLocalEncipherment: false })
.query({ source: 'backup' })
.reply(200, mockKmsBackupResponse);

const response = await agent
Expand Down Expand Up @@ -129,12 +129,12 @@ describe('recoveryMultisigTransaction', () => {

const kmsNockUser = nock(kmsUrl)
.get(`/key/${userPub}`)
.query({ source: 'user', useLocalEncipherment: false })
.query({ source: 'user' })
.reply(200, mockKmsUserResponse);

const kmsNockBackup = nock(kmsUrl)
.get(`/key/${backupPub}`)
.query({ source: 'backup', useLocalEncipherment: false })
.query({ source: 'backup' })
.reply(200, mockKmsBackupResponse);

const response = await agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ describe('EdDSA Recovery Signing', () => {
pub: commonKeychain,
source: 'user',
cfg: config,
options: { useLocalEncipherment: false },
})
.resolves(JSON.stringify(userPrvShare));

Expand All @@ -109,7 +108,6 @@ describe('EdDSA Recovery Signing', () => {
pub: commonKeychain,
source: 'backup',
cfg: config,
options: { useLocalEncipherment: false },
})
.resolves(JSON.stringify(backupPrvShare));

Expand All @@ -136,7 +134,6 @@ describe('EdDSA Recovery Signing', () => {
pub: commonKeychain,
source: 'user',
cfg: config,
options: { useLocalEncipherment: false },
})
.should.be.true();

Expand All @@ -145,7 +142,6 @@ describe('EdDSA Recovery Signing', () => {
pub: commonKeychain,
source: 'backup',
cfg: config,
options: { useLocalEncipherment: false },
})
.should.be.true();
});
Expand All @@ -157,7 +153,6 @@ describe('EdDSA Recovery Signing', () => {
pub: commonKeychain,
source: 'user',
cfg: config,
options: { useLocalEncipherment: false },
})
.resolves(undefined);

Expand Down Expand Up @@ -185,7 +180,6 @@ describe('EdDSA Recovery Signing', () => {
pub: commonKeychain,
source: 'user',
cfg: config,
options: { useLocalEncipherment: false },
})
.resolves(JSON.stringify(userPrvShare));

Expand All @@ -194,7 +188,6 @@ describe('EdDSA Recovery Signing', () => {
pub: commonKeychain,
source: 'backup',
cfg: config,
options: { useLocalEncipherment: false },
})
.resolves(undefined);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('signMpcTransaction', () => {
// Mock KMS responses
const kmsNock = nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'user', useLocalEncipherment: false })
.query({ source: 'user' })
.reply(200, mockKmsResponse);

const dataKeyNock = nock(kmsUrl).post('/generateDataKey').reply(200, mockDataKeyResponse);
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('signMpcTransaction', () => {
// Mock KMS responses for R share
const rKmsNock = nock(kmsUrl)
.get(`/key/${rInput.pub}`)
.query({ source: 'user', useLocalEncipherment: false })
.query({ source: 'user' })
.reply(200, mockKmsResponse);

const decryptDataKeyNock = nock(kmsUrl)
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('signMpcTransaction', () => {
// Mock KMS response for G share
const gKmsNock = nock(kmsUrl)
.get(`/key/${gInput.pub}`)
.query({ source: 'user', useLocalEncipherment: false })
.query({ source: 'user' })
.reply(200, mockKmsResponse);

const gResponse = await agent
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('signMpcTransaction', () => {

const kmsNock = nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'user', useLocalEncipherment: false })
.query({ source: 'user' })
.reply(404, { error: 'Key not found' });

const response = await agent
Expand Down Expand Up @@ -372,7 +372,7 @@ describe('signMpcTransaction', () => {
// Mock KMS responses for Round 1
const kmsNock = nock(kmsUrl)
.get(`/key/${round1Input.pub}`)
.query({ source: 'user', useLocalEncipherment: true })
.query({ source: 'user' })
.reply(200, mockKmsResponse);

const dataKeyNock = nock(kmsUrl).post('/generateDataKey').reply(200, mockDataKeyResponse);
Expand Down Expand Up @@ -434,7 +434,7 @@ describe('signMpcTransaction', () => {
// Mock KMS responses for Round 2
const r2KmsNock = nock(kmsUrl)
.get(`/key/${round2Input.pub}`)
.query({ source: 'user', useLocalEncipherment: true })
.query({ source: 'user' })
.reply(200, mockKmsResponse);

const decryptDataKeyNock = nock(kmsUrl)
Expand Down Expand Up @@ -482,7 +482,7 @@ describe('signMpcTransaction', () => {
// Mock KMS responses for Round 3
const r3KmsNock = nock(kmsUrl)
.get(`/key/${round3Input.pub}`)
.query({ source: 'user', useLocalEncipherment: true })
.query({ source: 'user' })
.reply(200, mockKmsResponse);

const r3DecryptDataKeyNock = nock(kmsUrl)
Expand Down Expand Up @@ -564,7 +564,7 @@ describe('signMpcTransaction', () => {

const kmsNock = nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'user', useLocalEncipherment: true })
.query({ source: 'user' })
.reply(200, mockKmsResponse);

const response = await agent
Expand Down Expand Up @@ -599,7 +599,7 @@ describe('signMpcTransaction', () => {

const kmsNock = nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'user', useLocalEncipherment: true })
.query({ source: 'user' })
.reply(200, mockKmsResponse);

const response = await agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('signMultisigTransaction', () => {

const kmsNock = nock(kmsUrl)
.get(`/key/${input.pub}`)
.query({ source: 'user', useLocalEncipherment: false })
.query({ source: 'user' })
.reply(200, mockKmsResponse);

const response = await agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ export async function ecdsaMPCv2Finalize(
pub: commonKeychain,
prv: privateMaterial.toString('base64'),
type: 'tss',
options: {
useLocalEncipherment: true,
},
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,12 @@ export async function signEddsaRecoveryTransaction({
pub: request.commonKeychain.toString(),
source: 'user',
cfg,
options: { useLocalEncipherment: false },
});

const backupPrv = await retrieveKmsPrvKey({
pub: request.commonKeychain.toString(),
source: 'backup',
cfg,
options: { useLocalEncipherment: false },
});

if (!userPrv || !backupPrv) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,9 @@ export async function signMpcTransaction(req: AwmApiSpecRouteRequest<'v1.mpc.sig

const bitgo = req.bitgo;
const coinInstance = await coinFactory.getCoin(coin, bitgo);
const options =
coinInstance.getMPCAlgorithm() === 'ecdsa'
? {
useLocalEncipherment: true,
}
: undefined;

// Get private key from KMS
const prv = await retrieveKmsPrvKey({ pub, source, cfg: req.config, options });
const prv = await retrieveKmsPrvKey({ pub, source, cfg: req.config });

if (!prv) {
const errorMsg = `Error while MPC signing, missing prv key for pub=${pub}, source=${source}`;
Expand Down
6 changes: 1 addition & 5 deletions src/api/advancedWalletManager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ export async function retrieveKmsPrvKey({
pub,
source,
cfg,
options,
}: {
pub: string;
source: string;
cfg: AdvancedWalletManagerConfig;
options?: {
useLocalEncipherment?: boolean;
};
}): Promise<string> {
const kms = new KmsClient(cfg);
// Retrieve the private key from KMS
let prv: string;
try {
const res = await kms.getKey({ pub, source, options });
const res = await kms.getKey({ pub, source });
prv = res.prv;
return prv;
} catch (error: any) {
Expand Down
1 change: 0 additions & 1 deletion src/kms/kmsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export class KmsClient {
try {
let req = superagent.get(`${this.url}/key/${params.pub}`).query({
source: params.source,
useLocalEncipherment: params.options?.useLocalEncipherment ?? false,
});
if (this.agent) req = req.agent(this.agent);
kmsResponse = await req;
Expand Down
3 changes: 0 additions & 3 deletions src/kms/types/getKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import * as z from 'zod';
export interface GetKeyParams {
pub: string;
source: string;
options?: {
useLocalEncipherment?: boolean;
};
}

export interface GetKeyResponse {
Expand Down
3 changes: 0 additions & 3 deletions src/kms/types/postKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ export interface PostKeyParams {
source: string;
type: 'independent' | 'tss';
seed?: string; // Optional seed for key generation
options?: {
useLocalEncipherment?: boolean;
};
}

export interface PostKeyResponse {
Expand Down