apeworx / ape-ledger Goto Github PK
View Code? Open in Web Editor NEWLedger Nano S and X account plugin for the Ape Framework
Home Page: https://www.apeworx.io/
License: Apache License 2.0
Ledger Nano S and X account plugin for the Ape Framework
Home Page: https://www.apeworx.io/
License: Apache License 2.0
Create the plugin
Currently, Ledger assumes Ethereum.
We can track the network information in the keyfile (much like we do in the ape-starknet
plugin) and then use that ecosystem when decoding the address.
Describe the syntax and semantics of how you would like to see this feature implemented. The more detailed the better!
Remember, your feature is much more likely to be included if it does not involve any breaking changes.
Include links to any open issues that must be resolved before this feature can be implemented.
ape
and plugin versions:$ ape --version
0.1.0b5
$ ape plugins list
Installed Plugins:
ledger 0.1.0b2
File site-packages/ape/contracts/base.py:206, in ContractTransactionHandler.__call__(self, *args, **kwargs)
203 if not selected_abi:
204 raise ArgumentsLengthError(len(args))
--> 206 return ContractTransaction( # type: ignore
207 abi=selected_abi,
208 address=self.contract.address,
209 provider=self.provider,
210 converter=self.converter,
211 )(*args, **kwargs)
File site-packages/ape/contracts/base.py:177, in ContractTransaction.__call__(self, *args, **kwargs)
175 sender = kwargs["sender"]
176 txn = self.encode(*args, **kwargs)
--> 177 return sender.call(txn)
179 raise TransactionError(message="Must specify a `sender`.")
File site-packages/ape/api/accounts.py:135, in AccountAPI.call(self, txn, send_everything)
132 elif not isinstance(txn.required_confirmations, int) or txn.required_confirmations < 0:
133 raise TransactionError(message="'required_confirmations' must be a positive integer.")
--> 135 txn.signature = self.sign_transaction(txn)
136 if not txn.signature:
137 raise SignatureError("The transaction was not signed.")
File site-packages/ape_ledger/accounts.py:93, in LedgerAccount.sign_transaction(self, txn)
92 def sign_transaction(self, txn: TransactionAPI) -> Optional[TransactionSignature]:
---> 93 signed_txn = self._client.sign_transaction(txn.as_dict())
95 return TransactionSignature(*signed_txn)
File site-packages/ape_ledger/client.py:366, in LedgerEthereumAccountClient.sign_transaction(self, txn)
353 """
354 Sign a transaction using your Ledger device. You will need to follow
355 the prompts on the device to validate the transaction data.
(...)
362 RLP transaction chunk - arbitrary
363 """
365 unsigned_transaction = serializable_unsigned_transaction_from_dict(txn)
--> 366 rlp_encoded_tx = rlp.encode(unsigned_transaction)
367 payload = self.path_bytes + rlp_encoded_tx
368 chunks = [payload[i : i + 255] for i in range(0, len(payload), 255)] # noqa: E203
File site-packages/rlp/codec.py:120, in encode(obj, sedes, infer_serializer, cache)
118 item = sedes.serialize(obj)
119 elif infer_serializer:
--> 120 item = infer_sedes(obj).serialize(obj)
121 else:
122 item = obj
File site-packages/rlp/codec.py:318, in infer_sedes(obj)
316 return text
317 msg = 'Did not find sedes handling type {}'.format(type(obj).__name__)
--> 318 raise TypeError(msg)
TypeError: Did not find sedes handling type TypedTransaction
When we added EIP1559 support, we probably forgot to update these plugins
ape
and plugin versions:
"eth-ape>=0.5.2",
"ape-hardhat>=0.5.1",
"ape-alchemy>=0.5.0",
"ape-solidity>=0.5.0",
"ape-vyper>=0.5.0",
"ape-ledger>=0.5.0",
"ape-etherscan>=0.5.1",
Python Version: 3.10.4
OS: macOS/linux/win
ubuntu-latest on github or ubuntu-22.04
building 'hid' extension
creating build
creating build/temp.linux-x86_64-3.10
creating build/temp.linux-x86_64-3.10/hidapi
creating build/temp.linux-x86_64-3.10/hidapi/libusb
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/opt/hostedtoolcache/Python/3.10.4/x64/include/python3.10 -c hid.c -o build/temp.linux-x86_64-3.10/hid.o
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/opt/hostedtoolcache/Python/3.10.4/x64/include/python3.10 -c hidapi/libusb/hid.c -o build/temp.linux-x86_64-3.10/hidapi/libusb/hid.o
hidapi/libusb/hid.c:47:10: fatal error: libusb.h: No such file or directory
47 | #include <libusb.h>
| ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> hidapi
note: This is an issue with the package mentioned above, not pip.
https://github.com/curvefi/curve-dao-operations/actions/runs/3554984959/jobs/5971413801
the issue is with the package hidapi:
Line 60 in 36c79ad
i am not sure what's the best way to fix this here, because it seems to work just about fine one my MacBook, but github ci really doesn't like it.
Fill this in if you have ideas on how the bug could be fixed.
Use CLI transaction display to show the user the transaction are signing.
This is largely due that Ledger devices required blind signing to work with us and that is not too secure.
The downside is that users have to confirm transactions twice: once in the CLI and again in the device. The CLI one won't be blind though.
Follow ape_accounts
Include links to any open issues that must be resolved before this feature can be implemented.
Would be really nice if the account container class did some sort of detection (perhaps lazily) of whether a device was connected, and if so, what accounts are connected via that device. Especially useful for something like ape-safe, where it dynamically detects what wallets it can use to sign with
May need to track some sort of "device ID" (maybe a processed version of the master pubkey) that can be used to detect which devices are connected to which accounts, and then based on the connected devices at the time that a request is made to the account container of which accounts are available we filter that response dynamically.
Include links to any open issues that must be resolved before this feature can be implemented.
ape
and plugin versions:$ ape --version
0.6.10
$ ape plugins list
Installed Plugins:
arbitrum 0.6.0
ledger 0.6.0
infura 0.6.1
etherscan 0.6.5.dev2+g46af3fe
Please include information like:
I added my ledger account from the HD path 'm/44'/60'/24'/0/0' by running "ledger add" and flipped pages to select the account I want to add
However, it seems ape-ledger is ignoring the page flip and registered the accounts associated with 'm/44'/60'/4'/0/0'
Right now I forcibly fixed it by replacing
" account_data = {"address": address, "hdpath": hdpath}"
with
" account_data = {"address": address, "hdpath": "m/44'/60'/24'/0/0"}"
in accounts.py
Try to use checkout https://github.com/ethereum/eth-account/blob/bd3dc2c0e85934b9c47980053d9f1d16a7540990/eth_account/hdaccount/deterministic.py#L187
for HDPath
instead of using our own implementation.
Keep in mind that ours is a bit ledger-specific, so we may need to subclass or something.
Rely on checkout https://github.com/ethereum/eth-account/blob/bd3dc2c0e85934b9c47980053d9f1d16a7540990/eth_account/hdaccount/deterministic.py#L187 for path validation (and class definition).
Just try (maybe a spike?)
Include links to any open issues that must be resolved before this feature can be implemented.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.