Diff

Differences From Artifact [ea79113063]:

To Artifact [09538af98b]:


254
255
256
257
258
259
260
























































261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

278
279
280
281
282
283
284
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325








326
327
328
329
330
331
332
333







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
-
-
-
-
-
-
-
+







		default {
			return -code error "Invalid block type $block(type)"
		}
	}

	return $blockData
}

proc ::nano::block::signBlockHash {blockHash key args} {
	set outputFormat "bytes"
	foreach arg $args {
		switch -exact -- $arg {
			"-hex" {
				set outputFormat "hex"
			}
			"-binary" {
				set outputFormat "bytes"
			}
		}
	}

	if {[string length $blockHash] != 32} {
		set blockHash [binary decode hex $blockHash]
	}

	if {[string length $key] != 32} {
		set key [binary decode hex $key]
	}

	set signature [::nano::internal::signDetached $blockHash $key]

	if {$outputFormat eq "hex"} {
		set signature [string toupper [binary encode hex $signature]]
	}

	return $signature
}

proc ::nano::block::signBlock {blockData args} {
	set blockHash [::nano::block::hash $blockData]

	tailcall ::nano::block::signBlockHash $blockHash {*}$args
}

proc ::nano::block::verifyBlockHash {blockHash signature pubKey} {
	if {[string length $blockHash] != 32} {
		set blockHash [binary decode hex $blockHash]
	}

	if {[string length $pubKey] != 32} {
		set key [binary decode hex $pubKey]
	}

	set valid [::nano::internal::verifyDetached $blockHash $signature $pubKey]

	return $signature
}

proc ::nano::block::verifyBlock {blockData args} {
	set blockHash [::nano::block::hash $blockData]

	tailcall ::nano::block::verifyBlockHash $blockHash {*}$args
}

proc ::nano::block::_dictToJSON {blockDict} {
	array set block $blockDict

	if {[info exists block(signKey)] && ([info exists block(_blockData)] || [info exists block(_blockHash)])} {
		if {![info exists block(_blockHash)]} {
			set block(_blockHash) [binary encode hex [::nano::block::hash $block(_blockData)]]
		}

		set signKey   [binary decode hex $block(signKey)]
		set blockHash [binary decode hex $block(_blockHash)]

		set signature [::nano::internal::signDetached $blockHash $signKey]
		set signature [binary encode hex $signature]
		set signature [string toupper $signature]

		set block(signature) $signature
		set block(signature) [::nano::block::signBlockHash $block(_blockHash) $block(signKey) -hex]
	}

	if {$block(type) eq "state"} {
		if {![info exists block(link)]} {
			set block(link) [::nano::address::toPublicKey $block(link_as_account) -hex]
		}
		if {![info exists block(link_as_address)]} {