MCPcopy
hub / github.com/Savjee/SavjeeCoin / isValid

Method isValid

src/blockchain.js:60–72  ·  view source on GitHub ↗

* Checks if the signature is valid (transaction has not been tampered with). * It uses the fromAddress as the public key. * * @returns {boolean}

()

Source from the content-addressed store, hash-verified

58 * @returns {boolean}
59 */
60 isValid() {
61 // If the transaction doesn't have a from address we assume it's a
62 // mining reward and that it's valid. You could verify this in a
63 // different way (special field for instance)
64 if (this.fromAddress === null) return true;
65
66 if (!this.signature || this.signature.length === 0) {
67 throw new Error('No signature in this transaction');
68 }
69
70 const publicKey = ec.keyFromPublic(this.fromAddress, 'hex');
71 return publicKey.verify(this.calculateHash(), this.signature);
72 }
73}
74
75class Block {

Callers 3

hasValidTransactionsMethod · 0.80
addTransactionMethod · 0.80

Calls 1

calculateHashMethod · 0.95

Tested by

no test coverage detected