core: Make the internal ssb.* API more explicitly not exposed to apps.
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled

This commit is contained in:
2025-09-28 17:19:58 -04:00
parent 63f7ff9f27
commit 81ade7a400
3 changed files with 13 additions and 12 deletions

View File

@@ -149,7 +149,7 @@ exports.app_socket = async function socket(request, response) {
parentApp: parentApp, parentApp: parentApp,
id: blobId, id: blobId,
}, },
await ssb.getIdentityInfo( await ssb_internal.getIdentityInfo(
credentials?.session?.name, credentials?.session?.name,
packageOwner, packageOwner,
packageName packageName

View File

@@ -312,7 +312,7 @@ async function getProcessBlob(blobId, key, options) {
{ {
action: 'identities', action: 'identities',
}, },
await ssb.getIdentityInfo( await ssb_internal.getIdentityInfo(
process?.credentials?.session?.name, process?.credentials?.session?.name,
options?.packageOwner, options?.packageOwner,
options?.packageName options?.packageName
@@ -551,9 +551,6 @@ async function getProcessBlob(blobId, key, options) {
); );
} }
}; };
imports.ssb.addEventListener = undefined;
imports.ssb.removeEventListener = undefined;
imports.ssb.getIdentityInfo = undefined;
if ( if (
process.credentials && process.credentials &&
@@ -683,19 +680,19 @@ async function getProcessBlob(blobId, key, options) {
/** /**
* SSB message added callback. * SSB message added callback.
*/ */
ssb.addEventListener('message', function () { ssb_internal.addEventListener('message', function () {
broadcastEvent('onMessage', [...arguments]); broadcastEvent('onMessage', [...arguments]);
}); });
ssb.addEventListener('blob', function () { ssb_internal.addEventListener('blob', function () {
broadcastEvent('onBlob', [...arguments]); broadcastEvent('onBlob', [...arguments]);
}); });
ssb.addEventListener('broadcasts', function () { ssb_internal.addEventListener('broadcasts', function () {
broadcastEvent('onBroadcastsChanged', []); broadcastEvent('onBroadcastsChanged', []);
}); });
ssb.addEventListener('connections', function () { ssb_internal.addEventListener('connections', function () {
broadcastEvent('onConnectionsChanged', []); broadcastEvent('onConnectionsChanged', []);
}); });

View File

@@ -2370,6 +2370,10 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
JS_SetPropertyStr(context, global, "ssb", object); JS_SetPropertyStr(context, global, "ssb", object);
JS_SetOpaque(object, ssb); JS_SetOpaque(object, ssb);
JSValue object_internal = JS_NewObjectClass(context, _tf_ssb_classId);
JS_SetPropertyStr(context, global, "ssb_internal", object_internal);
JS_SetOpaque(object_internal, ssb);
/* Requires an identity. */ /* Requires an identity. */
JS_SetPropertyStr(context, object, "createIdentity", JS_NewCFunction(context, _tf_ssb_createIdentity, "createIdentity", 1)); JS_SetPropertyStr(context, object, "createIdentity", JS_NewCFunction(context, _tf_ssb_createIdentity, "createIdentity", 1));
JS_SetPropertyStr(context, object, "addIdentity", JS_NewCFunction(context, _tf_ssb_addIdentity, "addIdentity", 2)); JS_SetPropertyStr(context, object, "addIdentity", JS_NewCFunction(context, _tf_ssb_addIdentity, "addIdentity", 2));
@@ -2387,7 +2391,6 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
JS_SetPropertyStr(context, object, "getServerIdentity", JS_NewCFunction(context, _tf_ssb_getServerIdentity, "getServerIdentity", 0)); JS_SetPropertyStr(context, object, "getServerIdentity", JS_NewCFunction(context, _tf_ssb_getServerIdentity, "getServerIdentity", 0));
JS_SetPropertyStr(context, object, "getAllIdentities", JS_NewCFunction(context, _tf_ssb_getAllIdentities, "getAllIdentities", 0)); JS_SetPropertyStr(context, object, "getAllIdentities", JS_NewCFunction(context, _tf_ssb_getAllIdentities, "getAllIdentities", 0));
JS_SetPropertyStr(context, object, "getActiveIdentity", JS_NewCFunction(context, _tf_ssb_getActiveIdentity, "getActiveIdentity", 3)); JS_SetPropertyStr(context, object, "getActiveIdentity", JS_NewCFunction(context, _tf_ssb_getActiveIdentity, "getActiveIdentity", 3));
JS_SetPropertyStr(context, object, "getIdentityInfo", JS_NewCFunction(context, _tf_ssb_getIdentityInfo, "getIdentityInfo", 3));
JS_SetPropertyStr(context, object, "blobGet", JS_NewCFunction(context, _tf_ssb_blobGet, "blobGet", 1)); JS_SetPropertyStr(context, object, "blobGet", JS_NewCFunction(context, _tf_ssb_blobGet, "blobGet", 1));
JS_SetPropertyStr(context, object, "connections", JS_NewCFunction(context, _tf_ssb_connections, "connections", 0)); JS_SetPropertyStr(context, object, "connections", JS_NewCFunction(context, _tf_ssb_connections, "connections", 0));
JS_SetPropertyStr(context, object, "storedConnections", JS_NewCFunction(context, _tf_ssb_storedConnections, "storedConnections", 0)); JS_SetPropertyStr(context, object, "storedConnections", JS_NewCFunction(context, _tf_ssb_storedConnections, "storedConnections", 0));
@@ -2406,8 +2409,9 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
JS_SetPropertyStr(context, object, "blobStore", JS_NewCFunction(context, _tf_ssb_blobStore, "blobStore", 1)); JS_SetPropertyStr(context, object, "blobStore", JS_NewCFunction(context, _tf_ssb_blobStore, "blobStore", 1));
/* Trusted only. */ /* Trusted only. */
JS_SetPropertyStr(context, object, "addEventListener", JS_NewCFunction(context, _tf_ssb_add_event_listener, "addEventListener", 2)); JS_SetPropertyStr(context, object_internal, "getIdentityInfo", JS_NewCFunction(context, _tf_ssb_getIdentityInfo, "getIdentityInfo", 3));
JS_SetPropertyStr(context, object, "removeEventListener", JS_NewCFunction(context, _tf_ssb_remove_event_listener, "removeEventListener", 2)); JS_SetPropertyStr(context, object_internal, "addEventListener", JS_NewCFunction(context, _tf_ssb_add_event_listener, "addEventListener", 2));
JS_SetPropertyStr(context, object_internal, "removeEventListener", JS_NewCFunction(context, _tf_ssb_remove_event_listener, "removeEventListener", 2));
JS_FreeValue(context, global); JS_FreeValue(context, global);
} }