-
Notifications
You must be signed in to change notification settings - Fork 54
/
types.ts
59 lines (53 loc) · 1.54 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-disable wrap-regex */
import { Cardano, InvalidStringError } from '@cardano-sdk/core';
export type Uri = Cardano.util.OpaqueString<'Uri'>;
export const Uri = (uri: string) => {
if (/^[a-z]+:\/\/.+/.test(uri)) {
return uri as unknown as Uri;
}
throw new InvalidStringError(
'Expected Uri to start with "[protocol]://", where protocol is usually "https" or "ipfs"'
);
};
export type ImageMediaType = Cardano.util.OpaqueString<'ImageMediaType'>;
export const ImageMediaType = (mediaType: string) => {
if (/^image\/.+$/.test(mediaType)) {
return mediaType as unknown as ImageMediaType;
}
throw new InvalidStringError('Expected media type to be "image/*"');
};
export type MediaType = Cardano.util.OpaqueString<'MediaType'>;
export const MediaType = (mediaType: string) => {
if (/^[a-z]+\/.+$/.test(mediaType)) {
return mediaType as unknown as MediaType;
}
throw new InvalidStringError('Expected media type to be "*/*"');
};
/**
* https://cips.cardano.org/cips/cip25/
*/
export interface NftMetadataFile {
name: string;
mediaType: MediaType;
src: Uri | Uri[];
otherProperties?: {
[key: string]: Cardano.Metadatum;
};
}
/**
* https://cips.cardano.org/cips/cip25/
*/
export interface NftMetadata {
name: string;
image: Uri | Uri[];
version: string;
mediaType?: ImageMediaType;
files?: NftMetadataFile[];
description?: string | string[];
otherProperties?: {
[key: string]: Cardano.Metadatum;
};
}
export interface NftMetadataProvider {
(asset: Cardano.Asset): Promise<NftMetadata | undefined>;
}