Tilde Friends
SSB Database

Classes

struct  _tf_ssb_following_t
 
struct  _tf_ssb_db_stored_connection_t
 
struct  _tf_ssb_identity_info_t
 

Typedefs

typedef struct _tf_ssb_t tf_ssb_t
 
typedef void() tf_ssb_db_blob_get_callback_t(bool found, const uint8_t *data, size_t size, void *user_data)
 
typedef void() tf_ssb_db_store_message_callback_t(const char *id, bool stored, void *user_data)
 
typedef void() tf_ssb_db_blob_store_callback_t(const char *id, bool is_new, void *user_data)
 
typedef struct _tf_ssb_following_t tf_ssb_following_t
 
typedef struct _tf_ssb_db_stored_connection_t tf_ssb_db_stored_connection_t
 
typedef struct _tf_ssb_identity_info_t tf_ssb_identity_info_t
 

Functions

void tf_ssb_db_init (tf_ssb_t *ssb)
 
void tf_ssb_db_init_reader (sqlite3 *db)
 
bool tf_ssb_db_message_content_get (tf_ssb_t *ssb, const char *id, uint8_t **out_blob, size_t *out_size)
 
bool tf_ssb_db_blob_has (sqlite3 *db, const char *id)
 
bool tf_ssb_db_blob_get (tf_ssb_t *ssb, const char *id, uint8_t **out_blob, size_t *out_size)
 
void tf_ssb_db_blob_get_async (tf_ssb_t *ssb, const char *id, tf_ssb_db_blob_get_callback_t *callback, void *user_data)
 
void tf_ssb_db_store_message (tf_ssb_t *ssb, JSContext *context, const char *id, JSValue val, const char *signature, int flags, tf_ssb_db_store_message_callback_t *callback, void *user_data)
 
void tf_ssb_db_blob_store_async (tf_ssb_t *ssb, const uint8_t *blob, size_t size, tf_ssb_db_blob_store_callback_t *callback, void *user_data)
 
bool tf_ssb_db_blob_store (tf_ssb_t *ssb, const uint8_t *blob, size_t size, char *out_id, size_t out_id_size, bool *out_new)
 
JSValue tf_ssb_db_get_message_by_id (tf_ssb_t *ssb, const char *id, bool is_keys)
 
bool tf_ssb_db_get_message_by_author_and_sequence (tf_ssb_t *ssb, const char *author, int32_t sequence, char *out_message_id, size_t out_message_id_size, char *out_previous, size_t out_previous_size, double *out_timestamp, char **out_content, char *out_hash, size_t out_hash_size, char *out_signature, size_t out_signature_size, int *out_flags)
 
bool tf_ssb_db_get_latest_message_by_author (tf_ssb_t *ssb, const char *author, int32_t *out_sequence, char *out_message_id, size_t out_message_id_size)
 
JSValue tf_ssb_db_visit_query (tf_ssb_t *ssb, const char *query, const JSValue binds, void(*callback)(JSValue row, void *user_data), void *user_data)
 
bool tf_ssb_db_check (sqlite3 *db, const char *author)
 
int tf_ssb_db_identity_get_count_for_user (tf_ssb_t *ssb, const char *user)
 
bool tf_ssb_db_identity_create (tf_ssb_t *ssb, const char *user, uint8_t *out_public_key, uint8_t *out_private_key)
 
bool tf_ssb_db_identity_delete (tf_ssb_t *ssb, const char *user, const char *public_key)
 
bool tf_ssb_db_identity_add (tf_ssb_t *ssb, const char *user, const char *public_key, const char *private_key)
 
bool tf_ssb_db_identity_get_active (sqlite3 *db, const char *user, const char *package_owner, const char *package_name, char *out_identity, size_t out_identity_size)
 
void tf_ssb_db_identity_visit (tf_ssb_t *ssb, const char *user, void(*callback)(const char *identity, void *user_data), void *user_data)
 
