Return SigningKey instance from Seedhex

        :param str seedhex: Hexadecimal seed string
357417
def from_seedhex(cls: Type[SigningKeyType], seedhex: str) -> SigningKeyType:
        
        regex_seedhex = compile("([0-9a-fA-F]{64})")
        match = search(regex_seedhex, seedhex)
        if not match:
            raise Exception('Error: Bad seed hexadecimal format')
        seedhex = match.groups()[0]
        seed = convert_seedhex_to_seed(seedhex)
        return cls(seed)
40970
def from_ewif_hex(cls: Type[SigningKeyType], ewif_hex: str, password: str) -> SigningKeyType:
        
        ewif_bytes = Base58Encoder.decode(ewif_hex)
        if len(ewif_bytes) != 39:
            raise Exception("Error: the size of EWIF is invalid")

        # extract data
        fi = ewif_bytes[0:1]
        checksum_from_ewif = ewif_bytes[-2:]
        ewif_no_checksum = ewif_bytes[0:-2]
        salt = ewif_bytes[1:5]
        encryptedhalf1 = ewif_bytes[5:21]
        encryptedhalf2 = ewif_bytes[21:37]

        # check format flag
        if fi != b"\x02":
            raise Exception("Error: bad format version, not EWIF")

        # checksum control
        checksum = libnacl.crypto_hash_sha256(libnacl.crypto_hash_sha256(ewif_no_checksum))[0:2]
        if checksum_from_ewif != checksum:
            raise Exception("Error: bad checksum of the EWIF")

        # SCRYPT
        password_bytes = password.encode("utf-8")
        scrypt_seed = scrypt(password_bytes, salt, 16384, 8, 8, 64)
        derivedhalf1 = scrypt_seed[0:32]
        derivedhalf2 = scrypt_seed[32:64]

        # AES
        aes = pyaes.AESModeOfOperationECB(derivedhalf2)
        decryptedhalf1 = aes.decrypt(encryptedhalf1)
        decryptedhalf2 = aes.decrypt(encryptedhalf2)

        # XOR
        seed1 = xor_bytes(decryptedhalf1, derivedhalf1[0:16])
        seed2 = xor_bytes(decryptedhalf2, derivedhalf1[16:32])
        seed = bytes(seed1 + seed2)

        # Password Control
        signer = SigningKey(seed)
        salt_from_seed = libnacl.crypto_hash_sha256(
            libnacl.crypto_hash_sha256(
                Base58Encoder.decode(signer.pubkey)))[0:4]
        if salt_from_seed != salt:
            raise Exception("Error: bad Password of EWIF address")

        return cls(seed)
1220689
def client_seed(a=random.randrange(0, 1 << SRP_KEY_SIZE)):
    
    if DEBUG:
        a = DEBUG_PRIVATE_KEY
    N, g, k = get_prime()
    A = pow(g, a, N)
    if DEBUG_PRINT:
        print('a=', binascii.b2a_hex(long2bytes(a)), end='\n')
        print('A=', binascii.b2a_hex(long2bytes(A)), end='\n')
    return A, a
279922
def sign(self, digest, **kwargs):
        
        ctx = libcrypto.EVP_PKEY_CTX_new(self.key, None)
        if ctx is None:
            raise PKeyError("Initailizing sign context")
        if libcrypto.EVP_PKEY_sign_init(ctx) < 1:
            raise PKeyError("sign_init")
        self._configure_context(ctx, kwargs)
        # Find out signature size
        siglen = c_long(0)
        if libcrypto.EVP_PKEY_sign(ctx, None, byref(siglen), digest,
                                   len(digest)) < 1:
            raise PKeyError("computing signature length")
        sig = create_string_buffer(siglen.value)
        if libcrypto.EVP_PKEY_sign(ctx, sig, byref(siglen), digest,
                                   len(digest)) < 1:
            raise PKeyError("signing")
        libcrypto.EVP_PKEY_CTX_free(ctx)
        return sig.raw[:int(siglen.value)]
196224
function ECKeySign(hashBytes, priKeyBytes) {
  let ec = new EC('secp256k1');
  let key = ec.keyFromPrivate(priKeyBytes, 'bytes');
  let signature = key.sign(hashBytes);
  let r = signature.r;
  let s = signature.s;
  let id = signature.recoveryParam;
  let rHex = r.toString('hex');
  while (rHex.length < 64) {
    rHex = "0" + rHex;
  }
  let sHex = s.toString('hex');
  while (sHex.length < 64) {
    sHex = "0" + sHex;
  }
  let idHex = byte2hexStr(id);
  let signHex = rHex + sHex + idHex;
  return hexStr2byteArray(signHex);
}
1069526
def sign_with_privkey(
    digest: bytes,
    privkey: Ed25519PrivateKey,
    global_pubkey: Ed25519PublicPoint,
    nonce: int,
    global_commit: Ed25519PublicPoint,
) -> Ed25519Signature:
    
    h = _ed25519.H(privkey)
    a = _ed25519.decodecoord(h)

    S = (nonce + _ed25519.Hint(global_commit + global_pubkey + digest) * a) % _ed25519.l
    return Ed25519Signature(_ed25519.encodeint(S))
