当前位置: 首页>>代码示例>>Python>>正文


Python SigningKey.from_string方法代码示例

本文整理汇总了Python中ecdsa.SigningKey.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python SigningKey.from_string方法的具体用法?Python SigningKey.from_string怎么用?Python SigningKey.from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ecdsa.SigningKey的用法示例。


在下文中一共展示了SigningKey.from_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
def run():
  key = SigningKey.from_string(get_key_from_wif(settings['wif']), SECP256k1, sha256)
  rs = compileASM(REDEEM_SCRIPT)
  txs = parsetxsfile(settings['file'])
  for tx in txs:
    tx.signatures = sign_detached(tx.tx, key, rs)
    print(",".join(tx.signatures))
开发者ID:patricklodder,项目名称:devfundtx,代码行数:9,代码来源:sign.py

示例2: Make_RegisterTransaction

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
def Make_RegisterTransaction(Prikey, Redeem_script, Name, Issuer, Admin, Inputs, Index, Count, Amount=-0.00000001):
    '''
    Name:发行的资产名
    Issuer:发行者
    Admin:管理员
    Inputs
    Count:inputs
    Amount:发行资产总量,默认无上限-0.00000001
    '''
    Name = '5b7b276c616e67273a277a682d434e272c276e616d65273a27{0}277d5d'.format(name_to_hex(Name))
    Amount = float_2_hex(Amount)
    #不需要找零
    #Antcoin:f252a09a24591e8da31deec970871cc7678cb55023db049551e91f7bac28e27b
    Outputs = big_or_little('f252a09a24591e8da31deec970871cc7678cb55023db049551e91f7bac28e27b') + float_2_hex(Count-100) + Admin if Count > 100 else ''
    #暂时支持1个inputs之后再改,'00'为索引
    RegisterTransaction = '4060' + hex(len(Name)/2)[2:] + Name + Amount + Issuer + Admin + '0001' + big_or_little(str(Inputs)) + '00'
    if Count > 100:
        RegisterTransaction += '0001' + Outputs
    else:
        RegisterTransaction += '0000'
    GetHashForSigning = big_or_little(sha256(binascii.unhexlify(RegisterTransaction)))#txid
    #print GetHashForSigning
    sk = SigningKey.from_string(binascii.unhexlify(Prikey), curve=NIST256p, hashfunc=hashlib.sha256)
    signature = binascii.hexlify(sk.sign(binascii.unhexlify(RegisterTransaction),hashfunc=hashlib.sha256))   
    return RegisterTransaction + '014140' + signature + '23' + Redeem_script
开发者ID:AntSharesSDK,项目名称:antshares-python,代码行数:27,代码来源:Make_RegisterTransaction.py

示例3: makeTransaction

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
    def makeTransaction(self, tx, account):
        """Make Transaction"""
        if tx.outputs == None:
            raise ValueError, 'Not correct Address, wrong length.'

        if tx.attributes == None:
            tx.attributes = []

        coins = self.findUnSpentCoins(account.scriptHash)
        tx.inputs, tx.outputs = self.selectInputs(tx.outputs, coins, account, tx.systemFee)

        # Make transaction
        stream = MemoryStream()
        writer = BinaryWriter(stream)
        tx.serializeUnsigned(writer)
        reg_tx = stream.toArray()
        tx.ensureHash()
        txid = tx.hash

        # RedeenScript
        contract = Contract()
        contract.createSignatureContract(account.publicKey)
        Redeem_script = contract.redeemScript

        # Add Signature
        sk = SigningKey.from_string(binascii.unhexlify(account.privateKey), curve=NIST256p, hashfunc=hashlib.sha256)
        signature = binascii.hexlify(sk.sign(binascii.unhexlify(reg_tx),hashfunc=hashlib.sha256))
        regtx = reg_tx + '014140' + signature + '23' + Redeem_script
        # sendRawTransaction
        print regtx
        response = self.node.sendRawTransaction(regtx)
        import json
        print response
        return txid