void tf_ssb_db_identity_visit_all (tf_ssb_t *ssb, void(*callback)(const char *identity, void *user_data), void *user_data)
 
const char * tf_ssb_db_get_user_for_identity (tf_ssb_t *ssb, const char *public_key)
 
bool tf_ssb_db_identity_get_private_key (tf_ssb_t *ssb, const char *user, const char *public_key, uint8_t *out_private_key, size_t private_key_size)
 
JSValue tf_ssb_format_message (JSContext *context, const char *previous, const char *author, int32_t sequence, double timestamp, const char *hash, const char *content, const char *signature, int flags)
 
const char ** tf_ssb_db_following_deep_ids (tf_ssb_t *ssb, const char **ids, int count, int depth)
 
tf_ssb_following_ttf_ssb_db_following_deep (tf_ssb_t *ssb, const char **ids, int count, int depth, bool include_blocks)
 
const char ** tf_ssb_db_get_all_visible_identities (tf_ssb_t *ssb, int depth)
 
tf_ssb_db_stored_connection_ttf_ssb_db_get_stored_connections (tf_ssb_t *ssb, int *out_count)
 
void tf_ssb_db_forget_stored_connection (tf_ssb_t *ssb, const char *address, int port, const char *pubkey)
 
bool tf_ssb_db_get_account_password_hash (tf_ssb_t *ssb, const char *name, char *out_password, size_t password_size)
 
bool tf_ssb_db_set_account_password (uv_loop_t *loop, sqlite3 *db, JSContext *context, const char *name, const char *password)
 
bool tf_ssb_db_register_account (uv_loop_t *loop, sqlite3 *db, JSContext *context, const char *name, const char *password)
 
const char * tf_ssb_db_get_property (tf_ssb_t *ssb, const char *id, const char *key)
 
bool tf_ssb_db_set_property (tf_ssb_t *ssb, const char *id, const char *key, const char *value)
 
bool tf_ssb_db_remove_property (tf_ssb_t *ssb, const char *id, const char *key)
 
bool tf_ssb_db_remove_value_from_array_property (tf_ssb_t *ssb, const char *id, const char *key, const char *value)
 
bool tf_ssb_db_add_value_to_array_property (tf_ssb_t *ssb, const char *id, const char *key, const char *value)
 
void tf_ssb_db_resolve_index_async (tf_ssb_t *ssb, const char *host, void(*callback)(const char *path, void *user_data), void *user_data)
 
bool tf_ssb_db_verify (tf_ssb_t *ssb, const char *id, int32_t debug_sequence, bool fix)
 
bool tf_ssb_db_user_has_permission (tf_ssb_t *ssb, sqlite3 *db, const char *id, const char *permission)
 
bool tf_ssb_db_get_global_setting_bool (sqlite3 *db, const char *name, bool *out_value)
 
bool tf_ssb_db_get_global_setting_int64 (sqlite3 *db, const char *name, int64_t *out_value)
 
bool tf_ssb_db_get_global_setting_string (sqlite3 *db, const char *name, char *out_value, size_t size)
 
bool tf_ssb_db_set_global_setting_from_string (sqlite3 *db, const char *name, char *value)
 
const char * tf_ssb_db_get_profile (sqlite3 *db, const char *id)
 
const char * tf_ssb_db_get_profile_name (sqlite3 *db, const char *id)
 
bool tf_ssb_db_generate_invite (sqlite3 *db, const char *id, const char *host, int port, int use_count, int expires_seconds, char *out_invite, size_t size)
 
bool tf_ssb_db_use_invite (sqlite3 *db, const char *id)
 
bool tf_ssb_db_is_account_familiar (sqlite3 *db, const char *id, int depth)
 
int tf_ssb_sqlite_authorizer (void *user_data, int action_code, const char *arg0, const char *arg1, const char *arg2, const char *arg3)
 
bool tf_ssb_db_has_invite (sqlite3 *db, const char *id)
 
