Skip to content

Commit e445af5

Browse files
WIP: E2E wallet generation
1 parent 53e0744 commit e445af5

File tree

5 files changed

+29
-36
lines changed

5 files changed

+29
-36
lines changed

src/kms/kmsClient.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ export class KmsClient {
2525
async postKey(params: PostKeyParams): Promise<PostKeyResponse> {
2626
debugLogger('Posting key to KMS: %O', params);
2727

28-
const kmsResponse = await superagent
29-
.post(`${this.url}/key`)
30-
.set('x-api-key', 'abc')
31-
.send(params);
32-
33-
try {
34-
PostKeyKmsSchema.parse(kmsResponse.body);
35-
} catch (error: any) {
36-
throw new Error(
37-
`KMS returned unexpected response${error.message ? `: ${error.message}` : ''}`,
38-
);
39-
}
40-
41-
const { pub, coin, source } = kmsResponse.body;
28+
// const kmsResponse = await superagent
29+
// .post(`${this.url}/key`)
30+
// .set('x-api-key', 'abc')
31+
// .send(params);
32+
//
33+
// try {
34+
// PostKeyKmsSchema.parse(kmsResponse.body);
35+
// } catch (error: any) {
36+
// throw new Error(
37+
// `KMS returned unexpected response${error.message ? `: ${error.message}` : ''}`,
38+
// );
39+
// }
40+
41+
const { pub, coin, source } = params;
4242
return { pub, coin, source } as PostKeyResponse;
4343
}
4444
}

src/masterBitgoExpress/enclavedExpressClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class EnclavedExpressClient {
7070
try {
7171
debugLogger('Creating independent keychain for coin: %s', this.coin);
7272
const { body: keychain } = await superagent
73-
.post(`${this.url}/api/${this.coin}/key/independent`)
73+
.post(`${this.url}/${this.coin}/key/independentKey`)
7474
.ca(this.sslCert)
7575
.agent(
7676
new https.Agent({

src/masterBitgoExpress/generateWallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function handleGenerateWalletOnPrem({
5454
n: 3,
5555
keys: [],
5656
type: 'cold',
57-
subType: 'onprem',
57+
subType: 'onPrem',
5858
multisigType: 'onchain',
5959
} as unknown as SupplementGenerateWalletOptions; // TODO: Add onprem to the SDK subType and remove "unknown" type casting
6060

src/masterExpressApi.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,10 @@ export const GenerateWalletRequest = h.httpRoute({
105105
params: {
106106
coin: t.string,
107107
},
108-
headers: {
109-
authorization: t.union([t.string, t.undefined]),
110-
'user-agent': t.union([t.string, t.undefined]),
108+
body: {
109+
label: t.string,
110+
enterprise: t.string,
111111
},
112-
body: WalletGenerateRequest,
113112
}),
114113
response: {
115114
200: WalletGenerateResponse,

src/masterExpressApp.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import debug from 'debug';
66
import https from 'https';
77
import http from 'http';
88
import superagent from 'superagent';
9+
import bodyParser from 'body-parser';
910

1011
import {
1112
createServer as createExpressApp,
@@ -29,7 +30,6 @@ import {
2930
prepareIpc,
3031
readCertificates,
3132
} from './shared/appUtils';
32-
import bodyParser from 'body-parser';
3333
import { ProxyAgent } from 'proxy-agent';
3434
import pjson from '../package.json';
3535
import { handleGenerateWalletOnPrem } from './masterBitgoExpress/generateWallet';
@@ -197,8 +197,6 @@ const handleGenerateWallet: ServiceFunction<typeof GenerateWalletRequest> = asyn
197197
coin,
198198
enterprise,
199199
label,
200-
authorization,
201-
'user-agent': userAgent,
202200
}) => {
203201
try {
204202
const cfg = config() as MasterExpressConfig;
@@ -207,29 +205,24 @@ const handleGenerateWallet: ServiceFunction<typeof GenerateWalletRequest> = asyn
207205
const bitGo = new BitGo({
208206
env: cfg.env,
209207
customRootURI: cfg.customRootUri,
210-
accessToken: authorization?.startsWith('Bearer ') ? authorization.substring(7) : undefined,
211-
userAgent: userAgent ? BITGOEXPRESS_USER_AGENT + ' ' + userAgent : BITGOEXPRESS_USER_AGENT,
208+
// accessToken: Authorization?.startsWith('Bearer ') ? Authorization.substring(7) : undefined,
209+
accessToken: 'v2xa0f0fa5fffa0ff7529b47c969cf544f4df1b21a5508109bed488a9d2c9d74f54',
210+
// userAgent: userAgent ? BITGOEXPRESS_USER_AGENT + ' ' + userAgent : BITGOEXPRESS_USER_AGENT,
212211
});
213212

214-
// Prepare the request object for the existing handler
215-
// const bitgoReq = {
216-
// bitgo,
217-
// body: req.body,
218-
// params: req.pathParams,
219-
// config: cfg,
220-
// } as BitGoRequest;
221-
222213
// Call the existing implementation
214+
console.log('here', bitGo);
223215
const result = await handleGenerateWalletOnPrem({
224216
bitGo,
225217
params: {
226218
coin,
227-
label,
228-
enterprise,
219+
label: 'world',
220+
enterprise: '6750c2d327511bc4e5f83ccfcfe1b3eb',
229221
multisigType: 'onchain', // Default multisig type
230222
isDistributedCustody: false, // Default value
231223
},
232224
});
225+
console.log(result);
233226
return Response.ok(result);
234227
} catch (error) {
235228
debugLogger('Failed to generate wallet:', error);
@@ -258,7 +251,8 @@ export function app(cfg: MasterExpressConfig): express.Application {
258251
console.log('Certificate length:', cfg.enclavedExpressSSLCert.length);
259252
console.log('Certificate content:', cfg.enclavedExpressSSLCert);
260253

261-
const app = createExpressApp(MasterExpressApi, (_app) => {
254+
const app = createExpressApp(MasterExpressApi, (app) => {
255+
app.use(bodyParser.json({ limit: '1mb' }));
262256
return {
263257
'api.v1.health.pingMasterExpress': {
264258
post: routeHandler({

0 commit comments

Comments
 (0)