omnipin 2.0.4 → 2.1.1
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/dist/index.js +281 -204
- package/package.json +5 -6
package/dist/index.js
CHANGED
|
@@ -776,13 +776,7 @@ function Signature_toHex(signature) {
|
|
|
776
776
|
size: 32
|
|
777
777
|
}), fromNumber(s, {
|
|
778
778
|
size: 32
|
|
779
|
-
}), 'number' == typeof signature.yParity ? fromNumber(
|
|
780
|
-
if (0 === yParity) return 27;
|
|
781
|
-
if (1 === yParity) return 28;
|
|
782
|
-
throw new InvalidYParityError({
|
|
783
|
-
value: yParity
|
|
784
|
-
});
|
|
785
|
-
}(signature.yParity), {
|
|
779
|
+
}), 'number' == typeof signature.yParity ? fromNumber(yParityToV(signature.yParity), {
|
|
786
780
|
size: 1
|
|
787
781
|
}) : '0x');
|
|
788
782
|
}
|
|
@@ -794,6 +788,13 @@ function vToYParity(v) {
|
|
|
794
788
|
value: v
|
|
795
789
|
});
|
|
796
790
|
}
|
|
791
|
+
function yParityToV(yParity) {
|
|
792
|
+
if (0 === yParity) return 27;
|
|
793
|
+
if (1 === yParity) return 28;
|
|
794
|
+
throw new InvalidYParityError({
|
|
795
|
+
value: yParity
|
|
796
|
+
});
|
|
797
|
+
}
|
|
797
798
|
function Value_format(value, decimals = 0) {
|
|
798
799
|
let display = value.toString(), negative = display.startsWith('-');
|
|
799
800
|
negative && (display = display.slice(1));
|
|
@@ -818,14 +819,30 @@ function coerce(o) {
|
|
|
818
819
|
if (ArrayBuffer.isView(o)) return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
819
820
|
throw Error('Unknown type, must be binary type');
|
|
820
821
|
}
|
|
821
|
-
function
|
|
822
|
+
function is_is(value) {
|
|
823
|
+
if (null === value) return 'null';
|
|
824
|
+
if (void 0 === value) return 'undefined';
|
|
825
|
+
if (!0 === value || !1 === value) return 'boolean';
|
|
826
|
+
let typeOf = typeof value;
|
|
827
|
+
if ('string' === typeOf || 'number' === typeOf || 'bigint' === typeOf || 'symbol' === typeOf) return typeOf;
|
|
828
|
+
if ('function' === typeOf) return 'Function';
|
|
829
|
+
if (Array.isArray(value)) return 'Array';
|
|
830
|
+
if (value instanceof Uint8Array) return 'Uint8Array';
|
|
831
|
+
if (value.constructor === Object) return 'Object';
|
|
832
|
+
let objectType = function(value) {
|
|
833
|
+
let objectTypeName = Object.prototype.toString.call(value).slice(8, -1);
|
|
834
|
+
if (objectTypeNames.includes(objectTypeName)) return objectTypeName;
|
|
835
|
+
}(value);
|
|
836
|
+
return objectType || 'Object';
|
|
837
|
+
}
|
|
838
|
+
function isBuffer(buf) {
|
|
822
839
|
return useBuffer && globalThis.Buffer.isBuffer(buf);
|
|
823
840
|
}
|
|
824
841
|
function asU8A(buf) {
|
|
825
|
-
return buf instanceof Uint8Array ?
|
|
842
|
+
return buf instanceof Uint8Array ? isBuffer(buf) ? new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength) : buf : Uint8Array.from(buf);
|
|
826
843
|
}
|
|
827
844
|
function compare(b1, b2) {
|
|
828
|
-
if (
|
|
845
|
+
if (isBuffer(b1) && isBuffer(b2)) return b1.compare(b2);
|
|
829
846
|
for(let i = 0; i < b1.length; i++)if (b1[i] !== b2[i]) return b1[i] < b2[i] ? -1 : 1;
|
|
830
847
|
return 0;
|
|
831
848
|
}
|
|
@@ -833,41 +850,10 @@ function byte_utils_utf8ToBytes(str) {
|
|
|
833
850
|
let out = [], p = 0;
|
|
834
851
|
for(let i = 0; i < str.length; i++){
|
|
835
852
|
let c = str.charCodeAt(i);
|
|
836
|
-
c < 128 ? out[p++] = c : (c < 2048 ? out[p++] = c >> 6 | 192 : ((0xFC00 & c) == 0xD800 && i + 1 < str.length && (0xFC00 & str.charCodeAt(i + 1)) == 0xDC00 ? (c = 0x10000 + ((0x03FF & c) << 10) + (0x03FF & str.charCodeAt(++i)), out[p++] = c >> 18 | 240, out[p++] = c >> 12 & 63 | 128) : out[p++] = c >> 12 | 224, out[p++] = c >> 6 & 63 | 128), out[p++] = 63 & c | 128);
|
|
853
|
+
c < 128 ? out[p++] = c : (c < 2048 ? out[p++] = c >> 6 | 192 : ((0xFC00 & c) == 0xD800 && i + 1 < str.length && (0xFC00 & str.charCodeAt(i + 1)) == 0xDC00 ? (c = 0x10000 + ((0x03FF & c) << 10) + (0x03FF & str.charCodeAt(++i)), out[p++] = c >> 18 | 240, out[p++] = c >> 12 & 63 | 128) : (c >= 0xD800 && c <= 0xDFFF && (c = 0xFFFD), out[p++] = c >> 12 | 224), out[p++] = c >> 6 & 63 | 128), out[p++] = 63 & c | 128);
|
|
837
854
|
}
|
|
838
855
|
return out;
|
|
839
856
|
}
|
|
840
|
-
function utf8Slice(buf, offset, end) {
|
|
841
|
-
let res = [];
|
|
842
|
-
for(; offset < end;){
|
|
843
|
-
let firstByte = buf[offset], codePoint = null, bytesPerSequence = firstByte > 0xef ? 4 : firstByte > 0xdf ? 3 : firstByte > 0xbf ? 2 : 1;
|
|
844
|
-
if (offset + bytesPerSequence <= end) {
|
|
845
|
-
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
846
|
-
switch(bytesPerSequence){
|
|
847
|
-
case 1:
|
|
848
|
-
firstByte < 0x80 && (codePoint = firstByte);
|
|
849
|
-
break;
|
|
850
|
-
case 2:
|
|
851
|
-
(0xc0 & (secondByte = buf[offset + 1])) == 0x80 && (tempCodePoint = (0x1f & firstByte) << 0x6 | 0x3f & secondByte) > 0x7f && (codePoint = tempCodePoint);
|
|
852
|
-
break;
|
|
853
|
-
case 3:
|
|
854
|
-
secondByte = buf[offset + 1], thirdByte = buf[offset + 2], (0xc0 & secondByte) == 0x80 && (0xc0 & thirdByte) == 0x80 && (tempCodePoint = (0xf & firstByte) << 0xc | (0x3f & secondByte) << 0x6 | 0x3f & thirdByte) > 0x7ff && (tempCodePoint < 0xd800 || tempCodePoint > 0xdfff) && (codePoint = tempCodePoint);
|
|
855
|
-
break;
|
|
856
|
-
case 4:
|
|
857
|
-
secondByte = buf[offset + 1], thirdByte = buf[offset + 2], fourthByte = buf[offset + 3], (0xc0 & secondByte) == 0x80 && (0xc0 & thirdByte) == 0x80 && (0xc0 & fourthByte) == 0x80 && (tempCodePoint = (0xf & firstByte) << 0x12 | (0x3f & secondByte) << 0xc | (0x3f & thirdByte) << 0x6 | 0x3f & fourthByte) > 0xffff && tempCodePoint < 0x110000 && (codePoint = tempCodePoint);
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
null === codePoint ? (codePoint = 0xfffd, bytesPerSequence = 1) : codePoint > 0xffff && (codePoint -= 0x10000, res.push(codePoint >>> 10 & 0x3ff | 0xd800), codePoint = 0xdc00 | 0x3ff & codePoint), res.push(codePoint), offset += bytesPerSequence;
|
|
861
|
-
}
|
|
862
|
-
return decodeCodePointsArray(res);
|
|
863
|
-
}
|
|
864
|
-
function decodeCodePointsArray(codePoints) {
|
|
865
|
-
let len = codePoints.length;
|
|
866
|
-
if (len <= MAX_ARGUMENTS_LENGTH) return String.fromCharCode.apply(String, codePoints);
|
|
867
|
-
let res = '', i = 0;
|
|
868
|
-
for(; i < len;)res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
|
|
869
|
-
return res;
|
|
870
|
-
}
|
|
871
857
|
function assertEnoughData(data, pos, need) {
|
|
872
858
|
if (data.length - pos < need) throw Error(`${decodeErrPrefix} not enough data for type`);
|
|
873
859
|
}
|
|
@@ -897,31 +883,31 @@ function readUint64(data, offset, options) {
|
|
|
897
883
|
if (!0 === options.allowBigInt) return value;
|
|
898
884
|
throw Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`);
|
|
899
885
|
}
|
|
900
|
-
function encodeUint(
|
|
901
|
-
return encodeUintValue(
|
|
886
|
+
function encodeUint(writer, token) {
|
|
887
|
+
return encodeUintValue(writer, 0, token.value);
|
|
902
888
|
}
|
|
903
|
-
function encodeUintValue(
|
|
889
|
+
function encodeUintValue(writer, major, uint) {
|
|
904
890
|
if (uint < uintBoundaries[0]) {
|
|
905
891
|
let nuint = Number(uint);
|
|
906
|
-
|
|
892
|
+
writer.push([
|
|
907
893
|
major | nuint
|
|
908
894
|
]);
|
|
909
895
|
} else if (uint < uintBoundaries[1]) {
|
|
910
896
|
let nuint = Number(uint);
|
|
911
|
-
|
|
897
|
+
writer.push([
|
|
912
898
|
24 | major,
|
|
913
899
|
nuint
|
|
914
900
|
]);
|
|
915
901
|
} else if (uint < uintBoundaries[2]) {
|
|
916
902
|
let nuint = Number(uint);
|
|
917
|
-
|
|
903
|
+
writer.push([
|
|
918
904
|
25 | major,
|
|
919
905
|
nuint >>> 8,
|
|
920
906
|
0xff & nuint
|
|
921
907
|
]);
|
|
922
908
|
} else if (uint < uintBoundaries[3]) {
|
|
923
909
|
let nuint = Number(uint);
|
|
924
|
-
|
|
910
|
+
writer.push([
|
|
925
911
|
26 | major,
|
|
926
912
|
nuint >>> 24 & 0xff,
|
|
927
913
|
nuint >>> 16 & 0xff,
|
|
@@ -941,34 +927,45 @@ function encodeUintValue(buf, major, uint) {
|
|
|
941
927
|
0,
|
|
942
928
|
0
|
|
943
929
|
], lo = Number(buint & BigInt(0xffffffff)), hi = Number(buint >> BigInt(32) & BigInt(0xffffffff));
|
|
944
|
-
set[8] = 0xff & lo, lo >>= 8, set[7] = 0xff & lo, lo >>= 8, set[6] = 0xff & lo, lo >>= 8, set[5] = 0xff & lo, set[4] = 0xff & hi, hi >>= 8, set[3] = 0xff & hi, hi >>= 8, set[2] = 0xff & hi, hi >>= 8, set[1] = 0xff & hi,
|
|
930
|
+
set[8] = 0xff & lo, lo >>= 8, set[7] = 0xff & lo, lo >>= 8, set[6] = 0xff & lo, lo >>= 8, set[5] = 0xff & lo, set[4] = 0xff & hi, hi >>= 8, set[3] = 0xff & hi, hi >>= 8, set[2] = 0xff & hi, hi >>= 8, set[1] = 0xff & hi, writer.push(set);
|
|
945
931
|
} else throw Error(`${decodeErrPrefix} encountered BigInt larger than allowable range`);
|
|
946
932
|
}
|
|
947
933
|
}
|
|
948
|
-
function encodeNegint(
|
|
934
|
+
function encodeNegint(writer, token) {
|
|
949
935
|
let negint = token.value;
|
|
950
|
-
encodeUintValue(
|
|
936
|
+
encodeUintValue(writer, token.type.majorEncoded, 'bigint' == typeof negint ? negint * neg1b - pos1b : -1 * negint - 1);
|
|
951
937
|
}
|
|
952
938
|
function toToken(data, pos, prefix, length) {
|
|
953
939
|
assertEnoughData(data, pos, prefix + length);
|
|
954
|
-
let buf =
|
|
940
|
+
let buf = data.slice(pos + prefix, pos + prefix + length);
|
|
955
941
|
return new Token(Type.bytes, buf, prefix + length);
|
|
956
942
|
}
|
|
957
943
|
function decodeBytesCompact(data, pos, minor) {
|
|
958
944
|
return toToken(data, pos, 1, minor);
|
|
959
945
|
}
|
|
960
946
|
function tokenBytes(token) {
|
|
961
|
-
return void 0 === token.encodedBytes && (token.encodedBytes = token.type
|
|
947
|
+
return void 0 === token.encodedBytes && (token.encodedBytes = Type.equals(token.type, Type.string) ? byte_utils_fromString(token.value) : token.value), token.encodedBytes;
|
|
962
948
|
}
|
|
963
|
-
function encodeBytes(
|
|
949
|
+
function encodeBytes(writer, token) {
|
|
964
950
|
let bytes = tokenBytes(token);
|
|
965
|
-
encodeUintValue(
|
|
951
|
+
encodeUintValue(writer, token.type.majorEncoded, bytes.length), writer.push(bytes);
|
|
966
952
|
}
|
|
967
953
|
function _3string_toToken(data, pos, prefix, length, options) {
|
|
968
954
|
let totLength = prefix + length;
|
|
969
955
|
assertEnoughData(data, pos, totLength);
|
|
970
|
-
let tok = new Token(Type.string,
|
|
971
|
-
|
|
956
|
+
let tok = new Token(Type.string, function(bytes, start, end) {
|
|
957
|
+
if (end - start < ASCII_THRESHOLD) {
|
|
958
|
+
let str = '';
|
|
959
|
+
for(let i = start; i < end; i++){
|
|
960
|
+
let c = bytes[i];
|
|
961
|
+
if (0x80 & c) return textDecoder.decode(bytes.subarray(start, end));
|
|
962
|
+
str += String.fromCharCode(c);
|
|
963
|
+
}
|
|
964
|
+
return str;
|
|
965
|
+
}
|
|
966
|
+
return textDecoder.decode(bytes.subarray(start, end));
|
|
967
|
+
}(data, pos + prefix, pos + totLength), totLength);
|
|
968
|
+
return !0 === options.retainStringBytes && (tok.byteValue = data.slice(pos + prefix, pos + totLength)), tok;
|
|
972
969
|
}
|
|
973
970
|
function decodeStringCompact(data, pos, minor, options) {
|
|
974
971
|
return _3string_toToken(data, pos, 1, minor, options);
|
|
@@ -979,8 +976,8 @@ function _4array_toToken(_data, _pos, prefix, length) {
|
|
|
979
976
|
function decodeArrayCompact(data, pos, minor) {
|
|
980
977
|
return _4array_toToken(data, pos, 1, minor);
|
|
981
978
|
}
|
|
982
|
-
function encodeArray(
|
|
983
|
-
encodeUintValue(
|
|
979
|
+
function encodeArray(writer, token) {
|
|
980
|
+
encodeUintValue(writer, Type.array.majorEncoded, token.value);
|
|
984
981
|
}
|
|
985
982
|
function _5map_toToken(_data, _pos, prefix, length) {
|
|
986
983
|
return new Token(Type.map, length, prefix);
|
|
@@ -988,14 +985,14 @@ function _5map_toToken(_data, _pos, prefix, length) {
|
|
|
988
985
|
function decodeMapCompact(data, pos, minor) {
|
|
989
986
|
return _5map_toToken(data, pos, 1, minor);
|
|
990
987
|
}
|
|
991
|
-
function encodeMap(
|
|
992
|
-
encodeUintValue(
|
|
988
|
+
function encodeMap(writer, token) {
|
|
989
|
+
encodeUintValue(writer, Type.map.majorEncoded, token.value);
|
|
993
990
|
}
|
|
994
991
|
function decodeTagCompact(_data, _pos, minor) {
|
|
995
992
|
return new Token(Type.tag, minor, 1);
|
|
996
993
|
}
|
|
997
|
-
function encodeTag(
|
|
998
|
-
encodeUintValue(
|
|
994
|
+
function encodeTag(writer, token) {
|
|
995
|
+
encodeUintValue(writer, Type.tag.majorEncoded, token.value);
|
|
999
996
|
}
|
|
1000
997
|
function createToken(value, bytes, options) {
|
|
1001
998
|
if (options) {
|
|
@@ -1004,24 +1001,24 @@ function createToken(value, bytes, options) {
|
|
|
1004
1001
|
}
|
|
1005
1002
|
return new Token(Type.float, value, bytes);
|
|
1006
1003
|
}
|
|
1007
|
-
function encodeFloat(
|
|
1004
|
+
function encodeFloat(writer, token, options) {
|
|
1008
1005
|
let float = token.value;
|
|
1009
|
-
if (!1 === float)
|
|
1006
|
+
if (!1 === float) writer.push([
|
|
1010
1007
|
Type.float.majorEncoded | MINOR_FALSE
|
|
1011
1008
|
]);
|
|
1012
|
-
else if (!0 === float)
|
|
1009
|
+
else if (!0 === float) writer.push([
|
|
1013
1010
|
Type.float.majorEncoded | MINOR_TRUE
|
|
1014
1011
|
]);
|
|
1015
|
-
else if (null === float)
|
|
1012
|
+
else if (null === float) writer.push([
|
|
1016
1013
|
Type.float.majorEncoded | MINOR_NULL
|
|
1017
1014
|
]);
|
|
1018
|
-
else if (void 0 === float)
|
|
1015
|
+
else if (void 0 === float) writer.push([
|
|
1019
1016
|
Type.float.majorEncoded | MINOR_UNDEFINED
|
|
1020
1017
|
]);
|
|
1021
1018
|
else {
|
|
1022
1019
|
var inp;
|
|
1023
1020
|
let success = !1;
|
|
1024
|
-
options && !0 === options.float64 || (encodeFloat16(float), float === readFloat16(_7float_ui8a, 1) || Number.isNaN(float) ? (_7float_ui8a[0] = 0xf9,
|
|
1021
|
+
options && !0 === options.float64 || (encodeFloat16(float), float === readFloat16(_7float_ui8a, 1) || Number.isNaN(float) ? (_7float_ui8a[0] = 0xf9, writer.push(_7float_ui8a.slice(0, 3)), success = !0) : (encodeFloat32(float), float === readFloat32(_7float_ui8a, 1) && (_7float_ui8a[0] = 0xfa, writer.push(_7float_ui8a.slice(0, 5)), success = !0))), success || (inp = float, _7float_dataView.setFloat64(0, inp, !1), readFloat64(_7float_ui8a, 1), _7float_ui8a[0] = 0xfb, writer.push(_7float_ui8a.slice(0, 9)));
|
|
1025
1022
|
}
|
|
1026
1023
|
}
|
|
1027
1024
|
function encodeFloat16(inp) {
|
|
@@ -1120,22 +1117,7 @@ function makeCborEncoders() {
|
|
|
1120
1117
|
return encoders[Type.uint.major] = encodeUint, encoders[Type.negint.major] = encodeNegint, encoders[Type.bytes.major] = encodeBytes, encoders[Type.string.major] = encodeString, encoders[Type.array.major] = encodeArray, encoders[Type.map.major] = encodeMap, encoders[Type.tag.major] = encodeTag, encoders[Type.float.major] = encodeFloat, encoders;
|
|
1121
1118
|
}
|
|
1122
1119
|
function encode_objectToTokens(obj, options = {}, refStack) {
|
|
1123
|
-
let typ =
|
|
1124
|
-
var value1;
|
|
1125
|
-
if (null === value) return 'null';
|
|
1126
|
-
if (void 0 === value) return 'undefined';
|
|
1127
|
-
if (!0 === value || !1 === value) return 'boolean';
|
|
1128
|
-
let typeOf = typeof value;
|
|
1129
|
-
if (typeofs.includes(typeOf)) return typeOf;
|
|
1130
|
-
if ('function' === typeOf) return 'Function';
|
|
1131
|
-
if (Array.isArray(value)) return 'Array';
|
|
1132
|
-
if ((value1 = value) && value1.constructor && value1.constructor.isBuffer && value1.constructor.isBuffer.call(null, value1)) return 'Buffer';
|
|
1133
|
-
let objectType = function(value) {
|
|
1134
|
-
let objectTypeName = Object.prototype.toString.call(value).slice(8, -1);
|
|
1135
|
-
if (objectTypeNames.includes(objectTypeName)) return objectTypeName;
|
|
1136
|
-
}(value);
|
|
1137
|
-
return objectType || 'Object';
|
|
1138
|
-
}(obj), customTypeEncoder = options && options.typeEncoders && options.typeEncoders[typ] || typeEncoders[typ];
|
|
1120
|
+
let typ = is_is(obj), customTypeEncoder = options && options.typeEncoders && options.typeEncoders[typ] || typeEncoders[typ];
|
|
1139
1121
|
if ('function' == typeof customTypeEncoder) {
|
|
1140
1122
|
let tokens = customTypeEncoder(obj, typ, options, refStack);
|
|
1141
1123
|
if (null != tokens) return tokens;
|
|
@@ -1144,35 +1126,91 @@ function encode_objectToTokens(obj, options = {}, refStack) {
|
|
|
1144
1126
|
if (!typeEncoder) throw Error(`${encodeErrPrefix} unsupported type: ${typ}`);
|
|
1145
1127
|
return typeEncoder(obj, typ, options, refStack);
|
|
1146
1128
|
}
|
|
1147
|
-
function
|
|
1148
|
-
|
|
1129
|
+
function tokensToEncoded(writer, tokens, encoders, options) {
|
|
1130
|
+
if (Array.isArray(tokens)) for (let token of tokens)tokensToEncoded(writer, token, encoders, options);
|
|
1131
|
+
else encoders[tokens.type.major](writer, tokens, options);
|
|
1132
|
+
}
|
|
1133
|
+
function encodeCustom(data, encoders, options, destination) {
|
|
1134
|
+
let hasDest = destination instanceof Uint8Array, writeTo = hasDest ? new bl_U8Bl(destination) : defaultWriter, tokens = encode_objectToTokens(data, options);
|
|
1149
1135
|
if (!Array.isArray(tokens) && options.quickEncodeToken) {
|
|
1150
1136
|
let quickBytes = options.quickEncodeToken(tokens);
|
|
1151
|
-
if (quickBytes) return quickBytes;
|
|
1137
|
+
if (quickBytes) return hasDest ? (writeTo.push(quickBytes), writeTo.toBytes()) : quickBytes;
|
|
1152
1138
|
let encoder = encoders[tokens.type.major];
|
|
1153
1139
|
if (encoder.encodedSize) {
|
|
1154
|
-
let
|
|
1155
|
-
if (encoder(
|
|
1156
|
-
return asU8A(
|
|
1140
|
+
let size = encoder.encodedSize(tokens, options);
|
|
1141
|
+
if (hasDest || (writeTo = new bl_Bl(size)), encoder(writeTo, tokens, options), 1 !== writeTo.chunks.length) throw Error(`Unexpected error: pre-calculated length for ${tokens} was wrong`);
|
|
1142
|
+
return hasDest ? writeTo.toBytes() : asU8A(writeTo.chunks[0]);
|
|
1157
1143
|
}
|
|
1158
1144
|
}
|
|
1159
|
-
return
|
|
1160
|
-
if (Array.isArray(tokens)) for (let token of tokens)tokensToEncoded(buf, token, encoders, options);
|
|
1161
|
-
else encoders[tokens.type.major](buf, tokens, options);
|
|
1162
|
-
}(encode_buf, tokens, encoders, options), encode_buf.toBytes(!0);
|
|
1145
|
+
return writeTo.reset(), tokensToEncoded(writeTo, tokens, encoders, options), writeTo.toBytes(!0);
|
|
1163
1146
|
}
|
|
1164
1147
|
function encode_encode(data, options) {
|
|
1165
|
-
return
|
|
1148
|
+
return !0 !== (options = Object.assign({}, defaultEncodeOptions, options)).addBreakTokens ? (defaultWriter.reset(), !function directEncode(writer, data, options, refStack) {
|
|
1149
|
+
let typ = is_is(data), customEncoder = options.typeEncoders && options.typeEncoders[typ];
|
|
1150
|
+
if (customEncoder) {
|
|
1151
|
+
let tokens = customEncoder(data, typ, options, refStack);
|
|
1152
|
+
if (null != tokens) return void tokensToEncoded(writer, tokens, cborEncoders, options);
|
|
1153
|
+
}
|
|
1154
|
+
switch(typ){
|
|
1155
|
+
case 'null':
|
|
1156
|
+
writer.push([
|
|
1157
|
+
SIMPLE_NULL
|
|
1158
|
+
]);
|
|
1159
|
+
return;
|
|
1160
|
+
case 'undefined':
|
|
1161
|
+
writer.push([
|
|
1162
|
+
SIMPLE_UNDEFINED
|
|
1163
|
+
]);
|
|
1164
|
+
return;
|
|
1165
|
+
case 'boolean':
|
|
1166
|
+
writer.push([
|
|
1167
|
+
data ? SIMPLE_TRUE : SIMPLE_FALSE
|
|
1168
|
+
]);
|
|
1169
|
+
return;
|
|
1170
|
+
case 'number':
|
|
1171
|
+
Number.isInteger(data) && Number.isSafeInteger(data) ? data >= 0 ? encodeUintValue(writer, MAJOR_UINT, data) : encodeUintValue(writer, MAJOR_NEGINT, -1 * data - 1) : encodeFloat(writer, new Token(Type.float, data), options);
|
|
1172
|
+
return;
|
|
1173
|
+
case 'bigint':
|
|
1174
|
+
data >= BigInt(0) ? encodeUintValue(writer, MAJOR_UINT, data) : encodeUintValue(writer, MAJOR_NEGINT, data * encode_neg1b - encode_pos1b);
|
|
1175
|
+
return;
|
|
1176
|
+
case 'string':
|
|
1177
|
+
{
|
|
1178
|
+
let bytes = byte_utils_fromString(data);
|
|
1179
|
+
encodeUintValue(writer, MAJOR_STRING, bytes.length), writer.push(bytes);
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
case 'Uint8Array':
|
|
1183
|
+
encodeUintValue(writer, MAJOR_BYTES, data.length), writer.push(data);
|
|
1184
|
+
return;
|
|
1185
|
+
case 'Array':
|
|
1186
|
+
if (!data.length) return void writer.push([
|
|
1187
|
+
MAJOR_ARRAY
|
|
1188
|
+
]);
|
|
1189
|
+
for (let elem of (refStack = Ref.createCheck(refStack, data), encodeUintValue(writer, MAJOR_ARRAY, data.length), data))directEncode(writer, elem, options, refStack);
|
|
1190
|
+
return;
|
|
1191
|
+
case 'Object':
|
|
1192
|
+
case 'Map':
|
|
1193
|
+
tokensToEncoded(writer, typeEncoders.Object(data, typ, options, refStack), cborEncoders, options);
|
|
1194
|
+
return;
|
|
1195
|
+
default:
|
|
1196
|
+
{
|
|
1197
|
+
let typeEncoder = typeEncoders[typ];
|
|
1198
|
+
if (!typeEncoder) throw Error(`${encodeErrPrefix} unsupported type: ${typ}`);
|
|
1199
|
+
tokensToEncoded(writer, typeEncoder(data, typ, options, refStack), cborEncoders, options);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
}(defaultWriter, data, options, void 0), defaultWriter.toBytes(!0)) : encodeCustom(data, cborEncoders, options);
|
|
1166
1203
|
}
|
|
1167
1204
|
function decode_decode(data, options) {
|
|
1168
1205
|
let [decoded, remainder] = function(data, options) {
|
|
1169
1206
|
if (!(data instanceof Uint8Array)) throw Error(`${decodeErrPrefix} data to decode must be a Uint8Array`);
|
|
1170
|
-
|
|
1207
|
+
options = Object.assign({}, defaultDecodeOptions, options);
|
|
1208
|
+
let u8aData = asU8A(data), tokeniser = options.tokenizer || new Tokeniser(u8aData, options), decoded = function tokensToObject(tokeniser, options) {
|
|
1171
1209
|
if (tokeniser.done()) return DONE;
|
|
1172
1210
|
let token = tokeniser.next();
|
|
1173
|
-
if (token.type
|
|
1211
|
+
if (Type.equals(token.type, Type.break)) return BREAK;
|
|
1174
1212
|
if (token.type.terminal) return token.value;
|
|
1175
|
-
if (token.type
|
|
1213
|
+
if (Type.equals(token.type, Type.array)) {
|
|
1176
1214
|
let arr = [];
|
|
1177
1215
|
for(let i = 0; i < token.value; i++){
|
|
1178
1216
|
let value = tokensToObject(tokeniser, options);
|
|
@@ -1185,8 +1223,8 @@ function decode_decode(data, options) {
|
|
|
1185
1223
|
}
|
|
1186
1224
|
return arr;
|
|
1187
1225
|
}
|
|
1188
|
-
if (token.type
|
|
1189
|
-
let useMaps = !0 === options.useMaps, obj = useMaps ? void 0 : {}, m = useMaps ? new Map() : void 0;
|
|
1226
|
+
if (Type.equals(token.type, Type.map)) return function(token, tokeniser, options) {
|
|
1227
|
+
let useMaps = !0 === options.useMaps, rejectDuplicateMapKeys = !0 === options.rejectDuplicateMapKeys, obj = useMaps ? void 0 : {}, m = useMaps ? new Map() : void 0;
|
|
1190
1228
|
for(let i = 0; i < token.value; i++){
|
|
1191
1229
|
let key = tokensToObject(tokeniser, options);
|
|
1192
1230
|
if (key === BREAK) {
|
|
@@ -1194,15 +1232,15 @@ function decode_decode(data, options) {
|
|
|
1194
1232
|
throw Error(`${decodeErrPrefix} got unexpected break to lengthed map`);
|
|
1195
1233
|
}
|
|
1196
1234
|
if (key === DONE) throw Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no key], expected ${token.value})`);
|
|
1197
|
-
if (!
|
|
1198
|
-
if (
|
|
1235
|
+
if (!useMaps && 'string' != typeof key) throw Error(`${decodeErrPrefix} non-string keys not supported (got ${typeof key})`);
|
|
1236
|
+
if (rejectDuplicateMapKeys && (useMaps && m.has(key) || !useMaps && Object.hasOwn(obj, key))) throw Error(`${decodeErrPrefix} found repeat map key "${key}"`);
|
|
1199
1237
|
let value = tokensToObject(tokeniser, options);
|
|
1200
1238
|
if (value === DONE) throw Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no value], expected ${token.value})`);
|
|
1201
1239
|
useMaps ? m.set(key, value) : obj[key] = value;
|
|
1202
1240
|
}
|
|
1203
1241
|
return useMaps ? m : obj;
|
|
1204
1242
|
}(token, tokeniser, options);
|
|
1205
|
-
if (token.type
|
|
1243
|
+
if (Type.equals(token.type, Type.tag)) {
|
|
1206
1244
|
if (options.tags && 'function' == typeof options.tags[token.value]) {
|
|
1207
1245
|
let tagged = tokensToObject(tokeniser, options);
|
|
1208
1246
|
return options.tags[token.value](tagged);
|
|
@@ -6563,6 +6601,29 @@ class InvalidLabelhashError extends Error {
|
|
|
6563
6601
|
super(`${labelhash}: ${details}`);
|
|
6564
6602
|
}
|
|
6565
6603
|
}
|
|
6604
|
+
let defaultSpinner = {
|
|
6605
|
+
interval: 120,
|
|
6606
|
+
frames: [
|
|
6607
|
+
'⠋',
|
|
6608
|
+
'⠙',
|
|
6609
|
+
'⠹',
|
|
6610
|
+
'⠸',
|
|
6611
|
+
'⠼',
|
|
6612
|
+
'⠴',
|
|
6613
|
+
'⠦',
|
|
6614
|
+
'⠧',
|
|
6615
|
+
'⠇',
|
|
6616
|
+
'⠏'
|
|
6617
|
+
]
|
|
6618
|
+
}, simpleSpinner = {
|
|
6619
|
+
interval: 120,
|
|
6620
|
+
frames: [
|
|
6621
|
+
'-',
|
|
6622
|
+
'\\',
|
|
6623
|
+
'|',
|
|
6624
|
+
'/'
|
|
6625
|
+
]
|
|
6626
|
+
};
|
|
6566
6627
|
class AsciiBar {
|
|
6567
6628
|
formatString = '#spinner #bar #message';
|
|
6568
6629
|
total = 100;
|
|
@@ -6585,10 +6646,7 @@ class AsciiBar {
|
|
|
6585
6646
|
currentSpinnerSymbol = '';
|
|
6586
6647
|
current = 0;
|
|
6587
6648
|
constructor(options){
|
|
6588
|
-
|
|
6589
|
-
for(let opt in options)void 0 !== this[opt] && (this[opt] = options[opt]);
|
|
6590
|
-
'win32' === process.platform && (this.spinner = simpleSpinner), this.enableSpinner && (this.spinnerTimeout = setTimeout(this.updateSpinner, this.spinner.interval));
|
|
6591
|
-
}
|
|
6649
|
+
options && (void 0 !== options.formatString && (this.formatString = options.formatString), void 0 !== options.total && (this.total = options.total), void 0 !== options.startDate && (this.startDate = options.startDate), void 0 !== options.stream && (this.stream = options.stream), void 0 !== options.width && (this.width = options.width), void 0 !== options.doneSymbol && (this.doneSymbol = options.doneSymbol), void 0 !== options.undoneSymbol && (this.undoneSymbol = options.undoneSymbol), void 0 !== options.print && (this.print = options.print), void 0 !== options.start && (this.current = options.start), void 0 !== options.enableSpinner && (this.enableSpinner = options.enableSpinner), void 0 !== options.lastUpdateForTiming && (this.lastUpdateForTiming = options.lastUpdateForTiming), void 0 !== options.autoStop && (this.autoStop = options.autoStop), void 0 !== options.hideCursor && (this.hideCursor = options.hideCursor), 'win32' === process.platform && (this.spinner = simpleSpinner), this.enableSpinner && (this.spinnerTimeout = setTimeout(this.updateSpinner, this.spinner.interval)));
|
|
6592
6650
|
}
|
|
6593
6651
|
renderLine() {
|
|
6594
6652
|
let plusCount = Math.round(this.current / this.total * this.width), minusCount = this.width - plusCount, plusString = '', minusString = '';
|
|
@@ -6626,35 +6684,10 @@ class AsciiBar {
|
|
|
6626
6684
|
}
|
|
6627
6685
|
let colorCodes = {
|
|
6628
6686
|
Reset: '\x1b[0m',
|
|
6629
|
-
|
|
6630
|
-
Blink: '\x1b[5m',
|
|
6631
|
-
Reverse: '\x1b[7m',
|
|
6632
|
-
Hidden: '\x1b[8m',
|
|
6687
|
+
Bright: '\x1b[1m',
|
|
6633
6688
|
Green: '\x1b[32m',
|
|
6634
6689
|
HideCursor: '\x1B[?25l',
|
|
6635
6690
|
ShowCursor: '\x1B[?25h'
|
|
6636
|
-
}, defaultSpinner = {
|
|
6637
|
-
interval: 120,
|
|
6638
|
-
frames: [
|
|
6639
|
-
'⠋',
|
|
6640
|
-
'⠙',
|
|
6641
|
-
'⠹',
|
|
6642
|
-
'⠸',
|
|
6643
|
-
'⠼',
|
|
6644
|
-
'⠴',
|
|
6645
|
-
'⠦',
|
|
6646
|
-
'⠧',
|
|
6647
|
-
'⠇',
|
|
6648
|
-
'⠏'
|
|
6649
|
-
]
|
|
6650
|
-
}, simpleSpinner = {
|
|
6651
|
-
interval: 120,
|
|
6652
|
-
frames: [
|
|
6653
|
-
'-',
|
|
6654
|
-
'\\',
|
|
6655
|
-
'|',
|
|
6656
|
-
'/'
|
|
6657
|
-
]
|
|
6658
6691
|
}, logger = {
|
|
6659
6692
|
start (...args) {
|
|
6660
6693
|
console.log('📦', ...args);
|
|
@@ -8483,6 +8516,7 @@ let createPresignedUrl = async ({ bucketName, apiUrl, file, token })=>{
|
|
|
8483
8516
|
verbose,
|
|
8484
8517
|
name,
|
|
8485
8518
|
car,
|
|
8519
|
+
size: car.size,
|
|
8486
8520
|
token
|
|
8487
8521
|
})).headers.get('x-amz-meta-cid'),
|
|
8488
8522
|
status: 'queued'
|
|
@@ -8553,21 +8587,7 @@ class digest_Digest {
|
|
|
8553
8587
|
let node_digest = (payload)=>{
|
|
8554
8588
|
let digest = new Uint8Array(digest_prefix.length + 32);
|
|
8555
8589
|
return digest.set(digest_prefix, 0), digest.set(__rspack_external_node_crypto_9ba42079.default.createHash('sha256').update(payload).digest(), digest_prefix.length), new digest_Digest(digest);
|
|
8556
|
-
}, sha256_code = 18,
|
|
8557
|
-
'string',
|
|
8558
|
-
'number',
|
|
8559
|
-
'bigint',
|
|
8560
|
-
'symbol'
|
|
8561
|
-
], objectTypeNames = [
|
|
8562
|
-
'Function',
|
|
8563
|
-
'Generator',
|
|
8564
|
-
'AsyncGenerator',
|
|
8565
|
-
'GeneratorFunction',
|
|
8566
|
-
'AsyncGeneratorFunction',
|
|
8567
|
-
'AsyncFunction',
|
|
8568
|
-
'Observable',
|
|
8569
|
-
'Array',
|
|
8570
|
-
'Buffer',
|
|
8590
|
+
}, sha256_code = 18, objectTypeNames = [
|
|
8571
8591
|
'Object',
|
|
8572
8592
|
'RegExp',
|
|
8573
8593
|
'Date',
|
|
@@ -8583,7 +8603,6 @@ let node_digest = (payload)=>{
|
|
|
8583
8603
|
'URL',
|
|
8584
8604
|
'HTMLElement',
|
|
8585
8605
|
'Int8Array',
|
|
8586
|
-
'Uint8Array',
|
|
8587
8606
|
'Uint8ClampedArray',
|
|
8588
8607
|
'Int16Array',
|
|
8589
8608
|
'Uint16Array',
|
|
@@ -8604,6 +8623,9 @@ class Type {
|
|
|
8604
8623
|
compare(typ) {
|
|
8605
8624
|
return this.major < typ.major ? -1 : +(this.major > typ.major);
|
|
8606
8625
|
}
|
|
8626
|
+
static equals(a, b) {
|
|
8627
|
+
return a === b || a.major === b.major && a.name === b.name;
|
|
8628
|
+
}
|
|
8607
8629
|
}
|
|
8608
8630
|
Type.uint = new Type(0, 'uint', !0), Type.negint = new Type(1, 'negint', !0), Type.bytes = new Type(2, 'bytes', !0), Type.string = new Type(3, 'string', !0), Type.array = new Type(4, 'array', !1), Type.map = new Type(5, 'map', !1), Type.tag = new Type(6, 'tag', !1), Type.float = new Type(7, 'float', !0), Type.false = new Type(7, 'false', !0), Type.true = new Type(7, 'true', !0), Type.null = new Type(7, 'null', !0), Type.undefined = new Type(7, 'undefined', !0), Type.break = new Type(7, 'break', !0);
|
|
8609
8631
|
class Token {
|
|
@@ -8614,11 +8636,11 @@ class Token {
|
|
|
8614
8636
|
return `Token[${this.type}].${this.value}`;
|
|
8615
8637
|
}
|
|
8616
8638
|
}
|
|
8617
|
-
let useBuffer = globalThis.process && !globalThis.process.browser && globalThis.Buffer && 'function' == typeof globalThis.Buffer.isBuffer,
|
|
8639
|
+
let useBuffer = globalThis.process && !globalThis.process.browser && globalThis.Buffer && 'function' == typeof globalThis.Buffer.isBuffer, textEncoder = new TextEncoder(), byte_utils_fromString = useBuffer ? (string)=>string.length >= 24 ? globalThis.Buffer.from(string) : byte_utils_utf8ToBytes(string) : (string)=>string.length >= 200 ? textEncoder.encode(string) : byte_utils_utf8ToBytes(string), byte_utils_fromArray = (arr)=>Uint8Array.from(arr), byte_utils_slice = useBuffer ? (bytes, start, end)=>isBuffer(bytes) ? new Uint8Array(bytes.subarray(start, end)) : bytes.slice(start, end) : (bytes, start, end)=>bytes.slice(start, end), byte_utils_concat = useBuffer ? (chunks, length)=>(chunks = chunks.map((c)=>c instanceof Uint8Array ? c : globalThis.Buffer.from(c)), asU8A(globalThis.Buffer.concat(chunks, length))) : (chunks, length)=>{
|
|
8618
8640
|
let out = new Uint8Array(length), off = 0;
|
|
8619
8641
|
for (let b of chunks)off + b.length > out.length && (b = b.subarray(0, out.length - off)), out.set(b, off), off += b.length;
|
|
8620
8642
|
return out;
|
|
8621
|
-
}, alloc = useBuffer ? (size)=>globalThis.Buffer.allocUnsafe(size) : (size)=>new Uint8Array(size)
|
|
8643
|
+
}, alloc = useBuffer ? (size)=>globalThis.Buffer.allocUnsafe(size) : (size)=>new Uint8Array(size);
|
|
8622
8644
|
class bl_Bl {
|
|
8623
8645
|
constructor(chunkSize = 256){
|
|
8624
8646
|
this.chunkSize = chunkSize, this.cursor = 0, this.maxCursor = -1, this.chunks = [], this._initReuseChunk = null;
|
|
@@ -8649,6 +8671,24 @@ class bl_Bl {
|
|
|
8649
8671
|
return reset && this.reset(), byts;
|
|
8650
8672
|
}
|
|
8651
8673
|
}
|
|
8674
|
+
class bl_U8Bl {
|
|
8675
|
+
constructor(dest){
|
|
8676
|
+
this.dest = dest, this.cursor = 0, this.chunks = [
|
|
8677
|
+
dest
|
|
8678
|
+
];
|
|
8679
|
+
}
|
|
8680
|
+
reset() {
|
|
8681
|
+
this.cursor = 0;
|
|
8682
|
+
}
|
|
8683
|
+
push(bytes) {
|
|
8684
|
+
if (this.cursor + bytes.length > this.dest.length) throw Error('write out of bounds, destination buffer is too small');
|
|
8685
|
+
this.dest.set(bytes, this.cursor), this.cursor += bytes.length;
|
|
8686
|
+
}
|
|
8687
|
+
toBytes(reset = !1) {
|
|
8688
|
+
let byts = this.dest.subarray(0, this.cursor);
|
|
8689
|
+
return reset && this.reset(), byts;
|
|
8690
|
+
}
|
|
8691
|
+
}
|
|
8652
8692
|
let decodeErrPrefix = 'CBOR decode error:', encodeErrPrefix = 'CBOR encode error:', uintMinorPrefixBytes = [];
|
|
8653
8693
|
uintMinorPrefixBytes[23] = 1, uintMinorPrefixBytes[24] = 2, uintMinorPrefixBytes[25] = 3, uintMinorPrefixBytes[26] = 5, uintMinorPrefixBytes[27] = 9;
|
|
8654
8694
|
let uintBoundaries = [
|
|
@@ -8678,7 +8718,7 @@ encodeNegint.encodedSize = function(token) {
|
|
|
8678
8718
|
var b1, b2;
|
|
8679
8719
|
return b1 = tokenBytes(tok1), b2 = tokenBytes(tok2), b1.length < b2.length ? -1 : b1.length > b2.length ? 1 : compare(b1, b2);
|
|
8680
8720
|
};
|
|
8681
|
-
let encodeString = encodeBytes;
|
|
8721
|
+
let textDecoder = new TextDecoder(), ASCII_THRESHOLD = 32, encodeString = encodeBytes;
|
|
8682
8722
|
encodeArray.compareTokens = encodeUint.compareTokens, encodeArray.encodedSize = function(token) {
|
|
8683
8723
|
return encodeUintValue.encodedSize(token.value);
|
|
8684
8724
|
}, encodeMap.compareTokens = encodeUint.compareTokens, encodeMap.encodedSize = function(token) {
|
|
@@ -8828,7 +8868,7 @@ let defaultEncodeOptions = {
|
|
|
8828
8868
|
throw Error('rfc8949MapSorter: complex key types are not supported yet');
|
|
8829
8869
|
},
|
|
8830
8870
|
quickEncodeToken: quickEncodeToken
|
|
8831
|
-
}), cborEncoders = makeCborEncoders(),
|
|
8871
|
+
}), cborEncoders = makeCborEncoders(), defaultWriter = new bl_Bl();
|
|
8832
8872
|
class Ref {
|
|
8833
8873
|
constructor(obj, parent){
|
|
8834
8874
|
this.obj = obj, this.parent = parent;
|
|
@@ -8879,29 +8919,35 @@ let simpleTokens = {
|
|
|
8879
8919
|
];
|
|
8880
8920
|
},
|
|
8881
8921
|
Object (obj, typ, options, refStack) {
|
|
8882
|
-
|
|
8883
|
-
|
|
8922
|
+
var entries;
|
|
8923
|
+
let entries1, isMap = 'Object' !== typ, keys = isMap ? obj.keys() : Object.keys(obj), maxLength = isMap ? obj.size : keys.length;
|
|
8924
|
+
if (maxLength) {
|
|
8925
|
+
entries1 = Array(maxLength), refStack = Ref.createCheck(refStack, obj);
|
|
8926
|
+
let skipUndefined = !isMap && options.ignoreUndefinedProperties, i = 0;
|
|
8927
|
+
for (let key of keys){
|
|
8928
|
+
let value = isMap ? obj.get(key) : obj[key];
|
|
8929
|
+
skipUndefined && void 0 === value || (entries1[i++] = [
|
|
8930
|
+
encode_objectToTokens(key, options, refStack),
|
|
8931
|
+
encode_objectToTokens(value, options, refStack)
|
|
8932
|
+
]);
|
|
8933
|
+
}
|
|
8934
|
+
i < maxLength && (entries1.length = i);
|
|
8935
|
+
}
|
|
8936
|
+
return entries1?.length ? (entries = entries1, options.mapSorter && entries.sort(options.mapSorter), options.addBreakTokens) ? [
|
|
8937
|
+
new Token(Type.map, entries1.length),
|
|
8938
|
+
entries1,
|
|
8939
|
+
new Token(Type.break)
|
|
8940
|
+
] : [
|
|
8941
|
+
new Token(Type.map, entries1.length),
|
|
8942
|
+
entries1
|
|
8943
|
+
] : !0 === options.addBreakTokens ? [
|
|
8884
8944
|
simpleTokens.emptyMap,
|
|
8885
8945
|
new Token(Type.break)
|
|
8886
8946
|
] : simpleTokens.emptyMap;
|
|
8887
|
-
refStack = Ref.createCheck(refStack, obj);
|
|
8888
|
-
let entries = [], i = 0;
|
|
8889
|
-
for (let key of keys)entries[i++] = [
|
|
8890
|
-
encode_objectToTokens(key, options, refStack),
|
|
8891
|
-
encode_objectToTokens(isMap ? obj.get(key) : obj[key], options, refStack)
|
|
8892
|
-
];
|
|
8893
|
-
return (options.mapSorter && entries.sort(options.mapSorter), options.addBreakTokens) ? [
|
|
8894
|
-
new Token(Type.map, length),
|
|
8895
|
-
entries,
|
|
8896
|
-
new Token(Type.break)
|
|
8897
|
-
] : [
|
|
8898
|
-
new Token(Type.map, length),
|
|
8899
|
-
entries
|
|
8900
|
-
];
|
|
8901
8947
|
}
|
|
8902
8948
|
};
|
|
8903
8949
|
for (let typ of (typeEncoders.Map = typeEncoders.Object, typeEncoders.Buffer = typeEncoders.Uint8Array, 'Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64'.split(' ')))typeEncoders[`${typ}Array`] = typeEncoders.DataView;
|
|
8904
|
-
let defaultDecodeOptions = {
|
|
8950
|
+
let MAJOR_UINT = Type.uint.majorEncoded, MAJOR_NEGINT = Type.negint.majorEncoded, MAJOR_BYTES = Type.bytes.majorEncoded, MAJOR_STRING = Type.string.majorEncoded, MAJOR_ARRAY = Type.array.majorEncoded, SIMPLE_FALSE = Type.float.majorEncoded | MINOR_FALSE, SIMPLE_TRUE = Type.float.majorEncoded | MINOR_TRUE, SIMPLE_NULL = Type.float.majorEncoded | MINOR_NULL, SIMPLE_UNDEFINED = Type.float.majorEncoded | MINOR_UNDEFINED, encode_neg1b = BigInt(-1), encode_pos1b = BigInt(1), defaultDecodeOptions = {
|
|
8905
8951
|
strict: !1,
|
|
8906
8952
|
allowIndefinite: !0,
|
|
8907
8953
|
allowUndefined: !0,
|
|
@@ -10239,7 +10285,7 @@ let filecoinMainnet = {
|
|
|
10239
10285
|
address: '0xf55dDbf63F1b55c3F1D4FA7e339a68AB7b64A5eB'
|
|
10240
10286
|
},
|
|
10241
10287
|
storageView: {
|
|
10242
|
-
address: '
|
|
10288
|
+
address: '0x638a4986332bF9B889E5D7435B966C5ecdE077Fa'
|
|
10243
10289
|
}
|
|
10244
10290
|
},
|
|
10245
10291
|
blockExplorer: 'https://filecoin.blockscout.com'
|
|
@@ -10263,7 +10309,7 @@ let filecoinMainnet = {
|
|
|
10263
10309
|
address: '0x839e5c9988e4e9977d40708d0094103c0839Ac9D'
|
|
10264
10310
|
},
|
|
10265
10311
|
storageView: {
|
|
10266
|
-
address: '
|
|
10312
|
+
address: '0x53d235D474585EC102ccaB7e0cdcE951dD00f716'
|
|
10267
10313
|
}
|
|
10268
10314
|
},
|
|
10269
10315
|
blockExplorer: 'https://filecoin-testnet.blockscout.com'
|
|
@@ -11226,7 +11272,7 @@ class TipAboveFeeCapError extends BaseError {
|
|
|
11226
11272
|
});
|
|
11227
11273
|
}
|
|
11228
11274
|
}
|
|
11229
|
-
let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', estimateGas = async ({ provider, to, data, from, value = '0x0' })=>toBigInt(await provider.request({
|
|
11275
|
+
let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_LIMIT = fromNumber(16777216), estimateGas = async ({ provider, to, data, from, value = '0x0' })=>toBigInt(await provider.request({
|
|
11230
11276
|
method: 'eth_estimateGas',
|
|
11231
11277
|
params: [
|
|
11232
11278
|
{
|
|
@@ -11234,7 +11280,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', estimateGas = a
|
|
|
11234
11280
|
to,
|
|
11235
11281
|
data,
|
|
11236
11282
|
value,
|
|
11237
|
-
gas:
|
|
11283
|
+
gas: fromNumber(SIMULATION_GAS_LIMIT)
|
|
11238
11284
|
},
|
|
11239
11285
|
'latest'
|
|
11240
11286
|
]
|
|
@@ -11245,7 +11291,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', estimateGas = a
|
|
|
11245
11291
|
to,
|
|
11246
11292
|
data,
|
|
11247
11293
|
from,
|
|
11248
|
-
gas:
|
|
11294
|
+
gas: fromNumber(SIMULATION_GAS_LIMIT)
|
|
11249
11295
|
},
|
|
11250
11296
|
'latest'
|
|
11251
11297
|
]
|
|
@@ -11481,7 +11527,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', estimateGas = a
|
|
|
11481
11527
|
calls
|
|
11482
11528
|
]),
|
|
11483
11529
|
to: chain.contracts.multicall3.address,
|
|
11484
|
-
gas:
|
|
11530
|
+
gas: fromNumber(SIMULATION_GAS_LIMIT)
|
|
11485
11531
|
},
|
|
11486
11532
|
'latest'
|
|
11487
11533
|
]
|
|
@@ -11686,7 +11732,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', estimateGas = a
|
|
|
11686
11732
|
chain
|
|
11687
11733
|
});
|
|
11688
11734
|
if (balance < amount) throw Error(`Not enough USDfc to deposit (need: ${Value_format(amount - balance, 18).slice(0, 5)})`);
|
|
11689
|
-
let { r, s } = await signErc20Permit({
|
|
11735
|
+
let { r, s, yParity } = await signErc20Permit({
|
|
11690
11736
|
privateKey,
|
|
11691
11737
|
address,
|
|
11692
11738
|
amount,
|
|
@@ -11700,7 +11746,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', estimateGas = a
|
|
|
11700
11746
|
address,
|
|
11701
11747
|
amount,
|
|
11702
11748
|
deadline,
|
|
11703
|
-
27,
|
|
11749
|
+
void 0 !== yParity ? yParityToV(yParity) : 27,
|
|
11704
11750
|
fromNumber(r, {
|
|
11705
11751
|
size: 32
|
|
11706
11752
|
}),
|
|
@@ -12697,8 +12743,24 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', estimateGas = a
|
|
|
12697
12743
|
return logger.info(`Pending piece upload: ${statusUrl}`), logger.info(`Pending transaction: ${chain.blockExplorer}/tx/${hash}`), await waitForTransaction(filProvider[chainId], hash), {
|
|
12698
12744
|
cid
|
|
12699
12745
|
};
|
|
12700
|
-
}, lighthouse_providerName = 'Lighthouse',
|
|
12701
|
-
if (first)
|
|
12746
|
+
}, lighthouse_providerName = 'Lighthouse', uploadOnLighthouse = async ({ car, name, first, token, verbose, cid })=>{
|
|
12747
|
+
if (first) {
|
|
12748
|
+
let fd = new FormData();
|
|
12749
|
+
fd.append('file', car, `${name}.car`);
|
|
12750
|
+
let res = await fetch('https://upload.lighthouse.storage/api/v0/dag/import', {
|
|
12751
|
+
method: 'POST',
|
|
12752
|
+
headers: {
|
|
12753
|
+
Authorization: `Bearer ${token}`
|
|
12754
|
+
},
|
|
12755
|
+
body: fd
|
|
12756
|
+
});
|
|
12757
|
+
verbose && logger.request('POST', res.url, res.status);
|
|
12758
|
+
let json = await res.json();
|
|
12759
|
+
if (!res.ok) throw new DeployError(lighthouse_providerName, json.error?.message || json.error || json.message || json.details || 'Unknown error');
|
|
12760
|
+
return {
|
|
12761
|
+
cid: json.data?.Hash || cid
|
|
12762
|
+
};
|
|
12763
|
+
}
|
|
12702
12764
|
let res = await fetch('https://api.lighthouse.storage/api/lighthouse/pin', {
|
|
12703
12765
|
method: 'POST',
|
|
12704
12766
|
headers: {
|
|
@@ -12711,7 +12773,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', estimateGas = a
|
|
|
12711
12773
|
});
|
|
12712
12774
|
verbose && logger.request('POST', res.url, res.status);
|
|
12713
12775
|
let json = await res.json();
|
|
12714
|
-
if (!res.ok) throw new DeployError(lighthouse_providerName, json.error.message);
|
|
12776
|
+
if (!res.ok) throw new DeployError(lighthouse_providerName, json.error?.message || json.error || json.message || json.details || 'Unknown error');
|
|
12715
12777
|
return {
|
|
12716
12778
|
cid,
|
|
12717
12779
|
status: 'queued'
|
|
@@ -13481,9 +13543,9 @@ class JSONEncoder extends Array {
|
|
|
13481
13543
|
}
|
|
13482
13544
|
prefix(buf) {
|
|
13483
13545
|
let recurs = this.inRecursive[this.inRecursive.length - 1];
|
|
13484
|
-
recurs && (recurs.type
|
|
13546
|
+
recurs && (Type.equals(recurs.type, Type.array) && (recurs.elements++, 1 !== recurs.elements && buf.push([
|
|
13485
13547
|
44
|
|
13486
|
-
])), recurs.type
|
|
13548
|
+
])), Type.equals(recurs.type, Type.map) && (recurs.elements++, 1 !== recurs.elements && (recurs.elements % 2 == 1 ? buf.push([
|
|
13487
13549
|
44
|
|
13488
13550
|
]) : buf.push([
|
|
13489
13551
|
58
|
|
@@ -13527,10 +13589,10 @@ class JSONEncoder extends Array {
|
|
|
13527
13589
|
if ('break' === token.type.name) {
|
|
13528
13590
|
let recurs = this.inRecursive.pop();
|
|
13529
13591
|
if (recurs) {
|
|
13530
|
-
if (recurs.type
|
|
13592
|
+
if (Type.equals(recurs.type, Type.array)) buf.push([
|
|
13531
13593
|
93
|
|
13532
13594
|
]);
|
|
13533
|
-
else if (recurs.type
|
|
13595
|
+
else if (Type.equals(recurs.type, Type.map)) buf.push([
|
|
13534
13596
|
125
|
|
13535
13597
|
]);
|
|
13536
13598
|
else throw Error('Unexpected recursive type; this should not happen!');
|
|
@@ -13730,7 +13792,13 @@ class Tokenizer {
|
|
|
13730
13792
|
}
|
|
13731
13793
|
break;
|
|
13732
13794
|
case 34:
|
|
13733
|
-
return this._pos++, new Token(Type.string,
|
|
13795
|
+
return this._pos++, new Token(Type.string, function(codePoints) {
|
|
13796
|
+
let len = codePoints.length;
|
|
13797
|
+
if (len <= 0x1000) return String.fromCharCode.apply(String, codePoints);
|
|
13798
|
+
let res = '', i = 0;
|
|
13799
|
+
for(; i < len;)res += String.fromCharCode.apply(String, codePoints.slice(i, i += 0x1000));
|
|
13800
|
+
return res;
|
|
13801
|
+
}(chars), this._pos - startPos);
|
|
13734
13802
|
default:
|
|
13735
13803
|
if (ch < 32) throw Error(`${decodeErrPrefix} invalid control character at position ${this._pos}`);
|
|
13736
13804
|
ch < 0x80 ? (chars.push(ch), this._pos++) : readUtf8Char();
|
|
@@ -13865,20 +13933,24 @@ class DagJsonTokenizer extends Tokenizer {
|
|
|
13865
13933
|
}
|
|
13866
13934
|
next() {
|
|
13867
13935
|
let token = this._next();
|
|
13868
|
-
if (token.type
|
|
13936
|
+
if (Type.equals(token.type, Type.map)) {
|
|
13869
13937
|
let keyToken = this._next();
|
|
13870
|
-
if (keyToken.type
|
|
13938
|
+
if (Type.equals(keyToken.type, Type.string) && '/' === keyToken.value) {
|
|
13871
13939
|
let valueToken = this._next();
|
|
13872
|
-
if (valueToken.type
|
|
13873
|
-
|
|
13940
|
+
if (Type.equals(valueToken.type, Type.string)) {
|
|
13941
|
+
let breakToken = this._next();
|
|
13942
|
+
if (!Type.equals(breakToken.type, Type.break)) throw Error('Invalid encoded CID form');
|
|
13874
13943
|
return this.tokenBuffer.push(valueToken), new Token(Type.tag, 42, 0);
|
|
13875
13944
|
}
|
|
13876
|
-
if (valueToken.type
|
|
13945
|
+
if (Type.equals(valueToken.type, Type.map)) {
|
|
13877
13946
|
let innerKeyToken = this._next();
|
|
13878
|
-
if (innerKeyToken.type
|
|
13947
|
+
if (Type.equals(innerKeyToken.type, Type.string) && 'bytes' === innerKeyToken.value) {
|
|
13879
13948
|
let innerValueToken = this._next();
|
|
13880
|
-
if (innerValueToken.type
|
|
13881
|
-
for(let i = 0; i < 2; i++)
|
|
13949
|
+
if (Type.equals(innerValueToken.type, Type.string)) {
|
|
13950
|
+
for(let i = 0; i < 2; i++){
|
|
13951
|
+
let breakToken = this._next();
|
|
13952
|
+
if (!Type.equals(breakToken.type, Type.break)) throw Error('Invalid encoded Bytes form');
|
|
13953
|
+
}
|
|
13882
13954
|
let bytes = base64.decode(`m${innerValueToken.value}`);
|
|
13883
13955
|
return new Token(Type.bytes, bytes, innerValueToken.value.length);
|
|
13884
13956
|
}
|
|
@@ -17543,7 +17615,8 @@ let uploadCAR = async (conf, car)=>{
|
|
|
17543
17615
|
}, storacha_abilities = [
|
|
17544
17616
|
'space/blob/add',
|
|
17545
17617
|
'space/index/add',
|
|
17546
|
-
'upload/add'
|
|
17618
|
+
'upload/add',
|
|
17619
|
+
'filecoin/offer'
|
|
17547
17620
|
], referenceToCID = (ref)=>{
|
|
17548
17621
|
var multihash;
|
|
17549
17622
|
let codeOffset, hashOffset, bytes;
|
|
@@ -17626,8 +17699,8 @@ let uploadCAR = async (conf, car)=>{
|
|
|
17626
17699
|
},
|
|
17627
17700
|
LIGHTHOUSE_TOKEN: {
|
|
17628
17701
|
name: 'Lighthouse',
|
|
17629
|
-
upload:
|
|
17630
|
-
supported: '
|
|
17702
|
+
upload: uploadOnLighthouse,
|
|
17703
|
+
supported: 'both',
|
|
17631
17704
|
protocol: 'ipfs'
|
|
17632
17705
|
},
|
|
17633
17706
|
SWARMY_TOKEN: {
|
|
@@ -20083,7 +20156,8 @@ let addr_abi = {
|
|
|
20083
20156
|
namehash(name)
|
|
20084
20157
|
])
|
|
20085
20158
|
]),
|
|
20086
|
-
to: '0xeEeEEEeE14D718C2B47D9923Deab1335E144EeEe'
|
|
20159
|
+
to: '0xeEeEEEeE14D718C2B47D9923Deab1335E144EeEe',
|
|
20160
|
+
gas: SIMULATION_GAS_LIMIT
|
|
20087
20161
|
},
|
|
20088
20162
|
'latest'
|
|
20089
20163
|
]
|
|
@@ -20140,7 +20214,8 @@ let addr_abi = {
|
|
|
20140
20214
|
data: AbiFunction_encodeData(get_resolver_abi, [
|
|
20141
20215
|
Bytes_toHex(utils_packetToBytes(name))
|
|
20142
20216
|
]),
|
|
20143
|
-
to: '0xeEeEEEeE14D718C2B47D9923Deab1335E144EeEe'
|
|
20217
|
+
to: '0xeEeEEEeE14D718C2B47D9923Deab1335E144EeEe',
|
|
20218
|
+
gas: SIMULATION_GAS_LIMIT
|
|
20144
20219
|
},
|
|
20145
20220
|
'latest'
|
|
20146
20221
|
]
|
|
@@ -20247,7 +20322,8 @@ let addr_abi = {
|
|
|
20247
20322
|
zeroAddress,
|
|
20248
20323
|
zeroAddress,
|
|
20249
20324
|
txData.nonce
|
|
20250
|
-
])
|
|
20325
|
+
]),
|
|
20326
|
+
gas: SIMULATION_GAS_LIMIT
|
|
20251
20327
|
},
|
|
20252
20328
|
'latest'
|
|
20253
20329
|
]
|
|
@@ -20622,7 +20698,8 @@ let ENS_DEPLOYER_ROLE = keccak256(Bytes_fromString('ENS_DEPLOYER')), execTransac
|
|
|
20622
20698
|
params: [
|
|
20623
20699
|
{
|
|
20624
20700
|
to: safe,
|
|
20625
|
-
data: AbiFunction_encodeData(getNonce)
|
|
20701
|
+
data: AbiFunction_encodeData(getNonce),
|
|
20702
|
+
gas: SIMULATION_GAS_LIMIT
|
|
20626
20703
|
},
|
|
20627
20704
|
'latest'
|
|
20628
20705
|
]
|
|
@@ -20930,7 +21007,7 @@ let ENS_DEPLOYER_ROLE = keccak256(Bytes_fromString('ENS_DEPLOYER')), execTransac
|
|
|
20930
21007
|
if (!(attempt < maxRetries)) return logger.error(gwOfflineMessage);
|
|
20931
21008
|
logger.text(`🔄 Retrying in ${retryInterval / 1000} seconds...`), await promises_setTimeout(retryInterval);
|
|
20932
21009
|
} catch (error) {
|
|
20933
|
-
if (error instanceof DOMException && attempt < maxRetries) logger.info(
|
|
21010
|
+
if (error instanceof DOMException && attempt < maxRetries) logger.info("⌛ Timed out. Retrying..."), await promises_setTimeout(retryInterval);
|
|
20934
21011
|
else throw logger.error(error instanceof DOMException ? gwOfflineMessage : `Error fetching endpoint: ${error.message}`), error;
|
|
20935
21012
|
}
|
|
20936
21013
|
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omnipin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"author": "v1rtl <hi@v1rtl.site>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/omnipin/omnipin.git"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@biomejs/biome": "^2.
|
|
10
|
+
"@biomejs/biome": "^2.4.5",
|
|
11
11
|
"@ipld/car": "^5.4.2",
|
|
12
12
|
"@ipld/dag-ucan": "^3.4.5",
|
|
13
|
-
"@rslib/core": "^0.19.
|
|
13
|
+
"@rslib/core": "^0.19.4",
|
|
14
14
|
"@size-limit/file": "^11.2.0",
|
|
15
15
|
"@stauro/filebase-upload": "npm:@jsr/stauro__filebase-upload",
|
|
16
16
|
"@storacha/capabilities": "^1.12.0",
|
|
17
|
-
"@types/bun": "^1.3.
|
|
17
|
+
"@types/bun": "^1.3.8",
|
|
18
18
|
"@types/varint": "^6.0.3",
|
|
19
19
|
"@ucanto/client": "^9.0.2",
|
|
20
20
|
"@ucanto/core": "^10.4.6",
|
|
21
21
|
"@ucanto/principal": "^9.0.3",
|
|
22
22
|
"@ucanto/transport": "^9.2.1",
|
|
23
23
|
"@web3-storage/data-segment": "^5.3.0",
|
|
24
|
-
"cborg": "^4.
|
|
24
|
+
"cborg": "^4.5.8",
|
|
25
25
|
"esbuild": "^0.27.2",
|
|
26
26
|
"ipfs-unixfs": "^12.0.0",
|
|
27
27
|
"ipfs-unixfs-importer": "^16.0.2",
|
|
@@ -55,7 +55,6 @@
|
|
|
55
55
|
],
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"overrides": {
|
|
58
|
-
"@multiformats/murmur3": "npm:@omnipin/multiformats-murmur3@2.2.0",
|
|
59
58
|
"multiformats": "13.4.2"
|
|
60
59
|
},
|
|
61
60
|
"release": {
|