@canton-network/wallet-gateway-remote 1.4.0 → 1.6.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 +69 -4
- package/dist/config/Config.d.ts.map +1 -1
- package/dist/config/Config.js +6 -0
- package/dist/config/ConfigUtils.d.ts.map +1 -1
- package/dist/config/ConfigUtils.js +3 -0
- package/dist/dapp-api/controller.d.ts +5 -1
- package/dist/dapp-api/controller.d.ts.map +1 -1
- package/dist/dapp-api/controller.js +104 -30
- package/dist/dapp-api/controller.test.js +2 -2
- package/dist/dapp-api/server.d.ts +3 -2
- package/dist/dapp-api/server.d.ts.map +1 -1
- package/dist/dapp-api/server.js +2 -2
- package/dist/dapp-api/server.test.js +1 -6
- package/dist/example-config.d.ts +3 -0
- package/dist/example-config.d.ts.map +1 -1
- package/dist/example-config.js +3 -0
- 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 +19 -7
- package/dist/ledger/transaction-service.d.ts +16 -11
- package/dist/ledger/transaction-service.d.ts.map +1 -1
- package/dist/ledger/transaction-service.js +135 -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 +390 -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 +90 -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/service-account-session.d.ts +16 -0
- package/dist/signing/service-account-session.d.ts.map +1 -0
- package/dist/signing/service-account-session.js +25 -0
- package/dist/signing/service-account-session.test.d.ts +2 -0
- package/dist/signing/service-account-session.test.d.ts.map +1 -0
- package/dist/signing/service-account-session.test.js +89 -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/signing/signing-worker.d.ts +83 -0
- package/dist/signing/signing-worker.d.ts.map +1 -0
- package/dist/signing/signing-worker.js +206 -0
- package/dist/signing/signing-worker.test.d.ts +2 -0
- package/dist/signing/signing-worker.test.d.ts.map +1 -0
- package/dist/signing/signing-worker.test.js +152 -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 +119 -95
- 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-C7V2yl2z.js → 404-C4hCL2o8.js} +2 -2
- package/dist/web/frontend/assets/{activities-NY8oZAkH.js → activities-Bq7yMMQY.js} +2 -2
- package/dist/web/frontend/assets/addIdentityProvider-DRJWLhHF.js +28 -0
- package/dist/web/frontend/assets/addNetwork-CJUaKP1q.js +38 -0
- package/dist/web/frontend/assets/addParty-2ObTLGIL.js +45 -0
- package/dist/web/frontend/assets/approve-BuA5DGC2.js +21 -0
- package/dist/web/frontend/assets/callback-C5vJWFLq.js +1 -0
- package/dist/web/frontend/assets/{identityProviders-BZ9h_VOJ.js → identityProviders-78FbpzYL.js} +2 -2
- package/dist/web/frontend/assets/{index-B-HiKugW.js → index-BTH_md6b.js} +3 -3
- package/dist/web/frontend/assets/index-CFnOucPK.js +4737 -0
- package/dist/web/frontend/assets/{login-CqwMEG9J.js → login-Dyn1o6fW.js} +2 -2
- package/dist/web/frontend/assets/{networks-BJvRi47M.js → networks-_el10AWP.js} +2 -2
- package/dist/web/frontend/assets/reviewIdentityProvider-DodUZ2mY.js +43 -0
- package/dist/web/frontend/assets/reviewNetwork-BFMtmKEL.js +43 -0
- package/dist/web/frontend/assets/settings-BBmkIfYm.js +37 -0
- package/dist/web/frontend/assets/{state-qAsNw5qf.js → state-DkxLvywv.js} +1 -1
- package/dist/web/frontend/assets/{utils-BDkHxi8V.js → utils-DvJKIYxT.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/addIdentityProvider-38ghz3RT.js +0 -28
- package/dist/web/frontend/assets/addNetwork-BaDhbrZl.js +0 -38
- 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
- package/dist/web/frontend/assets/reviewIdentityProvider-ySlQnw5R.js +0 -43
- package/dist/web/frontend/assets/reviewNetwork-DrVxeHd4.js +0 -43
- package/dist/web/frontend/assets/settings-BVNkaUyJ.js +0 -37
|
@@ -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;
|
|
@@ -65,6 +46,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
65
46
|
const adminAuth = network.adminAuth
|
|
66
47
|
? authSchema.parse(network.adminAuth)
|
|
67
48
|
: undefined;
|
|
49
|
+
const serviceAccountAuth = network.serviceAccountAuth
|
|
50
|
+
? authSchema.parse(network.serviceAccountAuth)
|
|
51
|
+
: undefined;
|
|
68
52
|
const newNetwork = {
|
|
69
53
|
name: network.name,
|
|
70
54
|
id: network.id,
|
|
@@ -73,6 +57,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
73
57
|
identityProviderId: network.identityProviderId,
|
|
74
58
|
auth,
|
|
75
59
|
adminAuth,
|
|
60
|
+
serviceAccountAuth,
|
|
76
61
|
ledgerApi,
|
|
77
62
|
};
|
|
78
63
|
// TODO: Add an explicit updateNetwork method to the User API spec and controller
|
|
@@ -152,14 +137,10 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
152
137
|
await store.removeIdp(params.identityProviderId);
|
|
153
138
|
return null;
|
|
154
139
|
},
|
|
155
|
-
listIdps: async () =>
|
|
140
|
+
listIdps: async () => ({ idps: await store.listIdps() }),
|
|
156
141
|
createWallet: async (params) => {
|
|
157
|
-
logger.info(`Creating wallet with params: ${JSON.stringify(params)}`);
|
|
158
142
|
const { signingProviderId, primary, partyHint } = params;
|
|
159
143
|
const connectedContext = assertConnected(authContext);
|
|
160
|
-
const userId = connectedContext.userId;
|
|
161
|
-
const email = await resolveUserEmail(connectedContext);
|
|
162
|
-
const notifier = notificationService.getNotifier(userId);
|
|
163
144
|
const network = await store.getCurrentNetwork();
|
|
164
145
|
if (network === undefined) {
|
|
165
146
|
throw new Error('No network session found');
|
|
@@ -168,6 +149,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
168
149
|
if (!network.adminAuth) {
|
|
169
150
|
throw new Error('No admin auth configured');
|
|
170
151
|
}
|
|
152
|
+
const notifier = notificationService.getNotifier(connectedContext.userId);
|
|
171
153
|
const adminTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth, logger);
|
|
172
154
|
const partyAllocator = new PartyAllocationService({
|
|
173
155
|
synchronizerId: network.synchronizerId,
|
|
@@ -179,7 +161,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
179
161
|
if (!drivers[signingProviderId]) {
|
|
180
162
|
throw new Error(`Signing provider ${signingProviderId} not supported`);
|
|
181
163
|
}
|
|
182
|
-
const wallet = await walletAllocationService.createWallet(
|
|
164
|
+
const wallet = await walletAllocationService.createWallet(connectedContext, partyHint, primary ?? false, signingProviderId, params.vaultName);
|
|
183
165
|
// Sync wallets (TODO: separate rights sync from wallet sync as we only need rights sync here)
|
|
184
166
|
const ledgerClient = new LedgerClient({
|
|
185
167
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
@@ -194,24 +176,21 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
194
176
|
return { wallet };
|
|
195
177
|
},
|
|
196
178
|
allocatePartyForWallet: async (params) => {
|
|
197
|
-
logger.info(`Allocating party for wallet: ${JSON.stringify(params)}`);
|
|
198
179
|
const connectedContext = assertConnected(authContext);
|
|
199
180
|
const userId = connectedContext.userId;
|
|
200
|
-
const email = await resolveUserEmail(connectedContext);
|
|
201
|
-
const notifier = notificationService.getNotifier(userId);
|
|
202
181
|
const network = await store.getCurrentNetwork();
|
|
203
182
|
if (!network) {
|
|
204
183
|
throw new Error('No network session found');
|
|
205
184
|
}
|
|
185
|
+
if (!network.adminAuth) {
|
|
186
|
+
throw new Error('No admin auth configured');
|
|
187
|
+
}
|
|
206
188
|
const allWallets = await store.getWallets();
|
|
207
189
|
const existingWallet = allWallets.find((w) => w.partyId === params.partyId && w.networkId === network.id);
|
|
208
190
|
if (!existingWallet) {
|
|
209
191
|
throw new Error(`Wallet not found for party ${params.partyId}`);
|
|
210
192
|
}
|
|
211
193
|
const idp = await store.getIdp(network.identityProviderId);
|
|
212
|
-
if (!network.adminAuth) {
|
|
213
|
-
throw new Error('No admin auth configured');
|
|
214
|
-
}
|
|
215
194
|
const accessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth, logger);
|
|
216
195
|
const partyAllocator = new PartyAllocationService({
|
|
217
196
|
synchronizerId: network.synchronizerId,
|
|
@@ -224,7 +203,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
224
203
|
if (!drivers[signingProviderId]) {
|
|
225
204
|
throw new Error(`Signing provider ${signingProviderId} not supported`);
|
|
226
205
|
}
|
|
227
|
-
await walletAllocationService.allocateParty(
|
|
206
|
+
await walletAllocationService.allocateParty(connectedContext, existingWallet, signingProviderId);
|
|
228
207
|
// Sync wallets (TODO: separate rights sync from wallet sync as we only need rights sync here)
|
|
229
208
|
const ledgerClient = new LedgerClient({
|
|
230
209
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
@@ -237,6 +216,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
237
216
|
const wallets = await store.getWallets();
|
|
238
217
|
const wallet = wallets.find((w) => w.partyId === existingWallet.partyId &&
|
|
239
218
|
w.networkId === network.id);
|
|
219
|
+
const notifier = notificationService.getNotifier(userId);
|
|
240
220
|
notifier?.emit('accountsChanged', wallets);
|
|
241
221
|
return { wallet };
|
|
242
222
|
},
|
|
@@ -249,7 +229,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
249
229
|
notifier?.emit('accountsChanged', wallets);
|
|
250
230
|
return null;
|
|
251
231
|
},
|
|
252
|
-
removeWallet: async (params) =>
|
|
232
|
+
removeWallet: async (params) => {
|
|
233
|
+
throw rpcErrors.methodNotSupported();
|
|
234
|
+
},
|
|
253
235
|
listWallets: async (params) => {
|
|
254
236
|
return await store.getWallets(params.filter);
|
|
255
237
|
},
|
|
@@ -265,36 +247,18 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
265
247
|
}
|
|
266
248
|
const connectedContext = assertConnected(authContext);
|
|
267
249
|
const userId = connectedContext.userId;
|
|
268
|
-
const email = await resolveUserEmail(connectedContext);
|
|
269
250
|
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
251
|
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
|
-
}
|
|
252
|
+
logDynamically(logger, 'signing transaction with params', {
|
|
253
|
+
info: { transactionId: signParams.transactionId },
|
|
254
|
+
debug: { signParams, wallet, connectedContext },
|
|
255
|
+
});
|
|
256
|
+
const response = await transactionService.sign(connectedContext, wallet, signParams);
|
|
257
|
+
logDynamically(logger, 'transaction signed with response', {
|
|
258
|
+
info: { transactionId: signParams.transactionId },
|
|
259
|
+
debug: { response },
|
|
260
|
+
});
|
|
261
|
+
return response;
|
|
298
262
|
},
|
|
299
263
|
signMessage: async (params) => {
|
|
300
264
|
const pending = await store.getMessageRaw(params.messageId);
|
|
@@ -437,56 +401,49 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
437
401
|
const transaction = await store.getTransaction(executeParams.transactionId);
|
|
438
402
|
const wallet = wallets.find((w) => w.partyId === executeParams.partyId);
|
|
439
403
|
if (wallet === undefined) {
|
|
440
|
-
throw new Error('
|
|
404
|
+
throw new Error('Requested wallet not found for user');
|
|
441
405
|
}
|
|
442
406
|
if (transaction === undefined) {
|
|
443
407
|
throw new Error('No transaction found');
|
|
444
408
|
}
|
|
445
|
-
const
|
|
409
|
+
const connectedContext = assertConnected(authContext);
|
|
410
|
+
const accessTokenProvider = AuthTokenProvider.fromToken(connectedContext.accessToken, logger);
|
|
446
411
|
if (network === undefined) {
|
|
447
412
|
throw new Error('No network session found');
|
|
448
413
|
}
|
|
449
|
-
const notifier = notificationService.getNotifier(userId);
|
|
450
|
-
// Create AccessTokenProvider for user token
|
|
451
|
-
const userAccessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken, logger);
|
|
414
|
+
const notifier = notificationService.getNotifier(connectedContext.userId);
|
|
452
415
|
const ledgerClient = new LedgerClient({
|
|
453
416
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
454
417
|
logger,
|
|
455
|
-
accessTokenProvider
|
|
418
|
+
accessTokenProvider,
|
|
456
419
|
});
|
|
457
420
|
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
|
-
}
|
|
421
|
+
logDynamically(logger, 'executing transaction with params', {
|
|
422
|
+
info: { transactionId: executeParams.transactionId },
|
|
423
|
+
debug: {
|
|
424
|
+
executeParams,
|
|
425
|
+
transaction,
|
|
426
|
+
wallet,
|
|
427
|
+
userId: connectedContext.userId,
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
const response = await transactionService.execute(connectedContext.userId, wallet, transaction, executeParams, ledgerClient, network);
|
|
431
|
+
logDynamically(logger, 'transaction executed with response', {
|
|
432
|
+
info: { transactionId: executeParams.transactionId },
|
|
433
|
+
debug: { response },
|
|
434
|
+
});
|
|
435
|
+
return response;
|
|
479
436
|
},
|
|
480
437
|
addSession: async function (params) {
|
|
481
438
|
try {
|
|
482
439
|
const newSessionId = v4();
|
|
483
440
|
logger.info(`Adding session with ID ${newSessionId} for network ${params.networkId}`);
|
|
441
|
+
const network = await store.getNetwork(params.networkId);
|
|
484
442
|
await store.setSession({
|
|
485
443
|
id: newSessionId,
|
|
486
444
|
network: params.networkId,
|
|
487
445
|
accessToken: authContext?.accessToken || '',
|
|
488
446
|
});
|
|
489
|
-
const network = await store.getCurrentNetwork();
|
|
490
447
|
const idp = await store.getIdp(network.identityProviderId);
|
|
491
448
|
// Assumption: `setSession` calls `assertConnected`, so its safe to declare that the authContext is defined.
|
|
492
449
|
const { userId, accessToken } = authContext;
|
|
@@ -555,7 +512,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
555
512
|
}
|
|
556
513
|
},
|
|
557
514
|
removeSession: async () => {
|
|
558
|
-
logger.info(authContext, 'Removing session');
|
|
515
|
+
logger.info({ authContext }, 'Removing session');
|
|
559
516
|
const userId = assertConnected(authContext).userId;
|
|
560
517
|
const notifier = notificationService.getNotifier(userId);
|
|
561
518
|
await store.removeSession();
|
|
@@ -726,6 +683,70 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
726
683
|
await store.removeTransaction(transaction.id);
|
|
727
684
|
return null;
|
|
728
685
|
},
|
|
686
|
+
generateApiKey: async (params) => {
|
|
687
|
+
const userId = assertConnected(authContext).userId;
|
|
688
|
+
const network = await store.getCurrentNetwork();
|
|
689
|
+
const apiKeyId = v4();
|
|
690
|
+
const generatedApiKey = crypto.randomBytes(32).toString('hex');
|
|
691
|
+
const hashedApiKey = crypto
|
|
692
|
+
.createHash('sha256')
|
|
693
|
+
.update(generatedApiKey)
|
|
694
|
+
.digest('hex');
|
|
695
|
+
const storedApiKey = {
|
|
696
|
+
id: apiKeyId,
|
|
697
|
+
name: params.name,
|
|
698
|
+
digest: hashedApiKey,
|
|
699
|
+
userId,
|
|
700
|
+
networkId: network.id,
|
|
701
|
+
email: authContext?.email || null,
|
|
702
|
+
createdAt: new Date(),
|
|
703
|
+
};
|
|
704
|
+
await store.addApiKey(storedApiKey);
|
|
705
|
+
logDynamically(logger, 'Generated new API key', {
|
|
706
|
+
info: { apiKeyId: storedApiKey.id },
|
|
707
|
+
debug: {
|
|
708
|
+
name: storedApiKey.name,
|
|
709
|
+
userId: storedApiKey.userId,
|
|
710
|
+
networkId: storedApiKey.networkId,
|
|
711
|
+
createdAt: storedApiKey.createdAt,
|
|
712
|
+
},
|
|
713
|
+
});
|
|
714
|
+
return {
|
|
715
|
+
id: storedApiKey.id,
|
|
716
|
+
apiKey: generatedApiKey,
|
|
717
|
+
};
|
|
718
|
+
},
|
|
719
|
+
listApiKeys: async () => {
|
|
720
|
+
const apiKeys = await store.listApiKeys().then((keys) => keys.map((key) => ({
|
|
721
|
+
id: key.id,
|
|
722
|
+
name: key.name,
|
|
723
|
+
createdAt: key.createdAt.toISOString(),
|
|
724
|
+
})));
|
|
725
|
+
return { apiKeys };
|
|
726
|
+
},
|
|
727
|
+
removeApiKey: async (params) => {
|
|
728
|
+
await store.removeApiKey(params.id);
|
|
729
|
+
return null;
|
|
730
|
+
},
|
|
731
|
+
listSigningProviderVaults: async (params) => {
|
|
732
|
+
const network = await store.getCurrentNetwork();
|
|
733
|
+
const idp = await store.getIdp(network.identityProviderId);
|
|
734
|
+
if (!network.adminAuth) {
|
|
735
|
+
throw new Error('No admin auth configured');
|
|
736
|
+
}
|
|
737
|
+
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth, logger);
|
|
738
|
+
const partyAllocator = new PartyAllocationService({
|
|
739
|
+
synchronizerId: network.synchronizerId,
|
|
740
|
+
accessTokenProvider: adminAccessTokenProvider,
|
|
741
|
+
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
742
|
+
logger,
|
|
743
|
+
});
|
|
744
|
+
const walletAllocationService = new WalletAllocationService(store, logger, partyAllocator, drivers);
|
|
745
|
+
if (!drivers[params.signingProviderId]) {
|
|
746
|
+
throw new Error(`Signing provider ${params.signingProviderId} not supported`);
|
|
747
|
+
}
|
|
748
|
+
return walletAllocationService.getVaults(assertConnected(authContext), params.signingProviderId);
|
|
749
|
+
},
|
|
729
750
|
});
|
|
730
751
|
};
|
|
731
752
|
function toAuthDto(auth) {
|
|
@@ -762,6 +783,9 @@ function toNetworkDto(network) {
|
|
|
762
783
|
...(network.adminAuth
|
|
763
784
|
? { adminAuth: toAuthDto(network.adminAuth) }
|
|
764
785
|
: {}),
|
|
786
|
+
...(network.serviceAccountAuth
|
|
787
|
+
? { serviceAccountAuth: toAuthDto(network.serviceAccountAuth) }
|
|
788
|
+
: {}),
|
|
765
789
|
};
|
|
766
790
|
}
|
|
767
791
|
function toPublicNetwork(network) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.test.d.ts","sourceRoot":"","sources":["../../src/user-api/controller.test.ts"],"names":[],"mappings":""}
|