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,462 @@
|
|
|
1
|
+
# Digital Signatures
|
|
2
|
+
|
|
3
|
+
<cite>
|
|
4
|
+
**Referenced Files in This Document**
|
|
5
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js)
|
|
6
|
+
- [signature.js](file://src/auth/ecc/src/signature.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
|
+
- [ecsignature.js](file://src/auth/ecc/src/ecsignature.js)
|
|
10
|
+
- [hash.js](file://src/auth/ecc/src/hash.js)
|
|
11
|
+
- [auth_index.js](file://src/auth/index.js)
|
|
12
|
+
- [broadcast_index.js](file://src/broadcast/index.js)
|
|
13
|
+
- [operations.js](file://src/broadcast/operations.js)
|
|
14
|
+
- [serializer.js](file://src/auth/serializer/src/serializer.js)
|
|
15
|
+
- [config.js](file://src/config.js)
|
|
16
|
+
- [Crypto.js](file://test/Crypto.js)
|
|
17
|
+
- [broadcast.html](file://examples/broadcast.html)
|
|
18
|
+
</cite>
|
|
19
|
+
|
|
20
|
+
## Table of Contents
|
|
21
|
+
1. [Introduction](#introduction)
|
|
22
|
+
2. [Project Structure](#project-structure)
|
|
23
|
+
3. [Core Components](#core-components)
|
|
24
|
+
4. [Architecture Overview](#architecture-overview)
|
|
25
|
+
5. [Detailed Component Analysis](#detailed-component-analysis)
|
|
26
|
+
6. [Dependency Analysis](#dependency-analysis)
|
|
27
|
+
7. [Performance Considerations](#performance-considerations)
|
|
28
|
+
8. [Troubleshooting Guide](#troubleshooting-guide)
|
|
29
|
+
9. [Conclusion](#conclusion)
|
|
30
|
+
10. [Appendices](#appendices)
|
|
31
|
+
|
|
32
|
+
## Introduction
|
|
33
|
+
This document explains the digital signature functionality in the VIZ JavaScript library with a focus on ECDSA signature generation, verification, and buffer handling. It covers how signatures are created for blockchain transactions, including chain ID integration and signature serialization, as well as validation workflows and integration with the broadcasting system. Practical examples demonstrate signing transactions, verifying signatures, and handling signature errors. Security considerations and performance optimization techniques are also addressed.
|
|
34
|
+
|
|
35
|
+
## Project Structure
|
|
36
|
+
The signature subsystem is primarily located under src/auth/ecc and integrates with the authentication and broadcasting layers. Key areas:
|
|
37
|
+
- ECC primitives and ECDSA implementation
|
|
38
|
+
- Signature class and compact DER encoding
|
|
39
|
+
- Private/Public key management
|
|
40
|
+
- Transaction signing and broadcasting pipeline
|
|
41
|
+
- Serializer for transaction buffers
|
|
42
|
+
- Configuration for chain ID and prefixes
|
|
43
|
+
|
|
44
|
+
```mermaid
|
|
45
|
+
graph TB
|
|
46
|
+
subgraph "ECC Core"
|
|
47
|
+
ESDSA["ecdsa.js"]
|
|
48
|
+
SIG["signature.js"]
|
|
49
|
+
PRIV["key_private.js"]
|
|
50
|
+
PUB["key_public.js"]
|
|
51
|
+
ESIG["ecsignature.js"]
|
|
52
|
+
HASH["hash.js"]
|
|
53
|
+
end
|
|
54
|
+
subgraph "Auth Layer"
|
|
55
|
+
AUTH["auth/index.js"]
|
|
56
|
+
SER["auth/serializer/src/serializer.js"]
|
|
57
|
+
end
|
|
58
|
+
subgraph "Broadcast Layer"
|
|
59
|
+
BIDX["broadcast/index.js"]
|
|
60
|
+
BOPS["broadcast/operations.js"]
|
|
61
|
+
end
|
|
62
|
+
CFG["config.js"]
|
|
63
|
+
ESDSA --> SIG
|
|
64
|
+
SIG --> PRIV
|
|
65
|
+
SIG --> PUB
|
|
66
|
+
ESIG --> SIG
|
|
67
|
+
HASH --> ESDSA
|
|
68
|
+
HASH --> SIG
|
|
69
|
+
AUTH --> SIG
|
|
70
|
+
AUTH --> PRIV
|
|
71
|
+
AUTH --> PUB
|
|
72
|
+
AUTH --> SER
|
|
73
|
+
BIDX --> AUTH
|
|
74
|
+
BOPS --> BIDX
|
|
75
|
+
AUTH --> CFG
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Diagram sources**
|
|
79
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L1-L219)
|
|
80
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L1-L163)
|
|
81
|
+
- [key_private.js](file://src/auth/ecc/src/key_private.js#L1-L172)
|
|
82
|
+
- [key_public.js](file://src/auth/ecc/src/key_public.js#L1-L170)
|
|
83
|
+
- [ecsignature.js](file://src/auth/ecc/src/ecsignature.js#L1-L127)
|
|
84
|
+
- [hash.js](file://src/auth/ecc/src/hash.js#L1-L59)
|
|
85
|
+
- [auth_index.js](file://src/auth/index.js#L1-L133)
|
|
86
|
+
- [serializer.js](file://src/auth/serializer/src/serializer.js#L1-L195)
|
|
87
|
+
- [broadcast_index.js](file://src/broadcast/index.js#L1-L137)
|
|
88
|
+
- [operations.js](file://src/broadcast/operations.js#L1-L475)
|
|
89
|
+
- [config.js](file://src/config.js#L1-L10)
|
|
90
|
+
|
|
91
|
+
**Section sources**
|
|
92
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L1-L219)
|
|
93
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L1-L163)
|
|
94
|
+
- [key_private.js](file://src/auth/ecc/src/key_private.js#L1-L172)
|
|
95
|
+
- [key_public.js](file://src/auth/ecc/src/key_public.js#L1-L170)
|
|
96
|
+
- [ecsignature.js](file://src/auth/ecc/src/ecsignature.js#L1-L127)
|
|
97
|
+
- [hash.js](file://src/auth/ecc/src/hash.js#L1-L59)
|
|
98
|
+
- [auth_index.js](file://src/auth/index.js#L1-L133)
|
|
99
|
+
- [serializer.js](file://src/auth/serializer/src/serializer.js#L1-L195)
|
|
100
|
+
- [broadcast_index.js](file://src/broadcast/index.js#L1-L137)
|
|
101
|
+
- [operations.js](file://src/broadcast/operations.js#L1-L475)
|
|
102
|
+
- [config.js](file://src/config.js#L1-L10)
|
|
103
|
+
|
|
104
|
+
## Core Components
|
|
105
|
+
- ECDSA engine: deterministic nonce generation, signature computation, verification, and public key recovery.
|
|
106
|
+
- Signature class: compact 65-byte encoding, DER conversion, hashing, and recovery of public keys from signatures.
|
|
107
|
+
- Private/Public keys: WIF encoding/decoding, shared secret derivation, and point arithmetic.
|
|
108
|
+
- Transaction signing: chain ID concatenation, transaction serialization, and signature aggregation.
|
|
109
|
+
- Broadcasting: transaction preparation, signing orchestration, and API broadcast.
|
|
110
|
+
|
|
111
|
+
**Section sources**
|
|
112
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L65-L137)
|
|
113
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L9-L163)
|
|
114
|
+
- [key_private.js](file://src/auth/ecc/src/key_private.js#L13-L168)
|
|
115
|
+
- [key_public.js](file://src/auth/ecc/src/key_public.js#L13-L170)
|
|
116
|
+
- [auth_index.js](file://src/auth/index.js#L107-L130)
|
|
117
|
+
|
|
118
|
+
## Architecture Overview
|
|
119
|
+
The signing pipeline integrates hashing, ECDSA, and serialization to produce a signed transaction ready for broadcast. Chain ID is prepended to the serialized transaction bytes prior to signing. The broadcaster prepares reference blocks and expiration, signs with provided keys, and submits to the API.
|
|
120
|
+
|
|
121
|
+
```mermaid
|
|
122
|
+
sequenceDiagram
|
|
123
|
+
participant App as "Application"
|
|
124
|
+
participant Br as "Broadcast Layer"
|
|
125
|
+
participant Auth as "Auth.signTransaction"
|
|
126
|
+
participant Ser as "Serializer"
|
|
127
|
+
participant Sig as "Signature"
|
|
128
|
+
participant Net as "API"
|
|
129
|
+
App->>Br : "send(tx, keys)"
|
|
130
|
+
Br->>Br : "_prepareTransaction()"
|
|
131
|
+
Br->>Ser : "transaction.toBuffer(tx)"
|
|
132
|
+
Ser-->>Br : "Buffer"
|
|
133
|
+
Br->>Auth : "signTransaction(tx, keys)"
|
|
134
|
+
Auth->>Auth : "load chain_id"
|
|
135
|
+
Auth->>Ser : "transaction.toBuffer(tx)"
|
|
136
|
+
Ser-->>Auth : "Buffer"
|
|
137
|
+
Auth->>Auth : "Buffer.concat(chain_id, tx_buf)"
|
|
138
|
+
Auth->>Sig : "Signature.signBuffer(bytes, key)"
|
|
139
|
+
Sig-->>Auth : "Signature"
|
|
140
|
+
Auth-->>Br : "signed_transaction with signatures"
|
|
141
|
+
Br->>Net : "broadcastTransaction*"
|
|
142
|
+
Net-->>Br : "result"
|
|
143
|
+
Br-->>App : "result"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Diagram sources**
|
|
147
|
+
- [broadcast_index.js](file://src/broadcast/index.js#L24-L47)
|
|
148
|
+
- [broadcast_index.js](file://src/broadcast/index.js#L49-L84)
|
|
149
|
+
- [auth_index.js](file://src/auth/index.js#L107-L130)
|
|
150
|
+
- [serializer.js](file://src/auth/serializer/src/serializer.js#L184-L192)
|
|
151
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L62-L98)
|
|
152
|
+
|
|
153
|
+
## Detailed Component Analysis
|
|
154
|
+
|
|
155
|
+
### ECDSA Engine
|
|
156
|
+
Implements deterministic nonce generation (RFC6979), signature computation with low-S normalization, raw verification, and public key recovery with recovery parameter calculation.
|
|
157
|
+
|
|
158
|
+
```mermaid
|
|
159
|
+
flowchart TD
|
|
160
|
+
Start(["Start sign"]) --> GenK["Deterministic nonce via RFC6979"]
|
|
161
|
+
GenK --> CheckSig{"Valid signature candidates?"}
|
|
162
|
+
CheckSig --> |No| Loop["Adjust HMAC state<br/>Recompute T"]
|
|
163
|
+
Loop --> CheckSig
|
|
164
|
+
CheckSig --> |Yes| LowS["Normalize s to low-S"]
|
|
165
|
+
LowS --> Ret(["Return ECSignature"])
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Diagram sources**
|
|
169
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L9-L63)
|
|
170
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L65-L95)
|
|
171
|
+
|
|
172
|
+
**Section sources**
|
|
173
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L65-L137)
|
|
174
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L147-L209)
|
|
175
|
+
|
|
176
|
+
### Signature Class
|
|
177
|
+
Provides compact 65-byte encoding (including recovery parameter), DER conversion, SHA-256 hashing, public key recovery, and convenience methods for buffers, hex, and strings.
|
|
178
|
+
|
|
179
|
+
```mermaid
|
|
180
|
+
classDiagram
|
|
181
|
+
class Signature {
|
|
182
|
+
+r
|
|
183
|
+
+s
|
|
184
|
+
+i
|
|
185
|
+
+toBuffer() Buffer
|
|
186
|
+
+fromBuffer(buf) Signature
|
|
187
|
+
+recoverPublicKey(sha256) PublicKey
|
|
188
|
+
+recoverPublicKeyFromBuffer(buf) PublicKey
|
|
189
|
+
+verifyHash(hash, publicKey) bool
|
|
190
|
+
+verifyBuffer(buf, publicKey) bool
|
|
191
|
+
+toHex() string
|
|
192
|
+
+fromHex(hex) Signature
|
|
193
|
+
+signBuffer(buf, privateKey) Signature
|
|
194
|
+
+signBufferSha256(buf32, privateKey) Signature
|
|
195
|
+
+signHex(hex, privateKey) Signature
|
|
196
|
+
+verifyHex(hex, publicKey) bool
|
|
197
|
+
}
|
|
198
|
+
class ECSignature {
|
|
199
|
+
+r
|
|
200
|
+
+s
|
|
201
|
+
+toDER() Buffer
|
|
202
|
+
+toCompact(i, compressed) Buffer
|
|
203
|
+
+parseCompact(buf) object
|
|
204
|
+
+fromDER(buf) ECSignature
|
|
205
|
+
+parseScriptSignature(buf) object
|
|
206
|
+
}
|
|
207
|
+
Signature --> ECSignature : "wraps"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Diagram sources**
|
|
211
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L9-L163)
|
|
212
|
+
- [ecsignature.js](file://src/auth/ecc/src/ecsignature.js#L6-L127)
|
|
213
|
+
|
|
214
|
+
**Section sources**
|
|
215
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L20-L163)
|
|
216
|
+
- [ecsignature.js](file://src/auth/ecc/src/ecsignature.js#L14-L127)
|
|
217
|
+
|
|
218
|
+
### Private and Public Keys
|
|
219
|
+
Manage key material, WIF encoding/decoding, public key derivation from private key, shared secrets, and hierarchical derivation.
|
|
220
|
+
|
|
221
|
+
```mermaid
|
|
222
|
+
classDiagram
|
|
223
|
+
class PrivateKey {
|
|
224
|
+
+d
|
|
225
|
+
+fromBuffer(buf) PrivateKey
|
|
226
|
+
+fromSeed(seed) PrivateKey
|
|
227
|
+
+fromWif(wif) PrivateKey
|
|
228
|
+
+toWif() string
|
|
229
|
+
+toPublicKey() PublicKey
|
|
230
|
+
+toBuffer() Buffer
|
|
231
|
+
+get_shared_secret(other) Buffer
|
|
232
|
+
+child(offset) PrivateKey
|
|
233
|
+
+toHex() string
|
|
234
|
+
+fromHex(hex) PrivateKey
|
|
235
|
+
}
|
|
236
|
+
class PublicKey {
|
|
237
|
+
+Q
|
|
238
|
+
+fromBuffer(buf) PublicKey
|
|
239
|
+
+fromString(str) PublicKey
|
|
240
|
+
+fromStringOrThrow(str) PublicKey
|
|
241
|
+
+toBuffer(compressed) Buffer
|
|
242
|
+
+toPublicKeyString(prefix) string
|
|
243
|
+
+toAddressString(prefix) string
|
|
244
|
+
+toPtsAddy() string
|
|
245
|
+
+child(offset) PublicKey
|
|
246
|
+
+toHex() string
|
|
247
|
+
}
|
|
248
|
+
PrivateKey --> PublicKey : "derive"
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**Diagram sources**
|
|
252
|
+
- [key_private.js](file://src/auth/ecc/src/key_private.js#L13-L168)
|
|
253
|
+
- [key_public.js](file://src/auth/ecc/src/key_public.js#L13-L170)
|
|
254
|
+
|
|
255
|
+
**Section sources**
|
|
256
|
+
- [key_private.js](file://src/auth/ecc/src/key_private.js#L21-L168)
|
|
257
|
+
- [key_public.js](file://src/auth/ecc/src/key_public.js#L22-L170)
|
|
258
|
+
|
|
259
|
+
### Transaction Signing and Broadcasting
|
|
260
|
+
- Chain ID is loaded from configuration and concatenated with the serialized transaction.
|
|
261
|
+
- The transaction is signed with the provided private key(s), producing compact signatures appended to the signed transaction.
|
|
262
|
+
- The broadcaster prepares reference blocks and expiration, then broadcasts the signed transaction.
|
|
263
|
+
|
|
264
|
+
```mermaid
|
|
265
|
+
sequenceDiagram
|
|
266
|
+
participant Br as "Broadcast Layer"
|
|
267
|
+
participant Auth as "Auth.signTransaction"
|
|
268
|
+
participant Ser as "Serializer"
|
|
269
|
+
participant Sig as "Signature"
|
|
270
|
+
participant Cfg as "Config"
|
|
271
|
+
Br->>Cfg : "get('chain_id')"
|
|
272
|
+
Cfg-->>Br : "Buffer(chain_id)"
|
|
273
|
+
Br->>Ser : "transaction.toBuffer(tx)"
|
|
274
|
+
Ser-->>Br : "txBuf"
|
|
275
|
+
Br->>Auth : "signTransaction(tx, keys)"
|
|
276
|
+
Auth->>Ser : "transaction.toBuffer(tx)"
|
|
277
|
+
Ser-->>Auth : "txBuf"
|
|
278
|
+
Auth->>Auth : "bytes = concat(chain_id, txBuf)"
|
|
279
|
+
Auth->>Sig : "Signature.signBuffer(bytes, key)"
|
|
280
|
+
Sig-->>Auth : "Signature"
|
|
281
|
+
Auth-->>Br : "signed_transaction"
|
|
282
|
+
Br->>Br : "broadcast via API"
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**Diagram sources**
|
|
286
|
+
- [broadcast_index.js](file://src/broadcast/index.js#L24-L47)
|
|
287
|
+
- [broadcast_index.js](file://src/broadcast/index.js#L49-L84)
|
|
288
|
+
- [auth_index.js](file://src/auth/index.js#L107-L130)
|
|
289
|
+
- [config.js](file://src/config.js#L1-L10)
|
|
290
|
+
|
|
291
|
+
**Section sources**
|
|
292
|
+
- [auth_index.js](file://src/auth/index.js#L107-L130)
|
|
293
|
+
- [broadcast_index.js](file://src/broadcast/index.js#L24-L84)
|
|
294
|
+
- [operations.js](file://src/broadcast/operations.js#L1-L475)
|
|
295
|
+
|
|
296
|
+
### Signature Buffer Encoding/Decoding and Standards
|
|
297
|
+
- Compact encoding: 65-byte buffer with a header byte indicating recovery parameter and compression, followed by r and s as 32-byte big-endian integers.
|
|
298
|
+
- DER encoding: standard ASN.1 DER integer sequences for r and s.
|
|
299
|
+
- Recovery parameter: embedded in the compact header to allow public key reconstruction.
|
|
300
|
+
|
|
301
|
+
```mermaid
|
|
302
|
+
flowchart TD
|
|
303
|
+
A["Compact Header Byte"] --> B["Recovery Param i"]
|
|
304
|
+
A --> C["Compression Flag"]
|
|
305
|
+
D["32-byte r"] --> E["Signature Buffer"]
|
|
306
|
+
F["32-byte s"] --> E
|
|
307
|
+
E --> G["65-byte compact signature"]
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Diagram sources**
|
|
311
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L20-L54)
|
|
312
|
+
- [ecsignature.js](file://src/auth/ecc/src/ecsignature.js#L86-L97)
|
|
313
|
+
|
|
314
|
+
**Section sources**
|
|
315
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L20-L54)
|
|
316
|
+
- [ecsignature.js](file://src/auth/ecc/src/ecsignature.js#L14-L97)
|
|
317
|
+
|
|
318
|
+
### Verification Workflows
|
|
319
|
+
- Raw verification: compute u1, u2, point multiplication, and compare affine X coordinate modulo n with r.
|
|
320
|
+
- Public key recovery: reconstruct candidate public keys from signature and message hash, then validate against expected public key.
|
|
321
|
+
|
|
322
|
+
```mermaid
|
|
323
|
+
flowchart TD
|
|
324
|
+
Start(["Verify"]) --> H["Hash message -> e"]
|
|
325
|
+
H --> V1["Check r,s in [1,n-1]"]
|
|
326
|
+
V1 --> |Fail| Fail["Invalid"]
|
|
327
|
+
V1 --> V2["c = s^-1 mod n"]
|
|
328
|
+
V2 --> V3["u1 = e*c mod n; u2 = r*c mod n"]
|
|
329
|
+
V3 --> V4["R = u1*G + u2*Q"]
|
|
330
|
+
V4 --> V5["R is infinity?"]
|
|
331
|
+
V5 --> |Yes| Fail
|
|
332
|
+
V5 --> |No| V6["v = R.x mod n"]
|
|
333
|
+
V6 --> V7{"v == r?"}
|
|
334
|
+
V7 --> |Yes| Pass["Valid"]
|
|
335
|
+
V7 --> |No| Fail
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**Diagram sources**
|
|
339
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L97-L137)
|
|
340
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L147-L209)
|
|
341
|
+
|
|
342
|
+
**Section sources**
|
|
343
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L97-L137)
|
|
344
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L147-L209)
|
|
345
|
+
|
|
346
|
+
### Practical Examples
|
|
347
|
+
- Signing a transaction with a WIF key and broadcasting a vote:
|
|
348
|
+
- See example usage in the HTML example invoking broadcast methods.
|
|
349
|
+
- Verifying a signature against a public key:
|
|
350
|
+
- Use Signature.verifyBuffer or Signature.verifyHash in tests.
|
|
351
|
+
|
|
352
|
+
**Section sources**
|
|
353
|
+
- [broadcast.html](file://examples/broadcast.html#L15-L25)
|
|
354
|
+
- [Crypto.js](file://test/Crypto.js#L15-L25)
|
|
355
|
+
|
|
356
|
+
## Dependency Analysis
|
|
357
|
+
- Auth.signTransaction depends on:
|
|
358
|
+
- Serializer for transaction.toBuffer
|
|
359
|
+
- Signature.signBuffer for signing
|
|
360
|
+
- Config for chain_id
|
|
361
|
+
- Broadcast Layer depends on:
|
|
362
|
+
- Auth.signTransaction
|
|
363
|
+
- API for broadcasting
|
|
364
|
+
- Operations metadata for wrappers
|
|
365
|
+
- ECC components depend on:
|
|
366
|
+
- BigInteger and ecurve for curve math
|
|
367
|
+
- Hash utilities for SHA-256, RIPEMD-160, HMAC-SHA256
|
|
368
|
+
|
|
369
|
+
```mermaid
|
|
370
|
+
graph LR
|
|
371
|
+
CFG["config.js"] --> AUTH["auth/index.js"]
|
|
372
|
+
SER["auth/serializer/src/serializer.js"] --> AUTH
|
|
373
|
+
SIG["auth/ecc/src/signature.js"] --> AUTH
|
|
374
|
+
HASH["auth/ecc/src/hash.js"] --> AUTH
|
|
375
|
+
HASH --> ESDSA["auth/ecc/src/ecdsa.js"]
|
|
376
|
+
PRIV["auth/ecc/src/key_private.js"] --> SIG
|
|
377
|
+
PUB["auth/ecc/src/key_public.js"] --> SIG
|
|
378
|
+
AUTH --> BIDX["broadcast/index.js"]
|
|
379
|
+
BOPS["broadcast/operations.js"] --> BIDX
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**Diagram sources**
|
|
383
|
+
- [auth_index.js](file://src/auth/index.js#L107-L130)
|
|
384
|
+
- [broadcast_index.js](file://src/broadcast/index.js#L24-L47)
|
|
385
|
+
- [operations.js](file://src/broadcast/operations.js#L1-L475)
|
|
386
|
+
- [config.js](file://src/config.js#L1-L10)
|
|
387
|
+
- [serializer.js](file://src/auth/serializer/src/serializer.js#L184-L192)
|
|
388
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L62-L98)
|
|
389
|
+
- [hash.js](file://src/auth/ecc/src/hash.js#L16-L34)
|
|
390
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L1-L219)
|
|
391
|
+
- [key_private.js](file://src/auth/ecc/src/key_private.js#L1-L172)
|
|
392
|
+
- [key_public.js](file://src/auth/ecc/src/key_public.js#L1-L170)
|
|
393
|
+
|
|
394
|
+
**Section sources**
|
|
395
|
+
- [auth_index.js](file://src/auth/index.js#L107-L130)
|
|
396
|
+
- [broadcast_index.js](file://src/broadcast/index.js#L24-L47)
|
|
397
|
+
- [operations.js](file://src/broadcast/operations.js#L1-L475)
|
|
398
|
+
- [config.js](file://src/config.js#L1-L10)
|
|
399
|
+
- [serializer.js](file://src/auth/serializer/src/serializer.js#L184-L192)
|
|
400
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L62-L98)
|
|
401
|
+
- [hash.js](file://src/auth/ecc/src/hash.js#L16-L34)
|
|
402
|
+
- [ecdsa.js](file://src/auth/ecc/src/ecdsa.js#L1-L219)
|
|
403
|
+
- [key_private.js](file://src/auth/ecc/src/key_private.js#L1-L172)
|
|
404
|
+
- [key_public.js](file://src/auth/ecc/src/key_public.js#L1-L170)
|
|
405
|
+
|
|
406
|
+
## Performance Considerations
|
|
407
|
+
- Deterministic nonce generation avoids repeated attempts in typical cases; however, the implementation retries until canonical signatures are produced. This is bounded and logged periodically.
|
|
408
|
+
- Low-S normalization reduces signature size and improves compatibility.
|
|
409
|
+
- Efficient buffer operations:
|
|
410
|
+
- Use Buffer.concat judiciously; pre-allocate buffers when possible.
|
|
411
|
+
- Prefer SHA-256 hashing once per message and reuse results.
|
|
412
|
+
- Serialization:
|
|
413
|
+
- Reuse ByteBuffer instances where feasible to reduce allocations.
|
|
414
|
+
- Broadcasting:
|
|
415
|
+
- Batch operations when possible to minimize round trips.
|
|
416
|
+
|
|
417
|
+
[No sources needed since this section provides general guidance]
|
|
418
|
+
|
|
419
|
+
## Troubleshooting Guide
|
|
420
|
+
Common issues and resolutions:
|
|
421
|
+
- Invalid signature length or malformed compact header:
|
|
422
|
+
- Ensure signatures are 65 bytes and header byte is valid.
|
|
423
|
+
- Signature verification fails:
|
|
424
|
+
- Confirm message hash matches the one used during signing.
|
|
425
|
+
- Verify the correct public key is used for verification.
|
|
426
|
+
- WIF decoding errors:
|
|
427
|
+
- Validate checksum and version byte.
|
|
428
|
+
- Chain ID mismatch:
|
|
429
|
+
- Ensure the configured chain_id matches the target network.
|
|
430
|
+
- Transaction not accepted:
|
|
431
|
+
- Check reference block numbers and expiration.
|
|
432
|
+
- Confirm required signatures are present.
|
|
433
|
+
|
|
434
|
+
**Section sources**
|
|
435
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L20-L28)
|
|
436
|
+
- [signature.js](file://src/auth/ecc/src/signature.js#L115-L121)
|
|
437
|
+
- [key_private.js](file://src/auth/ecc/src/key_private.js#L55-L70)
|
|
438
|
+
- [auth_index.js](file://src/auth/index.js#L113-L122)
|
|
439
|
+
- [broadcast_index.js](file://src/broadcast/index.js#L49-L84)
|
|
440
|
+
|
|
441
|
+
## Conclusion
|
|
442
|
+
The VIZ JavaScript library’s signature subsystem provides a robust, standards-compliant implementation of ECDSA with compact encoding, deterministic nonce generation, and seamless integration with transaction serialization and broadcasting. By adhering to the outlined workflows and best practices, developers can reliably sign and verify transactions while maintaining security and performance.
|
|
443
|
+
|
|
444
|
+
[No sources needed since this section summarizes without analyzing specific files]
|
|
445
|
+
|
|
446
|
+
## Appendices
|
|
447
|
+
|
|
448
|
+
### Security Considerations
|
|
449
|
+
- Use deterministic nonce generation to prevent nonce reuse vulnerabilities.
|
|
450
|
+
- Normalize s-values to low-S to avoid signature malleability.
|
|
451
|
+
- Validate all inputs: signatures, public keys, and chain IDs.
|
|
452
|
+
- Protect private keys and WIFs; prefer hardware or secure enclaves when possible.
|
|
453
|
+
|
|
454
|
+
[No sources needed since this section provides general guidance]
|
|
455
|
+
|
|
456
|
+
### Example References
|
|
457
|
+
- Signing and broadcasting a vote:
|
|
458
|
+
- [broadcast.html](file://examples/broadcast.html#L15-L25)
|
|
459
|
+
- Signature verification tests:
|
|
460
|
+
- [Crypto.js](file://test/Crypto.js#L15-L25)
|
|
461
|
+
|
|
462
|
+
[No sources needed since this section aggregates references]
|