Skip to content

Commit

Permalink
checks for the existence of a version before doing semver check (#1799)…
Browse files Browse the repository at this point in the history
… (#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
  • Loading branch information
aristidesstaffieri authored Jan 17, 2025
1 parent fc5e15f commit e1785f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/docs/guide/usingFreighterWebApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) -> <Promise<{ signedMessage: Buffer | null; signerAddress: string; } & { error?: string; }>>`
#### `signMessage(message: string, opts: { address: string }) -> <Promise<{ signedMessage: string | null; signerAddress: string; } & { error?: 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.

Expand Down
10 changes: 9 additions & 1 deletion docs/docs/playground/signMessage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ id: signMessage
title: signMessage
---

#### `signMessage(message: string, opts: { address: string }) -> <Promise<{ signedMessage: Buffer | null; signerAddress: string; } & { error?: string; }>>`
#### `signMessage(message: string, opts: { address: string }) -> <Promise<{ signedMessage: string | null; signerAddress: string; } & { error?: string; }>>`

import { SignMessageDemo } from "./components/SignMessageDemo";

<p>The signed message from the response is a base64 encoded string of the signature. Verification Example:</p>
<p>
```
const kp = <signing key pair>
const res = await stellarApi.signMessage("hi", { networkPassphrase: SorobanClient.Networks.TESTNET })
const passes = kp.verify(Buffer.from("hi", "base64"), Buffer.from(res.signedMessage, "base64")) // true
```
</p>
<strong>Test Freighter's `signMessage` method:</strong>
<SignMessageDemo />
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e1785f3

Please sign in to comment.