UNPKG

@silvana-one/nft

Version:
1,221 lines (1,210 loc) 249 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; 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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // dist/node/index.js var index_exports = {}; __export(index_exports, { Admin: () => Admin, AdminData: () => AdminData, AdvancedAdmin: () => AdvancedAdmin, AdvancedApproval: () => AdvancedApproval, AdvancedCollection: () => AdvancedCollection, AdvancedOffer: () => AdvancedOffer, AdvancedOwner: () => AdvancedOwner, Approval: () => Approval, ApproveEvent: () => ApproveEvent, Auction: () => Auction, AuctionBidEvent: () => AuctionBidEvent, AuctionFactory: () => AuctionFactory, AuctionPacked: () => AuctionPacked, AuctionState: () => AuctionState, BB_BidEvent: () => BB_BidEvent, BB_CancelBidEvent: () => BB_CancelBidEvent, BB_CancelOfferEvent: () => BB_CancelOfferEvent, BB_ChangeAdminEvent: () => BB_ChangeAdminEvent, BB_NewCollectionEvent: () => BB_NewCollectionEvent, BB_OfferEvent: () => BB_OfferEvent, BB_SaleEvent: () => BB_SaleEvent, BB_UpgradeVerificationKeyEvent: () => BB_UpgradeVerificationKeyEvent, Bid: () => Bid, BidEvent: () => BidEvent, BidFactory: () => BidFactory, BulletinBoard: () => BulletinBoard, Collection: () => Collection, CollectionData: () => CollectionData, CollectionErrors: () => CollectionErrors, CollectionFactory: () => CollectionFactory, ColorPlugin: () => ColorPlugin, DepositEvent: () => DepositEvent, LimitMintingEvent: () => LimitMintingEvent, MAX_ROYALTY_FEE: () => MAX_ROYALTY_FEE, Metadata: () => Metadata, MetadataFieldTypeValues: () => MetadataFieldTypeValues, MetadataMap: () => MetadataMap, MetadataTree: () => MetadataTree, MetadataValue: () => MetadataValue, MintEvent: () => MintEvent, MintParams: () => MintParams, MintParamsOption: () => MintParamsOption, MintRequest: () => MintRequest, MulDivResult: () => MulDivResult, NFT: () => NFT, NFTAddress: () => NFTAddress, NFTAdmin: () => NFTAdmin, NFTAdminAllowFlags: () => NFTAdminAllowFlags, NFTAdvancedAdmin: () => NFTAdvancedAdmin, NFTAdvancedAdminContract: () => NFTAdvancedAdminContract, NFTData: () => NFTData, NFTDataPacked: () => NFTDataPacked, NFTGameProgram: () => NFTGameProgram, NFTImmutableState: () => NFTImmutableState, NFTProgram: () => NFTProgram, NFTSharesData: () => NFTSharesData, NFTSharesDataPacked: () => NFTSharesDataPacked, NFTSharesFactory: () => NFTSharesFactory, NFTStandardApproval: () => NFTStandardApproval, NFTStandardOwner: () => NFTStandardOwner, NFTStandardUpdate: () => NFTStandardUpdate, NFTState: () => NFTState, NFTStateStruct: () => NFTStateStruct, NFTTransactionContext: () => NFTTransactionContext, NFTUpdateEvent: () => NFTUpdateEvent, NFTUpdateProof: () => NFTUpdateProof, NonFungibleTokenContractsFactory: () => NonFungibleTokenContractsFactory, Offer: () => Offer, OfferFactory: () => OfferFactory, Owner: () => Owner, OwnershipChangeEvent: () => OwnershipChangeEvent, PauseEvent: () => PauseEvent, PauseNFTEvent: () => PauseNFTEvent, SellEvent: () => SellEvent, SetAdminEvent: () => SetAdminEvent, SetBaseURLEvent: () => SetBaseURLEvent, SetNameEvent: () => SetNameEvent, SetRoyaltyFeeEvent: () => SetRoyaltyFeeEvent, SetTransferFeeEvent: () => SetTransferFeeEvent, TEXT_TREE_HEIGHT: () => TEXT_TREE_HEIGHT, Text: () => Text, TransferByProofParams: () => TransferByProofParams, TransferBySignatureParams: () => TransferBySignatureParams, TransferEvent: () => TransferEvent, TransferExtendedParams: () => TransferExtendedParams, UInt64Option: () => UInt64Option, Update: () => Update, UpdateEvent: () => UpdateEvent, UpgradeVerificationKeyData: () => UpgradeVerificationKeyData, UpgradeVerificationKeyEvent: () => UpgradeVerificationKeyEvent, WithdrawEvent: () => WithdrawEvent, fieldFromString: () => fieldFromString, fieldToString: () => fieldToString, mulDiv: () => mulDiv, nftVerificationKeys: () => nftVerificationKeys, pinMetadata: () => pinMetadata }); module.exports = __toCommonJS(index_exports); // dist/node/admin/advanced.js var import_tslib4 = require("tslib"); var import_o1js9 = require("o1js"); var import_storage3 = require("@silvana-one/storage"); // dist/node/interfaces/types.js var import_o1js = require("o1js"); var import_storage = require("@silvana-one/storage"); var UInt64Option = class extends (0, import_o1js.Option)(import_o1js.UInt64) { }; var NFTDataPacked = class extends (0, import_o1js.Struct)({ ownerX: import_o1js.Field, approvedX: import_o1js.Field, data: import_o1js.Field }) { static assertEqual(a, b) { a.ownerX.assertEquals(b.ownerX); a.approvedX.assertEquals(b.approvedX); a.data.assertEquals(b.data); } }; var NFTStateStruct = class _NFTStateStruct extends (0, import_o1js.Struct)({ name: import_o1js.Field, metadata: import_o1js.Field, storage: import_storage.Storage, packedData: NFTDataPacked, metadataVerificationKeyHash: import_o1js.Field }) { /** * Creates an NFTStateStruct from an account's app state. * @param account The account containing the zkApp state. * @returns A new NFTStateStruct instance. */ static fromAccount(account) { if (!account.zkapp?.appState) { throw new Error("Invalid zkApp account state"); } if (_NFTStateStruct.sizeInFields() !== account.zkapp?.appState.length) { throw new Error("Invalid NFTStateStruct size"); } return _NFTStateStruct.fromFields(account.zkapp?.appState); } /** * Asserts that two NFTStateStruct instances are equal. * @param a The first NFTStateStruct instance. * @param b The second NFTStateStruct instance. */ static assertEqual(a, b) { a.name.assertEquals(b.name); a.metadata.assertEquals(b.metadata); import_storage.Storage.assertEquals(a.storage, b.storage); NFTDataPacked.assertEqual(a.packedData, b.packedData); a.metadataVerificationKeyHash.assertEquals(b.metadataVerificationKeyHash); } }; var NFTImmutableState = class _NFTImmutableState extends (0, import_o1js.Struct)({ /** Determines if the NFT's ownership can be changed via a zero-knowledge proof (readonly). */ canChangeOwnerByProof: import_o1js.Bool, // readonly /** Specifies if the NFT's ownership can be transferred (readonly). */ canTransfer: import_o1js.Bool, // readonly /** Specifies if the NFT's approved address can be changed (readonly). */ canApprove: import_o1js.Bool, // readonly /** Indicates whether the NFT's metadata can be updated (readonly). */ canChangeMetadata: import_o1js.Bool, // readonly /** Determines whether the storage associated with the NFT can be altered (readonly). */ canChangeStorage: import_o1js.Bool, // readonly /** Specifies if the name of the NFT can be changed (readonly). */ canChangeName: import_o1js.Bool, // readonly /** Indicates whether the verification key hash for the metadata can be changed (readonly). */ canChangeMetadataVerificationKeyHash: import_o1js.Bool, // readonly /** Specifies if the NFT contract can be paused, preventing certain operations (readonly). */ canPause: import_o1js.Bool, // readonly /** The address of the NFT contract (readonly). */ address: import_o1js.PublicKey, // readonly /** The token ID associated with the NFT (readonly). */ tokenId: import_o1js.Field, // readonly /** The identifier of the NFT within the collection to be used off-chain(readonly). * It can be set to any value chosen by the creator for the new NFTs * and by default is set to 0. To uniquely identify the NFT, use the pair (NFT address, tokenId) or (collection address, NFT address) */ id: import_o1js.UInt64 // readonly }) { /** * Asserts that two NFTImmutableState instances are equal. * @param a The first NFTImmutableState instance. * @param b The second NFTImmutableState instance. */ static assertEqual(a, b) { a.canChangeOwnerByProof.assertEquals(b.canChangeOwnerByProof); a.canTransfer.assertEquals(b.canTransfer); a.canApprove.assertEquals(b.canApprove); a.canChangeMetadata.assertEquals(b.canChangeMetadata); a.canChangeStorage.assertEquals(b.canChangeStorage); a.canChangeName.assertEquals(b.canChangeName); a.canChangeMetadataVerificationKeyHash.assertEquals(b.canChangeMetadataVerificationKeyHash); a.canPause.assertEquals(b.canPause); a.address.assertEquals(b.address); a.tokenId.assertEquals(b.tokenId); a.id.assertEquals(b.id); } /** * Creates a new NFTImmutableState from NFTData and other parameters. * @param params The parameters including nftData, creator, address, and tokenId. * @returns A new NFTImmutableState instance. */ static fromNFTData(params) { const { nftData, address, tokenId } = params; return new _NFTImmutableState({ address, tokenId, id: nftData.id, canChangeOwnerByProof: nftData.canChangeOwnerByProof, canTransfer: nftData.canTransfer, canApprove: nftData.canApprove, canChangeMetadata: nftData.canChangeMetadata, canChangeStorage: nftData.canChangeStorage, canChangeName: nftData.canChangeName, canChangeMetadataVerificationKeyHash: nftData.canChangeMetadataVerificationKeyHash, canPause: nftData.canPause }); } }; var NFTTransactionContext = class extends (0, import_o1js.Struct)({ /** Custom context that can be interpreted by the owner or approved contract. * Can hold Storage and root or two PublicKeys and UInt64 * In case of holding Storage and root, the contracts can fetch using witnessAsync any off-chain data with unlimited size * and verify it using the root. */ custom: import_o1js.Provable.Array(import_o1js.Field, 3) }) { static assertEqual(a, b) { for (let i = 0; i < 3; i++) { a.custom[i].assertEquals(b.custom[i]); } } }; var NFTState = class _NFTState extends (0, import_o1js.Struct)({ /** The immutable state of the NFT. */ immutableState: NFTImmutableState, /** The name of the NFT. */ name: import_o1js.Field, /** The owner of the NFT. */ owner: import_o1js.PublicKey, /** The approved address of the NFT. */ approved: import_o1js.PublicKey, /** The metadata associated with the NFT. */ metadata: import_o1js.Field, /** The off-chain storage information (e.g., IPFS hash). */ storage: import_storage.Storage, /** The version number of the NFT state. */ version: import_o1js.UInt64, /** Indicates whether the NFT contract is currently paused. */ isPaused: import_o1js.Bool, /** The hash of the verification key used for metadata proofs. */ metadataVerificationKeyHash: import_o1js.Field, /** The public key of the creator of the NFT (readonly). */ creator: import_o1js.PublicKey, // readonly /** The transaction context of the NFT. */ context: NFTTransactionContext, // readonly /** The oracle address to link the NFT update with the network and accounts state */ oracleAddress: import_o1js.PublicKey // readonly }) { /** * Asserts that two NFTState instances are equal. * @param a The first NFTState instance. * @param b The second NFTState instance. */ static assertEqual(a, b) { NFTImmutableState.assertEqual(a.immutableState, b.immutableState); a.name.assertEquals(b.name); a.metadata.assertEquals(b.metadata); import_storage.Storage.assertEquals(a.storage, b.storage); a.owner.assertEquals(b.owner); a.approved.assertEquals(b.approved); a.version.assertEquals(b.version); a.isPaused.assertEquals(b.isPaused); a.metadataVerificationKeyHash.assertEquals(b.metadataVerificationKeyHash); a.creator.assertEquals(b.creator); NFTTransactionContext.assertEqual(a.context, b.context); a.oracleAddress.assertEquals(b.oracleAddress); } /** * Creates a new NFTState from an NFTStateStruct and other parameters. * @param params The parameters including nftState, creator, address, and tokenId. * @returns A new NFTState instance. */ static fromNFTState(params) { const { nftState, creator, address, tokenId, context, oracleAddress } = params; const nftData = NFTData.unpack(nftState.packedData); const immutableState = NFTImmutableState.fromNFTData({ nftData, address, tokenId }); return new _NFTState({ immutableState, name: nftState.name, metadata: nftState.metadata, storage: nftState.storage, owner: nftData.owner, approved: nftData.approved, version: nftData.version, isPaused: nftData.isPaused, metadataVerificationKeyHash: nftState.metadataVerificationKeyHash, creator, context: context ?? NFTTransactionContext.empty(), oracleAddress: oracleAddress ?? import_o1js.PublicKey.empty() }); } }; var _NFTUpdateProof = class _NFTUpdateProof extends import_o1js.DynamicProof { }; _NFTUpdateProof.publicInputType = NFTState; _NFTUpdateProof.publicOutputType = NFTState; _NFTUpdateProof.maxProofsVerified = 2; _NFTUpdateProof.featureFlags = import_o1js.FeatureFlags.allMaybe; var NFTUpdateProof = _NFTUpdateProof; var NFTData = class _NFTData extends (0, import_o1js.Struct)({ /** The owner of the NFT. */ owner: import_o1js.PublicKey, /** The approved address of the NFT. */ approved: import_o1js.PublicKey, /** The version number of the NFT state. */ version: import_o1js.UInt64, /** The unique identifier of the NFT within the collection. */ id: import_o1js.UInt64, /** Determines whether the NFT's ownership can be changed via a zero-knowledge proof (readonly). * * It can be used only with update() and updateWithOracle() methods and * in this case overrides both canTransfer and canApprove flags used in the transfer methods */ canChangeOwnerByProof: import_o1js.Bool, // readonly /** Specifies if the NFT's ownership can be transferred (readonly). Applies * to transfer methods and can be bypassed by the update() and updateWithOracle() methods */ canTransfer: import_o1js.Bool, // readonly /** Specifies if the NFT's approved address can be changed (readonly). Transfer methods reset approved address to PublicKey.empty() * on transfer independently from the canApprove flag value */ canApprove: import_o1js.Bool, // readonly /** Indicates whether the NFT's metadata can be updated (readonly). */ canChangeMetadata: import_o1js.Bool, // readonly /** Determines whether the storage associated with the NFT can be altered (readonly). */ canChangeStorage: import_o1js.Bool, // readonly /** Specifies if the name of the NFT can be changed (readonly). */ canChangeName: import_o1js.Bool, // readonly /** Indicates whether the verification key hash for the metadata can be changed (readonly). */ canChangeMetadataVerificationKeyHash: import_o1js.Bool, // readonly /** Specifies if the NFT contract can be paused, preventing certain operations (readonly). */ canPause: import_o1js.Bool, // readonly /** Indicates whether the NFT contract is currently paused. */ isPaused: import_o1js.Bool, /** Determines whether the owner's authorization is required to upgrade the NFT's verification key (readonly). */ requireOwnerAuthorizationToUpgrade: import_o1js.Bool // readonly }) { /** * Creates a new NFTData instance with optional parameters. * @param params The parameters to create the NFTData. * @returns A new NFTData instance. */ static new(params) { const { owner, approved, version, id, canChangeOwnerByProof, canTransfer, canApprove, canChangeMetadata, canChangeStorage, canChangeName, canChangeMetadataVerificationKeyHash, canPause, isPaused, requireOwnerAuthorizationToUpgrade } = params; return new _NFTData({ owner: typeof owner === "string" ? import_o1js.PublicKey.fromBase58(owner) : owner, approved: approved ? typeof approved === "string" ? import_o1js.PublicKey.fromBase58(approved) : approved : import_o1js.PublicKey.empty(), version: import_o1js.UInt64.from(BigInt(version ?? 0)), id: import_o1js.UInt64.from(BigInt(id ?? 0)), canChangeOwnerByProof: (0, import_o1js.Bool)(canChangeOwnerByProof ?? false), canTransfer: (0, import_o1js.Bool)(canTransfer ?? true), canApprove: (0, import_o1js.Bool)(canApprove ?? true), canChangeMetadata: (0, import_o1js.Bool)(canChangeMetadata ?? false), canChangeStorage: (0, import_o1js.Bool)(canChangeStorage ?? false), canChangeName: (0, import_o1js.Bool)(canChangeName ?? false), canChangeMetadataVerificationKeyHash: (0, import_o1js.Bool)(canChangeMetadataVerificationKeyHash ?? false), canPause: (0, import_o1js.Bool)(canPause ?? false), isPaused: (0, import_o1js.Bool)(isPaused ?? false), requireOwnerAuthorizationToUpgrade: (0, import_o1js.Bool)(requireOwnerAuthorizationToUpgrade ?? false) }); } /** * Packs the NFTData into a single Field for efficient storage. * @returns The packed Field representation of the NFTData. */ pack() { return new NFTDataPacked({ ownerX: this.owner.x, approvedX: this.approved.x, data: import_o1js.Field.fromBits([ this.canChangeOwnerByProof, this.canTransfer, this.canApprove, this.canChangeMetadata, this.canChangeStorage, this.canChangeName, this.canChangeMetadataVerificationKeyHash, this.canPause, this.isPaused, this.requireOwnerAuthorizationToUpgrade, this.owner.isOdd, this.approved.isOdd ]).add((0, import_o1js.Field)(this.id.value).mul((0, import_o1js.Field)(2 ** 12))).add((0, import_o1js.Field)(this.version.value).mul((0, import_o1js.Field)(2 ** (12 + 64)))) }); } /** * Unpacks a Field into an NFTData instance. * @param packed The packed Field representation of the NFTData. * @returns A new NFTData instance. */ static unpack(packed) { const unpacked = import_o1js.Provable.witness(_NFTData, () => { const bits = import_o1js.Gadgets.and(packed.data, (0, import_o1js.Field)(0xfffn), 12 + 64 + 64).toBits(12); const idField = import_o1js.Gadgets.and(packed.data, (0, import_o1js.Field)(0xffffffffffffffff000n), 12 + 64 + 64); const idBits = idField.toBits(64 + 12); const id = import_o1js.UInt64.Unsafe.fromField(import_o1js.Field.fromBits(idBits.slice(12, 64 + 12))); id.value.mul((0, import_o1js.Field)(2 ** 12)).assertEquals(idField); const versionField = import_o1js.Gadgets.and(packed.data, (0, import_o1js.Field)(0xffffffffffffffff0000000000000000000n), 64 + 64 + 12); const versionBits = versionField.toBits(12 + 64 + 64); const version = import_o1js.UInt64.Unsafe.fromField(import_o1js.Field.fromBits(versionBits.slice(12 + 64, 12 + 64 + 64))); version.value.mul((0, import_o1js.Field)(2 ** (12 + 64))).assertEquals(versionField); const canChangeOwnerByProof = bits[0]; const canTransfer = bits[1]; const canApprove = bits[2]; const canChangeMetadata = bits[3]; const canChangeStorage = bits[4]; const canChangeName = bits[5]; const canChangeMetadataVerificationKeyHash = bits[6]; const canPause = bits[7]; const isPaused = bits[8]; const requireOwnerAuthorizationToUpgrade = bits[9]; const ownerIsOdd = bits[10]; const approvedIsOdd = bits[11]; const owner = import_o1js.PublicKey.from({ x: packed.ownerX, isOdd: ownerIsOdd }); const approved = import_o1js.PublicKey.from({ x: packed.approvedX, isOdd: approvedIsOdd }); return new _NFTData({ owner, approved, id, version, canChangeOwnerByProof, canTransfer, canApprove, canChangeMetadata, canChangeStorage, canChangeName, canChangeMetadataVerificationKeyHash, canPause, isPaused, requireOwnerAuthorizationToUpgrade }); }); NFTDataPacked.assertEqual(unpacked.pack(), packed); return unpacked; } }; var MAX_ROYALTY_FEE = 1e5; var CollectionData = class _CollectionData extends (0, import_o1js.Struct)({ /** The royalty fee percentage (e.g., 1000 = 1%, 100 = 0.1%, 10000 = 10%, 100000 = 100%). */ royaltyFee: import_o1js.UInt32, // 1000 = 1%, 100 = 0.1%, 10000 = 10%, 100000 = 100% /** The transfer fee amount. */ transferFee: import_o1js.UInt64, /** If true, transferring NFTs requires approval from the admin contract. */ requireTransferApproval: import_o1js.Bool, /** If true, the minting is stopped and cannot be resumed. */ mintingIsLimited: import_o1js.Bool, /** Indicates whether the collection is currently paused. */ isPaused: import_o1js.Bool, /** The public key part (isOdd) of the pending creator. The x field is written to the contract state as pendingCreatorX */ pendingCreatorIsOdd: import_o1js.Bool }) { /** * Creates a new CollectionData instance with specified parameters. * @param params The parameters to create the CollectionData. * @returns A new CollectionData instance. */ static new(params) { const { royaltyFee, transferFee, requireTransferApproval, mintingIsLimited, isPaused } = params; return new _CollectionData({ royaltyFee: import_o1js.UInt32.from(royaltyFee ?? 0), transferFee: import_o1js.UInt64.from(BigInt(transferFee ?? 0)), requireTransferApproval: (0, import_o1js.Bool)(requireTransferApproval ?? false), mintingIsLimited: (0, import_o1js.Bool)(mintingIsLimited ?? false), isPaused: (0, import_o1js.Bool)(isPaused ?? false), pendingCreatorIsOdd: (0, import_o1js.Bool)(import_o1js.PublicKey.empty().isOdd) }); } /** * Packs the CollectionData into a CollectionDataPacked representation for efficient storage. * @returns The packed CollectionDataPacked instance. */ pack() { return import_o1js.Field.fromBits([ this.isPaused, this.requireTransferApproval, this.mintingIsLimited, this.pendingCreatorIsOdd ]).add((0, import_o1js.Field)(this.royaltyFee.value).mul((0, import_o1js.Field)(2 ** 4))).add((0, import_o1js.Field)(this.transferFee.value).mul((0, import_o1js.Field)(2 ** (4 + 32)))); } /** * Unpacks a CollectionDataPacked instance into a CollectionData instance. * @param packed The packed CollectionDataPacked instance. * @returns A new CollectionData instance. */ static unpack(packed) { const unpacked = import_o1js.Provable.witness(_CollectionData, () => { const bits = import_o1js.Gadgets.and(packed, (0, import_o1js.Field)(0xfn), 4 + 32 + 64).toBits(4); const royaltyFeeField = import_o1js.Gadgets.and(packed, (0, import_o1js.Field)(0xffffffff0n), 4 + 32 + 64); const royaltyFeeBits = royaltyFeeField.toBits(4 + 32); const royaltyFee = import_o1js.UInt32.Unsafe.fromField(import_o1js.Field.fromBits(royaltyFeeBits.slice(4, 4 + 32))); royaltyFee.value.mul((0, import_o1js.Field)(2 ** 4)).assertEquals(royaltyFeeField); const transferFeeField = import_o1js.Gadgets.and(packed, (0, import_o1js.Field)(0xffffffffffffffff000000000n), 4 + 32 + 64); const transferFeeBits = transferFeeField.toBits(4 + 32 + 64); const transferFee = import_o1js.UInt64.Unsafe.fromField(import_o1js.Field.fromBits(transferFeeBits.slice(4 + 32, 4 + 32 + 64))); transferFee.value.mul((0, import_o1js.Field)(2 ** (4 + 32))).assertEquals(transferFeeField); return new _CollectionData({ isPaused: bits[0], requireTransferApproval: bits[1], mintingIsLimited: bits[2], pendingCreatorIsOdd: bits[3], royaltyFee, transferFee }); }); unpacked.pack().assertEquals(packed); return unpacked; } static isPaused(packed) { return packed.toBits(4 + 32 + 64)[0]; } static requireTransferApproval(packed) { return packed.toBits(4 + 32 + 64)[1]; } }; var MintParams = class extends (0, import_o1js.Struct)({ /** The name of the NFT. */ name: import_o1js.Field, /** The address of the NFT contract. */ address: import_o1js.PublicKey, /** The token ID of the NFT. */ tokenId: import_o1js.Field, /** The data associated with the NFT, including owner, approved, version, id, permissions and flags. */ data: NFTData, /** The fee associated with minting the NFT. */ fee: import_o1js.UInt64, /** The metadata associated with the NFT. */ metadata: import_o1js.Field, /** The off-chain storage information (e.g., IPFS hash). */ storage: import_storage.Storage, /** The hash of the verification key used for metadata proofs. */ metadataVerificationKeyHash: import_o1js.Field, /** The expiry time slot for minting the NFT. */ expiry: import_o1js.UInt32 }) { }; var MintParamsOption = class extends (0, import_o1js.Option)(MintParams) { }; var MintRequest = class extends (0, import_o1js.Struct)({ /** The address of the NFT contract where the NFT will be minted. */ address: import_o1js.PublicKey, /** The owner of the new NFT (can be different from the sender). */ owner: import_o1js.PublicKey, // can be different from the sender /** A custom value that can be interpreted by the admin contract. */ context: NFTTransactionContext // should be interpreted by the admin contract }) { }; var TransferBySignatureParams = class extends (0, import_o1js.Struct)({ /** The address of the NFT contract. */ address: import_o1js.PublicKey, /** The receiver's public key. */ to: import_o1js.PublicKey, /** Optional price for the transfer. */ price: UInt64Option, /** Custom value that can be interpreted by the owner or approved contract. */ context: NFTTransactionContext }) { }; var TransferByProofParams = class extends (0, import_o1js.Struct)({ /** The address of the NFT contract. */ address: import_o1js.PublicKey, /** The sender's public key. */ from: import_o1js.PublicKey, /** The receiver's public key. */ to: import_o1js.PublicKey, /** Optional price for the transfer. */ price: UInt64Option, /** Custom value that can be interpreted by the owner or approved contract. */ context: NFTTransactionContext }) { }; var TransferExtendedParams = class extends (0, import_o1js.Struct)({ /** The public key of the sender (current owner) before the transfer. */ from: import_o1js.PublicKey, /** The public key of the recipient (new owner) after the transfer. */ to: import_o1js.PublicKey, /** The public key of the collection. */ collection: import_o1js.PublicKey, /** The public key address of the NFT being transferred. */ nft: import_o1js.PublicKey, /** The fee paid for the transfer. */ fee: UInt64Option, /** The price of the NFT being transferred. */ price: UInt64Option, /** Indicates whether the transfer is by owner or by approved address. */ transferByOwner: import_o1js.Bool, /** The public key of the approved address. */ approved: import_o1js.PublicKey, /** Custom value that can be interpreted by the owner or approved contract. */ context: NFTTransactionContext }) { }; // dist/node/interfaces/encoding.js var import_o1js2 = require("o1js"); function fieldToString(field) { return import_o1js2.Encoding.stringFromFields([field]); } function fieldFromString(storage) { const fields = import_o1js2.Encoding.stringToFields(storage); if (fields.length !== 1) throw new Error("String is too long"); return fields[0]; } // dist/node/interfaces/events.js var import_o1js3 = require("o1js"); var import_storage2 = require("@silvana-one/storage"); var MintEvent = class extends (0, import_o1js3.Struct)({ /** The initial state of the NFT at the time of minting. */ initialState: NFTStateStruct, /** The public key address of the minted NFT. */ address: import_o1js3.PublicKey, /** The token ID of the minted NFT. */ tokenId: import_o1js3.Field, /** The fee paid for the minting. * This fee is controlled by the admin contract * and is not checked by the Collection contract * Please check the admin contract code before using this fee */ fee: import_o1js3.UInt64 }) { }; var UpdateEvent = class extends (0, import_o1js3.Struct)({ /** The updated name of the NFT. */ name: import_o1js3.Field, /** The updated metadata hash of the NFT. */ metadata: import_o1js3.Field, /** Off-chain storage information, e.g., IPFS hash. */ storage: import_storage2.Storage, /** The owner of the NFT after the update. */ owner: import_o1js3.PublicKey, /** The approved address of the NFT after the update. */ approved: import_o1js3.PublicKey, /** The version number of the NFT state. */ version: import_o1js3.UInt64, /** Indicates whether the NFT is paused after the update. */ isPaused: import_o1js3.Bool, /** The hash of the verification key used for metadata proofs. */ metadataVerificationKeyHash: import_o1js3.Field }) { }; var ApproveEvent = class extends (0, import_o1js3.Struct)({ /** The public key address of the NFT. */ nftAddress: import_o1js3.PublicKey, /** The public key of the approved address. */ approved: import_o1js3.PublicKey }) { }; var TransferEvent = class extends (0, import_o1js3.Struct)({ /** The public key of the sender (current owner) before the transfer. */ from: import_o1js3.PublicKey, /** The public key of the recipient (new owner) after the transfer. */ to: import_o1js3.PublicKey, /** The public key of the collection. */ collection: import_o1js3.PublicKey, /** The public key address of the NFT being transferred. */ nft: import_o1js3.PublicKey, /** The fee paid for the transfer. */ fee: UInt64Option, /** The price of the NFT being transferred. */ price: UInt64Option, /** Indicates whether the transfer is by owner or by approved address. */ transferByOwner: import_o1js3.Bool, /** The public key of the approved address. */ approved: import_o1js3.PublicKey }) { }; var PauseNFTEvent = class extends (0, import_o1js3.Struct)({ /** The public key address of the NFT. */ address: import_o1js3.PublicKey, /** Indicates whether the NFT is paused (`true`) or resumed (`false`). */ isPaused: import_o1js3.Bool }) { }; var UpgradeVerificationKeyEvent = class extends (0, import_o1js3.Struct)({ /** The hash of the new verification key. */ verificationKeyHash: import_o1js3.Field, /** The public key address of the NFT whose verification key is upgraded. */ address: import_o1js3.PublicKey, /** The tokenId of the upgraded contract */ tokenId: import_o1js3.Field }) { }; var UpgradeVerificationKeyData = class extends (0, import_o1js3.Struct)({ /** The owner of the NFT. */ owner: import_o1js3.PublicKey, /** Indicates whether the owner approval is required to upgrade the verification key. */ isOwnerApprovalRequired: import_o1js3.Bool }) { }; var LimitMintingEvent = class extends (0, import_o1js3.Struct)({ /** Indicates whether minting is limited (`true`) or not (`false`). */ mintingLimited: import_o1js3.Bool }) { }; var NFTUpdateEvent = class extends (0, import_o1js3.Struct)({ /** The public key address of the NFT. */ address: import_o1js3.PublicKey }) { }; var SetNameEvent = class extends (0, import_o1js3.Struct)({ /** The updated name of the Collection. */ name: import_o1js3.Field }) { }; var SetBaseURLEvent = class extends (0, import_o1js3.Struct)({ /** The updated base URL of the Collection. */ baseURL: import_o1js3.Field }) { }; var SetRoyaltyFeeEvent = class extends (0, import_o1js3.Struct)({ /** The updated royalty fee of the Collection. */ royaltyFee: import_o1js3.UInt32 }) { }; var SetTransferFeeEvent = class extends (0, import_o1js3.Struct)({ /** The updated transfer fee of the Collection. */ transferFee: import_o1js3.UInt64 }) { }; var SetAdminEvent = class extends (0, import_o1js3.Struct)({ /** The updated admin contract of the Collection. */ admin: import_o1js3.PublicKey }) { }; // dist/node/interfaces/pausable.js var import_o1js4 = require("o1js"); var PauseEvent = class extends (0, import_o1js4.Struct)({ /** * Indicates whether the contract is currently paused. */ isPaused: import_o1js4.Bool }) { }; // dist/node/interfaces/ownable.js var import_o1js5 = require("o1js"); var OwnershipChangeEvent = class extends (0, import_o1js5.Struct)({ from: import_o1js5.PublicKey, to: import_o1js5.PublicKey }) { }; // dist/node/interfaces/owner.js var import_tslib = require("tslib"); var import_o1js6 = require("o1js"); var NFTStandardOwner = class extends import_o1js6.SmartContract { constructor() { super(...arguments); this.admin = (0, import_o1js6.State)(); } /** * Deploys the contract with initial settings. * @param props - Deployment properties including admin, upgradeAuthority, uri, canPause, and isPaused. */ async deploy(props) { await super.deploy(props); this.admin.set(props.admin); this.account.zkappUri.set(props.uri); this.account.permissions.set({ ...import_o1js6.Permissions.default(), setVerificationKey: import_o1js6.Permissions.VerificationKey.signature(), setPermissions: import_o1js6.Permissions.impossible() }); } /** * Ensures that the transaction is authorized by the contract owner. * @returns A signed `AccountUpdate` from the admin. */ async ensureOwnerSignature() { const admin = this.admin.getAndRequireEquals(); const adminUpdate = import_o1js6.AccountUpdate.createSigned(admin); adminUpdate.body.useFullCommitment = (0, import_o1js6.Bool)(true); return adminUpdate; } async canTransfer(params) { await this.ensureOwnerSignature(); return (0, import_o1js6.Bool)(true); } async canPause(collection, nft) { await this.ensureOwnerSignature(); return (0, import_o1js6.Bool)(true); } async canResume(collection, nft) { await this.ensureOwnerSignature(); return (0, import_o1js6.Bool)(true); } async canChangeVerificationKey(collection, nft, vk) { await this.ensureOwnerSignature(); return (0, import_o1js6.Bool)(true); } async canApproveAddress(collection, nft, approved) { await this.ensureOwnerSignature(); return (0, import_o1js6.Bool)(true); } }; (0, import_tslib.__decorate)([ (0, import_o1js6.state)(import_o1js6.PublicKey), (0, import_tslib.__metadata)("design:type", Object) ], NFTStandardOwner.prototype, "admin", void 0); (0, import_tslib.__decorate)([ import_o1js6.method.returns(import_o1js6.Bool), (0, import_tslib.__metadata)("design:type", Function), (0, import_tslib.__metadata)("design:paramtypes", [TransferExtendedParams]), (0, import_tslib.__metadata)("design:returntype", Promise) ], NFTStandardOwner.prototype, "canTransfer", null); (0, import_tslib.__decorate)([ import_o1js6.method.returns(import_o1js6.Bool), (0, import_tslib.__metadata)("design:type", Function), (0, import_tslib.__metadata)("design:paramtypes", [import_o1js6.PublicKey, import_o1js6.PublicKey]), (0, import_tslib.__metadata)("design:returntype", Promise) ], NFTStandardOwner.prototype, "canPause", null); (0, import_tslib.__decorate)([ import_o1js6.method.returns(import_o1js6.Bool), (0, import_tslib.__metadata)("design:type", Function), (0, import_tslib.__metadata)("design:paramtypes", [import_o1js6.PublicKey, import_o1js6.PublicKey]), (0, import_tslib.__metadata)("design:returntype", Promise) ], NFTStandardOwner.prototype, "canResume", null); (0, import_tslib.__decorate)([ import_o1js6.method.returns(import_o1js6.Bool), (0, import_tslib.__metadata)("design:type", Function), (0, import_tslib.__metadata)("design:paramtypes", [ import_o1js6.PublicKey, import_o1js6.PublicKey, import_o1js6.VerificationKey ]), (0, import_tslib.__metadata)("design:returntype", Promise) ], NFTStandardOwner.prototype, "canChangeVerificationKey", null); (0, import_tslib.__decorate)([ import_o1js6.method.returns(import_o1js6.Bool), (0, import_tslib.__metadata)("design:type", Function), (0, import_tslib.__metadata)("design:paramtypes", [ import_o1js6.PublicKey, import_o1js6.PublicKey, import_o1js6.PublicKey ]), (0, import_tslib.__metadata)("design:returntype", Promise) ], NFTStandardOwner.prototype, "canApproveAddress", null); // dist/node/interfaces/approval.js var import_tslib2 = require("tslib"); var import_o1js7 = require("o1js"); var NFTStandardApproval = class extends import_o1js7.SmartContract { constructor() { super(...arguments); this.admin = (0, import_o1js7.State)(); } /** * Deploys the contract with initial settings. * @param props - Deployment properties including admin, upgradeAuthority, uri, canPause, and isPaused. */ async deploy(props) { await super.deploy(props); this.admin.set(props.admin); this.account.zkappUri.set(props.uri); this.account.permissions.set({ ...import_o1js7.Permissions.default(), setVerificationKey: import_o1js7.Permissions.VerificationKey.signature(), setPermissions: import_o1js7.Permissions.impossible() }); } /** * Ensures that the transaction is authorized by the contract owner. * @returns A signed `AccountUpdate` from the admin. */ async ensureOwnerSignature() { const admin = this.admin.getAndRequireEquals(); const adminUpdate = import_o1js7.AccountUpdate.createSigned(admin); adminUpdate.body.useFullCommitment = (0, import_o1js7.Bool)(true); return adminUpdate; } /** * Determines if an NFT can be transferred. * * @param params - The transfer details. * @returns A `Promise` resolving to a `Bool` indicating whether the transfer is allowed. */ async canTransfer(params) { await this.ensureOwnerSignature(); return (0, import_o1js7.Bool)(true); } }; (0, import_tslib2.__decorate)([ (0, import_o1js7.state)(import_o1js7.PublicKey), (0, import_tslib2.__metadata)("design:type", Object) ], NFTStandardApproval.prototype, "admin", void 0); (0, import_tslib2.__decorate)([ import_o1js7.method.returns(import_o1js7.Bool), (0, import_tslib2.__metadata)("design:type", Function), (0, import_tslib2.__metadata)("design:paramtypes", [TransferExtendedParams]), (0, import_tslib2.__metadata)("design:returntype", Promise) ], NFTStandardApproval.prototype, "canTransfer", null); // dist/node/interfaces/update.js var import_tslib3 = require("tslib"); var import_o1js8 = require("o1js"); var NFTStandardUpdate = class extends import_o1js8.SmartContract { constructor() { super(...arguments); this.admin = (0, import_o1js8.State)(); } /** * Deploys the contract with initial settings. * @param props - Deployment properties including admin, upgradeAuthority, uri, canPause, and isPaused. */ async deploy(props) { await super.deploy(props); this.admin.set(props.admin); this.account.zkappUri.set(props.uri); this.account.permissions.set({ ...import_o1js8.Permissions.default(), setVerificationKey: import_o1js8.Permissions.VerificationKey.signature(), setPermissions: import_o1js8.Permissions.impossible() }); } /** * Ensures that the transaction is authorized by the contract owner. * @returns A signed `AccountUpdate` from the admin. */ async ensureOwnerSignature() { const admin = this.admin.getAndRequireEquals(); const adminUpdate = import_o1js8.AccountUpdate.createSigned(admin); adminUpdate.body.useFullCommitment = (0, import_o1js8.Bool)(true); return adminUpdate; } async canUpdate(collectionAddress, nftAddress, input, output) { await this.ensureOwnerSignature(); return (0, import_o1js8.Bool)(true); } }; (0, import_tslib3.__decorate)([ (0, import_o1js8.state)(import_o1js8.PublicKey), (0, import_tslib3.__metadata)("design:type", Object) ], NFTStandardUpdate.prototype, "admin", void 0); (0, import_tslib3.__decorate)([ import_o1js8.method.returns(import_o1js8.Bool), (0, import_tslib3.__metadata)("design:type", Function), (0, import_tslib3.__metadata)("design:paramtypes", [ import_o1js8.PublicKey, import_o1js8.PublicKey, NFTState, NFTState ]), (0, import_tslib3.__metadata)("design:returntype", Promise) ], NFTStandardUpdate.prototype, "canUpdate", null); // dist/node/admin/advanced.js var import_upgradable = require("@silvana-one/upgradable"); var AdminData = class _AdminData extends (0, import_o1js9.Struct)({ /** Indicates whether the contract can be paused. */ canPause: import_o1js9.Bool, /** Indicates whether the contract is currently paused. */ isPaused: import_o1js9.Bool, /** Indicates whether the contract can change the royalty fee. */ allowChangeRoyalty: import_o1js9.Bool, /** Indicates whether the contract can change the transfer fee. */ allowChangeTransferFee: import_o1js9.Bool, /** Indicates whether the contract can change the base URI. */ allowChangeBaseUri: import_o1js9.Bool, /** Indicates whether the contract can change the creator. */ allowChangeCreator: import_o1js9.Bool, /** Indicates whether the contract can change the admin. */ allowChangeAdmin: import_o1js9.Bool, /** Indicates whether the contract can change the name. */ allowChangeName: import_o1js9.Bool }) { static new(params = {}) { const { canPause, isPaused, allowChangeRoyalty, allowChangeTransferFee, allowChangeBaseUri, allowChangeCreator, allowChangeAdmin, allowChangeName } = params; return new _AdminData({ canPause: (0, import_o1js9.Bool)(canPause ?? true), isPaused: (0, import_o1js9.Bool)(isPaused ?? false), allowChangeRoyalty: (0, import_o1js9.Bool)(allowChangeRoyalty ?? false), allowChangeTransferFee: (0, import_o1js9.Bool)(allowChangeTransferFee ?? false), allowChangeBaseUri: (0, import_o1js9.Bool)(allowChangeBaseUri ?? false), allowChangeCreator: (0, import_o1js9.Bool)(allowChangeCreator ?? false), allowChangeAdmin: (0, import_o1js9.Bool)(allowChangeAdmin ?? false), allowChangeName: (0, import_o1js9.Bool)(allowChangeName ?? false) }); } /** * Packs the pause data into a `Field`. * @returns A `Field` representing the packed pause data. */ pack() { return import_o1js9.Field.fromBits([ this.isPaused, this.canPause, this.allowChangeRoyalty, this.allowChangeTransferFee, this.allowChangeBaseUri, this.allowChangeCreator, this.allowChangeAdmin, this.allowChangeName ]); } /** * Unpacks a `Field` into `PauseData`. * @param field The `Field` to unpack. * @returns An instance of `PauseData`. */ static unpack(field) { const [isPaused, canPause, allowChangeRoyalty, allowChangeTransferFee, allowChangeBaseUri, allowChangeCreator, allowChangeAdmin, allowChangeName] = field.toBits(8); return new _AdminData({ canPause, isPaused, allowChangeRoyalty, allowChangeTransferFee, allowChangeBaseUri, allowChangeCreator, allowChangeAdmin, allowChangeName }); } static isPaused(field) { return field.toBits(8)[0]; } }; var NFTAdvancedAdminContractErrors = { contractIsPaused: "Contract is paused", notWhitelisted: "Address not whitelisted", senderNotWhitelisted: "Sender address not whitelisted", cannotMint: "Cannot mint", verificationKeyHashNotFound: "Verification key hash not found", cannotUpgradeVerificationKey: "Cannot upgrade verification key" }; function NFTAdvancedAdminContract(params) { const { upgradeContract } = params; class NFTAdvancedAdmin2 extends import_o1js9.SmartContract { constructor() { super(...arguments); this.admin = (0, import_o1js9.State)(); this.upgradeAuthority = (0, import_o1js9.State)(); this.whitelist = (0, import_o1js9.State)(); this.data = (0, import_o1js9.State)(); this.events = { /** Emitted when the contract's verification key is upgraded. */ upgradeVerificationKey: import_o1js9.Field, /** Emitted when the contract is paused. */ pause: PauseEvent, /** Emitted when the contract is resumed. */ resume: PauseEvent, /** Emitted when ownership of the contract changes. */ ownershipChange: OwnershipChangeEvent, /** Emitted when the whitelist is updated. */ updateWhitelist: import_storage3.Whitelist }; } /** * Deploys the `NFTWhitelistedAdmin` contract with the provided initial settings. * @param props Deployment properties. */ async deploy(props) { await super.deploy(props); this.admin.set(props.admin); this.upgradeAuthority.set(props.upgradeAuthority); this.whitelist.set(props.whitelist); this.data.set(props.adminData.pack()); this.account.zkappUri.set(props.uri); this.account.permissions.set({ ...import_o1js9.Permissions.default(), // Allow the upgrade authority to set the verification key // even when there is no protocol upgrade setVerificationKey: import_o1js9.Permissions.VerificationKey.proofDuringCurrentVersion(), setPermissions: import_o1js9.Permissions.impossible(), access: import_o1js9.Permissions.proof(), send: import_o1js9.Permissions.proof(), setZkappUri: import_o1js9.Permissions.impossible(), setTokenSymbol: import_o1js9.Permissions.impossible() }); } /** * Ensures that the transaction is authorized by the contract owner. * @returns An `AccountUpdate` representing the admin's signed transaction. */ async ensureOwnerSignature() { const admin = this.admin.getAndRequireEquals(); const adminUpdate = import_o1js9.AccountUpdate.createSigned(admin); adminUpdate.body.useFullCommitment = (0, import_o1js9.Bool)(true); return adminUpdate; } /** Gets the upgrade contract constructor. */ get getUpgradeContractConstructor() { return upgradeContract; } /** * Retrieves the `UpgradeAuthorityBase` contract instance. * @returns An instance of the upgrade authority contract. */ async getUpgradeContract() { return new this.getUpgradeContractConstructor(this.upgradeAuthority.getAndRequireEquals()); } /** * Upgrades the contract's verification key using the Upgrade Authority Contract. * @param vk The new verification key. */ async upgradeVerificationKey(vk) { await this.ensureOwnerSignature(); const upgradeContract2 = await this.getUpgradeContract(); const previousVerificationKeyHash = import_o1js9.Provable.witness(import_o1js9.Field, () => { const account = import_o1js9.Mina.getAccount(this.address); const vkHash = account.zkapp?.verificationKey?.hash; if (!vkHash) { throw Error(NFTAdvancedAdminContractErrors.verificationKeyHashNotFound); } return vkHash; }); const data = new import_upgradable.VerificationKeyUpgradeData({ address: this.address, tokenId: this.tokenId, previousVerificationKeyHash, newVerificationKeyHash: vk.hash }); const upgradeAuthorityAnswer = await upgradeContract2.verifyUpgradeData(data); upgradeAuthorityAnswer.isVerified.assertTrue(NFTAdvancedAdminContractErrors.cannotUpgradeVerificationKey); this.account.verificationKey.set(vk); this.upgradeAuthority.set(upgradeAuthorityAnswer.nextUpgradeAuthority.orElse(this.upgradeAuthority.getAndRequireEquals())); this.emitEvent("upgradeVerificationKey", vk.hash); } /** * Determines if the minting request can proceed by checking if the owner and sender are whitelisted. * @param mintRequest The minting request parameters. * @returns A `MintParamsOption` indicating if minting is allowed. */ async canMint(mintRequest) { AdminData.isPaused(this.data.getAndRequireEquals()).assertFalse(NFTAdvancedAdminContractErrors.contractIsPaused); const whitelist = this.whitelist.getAndRequireEquals(); const ownerAmount = await whitelist.getWhitelistedAmount(mintRequest.owner); ownerAmount.isSome.assertTrue(NFTAdvancedAdminContractErrors.notWhitelisted); const sender = this.sender.getUnconstrained(); const senderUpdate = import_o1js9.AccountUpdate.createSigned(sender); senderUpdate.body.useFullCommitment = (0, import_o1js9.Bool)(true); const senderAmount = await whitelist.getWhitelistedAmount(sender); senderAmount.isSome.assertTrue(NFTAdvancedAdminContractErrors.senderNotWhitelisted); const mintParams = await import_o1js9.Provable.witnessAsync(MintParamsOption, async () => { return MintParamsOption.none(); }); return mintParams; } /** * Checks whether the NFT's state can be updated, ensuring the new owner is whitelisted. * @param input The current state of the NFT. * @param output The desired new state of the NFT. * @returns A `Bool` indicating whether the update is permitted. */ async canUpdate(input, output) { AdminData.isPaused(this.data.getAndRequireEquals()).assertFalse(NFTAdvancedAdminContractErrors.contractIsPaused); const whitelist = this.whitelist.getAndRequireEquals(); return (await whitelist.getWhitelistedAmount(output.owner)).isSome.and((await whitelist.getWhitelistedAmount(input.owner)).isSome); } /** * Verifies if the transfer between `from` and `to` addresses is allowed based on whitelist status. * @