0

I'm following this code from Phantom doc.

const provider = getProvider(); 
const message = "To avoid digital dognappers, sign below to authenticate with CryptoCorgis";
const encodedMessage = new TextEncoder().encode(message);
const signedMessage = await provider.signMessage(encodedMessage, "utf8");
console.log('Signature : ' + JSON.stringify( signedMessage ) );

And the console output for signedMessage is below.

Signature : {"signature":{"type":"Buffer","data":[124,66,191,12,89,236,90,243,235,24,181,69,221,212,190,153,225,201,69,131,231,221,125,229,101,202,245,39,75,81,243,119,109,131,223,7,174,98,249,148,18,227,51,54,3,218,200,74,118,189,57,96,187,145,0,146,137,192,147,113,107,19,94,1]},"publicKey":"zGmof8SeyvHZqsTBjsKXSV"}

If I do signedMessage.toString(), I get

Signature : [object Object]

So how do I get just the typical message hash signature in hexadecimal string?

1 Answer 1

1

You want to base58 encode the Uint8Array you get back. Typically the bs58 library is used for this.

import { encode } from 'bs58';

const message = new TextEncoder().encode('Please sign me :)');
const { signature } = await getProvider().signMessage(message, "utf8");
const base58 = encode(signature);

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.