@canton-network/wallet-gateway-remote 1.10.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +17 -2
- package/dist/ledger/transaction-service.d.ts +2 -8
- package/dist/ledger/transaction-service.d.ts.map +1 -1
- package/dist/ledger/transaction-service.js +51 -474
- package/dist/ledger/transaction-service.test.js +26 -18
- 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 +5 -6
- package/dist/ledger/wallet-allocation/wallet-allocation-service.test.js +1 -1
- package/dist/middleware/errorHandler.d.ts +4 -0
- package/dist/middleware/errorHandler.d.ts.map +1 -0
- package/dist/middleware/errorHandler.js +46 -0
- package/dist/middleware/errorHandler.test.d.ts +2 -0
- package/dist/middleware/errorHandler.test.d.ts.map +1 -0
- package/dist/middleware/errorHandler.test.js +100 -0
- package/dist/middleware/jsonRpcHandler.d.ts +0 -1
- package/dist/middleware/jsonRpcHandler.d.ts.map +1 -1
- package/dist/middleware/jsonRpcHandler.js +7 -4
- package/dist/middleware/jsonRpcHandler.test.js +30 -7
- package/dist/middleware/jwtAuth.d.ts.map +1 -1
- package/dist/middleware/jwtAuth.js +9 -4
- package/dist/middleware/jwtAuth.test.js +14 -7
- package/dist/middleware/sessionHandler.d.ts +1 -1
- package/dist/middleware/sessionHandler.d.ts.map +1 -1
- package/dist/middleware/sessionHandler.js +28 -15
- package/dist/middleware/sessionHandler.test.js +35 -1
- package/dist/web/frontend/404/index.html +2 -2
- package/dist/web/frontend/activities/index.html +3 -3
- package/dist/web/frontend/approve/index.html +3 -3
- package/dist/web/frontend/assets/{404-DaA35RoG.js → 404-CPixqKLO.js} +1 -1
- package/dist/web/frontend/assets/{activities-CuMcxQVi.js → activities-CVPKYW17.js} +1 -1
- package/dist/web/frontend/assets/{addIdentityProvider-BYCAWtiZ.js → addIdentityProvider-nAJ-qcC5.js} +1 -1
- package/dist/web/frontend/assets/{addNetwork-DJM_nq3n.js → addNetwork-BneU5JY2.js} +1 -1
- package/dist/web/frontend/assets/addParty-GstM-rQp.js +13 -0
- package/dist/web/frontend/assets/{approve-4Xp3Ck4z.js → approve-CWUpB-cM.js} +1 -1
- package/dist/web/frontend/assets/{callback-DCYIq514.js → callback-DX4EJbNv.js} +1 -1
- package/dist/web/frontend/assets/common-JTjsyB1o.js +31 -0
- package/dist/web/frontend/assets/editParty-B-21AFFC.js +14 -0
- package/dist/web/frontend/assets/{identityProviders-1ro-4zy9.js → identityProviders-DFmAVYxV.js} +1 -1
- package/dist/web/frontend/assets/{index-BhzcMGYw.js → index-BAXYVraq.js} +1 -1
- package/dist/web/frontend/assets/index-Cvcr2Fng.js +2 -0
- package/dist/web/frontend/assets/{index-D-NXyb6u.js → index-Dp1svjp8.js} +1 -1
- package/dist/web/frontend/assets/{login-VCs39tyk.js → login-DuwXiFvJ.js} +1 -1
- package/dist/web/frontend/assets/{networks-CRTkFNGb.js → networks-Bh4iCMzi.js} +1 -1
- package/dist/web/frontend/assets/{reviewIdentityProvider-8F5_K-A5.js → reviewIdentityProvider-Bd7IWXao.js} +1 -1
- package/dist/web/frontend/assets/{reviewNetwork-DL-oQDwd.js → reviewNetwork-CPEZ1fzY.js} +1 -1
- package/dist/web/frontend/assets/{settings-DgRrnzuq.js → settings-BUUAYz6_.js} +1 -1
- package/dist/web/frontend/callback/index.html +2 -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 +2 -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 +4 -3
- package/dist/web/frontend/parties/edit/index.html +17 -0
- package/dist/web/frontend/parties/index.html +2 -2
- package/dist/web/frontend/settings/index.html +2 -2
- package/dist/web/server.d.ts +1 -1
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +3 -3
- package/package.json +27 -28
- package/dist/web/frontend/assets/addParty-SChbVsEF.js +0 -43
- package/dist/web/frontend/assets/index-BjhQnXf1.js +0 -2
|
@@ -53,6 +53,11 @@ const executeParams = {
|
|
|
53
53
|
signature: 'signature',
|
|
54
54
|
signedBy: wallet.namespace,
|
|
55
55
|
};
|
|
56
|
+
const postWithRetry = vi.fn().mockResolvedValue({ updateId: 'ledger-update-1' });
|
|
57
|
+
const ledgerClient = {
|
|
58
|
+
postWithRetry,
|
|
59
|
+
getSynchronizerId: vi.fn(),
|
|
60
|
+
};
|
|
56
61
|
const network = {
|
|
57
62
|
id: 'network1',
|
|
58
63
|
name: 'testnet',
|
|
@@ -89,6 +94,9 @@ function createStore(transaction = pendingTransaction) {
|
|
|
89
94
|
function createService(store, drivers, notifier, logger) {
|
|
90
95
|
return new TransactionService(store, logger, drivers, notifier, 'HASHING_SCHEME_VERSION_V3');
|
|
91
96
|
}
|
|
97
|
+
vi.stubGlobal('crypto', {
|
|
98
|
+
randomUUID: vi.fn().mockReturnValue('internal-tx-uuid'),
|
|
99
|
+
});
|
|
92
100
|
describe('TransactionService', () => {
|
|
93
101
|
let logger;
|
|
94
102
|
let notifier;
|
|
@@ -106,7 +114,13 @@ describe('TransactionService', () => {
|
|
|
106
114
|
it('returns a signed result and persists signed status', async () => {
|
|
107
115
|
const store = createStore();
|
|
108
116
|
const service = createService(store, {
|
|
109
|
-
[SigningProvider.PARTICIPANT]: createDriver({
|
|
117
|
+
[SigningProvider.PARTICIPANT]: createDriver({
|
|
118
|
+
signTransaction: vi.fn().mockResolvedValue({
|
|
119
|
+
status: 'signed',
|
|
120
|
+
signature: 'none',
|
|
121
|
+
signedBy: 'namespace',
|
|
122
|
+
}),
|
|
123
|
+
}),
|
|
110
124
|
}, notifier, logger);
|
|
111
125
|
const participantWallet = walletWithProvider(SigningProvider.PARTICIPANT);
|
|
112
126
|
const result = await service.sign(authContext, participantWallet, signParams);
|
|
@@ -117,7 +131,7 @@ describe('TransactionService', () => {
|
|
|
117
131
|
partyId: wallet.partyId,
|
|
118
132
|
});
|
|
119
133
|
expect(store.getTransaction).toHaveBeenCalledWith(pendingTransaction.id);
|
|
120
|
-
expect(store.setTransactionSigned).toHaveBeenCalledWith(pendingTransaction.id, expect.any(Date));
|
|
134
|
+
expect(store.setTransactionSigned).toHaveBeenCalledWith(pendingTransaction.id, expect.any(Date), undefined);
|
|
121
135
|
expect(emit).toHaveBeenCalledWith('txChanged', expect.objectContaining({
|
|
122
136
|
id: pendingTransaction.id,
|
|
123
137
|
status: 'signed',
|
|
@@ -126,9 +140,10 @@ describe('TransactionService', () => {
|
|
|
126
140
|
});
|
|
127
141
|
describe('wallet-kernel', () => {
|
|
128
142
|
it('signs the transaction and persists the signed state', async () => {
|
|
129
|
-
const signTransaction = vi
|
|
130
|
-
|
|
131
|
-
|
|
143
|
+
const signTransaction = vi.fn().mockResolvedValue({
|
|
144
|
+
status: 'signed',
|
|
145
|
+
signature: 'kernel-signature',
|
|
146
|
+
});
|
|
132
147
|
const store = createStore();
|
|
133
148
|
const service = createService(store, {
|
|
134
149
|
[SigningProvider.WALLET_KERNEL]: createDriver({
|
|
@@ -141,7 +156,7 @@ describe('TransactionService', () => {
|
|
|
141
156
|
txHash: pendingTransaction.preparedTransactionHash,
|
|
142
157
|
keyIdentifier: { publicKey: wallet.publicKey },
|
|
143
158
|
});
|
|
144
|
-
expect(store.setTransactionSigned).toHaveBeenCalledWith(pendingTransaction.id, expect.any(Date));
|
|
159
|
+
expect(store.setTransactionSigned).toHaveBeenCalledWith(pendingTransaction.id, expect.any(Date), undefined);
|
|
145
160
|
expect(emit).toHaveBeenCalledWith('txChanged', expect.objectContaining({
|
|
146
161
|
id: pendingTransaction.id,
|
|
147
162
|
status: 'signed',
|
|
@@ -239,11 +254,11 @@ describe('TransactionService', () => {
|
|
|
239
254
|
});
|
|
240
255
|
describe('fireblocks', () => {
|
|
241
256
|
it('returns a base64 signature when signing completes', async () => {
|
|
242
|
-
const
|
|
257
|
+
const signature = Buffer.from('fireblocks-signature').toString('base64');
|
|
243
258
|
const signTransaction = vi.fn().mockResolvedValue({
|
|
244
259
|
status: 'signed',
|
|
245
260
|
txId: 'fb-tx-1',
|
|
246
|
-
signature
|
|
261
|
+
signature,
|
|
247
262
|
});
|
|
248
263
|
const store = createStore();
|
|
249
264
|
const service = createService(store, {
|
|
@@ -254,11 +269,11 @@ describe('TransactionService', () => {
|
|
|
254
269
|
const result = await service.sign(authContext, walletWithProvider(SigningProvider.FIREBLOCKS), signParams);
|
|
255
270
|
expect(signTransaction).toHaveBeenCalledWith(expect.objectContaining({
|
|
256
271
|
userId: authContext.userId,
|
|
257
|
-
txHash:
|
|
272
|
+
txHash: 'tx-hash',
|
|
258
273
|
}));
|
|
259
274
|
expect(result).toMatchObject({
|
|
260
275
|
status: 'signed',
|
|
261
|
-
signature
|
|
276
|
+
signature,
|
|
262
277
|
externalTxId: 'fb-tx-1',
|
|
263
278
|
});
|
|
264
279
|
});
|
|
@@ -437,7 +452,7 @@ describe('TransactionService', () => {
|
|
|
437
452
|
...pendingTransaction,
|
|
438
453
|
status,
|
|
439
454
|
};
|
|
440
|
-
expect(() => service.execute(authContext.userId, wallet, transaction, executeParams)).toThrow(`Cannot execute a ${status} transaction. Expected status: signed.`);
|
|
455
|
+
expect(() => service.execute(authContext.userId, wallet, transaction, executeParams, ledgerClient)).toThrow(`Cannot execute a ${status} transaction. Expected status: signed.`);
|
|
441
456
|
});
|
|
442
457
|
describe('participant', () => {
|
|
443
458
|
it('submits the prepared transaction to the ledger', async () => {
|
|
@@ -450,13 +465,6 @@ describe('TransactionService', () => {
|
|
|
450
465
|
},
|
|
451
466
|
};
|
|
452
467
|
const store = createStore(transaction);
|
|
453
|
-
const postWithRetry = vi
|
|
454
|
-
.fn()
|
|
455
|
-
.mockResolvedValue({ updateId: 'ledger-update-1' });
|
|
456
|
-
const ledgerClient = {
|
|
457
|
-
postWithRetry,
|
|
458
|
-
getSynchronizerId: vi.fn(),
|
|
459
|
-
};
|
|
460
468
|
const service = createService(store, {}, notifier, logger);
|
|
461
469
|
const result = await service.execute(authContext.userId, participantWallet, transaction, executeParams, ledgerClient, network);
|
|
462
470
|
expect(postWithRetry).toHaveBeenCalledWith('/v2/commands/submit-and-wait', expect.objectContaining({
|
package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fireblocks-wallet-allocator.d.ts","sourceRoot":"","sources":["../../../../src/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AACzD,OAAO,EAAE,KAAK,EAAgB,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAC/E,OAAO,EACH,sBAAsB,EAEzB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAC1E,OAAO,EACH,OAAO,EACP,SAAS,EACT,OAAO,EACV,MAAM,sCAAsC,CAAA;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAGjE,qBAAa,yBAA0B,YAAW,eAAe;IAEzD,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,cAAc;IACtB,SAAS,CAAC,aAAa,EAAE,sBAAsB;gBAHvC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,sBAAsB,EACpC,aAAa,EAAE,sBAAsB;IAG7C,OAAO,CAAC,MAAM,EAAE,MAAM;IAMtB,YAAY,CACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,YAAQ,EACxB,OAAO,EAAE,OAAO,GACjB,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"fireblocks-wallet-allocator.d.ts","sourceRoot":"","sources":["../../../../src/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AACzD,OAAO,EAAE,KAAK,EAAgB,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAC/E,OAAO,EACH,sBAAsB,EAEzB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAC1E,OAAO,EACH,OAAO,EACP,SAAS,EACT,OAAO,EACV,MAAM,sCAAsC,CAAA;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAGjE,qBAAa,yBAA0B,YAAW,eAAe;IAEzD,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,cAAc;IACtB,SAAS,CAAC,aAAa,EAAE,sBAAsB;gBAHvC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,sBAAsB,EACpC,aAAa,EAAE,sBAAsB;IAG7C,OAAO,CAAC,MAAM,EAAE,MAAM;IAMtB,YAAY,CACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,YAAQ,EACxB,OAAO,EAAE,OAAO,GACjB,OAAO,CAAC,MAAM,CAAC;IA0FZ,aAAa,CACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,cAAc,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;CA+DnB"}
|
|
@@ -22,14 +22,13 @@ export class FireblocksWalletAllocator {
|
|
|
22
22
|
const key = keys?.keys?.find((k) => k.name === keyName);
|
|
23
23
|
if (!key)
|
|
24
24
|
throw new Error('Fireblocks key not found');
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const transactions = await this.partyAllocator.generateTopologyTransactions(partyHint, formattedPublicKey);
|
|
25
|
+
const namespace = this.partyAllocator.createFingerprintFromKey(key.publicKey);
|
|
26
|
+
const transactions = await this.partyAllocator.generateTopologyTransactions(partyHint, key.publicKey);
|
|
28
27
|
const topologyTransactions = transactions.topologyTransactions ?? [];
|
|
29
28
|
const { status, txId } = await driver
|
|
30
29
|
.signTransaction({
|
|
31
30
|
tx: '',
|
|
32
|
-
txHash:
|
|
31
|
+
txHash: transactions.multiHash,
|
|
33
32
|
keyIdentifier: {
|
|
34
33
|
publicKey: key.publicKey,
|
|
35
34
|
},
|
|
@@ -60,7 +59,7 @@ export class FireblocksWalletAllocator {
|
|
|
60
59
|
if (!signature) {
|
|
61
60
|
throw new Error('Transaction signed but no signature found in result');
|
|
62
61
|
}
|
|
63
|
-
const partyId = await this.partyAllocator.allocatePartyWithExistingWallet(namespace, topologyTransactions,
|
|
62
|
+
const partyId = await this.partyAllocator.allocatePartyWithExistingWallet(namespace, topologyTransactions, signature, userId);
|
|
64
63
|
wallet = {
|
|
65
64
|
...walletBase,
|
|
66
65
|
partyId,
|
|
@@ -108,7 +107,7 @@ export class FireblocksWalletAllocator {
|
|
|
108
107
|
if (!signature) {
|
|
109
108
|
throw new Error('Transaction signed but no signature found in result');
|
|
110
109
|
}
|
|
111
|
-
const partyId = await this.partyAllocator.allocatePartyWithExistingWallet(existingWallet.namespace, existingWallet.topologyTransactions.split(', '),
|
|
110
|
+
const partyId = await this.partyAllocator.allocatePartyWithExistingWallet(existingWallet.namespace, existingWallet.topologyTransactions.split(', '), signature, userId);
|
|
112
111
|
walletUpdate = {
|
|
113
112
|
...walletUpdate,
|
|
114
113
|
partyId,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
+
import { Logger } from 'pino';
|
|
3
|
+
export declare function errorHandler(logger: Logger, isApiPath: (path: string) => boolean): (err: unknown, req: Request, res: Response, next: NextFunction) => void;
|
|
4
|
+
//# sourceMappingURL=errorHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/middleware/errorHandler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAsB7B,wBAAgB,YAAY,CACxB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,IAGhC,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,KACnB,IAAI,CA0CV"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { JsonRpcError, rpcErrors, toHttpErrorCode, } from '@canton-network/core-rpc-errors';
|
|
4
|
+
import { jsonRpcResponse } from '@canton-network/core-rpc-transport';
|
|
5
|
+
const isPayloadTooLargeError = (err) => {
|
|
6
|
+
if (typeof err !== 'object' || err === null) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const { status, statusCode } = err;
|
|
10
|
+
return status === 413 || statusCode === 413;
|
|
11
|
+
};
|
|
12
|
+
// Catches unhandled errors and prevents internal details like stack trace from reaching end user
|
|
13
|
+
export function errorHandler(logger, isApiPath) {
|
|
14
|
+
return (err, req, res, next) => {
|
|
15
|
+
// Full error with stack goes to logs only.
|
|
16
|
+
logger.error({ err }, 'Unhandled request error');
|
|
17
|
+
// If the response has already started, we can't safely send an error response.
|
|
18
|
+
if (res.headersSent) {
|
|
19
|
+
next(err);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (isPayloadTooLargeError(err)) {
|
|
23
|
+
res.status(413).json({ error: 'Payload Too Large' });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// jsonRpcHandler already maps controllers errors via handleRpcError.
|
|
27
|
+
// This only runs for errors that escape earlier middlewares (e.g. auth/session checks).
|
|
28
|
+
if (isApiPath(req.path)) {
|
|
29
|
+
const id = req.body?.id ?? null;
|
|
30
|
+
if (err instanceof JsonRpcError) {
|
|
31
|
+
res.status(toHttpErrorCode(err.code)).json(jsonRpcResponse(id, {
|
|
32
|
+
error: { code: err.code, message: err.message },
|
|
33
|
+
}));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
res.status(500).json(jsonRpcResponse(id, {
|
|
37
|
+
error: {
|
|
38
|
+
code: rpcErrors.internal().code,
|
|
39
|
+
message: 'Something went wrong',
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
res.status(500).json({ error: 'Internal Server Error' });
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorHandler.test.d.ts","sourceRoot":"","sources":["../../src/middleware/errorHandler.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { pino } from 'pino';
|
|
5
|
+
import { sink } from 'pino-test';
|
|
6
|
+
import { providerErrors, rpcErrors } from '@canton-network/core-rpc-errors';
|
|
7
|
+
import { errorHandler } from './errorHandler.js';
|
|
8
|
+
describe('errorHandler', () => {
|
|
9
|
+
const logger = pino({ level: 'silent' }, sink());
|
|
10
|
+
const isApiPath = (path) => path.startsWith('/api/');
|
|
11
|
+
let next;
|
|
12
|
+
let status;
|
|
13
|
+
let json;
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
next = vi.fn();
|
|
16
|
+
status = vi.fn().mockReturnThis();
|
|
17
|
+
json = vi.fn();
|
|
18
|
+
});
|
|
19
|
+
function makeReq(partial = {}) {
|
|
20
|
+
return {
|
|
21
|
+
path: '/api/v0/user',
|
|
22
|
+
body: { id: 1 },
|
|
23
|
+
...partial,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function makeRes(headersSent = false) {
|
|
27
|
+
return { status, json, headersSent };
|
|
28
|
+
}
|
|
29
|
+
it('maps a JsonRpcError to its HTTP status and keeps the message', () => {
|
|
30
|
+
const err = providerErrors.unauthorized({
|
|
31
|
+
message: 'User is not connected',
|
|
32
|
+
});
|
|
33
|
+
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
34
|
+
expect(status).toHaveBeenCalledWith(401);
|
|
35
|
+
expect(json).toHaveBeenCalledWith({
|
|
36
|
+
jsonrpc: '2.0',
|
|
37
|
+
id: 1,
|
|
38
|
+
error: {
|
|
39
|
+
code: providerErrors.unauthorized().code,
|
|
40
|
+
message: 'User is not connected',
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it('replaces an unexpected error with a generic JSON-RPC 500 on API paths', () => {
|
|
45
|
+
const err = new Error('connect ECONNREFUSED 127.0.0.1:5432');
|
|
46
|
+
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
47
|
+
expect(status).toHaveBeenCalledWith(500);
|
|
48
|
+
expect(json).toHaveBeenCalledWith({
|
|
49
|
+
jsonrpc: '2.0',
|
|
50
|
+
id: 1,
|
|
51
|
+
error: {
|
|
52
|
+
code: rpcErrors.internal().code,
|
|
53
|
+
message: 'Something went wrong',
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
it('never sends the stack trace to the client', () => {
|
|
58
|
+
const err = new Error('internal detail');
|
|
59
|
+
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
60
|
+
const body = JSON.stringify(json.mock.calls[0][0]);
|
|
61
|
+
expect(body).not.toContain('internal detail');
|
|
62
|
+
expect(body).not.toContain('at '); // stack trace
|
|
63
|
+
});
|
|
64
|
+
it('keeps the 413 from express.json() for err.status', () => {
|
|
65
|
+
const err = Object.assign(new Error('request too large'), {
|
|
66
|
+
status: 413,
|
|
67
|
+
});
|
|
68
|
+
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
69
|
+
expect(status).toHaveBeenCalledWith(413);
|
|
70
|
+
expect(json).toHaveBeenCalledWith({ error: 'Payload Too Large' });
|
|
71
|
+
});
|
|
72
|
+
it('keeps the 413 from express.json() for err.statusCode', () => {
|
|
73
|
+
const err = Object.assign(new Error('request too large'), {
|
|
74
|
+
statusCode: 413,
|
|
75
|
+
});
|
|
76
|
+
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
77
|
+
expect(status).toHaveBeenCalledWith(413);
|
|
78
|
+
expect(json).toHaveBeenCalledWith({ error: 'Payload Too Large' });
|
|
79
|
+
});
|
|
80
|
+
it('leaves an error without a 413 status as a generic 500', () => {
|
|
81
|
+
const err = Object.assign(new Error('not a 413 error'), {
|
|
82
|
+
status: 404,
|
|
83
|
+
});
|
|
84
|
+
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(), next);
|
|
85
|
+
expect(status).toHaveBeenCalledWith(500);
|
|
86
|
+
});
|
|
87
|
+
it('returns a generic error body for non-API paths', () => {
|
|
88
|
+
const req = makeReq({ path: '/login' });
|
|
89
|
+
errorHandler(logger, isApiPath)(new Error('internal detail'), req, makeRes(), next);
|
|
90
|
+
expect(status).toHaveBeenCalledWith(500);
|
|
91
|
+
expect(json).toHaveBeenCalledWith({ error: 'Internal Server Error' });
|
|
92
|
+
});
|
|
93
|
+
it('delegates to express when the response has already started', () => {
|
|
94
|
+
const err = new Error('error that some middleware started res on, but still passed error down');
|
|
95
|
+
errorHandler(logger, isApiPath)(err, makeReq(), makeRes(true), next);
|
|
96
|
+
expect(next).toHaveBeenCalledWith(err);
|
|
97
|
+
expect(status).not.toHaveBeenCalled();
|
|
98
|
+
expect(json).not.toHaveBeenCalled();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -9,7 +9,6 @@ interface JsonRpcHttpOptions<T> {
|
|
|
9
9
|
* Handles JSON-RPC errors and maps them to HTTP responses.
|
|
10
10
|
* @param error The error that occurred.
|
|
11
11
|
* @param id The JSON-RPC request ID.
|
|
12
|
-
* @param logger The logger instance.
|
|
13
12
|
* @param method The name of the JSON-RPC method being called.
|
|
14
13
|
* @returns A tuple containing the HTTP status code and the JSON-RPC response.
|
|
15
14
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonRpcHandler.d.ts","sourceRoot":"","sources":["../../src/middleware/jsonRpcHandler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAM7B,OAAO,EAGH,eAAe,EAClB,MAAM,4BAA4B,CAAA;AAInC,UAAU,kBAAkB,CAAC,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,CAAC,CAAA;CAChB;AAED
|
|
1
|
+
{"version":3,"file":"jsonRpcHandler.d.ts","sourceRoot":"","sources":["../../src/middleware/jsonRpcHandler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAM7B,OAAO,EAGH,eAAe,EAClB,MAAM,4BAA4B,CAAA;AAInC,UAAU,kBAAkB,CAAC,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,CAAC,CAAA;CAChB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GACvB,OAAO,OAAO,EACd,IAAI,MAAM,GAAG,MAAM,GAAG,IAAI,EAC1B,SAAS,MAAM,KAChB,CAAC,MAAM,EAAE,eAAe,CAiD1B,CAAA;AAED,eAAO,MAAM,cAAc,GAEtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,kCAGjD,kBAAkB,CAAC,CAAC,CAAC,MAMZ,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,8CAiF1D,CAAA"}
|
|
@@ -8,7 +8,6 @@ import { isJsCantonError } from '@canton-network/core-ledger-client';
|
|
|
8
8
|
* Handles JSON-RPC errors and maps them to HTTP responses.
|
|
9
9
|
* @param error The error that occurred.
|
|
10
10
|
* @param id The JSON-RPC request ID.
|
|
11
|
-
* @param logger The logger instance.
|
|
12
11
|
* @param method The name of the JSON-RPC method being called.
|
|
13
12
|
* @returns A tuple containing the HTTP status code and the JSON-RPC response.
|
|
14
13
|
*/
|
|
@@ -20,11 +19,14 @@ export const handleRpcError = (error, id, method) => {
|
|
|
20
19
|
error: {
|
|
21
20
|
...rpcErrors.internal(),
|
|
22
21
|
message: genericMessage,
|
|
23
|
-
data: error,
|
|
24
22
|
},
|
|
25
23
|
};
|
|
26
24
|
if (error instanceof JsonRpcError) {
|
|
27
|
-
response.error =
|
|
25
|
+
response.error = {
|
|
26
|
+
code: error.code,
|
|
27
|
+
message: error.message,
|
|
28
|
+
data: error.data,
|
|
29
|
+
};
|
|
28
30
|
const httpCode = toHttpErrorCode(error.code);
|
|
29
31
|
return [httpCode, jsonRpcResponse(id, response)];
|
|
30
32
|
}
|
|
@@ -102,7 +104,8 @@ export const jsonRpcHandler =
|
|
|
102
104
|
})
|
|
103
105
|
.catch((error) => {
|
|
104
106
|
const [status, response] = handleRpcError(error, id, method);
|
|
105
|
-
|
|
107
|
+
// Full error with callstack in logs, sanitized version in response
|
|
108
|
+
logger.error({ err: error, response }, 'RPC response: error with response');
|
|
106
109
|
res.status(status).json(response);
|
|
107
110
|
});
|
|
108
111
|
}
|
|
@@ -182,23 +182,47 @@ describe('handleRpcError', () => {
|
|
|
182
182
|
expect(body).toEqual({
|
|
183
183
|
jsonrpc: '2.0',
|
|
184
184
|
id: 99,
|
|
185
|
-
error: err,
|
|
185
|
+
error: { code: err.code, message: 'bad' },
|
|
186
186
|
});
|
|
187
187
|
expect(errorLog).not.toHaveBeenCalled();
|
|
188
188
|
});
|
|
189
|
-
it('
|
|
189
|
+
it('keeps the JsonRpcError message once the response is serialised', () => {
|
|
190
|
+
const err = rpcErrors.invalidParams({ message: 'error description' });
|
|
191
|
+
const [, body] = handleRpcError(err, 99);
|
|
192
|
+
expect(JSON.parse(JSON.stringify(body))).toMatchObject({
|
|
193
|
+
error: { code: err.code, message: 'error description' },
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
it('forwards data that was deliberately attached to a JsonRpcError', () => {
|
|
197
|
+
const err = rpcErrors.invalidParams({
|
|
198
|
+
message: 'bad',
|
|
199
|
+
data: { field: 'value' },
|
|
200
|
+
});
|
|
201
|
+
const [, body] = handleRpcError(err, 1);
|
|
202
|
+
expect(errorPayload(body)).toMatchObject({ data: { field: 'value' } });
|
|
203
|
+
});
|
|
204
|
+
it('forwards the Error message but not the error object itself', () => {
|
|
190
205
|
const [status, body] = handleRpcError(new Error('some error'), 'id', 'submit');
|
|
191
206
|
expect(status).toBe(500);
|
|
192
207
|
expect(body).toEqual({
|
|
193
208
|
jsonrpc: '2.0',
|
|
194
209
|
id: 'id',
|
|
195
|
-
error:
|
|
210
|
+
error: {
|
|
196
211
|
code: rpcErrors.internal().code,
|
|
197
212
|
message: 'some error',
|
|
198
|
-
|
|
199
|
-
}),
|
|
213
|
+
},
|
|
200
214
|
});
|
|
201
215
|
});
|
|
216
|
+
it('does not leak enumerable properties of runtime errors', () => {
|
|
217
|
+
const dbError = Object.assign(new Error('connect ECONNREFUSED'), {
|
|
218
|
+
code: 'ECONNREFUSED',
|
|
219
|
+
address: '127.0.0.1',
|
|
220
|
+
port: 5432,
|
|
221
|
+
});
|
|
222
|
+
const [, body] = handleRpcError(dbError, 1, 'listWallets');
|
|
223
|
+
expect(errorPayload(body)).not.toHaveProperty('data');
|
|
224
|
+
expect(JSON.stringify(body)).not.toContain('5432');
|
|
225
|
+
});
|
|
202
226
|
it('uses generic message when method name is omitted', () => {
|
|
203
227
|
const [status, body] = handleRpcError(new Error('x'), null);
|
|
204
228
|
expect(status).toBe(500);
|
|
@@ -245,10 +269,9 @@ describe('handleRpcError', () => {
|
|
|
245
269
|
it('falls back to generic internal error for unknown payloads', () => {
|
|
246
270
|
const [status, body] = handleRpcError({ foo: 'bar' }, 2, 'wrongMethod');
|
|
247
271
|
expect(status).toBe(500);
|
|
248
|
-
expect(errorPayload(body)).
|
|
272
|
+
expect(errorPayload(body)).toEqual({
|
|
249
273
|
code: rpcErrors.internal().code,
|
|
250
274
|
message: 'Something went wrong while calling wrongMethod',
|
|
251
|
-
data: { foo: 'bar' },
|
|
252
275
|
});
|
|
253
276
|
});
|
|
254
277
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwtAuth.d.ts","sourceRoot":"","sources":["../../src/middleware/jwtAuth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"jwtAuth.d.ts","sourceRoot":"","sources":["../../src/middleware/jwtAuth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAG9D,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAE7B,wBAAgB,OAAO,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,IAC9C,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,mBA4BhE"}
|
|
@@ -1,5 +1,7 @@
|
|
|
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
|
+
import { providerErrors } from '@canton-network/core-rpc-errors';
|
|
4
|
+
import { jsonRpcResponse } from '@canton-network/core-rpc-transport';
|
|
3
5
|
export function jwtAuth(authService, logger) {
|
|
4
6
|
return async (req, res, next) => {
|
|
5
7
|
// If the request has been verified as an API key, skip JWT verification
|
|
@@ -15,11 +17,14 @@ export function jwtAuth(authService, logger) {
|
|
|
15
17
|
next();
|
|
16
18
|
}
|
|
17
19
|
catch (err) {
|
|
20
|
+
// Reason stays in the logs, the client sees the token was rejected.
|
|
18
21
|
logger.warn({ err }, 'JWT verification failed');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
res.status(401).json(jsonRpcResponse(req.body?.id ?? null, {
|
|
23
|
+
error: {
|
|
24
|
+
code: providerErrors.unauthorized().code,
|
|
25
|
+
message: 'Invalid or expired token',
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
23
28
|
}
|
|
24
29
|
};
|
|
25
30
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
4
4
|
import { jwtAuth } from './jwtAuth.js';
|
|
5
|
+
import { providerErrors } from '@canton-network/core-rpc-errors';
|
|
5
6
|
import { pino } from 'pino';
|
|
6
7
|
import { sink } from 'pino-test';
|
|
7
8
|
describe('jwtAuth', () => {
|
|
@@ -64,10 +65,11 @@ describe('jwtAuth', () => {
|
|
|
64
65
|
expect(req.authContext).toBeUndefined();
|
|
65
66
|
expect(next).toHaveBeenCalledOnce();
|
|
66
67
|
});
|
|
67
|
-
it('returns
|
|
68
|
+
it('returns a JSON-RPC 401 when verification throws', async () => {
|
|
68
69
|
verifyToken.mockRejectedValue(new Error('bad sig'));
|
|
69
70
|
const req = makeReq({
|
|
70
71
|
headers: { authorization: 'Bearer x' },
|
|
72
|
+
body: { id: 7 },
|
|
71
73
|
});
|
|
72
74
|
const res = makeRes();
|
|
73
75
|
const middleware = jwtAuth(authService, logger);
|
|
@@ -75,19 +77,24 @@ describe('jwtAuth', () => {
|
|
|
75
77
|
expect(next).not.toHaveBeenCalled();
|
|
76
78
|
expect(status).toHaveBeenCalledWith(401);
|
|
77
79
|
expect(json).toHaveBeenCalledWith({
|
|
78
|
-
|
|
80
|
+
jsonrpc: '2.0',
|
|
81
|
+
id: 7,
|
|
82
|
+
error: {
|
|
83
|
+
code: providerErrors.unauthorized().code,
|
|
84
|
+
message: 'Invalid or expired token',
|
|
85
|
+
},
|
|
79
86
|
});
|
|
80
87
|
});
|
|
81
|
-
it('
|
|
82
|
-
verifyToken.mockRejectedValue('
|
|
88
|
+
it('does not leak the underlying verification failure to the client', async () => {
|
|
89
|
+
verifyToken.mockRejectedValue(new Error('signature doesnt match the secret which is leaked-secret-123'));
|
|
83
90
|
const req = makeReq({
|
|
84
91
|
headers: { authorization: 'Bearer x' },
|
|
85
92
|
});
|
|
86
93
|
const res = makeRes();
|
|
87
94
|
const middleware = jwtAuth(authService, logger);
|
|
88
95
|
await middleware(req, res, next);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
const body = JSON.stringify(json.mock.calls[0][0]);
|
|
97
|
+
expect(body).not.toContain('leaked-secret-123');
|
|
98
|
+
expect(body).toContain('Invalid or expired token');
|
|
92
99
|
});
|
|
93
100
|
});
|
|
@@ -9,5 +9,5 @@ import { Store } from '@canton-network/core-wallet-store';
|
|
|
9
9
|
* @param logger
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
export declare function sessionHandler(store: Store & AuthAware<Store>, allowedPaths: Record<string, string[]>, logger: Logger): (req: Request, res: Response, next: NextFunction) => Promise<void
|
|
12
|
+
export declare function sessionHandler(store: Store & AuthAware<Store>, allowedPaths: Record<string, string[]>, logger: Logger): (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
13
13
|
//# sourceMappingURL=sessionHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionHandler.d.ts","sourceRoot":"","sources":["../../src/middleware/sessionHandler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"sessionHandler.d.ts","sourceRoot":"","sources":["../../src/middleware/sessionHandler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AAG5D,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAA;AAEzD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,EAC/B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EACtC,MAAM,EAAE,MAAM,IAEA,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,wDAsDhE"}
|
|
@@ -1,5 +1,7 @@
|
|
|
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
|
+
import { providerErrors } from '@canton-network/core-rpc-errors';
|
|
4
|
+
import { jsonRpcResponse } from '@canton-network/core-rpc-transport';
|
|
3
5
|
/**
|
|
4
6
|
* Middleware to handle session validation based on user sessions.
|
|
5
7
|
* @param store needs to be AuthAware
|
|
@@ -13,26 +15,37 @@ export function sessionHandler(store, allowedPaths, logger) {
|
|
|
13
15
|
const allowedMethods = allowedPaths[req.baseUrl];
|
|
14
16
|
if (req.method !== 'POST') {
|
|
15
17
|
logger.debug(`Skipping authentication for ${req.method} request to ${req.baseUrl}`);
|
|
16
|
-
next();
|
|
18
|
+
return next();
|
|
17
19
|
}
|
|
18
|
-
|
|
20
|
+
if (allowedMethods &&
|
|
19
21
|
(allowedMethods.includes(req.body.method) ||
|
|
20
22
|
allowedMethods.includes('*'))) {
|
|
21
23
|
logger.debug(`Allowing unauthenticated access to ${req.baseUrl} for method ${req.body.method}`);
|
|
22
|
-
next();
|
|
24
|
+
return next();
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
next();
|
|
35
|
-
}
|
|
26
|
+
const reqId = req.body?.id ?? null;
|
|
27
|
+
if (!context?.accessToken) {
|
|
28
|
+
logger.debug('No access token provided for protected method');
|
|
29
|
+
return res.status(401).json(jsonRpcResponse(reqId, {
|
|
30
|
+
error: {
|
|
31
|
+
code: providerErrors.unauthorized().code,
|
|
32
|
+
message: 'No active session found',
|
|
33
|
+
},
|
|
34
|
+
}));
|
|
36
35
|
}
|
|
36
|
+
logger.debug('Checking for active session for ' + context.userId);
|
|
37
|
+
const session = await store
|
|
38
|
+
.withAuthContext(context)
|
|
39
|
+
.getSession(context.accessToken);
|
|
40
|
+
if (!session) {
|
|
41
|
+
logger.debug('No active session found for ' + context.userId);
|
|
42
|
+
return res.status(401).json(jsonRpcResponse(reqId, {
|
|
43
|
+
error: {
|
|
44
|
+
code: providerErrors.unauthorized().code,
|
|
45
|
+
message: 'No active session found',
|
|
46
|
+
},
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
next();
|
|
37
50
|
};
|
|
38
51
|
}
|