import { Buffer } from 'buffer/index.js'; import { ContractTransactionMetadata, ContractUpdateTransactionWithSchema, CreateContractTransactionMetadata } from '../GenericContract.js'; import { Cursor } from '../deserializationHelpers.js'; import { type Base58String, BlockItemSummary, type HexString, type InvokeContractSuccessResult, RejectedReceive, type SmartContractTypeValues } from '../types.js'; import * as AccountAddress from '../types/AccountAddress.js'; import * as ContractAddress from '../types/ContractAddress.js'; import * as ContractEvent from '../types/ContractEvent.js'; import * as EntrypointName from '../types/EntrypointName.js'; export declare namespace CIS2 { /** * Union between `ContractAddress` and an account address `AccountAddress`. */ type Address = ContractAddress.Type | AccountAddress.Type; /** * A Token ID that uniquely identifies the CIS-2 Token. */ type TokenId = HexString; /** * An amount of CIS-2 tokens. */ type TokenAmount = bigint; /** * A Token Address, that contains both a Contract Address and the unique * CIS-2 Token ID. */ type TokenAddress = { contract: ContractAddress.Type; id: TokenId; }; /** * A contract address along with the name of the hook to be triggered when receiving a CIS-2 transfer. */ type ContractReceiver = { /** Contract address to receive tokens */ address: ContractAddress.Type; /** Name of the entrypoint to be called on receiver contract. This is only the name of the function, NOT including the contract name */ hookName: EntrypointName.Type; }; /** * Union between an account address represented by an `AccountAddress` and a `ContractReceiver`. */ type Receiver = AccountAddress.Type | ContractReceiver; /** * Data needed to perform a "transfer" invocation according to the CIS-2 standard. */ type Transfer = { /** The ID of the token to transfer */ tokenId: HexString; /** The amount of tokens to transfer, cannot be negative. */ tokenAmount: TokenAmount; /** The address to transfer from */ from: Address; /** The receiver of the transfer */ to: Receiver; /** Optional additional data to include in the transaction */ data?: HexString; }; /** * Data needed to perform an "updateOperator" invocation according to the CIS-2 standard. */ type UpdateOperator = { /** The type of the update */ type: 'add' | 'remove'; /** The address be used for the operator update */ address: Address; }; /** * Metadata necessary for CIS-2 transactions */ type TransactionMetadata = ContractTransactionMetadata; /** * Metadata necessary for creating a {@link UpdateTransaction} */ type CreateTransactionMetadata = CreateContractTransactionMetadata; /** * Data needed for CIS-2 "balanceOf" query. */ type BalanceOfQuery = { /** The ID of the token to query */ tokenId: HexString; /** The address to query balance for */ address: Address; }; /** * Structure for holding metadata URL response from "tokenMetadata" query. */ type MetadataUrl = { /** The URL of the metadata */ url: string; /** An optional checksum for the URL */ hash?: HexString; }; /** * Data needed for CIS-2 "operatorOf" query. */ type OperatorOfQuery = { /** The owner address for the query */ owner: Address; /** The address to check whether it is an operator of `owner` */ address: Address; }; /** * An update transaction without header. This is useful for sending through a wallet, which supplies the header information. */ type UpdateTransaction = ContractUpdateTransactionWithSchema; /** * The type of a CIS-2 event. * @see {@linkcode Event} */ enum EventType { Transfer = 0, Mint = 1, Burn = 2, UpdateOperatorOf = 3, TokenMetadata = 4, Custom = 5 } /** * A CIS-2 transfer event. */ type TransferEvent = { /** The type of the event */ type: EventType.Transfer; /** The ID of the token transferred */ tokenId: TokenId; /** The amount of tokens transferred */ tokenAmount: TokenAmount; /** The address the tokens were transferred from */ from: Address; /** The address the tokens were transferred to */ to: Address; }; /** * A CIS-2 mint event. */ type MintEvent = { /** The type of the event */ type: EventType.Mint; /** The ID of the token minted */ tokenId: TokenId; /** The amount of tokens minted */ tokenAmount: TokenAmount; /** The address the tokens were minted for */ owner: Address; }; /** * A CIS-2 burn event. */ type BurnEvent = { /** The type of the event */ type: EventType.Burn; /** The ID of the token burned */ tokenId: TokenId; /** The amount of tokens burned */ tokenAmount: TokenAmount; /** The address the tokens were burned for */ owner: Address; }; /** * A CIS-2 update operator event. */ type UpdateOperatorEvent = { /** The type of the event */ type: EventType.UpdateOperatorOf; /** The operator update data */ updateOperatorData: UpdateOperator; /** The owner address for the updated operator */ owner: Address; }; /** * A CIS-2 token metadata event. */ type TokenMetadataEvent = { /** The type of the event */ type: EventType.TokenMetadata; /** The ID of the token for which the metadata was updated */ tokenId: TokenId; /** The updated metadata URL */ metadataUrl: MetadataUrl; }; /** * A custom event outside CIS-2. */ type CustomEvent = { /** The type of the event */ type: EventType.Custom; /** The raw data of the custom event */ data: Uint8Array; }; /** * A CIS-2 event. */ type Event = TransferEvent | MintEvent | BurnEvent | UpdateOperatorEvent | TokenMetadataEvent | CustomEvent; /** * A CIS-2 event that is not a {@linkcode CustomEvent}. * @see {@linkcode Event} */ type NonCustomEvent = Exclude; /** * The type of a CIS-2 rejection error. * @see {@linkcode RejectionError} */ enum ErrorType { InvalidTokenId = 0, InsufficientFunds = 1, Unauthorized = 2, Custom = 3 } /** * An invalid token CIS-2 rejection error. */ type InvalidTokenIdError = { /** The type of the error */ type: ErrorType.InvalidTokenId; /** The error tag specified in the CIS-2 standard */ tag: -42000001; }; /** * An insufficient funds CIS-2 rejection error. */ type InsufficientFundsError = { /** The type of the error */ type: ErrorType.InsufficientFunds; /** The error tag specified in the CIS-2 standard */ tag: -42000002; }; /** * An unauthorized CIS-2 rejection error. */ type UnauthorizedError = { /** The type of the error */ type: ErrorType.Unauthorized; /** The error tag specified in the CIS-2 standard */ tag: -42000003; }; /** * A rejection error outside of CIS-2. */ type CustomError = { /** The type of the error */ type: ErrorType.Custom; /** A custom error tag */ tag: number; }; /** * A CIS-2 rejection error. */ type RejectionError = InvalidTokenIdError | InsufficientFundsError | UnauthorizedError | CustomError; /** * Structure of a JSON-formatted address parameter. */ type AddressParamJson = { Account: [Base58String]; } | { Contract: [{ index: number; subindex: number; }]; }; /** * Structure of JSON formatted receiver parameter */ type ReceiverParamJson = { Account: [Base58String]; } | { Contract: [{ index: number; subindex: number; }, string]; }; /** * Structure of JSON formatted parameter used for CIS-2 "transfer" transactions */ type TransferParamJson = { token_id: HexString; amount: string; from: AddressParamJson; to: ReceiverParamJson; data: HexString; }; /** * Structure of JSON formatted parameter used for CIS-2 "updateOperator" transactions */ type UpdateOperatorParamJson = { update: { Add: Record; } | { Remove: Record; }; operator: AddressParamJson; }; } export declare function serializeAccountAddress(address: AccountAddress.Type): Uint8Array; /** * Serializes {@link ContractAddress} into bytes compatible with smart contract parameter deserialization * * @param {ContractAddress} address - The address to serialize * * @returns {Buffer} the address serialized to bytes */ export declare function serializeContractAddress(address: ContractAddress.Type): Uint8Array; /** * Serializes {@link EntrypointName.Type} contract entrypoint into bytes, prefixed by a 2-byte length * * @param {EntrypointName.Type} hook - the entrypoint to serialize * * @returns {Uint8Array} the entrypoint serialized to bytes */ export declare function serializeReceiveHookName(hook: EntrypointName.Type): Uint8Array; /** * Serializes a list of {@link CIS2.Transfer} data objects according to the CIS-2 standard. * * @param {CIS2.Transfer[]} transfers - A list of {@link CIS2.Transfer} objects * * @example * const transfers = [{ tokenId: ''; tokenAmount: 100n; from: '3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi', to: '3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi', data: '48656c6c6f20776f726c6421'; }]; * const bytes = serializeCIS2Transfers(transfers); */ export declare const serializeCIS2Transfers: (input: CIS2.Transfer[]) => Buffer; /** * Serializes a list of {@link CIS2.UpdateOperator} data objects according to the CIS-2 standard. * * @param {CIS2.UpdateOperator[]} updates - A list of {@link CIS2.UpdateOperator} objects * * @example * const updates = [{ * type: 'add', * address: '3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi' }]; * const bytes = serializeCIS2UpdateOperators(updates); */ export declare const serializeCIS2UpdateOperators: (input: CIS2.UpdateOperator[]) => Buffer; /** * Serializes a list of {@link CIS2.BalanceOfQuery} data objects according to the CIS-2 standard. * * @param {CIS2.BalanceOfQuery[]} queries - A list of {@link CIS2.BalanceOfQuery} objects * * @example * const queries = [{tokenId: '', address: '3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi'}]; * const bytes = serializeCIS2BalanceOfQueries(queries); */ export declare const serializeCIS2BalanceOfQueries: (input: CIS2.BalanceOfQuery[]) => Buffer; /** * Deserializes response of CIS-2 balanceOf query according to CIS-2 standard. * * @param {HexString} value - The hex string value to deserialize * * @returns {TokenAmount[]} A list of token balances. */ export declare const deserializeCIS2BalanceOfResponse: (value: string) => bigint[]; /** * Serializes a list of {@link HexString} token ID's according to the CIS-2 standard. * * @param {HexString[]} tokenIds - A list of {@link HexString} values * * @example * const tokenIds = ['', '01', 'e2']; * const bytes = serializeCIS2TokenIds(tokenIds); */ export declare const serializeCIS2TokenIds: (input: string[]) => Buffer; /** * Serializes {@link CIS2.MetadataUrl} metadata URL into bytes * * @param {CIS2.MetadataUrl} metadataUrl - the metadata URL to serialize * * @returns {Buffer} the metadata URL serialized to bytes */ export declare function serializeCIS2MetadataUrl({ url, hash }: CIS2.MetadataUrl): Buffer; /** * Attempts to deserialize some data into a {@link CIS2.MetadataUrl} * * @param {Cursor | HexString} value - the value to deserialize * * @throws if deserialization fails * * @returns {CIS2.MetadataUrl} the metadata URL */ export declare function deserializeCIS2MetadataUrl(value: Cursor | HexString): CIS2.MetadataUrl; /** * Deserializes response of CIS-2 tokenMetadata query according to CIS-2 standard. * * @param {HexString} value - The hex string value to deserialize * * @returns {CIS2MetadataUrl[]} A list of metadata URL objects. */ export declare const deserializeCIS2TokenMetadataResponse: (value: string) => CIS2.MetadataUrl[]; /** * Parses a token address from a Base58-string. Will throw if the Base58 * encoding is not a valid token address. * * @param str A Base58 encoded token address * @returns A parsed token address */ export declare function tokenAddressFromBase58(str: Base58String): CIS2.TokenAddress; /** * Returns the Base58-encoding of the given CIS2 Token Address. * * @param tokenAddress A token address to convert into the base58-string format * @returns The base58-formatted string */ export declare function tokenAddressToBase58(tokenAddress: CIS2.TokenAddress): Base58String; /** * Serializes a list of {@link CIS2.OperatorOfQuery} queries according to the CIS-2 standard. * * @param {CIS2.OperatorOfQuery[]} queries - A list of {@link CIS2.OperatorOfQuery} objects * * @example * const queries = [{owner: "3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi", address: {index: 123n, subindex: 0n}}]; * const bytes = serializeCIS2OperatorOfQueries(tokenIds); */ export declare const serializeCIS2OperatorOfQueries: (input: CIS2.OperatorOfQuery[]) => Buffer; /** * Deserializes response of CIS-2 operatorOf query according to CIS-2 standard. * * @param {HexString} value - The hex string value to deserialize * * @returns {boolean[]} A list of boolean values. */ export declare const deserializeCIS2OperatorOfResponse: (value: string) => boolean[]; /** * Format {@link CIS2.UpdateOperator} as JSON compatible with serialization wtih corresponding schema. */ export declare function formatCIS2UpdateOperator(input: CIS2.UpdateOperator): CIS2.UpdateOperatorParamJson; /** * Format {@link CIS2.Transfer} as JSON compatible with serialization wtih corresponding schema. */ export declare function formatCIS2Transfer(input: CIS2.Transfer): CIS2.TransferParamJson; /** * Deserializes a CIS-2 event according to the CIS-2 standard. * * @param {ContractEvent.Type} event - The event to deserialize * * @returns {CIS2.Event} The deserialized event */ export declare function deserializeCIS2Event(event: ContractEvent.Type): CIS2.Event; /** * Deserializes a successful contract invokation to a list of CIS-2 events according to the CIS-2 standard. * * @param {InvokeContractSuccessResult} result - The contract invokation result to deserialize * * @returns {CIS2.NonCustomEvent[]} The deserialized events */ export declare function deserializeCIS2EventsFromInvokationResult(result: InvokeContractSuccessResult): CIS2.NonCustomEvent[]; /** * Parses the {@linkcode CIS2.RejectionError} from a rejected receive error. * * @param {RejectedReceive} rejection - The rejected receive error * * @returns {CIS2.RejectionError} The parsed rejection error */ export declare function parseCIS2RejectionError(rejection: RejectedReceive): CIS2.RejectionError; /** * Deserializes all CIS-2 events (skipping custom events) from a {@linkcode BlockItemSummary}. * * @param {BlockItemSummary} summary - The summary to deserialize * * @returns {CIS2.NonCustomEvent[]} The deserialized events */ export declare function deserializeCIS2EventsFromSummary(summary: BlockItemSummary): CIS2.NonCustomEvent[];