@canton-network/core-wallet-store 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,36 +1,37 @@
1
1
  {
2
- "name": "@canton-network/core-wallet-store",
3
- "version": "0.1.0",
4
- "description": "The Store API provides persistency for the wallet kernel.",
5
- "author": "Marc Juchli <marc.juchli@digitalasset.com>",
6
- "license": "Apache-2.0",
7
- "packageManager": "yarn@4.9.2",
8
- "main": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
10
- "type": "module",
11
- "scripts": {
12
- "build": "tsc -b",
13
- "dev": "tsc -b --watch",
14
- "clean": "tsc -b --clean; rm -rf dist",
15
- "test": "yarn node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
16
- },
17
- "dependencies": {
18
- "zod": "^3.25.64"
19
- },
20
- "devDependencies": {
21
- "@jest/globals": "^29.0.0",
22
- "@swc/core": "^1.11.31",
23
- "@swc/jest": "^0.2.38",
24
- "@types/jest": "^30.0.0",
25
- "jest": "^30.0.0",
26
- "ts-jest": "^29.4.0",
27
- "ts-jest-resolver": "^2.0.1",
28
- "typescript": "^5.8.3"
29
- },
30
- "files": [
31
- "dist/*"
32
- ],
33
- "publishConfig": {
34
- "access": "public"
35
- }
36
- }
2
+ "name": "@canton-network/core-wallet-store",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "The Store API provides persistency for the wallet kernel",
6
+ "repository": "github:hyperledger-labs/splice-wallet-kernel",
7
+ "license": "Apache-2.0",
8
+ "author": "Marc Juchli <marc.juchli@digitalasset.com>",
9
+ "packageManager": "yarn@4.9.4",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "scripts": {
13
+ "build": "tsc -b",
14
+ "dev": "tsc -b --watch",
15
+ "clean": "tsc -b --clean; rm -rf dist",
16
+ "test": "yarn node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
17
+ },
18
+ "dependencies": {
19
+ "zod": "^3.25.64"
20
+ },
21
+ "devDependencies": {
22
+ "@jest/globals": "^29.0.0",
23
+ "@swc/core": "^1.11.31",
24
+ "@swc/jest": "^0.2.38",
25
+ "@types/jest": "^30.0.0",
26
+ "jest": "^30.0.0",
27
+ "ts-jest": "^29.4.0",
28
+ "ts-jest-resolver": "^2.0.1",
29
+ "typescript": "^5.8.3"
30
+ },
31
+ "files": [
32
+ "dist/**"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
37
+ }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Store.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Store.test.d.ts","sourceRoot":"","sources":["../src/Store.test.ts"],"names":[],"mappings":""}
@@ -1,155 +0,0 @@
1
- import { beforeEach, describe, expect, test } from '@jest/globals';
2
- import { StoreInternal } from './StoreInternal';
3
- const authContextMock = {
4
- userId: 'test-user-id',
5
- accessToken: 'test-access-token',
6
- };
7
- const storeConfig = {
8
- networks: [],
9
- };
10
- const implementations = [
11
- ['StoreInternal', StoreInternal],
12
- ];
13
- implementations.forEach(([name, StoreImpl]) => {
14
- describe(name, () => {
15
- let store;
16
- beforeEach(() => {
17
- store = new StoreImpl(storeConfig, authContextMock);
18
- });
19
- test('should add and retrieve wallets', async () => {
20
- const wallet = {
21
- primary: false,
22
- partyId: 'party1',
23
- hint: 'hint',
24
- signingProviderId: 'internal',
25
- publicKey: 'publicKey',
26
- namespace: 'namespace',
27
- chainId: 'network1',
28
- };
29
- await store.addWallet(wallet);
30
- const wallets = await store.getWallets();
31
- expect(wallets).toHaveLength(1);
32
- });
33
- test('should filter wallets', async () => {
34
- const wallet1 = {
35
- primary: false,
36
- partyId: 'party1',
37
- hint: 'hint1',
38
- signingProviderId: 'internal1',
39
- publicKey: 'publicKey',
40
- namespace: 'namespace',
41
- chainId: 'network1',
42
- };
43
- const wallet2 = {
44
- primary: false,
45
- partyId: 'party2',
46
- hint: 'hint2',
47
- signingProviderId: 'internal2',
48
- publicKey: 'publicKey',
49
- namespace: 'namespace',
50
- chainId: 'network1',
51
- };
52
- const wallet3 = {
53
- primary: false,
54
- partyId: 'party3',
55
- hint: 'hint3',
56
- signingProviderId: 'internal2',
57
- publicKey: 'publicKey',
58
- namespace: 'namespace',
59
- chainId: 'network2',
60
- };
61
- await store.addWallet(wallet1);
62
- await store.addWallet(wallet2);
63
- await store.addWallet(wallet3);
64
- const getAllWallets = await store.getWallets();
65
- const getWalletsByChainId = await store.getWallets({
66
- chainIds: ['network1'],
67
- });
68
- const getWalletsBySigningProviderId = await store.getWallets({
69
- signingProviderIds: ['internal2'],
70
- });
71
- const getWalletsByChainIdAndSigningProviderId = await store.getWallets({
72
- chainIds: ['network1'],
73
- signingProviderIds: ['internal2'],
74
- });
75
- expect(getAllWallets).toHaveLength(3);
76
- expect(getWalletsByChainId).toHaveLength(2);
77
- expect(getWalletsBySigningProviderId).toHaveLength(2);
78
- expect(getWalletsByChainIdAndSigningProviderId).toHaveLength(1);
79
- });
80
- test('should set and get primary wallet', async () => {
81
- const wallet1 = {
82
- primary: false,
83
- partyId: 'party1',
84
- hint: 'hint1',
85
- signingProviderId: 'internal',
86
- publicKey: 'publicKey',
87
- namespace: 'namespace',
88
- chainId: 'network1',
89
- };
90
- const wallet2 = {
91
- primary: false,
92
- partyId: 'party2',
93
- hint: 'hint2',
94
- signingProviderId: 'internal',
95
- publicKey: 'publicKey',
96
- namespace: 'namespace',
97
- chainId: 'network1',
98
- };
99
- await store.addWallet(wallet1);
100
- await store.addWallet(wallet2);
101
- await store.setPrimaryWallet('party2');
102
- const primary = await store.getPrimaryWallet();
103
- expect(primary?.partyId).toBe('party2');
104
- expect(primary?.primary).toBe(true);
105
- });
106
- test('should set and get session', async () => {
107
- const session = { network: 'net', accessToken: 'token' };
108
- await store.setSession(session);
109
- const result = await store.getSession();
110
- expect(result).toEqual(session);
111
- await store.removeSession();
112
- const removed = await store.getSession();
113
- expect(removed).toBeUndefined();
114
- });
115
- test('should add, list, get, update, and remove networks', async () => {
116
- const ledgerApi = {
117
- baseUrl: 'http://api',
118
- adminGrpcUrl: 'http://grpc',
119
- };
120
- const auth = {
121
- type: 'password',
122
- issuer: 'http://auth',
123
- configUrl: 'http://auth/.well-known/openid-configuration',
124
- tokenUrl: 'http://auth',
125
- grantType: 'password',
126
- clientId: 'cid',
127
- scope: 'scope',
128
- audience: 'aud',
129
- };
130
- const network = {
131
- name: 'testnet',
132
- chainId: 'network1',
133
- synchronizerId: 'sync1::fingerprint',
134
- description: 'Test Network',
135
- ledgerApi,
136
- auth,
137
- };
138
- await store.updateNetwork(network);
139
- const listed = await store.listNetworks();
140
- expect(listed).toHaveLength(1);
141
- expect(listed[0].name).toBe('testnet');
142
- const fetched = await store.getNetwork('network1');
143
- expect(fetched.description).toBe('Test Network');
144
- await store.removeNetwork('network1');
145
- const afterRemove = await store.listNetworks();
146
- expect(afterRemove).toHaveLength(0);
147
- });
148
- test('should throw when getting a non-existent network', async () => {
149
- await expect(store.getNetwork('doesnotexist')).rejects.toThrow();
150
- });
151
- test('should throw when getting current network if none set', async () => {
152
- await expect(store.getCurrentNetwork()).rejects.toThrow();
153
- });
154
- });
155
- });
@@ -1,40 +0,0 @@
1
- import { AuthContext, UserId, AuthAware } from 'core-wallet-auth';
2
- import { Store, Wallet, PartyId, Session, WalletFilter, Transaction } from './Store.js';
3
- import { Network } from './config/schema.js';
4
- interface UserStorage {
5
- wallets: Array<Wallet>;
6
- transactions: Map<string, Transaction>;
7
- session: Session | undefined;
8
- }
9
- export interface StoreInternalConfig {
10
- networks: Array<Network>;
11
- }
12
- type Memory = Map<UserId, UserStorage>;
13
- export declare class StoreInternal implements Store, AuthAware<StoreInternal> {
14
- private systemStorage;
15
- private userStorage;
16
- authContext: AuthContext | undefined;
17
- constructor(config: StoreInternalConfig, authContext?: AuthContext, userStorage?: Memory);
18
- withAuthContext(context?: AuthContext): StoreInternal;
19
- static createStorage(): UserStorage;
20
- private assertConnected;
21
- private getStorage;
22
- private updateStorage;
23
- getWallets(filter?: WalletFilter): Promise<Array<Wallet>>;
24
- getPrimaryWallet(): Promise<Wallet | undefined>;
25
- setPrimaryWallet(partyId: PartyId): Promise<void>;
26
- addWallet(wallet: Wallet): Promise<void>;
27
- getSession(): Promise<Session | undefined>;
28
- setSession(session: Session): Promise<void>;
29
- removeSession(): Promise<void>;
30
- getNetwork(chainId: string): Promise<Network>;
31
- getCurrentNetwork(): Promise<Network>;
32
- listNetworks(): Promise<Array<Network>>;
33
- updateNetwork(network: Network): Promise<void>;
34
- addNetwork(network: Network): Promise<void>;
35
- removeNetwork(chainId: string): Promise<void>;
36
- setTransaction(transaction: Transaction): Promise<void>;
37
- getTransaction(commandId: string): Promise<Transaction | undefined>;
38
- }
39
- export {};
40
- //# sourceMappingURL=StoreInternal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StoreInternal.d.ts","sourceRoot":"","sources":["../src/StoreInternal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EACH,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,YAAY,EACZ,WAAW,EACd,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAE5C,UAAU,WAAW;IACjB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACtB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IACtC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAA;CAC/B;AAED,MAAM,WAAW,mBAAmB;IAChC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;CAC3B;AAED,KAAK,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AAGtC,qBAAa,aAAc,YAAW,KAAK,EAAE,SAAS,CAAC,aAAa,CAAC;IACjE,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,WAAW,CAAQ;IAE3B,WAAW,EAAE,WAAW,GAAG,SAAS,CAAA;gBAGhC,MAAM,EAAE,mBAAmB,EAC3B,WAAW,CAAC,EAAE,WAAW,EACzB,WAAW,CAAC,EAAE,MAAM;IAOxB,eAAe,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,aAAa;IAIrD,MAAM,CAAC,aAAa,IAAI,WAAW;IAQnC,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,aAAa;IAOf,UAAU,CAAC,MAAM,GAAE,YAAiB,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAkB7D,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAK/C,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBxC,UAAU,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAI1C,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3C,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9B,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAW7C,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAkBrC,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAIvC,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAM9C,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAW3C,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7C,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAQvD,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;CAM5E"}
@@ -1,168 +0,0 @@
1
- // TODO: remove AuthAware and instead provide wrapper in clients
2
- export class StoreInternal {
3
- systemStorage;
4
- userStorage;
5
- authContext;
6
- constructor(config, authContext, userStorage) {
7
- this.systemStorage = config;
8
- this.authContext = authContext;
9
- this.userStorage = userStorage || new Map();
10
- }
11
- withAuthContext(context) {
12
- return new StoreInternal(this.systemStorage, context, this.userStorage);
13
- }
14
- static createStorage() {
15
- return {
16
- wallets: [],
17
- transactions: new Map(),
18
- session: undefined,
19
- };
20
- }
21
- assertConnected() {
22
- if (!this.authContext) {
23
- throw new Error('User is not connected');
24
- }
25
- return this.authContext.userId;
26
- }
27
- getStorage() {
28
- const userId = this.assertConnected();
29
- if (!this.userStorage.has(userId)) {
30
- this.userStorage.set(userId, StoreInternal.createStorage());
31
- }
32
- return this.userStorage.get(userId);
33
- }
34
- updateStorage(storage) {
35
- const userId = this.assertConnected();
36
- this.userStorage.set(userId, storage);
37
- }
38
- // Wallet methods
39
- async getWallets(filter = {}) {
40
- const { chainIds, signingProviderIds } = filter;
41
- const chainIdSet = chainIds ? new Set(chainIds) : null;
42
- const signingProviderIdSet = signingProviderIds
43
- ? new Set(signingProviderIds)
44
- : null;
45
- return this.getStorage().wallets.filter((wallet) => {
46
- const matchedChainIds = chainIdSet
47
- ? chainIdSet.has(wallet.chainId)
48
- : true;
49
- const matchedStorageProviderIdS = signingProviderIdSet
50
- ? signingProviderIdSet.has(wallet.signingProviderId)
51
- : true;
52
- return matchedChainIds && matchedStorageProviderIdS;
53
- });
54
- }
55
- async getPrimaryWallet() {
56
- const wallets = await this.getWallets();
57
- return wallets.find((w) => w.primary === true);
58
- }
59
- async setPrimaryWallet(partyId) {
60
- const storage = this.getStorage();
61
- if (!storage.wallets.some((w) => w.partyId === partyId)) {
62
- throw new Error(`Wallet with partyId "${partyId}" not found`);
63
- }
64
- const wallets = storage.wallets.map((w) => {
65
- if (w.partyId === partyId) {
66
- w.primary = true;
67
- }
68
- else {
69
- w.primary = false;
70
- }
71
- return w;
72
- });
73
- storage.wallets = wallets;
74
- this.updateStorage(storage);
75
- }
76
- async addWallet(wallet) {
77
- const storage = this.getStorage();
78
- if (storage.wallets.some((w) => w.partyId === wallet.partyId)) {
79
- throw new Error(`Wallet with partyId "${wallet.partyId}" already exists`);
80
- }
81
- const wallets = await this.getWallets();
82
- if (wallets.length === 0) {
83
- // If this is the first wallet, set it as primary automatically
84
- wallet.primary = true;
85
- }
86
- if (wallet.primary) {
87
- // If the new wallet is primary, set all others to non-primary
88
- storage.wallets.map((w) => (w.primary = false));
89
- }
90
- wallets.push(wallet);
91
- storage.wallets = wallets;
92
- this.updateStorage(storage);
93
- }
94
- // Session methods
95
- async getSession() {
96
- return this.getStorage().session;
97
- }
98
- async setSession(session) {
99
- const storage = this.getStorage();
100
- storage.session = session;
101
- this.updateStorage(storage);
102
- }
103
- async removeSession() {
104
- const storage = this.getStorage();
105
- storage.session = undefined;
106
- this.updateStorage(storage);
107
- }
108
- // Network methods
109
- async getNetwork(chainId) {
110
- this.assertConnected();
111
- const networks = await this.listNetworks();
112
- if (!networks)
113
- throw new Error('No networks available');
114
- const network = networks.find((n) => n.chainId === chainId);
115
- if (!network)
116
- throw new Error(`Network "${chainId}" not found`);
117
- return network;
118
- }
119
- async getCurrentNetwork() {
120
- const session = this.getStorage().session;
121
- if (!session) {
122
- throw new Error('No session found');
123
- }
124
- const chainId = session.network;
125
- if (!chainId) {
126
- throw new Error('No current network set in session');
127
- }
128
- const networks = await this.listNetworks();
129
- const network = networks.find((n) => n.chainId === chainId);
130
- if (!network) {
131
- throw new Error(`Network "${chainId}" not found`);
132
- }
133
- return network;
134
- }
135
- async listNetworks() {
136
- return this.systemStorage.networks;
137
- }
138
- async updateNetwork(network) {
139
- this.assertConnected();
140
- this.removeNetwork(network.chainId); // Ensure no duplicates
141
- this.systemStorage.networks.push(network);
142
- }
143
- async addNetwork(network) {
144
- const networkAlreadyExists = this.systemStorage.networks.find((n) => n.chainId === network.chainId);
145
- if (networkAlreadyExists) {
146
- throw new Error(`Network ${network.chainId} already exists`);
147
- }
148
- else {
149
- this.systemStorage.networks.push(network);
150
- }
151
- }
152
- async removeNetwork(chainId) {
153
- this.assertConnected();
154
- this.systemStorage.networks = this.systemStorage.networks.filter((n) => n.chainId !== chainId);
155
- }
156
- // Transaction methods
157
- async setTransaction(transaction) {
158
- this.assertConnected();
159
- const storage = this.getStorage();
160
- storage.transactions.set(transaction.commandId, transaction);
161
- this.updateStorage(storage);
162
- }
163
- async getTransaction(commandId) {
164
- this.assertConnected();
165
- const storage = this.getStorage();
166
- return storage.transactions.get(commandId);
167
- }
168
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=StoreInternal.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StoreInternal.test.d.ts","sourceRoot":"","sources":["../src/StoreInternal.test.ts"],"names":[],"mappings":""}
@@ -1,144 +0,0 @@
1
- import { beforeEach, describe, expect, test } from '@jest/globals';
2
- import { StoreInternal } from './StoreInternal';
3
- const authContextMock = {
4
- userId: 'test-user-id',
5
- accessToken: 'test-access-token',
6
- };
7
- const storeConfig = {
8
- networks: [],
9
- };
10
- describe('StoreInternal', () => {
11
- let store;
12
- beforeEach(() => {
13
- store = new StoreInternal(storeConfig, authContextMock);
14
- });
15
- test('should add and retrieve wallets', async () => {
16
- const wallet = {
17
- primary: false,
18
- partyId: 'party1',
19
- hint: 'hint',
20
- signingProviderId: 'internal',
21
- publicKey: 'publicKey',
22
- namespace: 'namespace',
23
- chainId: 'network1',
24
- };
25
- await store.addWallet(wallet);
26
- const wallets = await store.getWallets();
27
- expect(wallets).toHaveLength(1);
28
- });
29
- test('should filter wallets', async () => {
30
- const wallet1 = {
31
- primary: false,
32
- partyId: 'party1',
33
- hint: 'hint1',
34
- signingProviderId: 'internal1',
35
- publicKey: 'publicKey',
36
- namespace: 'namespace',
37
- chainId: 'network1',
38
- };
39
- const wallet2 = {
40
- primary: false,
41
- partyId: 'party2',
42
- hint: 'hint2',
43
- signingProviderId: 'internal2',
44
- publicKey: 'publicKey',
45
- namespace: 'namespace',
46
- chainId: 'network1',
47
- };
48
- const wallet3 = {
49
- primary: false,
50
- partyId: 'party3',
51
- hint: 'hint3',
52
- signingProviderId: 'internal2',
53
- publicKey: 'publicKey',
54
- namespace: 'namespace',
55
- chainId: 'network2',
56
- };
57
- await store.addWallet(wallet1);
58
- await store.addWallet(wallet2);
59
- await store.addWallet(wallet3);
60
- const getAllWallets = await store.getWallets();
61
- const getWalletsByChainId = await store.getWallets({
62
- chainIds: ['network1'],
63
- });
64
- const getWalletsBySigningProviderId = await store.getWallets({
65
- signingProviderIds: ['internal2'],
66
- });
67
- const getWalletsByChainIdAndSigningProviderId = await store.getWallets({
68
- chainIds: ['network1'],
69
- signingProviderIds: ['internal2'],
70
- });
71
- expect(getAllWallets).toHaveLength(3);
72
- expect(getWalletsByChainId).toHaveLength(2);
73
- expect(getWalletsBySigningProviderId).toHaveLength(2);
74
- expect(getWalletsByChainIdAndSigningProviderId).toHaveLength(1);
75
- });
76
- test('should set and get primary wallet', async () => {
77
- const wallet1 = {
78
- primary: false,
79
- partyId: 'party1',
80
- hint: 'hint1',
81
- signingProviderId: 'internal',
82
- publicKey: 'publicKey',
83
- namespace: 'namespace',
84
- chainId: 'network1',
85
- };
86
- const wallet2 = {
87
- primary: false,
88
- partyId: 'party2',
89
- hint: 'hint2',
90
- signingProviderId: 'internal',
91
- publicKey: 'publicKey',
92
- namespace: 'namespace',
93
- chainId: 'network1',
94
- };
95
- await store.addWallet(wallet1);
96
- await store.addWallet(wallet2);
97
- await store.setPrimaryWallet('party2');
98
- const primary = await store.getPrimaryWallet();
99
- expect(primary?.partyId).toBe('party2');
100
- expect(primary?.primary).toBe(true);
101
- });
102
- test('should set and get session', async () => {
103
- const session = { network: 'net', accessToken: 'token' };
104
- await store.setSession(session);
105
- const result = await store.getSession();
106
- expect(result).toEqual(session);
107
- await store.removeSession();
108
- const removed = await store.getSession();
109
- expect(removed).toBeUndefined();
110
- });
111
- test('should add, list, get, update, and remove networks', async () => {
112
- const ledgerApi = { baseUrl: 'http://api' };
113
- const auth = {
114
- type: 'password',
115
- tokenUrl: 'http://auth',
116
- grantType: 'password',
117
- clientId: 'cid',
118
- scope: 'scope',
119
- };
120
- const network = {
121
- name: 'testnet',
122
- chainId: 'network1',
123
- synchronizerId: 'sync1::fingerprint',
124
- description: 'Test Network',
125
- ledgerApi,
126
- auth,
127
- };
128
- await store.updateNetwork(network);
129
- const listed = await store.listNetworks();
130
- expect(listed).toHaveLength(1);
131
- expect(listed[0].name).toBe('testnet');
132
- const fetched = await store.getNetwork('network1');
133
- expect(fetched.description).toBe('Test Network');
134
- await store.removeNetwork('network1');
135
- const afterRemove = await store.listNetworks();
136
- expect(afterRemove).toHaveLength(0);
137
- });
138
- test('should throw when getting a non-existent network', async () => {
139
- await expect(store.getNetwork('doesnotexist')).rejects.toThrow();
140
- });
141
- test('should throw when getting current network if none set', async () => {
142
- await expect(store.getCurrentNetwork()).rejects.toThrow();
143
- });
144
- });