@cardanowall/poe-standard 0.2.0 → 0.4.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.
@@ -1,7 +1,17 @@
1
1
  import { PoeRecord } from './schema.cjs';
2
2
  import 'zod';
3
3
 
4
+ /** Canonical CBOR bytes of the full record body — the bytes the chunk-array
5
+ * transport carries on chain (see `carriage.ts`). */
4
6
  declare function encodePoeRecord(record: PoeRecord): Uint8Array;
7
+ /**
8
+ * Canonical CBOR bytes of the record body **with `sigs` removed** — the body
9
+ * a record-level signature covers. Producers prepend the 25-byte UTF-8 domain
10
+ * prefix `cardano-poe-record-sig-v1` before invoking Ed25519 (the crypto-core
11
+ * helper `buildLabel309SigStructure` handles the prefix and the
12
+ * `Sig_structure` wrapping). Extension keys are part of the signed body and
13
+ * pass through verbatim.
14
+ */
5
15
  declare function encodeRecordBodyForSigning(record: PoeRecord): Uint8Array;
6
16
 
7
17
  export { encodePoeRecord, encodeRecordBodyForSigning };
package/dist/encoder.d.ts CHANGED
@@ -1,7 +1,17 @@
1
1
  import { PoeRecord } from './schema.js';
2
2
  import 'zod';
3
3
 
4
+ /** Canonical CBOR bytes of the full record body — the bytes the chunk-array
5
+ * transport carries on chain (see `carriage.ts`). */
4
6
  declare function encodePoeRecord(record: PoeRecord): Uint8Array;
7
+ /**
8
+ * Canonical CBOR bytes of the record body **with `sigs` removed** — the body
9
+ * a record-level signature covers. Producers prepend the 25-byte UTF-8 domain
10
+ * prefix `cardano-poe-record-sig-v1` before invoking Ed25519 (the crypto-core
11
+ * helper `buildLabel309SigStructure` handles the prefix and the
12
+ * `Sig_structure` wrapping). Extension keys are part of the signed body and
13
+ * pass through verbatim.
14
+ */
5
15
  declare function encodeRecordBodyForSigning(record: PoeRecord): Uint8Array;
6
16
 
7
17
  export { encodePoeRecord, encodeRecordBodyForSigning };
