Why I'm doing it?
I'm still new on steemit, and for my introduction post I had some hassles. Like I prepared my post offline because I don't like doing stuff in the browser only to find myself at the end loosing my work of hours. I wrote all in xhtml with css formated only to figure out that in the end I had to format everything once more. So I thought I would make me some script to make this process how I want it.
What I did.
I installed python-steem(Documentation), but I couldn't find how to upload the images. After some searching I figured out that there is now way with this library. But anyway I like python the last years and have still some plans with python.
But I found imagehoster which looks like the base of steemitimages. So I played around and got it managed to upload an image with the help sign.js and curl.
By the way shot by my wife @malamia :) Thank you for that!
What's wrong with it?
But the differences of the secp256k1 implementations between node.js and python driving me nuts. Has anyone an idea how to get the signature in DER format converted to lower S (whatever that means. Only thing what I understood is that it is bitcoin specific and little endian instead of big endian, and shorter. I guess it's the same for the steem blockchain!?)
More details.
And it took me now the whole day to read the following:
- secp256k1 node.js implementation
- dsteem node.js implementation
- dsteem node.js docs
- secp256k1 python implementation
- steem python implementation
- steem python docs
- and some others I discarded like two python bitcoin libraries
Help very welcome
Maybe I have overlooked something in the python steem implementation :/
So if someone have an idea, I would be very happy!
Some code
#!/usr/bin/python3
from hashlib import sha256
import sys
import secp256k1
#first import of steembase.account fails. (at least on my machine)
try:
import steembase.account
except:
import steembase.account
from steem.utils import compat_bytes
class SteemitImages:
def __init__(self):
pass
def imageSign(_data, _key):
h = sha256()
h.update(b"ImageSigningChallenge")
h.update(_data)
# hash.digest() is the same as in sign.js
key = steembase.account.PrivateKey(_key)
# key is also the same as in sign.js
sk = secp256k1.PrivateKey(compat_bytes(key), raw=True)
sig = sk.ecdsa_sign(h.digest(), raw=True)
out = sk.ecdsa_signature_normalize(sig)
return out.hex()
def getDataFromFile(_file):
with open(_file, mode='rb') as file:
return file.read()
if __name__ == "__main__":
print(SteemitImages.imageSign(SteemitImages.getDataFromFile(sys.argv[2]),sys.argv[1]))
steem.chat for my challenge. Even better I had not to write it anymore because what I need exists already: imagehoster-python-client.
Finally @holger80 presented me solution through Thank you @holger80, you are my hero of the day :)