@canton-network/core-wallet-store-sql 0.10.0 → 0.11.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/dist/bootstrap.d.ts +6 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/index.cjs +526 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +515 -5
- package/dist/index.js.map +1 -0
- package/dist/migrations/001-init.d.ts.map +1 -1
- package/dist/migrations/001-init.js +0 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +29 -2
- package/dist/store-sql.d.ts.map +1 -1
- package/package.json +19 -9
- package/dist/cli.js +0 -66
- package/dist/migrations/002-drop-grpc-url.d.ts +0 -5
- package/dist/migrations/002-drop-grpc-url.d.ts.map +0 -1
- package/dist/migrations/002-drop-grpc-url.js +0 -16
- package/dist/migrator.js +0 -66
- package/dist/store-sql.js +0 -288
- package/dist/store-sql.test.d.ts +0 -2
- package/dist/store-sql.test.d.ts.map +0 -1
- package/dist/store-sql.test.js +0 -207
package/dist/store-sql.test.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { describe, expect, test } from '@jest/globals';
|
|
4
|
-
import { pino } from 'pino';
|
|
5
|
-
import { sink } from 'pino-test';
|
|
6
|
-
import { migrator } from './migrator';
|
|
7
|
-
import { connection, StoreSql } from './store-sql';
|
|
8
|
-
const authContextMock = {
|
|
9
|
-
userId: 'test-user-id',
|
|
10
|
-
accessToken: 'test-access-token',
|
|
11
|
-
};
|
|
12
|
-
const storeConfig = {
|
|
13
|
-
connection: {
|
|
14
|
-
type: 'memory',
|
|
15
|
-
},
|
|
16
|
-
networks: [],
|
|
17
|
-
};
|
|
18
|
-
const implementations = [['StoreSql', StoreSql]];
|
|
19
|
-
const ledgerApi = {
|
|
20
|
-
baseUrl: 'http://api',
|
|
21
|
-
};
|
|
22
|
-
const auth = {
|
|
23
|
-
identityProviderId: 'idp1',
|
|
24
|
-
type: 'password',
|
|
25
|
-
issuer: 'http://auth',
|
|
26
|
-
configUrl: 'http://auth/.well-known/openid-configuration',
|
|
27
|
-
tokenUrl: 'http://auth',
|
|
28
|
-
grantType: 'password',
|
|
29
|
-
clientId: 'cid',
|
|
30
|
-
scope: 'scope',
|
|
31
|
-
audience: 'aud',
|
|
32
|
-
};
|
|
33
|
-
const network = {
|
|
34
|
-
name: 'testnet',
|
|
35
|
-
chainId: 'network1',
|
|
36
|
-
synchronizerId: 'sync1::fingerprint',
|
|
37
|
-
description: 'Test Network',
|
|
38
|
-
ledgerApi,
|
|
39
|
-
auth,
|
|
40
|
-
};
|
|
41
|
-
implementations.forEach(([name, StoreImpl]) => {
|
|
42
|
-
describe(name, () => {
|
|
43
|
-
let db;
|
|
44
|
-
beforeEach(async () => {
|
|
45
|
-
db = connection(storeConfig);
|
|
46
|
-
const umzug = migrator(db);
|
|
47
|
-
await umzug.up();
|
|
48
|
-
});
|
|
49
|
-
afterEach(async () => {
|
|
50
|
-
await db.destroy();
|
|
51
|
-
});
|
|
52
|
-
test('should add and retrieve wallets', async () => {
|
|
53
|
-
const wallet = {
|
|
54
|
-
primary: false,
|
|
55
|
-
partyId: 'party1',
|
|
56
|
-
hint: 'hint',
|
|
57
|
-
signingProviderId: 'internal',
|
|
58
|
-
publicKey: 'publicKey',
|
|
59
|
-
namespace: 'namespace',
|
|
60
|
-
chainId: 'network1',
|
|
61
|
-
};
|
|
62
|
-
const store = new StoreImpl(db, pino(sink()), authContextMock);
|
|
63
|
-
await store.addNetwork(network);
|
|
64
|
-
await store.addWallet(wallet);
|
|
65
|
-
const wallets = await store.getWallets();
|
|
66
|
-
expect(wallets).toHaveLength(1);
|
|
67
|
-
});
|
|
68
|
-
test('should filter wallets', async () => {
|
|
69
|
-
const auth2 = {
|
|
70
|
-
identityProviderId: 'idp2',
|
|
71
|
-
type: 'password',
|
|
72
|
-
issuer: 'http://auth',
|
|
73
|
-
configUrl: 'http://auth/.well-known/openid-configuration',
|
|
74
|
-
tokenUrl: 'http://auth',
|
|
75
|
-
grantType: 'password',
|
|
76
|
-
clientId: 'cid',
|
|
77
|
-
scope: 'scope',
|
|
78
|
-
audience: 'aud',
|
|
79
|
-
};
|
|
80
|
-
const network2 = {
|
|
81
|
-
name: 'testnet',
|
|
82
|
-
chainId: 'network2',
|
|
83
|
-
synchronizerId: 'sync1::fingerprint',
|
|
84
|
-
description: 'Test Network',
|
|
85
|
-
ledgerApi,
|
|
86
|
-
auth: auth2,
|
|
87
|
-
};
|
|
88
|
-
const wallet1 = {
|
|
89
|
-
primary: false,
|
|
90
|
-
partyId: 'party1',
|
|
91
|
-
hint: 'hint1',
|
|
92
|
-
signingProviderId: 'internal',
|
|
93
|
-
publicKey: 'publicKey',
|
|
94
|
-
namespace: 'namespace',
|
|
95
|
-
chainId: 'network1',
|
|
96
|
-
};
|
|
97
|
-
const wallet2 = {
|
|
98
|
-
primary: false,
|
|
99
|
-
partyId: 'party2',
|
|
100
|
-
hint: 'hint2',
|
|
101
|
-
signingProviderId: 'internal',
|
|
102
|
-
publicKey: 'publicKey',
|
|
103
|
-
namespace: 'namespace',
|
|
104
|
-
chainId: 'network1',
|
|
105
|
-
};
|
|
106
|
-
const wallet3 = {
|
|
107
|
-
primary: false,
|
|
108
|
-
partyId: 'party3',
|
|
109
|
-
hint: 'hint3',
|
|
110
|
-
signingProviderId: 'internal',
|
|
111
|
-
publicKey: 'publicKey',
|
|
112
|
-
namespace: 'namespace',
|
|
113
|
-
chainId: 'network2',
|
|
114
|
-
};
|
|
115
|
-
const store = new StoreImpl(db, pino(sink()), authContextMock);
|
|
116
|
-
await store.addNetwork(network);
|
|
117
|
-
await store.addNetwork(network2);
|
|
118
|
-
await store.addWallet(wallet1);
|
|
119
|
-
await store.addWallet(wallet2);
|
|
120
|
-
await store.addWallet(wallet3);
|
|
121
|
-
const getAllWallets = await store.getWallets();
|
|
122
|
-
const getWalletsByChainId = await store.getWallets({
|
|
123
|
-
chainIds: ['network1'],
|
|
124
|
-
});
|
|
125
|
-
const getWalletsBySigningProviderId = await store.getWallets({
|
|
126
|
-
signingProviderIds: ['internal'],
|
|
127
|
-
});
|
|
128
|
-
const getWalletsByChainIdAndSigningProviderId = await store.getWallets({
|
|
129
|
-
chainIds: ['network1'],
|
|
130
|
-
signingProviderIds: ['internal'],
|
|
131
|
-
});
|
|
132
|
-
expect(getAllWallets).toHaveLength(3);
|
|
133
|
-
expect(getWalletsByChainId).toHaveLength(2);
|
|
134
|
-
expect(getWalletsBySigningProviderId).toHaveLength(3);
|
|
135
|
-
expect(getWalletsByChainIdAndSigningProviderId).toHaveLength(2);
|
|
136
|
-
});
|
|
137
|
-
test('should set and get primary wallet', async () => {
|
|
138
|
-
const wallet1 = {
|
|
139
|
-
primary: false,
|
|
140
|
-
partyId: 'party1',
|
|
141
|
-
hint: 'hint1',
|
|
142
|
-
signingProviderId: 'internal',
|
|
143
|
-
publicKey: 'publicKey',
|
|
144
|
-
namespace: 'namespace',
|
|
145
|
-
chainId: 'network1',
|
|
146
|
-
};
|
|
147
|
-
const wallet2 = {
|
|
148
|
-
primary: false,
|
|
149
|
-
partyId: 'party2',
|
|
150
|
-
hint: 'hint2',
|
|
151
|
-
signingProviderId: 'internal',
|
|
152
|
-
publicKey: 'publicKey',
|
|
153
|
-
namespace: 'namespace',
|
|
154
|
-
chainId: 'network1',
|
|
155
|
-
};
|
|
156
|
-
const store = new StoreImpl(db, pino(sink()), authContextMock);
|
|
157
|
-
await store.addNetwork(network);
|
|
158
|
-
await store.addWallet(wallet1);
|
|
159
|
-
await store.addWallet(wallet2);
|
|
160
|
-
await store.setPrimaryWallet('party2');
|
|
161
|
-
const primary = await store.getPrimaryWallet();
|
|
162
|
-
expect(primary?.partyId).toBe('party2');
|
|
163
|
-
expect(primary?.primary).toBe(true);
|
|
164
|
-
});
|
|
165
|
-
test('should set and get session', async () => {
|
|
166
|
-
const store = new StoreImpl(db, pino(sink()), authContextMock);
|
|
167
|
-
await store.addNetwork(network);
|
|
168
|
-
const session = {
|
|
169
|
-
network: 'network1',
|
|
170
|
-
accessToken: 'token',
|
|
171
|
-
};
|
|
172
|
-
await store.setSession(session);
|
|
173
|
-
const result = await store.getSession();
|
|
174
|
-
expect(result).toEqual({
|
|
175
|
-
...session,
|
|
176
|
-
userId: authContextMock.userId,
|
|
177
|
-
});
|
|
178
|
-
await store.removeSession();
|
|
179
|
-
const removed = await store.getSession();
|
|
180
|
-
expect(removed).toBeUndefined();
|
|
181
|
-
});
|
|
182
|
-
test('should add, list, get, update, and remove networks', async () => {
|
|
183
|
-
const store = new StoreImpl(db, pino(sink()), authContextMock);
|
|
184
|
-
await store.addNetwork(network);
|
|
185
|
-
const listed = await store.listNetworks();
|
|
186
|
-
expect(listed).toHaveLength(1);
|
|
187
|
-
expect(listed[0].description).toBe('Test Network');
|
|
188
|
-
await store.updateNetwork({
|
|
189
|
-
...network,
|
|
190
|
-
description: 'Updated Network',
|
|
191
|
-
});
|
|
192
|
-
const fetched = await store.getNetwork('network1');
|
|
193
|
-
expect(fetched.description).toBe('Updated Network');
|
|
194
|
-
await store.removeNetwork('network1');
|
|
195
|
-
const afterRemove = await store.listNetworks();
|
|
196
|
-
expect(afterRemove).toHaveLength(0);
|
|
197
|
-
});
|
|
198
|
-
test('should throw when getting a non-existent network', async () => {
|
|
199
|
-
const store = new StoreImpl(db, pino(sink()), authContextMock);
|
|
200
|
-
await expect(store.getNetwork('doesnotexist')).rejects.toThrow();
|
|
201
|
-
});
|
|
202
|
-
test('should throw when getting current network if none set', async () => {
|
|
203
|
-
const store = new StoreImpl(db, pino(sink()), authContextMock);
|
|
204
|
-
await expect(store.getCurrentNetwork()).rejects.toThrow();
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
});
|