1
var nacl1 = require('ed2curve');
var nacl = require('tweetnacl');
nacl.util = require('tweetnacl-util');

const theirPublicKey = nacl1.convertSecretKey("GDGM7ZAV5OJIVD375PBOJCBM2FDJOQKDJ5GCNKIGGMX7USFIHNQY2BTT");
console.log(theirPublicKey)

const mySecretKey = nacl1.convertSecretKey("SC77LFF57OC47LBV4D7WZ73FSQ67CL4JPVK65HOZJYCCPTO4IUMECFFJ");

console.log(mySecretKey)
var message = nacl.util.decodeUTF8('Hello!')
console.log(message)

var encryptedMessage = nacl.box(message, theirPublicKey, mySecretKey);

throw new TypeError('unexpected type ' + t + ', use Uint8Array'); ^

TypeError: unexpected type [object Undefined], use Uint8Array at checkArrayTypes (/home/priya/go_test/src/github.com/ed25519/node_modules/tweetnacl/nacl-fast.js:2152:14) at Function.nacl.box.before (/home/priya/go_test/src/github.com/ed25519/node_modules/tweetnacl/nacl-fast.js:2225:3) at Object.nacl.box (/home/priya/go_test/src/github.com/ed25519/node_modules/tweetnacl/nacl-fast.js:2220:20) at Object. (/home/priya/go_test/src/github.com/ed25519/curve.js:14:29) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)

This what I am getting. So please help me to resolve this. Thankyou

2 Answers 2

1

Once you generate Keypair using ed25519 you need to use stellar sdk to convert keys in string representation.

See exact StrKey functions function below of Stellar SDk:

/**
     * StrKey is a helper class that allows encoding and decoding strkey.
     */

    var StrKey = exports.StrKey = (function () {
      function StrKey() {
        _classCallCheck(this, StrKey);
      }

      _createClass(StrKey, null, {
        encodeEd25519PublicKey: {
          /**
           * Encodes data to strkey ed25519 public key.
           * @param {Buffer} data data to encode
           * @returns {string}
           */

          value: function encodeEd25519PublicKey(data) {
            return encodeCheck("ed25519PublicKey", data);
          }
        },
        decodeEd25519PublicKey: {

          /**
           * Decodes strkey ed25519 public key to raw data.
           * @param {string} data data to decode
           * @returns {Buffer}
           */

          value: function decodeEd25519PublicKey(data) {
            return decodeCheck("ed25519PublicKey", data);
          }
        },
        isValidEd25519PublicKey: {

          /**
           * Returns true if the given Stellar public key is a valid ed25519 public key.
           * @param {string} publicKey public key to check
           * @returns {boolean}
           */

          value: function isValidEd25519PublicKey(publicKey) {
            return isValid("ed25519PublicKey", publicKey);
          }
        },
        encodeEd25519SecretSeed: {

          /**
           * Encodes data to strkey ed25519 seed.
           * @param {Buffer} data data to encode
           * @returns {string}
           */

          value: function encodeEd25519SecretSeed(data) {
            return encodeCheck("ed25519SecretSeed", data);
          }
        },
        decodeEd25519SecretSeed: {

          /**
           * Decodes strkey ed25519 seed to raw data.
           * @param {string} data data to decode
           * @returns {Buffer}
           */

          value: function decodeEd25519SecretSeed(data) {
            return decodeCheck("ed25519SecretSeed", data);
          }
        },
        isValidEd25519SecretSeed: {

          /**
           * Returns true if the given Stellar secret key is a valid ed25519 secret seed.
           * @param {string} seed seed to check
           * @returns {boolean}
           */

          value: function isValidEd25519SecretSeed(seed) {
            return isValid("ed25519SecretSeed", seed);
          }
        },
        encodePreAuthTx: {

          /**
           * Encodes data to strkey preAuthTx.
           * @param {Buffer} data data to encode
           * @returns {string}
           */

          value: function encodePreAuthTx(data) {
            return encodeCheck("preAuthTx", data);
          }
        },
        decodePreAuthTx: {

          /**
           * Decodes strkey PreAuthTx to raw data.
           * @param {string} data data to decode
           * @returns {Buffer}
           */

          value: function decodePreAuthTx(data) {
            return decodeCheck("preAuthTx", data);
          }
        },
        encodeSha256Hash: {

          /**
           * Encodes data to strkey sha256 hash.
           * @param {Buffer} data data to encode
           * @returns {string}
           */

          value: function encodeSha256Hash(data) {
            return encodeCheck("sha256Hash", data);
          }
        },
        decodeSha256Hash: {

          /**
           * Decodes strkey sha256 hash to raw data.
           * @param {string} data data to decode
           * @returns {Buffer}
           */

          value: function decodeSha256Hash(data) {
            return decodeCheck("sha256Hash", data);
          }
        }
      });

      return StrKey;
    })();
1

TweetNacl doesn't talk Stellar. You need to convert the keys from their StrKey representation to Buffers.

StellarSdk.StrKey.decodeEd25519PublicKey() and StellarSdk.StrKey.decodeEd25519SecretSeed() is a good start, for javascript.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.