@breeztech/breez-sdk-spark 0.15.1 → 0.17.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/breez-sdk-spark.tgz +0 -0
- package/bundler/breez_sdk_spark_wasm.d.ts +604 -237
- package/bundler/breez_sdk_spark_wasm.js +1 -1
- package/bundler/breez_sdk_spark_wasm_bg.js +729 -434
- package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +63 -49
- package/bundler/storage/index.js +356 -34
- package/deno/breez_sdk_spark_wasm.d.ts +604 -237
- package/deno/breez_sdk_spark_wasm.js +729 -434
- package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +63 -49
- package/nodejs/breez_sdk_spark_wasm.d.ts +604 -237
- package/nodejs/breez_sdk_spark_wasm.js +741 -441
- package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +63 -49
- package/nodejs/index.js +10 -10
- package/nodejs/index.mjs +13 -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 +358 -125
- package/nodejs/mysql-storage/migrations.cjs +67 -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 +296 -119
- package/nodejs/postgres-storage/migrations.cjs +51 -0
- package/nodejs/postgres-token-store/index.cjs +89 -64
- package/nodejs/postgres-token-store/migrations.cjs +44 -0
- package/nodejs/storage/index.cjs +285 -125
- package/nodejs/storage/migrations.cjs +47 -0
- package/package.json +6 -1
- package/ssr/index.js +57 -28
- package/web/breez_sdk_spark_wasm.d.ts +667 -286
- package/web/breez_sdk_spark_wasm.js +729 -434
- package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +63 -49
- package/web/passkey-prf-provider/index.d.ts +203 -0
- package/web/passkey-prf-provider/index.js +733 -0
- package/web/storage/index.js +356 -34
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CommonJS implementation for Node.js PostgreSQL Session
|
|
2
|
+
* CommonJS implementation for Node.js PostgreSQL Session Store.
|
|
3
3
|
*
|
|
4
|
-
* Implements the JS-side `
|
|
4
|
+
* Implements the JS-side `SessionStore` interface consumed by the Breez
|
|
5
5
|
* SDK WASM bindings: `getSession(serviceIdentityKey)` returns the cached
|
|
6
6
|
* session for the (tenant, service) pair or `null` when not found, and
|
|
7
7
|
* `setSession(serviceIdentityKey, session)` upserts a session.
|
|
@@ -29,10 +29,10 @@ try {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const {
|
|
33
|
-
const {
|
|
32
|
+
const { SessionStoreError } = require("./errors.cjs");
|
|
33
|
+
const { SessionStoreMigrationManager } = require("./migrations.cjs");
|
|
34
34
|
|
|
35
|
-
class
|
|
35
|
+
class PostgresSessionStore {
|
|
36
36
|
/**
|
|
37
37
|
* @param {import('pg').Pool} pool
|
|
38
38
|
* @param {Buffer|Uint8Array} identity - 33-byte secp256k1 compressed pubkey
|
|
@@ -41,7 +41,7 @@ class PostgresSessionManager {
|
|
|
41
41
|
*/
|
|
42
42
|
constructor(pool, identity, logger = null, runMigration = true) {
|
|
43
43
|
if (!identity || identity.length !== 33) {
|
|
44
|
-
throw new
|
|
44
|
+
throw new SessionStoreError(
|
|
45
45
|
"tenant identity (33-byte secp256k1 pubkey) is required"
|
|
46
46
|
);
|
|
47
47
|
}
|
|
@@ -54,13 +54,13 @@ class PostgresSessionManager {
|
|
|
54
54
|
async initialize() {
|
|
55
55
|
try {
|
|
56
56
|
if (this.runMigration) {
|
|
57
|
-
const migrationManager = new
|
|
57
|
+
const migrationManager = new SessionStoreMigrationManager(this.logger);
|
|
58
58
|
await migrationManager.migrate(this.pool);
|
|
59
59
|
}
|
|
60
60
|
return this;
|
|
61
61
|
} catch (error) {
|
|
62
|
-
throw new
|
|
63
|
-
`Failed to initialize PostgreSQL session
|
|
62
|
+
throw new SessionStoreError(
|
|
63
|
+
`Failed to initialize PostgreSQL session store: ${error.message}`,
|
|
64
64
|
error
|
|
65
65
|
);
|
|
66
66
|
}
|
|
@@ -76,7 +76,7 @@ class PostgresSessionManager {
|
|
|
76
76
|
/**
|
|
77
77
|
* Returns the cached session for the given service identity key, or `null`
|
|
78
78
|
* if no session is cached. The Rust adapter maps `null` to
|
|
79
|
-
* `
|
|
79
|
+
* `SessionStoreError::NotFound`.
|
|
80
80
|
* @param {string} serviceIdentityKey - hex-encoded 33-byte secp256k1 pubkey
|
|
81
81
|
* @returns {Promise<{token: string, expiration: number} | null>}
|
|
82
82
|
*/
|
|
@@ -97,7 +97,7 @@ class PostgresSessionManager {
|
|
|
97
97
|
expiration: Number(row.expiration),
|
|
98
98
|
};
|
|
99
99
|
} catch (error) {
|
|
100
|
-
throw new
|
|
100
|
+
throw new SessionStoreError(
|
|
101
101
|
`Failed to read session: ${error.message}`,
|
|
102
102
|
error
|
|
103
103
|
);
|
|
@@ -120,7 +120,7 @@ class PostgresSessionManager {
|
|
|
120
120
|
[this.identity, serviceKey, session.token, session.expiration]
|
|
121
121
|
);
|
|
122
122
|
} catch (error) {
|
|
123
|
-
throw new
|
|
123
|
+
throw new SessionStoreError(
|
|
124
124
|
`Failed to write session: ${error.message}`,
|
|
125
125
|
error
|
|
126
126
|
);
|
|
@@ -130,7 +130,7 @@ class PostgresSessionManager {
|
|
|
130
130
|
|
|
131
131
|
function _decodePubkey(hex) {
|
|
132
132
|
if (typeof hex !== "string" || hex.length !== 66) {
|
|
133
|
-
throw new
|
|
133
|
+
throw new SessionStoreError(
|
|
134
134
|
"service_identity_key must be a 66-character hex-encoded 33-byte pubkey"
|
|
135
135
|
);
|
|
136
136
|
}
|
|
@@ -139,13 +139,13 @@ function _decodePubkey(hex) {
|
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* Convenience factory: creates a pool from a Pool config and returns an
|
|
142
|
-
* initialized `
|
|
143
|
-
* `
|
|
142
|
+
* initialized `PostgresSessionStore`. Most callers should use
|
|
143
|
+
* `createPostgresSessionStoreWithPool` instead so the pool can be shared
|
|
144
144
|
* across stores.
|
|
145
145
|
*/
|
|
146
|
-
async function
|
|
146
|
+
async function createPostgresSessionStore(poolConfig, identity, logger = null) {
|
|
147
147
|
const pool = new pg.Pool(poolConfig);
|
|
148
|
-
const manager = new
|
|
148
|
+
const manager = new PostgresSessionStore(
|
|
149
149
|
pool,
|
|
150
150
|
identity,
|
|
151
151
|
logger,
|
|
@@ -159,13 +159,13 @@ async function createPostgresSessionManager(poolConfig, identity, logger = null)
|
|
|
159
159
|
* Wraps an existing pool — useful when sharing the pool with the storage,
|
|
160
160
|
* tree store, and token store implementations.
|
|
161
161
|
*/
|
|
162
|
-
async function
|
|
162
|
+
async function createPostgresSessionStoreWithPool(
|
|
163
163
|
pool,
|
|
164
164
|
identity,
|
|
165
165
|
logger = null,
|
|
166
166
|
runMigration = true
|
|
167
167
|
) {
|
|
168
|
-
const manager = new
|
|
168
|
+
const manager = new PostgresSessionStore(
|
|
169
169
|
pool,
|
|
170
170
|
identity,
|
|
171
171
|
logger,
|
|
@@ -176,8 +176,8 @@ async function createPostgresSessionManagerWithPool(
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
module.exports = {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
PostgresSessionStore,
|
|
180
|
+
createPostgresSessionStore,
|
|
181
|
+
createPostgresSessionStoreWithPool,
|
|
182
|
+
SessionStoreError,
|
|
183
183
|
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Database Migration Manager for Breez SDK PostgreSQL Session
|
|
2
|
+
* Database Migration Manager for Breez SDK PostgreSQL Session Store.
|
|
3
3
|
*
|
|
4
4
|
* Uses a brz_session_schema_migrations table + pg_advisory_xact_lock to safely
|
|
5
5
|
* run migrations from concurrent processes. Mirrors the schema produced by
|
|
6
|
-
* the Rust `
|
|
6
|
+
* the Rust `PostgresSessionStore`.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const { SessionStoreError } = require("./errors.cjs");
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Advisory lock ID for session-
|
|
12
|
+
* Advisory lock ID for session-store migrations.
|
|
13
13
|
* Uses a different lock ID from the storage / tree store / token store
|
|
14
14
|
* migrations to avoid contention. Derived from ASCII bytes of "SESN"
|
|
15
15
|
* (0x5345534E).
|
|
16
16
|
*/
|
|
17
17
|
const MIGRATION_LOCK_ID = "1397245774"; // 0x5345534E as decimal string
|
|
18
18
|
|
|
19
|
-
class
|
|
19
|
+
class SessionStoreMigrationManager {
|
|
20
20
|
constructor(logger = null) {
|
|
21
21
|
this.logger = logger;
|
|
22
22
|
}
|
|
@@ -51,7 +51,7 @@ class SessionManagerMigrationManager {
|
|
|
51
51
|
if (currentVersion >= migrations.length) {
|
|
52
52
|
this._log(
|
|
53
53
|
"info",
|
|
54
|
-
`Session
|
|
54
|
+
`Session store database is up to date (version ${currentVersion})`
|
|
55
55
|
);
|
|
56
56
|
await client.query("COMMIT");
|
|
57
57
|
return;
|
|
@@ -59,7 +59,7 @@ class SessionManagerMigrationManager {
|
|
|
59
59
|
|
|
60
60
|
this._log(
|
|
61
61
|
"info",
|
|
62
|
-
`Migrating session
|
|
62
|
+
`Migrating session store database from version ${currentVersion} to ${migrations.length}`
|
|
63
63
|
);
|
|
64
64
|
|
|
65
65
|
for (let i = currentVersion; i < migrations.length; i++) {
|
|
@@ -67,7 +67,7 @@ class SessionManagerMigrationManager {
|
|
|
67
67
|
const version = i + 1;
|
|
68
68
|
this._log(
|
|
69
69
|
"debug",
|
|
70
|
-
`Running session
|
|
70
|
+
`Running session store migration ${version}: ${migration.name}`
|
|
71
71
|
);
|
|
72
72
|
|
|
73
73
|
for (const sql of migration.sql) {
|
|
@@ -83,12 +83,12 @@ class SessionManagerMigrationManager {
|
|
|
83
83
|
await client.query("COMMIT");
|
|
84
84
|
this._log(
|
|
85
85
|
"info",
|
|
86
|
-
"Session
|
|
86
|
+
"Session store database migration completed successfully"
|
|
87
87
|
);
|
|
88
88
|
} catch (error) {
|
|
89
89
|
await client.query("ROLLBACK").catch(() => {});
|
|
90
|
-
throw new
|
|
91
|
-
`Session
|
|
90
|
+
throw new SessionStoreError(
|
|
91
|
+
`Session store migration failed: ${error.message}`,
|
|
92
92
|
error
|
|
93
93
|
);
|
|
94
94
|
} finally {
|
|
@@ -137,12 +137,12 @@ class SessionManagerMigrationManager {
|
|
|
137
137
|
if (this.logger && typeof this.logger.log === "function") {
|
|
138
138
|
this.logger.log({ line: message, level });
|
|
139
139
|
} else if (level === "error") {
|
|
140
|
-
console.error(`[
|
|
140
|
+
console.error(`[SessionStoreMigrationManager] ${message}`);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
/**
|
|
145
|
-
* Migrations matching the Rust
|
|
145
|
+
* Migrations matching the Rust PostgresSessionStore schema exactly.
|
|
146
146
|
*/
|
|
147
147
|
_getMigrations() {
|
|
148
148
|
return [
|
|
@@ -162,4 +162,4 @@ class SessionManagerMigrationManager {
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
module.exports = {
|
|
165
|
+
module.exports = { SessionStoreMigrationManager };
|