@breeztech/breez-sdk-spark 0.15.0 → 0.16.1-dev1
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/breez-sdk-spark.tgz +0 -0
- package/bundler/breez_sdk_spark_wasm.d.ts +511 -215
- package/bundler/breez_sdk_spark_wasm.js +1 -1
- package/bundler/breez_sdk_spark_wasm_bg.js +567 -414
- package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +55 -46
- package/bundler/storage/index.js +205 -15
- package/deno/breez_sdk_spark_wasm.d.ts +511 -215
- package/deno/breez_sdk_spark_wasm.js +567 -414
- package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +55 -46
- package/nodejs/breez_sdk_spark_wasm.d.ts +511 -215
- package/nodejs/breez_sdk_spark_wasm.js +578 -421
- package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +55 -46
- package/nodejs/index.js +10 -10
- package/nodejs/index.mjs +12 -8
- package/nodejs/mysql-session-store/errors.cjs +13 -0
- package/nodejs/{mysql-session-manager → mysql-session-store}/index.cjs +24 -21
- package/nodejs/{mysql-session-manager → mysql-session-store}/migrations.cjs +17 -11
- package/nodejs/mysql-session-store/package.json +9 -0
- package/nodejs/mysql-storage/index.cjs +229 -111
- package/nodejs/mysql-storage/migrations.cjs +37 -2
- package/nodejs/mysql-token-store/index.cjs +99 -79
- package/nodejs/mysql-token-store/migrations.cjs +59 -2
- package/nodejs/mysql-tree-store/index.cjs +15 -9
- package/nodejs/mysql-tree-store/migrations.cjs +16 -2
- package/nodejs/package.json +2 -2
- package/nodejs/postgres-session-store/errors.cjs +13 -0
- package/nodejs/{postgres-session-manager → postgres-session-store}/index.cjs +23 -23
- package/nodejs/{postgres-session-manager → postgres-session-store}/migrations.cjs +14 -14
- package/nodejs/postgres-session-store/package.json +9 -0
- package/nodejs/postgres-storage/index.cjs +174 -107
- package/nodejs/postgres-storage/migrations.cjs +24 -0
- package/nodejs/postgres-token-store/index.cjs +89 -64
- package/nodejs/postgres-token-store/migrations.cjs +44 -0
- package/nodejs/storage/index.cjs +167 -113
- package/nodejs/storage/migrations.cjs +23 -0
- package/package.json +6 -1
- package/ssr/index.js +52 -28
- package/web/breez_sdk_spark_wasm.d.ts +566 -261
- package/web/breez_sdk_spark_wasm.js +567 -414
- package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +55 -46
- package/web/passkey-prf-provider/index.d.ts +203 -0
- package/web/passkey-prf-provider/index.js +733 -0
- package/web/storage/index.js +205 -15
- package/nodejs/mysql-session-manager/errors.cjs +0 -13
- package/nodejs/mysql-session-manager/package.json +0 -9
- package/nodejs/postgres-session-manager/errors.cjs +0 -13
- package/nodejs/postgres-session-manager/package.json +0 -9
|
Binary file
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_bitcoinchainservicehandle_free: (a: number, b: number) => void;
|
|
5
5
|
export const __wbg_breezsdk_free: (a: number, b: number) => void;
|
|
6
|
-
export const
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
9
|
-
export const __wbg_postgresconnectionpool_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_externalsigners_free: (a: number, b: number) => void;
|
|
7
|
+
export const __wbg_passkeyclient_free: (a: number, b: number) => void;
|
|
8
|
+
export const __wbg_passkeylabels_free: (a: number, b: number) => void;
|
|
10
9
|
export const __wbg_sdkbuilder_free: (a: number, b: number) => void;
|
|
11
10
|
export const __wbg_tokenissuer_free: (a: number, b: number) => void;
|
|
12
11
|
export const __wbg_wasmsdkcontext_free: (a: number, b: number) => void;
|
|
12
|
+
export const __wbg_wasmstorageconfig_free: (a: number, b: number) => void;
|
|
13
13
|
export const bitcoinchainservicehandle_broadcastTransaction: (a: number, b: number, c: number) => any;
|
|
14
14
|
export const bitcoinchainservicehandle_getAddressUtxos: (a: number, b: number, c: number) => any;
|
|
15
15
|
export const bitcoinchainservicehandle_getTransactionHex: (a: number, b: number, c: number) => any;
|
|
@@ -17,18 +17,18 @@ export const bitcoinchainservicehandle_getTransactionStatus: (a: number, b: numb
|
|
|
17
17
|
export const bitcoinchainservicehandle_recommendedFees: (a: number) => any;
|
|
18
18
|
export const breezsdk_addContact: (a: number, b: any) => any;
|
|
19
19
|
export const breezsdk_addEventListener: (a: number, b: any) => any;
|
|
20
|
+
export const breezsdk_authorizeLightningAddressTransfer: (a: number, b: any) => any;
|
|
20
21
|
export const breezsdk_buyBitcoin: (a: number, b: any) => any;
|
|
21
|
-
export const breezsdk_cancelLeafOptimization: (a: number) => any;
|
|
22
22
|
export const breezsdk_checkLightningAddressAvailable: (a: number, b: any) => any;
|
|
23
23
|
export const breezsdk_checkMessage: (a: number, b: any) => any;
|
|
24
24
|
export const breezsdk_claimDeposit: (a: number, b: any) => any;
|
|
25
25
|
export const breezsdk_claimHtlcPayment: (a: number, b: any) => any;
|
|
26
|
+
export const breezsdk_claimLightningAddressTransfer: (a: number, b: any) => any;
|
|
26
27
|
export const breezsdk_deleteContact: (a: number, b: number, c: number) => any;
|
|
27
28
|
export const breezsdk_deleteLightningAddress: (a: number) => any;
|
|
28
29
|
export const breezsdk_disconnect: (a: number) => any;
|
|
29
30
|
export const breezsdk_fetchConversionLimits: (a: number, b: any) => any;
|
|
30
31
|
export const breezsdk_getInfo: (a: number, b: any) => any;
|
|
31
|
-
export const breezsdk_getLeafOptimizationProgress: (a: number) => any;
|
|
32
32
|
export const breezsdk_getLightningAddress: (a: number) => any;
|
|
33
33
|
export const breezsdk_getPayment: (a: number, b: any) => any;
|
|
34
34
|
export const breezsdk_getTokenIssuer: (a: number) => number;
|
|
@@ -43,6 +43,7 @@ export const breezsdk_listWebhooks: (a: number) => any;
|
|
|
43
43
|
export const breezsdk_lnurlAuth: (a: number, b: any) => any;
|
|
44
44
|
export const breezsdk_lnurlPay: (a: number, b: any) => any;
|
|
45
45
|
export const breezsdk_lnurlWithdraw: (a: number, b: any) => any;
|
|
46
|
+
export const breezsdk_optimizeLeaves: (a: number, b: any) => any;
|
|
46
47
|
export const breezsdk_parse: (a: number, b: number, c: number) => any;
|
|
47
48
|
export const breezsdk_prepareLnurlPay: (a: number, b: any) => any;
|
|
48
49
|
export const breezsdk_prepareSendPayment: (a: number, b: any) => any;
|
|
@@ -55,65 +56,71 @@ export const breezsdk_registerWebhook: (a: number, b: any) => any;
|
|
|
55
56
|
export const breezsdk_removeEventListener: (a: number, b: number, c: number) => any;
|
|
56
57
|
export const breezsdk_sendPayment: (a: number, b: any) => any;
|
|
57
58
|
export const breezsdk_signMessage: (a: number, b: any) => any;
|
|
58
|
-
export const breezsdk_startLeafOptimization: (a: number) => any;
|
|
59
59
|
export const breezsdk_syncWallet: (a: number, b: any) => any;
|
|
60
60
|
export const breezsdk_unregisterWebhook: (a: number, b: any) => any;
|
|
61
61
|
export const breezsdk_updateContact: (a: number, b: any) => any;
|
|
62
62
|
export const breezsdk_updateUserSettings: (a: number, b: any) => any;
|
|
63
63
|
export const connect: (a: any) => any;
|
|
64
|
-
export const connectWithSigner: (a: any, b: any, c:
|
|
65
|
-
export const
|
|
66
|
-
export const createPostgresConnectionPool: (a: any) => [number, number, number];
|
|
64
|
+
export const connectWithSigner: (a: any, b: any, c: any, d: number, e: number) => any;
|
|
65
|
+
export const createTurnkeySigner: (a: any) => any;
|
|
67
66
|
export const defaultConfig: (a: any) => any;
|
|
68
|
-
export const
|
|
67
|
+
export const defaultExternalSigners: (a: number, b: number, c: number, d: number, e: any, f: number) => [number, number, number];
|
|
69
68
|
export const defaultMysqlStorageConfig: (a: number, b: number) => any;
|
|
70
69
|
export const defaultPostgresStorageConfig: (a: number, b: number) => any;
|
|
71
70
|
export const defaultServerConfig: (a: any) => any;
|
|
72
|
-
export const
|
|
73
|
-
export const
|
|
74
|
-
export const
|
|
75
|
-
export const
|
|
76
|
-
export const
|
|
77
|
-
export const
|
|
78
|
-
export const
|
|
79
|
-
export const
|
|
80
|
-
export const
|
|
81
|
-
export const
|
|
82
|
-
export const
|
|
83
|
-
export const
|
|
84
|
-
export const
|
|
85
|
-
export const
|
|
86
|
-
export const
|
|
87
|
-
export const
|
|
88
|
-
export const
|
|
89
|
-
export const
|
|
90
|
-
export const
|
|
91
|
-
export const
|
|
71
|
+
export const defaultStorage: (a: number, b: number) => number;
|
|
72
|
+
export const externalbreezsignerhandle_decryptEcies: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
73
|
+
export const externalbreezsignerhandle_derivePublicKey: (a: number, b: number, c: number) => any;
|
|
74
|
+
export const externalbreezsignerhandle_encryptEcies: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
75
|
+
export const externalbreezsignerhandle_hmacSha256: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
76
|
+
export const externalbreezsignerhandle_signEcdsa: (a: number, b: any, c: number, d: number) => any;
|
|
77
|
+
export const externalbreezsignerhandle_signEcdsaRecoverable: (a: number, b: any, c: number, d: number) => any;
|
|
78
|
+
export const externalbreezsignerhandle_signHashSchnorr: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
79
|
+
export const externalsigners_breezSigner: (a: number) => number;
|
|
80
|
+
export const externalsigners_sparkSigner: (a: number) => number;
|
|
81
|
+
export const externalsparksignerhandle_getIdentityPublicKey: (a: number) => any;
|
|
82
|
+
export const externalsparksignerhandle_getPublicKeyForLeaf: (a: number, b: any) => any;
|
|
83
|
+
export const externalsparksignerhandle_getStaticDepositPublicKey: (a: number, b: number) => any;
|
|
84
|
+
export const externalsparksignerhandle_prepareClaim: (a: number, b: any) => any;
|
|
85
|
+
export const externalsparksignerhandle_prepareLightningReceive: (a: number, b: any) => any;
|
|
86
|
+
export const externalsparksignerhandle_prepareStaticDeposit: (a: number, b: any) => any;
|
|
87
|
+
export const externalsparksignerhandle_prepareStaticDepositClaim: (a: number, b: any) => any;
|
|
88
|
+
export const externalsparksignerhandle_prepareTokenTransaction: (a: number, b: any) => any;
|
|
89
|
+
export const externalsparksignerhandle_prepareTransfer: (a: number, b: any) => any;
|
|
90
|
+
export const externalsparksignerhandle_signAuthenticationChallenge: (a: number, b: number, c: number) => any;
|
|
91
|
+
export const externalsparksignerhandle_signFrost: (a: number, b: number, c: number) => any;
|
|
92
|
+
export const externalsparksignerhandle_signMessage: (a: number, b: number, c: number) => any;
|
|
93
|
+
export const externalsparksignerhandle_signSparkInvoice: (a: number, b: any) => any;
|
|
94
|
+
export const externalsparksignerhandle_signStaticDepositRefund: (a: number, b: any) => any;
|
|
95
|
+
export const externalsparksignerhandle_startStaticDepositRefund: (a: number, b: any) => any;
|
|
92
96
|
export const getSparkStatus: () => any;
|
|
93
97
|
export const initLogging: (a: any, b: number, c: number) => any;
|
|
98
|
+
export const mysqlStorage: (a: any) => number;
|
|
94
99
|
export const newRestChainService: (a: number, b: number, c: any, d: any, e: number) => any;
|
|
95
100
|
export const newSharedSdkContext: (a: any) => any;
|
|
96
|
-
export const
|
|
97
|
-
export const
|
|
98
|
-
export const
|
|
99
|
-
export const
|
|
100
|
-
export const
|
|
101
|
+
export const passkeyclient_checkAvailability: (a: number) => any;
|
|
102
|
+
export const passkeyclient_labels: (a: number) => number;
|
|
103
|
+
export const passkeyclient_new: (a: any, b: number, c: number, d: number) => number;
|
|
104
|
+
export const passkeyclient_register: (a: number, b: any) => any;
|
|
105
|
+
export const passkeyclient_signIn: (a: number, b: any) => any;
|
|
106
|
+
export const passkeylabels_list: (a: number) => any;
|
|
107
|
+
export const passkeylabels_store: (a: number, b: number, c: number) => any;
|
|
108
|
+
export const postgresStorage: (a: any) => number;
|
|
101
109
|
export const sdkbuilder_build: (a: number) => any;
|
|
102
110
|
export const sdkbuilder_new: (a: any, b: any) => number;
|
|
103
|
-
export const sdkbuilder_newWithSigner: (a: any, b: any) => number;
|
|
111
|
+
export const sdkbuilder_newWithSigner: (a: any, b: any, c: any) => number;
|
|
112
|
+
export const sdkbuilder_withAccountNumber: (a: number, b: number) => number;
|
|
104
113
|
export const sdkbuilder_withChainService: (a: number, b: any) => number;
|
|
105
114
|
export const sdkbuilder_withDefaultStorage: (a: number, b: number, c: number) => any;
|
|
106
115
|
export const sdkbuilder_withFiatService: (a: number, b: any) => number;
|
|
107
|
-
export const sdkbuilder_withKeySet: (a: number, b: any) => number;
|
|
108
116
|
export const sdkbuilder_withLnurlClient: (a: number, b: any) => number;
|
|
109
117
|
export const sdkbuilder_withMysqlBackend: (a: number, b: any) => [number, number, number];
|
|
110
|
-
export const sdkbuilder_withMysqlConnectionPool: (a: number, b: number) => number;
|
|
111
118
|
export const sdkbuilder_withPaymentObserver: (a: number, b: any) => number;
|
|
112
119
|
export const sdkbuilder_withPostgresBackend: (a: number, b: any) => [number, number, number];
|
|
113
|
-
export const sdkbuilder_withPostgresConnectionPool: (a: number, b: number) => number;
|
|
114
120
|
export const sdkbuilder_withRestChainService: (a: number, b: number, c: number, d: any, e: number) => number;
|
|
115
121
|
export const sdkbuilder_withSharedContext: (a: number, b: number) => number;
|
|
116
122
|
export const sdkbuilder_withStorage: (a: number, b: any) => number;
|
|
123
|
+
export const sdkbuilder_withStorageBackend: (a: number, b: number) => number;
|
|
117
124
|
export const tokenissuer_burnIssuerToken: (a: number, b: any) => any;
|
|
118
125
|
export const tokenissuer_createIssuerToken: (a: number, b: any) => any;
|
|
119
126
|
export const tokenissuer_freezeIssuerToken: (a: number, b: any) => any;
|
|
@@ -139,16 +146,18 @@ export const intounderlyingsink_close: (a: number) => any;
|
|
|
139
146
|
export const intounderlyingsink_write: (a: number, b: any) => any;
|
|
140
147
|
export const intounderlyingsource_cancel: (a: number) => void;
|
|
141
148
|
export const intounderlyingsource_pull: (a: number, b: any) => any;
|
|
142
|
-
export const
|
|
143
|
-
export const
|
|
144
|
-
export const
|
|
145
|
-
export const
|
|
146
|
-
export const
|
|
149
|
+
export const __wbg_externalbreezsignerhandle_free: (a: number, b: number) => void;
|
|
150
|
+
export const __wbg_externalsparksignerhandle_free: (a: number, b: number) => void;
|
|
151
|
+
export const wasm_bindgen__convert__closures_____invoke__h4bd7a023e323559c: (a: number, b: number, c: any) => [number, number];
|
|
152
|
+
export const wasm_bindgen__convert__closures_____invoke__h4bd7a023e323559c_4: (a: number, b: number, c: any) => [number, number];
|
|
153
|
+
export const wasm_bindgen__convert__closures_____invoke__h4bd7a023e323559c_5: (a: number, b: number, c: any) => [number, number];
|
|
154
|
+
export const wasm_bindgen__convert__closures_____invoke__h4bd7a023e323559c_6: (a: number, b: number, c: any) => [number, number];
|
|
155
|
+
export const wasm_bindgen__convert__closures_____invoke__h4bd7a023e323559c_7: (a: number, b: number, c: any) => [number, number];
|
|
147
156
|
export const wasm_bindgen__convert__closures_____invoke__h41057d61edf43a32: (a: number, b: number, c: any, d: any) => void;
|
|
148
157
|
export const wasm_bindgen__convert__closures_____invoke__h4819aba3eed2db57: (a: number, b: number, c: any) => void;
|
|
149
158
|
export const wasm_bindgen__convert__closures_____invoke__h4819aba3eed2db57_2: (a: number, b: number, c: any) => void;
|
|
150
159
|
export const wasm_bindgen__convert__closures_____invoke__h4819aba3eed2db57_3: (a: number, b: number, c: any) => void;
|
|
151
|
-
export const
|
|
160
|
+
export const wasm_bindgen__convert__closures_____invoke__h484cd36e13f37bd7: (a: number, b: number) => void;
|
|
152
161
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
153
162
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
154
163
|
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
package/nodejs/index.js
CHANGED
|
@@ -48,14 +48,14 @@ try {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
// Automatically import and set up the PostgreSQL session
|
|
51
|
+
// Automatically import and set up the PostgreSQL session store for Node.js
|
|
52
52
|
try {
|
|
53
|
-
const {
|
|
54
|
-
global.
|
|
55
|
-
global.
|
|
53
|
+
const { createPostgresSessionStore, createPostgresSessionStoreWithPool } = require('./postgres-session-store/index.cjs');
|
|
54
|
+
global.createPostgresSessionStore = createPostgresSessionStore;
|
|
55
|
+
global.createPostgresSessionStoreWithPool = createPostgresSessionStoreWithPool;
|
|
56
56
|
} catch (error) {
|
|
57
57
|
if (error.code !== 'MODULE_NOT_FOUND') {
|
|
58
|
-
console.warn('Breez SDK: Failed to load PostgreSQL session
|
|
58
|
+
console.warn('Breez SDK: Failed to load PostgreSQL session store:', error.message);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -93,14 +93,14 @@ try {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
// Automatically import and set up the MySQL session
|
|
96
|
+
// Automatically import and set up the MySQL session store for Node.js
|
|
97
97
|
try {
|
|
98
|
-
const {
|
|
99
|
-
global.
|
|
100
|
-
global.
|
|
98
|
+
const { createMysqlSessionStore, createMysqlSessionStoreWithPool } = require('./mysql-session-store/index.cjs');
|
|
99
|
+
global.createMysqlSessionStore = createMysqlSessionStore;
|
|
100
|
+
global.createMysqlSessionStoreWithPool = createMysqlSessionStoreWithPool;
|
|
101
101
|
} catch (error) {
|
|
102
102
|
if (error.code !== 'MODULE_NOT_FOUND') {
|
|
103
|
-
console.warn('Breez SDK: Failed to load MySQL session
|
|
103
|
+
console.warn('Breez SDK: Failed to load MySQL session store:', error.message);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
package/nodejs/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ESM wrapper for the CJS Node.js entry
|
|
1
|
+
// ESM wrapper for the CJS Node.js entry: re-exports named bindings
|
|
2
2
|
// so that `import { connect } from '@breeztech/breez-sdk-spark'` works
|
|
3
3
|
// in ESM contexts.
|
|
4
4
|
import pkg from './index.js';
|
|
@@ -6,30 +6,34 @@ import pkg from './index.js';
|
|
|
6
6
|
export const {
|
|
7
7
|
connect,
|
|
8
8
|
connectWithSigner,
|
|
9
|
-
|
|
10
|
-
createPostgresConnectionPool,
|
|
9
|
+
createTurnkeySigner,
|
|
11
10
|
defaultConfig,
|
|
12
|
-
|
|
11
|
+
defaultExternalSigners,
|
|
13
12
|
defaultMysqlStorageConfig,
|
|
14
13
|
defaultPostgresStorageConfig,
|
|
15
14
|
defaultServerConfig,
|
|
15
|
+
defaultStorage,
|
|
16
16
|
getSparkStatus,
|
|
17
17
|
initLogging,
|
|
18
|
+
mysqlStorage,
|
|
18
19
|
newRestChainService,
|
|
19
20
|
newSharedSdkContext,
|
|
21
|
+
postgresStorage,
|
|
20
22
|
task_worker_entry_point,
|
|
21
23
|
BitcoinChainServiceHandle,
|
|
22
24
|
BreezSdk,
|
|
23
|
-
|
|
25
|
+
ExternalBreezSignerHandle,
|
|
26
|
+
ExternalSigners,
|
|
27
|
+
ExternalSparkSignerHandle,
|
|
24
28
|
IntoUnderlyingByteSource,
|
|
25
29
|
IntoUnderlyingSink,
|
|
26
30
|
IntoUnderlyingSource,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
PostgresConnectionPool,
|
|
31
|
+
PasskeyClient,
|
|
32
|
+
PasskeyLabels,
|
|
30
33
|
SdkBuilder,
|
|
31
34
|
TokenIssuer,
|
|
32
35
|
WasmSdkContext,
|
|
36
|
+
WasmStorageConfig,
|
|
33
37
|
} = pkg;
|
|
34
38
|
|
|
35
39
|
export default pkg;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// errors.cjs - Session store error wrapper with cause chain support
|
|
2
|
+
class SessionStoreError extends Error {
|
|
3
|
+
constructor(message, cause = null) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'SessionStoreError';
|
|
6
|
+
this.cause = cause;
|
|
7
|
+
if (Error.captureStackTrace) {
|
|
8
|
+
Error.captureStackTrace(this, SessionStoreError);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = { SessionStoreError };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CommonJS implementation for Node.js MySQL Session
|
|
2
|
+
* CommonJS implementation for Node.js MySQL Session Store.
|
|
3
3
|
*
|
|
4
|
-
* Mirrors `postgres-session-
|
|
4
|
+
* Mirrors `postgres-session-store/index.cjs` for MySQL 8.0+.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
let mysql;
|
|
@@ -23,10 +23,10 @@ try {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const {
|
|
27
|
-
const {
|
|
26
|
+
const { SessionStoreError } = require("./errors.cjs");
|
|
27
|
+
const { MysqlSessionStoreMigrationManager } = require("./migrations.cjs");
|
|
28
28
|
|
|
29
|
-
class
|
|
29
|
+
class MysqlSessionStore {
|
|
30
30
|
/**
|
|
31
31
|
* @param {import('mysql2/promise').Pool} pool
|
|
32
32
|
* @param {Buffer|Uint8Array} identity - 33-byte secp256k1 compressed pubkey
|
|
@@ -35,7 +35,7 @@ class MysqlSessionManager {
|
|
|
35
35
|
*/
|
|
36
36
|
constructor(pool, identity, logger = null, runMigration = true) {
|
|
37
37
|
if (!identity || identity.length !== 33) {
|
|
38
|
-
throw new
|
|
38
|
+
throw new SessionStoreError(
|
|
39
39
|
"tenant identity (33-byte secp256k1 pubkey) is required"
|
|
40
40
|
);
|
|
41
41
|
}
|
|
@@ -48,13 +48,13 @@ class MysqlSessionManager {
|
|
|
48
48
|
async initialize() {
|
|
49
49
|
try {
|
|
50
50
|
if (this.runMigration) {
|
|
51
|
-
const migrationManager = new
|
|
51
|
+
const migrationManager = new MysqlSessionStoreMigrationManager(this.logger);
|
|
52
52
|
await migrationManager.migrate(this.pool);
|
|
53
53
|
}
|
|
54
54
|
return this;
|
|
55
55
|
} catch (error) {
|
|
56
|
-
throw new
|
|
57
|
-
`Failed to initialize MySQL session
|
|
56
|
+
throw new SessionStoreError(
|
|
57
|
+
`Failed to initialize MySQL session store: ${error.message}`,
|
|
58
58
|
error
|
|
59
59
|
);
|
|
60
60
|
}
|
|
@@ -88,7 +88,7 @@ class MysqlSessionManager {
|
|
|
88
88
|
expiration: Number(row.expiration),
|
|
89
89
|
};
|
|
90
90
|
} catch (error) {
|
|
91
|
-
throw new
|
|
91
|
+
throw new SessionStoreError(
|
|
92
92
|
`Failed to read session: ${error.message}`,
|
|
93
93
|
error
|
|
94
94
|
);
|
|
@@ -109,7 +109,7 @@ class MysqlSessionManager {
|
|
|
109
109
|
[this.identity, serviceKey, session.token, session.expiration]
|
|
110
110
|
);
|
|
111
111
|
} catch (error) {
|
|
112
|
-
throw new
|
|
112
|
+
throw new SessionStoreError(
|
|
113
113
|
`Failed to write session: ${error.message}`,
|
|
114
114
|
error
|
|
115
115
|
);
|
|
@@ -119,16 +119,19 @@ class MysqlSessionManager {
|
|
|
119
119
|
|
|
120
120
|
function _decodePubkey(hex) {
|
|
121
121
|
if (typeof hex !== "string" || hex.length !== 66) {
|
|
122
|
-
throw new
|
|
122
|
+
throw new SessionStoreError(
|
|
123
123
|
"service_identity_key must be a 66-character hex-encoded 33-byte pubkey"
|
|
124
124
|
);
|
|
125
125
|
}
|
|
126
126
|
return Buffer.from(hex, "hex");
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
async function
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
async function createMysqlSessionStore(poolConfig, identity, logger = null) {
|
|
130
|
+
// Serialize JS `Date` parameters as UTC strings rather than host-local
|
|
131
|
+
// time. Paired with explicit `UTC_TIMESTAMP(6)` on the server side, this
|
|
132
|
+
// keeps timestamp comparisons consistent regardless of the host TZ.
|
|
133
|
+
const pool = mysql.createPool({ ...poolConfig, timezone: "Z" });
|
|
134
|
+
const manager = new MysqlSessionStore(
|
|
132
135
|
pool,
|
|
133
136
|
identity,
|
|
134
137
|
logger,
|
|
@@ -138,13 +141,13 @@ async function createMysqlSessionManager(poolConfig, identity, logger = null) {
|
|
|
138
141
|
return manager;
|
|
139
142
|
}
|
|
140
143
|
|
|
141
|
-
async function
|
|
144
|
+
async function createMysqlSessionStoreWithPool(
|
|
142
145
|
pool,
|
|
143
146
|
identity,
|
|
144
147
|
logger = null,
|
|
145
148
|
runMigration = true
|
|
146
149
|
) {
|
|
147
|
-
const manager = new
|
|
150
|
+
const manager = new MysqlSessionStore(
|
|
148
151
|
pool,
|
|
149
152
|
identity,
|
|
150
153
|
logger,
|
|
@@ -155,8 +158,8 @@ async function createMysqlSessionManagerWithPool(
|
|
|
155
158
|
}
|
|
156
159
|
|
|
157
160
|
module.exports = {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
MysqlSessionStore,
|
|
162
|
+
createMysqlSessionStore,
|
|
163
|
+
createMysqlSessionStoreWithPool,
|
|
164
|
+
SessionStoreError,
|
|
162
165
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Session
|
|
3
|
-
* `
|
|
2
|
+
* Session store migrations for MySQL 8.0+. Mirrors the Rust
|
|
3
|
+
* `MysqlSessionStore` schema exactly.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const {
|
|
6
|
+
const { SessionStoreError } = require("./errors.cjs");
|
|
7
7
|
|
|
8
8
|
const SESSION_MIGRATIONS_TABLE = "brz_session_schema_migrations";
|
|
9
9
|
const MIGRATION_LOCK_NAME = "breez_mysql_session_manager_migration_lock";
|
|
10
10
|
const MIGRATION_LOCK_TIMEOUT = 60;
|
|
11
11
|
|
|
12
|
-
class
|
|
12
|
+
class MysqlSessionStoreMigrationManager {
|
|
13
13
|
constructor(logger = null) {
|
|
14
14
|
this.logger = logger;
|
|
15
15
|
}
|
|
@@ -25,8 +25,8 @@ class MysqlSessionManagerMigrationManager {
|
|
|
25
25
|
[MIGRATION_LOCK_NAME, MIGRATION_LOCK_TIMEOUT]
|
|
26
26
|
);
|
|
27
27
|
if (!lockRows || lockRows[0].acquired !== 1) {
|
|
28
|
-
throw new
|
|
29
|
-
`Failed to acquire session
|
|
28
|
+
throw new SessionStoreError(
|
|
29
|
+
`Failed to acquire session store migration lock within ${MIGRATION_LOCK_TIMEOUT}s`
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -38,7 +38,7 @@ class MysqlSessionManagerMigrationManager {
|
|
|
38
38
|
await conn.query(`
|
|
39
39
|
CREATE TABLE IF NOT EXISTS \`${SESSION_MIGRATIONS_TABLE}\` (
|
|
40
40
|
version INT PRIMARY KEY,
|
|
41
|
-
applied_at DATETIME(6) NOT NULL DEFAULT
|
|
41
|
+
applied_at DATETIME(6) NOT NULL DEFAULT (UTC_TIMESTAMP(6))
|
|
42
42
|
)
|
|
43
43
|
`);
|
|
44
44
|
|
|
@@ -61,7 +61,7 @@ class MysqlSessionManagerMigrationManager {
|
|
|
61
61
|
await conn.query(sql);
|
|
62
62
|
}
|
|
63
63
|
await conn.query(
|
|
64
|
-
`INSERT INTO \`${SESSION_MIGRATIONS_TABLE}\` (version) VALUES (
|
|
64
|
+
`INSERT INTO \`${SESSION_MIGRATIONS_TABLE}\` (version, applied_at) VALUES (?, UTC_TIMESTAMP(6))`,
|
|
65
65
|
[version]
|
|
66
66
|
);
|
|
67
67
|
}
|
|
@@ -69,8 +69,8 @@ class MysqlSessionManagerMigrationManager {
|
|
|
69
69
|
await conn.query("COMMIT");
|
|
70
70
|
} catch (error) {
|
|
71
71
|
await conn.query("ROLLBACK").catch(() => {});
|
|
72
|
-
throw new
|
|
73
|
-
`Session
|
|
72
|
+
throw new SessionStoreError(
|
|
73
|
+
`Session store migration failed: ${error.message}`,
|
|
74
74
|
error
|
|
75
75
|
);
|
|
76
76
|
} finally {
|
|
@@ -123,6 +123,12 @@ class MysqlSessionManagerMigrationManager {
|
|
|
123
123
|
)`,
|
|
124
124
|
],
|
|
125
125
|
},
|
|
126
|
+
{
|
|
127
|
+
name: "Pin schema-migrations applied_at default to UTC",
|
|
128
|
+
sql: [
|
|
129
|
+
`ALTER TABLE \`${SESSION_MIGRATIONS_TABLE}\` MODIFY COLUMN applied_at DATETIME(6) NOT NULL DEFAULT (UTC_TIMESTAMP(6))`,
|
|
130
|
+
],
|
|
131
|
+
},
|
|
126
132
|
];
|
|
127
133
|
}
|
|
128
134
|
}
|
|
@@ -136,4 +142,4 @@ async function _mysqlTableExists(conn, tableName) {
|
|
|
136
142
|
return Number(rows[0].c) > 0;
|
|
137
143
|
}
|
|
138
144
|
|
|
139
|
-
module.exports = {
|
|
145
|
+
module.exports = { MysqlSessionStoreMigrationManager };
|