tf_ssb_identity_info_ttf_ssb_db_get_identity_info (tf_ssb_t *ssb, const char *user, const char *package_owner, const char *package_name)
 
void tf_ssb_db_add_blob_wants (sqlite3 *db, const char *id)
 

Detailed Description

This is the main interface to SSB persistence. Everything about getting and storing messages and blobs goes through here.

Typedef Documentation

◆ tf_ssb_db_blob_get_callback_t

typedef void() tf_ssb_db_blob_get_callback_t(bool found, const uint8_t *data, size_t size, void *user_data)

A function called when a blob is retrieved from the database.

Parameters
foundWhether the blob was found.
dataThe blob data if found.
sizeThe size of the blob data if found, in bytes.
user_dataThe user data.

◆ tf_ssb_db_blob_store_callback_t

typedef void() tf_ssb_db_blob_store_callback_t(const char *id, bool is_new, void *user_data)

A function called when a block is stored in the database.

Parameters
idThe blob identifier.
is_newTrue if the blob wasn't already in the database.
user_dataThe user data.

◆ tf_ssb_db_store_message_callback_t

typedef void() tf_ssb_db_store_message_callback_t(const char *id, bool stored, void *user_data)

A function called when a message is stored in the database.

Parameters
idThe message identifier.
storedTrue if the message wasn't already in the database.
user_dataThe user data.

◆ tf_ssb_db_stored_connection_t

Information about a stored SHS connection.

◆ tf_ssb_following_t

Information about a single followed account.

◆ tf_ssb_identity_info_t

Identity information

◆ tf_ssb_t

typedef struct _tf_ssb_t tf_ssb_t

An SSB instance.

Function Documentation

◆ tf_ssb_db_add_blob_wants()

void tf_ssb_db_add_blob_wants ( sqlite3 db,
const char *  id 
)

Add or update a blob wants cache entry.

Parameters
dbThe database.
idThe wanted blob ID.

◆ tf_ssb_db_add_value_to_array_property()

bool tf_ssb_db_add_value_to_array_property ( tf_ssb_t ssb,
const char *  id,
const char *  key,
const char *  value 
)

Ensure a value is in an entry in the properties table that is a JSON array.

Parameters
ssbThe SSB instance.
idThe user.
keyThe property key.
valueThe value to add to the JSON array.
Returns
true if the property was updated.

◆ tf_ssb_db_blob_get()

bool tf_ssb_db_blob_get ( tf_ssb_t ssb,
const char *  id,
uint8_t **  out_blob,
size_t *  out_size 
)

Retrieve a blob from the database.

Parameters
ssbThe SSB instance.
idThe blob identifier.
[out]out_blobPopulated with the blob data.
[out]out_sizeThe size of the blob data.
Returns
true If the blob was found and retrieved.

◆ tf_ssb_db_blob_get_async()

void tf_ssb_db_blob_get_async ( tf_ssb_t ssb,
const char *  id,
tf_ssb_db_blob_get_callback_t callback,
void *  user_data 
)

Retrieve a blob from the database asynchronously.

Parameters
ssbThe SSB instance.
idThe blob identifier.
callbackCallback called with the result.
user_dataThe user data.

◆ tf_ssb_db_blob_has()

bool tf_ssb_db_blob_has ( sqlite3 db,
const char *  id 
)

Determine whether a blob is in the database by ID.

Parameters
dbThe SQLite database instance to use.
idThe blob identifier.
Returns
true If the blob is in the database.

◆ tf_ssb_db_blob_store()

bool tf_ssb_db_blob_store ( tf_ssb_t ssb,
const uint8_t *  blob,
size_t  size,
char *  out_id,
size_t  out_id_size,
bool *  out_new 
)

Store a blob in the database and wait for the operation to complete.

Parameters
ssbThe SSB instance.
blobThe blob data.
sizeThe size of the blob.
[out]out_idPopulated with the blob identifier.
out_id_sizeThe size of the out_id buffer.
[out]out_newTrue if the blob wasn't already in the datbase.

