+18
-9
src/pds.js
+18
-9
src/pds.js
···
1
// === CID WRAPPER ===
2
// Explicit CID type for DAG-CBOR encoding (avoids fragile heuristic detection)
3
···
18
19
function encode(val) {
20
if (val === null) {
21
-
parts.push(0xf6) // null
22
} else if (val === true) {
23
-
parts.push(0xf5) // true
24
} else if (val === false) {
25
-
parts.push(0xf4) // false
26
} else if (typeof val === 'number') {
27
encodeInteger(val)
28
} else if (typeof val === 'string') {
···
82
83
function encode(val) {
84
if (val === null) {
85
-
parts.push(0xf6) // null
86
} else if (val === true) {
87
-
parts.push(0xf5) // true
88
} else if (val === false) {
89
-
parts.push(0xf4) // false
90
} else if (typeof val === 'number') {
91
if (Number.isInteger(val) && val >= 0) {
92
encodeHead(0, val)
···
99
parts.push(...bytes)
100
} else if (val instanceof CID) {
101
// CID - encode with CBOR tag 42 + 0x00 prefix
102
-
parts.push(0xd8, 42) // tag(42)
103
encodeHead(2, val.bytes.length + 1) // +1 for 0x00 prefix
104
parts.push(0x00) // multibase identity prefix
105
parts.push(...val.bytes)
···
569
570
function encode(val) {
571
if (val === null || val === undefined) {
572
-
parts.push(0xf6) // null
573
} else if (typeof val === 'number') {
574
encodeHead(0, val) // unsigned int
575
} else if (val instanceof CID) {
576
// CID - encode with CBOR tag 42 + 0x00 prefix (DAG-CBOR CID link)
577
-
parts.push(0xd8, 42) // tag 42
578
encodeHead(2, val.bytes.length + 1) // +1 for 0x00 prefix
579
parts.push(0x00) // multibase identity prefix
580
parts.push(...val.bytes)
···
1
+
// === CONSTANTS ===
2
+
// CBOR primitive markers (RFC 8949)
3
+
const CBOR_FALSE = 0xf4
4
+
const CBOR_TRUE = 0xf5
5
+
const CBOR_NULL = 0xf6
6
+
7
+
// DAG-CBOR CID link tag
8
+
const CBOR_TAG_CID = 42
9
+
10
// === CID WRAPPER ===
11
// Explicit CID type for DAG-CBOR encoding (avoids fragile heuristic detection)
12
···
27
28
function encode(val) {
29
if (val === null) {
30
+
parts.push(CBOR_NULL)
31
} else if (val === true) {
32
+
parts.push(CBOR_TRUE)
33
} else if (val === false) {
34
+
parts.push(CBOR_FALSE)
35
} else if (typeof val === 'number') {
36
encodeInteger(val)
37
} else if (typeof val === 'string') {
···
91
92
function encode(val) {
93
if (val === null) {
94
+
parts.push(CBOR_NULL)
95
} else if (val === true) {
96
+
parts.push(CBOR_TRUE)
97
} else if (val === false) {
98
+
parts.push(CBOR_FALSE)
99
} else if (typeof val === 'number') {
100
if (Number.isInteger(val) && val >= 0) {
101
encodeHead(0, val)
···
108
parts.push(...bytes)
109
} else if (val instanceof CID) {
110
// CID - encode with CBOR tag 42 + 0x00 prefix
111
+
parts.push(0xd8, CBOR_TAG_CID)
112
encodeHead(2, val.bytes.length + 1) // +1 for 0x00 prefix
113
parts.push(0x00) // multibase identity prefix
114
parts.push(...val.bytes)
···
578
579
function encode(val) {
580
if (val === null || val === undefined) {
581
+
parts.push(CBOR_NULL)
582
} else if (typeof val === 'number') {
583
encodeHead(0, val) // unsigned int
584
} else if (val instanceof CID) {
585
// CID - encode with CBOR tag 42 + 0x00 prefix (DAG-CBOR CID link)
586
+
parts.push(0xd8, CBOR_TAG_CID)
587
encodeHead(2, val.bytes.length + 1) // +1 for 0x00 prefix
588
parts.push(0x00) // multibase identity prefix
589
parts.push(...val.bytes)