UNPKG

@moralisweb3/common-aptos-utils

Version:

1,290 lines (1,255 loc) 285 kB
import { CoreError, CoreErrorCode, BigNumber, CoreProvider, Module } from '@moralisweb3/common-core'; var CommonAptosUtilsConfig = { defaultAptosNetwork: { name: 'defaultAptosNetwork', defaultValue: 'mainnet', }, }; var CommonAptosUtilsConfigSetup = /** @class */ (function () { function CommonAptosUtilsConfigSetup() { } CommonAptosUtilsConfigSetup.register = function (config) { config.registerKey(CommonAptosUtilsConfig.defaultAptosNetwork); }; return CommonAptosUtilsConfigSetup; }()); /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44; // There is almost no big endian hardware, but js typed arrays uses platform specific endianness. // So, just to be sure not to corrupt anything. if (!isLE) throw new Error('Non little-endian hardware is not supported'); const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0')); /** * @example bytesToHex(Uint8Array.from([0xde, 0xad, 0xbe, 0xef])) */ function bytesToHex(uint8a) { // pre-caching improves the speed 6x if (!(uint8a instanceof Uint8Array)) throw new Error('Uint8Array expected'); let hex = ''; for (let i = 0; i < uint8a.length; i++) { hex += hexes[uint8a[i]]; } return hex; } /** * @example hexToBytes('deadbeef') */ function hexToBytes(hex) { if (typeof hex !== 'string') { throw new TypeError('hexToBytes: expected string, got ' + typeof hex); } if (hex.length % 2) throw new Error('hexToBytes: received invalid unpadded hex'); const array = new Uint8Array(hex.length / 2); for (let i = 0; i < array.length; i++) { const j = i * 2; const hexByte = hex.slice(j, j + 2); const byte = Number.parseInt(hexByte, 16); if (Number.isNaN(byte) || byte < 0) throw new Error('Invalid byte sequence'); array[i] = byte; } return array; } /** * Copied (and remove obsolete functionalities) from https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/hex_string.ts because * - We only care about address validation and conversion, this is a dependency for AccountAddress * - Resolving this dependency in UMD gives dependency errors */ /** * A util class for working with hex strings. * Hex strings are strings that are prefixed with `0x` */ var HexString = /** @class */ (function () { /** * Creates new HexString instance from regular string. If specified string already starts with "0x" prefix, * it will not add another one * @param hexString String to convert * @example * ``` * const string = "string"; * new HexString(string); // "0xstring" * ``` */ function HexString(hexString) { if (hexString.startsWith('0x')) { this.hexString = hexString; } else { this.hexString = "0x".concat(hexString); } } /** * Creates new hex string from Buffer * @param buffer A buffer to convert * @returns New HexString */ HexString.fromBuffer = function (buffer) { return HexString.fromUint8Array(buffer); }; /** * Creates new hex string from Uint8Array * @param arr Uint8Array to convert * @returns New HexString */ HexString.fromUint8Array = function (arr) { return new HexString(bytesToHex(arr)); }; /** * Ensures `hexString` is instance of `HexString` class * @param hexString String to check * @returns New HexString if `hexString` is regular string or `hexString` if it is HexString instance * @example * ``` * const regularString = "string"; * const hexString = new HexString("string"); // "0xstring" * HexString.ensure(regularString); // "0xstring" * HexString.ensure(hexString); // "0xstring" * ``` */ HexString.ensure = function (hexString) { if (typeof hexString === 'string') { return new HexString(hexString); } return hexString; }; /** * Getter for inner hexString * @returns Inner hex string */ HexString.prototype.hex = function () { return this.hexString; }; /** * Getter for inner hexString without prefix * @returns Inner hex string without prefix * @example * ``` * const hexString = new HexString("string"); // "0xstring" * hexString.noPrefix(); // "string" * ``` */ HexString.prototype.noPrefix = function () { return this.hexString.slice(2); }; /** * Overrides default `toString` method * @returns Inner hex string */ HexString.prototype.toString = function () { return this.hex(); }; /** * Trimmes extra zeroes in the begining of a string * @returns Inner hexString without leading zeroes * @example * ``` * new HexString("0x000000string").toShortString(); // result = "0xstring" * ``` */ HexString.prototype.toShortString = function () { var trimmed = this.hexString.replace(/^0x0*/, ''); return "0x".concat(trimmed); }; /** * Converts hex string to a Uint8Array * @returns Uint8Array from inner hexString without prefix */ HexString.prototype.toUint8Array = function () { return Uint8Array.from(hexToBytes(this.noPrefix())); }; return HexString; }()); /** * Copied (and remove obsolete functionalities) from https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/aptos_types/account_address.ts because * - We only care about address validation and conversion * - Resolving this dependency in UMD gives dependency errors */ var AccountAddress = /** @class */ (function () { function AccountAddress(address) { if (address.length !== AccountAddress.LENGTH) { throw new Error('Expected address of length 32'); } this.address = address; } /** * Creates AccountAddress from a hex string. * @param addr Hex string can be with a prefix or without a prefix, * e.g. '0x1aa' or '1aa'. Hex string will be left padded with 0s if too short. */ AccountAddress.fromHex = function (addr) { var address = HexString.ensure(addr); // If an address hex has odd number of digits, padd the hex string with 0 // e.g. '1aa' would become '01aa'. if (address.noPrefix().length % 2 !== 0) { address = new HexString("0".concat(address.noPrefix())); } var addressBytes = address.toUint8Array(); if (addressBytes.length > AccountAddress.LENGTH) { // eslint-disable-next-line quotes throw new Error("Hex string is too long. Address's length is 32 bytes."); } else if (addressBytes.length === AccountAddress.LENGTH) { return new AccountAddress(addressBytes); } var res = new Uint8Array(AccountAddress.LENGTH); res.set(addressBytes, AccountAddress.LENGTH - addressBytes.length); return new AccountAddress(res); }; /** * Checks if the string is a valid AccountAddress * @param addr Hex string can be with a prefix or without a prefix, * e.g. '0x1aa' or '1aa'. Hex string will be left padded with 0s if too short. */ AccountAddress.isValid = function (addr) { // At least one zero is required if (addr === '') { return false; } var address = HexString.ensure(addr); // If an address hex has odd number of digits, padd the hex string with 0 // e.g. '1aa' would become '01aa'. if (address.noPrefix().length % 2 !== 0) { address = new HexString("0".concat(address.noPrefix())); } var addressBytes = address.toUint8Array(); return addressBytes.length <= AccountAddress.LENGTH; }; AccountAddress.LENGTH = 32; AccountAddress.CORE_CODE_ADDRESS = AccountAddress.fromHex('0x1'); return AccountAddress; }()); /** * A representation of an address on the Aptos network. * * Use this class any time you work with an address. * * @category DataType */ var AptosAddress = /** @class */ (function () { function AptosAddress(address) { this.address = address; } /** * Create a new instance of AptosAddress from any valid address input. * * @example `const address = AptosAddress.create("0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90")` * @throws an error when a passed address is invalid. */ AptosAddress.create = function (address) { if (address instanceof AptosAddress) { return address; } return new AptosAddress(AptosAddress.parse(address)); }; AptosAddress.fromJSON = function (json) { return AptosAddress.create(json); }; AptosAddress.parse = function (address) { try { if (!AccountAddress.isValid(address)) { throw new Error('Address is invalid'); } } catch (e) { throw new CoreError({ code: CoreErrorCode.INVALID_ARGUMENT, message: "Invalid address provided: ".concat(address), cause: e, }); } if (address.startsWith('0x')) { address = address.substring(2); } var addr = address.padStart(64, '0'); return "0x".concat(addr); }; /** * @deprecated This method will be removed soon. To format the value, use one of the properties. */ AptosAddress.prototype.format = function () { return this.address; }; /** * Check the equality between two Aptos addresses * @example `AptosAddress.equals("0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90", "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90")` */ AptosAddress.equals = function (addressA, addressB) { return AptosAddress.create(addressA).equals(addressB); }; /** * Checks the equality of the current address with another Aptos address. * @example `address.equals("0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90")` * @example `address.equals(AptosAddress.create("0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90"))` */ AptosAddress.prototype.equals = function (address) { return this.address === AptosAddress.create(address).address; }; /** * @returns a string representing the address. * @example address.toString(); // "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90" */ AptosAddress.prototype.toString = function () { return this.address; }; /** * @returns a string representing the address. * @example address.toJSON(); // "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90" */ AptosAddress.prototype.toJSON = function () { return this.address; }; Object.defineProperty(AptosAddress.prototype, "short", { /** * @returns a string representing the address, the leading zeros are removed from the address. * @example address.short; // "0x1" */ get: function () { var address = this.address.substring(2).replace(/^0+/, ''); return "0x".concat(address); }, enumerable: false, configurable: true }); return AptosAddress; }()); var aptosNetworkNames = ['mainnet', 'testnet', 'devnet']; var aptosChainIdToNetworkNames = { '1': 'mainnet', '2': 'testnet', }; /** * A representation of a Aptos network. * * @category DataType */ var AptosNetwork = /** @class */ (function () { function AptosNetwork(network) { this.network = network; } Object.defineProperty(AptosNetwork, "MAINNET", { /** * Returns MAINNET network * * @example AptosNetwork.MAINNET */ get: function () { return AptosNetwork.create('mainnet'); }, enumerable: false, configurable: true }); Object.defineProperty(AptosNetwork, "TESTNET", { /** * Returns TESTNET network * * @example AptosNetwork.MAINNET */ get: function () { return AptosNetwork.create('testnet'); }, enumerable: false, configurable: true }); Object.defineProperty(AptosNetwork, "DEVNET", { /** * Returns DEVNET network * * @example AptosNetwork.MAINNET */ get: function () { return AptosNetwork.create('devnet'); }, enumerable: false, configurable: true }); /** * Create a new instance of AptosNetwork from any valid network input. * * @example `const network = AptosNetwork.create("mainnet")` * @throws an error when a passed network is invalid. */ AptosNetwork.create = function (network) { return network instanceof AptosNetwork ? network : new AptosNetwork(AptosNetwork.parse(network)); }; AptosNetwork.parse = function (network) { var _a; if (typeof network !== 'string') { throw new CoreError({ code: CoreErrorCode.INVALID_ARGUMENT, message: "Aptos network is not supported: ".concat(network), }); } var networkName = (_a = aptosChainIdToNetworkNames[network]) !== null && _a !== void 0 ? _a : network; if (!aptosNetworkNames.includes(networkName)) { throw new CoreError({ code: CoreErrorCode.INVALID_ARGUMENT, message: "Aptos network is not supported: ".concat(network), }); } return networkName; }; /** * @deprecated This method will be removed soon. To format the value, use one of the properties. */ AptosNetwork.prototype.format = function () { return this.network; }; /** * Checks the equality of the current network with another Aptos network. * @example `network.equals("mainnet")` * @example `network.equals(AptosNetwork.create("mainnet"))` */ AptosNetwork.prototype.equals = function (network) { return this.network === AptosNetwork.create(network).network; }; /** * @returns a string representing the network. * @example network.toJSON(); // "mainnet" */ AptosNetwork.prototype.toJSON = function () { return this.network; }; /** * @returns a string representing the network. * @example network.toString(); // "mainnet" */ AptosNetwork.prototype.toString = function () { return this.network; }; return AptosNetwork; }()); var unitToDecimals = { aptos: 8, octas: 0, }; /** * The AptosNative class is a MoralisData that references to the value of Aptos native currency APT * * @category DataType */ var AptosNative = /** @class */ (function () { function AptosNative(rawValue) { this.rawValue = rawValue; } /** * Create a new instance of AptosNative from any valid {@link AptosNativeInput} value. * @param value - the value to create the AptosNative from * @param unit - the unit of the value (optional), defaults to `aptos` * @returns a new instance of AptosNative * @example * ```ts * const native = AptosNative.create(2, 'octas'); * const native = AptosNative.create(2); *``` */ AptosNative.create = function (value, unit) { if (value instanceof AptosNative) { return value; } return new AptosNative(AptosNative.parse(value, unit)); }; AptosNative.fromJSON = function (json) { return AptosNative.create(json, 'octas'); }; AptosNative.parse = function (value, unit) { if (unit === void 0) { unit = 'aptos'; } var decimal; if (typeof unit === 'number') { decimal = unit; } else if (unitToDecimals[unit] !== undefined) { decimal = unitToDecimals[unit]; } else { throw new CoreError({ code: CoreErrorCode.INVALID_ARGUMENT, message: "Not supported Aptos unit: ".concat(unit), }); } return BigNumber.fromDecimal(value.toString(), decimal); }; /** * Compares two AptosNativeish values. * @param valueA - the first value to compare * @param valueB - the second value to compare * @returns true if the values are equal * @example * ```ts * AptosNative.equals(AptosNative.create(1), AptosNative.create(1)); // true * ``` */ AptosNative.equals = function (valueA, valueB) { var aptosNativeA = AptosNative.create(valueA); var aptosNativeB = AptosNative.create(valueB); return aptosNativeA.octas === aptosNativeB.octas; }; /** * Compares AptosNative with current instance. * @param value - the value to compare with * @returns true if the values are equal * @example * ```ts * const native = AptosNative.create(2, 'octas'); * native.equals(AptosNative.create(1)); // false * ``` */ AptosNative.prototype.equals = function (value) { return AptosNative.equals(this, value); }; /** * @deprecated This method will be removed soon. To format the value, use one of the properties. */ AptosNative.prototype.format = function () { return this.octas; }; /** * Converts the AptosNative to a string. * @returns the value of the AptosNative as a string * @example `native.toJSON()` */ AptosNative.prototype.toJSON = function () { return this.octas; }; /** * Converts the AptosNative to a string. * @returns the value of the AptosNative as a string * @example `native.toString()` */ AptosNative.prototype.toString = function () { return this.octas; }; Object.defineProperty(AptosNative.prototype, "value", { /** * @returns the value of the AptosNative as a BigNumber * @example `native.value` */ get: function () { return this.rawValue; }, enumerable: false, configurable: true }); Object.defineProperty(AptosNative.prototype, "aptos", { /** * Converts the AptosNative to an aptos unit. * @returns the value of the AptosNative as an aptos string * @example `native.aptos` */ get: function () { return this.rawValue.toDecimal(unitToDecimals['aptos']); }, enumerable: false, configurable: true }); Object.defineProperty(AptosNative.prototype, "octas", { /** * Converts the AptosNative to a string. * @returns the value of the AptosNative as a string * @example `native.lamports` */ get: function () { return this.rawValue.toString(); }, enumerable: false, configurable: true }); return AptosNative; }()); var AptosNetworkResolver = /** @class */ (function () { function AptosNetworkResolver() { } AptosNetworkResolver.resolve = function (network, core) { if (!network) { network = core.config.get(CommonAptosUtilsConfig.defaultAptosNetwork); } return AptosNetwork.create(network).network; }; return AptosNetworkResolver; }()); /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(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 __()); } var CommonAptosUtils = /** @class */ (function (_super) { __extends(CommonAptosUtils, _super); function CommonAptosUtils(core) { return _super.call(this, CommonAptosUtils.moduleName, core) || this; } CommonAptosUtils.create = function (core) { return new CommonAptosUtils(core !== null && core !== void 0 ? core : CoreProvider.getDefault()); }; CommonAptosUtils.prototype.setup = function () { CommonAptosUtilsConfigSetup.register(this.core.config); }; CommonAptosUtils.prototype.start = function () { // Nothing }; Object.defineProperty(CommonAptosUtils.prototype, "AptosAddress", { get: function () { return AptosAddress; }, enumerable: false, configurable: true }); Object.defineProperty(CommonAptosUtils.prototype, "AptosNative", { get: function () { return AptosNative; }, enumerable: false, configurable: true }); Object.defineProperty(CommonAptosUtils.prototype, "AptosNetwork", { get: function () { return AptosNetwork; }, enumerable: false, configurable: true }); CommonAptosUtils.moduleName = 'aptosUtils'; return CommonAptosUtils; }(Module)); // $ref: #/components/schemas/NFTTokenResponse/properties/default_properties // typeName: NFTTokenResponse_default_properties var AptosNFTTokenResponseDefaultProperties = /** @class */ (function () { function AptosNFTTokenResponseDefaultProperties() { } AptosNFTTokenResponseDefaultProperties.create = function (input) { return input; }; AptosNFTTokenResponseDefaultProperties.fromJSON = function (json) { return json; }; return AptosNFTTokenResponseDefaultProperties; }()); var AptosNFTTokenResponse = /** @class */ (function () { function AptosNFTTokenResponse(input) { this.collectionDataIdHash = input.collectionDataIdHash; this.collectionName = input.collectionName; this.creatorAddress = AptosAddress.create(input.creatorAddress); this.defaultProperties = AptosNFTTokenResponseDefaultProperties.create(input.defaultProperties); this.description = input.description; this.descriptionMutable = input.descriptionMutable; this.largestPropertyVersion = input.largestPropertyVersion; this.lastTransactionTimestamp = input.lastTransactionTimestamp; this.lastTransactionVersion = input.lastTransactionVersion; this.maximum = input.maximum; this.maximumMutable = input.maximumMutable; this.metadataUri = input.metadataUri; this.name = input.name; this.payeeAddress = AptosAddress.create(input.payeeAddress); this.propertiesMutable = input.propertiesMutable; this.royaltyMutable = input.royaltyMutable; this.royaltyPointsDenominator = input.royaltyPointsDenominator; this.royaltyPointsNumerator = input.royaltyPointsNumerator; this.supply = input.supply; this.tokenDataIdHash = input.tokenDataIdHash; this.uriMutable = input.uriMutable; } AptosNFTTokenResponse.create = function (input) { if (input instanceof AptosNFTTokenResponse) { return input; } return new AptosNFTTokenResponse(input); }; AptosNFTTokenResponse.fromJSON = function (json) { var input = { collectionDataIdHash: json.collection_data_id_hash, collectionName: json.collection_name, creatorAddress: AptosAddress.fromJSON(json.creator_address), defaultProperties: AptosNFTTokenResponseDefaultProperties.fromJSON(json.default_properties), description: json.description, descriptionMutable: json.description_mutable, largestPropertyVersion: json.largest_property_version, lastTransactionTimestamp: json.last_transaction_timestamp, lastTransactionVersion: json.last_transaction_version, maximum: json.maximum, maximumMutable: json.maximum_mutable, metadataUri: json.metadata_uri, name: json.name, payeeAddress: AptosAddress.fromJSON(json.payee_address), propertiesMutable: json.properties_mutable, royaltyMutable: json.royalty_mutable, royaltyPointsDenominator: json.royalty_points_denominator, royaltyPointsNumerator: json.royalty_points_numerator, supply: json.supply, tokenDataIdHash: json.token_data_id_hash, uriMutable: json.uri_mutable, }; return AptosNFTTokenResponse.create(input); }; AptosNFTTokenResponse.prototype.toJSON = function () { return { collection_data_id_hash: this.collectionDataIdHash, collection_name: this.collectionName, creator_address: this.creatorAddress.toJSON(), default_properties: this.defaultProperties, description: this.description, description_mutable: this.descriptionMutable, largest_property_version: this.largestPropertyVersion, last_transaction_timestamp: this.lastTransactionTimestamp, last_transaction_version: this.lastTransactionVersion, maximum: this.maximum, maximum_mutable: this.maximumMutable, metadata_uri: this.metadataUri, name: this.name, payee_address: this.payeeAddress.toJSON(), properties_mutable: this.propertiesMutable, royalty_mutable: this.royaltyMutable, royalty_points_denominator: this.royaltyPointsDenominator, royalty_points_numerator: this.royaltyPointsNumerator, supply: this.supply, token_data_id_hash: this.tokenDataIdHash, uri_mutable: this.uriMutable, }; }; return AptosNFTTokenResponse; }()); var GetNFTsByIdsOperation = { operationId: "getNFTsByIds", groupName: "nfts", httpMethod: "get", routePattern: "/nfts", parameterNames: ["token_ids", "network"], hasResponse: true, hasBody: false, parseResponse: function (json) { return json.map(function (item) { return AptosNFTTokenResponse.fromJSON(item); }); }, serializeRequest: function (request) { var tokenIds = request.tokenIds; var network = request.network ? AptosNetwork.create(request.network) : undefined; return { token_ids: tokenIds, network: network ? network.toJSON() : undefined, }; }, }; var AptosNFTTokensByCollectionResponse = /** @class */ (function () { function AptosNFTTokensByCollectionResponse(input) { this.cursor = input.cursor; this.hasNextPage = input.hasNextPage; this.result = input.result.map(function (item) { return AptosNFTTokenResponse.create(item); }); } AptosNFTTokensByCollectionResponse.create = function (input) { if (input instanceof AptosNFTTokensByCollectionResponse) { return input; } return new AptosNFTTokensByCollectionResponse(input); }; AptosNFTTokensByCollectionResponse.fromJSON = function (json) { var input = { cursor: json.cursor, hasNextPage: json.hasNextPage, result: json.result.map(function (item) { return AptosNFTTokenResponse.fromJSON(item); }), }; return AptosNFTTokensByCollectionResponse.create(input); }; AptosNFTTokensByCollectionResponse.prototype.toJSON = function () { return { cursor: this.cursor, hasNextPage: this.hasNextPage, result: this.result.map(function (item) { return item.toJSON(); }), }; }; return AptosNFTTokensByCollectionResponse; }()); var GetNFTsByCollectionOperation = { operationId: "getNFTsByCollection", groupName: "nfts", httpMethod: "get", routePattern: "/nfts/collections/{collection_data_id_hash}/tokens", parameterNames: ["collection_data_id_hash", "limit", "offset", "cursor", "network"], hasResponse: true, hasBody: false, parseResponse: function (json) { return AptosNFTTokensByCollectionResponse.fromJSON(json); }, serializeRequest: function (request) { var collectionDataIdHash = request.collectionDataIdHash; var limit = request.limit; var offset = request.offset; var cursor = request.cursor; var network = request.network ? AptosNetwork.create(request.network) : undefined; return { collection_data_id_hash: collectionDataIdHash, limit: limit, offset: offset, cursor: cursor, network: network ? network.toJSON() : undefined, }; }, }; var AptosNFTTokensByCreatorsResponse = /** @class */ (function () { function AptosNFTTokensByCreatorsResponse(input) { this.cursor = input.cursor; this.hasNextPage = input.hasNextPage; this.result = input.result.map(function (item) { return AptosNFTTokenResponse.create(item); }); } AptosNFTTokensByCreatorsResponse.create = function (input) { if (input instanceof AptosNFTTokensByCreatorsResponse) { return input; } return new AptosNFTTokensByCreatorsResponse(input); }; AptosNFTTokensByCreatorsResponse.fromJSON = function (json) { var input = { cursor: json.cursor, hasNextPage: json.hasNextPage, result: json.result.map(function (item) { return AptosNFTTokenResponse.fromJSON(item); }), }; return AptosNFTTokensByCreatorsResponse.create(input); }; AptosNFTTokensByCreatorsResponse.prototype.toJSON = function () { return { cursor: this.cursor, hasNextPage: this.hasNextPage, result: this.result.map(function (item) { return item.toJSON(); }), }; }; return AptosNFTTokensByCreatorsResponse; }()); var GetNFTsByCreatorsOperation = { operationId: "getNFTsByCreators", groupName: "nfts", httpMethod: "get", routePattern: "/nfts/creators", parameterNames: ["limit", "offset", "cursor", "creator_addresses", "network"], hasResponse: true, hasBody: false, parseResponse: function (json) { return AptosNFTTokensByCreatorsResponse.fromJSON(json); }, serializeRequest: function (request) { var limit = request.limit; var offset = request.offset; var cursor = request.cursor; var creatorAddresses = request.creatorAddresses.map(function (item) { return AptosAddress.create(item); }); var network = request.network ? AptosNetwork.create(request.network) : undefined; return { limit: limit, offset: offset, cursor: cursor, creator_addresses: creatorAddresses.map(function (item) { return item.toJSON(); }), network: network ? network.toJSON() : undefined, }; }, }; var AptosNFTCollectionItemResponse = /** @class */ (function () { function AptosNFTCollectionItemResponse(input) { this.collectionDataIdHash = input.collectionDataIdHash; this.collectionName = input.collectionName; this.creatorAddress = AptosAddress.create(input.creatorAddress); this.description = input.description; this.descriptionMutable = input.descriptionMutable; this.lastTransactionTimestamp = input.lastTransactionTimestamp; this.lastTransactionVersion = input.lastTransactionVersion; this.maximum = input.maximum; this.maximumMutable = input.maximumMutable; this.metadataUri = input.metadataUri; this.supply = input.supply; this.tableHandle = input.tableHandle; this.uriMutable = input.uriMutable; } AptosNFTCollectionItemResponse.create = function (input) { if (input instanceof AptosNFTCollectionItemResponse) { return input; } return new AptosNFTCollectionItemResponse(input); }; AptosNFTCollectionItemResponse.fromJSON = function (json) { var input = { collectionDataIdHash: json.collection_data_id_hash, collectionName: json.collection_name, creatorAddress: AptosAddress.fromJSON(json.creator_address), description: json.description, descriptionMutable: json.description_mutable, lastTransactionTimestamp: json.last_transaction_timestamp, lastTransactionVersion: json.last_transaction_version, maximum: json.maximum, maximumMutable: json.maximum_mutable, metadataUri: json.metadata_uri, supply: json.supply, tableHandle: json.table_handle, uriMutable: json.uri_mutable, }; return AptosNFTCollectionItemResponse.create(input); }; AptosNFTCollectionItemResponse.prototype.toJSON = function () { return { collection_data_id_hash: this.collectionDataIdHash, collection_name: this.collectionName, creator_address: this.creatorAddress.toJSON(), description: this.description, description_mutable: this.descriptionMutable, last_transaction_timestamp: this.lastTransactionTimestamp, last_transaction_version: this.lastTransactionVersion, maximum: this.maximum, maximum_mutable: this.maximumMutable, metadata_uri: this.metadataUri, supply: this.supply, table_handle: this.tableHandle, uri_mutable: this.uriMutable, }; }; return AptosNFTCollectionItemResponse; }()); var AptosNFTCollectionsByNameRangeResponse = /** @class */ (function () { function AptosNFTCollectionsByNameRangeResponse(input) { this.cursor = input.cursor; this.hasNextPage = input.hasNextPage; this.result = input.result.map(function (item) { return AptosNFTCollectionItemResponse.create(item); }); } AptosNFTCollectionsByNameRangeResponse.create = function (input) { if (input instanceof AptosNFTCollectionsByNameRangeResponse) { return input; } return new AptosNFTCollectionsByNameRangeResponse(input); }; AptosNFTCollectionsByNameRangeResponse.fromJSON = function (json) { var input = { cursor: json.cursor, hasNextPage: json.hasNextPage, result: json.result.map(function (item) { return AptosNFTCollectionItemResponse.fromJSON(item); }), }; return AptosNFTCollectionsByNameRangeResponse.create(input); }; AptosNFTCollectionsByNameRangeResponse.prototype.toJSON = function () { return { cursor: this.cursor, hasNextPage: this.hasNextPage, result: this.result.map(function (item) { return item.toJSON(); }), }; }; return AptosNFTCollectionsByNameRangeResponse; }()); var GetNFTCollectionsOperation = { operationId: "getNFTCollections", groupName: "collections", httpMethod: "get", routePattern: "/collections", parameterNames: ["limit", "offset", "cursor", "fromName", "toName", "network"], hasResponse: true, hasBody: false, parseResponse: function (json) { return AptosNFTCollectionsByNameRangeResponse.fromJSON(json); }, serializeRequest: function (request) { var limit = request.limit; var offset = request.offset; var cursor = request.cursor; var fromName = request.fromName; var toName = request.toName; var network = request.network ? AptosNetwork.create(request.network) : undefined; return { limit: limit, offset: offset, cursor: cursor, fromName: fromName, toName: toName, network: network ? network.toJSON() : undefined, }; }, }; var GetNFTCollectionsByIdsOperation = { operationId: "getNFTCollectionsByIds", groupName: "collections", httpMethod: "get", routePattern: "/collections/ids", parameterNames: ["ids", "network"], hasResponse: true, hasBody: false, parseResponse: function (json) { return json.map(function (item) { return AptosNFTCollectionItemResponse.fromJSON(item); }); }, serializeRequest: function (request) { var ids = request.ids; var network = request.network ? AptosNetwork.create(request.network) : undefined; return { ids: ids, network: network ? network.toJSON() : undefined, }; }, }; var AptosNFTCollectionsByCreatorResponse = /** @class */ (function () { function AptosNFTCollectionsByCreatorResponse(input) { this.cursor = input.cursor; this.hasNextPage = input.hasNextPage; this.result = input.result.map(function (item) { return AptosNFTCollectionItemResponse.create(item); }); } AptosNFTCollectionsByCreatorResponse.create = function (input) { if (input instanceof AptosNFTCollectionsByCreatorResponse) { return input; } return new AptosNFTCollectionsByCreatorResponse(input); }; AptosNFTCollectionsByCreatorResponse.fromJSON = function (json) { var input = { cursor: json.cursor, hasNextPage: json.hasNextPage, result: json.result.map(function (item) { return AptosNFTCollectionItemResponse.fromJSON(item); }), }; return AptosNFTCollectionsByCreatorResponse.create(input); }; AptosNFTCollectionsByCreatorResponse.prototype.toJSON = function () { return { cursor: this.cursor, hasNextPage: this.hasNextPage, result: this.result.map(function (item) { return item.toJSON(); }), }; }; return AptosNFTCollectionsByCreatorResponse; }()); var GetNFTCollectionsByCreatorOperation = { operationId: "getNFTCollectionsByCreator", groupName: "collections", httpMethod: "get", routePattern: "/collections/creators", parameterNames: ["limit", "offset", "cursor", "creator_address", "network"], hasResponse: true, hasBody: false, parseResponse: function (json) { return AptosNFTCollectionsByCreatorResponse.fromJSON(json); }, serializeRequest: function (request) { var limit = request.limit; var offset = request.offset; var cursor = request.cursor; var creatorAddress = AptosAddress.create(request.creatorAddress); var network = request.network ? AptosNetwork.create(request.network) : undefined; return { limit: limit, offset: offset, cursor: cursor, creator_address: creatorAddress.toJSON(), network: network ? network.toJSON() : undefined, }; }, }; // $ref: #/components/schemas/NFTOwnerResponse/properties/token_properties // typeName: NFTOwnerResponse_token_properties var AptosNFTOwnerResponseTokenProperties = /** @class */ (function () { function AptosNFTOwnerResponseTokenProperties() { } AptosNFTOwnerResponseTokenProperties.create = function (input) { return input; }; AptosNFTOwnerResponseTokenProperties.fromJSON = function (json) { return json; }; return AptosNFTOwnerResponseTokenProperties; }()); var AptosNFTOwnerResponse = /** @class */ (function () { function AptosNFTOwnerResponse(input) { this.amount = AptosNative.create(input.amount); this.collectionDataIdHash = input.collectionDataIdHash; this.collectionName = input.collectionName; this.creatorAddress = AptosAddress.create(input.creatorAddress); this.lastTransactionTimestamp = input.lastTransactionTimestamp; this.lastTransactionVersion = input.lastTransactionVersion; this.name = input.name; this.ownerAddress = AptosAddress.create(input.ownerAddress); this.propertyVersion = input.propertyVersion; this.tableType = input.tableType; this.tokenDataIdHash = input.tokenDataIdHash; this.tokenProperties = AptosNFTOwnerResponseTokenProperties.create(input.tokenProperties); } AptosNFTOwnerResponse.create = function (input) { if (input instanceof AptosNFTOwnerResponse) { return input; } return new AptosNFTOwnerResponse(input); }; AptosNFTOwnerResponse.fromJSON = function (json) { var input = { amount: AptosNative.fromJSON(json.amount), collectionDataIdHash: json.collection_data_id_hash, collectionName: json.collection_name, creatorAddress: AptosAddress.fromJSON(json.creator_address), lastTransactionTimestamp: json.last_transaction_timestamp, lastTransactionVersion: json.last_transaction_version, name: json.name, ownerAddress: AptosAddress.fromJSON(json.owner_address), propertyVersion: json.property_version, tableType: json.table_type, tokenDataIdHash: json.token_data_id_hash, tokenProperties: AptosNFTOwnerResponseTokenProperties.fromJSON(json.token_properties), }; return AptosNFTOwnerResponse.create(input); }; AptosNFTOwnerResponse.prototype.toJSON = function () { return { amount: this.amount.toJSON(), collection_data_id_hash: this.collectionDataIdHash, collection_name: this.collectionName, creator_address: this.creatorAddress.toJSON(), last_transaction_timestamp: this.lastTransactionTimestamp, last_transaction_version: this.lastTransactionVersion, name: this.name, owner_address: this.ownerAddress.toJSON(), property_version: this.propertyVersion, table_type: this.tableType, token_data_id_hash: this.tokenDataIdHash, token_properties: this.tokenProperties, }; }; return AptosNFTOwnerResponse; }()); var AptosNFTOwnersByTokensResponse = /** @class */ (function () { function AptosNFTOwnersByTokensResponse(input) { this.cursor = input.cursor; this.hasNextPage = input.hasNextPage; this.result = input.result.map(function (item) { return AptosNFTOwnerResponse.create(item); }); } AptosNFTOwnersByTokensResponse.create = function (input) { if (input instanceof AptosNFTOwnersByTokensResponse) { return input; } return new AptosNFTOwnersByTokensResponse(input); }; AptosNFTOwnersByTokensResponse.fromJSON = function (json) { var input = { cursor: json.cursor, hasNextPage: json.hasNextPage, result: json.result.map(function (item) { return AptosNFTOwnerResponse.fromJSON(item); }), }; return AptosNFTOwnersByTokensResponse.create(input); }; AptosNFTOwnersByTokensResponse.prototype.toJSON = function () { return { cursor: this.cursor, hasNextPage: this.hasNextPage, result: this.result.map(function (item) { return item.toJSON(); }), }; }; return AptosNFTOwnersByTokensResponse; }()); var GetNFTOwnersByTokensOperation = { operationId: "getNFTOwnersByTokens", groupName: "nfts", httpMethod: "get", routePattern: "/nfts/owners", parameterNames: ["limit", "offset", "cursor", "token_ids", "network"], hasResponse: true, hasBody: false, parseResponse: function (json) { return AptosNFTOwnersByTokensResponse.fromJSON(json); }, serializeRequest: function (request) { var limit = request.limit; var offset = request.offset; var cursor = request.cursor; var tokenIds = request.tokenIds; var network = request.network ? AptosNetwork.create(request.network) : undefined; return { limit: limit, offset: offset, cursor: cursor, token_ids: tokenIds, network: network ? network.toJSON() : undefined, }; }, }; var AptosNFTOwnersByCollectionResponse = /** @class */ (function () { function AptosNFTOwnersByCollectionResponse(input) { this.cursor = input.cursor; this.hasNextPage = input.hasNextPage; this.result = input.result.map(function (item) { return AptosNFTOwnerResponse.create(item); }); } AptosNFTOwnersByCollectionResponse.create = function (input) { if (input instanceof AptosNFTOwnersByCollectionResponse) { return input; } return new AptosNFTOwnersByCollectionResponse(input); }; AptosNFTOwnersByCollectionResponse.fromJSON = function (json) { var input = { cursor: json.cursor, hasNextPage: json.hasNextPage, result: json.result.map(function (item) { return AptosNFTOwnerResponse.fromJSON(item); }), }; return AptosNFTOwnersByCollectionResponse.create(input); }; AptosNFTOwnersByCollectionResponse.prototype.toJSON = function () { return { cursor: this.cursor, hasNextPage: this.hasNextPage, result: this.result.map(function (item) { return item.toJSON(); }), }; }; return AptosNFTOwnersByCollectionResponse; }()); var GetNFTOwnersByCollectionOperation = { operationId: "getNFTOwnersByCollection", groupName: "nfts", httpMethod: "get", routePattern: "/nfts/collections/{collection_data_id_hash}/owners", parameterNames: ["collection_data_id_hash", "limit", "offset", "cursor", "wallet_blacklist", "wallet_whitelist", "network"], hasResponse: true, hasBody: false, parseResponse: function (json) { return AptosNFTOwnersByCollectionResponse.fromJSON(json); }, serializeRequest: function (request) { var collectionDataIdHash = request.collectionDataIdHash; var limit = request.limit; var offset = request.offset; var cursor = request.cursor; var walletBlacklist = request.walletBlacklist; var walletWhitelist = request.walletWhitelist; var network = request.network ? AptosNetwork.create(request.network) : undefined; return { collection_data_id_hash: collectionDataIdHash, limit: limit, offset: offset, cursor: cursor, wallet_blacklist: walletBlacklist, wallet_whitelist: walletWhitelist, network: network ? network.toJSON() : undefined, }; }, }; // $ref: #/components/schemas/NFTOwnersOfCollectionResponse // type: NFTOwnersOfCollectionResponse // properties: // - cursor ($ref: #/components/schemas/NFTOwnersOfCollectionResponse/properties/cursor) // - hasNextPage ($ref: #/components/schemas/NFTOwnersOfCollectionResponse/properties/hasNextPage) // - result ($ref: #/components/schemas/NFTOwnersOfCollectionResponse/properties/result) var AptosNFTOwnersOfCollectionResponse = /** @class */ (function () { function AptosNFTOwnersOfCollectionResponse(input) { this.cursor = input.cursor; this.hasNextPage = input.hasNextPage; this.result = input.result; } AptosNFTOwnersOfCollectionResponse.create = function (input) { if (input instanceof AptosNFTOwnersOfCollectionResponse) { return input; } return new AptosNFTOwnersOfCollectionResponse(input); }; AptosNFTOwnersOfCollectionResponse.fromJSON = function (json) { var input = {