@neardefi/shade-agent-js
Version:
This library is intended to be used in conjunction with the [shade agent template](https://github.com/NearDeFi/shade-agent-template/).
1,150 lines (1,133 loc) • 674 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
// node_modules/borsh/lib/cjs/types.js
var require_types = __commonJS({
"node_modules/borsh/lib/cjs/types.js"(exports2) {
"use strict";
exports2.__esModule = true;
exports2.integers = void 0;
exports2.integers = ["u8", "u16", "u32", "u64", "u128", "i8", "i16", "i32", "i64", "i128", "f32", "f64"];
}
});
// node_modules/borsh/lib/cjs/buffer.js
var require_buffer = __commonJS({
"node_modules/borsh/lib/cjs/buffer.js"(exports2) {
"use strict";
exports2.__esModule = true;
exports2.DecodeBuffer = exports2.EncodeBuffer = void 0;
var EncodeBuffer = (
/** @class */
function() {
function EncodeBuffer2() {
this.offset = 0;
this.buffer_size = 256;
this.buffer = new ArrayBuffer(this.buffer_size);
this.view = new DataView(this.buffer);
}
EncodeBuffer2.prototype.resize_if_necessary = function(needed_space) {
if (this.buffer_size - this.offset < needed_space) {
this.buffer_size = Math.max(this.buffer_size * 2, this.buffer_size + needed_space);
var new_buffer = new ArrayBuffer(this.buffer_size);
new Uint8Array(new_buffer).set(new Uint8Array(this.buffer));
this.buffer = new_buffer;
this.view = new DataView(new_buffer);
}
};
EncodeBuffer2.prototype.get_used_buffer = function() {
return new Uint8Array(this.buffer).slice(0, this.offset);
};
EncodeBuffer2.prototype.store_value = function(value, type) {
var bSize = type.substring(1);
var size = parseInt(bSize) / 8;
this.resize_if_necessary(size);
var toCall = type[0] === "f" ? "setFloat".concat(bSize) : type[0] === "i" ? "setInt".concat(bSize) : "setUint".concat(bSize);
this.view[toCall](this.offset, value, true);
this.offset += size;
};
EncodeBuffer2.prototype.store_bytes = function(from) {
this.resize_if_necessary(from.length);
new Uint8Array(this.buffer).set(new Uint8Array(from), this.offset);
this.offset += from.length;
};
return EncodeBuffer2;
}()
);
exports2.EncodeBuffer = EncodeBuffer;
var DecodeBuffer = (
/** @class */
function() {
function DecodeBuffer2(buf) {
this.offset = 0;
this.buffer_size = buf.length;
this.buffer = new ArrayBuffer(buf.length);
new Uint8Array(this.buffer).set(buf);
this.view = new DataView(this.buffer);
}
DecodeBuffer2.prototype.assert_enough_buffer = function(size) {
if (this.offset + size > this.buffer.byteLength) {
throw new Error("Error in schema, the buffer is smaller than expected");
}
};
DecodeBuffer2.prototype.consume_value = function(type) {
var bSize = type.substring(1);
var size = parseInt(bSize) / 8;
this.assert_enough_buffer(size);
var toCall = type[0] === "f" ? "getFloat".concat(bSize) : type[0] === "i" ? "getInt".concat(bSize) : "getUint".concat(bSize);
var ret = this.view[toCall](this.offset, true);
this.offset += size;
return ret;
};
DecodeBuffer2.prototype.consume_bytes = function(size) {
this.assert_enough_buffer(size);
var ret = this.buffer.slice(this.offset, this.offset + size);
this.offset += size;
return ret;
};
return DecodeBuffer2;
}()
);
exports2.DecodeBuffer = DecodeBuffer;
}
});
// node_modules/borsh/lib/cjs/utils.js
var require_utils = __commonJS({
"node_modules/borsh/lib/cjs/utils.js"(exports2) {
"use strict";
var __extends = exports2 && exports2.__extends || /* @__PURE__ */ function() {
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
d2.__proto__ = b2;
} || function(d2, b2) {
for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
};
return extendStatics(d, b);
};
return function(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
}();
exports2.__esModule = true;
exports2.validate_schema = exports2.ErrorSchema = exports2.expect_enum = exports2.expect_same_size = exports2.expect_bigint = exports2.expect_type = exports2.isArrayLike = void 0;
var types_js_1 = require_types();
function isArrayLike(value) {
return Array.isArray(value) || !!value && typeof value === "object" && "length" in value && typeof value.length === "number" && (value.length === 0 || value.length > 0 && value.length - 1 in value);
}
exports2.isArrayLike = isArrayLike;
function expect_type(value, type, fieldPath) {
if (typeof value !== type) {
throw new Error("Expected ".concat(type, " not ").concat(typeof value, "(").concat(value, ") at ").concat(fieldPath.join(".")));
}
}
exports2.expect_type = expect_type;
function expect_bigint(value, fieldPath) {
var basicType = ["number", "string", "bigint", "boolean"].includes(typeof value);
var strObject = typeof value === "object" && value !== null && "toString" in value;
if (!basicType && !strObject) {
throw new Error("Expected bigint, number, boolean or string not ".concat(typeof value, "(").concat(value, ") at ").concat(fieldPath.join(".")));
}
}
exports2.expect_bigint = expect_bigint;
function expect_same_size(length, expected, fieldPath) {
if (length !== expected) {
throw new Error("Array length ".concat(length, " does not match schema length ").concat(expected, " at ").concat(fieldPath.join(".")));
}
}
exports2.expect_same_size = expect_same_size;
function expect_enum(value, fieldPath) {
if (typeof value !== "object" || value === null) {
throw new Error("Expected object not ".concat(typeof value, "(").concat(value, ") at ").concat(fieldPath.join(".")));
}
}
exports2.expect_enum = expect_enum;
var VALID_STRING_TYPES = types_js_1.integers.concat(["bool", "string"]);
var VALID_OBJECT_KEYS = ["option", "enum", "array", "set", "map", "struct"];
var ErrorSchema = (
/** @class */
function(_super) {
__extends(ErrorSchema2, _super);
function ErrorSchema2(schema, expected) {
var message = "Invalid schema: ".concat(JSON.stringify(schema), " expected ").concat(expected);
return _super.call(this, message) || this;
}
return ErrorSchema2;
}(Error)
);
exports2.ErrorSchema = ErrorSchema;
function validate_schema(schema) {
if (typeof schema === "string" && VALID_STRING_TYPES.includes(schema)) {
return;
}
if (schema && typeof schema === "object") {
var keys = Object.keys(schema);
if (keys.length === 1 && VALID_OBJECT_KEYS.includes(keys[0])) {
var key = keys[0];
if (key === "option")
return validate_schema(schema[key]);
if (key === "enum")
return validate_enum_schema(schema[key]);
if (key === "array")
return validate_array_schema(schema[key]);
if (key === "set")
return validate_schema(schema[key]);
if (key === "map")
return validate_map_schema(schema[key]);
if (key === "struct")
return validate_struct_schema(schema[key]);
}
}
throw new ErrorSchema(schema, VALID_OBJECT_KEYS.join(", ") + " or " + VALID_STRING_TYPES.join(", "));
}
exports2.validate_schema = validate_schema;
function validate_enum_schema(schema) {
if (!Array.isArray(schema))
throw new ErrorSchema(schema, "Array");
for (var _i = 0, schema_1 = schema; _i < schema_1.length; _i++) {
var sch = schema_1[_i];
if (typeof sch !== "object" || !("struct" in sch)) {
throw new Error('Missing "struct" key in enum schema');
}
if (typeof sch.struct !== "object" || Object.keys(sch.struct).length !== 1) {
throw new Error('The "struct" in each enum must have a single key');
}
validate_schema({ struct: sch.struct });
}
}
function validate_array_schema(schema) {
if (typeof schema !== "object")
throw new ErrorSchema(schema, "{ type, len? }");
if (schema.len && typeof schema.len !== "number") {
throw new Error("Invalid schema: ".concat(schema));
}
if ("type" in schema)
return validate_schema(schema.type);
throw new ErrorSchema(schema, "{ type, len? }");
}
function validate_map_schema(schema) {
if (typeof schema === "object" && "key" in schema && "value" in schema) {
validate_schema(schema.key);
validate_schema(schema.value);
} else {
throw new ErrorSchema(schema, "{ key, value }");
}
}
function validate_struct_schema(schema) {
if (typeof schema !== "object")
throw new ErrorSchema(schema, "object");
for (var key in schema) {
validate_schema(schema[key]);
}
}
}
});
// node_modules/borsh/lib/cjs/serialize.js
var require_serialize = __commonJS({
"node_modules/borsh/lib/cjs/serialize.js"(exports2) {
"use strict";
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
if (k2 === void 0) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() {
return m[k];
} };
}
Object.defineProperty(o, k2, desc);
} : function(o, m, k, k2) {
if (k2 === void 0) k2 = k;
o[k2] = m[k];
});
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
} : function(o, v) {
o["default"] = v;
});
var __importStar = exports2 && exports2.__importStar || function(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) {
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
}
__setModuleDefault(result, mod);
return result;
};
exports2.__esModule = true;
exports2.BorshSerializer = void 0;
var types_js_1 = require_types();
var buffer_js_1 = require_buffer();
var utils = __importStar(require_utils());
var BorshSerializer = (
/** @class */
function() {
function BorshSerializer2(checkTypes) {
this.encoded = new buffer_js_1.EncodeBuffer();
this.fieldPath = ["value"];
this.checkTypes = checkTypes;
}
BorshSerializer2.prototype.encode = function(value, schema) {
this.encode_value(value, schema);
return this.encoded.get_used_buffer();
};
BorshSerializer2.prototype.encode_value = function(value, schema) {
if (typeof schema === "string") {
if (types_js_1.integers.includes(schema))
return this.encode_integer(value, schema);
if (schema === "string")
return this.encode_string(value);
if (schema === "bool")
return this.encode_boolean(value);
}
if (typeof schema === "object") {
if ("option" in schema)
return this.encode_option(value, schema);
if ("enum" in schema)
return this.encode_enum(value, schema);
if ("array" in schema)
return this.encode_array(value, schema);
if ("set" in schema)
return this.encode_set(value, schema);
if ("map" in schema)
return this.encode_map(value, schema);
if ("struct" in schema)
return this.encode_struct(value, schema);
}
};
BorshSerializer2.prototype.encode_integer = function(value, schema) {
var size = parseInt(schema.substring(1));
if (size <= 32 || schema == "f64") {
this.checkTypes && utils.expect_type(value, "number", this.fieldPath);
this.encoded.store_value(value, schema);
} else {
this.checkTypes && utils.expect_bigint(value, this.fieldPath);
this.encode_bigint(BigInt(value), size);
}
};
BorshSerializer2.prototype.encode_bigint = function(value, size) {
var buffer_len = size / 8;
var buffer = new Uint8Array(buffer_len);
for (var i = 0; i < buffer_len; i++) {
buffer[i] = Number(value & BigInt(255));
value = value >> BigInt(8);
}
this.encoded.store_bytes(new Uint8Array(buffer));
};
BorshSerializer2.prototype.encode_string = function(value) {
this.checkTypes && utils.expect_type(value, "string", this.fieldPath);
var _value = value;
this.encoded.store_value(_value.length, "u32");
for (var i = 0; i < _value.length; i++) {
this.encoded.store_value(_value.charCodeAt(i), "u8");
}
};
BorshSerializer2.prototype.encode_boolean = function(value) {
this.checkTypes && utils.expect_type(value, "boolean", this.fieldPath);
this.encoded.store_value(value ? 1 : 0, "u8");
};
BorshSerializer2.prototype.encode_option = function(value, schema) {
if (value === null || value === void 0) {
this.encoded.store_value(0, "u8");
} else {
this.encoded.store_value(1, "u8");
this.encode_value(value, schema.option);
}
};
BorshSerializer2.prototype.encode_enum = function(value, schema) {
this.checkTypes && utils.expect_enum(value, this.fieldPath);
var valueKey = Object.keys(value)[0];
for (var i = 0; i < schema["enum"].length; i++) {
var valueSchema = schema["enum"][i];
if (valueKey === Object.keys(valueSchema.struct)[0]) {
this.encoded.store_value(i, "u8");
return this.encode_struct(value, valueSchema);
}
}
throw new Error("Enum key (".concat(valueKey, ") not found in enum schema: ").concat(JSON.stringify(schema), " at ").concat(this.fieldPath.join(".")));
};
BorshSerializer2.prototype.encode_array = function(value, schema) {
if (utils.isArrayLike(value))
return this.encode_arraylike(value, schema);
if (value instanceof ArrayBuffer)
return this.encode_buffer(value, schema);
throw new Error("Expected Array-like not ".concat(typeof value, "(").concat(value, ") at ").concat(this.fieldPath.join(".")));
};
BorshSerializer2.prototype.encode_arraylike = function(value, schema) {
if (schema.array.len) {
utils.expect_same_size(value.length, schema.array.len, this.fieldPath);
} else {
this.encoded.store_value(value.length, "u32");
}
for (var i = 0; i < value.length; i++) {
this.encode_value(value[i], schema.array.type);
}
};
BorshSerializer2.prototype.encode_buffer = function(value, schema) {
if (schema.array.len) {
utils.expect_same_size(value.byteLength, schema.array.len, this.fieldPath);
} else {
this.encoded.store_value(value.byteLength, "u32");
}
this.encoded.store_bytes(new Uint8Array(value));
};
BorshSerializer2.prototype.encode_set = function(value, schema) {
this.checkTypes && utils.expect_type(value, "object", this.fieldPath);
var isSet = value instanceof Set;
var values = isSet ? Array.from(value.values()) : Object.values(value);
this.encoded.store_value(values.length, "u32");
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
var value_1 = values_1[_i];
this.encode_value(value_1, schema.set);
}
};
BorshSerializer2.prototype.encode_map = function(value, schema) {
this.checkTypes && utils.expect_type(value, "object", this.fieldPath);
var isMap = value instanceof Map;
var keys = isMap ? Array.from(value.keys()) : Object.keys(value);
this.encoded.store_value(keys.length, "u32");
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
var key = keys_1[_i];
this.encode_value(key, schema.map.key);
this.encode_value(isMap ? value.get(key) : value[key], schema.map.value);
}
};
BorshSerializer2.prototype.encode_struct = function(value, schema) {
this.checkTypes && utils.expect_type(value, "object", this.fieldPath);
for (var _i = 0, _a = Object.keys(schema.struct); _i < _a.length; _i++) {
var key = _a[_i];
this.fieldPath.push(key);
this.encode_value(value[key], schema.struct[key]);
this.fieldPath.pop();
}
};
return BorshSerializer2;
}()
);
exports2.BorshSerializer = BorshSerializer;
}
});
// node_modules/borsh/lib/cjs/deserialize.js
var require_deserialize = __commonJS({
"node_modules/borsh/lib/cjs/deserialize.js"(exports2) {
"use strict";
exports2.__esModule = true;
exports2.BorshDeserializer = void 0;
var types_js_1 = require_types();
var buffer_js_1 = require_buffer();
var BorshDeserializer = (
/** @class */
function() {
function BorshDeserializer2(bufferArray) {
this.buffer = new buffer_js_1.DecodeBuffer(bufferArray);
}
BorshDeserializer2.prototype.decode = function(schema) {
return this.decode_value(schema);
};
BorshDeserializer2.prototype.decode_value = function(schema) {
if (typeof schema === "string") {
if (types_js_1.integers.includes(schema))
return this.decode_integer(schema);
if (schema === "string")
return this.decode_string();
if (schema === "bool")
return this.decode_boolean();
}
if (typeof schema === "object") {
if ("option" in schema)
return this.decode_option(schema);
if ("enum" in schema)
return this.decode_enum(schema);
if ("array" in schema)
return this.decode_array(schema);
if ("set" in schema)
return this.decode_set(schema);
if ("map" in schema)
return this.decode_map(schema);
if ("struct" in schema)
return this.decode_struct(schema);
}
throw new Error("Unsupported type: ".concat(schema));
};
BorshDeserializer2.prototype.decode_integer = function(schema) {
var size = parseInt(schema.substring(1));
if (size <= 32 || schema == "f64") {
return this.buffer.consume_value(schema);
}
return this.decode_bigint(size, schema.startsWith("i"));
};
BorshDeserializer2.prototype.decode_bigint = function(size, signed) {
if (signed === void 0) {
signed = false;
}
var buffer_len = size / 8;
var buffer = new Uint8Array(this.buffer.consume_bytes(buffer_len));
var bits = buffer.reduceRight(function(r, x) {
return r + x.toString(16).padStart(2, "0");
}, "");
if (signed && buffer[buffer_len - 1]) {
return BigInt.asIntN(size, BigInt("0x".concat(bits)));
}
return BigInt("0x".concat(bits));
};
BorshDeserializer2.prototype.decode_string = function() {
var len = this.decode_integer("u32");
var buffer = new Uint8Array(this.buffer.consume_bytes(len));
return String.fromCharCode.apply(null, buffer);
};
BorshDeserializer2.prototype.decode_boolean = function() {
return this.buffer.consume_value("u8") > 0;
};
BorshDeserializer2.prototype.decode_option = function(schema) {
var option = this.buffer.consume_value("u8");
if (option === 1) {
return this.decode_value(schema.option);
}
if (option !== 0) {
throw new Error("Invalid option ".concat(option));
}
return null;
};
BorshDeserializer2.prototype.decode_enum = function(schema) {
var _a;
var valueIndex = this.buffer.consume_value("u8");
if (valueIndex > schema["enum"].length) {
throw new Error("Enum option ".concat(valueIndex, " is not available"));
}
var struct = schema["enum"][valueIndex].struct;
var key = Object.keys(struct)[0];
return _a = {}, _a[key] = this.decode_value(struct[key]), _a;
};
BorshDeserializer2.prototype.decode_array = function(schema) {
var result = [];
var len = schema.array.len ? schema.array.len : this.decode_integer("u32");
for (var i = 0; i < len; ++i) {
result.push(this.decode_value(schema.array.type));
}
return result;
};
BorshDeserializer2.prototype.decode_set = function(schema) {
var len = this.decode_integer("u32");
var result = /* @__PURE__ */ new Set();
for (var i = 0; i < len; ++i) {
result.add(this.decode_value(schema.set));
}
return result;
};
BorshDeserializer2.prototype.decode_map = function(schema) {
var len = this.decode_integer("u32");
var result = /* @__PURE__ */ new Map();
for (var i = 0; i < len; ++i) {
var key = this.decode_value(schema.map.key);
var value = this.decode_value(schema.map.value);
result.set(key, value);
}
return result;
};
BorshDeserializer2.prototype.decode_struct = function(schema) {
var result = {};
for (var key in schema.struct) {
result[key] = this.decode_value(schema.struct[key]);
}
return result;
};
return BorshDeserializer2;
}()
);
exports2.BorshDeserializer = BorshDeserializer;
}
});
// node_modules/borsh/lib/cjs/index.js
var require_cjs = __commonJS({
"node_modules/borsh/lib/cjs/index.js"(exports2) {
"use strict";
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
if (k2 === void 0) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() {
return m[k];
} };
}
Object.defineProperty(o, k2, desc);
} : function(o, m, k, k2) {
if (k2 === void 0) k2 = k;
o[k2] = m[k];
});
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
} : function(o, v) {
o["default"] = v;
});
var __importStar = exports2 && exports2.__importStar || function(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) {
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
}
__setModuleDefault(result, mod);
return result;
};
exports2.__esModule = true;
exports2.deserialize = exports2.serialize = void 0;
var serialize_js_1 = require_serialize();
var deserialize_js_1 = require_deserialize();
var utils = __importStar(require_utils());
function serialize(schema, value, validate) {
if (validate === void 0) {
validate = true;
}
if (validate)
utils.validate_schema(schema);
var serializer = new serialize_js_1.BorshSerializer(validate);
return serializer.encode(value, schema);
}
exports2.serialize = serialize;
function deserialize(schema, buffer, validate) {
if (validate === void 0) {
validate = true;
}
if (validate)
utils.validate_schema(schema);
var deserializer = new deserialize_js_1.BorshDeserializer(buffer);
return deserializer.decode(schema);
}
exports2.deserialize = deserialize;
}
});
// node_modules/@near-js/utils/lib/commonjs/constants.cjs
var require_constants = __commonJS({
"node_modules/@near-js/utils/lib/commonjs/constants.cjs"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.DEFAULT_FUNCTION_CALL_GAS = void 0;
exports2.DEFAULT_FUNCTION_CALL_GAS = 30000000000000n;
}
});
// node_modules/@near-js/utils/lib/commonjs/errors/error_messages.json
var require_error_messages = __commonJS({
"node_modules/@near-js/utils/lib/commonjs/errors/error_messages.json"(exports2, module2) {
module2.exports = {
GasLimitExceeded: "Exceeded the maximum amount of gas allowed to burn per contract",
MethodEmptyName: "Method name is empty",
WasmerCompileError: "Wasmer compilation error: {{msg}}",
GuestPanic: "Smart contract panicked: {{panic_msg}}",
Memory: "Error creating Wasm memory",
GasExceeded: "Exceeded the prepaid gas",
MethodUTF8Error: "Method name is not valid UTF8 string",
BadUTF16: "String encoding is bad UTF-16 sequence",
WasmTrap: "WebAssembly trap: {{msg}}",
GasInstrumentation: "Gas instrumentation failed or contract has denied instructions.",
InvalidPromiseIndex: "{{promise_idx}} does not correspond to existing promises",
InvalidPromiseResultIndex: "Accessed invalid promise result index: {{result_idx}}",
Deserialization: "Error happened while deserializing the module",
MethodNotFound: "Contract method is not found",
InvalidRegisterId: "Accessed invalid register id: {{register_id}}",
InvalidReceiptIndex: "VM Logic returned an invalid receipt index: {{receipt_index}}",
EmptyMethodName: "Method name is empty in contract call",
CannotReturnJointPromise: "Returning joint promise is currently prohibited",
StackHeightInstrumentation: "Stack instrumentation failed",
CodeDoesNotExist: "Cannot find contract code for account {{account_id}}",
MethodInvalidSignature: "Invalid method signature",
IntegerOverflow: "Integer overflow happened during contract execution",
MemoryAccessViolation: "MemoryAccessViolation",
InvalidIteratorIndex: "Iterator index {{iterator_index}} does not exist",
IteratorWasInvalidated: "Iterator {{iterator_index}} was invalidated after its creation by performing a mutable operation on trie",
InvalidAccountId: "VM Logic returned an invalid account id",
Serialization: "Error happened while serializing the module",
CannotAppendActionToJointPromise: "Actions can only be appended to non-joint promise.",
InternalMemoryDeclared: "Internal memory declaration has been found in the module",
Instantiate: "Error happened during instantiation",
ProhibitedInView: "{{method_name}} is not allowed in view calls",
InvalidMethodName: "VM Logic returned an invalid method name",
BadUTF8: "String encoding is bad UTF-8 sequence",
BalanceExceeded: "Exceeded the account balance",
LinkError: "Wasm contract link error: {{msg}}",
InvalidPublicKey: "VM Logic provided an invalid public key",
ActorNoPermission: "Actor {{actor_id}} doesn't have permission to account {{account_id}} to complete the action",
LackBalanceForState: "The account {{account_id}} wouldn't have enough balance to cover storage, required to have {{amount}} yoctoNEAR more",
ReceiverMismatch: "Wrong AccessKey used for transaction: transaction is sent to receiver_id={{tx_receiver}}, but is signed with function call access key that restricted to only use with receiver_id={{ak_receiver}}. Either change receiver_id in your transaction or switch to use a FullAccessKey.",
CostOverflow: "Transaction gas or balance cost is too high",
InvalidSignature: "Transaction is not signed with the given public key",
AccessKeyNotFound: `Signer "{{account_id}}" doesn't have access key with the given public_key {{public_key}}`,
NotEnoughBalance: "Sender {{signer_id}} does not have enough balance {{#formatNear}}{{balance}}{{/formatNear}} for operation costing {{#formatNear}}{{cost}}{{/formatNear}}",
NotEnoughAllowance: "Access Key {account_id}:{public_key} does not have enough balance {{#formatNear}}{{allowance}}{{/formatNear}} for transaction costing {{#formatNear}}{{cost}}{{/formatNear}}",
Expired: "Transaction has expired",
DeleteAccountStaking: "Account {{account_id}} is staking and can not be deleted",
SignerDoesNotExist: "Signer {{signer_id}} does not exist",
TriesToStake: "Account {{account_id}} tried to stake {{#formatNear}}{{stake}}{{/formatNear}}, but has staked {{#formatNear}}{{locked}}{{/formatNear}} and only has {{#formatNear}}{{balance}}{{/formatNear}}",
AddKeyAlreadyExists: "The public key {{public_key}} is already used for an existing access key",
InvalidSigner: "Invalid signer account ID {{signer_id}} according to requirements",
CreateAccountNotAllowed: "The new account_id {{account_id}} can't be created by {{predecessor_id}}",
RequiresFullAccess: "The transaction contains more then one action, but it was signed with an access key which allows transaction to apply only one specific action. To apply more then one actions TX must be signed with a full access key",
TriesToUnstake: "Account {{account_id}} is not yet staked, but tried to unstake",
InvalidNonce: "Transaction nonce {{tx_nonce}} must be larger than nonce of the used access key {{ak_nonce}}",
AccountAlreadyExists: "Can't create a new account {{account_id}}, because it already exists",
InvalidChain: "Transaction parent block hash doesn't belong to the current chain",
AccountDoesNotExist: "Can't complete the action because account {{account_id}} doesn't exist",
AccessKeyDoesNotExist: "Can't complete the action because access key {{public_key}} doesn't exist",
MethodNameMismatch: "Transaction method name {{method_name}} isn't allowed by the access key",
DeleteAccountHasRent: "Account {{account_id}} can't be deleted. It has {{#formatNear}}{{balance}}{{/formatNear}}, which is enough to cover the rent",
DeleteAccountHasEnoughBalance: "Account {{account_id}} can't be deleted. It has {{#formatNear}}{{balance}}{{/formatNear}}, which is enough to cover it's storage",
InvalidReceiver: "Invalid receiver account ID {{receiver_id}} according to requirements",
DeleteKeyDoesNotExist: "Account {{account_id}} tries to remove an access key that doesn't exist",
Timeout: "Timeout exceeded",
Closed: "Connection closed",
ShardCongested: "Shard {{shard_id}} rejected the transaction due to congestion level {{congestion_level}}, try again later",
ShardStuck: "Shard {{shard_id}} rejected the transaction because it missed {{missed_chunks}} chunks and needs to recover before accepting new transactions, try again later"
};
}
});
// node_modules/@near-js/utils/lib/commonjs/errors/errors.cjs
var require_errors = __commonJS({
"node_modules/@near-js/utils/lib/commonjs/errors/errors.cjs"(exports2) {
"use strict";
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
return mod && mod.__esModule ? mod : { "default": mod };
};
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.ErrorMessages = void 0;
var error_messages_json_1 = __importDefault(require_error_messages());
exports2.ErrorMessages = error_messages_json_1.default;
}
});
// node_modules/@near-js/types/lib/commonjs/assignable.cjs
var require_assignable = __commonJS({
"node_modules/@near-js/types/lib/commonjs/assignable.cjs"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.Assignable = void 0;
var Assignable = class {
constructor(properties) {
Object.keys(properties).map((key) => {
this[key] = properties[key];
});
}
};
exports2.Assignable = Assignable;
}
});
// node_modules/@near-js/types/lib/commonjs/enum.cjs
var require_enum = __commonJS({
"node_modules/@near-js/types/lib/commonjs/enum.cjs"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.Enum = void 0;
var Enum = class {
constructor(properties) {
if (Object.keys(properties).length !== 1) {
throw new Error("Enum can only take single value");
}
Object.keys(properties).map((key) => {
this[key] = properties[key];
});
}
};
exports2.Enum = Enum;
}
});
// node_modules/@near-js/types/lib/commonjs/errors.cjs
var require_errors2 = __commonJS({
"node_modules/@near-js/types/lib/commonjs/errors.cjs"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.ErrorContext = exports2.TypedError = exports2.ArgumentTypeError = exports2.PositionalArgsError = void 0;
var PositionalArgsError = class extends Error {
constructor() {
super("Contract method calls expect named arguments wrapped in object, e.g. { argName1: argValue1, argName2: argValue2 }");
}
};
exports2.PositionalArgsError = PositionalArgsError;
var ArgumentTypeError = class extends Error {
constructor(argName, argType, argValue) {
super(`Expected ${argType} for '${argName}' argument, but got '${JSON.stringify(argValue)}'`);
}
};
exports2.ArgumentTypeError = ArgumentTypeError;
var TypedError = class extends Error {
constructor(message, type, context) {
super(message);
__publicField(this, "type");
__publicField(this, "context");
this.type = type || "UntypedError";
this.context = context;
}
};
exports2.TypedError = TypedError;
var ErrorContext = class {
constructor(transactionHash) {
__publicField(this, "transactionHash");
this.transactionHash = transactionHash;
}
};
exports2.ErrorContext = ErrorContext;
}
});
// node_modules/@near-js/types/lib/commonjs/provider/light_client.cjs
var require_light_client = __commonJS({
"node_modules/@near-js/types/lib/commonjs/provider/light_client.cjs"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.IdType = void 0;
var IdType;
(function(IdType2) {
IdType2["Transaction"] = "transaction";
IdType2["Receipt"] = "receipt";
})(IdType || (exports2.IdType = IdType = {}));
}
});
// node_modules/@near-js/types/lib/commonjs/provider/response.cjs
var require_response = __commonJS({
"node_modules/@near-js/types/lib/commonjs/provider/response.cjs"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.FinalExecutionStatusBasic = exports2.ExecutionStatusBasic = void 0;
var ExecutionStatusBasic;
(function(ExecutionStatusBasic2) {
ExecutionStatusBasic2["Unknown"] = "Unknown";
ExecutionStatusBasic2["Pending"] = "Pending";
ExecutionStatusBasic2["Failure"] = "Failure";
})(ExecutionStatusBasic || (exports2.ExecutionStatusBasic = ExecutionStatusBasic = {}));
var FinalExecutionStatusBasic;
(function(FinalExecutionStatusBasic2) {
FinalExecutionStatusBasic2["NotStarted"] = "NotStarted";
FinalExecutionStatusBasic2["Started"] = "Started";
FinalExecutionStatusBasic2["Failure"] = "Failure";
})(FinalExecutionStatusBasic || (exports2.FinalExecutionStatusBasic = FinalExecutionStatusBasic = {}));
}
});
// node_modules/@near-js/types/lib/commonjs/provider/index.cjs
var require_provider = __commonJS({
"node_modules/@near-js/types/lib/commonjs/provider/index.cjs"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.FinalExecutionStatusBasic = exports2.ExecutionStatusBasic = exports2.IdType = void 0;
var light_client_1 = require_light_client();
Object.defineProperty(exports2, "IdType", { enumerable: true, get: function() {
return light_client_1.IdType;
} });
var response_1 = require_response();
Object.defineProperty(exports2, "ExecutionStatusBasic", { enumerable: true, get: function() {
return response_1.ExecutionStatusBasic;
} });
Object.defineProperty(exports2, "FinalExecutionStatusBasic", { enumerable: true, get: function() {
return response_1.FinalExecutionStatusBasic;
} });
}
});
// node_modules/@near-js/types/lib/commonjs/index.cjs
var require_commonjs = __commonJS({
"node_modules/@near-js/types/lib/commonjs/index.cjs"(exports2) {
"use strict";
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
if (k2 === void 0) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() {
return m[k];
} };
}
Object.defineProperty(o, k2, desc);
} : function(o, m, k, k2) {
if (k2 === void 0) k2 = k;
o[k2] = m[k];
});
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
};
Object.defineProperty(exports2, "__esModule", { value: true });
__exportStar(require_assignable(), exports2);
__exportStar(require_enum(), exports2);
__exportStar(require_errors2(), exports2);
__exportStar(require_provider(), exports2);
}
});
// node_modules/mustache/mustache.js
var require_mustache = __commonJS({
"node_modules/mustache/mustache.js"(exports2, module2) {
(function(global2, factory) {
typeof exports2 === "object" && typeof module2 !== "undefined" ? module2.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global2 = global2 || self, global2.Mustache = factory());
})(exports2, function() {
"use strict";
var objectToString = Object.prototype.toString;
var isArray = Array.isArray || function isArrayPolyfill(object) {
return objectToString.call(object) === "[object Array]";
};
function isFunction(object) {
return typeof object === "function";
}
function typeStr(obj) {
return isArray(obj) ? "array" : typeof obj;
}
function escapeRegExp(string) {
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
}
function hasProperty(obj, propName) {
return obj != null && typeof obj === "object" && propName in obj;
}
function primitiveHasOwnProperty(primitive, propName) {
return primitive != null && typeof primitive !== "object" && primitive.hasOwnProperty && primitive.hasOwnProperty(propName);
}
var regExpTest = RegExp.prototype.test;
function testRegExp(re, string) {
return regExpTest.call(re, string);
}
var nonSpaceRe = /\S/;
function isWhitespace(string) {
return !testRegExp(nonSpaceRe, string);
}
var entityMap = {
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
"/": "/",
"`": "`",
"=": "="
};
function escapeHtml(string) {
return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap(s) {
return entityMap[s];
});
}
var whiteRe = /\s*/;
var spaceRe = /\s+/;
var equalsRe = /\s*=/;
var curlyRe = /\s*\}/;
var tagRe = /#|\^|\/|>|\{|&|=|!/;
function parseTemplate(template, tags) {
if (!template)
return [];
var lineHasNonSpace = false;
var sections = [];
var tokens = [];
var spaces = [];
var hasTag = false;
var nonSpace = false;
var indentation = "";
var tagIndex = 0;
function stripSpace() {
if (hasTag && !nonSpace) {
while (spaces.length)
delete tokens[spaces.pop()];
} else {
spaces = [];
}
hasTag = false;
nonSpace = false;
}
var openingTagRe, closingTagRe, closingCurlyRe;
function compileTags(tagsToCompile) {
if (typeof tagsToCompile === "string")
tagsToCompile = tagsToCompile.split(spaceRe, 2);
if (!isArray(tagsToCompile) || tagsToCompile.length !== 2)
throw new Error("Invalid tags: " + tagsToCompile);
openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + "\\s*");
closingTagRe = new RegExp("\\s*" + escapeRegExp(tagsToCompile[1]));
closingCurlyRe = new RegExp("\\s*" + escapeRegExp("}" + tagsToCompile[1]));
}
compileTags(tags || mustache.tags);
var scanner = new Scanner(template);
var start, type, value, chr, token, openSection;
while (!scanner.eos()) {
start = scanner.pos;
value = scanner.scanUntil(openingTagRe);
if (value) {
for (var i = 0, valueLength = value.length; i < valueLength; ++i) {
chr = value.charAt(i);
if (isWhitespace(chr)) {
spaces.push(tokens.length);
indentation += chr;
} else {
nonSpace = true;
lineHasNonSpace = true;
indentation += " ";
}
tokens.push(["text", chr, start, start + 1]);
start += 1;
if (chr === "\n") {
stripSpace();
indentation = "";
tagIndex = 0;
lineHasNonSpace = false;
}
}
}
if (!scanner.scan(openingTagRe))
break;
hasTag = true;
type = scanner.scan(tagRe) || "name";
scanner.scan(whiteRe);
if (type === "=") {
value = scanner.scanUntil(equalsRe);
scanner.scan(equalsRe);
scanner.scanUntil(closingTagRe);
} else if (type === "{") {
value = scanner.scanUntil(closingCurlyRe);
scanner.scan(curlyRe);
scanner.scanUntil(closingTagRe);
type = "&";
} else {
value = scanner.scanUntil(closingTagRe);
}
if (!scanner.scan(closingTagRe))
throw new Error("Unclosed tag at " + scanner.pos);
if (type == ">") {
token = [type, value, start, scanner.pos, indentation, tagIndex, lineHasNonSpace];
} else {
token = [type, value, start, scanner.pos];
}
tagIndex++;
tokens.push(token);
if (type === "#" || type === "^") {
sections.push(token);
} else if (type === "/") {
openSection = sections.pop();
if (!openSection)
throw new Error('Unopened section "' + value + '" at ' + start);
if (openSection[1] !== value)
throw new Error('Unclosed section "' + openSection[1] + '" at ' + start);
} else if (type === "name" || type === "{" || type === "&") {
nonSpace = true;
} else if (type === "=") {
compileTags(value);
}
}
stripSpace();
openSection = sections.pop();
if (openSection)
throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
return nestTokens(squashTokens(tokens));
}
function squashTokens(tokens) {
var squashedTokens = [];
var token, lastToken;
for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
token = tokens[i];
if (token) {
if (token[0] === "text" && lastToken && lastToken[0] === "text") {
lastToken[1] += token[1];
lastToken[3] = token[3];
} else {
squashedTokens.push(token);
lastToken = token;
}
}
}
return squashedTokens;
}
function nestTokens(tokens) {
var nestedTokens = [];
var collector = nestedTokens;
var sections = [];
var token, section;
for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
token = tokens[i];
switch (token[0]) {
case "#":
case "^":
collector.push(token);
sections.push(token);
collector = token[4] = [];
break;
case "/":
section = sections.pop();
section[5] = token[2];
collector = sections.length > 0 ? sections[sections.length - 1][4] : nestedTokens;
break;
default:
collector.push(token);
}
}
return nestedTokens;
}
function Scanner(string) {
this.string = string;
this.tail = string;
this.pos = 0;
}
Scanner.prototype.eos = function eos() {
return this.tail === "";
};
Scanner.prototype.scan = function scan(re) {
var match = this.tail.match(re);
if (!match || match.index !== 0)
return "";
var string = match[0];
this.tail = this.tail.substring(string.length);
this.pos += string.length;
return string;
};
Scanner.prototype.scanUntil = function scanUntil(re) {
var index = this.tail.search(re), match;
switch (index) {
case -1:
match = this.tail;
this.tail = "";
break;
case 0:
match = "";
break;
default:
match = this.tail.substring(0, index);
this.tail = this.tail.substring(index);
}
this.pos += match.length;
return match;
};
function Context(view, parentContext) {
this.view = view;
this.cache = { ".": this.view };
this.parent = parentContext;
}
Context.prototype.push = function push(view) {
return new Context(view, this);
};
Context.prototype.lookup = function lookup(name) {
var cache = this.cache;
var value;
if (cache.hasOwnProperty(name)) {
value = cache[name];
} else {
var context = this, intermediateValue, names, index, lookupHit = false;
while (context) {
if (name.indexOf(".") > 0) {
intermediateValue = context.view;
names = name.split(".");
index = 0;
while (intermediateValue != null && index < names.length) {
if (index === names.length - 1)
lookupHit = hasProperty(intermediateValue, names[index]) || primitiveHasOwnProperty(intermed