Index: nano.tcl ================================================================== --- nano.tcl +++ nano.tcl @@ -7,10 +7,15 @@ 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 set outputFormat "bytes" @@ -104,11 +109,11 @@ } } } if {![info exists inputFormat]} { - if {[string length $pubKey] == 32} { + if {[string length $pubKey] == $::nano::key::publicKeyLength} { set inputFormat "bytes" } else { set inputFormat "hex" } } @@ -115,11 +120,11 @@ if {$inputFormat eq "hex"} { set pubKey [binary decode hex $pubKey] } - if {[string length $pubKey] != 32} { + if {[string length $pubKey] != $::nano::key::publicKeyLength} { return -code error "Invalid key (length)" } set checksum [string reverse [::nano::internal::hashData $pubKey 5]] append pubKey $checksum @@ -174,11 +179,11 @@ return -code error "Invalid option: $arg" } } } } - if {[string length $seed] != 32} { + if {[string length $seed] != $::nano::key::seedLength} { set seed [binary decode hex $seed] } set key [::nano::internal::generateKey $seed $index] if {$outputFormat eq "hex"} { @@ -202,11 +207,11 @@ return -code error "Invalid option: $arg" } } } - if {[string length $key] != 32} { + if {[string length $key] != $::nano::key::privateKeyLength} { set key [binary decode hex $key] } set pubKey [::nano::internal::publicKey $key] if {$outputFormat eq "hex"} { @@ -270,15 +275,15 @@ set outputFormat "bytes" } } } - if {[string length $blockHash] != 32} { + if {[string length $blockHash] != $::nano::block::hashLength} { set blockHash [binary decode hex $blockHash] } - if {[string length $key] != 32} { + if {[string length $key] != $::nano::key::privateKeyLength} { set key [binary decode hex $key] } set signature [::nano::internal::signDetached $blockHash $key] @@ -294,15 +299,15 @@ tailcall ::nano::block::signBlockHash $blockHash {*}$args } proc ::nano::block::verifyBlockHash {blockHash signature pubKey} { - if {[string length $blockHash] != 32} { + if {[string length $blockHash] != $::nano::block::hashLength} { set blockHash [binary decode hex $blockHash] } - if {[string length $pubKey] != 32} { + if {[string length $pubKey] != $::nano::key::publicKeyLength} { set key [binary decode hex $pubKey] } set valid [::nano::internal::verifyDetached $blockHash $signature $pubKey] @@ -494,11 +499,11 @@ return -code error "Invalid option: $arg" } } } - set hash [::nano::internal::hashData $blockData 32] + set hash [::nano::internal::hashData $blockData $::nano::block::hashLength] if {$outputFormat eq "hex"} { set hash [string toupper [binary encode hex $hash]] }