@canton-network/core-signing-store-sql 0.12.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/schema.js ADDED
@@ -0,0 +1,96 @@
1
+ // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { z } from 'zod';
4
+ // Signing driver conversion functions
5
+ export const fromSigningKey = (key, userId, encrypt) => {
6
+ return {
7
+ id: key.id,
8
+ userId: userId,
9
+ name: key.name,
10
+ publicKey: key.publicKey,
11
+ privateKey: key.privateKey
12
+ ? encrypt
13
+ ? encrypt(key.privateKey)
14
+ : key.privateKey
15
+ : null,
16
+ metadata: key.metadata ? JSON.stringify(key.metadata) : null,
17
+ createdAt: key.createdAt.toISOString(),
18
+ updatedAt: key.updatedAt.toISOString(),
19
+ };
20
+ };
21
+ export const toSigningKey = (table, decrypt) => {
22
+ return {
23
+ id: table.id,
24
+ name: table.name,
25
+ publicKey: table.publicKey,
26
+ ...(table.privateKey
27
+ ? {
28
+ privateKey: decrypt
29
+ ? decrypt(table.privateKey)
30
+ : table.privateKey,
31
+ }
32
+ : {}),
33
+ createdAt: new Date(table.createdAt),
34
+ updatedAt: new Date(table.updatedAt),
35
+ ...(table.metadata ? { metadata: JSON.parse(table.metadata) } : {}),
36
+ };
37
+ };
38
+ export const fromSigningTransaction = (transaction, userId) => {
39
+ return {
40
+ id: transaction.id,
41
+ userId: userId,
42
+ hash: transaction.hash,
43
+ signature: transaction.signature || null,
44
+ publicKey: transaction.publicKey,
45
+ status: transaction.status,
46
+ metadata: transaction.metadata
47
+ ? JSON.stringify(transaction.metadata)
48
+ : null,
49
+ createdAt: transaction.createdAt.toISOString(),
50
+ updatedAt: transaction.updatedAt.toISOString(),
51
+ };
52
+ };
53
+ export const toSigningTransaction = (table) => {
54
+ return {
55
+ id: table.id,
56
+ hash: table.hash,
57
+ ...(table.signature ? { signature: table.signature } : {}),
58
+ publicKey: table.publicKey,
59
+ status: table.status,
60
+ ...(table.metadata ? { metadata: JSON.parse(table.metadata) } : {}),
61
+ createdAt: new Date(table.createdAt),
62
+ updatedAt: new Date(table.updatedAt),
63
+ };
64
+ };
65
+ export const fromSigningDriverConfig = (config, userId) => {
66
+ return {
67
+ userId: userId,
68
+ driverId: config.driverId,
69
+ config: JSON.stringify(config.config),
70
+ };
71
+ };
72
+ export const toSigningDriverConfig = (table) => {
73
+ return {
74
+ driverId: table.driverId,
75
+ config: JSON.parse(table.config),
76
+ };
77
+ };
78
+ export const storeConfigSchema = z.object({
79
+ connection: z.discriminatedUnion('type', [
80
+ z.object({
81
+ type: z.literal('memory'),
82
+ }),
83
+ z.object({
84
+ type: z.literal('sqlite'),
85
+ database: z.string(),
86
+ }),
87
+ z.object({
88
+ type: z.literal('postgres'),
89
+ host: z.string(),
90
+ port: z.number(),
91
+ user: z.string(),
92
+ password: z.string(),
93
+ database: z.string(),
94
+ }),
95
+ ]),
96
+ });
@@ -0,0 +1,29 @@
1
+ import { Logger } from 'pino';
2
+ import { AuthContext, AuthAware } from '@canton-network/core-wallet-auth';
3
+ import { SigningDriverStore, SigningKey, SigningTransaction, SigningDriverStatus, SigningDriverConfig } from '@canton-network/core-signing-lib';
4
+ import { Kysely } from 'kysely';
5
+ import { DB, StoreConfig } from './schema.js';
6
+ export declare class StoreSql implements SigningDriverStore, AuthAware<StoreSql> {
7
+ private db;
8
+ private logger;
9
+ authContext: AuthContext | undefined;
10
+ constructor(db: Kysely<DB>, logger: Logger, authContext?: AuthContext);
11
+ withAuthContext(context?: AuthContext): StoreSql;
12
+ private assertConnected;
13
+ getSigningKey(userId: string, keyId: string): Promise<SigningKey | undefined>;
14
+ getSigningKeyByPublicKey(publicKey: string): Promise<SigningKey | undefined>;
15
+ setSigningKey(userId: string, key: SigningKey): Promise<void>;
16
+ deleteSigningKey(userId: string, keyId: string): Promise<void>;
17
+ listSigningKeys(userId: string): Promise<SigningKey[]>;
18
+ getSigningTransaction(userId: string, txId: string): Promise<SigningTransaction | undefined>;
19
+ setSigningTransaction(userId: string, transaction: SigningTransaction): Promise<void>;
20
+ updateSigningTransactionStatus(userId: string, txId: string, status: SigningDriverStatus): Promise<void>;
21
+ listSigningTransactions(userId: string, limit?: number, before?: string): Promise<SigningTransaction[]>;
22
+ listSigningTransactionsByTxIdsAndPublicKeys(txIds: string[], publicKeys: string[]): Promise<SigningTransaction[]>;
23
+ getSigningDriverConfiguration(userId: string, driverId: string): Promise<SigningDriverConfig | undefined>;
24
+ setSigningDriverConfiguration(userId: string, config: SigningDriverConfig): Promise<void>;
25
+ setSigningKeys(userId: string, keys: SigningKey[]): Promise<void>;
26
+ setSigningTransactions(userId: string, transactions: SigningTransaction[]): Promise<void>;
27
+ }
28
+ export declare const connection: (config: StoreConfig) => Kysely<DB>;
29
+ //# sourceMappingURL=store-sql.d.ts.map
@@ -0,0 +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,EAEZ,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACH,kBAAkB,EAClB,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAmB,MAAM,EAAiB,MAAM,QAAQ,CAAA;AAE/D,OAAO,EACH,EAAE,EAQF,WAAW,EACd,MAAM,aAAa,CAAA;AAEpB,qBAAa,QAAS,YAAW,kBAAkB,EAAE,SAAS,CAAC,QAAQ,CAAC;IAIhE,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;IA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,MAAM,EACd,MAAM,EAAE,mBAAmB,GAC5B,OAAO,CAAC,IAAI,CAAC;IAcV,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBjE,sBAAsB,CACxB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,kBAAkB,EAAE,GACnC,OAAO,CAAC,IAAI,CAAC;CAsBnB;AAED,eAAO,MAAM,UAAU,GAAI,QAAQ,WAAW,eAqB7C,CAAA"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@canton-network/core-signing-store-sql",
3
+ "version": "0.12.0",
4
+ "type": "module",
5
+ "repository": "github:hyperledger-labs/splice-wallet-kernel",
6
+ "description": "SQL implementation of the Store API",
7
+ "license": "Apache-2.0",
8
+ "author": "Marc Juchli <marc.juchli@digitalasset.com>",
9
+ "packageManager": "yarn@4.9.4",
10
+ "main": "dist/index.cjs",
11
+ "module": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "scripts": {
22
+ "build": "tsup && tsc -p tsconfig.types.json && tsc -b tsconfig.migrations.json",
23
+ "dev": "tsup --watch --onSuccess \"tsc -p tsconfig.types.json && tsc -b tsconfig.migrations.json\"",
24
+ "flatpack": "yarn pack --out \"$FLATPACK_OUTDIR\"",
25
+ "clean": "tsc -b --clean; rm -rf dist"
26
+ },
27
+ "dependencies": {
28
+ "@canton-network/core-ledger-client": "^0.18.0",
29
+ "@canton-network/core-rpc-errors": "^0.8.0",
30
+ "@canton-network/core-signing-lib": "^0.13.0",
31
+ "@canton-network/core-wallet-auth": "^0.12.0",
32
+ "@canton-network/core-wallet-store": "^0.11.0",
33
+ "better-sqlite3": "^12.2.0",
34
+ "commander": "^14.0.0",
35
+ "kysely": "^0.28.5",
36
+ "pino": "^10.0.0",
37
+ "umzug": "^3.8.2",
38
+ "zod": "^3.25.64"
39
+ },
40
+ "devDependencies": {
41
+ "@swc/core": "^1.11.31",
42
+ "@types/better-sqlite3": "^7.6.13",
43
+ "tsup": "^8.5.0",
44
+ "tsx": "^4.20.4",
45
+ "typescript": "^5.8.3"
46
+ },
47
+ "files": [
48
+ "dist/**"
49
+ ],
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }