elective-stereophonic
elective-stereophonic
How to sign a transaction locally and then send it to a server?
Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest Nxt Client: Nxt 1.11.15

Author Topic: How to sign a transaction locally and then send it to a server?  (Read 1735 times)

box1413

  • Hero Member
  • *****
  • Karma: +101/-4
  • Offline Offline
  • Posts: 687
    • View Profile
How to sign a transaction locally and then send it to a server?
« on: January 21, 2017, 06:14:04 am »

Does anyone know which api involves signing a transaction locally then sending it to a server without revealing your password?

Which api's do I have to use?

And is there a code example of this in action?

There's so many API's I just don't know which one to use or how to combine them.
Logged

lurker10

  • Hero Member
  • *****
  • Karma: +168/-33
  • Offline Offline
  • Posts: 1334
    • View Profile
Re: How to sign a transaction locally and then send it to a server?
« Reply #1 on: January 21, 2017, 07:06:45 am »

Any API with a broadcast=false will give you transaction bytes for that transaction. After that use broadcastTransaction API to send it to the network without revealing the passphrase.
Logged
Run a node - win a prize! "Lucky node" project jar: NXT-8F28-EDVE-LPPX-HY4E7

ScripterRon

  • Hero Member
  • *****
  • Karma: +75/-2
  • Offline Offline
  • Posts: 523
    • View Profile
Re: How to sign a transaction locally and then send it to a server?
« Reply #2 on: January 21, 2017, 04:29:25 pm »

Take a look at https://github.com/ScripterRon/NxtCore to see how to sign a transaction.  The Transaction() class creates a signed or unsigned transaction.  The relevant code is the following:
Code: [Select]
  //
  // Sign the transaction
  //
  byte[] txBytes = getBytes(true);
  this.signature = Crypto.sign(txBytes, passPhrase);
  this.signatureHash = Crypto.singleDigest(signature);
The unsigned bytes returned by the server with broadcast=false contain 64 bytes of zero in place of the signature.  Replace those bytes with the signature returned by Crypto.sign() and then broadcast the transaction using the broadcastTransaction API.  The signature bytes are at offset 95 in the transaction (see Transaction.getBytes()).

If you are using Java, you can use the crypto routines in NxtCore.  Otherwise, you will need to provide the crypto routines in your language.  Take a look at the Crypto() class to see what you need to do.

I took a different approach for Ardor which might be simpler to understand.  Take a look at https://github.com/ScripterRon/Nxt2API.  Look at Nxt.broadcastTransaction() which takes the unsigned bytes returned by the server, signs the transaction, and then broadcasts the transaction.  While this library is for use with Ardor, transaction signing is the same as Nxt (the transaction offset of the signature is different).
Logged
 

elective-stereophonic
elective-stereophonic
assembly
assembly