◆ tf_ssb_db_blob_store_async()

void tf_ssb_db_blob_store_async ( tf_ssb_t ssb,
const uint8_t *  blob,
size_t  size,
tf_ssb_db_blob_store_callback_t callback,
void *  user_data 
)

Store a blob in the database asynchronously.

Parameters
ssbThe SSB instance.
blobThe blob data.
sizeThe size of the blob data.
callbackA callback to call upon completion.
user_dataUser data for the callback.

◆ tf_ssb_db_check()

bool tf_ssb_db_check ( sqlite3 db,
const char *  author 
)

Sanity check the feed for the given author.

Parameters
dbThe SQLite database instance to use.
authorThe identity of the author to check.
Returns
True if the author's feed is fully valid.

◆ tf_ssb_db_following_deep()

tf_ssb_following_t * tf_ssb_db_following_deep ( tf_ssb_t ssb,
const char **  ids,
int  count,
int  depth,
bool  include_blocks 
)

Return information about identities visible from a set of identities given known follows and blocks.

Parameters
ssbThe SSB instance.
idsAn array of identities.
countThe number of identities.
depthThe following depth to use (prefer 2).
include_blocksWhether to include blocked identities in results.
Returns
An array of information about visible accounts. Free with tf_free().

◆ tf_ssb_db_following_deep_ids()

const char ** tf_ssb_db_following_deep_ids ( tf_ssb_t ssb,
const char **  ids,
int  count,
int  depth 
)

Get all the identities visible from a set of identities given known follows and blocks.

Parameters
ssbThe SSB instance.
idsAn array of identities.
countThe number of identities.
depthThe following depth to use (prefer 2).
Returns
An array of identities. Free with tf_free().

◆ tf_ssb_db_forget_stored_connection()

void tf_ssb_db_forget_stored_connection ( tf_ssb_t ssb,
const char *  address,
int  port,
const char *  pubkey 
)

Remove a stored connection.

Parameters
ssbThe SSB instance.
addressThe connection address.
portThe connection network port number.
pubkeyThe identity of the connection.

◆ tf_ssb_db_generate_invite()

bool tf_ssb_db_generate_invite ( sqlite3 db,
const char *  id,
const char *  host,
int  port,
int  use_count,
int  expires_seconds,
char *  out_invite,
size_t  size 
)

Generate an invite code and store information for it to be usable.

Parameters
dbThe database.
idThe identity.
hostHostname to which recipient should connect.
portThe port to which the recipient should connect.
use_countNumber of times the invite code is allowed to be used, or -1 for indefinitely.
expires_secondsHow long the invite lasts.
out_invitePopulated with the invite code on success.
sizeThe size of the out_invite buffer.
Returns
true If an invite was generated.

◆ tf_ssb_db_get_account_password_hash()

bool tf_ssb_db_get_account_password_hash ( tf_ssb_t ssb,
const char *  name,
char *  out_password,
size_t  password_size 
)

Retrieve a user's hashed password from the database.

Parameters
ssbThe SSB instance.
nameThe username.
[out]out_passwordPopulated with the password.
password_sizeThe size of the out_password buffer.
Returns
true if the password hash was successfully retrieved.

◆ tf_ssb_db_get_all_visible_identities()

const char ** tf_ssb_db_get_all_visible_identities ( tf_ssb_t ssb,
int  depth 
)

Get all visible identities from all local accounts.

Parameters
ssbThe SSB instance.
depthThe following depth to consider (prefer 2).
Returns
The visible identities. Free with tf_free().

◆ tf_ssb_db_get_global_setting_bool()

bool tf_ssb_db_get_global_setting_bool ( sqlite3 db,
const char *  name,
bool *  out_value 
)

Get a boolean global setting value.

Parameters
dbThe database.
nameThe setting name.
out_valuePopulated with the value.
Returns
true if the setting was found.

◆ tf_ssb_db_get_global_setting_int64()

