-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ACN keys #85
ACN keys #85
Conversation
Codecov Report
@@ Coverage Diff @@
## main #85 +/- ##
=======================================
Coverage 96.76% 96.76%
=======================================
Files 317 317
Lines 24763 24763
=======================================
Hits 23962 23962
Misses 801 801
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
tests/conftest.py
Outdated
DEFAULT_LEDGER_LIBP2P_NODE = "fetchai" # Secp256k1 keys | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work if we just change it to eth?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, now changed to cosmos tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure linters pass
Please also open a PR on the go repo and reenable the test to check for matching code, once merged there.
can we make it so that we simply download / install the open-acn repo into |
Not at the moment. In a separate step we can make it a submodule. It is important that the whole packages with all its files is downloadable. Otherwise we need to extend the framework. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
ACN REPORT
documentation
ACN
libp2p
https://docs.libp2p.io
https://docs.libp2p.io/concepts/peer-id/
https://blog.ipfs.io/2020-06-09-libp2p-in-2020/
https://max-inden.de/static/introduction-to-libp2p.pdf
https://discuss.libp2p.io/t/generating-peer-id/
https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#ecdsa
docs: add peer id spec libp2p/specs#100
Using an ethereum key in libp2p libp2p/libp2p#62
cryptography
Code
python side:
_make_libp2p_connection
creates:.evn.libp2p
thus, what we get from the python side of things:
libp2p_node
# executablelibp2p_node_<port>.log
.evn.libp2p
agent_address_cert.txt
# signed agent public key<node_public_key>.txt
# contains thenode_key.private_key
helpers/acn/agent_record/AgentRecord.from_cert_request
cert_request.get_signature(data_dir)
-> creates
<agent_address>_cert.txt
here the signature is generated, serving as the proof-of-representation (PoR), stored in
.evn.libp2p
example of (private) peer key (id), as output by our python to
.evn.libp2p
*I removed all irrelevant keys
2.DEFAULT_LEDGER = DEFAULT_LEDGER_LIBP2P_NODE = "ethereum"; tests: FAIL
summary observations:
AEA_AGENT_ADDR
andAEA_P2P_POR_ADDRESS
are redundantgolang side:
there are lots of FetchAI-named functions. In reality probably more general
there are 4 cryptolibraries that are using in the code base
NOTE: these contain modules, function as types that are highly similar or even identically named
for the crypto libraries now namedspaced:
crypto
,p2pCrypto
,ethCrypto
the errors are passed back to
main
and raised only there, so you lose the tracestack.Hence I added: file name and line no. in logging, full traceback on error
errors faced:
aea:connection.py:521 Couldn't connect to libp2p process: encoding/hex: invalid byte: U+0078 'x'
decoding error: "0x" prefix issue
dhtclient.IdentityFromFetchAIKey
->dhtclient.IdentityFromEthereumKey
dhtpeer.IdentityFromFetchAIKey
->dhtpeer.IdentityFromEthereumKey
utils.KeyPairFromFetchAIKey
->utils.KeyPairFromEthereumKey
aea:connection.py:521 Couldn't connect to libp2p process: Wrong peer public key
it seems like splitting off the "0x" is the right way to go. AgentRecord validation (
IsValidProofOfRepresentation
) fails, the logging showsIsValidProofOfRepresentation
is defined indht/dhtnode/utils.go
and used indht/common/handlers.go
dht/dhtnode/utils.go
dht/dhtclient/dhtclient.go
In these FetchAI specific functions
FetchAIPublicKeyFromPubKey
andIDFromFetchAIPublicKey
are used (defined inutils/utils.go
). I implemented theEthereumPublicKeyFromPubKey
, which replaces the first two characters of the pub2peer string with0x
situation is now as follows
Now needs to be figured out is how the other half of the peer public key can be retrieved.
EthereumPublicKeyFromPubKey
KeyPairFromEthereumKey
IDFromEthereumPublicKey
x509: unsupported elliptic curve
the fetch/cosmos and ETH keys are of a different type
get public key from private key (ensure this matches the environmental variable file)
this is interesting, since it showcases that although the pubKey can be retrieved,
(and type can be checked, see
TestEthereumKeyType
above)but only gives an elliptic curve error when calling
.Raw()
to convert to bytestesting the implementation into
KeyPairFromEthereumKey
func TestEthereumPublicKeyFromPubKey(t *testing.T) {
privateKeyHex := "0xbb0c01836c9ddfc89a890d829dfaa569be545bac71cf20bbff8e02a114a2f042"
expectedPublicKeyHex := "0x4a47e8a74fab63f0a8e7615cc9776960159bc79cefc9b6e3164c4c4e018247f58ee51a200a4286fb49af6246c1e14649395a5e658209dbc6086c89530acf7ade"
_, pubKey, err := KeyPairFromEthereumKey(privateKeyHex)
assert.Equal(t, nil, err)
publicKeyHex, err := EthereumPublicKeyFromPubKey(pubKey)
assert.Equal(t, nil, err)
assert.Equal(t, expectedPublicKeyHex, publicKeyHex)
}
now we still need to get the peerID from the public key
func TestIDFromEthereumPublicKey(t *testing.T) {
privateKeyHex := "0xbb0c01836c9ddfc89a890d829dfaa569be545bac71cf20bbff8e02a114a2f042"
_, pubKey, err := KeyPairFromEthereumKey(privateKeyHex)
assert.Equal(t, nil, err)
publicKeyHex, err := EthereumPublicKeyFromPubKey(pubKey)
assert.Equal(t, nil, err)
peerID, err := IDFromEthereumPublicKey(publicKeyHex) // Uncompressed
assert.Equal(t, nil, err)
assert.NotEqual(t, 0, len(peerID))
}
representativePeerPubKey: 029ad4a30398fbd4fc61996918e3e36bad3e9241d3e734373b9e795d209019141c
record.PeerPublicKey: 0x9ad4a30398fbd4fc61996918e3e36bad3e9241d3e734373b9e795d209019141cbd680153b2c8847e2e2134315057004d50971af04b94d46c59ebed2b471a80ce
What we learn here is that the key is compressed.
https://davidederosa.com/basic-blockchain-programming/elliptic-curve-keys/
e.g. 029ad4a30398fbd4fc61996918e3e36bad3e9241d3e734373b9e795d209019141c
where:
we should thus be able to uncompress the key
what we learn here is that the 'default' for libp2p keys is
which does not match what we provide
should be able to compute the pulbic key myself, knowing the elliptic curve. Trying to decompress the key