hukkin / cosmospy Goto Github PK
View Code? Open in Web Editor NEWPython tools for Cosmos wallet management and offline transaction signing
License: MIT License
Python tools for Cosmos wallet management and offline transaction signing
License: MIT License
from cosmospy import BIP32DerivationError, seed_to_privkey
seed = ("angry mouse")
try:
privkey = seed_to_privkey(seed,"m/44'/118'/1'/0/0")
except BIP32DerivationError:
print("No valid private key in this derivation path!")
AttributeError Traceback (most recent call last)
in
9 seed = ("angry mouse")
10 try:
---> 11 privkey = seed_to_privkey(seed,"m/44'/118'/2'/0/0")
12 except BIP32DerivationError:
13 print("No valid private key in this derivation path!")
C:\ProgramData\Anaconda3\lib\site-packages\cosmospy_wallet.py in seed_to_privkey(seed, path)
45 # This can raise a hdwallets.BIP32DerivationError
(which we alias so
46 # that the same exception type is also in the cosmospy
namespace).
---> 47 derived_privkey = hd_wallet.get_privkey_from_path(path)
48
49 return derived_privkey
C:\ProgramData\Anaconda3\lib\site-packages\hdwallets_bip32.py in get_privkey_from_path(self, path)
78 :return: privkey (bytes)
79 """
---> 80 return self.get_extended_privkey_from_path(path)[1]
81
82 def get_extended_pubkey_from_path(
C:\ProgramData\Anaconda3\lib\site-packages\hdwallets_bip32.py in get_extended_privkey_from_path(self, path)
68 assert isinstance(privkey, bytes)
69 for index in path:
---> 70 privkey, chaincode = _derive_private_child(privkey, chaincode, index)
71 return chaincode, privkey
72
C:\ProgramData\Anaconda3\lib\site-packages\hdwallets_utils.py in _derive_private_child(privkey, chaincode, index)
60 f"Invalid private key at index {index}, try the next one!"
61 )
---> 62 secret = k_int.to_bytes(32, "big")
63
64 return secret, payload[32:]
AttributeError: 'mpz' object has no attribute 'to_bytes'
I am wondering if the module will add seed to publickey
and publickey to consensus key or operator key.
Thanks
Hi @hukkinj1
Is the code ready for Stargate? :)
Is it possible to generate seeds words from a keypair?
Cosmostation will not take any privkey, one must enter seed words instead.
I am the receiver of this transaction and I want to spend 0.1 atom from this account. but when I run the following code I get ""signature verification failed; verify correct account sequence and chain-id" error.
curl -X POST "https://lcd.nylira.net/txs" -H "accept: application/json" -H "Content-Type: application/json" -d "{"tx":{"msg":[{"type":"cosmos-sdk/MsgSend","value":{"from_address":"cosmos15wa26mgeuxvtfpnqfle98wupdeeyxzdu7lff9a","to_address":"cosmos15wa26mgeuxvtfpnqfle98wupdeeyxzdu7lff9a","amount":[{"denom":"uatom","amount":"100000"}]}}],"fee":{"gas":"70000","amount":[{"denom":"uatom","amount":"1000"}]},"memo":"","signatures":[{"signature":"8KyuGPORRF5Eakxw5URy9BM0CjDM72pw25PuhXVBGCcZCvxZ/UIsssNR+OO9DH9JUDp89yX/RUMFvbES1MGwhA==","pub_key":{"type":"tendermint/PubKeySecp256k1","value":"A3ouexs2TMGjefw2zBWKNnwSZJgFsMYmf5OHkfwdWTWX"},"account_number":"11335","sequence":"0"}]},"mode":"sync"}"
since I'm sure that my signature is true,the chain-id should be wrong. I can't find the right chain-id. can you help me please?
hi. I use this link to post transaction created by this library. but when I paste the body of transaction at "POST/txs" I get the "TypeError: Failed to fetch" and when I use the curl command I get as a result the code of a HTML file. the transaction I'm trying to post is :
{"tx":{"msg":[{"type":"cosmos-sdk/MsgSend","value":{"from_address":"cosmos1j32hpgtzh4sudpl0658ylr2tdzu65reyy78x50","to_address":"cosmos1j32hpgtzh4sudpl0658ylr2tdzu65reyy78x50","amount":[{"denom":"uatom","amount":"2"}]}}],"fee":{"gas":"70000","amount":[{"denom":"uatom","amount":"1000"}]},"memo":"","signatures":[{"signature":"LY2iTu+6LeMh/s6ASSRlnxJE3aSpTp6Ung0JMIbyPLF+LDI7YH7M+HRzdtc+5kx+V/8fKmWxfAZIqoyNv0Rh3g==","pub_key":{"type":"tendermint/PubKeySecp256k1","value":"A8mdavgH7MjKqgPdZ8Q9T1xihUbiiRzBqnOR5zCGA40p"},"account_number":"11335","sequence":"0"}]},"mode":"sync"}
thanks for your code, but i think some issue from my end, suppose the JSON part can't parse
privkey = seed_to_privkey(seed, path="m/44'/118'/0'/0/0")
tx = Transaction(
privkey=privkey,
account_num=account_number,
sequence=1,
fee=0,
gas=80000,
memo="",
sync_mode='BROADCAST_MODE_SYNC',
chain_id='korellia'
)
tx.add_transfer(
recipient="kyve13nwxn4tuszwk6s93vk73xxe6xwf3ssauk5hhde", amount=10000
)
pushable_tx= tx.get_pushable()
api_base_url = "https://api.korellia.kyve.network"
headers = {'content-type': 'application/json'}
result = requests.post(api_base_url + "/cosmos/tx/v1beta1/txs", data=pushable_tx, proxies=proxies,headers=headers)
print(result.status_code, result.text)
400 {
"code": 3,
"message": "invalid empty tx",
"details": [
]
}
{
"tx": {
"msg": [
{
"type": "cosmos-sdk/MsgSend",
"value": {
"from_address": "kyve1t5jjcj9terudp8serzcrsud86zgq8ad5zxxxx",
"to_address": "kyve13nwxn4tuszwk6s93vk73xxe6xwf3ssaukxxxx",
"amount": [
{
"denom": "uatom",
"amount": "10000"
}
]
}
}
],
"fee": {
"gas": "80000",
"amount": [
{
"denom": "uatom",
"amount": "0"
}
]
},
"memo": "",
"signatures": [
{
"signature": "yZ1Muoe1fQTdwD9wM56hs0mCJEO6S9sxDPEQaCxuL/ZF86zXRqlXMaip0wyKPh1isghjsichoUVoJPLN+KYHTA==",
"pub_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "A38+HgWr2p+qRCvMRuAMwNw6S3gdcGOoprByctGzqhrv"
},
"account_number": "26553",
"sequence": "1"
}
]
},
"mode": "BROADCAST_MODE_SYNC"
}
Hi,
I see REST endpoint /txs has been migrated now and replaced by /cosmos/tx/v1beta1/txs
And that needs enoded transaction string using protobuf. Any plans to support this?
https://docs.cosmos.network/master/migrations/rest.html
Thanks
Currently we use bip32
PyPI library, which requires coincurve
, for BIP32 key derivation. We should derive keys without these added dependencies.
how can I get the average fee of the chain using this library or using any curl command?
I searched for this in https://cosmos.network/rpc/v0.37.9 but couldn't find any fee-related "Get" function.
Can any function be implemented to deal with seed words?
At starname (https://starname.me/), we would like to use this library however we need to customize so far the PATH and the HMR
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.