From e1785f379982059da2270e877714c38cf4310557 Mon Sep 17 00:00:00 2001 From: aristides Date: Fri, 17 Jan 2025 10:18:46 -0700 Subject: [PATCH] checks for the existence of a version before doing semver check (#1799) (#1800) * checks for the existence of a version before doing semver check * updates stale reference to old response type for signMessag API * adds example for decoding signatures * updates response type for signedMessage API in guide example --- docs/docs/guide/usingFreighterWebApp.md | 4 ++-- docs/docs/playground/signMessage.mdx | 10 +++++++++- .../messageListener/freighterApiMessageListener.ts | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/docs/guide/usingFreighterWebApp.md b/docs/docs/guide/usingFreighterWebApp.md index c0aaf543eb..d07ad57e83 100644 --- a/docs/docs/guide/usingFreighterWebApp.md +++ b/docs/docs/guide/usingFreighterWebApp.md @@ -200,9 +200,9 @@ The second parameter is an optional `opts` object where you can specify which ac ### signMessage -#### `signMessage(message: string, opts: { address: string }) -> >` +#### `signMessage(message: string, opts: { address: string }) -> >` -This function accepts a string as the first parameter, which it will decode, sign as the user, and return a Buffer of the signed contents. +This function accepts a string as the first parameter, which it will decode, sign as the user, and return a base64 encoded string of the signed contents. The second parameter is an optional `opts` object where you can specify which account's signature you’re requesting. If Freighter has the public key requested, it will switch to that account. If not, it will alert the user that they do not have the requested account. diff --git a/docs/docs/playground/signMessage.mdx b/docs/docs/playground/signMessage.mdx index fe0e311969..fd4b803c82 100644 --- a/docs/docs/playground/signMessage.mdx +++ b/docs/docs/playground/signMessage.mdx @@ -3,9 +3,17 @@ id: signMessage title: signMessage --- -#### `signMessage(message: string, opts: { address: string }) -> >` +#### `signMessage(message: string, opts: { address: string }) -> >` import { SignMessageDemo } from "./components/SignMessageDemo"; +

The signed message from the response is a base64 encoded string of the signature. Verification Example:

+

+``` +const kp = +const res = await stellarApi.signMessage("hi", { networkPassphrase: SorobanClient.Networks.TESTNET }) +const passes = kp.verify(Buffer.from("hi", "base64"), Buffer.from(res.signedMessage, "base64")) // true +``` +

Test Freighter's `signMessage` method: diff --git a/extension/src/background/messageListener/freighterApiMessageListener.ts b/extension/src/background/messageListener/freighterApiMessageListener.ts index 471c059d44..9e71feec4c 100644 --- a/extension/src/background/messageListener/freighterApiMessageListener.ts +++ b/extension/src/background/messageListener/freighterApiMessageListener.ts @@ -341,7 +341,7 @@ export const freighterApiMessageListener = ( localStore.setItem(ALLOWLIST_ID, allowList.join()); } - if (semver.gte(apiVersion, "4.0.0")) { + if (apiVersion && semver.gte(apiVersion, "4.0.0")) { resolve({ signedBlob: Buffer.from(signedBlob).toString("base64"), signerAddress,