viz-js-lib 0.11.0 → 0.12.4

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 (60) hide show
  1. package/.qoder/docs/spec/viz-dns-nameserver-spec.md +982 -0
  2. package/.qoder/docs/viz-cpp-node-docs/data-types.md +322 -0
  3. package/.qoder/docs/viz-cpp-node-docs/index.md +160 -0
  4. package/.qoder/docs/viz-cpp-node-docs/op-account-market.md +236 -0
  5. package/.qoder/docs/viz-cpp-node-docs/op-account.md +199 -0
  6. package/.qoder/docs/viz-cpp-node-docs/op-award.md +162 -0
  7. package/.qoder/docs/viz-cpp-node-docs/op-committee.md +193 -0
  8. package/.qoder/docs/viz-cpp-node-docs/op-content.md +157 -0
  9. package/.qoder/docs/viz-cpp-node-docs/op-escrow.md +224 -0
  10. package/.qoder/docs/viz-cpp-node-docs/op-invite.md +219 -0
  11. package/.qoder/docs/viz-cpp-node-docs/op-proposal.md +229 -0
  12. package/.qoder/docs/viz-cpp-node-docs/op-recovery.md +188 -0
  13. package/.qoder/docs/viz-cpp-node-docs/op-subscription.md +146 -0
  14. package/.qoder/docs/viz-cpp-node-docs/op-transfer-vesting.md +224 -0
  15. package/.qoder/docs/viz-cpp-node-docs/op-witness.md +252 -0
  16. package/.qoder/docs/viz-cpp-node-docs/plugins.md +887 -0
  17. package/.qoder/docs/viz-cpp-node-docs/virtual-operations.md +513 -0
  18. package/.qoder/repowiki/en/content/API Reference/API Reference.md +724 -0
  19. package/.qoder/repowiki/en/content/API Reference/Configuration Options.md +410 -0
  20. package/.qoder/repowiki/en/content/API Reference/Core API Methods.md +547 -0
  21. package/.qoder/repowiki/en/content/API Reference/Streaming APIs.md +380 -0
  22. package/.qoder/repowiki/en/content/API Reference/Transport Layer.md +341 -0
  23. package/.qoder/repowiki/en/content/API Reference/VIZ Blockchain Operations Coverage Status.md +427 -0
  24. package/.qoder/repowiki/en/content/Authentication & Cryptography/Authentication & Cryptography.md +430 -0
  25. package/.qoder/repowiki/en/content/Authentication & Cryptography/Digital Signatures.md +462 -0
  26. package/.qoder/repowiki/en/content/Authentication & Cryptography/Key Management.md +456 -0
  27. package/.qoder/repowiki/en/content/Authentication & Cryptography/Memo Encryption.md +331 -0
  28. package/.qoder/repowiki/en/content/Authentication & Cryptography/Security Practices.md +488 -0
  29. package/.qoder/repowiki/en/content/Broadcast Transactions/Broadcast Transactions.md +432 -0
  30. package/.qoder/repowiki/en/content/Broadcast Transactions/Network Broadcasting.md +418 -0
  31. package/.qoder/repowiki/en/content/Broadcast Transactions/Operation Construction.md +352 -0
  32. package/.qoder/repowiki/en/content/Broadcast Transactions/Transaction Preparation.md +353 -0
  33. package/.qoder/repowiki/en/content/Broadcast Transactions/Transaction Signing.md +404 -0
  34. package/.qoder/repowiki/en/content/Data Serialization/Data Serialization.md +540 -0
  35. package/.qoder/repowiki/en/content/Data Serialization/Encoding & Decoding.md +463 -0
  36. package/.qoder/repowiki/en/content/Data Serialization/Object Templates.md +413 -0
  37. package/.qoder/repowiki/en/content/Data Serialization/Type System.md +514 -0
  38. package/.qoder/repowiki/en/content/Data Serialization/Validation Rules.md +439 -0
  39. package/.qoder/repowiki/en/content/Examples & Tutorials.md +485 -0
  40. package/.qoder/repowiki/en/content/Getting Started.md +345 -0
  41. package/.qoder/repowiki/en/content/Testing & Development.md +637 -0
  42. package/.qoder/repowiki/en/content/Utilities & Helpers.md +557 -0
  43. package/.qoder/repowiki/en/meta/repowiki-metadata.json +1 -0
  44. package/VIZ-JS-LIB-COVERAGE-STATUS.md +356 -0
  45. package/config.json +3 -1
  46. package/dist/statistics.html +1 -1
  47. package/dist/viz-tests.min.js +32 -42
  48. package/dist/viz-tests.min.js.gz +0 -0
  49. package/dist/viz.min.js +8 -18
  50. package/dist/viz.min.js.gz +0 -0
  51. package/lib/api/methods.js +24 -0
  52. package/lib/auth/serializer/src/ChainTypes.js +2 -1
  53. package/lib/auth/serializer/src/operations.js +35 -2
  54. package/lib/broadcast/index.js +29 -15
  55. package/lib/broadcast/operations.js +4 -0
  56. package/lib/dns.js +658 -0
  57. package/lib/index.js +3 -1
  58. package/package.json +3 -2
  59. package/test/dns.test.js +395 -0
  60. package/webpack/makeConfig.js +3 -0
