|
| 1 | +import { AppMode, AdvancedWalletManagerConfig, TlsMode } from '../../../initConfig'; |
| 2 | +import { app as expressApp } from '../../../advancedWalletManagerApp'; |
| 3 | + |
| 4 | +import express from 'express'; |
| 5 | +import nock from 'nock'; |
| 6 | +import 'should'; |
| 7 | +import * as request from 'supertest'; |
| 8 | +import { DklsTypes, DklsUtils } from '@bitgo-beta/sdk-lib-mpc'; |
| 9 | + |
| 10 | +describe('recoveryMpc', async () => { |
| 11 | + let cfg: AdvancedWalletManagerConfig; |
| 12 | + let app: express.Application; |
| 13 | + let agent: request.SuperAgentTest; |
| 14 | + |
| 15 | + // test config |
| 16 | + const kmsUrl = 'http://kms.invalid'; |
| 17 | + const eddsaCoin = 'tsol'; |
| 18 | + const nonSol = 'tnear'; |
| 19 | + const accessToken = 'test-token'; |
| 20 | + |
| 21 | + // sinon stubs |
| 22 | + // let configStub: sinon.SinonStub; |
| 23 | + |
| 24 | + // kms nocks setup |
| 25 | + const [userShare, backupShare] = await DklsUtils.generateDKGKeyShares(); |
| 26 | + const userKeyShare = userShare.getKeyShare().toString('base64'); |
| 27 | + const backupKeyShare = backupShare.getKeyShare().toString('base64'); |
| 28 | + const commonKeychain = DklsTypes.getCommonKeychain(userShare.getKeyShare()); |
| 29 | + |
| 30 | + const mockKmsUserResponse = { |
| 31 | + prv: JSON.stringify(userKeyShare), |
| 32 | + pub: commonKeychain, |
| 33 | + source: 'user', |
| 34 | + type: 'tss', |
| 35 | + }; |
| 36 | + |
| 37 | + const mockKmsBackupResponse = { |
| 38 | + prv: JSON.stringify(backupKeyShare), |
| 39 | + pub: commonKeychain, |
| 40 | + source: 'backup', |
| 41 | + type: 'tss', |
| 42 | + }; |
| 43 | + const input = { |
| 44 | + txHex: |
| 45 | + '', |
| 46 | + pub: commonKeychain, |
| 47 | + }; |
| 48 | + |
| 49 | + before(async () => { |
| 50 | + // nock config |
| 51 | + nock.disableNetConnect(); |
| 52 | + nock.enableNetConnect('127.0.0.1'); |
| 53 | + |
| 54 | + // app config |
| 55 | + cfg = { |
| 56 | + appMode: AppMode.ADVANCED_WALLET_MANAGER, |
| 57 | + port: 0, // Let OS assign a free port |
| 58 | + bind: 'localhost', |
| 59 | + timeout: 60000, |
| 60 | + kmsUrl: kmsUrl, |
| 61 | + httpLoggerFile: '', |
| 62 | + tlsMode: TlsMode.DISABLED, |
| 63 | + allowSelfSigned: true, |
| 64 | + recoveryMode: true, |
| 65 | + }; |
| 66 | + |
| 67 | + // app setup |
| 68 | + app = expressApp(cfg); |
| 69 | + agent = request.agent(app); |
| 70 | + }); |
| 71 | + |
| 72 | + afterEach(() => { |
| 73 | + nock.cleanAll(); |
| 74 | + }); |
| 75 | + |
| 76 | + // happy path test |
| 77 | + it('should be sign a MPC Recovery', async () => { |
| 78 | + // nocks for KMS responses |
| 79 | + const userKmsNock = nock(kmsUrl) |
| 80 | + .get(`/key/${input.pub}`) |
| 81 | + .query({ source: 'user', useLocalEncipherment: false }) |
| 82 | + .reply(200, mockKmsUserResponse) |
| 83 | + .persist(); |
| 84 | + const backupKmsNock = nock(kmsUrl) |
| 85 | + .get(`/key/${input.pub}`) |
| 86 | + .query({ source: 'backup', useLocalEncipherment: false }) |
| 87 | + .reply(200, mockKmsBackupResponse) |
| 88 | + .persist(); |
| 89 | + |
| 90 | + const eddsaSignatureResponse = await agent |
| 91 | + .post(`/api/${eddsaCoin}/mpc/recovery`) |
| 92 | + .set('Authorization', `Bearer ${accessToken}`) |
| 93 | + .send(input); |
| 94 | + |
| 95 | + eddsaSignatureResponse.status.should.equal(200); |
| 96 | + eddsaSignatureResponse.body.should.have.property('txHex'); |
| 97 | + eddsaSignatureResponse.body.txHex.should.equal(input.txHex); |
| 98 | + }); |
| 99 | +}); |
0 commit comments