예제 #1
0
파일: txn.py 프로젝트: algorand/pyteal
    def __teal__(self, options: "CompileOptions"):
        verifyFieldVersion(self.field.arg_name, self.field.min_version, options.version)
        verifyProgramVersion(
            self.op.min_version,
            options.version,
            "Program version too low to use op {}".format(self.op),
        )

        op = TealOp(self, self.op, self.field.arg_name)
        return TealBlock.FromOp(options, op)
예제 #2
0
    def __teal__(self, options: "CompileOptions"):
        verifyFieldVersion(self.field.arg_name, self.field.min_version,
                           options.version)

        verifyProgramVersion(
            Op.gitxn.min_version,
            options.version,
            "Program version too low to use gitxn",
        )
        op = TealOp(self, Op.gitxn, self.txnIndex, self.field.arg_name)
        return TealBlock.FromOp(options, op)
예제 #3
0
파일: jsonref.py 프로젝트: algorand/pyteal
    def __teal__(self, options: "CompileOptions"):
        verifyProgramVersion(
            Op.json_ref.min_version,
            options.version,
            "Program version too low to use op json_ref",
        )

        verifyFieldVersion(self.type.arg_name, self.type.min_version,
                           options.version)

        op = TealOp(self, Op.json_ref, self.type.arg_name)
        return TealBlock.FromOp(options, op, self.json_obj, self.key)
예제 #4
0
def EcdsaRecover(curve: EcdsaCurve, data: Expr, recovery_id: Expr, sigA: Expr,
                 sigB: Expr) -> MultiValue:
    """Recover an ECDSA public key from a signature.
    All byte arguments must be big endian encoded.
    Args:
        curve: Enum representing the ECDSA curve used for the public key
        data: Hash value of the signed data. Must be 32 bytes long.
        recovery_id: value used to extract public key from signature. Must evaluate to uint.
        sigA: First component of the signature. Must evaluate to bytes.
        sigB: Second component of the signature. Must evaluate to bytes.
    Returns:
        A MultiValue expression representing the two components of the public key, big endian
        encoded.
    """

    if not isinstance(curve, EcdsaCurve):
        raise TealTypeError(curve, EcdsaCurve)

    if curve != EcdsaCurve.Secp256k1:
        raise TealInputError("Recover only supports Secp256k1")

    require_type(data, TealType.bytes)
    require_type(recovery_id, TealType.uint64)
    require_type(sigA, TealType.bytes)
    require_type(sigB, TealType.bytes)
    return MultiValue(
        Op.ecdsa_pk_recover,
        EcdsaPubkey,
        immediate_args=[curve.arg_name],
        args=[data, recovery_id, sigA, sigB],
        compile_check=lambda options: verifyFieldVersion(
            curve.arg_name, curve.min_version, options.version),
    )
예제 #5
0
파일: txn.py 프로젝트: algorand/pyteal
    def __teal__(self, options: "CompileOptions"):
        verifyFieldVersion(self.field.arg_name, self.field.min_version, options.version)

        opToUse = self.staticOp if type(self.index) is int else self.dynamicOp
        if opToUse is None:
            raise TealCompileError("Dynamic array indexing not supported", self)

        verifyProgramVersion(
            opToUse.min_version,
            options.version,
            "Program version too low to use op {}".format(opToUse),
        )

        if type(self.index) is int:
            op = TealOp(self, opToUse, self.field.arg_name, self.index)
            return TealBlock.FromOp(options, op)

        op = TealOp(self, opToUse, self.field.arg_name)
        return TealBlock.FromOp(options, op, cast(Expr, self.index))
예제 #6
0
    def __teal__(self, options: "CompileOptions"):
        verifyFieldVersion(self.field.arg_name, self.field.min_version,
                           options.version)

        if type(self.index) is int:
            opToUse = Op.gitxna
        else:
            opToUse = Op.gitxnas

        verifyProgramVersion(
            opToUse.min_version,
            options.version,
            "Program version too low to use op {}".format(opToUse),
        )

        if type(self.index) is int:
            op = TealOp(self, opToUse, self.txnIndex, self.field.arg_name,
                        self.index)
            return TealBlock.FromOp(options, op)
        op = TealOp(self, opToUse, self.txnIndex, self.field.arg_name)
        return TealBlock.FromOp(options, op, cast(Expr, self.index))
예제 #7
0
    def __teal__(self, options: "CompileOptions"):
        verifyFieldVersion(self.field.arg_name, self.field.min_version,
                           options.version)

        if type(self.txnIndex) is int:
            verifyProgramVersion(
                Op.gtxn.min_version,
                options.version,
                "Program version too low to use gtxn",
            )
            op = TealOp(self, Op.gtxn, self.txnIndex, self.field.arg_name)
            return TealBlock.FromOp(options, op)

        verifyProgramVersion(
            Op.gtxns.min_version,
            options.version,
            "Program version too low to index Gtxn with dynamic values",
        )

        op = TealOp(self, Op.gtxns, self.field.arg_name)
        return TealBlock.FromOp(options, op, cast(Expr, self.txnIndex))
예제 #8
0
    def __init__(self, standard: VrfVerifyStandard, message: Expr, proof: Expr,
                 public_key: Expr) -> None:
        require_type(message, TealType.bytes)
        require_type(proof, TealType.bytes)
        require_type(public_key, TealType.bytes)

        self.standard = standard

        super().__init__(
            Op.vrf_verify,
            [TealType.bytes, TealType.uint64],
            immediate_args=[standard.arg_name],
            args=[message, proof, public_key],
            compile_check=lambda options: verifyFieldVersion(
                standard.arg_name, standard.min_version, options.version),
        )
예제 #9
0
def EcdsaDecompress(curve: EcdsaCurve, compressed_pk: Expr) -> MultiValue:
    """Decompress an ECDSA public key.
    Args:
        curve: Enum representing the ECDSA curve used for the public key
        compressed_pk: The compressed public key. Must be 33 bytes long and big endian encoded.
    Returns:
        A MultiValue expression representing the two components of the public key, big endian
        encoded.
    """

    if not isinstance(curve, EcdsaCurve):
        raise TealTypeError(curve, EcdsaCurve)

    require_type(compressed_pk, TealType.bytes)
    return MultiValue(
        Op.ecdsa_pk_decompress,
        EcdsaPubkey,
        immediate_args=[curve.arg_name],
        args=[compressed_pk],
        compile_check=lambda options: verifyFieldVersion(
            curve.arg_name, curve.min_version, options.version),
    )
예제 #10
0
파일: global_.py 프로젝트: algorand/pyteal
    def __teal__(self, options: "CompileOptions"):
        verifyFieldVersion(self.field.arg_name, self.field.min_version, options.version)

        op = TealOp(self, Op.global_, self.field.arg_name)
        return TealBlock.FromOp(options, op)
예제 #11
0
    def __teal__(self, options: "CompileOptions"):
        verifyFieldVersion(self.encoding.arg_name, self.encoding.min_version,
                           options.version)

        op = TealOp(self, Op.base64_decode, self.encoding.arg_name)
        return TealBlock.FromOp(options, op, self.base64)