@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.
- package/README.md +107 -31
- package/dist/auth/jwt-auth-service.d.ts.map +1 -1
- package/dist/auth/jwt-auth-service.js +164 -77
- package/dist/config/Config.d.ts +407 -24
- package/dist/config/Config.d.ts.map +1 -1
- package/dist/config/Config.js +146 -11
- package/dist/config/ConfigUtils.d.ts +16 -1
- package/dist/config/ConfigUtils.d.ts.map +1 -1
- package/dist/config/ConfigUtils.js +150 -60
- package/dist/dapp-api/controller.d.ts +13 -1
- package/dist/dapp-api/controller.d.ts.map +1 -1
- package/dist/dapp-api/controller.js +16 -20
- package/dist/dapp-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/dapp-api/rpc-gen/typings.d.ts +33 -3
- package/dist/dapp-api/rpc-gen/typings.d.ts.map +1 -1
- package/dist/dapp-api/server.d.ts +10 -5
- package/dist/dapp-api/server.d.ts.map +1 -1
- package/dist/dapp-api/server.js +10 -3
- package/dist/dapp-api/sse-sink.d.ts.map +1 -1
- package/dist/env.d.ts +1 -24
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +0 -23
- package/dist/example-config.d.ts +94 -62
- package/dist/example-config.d.ts.map +1 -1
- package/dist/example-config.js +95 -61
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -32
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +86 -127
- package/dist/ledger/party-allocation-service.d.ts +1 -4
- package/dist/ledger/party-allocation-service.d.ts.map +1 -1
- package/dist/ledger/party-allocation-service.js +1 -3
- 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.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/dfns-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/fireblocks-wallet-allocator.d.ts.map +1 -1
- package/dist/ledger/wallet-allocation/signing-providers/kernel-wallet-allocator.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/ledger/wallet-allocation/wallet-allocation-service.d.ts +2 -2
- 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 +14 -1
- package/dist/ledger/wallet-sync-service.d.ts.map +1 -1
- package/dist/ledger/wallet-sync-service.js +240 -72
- package/dist/middleware/apiKeyAuth.d.ts.map +1 -1
- package/dist/middleware/apiKeyAuth.js +4 -8
- package/dist/middleware/errorHandler.d.ts +1 -1
- package/dist/middleware/errorHandler.d.ts.map +1 -1
- package/dist/middleware/jsonRpcHandler.d.ts.map +1 -1
- package/dist/middleware/jsonRpcHandler.js +3 -3
- package/dist/middleware/jwtAuth.d.ts +1 -1
- package/dist/middleware/jwtAuth.d.ts.map +1 -1
- package/dist/middleware/jwtAuth.js +17 -2
- package/dist/middleware/rateLimit.d.ts.map +1 -1
- package/dist/middleware/rateLimit.js +3 -9
- package/dist/middleware/securityHeaders.d.ts.map +1 -1
- package/dist/middleware/sessionHandler.d.ts +3 -3
- package/dist/middleware/sessionHandler.d.ts.map +1 -1
- package/dist/middleware/sessionHandler.js +8 -8
- package/dist/notices/server-notices.d.ts +24 -0
- package/dist/notices/server-notices.d.ts.map +1 -0
- package/dist/notices/server-notices.js +40 -0
- package/dist/notices/server-status-service.d.ts +11 -0
- package/dist/notices/server-status-service.d.ts.map +1 -0
- package/dist/notices/server-status-service.js +17 -0
- package/dist/signing/service-account-session.d.ts +16 -2
- package/dist/signing/service-account-session.d.ts.map +1 -1
- package/dist/signing/service-account-session.js +32 -1
- package/dist/signing-providers-registration.d.ts +7 -0
- package/dist/signing-providers-registration.d.ts.map +1 -0
- package/dist/signing-providers-registration.js +276 -0
- package/dist/user-api/controller.d.ts +25 -4
- package/dist/user-api/controller.d.ts.map +1 -1
- package/dist/user-api/controller.js +218 -235
- package/dist/user-api/rpc-gen/index.d.ts +27 -9
- package/dist/user-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/user-api/rpc-gen/index.js +9 -3
- package/dist/user-api/rpc-gen/schemas.d.ts.map +1 -1
- package/dist/user-api/rpc-gen/schemas.js +86 -11
- package/dist/user-api/rpc-gen/typings.d.ts +158 -58
- package/dist/user-api/rpc-gen/typings.d.ts.map +1 -1
- package/dist/user-api/server.d.ts +7 -5
- package/dist/user-api/server.d.ts.map +1 -1
- package/dist/user-api/server.js +7 -2
- package/dist/web/frontend/404/index.html +3 -2
- package/dist/web/frontend/activities/index.html +4 -3
- package/dist/web/frontend/admin/index.html +16 -0
- package/dist/web/frontend/api-keys/add/index.html +3 -2
- package/dist/web/frontend/api-keys/index.html +3 -2
- package/dist/web/frontend/approve/index.html +4 -3
- package/dist/web/frontend/assets/404-N2p-H94F.js +5 -0
- package/dist/web/frontend/assets/activities-CIyMcvMq.js +71 -0
- package/dist/web/frontend/assets/addApiKey-DD_HxolC.js +92 -0
- package/dist/web/frontend/assets/addIdentityProvider-DNaST3bz.js +28 -0
- package/dist/web/frontend/assets/addNetwork-BwV-qK9L.js +38 -0
- package/dist/web/frontend/assets/addParty-DtBW1rpV.js +14 -0
- package/dist/web/frontend/assets/admin-CKAkdJym.js +53 -0
- package/dist/web/frontend/assets/apiKeys-CcnbBkNH.js +68 -0
- package/dist/web/frontend/assets/approve-33mo5eC8.js +27 -0
- package/dist/web/frontend/assets/callback-lKGXXz-1.js +7 -0
- package/dist/web/frontend/assets/common-DaUa4tUM.js +15 -0
- package/dist/web/frontend/assets/dist-BW5ACUmw.js +2 -0
- package/dist/web/frontend/assets/dist-CVv1nHd6.js +1 -0
- package/dist/web/frontend/assets/editParty-ZifjLzYx.js +15 -0
- package/dist/web/frontend/assets/frontend-Bs6UVmG1.js +4968 -0
- package/dist/web/frontend/assets/identityProviders-D5s7N-Ec.js +76 -0
- package/dist/web/frontend/assets/login-BAJsIB9G.js +11 -0
- package/dist/web/frontend/assets/networks-Do-zoG5E.js +78 -0
- package/dist/web/frontend/assets/parties-DFcN190b.js +51 -0
- package/dist/web/frontend/assets/reviewIdentityProvider-C2tsrpKc.js +43 -0
- package/dist/web/frontend/assets/reviewNetwork-BEGzls61.js +43 -0
- package/dist/web/frontend/assets/rolldown-runtime-pP25SEvz.js +1 -0
- package/dist/web/frontend/assets/selfIssuedLogin-a2KenO2P.js +112 -0
- package/dist/web/frontend/assets/signMessage-CQF0sCMe.js +23 -0
- package/dist/web/frontend/callback/index.html +3 -2
- package/dist/web/frontend/identity-providers/add/index.html +3 -2
- package/dist/web/frontend/identity-providers/index.html +3 -2
- package/dist/web/frontend/identity-providers/review/index.html +3 -2
- package/dist/web/frontend/index.html +2 -1
- package/dist/web/frontend/login/index.html +4 -11
- package/dist/web/frontend/networks/add/index.html +3 -2
- package/dist/web/frontend/networks/index.html +3 -2
- package/dist/web/frontend/networks/review/index.html +3 -2
- package/dist/web/frontend/parties/add/index.html +5 -5
- package/dist/web/frontend/parties/edit/index.html +5 -5
- package/dist/web/frontend/parties/index.html +4 -3
- package/dist/web/frontend/self-issued-login/index.html +16 -0
- package/dist/web/frontend/sign-message/index.html +3 -2
- package/dist/web/route-inputs.d.ts.map +1 -1
- package/dist/web/route-inputs.js +2 -1
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +1 -1
- package/package.json +53 -51
- 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 -659
- 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 -26
- 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 -531
- 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 -79
- package/dist/dapp-api/sse-sink.test.d.ts +0 -2
- package/dist/dapp-api/sse-sink.test.d.ts.map +0 -1
- package/dist/dapp-api/sse-sink.test.js +0 -30
- 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/self-issued-auth-service.d.ts +0 -50
- package/dist/ledger/self-issued-auth-service.d.ts.map +0 -1
- package/dist/ledger/self-issued-auth-service.js +0 -263
- package/dist/ledger/self-issued-auth-service.test.d.ts +0 -2
- package/dist/ledger/self-issued-auth-service.test.d.ts.map +0 -1
- package/dist/ledger/self-issued-auth-service.test.js +0 -454
- 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 -1017
- 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 -138
- 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 -377
- 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 -215
- 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 -88
- package/dist/signing/signing-worker.d.ts +0 -86
- package/dist/signing/signing-worker.d.ts.map +0 -1
- package/dist/signing/signing-worker.js +0 -216
- 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 -158
- 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 -1228
- 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 -117
- 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/404-B1XXXMXN.js +0 -5
- package/dist/web/frontend/assets/activities-HZnPjlMp.js +0 -61
- package/dist/web/frontend/assets/addApiKey-BvkCtUF3.js +0 -92
- package/dist/web/frontend/assets/addIdentityProvider-Dvjma837.js +0 -28
- package/dist/web/frontend/assets/addNetwork-Cahac0uo.js +0 -38
- package/dist/web/frontend/assets/addParty-Cdoed_Yx.js +0 -13
- package/dist/web/frontend/assets/apiKeys-BwV6ylWL.js +0 -68
- package/dist/web/frontend/assets/approve-B0nIfe2y.js +0 -26
- package/dist/web/frontend/assets/callback-BieW5Ux2.js +0 -7
- package/dist/web/frontend/assets/common-Bv9twGrA.js +0 -31
- package/dist/web/frontend/assets/editParty-OOjTHFay.js +0 -14
- package/dist/web/frontend/assets/identityProviders-BxJAq1Ne.js +0 -71
- package/dist/web/frontend/assets/index-Bo6MnlYI.js +0 -2
- package/dist/web/frontend/assets/index-CG_aFABR.js +0 -1
- package/dist/web/frontend/assets/index-D1Brmwbg.js +0 -93
- package/dist/web/frontend/assets/index-pMOoiNFq.js +0 -4887
- package/dist/web/frontend/assets/login-BHxgJEz_.js +0 -11
- package/dist/web/frontend/assets/networks-CBprjUF5.js +0 -73
- package/dist/web/frontend/assets/onboarding-ChmWs-TC.js +0 -84
- package/dist/web/frontend/assets/reviewIdentityProvider-CCmKgN8N.js +0 -43
- package/dist/web/frontend/assets/reviewNetwork-CX8Bmuf3.js +0 -43
- package/dist/web/frontend/assets/signMessage-BN_6S5FV.js +0 -79
- package/dist/web/frontend/onboarding/index.html +0 -23
- 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,1017 +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 { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
4
|
-
import { pino } from 'pino';
|
|
5
|
-
import { sink } from 'pino-test';
|
|
6
|
-
import { SigningProvider, } from '@canton-network/core-signing-lib';
|
|
7
|
-
import { InternalSigningDriver } from '@canton-network/core-signing-internal';
|
|
8
|
-
import { ParticipantSigningDriver } from '@canton-network/core-signing-participant';
|
|
9
|
-
import { StoreSql, connection, migrator, } from '@canton-network/core-signing-store-sql';
|
|
10
|
-
import { PartyLevelRight, UserLevelRight, } from '@canton-network/core-wallet-store';
|
|
11
|
-
import { StoreInternal } from '@canton-network/core-wallet-store-inmemory';
|
|
12
|
-
import { WALLET_DISABLED_REASON } from '@canton-network/core-types';
|
|
13
|
-
import { WalletSyncService } from './wallet-sync-service.js';
|
|
14
|
-
import { PartyAllocationService } from './party-allocation-service.js';
|
|
15
|
-
import { getLogger } from '@logtape/logtape';
|
|
16
|
-
const { mockLedgerGet } = vi.hoisted(() => ({
|
|
17
|
-
mockLedgerGet: vi.fn(),
|
|
18
|
-
}));
|
|
19
|
-
vi.mock('@canton-network/core-ledger-client', () => ({
|
|
20
|
-
LedgerClient: vi.fn(function LedgerClientMock() {
|
|
21
|
-
return {
|
|
22
|
-
getWithRetry: mockLedgerGet,
|
|
23
|
-
};
|
|
24
|
-
}),
|
|
25
|
-
defaultRetryableOptions: {},
|
|
26
|
-
}));
|
|
27
|
-
// Test subclass to expose protected method
|
|
28
|
-
class TestableWalletSyncService extends WalletSyncService {
|
|
29
|
-
async resolveSigningProvider(partyNamespace, participantNamespace) {
|
|
30
|
-
return super.resolveSigningProvider(partyNamespace, participantNamespace);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const testATP = (user, token) => ({
|
|
34
|
-
getAccessToken: async () => token,
|
|
35
|
-
getAuthContext: async () => ({
|
|
36
|
-
userId: user,
|
|
37
|
-
accessToken: token,
|
|
38
|
-
}),
|
|
39
|
-
});
|
|
40
|
-
describe('WalletSyncService - resolveSigningProvider', () => {
|
|
41
|
-
const authContext = {
|
|
42
|
-
userId: 'test-user-id',
|
|
43
|
-
accessToken: 'test-access-token',
|
|
44
|
-
};
|
|
45
|
-
let mockLogger;
|
|
46
|
-
let store;
|
|
47
|
-
let ledgerClient;
|
|
48
|
-
let partyAllocator;
|
|
49
|
-
let service;
|
|
50
|
-
beforeEach(async () => {
|
|
51
|
-
mockLogger = pino(sink());
|
|
52
|
-
// Create in-memory SQLite store for InternalSigningDriver
|
|
53
|
-
const db = connection({
|
|
54
|
-
connection: {
|
|
55
|
-
type: 'sqlite',
|
|
56
|
-
database: ':memory:',
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
const umzug = migrator(db);
|
|
60
|
-
const pending = await umzug.pending();
|
|
61
|
-
if (pending.length > 0) {
|
|
62
|
-
await umzug.up();
|
|
63
|
-
}
|
|
64
|
-
const signingStore = new StoreSql(db, mockLogger, authContext);
|
|
65
|
-
// Create real InternalSigningDriver with real store
|
|
66
|
-
const internalDriver = new InternalSigningDriver(signingStore);
|
|
67
|
-
// Store is not used in resolveSigningProvider tests
|
|
68
|
-
store = {};
|
|
69
|
-
// Create real PartyAllocationService
|
|
70
|
-
partyAllocator = new PartyAllocationService({
|
|
71
|
-
synchronizerId: 'test-sync-id',
|
|
72
|
-
accessTokenProvider: testATP('admin', 'admin.jwt'),
|
|
73
|
-
httpLedgerUrl: 'http://test',
|
|
74
|
-
logger: mockLogger,
|
|
75
|
-
});
|
|
76
|
-
// Create mocked ledger client (whole module is already mocked)
|
|
77
|
-
const ledgerModule = await import('@canton-network/core-ledger-client');
|
|
78
|
-
ledgerClient = new ledgerModule.LedgerClient({
|
|
79
|
-
baseUrl: new URL('http://test'),
|
|
80
|
-
logger: mockLogger,
|
|
81
|
-
accessTokenProvider: testATP('token', 'token'),
|
|
82
|
-
});
|
|
83
|
-
// Create service with real drivers
|
|
84
|
-
service = new TestableWalletSyncService(store, ledgerClient, authContext, mockLogger, {
|
|
85
|
-
[SigningProvider.WALLET_KERNEL]: internalDriver,
|
|
86
|
-
[SigningProvider.PARTICIPANT]: new ParticipantSigningDriver(),
|
|
87
|
-
}, partyAllocator);
|
|
88
|
-
});
|
|
89
|
-
afterEach(() => {
|
|
90
|
-
vi.restoreAllMocks();
|
|
91
|
-
mockLedgerGet.mockClear();
|
|
92
|
-
});
|
|
93
|
-
it('resolves participant when namespace matches participant namespace', async () => {
|
|
94
|
-
const participantNamespace = 'participant-namespace-123';
|
|
95
|
-
const result = await service.resolveSigningProvider(participantNamespace, participantNamespace);
|
|
96
|
-
expect(result).not.toBeNull();
|
|
97
|
-
expect(result).toEqual({
|
|
98
|
-
matched: true,
|
|
99
|
-
signingProviderId: SigningProvider.PARTICIPANT,
|
|
100
|
-
});
|
|
101
|
-
if (result) {
|
|
102
|
-
expect('publicKey' in result).toBe(false);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
it('resolves wallet-kernel when namespace matches internal key', async () => {
|
|
106
|
-
const internalDriver = service['signingDrivers'][SigningProvider.WALLET_KERNEL];
|
|
107
|
-
const controller = internalDriver.controller(authContext.userId);
|
|
108
|
-
const key = await controller.createKey({ name: 'test-key' });
|
|
109
|
-
if ('error' in key) {
|
|
110
|
-
throw new Error(`Failed to create key in test: ${key.error_description}`);
|
|
111
|
-
}
|
|
112
|
-
const namespace = partyAllocator.createFingerprintFromKey(key.publicKey);
|
|
113
|
-
const differentParticipantNamespace = 'different-participant-namespace';
|
|
114
|
-
const result = await service.resolveSigningProvider(namespace, differentParticipantNamespace);
|
|
115
|
-
expect(result).not.toBeNull();
|
|
116
|
-
if (result) {
|
|
117
|
-
expect(result.signingProviderId).toBe(SigningProvider.WALLET_KERNEL);
|
|
118
|
-
if (result.signingProviderId !== SigningProvider.PARTICIPANT) {
|
|
119
|
-
expect(result.publicKey).toBe(key.publicKey);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
it('resolves fireblocks when namespace matches fireblocks key', async () => {
|
|
124
|
-
const fireblocksPublicKeyHex = '02fefbcc9aebc8a479f211167a9f564df53aefd603a8662d9449a98c1ead2eba';
|
|
125
|
-
// Convert hex to base64, then calculate namespace
|
|
126
|
-
const normalizedKey = partyAllocator.normalizePublicKeyToBase64(fireblocksPublicKeyHex);
|
|
127
|
-
const namespace = partyAllocator.createFingerprintFromKey(normalizedKey);
|
|
128
|
-
const mockFireblocksDriver = {
|
|
129
|
-
controller: vi.fn().mockReturnValue({
|
|
130
|
-
getKeys: vi
|
|
131
|
-
.fn()
|
|
132
|
-
.mockResolvedValue({
|
|
133
|
-
keys: [
|
|
134
|
-
{
|
|
135
|
-
id: '44-6767-1-0-0',
|
|
136
|
-
name: 'test-vault',
|
|
137
|
-
publicKey: fireblocksPublicKeyHex,
|
|
138
|
-
},
|
|
139
|
-
],
|
|
140
|
-
}),
|
|
141
|
-
}),
|
|
142
|
-
partyMode: 'EXTERNAL',
|
|
143
|
-
signingProvider: SigningProvider.FIREBLOCKS,
|
|
144
|
-
};
|
|
145
|
-
const serviceWithFireblocks = new TestableWalletSyncService(store, ledgerClient, authContext, mockLogger, {
|
|
146
|
-
[SigningProvider.FIREBLOCKS]: mockFireblocksDriver,
|
|
147
|
-
}, partyAllocator);
|
|
148
|
-
const differentParticipantNamespace = 'different-participant-namespace';
|
|
149
|
-
const result = await serviceWithFireblocks.resolveSigningProvider(namespace, differentParticipantNamespace);
|
|
150
|
-
expect(result).not.toBeNull();
|
|
151
|
-
if (result) {
|
|
152
|
-
expect(result.signingProviderId).toBe(SigningProvider.FIREBLOCKS);
|
|
153
|
-
if (result.signingProviderId !== SigningProvider.PARTICIPANT) {
|
|
154
|
-
expect(result.publicKey).toBe(fireblocksPublicKeyHex);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
it('returns unmatched and defaults to participant when no signing provider match is found', async () => {
|
|
159
|
-
const unknownNamespace = 'unknown-namespace-123';
|
|
160
|
-
const differentParticipantNamespace = 'different-participant-namespace';
|
|
161
|
-
const result = await service.resolveSigningProvider(unknownNamespace, differentParticipantNamespace);
|
|
162
|
-
expect(result).toEqual({
|
|
163
|
-
matched: false,
|
|
164
|
-
signingProviderId: SigningProvider.PARTICIPANT,
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
describe('WalletSyncService - multi-network features', () => {
|
|
169
|
-
const authContext = {
|
|
170
|
-
userId: 'test-user-id',
|
|
171
|
-
accessToken: 'test-access-token',
|
|
172
|
-
};
|
|
173
|
-
let mockLogger;
|
|
174
|
-
let store;
|
|
175
|
-
let mockLedgerClient;
|
|
176
|
-
let partyAllocator;
|
|
177
|
-
let service;
|
|
178
|
-
const createNetwork = (id) => ({
|
|
179
|
-
id,
|
|
180
|
-
name: `Network ${id}`,
|
|
181
|
-
synchronizerId: `${id}-sync`,
|
|
182
|
-
identityProviderId: 'idp1',
|
|
183
|
-
description: `Test Network ${id}`,
|
|
184
|
-
ledgerApi: { baseUrl: `http://${id}` },
|
|
185
|
-
auth: {
|
|
186
|
-
method: 'authorization_code',
|
|
187
|
-
clientId: 'cid',
|
|
188
|
-
scope: 'scope',
|
|
189
|
-
audience: 'aud',
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
const createWallet = (partyId, networkId, disabled = false, status = 'allocated') => ({
|
|
193
|
-
primary: false,
|
|
194
|
-
partyId,
|
|
195
|
-
status,
|
|
196
|
-
hint: partyId.split('::')[0],
|
|
197
|
-
signingProviderId: 'internal',
|
|
198
|
-
publicKey: 'publicKey',
|
|
199
|
-
namespace: 'namespace',
|
|
200
|
-
networkId,
|
|
201
|
-
userId: 'user-1',
|
|
202
|
-
disabled,
|
|
203
|
-
rights: [PartyLevelRight.CanActAs],
|
|
204
|
-
});
|
|
205
|
-
const setSession = async (networkId) => {
|
|
206
|
-
await store.setSession({
|
|
207
|
-
id: `sess-${networkId}`,
|
|
208
|
-
origin: 'dapp-1',
|
|
209
|
-
network: networkId,
|
|
210
|
-
accessToken: 'test-access-token',
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
beforeEach(async () => {
|
|
214
|
-
mockLogger = pino(sink());
|
|
215
|
-
store = new StoreInternal({
|
|
216
|
-
idps: [],
|
|
217
|
-
networks: [],
|
|
218
|
-
}, getLogger('mock'), authContext);
|
|
219
|
-
// Add a default IdP that tests can use (use updateIdp to avoid errors if it already exists)
|
|
220
|
-
try {
|
|
221
|
-
await store.addIdp({
|
|
222
|
-
id: 'idp1',
|
|
223
|
-
type: 'oauth',
|
|
224
|
-
issuer: 'http://auth',
|
|
225
|
-
configUrl: 'http://auth/.well-known/openid-configuration',
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
catch {
|
|
229
|
-
// IdP might already exist from previous test, use updateIdp instead
|
|
230
|
-
await store.updateIdp({
|
|
231
|
-
id: 'idp1',
|
|
232
|
-
type: 'oauth',
|
|
233
|
-
issuer: 'http://auth',
|
|
234
|
-
configUrl: 'http://auth/.well-known/openid-configuration',
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
partyAllocator = new PartyAllocationService({
|
|
238
|
-
synchronizerId: 'test-sync-id',
|
|
239
|
-
accessTokenProvider: testATP('admin', 'admin.jwt'),
|
|
240
|
-
httpLedgerUrl: 'http://test',
|
|
241
|
-
logger: mockLogger,
|
|
242
|
-
});
|
|
243
|
-
const ledgerModule = await import('@canton-network/core-ledger-client');
|
|
244
|
-
mockLedgerClient = new ledgerModule.LedgerClient({
|
|
245
|
-
baseUrl: new URL('http://test'),
|
|
246
|
-
logger: mockLogger,
|
|
247
|
-
accessTokenProvider: testATP('token', 'token'),
|
|
248
|
-
});
|
|
249
|
-
service = new WalletSyncService(store, mockLedgerClient, authContext, mockLogger, {}, partyAllocator);
|
|
250
|
-
});
|
|
251
|
-
afterEach(() => {
|
|
252
|
-
vi.restoreAllMocks();
|
|
253
|
-
mockLedgerGet.mockClear();
|
|
254
|
-
});
|
|
255
|
-
it('isWalletSyncNeeded should filter by current network', async () => {
|
|
256
|
-
const network1 = createNetwork('network1');
|
|
257
|
-
await store.addNetwork(network1);
|
|
258
|
-
await setSession('network1');
|
|
259
|
-
await store.addWallet(createWallet('party1::namespace', 'network1'));
|
|
260
|
-
await store.addWallet(createWallet('party2::namespace', 'network2'));
|
|
261
|
-
mockLedgerGet.mockResolvedValueOnce({
|
|
262
|
-
rights: [
|
|
263
|
-
{
|
|
264
|
-
kind: {
|
|
265
|
-
CanActAs: {
|
|
266
|
-
value: {
|
|
267
|
-
party: 'party1::namespace',
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
},
|
|
272
|
-
],
|
|
273
|
-
});
|
|
274
|
-
const syncNeeded = await service.isWalletSyncNeeded();
|
|
275
|
-
// Should return false because party1 already exists in network1
|
|
276
|
-
expect(syncNeeded).toBe(false);
|
|
277
|
-
});
|
|
278
|
-
it('isWalletSyncNeeded should detect new parties for current network only', async () => {
|
|
279
|
-
const network1 = createNetwork('network1');
|
|
280
|
-
await store.addNetwork(network1);
|
|
281
|
-
await setSession('network1');
|
|
282
|
-
mockLedgerGet.mockResolvedValueOnce({
|
|
283
|
-
rights: [
|
|
284
|
-
{
|
|
285
|
-
kind: {
|
|
286
|
-
CanActAs: {
|
|
287
|
-
value: {
|
|
288
|
-
party: 'party1::namespace',
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
},
|
|
293
|
-
],
|
|
294
|
-
});
|
|
295
|
-
const syncNeeded = await service.isWalletSyncNeeded();
|
|
296
|
-
// Should return true because party1 exists on ledger but not in store for network1
|
|
297
|
-
expect(syncNeeded).toBe(true);
|
|
298
|
-
});
|
|
299
|
-
it('syncWallets should only sync wallets for current network', async () => {
|
|
300
|
-
const network1 = createNetwork('network1');
|
|
301
|
-
await store.addNetwork(network1);
|
|
302
|
-
await setSession('network1');
|
|
303
|
-
await store.addWallet(createWallet('party1::namespace', 'network1'));
|
|
304
|
-
const addWalletSpy = vi.spyOn(store, 'addWallet');
|
|
305
|
-
mockLedgerGet
|
|
306
|
-
.mockResolvedValueOnce({
|
|
307
|
-
participantId: 'participant1::namespace',
|
|
308
|
-
})
|
|
309
|
-
.mockResolvedValueOnce({
|
|
310
|
-
rights: [
|
|
311
|
-
{
|
|
312
|
-
kind: {
|
|
313
|
-
CanActAs: {
|
|
314
|
-
value: {
|
|
315
|
-
party: 'party1::namespace',
|
|
316
|
-
},
|
|
317
|
-
},
|
|
318
|
-
},
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
kind: {
|
|
322
|
-
CanActAs: {
|
|
323
|
-
value: {
|
|
324
|
-
party: 'party3::namespace',
|
|
325
|
-
},
|
|
326
|
-
},
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
|
-
],
|
|
330
|
-
});
|
|
331
|
-
await service.syncWallets();
|
|
332
|
-
// Should only add wallet for party3 (party1 already exists)
|
|
333
|
-
const wallets = await store.getAllWallets({ networkIds: ['network1'] });
|
|
334
|
-
expect(wallets.some((w) => w.partyId === 'party3::namespace')).toBe(true);
|
|
335
|
-
expect(addWalletSpy).toHaveBeenCalled();
|
|
336
|
-
});
|
|
337
|
-
it('syncWallets should handle same party ID across different networks', async () => {
|
|
338
|
-
const network1 = createNetwork('network1');
|
|
339
|
-
await store.addNetwork(network1);
|
|
340
|
-
await setSession('network1');
|
|
341
|
-
// Mock ledger client to return rights for party1
|
|
342
|
-
mockLedgerGet
|
|
343
|
-
.mockResolvedValueOnce({
|
|
344
|
-
participantId: 'participant1::namespace',
|
|
345
|
-
})
|
|
346
|
-
.mockResolvedValueOnce({
|
|
347
|
-
rights: [
|
|
348
|
-
{
|
|
349
|
-
kind: {
|
|
350
|
-
CanActAs: {
|
|
351
|
-
value: {
|
|
352
|
-
party: 'party1::namespace',
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
},
|
|
357
|
-
],
|
|
358
|
-
});
|
|
359
|
-
await service.syncWallets();
|
|
360
|
-
// Should add party1 for network1
|
|
361
|
-
const wallets = await store.getAllWallets({ networkIds: ['network1'] });
|
|
362
|
-
expect(wallets.some((w) => w.partyId === 'party1::namespace')).toBe(true);
|
|
363
|
-
});
|
|
364
|
-
it('isWalletSyncNeeded should detect multi-hosted party on different network', async () => {
|
|
365
|
-
const network1 = createNetwork('network1');
|
|
366
|
-
const network2 = createNetwork('network2');
|
|
367
|
-
await store.addNetwork(network1);
|
|
368
|
-
await store.addNetwork(network2);
|
|
369
|
-
await store.addWallet(createWallet('party1::namespace', 'network1'));
|
|
370
|
-
// Mock ledger client to return rights for party1 (multi-hosted party) for network1 check
|
|
371
|
-
mockLedgerGet.mockResolvedValueOnce({
|
|
372
|
-
rights: [
|
|
373
|
-
{
|
|
374
|
-
kind: {
|
|
375
|
-
CanActAs: {
|
|
376
|
-
value: {
|
|
377
|
-
party: 'party1::namespace',
|
|
378
|
-
},
|
|
379
|
-
},
|
|
380
|
-
},
|
|
381
|
-
},
|
|
382
|
-
],
|
|
383
|
-
});
|
|
384
|
-
await setSession('network1');
|
|
385
|
-
// Check sync needed for network1 (party already exists)
|
|
386
|
-
const syncNeeded1 = await service.isWalletSyncNeeded();
|
|
387
|
-
expect(syncNeeded1).toBe(false);
|
|
388
|
-
// Mock ledger client to return rights for party1 for network2 check
|
|
389
|
-
mockLedgerGet.mockResolvedValueOnce({
|
|
390
|
-
rights: [
|
|
391
|
-
{
|
|
392
|
-
kind: {
|
|
393
|
-
CanActAs: {
|
|
394
|
-
value: {
|
|
395
|
-
party: 'party1::namespace',
|
|
396
|
-
},
|
|
397
|
-
},
|
|
398
|
-
},
|
|
399
|
-
},
|
|
400
|
-
],
|
|
401
|
-
});
|
|
402
|
-
await setSession('network2');
|
|
403
|
-
// Check sync needed for network2 (party doesn't exist yet)
|
|
404
|
-
const syncNeeded2 = await service.isWalletSyncNeeded();
|
|
405
|
-
expect(syncNeeded2).toBe(true);
|
|
406
|
-
});
|
|
407
|
-
it('syncWallets should handle multi-hosted party across networks', async () => {
|
|
408
|
-
const network1 = createNetwork('network1');
|
|
409
|
-
const network2 = createNetwork('network2');
|
|
410
|
-
await store.addNetwork(network1);
|
|
411
|
-
await store.addNetwork(network2);
|
|
412
|
-
// Add wallet to network1 (simulating it was synced there previously)
|
|
413
|
-
await setSession('network1');
|
|
414
|
-
await store.addWallet(createWallet('party1::namespace', 'network1'));
|
|
415
|
-
// Sync on network1 (party already exists, should not add)
|
|
416
|
-
await setSession('network1');
|
|
417
|
-
// Only need one mock since resolveSigningProvider won't be called if party already exists
|
|
418
|
-
mockLedgerGet
|
|
419
|
-
.mockResolvedValueOnce({
|
|
420
|
-
participantId: 'participant1::namespace',
|
|
421
|
-
})
|
|
422
|
-
.mockResolvedValueOnce({
|
|
423
|
-
rights: [
|
|
424
|
-
{
|
|
425
|
-
kind: {
|
|
426
|
-
CanActAs: {
|
|
427
|
-
value: {
|
|
428
|
-
party: 'party1::namespace',
|
|
429
|
-
},
|
|
430
|
-
},
|
|
431
|
-
},
|
|
432
|
-
},
|
|
433
|
-
],
|
|
434
|
-
});
|
|
435
|
-
const syncResult1 = await service.syncWallets();
|
|
436
|
-
expect(syncResult1.added.length).toBe(0); // Should not add, already exists
|
|
437
|
-
// Sync on network2 (party doesn't exist, should add)
|
|
438
|
-
await setSession('network2');
|
|
439
|
-
// Verify no wallets exist for network2 before sync
|
|
440
|
-
const walletsBeforeSync = await store.getAllWallets({
|
|
441
|
-
networkIds: ['network2'],
|
|
442
|
-
});
|
|
443
|
-
expect(walletsBeforeSync.length).toBe(0);
|
|
444
|
-
mockLedgerGet.mockClear();
|
|
445
|
-
// First mock: resolveSigningProvider calls ledgerClient.getWithRetry('/v2/parties/participant-id')
|
|
446
|
-
mockLedgerGet.mockResolvedValueOnce({
|
|
447
|
-
participantId: 'participant1::namespace',
|
|
448
|
-
});
|
|
449
|
-
// Second mock: getPartiesRightsMap calls ledgerClient.getWithRetry('/v2/users/{user-id}/rights')
|
|
450
|
-
mockLedgerGet.mockResolvedValueOnce({
|
|
451
|
-
rights: [
|
|
452
|
-
{
|
|
453
|
-
kind: {
|
|
454
|
-
CanActAs: {
|
|
455
|
-
value: {
|
|
456
|
-
party: 'party1::namespace',
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
},
|
|
460
|
-
},
|
|
461
|
-
],
|
|
462
|
-
});
|
|
463
|
-
expect(mockLedgerGet).toHaveBeenCalledTimes(0);
|
|
464
|
-
const syncResult = await service.syncWallets();
|
|
465
|
-
expect(mockLedgerGet).toHaveBeenCalledTimes(2); // Once for rights, once for participantId
|
|
466
|
-
expect(syncResult.added.length).toBe(1);
|
|
467
|
-
expect(syncResult.added[0].partyId).toBe('party1::namespace');
|
|
468
|
-
expect(syncResult.added[0].networkId).toBe('network2');
|
|
469
|
-
expect(syncResult.added[0].disabled).toBe(false);
|
|
470
|
-
const network2Wallets = await store.getAllWallets({
|
|
471
|
-
networkIds: ['network2'],
|
|
472
|
-
});
|
|
473
|
-
const party1Wallet = network2Wallets.find((w) => w.partyId === 'party1::namespace');
|
|
474
|
-
expect(party1Wallet).toBeDefined();
|
|
475
|
-
expect(party1Wallet?.networkId).toBe('network2');
|
|
476
|
-
expect(party1Wallet?.disabled).toBe(false);
|
|
477
|
-
});
|
|
478
|
-
describe('Wallet sync - handling wallet not having a party', () => {
|
|
479
|
-
// When party is not on ledger (e.g. after participant reset), sync marks wallet
|
|
480
|
-
// status as 'initialized' so the user can manually re-allocate each one with "Allocate" button
|
|
481
|
-
it('isWalletSyncNeeded should return true when allocated wallet exists but has no party', async () => {
|
|
482
|
-
const network1 = createNetwork('network1');
|
|
483
|
-
await store.addNetwork(network1);
|
|
484
|
-
await setSession('network1');
|
|
485
|
-
await store.addWallet(createWallet('party1::namespace', 'network1', undefined, 'allocated'));
|
|
486
|
-
await store.addWallet(createWallet('party2::namespace', 'network1', undefined, 'allocated'));
|
|
487
|
-
mockLedgerGet.mockResolvedValueOnce({
|
|
488
|
-
rights: [
|
|
489
|
-
{
|
|
490
|
-
kind: {
|
|
491
|
-
CanActAs: {
|
|
492
|
-
value: {
|
|
493
|
-
party: 'party2::namespace',
|
|
494
|
-
},
|
|
495
|
-
},
|
|
496
|
-
},
|
|
497
|
-
},
|
|
498
|
-
],
|
|
499
|
-
});
|
|
500
|
-
const syncNeeded = await service.isWalletSyncNeeded();
|
|
501
|
-
expect(syncNeeded).toBe(true);
|
|
502
|
-
});
|
|
503
|
-
it('isWalletSyncNeeded should return false when initialized wallet exists and has no party', async () => {
|
|
504
|
-
const network1 = createNetwork('network1');
|
|
505
|
-
await store.addNetwork(network1);
|
|
506
|
-
await setSession('network1');
|
|
507
|
-
await store.addWallet(createWallet('party1::namespace', 'network1', undefined, 'initialized'));
|
|
508
|
-
await store.addWallet(createWallet('party2::namespace', 'network1', undefined, 'allocated'));
|
|
509
|
-
mockLedgerGet.mockResolvedValueOnce({
|
|
510
|
-
rights: [
|
|
511
|
-
{
|
|
512
|
-
kind: {
|
|
513
|
-
CanActAs: {
|
|
514
|
-
value: {
|
|
515
|
-
party: 'party2::namespace',
|
|
516
|
-
},
|
|
517
|
-
},
|
|
518
|
-
},
|
|
519
|
-
},
|
|
520
|
-
],
|
|
521
|
-
});
|
|
522
|
-
const syncNeeded = await service.isWalletSyncNeeded();
|
|
523
|
-
expect(syncNeeded).toBe(false);
|
|
524
|
-
});
|
|
525
|
-
it('syncWallets marks allocated wallet as initialized user has no rights to the party', async () => {
|
|
526
|
-
const network1 = createNetwork('network1');
|
|
527
|
-
await store.addNetwork(network1);
|
|
528
|
-
await setSession('network1');
|
|
529
|
-
await store.addWallet(createWallet('party1::namespace', 'network1'));
|
|
530
|
-
mockLedgerGet
|
|
531
|
-
.mockResolvedValueOnce({
|
|
532
|
-
participantId: 'participant1::namespace',
|
|
533
|
-
})
|
|
534
|
-
.mockResolvedValueOnce({
|
|
535
|
-
rights: [
|
|
536
|
-
{
|
|
537
|
-
kind: {
|
|
538
|
-
CanActAs: {
|
|
539
|
-
value: { party: 'party2::namespace' },
|
|
540
|
-
},
|
|
541
|
-
},
|
|
542
|
-
},
|
|
543
|
-
],
|
|
544
|
-
});
|
|
545
|
-
const updateWalletSpy = vi.spyOn(store, 'updateWallet');
|
|
546
|
-
const result = await service.syncWallets();
|
|
547
|
-
expect(updateWalletSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
548
|
-
partyId: 'party1::namespace',
|
|
549
|
-
networkId: 'network1',
|
|
550
|
-
status: 'initialized',
|
|
551
|
-
}));
|
|
552
|
-
const wallets = await store.getWallets();
|
|
553
|
-
const party1Wallet = wallets.find((w) => w.partyId === 'party1::namespace');
|
|
554
|
-
expect(party1Wallet?.status).toBe('initialized');
|
|
555
|
-
expect(result.added.length).toBe(1);
|
|
556
|
-
expect(result.updated.length).toBe(1);
|
|
557
|
-
expect(result.disabled.length).toBe(0);
|
|
558
|
-
expect(result.added[0].partyId).toBe('party2::namespace');
|
|
559
|
-
expect(result.updated[0]).toMatchObject({
|
|
560
|
-
partyId: 'party1::namespace',
|
|
561
|
-
status: 'initialized',
|
|
562
|
-
rights: [],
|
|
563
|
-
});
|
|
564
|
-
});
|
|
565
|
-
it('syncWallets skips wallet when status is already initialized', async () => {
|
|
566
|
-
const network1 = createNetwork('network1');
|
|
567
|
-
await store.addNetwork(network1);
|
|
568
|
-
await setSession('network1');
|
|
569
|
-
const initializedWallet = createWallet('party1::namespace', 'network1', false, 'initialized');
|
|
570
|
-
initializedWallet.rights = [];
|
|
571
|
-
await store.addWallet(initializedWallet);
|
|
572
|
-
mockLedgerGet
|
|
573
|
-
.mockResolvedValueOnce({
|
|
574
|
-
participantId: 'participant1::namespace',
|
|
575
|
-
})
|
|
576
|
-
.mockResolvedValueOnce({
|
|
577
|
-
rights: [
|
|
578
|
-
{
|
|
579
|
-
kind: {
|
|
580
|
-
CanActAs: {
|
|
581
|
-
value: { party: 'party2::namespace' },
|
|
582
|
-
},
|
|
583
|
-
},
|
|
584
|
-
},
|
|
585
|
-
],
|
|
586
|
-
});
|
|
587
|
-
const updateWalletSpy = vi.spyOn(store, 'updateWallet');
|
|
588
|
-
const result = await service.syncWallets();
|
|
589
|
-
expect(updateWalletSpy).not.toHaveBeenCalled();
|
|
590
|
-
const wallets = await store.getWallets();
|
|
591
|
-
const party1Wallet = wallets.find((w) => w.partyId === 'party1::namespace');
|
|
592
|
-
expect(party1Wallet?.status).toBe('initialized');
|
|
593
|
-
expect(result.added.length).toBe(1);
|
|
594
|
-
expect(result.disabled.length).toBe(0);
|
|
595
|
-
expect(result.updated.length).toBe(0);
|
|
596
|
-
expect(result.added[0].partyId).toBe('party2::namespace');
|
|
597
|
-
});
|
|
598
|
-
it('syncWallets marks multiple wallets as initialized when user has no rights to those parties', async () => {
|
|
599
|
-
const network1 = createNetwork('network1');
|
|
600
|
-
await store.addNetwork(network1);
|
|
601
|
-
await setSession('network1');
|
|
602
|
-
await store.addWallet(createWallet('party1::namespace', 'network1'));
|
|
603
|
-
await store.addWallet(createWallet('party2::namespace', 'network1'));
|
|
604
|
-
mockLedgerGet
|
|
605
|
-
.mockResolvedValueOnce({
|
|
606
|
-
participantId: 'participant1::namespace',
|
|
607
|
-
})
|
|
608
|
-
.mockResolvedValueOnce({
|
|
609
|
-
rights: [
|
|
610
|
-
{
|
|
611
|
-
kind: {
|
|
612
|
-
CanActAs: {
|
|
613
|
-
value: { party: 'party3::namespace' },
|
|
614
|
-
},
|
|
615
|
-
},
|
|
616
|
-
},
|
|
617
|
-
],
|
|
618
|
-
});
|
|
619
|
-
const updateWalletSpy = vi.spyOn(store, 'updateWallet');
|
|
620
|
-
const result = await service.syncWallets();
|
|
621
|
-
expect(updateWalletSpy).toHaveBeenCalledTimes(4);
|
|
622
|
-
expect(updateWalletSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
623
|
-
partyId: 'party1::namespace',
|
|
624
|
-
networkId: 'network1',
|
|
625
|
-
status: 'initialized',
|
|
626
|
-
}));
|
|
627
|
-
expect(updateWalletSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
628
|
-
partyId: 'party2::namespace',
|
|
629
|
-
networkId: 'network1',
|
|
630
|
-
status: 'initialized',
|
|
631
|
-
}));
|
|
632
|
-
expect(updateWalletSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
633
|
-
partyId: 'party1::namespace',
|
|
634
|
-
networkId: 'network1',
|
|
635
|
-
rights: [],
|
|
636
|
-
}));
|
|
637
|
-
expect(updateWalletSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
638
|
-
partyId: 'party2::namespace',
|
|
639
|
-
networkId: 'network1',
|
|
640
|
-
rights: [],
|
|
641
|
-
}));
|
|
642
|
-
expect(result.added.length).toBe(1);
|
|
643
|
-
expect(result.disabled.length).toBe(0);
|
|
644
|
-
expect(result.updated.length).toBe(2);
|
|
645
|
-
expect(result.added[0].partyId).toBe('party3::namespace');
|
|
646
|
-
});
|
|
647
|
-
it('syncWallets disables participant wallet user has no rights to the party', async () => {
|
|
648
|
-
const network1 = createNetwork('network1');
|
|
649
|
-
await store.addNetwork(network1);
|
|
650
|
-
await setSession('network1');
|
|
651
|
-
const participantWallet = createWallet('party1::namespace', 'network1');
|
|
652
|
-
participantWallet.signingProviderId = SigningProvider.PARTICIPANT;
|
|
653
|
-
await store.addWallet(participantWallet);
|
|
654
|
-
mockLedgerGet
|
|
655
|
-
.mockResolvedValueOnce({
|
|
656
|
-
participantId: 'participant1::namespace',
|
|
657
|
-
})
|
|
658
|
-
.mockResolvedValueOnce({
|
|
659
|
-
rights: [
|
|
660
|
-
{
|
|
661
|
-
kind: {
|
|
662
|
-
CanActAs: {
|
|
663
|
-
value: { party: 'party2::namespace' },
|
|
664
|
-
},
|
|
665
|
-
},
|
|
666
|
-
},
|
|
667
|
-
],
|
|
668
|
-
});
|
|
669
|
-
const updateWalletSpy = vi.spyOn(store, 'updateWallet');
|
|
670
|
-
const result = await service.syncWallets();
|
|
671
|
-
expect(updateWalletSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
672
|
-
partyId: 'party1::namespace',
|
|
673
|
-
networkId: 'network1',
|
|
674
|
-
disabled: true,
|
|
675
|
-
reason: 'participant namespace changed',
|
|
676
|
-
}));
|
|
677
|
-
const wallets = await store.getWallets();
|
|
678
|
-
const party1Wallet = wallets.find((w) => w.partyId === 'party1::namespace');
|
|
679
|
-
expect(party1Wallet?.disabled).toBe(true);
|
|
680
|
-
expect(party1Wallet?.reason).toBe('participant namespace changed');
|
|
681
|
-
expect(result.added.length).toBe(1);
|
|
682
|
-
expect(result.updated.length).toBe(0);
|
|
683
|
-
expect(result.disabled.length).toBe(1);
|
|
684
|
-
expect(result.added[0].partyId).toBe('party2::namespace');
|
|
685
|
-
expect(result.disabled[0].partyId).toBe('party1::namespace');
|
|
686
|
-
});
|
|
687
|
-
it('syncWallets reports proper changes while adding a wallet when there are disabled wallets', async () => {
|
|
688
|
-
const network1 = createNetwork('network1');
|
|
689
|
-
await store.addNetwork(network1);
|
|
690
|
-
await setSession('network1');
|
|
691
|
-
const disabledWallet = {
|
|
692
|
-
...createWallet('party1::namespace', 'network1', true),
|
|
693
|
-
rights: [],
|
|
694
|
-
};
|
|
695
|
-
await store.addWallet(disabledWallet);
|
|
696
|
-
mockLedgerGet
|
|
697
|
-
.mockResolvedValueOnce({
|
|
698
|
-
participantId: 'participant1::namespace',
|
|
699
|
-
})
|
|
700
|
-
.mockResolvedValueOnce({
|
|
701
|
-
rights: [
|
|
702
|
-
{
|
|
703
|
-
kind: {
|
|
704
|
-
CanActAs: {
|
|
705
|
-
value: { party: 'party2::namespace' },
|
|
706
|
-
},
|
|
707
|
-
},
|
|
708
|
-
},
|
|
709
|
-
],
|
|
710
|
-
});
|
|
711
|
-
const updateWalletSpy = vi.spyOn(store, 'updateWallet');
|
|
712
|
-
const addWalletSpy = vi.spyOn(store, 'addWallet');
|
|
713
|
-
const result = await service.syncWallets();
|
|
714
|
-
expect(updateWalletSpy).not.toHaveBeenCalled();
|
|
715
|
-
expect(addWalletSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
716
|
-
partyId: 'party2::namespace',
|
|
717
|
-
networkId: 'network1',
|
|
718
|
-
disabled: false,
|
|
719
|
-
}));
|
|
720
|
-
const wallets = await store.getWallets();
|
|
721
|
-
const party1Wallet = wallets.find((w) => w.partyId === 'party1::namespace');
|
|
722
|
-
expect(party1Wallet?.disabled).toBe(true);
|
|
723
|
-
expect(result.added.length).toBe(1);
|
|
724
|
-
expect(result.added[0].partyId).toBe('party2::namespace');
|
|
725
|
-
expect(result.updated.length).toBe(0);
|
|
726
|
-
expect(result.disabled.length).toBe(0);
|
|
727
|
-
});
|
|
728
|
-
it('syncWallets reports proper changes while adding a disabled wallet when there are disabled wallets', async () => {
|
|
729
|
-
const network1 = createNetwork('network1');
|
|
730
|
-
await store.addNetwork(network1);
|
|
731
|
-
await setSession('network1');
|
|
732
|
-
const disabledWallet = {
|
|
733
|
-
...createWallet('party1::unknown-namespace-123', 'network1', true),
|
|
734
|
-
rights: [],
|
|
735
|
-
};
|
|
736
|
-
await store.addWallet(disabledWallet);
|
|
737
|
-
mockLedgerGet
|
|
738
|
-
.mockResolvedValueOnce({
|
|
739
|
-
participantId: 'participant1::namespace',
|
|
740
|
-
})
|
|
741
|
-
.mockResolvedValueOnce({
|
|
742
|
-
rights: [
|
|
743
|
-
{
|
|
744
|
-
kind: {
|
|
745
|
-
CanActAs: {
|
|
746
|
-
value: {
|
|
747
|
-
party: 'party2::unknown-namespace-123',
|
|
748
|
-
},
|
|
749
|
-
},
|
|
750
|
-
},
|
|
751
|
-
},
|
|
752
|
-
],
|
|
753
|
-
});
|
|
754
|
-
const updateWalletSpy = vi.spyOn(store, 'updateWallet');
|
|
755
|
-
const addWalletSpy = vi.spyOn(store, 'addWallet');
|
|
756
|
-
const result = await service.syncWallets();
|
|
757
|
-
expect(updateWalletSpy).not.toHaveBeenCalled();
|
|
758
|
-
expect(addWalletSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
759
|
-
partyId: 'party2::unknown-namespace-123',
|
|
760
|
-
networkId: 'network1',
|
|
761
|
-
disabled: true,
|
|
762
|
-
reason: WALLET_DISABLED_REASON.NO_SIGNING_PROVIDER_MATCHED,
|
|
763
|
-
}));
|
|
764
|
-
const wallets = await store.getWallets();
|
|
765
|
-
const party1Wallet = wallets.find((w) => w.partyId === 'party2::unknown-namespace-123');
|
|
766
|
-
expect(party1Wallet?.disabled).toBe(true);
|
|
767
|
-
expect(party1Wallet?.reason).toBe(WALLET_DISABLED_REASON.NO_SIGNING_PROVIDER_MATCHED);
|
|
768
|
-
expect(result.added.length).toBe(0);
|
|
769
|
-
expect(result.updated.length).toBe(0);
|
|
770
|
-
expect(result.disabled.length).toBe(1);
|
|
771
|
-
expect(result.disabled[0].partyId).toBe('party2::unknown-namespace-123');
|
|
772
|
-
});
|
|
773
|
-
});
|
|
774
|
-
describe('Wallet sync - rights tracking', () => {
|
|
775
|
-
it('isWalletSyncNeeded should return true when wallet rights changed on ledger', async () => {
|
|
776
|
-
const network1 = createNetwork('network1');
|
|
777
|
-
await store.addNetwork(network1);
|
|
778
|
-
await setSession('network1');
|
|
779
|
-
await store.addWallet({
|
|
780
|
-
...createWallet('party1::namespace', 'network1'),
|
|
781
|
-
rights: [PartyLevelRight.CanActAs],
|
|
782
|
-
});
|
|
783
|
-
mockLedgerGet.mockResolvedValueOnce({
|
|
784
|
-
rights: [
|
|
785
|
-
{
|
|
786
|
-
kind: {
|
|
787
|
-
CanReadAs: {
|
|
788
|
-
value: {
|
|
789
|
-
party: 'party1::namespace',
|
|
790
|
-
},
|
|
791
|
-
},
|
|
792
|
-
},
|
|
793
|
-
},
|
|
794
|
-
],
|
|
795
|
-
});
|
|
796
|
-
const syncNeeded = await service.isWalletSyncNeeded();
|
|
797
|
-
expect(syncNeeded).toBe(true);
|
|
798
|
-
});
|
|
799
|
-
it('syncWallets updates rights when they changed on ledger', async () => {
|
|
800
|
-
const network1 = createNetwork('network1');
|
|
801
|
-
await store.addNetwork(network1);
|
|
802
|
-
await setSession('network1');
|
|
803
|
-
await store.addWallet({
|
|
804
|
-
...createWallet('party1::namespace', 'network1'),
|
|
805
|
-
rights: [PartyLevelRight.CanActAs],
|
|
806
|
-
});
|
|
807
|
-
await store.addWallet({
|
|
808
|
-
...createWallet('party3::namespace', 'network1'),
|
|
809
|
-
rights: [PartyLevelRight.CanActAs],
|
|
810
|
-
});
|
|
811
|
-
mockLedgerGet
|
|
812
|
-
.mockResolvedValueOnce({
|
|
813
|
-
participantId: 'participant1::namespace',
|
|
814
|
-
})
|
|
815
|
-
.mockResolvedValueOnce({
|
|
816
|
-
rights: [
|
|
817
|
-
{
|
|
818
|
-
kind: {
|
|
819
|
-
CanReadAs: {
|
|
820
|
-
value: {
|
|
821
|
-
party: 'party1::namespace',
|
|
822
|
-
},
|
|
823
|
-
},
|
|
824
|
-
},
|
|
825
|
-
},
|
|
826
|
-
{
|
|
827
|
-
kind: {
|
|
828
|
-
CanActAs: {
|
|
829
|
-
value: {
|
|
830
|
-
party: 'party2::namespace',
|
|
831
|
-
},
|
|
832
|
-
},
|
|
833
|
-
},
|
|
834
|
-
},
|
|
835
|
-
],
|
|
836
|
-
});
|
|
837
|
-
const result = await service.syncWallets();
|
|
838
|
-
expect(result.updated).toEqual(expect.arrayContaining([
|
|
839
|
-
expect.objectContaining({
|
|
840
|
-
partyId: 'party1::namespace',
|
|
841
|
-
rights: [PartyLevelRight.CanReadAs],
|
|
842
|
-
}),
|
|
843
|
-
]));
|
|
844
|
-
const wallets = await store.getWallets();
|
|
845
|
-
const updatedWallet = wallets.find((w) => w.partyId === 'party1::namespace');
|
|
846
|
-
expect(updatedWallet?.rights).toEqual([PartyLevelRight.CanReadAs]);
|
|
847
|
-
// party2 wallet added
|
|
848
|
-
expect(result.added.length).toBe(1);
|
|
849
|
-
// party1 wallet updated rights
|
|
850
|
-
// party3 wallet updated to initialized (no rights)
|
|
851
|
-
expect(result.updated.length).toBe(2);
|
|
852
|
-
});
|
|
853
|
-
it('syncWallets reports a reinitialized wallet once when its rights are also cleared', async () => {
|
|
854
|
-
const network1 = createNetwork('network1');
|
|
855
|
-
await store.addNetwork(network1);
|
|
856
|
-
await setSession('network1');
|
|
857
|
-
await store.addWallet({
|
|
858
|
-
...createWallet('party1::namespace', 'network1'),
|
|
859
|
-
rights: [PartyLevelRight.CanActAs],
|
|
860
|
-
});
|
|
861
|
-
mockLedgerGet
|
|
862
|
-
.mockResolvedValueOnce({
|
|
863
|
-
participantId: 'participant1::namespace',
|
|
864
|
-
})
|
|
865
|
-
.mockResolvedValueOnce({
|
|
866
|
-
rights: [
|
|
867
|
-
{
|
|
868
|
-
kind: {
|
|
869
|
-
CanActAs: {
|
|
870
|
-
value: { party: 'party2::namespace' },
|
|
871
|
-
},
|
|
872
|
-
},
|
|
873
|
-
},
|
|
874
|
-
],
|
|
875
|
-
});
|
|
876
|
-
const result = await service.syncWallets();
|
|
877
|
-
const wallets = await store.getWallets();
|
|
878
|
-
expect(result.added.map((wallet) => wallet.partyId)).toEqual([
|
|
879
|
-
'party2::namespace',
|
|
880
|
-
]);
|
|
881
|
-
expect(result.disabled).toEqual([]);
|
|
882
|
-
expect(result.updated).toEqual([
|
|
883
|
-
expect.objectContaining({
|
|
884
|
-
partyId: 'party1::namespace',
|
|
885
|
-
status: 'initialized',
|
|
886
|
-
rights: [],
|
|
887
|
-
}),
|
|
888
|
-
]);
|
|
889
|
-
expect(wallets.find((w) => w.partyId === 'party1::namespace')).toMatchObject({
|
|
890
|
-
status: 'initialized',
|
|
891
|
-
rights: [],
|
|
892
|
-
});
|
|
893
|
-
});
|
|
894
|
-
it('syncWallets does not create wallets from CanReadAsAnyParty alone', async () => {
|
|
895
|
-
const network1 = createNetwork('network1');
|
|
896
|
-
await store.addNetwork(network1);
|
|
897
|
-
await setSession('network1');
|
|
898
|
-
mockLedgerGet
|
|
899
|
-
.mockResolvedValueOnce({
|
|
900
|
-
participantId: 'participant1::namespace',
|
|
901
|
-
})
|
|
902
|
-
.mockResolvedValueOnce({
|
|
903
|
-
rights: [
|
|
904
|
-
{
|
|
905
|
-
kind: {
|
|
906
|
-
CanReadAsAnyParty: {
|
|
907
|
-
value: {},
|
|
908
|
-
},
|
|
909
|
-
},
|
|
910
|
-
},
|
|
911
|
-
],
|
|
912
|
-
});
|
|
913
|
-
const result = await service.syncWallets();
|
|
914
|
-
expect(result.added).toHaveLength(0);
|
|
915
|
-
expect((await store.getWallets()).length).toBe(0);
|
|
916
|
-
});
|
|
917
|
-
it('syncRights updates stored rights without syncing wallets', async () => {
|
|
918
|
-
const network1 = createNetwork('network1');
|
|
919
|
-
await store.addNetwork(network1);
|
|
920
|
-
await setSession('network1');
|
|
921
|
-
await store.addWallet({
|
|
922
|
-
...createWallet('party1::namespace', 'network1'),
|
|
923
|
-
rights: [PartyLevelRight.CanActAs],
|
|
924
|
-
});
|
|
925
|
-
await store.addWallet({
|
|
926
|
-
...createWallet('party3::namespace', 'network1'),
|
|
927
|
-
rights: [PartyLevelRight.CanActAs],
|
|
928
|
-
});
|
|
929
|
-
await store.addWallet({
|
|
930
|
-
...createWallet('party4::namespace', 'network1', false, 'initialized'),
|
|
931
|
-
rights: [],
|
|
932
|
-
});
|
|
933
|
-
mockLedgerGet.mockResolvedValueOnce({
|
|
934
|
-
rights: [
|
|
935
|
-
{
|
|
936
|
-
kind: {
|
|
937
|
-
CanReadAs: {
|
|
938
|
-
value: {
|
|
939
|
-
party: 'party1::namespace',
|
|
940
|
-
},
|
|
941
|
-
},
|
|
942
|
-
},
|
|
943
|
-
},
|
|
944
|
-
{
|
|
945
|
-
kind: {
|
|
946
|
-
CanActAs: {
|
|
947
|
-
value: {
|
|
948
|
-
party: 'party2::namespace',
|
|
949
|
-
},
|
|
950
|
-
},
|
|
951
|
-
},
|
|
952
|
-
},
|
|
953
|
-
{
|
|
954
|
-
kind: {
|
|
955
|
-
CanActAs: {
|
|
956
|
-
value: {
|
|
957
|
-
party: 'party4::namespace',
|
|
958
|
-
},
|
|
959
|
-
},
|
|
960
|
-
},
|
|
961
|
-
},
|
|
962
|
-
{
|
|
963
|
-
kind: {
|
|
964
|
-
CanReadAsAnyParty: {
|
|
965
|
-
value: {},
|
|
966
|
-
},
|
|
967
|
-
},
|
|
968
|
-
},
|
|
969
|
-
],
|
|
970
|
-
});
|
|
971
|
-
const updated = await service.syncRights();
|
|
972
|
-
// party1 rights changed, party3 lost its rights and is cleared, without a status change.
|
|
973
|
-
expect(updated.map((wallet) => wallet.partyId)).toEqual([
|
|
974
|
-
'party1::namespace',
|
|
975
|
-
'party3::namespace',
|
|
976
|
-
]);
|
|
977
|
-
expect(updated[0]).toMatchObject({
|
|
978
|
-
rights: [PartyLevelRight.CanReadAs],
|
|
979
|
-
status: 'allocated',
|
|
980
|
-
});
|
|
981
|
-
expect(updated[1]).toMatchObject({
|
|
982
|
-
rights: [],
|
|
983
|
-
status: 'allocated',
|
|
984
|
-
});
|
|
985
|
-
expect(mockLedgerGet).toHaveBeenCalledTimes(1);
|
|
986
|
-
expect(mockLedgerGet).toHaveBeenCalledWith('/v2/users/{user-id}/rights', expect.anything(), expect.objectContaining({
|
|
987
|
-
path: { 'user-id': 'test-user-id' },
|
|
988
|
-
}));
|
|
989
|
-
const wallets = await store.getWallets();
|
|
990
|
-
// party2 is on the ledger but must not be created by rights sync.
|
|
991
|
-
expect(wallets.map((w) => w.partyId).sort()).toEqual([
|
|
992
|
-
'party1::namespace',
|
|
993
|
-
'party3::namespace',
|
|
994
|
-
'party4::namespace',
|
|
995
|
-
]);
|
|
996
|
-
expect(wallets.find((w) => w.partyId === 'party1::namespace')).toMatchObject({
|
|
997
|
-
primary: true,
|
|
998
|
-
status: 'allocated',
|
|
999
|
-
rights: [PartyLevelRight.CanReadAs],
|
|
1000
|
-
});
|
|
1001
|
-
// Party is absent from the snapshot, so stored rights are cleared. Status stays allocated.
|
|
1002
|
-
expect(wallets.find((w) => w.partyId === 'party3::namespace')).toMatchObject({
|
|
1003
|
-
status: 'allocated',
|
|
1004
|
-
disabled: false,
|
|
1005
|
-
rights: [],
|
|
1006
|
-
});
|
|
1007
|
-
// Initialized wallets are skipped even if the ledger already has rights for that party.
|
|
1008
|
-
expect(wallets.find((w) => w.partyId === 'party4::namespace')).toMatchObject({
|
|
1009
|
-
status: 'initialized',
|
|
1010
|
-
rights: [],
|
|
1011
|
-
});
|
|
1012
|
-
expect(await store.getUserRights(network1.id)).toEqual([
|
|
1013
|
-
UserLevelRight.CanReadAsAnyParty,
|
|
1014
|
-
]);
|
|
1015
|
-
});
|
|
1016
|
-
});
|
|
1017
|
-
});
|