@canton-network/core-wallet-store-sql 0.27.0 → 0.28.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/dist/index.cjs +136 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +136 -46
- package/dist/index.js.map +1 -1
- package/dist/migrations/009-add-wallet-rights-columns.d.ts +5 -0
- package/dist/migrations/009-add-wallet-rights-columns.d.ts.map +1 -0
- package/dist/migrations/009-add-wallet-rights-columns.js +38 -0
- package/dist/migrations/010-add-transaction-network-id.d.ts +5 -0
- package/dist/migrations/010-add-transaction-network-id.d.ts.map +1 -0
- package/dist/migrations/010-add-transaction-network-id.js +153 -0
- package/dist/schema.d.ts +32 -11
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +26 -9
- package/dist/store-sql.d.ts +3 -1
- package/dist/store-sql.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"010-add-transaction-network-id.d.ts","sourceRoot":"","sources":["../../src/migrations/010-add-transaction-network-id.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAO,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAA;AAGjC,wBAAsB,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkGtD;AAED,wBAAsB,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkExD"}
|
|
@@ -0,0 +1,153 @@
|
|
|
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 { sql } from 'kysely';
|
|
4
|
+
import { isPostgres } from '../utils.js';
|
|
5
|
+
export async function up(db) {
|
|
6
|
+
console.log('Adding network_id column to transactions table');
|
|
7
|
+
await db.schema
|
|
8
|
+
.alterTable('transactions')
|
|
9
|
+
.addColumn('network_id', 'text')
|
|
10
|
+
.execute();
|
|
11
|
+
// Remove records we cannot map to exactly one network for the user.
|
|
12
|
+
await sql `
|
|
13
|
+
DELETE FROM transactions
|
|
14
|
+
WHERE (
|
|
15
|
+
SELECT COUNT(*)
|
|
16
|
+
FROM networks n
|
|
17
|
+
WHERE n.user_id = transactions.user_id
|
|
18
|
+
) <> 1
|
|
19
|
+
`.execute(db);
|
|
20
|
+
// Backfill from the single network owned by the transaction user.
|
|
21
|
+
await sql `
|
|
22
|
+
UPDATE transactions
|
|
23
|
+
SET network_id = (
|
|
24
|
+
SELECT n.id
|
|
25
|
+
FROM networks n
|
|
26
|
+
WHERE n.user_id = transactions.user_id
|
|
27
|
+
)
|
|
28
|
+
WHERE network_id IS NULL
|
|
29
|
+
`.execute(db);
|
|
30
|
+
const pg = await isPostgres(db);
|
|
31
|
+
if (pg) {
|
|
32
|
+
await sql `
|
|
33
|
+
ALTER TABLE transactions
|
|
34
|
+
ADD CONSTRAINT transactions_network_fk
|
|
35
|
+
FOREIGN KEY (network_id) REFERENCES networks(id) ON DELETE CASCADE
|
|
36
|
+
`.execute(db);
|
|
37
|
+
await sql `
|
|
38
|
+
ALTER TABLE transactions
|
|
39
|
+
ALTER COLUMN network_id SET NOT NULL
|
|
40
|
+
`.execute(db);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// SQLite: recreate table to enforce NOT NULL on network_id.
|
|
44
|
+
await db.schema.dropTable('transactions_new').ifExists().execute();
|
|
45
|
+
await db.schema
|
|
46
|
+
.createTable('transactions_new')
|
|
47
|
+
.addColumn('command_id', 'text', (col) => col.primaryKey())
|
|
48
|
+
.addColumn('status', 'text', (col) => col.notNull())
|
|
49
|
+
.addColumn('prepared_transaction', 'text', (col) => col.notNull())
|
|
50
|
+
.addColumn('prepared_transaction_hash', 'text', (col) => col.notNull())
|
|
51
|
+
.addColumn('payload', 'text')
|
|
52
|
+
.addColumn('origin', 'text')
|
|
53
|
+
.addColumn('user_id', 'text', (col) => col.notNull())
|
|
54
|
+
.addColumn('network_id', 'text', (col) => col.references('networks.id').onDelete('cascade').notNull())
|
|
55
|
+
.addColumn('created_at', 'text')
|
|
56
|
+
.addColumn('signed_at', 'text')
|
|
57
|
+
.addColumn('external_tx_id', 'text')
|
|
58
|
+
.execute();
|
|
59
|
+
await sql `
|
|
60
|
+
INSERT INTO transactions_new (
|
|
61
|
+
command_id,
|
|
62
|
+
status,
|
|
63
|
+
prepared_transaction,
|
|
64
|
+
prepared_transaction_hash,
|
|
65
|
+
payload,
|
|
66
|
+
origin,
|
|
67
|
+
user_id,
|
|
68
|
+
network_id,
|
|
69
|
+
created_at,
|
|
70
|
+
signed_at,
|
|
71
|
+
external_tx_id
|
|
72
|
+
)
|
|
73
|
+
SELECT
|
|
74
|
+
command_id,
|
|
75
|
+
status,
|
|
76
|
+
prepared_transaction,
|
|
77
|
+
prepared_transaction_hash,
|
|
78
|
+
payload,
|
|
79
|
+
origin,
|
|
80
|
+
user_id,
|
|
81
|
+
network_id,
|
|
82
|
+
created_at,
|
|
83
|
+
signed_at,
|
|
84
|
+
external_tx_id
|
|
85
|
+
FROM transactions
|
|
86
|
+
`.execute(db);
|
|
87
|
+
await db.schema.dropTable('transactions').execute();
|
|
88
|
+
await db.schema
|
|
89
|
+
.alterTable('transactions_new')
|
|
90
|
+
.renameTo('transactions')
|
|
91
|
+
.execute();
|
|
92
|
+
}
|
|
93
|
+
export async function down(db) {
|
|
94
|
+
console.log('Dropping network_id column from transactions table');
|
|
95
|
+
const pg = await isPostgres(db);
|
|
96
|
+
if (pg) {
|
|
97
|
+
await sql `
|
|
98
|
+
ALTER TABLE transactions
|
|
99
|
+
DROP CONSTRAINT IF EXISTS transactions_network_fk
|
|
100
|
+
`.execute(db);
|
|
101
|
+
await sql `
|
|
102
|
+
ALTER TABLE transactions
|
|
103
|
+
DROP COLUMN network_id
|
|
104
|
+
`.execute(db);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// SQLite: recreate table without network_id.
|
|
108
|
+
await db.schema.dropTable('transactions_new').ifExists().execute();
|
|
109
|
+
await db.schema
|
|
110
|
+
.createTable('transactions_new')
|
|
111
|
+
.addColumn('command_id', 'text', (col) => col.primaryKey())
|
|
112
|
+
.addColumn('status', 'text', (col) => col.notNull())
|
|
113
|
+
.addColumn('prepared_transaction', 'text', (col) => col.notNull())
|
|
114
|
+
.addColumn('prepared_transaction_hash', 'text', (col) => col.notNull())
|
|
115
|
+
.addColumn('payload', 'text')
|
|
116
|
+
.addColumn('origin', 'text')
|
|
117
|
+
.addColumn('user_id', 'text', (col) => col.notNull())
|
|
118
|
+
.addColumn('created_at', 'text')
|
|
119
|
+
.addColumn('signed_at', 'text')
|
|
120
|
+
.addColumn('external_tx_id', 'text')
|
|
121
|
+
.execute();
|
|
122
|
+
await sql `
|
|
123
|
+
INSERT INTO transactions_new (
|
|
124
|
+
command_id,
|
|
125
|
+
status,
|
|
126
|
+
prepared_transaction,
|
|
127
|
+
prepared_transaction_hash,
|
|
128
|
+
payload,
|
|
129
|
+
origin,
|
|
130
|
+
user_id,
|
|
131
|
+
created_at,
|
|
132
|
+
signed_at,
|
|
133
|
+
external_tx_id
|
|
134
|
+
)
|
|
135
|
+
SELECT
|
|
136
|
+
command_id,
|
|
137
|
+
status,
|
|
138
|
+
prepared_transaction,
|
|
139
|
+
prepared_transaction_hash,
|
|
140
|
+
payload,
|
|
141
|
+
origin,
|
|
142
|
+
user_id,
|
|
143
|
+
created_at,
|
|
144
|
+
signed_at,
|
|
145
|
+
external_tx_id
|
|
146
|
+
FROM transactions
|
|
147
|
+
`.execute(db);
|
|
148
|
+
await db.schema.dropTable('transactions').execute();
|
|
149
|
+
await db.schema
|
|
150
|
+
.alterTable('transactions_new')
|
|
151
|
+
.renameTo('transactions')
|
|
152
|
+
.execute();
|
|
153
|
+
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Idp, UserId } from '@canton-network/core-wallet-auth';
|
|
2
|
-
import { Wallet, Transaction, Session, Network, WalletStatus, UpdateWallet } from '@canton-network/core-wallet-store';
|
|
2
|
+
import { Wallet, Transaction, Session, Network, WalletStatus, UpdateWallet, PartyLevelRight, UserLevelRight } from '@canton-network/core-wallet-store';
|
|
3
3
|
interface MigrationTable {
|
|
4
4
|
name: string;
|
|
5
5
|
executedAt: string;
|
|
@@ -21,6 +21,11 @@ interface NetworkTable {
|
|
|
21
21
|
auth: string;
|
|
22
22
|
adminAuth: string | undefined;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Wallet table schema
|
|
26
|
+
* Primary key on (partyId, networkId, userId)
|
|
27
|
+
* Unique constraint on (networkId, userId) for primary wallet per network per user
|
|
28
|
+
*/
|
|
24
29
|
interface WalletTable {
|
|
25
30
|
primary: number;
|
|
26
31
|
partyId: string;
|
|
@@ -30,23 +35,35 @@ interface WalletTable {
|
|
|
30
35
|
networkId: string;
|
|
31
36
|
signingProviderId: string;
|
|
32
37
|
userId: UserId;
|
|
33
|
-
externalTxId
|
|
34
|
-
topologyTransactions
|
|
35
|
-
status
|
|
38
|
+
externalTxId: string | null;
|
|
39
|
+
topologyTransactions: string | null;
|
|
40
|
+
status: string | null;
|
|
36
41
|
disabled: number;
|
|
37
|
-
reason
|
|
42
|
+
reason: string | null;
|
|
38
43
|
}
|
|
39
44
|
interface UpdateWalletProperties {
|
|
40
45
|
primary?: number;
|
|
41
|
-
externalTxId?: string;
|
|
42
|
-
topologyTransactions?: string;
|
|
43
|
-
status?: string;
|
|
46
|
+
externalTxId?: string | null;
|
|
47
|
+
topologyTransactions?: string | null;
|
|
48
|
+
status?: string | null;
|
|
44
49
|
disabled?: number;
|
|
45
|
-
reason?: string;
|
|
50
|
+
reason?: string | null;
|
|
51
|
+
}
|
|
52
|
+
interface UserPartyRightTable {
|
|
53
|
+
userId: UserId;
|
|
54
|
+
networkId: string;
|
|
55
|
+
partyId: string;
|
|
56
|
+
right: PartyLevelRight;
|
|
57
|
+
}
|
|
58
|
+
interface UserRightTable {
|
|
59
|
+
userId: UserId;
|
|
60
|
+
networkId: string;
|
|
61
|
+
right: UserLevelRight;
|
|
46
62
|
}
|
|
47
63
|
interface TransactionTable {
|
|
48
64
|
status: string;
|
|
49
65
|
commandId: string;
|
|
66
|
+
networkId: string;
|
|
50
67
|
preparedTransaction: string;
|
|
51
68
|
preparedTransactionHash: string;
|
|
52
69
|
payload: string | undefined;
|
|
@@ -65,6 +82,8 @@ export interface DB {
|
|
|
65
82
|
idps: IdpTable;
|
|
66
83
|
networks: NetworkTable;
|
|
67
84
|
wallets: WalletTable;
|
|
85
|
+
userPartyRights: UserPartyRightTable;
|
|
86
|
+
userRights: UserRightTable;
|
|
68
87
|
transactions: TransactionTable;
|
|
69
88
|
sessions: SessionTable;
|
|
70
89
|
}
|
|
@@ -74,9 +93,11 @@ export declare const toNetwork: (table: NetworkTable) => Network;
|
|
|
74
93
|
export declare const fromNetwork: (network: Network, userId?: UserId) => NetworkTable;
|
|
75
94
|
export declare const fromWallet: (wallet: Wallet, userId: UserId) => WalletTable;
|
|
76
95
|
export declare const toWalletUpdateProperties: (params: UpdateWallet) => UpdateWalletProperties;
|
|
77
|
-
export declare const toWalletStatus: (status?: string) => WalletStatus;
|
|
96
|
+
export declare const toWalletStatus: (status?: string | null) => WalletStatus;
|
|
78
97
|
export declare const toWallet: (table: WalletTable) => Wallet;
|
|
79
|
-
export declare const
|
|
98
|
+
export declare const fromPartyRight: (right: string) => PartyLevelRight | undefined;
|
|
99
|
+
export declare const fromUserRight: (right: string) => UserLevelRight | undefined;
|
|
100
|
+
export declare const fromTransaction: (transaction: Transaction, userId: UserId, networkId: string) => TransactionTable;
|
|
80
101
|
export declare const toTransaction: (table: TransactionTable) => Transaction;
|
|
81
102
|
export {};
|
|
82
103
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,GAAG,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EACH,MAAM,EACN,WAAW,EACX,OAAO,EACP,OAAO,EACP,YAAY,EACZ,YAAY,EACf,MAAM,mCAAmC,CAAA;AAE1C,UAAU,cAAc;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACrB;AAED,UAAU,QAAQ;IACd,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,OAAO,GAAG,aAAa,CAAA;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;CAChC;AAED,UAAU,YAAY;IAClB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,WAAW,EAAE,MAAM,CAAA;IACnB,gBAAgB,EAAE,MAAM,CAAA;IACxB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAE1B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;CAChC;AAED,UAAU,WAAW;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,iBAAiB,EAAE,MAAM,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,GA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e,EAAE,mBAAmB,CAAA;IACpC,UAAU,EAAE,cAAc,CAAA;IAC1B,YAAY,EAAE,gBAAgB,CAAA;IAC9B,QAAQ,EAAE,YAAY,CAAA;CACzB;AAED,eAAO,MAAM,KAAK,GAAI,OAAO,QAAQ,KAAG,GAqBvC,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,KAAK,GAAG,KAAG,QAiBlC,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,OAAO,YAAY,KAAG,OAqB/C,CAAA;AAED,eAAO,MAAM,WAAW,GACpB,SAAS,OAAO,EAChB,SAAS,MAAM,KAChB,YAcF,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM,KAAG,WAe3D,CAAA;AAGD,eAAO,MAAM,wBAAwB,GACjC,QAAQ,YAAY,KACrB,sBAiBF,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,GAAG,IAAI,KAAG,YAIvD,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,WAAW,KAAG,MAsB7C,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,eAAe,GAAG,SAKhE,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,cAAc,GAAG,SAK9D,CAAA;AAED,eAAO,MAAM,eAAe,GACxB,aAAa,WAAW,EACxB,QAAQ,MAAM,EACd,WAAW,MAAM,KAClB,gBAaF,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,gBAAgB,KAAG,WAuBvD,CAAA"}
|
package/dist/schema.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { authSchema } from '@canton-network/core-wallet-auth';
|
|
4
|
+
import { PartyLevelRight, UserLevelRight, } from '@canton-network/core-wallet-store';
|
|
4
5
|
export const toIdp = (table) => {
|
|
5
6
|
switch (table.type) {
|
|
6
7
|
case 'oauth': {
|
|
@@ -74,16 +75,18 @@ export const fromNetwork = (network, userId) => {
|
|
|
74
75
|
};
|
|
75
76
|
};
|
|
76
77
|
export const fromWallet = (wallet, userId) => {
|
|
77
|
-
const { externalTxId, topologyTransactions, ...rest } = wallet;
|
|
78
|
+
const { externalTxId, topologyTransactions, rights, ...rest } = wallet;
|
|
79
|
+
void rights;
|
|
78
80
|
return {
|
|
79
81
|
...rest,
|
|
80
82
|
primary: wallet.primary ? 1 : 0,
|
|
81
83
|
userId: userId,
|
|
82
84
|
disabled: wallet.disabled !== undefined && wallet.disabled ? 1 : 0,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
reason: wallet.reason ?? null,
|
|
86
|
+
externalTxId: externalTxId && externalTxId !== '' ? externalTxId : null,
|
|
87
|
+
topologyTransactions: topologyTransactions && topologyTransactions !== ''
|
|
88
|
+
? topologyTransactions
|
|
89
|
+
: null,
|
|
87
90
|
};
|
|
88
91
|
};
|
|
89
92
|
// only update fields that are explicitly provided to prevent data loss
|
|
@@ -116,20 +119,34 @@ export const toWallet = (table) => {
|
|
|
116
119
|
networkId: table.networkId,
|
|
117
120
|
signingProviderId: table.signingProviderId,
|
|
118
121
|
disabled: table.disabled === 1,
|
|
119
|
-
...(table.externalTxId !==
|
|
122
|
+
...(table.externalTxId !== null && {
|
|
120
123
|
externalTxId: table.externalTxId,
|
|
121
124
|
}),
|
|
122
|
-
...(table.topologyTransactions !==
|
|
125
|
+
...(table.topologyTransactions !== null && {
|
|
123
126
|
topologyTransactions: table.topologyTransactions,
|
|
124
127
|
}),
|
|
125
|
-
...(table.reason !==
|
|
128
|
+
...(table.reason !== null && {
|
|
126
129
|
reason: table.reason,
|
|
127
130
|
}),
|
|
131
|
+
rights: [],
|
|
128
132
|
};
|
|
129
133
|
};
|
|
130
|
-
export const
|
|
134
|
+
export const fromPartyRight = (right) => {
|
|
135
|
+
if (Object.values(PartyLevelRight).includes(right)) {
|
|
136
|
+
return right;
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
};
|
|
140
|
+
export const fromUserRight = (right) => {
|
|
141
|
+
if (Object.values(UserLevelRight).includes(right)) {
|
|
142
|
+
return right;
|
|
143
|
+
}
|
|
144
|
+
return undefined;
|
|
145
|
+
};
|
|
146
|
+
export const fromTransaction = (transaction, userId, networkId) => {
|
|
131
147
|
return {
|
|
132
148
|
...transaction,
|
|
149
|
+
networkId,
|
|
133
150
|
payload: transaction.payload
|
|
134
151
|
? JSON.stringify(transaction.payload)
|
|
135
152
|
: undefined,
|
package/dist/store-sql.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Logger } from 'pino';
|
|
2
2
|
import { AuthContext, AuthAware, Idp } from '@canton-network/core-wallet-auth';
|
|
3
|
-
import { Store as BaseStore, Wallet, PartyId, Session, WalletFilter, Transaction, Network, StoreConfig, UpdateWallet, CurrentNetworkWalletFilter } from '@canton-network/core-wallet-store';
|
|
3
|
+
import { Store as BaseStore, Wallet, PartyId, Session, WalletFilter, Transaction, Network, StoreConfig, UpdateWallet, CurrentNetworkWalletFilter, UserLevelRight } from '@canton-network/core-wallet-store';
|
|
4
4
|
import { Kysely } from 'kysely';
|
|
5
5
|
import { DB } from './schema.js';
|
|
6
6
|
export declare class StoreSql implements BaseStore, AuthAware<StoreSql> {
|
|
@@ -17,6 +17,8 @@ export declare class StoreSql implements BaseStore, AuthAware<StoreSql> {
|
|
|
17
17
|
addWallet(wallet: Wallet): Promise<void>;
|
|
18
18
|
updateWallet(params: UpdateWallet): Promise<void>;
|
|
19
19
|
removeWallet(partyId: PartyId): Promise<void>;
|
|
20
|
+
getUserRights(networkId?: string): Promise<Array<UserLevelRight>>;
|
|
21
|
+
setUserRights(networkId: string, rights: Array<UserLevelRight>): Promise<void>;
|
|
20
22
|
getSession(): Promise<Session | undefined>;
|
|
21
23
|
setSession(session: Session): Promise<void>;
|
|
22
24
|
removeSession(): Promise<void>;
|
package/dist/store-sql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-sql.d.ts","sourceRoot":"","sources":["../src/store-sql.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EACH,WAAW,EAEX,SAAS,EAET,GAAG,EACN,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACH,KAAK,IAAI,SAAS,EAClB,MAAM,EACN,OAAO,EACP,OAAO,EACP,YAAY,EACZ,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,0BAA0B,
|
|
1
|
+
{"version":3,"file":"store-sql.d.ts","sourceRoot":"","sources":["../src/store-sql.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EACH,WAAW,EAEX,SAAS,EAET,GAAG,EACN,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACH,KAAK,IAAI,SAAS,EAClB,MAAM,EACN,OAAO,EACP,OAAO,EACP,YAAY,EACZ,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,0BAA0B,EAE1B,cAAc,EACjB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAmB,MAAM,EAAkC,MAAM,QAAQ,CAAA;AAEhF,OAAO,EACH,EAAE,EAYL,MAAM,aAAa,CAAA;AAGpB,qBAAa,QAAS,YAAW,SAAS,EAAE,SAAS,CAAC,QAAQ,CAAC;IAIvD,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,MAAM;IAJlB,WAAW,EAAE,WAAW,GAAG,SAAS,CAAA;gBAGxB,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,EACd,MAAM,EAAE,MAAM,EACtB,WAAW,CAAC,EAAE,WAAW;IAM7B,eAAe,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,QAAQ;IAIh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IAsBvC,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAW/C,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAkBrC,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAmBvC,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAe9C,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B3C,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB/C,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBvD,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAiBnE,gBAAgB,IAAI,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAgB/C,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAc5D;AAED,eAAO,MAAM,UAAU,GAAI,QAAQ,WAAW,eA8B7C,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canton-network/core-wallet-store-sql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SQL implementation of the Store API",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"test": "yarn node --experimental-vm-modules $(yarn bin jest)"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@canton-network/core-ledger-client": "^0.
|
|
29
|
-
"@canton-network/core-rpc-errors": "^0.19.
|
|
30
|
-
"@canton-network/core-wallet-auth": "^0.24.
|
|
31
|
-
"@canton-network/core-wallet-store": "^0.
|
|
28
|
+
"@canton-network/core-ledger-client": "^0.33.1",
|
|
29
|
+
"@canton-network/core-rpc-errors": "^0.19.2",
|
|
30
|
+
"@canton-network/core-wallet-auth": "^0.24.2",
|
|
31
|
+
"@canton-network/core-wallet-store": "^0.28.1",
|
|
32
32
|
"better-sqlite3": "^12.6.2",
|
|
33
33
|
"commander": "^14.0.3",
|
|
34
|
-
"kysely": "^0.28.
|
|
34
|
+
"kysely": "^0.28.14",
|
|
35
35
|
"pg": "^8.19.0",
|
|
36
36
|
"pino": "^10.3.1",
|
|
37
37
|
"umzug": "^3.8.2",
|