flatsql 0.4.0 → 0.4.3
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 +100 -0
- package/package.json +21 -6
- package/sdm/flatsql-spatial.wasm +0 -0
- package/sdm/index.d.ts +88 -0
- package/sdm/index.js +253 -0
- package/sdm/manifest.json +402 -0
- package/wasm/flatsql-wasi.wasm +0 -0
- package/wasm/flatsql.js +16 -2
- package/wasm/flatsql.wasm +0 -0
- package/wasm/index.d.ts +40 -1
- package/wasm/index.js +75 -19
package/wasm/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface FlatSQLDatabase {
|
|
|
29
29
|
registerFileId(fileId: string, tableName: string): void;
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Enable demo field extractors for User and
|
|
32
|
+
* Enable built-in demo field extractors for User, Post, MPE, and Telemetry tables
|
|
33
33
|
*/
|
|
34
34
|
enableDemoExtractors(): void;
|
|
35
35
|
|
|
@@ -249,6 +249,35 @@ export interface FlatSQL {
|
|
|
249
249
|
*/
|
|
250
250
|
createTestPost(id: number, userId: number, title: string): Uint8Array;
|
|
251
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Create a test CCSDS OMM / MPE FlatBuffer (for demos)
|
|
254
|
+
*/
|
|
255
|
+
createTestMPE(
|
|
256
|
+
entityId: string,
|
|
257
|
+
epoch: number,
|
|
258
|
+
meanMotion: number,
|
|
259
|
+
eccentricity: number,
|
|
260
|
+
inclination: number,
|
|
261
|
+
raOfAscNode: number,
|
|
262
|
+
argOfPericenter: number,
|
|
263
|
+
meanAnomaly: number,
|
|
264
|
+
bstar: number,
|
|
265
|
+
meanElementTheory?: number
|
|
266
|
+
): Uint8Array;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Create a test CCSDS-style telemetry FlatBuffer (for demos)
|
|
270
|
+
*/
|
|
271
|
+
createTestTelemetry(
|
|
272
|
+
packetId: number,
|
|
273
|
+
spacecraft: string,
|
|
274
|
+
subsystem: string,
|
|
275
|
+
mode: string,
|
|
276
|
+
temperatureC: number,
|
|
277
|
+
signalDb: number,
|
|
278
|
+
timestampS: number
|
|
279
|
+
): Uint8Array;
|
|
280
|
+
|
|
252
281
|
/**
|
|
253
282
|
* Check if WASM was loaded with integrity verification
|
|
254
283
|
*/
|
|
@@ -283,6 +312,16 @@ export interface InitOptions {
|
|
|
283
312
|
*/
|
|
284
313
|
requireIntegrity?: boolean;
|
|
285
314
|
|
|
315
|
+
/**
|
|
316
|
+
* SHA-384 digest provider used for browser integrity verification.
|
|
317
|
+
* Browser WebCrypto is intentionally not used; browser callers that require
|
|
318
|
+
* integrity verification must pass a WASM/native-backed provider.
|
|
319
|
+
* The result may be a base64 digest string or raw digest bytes.
|
|
320
|
+
*/
|
|
321
|
+
computeSHA384?: (
|
|
322
|
+
data: ArrayBuffer
|
|
323
|
+
) => Promise<string | Uint8Array | ArrayBuffer> | string | Uint8Array | ArrayBuffer;
|
|
324
|
+
|
|
286
325
|
/**
|
|
287
326
|
* Custom Emscripten module factory function
|
|
288
327
|
* Default: built-in FlatSQLModule
|
package/wasm/index.js
CHANGED
|
@@ -9,30 +9,60 @@ let api = null;
|
|
|
9
9
|
// Security: Track if integrity was verified
|
|
10
10
|
let integrityVerified = false;
|
|
11
11
|
|
|
12
|
+
function toBase64(bytes) {
|
|
13
|
+
if (typeof Buffer !== 'undefined') {
|
|
14
|
+
return Buffer.from(bytes).toString('base64');
|
|
15
|
+
}
|
|
16
|
+
let binary = '';
|
|
17
|
+
for (let offset = 0; offset < bytes.length; offset += 0x8000) {
|
|
18
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + 0x8000));
|
|
19
|
+
}
|
|
20
|
+
return btoa(binary);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function normalizeHashResult(value) {
|
|
24
|
+
if (typeof value === 'string') {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
if (value instanceof Uint8Array) {
|
|
28
|
+
return toBase64(value);
|
|
29
|
+
}
|
|
30
|
+
if (ArrayBuffer.isView(value)) {
|
|
31
|
+
return toBase64(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
32
|
+
}
|
|
33
|
+
if (value instanceof ArrayBuffer) {
|
|
34
|
+
return toBase64(new Uint8Array(value));
|
|
35
|
+
}
|
|
36
|
+
throw new Error('SHA-384 provider must return a base64 string or binary digest');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function hasNodeProcess() {
|
|
40
|
+
return typeof process !== 'undefined' &&
|
|
41
|
+
process.versions !== undefined &&
|
|
42
|
+
typeof process.versions.node === 'string';
|
|
43
|
+
}
|
|
44
|
+
|
|
12
45
|
/**
|
|
13
|
-
* Compute SHA-384 hash of data and return as base64
|
|
14
|
-
*
|
|
46
|
+
* Compute SHA-384 hash of data and return as base64.
|
|
47
|
+
* Browser WebCrypto is intentionally not used; browser callers that require
|
|
48
|
+
* integrity verification must pass computeSHA384 backed by WASM/native crypto.
|
|
15
49
|
* @param {ArrayBuffer} data
|
|
50
|
+
* @param {(data: ArrayBuffer) => Promise<string|Uint8Array|ArrayBuffer>|string|Uint8Array|ArrayBuffer} [provider]
|
|
16
51
|
* @returns {Promise<string>}
|
|
17
52
|
*/
|
|
18
|
-
async function computeSHA384(data) {
|
|
19
|
-
if (typeof
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (typeof btoa !== 'undefined') {
|
|
25
|
-
return btoa(String.fromCharCode(...hashArray));
|
|
26
|
-
} else {
|
|
27
|
-
return Buffer.from(hashArray).toString('base64');
|
|
28
|
-
}
|
|
29
|
-
} else {
|
|
30
|
-
// Node.js fallback using dynamic import
|
|
31
|
-
const cryptoModule = await import('crypto');
|
|
53
|
+
async function computeSHA384(data, provider) {
|
|
54
|
+
if (typeof provider === 'function') {
|
|
55
|
+
return normalizeHashResult(await provider(data));
|
|
56
|
+
}
|
|
57
|
+
if (hasNodeProcess()) {
|
|
58
|
+
const cryptoModule = await import('node:crypto');
|
|
32
59
|
const hash = cryptoModule.createHash('sha384');
|
|
33
60
|
hash.update(Buffer.from(data));
|
|
34
61
|
return hash.digest('base64');
|
|
35
62
|
}
|
|
63
|
+
throw new Error(
|
|
64
|
+
'WASM integrity verification requires a computeSHA384 option backed by WASM/native crypto; browser WebCrypto is intentionally not used.'
|
|
65
|
+
);
|
|
36
66
|
}
|
|
37
67
|
|
|
38
68
|
/**
|
|
@@ -41,8 +71,8 @@ async function computeSHA384(data) {
|
|
|
41
71
|
* @param {string} expectedHash - Expected SHA-384 hash (base64)
|
|
42
72
|
* @returns {Promise<boolean>}
|
|
43
73
|
*/
|
|
44
|
-
async function verifyWASMIntegrity(wasmBinary, expectedHash) {
|
|
45
|
-
const computedHash = await computeSHA384(wasmBinary);
|
|
74
|
+
async function verifyWASMIntegrity(wasmBinary, expectedHash, options = {}) {
|
|
75
|
+
const computedHash = await computeSHA384(wasmBinary, options.computeSHA384);
|
|
46
76
|
return computedHash === expectedHash;
|
|
47
77
|
}
|
|
48
78
|
|
|
@@ -177,7 +207,7 @@ export async function initFlatSQL(moduleFactoryOrOptions) {
|
|
|
177
207
|
}
|
|
178
208
|
|
|
179
209
|
// Verify integrity
|
|
180
|
-
const isValid = await verifyWASMIntegrity(wasmBinary, expectedIntegrity);
|
|
210
|
+
const isValid = await verifyWASMIntegrity(wasmBinary, expectedIntegrity, options);
|
|
181
211
|
if (!isValid) {
|
|
182
212
|
throw new Error(
|
|
183
213
|
'WASM integrity check failed: hash mismatch. ' +
|
|
@@ -243,6 +273,8 @@ export async function initFlatSQL(moduleFactoryOrOptions) {
|
|
|
243
273
|
// Test helpers
|
|
244
274
|
createTestUser: Module.cwrap('flatsql_create_test_user', 'number', ['number', 'string', 'string', 'number']),
|
|
245
275
|
createTestPost: Module.cwrap('flatsql_create_test_post', 'number', ['number', 'number', 'string']),
|
|
276
|
+
createTestMPE: Module.cwrap('flatsql_create_test_mpe', 'number', ['string', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number', 'number']),
|
|
277
|
+
createTestTelemetry: Module.cwrap('flatsql_create_test_telemetry', 'number', ['number', 'string', 'string', 'string', 'number', 'number', 'number']),
|
|
246
278
|
testBufferSize: Module.cwrap('flatsql_test_buffer_size', 'number', []),
|
|
247
279
|
|
|
248
280
|
// Stats
|
|
@@ -333,6 +365,30 @@ export class FlatSQL {
|
|
|
333
365
|
return new Uint8Array(Module.HEAPU8.buffer, ptr, size).slice();
|
|
334
366
|
}
|
|
335
367
|
|
|
368
|
+
createTestMPE(entityId, epoch, meanMotion, eccentricity, inclination,
|
|
369
|
+
raOfAscNode, argOfPericenter, meanAnomaly, bstar, meanElementTheory = 0) {
|
|
370
|
+
const ptr = api.createTestMPE(
|
|
371
|
+
entityId,
|
|
372
|
+
epoch,
|
|
373
|
+
meanMotion,
|
|
374
|
+
eccentricity,
|
|
375
|
+
inclination,
|
|
376
|
+
raOfAscNode,
|
|
377
|
+
argOfPericenter,
|
|
378
|
+
meanAnomaly,
|
|
379
|
+
bstar,
|
|
380
|
+
meanElementTheory
|
|
381
|
+
);
|
|
382
|
+
const size = api.testBufferSize();
|
|
383
|
+
return new Uint8Array(Module.HEAPU8.buffer, ptr, size).slice();
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
createTestTelemetry(packetId, spacecraft, subsystem, mode, temperatureC, signalDb, timestampS) {
|
|
387
|
+
const ptr = api.createTestTelemetry(packetId, spacecraft, subsystem, mode, temperatureC, signalDb, timestampS);
|
|
388
|
+
const size = api.testBufferSize();
|
|
389
|
+
return new Uint8Array(Module.HEAPU8.buffer, ptr, size).slice();
|
|
390
|
+
}
|
|
391
|
+
|
|
336
392
|
/**
|
|
337
393
|
* Check if WASM was loaded with integrity verification
|
|
338
394
|
* @returns {boolean}
|