开发者ID:AntSharesSDK,项目名称:antshares-python,代码行数:36,代码来源:Wallet.py

示例4: check_for_privkey

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
def check_for_privkey(keydir, jid, stderr):
    # the "anonymous ID" case
    if jid.startswith("anonid0-"):
        return None

    # the "old-style ID" case
    # FIXME: once it is possible for addons to change from old-style IDs
    # to new, cryptographic IDs on AMO and in Firefox, warn users that
    # continuing to use old-style IDs is less secure, and provide them with
    # instructions for changing to new IDs.
    if not jid.startswith("jid0-"):
        return None

    keypath = os.path.join(keydir, jid)
    if not os.path.isfile(keypath):
        msg = """\
Your package.json says our ID is:
  %(jid)s
But I don't have a corresponding private key in:
  %(keypath)s

If you are the original developer of this package and have recently copied
the source code from a different machine to this one, you should copy the
private key into the file named above.

Otherwise, if you are a new developer who has made a copy of an existing
package to use as a starting point, you need to remove the 'id' property
from package.json, so that we can generate a new id and keypair. This will
disassociate our new package from the old one.

If you're collaborating on the same addon with a team, make sure at least
one person on the team has the private key. In the future, you may not
be able to distribute your addon without it.
"""
        print >> stderr, msg % {"jid": jid, "keypath": keypath}
        return None
    keylines = open(keypath, "r").readlines()
    keydata = {}
    for line in keylines:
        line = line.strip()
        if line:
            k, v = line.split(":", 1)
            keydata[k.strip()] = v.strip()
    if "private-key" not in keydata:
        raise ValueError("invalid keydata: can't find 'private-key' line")
    sk_s = remove_prefix(keydata["private-key"], "private-jid0-", errormsg="unable to parse private-key data")
    from ecdsa import SigningKey, VerifyingKey, NIST256p

    sk = SigningKey.from_string(my_b32decode(sk_s), curve=NIST256p)
    vk = sk.get_verifying_key()

    jid_2 = vk_to_jid(vk)
    if jid_2 != jid:
        raise ValueError("invalid keydata: private-key in %s does not match" " public key for %s" % (keypath, jid))
    vk_s = remove_prefix(keydata["public-key"], "public-jid0-", errormsg="unable to parse public-key data")
    vk2 = VerifyingKey.from_string(my_b32decode(vk_s), curve=NIST256p)
    if vk.to_string() != vk2.to_string():
        raise ValueError("invalid keydata: public-key mismatch")
    return sk
开发者ID:ongaeshi,项目名称:addon-sdk,代码行数:61,代码来源:preflight.py

示例5: __init__

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
        def __init__(self, privkey, pubkey = None, compressed = True):
            self.private_key = SigningKey.from_string(privkey, SECP256k1, sha256)

            if (compressed):
                # use the compressed public key
                self.public_key = BlockIo.Helper.compress_pubkey(self.private_key.get_verifying_key().to_string())
            else:
                # use the uncompressed public key
                self.public_key = unhexlify('04' + hexlify(self.private_key.get_verifying_key().to_string()))
开发者ID:BlockIo,项目名称:block_io-python,代码行数:11,代码来源:__init__.py

示例6: hex2key

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
def hex2key(hex_key):
    key_bytes = unhexlify(hex_key)
    if len(hex_key) == 64:
        return SigningKey.from_string(key_bytes, curve=NIST256p,
                hashfunc=sha256)
    elif len(hex_key) == 128:
        return VerifyingKey.from_string(key_bytes, curve=NIST256p,
                hashfunc=sha256)
    else:
        raise ValueError("Key in hex form is of the wrong length.")
开发者ID:Acidity,项目名称:evesrp,代码行数:12,代码来源:heroku.py

示例7: load_db_private_key

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
    def load_db_private_key(self):
        with Transaction() as tx:
            sql = "SELECT * FROM `ecdsa_pairs` WHERE `public_key`=?;"
            tx.execute(sql, (self.get_public_key(),))
            rows = tx.fetchall()
            if not len(rows):
                return

            row = rows[0]
            self.private_key = self.parse_private_key(row["private_key"])
            self.sign_key = SigningKey.from_string(self.private_key, SECP256k1) 
            self.verify_key = self.sign_key.get_verifying_key()
