3

I have a problem when trying to use sign function from TweetNaCl. It always throws error unexpected type, use Uint8Array.

const nacl = require('tweetnacl')
nacl.util = require('tweetnacl-util')

const b = nacl.sign.keyPair()
// console.log(b.secretKey) the result is already in Uint8Array form

const c = b.secretKey

const sign= nacl.sign("message", c)
//error unexpected type, use Uint8Array
nacl.sign.keyPair()

wil return an object containing secretkey and publickey .. but when trying to sign

nacl.sign("message", privatekey)

error is trown

Anyone knows how to overcome this? thank you :)

Shaun the Sheep
  • 22,353
  • 1
  • 72
  • 100
theboyonfire
  • 526
  • 1
  • 6
  • 22
  • 2
    All API functions expect `Uint8Arrays`, [here](https://www.npmjs.com/package/tweetnacl#usage). `c` is of type `Uint8Array`, but `"message"` is _not_. Encoding / Decoding of strings is made possible with tweetnacl-util, [here](https://github.com/dchest/tweetnacl-util-js#documentation). – Topaco Jan 06 '20 at 15:18
  • 2
    Ah yes! thanks.. nacl.util.decodeUTF8("message") – theboyonfire Jan 06 '20 at 19:23

0 Answers0