String Method in GoOperating System:
Big library: https://golang.org/pkg/math/big/Bytes library: https://golang.org/pkg/bytes/Thus far in this Tutorial Series, most of the core blockchain features have been added to this example blockchain. With the wallet module now fully functional, it is possible to modify the transaction system to appropriately lock, verify and sign the data. This includes working backwards from an address to a public hash key and a checksum and then using those pieces to manipulate the wallets and the transactions.
All transactions must be signed in a blockchain. In Cryptography, a Digital Signature is a concept that guarantees core behavior of the blockchain:
The digital signature is derived from the private key of an account and verified with the public key of that account. The signature itself is stored in the Transaction Inputs and can be verified through the Outputs.
This image details a flowchart of the current format of transactions and blocks in the blockchain. In this chart, User A mines the Genesis block and obtains a reward of 100 tokens. User A then sends 10 tokens to User B in Block 1. When User A creates the initial transaction, the input in Block 1 references the Output from the Genesis Block. This Input contains the public key of User A and a signature for the entire Transaction. The Blockchain verifies that the Input matches the hash of the referenced Output from the Genesis block. This is the mechanism that allows a user to spend tokens that are allocated to them.
The Verification process uses this idea of recreation and redundancy. To verify an address, the blockchain decodes the address using a base58 decoder algorithm and then splits the bytes of the resulting hash into pieces. Each of those pieces are used to rebuild the checksum of the address. This original checksum can then be compared with the new checksum to verify that the address is real. The same is true for a Transaction. When a signature is made, it is derived from two numbers which are concatenated and stored in an Input. The numbers can be split and then regenerated through an ecdsaalgorithm to verify that the transaction is real. Along with these two numbers is the public key of the user who created the transaction. Public keys are made up of two coordinate numbers on an elliptic curve and they also can be split and verified using an ecdsa algorithm.
Above is an image that contains an Address, the Address's full hash and that full hash split into the Version Hash, the Pub Key Hash and the checksum. Each of these components are combined to create the address and also can be used to re-build the checksum for verification.
Here is the code which is used to verify a transaction. The variables R and S are variables which are derived from the signature of the address. These two numbers are originally a part of an elliptic curve algorithm. The X and Y values are the two halves of the Public Key and can similarly be split into separate pieces. On the final line, a new elliptic curve is used along with the x and y values from the transaction digital signature to regenerate and rebuild the public key. This public key is then used with R, S and Hashed Transaction Data to verify the Transaction Data.
The Source Code for this video may be found here: https://github.com/tensor-programming/golang-blockchain/tree/part_6