Data Objects
With Data Objects you can add data to a TokenScript. Data objects are in a format that allows efficient signing and onchain storage.
There will be a lot of cases where you want to integrate data in the TokenScript. This can be some other file describing a function, an image file for a logo, a signed file to attest identity, a set of information and much more.
Data objects are defined by <asnx:module> in TokenScript XML markup. TokenScript uses DER-encoded data in a modified ASN.1 format, which is also used for SSL certificates or as X.509 like for the Estonian e-residency.
Data objects can be stored offchain as a file on the wallet device, or onchain as part of a smart contract.
Data Structure
TokenScript created its own format for DataObjects, relying on well established technology. The data is structured in a way that it can be put on the blockchain with low gas costs, but also used offchain. It is designed to be interoperable, extensible and longevitable.
Other than JSON data objects, the data is separated from the scheme. It consists of pure data. The scheme for the data is transferred offchain. The data is encoded in a string of bytes, separated by structural bytes according to standard DER encoding rules. To be used in TokenScript the data is usually written in ASN.X, an XML scheme language.
This data structure has several advantages. Compared with a JSON object it reduces gas cost by more than 50%. As a string of DER-encoded bytes it is useful for signing, like for an attestation. This data structure has also a better interoperability than JSON, and it can be easily extended.
Using Data Objects
Data objects can be used in multiple ways: They can transport information about the token, like a ticket number or the date of a soccer match or even a icon or a picture. They can also be the data to be signed for an attestation to proof identity or ownership. Finally, they can carry more complex operational information, like a blueprint for smart contract transactions or a key to interact with a third party API.
Data objects can be used onchain. They can be part of a smart contract and be downloaded from a blockchain, for example, to get the data needed to start an attestation process. However, in most cases the data doesn't need to be onchain.
For example, when an event organiser issues thousands of ticket, the tickets don’t need to be onchain. It is enough when the tickets are data objects ascribed to an Ethereum address and signed by the issuer. They can be just a data object. However, when the tickets are sold and transferred, the data objects can be used to create an Ethereum transaction which proof that the ticket is valid.