1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
+
|
#! /usr/bin/env tclsh
lappend auto_path [file join [file dirname [info script]] .. ..]
package require nano
proc test_selftest {} {
::nano::internal::selfTest
return true
}
proc test_signatures {} {
# Detached signature
set data [binary decode hex 0000000000000000000000000000000000000000000000000000000000000000]
set key [binary decode hex C4D214F19E706E9C7487CEF00DE8059200C32414F0ED82E5E33B523AEDF719BA]
set sig [string toupper [binary encode hex [::nano::internal::signDetached $data $key]]]
set sig_expected 1C2DE9B8A71215F949A11BBEA7EFA4ECD67A8C2B5A9AD98AE6B1AB7F7A3D2CFD715F570309148C7B39C346FB9B91B321D7E75BD598F271AF31AB60A99D086709
|
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
set data [binary decode hex 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
set pubKey [::nano::internal::publicKey $key]
set sig [::nano::internal::signDetached $data $key]
set verified [::nano::internal::verifyDetached $data $sig $pubKey]
if {!$verified} {
puts "\[2.FAIL\] Got: $verified"
puts "\[2.FAIL\] Exp: true"
return false
}
return true
}
proc test_addressformat {} {
set addr nano_35ynhw4qd1pam88azf86nk8ka5sthnzaubcw5fawingep1sjydwaiw8xy7t6
set pub 8fd47f057582c8998c8fb4c4a48d240f3a7d3e8da55c1b51c851ccb0331f2f88
set pubCheck [string tolower [::nano::address::toPublicKey $addr -hex -verify]]
if {$pubCheck ne $pub} {
puts "\[1.FAIL\] Got: $pubCheck"
puts "\[1.FAIL\] Exp: $pub"
return false
}
set addrCheck [::nano::address::fromPublicKey $pub]
if {$addrCheck ne $addr} {
puts "\[1.FAIL\] Got: $addrCheck"
puts "\[1.FAIL\] Exp: $addr"
return false
}
return true
}
set tests {
selftest
signatures
hashing
keygeneration
addressformat
}
foreach test $tests {
if {![test_$test]} {
puts "FAILED test $test"
exit 1
} else {
|