@@ -0,0 +1,439 @@
1
+ # Validation Rules
2
+
3
+ <cite>
4
+ **Referenced Files in This Document**
5
+ - [validation.js](file://src/auth/serializer/src/validation.js)
6
+ - [types.js](file://src/auth/serializer/src/types.js)
7
+ - [serializer.js](file://src/auth/serializer/src/serializer.js)
8
+ - [operations.js](file://src/auth/serializer/src/operations.js)
9
+ - [ChainTypes.js](file://src/auth/serializer/src/ChainTypes.js)
10
+ - [error_with_cause.js](file://src/auth/serializer/src/error_with_cause.js)
11
+ - [number_utils.js](file://src/auth/serializer/src/number_utils.js)
12
+ - [fast_parser.js](file://src/auth/serializer/src/fast_parser.js)
13
+ - [template.js](file://src/auth/serializer/src/template.js)
14
+ - [index.js](file://src/auth/serializer/index.js)
15
+ - [types_test.js](file://test/types_test.js)
16
+ - [all_types.js](file://test/all_types.js)
17
+ </cite>
18
+
19
+ ## Table of Contents
20
+ 1. [Introduction](#introduction)
21
+ 2. [Project Structure](#project-structure)
22
+ 3. [Core Components](#core-components)
23
+ 4. [Architecture Overview](#architecture-overview)
24
+ 5. [Detailed Component Analysis](#detailed-component-analysis)
25
+ 6. [Dependency Analysis](#dependency-analysis)
26
+ 7. [Performance Considerations](#performance-considerations)
27
+ 8. [Troubleshooting Guide](#troubleshooting-guide)
28
+ 9. [Conclusion](#conclusion)
29
+ 10. [Appendices](#appendices)
30
+
31
+ ## Introduction
32
+ This document explains the validation system that ensures data integrity during serialization in the Viz JavaScript library. It covers validation rule definitions, constraint checking, error handling mechanisms, and the validation pipeline. It also documents built-in validators, how to create custom validators, performance considerations, examples of input validation and business rule enforcement, error reporting, debugging techniques, common failure modes, and best practices for maintaining data consistency across the blockchain network.
33
+
34
+ ## Project Structure
35
+ The validation system lives primarily under the serializer module. At a high level:
36
+ - validation.js defines low-level validators for primitive and structured types.
37
+ - types.js defines concrete serializers for each type, invoking validation rules during append/fromObject/toObject.
38
+ - operations.js composes higher-level operations from basic types and validators.
39
+ - serializer.js orchestrates the end-to-end serialization pipeline and wraps errors with context.
40
+ - ChainTypes.js enumerates protocol-specific identifiers used by validators.
41
+ - Supporting modules include error_with_cause.js, number_utils.js, fast_parser.js, and template.js.
42
+
43
+ ```mermaid
44
+ graph TB
45
+ subgraph "Serializer Core"
46
+ V["validation.js"]
47
+ T["types.js"]
48
+ S["serializer.js"]
49
+ O["operations.js"]
50
+ CT["ChainTypes.js"]
51
+ end
52
+ subgraph "Support"
53
+ E["error_with_cause.js"]
54
+ NU["number_utils.js"]
55
+ FP["fast_parser.js"]
56
+ TM["template.js"]
57
+ end
58
+ V --> T
59
+ T --> S
60
+ S --> O
61
+ CT --> V
62
+ CT --> T
63
+ E --> S
64
+ NU --> T
65
+ FP --> T
66
+ TM --> S
67
+ ```
68
+
69
+ **Diagram sources**
70
+ - [validation.js](file://src/auth/serializer/src/validation.js#L29-L288)
71
+ - [types.js](file://src/auth/serializer/src/types.js#L1-L953)
72
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L1-L195)
73
+ - [operations.js](file://src/auth/serializer/src/operations.js#L1-L922)
74
+ - [ChainTypes.js](file://src/auth/serializer/src/ChainTypes.js#L1-L84)
75
+ - [error_with_cause.js](file://src/auth/serializer/src/error_with_cause.js#L1-L27)
76
+ - [number_utils.js](file://src/auth/serializer/src/number_utils.js#L1-L54)
77
+ - [fast_parser.js](file://src/auth/serializer/src/fast_parser.js#L1-L58)
78
+ - [template.js](file://src/auth/serializer/src/template.js#L1-L17)
79
+
80
+ **Section sources**
81
+ - [index.js](file://src/auth/serializer/index.js#L1-L20)
82
+ - [validation.js](file://src/auth/serializer/src/validation.js#L29-L288)
83
+ - [types.js](file://src/auth/serializer/src/types.js#L1-L953)
84
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L1-L195)
85
+ - [operations.js](file://src/auth/serializer/src/operations.js#L1-L922)
86
+ - [ChainTypes.js](file://src/auth/serializer/src/ChainTypes.js#L1-L84)
87
+ - [error_with_cause.js](file://src/auth/serializer/src/error_with_cause.js#L1-L27)
88
+ - [number_utils.js](file://src/auth/serializer/src/number_utils.js#L1-L54)
89
+ - [fast_parser.js](file://src/auth/serializer/src/fast_parser.js#L1-L58)
90
+ - [template.js](file://src/auth/serializer/src/template.js#L1-L17)
91
+
92
+ ## Core Components
93
+ - Validation rules: Centralized in validation.js, providing type checks, numeric conversions, overflow guards, and object-id parsing/formatting.
94
+ - Type serializers: Defined in types.js, each type’s appendByteBuffer/fromObject/toObject invokes validation rules.
95
+ - Operation serializers: Composed in operations.js from types.js, enforcing business constraints via type-level validators.
96
+ - Serialization pipeline: Implemented in serializer.js, which iterates fields, calls type serializers, and wraps exceptions with contextual messages.
97
+ - Error handling: error_with_cause.js provides nested error reporting to aid debugging.
98
+ - Utilities: number_utils.js handles implied decimal conversions; fast_parser.js provides optimized parsing for fixed-size data; template.js prints example JSON templates.
99
+
100
+ **Section sources**
101
+ - [validation.js](file://src/auth/serializer/src/validation.js#L29-L288)
102
+ - [types.js](file://src/auth/serializer/src/types.js#L1-L953)
103
+ - [operations.js](file://src/auth/serializer/src/operations.js#L1-L922)
104
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L1-L195)
105
+ - [error_with_cause.js](file://src/auth/serializer/src/error_with_cause.js#L1-L27)
106
+ - [number_utils.js](file://src/auth/serializer/src/number_utils.js#L1-L54)
107
+ - [fast_parser.js](file://src/auth/serializer/src/fast_parser.js#L1-L58)
108
+ - [template.js](file://src/auth/serializer/src/template.js#L1-L17)
109
+
110
+ ## Architecture Overview
111
+ The validation pipeline runs during three phases:
112
+ - fromByteBuffer: reads raw bytes and reconstructs objects, applying type-specific validators.
113
+ - appendByteBuffer: converts JS objects to byte buffers, validating and normalizing values.
114
+ - toObject: converts serialized data back to plain objects, ensuring consistent representation.
115
+
116
+ ```mermaid
117
+ sequenceDiagram
118
+ participant Caller as "Caller"
119
+ participant Ser as "Serializer"
120
+ participant Typ as "Type (types.js)"
121
+ participant Val as "Validators (validation.js)"
122
+ Caller->>Ser : appendByteBuffer(object)
123
+ Ser->>Typ : iterate fields and call appendByteBuffer(field)
124
+ Typ->>Val : apply validation rules (range, type, format)
125
+ Val-->>Typ : validated/converted value
126
+ Typ-->>Ser : write bytes to buffer
127
+ Ser-->>Caller : ByteBuffer
128
+ Caller->>Ser : fromByteBuffer(buffer)
129
+ Ser->>Typ : iterate fields and call fromByteBuffer
130
+ Typ->>Val : apply validation rules (format, ids)
131
+ Val-->>Typ : normalized value
132
+ Typ-->>Ser : parsed value
133
+ Ser-->>Caller : object
134
+ Caller->>Ser : toObject(serialized)
135
+ Ser->>Typ : iterate fields and call toObject
136
+ Typ->>Val : apply validation rules (ranges, types)
137
+ Val-->>Typ : normalized value
138
+ Typ-->>Ser : plain object
139
+ Ser-->>Caller : object
140
+ ```
141
+
142
+ **Diagram sources**
143
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L17-L138)
144
+ - [types.js](file://src/auth/serializer/src/types.js#L31-L953)
145
+ - [validation.js](file://src/auth/serializer/src/validation.js#L29-L288)
146
+
147
+ ## Detailed Component Analysis
148
+
149
+ ### Validation Rule Definitions (validation.js)
150
+ - Empty handling: Many validators skip validation for null/undefined except required.
151
+ - Primitive checks: string, number, whole_number, unsigned.
152
+ - Numeric conversion: to_number, to_long, to_string with overflow guards.
153
+ - Range checks: require_range with bounds validation.
154
+ - Pattern matching: require_test and require_match for regex validation.
155
+ - Object ID parsing: require_object_type, get_instance, require_relative_type, get_relative_instance, require_protocol_type, get_protocol_instance, get_protocol_type, get_protocol_type_name, require_implementation_type, get_implementation_instance.
156
+ - Overflow protection: no_overflow53 and no_overflow64 for safe numeric conversions.
157
+ - Protocol constants: MAX_SAFE_INT/MIN_SAFE_INT define safe 53-bit numeric limits.
158
+
159
+ ```mermaid
160
+ flowchart TD
161
+ Start(["Validator Entry"]) --> CheckEmpty["Check is_empty(value)"]
162
+ CheckEmpty --> IsEmpty{"Empty?"}
163
+ IsEmpty -- "Yes" --> ReturnUnchanged["Return value unchanged"]
164
+ IsEmpty -- "No" --> ApplyRule["Apply specific rule"]
165
+ ApplyRule --> RangeCheck{"Range check?"}
166
+ RangeCheck -- "Yes" --> ValidateRange["require_range(min,max)"]
167
+ RangeCheck -- "No" --> TypeCheck{"Type check?"}
168
+ TypeCheck -- "Yes" --> ValidateType["string/number/..."]
169
+ TypeCheck -- "No" --> PatternCheck{"Pattern match?"}
170
+ PatternCheck -- "Yes" --> RegexMatch["require_test/match"]
171
+ PatternCheck -- "No" --> ObjectIdCheck{"Object ID?"}
172
+ ObjectIdCheck -- "Yes" --> ParseId["require_object_type/get_instance"]
173
+ ObjectIdCheck -- "No" --> Convert["to_number/to_long/to_string"]
174
+ Convert --> OverflowCheck{"Overflow?"}
175
+ OverflowCheck -- "Yes" --> ThrowOverflow["Throw overflow error"]
176
+ OverflowCheck -- "No" --> Done(["Return validated value"])
177
+ ValidateRange --> Done
178
+ ValidateType --> Done
179
+ RegexMatch --> Done
180
+ ParseId --> Done
181
+ ThrowOverflow --> End(["Exit with error"])
182
+ ```
183
+
184
+ **Diagram sources**
185
+ - [validation.js](file://src/auth/serializer/src/validation.js#L31-L286)
186
+
187
+ **Section sources**
188
+ - [validation.js](file://src/auth/serializer/src/validation.js#L29-L288)
189
+
190
+ ### Constraint Checking in Type Serializers (types.js)
191
+ - Range constraints: uint8/uint16/uint32/varint32 use require_range to enforce bounds.
192
+ - Required fields: int64, string, bytes, array, set, map, static_variant, time_point_sec enforce presence and format.
193
+ - Numeric safety: asset uses number_utils for implied decimals; int64/uint64 rely on to_long and unsigned conversion.
194
+ - Object IDs: protocol_id_type, object_id_type, vote_id parse and validate identifiers.
195
+ - Optional fields: optional wraps underlying types and serializes null/undefined as a flag.
196
+ - Collections: array, set, map, fixed_array sort and deduplicate items where applicable.
197
+
198
+ ```mermaid
199
+ classDiagram
200
+ class Validators {
201
+ +required(value, field)
202
+ +require_range(min,max,value, field)
203
+ +to_number(value, field)
204
+ +to_long(value, field)
205
+ +to_string(value, field)
206
+ +require_object_type(rs,type,value, field)
207
+ +get_instance(rs,type,value, field)
208
+ +no_overflow53(value, field)
209
+ +no_overflow64(value, field)
210
+ }
211
+ class Types {
212
+ +uint8
213
+ +uint16
214
+ +uint32
215
+ +varint32
216
+ +int64
217
+ +uint64
218
+ +string
219
+ +bytes
220
+ +array
221
+ +set
222
+ +map
223
+ +fixed_array
224
+ +protocol_id_type
225
+ +object_id_type
226
+ +vote_id
227
+ +optional
228
+ +asset
229
+ +time_point_sec
230
+ }
231
+ Validators <.. Types : "used by"
232
+ ```
233
+
234
+ **Diagram sources**
235
+ - [validation.js](file://src/auth/serializer/src/validation.js#L29-L288)
236
+ - [types.js](file://src/auth/serializer/src/types.js#L30-L953)
237
+
238
+ **Section sources**
239
+ - [types.js](file://src/auth/serializer/src/types.js#L30-L953)
240
+
241
+ ### Error Handling Mechanisms (error_with_cause.js and serializer.js)
242
+ - Nested error reporting: ErrorWithCause augments messages with cause and stack traces.
243
+ - Serializer wrapping: serializer.js catches exceptions during fromByteBuffer/fromObject/toObject and throws with operation.field context.
244
+ - Debug printing: HEX_DUMP enables hex dumps of fields for inspection.
245
+
246
+ ```mermaid
247
+ sequenceDiagram
248
+ participant Ser as "Serializer"
249
+ participant Type as "Type"
250
+ participant Val as "Validator"
251
+ participant Err as "ErrorWithCause"
252
+ Ser->>Type : appendByteBuffer(field)
253
+ Type->>Val : validate(value)
254
+ Val-->>Type : throws Error
255
+ Type-->>Ser : propagate Error
256
+ Ser->>Err : wrap with operation.field context
257
+ Err-->>Ser : ErrorWithCause
258
+ Ser-->>Caller : ErrorWithCause
259
+ ```
260
+
261
+ **Diagram sources**
262
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L17-L138)
263
+ - [error_with_cause.js](file://src/auth/serializer/src/error_with_cause.js#L1-L27)
264
+
265
+ **Section sources**
266
+ - [error_with_cause.js](file://src/auth/serializer/src/error_with_cause.js#L1-L27)
267
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L17-L138)
268
+
269
+ ### Validation Pipeline Orchestration (serializer.js)
270
+ - Iteration: Serializers iterate keys and call type methods in order.
271
+ - fromByteBuffer: reads bytes, applies type parsing, and validates.
272
+ - appendByteBuffer: writes bytes, converting JS values to wire format.
273
+ - toObject: reconstructs plain objects, normalizing types and applying validation.
274
+ - Comparison: compare method uses first field comparator or hex-string comparison for buffers.
275
+
276
+ **Section sources**
277
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L17-L164)
278
+
279
+ ### Built-in Validators and Business Rule Enforcement (operations.js)
280
+ - Operations compose types to enforce business rules:
281
+ - vote: enforces weight range and string fields.
282
+ - content: enforces metadata length and JSON formatting.
283
+ - transfer/transfer_to_vesting/withdraw_vesting: enforce asset amounts and memo constraints.
284
+ - authority/account_update: enforce nested structures and thresholds.
285
+ - chain_properties_update/versioned_chain_properties_update: enforce versioned property sets.
286
+ - committee operations: enforce request IDs, votes, and payouts.
287
+ - paid subscription operations: enforce periods, amounts, and renewal flags.
288
+ - Static variants: operation.st_operations enumerate all operation types and their fields.
289
+
290
+ **Section sources**
291
+ - [operations.js](file://src/auth/serializer/src/operations.js#L73-L914)
292
+
293
+ ### Protocol Object ID Validation (ChainTypes.js and validation.js)
294
+ - Reserved spaces: relative_protocol_ids, protocol_ids, implementation_ids.
295
+ - Object type mapping: operations and object_type enums define canonical IDs.
296
+ - Validators: require_object_type/get_instance extract instance numbers from formatted IDs.
297
+
298
+ **Section sources**
299
+ - [ChainTypes.js](file://src/auth/serializer/src/ChainTypes.js#L7-L84)
300
+ - [validation.js](file://src/auth/serializer/src/validation.js#L158-L224)
301
+
302
+ ### Number Utilities and Precision (number_utils.js)
303
+ - Implied decimal conversion: toImpliedDecimal/fromImpliedDecimal handle precision and padding.
304
+ - Assertions: guard against invalid formats and excessive decimal digits.
305
+ - Safe numeric limits: align with no_overflow53/no_overflow64.
306
+
307
+ **Section sources**
308
+ - [number_utils.js](file://src/auth/serializer/src/number_utils.js#L10-L53)
309
+
310
+ ### Fast Parser Utilities (fast_parser.js)
311
+ - Fixed-size data: public_key, ripemd160, time_point_sec parsing/writing.
312
+ - Optimizations: avoid intermediate copies where possible.
313
+
314
+ **Section sources**
315
+ - [fast_parser.js](file://src/auth/serializer/src/fast_parser.js#L3-L57)
316
+
317
+ ### Template Generation (template.js)
318
+ - Generates example JSON with default values and annotations for debugging.
319
+
320
+ **Section sources**
321
+ - [template.js](file://src/auth/serializer/src/template.js#L1-L17)
322
+
323
+ ## Dependency Analysis
324
+ - validation.js is a pure function library imported by types.js and indirectly by operations.js.
325
+ - types.js depends on validation.js, ChainTypes.js, fast_parser.js, number_utils.js, and ecc types.
326
+ - operations.js depends on types.js and serializer.js.
327
+ - serializer.js depends on error_with_cause.js and ByteBuffer.
328
+ - Tests exercise validation via types_test.js and all_types.js.
329
+
330
+ ```mermaid
331
+ graph LR
332
+ V["validation.js"] --> T["types.js"]
333
+ CT["ChainTypes.js"] --> V
334
+ CT --> T
335
+ FP["fast_parser.js"] --> T
336
+ NU["number_utils.js"] --> T
337
+ T --> S["serializer.js"]
338
+ S --> O["operations.js"]
339
+ E["error_with_cause.js"] --> S
340
+ T --> O
341
+ ```
342
+
343
+ **Diagram sources**
344
+ - [validation.js](file://src/auth/serializer/src/validation.js#L1-L288)
345
+ - [types.js](file://src/auth/serializer/src/types.js#L1-L953)
346
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L1-L195)
347
+ - [operations.js](file://src/auth/serializer/src/operations.js#L1-L922)
348
+ - [ChainTypes.js](file://src/auth/serializer/src/ChainTypes.js#L1-L84)
349
+ - [error_with_cause.js](file://src/auth/serializer/src/error_with_cause.js#L1-L27)
350
+ - [fast_parser.js](file://src/auth/serializer/src/fast_parser.js#L1-L58)
351
+ - [number_utils.js](file://src/auth/serializer/src/number_utils.js#L1-L54)
352
+
353
+ **Section sources**
354
+ - [types.js](file://src/auth/serializer/src/types.js#L1-L953)
355
+ - [operations.js](file://src/auth/serializer/src/operations.js#L1-L922)
356
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L1-L195)
357
+ - [validation.js](file://src/auth/serializer/src/validation.js#L1-L288)
358
+ - [ChainTypes.js](file://src/auth/serializer/src/ChainTypes.js#L1-L84)
359
+ - [error_with_cause.js](file://src/auth/serializer/src/error_with_cause.js#L1-L27)
360
+ - [fast_parser.js](file://src/auth/serializer/src/fast_parser.js#L1-L58)
361
+ - [number_utils.js](file://src/auth/serializer/src/number_utils.js#L1-L54)
362
+
363
+ ## Performance Considerations
364
+ - Prefer to_number/to_long once per value; avoid repeated conversions.
365
+ - Use HEX_DUMP judiciously; it adds overhead by printing hex dumps.
366
+ - Sorting collections (array/set/map/static_variant) incurs O(n log n) cost; minimize unnecessary sorting.
367
+ - Avoid redundant regex matching; cache compiled patterns if reused frequently.
368
+ - Use fast_parser for fixed-size primitives to reduce overhead.
369
+ - Keep numeric conversions within safe ranges to prevent overflow checks.
370
+
371
+ [No sources needed since this section provides general guidance]
372
+
373
+ ## Troubleshooting Guide
374
+ Common validation failures and remedies:
375
+ - Required field missing: Ensure all required fields are present before serialization.
376
+ - Out-of-range values: Clamp values to declared ranges (e.g., uint8/uint16/uint32/varint32).
377
+ - Invalid object ID format: Use require_object_type or protocol_id_type helpers to format IDs correctly.
378
+ - Overflow errors: Use to_long and no_overflow64 for 64-bit values; use no_overflow53 for 53-bit safe numbers.
379
+ - Duplicate entries in set/map: Remove duplicates prior to serialization; serializers will reject duplicates.
380
+ - Incorrect asset precision: Use number_utils toImpliedDecimal/fromImpliedDecimal to normalize amounts.
381
+ - Date/time parsing: Ensure time_point_sec is a number of seconds since epoch or ISO string ending with Z.
382
+
383
+ Debugging techniques:
384
+ - Enable HEX_DUMP to inspect per-field hex dumps during serialization.
385
+ - Use template to generate example JSON with defaults and annotations.
386
+ - Wrap calls with try/catch and inspect ErrorWithCause messages for nested causes.
387
+ - Run tests that exercise edge cases (e.g., types_test.js and all_types.js).
388
+
389
+ **Section sources**
390
+ - [types_test.js](file://test/types_test.js#L11-L141)
391
+ - [all_types.js](file://test/all_types.js#L65-L115)
392
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L26-L49)
393
+ - [template.js](file://src/auth/serializer/src/template.js#L1-L17)
394
+ - [error_with_cause.js](file://src/auth/serializer/src/error_with_cause.js#L18-L23)
395
+
396
+ ## Conclusion
397
+ The validation system integrates tightly with the serializer pipeline to ensure data integrity across the wire. Built-in validators enforce type correctness, numeric safety, and protocol-specific object IDs. The pipeline’s error handling provides actionable diagnostics, while utilities and tests help maintain robustness. Following the best practices outlined here will help preserve consistency across the blockchain network.
398
+
399
+ [No sources needed since this section summarizes without analyzing specific files]
400
+
401
+ ## Appendices
402
+
403
+ ### Example Workflows
404
+
405
+ #### Input Validation Workflow
406
+ ```mermaid
407
+ flowchart TD
408
+ A["Receive JS object"] --> B["Serializer.fromObject"]
409
+ B --> C["Type.fromObject(value)"]
410
+ C --> D["Validators.apply(value)"]
411
+ D --> E{"Valid?"}
412
+ E -- "No" --> F["Throw ErrorWithCause"]
413
+ E -- "Yes" --> G["Return normalized value"]
414
+ G --> H["Append to ByteBuffer"]
415
+ ```
416
+
417
+ **Diagram sources**
418
+ - [serializer.js](file://src/auth/serializer/src/serializer.js#L79-L99)
419
+ - [types.js](file://src/auth/serializer/src/types.js#L149-L167)
420
+ - [validation.js](file://src/auth/serializer/src/validation.js#L149-L156)
421
+
422
+ #### Business Rule Enforcement (Transfer)
423
+ - Amount must be a valid asset string with implied decimals.
424
+ - Memo must be a string.
425
+ - From/To must be non-empty strings.
426
+ - Enforced by asset and string serializers and require_range for weights.
427
+
428
+ **Section sources**
429
+ - [types.js](file://src/auth/serializer/src/types.js#L30-L69)
430
+ - [operations.js](file://src/auth/serializer/src/operations.js#L197-L212)
431
+
432
+ ### Best Practices for Data Consistency
433
+ - Always validate inputs before serialization.
434
+ - Use protocol_id_type helpers to ensure consistent object IDs.
435
+ - Normalize numeric values with number_utils to avoid precision drift.
436
+ - Keep operations deterministic by sorting sets/maps and arrays where required.
437
+ - Add unit tests covering boundary conditions and error paths.
438
+
439
+ [No sources needed since this section provides general guidance]