@canton-network/wallet-gateway-remote 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/jwt-auth-service.d.ts.map +1 -1
- package/dist/auth/jwt-auth-service.js +6 -5
- package/dist/auth/jwt-auth-service.test.d.ts +2 -0
- package/dist/auth/jwt-auth-service.test.d.ts.map +1 -0
- package/dist/auth/jwt-auth-service.test.js +259 -0
- package/dist/auth/jwt-unsafe-auth-service.test.d.ts +2 -0
- package/dist/auth/jwt-unsafe-auth-service.test.d.ts.map +1 -0
- package/dist/auth/jwt-unsafe-auth-service.test.js +120 -0
- package/dist/config/Config.d.ts +60 -4
- package/dist/config/Config.d.ts.map +1 -1
- package/dist/config/Config.js +1 -0
- package/dist/config/ConfigUtils.d.ts.map +1 -1
- package/dist/config/ConfigUtils.js +3 -0
- package/dist/dapp-api/controller.d.ts.map +1 -1
- package/dist/dapp-api/controller.js +54 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +3 -6
- package/dist/ledger/transaction-service.d.ts +14 -11
- package/dist/ledger/transaction-service.d.ts.map +1 -1
- package/dist/ledger/transaction-service.js +95 -8
- package/dist/ledger/transaction-service.test.d.ts +2 -0
- package/dist/ledger/transaction-service.test.d.ts.map +1 -0
- package/dist/ledger/transaction-service.test.js +356 -0
- package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.d.ts +5 -2
- package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.js +7 -6
- package/dist/ledger/wallet-allocation/wallet-allocation-service.d.ts +11 -5
- package/dist/ledger/wallet-allocation/wallet-allocation-service.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/wallet-allocation-service.js +28 -14
- package/dist/ledger/wallet-allocation/wallet-allocation-service.test.js +550 -19
- package/dist/ledger/wallet-sync-service.js +3 -3
- package/dist/middleware/apiKeyAuth.d.ts +6 -0
- package/dist/middleware/apiKeyAuth.d.ts.map +1 -0
- package/dist/middleware/apiKeyAuth.js +88 -0
- package/dist/middleware/apiKeyAuth.test.d.ts +2 -0
- package/dist/middleware/apiKeyAuth.test.d.ts.map +1 -0
- package/dist/middleware/apiKeyAuth.test.js +126 -0
- package/dist/middleware/jsonRpcHandler.d.ts +11 -1
- package/dist/middleware/jsonRpcHandler.d.ts.map +1 -1
- package/dist/middleware/jsonRpcHandler.js +14 -15
- package/dist/middleware/jsonRpcHandler.test.d.ts +2 -0
- package/dist/middleware/jsonRpcHandler.test.d.ts.map +1 -0
- package/dist/middleware/jsonRpcHandler.test.js +254 -0
- package/dist/middleware/jwtAuth.d.ts.map +1 -1
- package/dist/middleware/jwtAuth.js +4 -0
- package/dist/middleware/jwtAuth.test.d.ts +2 -0
- package/dist/middleware/jwtAuth.test.d.ts.map +1 -0
- package/dist/middleware/jwtAuth.test.js +93 -0
- package/dist/middleware/rateLimit.test.js +12 -0
- package/dist/middleware/sessionHandler.js +1 -1
- package/dist/middleware/sessionHandler.test.d.ts +2 -0
- package/dist/middleware/sessionHandler.test.d.ts.map +1 -0
- package/dist/middleware/sessionHandler.test.js +121 -0
- package/dist/notification/NotificationService.test.d.ts +2 -0
- package/dist/notification/NotificationService.test.d.ts.map +1 -0
- package/dist/notification/NotificationService.test.js +110 -0
- package/dist/signing/signing-drivers.d.ts +7 -0
- package/dist/signing/signing-drivers.d.ts.map +1 -0
- package/dist/signing/signing-drivers.js +3 -0
- package/dist/user-api/controller.d.ts +6 -4
- package/dist/user-api/controller.d.ts.map +1 -1
- package/dist/user-api/controller.js +111 -94
- package/dist/user-api/controller.test.d.ts +2 -0
- package/dist/user-api/controller.test.d.ts.map +1 -0
- package/dist/user-api/controller.test.js +862 -0
- package/dist/user-api/rpc-gen/index.d.ts +12 -0
- package/dist/user-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/user-api/rpc-gen/index.js +4 -0
- package/dist/user-api/rpc-gen/typings.d.ts +52 -3
- package/dist/user-api/rpc-gen/typings.d.ts.map +1 -1
- package/dist/utils.d.ts +17 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +53 -2
- package/dist/utils.test.d.ts +2 -0
- package/dist/utils.test.d.ts.map +1 -0
- package/dist/utils.test.js +24 -0
- package/dist/web/frontend/404/index.html +2 -2
- package/dist/web/frontend/activities/index.html +3 -3
- package/dist/web/frontend/approve/index.html +4 -4
- package/dist/web/frontend/assets/404-MVLWUPwN.js +5 -0
- package/dist/web/frontend/assets/{activities-NY8oZAkH.js → activities-DaWkmGqA.js} +2 -2
- package/dist/web/frontend/assets/{addIdentityProvider-38ghz3RT.js → addIdentityProvider--rBb0ihb.js} +2 -2
- package/dist/web/frontend/assets/{addNetwork-BaDhbrZl.js → addNetwork-C6UDsRkU.js} +4 -4
- package/dist/web/frontend/assets/addParty-B3fFD1eM.js +45 -0
- package/dist/web/frontend/assets/approve-WbGL4E82.js +21 -0
- package/dist/web/frontend/assets/callback--tihEryB.js +1 -0
- package/dist/web/frontend/assets/{identityProviders-BZ9h_VOJ.js → identityProviders-Dra4qG6t.js} +2 -2
- package/dist/web/frontend/assets/{index-B-HiKugW.js → index-Bm76pXA_.js} +2 -2
- package/dist/web/frontend/assets/index-D1dC4Cl9.js +4477 -0
- package/dist/web/frontend/assets/{login-CqwMEG9J.js → login-BC8a-kD_.js} +2 -2
- package/dist/web/frontend/assets/{networks-BJvRi47M.js → networks-B3ztsogL.js} +2 -2
- package/dist/web/frontend/assets/{reviewIdentityProvider-ySlQnw5R.js → reviewIdentityProvider-Co420Dbk.js} +3 -3
- package/dist/web/frontend/assets/{reviewNetwork-DrVxeHd4.js → reviewNetwork-B-Sh8pCH.js} +3 -3
- package/dist/web/frontend/assets/{settings-BVNkaUyJ.js → settings-DvyUjqLl.js} +1 -1
- package/dist/web/frontend/assets/{state-qAsNw5qf.js → state-Bq65GwdF.js} +1 -1
- package/dist/web/frontend/assets/{utils-BDkHxi8V.js → utils-B2iziW8V.js} +1 -1
- package/dist/web/frontend/callback/index.html +2 -2
- package/dist/web/frontend/identity-providers/add/index.html +3 -3
- package/dist/web/frontend/identity-providers/index.html +3 -3
- package/dist/web/frontend/identity-providers/review/index.html +3 -3
- package/dist/web/frontend/index.html +1 -1
- package/dist/web/frontend/login/index.html +3 -3
- package/dist/web/frontend/networks/add/index.html +3 -3
- package/dist/web/frontend/networks/index.html +3 -3
- package/dist/web/frontend/networks/review/index.html +3 -3
- package/dist/web/frontend/parties/add/index.html +5 -5
- package/dist/web/frontend/parties/index.html +4 -4
- package/dist/web/frontend/settings/index.html +3 -3
- package/package.json +36 -32
- package/dist/web/frontend/assets/404-C7V2yl2z.js +0 -5
- package/dist/web/frontend/assets/addParty-j3JWZX5a.js +0 -41
- package/dist/web/frontend/assets/approve-43nVzAAC.js +0 -21
- package/dist/web/frontend/assets/callback-BBMiCjHR.js +0 -1
- package/dist/web/frontend/assets/index-DoNqknyE.js +0 -4042
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
5
|
import { LedgerClient } from '@canton-network/core-ledger-client';
|
|
6
6
|
import buildController from './rpc-gen/index.js';
|
|
7
|
-
import { assertConnected, authSchema, AuthTokenProvider,
|
|
8
|
-
import { isRpcError, SigningProvider
|
|
7
|
+
import { assertConnected, authSchema, AuthTokenProvider, idpSchema, } from '@canton-network/core-wallet-auth';
|
|
8
|
+
import { isRpcError, SigningProvider } from '@canton-network/core-signing-lib';
|
|
9
9
|
import { PartyAllocationService } from '../ledger/party-allocation-service.js';
|
|
10
10
|
import { WalletAllocationService } from '../ledger/wallet-allocation/wallet-allocation-service.js';
|
|
11
11
|
import { WalletSyncService } from '../ledger/wallet-sync-service.js';
|
|
12
|
-
import { networkStatus } from '../utils.js';
|
|
12
|
+
import { logDynamically, networkStatus } from '../utils.js';
|
|
13
13
|
import { v4 } from 'uuid';
|
|
14
14
|
import { TransactionService } from '../ledger/transaction-service.js';
|
|
15
|
+
import { rpcErrors } from '@canton-network/core-rpc-errors';
|
|
16
|
+
import crypto from 'crypto';
|
|
15
17
|
export const userController = (kernelInfo, userUrl, store, notificationService, authContext, drivers, _logger, adminUserId) => {
|
|
16
18
|
const logger = _logger.child({ component: 'user-controller' });
|
|
17
19
|
const provider = {
|
|
@@ -26,27 +28,6 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
26
28
|
throw new Error('Unauthorized: only the admin user can perform this operation');
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
|
-
async function resolveUserEmail(connectedContext) {
|
|
30
|
-
if (connectedContext.email) {
|
|
31
|
-
return connectedContext.email;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const network = await store.getCurrentNetwork();
|
|
35
|
-
if (!network) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
const idp = await store.getIdp(network.identityProviderId);
|
|
39
|
-
if (idp.type !== 'oauth') {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
const userInfo = await fetchOidcUserInfo(idp.configUrl, connectedContext.accessToken);
|
|
43
|
-
return userInfo?.email;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
logger.warn(error, 'Failed to resolve user email from OIDC userinfo');
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
31
|
return buildController({
|
|
51
32
|
getUser: async () => {
|
|
52
33
|
const userId = assertConnected(authContext).userId;
|
|
@@ -152,14 +133,10 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
152
133
|
await store.removeIdp(params.identityProviderId);
|
|
153
134
|
return null;
|
|
154
135
|
},
|
|
155
|
-
listIdps: async () =>
|
|
136
|
+
listIdps: async () => ({ idps: await store.listIdps() }),
|
|
156
137
|
createWallet: async (params) => {
|
|
157
|
-
logger.info(`Creating wallet with params: ${JSON.stringify(params)}`);
|
|
158
138
|
const { signingProviderId, primary, partyHint } = params;
|
|
159
139
|
const connectedContext = assertConnected(authContext);
|
|
160
|
-
const userId = connectedContext.userId;
|
|
161
|
-
const email = await resolveUserEmail(connectedContext);
|
|
162
|
-
const notifier = notificationService.getNotifier(userId);
|
|
163
140
|
const network = await store.getCurrentNetwork();
|
|
164
141
|
if (network === undefined) {
|
|
165
142
|
throw new Error('No network session found');
|
|
@@ -168,6 +145,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
168
145
|
if (!network.adminAuth) {
|
|
169
146
|
throw new Error('No admin auth configured');
|
|
170
147
|
}
|
|
148
|
+
const notifier = notificationService.getNotifier(connectedContext.userId);
|
|
171
149
|
const adminTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth, logger);
|
|
172
150
|
const partyAllocator = new PartyAllocationService({
|
|
173
151
|
synchronizerId: network.synchronizerId,
|
|
@@ -179,7 +157,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
179
157
|
if (!drivers[signingProviderId]) {
|
|
180
158
|
throw new Error(`Signing provider ${signingProviderId} not supported`);
|
|
181
159
|
}
|
|
182
|
-
const wallet = await walletAllocationService.createWallet(
|
|
160
|
+
const wallet = await walletAllocationService.createWallet(connectedContext, partyHint, primary ?? false, signingProviderId, params.vaultName);
|
|
183
161
|
// Sync wallets (TODO: separate rights sync from wallet sync as we only need rights sync here)
|
|
184
162
|
const ledgerClient = new LedgerClient({
|
|
185
163
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
@@ -194,24 +172,21 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
194
172
|
return { wallet };
|
|
195
173
|
},
|
|
196
174
|
allocatePartyForWallet: async (params) => {
|
|
197
|
-
logger.info(`Allocating party for wallet: ${JSON.stringify(params)}`);
|
|
198
175
|
const connectedContext = assertConnected(authContext);
|
|
199
176
|
const userId = connectedContext.userId;
|
|
200
|
-
const email = await resolveUserEmail(connectedContext);
|
|
201
|
-
const notifier = notificationService.getNotifier(userId);
|
|
202
177
|
const network = await store.getCurrentNetwork();
|
|
203
178
|
if (!network) {
|
|
204
179
|
throw new Error('No network session found');
|
|
205
180
|
}
|
|
181
|
+
if (!network.adminAuth) {
|
|
182
|
+
throw new Error('No admin auth configured');
|
|
183
|
+
}
|
|
206
184
|
const allWallets = await store.getWallets();
|
|
207
185
|
const existingWallet = allWallets.find((w) => w.partyId === params.partyId && w.networkId === network.id);
|
|
208
186
|
if (!existingWallet) {
|
|
209
187
|
throw new Error(`Wallet not found for party ${params.partyId}`);
|
|
210
188
|
}
|
|
211
189
|
const idp = await store.getIdp(network.identityProviderId);
|
|
212
|
-
if (!network.adminAuth) {
|
|
213
|
-
throw new Error('No admin auth configured');
|
|
214
|
-
}
|
|
215
190
|
const accessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth, logger);
|
|
216
191
|
const partyAllocator = new PartyAllocationService({
|
|
217
192
|
synchronizerId: network.synchronizerId,
|
|
@@ -224,7 +199,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
224
199
|
if (!drivers[signingProviderId]) {
|
|
225
200
|
throw new Error(`Signing provider ${signingProviderId} not supported`);
|
|
226
201
|
}
|
|
227
|
-
await walletAllocationService.allocateParty(
|
|
202
|
+
await walletAllocationService.allocateParty(connectedContext, existingWallet, signingProviderId);
|
|
228
203
|
// Sync wallets (TODO: separate rights sync from wallet sync as we only need rights sync here)
|
|
229
204
|
const ledgerClient = new LedgerClient({
|
|
230
205
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
@@ -237,6 +212,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
237
212
|
const wallets = await store.getWallets();
|
|
238
213
|
const wallet = wallets.find((w) => w.partyId === existingWallet.partyId &&
|
|
239
214
|
w.networkId === network.id);
|
|
215
|
+
const notifier = notificationService.getNotifier(userId);
|
|
240
216
|
notifier?.emit('accountsChanged', wallets);
|
|
241
217
|
return { wallet };
|
|
242
218
|
},
|
|
@@ -249,7 +225,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
249
225
|
notifier?.emit('accountsChanged', wallets);
|
|
250
226
|
return null;
|
|
251
227
|
},
|
|
252
|
-
removeWallet: async (params) =>
|
|
228
|
+
removeWallet: async (params) => {
|
|
229
|
+
throw rpcErrors.methodNotSupported();
|
|
230
|
+
},
|
|
253
231
|
listWallets: async (params) => {
|
|
254
232
|
return await store.getWallets(params.filter);
|
|
255
233
|
},
|
|
@@ -265,36 +243,18 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
265
243
|
}
|
|
266
244
|
const connectedContext = assertConnected(authContext);
|
|
267
245
|
const userId = connectedContext.userId;
|
|
268
|
-
const email = await resolveUserEmail(connectedContext);
|
|
269
246
|
const notifier = notificationService.getNotifier(userId);
|
|
270
|
-
const signingProvider = wallet.signingProviderId;
|
|
271
|
-
const driver = drivers[signingProvider]?.controller(userId);
|
|
272
|
-
if (!driver) {
|
|
273
|
-
throw new Error(`No driver found for ${wallet.signingProviderId}`);
|
|
274
|
-
}
|
|
275
247
|
const transactionService = new TransactionService(store, logger, drivers, notifier);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
return transactionService.signWithBlockdaemon(email, wallet, signParams);
|
|
288
|
-
}
|
|
289
|
-
case SigningProvider.FIREBLOCKS: {
|
|
290
|
-
return transactionService.signWithFireblocks(userId, wallet, signParams);
|
|
291
|
-
}
|
|
292
|
-
case SigningProvider.DFNS: {
|
|
293
|
-
return transactionService.signWithDfns(userId, wallet, signParams);
|
|
294
|
-
}
|
|
295
|
-
default:
|
|
296
|
-
throw new Error(`Unsupported signing provider: ${wallet.signingProviderId}`);
|
|
297
|
-
}
|
|
248
|
+
logDynamically(logger, 'signing transaction with params', {
|
|
249
|
+
info: { transactionId: signParams.transactionId },
|
|
250
|
+
debug: { signParams, wallet, connectedContext },
|
|
251
|
+
});
|
|
252
|
+
const response = await transactionService.sign(connectedContext, wallet, signParams);
|
|
253
|
+
logDynamically(logger, 'transaction signed with response', {
|
|
254
|
+
info: { transactionId: signParams.transactionId },
|
|
255
|
+
debug: { response },
|
|
256
|
+
});
|
|
257
|
+
return response;
|
|
298
258
|
},
|
|
299
259
|
signMessage: async (params) => {
|
|
300
260
|
const pending = await store.getMessageRaw(params.messageId);
|
|
@@ -437,45 +397,38 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
437
397
|
const transaction = await store.getTransaction(executeParams.transactionId);
|
|
438
398
|
const wallet = wallets.find((w) => w.partyId === executeParams.partyId);
|
|
439
399
|
if (wallet === undefined) {
|
|
440
|
-
throw new Error('
|
|
400
|
+
throw new Error('Requested wallet not found for user');
|
|
441
401
|
}
|
|
442
402
|
if (transaction === undefined) {
|
|
443
403
|
throw new Error('No transaction found');
|
|
444
404
|
}
|
|
445
|
-
const
|
|
405
|
+
const connectedContext = assertConnected(authContext);
|
|
406
|
+
const accessTokenProvider = AuthTokenProvider.fromToken(connectedContext.accessToken, logger);
|
|
446
407
|
if (network === undefined) {
|
|
447
408
|
throw new Error('No network session found');
|
|
448
409
|
}
|
|
449
|
-
const notifier = notificationService.getNotifier(userId);
|
|
450
|
-
// Create AccessTokenProvider for user token
|
|
451
|
-
const userAccessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken, logger);
|
|
410
|
+
const notifier = notificationService.getNotifier(connectedContext.userId);
|
|
452
411
|
const ledgerClient = new LedgerClient({
|
|
453
412
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
454
413
|
logger,
|
|
455
|
-
accessTokenProvider
|
|
414
|
+
accessTokenProvider,
|
|
456
415
|
});
|
|
457
416
|
const transactionService = new TransactionService(store, logger, drivers, notifier);
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
case SigningProvider.DFNS: {
|
|
474
|
-
return transactionService.executeWithDfns(transaction);
|
|
475
|
-
}
|
|
476
|
-
default:
|
|
477
|
-
throw new Error(`Unsupported signing provider: ${wallet.signingProviderId}`);
|
|
478
|
-
}
|
|
417
|
+
logDynamically(logger, 'executing transaction with params', {
|
|
418
|
+
info: { transactionId: executeParams.transactionId },
|
|
419
|
+
debug: {
|
|
420
|
+
executeParams,
|
|
421
|
+
transaction,
|
|
422
|
+
wallet,
|
|
423
|
+
userId: connectedContext.userId,
|
|
424
|
+
},
|
|
425
|
+
});
|
|
426
|
+
const response = await transactionService.execute(connectedContext.userId, wallet, transaction, executeParams, ledgerClient, network);
|
|
427
|
+
logDynamically(logger, 'transaction executed with response', {
|
|
428
|
+
info: { transactionId: executeParams.transactionId },
|
|
429
|
+
debug: { response },
|
|
430
|
+
});
|
|
431
|
+
return response;
|
|
479
432
|
},
|
|
480
433
|
addSession: async function (params) {
|
|
481
434
|
try {
|
|
@@ -555,7 +508,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
555
508
|
}
|
|
556
509
|
},
|
|
557
510
|
removeSession: async () => {
|
|
558
|
-
logger.info(authContext, 'Removing session');
|
|
511
|
+
logger.info({ authContext }, 'Removing session');
|
|
559
512
|
const userId = assertConnected(authContext).userId;
|
|
560
513
|
const notifier = notificationService.getNotifier(userId);
|
|
561
514
|
await store.removeSession();
|
|
@@ -726,6 +679,70 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
726
679
|
await store.removeTransaction(transaction.id);
|
|
727
680
|
return null;
|
|
728
681
|
},
|
|
682
|
+
generateApiKey: async (params) => {
|
|
683
|
+
const userId = assertConnected(authContext).userId;
|
|
684
|
+
const network = await store.getCurrentNetwork();
|
|
685
|
+
const apiKeyId = v4();
|
|
686
|
+
const generatedApiKey = crypto.randomBytes(32).toString('hex');
|
|
687
|
+
const hashedApiKey = crypto
|
|
688
|
+
.createHash('sha256')
|
|
689
|
+
.update(generatedApiKey)
|
|
690
|
+
.digest('hex');
|
|
691
|
+
const storedApiKey = {
|
|
692
|
+
id: apiKeyId,
|
|
693
|
+
name: params.name,
|
|
694
|
+
digest: hashedApiKey,
|
|
695
|
+
userId,
|
|
696
|
+
networkId: network.id,
|
|
697
|
+
email: authContext?.email || null,
|
|
698
|
+
createdAt: new Date(),
|
|
699
|
+
};
|
|
700
|
+
await store.addApiKey(storedApiKey);
|
|
701
|
+
logDynamically(logger, 'Generated new API key', {
|
|
702
|
+
info: { apiKeyId: storedApiKey.id },
|
|
703
|
+
debug: {
|
|
704
|
+
name: storedApiKey.name,
|
|
705
|
+
userId: storedApiKey.userId,
|
|
706
|
+
networkId: storedApiKey.networkId,
|
|
707
|
+
createdAt: storedApiKey.createdAt,
|
|
708
|
+
},
|
|
709
|
+
});
|
|
710
|
+
return {
|
|
711
|
+
id: storedApiKey.id,
|
|
712
|
+
apiKey: generatedApiKey,
|
|
713
|
+
};
|
|
714
|
+
},
|
|
715
|
+
listApiKeys: async () => {
|
|
716
|
+
const apiKeys = await store.listApiKeys().then((keys) => keys.map((key) => ({
|
|
717
|
+
id: key.id,
|
|
718
|
+
name: key.name,
|
|
719
|
+
createdAt: key.createdAt.toISOString(),
|
|
720
|
+
})));
|
|
721
|
+
return { apiKeys };
|
|
722
|
+
},
|
|
723
|
+
removeApiKey: async (params) => {
|
|
724
|
+
await store.removeApiKey(params.id);
|
|
725
|
+
return null;
|
|
726
|
+
},
|
|
727
|
+
listSigningProviderVaults: async (params) => {
|
|
728
|
+
const network = await store.getCurrentNetwork();
|
|
729
|
+
const idp = await store.getIdp(network.identityProviderId);
|
|
730
|
+
if (!network.adminAuth) {
|
|
731
|
+
throw new Error('No admin auth configured');
|
|
732
|
+
}
|
|
733
|
+
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth, logger);
|
|
734
|
+
const partyAllocator = new PartyAllocationService({
|
|
735
|
+
synchronizerId: network.synchronizerId,
|
|
736
|
+
accessTokenProvider: adminAccessTokenProvider,
|
|
737
|
+
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
738
|
+
logger,
|
|
739
|
+
});
|
|
740
|
+
const walletAllocationService = new WalletAllocationService(store, logger, partyAllocator, drivers);
|
|
741
|
+
if (!drivers[params.signingProviderId]) {
|
|
742
|
+
throw new Error(`Signing provider ${params.signingProviderId} not supported`);
|
|
743
|
+
}
|
|
744
|
+
return walletAllocationService.getVaults(assertConnected(authContext), params.signingProviderId);
|
|
745
|
+
},
|
|
729
746
|
});
|
|
730
747
|
};
|
|
731
748
|
function toAuthDto(auth) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.test.d.ts","sourceRoot":"","sources":["../../src/user-api/controller.test.ts"],"names":[],"mappings":""}
|