@totemsdk/omnia-host 0.5.0 → 0.7.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/lifecycle.js
CHANGED
|
@@ -41,6 +41,11 @@ function createOmniaHost(config, dependencies = {}) {
|
|
|
41
41
|
ownedStore = new sqlite_store_js_1.SqliteChannelStore(config.dbPath);
|
|
42
42
|
channelStore = ownedStore;
|
|
43
43
|
}
|
|
44
|
+
// CAN-002: recovered channels must carry the local signer so the router can
|
|
45
|
+
// identify the counterparty (otherwise multi-hop payments loop back).
|
|
46
|
+
if (channelStore instanceof sqlite_store_js_1.SqliteChannelStore) {
|
|
47
|
+
channelStore.setLocalSigner(dependencies.signer);
|
|
48
|
+
}
|
|
44
49
|
if (!operationStore && !injectedOperationStore) {
|
|
45
50
|
ownedOperationStore = new operations_js_1.OperationStore(config.dbPath);
|
|
46
51
|
operationStore = ownedOperationStore;
|
|
@@ -6,11 +6,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.OperationStore = void 0;
|
|
7
7
|
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
8
8
|
const node_crypto_1 = require("node:crypto");
|
|
9
|
+
/**
|
|
10
|
+
* CAN-001: operation requests/results can carry `bigint` amounts (e.g. a
|
|
11
|
+
* multi-hop route's hop amounts). `JSON.stringify` throws on bigint, so encode
|
|
12
|
+
* with a reversible tag and decode it back — the journal never sees a raw
|
|
13
|
+
* primitive it cannot persist.
|
|
14
|
+
*/
|
|
15
|
+
function bigintReplacer(_key, value) {
|
|
16
|
+
return typeof value === 'bigint' ? { $bigint: value.toString() } : value;
|
|
17
|
+
}
|
|
18
|
+
function bigintReviver(_key, value) {
|
|
19
|
+
if (value !== null &&
|
|
20
|
+
typeof value === 'object' &&
|
|
21
|
+
typeof value.$bigint === 'string' &&
|
|
22
|
+
Object.keys(value).length === 1) {
|
|
23
|
+
return BigInt(value.$bigint);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
9
27
|
function encode(value) {
|
|
10
|
-
return value === undefined ? null : JSON.stringify(value);
|
|
28
|
+
return value === undefined ? null : JSON.stringify(value, bigintReplacer);
|
|
11
29
|
}
|
|
12
30
|
function decode(value) {
|
|
13
|
-
return value === null ? undefined : JSON.parse(value);
|
|
31
|
+
return value === null ? undefined : JSON.parse(value, bigintReviver);
|
|
14
32
|
}
|
|
15
33
|
function toRecord(row) {
|
|
16
34
|
return {
|
|
@@ -90,6 +108,8 @@ class OperationStore {
|
|
|
90
108
|
}
|
|
91
109
|
exports.OperationStore = OperationStore;
|
|
92
110
|
function canonical(value) {
|
|
111
|
+
if (typeof value === 'bigint')
|
|
112
|
+
return `{"$bigint":${JSON.stringify(value.toString())}}`;
|
|
93
113
|
if (value === null || typeof value !== 'object')
|
|
94
114
|
return JSON.stringify(value);
|
|
95
115
|
if (Array.isArray(value))
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import { type OmniaChannel } from '@totemsdk/omnia';
|
|
1
|
+
import { type OmniaChannel, type ChannelSigner } from '@totemsdk/omnia';
|
|
2
2
|
/** SQLite-backed Map facade accepted by @totemsdk/omnia's ChannelStore type. */
|
|
3
3
|
export declare class SqliteChannelStore extends Map<string, OmniaChannel> {
|
|
4
4
|
private readonly db;
|
|
5
5
|
private readonly readStatement;
|
|
6
6
|
private readonly writeStatement;
|
|
7
7
|
private readonly deleteStatement;
|
|
8
|
+
/**
|
|
9
|
+
* CAN-002: a recovered channel loses `localSigner` (it is not serializable),
|
|
10
|
+
* so the router's `counterpartPkd()` cannot tell which party is local and
|
|
11
|
+
* multi-hop payments loop back. Re-bind the host's signer on every read.
|
|
12
|
+
*/
|
|
13
|
+
private localSigner?;
|
|
8
14
|
constructor(dbPath: string);
|
|
15
|
+
/** Attach the host's signer so recovered channels carry it (CAN-002). */
|
|
16
|
+
setLocalSigner(signer?: ChannelSigner): void;
|
|
17
|
+
private rebind;
|
|
9
18
|
get(channelId: string): OmniaChannel | undefined;
|
|
10
19
|
set(channelId: string, channel: OmniaChannel): this;
|
|
11
20
|
has(channelId: string): boolean;
|
|
@@ -28,6 +28,12 @@ class SqliteChannelStore extends Map {
|
|
|
28
28
|
readStatement;
|
|
29
29
|
writeStatement;
|
|
30
30
|
deleteStatement;
|
|
31
|
+
/**
|
|
32
|
+
* CAN-002: a recovered channel loses `localSigner` (it is not serializable),
|
|
33
|
+
* so the router's `counterpartPkd()` cannot tell which party is local and
|
|
34
|
+
* multi-hop payments loop back. Re-bind the host's signer on every read.
|
|
35
|
+
*/
|
|
36
|
+
localSigner;
|
|
31
37
|
constructor(dbPath) {
|
|
32
38
|
super();
|
|
33
39
|
this.db = new better_sqlite3_1.default(dbPath);
|
|
@@ -49,9 +55,16 @@ class SqliteChannelStore extends Map {
|
|
|
49
55
|
`);
|
|
50
56
|
this.deleteStatement = this.db.prepare('DELETE FROM omnia_channels WHERE channel_id = ?');
|
|
51
57
|
}
|
|
58
|
+
/** Attach the host's signer so recovered channels carry it (CAN-002). */
|
|
59
|
+
setLocalSigner(signer) {
|
|
60
|
+
this.localSigner = signer;
|
|
61
|
+
}
|
|
62
|
+
rebind(channel) {
|
|
63
|
+
return this.localSigner ? { ...channel, localSigner: this.localSigner } : channel;
|
|
64
|
+
}
|
|
52
65
|
get(channelId) {
|
|
53
66
|
const row = this.readStatement.get(channelId);
|
|
54
|
-
return row ? (0, omnia_1.recoverChannel)(row.channel_json) : undefined;
|
|
67
|
+
return row ? this.rebind((0, omnia_1.recoverChannel)(row.channel_json)) : undefined;
|
|
55
68
|
}
|
|
56
69
|
set(channelId, channel) {
|
|
57
70
|
this.writeStatement.run(channelId, (0, omnia_1.serializeChannelSnapshot)(channel), Date.now());
|
|
@@ -74,7 +87,7 @@ class SqliteChannelStore extends Map {
|
|
|
74
87
|
const rows = this.db.prepare('SELECT channel_id, channel_json FROM omnia_channels ORDER BY channel_id').iterate();
|
|
75
88
|
return iterator(Array.from(rows, (row) => [
|
|
76
89
|
row.channel_id,
|
|
77
|
-
(0, omnia_1.recoverChannel)(row.channel_json),
|
|
90
|
+
this.rebind((0, omnia_1.recoverChannel)(row.channel_json)),
|
|
78
91
|
]));
|
|
79
92
|
}
|
|
80
93
|
keys() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/omnia-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Durable Omnia node daemon for channel lifecycle, routing, and control APIs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"ws": "^8.21.1",
|
|
25
25
|
"@totemsdk/chain-provider": "^0.2.1",
|
|
26
26
|
"@totemsdk/core": "^1.2.11",
|
|
27
|
-
"@totemsdk/
|
|
28
|
-
"@totemsdk/manifest": "^1.0.0",
|
|
27
|
+
"@totemsdk/manifest": "^2.0.0",
|
|
29
28
|
"@totemsdk/omnia": "^2.0.1",
|
|
29
|
+
"@totemsdk/identity": "^1.0.1",
|
|
30
30
|
"@totemsdk/omnia-router": "^0.3.0",
|
|
31
31
|
"@totemsdk/omnia-factory": "^0.5.0",
|
|
32
32
|
"@totemsdk/omnia-vtxo": "^0.5.0",
|
|
33
|
-
"@totemsdk/minima-rpc": "^0.2.2",
|
|
34
33
|
"@totemsdk/omnia-splice": "^0.3.0",
|
|
35
34
|
"@totemsdk/storage": "^0.1.0",
|
|
35
|
+
"@totemsdk/minima-rpc": "^0.2.2",
|
|
36
36
|
"@totemsdk/wots-lease": "^1.0.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|