@canton-network/wallet-gateway-remote 1.12.0 → 1.14.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/README.md +107 -31
- package/dist/auth/jwt-auth-service.d.ts.map +1 -1
- package/dist/auth/jwt-auth-service.js +164 -77
- package/dist/config/Config.d.ts +407 -24
- package/dist/config/Config.d.ts.map +1 -1
- package/dist/config/Config.js +146 -11
- package/dist/config/ConfigUtils.d.ts +16 -1
- package/dist/config/ConfigUtils.d.ts.map +1 -1
- package/dist/config/ConfigUtils.js +150 -60
- package/dist/dapp-api/controller.d.ts +13 -1
- package/dist/dapp-api/controller.d.ts.map +1 -1
- package/dist/dapp-api/controller.js +16 -20
- package/dist/dapp-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/dapp-api/rpc-gen/typings.d.ts +33 -3
- package/dist/dapp-api/rpc-gen/typings.d.ts.map +1 -1
- package/dist/dapp-api/server.d.ts +10 -5
- package/dist/dapp-api/server.d.ts.map +1 -1
- package/dist/dapp-api/server.js +10 -3
- package/dist/dapp-api/sse-sink.d.ts.map +1 -1
- package/dist/env.d.ts +1 -24
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +0 -23
- package/dist/example-config.d.ts +94 -62
- package/dist/example-config.d.ts.map +1 -1
- package/dist/example-config.js +95 -61
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -32
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +86 -127
- package/dist/ledger/party-allocation-service.d.ts +1 -4
- package/dist/ledger/party-allocation-service.d.ts.map +1 -1
- package/dist/ledger/party-allocation-service.js +1 -3
- package/dist/ledger/wallet-allocation/signing-providers/bitgo-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/bitgo-wallet-allocator.js +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/blockdaemon-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/dfns-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/kernel-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/participant-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/securosys-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/wallet-allocation-service.d.ts +2 -2
- package/dist/ledger/wallet-allocation/wallet-allocation-service.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/wallet-allocation-service.js +2 -2
- package/dist/ledger/wallet-sync-service.d.ts +14 -1
- package/dist/ledger/wallet-sync-service.d.ts.map +1 -1
- package/dist/ledger/wallet-sync-service.js +240 -72
- package/dist/middleware/apiKeyAuth.d.ts.map +1 -1
- package/dist/middleware/apiKeyAuth.js +4 -8
- package/dist/middleware/errorHandler.d.ts +1 -1
- package/dist/middleware/errorHandler.d.ts.map +1 -1
- package/dist/middleware/jsonRpcHandler.d.ts.map +1 -1
- package/dist/middleware/jsonRpcHandler.js +3 -3
- package/dist/middleware/jwtAuth.d.ts +1 -1
- package/dist/middleware/jwtAuth.d.ts.map +1 -1
- package/dist/middleware/jwtAuth.js +17 -2
- package/dist/middleware/rateLimit.d.ts.map +1 -1
- package/dist/middleware/rateLimit.js +3 -9
- package/dist/middleware/securityHeaders.d.ts.map +1 -1
- package/dist/middleware/sessionHandler.d.ts +3 -3
- package/dist/middleware/sessionHandler.d.ts.map +1 -1
- package/dist/middleware/sessionHandler.js +8 -8
- package/dist/notices/server-notices.d.ts +24 -0
- package/dist/notices/server-notices.d.ts.map +1 -0
- package/dist/notices/server-notices.js +40 -0
- package/dist/notices/server-status-service.d.ts +11 -0
- package/dist/notices/server-status-service.d.ts.map +1 -0
- package/dist/notices/server-status-service.js +17 -0
- package/dist/signing/service-account-session.d.ts +16 -2
- package/dist/signing/service-account-session.d.ts.map +1 -1
- package/dist/signing/service-account-session.js +32 -1
- package/dist/signing-providers-registration.d.ts +7 -0
- package/dist/signing-providers-registration.d.ts.map +1 -0
- package/dist/signing-providers-registration.js +276 -0
- package/dist/user-api/controller.d.ts +25 -4
- package/dist/user-api/controller.d.ts.map +1 -1
- package/dist/user-api/controller.js +218 -235
- package/dist/user-api/rpc-gen/index.d.ts +27 -9
- package/dist/user-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/user-api/rpc-gen/index.js +9 -3
- package/dist/user-api/rpc-gen/schemas.d.ts.map +1 -1
- package/dist/user-api/rpc-gen/schemas.js +86 -11
- package/dist/user-api/rpc-gen/typings.d.ts +158 -58
- package/dist/user-api/rpc-gen/typings.d.ts.map +1 -1
- package/dist/user-api/server.d.ts +7 -5
- package/dist/user-api/server.d.ts.map +1 -1
- package/dist/user-api/server.js +7 -2
- package/dist/web/frontend/404/index.html +3 -2
- package/dist/web/frontend/activities/index.html +4 -3
- package/dist/web/frontend/admin/index.html +16 -0
- package/dist/web/frontend/api-keys/add/index.html +3 -2
- package/dist/web/frontend/api-keys/index.html +3 -2
- package/dist/web/frontend/approve/index.html +4 -3
- package/dist/web/frontend/assets/404-N2p-H94F.js +5 -0
- package/dist/web/frontend/assets/activities-CIyMcvMq.js +71 -0
- package/dist/web/frontend/assets/addApiKey-DD_HxolC.js +92 -0
- package/dist/web/frontend/assets/addIdentityProvider-DNaST3bz.js +28 -0
- package/dist/web/frontend/assets/addNetwork-BwV-qK9L.js +38 -0
- package/dist/web/frontend/assets/addParty-DtBW1rpV.js +14 -0
- package/dist/web/frontend/assets/admin-CKAkdJym.js +53 -0
- package/dist/web/frontend/assets/apiKeys-CcnbBkNH.js +68 -0
- package/dist/web/frontend/assets/approve-33mo5eC8.js +27 -0
- package/dist/web/frontend/assets/callback-lKGXXz-1.js +7 -0
- package/dist/web/frontend/assets/common-DaUa4tUM.js +15 -0
- package/dist/web/frontend/assets/dist-BW5ACUmw.js +2 -0
- package/dist/web/frontend/assets/dist-CVv1nHd6.js +1 -0
- package/dist/web/frontend/assets/editParty-ZifjLzYx.js +15 -0
- package/dist/web/frontend/assets/frontend-Bs6UVmG1.js +4968 -0
- package/dist/web/frontend/assets/identityProviders-D5s7N-Ec.js +76 -0
- package/dist/web/frontend/assets/login-BAJsIB9G.js +11 -0
- package/dist/web/frontend/assets/networks-Do-zoG5E.js +78 -0
- package/dist/web/frontend/assets/parties-DFcN190b.js +51 -0
- package/dist/web/frontend/assets/reviewIdentityProvider-C2tsrpKc.js +43 -0
- package/dist/web/frontend/assets/reviewNetwork-BEGzls61.js +43 -0
- package/dist/web/frontend/assets/rolldown-runtime-pP25SEvz.js +1 -0
- package/dist/web/frontend/assets/selfIssuedLogin-a2KenO2P.js +112 -0
- package/dist/web/frontend/assets/signMessage-CQF0sCMe.js +23 -0
- package/dist/web/frontend/callback/index.html +3 -2
- package/dist/web/frontend/identity-providers/add/index.html +3 -2
- package/dist/web/frontend/identity-providers/index.html +3 -2
- package/dist/web/frontend/identity-providers/review/index.html +3 -2
- package/dist/web/frontend/index.html +2 -1
- package/dist/web/frontend/login/index.html +4 -11
- package/dist/web/frontend/networks/add/index.html +3 -2
- package/dist/web/frontend/networks/index.html +3 -2
- package/dist/web/frontend/networks/review/index.html +3 -2
- package/dist/web/frontend/parties/add/index.html +5 -5
- package/dist/web/frontend/parties/edit/index.html +5 -5
- package/dist/web/frontend/parties/index.html +4 -3
- package/dist/web/frontend/self-issued-login/index.html +16 -0
- package/dist/web/frontend/sign-message/index.html +3 -2
- package/dist/web/route-inputs.d.ts.map +1 -1
- package/dist/web/route-inputs.js +2 -1
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +1 -1
- package/package.json +53 -51
- package/dist/auth/jwt-auth-service.test.d.ts +0 -2
- package/dist/auth/jwt-auth-service.test.d.ts.map +0 -1
- package/dist/auth/jwt-auth-service.test.js +0 -659
- package/dist/config/Config.test.d.ts +0 -2
- package/dist/config/Config.test.d.ts.map +0 -1
- package/dist/config/Config.test.js +0 -26
- package/dist/dapp-api/controller.test.d.ts +0 -2
- package/dist/dapp-api/controller.test.d.ts.map +0 -1
- package/dist/dapp-api/controller.test.js +0 -531
- package/dist/dapp-api/server.test.d.ts +0 -2
- package/dist/dapp-api/server.test.d.ts.map +0 -1
- package/dist/dapp-api/server.test.js +0 -79
- package/dist/dapp-api/sse-sink.test.d.ts +0 -2
- package/dist/dapp-api/sse-sink.test.d.ts.map +0 -1
- package/dist/dapp-api/sse-sink.test.js +0 -30
- package/dist/ledger/party-allocation-service.test.d.ts +0 -2
- package/dist/ledger/party-allocation-service.test.d.ts.map +0 -1
- package/dist/ledger/party-allocation-service.test.js +0 -105
- package/dist/ledger/self-issued-auth-service.d.ts +0 -50
- package/dist/ledger/self-issued-auth-service.d.ts.map +0 -1
- package/dist/ledger/self-issued-auth-service.js +0 -263
- package/dist/ledger/self-issued-auth-service.test.d.ts +0 -2
- package/dist/ledger/self-issued-auth-service.test.d.ts.map +0 -1
- package/dist/ledger/self-issued-auth-service.test.js +0 -454
- package/dist/ledger/wallet-allocation/wallet-allocation-service.test.d.ts +0 -2
- package/dist/ledger/wallet-allocation/wallet-allocation-service.test.d.ts.map +0 -1
- package/dist/ledger/wallet-allocation/wallet-allocation-service.test.js +0 -1005
- package/dist/ledger/wallet-sync-service.test.d.ts +0 -2
- package/dist/ledger/wallet-sync-service.test.d.ts.map +0 -1
- package/dist/ledger/wallet-sync-service.test.js +0 -1017
- package/dist/middleware/apiKeyAuth.test.d.ts +0 -2
- package/dist/middleware/apiKeyAuth.test.d.ts.map +0 -1
- package/dist/middleware/apiKeyAuth.test.js +0 -126
- package/dist/middleware/errorHandler.test.d.ts +0 -2
- package/dist/middleware/errorHandler.test.d.ts.map +0 -1
- package/dist/middleware/errorHandler.test.js +0 -138
- package/dist/middleware/jsonRpcHandler.test.d.ts +0 -2
- package/dist/middleware/jsonRpcHandler.test.d.ts.map +0 -1
- package/dist/middleware/jsonRpcHandler.test.js +0 -377
- package/dist/middleware/jwtAuth.test.d.ts +0 -2
- package/dist/middleware/jwtAuth.test.d.ts.map +0 -1
- package/dist/middleware/jwtAuth.test.js +0 -100
- package/dist/middleware/rateLimit.test.d.ts +0 -2
- package/dist/middleware/rateLimit.test.d.ts.map +0 -1
- package/dist/middleware/rateLimit.test.js +0 -56
- package/dist/middleware/securityHeaders.test.d.ts +0 -2
- package/dist/middleware/securityHeaders.test.d.ts.map +0 -1
- package/dist/middleware/securityHeaders.test.js +0 -18
- package/dist/middleware/sessionHandler.test.d.ts +0 -2
- package/dist/middleware/sessionHandler.test.d.ts.map +0 -1
- package/dist/middleware/sessionHandler.test.js +0 -215
- package/dist/signing/service-account-session.test.d.ts +0 -2
- package/dist/signing/service-account-session.test.d.ts.map +0 -1
- package/dist/signing/service-account-session.test.js +0 -88
- package/dist/signing/signing-worker.d.ts +0 -86
- package/dist/signing/signing-worker.d.ts.map +0 -1
- package/dist/signing/signing-worker.js +0 -216
- package/dist/signing/signing-worker.test.d.ts +0 -2
- package/dist/signing/signing-worker.test.d.ts.map +0 -1
- package/dist/signing/signing-worker.test.js +0 -158
- package/dist/user-api/controller.test.d.ts +0 -2
- package/dist/user-api/controller.test.d.ts.map +0 -1
- package/dist/user-api/controller.test.js +0 -1228
- package/dist/user-api/server.test.d.ts +0 -2
- package/dist/user-api/server.test.d.ts.map +0 -1
- package/dist/user-api/server.test.js +0 -117
- package/dist/user-api/token-network-matching.test.d.ts +0 -2
- package/dist/user-api/token-network-matching.test.d.ts.map +0 -1
- package/dist/user-api/token-network-matching.test.js +0 -66
- package/dist/utils.test.d.ts +0 -2
- package/dist/utils.test.d.ts.map +0 -1
- package/dist/utils.test.js +0 -24
- package/dist/web/frontend/assets/404-B1XXXMXN.js +0 -5
- package/dist/web/frontend/assets/activities-HZnPjlMp.js +0 -61
- package/dist/web/frontend/assets/addApiKey-BvkCtUF3.js +0 -92
- package/dist/web/frontend/assets/addIdentityProvider-Dvjma837.js +0 -28
- package/dist/web/frontend/assets/addNetwork-Cahac0uo.js +0 -38
- package/dist/web/frontend/assets/addParty-Cdoed_Yx.js +0 -13
- package/dist/web/frontend/assets/apiKeys-BwV6ylWL.js +0 -68
- package/dist/web/frontend/assets/approve-B0nIfe2y.js +0 -26
- package/dist/web/frontend/assets/callback-BieW5Ux2.js +0 -7
- package/dist/web/frontend/assets/common-Bv9twGrA.js +0 -31
- package/dist/web/frontend/assets/editParty-OOjTHFay.js +0 -14
- package/dist/web/frontend/assets/identityProviders-BxJAq1Ne.js +0 -71
- package/dist/web/frontend/assets/index-Bo6MnlYI.js +0 -2
- package/dist/web/frontend/assets/index-CG_aFABR.js +0 -1
- package/dist/web/frontend/assets/index-D1Brmwbg.js +0 -93
- package/dist/web/frontend/assets/index-pMOoiNFq.js +0 -4887
- package/dist/web/frontend/assets/login-BHxgJEz_.js +0 -11
- package/dist/web/frontend/assets/networks-CBprjUF5.js +0 -73
- package/dist/web/frontend/assets/onboarding-ChmWs-TC.js +0 -84
- package/dist/web/frontend/assets/reviewIdentityProvider-CCmKgN8N.js +0 -43
- package/dist/web/frontend/assets/reviewNetwork-CX8Bmuf3.js +0 -43
- package/dist/web/frontend/assets/signMessage-BN_6S5FV.js +0 -79
- package/dist/web/frontend/onboarding/index.html +0 -23
- package/dist/web/route-inputs.test.d.ts +0 -2
- package/dist/web/route-inputs.test.d.ts.map +0 -1
- package/dist/web/route-inputs.test.js +0 -30
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// Disabled unused vars rule to allow for future implementations
|
|
4
|
-
/*
|
|
4
|
+
/* oxlint-disable no-unused-vars */
|
|
5
5
|
import { LedgerClient } from '@canton-network/core-ledger-client';
|
|
6
6
|
import buildController from './rpc-gen/index.js';
|
|
7
7
|
import { assertConnected, authSchema, AuthTokenProvider, idpSchema, resolveAuthIdentityProviderId, assertIsConnected, } from '@canton-network/core-wallet-auth';
|
|
8
|
-
import { isRpcError, SigningProvider } from '@canton-network/core-signing-lib';
|
|
9
8
|
import { PartyAllocationService } from '../ledger/party-allocation-service.js';
|
|
10
9
|
import { WalletAllocationService } from '../ledger/wallet-allocation/wallet-allocation-service.js';
|
|
11
10
|
import { WalletSyncService } from '../ledger/wallet-sync-service.js';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { providerErrors, rpcErrors } from '@canton-network/core-rpc-errors';
|
|
15
|
-
import crypto from 'crypto';
|
|
11
|
+
import { errorCodes, providerErrors, rpcErrors, } from '@canton-network/core-rpc-errors';
|
|
12
|
+
import { randomBytes, createHash, timingSafeEqual } from 'crypto';
|
|
16
13
|
import { assertTokenClaimsMatchNetwork } from './token-network-matching.js';
|
|
17
|
-
import { TransactionService, logDynamically, networkStatus, } from '@canton-network/core-wallet-services';
|
|
18
|
-
export const userController = (kernelInfo, userUrl, store, notificationService, authContext, drivers, _logger, hashingSchemeVersion, adminUserId) => {
|
|
14
|
+
import { assertLoginAllowed, SelfIssuedAuthService, SignMessageService, TransactionService, logDynamically, networkStatus, toSelfIssuedLoginAuthContext, } from '@canton-network/core-wallet-services';
|
|
15
|
+
export const userController = ({ kernelInfo, userUrl, store, notificationService, authContext, drivers, logger: _logger, hashingSchemeVersion, adminUserId, serverStatus, configManaged, }) => {
|
|
19
16
|
const logger = _logger.child({ component: 'user-controller' });
|
|
20
17
|
const provider = {
|
|
21
18
|
id: kernelInfo.id,
|
|
@@ -27,21 +24,97 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
27
24
|
const userId = authContext?.userId;
|
|
28
25
|
return !!adminUserId && !!userId && userId === adminUserId;
|
|
29
26
|
}
|
|
27
|
+
function assertNotConfigManaged(kind, id) {
|
|
28
|
+
const ids = kind === 'Network' ? configManaged.networkIds : configManaged.idpIds;
|
|
29
|
+
if (ids.has(id)) {
|
|
30
|
+
throw new Error(`${kind} ${id} is managed by the config file and cannot be changed at runtime`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
30
33
|
function assertAdmin() {
|
|
31
34
|
assertIsConnected(authContext);
|
|
32
35
|
if (!adminUserId || authContext.userId !== adminUserId) {
|
|
33
36
|
throw new Error('Unauthorized: only the admin user can perform this operation');
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
|
-
function
|
|
39
|
+
function requireSelfIssuedLoginSession() {
|
|
37
40
|
if (!authContext || authContext.isApiKey || !authContext.sessionId) {
|
|
38
|
-
throw new Error('No
|
|
41
|
+
throw new Error('No self-issued login session found');
|
|
39
42
|
}
|
|
40
43
|
return {
|
|
41
44
|
userId: authContext.userId,
|
|
42
45
|
sessionId: authContext.sessionId,
|
|
43
46
|
};
|
|
44
47
|
}
|
|
48
|
+
async function selfIssuedAuthService(session = requireSelfIssuedLoginSession()) {
|
|
49
|
+
const selfIssuedAuthContext = toSelfIssuedLoginAuthContext(session);
|
|
50
|
+
const scopedStore = authAwareStore.withAuthContext(selfIssuedAuthContext);
|
|
51
|
+
const network = await scopedStore.getCurrentNetwork();
|
|
52
|
+
if (network.auth.method !== 'self_issued') {
|
|
53
|
+
throw new Error('Network does not use self_issued authentication');
|
|
54
|
+
}
|
|
55
|
+
const idp = await authAwareStore.getIdp(network.identityProviderId);
|
|
56
|
+
if (idp.type !== 'self_issued') {
|
|
57
|
+
throw new Error('Identity provider is not configured for self_issued authentication');
|
|
58
|
+
}
|
|
59
|
+
if (!network.adminAuth) {
|
|
60
|
+
throw new Error('No admin auth configured');
|
|
61
|
+
}
|
|
62
|
+
const adminIdp = await authAwareStore.getIdp(resolveAuthIdentityProviderId(network.adminAuth, network.identityProviderId));
|
|
63
|
+
const adminTokenProvider = AuthTokenProvider.fromGatewayConfig(adminIdp, network.adminAuth);
|
|
64
|
+
const partyAllocator = new PartyAllocationService({
|
|
65
|
+
synchronizerId: network.synchronizerId,
|
|
66
|
+
accessTokenProvider: adminTokenProvider,
|
|
67
|
+
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
68
|
+
});
|
|
69
|
+
const walletAllocator = new WalletAllocationService(scopedStore, logger, partyAllocator, drivers);
|
|
70
|
+
const ledgerClient = new LedgerClient({
|
|
71
|
+
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
72
|
+
accessTokenProvider: adminTokenProvider,
|
|
73
|
+
});
|
|
74
|
+
const walletSynchronizer = new WalletSyncService(scopedStore, ledgerClient, selfIssuedAuthContext, logger, drivers, partyAllocator);
|
|
75
|
+
return new SelfIssuedAuthService(session, scopedStore, logger, walletAllocator, ledgerClient, walletSynchronizer, new SignMessageService(scopedStore, drivers, notificationService.getNotifier(session.sessionId)));
|
|
76
|
+
}
|
|
77
|
+
async function connectIfAccessTokenSigned(service, selfIssuedLoginSession, signature) {
|
|
78
|
+
if (signature.status === 'awaiting-signature') {
|
|
79
|
+
return {
|
|
80
|
+
status: 'awaiting-signature',
|
|
81
|
+
messageId: signature.messageId,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (signature.status === 'failed') {
|
|
85
|
+
return {
|
|
86
|
+
status: 'failed',
|
|
87
|
+
messageId: signature.messageId,
|
|
88
|
+
failureReason: signature.failureReason,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const connection = await service.connectWithSignedAccessToken(signature.messageId);
|
|
92
|
+
if (connection.status === 'failed') {
|
|
93
|
+
return {
|
|
94
|
+
status: 'failed',
|
|
95
|
+
messageId: signature.messageId,
|
|
96
|
+
failureReason: connection.failureReason,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const { wallet, accessToken, session } = connection;
|
|
100
|
+
const connectedContext = {
|
|
101
|
+
userId: selfIssuedLoginSession.userId,
|
|
102
|
+
accessToken,
|
|
103
|
+
};
|
|
104
|
+
const scopedStore = authAwareStore.withAuthContext(connectedContext);
|
|
105
|
+
const network = await scopedStore.getCurrentNetwork();
|
|
106
|
+
const ledgerClient = new LedgerClient({
|
|
107
|
+
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
108
|
+
accessTokenProvider: AuthTokenProvider.fromToken(accessToken),
|
|
109
|
+
});
|
|
110
|
+
await emitSessionConnected(session.id, network, connectedContext, ledgerClient);
|
|
111
|
+
return {
|
|
112
|
+
status: 'connected',
|
|
113
|
+
wallet,
|
|
114
|
+
accessToken,
|
|
115
|
+
sessionId: session.id,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
45
118
|
async function emitSessionConnected(sessionId, network, { userId, accessToken }, ledgerClient) {
|
|
46
119
|
const status = await networkStatus(ledgerClient);
|
|
47
120
|
const statusEvent = {
|
|
@@ -73,9 +146,11 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
73
146
|
/**
|
|
74
147
|
* Session responses always include user auth for the UI.
|
|
75
148
|
* Privileged credentials are included only for the admin user.
|
|
149
|
+
* Client secrets are never included, a self_signed secret lets the
|
|
150
|
+
* caller sign tokens for any user.
|
|
76
151
|
*/
|
|
77
152
|
function toSessionNetwork(network) {
|
|
78
|
-
const dto = toNetworkDto(network);
|
|
153
|
+
const dto = toNetworkDto(network, true);
|
|
79
154
|
if (isAdmin()) {
|
|
80
155
|
return dto;
|
|
81
156
|
}
|
|
@@ -83,18 +158,25 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
83
158
|
return rest;
|
|
84
159
|
}
|
|
85
160
|
const authAwareStore = store;
|
|
161
|
+
const signMessageService = async () => {
|
|
162
|
+
assertIsConnected(authContext);
|
|
163
|
+
const session = await store.getSession(authContext.accessToken);
|
|
164
|
+
if (!session) {
|
|
165
|
+
throw new Error('No active session found');
|
|
166
|
+
}
|
|
167
|
+
return new SignMessageService(store, drivers, notificationService.getNotifier(session.id));
|
|
168
|
+
};
|
|
86
169
|
const getSigningProviderKeys = async (params) => {
|
|
87
170
|
const network = await store.getCurrentNetwork();
|
|
88
171
|
if (!network.adminAuth) {
|
|
89
172
|
throw new Error('No admin auth configured');
|
|
90
173
|
}
|
|
91
174
|
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
92
|
-
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth
|
|
175
|
+
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
93
176
|
const partyAllocator = new PartyAllocationService({
|
|
94
177
|
synchronizerId: network.synchronizerId,
|
|
95
178
|
accessTokenProvider: adminAccessTokenProvider,
|
|
96
179
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
97
|
-
logger,
|
|
98
180
|
});
|
|
99
181
|
const walletAllocationService = new WalletAllocationService(store, logger, partyAllocator, drivers);
|
|
100
182
|
if (!drivers[params.signingProviderId])
|
|
@@ -112,9 +194,14 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
112
194
|
isAdmin: isAdmin(),
|
|
113
195
|
};
|
|
114
196
|
},
|
|
197
|
+
getServerStatus: async () => {
|
|
198
|
+
assertAdmin();
|
|
199
|
+
return serverStatus.getStatus();
|
|
200
|
+
},
|
|
115
201
|
addNetwork: async (params) => {
|
|
116
202
|
assertAdmin();
|
|
117
203
|
const { network } = params;
|
|
204
|
+
assertNotConfigManaged('Network', network.id);
|
|
118
205
|
const ledgerApi = {
|
|
119
206
|
baseUrl: network.ledgerApi ?? '',
|
|
120
207
|
};
|
|
@@ -168,6 +255,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
168
255
|
},
|
|
169
256
|
removeNetwork: async (params) => {
|
|
170
257
|
assertAdmin();
|
|
258
|
+
assertNotConfigManaged('Network', params.networkName);
|
|
171
259
|
await store.removeNetwork(params.networkName);
|
|
172
260
|
return null;
|
|
173
261
|
},
|
|
@@ -175,12 +263,17 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
175
263
|
const networks = await store.listNetworks();
|
|
176
264
|
return {
|
|
177
265
|
networks: networks.map(toPublicNetwork),
|
|
266
|
+
...(isAdmin() && {
|
|
267
|
+
configManagedIds: [...configManaged.networkIds],
|
|
268
|
+
}),
|
|
178
269
|
};
|
|
179
270
|
},
|
|
180
271
|
getNetwork: async (params) => {
|
|
181
272
|
assertAdmin();
|
|
182
273
|
const network = await store.getNetwork(params.networkId);
|
|
183
|
-
return {
|
|
274
|
+
return {
|
|
275
|
+
network: toNetworkDto(network, configManaged.networkIds.has(network.id)),
|
|
276
|
+
};
|
|
184
277
|
},
|
|
185
278
|
selfSignedAccessToken: async (params) => {
|
|
186
279
|
const network = (await store.listNetworks()).find((n) => n.id === params.networkId);
|
|
@@ -191,13 +284,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
191
284
|
if (auth.method !== 'self_signed') {
|
|
192
285
|
throw new Error('Network does not use self_signed authentication');
|
|
193
286
|
}
|
|
194
|
-
const clientSecretMatch =
|
|
195
|
-
.createHash('sha256')
|
|
287
|
+
const clientSecretMatch = timingSafeEqual(createHash('sha256')
|
|
196
288
|
.update(params.clientSecret, 'utf8')
|
|
197
|
-
.digest(),
|
|
198
|
-
.createHash('sha256')
|
|
199
|
-
.update(auth.clientSecret, 'utf8')
|
|
200
|
-
.digest());
|
|
289
|
+
.digest(), createHash('sha256').update(auth.clientSecret, 'utf8').digest());
|
|
201
290
|
if (!clientSecretMatch) {
|
|
202
291
|
throw providerErrors.unauthorized({
|
|
203
292
|
message: 'Invalid client secret',
|
|
@@ -220,12 +309,13 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
220
309
|
scope: auth.scope,
|
|
221
310
|
audience: auth.audience,
|
|
222
311
|
},
|
|
223
|
-
}
|
|
312
|
+
}).getAccessToken();
|
|
224
313
|
return { accessToken };
|
|
225
314
|
},
|
|
226
315
|
addIdp: async (params) => {
|
|
227
316
|
assertAdmin();
|
|
228
317
|
const validatedIdp = idpSchema.parse(params.idp);
|
|
318
|
+
assertNotConfigManaged('Identity provider', validatedIdp.id);
|
|
229
319
|
// TODO: Add an explicit updateIdp method to the User API spec and controller
|
|
230
320
|
const existingIdps = await store.listIdps();
|
|
231
321
|
if (existingIdps.find((n) => n.id === validatedIdp.id)) {
|
|
@@ -240,11 +330,15 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
240
330
|
},
|
|
241
331
|
removeIdp: async (params) => {
|
|
242
332
|
assertAdmin();
|
|
333
|
+
assertNotConfigManaged('Identity provider', params.identityProviderId);
|
|
243
334
|
logger.info(`Removing IDP ${params.identityProviderId}`);
|
|
244
335
|
await store.removeIdp(params.identityProviderId);
|
|
245
336
|
return null;
|
|
246
337
|
},
|
|
247
|
-
listIdps: async () => ({
|
|
338
|
+
listIdps: async () => ({
|
|
339
|
+
idps: await store.listIdps(),
|
|
340
|
+
...(isAdmin() && { configManagedIds: [...configManaged.idpIds] }),
|
|
341
|
+
}),
|
|
248
342
|
createWallet: async (params) => {
|
|
249
343
|
const { signingProviderId, primary, partyHint } = params;
|
|
250
344
|
assertIsConnected(authContext);
|
|
@@ -256,12 +350,11 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
256
350
|
throw new Error('No admin auth configured');
|
|
257
351
|
}
|
|
258
352
|
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
259
|
-
const adminTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth
|
|
353
|
+
const adminTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
260
354
|
const partyAllocator = new PartyAllocationService({
|
|
261
355
|
synchronizerId: network.synchronizerId,
|
|
262
356
|
accessTokenProvider: adminTokenProvider,
|
|
263
357
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
264
|
-
logger,
|
|
265
358
|
});
|
|
266
359
|
const walletAllocationService = new WalletAllocationService(store, logger, partyAllocator, drivers);
|
|
267
360
|
if (!drivers[signingProviderId]) {
|
|
@@ -270,8 +363,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
270
363
|
const wallet = await walletAllocationService.createWallet(authContext, partyHint, primary ?? false, signingProviderId, params.keyName);
|
|
271
364
|
const ledgerClient = new LedgerClient({
|
|
272
365
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
273
|
-
|
|
274
|
-
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken, logger),
|
|
366
|
+
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken),
|
|
275
367
|
});
|
|
276
368
|
const service = new WalletSyncService(store, ledgerClient, authContext, logger);
|
|
277
369
|
await service.syncRights();
|
|
@@ -283,7 +375,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
283
375
|
const walletWithUpdatedRights = wallets.find((w) => w.partyId === wallet.partyId && w.networkId === network.id);
|
|
284
376
|
return { wallet: walletWithUpdatedRights ?? wallet };
|
|
285
377
|
},
|
|
286
|
-
|
|
378
|
+
startSelfIssuedLoginSession: async (params) => {
|
|
287
379
|
const username = params.username.trim();
|
|
288
380
|
if (!username) {
|
|
289
381
|
throw new Error('username is required');
|
|
@@ -296,8 +388,8 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
296
388
|
userId: username,
|
|
297
389
|
accessToken: '',
|
|
298
390
|
});
|
|
299
|
-
await
|
|
300
|
-
const sessionId =
|
|
391
|
+
await assertLoginAllowed(authAwareStore, network, username);
|
|
392
|
+
const sessionId = crypto.randomUUID();
|
|
301
393
|
await onboardingStore.setSession({
|
|
302
394
|
id: sessionId,
|
|
303
395
|
origin: params.origin,
|
|
@@ -305,48 +397,58 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
305
397
|
});
|
|
306
398
|
return { sessionId };
|
|
307
399
|
},
|
|
308
|
-
|
|
309
|
-
const service = await
|
|
310
|
-
return service.
|
|
400
|
+
getSelfIssuedLoginMode: async (_params) => {
|
|
401
|
+
const service = await selfIssuedAuthService();
|
|
402
|
+
return service.getLoginMode();
|
|
311
403
|
},
|
|
312
404
|
createSelfIssuedWallet: async (params) => {
|
|
313
405
|
const { signingProviderId } = params;
|
|
314
406
|
if (!drivers[signingProviderId]) {
|
|
315
407
|
throw new Error(`Signing provider ${signingProviderId} not supported`);
|
|
316
408
|
}
|
|
317
|
-
const service = await
|
|
409
|
+
const service = await selfIssuedAuthService();
|
|
318
410
|
const wallet = await service.createWallet({
|
|
319
411
|
partyHint: params.partyHint,
|
|
320
412
|
signingProviderId: signingProviderId,
|
|
413
|
+
keyName: params.keyName,
|
|
321
414
|
});
|
|
322
415
|
return { wallet };
|
|
323
416
|
},
|
|
417
|
+
listSelfIssuedSigningProviderKeys: async (params) => {
|
|
418
|
+
const { signingProviderId } = params;
|
|
419
|
+
if (!drivers[signingProviderId]) {
|
|
420
|
+
throw new Error(`Signing provider ${signingProviderId} not supported`);
|
|
421
|
+
}
|
|
422
|
+
const service = await selfIssuedAuthService();
|
|
423
|
+
return service.listSigningProviderKeys(signingProviderId);
|
|
424
|
+
},
|
|
324
425
|
allocateSelfIssuedWallet: async (params) => {
|
|
325
|
-
const service = await
|
|
326
|
-
const allocated = await service.allocateParty(
|
|
327
|
-
partyId: params.partyId,
|
|
328
|
-
});
|
|
426
|
+
const service = await selfIssuedAuthService();
|
|
427
|
+
const allocated = await service.allocateParty(params.partyId);
|
|
329
428
|
return { wallet: allocated };
|
|
330
429
|
},
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
const service = await
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
430
|
+
signSelfIssuedAccessToken: async (params) => {
|
|
431
|
+
const selfIssuedLoginSession = requireSelfIssuedLoginSession();
|
|
432
|
+
const service = await selfIssuedAuthService(selfIssuedLoginSession);
|
|
433
|
+
const signature = await service.signAccessToken(params.partyId);
|
|
434
|
+
return connectIfAccessTokenSigned(service, selfIssuedLoginSession, signature);
|
|
435
|
+
},
|
|
436
|
+
getSignSelfIssuedAccessTokenStatus: async (params) => {
|
|
437
|
+
const selfIssuedLoginSession = requireSelfIssuedLoginSession();
|
|
438
|
+
const service = await selfIssuedAuthService(selfIssuedLoginSession);
|
|
439
|
+
const signature = await service.getAccessTokenSignatureStatus(params.messageId);
|
|
440
|
+
return connectIfAccessTokenSigned(service, selfIssuedLoginSession, signature);
|
|
441
|
+
},
|
|
442
|
+
removeSelfIssuedLoginSession: async (_params) => {
|
|
443
|
+
const session = requireSelfIssuedLoginSession();
|
|
444
|
+
await authAwareStore
|
|
445
|
+
.withAuthContext({
|
|
446
|
+
userId: session.userId,
|
|
447
|
+
accessToken: '',
|
|
448
|
+
sessionId: session.sessionId,
|
|
449
|
+
})
|
|
450
|
+
.removeSelfIssuedLoginSession(session.sessionId);
|
|
451
|
+
return null;
|
|
350
452
|
},
|
|
351
453
|
allocatePartyForWallet: async (params) => {
|
|
352
454
|
assertIsConnected(authContext);
|
|
@@ -363,12 +465,11 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
363
465
|
throw new Error(`Wallet not found for party ${params.partyId}`);
|
|
364
466
|
}
|
|
365
467
|
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
366
|
-
const accessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth
|
|
468
|
+
const accessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
367
469
|
const partyAllocator = new PartyAllocationService({
|
|
368
470
|
synchronizerId: network.synchronizerId,
|
|
369
471
|
accessTokenProvider,
|
|
370
472
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
371
|
-
logger,
|
|
372
473
|
});
|
|
373
474
|
const walletAllocationService = new WalletAllocationService(store, logger, partyAllocator, drivers);
|
|
374
475
|
const signingProviderId = existingWallet.signingProviderId;
|
|
@@ -378,8 +479,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
378
479
|
await walletAllocationService.allocateParty(authContext, existingWallet, signingProviderId);
|
|
379
480
|
const ledgerClient = new LedgerClient({
|
|
380
481
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
381
|
-
|
|
382
|
-
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken, logger),
|
|
482
|
+
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken),
|
|
383
483
|
});
|
|
384
484
|
const service = new WalletSyncService(store, ledgerClient, authContext, logger);
|
|
385
485
|
await service.syncRights();
|
|
@@ -422,7 +522,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
422
522
|
throw new Error('No active session found');
|
|
423
523
|
}
|
|
424
524
|
const notifier = notificationService.getNotifier(session.id);
|
|
425
|
-
const transactionService = new TransactionService(store,
|
|
525
|
+
const transactionService = new TransactionService(store, drivers, notifier, hashingSchemeVersion);
|
|
426
526
|
logDynamically(logger, 'signing transaction with params', {
|
|
427
527
|
info: { transactionId: signParams.transactionId },
|
|
428
528
|
debug: { signParams, wallet, authContext },
|
|
@@ -435,153 +535,24 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
435
535
|
return response;
|
|
436
536
|
},
|
|
437
537
|
signMessage: async (params) => {
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
assertIsConnected(authContext);
|
|
446
|
-
const userId = authContext.userId;
|
|
447
|
-
if (pending.userId !== userId) {
|
|
448
|
-
throw new Error(`Message signing request ${pending.id} is not owned by user ${userId}`);
|
|
449
|
-
}
|
|
450
|
-
const session = await store.getSession(authContext.accessToken);
|
|
451
|
-
if (!session) {
|
|
452
|
-
throw new Error('No active session found');
|
|
453
|
-
}
|
|
454
|
-
const notifier = notificationService.getNotifier(session.id);
|
|
455
|
-
const emitFailedAndPersist = async (details) => {
|
|
456
|
-
// Best-effort: make sure listeners see a terminal state.
|
|
457
|
-
try {
|
|
458
|
-
await store.setMessageRawStatus(pending.id, 'failed');
|
|
459
|
-
}
|
|
460
|
-
catch {
|
|
461
|
-
// ignore (e.g. record removed concurrently)
|
|
462
|
-
}
|
|
463
|
-
notifier.emit('messageSignature', {
|
|
464
|
-
status: 'failed',
|
|
465
|
-
messageId: pending.id,
|
|
466
|
-
});
|
|
467
|
-
// Preserve the original error message for the caller/UI.
|
|
468
|
-
throw new Error(details);
|
|
469
|
-
};
|
|
470
|
-
const wallet = (await store.getWallets()).find((w) => w.partyId === pending.partyId);
|
|
471
|
-
if (!wallet) {
|
|
472
|
-
return await emitFailedAndPersist(`No wallet found for partyId ${pending.partyId} (from message request ${pending.id})`);
|
|
473
|
-
}
|
|
474
|
-
if (wallet.publicKey !== pending.publicKey) {
|
|
475
|
-
return await emitFailedAndPersist(`Wallet public key changed for partyId ${pending.partyId}; refusing to sign message request ${pending.id}`);
|
|
476
|
-
}
|
|
477
|
-
// TODO: support other signing providers
|
|
478
|
-
if (wallet.signingProviderId !== SigningProvider.WALLET_KERNEL) {
|
|
479
|
-
return await emitFailedAndPersist(`signMessage is only supported for ${SigningProvider.WALLET_KERNEL} wallets, got ${wallet.signingProviderId}`);
|
|
480
|
-
}
|
|
481
|
-
const driver = drivers[SigningProvider.WALLET_KERNEL]?.controller(userId);
|
|
482
|
-
if (!driver) {
|
|
483
|
-
return await emitFailedAndPersist('Wallet Kernel signing driver not available');
|
|
484
|
-
}
|
|
485
|
-
const result = await driver.signMessage({
|
|
486
|
-
message: pending.message,
|
|
487
|
-
keyIdentifier: { publicKey: wallet.publicKey },
|
|
488
|
-
});
|
|
489
|
-
if (isRpcError(result)) {
|
|
490
|
-
await store.setMessageRawStatus(pending.id, 'failed');
|
|
491
|
-
notifier.emit('messageSignature', {
|
|
492
|
-
status: 'failed',
|
|
493
|
-
messageId: pending.id,
|
|
494
|
-
});
|
|
495
|
-
throw new Error(result.error_description);
|
|
496
|
-
}
|
|
497
|
-
if (!result?.signature) {
|
|
498
|
-
await store.setMessageRawStatus(pending.id, 'failed');
|
|
499
|
-
notifier.emit('messageSignature', {
|
|
500
|
-
status: 'failed',
|
|
501
|
-
messageId: pending.id,
|
|
502
|
-
});
|
|
503
|
-
throw new Error(`signMessage failed`);
|
|
504
|
-
}
|
|
505
|
-
await store.setMessageRawStatus(pending.id, 'signed', {
|
|
506
|
-
signedAt: new Date(),
|
|
507
|
-
signature: result.signature,
|
|
508
|
-
});
|
|
509
|
-
notifier.emit('messageSignature', {
|
|
510
|
-
status: 'signed',
|
|
511
|
-
messageId: pending.id,
|
|
512
|
-
signature: result.signature,
|
|
513
|
-
});
|
|
514
|
-
return {
|
|
515
|
-
signature: result.signature,
|
|
516
|
-
publicKey: wallet.publicKey,
|
|
517
|
-
};
|
|
538
|
+
const service = await signMessageService();
|
|
539
|
+
return service.sign(assertConnected(authContext), params.messageId, 'regular');
|
|
540
|
+
},
|
|
541
|
+
getSignMessageStatus: async (params) => {
|
|
542
|
+
const service = await signMessageService();
|
|
543
|
+
return service.refreshMessage(assertConnected(authContext), params.messageId, 'regular');
|
|
518
544
|
},
|
|
519
545
|
getMessageToSign: async (params) => {
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
throw new Error(`Message signing request not found with id: ${params.messageId}`);
|
|
523
|
-
}
|
|
524
|
-
return {
|
|
525
|
-
message: {
|
|
526
|
-
id: message.id,
|
|
527
|
-
status: message.status,
|
|
528
|
-
partyId: message.partyId,
|
|
529
|
-
publicKey: message.publicKey,
|
|
530
|
-
message: message.message,
|
|
531
|
-
...(message.origin !== null && { origin: message.origin }),
|
|
532
|
-
...(message.createdAt && {
|
|
533
|
-
createdAt: message.createdAt.toISOString(),
|
|
534
|
-
}),
|
|
535
|
-
...(message.signedAt && {
|
|
536
|
-
signedAt: message.signedAt.toISOString(),
|
|
537
|
-
}),
|
|
538
|
-
...(message.signature && { signature: message.signature }),
|
|
539
|
-
},
|
|
540
|
-
};
|
|
546
|
+
const service = await signMessageService();
|
|
547
|
+
return service.getMessage(params.messageId, 'regular');
|
|
541
548
|
},
|
|
542
549
|
listMessagesToSign: async () => {
|
|
543
|
-
const
|
|
544
|
-
return
|
|
545
|
-
messages: messages.map((message) => ({
|
|
546
|
-
id: message.id,
|
|
547
|
-
status: message.status,
|
|
548
|
-
partyId: message.partyId,
|
|
549
|
-
publicKey: message.publicKey,
|
|
550
|
-
message: message.message,
|
|
551
|
-
...(message.origin !== null && { origin: message.origin }),
|
|
552
|
-
...(message.createdAt && {
|
|
553
|
-
createdAt: message.createdAt.toISOString(),
|
|
554
|
-
}),
|
|
555
|
-
...(message.signedAt && {
|
|
556
|
-
signedAt: message.signedAt.toISOString(),
|
|
557
|
-
}),
|
|
558
|
-
...(message.signature && { signature: message.signature }),
|
|
559
|
-
})),
|
|
560
|
-
};
|
|
550
|
+
const service = await signMessageService();
|
|
551
|
+
return service.listMessages('regular');
|
|
561
552
|
},
|
|
562
553
|
deleteMessageToSign: async (params) => {
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
throw new Error(`Message signing request not found with id: ${params.messageId}`);
|
|
566
|
-
}
|
|
567
|
-
if (message.status !== 'pending') {
|
|
568
|
-
throw new Error(`Cannot delete message with status '${message.status}'. Only pending messages can be deleted.`);
|
|
569
|
-
}
|
|
570
|
-
assertIsConnected(authContext);
|
|
571
|
-
const userId = authContext.userId;
|
|
572
|
-
if (message.userId !== userId) {
|
|
573
|
-
throw new Error(`Message signing request ${message.id} is not owned by user ${userId}`);
|
|
574
|
-
}
|
|
575
|
-
await store.removeMessageRaw(message.id);
|
|
576
|
-
const session = await store.getSession(authContext.accessToken);
|
|
577
|
-
if (session) {
|
|
578
|
-
notificationService
|
|
579
|
-
.getNotifier(session.id)
|
|
580
|
-
.emit('messageSignature', {
|
|
581
|
-
status: 'failed',
|
|
582
|
-
messageId: message.id,
|
|
583
|
-
});
|
|
584
|
-
}
|
|
554
|
+
const service = await signMessageService();
|
|
555
|
+
await service.deleteMessage(assertConnected(authContext), params.messageId, 'regular');
|
|
585
556
|
return null;
|
|
586
557
|
},
|
|
587
558
|
execute: async (executeParams) => {
|
|
@@ -596,7 +567,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
596
567
|
throw new Error('No transaction found');
|
|
597
568
|
}
|
|
598
569
|
assertIsConnected(authContext);
|
|
599
|
-
const accessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken
|
|
570
|
+
const accessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken);
|
|
600
571
|
if (network === undefined) {
|
|
601
572
|
throw new Error('No network session found');
|
|
602
573
|
}
|
|
@@ -607,10 +578,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
607
578
|
const notifier = notificationService.getNotifier(session.id);
|
|
608
579
|
const ledgerClient = new LedgerClient({
|
|
609
580
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
610
|
-
logger,
|
|
611
581
|
accessTokenProvider,
|
|
612
582
|
});
|
|
613
|
-
const transactionService = new TransactionService(store,
|
|
583
|
+
const transactionService = new TransactionService(store, drivers, notifier, hashingSchemeVersion);
|
|
614
584
|
logDynamically(logger, 'executing transaction with params', {
|
|
615
585
|
info: { transactionId: executeParams.transactionId },
|
|
616
586
|
debug: {
|
|
@@ -631,7 +601,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
631
601
|
try {
|
|
632
602
|
assertIsConnected(authContext);
|
|
633
603
|
const { accessToken } = authContext;
|
|
634
|
-
const newSessionId =
|
|
604
|
+
const newSessionId = crypto.randomUUID();
|
|
635
605
|
logger.info(`Adding session with ID ${newSessionId} for network ${params.networkId}`);
|
|
636
606
|
const network = await store.getNetwork(params.networkId);
|
|
637
607
|
const idp = await store.getIdp(network.identityProviderId);
|
|
@@ -644,8 +614,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
644
614
|
});
|
|
645
615
|
const ledgerClient = new LedgerClient({
|
|
646
616
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
647
|
-
|
|
648
|
-
accessTokenProvider: AuthTokenProvider.fromToken(accessToken, logger),
|
|
617
|
+
accessTokenProvider: AuthTokenProvider.fromToken(accessToken),
|
|
649
618
|
});
|
|
650
619
|
const status = await emitSessionConnected(newSessionId, network, authContext, ledgerClient);
|
|
651
620
|
// Only bootstrap wallets the first time a session is created.
|
|
@@ -665,12 +634,11 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
665
634
|
throw new Error('No admin auth configured');
|
|
666
635
|
}
|
|
667
636
|
const adminIdp = await getIdpForAuth(network, network.adminAuth);
|
|
668
|
-
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(adminIdp, network.adminAuth
|
|
637
|
+
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(adminIdp, network.adminAuth);
|
|
669
638
|
const partyAllocator = new PartyAllocationService({
|
|
670
639
|
synchronizerId: network.synchronizerId,
|
|
671
640
|
accessTokenProvider: adminAccessTokenProvider,
|
|
672
641
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
673
|
-
logger,
|
|
674
642
|
});
|
|
675
643
|
const service = new WalletSyncService(store, ledgerClient, authContext, logger, drivers, partyAllocator);
|
|
676
644
|
await service.syncWallets();
|
|
@@ -732,8 +700,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
732
700
|
const network = await store.getNetwork(session.network);
|
|
733
701
|
const ledgerClient = new LedgerClient({
|
|
734
702
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
735
|
-
|
|
736
|
-
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken, logger),
|
|
703
|
+
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken),
|
|
737
704
|
});
|
|
738
705
|
const idp = await store.getIdp(network.identityProviderId);
|
|
739
706
|
const status = await networkStatus(ledgerClient);
|
|
@@ -758,26 +725,25 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
758
725
|
syncWallets: async function () {
|
|
759
726
|
const network = await store.getCurrentNetwork();
|
|
760
727
|
const { userId } = assertConnected(authContext);
|
|
761
|
-
const userAccessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken
|
|
728
|
+
const userAccessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken);
|
|
762
729
|
if (!network.adminAuth) {
|
|
763
730
|
throw new Error('No admin auth configured');
|
|
764
731
|
}
|
|
765
732
|
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
766
|
-
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth
|
|
733
|
+
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
767
734
|
const partyAllocator = new PartyAllocationService({
|
|
768
735
|
synchronizerId: network.synchronizerId,
|
|
769
736
|
accessTokenProvider: adminAccessTokenProvider,
|
|
770
737
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
771
|
-
logger,
|
|
772
738
|
});
|
|
773
739
|
const userLedger = new LedgerClient({
|
|
774
740
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
775
|
-
logger,
|
|
776
741
|
accessTokenProvider: userAccessTokenProvider,
|
|
777
742
|
});
|
|
778
743
|
const service = new WalletSyncService(store, userLedger, authContext, logger, drivers, partyAllocator);
|
|
779
744
|
const result = await service.syncWallets();
|
|
780
|
-
if (
|
|
745
|
+
if (result.added.length === 0 &&
|
|
746
|
+
result.updated.length === 0 &&
|
|
781
747
|
result.disabled.length === 0) {
|
|
782
748
|
return result;
|
|
783
749
|
}
|
|
@@ -790,21 +756,19 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
790
756
|
isWalletSyncNeeded: async () => {
|
|
791
757
|
const network = await store.getCurrentNetwork();
|
|
792
758
|
assertConnected(authContext);
|
|
793
|
-
const userAccessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken
|
|
759
|
+
const userAccessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken);
|
|
794
760
|
if (!network.adminAuth) {
|
|
795
761
|
throw new Error('No admin auth configured');
|
|
796
762
|
}
|
|
797
763
|
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
798
|
-
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth
|
|
764
|
+
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
799
765
|
const partyAllocator = new PartyAllocationService({
|
|
800
766
|
synchronizerId: network.synchronizerId,
|
|
801
767
|
accessTokenProvider: adminAccessTokenProvider,
|
|
802
768
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
803
|
-
logger,
|
|
804
769
|
});
|
|
805
770
|
const userLedger = new LedgerClient({
|
|
806
771
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
807
|
-
logger,
|
|
808
772
|
accessTokenProvider: userAccessTokenProvider,
|
|
809
773
|
});
|
|
810
774
|
const service = new WalletSyncService(store, userLedger, authContext, logger, drivers, partyAllocator);
|
|
@@ -837,6 +801,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
837
801
|
...(transaction.externalTxId && {
|
|
838
802
|
externalTxId: transaction.externalTxId,
|
|
839
803
|
}),
|
|
804
|
+
...(transaction.failureReason && {
|
|
805
|
+
failureReason: transaction.failureReason,
|
|
806
|
+
}),
|
|
840
807
|
};
|
|
841
808
|
},
|
|
842
809
|
listTransactions: async function (params) {
|
|
@@ -864,6 +831,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
864
831
|
...(transaction.externalTxId && {
|
|
865
832
|
externalTxId: transaction.externalTxId,
|
|
866
833
|
}),
|
|
834
|
+
...(transaction.failureReason && {
|
|
835
|
+
failureReason: transaction.failureReason,
|
|
836
|
+
}),
|
|
867
837
|
}));
|
|
868
838
|
if (page.nextCursor === null) {
|
|
869
839
|
return { transactions: txs, count: txCount };
|
|
@@ -893,16 +863,19 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
893
863
|
notificationService.getNotifier(session.id).emit('txChanged', {
|
|
894
864
|
status: 'failed',
|
|
895
865
|
commandId: transaction.commandId,
|
|
866
|
+
error: {
|
|
867
|
+
code: errorCodes.provider.userRejectedRequest,
|
|
868
|
+
message: 'Rejected by the user',
|
|
869
|
+
},
|
|
896
870
|
});
|
|
897
871
|
return null;
|
|
898
872
|
},
|
|
899
873
|
generateApiKey: async (params) => {
|
|
900
874
|
const userId = assertConnected(authContext).userId;
|
|
901
875
|
const network = await store.getCurrentNetwork();
|
|
902
|
-
const apiKeyId =
|
|
903
|
-
const generatedApiKey =
|
|
904
|
-
const hashedApiKey =
|
|
905
|
-
.createHash('sha256')
|
|
876
|
+
const apiKeyId = crypto.randomUUID();
|
|
877
|
+
const generatedApiKey = randomBytes(32).toString('hex');
|
|
878
|
+
const hashedApiKey = createHash('sha256')
|
|
906
879
|
.update(generatedApiKey)
|
|
907
880
|
.digest('hex');
|
|
908
881
|
const storedApiKey = {
|
|
@@ -941,6 +914,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
941
914
|
await store.removeApiKey(params.id);
|
|
942
915
|
return null;
|
|
943
916
|
},
|
|
917
|
+
listSigningProviders: async () => ({
|
|
918
|
+
signingProviders: Object.keys(drivers),
|
|
919
|
+
}),
|
|
944
920
|
listSigningProviderKeys: async (params) => {
|
|
945
921
|
return await getSigningProviderKeys(params);
|
|
946
922
|
},
|
|
@@ -959,12 +935,11 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
959
935
|
throw new Error('No admin auth configured');
|
|
960
936
|
}
|
|
961
937
|
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
962
|
-
const adminTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth
|
|
938
|
+
const adminTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
963
939
|
const partyAllocator = new PartyAllocationService({
|
|
964
940
|
synchronizerId: network.synchronizerId,
|
|
965
941
|
accessTokenProvider: adminTokenProvider,
|
|
966
942
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
967
|
-
logger,
|
|
968
943
|
});
|
|
969
944
|
const normalizedKey = partyAllocator.normalizePublicKeyToBase64(publicKey);
|
|
970
945
|
if (!normalizedKey) {
|
|
@@ -1012,7 +987,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
1012
987
|
throw new Error('No active session found');
|
|
1013
988
|
}
|
|
1014
989
|
const notifier = notificationService.getNotifier(session.id);
|
|
1015
|
-
const transactionService = new TransactionService(store,
|
|
990
|
+
const transactionService = new TransactionService(store, drivers, notifier, hashingSchemeVersion);
|
|
1016
991
|
const result = await transactionService.refreshTransaction(authContext, wallet, tx.id);
|
|
1017
992
|
logDynamically(logger, `refreshed transaction status`, {
|
|
1018
993
|
info: { transactionId: tx.id, status: result.status },
|
|
@@ -1022,7 +997,8 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
1022
997
|
},
|
|
1023
998
|
});
|
|
1024
999
|
};
|
|
1025
|
-
function toAuthDto(auth) {
|
|
1000
|
+
function toAuthDto(auth, redactSecrets) {
|
|
1001
|
+
const clientSecret = (secret) => (redactSecrets ? '' : secret);
|
|
1026
1002
|
switch (auth.method) {
|
|
1027
1003
|
case 'authorization_code':
|
|
1028
1004
|
return {
|
|
@@ -1040,7 +1016,7 @@ function toAuthDto(auth) {
|
|
|
1040
1016
|
audience: auth.audience,
|
|
1041
1017
|
scope: auth.scope,
|
|
1042
1018
|
clientId: auth.clientId,
|
|
1043
|
-
clientSecret: auth.clientSecret,
|
|
1019
|
+
clientSecret: clientSecret(auth.clientSecret),
|
|
1044
1020
|
};
|
|
1045
1021
|
case 'self_signed':
|
|
1046
1022
|
return {
|
|
@@ -1048,7 +1024,7 @@ function toAuthDto(auth) {
|
|
|
1048
1024
|
audience: auth.audience,
|
|
1049
1025
|
scope: auth.scope,
|
|
1050
1026
|
clientId: auth.clientId,
|
|
1051
|
-
clientSecret: auth.clientSecret,
|
|
1027
|
+
clientSecret: clientSecret(auth.clientSecret),
|
|
1052
1028
|
issuer: auth.issuer,
|
|
1053
1029
|
};
|
|
1054
1030
|
case 'self_issued':
|
|
@@ -1059,7 +1035,12 @@ function toAuthDto(auth) {
|
|
|
1059
1035
|
};
|
|
1060
1036
|
}
|
|
1061
1037
|
}
|
|
1062
|
-
|
|
1038
|
+
/**
|
|
1039
|
+
* @param redactSecrets returns the client secrets empty. Secrets of
|
|
1040
|
+
* config-managed networks usually come from environment variables of the
|
|
1041
|
+
* Wallet Gateway.
|
|
1042
|
+
*/
|
|
1043
|
+
function toNetworkDto(network, redactSecrets) {
|
|
1063
1044
|
return {
|
|
1064
1045
|
id: network.id,
|
|
1065
1046
|
name: network.name,
|
|
@@ -1067,12 +1048,14 @@ function toNetworkDto(network) {
|
|
|
1067
1048
|
synchronizerId: network.synchronizerId,
|
|
1068
1049
|
identityProviderId: network.identityProviderId,
|
|
1069
1050
|
ledgerApi: network.ledgerApi.baseUrl,
|
|
1070
|
-
auth: toAuthDto(network.auth),
|
|
1051
|
+
auth: toAuthDto(network.auth, redactSecrets),
|
|
1071
1052
|
...(network.adminAuth
|
|
1072
|
-
? { adminAuth: toAuthDto(network.adminAuth) }
|
|
1053
|
+
? { adminAuth: toAuthDto(network.adminAuth, redactSecrets) }
|
|
1073
1054
|
: {}),
|
|
1074
1055
|
...(network.serviceAccountAuth
|
|
1075
|
-
? {
|
|
1056
|
+
? {
|
|
1057
|
+
serviceAccountAuth: toAuthDto(network.serviceAccountAuth, redactSecrets),
|
|
1058
|
+
}
|
|
1076
1059
|
: {}),
|
|
1077
1060
|
};
|
|
1078
1061
|
}
|