@canton-network/wallet-gateway-remote 1.11.1 → 1.11.3-backport.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.
@@ -1,4 +1,10 @@
1
1
  import type { NextFunction, Request, Response } from 'express';
2
2
  import { Logger } from 'pino';
3
+ /**
4
+ * Determines the level an error thrown from an RPC method should be logged
5
+ * at: `info` for an expected, client/business-caused rejection, `error` for
6
+ * an unexpected system fault (including anything we can't classify).
7
+ */
8
+ export declare const errorLogLevel: (error: unknown) => "info" | "error";
3
9
  export declare function errorHandler(logger: Logger, isApiPath: (path: string) => boolean): (err: unknown, req: Request, res: Response, next: NextFunction) => void;
4
10
  //# sourceMappingURL=errorHandler.d.ts.map
@@ -1 +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"}
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;AAwD7B;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,MAAM,GAAG,OAYvD,CAAA;AAgBD,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"}
@@ -2,6 +2,69 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { JsonRpcError, rpcErrors, toHttpErrorCode, } from '@canton-network/core-rpc-errors';
4
4
  import { jsonRpcResponse } from '@canton-network/core-rpc-transport';
5
+ import { isJsCantonError } from '@canton-network/core-ledger-client';
6
+ // Mirrors ErrorCategory.asInt from com.digitalasset.base.error (Canton's
7
+ // error category taxonomy). Kept in sync with that source rather than
8
+ // re-derived, since the numeric values are part of Canton's wire contract.
9
+ //
10
+ // view source at: https://github.com/digital-asset/canton/blob/2fcea1a4826fd63b6a9ea554c13cb685ae8f2ee2/base/errors/src/main/scala/com/digitalasset/base/error/ErrorCategory.scala#L1
11
+ var CantonErrorCategory;
12
+ (function (CantonErrorCategory) {
13
+ CantonErrorCategory[CantonErrorCategory["TransientServerFailure"] = 1] = "TransientServerFailure";
14
+ CantonErrorCategory[CantonErrorCategory["ContentionOnSharedResources"] = 2] = "ContentionOnSharedResources";
15
+ CantonErrorCategory[CantonErrorCategory["DeadlineExceededRequestStateUnknown"] = 3] = "DeadlineExceededRequestStateUnknown";
16
+ CantonErrorCategory[CantonErrorCategory["SystemInternalAssumptionViolated"] = 4] = "SystemInternalAssumptionViolated";
17
+ CantonErrorCategory[CantonErrorCategory["SecurityAlert"] = 5] = "SecurityAlert";
18
+ CantonErrorCategory[CantonErrorCategory["AuthInterceptorInvalidAuthenticationCredentials"] = 6] = "AuthInterceptorInvalidAuthenticationCredentials";
19
+ CantonErrorCategory[CantonErrorCategory["InsufficientPermission"] = 7] = "InsufficientPermission";
20
+ CantonErrorCategory[CantonErrorCategory["InvalidIndependentOfSystemState"] = 8] = "InvalidIndependentOfSystemState";
21
+ CantonErrorCategory[CantonErrorCategory["InvalidGivenCurrentSystemStateOther"] = 9] = "InvalidGivenCurrentSystemStateOther";
22
+ CantonErrorCategory[CantonErrorCategory["InvalidGivenCurrentSystemStateResourceExists"] = 10] = "InvalidGivenCurrentSystemStateResourceExists";
23
+ CantonErrorCategory[CantonErrorCategory["InvalidGivenCurrentSystemStateResourceMissing"] = 11] = "InvalidGivenCurrentSystemStateResourceMissing";
24
+ CantonErrorCategory[CantonErrorCategory["InvalidGivenCurrentSystemStateSeekAfterEnd"] = 12] = "InvalidGivenCurrentSystemStateSeekAfterEnd";
25
+ CantonErrorCategory[CantonErrorCategory["BackgroundProcessDegradationWarning"] = 13] = "BackgroundProcessDegradationWarning";
26
+ CantonErrorCategory[CantonErrorCategory["InternalUnsupportedOperation"] = 14] = "InternalUnsupportedOperation";
27
+ })(CantonErrorCategory || (CantonErrorCategory = {}));
28
+ // Canton error categories that Canton itself does not log at ERROR (see
29
+ // ErrorCategory.logLevel in com.digitalasset.base.error). Of the 14 defined
30
+ // categories, only SystemInternalAssumptionViolated and
31
+ // InternalUnsupportedOperation represent genuine system faults; the rest are
32
+ // expected client-, contention-, or state-dependent outcomes that Canton
33
+ // logs at INFO or WARN. We collapse Canton's INFO/WARN into our own `info`
34
+ // here, and treat anything outside this set (including category numbers we
35
+ // don't yet know about) as `error`.
36
+ const NON_CRITICAL_CANTON_ERROR_CATEGORIES = new Set([
37
+ CantonErrorCategory.TransientServerFailure,
38
+ CantonErrorCategory.ContentionOnSharedResources,
39
+ CantonErrorCategory.DeadlineExceededRequestStateUnknown,
40
+ CantonErrorCategory.SecurityAlert,
41
+ CantonErrorCategory.AuthInterceptorInvalidAuthenticationCredentials,
42
+ CantonErrorCategory.InsufficientPermission,
43
+ CantonErrorCategory.InvalidIndependentOfSystemState,
44
+ CantonErrorCategory.InvalidGivenCurrentSystemStateOther,
45
+ CantonErrorCategory.InvalidGivenCurrentSystemStateResourceExists,
46
+ CantonErrorCategory.InvalidGivenCurrentSystemStateResourceMissing,
47
+ CantonErrorCategory.InvalidGivenCurrentSystemStateSeekAfterEnd,
48
+ CantonErrorCategory.BackgroundProcessDegradationWarning,
49
+ // SystemInternalAssumptionViolated and InternalUnsupportedOperation are
50
+ // excluded - Canton logs both at ERROR as genuine system faults.
51
+ ]);
52
+ /**
53
+ * Determines the level an error thrown from an RPC method should be logged
54
+ * at: `info` for an expected, client/business-caused rejection, `error` for
55
+ * an unexpected system fault (including anything we can't classify).
56
+ */
57
+ export const errorLogLevel = (error) => {
58
+ if (error instanceof JsonRpcError) {
59
+ return toHttpErrorCode(error.code) < 500 ? 'info' : 'error';
60
+ }
61
+ if (isJsCantonError(error)) {
62
+ return NON_CRITICAL_CANTON_ERROR_CATEGORIES.has(error.errorCategory)
63
+ ? 'info'
64
+ : 'error';
65
+ }
66
+ return 'error';
67
+ };
5
68
  const isPayloadTooLargeError = (err) => {
6
69
  if (typeof err !== 'object' || err === null) {
7
70
  return false;
@@ -4,7 +4,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
4
4
  import { pino } from 'pino';
5
5
  import { sink } from 'pino-test';
6
6
  import { providerErrors, rpcErrors } from '@canton-network/core-rpc-errors';
7
- import { errorHandler } from './errorHandler.js';
7
+ import { errorHandler, errorLogLevel } from './errorHandler.js';
8
8
  describe('errorHandler', () => {
9
9
  const logger = pino({ level: 'silent' }, sink());
10
10
  const isApiPath = (path) => path.startsWith('/api/');
@@ -98,3 +98,41 @@ describe('errorHandler', () => {
98
98
  expect(json).not.toHaveBeenCalled();
99
99
  });
100
100
  });
101
+ describe('errorLogLevel', () => {
102
+ function makeJsCantonError(errorCategory) {
103
+ return {
104
+ code: 'DAML_FAILURE',
105
+ cause: 'some ledger rejection',
106
+ errorCategory,
107
+ };
108
+ }
109
+ it('logs client-caused JsonRpcErrors (HTTP < 500) at info', () => {
110
+ const err = rpcErrors.invalidParams({ message: 'bad params' });
111
+ expect(errorLogLevel(err)).toBe('info');
112
+ });
113
+ it('logs server-caused JsonRpcErrors (HTTP 500) at error', () => {
114
+ const err = rpcErrors.internal({ message: 'boom' });
115
+ expect(errorLogLevel(err)).toBe('error');
116
+ });
117
+ it('logs a JsCantonError in a non-alerting Canton category at info', () => {
118
+ // 9 = InvalidGivenCurrentSystemStateOther, e.g. a failed Daml
119
+ // `requirement`/assertion - an expected business rejection.
120
+ const err = makeJsCantonError(9);
121
+ expect(errorLogLevel(err)).toBe('info');
122
+ });
123
+ it('logs a JsCantonError in a system-fault Canton category at error', () => {
124
+ // 4 = SystemInternalAssumptionViolated - a genuine internal bug.
125
+ const err = makeJsCantonError(4);
126
+ expect(errorLogLevel(err)).toBe('error');
127
+ });
128
+ it('logs a JsCantonError with an unrecognized category at error', () => {
129
+ const err = makeJsCantonError(999);
130
+ expect(errorLogLevel(err)).toBe('error');
131
+ });
132
+ it('logs a plain Error at error', () => {
133
+ expect(errorLogLevel(new Error('boom'))).toBe('error');
134
+ });
135
+ it('logs an unrecognized error shape at error', () => {
136
+ expect(errorLogLevel({ foo: 'bar' })).toBe('error');
137
+ });
138
+ });
@@ -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;;;;;;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"}
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;AAKnC,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"}
@@ -4,6 +4,7 @@ import { JsonRpcError, rpcErrors, toHttpErrorCode, } from '@canton-network/core-
4
4
  import { ErrorResponse, JsonRpcRequest, } from '@canton-network/core-types';
5
5
  import { jsonRpcResponse } from '@canton-network/core-rpc-transport';
6
6
  import { isJsCantonError } from '@canton-network/core-ledger-client';
7
+ import { errorLogLevel } from './errorHandler.js';
7
8
  /**
8
9
  * Handles JSON-RPC errors and maps them to HTTP responses.
9
10
  * @param error The error that occurred.
@@ -105,7 +106,7 @@ export const jsonRpcHandler =
105
106
  .catch((error) => {
106
107
  const [status, response] = handleRpcError(error, id, method);
107
108
  // Full error with callstack in logs, sanitized version in response
108
- logger.error({ err: error, response }, 'RPC response: error with response');
109
+ logger[errorLogLevel(error)]({ err: error, response }, 'RPC response: error with response');
109
110
  res.status(status).json(response);
110
111
  });
111
112
  }
@@ -836,32 +836,6 @@ describe('userController', () => {
836
836
  networkId: 'network1',
837
837
  })).rejects.toThrow('Failed to add session');
838
838
  });
839
- it('addSession rejects token with client_id claim and auth.clientId mismatch', async () => {
840
- const authWithInvalidSubject = createAuthWithAddSessionClaims({
841
- client_id: 'wrong-client-id',
842
- });
843
- const store = await createStore(logger, authWithInvalidSubject, {
844
- withWallet: false,
845
- });
846
- const controller = createController(store, notificationService, logger, authWithInvalidSubject);
847
- await expect(controller.addSession({
848
- origin: 'dapp-1',
849
- networkId: 'network1',
850
- })).rejects.toThrow('Failed to add session');
851
- });
852
- it('addSession rejects token with azp claim and auth.clientId mismatch', async () => {
853
- const authWithInvalidSubject = createAuthWithAddSessionClaims({
854
- azp: 'wrong-client-id',
855
- });
856
- const store = await createStore(logger, authWithInvalidSubject, {
857
- withWallet: false,
858
- });
859
- const controller = createController(store, notificationService, logger, authWithInvalidSubject);
860
- await expect(controller.addSession({
861
- origin: 'dapp-1',
862
- networkId: 'network1',
863
- })).rejects.toThrow('Failed to add session');
864
- });
865
839
  it("addSession passes when token doesn't token have azp and client-id claims", async () => {
866
840
  const authWithInvalidSubject = createAuthWithAddSessionClaims();
867
841
  const store = await createStore(logger, authWithInvalidSubject, {
@@ -1 +1 @@
1
- {"version":3,"file":"token-network-matching.d.ts","sourceRoot":"","sources":["../../src/user-api/token-network-matching.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;AAe3D,wBAAgB,6BAA6B,CACzC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,GAAG,GACT,IAAI,CAsBN"}
1
+ {"version":3,"file":"token-network-matching.d.ts","sourceRoot":"","sources":["../../src/user-api/token-network-matching.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;AAe3D,wBAAgB,6BAA6B,CACzC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,GAAG,GACT,IAAI,CAcN"}
@@ -21,9 +21,4 @@ export function assertTokenClaimsMatchNetwork(accessToken, network, idp) {
21
21
  if (!tokenAudiences.includes(network.auth.audience)) {
22
22
  throw new Error(`Token aud claim doesn't match network's auth audience.`);
23
23
  }
24
- // check client ID based on `azp` (Authorized Party) claim or `client_id` claim, only if present.
25
- const tokenClientId = tokenClaims.azp || tokenClaims.client_id;
26
- if (tokenClientId && tokenClientId !== network.auth.clientId) {
27
- throw new Error(`Token client ID doesn't match network's auth clientId.`);
28
- }
29
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canton-network/wallet-gateway-remote",
3
- "version": "1.11.1",
3
+ "version": "1.11.3-backport.1",
4
4
  "type": "module",
5
5
  "description": "A server-side Wallet Gateway implementation over HTTP",
6
6
  "license": "Apache-2.0",
@@ -17,26 +17,26 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@canton-network/core-ledger-client": "^1.12.1",
21
- "@canton-network/core-rpc-errors": "^1.11.0",
22
- "@canton-network/core-rpc-transport": "^1.12.0",
23
- "@canton-network/core-signing-bitgo": "^1.2.0",
24
- "@canton-network/core-signing-blockdaemon": "^1.12.0",
25
- "@canton-network/core-signing-dfns": "^0.13.0",
26
- "@canton-network/core-signing-fireblocks": "^1.12.0",
27
- "@canton-network/core-signing-internal": "^1.13.1",
28
- "@canton-network/core-signing-lib": "^1.12.0",
29
- "@canton-network/core-signing-participant": "^1.12.1",
30
- "@canton-network/core-signing-securosys": "^0.4.0",
31
- "@canton-network/core-signing-store-sql": "1.13.1",
32
- "@canton-network/core-tx-visualizer": "^1.11.0",
33
- "@canton-network/core-types": "^1.12.0",
34
- "@canton-network/core-wallet-auth": "^1.12.0",
35
- "@canton-network/core-wallet-dapp-rpc-client": "^1.12.0",
36
- "@canton-network/core-wallet-store": "^1.13.0",
37
- "@canton-network/core-wallet-store-sql": "1.13.1",
38
- "@canton-network/core-wallet-ui-components": "^1.14.0",
39
- "@canton-network/core-wallet-user-rpc-client": "^1.13.0",
20
+ "@canton-network/core-ledger-client": "^1.12.2-backport.1",
21
+ "@canton-network/core-rpc-errors": "^1.11.1-backport.1",
22
+ "@canton-network/core-rpc-transport": "^1.12.1-backport.1",
23
+ "@canton-network/core-signing-bitgo": "^1.2.1-backport.1",
24
+ "@canton-network/core-signing-blockdaemon": "^1.12.1-backport.1",
25
+ "@canton-network/core-signing-dfns": "^0.13.1-backport.1",
26
+ "@canton-network/core-signing-fireblocks": "^1.12.1-backport.1",
27
+ "@canton-network/core-signing-internal": "^1.13.2-backport.1",
28
+ "@canton-network/core-signing-lib": "^1.12.1-backport.1",
29
+ "@canton-network/core-signing-participant": "^1.12.2-backport.1",
30
+ "@canton-network/core-signing-securosys": "^0.4.1-backport.1",
31
+ "@canton-network/core-signing-store-sql": "1.13.2-backport.1",
32
+ "@canton-network/core-tx-visualizer": "^1.11.1-backport.1",
33
+ "@canton-network/core-types": "^1.12.1-backport.1",
34
+ "@canton-network/core-wallet-auth": "^1.12.1-backport.1",
35
+ "@canton-network/core-wallet-dapp-rpc-client": "^1.12.1-backport.1",
36
+ "@canton-network/core-wallet-store": "^1.13.1-backport.1",
37
+ "@canton-network/core-wallet-store-sql": "1.13.2-backport.1",
38
+ "@canton-network/core-wallet-ui-components": "^1.14.1-backport.1",
39
+ "@canton-network/core-wallet-user-rpc-client": "^1.13.1-backport.1",
40
40
  "@commander-js/extra-typings": "^14.0.0",
41
41
  "@logtape/adaptor-pino": "^2.3.1",
42
42
  "@logtape/logtape": "^2.3.1",
@@ -56,7 +56,7 @@
56
56
  "zod": "^4.4.3"
57
57
  },
58
58
  "devDependencies": {
59
- "@canton-network/core-wallet-store-inmemory": "^1.14.0",
59
+ "@canton-network/core-wallet-store-inmemory": "^1.14.1-backport.1",
60
60
  "@open-wc/testing-helpers": "^3.0.1",
61
61
  "@types/cors": "^2.8.19",
62
62
  "@types/express": "^5.0.6",