@canton-network/wallet-gateway-remote 1.11.3 → 1.13.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 +105 -29
- package/dist/auth/jwt-auth-service.d.ts +5 -4
- package/dist/auth/jwt-auth-service.d.ts.map +1 -1
- package/dist/auth/jwt-auth-service.js +219 -78
- package/dist/config/Config.d.ts +194 -19
- package/dist/config/Config.d.ts.map +1 -1
- package/dist/config/Config.js +120 -6
- package/dist/config/ConfigUtils.d.ts +1 -1
- package/dist/config/ConfigUtils.d.ts.map +1 -1
- package/dist/config/ConfigUtils.js +46 -9
- package/dist/dapp-api/controller.d.ts +5 -7
- package/dist/dapp-api/controller.d.ts.map +1 -1
- package/dist/dapp-api/controller.js +43 -38
- package/dist/dapp-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/dapp-api/rpc-gen/schemas.d.ts +3 -0
- package/dist/dapp-api/rpc-gen/schemas.d.ts.map +1 -0
- package/dist/dapp-api/rpc-gen/schemas.js +201 -0
- package/dist/dapp-api/rpc-gen/typings.d.ts +11 -4
- package/dist/dapp-api/rpc-gen/typings.d.ts.map +1 -1
- package/dist/dapp-api/server.d.ts +8 -9
- package/dist/dapp-api/server.d.ts.map +1 -1
- package/dist/dapp-api/server.js +7 -43
- package/dist/dapp-api/sse-sink.d.ts +18 -0
- package/dist/dapp-api/sse-sink.d.ts.map +1 -0
- package/dist/dapp-api/sse-sink.js +27 -0
- package/dist/env.d.ts +1 -25
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +0 -23
- package/dist/example-config.d.ts +40 -4
- package/dist/example-config.d.ts.map +1 -1
- package/dist/example-config.js +44 -8
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +75 -28
- package/dist/init.d.ts +2 -2
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +30 -107
- package/dist/ledger/party-allocation-service.d.ts +3 -6
- package/dist/ledger/party-allocation-service.d.ts.map +1 -1
- package/dist/ledger/party-allocation-service.js +1 -3
- package/dist/ledger/self-issued-auth-service.d.ts +50 -0
- package/dist/ledger/self-issued-auth-service.d.ts.map +1 -0
- package/dist/ledger/self-issued-auth-service.js +264 -0
- package/dist/ledger/wallet-allocation/signing-providers/bitgo-wallet-allocator.d.ts +7 -7
- 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 +7 -7
- package/dist/ledger/wallet-allocation/signing-providers/blockdaemon-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/blockdaemon-wallet-allocator.js +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/dfns-wallet-allocator.d.ts +7 -7
- package/dist/ledger/wallet-allocation/signing-providers/dfns-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/dfns-wallet-allocator.js +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.d.ts +7 -7
- package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.js +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/kernel-wallet-allocator.d.ts +7 -7
- package/dist/ledger/wallet-allocation/signing-providers/kernel-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/kernel-wallet-allocator.js +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/participant-wallet-allocator.d.ts +6 -6
- 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 +7 -7
- package/dist/ledger/wallet-allocation/signing-providers/securosys-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/securosys-wallet-allocator.js +1 -1
- package/dist/ledger/wallet-allocation/wallet-allocation-service.d.ts +8 -8
- 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 +15 -9
- package/dist/ledger/wallet-sync-service.d.ts.map +1 -1
- package/dist/ledger/wallet-sync-service.js +184 -35
- package/dist/middleware/apiKeyAuth.d.ts +3 -3
- package/dist/middleware/apiKeyAuth.d.ts.map +1 -1
- package/dist/middleware/apiKeyAuth.js +6 -10
- package/dist/middleware/errorHandler.d.ts +7 -1
- package/dist/middleware/errorHandler.d.ts.map +1 -1
- package/dist/middleware/errorHandler.js +85 -1
- package/dist/middleware/jsonRpcHandler.d.ts +6 -4
- package/dist/middleware/jsonRpcHandler.d.ts.map +1 -1
- package/dist/middleware/jsonRpcHandler.js +49 -10
- package/dist/middleware/jwtAuth.d.ts +2 -2
- package/dist/middleware/jwtAuth.d.ts.map +1 -1
- package/dist/middleware/jwtAuth.js +17 -2
- package/dist/middleware/securityHeaders.d.ts.map +1 -1
- package/dist/middleware/sessionHandler.d.ts +6 -4
- package/dist/middleware/sessionHandler.d.ts.map +1 -1
- package/dist/middleware/sessionHandler.js +25 -1
- package/dist/signing/service-account-session.d.ts +3 -3
- package/dist/signing/service-account-session.d.ts.map +1 -1
- package/dist/signing/service-account-session.js +3 -3
- package/dist/signing/signing-worker.d.ts +18 -16
- package/dist/signing/signing-worker.d.ts.map +1 -1
- package/dist/signing/signing-worker.js +19 -16
- package/dist/signing-providers-registration.d.ts +6 -0
- package/dist/signing-providers-registration.d.ts.map +1 -0
- package/dist/signing-providers-registration.js +216 -0
- package/dist/user-api/controller.d.ts +14 -7
- package/dist/user-api/controller.d.ts.map +1 -1
- package/dist/user-api/controller.js +441 -154
- package/dist/user-api/rpc-gen/index.d.ts +27 -0
- package/dist/user-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/user-api/rpc-gen/index.js +9 -0
- package/dist/user-api/rpc-gen/schemas.d.ts +3 -0
- package/dist/user-api/rpc-gen/schemas.d.ts.map +1 -0
- package/dist/user-api/rpc-gen/schemas.js +1067 -0
- package/dist/user-api/rpc-gen/typings.d.ts +237 -41
- package/dist/user-api/rpc-gen/typings.d.ts.map +1 -1
- package/dist/user-api/server.d.ts +7 -8
- package/dist/user-api/server.d.ts.map +1 -1
- package/dist/user-api/server.js +2 -0
- package/dist/user-api/token-network-matching.d.ts +2 -2
- package/dist/user-api/token-network-matching.d.ts.map +1 -1
- package/dist/user-api/token-network-matching.js +9 -7
- package/dist/utils.d.ts +0 -29
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -57
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -5
- package/dist/web/frontend/404/index.html +2 -2
- package/dist/web/frontend/activities/index.html +3 -3
- package/dist/web/frontend/api-keys/add/index.html +2 -2
- package/dist/web/frontend/api-keys/index.html +2 -2
- package/dist/web/frontend/approve/index.html +4 -3
- package/dist/web/frontend/assets/{404-Ds_FbOi_.js → 404-D6hNG1H8.js} +1 -1
- package/dist/web/frontend/assets/{activities-DSP_NZCE.js → activities-CSaNJ4Bw.js} +2 -2
- package/dist/web/frontend/assets/{addApiKey-Zv2CS3ub.js → addApiKey-IKOYP6lC.js} +2 -2
- package/dist/web/frontend/assets/addIdentityProvider-CnRS1C3U.js +28 -0
- package/dist/web/frontend/assets/{addNetwork-B620CvC-.js → addNetwork-Wq0K3t5Z.js} +4 -4
- package/dist/web/frontend/assets/addParty-B0GaqKvG.js +14 -0
- package/dist/web/frontend/assets/{apiKeys-ohQpjexi.js → apiKeys-BgJyxg5r.js} +2 -2
- package/dist/web/frontend/assets/approve-kKlT_54l.js +27 -0
- package/dist/web/frontend/assets/callback-83Lr1QFW.js +7 -0
- package/dist/web/frontend/assets/common-BkYw_tO_.js +31 -0
- package/dist/web/frontend/assets/editParty-DU9eMclk.js +15 -0
- package/dist/web/frontend/assets/{identityProviders-C26I4FyE.js → identityProviders-sWmbKlSu.js} +2 -2
- package/dist/web/frontend/assets/index-AvzB2hln.js +93 -0
- package/dist/web/frontend/assets/index-BF3EIXoM.js +2 -0
- package/dist/web/frontend/assets/index-CGK8ht7_.js +1 -0
- package/dist/web/frontend/assets/index-DRQ0oWml.js +4814 -0
- package/dist/web/frontend/assets/index-NgSpx7q_.js +3 -0
- package/dist/web/frontend/assets/login-BqK1nbQm.js +11 -0
- package/dist/web/frontend/assets/{networks-CtFnklqS.js → networks-C62lWsP4.js} +4 -4
- package/dist/web/frontend/assets/{reviewIdentityProvider-GBlomu4-.js → reviewIdentityProvider-pILqo6EV.js} +3 -3
- package/dist/web/frontend/assets/{reviewNetwork-CWEgNcCg.js → reviewNetwork-DZOWqkuG.js} +4 -4
- package/dist/web/frontend/assets/selfIssuedLogin-DarXIpvS.js +81 -0
- package/dist/web/frontend/assets/signMessage-k9b_lLxh.js +23 -0
- package/dist/web/frontend/callback/index.html +3 -2
- package/dist/web/frontend/identity-providers/add/index.html +2 -2
- package/dist/web/frontend/identity-providers/index.html +2 -2
- package/dist/web/frontend/identity-providers/review/index.html +2 -2
- package/dist/web/frontend/index.html +1 -1
- package/dist/web/frontend/login/index.html +3 -2
- package/dist/web/frontend/networks/add/index.html +2 -2
- package/dist/web/frontend/networks/index.html +2 -2
- package/dist/web/frontend/networks/review/index.html +2 -2
- package/dist/web/frontend/parties/add/index.html +5 -4
- package/dist/web/frontend/parties/edit/index.html +5 -4
- package/dist/web/frontend/parties/index.html +3 -2
- package/dist/web/frontend/self-issued-login/index.html +24 -0
- package/dist/web/frontend/sign-message/index.html +2 -2
- package/dist/web/route-inputs.js +1 -1
- package/dist/web/server.d.ts +1 -1
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +1 -1
- package/package.json +54 -50
- 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 -466
- 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 -19
- 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 -535
- 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 -40
- 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/transaction-service.d.ts +0 -27
- package/dist/ledger/transaction-service.d.ts.map +0 -1
- package/dist/ledger/transaction-service.js +0 -297
- package/dist/ledger/transaction-service.test.d.ts +0 -2
- package/dist/ledger/transaction-service.test.d.ts.map +0 -1
- package/dist/ledger/transaction-service.test.js +0 -551
- 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 -857
- 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 -100
- 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 -277
- 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 -155
- package/dist/notification/NotificationService.d.ts +0 -18
- package/dist/notification/NotificationService.d.ts.map +0 -1
- package/dist/notification/NotificationService.js +0 -26
- package/dist/notification/NotificationService.test.d.ts +0 -2
- package/dist/notification/NotificationService.test.d.ts.map +0 -1
- package/dist/notification/NotificationService.test.js +0 -110
- 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 -89
- package/dist/signing/signing-drivers.d.ts +0 -7
- package/dist/signing/signing-drivers.d.ts.map +0 -1
- package/dist/signing/signing-drivers.js +0 -3
- 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 -155
- 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 -1100
- 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 -116
- 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/addIdentityProvider-BqiC9u9A.js +0 -28
- package/dist/web/frontend/assets/addParty-CSMZt930.js +0 -13
- package/dist/web/frontend/assets/approve-D5YmfGHz.js +0 -21
- package/dist/web/frontend/assets/callback-Dk9tIdBj.js +0 -7
- package/dist/web/frontend/assets/common-BCDg7K0r.js +0 -31
- package/dist/web/frontend/assets/editParty-DX9X91dp.js +0 -14
- package/dist/web/frontend/assets/index-BCECRB_Y.js +0 -4943
- package/dist/web/frontend/assets/index-Cvcr2Fng.js +0 -2
- package/dist/web/frontend/assets/index-DrEQVBtC.js +0 -93
- package/dist/web/frontend/assets/login-dmjNaK2x.js +0 -11
- package/dist/web/frontend/assets/settings-DSh9rqaO.js +0 -37
- package/dist/web/frontend/assets/signMessage-CT2_Y1LA.js +0 -79
- package/dist/web/frontend/settings/index.html +0 -15
- 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,20 +1,19 @@
|
|
|
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
|
-
import { assertConnected, authSchema, AuthTokenProvider, idpSchema, } from '@canton-network/core-wallet-auth';
|
|
8
|
-
import { isRpcError, SigningProvider } from '@canton-network/core-signing-lib';
|
|
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
9
|
import { PartyAllocationService } from '../ledger/party-allocation-service.js';
|
|
10
10
|
import { WalletAllocationService } from '../ledger/wallet-allocation/wallet-allocation-service.js';
|
|
11
11
|
import { WalletSyncService } from '../ledger/wallet-sync-service.js';
|
|
12
|
-
import {
|
|
13
|
-
import { v4 } from 'uuid';
|
|
14
|
-
import { TransactionService } from '../ledger/transaction-service.js';
|
|
12
|
+
import { assertLoginAllowed, createSelfIssuedAuthService, } from '../ledger/self-issued-auth-service.js';
|
|
15
13
|
import { providerErrors, rpcErrors } from '@canton-network/core-rpc-errors';
|
|
16
|
-
import
|
|
14
|
+
import { randomBytes, createHash, timingSafeEqual } from 'crypto';
|
|
17
15
|
import { assertTokenClaimsMatchNetwork } from './token-network-matching.js';
|
|
16
|
+
import { TransactionService, logDynamically, networkStatus, } from '@canton-network/core-wallet-services';
|
|
18
17
|
export const userController = (kernelInfo, userUrl, store, notificationService, authContext, drivers, _logger, hashingSchemeVersion, adminUserId) => {
|
|
19
18
|
const logger = _logger.child({ component: 'user-controller' });
|
|
20
19
|
const provider = {
|
|
@@ -28,11 +27,48 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
28
27
|
return !!adminUserId && !!userId && userId === adminUserId;
|
|
29
28
|
}
|
|
30
29
|
function assertAdmin() {
|
|
31
|
-
|
|
32
|
-
if (!adminUserId || userId !== adminUserId) {
|
|
30
|
+
assertIsConnected(authContext);
|
|
31
|
+
if (!adminUserId || authContext.userId !== adminUserId) {
|
|
33
32
|
throw new Error('Unauthorized: only the admin user can perform this operation');
|
|
34
33
|
}
|
|
35
34
|
}
|
|
35
|
+
function requireSelfIssuedLoginSession() {
|
|
36
|
+
if (!authContext || authContext.isApiKey || !authContext.sessionId) {
|
|
37
|
+
throw new Error('No self-issued login session found');
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
userId: authContext.userId,
|
|
41
|
+
sessionId: authContext.sessionId,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async function emitSessionConnected(sessionId, network, { userId, accessToken }, ledgerClient) {
|
|
45
|
+
const status = await networkStatus(ledgerClient);
|
|
46
|
+
const statusEvent = {
|
|
47
|
+
provider: provider,
|
|
48
|
+
connection: {
|
|
49
|
+
isConnected: status.isConnected,
|
|
50
|
+
reason: status.reason ? status.reason : 'OK',
|
|
51
|
+
isNetworkConnected: status.isConnected,
|
|
52
|
+
networkReason: status.reason ? status.reason : 'OK',
|
|
53
|
+
},
|
|
54
|
+
network: {
|
|
55
|
+
networkId: network.id,
|
|
56
|
+
ledgerApi: network.ledgerApi.baseUrl,
|
|
57
|
+
accessToken: accessToken,
|
|
58
|
+
},
|
|
59
|
+
session: {
|
|
60
|
+
accessToken: accessToken,
|
|
61
|
+
userId: userId,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const notifier = notificationService.getNotifier(sessionId);
|
|
65
|
+
notifier.emit('statusChanged', statusEvent);
|
|
66
|
+
notifier.emit('connected', statusEvent);
|
|
67
|
+
return status;
|
|
68
|
+
}
|
|
69
|
+
async function getIdpForAuth(network, auth) {
|
|
70
|
+
return await store.getIdp(resolveAuthIdentityProviderId(auth, network.identityProviderId));
|
|
71
|
+
}
|
|
36
72
|
/**
|
|
37
73
|
* Session responses always include user auth for the UI.
|
|
38
74
|
* Privileged credentials are included only for the admin user.
|
|
@@ -45,18 +81,18 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
45
81
|
const { adminAuth: _adminAuth, serviceAccountAuth: _sa, ...rest } = dto;
|
|
46
82
|
return rest;
|
|
47
83
|
}
|
|
84
|
+
const authAwareStore = store;
|
|
48
85
|
const getSigningProviderKeys = async (params) => {
|
|
49
86
|
const network = await store.getCurrentNetwork();
|
|
50
|
-
const idp = await store.getIdp(network.identityProviderId);
|
|
51
87
|
if (!network.adminAuth) {
|
|
52
88
|
throw new Error('No admin auth configured');
|
|
53
89
|
}
|
|
54
|
-
const
|
|
90
|
+
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
91
|
+
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
55
92
|
const partyAllocator = new PartyAllocationService({
|
|
56
93
|
synchronizerId: network.synchronizerId,
|
|
57
94
|
accessTokenProvider: adminAccessTokenProvider,
|
|
58
95
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
59
|
-
logger,
|
|
60
96
|
});
|
|
61
97
|
const walletAllocationService = new WalletAllocationService(store, logger, partyAllocator, drivers);
|
|
62
98
|
if (!drivers[params.signingProviderId])
|
|
@@ -68,9 +104,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
68
104
|
};
|
|
69
105
|
return buildController({
|
|
70
106
|
getUser: async () => {
|
|
71
|
-
|
|
107
|
+
assertIsConnected(authContext);
|
|
72
108
|
return {
|
|
73
|
-
userId,
|
|
109
|
+
userId: authContext.userId,
|
|
74
110
|
isAdmin: isAdmin(),
|
|
75
111
|
};
|
|
76
112
|
},
|
|
@@ -98,6 +134,24 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
98
134
|
serviceAccountAuth,
|
|
99
135
|
ledgerApi,
|
|
100
136
|
};
|
|
137
|
+
const referencedIdentityProviderIds = new Set([
|
|
138
|
+
newNetwork.identityProviderId,
|
|
139
|
+
...[
|
|
140
|
+
newNetwork.auth,
|
|
141
|
+
newNetwork.adminAuth,
|
|
142
|
+
newNetwork.serviceAccountAuth,
|
|
143
|
+
].flatMap((auth) => auth?.method === 'client_credentials' &&
|
|
144
|
+
auth.identityProviderId
|
|
145
|
+
? [auth.identityProviderId]
|
|
146
|
+
: []),
|
|
147
|
+
]);
|
|
148
|
+
const configuredIdentityProviderIds = new Set((await store.listIdps()).map((idp) => idp.id));
|
|
149
|
+
const missingIdentityProviderId = [
|
|
150
|
+
...referencedIdentityProviderIds,
|
|
151
|
+
].find((id) => !configuredIdentityProviderIds.has(id));
|
|
152
|
+
if (missingIdentityProviderId) {
|
|
153
|
+
throw new Error(`Identity provider "${missingIdentityProviderId}" not found`);
|
|
154
|
+
}
|
|
101
155
|
// TODO: Add an explicit updateNetwork method to the User API spec and controller
|
|
102
156
|
const existingNetworks = await store.listNetworks();
|
|
103
157
|
if (existingNetworks.find((n) => n.id === newNetwork.id)) {
|
|
@@ -135,13 +189,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
135
189
|
if (auth.method !== 'self_signed') {
|
|
136
190
|
throw new Error('Network does not use self_signed authentication');
|
|
137
191
|
}
|
|
138
|
-
const clientSecretMatch =
|
|
139
|
-
.createHash('sha256')
|
|
192
|
+
const clientSecretMatch = timingSafeEqual(createHash('sha256')
|
|
140
193
|
.update(params.clientSecret, 'utf8')
|
|
141
|
-
.digest(),
|
|
142
|
-
.createHash('sha256')
|
|
143
|
-
.update(auth.clientSecret, 'utf8')
|
|
144
|
-
.digest());
|
|
194
|
+
.digest(), createHash('sha256').update(auth.clientSecret, 'utf8').digest());
|
|
145
195
|
if (!clientSecretMatch) {
|
|
146
196
|
throw providerErrors.unauthorized({
|
|
147
197
|
message: 'Invalid client secret',
|
|
@@ -164,7 +214,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
164
214
|
scope: auth.scope,
|
|
165
215
|
audience: auth.audience,
|
|
166
216
|
},
|
|
167
|
-
}
|
|
217
|
+
}).getAccessToken();
|
|
168
218
|
return { accessToken };
|
|
169
219
|
},
|
|
170
220
|
addIdp: async (params) => {
|
|
@@ -191,44 +241,113 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
191
241
|
listIdps: async () => ({ idps: await store.listIdps() }),
|
|
192
242
|
createWallet: async (params) => {
|
|
193
243
|
const { signingProviderId, primary, partyHint } = params;
|
|
194
|
-
|
|
244
|
+
assertIsConnected(authContext);
|
|
195
245
|
const network = await store.getCurrentNetwork();
|
|
196
246
|
if (network === undefined) {
|
|
197
247
|
throw new Error('No network session found');
|
|
198
248
|
}
|
|
199
|
-
const idp = await store.getIdp(network.identityProviderId);
|
|
200
249
|
if (!network.adminAuth) {
|
|
201
250
|
throw new Error('No admin auth configured');
|
|
202
251
|
}
|
|
203
|
-
const
|
|
252
|
+
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
253
|
+
const adminTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
204
254
|
const partyAllocator = new PartyAllocationService({
|
|
205
255
|
synchronizerId: network.synchronizerId,
|
|
206
256
|
accessTokenProvider: adminTokenProvider,
|
|
207
257
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
208
|
-
logger,
|
|
209
258
|
});
|
|
210
259
|
const walletAllocationService = new WalletAllocationService(store, logger, partyAllocator, drivers);
|
|
211
260
|
if (!drivers[signingProviderId]) {
|
|
212
261
|
throw new Error(`Signing provider ${signingProviderId} not supported`);
|
|
213
262
|
}
|
|
214
|
-
const wallet = await walletAllocationService.createWallet(
|
|
215
|
-
// Sync wallets (TODO: separate rights sync from wallet sync as we only need rights sync here)
|
|
263
|
+
const wallet = await walletAllocationService.createWallet(authContext, partyHint, primary ?? false, signingProviderId, params.keyName);
|
|
216
264
|
const ledgerClient = new LedgerClient({
|
|
217
265
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
218
|
-
|
|
219
|
-
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken, logger),
|
|
266
|
+
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken),
|
|
220
267
|
});
|
|
221
|
-
const service = new WalletSyncService(store, ledgerClient, authContext, logger
|
|
222
|
-
await service.
|
|
268
|
+
const service = new WalletSyncService(store, ledgerClient, authContext, logger);
|
|
269
|
+
await service.syncRights();
|
|
223
270
|
// Notify about the change and return the new wallet
|
|
224
271
|
const wallets = await store.getWallets();
|
|
225
272
|
notificationService
|
|
226
|
-
.getNotifier(
|
|
273
|
+
.getNotifier(authContext.userId)
|
|
227
274
|
.emit('accountsChanged', wallets);
|
|
275
|
+
const walletWithUpdatedRights = wallets.find((w) => w.partyId === wallet.partyId && w.networkId === network.id);
|
|
276
|
+
return { wallet: walletWithUpdatedRights ?? wallet };
|
|
277
|
+
},
|
|
278
|
+
startSelfIssuedLoginSession: async (params) => {
|
|
279
|
+
const username = params.username.trim();
|
|
280
|
+
if (!username) {
|
|
281
|
+
throw new Error('username is required');
|
|
282
|
+
}
|
|
283
|
+
const network = await authAwareStore.getNetwork(params.networkId);
|
|
284
|
+
if (network.auth.method !== 'self_issued') {
|
|
285
|
+
throw new Error('Network does not use self_issued authentication');
|
|
286
|
+
}
|
|
287
|
+
const onboardingStore = authAwareStore.withAuthContext({
|
|
288
|
+
userId: username,
|
|
289
|
+
accessToken: '',
|
|
290
|
+
});
|
|
291
|
+
await assertLoginAllowed(authAwareStore, network, username);
|
|
292
|
+
const sessionId = crypto.randomUUID();
|
|
293
|
+
await onboardingStore.setSession({
|
|
294
|
+
id: sessionId,
|
|
295
|
+
origin: params.origin,
|
|
296
|
+
network: network.id,
|
|
297
|
+
});
|
|
298
|
+
return { sessionId };
|
|
299
|
+
},
|
|
300
|
+
getSelfIssuedLoginMode: async (_params) => {
|
|
301
|
+
const service = await createSelfIssuedAuthService(authAwareStore, requireSelfIssuedLoginSession(), drivers, logger);
|
|
302
|
+
return service.getLoginMode();
|
|
303
|
+
},
|
|
304
|
+
createSelfIssuedWallet: async (params) => {
|
|
305
|
+
const { signingProviderId } = params;
|
|
306
|
+
if (!drivers[signingProviderId]) {
|
|
307
|
+
throw new Error(`Signing provider ${signingProviderId} not supported`);
|
|
308
|
+
}
|
|
309
|
+
const service = await createSelfIssuedAuthService(authAwareStore, requireSelfIssuedLoginSession(), drivers, logger);
|
|
310
|
+
const wallet = await service.createWallet({
|
|
311
|
+
partyHint: params.partyHint,
|
|
312
|
+
signingProviderId: signingProviderId,
|
|
313
|
+
});
|
|
228
314
|
return { wallet };
|
|
229
315
|
},
|
|
316
|
+
allocateSelfIssuedWallet: async (params) => {
|
|
317
|
+
const service = await createSelfIssuedAuthService(authAwareStore, requireSelfIssuedLoginSession(), drivers, logger);
|
|
318
|
+
const allocated = await service.allocateParty(params.partyId);
|
|
319
|
+
return { wallet: allocated };
|
|
320
|
+
},
|
|
321
|
+
completeSelfIssuedLogin: async (params) => {
|
|
322
|
+
const selfIssuedLoginSession = requireSelfIssuedLoginSession();
|
|
323
|
+
const service = await createSelfIssuedAuthService(authAwareStore, selfIssuedLoginSession, drivers, logger);
|
|
324
|
+
const { wallet, accessToken, session } = await service.completeLogin(params.partyId);
|
|
325
|
+
const connectedContext = {
|
|
326
|
+
userId: selfIssuedLoginSession.userId,
|
|
327
|
+
accessToken,
|
|
328
|
+
};
|
|
329
|
+
const scopedStore = authAwareStore.withAuthContext(connectedContext);
|
|
330
|
+
const network = await scopedStore.getCurrentNetwork();
|
|
331
|
+
const ledgerClient = new LedgerClient({
|
|
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 };
|
|
337
|
+
},
|
|
338
|
+
removeSelfIssuedLoginSession: async (_params) => {
|
|
339
|
+
const session = requireSelfIssuedLoginSession();
|
|
340
|
+
await authAwareStore
|
|
341
|
+
.withAuthContext({
|
|
342
|
+
userId: session.userId,
|
|
343
|
+
accessToken: '',
|
|
344
|
+
sessionId: session.sessionId,
|
|
345
|
+
})
|
|
346
|
+
.removeSelfIssuedLoginSession(session.sessionId);
|
|
347
|
+
return null;
|
|
348
|
+
},
|
|
230
349
|
allocatePartyForWallet: async (params) => {
|
|
231
|
-
|
|
350
|
+
assertIsConnected(authContext);
|
|
232
351
|
const network = await store.getCurrentNetwork();
|
|
233
352
|
if (!network) {
|
|
234
353
|
throw new Error('No network session found');
|
|
@@ -241,34 +360,31 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
241
360
|
if (!existingWallet) {
|
|
242
361
|
throw new Error(`Wallet not found for party ${params.partyId}`);
|
|
243
362
|
}
|
|
244
|
-
const idp = await
|
|
245
|
-
const accessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth
|
|
363
|
+
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
364
|
+
const accessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
246
365
|
const partyAllocator = new PartyAllocationService({
|
|
247
366
|
synchronizerId: network.synchronizerId,
|
|
248
367
|
accessTokenProvider,
|
|
249
368
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
250
|
-
logger,
|
|
251
369
|
});
|
|
252
370
|
const walletAllocationService = new WalletAllocationService(store, logger, partyAllocator, drivers);
|
|
253
371
|
const signingProviderId = existingWallet.signingProviderId;
|
|
254
372
|
if (!drivers[signingProviderId]) {
|
|
255
373
|
throw new Error(`Signing provider ${signingProviderId} not supported`);
|
|
256
374
|
}
|
|
257
|
-
await walletAllocationService.allocateParty(
|
|
258
|
-
// Sync wallets (TODO: separate rights sync from wallet sync as we only need rights sync here)
|
|
375
|
+
await walletAllocationService.allocateParty(authContext, existingWallet, signingProviderId);
|
|
259
376
|
const ledgerClient = new LedgerClient({
|
|
260
377
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
261
|
-
|
|
262
|
-
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken, logger),
|
|
378
|
+
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken),
|
|
263
379
|
});
|
|
264
|
-
const service = new WalletSyncService(store, ledgerClient, authContext, logger
|
|
265
|
-
await service.
|
|
380
|
+
const service = new WalletSyncService(store, ledgerClient, authContext, logger);
|
|
381
|
+
await service.syncRights();
|
|
266
382
|
// Notify about the change and return the updated wallet
|
|
267
383
|
const wallets = await store.getWallets();
|
|
268
384
|
const wallet = wallets.find((w) => w.partyId === existingWallet.partyId &&
|
|
269
385
|
w.networkId === network.id);
|
|
270
386
|
notificationService
|
|
271
|
-
.getNotifier(
|
|
387
|
+
.getNotifier(authContext.userId)
|
|
272
388
|
.emit('accountsChanged', wallets);
|
|
273
389
|
return { wallet };
|
|
274
390
|
},
|
|
@@ -294,20 +410,20 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
294
410
|
const wallets = await store.getWallets();
|
|
295
411
|
const wallet = wallets.find((w) => w.partyId === signParams.partyId);
|
|
296
412
|
if (wallet === undefined) {
|
|
297
|
-
throw new Error(
|
|
413
|
+
throw new Error(`No wallet found for partyId ${signParams.partyId}`);
|
|
298
414
|
}
|
|
299
|
-
|
|
300
|
-
const session = await store.getSession(
|
|
415
|
+
assertIsConnected(authContext);
|
|
416
|
+
const session = await store.getSession(authContext.accessToken);
|
|
301
417
|
if (!session) {
|
|
302
418
|
throw new Error('No active session found');
|
|
303
419
|
}
|
|
304
420
|
const notifier = notificationService.getNotifier(session.id);
|
|
305
|
-
const transactionService = new TransactionService(store,
|
|
421
|
+
const transactionService = new TransactionService(store, drivers, notifier, hashingSchemeVersion);
|
|
306
422
|
logDynamically(logger, 'signing transaction with params', {
|
|
307
423
|
info: { transactionId: signParams.transactionId },
|
|
308
|
-
debug: { signParams, wallet,
|
|
424
|
+
debug: { signParams, wallet, authContext },
|
|
309
425
|
});
|
|
310
|
-
const response = await transactionService.sign(
|
|
426
|
+
const response = await transactionService.sign(authContext, wallet, signParams);
|
|
311
427
|
logDynamically(logger, 'transaction signed with response', {
|
|
312
428
|
info: { transactionId: signParams.transactionId },
|
|
313
429
|
debug: { response },
|
|
@@ -322,11 +438,12 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
322
438
|
if (pending.status !== 'pending') {
|
|
323
439
|
throw new Error(`Cannot sign message with status '${pending.status}'. Only pending messages can be signed.`);
|
|
324
440
|
}
|
|
325
|
-
|
|
441
|
+
assertIsConnected(authContext);
|
|
442
|
+
const userId = authContext.userId;
|
|
326
443
|
if (pending.userId !== userId) {
|
|
327
444
|
throw new Error(`Message signing request ${pending.id} is not owned by user ${userId}`);
|
|
328
445
|
}
|
|
329
|
-
const session = await store.getSession(
|
|
446
|
+
const session = await store.getSession(authContext.accessToken);
|
|
330
447
|
if (!session) {
|
|
331
448
|
throw new Error('No active session found');
|
|
332
449
|
}
|
|
@@ -334,7 +451,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
334
451
|
const emitFailedAndPersist = async (details) => {
|
|
335
452
|
// Best-effort: make sure listeners see a terminal state.
|
|
336
453
|
try {
|
|
337
|
-
await store.setMessageRawStatus(pending.id, 'failed'
|
|
454
|
+
await store.setMessageRawStatus(pending.id, 'failed', {
|
|
455
|
+
failureReason: details,
|
|
456
|
+
});
|
|
338
457
|
}
|
|
339
458
|
catch {
|
|
340
459
|
// ignore (e.g. record removed concurrently)
|
|
@@ -346,6 +465,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
346
465
|
// Preserve the original error message for the caller/UI.
|
|
347
466
|
throw new Error(details);
|
|
348
467
|
};
|
|
468
|
+
if (!pending.message) {
|
|
469
|
+
return await emitFailedAndPersist(`Message request ${pending.id} has an empty message.`);
|
|
470
|
+
}
|
|
349
471
|
const wallet = (await store.getWallets()).find((w) => w.partyId === pending.partyId);
|
|
350
472
|
if (!wallet) {
|
|
351
473
|
return await emitFailedAndPersist(`No wallet found for partyId ${pending.partyId} (from message request ${pending.id})`);
|
|
@@ -353,46 +475,157 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
353
475
|
if (wallet.publicKey !== pending.publicKey) {
|
|
354
476
|
return await emitFailedAndPersist(`Wallet public key changed for partyId ${pending.partyId}; refusing to sign message request ${pending.id}`);
|
|
355
477
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return await emitFailedAndPersist(`signMessage is only supported for ${SigningProvider.WALLET_KERNEL} wallets, got ${wallet.signingProviderId}`);
|
|
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}`);
|
|
359
480
|
}
|
|
360
|
-
const driver = drivers[
|
|
481
|
+
const driver = drivers[wallet.signingProviderId]?.controller(userId);
|
|
361
482
|
if (!driver) {
|
|
362
|
-
return await emitFailedAndPersist(
|
|
483
|
+
return await emitFailedAndPersist(`${wallet.signingProviderId} signing driver not available`);
|
|
363
484
|
}
|
|
364
485
|
const result = await driver.signMessage({
|
|
365
486
|
message: pending.message,
|
|
366
487
|
keyIdentifier: { publicKey: wallet.publicKey },
|
|
488
|
+
internalTxId: pending.id,
|
|
367
489
|
});
|
|
368
490
|
if (isRpcError(result)) {
|
|
369
|
-
await
|
|
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
|
+
});
|
|
370
502
|
notifier.emit('messageSignature', {
|
|
371
|
-
status: '
|
|
503
|
+
status: 'signed',
|
|
372
504
|
messageId: pending.id,
|
|
505
|
+
signature: result.signature,
|
|
373
506
|
});
|
|
374
|
-
|
|
507
|
+
return {
|
|
508
|
+
status: result.status,
|
|
509
|
+
signature: result.signature,
|
|
510
|
+
publicKey: wallet.publicKey,
|
|
511
|
+
...(result.txId && { externalTxId: result.txId }),
|
|
512
|
+
};
|
|
375
513
|
}
|
|
376
|
-
if (
|
|
377
|
-
await store.setMessageRawStatus(pending.id, '
|
|
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
|
+
});
|
|
378
528
|
notifier.emit('messageSignature', {
|
|
379
529
|
status: 'failed',
|
|
380
530
|
messageId: pending.id,
|
|
381
531
|
});
|
|
382
|
-
|
|
532
|
+
return {
|
|
533
|
+
publicKey: wallet.publicKey,
|
|
534
|
+
status: 'failed',
|
|
535
|
+
failureReason,
|
|
536
|
+
...(result.txId && { externalTxId: result.txId }),
|
|
537
|
+
};
|
|
383
538
|
}
|
|
384
|
-
await
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
539
|
+
return await emitFailedAndPersist(`Signing provider returned status: ${result.status} without a txId`);
|
|
540
|
+
},
|
|
541
|
+
getSignMessageStatus: async (params) => {
|
|
542
|
+
const message = await store.getMessageRaw(params.messageId);
|
|
543
|
+
if (!message) {
|
|
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,
|
|
392
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
|
+
}
|
|
393
626
|
return {
|
|
394
|
-
|
|
395
|
-
|
|
627
|
+
status: 'awaiting-signature',
|
|
628
|
+
externalTxId: message.externalTxId,
|
|
396
629
|
};
|
|
397
630
|
},
|
|
398
631
|
getMessageToSign: async (params) => {
|
|
@@ -415,6 +648,12 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
415
648
|
signedAt: message.signedAt.toISOString(),
|
|
416
649
|
}),
|
|
417
650
|
...(message.signature && { signature: message.signature }),
|
|
651
|
+
...(message.externalTxId && {
|
|
652
|
+
externalTxId: message.externalTxId,
|
|
653
|
+
}),
|
|
654
|
+
...(message.failureReason && {
|
|
655
|
+
failureReason: message.failureReason,
|
|
656
|
+
}),
|
|
418
657
|
},
|
|
419
658
|
};
|
|
420
659
|
},
|
|
@@ -435,6 +674,12 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
435
674
|
signedAt: message.signedAt.toISOString(),
|
|
436
675
|
}),
|
|
437
676
|
...(message.signature && { signature: message.signature }),
|
|
677
|
+
...(message.externalTxId && {
|
|
678
|
+
externalTxId: message.externalTxId,
|
|
679
|
+
}),
|
|
680
|
+
...(message.failureReason && {
|
|
681
|
+
failureReason: message.failureReason,
|
|
682
|
+
}),
|
|
438
683
|
})),
|
|
439
684
|
};
|
|
440
685
|
},
|
|
@@ -443,14 +688,25 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
443
688
|
if (!message) {
|
|
444
689
|
throw new Error(`Message signing request not found with id: ${params.messageId}`);
|
|
445
690
|
}
|
|
446
|
-
if (message.status !== 'pending'
|
|
447
|
-
|
|
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.`);
|
|
448
694
|
}
|
|
449
|
-
|
|
695
|
+
assertIsConnected(authContext);
|
|
696
|
+
const userId = authContext.userId;
|
|
450
697
|
if (message.userId !== userId) {
|
|
451
698
|
throw new Error(`Message signing request ${message.id} is not owned by user ${userId}`);
|
|
452
699
|
}
|
|
453
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
|
+
}
|
|
454
710
|
return null;
|
|
455
711
|
},
|
|
456
712
|
execute: async (executeParams) => {
|
|
@@ -464,32 +720,31 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
464
720
|
if (transaction === undefined) {
|
|
465
721
|
throw new Error('No transaction found');
|
|
466
722
|
}
|
|
467
|
-
|
|
468
|
-
const accessTokenProvider = AuthTokenProvider.fromToken(
|
|
723
|
+
assertIsConnected(authContext);
|
|
724
|
+
const accessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken);
|
|
469
725
|
if (network === undefined) {
|
|
470
726
|
throw new Error('No network session found');
|
|
471
727
|
}
|
|
472
|
-
const session = await store.getSession(
|
|
728
|
+
const session = await store.getSession(authContext.accessToken);
|
|
473
729
|
if (!session) {
|
|
474
730
|
throw new Error('No active session found');
|
|
475
731
|
}
|
|
476
732
|
const notifier = notificationService.getNotifier(session.id);
|
|
477
733
|
const ledgerClient = new LedgerClient({
|
|
478
734
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
479
|
-
logger,
|
|
480
735
|
accessTokenProvider,
|
|
481
736
|
});
|
|
482
|
-
const transactionService = new TransactionService(store,
|
|
737
|
+
const transactionService = new TransactionService(store, drivers, notifier, hashingSchemeVersion);
|
|
483
738
|
logDynamically(logger, 'executing transaction with params', {
|
|
484
739
|
info: { transactionId: executeParams.transactionId },
|
|
485
740
|
debug: {
|
|
486
741
|
executeParams,
|
|
487
742
|
transaction,
|
|
488
743
|
wallet,
|
|
489
|
-
userId:
|
|
744
|
+
userId: authContext.userId,
|
|
490
745
|
},
|
|
491
746
|
});
|
|
492
|
-
const response = await transactionService.execute(
|
|
747
|
+
const response = await transactionService.execute(authContext.userId, wallet, transaction, executeParams, ledgerClient, authContext, network);
|
|
493
748
|
logDynamically(logger, 'transaction executed with response', {
|
|
494
749
|
info: { transactionId: executeParams.transactionId },
|
|
495
750
|
debug: { response },
|
|
@@ -498,9 +753,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
498
753
|
},
|
|
499
754
|
addSession: async function (params) {
|
|
500
755
|
try {
|
|
501
|
-
|
|
502
|
-
const {
|
|
503
|
-
const newSessionId =
|
|
756
|
+
assertIsConnected(authContext);
|
|
757
|
+
const { accessToken } = authContext;
|
|
758
|
+
const newSessionId = crypto.randomUUID();
|
|
504
759
|
logger.info(`Adding session with ID ${newSessionId} for network ${params.networkId}`);
|
|
505
760
|
const network = await store.getNetwork(params.networkId);
|
|
506
761
|
const idp = await store.getIdp(network.identityProviderId);
|
|
@@ -509,35 +764,13 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
509
764
|
id: newSessionId,
|
|
510
765
|
origin: params.origin,
|
|
511
766
|
network: params.networkId,
|
|
512
|
-
accessToken:
|
|
767
|
+
accessToken: accessToken || '',
|
|
513
768
|
});
|
|
514
|
-
const notifier = notificationService.getNotifier(newSessionId);
|
|
515
769
|
const ledgerClient = new LedgerClient({
|
|
516
770
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
517
|
-
|
|
518
|
-
accessTokenProvider: AuthTokenProvider.fromToken(accessToken, logger),
|
|
771
|
+
accessTokenProvider: AuthTokenProvider.fromToken(accessToken),
|
|
519
772
|
});
|
|
520
|
-
const status = await
|
|
521
|
-
const statusEvent = {
|
|
522
|
-
provider: provider,
|
|
523
|
-
connection: {
|
|
524
|
-
isConnected: status.isConnected,
|
|
525
|
-
reason: status.reason ? status.reason : 'OK',
|
|
526
|
-
isNetworkConnected: status.isConnected,
|
|
527
|
-
networkReason: status.reason ? status.reason : 'OK',
|
|
528
|
-
},
|
|
529
|
-
network: {
|
|
530
|
-
networkId: network.id,
|
|
531
|
-
ledgerApi: network.ledgerApi.baseUrl,
|
|
532
|
-
accessToken: accessToken,
|
|
533
|
-
},
|
|
534
|
-
session: {
|
|
535
|
-
accessToken: accessToken,
|
|
536
|
-
userId: userId,
|
|
537
|
-
},
|
|
538
|
-
};
|
|
539
|
-
notifier.emit('statusChanged', statusEvent);
|
|
540
|
-
notifier.emit('connected', statusEvent);
|
|
773
|
+
const status = await emitSessionConnected(newSessionId, network, authContext, ledgerClient);
|
|
541
774
|
// Only bootstrap wallets the first time a session is created.
|
|
542
775
|
// Session creation must remain successful when the ledger or
|
|
543
776
|
// wallet synchronization is unavailable.
|
|
@@ -554,14 +787,14 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
554
787
|
if (!network.adminAuth) {
|
|
555
788
|
throw new Error('No admin auth configured');
|
|
556
789
|
}
|
|
557
|
-
const
|
|
790
|
+
const adminIdp = await getIdpForAuth(network, network.adminAuth);
|
|
791
|
+
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(adminIdp, network.adminAuth);
|
|
558
792
|
const partyAllocator = new PartyAllocationService({
|
|
559
793
|
synchronizerId: network.synchronizerId,
|
|
560
794
|
accessTokenProvider: adminAccessTokenProvider,
|
|
561
795
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
562
|
-
logger,
|
|
563
796
|
});
|
|
564
|
-
const service = new WalletSyncService(store, ledgerClient,
|
|
797
|
+
const service = new WalletSyncService(store, ledgerClient, authContext, logger, drivers, partyAllocator);
|
|
565
798
|
await service.syncWallets();
|
|
566
799
|
}
|
|
567
800
|
catch (error) {
|
|
@@ -621,8 +854,7 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
621
854
|
const network = await store.getNetwork(session.network);
|
|
622
855
|
const ledgerClient = new LedgerClient({
|
|
623
856
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
624
|
-
|
|
625
|
-
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken, logger),
|
|
857
|
+
accessTokenProvider: AuthTokenProvider.fromToken(authContext.accessToken),
|
|
626
858
|
});
|
|
627
859
|
const idp = await store.getIdp(network.identityProviderId);
|
|
628
860
|
const status = await networkStatus(ledgerClient);
|
|
@@ -647,21 +879,19 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
647
879
|
syncWallets: async function () {
|
|
648
880
|
const network = await store.getCurrentNetwork();
|
|
649
881
|
const { userId } = assertConnected(authContext);
|
|
650
|
-
const userAccessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken
|
|
651
|
-
const idp = await store.getIdp(network.identityProviderId);
|
|
882
|
+
const userAccessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken);
|
|
652
883
|
if (!network.adminAuth) {
|
|
653
884
|
throw new Error('No admin auth configured');
|
|
654
885
|
}
|
|
655
|
-
const
|
|
886
|
+
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
887
|
+
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
656
888
|
const partyAllocator = new PartyAllocationService({
|
|
657
889
|
synchronizerId: network.synchronizerId,
|
|
658
890
|
accessTokenProvider: adminAccessTokenProvider,
|
|
659
891
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
660
|
-
logger,
|
|
661
892
|
});
|
|
662
893
|
const userLedger = new LedgerClient({
|
|
663
894
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
664
|
-
logger,
|
|
665
895
|
accessTokenProvider: userAccessTokenProvider,
|
|
666
896
|
});
|
|
667
897
|
const service = new WalletSyncService(store, userLedger, authContext, logger, drivers, partyAllocator);
|
|
@@ -679,21 +909,19 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
679
909
|
isWalletSyncNeeded: async () => {
|
|
680
910
|
const network = await store.getCurrentNetwork();
|
|
681
911
|
assertConnected(authContext);
|
|
682
|
-
const userAccessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken
|
|
683
|
-
const idp = await store.getIdp(network.identityProviderId);
|
|
912
|
+
const userAccessTokenProvider = AuthTokenProvider.fromToken(authContext.accessToken);
|
|
684
913
|
if (!network.adminAuth) {
|
|
685
914
|
throw new Error('No admin auth configured');
|
|
686
915
|
}
|
|
687
|
-
const
|
|
916
|
+
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
917
|
+
const adminAccessTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
688
918
|
const partyAllocator = new PartyAllocationService({
|
|
689
919
|
synchronizerId: network.synchronizerId,
|
|
690
920
|
accessTokenProvider: adminAccessTokenProvider,
|
|
691
921
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
692
|
-
logger,
|
|
693
922
|
});
|
|
694
923
|
const userLedger = new LedgerClient({
|
|
695
924
|
baseUrl: new URL(network.ledgerApi.baseUrl),
|
|
696
|
-
logger,
|
|
697
925
|
accessTokenProvider: userAccessTokenProvider,
|
|
698
926
|
});
|
|
699
927
|
const service = new WalletSyncService(store, userLedger, authContext, logger, drivers, partyAllocator);
|
|
@@ -726,6 +954,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
726
954
|
...(transaction.externalTxId && {
|
|
727
955
|
externalTxId: transaction.externalTxId,
|
|
728
956
|
}),
|
|
957
|
+
...(transaction.failureReason && {
|
|
958
|
+
failureReason: transaction.failureReason,
|
|
959
|
+
}),
|
|
729
960
|
};
|
|
730
961
|
},
|
|
731
962
|
listTransactions: async function (params) {
|
|
@@ -753,6 +984,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
753
984
|
...(transaction.externalTxId && {
|
|
754
985
|
externalTxId: transaction.externalTxId,
|
|
755
986
|
}),
|
|
987
|
+
...(transaction.failureReason && {
|
|
988
|
+
failureReason: transaction.failureReason,
|
|
989
|
+
}),
|
|
756
990
|
}));
|
|
757
991
|
if (page.nextCursor === null) {
|
|
758
992
|
return { transactions: txs, count: txCount };
|
|
@@ -770,7 +1004,8 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
770
1004
|
if (!transaction) {
|
|
771
1005
|
throw new Error(`Transaction not found with id: ${params.transactionId}`);
|
|
772
1006
|
}
|
|
773
|
-
if (transaction.status !== 'pending'
|
|
1007
|
+
if (transaction.status !== 'pending' &&
|
|
1008
|
+
transaction.status !== 'awaiting-signature') {
|
|
774
1009
|
throw new Error(`Cannot delete transaction with status '${transaction.status}'. Only pending transactions can be deleted.`);
|
|
775
1010
|
}
|
|
776
1011
|
const session = await store.getSession(assertConnected(authContext).accessToken);
|
|
@@ -787,10 +1022,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
787
1022
|
generateApiKey: async (params) => {
|
|
788
1023
|
const userId = assertConnected(authContext).userId;
|
|
789
1024
|
const network = await store.getCurrentNetwork();
|
|
790
|
-
const apiKeyId =
|
|
791
|
-
const generatedApiKey =
|
|
792
|
-
const hashedApiKey =
|
|
793
|
-
.createHash('sha256')
|
|
1025
|
+
const apiKeyId = crypto.randomUUID();
|
|
1026
|
+
const generatedApiKey = randomBytes(32).toString('hex');
|
|
1027
|
+
const hashedApiKey = createHash('sha256')
|
|
794
1028
|
.update(generatedApiKey)
|
|
795
1029
|
.digest('hex');
|
|
796
1030
|
const storedApiKey = {
|
|
@@ -829,6 +1063,9 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
829
1063
|
await store.removeApiKey(params.id);
|
|
830
1064
|
return null;
|
|
831
1065
|
},
|
|
1066
|
+
listSigningProviders: async () => ({
|
|
1067
|
+
signingProviders: Object.keys(drivers),
|
|
1068
|
+
}),
|
|
832
1069
|
listSigningProviderKeys: async (params) => {
|
|
833
1070
|
return await getSigningProviderKeys(params);
|
|
834
1071
|
},
|
|
@@ -846,13 +1083,12 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
846
1083
|
if (!network.adminAuth) {
|
|
847
1084
|
throw new Error('No admin auth configured');
|
|
848
1085
|
}
|
|
849
|
-
const idp = await
|
|
850
|
-
const adminTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth
|
|
1086
|
+
const idp = await getIdpForAuth(network, network.adminAuth);
|
|
1087
|
+
const adminTokenProvider = AuthTokenProvider.fromGatewayConfig(idp, network.adminAuth);
|
|
851
1088
|
const partyAllocator = new PartyAllocationService({
|
|
852
1089
|
synchronizerId: network.synchronizerId,
|
|
853
1090
|
accessTokenProvider: adminTokenProvider,
|
|
854
1091
|
httpLedgerUrl: network.ledgerApi.baseUrl,
|
|
855
|
-
logger,
|
|
856
1092
|
});
|
|
857
1093
|
const normalizedKey = partyAllocator.normalizePublicKeyToBase64(publicKey);
|
|
858
1094
|
if (!normalizedKey) {
|
|
@@ -872,29 +1108,80 @@ export const userController = (kernelInfo, userUrl, store, notificationService,
|
|
|
872
1108
|
getWallet: async (params) => {
|
|
873
1109
|
return await store.getWallet(params.partyId);
|
|
874
1110
|
},
|
|
1111
|
+
getTransactionStatus: async (params) => {
|
|
1112
|
+
const tx = await store.getTransaction(params.transactionId);
|
|
1113
|
+
if (!tx)
|
|
1114
|
+
throw new Error(`Transaction with txId: ${params.transactionId} not found in store`);
|
|
1115
|
+
//no externalTxId means nothing sent to signing provider, so no need to poll
|
|
1116
|
+
if (!tx.externalTxId || tx.status !== 'awaiting-signature') {
|
|
1117
|
+
return {
|
|
1118
|
+
status: tx.status,
|
|
1119
|
+
...(tx.externalTxId && { externalTxId: tx.externalTxId }),
|
|
1120
|
+
...(tx.failureReason && {
|
|
1121
|
+
failureReason: tx.failureReason,
|
|
1122
|
+
}),
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
const wallet = params.partyId
|
|
1126
|
+
? (await store.getWallets()).find((x) => x.partyId === params.partyId)
|
|
1127
|
+
: await store.getPrimaryWallet();
|
|
1128
|
+
if (!wallet) {
|
|
1129
|
+
throw new Error(params.partyId
|
|
1130
|
+
? `No wallet found for partyId: ${params.partyId}`
|
|
1131
|
+
: `No primary wallet found`);
|
|
1132
|
+
}
|
|
1133
|
+
assertIsConnected(authContext);
|
|
1134
|
+
const session = await store.getSession(authContext.accessToken);
|
|
1135
|
+
if (!session) {
|
|
1136
|
+
throw new Error('No active session found');
|
|
1137
|
+
}
|
|
1138
|
+
const notifier = notificationService.getNotifier(session.id);
|
|
1139
|
+
const transactionService = new TransactionService(store, drivers, notifier, hashingSchemeVersion);
|
|
1140
|
+
const result = await transactionService.refreshTransaction(authContext, wallet, tx.id);
|
|
1141
|
+
logDynamically(logger, `refreshed transaction status`, {
|
|
1142
|
+
info: { transactionId: tx.id, status: result.status },
|
|
1143
|
+
debug: { result },
|
|
1144
|
+
});
|
|
1145
|
+
return result;
|
|
1146
|
+
},
|
|
875
1147
|
});
|
|
876
1148
|
};
|
|
877
1149
|
function toAuthDto(auth) {
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
1150
|
+
switch (auth.method) {
|
|
1151
|
+
case 'authorization_code':
|
|
1152
|
+
return {
|
|
1153
|
+
method: auth.method,
|
|
1154
|
+
audience: auth.audience,
|
|
1155
|
+
scope: auth.scope,
|
|
1156
|
+
clientId: auth.clientId,
|
|
1157
|
+
};
|
|
1158
|
+
case 'client_credentials':
|
|
1159
|
+
return {
|
|
1160
|
+
method: auth.method,
|
|
1161
|
+
...(auth.identityProviderId
|
|
1162
|
+
? { identityProviderId: auth.identityProviderId }
|
|
1163
|
+
: {}),
|
|
1164
|
+
audience: auth.audience,
|
|
1165
|
+
scope: auth.scope,
|
|
1166
|
+
clientId: auth.clientId,
|
|
1167
|
+
clientSecret: auth.clientSecret,
|
|
1168
|
+
};
|
|
1169
|
+
case 'self_signed':
|
|
1170
|
+
return {
|
|
1171
|
+
method: auth.method,
|
|
1172
|
+
audience: auth.audience,
|
|
1173
|
+
scope: auth.scope,
|
|
1174
|
+
clientId: auth.clientId,
|
|
1175
|
+
clientSecret: auth.clientSecret,
|
|
1176
|
+
issuer: auth.issuer,
|
|
1177
|
+
};
|
|
1178
|
+
case 'self_issued':
|
|
1179
|
+
return {
|
|
1180
|
+
method: auth.method,
|
|
1181
|
+
audience: auth.audience,
|
|
1182
|
+
scope: auth.scope,
|
|
1183
|
+
};
|
|
896
1184
|
}
|
|
897
|
-
return base;
|
|
898
1185
|
}
|
|
899
1186
|
function toNetworkDto(network) {
|
|
900
1187
|
return {
|
|
@@ -924,7 +1211,7 @@ function toPublicNetwork(network) {
|
|
|
924
1211
|
ledgerApi: network.ledgerApi.baseUrl,
|
|
925
1212
|
authMethod: auth.method,
|
|
926
1213
|
...(auth.method !== 'client_credentials' && {
|
|
927
|
-
clientId: auth.clientId,
|
|
1214
|
+
...('clientId' in auth ? { clientId: auth.clientId } : {}),
|
|
928
1215
|
scope: auth.scope,
|
|
929
1216
|
audience: auth.audience,
|
|
930
1217
|
}),
|