开发者ID:robertsdotpm,项目名称:coinbend,代码行数:14,代码来源:ecdsa_crypt.py

示例8: __init__

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
	def __init__(self, key=None):
		
		self.secretKey = self.verifKey = None
		
		# Recuperation
		if key is not None:
			self.secretKey = SigningKey.from_string(key, curve=NIST384p)
		
		# Auto-generation	
		else:
			self.secretKey = SigningKey.generate(curve=NIST384p)
			
		self.verifKey = self.secretKey.get_verifying_key()
开发者ID:El-gitano,项目名称:otr_new,代码行数:15,代码来源:pycrypto.py

示例9: sign

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
    def sign(self, msg, private_key=None):
        if private_key == None:
            sign_key = self.sign_key
        else:
            private_key = self.parse_private_key(private_key)
            sign_key = SigningKey.from_string(private_key, SECP256k1)

        if sign_key == None:
            raise Exception("Private key for ECDSA keypair not known.")

        if type(msg) == str:
            msg = msg.encode("ascii")

        return base64.b64encode(sign_key.sign(msg)).decode("utf-8")
开发者ID:robertsdotpm,项目名称:coinbend,代码行数:16,代码来源:ecdsa_crypt.py

示例10: sign

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
    def sign(self, msg, private_key=None):
        if private_key == None:
            sign_key = self.sign_key
        else:
            private_key = self.parse_private_key(private_key)
            sign_key = SigningKey.from_string(private_key, SECP256k1)

        if sign_key == None:
            raise Exception("Private key for ECDSA keypair not known.")

        if type(msg) == str:
            msg = msg.encode("ascii")

        return binascii.hexlify(sign_key.sign(msg, sigencode=ecdsa.util.sigencode_der, hashfunc=hashlib.sha256)).decode("utf-8")
开发者ID:StorjOld,项目名称:bridge-client-python,代码行数:16,代码来源:keypair.py

示例11: Make_IssueTransaction

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
def Make_IssueTransaction(Prikey, Redeem_script, Outputs, Txid):
    Nonce = random.randint(268435456, 4294967295)
    Nonce = hex(Nonce)[2:-1]
    if len(Nonce)%2==1:
        Nonce = '0'+Nonce
    value = 1
    if len(Outputs)> 16777215 or 'L' in Nonce:
        #未测试,L会出现其中?
        assert False
    IssueTransaction = '01'+ big_or_little(Nonce) + hex(len(Outputs))[2:].zfill(6)
    for o in Outputs:
        IssueTransaction = IssueTransaction + big_or_little(Txid) + float_2_hex(o['value']) + big_or_little(o['scripthash'])
    sk = SigningKey.from_string(binascii.unhexlify(Prikey), curve=NIST256p, hashfunc=hashlib.sha256)
    signature = binascii.hexlify(sk.sign(binascii.unhexlify(IssueTransaction),hashfunc=hashlib.sha256))
    return IssueTransaction + '014140' + signature + '23' + Redeem_script
开发者ID:AntSharesSDK,项目名称:antshares-python,代码行数:17,代码来源:Make_IssueTransaction.py

示例12: __init__

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
	def __init__(self, identity, private, public):
		"""Configure HTDSA signed request/response authentication.
		
		To perform the cryptographic operations required for the HTDSA protocol you must pass in either instances of
		`ecdsa` signing and verifying keys, or their hex-encoded versions which will be converted automatically.
		
		Additionally, the identity token (opaque identifier) assigned to your client application by the provider will
		need to be passed in so we can identify ourselves.
		
		The private key is your application's private key. The public key is the provider's service key you were given
		when registering your application.
		"""
		
		self.identity = identity
		self.private = SigningKey.from_string(unhexlify(private), NIST256p) if isinstance(private, (str, unicode)) else private
		self.public = VerifyingKey.from_string(unhexlify(public), NIST256p) if isinstance(public, (str, unicode)) else public
