@hashgraphonline/standards-agent-kit 0.2.127 → 0.2.129

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.
Files changed (41) hide show
  1. package/dist/cjs/standards-agent-kit.cjs +1 -1
  2. package/dist/cjs/standards-agent-kit.cjs.map +1 -1
  3. package/dist/cjs/tools/inscriber/InscribeFromBufferTool.d.ts +2 -10
  4. package/dist/cjs/tools/inscriber/InscribeHashinalTool.d.ts +62 -30
  5. package/dist/cjs/utils/content-resolver.d.ts +10 -0
  6. package/dist/cjs/utils/metadata-defaults.d.ts +18 -0
  7. package/dist/cjs/validation/content-ref-schemas.d.ts +9 -0
  8. package/dist/cjs/validation/hip412-schemas.d.ts +125 -0
  9. package/dist/es/standards-agent-kit.es36.js +11 -63
  10. package/dist/es/standards-agent-kit.es36.js.map +1 -1
  11. package/dist/es/standards-agent-kit.es37.js +159 -33
  12. package/dist/es/standards-agent-kit.es37.js.map +1 -1
  13. package/dist/es/standards-agent-kit.es44.js +57 -0
  14. package/dist/es/standards-agent-kit.es44.js.map +1 -0
  15. package/dist/es/standards-agent-kit.es45.js +6 -0
  16. package/dist/es/standards-agent-kit.es45.js.map +1 -0
  17. package/dist/es/standards-agent-kit.es46.js +43 -0
  18. package/dist/es/standards-agent-kit.es46.js.map +1 -0
  19. package/dist/es/standards-agent-kit.es47.js +15 -0
  20. package/dist/es/standards-agent-kit.es47.js.map +1 -0
  21. package/dist/es/tools/inscriber/InscribeFromBufferTool.d.ts +2 -10
  22. package/dist/es/tools/inscriber/InscribeHashinalTool.d.ts +62 -30
  23. package/dist/es/utils/content-resolver.d.ts +10 -0
  24. package/dist/es/utils/metadata-defaults.d.ts +18 -0
  25. package/dist/es/validation/content-ref-schemas.d.ts +9 -0
  26. package/dist/es/validation/hip412-schemas.d.ts +125 -0
  27. package/dist/umd/standards-agent-kit.umd.js +1 -1
  28. package/dist/umd/standards-agent-kit.umd.js.map +1 -1
  29. package/dist/umd/tools/inscriber/InscribeFromBufferTool.d.ts +2 -10
  30. package/dist/umd/tools/inscriber/InscribeHashinalTool.d.ts +62 -30
  31. package/dist/umd/utils/content-resolver.d.ts +10 -0
  32. package/dist/umd/utils/metadata-defaults.d.ts +18 -0
  33. package/dist/umd/validation/content-ref-schemas.d.ts +9 -0
  34. package/dist/umd/validation/hip412-schemas.d.ts +125 -0
  35. package/package.json +34 -31
  36. package/src/tools/inscriber/InscribeFromBufferTool.ts +30 -133
  37. package/src/tools/inscriber/InscribeHashinalTool.ts +271 -46
  38. package/src/utils/content-resolver.ts +87 -0
  39. package/src/utils/metadata-defaults.ts +25 -0
  40. package/src/validation/content-ref-schemas.ts +20 -0
  41. package/src/validation/hip412-schemas.ts +52 -0
