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.
- package/.qoder/docs/spec/viz-dns-nameserver-spec.md +982 -0
- package/.qoder/docs/viz-cpp-node-docs/data-types.md +322 -0
- package/.qoder/docs/viz-cpp-node-docs/index.md +160 -0
- package/.qoder/docs/viz-cpp-node-docs/op-account-market.md +236 -0
- package/.qoder/docs/viz-cpp-node-docs/op-account.md +199 -0
- package/.qoder/docs/viz-cpp-node-docs/op-award.md +162 -0
- package/.qoder/docs/viz-cpp-node-docs/op-committee.md +193 -0
- package/.qoder/docs/viz-cpp-node-docs/op-content.md +157 -0
- package/.qoder/docs/viz-cpp-node-docs/op-escrow.md +224 -0
- package/.qoder/docs/viz-cpp-node-docs/op-invite.md +219 -0
- package/.qoder/docs/viz-cpp-node-docs/op-proposal.md +229 -0
- package/.qoder/docs/viz-cpp-node-docs/op-recovery.md +188 -0
- package/.qoder/docs/viz-cpp-node-docs/op-subscription.md +146 -0
- package/.qoder/docs/viz-cpp-node-docs/op-transfer-vesting.md +224 -0
- package/.qoder/docs/viz-cpp-node-docs/op-witness.md +252 -0
- package/.qoder/docs/viz-cpp-node-docs/plugins.md +887 -0
- package/.qoder/docs/viz-cpp-node-docs/virtual-operations.md +513 -0
- package/.qoder/repowiki/en/content/API Reference/API Reference.md +724 -0
- package/.qoder/repowiki/en/content/API Reference/Configuration Options.md +410 -0
- package/.qoder/repowiki/en/content/API Reference/Core API Methods.md +547 -0
- package/.qoder/repowiki/en/content/API Reference/Streaming APIs.md +380 -0
- package/.qoder/repowiki/en/content/API Reference/Transport Layer.md +341 -0
- package/.qoder/repowiki/en/content/API Reference/VIZ Blockchain Operations Coverage Status.md +427 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Authentication & Cryptography.md +430 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Digital Signatures.md +462 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Key Management.md +456 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Memo Encryption.md +331 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Security Practices.md +488 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Broadcast Transactions.md +432 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Network Broadcasting.md +418 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Operation Construction.md +352 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Transaction Preparation.md +353 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Transaction Signing.md +404 -0
- package/.qoder/repowiki/en/content/Data Serialization/Data Serialization.md +540 -0
- package/.qoder/repowiki/en/content/Data Serialization/Encoding & Decoding.md +463 -0
- package/.qoder/repowiki/en/content/Data Serialization/Object Templates.md +413 -0
- package/.qoder/repowiki/en/content/Data Serialization/Type System.md +514 -0
- package/.qoder/repowiki/en/content/Data Serialization/Validation Rules.md +439 -0
- package/.qoder/repowiki/en/content/Examples & Tutorials.md +485 -0
- package/.qoder/repowiki/en/content/Getting Started.md +345 -0
- package/.qoder/repowiki/en/content/Testing & Development.md +637 -0
- package/.qoder/repowiki/en/content/Utilities & Helpers.md +557 -0
- package/.qoder/repowiki/en/meta/repowiki-metadata.json +1 -0
- package/VIZ-JS-LIB-COVERAGE-STATUS.md +356 -0
- package/config.json +3 -1
- package/dist/statistics.html +1 -1
- package/dist/viz-tests.min.js +32 -42
- package/dist/viz-tests.min.js.gz +0 -0
- package/dist/viz.min.js +8 -18
- package/dist/viz.min.js.gz +0 -0
- package/lib/api/methods.js +24 -0
- package/lib/auth/serializer/src/ChainTypes.js +2 -1
- package/lib/auth/serializer/src/operations.js +35 -2
- package/lib/broadcast/index.js +29 -15
- package/lib/broadcast/operations.js +4 -0
- package/lib/dns.js +658 -0
- package/lib/index.js +3 -1
- package/package.json +3 -2
- package/test/dns.test.js +395 -0
- package/webpack/makeConfig.js +3 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
# Utilities & Helpers
|
|
2
|
+
|
|
3
|
+
<cite>
|
|
4
|
+
**Referenced Files in This Document**
|
|
5
|
+
- [src/index.js](file://src/index.js)
|
|
6
|
+
- [src/browser.js](file://src/browser.js)
|
|
7
|
+
- [src/config.js](file://src/config.js)
|
|
8
|
+
- [config.json](file://config.json)
|
|
9
|
+
- [src/utils.js](file://src/utils.js)
|
|
10
|
+
- [src/broadcast/helpers.js](file://src/broadcast/helpers.js)
|
|
11
|
+
- [src/formatter.js](file://src/formatter.js)
|
|
12
|
+
- [src/dns.js](file://src/dns.js)
|
|
13
|
+
- [src/auth/serializer/src/number_utils.js](file://src/auth/serializer/src/number_utils.js)
|
|
14
|
+
- [src/auth/ecc/src/key_utils.js](file://src/auth/ecc/src/key_utils.js)
|
|
15
|
+
- [src/auth/ecc/src/address.js](file://src/auth/ecc/src/address.js)
|
|
16
|
+
- [test/number_utils.js](file://test/number_utils.js)
|
|
17
|
+
- [test/Crypto.js](file://test/Crypto.js)
|
|
18
|
+
- [test/dns.test.js](file://test/dns.test.js)
|
|
19
|
+
- [examples/get-post-content.js](file://examples/get-post-content.js)
|
|
20
|
+
</cite>
|
|
21
|
+
|
|
22
|
+
## Update Summary
|
|
23
|
+
**Changes Made**
|
|
24
|
+
- Added comprehensive DNS Nameserver module documentation covering validation functions, record creation, parsing, and manipulation capabilities for VIZ blockchain NS records (A and TXT)
|
|
25
|
+
- Updated project structure to include DNS module integration
|
|
26
|
+
- Enhanced core components section to reflect new decentralized domain name resolution capabilities
|
|
27
|
+
- Added practical DNS usage examples and integration patterns
|
|
28
|
+
- Updated browser export to include DNS module for browser environments
|
|
29
|
+
|
|
30
|
+
## Table of Contents
|
|
31
|
+
1. [Introduction](#introduction)
|
|
32
|
+
2. [Project Structure](#project-structure)
|
|
33
|
+
3. [Core Components](#core-components)
|
|
34
|
+
4. [Architecture Overview](#architecture-overview)
|
|
35
|
+
5. [Detailed Component Analysis](#detailed-component-analysis)
|
|
36
|
+
6. [DNS Nameserver Module](#dns-nameserver-module)
|
|
37
|
+
7. [Dependency Analysis](#dependency-analysis)
|
|
38
|
+
8. [Performance Considerations](#performance-considerations)
|
|
39
|
+
9. [Troubleshooting Guide](#troubleshooting-guide)
|
|
40
|
+
10. [Conclusion](#conclusion)
|
|
41
|
+
11. [Appendices](#appendices)
|
|
42
|
+
|
|
43
|
+
## Introduction
|
|
44
|
+
This document describes the utility functions and helper modules in the VIZ JavaScript library with a focus on:
|
|
45
|
+
- Formatting utilities for currency display, numeric conversions, and string processing
|
|
46
|
+
- Configuration management and environment detection
|
|
47
|
+
- Browser compatibility helpers
|
|
48
|
+
- **New**: DNS Nameserver module for decentralized domain name resolution
|
|
49
|
+
- Practical usage patterns, performance tips, and cross-platform considerations
|
|
50
|
+
- Guidelines for extending utilities consistently across Node.js and browser environments
|
|
51
|
+
|
|
52
|
+
## Project Structure
|
|
53
|
+
The utilities and helpers are organized under the src directory and integrated via module exports and environment-aware entry points. The primary modules covered here are:
|
|
54
|
+
- Configuration and environment exposure
|
|
55
|
+
- Numeric formatting and currency helpers
|
|
56
|
+
- String processing and content helpers
|
|
57
|
+
- Broadcast helpers for authority management
|
|
58
|
+
- Number utilities for implied decimals
|
|
59
|
+
- Cryptographic key utilities and address helpers
|
|
60
|
+
- **New**: DNS Nameserver module for decentralized domain resolution
|
|
61
|
+
|
|
62
|
+
```mermaid
|
|
63
|
+
graph TB
|
|
64
|
+
subgraph "Entry Points"
|
|
65
|
+
IDX["src/index.js"]
|
|
66
|
+
BRW["src/browser.js"]
|
|
67
|
+
end
|
|
68
|
+
subgraph "Utilities"
|
|
69
|
+
CFG["src/config.js"]
|
|
70
|
+
UTL["src/utils.js"]
|
|
71
|
+
FMT["src/formatter.js"]
|
|
72
|
+
DNS["src/dns.js"]
|
|
73
|
+
NMB["src/auth/serializer/src/number_utils.js"]
|
|
74
|
+
KEY["src/auth/ecc/src/key_utils.js"]
|
|
75
|
+
ADH["src/auth/ecc/src/address.js"]
|
|
76
|
+
BHL["src/broadcast/helpers.js"]
|
|
77
|
+
end
|
|
78
|
+
IDX --> CFG
|
|
79
|
+
IDX --> UTL
|
|
80
|
+
IDX --> FMT
|
|
81
|
+
IDX --> DNS
|
|
82
|
+
IDX --> NMB
|
|
83
|
+
IDX --> KEY
|
|
84
|
+
IDX --> ADH
|
|
85
|
+
IDX --> BHL
|
|
86
|
+
BRW --> IDX
|
|
87
|
+
BRW --> CFG
|
|
88
|
+
BRW --> UTL
|
|
89
|
+
BRW --> FMT
|
|
90
|
+
BRW --> DNS
|
|
91
|
+
BRW --> KEY
|
|
92
|
+
BRW --> ADH
|
|
93
|
+
BRW --> BHL
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Diagram sources**
|
|
97
|
+
- [src/index.js:1-22](file://src/index.js#L1-L22)
|
|
98
|
+
- [src/browser.js:1-30](file://src/browser.js#L1-L30)
|
|
99
|
+
- [src/config.js:1-10](file://src/config.js#L1-L10)
|
|
100
|
+
- [src/utils.js:1-348](file://src/utils.js#L1-L348)
|
|
101
|
+
- [src/formatter.js:1-87](file://src/formatter.js#L1-L87)
|
|
102
|
+
- [src/dns.js:1-575](file://src/dns.js#L1-L575)
|
|
103
|
+
- [src/auth/serializer/src/number_utils.js:1-54](file://src/auth/serializer/src/number_utils.js#L1-L54)
|
|
104
|
+
- [src/auth/ecc/src/key_utils.js:1-89](file://src/auth/ecc/src/key_utils.js#L1-L89)
|
|
105
|
+
- [src/auth/ecc/src/address.js:1-57](file://src/auth/ecc/src/address.js#L1-L57)
|
|
106
|
+
- [src/broadcast/helpers.js:1-82](file://src/broadcast/helpers.js#L1-L82)
|
|
107
|
+
|
|
108
|
+
**Section sources**
|
|
109
|
+
- [src/index.js:1-22](file://src/index.js#L1-L22)
|
|
110
|
+
- [src/browser.js:1-30](file://src/browser.js#L1-L30)
|
|
111
|
+
|
|
112
|
+
## Core Components
|
|
113
|
+
- Configuration management: centralized getters/setters backed by a JSON configuration file
|
|
114
|
+
- Environment detection and globals: exposes a unified viz object in both browser and Node.js contexts
|
|
115
|
+
- Formatting utilities: currency-like formatting, numeric estimations, suggested passwords, and content permlinks
|
|
116
|
+
- Numeric utilities: conversion between implied decimals and formatted strings
|
|
117
|
+
- String processing: camelCase conversion and validation helpers
|
|
118
|
+
- Broadcast helpers: account authority management helpers
|
|
119
|
+
- Cryptographic helpers: entropy collection, random key generation, and address encoding/decoding
|
|
120
|
+
- **New**: DNS Nameserver helpers: validation functions, record creation, parsing, and metadata manipulation for decentralized domain resolution
|
|
121
|
+
|
|
122
|
+
**Section sources**
|
|
123
|
+
- [src/config.js:1-10](file://src/config.js#L1-L10)
|
|
124
|
+
- [config.json:1-7](file://config.json#L1-L7)
|
|
125
|
+
- [src/browser.js:1-30](file://src/browser.js#L1-L30)
|
|
126
|
+
- [src/formatter.js:1-87](file://src/formatter.js#L1-L87)
|
|
127
|
+
- [src/auth/serializer/src/number_utils.js:1-54](file://src/auth/serializer/src/number_utils.js#L1-L54)
|
|
128
|
+
- [src/utils.js:1-348](file://src/utils.js#L1-L348)
|
|
129
|
+
- [src/broadcast/helpers.js:1-82](file://src/broadcast/helpers.js#L1-L82)
|
|
130
|
+
- [src/auth/ecc/src/key_utils.js:1-89](file://src/auth/ecc/src/key_utils.js#L1-L89)
|
|
131
|
+
- [src/auth/ecc/src/address.js:1-57](file://src/auth/ecc/src/address.js#L1-L57)
|
|
132
|
+
- [src/dns.js:1-575](file://src/dns.js#L1-L575)
|
|
133
|
+
|
|
134
|
+
## Architecture Overview
|
|
135
|
+
The library exposes a cohesive API surface through two entry points:
|
|
136
|
+
- Node.js: src/index.js exports the entire suite including the new DNS module
|
|
137
|
+
- Browser: src/browser.js wraps the Node exports and attaches to window/global
|
|
138
|
+
|
|
139
|
+
Formatting utilities are provided by a factory that receives the API client, enabling dynamic property retrieval and estimation functions. Numeric and cryptographic utilities are standalone modules designed for reuse across modules. The DNS module integrates seamlessly with the existing architecture for decentralized domain name resolution.
|
|
140
|
+
|
|
141
|
+
```mermaid
|
|
142
|
+
graph TB
|
|
143
|
+
API["API Client"]
|
|
144
|
+
FMT["formatter.js (factory)"]
|
|
145
|
+
CFG["config.js"]
|
|
146
|
+
UTL["utils.js"]
|
|
147
|
+
DNS["dns.js"]
|
|
148
|
+
NMB["number_utils.js"]
|
|
149
|
+
KEY["key_utils.js"]
|
|
150
|
+
ADH["address.js"]
|
|
151
|
+
BHL["broadcast/helpers.js"]
|
|
152
|
+
API --> FMT
|
|
153
|
+
CFG --> FMT
|
|
154
|
+
CFG --> ADH
|
|
155
|
+
KEY --> FMT
|
|
156
|
+
NMB --> FMT
|
|
157
|
+
UTL --> FMT
|
|
158
|
+
DNS --> FMT
|
|
159
|
+
BHL --> API
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Diagram sources**
|
|
163
|
+
- [src/formatter.js:1-87](file://src/formatter.js#L1-L87)
|
|
164
|
+
- [src/config.js:1-10](file://src/config.js#L1-L10)
|
|
165
|
+
- [src/auth/serializer/src/number_utils.js:1-54](file://src/auth/serializer/src/number_utils.js#L1-L54)
|
|
166
|
+
- [src/auth/ecc/src/key_utils.js:1-89](file://src/auth/ecc/src/key_utils.js#L1-L89)
|
|
167
|
+
- [src/auth/ecc/src/address.js:1-57](file://src/auth/ecc/src/address.js#L1-L57)
|
|
168
|
+
- [src/broadcast/helpers.js:1-82](file://src/broadcast/helpers.js#L1-L82)
|
|
169
|
+
- [src/dns.js:1-575](file://src/dns.js#L1-L575)
|
|
170
|
+
|
|
171
|
+
## Detailed Component Analysis
|
|
172
|
+
|
|
173
|
+
### Configuration Management
|
|
174
|
+
- Purpose: centralize runtime configuration with simple get/set accessors
|
|
175
|
+
- Behavior: loads defaults from config.json and exposes functions to retrieve or update values
|
|
176
|
+
- Usage pattern: import config and call get(key) or set(key, value)
|
|
177
|
+
|
|
178
|
+
```mermaid
|
|
179
|
+
flowchart TD
|
|
180
|
+
Start(["Load config"]) --> Read["Read defaultConfig from config.json"]
|
|
181
|
+
Read --> Expose["Expose get(key) and set(key,value)"]
|
|
182
|
+
Expose --> Use["Modules call config.get/set"]
|
|
183
|
+
Use --> End(["Done"])
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Diagram sources**
|
|
187
|
+
- [src/config.js:1-10](file://src/config.js#L1-L10)
|
|
188
|
+
- [config.json:1-7](file://config.json#L1-L7)
|
|
189
|
+
|
|
190
|
+
**Section sources**
|
|
191
|
+
- [src/config.js:1-10](file://src/config.js#L1-L10)
|
|
192
|
+
- [config.json:1-7](file://config.json#L1-L7)
|
|
193
|
+
|
|
194
|
+
### Environment Detection and Global Exposure
|
|
195
|
+
- Purpose: ensure the library is usable in both browser and Node.js
|
|
196
|
+
- Behavior: creates a viz object containing all modules and attaches it to window/global when available
|
|
197
|
+
- Cross-platform: guards typeof window and typeof global to avoid errors in non-browser/non-node environments
|
|
198
|
+
- **Updated**: Now includes DNS module in browser exports
|
|
199
|
+
|
|
200
|
+
```mermaid
|
|
201
|
+
sequenceDiagram
|
|
202
|
+
participant Loader as "Module Loader"
|
|
203
|
+
participant Browser as "src/browser.js"
|
|
204
|
+
participant Node as "src/index.js"
|
|
205
|
+
participant Globals as "Global Objects"
|
|
206
|
+
Loader->>Browser : require('./browser')
|
|
207
|
+
Browser->>Node : require('./index.js')
|
|
208
|
+
Browser->>Globals : attach viz to window/global
|
|
209
|
+
Loader-->>Browser : exports viz
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Diagram sources**
|
|
213
|
+
- [src/browser.js:1-30](file://src/browser.js#L1-L30)
|
|
214
|
+
- [src/index.js:1-22](file://src/index.js#L1-L22)
|
|
215
|
+
|
|
216
|
+
**Section sources**
|
|
217
|
+
- [src/browser.js:1-30](file://src/browser.js#L1-L30)
|
|
218
|
+
- [src/index.js:1-22](file://src/index.js#L1-L22)
|
|
219
|
+
|
|
220
|
+
### Formatting Utilities (Currency, Numbers, Strings)
|
|
221
|
+
- Currency-like formatting: adds thousands separators to numeric strings
|
|
222
|
+
- Numeric estimations: computes account value using vesting shares and global props
|
|
223
|
+
- Password suggestion: generates a random WIF-derived password
|
|
224
|
+
- Content permlink generation: builds deterministic permlinks with timestamps
|
|
225
|
+
- Amount formatting: appends asset suffix to amounts
|
|
226
|
+
- String processing: camelCase conversion and account name validation
|
|
227
|
+
|
|
228
|
+
```mermaid
|
|
229
|
+
flowchart TD
|
|
230
|
+
Start(["estimateAccountValue(account, options)"]) --> CheckGprops{"Has gprops?"}
|
|
231
|
+
CheckGprops --> |No| Fetch["Fetch state via VIZ_API.getStateAsync"]
|
|
232
|
+
CheckGprops --> |Yes| Compute["Compute vestingVIZ from gprops"]
|
|
233
|
+
Fetch --> Compute
|
|
234
|
+
Compute --> Sum["Sum balance + vesting_viz"]
|
|
235
|
+
Sum --> Format["Format to fixed(3)"]
|
|
236
|
+
Format --> End(["Return formatted value"])
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
**Diagram sources**
|
|
240
|
+
- [src/formatter.js:19-49](file://src/formatter.js#L19-L49)
|
|
241
|
+
|
|
242
|
+
**Section sources**
|
|
243
|
+
- [src/formatter.js:1-87](file://src/formatter.js#L1-L87)
|
|
244
|
+
- [src/utils.js:10-47](file://src/utils.js#L10-L47)
|
|
245
|
+
|
|
246
|
+
### Numeric Utilities (Implied Decimals)
|
|
247
|
+
- Purpose: convert between human-readable numbers and implied-decimal strings for asset precision
|
|
248
|
+
- Functions: toImpliedDecimal(number, precision), fromImpliedDecimal(number, precision)
|
|
249
|
+
- Validation: strict assertions for overflow, invalid formats, and precision limits
|
|
250
|
+
|
|
251
|
+
```mermaid
|
|
252
|
+
flowchart TD
|
|
253
|
+
A["toImpliedDecimal(number, precision)"] --> B["Normalize input to string"]
|
|
254
|
+
B --> C{"Contains '.'?"}
|
|
255
|
+
C --> |Yes| Split["Split into whole and decimal parts"]
|
|
256
|
+
C --> |No| WholeOnly["Set decimal part empty"]
|
|
257
|
+
Split --> Pad["Pad decimal to precision length"]
|
|
258
|
+
WholeOnly --> Pad
|
|
259
|
+
Pad --> Trim["Trim leading zeros from whole"]
|
|
260
|
+
Trim --> Out["Return combined string"]
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Diagram sources**
|
|
264
|
+
- [src/auth/serializer/src/number_utils.js:10-35](file://src/auth/serializer/src/number_utils.js#L10-L35)
|
|
265
|
+
|
|
266
|
+
**Section sources**
|
|
267
|
+
- [src/auth/serializer/src/number_utils.js:1-54](file://src/auth/serializer/src/number_utils.js#L1-L54)
|
|
268
|
+
- [test/number_utils.js:1-29](file://test/number_utils.js#L1-L29)
|
|
269
|
+
|
|
270
|
+
### String Processing and Validation
|
|
271
|
+
- camelCase conversion: transforms snake_case identifiers to camelCase
|
|
272
|
+
- Account name validation: enforces naming rules for segmented account names
|
|
273
|
+
|
|
274
|
+
```mermaid
|
|
275
|
+
flowchart TD
|
|
276
|
+
S(["validateAccountName(value)"]) --> Empty{"Empty?"}
|
|
277
|
+
Empty --> |Yes| Err1["Return 'not be empty'"]
|
|
278
|
+
Empty --> |No| Len["Check length 2..25"]
|
|
279
|
+
Len --> Segments["Split by '.' and iterate segments"]
|
|
280
|
+
Segments --> Rules["Validate start/end, allowed chars, dashes, min length"]
|
|
281
|
+
Rules --> OK{"All valid?"}
|
|
282
|
+
OK --> |Yes| Null["Return null"]
|
|
283
|
+
OK --> |No| Err["Return violation message"]
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Diagram sources**
|
|
287
|
+
- [src/utils.js:10-47](file://src/utils.js#L10-L47)
|
|
288
|
+
|
|
289
|
+
**Section sources**
|
|
290
|
+
- [src/utils.js:1-8](file://src/utils.js#L1-L8)
|
|
291
|
+
|
|
292
|
+
### Broadcast Helpers (Authority Management)
|
|
293
|
+
- Purpose: add/remove authorized accounts to a user's authority structures
|
|
294
|
+
- Behavior: fetch account, update account_auths, and issue account_update transaction via broadcaster
|
|
295
|
+
|
|
296
|
+
```mermaid
|
|
297
|
+
sequenceDiagram
|
|
298
|
+
participant Caller as "Caller"
|
|
299
|
+
participant Helper as "helpers.js"
|
|
300
|
+
participant API as "api.getAccountsAsync"
|
|
301
|
+
participant Broadcaster as "Broadcaster.accountUpdate"
|
|
302
|
+
Caller->>Helper : addAccountAuth(activeWif, username, authorizedUsername, role, cb)
|
|
303
|
+
Helper->>API : fetch account by username
|
|
304
|
+
API-->>Helper : account object
|
|
305
|
+
Helper->>Helper : append authorizedUsername with default weight
|
|
306
|
+
Helper->>Broadcaster : accountUpdate with updated authority
|
|
307
|
+
Broadcaster-->>Helper : callback result
|
|
308
|
+
Helper-->>Caller : invoke cb(null, result)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Diagram sources**
|
|
312
|
+
- [src/broadcast/helpers.js:6-41](file://src/broadcast/helpers.js#L6-L41)
|
|
313
|
+
|
|
314
|
+
**Section sources**
|
|
315
|
+
- [src/broadcast/helpers.js:1-82](file://src/broadcast/helpers.js#L1-L82)
|
|
316
|
+
|
|
317
|
+
### Cryptographic Helpers (Entropy, Keys, Addresses)
|
|
318
|
+
- Entropy and randomness: collects browser entropy, hashes buffers, and produces 32-byte random keys
|
|
319
|
+
- Address encoding/decoding: validates prefixes, decodes base58, and verifies checksums
|
|
320
|
+
|
|
321
|
+
```mermaid
|
|
322
|
+
flowchart TD
|
|
323
|
+
Start(["get_random_key(entropy)"]) --> Bytes["random32ByteBuffer(entropy)"]
|
|
324
|
+
Bytes --> Hash["Hash buffers and concatenate"]
|
|
325
|
+
Hash --> Key["PrivateKey.fromBuffer(...)"]
|
|
326
|
+
Key --> End(["Return PrivateKey"])
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
**Diagram sources**
|
|
330
|
+
- [src/auth/ecc/src/key_utils.js:29-55](file://src/auth/ecc/src/key_utils.js#L29-L55)
|
|
331
|
+
|
|
332
|
+
**Section sources**
|
|
333
|
+
- [src/auth/ecc/src/key_utils.js:1-89](file://src/auth/ecc/src/key_utils.js#L1-L89)
|
|
334
|
+
- [src/auth/ecc/src/address.js:1-57](file://src/auth/ecc/src/address.js#L1-L57)
|
|
335
|
+
|
|
336
|
+
### Voice Utilities (Content Publishing)
|
|
337
|
+
- Purpose: helpers for publishing text, encoded text, publications, and related operations
|
|
338
|
+
- Features: previous sequence handling, optional reply/share, optional beneficiaries, passphrase-based encryption
|
|
339
|
+
- Notes: integrates with API and broadcast modules to submit custom operations
|
|
340
|
+
|
|
341
|
+
```mermaid
|
|
342
|
+
sequenceDiagram
|
|
343
|
+
participant Caller as "Caller"
|
|
344
|
+
participant Utils as "utils.js"
|
|
345
|
+
participant API as "viz.api.getAccount"
|
|
346
|
+
participant Broadcast as "viz.broadcast.custom"
|
|
347
|
+
Caller->>Utils : voiceText(...)
|
|
348
|
+
Utils->>API : getAccount(account, 'V')
|
|
349
|
+
API-->>Utils : { custom_sequence_block_num }
|
|
350
|
+
Utils->>Broadcast : custom([...], 'V', JSON.stringify(object))
|
|
351
|
+
Broadcast-->>Utils : { err, result }
|
|
352
|
+
Utils-->>Caller : callback(!err)
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**Diagram sources**
|
|
356
|
+
- [src/utils.js:84-127](file://src/utils.js#L84-L127)
|
|
357
|
+
|
|
358
|
+
**Section sources**
|
|
359
|
+
- [src/utils.js:49-206](file://src/utils.js#L49-L206)
|
|
360
|
+
|
|
361
|
+
## DNS Nameserver Module
|
|
362
|
+
|
|
363
|
+
**New Section**: The VIZ DNS Nameserver module provides comprehensive support for decentralized domain name resolution on the VIZ blockchain. It enables storing and managing DNS records (A and TXT) within account metadata, facilitating human-readable domain names for blockchain applications.
|
|
364
|
+
|
|
365
|
+
### Core Functionality
|
|
366
|
+
The DNS module offers four main categories of functionality:
|
|
367
|
+
|
|
368
|
+
#### Validation Functions
|
|
369
|
+
- `isValidIPv4(ipv4)`: Validates IPv4 address format using regex pattern matching
|
|
370
|
+
- `isValidSHA256Hash(hash)`: Validates SHA256 hexadecimal hash strings (exactly 64 hex characters)
|
|
371
|
+
- `isValidTTL(ttl)`: Validates time-to-live values (positive integers)
|
|
372
|
+
- `isValidTxtRecord(txt)`: Validates TXT record values (1-256 characters)
|
|
373
|
+
- `isValidSslTxtRecord(txt)`: Specialized validator for SSL certificate hash records
|
|
374
|
+
|
|
375
|
+
#### Record Creation Functions
|
|
376
|
+
- `createARecord(ipv4)`: Creates A record tuples for IPv4 address resolution
|
|
377
|
+
- `createSslTxtRecord(hash)`: Creates SSL certificate hash TXT records
|
|
378
|
+
- `createTxtRecord(value)`: Creates generic TXT record tuples
|
|
379
|
+
- `createNsMetadata(options)`: Creates complete NS metadata objects with TTL support
|
|
380
|
+
|
|
381
|
+
#### Parsing and Extraction Functions
|
|
382
|
+
- `parseNsMetadata(jsonMetadata)`: Parses NS metadata from JSON strings or objects
|
|
383
|
+
- `extractARecords(jsonMetadata)`: Extracts all IPv4 addresses from NS records
|
|
384
|
+
- `extractSslHash(jsonMetadata)`: Extracts SSL certificate hash from TXT records
|
|
385
|
+
- `extractTxtRecords(jsonMetadata)`: Extracts all TXT record values
|
|
386
|
+
- `extractTtl(jsonMetadata)`: Extracts TTL value with default fallback
|
|
387
|
+
- `getNsSummary(jsonMetadata)`: Provides comprehensive record summary
|
|
388
|
+
- `hasNsRecords(jsonMetadata)`: Checks for presence of NS records
|
|
389
|
+
|
|
390
|
+
#### Metadata Manipulation Functions
|
|
391
|
+
- `mergeNsMetadata(existingMetadata, nsData)`: Merges NS data into existing metadata
|
|
392
|
+
- `removeNsMetadata(existingMetadata)`: Removes NS data from metadata
|
|
393
|
+
- `addARecord(jsonMetadata, ipv4)`: Adds A record to existing metadata
|
|
394
|
+
- `removeARecord(jsonMetadata, ipv4)`: Removes specific A record
|
|
395
|
+
- `setSslHash(jsonMetadata, hash)`: Sets or updates SSL hash
|
|
396
|
+
- `removeSslHash(jsonMetadata)`: Removes SSL hash record
|
|
397
|
+
- `setTtl(jsonMetadata, ttl)`: Updates TTL value
|
|
398
|
+
- `validateNsMetadata(nsData)`: Comprehensive metadata validation
|
|
399
|
+
|
|
400
|
+
### Constants and Configuration
|
|
401
|
+
The module defines several important constants:
|
|
402
|
+
- `DEFAULT_TTL`: 28800 seconds (8 hours) default TTL
|
|
403
|
+
- `MAX_TXT_LENGTH`: 256 character limit for TXT records
|
|
404
|
+
- `SHA256_HEX_LENGTH`: 64 character length for SHA256 hashes
|
|
405
|
+
|
|
406
|
+
### Usage Examples
|
|
407
|
+
|
|
408
|
+
#### Creating DNS Records
|
|
409
|
+
```javascript
|
|
410
|
+
const viz = require('viz-js-lib');
|
|
411
|
+
|
|
412
|
+
// Create A records for domain resolution
|
|
413
|
+
const nsMetadata = viz.dns.createNsMetadata({
|
|
414
|
+
aRecords: ['188.120.231.153', '192.168.1.100'],
|
|
415
|
+
sslHash: '4a4613daef37cbc5c4a5156cd7b24ea2e6ee2e5f1e7461262a2df2b63cbf17e2',
|
|
416
|
+
ttl: 28800
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// Parse existing metadata
|
|
420
|
+
const parsed = viz.dns.parseNsMetadata(account.json_metadata);
|
|
421
|
+
const aRecords = viz.dns.extractARecords(parsed);
|
|
422
|
+
const sslHash = viz.dns.extractSslHash(parsed);
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
#### Validating DNS Data
|
|
426
|
+
```javascript
|
|
427
|
+
// Validate individual components
|
|
428
|
+
const isValidIP = viz.dns.isValidIPv4('188.120.231.153');
|
|
429
|
+
const isValidSSL = viz.dns.isValidSslTxtRecord('ssl=4a4613daef37cbc5c4a5156cd7b24ea2e6ee2e5f1e7461262a2df2b63cbf17e2');
|
|
430
|
+
const isValidTTL = viz.dns.isValidTTL(28800);
|
|
431
|
+
|
|
432
|
+
// Validate complete metadata structure
|
|
433
|
+
const validation = viz.dns.validateNsMetadata(nsMetadata);
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
#### Managing DNS Metadata
|
|
437
|
+
```javascript
|
|
438
|
+
// Add A record to existing metadata
|
|
439
|
+
const updatedMetadata = viz.dns.addARecord(existingMetadata, '10.0.0.1');
|
|
440
|
+
|
|
441
|
+
// Set SSL hash
|
|
442
|
+
const sslMetadata = viz.dns.setSslHash(updatedMetadata, 'new_hash_value');
|
|
443
|
+
|
|
444
|
+
// Remove SSL hash
|
|
445
|
+
const cleanMetadata = viz.dns.removeSslHash(sslMetadata);
|
|
446
|
+
|
|
447
|
+
// Update TTL
|
|
448
|
+
const ttlUpdated = viz.dns.setTtl(cleanMetadata, 3600);
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Integration with VIZ Blockchain
|
|
452
|
+
The DNS module integrates seamlessly with VIZ blockchain operations:
|
|
453
|
+
- Stores DNS records in account `json_metadata` field
|
|
454
|
+
- Uses NS (Nameserver) record format compatible with VIZ standards
|
|
455
|
+
- Supports TTL (Time-To-Live) for record expiration
|
|
456
|
+
- Enables SSL certificate hash verification for secure connections
|
|
457
|
+
- Provides backward compatibility with existing account metadata
|
|
458
|
+
|
|
459
|
+
**Section sources**
|
|
460
|
+
- [src/dns.js:1-575](file://src/dns.js#L1-L575)
|
|
461
|
+
- [test/dns.test.js:1-396](file://test/dns.test.js#L1-L396)
|
|
462
|
+
|
|
463
|
+
## Dependency Analysis
|
|
464
|
+
Utilities depend on configuration, API clients, and cryptographic primitives. The formatter module depends on the API client to fetch global properties for estimations. The broadcast helpers depend on the API to retrieve account data and on the broadcaster to submit transactions. The DNS module operates independently but integrates with the existing module ecosystem.
|
|
465
|
+
|
|
466
|
+
```mermaid
|
|
467
|
+
graph LR
|
|
468
|
+
CFG["config.js"] --> FMT["formatter.js"]
|
|
469
|
+
CFG --> ADH["address.js"]
|
|
470
|
+
API["API Client"] --> FMT
|
|
471
|
+
API --> BHL["broadcast/helpers.js"]
|
|
472
|
+
KEY["key_utils.js"] --> FMT
|
|
473
|
+
NMB["number_utils.js"] --> FMT
|
|
474
|
+
UTL["utils.js"] --> FMT
|
|
475
|
+
DNS["dns.js"] --> FMT
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
**Diagram sources**
|
|
479
|
+
- [src/config.js:1-10](file://src/config.js#L1-L10)
|
|
480
|
+
- [src/formatter.js:1-87](file://src/formatter.js#L1-L87)
|
|
481
|
+
- [src/auth/serializer/src/number_utils.js:1-54](file://src/auth/serializer/src/number_utils.js#L1-L54)
|
|
482
|
+
- [src/auth/ecc/src/key_utils.js:1-89](file://src/auth/ecc/src/key_utils.js#L1-L89)
|
|
483
|
+
- [src/auth/ecc/src/address.js:1-57](file://src/auth/ecc/src/address.js#L1-L57)
|
|
484
|
+
- [src/broadcast/helpers.js:1-82](file://src/broadcast/helpers.js#L1-L82)
|
|
485
|
+
- [src/utils.js:1-348](file://src/utils.js#L1-L348)
|
|
486
|
+
- [src/dns.js:1-575](file://src/dns.js#L1-L575)
|
|
487
|
+
|
|
488
|
+
**Section sources**
|
|
489
|
+
- [src/formatter.js:1-87](file://src/formatter.js#L1-L87)
|
|
490
|
+
- [src/broadcast/helpers.js:1-82](file://src/broadcast/helpers.js#L1-L82)
|
|
491
|
+
- [src/utils.js:1-348](file://src/utils.js#L1-L348)
|
|
492
|
+
- [src/dns.js:1-575](file://src/dns.js#L1-L575)
|
|
493
|
+
|
|
494
|
+
## Performance Considerations
|
|
495
|
+
- Prefer precomputed or cached global properties when estimating account values to reduce API calls
|
|
496
|
+
- Avoid repeated JSON parsing/stringification in tight loops; reuse parsed objects where possible
|
|
497
|
+
- Use toImpliedDecimal/fromImpliedDecimal for precise asset arithmetic to prevent floating-point drift
|
|
498
|
+
- Minimize DOM-dependent entropy gathering in headless environments; fallback to hashing in Node.js
|
|
499
|
+
- Batch broadcast operations when adding/removing multiple authorities to reduce network overhead
|
|
500
|
+
- **New**: Cache DNS validation results for frequently accessed domains to improve performance
|
|
501
|
+
- **New**: Use TTL values strategically to balance freshness with reduced metadata updates
|
|
502
|
+
|
|
503
|
+
## Troubleshooting Guide
|
|
504
|
+
- Configuration not applied: verify config.json exists and config.get/set are invoked after module load
|
|
505
|
+
- Formatting errors: ensure numeric inputs are strings or numbers within safe integer bounds before conversion
|
|
506
|
+
- Authority updates failing: confirm account exists, authority structure is valid, and weights are set appropriately
|
|
507
|
+
- Entropy issues: ensure sufficient browser entropy is available; fallback hashing occurs automatically
|
|
508
|
+
- Address validation failures: check prefix matches configured address_prefix and checksum verification passes
|
|
509
|
+
- **New**: DNS validation failures: verify IPv4 addresses match regex pattern, SHA256 hashes are exactly 64 hex characters, and TTL values are positive integers
|
|
510
|
+
- **New**: Metadata parsing errors: ensure JSON metadata is properly formatted and contains required `ns` array and `ttl` fields
|
|
511
|
+
- **New**: SSL hash validation: remember that SSL hashes are automatically lowercased when created
|
|
512
|
+
|
|
513
|
+
**Section sources**
|
|
514
|
+
- [src/config.js:1-10](file://src/config.js#L1-L10)
|
|
515
|
+
- [src/auth/serializer/src/number_utils.js:1-54](file://src/auth/serializer/src/number_utils.js#L1-L54)
|
|
516
|
+
- [src/broadcast/helpers.js:1-82](file://src/broadcast/helpers.js#L1-L82)
|
|
517
|
+
- [src/auth/ecc/src/key_utils.js:66-86](file://src/auth/ecc/src/key_utils.js#L66-L86)
|
|
518
|
+
- [src/auth/ecc/src/address.js:19-30](file://src/auth/ecc/src/address.js#L19-L30)
|
|
519
|
+
- [src/dns.js:1-575](file://src/dns.js#L1-L575)
|
|
520
|
+
|
|
521
|
+
## Conclusion
|
|
522
|
+
The VIZ JavaScript library provides a robust set of utilities spanning configuration, formatting, numeric precision, string processing, broadcasting, cryptography, and now decentralized domain name resolution. The new DNS Nameserver module enhances the library's capabilities for blockchain-based applications requiring human-readable domain names. These modules are designed for cross-platform use and integrate cleanly with the API and broadcast layers. Following the patterns and guidelines outlined here ensures consistent behavior and maintainability across environments.
|
|
523
|
+
|
|
524
|
+
## Appendices
|
|
525
|
+
|
|
526
|
+
### Practical Examples and Integration Patterns
|
|
527
|
+
- Using formatter utilities:
|
|
528
|
+
- Estimate account value: call the estimation function with an account object and optional global properties
|
|
529
|
+
- Generate a suggested password: use the password creation utility for secure, WIF-derived credentials
|
|
530
|
+
- Format amounts: append asset suffixes and apply thousand separators for display
|
|
531
|
+
- Numeric conversions:
|
|
532
|
+
- Convert amounts to implied decimals before broadcasting operations
|
|
533
|
+
- Convert back to human-readable form for display
|
|
534
|
+
- String processing:
|
|
535
|
+
- Normalize identifiers using camelCase conversion
|
|
536
|
+
- Validate account names before registration or delegation
|
|
537
|
+
- Broadcasting authority changes:
|
|
538
|
+
- Use helper functions to add or remove authorized accounts safely
|
|
539
|
+
- Environment usage:
|
|
540
|
+
- In Node.js, require the main index module
|
|
541
|
+
- In browsers, include the browser entry to expose the viz object globally
|
|
542
|
+
- **New**: DNS Nameserver usage:
|
|
543
|
+
- Create DNS metadata for account registration: use `createNsMetadata()` with A records and optional SSL hash
|
|
544
|
+
- Validate DNS data before submission: use validation functions for IP addresses, hashes, and TTL values
|
|
545
|
+
- Parse existing DNS records: use `parseNsMetadata()` to extract A records and SSL hashes from account metadata
|
|
546
|
+
- Manage DNS metadata: use manipulation functions to add, remove, or update DNS records
|
|
547
|
+
- Integrate with blockchain operations: store DNS metadata in account `json_metadata` field for decentralized domain resolution
|
|
548
|
+
|
|
549
|
+
**Section sources**
|
|
550
|
+
- [src/formatter.js:19-85](file://src/formatter.js#L19-L85)
|
|
551
|
+
- [src/auth/serializer/src/number_utils.js:10-53](file://src/auth/serializer/src/number_utils.js#L10-L53)
|
|
552
|
+
- [src/utils.js:10-127](file://src/utils.js#L10-L127)
|
|
553
|
+
- [src/broadcast/helpers.js:6-81](file://src/broadcast/helpers.js#L6-L81)
|
|
554
|
+
- [src/index.js:1-22](file://src/index.js#L1-L22)
|
|
555
|
+
- [src/browser.js:1-30](file://src/browser.js#L1-L30)
|
|
556
|
+
- [src/dns.js:1-575](file://src/dns.js#L1-L575)
|
|
557
|
+
- [examples/get-post-content.js:1-5](file://examples/get-post-content.js#L1-L5)
|