开发者ID:marrow,项目名称:htdsa-python,代码行数:18,代码来源:auth.py

示例13: new

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
 def new(cls, string=None):
     """Returns a new Address object.
     If a string is passed, the Address object will be
     created using that string and will be deterministic.
     If no string is passed, the Address object will
     be generated randomly.
     """
     # Generates warner ECDSA objects
     if string:
         # deterministic private key
         ecdsaPrivkey = SigningKey.from_string(
             string=string, curve=SECP256k1)
     else:
         # random private key
         ecdsaPrivkey = SigningKey.generate(
             curve=SECP256k1, entropy=None)
     return cls.fromPrivkey(ecdsaPrivkey)
开发者ID:hankhero,项目名称:ngcccbase,代码行数:19,代码来源:address.py

示例14: check_for_privkey

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
def check_for_privkey(keydir, jid, stderr):
    keypath = os.path.join(keydir, jid)
    if not os.path.isfile(keypath):
        msg = """\
Your package.json says our ID is:
  %(jid)s
But I don't have a corresponding private key in:
  %(keypath)s

If you are the original developer of this package and have recently copied
the source code from a different machine to this one, you need to copy the
private key into the file named above.

Otherwise, if you are a new developer who has made a copy of an existing
package to use as a starting point, you need to remove the 'id' property
from package.json, so that we can generate a new id and keypair. This will
disassociate our new package from the old one.
"""
        print >>stderr, msg % {"jid": jid, "keypath": keypath}
        return None
    keylines = open(keypath, "r").readlines()
    keydata = {}
    for line in keylines:
        line = line.strip()
        if line:
            k,v = line.split(":", 1)
            keydata[k.strip()] = v.strip()
    if "private-key" not in keydata:
        raise ValueError("invalid keydata: can't find 'private-key' line")
    sk_s = remove_prefix(keydata["private-key"], "private-jid0-",
                         errormsg="unable to parse private-key data")
    from ecdsa import SigningKey, VerifyingKey, NIST256p
    sk = SigningKey.from_string(my_b32decode(sk_s), curve=NIST256p)
    vk = sk.get_verifying_key()

    jid_2 = vk_to_jid(vk)
    if jid_2 != jid:
        raise ValueError("invalid keydata: private-key in %s does not match"
                         " public key for %s" % (keypath, jid))
    vk_s = remove_prefix(keydata["public-key"], "public-jid0-",
                         errormsg="unable to parse public-key data")
    vk2 = VerifyingKey.from_string(my_b32decode(vk_s), curve=NIST256p)
    if vk.to_string() != vk2.to_string():
        raise ValueError("invalid keydata: public-key mismatch")
    return sk
开发者ID:8planes,项目名称:mirosubs-jetpack,代码行数:47,代码来源:preflight.py

示例15: get_transaction_signature

# 需要导入模块: from ecdsa import SigningKey [as 别名]
# 或者: from ecdsa.SigningKey import from_string [as 别名]
def get_transaction_signature(transaction, private_key):
    """
    Gets the sigscript of a raw transaction
    private_key should be in bytes form
    """
    packed_raw_transaction = get_packed_transaction(transaction)
    hash = hashlib.sha256(hashlib.sha256(packed_raw_transaction).digest()).digest()
    public_key = bitcoin_address_utils.get_public_key(private_key)
    key = SigningKey.from_string(private_key, curve=SECP256k1)
    signature = key.sign_digest(hash, sigencode=util.sigencode_der_canonize)
    signature += bytes.fromhex("01") #hash code type

    sigscript = struct.pack("<B", len(signature))
    sigscript += signature
    sigscript += struct.pack("<B", len(public_key))
    sigscript += public_key

    return sigscript
开发者ID:zhangxiongfei2012,项目名称:simple-bitcoin,代码行数:20,代码来源:bitcoin_transaction_utils.py


注:本文中的ecdsa.SigningKey.from_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。