space-data-module-sdk 0.5.9 → 0.5.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "space-data-module-sdk",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "description": "Module SDK for building, validating, signing, and deploying WebAssembly modules on the Space Data Network.",
5
5
  "type": "module",
6
6
  "types": "./src/index.d.ts",
@@ -277,7 +277,27 @@ function validateEncTable(table, buffer, label) {
277
277
  maxLength: 32,
278
278
  });
279
279
  assertOptionalStringField(buffer, tableMeta, 22, `${label} root type`);
280
- const record = normalizeEncTable(table.unpack());
280
+ const timestamp = table.TIMESTAMP();
281
+ const record = {
282
+ version: Number(table.VERSION()),
283
+ keyExchange:
284
+ KEY_EXCHANGE_NAME_BY_VALUE[table.KEY_EXCHANGE()] ??
285
+ String(table.KEY_EXCHANGE()),
286
+ symmetric:
287
+ SYMMETRIC_ALGO_NAME_BY_VALUE[table.SYMMETRIC()] ??
288
+ String(table.SYMMETRIC()),
289
+ keyDerivation:
290
+ KDF_NAME_BY_VALUE[table.KEY_DERIVATION()] ??
291
+ String(table.KEY_DERIVATION()),
292
+ ephemeralPublicKey: normalizeByteField(table.ephemeralPublicKeyArray()),
293
+ nonceStart: normalizeByteField(table.nonceStartArray()),
294
+ recipientKeyId: normalizeByteField(table.recipientKeyIdArray()),
295
+ context: normalizeStringField(table.CONTEXT()),
296
+ schemaHash: normalizeByteField(table.schemaHashArray()),
297
+ rootType: normalizeStringField(table.ROOT_TYPE()),
298
+ timestamp:
299
+ timestamp === undefined || timestamp === null ? 0 : Number(timestamp),
300
+ };
281
301
  if (!record.ephemeralPublicKey?.length) {
282
302
  throw new Error(`${label} is missing the ephemeral public key.`);
283
303
  }
