-
Notifications
You must be signed in to change notification settings - Fork 305
feat(sdk-core): add createOfflineKeyGenRound1Share to EddsaMPCv2Utils #9187
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
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 |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ export class EddsaMPCv2Utils extends BaseEddsaUtils { | |
| private static readonly MPS_DSG_SIGNING_USER_GPG_KEY = 'MPS_DSG_SIGNING_USER_GPG_KEY'; | ||
| private static readonly MPS_DSG_SIGNING_ROUND1_STATE = 'MPS_DSG_SIGNING_ROUND1_STATE'; | ||
| private static readonly MPS_DSG_SIGNING_ROUND2_STATE = 'MPS_DSG_SIGNING_ROUND2_STATE'; | ||
| private static readonly MPS_DKG_KEYGEN_ROUND1_STATE = 'MPS_DKG_KEYGEN_ROUND1_STATE'; | ||
|
|
||
| /** @inheritdoc */ | ||
| async createKeychains(params: { | ||
|
|
@@ -558,6 +559,56 @@ export class EddsaMPCv2Utils extends BaseEddsaUtils { | |
|
|
||
| // #region external signer | ||
|
|
||
| // #region KeyGenRound1Share | ||
| async createOfflineKeyGenRound1Share(params: { | ||
| walletPassphrase: string; | ||
| encryptedUserGpgPrvKey: string; | ||
| bitgoGpgPubKey: string; | ||
| counterPartyGpgPubKey: string; | ||
| partyId?: MPCv2PartiesEnum; | ||
|
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. you're using the full enum here which also includes you can use the narrower type |
||
| }): Promise<{ | ||
| signedMsg1: MPSTypes.MPSSignedMessage; | ||
| encryptedRound1Session: string; | ||
| }> { | ||
| const { walletPassphrase, encryptedUserGpgPrvKey, bitgoGpgPubKey, counterPartyGpgPubKey } = params; | ||
| const partyId = params.partyId ?? MPCv2PartiesEnum.USER; | ||
|
|
||
| const decryptedGpgPrvKey = isV2Envelope(encryptedUserGpgPrvKey) | ||
| ? await this.bitgo.decryptAsync({ input: encryptedUserGpgPrvKey, password: walletPassphrase }) | ||
| : this.bitgo.decrypt({ input: encryptedUserGpgPrvKey, password: walletPassphrase }); | ||
| const gpgPrvKey = await pgp.readPrivateKey({ armoredKey: decryptedGpgPrvKey }); | ||
|
|
||
| const [, ownSk] = await MPSComms.extractEd25519KeyPair(gpgPrvKey); | ||
|
|
||
| const bitgoKeyObj = await pgp.readKey({ armoredKey: bitgoGpgPubKey }); | ||
|
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. consider this check reading the armored key |
||
| const bitgoPk = await MPSComms.extractEd25519PublicKey(bitgoKeyObj); | ||
|
|
||
| const counterPartyKeyObj = await pgp.readKey({ armoredKey: counterPartyGpgPubKey }); | ||
| const counterPartyPk = await MPSComms.extractEd25519PublicKey(counterPartyKeyObj); | ||
|
|
||
| const dkg = new EddsaMPSDkg.DKG(3, 2, partyId); | ||
| await dkg.initDkg(ownSk, [counterPartyPk, bitgoPk]); | ||
|
|
||
| const msg1 = dkg.getFirstMessage(); | ||
| const signedMsg1 = await MPSComms.detachSignMpsMessage(Buffer.from(msg1.payload), gpgPrvKey); | ||
|
|
||
| const sessionPayload = JSON.stringify({ | ||
| dkgSession: dkg.getSession(), | ||
| ownMsgPayload: Buffer.from(msg1.payload).toString('base64'), | ||
| ownMsgFrom: msg1.from, | ||
| }); | ||
|
|
||
| const encryptedRound1Session = await this.bitgo.encryptAsync({ | ||
| input: sessionPayload, | ||
| password: walletPassphrase, | ||
| adata: EddsaMPCv2Utils.MPS_DKG_KEYGEN_ROUND1_STATE, | ||
|
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. bind adata: you can see below these lines (line 666 rn) that signing already binds that extra context into |
||
| encryptionVersion: 1, | ||
| }); | ||
|
|
||
| return { signedMsg1, encryptedRound1Session }; | ||
| } | ||
| // #endregion | ||
|
|
||
| // #region Round1Share | ||
| async createOfflineRound1Share(params: { | ||
| txRequest: TxRequest; | ||
|
|
||
|
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. Add USER vs BACKUP test, i.e. |
Uh oh!
There was an error while loading. Please reload this page.