|
7 | 7 | Wallet, |
8 | 8 | IRequestTracer, |
9 | 9 | EddsaUtils, |
| 10 | + CustomRShareGeneratingFunction, |
| 11 | + CustomGShareGeneratingFunction, |
| 12 | + CustomCommitmentGeneratingFunction, |
10 | 13 | } from '@bitgo/sdk-core'; |
11 | 14 | import { EnclavedExpressClient } from '../clients/enclavedExpressClient'; |
12 | 15 | import { exchangeEddsaCommitments } from '@bitgo/sdk-core/dist/src/bitgo/tss/common'; |
@@ -82,3 +85,70 @@ export async function handleEddsaSigning( |
82 | 85 | logger.debug('Successfully completed signing!'); |
83 | 86 | return await getTxRequest(bitgo, wallet.id(), txRequestId, reqId); |
84 | 87 | } |
| 88 | + |
| 89 | +// Commitment |
| 90 | +export function createCustomCommitmentGenerator( |
| 91 | + bitgo: BitGoBase, |
| 92 | + wallet: Wallet, |
| 93 | + enclavedExpressClient: EnclavedExpressClient, |
| 94 | + source: 'user' | 'backup', |
| 95 | + pub: string, |
| 96 | +): CustomCommitmentGeneratingFunction { |
| 97 | + return async function customCommitmentGeneratingFunction(params) { |
| 98 | + const eddsaUtils = new EddsaUtils(bitgo, wallet.baseCoin); |
| 99 | + const bitgoGpgKey = await eddsaUtils.getBitgoPublicGpgKey(); |
| 100 | + const { txRequest } = params; |
| 101 | + const response = await enclavedExpressClient.signMpcCommitment({ |
| 102 | + txRequest, |
| 103 | + bitgoGpgPubKey: bitgoGpgKey.armor(), |
| 104 | + source, |
| 105 | + pub, |
| 106 | + }); |
| 107 | + return { |
| 108 | + ...response, |
| 109 | + encryptedUserToBitgoRShare: { |
| 110 | + ...response.encryptedUserToBitgoRShare, |
| 111 | + encryptedDataKey: response.encryptedDataKey, |
| 112 | + }, |
| 113 | + }; |
| 114 | + }; |
| 115 | +} |
| 116 | + |
| 117 | +// RShare |
| 118 | +export function createCustomRShareGenerator( |
| 119 | + enclavedExpressClient: EnclavedExpressClient, |
| 120 | + source: 'user' | 'backup', |
| 121 | + pub: string, |
| 122 | +): CustomRShareGeneratingFunction { |
| 123 | + return async function customRShareGeneratingFunction(params) { |
| 124 | + const { txRequest, encryptedUserToBitgoRShare } = params; |
| 125 | + const encryptedDataKey = (encryptedUserToBitgoRShare as any).encryptedDataKey; |
| 126 | + return await enclavedExpressClient.signMpcRShare({ |
| 127 | + txRequest, |
| 128 | + encryptedUserToBitgoRShare, |
| 129 | + encryptedDataKey, |
| 130 | + source, |
| 131 | + pub, |
| 132 | + }); |
| 133 | + }; |
| 134 | +} |
| 135 | + |
| 136 | +// GShare |
| 137 | +export function createCustomGShareGenerator( |
| 138 | + enclavedExpressClient: EnclavedExpressClient, |
| 139 | + source: 'user' | 'backup', |
| 140 | + pub: string, |
| 141 | +): CustomGShareGeneratingFunction { |
| 142 | + return async function customGShareGeneratingFunction(params) { |
| 143 | + const { txRequest, bitgoToUserRShare, userToBitgoRShare, bitgoToUserCommitment } = params; |
| 144 | + const response = await enclavedExpressClient.signMpcGShare({ |
| 145 | + txRequest, |
| 146 | + bitgoToUserRShare, |
| 147 | + userToBitgoRShare, |
| 148 | + bitgoToUserCommitment, |
| 149 | + source, |
| 150 | + pub, |
| 151 | + }); |
| 152 | + return response.gShare; |
| 153 | + }; |
| 154 | +} |
0 commit comments