Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('signTxRequest:', function () {
it('should throw if round 2 response has wrong type', async function () {
const messageBuffer = Buffer.from(signableHex, 'hex');
const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(
await bitgoDsg.initDsg(
bitgoKeyShare,
messageBuffer,
txRequest.transactions![0].unsignedTx.derivationPath,
Expand Down Expand Up @@ -433,7 +433,7 @@ describe('signTxRequest:', function () {
: txRequest.transactions![0].unsignedTx.signableHex;
const messageBuffer = Buffer.from(txOrMessageToSign, 'hex');
const bitgoSession = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoSession.initDsg(
await bitgoSession.initDsg(
bitgoKeyShare,
messageBuffer,
txRequest.transactions?.[0].unsignedTx.derivationPath || 'm/0',
Expand Down
2 changes: 1 addition & 1 deletion modules/express/test/unit/clientRoutes/externalSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ describe('External signer', () => {
// Initialise BitGo-side DSG session (party 2, co-signing with User party 0)
const message = Buffer.from(signableHex, 'hex');
const bitgoDsg = new EddsaMPSDsg.DSG(2 /* BITGO */);
bitgoDsg.initDsg(bitgoKeyShareBuffer, message, derivationPath, 0 /* USER */);
await bitgoDsg.initDsg(bitgoKeyShareBuffer, message, derivationPath, 0 /* USER */);

const baseTxRequest = {
txRequestId: 'eddsa-mpcv2-round-trip-test',
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-sol/src/sol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ export class Sol extends BaseCoin {
throw new Error('EdDSA MPCv2 recovery: commonKeyChain from keycard does not match bitgoKey');
}

const signature = EDDSAUtils.signRecoveryEddsaMPCv2(
const signature = await EDDSAUtils.signRecoveryEddsaMPCv2(
unsignedTransaction.signablePayload,
currPath,
userKeyShare,
Expand Down
16 changes: 8 additions & 8 deletions modules/sdk-core/src/bitgo/utils/tss/eddsa/eddsaMPCv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export class EddsaMPCv2Utils extends BaseEddsaUtils {
const partyId = params.mpcv2PartyId ?? MPCv2PartiesEnum.USER;
const signerShareType = partyId === MPCv2PartiesEnum.USER ? SignatureShareType.USER : SignatureShareType.BACKUP;
const userDsg = new EddsaMPSDsg.DSG(partyId);
userDsg.initDsg(userKeyShare, bufferContent, derivationPath, MPCv2PartiesEnum.BITGO);
await userDsg.initDsg(userKeyShare, bufferContent, derivationPath, MPCv2PartiesEnum.BITGO);
const userMsg1 = userDsg.getFirstMessage();

// ── API Round 1 ───────────────────────────────────────────────────────────
Expand Down Expand Up @@ -581,7 +581,7 @@ export class EddsaMPCv2Utils extends BaseEddsaUtils {
const userGpgPrvKey = await pgp.readPrivateKey({ armoredKey: userGpgKey.privateKey });

const userDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.USER);
userDsg.initDsg(userKeyShare, Buffer.from(signableHex, 'hex'), derivationPath, MPCv2PartiesEnum.BITGO);
await userDsg.initDsg(userKeyShare, Buffer.from(signableHex, 'hex'), derivationPath, MPCv2PartiesEnum.BITGO);
const userMsg1 = userDsg.getFirstMessage();
const signatureShareRound1 = await getSignatureShareRoundOne(userMsg1, userGpgPrvKey);
const sessionPayload = JSON.stringify({
Expand Down Expand Up @@ -693,7 +693,7 @@ export class EddsaMPCv2Utils extends BaseEddsaUtils {
};

const userDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.USER);
userDsg.restoreSession(dsgSession);
await userDsg.restoreSession(dsgSession);
const userMsg1: MPSTypes.DeserializedMessage = {
from: MPCv2PartiesEnum.USER,
payload: new Uint8Array(Buffer.from(userMsgPayload, 'base64')),
Expand Down Expand Up @@ -800,7 +800,7 @@ export class EddsaMPCv2Utils extends BaseEddsaUtils {
};

const userDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.USER);
userDsg.restoreSession(dsgSession);
await userDsg.restoreSession(dsgSession);
const userMsg2: MPSTypes.DeserializedMessage = {
from: MPCv2PartiesEnum.USER,
payload: new Uint8Array(Buffer.from(userMsgPayload, 'base64')),
Expand Down Expand Up @@ -1021,25 +1021,25 @@ export async function getEddsaMpcV2RecoveryKeySharesFromReducedKey(
* @param commonKeyChain 128-hex-char string: 32-byte pub + 32-byte rootChainCode
* @returns 64-byte Ed25519 signature Buffer
*/
export function signRecoveryEddsaMPCv2(
export async function signRecoveryEddsaMPCv2(
message: Buffer,
derivationPath: string,
userKeyShare: Buffer,
backupKeyShare: Buffer,
commonKeyChain: string
): Buffer {
): Promise<Buffer> {
const userDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.USER);
const backupDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BACKUP);

const signature = MPSUtil.executeTillRound(
const signature = (await MPSUtil.executeTillRound(
3,
userDsg,
backupDsg,
userKeyShare,
backupKeyShare,
message,
derivationPath
) as Buffer;
)) as Buffer;

// deriveUnhardenedMps returns 128 hex chars: first 64 are the 32-byte public key
const derivedKeychain = deriveUnhardenedMps(commonKeyChain, derivationPath);
Expand Down
57 changes: 28 additions & 29 deletions modules/sdk-core/test/unit/bitgo/utils/tss/eddsa/eddsaMPCv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('EdDSA MPS DSG helper functions', async () => {
it('getSignatureShareRoundOne should build a valid round-1 share', async () => {
const messageBuffer = Buffer.from(signableHex, 'hex');
const userDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.USER);
userDsg.initDsg(userKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
await userDsg.initDsg(userKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
const userMsg1 = userDsg.getFirstMessage();

const share: SignatureShareRecord = await getSignatureShareRoundOne(userMsg1, userGpgPrivKey);
Expand All @@ -94,7 +94,7 @@ describe('EdDSA MPS DSG helper functions', async () => {
it('getSignatureShareRoundOne should build a valid backup round-1 share', async () => {
const messageBuffer = Buffer.from(signableHex, 'hex');
const backupDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BACKUP);
backupDsg.initDsg(backupKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
await backupDsg.initDsg(backupKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
const backupMsg1 = backupDsg.getFirstMessage();

const share: SignatureShareRecord = await getSignatureShareRoundOne(
Expand All @@ -119,7 +119,7 @@ describe('EdDSA MPS DSG helper functions', async () => {
it('verifyPeerMessageRoundOne should verify a valid BitGo round-1 message', async () => {
const messageBuffer = Buffer.from(signableHex, 'hex');
const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
const bitgoMsg1 = bitgoDsg.getFirstMessage();

const bitgoSignedMsg1 = await MPSComms.detachSignMpsMessage(Buffer.from(bitgoMsg1.payload), bitgoGpgPrivKey);
Expand Down Expand Up @@ -153,11 +153,11 @@ describe('EdDSA MPS DSG helper functions', async () => {
it('getSignatureShareRoundTwo should build a valid round-2 share', async () => {
const messageBuffer = Buffer.from(signableHex, 'hex');
const userDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.USER);
userDsg.initDsg(userKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
await userDsg.initDsg(userKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
const userMsg1 = userDsg.getFirstMessage();

const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
const bitgoMsg1 = bitgoDsg.getFirstMessage();

const bitgoSignedMsg1 = await MPSComms.detachSignMpsMessage(Buffer.from(bitgoMsg1.payload), bitgoGpgPrivKey);
Expand Down Expand Up @@ -185,11 +185,11 @@ describe('EdDSA MPS DSG helper functions', async () => {
it('getSignatureShareRoundTwo should build a valid backup round-2 share', async () => {
const messageBuffer = Buffer.from(signableHex, 'hex');
const backupDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BACKUP);
backupDsg.initDsg(backupKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
await backupDsg.initDsg(backupKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
const backupMsg1 = backupDsg.getFirstMessage();

const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BACKUP);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BACKUP);
const bitgoMsg1 = bitgoDsg.getFirstMessage();

const bitgoSignedMsg1 = await MPSComms.detachSignMpsMessage(Buffer.from(bitgoMsg1.payload), bitgoGpgPrivKey);
Expand Down Expand Up @@ -221,11 +221,11 @@ describe('EdDSA MPS DSG helper functions', async () => {
it('verifyPeerMessageRoundTwo should verify a valid BitGo round-2 message', async () => {
const messageBuffer = Buffer.from(signableHex, 'hex');
const userDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.USER);
userDsg.initDsg(userKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
await userDsg.initDsg(userKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
const userMsg1 = userDsg.getFirstMessage();

const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
const bitgoMsg1 = bitgoDsg.getFirstMessage();

const [bitgoMsg2] = bitgoDsg.handleIncomingMessages([bitgoMsg1, userMsg1]);
Expand Down Expand Up @@ -261,11 +261,11 @@ describe('EdDSA MPS DSG helper functions', async () => {
it('getSignatureShareRoundThree should build a valid round-3 share', async () => {
const messageBuffer = Buffer.from(signableHex, 'hex');
const userDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.USER);
userDsg.initDsg(userKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
await userDsg.initDsg(userKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
const userMsg1 = userDsg.getFirstMessage();

const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
const bitgoMsg1 = bitgoDsg.getFirstMessage();

// Advance to round 2
Expand Down Expand Up @@ -302,11 +302,11 @@ describe('EdDSA MPS DSG helper functions', async () => {
it('getSignatureShareRoundThree should build a valid backup round-3 share', async () => {
const messageBuffer = Buffer.from(signableHex, 'hex');
const backupDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BACKUP);
backupDsg.initDsg(backupKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
await backupDsg.initDsg(backupKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BITGO);
const backupMsg1 = backupDsg.getFirstMessage();

const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BACKUP);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.BACKUP);
const bitgoMsg1 = bitgoDsg.getFirstMessage();

const bitgoSignedMsg1 = await MPSComms.detachSignMpsMessage(Buffer.from(bitgoMsg1.payload), bitgoGpgPrivKey);
Expand Down Expand Up @@ -698,7 +698,7 @@ describe('EddsaMPCv2Utils.createOfflineRound2Share', () => {

const messageBuffer = Buffer.from(signableHex, 'hex');
const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);

const txRequestRound1 = await signBitgoEddsaRound1(
bitgoDsg,
Expand Down Expand Up @@ -756,7 +756,7 @@ describe('EddsaMPCv2Utils.createOfflineRound2Share', () => {

const messageBuffer = Buffer.from(signableHex, 'hex');
const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);

const txRequestRound1 = await signBitgoEddsaRound1(
bitgoDsg,
Expand Down Expand Up @@ -817,7 +817,7 @@ describe('EddsaMPCv2Utils.createOfflineRound2Share', () => {

const messageBuffer = Buffer.from(signableHex, 'hex');
const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);

const txRequestRound1 = await signBitgoEddsaRound1(
bitgoDsg,
Expand Down Expand Up @@ -869,7 +869,7 @@ describe('EddsaMPCv2Utils.createOfflineRound2Share', () => {

const messageBuffer = Buffer.from(signableHex, 'hex');
const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, derivationPath, MPCv2PartiesEnum.USER);

const txRequestRound1 = await signBitgoEddsaRound1(
bitgoDsg,
Expand Down Expand Up @@ -1073,7 +1073,7 @@ describe('EddsaMPCv2Utils.createOfflineRound3Share', () => {
const transaction = assertSingleTransaction(txRequest);
const messageBuffer = Buffer.from(transaction.unsignedTx.signableHex, 'hex');
const bitgoDsg = new EddsaMPSDsg.DSG(MPCv2PartiesEnum.BITGO);
bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, transaction.unsignedTx.derivationPath, MPCv2PartiesEnum.USER);
await bitgoDsg.initDsg(bitgoKeyShare, messageBuffer, transaction.unsignedTx.derivationPath, MPCv2PartiesEnum.USER);

const txRequestRound1 = await signBitgoEddsaRound1(
bitgoDsg,
Expand Down Expand Up @@ -1782,7 +1782,7 @@ describe('signRecoveryEddsaMPCv2', () => {
const message = Buffer.from('deadbeef', 'hex');
const commonKeyChain = userDkg.getCommonKeychain();

const signature = EDDSAUtils.signRecoveryEddsaMPCv2(
const signature = await EDDSAUtils.signRecoveryEddsaMPCv2(
message,
derivationPath,
userDkg.getKeyShare(),
Expand All @@ -1803,7 +1803,7 @@ describe('signRecoveryEddsaMPCv2', () => {
const message = Buffer.from('deadbeef', 'hex');
const commonKeyChain = userDkg.getCommonKeychain();

const signature = EDDSAUtils.signRecoveryEddsaMPCv2(
const signature = await EDDSAUtils.signRecoveryEddsaMPCv2(
message,
derivationPath,
userDkg.getKeyShare(),
Expand All @@ -1827,15 +1827,14 @@ describe('signRecoveryEddsaMPCv2', () => {
const [wrongDkg] = await MPSUtil.generateEdDsaDKGKeyShares();
const message = Buffer.from('deadbeef', 'hex');

assert.throws(
() =>
EDDSAUtils.signRecoveryEddsaMPCv2(
message,
derivationPath,
userDkg.getKeyShare(),
backupDkg.getKeyShare(),
wrongDkg.getCommonKeychain() // key chain from a different wallet
),
await assert.rejects(
EDDSAUtils.signRecoveryEddsaMPCv2(
message,
derivationPath,
userDkg.getKeyShare(),
backupDkg.getKeyShare(),
wrongDkg.getCommonKeychain() // key chain from a different wallet
),
/EdDSA MPCv2 recovery signature verification failed/
);
});
Expand Down
Loading
Loading