def calculate(self, leftNode, rightNode): self.leftNode = leftNode self.rightNode = rightNode if len(self.rightNode.hashValue) > 0: self.hashValue = getHashValue(self.leftNode.hashValue, self.rightNode.hashValue) else: self.hashValue = getHashValue(self.leftNode.hashValue, "")
def verifyScriptSig(scriptSig: str, msg: str) -> bool: stack: deque = deque() params: List[str] = scriptSig.split("\t") stack.append(params[0]) popped: str = "" for i in range(1, len(params)): if params[i] not in opcodeList: stack.append(params[i]) else: if params[i] == "OP_DUP": popped = stack.pop() stack.append(popped) stack.append(popped) elif params[i] == "OP_HASH160": popped = stack.pop() reqHash: str = utils.getHashValue(popped, hashSize) stack.append(reqHash) elif params[i] == "OP_EQUALVERIFY": first: str = stack.pop() second: str = stack.pop() if first != second: return False elif params[i] == "OP_CHECKSIG": pubKey = RSA.importKey(stack.pop()) signature: str = stack.pop() if not utils.verify(pubKey, msg, signature): return False return True
def __init__(self, txnList: List[Transaction], blockHeader: BlockHeader, fullMerkleTree: List[MerkleTreeNode]): self.txnList: List[Transaction] = txnList self.blockHeader: BlockHeader = blockHeader self.merkleTree: List[MerkleTreeNode] = fullMerkleTree self.hash: str = utils.getHashValue(blockHeader.getRawDataToHash(), hashSize)
def calculate(self, nodeList): self.nodeList = nodeList for i in nodeList: self.hashValue += i.hashValue self.hashValue = getHashValue(self.hashValue, hashSize)
def comparePubKeyAndScript(pubKey: str, pubKeyScript: str) -> bool: return pubKeyScript == createPubKeyScript( utils.getHashValue(pubKey, hashSize))
def reCalculateHash(self) -> None: self.hash: str = utils.getHashValue( self.blockHeader.getRawDataToHash(), hashSize)
def calculateHash(self) -> None: rawData = self.getRawDataToHash() self.hash = utils.getHashValue(rawData, hashSize)
def createScriptPubKey(self, publicKeyOfReceiver: str): self.scriptPubKey = ScriptEngine.createPubKeyScript( utils.getHashValue(publicKeyOfReceiver, hashSize))