@canton-network/wallet-gateway-remote 1.13.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 +2 -2
- package/dist/auth/jwt-auth-service.d.ts.map +1 -1
- package/dist/auth/jwt-auth-service.js +16 -2
- package/dist/config/Config.d.ts +261 -2
- package/dist/config/Config.d.ts.map +1 -1
- package/dist/config/Config.js +26 -5
- package/dist/config/ConfigUtils.d.ts +16 -1
- package/dist/config/ConfigUtils.d.ts.map +1 -1
- package/dist/config/ConfigUtils.js +147 -59
- 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 +2 -1
- package/dist/dapp-api/rpc-gen/typings.d.ts +30 -0
- 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/example-config.d.ts +58 -62
- package/dist/example-config.d.ts.map +1 -1
- package/dist/example-config.js +59 -61
- package/dist/index.js +7 -4
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +64 -19
- package/dist/ledger/wallet-sync-service.d.ts +11 -1
- package/dist/ledger/wallet-sync-service.d.ts.map +1 -1
- package/dist/ledger/wallet-sync-service.js +101 -48
- package/dist/middleware/rateLimit.d.ts.map +1 -1
- package/dist/middleware/rateLimit.js +3 -9
- 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 +31 -0
- package/dist/signing-providers-registration.d.ts +2 -1
- package/dist/signing-providers-registration.d.ts.map +1 -1
- package/dist/signing-providers-registration.js +76 -16
- package/dist/user-api/controller.d.ts +20 -2
- package/dist/user-api/controller.d.ts.map +1 -1
- package/dist/user-api/controller.js +161 -302
- package/dist/user-api/rpc-gen/index.d.ts +12 -3
- package/dist/user-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/user-api/rpc-gen/index.js +4 -1
- package/dist/user-api/rpc-gen/schemas.d.ts.map +1 -1
- package/dist/user-api/rpc-gen/schemas.js +46 -3
- package/dist/user-api/rpc-gen/typings.d.ts +113 -35
- 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 -4
- 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 -3
- 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 -12
- 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 +5 -13
- 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 +1 -0
- package/package.json +34 -30
- 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 -264
- 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 -213
- package/dist/web/frontend/assets/404-D6hNG1H8.js +0 -5
- package/dist/web/frontend/assets/activities-CSaNJ4Bw.js +0 -61
- package/dist/web/frontend/assets/addApiKey-IKOYP6lC.js +0 -92
- package/dist/web/frontend/assets/addIdentityProvider-CnRS1C3U.js +0 -28
- package/dist/web/frontend/assets/addNetwork-Wq0K3t5Z.js +0 -38
- package/dist/web/frontend/assets/addParty-B0GaqKvG.js +0 -14
- package/dist/web/frontend/assets/apiKeys-BgJyxg5r.js +0 -68
- package/dist/web/frontend/assets/approve-kKlT_54l.js +0 -27
- package/dist/web/frontend/assets/callback-83Lr1QFW.js +0 -7
- package/dist/web/frontend/assets/common-BkYw_tO_.js +0 -31
- package/dist/web/frontend/assets/editParty-DU9eMclk.js +0 -15
- package/dist/web/frontend/assets/identityProviders-sWmbKlSu.js +0 -71
- package/dist/web/frontend/assets/index-AvzB2hln.js +0 -93
- package/dist/web/frontend/assets/index-BF3EIXoM.js +0 -2
- package/dist/web/frontend/assets/index-CGK8ht7_.js +0 -1
- package/dist/web/frontend/assets/index-DRQ0oWml.js +0 -4814
- package/dist/web/frontend/assets/index-NgSpx7q_.js +0 -3
- package/dist/web/frontend/assets/login-BqK1nbQm.js +0 -11
- package/dist/web/frontend/assets/networks-C62lWsP4.js +0 -73
- package/dist/web/frontend/assets/reviewIdentityProvider-pILqo6EV.js +0 -43
- package/dist/web/frontend/assets/reviewNetwork-DZOWqkuG.js +0 -43
- package/dist/web/frontend/assets/selfIssuedLogin-DarXIpvS.js +0 -81
- package/dist/web/frontend/assets/signMessage-k9b_lLxh.js +0 -23
|
@@ -5,16 +5,14 @@
|
|
|
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, SIGN_MESSAGE_CAPABLE_SIGNING_PROVIDERS, 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 { providerErrors, rpcErrors } from '@canton-network/core-rpc-errors';
|
|
11
|
+
import { errorCodes, providerErrors, rpcErrors, } from '@canton-network/core-rpc-errors';
|
|
14
12
|
import { randomBytes, createHash, timingSafeEqual } from 'crypto';
|
|
15
13
|
import { assertTokenClaimsMatchNetwork } from './token-network-matching.js';
|
|
16
|
-
import { TransactionService, logDynamically, networkStatus, } from '@canton-network/core-wallet-services';
|
|
17
|
-
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, }) => {
|
|
18
16
|
const logger = _logger.child({ component: 'user-controller' });
|
|
19
17
|
const provider = {
|
|
20
18
|
id: kernelInfo.id,
|
|
@@ -26,6 +24,12 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
26
24
|
const userId = authContext?.userId;
|
|
27
25
|
return !!adminUserId && !!userId && userId === adminUserId;
|
|
28
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
|
+
}
|
|
29
33
|
function assertAdmin() {
|
|
30
34
|
assertIsConnected(authContext);
|
|
31
35
|
if (!adminUserId || authContext.userId !== adminUserId) {
|
|
@@ -41,6 +45,76 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
41
45
|
sessionId: authContext.sessionId,
|
|
42
46
|
};
|
|
43
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
|
+
}
|
|
44
118
|
async function emitSessionConnected(sessionId, network, { userId, accessToken }, ledgerClient) {
|
|
45
119
|
const status = await networkStatus(ledgerClient);
|
|
46
120
|
const statusEvent = {
|
|
@@ -72,9 +146,11 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
72
146
|
/**
|
|
73
147
|
* Session responses always include user auth for the UI.
|
|
74
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.
|
|
75
151
|
*/
|
|
76
152
|
function toSessionNetwork(network) {
|
|
77
|
-
const dto = toNetworkDto(network);
|
|
153
|
+
const dto = toNetworkDto(network, true);
|
|
78
154
|
if (isAdmin()) {
|
|
79
155
|
return dto;
|
|
80
156
|
}
|
|
@@ -82,6 +158,14 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
82
158
|
return rest;
|
|
83
159
|
}
|
|
84
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
|
+
};
|
|
85
169
|
const getSigningProviderKeys = async (params) => {
|
|
86
170
|
const network = await store.getCurrentNetwork();
|
|
87
171
|
if (!network.adminAuth) {
|
|
@@ -110,9 +194,14 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
110
194
|
isAdmin: isAdmin(),
|
|
111
195
|
};
|
|
112
196
|
},
|
|
197
|
+
getServerStatus: async () => {
|
|
198
|
+
assertAdmin();
|
|
199
|
+
return serverStatus.getStatus();
|
|
200
|
+
},
|
|
113
201
|
addNetwork: async (params) => {
|
|
114
202
|
assertAdmin();
|
|
115
203
|
const { network } = params;
|
|
204
|
+
assertNotConfigManaged('Network', network.id);
|
|
116
205
|
const ledgerApi = {
|
|
117
206
|
baseUrl: network.ledgerApi ?? '',
|
|
118
207
|
};
|
|
@@ -166,6 +255,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
166
255
|
},
|
|
167
256
|
removeNetwork: async (params) => {
|
|
168
257
|
assertAdmin();
|
|
258
|
+
assertNotConfigManaged('Network', params.networkName);
|
|
169
259
|
await store.removeNetwork(params.networkName);
|
|
170
260
|
return null;
|
|
171
261
|
},
|
|
@@ -173,12 +263,17 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
173
263
|
const networks = await store.listNetworks();
|
|
174
264
|
return {
|
|
175
265
|
networks: networks.map(toPublicNetwork),
|
|
266
|
+
...(isAdmin() && {
|
|
267
|
+
configManagedIds: [...configManaged.networkIds],
|
|
268
|
+
}),
|
|
176
269
|
};
|
|
177
270
|
},
|
|
178
271
|
getNetwork: async (params) => {
|
|
179
272
|
assertAdmin();
|
|
180
273
|
const network = await store.getNetwork(params.networkId);
|
|
181
|
-
return {
|
|
274
|
+
return {
|
|
275
|
+
network: toNetworkDto(network, configManaged.networkIds.has(network.id)),
|
|
276
|
+
};
|
|
182
277
|
},
|
|
183
278
|
selfSignedAccessToken: async (params) => {
|
|
184
279
|
const network = (await store.listNetworks()).find((n) => n.id === params.networkId);
|
|
@@ -220,6 +315,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
220
315
|
addIdp: async (params) => {
|
|
221
316
|
assertAdmin();
|
|
222
317
|
const validatedIdp = idpSchema.parse(params.idp);
|
|
318
|
+
assertNotConfigManaged('Identity provider', validatedIdp.id);
|
|
223
319
|
// TODO: Add an explicit updateIdp method to the User API spec and controller
|
|
224
320
|
const existingIdps = await store.listIdps();
|
|
225
321
|
if (existingIdps.find((n) => n.id === validatedIdp.id)) {
|
|
@@ -234,11 +330,15 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
234
330
|
},
|
|
235
331
|
removeIdp: async (params) => {
|
|
236
332
|
assertAdmin();
|
|
333
|
+
assertNotConfigManaged('Identity provider', params.identityProviderId);
|
|
237
334
|
logger.info(`Removing IDP ${params.identityProviderId}`);
|
|
238
335
|
await store.removeIdp(params.identityProviderId);
|
|
239
336
|
return null;
|
|
240
337
|
},
|
|
241
|
-
listIdps: async () => ({
|
|
338
|
+
listIdps: async () => ({
|
|
339
|
+
idps: await store.listIdps(),
|
|
340
|
+
...(isAdmin() && { configManagedIds: [...configManaged.idpIds] }),
|
|
341
|
+
}),
|
|
242
342
|
createWallet: async (params) => {
|
|
243
343
|
const { signingProviderId, primary, partyHint } = params;
|
|
244
344
|
assertIsConnected(authContext);
|
|
@@ -298,7 +398,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
298
398
|
return { sessionId };
|
|
299
399
|
},
|
|
300
400
|
getSelfIssuedLoginMode: async (_params) => {
|
|
301
|
-
const service = await
|
|
401
|
+
const service = await selfIssuedAuthService();
|
|
302
402
|
return service.getLoginMode();
|
|
303
403
|
},
|
|
304
404
|
createSelfIssuedWallet: async (params) => {
|
|
@@ -306,34 +406,38 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
306
406
|
if (!drivers[signingProviderId]) {
|
|
307
407
|
throw new Error(`Signing provider ${signingProviderId} not supported`);
|
|
308
408
|
}
|
|
309
|
-
const service = await
|
|
409
|
+
const service = await selfIssuedAuthService();
|
|
310
410
|
const wallet = await service.createWallet({
|
|
311
411
|
partyHint: params.partyHint,
|
|
312
412
|
signingProviderId: signingProviderId,
|
|
413
|
+
keyName: params.keyName,
|
|
313
414
|
});
|
|
314
415
|
return { wallet };
|
|
315
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
|
+
},
|
|
316
425
|
allocateSelfIssuedWallet: async (params) => {
|
|
317
|
-
const service = await
|
|
426
|
+
const service = await selfIssuedAuthService();
|
|
318
427
|
const allocated = await service.allocateParty(params.partyId);
|
|
319
428
|
return { wallet: allocated };
|
|
320
429
|
},
|
|
321
|
-
|
|
430
|
+
signSelfIssuedAccessToken: async (params) => {
|
|
322
431
|
const selfIssuedLoginSession = requireSelfIssuedLoginSession();
|
|
323
|
-
const service = await
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
333
|
-
accessTokenProvider: AuthTokenProvider.fromToken(accessToken),
|
|
334
|
-
});
|
|
335
|
-
await emitSessionConnected(session.id, network, connectedContext, ledgerClient);
|
|
336
|
-
return { wallet, accessToken, sessionId: session.id };
|
|
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);
|
|
337
441
|
},
|
|
338
442
|
removeSelfIssuedLoginSession: async (_params) => {
|
|
339
443
|
const session = requireSelfIssuedLoginSession();
|
|
@@ -431,282 +535,24 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
431
535
|
return response;
|
|
432
536
|
},
|
|
433
537
|
signMessage: async (params) => {
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
throw new Error(`Message signing request not found with id: ${params.messageId}`);
|
|
437
|
-
}
|
|
438
|
-
if (pending.status !== 'pending') {
|
|
439
|
-
throw new Error(`Cannot sign message with status '${pending.status}'. Only pending messages can be signed.`);
|
|
440
|
-
}
|
|
441
|
-
assertIsConnected(authContext);
|
|
442
|
-
const userId = authContext.userId;
|
|
443
|
-
if (pending.userId !== userId) {
|
|
444
|
-
throw new Error(`Message signing request ${pending.id} is not owned by user ${userId}`);
|
|
445
|
-
}
|
|
446
|
-
const session = await store.getSession(authContext.accessToken);
|
|
447
|
-
if (!session) {
|
|
448
|
-
throw new Error('No active session found');
|
|
449
|
-
}
|
|
450
|
-
const notifier = notificationService.getNotifier(session.id);
|
|
451
|
-
const emitFailedAndPersist = async (details) => {
|
|
452
|
-
// Best-effort: make sure listeners see a terminal state.
|
|
453
|
-
try {
|
|
454
|
-
await store.setMessageRawStatus(pending.id, 'failed', {
|
|
455
|
-
failureReason: details,
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
catch {
|
|
459
|
-
// ignore (e.g. record removed concurrently)
|
|
460
|
-
}
|
|
461
|
-
notifier.emit('messageSignature', {
|
|
462
|
-
status: 'failed',
|
|
463
|
-
messageId: pending.id,
|
|
464
|
-
});
|
|
465
|
-
// Preserve the original error message for the caller/UI.
|
|
466
|
-
throw new Error(details);
|
|
467
|
-
};
|
|
468
|
-
if (!pending.message) {
|
|
469
|
-
return await emitFailedAndPersist(`Message request ${pending.id} has an empty message.`);
|
|
470
|
-
}
|
|
471
|
-
const wallet = (await store.getWallets()).find((w) => w.partyId === pending.partyId);
|
|
472
|
-
if (!wallet) {
|
|
473
|
-
return await emitFailedAndPersist(`No wallet found for partyId ${pending.partyId} (from message request ${pending.id})`);
|
|
474
|
-
}
|
|
475
|
-
if (wallet.publicKey !== pending.publicKey) {
|
|
476
|
-
return await emitFailedAndPersist(`Wallet public key changed for partyId ${pending.partyId}; refusing to sign message request ${pending.id}`);
|
|
477
|
-
}
|
|
478
|
-
if (!SIGN_MESSAGE_CAPABLE_SIGNING_PROVIDERS.includes(wallet.signingProviderId)) {
|
|
479
|
-
return await emitFailedAndPersist(`signMessage is only supported for ${SIGN_MESSAGE_CAPABLE_SIGNING_PROVIDERS.join(', ')} wallets, got ${wallet.signingProviderId}`);
|
|
480
|
-
}
|
|
481
|
-
const driver = drivers[wallet.signingProviderId]?.controller(userId);
|
|
482
|
-
if (!driver) {
|
|
483
|
-
return await emitFailedAndPersist(`${wallet.signingProviderId} signing driver not available`);
|
|
484
|
-
}
|
|
485
|
-
const result = await driver.signMessage({
|
|
486
|
-
message: pending.message,
|
|
487
|
-
keyIdentifier: { publicKey: wallet.publicKey },
|
|
488
|
-
internalTxId: pending.id,
|
|
489
|
-
});
|
|
490
|
-
if (isRpcError(result)) {
|
|
491
|
-
return await emitFailedAndPersist(result.error_description);
|
|
492
|
-
}
|
|
493
|
-
if (result.status === 'signed') {
|
|
494
|
-
if (!result.signature) {
|
|
495
|
-
return await emitFailedAndPersist('No signature returned from signing driver');
|
|
496
|
-
}
|
|
497
|
-
await store.setMessageRawStatus(pending.id, 'signed', {
|
|
498
|
-
signedAt: new Date(),
|
|
499
|
-
signature: result.signature,
|
|
500
|
-
externalTxId: result.txId,
|
|
501
|
-
});
|
|
502
|
-
notifier.emit('messageSignature', {
|
|
503
|
-
status: 'signed',
|
|
504
|
-
messageId: pending.id,
|
|
505
|
-
signature: result.signature,
|
|
506
|
-
});
|
|
507
|
-
return {
|
|
508
|
-
status: result.status,
|
|
509
|
-
signature: result.signature,
|
|
510
|
-
publicKey: wallet.publicKey,
|
|
511
|
-
...(result.txId && { externalTxId: result.txId }),
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
if (result.status === 'pending' && result.txId) {
|
|
515
|
-
await store.setMessageRawStatus(pending.id, 'awaiting-signature', { externalTxId: result.txId });
|
|
516
|
-
return {
|
|
517
|
-
publicKey: wallet.publicKey,
|
|
518
|
-
status: 'awaiting-signature',
|
|
519
|
-
externalTxId: result.txId,
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
if (result.status === 'failed' || result.status === 'rejected') {
|
|
523
|
-
const failureReason = `Signing provider returned status: ${result.status}`;
|
|
524
|
-
await store.setMessageRawStatus(pending.id, 'failed', {
|
|
525
|
-
failureReason,
|
|
526
|
-
...(result.txId && { externalTxId: result.txId }),
|
|
527
|
-
});
|
|
528
|
-
notifier.emit('messageSignature', {
|
|
529
|
-
status: 'failed',
|
|
530
|
-
messageId: pending.id,
|
|
531
|
-
});
|
|
532
|
-
return {
|
|
533
|
-
publicKey: wallet.publicKey,
|
|
534
|
-
status: 'failed',
|
|
535
|
-
failureReason,
|
|
536
|
-
...(result.txId && { externalTxId: result.txId }),
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
return await emitFailedAndPersist(`Signing provider returned status: ${result.status} without a txId`);
|
|
538
|
+
const service = await signMessageService();
|
|
539
|
+
return service.sign(assertConnected(authContext), params.messageId, 'regular');
|
|
540
540
|
},
|
|
541
541
|
getSignMessageStatus: async (params) => {
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
throw new Error(`Message signing request not found with id: ${params.messageId}`);
|
|
545
|
-
}
|
|
546
|
-
if (!message.externalTxId ||
|
|
547
|
-
message.status !== 'awaiting-signature') {
|
|
548
|
-
return {
|
|
549
|
-
status: message.status,
|
|
550
|
-
...(message.externalTxId && {
|
|
551
|
-
externalTxId: message.externalTxId,
|
|
552
|
-
}),
|
|
553
|
-
...(message.signature && { signature: message.signature }),
|
|
554
|
-
...(message.failureReason && {
|
|
555
|
-
failureReason: message.failureReason,
|
|
556
|
-
}),
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
const wallet = (await store.getWallets()).find((w) => w.partyId === message.partyId);
|
|
560
|
-
if (!wallet) {
|
|
561
|
-
throw new Error(`No wallet found for partyId ${message.partyId}`);
|
|
562
|
-
}
|
|
563
|
-
assertIsConnected(authContext);
|
|
564
|
-
const provider = wallet.signingProviderId;
|
|
565
|
-
const signingProvider = drivers[provider];
|
|
566
|
-
if (!signingProvider) {
|
|
567
|
-
throw new Error(`No driver found for provider ${provider}`);
|
|
568
|
-
}
|
|
569
|
-
if (provider === SigningProvider.BLOCKDAEMON &&
|
|
570
|
-
!authContext.email) {
|
|
571
|
-
throw new Error('Invalid auth context (missing email) for SigningProvider BlockDaemon');
|
|
572
|
-
}
|
|
573
|
-
const session = await store.getSession(authContext.accessToken);
|
|
574
|
-
if (!session) {
|
|
575
|
-
throw new Error('No active session found');
|
|
576
|
-
}
|
|
577
|
-
const notifier = notificationService.getNotifier(session.id);
|
|
578
|
-
const controllerId = provider === SigningProvider.BLOCKDAEMON
|
|
579
|
-
? authContext.email
|
|
580
|
-
: authContext.userId;
|
|
581
|
-
const signingDriver = signingProvider.controller(controllerId);
|
|
582
|
-
const signingResult = await signingDriver.getTransaction({
|
|
583
|
-
userId: controllerId,
|
|
584
|
-
txId: message.externalTxId,
|
|
585
|
-
});
|
|
586
|
-
if (isRpcError(signingResult)) {
|
|
587
|
-
throw new Error(signingResult.error_description);
|
|
588
|
-
}
|
|
589
|
-
if (signingResult.status === 'signed') {
|
|
590
|
-
if (!signingResult.signature) {
|
|
591
|
-
throw new Error('No signature returned from signing driver');
|
|
592
|
-
}
|
|
593
|
-
await store.setMessageRawStatus(message.id, 'signed', {
|
|
594
|
-
signedAt: new Date(),
|
|
595
|
-
signature: signingResult.signature,
|
|
596
|
-
externalTxId: message.externalTxId,
|
|
597
|
-
});
|
|
598
|
-
notifier.emit('messageSignature', {
|
|
599
|
-
status: 'signed',
|
|
600
|
-
messageId: message.id,
|
|
601
|
-
signature: signingResult.signature,
|
|
602
|
-
});
|
|
603
|
-
return {
|
|
604
|
-
status: 'signed',
|
|
605
|
-
externalTxId: message.externalTxId,
|
|
606
|
-
signature: signingResult.signature,
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
if (signingResult.status === 'failed' ||
|
|
610
|
-
signingResult.status === 'rejected') {
|
|
611
|
-
const failureReason = `Signing provider returned status: ${signingResult.status}`;
|
|
612
|
-
await store.setMessageRawStatus(message.id, 'failed', {
|
|
613
|
-
externalTxId: message.externalTxId,
|
|
614
|
-
failureReason,
|
|
615
|
-
});
|
|
616
|
-
notifier.emit('messageSignature', {
|
|
617
|
-
status: 'failed',
|
|
618
|
-
messageId: message.id,
|
|
619
|
-
});
|
|
620
|
-
return {
|
|
621
|
-
status: 'failed',
|
|
622
|
-
externalTxId: message.externalTxId,
|
|
623
|
-
failureReason,
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
return {
|
|
627
|
-
status: 'awaiting-signature',
|
|
628
|
-
externalTxId: message.externalTxId,
|
|
629
|
-
};
|
|
542
|
+
const service = await signMessageService();
|
|
543
|
+
return service.refreshMessage(assertConnected(authContext), params.messageId, 'regular');
|
|
630
544
|
},
|
|
631
545
|
getMessageToSign: async (params) => {
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
throw new Error(`Message signing request not found with id: ${params.messageId}`);
|
|
635
|
-
}
|
|
636
|
-
return {
|
|
637
|
-
message: {
|
|
638
|
-
id: message.id,
|
|
639
|
-
status: message.status,
|
|
640
|
-
partyId: message.partyId,
|
|
641
|
-
publicKey: message.publicKey,
|
|
642
|
-
message: message.message,
|
|
643
|
-
...(message.origin !== null && { origin: message.origin }),
|
|
644
|
-
...(message.createdAt && {
|
|
645
|
-
createdAt: message.createdAt.toISOString(),
|
|
646
|
-
}),
|
|
647
|
-
...(message.signedAt && {
|
|
648
|
-
signedAt: message.signedAt.toISOString(),
|
|
649
|
-
}),
|
|
650
|
-
...(message.signature && { signature: message.signature }),
|
|
651
|
-
...(message.externalTxId && {
|
|
652
|
-
externalTxId: message.externalTxId,
|
|
653
|
-
}),
|
|
654
|
-
...(message.failureReason && {
|
|
655
|
-
failureReason: message.failureReason,
|
|
656
|
-
}),
|
|
657
|
-
},
|
|
658
|
-
};
|
|
546
|
+
const service = await signMessageService();
|
|
547
|
+
return service.getMessage(params.messageId, 'regular');
|
|
659
548
|
},
|
|
660
549
|
listMessagesToSign: async () => {
|
|
661
|
-
const
|
|
662
|
-
return
|
|
663
|
-
messages: messages.map((message) => ({
|
|
664
|
-
id: message.id,
|
|
665
|
-
status: message.status,
|
|
666
|
-
partyId: message.partyId,
|
|
667
|
-
publicKey: message.publicKey,
|
|
668
|
-
message: message.message,
|
|
669
|
-
...(message.origin !== null && { origin: message.origin }),
|
|
670
|
-
...(message.createdAt && {
|
|
671
|
-
createdAt: message.createdAt.toISOString(),
|
|
672
|
-
}),
|
|
673
|
-
...(message.signedAt && {
|
|
674
|
-
signedAt: message.signedAt.toISOString(),
|
|
675
|
-
}),
|
|
676
|
-
...(message.signature && { signature: message.signature }),
|
|
677
|
-
...(message.externalTxId && {
|
|
678
|
-
externalTxId: message.externalTxId,
|
|
679
|
-
}),
|
|
680
|
-
...(message.failureReason && {
|
|
681
|
-
failureReason: message.failureReason,
|
|
682
|
-
}),
|
|
683
|
-
})),
|
|
684
|
-
};
|
|
550
|
+
const service = await signMessageService();
|
|
551
|
+
return service.listMessages('regular');
|
|
685
552
|
},
|
|
686
553
|
deleteMessageToSign: async (params) => {
|
|
687
|
-
const
|
|
688
|
-
|
|
689
|
-
throw new Error(`Message signing request not found with id: ${params.messageId}`);
|
|
690
|
-
}
|
|
691
|
-
if (message.status !== 'pending' &&
|
|
692
|
-
message.status !== 'awaiting-signature') {
|
|
693
|
-
throw new Error(`Cannot delete message with status '${message.status}'. Only pending or awaiting-signature messages can be deleted.`);
|
|
694
|
-
}
|
|
695
|
-
assertIsConnected(authContext);
|
|
696
|
-
const userId = authContext.userId;
|
|
697
|
-
if (message.userId !== userId) {
|
|
698
|
-
throw new Error(`Message signing request ${message.id} is not owned by user ${userId}`);
|
|
699
|
-
}
|
|
700
|
-
await store.removeMessageRaw(message.id);
|
|
701
|
-
const session = await store.getSession(authContext.accessToken);
|
|
702
|
-
if (session) {
|
|
703
|
-
notificationService
|
|
704
|
-
.getNotifier(session.id)
|
|
705
|
-
.emit('messageSignature', {
|
|
706
|
-
status: 'failed',
|
|
707
|
-
messageId: message.id,
|
|
708
|
-
});
|
|
709
|
-
}
|
|
554
|
+
const service = await signMessageService();
|
|
555
|
+
await service.deleteMessage(assertConnected(authContext), params.messageId, 'regular');
|
|
710
556
|
return null;
|
|
711
557
|
},
|
|
712
558
|
execute: async (executeParams) => {
|
|
@@ -896,7 +742,8 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
896
742
|
});
|
|
897
743
|
const service = new WalletSyncService(store, userLedger, authContext, logger, drivers, partyAllocator);
|
|
898
744
|
const result = await service.syncWallets();
|
|
899
|
-
if (
|
|
745
|
+
if (result.added.length === 0 &&
|
|
746
|
+
result.updated.length === 0 &&
|
|
900
747
|
result.disabled.length === 0) {
|
|
901
748
|
return result;
|
|
902
749
|
}
|
|
@@ -1016,6 +863,10 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
1016
863
|
notificationService.getNotifier(session.id).emit('txChanged', {
|
|
1017
864
|
status: 'failed',
|
|
1018
865
|
commandId: transaction.commandId,
|
|
866
|
+
error: {
|
|
867
|
+
code: errorCodes.provider.userRejectedRequest,
|
|
868
|
+
message: 'Rejected by the user',
|
|
869
|
+
},
|
|
1019
870
|
});
|
|
1020
871
|
return null;
|
|
1021
872
|
},
|
|
@@ -1146,7 +997,8 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
1146
997
|
},
|
|
1147
998
|
});
|
|
1148
999
|
};
|
|
1149
|
-
function toAuthDto(auth) {
|
|
1000
|
+
function toAuthDto(auth, redactSecrets) {
|
|
1001
|
+
const clientSecret = (secret) => (redactSecrets ? '' : secret);
|
|
1150
1002
|
switch (auth.method) {
|
|
1151
1003
|
case 'authorization_code':
|
|
1152
1004
|
return {
|
|
@@ -1164,7 +1016,7 @@ function toAuthDto(auth) {
|
|
|
1164
1016
|
audience: auth.audience,
|
|
1165
1017
|
scope: auth.scope,
|
|
1166
1018
|
clientId: auth.clientId,
|
|
1167
|
-
clientSecret: auth.clientSecret,
|
|
1019
|
+
clientSecret: clientSecret(auth.clientSecret),
|
|
1168
1020
|
};
|
|
1169
1021
|
case 'self_signed':
|
|
1170
1022
|
return {
|
|
@@ -1172,7 +1024,7 @@ function toAuthDto(auth) {
|
|
|
1172
1024
|
audience: auth.audience,
|
|
1173
1025
|
scope: auth.scope,
|
|
1174
1026
|
clientId: auth.clientId,
|
|
1175
|
-
clientSecret: auth.clientSecret,
|
|
1027
|
+
clientSecret: clientSecret(auth.clientSecret),
|
|
1176
1028
|
issuer: auth.issuer,
|
|
1177
1029
|
};
|
|
1178
1030
|
case 'self_issued':
|
|
@@ -1183,7 +1035,12 @@ function toAuthDto(auth) {
|
|
|
1183
1035
|
};
|
|
1184
1036
|
}
|
|
1185
1037
|
}
|
|
1186
|
-
|
|
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) {
|
|
1187
1044
|
return {
|
|
1188
1045
|
id: network.id,
|
|
1189
1046
|
name: network.name,
|
|
@@ -1191,12 +1048,14 @@ function toNetworkDto(network) {
|
|
|
1191
1048
|
synchronizerId: network.synchronizerId,
|
|
1192
1049
|
identityProviderId: network.identityProviderId,
|
|
1193
1050
|
ledgerApi: network.ledgerApi.baseUrl,
|
|
1194
|
-
auth: toAuthDto(network.auth),
|
|
1051
|
+
auth: toAuthDto(network.auth, redactSecrets),
|
|
1195
1052
|
...(network.adminAuth
|
|
1196
|
-
? { adminAuth: toAuthDto(network.adminAuth) }
|
|
1053
|
+
? { adminAuth: toAuthDto(network.adminAuth, redactSecrets) }
|
|
1197
1054
|
: {}),
|
|
1198
1055
|
...(network.serviceAccountAuth
|
|
1199
|
-
? {
|
|
1056
|
+
? {
|
|
1057
|
+
serviceAccountAuth: toAuthDto(network.serviceAccountAuth, redactSecrets),
|
|
1058
|
+
}
|
|
1200
1059
|
: {}),
|
|
1201
1060
|
};
|
|
1202
1061
|
}
|