|
2 | 2 | * @prettier |
3 | 3 | */ |
4 | 4 | import { |
5 | | - EddsaUtils, |
6 | | - EcdsaUtils, |
7 | | - EcdsaMPCv2Utils, |
8 | | - CustomGShareGeneratingFunction, |
9 | | - CustomRShareGeneratingFunction, |
10 | | - UnsupportedCoinError, |
11 | | - GShare, |
12 | | - SignShare, |
13 | | - CustomCommitmentGeneratingFunction, |
14 | 5 | CommitmentShareRecord, |
15 | | - EncryptedSignerShareRecord, |
16 | | - CustomPaillierModulusGetterFunction, |
| 6 | + CreateNetworkConnectionParams, |
| 7 | + CustomCommitmentGeneratingFunction, |
| 8 | + CustomGShareGeneratingFunction, |
17 | 9 | CustomKShareGeneratingFunction, |
| 10 | + CustomMPCv2SigningRound1GeneratingFunction, |
| 11 | + CustomMPCv2SigningRound2GeneratingFunction, |
| 12 | + CustomMPCv2SigningRound3GeneratingFunction, |
18 | 13 | CustomMuDeltaShareGeneratingFunction, |
| 14 | + CustomPaillierModulusGetterFunction, |
| 15 | + CustomRShareGeneratingFunction, |
19 | 16 | CustomSShareGeneratingFunction, |
| 17 | + EcdsaMPCv2Utils, |
| 18 | + EcdsaUtils, |
| 19 | + EddsaUtils, |
| 20 | + EncryptedSignerShareRecord, |
| 21 | + encryptRsaWithAesGcm, |
| 22 | + GetNetworkPartnersResponse, |
| 23 | + GShare, |
| 24 | + MPCType, |
| 25 | + ShareType, |
| 26 | + SignShare, |
| 27 | + SShare, |
20 | 28 | TssEcdsaStep1ReturnMessage, |
21 | 29 | TssEcdsaStep2ReturnMessage, |
22 | | - SShare, |
23 | | - ShareType, |
24 | | - MPCType, |
25 | | - CreateNetworkConnectionParams, |
26 | | - GetNetworkPartnersResponse, |
27 | | - encryptRsaWithAesGcm, |
| 30 | + UnsupportedCoinError, |
28 | 31 | Wallet, |
29 | | - CustomMPCv2SigningRound1GeneratingFunction, |
30 | | - CustomMPCv2SigningRound2GeneratingFunction, |
31 | | - CustomMPCv2SigningRound3GeneratingFunction, |
32 | 32 | } from '@bitgo/sdk-core'; |
33 | 33 | import { BitGo, BitGoOptions, Coin, CustomSigningFunction, SignedTransaction, SignedTransactionRequest } from 'bitgo'; |
34 | 34 | import * as bodyParser from 'body-parser'; |
@@ -965,7 +965,7 @@ async function handleV2SendMany(req: express.Request) { |
965 | 965 | } |
966 | 966 |
|
967 | 967 | /** |
968 | | - * Routes payload meant for prebuildAndSignTransaction() in sdk-core which |
| 968 | + * payload meant for prebuildAndSignTransaction() in sdk-core which |
969 | 969 | * validates the payload and makes the appropriate request to WP to |
970 | 970 | * build, sign, and send a tx. |
971 | 971 | * - sends request to Platform to build the transaction |
@@ -1025,6 +1025,43 @@ async function handleWalletUpdate(req: express.Request): Promise<unknown> { |
1025 | 1025 | return await bitgo.put(wallet.url()).send(req.body).result(); |
1026 | 1026 | } |
1027 | 1027 |
|
| 1028 | +/** |
| 1029 | + * Changes a keychain's passphrase, re-encrypting the key to a new password |
| 1030 | + * @param req |
| 1031 | + */ |
| 1032 | +export async function handleKeychainChangePassword(req: express.Request): Promise<unknown> { |
| 1033 | + const { oldPassword, newPassword, otp } = req.body; |
| 1034 | + if (!oldPassword || !newPassword) { |
| 1035 | + throw new ApiResponseError('Missing 1 or more required fields: [oldPassword, newPassword]', 400); |
| 1036 | + } |
| 1037 | + const reqId = new RequestTracer(); |
| 1038 | + |
| 1039 | + const bitgo = req.bitgo; |
| 1040 | + const coin = bitgo.coin(req.params.coin); |
| 1041 | + |
| 1042 | + if (otp) { |
| 1043 | + await bitgo.unlock({ otp }); |
| 1044 | + } |
| 1045 | + |
| 1046 | + const keychain = await coin.keychains().get({ |
| 1047 | + id: req.params.id, |
| 1048 | + reqId, |
| 1049 | + }); |
| 1050 | + if (!keychain) { |
| 1051 | + throw new ApiResponseError(`Keychain ${req.params.id} not found`, 404); |
| 1052 | + } |
| 1053 | + |
| 1054 | + const updatedKeychain = coin.keychains().updateSingleKeychainPassword({ |
| 1055 | + keychain, |
| 1056 | + oldPassword, |
| 1057 | + newPassword, |
| 1058 | + }); |
| 1059 | + |
| 1060 | + return bitgo.put(coin.url(`/key/${updatedKeychain.id}`)).send({ |
| 1061 | + encryptedPrv: updatedKeychain.encryptedPrv, |
| 1062 | + }); |
| 1063 | +} |
| 1064 | + |
1028 | 1065 | /** |
1029 | 1066 | * handle any other API call |
1030 | 1067 | * @param req |
@@ -1577,6 +1614,14 @@ export function setupAPIRoutes(app: express.Application, config: Config): void { |
1577 | 1614 |
|
1578 | 1615 | app.put('/express/api/v2/:coin/wallet/:id', parseBody, prepareBitGo(config), promiseWrapper(handleWalletUpdate)); |
1579 | 1616 |
|
| 1617 | + // change wallet passphrase |
| 1618 | + app.post( |
| 1619 | + '/api/v2/:coin/keychain/:id/changepassword', |
| 1620 | + parseBody, |
| 1621 | + prepareBitGo(config), |
| 1622 | + promiseWrapper(handleKeychainChangePassword) |
| 1623 | + ); |
| 1624 | + |
1580 | 1625 | // create address |
1581 | 1626 | app.post('/api/v2/:coin/wallet/:id/address', parseBody, prepareBitGo(config), promiseWrapper(handleV2CreateAddress)); |
1582 | 1627 |
|
|
0 commit comments