sign.py (1833B)
1 # local imports 2 from chainlib.jsonrpc import JSONRPCRequest 3 4 5 def new_account(passphrase='', id_generator=None): 6 """Generate json-rpc query to create new account in keystore. 7 8 Uses the personal_newAccount rpc call. 9 10 :param passphrase: Passphrase string 11 :type passphrase: str 12 :param id_generator: JSONRPC id generator 13 :type id_generator: JSONRPCIdGenerator 14 :rtype: dict 15 :returns: rpc query object 16 """ 17 j = JSONRPCRequest(id_generator) 18 o = j.template() 19 o['method'] = 'personal_newAccount' 20 o['params'] = [passphrase] 21 return j.finalize(o) 22 23 24 def sign_transaction(payload, id_generator=None): 25 """Generate json-rpc query to sign transaction using the node keystore. 26 27 The node must have the private key corresponding to the from-field in the transaction object. 28 29 :param payload: Transaction 30 :type payload: dict 31 :param id_generator: JSONRPC id generator 32 :type id_generator: JSONRPCIdGenerator 33 :rtype: dict 34 :returns: rpc query object 35 """ 36 j = JSONRPCRequest(id_generator) 37 o = j.template() 38 o['method'] = 'eth_signTransaction' 39 o['params'] = [payload] 40 return j.finalize(o) 41 42 43 def sign_message(address, payload, id_generator=None): 44 """Generate json-rpc query to sign an arbirary message using the node keystore. 45 46 The node must have the private key corresponding to the address parameter. 47 48 :param address: Address of key to sign with, in hex 49 :type address: str 50 :param payload: Arbirary message, in hex 51 :type payload: str 52 :param id_generator: JSONRPC id generator 53 :type id_generator: JSONRPCIdGenerator 54 :rtype: dict 55 :returns: rpc query object 56 """ 57 j = JSONRPCRequest(id_generator) 58 o = j.template() 59 o['method'] = 'eth_sign' 60 o['params'] = [address, payload] 61 return j.finalize(o)