Author Topic: Issues in decrypting MEMO  (Read 5897 times)

0 Members and 1 Guest are viewing this topic.

Offline monsterer

@xeroc yes I am using the same script you mentioned.
Actually my application does not store merchants private key, is there anyway I can get it through API call?

You decode a memo using the sender's public memo key, and the private key from the receipient's account
My opinions do not represent those of metaexchange unless explicitly stated.
https://metaexchange.info | Bitcoin<->Altcoin exchange | Instant | Safe | Low spreads

Offline madforstrength

@xeroc lemme explain what I am doing,

Well I am working on developing a payment gateway for bitshares in my project, I have created the invoice successfully, now when a user makes payment then he is redirected to my url along with block and transaction numbers.

I then call API with this data to get the whole transaction.
E.g.
Code: [Select]
{"id":1,"method":"get_transaction","params":[3153947,0]}
The API returns me transaction details like (to, from, amount and memo). but memo is encrypted :(

So I call the API again for getting the account to which payment was made.
E.g. 
Code: [Select]
{"id":1,"method":"get_accounts","params":[["1.2.96993"]]}
I extract the memo key from options and then use this memo key as wif key in your code but still getting the following error:

Code: [Select]
Traceback (most recent call last):
  File "memo/memo_test.py", line 11, in <module>
    priv = PrivateKey(wifkey)
  File "/home/developer03/.local/lib/python3.4/site-packages/graphenelib-0.3rc1-py3.4.egg/graphenebase/account.py", line 249, in __init__
  File "/home/developer03/.local/lib/python3.4/site-packages/graphenelib-0.3rc1-py3.4.egg/graphenebase/account.py", line 258, in compressedpubkey
  File "/usr/local/lib/python3.4/dist-packages/ecdsa/keys.py", line 149, in from_string
    assert len(string) == curve.baselen, (len(string), curve.baselen)
AssertionError: (33, 32)

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
private keys are "private"
If you want to have the memo decrypted you NEED to provide the memo key.
you may want to take a look at this script:
https://github.com/xeroc/python-graphenelib/blob/master/scripts/monitor-deposits/monitor.py

what merchant app are you building? Is this the POS project of bts-munich or another project?

Offline madforstrength

@xeroc yes I am using the same script you mentioned.
Actually my application does not store merchants private key, is there anyway I can get it through API call?

This is the exact script I am using

Code: [Select]
wifkey = "BTS81JWvhxW5YQ52rDC2fzCddi3BopYrEtT2qza3qu55s7iFAjLLo"
from graphenebase import Memo, PrivateKey, PublicKey
memo = {
                        "from": "BTS8citBkJYULm8oRsscFbU277GwPMm2NaELESncQqBgynyoKeFK8",
                        "to": "BTS81JWvhxW5YQ52rDC2fzCddi3BopYrEtT2qza3qu55s7iFAjLLo",
                        "nonce": "8864538374045458127",
                        "message": "47db5a59f700b4df2ab7fdcafe638404"
                    }
priv = PrivateKey(wifkey)
pub = PublicKey(memo["from"], prefix="GPH")
dec = decode_memo(priv, pub, memo["nonce"], memo["message"])
print(dec)

And it is giving me this error:
Code: [Select]
Traceback (most recent call last):
  File "memo/memo_test.py", line 11, in <module>
    priv = PrivateKey(wifkey)
  File "/home/developer03/.local/lib/python3.4/site-packages/graphenelib-0.3rc1-py3.4.egg/graphenebase/account.py", line 249, in __init__
  File "/home/developer03/.local/lib/python3.4/site-packages/graphenelib-0.3rc1-py3.4.egg/graphenebase/account.py", line 258, in compressedpubkey
  File "/usr/local/lib/python3.4/dist-packages/ecdsa/keys.py", line 149, in from_string
    assert len(string) == curve.baselen, (len(string), curve.baselen)
AssertionError: (33, 32)
« Last Edit: February 01, 2016, 12:29:47 pm by madforstrength »

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Hi xeroc,

Thanks for your help buddy. Well I am using API to get the transaction to the merchant's account.

I have tried the memo_key found in options returned when we use "get_accounts" to fetch account details but now I am getting this error:

Quote
--cannot decode-- (33, 32)

This is how the memo module is supposed to be used:
Code: [Select]
from graphenebase import Memo, PrivateKey, PublicKey
memo = {"from": "GPH6Co3ctgs6BSsGkti3iVcArMKywbwhnzKDAgmkb6J3Cad7ykDYX",
        "to": "GPH7gU4pHJ9rTUfVA6q6dEgCxgMGVLmq1YM3HRAKpj1VnTzJhrAn2",
        "nonce": "9729217759611568577",
        "message": "aac432f92a8bf52828ac1fda8a3bf6e3"}
priv = PrivateKey("WIF-KEY")
pub = PublicKey("OTHERS-PUBKEY", prefix="GPH")
dec = decode_memo(priv, pub, memo["nonce"], memo["message"])
print(dec)

Quote
Also "get_account_history" is not available in database API and I can't use CLI for this due to nature of my application.
That is true. the get_account_history api is only available in the
history_api and the one implemented in the witness node will NOT decode
the memo because it does not have the private key anywhere. Only the cli
wallet has the private keys.

The only way to work this out for you is to either write a memo decoding
wrapper that uses python3 or to migrate the code over to python2.. not
sure what needs to be done to do that though ..

Offline madforstrength

Hi xeroc,

Thanks for your help buddy. Well I am using API to get the transaction to the merchant's account.

I have tried the memo_key found in options returned when we use "get_accounts" to fetch account details but now I am getting this error:

Quote
--cannot decode-- (33, 32)

Also "get_account_history" is not available in database API and I can't use CLI for this due to nature of my application.
« Last Edit: February 01, 2016, 11:19:11 am by madforstrength »

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
afaik you can use "get_account_history <account name> <limit>" on the cli wallet to get the history which also contains a description parameter that has the decoded memo message

The base58 issue tells me that you have not provided a valid wif private key for decription of the memo

Offline madforstrength

Hello Again Guyz,

Today I am having issue in decrypting the memo of transaction.

Firstly our application is on python2.7 so we cant just install python-graphenelib and use it.

Secondly even if I am installing it on my local machine when I ran memo_decode it gave me
Quote
--cannot decode-- Error loading Base58 object

So ideally I would be glad to know if there is some API that can decrypt the memo for me ;)

Or is there any script that uses python 2.7 to decrypt memo?

Or if none of the above than how can I resolve base58 issue? :(

Thanks and Regards