@canton-network/wallet-gateway-remote 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/README.md +107 -31
  2. package/dist/auth/jwt-auth-service.d.ts.map +1 -1
  3. package/dist/auth/jwt-auth-service.js +164 -77
  4. package/dist/config/Config.d.ts +407 -24
  5. package/dist/config/Config.d.ts.map +1 -1
  6. package/dist/config/Config.js +146 -11
  7. package/dist/config/ConfigUtils.d.ts +16 -1
  8. package/dist/config/ConfigUtils.d.ts.map +1 -1
  9. package/dist/config/ConfigUtils.js +150 -60
  10. package/dist/dapp-api/controller.d.ts +13 -1
  11. package/dist/dapp-api/controller.d.ts.map +1 -1
  12. package/dist/dapp-api/controller.js +16 -20
  13. package/dist/dapp-api/rpc-gen/index.d.ts.map +1 -1
  14. package/dist/dapp-api/rpc-gen/typings.d.ts +33 -3
  15. package/dist/dapp-api/rpc-gen/typings.d.ts.map +1 -1
  16. package/dist/dapp-api/server.d.ts +10 -5
  17. package/dist/dapp-api/server.d.ts.map +1 -1
  18. package/dist/dapp-api/server.js +10 -3
  19. package/dist/dapp-api/sse-sink.d.ts.map +1 -1
  20. package/dist/env.d.ts +1 -24
  21. package/dist/env.d.ts.map +1 -1
  22. package/dist/env.js +0 -23
  23. package/dist/example-config.d.ts +94 -62
  24. package/dist/example-config.d.ts.map +1 -1
  25. package/dist/example-config.js +95 -61
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +82 -32
  29. package/dist/init.d.ts.map +1 -1
  30. package/dist/init.js +86 -127
  31. package/dist/ledger/party-allocation-service.d.ts +1 -4
  32. package/dist/ledger/party-allocation-service.d.ts.map +1 -1
  33. package/dist/ledger/party-allocation-service.js +1 -3
  34. package/dist/ledger/wallet-allocation/signing-providers/bitgo-wallet-allocator.d.ts.map +1 -1
  35. package/dist/ledger/wallet-allocation/signing-providers/bitgo-wallet-allocator.js +1 -1
  36. package/dist/ledger/wallet-allocation/signing-providers/blockdaemon-wallet-allocator.d.ts.map +1 -1
  37. package/dist/ledger/wallet-allocation/signing-providers/dfns-wallet-allocator.d.ts.map +1 -1
  38. package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.d.ts.map +1 -1
  39. package/dist/ledger/wallet-allocation/signing-providers/kernel-wallet-allocator.d.ts.map +1 -1
  40. package/dist/ledger/wallet-allocation/signing-providers/participant-wallet-allocator.d.ts.map +1 -1
  41. package/dist/ledger/wallet-allocation/signing-providers/securosys-wallet-allocator.d.ts.map +1 -1
  42. package/dist/ledger/wallet-allocation/wallet-allocation-service.d.ts +2 -2
  43. package/dist/ledger/wallet-allocation/wallet-allocation-service.d.ts.map +1 -1
  44. package/dist/ledger/wallet-allocation/wallet-allocation-service.js +2 -2
  45. package/dist/ledger/wallet-sync-service.d.ts +14 -1
  46. package/dist/ledger/wallet-sync-service.d.ts.map +1 -1
  47. package/dist/ledger/wallet-sync-service.js +240 -72
  48. package/dist/middleware/apiKeyAuth.d.ts.map +1 -1
  49. package/dist/middleware/apiKeyAuth.js +4 -8
  50. package/dist/middleware/errorHandler.d.ts +1 -1
  51. package/dist/middleware/errorHandler.d.ts.map +1 -1
  52. package/dist/middleware/jsonRpcHandler.d.ts.map +1 -1
  53. package/dist/middleware/jsonRpcHandler.js +3 -3
  54. package/dist/middleware/jwtAuth.d.ts +1 -1
  55. package/dist/middleware/jwtAuth.d.ts.map +1 -1
  56. package/dist/middleware/jwtAuth.js +17 -2
  57. package/dist/middleware/rateLimit.d.ts.map +1 -1
  58. package/dist/middleware/rateLimit.js +3 -9
  59. package/dist/middleware/securityHeaders.d.ts.map +1 -1
  60. package/dist/middleware/sessionHandler.d.ts +3 -3
  61. package/dist/middleware/sessionHandler.d.ts.map +1 -1
  62. package/dist/middleware/sessionHandler.js +8 -8
  63. package/dist/notices/server-notices.d.ts +24 -0
  64. package/dist/notices/server-notices.d.ts.map +1 -0
  65. package/dist/notices/server-notices.js +40 -0
  66. package/dist/notices/server-status-service.d.ts +11 -0
  67. package/dist/notices/server-status-service.d.ts.map +1 -0
  68. package/dist/notices/server-status-service.js +17 -0
  69. package/dist/signing/service-account-session.d.ts +16 -2
  70. package/dist/signing/service-account-session.d.ts.map +1 -1
  71. package/dist/signing/service-account-session.js +32 -1
  72. package/dist/signing-providers-registration.d.ts +7 -0
  73. package/dist/signing-providers-registration.d.ts.map +1 -0
  74. package/dist/signing-providers-registration.js +276 -0
  75. package/dist/user-api/controller.d.ts +25 -4
  76. package/dist/user-api/controller.d.ts.map +1 -1
  77. package/dist/user-api/controller.js +218 -235
  78. package/dist/user-api/rpc-gen/index.d.ts +27 -9
  79. package/dist/user-api/rpc-gen/index.d.ts.map +1 -1
  80. package/dist/user-api/rpc-gen/index.js +9 -3
  81. package/dist/user-api/rpc-gen/schemas.d.ts.map +1 -1
  82. package/dist/user-api/rpc-gen/schemas.js +86 -11
  83. package/dist/user-api/rpc-gen/typings.d.ts +158 -58
  84. package/dist/user-api/rpc-gen/typings.d.ts.map +1 -1
  85. package/dist/user-api/server.d.ts +7 -5
  86. package/dist/user-api/server.d.ts.map +1 -1
  87. package/dist/user-api/server.js +7 -2
  88. package/dist/web/frontend/404/index.html +3 -2
  89. package/dist/web/frontend/activities/index.html +4 -3
  90. package/dist/web/frontend/admin/index.html +16 -0
  91. package/dist/web/frontend/api-keys/add/index.html +3 -2
  92. package/dist/web/frontend/api-keys/index.html +3 -2
  93. package/dist/web/frontend/approve/index.html +4 -3
  94. package/dist/web/frontend/assets/404-N2p-H94F.js +5 -0
  95. package/dist/web/frontend/assets/activities-CIyMcvMq.js +71 -0
  96. package/dist/web/frontend/assets/addApiKey-DD_HxolC.js +92 -0
  97. package/dist/web/frontend/assets/addIdentityProvider-DNaST3bz.js +28 -0
  98. package/dist/web/frontend/assets/addNetwork-BwV-qK9L.js +38 -0
  99. package/dist/web/frontend/assets/addParty-DtBW1rpV.js +14 -0
  100. package/dist/web/frontend/assets/admin-CKAkdJym.js +53 -0
  101. package/dist/web/frontend/assets/apiKeys-CcnbBkNH.js +68 -0
  102. package/dist/web/frontend/assets/approve-33mo5eC8.js +27 -0
  103. package/dist/web/frontend/assets/callback-lKGXXz-1.js +7 -0
  104. package/dist/web/frontend/assets/common-DaUa4tUM.js +15 -0
  105. package/dist/web/frontend/assets/dist-BW5ACUmw.js +2 -0
  106. package/dist/web/frontend/assets/dist-CVv1nHd6.js +1 -0
  107. package/dist/web/frontend/assets/editParty-ZifjLzYx.js +15 -0
  108. package/dist/web/frontend/assets/frontend-Bs6UVmG1.js +4968 -0
  109. package/dist/web/frontend/assets/identityProviders-D5s7N-Ec.js +76 -0
  110. package/dist/web/frontend/assets/login-BAJsIB9G.js +11 -0
  111. package/dist/web/frontend/assets/networks-Do-zoG5E.js +78 -0
  112. package/dist/web/frontend/assets/parties-DFcN190b.js +51 -0
  113. package/dist/web/frontend/assets/reviewIdentityProvider-C2tsrpKc.js +43 -0
  114. package/dist/web/frontend/assets/reviewNetwork-BEGzls61.js +43 -0
  115. package/dist/web/frontend/assets/rolldown-runtime-pP25SEvz.js +1 -0
  116. package/dist/web/frontend/assets/selfIssuedLogin-a2KenO2P.js +112 -0
  117. package/dist/web/frontend/assets/signMessage-CQF0sCMe.js +23 -0
  118. package/dist/web/frontend/callback/index.html +3 -2
  119. package/dist/web/frontend/identity-providers/add/index.html +3 -2
  120. package/dist/web/frontend/identity-providers/index.html +3 -2
  121. package/dist/web/frontend/identity-providers/review/index.html +3 -2
  122. package/dist/web/frontend/index.html +2 -1
  123. package/dist/web/frontend/login/index.html +4 -11
  124. package/dist/web/frontend/networks/add/index.html +3 -2
  125. package/dist/web/frontend/networks/index.html +3 -2
  126. package/dist/web/frontend/networks/review/index.html +3 -2
  127. package/dist/web/frontend/parties/add/index.html +5 -5
  128. package/dist/web/frontend/parties/edit/index.html +5 -5
  129. package/dist/web/frontend/parties/index.html +4 -3
  130. package/dist/web/frontend/self-issued-login/index.html +16 -0
  131. package/dist/web/frontend/sign-message/index.html +3 -2
  132. package/dist/web/route-inputs.d.ts.map +1 -1
  133. package/dist/web/route-inputs.js +2 -1
  134. package/dist/web/server.d.ts.map +1 -1
  135. package/dist/web/server.js +1 -1
  136. package/package.json +53 -51
  137. package/dist/auth/jwt-auth-service.test.d.ts +0 -2
  138. package/dist/auth/jwt-auth-service.test.d.ts.map +0 -1
  139. package/dist/auth/jwt-auth-service.test.js +0 -659
  140. package/dist/config/Config.test.d.ts +0 -2
  141. package/dist/config/Config.test.d.ts.map +0 -1
  142. package/dist/config/Config.test.js +0 -26
  143. package/dist/dapp-api/controller.test.d.ts +0 -2
  144. package/dist/dapp-api/controller.test.d.ts.map +0 -1
  145. package/dist/dapp-api/controller.test.js +0 -531
  146. package/dist/dapp-api/server.test.d.ts +0 -2
  147. package/dist/dapp-api/server.test.d.ts.map +0 -1
  148. package/dist/dapp-api/server.test.js +0 -79
  149. package/dist/dapp-api/sse-sink.test.d.ts +0 -2
  150. package/dist/dapp-api/sse-sink.test.d.ts.map +0 -1
  151. package/dist/dapp-api/sse-sink.test.js +0 -30
  152. package/dist/ledger/party-allocation-service.test.d.ts +0 -2
  153. package/dist/ledger/party-allocation-service.test.d.ts.map +0 -1
  154. package/dist/ledger/party-allocation-service.test.js +0 -105
  155. package/dist/ledger/self-issued-auth-service.d.ts +0 -50
  156. package/dist/ledger/self-issued-auth-service.d.ts.map +0 -1
  157. package/dist/ledger/self-issued-auth-service.js +0 -263
  158. package/dist/ledger/self-issued-auth-service.test.d.ts +0 -2
  159. package/dist/ledger/self-issued-auth-service.test.d.ts.map +0 -1
  160. package/dist/ledger/self-issued-auth-service.test.js +0 -454
  161. package/dist/ledger/wallet-allocation/wallet-allocation-service.test.d.ts +0 -2
  162. package/dist/ledger/wallet-allocation/wallet-allocation-service.test.d.ts.map +0 -1
  163. package/dist/ledger/wallet-allocation/wallet-allocation-service.test.js +0 -1005
  164. package/dist/ledger/wallet-sync-service.test.d.ts +0 -2
  165. package/dist/ledger/wallet-sync-service.test.d.ts.map +0 -1
  166. package/dist/ledger/wallet-sync-service.test.js +0 -1017
  167. package/dist/middleware/apiKeyAuth.test.d.ts +0 -2
  168. package/dist/middleware/apiKeyAuth.test.d.ts.map +0 -1
  169. package/dist/middleware/apiKeyAuth.test.js +0 -126
  170. package/dist/middleware/errorHandler.test.d.ts +0 -2
  171. package/dist/middleware/errorHandler.test.d.ts.map +0 -1
  172. package/dist/middleware/errorHandler.test.js +0 -138
  173. package/dist/middleware/jsonRpcHandler.test.d.ts +0 -2
  174. package/dist/middleware/jsonRpcHandler.test.d.ts.map +0 -1
  175. package/dist/middleware/jsonRpcHandler.test.js +0 -377
  176. package/dist/middleware/jwtAuth.test.d.ts +0 -2
  177. package/dist/middleware/jwtAuth.test.d.ts.map +0 -1
  178. package/dist/middleware/jwtAuth.test.js +0 -100
  179. package/dist/middleware/rateLimit.test.d.ts +0 -2
  180. package/dist/middleware/rateLimit.test.d.ts.map +0 -1
  181. package/dist/middleware/rateLimit.test.js +0 -56
  182. package/dist/middleware/securityHeaders.test.d.ts +0 -2
  183. package/dist/middleware/securityHeaders.test.d.ts.map +0 -1
  184. package/dist/middleware/securityHeaders.test.js +0 -18
  185. package/dist/middleware/sessionHandler.test.d.ts +0 -2
  186. package/dist/middleware/sessionHandler.test.d.ts.map +0 -1
  187. package/dist/middleware/sessionHandler.test.js +0 -215
  188. package/dist/signing/service-account-session.test.d.ts +0 -2
  189. package/dist/signing/service-account-session.test.d.ts.map +0 -1
  190. package/dist/signing/service-account-session.test.js +0 -88
  191. package/dist/signing/signing-worker.d.ts +0 -86
  192. package/dist/signing/signing-worker.d.ts.map +0 -1
  193. package/dist/signing/signing-worker.js +0 -216
  194. package/dist/signing/signing-worker.test.d.ts +0 -2
  195. package/dist/signing/signing-worker.test.d.ts.map +0 -1
  196. package/dist/signing/signing-worker.test.js +0 -158
  197. package/dist/user-api/controller.test.d.ts +0 -2
  198. package/dist/user-api/controller.test.d.ts.map +0 -1
  199. package/dist/user-api/controller.test.js +0 -1228
  200. package/dist/user-api/server.test.d.ts +0 -2
  201. package/dist/user-api/server.test.d.ts.map +0 -1
  202. package/dist/user-api/server.test.js +0 -117
  203. package/dist/user-api/token-network-matching.test.d.ts +0 -2
  204. package/dist/user-api/token-network-matching.test.d.ts.map +0 -1
  205. package/dist/user-api/token-network-matching.test.js +0 -66
  206. package/dist/utils.test.d.ts +0 -2
  207. package/dist/utils.test.d.ts.map +0 -1
  208. package/dist/utils.test.js +0 -24
  209. package/dist/web/frontend/assets/404-B1XXXMXN.js +0 -5
  210. package/dist/web/frontend/assets/activities-HZnPjlMp.js +0 -61
  211. package/dist/web/frontend/assets/addApiKey-BvkCtUF3.js +0 -92
  212. package/dist/web/frontend/assets/addIdentityProvider-Dvjma837.js +0 -28
  213. package/dist/web/frontend/assets/addNetwork-Cahac0uo.js +0 -38
  214. package/dist/web/frontend/assets/addParty-Cdoed_Yx.js +0 -13
  215. package/dist/web/frontend/assets/apiKeys-BwV6ylWL.js +0 -68
  216. package/dist/web/frontend/assets/approve-B0nIfe2y.js +0 -26
  217. package/dist/web/frontend/assets/callback-BieW5Ux2.js +0 -7
  218. package/dist/web/frontend/assets/common-Bv9twGrA.js +0 -31
  219. package/dist/web/frontend/assets/editParty-OOjTHFay.js +0 -14
  220. package/dist/web/frontend/assets/identityProviders-BxJAq1Ne.js +0 -71
  221. package/dist/web/frontend/assets/index-Bo6MnlYI.js +0 -2
  222. package/dist/web/frontend/assets/index-CG_aFABR.js +0 -1
  223. package/dist/web/frontend/assets/index-D1Brmwbg.js +0 -93
  224. package/dist/web/frontend/assets/index-pMOoiNFq.js +0 -4887
  225. package/dist/web/frontend/assets/login-BHxgJEz_.js +0 -11
  226. package/dist/web/frontend/assets/networks-CBprjUF5.js +0 -73
  227. package/dist/web/frontend/assets/onboarding-ChmWs-TC.js +0 -84
  228. package/dist/web/frontend/assets/reviewIdentityProvider-CCmKgN8N.js +0 -43
  229. package/dist/web/frontend/assets/reviewNetwork-CX8Bmuf3.js +0 -43
  230. package/dist/web/frontend/assets/signMessage-BN_6S5FV.js +0 -79
  231. package/dist/web/frontend/onboarding/index.html +0 -23
  232. package/dist/web/route-inputs.test.d.ts +0 -2
  233. package/dist/web/route-inputs.test.d.ts.map +0 -1
  234. package/dist/web/route-inputs.test.js +0 -30
