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
4 changes: 2 additions & 2 deletions modules/bitgo/src/v2/internal/blsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class BlsUtils extends MpcUtils {

const userKeychainParams: any = {
source: 'user',
type: 'blsdkg',
keyType: 'blsdkg',
commonPub: commonPub,
encryptedPrv: this.bitgo.encrypt({ input: userPrivateKey, password: passphrase }),
originalPasscodeEncryptionCode: originalPasscodeEncryptionCode,
Expand Down Expand Up @@ -132,7 +132,7 @@ export class BlsUtils extends MpcUtils {

return await this.baseCoin.keychains().createBackup({
source: 'backup',
type: 'blsdkg',
keyType: 'blsdkg',
commonPub: commonPub,
prv: backupPrivateKey,
encryptedPrv: this.bitgo.encrypt({ input: backupPrivateKey, password: passphrase }),
Expand Down
6 changes: 3 additions & 3 deletions modules/bitgo/src/v2/internal/mpcUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { SerializedKeyPair, readPrivateKey, decrypt, readMessage } from 'openpgp';
import { BitGo } from '../../bitgo';
import { BaseCoin, KeychainsTriplet } from '../baseCoin';
import { Keychain } from '../keychains';
import { Keychain, KeyType } from '../keychains';
import { encryptText, getBitgoGpgPubKey } from './opengpgUtils';

export interface MpcKeyShare {
Expand Down Expand Up @@ -43,15 +43,15 @@ export abstract class MpcUtils {
userGpgKey: SerializedKeyPair<string>,
userKeyShare: MpcKeyShare,
backupKeyShare: MpcKeyShare,
keyType: string,
keyType: KeyType,
enterprise?: string
): Promise<Keychain> {
const bitgoKey = await getBitgoGpgPubKey(this.bitgo);
const encUserToBitGoMessage = await encryptText(userKeyShare.privateShare, bitgoKey);
const encBackupToBitGoMessage = await encryptText(backupKeyShare.privateShare, bitgoKey);

const createBitGoMPCParams = {
type: keyType,
keyType,
source: 'bitgo',
keyShares: [
{
Expand Down
6 changes: 3 additions & 3 deletions modules/bitgo/src/v2/internal/tssUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Eddsa, {
} from '@bitgo/account-lib/dist/src/mpc/tss';

import { BaseCoin, KeychainsTriplet } from '../baseCoin';
import { Keychain } from '../keychains';
import { Keychain, KeyType } from '../keychains';
import { BitGo } from '../../bitgo';
import { encryptText, getBitgoGpgPubKey } from './opengpgUtils';
import { MpcUtils } from './mpcUtils';
Expand Down Expand Up @@ -151,7 +151,7 @@ export class TssUtils extends MpcUtils {

const userKeychainParams = {
source: 'user',
type: 'tss',
keyType: 'tss' as KeyType,
commonKeychain: bitgoKeychain.commonKeychain,
encryptedPrv: this.bitgo.encrypt({ input: JSON.stringify(userSigningMaterial), password: passphrase }),
originalPasscodeEncryptionCode,
Expand Down Expand Up @@ -213,7 +213,7 @@ export class TssUtils extends MpcUtils {

return await this.baseCoin.keychains().createBackup({
source: 'backup',
type: 'tss',
keyType: 'tss',
commonKeychain: bitgoKeychain.commonKeychain,
prv: prv,
encryptedPrv: this.bitgo.encrypt({ input: prv, password: passphrase }),
Expand Down
9 changes: 8 additions & 1 deletion modules/bitgo/src/v2/keychains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { TssUtils } from './internal/tssUtils';
import { BlsUtils } from './internal/blsUtils';

const { validateParams } = common;

export type KeyType = 'tss' | 'independent' | 'blsdkg';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


export interface Keychain {
id: string;
pub: string;
Expand Down Expand Up @@ -60,6 +63,7 @@ interface AddKeychainOptions {
commonKeychain?: string;
encryptedPrv?: string;
type?: string;
keyType?: KeyType;
source?: string;
originalPasscodeEncryptionCode?: string;
enterprise?: string;
Expand All @@ -86,6 +90,7 @@ export interface CreateBackupOptions {
disableKRSEmail?: boolean;
krsSpecific?: any;
type?: string;
keyType?: KeyType;
reqId?: RequestTracer;
commonPub?: string;
commonKeychain?: string;
Expand All @@ -97,6 +102,7 @@ interface CreateBitGoOptions {
source?: 'bitgo';
enterprise?: string;
reqId?: RequestTracer;
keyType?: KeyType;
}

interface CreateMpcOptions {
Expand Down Expand Up @@ -276,7 +282,7 @@ export class Keychains {
*/
async add(params: AddKeychainOptions = {}): Promise<Keychain> {
params = params || {};
validateParams(params, [], ['pub', 'encryptedPrv', 'type', 'source', 'originalPasscodeEncryptionCode', 'enterprise', 'derivedFromParentWithSeed']);
validateParams(params, [], ['pub', 'encryptedPrv', 'keyType', 'type', 'source', 'originalPasscodeEncryptionCode', 'enterprise', 'derivedFromParentWithSeed']);

if (!_.isUndefined(params.disableKRSEmail)) {
if (!_.isBoolean(params.disableKRSEmail)) {
Expand All @@ -294,6 +300,7 @@ export class Keychains {
commonKeychain: params.commonKeychain,
encryptedPrv: params.encryptedPrv,
type: params.type,
keyType: params.keyType,
source: params.source,
provider: params.provider,
originalPasscodeEncryptionCode: params.originalPasscodeEncryptionCode,
Expand Down
6 changes: 3 additions & 3 deletions modules/bitgo/test/v2/unit/internal/blsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe('BLS Utils:', async function () {
};

nock(bgUrl)
.post(`/api/v2/${params.coin}/key`, _.matches({ type: 'blsdkg', source: 'bitgo' }))
.post(`/api/v2/${params.coin}/key`, _.matches({ keyType: 'blsdkg', source: 'bitgo' }))
.reply(200, bitgoKeychain);

return bitgoKeychain;
Expand All @@ -267,7 +267,7 @@ describe('BLS Utils:', async function () {
};

nock('https://bitgo.fakeurl')
.post(`/api/v2/${params.coin}/key`, _.matches({ type: 'blsdkg', source: 'user' }))
.post(`/api/v2/${params.coin}/key`, _.matches({ keyType: 'blsdkg', source: 'user' }))
.reply(200, userKeychain);

return userKeychain;
Expand All @@ -282,7 +282,7 @@ describe('BLS Utils:', async function () {
};

nock('https://bitgo.fakeurl')
.post(`/api/v2/${params.coin}/key`, _.matches({ type: 'blsdkg', source: 'backup' }))
.post(`/api/v2/${params.coin}/key`, _.matches({ keyType: 'blsdkg', source: 'backup' }))
.reply(200, backupKeychain);

return backupKeychain;
Expand Down
6 changes: 3 additions & 3 deletions modules/bitgo/test/v2/unit/internal/tssUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ describe('TSS Utils:', async function () {
};

nock(bgUrl)
.post(`/api/v2/${params.coin}/key`, _.matches({ type: 'tss', source: 'bitgo' }))
.post(`/api/v2/${params.coin}/key`, _.matches({ keyType: 'tss', source: 'bitgo' }))
.reply(200, bitgoKeychain);

return bitgoKeychain;
Expand All @@ -765,7 +765,7 @@ describe('TSS Utils:', async function () {
};

nock('https://bitgo.fakeurl')
.post(`/api/v2/${params.coin}/key`, _.matches({ type: 'tss', source: 'user' }))
.post(`/api/v2/${params.coin}/key`, _.matches({ keyType: 'tss', source: 'user' }))
.reply(200, userKeychain);

return userKeychain;
Expand All @@ -780,7 +780,7 @@ describe('TSS Utils:', async function () {
};

nock('https://bitgo.fakeurl')
.post(`/api/v2/${params.coin}/key`, _.matches({ type: 'tss', source: 'backup' }))
.post(`/api/v2/${params.coin}/key`, _.matches({ keyType: 'tss', source: 'backup' }))
.reply(200, backupKeychain);

return backupKeychain;
Expand Down