@protokol/nft-base-crypto
Version:
Transaction Builders For Base NFT Transaction Types
178 lines • 7.46 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NFTRegisterCollectionTransaction = 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");
const schemas_1 = require("./utils/schemas");
class NFTRegisterCollectionTransaction extends core_nft_crypto_1.AbstractNFTTransaction {
static getAssetSchema() {
return {
type: "object",
required: ["nftCollection"],
properties: {
nftCollection: {
type: "object",
required: ["name", "description", "maximumSupply", "jsonSchema"],
properties: {
name: {
allOf: [
schemas_1.stringPattern,
{
minLength: defaults_1.defaults.nftCollectionName.minLength,
maxLength: defaults_1.defaults.nftCollectionName.maxLength,
},
],
},
description: {
allOf: [
schemas_1.stringPattern,
{
minLength: defaults_1.defaults.nftCollectionDescription.minLength,
maxLength: defaults_1.defaults.nftCollectionDescription.maxLength,
},
],
},
maximumSupply: {
type: "integer",
minimum: 1,
},
jsonSchema: {
type: "object",
collectionJsonSchemaByteSize: defaults_1.defaults.nftCollectionJsonSchemaByteSize,
},
metadata: {
type: "object",
tokenAttributesByteSize: defaults_1.defaults.nftTokenAttributesByteSize,
},
allowedIssuers: {
type: "array",
minItems: defaults_1.defaults.nftCollectionAllowedIssuers.minItems,
maxItems: defaults_1.defaults.nftCollectionAllowedIssuers.maxItems,
uniqueItems: true,
items: {
$ref: "publicKey",
},
},
},
},
},
};
}
serialize() {
var _a;
const { data } = this;
utils_1.Asserts.assert.defined((_a = data.asset) === null || _a === void 0 ? void 0 : _a.nftCollection);
const nftCollectionAsset = data.asset.nftCollection;
const nameBuffer = Buffer.from(nftCollectionAsset.name, "utf8");
const descriptionBuffer = Buffer.from(nftCollectionAsset.description, "utf8");
const jsonSchemaBuffer = Buffer.from(JSON.stringify(nftCollectionAsset.jsonSchema), "utf8");
const buffersAllowedIssuersPublicKeys = [];
if (nftCollectionAsset.allowedIssuers) {
for (const publicKey of nftCollectionAsset.allowedIssuers) {
buffersAllowedIssuersPublicKeys.push(Buffer.from(publicKey, "utf8"));
}
}
const metadataBuffer = nftCollectionAsset.metadata
? Buffer.from(JSON.stringify(nftCollectionAsset.metadata))
: Buffer.from("");
const buffer = new bytebuffer_1.default(nameBuffer.length +
descriptionBuffer.length +
8 +
jsonSchemaBuffer.length +
3 +
buffersAllowedIssuersPublicKeys.length * 66 +
4 +
metadataBuffer.length, true);
buffer.writeByte(nameBuffer.length);
buffer.append(nameBuffer, "hex");
buffer.writeByte(descriptionBuffer.length);
buffer.append(descriptionBuffer, "hex");
buffer.writeUint32(nftCollectionAsset.maximumSupply);
buffer.writeUint32(jsonSchemaBuffer.length);
buffer.append(jsonSchemaBuffer, "hex");
buffer.writeByte(buffersAllowedIssuersPublicKeys.length);
if (nftCollectionAsset.allowedIssuers) {
for (const buf of buffersAllowedIssuersPublicKeys) {
buffer.append(buf, "hex");
}
}
buffer.writeUint32(metadataBuffer.length);
if (nftCollectionAsset.metadata) {
buffer.append(metadataBuffer, "hex");
}
return buffer;
}
deserialize(buf) {
const { data } = this;
const nameLength = buf.readUint8();
const name = buf.readString(nameLength);
const descriptionLength = buf.readUint8();
const description = buf.readString(descriptionLength);
const maximumSupply = buf.readUint32();
const schemaLength = buf.readUInt32();
const jsonSchema = JSON.parse(buf.readBytes(schemaLength).toBuffer().toString("utf8"));
const nftCollection = {
name,
description,
maximumSupply,
jsonSchema,
};
const numberOfSchemaIssuers = buf.readUint8();
if (numberOfSchemaIssuers !== 0) {
const allowedSchemaIssuers = [];
for (let i = 0; i < numberOfSchemaIssuers; i++) {
allowedSchemaIssuers.push(buf.readString(66));
}
nftCollection.allowedIssuers = allowedSchemaIssuers;
}
const metadataLength = buf.readUint32();
if (metadataLength) {
nftCollection.metadata = JSON.parse(buf.readBytes(metadataLength).toBuffer().toString("utf8"));
}
data.asset = {
nftCollection,
};
}
hasVendorField() {
return true;
}
}
exports.NFTRegisterCollectionTransaction = NFTRegisterCollectionTransaction;
Object.defineProperty(NFTRegisterCollectionTransaction, "typeGroup", {
enumerable: true,
configurable: true,
writable: true,
value: enums_1.NFTBaseTransactionGroup
});
Object.defineProperty(NFTRegisterCollectionTransaction, "type", {
enumerable: true,
configurable: true,
writable: true,
value: enums_1.NFTBaseTransactionTypes.NFTRegisterCollection
});
Object.defineProperty(NFTRegisterCollectionTransaction, "key", {
enumerable: true,
configurable: true,
writable: true,
value: "NFTRegisterCollection"
});
Object.defineProperty(NFTRegisterCollectionTransaction, "version", {
enumerable: true,
configurable: true,
writable: true,
value: enums_1.NFTBaseTransactionVersion
});
Object.defineProperty(NFTRegisterCollectionTransaction, "defaultStaticFee", {
enumerable: true,
configurable: true,
writable: true,
value: crypto_1.Utils.BigNumber.make(enums_1.NFTBaseStaticFees.NFTRegisterCollection)
});
//# sourceMappingURL=nft-register-collection.js.map