@steemit/steem-js 1.0.6 → 1.0.7
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/api/rpc-auth.d.ts +2 -6
- package/dist/browser.esm.js +53 -23
- package/dist/browser.esm.js.map +1 -1
- package/dist/index.cjs +50 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -3
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +2562 -164
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/umd.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
(function() {
|
|
2
2
|
// Provide minimal polyfills for browser
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
var g = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
4
|
+
|
|
5
|
+
// Process polyfill
|
|
6
|
+
if (typeof g.process === 'undefined') {
|
|
7
|
+
g.process = {
|
|
8
|
+
browser: true,
|
|
9
|
+
env: {},
|
|
10
|
+
version: '',
|
|
11
|
+
versions: {},
|
|
12
|
+
nextTick: function(fn) { setTimeout(fn, 0); },
|
|
13
|
+
exit: function() {},
|
|
14
|
+
cwd: function() { return '/'; },
|
|
15
|
+
platform: 'browser'
|
|
16
|
+
};
|
|
17
|
+
if (typeof globalThis !== 'undefined') {
|
|
18
|
+
globalThis.process = g.process;
|
|
16
19
|
}
|
|
17
20
|
}
|
|
21
|
+
// Buffer will be set in outro after all modules are loaded
|
|
18
22
|
})();
|
|
19
23
|
(function (global, factory) {
|
|
20
24
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -937,6 +941,2353 @@
|
|
|
937
941
|
};
|
|
938
942
|
}
|
|
939
943
|
|
|
944
|
+
var buffer = {};
|
|
945
|
+
|
|
946
|
+
var base64Js = {};
|
|
947
|
+
|
|
948
|
+
base64Js.byteLength = byteLength;
|
|
949
|
+
base64Js.toByteArray = toByteArray;
|
|
950
|
+
base64Js.fromByteArray = fromByteArray;
|
|
951
|
+
|
|
952
|
+
var lookup = [];
|
|
953
|
+
var revLookup = [];
|
|
954
|
+
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
|
|
955
|
+
|
|
956
|
+
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
957
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
958
|
+
lookup[i] = code[i];
|
|
959
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// Support decoding URL-safe base64 strings, as Node.js does.
|
|
963
|
+
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
|
964
|
+
revLookup['-'.charCodeAt(0)] = 62;
|
|
965
|
+
revLookup['_'.charCodeAt(0)] = 63;
|
|
966
|
+
|
|
967
|
+
function getLens (b64) {
|
|
968
|
+
var len = b64.length;
|
|
969
|
+
|
|
970
|
+
if (len % 4 > 0) {
|
|
971
|
+
throw new Error('Invalid string. Length must be a multiple of 4')
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// Trim off extra bytes after placeholder bytes are found
|
|
975
|
+
// See: https://github.com/beatgammit/base64-js/issues/42
|
|
976
|
+
var validLen = b64.indexOf('=');
|
|
977
|
+
if (validLen === -1) validLen = len;
|
|
978
|
+
|
|
979
|
+
var placeHoldersLen = validLen === len
|
|
980
|
+
? 0
|
|
981
|
+
: 4 - (validLen % 4);
|
|
982
|
+
|
|
983
|
+
return [validLen, placeHoldersLen]
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// base64 is 4/3 + up to two characters of the original data
|
|
987
|
+
function byteLength (b64) {
|
|
988
|
+
var lens = getLens(b64);
|
|
989
|
+
var validLen = lens[0];
|
|
990
|
+
var placeHoldersLen = lens[1];
|
|
991
|
+
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function _byteLength (b64, validLen, placeHoldersLen) {
|
|
995
|
+
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
function toByteArray (b64) {
|
|
999
|
+
var tmp;
|
|
1000
|
+
var lens = getLens(b64);
|
|
1001
|
+
var validLen = lens[0];
|
|
1002
|
+
var placeHoldersLen = lens[1];
|
|
1003
|
+
|
|
1004
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
1005
|
+
|
|
1006
|
+
var curByte = 0;
|
|
1007
|
+
|
|
1008
|
+
// if there are placeholders, only get up to the last complete 4 chars
|
|
1009
|
+
var len = placeHoldersLen > 0
|
|
1010
|
+
? validLen - 4
|
|
1011
|
+
: validLen;
|
|
1012
|
+
|
|
1013
|
+
var i;
|
|
1014
|
+
for (i = 0; i < len; i += 4) {
|
|
1015
|
+
tmp =
|
|
1016
|
+
(revLookup[b64.charCodeAt(i)] << 18) |
|
|
1017
|
+
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
|
1018
|
+
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
|
1019
|
+
revLookup[b64.charCodeAt(i + 3)];
|
|
1020
|
+
arr[curByte++] = (tmp >> 16) & 0xFF;
|
|
1021
|
+
arr[curByte++] = (tmp >> 8) & 0xFF;
|
|
1022
|
+
arr[curByte++] = tmp & 0xFF;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
if (placeHoldersLen === 2) {
|
|
1026
|
+
tmp =
|
|
1027
|
+
(revLookup[b64.charCodeAt(i)] << 2) |
|
|
1028
|
+
(revLookup[b64.charCodeAt(i + 1)] >> 4);
|
|
1029
|
+
arr[curByte++] = tmp & 0xFF;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
if (placeHoldersLen === 1) {
|
|
1033
|
+
tmp =
|
|
1034
|
+
(revLookup[b64.charCodeAt(i)] << 10) |
|
|
1035
|
+
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
|
1036
|
+
(revLookup[b64.charCodeAt(i + 2)] >> 2);
|
|
1037
|
+
arr[curByte++] = (tmp >> 8) & 0xFF;
|
|
1038
|
+
arr[curByte++] = tmp & 0xFF;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
return arr
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function tripletToBase64 (num) {
|
|
1045
|
+
return lookup[num >> 18 & 0x3F] +
|
|
1046
|
+
lookup[num >> 12 & 0x3F] +
|
|
1047
|
+
lookup[num >> 6 & 0x3F] +
|
|
1048
|
+
lookup[num & 0x3F]
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
function encodeChunk (uint8, start, end) {
|
|
1052
|
+
var tmp;
|
|
1053
|
+
var output = [];
|
|
1054
|
+
for (var i = start; i < end; i += 3) {
|
|
1055
|
+
tmp =
|
|
1056
|
+
((uint8[i] << 16) & 0xFF0000) +
|
|
1057
|
+
((uint8[i + 1] << 8) & 0xFF00) +
|
|
1058
|
+
(uint8[i + 2] & 0xFF);
|
|
1059
|
+
output.push(tripletToBase64(tmp));
|
|
1060
|
+
}
|
|
1061
|
+
return output.join('')
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
function fromByteArray (uint8) {
|
|
1065
|
+
var tmp;
|
|
1066
|
+
var len = uint8.length;
|
|
1067
|
+
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
|
1068
|
+
var parts = [];
|
|
1069
|
+
var maxChunkLength = 16383; // must be multiple of 3
|
|
1070
|
+
|
|
1071
|
+
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
1072
|
+
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
1073
|
+
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
1077
|
+
if (extraBytes === 1) {
|
|
1078
|
+
tmp = uint8[len - 1];
|
|
1079
|
+
parts.push(
|
|
1080
|
+
lookup[tmp >> 2] +
|
|
1081
|
+
lookup[(tmp << 4) & 0x3F] +
|
|
1082
|
+
'=='
|
|
1083
|
+
);
|
|
1084
|
+
} else if (extraBytes === 2) {
|
|
1085
|
+
tmp = (uint8[len - 2] << 8) + uint8[len - 1];
|
|
1086
|
+
parts.push(
|
|
1087
|
+
lookup[tmp >> 10] +
|
|
1088
|
+
lookup[(tmp >> 4) & 0x3F] +
|
|
1089
|
+
lookup[(tmp << 2) & 0x3F] +
|
|
1090
|
+
'='
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
return parts.join('')
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
var ieee754 = {};
|
|
1098
|
+
|
|
1099
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
1100
|
+
|
|
1101
|
+
ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
|
|
1102
|
+
var e, m;
|
|
1103
|
+
var eLen = (nBytes * 8) - mLen - 1;
|
|
1104
|
+
var eMax = (1 << eLen) - 1;
|
|
1105
|
+
var eBias = eMax >> 1;
|
|
1106
|
+
var nBits = -7;
|
|
1107
|
+
var i = isLE ? (nBytes - 1) : 0;
|
|
1108
|
+
var d = isLE ? -1 : 1;
|
|
1109
|
+
var s = buffer[offset + i];
|
|
1110
|
+
|
|
1111
|
+
i += d;
|
|
1112
|
+
|
|
1113
|
+
e = s & ((1 << (-nBits)) - 1);
|
|
1114
|
+
s >>= (-nBits);
|
|
1115
|
+
nBits += eLen;
|
|
1116
|
+
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
1117
|
+
|
|
1118
|
+
m = e & ((1 << (-nBits)) - 1);
|
|
1119
|
+
e >>= (-nBits);
|
|
1120
|
+
nBits += mLen;
|
|
1121
|
+
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
1122
|
+
|
|
1123
|
+
if (e === 0) {
|
|
1124
|
+
e = 1 - eBias;
|
|
1125
|
+
} else if (e === eMax) {
|
|
1126
|
+
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
|
1127
|
+
} else {
|
|
1128
|
+
m = m + Math.pow(2, mLen);
|
|
1129
|
+
e = e - eBias;
|
|
1130
|
+
}
|
|
1131
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
|
1132
|
+
};
|
|
1133
|
+
|
|
1134
|
+
ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
|
1135
|
+
var e, m, c;
|
|
1136
|
+
var eLen = (nBytes * 8) - mLen - 1;
|
|
1137
|
+
var eMax = (1 << eLen) - 1;
|
|
1138
|
+
var eBias = eMax >> 1;
|
|
1139
|
+
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
|
|
1140
|
+
var i = isLE ? 0 : (nBytes - 1);
|
|
1141
|
+
var d = isLE ? 1 : -1;
|
|
1142
|
+
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
1143
|
+
|
|
1144
|
+
value = Math.abs(value);
|
|
1145
|
+
|
|
1146
|
+
if (isNaN(value) || value === Infinity) {
|
|
1147
|
+
m = isNaN(value) ? 1 : 0;
|
|
1148
|
+
e = eMax;
|
|
1149
|
+
} else {
|
|
1150
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
1151
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
1152
|
+
e--;
|
|
1153
|
+
c *= 2;
|
|
1154
|
+
}
|
|
1155
|
+
if (e + eBias >= 1) {
|
|
1156
|
+
value += rt / c;
|
|
1157
|
+
} else {
|
|
1158
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
1159
|
+
}
|
|
1160
|
+
if (value * c >= 2) {
|
|
1161
|
+
e++;
|
|
1162
|
+
c /= 2;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
if (e + eBias >= eMax) {
|
|
1166
|
+
m = 0;
|
|
1167
|
+
e = eMax;
|
|
1168
|
+
} else if (e + eBias >= 1) {
|
|
1169
|
+
m = ((value * c) - 1) * Math.pow(2, mLen);
|
|
1170
|
+
e = e + eBias;
|
|
1171
|
+
} else {
|
|
1172
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
1173
|
+
e = 0;
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
|
1178
|
+
|
|
1179
|
+
e = (e << mLen) | m;
|
|
1180
|
+
eLen += mLen;
|
|
1181
|
+
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
|
1182
|
+
|
|
1183
|
+
buffer[offset + i - d] |= s * 128;
|
|
1184
|
+
};
|
|
1185
|
+
|
|
1186
|
+
/*!
|
|
1187
|
+
* The buffer module from node.js, for the browser.
|
|
1188
|
+
*
|
|
1189
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
1190
|
+
* @license MIT
|
|
1191
|
+
*/
|
|
1192
|
+
|
|
1193
|
+
(function (exports$1) {
|
|
1194
|
+
|
|
1195
|
+
const base64 = base64Js;
|
|
1196
|
+
const ieee754$1 = ieee754;
|
|
1197
|
+
const customInspectSymbol =
|
|
1198
|
+
(typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
|
|
1199
|
+
? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
|
|
1200
|
+
: null;
|
|
1201
|
+
|
|
1202
|
+
exports$1.Buffer = Buffer;
|
|
1203
|
+
exports$1.SlowBuffer = SlowBuffer;
|
|
1204
|
+
exports$1.INSPECT_MAX_BYTES = 50;
|
|
1205
|
+
|
|
1206
|
+
const K_MAX_LENGTH = 0x7fffffff;
|
|
1207
|
+
exports$1.kMaxLength = K_MAX_LENGTH;
|
|
1208
|
+
|
|
1209
|
+
/**
|
|
1210
|
+
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
1211
|
+
* === true Use Uint8Array implementation (fastest)
|
|
1212
|
+
* === false Print warning and recommend using `buffer` v4.x which has an Object
|
|
1213
|
+
* implementation (most compatible, even IE6)
|
|
1214
|
+
*
|
|
1215
|
+
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
1216
|
+
* Opera 11.6+, iOS 4.2+.
|
|
1217
|
+
*
|
|
1218
|
+
* We report that the browser does not support typed arrays if the are not subclassable
|
|
1219
|
+
* using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
|
|
1220
|
+
* (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
|
|
1221
|
+
* for __proto__ and has a buggy typed array implementation.
|
|
1222
|
+
*/
|
|
1223
|
+
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
1224
|
+
|
|
1225
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
|
1226
|
+
typeof console.error === 'function') {
|
|
1227
|
+
console.error(
|
|
1228
|
+
'This browser lacks typed array (Uint8Array) support which is required by ' +
|
|
1229
|
+
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
function typedArraySupport () {
|
|
1234
|
+
// Can typed array instances can be augmented?
|
|
1235
|
+
try {
|
|
1236
|
+
const arr = new Uint8Array(1);
|
|
1237
|
+
const proto = { foo: function () { return 42 } };
|
|
1238
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
1239
|
+
Object.setPrototypeOf(arr, proto);
|
|
1240
|
+
return arr.foo() === 42
|
|
1241
|
+
} catch (e) {
|
|
1242
|
+
return false
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
Object.defineProperty(Buffer.prototype, 'parent', {
|
|
1247
|
+
enumerable: true,
|
|
1248
|
+
get: function () {
|
|
1249
|
+
if (!Buffer.isBuffer(this)) return undefined
|
|
1250
|
+
return this.buffer
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
|
|
1254
|
+
Object.defineProperty(Buffer.prototype, 'offset', {
|
|
1255
|
+
enumerable: true,
|
|
1256
|
+
get: function () {
|
|
1257
|
+
if (!Buffer.isBuffer(this)) return undefined
|
|
1258
|
+
return this.byteOffset
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
function createBuffer (length) {
|
|
1263
|
+
if (length > K_MAX_LENGTH) {
|
|
1264
|
+
throw new RangeError('The value "' + length + '" is invalid for option "size"')
|
|
1265
|
+
}
|
|
1266
|
+
// Return an augmented `Uint8Array` instance
|
|
1267
|
+
const buf = new Uint8Array(length);
|
|
1268
|
+
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
1269
|
+
return buf
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
/**
|
|
1273
|
+
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
1274
|
+
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
1275
|
+
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
1276
|
+
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
1277
|
+
* returns a single octet.
|
|
1278
|
+
*
|
|
1279
|
+
* The `Uint8Array` prototype remains unmodified.
|
|
1280
|
+
*/
|
|
1281
|
+
|
|
1282
|
+
function Buffer (arg, encodingOrOffset, length) {
|
|
1283
|
+
// Common case.
|
|
1284
|
+
if (typeof arg === 'number') {
|
|
1285
|
+
if (typeof encodingOrOffset === 'string') {
|
|
1286
|
+
throw new TypeError(
|
|
1287
|
+
'The "string" argument must be of type string. Received type number'
|
|
1288
|
+
)
|
|
1289
|
+
}
|
|
1290
|
+
return allocUnsafe(arg)
|
|
1291
|
+
}
|
|
1292
|
+
return from(arg, encodingOrOffset, length)
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
Buffer.poolSize = 8192; // not used by this implementation
|
|
1296
|
+
|
|
1297
|
+
function from (value, encodingOrOffset, length) {
|
|
1298
|
+
if (typeof value === 'string') {
|
|
1299
|
+
return fromString(value, encodingOrOffset)
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
if (ArrayBuffer.isView(value)) {
|
|
1303
|
+
return fromArrayView(value)
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
if (value == null) {
|
|
1307
|
+
throw new TypeError(
|
|
1308
|
+
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
1309
|
+
'or Array-like Object. Received type ' + (typeof value)
|
|
1310
|
+
)
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
if (isInstance(value, ArrayBuffer) ||
|
|
1314
|
+
(value && isInstance(value.buffer, ArrayBuffer))) {
|
|
1315
|
+
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
if (typeof SharedArrayBuffer !== 'undefined' &&
|
|
1319
|
+
(isInstance(value, SharedArrayBuffer) ||
|
|
1320
|
+
(value && isInstance(value.buffer, SharedArrayBuffer)))) {
|
|
1321
|
+
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
if (typeof value === 'number') {
|
|
1325
|
+
throw new TypeError(
|
|
1326
|
+
'The "value" argument must not be of type number. Received type number'
|
|
1327
|
+
)
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
1331
|
+
if (valueOf != null && valueOf !== value) {
|
|
1332
|
+
return Buffer.from(valueOf, encodingOrOffset, length)
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
const b = fromObject(value);
|
|
1336
|
+
if (b) return b
|
|
1337
|
+
|
|
1338
|
+
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
|
|
1339
|
+
typeof value[Symbol.toPrimitive] === 'function') {
|
|
1340
|
+
return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
throw new TypeError(
|
|
1344
|
+
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
1345
|
+
'or Array-like Object. Received type ' + (typeof value)
|
|
1346
|
+
)
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
1351
|
+
* if value is a number.
|
|
1352
|
+
* Buffer.from(str[, encoding])
|
|
1353
|
+
* Buffer.from(array)
|
|
1354
|
+
* Buffer.from(buffer)
|
|
1355
|
+
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
1356
|
+
**/
|
|
1357
|
+
Buffer.from = function (value, encodingOrOffset, length) {
|
|
1358
|
+
return from(value, encodingOrOffset, length)
|
|
1359
|
+
};
|
|
1360
|
+
|
|
1361
|
+
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
|
1362
|
+
// https://github.com/feross/buffer/pull/148
|
|
1363
|
+
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
|
|
1364
|
+
Object.setPrototypeOf(Buffer, Uint8Array);
|
|
1365
|
+
|
|
1366
|
+
function assertSize (size) {
|
|
1367
|
+
if (typeof size !== 'number') {
|
|
1368
|
+
throw new TypeError('"size" argument must be of type number')
|
|
1369
|
+
} else if (size < 0) {
|
|
1370
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
function alloc (size, fill, encoding) {
|
|
1375
|
+
assertSize(size);
|
|
1376
|
+
if (size <= 0) {
|
|
1377
|
+
return createBuffer(size)
|
|
1378
|
+
}
|
|
1379
|
+
if (fill !== undefined) {
|
|
1380
|
+
// Only pay attention to encoding if it's a string. This
|
|
1381
|
+
// prevents accidentally sending in a number that would
|
|
1382
|
+
// be interpreted as a start offset.
|
|
1383
|
+
return typeof encoding === 'string'
|
|
1384
|
+
? createBuffer(size).fill(fill, encoding)
|
|
1385
|
+
: createBuffer(size).fill(fill)
|
|
1386
|
+
}
|
|
1387
|
+
return createBuffer(size)
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
/**
|
|
1391
|
+
* Creates a new filled Buffer instance.
|
|
1392
|
+
* alloc(size[, fill[, encoding]])
|
|
1393
|
+
**/
|
|
1394
|
+
Buffer.alloc = function (size, fill, encoding) {
|
|
1395
|
+
return alloc(size, fill, encoding)
|
|
1396
|
+
};
|
|
1397
|
+
|
|
1398
|
+
function allocUnsafe (size) {
|
|
1399
|
+
assertSize(size);
|
|
1400
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
/**
|
|
1404
|
+
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
1405
|
+
* */
|
|
1406
|
+
Buffer.allocUnsafe = function (size) {
|
|
1407
|
+
return allocUnsafe(size)
|
|
1408
|
+
};
|
|
1409
|
+
/**
|
|
1410
|
+
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
1411
|
+
*/
|
|
1412
|
+
Buffer.allocUnsafeSlow = function (size) {
|
|
1413
|
+
return allocUnsafe(size)
|
|
1414
|
+
};
|
|
1415
|
+
|
|
1416
|
+
function fromString (string, encoding) {
|
|
1417
|
+
if (typeof encoding !== 'string' || encoding === '') {
|
|
1418
|
+
encoding = 'utf8';
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
1422
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
const length = byteLength(string, encoding) | 0;
|
|
1426
|
+
let buf = createBuffer(length);
|
|
1427
|
+
|
|
1428
|
+
const actual = buf.write(string, encoding);
|
|
1429
|
+
|
|
1430
|
+
if (actual !== length) {
|
|
1431
|
+
// Writing a hex string, for example, that contains invalid characters will
|
|
1432
|
+
// cause everything after the first invalid character to be ignored. (e.g.
|
|
1433
|
+
// 'abxxcd' will be treated as 'ab')
|
|
1434
|
+
buf = buf.slice(0, actual);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
return buf
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
function fromArrayLike (array) {
|
|
1441
|
+
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
1442
|
+
const buf = createBuffer(length);
|
|
1443
|
+
for (let i = 0; i < length; i += 1) {
|
|
1444
|
+
buf[i] = array[i] & 255;
|
|
1445
|
+
}
|
|
1446
|
+
return buf
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
function fromArrayView (arrayView) {
|
|
1450
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
1451
|
+
const copy = new Uint8Array(arrayView);
|
|
1452
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
|
|
1453
|
+
}
|
|
1454
|
+
return fromArrayLike(arrayView)
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
function fromArrayBuffer (array, byteOffset, length) {
|
|
1458
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
1459
|
+
throw new RangeError('"offset" is outside of buffer bounds')
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
1463
|
+
throw new RangeError('"length" is outside of buffer bounds')
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
let buf;
|
|
1467
|
+
if (byteOffset === undefined && length === undefined) {
|
|
1468
|
+
buf = new Uint8Array(array);
|
|
1469
|
+
} else if (length === undefined) {
|
|
1470
|
+
buf = new Uint8Array(array, byteOffset);
|
|
1471
|
+
} else {
|
|
1472
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
// Return an augmented `Uint8Array` instance
|
|
1476
|
+
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
1477
|
+
|
|
1478
|
+
return buf
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
function fromObject (obj) {
|
|
1482
|
+
if (Buffer.isBuffer(obj)) {
|
|
1483
|
+
const len = checked(obj.length) | 0;
|
|
1484
|
+
const buf = createBuffer(len);
|
|
1485
|
+
|
|
1486
|
+
if (buf.length === 0) {
|
|
1487
|
+
return buf
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
obj.copy(buf, 0, 0, len);
|
|
1491
|
+
return buf
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
if (obj.length !== undefined) {
|
|
1495
|
+
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
|
1496
|
+
return createBuffer(0)
|
|
1497
|
+
}
|
|
1498
|
+
return fromArrayLike(obj)
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
1502
|
+
return fromArrayLike(obj.data)
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
function checked (length) {
|
|
1507
|
+
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
|
|
1508
|
+
// length is NaN (which is otherwise coerced to zero.)
|
|
1509
|
+
if (length >= K_MAX_LENGTH) {
|
|
1510
|
+
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
1511
|
+
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
|
1512
|
+
}
|
|
1513
|
+
return length | 0
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
function SlowBuffer (length) {
|
|
1517
|
+
if (+length != length) { // eslint-disable-line eqeqeq
|
|
1518
|
+
length = 0;
|
|
1519
|
+
}
|
|
1520
|
+
return Buffer.alloc(+length)
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
Buffer.isBuffer = function isBuffer (b) {
|
|
1524
|
+
return b != null && b._isBuffer === true &&
|
|
1525
|
+
b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1528
|
+
Buffer.compare = function compare (a, b) {
|
|
1529
|
+
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
|
|
1530
|
+
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
|
|
1531
|
+
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
|
1532
|
+
throw new TypeError(
|
|
1533
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
1534
|
+
)
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
if (a === b) return 0
|
|
1538
|
+
|
|
1539
|
+
let x = a.length;
|
|
1540
|
+
let y = b.length;
|
|
1541
|
+
|
|
1542
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
1543
|
+
if (a[i] !== b[i]) {
|
|
1544
|
+
x = a[i];
|
|
1545
|
+
y = b[i];
|
|
1546
|
+
break
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
if (x < y) return -1
|
|
1551
|
+
if (y < x) return 1
|
|
1552
|
+
return 0
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
Buffer.isEncoding = function isEncoding (encoding) {
|
|
1556
|
+
switch (String(encoding).toLowerCase()) {
|
|
1557
|
+
case 'hex':
|
|
1558
|
+
case 'utf8':
|
|
1559
|
+
case 'utf-8':
|
|
1560
|
+
case 'ascii':
|
|
1561
|
+
case 'latin1':
|
|
1562
|
+
case 'binary':
|
|
1563
|
+
case 'base64':
|
|
1564
|
+
case 'ucs2':
|
|
1565
|
+
case 'ucs-2':
|
|
1566
|
+
case 'utf16le':
|
|
1567
|
+
case 'utf-16le':
|
|
1568
|
+
return true
|
|
1569
|
+
default:
|
|
1570
|
+
return false
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
|
|
1574
|
+
Buffer.concat = function concat (list, length) {
|
|
1575
|
+
if (!Array.isArray(list)) {
|
|
1576
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
if (list.length === 0) {
|
|
1580
|
+
return Buffer.alloc(0)
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
let i;
|
|
1584
|
+
if (length === undefined) {
|
|
1585
|
+
length = 0;
|
|
1586
|
+
for (i = 0; i < list.length; ++i) {
|
|
1587
|
+
length += list[i].length;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
1592
|
+
let pos = 0;
|
|
1593
|
+
for (i = 0; i < list.length; ++i) {
|
|
1594
|
+
let buf = list[i];
|
|
1595
|
+
if (isInstance(buf, Uint8Array)) {
|
|
1596
|
+
if (pos + buf.length > buffer.length) {
|
|
1597
|
+
if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
|
|
1598
|
+
buf.copy(buffer, pos);
|
|
1599
|
+
} else {
|
|
1600
|
+
Uint8Array.prototype.set.call(
|
|
1601
|
+
buffer,
|
|
1602
|
+
buf,
|
|
1603
|
+
pos
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
} else if (!Buffer.isBuffer(buf)) {
|
|
1607
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
1608
|
+
} else {
|
|
1609
|
+
buf.copy(buffer, pos);
|
|
1610
|
+
}
|
|
1611
|
+
pos += buf.length;
|
|
1612
|
+
}
|
|
1613
|
+
return buffer
|
|
1614
|
+
};
|
|
1615
|
+
|
|
1616
|
+
function byteLength (string, encoding) {
|
|
1617
|
+
if (Buffer.isBuffer(string)) {
|
|
1618
|
+
return string.length
|
|
1619
|
+
}
|
|
1620
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
1621
|
+
return string.byteLength
|
|
1622
|
+
}
|
|
1623
|
+
if (typeof string !== 'string') {
|
|
1624
|
+
throw new TypeError(
|
|
1625
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
|
1626
|
+
'Received type ' + typeof string
|
|
1627
|
+
)
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
const len = string.length;
|
|
1631
|
+
const mustMatch = (arguments.length > 2 && arguments[2] === true);
|
|
1632
|
+
if (!mustMatch && len === 0) return 0
|
|
1633
|
+
|
|
1634
|
+
// Use a for loop to avoid recursion
|
|
1635
|
+
let loweredCase = false;
|
|
1636
|
+
for (;;) {
|
|
1637
|
+
switch (encoding) {
|
|
1638
|
+
case 'ascii':
|
|
1639
|
+
case 'latin1':
|
|
1640
|
+
case 'binary':
|
|
1641
|
+
return len
|
|
1642
|
+
case 'utf8':
|
|
1643
|
+
case 'utf-8':
|
|
1644
|
+
return utf8ToBytes(string).length
|
|
1645
|
+
case 'ucs2':
|
|
1646
|
+
case 'ucs-2':
|
|
1647
|
+
case 'utf16le':
|
|
1648
|
+
case 'utf-16le':
|
|
1649
|
+
return len * 2
|
|
1650
|
+
case 'hex':
|
|
1651
|
+
return len >>> 1
|
|
1652
|
+
case 'base64':
|
|
1653
|
+
return base64ToBytes(string).length
|
|
1654
|
+
default:
|
|
1655
|
+
if (loweredCase) {
|
|
1656
|
+
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
|
|
1657
|
+
}
|
|
1658
|
+
encoding = ('' + encoding).toLowerCase();
|
|
1659
|
+
loweredCase = true;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
Buffer.byteLength = byteLength;
|
|
1664
|
+
|
|
1665
|
+
function slowToString (encoding, start, end) {
|
|
1666
|
+
let loweredCase = false;
|
|
1667
|
+
|
|
1668
|
+
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
1669
|
+
// property of a typed array.
|
|
1670
|
+
|
|
1671
|
+
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
1672
|
+
// to their upper/lower bounds if the value passed is out of range.
|
|
1673
|
+
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
1674
|
+
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
1675
|
+
if (start === undefined || start < 0) {
|
|
1676
|
+
start = 0;
|
|
1677
|
+
}
|
|
1678
|
+
// Return early if start > this.length. Done here to prevent potential uint32
|
|
1679
|
+
// coercion fail below.
|
|
1680
|
+
if (start > this.length) {
|
|
1681
|
+
return ''
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
if (end === undefined || end > this.length) {
|
|
1685
|
+
end = this.length;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
if (end <= 0) {
|
|
1689
|
+
return ''
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
// Force coercion to uint32. This will also coerce falsey/NaN values to 0.
|
|
1693
|
+
end >>>= 0;
|
|
1694
|
+
start >>>= 0;
|
|
1695
|
+
|
|
1696
|
+
if (end <= start) {
|
|
1697
|
+
return ''
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
if (!encoding) encoding = 'utf8';
|
|
1701
|
+
|
|
1702
|
+
while (true) {
|
|
1703
|
+
switch (encoding) {
|
|
1704
|
+
case 'hex':
|
|
1705
|
+
return hexSlice(this, start, end)
|
|
1706
|
+
|
|
1707
|
+
case 'utf8':
|
|
1708
|
+
case 'utf-8':
|
|
1709
|
+
return utf8Slice(this, start, end)
|
|
1710
|
+
|
|
1711
|
+
case 'ascii':
|
|
1712
|
+
return asciiSlice(this, start, end)
|
|
1713
|
+
|
|
1714
|
+
case 'latin1':
|
|
1715
|
+
case 'binary':
|
|
1716
|
+
return latin1Slice(this, start, end)
|
|
1717
|
+
|
|
1718
|
+
case 'base64':
|
|
1719
|
+
return base64Slice(this, start, end)
|
|
1720
|
+
|
|
1721
|
+
case 'ucs2':
|
|
1722
|
+
case 'ucs-2':
|
|
1723
|
+
case 'utf16le':
|
|
1724
|
+
case 'utf-16le':
|
|
1725
|
+
return utf16leSlice(this, start, end)
|
|
1726
|
+
|
|
1727
|
+
default:
|
|
1728
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
1729
|
+
encoding = (encoding + '').toLowerCase();
|
|
1730
|
+
loweredCase = true;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
|
1736
|
+
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
|
1737
|
+
// reliably in a browserify context because there could be multiple different
|
|
1738
|
+
// copies of the 'buffer' package in use. This method works even for Buffer
|
|
1739
|
+
// instances that were created from another copy of the `buffer` package.
|
|
1740
|
+
// See: https://github.com/feross/buffer/issues/154
|
|
1741
|
+
Buffer.prototype._isBuffer = true;
|
|
1742
|
+
|
|
1743
|
+
function swap (b, n, m) {
|
|
1744
|
+
const i = b[n];
|
|
1745
|
+
b[n] = b[m];
|
|
1746
|
+
b[m] = i;
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
Buffer.prototype.swap16 = function swap16 () {
|
|
1750
|
+
const len = this.length;
|
|
1751
|
+
if (len % 2 !== 0) {
|
|
1752
|
+
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
1753
|
+
}
|
|
1754
|
+
for (let i = 0; i < len; i += 2) {
|
|
1755
|
+
swap(this, i, i + 1);
|
|
1756
|
+
}
|
|
1757
|
+
return this
|
|
1758
|
+
};
|
|
1759
|
+
|
|
1760
|
+
Buffer.prototype.swap32 = function swap32 () {
|
|
1761
|
+
const len = this.length;
|
|
1762
|
+
if (len % 4 !== 0) {
|
|
1763
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
1764
|
+
}
|
|
1765
|
+
for (let i = 0; i < len; i += 4) {
|
|
1766
|
+
swap(this, i, i + 3);
|
|
1767
|
+
swap(this, i + 1, i + 2);
|
|
1768
|
+
}
|
|
1769
|
+
return this
|
|
1770
|
+
};
|
|
1771
|
+
|
|
1772
|
+
Buffer.prototype.swap64 = function swap64 () {
|
|
1773
|
+
const len = this.length;
|
|
1774
|
+
if (len % 8 !== 0) {
|
|
1775
|
+
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
1776
|
+
}
|
|
1777
|
+
for (let i = 0; i < len; i += 8) {
|
|
1778
|
+
swap(this, i, i + 7);
|
|
1779
|
+
swap(this, i + 1, i + 6);
|
|
1780
|
+
swap(this, i + 2, i + 5);
|
|
1781
|
+
swap(this, i + 3, i + 4);
|
|
1782
|
+
}
|
|
1783
|
+
return this
|
|
1784
|
+
};
|
|
1785
|
+
|
|
1786
|
+
Buffer.prototype.toString = function toString () {
|
|
1787
|
+
const length = this.length;
|
|
1788
|
+
if (length === 0) return ''
|
|
1789
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
1790
|
+
return slowToString.apply(this, arguments)
|
|
1791
|
+
};
|
|
1792
|
+
|
|
1793
|
+
Buffer.prototype.toLocaleString = Buffer.prototype.toString;
|
|
1794
|
+
|
|
1795
|
+
Buffer.prototype.equals = function equals (b) {
|
|
1796
|
+
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
1797
|
+
if (this === b) return true
|
|
1798
|
+
return Buffer.compare(this, b) === 0
|
|
1799
|
+
};
|
|
1800
|
+
|
|
1801
|
+
Buffer.prototype.inspect = function inspect () {
|
|
1802
|
+
let str = '';
|
|
1803
|
+
const max = exports$1.INSPECT_MAX_BYTES;
|
|
1804
|
+
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
|
|
1805
|
+
if (this.length > max) str += ' ... ';
|
|
1806
|
+
return '<Buffer ' + str + '>'
|
|
1807
|
+
};
|
|
1808
|
+
if (customInspectSymbol) {
|
|
1809
|
+
Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
1813
|
+
if (isInstance(target, Uint8Array)) {
|
|
1814
|
+
target = Buffer.from(target, target.offset, target.byteLength);
|
|
1815
|
+
}
|
|
1816
|
+
if (!Buffer.isBuffer(target)) {
|
|
1817
|
+
throw new TypeError(
|
|
1818
|
+
'The "target" argument must be one of type Buffer or Uint8Array. ' +
|
|
1819
|
+
'Received type ' + (typeof target)
|
|
1820
|
+
)
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
if (start === undefined) {
|
|
1824
|
+
start = 0;
|
|
1825
|
+
}
|
|
1826
|
+
if (end === undefined) {
|
|
1827
|
+
end = target ? target.length : 0;
|
|
1828
|
+
}
|
|
1829
|
+
if (thisStart === undefined) {
|
|
1830
|
+
thisStart = 0;
|
|
1831
|
+
}
|
|
1832
|
+
if (thisEnd === undefined) {
|
|
1833
|
+
thisEnd = this.length;
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
1837
|
+
throw new RangeError('out of range index')
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
1841
|
+
return 0
|
|
1842
|
+
}
|
|
1843
|
+
if (thisStart >= thisEnd) {
|
|
1844
|
+
return -1
|
|
1845
|
+
}
|
|
1846
|
+
if (start >= end) {
|
|
1847
|
+
return 1
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
start >>>= 0;
|
|
1851
|
+
end >>>= 0;
|
|
1852
|
+
thisStart >>>= 0;
|
|
1853
|
+
thisEnd >>>= 0;
|
|
1854
|
+
|
|
1855
|
+
if (this === target) return 0
|
|
1856
|
+
|
|
1857
|
+
let x = thisEnd - thisStart;
|
|
1858
|
+
let y = end - start;
|
|
1859
|
+
const len = Math.min(x, y);
|
|
1860
|
+
|
|
1861
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
1862
|
+
const targetCopy = target.slice(start, end);
|
|
1863
|
+
|
|
1864
|
+
for (let i = 0; i < len; ++i) {
|
|
1865
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
1866
|
+
x = thisCopy[i];
|
|
1867
|
+
y = targetCopy[i];
|
|
1868
|
+
break
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
if (x < y) return -1
|
|
1873
|
+
if (y < x) return 1
|
|
1874
|
+
return 0
|
|
1875
|
+
};
|
|
1876
|
+
|
|
1877
|
+
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
1878
|
+
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
1879
|
+
//
|
|
1880
|
+
// Arguments:
|
|
1881
|
+
// - buffer - a Buffer to search
|
|
1882
|
+
// - val - a string, Buffer, or number
|
|
1883
|
+
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
1884
|
+
// - encoding - an optional encoding, relevant is val is a string
|
|
1885
|
+
// - dir - true for indexOf, false for lastIndexOf
|
|
1886
|
+
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
1887
|
+
// Empty buffer means no match
|
|
1888
|
+
if (buffer.length === 0) return -1
|
|
1889
|
+
|
|
1890
|
+
// Normalize byteOffset
|
|
1891
|
+
if (typeof byteOffset === 'string') {
|
|
1892
|
+
encoding = byteOffset;
|
|
1893
|
+
byteOffset = 0;
|
|
1894
|
+
} else if (byteOffset > 0x7fffffff) {
|
|
1895
|
+
byteOffset = 0x7fffffff;
|
|
1896
|
+
} else if (byteOffset < -2147483648) {
|
|
1897
|
+
byteOffset = -2147483648;
|
|
1898
|
+
}
|
|
1899
|
+
byteOffset = +byteOffset; // Coerce to Number.
|
|
1900
|
+
if (numberIsNaN(byteOffset)) {
|
|
1901
|
+
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
1902
|
+
byteOffset = dir ? 0 : (buffer.length - 1);
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
1906
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
1907
|
+
if (byteOffset >= buffer.length) {
|
|
1908
|
+
if (dir) return -1
|
|
1909
|
+
else byteOffset = buffer.length - 1;
|
|
1910
|
+
} else if (byteOffset < 0) {
|
|
1911
|
+
if (dir) byteOffset = 0;
|
|
1912
|
+
else return -1
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
// Normalize val
|
|
1916
|
+
if (typeof val === 'string') {
|
|
1917
|
+
val = Buffer.from(val, encoding);
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
1921
|
+
if (Buffer.isBuffer(val)) {
|
|
1922
|
+
// Special case: looking for empty string/buffer always fails
|
|
1923
|
+
if (val.length === 0) {
|
|
1924
|
+
return -1
|
|
1925
|
+
}
|
|
1926
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
1927
|
+
} else if (typeof val === 'number') {
|
|
1928
|
+
val = val & 0xFF; // Search for a byte value [0-255]
|
|
1929
|
+
if (typeof Uint8Array.prototype.indexOf === 'function') {
|
|
1930
|
+
if (dir) {
|
|
1931
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
1932
|
+
} else {
|
|
1933
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
throw new TypeError('val must be string, number or Buffer')
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
1943
|
+
let indexSize = 1;
|
|
1944
|
+
let arrLength = arr.length;
|
|
1945
|
+
let valLength = val.length;
|
|
1946
|
+
|
|
1947
|
+
if (encoding !== undefined) {
|
|
1948
|
+
encoding = String(encoding).toLowerCase();
|
|
1949
|
+
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
1950
|
+
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
1951
|
+
if (arr.length < 2 || val.length < 2) {
|
|
1952
|
+
return -1
|
|
1953
|
+
}
|
|
1954
|
+
indexSize = 2;
|
|
1955
|
+
arrLength /= 2;
|
|
1956
|
+
valLength /= 2;
|
|
1957
|
+
byteOffset /= 2;
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
function read (buf, i) {
|
|
1962
|
+
if (indexSize === 1) {
|
|
1963
|
+
return buf[i]
|
|
1964
|
+
} else {
|
|
1965
|
+
return buf.readUInt16BE(i * indexSize)
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
let i;
|
|
1970
|
+
if (dir) {
|
|
1971
|
+
let foundIndex = -1;
|
|
1972
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
1973
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
1974
|
+
if (foundIndex === -1) foundIndex = i;
|
|
1975
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
1976
|
+
} else {
|
|
1977
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
1978
|
+
foundIndex = -1;
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
} else {
|
|
1982
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
1983
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
1984
|
+
let found = true;
|
|
1985
|
+
for (let j = 0; j < valLength; j++) {
|
|
1986
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
1987
|
+
found = false;
|
|
1988
|
+
break
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
if (found) return i
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
return -1
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
1999
|
+
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
2000
|
+
};
|
|
2001
|
+
|
|
2002
|
+
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
2003
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
2004
|
+
};
|
|
2005
|
+
|
|
2006
|
+
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
2007
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
2008
|
+
};
|
|
2009
|
+
|
|
2010
|
+
function hexWrite (buf, string, offset, length) {
|
|
2011
|
+
offset = Number(offset) || 0;
|
|
2012
|
+
const remaining = buf.length - offset;
|
|
2013
|
+
if (!length) {
|
|
2014
|
+
length = remaining;
|
|
2015
|
+
} else {
|
|
2016
|
+
length = Number(length);
|
|
2017
|
+
if (length > remaining) {
|
|
2018
|
+
length = remaining;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
const strLen = string.length;
|
|
2023
|
+
|
|
2024
|
+
if (length > strLen / 2) {
|
|
2025
|
+
length = strLen / 2;
|
|
2026
|
+
}
|
|
2027
|
+
let i;
|
|
2028
|
+
for (i = 0; i < length; ++i) {
|
|
2029
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
2030
|
+
if (numberIsNaN(parsed)) return i
|
|
2031
|
+
buf[offset + i] = parsed;
|
|
2032
|
+
}
|
|
2033
|
+
return i
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
function utf8Write (buf, string, offset, length) {
|
|
2037
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
function asciiWrite (buf, string, offset, length) {
|
|
2041
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
function base64Write (buf, string, offset, length) {
|
|
2045
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
function ucs2Write (buf, string, offset, length) {
|
|
2049
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
2053
|
+
// Buffer#write(string)
|
|
2054
|
+
if (offset === undefined) {
|
|
2055
|
+
encoding = 'utf8';
|
|
2056
|
+
length = this.length;
|
|
2057
|
+
offset = 0;
|
|
2058
|
+
// Buffer#write(string, encoding)
|
|
2059
|
+
} else if (length === undefined && typeof offset === 'string') {
|
|
2060
|
+
encoding = offset;
|
|
2061
|
+
length = this.length;
|
|
2062
|
+
offset = 0;
|
|
2063
|
+
// Buffer#write(string, offset[, length][, encoding])
|
|
2064
|
+
} else if (isFinite(offset)) {
|
|
2065
|
+
offset = offset >>> 0;
|
|
2066
|
+
if (isFinite(length)) {
|
|
2067
|
+
length = length >>> 0;
|
|
2068
|
+
if (encoding === undefined) encoding = 'utf8';
|
|
2069
|
+
} else {
|
|
2070
|
+
encoding = length;
|
|
2071
|
+
length = undefined;
|
|
2072
|
+
}
|
|
2073
|
+
} else {
|
|
2074
|
+
throw new Error(
|
|
2075
|
+
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
2076
|
+
)
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
const remaining = this.length - offset;
|
|
2080
|
+
if (length === undefined || length > remaining) length = remaining;
|
|
2081
|
+
|
|
2082
|
+
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
2083
|
+
throw new RangeError('Attempt to write outside buffer bounds')
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
if (!encoding) encoding = 'utf8';
|
|
2087
|
+
|
|
2088
|
+
let loweredCase = false;
|
|
2089
|
+
for (;;) {
|
|
2090
|
+
switch (encoding) {
|
|
2091
|
+
case 'hex':
|
|
2092
|
+
return hexWrite(this, string, offset, length)
|
|
2093
|
+
|
|
2094
|
+
case 'utf8':
|
|
2095
|
+
case 'utf-8':
|
|
2096
|
+
return utf8Write(this, string, offset, length)
|
|
2097
|
+
|
|
2098
|
+
case 'ascii':
|
|
2099
|
+
case 'latin1':
|
|
2100
|
+
case 'binary':
|
|
2101
|
+
return asciiWrite(this, string, offset, length)
|
|
2102
|
+
|
|
2103
|
+
case 'base64':
|
|
2104
|
+
// Warning: maxLength not taken into account in base64Write
|
|
2105
|
+
return base64Write(this, string, offset, length)
|
|
2106
|
+
|
|
2107
|
+
case 'ucs2':
|
|
2108
|
+
case 'ucs-2':
|
|
2109
|
+
case 'utf16le':
|
|
2110
|
+
case 'utf-16le':
|
|
2111
|
+
return ucs2Write(this, string, offset, length)
|
|
2112
|
+
|
|
2113
|
+
default:
|
|
2114
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
2115
|
+
encoding = ('' + encoding).toLowerCase();
|
|
2116
|
+
loweredCase = true;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
};
|
|
2120
|
+
|
|
2121
|
+
Buffer.prototype.toJSON = function toJSON () {
|
|
2122
|
+
return {
|
|
2123
|
+
type: 'Buffer',
|
|
2124
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
2125
|
+
}
|
|
2126
|
+
};
|
|
2127
|
+
|
|
2128
|
+
function base64Slice (buf, start, end) {
|
|
2129
|
+
if (start === 0 && end === buf.length) {
|
|
2130
|
+
return base64.fromByteArray(buf)
|
|
2131
|
+
} else {
|
|
2132
|
+
return base64.fromByteArray(buf.slice(start, end))
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
function utf8Slice (buf, start, end) {
|
|
2137
|
+
end = Math.min(buf.length, end);
|
|
2138
|
+
const res = [];
|
|
2139
|
+
|
|
2140
|
+
let i = start;
|
|
2141
|
+
while (i < end) {
|
|
2142
|
+
const firstByte = buf[i];
|
|
2143
|
+
let codePoint = null;
|
|
2144
|
+
let bytesPerSequence = (firstByte > 0xEF)
|
|
2145
|
+
? 4
|
|
2146
|
+
: (firstByte > 0xDF)
|
|
2147
|
+
? 3
|
|
2148
|
+
: (firstByte > 0xBF)
|
|
2149
|
+
? 2
|
|
2150
|
+
: 1;
|
|
2151
|
+
|
|
2152
|
+
if (i + bytesPerSequence <= end) {
|
|
2153
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
2154
|
+
|
|
2155
|
+
switch (bytesPerSequence) {
|
|
2156
|
+
case 1:
|
|
2157
|
+
if (firstByte < 0x80) {
|
|
2158
|
+
codePoint = firstByte;
|
|
2159
|
+
}
|
|
2160
|
+
break
|
|
2161
|
+
case 2:
|
|
2162
|
+
secondByte = buf[i + 1];
|
|
2163
|
+
if ((secondByte & 0xC0) === 0x80) {
|
|
2164
|
+
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
|
|
2165
|
+
if (tempCodePoint > 0x7F) {
|
|
2166
|
+
codePoint = tempCodePoint;
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
break
|
|
2170
|
+
case 3:
|
|
2171
|
+
secondByte = buf[i + 1];
|
|
2172
|
+
thirdByte = buf[i + 2];
|
|
2173
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
2174
|
+
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
|
|
2175
|
+
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
2176
|
+
codePoint = tempCodePoint;
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
break
|
|
2180
|
+
case 4:
|
|
2181
|
+
secondByte = buf[i + 1];
|
|
2182
|
+
thirdByte = buf[i + 2];
|
|
2183
|
+
fourthByte = buf[i + 3];
|
|
2184
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
2185
|
+
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
|
|
2186
|
+
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
2187
|
+
codePoint = tempCodePoint;
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
if (codePoint === null) {
|
|
2194
|
+
// we did not generate a valid codePoint so insert a
|
|
2195
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
|
2196
|
+
codePoint = 0xFFFD;
|
|
2197
|
+
bytesPerSequence = 1;
|
|
2198
|
+
} else if (codePoint > 0xFFFF) {
|
|
2199
|
+
// encode to utf16 (surrogate pair dance)
|
|
2200
|
+
codePoint -= 0x10000;
|
|
2201
|
+
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
|
|
2202
|
+
codePoint = 0xDC00 | codePoint & 0x3FF;
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
res.push(codePoint);
|
|
2206
|
+
i += bytesPerSequence;
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
return decodeCodePointsArray(res)
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
2213
|
+
// the lowest limit is Chrome, with 0x10000 args.
|
|
2214
|
+
// We go 1 magnitude less, for safety
|
|
2215
|
+
const MAX_ARGUMENTS_LENGTH = 0x1000;
|
|
2216
|
+
|
|
2217
|
+
function decodeCodePointsArray (codePoints) {
|
|
2218
|
+
const len = codePoints.length;
|
|
2219
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
2220
|
+
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
// Decode in chunks to avoid "call stack size exceeded".
|
|
2224
|
+
let res = '';
|
|
2225
|
+
let i = 0;
|
|
2226
|
+
while (i < len) {
|
|
2227
|
+
res += String.fromCharCode.apply(
|
|
2228
|
+
String,
|
|
2229
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
2230
|
+
);
|
|
2231
|
+
}
|
|
2232
|
+
return res
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
function asciiSlice (buf, start, end) {
|
|
2236
|
+
let ret = '';
|
|
2237
|
+
end = Math.min(buf.length, end);
|
|
2238
|
+
|
|
2239
|
+
for (let i = start; i < end; ++i) {
|
|
2240
|
+
ret += String.fromCharCode(buf[i] & 0x7F);
|
|
2241
|
+
}
|
|
2242
|
+
return ret
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
function latin1Slice (buf, start, end) {
|
|
2246
|
+
let ret = '';
|
|
2247
|
+
end = Math.min(buf.length, end);
|
|
2248
|
+
|
|
2249
|
+
for (let i = start; i < end; ++i) {
|
|
2250
|
+
ret += String.fromCharCode(buf[i]);
|
|
2251
|
+
}
|
|
2252
|
+
return ret
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
function hexSlice (buf, start, end) {
|
|
2256
|
+
const len = buf.length;
|
|
2257
|
+
|
|
2258
|
+
if (!start || start < 0) start = 0;
|
|
2259
|
+
if (!end || end < 0 || end > len) end = len;
|
|
2260
|
+
|
|
2261
|
+
let out = '';
|
|
2262
|
+
for (let i = start; i < end; ++i) {
|
|
2263
|
+
out += hexSliceLookupTable[buf[i]];
|
|
2264
|
+
}
|
|
2265
|
+
return out
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2268
|
+
function utf16leSlice (buf, start, end) {
|
|
2269
|
+
const bytes = buf.slice(start, end);
|
|
2270
|
+
let res = '';
|
|
2271
|
+
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
|
|
2272
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
2273
|
+
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
|
|
2274
|
+
}
|
|
2275
|
+
return res
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
Buffer.prototype.slice = function slice (start, end) {
|
|
2279
|
+
const len = this.length;
|
|
2280
|
+
start = ~~start;
|
|
2281
|
+
end = end === undefined ? len : ~~end;
|
|
2282
|
+
|
|
2283
|
+
if (start < 0) {
|
|
2284
|
+
start += len;
|
|
2285
|
+
if (start < 0) start = 0;
|
|
2286
|
+
} else if (start > len) {
|
|
2287
|
+
start = len;
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
if (end < 0) {
|
|
2291
|
+
end += len;
|
|
2292
|
+
if (end < 0) end = 0;
|
|
2293
|
+
} else if (end > len) {
|
|
2294
|
+
end = len;
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
if (end < start) end = start;
|
|
2298
|
+
|
|
2299
|
+
const newBuf = this.subarray(start, end);
|
|
2300
|
+
// Return an augmented `Uint8Array` instance
|
|
2301
|
+
Object.setPrototypeOf(newBuf, Buffer.prototype);
|
|
2302
|
+
|
|
2303
|
+
return newBuf
|
|
2304
|
+
};
|
|
2305
|
+
|
|
2306
|
+
/*
|
|
2307
|
+
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
2308
|
+
*/
|
|
2309
|
+
function checkOffset (offset, ext, length) {
|
|
2310
|
+
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
2311
|
+
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
Buffer.prototype.readUintLE =
|
|
2315
|
+
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
2316
|
+
offset = offset >>> 0;
|
|
2317
|
+
byteLength = byteLength >>> 0;
|
|
2318
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
2319
|
+
|
|
2320
|
+
let val = this[offset];
|
|
2321
|
+
let mul = 1;
|
|
2322
|
+
let i = 0;
|
|
2323
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
2324
|
+
val += this[offset + i] * mul;
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
return val
|
|
2328
|
+
};
|
|
2329
|
+
|
|
2330
|
+
Buffer.prototype.readUintBE =
|
|
2331
|
+
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
2332
|
+
offset = offset >>> 0;
|
|
2333
|
+
byteLength = byteLength >>> 0;
|
|
2334
|
+
if (!noAssert) {
|
|
2335
|
+
checkOffset(offset, byteLength, this.length);
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
let val = this[offset + --byteLength];
|
|
2339
|
+
let mul = 1;
|
|
2340
|
+
while (byteLength > 0 && (mul *= 0x100)) {
|
|
2341
|
+
val += this[offset + --byteLength] * mul;
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
return val
|
|
2345
|
+
};
|
|
2346
|
+
|
|
2347
|
+
Buffer.prototype.readUint8 =
|
|
2348
|
+
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
2349
|
+
offset = offset >>> 0;
|
|
2350
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
2351
|
+
return this[offset]
|
|
2352
|
+
};
|
|
2353
|
+
|
|
2354
|
+
Buffer.prototype.readUint16LE =
|
|
2355
|
+
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
2356
|
+
offset = offset >>> 0;
|
|
2357
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
2358
|
+
return this[offset] | (this[offset + 1] << 8)
|
|
2359
|
+
};
|
|
2360
|
+
|
|
2361
|
+
Buffer.prototype.readUint16BE =
|
|
2362
|
+
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
2363
|
+
offset = offset >>> 0;
|
|
2364
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
2365
|
+
return (this[offset] << 8) | this[offset + 1]
|
|
2366
|
+
};
|
|
2367
|
+
|
|
2368
|
+
Buffer.prototype.readUint32LE =
|
|
2369
|
+
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
2370
|
+
offset = offset >>> 0;
|
|
2371
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2372
|
+
|
|
2373
|
+
return ((this[offset]) |
|
|
2374
|
+
(this[offset + 1] << 8) |
|
|
2375
|
+
(this[offset + 2] << 16)) +
|
|
2376
|
+
(this[offset + 3] * 0x1000000)
|
|
2377
|
+
};
|
|
2378
|
+
|
|
2379
|
+
Buffer.prototype.readUint32BE =
|
|
2380
|
+
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
2381
|
+
offset = offset >>> 0;
|
|
2382
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2383
|
+
|
|
2384
|
+
return (this[offset] * 0x1000000) +
|
|
2385
|
+
((this[offset + 1] << 16) |
|
|
2386
|
+
(this[offset + 2] << 8) |
|
|
2387
|
+
this[offset + 3])
|
|
2388
|
+
};
|
|
2389
|
+
|
|
2390
|
+
Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
|
|
2391
|
+
offset = offset >>> 0;
|
|
2392
|
+
validateNumber(offset, 'offset');
|
|
2393
|
+
const first = this[offset];
|
|
2394
|
+
const last = this[offset + 7];
|
|
2395
|
+
if (first === undefined || last === undefined) {
|
|
2396
|
+
boundsError(offset, this.length - 8);
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
const lo = first +
|
|
2400
|
+
this[++offset] * 2 ** 8 +
|
|
2401
|
+
this[++offset] * 2 ** 16 +
|
|
2402
|
+
this[++offset] * 2 ** 24;
|
|
2403
|
+
|
|
2404
|
+
const hi = this[++offset] +
|
|
2405
|
+
this[++offset] * 2 ** 8 +
|
|
2406
|
+
this[++offset] * 2 ** 16 +
|
|
2407
|
+
last * 2 ** 24;
|
|
2408
|
+
|
|
2409
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32))
|
|
2410
|
+
});
|
|
2411
|
+
|
|
2412
|
+
Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
|
|
2413
|
+
offset = offset >>> 0;
|
|
2414
|
+
validateNumber(offset, 'offset');
|
|
2415
|
+
const first = this[offset];
|
|
2416
|
+
const last = this[offset + 7];
|
|
2417
|
+
if (first === undefined || last === undefined) {
|
|
2418
|
+
boundsError(offset, this.length - 8);
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
const hi = first * 2 ** 24 +
|
|
2422
|
+
this[++offset] * 2 ** 16 +
|
|
2423
|
+
this[++offset] * 2 ** 8 +
|
|
2424
|
+
this[++offset];
|
|
2425
|
+
|
|
2426
|
+
const lo = this[++offset] * 2 ** 24 +
|
|
2427
|
+
this[++offset] * 2 ** 16 +
|
|
2428
|
+
this[++offset] * 2 ** 8 +
|
|
2429
|
+
last;
|
|
2430
|
+
|
|
2431
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo)
|
|
2432
|
+
});
|
|
2433
|
+
|
|
2434
|
+
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
|
2435
|
+
offset = offset >>> 0;
|
|
2436
|
+
byteLength = byteLength >>> 0;
|
|
2437
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
2438
|
+
|
|
2439
|
+
let val = this[offset];
|
|
2440
|
+
let mul = 1;
|
|
2441
|
+
let i = 0;
|
|
2442
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
2443
|
+
val += this[offset + i] * mul;
|
|
2444
|
+
}
|
|
2445
|
+
mul *= 0x80;
|
|
2446
|
+
|
|
2447
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
2448
|
+
|
|
2449
|
+
return val
|
|
2450
|
+
};
|
|
2451
|
+
|
|
2452
|
+
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
|
2453
|
+
offset = offset >>> 0;
|
|
2454
|
+
byteLength = byteLength >>> 0;
|
|
2455
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
2456
|
+
|
|
2457
|
+
let i = byteLength;
|
|
2458
|
+
let mul = 1;
|
|
2459
|
+
let val = this[offset + --i];
|
|
2460
|
+
while (i > 0 && (mul *= 0x100)) {
|
|
2461
|
+
val += this[offset + --i] * mul;
|
|
2462
|
+
}
|
|
2463
|
+
mul *= 0x80;
|
|
2464
|
+
|
|
2465
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
2466
|
+
|
|
2467
|
+
return val
|
|
2468
|
+
};
|
|
2469
|
+
|
|
2470
|
+
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
|
2471
|
+
offset = offset >>> 0;
|
|
2472
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
2473
|
+
if (!(this[offset] & 0x80)) return (this[offset])
|
|
2474
|
+
return ((0xff - this[offset] + 1) * -1)
|
|
2475
|
+
};
|
|
2476
|
+
|
|
2477
|
+
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
2478
|
+
offset = offset >>> 0;
|
|
2479
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
2480
|
+
const val = this[offset] | (this[offset + 1] << 8);
|
|
2481
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
2482
|
+
};
|
|
2483
|
+
|
|
2484
|
+
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
2485
|
+
offset = offset >>> 0;
|
|
2486
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
2487
|
+
const val = this[offset + 1] | (this[offset] << 8);
|
|
2488
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
2489
|
+
};
|
|
2490
|
+
|
|
2491
|
+
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
2492
|
+
offset = offset >>> 0;
|
|
2493
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2494
|
+
|
|
2495
|
+
return (this[offset]) |
|
|
2496
|
+
(this[offset + 1] << 8) |
|
|
2497
|
+
(this[offset + 2] << 16) |
|
|
2498
|
+
(this[offset + 3] << 24)
|
|
2499
|
+
};
|
|
2500
|
+
|
|
2501
|
+
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
2502
|
+
offset = offset >>> 0;
|
|
2503
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2504
|
+
|
|
2505
|
+
return (this[offset] << 24) |
|
|
2506
|
+
(this[offset + 1] << 16) |
|
|
2507
|
+
(this[offset + 2] << 8) |
|
|
2508
|
+
(this[offset + 3])
|
|
2509
|
+
};
|
|
2510
|
+
|
|
2511
|
+
Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
|
|
2512
|
+
offset = offset >>> 0;
|
|
2513
|
+
validateNumber(offset, 'offset');
|
|
2514
|
+
const first = this[offset];
|
|
2515
|
+
const last = this[offset + 7];
|
|
2516
|
+
if (first === undefined || last === undefined) {
|
|
2517
|
+
boundsError(offset, this.length - 8);
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
const val = this[offset + 4] +
|
|
2521
|
+
this[offset + 5] * 2 ** 8 +
|
|
2522
|
+
this[offset + 6] * 2 ** 16 +
|
|
2523
|
+
(last << 24); // Overflow
|
|
2524
|
+
|
|
2525
|
+
return (BigInt(val) << BigInt(32)) +
|
|
2526
|
+
BigInt(first +
|
|
2527
|
+
this[++offset] * 2 ** 8 +
|
|
2528
|
+
this[++offset] * 2 ** 16 +
|
|
2529
|
+
this[++offset] * 2 ** 24)
|
|
2530
|
+
});
|
|
2531
|
+
|
|
2532
|
+
Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
|
|
2533
|
+
offset = offset >>> 0;
|
|
2534
|
+
validateNumber(offset, 'offset');
|
|
2535
|
+
const first = this[offset];
|
|
2536
|
+
const last = this[offset + 7];
|
|
2537
|
+
if (first === undefined || last === undefined) {
|
|
2538
|
+
boundsError(offset, this.length - 8);
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
const val = (first << 24) + // Overflow
|
|
2542
|
+
this[++offset] * 2 ** 16 +
|
|
2543
|
+
this[++offset] * 2 ** 8 +
|
|
2544
|
+
this[++offset];
|
|
2545
|
+
|
|
2546
|
+
return (BigInt(val) << BigInt(32)) +
|
|
2547
|
+
BigInt(this[++offset] * 2 ** 24 +
|
|
2548
|
+
this[++offset] * 2 ** 16 +
|
|
2549
|
+
this[++offset] * 2 ** 8 +
|
|
2550
|
+
last)
|
|
2551
|
+
});
|
|
2552
|
+
|
|
2553
|
+
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
2554
|
+
offset = offset >>> 0;
|
|
2555
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2556
|
+
return ieee754$1.read(this, offset, true, 23, 4)
|
|
2557
|
+
};
|
|
2558
|
+
|
|
2559
|
+
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
2560
|
+
offset = offset >>> 0;
|
|
2561
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
2562
|
+
return ieee754$1.read(this, offset, false, 23, 4)
|
|
2563
|
+
};
|
|
2564
|
+
|
|
2565
|
+
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
2566
|
+
offset = offset >>> 0;
|
|
2567
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
2568
|
+
return ieee754$1.read(this, offset, true, 52, 8)
|
|
2569
|
+
};
|
|
2570
|
+
|
|
2571
|
+
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
2572
|
+
offset = offset >>> 0;
|
|
2573
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
2574
|
+
return ieee754$1.read(this, offset, false, 52, 8)
|
|
2575
|
+
};
|
|
2576
|
+
|
|
2577
|
+
function checkInt (buf, value, offset, ext, max, min) {
|
|
2578
|
+
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
2579
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
2580
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
Buffer.prototype.writeUintLE =
|
|
2584
|
+
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
2585
|
+
value = +value;
|
|
2586
|
+
offset = offset >>> 0;
|
|
2587
|
+
byteLength = byteLength >>> 0;
|
|
2588
|
+
if (!noAssert) {
|
|
2589
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
2590
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
let mul = 1;
|
|
2594
|
+
let i = 0;
|
|
2595
|
+
this[offset] = value & 0xFF;
|
|
2596
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
2597
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
return offset + byteLength
|
|
2601
|
+
};
|
|
2602
|
+
|
|
2603
|
+
Buffer.prototype.writeUintBE =
|
|
2604
|
+
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
2605
|
+
value = +value;
|
|
2606
|
+
offset = offset >>> 0;
|
|
2607
|
+
byteLength = byteLength >>> 0;
|
|
2608
|
+
if (!noAssert) {
|
|
2609
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
2610
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
let i = byteLength - 1;
|
|
2614
|
+
let mul = 1;
|
|
2615
|
+
this[offset + i] = value & 0xFF;
|
|
2616
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
2617
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
return offset + byteLength
|
|
2621
|
+
};
|
|
2622
|
+
|
|
2623
|
+
Buffer.prototype.writeUint8 =
|
|
2624
|
+
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
2625
|
+
value = +value;
|
|
2626
|
+
offset = offset >>> 0;
|
|
2627
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
|
2628
|
+
this[offset] = (value & 0xff);
|
|
2629
|
+
return offset + 1
|
|
2630
|
+
};
|
|
2631
|
+
|
|
2632
|
+
Buffer.prototype.writeUint16LE =
|
|
2633
|
+
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
|
2634
|
+
value = +value;
|
|
2635
|
+
offset = offset >>> 0;
|
|
2636
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
2637
|
+
this[offset] = (value & 0xff);
|
|
2638
|
+
this[offset + 1] = (value >>> 8);
|
|
2639
|
+
return offset + 2
|
|
2640
|
+
};
|
|
2641
|
+
|
|
2642
|
+
Buffer.prototype.writeUint16BE =
|
|
2643
|
+
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
2644
|
+
value = +value;
|
|
2645
|
+
offset = offset >>> 0;
|
|
2646
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
2647
|
+
this[offset] = (value >>> 8);
|
|
2648
|
+
this[offset + 1] = (value & 0xff);
|
|
2649
|
+
return offset + 2
|
|
2650
|
+
};
|
|
2651
|
+
|
|
2652
|
+
Buffer.prototype.writeUint32LE =
|
|
2653
|
+
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
|
2654
|
+
value = +value;
|
|
2655
|
+
offset = offset >>> 0;
|
|
2656
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
2657
|
+
this[offset + 3] = (value >>> 24);
|
|
2658
|
+
this[offset + 2] = (value >>> 16);
|
|
2659
|
+
this[offset + 1] = (value >>> 8);
|
|
2660
|
+
this[offset] = (value & 0xff);
|
|
2661
|
+
return offset + 4
|
|
2662
|
+
};
|
|
2663
|
+
|
|
2664
|
+
Buffer.prototype.writeUint32BE =
|
|
2665
|
+
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
|
2666
|
+
value = +value;
|
|
2667
|
+
offset = offset >>> 0;
|
|
2668
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
2669
|
+
this[offset] = (value >>> 24);
|
|
2670
|
+
this[offset + 1] = (value >>> 16);
|
|
2671
|
+
this[offset + 2] = (value >>> 8);
|
|
2672
|
+
this[offset + 3] = (value & 0xff);
|
|
2673
|
+
return offset + 4
|
|
2674
|
+
};
|
|
2675
|
+
|
|
2676
|
+
function wrtBigUInt64LE (buf, value, offset, min, max) {
|
|
2677
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
2678
|
+
|
|
2679
|
+
let lo = Number(value & BigInt(0xffffffff));
|
|
2680
|
+
buf[offset++] = lo;
|
|
2681
|
+
lo = lo >> 8;
|
|
2682
|
+
buf[offset++] = lo;
|
|
2683
|
+
lo = lo >> 8;
|
|
2684
|
+
buf[offset++] = lo;
|
|
2685
|
+
lo = lo >> 8;
|
|
2686
|
+
buf[offset++] = lo;
|
|
2687
|
+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
|
|
2688
|
+
buf[offset++] = hi;
|
|
2689
|
+
hi = hi >> 8;
|
|
2690
|
+
buf[offset++] = hi;
|
|
2691
|
+
hi = hi >> 8;
|
|
2692
|
+
buf[offset++] = hi;
|
|
2693
|
+
hi = hi >> 8;
|
|
2694
|
+
buf[offset++] = hi;
|
|
2695
|
+
return offset
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2698
|
+
function wrtBigUInt64BE (buf, value, offset, min, max) {
|
|
2699
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
2700
|
+
|
|
2701
|
+
let lo = Number(value & BigInt(0xffffffff));
|
|
2702
|
+
buf[offset + 7] = lo;
|
|
2703
|
+
lo = lo >> 8;
|
|
2704
|
+
buf[offset + 6] = lo;
|
|
2705
|
+
lo = lo >> 8;
|
|
2706
|
+
buf[offset + 5] = lo;
|
|
2707
|
+
lo = lo >> 8;
|
|
2708
|
+
buf[offset + 4] = lo;
|
|
2709
|
+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
|
|
2710
|
+
buf[offset + 3] = hi;
|
|
2711
|
+
hi = hi >> 8;
|
|
2712
|
+
buf[offset + 2] = hi;
|
|
2713
|
+
hi = hi >> 8;
|
|
2714
|
+
buf[offset + 1] = hi;
|
|
2715
|
+
hi = hi >> 8;
|
|
2716
|
+
buf[offset] = hi;
|
|
2717
|
+
return offset + 8
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
|
|
2721
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
2722
|
+
});
|
|
2723
|
+
|
|
2724
|
+
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
|
|
2725
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
2726
|
+
});
|
|
2727
|
+
|
|
2728
|
+
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
2729
|
+
value = +value;
|
|
2730
|
+
offset = offset >>> 0;
|
|
2731
|
+
if (!noAssert) {
|
|
2732
|
+
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
2733
|
+
|
|
2734
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
let i = 0;
|
|
2738
|
+
let mul = 1;
|
|
2739
|
+
let sub = 0;
|
|
2740
|
+
this[offset] = value & 0xFF;
|
|
2741
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
2742
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
2743
|
+
sub = 1;
|
|
2744
|
+
}
|
|
2745
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
return offset + byteLength
|
|
2749
|
+
};
|
|
2750
|
+
|
|
2751
|
+
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
2752
|
+
value = +value;
|
|
2753
|
+
offset = offset >>> 0;
|
|
2754
|
+
if (!noAssert) {
|
|
2755
|
+
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
2756
|
+
|
|
2757
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
2758
|
+
}
|
|
2759
|
+
|
|
2760
|
+
let i = byteLength - 1;
|
|
2761
|
+
let mul = 1;
|
|
2762
|
+
let sub = 0;
|
|
2763
|
+
this[offset + i] = value & 0xFF;
|
|
2764
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
2765
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
2766
|
+
sub = 1;
|
|
2767
|
+
}
|
|
2768
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
return offset + byteLength
|
|
2772
|
+
};
|
|
2773
|
+
|
|
2774
|
+
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
2775
|
+
value = +value;
|
|
2776
|
+
offset = offset >>> 0;
|
|
2777
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
|
|
2778
|
+
if (value < 0) value = 0xff + value + 1;
|
|
2779
|
+
this[offset] = (value & 0xff);
|
|
2780
|
+
return offset + 1
|
|
2781
|
+
};
|
|
2782
|
+
|
|
2783
|
+
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
2784
|
+
value = +value;
|
|
2785
|
+
offset = offset >>> 0;
|
|
2786
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
|
|
2787
|
+
this[offset] = (value & 0xff);
|
|
2788
|
+
this[offset + 1] = (value >>> 8);
|
|
2789
|
+
return offset + 2
|
|
2790
|
+
};
|
|
2791
|
+
|
|
2792
|
+
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
2793
|
+
value = +value;
|
|
2794
|
+
offset = offset >>> 0;
|
|
2795
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
|
|
2796
|
+
this[offset] = (value >>> 8);
|
|
2797
|
+
this[offset + 1] = (value & 0xff);
|
|
2798
|
+
return offset + 2
|
|
2799
|
+
};
|
|
2800
|
+
|
|
2801
|
+
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
2802
|
+
value = +value;
|
|
2803
|
+
offset = offset >>> 0;
|
|
2804
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
|
|
2805
|
+
this[offset] = (value & 0xff);
|
|
2806
|
+
this[offset + 1] = (value >>> 8);
|
|
2807
|
+
this[offset + 2] = (value >>> 16);
|
|
2808
|
+
this[offset + 3] = (value >>> 24);
|
|
2809
|
+
return offset + 4
|
|
2810
|
+
};
|
|
2811
|
+
|
|
2812
|
+
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
2813
|
+
value = +value;
|
|
2814
|
+
offset = offset >>> 0;
|
|
2815
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
|
|
2816
|
+
if (value < 0) value = 0xffffffff + value + 1;
|
|
2817
|
+
this[offset] = (value >>> 24);
|
|
2818
|
+
this[offset + 1] = (value >>> 16);
|
|
2819
|
+
this[offset + 2] = (value >>> 8);
|
|
2820
|
+
this[offset + 3] = (value & 0xff);
|
|
2821
|
+
return offset + 4
|
|
2822
|
+
};
|
|
2823
|
+
|
|
2824
|
+
Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
|
|
2825
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
2826
|
+
});
|
|
2827
|
+
|
|
2828
|
+
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
|
|
2829
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
2830
|
+
});
|
|
2831
|
+
|
|
2832
|
+
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
2833
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
2834
|
+
if (offset < 0) throw new RangeError('Index out of range')
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
2838
|
+
value = +value;
|
|
2839
|
+
offset = offset >>> 0;
|
|
2840
|
+
if (!noAssert) {
|
|
2841
|
+
checkIEEE754(buf, value, offset, 4);
|
|
2842
|
+
}
|
|
2843
|
+
ieee754$1.write(buf, value, offset, littleEndian, 23, 4);
|
|
2844
|
+
return offset + 4
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
2848
|
+
return writeFloat(this, value, offset, true, noAssert)
|
|
2849
|
+
};
|
|
2850
|
+
|
|
2851
|
+
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
2852
|
+
return writeFloat(this, value, offset, false, noAssert)
|
|
2853
|
+
};
|
|
2854
|
+
|
|
2855
|
+
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
2856
|
+
value = +value;
|
|
2857
|
+
offset = offset >>> 0;
|
|
2858
|
+
if (!noAssert) {
|
|
2859
|
+
checkIEEE754(buf, value, offset, 8);
|
|
2860
|
+
}
|
|
2861
|
+
ieee754$1.write(buf, value, offset, littleEndian, 52, 8);
|
|
2862
|
+
return offset + 8
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
2866
|
+
return writeDouble(this, value, offset, true, noAssert)
|
|
2867
|
+
};
|
|
2868
|
+
|
|
2869
|
+
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
2870
|
+
return writeDouble(this, value, offset, false, noAssert)
|
|
2871
|
+
};
|
|
2872
|
+
|
|
2873
|
+
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
2874
|
+
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
2875
|
+
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
|
2876
|
+
if (!start) start = 0;
|
|
2877
|
+
if (!end && end !== 0) end = this.length;
|
|
2878
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
2879
|
+
if (!targetStart) targetStart = 0;
|
|
2880
|
+
if (end > 0 && end < start) end = start;
|
|
2881
|
+
|
|
2882
|
+
// Copy 0 bytes; we're done
|
|
2883
|
+
if (end === start) return 0
|
|
2884
|
+
if (target.length === 0 || this.length === 0) return 0
|
|
2885
|
+
|
|
2886
|
+
// Fatal error conditions
|
|
2887
|
+
if (targetStart < 0) {
|
|
2888
|
+
throw new RangeError('targetStart out of bounds')
|
|
2889
|
+
}
|
|
2890
|
+
if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
|
2891
|
+
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
2892
|
+
|
|
2893
|
+
// Are we oob?
|
|
2894
|
+
if (end > this.length) end = this.length;
|
|
2895
|
+
if (target.length - targetStart < end - start) {
|
|
2896
|
+
end = target.length - targetStart + start;
|
|
2897
|
+
}
|
|
2898
|
+
|
|
2899
|
+
const len = end - start;
|
|
2900
|
+
|
|
2901
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
2902
|
+
// Use built-in when available, missing from IE11
|
|
2903
|
+
this.copyWithin(targetStart, start, end);
|
|
2904
|
+
} else {
|
|
2905
|
+
Uint8Array.prototype.set.call(
|
|
2906
|
+
target,
|
|
2907
|
+
this.subarray(start, end),
|
|
2908
|
+
targetStart
|
|
2909
|
+
);
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2912
|
+
return len
|
|
2913
|
+
};
|
|
2914
|
+
|
|
2915
|
+
// Usage:
|
|
2916
|
+
// buffer.fill(number[, offset[, end]])
|
|
2917
|
+
// buffer.fill(buffer[, offset[, end]])
|
|
2918
|
+
// buffer.fill(string[, offset[, end]][, encoding])
|
|
2919
|
+
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
2920
|
+
// Handle string cases:
|
|
2921
|
+
if (typeof val === 'string') {
|
|
2922
|
+
if (typeof start === 'string') {
|
|
2923
|
+
encoding = start;
|
|
2924
|
+
start = 0;
|
|
2925
|
+
end = this.length;
|
|
2926
|
+
} else if (typeof end === 'string') {
|
|
2927
|
+
encoding = end;
|
|
2928
|
+
end = this.length;
|
|
2929
|
+
}
|
|
2930
|
+
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
2931
|
+
throw new TypeError('encoding must be a string')
|
|
2932
|
+
}
|
|
2933
|
+
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
2934
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
2935
|
+
}
|
|
2936
|
+
if (val.length === 1) {
|
|
2937
|
+
const code = val.charCodeAt(0);
|
|
2938
|
+
if ((encoding === 'utf8' && code < 128) ||
|
|
2939
|
+
encoding === 'latin1') {
|
|
2940
|
+
// Fast path: If `val` fits into a single byte, use that numeric value.
|
|
2941
|
+
val = code;
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
} else if (typeof val === 'number') {
|
|
2945
|
+
val = val & 255;
|
|
2946
|
+
} else if (typeof val === 'boolean') {
|
|
2947
|
+
val = Number(val);
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2950
|
+
// Invalid ranges are not set to a default, so can range check early.
|
|
2951
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
2952
|
+
throw new RangeError('Out of range index')
|
|
2953
|
+
}
|
|
2954
|
+
|
|
2955
|
+
if (end <= start) {
|
|
2956
|
+
return this
|
|
2957
|
+
}
|
|
2958
|
+
|
|
2959
|
+
start = start >>> 0;
|
|
2960
|
+
end = end === undefined ? this.length : end >>> 0;
|
|
2961
|
+
|
|
2962
|
+
if (!val) val = 0;
|
|
2963
|
+
|
|
2964
|
+
let i;
|
|
2965
|
+
if (typeof val === 'number') {
|
|
2966
|
+
for (i = start; i < end; ++i) {
|
|
2967
|
+
this[i] = val;
|
|
2968
|
+
}
|
|
2969
|
+
} else {
|
|
2970
|
+
const bytes = Buffer.isBuffer(val)
|
|
2971
|
+
? val
|
|
2972
|
+
: Buffer.from(val, encoding);
|
|
2973
|
+
const len = bytes.length;
|
|
2974
|
+
if (len === 0) {
|
|
2975
|
+
throw new TypeError('The value "' + val +
|
|
2976
|
+
'" is invalid for argument "value"')
|
|
2977
|
+
}
|
|
2978
|
+
for (i = 0; i < end - start; ++i) {
|
|
2979
|
+
this[i + start] = bytes[i % len];
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
return this
|
|
2984
|
+
};
|
|
2985
|
+
|
|
2986
|
+
// CUSTOM ERRORS
|
|
2987
|
+
// =============
|
|
2988
|
+
|
|
2989
|
+
// Simplified versions from Node, changed for Buffer-only usage
|
|
2990
|
+
const errors = {};
|
|
2991
|
+
function E (sym, getMessage, Base) {
|
|
2992
|
+
errors[sym] = class NodeError extends Base {
|
|
2993
|
+
constructor () {
|
|
2994
|
+
super();
|
|
2995
|
+
|
|
2996
|
+
Object.defineProperty(this, 'message', {
|
|
2997
|
+
value: getMessage.apply(this, arguments),
|
|
2998
|
+
writable: true,
|
|
2999
|
+
configurable: true
|
|
3000
|
+
});
|
|
3001
|
+
|
|
3002
|
+
// Add the error code to the name to include it in the stack trace.
|
|
3003
|
+
this.name = `${this.name} [${sym}]`;
|
|
3004
|
+
// Access the stack to generate the error message including the error code
|
|
3005
|
+
// from the name.
|
|
3006
|
+
this.stack; // eslint-disable-line no-unused-expressions
|
|
3007
|
+
// Reset the name to the actual name.
|
|
3008
|
+
delete this.name;
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
get code () {
|
|
3012
|
+
return sym
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
set code (value) {
|
|
3016
|
+
Object.defineProperty(this, 'code', {
|
|
3017
|
+
configurable: true,
|
|
3018
|
+
enumerable: true,
|
|
3019
|
+
value,
|
|
3020
|
+
writable: true
|
|
3021
|
+
});
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
toString () {
|
|
3025
|
+
return `${this.name} [${sym}]: ${this.message}`
|
|
3026
|
+
}
|
|
3027
|
+
};
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
E('ERR_BUFFER_OUT_OF_BOUNDS',
|
|
3031
|
+
function (name) {
|
|
3032
|
+
if (name) {
|
|
3033
|
+
return `${name} is outside of buffer bounds`
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
return 'Attempt to access memory outside buffer bounds'
|
|
3037
|
+
}, RangeError);
|
|
3038
|
+
E('ERR_INVALID_ARG_TYPE',
|
|
3039
|
+
function (name, actual) {
|
|
3040
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`
|
|
3041
|
+
}, TypeError);
|
|
3042
|
+
E('ERR_OUT_OF_RANGE',
|
|
3043
|
+
function (str, range, input) {
|
|
3044
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
3045
|
+
let received = input;
|
|
3046
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
3047
|
+
received = addNumericalSeparator(String(input));
|
|
3048
|
+
} else if (typeof input === 'bigint') {
|
|
3049
|
+
received = String(input);
|
|
3050
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
3051
|
+
received = addNumericalSeparator(received);
|
|
3052
|
+
}
|
|
3053
|
+
received += 'n';
|
|
3054
|
+
}
|
|
3055
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
3056
|
+
return msg
|
|
3057
|
+
}, RangeError);
|
|
3058
|
+
|
|
3059
|
+
function addNumericalSeparator (val) {
|
|
3060
|
+
let res = '';
|
|
3061
|
+
let i = val.length;
|
|
3062
|
+
const start = val[0] === '-' ? 1 : 0;
|
|
3063
|
+
for (; i >= start + 4; i -= 3) {
|
|
3064
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
3065
|
+
}
|
|
3066
|
+
return `${val.slice(0, i)}${res}`
|
|
3067
|
+
}
|
|
3068
|
+
|
|
3069
|
+
// CHECK FUNCTIONS
|
|
3070
|
+
// ===============
|
|
3071
|
+
|
|
3072
|
+
function checkBounds (buf, offset, byteLength) {
|
|
3073
|
+
validateNumber(offset, 'offset');
|
|
3074
|
+
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
|
|
3075
|
+
boundsError(offset, buf.length - (byteLength + 1));
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
function checkIntBI (value, min, max, buf, offset, byteLength) {
|
|
3080
|
+
if (value > max || value < min) {
|
|
3081
|
+
const n = typeof min === 'bigint' ? 'n' : '';
|
|
3082
|
+
let range;
|
|
3083
|
+
{
|
|
3084
|
+
if (min === 0 || min === BigInt(0)) {
|
|
3085
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
|
|
3086
|
+
} else {
|
|
3087
|
+
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
3088
|
+
`${(byteLength + 1) * 8 - 1}${n}`;
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
|
|
3092
|
+
}
|
|
3093
|
+
checkBounds(buf, offset, byteLength);
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3096
|
+
function validateNumber (value, name) {
|
|
3097
|
+
if (typeof value !== 'number') {
|
|
3098
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
|
|
3102
|
+
function boundsError (value, length, type) {
|
|
3103
|
+
if (Math.floor(value) !== value) {
|
|
3104
|
+
validateNumber(value, type);
|
|
3105
|
+
throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
if (length < 0) {
|
|
3109
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
|
|
3110
|
+
}
|
|
3111
|
+
|
|
3112
|
+
throw new errors.ERR_OUT_OF_RANGE('offset',
|
|
3113
|
+
`>= ${0} and <= ${length}`,
|
|
3114
|
+
value)
|
|
3115
|
+
}
|
|
3116
|
+
|
|
3117
|
+
// HELPER FUNCTIONS
|
|
3118
|
+
// ================
|
|
3119
|
+
|
|
3120
|
+
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
3121
|
+
|
|
3122
|
+
function base64clean (str) {
|
|
3123
|
+
// Node takes equal signs as end of the Base64 encoding
|
|
3124
|
+
str = str.split('=')[0];
|
|
3125
|
+
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
3126
|
+
str = str.trim().replace(INVALID_BASE64_RE, '');
|
|
3127
|
+
// Node converts strings with length < 2 to ''
|
|
3128
|
+
if (str.length < 2) return ''
|
|
3129
|
+
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
3130
|
+
while (str.length % 4 !== 0) {
|
|
3131
|
+
str = str + '=';
|
|
3132
|
+
}
|
|
3133
|
+
return str
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3136
|
+
function utf8ToBytes (string, units) {
|
|
3137
|
+
units = units || Infinity;
|
|
3138
|
+
let codePoint;
|
|
3139
|
+
const length = string.length;
|
|
3140
|
+
let leadSurrogate = null;
|
|
3141
|
+
const bytes = [];
|
|
3142
|
+
|
|
3143
|
+
for (let i = 0; i < length; ++i) {
|
|
3144
|
+
codePoint = string.charCodeAt(i);
|
|
3145
|
+
|
|
3146
|
+
// is surrogate component
|
|
3147
|
+
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
3148
|
+
// last char was a lead
|
|
3149
|
+
if (!leadSurrogate) {
|
|
3150
|
+
// no lead yet
|
|
3151
|
+
if (codePoint > 0xDBFF) {
|
|
3152
|
+
// unexpected trail
|
|
3153
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
3154
|
+
continue
|
|
3155
|
+
} else if (i + 1 === length) {
|
|
3156
|
+
// unpaired lead
|
|
3157
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
3158
|
+
continue
|
|
3159
|
+
}
|
|
3160
|
+
|
|
3161
|
+
// valid lead
|
|
3162
|
+
leadSurrogate = codePoint;
|
|
3163
|
+
|
|
3164
|
+
continue
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
// 2 leads in a row
|
|
3168
|
+
if (codePoint < 0xDC00) {
|
|
3169
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
3170
|
+
leadSurrogate = codePoint;
|
|
3171
|
+
continue
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
// valid surrogate pair
|
|
3175
|
+
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
|
|
3176
|
+
} else if (leadSurrogate) {
|
|
3177
|
+
// valid bmp char, but last char was a lead
|
|
3178
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
3179
|
+
}
|
|
3180
|
+
|
|
3181
|
+
leadSurrogate = null;
|
|
3182
|
+
|
|
3183
|
+
// encode utf8
|
|
3184
|
+
if (codePoint < 0x80) {
|
|
3185
|
+
if ((units -= 1) < 0) break
|
|
3186
|
+
bytes.push(codePoint);
|
|
3187
|
+
} else if (codePoint < 0x800) {
|
|
3188
|
+
if ((units -= 2) < 0) break
|
|
3189
|
+
bytes.push(
|
|
3190
|
+
codePoint >> 0x6 | 0xC0,
|
|
3191
|
+
codePoint & 0x3F | 0x80
|
|
3192
|
+
);
|
|
3193
|
+
} else if (codePoint < 0x10000) {
|
|
3194
|
+
if ((units -= 3) < 0) break
|
|
3195
|
+
bytes.push(
|
|
3196
|
+
codePoint >> 0xC | 0xE0,
|
|
3197
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
3198
|
+
codePoint & 0x3F | 0x80
|
|
3199
|
+
);
|
|
3200
|
+
} else if (codePoint < 0x110000) {
|
|
3201
|
+
if ((units -= 4) < 0) break
|
|
3202
|
+
bytes.push(
|
|
3203
|
+
codePoint >> 0x12 | 0xF0,
|
|
3204
|
+
codePoint >> 0xC & 0x3F | 0x80,
|
|
3205
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
3206
|
+
codePoint & 0x3F | 0x80
|
|
3207
|
+
);
|
|
3208
|
+
} else {
|
|
3209
|
+
throw new Error('Invalid code point')
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
|
|
3213
|
+
return bytes
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
function asciiToBytes (str) {
|
|
3217
|
+
const byteArray = [];
|
|
3218
|
+
for (let i = 0; i < str.length; ++i) {
|
|
3219
|
+
// Node's code seems to be doing this and not & 0x7F..
|
|
3220
|
+
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
3221
|
+
}
|
|
3222
|
+
return byteArray
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
function utf16leToBytes (str, units) {
|
|
3226
|
+
let c, hi, lo;
|
|
3227
|
+
const byteArray = [];
|
|
3228
|
+
for (let i = 0; i < str.length; ++i) {
|
|
3229
|
+
if ((units -= 2) < 0) break
|
|
3230
|
+
|
|
3231
|
+
c = str.charCodeAt(i);
|
|
3232
|
+
hi = c >> 8;
|
|
3233
|
+
lo = c % 256;
|
|
3234
|
+
byteArray.push(lo);
|
|
3235
|
+
byteArray.push(hi);
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
return byteArray
|
|
3239
|
+
}
|
|
3240
|
+
|
|
3241
|
+
function base64ToBytes (str) {
|
|
3242
|
+
return base64.toByteArray(base64clean(str))
|
|
3243
|
+
}
|
|
3244
|
+
|
|
3245
|
+
function blitBuffer (src, dst, offset, length) {
|
|
3246
|
+
let i;
|
|
3247
|
+
for (i = 0; i < length; ++i) {
|
|
3248
|
+
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
3249
|
+
dst[i + offset] = src[i];
|
|
3250
|
+
}
|
|
3251
|
+
return i
|
|
3252
|
+
}
|
|
3253
|
+
|
|
3254
|
+
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
|
|
3255
|
+
// the `instanceof` check but they should be treated as of that type.
|
|
3256
|
+
// See: https://github.com/feross/buffer/issues/166
|
|
3257
|
+
function isInstance (obj, type) {
|
|
3258
|
+
return obj instanceof type ||
|
|
3259
|
+
(obj != null && obj.constructor != null && obj.constructor.name != null &&
|
|
3260
|
+
obj.constructor.name === type.name)
|
|
3261
|
+
}
|
|
3262
|
+
function numberIsNaN (obj) {
|
|
3263
|
+
// For IE11 support
|
|
3264
|
+
return obj !== obj // eslint-disable-line no-self-compare
|
|
3265
|
+
}
|
|
3266
|
+
|
|
3267
|
+
// Create lookup table for `toString('hex')`
|
|
3268
|
+
// See: https://github.com/feross/buffer/issues/219
|
|
3269
|
+
const hexSliceLookupTable = (function () {
|
|
3270
|
+
const alphabet = '0123456789abcdef';
|
|
3271
|
+
const table = new Array(256);
|
|
3272
|
+
for (let i = 0; i < 16; ++i) {
|
|
3273
|
+
const i16 = i * 16;
|
|
3274
|
+
for (let j = 0; j < 16; ++j) {
|
|
3275
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
return table
|
|
3279
|
+
})();
|
|
3280
|
+
|
|
3281
|
+
// Return not function with Error if BigInt not supported
|
|
3282
|
+
function defineBigIntMethod (fn) {
|
|
3283
|
+
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
|
|
3284
|
+
}
|
|
3285
|
+
|
|
3286
|
+
function BufferBigIntNotDefined () {
|
|
3287
|
+
throw new Error('BigInt not supported')
|
|
3288
|
+
}
|
|
3289
|
+
} (buffer));
|
|
3290
|
+
|
|
940
3291
|
var elliptic = {};
|
|
941
3292
|
|
|
942
3293
|
var version = "6.6.1";
|
|
@@ -7689,7 +10040,7 @@
|
|
|
7689
10040
|
for (var j = 0; j < 80; j++) {
|
|
7690
10041
|
var T = sum32(
|
|
7691
10042
|
rotl32(
|
|
7692
|
-
sum32_4(A, f(j, B, C, D), msg[r[j] + start], K
|
|
10043
|
+
sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
|
|
7693
10044
|
s[j]),
|
|
7694
10045
|
E);
|
|
7695
10046
|
A = E;
|
|
@@ -7736,7 +10087,7 @@
|
|
|
7736
10087
|
return x ^ (y | (~z));
|
|
7737
10088
|
}
|
|
7738
10089
|
|
|
7739
|
-
function K
|
|
10090
|
+
function K(j) {
|
|
7740
10091
|
if (j <= 15)
|
|
7741
10092
|
return 0x00000000;
|
|
7742
10093
|
else if (j <= 31)
|
|
@@ -13946,27 +16297,27 @@
|
|
|
13946
16297
|
hmac.create = (hash, key) => new _HMAC(hash, key);
|
|
13947
16298
|
|
|
13948
16299
|
function sha256$1(data, encoding) {
|
|
13949
|
-
const input = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
16300
|
+
const input = buffer.Buffer.isBuffer(data) ? data : buffer.Buffer.from(data);
|
|
13950
16301
|
const hash = sha256$2(input);
|
|
13951
16302
|
if (encoding) {
|
|
13952
|
-
return Buffer.from(hash).toString(encoding);
|
|
16303
|
+
return buffer.Buffer.from(hash).toString(encoding);
|
|
13953
16304
|
}
|
|
13954
|
-
return Buffer.from(hash);
|
|
16305
|
+
return buffer.Buffer.from(hash);
|
|
13955
16306
|
}
|
|
13956
16307
|
function sha512(data, encoding) {
|
|
13957
|
-
const input = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
16308
|
+
const input = buffer.Buffer.isBuffer(data) ? data : buffer.Buffer.from(data);
|
|
13958
16309
|
const hash = sha512$1(input);
|
|
13959
16310
|
if (encoding) {
|
|
13960
|
-
return Buffer.from(hash).toString(encoding);
|
|
16311
|
+
return buffer.Buffer.from(hash).toString(encoding);
|
|
13961
16312
|
}
|
|
13962
|
-
return Buffer.from(hash);
|
|
16313
|
+
return buffer.Buffer.from(hash);
|
|
13963
16314
|
}
|
|
13964
|
-
function HmacSHA256(buffer, secret) {
|
|
13965
|
-
return Buffer.from(hmac(sha256$2, secret, buffer));
|
|
16315
|
+
function HmacSHA256(buffer$1, secret) {
|
|
16316
|
+
return buffer.Buffer.from(hmac(sha256$2, secret, buffer$1));
|
|
13966
16317
|
}
|
|
13967
16318
|
function ripemd160$1(data) {
|
|
13968
|
-
const input = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
13969
|
-
return Buffer.from(ripemd160$2(input));
|
|
16319
|
+
const input = buffer.Buffer.isBuffer(data) ? data : buffer.Buffer.from(data);
|
|
16320
|
+
return buffer.Buffer.from(ripemd160$2(input));
|
|
13970
16321
|
}
|
|
13971
16322
|
|
|
13972
16323
|
// base-x encoding / decoding
|
|
@@ -14105,7 +16456,7 @@
|
|
|
14105
16456
|
this.Q = Q;
|
|
14106
16457
|
}
|
|
14107
16458
|
static fromBinary(bin) {
|
|
14108
|
-
return PublicKey.fromBuffer(Buffer.from(bin, 'binary'));
|
|
16459
|
+
return PublicKey.fromBuffer(buffer.Buffer.from(bin, 'binary'));
|
|
14109
16460
|
}
|
|
14110
16461
|
static fromBuffer(buffer) {
|
|
14111
16462
|
if (buffer.toString("hex") === "000000000000000000000000000000000000000000000000000000000000000000") {
|
|
@@ -14115,15 +16466,15 @@
|
|
|
14115
16466
|
}
|
|
14116
16467
|
toBuffer(compressed = true) {
|
|
14117
16468
|
if (this.Q === null) {
|
|
14118
|
-
return Buffer.from("000000000000000000000000000000000000000000000000000000000000000000", "hex");
|
|
16469
|
+
return buffer.Buffer.from("000000000000000000000000000000000000000000000000000000000000000000", "hex");
|
|
14119
16470
|
}
|
|
14120
|
-
return Buffer.from(this.Q.encode('array', compressed));
|
|
16471
|
+
return buffer.Buffer.from(this.Q.encode('array', compressed));
|
|
14121
16472
|
}
|
|
14122
16473
|
static fromPoint(point) {
|
|
14123
16474
|
return new PublicKey(point);
|
|
14124
16475
|
}
|
|
14125
16476
|
toUncompressed() {
|
|
14126
|
-
const buf = Buffer.from(this.Q.encode('array', false));
|
|
16477
|
+
const buf = buffer.Buffer.from(this.Q.encode('array', false));
|
|
14127
16478
|
const point = secp256k1$2.curve.decodePoint(buf);
|
|
14128
16479
|
return PublicKey.fromPoint(point);
|
|
14129
16480
|
}
|
|
@@ -14146,7 +16497,7 @@
|
|
|
14146
16497
|
return prefix + this.pubdata;
|
|
14147
16498
|
const pub_buf = this.toBuffer();
|
|
14148
16499
|
const checksum = ripemd160$1(pub_buf);
|
|
14149
|
-
const addy = Buffer.concat([pub_buf, checksum.slice(0, 4)]);
|
|
16500
|
+
const addy = buffer.Buffer.concat([pub_buf, checksum.slice(0, 4)]);
|
|
14150
16501
|
this.pubdata = bs58.encode(addy);
|
|
14151
16502
|
return prefix + this.pubdata;
|
|
14152
16503
|
}
|
|
@@ -14177,12 +16528,12 @@
|
|
|
14177
16528
|
throw new Error(`Expecting key to begin with ${prefixStr}, instead got ${prefix}`);
|
|
14178
16529
|
public_key = public_key.slice(prefixStr.length);
|
|
14179
16530
|
const decoded = bs58.decode(public_key);
|
|
14180
|
-
const buffer = Buffer.from(decoded);
|
|
14181
|
-
const checksum = buffer.slice(-4);
|
|
14182
|
-
const key = buffer.slice(0, -4);
|
|
16531
|
+
const buffer$1 = buffer.Buffer.from(decoded);
|
|
16532
|
+
const checksum = buffer$1.slice(-4);
|
|
16533
|
+
const key = buffer$1.slice(0, -4);
|
|
14183
16534
|
const new_checksum = ripemd160$1(key);
|
|
14184
16535
|
const new_checksum_slice = new_checksum.slice(0, 4);
|
|
14185
|
-
if (!Buffer.isBuffer(checksum) || !Buffer.isBuffer(new_checksum_slice) || !checksum.equals(new_checksum_slice)) {
|
|
16536
|
+
if (!buffer.Buffer.isBuffer(checksum) || !buffer.Buffer.isBuffer(new_checksum_slice) || !checksum.equals(new_checksum_slice)) {
|
|
14186
16537
|
throw new Error('Checksum did not match');
|
|
14187
16538
|
}
|
|
14188
16539
|
return PublicKey.fromBuffer(key);
|
|
@@ -14192,26 +16543,26 @@
|
|
|
14192
16543
|
const pub_sha = sha512(pub_buf);
|
|
14193
16544
|
const addy = ripemd160$1(pub_sha);
|
|
14194
16545
|
const checksum = ripemd160$1(addy);
|
|
14195
|
-
const addr_checksum = Buffer.concat([addy, checksum.slice(0, 4)]);
|
|
16546
|
+
const addr_checksum = buffer.Buffer.concat([addy, checksum.slice(0, 4)]);
|
|
14196
16547
|
return address_prefix + bs58.encode(addr_checksum);
|
|
14197
16548
|
}
|
|
14198
16549
|
toPtsAddy() {
|
|
14199
16550
|
const pub_buf = this.toBuffer();
|
|
14200
16551
|
const pub_sha = sha256$1(pub_buf);
|
|
14201
16552
|
const addy = ripemd160$1(pub_sha);
|
|
14202
|
-
const versionBuffer = Buffer.from([0x38]); // version 56(decimal)
|
|
14203
|
-
const addr = Buffer.concat([versionBuffer, addy]);
|
|
16553
|
+
const versionBuffer = buffer.Buffer.from([0x38]); // version 56(decimal)
|
|
16554
|
+
const addr = buffer.Buffer.concat([versionBuffer, addy]);
|
|
14204
16555
|
let checksum = sha256$1(addr);
|
|
14205
16556
|
checksum = sha256$1(checksum);
|
|
14206
|
-
const addr_checksum = Buffer.concat([addr, checksum.slice(0, 4)]);
|
|
16557
|
+
const addr_checksum = buffer.Buffer.concat([addr, checksum.slice(0, 4)]);
|
|
14207
16558
|
return bs58.encode(addr_checksum);
|
|
14208
16559
|
}
|
|
14209
16560
|
child(offset) {
|
|
14210
|
-
if (!Buffer.isBuffer(offset))
|
|
16561
|
+
if (!buffer.Buffer.isBuffer(offset))
|
|
14211
16562
|
throw new Error("Buffer required: offset");
|
|
14212
16563
|
if (offset.length !== 32)
|
|
14213
16564
|
throw new Error("offset length");
|
|
14214
|
-
offset = Buffer.concat([this.toBuffer(), offset]);
|
|
16565
|
+
offset = buffer.Buffer.concat([this.toBuffer(), offset]);
|
|
14215
16566
|
offset = sha256$1(offset);
|
|
14216
16567
|
const c = new BN(offset);
|
|
14217
16568
|
if (c.cmp(n$1) >= 0)
|
|
@@ -14223,12 +16574,12 @@
|
|
|
14223
16574
|
return PublicKey.fromPoint(Qprime);
|
|
14224
16575
|
}
|
|
14225
16576
|
static fromHex(hex) {
|
|
14226
|
-
const buffer = Buffer.from(hex, 'hex');
|
|
14227
|
-
if (buffer.length === 0) {
|
|
16577
|
+
const buffer$1 = buffer.Buffer.from(hex, 'hex');
|
|
16578
|
+
if (buffer$1.length === 0) {
|
|
14228
16579
|
// Return null public key for zero hex
|
|
14229
16580
|
return new PublicKey(null);
|
|
14230
16581
|
}
|
|
14231
|
-
return PublicKey.fromBuffer(buffer);
|
|
16582
|
+
return PublicKey.fromBuffer(buffer$1);
|
|
14232
16583
|
}
|
|
14233
16584
|
toHex() {
|
|
14234
16585
|
if (!this.Q) {
|
|
@@ -14237,7 +16588,7 @@
|
|
|
14237
16588
|
return this.toBuffer().toString('hex');
|
|
14238
16589
|
}
|
|
14239
16590
|
static fromStringHex(hex) {
|
|
14240
|
-
return PublicKey.fromString(Buffer.from(hex, 'hex').toString());
|
|
16591
|
+
return PublicKey.fromString(buffer.Buffer.from(hex, 'hex').toString());
|
|
14241
16592
|
}
|
|
14242
16593
|
}
|
|
14243
16594
|
|
|
@@ -14253,7 +16604,7 @@
|
|
|
14253
16604
|
this.d = d;
|
|
14254
16605
|
}
|
|
14255
16606
|
static fromBuffer(buf) {
|
|
14256
|
-
if (!Buffer.isBuffer(buf)) {
|
|
16607
|
+
if (!buffer.Buffer.isBuffer(buf)) {
|
|
14257
16608
|
throw new Error("Expecting parameter to be a Buffer type");
|
|
14258
16609
|
}
|
|
14259
16610
|
if (32 !== buf.length) {
|
|
@@ -14285,7 +16636,7 @@
|
|
|
14285
16636
|
* @return {string} Wallet Import Format (still a secret, Not encrypted)
|
|
14286
16637
|
*/
|
|
14287
16638
|
static fromWif(private_wif) {
|
|
14288
|
-
const private_wif_buffer = Buffer.from(bs58.decode(private_wif));
|
|
16639
|
+
const private_wif_buffer = buffer.Buffer.from(bs58.decode(private_wif));
|
|
14289
16640
|
const version = private_wif_buffer.readUInt8(0);
|
|
14290
16641
|
if (version !== 0x80)
|
|
14291
16642
|
throw new Error(`Expected version ${0x80}, instead got ${version}`);
|
|
@@ -14304,11 +16655,11 @@
|
|
|
14304
16655
|
toWif() {
|
|
14305
16656
|
const private_key = this.toBuffer();
|
|
14306
16657
|
// checksum includes the version
|
|
14307
|
-
const private_wif = Buffer.concat([Buffer.from([0x80]), private_key]);
|
|
16658
|
+
const private_wif = buffer.Buffer.concat([buffer.Buffer.from([0x80]), private_key]);
|
|
14308
16659
|
let checksum = sha256$1(private_wif);
|
|
14309
16660
|
checksum = sha256$1(checksum);
|
|
14310
16661
|
checksum = checksum.slice(0, 4);
|
|
14311
|
-
const private_wif_buffer = Buffer.concat([private_wif, checksum]);
|
|
16662
|
+
const private_wif_buffer = buffer.Buffer.concat([private_wif, checksum]);
|
|
14312
16663
|
return bs58.encode(private_wif_buffer);
|
|
14313
16664
|
}
|
|
14314
16665
|
/** Alias for {@link toWif} */
|
|
@@ -14328,7 +16679,7 @@
|
|
|
14328
16679
|
return this.public_key = PublicKey.fromPoint(this.toPublicKeyPoint());
|
|
14329
16680
|
}
|
|
14330
16681
|
toBuffer() {
|
|
14331
|
-
return this.d.toArrayLike(Buffer, 'be', 32);
|
|
16682
|
+
return this.d.toArrayLike(buffer.Buffer, 'be', 32);
|
|
14332
16683
|
}
|
|
14333
16684
|
/** ECIES */
|
|
14334
16685
|
get_shared_secret(public_key) {
|
|
@@ -14340,13 +16691,13 @@
|
|
|
14340
16691
|
}
|
|
14341
16692
|
// ECDH: shared_secret = private_key * public_key_point
|
|
14342
16693
|
const P = pubKey.Q.mul(this.d);
|
|
14343
|
-
const S = P.getX().toArrayLike(Buffer, 'be', 32);
|
|
16694
|
+
const S = P.getX().toArrayLike(buffer.Buffer, 'be', 32);
|
|
14344
16695
|
// SHA512 used in ECIES
|
|
14345
16696
|
return sha512(S);
|
|
14346
16697
|
}
|
|
14347
16698
|
/** @throws {Error} - overflow of the key could not be derived */
|
|
14348
16699
|
child(offset) {
|
|
14349
|
-
offset = Buffer.concat([this.toPublicKey().toBuffer(), offset]);
|
|
16700
|
+
offset = buffer.Buffer.concat([this.toPublicKey().toBuffer(), offset]);
|
|
14350
16701
|
offset = sha256$1(offset);
|
|
14351
16702
|
const c = new BN(offset);
|
|
14352
16703
|
if (c.gte(n)) {
|
|
@@ -14359,7 +16710,7 @@
|
|
|
14359
16710
|
return new PrivateKey(derived);
|
|
14360
16711
|
}
|
|
14361
16712
|
static fromHex(hex) {
|
|
14362
|
-
return PrivateKey.fromBuffer(Buffer.from(hex, 'hex'));
|
|
16713
|
+
return PrivateKey.fromBuffer(buffer.Buffer.from(hex, 'hex'));
|
|
14363
16714
|
}
|
|
14364
16715
|
toHex() {
|
|
14365
16716
|
return this.toBuffer().toString('hex');
|
|
@@ -14382,7 +16733,7 @@
|
|
|
14382
16733
|
break;
|
|
14383
16734
|
}
|
|
14384
16735
|
case 'Buffer': {
|
|
14385
|
-
if (Buffer.isBuffer(value))
|
|
16736
|
+
if (buffer.Buffer.isBuffer(value))
|
|
14386
16737
|
return;
|
|
14387
16738
|
break;
|
|
14388
16739
|
}
|
|
@@ -14484,15 +16835,15 @@
|
|
|
14484
16835
|
if (compressed)
|
|
14485
16836
|
i += 4;
|
|
14486
16837
|
i += 27;
|
|
14487
|
-
const buffer = Buffer.alloc(65);
|
|
14488
|
-
buffer.writeUInt8(i, 0);
|
|
14489
|
-
this.r.toArrayLike(Buffer, 'be', 32).copy(buffer, 1);
|
|
14490
|
-
this.s.toArrayLike(Buffer, 'be', 32).copy(buffer, 33);
|
|
14491
|
-
return buffer;
|
|
16838
|
+
const buffer$1 = buffer.Buffer.alloc(65);
|
|
16839
|
+
buffer$1.writeUInt8(i, 0);
|
|
16840
|
+
this.r.toArrayLike(buffer.Buffer, 'be', 32).copy(buffer$1, 1);
|
|
16841
|
+
this.s.toArrayLike(buffer.Buffer, 'be', 32).copy(buffer$1, 33);
|
|
16842
|
+
return buffer$1;
|
|
14492
16843
|
}
|
|
14493
16844
|
toDER() {
|
|
14494
|
-
const rBa = this.r.toArrayLike(Buffer, 'be');
|
|
14495
|
-
const sBa = this.s.toArrayLike(Buffer, 'be');
|
|
16845
|
+
const rBa = this.r.toArrayLike(buffer.Buffer, 'be');
|
|
16846
|
+
const sBa = this.s.toArrayLike(buffer.Buffer, 'be');
|
|
14496
16847
|
const sequence = [];
|
|
14497
16848
|
// INTEGER
|
|
14498
16849
|
sequence.push(0x02, rBa.length);
|
|
@@ -14502,12 +16853,12 @@
|
|
|
14502
16853
|
Array.from(sBa).forEach(b => sequence.push(b));
|
|
14503
16854
|
// SEQUENCE
|
|
14504
16855
|
sequence.unshift(0x30, sequence.length);
|
|
14505
|
-
return Buffer.from(sequence);
|
|
16856
|
+
return buffer.Buffer.from(sequence);
|
|
14506
16857
|
}
|
|
14507
16858
|
toScriptSignature(hashType) {
|
|
14508
|
-
const hashTypeBuffer = Buffer.alloc(1);
|
|
16859
|
+
const hashTypeBuffer = buffer.Buffer.alloc(1);
|
|
14509
16860
|
hashTypeBuffer.writeUInt8(hashType, 0);
|
|
14510
|
-
return Buffer.concat([this.toDER(), hashTypeBuffer]);
|
|
16861
|
+
return buffer.Buffer.concat([this.toDER(), hashTypeBuffer]);
|
|
14511
16862
|
}
|
|
14512
16863
|
}
|
|
14513
16864
|
|
|
@@ -14516,24 +16867,24 @@
|
|
|
14516
16867
|
enforce('Buffer', hash);
|
|
14517
16868
|
enforce(BN, d);
|
|
14518
16869
|
if (nonce) {
|
|
14519
|
-
hash = sha256$1(Buffer.concat([hash, Buffer.alloc(nonce)]));
|
|
16870
|
+
hash = sha256$1(buffer.Buffer.concat([hash, buffer.Buffer.alloc(nonce)]));
|
|
14520
16871
|
}
|
|
14521
16872
|
// sanity check
|
|
14522
16873
|
if (hash.length !== 32)
|
|
14523
16874
|
throw new Error('Hash must be 256 bit');
|
|
14524
|
-
const x = d.toArrayLike(Buffer, 'be', 32);
|
|
14525
|
-
let k = Buffer.alloc(32);
|
|
14526
|
-
let v = Buffer.alloc(32);
|
|
16875
|
+
const x = d.toArrayLike(buffer.Buffer, 'be', 32);
|
|
16876
|
+
let k = buffer.Buffer.alloc(32);
|
|
16877
|
+
let v = buffer.Buffer.alloc(32);
|
|
14527
16878
|
// Step B
|
|
14528
16879
|
v.fill(1);
|
|
14529
16880
|
// Step C
|
|
14530
16881
|
k.fill(0);
|
|
14531
16882
|
// Step D
|
|
14532
|
-
k = HmacSHA256(Buffer.concat([v, Buffer.from([0]), x, hash]), k);
|
|
16883
|
+
k = HmacSHA256(buffer.Buffer.concat([v, buffer.Buffer.from([0]), x, hash]), k);
|
|
14533
16884
|
// Step E
|
|
14534
16885
|
v = HmacSHA256(v, k);
|
|
14535
16886
|
// Step F
|
|
14536
|
-
k = HmacSHA256(Buffer.concat([v, Buffer.from([1]), x, hash]), k);
|
|
16887
|
+
k = HmacSHA256(buffer.Buffer.concat([v, buffer.Buffer.from([1]), x, hash]), k);
|
|
14537
16888
|
// Step G
|
|
14538
16889
|
v = HmacSHA256(v, k);
|
|
14539
16890
|
// Step H1/H2a, ignored as tlen === qlen (256 bit)
|
|
@@ -14542,7 +16893,7 @@
|
|
|
14542
16893
|
let T = new BN(v);
|
|
14543
16894
|
// Step H3, repeat until T is within the interval [1, n - 1] and passes the supplied check
|
|
14544
16895
|
while ((T.isNeg() || T.isZero()) || (T.gte(new BN(curve.n.toString()))) || !checkSig(T)) {
|
|
14545
|
-
k = HmacSHA256(Buffer.concat([v, Buffer.from([0])]), k);
|
|
16896
|
+
k = HmacSHA256(buffer.Buffer.concat([v, buffer.Buffer.from([0])]), k);
|
|
14546
16897
|
v = HmacSHA256(v, k);
|
|
14547
16898
|
// Step H1/H2a, again, ignored as tlen === qlen (256 bit)
|
|
14548
16899
|
// Step H2b again
|
|
@@ -14639,10 +16990,10 @@
|
|
|
14639
16990
|
return new Signature(r, s, i);
|
|
14640
16991
|
}
|
|
14641
16992
|
toBuffer() {
|
|
14642
|
-
const buf = Buffer.alloc(65);
|
|
16993
|
+
const buf = buffer.Buffer.alloc(65);
|
|
14643
16994
|
buf.writeUInt8(this.i, 0);
|
|
14644
|
-
this.r.toArrayLike(Buffer, 'be', 32).copy(buf, 1);
|
|
14645
|
-
this.s.toArrayLike(Buffer, 'be', 32).copy(buf, 33);
|
|
16995
|
+
this.r.toArrayLike(buffer.Buffer, 'be', 32).copy(buf, 1);
|
|
16996
|
+
this.s.toArrayLike(buffer.Buffer, 'be', 32).copy(buf, 33);
|
|
14646
16997
|
return buf;
|
|
14647
16998
|
}
|
|
14648
16999
|
static signBuffer(buf, private_key) {
|
|
@@ -14650,7 +17001,7 @@
|
|
|
14650
17001
|
return Signature.signBufferSha256(_hash, private_key);
|
|
14651
17002
|
}
|
|
14652
17003
|
static signBufferSha256(buf_sha256, private_key) {
|
|
14653
|
-
if (buf_sha256.length !== 32 || !Buffer.isBuffer(buf_sha256)) {
|
|
17004
|
+
if (buf_sha256.length !== 32 || !buffer.Buffer.isBuffer(buf_sha256)) {
|
|
14654
17005
|
throw new Error("buf_sha256: 32 byte buffer required");
|
|
14655
17006
|
}
|
|
14656
17007
|
const privKey = typeof private_key === 'string' ? PrivateKey.fromWif(private_key) : private_key;
|
|
@@ -14664,8 +17015,8 @@
|
|
|
14664
17015
|
// Based on C++ is_fc_canonical logic
|
|
14665
17016
|
while (true) {
|
|
14666
17017
|
ecsignature = sign$3(secp256k1, buf_sha256, d, nonce++);
|
|
14667
|
-
const rBa = ecsignature.r.toArrayLike(Buffer, 'be', 32);
|
|
14668
|
-
const sBa = ecsignature.s.toArrayLike(Buffer, 'be', 32);
|
|
17018
|
+
const rBa = ecsignature.r.toArrayLike(buffer.Buffer, 'be', 32);
|
|
17019
|
+
const sBa = ecsignature.s.toArrayLike(buffer.Buffer, 'be', 32);
|
|
14669
17020
|
// Check for canonical signature based on Steem C++ implementation
|
|
14670
17021
|
// libraries/fc/src/crypto/elliptic_common.cpp is_fc_canonical
|
|
14671
17022
|
const isCanonical = !(rBa[0] & 0x80)
|
|
@@ -14695,7 +17046,7 @@
|
|
|
14695
17046
|
&& !(s[0] === 0 && !(s[1] & 0x80));
|
|
14696
17047
|
}
|
|
14697
17048
|
static sign(string, private_key) {
|
|
14698
|
-
return Signature.signBuffer(Buffer.from(string), private_key);
|
|
17049
|
+
return Signature.signBuffer(buffer.Buffer.from(string), private_key);
|
|
14699
17050
|
}
|
|
14700
17051
|
verifyBuffer(buf, public_key) {
|
|
14701
17052
|
const _hash = sha256$1(buf);
|
|
@@ -14730,7 +17081,7 @@
|
|
|
14730
17081
|
return v.eq(this.r);
|
|
14731
17082
|
}
|
|
14732
17083
|
static fromHex(hex) {
|
|
14733
|
-
return Signature.fromBuffer(Buffer.from(hex, 'hex'));
|
|
17084
|
+
return Signature.fromBuffer(buffer.Buffer.from(hex, 'hex'));
|
|
14734
17085
|
}
|
|
14735
17086
|
toHex() {
|
|
14736
17087
|
return this.toBuffer().toString('hex');
|
|
@@ -14768,19 +17119,19 @@
|
|
|
14768
17119
|
static fromPublicKey(public_key, compressed = true) {
|
|
14769
17120
|
const pub_buffer = public_key.toBuffer(compressed);
|
|
14770
17121
|
const checksum = ripemd160$1(pub_buffer).subarray(0, 4);
|
|
14771
|
-
const addr = Buffer.concat([pub_buffer, checksum]);
|
|
17122
|
+
const addr = buffer.Buffer.concat([pub_buffer, checksum]);
|
|
14772
17123
|
return getConfig().get('address_prefix') + bs58.encode(addr);
|
|
14773
17124
|
}
|
|
14774
17125
|
static fromPublic(public_key, compressed = true, version = 56) {
|
|
14775
17126
|
const sha2 = sha256$1(public_key.toBuffer(compressed));
|
|
14776
17127
|
const rep = ripemd160$1(sha2);
|
|
14777
|
-
const versionBuffer = Buffer.alloc(1);
|
|
17128
|
+
const versionBuffer = buffer.Buffer.alloc(1);
|
|
14778
17129
|
versionBuffer.writeUInt8(0xFF & version, 0);
|
|
14779
|
-
const addr = Buffer.concat([versionBuffer, rep]);
|
|
17130
|
+
const addr = buffer.Buffer.concat([versionBuffer, rep]);
|
|
14780
17131
|
let check = sha256$1(addr);
|
|
14781
17132
|
check = sha256$1(check);
|
|
14782
|
-
const buffer = Buffer.concat([addr, check.subarray(0, 4)]);
|
|
14783
|
-
return new Address(ripemd160$1(buffer));
|
|
17133
|
+
const buffer$1 = buffer.Buffer.concat([addr, check.subarray(0, 4)]);
|
|
17134
|
+
return new Address(ripemd160$1(buffer$1));
|
|
14784
17135
|
}
|
|
14785
17136
|
static toBuffer(address) {
|
|
14786
17137
|
return Address.fromString(address);
|
|
@@ -14794,7 +17145,7 @@
|
|
|
14794
17145
|
toString(address_prefix = String(getConfig().get('address_prefix')) || 'STM') {
|
|
14795
17146
|
// Always use ripemd160 checksum and STM prefix, as in original Steem-js
|
|
14796
17147
|
const checksum = ripemd160$1(this.addy).subarray(0, 4);
|
|
14797
|
-
const addy = Buffer.concat([this.addy, checksum]);
|
|
17148
|
+
const addy = buffer.Buffer.concat([this.addy, checksum]);
|
|
14798
17149
|
return address_prefix + bs58.encode(addy);
|
|
14799
17150
|
}
|
|
14800
17151
|
}
|
|
@@ -14815,7 +17166,7 @@
|
|
|
14815
17166
|
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
14816
17167
|
const array = new Uint8Array(size);
|
|
14817
17168
|
crypto.getRandomValues(array);
|
|
14818
|
-
return Buffer.from(array);
|
|
17169
|
+
return buffer.Buffer.from(array);
|
|
14819
17170
|
}
|
|
14820
17171
|
// Fallback to Node.js crypto only if Web Crypto API is not available
|
|
14821
17172
|
// This code path should not be reached in Node.js 18+ (which has Web Crypto API)
|
|
@@ -14845,8 +17196,39 @@
|
|
|
14845
17196
|
/**
|
|
14846
17197
|
* Signing constant used to reserve opcode space and prevent cross-protocol attacks.
|
|
14847
17198
|
* Output of `sha256('steem_jsonrpc_auth')`.
|
|
17199
|
+
* Using lazy initialization to avoid Buffer dependency issues in UMD builds.
|
|
14848
17200
|
*/
|
|
14849
|
-
|
|
17201
|
+
let _K = null;
|
|
17202
|
+
function getK() {
|
|
17203
|
+
if (!_K) {
|
|
17204
|
+
_K = buffer.Buffer.from('3b3b081e46ea808d5a96b08c4bc5003f5e15767090f344faab531ec57565136b', 'hex');
|
|
17205
|
+
}
|
|
17206
|
+
return _K;
|
|
17207
|
+
}
|
|
17208
|
+
// Create a Proxy to make K behave like a Buffer but with lazy initialization
|
|
17209
|
+
// This avoids executing Buffer.from() at module load time when Buffer may not be available in UMD builds
|
|
17210
|
+
new Proxy({}, {
|
|
17211
|
+
get(_target, prop) {
|
|
17212
|
+
const k = getK();
|
|
17213
|
+
const value = k[prop];
|
|
17214
|
+
if (typeof value === 'function') {
|
|
17215
|
+
return value.bind(k);
|
|
17216
|
+
}
|
|
17217
|
+
return value;
|
|
17218
|
+
},
|
|
17219
|
+
has(_target, prop) {
|
|
17220
|
+
const k = getK();
|
|
17221
|
+
return prop in k;
|
|
17222
|
+
},
|
|
17223
|
+
ownKeys(_target) {
|
|
17224
|
+
const k = getK();
|
|
17225
|
+
return Object.keys(k);
|
|
17226
|
+
},
|
|
17227
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
17228
|
+
const k = getK();
|
|
17229
|
+
return Object.getOwnPropertyDescriptor(k, prop);
|
|
17230
|
+
}
|
|
17231
|
+
});
|
|
14850
17232
|
/**
|
|
14851
17233
|
* Create request hash to be signed.
|
|
14852
17234
|
*
|
|
@@ -14860,16 +17242,16 @@
|
|
|
14860
17242
|
*/
|
|
14861
17243
|
function hashMessage(timestamp, account, method, params, nonce) {
|
|
14862
17244
|
// First hash: sha256(timestamp + account + method + params)
|
|
14863
|
-
const firstInput = Buffer.concat([
|
|
14864
|
-
Buffer.from(timestamp),
|
|
14865
|
-
Buffer.from(account),
|
|
14866
|
-
Buffer.from(method),
|
|
14867
|
-
Buffer.from(params)
|
|
17245
|
+
const firstInput = buffer.Buffer.concat([
|
|
17246
|
+
buffer.Buffer.from(timestamp),
|
|
17247
|
+
buffer.Buffer.from(account),
|
|
17248
|
+
buffer.Buffer.from(method),
|
|
17249
|
+
buffer.Buffer.from(params)
|
|
14868
17250
|
]);
|
|
14869
|
-
const firstHash = Buffer.from(sha256$2(firstInput));
|
|
17251
|
+
const firstHash = buffer.Buffer.from(sha256$2(firstInput));
|
|
14870
17252
|
// Second hash: sha256(K + firstHash + nonce)
|
|
14871
|
-
const secondInput = Buffer.concat([
|
|
14872
|
-
return Buffer.from(sha256$2(secondInput));
|
|
17253
|
+
const secondInput = buffer.Buffer.concat([getK(), firstHash, nonce]);
|
|
17254
|
+
return buffer.Buffer.from(sha256$2(secondInput));
|
|
14873
17255
|
}
|
|
14874
17256
|
/**
|
|
14875
17257
|
* Sign a JSON RPC Request.
|
|
@@ -14878,7 +17260,7 @@
|
|
|
14878
17260
|
if (!request.params) {
|
|
14879
17261
|
throw new Error('Unable to sign a request without params');
|
|
14880
17262
|
}
|
|
14881
|
-
const params = Buffer.from(JSON.stringify(request.params), 'utf8').toString('base64');
|
|
17263
|
+
const params = buffer.Buffer.from(JSON.stringify(request.params), 'utf8').toString('base64');
|
|
14882
17264
|
const nonceBytes = randomBytes(8);
|
|
14883
17265
|
const nonce = nonceBytes.toString('hex');
|
|
14884
17266
|
const timestamp = new Date().toISOString();
|
|
@@ -14928,7 +17310,7 @@
|
|
|
14928
17310
|
}
|
|
14929
17311
|
let params;
|
|
14930
17312
|
try {
|
|
14931
|
-
const jsonString = Buffer.from(signed.params, 'base64').toString('utf8');
|
|
17313
|
+
const jsonString = buffer.Buffer.from(signed.params, 'base64').toString('utf8');
|
|
14932
17314
|
params = JSON.parse(jsonString);
|
|
14933
17315
|
}
|
|
14934
17316
|
catch (cause) {
|
|
@@ -14938,7 +17320,7 @@
|
|
|
14938
17320
|
if (signed.nonce == undefined || typeof signed.nonce !== 'string') {
|
|
14939
17321
|
throw new Error('Invalid nonce');
|
|
14940
17322
|
}
|
|
14941
|
-
const nonce = Buffer.from(signed.nonce, 'hex');
|
|
17323
|
+
const nonce = buffer.Buffer.from(signed.nonce, 'hex');
|
|
14942
17324
|
if (nonce.length !== 8) {
|
|
14943
17325
|
throw new Error('Invalid nonce');
|
|
14944
17326
|
}
|
|
@@ -14962,7 +17344,6 @@
|
|
|
14962
17344
|
|
|
14963
17345
|
var rpcAuth = /*#__PURE__*/Object.freeze({
|
|
14964
17346
|
__proto__: null,
|
|
14965
|
-
K: K,
|
|
14966
17347
|
sign: sign$2,
|
|
14967
17348
|
validate: validate
|
|
14968
17349
|
});
|
|
@@ -22658,10 +25039,10 @@
|
|
|
22658
25039
|
for (const sig of signatures) {
|
|
22659
25040
|
// Each signature should be a Buffer or hex string
|
|
22660
25041
|
if (typeof sig === 'string') {
|
|
22661
|
-
const sigBuffer = Buffer.from(sig, 'hex');
|
|
25042
|
+
const sigBuffer = buffer.Buffer.from(sig, 'hex');
|
|
22662
25043
|
bb.append(sigBuffer);
|
|
22663
25044
|
}
|
|
22664
|
-
else if (Buffer.isBuffer(sig)) {
|
|
25045
|
+
else if (buffer.Buffer.isBuffer(sig)) {
|
|
22665
25046
|
bb.append(sig);
|
|
22666
25047
|
}
|
|
22667
25048
|
else {
|
|
@@ -22670,7 +25051,7 @@
|
|
|
22670
25051
|
}
|
|
22671
25052
|
}
|
|
22672
25053
|
bb.flip();
|
|
22673
|
-
return Buffer.from(bb.toBuffer());
|
|
25054
|
+
return buffer.Buffer.from(bb.toBuffer());
|
|
22674
25055
|
}
|
|
22675
25056
|
/**
|
|
22676
25057
|
* Serialize an operation to binary format
|
|
@@ -22792,7 +25173,7 @@
|
|
|
22792
25173
|
const pubKey = PublicKey.fromStringOrThrow(dataObj.memo_key);
|
|
22793
25174
|
bb.append(pubKey.toBuffer());
|
|
22794
25175
|
}
|
|
22795
|
-
else if (Buffer.isBuffer(dataObj.memo_key)) {
|
|
25176
|
+
else if (buffer.Buffer.isBuffer(dataObj.memo_key)) {
|
|
22796
25177
|
bb.append(dataObj.memo_key);
|
|
22797
25178
|
}
|
|
22798
25179
|
else if (dataObj.memo_key && typeof dataObj.memo_key.toBuffer === 'function') {
|
|
@@ -22886,7 +25267,7 @@
|
|
|
22886
25267
|
// ByteBuffer can accept number directly for small values
|
|
22887
25268
|
bb.writeInt64(amountValue);
|
|
22888
25269
|
bb.writeUint8(precision);
|
|
22889
|
-
const symbolBytes = Buffer.from(symbol, 'utf8');
|
|
25270
|
+
const symbolBytes = buffer.Buffer.from(symbol, 'utf8');
|
|
22890
25271
|
bb.append(symbolBytes);
|
|
22891
25272
|
for (let i = symbolBytes.length; i < 7; i++) {
|
|
22892
25273
|
bb.writeUint8(0);
|
|
@@ -22947,16 +25328,16 @@
|
|
|
22947
25328
|
nonceLong = Long.fromNumber(memo.nonce, true); // unsigned
|
|
22948
25329
|
}
|
|
22949
25330
|
// ByteBuffer.writeUint64 may not accept Long objects directly, so write manually
|
|
22950
|
-
const nonceBuf = Buffer.from(nonceLong.toBytesLE());
|
|
25331
|
+
const nonceBuf = buffer.Buffer.from(nonceLong.toBytesLE());
|
|
22951
25332
|
bb.append(nonceBuf);
|
|
22952
25333
|
// Write checksum (uint32)
|
|
22953
25334
|
bb.writeUint32(memo.check);
|
|
22954
25335
|
// Write encrypted data
|
|
22955
|
-
const encryptedBuffer = Buffer.from(memo.encrypted, 'hex');
|
|
25336
|
+
const encryptedBuffer = buffer.Buffer.from(memo.encrypted, 'hex');
|
|
22956
25337
|
bb.writeVarint32(encryptedBuffer.length);
|
|
22957
25338
|
bb.append(encryptedBuffer);
|
|
22958
25339
|
bb.flip();
|
|
22959
|
-
return Buffer.from(bb.toBuffer());
|
|
25340
|
+
return buffer.Buffer.from(bb.toBuffer());
|
|
22960
25341
|
}
|
|
22961
25342
|
}
|
|
22962
25343
|
const transaction = {
|
|
@@ -22970,7 +25351,7 @@
|
|
|
22970
25351
|
return trx;
|
|
22971
25352
|
},
|
|
22972
25353
|
toBuffer(trx) {
|
|
22973
|
-
return Buffer.from(JSON.stringify(trx));
|
|
25354
|
+
return buffer.Buffer.from(JSON.stringify(trx));
|
|
22974
25355
|
}
|
|
22975
25356
|
};
|
|
22976
25357
|
|
|
@@ -23024,7 +25405,7 @@
|
|
|
23024
25405
|
isWif(privWif) {
|
|
23025
25406
|
let isWif = false;
|
|
23026
25407
|
try {
|
|
23027
|
-
const bufWif = Buffer.from(bs58.decode(privWif));
|
|
25408
|
+
const bufWif = buffer.Buffer.from(bs58.decode(privWif));
|
|
23028
25409
|
const privKey = bufWif.slice(0, -4);
|
|
23029
25410
|
const checksum = bufWif.slice(-4);
|
|
23030
25411
|
let newChecksum = sha256$1(privKey);
|
|
@@ -23042,12 +25423,12 @@
|
|
|
23042
25423
|
toWif(name, password, role) {
|
|
23043
25424
|
const seed = name + role + password;
|
|
23044
25425
|
const brainKey = seed.trim().split(/[\t\n\v\f\r ]+/).join(' ');
|
|
23045
|
-
const hashSha256 = sha256$1(Buffer.from(brainKey));
|
|
23046
|
-
const privKey = Buffer.concat([Buffer.from([0x80]), hashSha256]);
|
|
25426
|
+
const hashSha256 = sha256$1(buffer.Buffer.from(brainKey));
|
|
25427
|
+
const privKey = buffer.Buffer.concat([buffer.Buffer.from([0x80]), hashSha256]);
|
|
23047
25428
|
let checksum = sha256$1(privKey);
|
|
23048
25429
|
checksum = sha256$1(checksum);
|
|
23049
25430
|
checksum = checksum.slice(0, 4);
|
|
23050
|
-
const privWif = Buffer.concat([privKey, checksum]);
|
|
25431
|
+
const privWif = buffer.Buffer.concat([privKey, checksum]);
|
|
23051
25432
|
return bs58.encode(privWif);
|
|
23052
25433
|
},
|
|
23053
25434
|
wifIsValid(privWif, pubWif) {
|
|
@@ -23072,13 +25453,13 @@
|
|
|
23072
25453
|
const signatures = [];
|
|
23073
25454
|
const trxObjWithSigs = trx;
|
|
23074
25455
|
if (Array.isArray(trxObjWithSigs.signatures)) {
|
|
23075
|
-
signatures.push(...trxObjWithSigs.signatures.map((sig) => Buffer.isBuffer(sig) ? sig.toString('hex') : String(sig)));
|
|
25456
|
+
signatures.push(...trxObjWithSigs.signatures.map((sig) => buffer.Buffer.isBuffer(sig) ? sig.toString('hex') : String(sig)));
|
|
23076
25457
|
}
|
|
23077
25458
|
const chainId = getConfig().get('chain_id') || '';
|
|
23078
|
-
const cid = Buffer.from(chainId, 'hex');
|
|
25459
|
+
const cid = buffer.Buffer.from(chainId, 'hex');
|
|
23079
25460
|
const buf = transaction.toBuffer(trx);
|
|
23080
25461
|
for (const key of keys) {
|
|
23081
|
-
const sig = Signature.signBuffer(Buffer.concat([cid, buf]), key);
|
|
25462
|
+
const sig = Signature.signBuffer(buffer.Buffer.concat([cid, buf]), key);
|
|
23082
25463
|
// Use toBuffer() to match old-steem-js behavior
|
|
23083
25464
|
// The serializer will convert Buffer to hex string when needed
|
|
23084
25465
|
signatures.push(sig.toBuffer().toString('hex'));
|
|
@@ -23099,7 +25480,7 @@
|
|
|
23099
25480
|
// Export crypto functions
|
|
23100
25481
|
const sign$1 = (message, privateKey) => {
|
|
23101
25482
|
const priv = PrivateKey.fromWif(privateKey);
|
|
23102
|
-
const sig = Signature.signBuffer(Buffer.from(message), priv);
|
|
25483
|
+
const sig = Signature.signBuffer(buffer.Buffer.from(message), priv);
|
|
23103
25484
|
return sig.toHex();
|
|
23104
25485
|
};
|
|
23105
25486
|
const verifySignature = (message, signature, publicKey) => {
|
|
@@ -23108,7 +25489,7 @@
|
|
|
23108
25489
|
if (!pub)
|
|
23109
25490
|
return false;
|
|
23110
25491
|
const sigObj = Signature.fromHex(signature);
|
|
23111
|
-
return sigObj.verifyBuffer(Buffer.from(message), pub);
|
|
25492
|
+
return sigObj.verifyBuffer(buffer.Buffer.from(message), pub);
|
|
23112
25493
|
}
|
|
23113
25494
|
catch {
|
|
23114
25495
|
return false;
|
|
@@ -23119,7 +25500,7 @@
|
|
|
23119
25500
|
const pub = PublicKey.fromString(publicKey);
|
|
23120
25501
|
if (!pub)
|
|
23121
25502
|
return false;
|
|
23122
|
-
const serialized = Buffer.from(JSON.stringify(transaction));
|
|
25503
|
+
const serialized = buffer.Buffer.from(JSON.stringify(transaction));
|
|
23123
25504
|
const trx = transaction;
|
|
23124
25505
|
if (!trx.signatures || !Array.isArray(trx.signatures))
|
|
23125
25506
|
return false;
|
|
@@ -23139,12 +25520,12 @@
|
|
|
23139
25520
|
};
|
|
23140
25521
|
const getPrivateKey = (seed) => {
|
|
23141
25522
|
const brainKey = seed.trim().split(/[\t\n\v\f\r ]+/).join(' ');
|
|
23142
|
-
const hashSha256 = sha256$1(Buffer.from(brainKey));
|
|
23143
|
-
const privKey = Buffer.concat([Buffer.from([0x80]), hashSha256]);
|
|
25523
|
+
const hashSha256 = sha256$1(buffer.Buffer.from(brainKey));
|
|
25524
|
+
const privKey = buffer.Buffer.concat([buffer.Buffer.from([0x80]), hashSha256]);
|
|
23144
25525
|
let checksum = sha256$1(privKey);
|
|
23145
25526
|
checksum = sha256$1(checksum);
|
|
23146
25527
|
checksum = checksum.slice(0, 4);
|
|
23147
|
-
const privWif = Buffer.concat([privKey, checksum]);
|
|
25528
|
+
const privWif = buffer.Buffer.concat([privKey, checksum]);
|
|
23148
25529
|
return bs58.encode(privWif);
|
|
23149
25530
|
};
|
|
23150
25531
|
// Add stub for test compatibility
|
|
@@ -24055,8 +26436,8 @@
|
|
|
24055
26436
|
const { getConfig } = await Promise.resolve().then(function () { return config$1; });
|
|
24056
26437
|
// sha256 is already imported at the top
|
|
24057
26438
|
const buf = transactionSerializer.toBuffer(transaction);
|
|
24058
|
-
const chainId = Buffer.from(getConfig().get('chain_id') || '', 'hex');
|
|
24059
|
-
const digest = Buffer.from(sha256$2(Buffer.concat([chainId, buf])));
|
|
26439
|
+
const chainId = buffer.Buffer.from(getConfig().get('chain_id') || '', 'hex');
|
|
26440
|
+
const digest = buffer.Buffer.from(sha256$2(buffer.Buffer.concat([chainId, buf])));
|
|
24060
26441
|
debug.transaction('\n=== Transaction Debug Info (before signing) ===');
|
|
24061
26442
|
debug.transaction('Transaction:', JSON.stringify(transaction, null, 2));
|
|
24062
26443
|
debug.transaction('Transaction.toHex():', buf.toString('hex'));
|
|
@@ -24303,7 +26684,7 @@
|
|
|
24303
26684
|
}
|
|
24304
26685
|
const blockObj = block;
|
|
24305
26686
|
const headBlockId = blockObj && blockObj.previous ? blockObj.previous : '0000000000000000000000000000000000000000';
|
|
24306
|
-
const refBlockPrefix = Buffer.from(headBlockId, 'hex').readUInt32LE(4);
|
|
26687
|
+
const refBlockPrefix = buffer.Buffer.from(headBlockId, 'hex').readUInt32LE(4);
|
|
24307
26688
|
const transactionObj = transaction;
|
|
24308
26689
|
return {
|
|
24309
26690
|
...transactionObj,
|
|
@@ -24882,7 +27263,7 @@
|
|
|
24882
27263
|
}
|
|
24883
27264
|
createSuggestedPassword() {
|
|
24884
27265
|
const PASSWORD_LENGTH = 32;
|
|
24885
|
-
const privateKey = PrivateKey.fromBuffer(Buffer.from(Array(32).fill(0).map(() => Math.floor(Math.random() * 256))));
|
|
27266
|
+
const privateKey = PrivateKey.fromBuffer(buffer.Buffer.from(Array(32).fill(0).map(() => Math.floor(Math.random() * 256))));
|
|
24886
27267
|
return privateKey.toWif().substring(3, 3 + PASSWORD_LENGTH);
|
|
24887
27268
|
}
|
|
24888
27269
|
reputation(reputation, decimal_places = 0) {
|
|
@@ -25453,7 +27834,7 @@
|
|
|
25453
27834
|
let uniqueNonceEntropy = null;
|
|
25454
27835
|
function sha512Buffer(data) {
|
|
25455
27836
|
const result = sha512(data);
|
|
25456
|
-
return Buffer.isBuffer(result) ? result : Buffer.from(result, 'hex');
|
|
27837
|
+
return buffer.Buffer.isBuffer(result) ? result : buffer.Buffer.from(result, 'hex');
|
|
25457
27838
|
}
|
|
25458
27839
|
class Aes {
|
|
25459
27840
|
static uniqueNonce() {
|
|
@@ -25476,11 +27857,11 @@
|
|
|
25476
27857
|
throw new TypeError('nonce is required');
|
|
25477
27858
|
}
|
|
25478
27859
|
let messageBuffer;
|
|
25479
|
-
if (!Buffer.isBuffer(message)) {
|
|
27860
|
+
if (!buffer.Buffer.isBuffer(message)) {
|
|
25480
27861
|
if (typeof message !== 'string') {
|
|
25481
27862
|
throw new TypeError('message should be buffer or string');
|
|
25482
27863
|
}
|
|
25483
|
-
messageBuffer = Buffer.from(message, 'binary');
|
|
27864
|
+
messageBuffer = buffer.Buffer.from(message, 'binary');
|
|
25484
27865
|
}
|
|
25485
27866
|
else {
|
|
25486
27867
|
messageBuffer = message;
|
|
@@ -25490,23 +27871,23 @@
|
|
|
25490
27871
|
// Convert nonce string to Long and write as uint64
|
|
25491
27872
|
const nonceLong = Long.fromString(nonce, true, 10); // unsigned, base 10
|
|
25492
27873
|
// ByteBuffer.writeUint64 may not accept Long objects directly, so write manually using toBytesLE
|
|
25493
|
-
const nonceBuf = Buffer.from(nonceLong.toBytesLE());
|
|
27874
|
+
const nonceBuf = buffer.Buffer.from(nonceLong.toBytesLE());
|
|
25494
27875
|
ebuf.append(nonceBuf);
|
|
25495
27876
|
ebuf.append(S.toString('binary'), 'binary');
|
|
25496
|
-
const ebufBuffer = Buffer.from(ebuf.copy(0, ebuf.offset).toBinary(), 'binary');
|
|
27877
|
+
const ebufBuffer = buffer.Buffer.from(ebuf.copy(0, ebuf.offset).toBinary(), 'binary');
|
|
25497
27878
|
const encryption_key = sha512Buffer(ebufBuffer);
|
|
25498
27879
|
const iv = encryption_key.slice(32, 48);
|
|
25499
27880
|
const key = encryption_key.slice(0, 32);
|
|
25500
27881
|
let check = sha256$1(encryption_key);
|
|
25501
|
-
if (!Buffer.isBuffer(check)) {
|
|
25502
|
-
check = Buffer.from(check, 'hex');
|
|
27882
|
+
if (!buffer.Buffer.isBuffer(check)) {
|
|
27883
|
+
check = buffer.Buffer.from(check, 'hex');
|
|
25503
27884
|
}
|
|
25504
27885
|
check = check.slice(0, 4);
|
|
25505
27886
|
const checkBinary = check.toString('binary');
|
|
25506
27887
|
const cbuf = ByteBuffer.fromBinary(checkBinary, ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
|
|
25507
27888
|
const checksum = cbuf.readUint32();
|
|
25508
27889
|
// Use @noble/ciphers for AES-256-CBC encryption
|
|
25509
|
-
const encrypted = Buffer.from(cbc(key, iv).encrypt(messageBuffer));
|
|
27890
|
+
const encrypted = buffer.Buffer.from(cbc(key, iv).encrypt(messageBuffer));
|
|
25510
27891
|
return {
|
|
25511
27892
|
nonce,
|
|
25512
27893
|
message: encrypted.toString('hex'),
|
|
@@ -25534,16 +27915,16 @@
|
|
|
25534
27915
|
// Convert nonce string to Long and write as uint64
|
|
25535
27916
|
const nonceLong = Long.fromString(nonce, true, 10); // unsigned, base 10
|
|
25536
27917
|
// ByteBuffer.writeUint64 may not accept Long objects directly, so write manually using toBytesLE
|
|
25537
|
-
const nonceBuf = Buffer.from(nonceLong.toBytesLE());
|
|
27918
|
+
const nonceBuf = buffer.Buffer.from(nonceLong.toBytesLE());
|
|
25538
27919
|
ebuf.append(nonceBuf);
|
|
25539
27920
|
ebuf.append(S.toString('binary'), 'binary');
|
|
25540
|
-
const ebufBuffer = Buffer.from(ebuf.copy(0, ebuf.offset).toBinary(), 'binary');
|
|
27921
|
+
const ebufBuffer = buffer.Buffer.from(ebuf.copy(0, ebuf.offset).toBinary(), 'binary');
|
|
25541
27922
|
const encryption_key = sha512Buffer(ebufBuffer);
|
|
25542
27923
|
const iv = encryption_key.slice(32, 48);
|
|
25543
27924
|
const key = encryption_key.slice(0, 32);
|
|
25544
27925
|
let check = sha256$1(encryption_key);
|
|
25545
|
-
if (!Buffer.isBuffer(check)) {
|
|
25546
|
-
check = Buffer.from(check, 'hex');
|
|
27926
|
+
if (!buffer.Buffer.isBuffer(check)) {
|
|
27927
|
+
check = buffer.Buffer.from(check, 'hex');
|
|
25547
27928
|
}
|
|
25548
27929
|
check = check.slice(0, 4);
|
|
25549
27930
|
const checkBinary = check.toString('binary');
|
|
@@ -25553,8 +27934,8 @@
|
|
|
25553
27934
|
throw new Error('Invalid checksum');
|
|
25554
27935
|
}
|
|
25555
27936
|
// Use @noble/ciphers for AES-256-CBC decryption
|
|
25556
|
-
const messageBuffer = Buffer.from(message, 'hex');
|
|
25557
|
-
return Buffer.from(cbc(key, iv).decrypt(messageBuffer));
|
|
27937
|
+
const messageBuffer = buffer.Buffer.from(message, 'hex');
|
|
27938
|
+
return buffer.Buffer.from(cbc(key, iv).decrypt(messageBuffer));
|
|
25558
27939
|
}
|
|
25559
27940
|
static fromSeed(seed) {
|
|
25560
27941
|
return sha256$1(seed);
|
|
@@ -25563,7 +27944,7 @@
|
|
|
25563
27944
|
return buffer;
|
|
25564
27945
|
}
|
|
25565
27946
|
static fromString(string) {
|
|
25566
|
-
return Buffer.from(string, 'hex');
|
|
27947
|
+
return buffer.Buffer.from(string, 'hex');
|
|
25567
27948
|
}
|
|
25568
27949
|
static toBuffer(aes) {
|
|
25569
27950
|
return aes;
|
|
@@ -25604,7 +27985,7 @@
|
|
|
25604
27985
|
}
|
|
25605
27986
|
const mbuf = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);
|
|
25606
27987
|
mbuf.writeVString(plain);
|
|
25607
|
-
const message = Buffer.from(mbuf.copy(0, mbuf.offset).toBinary(), 'binary');
|
|
27988
|
+
const message = buffer.Buffer.from(mbuf.copy(0, mbuf.offset).toBinary(), 'binary');
|
|
25608
27989
|
const { nonce, message: encrypted, checksum } = Aes.encrypt(privateKey, publicKey, message, testNonce);
|
|
25609
27990
|
const memoData = {
|
|
25610
27991
|
from: privateKey.toPublicKey(),
|
|
@@ -25633,7 +28014,7 @@
|
|
|
25633
28014
|
}
|
|
25634
28015
|
try {
|
|
25635
28016
|
const decoded = bs58.decode(memo);
|
|
25636
|
-
const memoData = Serializer.fromBuffer(Buffer.from(decoded));
|
|
28017
|
+
const memoData = Serializer.fromBuffer(buffer.Buffer.from(decoded));
|
|
25637
28018
|
const { from, to, nonce, check, encrypted } = memoData;
|
|
25638
28019
|
const pubkey = privateKey.toPublicKey().toString();
|
|
25639
28020
|
const otherpub = pubkey === from.toString() ? to : from;
|
|
@@ -25646,7 +28027,7 @@
|
|
|
25646
28027
|
catch {
|
|
25647
28028
|
mbuf.reset();
|
|
25648
28029
|
// Sender did not length-prefix the memo
|
|
25649
|
-
const memo = Buffer.from(mbuf.toString('binary'), 'binary').toString('utf-8');
|
|
28030
|
+
const memo = buffer.Buffer.from(mbuf.toString('binary'), 'binary').toString('utf-8');
|
|
25650
28031
|
return '#' + memo;
|
|
25651
28032
|
}
|
|
25652
28033
|
}
|
|
@@ -25747,7 +28128,6 @@
|
|
|
25747
28128
|
return new Convert(type);
|
|
25748
28129
|
}
|
|
25749
28130
|
|
|
25750
|
-
// Minimal implementation for types to satisfy test imports
|
|
25751
28131
|
const vote_id = {
|
|
25752
28132
|
fromObject: (id) => {
|
|
25753
28133
|
if (typeof id !== 'string') {
|
|
@@ -25833,7 +28213,7 @@
|
|
|
25833
28213
|
return [...arr].sort((a, b) => {
|
|
25834
28214
|
if (typeof a === 'number' && typeof b === 'number')
|
|
25835
28215
|
return a - b;
|
|
25836
|
-
if (Buffer.isBuffer(a) && Buffer.isBuffer(b))
|
|
28216
|
+
if (buffer.Buffer.isBuffer(a) && buffer.Buffer.isBuffer(b))
|
|
25837
28217
|
return a.toString('hex').localeCompare(b.toString('hex'));
|
|
25838
28218
|
if (typeof a === 'string' && typeof b === 'string')
|
|
25839
28219
|
return a.localeCompare(b);
|
|
@@ -25845,7 +28225,7 @@
|
|
|
25845
28225
|
toObject: (set) => [...set].sort((a, b) => {
|
|
25846
28226
|
if (typeof a === 'number' && typeof b === 'number')
|
|
25847
28227
|
return a - b;
|
|
25848
|
-
if (Buffer.isBuffer(a) && Buffer.isBuffer(b))
|
|
28228
|
+
if (buffer.Buffer.isBuffer(a) && buffer.Buffer.isBuffer(b))
|
|
25849
28229
|
return a.toString('hex').localeCompare(b.toString('hex'));
|
|
25850
28230
|
if (typeof a === 'string' && typeof b === 'string')
|
|
25851
28231
|
return a.localeCompare(b);
|
|
@@ -25892,7 +28272,7 @@
|
|
|
25892
28272
|
const kb = b[0];
|
|
25893
28273
|
if (typeof ka === 'number' && typeof kb === 'number')
|
|
25894
28274
|
return ka - kb;
|
|
25895
|
-
if (Buffer.isBuffer(ka) && Buffer.isBuffer(kb))
|
|
28275
|
+
if (buffer.Buffer.isBuffer(ka) && buffer.Buffer.isBuffer(kb))
|
|
25896
28276
|
return ka.toString('hex').localeCompare(kb.toString('hex'));
|
|
25897
28277
|
if (typeof ka === 'string' && typeof kb === 'string')
|
|
25898
28278
|
return ka.localeCompare(kb);
|
|
@@ -25904,7 +28284,7 @@
|
|
|
25904
28284
|
const kb = b[0];
|
|
25905
28285
|
if (typeof ka === 'number' && typeof kb === 'number')
|
|
25906
28286
|
return ka - kb;
|
|
25907
|
-
if (Buffer.isBuffer(ka) && Buffer.isBuffer(kb))
|
|
28287
|
+
if (buffer.Buffer.isBuffer(ka) && buffer.Buffer.isBuffer(kb))
|
|
25908
28288
|
return ka.toString('hex').localeCompare(kb.toString('hex'));
|
|
25909
28289
|
if (typeof ka === 'string' && typeof kb === 'string')
|
|
25910
28290
|
return ka.localeCompare(kb);
|
|
@@ -25933,12 +28313,12 @@
|
|
|
25933
28313
|
};
|
|
25934
28314
|
const string = {
|
|
25935
28315
|
toHex: (value) => {
|
|
25936
|
-
return Buffer.from(value, 'utf8').toString('hex');
|
|
28316
|
+
return buffer.Buffer.from(value, 'utf8').toString('hex');
|
|
25937
28317
|
}
|
|
25938
28318
|
};
|
|
25939
28319
|
const public_key = {
|
|
25940
28320
|
toHex: (key) => {
|
|
25941
|
-
return Buffer.from(key, 'utf8').toString('hex');
|
|
28321
|
+
return buffer.Buffer.from(key, 'utf8').toString('hex');
|
|
25942
28322
|
}
|
|
25943
28323
|
};
|
|
25944
28324
|
const uint16 = {
|
|
@@ -26005,7 +28385,7 @@
|
|
|
26005
28385
|
};
|
|
26006
28386
|
const type_id = {
|
|
26007
28387
|
toHex: (value) => {
|
|
26008
|
-
return Buffer.from(value, 'utf8').toString('hex');
|
|
28388
|
+
return buffer.Buffer.from(value, 'utf8').toString('hex');
|
|
26009
28389
|
}
|
|
26010
28390
|
};
|
|
26011
28391
|
const protocol_id_type = (_name) => ({
|
|
@@ -26095,22 +28475,22 @@
|
|
|
26095
28475
|
});
|
|
26096
28476
|
|
|
26097
28477
|
const serializeTransaction = (transaction) => {
|
|
26098
|
-
return Buffer.from(JSON.stringify(transaction));
|
|
28478
|
+
return buffer.Buffer.from(JSON.stringify(transaction));
|
|
26099
28479
|
};
|
|
26100
28480
|
const serializeOperation = (operation) => {
|
|
26101
|
-
return Buffer.from(JSON.stringify(operation));
|
|
28481
|
+
return buffer.Buffer.from(JSON.stringify(operation));
|
|
26102
28482
|
};
|
|
26103
28483
|
const getTransactionDigest = (transaction) => {
|
|
26104
28484
|
const serialized = serializeTransaction(transaction);
|
|
26105
|
-
const serializedBuf = Buffer.isBuffer(serialized) ? serialized : Buffer.from(serialized);
|
|
26106
|
-
return Buffer.from(sha256$2(serializedBuf));
|
|
28485
|
+
const serializedBuf = buffer.Buffer.isBuffer(serialized) ? serialized : buffer.Buffer.from(serialized);
|
|
28486
|
+
return buffer.Buffer.from(sha256$2(serializedBuf));
|
|
26107
28487
|
};
|
|
26108
28488
|
const getTransactionId = (transaction) => {
|
|
26109
28489
|
const digest = getTransactionDigest(transaction);
|
|
26110
28490
|
return digest.toString('hex');
|
|
26111
28491
|
};
|
|
26112
28492
|
const serialize = (operation) => {
|
|
26113
|
-
return Buffer.from(JSON.stringify(operation));
|
|
28493
|
+
return buffer.Buffer.from(JSON.stringify(operation));
|
|
26114
28494
|
};
|
|
26115
28495
|
const deserialize = (buffer) => {
|
|
26116
28496
|
if (!buffer || buffer.length === 0)
|
|
@@ -26144,20 +28524,20 @@
|
|
|
26144
28524
|
});
|
|
26145
28525
|
|
|
26146
28526
|
const sha256 = (data) => {
|
|
26147
|
-
const input = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
26148
|
-
return Buffer.from(sha256$2(input));
|
|
28527
|
+
const input = buffer.Buffer.isBuffer(data) ? data : buffer.Buffer.from(data);
|
|
28528
|
+
return buffer.Buffer.from(sha256$2(input));
|
|
26149
28529
|
};
|
|
26150
28530
|
const ripemd160 = (data) => {
|
|
26151
|
-
const input = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
26152
|
-
return Buffer.from(ripemd160$2(input));
|
|
28531
|
+
const input = buffer.Buffer.isBuffer(data) ? data : buffer.Buffer.from(data);
|
|
28532
|
+
return buffer.Buffer.from(ripemd160$2(input));
|
|
26153
28533
|
};
|
|
26154
28534
|
const doubleSha256 = (data) => {
|
|
26155
28535
|
return sha256(sha256(data));
|
|
26156
28536
|
};
|
|
26157
28537
|
const hmacSha256 = (key, data) => {
|
|
26158
|
-
const keyBuf = Buffer.isBuffer(key) ? key : Buffer.from(key);
|
|
26159
|
-
const dataBuf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
26160
|
-
return Buffer.from(hmac(sha256$2, keyBuf, dataBuf));
|
|
28538
|
+
const keyBuf = buffer.Buffer.isBuffer(key) ? key : buffer.Buffer.from(key);
|
|
28539
|
+
const dataBuf = buffer.Buffer.isBuffer(data) ? data : buffer.Buffer.from(data);
|
|
28540
|
+
return buffer.Buffer.from(hmac(sha256$2, keyBuf, dataBuf));
|
|
26161
28541
|
};
|
|
26162
28542
|
/**
|
|
26163
28543
|
* Generate a cryptographically secure key pair using ECC secp256k1
|
|
@@ -26181,7 +28561,7 @@
|
|
|
26181
28561
|
*/
|
|
26182
28562
|
const sign = (message, privateKey) => {
|
|
26183
28563
|
const privKey = PrivateKey.fromWif(privateKey);
|
|
26184
|
-
const messageBuffer = Buffer.isBuffer(message) ? message : Buffer.from(message);
|
|
28564
|
+
const messageBuffer = buffer.Buffer.isBuffer(message) ? message : buffer.Buffer.from(message);
|
|
26185
28565
|
const sig = Signature.signBuffer(messageBuffer, privKey);
|
|
26186
28566
|
return sig.toHex();
|
|
26187
28567
|
};
|
|
@@ -26199,7 +28579,7 @@
|
|
|
26199
28579
|
return false;
|
|
26200
28580
|
}
|
|
26201
28581
|
const sigObj = Signature.fromHex(signature);
|
|
26202
|
-
const messageBuffer = Buffer.isBuffer(message) ? message : Buffer.from(message);
|
|
28582
|
+
const messageBuffer = buffer.Buffer.isBuffer(message) ? message : buffer.Buffer.from(message);
|
|
26203
28583
|
return sigObj.verifyBuffer(messageBuffer, pub);
|
|
26204
28584
|
}
|
|
26205
28585
|
catch {
|
|
@@ -26247,6 +28627,24 @@
|
|
|
26247
28627
|
if (typeof setApi === 'function') {
|
|
26248
28628
|
setApi(api);
|
|
26249
28629
|
}
|
|
28630
|
+
// Make Buffer available globally for UMD builds
|
|
28631
|
+
// This ensures Buffer is available before the script finishes loading
|
|
28632
|
+
// Browser doesn't have native Buffer, so we use the buffer polyfill package
|
|
28633
|
+
if (typeof window !== 'undefined' || typeof globalThis !== 'undefined') {
|
|
28634
|
+
try {
|
|
28635
|
+
// BufferPolyfill is imported from 'buffer' package (polyfill for browser)
|
|
28636
|
+
// Expose it globally so code can use Buffer directly
|
|
28637
|
+
if (typeof globalThis !== 'undefined' && typeof globalThis.Buffer === 'undefined') {
|
|
28638
|
+
globalThis.Buffer = buffer.Buffer;
|
|
28639
|
+
}
|
|
28640
|
+
if (typeof window !== 'undefined' && typeof window.Buffer === 'undefined') {
|
|
28641
|
+
window.Buffer = buffer.Buffer;
|
|
28642
|
+
}
|
|
28643
|
+
}
|
|
28644
|
+
catch {
|
|
28645
|
+
// Buffer should be available from the inject plugin transformation
|
|
28646
|
+
}
|
|
28647
|
+
}
|
|
26250
28648
|
|
|
26251
28649
|
return steem;
|
|
26252
28650
|
|