crypto

sha256(key: Any) bytes

Encrypts a key using SHA-256.

>>> sha256('unit test')
b'\xdau1>J\xc2W\xf8LN\xfb2\x0f\xbd\x01\x1cr@<\xf5\x93<\x90\xd2\xe3\xb8$\xd6H\x96\xf8\x9a'
>>> sha256(10)
b'\x9c\x82r\x01\xb9@\x19\xb4/\x85pk\xc4\x9cY\xff\x84\xb5`M\x11\xca\xaf\xb9\n\xb9HV\xc4\xe1\xddz'
Parameters:

key (Any) – the key to be encrypted

Returns:

a byte value that represents the encrypted key

Return type:

bytes

Deprecated since version 1.3.0: This module is deprecated. Use CryptoLib from boa3.sc.contracts instead

ripemd160(key: Any) bytes

Encrypts a key using RIPEMD-160.

>>> ripemd160('unit test')
b'H\x8e\xef\xf4Zh\x89:\xe6\xf1\xdc\x08\xdd\x8f\x01\rD\n\xbdH'
>>> ripemd160(10)
b'\xc0\xda\x02P8\xed\x83\xc6\x87\xdd\xc40\xda\x98F\xec\xb9\x7f9\x98'
Parameters:

key (Any) – the key to be encrypted

Returns:

a byte value that represents the encrypted key

Return type:

bytes

Deprecated since version 1.3.0: This module is deprecated. Use CryptoLib from boa3.sc.contracts instead

hash160(key: Any) bytes

Encrypts a key using HASH160.

>>> hash160('unit test')
b'#Q\xc9\xaf+c\x12\xb1\xb9\x9e\xa1\x89t\xa228g\xec\x0eF'
>>> hash160(10)
b'\x89\x86D\x19\xa8\xc3v%\x00\xfe\x9a\x98\xaf\x8f\xbbO3u\x08\xf0'
Parameters:

key (Any) – the key to be encrypted

Returns:

a byte value that represents the encrypted key

Return type:

bytes

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.utils instead

hash256(key: Any) bytes

Encrypts a key using HASH256.

>>> hash256('unit test')
b'\xdau1>J\xc2W\xf8LN\xfb2\x0f\xbd\x01\x1cr@<\xf5\x93<\x90\xd2\xe3\xb8$\xd6H\x96\xf8\x9a'
>>> hash256(10)
b'\x9c\x82r\x01\xb9@\x19\xb4/\x85pk\xc4\x9cY\xff\x84\xb5`M\x11\xca\xaf\xb9\n\xb9HV\xc4\xe1\xddz'
Parameters:

key (Any) – the key to be encrypted

Returns:

a byte value that represents the encrypted key

Return type:

bytes

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.utils instead

check_sig(pub_key: ECPoint, signature: bytes) bool

Checks the signature for the current script container.

>>> check_sig(ECPoint(b'\x03\x5a\x92\x8f\x20\x16\x39\x20\x4e\x06\xb4\x36\x8b\x1a\x93\x36\x54\x62\xa8\xeb\xbf\xf0\xb8\x81\x81\x51\xb7\x4f\xaa\xb3\xa2\xb6\x1a'),
...           b'wrongsignature')
False
Parameters:
Returns:

whether the signature is valid or not

Return type:

bool

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.utils instead

check_multisig(pubkeys: list[ECPoint], signatures: list[bytes]) bool

Checks the signatures for the current script container.

>>> check_multisig([ECPoint(b"\x03\xcd\xb0\x67\xd9\x30\xfd\x5a\xda\xa6\xc6\x85\x45\x01\x60\x44\xaa\xdd\xec\x64\xba\x39\xe5\x48\x25\x0e\xae\xa5\x51\x17\x2e\x53\x5c"),
...                 ECPoint(b"\x03l\x841\xccx\xb31w\xa6\x0bK\xcc\x02\xba\xf6\r\x05\xfe\xe5\x03\x8es9\xd3\xa6\x88\xe3\x94\xc2\xcb\xd8C")],
...                [b'wrongsignature1', b'wrongsignature2'])
False
Parameters:
Returns:

a boolean value that represents whether the signatures were validated

Return type:

bool

Deprecated since version 1.3.0: This module is deprecated. Use boa3.sc.utils instead

verify_with_ecdsa(message: bytes, pubkey: ECPoint, signature: bytes, curve: NamedCurveHash) bool

