@capxul/mcp 1.0.0-alpha.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -62
- package/dist/{_esm-DUwdnl5L.mjs → _esm-CC5QpzeQ.mjs} +2 -236
- package/dist/alchemy-rpc-BuobS4-x.mjs +2 -0
- package/dist/{alchemy-rpc-mjuofdCf.mjs → alchemy-rpc-vGO5qErZ.mjs} +23 -3
- package/dist/{chunk-Dg0SBOkb.mjs → chunk-B5meny8j.mjs} +3 -1
- package/dist/esm-D2-zCfAo.mjs +4088 -0
- package/dist/eventemitter3-D-pLUuAN.mjs +238 -0
- package/dist/lib-B8hqwgiz.mjs +654 -0
- package/dist/lib-BGlYlc2Y.mjs +3 -0
- package/dist/lib-BRkcywUv.mjs +539 -0
- package/dist/lib-BSq2-y-R.mjs +3 -0
- package/dist/lib-CifIgXqP.mjs +12219 -0
- package/dist/lib-CnLS6gjn.mjs +6980 -0
- package/dist/lib-Dn7-RQTV.mjs +3635 -0
- package/dist/lib-YbuuWTqT.mjs +3 -0
- package/dist/lib-cc_08w0f.mjs +2148 -0
- package/dist/lib-hCYuvdcy.mjs +1764 -0
- package/dist/lib-yehPdjuB.mjs +3 -0
- package/dist/main.mjs +31187 -4071
- package/dist/{src-BDIKpZXn.mjs → src-2B8HO-zu.mjs} +944 -789
- package/dist/src-HgvNZjX7.mjs +2 -0
- package/dist/{src-Cg8p_ZgR.mjs → src-Iv70gRG_.mjs} +1 -1
- package/package.json +14 -20
- package/dist/alchemy-rpc-DxVP2GsG.mjs +0 -2
- package/dist/src-BmSYoMhj.mjs +0 -2
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import { t as __commonJSMin } from "./chunk-B5meny8j.mjs";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@ethersproject+logger@5.8.0/node_modules/@ethersproject/logger/lib/_version.js
|
|
3
|
+
var require__version$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.version = void 0;
|
|
6
|
+
exports.version = "logger/5.8.0";
|
|
7
|
+
}));
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region ../../node_modules/.pnpm/@ethersproject+logger@5.8.0/node_modules/@ethersproject/logger/lib/index.js
|
|
10
|
+
var require_lib$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Logger = exports.ErrorCode = exports.LogLevel = void 0;
|
|
13
|
+
var _permanentCensorErrors = false;
|
|
14
|
+
var _censorErrors = false;
|
|
15
|
+
var LogLevels = {
|
|
16
|
+
debug: 1,
|
|
17
|
+
"default": 2,
|
|
18
|
+
info: 2,
|
|
19
|
+
warning: 3,
|
|
20
|
+
error: 4,
|
|
21
|
+
off: 5
|
|
22
|
+
};
|
|
23
|
+
var _logLevel = LogLevels["default"];
|
|
24
|
+
var _version_1 = require__version$1();
|
|
25
|
+
var _globalLogger = null;
|
|
26
|
+
function _checkNormalize() {
|
|
27
|
+
try {
|
|
28
|
+
var missing_1 = [];
|
|
29
|
+
[
|
|
30
|
+
"NFD",
|
|
31
|
+
"NFC",
|
|
32
|
+
"NFKD",
|
|
33
|
+
"NFKC"
|
|
34
|
+
].forEach(function(form) {
|
|
35
|
+
try {
|
|
36
|
+
if ("test".normalize(form) !== "test") throw new Error("bad normalize");
|
|
37
|
+
} catch (error) {
|
|
38
|
+
missing_1.push(form);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (missing_1.length) throw new Error("missing " + missing_1.join(", "));
|
|
42
|
+
if (String.fromCharCode(233).normalize("NFD") !== String.fromCharCode(101, 769)) throw new Error("broken implementation");
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return error.message;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
var _normalizeError = _checkNormalize();
|
|
49
|
+
var LogLevel;
|
|
50
|
+
(function(LogLevel) {
|
|
51
|
+
LogLevel["DEBUG"] = "DEBUG";
|
|
52
|
+
LogLevel["INFO"] = "INFO";
|
|
53
|
+
LogLevel["WARNING"] = "WARNING";
|
|
54
|
+
LogLevel["ERROR"] = "ERROR";
|
|
55
|
+
LogLevel["OFF"] = "OFF";
|
|
56
|
+
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
57
|
+
var ErrorCode;
|
|
58
|
+
(function(ErrorCode) {
|
|
59
|
+
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
60
|
+
ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
61
|
+
ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
62
|
+
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
63
|
+
ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
64
|
+
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
65
|
+
ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
66
|
+
ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
67
|
+
ErrorCode["MISSING_NEW"] = "MISSING_NEW";
|
|
68
|
+
ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
69
|
+
ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
70
|
+
ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
71
|
+
ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
72
|
+
ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
73
|
+
ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
74
|
+
ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
75
|
+
ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
76
|
+
ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
77
|
+
ErrorCode["ACTION_REJECTED"] = "ACTION_REJECTED";
|
|
78
|
+
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
|
|
79
|
+
var HEX = "0123456789abcdef";
|
|
80
|
+
exports.Logger = function() {
|
|
81
|
+
function Logger(version) {
|
|
82
|
+
Object.defineProperty(this, "version", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
value: version,
|
|
85
|
+
writable: false
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
Logger.prototype._log = function(logLevel, args) {
|
|
89
|
+
var level = logLevel.toLowerCase();
|
|
90
|
+
if (LogLevels[level] == null) this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
91
|
+
if (_logLevel > LogLevels[level]) return;
|
|
92
|
+
console.log.apply(console, args);
|
|
93
|
+
};
|
|
94
|
+
Logger.prototype.debug = function() {
|
|
95
|
+
var args = [];
|
|
96
|
+
for (var _i = 0; _i < arguments.length; _i++) args[_i] = arguments[_i];
|
|
97
|
+
this._log(Logger.levels.DEBUG, args);
|
|
98
|
+
};
|
|
99
|
+
Logger.prototype.info = function() {
|
|
100
|
+
var args = [];
|
|
101
|
+
for (var _i = 0; _i < arguments.length; _i++) args[_i] = arguments[_i];
|
|
102
|
+
this._log(Logger.levels.INFO, args);
|
|
103
|
+
};
|
|
104
|
+
Logger.prototype.warn = function() {
|
|
105
|
+
var args = [];
|
|
106
|
+
for (var _i = 0; _i < arguments.length; _i++) args[_i] = arguments[_i];
|
|
107
|
+
this._log(Logger.levels.WARNING, args);
|
|
108
|
+
};
|
|
109
|
+
Logger.prototype.makeError = function(message, code, params) {
|
|
110
|
+
if (_censorErrors) return this.makeError("censored error", code, {});
|
|
111
|
+
if (!code) code = Logger.errors.UNKNOWN_ERROR;
|
|
112
|
+
if (!params) params = {};
|
|
113
|
+
var messageDetails = [];
|
|
114
|
+
Object.keys(params).forEach(function(key) {
|
|
115
|
+
var value = params[key];
|
|
116
|
+
try {
|
|
117
|
+
if (value instanceof Uint8Array) {
|
|
118
|
+
var hex = "";
|
|
119
|
+
for (var i = 0; i < value.length; i++) {
|
|
120
|
+
hex += HEX[value[i] >> 4];
|
|
121
|
+
hex += HEX[value[i] & 15];
|
|
122
|
+
}
|
|
123
|
+
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
124
|
+
} else messageDetails.push(key + "=" + JSON.stringify(value));
|
|
125
|
+
} catch (error) {
|
|
126
|
+
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
messageDetails.push("code=" + code);
|
|
130
|
+
messageDetails.push("version=" + this.version);
|
|
131
|
+
var reason = message;
|
|
132
|
+
var url = "";
|
|
133
|
+
switch (code) {
|
|
134
|
+
case ErrorCode.NUMERIC_FAULT:
|
|
135
|
+
url = "NUMERIC_FAULT";
|
|
136
|
+
var fault = message;
|
|
137
|
+
switch (fault) {
|
|
138
|
+
case "overflow":
|
|
139
|
+
case "underflow":
|
|
140
|
+
case "division-by-zero":
|
|
141
|
+
url += "-" + fault;
|
|
142
|
+
break;
|
|
143
|
+
case "negative-power":
|
|
144
|
+
case "negative-width":
|
|
145
|
+
url += "-unsupported";
|
|
146
|
+
break;
|
|
147
|
+
case "unbound-bitwise-result":
|
|
148
|
+
url += "-unbound-result";
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case ErrorCode.CALL_EXCEPTION:
|
|
153
|
+
case ErrorCode.INSUFFICIENT_FUNDS:
|
|
154
|
+
case ErrorCode.MISSING_NEW:
|
|
155
|
+
case ErrorCode.NONCE_EXPIRED:
|
|
156
|
+
case ErrorCode.REPLACEMENT_UNDERPRICED:
|
|
157
|
+
case ErrorCode.TRANSACTION_REPLACED:
|
|
158
|
+
case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
|
|
159
|
+
url = code;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
if (url) message += " [ See: https://links.ethers.org/v5-errors-" + url + " ]";
|
|
163
|
+
if (messageDetails.length) message += " (" + messageDetails.join(", ") + ")";
|
|
164
|
+
var error = new Error(message);
|
|
165
|
+
error.reason = reason;
|
|
166
|
+
error.code = code;
|
|
167
|
+
Object.keys(params).forEach(function(key) {
|
|
168
|
+
error[key] = params[key];
|
|
169
|
+
});
|
|
170
|
+
return error;
|
|
171
|
+
};
|
|
172
|
+
Logger.prototype.throwError = function(message, code, params) {
|
|
173
|
+
throw this.makeError(message, code, params);
|
|
174
|
+
};
|
|
175
|
+
Logger.prototype.throwArgumentError = function(message, name, value) {
|
|
176
|
+
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
|
|
177
|
+
argument: name,
|
|
178
|
+
value
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
Logger.prototype.assert = function(condition, message, code, params) {
|
|
182
|
+
if (!!condition) return;
|
|
183
|
+
this.throwError(message, code, params);
|
|
184
|
+
};
|
|
185
|
+
Logger.prototype.assertArgument = function(condition, message, name, value) {
|
|
186
|
+
if (!!condition) return;
|
|
187
|
+
this.throwArgumentError(message, name, value);
|
|
188
|
+
};
|
|
189
|
+
Logger.prototype.checkNormalize = function(message) {
|
|
190
|
+
if (message == null) message = "platform missing String.prototype.normalize";
|
|
191
|
+
if (_normalizeError) this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
192
|
+
operation: "String.prototype.normalize",
|
|
193
|
+
form: _normalizeError
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
Logger.prototype.checkSafeUint53 = function(value, message) {
|
|
197
|
+
if (typeof value !== "number") return;
|
|
198
|
+
if (message == null) message = "value not safe";
|
|
199
|
+
if (value < 0 || value >= 9007199254740991) this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
200
|
+
operation: "checkSafeInteger",
|
|
201
|
+
fault: "out-of-safe-range",
|
|
202
|
+
value
|
|
203
|
+
});
|
|
204
|
+
if (value % 1) this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
205
|
+
operation: "checkSafeInteger",
|
|
206
|
+
fault: "non-integer",
|
|
207
|
+
value
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
Logger.prototype.checkArgumentCount = function(count, expectedCount, message) {
|
|
211
|
+
if (message) message = ": " + message;
|
|
212
|
+
else message = "";
|
|
213
|
+
if (count < expectedCount) this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
|
|
214
|
+
count,
|
|
215
|
+
expectedCount
|
|
216
|
+
});
|
|
217
|
+
if (count > expectedCount) this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
218
|
+
count,
|
|
219
|
+
expectedCount
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
Logger.prototype.checkNew = function(target, kind) {
|
|
223
|
+
if (target === Object || target == null) this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
224
|
+
};
|
|
225
|
+
Logger.prototype.checkAbstract = function(target, kind) {
|
|
226
|
+
if (target === kind) this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
227
|
+
name: target.name,
|
|
228
|
+
operation: "new"
|
|
229
|
+
});
|
|
230
|
+
else if (target === Object || target == null) this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
231
|
+
};
|
|
232
|
+
Logger.globalLogger = function() {
|
|
233
|
+
if (!_globalLogger) _globalLogger = new Logger(_version_1.version);
|
|
234
|
+
return _globalLogger;
|
|
235
|
+
};
|
|
236
|
+
Logger.setCensorship = function(censorship, permanent) {
|
|
237
|
+
if (!censorship && permanent) this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, { operation: "setCensorship" });
|
|
238
|
+
if (_permanentCensorErrors) {
|
|
239
|
+
if (!censorship) return;
|
|
240
|
+
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, { operation: "setCensorship" });
|
|
241
|
+
}
|
|
242
|
+
_censorErrors = !!censorship;
|
|
243
|
+
_permanentCensorErrors = !!permanent;
|
|
244
|
+
};
|
|
245
|
+
Logger.setLogLevel = function(logLevel) {
|
|
246
|
+
var level = LogLevels[logLevel.toLowerCase()];
|
|
247
|
+
if (level == null) {
|
|
248
|
+
Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
_logLevel = level;
|
|
252
|
+
};
|
|
253
|
+
Logger.from = function(version) {
|
|
254
|
+
return new Logger(version);
|
|
255
|
+
};
|
|
256
|
+
Logger.errors = ErrorCode;
|
|
257
|
+
Logger.levels = LogLevel;
|
|
258
|
+
return Logger;
|
|
259
|
+
}();
|
|
260
|
+
}));
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region ../../node_modules/.pnpm/@ethersproject+bytes@5.8.0/node_modules/@ethersproject/bytes/lib/_version.js
|
|
263
|
+
var require__version = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
264
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
265
|
+
exports.version = void 0;
|
|
266
|
+
exports.version = "bytes/5.8.0";
|
|
267
|
+
}));
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region ../../node_modules/.pnpm/@ethersproject+bytes@5.8.0/node_modules/@ethersproject/bytes/lib/index.js
|
|
270
|
+
var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
271
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
272
|
+
exports.joinSignature = exports.splitSignature = exports.hexZeroPad = exports.hexStripZeros = exports.hexValue = exports.hexConcat = exports.hexDataSlice = exports.hexDataLength = exports.hexlify = exports.isHexString = exports.zeroPad = exports.stripZeros = exports.concat = exports.arrayify = exports.isBytes = exports.isBytesLike = void 0;
|
|
273
|
+
var logger_1 = require_lib$1();
|
|
274
|
+
var _version_1 = require__version();
|
|
275
|
+
var logger = new logger_1.Logger(_version_1.version);
|
|
276
|
+
function isHexable(value) {
|
|
277
|
+
return !!value.toHexString;
|
|
278
|
+
}
|
|
279
|
+
function addSlice(array) {
|
|
280
|
+
if (array.slice) return array;
|
|
281
|
+
array.slice = function() {
|
|
282
|
+
var args = Array.prototype.slice.call(arguments);
|
|
283
|
+
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
284
|
+
};
|
|
285
|
+
return array;
|
|
286
|
+
}
|
|
287
|
+
function isBytesLike(value) {
|
|
288
|
+
return isHexString(value) && !(value.length % 2) || isBytes(value);
|
|
289
|
+
}
|
|
290
|
+
exports.isBytesLike = isBytesLike;
|
|
291
|
+
function isInteger(value) {
|
|
292
|
+
return typeof value === "number" && value == value && value % 1 === 0;
|
|
293
|
+
}
|
|
294
|
+
function isBytes(value) {
|
|
295
|
+
if (value == null) return false;
|
|
296
|
+
if (value.constructor === Uint8Array) return true;
|
|
297
|
+
if (typeof value === "string") return false;
|
|
298
|
+
if (!isInteger(value.length) || value.length < 0) return false;
|
|
299
|
+
for (var i = 0; i < value.length; i++) {
|
|
300
|
+
var v = value[i];
|
|
301
|
+
if (!isInteger(v) || v < 0 || v >= 256) return false;
|
|
302
|
+
}
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
exports.isBytes = isBytes;
|
|
306
|
+
function arrayify(value, options) {
|
|
307
|
+
if (!options) options = {};
|
|
308
|
+
if (typeof value === "number") {
|
|
309
|
+
logger.checkSafeUint53(value, "invalid arrayify value");
|
|
310
|
+
var result = [];
|
|
311
|
+
while (value) {
|
|
312
|
+
result.unshift(value & 255);
|
|
313
|
+
value = parseInt(String(value / 256));
|
|
314
|
+
}
|
|
315
|
+
if (result.length === 0) result.push(0);
|
|
316
|
+
return addSlice(new Uint8Array(result));
|
|
317
|
+
}
|
|
318
|
+
if (options.allowMissingPrefix && typeof value === "string" && value.substring(0, 2) !== "0x") value = "0x" + value;
|
|
319
|
+
if (isHexable(value)) value = value.toHexString();
|
|
320
|
+
if (isHexString(value)) {
|
|
321
|
+
var hex = value.substring(2);
|
|
322
|
+
if (hex.length % 2) if (options.hexPad === "left") hex = "0" + hex;
|
|
323
|
+
else if (options.hexPad === "right") hex += "0";
|
|
324
|
+
else logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
325
|
+
var result = [];
|
|
326
|
+
for (var i = 0; i < hex.length; i += 2) result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
327
|
+
return addSlice(new Uint8Array(result));
|
|
328
|
+
}
|
|
329
|
+
if (isBytes(value)) return addSlice(new Uint8Array(value));
|
|
330
|
+
return logger.throwArgumentError("invalid arrayify value", "value", value);
|
|
331
|
+
}
|
|
332
|
+
exports.arrayify = arrayify;
|
|
333
|
+
function concat(items) {
|
|
334
|
+
var objects = items.map(function(item) {
|
|
335
|
+
return arrayify(item);
|
|
336
|
+
});
|
|
337
|
+
var length = objects.reduce(function(accum, item) {
|
|
338
|
+
return accum + item.length;
|
|
339
|
+
}, 0);
|
|
340
|
+
var result = new Uint8Array(length);
|
|
341
|
+
objects.reduce(function(offset, object) {
|
|
342
|
+
result.set(object, offset);
|
|
343
|
+
return offset + object.length;
|
|
344
|
+
}, 0);
|
|
345
|
+
return addSlice(result);
|
|
346
|
+
}
|
|
347
|
+
exports.concat = concat;
|
|
348
|
+
function stripZeros(value) {
|
|
349
|
+
var result = arrayify(value);
|
|
350
|
+
if (result.length === 0) return result;
|
|
351
|
+
var start = 0;
|
|
352
|
+
while (start < result.length && result[start] === 0) start++;
|
|
353
|
+
if (start) result = result.slice(start);
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
exports.stripZeros = stripZeros;
|
|
357
|
+
function zeroPad(value, length) {
|
|
358
|
+
value = arrayify(value);
|
|
359
|
+
if (value.length > length) logger.throwArgumentError("value out of range", "value", arguments[0]);
|
|
360
|
+
var result = new Uint8Array(length);
|
|
361
|
+
result.set(value, length - value.length);
|
|
362
|
+
return addSlice(result);
|
|
363
|
+
}
|
|
364
|
+
exports.zeroPad = zeroPad;
|
|
365
|
+
function isHexString(value, length) {
|
|
366
|
+
if (typeof value !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) return false;
|
|
367
|
+
if (length && value.length !== 2 + 2 * length) return false;
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
exports.isHexString = isHexString;
|
|
371
|
+
var HexCharacters = "0123456789abcdef";
|
|
372
|
+
function hexlify(value, options) {
|
|
373
|
+
if (!options) options = {};
|
|
374
|
+
if (typeof value === "number") {
|
|
375
|
+
logger.checkSafeUint53(value, "invalid hexlify value");
|
|
376
|
+
var hex = "";
|
|
377
|
+
while (value) {
|
|
378
|
+
hex = HexCharacters[value & 15] + hex;
|
|
379
|
+
value = Math.floor(value / 16);
|
|
380
|
+
}
|
|
381
|
+
if (hex.length) {
|
|
382
|
+
if (hex.length % 2) hex = "0" + hex;
|
|
383
|
+
return "0x" + hex;
|
|
384
|
+
}
|
|
385
|
+
return "0x00";
|
|
386
|
+
}
|
|
387
|
+
if (typeof value === "bigint") {
|
|
388
|
+
value = value.toString(16);
|
|
389
|
+
if (value.length % 2) return "0x0" + value;
|
|
390
|
+
return "0x" + value;
|
|
391
|
+
}
|
|
392
|
+
if (options.allowMissingPrefix && typeof value === "string" && value.substring(0, 2) !== "0x") value = "0x" + value;
|
|
393
|
+
if (isHexable(value)) return value.toHexString();
|
|
394
|
+
if (isHexString(value)) {
|
|
395
|
+
if (value.length % 2) if (options.hexPad === "left") value = "0x0" + value.substring(2);
|
|
396
|
+
else if (options.hexPad === "right") value += "0";
|
|
397
|
+
else logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
398
|
+
return value.toLowerCase();
|
|
399
|
+
}
|
|
400
|
+
if (isBytes(value)) {
|
|
401
|
+
var result = "0x";
|
|
402
|
+
for (var i = 0; i < value.length; i++) {
|
|
403
|
+
var v = value[i];
|
|
404
|
+
result += HexCharacters[(v & 240) >> 4] + HexCharacters[v & 15];
|
|
405
|
+
}
|
|
406
|
+
return result;
|
|
407
|
+
}
|
|
408
|
+
return logger.throwArgumentError("invalid hexlify value", "value", value);
|
|
409
|
+
}
|
|
410
|
+
exports.hexlify = hexlify;
|
|
411
|
+
function hexDataLength(data) {
|
|
412
|
+
if (typeof data !== "string") data = hexlify(data);
|
|
413
|
+
else if (!isHexString(data) || data.length % 2) return null;
|
|
414
|
+
return (data.length - 2) / 2;
|
|
415
|
+
}
|
|
416
|
+
exports.hexDataLength = hexDataLength;
|
|
417
|
+
function hexDataSlice(data, offset, endOffset) {
|
|
418
|
+
if (typeof data !== "string") data = hexlify(data);
|
|
419
|
+
else if (!isHexString(data) || data.length % 2) logger.throwArgumentError("invalid hexData", "value", data);
|
|
420
|
+
offset = 2 + 2 * offset;
|
|
421
|
+
if (endOffset != null) return "0x" + data.substring(offset, 2 + 2 * endOffset);
|
|
422
|
+
return "0x" + data.substring(offset);
|
|
423
|
+
}
|
|
424
|
+
exports.hexDataSlice = hexDataSlice;
|
|
425
|
+
function hexConcat(items) {
|
|
426
|
+
var result = "0x";
|
|
427
|
+
items.forEach(function(item) {
|
|
428
|
+
result += hexlify(item).substring(2);
|
|
429
|
+
});
|
|
430
|
+
return result;
|
|
431
|
+
}
|
|
432
|
+
exports.hexConcat = hexConcat;
|
|
433
|
+
function hexValue(value) {
|
|
434
|
+
var trimmed = hexStripZeros(hexlify(value, { hexPad: "left" }));
|
|
435
|
+
if (trimmed === "0x") return "0x0";
|
|
436
|
+
return trimmed;
|
|
437
|
+
}
|
|
438
|
+
exports.hexValue = hexValue;
|
|
439
|
+
function hexStripZeros(value) {
|
|
440
|
+
if (typeof value !== "string") value = hexlify(value);
|
|
441
|
+
if (!isHexString(value)) logger.throwArgumentError("invalid hex string", "value", value);
|
|
442
|
+
value = value.substring(2);
|
|
443
|
+
var offset = 0;
|
|
444
|
+
while (offset < value.length && value[offset] === "0") offset++;
|
|
445
|
+
return "0x" + value.substring(offset);
|
|
446
|
+
}
|
|
447
|
+
exports.hexStripZeros = hexStripZeros;
|
|
448
|
+
function hexZeroPad(value, length) {
|
|
449
|
+
if (typeof value !== "string") value = hexlify(value);
|
|
450
|
+
else if (!isHexString(value)) logger.throwArgumentError("invalid hex string", "value", value);
|
|
451
|
+
if (value.length > 2 * length + 2) logger.throwArgumentError("value out of range", "value", arguments[1]);
|
|
452
|
+
while (value.length < 2 * length + 2) value = "0x0" + value.substring(2);
|
|
453
|
+
return value;
|
|
454
|
+
}
|
|
455
|
+
exports.hexZeroPad = hexZeroPad;
|
|
456
|
+
function splitSignature(signature) {
|
|
457
|
+
var result = {
|
|
458
|
+
r: "0x",
|
|
459
|
+
s: "0x",
|
|
460
|
+
_vs: "0x",
|
|
461
|
+
recoveryParam: 0,
|
|
462
|
+
v: 0,
|
|
463
|
+
yParityAndS: "0x",
|
|
464
|
+
compact: "0x"
|
|
465
|
+
};
|
|
466
|
+
if (isBytesLike(signature)) {
|
|
467
|
+
var bytes = arrayify(signature);
|
|
468
|
+
if (bytes.length === 64) {
|
|
469
|
+
result.v = 27 + (bytes[32] >> 7);
|
|
470
|
+
bytes[32] &= 127;
|
|
471
|
+
result.r = hexlify(bytes.slice(0, 32));
|
|
472
|
+
result.s = hexlify(bytes.slice(32, 64));
|
|
473
|
+
} else if (bytes.length === 65) {
|
|
474
|
+
result.r = hexlify(bytes.slice(0, 32));
|
|
475
|
+
result.s = hexlify(bytes.slice(32, 64));
|
|
476
|
+
result.v = bytes[64];
|
|
477
|
+
} else logger.throwArgumentError("invalid signature string", "signature", signature);
|
|
478
|
+
if (result.v < 27) if (result.v === 0 || result.v === 1) result.v += 27;
|
|
479
|
+
else logger.throwArgumentError("signature invalid v byte", "signature", signature);
|
|
480
|
+
result.recoveryParam = 1 - result.v % 2;
|
|
481
|
+
if (result.recoveryParam) bytes[32] |= 128;
|
|
482
|
+
result._vs = hexlify(bytes.slice(32, 64));
|
|
483
|
+
} else {
|
|
484
|
+
result.r = signature.r;
|
|
485
|
+
result.s = signature.s;
|
|
486
|
+
result.v = signature.v;
|
|
487
|
+
result.recoveryParam = signature.recoveryParam;
|
|
488
|
+
result._vs = signature._vs;
|
|
489
|
+
if (result._vs != null) {
|
|
490
|
+
var vs_1 = zeroPad(arrayify(result._vs), 32);
|
|
491
|
+
result._vs = hexlify(vs_1);
|
|
492
|
+
var recoveryParam = vs_1[0] >= 128 ? 1 : 0;
|
|
493
|
+
if (result.recoveryParam == null) result.recoveryParam = recoveryParam;
|
|
494
|
+
else if (result.recoveryParam !== recoveryParam) logger.throwArgumentError("signature recoveryParam mismatch _vs", "signature", signature);
|
|
495
|
+
vs_1[0] &= 127;
|
|
496
|
+
var s = hexlify(vs_1);
|
|
497
|
+
if (result.s == null) result.s = s;
|
|
498
|
+
else if (result.s !== s) logger.throwArgumentError("signature v mismatch _vs", "signature", signature);
|
|
499
|
+
}
|
|
500
|
+
if (result.recoveryParam == null) if (result.v == null) logger.throwArgumentError("signature missing v and recoveryParam", "signature", signature);
|
|
501
|
+
else if (result.v === 0 || result.v === 1) result.recoveryParam = result.v;
|
|
502
|
+
else result.recoveryParam = 1 - result.v % 2;
|
|
503
|
+
else if (result.v == null) result.v = 27 + result.recoveryParam;
|
|
504
|
+
else {
|
|
505
|
+
var recId = result.v === 0 || result.v === 1 ? result.v : 1 - result.v % 2;
|
|
506
|
+
if (result.recoveryParam !== recId) logger.throwArgumentError("signature recoveryParam mismatch v", "signature", signature);
|
|
507
|
+
}
|
|
508
|
+
if (result.r == null || !isHexString(result.r)) logger.throwArgumentError("signature missing or invalid r", "signature", signature);
|
|
509
|
+
else result.r = hexZeroPad(result.r, 32);
|
|
510
|
+
if (result.s == null || !isHexString(result.s)) logger.throwArgumentError("signature missing or invalid s", "signature", signature);
|
|
511
|
+
else result.s = hexZeroPad(result.s, 32);
|
|
512
|
+
var vs = arrayify(result.s);
|
|
513
|
+
if (vs[0] >= 128) logger.throwArgumentError("signature s out of range", "signature", signature);
|
|
514
|
+
if (result.recoveryParam) vs[0] |= 128;
|
|
515
|
+
var _vs = hexlify(vs);
|
|
516
|
+
if (result._vs) {
|
|
517
|
+
if (!isHexString(result._vs)) logger.throwArgumentError("signature invalid _vs", "signature", signature);
|
|
518
|
+
result._vs = hexZeroPad(result._vs, 32);
|
|
519
|
+
}
|
|
520
|
+
if (result._vs == null) result._vs = _vs;
|
|
521
|
+
else if (result._vs !== _vs) logger.throwArgumentError("signature _vs mismatch v and s", "signature", signature);
|
|
522
|
+
}
|
|
523
|
+
result.yParityAndS = result._vs;
|
|
524
|
+
result.compact = result.r + result.yParityAndS.substring(2);
|
|
525
|
+
return result;
|
|
526
|
+
}
|
|
527
|
+
exports.splitSignature = splitSignature;
|
|
528
|
+
function joinSignature(signature) {
|
|
529
|
+
signature = splitSignature(signature);
|
|
530
|
+
return hexlify(concat([
|
|
531
|
+
signature.r,
|
|
532
|
+
signature.s,
|
|
533
|
+
signature.recoveryParam ? "0x1c" : "0x1b"
|
|
534
|
+
]));
|
|
535
|
+
}
|
|
536
|
+
exports.joinSignature = joinSignature;
|
|
537
|
+
}));
|
|
538
|
+
//#endregion
|
|
539
|
+
export { require_lib$1 as n, require_lib as t };
|