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,331 @@
1
+ # Memo Encryption
2
+
3
+ <cite>
4
+ **Referenced Files in This Document**
5
+ - [memo.js](file://src/auth/memo.js)
6
+ - [aes.js](file://src/auth/ecc/src/aes.js)
7
+ - [key_private.js](file://src/auth/ecc/src/key_private.js)
8
+ - [key_public.js](file://src/auth/ecc/src/key_public.js)
9
+ - [hash.js](file://src/auth/ecc/src/hash.js)
10
+ - [operations.js](file://src/auth/serializer/src/operations.js)
11
+ - [memo.test.js](file://test/memo.test.js)
12
+ - [operations.js](file://src/broadcast/operations.js)
13
+ </cite>
14
+
15
+ ## Table of Contents
16
+ 1. [Introduction](#introduction)
17
+ 2. [Project Structure](#project-structure)
18
+ 3. [Core Components](#core-components)
19
+ 4. [Architecture Overview](#architecture-overview)
20
+ 5. [Detailed Component Analysis](#detailed-component-analysis)
21
+ 6. [Dependency Analysis](#dependency-analysis)
22
+ 7. [Performance Considerations](#performance-considerations)
23
+ 8. [Troubleshooting Guide](#troubleshooting-guide)
24
+ 9. [Conclusion](#conclusion)
25
+ 10. [Appendices](#appendices)
26
+
27
+ ## Introduction
28
+ This document explains the memo encryption and decryption functionality in the VIZ JavaScript library. It covers the AES-based encryption workflow, key derivation for encrypted memos, nonce handling, and secure message handling. It also documents memo decryption processes, key validation, error handling for malformed memos, and practical examples for encrypting private messages and decrypting received memos. Security considerations, key management for memos, and integration with comment operations are addressed.
29
+
30
+ ## Project Structure
31
+ The memo encryption feature spans several modules:
32
+ - Memo API: encode/decode functions for encrypted memos
33
+ - ECC (Elliptic Curve Cryptography): AES implementation, key derivation, and key utilities
34
+ - Serializer: encrypted memo data model definition
35
+ - Tests: validation of encryption/decryption behavior
36
+ - Broadcast operations: integration points for memo fields in blockchain operations
37
+
38
+ ```mermaid
39
+ graph TB
40
+ subgraph "Memo Layer"
41
+ M["memo.js<br/>encode/decode"]
42
+ end
43
+ subgraph "ECC Layer"
44
+ AES["aes.js<br/>AES encrypt/decrypt"]
45
+ KPR["key_private.js<br/>PrivateKey"]
46
+ KPU["key_public.js<br/>PublicKey"]
47
+ HASH["hash.js<br/>sha256/sha512"]
48
+ end
49
+ subgraph "Serializer Layer"
50
+ OPS["operations.js<br/>encrypted_memo schema"]
51
+ end
52
+ subgraph "Broadcast Layer"
53
+ BOPS["broadcast/operations.js<br/>operation definitions"]
54
+ end
55
+ M --> AES
56
+ AES --> KPR
57
+ AES --> KPU
58
+ AES --> HASH
59
+ M --> OPS
60
+ BOPS --> OPS
61
+ ```
62
+
63
+ **Diagram sources**
64
+ - [memo.js](file://src/auth/memo.js#L1-L113)
65
+ - [aes.js](file://src/auth/ecc/src/aes.js#L1-L181)
66
+ - [key_private.js](file://src/auth/ecc/src/key_private.js#L1-L172)
67
+ - [key_public.js](file://src/auth/ecc/src/key_public.js#L1-L170)
68
+ - [hash.js](file://src/auth/ecc/src/hash.js#L1-L59)
69
+ - [operations.js](file://src/auth/serializer/src/operations.js#L83-L91)
70
+ - [operations.js](file://src/broadcast/operations.js#L29-L36)
71
+
72
+ **Section sources**
73
+ - [memo.js](file://src/auth/memo.js#L1-L113)
74
+ - [aes.js](file://src/auth/ecc/src/aes.js#L1-L181)
75
+ - [operations.js](file://src/auth/serializer/src/operations.js#L83-L91)
76
+ - [operations.js](file://src/broadcast/operations.js#L29-L36)
77
+
78
+ ## Core Components
79
+ - Memo encode/decode API: Provides functions to encrypt and decrypt memo strings prefixed with a hash marker. It validates inputs, converts keys to objects, serializes/deserializes encrypted memo structures, and handles base58 encoding/decoding.
80
+ - AES engine: Implements ECIES-style AES-256-CBC encryption/decryption using a shared secret derived from elliptic curve Diffie-Hellman, with HMAC-like checksum validation.
81
+ - Key utilities: PrivateKey and PublicKey classes handle key conversion, WIF serialization, shared secret computation, and public key string formats.
82
+ - Serializer: Defines the encrypted_memo data model with fields for sender public key, recipient public key, nonce, checksum, and encrypted payload.
83
+ - Operation definitions: Transfer and other operations include a memo field, enabling encrypted memos to be included in blockchain transactions.
84
+
85
+ **Section sources**
86
+ - [memo.js](file://src/auth/memo.js#L16-L84)
87
+ - [aes.js](file://src/auth/ecc/src/aes.js#L23-L101)
88
+ - [key_private.js](file://src/auth/ecc/src/key_private.js#L105-L119)
89
+ - [key_public.js](file://src/auth/ecc/src/key_public.js#L86-L100)
90
+ - [operations.js](file://src/auth/serializer/src/operations.js#L83-L91)
91
+ - [operations.js](file://src/broadcast/operations.js#L29-L36)
92
+
93
+ ## Architecture Overview
94
+ The memo encryption workflow integrates the memo API with the AES engine and serializer. The process involves:
95
+ - Preparing the memo text with a hash prefix
96
+ - Deriving a shared secret from the sender’s private key and recipient’s public key
97
+ - Computing an encryption key and IV from the shared secret
98
+ - Encrypting the memo payload and generating a checksum
99
+ - Serializing the encrypted memo structure and base58-encoding it
100
+ - Decryption reverses the process, validating the checksum and reconstructing the original memo
101
+
102
+ ```mermaid
103
+ sequenceDiagram
104
+ participant App as "Application"
105
+ participant Memo as "memo.js"
106
+ participant AES as "aes.js"
107
+ participant KPR as "PrivateKey"
108
+ participant KPU as "PublicKey"
109
+ participant SER as "encrypted_memo schema"
110
+ App->>Memo : encode(private_key, public_key, memo)
111
+ Memo->>Memo : validate inputs and strip hash prefix
112
+ Memo->>AES : encrypt(private_key, public_key, memo, nonce)
113
+ AES->>KPR : get_shared_secret(public_key)
114
+ AES->>AES : derive key and IV from shared secret
115
+ AES->>AES : encrypt payload with AES-256-CBC
116
+ AES-->>Memo : {nonce, message, checksum}
117
+ Memo->>SER : serialize encrypted_memo(from, to, nonce, check, encrypted)
118
+ Memo-->>App : base58-encoded memo string
119
+ App->>Memo : decode(private_key, memo)
120
+ Memo->>Memo : parse base58 and deserialize encrypted_memo
121
+ Memo->>AES : decrypt(private_key, otherpub, nonce, encrypted, check)
122
+ AES->>AES : validate checksum and decrypt payload
123
+ AES-->>Memo : decrypted memo
124
+ Memo-->>App : memo with hash prefix restored
125
+ ```
126
+
127
+ **Diagram sources**
128
+ - [memo.js](file://src/auth/memo.js#L56-L84)
129
+ - [aes.js](file://src/auth/ecc/src/aes.js#L23-L101)
130
+ - [key_private.js](file://src/auth/ecc/src/key_private.js#L105-L119)
131
+ - [operations.js](file://src/auth/serializer/src/operations.js#L83-L91)
132
+
133
+ ## Detailed Component Analysis
134
+
135
+ ### Memo Encode/Decode API
136
+ - encode: Validates inputs, accepts either WIF or PrivateKey and PublicKey objects, prefixes the memo with a hash, serializes the encrypted memo structure, and base58-encodes the result.
137
+ - decode: Validates inputs, checks for hash prefix, decodes base58, deserializes the encrypted memo, determines the other party’s public key, decrypts the payload, and restores the hash prefix.
138
+ - Environment check: A self-test ensures encryption/decryption works in the current environment and throws an error if unsupported.
139
+
140
+ ```mermaid
141
+ flowchart TD
142
+ Start(["encode/decode entry"]) --> Validate["Validate inputs"]
143
+ Validate --> Prefix{"Has hash prefix?"}
144
+ Prefix --> |No| ReturnPlain["Return plain text"]
145
+ Prefix --> |Yes| ConvertKeys["Convert keys to objects"]
146
+ ConvertKeys --> Serialize["Serialize encrypted_memo"]
147
+ Serialize --> Base58["Base58 encode"]
148
+ Base58 --> End(["Exit"])
149
+ DecodeStart(["decode entry"]) --> CheckPrefix["Check hash prefix"]
150
+ CheckPrefix --> Parse["Parse base58 and serialized memo"]
151
+ Parse --> DeterminePub["Determine other party's public key"]
152
+ DeterminePub --> Decrypt["Decrypt payload"]
153
+ Decrypt --> RestorePrefix["Restore hash prefix"]
154
+ RestorePrefix --> DecodeEnd(["Exit"])
155
+ ```
156
+
157
+ **Diagram sources**
158
+ - [memo.js](file://src/auth/memo.js#L16-L84)
159
+
160
+ **Section sources**
161
+ - [memo.js](file://src/auth/memo.js#L16-L84)
162
+
163
+ ### AES Engine (ECIES-style)
164
+ - Key derivation: Computes a shared secret using elliptic curve Diffie-Hellman, then hashes it to produce a 512-bit value. Uses the first 32 bytes as the AES key and bytes 32–48 as the initialization vector.
165
+ - Checksum: Computes a 32-bit checksum from the encryption key to validate decryption integrity.
166
+ - Nonce handling: Generates a unique 64-bit nonce combining timestamp and entropy to prevent reuse of the same key/IV pair.
167
+ - Encryption/decryption: Uses AES-256-CBC with deterministic IV derived from the shared secret.
168
+
169
+ ```mermaid
170
+ flowchart TD
171
+ A["Inputs: private_key, public_key, nonce, message, checksum"] --> B["Compute shared secret S"]
172
+ B --> C["Derive key and IV from S"]
173
+ C --> D{"checksum present?"}
174
+ D --> |Yes| E["Validate checksum"]
175
+ E --> F["Decrypt with AES-256-CBC"]
176
+ D --> |No| G["Encrypt with AES-256-CBC"]
177
+ F --> H["Return {nonce, message, checksum}"]
178
+ G --> H
179
+ ```
180
+
181
+ **Diagram sources**
182
+ - [aes.js](file://src/auth/ecc/src/aes.js#L45-L101)
183
+
184
+ **Section sources**
185
+ - [aes.js](file://src/auth/ecc/src/aes.js#L23-L101)
186
+
187
+ ### Key Utilities (PrivateKey and PublicKey)
188
+ - PrivateKey: Provides WIF serialization/deserialization, shared secret computation with a public key, and helper conversions.
189
+ - PublicKey: Handles string and buffer conversions, address generation, and public key string formats.
190
+
191
+ ```mermaid
192
+ classDiagram
193
+ class PrivateKey {
194
+ +fromBuffer(buf)
195
+ +fromSeed(seed)
196
+ +fromWif(wif)
197
+ +toWif()
198
+ +toPublicKey()
199
+ +get_shared_secret(public_key)
200
+ +toBuffer()
201
+ +toHex()
202
+ }
203
+ class PublicKey {
204
+ +fromBuffer(buffer)
205
+ +fromString(str, prefix)
206
+ +toPublicKeyString(prefix)
207
+ +toBlockchainAddress()
208
+ +toBuffer(compressed)
209
+ +toHex()
210
+ }
211
+ PrivateKey --> PublicKey : "derive public key"
212
+ PrivateKey --> PublicKey : "shared secret"
213
+ ```
214
+
215
+ **Diagram sources**
216
+ - [key_private.js](file://src/auth/ecc/src/key_private.js#L105-L119)
217
+ - [key_public.js](file://src/auth/ecc/src/key_public.js#L86-L100)
218
+
219
+ **Section sources**
220
+ - [key_private.js](file://src/auth/ecc/src/key_private.js#L105-L119)
221
+ - [key_public.js](file://src/auth/ecc/src/key_public.js#L86-L100)
222
+
223
+ ### Serializer: Encrypted Memo Schema
224
+ - encrypted_memo defines the structure for serialized encrypted memos: from, to, nonce, check, and encrypted payload. This schema is used to serialize and deserialize memo data during encode/decode.
225
+
226
+ ```mermaid
227
+ erDiagram
228
+ ENCRYPTED_MEMO {
229
+ string from
230
+ string to
231
+ string nonce
232
+ number check
233
+ string encrypted
234
+ }
235
+ ```
236
+
237
+ **Diagram sources**
238
+ - [operations.js](file://src/auth/serializer/src/operations.js#L83-L91)
239
+
240
+ **Section sources**
241
+ - [operations.js](file://src/auth/serializer/src/operations.js#L83-L91)
242
+
243
+ ### Integration with Operations
244
+ - Transfer operation includes a memo field, enabling encrypted memos to be attached to transfers.
245
+ - Other operations define memo fields for award and fixed_award operations, allowing secure messaging in various transaction types.
246
+
247
+ ```mermaid
248
+ graph LR
249
+ OP["transfer operation"] --> MEMO["memo field"]
250
+ OP2["award operation"] --> MEMO2["memo field"]
251
+ OP3["fixed_award operation"] --> MEMO3["memo field"]
252
+ ```
253
+
254
+ **Diagram sources**
255
+ - [operations.js](file://src/broadcast/operations.js#L29-L36)
256
+ - [operations.js](file://src/broadcast/operations.js#L383-L398)
257
+
258
+ **Section sources**
259
+ - [operations.js](file://src/broadcast/operations.js#L29-L36)
260
+ - [operations.js](file://src/broadcast/operations.js#L383-L398)
261
+
262
+ ## Dependency Analysis
263
+ Memo encryption depends on:
264
+ - AES engine for cryptographic operations
265
+ - Key utilities for key conversion and shared secret computation
266
+ - Serializer for memo data model
267
+ - Operation definitions for memo field integration
268
+
269
+ ```mermaid
270
+ graph TB
271
+ Memo["memo.js"] --> AES["aes.js"]
272
+ AES --> KPR["key_private.js"]
273
+ AES --> KPU["key_public.js"]
274
+ AES --> HASH["hash.js"]
275
+ Memo --> OPS["encrypted_memo schema"]
276
+ BOPS["broadcast operations"] --> OPS
277
+ ```
278
+
279
+ **Diagram sources**
280
+ - [memo.js](file://src/auth/memo.js#L1-L113)
281
+ - [aes.js](file://src/auth/ecc/src/aes.js#L1-L181)
282
+ - [key_private.js](file://src/auth/ecc/src/key_private.js#L1-L172)
283
+ - [key_public.js](file://src/auth/ecc/src/key_public.js#L1-L170)
284
+ - [hash.js](file://src/auth/ecc/src/hash.js#L1-L59)
285
+ - [operations.js](file://src/auth/serializer/src/operations.js#L83-L91)
286
+ - [operations.js](file://src/broadcast/operations.js#L29-L36)
287
+
288
+ **Section sources**
289
+ - [memo.js](file://src/auth/memo.js#L1-L113)
290
+ - [aes.js](file://src/auth/ecc/src/aes.js#L1-L181)
291
+ - [operations.js](file://src/auth/serializer/src/operations.js#L83-L91)
292
+ - [operations.js](file://src/broadcast/operations.js#L29-L36)
293
+
294
+ ## Performance Considerations
295
+ - AES-256-CBC is efficient and widely supported. The primary cost is the elliptic curve shared secret computation and hashing.
296
+ - Nonce uniqueness prevents IV reuse, which is critical for security and avoids performance penalties from collision handling.
297
+ - Base58 encoding increases payload size slightly but is negligible compared to the benefits of compact representation.
298
+
299
+ ## Troubleshooting Guide
300
+ Common issues and resolutions:
301
+ - Unsupported environment: The memo module performs a self-test and throws an error if encryption fails. Ensure the runtime supports the required cryptographic operations.
302
+ - Invalid key or checksum mismatch: During decryption, if the computed checksum does not match the stored checksum, an error is thrown indicating an invalid key.
303
+ - Malformed memo: If the memo lacks the expected hash prefix or serialization structure, decoding may fail. Ensure the memo is properly base58-encoded and includes the encrypted_memo structure.
304
+ - Key format errors: Ensure private keys are provided in WIF format or PrivateKey objects, and public keys are provided as PublicKey objects or strings.
305
+
306
+ **Section sources**
307
+ - [memo.js](file://src/auth/memo.js#L92-L109)
308
+ - [aes.js](file://src/auth/ecc/src/aes.js#L93-L96)
309
+ - [memo.test.js](file://test/memo.test.js#L1-L38)
310
+
311
+ ## Conclusion
312
+ The VIZ JavaScript library provides a robust memo encryption system built on AES-256-CBC with ECIES-style key derivation. The memo encode/decode API integrates seamlessly with the serializer and blockchain operations, enabling secure, encrypted messaging in transfers and other operations. Proper key management, nonce handling, and checksum validation ensure confidentiality and integrity. The included tests validate the workflow and serve as practical examples for developers integrating memo encryption.
313
+
314
+ ## Appendices
315
+
316
+ ### Practical Examples
317
+ - Encrypting a private message:
318
+ - Prepare the memo text with a hash prefix.
319
+ - Call the encode function with the sender’s private key and recipient’s public key.
320
+ - Use the returned base58-encoded memo string in a transfer or other operation that supports a memo field.
321
+ - Decrypting a received memo:
322
+ - Call the decode function with the recipient’s private key and the received memo string.
323
+ - The function returns the original memo text with the hash prefix restored.
324
+ - Secure communication patterns:
325
+ - Always validate that the memo is encrypted (starts with a hash) before attempting to decode.
326
+ - Ensure the private key used for decryption matches the intended recipient.
327
+ - Store and transmit only the base58-encoded memo string to minimize exposure of raw cryptographic material.
328
+
329
+ **Section sources**
330
+ - [memo.js](file://src/auth/memo.js#L56-L84)
331
+ - [memo.test.js](file://test/memo.test.js#L17-L36)