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
2 changes: 1 addition & 1 deletion modules/abstract-lightning/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
]
},
"dependencies": {
"@bitgo/public-types": "6.17.0",
"@bitgo/public-types": "6.21.0",
"@bitgo/sdk-core": "^37.3.0",
"@bitgo/statics": "^58.43.0",
"@bitgo/utxo-lib": "^11.22.1",
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"superagent": "^9.0.1"
},
"devDependencies": {
"@bitgo/public-types": "6.17.0",
"@bitgo/public-types": "6.21.0",
"@bitgo/sdk-opensslbytes": "^2.1.0",
"@bitgo/sdk-test": "^9.1.46",
"@openpgp/web-stream-tools": "0.0.14",
Expand Down
2 changes: 1 addition & 1 deletion modules/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"superagent": "^9.0.1"
},
"devDependencies": {
"@bitgo/public-types": "6.17.0",
"@bitgo/public-types": "6.21.0",
"@bitgo/sdk-lib-mpc": "^10.14.0",
"@bitgo/sdk-test": "^9.1.46",
"@types/argparse": "^1.0.36",
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-flrp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@bitgo/sdk-test": "^9.1.46"
},
"dependencies": {
"@bitgo/public-types": "6.17.0",
"@bitgo/public-types": "6.21.0",
"@bitgo/sdk-core": "^37.3.0",
"@bitgo/secp256k1": "^1.11.0",
"@bitgo/statics": "^58.43.0",
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-sol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"dependencies": {
"@bitgo/logger": "^1.4.0",
"@bitgo/public-types": "6.17.0",
"@bitgo/public-types": "6.21.0",
"@bitgo/sdk-core": "^37.3.0",
"@bitgo/sdk-lib-mpc": "^10.14.0",
"@bitgo/statics": "^58.43.0",
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
]
},
"dependencies": {
"@bitgo/public-types": "6.17.0",
"@bitgo/public-types": "6.21.0",
"@bitgo/sdk-lib-mpc": "^10.14.0",
"@bitgo/secp256k1": "^1.11.0",
"@bitgo/sjcl": "^1.1.0",
Expand Down
163 changes: 163 additions & 0 deletions modules/sdk-core/src/bitgo/utils/tss/eddsa/SMC/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import assert from 'assert';
import {
EddsaBitgoToOVC1Round1Response,
EddsaBitgoToOVC1Round2Response,
EddsaKeyCreationMPCv2StateEnum,
EddsaMPCv2KeyGenRound1Response,
EddsaMPCv2KeyGenRound2Response,
EddsaOVC1ToBitgoRound1Payload,
EddsaOVC2ToBitgoRound2Payload,
OVCIndexEnum,
} from '@bitgo/public-types';
import { IBaseCoin } from '../../../../baseCoin';
import { BitGoBase } from '../../../../bitgoBase';
import { decodeOrElse, Keychain } from '../../../..';
import { EddsaMPCv2Utils } from '../eddsaMPCv2';
import { EddsaMPCv2KeyGenSendFn, KeyGenSenderForEnterprise } from '../eddsaMPCv2KeyGenSender';

export class MPCv2SMCUtils {
private MPCv2Utils: EddsaMPCv2Utils;

constructor(private bitgo: BitGoBase, private baseCoin: IBaseCoin) {
this.MPCv2Utils = new EddsaMPCv2Utils(bitgo, baseCoin);
}

public async keyGenRound1(
enterprise: string,
payload: EddsaOVC1ToBitgoRound1Payload
): Promise<EddsaBitgoToOVC1Round1Response> {
return this.keyGenRound1BySender(KeyGenSenderForEnterprise(this.bitgo, enterprise), payload);
}

public async keyGenRound2(
enterprise: string,
payload: EddsaOVC2ToBitgoRound2Payload
): Promise<EddsaBitgoToOVC1Round2Response> {
return this.keyGenRound2BySender(KeyGenSenderForEnterprise(this.bitgo, enterprise), payload);
}

public async keyGenRound1BySender(
senderFn: EddsaMPCv2KeyGenSendFn<EddsaMPCv2KeyGenRound1Response>,
payload: EddsaOVC1ToBitgoRound1Payload
): Promise<EddsaBitgoToOVC1Round1Response> {
assert(
payload.state === EddsaKeyCreationMPCv2StateEnum.WaitingForBitgoRound1Data,
`Invalid state for round 1, expected: ${EddsaKeyCreationMPCv2StateEnum.WaitingForBitgoRound1Data}, got: ${payload.state}`
);
decodeOrElse(EddsaOVC1ToBitgoRound1Payload.name, EddsaOVC1ToBitgoRound1Payload, payload, (errors) => {
throw new Error(`error(s) parsing payload: ${errors}`);
});

const ovc1 = payload.ovc[OVCIndexEnum.ONE];
const ovc2 = payload.ovc[OVCIndexEnum.TWO];
const result = await this.MPCv2Utils.sendKeyGenerationRound1BySender(senderFn, {
userGpgPublicKey: ovc1.gpgPubKey,
backupGpgPublicKey: ovc2.gpgPubKey,
userMsg1: ovc1.ovcMsg1,
backupMsg1: ovc2.ovcMsg1,
});

const response = {
state: EddsaKeyCreationMPCv2StateEnum.WaitingForOVC1Round2Data,
tssVersion: payload.tssVersion,
walletType: payload.walletType,
coin: payload.coin,
ovc: payload.ovc,
Comment thread
kisslove-dewangan marked this conversation as resolved.
platform: {
sessionId: result.sessionId,
bitgoMsg1: result.bitgoMsg1,
},
};

return decodeOrElse(EddsaBitgoToOVC1Round1Response.name, EddsaBitgoToOVC1Round1Response, response, (errors) => {
throw new Error(`error(s) parsing response: ${errors}`);
});
}

public async keyGenRound2BySender(
senderFn: EddsaMPCv2KeyGenSendFn<EddsaMPCv2KeyGenRound2Response>,
payload: EddsaOVC2ToBitgoRound2Payload
): Promise<EddsaBitgoToOVC1Round2Response> {
assert(
payload.state === EddsaKeyCreationMPCv2StateEnum.WaitingForBitgoRound2Data,
`Invalid state for round 2, expected: ${EddsaKeyCreationMPCv2StateEnum.WaitingForBitgoRound2Data}, got: ${payload.state}`
);
decodeOrElse(EddsaOVC2ToBitgoRound2Payload.name, EddsaOVC2ToBitgoRound2Payload, payload, (errors) => {
throw new Error(`error(s) parsing payload: ${errors}`);
});

const ovc1 = payload.ovc[OVCIndexEnum.ONE];
const ovc2 = payload.ovc[OVCIndexEnum.TWO];
const sessionId = payload.platform.sessionId;
const result = await this.MPCv2Utils.sendKeyGenerationRound2BySender(senderFn, {
sessionId,
userMsg2: ovc1.ovcMsg2,
backupMsg2: ovc2.ovcMsg2,
});

assert.equal(sessionId, result.sessionId, 'Round 1 and round 2 session IDs do not match');
Comment thread
kisslove-dewangan marked this conversation as resolved.

const keychains = this.baseCoin.keychains();
const bitgoKeychain = await keychains.add({
source: 'bitgo',
keyType: 'tss',
commonKeychain: result.commonPublicKeychain,
isMPCv2: true,
});

const response = {
state: EddsaKeyCreationMPCv2StateEnum.WaitingForOVC1GenerateKey,
bitGoKeyId: bitgoKeychain.id,
tssVersion: payload.tssVersion,
walletType: payload.walletType,
coin: payload.coin,
ovc: payload.ovc,
platform: {
// sessionId carried over from payload.platform; safe because the assert above
// guarantees it equals result.sessionId.
...payload.platform,
commonPublicKeychain: result.commonPublicKeychain,
bitgoMsg2: result.bitgoMsg2,
},
};

return decodeOrElse(EddsaBitgoToOVC1Round2Response.name, EddsaBitgoToOVC1Round2Response, response, (errors) => {
throw new Error(`error(s) parsing response: ${errors}`);
});
}

public async uploadClientKeys(
bitgoKeyId: string,
userCommonKeychain: string,
backupCommonKeychain: string
): Promise<{ userKeychain: Keychain; backupKeychain: Keychain; bitgoKeychain: Keychain }> {
assert(
userCommonKeychain === backupCommonKeychain,
'Common keychain mismatch between the user and backup keychains'
);

const keychains = this.baseCoin.keychains();
const bitgoKeychain = await keychains.get({ id: bitgoKeyId });
assert(bitgoKeychain, 'Keychain not found');
assert(bitgoKeychain.source === 'bitgo', 'The keychain is not a BitGo keychain');
assert(bitgoKeychain.type === 'tss', 'BitGo keychain is not a TSS keychain');
assert(bitgoKeychain.commonKeychain, 'BitGo keychain does not have a common keychain');
assert(bitgoKeychain.commonKeychain === userCommonKeychain, 'Common keychain mismatch between the OVCs and BitGo');

const userKeychainPromise = keychains.add({
source: 'user',
keyType: 'tss',
commonKeychain: userCommonKeychain,
isMPCv2: true,
});
const backupKeychainPromise = keychains.add({
source: 'backup',
keyType: 'tss',
commonKeychain: backupCommonKeychain,
isMPCv2: true,
});

const [userKeychain, backupKeychain] = await Promise.all([userKeychainPromise, backupKeychainPromise]);
return { userKeychain, backupKeychain, bitgoKeychain };
}
}
Comment thread
kisslove-dewangan marked this conversation as resolved.
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/utils/tss/eddsa/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export {
export * from './eddsaMPCv2';
export * from './eddsaMPCv2KeyGenSender';
export * from './typesEddsaMPCv2';
export * from './SMC/utils';
Loading
Loading