package/dist/encoder.js CHANGED
@@ -1592,95 +1592,47 @@ function encodeCanonicalCbor(value) {
1592
1592
 
1593
1593
  // src/encoder.ts
1594
1594
  function encodePoeRecord(record) {
1595
- return encodeCanonicalCbor(recordToCbor(record));
1596
- }
1597
- function encodeRecordBodyForSigning(record) {
1598
- const body = recordToCborInternal(
1595
+ return encodeCanonicalCbor(toCborValue(
1599
1596
  record,
1600
1597
  /* includeSigs */
1601
- false
1602
- );
1603
- return encodeCanonicalCbor(body);
1598
+ true
1599
+ ));
1604
1600
  }
1605
- function recordToCbor(record) {
1606
- return recordToCborInternal(
1601
+ function encodeRecordBodyForSigning(record) {
1602
+ return encodeCanonicalCbor(toCborValue(
1607
1603
  record,
1608
1604
  /* includeSigs */
1609
- true
1610
- );
1611
- }
1612
- function recordToCborInternal(record, includeSigs) {
1613
- const out = { v: record.v };
1614
- if (record.items !== void 0) out["items"] = record.items.map(itemToCbor);
1615
- if (record.merkle !== void 0) out["merkle"] = record.merkle.map(merkleToCbor);
1616
- if (record.supersedes !== void 0) out["supersedes"] = record.supersedes;
1617
- if (includeSigs && record.sigs !== void 0) out["sigs"] = record.sigs.map(sigEntryToCbor);
1618
- if (record.crit !== void 0) out["crit"] = record.crit.slice();
1619
- for (const [k4, v3] of Object.entries(record)) {
1620
- if (k4 === "v" || k4 === "items" || k4 === "merkle" || k4 === "supersedes" || k4 === "sigs" || k4 === "crit") {
1621
- continue;
1622
- }
1623
- out[k4] = v3;
1624
- }
1625
- return out;
1626
- }
1627
- function itemToCbor(item) {
1628
- const out = { hashes: hashesToCbor(item.hashes) };
1629
- if (item.uris !== void 0) {
1630
- out["uris"] = item.uris.map((chunks) => chunks.slice());
1631
- }
1632
- if (item.enc !== void 0) {
1633
- out["enc"] = envelopeToCbor(item.enc);
1634
- }
1635
- return out;
1605
+ false
1606
+ ));
1636
1607
  }
1637
- function hashesToCbor(hashes) {
1608
+ function toCborValue(record, includeSigs) {
1638
1609
  const out = {};
1639
- for (const [alg, digest] of Object.entries(hashes)) {
1640
- out[alg] = digest;
1610
+ for (const [key, value] of Object.entries(record)) {
1611
+ if (value === void 0) continue;
1612
+ if (!includeSigs && key === "sigs") continue;
1613
+ out[key] = stripUndefined(value);
1641
1614
  }
1642
1615
  return out;
1643
1616
  }
1644
- function merkleToCbor(commit) {
1645
- const out = {
1646
- alg: commit.alg,
1647
- root: commit.root,
1648
- leaf_count: commit.leaf_count
1649
- };
1650
- if (commit.uris !== void 0) {
1651
- out["uris"] = commit.uris.map((chunks) => chunks.slice());
1617
+ function stripUndefined(value) {
1618
+ if (value === null || typeof value !== "object" || value instanceof Uint8Array) {
1619
+ return value;
1652
1620
  }
1653
- return out;
1654
- }
1655
- function envelopeToCbor(enc) {
1656
- const out = {
1657
- scheme: enc.scheme,
1658
- aead: enc.aead,
1659
- nonce: enc.nonce
1660
- };
1661
- if (enc.kem !== void 0) out["kem"] = enc.kem;
1662
- if (enc.slots !== void 0) out["slots"] = enc.slots.map(slotToCbor);
1663
- if (enc.slots_mac !== void 0) out["slots_mac"] = enc.slots_mac;
1664
- if (enc.passphrase !== void 0) out["passphrase"] = passphraseToCbor(enc.passphrase);
1665
- return out;
1666
- }
1667
- function slotToCbor(slot) {
1668
- if (slot.kem_ct !== void 0) {
1669
- return { kem_ct: slot.kem_ct.map((c4) => c4), wrap: slot.wrap };
1621
+ if (Array.isArray(value)) {
1622
+ return value.map((element) => stripUndefined(element));
1670
1623
  }
1671
- return { epk: slot.epk, wrap: slot.wrap };
1672
- }
1673
- function passphraseToCbor(pp) {
1674
- return {
1675
- alg: pp.alg,
1676
- salt: pp.salt,
1677
- params: pp.params
1678
- };
1679
- }
1680
- function sigEntryToCbor(entry) {
1681
- const out = { cose_sign1: entry.cose_sign1.map((b5) => b5) };
1682
- if (entry.cose_key !== void 0) {
1683
- out["cose_key"] = entry.cose_key.map((b5) => b5);
1624
+ if (value instanceof Map) {
1625
+ const out2 = /* @__PURE__ */ new Map();
1626
+ for (const [k4, v3] of value) {
1627
+ if (v3 === void 0) continue;
1628
+ out2.set(k4, stripUndefined(v3));
1629
+ }
1630
+ return out2;
1631
+ }
1632
+ const out = {};
1633
+ for (const [k4, v3] of Object.entries(value)) {
1634
+ if (v3 === void 0) continue;
1635
+ out[k4] = stripUndefined(v3);
1684
1636
  }
1685
1637
  return out;
1686
1638
  }