-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk-core): add MPCv2 wallet creation
- Loading branch information
Showing
14 changed files
with
1,256 additions
and
80 deletions.
There are no files selected for viewing
428 changes: 428 additions & 0 deletions
428
modules/bitgo/test/v2/unit/internal/tssUtils/ecdsaMPCv2.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import * as openpgp from 'openpgp'; | ||
import { ec } from 'elliptic'; | ||
|
||
import { IBaseCoin } from '../../../baseCoin'; | ||
import baseTSSUtils from '../baseTSSUtils'; | ||
import { KeyShare } from './types'; | ||
import { BackupGpgKey } from '../baseTypes'; | ||
import { generateGPGKeyPair, getBitgoGpgPubKey, getTrustGpgPubKey } from '../../opengpgUtils'; | ||
import { BitGoBase } from '../../../bitgoBase'; | ||
import { IWallet } from '../../../wallet'; | ||
|
||
/** @inheritdoc */ | ||
export class BaseEcdsaUtils extends baseTSSUtils<KeyShare> { | ||
// We do not have full support for 3-party verification (w/ external source) of key shares and signature shares. There is no 3rd party key service support with this release. | ||
protected bitgoPublicGpgKey: openpgp.Key; | ||
|
||
constructor(bitgo: BitGoBase, baseCoin: IBaseCoin, wallet?: IWallet) { | ||
super(bitgo, baseCoin, wallet); | ||
this.setBitgoGpgPubKey(bitgo); | ||
} | ||
|
||
private async setBitgoGpgPubKey(bitgo) { | ||
this.bitgoPublicGpgKey = await getBitgoGpgPubKey(bitgo); | ||
} | ||
|
||
async getBitgoPublicGpgKey(): Promise<openpgp.Key> { | ||
if (!this.bitgoPublicGpgKey) { | ||
// retry getting bitgo's gpg key | ||
await this.setBitgoGpgPubKey(this.bitgo); | ||
if (!this.bitgoPublicGpgKey) { | ||
throw new Error("Failed to get Bitgo's gpg key"); | ||
} | ||
} | ||
|
||
return this.bitgoPublicGpgKey; | ||
} | ||
|
||
/** | ||
* Gets backup pub gpg key string | ||
* if a third party provided then get from trust | ||
* @param isThirdPartyBackup | ||
*/ | ||
async getBackupGpgPubKey(isThirdPartyBackup = false): Promise<BackupGpgKey> { | ||
return isThirdPartyBackup ? getTrustGpgPubKey(this.bitgo) : generateGPGKeyPair('secp256k1'); | ||
} | ||
|
||
/** | ||
* util function that checks that a commonKeychain is valid and can ultimately resolve to a valid public key | ||
* @param commonKeychain - a user uploaded commonKeychain string | ||
* @throws if the commonKeychain is invalid length or invalid format | ||
*/ | ||
|
||
static validateCommonKeychainPublicKey(commonKeychain: string) { | ||
const pub = BaseEcdsaUtils.getPublicKeyFromCommonKeychain(commonKeychain); | ||
const secp256k1 = new ec('secp256k1'); | ||
const key = secp256k1.keyFromPublic(pub, 'hex'); | ||
return key.getPublic().encode('hex', false).slice(2); | ||
} | ||
|
||
/** | ||
* Gets the common public key from commonKeychain. | ||
* | ||
* @param {String} commonKeychain common key chain between n parties | ||
* @returns {string} encoded public key | ||
*/ | ||
static getPublicKeyFromCommonKeychain(commonKeychain: string): string { | ||
if (commonKeychain.length !== 130) { | ||
throw new Error(`Invalid commonKeychain length, expected 130, got ${commonKeychain.length}`); | ||
} | ||
const commonPubHexStr = commonKeychain.slice(0, 66); | ||
return commonPubHexStr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.