def op_checksig(stack, z): if len(stack) < 2: return False sec_pubkey = stack.pop() der_signature = stack.pop()[:-1] point = S256Point.parse(sec_pubkey) sig = Signature.parse(der_signature) if point.verify(z, sig): stack.append(encode_num(1)) else: stack.append(encode_num(0)) return True
def op_checksig(stack, z): if len(stack) < 2: return False sec_pubkey = stack.pop() der_signature = stack.pop()[:-1] try: point = S256Point.parse(sec_pubkey) sig = Signature.parse(der_signature) except (ValueError, SyntaxError) as e: return False if point.verify(z, sig): stack.append(encode_num(1)) else: stack.append(encode_num(0)) return True
def op_checkmultisig(stack, z): if len(stack) < 1: return False n = decode_num(stack.pop()) if len(stack) < n + 1: return False sec_pubkeys = [] for _ in range(n): sec_pubkeys.append(stack.pop()) m = decode_num(stack.pop()) if len(stack) < m + 1: return False der_signatures = [] for _ in range(m): der_signatures.append(stack.pop()[:-1]) stack.pop() try: points = [S256Point.parse(sec) for sec in sec_pubkeys] sigs = [Signature.parse(der) for der in der_signatures] for sig in sigs: if len(points) == 0: print("signatures no good or not in right order") return False while points: point = points.pop(0) if point.verify(z, sig): break stack.append(encode_num(1)) except (ValueError, SyntaxError): return False return True
import op n = 65 e = op.encode_num(n) print(e) d = op.decode_num(e) print(d)