forked from LBRYCommunity/lbry-sdk
Changed txo.private_key to be an object
This commit is contained in:
parent
37665f2df7
commit
7e1f8a56d5
5 changed files with 19 additions and 26 deletions
|
@ -1900,10 +1900,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
if not preview:
|
if not preview:
|
||||||
await tx.sign([account])
|
await tx.sign([account])
|
||||||
await account.ledger.broadcast(tx)
|
await account.ledger.broadcast(tx)
|
||||||
channel_pubkey_hash = account.ledger.public_key_to_address(
|
account.add_channel_private_key(txo.private_key)
|
||||||
txo.claim.channel.public_key_bytes
|
|
||||||
)
|
|
||||||
account.add_channel_private_key(txo.claim_name, channel_pubkey_hash, txo.private_key)
|
|
||||||
self.default_wallet.save()
|
self.default_wallet.save()
|
||||||
await self.storage.save_claims([self._old_get_temp_claim_info(
|
await self.storage.save_claims([self._old_get_temp_claim_info(
|
||||||
tx, txo, claim_address, claim, name, dewies_to_lbc(amount)
|
tx, txo, claim_address, claim, name, dewies_to_lbc(amount)
|
||||||
|
@ -2041,10 +2038,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
if not preview:
|
if not preview:
|
||||||
await tx.sign([account])
|
await tx.sign([account])
|
||||||
await account.ledger.broadcast(tx)
|
await account.ledger.broadcast(tx)
|
||||||
channel_pubkey_hash = account.ledger.public_key_to_address(
|
account.add_channel_private_key(new_txo.private_key)
|
||||||
new_txo.claim.channel.public_key_bytes
|
|
||||||
)
|
|
||||||
account.add_channel_private_key(new_txo.claim_name, channel_pubkey_hash, new_txo.private_key)
|
|
||||||
self.default_wallet.save()
|
self.default_wallet.save()
|
||||||
await self.storage.save_claims([self._old_get_temp_claim_info(
|
await self.storage.save_claims([self._old_get_temp_claim_info(
|
||||||
tx, new_txo, claim_address, new_txo.claim, new_txo.claim_name, dewies_to_lbc(amount)
|
tx, new_txo, claim_address, new_txo.claim, new_txo.claim_name, dewies_to_lbc(amount)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import hashlib
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
|
@ -38,14 +37,14 @@ class Account(BaseAccount):
|
||||||
super().apply(d)
|
super().apply(d)
|
||||||
self.channel_keys.update(d.get('certificates', {}))
|
self.channel_keys.update(d.get('certificates', {}))
|
||||||
|
|
||||||
def add_channel_private_key(self, channel_name, channel_pubkey_hash, private_key):
|
def add_channel_private_key(self, private_key):
|
||||||
if channel_pubkey_hash not in self.channel_keys:
|
public_key_bytes = private_key.get_verifying_key().to_der()
|
||||||
self.channel_keys[channel_pubkey_hash] = private_key
|
channel_pubkey_hash = self.ledger.public_key_to_address(public_key_bytes)
|
||||||
else:
|
self.channel_keys[channel_pubkey_hash] = private_key.to_pem().decode()
|
||||||
log.info("Public-Private key mapping for the channel %s already exists. Skipping...", channel_name)
|
|
||||||
|
|
||||||
def get_channel_private_key(self, channel_pubkey_hash):
|
def get_channel_private_key(self, channel_pubkey_hash):
|
||||||
return self.channel_keys.get(channel_pubkey_hash)
|
private_key_pem = self.channel_keys.get(channel_pubkey_hash)
|
||||||
|
return self._get_private_key_object_from_pem(private_key_pem)
|
||||||
|
|
||||||
async def maybe_migrate_certificates(self):
|
async def maybe_migrate_certificates(self):
|
||||||
if not self.channel_keys:
|
if not self.channel_keys:
|
||||||
|
@ -170,6 +169,10 @@ class Account(BaseAccount):
|
||||||
await self.ledger.db.release_all_outputs(self)
|
await self.ledger.db.release_all_outputs(self)
|
||||||
|
|
||||||
def _get_pubkey_address_from_private_key_pem(self, private_key_pem):
|
def _get_pubkey_address_from_private_key_pem(self, private_key_pem):
|
||||||
private_key = ecdsa.SigningKey.from_pem(private_key_pem, hashfunc=hashlib.sha256)
|
private_key = self._get_private_key_object_from_pem(private_key_pem)
|
||||||
public_key_der = private_key.get_verifying_key().to_der()
|
public_key_der = private_key.get_verifying_key().to_der()
|
||||||
return self.ledger.public_key_to_address(public_key_der)
|
return self.ledger.public_key_to_address(public_key_der)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_private_key_object_from_pem(private_key_pem):
|
||||||
|
return ecdsa.SigningKey.from_pem(private_key_pem, hashfunc=sha256)
|
||||||
|
|
|
@ -143,8 +143,7 @@ class Output(BaseOutput):
|
||||||
self.claim.signing_channel_hash,
|
self.claim.signing_channel_hash,
|
||||||
self.claim.to_message_bytes()
|
self.claim.to_message_bytes()
|
||||||
]))
|
]))
|
||||||
private_key = ecdsa.SigningKey.from_pem(channel.private_key, hashfunc=hashlib.sha256)
|
self.claim.signature = channel.private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256)
|
||||||
self.claim.signature = private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256)
|
|
||||||
self.script.generate()
|
self.script.generate()
|
||||||
|
|
||||||
def clear_signature(self):
|
def clear_signature(self):
|
||||||
|
@ -152,14 +151,12 @@ class Output(BaseOutput):
|
||||||
self.claim.clear_signature()
|
self.claim.clear_signature()
|
||||||
|
|
||||||
def generate_channel_private_key(self):
|
def generate_channel_private_key(self):
|
||||||
private_key = ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1, hashfunc=hashlib.sha256)
|
self.private_key = ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1, hashfunc=hashlib.sha256)
|
||||||
self.private_key = private_key.to_pem().decode()
|
self.claim.channel.public_key_bytes = self.private_key.get_verifying_key().to_der()
|
||||||
self.claim.channel.public_key_bytes = private_key.get_verifying_key().to_der()
|
|
||||||
self.script.generate()
|
self.script.generate()
|
||||||
return self.private_key
|
return self.private_key
|
||||||
|
|
||||||
def is_channel_private_key(self, private_key_pem):
|
def is_channel_private_key(self, private_key):
|
||||||
private_key = ecdsa.SigningKey.from_pem(private_key_pem, hashfunc=hashlib.sha256)
|
|
||||||
return self.claim.channel.public_key_bytes == private_key.get_verifying_key().to_der()
|
return self.claim.channel.public_key_bytes == private_key.get_verifying_key().to_der()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -300,8 +300,7 @@ class ChannelCommands(CommandTestCase):
|
||||||
|
|
||||||
# send the private key too
|
# send the private key too
|
||||||
channel_pubkey_address_hash = self.account.ledger.public_key_to_address(unhexlify(channel['public_key']))
|
channel_pubkey_address_hash = self.account.ledger.public_key_to_address(unhexlify(channel['public_key']))
|
||||||
account2.add_channel_private_key('@featurechannel', channel_pubkey_address_hash,
|
account2.add_channel_private_key('@featurechannel', self.account.channel_keys[channel_pubkey_address_hash])
|
||||||
self.account.channel_keys[channel_pubkey_address_hash])
|
|
||||||
|
|
||||||
# now should have private key
|
# now should have private key
|
||||||
txo = (await account2.get_channels())[0]
|
txo = (await account2.get_channels())[0]
|
||||||
|
|
|
@ -333,7 +333,7 @@ def generate_signed_legacy(address: bytes, output: Output):
|
||||||
claim.SerializeToString(),
|
claim.SerializeToString(),
|
||||||
output.claim_hash[::-1]
|
output.claim_hash[::-1]
|
||||||
]))
|
]))
|
||||||
private_key = ecdsa.SigningKey.from_pem(output.private_key, hashfunc=hashlib.sha256)
|
private_key = output.private_key
|
||||||
signature = private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256)
|
signature = private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256)
|
||||||
claim.publisherSignature.version = 1
|
claim.publisherSignature.version = 1
|
||||||
claim.publisherSignature.signatureType = 1
|
claim.publisherSignature.signatureType = 1
|
||||||
|
|
Loading…
Reference in a new issue