bool tf_ssb_db_get_global_setting_int64 ( sqlite3 db,
const char *  name,
int64_t *  out_value 
)

Get an int64_t global setting value.

Parameters
dbThe database.
nameThe setting name.
out_valuePopulated with the value.
Returns
true if the setting was found.

◆ tf_ssb_db_get_global_setting_string()

bool tf_ssb_db_get_global_setting_string ( sqlite3 db,
const char *  name,
char *  out_value,
size_t  size 
)

Get a string global setting value.

Parameters
dbThe database.
nameThe setting name.
out_valuePopulated with the value.
sizeThe size of the out_value buffer.
Returns
true if the setting was found.

◆ tf_ssb_db_get_identity_info()

tf_ssb_identity_info_t * tf_ssb_db_get_identity_info ( tf_ssb_t ssb,
const char *  user,
const char *  package_owner,
const char *  package_name 
)

Get available identities, names, and the active identity for a user.

Parameters
ssbThe SSB instance.
userThe user name.
package_ownerThe owner of the package for which identity info is being fetched.
package_nameThe name of the package for which identity info is being fetched.
Returns
A struct of identities, names, and the active identity. Free with tf_free().

◆ tf_ssb_db_get_latest_message_by_author()

bool tf_ssb_db_get_latest_message_by_author ( tf_ssb_t ssb,
const char *  author,
int32_t *  out_sequence,
char *  out_message_id,
size_t  out_message_id_size 
)

Get information about the last message from an author.

Parameters
ssbThe SSB instance.
authorThe author's identity.
[out]out_sequencePopulated with the message sequence number.
[out]out_message_idPopulated with the message identifier.
out_message_id_sizeThe size of the out_message_id buffer.
Returns
True if the message was found and information was retrieved.

◆ tf_ssb_db_get_message_by_author_and_sequence()

bool tf_ssb_db_get_message_by_author_and_sequence ( tf_ssb_t ssb,
const char *  author,
int32_t  sequence,
char *  out_message_id,
size_t  out_message_id_size,
char *  out_previous,
size_t  out_previous_size,
double *  out_timestamp,
char **  out_content,
char *  out_hash,
size_t  out_hash_size,
char *  out_signature,
size_t  out_signature_size,
int *  out_flags 
)

Get a message by its author and sequence number.

Parameters
ssbThe SSB instance.
authorThe author's identity.
sequenceThe message sequence number.
[out]out_message_idPopulated with the message identifier.
out_message_id_sizeThe size of the out_message_id buffer.
[out]out_previousPopulated with the previous message identifier.
out_previous_sizeThe size of the out_previous buffer.
[out]out_timestampPopulated with the timestamp.
[out]out_contentPopulated with the message content. Free with tf_free().
[out]out_hashPopulated with the message hash format.
out_hash_sizeThe size of the out_hash buffer.
[out]out_signaturePopulated with the message signature.
out_signature_sizeThe size of the out_signature buffer.
[out]out_flagsPopulated with flags describing the format of the message.
Returns
True if the message was found and retrieved.

◆ tf_ssb_db_get_message_by_id()

JSValue tf_ssb_db_get_message_by_id ( tf_ssb_t ssb,
const char *  id,
bool  is_keys 
)

Get a message by its identifier.

Parameters
ssbThe SSB instance.
idThe message identifier.
is_keysWhether to produce {"key": id, "value": message, "timestamp": ts} or just the message.
Returns
The message.

◆ tf_ssb_db_get_profile()

const char * tf_ssb_db_get_profile ( sqlite3 db,
const char *  id 
)

Get the latest profile information for the given identity.

Parameters
dbThe database.
idThe identity.
Returns
A JSON representation of the latest profile information set for the account. Free with tf_free().

◆ tf_ssb_db_get_profile_name()

const char * tf_ssb_db_get_profile_name ( sqlite3 db,
const char *  id 
)

Get the latest profile name for the given identity.

Parameters
dbThe database.
idThe identity.
Returns
The name. Free with tf_free().

