@metamask/snaps-sdk
Version:
A library containing the core functionality for building MetaMask Snaps
30 lines • 1.14 kB
JavaScript
import { array, size, literal, number, object, refine, string, record, nullable, optional } from "@metamask/superstruct";
import { assert, CaipAssetTypeStruct } from "@metamask/utils";
export const FungibleAssetUnitStruct = object({
name: optional(string()),
symbol: optional(string()),
decimals: number(),
});
export const AssetIconUrlStruct = refine(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
assert(url.protocol === 'https:' ||
value.startsWith('data:image/svg+xml;base64,'));
return true;
}
catch {
return 'Invalid URL';
}
});
export const FungibleAssetMetadataStruct = object({
name: optional(string()),
symbol: optional(string()),
fungible: literal(true),
iconUrl: AssetIconUrlStruct,
units: size(array(FungibleAssetUnitStruct), 1, Infinity),
});
export const OnAssetsLookupResponseStruct = object({
assets: record(CaipAssetTypeStruct, nullable(FungibleAssetMetadataStruct)),
});
//# sourceMappingURL=assets-lookup.mjs.map