Using the elliptic curve, it checks if the signature of the message was originally produced by the public key.

>>> verify_with_ecdsa(b'unit test', ECPoint(b'\x03\x5a\x92\x8f\x20\x16\x39\x20\x4e\x06\xb4\x36\x8b\x1a\x93\x36\x54\x62\xa8\xeb\xbf\xf0\xb8\x81\x81\x51\xb7\x4f\xaa\xb3\xa2\xb6\x1a'),
...                   b'wrong_signature', NamedCurveHash.SECP256R1SHA256)
False
Parameters:
  • message (bytes) – the encrypted message

  • pubkey (boa3.builtin.type.ECPoint) – the public key that might have created the item

  • signature (bytes) – the signature of the item

  • curve (boa3.builtin.interop.crypto.namedcurve.NamedCurveHash) – the curve that will be used by the ecdsa

Returns:

a boolean value that represents whether the signature is valid

Return type:

bool

Deprecated since version 1.3.0: This module is deprecated. Use CryptoLib from boa3.sc.contracts instead

murmur32(data: bytes, seed: int) bytes

Computes the hash value for the specified byte array using the murmur32 algorithm.

>>> murmur32(b'unit test', 0)
b"\x90D'G"
Parameters:
  • data (bytes) – the input to compute the hash code for

  • seed (int) – the seed of the murmur32 hash function

Returns:

the hash value

Return type:

bytes

Deprecated since version 1.3.0: This module is deprecated. Use CryptoLib from boa3.sc.contracts instead

bls12_381_add(x: IBls12381, y: IBls12381) IBls12381

Add operation of two bls12381 points.

Parameters:
  • x (IBls12381) – The first point

  • y (IBls12381) – The second point

Returns:

the two points sum

Return type:

IBls12381

Deprecated since version 1.3.0: This module is deprecated. Use CryptoLib from boa3.sc.contracts instead

bls12_381_deserialize(data: bytes) IBls12381

Deserialize a bls12381 point.

Parameters:

data (bytes) – The point as byte array

Returns:

the deserialized point

Return type:

IBls12381

Deprecated since version 1.3.0: This module is deprecated. Use CryptoLib from boa3.sc.contracts instead

bls12_381_equal(x: IBls12381, y: IBls12381) bool

Determines whether the specified points are equal.

Parameters:
  • x (bytes) – The first point

  • y (bytes) – The second point

Returns:

whether the specified points are equal or not

Return type:

bool

Deprecated since version 1.3.0: This module is deprecated. Use CryptoLib from boa3.sc.contracts instead

bls12_381_mul(x: IBls12381, mul: bytes, neg: bool) IBls12381

Mul operation of gt point and multiplier.

Parameters:
  • x (IBls12381) – The point

  • mul (int) – Multiplier, 32 bytes, little-endian

  • neg (bool) – negative number

Returns:

the two points product

Return type:

IBls12381

Deprecated since version 1.3.0: This module is deprecated. Use CryptoLib from boa3.sc.contracts instead

bls12_381_pairing(g1: IBls12381, g2: IBls12381) IBls12381

Pairing operation of g1 and g2.

Parameters:
  • g1 (IBls12381) – The g1 point

  • g2 (IBls12381) – The g2 point

Returns:

the two points pairing

Return type:

IBls12381

Deprecated since version 1.3.0: This module is deprecated. Use CryptoLib from boa3.sc.contracts instead

bls12_381_serialize(g: IBls12381) bytes

Serialize a bls12381 point.

Parameters:

g (IBls12381) – The point to be serialized.

Returns:

the serialized point

Return type:

bytes

Deprecated since version 1.3.0: This module is deprecated. Use CryptoLib from boa3.sc.contracts instead

Subpackages

class NamedCurveHash(value)

Bases: IntFlag

Represents the named curve used in ECDSA.

Check out Neo’s Documentation to learn more about ECDSA signing.

SECP256K1SHA256

The secp256k1 curve and SHA256 hash algorithm.

SECP256R1SHA256

The secp256r1 curve, which known as prime256v1 or nistP-256, and SHA256 hash algorithm.

SECP256K1KECCAK256

The secp256k1 curve and Keccak256 hash algorithm.

SECP256R1KECCAK256

The secp256r1 curve, which known as prime256v1 or nistP-256, and Keccak256 hash algorithm.