357372
def sign(self, msg, key):
        
        hasher = hashes.Hash(self.hash_algorithm(), backend=default_backend())
        hasher.update(msg)
        digest = hasher.finalize()
        sig = key.sign(
            digest,
            padding.PSS(
                mgf=padding.MGF1(self.hash_algorithm()),
                salt_length=padding.PSS.MAX_LENGTH),
            utils.Prehashed(self.hash_algorithm()))
        return sig
711743
def fingerprint_from_raw_ssh_pub_key(key):
    
    fp_plain = hashlib.md5(key).hexdigest()
    return ':'.join(a + b for a, b in zip(fp_plain[::2], fp_plain[1::2]))
1234087
def create_token(key, payload):
  
  token = hmac.new(key)
  token.update(json.dumps(payload))
  return token.hexdigest()
683786
def sign(s, passphrase, sig_format=SER_COMPACT, curve='secp160r1'):
    
    if isinstance(s, six.text_type):
        raise ValueError("Encode `s` to a bytestring yourself to" +
                         " prevent problems with different default encodings")
    curve = Curve.by_name(curve)
    privkey = curve.passphrase_to_privkey(passphrase)
    return privkey.sign(hashlib.sha512(s).digest(), sig_format)
1101661
def signingPayloadState(self, identifier=None):
        
        if self.operation.get(TXN_TYPE) == ATTRIB:
            d = deepcopy(super().signingPayloadState(identifier=identifier))
            op = d[OPERATION]
            keyName = {RAW, ENC, HASH}.intersection(set(op.keys())).pop()
            op[keyName] = sha256(op[keyName].encode()).hexdigest()
            return d
        return super().signingPayloadState(identifier=identifier)
330758
def crypto_sign_open(signed, pk):
    
    message = ffi.new("unsigned char[]", len(signed))
    message_len = ffi.new("unsigned long long *")

    if lib.crypto_sign_open(
            message, message_len, signed, len(signed), pk) != 0:
        raise exc.BadSignatureError("Signature was forged or corrupt")

    return ffi.buffer(message, message_len[0])[:]
365505
def sign_all_unsigned_inputs(hex_privkey, unsigned_tx_hex):
    
    inputs, outputs, locktime, version = deserialize_transaction(unsigned_tx_hex)
    tx_hex = unsigned_tx_hex
    for index in xrange(0, len(inputs)):
        if len(inputs[index]['script_sig']) == 0:

            # tx with index i signed with privkey
            tx_hex = sign_transaction(str(unsigned_tx_hex), index, hex_privkey)
            unsigned_tx_hex = tx_hex

    return tx_hex
894165
function getKeys (secret) {
	var hash = crypto.createHash('sha256').update(secret, 'utf8').digest();
	var keypair = naclInstance.crypto_sign_keypair_from_seed(hash);

	return {
		publicKey : Buffer.from(keypair.signPk).toString('hex'),
		privateKey : Buffer.from(keypair.signSk).toString('hex')
	};
}
113245
def to_signed_str(self, private, public, passphrase=None):
        '''
        
        '''
        from pyxmli import xmldsig
        try:
            from Crypto.PublicKey import RSA
        except ImportError:
            raise ImportError('PyCrypto 2.5 or more recent module is ' \
                              'required to enable XMLi signing.\n' \
                              'Please visit: http://pycrypto.sourceforge.net/')
            
        if not isinstance(private, RSA._RSAobj):
            private = RSA.importKey(private.read(), passphrase=passphrase)
        
        if not isinstance(public, RSA._RSAobj):
            public = RSA.importKey(public.read())
            
        return to_unicode(xmldsig.sign(to_unicode(self.to_string()),
                                       private, public))
1243587
def _random_key(self):
        
        hashstr = '%s%s' % (random.random(), self.time_module.time())
        return hashlib.md5(hashstr).hexdigest()
254892
def master_key_from_seed(seed):
        
        S = get_bytes(seed)
        I = hmac.new(b"Bitcoin seed", S, hashlib.sha512).digest()
        Il, Ir = I[:32], I[32:]
        parse_Il = int.from_bytes(Il, 'big')
        if parse_Il == 0 or parse_Il >= bitcoin_curve.n:
            raise ValueError("Bad seed, resulting in invalid key!")

        return HDPrivateKey(key=parse_Il, chain_code=Ir, index=0, depth=0)