@@ -0,0 +1,87 @@
1
+ import { ContentResolverRegistry } from '@hashgraphonline/standards-sdk';
2
+
3
+ export interface ContentResolutionResult {
4
+ buffer: Buffer;
5
+ mimeType?: string;
6
+ fileName?: string;
7
+ wasReference?: boolean;
8
+ }
9
+
10
+ /**
11
+ * Resolves content from various input formats (content-ref, base64, plain text)
12
+ */
13
+ export async function resolveContent(
14
+ input: string,
15
+ providedMimeType?: string,
16
+ providedFileName?: string
17
+ ): Promise<ContentResolutionResult> {
18
+ const trimmedInput = input.trim();
19
+
20
+ const resolver = ContentResolverRegistry.getResolver();
21
+
22
+ if (!resolver) {
23
+ return handleDirectContent(
24
+ trimmedInput,
25
+ providedMimeType,
26
+ providedFileName
27
+ );
28
+ }
29
+
30
+ const referenceId = resolver.extractReferenceId(trimmedInput);
31
+
32
+ if (referenceId) {
33
+ try {
34
+ const resolution = await resolver.resolveReference(referenceId);
35
+
36
+ return {
37
+ buffer: resolution.content,
38
+ mimeType: resolution.metadata?.mimeType || providedMimeType,
39
+ fileName: resolution.metadata?.fileName || providedFileName,
40
+ wasReference: true,
41
+ };
42
+ } catch (error) {
43
+ const errorMsg =
44
+ error instanceof Error
45
+ ? error.message
46
+ : 'Unknown error resolving reference';
47
+ throw new Error(`Reference resolution failed: ${errorMsg}`);
48
+ }
49
+ }
50
+
51
+ return handleDirectContent(trimmedInput, providedMimeType, providedFileName);
52
+ }
53
+
54
+ /**
55
+ * Handles direct content (base64 or plain text)
56
+ */
57
+ function handleDirectContent(
58
+ input: string,
59
+ providedMimeType?: string,
60
+ providedFileName?: string
61
+ ): ContentResolutionResult {
62
+ const isValidBase64 = /^[A-Za-z0-9+/]*={0,2}$/.test(input);
63
+
64
+ if (isValidBase64) {
65
+ try {
66
+ const buffer = Buffer.from(input, 'base64');
67
+ return {
68
+ buffer,
69
+ mimeType: providedMimeType,
70
+ fileName: providedFileName,
71
+ wasReference: false,
72
+ };
73
+ } catch (error) {
74
+ throw new Error(
75
+ 'Failed to decode base64 data. Please ensure the data is properly encoded.'
76
+ );
77
+ }
78
+ }
79
+
80
+ const buffer = Buffer.from(input, 'utf8');
81
+ return {
82
+ buffer,
83
+ mimeType: providedMimeType || 'text/plain',
84
+ fileName: providedFileName,
85
+ wasReference: false,
86
+ };
87
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Generates default metadata for NFT inscription
3
+ */
4
+ export function generateDefaultMetadata(params: {
5
+ name?: string;
6
+ creator?: string;
7
+ description?: string;
8
+ type?: string;
9
+ fileName?: string;
10
+ mimeType?: string;
11
+ operatorAccount: string;
12
+ }) {
13
+ const defaultName = params.fileName?.replace(/\.[^/.]+$/, '') || 'Hashinal NFT';
14
+ const defaultType = params.mimeType?.startsWith('image/') ? 'image' :
15
+ params.mimeType?.startsWith('video/') ? 'video' :
16
+ params.mimeType?.startsWith('audio/') ? 'audio' : 'media';
17
+
18
+ return {
19
+ name: params.name || defaultName,
20
+ creator: params.creator || params.operatorAccount,
21
+ description: params.description || `${defaultType.charAt(0).toUpperCase() + defaultType.slice(1)} NFT inscribed as Hashinal`,
22
+ type: params.type || defaultType,
23
+ image: '',
24
+ };
25
+ }
@@ -0,0 +1,20 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Validates content reference format
5
+ */
6
+ export const contentRefSchema = z
7
+ .string()
8
+ .regex(/^content-ref:[a-fA-F0-9]{64}$/, 'Content reference must be in format "content-ref:[64-char hex]"')
9
+ .describe('Content reference in format "content-ref:[id]"');
10
+
11
+ /**
12
+ * Validates content reference or returns error for dumber models
13
+ */
14
+ export function validateContentRef(input: string): string {
15
+ try {
16
+ return contentRefSchema.parse(input);
17
+ } catch (error) {
18
+ throw new Error(`Invalid content reference format. Expected "content-ref:[64-character-hash]" but got "${input}"`);
19
+ }
20
+ }
@@ -0,0 +1,52 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * HIP-412 file schema for multi-file NFTs
5
+ */
6
+ export const hip412FileSchema = z.object({
7
+ uri: z.string().describe('URI of the file'),
8
+ checksum: z.string().optional().describe('SHA-256 checksum of the file'),
9
+ is_default_file: z.boolean().optional().describe('Whether this is the default file'),
10
+ type: z.string().describe('MIME type of the file'),
11
+ });
12
+
13
+ /**
14
+ * HIP-412 attribute schema for NFT traits
15
+ */
16
+ export const hip412AttributeSchema = z.object({
17
+ trait_type: z.string().describe('The trait type'),
18
+ value: z.union([z.string(), z.number()]).describe('The trait value'),
19
+ display_type: z.string().optional().describe('Display type for the attribute'),
20
+ });
21
+
22
+ /**
23
+ * HIP-412 compliant metadata schema for Hedera NFTs
24
+ */
25
+ export const hip412MetadataSchema = z.object({
26
+ name: z.string().describe('Token name (required by HIP-412)'),
27
+ description: z.string().describe('Human readable description (required by HIP-412)'),
28
+ image: z.string().describe('Preview image URI (required by HIP-412)'),
29
+ type: z.string().describe('MIME type (required by HIP-412)'),
30
+ creator: z.string().optional().describe('Creator name or comma-separated names'),
31
+ creatorDID: z.string().optional().describe('Decentralized identifier for creator'),
32
+ checksum: z.string().optional().describe('SHA-256 checksum of the image'),
33
+ format: z.string().optional().default('HIP412@2.0.0').describe('Metadata format version'),
34
+ files: z.array(hip412FileSchema).optional().describe('Array of files for multi-file NFTs'),
35
+ attributes: z.array(hip412AttributeSchema).optional().describe('NFT attributes/traits'),
36
+ properties: z.record(z.unknown()).optional().describe('Additional properties'),
37
+ });
38
+
39
+ /**
40
+ * Validates metadata against HIP-412 standard
41
+ */
42
+ export function validateHIP412Metadata(metadata: any): z.infer<typeof hip412MetadataSchema> {
43
+ try {
44
+ return hip412MetadataSchema.parse(metadata);
45
+ } catch (error) {
46
+ if (error instanceof z.ZodError) {
47
+ const issues = error.errors.map(err => `${err.path.join('.')}: ${err.message}`).join('; ');
48
+ throw new Error(`HIP-412 metadata validation failed: ${issues}`);
49
+ }
50
+ throw error;
51
+ }
52
+ }