@@ -316,7 +336,17 @@ function validatePnmTable(table, buffer, label) {
316
336
  assertOptionalStringField(buffer, tableMeta, 16, `${label} timestamp signature`);
317
337
  assertOptionalStringField(buffer, tableMeta, 18, `${label} signature type`);
318
338
  assertOptionalStringField(buffer, tableMeta, 20, `${label} timestamp signature type`);
319
- const record = normalizePnmTable(table.unpack());
339
+ const record = {
340
+ multiformatAddress: normalizeStringField(table.MULTIFORMAT_ADDRESS()),
341
+ publishTimestamp: normalizeStringField(table.PUBLISH_TIMESTAMP()),
342
+ cid: normalizeStringField(table.CID()),
343
+ fileName: normalizeStringField(table.FILE_NAME()),
344
+ fileId: normalizeStringField(table.FILE_ID()),
345
+ signature: normalizeStringField(table.SIGNATURE()),
346
+ timestampSignature: normalizeStringField(table.TIMESTAMP_SIGNATURE()),
347
+ signatureType: normalizeStringField(table.SIGNATURE_TYPE()),
348
+ timestampSignatureType: normalizeStringField(table.TIMESTAMP_SIGNATURE_TYPE()),
349
+ };
320
350
  if (
321
351
  !record.multiformatAddress &&
322
352
  !record.publishTimestamp &&
@@ -426,48 +456,6 @@ function pnmTableFromObject(record = {}) {
426
456
  );
427
457
  }
428
458
 
429
- function normalizeEncTable(table) {
430
- if (!table) {
431
- return null;
432
- }
433
- return {
434
- version: Number(table.VERSION ?? 1),
435
- keyExchange:
436
- KEY_EXCHANGE_NAME_BY_VALUE[table.KEY_EXCHANGE] ?? String(table.KEY_EXCHANGE),
437
- symmetric:
438
- SYMMETRIC_ALGO_NAME_BY_VALUE[table.SYMMETRIC] ?? String(table.SYMMETRIC),
439
- keyDerivation:
440
- KDF_NAME_BY_VALUE[table.KEY_DERIVATION] ?? String(table.KEY_DERIVATION),
441
- ephemeralPublicKey: normalizeByteField(table.EPHEMERAL_PUBLIC_KEY),
442
- nonceStart: normalizeByteField(table.NONCE_START),
443
- recipientKeyId: normalizeByteField(table.RECIPIENT_KEY_ID),
444
- context: normalizeStringField(table.CONTEXT),
445
- schemaHash: normalizeByteField(table.SCHEMA_HASH),
446
- rootType: normalizeStringField(table.ROOT_TYPE),
447
- timestamp:
448
- table.TIMESTAMP === undefined || table.TIMESTAMP === null
449
- ? 0
450
- : Number(table.TIMESTAMP),
451
- };
452
- }
453
-
454
- function normalizePnmTable(table) {
455
- if (!table) {
456
- return null;
457
- }
458
- return {
459
- multiformatAddress: normalizeStringField(table.MULTIFORMAT_ADDRESS),
460
- publishTimestamp: normalizeStringField(table.PUBLISH_TIMESTAMP),
461
- cid: normalizeStringField(table.CID),
462
- fileName: normalizeStringField(table.FILE_NAME),
463
- fileId: normalizeStringField(table.FILE_ID),
464
- signature: normalizeStringField(table.SIGNATURE),
465
- timestampSignature: normalizeStringField(table.TIMESTAMP_SIGNATURE),
466
- signatureType: normalizeStringField(table.SIGNATURE_TYPE),
467
- timestampSignatureType: normalizeStringField(table.TIMESTAMP_SIGNATURE_TYPE),
468
- };
469
- }
470
-
471
459
  function readFooterLength(bytes) {
472
460
  const view = toUint8Array(bytes);
473
461
  if (view.length < TRAILER_FOOTER_LENGTH) {
@@ -601,7 +589,6 @@ export function decodePublicationRecordCollection(bytes) {
601
589
  if (recordTables.length === 0) {
602
590
  throw new Error("REC trailer does not contain any records.");
603
591
  }
604
- const collection = collectionTable.unpack();
605
592
  const records = [];
606
593
  let enc = null;
607
594
  let pnm = null;
@@ -622,10 +609,9 @@ export function decodePublicationRecordCollection(bytes) {
622
609
  8,
623
610
  `REC trailer record ${index} standard`,
624
611
  );
625
- const unpackedRecord = collection.RECORDS[index];
626
612
  const recordType = recordTable.value_type();
627
613
  const standard =
628
- normalizeStringField(unpackedRecord?.standard) ??
614
+ normalizeStringField(recordTable.standard()) ??
629
615
  STANDARD_BY_RECORD_TYPE[recordType] ??
630
616
  null;
631
617
  const expectedStandard =
@@ -644,10 +630,7 @@ export function decodePublicationRecordCollection(bytes) {
644
630
  if (!valueMeta) {
645
631
  throw new Error(`REC trailer record ${index} is missing a value.`);
646
632
  }
647
- let value =
648
- standard === "ENC" || standard === "PNM"
649
- ? null
650
- : unpackedRecord?.value ?? null;
633
+ let value = null;
651
634
  if (standard === "ENC") {
652
635
  const encTable = recordTable.value(new ENC());
653
636
  if (!encTable) {
@@ -684,7 +667,9 @@ export function decodePublicationRecordCollection(bytes) {
684
667
  });
685
668
  }
686
669
  return {
687
- version: normalizeStringField(collection.version) ?? DEFAULT_RECORD_COLLECTION_VERSION,
670
+ version:
671
+ normalizeStringField(collectionTable.version()) ??
672
+ DEFAULT_RECORD_COLLECTION_VERSION,
688
673
  records,
689
674
  enc,
690
675
  pnm,