test/functional/test_framework/key.py
def sign_ecdsa(self, msg, low_s=True):
        """Construct a DER-encoded ECDSA signature with this key."""
        assert(self.valid)
        z = int.from_bytes(msg, 'big')
        # Note: no RFC6979, but a simple random nonce (some tests rely on
        # distinct transactions for the same operation)
        k = random.randrange(1, SECP256K1_ORDER)
        R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, k)]))
        r = R[0] % SECP256K1_ORDER
        s = (modinv(k, SECP256K1_ORDER) * (z + self.secret * r)) % SECP256K1_ORDER
        if low_s and s > SECP256K1_ORDER_HALF:
            s = SECP256K1_ORDER - s
        rb = r.to_bytes((r.bit_length() + 8) // 8, 'big')
        sb = s.to_bytes((s.bit_length() + 8) // 8, 'big')
        return b'\x30' + \
            bytes([4 + len(rb) + len(sb), 2, len(rb)]) + \
            rb + bytes([2, len(sb)]) + sb
Construct a DER-encoded ECDSA signature with this key.
Construct a DER-encoded ECDSA signature with this key.
Construct a DER - encoded ECDSA signature with this key .
def sign_ecdsa(self, msg, low_s=True):
        assert(self.valid)
        z = int.from_bytes(msg, 'big')
        k = random.randrange(1, SECP256K1_ORDER)
        R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, k)]))
        r = R[0] % SECP256K1_ORDER
        s = (modinv(k, SECP256K1_ORDER) * (z + self.secret * r)) % SECP256K1_ORDER
        if low_s and s > SECP256K1_ORDER_HALF:
            s = SECP256K1_ORDER - s
        rb = r.to_bytes((r.bit_length() + 8) // 8, 'big')
        sb = s.to_bytes((s.bit_length() + 8) // 8, 'big')
        return b'\x30' + \
            bytes([4 + len(rb) + len(sb), 2, len(rb)]) + \
            rb + bytes([2, len(sb)]) + sb
def sign_ecdsa ( self , msg , low_s = True ) : assert ( self . valid ) z = int . from_bytes ( msg , 'big' ) k = random . randrange ( 1 , SECP256K1_ORDER ) R = SECP256K1 . affine ( SECP256K1 . mul ( [ ( SECP256K1_G , k ) ] ) ) r = R [ 0 ] % SECP256K1_ORDER s = ( modinv ( k , SECP256K1_ORDER ) * ( z + self . secret * r ) ) % SECP256K1_ORDER if low_s and s > SECP256K1_ORDER_HALF : s = SECP256K1_ORDER - s rb = r . to_bytes ( ( r . bit_length ( ) + 8 ) // 8 , 'big' ) sb = s . to_bytes ( ( s . bit_length ( ) + 8 ) // 8 , 'big' ) return b'\x30' + bytes ( [ 4 + len ( rb ) + len ( sb ) , 2 , len ( rb ) ] ) + rb + bytes ( [ 2 , len ( sb ) ] ) + sb
Construct a DER-encoded ECDSA signature with this key.
Construct a DER - encoded ECDSA signature with this key .
"""Construct a DER-encoded ECDSA signature with this key.""" # Note: no RFC6979, but a simple random nonce (some tests rely on # distinct transactions for the same operation)
self
msg
low_s