criptolib
- class CryptoLib
Bases:
object
A class used to represent the CryptoLib native contract.
Check out Neo’s Documentation to learn more about the CryptoLib class.
- hash: UInt160
- classmethod murmur32(data: bytes, seed: int) bytes
Computes the hash value for the specified byte array using the murmur32 algorithm.
>>> CryptoLib.murmur32(b'unit test', 0) b"\x90D'G"
- classmethod sha256(key: Any) bytes
Encrypts a key using SHA-256.
>>> CryptoLib.sha256('unit test') b'\xdau1>J\xc2W\xf8LN\xfb2\x0f\xbd\x01\x1cr@<\xf5\x93<\x90\xd2\xe3\xb8$\xd6H\x96\xf8\x9a'
>>> CryptoLib.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:
- classmethod ripemd160(key: Any) bytes
Encrypts a key using RIPEMD-160.
>>> CryptoLib.ripemd160('unit test') b'H\x8e\xef\xf4Zh\x89:\xe6\xf1\xdc\x08\xdd\x8f\x01\rD\n\xbdH'
>>> CryptoLib.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:
- classmethod verify_with_ecdsa(message: bytes, pubkey: ECPoint, signature: bytes, curve: NamedCurve) bool
Using the elliptic curve, it checks if the signature of the message was originally produced by the public key.
>>> CryptoLib.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', NamedCurve.SECP256R1) False
- Parameters:
message (bytes) – the encrypted message
pubkey (ECPoint) – the public key that might have created the item
signature (bytes) – the signature of the item
curve (NamedCurve) – the curve that will be used by the ecdsa
- Returns:
a boolean value that represents whether the signature is valid
- Return type:
- classmethod 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
- classmethod 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
- classmethod bls12_381_equal(x: IBls12381, y: IBls12381) bool
Determines whether the specified points are equal.
- Parameters:
x (IBls12381) – The first point
y (IBls12381) – The second point
- Returns:
whether the specified points are equal or not
- Return type:
- classmethod bls12_381_mul(x: IBls12381, mul: bytes, neg: bool) IBls12381
Mul operation of gt point and multiplier.
- classmethod 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
- class NamedCurve(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
IntFlag
Represents the named curve used in ECDSA.
Check out Neo’s Documentation to learn more about ECDSA signing.
- SECP256K1
The secp256k1 curve.
- SECP256R1
The secp256r1 curve, which known as prime256v1 or nistP-256.
- class IBls12381
Bases:
object