◆ tf_ssb_db_get_property()

const char * tf_ssb_db_get_property ( tf_ssb_t ssb,
const char *  id,
const char *  key 
)

Get an entry from the properties table.

Parameters
ssbThe SSB instance.
idThe user.
keyThe property key.
Returns
The property value or null. Free with tf_free().

◆ tf_ssb_db_get_stored_connections()

tf_ssb_db_stored_connection_t * tf_ssb_db_get_stored_connections ( tf_ssb_t ssb,
int *  out_count 
)

Get the list of stored connections from the SSB connection tracker.

Parameters
ssbThe SSB instance.
[out]out_countPopulated with the number of returned connections.
Returns
Information about all the stored connections.

◆ tf_ssb_db_get_user_for_identity()

const char * tf_ssb_db_get_user_for_identity ( tf_ssb_t ssb,
const char *  public_key 
)

Get the user owning an identity.

Parameters
ssbThe SSB instance.
public_keythe identity.
Returns
The username of the owner of the identity or NULL.

◆ tf_ssb_db_has_invite()

bool tf_ssb_db_has_invite ( sqlite3 db,
const char *  id 
)

Check if we have an invite for the given account.

Parameters
dbThe database.
idThe invite public key to check.
Returns
true If we have a valid invite for the address.

◆ tf_ssb_db_identity_add()

bool tf_ssb_db_identity_add ( tf_ssb_t ssb,
const char *  user,
const char *  public_key,
const char *  private_key 
)

Add an identity for a user to the database.

Parameters
ssbThe SSB instance.
userThe user's username.
public_keyThe public key of the identity.
private_keyThe private key of the identity.

◆ tf_ssb_db_identity_create()

bool tf_ssb_db_identity_create ( tf_ssb_t ssb,
const char *  user,
uint8_t *  out_public_key,
uint8_t *  out_private_key 
)

Create a new identity for a user.

Parameters
ssbThe SSB instance.
userThe user's username.
[out]out_public_keyA buffer populated with the new public key.
[out]out_private_keyA buffer populated with the new private key.
Returns
True if the identity was created.

◆ tf_ssb_db_identity_delete()

bool tf_ssb_db_identity_delete ( tf_ssb_t ssb,
const char *  user,
const char *  public_key 
)

Delete an identity for a user from the database. This is an unrecoverable operation.

Parameters
ssbThe SSB instance.
userThe user's username.
public_keyThe identity to delete.
Returns
True if the identity was deleted.

◆ tf_ssb_db_identity_get_active()

bool tf_ssb_db_identity_get_active ( sqlite3 db,
const char *  user,
const char *  package_owner,
const char *  package_name,
char *  out_identity,
size_t  out_identity_size 
)

Get the active identity for a user for a given package.

Parameters
dbAn sqlite3 database.
userThe username.
package_ownerThe username of the package owner.
package_nameThe name of the package.
[out]out_identityPopulated with the identity.
out_identity_sizeThe size of the out_identity buffer.
Returns
true If the identity was retrieved.

◆ tf_ssb_db_identity_get_count_for_user()

int tf_ssb_db_identity_get_count_for_user ( tf_ssb_t ssb,
const char *  user 
)

Get the number of SSB identities a Tilde Friends user has.

Parameters
ssbThe SSB instance.
userThe user's username.
Returns
The number of identities found.

◆ tf_ssb_db_identity_get_private_key()

bool tf_ssb_db_identity_get_private_key ( tf_ssb_t ssb,
const char *  user,
const char *  public_key,
uint8_t *  out_private_key,
size_t  private_key_size 
)

Get the private key for an identity in the database.

Parameters
ssbThe SSB instance.
userThe owning user's username.
public_keyThe public key of the identity.
[out]out_private_keyA buffer to receive the private key of the identity.
private_key_sizeThe size of the out_private_key buffer.
Returns
True if the private key was found and retrieved.

◆ tf_ssb_db_identity_visit()

