@chillwhales/lsp4 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +119 -316
- package/dist/index.d.ts +119 -316
- package/dist/index.mjs +45 -11
- package/package.json +9 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,48 +1,25 @@
|
|
|
1
1
|
import * as _chillwhales_lsp2 from '@chillwhales/lsp2';
|
|
2
2
|
import { Image } from '@chillwhales/lsp2';
|
|
3
|
+
import { ImageSize } from '@chillwhales/utils';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Asset attribute schema
|
|
7
8
|
* Supports string, number, and boolean attribute types
|
|
8
9
|
*/
|
|
9
|
-
declare const attributesSchema: z.ZodDiscriminatedUnion<
|
|
10
|
+
declare const attributesSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
10
11
|
key: z.ZodString;
|
|
11
12
|
value: z.ZodString;
|
|
12
13
|
type: z.ZodLiteral<"string">;
|
|
13
|
-
},
|
|
14
|
-
type: "string";
|
|
15
|
-
value: string;
|
|
16
|
-
key: string;
|
|
17
|
-
}, {
|
|
18
|
-
type: "string";
|
|
19
|
-
value: string;
|
|
20
|
-
key: string;
|
|
21
|
-
}>, z.ZodObject<{
|
|
14
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
22
15
|
key: z.ZodString;
|
|
23
|
-
value: z.
|
|
16
|
+
value: z.ZodString;
|
|
24
17
|
type: z.ZodLiteral<"number">;
|
|
25
|
-
},
|
|
26
|
-
type: "number";
|
|
27
|
-
value: string;
|
|
28
|
-
key: string;
|
|
29
|
-
}, {
|
|
30
|
-
type: "number";
|
|
31
|
-
value: string;
|
|
32
|
-
key: string;
|
|
33
|
-
}>, z.ZodObject<{
|
|
18
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
34
19
|
key: z.ZodString;
|
|
35
20
|
value: z.ZodBoolean;
|
|
36
21
|
type: z.ZodLiteral<"boolean">;
|
|
37
|
-
},
|
|
38
|
-
type: "boolean";
|
|
39
|
-
value: boolean;
|
|
40
|
-
key: string;
|
|
41
|
-
}, {
|
|
42
|
-
type: "boolean";
|
|
43
|
-
value: boolean;
|
|
44
|
-
key: string;
|
|
45
|
-
}>]>;
|
|
22
|
+
}, z.core.$strip>], "type">;
|
|
46
23
|
/**
|
|
47
24
|
* LSP4 Digital Asset metadata schema
|
|
48
25
|
* Full metadata structure for LSP7/LSP8 tokens
|
|
@@ -54,319 +31,74 @@ declare const lsp4MetadataSchema: z.ZodObject<{
|
|
|
54
31
|
links: z.ZodArray<z.ZodObject<{
|
|
55
32
|
title: z.ZodString;
|
|
56
33
|
url: z.ZodString;
|
|
57
|
-
},
|
|
58
|
-
url: string;
|
|
59
|
-
title: string;
|
|
60
|
-
}, {
|
|
61
|
-
url: string;
|
|
62
|
-
title: string;
|
|
63
|
-
}>, "many">;
|
|
34
|
+
}, z.core.$strip>>;
|
|
64
35
|
icon: z.ZodArray<z.ZodObject<{
|
|
65
36
|
url: z.ZodString;
|
|
66
37
|
width: z.ZodNumber;
|
|
67
38
|
height: z.ZodNumber;
|
|
68
|
-
verification: z.ZodDiscriminatedUnion<
|
|
39
|
+
verification: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
69
40
|
data: z.ZodString;
|
|
70
|
-
method: z.ZodEnum<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}, {
|
|
75
|
-
method:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
41
|
+
method: z.ZodEnum<{
|
|
42
|
+
"keccak256(utf8)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8;
|
|
43
|
+
"keccak256(bytes)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
44
|
+
}>;
|
|
45
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
46
|
+
method: z.ZodEnum<{
|
|
47
|
+
ecdsa: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
48
|
+
}>;
|
|
79
49
|
data: z.ZodString;
|
|
80
50
|
source: z.ZodString;
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
data: string;
|
|
84
|
-
source: string;
|
|
85
|
-
}, {
|
|
86
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
87
|
-
data: string;
|
|
88
|
-
source: string;
|
|
89
|
-
}>]>;
|
|
90
|
-
}, "strip", z.ZodTypeAny, {
|
|
91
|
-
url: string;
|
|
92
|
-
width: number;
|
|
93
|
-
height: number;
|
|
94
|
-
verification: {
|
|
95
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
96
|
-
data: string;
|
|
97
|
-
} | {
|
|
98
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
99
|
-
data: string;
|
|
100
|
-
source: string;
|
|
101
|
-
};
|
|
102
|
-
}, {
|
|
103
|
-
url: string;
|
|
104
|
-
width: number;
|
|
105
|
-
height: number;
|
|
106
|
-
verification: {
|
|
107
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
108
|
-
data: string;
|
|
109
|
-
} | {
|
|
110
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
111
|
-
data: string;
|
|
112
|
-
source: string;
|
|
113
|
-
};
|
|
114
|
-
}>, "many">;
|
|
51
|
+
}, z.core.$strip>], "method">;
|
|
52
|
+
}, z.core.$strip>>;
|
|
115
53
|
images: z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
116
54
|
url: z.ZodString;
|
|
117
55
|
width: z.ZodNumber;
|
|
118
56
|
height: z.ZodNumber;
|
|
119
|
-
verification: z.ZodDiscriminatedUnion<
|
|
57
|
+
verification: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
120
58
|
data: z.ZodString;
|
|
121
|
-
method: z.ZodEnum<
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}, {
|
|
126
|
-
method:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
59
|
+
method: z.ZodEnum<{
|
|
60
|
+
"keccak256(utf8)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8;
|
|
61
|
+
"keccak256(bytes)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
62
|
+
}>;
|
|
63
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
64
|
+
method: z.ZodEnum<{
|
|
65
|
+
ecdsa: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
66
|
+
}>;
|
|
130
67
|
data: z.ZodString;
|
|
131
68
|
source: z.ZodString;
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
data: string;
|
|
135
|
-
source: string;
|
|
136
|
-
}, {
|
|
137
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
138
|
-
data: string;
|
|
139
|
-
source: string;
|
|
140
|
-
}>]>;
|
|
141
|
-
}, "strip", z.ZodTypeAny, {
|
|
142
|
-
url: string;
|
|
143
|
-
width: number;
|
|
144
|
-
height: number;
|
|
145
|
-
verification: {
|
|
146
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
147
|
-
data: string;
|
|
148
|
-
} | {
|
|
149
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
150
|
-
data: string;
|
|
151
|
-
source: string;
|
|
152
|
-
};
|
|
153
|
-
}, {
|
|
154
|
-
url: string;
|
|
155
|
-
width: number;
|
|
156
|
-
height: number;
|
|
157
|
-
verification: {
|
|
158
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
159
|
-
data: string;
|
|
160
|
-
} | {
|
|
161
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
162
|
-
data: string;
|
|
163
|
-
source: string;
|
|
164
|
-
};
|
|
165
|
-
}>, "many">, "many">;
|
|
69
|
+
}, z.core.$strip>], "method">;
|
|
70
|
+
}, z.core.$strip>>>;
|
|
166
71
|
assets: z.ZodArray<z.ZodObject<{
|
|
167
72
|
url: z.ZodString;
|
|
168
73
|
fileType: z.ZodString;
|
|
169
|
-
verification: z.ZodDiscriminatedUnion<
|
|
74
|
+
verification: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
170
75
|
data: z.ZodString;
|
|
171
|
-
method: z.ZodEnum<
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}, {
|
|
176
|
-
method:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
76
|
+
method: z.ZodEnum<{
|
|
77
|
+
"keccak256(utf8)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8;
|
|
78
|
+
"keccak256(bytes)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
79
|
+
}>;
|
|
80
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
81
|
+
method: z.ZodEnum<{
|
|
82
|
+
ecdsa: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
83
|
+
}>;
|
|
180
84
|
data: z.ZodString;
|
|
181
85
|
source: z.ZodString;
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
source: string;
|
|
186
|
-
}, {
|
|
187
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
188
|
-
data: string;
|
|
189
|
-
source: string;
|
|
190
|
-
}>]>;
|
|
191
|
-
}, "strip", z.ZodTypeAny, {
|
|
192
|
-
url: string;
|
|
193
|
-
verification: {
|
|
194
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
195
|
-
data: string;
|
|
196
|
-
} | {
|
|
197
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
198
|
-
data: string;
|
|
199
|
-
source: string;
|
|
200
|
-
};
|
|
201
|
-
fileType: string;
|
|
202
|
-
}, {
|
|
203
|
-
url: string;
|
|
204
|
-
verification: {
|
|
205
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
206
|
-
data: string;
|
|
207
|
-
} | {
|
|
208
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
209
|
-
data: string;
|
|
210
|
-
source: string;
|
|
211
|
-
};
|
|
212
|
-
fileType: string;
|
|
213
|
-
}>, "many">;
|
|
214
|
-
attributes: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
86
|
+
}, z.core.$strip>], "method">;
|
|
87
|
+
}, z.core.$strip>>;
|
|
88
|
+
attributes: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
215
89
|
key: z.ZodString;
|
|
216
90
|
value: z.ZodString;
|
|
217
91
|
type: z.ZodLiteral<"string">;
|
|
218
|
-
},
|
|
219
|
-
type: "string";
|
|
220
|
-
value: string;
|
|
221
|
-
key: string;
|
|
222
|
-
}, {
|
|
223
|
-
type: "string";
|
|
224
|
-
value: string;
|
|
225
|
-
key: string;
|
|
226
|
-
}>, z.ZodObject<{
|
|
92
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
227
93
|
key: z.ZodString;
|
|
228
|
-
value: z.
|
|
94
|
+
value: z.ZodString;
|
|
229
95
|
type: z.ZodLiteral<"number">;
|
|
230
|
-
},
|
|
231
|
-
type: "number";
|
|
232
|
-
value: string;
|
|
233
|
-
key: string;
|
|
234
|
-
}, {
|
|
235
|
-
type: "number";
|
|
236
|
-
value: string;
|
|
237
|
-
key: string;
|
|
238
|
-
}>, z.ZodObject<{
|
|
96
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
239
97
|
key: z.ZodString;
|
|
240
98
|
value: z.ZodBoolean;
|
|
241
99
|
type: z.ZodLiteral<"boolean">;
|
|
242
|
-
},
|
|
243
|
-
|
|
244
|
-
value: boolean;
|
|
245
|
-
key: string;
|
|
246
|
-
}, {
|
|
247
|
-
type: "boolean";
|
|
248
|
-
value: boolean;
|
|
249
|
-
key: string;
|
|
250
|
-
}>]>, "many">;
|
|
251
|
-
}, "strip", z.ZodTypeAny, {
|
|
252
|
-
name: string | null;
|
|
253
|
-
description: string | null;
|
|
254
|
-
category: string | null;
|
|
255
|
-
links: {
|
|
256
|
-
url: string;
|
|
257
|
-
title: string;
|
|
258
|
-
}[];
|
|
259
|
-
icon: {
|
|
260
|
-
url: string;
|
|
261
|
-
width: number;
|
|
262
|
-
height: number;
|
|
263
|
-
verification: {
|
|
264
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
265
|
-
data: string;
|
|
266
|
-
} | {
|
|
267
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
268
|
-
data: string;
|
|
269
|
-
source: string;
|
|
270
|
-
};
|
|
271
|
-
}[];
|
|
272
|
-
images: {
|
|
273
|
-
url: string;
|
|
274
|
-
width: number;
|
|
275
|
-
height: number;
|
|
276
|
-
verification: {
|
|
277
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
278
|
-
data: string;
|
|
279
|
-
} | {
|
|
280
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
281
|
-
data: string;
|
|
282
|
-
source: string;
|
|
283
|
-
};
|
|
284
|
-
}[][];
|
|
285
|
-
assets: {
|
|
286
|
-
url: string;
|
|
287
|
-
verification: {
|
|
288
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
289
|
-
data: string;
|
|
290
|
-
} | {
|
|
291
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
292
|
-
data: string;
|
|
293
|
-
source: string;
|
|
294
|
-
};
|
|
295
|
-
fileType: string;
|
|
296
|
-
}[];
|
|
297
|
-
attributes: ({
|
|
298
|
-
type: "string";
|
|
299
|
-
value: string;
|
|
300
|
-
key: string;
|
|
301
|
-
} | {
|
|
302
|
-
type: "number";
|
|
303
|
-
value: string;
|
|
304
|
-
key: string;
|
|
305
|
-
} | {
|
|
306
|
-
type: "boolean";
|
|
307
|
-
value: boolean;
|
|
308
|
-
key: string;
|
|
309
|
-
})[];
|
|
310
|
-
}, {
|
|
311
|
-
name: string | null;
|
|
312
|
-
description: string | null;
|
|
313
|
-
category: string | null;
|
|
314
|
-
links: {
|
|
315
|
-
url: string;
|
|
316
|
-
title: string;
|
|
317
|
-
}[];
|
|
318
|
-
icon: {
|
|
319
|
-
url: string;
|
|
320
|
-
width: number;
|
|
321
|
-
height: number;
|
|
322
|
-
verification: {
|
|
323
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
324
|
-
data: string;
|
|
325
|
-
} | {
|
|
326
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
327
|
-
data: string;
|
|
328
|
-
source: string;
|
|
329
|
-
};
|
|
330
|
-
}[];
|
|
331
|
-
images: {
|
|
332
|
-
url: string;
|
|
333
|
-
width: number;
|
|
334
|
-
height: number;
|
|
335
|
-
verification: {
|
|
336
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
337
|
-
data: string;
|
|
338
|
-
} | {
|
|
339
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
340
|
-
data: string;
|
|
341
|
-
source: string;
|
|
342
|
-
};
|
|
343
|
-
}[][];
|
|
344
|
-
assets: {
|
|
345
|
-
url: string;
|
|
346
|
-
verification: {
|
|
347
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
348
|
-
data: string;
|
|
349
|
-
} | {
|
|
350
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
351
|
-
data: string;
|
|
352
|
-
source: string;
|
|
353
|
-
};
|
|
354
|
-
fileType: string;
|
|
355
|
-
}[];
|
|
356
|
-
attributes: ({
|
|
357
|
-
type: "string";
|
|
358
|
-
value: string;
|
|
359
|
-
key: string;
|
|
360
|
-
} | {
|
|
361
|
-
type: "number";
|
|
362
|
-
value: string;
|
|
363
|
-
key: string;
|
|
364
|
-
} | {
|
|
365
|
-
type: "boolean";
|
|
366
|
-
value: boolean;
|
|
367
|
-
key: string;
|
|
368
|
-
})[];
|
|
369
|
-
}>;
|
|
100
|
+
}, z.core.$strip>], "type">>;
|
|
101
|
+
}, z.core.$strip>;
|
|
370
102
|
|
|
371
103
|
/**
|
|
372
104
|
* LSP4 Inferred Types
|
|
@@ -376,6 +108,20 @@ declare const lsp4MetadataSchema: z.ZodObject<{
|
|
|
376
108
|
|
|
377
109
|
type LSP4Attribute = z.infer<typeof attributesSchema>;
|
|
378
110
|
type LSP4Metadata = z.infer<typeof lsp4MetadataSchema>;
|
|
111
|
+
/**
|
|
112
|
+
* Extended NFT metadata with optional token identification fields.
|
|
113
|
+
*
|
|
114
|
+
* Adds `tokenName`, `tokenIdFormat`, and `formattedTokenId` on top of
|
|
115
|
+
* standard LSP4 metadata for use with `getNftDisplayName`.
|
|
116
|
+
*/
|
|
117
|
+
interface NftMetadata extends LSP4Metadata {
|
|
118
|
+
/** Token collection name (e.g., "CoolCats") */
|
|
119
|
+
tokenName?: string;
|
|
120
|
+
/** Format of the token ID (e.g., "NUMBER", "STRING") */
|
|
121
|
+
tokenIdFormat?: string;
|
|
122
|
+
/** Pre-formatted token ID for display */
|
|
123
|
+
formattedTokenId?: string;
|
|
124
|
+
}
|
|
379
125
|
|
|
380
126
|
/**
|
|
381
127
|
* LSP4 Digital Asset Metadata Utilities
|
|
@@ -415,6 +161,63 @@ declare function getImageUrl(options: {
|
|
|
415
161
|
* @returns Display name string
|
|
416
162
|
*/
|
|
417
163
|
declare function getAssetDisplayName(metadata: LSP4Metadata): string;
|
|
164
|
+
/**
|
|
165
|
+
* Extract avatar image URL from Digital Asset metadata.
|
|
166
|
+
* Prefers icon, falls back to images. Optionally finds the closest image
|
|
167
|
+
* to target dimensions.
|
|
168
|
+
*
|
|
169
|
+
* @param metadata - Digital Asset (LSP7/LSP8) metadata
|
|
170
|
+
* @param parseUrl - Function to parse/transform the URL (e.g., IPFS gateway resolution)
|
|
171
|
+
* @param options - Optional target dimensions `{ width, height }`
|
|
172
|
+
* @returns Parsed URL or undefined if no image found
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* // Get first available image (prefers icon)
|
|
177
|
+
* getAssetImageUrl(asset, parseIpfsUrl)
|
|
178
|
+
*
|
|
179
|
+
* // Get image closest to 128×128
|
|
180
|
+
* getAssetImageUrl(asset, parseIpfsUrl, { width: 128, height: 128 })
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function getAssetImageUrl(metadata: LSP4Metadata, parseUrl: (url: string) => string, options?: Partial<ImageSize>): string | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* Extract avatar image URL from NFT metadata.
|
|
186
|
+
* Prefers images (usually more detailed), falls back to icon.
|
|
187
|
+
* Optionally finds the closest image to target dimensions.
|
|
188
|
+
*
|
|
189
|
+
* @param metadata - NFT (LSP8 token) metadata
|
|
190
|
+
* @param parseUrl - Function to parse/transform the URL (e.g., IPFS gateway resolution)
|
|
191
|
+
* @param options - Optional target dimensions `{ width, height }`
|
|
192
|
+
* @returns Parsed URL or undefined if no image found
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* // Get first available image (prefers full images)
|
|
197
|
+
* getNftImageUrl(nft, parseIpfsUrl)
|
|
198
|
+
*
|
|
199
|
+
* // Get image closest to 256×256
|
|
200
|
+
* getNftImageUrl(nft, parseIpfsUrl, { width: 256, height: 256 })
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
declare function getNftImageUrl(metadata: LSP4Metadata, parseUrl: (url: string) => string, options?: Partial<ImageSize>): string | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Get display name for NFT (LSP8 token).
|
|
206
|
+
* Includes token ID formatting (e.g., "TokenName #123").
|
|
207
|
+
*
|
|
208
|
+
* @param metadata - NFT metadata with optional token info
|
|
209
|
+
* @returns Display name string, possibly with token ID suffix
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* getNftDisplayName({ tokenName: "CoolCats", tokenIdFormat: "NUMBER", formattedTokenId: "42" })
|
|
214
|
+
* // => "CoolCats #42"
|
|
215
|
+
*
|
|
216
|
+
* getNftDisplayName({ tokenName: "Art" })
|
|
217
|
+
* // => "Art"
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
declare function getNftDisplayName(metadata: NftMetadata): string;
|
|
418
221
|
|
|
419
222
|
/**
|
|
420
223
|
* LSP4 Type Guards
|
|
@@ -431,5 +234,5 @@ declare function isAttributesSchema(obj: unknown): obj is z.infer<typeof attribu
|
|
|
431
234
|
*/
|
|
432
235
|
declare function isLsp4MetadataSchema(obj: unknown): obj is z.infer<typeof lsp4MetadataSchema>;
|
|
433
236
|
|
|
434
|
-
export { attributesSchema, getAssetDisplayName, getImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
|
435
|
-
export type { LSP4Attribute, LSP4Metadata };
|
|
237
|
+
export { attributesSchema, getAssetDisplayName, getAssetImageUrl, getImageUrl, getNftDisplayName, getNftImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
|
238
|
+
export type { LSP4Attribute, LSP4Metadata, NftMetadata };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,48 +1,25 @@
|
|
|
1
1
|
import * as _chillwhales_lsp2 from '@chillwhales/lsp2';
|
|
2
2
|
import { Image } from '@chillwhales/lsp2';
|
|
3
|
+
import { ImageSize } from '@chillwhales/utils';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Asset attribute schema
|
|
7
8
|
* Supports string, number, and boolean attribute types
|
|
8
9
|
*/
|
|
9
|
-
declare const attributesSchema: z.ZodDiscriminatedUnion<
|
|
10
|
+
declare const attributesSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
10
11
|
key: z.ZodString;
|
|
11
12
|
value: z.ZodString;
|
|
12
13
|
type: z.ZodLiteral<"string">;
|
|
13
|
-
},
|
|
14
|
-
type: "string";
|
|
15
|
-
value: string;
|
|
16
|
-
key: string;
|
|
17
|
-
}, {
|
|
18
|
-
type: "string";
|
|
19
|
-
value: string;
|
|
20
|
-
key: string;
|
|
21
|
-
}>, z.ZodObject<{
|
|
14
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
22
15
|
key: z.ZodString;
|
|
23
|
-
value: z.
|
|
16
|
+
value: z.ZodString;
|
|
24
17
|
type: z.ZodLiteral<"number">;
|
|
25
|
-
},
|
|
26
|
-
type: "number";
|
|
27
|
-
value: string;
|
|
28
|
-
key: string;
|
|
29
|
-
}, {
|
|
30
|
-
type: "number";
|
|
31
|
-
value: string;
|
|
32
|
-
key: string;
|
|
33
|
-
}>, z.ZodObject<{
|
|
18
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
34
19
|
key: z.ZodString;
|
|
35
20
|
value: z.ZodBoolean;
|
|
36
21
|
type: z.ZodLiteral<"boolean">;
|
|
37
|
-
},
|
|
38
|
-
type: "boolean";
|
|
39
|
-
value: boolean;
|
|
40
|
-
key: string;
|
|
41
|
-
}, {
|
|
42
|
-
type: "boolean";
|
|
43
|
-
value: boolean;
|
|
44
|
-
key: string;
|
|
45
|
-
}>]>;
|
|
22
|
+
}, z.core.$strip>], "type">;
|
|
46
23
|
/**
|
|
47
24
|
* LSP4 Digital Asset metadata schema
|
|
48
25
|
* Full metadata structure for LSP7/LSP8 tokens
|
|
@@ -54,319 +31,74 @@ declare const lsp4MetadataSchema: z.ZodObject<{
|
|
|
54
31
|
links: z.ZodArray<z.ZodObject<{
|
|
55
32
|
title: z.ZodString;
|
|
56
33
|
url: z.ZodString;
|
|
57
|
-
},
|
|
58
|
-
url: string;
|
|
59
|
-
title: string;
|
|
60
|
-
}, {
|
|
61
|
-
url: string;
|
|
62
|
-
title: string;
|
|
63
|
-
}>, "many">;
|
|
34
|
+
}, z.core.$strip>>;
|
|
64
35
|
icon: z.ZodArray<z.ZodObject<{
|
|
65
36
|
url: z.ZodString;
|
|
66
37
|
width: z.ZodNumber;
|
|
67
38
|
height: z.ZodNumber;
|
|
68
|
-
verification: z.ZodDiscriminatedUnion<
|
|
39
|
+
verification: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
69
40
|
data: z.ZodString;
|
|
70
|
-
method: z.ZodEnum<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}, {
|
|
75
|
-
method:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
41
|
+
method: z.ZodEnum<{
|
|
42
|
+
"keccak256(utf8)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8;
|
|
43
|
+
"keccak256(bytes)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
44
|
+
}>;
|
|
45
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
46
|
+
method: z.ZodEnum<{
|
|
47
|
+
ecdsa: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
48
|
+
}>;
|
|
79
49
|
data: z.ZodString;
|
|
80
50
|
source: z.ZodString;
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
data: string;
|
|
84
|
-
source: string;
|
|
85
|
-
}, {
|
|
86
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
87
|
-
data: string;
|
|
88
|
-
source: string;
|
|
89
|
-
}>]>;
|
|
90
|
-
}, "strip", z.ZodTypeAny, {
|
|
91
|
-
url: string;
|
|
92
|
-
width: number;
|
|
93
|
-
height: number;
|
|
94
|
-
verification: {
|
|
95
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
96
|
-
data: string;
|
|
97
|
-
} | {
|
|
98
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
99
|
-
data: string;
|
|
100
|
-
source: string;
|
|
101
|
-
};
|
|
102
|
-
}, {
|
|
103
|
-
url: string;
|
|
104
|
-
width: number;
|
|
105
|
-
height: number;
|
|
106
|
-
verification: {
|
|
107
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
108
|
-
data: string;
|
|
109
|
-
} | {
|
|
110
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
111
|
-
data: string;
|
|
112
|
-
source: string;
|
|
113
|
-
};
|
|
114
|
-
}>, "many">;
|
|
51
|
+
}, z.core.$strip>], "method">;
|
|
52
|
+
}, z.core.$strip>>;
|
|
115
53
|
images: z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
116
54
|
url: z.ZodString;
|
|
117
55
|
width: z.ZodNumber;
|
|
118
56
|
height: z.ZodNumber;
|
|
119
|
-
verification: z.ZodDiscriminatedUnion<
|
|
57
|
+
verification: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
120
58
|
data: z.ZodString;
|
|
121
|
-
method: z.ZodEnum<
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}, {
|
|
126
|
-
method:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
59
|
+
method: z.ZodEnum<{
|
|
60
|
+
"keccak256(utf8)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8;
|
|
61
|
+
"keccak256(bytes)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
62
|
+
}>;
|
|
63
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
64
|
+
method: z.ZodEnum<{
|
|
65
|
+
ecdsa: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
66
|
+
}>;
|
|
130
67
|
data: z.ZodString;
|
|
131
68
|
source: z.ZodString;
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
data: string;
|
|
135
|
-
source: string;
|
|
136
|
-
}, {
|
|
137
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
138
|
-
data: string;
|
|
139
|
-
source: string;
|
|
140
|
-
}>]>;
|
|
141
|
-
}, "strip", z.ZodTypeAny, {
|
|
142
|
-
url: string;
|
|
143
|
-
width: number;
|
|
144
|
-
height: number;
|
|
145
|
-
verification: {
|
|
146
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
147
|
-
data: string;
|
|
148
|
-
} | {
|
|
149
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
150
|
-
data: string;
|
|
151
|
-
source: string;
|
|
152
|
-
};
|
|
153
|
-
}, {
|
|
154
|
-
url: string;
|
|
155
|
-
width: number;
|
|
156
|
-
height: number;
|
|
157
|
-
verification: {
|
|
158
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
159
|
-
data: string;
|
|
160
|
-
} | {
|
|
161
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
162
|
-
data: string;
|
|
163
|
-
source: string;
|
|
164
|
-
};
|
|
165
|
-
}>, "many">, "many">;
|
|
69
|
+
}, z.core.$strip>], "method">;
|
|
70
|
+
}, z.core.$strip>>>;
|
|
166
71
|
assets: z.ZodArray<z.ZodObject<{
|
|
167
72
|
url: z.ZodString;
|
|
168
73
|
fileType: z.ZodString;
|
|
169
|
-
verification: z.ZodDiscriminatedUnion<
|
|
74
|
+
verification: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
170
75
|
data: z.ZodString;
|
|
171
|
-
method: z.ZodEnum<
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}, {
|
|
176
|
-
method:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
76
|
+
method: z.ZodEnum<{
|
|
77
|
+
"keccak256(utf8)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8;
|
|
78
|
+
"keccak256(bytes)": _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
79
|
+
}>;
|
|
80
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
81
|
+
method: z.ZodEnum<{
|
|
82
|
+
ecdsa: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
83
|
+
}>;
|
|
180
84
|
data: z.ZodString;
|
|
181
85
|
source: z.ZodString;
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
source: string;
|
|
186
|
-
}, {
|
|
187
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
188
|
-
data: string;
|
|
189
|
-
source: string;
|
|
190
|
-
}>]>;
|
|
191
|
-
}, "strip", z.ZodTypeAny, {
|
|
192
|
-
url: string;
|
|
193
|
-
verification: {
|
|
194
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
195
|
-
data: string;
|
|
196
|
-
} | {
|
|
197
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
198
|
-
data: string;
|
|
199
|
-
source: string;
|
|
200
|
-
};
|
|
201
|
-
fileType: string;
|
|
202
|
-
}, {
|
|
203
|
-
url: string;
|
|
204
|
-
verification: {
|
|
205
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
206
|
-
data: string;
|
|
207
|
-
} | {
|
|
208
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
209
|
-
data: string;
|
|
210
|
-
source: string;
|
|
211
|
-
};
|
|
212
|
-
fileType: string;
|
|
213
|
-
}>, "many">;
|
|
214
|
-
attributes: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
86
|
+
}, z.core.$strip>], "method">;
|
|
87
|
+
}, z.core.$strip>>;
|
|
88
|
+
attributes: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
215
89
|
key: z.ZodString;
|
|
216
90
|
value: z.ZodString;
|
|
217
91
|
type: z.ZodLiteral<"string">;
|
|
218
|
-
},
|
|
219
|
-
type: "string";
|
|
220
|
-
value: string;
|
|
221
|
-
key: string;
|
|
222
|
-
}, {
|
|
223
|
-
type: "string";
|
|
224
|
-
value: string;
|
|
225
|
-
key: string;
|
|
226
|
-
}>, z.ZodObject<{
|
|
92
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
227
93
|
key: z.ZodString;
|
|
228
|
-
value: z.
|
|
94
|
+
value: z.ZodString;
|
|
229
95
|
type: z.ZodLiteral<"number">;
|
|
230
|
-
},
|
|
231
|
-
type: "number";
|
|
232
|
-
value: string;
|
|
233
|
-
key: string;
|
|
234
|
-
}, {
|
|
235
|
-
type: "number";
|
|
236
|
-
value: string;
|
|
237
|
-
key: string;
|
|
238
|
-
}>, z.ZodObject<{
|
|
96
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
239
97
|
key: z.ZodString;
|
|
240
98
|
value: z.ZodBoolean;
|
|
241
99
|
type: z.ZodLiteral<"boolean">;
|
|
242
|
-
},
|
|
243
|
-
|
|
244
|
-
value: boolean;
|
|
245
|
-
key: string;
|
|
246
|
-
}, {
|
|
247
|
-
type: "boolean";
|
|
248
|
-
value: boolean;
|
|
249
|
-
key: string;
|
|
250
|
-
}>]>, "many">;
|
|
251
|
-
}, "strip", z.ZodTypeAny, {
|
|
252
|
-
name: string | null;
|
|
253
|
-
description: string | null;
|
|
254
|
-
category: string | null;
|
|
255
|
-
links: {
|
|
256
|
-
url: string;
|
|
257
|
-
title: string;
|
|
258
|
-
}[];
|
|
259
|
-
icon: {
|
|
260
|
-
url: string;
|
|
261
|
-
width: number;
|
|
262
|
-
height: number;
|
|
263
|
-
verification: {
|
|
264
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
265
|
-
data: string;
|
|
266
|
-
} | {
|
|
267
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
268
|
-
data: string;
|
|
269
|
-
source: string;
|
|
270
|
-
};
|
|
271
|
-
}[];
|
|
272
|
-
images: {
|
|
273
|
-
url: string;
|
|
274
|
-
width: number;
|
|
275
|
-
height: number;
|
|
276
|
-
verification: {
|
|
277
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
278
|
-
data: string;
|
|
279
|
-
} | {
|
|
280
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
281
|
-
data: string;
|
|
282
|
-
source: string;
|
|
283
|
-
};
|
|
284
|
-
}[][];
|
|
285
|
-
assets: {
|
|
286
|
-
url: string;
|
|
287
|
-
verification: {
|
|
288
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
289
|
-
data: string;
|
|
290
|
-
} | {
|
|
291
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
292
|
-
data: string;
|
|
293
|
-
source: string;
|
|
294
|
-
};
|
|
295
|
-
fileType: string;
|
|
296
|
-
}[];
|
|
297
|
-
attributes: ({
|
|
298
|
-
type: "string";
|
|
299
|
-
value: string;
|
|
300
|
-
key: string;
|
|
301
|
-
} | {
|
|
302
|
-
type: "number";
|
|
303
|
-
value: string;
|
|
304
|
-
key: string;
|
|
305
|
-
} | {
|
|
306
|
-
type: "boolean";
|
|
307
|
-
value: boolean;
|
|
308
|
-
key: string;
|
|
309
|
-
})[];
|
|
310
|
-
}, {
|
|
311
|
-
name: string | null;
|
|
312
|
-
description: string | null;
|
|
313
|
-
category: string | null;
|
|
314
|
-
links: {
|
|
315
|
-
url: string;
|
|
316
|
-
title: string;
|
|
317
|
-
}[];
|
|
318
|
-
icon: {
|
|
319
|
-
url: string;
|
|
320
|
-
width: number;
|
|
321
|
-
height: number;
|
|
322
|
-
verification: {
|
|
323
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
324
|
-
data: string;
|
|
325
|
-
} | {
|
|
326
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
327
|
-
data: string;
|
|
328
|
-
source: string;
|
|
329
|
-
};
|
|
330
|
-
}[];
|
|
331
|
-
images: {
|
|
332
|
-
url: string;
|
|
333
|
-
width: number;
|
|
334
|
-
height: number;
|
|
335
|
-
verification: {
|
|
336
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
337
|
-
data: string;
|
|
338
|
-
} | {
|
|
339
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
340
|
-
data: string;
|
|
341
|
-
source: string;
|
|
342
|
-
};
|
|
343
|
-
}[][];
|
|
344
|
-
assets: {
|
|
345
|
-
url: string;
|
|
346
|
-
verification: {
|
|
347
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
348
|
-
data: string;
|
|
349
|
-
} | {
|
|
350
|
-
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
351
|
-
data: string;
|
|
352
|
-
source: string;
|
|
353
|
-
};
|
|
354
|
-
fileType: string;
|
|
355
|
-
}[];
|
|
356
|
-
attributes: ({
|
|
357
|
-
type: "string";
|
|
358
|
-
value: string;
|
|
359
|
-
key: string;
|
|
360
|
-
} | {
|
|
361
|
-
type: "number";
|
|
362
|
-
value: string;
|
|
363
|
-
key: string;
|
|
364
|
-
} | {
|
|
365
|
-
type: "boolean";
|
|
366
|
-
value: boolean;
|
|
367
|
-
key: string;
|
|
368
|
-
})[];
|
|
369
|
-
}>;
|
|
100
|
+
}, z.core.$strip>], "type">>;
|
|
101
|
+
}, z.core.$strip>;
|
|
370
102
|
|
|
371
103
|
/**
|
|
372
104
|
* LSP4 Inferred Types
|
|
@@ -376,6 +108,20 @@ declare const lsp4MetadataSchema: z.ZodObject<{
|
|
|
376
108
|
|
|
377
109
|
type LSP4Attribute = z.infer<typeof attributesSchema>;
|
|
378
110
|
type LSP4Metadata = z.infer<typeof lsp4MetadataSchema>;
|
|
111
|
+
/**
|
|
112
|
+
* Extended NFT metadata with optional token identification fields.
|
|
113
|
+
*
|
|
114
|
+
* Adds `tokenName`, `tokenIdFormat`, and `formattedTokenId` on top of
|
|
115
|
+
* standard LSP4 metadata for use with `getNftDisplayName`.
|
|
116
|
+
*/
|
|
117
|
+
interface NftMetadata extends LSP4Metadata {
|
|
118
|
+
/** Token collection name (e.g., "CoolCats") */
|
|
119
|
+
tokenName?: string;
|
|
120
|
+
/** Format of the token ID (e.g., "NUMBER", "STRING") */
|
|
121
|
+
tokenIdFormat?: string;
|
|
122
|
+
/** Pre-formatted token ID for display */
|
|
123
|
+
formattedTokenId?: string;
|
|
124
|
+
}
|
|
379
125
|
|
|
380
126
|
/**
|
|
381
127
|
* LSP4 Digital Asset Metadata Utilities
|
|
@@ -415,6 +161,63 @@ declare function getImageUrl(options: {
|
|
|
415
161
|
* @returns Display name string
|
|
416
162
|
*/
|
|
417
163
|
declare function getAssetDisplayName(metadata: LSP4Metadata): string;
|
|
164
|
+
/**
|
|
165
|
+
* Extract avatar image URL from Digital Asset metadata.
|
|
166
|
+
* Prefers icon, falls back to images. Optionally finds the closest image
|
|
167
|
+
* to target dimensions.
|
|
168
|
+
*
|
|
169
|
+
* @param metadata - Digital Asset (LSP7/LSP8) metadata
|
|
170
|
+
* @param parseUrl - Function to parse/transform the URL (e.g., IPFS gateway resolution)
|
|
171
|
+
* @param options - Optional target dimensions `{ width, height }`
|
|
172
|
+
* @returns Parsed URL or undefined if no image found
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* // Get first available image (prefers icon)
|
|
177
|
+
* getAssetImageUrl(asset, parseIpfsUrl)
|
|
178
|
+
*
|
|
179
|
+
* // Get image closest to 128×128
|
|
180
|
+
* getAssetImageUrl(asset, parseIpfsUrl, { width: 128, height: 128 })
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function getAssetImageUrl(metadata: LSP4Metadata, parseUrl: (url: string) => string, options?: Partial<ImageSize>): string | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* Extract avatar image URL from NFT metadata.
|
|
186
|
+
* Prefers images (usually more detailed), falls back to icon.
|
|
187
|
+
* Optionally finds the closest image to target dimensions.
|
|
188
|
+
*
|
|
189
|
+
* @param metadata - NFT (LSP8 token) metadata
|
|
190
|
+
* @param parseUrl - Function to parse/transform the URL (e.g., IPFS gateway resolution)
|
|
191
|
+
* @param options - Optional target dimensions `{ width, height }`
|
|
192
|
+
* @returns Parsed URL or undefined if no image found
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* // Get first available image (prefers full images)
|
|
197
|
+
* getNftImageUrl(nft, parseIpfsUrl)
|
|
198
|
+
*
|
|
199
|
+
* // Get image closest to 256×256
|
|
200
|
+
* getNftImageUrl(nft, parseIpfsUrl, { width: 256, height: 256 })
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
declare function getNftImageUrl(metadata: LSP4Metadata, parseUrl: (url: string) => string, options?: Partial<ImageSize>): string | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Get display name for NFT (LSP8 token).
|
|
206
|
+
* Includes token ID formatting (e.g., "TokenName #123").
|
|
207
|
+
*
|
|
208
|
+
* @param metadata - NFT metadata with optional token info
|
|
209
|
+
* @returns Display name string, possibly with token ID suffix
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* getNftDisplayName({ tokenName: "CoolCats", tokenIdFormat: "NUMBER", formattedTokenId: "42" })
|
|
214
|
+
* // => "CoolCats #42"
|
|
215
|
+
*
|
|
216
|
+
* getNftDisplayName({ tokenName: "Art" })
|
|
217
|
+
* // => "Art"
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
declare function getNftDisplayName(metadata: NftMetadata): string;
|
|
418
221
|
|
|
419
222
|
/**
|
|
420
223
|
* LSP4 Type Guards
|
|
@@ -431,5 +234,5 @@ declare function isAttributesSchema(obj: unknown): obj is z.infer<typeof attribu
|
|
|
431
234
|
*/
|
|
432
235
|
declare function isLsp4MetadataSchema(obj: unknown): obj is z.infer<typeof lsp4MetadataSchema>;
|
|
433
236
|
|
|
434
|
-
export { attributesSchema, getAssetDisplayName, getImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
|
435
|
-
export type { LSP4Attribute, LSP4Metadata };
|
|
237
|
+
export { attributesSchema, getAssetDisplayName, getAssetImageUrl, getImageUrl, getNftDisplayName, getNftImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
|
238
|
+
export type { LSP4Attribute, LSP4Metadata, NftMetadata };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { findBestImage, isNumeric } from '@chillwhales/utils';
|
|
1
2
|
import { assetSchema, imageSchema, linkSchema } from '@chillwhales/lsp2';
|
|
2
|
-
import { isNumeric } from '@chillwhales/utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
function getImageUrl(options) {
|
|
@@ -17,33 +17,67 @@ function getImageUrl(options) {
|
|
|
17
17
|
function getAssetDisplayName(metadata) {
|
|
18
18
|
return metadata.name || "Digital Asset";
|
|
19
19
|
}
|
|
20
|
+
function getAssetImageUrl(metadata, parseUrl, options) {
|
|
21
|
+
const icon = findBestImage(metadata.icon, options);
|
|
22
|
+
if (icon?.url) {
|
|
23
|
+
return parseUrl(icon.url);
|
|
24
|
+
}
|
|
25
|
+
const allImages = metadata.images?.flat();
|
|
26
|
+
const image = findBestImage(allImages, options);
|
|
27
|
+
if (image?.url) {
|
|
28
|
+
return parseUrl(image.url);
|
|
29
|
+
}
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
function getNftImageUrl(metadata, parseUrl, options) {
|
|
33
|
+
const allImages = metadata.images?.flat();
|
|
34
|
+
const image = findBestImage(allImages, options);
|
|
35
|
+
if (image?.url) {
|
|
36
|
+
return parseUrl(image.url);
|
|
37
|
+
}
|
|
38
|
+
const icon = findBestImage(metadata.icon, options);
|
|
39
|
+
if (icon?.url) {
|
|
40
|
+
return parseUrl(icon.url);
|
|
41
|
+
}
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
function getNftDisplayName(metadata) {
|
|
45
|
+
const baseName = metadata.tokenName || "NFT";
|
|
46
|
+
if (metadata.tokenIdFormat === "NUMBER" && metadata.formattedTokenId) {
|
|
47
|
+
return `${baseName} #${metadata.formattedTokenId}`;
|
|
48
|
+
}
|
|
49
|
+
if (metadata.formattedTokenId) {
|
|
50
|
+
return `${baseName} ${metadata.formattedTokenId}`;
|
|
51
|
+
}
|
|
52
|
+
return baseName;
|
|
53
|
+
}
|
|
20
54
|
|
|
21
55
|
const attributesSchema = z.discriminatedUnion("type", [
|
|
22
56
|
z.object({
|
|
23
|
-
key: z.string({
|
|
24
|
-
value: z.string({
|
|
57
|
+
key: z.string({ error: "Invalid value, not a string" }),
|
|
58
|
+
value: z.string({ error: "Invalid value, not a string" }),
|
|
25
59
|
type: z.literal("string")
|
|
26
60
|
}),
|
|
27
61
|
z.object({
|
|
28
|
-
key: z.string({
|
|
29
|
-
value: z.string({
|
|
62
|
+
key: z.string({ error: "Invalid value, not a string" }),
|
|
63
|
+
value: z.string({ error: "Value required" }).refine(isNumeric, "Invalid value, not a number"),
|
|
30
64
|
type: z.literal("number")
|
|
31
65
|
}),
|
|
32
66
|
z.object({
|
|
33
|
-
key: z.string({
|
|
34
|
-
value: z.boolean({
|
|
67
|
+
key: z.string({ error: "Invalid value, not a string" }),
|
|
68
|
+
value: z.boolean({ error: "Invalid value, not a boolean" }),
|
|
35
69
|
type: z.literal("boolean")
|
|
36
70
|
})
|
|
37
71
|
]);
|
|
38
72
|
const lsp4MetadataSchema = z.object({
|
|
39
73
|
name: z.string({
|
|
40
|
-
|
|
74
|
+
error: "Name must be a string"
|
|
41
75
|
}).nullable(),
|
|
42
76
|
description: z.string({
|
|
43
|
-
|
|
77
|
+
error: "Description must be a string"
|
|
44
78
|
}).nullable(),
|
|
45
79
|
category: z.string({
|
|
46
|
-
|
|
80
|
+
error: "Category must be a string"
|
|
47
81
|
}).nullable(),
|
|
48
82
|
links: z.array(linkSchema),
|
|
49
83
|
icon: z.array(imageSchema),
|
|
@@ -61,4 +95,4 @@ function isLsp4MetadataSchema(obj) {
|
|
|
61
95
|
return success;
|
|
62
96
|
}
|
|
63
97
|
|
|
64
|
-
export { attributesSchema, getAssetDisplayName, getImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
|
98
|
+
export { attributesSchema, getAssetDisplayName, getAssetImageUrl, getImageUrl, getNftDisplayName, getNftImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chillwhales/lsp4",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "LSP4 Digital Asset Metadata — schemas, types, and utilities for LSP7/LSP8 token metadata on LUKSO",
|
|
6
6
|
"author": "b00ste",
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
"url": "git+https://github.com/chillwhales/LSPs.git",
|
|
26
26
|
"directory": "packages/lsp4"
|
|
27
27
|
},
|
|
28
|
+
"homepage": "https://github.com/chillwhales/LSPs/tree/main/packages/lsp4",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/chillwhales/LSPs/issues"
|
|
31
|
+
},
|
|
28
32
|
"keywords": [
|
|
29
33
|
"chillwhales",
|
|
30
34
|
"lukso",
|
|
@@ -37,14 +41,14 @@
|
|
|
37
41
|
],
|
|
38
42
|
"sideEffects": false,
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"zod": "^3.
|
|
41
|
-
"@chillwhales/lsp2": "0.
|
|
42
|
-
"@chillwhales/utils": "0.
|
|
44
|
+
"zod": "^4.3.6",
|
|
45
|
+
"@chillwhales/lsp2": "0.2.1",
|
|
46
|
+
"@chillwhales/utils": "0.2.1"
|
|
43
47
|
},
|
|
44
48
|
"devDependencies": {
|
|
45
49
|
"typescript": "^5.9.3",
|
|
46
50
|
"unbuild": "^3.6.1",
|
|
47
|
-
"vitest": "^4.0.
|
|
51
|
+
"vitest": "^4.0.18",
|
|
48
52
|
"@chillwhales/config": "0.0.0"
|
|
49
53
|
},
|
|
50
54
|
"scripts": {
|