Comment: | Made API more consistent |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
6881dd597ed2f34dc0116f741da30868 |
User & Date: | rkeene on 2018-07-06 02:35:06 |
Other Links: | manifest | tags |
2018-07-06
| ||
14:53 | Updated work nomenclature to be more clear check-in: 3aeba5d8ef user: rkeene tags: trunk | |
02:35 | Made API more consistent check-in: 6881dd597e user: rkeene tags: trunk | |
2018-07-05
| ||
17:19 | Improved random number generation mechanisms check-in: e302d11ff2 user: rkeene tags: trunk | |
Added build/nano.txt version [698fe4d7c1].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | Address ::nano::address::toPublicKey address ?-hex|-binary? ?-verify|-no-verify? -> publicKey ::nano::address::fromPublicKey pubKey ?-xrb|-nano? -> address ::nano::address::fromPrivateKey privateKey ?-xrb|-nano? -> address Key and Seed ::nano::key::newSeed ?-hex|-binary? -> seed ::nano::key::newKey ?-hex|-binary? -> privateKey ::nano::key::fromSeed seed ?index? ?-hex|-binary? -> privateKey ::nano::key::publicKeyFromPrivateKey privateKey ?-hex|-binary? -> publicKey Low-level Block ::nano::block::json::toBlock blockJSON -> blockData ::nano::block::json::fromDict blockDict -> blockJSON ::nano::block::json::fromBlock blockData ?-xrb|-nano? ?-type=<blockType>? ?-signKey=<privateKey>? -> blockJSON ::nano::block::json::sign blockJSON privateKey ?-update|-signature ?-hex|binary?? -> signature|blockJSON ::nano::block::json::verifySignature blockJSON args -> boolean ::nano::block::json::work blockJSON ?-update|-work ?-hex|-binary?? -> work|blockJSON ::nano::block::json::validateWork blockJSON -> boolean ::nano::block::dict::toBlock blockDict -> blockData ::nano::block::dict::fromJSON blockJSON -> blockDict ::nano::block::dict::fromBlock blockData ?-xrb|-nano? ?-type=<blockType>? ?-signKey=<privatKey>? -> blockDict ::nano::block::dict::sign blockDict privateKey ?-update|-signature ?-hex|-binary?? -> signature|blockDict ::nano::block::dict::verifySignature blockDict args -> boolean ::nano::block::dict::work blockDict ?-update|-work ?-hex|-binary?? -> work|blockDict ::nano::block::dict::validateWork blockDict -> boolean ::nano::block::hash blockData ?-hex|-binary? -> blockHash ::nano::block::signBlockHash blockHash privateKey ?-hex|-binary? -> signature ::nano::block::sign blockData privateKey ?-hex|-binary? -> signature ::nano::block::verifyBlockHash blockHash signature publicKey -> boolean ::nano::block::verify blockData signature publicKey -> boolean ::nano::block::create::send args -> blockJSON|blockDict ::nano::block::create::receive args -> blockJSON|blockDict ::nano::block::create::setRepresentative args -> blockJSON|blockDict ::nano::work::fromBlockHash blockHash -> work ::nano::work::fromBlock blockData -> work ::nano::work::validate blockHash work -> boolean :nano::account::setFrontier account frontierHash balance representative -> nil :nano::account::getFrontier account args -> frontierInfo :nano::account::addPending account blockHash amount -> nil :nano::account::receive account blockHash privateKey -> blockJSON|blockDict :nano::account::send fromAccount toAccount amount privateKey -> blockJSON|blockDict :nano::account::receiveAllPending account privateKey -> ListOfBlockJSON|ListOfBlockDict |
Modified build/test/test.tcl from [154ad80750] to [a74429d687].
83 84 85 86 87 88 89 | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | - + | } return true } proc test_keygeneration {} { # Generate a new key pair |
105 106 107 108 109 110 111 | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | - + | puts "\[2.FAIL\] Exp: true" return false } # Create a key pair from a seed and index set seed [binary decode hex C4D214F19E706E9C7487CEF00DE8059200C32414F0ED82E5E33B523AEDF719BA] |
143 144 145 146 147 148 149 | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | - + - + - + - + - - + + - - + + | } return true } proc test_blocks {} { set seed [binary decode hex C4D214F19E706E9C7487CEF00DE8059200C32414F0ED82E5E33B523AEDF719BA] |
238 239 240 241 242 243 244 | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | - + | puts "\[2.FAIL\] Exp: false" return false } # Generation set blockhash "1C840FED01000000D8CBCF440CB1E4DF386761E6E66609563BD62A649DF6D0BE" |
Modified examples/generate-work/generate-work from [dad84c19fb] to [9ea0cf83ab].
1 2 3 4 5 6 7 8 9 10 11 12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | - + | #! /usr/bin/env tclsh package require nano if {[llength $argv] == 0} { puts stderr "Usage: generate-work <hash>..." exit 1 } foreach arg $argv { if {[catch { |
Modified examples/offline-batch-sign/sign from [9a3ce01965] to [aeab02f36b].
39 40 41 42 43 44 45 | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | - + - + | prompt "Seed" seed if {[string length $seed] == 0} { break } if {[catch { # Verify the seed |
Modified nano.c from [ec928b6713] to [5ea860caff].
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | + + + | memcpy(workOut, work, sizeof(work)); return; } static int nano_tcl_validate_work(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { unsigned char *blockhash, *work; Tcl_WideUInt tclWorkMin; uint64_t workMin = NANO_WORK_DEFAULT_MIN; int blockhash_length, work_length; int valid, result; int tgwifo_ret; if (objc < 3 || objc > 4) { Tcl_WrongNumArgs(interp, 1, objv, "workBlockhash work ?workMin?"); return(TCL_ERROR); } |
459 460 461 462 463 464 465 | 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | - - - + + + + - - - + + + - + + - - - - + + + + + + | if (work_length != NANO_WORK_VALUE_LENGTH) { Tcl_SetResult(interp, "Work size is wrong", NULL); return(TCL_ERROR); } if (objc == 4) { |
Modified nano.tcl from [9876c8ba9b] to [a0ad3d6e3d].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | + + + + + + | #! /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::json {} namespace eval ::nano::block::dict {} namespace eval ::nano::block::create {} namespace eval ::nano::work {} namespace eval ::nano::account {} # Constants set ::nano::block::stateBlockPreamble [binary decode hex "0000000000000000000000000000000000000000000000000000000000000006"] set ::nano::address::base32alphabet {13456789abcdefghijkmnopqrstuwxyz} # Address management functions proc ::nano::address::toPublicKey {address args} { set performChecksumCheck false set outputFormat "bytes" foreach arg $args { switch -exact -- $arg { "-verify" { set performChecksumCheck true |
80 81 82 83 84 85 86 | 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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | - + - - - - - - - - + - - - - - - - - + - - - - - - + + - - + + - - + + - - + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | set result $resultBinary } return $result } |
185 186 187 188 189 190 191 | 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | - + - - + + - + + - - + + - - + | if {$outputFormat eq "hex"} { set key [binary encode hex $key] } return $key } |
256 257 258 259 260 261 262 | 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 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - + - - + - - - - - - - - - - - - - - - - - - - + - - + - - - - - - - - + - - - - - - - - + | return -code error "Invalid block type $block(type)" } } return $blockData } |
374 375 376 377 378 379 380 381 382 | 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | + + + + + + + - + + + + + + + + + + + + + - + | set blockJSONEntries [lmap field $blockJSONFields { if {![info exists block($field)]} { continue } switch -exact -- $field { "source" - "previous" - "link" - "_blockHash" - "_workHash" { if {[string length $block($field)] == $::nano::block::hashLength} { set block($field) [binary encode hex $block($field)] } set block($field) [string toupper $block($field)] } "signature" { if {[string length $block($field)] == $::nano::block::signatureLength} { set block($field) [binary encode hex $block($field)] |
426 427 428 429 430 431 432 | 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | - + - + | set addArgs_fromPublicKey [list] if {$addressPrefix eq "xrb_"} { lappend addArgs_fromPublicKey "-xrb" } switch -- $block(type) { "state" { |
485 486 487 488 489 490 491 | 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | - - + + - + | } set block(_blockData) $blockData return [array get block] } |
518 519 520 521 522 523 524 | 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | if {$outputFormat eq "hex"} { set hash [string toupper [binary encode hex $hash]] } return $hash } proc ::nano::block::signBlockHash {blockHash privateKey args} { set outputFormat "bytes" foreach arg $args { switch -exact -- $arg { "-hex" { set outputFormat "hex" } "-binary" { set outputFormat "bytes" } default { return -code error "Invalid option: $arg" } } } if {[string length $blockHash] != $::nano::block::hashLength} { set blockHash [binary decode hex $blockHash] } if {[string length $privateKey] != $::nano::key::privateKeyLength} { set privateKey [binary decode hex $privateKey] } set signature [::nano::internal::signDetached $blockHash $privateKey] if {$outputFormat eq "hex"} { set signature [string toupper [binary encode hex $signature]] } return $signature } |
553 554 555 556 557 558 559 | 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 | + + - + + + - + + | "balance" $block(balance) \ "link_as_account" $block(to) \ "_workHash" $block(previous) \ "_comment" "Send $block(amount) raw from $block(from) to $block(to)" \ ] if {[info exists block(signKey)]} { set blockDict [::nano::block::dict::sign $blockDict $block(signKey) -update] } |
591 592 593 594 595 596 597 | 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | + + - + + + - + | "balance" $block(balance) \ "link" $block(sourceBlock) \ "_workHash" $block(_workHash) \ "_comment" "Receive $block(amount) raw on $block(to) from hash $block(sourceBlock)" \ ] if {[info exists block(signKey)]} { set blockDict [::nano::block::dict::sign $blockDict $block(signKey) -update] } |
619 620 621 622 623 624 625 | 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 | + + + + + - - + + + + + + - - - + + + - + + - - + + - - - + - - - - - + - - - - - + + + - + - + - + | "_workHash" $block(previous) \ ] if {[info exists block(signKey)]} { dict set blockDict signKey $block(signKey) } if {[info exists block(signKey)]} { set blockDict [::nano::block::dict::sign $blockDict $block(signKey) -update] } if {[info exists block(-json)] && $block(-json)} { |
690 691 692 693 694 695 696 | 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 | - + + + | proc ::nano::account::receive {account blockHash signKey} { set accountPubKey [::nano::address::toPublicKey $account -hex] set frontierInfo [getFrontier $account] dict with frontierInfo {} set blockInfo [dict get $::nano::account::pending $accountPubKey $blockHash] |
730 731 732 733 734 735 736 | 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 | - + + | set block [::nano::block::create::send \ from $fromAccount \ to $toAccount \ previous $fromFrontierHash \ previousBalance $fromBalance \ amount $amount \ |