@bcts/dcbor 1.0.0-alpha.16 → 1.0.0-alpha.18
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 +1 -1
- package/dist/index.cjs +789 -474
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +160 -23
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +160 -23
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +789 -474
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +797 -490
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/bignum.ts +334 -0
- package/src/byte-string.ts +17 -17
- package/src/date.ts +11 -11
- package/src/index.ts +10 -0
- package/src/map.ts +23 -23
- package/src/prelude.ts +3 -0
- package/src/set.ts +9 -9
- package/src/tags-store.ts +17 -17
- package/src/tags.ts +46 -0
package/dist/index.iife.js
CHANGED
|
@@ -8,14 +8,14 @@ var bctsDcbor = (function(exports) {
|
|
|
8
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
10
|
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
11
|
-
var __copyProps = (to, from
|
|
12
|
-
if (from
|
|
13
|
-
for (var keys = __getOwnPropNames(from
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
14
|
key = keys[i];
|
|
15
15
|
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
16
|
__defProp(to, key, {
|
|
17
|
-
get: ((k) => from
|
|
18
|
-
enumerable: !(desc = __getOwnPropDesc(from
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -120,14 +120,14 @@ var bctsDcbor = (function(exports) {
|
|
|
120
120
|
};
|
|
121
121
|
GenericCollection.prototype.forEach = function(callback) {
|
|
122
122
|
var thisp = arguments[1];
|
|
123
|
-
return this.reduce(function(undefined
|
|
123
|
+
return this.reduce(function(undefined, value, key, object, depth) {
|
|
124
124
|
callback.call(thisp, value, key, object, depth);
|
|
125
125
|
}, void 0);
|
|
126
126
|
};
|
|
127
127
|
GenericCollection.prototype.map = function(callback) {
|
|
128
128
|
var thisp = arguments[1];
|
|
129
129
|
var result = [];
|
|
130
|
-
this.reduce(function(undefined
|
|
130
|
+
this.reduce(function(undefined, value, key, object, depth) {
|
|
131
131
|
result.push(callback.call(thisp, value, key, object, depth));
|
|
132
132
|
}, void 0);
|
|
133
133
|
return result;
|
|
@@ -135,7 +135,7 @@ var bctsDcbor = (function(exports) {
|
|
|
135
135
|
GenericCollection.prototype.enumerate = function(start) {
|
|
136
136
|
if (start == null) start = 0;
|
|
137
137
|
var result = [];
|
|
138
|
-
this.reduce(function(undefined
|
|
138
|
+
this.reduce(function(undefined, value) {
|
|
139
139
|
result.push([start++, value]);
|
|
140
140
|
}, void 0);
|
|
141
141
|
return result;
|
|
@@ -162,7 +162,7 @@ var bctsDcbor = (function(exports) {
|
|
|
162
162
|
};
|
|
163
163
|
GenericCollection.prototype.toObject = function() {
|
|
164
164
|
var object = {};
|
|
165
|
-
this.reduce(function(undefined
|
|
165
|
+
this.reduce(function(undefined, value, key) {
|
|
166
166
|
object[key] = value;
|
|
167
167
|
}, void 0);
|
|
168
168
|
return object;
|
|
@@ -173,7 +173,7 @@ var bctsDcbor = (function(exports) {
|
|
|
173
173
|
GenericCollection.prototype.filter = function(callback) {
|
|
174
174
|
var thisp = arguments[1];
|
|
175
175
|
var result = this.constructClone();
|
|
176
|
-
this.reduce(function(undefined
|
|
176
|
+
this.reduce(function(undefined, value, key, object, depth) {
|
|
177
177
|
if (callback.call(thisp, value, key, object, depth)) result.add(value, key);
|
|
178
178
|
}, void 0);
|
|
179
179
|
return result;
|
|
@@ -225,7 +225,7 @@ var bctsDcbor = (function(exports) {
|
|
|
225
225
|
GenericCollection.prototype.average = function(zero) {
|
|
226
226
|
var sum = zero === void 0 ? 0 : zero;
|
|
227
227
|
var count = zero === void 0 ? 0 : zero;
|
|
228
|
-
this.reduce(function(undefined
|
|
228
|
+
this.reduce(function(undefined, value) {
|
|
229
229
|
sum += value;
|
|
230
230
|
count += 1;
|
|
231
231
|
}, void 0);
|
|
@@ -906,8 +906,8 @@ var bctsDcbor = (function(exports) {
|
|
|
906
906
|
};
|
|
907
907
|
Object.addEach = function(target, source, overrides) {
|
|
908
908
|
var overridesExistingProperty = arguments.length === 3 ? overrides : true;
|
|
909
|
-
if (!source) {} else if (typeof source.forEach === "function" && !source.hasOwnProperty("forEach")) if (source.isMap === true) source.forEach(function(value, key
|
|
910
|
-
target[key
|
|
909
|
+
if (!source) {} else if (typeof source.forEach === "function" && !source.hasOwnProperty("forEach")) if (source.isMap === true) source.forEach(function(value, key) {
|
|
910
|
+
target[key] = value;
|
|
911
911
|
});
|
|
912
912
|
else source.forEach(function(pair) {
|
|
913
913
|
target[pair[0]] = pair[1];
|
|
@@ -918,8 +918,8 @@ var bctsDcbor = (function(exports) {
|
|
|
918
918
|
};
|
|
919
919
|
Object.defineEach = function(target, source, overrides, configurable, enumerable, writable) {
|
|
920
920
|
var overridesExistingProperty = arguments.length === 3 ? overrides : true;
|
|
921
|
-
if (!source) {} else if (typeof source.forEach === "function" && !source.hasOwnProperty("forEach")) if (source.isMap === true) source.forEach(function(value, key
|
|
922
|
-
Object.defineProperty(target, key
|
|
921
|
+
if (!source) {} else if (typeof source.forEach === "function" && !source.hasOwnProperty("forEach")) if (source.isMap === true) source.forEach(function(value, key) {
|
|
922
|
+
Object.defineProperty(target, key, {
|
|
923
923
|
value,
|
|
924
924
|
writable,
|
|
925
925
|
configurable,
|
|
@@ -1194,10 +1194,10 @@ var bctsDcbor = (function(exports) {
|
|
|
1194
1194
|
if (this === that) return 0;
|
|
1195
1195
|
if (!that) return 1;
|
|
1196
1196
|
var length = Math.min(this.length, that.length);
|
|
1197
|
-
var comparison = this.zip(that).reduce(function(comparison
|
|
1198
|
-
if (comparison
|
|
1197
|
+
var comparison = this.zip(that).reduce(function(comparison, pair, index) {
|
|
1198
|
+
if (comparison === 0) if (index >= length) return comparison;
|
|
1199
1199
|
else return compare(pair[0], pair[1]);
|
|
1200
|
-
else return comparison
|
|
1200
|
+
else return comparison;
|
|
1201
1201
|
}, 0);
|
|
1202
1202
|
if (comparison === 0) return this.length - that.length;
|
|
1203
1203
|
return comparison;
|
|
@@ -1547,7 +1547,7 @@ var bctsDcbor = (function(exports) {
|
|
|
1547
1547
|
};
|
|
1548
1548
|
GenericSet.prototype.forEach = function(callback) {
|
|
1549
1549
|
var thisp = arguments[1];
|
|
1550
|
-
return this.reduce(function(undefined
|
|
1550
|
+
return this.reduce(function(undefined, value, key, object, depth) {
|
|
1551
1551
|
callback.call(thisp, value, value, object, depth);
|
|
1552
1552
|
}, void 0);
|
|
1553
1553
|
};
|
|
@@ -1608,19 +1608,19 @@ var bctsDcbor = (function(exports) {
|
|
|
1608
1608
|
List.prototype.find = function(value, equals, index) {
|
|
1609
1609
|
equals = equals || this.contentEquals;
|
|
1610
1610
|
var head = this.head;
|
|
1611
|
-
var at
|
|
1612
|
-
while (at
|
|
1613
|
-
if (equals(at
|
|
1614
|
-
at
|
|
1611
|
+
var at = this.scan(index, head.next);
|
|
1612
|
+
while (at !== head) {
|
|
1613
|
+
if (equals(at.value, value)) return at;
|
|
1614
|
+
at = at.next;
|
|
1615
1615
|
}
|
|
1616
1616
|
};
|
|
1617
1617
|
List.prototype.findLast = function(value, equals, index) {
|
|
1618
1618
|
equals = equals || this.contentEquals;
|
|
1619
1619
|
var head = this.head;
|
|
1620
|
-
var at
|
|
1621
|
-
while (at
|
|
1622
|
-
if (equals(at
|
|
1623
|
-
at
|
|
1620
|
+
var at = this.scan(index, head.prev);
|
|
1621
|
+
while (at !== head) {
|
|
1622
|
+
if (equals(at.value, value)) return at;
|
|
1623
|
+
at = at.prev;
|
|
1624
1624
|
}
|
|
1625
1625
|
};
|
|
1626
1626
|
List.prototype.has = function(value, equals) {
|
|
@@ -1643,14 +1643,14 @@ var bctsDcbor = (function(exports) {
|
|
|
1643
1643
|
List.prototype.deleteAll = function(value, equals) {
|
|
1644
1644
|
equals = equals || this.contentEquals;
|
|
1645
1645
|
var head = this.head;
|
|
1646
|
-
var at
|
|
1646
|
+
var at = head.next;
|
|
1647
1647
|
var count = 0;
|
|
1648
|
-
while (at
|
|
1649
|
-
if (equals(value, at
|
|
1650
|
-
at
|
|
1648
|
+
while (at !== head) {
|
|
1649
|
+
if (equals(value, at.value)) {
|
|
1650
|
+
at["delete"]();
|
|
1651
1651
|
count++;
|
|
1652
1652
|
}
|
|
1653
|
-
at
|
|
1653
|
+
at = at.next;
|
|
1654
1654
|
}
|
|
1655
1655
|
this.length -= count;
|
|
1656
1656
|
return count;
|
|
@@ -1678,12 +1678,12 @@ var bctsDcbor = (function(exports) {
|
|
|
1678
1678
|
this.length += arguments.length;
|
|
1679
1679
|
};
|
|
1680
1680
|
List.prototype.unshift = function() {
|
|
1681
|
-
var at
|
|
1681
|
+
var at = this.head;
|
|
1682
1682
|
for (var i = 0; i < arguments.length; i++) {
|
|
1683
1683
|
var value = arguments[i];
|
|
1684
1684
|
var node = new this.Node(value);
|
|
1685
|
-
at
|
|
1686
|
-
at
|
|
1685
|
+
at.addAfter(node);
|
|
1686
|
+
at = node;
|
|
1687
1687
|
}
|
|
1688
1688
|
this.length += arguments.length;
|
|
1689
1689
|
};
|
|
@@ -1728,41 +1728,41 @@ var bctsDcbor = (function(exports) {
|
|
|
1728
1728
|
List.prototype.one = function() {
|
|
1729
1729
|
return this.peek();
|
|
1730
1730
|
};
|
|
1731
|
-
List.prototype.scan = function(at
|
|
1731
|
+
List.prototype.scan = function(at, fallback) {
|
|
1732
1732
|
var head = this.head;
|
|
1733
|
-
if (typeof at
|
|
1734
|
-
var count = at
|
|
1733
|
+
if (typeof at === "number") {
|
|
1734
|
+
var count = at;
|
|
1735
1735
|
if (count >= 0) {
|
|
1736
|
-
at
|
|
1736
|
+
at = head.next;
|
|
1737
1737
|
while (count) {
|
|
1738
1738
|
count--;
|
|
1739
|
-
at
|
|
1740
|
-
if (at
|
|
1739
|
+
at = at.next;
|
|
1740
|
+
if (at == head) break;
|
|
1741
1741
|
}
|
|
1742
1742
|
} else {
|
|
1743
|
-
at
|
|
1743
|
+
at = head;
|
|
1744
1744
|
while (count < 0) {
|
|
1745
1745
|
count++;
|
|
1746
|
-
at
|
|
1747
|
-
if (at
|
|
1746
|
+
at = at.prev;
|
|
1747
|
+
if (at == head) break;
|
|
1748
1748
|
}
|
|
1749
1749
|
}
|
|
1750
|
-
return at
|
|
1751
|
-
} else return at
|
|
1750
|
+
return at;
|
|
1751
|
+
} else return at || fallback;
|
|
1752
1752
|
};
|
|
1753
|
-
List.prototype.slice = function(at
|
|
1753
|
+
List.prototype.slice = function(at, end) {
|
|
1754
1754
|
var sliced = [];
|
|
1755
1755
|
var head = this.head;
|
|
1756
|
-
at
|
|
1756
|
+
at = this.scan(at, head.next);
|
|
1757
1757
|
end = this.scan(end, head);
|
|
1758
|
-
while (at
|
|
1759
|
-
sliced.push(at
|
|
1760
|
-
at
|
|
1758
|
+
while (at !== end && at !== head) {
|
|
1759
|
+
sliced.push(at.value);
|
|
1760
|
+
at = at.next;
|
|
1761
1761
|
}
|
|
1762
1762
|
return sliced;
|
|
1763
1763
|
};
|
|
1764
|
-
List.prototype.splice = function(at
|
|
1765
|
-
return this.swap(at
|
|
1764
|
+
List.prototype.splice = function(at, length) {
|
|
1765
|
+
return this.swap(at, length, Array.prototype.slice.call(arguments, 2));
|
|
1766
1766
|
};
|
|
1767
1767
|
List.prototype.swap = function(start, length, plus, _before, _after) {
|
|
1768
1768
|
var initial = start;
|
|
@@ -1770,31 +1770,31 @@ var bctsDcbor = (function(exports) {
|
|
|
1770
1770
|
if (length == null) length = Infinity;
|
|
1771
1771
|
plus = Array.from(plus);
|
|
1772
1772
|
var minus = [];
|
|
1773
|
-
var at
|
|
1774
|
-
while (length-- && length >= 0 && at
|
|
1775
|
-
minus.push(at
|
|
1776
|
-
at
|
|
1773
|
+
var at = start;
|
|
1774
|
+
while (length-- && length >= 0 && at !== this.head) {
|
|
1775
|
+
minus.push(at.value);
|
|
1776
|
+
at = at.next;
|
|
1777
1777
|
}
|
|
1778
1778
|
_before && _before.call(this, start, plus, minus);
|
|
1779
|
-
var at
|
|
1780
|
-
for (var i = 0, at
|
|
1781
|
-
if (initial == null && at
|
|
1779
|
+
var at = start;
|
|
1780
|
+
for (var i = 0, at = start; i < minus.length; i++, at = at.next) at["delete"]();
|
|
1781
|
+
if (initial == null && at === this.head) at = this.head.next;
|
|
1782
1782
|
for (var i = 0; i < plus.length; i++) {
|
|
1783
1783
|
var node = new this.Node(plus[i]);
|
|
1784
|
-
at
|
|
1784
|
+
at.addBefore(node);
|
|
1785
1785
|
}
|
|
1786
1786
|
this.length += plus.length - minus.length;
|
|
1787
1787
|
_after && _after.call(this, start, plus, minus);
|
|
1788
1788
|
return minus;
|
|
1789
1789
|
};
|
|
1790
1790
|
List.prototype.reverse = function() {
|
|
1791
|
-
var at
|
|
1791
|
+
var at = this.head;
|
|
1792
1792
|
do {
|
|
1793
|
-
var temp = at
|
|
1794
|
-
at
|
|
1795
|
-
at
|
|
1796
|
-
at
|
|
1797
|
-
} while (at
|
|
1793
|
+
var temp = at.next;
|
|
1794
|
+
at.next = at.prev;
|
|
1795
|
+
at.prev = temp;
|
|
1796
|
+
at = at.next;
|
|
1797
|
+
} while (at !== this.head);
|
|
1798
1798
|
return this;
|
|
1799
1799
|
};
|
|
1800
1800
|
List.prototype.sort = function() {
|
|
@@ -1803,20 +1803,20 @@ var bctsDcbor = (function(exports) {
|
|
|
1803
1803
|
List.prototype.reduce = function(callback, basis) {
|
|
1804
1804
|
var thisp = arguments[2];
|
|
1805
1805
|
var head = this.head;
|
|
1806
|
-
var at
|
|
1807
|
-
while (at
|
|
1808
|
-
basis = callback.call(thisp, basis, at
|
|
1809
|
-
at
|
|
1806
|
+
var at = head.next;
|
|
1807
|
+
while (at !== head) {
|
|
1808
|
+
basis = callback.call(thisp, basis, at.value, at, this);
|
|
1809
|
+
at = at.next;
|
|
1810
1810
|
}
|
|
1811
1811
|
return basis;
|
|
1812
1812
|
};
|
|
1813
1813
|
List.prototype.reduceRight = function(callback, basis) {
|
|
1814
1814
|
var thisp = arguments[2];
|
|
1815
1815
|
var head = this.head;
|
|
1816
|
-
var at
|
|
1817
|
-
while (at
|
|
1818
|
-
basis = callback.call(thisp, basis, at
|
|
1819
|
-
at
|
|
1816
|
+
var at = head.prev;
|
|
1817
|
+
while (at !== head) {
|
|
1818
|
+
basis = callback.call(thisp, basis, at.value, at, this);
|
|
1819
|
+
at = at.prev;
|
|
1820
1820
|
}
|
|
1821
1821
|
return basis;
|
|
1822
1822
|
};
|
|
@@ -2173,8 +2173,8 @@ var bctsDcbor = (function(exports) {
|
|
|
2173
2173
|
GenericMap.prototype["delete"] = function(key) {
|
|
2174
2174
|
var item = new this.Item(key);
|
|
2175
2175
|
if (this.store.has(item)) {
|
|
2176
|
-
var from
|
|
2177
|
-
if (this.dispatchesMapChanges) this.dispatchBeforeMapChange(key, from
|
|
2176
|
+
var from = this.store.get(item).value;
|
|
2177
|
+
if (this.dispatchesMapChanges) this.dispatchBeforeMapChange(key, from);
|
|
2178
2178
|
this.store["delete"](item);
|
|
2179
2179
|
this.length--;
|
|
2180
2180
|
if (this.dispatchesMapChanges) this.dispatchMapChange(key, void 0);
|
|
@@ -2185,8 +2185,8 @@ var bctsDcbor = (function(exports) {
|
|
|
2185
2185
|
GenericMap.prototype.clear = function() {
|
|
2186
2186
|
var keys, key;
|
|
2187
2187
|
if (this.dispatchesMapChanges) {
|
|
2188
|
-
this.forEach(function(value, key
|
|
2189
|
-
this.dispatchBeforeMapChange(key
|
|
2188
|
+
this.forEach(function(value, key) {
|
|
2189
|
+
this.dispatchBeforeMapChange(key, value);
|
|
2190
2190
|
}, this);
|
|
2191
2191
|
keys = this.keysArray();
|
|
2192
2192
|
}
|
|
@@ -2195,13 +2195,13 @@ var bctsDcbor = (function(exports) {
|
|
|
2195
2195
|
if (this.dispatchesMapChanges) for (var i = 0; key = keys[i]; i++) this.dispatchMapChange(key);
|
|
2196
2196
|
};
|
|
2197
2197
|
GenericMap.prototype.reduce = function(callback, basis, thisp) {
|
|
2198
|
-
return this.store.reduce(function(basis
|
|
2199
|
-
return callback.call(thisp, basis
|
|
2198
|
+
return this.store.reduce(function(basis, item) {
|
|
2199
|
+
return callback.call(thisp, basis, item.value, item.key, this);
|
|
2200
2200
|
}, basis, this);
|
|
2201
2201
|
};
|
|
2202
2202
|
GenericMap.prototype.reduceRight = function(callback, basis, thisp) {
|
|
2203
|
-
return this.store.reduceRight(function(basis
|
|
2204
|
-
return callback.call(thisp, basis
|
|
2203
|
+
return this.store.reduceRight(function(basis, item) {
|
|
2204
|
+
return callback.call(thisp, basis, item.value, item.key, this);
|
|
2205
2205
|
}, basis, this);
|
|
2206
2206
|
};
|
|
2207
2207
|
GenericMap.prototype.keysArray = function() {
|
|
@@ -2367,8 +2367,8 @@ var bctsDcbor = (function(exports) {
|
|
|
2367
2367
|
Dict.prototype.reduceRight = function(callback, basis, thisp) {
|
|
2368
2368
|
var self = this;
|
|
2369
2369
|
var store = this.store;
|
|
2370
|
-
basis = Object.keys(this.store).reduceRight(function(basis
|
|
2371
|
-
return callback.call(thisp, basis
|
|
2370
|
+
basis = Object.keys(this.store).reduceRight(function(basis, key) {
|
|
2371
|
+
return callback.call(thisp, basis, store[key], key, self);
|
|
2372
2372
|
}, basis);
|
|
2373
2373
|
if (this._hasProto) return callback.call(thisp, basis, this._protoValue, "__proto__", self);
|
|
2374
2374
|
return basis;
|
|
@@ -2498,10 +2498,10 @@ var bctsDcbor = (function(exports) {
|
|
|
2498
2498
|
var thisp = arguments[2];
|
|
2499
2499
|
var buckets = this.buckets;
|
|
2500
2500
|
var index = 0;
|
|
2501
|
-
return buckets.reduce(function(basis
|
|
2502
|
-
return bucket.reduce(function(basis
|
|
2503
|
-
return callback.call(thisp, basis
|
|
2504
|
-
}, basis
|
|
2501
|
+
return buckets.reduce(function(basis, bucket) {
|
|
2502
|
+
return bucket.reduce(function(basis, value) {
|
|
2503
|
+
return callback.call(thisp, basis, value, index++, this);
|
|
2504
|
+
}, basis, this);
|
|
2505
2505
|
}, basis, this);
|
|
2506
2506
|
};
|
|
2507
2507
|
FastSet.prototype.one = function() {
|
|
@@ -2533,17 +2533,17 @@ var bctsDcbor = (function(exports) {
|
|
|
2533
2533
|
bucket = buckets.get(hash);
|
|
2534
2534
|
callback.call(thisp, branch + charmap.through + charmap.branchDown + " " + hash);
|
|
2535
2535
|
bucket.forEach(function(value, node) {
|
|
2536
|
-
var branch
|
|
2536
|
+
var branch, below, written;
|
|
2537
2537
|
if (node === bucket.head.prev) {
|
|
2538
|
-
branch
|
|
2538
|
+
branch = charmap.fromAbove;
|
|
2539
2539
|
below = " ";
|
|
2540
2540
|
} else {
|
|
2541
|
-
branch
|
|
2541
|
+
branch = charmap.fromBoth;
|
|
2542
2542
|
below = charmap.strafe;
|
|
2543
2543
|
}
|
|
2544
2544
|
logNode(node, function(line) {
|
|
2545
2545
|
if (!written) {
|
|
2546
|
-
callback.call(thisp, leader + " " + branch
|
|
2546
|
+
callback.call(thisp, leader + " " + branch + charmap.through + charmap.through + line);
|
|
2547
2547
|
written = true;
|
|
2548
2548
|
} else callback.call(thisp, leader + " " + below + " " + line);
|
|
2549
2549
|
}, function(line) {
|
|
@@ -2729,16 +2729,16 @@ var bctsDcbor = (function(exports) {
|
|
|
2729
2729
|
var thisp = arguments[2];
|
|
2730
2730
|
var list = this.order;
|
|
2731
2731
|
var index = 0;
|
|
2732
|
-
return list.reduce(function(basis
|
|
2733
|
-
return callback.call(thisp, basis
|
|
2732
|
+
return list.reduce(function(basis, value) {
|
|
2733
|
+
return callback.call(thisp, basis, value, index++, this);
|
|
2734
2734
|
}, basis, this);
|
|
2735
2735
|
};
|
|
2736
2736
|
CollectionsSet.prototype.reduceRight = function(callback, basis) {
|
|
2737
2737
|
var thisp = arguments[2];
|
|
2738
2738
|
var list = this.order;
|
|
2739
2739
|
var index = this.length - 1;
|
|
2740
|
-
return list.reduceRight(function(basis
|
|
2741
|
-
return callback.call(thisp, basis
|
|
2740
|
+
return list.reduceRight(function(basis, value) {
|
|
2741
|
+
return callback.call(thisp, basis, value, index--, this);
|
|
2742
2742
|
}, basis, this);
|
|
2743
2743
|
};
|
|
2744
2744
|
CollectionsSet.prototype.iterate = function() {
|
|
@@ -2923,8 +2923,8 @@ var bctsDcbor = (function(exports) {
|
|
|
2923
2923
|
}
|
|
2924
2924
|
var Set = require__set().CollectionsSet;
|
|
2925
2925
|
var GenericMap = require_generic_map();
|
|
2926
|
-
CollectionsMap = Map = function Map
|
|
2927
|
-
if (!(this instanceof Map
|
|
2926
|
+
CollectionsMap = Map = function Map(values, equals, hash, getDefault) {
|
|
2927
|
+
if (!(this instanceof Map)) return new Map(values, equals, hash, getDefault);
|
|
2928
2928
|
equals = equals || Object.equals;
|
|
2929
2929
|
hash = hash || Object.hash;
|
|
2930
2930
|
getDefault = getDefault || Function.noop;
|
|
@@ -3235,15 +3235,15 @@ var bctsDcbor = (function(exports) {
|
|
|
3235
3235
|
return dispatchingGetter.overriddenDescriptor.value;
|
|
3236
3236
|
};
|
|
3237
3237
|
propertyListener.set = function dispatchingSetter(value) {
|
|
3238
|
-
var descriptor, isActive, overriddenDescriptor
|
|
3239
|
-
if (value !== overriddenDescriptor
|
|
3238
|
+
var descriptor, isActive, overriddenDescriptor = dispatchingSetter.overriddenDescriptor;
|
|
3239
|
+
if (value !== overriddenDescriptor.value) {
|
|
3240
3240
|
if (!(isActive = (descriptor = dispatchingSetter.descriptor).isActive)) {
|
|
3241
3241
|
descriptor.isActive = true;
|
|
3242
3242
|
try {
|
|
3243
|
-
dispatchingSetter.dispatchEach(descriptor._willChangeListeners, dispatchingSetter.key, overriddenDescriptor
|
|
3243
|
+
dispatchingSetter.dispatchEach(descriptor._willChangeListeners, dispatchingSetter.key, overriddenDescriptor.value, this);
|
|
3244
3244
|
} finally {}
|
|
3245
3245
|
}
|
|
3246
|
-
overriddenDescriptor
|
|
3246
|
+
overriddenDescriptor.value = value;
|
|
3247
3247
|
if (!isActive) try {
|
|
3248
3248
|
dispatchingSetter.dispatchEach(descriptor._changeListeners, dispatchingSetter.key, value, this);
|
|
3249
3249
|
} finally {
|
|
@@ -3590,18 +3590,18 @@ var bctsDcbor = (function(exports) {
|
|
|
3590
3590
|
if (this.contentEquals(value, this.root.value)) return this.root;
|
|
3591
3591
|
}
|
|
3592
3592
|
};
|
|
3593
|
-
SortedSet.prototype.findGreatest = function(at
|
|
3593
|
+
SortedSet.prototype.findGreatest = function(at) {
|
|
3594
3594
|
if (this.root) {
|
|
3595
|
-
at
|
|
3596
|
-
while (at
|
|
3597
|
-
return at
|
|
3595
|
+
at = at || this.root;
|
|
3596
|
+
while (at.right) at = at.right;
|
|
3597
|
+
return at;
|
|
3598
3598
|
}
|
|
3599
3599
|
};
|
|
3600
|
-
SortedSet.prototype.findLeast = function(at
|
|
3600
|
+
SortedSet.prototype.findLeast = function(at) {
|
|
3601
3601
|
if (this.root) {
|
|
3602
|
-
at
|
|
3603
|
-
while (at
|
|
3604
|
-
return at
|
|
3602
|
+
at = at || this.root;
|
|
3603
|
+
while (at.left) at = at.left;
|
|
3604
|
+
return at;
|
|
3605
3605
|
}
|
|
3606
3606
|
};
|
|
3607
3607
|
SortedSet.prototype.findGreatestLessThanOrEqual = function(value) {
|
|
@@ -3668,8 +3668,8 @@ var bctsDcbor = (function(exports) {
|
|
|
3668
3668
|
}
|
|
3669
3669
|
return sliced;
|
|
3670
3670
|
};
|
|
3671
|
-
SortedSet.prototype.splice = function(at
|
|
3672
|
-
return this.swap(at
|
|
3671
|
+
SortedSet.prototype.splice = function(at, length) {
|
|
3672
|
+
return this.swap(at, length, Array.prototype.slice.call(arguments, 2));
|
|
3673
3673
|
};
|
|
3674
3674
|
SortedSet.prototype.swap = function(start, length, plus) {
|
|
3675
3675
|
if (start === void 0 && length === void 0) return [];
|
|
@@ -3757,16 +3757,16 @@ var bctsDcbor = (function(exports) {
|
|
|
3757
3757
|
};
|
|
3758
3758
|
SortedSet.prototype.splayIndex = function(index) {
|
|
3759
3759
|
if (this.root) {
|
|
3760
|
-
var at
|
|
3760
|
+
var at = this.root;
|
|
3761
3761
|
var atIndex = this.root.index;
|
|
3762
|
-
while (atIndex !== index) if (atIndex > index && at
|
|
3763
|
-
at
|
|
3764
|
-
atIndex -= 1 + (at
|
|
3765
|
-
} else if (atIndex < index && at
|
|
3766
|
-
at
|
|
3767
|
-
atIndex += 1 + (at
|
|
3762
|
+
while (atIndex !== index) if (atIndex > index && at.left) {
|
|
3763
|
+
at = at.left;
|
|
3764
|
+
atIndex -= 1 + (at.right ? at.right.length : 0);
|
|
3765
|
+
} else if (atIndex < index && at.right) {
|
|
3766
|
+
at = at.right;
|
|
3767
|
+
atIndex += 1 + (at.left ? at.left.length : 0);
|
|
3768
3768
|
} else break;
|
|
3769
|
-
this.splay(at
|
|
3769
|
+
this.splay(at.value);
|
|
3770
3770
|
return this.root.index === index;
|
|
3771
3771
|
}
|
|
3772
3772
|
return false;
|
|
@@ -3779,12 +3779,12 @@ var bctsDcbor = (function(exports) {
|
|
|
3779
3779
|
if (this.root) basis = this.root.reduceRight(callback, basis, this.length - 1, thisp, this);
|
|
3780
3780
|
return basis;
|
|
3781
3781
|
};
|
|
3782
|
-
SortedSet.prototype.min = function(at
|
|
3783
|
-
var least = this.findLeast(at
|
|
3782
|
+
SortedSet.prototype.min = function(at) {
|
|
3783
|
+
var least = this.findLeast(at);
|
|
3784
3784
|
if (least) return least.value;
|
|
3785
3785
|
};
|
|
3786
|
-
SortedSet.prototype.max = function(at
|
|
3787
|
-
var greatest = this.findGreatest(at
|
|
3786
|
+
SortedSet.prototype.max = function(at) {
|
|
3787
|
+
var greatest = this.findGreatest(at);
|
|
3788
3788
|
if (greatest) return greatest.value;
|
|
3789
3789
|
};
|
|
3790
3790
|
SortedSet.prototype.one = function() {
|
|
@@ -4341,7 +4341,7 @@ var import_sorted_map = require_sorted_map();
|
|
|
4341
4341
|
if (!Object.defineProperty || !function() {
|
|
4342
4342
|
try {
|
|
4343
4343
|
return Object.defineProperty({}, "x", {}), !0;
|
|
4344
|
-
} catch (e
|
|
4344
|
+
} catch (e) {
|
|
4345
4345
|
return !1;
|
|
4346
4346
|
}
|
|
4347
4347
|
}()) {
|
|
@@ -4349,7 +4349,7 @@ var import_sorted_map = require_sorted_map();
|
|
|
4349
4349
|
Object.defineProperty = function(t, r, o) {
|
|
4350
4350
|
if (e) try {
|
|
4351
4351
|
return e(t, r, o);
|
|
4352
|
-
} catch (e
|
|
4352
|
+
} catch (e) {}
|
|
4353
4353
|
if (t !== Object(t)) throw TypeError("Object.defineProperty called on non-object");
|
|
4354
4354
|
return Object.prototype.__defineGetter__ && "get" in o && Object.prototype.__defineGetter__.call(t, r, o.get), Object.prototype.__defineSetter__ && "set" in o && Object.prototype.__defineSetter__.call(t, r, o.set), "value" in o && (t[r] = o.value), t;
|
|
4355
4355
|
};
|
|
@@ -4596,7 +4596,7 @@ var import_sorted_map = require_sorted_map();
|
|
|
4596
4596
|
|
|
4597
4597
|
//#endregion
|
|
4598
4598
|
//#region src/exact.ts
|
|
4599
|
-
var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
4599
|
+
var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data(), 1);
|
|
4600
4600
|
const hasFract = (n) => {
|
|
4601
4601
|
return n % 1 !== 0;
|
|
4602
4602
|
};
|
|
@@ -4930,8 +4930,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
4930
4930
|
const f = binary16ToNumber(numberToBinary16(n));
|
|
4931
4931
|
if (f === n) return f16CborData(f);
|
|
4932
4932
|
if (n < 0) {
|
|
4933
|
-
const u
|
|
4934
|
-
if (u
|
|
4933
|
+
const u = ExactU64.exactFromF32(-1 - n);
|
|
4934
|
+
if (u !== void 0) return encodeVarInt(typeof u === "bigint" ? Number(u) : u, MajorType.Negative);
|
|
4935
4935
|
}
|
|
4936
4936
|
const u = ExactU32.exactFromF32(n);
|
|
4937
4937
|
if (u !== void 0) return encodeVarInt(u, MajorType.Unsigned);
|
|
@@ -4948,8 +4948,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
4948
4948
|
const f16CborData = (value) => {
|
|
4949
4949
|
const n = value;
|
|
4950
4950
|
if (n < 0) {
|
|
4951
|
-
const u
|
|
4952
|
-
if (u
|
|
4951
|
+
const u = ExactU64.exactFromF64(-1 - n);
|
|
4952
|
+
if (u !== void 0) return encodeVarInt(typeof u === "bigint" ? Number(u) : u, MajorType.Negative);
|
|
4953
4953
|
}
|
|
4954
4954
|
const u = ExactU16.exactFromF64(n);
|
|
4955
4955
|
if (u !== void 0) return encodeVarInt(u, MajorType.Unsigned);
|
|
@@ -5103,9 +5103,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5103
5103
|
* Stores tags with their names and optional summarizer functions.
|
|
5104
5104
|
*/
|
|
5105
5105
|
var TagsStore = class {
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5106
|
+
_tagsByValue = /* @__PURE__ */ new Map();
|
|
5107
|
+
_tagsByName = /* @__PURE__ */ new Map();
|
|
5108
|
+
_summarizers = /* @__PURE__ */ new Map();
|
|
5109
5109
|
constructor() {}
|
|
5110
5110
|
/**
|
|
5111
5111
|
* Insert a tag into the registry.
|
|
@@ -5127,11 +5127,11 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5127
5127
|
insert(tag) {
|
|
5128
5128
|
const name = tag.name;
|
|
5129
5129
|
if (name === void 0 || name === "") throw new Error(`Tag ${tag.value} must have a non-empty name`);
|
|
5130
|
-
const key = this
|
|
5131
|
-
const existing = this
|
|
5130
|
+
const key = this._valueKey(tag.value);
|
|
5131
|
+
const existing = this._tagsByValue.get(key);
|
|
5132
5132
|
if (existing?.name !== void 0 && existing.name !== name) throw new Error(`Attempt to register tag: ${tag.value} '${existing.name}' with different name: '${name}'`);
|
|
5133
|
-
this
|
|
5134
|
-
this
|
|
5133
|
+
this._tagsByValue.set(key, tag);
|
|
5134
|
+
this._tagsByName.set(name, tag);
|
|
5135
5135
|
}
|
|
5136
5136
|
/**
|
|
5137
5137
|
* Insert multiple tags into the registry.
|
|
@@ -5165,31 +5165,31 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5165
5165
|
* });
|
|
5166
5166
|
* ```
|
|
5167
5167
|
*/
|
|
5168
|
-
setSummarizer(tagValue
|
|
5169
|
-
const key = this
|
|
5170
|
-
this
|
|
5168
|
+
setSummarizer(tagValue, summarizer) {
|
|
5169
|
+
const key = this._valueKey(tagValue);
|
|
5170
|
+
this._summarizers.set(key, summarizer);
|
|
5171
5171
|
}
|
|
5172
5172
|
assignedNameForTag(tag) {
|
|
5173
|
-
const key = this
|
|
5174
|
-
return this
|
|
5173
|
+
const key = this._valueKey(tag.value);
|
|
5174
|
+
return this._tagsByValue.get(key)?.name;
|
|
5175
5175
|
}
|
|
5176
5176
|
nameForTag(tag) {
|
|
5177
5177
|
return this.assignedNameForTag(tag) ?? tag.value.toString();
|
|
5178
5178
|
}
|
|
5179
5179
|
tagForValue(value) {
|
|
5180
|
-
const key = this
|
|
5181
|
-
return this
|
|
5180
|
+
const key = this._valueKey(value);
|
|
5181
|
+
return this._tagsByValue.get(key);
|
|
5182
5182
|
}
|
|
5183
5183
|
tagForName(name) {
|
|
5184
|
-
return this
|
|
5184
|
+
return this._tagsByName.get(name);
|
|
5185
5185
|
}
|
|
5186
5186
|
nameForValue(value) {
|
|
5187
5187
|
const tag = this.tagForValue(value);
|
|
5188
5188
|
return tag !== void 0 ? this.nameForTag(tag) : value.toString();
|
|
5189
5189
|
}
|
|
5190
5190
|
summarizer(tag) {
|
|
5191
|
-
const key = this
|
|
5192
|
-
return this
|
|
5191
|
+
const key = this._valueKey(tag);
|
|
5192
|
+
return this._summarizers.get(key);
|
|
5193
5193
|
}
|
|
5194
5194
|
/**
|
|
5195
5195
|
* Create a string key for a numeric tag value.
|
|
@@ -5197,7 +5197,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5197
5197
|
*
|
|
5198
5198
|
* @private
|
|
5199
5199
|
*/
|
|
5200
|
-
|
|
5200
|
+
_valueKey(value) {
|
|
5201
5201
|
return value.toString();
|
|
5202
5202
|
}
|
|
5203
5203
|
};
|
|
@@ -5244,9 +5244,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5244
5244
|
* Convert hex string to bytes.
|
|
5245
5245
|
*/
|
|
5246
5246
|
const hexToBytes = (hexString) => {
|
|
5247
|
-
const hex
|
|
5248
|
-
const bytes = new Uint8Array(hex
|
|
5249
|
-
for (let i = 0; i < hex
|
|
5247
|
+
const hex = hexString.replace(/\s/g, "");
|
|
5248
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
5249
|
+
for (let i = 0; i < hex.length; i += 2) bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);
|
|
5250
5250
|
return bytes;
|
|
5251
5251
|
};
|
|
5252
5252
|
/**
|
|
@@ -5255,7 +5255,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5255
5255
|
* @param cbor - CBOR value to convert
|
|
5256
5256
|
* @returns Hex string
|
|
5257
5257
|
*/
|
|
5258
|
-
const hex = (cbor
|
|
5258
|
+
const hex = (cbor) => bytesToHex(cborData(cbor));
|
|
5259
5259
|
/**
|
|
5260
5260
|
* Returns the encoded hexadecimal representation of CBOR with options.
|
|
5261
5261
|
*
|
|
@@ -5267,9 +5267,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5267
5267
|
* @param opts - Formatting options
|
|
5268
5268
|
* @returns Hex string (possibly annotated)
|
|
5269
5269
|
*/
|
|
5270
|
-
const hexOpt = (cbor
|
|
5271
|
-
if (opts.annotate !== true) return hex(cbor
|
|
5272
|
-
const items = dumpItems(cbor
|
|
5270
|
+
const hexOpt = (cbor, opts = {}) => {
|
|
5271
|
+
if (opts.annotate !== true) return hex(cbor);
|
|
5272
|
+
const items = dumpItems(cbor, 0, opts);
|
|
5273
5273
|
const roundedNoteColumn = (items.reduce((largest, item) => {
|
|
5274
5274
|
return Math.max(largest, item.formatFirstColumn().length);
|
|
5275
5275
|
}, 0) + 4 & -4) - 1;
|
|
@@ -5302,35 +5302,35 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5302
5302
|
/**
|
|
5303
5303
|
* Generate dump items for a CBOR value (recursive).
|
|
5304
5304
|
*/
|
|
5305
|
-
function dumpItems(cbor
|
|
5305
|
+
function dumpItems(cbor, level, opts) {
|
|
5306
5306
|
const items = [];
|
|
5307
|
-
switch (cbor
|
|
5307
|
+
switch (cbor.type) {
|
|
5308
5308
|
case MajorType.Unsigned: {
|
|
5309
|
-
const data = cborData(cbor
|
|
5310
|
-
items.push(new DumpItem(level, [data], `unsigned(${cbor
|
|
5309
|
+
const data = cborData(cbor);
|
|
5310
|
+
items.push(new DumpItem(level, [data], `unsigned(${cbor.value})`));
|
|
5311
5311
|
break;
|
|
5312
5312
|
}
|
|
5313
5313
|
case MajorType.Negative: {
|
|
5314
|
-
const data = cborData(cbor
|
|
5315
|
-
const actualValue = typeof cbor
|
|
5314
|
+
const data = cborData(cbor);
|
|
5315
|
+
const actualValue = typeof cbor.value === "bigint" ? -1n - cbor.value : -1 - cbor.value;
|
|
5316
5316
|
items.push(new DumpItem(level, [data], `negative(${actualValue})`));
|
|
5317
5317
|
break;
|
|
5318
5318
|
}
|
|
5319
5319
|
case MajorType.ByteString: {
|
|
5320
|
-
const header = encodeVarInt(cbor
|
|
5321
|
-
items.push(new DumpItem(level, [header], `bytes(${cbor
|
|
5322
|
-
if (cbor
|
|
5320
|
+
const header = encodeVarInt(cbor.value.length, MajorType.ByteString);
|
|
5321
|
+
items.push(new DumpItem(level, [header], `bytes(${cbor.value.length})`));
|
|
5322
|
+
if (cbor.value.length > 0) {
|
|
5323
5323
|
let note = void 0;
|
|
5324
5324
|
try {
|
|
5325
|
-
const sanitizedText = sanitized(new TextDecoder("utf-8", { fatal: true }).decode(cbor
|
|
5325
|
+
const sanitizedText = sanitized(new TextDecoder("utf-8", { fatal: true }).decode(cbor.value));
|
|
5326
5326
|
if (sanitizedText !== void 0 && sanitizedText !== "") note = flanked(sanitizedText, "\"", "\"");
|
|
5327
5327
|
} catch {}
|
|
5328
|
-
items.push(new DumpItem(level + 1, [cbor
|
|
5328
|
+
items.push(new DumpItem(level + 1, [cbor.value], note));
|
|
5329
5329
|
}
|
|
5330
5330
|
break;
|
|
5331
5331
|
}
|
|
5332
5332
|
case MajorType.Text: {
|
|
5333
|
-
const utf8Data = new TextEncoder().encode(cbor
|
|
5333
|
+
const utf8Data = new TextEncoder().encode(cbor.value);
|
|
5334
5334
|
const header = encodeVarInt(utf8Data.length, MajorType.Text);
|
|
5335
5335
|
const firstByte = header[0];
|
|
5336
5336
|
if (firstByte === void 0) throw new CborError({
|
|
@@ -5339,61 +5339,61 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5339
5339
|
});
|
|
5340
5340
|
const headerData = [new Uint8Array([firstByte]), header.slice(1)];
|
|
5341
5341
|
items.push(new DumpItem(level, headerData, `text(${utf8Data.length})`));
|
|
5342
|
-
items.push(new DumpItem(level + 1, [utf8Data], flanked(cbor
|
|
5342
|
+
items.push(new DumpItem(level + 1, [utf8Data], flanked(cbor.value, "\"", "\"")));
|
|
5343
5343
|
break;
|
|
5344
5344
|
}
|
|
5345
5345
|
case MajorType.Array: {
|
|
5346
|
-
const header = encodeVarInt(cbor
|
|
5346
|
+
const header = encodeVarInt(cbor.value.length, MajorType.Array);
|
|
5347
5347
|
const firstByte = header[0];
|
|
5348
5348
|
if (firstByte === void 0) throw new CborError({
|
|
5349
5349
|
type: "Custom",
|
|
5350
5350
|
message: "Invalid varint encoding"
|
|
5351
5351
|
});
|
|
5352
5352
|
const headerData = [new Uint8Array([firstByte]), header.slice(1)];
|
|
5353
|
-
items.push(new DumpItem(level, headerData, `array(${cbor
|
|
5354
|
-
for (const item of cbor
|
|
5353
|
+
items.push(new DumpItem(level, headerData, `array(${cbor.value.length})`));
|
|
5354
|
+
for (const item of cbor.value) items.push(...dumpItems(item, level + 1, opts));
|
|
5355
5355
|
break;
|
|
5356
5356
|
}
|
|
5357
5357
|
case MajorType.Map: {
|
|
5358
|
-
const header = encodeVarInt(cbor
|
|
5358
|
+
const header = encodeVarInt(cbor.value.size, MajorType.Map);
|
|
5359
5359
|
const firstByte = header[0];
|
|
5360
5360
|
if (firstByte === void 0) throw new CborError({
|
|
5361
5361
|
type: "Custom",
|
|
5362
5362
|
message: "Invalid varint encoding"
|
|
5363
5363
|
});
|
|
5364
5364
|
const headerData = [new Uint8Array([firstByte]), header.slice(1)];
|
|
5365
|
-
items.push(new DumpItem(level, headerData, `map(${cbor
|
|
5366
|
-
for (const entry of cbor
|
|
5365
|
+
items.push(new DumpItem(level, headerData, `map(${cbor.value.size})`));
|
|
5366
|
+
for (const entry of cbor.value.entriesArray) {
|
|
5367
5367
|
items.push(...dumpItems(entry.key, level + 1, opts));
|
|
5368
5368
|
items.push(...dumpItems(entry.value, level + 1, opts));
|
|
5369
5369
|
}
|
|
5370
5370
|
break;
|
|
5371
5371
|
}
|
|
5372
5372
|
case MajorType.Tagged: {
|
|
5373
|
-
const tagValue
|
|
5374
|
-
if (tagValue
|
|
5373
|
+
const tagValue = cbor.tag;
|
|
5374
|
+
if (tagValue === void 0) throw new CborError({
|
|
5375
5375
|
type: "Custom",
|
|
5376
5376
|
message: "Tagged CBOR value must have a tag"
|
|
5377
5377
|
});
|
|
5378
|
-
const header = encodeVarInt(typeof tagValue
|
|
5378
|
+
const header = encodeVarInt(typeof tagValue === "bigint" ? Number(tagValue) : tagValue, MajorType.Tagged);
|
|
5379
5379
|
const firstByte = header[0];
|
|
5380
5380
|
if (firstByte === void 0) throw new CborError({
|
|
5381
5381
|
type: "Custom",
|
|
5382
5382
|
message: "Invalid varint encoding"
|
|
5383
5383
|
});
|
|
5384
5384
|
const headerData = [new Uint8Array([firstByte]), header.slice(1)];
|
|
5385
|
-
const noteComponents = [`tag(${tagValue
|
|
5386
|
-
const tag = createTag(typeof tagValue
|
|
5385
|
+
const noteComponents = [`tag(${tagValue})`];
|
|
5386
|
+
const tag = createTag(typeof tagValue === "bigint" ? Number(tagValue) : tagValue);
|
|
5387
5387
|
const tagName = opts.tagsStore?.assignedNameForTag(tag);
|
|
5388
5388
|
if (tagName !== void 0) noteComponents.push(tagName);
|
|
5389
5389
|
const tagNote = noteComponents.join(" ");
|
|
5390
5390
|
items.push(new DumpItem(level, headerData, tagNote));
|
|
5391
|
-
items.push(...dumpItems(cbor
|
|
5391
|
+
items.push(...dumpItems(cbor.value, level + 1, opts));
|
|
5392
5392
|
break;
|
|
5393
5393
|
}
|
|
5394
5394
|
case MajorType.Simple: {
|
|
5395
|
-
const data = cborData(cbor
|
|
5396
|
-
const simple = cbor
|
|
5395
|
+
const data = cborData(cbor);
|
|
5396
|
+
const simple = cbor.value;
|
|
5397
5397
|
let note;
|
|
5398
5398
|
if (simple.type === "True") note = "true";
|
|
5399
5399
|
else if (simple.type === "False") note = "false";
|
|
@@ -5449,8 +5449,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5449
5449
|
* // date(1234567890)
|
|
5450
5450
|
* ```
|
|
5451
5451
|
*/
|
|
5452
|
-
function diagnosticOpt(cbor
|
|
5453
|
-
return formatDiagnostic(cbor
|
|
5452
|
+
function diagnosticOpt(cbor, opts) {
|
|
5453
|
+
return formatDiagnostic(cbor, {
|
|
5454
5454
|
...DEFAULT_OPTS,
|
|
5455
5455
|
...opts
|
|
5456
5456
|
});
|
|
@@ -5469,8 +5469,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5469
5469
|
* // For nested structures: multi-line formatted output
|
|
5470
5470
|
* ```
|
|
5471
5471
|
*/
|
|
5472
|
-
function diagnostic(cbor
|
|
5473
|
-
return diagnosticOpt(cbor
|
|
5472
|
+
function diagnostic(cbor) {
|
|
5473
|
+
return diagnosticOpt(cbor);
|
|
5474
5474
|
}
|
|
5475
5475
|
/**
|
|
5476
5476
|
* Format CBOR value using custom summarizers for tagged values.
|
|
@@ -5489,8 +5489,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5489
5489
|
* // "custom-summary" (instead of full content)
|
|
5490
5490
|
* ```
|
|
5491
5491
|
*/
|
|
5492
|
-
function summary(cbor
|
|
5493
|
-
return diagnosticOpt(cbor
|
|
5492
|
+
function summary(cbor) {
|
|
5493
|
+
return diagnosticOpt(cbor, {
|
|
5494
5494
|
summarize: true,
|
|
5495
5495
|
flat: true
|
|
5496
5496
|
});
|
|
@@ -5500,16 +5500,16 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5500
5500
|
*
|
|
5501
5501
|
* @internal
|
|
5502
5502
|
*/
|
|
5503
|
-
function formatDiagnostic(cbor
|
|
5504
|
-
switch (cbor
|
|
5505
|
-
case MajorType.Unsigned: return formatUnsigned(cbor
|
|
5506
|
-
case MajorType.Negative: return formatNegative(cbor
|
|
5507
|
-
case MajorType.ByteString: return formatBytes(cbor
|
|
5508
|
-
case MajorType.Text: return formatText(cbor
|
|
5509
|
-
case MajorType.Array: return formatArray(cbor
|
|
5510
|
-
case MajorType.Map: return formatMap(cbor
|
|
5511
|
-
case MajorType.Tagged: return formatTagged(cbor
|
|
5512
|
-
case MajorType.Simple: return formatSimple(cbor
|
|
5503
|
+
function formatDiagnostic(cbor, opts) {
|
|
5504
|
+
switch (cbor.type) {
|
|
5505
|
+
case MajorType.Unsigned: return formatUnsigned(cbor.value);
|
|
5506
|
+
case MajorType.Negative: return formatNegative(cbor.value);
|
|
5507
|
+
case MajorType.ByteString: return formatBytes(cbor.value);
|
|
5508
|
+
case MajorType.Text: return formatText(cbor.value);
|
|
5509
|
+
case MajorType.Array: return formatArray(cbor.value, opts);
|
|
5510
|
+
case MajorType.Map: return formatMap(cbor.value, opts);
|
|
5511
|
+
case MajorType.Tagged: return formatTagged(cbor.tag, cbor.value, opts);
|
|
5512
|
+
case MajorType.Simple: return formatSimple(cbor.value);
|
|
5513
5513
|
}
|
|
5514
5514
|
}
|
|
5515
5515
|
/**
|
|
@@ -5590,9 +5590,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5590
5590
|
if (opts.summarize === true) {
|
|
5591
5591
|
const summarizer = resolveTagsStore(opts.tags)?.summarizer(tag);
|
|
5592
5592
|
if (summarizer !== void 0) {
|
|
5593
|
-
const result
|
|
5594
|
-
if (result
|
|
5595
|
-
else return `<error: ${result
|
|
5593
|
+
const result = summarizer(content, opts.flat ?? false);
|
|
5594
|
+
if (result.ok) return result.value;
|
|
5595
|
+
else return `<error: ${result.error.type === "Custom" ? result.error.message : result.error.type === "WrongTag" ? `expected CBOR tag ${result.error.expected.value}, but got ${result.error.actual.value}` : result.error.type}>`;
|
|
5596
5596
|
}
|
|
5597
5597
|
}
|
|
5598
5598
|
let comment;
|
|
@@ -5695,13 +5695,13 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5695
5695
|
//#endregion
|
|
5696
5696
|
//#region src/decode.ts
|
|
5697
5697
|
function decodeCbor(data) {
|
|
5698
|
-
const { cbor
|
|
5698
|
+
const { cbor, len } = decodeCborInternal(new DataView(data.buffer, data.byteOffset, data.byteLength));
|
|
5699
5699
|
const remaining = data.length - len;
|
|
5700
5700
|
if (remaining !== 0) throw new CborError({
|
|
5701
5701
|
type: "UnusedData",
|
|
5702
5702
|
count: remaining
|
|
5703
5703
|
});
|
|
5704
|
-
return cbor
|
|
5704
|
+
return cbor;
|
|
5705
5705
|
}
|
|
5706
5706
|
function parseHeader(header) {
|
|
5707
5707
|
return {
|
|
@@ -5776,26 +5776,26 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5776
5776
|
const { majorType, value, varIntLen } = parseHeaderVarint(data);
|
|
5777
5777
|
switch (majorType) {
|
|
5778
5778
|
case MajorType.Unsigned: {
|
|
5779
|
-
const cbor
|
|
5779
|
+
const cbor = attachMethods({
|
|
5780
5780
|
isCbor: true,
|
|
5781
5781
|
type: MajorType.Unsigned,
|
|
5782
5782
|
value
|
|
5783
5783
|
});
|
|
5784
|
-
checkCanonicalEncoding(cbor
|
|
5784
|
+
checkCanonicalEncoding(cbor, new Uint8Array(data.buffer, data.byteOffset, varIntLen));
|
|
5785
5785
|
return {
|
|
5786
|
-
cbor
|
|
5786
|
+
cbor,
|
|
5787
5787
|
len: varIntLen
|
|
5788
5788
|
};
|
|
5789
5789
|
}
|
|
5790
5790
|
case MajorType.Negative: {
|
|
5791
|
-
const cbor
|
|
5791
|
+
const cbor = attachMethods({
|
|
5792
5792
|
isCbor: true,
|
|
5793
5793
|
type: MajorType.Negative,
|
|
5794
5794
|
value
|
|
5795
5795
|
});
|
|
5796
|
-
checkCanonicalEncoding(cbor
|
|
5796
|
+
checkCanonicalEncoding(cbor, new Uint8Array(data.buffer, data.byteOffset, varIntLen));
|
|
5797
5797
|
return {
|
|
5798
|
-
cbor
|
|
5798
|
+
cbor,
|
|
5799
5799
|
len: varIntLen
|
|
5800
5800
|
};
|
|
5801
5801
|
}
|
|
@@ -5851,9 +5851,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5851
5851
|
for (let i = 0; i < value; i++) {
|
|
5852
5852
|
const { cbor: key, len: keyLen } = decodeCborInternal(from(data, pos));
|
|
5853
5853
|
pos += keyLen;
|
|
5854
|
-
const { cbor: value
|
|
5854
|
+
const { cbor: value, len: valueLen } = decodeCborInternal(from(data, pos));
|
|
5855
5855
|
pos += valueLen;
|
|
5856
|
-
map.setNext(key, value
|
|
5856
|
+
map.setNext(key, value);
|
|
5857
5857
|
}
|
|
5858
5858
|
return {
|
|
5859
5859
|
cbor: attachMethods({
|
|
@@ -5952,8 +5952,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5952
5952
|
}
|
|
5953
5953
|
}
|
|
5954
5954
|
}
|
|
5955
|
-
function checkCanonicalEncoding(cbor
|
|
5956
|
-
if (!areBytesEqual(buf, isCbor(cbor
|
|
5955
|
+
function checkCanonicalEncoding(cbor, buf) {
|
|
5956
|
+
if (!areBytesEqual(buf, isCbor(cbor) ? cborData(cbor) : encodeCbor(cbor))) throw new CborError({ type: "NonCanonicalNumeric" });
|
|
5957
5957
|
}
|
|
5958
5958
|
|
|
5959
5959
|
//#endregion
|
|
@@ -5970,10 +5970,10 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
5970
5970
|
* Extract native JavaScript value from CBOR.
|
|
5971
5971
|
* Converts CBOR types to their JavaScript equivalents.
|
|
5972
5972
|
*/
|
|
5973
|
-
const extractCbor = (cbor
|
|
5973
|
+
const extractCbor = (cbor) => {
|
|
5974
5974
|
let c;
|
|
5975
|
-
if (cbor
|
|
5976
|
-
else c = cbor
|
|
5975
|
+
if (cbor instanceof Uint8Array) c = decodeCbor(cbor);
|
|
5976
|
+
else c = cbor;
|
|
5977
5977
|
switch (c.type) {
|
|
5978
5978
|
case MajorType.Unsigned: return c.value;
|
|
5979
5979
|
case MajorType.Negative: if (typeof c.value === "bigint") return -c.value - 1n;
|
|
@@ -6004,8 +6004,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6004
6004
|
* }
|
|
6005
6005
|
* ```
|
|
6006
6006
|
*/
|
|
6007
|
-
const isUnsigned = (cbor
|
|
6008
|
-
return cbor
|
|
6007
|
+
const isUnsigned = (cbor) => {
|
|
6008
|
+
return cbor.type === MajorType.Unsigned;
|
|
6009
6009
|
};
|
|
6010
6010
|
/**
|
|
6011
6011
|
* Check if CBOR value is a negative integer.
|
|
@@ -6013,8 +6013,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6013
6013
|
* @param cbor - CBOR value to check
|
|
6014
6014
|
* @returns True if value is negative integer
|
|
6015
6015
|
*/
|
|
6016
|
-
const isNegative = (cbor
|
|
6017
|
-
return cbor
|
|
6016
|
+
const isNegative = (cbor) => {
|
|
6017
|
+
return cbor.type === MajorType.Negative;
|
|
6018
6018
|
};
|
|
6019
6019
|
/**
|
|
6020
6020
|
* Check if CBOR value is any integer (unsigned or negative).
|
|
@@ -6022,8 +6022,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6022
6022
|
* @param cbor - CBOR value to check
|
|
6023
6023
|
* @returns True if value is an integer
|
|
6024
6024
|
*/
|
|
6025
|
-
const isInteger = (cbor
|
|
6026
|
-
return cbor
|
|
6025
|
+
const isInteger = (cbor) => {
|
|
6026
|
+
return cbor.type === MajorType.Unsigned || cbor.type === MajorType.Negative;
|
|
6027
6027
|
};
|
|
6028
6028
|
/**
|
|
6029
6029
|
* Check if CBOR value is a byte string.
|
|
@@ -6031,8 +6031,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6031
6031
|
* @param cbor - CBOR value to check
|
|
6032
6032
|
* @returns True if value is byte string
|
|
6033
6033
|
*/
|
|
6034
|
-
const isBytes = (cbor
|
|
6035
|
-
return cbor
|
|
6034
|
+
const isBytes = (cbor) => {
|
|
6035
|
+
return cbor.type === MajorType.ByteString;
|
|
6036
6036
|
};
|
|
6037
6037
|
/**
|
|
6038
6038
|
* Check if CBOR value is a text string.
|
|
@@ -6040,8 +6040,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6040
6040
|
* @param cbor - CBOR value to check
|
|
6041
6041
|
* @returns True if value is text string
|
|
6042
6042
|
*/
|
|
6043
|
-
const isText = (cbor
|
|
6044
|
-
return cbor
|
|
6043
|
+
const isText = (cbor) => {
|
|
6044
|
+
return cbor.type === MajorType.Text;
|
|
6045
6045
|
};
|
|
6046
6046
|
/**
|
|
6047
6047
|
* Check if CBOR value is an array.
|
|
@@ -6049,8 +6049,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6049
6049
|
* @param cbor - CBOR value to check
|
|
6050
6050
|
* @returns True if value is array
|
|
6051
6051
|
*/
|
|
6052
|
-
const isArray = (cbor
|
|
6053
|
-
return cbor
|
|
6052
|
+
const isArray = (cbor) => {
|
|
6053
|
+
return cbor.type === MajorType.Array;
|
|
6054
6054
|
};
|
|
6055
6055
|
/**
|
|
6056
6056
|
* Check if CBOR value is a map.
|
|
@@ -6058,8 +6058,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6058
6058
|
* @param cbor - CBOR value to check
|
|
6059
6059
|
* @returns True if value is map
|
|
6060
6060
|
*/
|
|
6061
|
-
const isMap = (cbor
|
|
6062
|
-
return cbor
|
|
6061
|
+
const isMap = (cbor) => {
|
|
6062
|
+
return cbor.type === MajorType.Map;
|
|
6063
6063
|
};
|
|
6064
6064
|
/**
|
|
6065
6065
|
* Check if CBOR value is tagged.
|
|
@@ -6067,8 +6067,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6067
6067
|
* @param cbor - CBOR value to check
|
|
6068
6068
|
* @returns True if value is tagged
|
|
6069
6069
|
*/
|
|
6070
|
-
const isTagged = (cbor
|
|
6071
|
-
return cbor
|
|
6070
|
+
const isTagged = (cbor) => {
|
|
6071
|
+
return cbor.type === MajorType.Tagged;
|
|
6072
6072
|
};
|
|
6073
6073
|
/**
|
|
6074
6074
|
* Check if CBOR value is a simple value.
|
|
@@ -6076,8 +6076,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6076
6076
|
* @param cbor - CBOR value to check
|
|
6077
6077
|
* @returns True if value is simple
|
|
6078
6078
|
*/
|
|
6079
|
-
const isSimple = (cbor
|
|
6080
|
-
return cbor
|
|
6079
|
+
const isSimple = (cbor) => {
|
|
6080
|
+
return cbor.type === MajorType.Simple;
|
|
6081
6081
|
};
|
|
6082
6082
|
/**
|
|
6083
6083
|
* Check if CBOR value is a boolean (true or false).
|
|
@@ -6085,9 +6085,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6085
6085
|
* @param cbor - CBOR value to check
|
|
6086
6086
|
* @returns True if value is boolean
|
|
6087
6087
|
*/
|
|
6088
|
-
const isBoolean = (cbor
|
|
6089
|
-
if (cbor
|
|
6090
|
-
return cbor
|
|
6088
|
+
const isBoolean = (cbor) => {
|
|
6089
|
+
if (cbor.type !== MajorType.Simple) return false;
|
|
6090
|
+
return cbor.value.type === "False" || cbor.value.type === "True";
|
|
6091
6091
|
};
|
|
6092
6092
|
/**
|
|
6093
6093
|
* Check if CBOR value is null.
|
|
@@ -6095,9 +6095,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6095
6095
|
* @param cbor - CBOR value to check
|
|
6096
6096
|
* @returns True if value is null
|
|
6097
6097
|
*/
|
|
6098
|
-
const isNull = (cbor
|
|
6099
|
-
if (cbor
|
|
6100
|
-
return cbor
|
|
6098
|
+
const isNull = (cbor) => {
|
|
6099
|
+
if (cbor.type !== MajorType.Simple) return false;
|
|
6100
|
+
return cbor.value.type === "Null";
|
|
6101
6101
|
};
|
|
6102
6102
|
/**
|
|
6103
6103
|
* Check if CBOR value is a float (f16, f32, or f64).
|
|
@@ -6105,9 +6105,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6105
6105
|
* @param cbor - CBOR value to check
|
|
6106
6106
|
* @returns True if value is float
|
|
6107
6107
|
*/
|
|
6108
|
-
const isFloat = (cbor
|
|
6109
|
-
if (cbor
|
|
6110
|
-
return isFloat$1(cbor
|
|
6108
|
+
const isFloat = (cbor) => {
|
|
6109
|
+
if (cbor.type !== MajorType.Simple) return false;
|
|
6110
|
+
return isFloat$1(cbor.value);
|
|
6111
6111
|
};
|
|
6112
6112
|
/**
|
|
6113
6113
|
* Extract unsigned integer value if type matches.
|
|
@@ -6115,8 +6115,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6115
6115
|
* @param cbor - CBOR value
|
|
6116
6116
|
* @returns Unsigned integer or undefined
|
|
6117
6117
|
*/
|
|
6118
|
-
const asUnsigned = (cbor
|
|
6119
|
-
if (cbor
|
|
6118
|
+
const asUnsigned = (cbor) => {
|
|
6119
|
+
if (cbor.type === MajorType.Unsigned) return cbor.value;
|
|
6120
6120
|
};
|
|
6121
6121
|
/**
|
|
6122
6122
|
* Extract negative integer value if type matches.
|
|
@@ -6124,9 +6124,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6124
6124
|
* @param cbor - CBOR value
|
|
6125
6125
|
* @returns Negative integer or undefined
|
|
6126
6126
|
*/
|
|
6127
|
-
const asNegative = (cbor
|
|
6128
|
-
if (cbor
|
|
6129
|
-
else return -cbor
|
|
6127
|
+
const asNegative = (cbor) => {
|
|
6128
|
+
if (cbor.type === MajorType.Negative) if (typeof cbor.value === "bigint") return -cbor.value - 1n;
|
|
6129
|
+
else return -cbor.value - 1;
|
|
6130
6130
|
};
|
|
6131
6131
|
/**
|
|
6132
6132
|
* Extract any integer value (unsigned or negative) if type matches.
|
|
@@ -6134,10 +6134,10 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6134
6134
|
* @param cbor - CBOR value
|
|
6135
6135
|
* @returns Integer or undefined
|
|
6136
6136
|
*/
|
|
6137
|
-
const asInteger = (cbor
|
|
6138
|
-
if (cbor
|
|
6139
|
-
else if (cbor
|
|
6140
|
-
else return -cbor
|
|
6137
|
+
const asInteger = (cbor) => {
|
|
6138
|
+
if (cbor.type === MajorType.Unsigned) return cbor.value;
|
|
6139
|
+
else if (cbor.type === MajorType.Negative) if (typeof cbor.value === "bigint") return -cbor.value - 1n;
|
|
6140
|
+
else return -cbor.value - 1;
|
|
6141
6141
|
};
|
|
6142
6142
|
/**
|
|
6143
6143
|
* Extract byte string value if type matches.
|
|
@@ -6145,8 +6145,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6145
6145
|
* @param cbor - CBOR value
|
|
6146
6146
|
* @returns Byte string or undefined
|
|
6147
6147
|
*/
|
|
6148
|
-
const asBytes = (cbor
|
|
6149
|
-
if (cbor
|
|
6148
|
+
const asBytes = (cbor) => {
|
|
6149
|
+
if (cbor.type === MajorType.ByteString) return cbor.value;
|
|
6150
6150
|
};
|
|
6151
6151
|
/**
|
|
6152
6152
|
* Extract text string value if type matches.
|
|
@@ -6154,8 +6154,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6154
6154
|
* @param cbor - CBOR value
|
|
6155
6155
|
* @returns Text string or undefined
|
|
6156
6156
|
*/
|
|
6157
|
-
const asText = (cbor
|
|
6158
|
-
if (cbor
|
|
6157
|
+
const asText = (cbor) => {
|
|
6158
|
+
if (cbor.type === MajorType.Text) return cbor.value;
|
|
6159
6159
|
};
|
|
6160
6160
|
/**
|
|
6161
6161
|
* Extract array value if type matches.
|
|
@@ -6163,8 +6163,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6163
6163
|
* @param cbor - CBOR value
|
|
6164
6164
|
* @returns Array or undefined
|
|
6165
6165
|
*/
|
|
6166
|
-
const asArray = (cbor
|
|
6167
|
-
if (cbor
|
|
6166
|
+
const asArray = (cbor) => {
|
|
6167
|
+
if (cbor.type === MajorType.Array) return cbor.value;
|
|
6168
6168
|
};
|
|
6169
6169
|
/**
|
|
6170
6170
|
* Extract map value if type matches.
|
|
@@ -6172,8 +6172,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6172
6172
|
* @param cbor - CBOR value
|
|
6173
6173
|
* @returns Map or undefined
|
|
6174
6174
|
*/
|
|
6175
|
-
const asMap = (cbor
|
|
6176
|
-
if (cbor
|
|
6175
|
+
const asMap = (cbor) => {
|
|
6176
|
+
if (cbor.type === MajorType.Map) return cbor.value;
|
|
6177
6177
|
};
|
|
6178
6178
|
/**
|
|
6179
6179
|
* Extract boolean value if type matches.
|
|
@@ -6181,10 +6181,10 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6181
6181
|
* @param cbor - CBOR value
|
|
6182
6182
|
* @returns Boolean or undefined
|
|
6183
6183
|
*/
|
|
6184
|
-
const asBoolean = (cbor
|
|
6185
|
-
if (cbor
|
|
6186
|
-
if (cbor
|
|
6187
|
-
if (cbor
|
|
6184
|
+
const asBoolean = (cbor) => {
|
|
6185
|
+
if (cbor.type !== MajorType.Simple) return;
|
|
6186
|
+
if (cbor.value.type === "True") return true;
|
|
6187
|
+
if (cbor.value.type === "False") return false;
|
|
6188
6188
|
};
|
|
6189
6189
|
/**
|
|
6190
6190
|
* Extract float value if type matches.
|
|
@@ -6192,9 +6192,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6192
6192
|
* @param cbor - CBOR value
|
|
6193
6193
|
* @returns Float or undefined
|
|
6194
6194
|
*/
|
|
6195
|
-
const asFloat = (cbor
|
|
6196
|
-
if (cbor
|
|
6197
|
-
const simple = cbor
|
|
6195
|
+
const asFloat = (cbor) => {
|
|
6196
|
+
if (cbor.type !== MajorType.Simple) return;
|
|
6197
|
+
const simple = cbor.value;
|
|
6198
6198
|
if (isFloat$1(simple)) return simple.value;
|
|
6199
6199
|
};
|
|
6200
6200
|
/**
|
|
@@ -6203,12 +6203,12 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6203
6203
|
* @param cbor - CBOR value
|
|
6204
6204
|
* @returns Number or undefined
|
|
6205
6205
|
*/
|
|
6206
|
-
const asNumber = (cbor
|
|
6207
|
-
if (cbor
|
|
6208
|
-
if (cbor
|
|
6209
|
-
else return -cbor
|
|
6210
|
-
if (cbor
|
|
6211
|
-
const simple = cbor
|
|
6206
|
+
const asNumber = (cbor) => {
|
|
6207
|
+
if (cbor.type === MajorType.Unsigned) return cbor.value;
|
|
6208
|
+
if (cbor.type === MajorType.Negative) if (typeof cbor.value === "bigint") return -cbor.value - 1n;
|
|
6209
|
+
else return -cbor.value - 1;
|
|
6210
|
+
if (cbor.type === MajorType.Simple) {
|
|
6211
|
+
const simple = cbor.value;
|
|
6212
6212
|
if (isFloat$1(simple)) return simple.value;
|
|
6213
6213
|
}
|
|
6214
6214
|
};
|
|
@@ -6219,8 +6219,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6219
6219
|
* @returns Unsigned integer
|
|
6220
6220
|
* @throws {CborError} With type 'WrongType' if cbor is not an unsigned integer
|
|
6221
6221
|
*/
|
|
6222
|
-
const expectUnsigned = (cbor
|
|
6223
|
-
const value = asUnsigned(cbor
|
|
6222
|
+
const expectUnsigned = (cbor) => {
|
|
6223
|
+
const value = asUnsigned(cbor);
|
|
6224
6224
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6225
6225
|
return value;
|
|
6226
6226
|
};
|
|
@@ -6231,8 +6231,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6231
6231
|
* @returns Negative integer
|
|
6232
6232
|
* @throws {CborError} With type 'WrongType' if cbor is not a negative integer
|
|
6233
6233
|
*/
|
|
6234
|
-
const expectNegative = (cbor
|
|
6235
|
-
const value = asNegative(cbor
|
|
6234
|
+
const expectNegative = (cbor) => {
|
|
6235
|
+
const value = asNegative(cbor);
|
|
6236
6236
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6237
6237
|
return value;
|
|
6238
6238
|
};
|
|
@@ -6243,8 +6243,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6243
6243
|
* @returns Integer
|
|
6244
6244
|
* @throws {CborError} With type 'WrongType' if cbor is not an integer
|
|
6245
6245
|
*/
|
|
6246
|
-
const expectInteger = (cbor
|
|
6247
|
-
const value = asInteger(cbor
|
|
6246
|
+
const expectInteger = (cbor) => {
|
|
6247
|
+
const value = asInteger(cbor);
|
|
6248
6248
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6249
6249
|
return value;
|
|
6250
6250
|
};
|
|
@@ -6255,8 +6255,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6255
6255
|
* @returns Byte string
|
|
6256
6256
|
* @throws {CborError} With type 'WrongType' if cbor is not a byte string
|
|
6257
6257
|
*/
|
|
6258
|
-
const expectBytes = (cbor
|
|
6259
|
-
const value = asBytes(cbor
|
|
6258
|
+
const expectBytes = (cbor) => {
|
|
6259
|
+
const value = asBytes(cbor);
|
|
6260
6260
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6261
6261
|
return value;
|
|
6262
6262
|
};
|
|
@@ -6267,8 +6267,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6267
6267
|
* @returns Text string
|
|
6268
6268
|
* @throws {CborError} With type 'WrongType' if cbor is not a text string
|
|
6269
6269
|
*/
|
|
6270
|
-
const expectText = (cbor
|
|
6271
|
-
const value = asText(cbor
|
|
6270
|
+
const expectText = (cbor) => {
|
|
6271
|
+
const value = asText(cbor);
|
|
6272
6272
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6273
6273
|
return value;
|
|
6274
6274
|
};
|
|
@@ -6279,8 +6279,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6279
6279
|
* @returns Array
|
|
6280
6280
|
* @throws {CborError} With type 'WrongType' if cbor is not an array
|
|
6281
6281
|
*/
|
|
6282
|
-
const expectArray = (cbor
|
|
6283
|
-
const value = asArray(cbor
|
|
6282
|
+
const expectArray = (cbor) => {
|
|
6283
|
+
const value = asArray(cbor);
|
|
6284
6284
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6285
6285
|
return value;
|
|
6286
6286
|
};
|
|
@@ -6291,8 +6291,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6291
6291
|
* @returns Map
|
|
6292
6292
|
* @throws {CborError} With type 'WrongType' if cbor is not a map
|
|
6293
6293
|
*/
|
|
6294
|
-
const expectMap = (cbor
|
|
6295
|
-
const value = asMap(cbor
|
|
6294
|
+
const expectMap = (cbor) => {
|
|
6295
|
+
const value = asMap(cbor);
|
|
6296
6296
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6297
6297
|
return value;
|
|
6298
6298
|
};
|
|
@@ -6303,8 +6303,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6303
6303
|
* @returns Boolean
|
|
6304
6304
|
* @throws {CborError} With type 'WrongType' if cbor is not a boolean
|
|
6305
6305
|
*/
|
|
6306
|
-
const expectBoolean = (cbor
|
|
6307
|
-
const value = asBoolean(cbor
|
|
6306
|
+
const expectBoolean = (cbor) => {
|
|
6307
|
+
const value = asBoolean(cbor);
|
|
6308
6308
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6309
6309
|
return value;
|
|
6310
6310
|
};
|
|
@@ -6315,8 +6315,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6315
6315
|
* @returns Float
|
|
6316
6316
|
* @throws {CborError} With type 'WrongType' if cbor is not a float
|
|
6317
6317
|
*/
|
|
6318
|
-
const expectFloat = (cbor
|
|
6319
|
-
const value = asFloat(cbor
|
|
6318
|
+
const expectFloat = (cbor) => {
|
|
6319
|
+
const value = asFloat(cbor);
|
|
6320
6320
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6321
6321
|
return value;
|
|
6322
6322
|
};
|
|
@@ -6327,8 +6327,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6327
6327
|
* @returns Number
|
|
6328
6328
|
* @throws {CborError} With type 'WrongType' if cbor is not a number
|
|
6329
6329
|
*/
|
|
6330
|
-
const expectNumber = (cbor
|
|
6331
|
-
const value = asNumber(cbor
|
|
6330
|
+
const expectNumber = (cbor) => {
|
|
6331
|
+
const value = asNumber(cbor);
|
|
6332
6332
|
if (value === void 0) throw new CborError({ type: "WrongType" });
|
|
6333
6333
|
return value;
|
|
6334
6334
|
};
|
|
@@ -6339,9 +6339,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6339
6339
|
* @param index - Array index
|
|
6340
6340
|
* @returns Item at index or undefined
|
|
6341
6341
|
*/
|
|
6342
|
-
const arrayItem = (cbor
|
|
6343
|
-
if (cbor
|
|
6344
|
-
const array = cbor
|
|
6342
|
+
const arrayItem = (cbor, index) => {
|
|
6343
|
+
if (cbor.type !== MajorType.Array) return;
|
|
6344
|
+
const array = cbor.value;
|
|
6345
6345
|
if (index < 0 || index >= array.length) return;
|
|
6346
6346
|
return array[index];
|
|
6347
6347
|
};
|
|
@@ -6351,9 +6351,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6351
6351
|
* @param cbor - CBOR value (must be array)
|
|
6352
6352
|
* @returns Array length or undefined
|
|
6353
6353
|
*/
|
|
6354
|
-
const arrayLength = (cbor
|
|
6355
|
-
if (cbor
|
|
6356
|
-
return cbor
|
|
6354
|
+
const arrayLength = (cbor) => {
|
|
6355
|
+
if (cbor.type !== MajorType.Array) return;
|
|
6356
|
+
return cbor.value.length;
|
|
6357
6357
|
};
|
|
6358
6358
|
/**
|
|
6359
6359
|
* Check if array is empty.
|
|
@@ -6361,9 +6361,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6361
6361
|
* @param cbor - CBOR value (must be array)
|
|
6362
6362
|
* @returns True if empty, false if not empty, undefined if not array
|
|
6363
6363
|
*/
|
|
6364
|
-
const arrayIsEmpty = (cbor
|
|
6365
|
-
if (cbor
|
|
6366
|
-
return cbor
|
|
6364
|
+
const arrayIsEmpty = (cbor) => {
|
|
6365
|
+
if (cbor.type !== MajorType.Array) return;
|
|
6366
|
+
return cbor.value.length === 0;
|
|
6367
6367
|
};
|
|
6368
6368
|
/**
|
|
6369
6369
|
* Get map value by key.
|
|
@@ -6372,9 +6372,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6372
6372
|
* @param key - Map key
|
|
6373
6373
|
* @returns Value for key or undefined
|
|
6374
6374
|
*/
|
|
6375
|
-
function mapValue(cbor
|
|
6376
|
-
if (cbor
|
|
6377
|
-
return cbor
|
|
6375
|
+
function mapValue(cbor, key) {
|
|
6376
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6377
|
+
return cbor.value.get(key);
|
|
6378
6378
|
}
|
|
6379
6379
|
/**
|
|
6380
6380
|
* Check if map has key.
|
|
@@ -6383,9 +6383,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6383
6383
|
* @param key - Map key
|
|
6384
6384
|
* @returns True if key exists, false otherwise, undefined if not map
|
|
6385
6385
|
*/
|
|
6386
|
-
function mapHas(cbor
|
|
6387
|
-
if (cbor
|
|
6388
|
-
return cbor
|
|
6386
|
+
function mapHas(cbor, key) {
|
|
6387
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6388
|
+
return cbor.value.has(key);
|
|
6389
6389
|
}
|
|
6390
6390
|
/**
|
|
6391
6391
|
* Get all map keys.
|
|
@@ -6393,9 +6393,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6393
6393
|
* @param cbor - CBOR value (must be map)
|
|
6394
6394
|
* @returns Array of keys or undefined
|
|
6395
6395
|
*/
|
|
6396
|
-
const mapKeys = (cbor
|
|
6397
|
-
if (cbor
|
|
6398
|
-
return cbor
|
|
6396
|
+
const mapKeys = (cbor) => {
|
|
6397
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6398
|
+
return cbor.value.entriesArray.map((e) => e.key);
|
|
6399
6399
|
};
|
|
6400
6400
|
/**
|
|
6401
6401
|
* Get all map values.
|
|
@@ -6403,9 +6403,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6403
6403
|
* @param cbor - CBOR value (must be map)
|
|
6404
6404
|
* @returns Array of values or undefined
|
|
6405
6405
|
*/
|
|
6406
|
-
const mapValues = (cbor
|
|
6407
|
-
if (cbor
|
|
6408
|
-
return cbor
|
|
6406
|
+
const mapValues = (cbor) => {
|
|
6407
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6408
|
+
return cbor.value.entriesArray.map((e) => e.value);
|
|
6409
6409
|
};
|
|
6410
6410
|
/**
|
|
6411
6411
|
* Get map size.
|
|
@@ -6413,9 +6413,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6413
6413
|
* @param cbor - CBOR value (must be map)
|
|
6414
6414
|
* @returns Map size or undefined
|
|
6415
6415
|
*/
|
|
6416
|
-
const mapSize = (cbor
|
|
6417
|
-
if (cbor
|
|
6418
|
-
return cbor
|
|
6416
|
+
const mapSize = (cbor) => {
|
|
6417
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6418
|
+
return cbor.value.size;
|
|
6419
6419
|
};
|
|
6420
6420
|
/**
|
|
6421
6421
|
* Check if map is empty.
|
|
@@ -6423,9 +6423,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6423
6423
|
* @param cbor - CBOR value (must be map)
|
|
6424
6424
|
* @returns True if empty, false if not empty, undefined if not map
|
|
6425
6425
|
*/
|
|
6426
|
-
const mapIsEmpty = (cbor
|
|
6427
|
-
if (cbor
|
|
6428
|
-
return cbor
|
|
6426
|
+
const mapIsEmpty = (cbor) => {
|
|
6427
|
+
if (cbor.type !== MajorType.Map) return;
|
|
6428
|
+
return cbor.value.size === 0;
|
|
6429
6429
|
};
|
|
6430
6430
|
/**
|
|
6431
6431
|
* Get tag value from tagged CBOR.
|
|
@@ -6433,9 +6433,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6433
6433
|
* @param cbor - CBOR value (must be tagged)
|
|
6434
6434
|
* @returns Tag value or undefined
|
|
6435
6435
|
*/
|
|
6436
|
-
const tagValue = (cbor
|
|
6437
|
-
if (cbor
|
|
6438
|
-
return cbor
|
|
6436
|
+
const tagValue = (cbor) => {
|
|
6437
|
+
if (cbor.type !== MajorType.Tagged) return;
|
|
6438
|
+
return cbor.tag;
|
|
6439
6439
|
};
|
|
6440
6440
|
/**
|
|
6441
6441
|
* Get content from tagged CBOR.
|
|
@@ -6443,9 +6443,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6443
6443
|
* @param cbor - CBOR value (must be tagged)
|
|
6444
6444
|
* @returns Tagged content or undefined
|
|
6445
6445
|
*/
|
|
6446
|
-
const tagContent = (cbor
|
|
6447
|
-
if (cbor
|
|
6448
|
-
return cbor
|
|
6446
|
+
const tagContent = (cbor) => {
|
|
6447
|
+
if (cbor.type !== MajorType.Tagged) return;
|
|
6448
|
+
return cbor.value;
|
|
6449
6449
|
};
|
|
6450
6450
|
/**
|
|
6451
6451
|
* Check if CBOR has a specific tag.
|
|
@@ -6454,9 +6454,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6454
6454
|
* @param tag - Tag value to check
|
|
6455
6455
|
* @returns True if has tag, false otherwise
|
|
6456
6456
|
*/
|
|
6457
|
-
const hasTag = (cbor
|
|
6458
|
-
if (cbor
|
|
6459
|
-
return cbor
|
|
6457
|
+
const hasTag = (cbor, tag) => {
|
|
6458
|
+
if (cbor.type !== MajorType.Tagged) return false;
|
|
6459
|
+
return cbor.tag === tag;
|
|
6460
6460
|
};
|
|
6461
6461
|
/**
|
|
6462
6462
|
* Extract content if has specific tag.
|
|
@@ -6465,8 +6465,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6465
6465
|
* @param tag - Expected tag value
|
|
6466
6466
|
* @returns Tagged content or undefined
|
|
6467
6467
|
*/
|
|
6468
|
-
const getTaggedContent = (cbor
|
|
6469
|
-
if (cbor
|
|
6468
|
+
const getTaggedContent = (cbor, tag) => {
|
|
6469
|
+
if (cbor.type === MajorType.Tagged && cbor.tag === tag) return cbor.value;
|
|
6470
6470
|
};
|
|
6471
6471
|
/**
|
|
6472
6472
|
* Extract content if has specific tag, throwing if not.
|
|
@@ -6476,8 +6476,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6476
6476
|
* @returns Tagged content
|
|
6477
6477
|
* @throws {CborError} With type 'WrongType' if cbor is not tagged with the expected tag
|
|
6478
6478
|
*/
|
|
6479
|
-
const expectTaggedContent = (cbor
|
|
6480
|
-
const content = getTaggedContent(cbor
|
|
6479
|
+
const expectTaggedContent = (cbor, tag) => {
|
|
6480
|
+
const content = getTaggedContent(cbor, tag);
|
|
6481
6481
|
if (content === void 0) throw new CborError({ type: "WrongType" });
|
|
6482
6482
|
return content;
|
|
6483
6483
|
};
|
|
@@ -6488,12 +6488,12 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6488
6488
|
* @param cbor - CBOR value
|
|
6489
6489
|
* @returns [Tag, Cbor] tuple or undefined
|
|
6490
6490
|
*/
|
|
6491
|
-
const asTaggedValue = (cbor
|
|
6492
|
-
if (cbor
|
|
6491
|
+
const asTaggedValue = (cbor) => {
|
|
6492
|
+
if (cbor.type !== MajorType.Tagged) return;
|
|
6493
6493
|
return [{
|
|
6494
|
-
value: cbor
|
|
6495
|
-
name: `tag-${cbor
|
|
6496
|
-
}, cbor
|
|
6494
|
+
value: cbor.tag,
|
|
6495
|
+
name: `tag-${cbor.tag}`
|
|
6496
|
+
}, cbor.value];
|
|
6497
6497
|
};
|
|
6498
6498
|
/**
|
|
6499
6499
|
* Alias for asBytes - extract byte string value if type matches.
|
|
@@ -6509,9 +6509,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6509
6509
|
* @param cbor - CBOR value
|
|
6510
6510
|
* @returns Array wrapper with get() method or undefined
|
|
6511
6511
|
*/
|
|
6512
|
-
const asCborArray = (cbor
|
|
6513
|
-
if (cbor
|
|
6514
|
-
const arr = cbor
|
|
6512
|
+
const asCborArray = (cbor) => {
|
|
6513
|
+
if (cbor.type !== MajorType.Array) return;
|
|
6514
|
+
const arr = cbor.value;
|
|
6515
6515
|
return {
|
|
6516
6516
|
length: arr.length,
|
|
6517
6517
|
get(index) {
|
|
@@ -6536,9 +6536,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6536
6536
|
* @param cbor - CBOR value
|
|
6537
6537
|
* @returns True if value is numeric
|
|
6538
6538
|
*/
|
|
6539
|
-
const isNumber = (cbor
|
|
6540
|
-
if (cbor
|
|
6541
|
-
if (cbor
|
|
6539
|
+
const isNumber = (cbor) => {
|
|
6540
|
+
if (cbor.type === MajorType.Unsigned || cbor.type === MajorType.Negative) return true;
|
|
6541
|
+
if (cbor.type === MajorType.Simple) return isFloat$1(cbor.value);
|
|
6542
6542
|
return false;
|
|
6543
6543
|
};
|
|
6544
6544
|
|
|
@@ -6574,13 +6574,13 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6574
6574
|
* encoded CBOR representation, ensuring deterministic encoding.
|
|
6575
6575
|
*/
|
|
6576
6576
|
var CborMap = class CborMap {
|
|
6577
|
-
|
|
6577
|
+
_dict;
|
|
6578
6578
|
/**
|
|
6579
6579
|
* Creates a new, empty CBOR Map.
|
|
6580
6580
|
* Optionally initializes from a JavaScript Map.
|
|
6581
6581
|
*/
|
|
6582
6582
|
constructor(map) {
|
|
6583
|
-
this
|
|
6583
|
+
this._dict = new import_sorted_map.SortedMap(null, areBytesEqual, lexicographicallyCompareBytes);
|
|
6584
6584
|
if (map !== void 0) for (const [key, value] of map.entries()) this.set(key, value);
|
|
6585
6585
|
}
|
|
6586
6586
|
/**
|
|
@@ -6598,7 +6598,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6598
6598
|
const keyCbor = cbor(key);
|
|
6599
6599
|
const valueCbor = cbor(value);
|
|
6600
6600
|
const keyData = cborData(keyCbor);
|
|
6601
|
-
this
|
|
6601
|
+
this._dict.set(keyData, {
|
|
6602
6602
|
key: keyCbor,
|
|
6603
6603
|
value: valueCbor
|
|
6604
6604
|
});
|
|
@@ -6609,7 +6609,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6609
6609
|
insert(key, value) {
|
|
6610
6610
|
this.set(key, value);
|
|
6611
6611
|
}
|
|
6612
|
-
|
|
6612
|
+
_makeKey(key) {
|
|
6613
6613
|
return cborData(cbor(key));
|
|
6614
6614
|
}
|
|
6615
6615
|
/**
|
|
@@ -6618,8 +6618,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6618
6618
|
* Matches Rust's Map::get().
|
|
6619
6619
|
*/
|
|
6620
6620
|
get(key) {
|
|
6621
|
-
const keyData = this
|
|
6622
|
-
const value = this
|
|
6621
|
+
const keyData = this._makeKey(key);
|
|
6622
|
+
const value = this._dict.get(keyData);
|
|
6623
6623
|
if (value === void 0) return;
|
|
6624
6624
|
return extractCbor(value.value);
|
|
6625
6625
|
}
|
|
@@ -6638,56 +6638,56 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6638
6638
|
* Matches Rust's Map::contains_key().
|
|
6639
6639
|
*/
|
|
6640
6640
|
containsKey(key) {
|
|
6641
|
-
const keyData = this
|
|
6642
|
-
return this
|
|
6641
|
+
const keyData = this._makeKey(key);
|
|
6642
|
+
return this._dict.has(keyData);
|
|
6643
6643
|
}
|
|
6644
6644
|
delete(key) {
|
|
6645
|
-
const keyData = this
|
|
6646
|
-
const existed = this
|
|
6647
|
-
this
|
|
6645
|
+
const keyData = this._makeKey(key);
|
|
6646
|
+
const existed = this._dict.has(keyData);
|
|
6647
|
+
this._dict.delete(keyData);
|
|
6648
6648
|
return existed;
|
|
6649
6649
|
}
|
|
6650
6650
|
has(key) {
|
|
6651
|
-
const keyData = this
|
|
6652
|
-
return this
|
|
6651
|
+
const keyData = this._makeKey(key);
|
|
6652
|
+
return this._dict.has(keyData);
|
|
6653
6653
|
}
|
|
6654
6654
|
clear() {
|
|
6655
|
-
this
|
|
6655
|
+
this._dict = new import_sorted_map.SortedMap(null, areBytesEqual, lexicographicallyCompareBytes);
|
|
6656
6656
|
}
|
|
6657
6657
|
/**
|
|
6658
6658
|
* Returns the number of entries in the map.
|
|
6659
6659
|
* Matches Rust's Map::len().
|
|
6660
6660
|
*/
|
|
6661
6661
|
get length() {
|
|
6662
|
-
return this
|
|
6662
|
+
return this._dict.length;
|
|
6663
6663
|
}
|
|
6664
6664
|
/**
|
|
6665
6665
|
* Alias for length to match JavaScript Map API.
|
|
6666
6666
|
* Also matches Rust's Map::len().
|
|
6667
6667
|
*/
|
|
6668
6668
|
get size() {
|
|
6669
|
-
return this
|
|
6669
|
+
return this._dict.length;
|
|
6670
6670
|
}
|
|
6671
6671
|
/**
|
|
6672
6672
|
* Returns the number of entries in the map.
|
|
6673
6673
|
* Matches Rust's Map::len().
|
|
6674
6674
|
*/
|
|
6675
6675
|
len() {
|
|
6676
|
-
return this
|
|
6676
|
+
return this._dict.length;
|
|
6677
6677
|
}
|
|
6678
6678
|
/**
|
|
6679
6679
|
* Checks if the map is empty.
|
|
6680
6680
|
* Matches Rust's Map::is_empty().
|
|
6681
6681
|
*/
|
|
6682
6682
|
isEmpty() {
|
|
6683
|
-
return this
|
|
6683
|
+
return this._dict.length === 0;
|
|
6684
6684
|
}
|
|
6685
6685
|
/**
|
|
6686
6686
|
* Get the entries of the map as an array.
|
|
6687
6687
|
* Keys are sorted in lexicographic order of their encoded CBOR bytes.
|
|
6688
6688
|
*/
|
|
6689
6689
|
get entriesArray() {
|
|
6690
|
-
return this
|
|
6690
|
+
return this._dict.map((value, _key) => ({
|
|
6691
6691
|
key: value.key,
|
|
6692
6692
|
value: value.value
|
|
6693
6693
|
}));
|
|
@@ -6714,16 +6714,16 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6714
6714
|
* Matches Rust's Map::insert_next().
|
|
6715
6715
|
*/
|
|
6716
6716
|
setNext(key, value) {
|
|
6717
|
-
const lastEntry = this
|
|
6717
|
+
const lastEntry = this._dict.max();
|
|
6718
6718
|
if (lastEntry === void 0) {
|
|
6719
6719
|
this.set(key, value);
|
|
6720
6720
|
return;
|
|
6721
6721
|
}
|
|
6722
6722
|
const keyCbor = cbor(key);
|
|
6723
6723
|
const newKey = cborData(keyCbor);
|
|
6724
|
-
if (this
|
|
6725
|
-
if (lexicographicallyCompareBytes(newKey, this
|
|
6726
|
-
this
|
|
6724
|
+
if (this._dict.has(newKey)) throw new CborError({ type: "DuplicateMapKey" });
|
|
6725
|
+
if (lexicographicallyCompareBytes(newKey, this._makeKey(lastEntry.key)) <= 0) throw new CborError({ type: "MisorderedMapKey" });
|
|
6726
|
+
this._dict.set(newKey, {
|
|
6727
6727
|
key: keyCbor,
|
|
6728
6728
|
value: cbor(value)
|
|
6729
6729
|
});
|
|
@@ -6739,17 +6739,17 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6739
6739
|
const valueDebug = CborMap.formatDebug(entry.value);
|
|
6740
6740
|
return `0x${bytesToHex(encodeCbor(entry.key))}: (${keyDebug}, ${valueDebug})`;
|
|
6741
6741
|
}
|
|
6742
|
-
static formatDebug(cbor
|
|
6743
|
-
switch (cbor
|
|
6744
|
-
case MajorType.Unsigned: return `unsigned(${cbor
|
|
6745
|
-
case MajorType.Negative: return `negative(${typeof cbor
|
|
6746
|
-
case MajorType.ByteString: return `bytes(${bytesToHex(cbor
|
|
6747
|
-
case MajorType.Text: return `text("${cbor
|
|
6748
|
-
case MajorType.Array: return `array([${cbor
|
|
6749
|
-
case MajorType.Map: return cbor
|
|
6750
|
-
case MajorType.Tagged: return `tagged(${cbor
|
|
6742
|
+
static formatDebug(cbor) {
|
|
6743
|
+
switch (cbor.type) {
|
|
6744
|
+
case MajorType.Unsigned: return `unsigned(${cbor.value})`;
|
|
6745
|
+
case MajorType.Negative: return `negative(${typeof cbor.value === "bigint" ? -cbor.value - 1n : -cbor.value - 1})`;
|
|
6746
|
+
case MajorType.ByteString: return `bytes(${bytesToHex(cbor.value)})`;
|
|
6747
|
+
case MajorType.Text: return `text("${cbor.value}")`;
|
|
6748
|
+
case MajorType.Array: return `array([${cbor.value.map(CborMap.formatDebug).join(", ")}])`;
|
|
6749
|
+
case MajorType.Map: return cbor.value.debug;
|
|
6750
|
+
case MajorType.Tagged: return `tagged(${cbor.tag}, ${CborMap.formatDebug(cbor.value)})`;
|
|
6751
6751
|
case MajorType.Simple: {
|
|
6752
|
-
const simple = cbor
|
|
6752
|
+
const simple = cbor.value;
|
|
6753
6753
|
if (typeof simple === "object" && simple !== null && "type" in simple) switch (simple.type) {
|
|
6754
6754
|
case "True": return "simple(true)";
|
|
6755
6755
|
case "False": return "simple(false)";
|
|
@@ -6758,7 +6758,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6758
6758
|
}
|
|
6759
6759
|
return "simple";
|
|
6760
6760
|
}
|
|
6761
|
-
default: return diagnostic(cbor
|
|
6761
|
+
default: return diagnostic(cbor);
|
|
6762
6762
|
}
|
|
6763
6763
|
}
|
|
6764
6764
|
static entryDiagnostic(entry) {
|
|
@@ -6787,20 +6787,20 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6787
6787
|
/**
|
|
6788
6788
|
* Types of edges in the CBOR tree traversal.
|
|
6789
6789
|
*/
|
|
6790
|
-
let EdgeType = /* @__PURE__ */ function(EdgeType
|
|
6790
|
+
let EdgeType = /* @__PURE__ */ function(EdgeType) {
|
|
6791
6791
|
/** No specific edge type (root element) */
|
|
6792
|
-
EdgeType
|
|
6792
|
+
EdgeType["None"] = "none";
|
|
6793
6793
|
/** Element within an array */
|
|
6794
|
-
EdgeType
|
|
6794
|
+
EdgeType["ArrayElement"] = "array_element";
|
|
6795
6795
|
/** Key-value pair in a map (semantic unit) */
|
|
6796
|
-
EdgeType
|
|
6796
|
+
EdgeType["MapKeyValue"] = "map_key_value";
|
|
6797
6797
|
/** Key within a map */
|
|
6798
|
-
EdgeType
|
|
6798
|
+
EdgeType["MapKey"] = "map_key";
|
|
6799
6799
|
/** Value within a map */
|
|
6800
|
-
EdgeType
|
|
6800
|
+
EdgeType["MapValue"] = "map_value";
|
|
6801
6801
|
/** Content of a tagged value */
|
|
6802
|
-
EdgeType
|
|
6803
|
-
return EdgeType
|
|
6802
|
+
EdgeType["TaggedContent"] = "tagged_content";
|
|
6803
|
+
return EdgeType;
|
|
6804
6804
|
}({});
|
|
6805
6805
|
/**
|
|
6806
6806
|
* Returns a short text label for the edge type, or undefined if no label is needed.
|
|
@@ -6911,35 +6911,35 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6911
6911
|
* });
|
|
6912
6912
|
* ```
|
|
6913
6913
|
*/
|
|
6914
|
-
const walk = (cbor
|
|
6915
|
-
walkInternal(cbor
|
|
6914
|
+
const walk = (cbor, initialState, visitor) => {
|
|
6915
|
+
walkInternal(cbor, 0, { type: EdgeType.None }, initialState, visitor);
|
|
6916
6916
|
};
|
|
6917
6917
|
/**
|
|
6918
6918
|
* Internal recursive walk implementation.
|
|
6919
6919
|
*
|
|
6920
6920
|
* @internal
|
|
6921
6921
|
*/
|
|
6922
|
-
function walkInternal(cbor
|
|
6922
|
+
function walkInternal(cbor, level, edge, state, visitor, skipVisit = false) {
|
|
6923
6923
|
let currentState = state;
|
|
6924
6924
|
let stopDescent = false;
|
|
6925
6925
|
if (!skipVisit) {
|
|
6926
6926
|
const [newState, stop] = visitor({
|
|
6927
6927
|
type: "single",
|
|
6928
|
-
cbor
|
|
6928
|
+
cbor
|
|
6929
6929
|
}, level, edge, currentState);
|
|
6930
6930
|
currentState = newState;
|
|
6931
6931
|
stopDescent = stop;
|
|
6932
6932
|
if (stopDescent) return currentState;
|
|
6933
6933
|
}
|
|
6934
|
-
switch (cbor
|
|
6934
|
+
switch (cbor.type) {
|
|
6935
6935
|
case MajorType.Array:
|
|
6936
|
-
currentState = walkArray(cbor
|
|
6936
|
+
currentState = walkArray(cbor, level, currentState, visitor);
|
|
6937
6937
|
break;
|
|
6938
6938
|
case MajorType.Map:
|
|
6939
|
-
currentState = walkMap(cbor
|
|
6939
|
+
currentState = walkMap(cbor, level, currentState, visitor);
|
|
6940
6940
|
break;
|
|
6941
6941
|
case MajorType.Tagged:
|
|
6942
|
-
currentState = walkTagged(cbor
|
|
6942
|
+
currentState = walkTagged(cbor, level, currentState, visitor);
|
|
6943
6943
|
break;
|
|
6944
6944
|
default: break;
|
|
6945
6945
|
}
|
|
@@ -6950,10 +6950,10 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6950
6950
|
*
|
|
6951
6951
|
* @internal
|
|
6952
6952
|
*/
|
|
6953
|
-
function walkArray(cbor
|
|
6953
|
+
function walkArray(cbor, level, state, visitor) {
|
|
6954
6954
|
let currentState = state;
|
|
6955
|
-
for (let index = 0; index < cbor
|
|
6956
|
-
const item = cbor
|
|
6955
|
+
for (let index = 0; index < cbor.value.length; index++) {
|
|
6956
|
+
const item = cbor.value[index];
|
|
6957
6957
|
if (item === void 0) throw new CborError({
|
|
6958
6958
|
type: "Custom",
|
|
6959
6959
|
message: `Array element at index ${index} is undefined`
|
|
@@ -6975,9 +6975,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6975
6975
|
*
|
|
6976
6976
|
* @internal
|
|
6977
6977
|
*/
|
|
6978
|
-
function walkMap(cbor
|
|
6978
|
+
function walkMap(cbor, level, state, visitor) {
|
|
6979
6979
|
let currentState = state;
|
|
6980
|
-
for (const entry of cbor
|
|
6980
|
+
for (const entry of cbor.value.entriesArray) {
|
|
6981
6981
|
const { key, value } = entry;
|
|
6982
6982
|
const [kvState, kvStop] = visitor({
|
|
6983
6983
|
type: "keyvalue",
|
|
@@ -6997,8 +6997,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
6997
6997
|
*
|
|
6998
6998
|
* @internal
|
|
6999
6999
|
*/
|
|
7000
|
-
function walkTagged(cbor
|
|
7001
|
-
return walkInternal(cbor
|
|
7000
|
+
function walkTagged(cbor, level, state, visitor) {
|
|
7001
|
+
return walkInternal(cbor.value, level + 1, { type: EdgeType.TaggedContent }, state, visitor);
|
|
7002
7002
|
}
|
|
7003
7003
|
|
|
7004
7004
|
//#endregion
|
|
@@ -7208,7 +7208,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7208
7208
|
}
|
|
7209
7209
|
case MajorType.Map: {
|
|
7210
7210
|
const entries = c.value.entriesArray;
|
|
7211
|
-
const flatArrayBytes = concatBytes(entries.map(({ key, value
|
|
7211
|
+
const flatArrayBytes = concatBytes(entries.map(({ key, value }) => concatBytes([cborData(key), cborData(value)])));
|
|
7212
7212
|
const lengthBytes = encodeVarInt(entries.length, MajorType.Map);
|
|
7213
7213
|
return new Uint8Array([...lengthBytes, ...flatArrayBytes]);
|
|
7214
7214
|
}
|
|
@@ -7230,15 +7230,15 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7230
7230
|
const toByteString = (data) => {
|
|
7231
7231
|
return cbor(data);
|
|
7232
7232
|
};
|
|
7233
|
-
const toByteStringFromHex = (hex
|
|
7234
|
-
return toByteString(hexToBytes(hex
|
|
7233
|
+
const toByteStringFromHex = (hex) => {
|
|
7234
|
+
return toByteString(hexToBytes(hex));
|
|
7235
7235
|
};
|
|
7236
7236
|
const toTaggedValue = (tag, item) => {
|
|
7237
|
-
const tagValue
|
|
7237
|
+
const tagValue = typeof tag === "object" && "value" in tag ? tag.value : tag;
|
|
7238
7238
|
return attachMethods({
|
|
7239
7239
|
isCbor: true,
|
|
7240
7240
|
type: MajorType.Tagged,
|
|
7241
|
-
tag: tagValue
|
|
7241
|
+
tag: tagValue,
|
|
7242
7242
|
value: cbor(item)
|
|
7243
7243
|
});
|
|
7244
7244
|
};
|
|
@@ -7419,11 +7419,11 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7419
7419
|
validateTag(expectedTags) {
|
|
7420
7420
|
if (this.type !== MajorType.Tagged) throw new CborError({ type: "WrongType" });
|
|
7421
7421
|
const expectedValues = expectedTags.map((t) => t.value);
|
|
7422
|
-
const tagValue
|
|
7423
|
-
const matchingTag = expectedTags.find((t) => t.value === tagValue
|
|
7422
|
+
const tagValue = this.tag;
|
|
7423
|
+
const matchingTag = expectedTags.find((t) => t.value === tagValue);
|
|
7424
7424
|
if (matchingTag === void 0) throw new CborError({
|
|
7425
7425
|
type: "Custom",
|
|
7426
|
-
message: `Wrong tag: expected ${expectedValues.join(" or ")}, got ${tagValue
|
|
7426
|
+
message: `Wrong tag: expected ${expectedValues.join(" or ")}, got ${tagValue}`
|
|
7427
7427
|
});
|
|
7428
7428
|
return matchingTag;
|
|
7429
7429
|
},
|
|
@@ -7469,8 +7469,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7469
7469
|
tryFromData(data) {
|
|
7470
7470
|
return decodeCbor(data);
|
|
7471
7471
|
},
|
|
7472
|
-
tryFromHex(hex
|
|
7473
|
-
const data = hexToBytes(hex
|
|
7472
|
+
tryFromHex(hex) {
|
|
7473
|
+
const data = hexToBytes(hex);
|
|
7474
7474
|
return this.tryFromData(data);
|
|
7475
7475
|
}
|
|
7476
7476
|
};
|
|
@@ -7543,14 +7543,14 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7543
7543
|
* @returns The matching tag
|
|
7544
7544
|
* @throws Error if the value is not tagged or has an unexpected tag
|
|
7545
7545
|
*/
|
|
7546
|
-
const validateTag = (cbor
|
|
7547
|
-
if (cbor
|
|
7546
|
+
const validateTag = (cbor, expectedTags) => {
|
|
7547
|
+
if (cbor.type !== MajorType.Tagged) throw new CborError({ type: "WrongType" });
|
|
7548
7548
|
const expectedValues = expectedTags.map((t) => t.value);
|
|
7549
|
-
const tagValue
|
|
7550
|
-
const matchingTag = expectedTags.find((t) => t.value === tagValue
|
|
7549
|
+
const tagValue = cbor.tag;
|
|
7550
|
+
const matchingTag = expectedTags.find((t) => t.value === tagValue);
|
|
7551
7551
|
if (matchingTag === void 0) throw new CborError({
|
|
7552
7552
|
type: "Custom",
|
|
7553
|
-
message: `Wrong tag: expected ${expectedValues.join(" or ")}, got ${tagValue
|
|
7553
|
+
message: `Wrong tag: expected ${expectedValues.join(" or ")}, got ${tagValue}`
|
|
7554
7554
|
});
|
|
7555
7555
|
return matchingTag;
|
|
7556
7556
|
};
|
|
@@ -7561,9 +7561,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7561
7561
|
* @returns The untagged content
|
|
7562
7562
|
* @throws Error if the value is not tagged
|
|
7563
7563
|
*/
|
|
7564
|
-
const extractTaggedContent = (cbor
|
|
7565
|
-
if (cbor
|
|
7566
|
-
return cbor
|
|
7564
|
+
const extractTaggedContent = (cbor) => {
|
|
7565
|
+
if (cbor.type !== MajorType.Tagged) throw new CborError({ type: "WrongType" });
|
|
7566
|
+
return cbor.value;
|
|
7567
7567
|
};
|
|
7568
7568
|
|
|
7569
7569
|
//#endregion
|
|
@@ -7622,7 +7622,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7622
7622
|
* ```
|
|
7623
7623
|
*/
|
|
7624
7624
|
var CborDate = class CborDate {
|
|
7625
|
-
|
|
7625
|
+
_datetime;
|
|
7626
7626
|
/**
|
|
7627
7627
|
* Creates a new `CborDate` from the given JavaScript `Date`.
|
|
7628
7628
|
*
|
|
@@ -7641,7 +7641,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7641
7641
|
*/
|
|
7642
7642
|
static fromDatetime(dateTime) {
|
|
7643
7643
|
const instance = new CborDate();
|
|
7644
|
-
instance
|
|
7644
|
+
instance._datetime = new Date(dateTime);
|
|
7645
7645
|
return instance;
|
|
7646
7646
|
}
|
|
7647
7647
|
/**
|
|
@@ -7805,7 +7805,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7805
7805
|
* ```
|
|
7806
7806
|
*/
|
|
7807
7807
|
datetime() {
|
|
7808
|
-
return new Date(this
|
|
7808
|
+
return new Date(this._datetime);
|
|
7809
7809
|
}
|
|
7810
7810
|
/**
|
|
7811
7811
|
* Returns the `CborDate` as the number of seconds since the Unix epoch.
|
|
@@ -7824,7 +7824,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7824
7824
|
* ```
|
|
7825
7825
|
*/
|
|
7826
7826
|
timestamp() {
|
|
7827
|
-
return Math.trunc(this
|
|
7827
|
+
return Math.trunc(this._datetime.getTime() / 1e3) + this._datetime.getTime() % 1e3 / 1e3;
|
|
7828
7828
|
}
|
|
7829
7829
|
/**
|
|
7830
7830
|
* Add seconds to this date.
|
|
@@ -7922,18 +7922,18 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7922
7922
|
*
|
|
7923
7923
|
* @throws Error if the CBOR value is not a valid timestamp
|
|
7924
7924
|
*/
|
|
7925
|
-
fromUntaggedCbor(cbor
|
|
7925
|
+
fromUntaggedCbor(cbor) {
|
|
7926
7926
|
let timestamp;
|
|
7927
|
-
switch (cbor
|
|
7927
|
+
switch (cbor.type) {
|
|
7928
7928
|
case MajorType.Unsigned:
|
|
7929
|
-
timestamp = typeof cbor
|
|
7929
|
+
timestamp = typeof cbor.value === "number" ? cbor.value : Number(cbor.value);
|
|
7930
7930
|
break;
|
|
7931
7931
|
case MajorType.Negative:
|
|
7932
|
-
if (typeof cbor
|
|
7933
|
-
else timestamp = -cbor
|
|
7932
|
+
if (typeof cbor.value === "bigint") timestamp = Number(-cbor.value - 1n);
|
|
7933
|
+
else timestamp = -cbor.value - 1;
|
|
7934
7934
|
break;
|
|
7935
7935
|
case MajorType.Simple:
|
|
7936
|
-
if (cbor
|
|
7936
|
+
if (cbor.value.type === "Float") timestamp = cbor.value.value;
|
|
7937
7937
|
else throw new CborError({
|
|
7938
7938
|
type: "Custom",
|
|
7939
7939
|
message: "Invalid date CBOR: expected numeric value"
|
|
@@ -7944,7 +7944,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7944
7944
|
message: "Invalid date CBOR: expected numeric value"
|
|
7945
7945
|
});
|
|
7946
7946
|
}
|
|
7947
|
-
this
|
|
7947
|
+
this._datetime = CborDate.fromTimestamp(timestamp)._datetime;
|
|
7948
7948
|
return this;
|
|
7949
7949
|
}
|
|
7950
7950
|
/**
|
|
@@ -7956,9 +7956,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7956
7956
|
*
|
|
7957
7957
|
* @throws Error if the CBOR value has the wrong tag or cannot be decoded
|
|
7958
7958
|
*/
|
|
7959
|
-
fromTaggedCbor(cbor
|
|
7960
|
-
validateTag(cbor
|
|
7961
|
-
const content = extractTaggedContent(cbor
|
|
7959
|
+
fromTaggedCbor(cbor) {
|
|
7960
|
+
validateTag(cbor, this.cborTags());
|
|
7961
|
+
const content = extractTaggedContent(cbor);
|
|
7962
7962
|
return this.fromUntaggedCbor(content);
|
|
7963
7963
|
}
|
|
7964
7964
|
/**
|
|
@@ -7967,8 +7967,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7967
7967
|
* @param cbor - Tagged CBOR value
|
|
7968
7968
|
* @returns New CborDate instance
|
|
7969
7969
|
*/
|
|
7970
|
-
static fromTaggedCbor(cbor
|
|
7971
|
-
return new CborDate().fromTaggedCbor(cbor
|
|
7970
|
+
static fromTaggedCbor(cbor) {
|
|
7971
|
+
return new CborDate().fromTaggedCbor(cbor);
|
|
7972
7972
|
}
|
|
7973
7973
|
/**
|
|
7974
7974
|
* Static method to create a CborDate from untagged CBOR.
|
|
@@ -7976,8 +7976,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
7976
7976
|
* @param cbor - Untagged CBOR value
|
|
7977
7977
|
* @returns New CborDate instance
|
|
7978
7978
|
*/
|
|
7979
|
-
static fromUntaggedCbor(cbor
|
|
7980
|
-
return new CborDate().fromUntaggedCbor(cbor
|
|
7979
|
+
static fromUntaggedCbor(cbor) {
|
|
7980
|
+
return new CborDate().fromUntaggedCbor(cbor);
|
|
7981
7981
|
}
|
|
7982
7982
|
/**
|
|
7983
7983
|
* Implementation of the `toString` method for `CborDate`.
|
|
@@ -8002,7 +8002,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8002
8002
|
* ```
|
|
8003
8003
|
*/
|
|
8004
8004
|
toString() {
|
|
8005
|
-
const dt = this
|
|
8005
|
+
const dt = this._datetime;
|
|
8006
8006
|
if (!(dt.getUTCHours() !== 0 || dt.getUTCMinutes() !== 0 || dt.getUTCSeconds() !== 0)) {
|
|
8007
8007
|
const datePart = dt.toISOString().split("T")[0];
|
|
8008
8008
|
if (datePart === void 0) throw new CborError({
|
|
@@ -8019,7 +8019,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8019
8019
|
* @returns true if dates represent the same moment in time
|
|
8020
8020
|
*/
|
|
8021
8021
|
equals(other) {
|
|
8022
|
-
return this
|
|
8022
|
+
return this._datetime.getTime() === other._datetime.getTime();
|
|
8023
8023
|
}
|
|
8024
8024
|
/**
|
|
8025
8025
|
* Compare two dates.
|
|
@@ -8028,8 +8028,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8028
8028
|
* @returns -1 if this < other, 0 if equal, 1 if this > other
|
|
8029
8029
|
*/
|
|
8030
8030
|
compare(other) {
|
|
8031
|
-
const thisTime = this
|
|
8032
|
-
const otherTime = other
|
|
8031
|
+
const thisTime = this._datetime.getTime();
|
|
8032
|
+
const otherTime = other._datetime.getTime();
|
|
8033
8033
|
if (thisTime < otherTime) return -1;
|
|
8034
8034
|
if (thisTime > otherTime) return 1;
|
|
8035
8035
|
return 0;
|
|
@@ -8043,10 +8043,272 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8043
8043
|
return this.toString();
|
|
8044
8044
|
}
|
|
8045
8045
|
constructor() {
|
|
8046
|
-
this
|
|
8046
|
+
this._datetime = /* @__PURE__ */ new Date();
|
|
8047
8047
|
}
|
|
8048
8048
|
};
|
|
8049
8049
|
|
|
8050
|
+
//#endregion
|
|
8051
|
+
//#region src/bignum.ts
|
|
8052
|
+
/**
|
|
8053
|
+
* CBOR bignum (tags 2 and 3) support.
|
|
8054
|
+
*
|
|
8055
|
+
* This module provides conversion between CBOR and JavaScript BigInt types,
|
|
8056
|
+
* implementing RFC 8949 §3.4.3 (Bignums) with dCBOR/CDE canonical encoding rules.
|
|
8057
|
+
*
|
|
8058
|
+
* Encoding:
|
|
8059
|
+
* - `biguintToCbor` always encodes as tag 2 (positive bignum) with a byte
|
|
8060
|
+
* string content.
|
|
8061
|
+
* - `bigintToCbor` encodes as tag 2 for non-negative values or tag 3
|
|
8062
|
+
* (negative bignum) for negative values.
|
|
8063
|
+
* - No numeric reduction is performed: values are always encoded as bignums,
|
|
8064
|
+
* even if they would fit in normal CBOR integers.
|
|
8065
|
+
*
|
|
8066
|
+
* Decoding:
|
|
8067
|
+
* - Accepts CBOR integers (major types 0 and 1) and converts them to bigints.
|
|
8068
|
+
* - Accepts tag 2 (positive bignum) and tag 3 (negative bignum) with byte
|
|
8069
|
+
* string content.
|
|
8070
|
+
* - Enforces shortest-form canonical representation for bignum magnitudes.
|
|
8071
|
+
* - Rejects floating-point values.
|
|
8072
|
+
*
|
|
8073
|
+
* @module bignum
|
|
8074
|
+
*/
|
|
8075
|
+
const TAG_2_POSITIVE_BIGNUM = 2;
|
|
8076
|
+
const TAG_3_NEGATIVE_BIGNUM = 3;
|
|
8077
|
+
/**
|
|
8078
|
+
* Validates that a bignum magnitude byte string is in shortest canonical form.
|
|
8079
|
+
*
|
|
8080
|
+
* Matches Rust's `validate_bignum_magnitude()`.
|
|
8081
|
+
*
|
|
8082
|
+
* Rules:
|
|
8083
|
+
* - For positive bignums (tag 2): empty byte string represents zero;
|
|
8084
|
+
* non-empty must not have leading zero bytes.
|
|
8085
|
+
* - For negative bignums (tag 3): byte string must not be empty
|
|
8086
|
+
* (magnitude zero is encoded as `0x00`); must not have leading zero bytes
|
|
8087
|
+
* except when the magnitude is zero (single `0x00`).
|
|
8088
|
+
*
|
|
8089
|
+
* @param bytes - The magnitude byte string to validate
|
|
8090
|
+
* @param isNegative - Whether this is for a negative bignum (tag 3)
|
|
8091
|
+
* @throws CborError with type NonCanonicalNumeric on validation failure
|
|
8092
|
+
*/
|
|
8093
|
+
function validateBignumMagnitude(bytes, isNegative) {
|
|
8094
|
+
if (isNegative) {
|
|
8095
|
+
if (bytes.length === 0) throw new CborError({ type: "NonCanonicalNumeric" });
|
|
8096
|
+
if (bytes.length > 1 && bytes[0] === 0) throw new CborError({ type: "NonCanonicalNumeric" });
|
|
8097
|
+
} else if (bytes.length > 0 && bytes[0] === 0) throw new CborError({ type: "NonCanonicalNumeric" });
|
|
8098
|
+
}
|
|
8099
|
+
/**
|
|
8100
|
+
* Strips leading zero bytes from a byte array, returning the minimal
|
|
8101
|
+
* representation.
|
|
8102
|
+
*
|
|
8103
|
+
* Matches Rust's `strip_leading_zeros()`.
|
|
8104
|
+
*
|
|
8105
|
+
* @param bytes - The byte array to strip
|
|
8106
|
+
* @returns A subarray with leading zeros removed
|
|
8107
|
+
*/
|
|
8108
|
+
function stripLeadingZeros(bytes) {
|
|
8109
|
+
let start = 0;
|
|
8110
|
+
while (start < bytes.length && bytes[start] === 0) start++;
|
|
8111
|
+
return bytes.subarray(start);
|
|
8112
|
+
}
|
|
8113
|
+
/**
|
|
8114
|
+
* Convert a non-negative bigint to a big-endian byte array.
|
|
8115
|
+
*
|
|
8116
|
+
* Zero returns an empty Uint8Array.
|
|
8117
|
+
*
|
|
8118
|
+
* @param value - A non-negative bigint value
|
|
8119
|
+
* @returns Big-endian byte representation
|
|
8120
|
+
*/
|
|
8121
|
+
function bigintToBytes(value) {
|
|
8122
|
+
if (value === 0n) return new Uint8Array(0);
|
|
8123
|
+
const hex = value.toString(16);
|
|
8124
|
+
const padded = hex.length % 2 !== 0 ? `0${hex}` : hex;
|
|
8125
|
+
const bytes = new Uint8Array(padded.length / 2);
|
|
8126
|
+
for (let i = 0; i < bytes.length; i++) bytes[i] = parseInt(padded.substring(i * 2, i * 2 + 2), 16);
|
|
8127
|
+
return bytes;
|
|
8128
|
+
}
|
|
8129
|
+
/**
|
|
8130
|
+
* Convert a big-endian byte array to a bigint.
|
|
8131
|
+
*
|
|
8132
|
+
* Empty array returns 0n.
|
|
8133
|
+
*
|
|
8134
|
+
* @param bytes - Big-endian byte representation
|
|
8135
|
+
* @returns The bigint value
|
|
8136
|
+
*/
|
|
8137
|
+
function bytesToBigint(bytes) {
|
|
8138
|
+
if (bytes.length === 0) return 0n;
|
|
8139
|
+
let result = 0n;
|
|
8140
|
+
for (const byte of bytes) result = result << 8n | BigInt(byte);
|
|
8141
|
+
return result;
|
|
8142
|
+
}
|
|
8143
|
+
/**
|
|
8144
|
+
* Encode a non-negative bigint as a CBOR tag 2 (positive bignum).
|
|
8145
|
+
*
|
|
8146
|
+
* Matches Rust's `From<BigUint> for CBOR`.
|
|
8147
|
+
*
|
|
8148
|
+
* The value is always encoded as a bignum regardless of size.
|
|
8149
|
+
* Zero is encoded as tag 2 with an empty byte string.
|
|
8150
|
+
*
|
|
8151
|
+
* @param value - A non-negative bigint (must be >= 0n)
|
|
8152
|
+
* @returns CBOR tagged value
|
|
8153
|
+
* @throws CborError with type OutOfRange if value is negative
|
|
8154
|
+
*/
|
|
8155
|
+
function biguintToCbor(value) {
|
|
8156
|
+
if (value < 0n) throw new CborError({ type: "OutOfRange" });
|
|
8157
|
+
return toTaggedValue(TAG_2_POSITIVE_BIGNUM, stripLeadingZeros(bigintToBytes(value)));
|
|
8158
|
+
}
|
|
8159
|
+
/**
|
|
8160
|
+
* Encode a bigint as a CBOR tag 2 or tag 3 bignum.
|
|
8161
|
+
*
|
|
8162
|
+
* Matches Rust's `From<BigInt> for CBOR`.
|
|
8163
|
+
*
|
|
8164
|
+
* - Non-negative values use tag 2 (positive bignum).
|
|
8165
|
+
* - Negative values use tag 3 (negative bignum), where the encoded
|
|
8166
|
+
* magnitude is `|value| - 1` per RFC 8949.
|
|
8167
|
+
*
|
|
8168
|
+
* @param value - Any bigint value
|
|
8169
|
+
* @returns CBOR tagged value
|
|
8170
|
+
*/
|
|
8171
|
+
function bigintToCbor(value) {
|
|
8172
|
+
if (value >= 0n) return biguintToCbor(value);
|
|
8173
|
+
const stripped = stripLeadingZeros(bigintToBytes(-value - 1n));
|
|
8174
|
+
return toTaggedValue(TAG_3_NEGATIVE_BIGNUM, stripped.length === 0 ? new Uint8Array([0]) : stripped);
|
|
8175
|
+
}
|
|
8176
|
+
/**
|
|
8177
|
+
* Decode a BigUint from an untagged CBOR byte string.
|
|
8178
|
+
*
|
|
8179
|
+
* Matches Rust's `biguint_from_untagged_cbor()`.
|
|
8180
|
+
*
|
|
8181
|
+
* This function is intended for use in tag summarizers where the tag has
|
|
8182
|
+
* already been stripped. It expects a CBOR byte string representing the
|
|
8183
|
+
* big-endian magnitude of a positive bignum (tag 2 content).
|
|
8184
|
+
*
|
|
8185
|
+
* Enforces canonical encoding: no leading zero bytes (except empty for zero).
|
|
8186
|
+
*
|
|
8187
|
+
* @param cbor - A CBOR value that should be a byte string
|
|
8188
|
+
* @returns Non-negative bigint
|
|
8189
|
+
* @throws CborError with type WrongType if not a byte string
|
|
8190
|
+
* @throws CborError with type NonCanonicalNumeric if encoding is non-canonical
|
|
8191
|
+
*/
|
|
8192
|
+
function biguintFromUntaggedCbor(cbor) {
|
|
8193
|
+
if (cbor.type !== MajorType.ByteString) throw new CborError({ type: "WrongType" });
|
|
8194
|
+
const bytes = cbor.value;
|
|
8195
|
+
validateBignumMagnitude(bytes, false);
|
|
8196
|
+
return bytesToBigint(bytes);
|
|
8197
|
+
}
|
|
8198
|
+
/**
|
|
8199
|
+
* Decode a BigInt from an untagged CBOR byte string for a negative bignum.
|
|
8200
|
+
*
|
|
8201
|
+
* Matches Rust's `bigint_from_negative_untagged_cbor()`.
|
|
8202
|
+
*
|
|
8203
|
+
* This function is intended for use in tag summarizers where the tag has
|
|
8204
|
+
* already been stripped. It expects a CBOR byte string representing `n` where
|
|
8205
|
+
* the actual value is `-1 - n` (tag 3 content per RFC 8949).
|
|
8206
|
+
*
|
|
8207
|
+
* Enforces canonical encoding: no leading zero bytes (except single `0x00`
|
|
8208
|
+
* for -1).
|
|
8209
|
+
*
|
|
8210
|
+
* @param cbor - A CBOR value that should be a byte string
|
|
8211
|
+
* @returns Negative bigint
|
|
8212
|
+
* @throws CborError with type WrongType if not a byte string
|
|
8213
|
+
* @throws CborError with type NonCanonicalNumeric if encoding is non-canonical
|
|
8214
|
+
*/
|
|
8215
|
+
function bigintFromNegativeUntaggedCbor(cbor) {
|
|
8216
|
+
if (cbor.type !== MajorType.ByteString) throw new CborError({ type: "WrongType" });
|
|
8217
|
+
const bytes = cbor.value;
|
|
8218
|
+
validateBignumMagnitude(bytes, true);
|
|
8219
|
+
return -(bytesToBigint(bytes) + 1n);
|
|
8220
|
+
}
|
|
8221
|
+
/**
|
|
8222
|
+
* Convert CBOR to a non-negative bigint.
|
|
8223
|
+
*
|
|
8224
|
+
* Matches Rust's `TryFrom<CBOR> for BigUint`.
|
|
8225
|
+
*
|
|
8226
|
+
* Accepts:
|
|
8227
|
+
* - Major type 0 (unsigned integer)
|
|
8228
|
+
* - Tag 2 (positive bignum) with canonical byte string
|
|
8229
|
+
*
|
|
8230
|
+
* Rejects:
|
|
8231
|
+
* - Major type 1 (negative integer) -> OutOfRange
|
|
8232
|
+
* - Tag 3 (negative bignum) -> OutOfRange
|
|
8233
|
+
* - Floating-point values -> WrongType
|
|
8234
|
+
* - Non-canonical bignum encodings -> NonCanonicalNumeric
|
|
8235
|
+
*
|
|
8236
|
+
* @param cbor - The CBOR value to convert
|
|
8237
|
+
* @returns Non-negative bigint
|
|
8238
|
+
* @throws CborError
|
|
8239
|
+
*/
|
|
8240
|
+
function cborToBiguint(cbor) {
|
|
8241
|
+
switch (cbor.type) {
|
|
8242
|
+
case MajorType.Unsigned: return BigInt(cbor.value);
|
|
8243
|
+
case MajorType.Negative: throw new CborError({ type: "OutOfRange" });
|
|
8244
|
+
case MajorType.Tagged: {
|
|
8245
|
+
const tagValue = Number(cbor.tag);
|
|
8246
|
+
if (tagValue === TAG_2_POSITIVE_BIGNUM) {
|
|
8247
|
+
const inner = cbor.value;
|
|
8248
|
+
if (inner.type !== MajorType.ByteString) throw new CborError({ type: "WrongType" });
|
|
8249
|
+
const bytes = inner.value;
|
|
8250
|
+
validateBignumMagnitude(bytes, false);
|
|
8251
|
+
return bytesToBigint(bytes);
|
|
8252
|
+
} else if (tagValue === TAG_3_NEGATIVE_BIGNUM) throw new CborError({ type: "OutOfRange" });
|
|
8253
|
+
throw new CborError({ type: "WrongType" });
|
|
8254
|
+
}
|
|
8255
|
+
case MajorType.ByteString:
|
|
8256
|
+
case MajorType.Text:
|
|
8257
|
+
case MajorType.Array:
|
|
8258
|
+
case MajorType.Map:
|
|
8259
|
+
case MajorType.Simple: throw new CborError({ type: "WrongType" });
|
|
8260
|
+
}
|
|
8261
|
+
}
|
|
8262
|
+
/**
|
|
8263
|
+
* Convert CBOR to a bigint (any sign).
|
|
8264
|
+
*
|
|
8265
|
+
* Matches Rust's `TryFrom<CBOR> for BigInt`.
|
|
8266
|
+
*
|
|
8267
|
+
* Accepts:
|
|
8268
|
+
* - Major type 0 (unsigned integer)
|
|
8269
|
+
* - Major type 1 (negative integer)
|
|
8270
|
+
* - Tag 2 (positive bignum) with canonical byte string
|
|
8271
|
+
* - Tag 3 (negative bignum) with canonical byte string
|
|
8272
|
+
*
|
|
8273
|
+
* Rejects:
|
|
8274
|
+
* - Floating-point values -> WrongType
|
|
8275
|
+
* - Non-canonical bignum encodings -> NonCanonicalNumeric
|
|
8276
|
+
*
|
|
8277
|
+
* @param cbor - The CBOR value to convert
|
|
8278
|
+
* @returns A bigint value
|
|
8279
|
+
* @throws CborError
|
|
8280
|
+
*/
|
|
8281
|
+
function cborToBigint(cbor) {
|
|
8282
|
+
switch (cbor.type) {
|
|
8283
|
+
case MajorType.Unsigned: return BigInt(cbor.value);
|
|
8284
|
+
case MajorType.Negative: return -(BigInt(cbor.value) + 1n);
|
|
8285
|
+
case MajorType.Tagged: {
|
|
8286
|
+
const tagValue = Number(cbor.tag);
|
|
8287
|
+
if (tagValue === TAG_2_POSITIVE_BIGNUM) {
|
|
8288
|
+
const inner = cbor.value;
|
|
8289
|
+
if (inner.type !== MajorType.ByteString) throw new CborError({ type: "WrongType" });
|
|
8290
|
+
const bytes = inner.value;
|
|
8291
|
+
validateBignumMagnitude(bytes, false);
|
|
8292
|
+
const mag = bytesToBigint(bytes);
|
|
8293
|
+
if (mag === 0n) return 0n;
|
|
8294
|
+
return mag;
|
|
8295
|
+
} else if (tagValue === TAG_3_NEGATIVE_BIGNUM) {
|
|
8296
|
+
const inner = cbor.value;
|
|
8297
|
+
if (inner.type !== MajorType.ByteString) throw new CborError({ type: "WrongType" });
|
|
8298
|
+
const bytes = inner.value;
|
|
8299
|
+
validateBignumMagnitude(bytes, true);
|
|
8300
|
+
return -(bytesToBigint(bytes) + 1n);
|
|
8301
|
+
}
|
|
8302
|
+
throw new CborError({ type: "WrongType" });
|
|
8303
|
+
}
|
|
8304
|
+
case MajorType.ByteString:
|
|
8305
|
+
case MajorType.Text:
|
|
8306
|
+
case MajorType.Array:
|
|
8307
|
+
case MajorType.Map:
|
|
8308
|
+
case MajorType.Simple: throw new CborError({ type: "WrongType" });
|
|
8309
|
+
}
|
|
8310
|
+
}
|
|
8311
|
+
|
|
8050
8312
|
//#endregion
|
|
8051
8313
|
//#region src/tags.ts
|
|
8052
8314
|
/**
|
|
@@ -8076,6 +8338,16 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8076
8338
|
*/
|
|
8077
8339
|
const TAG_NEGATIVE_BIGNUM = 3;
|
|
8078
8340
|
/**
|
|
8341
|
+
* Name for tag 2 (positive bignum).
|
|
8342
|
+
* Matches Rust's `TAG_NAME_POSITIVE_BIGNUM`.
|
|
8343
|
+
*/
|
|
8344
|
+
const TAG_NAME_POSITIVE_BIGNUM = "positive-bignum";
|
|
8345
|
+
/**
|
|
8346
|
+
* Name for tag 3 (negative bignum).
|
|
8347
|
+
* Matches Rust's `TAG_NAME_NEGATIVE_BIGNUM`.
|
|
8348
|
+
*/
|
|
8349
|
+
const TAG_NAME_NEGATIVE_BIGNUM = "negative-bignum";
|
|
8350
|
+
/**
|
|
8079
8351
|
* Tag 4: Decimal fraction [exponent, mantissa]
|
|
8080
8352
|
*/
|
|
8081
8353
|
const TAG_DECIMAL_FRACTION = 4;
|
|
@@ -8166,6 +8438,41 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8166
8438
|
};
|
|
8167
8439
|
}
|
|
8168
8440
|
});
|
|
8441
|
+
const biguintTag = createTag(TAG_POSITIVE_BIGNUM, TAG_NAME_POSITIVE_BIGNUM);
|
|
8442
|
+
const bigintTag = createTag(TAG_NEGATIVE_BIGNUM, TAG_NAME_NEGATIVE_BIGNUM);
|
|
8443
|
+
tagsStore.insertAll([biguintTag, bigintTag]);
|
|
8444
|
+
tagsStore.setSummarizer(TAG_POSITIVE_BIGNUM, (untaggedCbor, _flat) => {
|
|
8445
|
+
try {
|
|
8446
|
+
return {
|
|
8447
|
+
ok: true,
|
|
8448
|
+
value: `bignum(${biguintFromUntaggedCbor(untaggedCbor)})`
|
|
8449
|
+
};
|
|
8450
|
+
} catch (e) {
|
|
8451
|
+
return {
|
|
8452
|
+
ok: false,
|
|
8453
|
+
error: {
|
|
8454
|
+
type: "Custom",
|
|
8455
|
+
message: e instanceof Error ? e.message : String(e)
|
|
8456
|
+
}
|
|
8457
|
+
};
|
|
8458
|
+
}
|
|
8459
|
+
});
|
|
8460
|
+
tagsStore.setSummarizer(TAG_NEGATIVE_BIGNUM, (untaggedCbor, _flat) => {
|
|
8461
|
+
try {
|
|
8462
|
+
return {
|
|
8463
|
+
ok: true,
|
|
8464
|
+
value: `bignum(${bigintFromNegativeUntaggedCbor(untaggedCbor)})`
|
|
8465
|
+
};
|
|
8466
|
+
} catch (e) {
|
|
8467
|
+
return {
|
|
8468
|
+
ok: false,
|
|
8469
|
+
error: {
|
|
8470
|
+
type: "Custom",
|
|
8471
|
+
message: e instanceof Error ? e.message : String(e)
|
|
8472
|
+
}
|
|
8473
|
+
};
|
|
8474
|
+
}
|
|
8475
|
+
});
|
|
8169
8476
|
};
|
|
8170
8477
|
/**
|
|
8171
8478
|
* Register standard tags in the global tags store.
|
|
@@ -8249,9 +8556,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8249
8556
|
* ```
|
|
8250
8557
|
*/
|
|
8251
8558
|
var CborSet = class CborSet {
|
|
8252
|
-
|
|
8559
|
+
_map;
|
|
8253
8560
|
constructor() {
|
|
8254
|
-
this
|
|
8561
|
+
this._map = new CborMap();
|
|
8255
8562
|
}
|
|
8256
8563
|
/**
|
|
8257
8564
|
* Create CborSet from array.
|
|
@@ -8313,7 +8620,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8313
8620
|
*/
|
|
8314
8621
|
insert(value) {
|
|
8315
8622
|
const cborValue = encodeCborValue(value);
|
|
8316
|
-
this
|
|
8623
|
+
this._map.set(cborValue, cborValue);
|
|
8317
8624
|
}
|
|
8318
8625
|
/**
|
|
8319
8626
|
* Check if set contains an element.
|
|
@@ -8330,7 +8637,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8330
8637
|
*/
|
|
8331
8638
|
contains(value) {
|
|
8332
8639
|
const cborValue = encodeCborValue(value);
|
|
8333
|
-
return this
|
|
8640
|
+
return this._map.has(cborValue);
|
|
8334
8641
|
}
|
|
8335
8642
|
/**
|
|
8336
8643
|
* Remove an element from the set.
|
|
@@ -8347,13 +8654,13 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8347
8654
|
*/
|
|
8348
8655
|
delete(value) {
|
|
8349
8656
|
const cborValue = encodeCborValue(value);
|
|
8350
|
-
return this
|
|
8657
|
+
return this._map.delete(cborValue);
|
|
8351
8658
|
}
|
|
8352
8659
|
/**
|
|
8353
8660
|
* Remove all elements from the set.
|
|
8354
8661
|
*/
|
|
8355
8662
|
clear() {
|
|
8356
|
-
this
|
|
8663
|
+
this._map.clear();
|
|
8357
8664
|
}
|
|
8358
8665
|
/**
|
|
8359
8666
|
* Get the number of elements in the set.
|
|
@@ -8361,7 +8668,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8361
8668
|
* @returns Number of elements
|
|
8362
8669
|
*/
|
|
8363
8670
|
get size() {
|
|
8364
|
-
return this
|
|
8671
|
+
return this._map.size;
|
|
8365
8672
|
}
|
|
8366
8673
|
/**
|
|
8367
8674
|
* Check if the set is empty.
|
|
@@ -8369,7 +8676,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8369
8676
|
* @returns true if set has no elements
|
|
8370
8677
|
*/
|
|
8371
8678
|
isEmpty() {
|
|
8372
|
-
return this
|
|
8679
|
+
return this._map.size === 0;
|
|
8373
8680
|
}
|
|
8374
8681
|
/**
|
|
8375
8682
|
* Create a new set containing elements in this set or the other set.
|
|
@@ -8468,7 +8775,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8468
8775
|
* ```
|
|
8469
8776
|
*/
|
|
8470
8777
|
*[Symbol.iterator]() {
|
|
8471
|
-
for (const [_, value] of this
|
|
8778
|
+
for (const [_, value] of this._map) yield value;
|
|
8472
8779
|
}
|
|
8473
8780
|
/**
|
|
8474
8781
|
* Get all values as an array.
|
|
@@ -8526,8 +8833,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8526
8833
|
* @param cbor - Tagged CBOR value with tag(258)
|
|
8527
8834
|
* @returns Decoded CborSet instance
|
|
8528
8835
|
*/
|
|
8529
|
-
static fromTaggedCborStatic(cbor
|
|
8530
|
-
return new CborSet().fromTaggedCbor(cbor
|
|
8836
|
+
static fromTaggedCborStatic(cbor) {
|
|
8837
|
+
return new CborSet().fromTaggedCbor(cbor);
|
|
8531
8838
|
}
|
|
8532
8839
|
/**
|
|
8533
8840
|
* Convert to CBOR array (untagged).
|
|
@@ -8659,7 +8966,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8659
8966
|
* ```
|
|
8660
8967
|
*/
|
|
8661
8968
|
var ByteString = class ByteString {
|
|
8662
|
-
|
|
8969
|
+
_data;
|
|
8663
8970
|
/**
|
|
8664
8971
|
* Creates a new `ByteString` from a Uint8Array or array of bytes.
|
|
8665
8972
|
*
|
|
@@ -8675,8 +8982,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8675
8982
|
* ```
|
|
8676
8983
|
*/
|
|
8677
8984
|
constructor(data) {
|
|
8678
|
-
if (Array.isArray(data)) this
|
|
8679
|
-
else this
|
|
8985
|
+
if (Array.isArray(data)) this._data = new Uint8Array(data);
|
|
8986
|
+
else this._data = new Uint8Array(data);
|
|
8680
8987
|
}
|
|
8681
8988
|
/**
|
|
8682
8989
|
* Creates a new `ByteString` from various input types.
|
|
@@ -8710,7 +9017,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8710
9017
|
* ```
|
|
8711
9018
|
*/
|
|
8712
9019
|
data() {
|
|
8713
|
-
return this
|
|
9020
|
+
return this._data;
|
|
8714
9021
|
}
|
|
8715
9022
|
/**
|
|
8716
9023
|
* Returns the length of the byte string in bytes.
|
|
@@ -8727,7 +9034,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8727
9034
|
* ```
|
|
8728
9035
|
*/
|
|
8729
9036
|
len() {
|
|
8730
|
-
return this
|
|
9037
|
+
return this._data.length;
|
|
8731
9038
|
}
|
|
8732
9039
|
/**
|
|
8733
9040
|
* Returns `true` if the byte string contains no bytes.
|
|
@@ -8744,7 +9051,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8744
9051
|
* ```
|
|
8745
9052
|
*/
|
|
8746
9053
|
isEmpty() {
|
|
8747
|
-
return this
|
|
9054
|
+
return this._data.length === 0;
|
|
8748
9055
|
}
|
|
8749
9056
|
/**
|
|
8750
9057
|
* Extends the byte string with additional bytes.
|
|
@@ -8764,10 +9071,10 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8764
9071
|
*/
|
|
8765
9072
|
extend(other) {
|
|
8766
9073
|
const otherArray = Array.isArray(other) ? new Uint8Array(other) : other;
|
|
8767
|
-
const newData = new Uint8Array(this
|
|
8768
|
-
newData.set(this
|
|
8769
|
-
newData.set(otherArray, this
|
|
8770
|
-
this
|
|
9074
|
+
const newData = new Uint8Array(this._data.length + otherArray.length);
|
|
9075
|
+
newData.set(this._data, 0);
|
|
9076
|
+
newData.set(otherArray, this._data.length);
|
|
9077
|
+
this._data = newData;
|
|
8771
9078
|
}
|
|
8772
9079
|
/**
|
|
8773
9080
|
* Creates a new Uint8Array containing a copy of the byte string's data.
|
|
@@ -8787,7 +9094,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8787
9094
|
* ```
|
|
8788
9095
|
*/
|
|
8789
9096
|
toUint8Array() {
|
|
8790
|
-
return new Uint8Array(this
|
|
9097
|
+
return new Uint8Array(this._data);
|
|
8791
9098
|
}
|
|
8792
9099
|
/**
|
|
8793
9100
|
* Returns an iterator over the bytes in the byte string.
|
|
@@ -8813,7 +9120,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8813
9120
|
* ```
|
|
8814
9121
|
*/
|
|
8815
9122
|
iter() {
|
|
8816
|
-
return this
|
|
9123
|
+
return this._data.values();
|
|
8817
9124
|
}
|
|
8818
9125
|
/**
|
|
8819
9126
|
* Makes ByteString iterable.
|
|
@@ -8833,7 +9140,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8833
9140
|
* ```
|
|
8834
9141
|
*/
|
|
8835
9142
|
toCbor() {
|
|
8836
|
-
return cbor(this
|
|
9143
|
+
return cbor(this._data);
|
|
8837
9144
|
}
|
|
8838
9145
|
/**
|
|
8839
9146
|
* Attempts to convert a CBOR value into a ByteString.
|
|
@@ -8857,9 +9164,9 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8857
9164
|
* }
|
|
8858
9165
|
* ```
|
|
8859
9166
|
*/
|
|
8860
|
-
static fromCbor(cbor
|
|
8861
|
-
if (cbor
|
|
8862
|
-
return new ByteString(cbor
|
|
9167
|
+
static fromCbor(cbor) {
|
|
9168
|
+
if (cbor.type !== MajorType.ByteString) throw new CborError({ type: "WrongType" });
|
|
9169
|
+
return new ByteString(cbor.value);
|
|
8863
9170
|
}
|
|
8864
9171
|
/**
|
|
8865
9172
|
* Get element at index.
|
|
@@ -8868,7 +9175,7 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8868
9175
|
* @returns Byte at index or undefined
|
|
8869
9176
|
*/
|
|
8870
9177
|
at(index) {
|
|
8871
|
-
return this
|
|
9178
|
+
return this._data[index];
|
|
8872
9179
|
}
|
|
8873
9180
|
/**
|
|
8874
9181
|
* Equality comparison.
|
|
@@ -8877,8 +9184,8 @@ var import_byte_data = /* @__PURE__ */ __toESM(require_byte_data());
|
|
|
8877
9184
|
* @returns true if equal
|
|
8878
9185
|
*/
|
|
8879
9186
|
equals(other) {
|
|
8880
|
-
if (this
|
|
8881
|
-
for (let i = 0; i < this
|
|
9187
|
+
if (this._data.length !== other._data.length) return false;
|
|
9188
|
+
for (let i = 0; i < this._data.length; i++) if (this._data[i] !== other._data[i]) return false;
|
|
8882
9189
|
return true;
|
|
8883
9190
|
}
|
|
8884
9191
|
/**
|
|
@@ -8916,6 +9223,8 @@ exports.TAG_EPOCH_DATE = TAG_EPOCH_DATE;
|
|
|
8916
9223
|
exports.TAG_EPOCH_DATE_TIME = TAG_EPOCH_DATE_TIME;
|
|
8917
9224
|
exports.TAG_MIME_MESSAGE = TAG_MIME_MESSAGE;
|
|
8918
9225
|
exports.TAG_NAME_DATE = TAG_NAME_DATE;
|
|
9226
|
+
exports.TAG_NAME_NEGATIVE_BIGNUM = TAG_NAME_NEGATIVE_BIGNUM;
|
|
9227
|
+
exports.TAG_NAME_POSITIVE_BIGNUM = TAG_NAME_POSITIVE_BIGNUM;
|
|
8919
9228
|
exports.TAG_NEGATIVE_BIGNUM = TAG_NEGATIVE_BIGNUM;
|
|
8920
9229
|
exports.TAG_POSITIVE_BIGNUM = TAG_POSITIVE_BIGNUM;
|
|
8921
9230
|
exports.TAG_REGEXP = TAG_REGEXP;
|
|
@@ -8944,9 +9253,15 @@ exports.asSingle = asSingle;
|
|
|
8944
9253
|
exports.asTaggedValue = asTaggedValue;
|
|
8945
9254
|
exports.asText = asText;
|
|
8946
9255
|
exports.asUnsigned = asUnsigned;
|
|
9256
|
+
exports.bigintFromNegativeUntaggedCbor = bigintFromNegativeUntaggedCbor;
|
|
9257
|
+
exports.bigintToCbor = bigintToCbor;
|
|
9258
|
+
exports.biguintFromUntaggedCbor = biguintFromUntaggedCbor;
|
|
9259
|
+
exports.biguintToCbor = biguintToCbor;
|
|
8947
9260
|
exports.bytesToHex = bytesToHex;
|
|
8948
9261
|
exports.cbor = cbor;
|
|
8949
9262
|
exports.cborData = cborData;
|
|
9263
|
+
exports.cborToBigint = cborToBigint;
|
|
9264
|
+
exports.cborToBiguint = cborToBiguint;
|
|
8950
9265
|
exports.createTag = createTag;
|
|
8951
9266
|
exports.createTaggedCbor = createTaggedCbor;
|
|
8952
9267
|
exports.decodeCbor = decodeCbor;
|