Origin transaction should verify existing public key#583 #626
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
/api/origin_key
-> Origin endpoint is leveraged to add origin public key and its corresponding certificate, An origin transaction is created, on post request, with content as origin_public_key and certificate, But there are no checks for to ensure that this origin public key has already been included in existing transaction. A check is introduced leveraging the OriginKey store to check if the origin Public key already exists before creating/accepting the transaction.Checks are done at two different location/Stages:
origin Api controller
, During post callPending_transaction_validation.ex
in do_accept_tx(:origin), validation of txNew error logging for both locations api call and during validation is introduced.
##Fixes
Type of change
How Has This Been Tested?
How to test?
key certificate is ""
-Crypto.get_key_certificate(public_key)Accepting a Origin tx with no existing origin public key in store
iex> alias Archethic.Crypto
iex> alias Archethic.SharedSecrets.MemTable.OriginKeyLookup
iex> {public_key, _} = Crypto.derive_keypair("has_origin_public_key_Seed", 0)
iex> certificate = Crypto.get_key_certificate(public_key)
iex> pb_key = public_key|>Base.encode16
iex> cert = certificate|>Base.encode16
Check tx address in Origin Explorer
Rejecting a Origin tx with existing origin public key in store
error - public key exists
Checklist: