@qntx/wallet-engine 0.13.0 → 0.14.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/README.md +1057 -20
- package/dist/apps-fiat24.d.mts +202 -0
- package/dist/apps-fiat24.mjs +1378 -0
- package/dist/apps-fiat24.mjs.map +1 -0
- package/dist/apps-hyperliquid.d.mts +549 -0
- package/dist/apps-hyperliquid.mjs +2742 -0
- package/dist/apps-hyperliquid.mjs.map +1 -0
- package/dist/apps-polymarket.d.mts +729 -0
- package/dist/apps-polymarket.mjs +3786 -0
- package/dist/apps-polymarket.mjs.map +1 -0
- package/dist/apps.d.mts +136 -0
- package/dist/apps.mjs +535 -0
- package/dist/apps.mjs.map +1 -0
- package/dist/connect-BY1C5ZRI.mjs +210 -0
- package/dist/connect-BY1C5ZRI.mjs.map +1 -0
- package/dist/connect.d.mts +17 -9
- package/dist/connect.mjs +3 -185
- package/dist/{errors-CQnlTc1i.d.mts → controller-DpNVHVsj.d.mts} +1093 -758
- package/dist/controller-rMnaxKAH.mjs +46 -0
- package/dist/controller-rMnaxKAH.mjs.map +1 -0
- package/dist/decimal-COJ4g8qy.mjs +38 -0
- package/dist/decimal-COJ4g8qy.mjs.map +1 -0
- package/dist/eligibility-BfM9ybYZ.mjs +48 -0
- package/dist/eligibility-BfM9ybYZ.mjs.map +1 -0
- package/dist/engine-Dic_kkEr.d.mts +1829 -0
- package/dist/errors-B8W-hoYW.d.mts +7 -0
- package/dist/errors-horUy5k1.mjs +24 -0
- package/dist/errors-horUy5k1.mjs.map +1 -0
- package/dist/gateway-contract.d.mts +3 -608
- package/dist/gateway-contract.mjs +1467 -161
- package/dist/gateway-contract.mjs.map +1 -1
- package/dist/idb.d.mts +5 -0
- package/dist/idb.mjs +122 -46
- package/dist/idb.mjs.map +1 -1
- package/dist/index-vBgfOFIh.d.mts +2227 -0
- package/dist/index.d.mts +58 -618
- package/dist/index.mjs +21963 -6836
- package/dist/index.mjs.map +1 -1
- package/dist/json-BDwV38cj.mjs +15 -0
- package/dist/json-BDwV38cj.mjs.map +1 -0
- package/dist/link-Ceq8Dggp.mjs +139 -0
- package/dist/link-Ceq8Dggp.mjs.map +1 -0
- package/dist/primitives-DbSHLZKq.mjs +31 -0
- package/dist/primitives-DbSHLZKq.mjs.map +1 -0
- package/dist/push-message-AQuzoNFY.d.mts +84 -0
- package/dist/push-message-kbnH1A5w.mjs +142 -0
- package/dist/push-message-kbnH1A5w.mjs.map +1 -0
- package/dist/push.d.mts +13 -0
- package/dist/push.mjs +70 -0
- package/dist/push.mjs.map +1 -0
- package/dist/qr.d.mts +292 -0
- package/dist/qr.mjs +1725 -0
- package/dist/qr.mjs.map +1 -0
- package/dist/registry-CbtwcxkX.mjs +374 -0
- package/dist/registry-CbtwcxkX.mjs.map +1 -0
- package/dist/risk-DyABgg4W.mjs +757 -0
- package/dist/risk-DyABgg4W.mjs.map +1 -0
- package/dist/session-CNJFLarP.mjs +18 -0
- package/dist/session-CNJFLarP.mjs.map +1 -0
- package/dist/socket-ChG9JRT_.mjs +110 -0
- package/dist/socket-ChG9JRT_.mjs.map +1 -0
- package/dist/spi-BrTw5s98.d.mts +3 -0
- package/dist/timer-Cdk5rGM2.mjs +43 -0
- package/dist/timer-Cdk5rGM2.mjs.map +1 -0
- package/dist/types-BpvioFGo.d.mts +258 -0
- package/dist/types-DbftVZ3I.mjs +90 -0
- package/dist/types-DbftVZ3I.mjs.map +1 -0
- package/dist/walletconnect.d.mts +86 -0
- package/dist/walletconnect.mjs +1507 -0
- package/dist/walletconnect.mjs.map +1 -0
- package/dist/webln-BgrtPXpG.mjs +2593 -0
- package/dist/webln-BgrtPXpG.mjs.map +1 -0
- package/dist/webln-Bllk_xJ2.d.mts +666 -0
- package/package.json +92 -19
- package/dist/connect.mjs.map +0 -1
- package/dist/registry-DwguKWvt.d.mts +0 -27
- package/dist/registry-oorLoGtz.mjs +0 -120
- package/dist/registry-oorLoGtz.mjs.map +0 -1
- package/dist/webln-DKqCnqx1.mjs +0 -3677
- package/dist/webln-DKqCnqx1.mjs.map +0 -1
package/dist/idb.mjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
2
|
+
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
3
|
+
import { hmac } from "@noble/hashes/hmac.js";
|
|
4
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
5
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
6
|
+
import "@qntx/wallet-chains";
|
|
2
7
|
// src/errors.ts
|
|
3
|
-
/** Typed engine errors: store codes are `closed` and `
|
|
8
|
+
/** Typed engine errors: store codes are `closed` and `invalid-input`. */
|
|
4
9
|
var EngineStoreError = class extends Error {
|
|
5
10
|
code;
|
|
6
11
|
constructor(code, message) {
|
|
@@ -39,13 +44,13 @@ async function done(tx) {
|
|
|
39
44
|
});
|
|
40
45
|
}
|
|
41
46
|
// src/idb/public-store.ts
|
|
42
|
-
const STORE
|
|
47
|
+
const STORE = "records";
|
|
43
48
|
/** An unencrypted IndexedDB PublicStore: one database, one `records` object store. */
|
|
44
49
|
async function openIndexedDbPublicStore(options) {
|
|
45
50
|
const db = await new Promise((resolve, reject) => {
|
|
46
51
|
const open = indexedDB.open(options.name, 1);
|
|
47
52
|
open.addEventListener("upgradeneeded", () => {
|
|
48
|
-
open.result.createObjectStore(STORE
|
|
53
|
+
open.result.createObjectStore(STORE);
|
|
49
54
|
});
|
|
50
55
|
open.addEventListener("success", () => {
|
|
51
56
|
resolve(open.result);
|
|
@@ -57,91 +62,161 @@ async function openIndexedDbPublicStore(options) {
|
|
|
57
62
|
return {
|
|
58
63
|
get: async (key) => {
|
|
59
64
|
checkName("key", key);
|
|
60
|
-
const value = await request(db.transaction(STORE
|
|
65
|
+
const value = await request(db.transaction(STORE, "readonly").objectStore(STORE).get(key));
|
|
61
66
|
return value === void 0 ? void 0 : new Uint8Array(value);
|
|
62
67
|
},
|
|
63
68
|
put: async (key, bytes) => {
|
|
64
69
|
checkName("key", key);
|
|
65
|
-
const tx = db.transaction(STORE
|
|
66
|
-
tx.objectStore(STORE
|
|
70
|
+
const tx = db.transaction(STORE, "readwrite");
|
|
71
|
+
tx.objectStore(STORE).put(new Uint8Array(bytes), key);
|
|
67
72
|
await done(tx);
|
|
68
73
|
}
|
|
69
74
|
};
|
|
70
75
|
}
|
|
71
76
|
// src/idb/indexeddb.ts
|
|
72
77
|
/**
|
|
73
|
-
* The Web EngineStore: one IndexedDB database,
|
|
74
|
-
* record with XChaCha20-Poly1305.
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
+
* The Web EngineStore: one IndexedDB database (format 2), two object stores, values encrypted per
|
|
79
|
+
* record with XChaCha20-Poly1305. The injected data key derives two subkeys at open via
|
|
80
|
+
* HKDF-SHA256: `sealKey` encrypts every row, `idKey` names them — a record id is the lowercase hex
|
|
81
|
+
* of `hmac(sha256, idKey, utf8(collection) ‖ 0x00 ‖ utf8(key))`, so nothing readable on disk
|
|
82
|
+
* reveals collection names or record keys.
|
|
83
|
+
*
|
|
84
|
+
* `records` maps id → nonce‖ciphertext(value) under AAD `record\0${id}`; `index` maps the same id →
|
|
85
|
+
* nonce‖ciphertext(utf8(`${collection}\0${key}`)) under AAD `index\0${id}` and backs `list`. Moving
|
|
86
|
+
* a row to another id fails its MAC, same as a tampered payload, and a record that fails its MAC
|
|
87
|
+
* reads exactly like a missing one. A reserved `check` row in `index` sealed under a fixed AAD
|
|
88
|
+
* proves the data key at open: a database keyed differently is rebuilt empty. This still leaks the
|
|
89
|
+
* record count, the value sizes and write timing. `close()` drops the connection, wipes both
|
|
90
|
+
* subkeys and latches every call to `closed`.
|
|
78
91
|
*/
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const
|
|
92
|
+
const RECORDS = "records";
|
|
93
|
+
const INDEX = "index";
|
|
94
|
+
const CHECK_KEY = "check";
|
|
95
|
+
const CHECK_AAD = new TextEncoder().encode("qntx-engine-store-check");
|
|
96
|
+
const utf8 = new TextEncoder();
|
|
97
|
+
const utf8decode = new TextDecoder();
|
|
98
|
+
const recordId = (idKey, collection, recordKey) => {
|
|
99
|
+
const c = utf8.encode(collection);
|
|
100
|
+
const k = utf8.encode(recordKey);
|
|
101
|
+
const msg = new Uint8Array(c.length + 1 + k.length);
|
|
102
|
+
msg.set(c, 0);
|
|
103
|
+
msg.set(k, c.length + 1);
|
|
104
|
+
const hex = bytesToHex(hmac(sha256, idKey, msg));
|
|
105
|
+
msg.fill(0);
|
|
106
|
+
return hex;
|
|
107
|
+
};
|
|
108
|
+
const aad = (kind, id) => utf8.encode(`${kind}\u0000${id}`);
|
|
109
|
+
const sealRecord = (key, random, aadBytes, bytes) => {
|
|
110
|
+
const nonce = random(24);
|
|
111
|
+
const ciphertext = xchacha20poly1305(key, nonce, aadBytes).encrypt(bytes);
|
|
112
|
+
const record = new Uint8Array(24 + ciphertext.length);
|
|
113
|
+
record.set(nonce, 0);
|
|
114
|
+
record.set(ciphertext, 24);
|
|
115
|
+
return record;
|
|
116
|
+
};
|
|
117
|
+
/** The plaintext, or `undefined` when the record fails authentication — it reads as deleted. */
|
|
118
|
+
const openRecord = (key, aadBytes, record) => {
|
|
119
|
+
if (record.length < 24) return;
|
|
120
|
+
try {
|
|
121
|
+
return xchacha20poly1305(key, record.slice(0, 24), aadBytes).decrypt(record.slice(24));
|
|
122
|
+
} catch {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
82
126
|
async function openIndexedDbEngineStore(options) {
|
|
83
127
|
const key = new Uint8Array(options.dataKey);
|
|
84
|
-
|
|
85
|
-
|
|
128
|
+
const sealKey = hkdf(sha256, key, void 0, utf8.encode("qntx/engine-store/seal"), 32);
|
|
129
|
+
const idKey = hkdf(sha256, key, void 0, utf8.encode("qntx/engine-store/id"), 32);
|
|
130
|
+
key.fill(0);
|
|
131
|
+
const db = await new Promise((resolve, reject) => {
|
|
132
|
+
const open = indexedDB.open(options.name, 2);
|
|
86
133
|
open.addEventListener("upgradeneeded", () => {
|
|
87
|
-
open
|
|
134
|
+
const { result } = open;
|
|
135
|
+
for (const storeName of result.objectStoreNames) result.deleteObjectStore(storeName);
|
|
136
|
+
result.createObjectStore(RECORDS);
|
|
137
|
+
result.createObjectStore(INDEX);
|
|
88
138
|
});
|
|
89
139
|
open.addEventListener("success", () => {
|
|
90
|
-
resolve(
|
|
140
|
+
resolve(open.result);
|
|
91
141
|
});
|
|
92
142
|
open.addEventListener("error", () => {
|
|
93
|
-
|
|
143
|
+
sealKey.fill(0);
|
|
144
|
+
idKey.fill(0);
|
|
94
145
|
reject(new Error("indexeddb open failed", { cause: open.error }));
|
|
95
146
|
});
|
|
96
147
|
});
|
|
148
|
+
try {
|
|
149
|
+
await checkStoreKey(db, sealKey, options.random);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
db.close();
|
|
152
|
+
sealKey.fill(0);
|
|
153
|
+
idKey.fill(0);
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
return makeStore(db, sealKey, idKey, options.random);
|
|
97
157
|
}
|
|
98
|
-
|
|
158
|
+
/** One read-write transaction before the store is handed out: `check` must open under this key. */
|
|
159
|
+
async function checkStoreKey(db, key, random) {
|
|
160
|
+
const tx = db.transaction([RECORDS, INDEX], "readwrite");
|
|
161
|
+
const index = tx.objectStore(INDEX);
|
|
162
|
+
const existing = await request(index.get(CHECK_KEY));
|
|
163
|
+
if (existing === void 0 || openRecord(key, CHECK_AAD, existing) === void 0) {
|
|
164
|
+
tx.objectStore(RECORDS).clear();
|
|
165
|
+
index.clear();
|
|
166
|
+
index.put(sealRecord(key, random, CHECK_AAD, /* @__PURE__ */ new Uint8Array(0)), CHECK_KEY);
|
|
167
|
+
}
|
|
168
|
+
await done(tx);
|
|
169
|
+
}
|
|
170
|
+
function makeStore(db, sealKey, idKey, random) {
|
|
99
171
|
let closed = false;
|
|
100
172
|
const guard = () => {
|
|
101
173
|
if (closed) throw new EngineStoreError("closed", "engine store is closed");
|
|
102
174
|
return db;
|
|
103
175
|
};
|
|
104
|
-
const seal = (collection, recordKey, bytes) => {
|
|
105
|
-
const nonce = random(24);
|
|
106
|
-
const ciphertext = xchacha20poly1305(key, nonce, aad(collection, recordKey)).encrypt(bytes);
|
|
107
|
-
const record = new Uint8Array(24 + ciphertext.length);
|
|
108
|
-
record.set(nonce, 0);
|
|
109
|
-
record.set(ciphertext, 24);
|
|
110
|
-
return record;
|
|
111
|
-
};
|
|
112
|
-
const open = (collection, recordKey, record) => {
|
|
113
|
-
if (record.length < 24) throw new EngineStoreError("integrity", "engine record too short");
|
|
114
|
-
try {
|
|
115
|
-
return xchacha20poly1305(key, record.slice(0, 24), aad(collection, recordKey)).decrypt(record.slice(24));
|
|
116
|
-
} catch {
|
|
117
|
-
throw new EngineStoreError("integrity", "engine record failed integrity");
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
176
|
const make = (name) => ({
|
|
121
177
|
get: async (recordKey) => {
|
|
122
178
|
const database = guard();
|
|
123
179
|
checkName("key", recordKey);
|
|
124
|
-
const
|
|
125
|
-
|
|
180
|
+
const recId = recordId(idKey, name, recordKey);
|
|
181
|
+
const record = await request(database.transaction(RECORDS, "readonly").objectStore(RECORDS).get(recId));
|
|
182
|
+
return record === void 0 ? void 0 : openRecord(sealKey, aad("record", recId), record);
|
|
126
183
|
},
|
|
127
184
|
put: async (recordKey, bytes) => {
|
|
128
185
|
const database = guard();
|
|
129
186
|
checkName("key", recordKey);
|
|
130
|
-
const
|
|
131
|
-
|
|
187
|
+
const recId = recordId(idKey, name, recordKey);
|
|
188
|
+
const header = utf8.encode(`${name}\u0000${recordKey}`);
|
|
189
|
+
const tx = database.transaction([RECORDS, INDEX], "readwrite");
|
|
190
|
+
tx.objectStore(RECORDS).put(sealRecord(sealKey, random, aad("record", recId), bytes), recId);
|
|
191
|
+
tx.objectStore(INDEX).put(sealRecord(sealKey, random, aad("index", recId), header), recId);
|
|
132
192
|
await done(tx);
|
|
133
193
|
},
|
|
134
194
|
delete: async (recordKey) => {
|
|
135
195
|
const database = guard();
|
|
136
196
|
checkName("key", recordKey);
|
|
137
|
-
const
|
|
138
|
-
tx.
|
|
197
|
+
const recId = recordId(idKey, name, recordKey);
|
|
198
|
+
const tx = database.transaction([RECORDS, INDEX], "readwrite");
|
|
199
|
+
tx.objectStore(RECORDS).delete(recId);
|
|
200
|
+
tx.objectStore(INDEX).delete(recId);
|
|
139
201
|
await done(tx);
|
|
140
202
|
},
|
|
141
203
|
list: async () => {
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
|
|
204
|
+
const index = guard().transaction(INDEX, "readonly").objectStore(INDEX);
|
|
205
|
+
const keys = request(index.getAllKeys());
|
|
206
|
+
const values = request(index.getAll());
|
|
207
|
+
const [allKeys, allValues] = await Promise.all([keys, values]);
|
|
208
|
+
const out = [];
|
|
209
|
+
for (const [i, k] of allKeys.entries()) {
|
|
210
|
+
if (k === CHECK_KEY || typeof k !== "string") continue;
|
|
211
|
+
const value = allValues[i];
|
|
212
|
+
if (!(value instanceof Uint8Array)) continue;
|
|
213
|
+
const plain = openRecord(sealKey, aad("index", k), value);
|
|
214
|
+
if (plain === void 0) continue;
|
|
215
|
+
const text = utf8decode.decode(plain);
|
|
216
|
+
const nul = text.indexOf("\0");
|
|
217
|
+
if (nul !== -1 && text.slice(0, nul) === name) out.push(text.slice(nul + 1));
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
145
220
|
}
|
|
146
221
|
});
|
|
147
222
|
return {
|
|
@@ -152,7 +227,8 @@ function makeStore(db, key, random) {
|
|
|
152
227
|
close: async () => {
|
|
153
228
|
closed = true;
|
|
154
229
|
db.close();
|
|
155
|
-
|
|
230
|
+
sealKey.fill(0);
|
|
231
|
+
idKey.fill(0);
|
|
156
232
|
await Promise.resolve();
|
|
157
233
|
}
|
|
158
234
|
};
|
package/dist/idb.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idb.mjs","names":["STORE"],"sources":["../src/errors.ts","../src/store/guard.ts","../src/idb/requests.ts","../src/idb/public-store.ts","../src/idb/indexeddb.ts"],"sourcesContent":["export type EngineErrorCode = \"closed\" | \"integrity\" | \"invalid-input\";\n\n/** Typed engine errors: store codes are `closed` and `integrity` (decrypt or bind failure). */\nexport class EngineStoreError extends Error {\n readonly code: EngineErrorCode;\n\n constructor(code: EngineErrorCode, message: string) {\n super(message);\n this.name = \"EngineStoreError\";\n this.code = code;\n }\n}\n\nexport const errorMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error);\n","import { EngineStoreError } from \"../errors.ts\";\n\n/** NUL is the composite-key/AAD separator — a name or key containing it collides. */\nexport function checkName(kind: \"collection\" | \"key\", value: string): void {\n if (value.includes(\"\\u0000\")) {\n throw new EngineStoreError(\"invalid-input\", `${kind} must not contain NUL`);\n }\n}\n","export async function request<T>(req: IDBRequest<T>): Promise<T> {\n return new Promise((resolve, reject) => {\n req.addEventListener(\"success\", () => {\n resolve(req.result);\n });\n req.addEventListener(\"error\", () => {\n reject(new Error(\"indexeddb request failed\", { cause: req.error }));\n });\n });\n}\n\nexport async function done(tx: IDBTransaction): Promise<void> {\n return new Promise((resolve, reject) => {\n tx.addEventListener(\"complete\", () => {\n resolve();\n });\n tx.addEventListener(\"error\", () => {\n reject(new Error(\"indexeddb transaction failed\", { cause: tx.error }));\n });\n tx.addEventListener(\"abort\", () => {\n reject(new Error(\"indexeddb transaction aborted\", { cause: tx.error }));\n });\n });\n}\n","import { checkName } from \"../store/guard.ts\";\nimport type { PublicStore } from \"../store/port.ts\";\nimport { done, request } from \"./requests.ts\";\n\nexport type IndexedDbPublicStoreOptions = { readonly name: string };\n\nconst STORE = \"records\";\n\n/** An unencrypted IndexedDB PublicStore: one database, one `records` object store. */\nexport async function openIndexedDbPublicStore(\n options: IndexedDbPublicStoreOptions,\n): Promise<PublicStore> {\n const db = await new Promise<IDBDatabase>((resolve, reject) => {\n const open = indexedDB.open(options.name, 1);\n open.addEventListener(\"upgradeneeded\", () => {\n open.result.createObjectStore(STORE);\n });\n open.addEventListener(\"success\", () => {\n resolve(open.result);\n });\n open.addEventListener(\"error\", () => {\n reject(new Error(\"indexeddb open failed\", { cause: open.error }));\n });\n });\n return {\n get: async (key) => {\n checkName(\"key\", key);\n const tx = db.transaction(STORE, \"readonly\");\n // oxlint-disable-next-line typescript/no-unsafe-argument -- IDB get() is any-typed by spec\n const value = await request<Uint8Array | undefined>(tx.objectStore(STORE).get(key));\n return value === undefined ? undefined : new Uint8Array(value);\n },\n put: async (key, bytes) => {\n checkName(\"key\", key);\n const tx = db.transaction(STORE, \"readwrite\");\n tx.objectStore(STORE).put(new Uint8Array(bytes), key);\n await done(tx);\n },\n };\n}\n","/**\n * The Web EngineStore: one IndexedDB database, one `records` object store, values encrypted per\n * record with XChaCha20-Poly1305. Key = the injected 32-byte data key; nonce = 24 random bytes\n * stored as nonce‖ciphertext; AAD = UTF-8 `<collection>\\0<key>` — moving a record to another key or\n * collection fails the MAC, same as a tampered payload. `close()` drops the connection, wipes the\n * module-held key copy and latches every call to `closed`.\n */\nimport { xchacha20poly1305 } from \"@noble/ciphers/chacha.js\";\n\nimport { EngineStoreError } from \"../errors.ts\";\nimport { checkName } from \"../store/guard.ts\";\nimport type { EngineCollection, EngineStore } from \"../store/port.ts\";\nimport { done, request } from \"./requests.ts\";\n\nexport { openIndexedDbPublicStore } from \"./public-store.ts\";\nexport type { IndexedDbPublicStoreOptions } from \"./public-store.ts\";\n\nexport type Random = (length: number) => Uint8Array;\n\nexport type IndexedDbEngineStoreOptions = {\n readonly name: string;\n readonly dataKey: Uint8Array;\n readonly random: Random;\n};\n\nconst STORE = \"records\";\n\nconst id = (collection: string, recordKey: string): string => `${collection}\\u0000${recordKey}`;\nconst aad = (collection: string, recordKey: string): Uint8Array =>\n new TextEncoder().encode(`${collection}\\u0000${recordKey}`);\n\nexport async function openIndexedDbEngineStore(\n options: IndexedDbEngineStoreOptions,\n): Promise<EngineStore> {\n const key = new Uint8Array(options.dataKey);\n return new Promise<EngineStore>((resolve, reject) => {\n const open = indexedDB.open(options.name, 1);\n open.addEventListener(\"upgradeneeded\", () => {\n open.result.createObjectStore(STORE);\n });\n open.addEventListener(\"success\", () => {\n resolve(makeStore(open.result, key, options.random));\n });\n open.addEventListener(\"error\", () => {\n key.fill(0);\n reject(new Error(\"indexeddb open failed\", { cause: open.error }));\n });\n });\n}\n\nfunction makeStore(db: IDBDatabase, key: Uint8Array, random: Random): EngineStore {\n let closed = false;\n\n const guard = (): IDBDatabase => {\n if (closed) {\n throw new EngineStoreError(\"closed\", \"engine store is closed\");\n }\n return db;\n };\n\n const seal = (collection: string, recordKey: string, bytes: Uint8Array): Uint8Array => {\n const nonce = random(24);\n const ciphertext = xchacha20poly1305(key, nonce, aad(collection, recordKey)).encrypt(bytes);\n const record = new Uint8Array(24 + ciphertext.length);\n record.set(nonce, 0);\n record.set(ciphertext, 24);\n return record;\n };\n\n const open = (collection: string, recordKey: string, record: Uint8Array): Uint8Array => {\n if (record.length < 24) {\n throw new EngineStoreError(\"integrity\", \"engine record too short\");\n }\n try {\n return xchacha20poly1305(key, record.slice(0, 24), aad(collection, recordKey)).decrypt(\n record.slice(24),\n );\n } catch {\n throw new EngineStoreError(\"integrity\", \"engine record failed integrity\");\n }\n };\n\n const make = (name: string): EngineCollection => ({\n get: async (recordKey) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const tx = database.transaction(STORE, \"readonly\");\n const raw = tx.objectStore(STORE).get(id(name, recordKey));\n // oxlint-disable-next-line typescript/no-unsafe-argument -- IDB get() is any-typed by spec\n const record = await request<Uint8Array | undefined>(raw);\n return record === undefined ? undefined : open(name, recordKey, record);\n },\n put: async (recordKey, bytes) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const tx = database.transaction(STORE, \"readwrite\");\n tx.objectStore(STORE).put(seal(name, recordKey, bytes), id(name, recordKey));\n await done(tx);\n },\n delete: async (recordKey) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const tx = database.transaction(STORE, \"readwrite\");\n tx.objectStore(STORE).delete(id(name, recordKey));\n await done(tx);\n },\n list: async () => {\n const database = guard();\n const tx = database.transaction(STORE, \"readonly\");\n const all = tx.objectStore(STORE).getAllKeys();\n const keys = await request<IDBValidKey[]>(all);\n const prefix = `${name}\\u0000`;\n return keys\n .filter((k): k is string => typeof k === \"string\" && k.startsWith(prefix))\n .map((k) => k.slice(prefix.length));\n },\n });\n\n return {\n collection: (name) => {\n checkName(\"collection\", name);\n return make(name);\n },\n close: async () => {\n closed = true;\n db.close();\n key.fill(0);\n await Promise.resolve();\n },\n };\n}\n"],"mappings":";;;AAGA,IAAa,mBAAb,cAAsC,MAAM;CAC1C;CAEA,YAAY,MAAuB,SAAiB;EAClD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;ACRA,SAAgB,UAAU,MAA4B,OAAqB;CACzE,IAAI,MAAM,SAAS,IAAQ,GACzB,MAAM,IAAI,iBAAiB,iBAAiB,GAAG,KAAK,sBAAsB;AAE9E;;ACPA,eAAsB,QAAW,KAAgC;CAC/D,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,IAAI,iBAAiB,iBAAiB;GACpC,QAAQ,IAAI,MAAM;EACpB,CAAC;EACD,IAAI,iBAAiB,eAAe;GAClC,OAAO,IAAI,MAAM,4BAA4B,EAAE,OAAO,IAAI,MAAM,CAAC,CAAC;EACpE,CAAC;CACH,CAAC;AACH;AAEA,eAAsB,KAAK,IAAmC;CAC5D,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,GAAG,iBAAiB,kBAAkB;GACpC,QAAQ;EACV,CAAC;EACD,GAAG,iBAAiB,eAAe;GACjC,OAAO,IAAI,MAAM,gCAAgC,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;EACvE,CAAC;EACD,GAAG,iBAAiB,eAAe;GACjC,OAAO,IAAI,MAAM,iCAAiC,EAAE,OA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C,YAAY,KAAK,CAAC,CAAC,IAAI,GAAG,MAAM,SAAS,CAEH,CAAG;GACxD,OAAO,WAAW,KAAA,IAAY,KAAA,IAAY,KAAK,MAAM,WAAW,MAAM;EACxE;EACA,KAAK,OAAO,WAAW,UAAU;GAC/B,MAAM,WAAW,MAAM;GACvB,UAAU,OAAO,SAAS;GAC1B,MAAM,KAAK,SAAS,YAAY,OAAO,WAAW;GAClD,GAAG,YAAY,KAAK,CAAC,CAAC,IAAI,KAAK,MAAM,WAAW,KAAK,GAAG,GAAG,MAAM,SAAS,CAAC;GAC3E,MAAM,KAAK,EAAE;EACf;EACA,QAAQ,OAAO,cAAc;GAC3B,MAAM,WAAW,MAAM;GACvB,UAAU,OAAO,SAAS;GAC1B,MAAM,KAAK,SAAS,YAAY,OAAO,WAAW;GAClD,GAAG,YAAY,KAAK,CAAC,CAAC,OAAO,GAAG,MAAM,SAAS,CAAC;GAChD,MAAM,KAAK,EAAE;EACf;EACA,MAAM,YAAY;GAIhB,MAAM,OAAO,MAAM,QAHF,MACC,CAAC,CAAC,YAAY,OAAO,UAC1B,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,WACQ,CAAG;GAC7C,MAAM,SAAS,GAAG,KAAK;GACvB,OAAO,KACJ,QAAQ,MAAmB,OAAO,MAAM,YAAY,EAAE,WAAW,MAAM,CAAC,CAAC,CACzE,KAAK,MAAM,EAAE,MAAM,OAAO,MAAM,CAAC;EACtC;CACF;CAEA,OAAO;EACL,aAAa,SAAS;GACpB,UAAU,cAAc,IAAI;GAC5B,OAAO,KAAK,IAAI;EAClB;EACA,OAAO,YAAY;GACjB,SAAS;GACT,GAAG,MAAM;GACT,IAAI,KAAK,CAAC;GACV,MAAM,QAAQ,QAAQ;EACxB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"idb.mjs","names":[],"sources":["../src/errors.ts","../src/store/guard.ts","../src/idb/requests.ts","../src/idb/public-store.ts","../src/idb/indexeddb.ts"],"sourcesContent":["import { ChainError } from \"@qntx/wallet-chains\";\n\nexport type EngineErrorCode = \"closed\" | \"invalid-input\";\n\n/** Typed engine errors: store codes are `closed` and `invalid-input`. */\nexport class EngineStoreError extends Error {\n readonly code: EngineErrorCode;\n\n constructor(code: EngineErrorCode, message: string) {\n super(message);\n this.name = \"EngineStoreError\";\n this.code = code;\n }\n}\n\nexport const errorMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error);\n\n/** Why an NFT transfer preparation refused, surfaced for callers that branch on it. */\nexport type NftRefusal =\n | \"not-nft\"\n | \"not-owned\"\n | \"insufficient-balance\"\n | \"programmable\"\n | \"frozen\"\n | \"not-found\";\n\n/** An NFT send refusal: `code` stays `invalid-request`, `reason` names which guard fired. */\nexport class NftTransferError extends ChainError {\n readonly reason: NftRefusal;\n\n constructor(reason: NftRefusal, message: string) {\n super(\"invalid-request\", message);\n this.name = \"NftTransferError\";\n this.reason = reason;\n }\n}\n","import { EngineStoreError } from \"../errors.ts\";\n\n/** NUL is the composite-key/AAD separator — a name or key containing it collides. */\nexport function checkName(kind: \"collection\" | \"key\", value: string): void {\n if (value.includes(\"\\u0000\")) {\n throw new EngineStoreError(\"invalid-input\", `${kind} must not contain NUL`);\n }\n}\n","export async function request<T>(req: IDBRequest<T>): Promise<T> {\n return new Promise((resolve, reject) => {\n req.addEventListener(\"success\", () => {\n resolve(req.result);\n });\n req.addEventListener(\"error\", () => {\n reject(new Error(\"indexeddb request failed\", { cause: req.error }));\n });\n });\n}\n\nexport async function done(tx: IDBTransaction): Promise<void> {\n return new Promise((resolve, reject) => {\n tx.addEventListener(\"complete\", () => {\n resolve();\n });\n tx.addEventListener(\"error\", () => {\n reject(new Error(\"indexeddb transaction failed\", { cause: tx.error }));\n });\n tx.addEventListener(\"abort\", () => {\n reject(new Error(\"indexeddb transaction aborted\", { cause: tx.error }));\n });\n });\n}\n","import { checkName } from \"../store/guard.ts\";\nimport type { PublicStore } from \"../store/port.ts\";\nimport { done, request } from \"./requests.ts\";\n\nexport type IndexedDbPublicStoreOptions = { readonly name: string };\n\nconst STORE = \"records\";\n\n/** An unencrypted IndexedDB PublicStore: one database, one `records` object store. */\nexport async function openIndexedDbPublicStore(\n options: IndexedDbPublicStoreOptions,\n): Promise<PublicStore> {\n const db = await new Promise<IDBDatabase>((resolve, reject) => {\n const open = indexedDB.open(options.name, 1);\n open.addEventListener(\"upgradeneeded\", () => {\n open.result.createObjectStore(STORE);\n });\n open.addEventListener(\"success\", () => {\n resolve(open.result);\n });\n open.addEventListener(\"error\", () => {\n reject(new Error(\"indexeddb open failed\", { cause: open.error }));\n });\n });\n return {\n get: async (key) => {\n checkName(\"key\", key);\n const tx = db.transaction(STORE, \"readonly\");\n // oxlint-disable-next-line typescript/no-unsafe-argument -- IDB get() is any-typed by spec\n const value = await request<Uint8Array | undefined>(tx.objectStore(STORE).get(key));\n return value === undefined ? undefined : new Uint8Array(value);\n },\n put: async (key, bytes) => {\n checkName(\"key\", key);\n const tx = db.transaction(STORE, \"readwrite\");\n tx.objectStore(STORE).put(new Uint8Array(bytes), key);\n await done(tx);\n },\n };\n}\n","/**\n * The Web EngineStore: one IndexedDB database (format 2), two object stores, values encrypted per\n * record with XChaCha20-Poly1305. The injected data key derives two subkeys at open via\n * HKDF-SHA256: `sealKey` encrypts every row, `idKey` names them — a record id is the lowercase hex\n * of `hmac(sha256, idKey, utf8(collection) ‖ 0x00 ‖ utf8(key))`, so nothing readable on disk\n * reveals collection names or record keys.\n *\n * `records` maps id → nonce‖ciphertext(value) under AAD `record\\0${id}`; `index` maps the same id →\n * nonce‖ciphertext(utf8(`${collection}\\0${key}`)) under AAD `index\\0${id}` and backs `list`. Moving\n * a row to another id fails its MAC, same as a tampered payload, and a record that fails its MAC\n * reads exactly like a missing one. A reserved `check` row in `index` sealed under a fixed AAD\n * proves the data key at open: a database keyed differently is rebuilt empty. This still leaks the\n * record count, the value sizes and write timing. `close()` drops the connection, wipes both\n * subkeys and latches every call to `closed`.\n */\nimport { xchacha20poly1305 } from \"@noble/ciphers/chacha.js\";\nimport { hkdf } from \"@noble/hashes/hkdf.js\";\nimport { hmac } from \"@noble/hashes/hmac.js\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { bytesToHex } from \"@noble/hashes/utils.js\";\n\nimport { EngineStoreError } from \"../errors.ts\";\nimport { checkName } from \"../store/guard.ts\";\nimport type { EngineCollection, EngineStore } from \"../store/port.ts\";\nimport { done, request } from \"./requests.ts\";\n\nexport { openIndexedDbPublicStore } from \"./public-store.ts\";\nexport type { IndexedDbPublicStoreOptions } from \"./public-store.ts\";\n\nexport type Random = (length: number) => Uint8Array;\n\nexport type IndexedDbEngineStoreOptions = {\n readonly name: string;\n readonly dataKey: Uint8Array;\n readonly random: Random;\n};\n\nconst RECORDS = \"records\";\nconst INDEX = \"index\";\nconst CHECK_KEY = \"check\";\nconst CHECK_AAD = new TextEncoder().encode(\"qntx-engine-store-check\");\n\nconst utf8 = new TextEncoder();\nconst utf8decode = new TextDecoder();\n\nconst recordId = (idKey: Uint8Array, collection: string, recordKey: string): string => {\n const c = utf8.encode(collection);\n const k = utf8.encode(recordKey);\n const msg = new Uint8Array(c.length + 1 + k.length);\n msg.set(c, 0);\n msg.set(k, c.length + 1);\n const hex = bytesToHex(hmac(sha256, idKey, msg));\n msg.fill(0);\n return hex;\n};\n\nconst aad = (kind: \"record\" | \"index\", id: string): Uint8Array => utf8.encode(`${kind}\\u0000${id}`);\n\nconst sealRecord = (\n key: Uint8Array,\n random: Random,\n aadBytes: Uint8Array,\n bytes: Uint8Array,\n): Uint8Array => {\n const nonce = random(24);\n const ciphertext = xchacha20poly1305(key, nonce, aadBytes).encrypt(bytes);\n const record = new Uint8Array(24 + ciphertext.length);\n record.set(nonce, 0);\n record.set(ciphertext, 24);\n return record;\n};\n\n/** The plaintext, or `undefined` when the record fails authentication — it reads as deleted. */\nconst openRecord = (\n key: Uint8Array,\n aadBytes: Uint8Array,\n record: Uint8Array,\n): Uint8Array | undefined => {\n if (record.length < 24) {\n return undefined;\n }\n try {\n return xchacha20poly1305(key, record.slice(0, 24), aadBytes).decrypt(record.slice(24));\n } catch {\n return undefined;\n }\n};\n\nexport async function openIndexedDbEngineStore(\n options: IndexedDbEngineStoreOptions,\n): Promise<EngineStore> {\n const key = new Uint8Array(options.dataKey);\n const sealKey = hkdf(sha256, key, undefined, utf8.encode(\"qntx/engine-store/seal\"), 32);\n const idKey = hkdf(sha256, key, undefined, utf8.encode(\"qntx/engine-store/id\"), 32);\n key.fill(0);\n const db = await new Promise<IDBDatabase>((resolve, reject) => {\n const open = indexedDB.open(options.name, 2);\n open.addEventListener(\"upgradeneeded\", () => {\n const { result } = open;\n for (const storeName of result.objectStoreNames) {\n result.deleteObjectStore(storeName);\n }\n result.createObjectStore(RECORDS);\n result.createObjectStore(INDEX);\n });\n open.addEventListener(\"success\", () => {\n resolve(open.result);\n });\n open.addEventListener(\"error\", () => {\n sealKey.fill(0);\n idKey.fill(0);\n reject(new Error(\"indexeddb open failed\", { cause: open.error }));\n });\n });\n try {\n await checkStoreKey(db, sealKey, options.random);\n } catch (error) {\n db.close();\n sealKey.fill(0);\n idKey.fill(0);\n throw error;\n }\n return makeStore(db, sealKey, idKey, options.random);\n}\n\n/** One read-write transaction before the store is handed out: `check` must open under this key. */\nasync function checkStoreKey(db: IDBDatabase, key: Uint8Array, random: Random): Promise<void> {\n const tx = db.transaction([RECORDS, INDEX], \"readwrite\");\n const index = tx.objectStore(INDEX);\n // oxlint-disable-next-line typescript/no-unsafe-argument -- IDB get() is any-typed by spec\n const existing = await request<Uint8Array | undefined>(index.get(CHECK_KEY));\n if (existing === undefined || openRecord(key, CHECK_AAD, existing) === undefined) {\n // Rows sealed under another data key (a reset or recreated vault) are unreadable by\n // construction — the store is rebuilt empty rather than served back as dead rows.\n tx.objectStore(RECORDS).clear();\n index.clear();\n index.put(sealRecord(key, random, CHECK_AAD, new Uint8Array(0)), CHECK_KEY);\n }\n await done(tx);\n}\n\nfunction makeStore(\n db: IDBDatabase,\n sealKey: Uint8Array,\n idKey: Uint8Array,\n random: Random,\n): EngineStore {\n let closed = false;\n\n const guard = (): IDBDatabase => {\n if (closed) {\n throw new EngineStoreError(\"closed\", \"engine store is closed\");\n }\n return db;\n };\n\n const make = (name: string): EngineCollection => ({\n get: async (recordKey) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const recId = recordId(idKey, name, recordKey);\n const tx = database.transaction(RECORDS, \"readonly\");\n const raw = tx.objectStore(RECORDS).get(recId);\n // oxlint-disable-next-line typescript/no-unsafe-argument -- IDB get() is any-typed by spec\n const record = await request<Uint8Array | undefined>(raw);\n return record === undefined ? undefined : openRecord(sealKey, aad(\"record\", recId), record);\n },\n put: async (recordKey, bytes) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const recId = recordId(idKey, name, recordKey);\n const header = utf8.encode(`${name}\\u0000${recordKey}`);\n const tx = database.transaction([RECORDS, INDEX], \"readwrite\");\n tx.objectStore(RECORDS).put(sealRecord(sealKey, random, aad(\"record\", recId), bytes), recId);\n tx.objectStore(INDEX).put(sealRecord(sealKey, random, aad(\"index\", recId), header), recId);\n await done(tx);\n },\n delete: async (recordKey) => {\n const database = guard();\n checkName(\"key\", recordKey);\n const recId = recordId(idKey, name, recordKey);\n const tx = database.transaction([RECORDS, INDEX], \"readwrite\");\n tx.objectStore(RECORDS).delete(recId);\n tx.objectStore(INDEX).delete(recId);\n await done(tx);\n },\n list: async () => {\n const database = guard();\n const tx = database.transaction(INDEX, \"readonly\");\n const index = tx.objectStore(INDEX);\n // Both requests issue in this task so the transaction stays alive; getAll returns values\n // in the same key order as getAllKeys.\n const keys = request<IDBValidKey[]>(index.getAllKeys());\n const values = request<unknown[]>(index.getAll());\n const [allKeys, allValues] = await Promise.all([keys, values]);\n const out: string[] = [];\n for (const [i, k] of allKeys.entries()) {\n if (k === CHECK_KEY || typeof k !== \"string\") {\n continue;\n }\n const value = allValues[i];\n if (!(value instanceof Uint8Array)) {\n continue;\n }\n const plain = openRecord(sealKey, aad(\"index\", k), value);\n if (plain === undefined) {\n continue;\n }\n const text = utf8decode.decode(plain);\n const nul = text.indexOf(\"\\u0000\");\n if (nul !== -1 && text.slice(0, nul) === name) {\n out.push(text.slice(nul + 1));\n }\n }\n return out;\n },\n });\n\n return {\n collection: (name) => {\n checkName(\"collection\", name);\n return make(name);\n },\n close: async () => {\n closed = true;\n db.close();\n sealKey.fill(0);\n idKey.fill(0);\n await Promise.resolve();\n },\n };\n}\n"],"mappings":";;;;;;;;AAKA,IAAa,mBAAb,cAAsC,MAAM;CAC1C;CAEA,YAAY,MAAuB,SAAiB;EAClD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;ACVA,SAAgB,UAAU,MAA4B,OAAqB;CACzE,IAAI,MAAM,SAAS,IAAQ,GACzB,MAAM,IAAI,iBAAiB,iBAAiB,GAAG,KAAK,sBAAsB;AAE9E;;ACPA,eAAsB,QAAW,KAAgC;CAC/D,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,IAAI,iBAAiB,iBAAiB;GACpC,QAAQ,IAAI,MAAM;EACpB,CAAC;EACD,IAAI,iBAAiB,eAAe;GAClC,OAAO,IAAI,MAAM,4BAA4B,EAAE,OAAO,IAAI,MAAM,CAAC,CAAC;EACpE,CAAC;CACH,CAAC;AACH;AAEA,eAAsB,KAAK,IAAmC;CAC5D,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,GAAG,iBAAiB,kBAAkB;GACpC,QAAQ;EACV,CAAC;EACD,GAAG,iBAAiB,eAAe;GACjC,OAAO,IAAI,MAAM,gCAAgC,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;EACvE,CAAC;EACD,GAAG,iBAAiB,eAAe;GACjC,OAAO,IAAI,MAAM,iCAAiC,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;EACxE,CAAC;CACH,CAAC;AACH;;ACjBA,MAAM,QAAQ;;AAGd,eAAsB,yBACpB,SACsB;CACtB,MAAM,KAAK,MAAM,IAAI,SAAsB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