void tf_ssb_db_identity_visit ( tf_ssb_t ssb,
const char *  user,
void(*)(const char *identity, void *user_data)  callback,
void *  user_data 
)

Call a function for each identity owned by a user.

Parameters
ssbThe SSB instance.
userThe user's username.
callbackThe function to call for each identity.
user_dataUser data to pass to the callback.

◆ tf_ssb_db_identity_visit_all()

void tf_ssb_db_identity_visit_all ( tf_ssb_t ssb,
void(*)(const char *identity, void *user_data)  callback,
void *  user_data 
)

Call a function for all identities in the database.

Parameters
ssbThe SSB instance.
callbackThe callback to call for each identity.
user_dataUser data to pass to the callback.

◆ tf_ssb_db_init()

void tf_ssb_db_init ( tf_ssb_t ssb)

Initialize the database writer for an SSB instance.

Parameters
ssbThe SSB instance.

◆ tf_ssb_db_init_reader()

void tf_ssb_db_init_reader ( sqlite3 db)

Configure an opened SQLite database for reading.

◆ tf_ssb_db_is_account_familiar()

bool tf_ssb_db_is_account_familiar ( sqlite3 db,
const char *  id,
int  depth 
)

Determine if an account is familiar, meaning it is local or within the given follow depth of the local accounts or we have already replicated data for it.

Parameters
dbThe database.
idThe identity.
depthThe follow depth.
Returns
true if the account is familiar.

◆ tf_ssb_db_message_content_get()

bool tf_ssb_db_message_content_get ( tf_ssb_t ssb,
const char *  id,
uint8_t **  out_blob,
size_t *  out_size 
)

Get message content by ID.

Parameters
ssbThe SSB instance.
idThe message identifier.
[out]out_blobPopulated with the message content.
[out]out_sizePOpulated with the size of the message content.
Returns
true If the message content was found and retrieved.

◆ tf_ssb_db_register_account()

bool tf_ssb_db_register_account ( uv_loop_t loop,
sqlite3 db,
JSContext context,
const char *  name,
const char *  password 
)

Add a user account to the database.

Parameters
loopThe event loop.
dbA DB writer.
contextA JS context.
nameThe username to add.
passwordThe user's raw password.
Returns
true If the user was added successfully.

◆ tf_ssb_db_remove_property()

bool tf_ssb_db_remove_property ( tf_ssb_t ssb,
const char *  id,
const char *  key 
)

Remove an entry in the properties table.

Parameters
ssbThe SSB instance.
idThe user.
keyThe property key.
Returns
true if the property was removed successfully.

◆ tf_ssb_db_remove_value_from_array_property()

bool tf_ssb_db_remove_value_from_array_property ( tf_ssb_t ssb,
const char *  id,
const char *  key,
const char *  value 
)

Remove a value from an entry in the properties table that is a JSON array.

Parameters
ssbThe SSB instance.
idThe user.
keyThe property key.
valueThe value to remove from the JSON array.
Returns
true if the property was updated.

◆ tf_ssb_db_resolve_index_async()

void tf_ssb_db_resolve_index_async ( tf_ssb_t ssb,
const char *  host,
void(*)(const char *path, void *user_data)  callback,
void *  user_data 
)

Resolve a hostname to its index path by global settings.

Parameters
ssbThe SSB instance.
hostThe hostname.
callbackThe callback.
user_dataThe callback user data.

◆ tf_ssb_db_set_account_password()

bool tf_ssb_db_set_account_password ( uv_loop_t loop,
sqlite3 db,
JSContext context,
const char *  name,
const char *  password 
)

Insert or update a user's hashed password in the database.

Parameters
loopThe event loop.
dbA DB writer.
contextA JS context.
nameThe username.
passwordThe raw password.
Returns
true if the hash of the password was successfully stored.

◆ tf_ssb_db_set_global_setting_from_string()

bool tf_ssb_db_set_global_setting_from_string ( sqlite3 db,
const char *  name,
char *  value 
)

