@chillwhales/lsp3 0.1.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/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/index.d.mts +321 -0
- package/dist/index.d.ts +321 -0
- package/dist/index.mjs +36 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chillwhales contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @chillwhales/lsp3
|
|
2
|
+
|
|
3
|
+
[](./LICENSE)
|
|
4
|
+
|
|
5
|
+
LSP3 Universal Profile Metadata — schemas, types, and utilities for reading and validating profile metadata on LUKSO.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @chillwhales/lsp3
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import {
|
|
17
|
+
lsp3ProfileSchema,
|
|
18
|
+
getProfileDisplayName,
|
|
19
|
+
getProfileImageUrl,
|
|
20
|
+
} from "@chillwhales/lsp3";
|
|
21
|
+
|
|
22
|
+
// Validate raw profile metadata fetched from IPFS / on-chain
|
|
23
|
+
const raw = {
|
|
24
|
+
name: "Alice",
|
|
25
|
+
description: "Builder on LUKSO",
|
|
26
|
+
tags: ["developer"],
|
|
27
|
+
links: [{ title: "Website", url: "https://alice.dev" }],
|
|
28
|
+
avatar: [],
|
|
29
|
+
profileImage: [{ url: "ipfs://QmImg...", width: 256, height: 256 }],
|
|
30
|
+
backgroundImage: [],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const profile = lsp3ProfileSchema.parse(raw);
|
|
34
|
+
|
|
35
|
+
// Extract display-ready values
|
|
36
|
+
const name = getProfileDisplayName(profile); // "Alice"
|
|
37
|
+
const imageUrl = getProfileImageUrl(profile, (url) =>
|
|
38
|
+
url.replace("ipfs://", "https://api.universalprofile.cloud/ipfs/"),
|
|
39
|
+
);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
> **Spec:** [LSP-3 Universal Profile Metadata](https://docs.lukso.tech/standards/universal-profile/lsp3-profile-metadata)
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
Types are exported and available in your editor via TypeScript IntelliSense.
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
[MIT](./LICENSE)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as _chillwhales_lsp2 from '@chillwhales/lsp2';
|
|
3
|
+
import { ImageSize } from '@chillwhales/lsp2';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* LSP3 Profile metadata schema
|
|
7
|
+
* Full metadata structure for Universal Profiles
|
|
8
|
+
*/
|
|
9
|
+
declare const lsp3ProfileSchema: z.ZodObject<{
|
|
10
|
+
name: z.ZodNullable<z.ZodString>;
|
|
11
|
+
description: z.ZodNullable<z.ZodString>;
|
|
12
|
+
tags: z.ZodArray<z.ZodString, "many">;
|
|
13
|
+
links: z.ZodArray<z.ZodObject<{
|
|
14
|
+
title: z.ZodString;
|
|
15
|
+
url: z.ZodString;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
url: string;
|
|
18
|
+
title: string;
|
|
19
|
+
}, {
|
|
20
|
+
url: string;
|
|
21
|
+
title: string;
|
|
22
|
+
}>, "many">;
|
|
23
|
+
avatar: z.ZodArray<z.ZodObject<{
|
|
24
|
+
url: z.ZodString;
|
|
25
|
+
fileType: z.ZodString;
|
|
26
|
+
verification: z.ZodDiscriminatedUnion<"method", [z.ZodObject<{
|
|
27
|
+
data: z.ZodString;
|
|
28
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES, _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8]>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
31
|
+
data: string;
|
|
32
|
+
}, {
|
|
33
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
34
|
+
data: string;
|
|
35
|
+
}>, z.ZodObject<{
|
|
36
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
37
|
+
data: z.ZodString;
|
|
38
|
+
source: z.ZodString;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
41
|
+
data: string;
|
|
42
|
+
source: string;
|
|
43
|
+
}, {
|
|
44
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
45
|
+
data: string;
|
|
46
|
+
source: string;
|
|
47
|
+
}>]>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
url: string;
|
|
50
|
+
verification: {
|
|
51
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
52
|
+
data: string;
|
|
53
|
+
} | {
|
|
54
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
55
|
+
data: string;
|
|
56
|
+
source: string;
|
|
57
|
+
};
|
|
58
|
+
fileType: string;
|
|
59
|
+
}, {
|
|
60
|
+
url: string;
|
|
61
|
+
verification: {
|
|
62
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
63
|
+
data: string;
|
|
64
|
+
} | {
|
|
65
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
66
|
+
data: string;
|
|
67
|
+
source: string;
|
|
68
|
+
};
|
|
69
|
+
fileType: string;
|
|
70
|
+
}>, "many">;
|
|
71
|
+
profileImage: z.ZodArray<z.ZodObject<{
|
|
72
|
+
url: z.ZodString;
|
|
73
|
+
width: z.ZodNumber;
|
|
74
|
+
height: z.ZodNumber;
|
|
75
|
+
verification: z.ZodDiscriminatedUnion<"method", [z.ZodObject<{
|
|
76
|
+
data: z.ZodString;
|
|
77
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES, _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8]>;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
80
|
+
data: string;
|
|
81
|
+
}, {
|
|
82
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
83
|
+
data: string;
|
|
84
|
+
}>, z.ZodObject<{
|
|
85
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
86
|
+
data: z.ZodString;
|
|
87
|
+
source: z.ZodString;
|
|
88
|
+
}, "strip", z.ZodTypeAny, {
|
|
89
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
90
|
+
data: string;
|
|
91
|
+
source: string;
|
|
92
|
+
}, {
|
|
93
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
94
|
+
data: string;
|
|
95
|
+
source: string;
|
|
96
|
+
}>]>;
|
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
url: string;
|
|
99
|
+
width: number;
|
|
100
|
+
height: number;
|
|
101
|
+
verification: {
|
|
102
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
103
|
+
data: string;
|
|
104
|
+
} | {
|
|
105
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
106
|
+
data: string;
|
|
107
|
+
source: string;
|
|
108
|
+
};
|
|
109
|
+
}, {
|
|
110
|
+
url: string;
|
|
111
|
+
width: number;
|
|
112
|
+
height: number;
|
|
113
|
+
verification: {
|
|
114
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
115
|
+
data: string;
|
|
116
|
+
} | {
|
|
117
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
118
|
+
data: string;
|
|
119
|
+
source: string;
|
|
120
|
+
};
|
|
121
|
+
}>, "many">;
|
|
122
|
+
backgroundImage: z.ZodArray<z.ZodObject<{
|
|
123
|
+
url: z.ZodString;
|
|
124
|
+
width: z.ZodNumber;
|
|
125
|
+
height: z.ZodNumber;
|
|
126
|
+
verification: z.ZodDiscriminatedUnion<"method", [z.ZodObject<{
|
|
127
|
+
data: z.ZodString;
|
|
128
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES, _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8]>;
|
|
129
|
+
}, "strip", z.ZodTypeAny, {
|
|
130
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
131
|
+
data: string;
|
|
132
|
+
}, {
|
|
133
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
134
|
+
data: string;
|
|
135
|
+
}>, z.ZodObject<{
|
|
136
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
137
|
+
data: z.ZodString;
|
|
138
|
+
source: z.ZodString;
|
|
139
|
+
}, "strip", z.ZodTypeAny, {
|
|
140
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
141
|
+
data: string;
|
|
142
|
+
source: string;
|
|
143
|
+
}, {
|
|
144
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
145
|
+
data: string;
|
|
146
|
+
source: string;
|
|
147
|
+
}>]>;
|
|
148
|
+
}, "strip", z.ZodTypeAny, {
|
|
149
|
+
url: string;
|
|
150
|
+
width: number;
|
|
151
|
+
height: number;
|
|
152
|
+
verification: {
|
|
153
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
154
|
+
data: string;
|
|
155
|
+
} | {
|
|
156
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
157
|
+
data: string;
|
|
158
|
+
source: string;
|
|
159
|
+
};
|
|
160
|
+
}, {
|
|
161
|
+
url: string;
|
|
162
|
+
width: number;
|
|
163
|
+
height: number;
|
|
164
|
+
verification: {
|
|
165
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
166
|
+
data: string;
|
|
167
|
+
} | {
|
|
168
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
169
|
+
data: string;
|
|
170
|
+
source: string;
|
|
171
|
+
};
|
|
172
|
+
}>, "many">;
|
|
173
|
+
}, "strip", z.ZodTypeAny, {
|
|
174
|
+
name: string | null;
|
|
175
|
+
description: string | null;
|
|
176
|
+
tags: string[];
|
|
177
|
+
links: {
|
|
178
|
+
url: string;
|
|
179
|
+
title: string;
|
|
180
|
+
}[];
|
|
181
|
+
avatar: {
|
|
182
|
+
url: string;
|
|
183
|
+
verification: {
|
|
184
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
185
|
+
data: string;
|
|
186
|
+
} | {
|
|
187
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
188
|
+
data: string;
|
|
189
|
+
source: string;
|
|
190
|
+
};
|
|
191
|
+
fileType: string;
|
|
192
|
+
}[];
|
|
193
|
+
profileImage: {
|
|
194
|
+
url: string;
|
|
195
|
+
width: number;
|
|
196
|
+
height: number;
|
|
197
|
+
verification: {
|
|
198
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
199
|
+
data: string;
|
|
200
|
+
} | {
|
|
201
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
202
|
+
data: string;
|
|
203
|
+
source: string;
|
|
204
|
+
};
|
|
205
|
+
}[];
|
|
206
|
+
backgroundImage: {
|
|
207
|
+
url: string;
|
|
208
|
+
width: number;
|
|
209
|
+
height: number;
|
|
210
|
+
verification: {
|
|
211
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
212
|
+
data: string;
|
|
213
|
+
} | {
|
|
214
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
215
|
+
data: string;
|
|
216
|
+
source: string;
|
|
217
|
+
};
|
|
218
|
+
}[];
|
|
219
|
+
}, {
|
|
220
|
+
name: string | null;
|
|
221
|
+
description: string | null;
|
|
222
|
+
tags: string[];
|
|
223
|
+
links: {
|
|
224
|
+
url: string;
|
|
225
|
+
title: string;
|
|
226
|
+
}[];
|
|
227
|
+
avatar: {
|
|
228
|
+
url: string;
|
|
229
|
+
verification: {
|
|
230
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
231
|
+
data: string;
|
|
232
|
+
} | {
|
|
233
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
234
|
+
data: string;
|
|
235
|
+
source: string;
|
|
236
|
+
};
|
|
237
|
+
fileType: string;
|
|
238
|
+
}[];
|
|
239
|
+
profileImage: {
|
|
240
|
+
url: string;
|
|
241
|
+
width: number;
|
|
242
|
+
height: number;
|
|
243
|
+
verification: {
|
|
244
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
245
|
+
data: string;
|
|
246
|
+
} | {
|
|
247
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
248
|
+
data: string;
|
|
249
|
+
source: string;
|
|
250
|
+
};
|
|
251
|
+
}[];
|
|
252
|
+
backgroundImage: {
|
|
253
|
+
url: string;
|
|
254
|
+
width: number;
|
|
255
|
+
height: number;
|
|
256
|
+
verification: {
|
|
257
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
258
|
+
data: string;
|
|
259
|
+
} | {
|
|
260
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
261
|
+
data: string;
|
|
262
|
+
source: string;
|
|
263
|
+
};
|
|
264
|
+
}[];
|
|
265
|
+
}>;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* LSP3 Type Guards
|
|
269
|
+
*
|
|
270
|
+
* Runtime type guards for LSP3 schemas.
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Type guard for LSP3 profile schema
|
|
275
|
+
*/
|
|
276
|
+
declare function isLsp3ProfileSchema(obj: unknown): obj is z.infer<typeof lsp3ProfileSchema>;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* LSP3 Inferred Types
|
|
280
|
+
*
|
|
281
|
+
* TypeScript types inferred from LSP3 Zod schemas.
|
|
282
|
+
*/
|
|
283
|
+
|
|
284
|
+
type LSP3Profile = z.infer<typeof lsp3ProfileSchema>;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* LSP3 Universal Profile Metadata Utilities
|
|
288
|
+
*
|
|
289
|
+
* Pure functions for working with LSP3 profile metadata.
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Extract profile image URL from Universal Profile metadata.
|
|
294
|
+
* Uses the `profileImage` field and optionally finds the closest image to target dimensions.
|
|
295
|
+
*
|
|
296
|
+
* @param metadata - Universal Profile metadata (expects a `profileImage` array)
|
|
297
|
+
* @param parseUrl - Function to parse/transform the URL (e.g., IPFS parsing)
|
|
298
|
+
* @param options - Optional target dimensions { width, height }
|
|
299
|
+
* @returns Parsed URL from `metadata.profileImage` or undefined if no image
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* // Get first available profile image
|
|
304
|
+
* getProfileImageUrl(profile, parseIpfsUrl)
|
|
305
|
+
*
|
|
306
|
+
* // Get profile image closest to 64x64
|
|
307
|
+
* getProfileImageUrl(profile, parseIpfsUrl, { width: 64, height: 64 })
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
declare function getProfileImageUrl(metadata: LSP3Profile, parseUrl: (url: string) => string, options?: Partial<ImageSize>): string | undefined;
|
|
311
|
+
/**
|
|
312
|
+
* Get display name for Universal Profile.
|
|
313
|
+
* Falls back to 'Anonymous' if no name.
|
|
314
|
+
*
|
|
315
|
+
* @param metadata - Universal Profile metadata
|
|
316
|
+
* @returns Display name string
|
|
317
|
+
*/
|
|
318
|
+
declare function getProfileDisplayName(metadata: LSP3Profile): string;
|
|
319
|
+
|
|
320
|
+
export { getProfileDisplayName, getProfileImageUrl, isLsp3ProfileSchema, lsp3ProfileSchema };
|
|
321
|
+
export type { LSP3Profile };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as _chillwhales_lsp2 from '@chillwhales/lsp2';
|
|
3
|
+
import { ImageSize } from '@chillwhales/lsp2';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* LSP3 Profile metadata schema
|
|
7
|
+
* Full metadata structure for Universal Profiles
|
|
8
|
+
*/
|
|
9
|
+
declare const lsp3ProfileSchema: z.ZodObject<{
|
|
10
|
+
name: z.ZodNullable<z.ZodString>;
|
|
11
|
+
description: z.ZodNullable<z.ZodString>;
|
|
12
|
+
tags: z.ZodArray<z.ZodString, "many">;
|
|
13
|
+
links: z.ZodArray<z.ZodObject<{
|
|
14
|
+
title: z.ZodString;
|
|
15
|
+
url: z.ZodString;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
url: string;
|
|
18
|
+
title: string;
|
|
19
|
+
}, {
|
|
20
|
+
url: string;
|
|
21
|
+
title: string;
|
|
22
|
+
}>, "many">;
|
|
23
|
+
avatar: z.ZodArray<z.ZodObject<{
|
|
24
|
+
url: z.ZodString;
|
|
25
|
+
fileType: z.ZodString;
|
|
26
|
+
verification: z.ZodDiscriminatedUnion<"method", [z.ZodObject<{
|
|
27
|
+
data: z.ZodString;
|
|
28
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES, _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8]>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
31
|
+
data: string;
|
|
32
|
+
}, {
|
|
33
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
34
|
+
data: string;
|
|
35
|
+
}>, z.ZodObject<{
|
|
36
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
37
|
+
data: z.ZodString;
|
|
38
|
+
source: z.ZodString;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
41
|
+
data: string;
|
|
42
|
+
source: string;
|
|
43
|
+
}, {
|
|
44
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
45
|
+
data: string;
|
|
46
|
+
source: string;
|
|
47
|
+
}>]>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
url: string;
|
|
50
|
+
verification: {
|
|
51
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
52
|
+
data: string;
|
|
53
|
+
} | {
|
|
54
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
55
|
+
data: string;
|
|
56
|
+
source: string;
|
|
57
|
+
};
|
|
58
|
+
fileType: string;
|
|
59
|
+
}, {
|
|
60
|
+
url: string;
|
|
61
|
+
verification: {
|
|
62
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
63
|
+
data: string;
|
|
64
|
+
} | {
|
|
65
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
66
|
+
data: string;
|
|
67
|
+
source: string;
|
|
68
|
+
};
|
|
69
|
+
fileType: string;
|
|
70
|
+
}>, "many">;
|
|
71
|
+
profileImage: z.ZodArray<z.ZodObject<{
|
|
72
|
+
url: z.ZodString;
|
|
73
|
+
width: z.ZodNumber;
|
|
74
|
+
height: z.ZodNumber;
|
|
75
|
+
verification: z.ZodDiscriminatedUnion<"method", [z.ZodObject<{
|
|
76
|
+
data: z.ZodString;
|
|
77
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES, _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8]>;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
80
|
+
data: string;
|
|
81
|
+
}, {
|
|
82
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
83
|
+
data: string;
|
|
84
|
+
}>, z.ZodObject<{
|
|
85
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
86
|
+
data: z.ZodString;
|
|
87
|
+
source: z.ZodString;
|
|
88
|
+
}, "strip", z.ZodTypeAny, {
|
|
89
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
90
|
+
data: string;
|
|
91
|
+
source: string;
|
|
92
|
+
}, {
|
|
93
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
94
|
+
data: string;
|
|
95
|
+
source: string;
|
|
96
|
+
}>]>;
|
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
url: string;
|
|
99
|
+
width: number;
|
|
100
|
+
height: number;
|
|
101
|
+
verification: {
|
|
102
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
103
|
+
data: string;
|
|
104
|
+
} | {
|
|
105
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
106
|
+
data: string;
|
|
107
|
+
source: string;
|
|
108
|
+
};
|
|
109
|
+
}, {
|
|
110
|
+
url: string;
|
|
111
|
+
width: number;
|
|
112
|
+
height: number;
|
|
113
|
+
verification: {
|
|
114
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
115
|
+
data: string;
|
|
116
|
+
} | {
|
|
117
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
118
|
+
data: string;
|
|
119
|
+
source: string;
|
|
120
|
+
};
|
|
121
|
+
}>, "many">;
|
|
122
|
+
backgroundImage: z.ZodArray<z.ZodObject<{
|
|
123
|
+
url: z.ZodString;
|
|
124
|
+
width: z.ZodNumber;
|
|
125
|
+
height: z.ZodNumber;
|
|
126
|
+
verification: z.ZodDiscriminatedUnion<"method", [z.ZodObject<{
|
|
127
|
+
data: z.ZodString;
|
|
128
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES, _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8]>;
|
|
129
|
+
}, "strip", z.ZodTypeAny, {
|
|
130
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
131
|
+
data: string;
|
|
132
|
+
}, {
|
|
133
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
134
|
+
data: string;
|
|
135
|
+
}>, z.ZodObject<{
|
|
136
|
+
method: z.ZodEnum<[_chillwhales_lsp2.VERIFICATION_METHODS.ECDSA]>;
|
|
137
|
+
data: z.ZodString;
|
|
138
|
+
source: z.ZodString;
|
|
139
|
+
}, "strip", z.ZodTypeAny, {
|
|
140
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
141
|
+
data: string;
|
|
142
|
+
source: string;
|
|
143
|
+
}, {
|
|
144
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
145
|
+
data: string;
|
|
146
|
+
source: string;
|
|
147
|
+
}>]>;
|
|
148
|
+
}, "strip", z.ZodTypeAny, {
|
|
149
|
+
url: string;
|
|
150
|
+
width: number;
|
|
151
|
+
height: number;
|
|
152
|
+
verification: {
|
|
153
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
154
|
+
data: string;
|
|
155
|
+
} | {
|
|
156
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
157
|
+
data: string;
|
|
158
|
+
source: string;
|
|
159
|
+
};
|
|
160
|
+
}, {
|
|
161
|
+
url: string;
|
|
162
|
+
width: number;
|
|
163
|
+
height: number;
|
|
164
|
+
verification: {
|
|
165
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
166
|
+
data: string;
|
|
167
|
+
} | {
|
|
168
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
169
|
+
data: string;
|
|
170
|
+
source: string;
|
|
171
|
+
};
|
|
172
|
+
}>, "many">;
|
|
173
|
+
}, "strip", z.ZodTypeAny, {
|
|
174
|
+
name: string | null;
|
|
175
|
+
description: string | null;
|
|
176
|
+
tags: string[];
|
|
177
|
+
links: {
|
|
178
|
+
url: string;
|
|
179
|
+
title: string;
|
|
180
|
+
}[];
|
|
181
|
+
avatar: {
|
|
182
|
+
url: string;
|
|
183
|
+
verification: {
|
|
184
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
185
|
+
data: string;
|
|
186
|
+
} | {
|
|
187
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
188
|
+
data: string;
|
|
189
|
+
source: string;
|
|
190
|
+
};
|
|
191
|
+
fileType: string;
|
|
192
|
+
}[];
|
|
193
|
+
profileImage: {
|
|
194
|
+
url: string;
|
|
195
|
+
width: number;
|
|
196
|
+
height: number;
|
|
197
|
+
verification: {
|
|
198
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
199
|
+
data: string;
|
|
200
|
+
} | {
|
|
201
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
202
|
+
data: string;
|
|
203
|
+
source: string;
|
|
204
|
+
};
|
|
205
|
+
}[];
|
|
206
|
+
backgroundImage: {
|
|
207
|
+
url: string;
|
|
208
|
+
width: number;
|
|
209
|
+
height: number;
|
|
210
|
+
verification: {
|
|
211
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
212
|
+
data: string;
|
|
213
|
+
} | {
|
|
214
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
215
|
+
data: string;
|
|
216
|
+
source: string;
|
|
217
|
+
};
|
|
218
|
+
}[];
|
|
219
|
+
}, {
|
|
220
|
+
name: string | null;
|
|
221
|
+
description: string | null;
|
|
222
|
+
tags: string[];
|
|
223
|
+
links: {
|
|
224
|
+
url: string;
|
|
225
|
+
title: string;
|
|
226
|
+
}[];
|
|
227
|
+
avatar: {
|
|
228
|
+
url: string;
|
|
229
|
+
verification: {
|
|
230
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
231
|
+
data: string;
|
|
232
|
+
} | {
|
|
233
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
234
|
+
data: string;
|
|
235
|
+
source: string;
|
|
236
|
+
};
|
|
237
|
+
fileType: string;
|
|
238
|
+
}[];
|
|
239
|
+
profileImage: {
|
|
240
|
+
url: string;
|
|
241
|
+
width: number;
|
|
242
|
+
height: number;
|
|
243
|
+
verification: {
|
|
244
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
245
|
+
data: string;
|
|
246
|
+
} | {
|
|
247
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
248
|
+
data: string;
|
|
249
|
+
source: string;
|
|
250
|
+
};
|
|
251
|
+
}[];
|
|
252
|
+
backgroundImage: {
|
|
253
|
+
url: string;
|
|
254
|
+
width: number;
|
|
255
|
+
height: number;
|
|
256
|
+
verification: {
|
|
257
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_UTF8 | _chillwhales_lsp2.VERIFICATION_METHODS.HASH_KECCAK256_BYTES;
|
|
258
|
+
data: string;
|
|
259
|
+
} | {
|
|
260
|
+
method: _chillwhales_lsp2.VERIFICATION_METHODS.ECDSA;
|
|
261
|
+
data: string;
|
|
262
|
+
source: string;
|
|
263
|
+
};
|
|
264
|
+
}[];
|
|
265
|
+
}>;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* LSP3 Type Guards
|
|
269
|
+
*
|
|
270
|
+
* Runtime type guards for LSP3 schemas.
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Type guard for LSP3 profile schema
|
|
275
|
+
*/
|
|
276
|
+
declare function isLsp3ProfileSchema(obj: unknown): obj is z.infer<typeof lsp3ProfileSchema>;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* LSP3 Inferred Types
|
|
280
|
+
*
|
|
281
|
+
* TypeScript types inferred from LSP3 Zod schemas.
|
|
282
|
+
*/
|
|
283
|
+
|
|
284
|
+
type LSP3Profile = z.infer<typeof lsp3ProfileSchema>;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* LSP3 Universal Profile Metadata Utilities
|
|
288
|
+
*
|
|
289
|
+
* Pure functions for working with LSP3 profile metadata.
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Extract profile image URL from Universal Profile metadata.
|
|
294
|
+
* Uses the `profileImage` field and optionally finds the closest image to target dimensions.
|
|
295
|
+
*
|
|
296
|
+
* @param metadata - Universal Profile metadata (expects a `profileImage` array)
|
|
297
|
+
* @param parseUrl - Function to parse/transform the URL (e.g., IPFS parsing)
|
|
298
|
+
* @param options - Optional target dimensions { width, height }
|
|
299
|
+
* @returns Parsed URL from `metadata.profileImage` or undefined if no image
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* // Get first available profile image
|
|
304
|
+
* getProfileImageUrl(profile, parseIpfsUrl)
|
|
305
|
+
*
|
|
306
|
+
* // Get profile image closest to 64x64
|
|
307
|
+
* getProfileImageUrl(profile, parseIpfsUrl, { width: 64, height: 64 })
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
declare function getProfileImageUrl(metadata: LSP3Profile, parseUrl: (url: string) => string, options?: Partial<ImageSize>): string | undefined;
|
|
311
|
+
/**
|
|
312
|
+
* Get display name for Universal Profile.
|
|
313
|
+
* Falls back to 'Anonymous' if no name.
|
|
314
|
+
*
|
|
315
|
+
* @param metadata - Universal Profile metadata
|
|
316
|
+
* @returns Display name string
|
|
317
|
+
*/
|
|
318
|
+
declare function getProfileDisplayName(metadata: LSP3Profile): string;
|
|
319
|
+
|
|
320
|
+
export { getProfileDisplayName, getProfileImageUrl, isLsp3ProfileSchema, lsp3ProfileSchema };
|
|
321
|
+
export type { LSP3Profile };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { imageSchema, assetSchema, linkSchema, tagSchema, findBestImage } from '@chillwhales/lsp2';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const lsp3ProfileSchema = z.object({
|
|
5
|
+
name: z.string({
|
|
6
|
+
invalid_type_error: "Name must be a string"
|
|
7
|
+
}).nullable(),
|
|
8
|
+
description: z.string({
|
|
9
|
+
invalid_type_error: "Description must be a string"
|
|
10
|
+
}).nullable(),
|
|
11
|
+
tags: z.array(tagSchema, {
|
|
12
|
+
invalid_type_error: "Invalid value, not an array"
|
|
13
|
+
}),
|
|
14
|
+
links: z.array(linkSchema),
|
|
15
|
+
avatar: z.array(assetSchema),
|
|
16
|
+
profileImage: z.array(imageSchema),
|
|
17
|
+
backgroundImage: z.array(imageSchema)
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function isLsp3ProfileSchema(obj) {
|
|
21
|
+
const { success } = lsp3ProfileSchema.safeParse(obj);
|
|
22
|
+
return success;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getProfileImageUrl(metadata, parseUrl, options) {
|
|
26
|
+
const profileImage = findBestImage(metadata.profileImage, options);
|
|
27
|
+
if (profileImage?.url) {
|
|
28
|
+
return parseUrl(profileImage.url);
|
|
29
|
+
}
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
function getProfileDisplayName(metadata) {
|
|
33
|
+
return metadata.name || "Anonymous";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { getProfileDisplayName, getProfileImageUrl, isLsp3ProfileSchema, lsp3ProfileSchema };
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chillwhales/lsp3",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "LSP3 Universal Profile Metadata — schemas, types, and utilities for profile metadata on LUKSO",
|
|
6
|
+
"author": "b00ste",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"types": "./dist/index.d.mts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/chillwhales/LSPs.git",
|
|
26
|
+
"directory": "packages/lsp3"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"chillwhales",
|
|
30
|
+
"lukso",
|
|
31
|
+
"lsp",
|
|
32
|
+
"lsp3",
|
|
33
|
+
"universal-profile",
|
|
34
|
+
"profile-metadata"
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"zod": "^3.24.1",
|
|
39
|
+
"@chillwhales/lsp2": "0.1.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"typescript": "^5.9.3",
|
|
43
|
+
"unbuild": "^3.6.1",
|
|
44
|
+
"vitest": "^4.0.17",
|
|
45
|
+
"@chillwhales/config": "0.0.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "unbuild",
|
|
49
|
+
"build:watch": "unbuild --watch",
|
|
50
|
+
"clean": "rm -rf dist",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"test:watch": "vitest"
|
|
53
|
+
}
|
|
54
|
+
}
|