-
Notifications
You must be signed in to change notification settings - Fork 302
feat(sdk-core): add webauthnInfo support to createMpc #8607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
18a642a
4eae3e5
0636e4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import { EcdsaPaillierProof, EcdsaRangeProof, EcdsaTypes, hexToBigInt, minModulu | |
| import { bip32 } from '@bitgo/utxo-lib'; | ||
|
|
||
| import { ECDSA, Ecdsa } from '../../../../account-lib/mpc/tss'; | ||
| import { AddKeychainOptions, Keychain, KeyType } from '../../../keychain'; | ||
| import { AddKeychainOptions, Keychain, KeyType, GenerateWalletWebauthnInfo } from '../../../keychain'; | ||
| import ECDSAMethods, { ECDSAMethodTypes } from '../../../tss/ecdsa'; | ||
| import { KeychainsTriplet } from '../../../baseCoin'; | ||
| import { | ||
|
|
@@ -106,6 +106,7 @@ export class EcdsaUtils extends BaseEcdsaUtils { | |
| passphrase: string; | ||
| enterprise?: string | undefined; | ||
| originalPasscodeEncryptionCode?: string | undefined; | ||
| webauthnInfo?: GenerateWalletWebauthnInfo; | ||
| }): Promise<KeychainsTriplet> { | ||
| const MPC = new Ecdsa(); | ||
| const m = 2; | ||
|
|
@@ -138,6 +139,7 @@ export class EcdsaUtils extends BaseEcdsaUtils { | |
| bitgoKeychain, | ||
| passphrase: params.passphrase, | ||
| originalPasscodeEncryptionCode: params.originalPasscodeEncryptionCode, | ||
| webauthnInfo: params.webauthnInfo, | ||
| }); | ||
| const backupKeychainPromise = this.createBackupKeychain({ | ||
| userGpgKey, | ||
|
|
@@ -177,6 +179,7 @@ export class EcdsaUtils extends BaseEcdsaUtils { | |
| bitgoKeychain, | ||
| passphrase, | ||
| originalPasscodeEncryptionCode, | ||
| webauthnInfo, | ||
| }: CreateEcdsaKeychainParams): Promise<Keychain> { | ||
| if (!passphrase) { | ||
| throw new Error('Please provide a wallet passphrase'); | ||
|
|
@@ -191,7 +194,8 @@ export class EcdsaUtils extends BaseEcdsaUtils { | |
| backupKeyShare.userHeldKeyShare, | ||
| bitgoKeychain, | ||
| passphrase, | ||
| originalPasscodeEncryptionCode | ||
| originalPasscodeEncryptionCode, | ||
| webauthnInfo | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -304,7 +308,8 @@ export class EcdsaUtils extends BaseEcdsaUtils { | |
| backupKeyShare: KeyShare, | ||
| bitgoKeychain: Keychain, | ||
| passphrase: string, | ||
| originalPasscodeEncryptionCode?: string | ||
| originalPasscodeEncryptionCode?: string, | ||
| webauthnInfo?: GenerateWalletWebauthnInfo | ||
| ): Promise<Keychain> { | ||
| const bitgoKeyShares = bitgoKeychain.keyShares; | ||
| if (!bitgoKeyShares) { | ||
|
|
@@ -399,6 +404,19 @@ export class EcdsaUtils extends BaseEcdsaUtils { | |
| password: passphrase, | ||
| }), | ||
| originalPasscodeEncryptionCode, | ||
| webauthnDevices: | ||
| webauthnInfo && recipientIndex === 1 | ||
| ? [ | ||
| { | ||
| otpDeviceId: webauthnInfo.otpDeviceId, | ||
| prfSalt: webauthnInfo.prfSalt, | ||
| encryptedPrv: this.bitgo.encrypt({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can use await this.bitgo.encryptAsync() instead of this.bitgo.encrypt() for the webauthn entry. it handles both v1/v2 based on |
||
| input: prv, | ||
| password: webauthnInfo.passphrase, | ||
| }), | ||
| }, | ||
| ] | ||
| : undefined, | ||
| }; | ||
|
|
||
| const keychains = this.baseCoin.keychains(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ import { | |
| } from '@bitgo/public-types'; | ||
|
|
||
| import { Ecdsa } from '../../../../account-lib'; | ||
| import { AddKeychainOptions, Keychain, KeyType } from '../../../keychain'; | ||
| import { AddKeychainOptions, Keychain, KeyType, GenerateWalletWebauthnInfo } from '../../../keychain'; | ||
| import { DecryptedRetrofitPayload } from '../../../keychain/iKeychains'; | ||
| import { ECDSAMethodTypes, getTxRequest } from '../../../tss'; | ||
| import { sendSignatureShareV2, sendTxRequest } from '../../../tss/common'; | ||
|
|
@@ -57,6 +57,7 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils { | |
| enterprise: string; | ||
| originalPasscodeEncryptionCode?: string; | ||
| retrofit?: DecryptedRetrofitPayload; | ||
| webauthnInfo?: GenerateWalletWebauthnInfo; | ||
| }): Promise<KeychainsTriplet> { | ||
| const { userSession, backupSession } = this.getUserAndBackupSession(2, 3, params.retrofit); | ||
| const userGpgKey = await generateGPGKeyPair('secp256k1'); | ||
|
|
@@ -318,7 +319,8 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils { | |
| userPrivateMaterial, | ||
| userReducedPrivateMaterial, | ||
| params.passphrase, | ||
| params.originalPasscodeEncryptionCode | ||
| params.originalPasscodeEncryptionCode, | ||
| params.webauthnInfo | ||
| ); | ||
| const backupKeychainPromise = this.addBackupKeychain( | ||
| bitgoCommonKeychain, | ||
|
|
@@ -350,20 +352,23 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils { | |
| privateMaterial?: Buffer, | ||
| reducedPrivateMaterial?: Buffer, | ||
| passphrase?: string, | ||
| originalPasscodeEncryptionCode?: string | ||
| originalPasscodeEncryptionCode?: string, | ||
| webauthnInfo?: GenerateWalletWebauthnInfo | ||
| ): Promise<Keychain> { | ||
| let source: string; | ||
| let encryptedPrv: string | undefined = undefined; | ||
| let reducedEncryptedPrv: string | undefined = undefined; | ||
| let privateMaterialBase64: string | undefined = undefined; | ||
| switch (participantIndex) { | ||
| case MPCv2PartiesEnum.USER: | ||
| case MPCv2PartiesEnum.BACKUP: | ||
| source = participantIndex === MPCv2PartiesEnum.USER ? 'user' : 'backup'; | ||
| assert(privateMaterial, `Private material is required for ${source} keychain`); | ||
| assert(reducedPrivateMaterial, `Reduced private material is required for ${source} keychain`); | ||
| assert(passphrase, `Passphrase is required for ${source} keychain`); | ||
| privateMaterialBase64 = privateMaterial.toString('base64'); | ||
| encryptedPrv = this.bitgo.encrypt({ | ||
| input: privateMaterial.toString('base64'), | ||
| input: privateMaterialBase64, | ||
| password: passphrase, | ||
| }); | ||
| // Encrypts the CBOR-encoded ReducedKeyShare (which contains the party's private | ||
|
|
@@ -393,6 +398,19 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils { | |
| isMPCv2: true, | ||
| }; | ||
|
|
||
| if (webauthnInfo && participantIndex === MPCv2PartiesEnum.USER && privateMaterialBase64) { | ||
| recipientKeychainParams.webauthnDevices = [ | ||
| { | ||
| otpDeviceId: webauthnInfo.otpDeviceId, | ||
| prfSalt: webauthnInfo.prfSalt, | ||
| encryptedPrv: this.bitgo.encrypt({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, can use this.bitgo.encryptAsync() |
||
| input: privateMaterialBase64, | ||
| password: webauthnInfo.passphrase, | ||
| }), | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| const keychains = this.baseCoin.keychains(); | ||
| return { ...(await keychains.add(recipientKeychainParams)), reducedEncryptedPrv: reducedEncryptedPrv }; | ||
| } | ||
|
|
@@ -512,15 +530,17 @@ export class EcdsaMPCv2Utils extends BaseEcdsaUtils { | |
| privateMaterial: Buffer, | ||
| reducedPrivateMaterial: Buffer, | ||
| passphrase: string, | ||
| originalPasscodeEncryptionCode?: string | ||
| originalPasscodeEncryptionCode?: string, | ||
| webauthnInfo?: GenerateWalletWebauthnInfo | ||
| ): Promise<Keychain> { | ||
| return this.createParticipantKeychain( | ||
| MPCv2PartiesEnum.USER, | ||
| commonKeychain, | ||
| privateMaterial, | ||
| reducedPrivateMaterial, | ||
| passphrase, | ||
| originalPasscodeEncryptionCode | ||
| originalPasscodeEncryptionCode, | ||
| webauthnInfo | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| import assert from 'assert'; | ||
| import * as openpgp from 'openpgp'; | ||
| import Eddsa, { GShare, SignShare } from '../../../../account-lib/mpc/tss'; | ||
| import { AddKeychainOptions, CreateBackupOptions, Keychain } from '../../../keychain'; | ||
| import { AddKeychainOptions, CreateBackupOptions, Keychain, GenerateWalletWebauthnInfo } from '../../../keychain'; | ||
| import { verifyWalletSignature } from '../../../tss/eddsa/eddsa'; | ||
| import { createShareProof, encryptText, generateGPGKeyPair, getBitgoGpgPubKey } from '../../opengpgUtils'; | ||
| import { | ||
|
|
@@ -128,6 +128,7 @@ export class EddsaUtils extends baseTSSUtils<KeyShare> { | |
| bitgoKeychain, | ||
| passphrase, | ||
| originalPasscodeEncryptionCode, | ||
| webauthnInfo, | ||
| }: CreateEddsaKeychainParams): Promise<Keychain> { | ||
| const MPC = await Eddsa.initialize(); | ||
| const bitgoKeyShares = bitgoKeychain.keyShares; | ||
|
|
@@ -189,6 +190,18 @@ export class EddsaUtils extends baseTSSUtils<KeyShare> { | |
| password: passphrase, | ||
| }); | ||
| } | ||
| if (webauthnInfo && userKeychainParams.encryptedPrv) { | ||
| userKeychainParams.webauthnDevices = [ | ||
| { | ||
| otpDeviceId: webauthnInfo.otpDeviceId, | ||
| prfSalt: webauthnInfo.prfSalt, | ||
| encryptedPrv: this.bitgo.encrypt({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| input: JSON.stringify(userSigningMaterial), | ||
| password: webauthnInfo.passphrase, | ||
| }), | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| return await this.baseCoin.keychains().add(userKeychainParams); | ||
| } | ||
|
|
@@ -344,6 +357,7 @@ export class EddsaUtils extends baseTSSUtils<KeyShare> { | |
| passphrase?: string; | ||
| enterprise?: string; | ||
| originalPasscodeEncryptionCode?: string; | ||
| webauthnInfo?: GenerateWalletWebauthnInfo; | ||
| }): Promise<KeychainsTriplet> { | ||
| const MPC = await Eddsa.initialize(); | ||
| const m = 2; | ||
|
|
@@ -370,6 +384,7 @@ export class EddsaUtils extends baseTSSUtils<KeyShare> { | |
| bitgoKeychain, | ||
| passphrase: params.passphrase, | ||
| originalPasscodeEncryptionCode: params.originalPasscodeEncryptionCode, | ||
| webauthnInfo: params.webauthnInfo, | ||
| }); | ||
| const backupKeychainPromise = this.createBackupKeychain({ | ||
| userGpgKey, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use MPCv2PartiesEnum.USER instead of 1