UNPKG

@protokol/nft-base-crypto

Version:

Transaction Builders For Base NFT Transaction Types

108 lines 4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.NFTCreateTransaction = void 0; const crypto_1 = require("@arkecosystem/crypto"); const core_nft_crypto_1 = require("@protokol/core-nft-crypto"); const utils_1 = require("@protokol/utils"); const bytebuffer_1 = __importDefault(require("bytebuffer")); const defaults_1 = require("../defaults"); const enums_1 = require("../enums"); class NFTCreateTransaction extends core_nft_crypto_1.AbstractNFTTransaction { static getAssetSchema() { return { type: "object", required: ["nftToken"], properties: { nftToken: { type: "object", required: ["collectionId", "attributes"], properties: { collectionId: { $ref: "transactionId", }, attributes: { type: "object", tokenAttributesByteSize: defaults_1.defaults.nftTokenAttributesByteSize, }, recipientId: { $ref: "address", }, }, }, }, }; } serialize() { var _a, _b; const { data } = this; utils_1.Asserts.assert.defined((_a = data.asset) === null || _a === void 0 ? void 0 : _a.nftToken); const nftToken = data.asset.nftToken; const dataBuffer = Buffer.from(JSON.stringify(nftToken.attributes)); const recipientLength = ((_b = nftToken.recipientId) === null || _b === void 0 ? void 0 : _b.length) || 0; const buffer = new bytebuffer_1.default(32 + 4 + dataBuffer.length + 1 + recipientLength, true); buffer.append(nftToken.collectionId, "hex"); buffer.writeUint32(dataBuffer.length); buffer.append(dataBuffer, "hex"); buffer.writeByte(recipientLength); if (recipientLength) { const { addressBuffer } = crypto_1.Identities.Address.toBuffer(nftToken.recipientId); buffer.append(addressBuffer); } return buffer; } deserialize(buf) { const { data } = this; const collectionId = buf.readBytes(32).toString("hex"); const attributesLength = buf.readUInt32(); const attributes = JSON.parse(buf.readBytes(attributesLength).toBuffer().toString("utf8")); const nftToken = { collectionId, attributes, }; const recipientLength = buf.readUint8(); if (recipientLength) { nftToken.recipientId = crypto_1.Identities.Address.fromBuffer(buf.readBytes(21).toBuffer()); } data.asset = { nftToken, }; } hasVendorField() { return true; } } exports.NFTCreateTransaction = NFTCreateTransaction; Object.defineProperty(NFTCreateTransaction, "typeGroup", { enumerable: true, configurable: true, writable: true, value: enums_1.NFTBaseTransactionGroup }); Object.defineProperty(NFTCreateTransaction, "type", { enumerable: true, configurable: true, writable: true, value: enums_1.NFTBaseTransactionTypes.NFTCreate }); Object.defineProperty(NFTCreateTransaction, "key", { enumerable: true, configurable: true, writable: true, value: "NFTCreate" }); Object.defineProperty(NFTCreateTransaction, "version", { enumerable: true, configurable: true, writable: true, value: enums_1.NFTBaseTransactionVersion }); Object.defineProperty(NFTCreateTransaction, "defaultStaticFee", { enumerable: true, configurable: true, writable: true, value: crypto_1.Utils.BigNumber.make(enums_1.NFTBaseStaticFees.NFTCreate) }); //# sourceMappingURL=nft-create.js.map