Set a global setting from a string representation of its value.

Parameters
dbThe database.
nameThe setting name.
valueThe settinv value.
Returns
true if the setting was set.

◆ tf_ssb_db_set_property()

bool tf_ssb_db_set_property ( tf_ssb_t ssb,
const char *  id,
const char *  key,
const char *  value 
)

Store an entry in the properties table.

Parameters
ssbThe SSB instance.
idThe user.
keyThe property key.
valueThe property value.
Returns
true if the property was stored successfully.

◆ tf_ssb_db_store_message()

void tf_ssb_db_store_message ( tf_ssb_t ssb,
JSContext context,
const char *  id,
JSValue  val,
const char *  signature,
int  flags,
tf_ssb_db_store_message_callback_t callback,
void *  user_data 
)

Store a message in the database.

Parameters
ssbThe SSB instance.
contextThe JS context.
idThe message identifier.
valThe message object.
signatureThe signature of the message.
flagstf_ssb_message_flags_t describing the message.
callbackA callback to call upon completion.
user_dataUser data for the callback.

◆ tf_ssb_db_use_invite()

bool tf_ssb_db_use_invite ( sqlite3 db,
const char *  id 
)

Consume and validate an invite.

Parameters
dbThe database.
idThe invite public key.
Returns
true If the invite was valid and successfully consumed.

◆ tf_ssb_db_user_has_permission()

bool tf_ssb_db_user_has_permission ( tf_ssb_t ssb,
sqlite3 db,
const char *  id,
const char *  permission 
)

Check if a user has a specific permission.

Parameters
ssbThe SSB instance.
dbOptional database instance. If NULL, one will be acquired from ssb.
idThe user ID.
permissionThe name of the permission.
Returns
true If the user has the requested permission.

◆ tf_ssb_db_verify()

bool tf_ssb_db_verify ( tf_ssb_t ssb,
const char *  id,
int32_t  debug_sequence,
bool  fix 
)

Verify an author's feed.

Parameters
ssbThe SSB instance.
idThe author'd identity.
debug_sequenceMessage sequence number to debug if non-zero.
fixFix invalid messages when possible.
Returns
true If the feed verified successfully.

◆ tf_ssb_db_visit_query()

JSValue tf_ssb_db_visit_query ( tf_ssb_t ssb,
const char *  query,
const JSValue  binds,
void(*)(JSValue row, void *user_data)  callback,
void *  user_data 
)

Call a function for each result row of an SQL query.

Parameters
ssbThe SSB instance.
queryThe SQL query.
bindsAn array of values to bind to SQL parameters.
callbackA callback to call for each result row.
user_dataUser data to pass to the callback.
Returns
A promise resolved when the query completes or rejected if it fails.

◆ tf_ssb_format_message()

JSValue tf_ssb_format_message ( JSContext context,
const char *  previous,
const char *  author,
int32_t  sequence,
double  timestamp,
const char *  hash,
const char *  content,
const char *  signature,
int  flags 
)

Format a message in the standard format for SSB signing.

Parameters
contextA JS context.
previousThe previous message identifier.
authorThe author's public key.
sequenceThe message sequence number.
timestampThe message timestamp.
hashThe hash type (probably "sha256").
contentThe message content.
signatureThe signature of the message.
flagstf_ssb_message_flags_t describing the message.

◆ tf_ssb_sqlite_authorizer()

int tf_ssb_sqlite_authorizer ( void *  user_data,
int  action_code,
const char *  arg0,
const char *  arg1,
const char *  arg2,
const char *  arg3 
)

An SQLite authorizer callback. See https://www.sqlite.org/c3ref/set_authorizer.html for use.

Parameters
user_dataUser data registered with the authorizer.
action_codeThe type of action.
arg0Depends on the action.
arg1Depends on the action.
arg2Depends on the action.
arg3Depends on the action.
Returns
A value indicating whether the operation is allowed.