* Checks if the signature is valid (transaction has not been tampered with). * It uses the fromAddress as the public key. * * @returns {boolean}
()
| 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 | |
| 75 | class Block { |
no test coverage detected