1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#! /usr/bin/env tclsh
package require json
package require json::write
namespace eval ::nano {}
namespace eval ::nano::address {}
namespace eval ::nano::key {}
namespace eval ::nano::block {}
namespace eval ::nano::block::create {}
namespace eval ::nano::account {}
set ::nano::block::hashLength 32
set ::nano::key::publicKeyLength 32
set ::nano::key::privateKeyLength 32
set ::nano::key::seedLength 32
set ::nano::address::base32alphabet {13456789abcdefghijkmnopqrstuwxyz}
proc ::nano::address::toPublicKey {address args} {
set performChecksumCheck false
|
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#! /usr/bin/env tclsh
package require json
package require json::write
namespace eval ::nano {}
namespace eval ::nano::address {}
namespace eval ::nano::key {}
namespace eval ::nano::block {}
namespace eval ::nano::block::create {}
namespace eval ::nano::account {}
set ::nano::block::hashLength 32
set ::nano::block::signatureLength 64
set ::nano::key::publicKeyLength 32
set ::nano::key::privateKeyLength 32
set ::nano::key::seedLength 32
set ::nano::address::base32alphabet {13456789abcdefghijkmnopqrstuwxyz}
proc ::nano::address::toPublicKey {address args} {
set performChecksumCheck false
|
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
|
}
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] != $::nano::block::hashLength} {
set blockHash [binary decode hex $blockHash]
}
if {[string length $pubKey] != $::nano::key::publicKeyLength} {
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)]]
|
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
|
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
334
335
336
337
338
339
340
341
342
343
344
345
|
}
proc ::nano::block::signBlock {blockData args} {
set blockHash [::nano::block::hash $blockData]
tailcall ::nano::block::signBlockHash $blockHash {*}$args
}
proc ::nano::block::signBlockJSON {blockJSON args} {
set blockData [::nano::block::fromJSON $blockJSON]
tailcall ::nano::block::signBlock $blockData {*}$args
}
proc ::nano::block::verifyBlockHash {blockHash signature pubKey} {
if {[string length $blockHash] != $::nano::block::hashLength} {
set blockHash [binary decode hex $blockHash]
}
if {[string length $signature] != $::nano::block::signatureLength} {
set signature [binary decode hex $signature]
}
if {[string length $pubKey] != $::nano::key::publicKeyLength} {
set key [binary decode hex $pubKey]
}
set valid [::nano::internal::verifyDetached $blockHash $signature $pubKey]
return $valid
}
proc ::nano::block::verifyBlock {blockData args} {
set blockHash [::nano::block::hash $blockData]
tailcall ::nano::block::verifyBlockHash $blockHash {*}$args
}
proc ::nano::block::verifyBlockJSON {blockJSON args} {
set blockData [::nano::block::fromJSON $blockJSON]
tailcall ::nano::block::verifyBlock $blockData {*}$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)]]
|