-
Notifications
You must be signed in to change notification settings - Fork 55
/
Asset.ts
112 lines (104 loc) · 3.05 KB
/
Asset.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { Hash28ByteBase16, OpaqueString, assertIsHexString, typedBech32 } from '../util';
import { InvalidStringError } from '../..';
import { TransactionId } from './Transaction';
export type AssetId = OpaqueString<'AssetId'>;
export type AssetName = OpaqueString<'AssetName'>;
export const AssetName = (value: string): AssetName => {
if (value.length > 0) {
assertIsHexString(value);
if (value.length > 64) {
throw new InvalidStringError('too long');
}
}
return value as unknown as AssetName;
};
/**
* @param {string} value concatenated PolicyId and AssetName
* @throws InvalidStringError
*/
export const AssetId = (value: string): AssetId => {
assertIsHexString(value);
if (value.length > 120) throw new InvalidStringError('too long');
if (value.length < 56) throw new InvalidStringError('too short');
return value as unknown as AssetId;
};
export type PolicyId = Hash28ByteBase16<'PolicyId'>;
export const PolicyId = (value: string): PolicyId => Hash28ByteBase16(value);
/**
* Fingerprint of a native asset for human comparison
* See CIP-0014
*/
export type AssetFingerprint = OpaqueString<'AssetFingerprint'>;
export const AssetFingerprint = (value: string): AssetFingerprint => typedBech32(value, 'asset', 32);
/**
* Either on-chain or off-chain asset metadata
*
* CIP-0031
* https://github.com/cardano-foundation/CIPs/pull/137
*/
export interface AssetMetadata {
/**
* Asset name
*/
name?: string;
/**
* when present, field and overrides default ticker which is the asset name
*/
ticker?: string;
/**
* MUST be either https, ipfs, or data. logo MUST be a browser supported image format.
*/
logo?: string;
/**
* MUST be either https, ipfs, or data. logo MUST be a browser supported image format.
*/
icon?: string;
/**
* MUST be either https, ipfs, or data. logo MUST be a browser supported image format.
*/
image?: string;
/**
* https only url that refers to metadata stored offchain.
* The URL SHOULD use the project domain and
* MUST return authenticity metadata in either html or json format (see below)
*/
url?: string;
/**
* additional description that defines the usage of the token
*/
desc?: string;
/**
* how many decimal places should the token support? For ADA, this would be 6 e.g. 1 ADA is 10^6 Lovelace
*/
decimals?: number;
/**
* https only url that holds the metadata in the onchain format.
* The URL SHOULD use the project domain and MUST return the token metadata as described above
*/
ref?: string;
/**
* when not specified, version will default to `1.0`
*/
version?: '1.0';
/**
* Possibly: 'logo-[size]' or 'icon-[size]' where size is one of 16, 32, 64, 96, 128
*/
[key: string]: unknown;
}
export interface AssetMintOrBurn {
transactionId: TransactionId;
/**
* Positive = mint
* Negative = burn
*/
quantity: bigint;
}
export interface Asset {
assetId: AssetId;
policyId: PolicyId;
name: string;
fingerprint: AssetFingerprint;
quantity: bigint;
history: AssetMintOrBurn[];
metadata?: AssetMetadata;
}