UNPKG

@metamask/snaps-sdk

Version:

A library containing the core functionality for building MetaMask Snaps

105 lines 5.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OnAssetsLookupResponseStruct = exports.AssetMetadataStruct = exports.NonFungibleAssetMetadataStruct = exports.NonFungibleAssetCollectionStruct = exports.FungibleAssetMetadataStruct = exports.AssetIconUrlStruct = exports.FungibleAssetUnitStruct = void 0; const superstruct_1 = require("@metamask/superstruct"); const utils_1 = require("@metamask/utils"); const internals_1 = require("../../internals/index.cjs"); exports.FungibleAssetUnitStruct = (0, superstruct_1.object)({ name: (0, superstruct_1.optional)((0, superstruct_1.string)()), symbol: (0, superstruct_1.optional)((0, superstruct_1.string)()), decimals: (0, superstruct_1.number)(), }); exports.AssetIconUrlStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Asset URL', (value) => { try { const url = new URL(value); // For now, we require asset URLs to either be base64 SVGs or remote HTTPS URLs (0, utils_1.assert)(url.protocol === 'https:' || value.startsWith('data:image/svg+xml;base64,')); return true; } catch { return 'Invalid URL'; } }); /** * A struct representing the metadata for a fungible asset. * * @property name - The name of the asset, if available. * @property symbol - The symbol of the asset, if available. * @property fungible - Indicates that this is a fungible asset. This is always ` * true` for fungible assets. * @property iconUrl - The URL of the asset's icon, which can be a base64 SVG or a remote HTTPS URL. * @property units - An array of units for the asset, each represented by {@link FungibleAssetUnitStruct}. */ exports.FungibleAssetMetadataStruct = (0, superstruct_1.object)({ name: (0, superstruct_1.optional)((0, superstruct_1.string)()), symbol: (0, superstruct_1.optional)((0, superstruct_1.string)()), fungible: (0, superstruct_1.literal)(true), iconUrl: exports.AssetIconUrlStruct, units: (0, superstruct_1.size)((0, superstruct_1.array)(exports.FungibleAssetUnitStruct), 1, Infinity), }); /** * A collection of non-fungible assets, which can be used to group * assets that share a common theme or creator. * * @property name - The name of the collection. * @property address - The CAIP-10 account ID of the collection's creator. * @property symbol - The symbol of the collection. * @property tokenCount - The number of tokens in the collection, if available. * @property creator - The CAIP-10 account ID of the collection's creator, if * available. * @property imageUrl - The URL of the collection's image. */ exports.NonFungibleAssetCollectionStruct = (0, superstruct_1.object)({ name: (0, superstruct_1.string)(), address: utils_1.CaipAccountIdStruct, symbol: (0, superstruct_1.string)(), tokenCount: (0, superstruct_1.optional)((0, superstruct_1.number)()), creator: (0, superstruct_1.optional)(utils_1.CaipAccountIdStruct), imageUrl: (0, superstruct_1.optional)(exports.AssetIconUrlStruct), }); /** * A struct representing the metadata for a non-fungible asset. * * @property fungible - Indicates that this is a non-fungible asset. * This is always `false` for non-fungible assets. * @property name - The name of the asset, if available. * @property symbol - The symbol of the asset, if available. * @property imageUrl - The URL of the asset's image, which can be a base64 SVG or a remote HTTPS URL. * @property description - A description of the asset, if available. * @property acquiredAt - The timestamp when the asset was acquired, if available. * @property isPossibleSpam - Indicates if the asset is possibly spam, if available. * @property attributes - Additional attributes of the asset, represented as a record of string keys and * string or number values. * @property collection - The collection the asset belongs to, if available. See {@link NonFungibleAssetCollectionStruct}. */ exports.NonFungibleAssetMetadataStruct = (0, superstruct_1.object)({ fungible: (0, superstruct_1.literal)(false), name: (0, superstruct_1.optional)((0, superstruct_1.string)()), symbol: (0, superstruct_1.optional)((0, superstruct_1.string)()), imageUrl: (0, superstruct_1.optional)(exports.AssetIconUrlStruct), description: (0, superstruct_1.optional)((0, superstruct_1.string)()), acquiredAt: (0, superstruct_1.optional)((0, superstruct_1.number)()), isPossibleSpam: (0, superstruct_1.optional)((0, superstruct_1.boolean)()), attributes: (0, superstruct_1.optional)((0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()]))), collection: (0, superstruct_1.optional)(exports.NonFungibleAssetCollectionStruct), }); /** * A struct representing the metadata for an asset, which can be either * {@link FungibleAssetMetadataStruct} or {@link NonFungibleAssetMetadataStruct}. */ exports.AssetMetadataStruct = (0, internals_1.selectiveUnion)((metadata) => { if ((0, utils_1.isObject)(metadata) && metadata.fungible) { return exports.FungibleAssetMetadataStruct; } return exports.NonFungibleAssetMetadataStruct; }); /** * A struct representing the response of the `onAssetsLookup` method. * * @property assets - An object containing a mapping between the CAIP-19 key and a metadata object or null. */ exports.OnAssetsLookupResponseStruct = (0, superstruct_1.object)({ assets: (0, superstruct_1.record)(utils_1.CaipAssetTypeOrIdStruct, (0, superstruct_1.nullable)(exports.AssetMetadataStruct)), }); //# sourceMappingURL=assets-lookup.cjs.map