@@ -1,216 +0,0 @@
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 { resolveAutomationRunContext } from './service-account-session.js';
4
- import { TransactionService, } from '@canton-network/core-wallet-services';
5
- /**
6
- * Background poller that completes service-account transactions stuck in external
7
- * custody approval.
8
- *
9
- * ## When this runs
10
- *
11
- * During M2M automation (`prepareExecute` → `signAndExecute`), external signing
12
- * providers (Fireblocks, Blockdaemon, Dfns) may return `pending` instead of a
13
- * signature. The gateway persists the transaction with `status: 'pending'` and `status: 'awaiting-signature'` and
14
- * an `externalTxId` from the provider. This worker picks up those rows on each
15
- * tick via {@link Store.listAllPendingTransactions} (rows with an
16
- * `externalTxId` are processed; others are skipped).
17
- *
18
- * Participant and wallet-kernel sign synchronously and never appear here.
19
- *
20
- * ## What happens on each tick
21
- *
22
- * For every pending row the worker resolves an M2M auth context
23
- * ({@link resolveAutomationRunContext}), loads the user's primary wallet, and
24
- * calls {@link TransactionService.signAndExecute}.
25
- *
26
- * Although the worker always invokes `signAndExecute`, **retries do not submit a
27
- * new sign request**. `signAndExecute`branches on the stored transaction's status
28
- *
29
- * - **First pass** ( `pending`, no `externalTxId`): calls `sign()` which submits to singing provider
30
- * via `driver.signTransaction()` and stores the returned `externalTxId` with status `awaiting-signature`
31
- * - **Subsequent ticks** (`awaiting-signature` with `externalTxId` present): `refreshTransaction()`
32
- * which polls the existing requst via `driver.getTransaction()` and updated the stored status
33
- *
34
- * `sign()` initiates only and will throw for a transaction that already has an `externalTxId`
35
- *
36
- * `signAndExecute` then:
37
- *
38
- * - returns `{status: pending}` while provider still reports the request as awaiting approval
39
- * (worker logs and waits for the next tick), or
40
- * - calls `execute()` once provider reports `signed`. The signature is re-fetched from provider at
41
- * execution time rather than carried from the signing step.
42
- *
43
- * A transaction is re-read before processing so a concurrent DApp call or an
44
- * earlier tick that already completed it is skipped.
45
- *
46
- * Rows that reach `failed` (rejected by provider or by the ledger) are not retried and `failureReason` records why
47
- *
48
- * ## Lifecycle
49
- *
50
- * Started once at gateway init (`start()`). Ticks are serialized: if a tick is
51
- * still running, the next interval callback is a no-op. Use `stop()` on shutdown.
52
- */
53
- export class SigningWorker {
54
- constructor(options) {
55
- this.options = options;
56
- this.running = false;
57
- }
58
- /** Starts the interval timer. Idempotent if already started. */
59
- start() {
60
- this.options.logger.info('Starting signing worker');
61
- if (this.timer) {
62
- return;
63
- }
64
- this.timer = setInterval(() => {
65
- void this.tick();
66
- }, this.options.intervalMs);
67
- this.options.logger.info({ intervalMs: this.options.intervalMs }, 'Signing worker started');
68
- }
69
- /** Clears the interval timer. */
70
- stop() {
71
- if (this.timer) {
72
- clearInterval(this.timer);
73
- this.timer = undefined;
74
- }
75
- }
76
- /**
77
- * One poll cycle: list all pending transactions and attempt to complete
78
- * external-custody rows via {@link processPending}. Safe to call directly in
79
- * tests.
80
- */
81
- async tick() {
82
- this.options.logger.trace(`Signing worker: executing a tick`);
83
- if (this.running) {
84
- return;
85
- }
86
- this.running = true;
87
- try {
88
- const pending = await this.options.store.listAllPendingTransactions();
89
- for (const tx of pending) {
90
- if (!tx.externalTxId) {
91
- continue;
92
- }
93
- await this.processPending(tx);
94
- }
95
- }
96
- catch (error) {
97
- this.options.logger.error({ err: error }, 'Signing worker tick failed');
98
- }
99
- finally {
100
- this.running = false;
101
- }
102
- }
103
- /**
104
- * Drives a single pending transaction through `signAndExecute`. Skips when
105
- * automation context, submitting wallet, or refreshed `pending` status is missing.
106
- * Errors are logged per transaction; other rows in the same tick still run.
107
- */
108
- async processPending(transaction) {
109
- const logger = this.options.logger;
110
- const { userId, networkId, externalTxId } = transaction;
111
- if (!externalTxId || !userId || !networkId) {
112
- logger.debug({ transaction }, 'Skipping signing worker tick: missing required fields');
113
- return;
114
- }
115
- const runContext = await resolveAutomationRunContext(this.options.store, userId, networkId, logger);
116
- if (!runContext) {
117
- logger.debug({ runContext, transactionId: transaction.id }, 'Skipping signing worker tick: no run context');
118
- return;
119
- }
120
- const store = runContext.scopedStore;
121
- const wallet = await resolveWalletFromTransaction(transaction, store, logger);
122
- if (!wallet) {
123
- logger.warn({
124
- userId,
125
- networkId,
126
- transactionId: transaction.id,
127
- commandId: transaction.commandId,
128
- }, 'Skipping signing worker tick: could not deduce submitting wallet from transaction payload');
129
- return;
130
- }
131
- const refreshedTx = await store.getTransaction(transaction.id);
132
- if (!refreshedTx ||
133
- (refreshedTx.status !== 'pending' &&
134
- refreshedTx.status !== 'awaiting-signature')) {
135
- logger.debug({ refreshedTx }, 'Skipping signing worker tick: transaction no longer pending');
136
- return;
137
- }
138
- const session = await store.getSession(runContext.authContext.accessToken);
139
- if (!session) {
140
- logger.error({ userId, networkId, transactionId: transaction.id }, 'Signing worker tick failed: session not found');
141
- return;
142
- }
143
- const notifier = this.options.notificationService.getNotifier(session.id);
144
- const transactionLogger = this.options.logger.child({
145
- component: 'TransactionService',
146
- });
147
- const transactionService = new TransactionService(store, transactionLogger, this.options.signingDrivers, notifier, this.options.hashingSchemeVersion);
148
- try {
149
- const result = await transactionService.signAndExecute(runContext.authContext, runContext.network, wallet, refreshedTx);
150
- if ('status' in result && result.status === 'pending') {
151
- logger.info({
152
- userId,
153
- networkId,
154
- transactionId: transaction.id,
155
- commandId: transaction.commandId,
156
- externalTxId: result.externalTxId,
157
- signingProviderId: wallet.signingProviderId,
158
- }, 'Signing worker: transaction still awaiting external signing');
159
- }
160
- else {
161
- logger.info({
162
- userId,
163
- networkId,
164
- transactionId: transaction.id,
165
- commandId: transaction.commandId,
166
- externalTxId: transaction.externalTxId,
167
- partyId: wallet.partyId,
168
- signingProviderId: wallet.signingProviderId,
169
- result,
170
- }, 'Signing worker completed service account transaction');
171
- }
172
- }
173
- catch (error) {
174
- logger.error({
175
- err: error,
176
- userId,
177
- networkId,
178
- transactionId: transaction.id,
179
- commandId: transaction.commandId,
180
- externalTxId: transaction.externalTxId,
181
- partyId: wallet.partyId,
182
- signingProviderId: wallet.signingProviderId,
183
- }, 'Signing worker failed to complete service account transaction');
184
- }
185
- }
186
- }
187
- /**
188
- * Given the transaction, attempt to resolve the original wallet that submitted it.
189
- * It's not guaranteed that the primary wallet was used, so we check the `actAs` field in the payload and find a wallet with a matching party ID.
190
- *
191
- * Returns `undefined` if the wallet cannot be resolved.
192
- */
193
- async function resolveWalletFromTransaction(tx, store, logger) {
194
- logger.debug({ tx, store }, 'Resolving wallet from transaction payload');
195
- // first see if we can determine the wallet from the payload's actAs field.
196
- // If not, we will default to the primary wallet.
197
- let wallet = undefined;
198
- const payload = tx.payload;
199
- if (payload && typeof payload === 'object') {
200
- const actAs = payload.actAs;
201
- if (Array.isArray(actAs) && actAs.length !== 0) {
202
- if (actAs.length > 1) {
203
- logger.warn({ actAs }, 'Transaction has multiple acting parties; using the first one to resolve wallet');
204
- }
205
- const partyId = actAs[0];
206
- const wallets = await store.getAllWallets();
207
- wallet = wallets.find((wallet) => wallet.partyId === partyId);
208
- }
209
- }
210
- if (!wallet) {
211
- // No actAs was given: lets default to the primary party.
212
- wallet = await store.getPrimaryWallet();
213
- logger.debug({ wallet, tx }, 'Transaction has no actAs; using primary wallet');
214
- }
215
- return wallet;
216
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=signing-worker.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signing-worker.test.d.ts","sourceRoot":"","sources":["../../src/signing/signing-worker.test.ts"],"names":[],"mappings":""}
@@ -1,158 +0,0 @@
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 { describe, expect, it, vi } from 'vitest';
4
- import { pino } from 'pino';
5
- import { sink } from 'pino-test';
6
- import { SigningWorker } from './signing-worker.js';
7
- import { SigningProvider } from '@canton-network/core-signing-lib';
8
- const mocks = vi.hoisted(() => ({
9
- signAndExecute: vi.fn().mockResolvedValue({ commandId: 'cmd-1' }),
10
- }));
11
- vi.mock('@canton-network/core-wallet-auth', async () => {
12
- const actual = await vi.importActual('@canton-network/core-wallet-auth');
13
- return {
14
- ...actual,
15
- AuthTokenProvider: {
16
- fromGatewayConfig: vi.fn().mockReturnValue({
17
- getAuthContext: vi.fn().mockResolvedValue({
18
- userId: 'service_account',
19
- accessToken: 'abc',
20
- }),
21
- }),
22
- },
23
- };
24
- });
25
- vi.mock('@canton-network/core-wallet-services', async (importOriginal) => {
26
- const actual = await importOriginal();
27
- return {
28
- ...actual,
29
- TransactionService: vi.fn(function TransactionServiceMock() {
30
- return { signAndExecute: mocks.signAndExecute };
31
- }),
32
- };
33
- });
34
- const idp = {
35
- id: 'idp1',
36
- type: 'oauth',
37
- issuer: 'https://issuer.example',
38
- configUrl: 'https://issuer.example/.well-known/openid-configuration',
39
- };
40
- const m2mNetwork = {
41
- id: 'net-m2m',
42
- name: 'm2m',
43
- description: '',
44
- synchronizerId: 'sync::fp',
45
- identityProviderId: 'idp1',
46
- ledgerApi: { baseUrl: 'http://ledger' },
47
- auth: {
48
- method: 'authorization_code',
49
- clientId: 'user',
50
- audience: 'aud',
51
- scope: 'scope',
52
- },
53
- serviceAccountAuth: {
54
- method: 'client_credentials',
55
- clientId: 'svc',
56
- clientSecret: 'secret',
57
- audience: 'aud',
58
- scope: 'scope',
59
- },
60
- };
61
- const wallet = {
62
- primary: true,
63
- partyId: 'party::ns',
64
- status: 'allocated',
65
- hint: 'party',
66
- publicKey: 'pk',
67
- namespace: 'ns',
68
- networkId: 'net-m2m',
69
- signingProviderId: SigningProvider.FIREBLOCKS,
70
- rights: [],
71
- };
72
- const aliceWallet = {
73
- primary: false,
74
- partyId: 'alice::ns2',
75
- status: 'allocated',
76
- hint: 'alice',
77
- publicKey: 'pk2',
78
- namespace: 'ns2',
79
- networkId: 'net-m2m',
80
- signingProviderId: SigningProvider.FIREBLOCKS,
81
- rights: [],
82
- };
83
- const pendingTransaction = {
84
- id: 'tx-1',
85
- commandId: 'cmd-1',
86
- status: 'pending',
87
- preparedTransaction: 'blob',
88
- preparedTransactionHash: 'hash',
89
- externalTxId: 'ext-1',
90
- origin: null,
91
- userId: 'user-1',
92
- networkId: 'net-m2m',
93
- };
94
- function createWorker(storeOverrides = {}) {
95
- const scopedStore = {
96
- setSession: vi.fn().mockResolvedValue(undefined),
97
- getSession: vi.fn().mockResolvedValue({ id: 'session-1' }),
98
- getPrimaryWallet: vi.fn().mockResolvedValue(wallet),
99
- getAllWallets: vi.fn().mockResolvedValue([wallet, aliceWallet]),
100
- getTransaction: vi.fn().mockResolvedValue(pendingTransaction),
101
- };
102
- const store = {
103
- listAllPendingTransactions: vi
104
- .fn()
105
- .mockResolvedValue([pendingTransaction]),
106
- getIdp: vi.fn().mockResolvedValue(idp),
107
- getNetwork: vi.fn().mockResolvedValue(m2mNetwork),
108
- getSession: vi.fn().mockResolvedValue({ id: 'session-1' }),
109
- withAuthContext: vi.fn().mockReturnValue(scopedStore),
110
- ...storeOverrides,
111
- };
112
- const logger = pino({ level: 'silent' }, sink());
113
- return {
114
- worker: new SigningWorker({
115
- intervalMs: 1000,
116
- signingDrivers: {},
117
- store: store,
118
- notificationService: {
119
- getNotifier: vi.fn(() => ({ emit: vi.fn() })),
120
- },
121
- logger,
122
- hashingSchemeVersion: 'HASHING_SCHEME_VERSION_V3',
123
- }),
124
- store,
125
- scopedStore,
126
- };
127
- }
128
- describe('SigningWorker', () => {
129
- it('completes pending external transactions with a primary wallet', async () => {
130
- const { worker } = createWorker();
131
- await worker.tick();
132
- expect(mocks.signAndExecute.mock.calls[0][2].partyId).toBe('party::ns');
133
- });
134
- it('uses a non-primary wallet when actAs payload is present', async () => {
135
- const { worker } = createWorker({
136
- listAllPendingTransactions: vi.fn().mockResolvedValue([
137
- {
138
- ...pendingTransaction,
139
- payload: { actAs: ['alice::ns2'] },
140
- },
141
- ]),
142
- });
143
- await worker.tick();
144
- expect(mocks.signAndExecute).toHaveBeenCalledOnce();
145
- expect(mocks.signAndExecute.mock.calls[0][2].partyId).toBe('alice::ns2');
146
- });
147
- it('skips pending transactions without an externalTxId', async () => {
148
- const { worker } = createWorker({
149
- listAllPendingTransactions: vi
150
- .fn()
151
- .mockResolvedValue([
152
- { ...pendingTransaction, externalTxId: undefined },
153
- ]),
154
- });
155
- await worker.tick();
156
- expect(mocks.signAndExecute).not.toHaveBeenCalled();
157
- });
158
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=controller.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"controller.test.d.ts","sourceRoot":"","sources":["../../src/user-api/controller.test.ts"],"names":[],"mappings":""}