stellar - implemented stellar_sign_message and stellar_verify_message

This commit is contained in:
ZuluCrypto 2018-01-14 14:33:06 -07:00 committed by Tomas Susanka
parent 02daa3b74f
commit a13b6ced38
2 changed files with 42 additions and 0 deletions

View File

@ -855,6 +855,40 @@ def stellar_get_address(connect, account):
response = client.stellar_get_public_key(index) response = client.stellar_get_public_key(index)
return stellar.address_from_public_key(response.public_key) return stellar.address_from_public_key(response.public_key)
@cli.command(help='Sign a string with a Stellar key')
@click.option('-a', '--account', required=False, help="Account number (1 is the default primary account corresponding to m/44'/148'/0')")
@click.argument('message')
@click.pass_obj
def stellar_sign_message(connect, account, message):
index = stellar.get_index_from_account_number(account)
client = connect()
response = client.stellar_sign_message(index, message)
return base64.b64encode(response.signature)
@cli.command(help='Verify that a signature is valid')
@click.option('--message-is-b64/--no-message-is-b64', default=False, required=False, help="If set, the message argument will be interpreted as a base64-encoded string")
@click.argument('address')
@click.argument('signatureb64')
@click.argument('message')
@click.pass_obj
def stellar_verify_message(connect, address, message_is_b64, signatureb64, message):
if message_is_b64:
message = base64.b64decode(message)
else:
message = message.encode('utf-8')
pubkey_bytes = stellar.address_to_public_key(address)
client = connect()
response = client.stellar_verify_message(pubkey_bytes, base64.b64decode(signatureb64), message)
if response.is_verified:
return "Success: message verified"
else:
print "ERROR: invalid signature, verification failed"
sys.exit(1)
@cli.command(help='Sign a base64-encoded transaction envelope') @cli.command(help='Sign a base64-encoded transaction envelope')
@click.option('-a', '--account', required=False, help="Account number (1 is the default primary account corresponding to m/44'/148'/0')") @click.option('-a', '--account', required=False, help="Account number (1 is the default primary account corresponding to m/44'/148'/0')")
@click.option('-n', '--network-passphrase', required=False, help="Network passphrase (blank for public network). Testnet is: 'Test SDF Network ; September 2015'") @click.option('-n', '--network-passphrase', required=False, help="Network passphrase (blank for public network). Testnet is: 'Test SDF Network ; September 2015'")

View File

@ -945,6 +945,14 @@ class ProtocolMixin(object):
def stellar_get_public_key(self, index): def stellar_get_public_key(self, index):
return self.call(proto.StellarGetPublicKey(index=index)) return self.call(proto.StellarGetPublicKey(index=index))
@expect(proto.StellarSignedData)
def stellar_sign_message(self, index, message):
return self.call(proto.StellarSignString(index=index, message=message))
@expect(proto.StellarMessageVerification)
def stellar_verify_message(self, pubkey_bytes, signature, message):
return self.call(proto.StellarVerifyMessage(public_key=pubkey_bytes, message=message, signature=signature))
def verify_message(self, coin_name, address, signature, message): def verify_message(self, coin_name, address, signature, message):
# Convert message to UTF8 NFC (seems to be a bitcoin-qt standard) # Convert message to UTF8 NFC (seems to be a bitcoin-qt standard)
message = normalize_nfc(message).encode('utf-8') message = normalize_nfc(message).encode('utf-8')