Skip to Content
defold-typescript libraries
widgrensitasobi-defold

widgrensit/asobi-defold/asobi.device

Guest device credentials: a stable device id and secret that a game generates once, saves, and presents to guest sign-in on every launch, so the same pair resumes the same player.

  • GitHub: widgrensit/asobi-defold — pinned to v1.18.1
    1. Pick a release from widgrensit/asobi-defold releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as device from "asobi.device"

Functions

generate(opts?: Pick<DeviceOptions, 'random_bytes' | 'device_id'>): LuaMultiReturn<[ device_id: string, device_secret: string ]>

Generates a new device id and secret without saving them. The secret is standard base64 of 32 random bytes, the shape the server requires.

Parameters

  • opts?: Pick<DeviceOptions, 'random_bytes' | 'device_id'> — The random byte source and a fixed device id.

Returns

  • LuaMultiReturn<[ device_id: string, device_secret: string ]> — The device id and the device secret.

load_or_create(opts?: DeviceOptions): LuaMultiReturn<[ device_id: string, device_secret: string ]>

Loads the saved device id and secret, or generates a pair and saves it on first run. Outside the engine it generates a pair without saving. On HTML5 a pair saved in the older save format is replaced, since web builds writing it all minted the same id.

Parameters

  • opts?: DeviceOptions — The save file, the random byte source and a fixed device id.

Returns

  • LuaMultiReturn<[ device_id: string, device_secret: string ]> — The device id and the device secret.

clear(opts?: Pick<DeviceOptions, 'app' | 'file'>)

Erases the saved pair, so the next load_or_create mints a new guest. The server account is not deleted. Pass the same save file used to sign in.

Parameters

  • opts?: Pick<DeviceOptions, 'app' | 'file'> — The save file.

Variables

_base64: (bytes: string) => string

Internal. The standard base64 encoder generate uses, exposed for upstream's encoder test.

Types

DeviceOptions

DeviceOptions.app?: string

The save file's application name, passed to sys.get_save_file. Defaults to "asobi".

DeviceOptions.file?: string

The save file's name, passed to sys.get_save_file. Defaults to "guest_device".

DeviceOptions.random_bytes?: (n: number) => string

Returns n random bytes from a stronger source than the default, which uses the browser's crypto on HTML5 and a seeded math.random elsewhere. It must return at least 32 bytes when asked for 32.

DeviceOptions.device_id?: string

A fixed device id, used in place of a random one.

On this page