BitShares Forum

Main => Technical Support => Topic started by: TechnoL0g on June 04, 2018, 02:05:12 pm

Title: Help: Decrypt / Decode Memo from tx - bitsharesjs (solved)
Post by: TechnoL0g on June 04, 2018, 02:05:12 pm
Need help with working examples of decode memo on bitsharesjs.
node -v 8.11.1

I get the transaction history:

Code: [Select]
{
       from: '<BTS Address>',
       to: '<BTS Address>',
       nonce: '<random>',
       message: '<encrypted message>'
}

What sequence of steps is needed to perform the decryption?

by doing:

Code: [Select]
Aes.decrypt_with_checksum(
          private_key,
          public_key,
          memo.nonce,
          memo.message
        ).toString("utf-8");


getting an error: transfer memo exception ...
~TypeError: private_key.get_shared_secret is not a function.
~node_modules\bitsharesjs\dist\ecc\src\aes.js:97


Has anyone encountered a similar problem?

Title: Re: Help: Decrypt / Decode Memo from tx - bitsharesjs
Post by: abit on June 05, 2018, 10:19:30 am
Something like this.

If you have private key of `memo.to`:

 Aes.decrypt_with_checksum(
          PublicKey.fromPublicKeyString(memo.from),
          PrivateKey.fromWif(private_key),
          memo.nonce,
          memo.message
        ).toString("utf-8");

Title: Re: Help: Decrypt / Decode Memo from tx - bitsharesjs
Post by: TechnoL0g on June 05, 2018, 08:12:01 pm
Something like this.

If you have private key of `memo.to`:

 Aes.decrypt_with_checksum(
          PublicKey.fromPublicKeyString(memo.from),
          PrivateKey.fromWif(private_key),
          memo.nonce,
          memo.message
        ).toString("utf-8");

Thanks a friend, it helped me with the above problem!

But now a new one has appeared: AssertionError [ERR_ASSERTION]: Expecting key to begin with GPH, instead got BTS

I need to specify the main blockchain type? but where, heh ..
I found the config in bitsharesjs-ws, probably do not look in the right direction.

It is only necessary to decrypt memo, this should not be a big problem.
Unfortunately in the documentation, I could not find any specifications for this particular issue, only python lib.
Title: Re: Help: Decrypt / Decode Memo from tx - bitsharesjs
Post by: TechnoL0g on June 06, 2018, 12:06:50 am
Problem Solved.

First it was necessary to connect to the Bitshares network and initialize:


Code: [Select]
import {Apis} from "bitsharesjs-ws";
import {PrivateKey, key, PublicKey, Aes} from "../lib";

Apis.instance("wss://bitshares.openledger.info/ws", true).init_promise.then((res) => {
    console.log("connected to:", res[0].network);
    code..
}

Thx you for helping the newcomer!