예제 #1
0
 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, "")
예제 #2
0
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
예제 #3
0
 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)
예제 #4
0
 def calculate(self, nodeList):
     self.nodeList = nodeList
     for i in nodeList:
         self.hashValue += i.hashValue
     self.hashValue = getHashValue(self.hashValue, hashSize)
예제 #5
0
def comparePubKeyAndScript(pubKey: str, pubKeyScript: str) -> bool:
    return pubKeyScript == createPubKeyScript(
        utils.getHashValue(pubKey, hashSize))
예제 #6
0
 def reCalculateHash(self) -> None:
     self.hash: str = utils.getHashValue(
         self.blockHeader.getRawDataToHash(), hashSize)
예제 #7
0
 def calculateHash(self) -> None:
     rawData = self.getRawDataToHash()
     self.hash = utils.getHashValue(rawData, hashSize)
예제 #8
0
 def createScriptPubKey(self, publicKeyOfReceiver: str):
     self.scriptPubKey = ScriptEngine.createPubKeyScript(
         utils.getHashValue(publicKeyOfReceiver, hashSize))