Signed Players

Long-term memory belongs to the playerId your backend sends. With signed players required, LoreMind recalls and saves a player's memories only when the request also carries a short-lived token your backend signed for that player. Anyone who gets hold of your Server Key still can't read or change a player's memories without your signing secret.

Signed players are off until you turn them on. Requests that don't ask for memory are not affected.

How It Works

  1. Your game signs the player in with your backend, as it does today.
  2. For each memory request, your backend signs a token for that playerId with your project's signing secret.
  3. Your backend sends the token as playerAssertion in the request body.
  4. LoreMind checks the token. Without a valid one, the request is refused with 403, and nothing is charged.

Keep the signing secret on your backend only, like your Server Key. Never put it in a game build.

Turn It On

  1. In the dashboard, open your project and go to Settings, then Signed Players. Only team owners and admins can change these settings.
  2. Click Create Secret and copy the secret. It is shown only once.
  3. Store it on your backend, in an environment variable or a secrets manager.
  4. Update your backend to send playerAssertion with every memory request (see below), and deploy it.
  5. Turn on Require Signed Players.

Do step 5 only after your backend sends tokens: from then on, memory requests without a valid token are refused.

Signing a Player

The token is a standard JWT signed with HS256. The key is the signing secret exactly as shown, as UTF-8 bytes.

ClaimRequiredValue
subYesThe request's playerId, exactly
expYesWhen the token expires, in seconds since the Unix epoch. It must still be in the future when the request arrives, and at most 1 hour away
nbfNoIf present, the token is refused before this time

The header's alg must be HS256; tokens signed with any other algorithm are refused. Other claims are ignored.

Make a new token for each request and keep it short-lived: 5 minutes is plenty. Tokens that expire more than 1 hour after the request arrives are refused.

LoreMind allows up to 30 seconds of difference between its clock and your backend's, for both exp and nbf. Keep your backend's clock in sync.

Node.js (jose)

javascript
import { SignJWT } from 'jose';

const key = new TextEncoder().encode(process.env.LOREMIND_PLAYER_SIGNING_SECRET);

const playerAssertion = await new SignJWT({})
  .setProtectedHeader({ alg: 'HS256' })
  .setSubject(playerId)
  .setExpirationTime('5m')
  .sign(key);

Python (PyJWT)

python
import os
import time

import jwt

player_assertion = jwt.encode(
    {"sub": player_id, "exp": int(time.time()) + 300},
    os.environ["LOREMIND_PLAYER_SIGNING_SECRET"],
    algorithm="HS256",
)

C# (System.IdentityModel.Tokens.Jwt)

csharp
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using Microsoft.IdentityModel.Tokens;

var key = new SymmetricSecurityKey(
    Encoding.UTF8.GetBytes(Environment.GetEnvironmentVariable("LOREMIND_PLAYER_SIGNING_SECRET")!));
var token = new JwtSecurityToken(
    claims: new[] { new Claim(JwtRegisteredClaimNames.Sub, playerId) },
    expires: DateTime.UtcNow.AddMinutes(5),
    signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256));
var playerAssertion = new JwtSecurityTokenHandler().WriteToken(token);

Sending the Token

Add playerAssertion to the POST /npc/interact body, next to playerId:

bash
curl -X POST https://loremind.peekgames.dev/api/loremind/v1/npc/interact \
  -H "Authorization: Bearer sk_server_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Do you remember me?",
    "entityMindId": "em_abc123",
    "playerId": "steam_76561198012345678",
    "memory": { "retrieve": true },
    "playerAssertion": "eyJhbGciOiJIUzI1NiJ9..."
  }'

Sign the playerId your backend verified for the signed-in player, never one the game client sent. If your game uses the Unity SDK with your own backend, your backend adds playerAssertion to the request body before it forwards the request to LoreMind.

While signed players are not required, LoreMind accepts playerAssertion and ignores it, so you can deploy your backend change first.

Errors

Both errors are 403, and the request is not charged.

CodeCauseWhat to do
PLAYER_ASSERTION_REQUIREDA memory request (memory.retrieve: true) came without playerAssertionSign the player and send the token with the request
PLAYER_ASSERTION_INVALIDThe token is malformed, expired, valid for more than 1 hour, signed with another secret or algorithm, or its sub is not the request's playerIdSign a new token for this playerId with the current signing secret
json
{
  "error": "Player assertion required",
  "code": "PLAYER_ASSERTION_REQUIRED",
  "message": "This project requires signed players for memory requests. Send playerAssertion: a token your server signs for this playerId with the project signing secret."
}

Don't retry either error unchanged: the same request fails the same way.

Replacing the Secret

Replace Secret creates a new signing secret, and tokens signed with the old one stop working at once. While signed players are required, memory requests are refused until your backend signs with the new secret. To switch without refused requests:

  1. Turn off Require Signed Players.
  2. Click Replace Secret, then put the new secret on your backend and deploy it.
  3. Turn Require Signed Players back on.

Replace the secret right away if it may have been exposed.

Turning It Off

Turn off Require Signed Players at any time. Memory requests then work without a token, as before.

Testing

The Playground's test players are not affected. Memory requests sent straight from the Unity Editor with a Server Key carry no token, so while signed players are required, those requests are refused. Test memory in the Playground, or turn signed players on once your backend signs players.

Next Steps