
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@magmalayer/socialkit
Advanced tools
[!WARNING]
This SDK is still a work-in-progress. This is the only source of documentation as we finalize the SDK and accompanying resources.To understand the code better, look through the repository and provided types.
This SDK is available on NPM, you can install it using your preferred package manager.
npm install @magmalayer/socialkit
Socialkit TS SDK is a complete rewrite of our original JS SDK.
As Socialkit and its usage scaled, so did the demand for a better DX at scale. This SDK is made to support development at scale by providing types and a more abstract view of Socialkit internals.
[!IMPORTANT] A complete migration guide will be provided together with other resources once this SDK reaches beta.
We recognize the annoyance of breaking backward compatibility, however, in order to make the future of Socialkit development simpler and leaner we had to do it.
The majority of functions are named the same, however, their signatures have changed.
[!IMPORTANT] Socialkit TS SDK no longer provides errors as a response. You need to catch it using try{}catch{} or with a provided
catchErrorutility method.
Once the SDK is deemed finalized we will provide a complete documentation rewrite.
import { Socialkit } from "@magmalayer/socialkit";
// Use Socialkit defaults
const socialkit = new Socialkit({});
// Disable encryption, do not connect to Encryption nodes
const socialkit = new Socialkit({ encryption: false });
// Choose your own Ceramic Storage gateway
const socialkit = new Socialkit({
storage: {
gateway: "...",
},
});
When using the new SDK you have 2 main options to catch errors.
The third option is to not catch errors at all.
Standard try/catch practices apply.
let post
try{
post = await socialkit.createPost(...)
}catch(error){
console.log("Error", error)
}
console.log("Result", post)
This is a utility method provided by Socialkit, originally implemented in Radash.
We've modified the call signature to make it more convenient for our use case.
import { catchError } from "@magmalayer/socialkit"
const [post, error] = await catchError(
() => socialkit.createPost(...)
)
if(error){
console.warn("Error", error)
}
console.log("Result", post)
Our SDK now exports multiple Authentication providers. These replace the old { chain, provider } methodology.
Socialkit TS SDK allows you to define the SDK to authenticate the user with, options are storage and encryption.
import { SocialkitResources } from "@magmalayer/socialkit";
// SocialkitResources.encryption
// SocialkitResources.storage
import { Socialkit, SocialkitResources } from "@magmalayer/socialkit"
import { SocialkitEVMAuth } from "@magmalayer/socialkit/auth"
// Browser provider
const provider = window.ethereum
// Ethers provider
const provider = new Wallet(...)
// Socialkit Authenticator
const auth = new SocialkitEVMAuth(provider)
const authResult = await socialkit.connectUser({ auth })
// Wait for the user profile to be indexed
await authResult.waitIndexing()
console.log({ authResult })
// By default all available scopes will be authenticated
// In case a scope is already authenticated it will *not* be removed
// Authenticate storage only
const authResult = await socialkit.connectUser({ auth, scopes: [ SocialkitResources.storage ]})
This method always returns true/false.
// Check if any user is connected
const connected = await socialkit.isUserConnected();
// Check if a user with the specified wallet address is connected
const connected = await socialkit.isUserConnected("0x00...");
This method either returns the currently connected user (SocialkitConnectResult) or false.
// Get the currently connected user
const currentUser = await socialkit.getConnectedUser();
if (!currentUser) {
// Notify the user or reconnect
throw "There is no active user session.";
}
console.log({ currentUser });
All methods that create or modify content, expose a waitIndexing method in their result. This allows you to guarantee Socialkit' indexing nodes indexed and store the new content.
This has been done to allow quicker UI updates in case you don't care about the status of indexing or are handling multiple actions at once.
import { MethodStatuses } from "@magmalayer/socialkit"
// Create a stream
const post = await socialkit.createPost({ ... })
// Wait for the stream to get indexed
const postIndexingResult = await post.waitIndexing()
// Alternatively you can check for the error field, as such: if ("error" in postIndexingResult)
if(postIndexingResult.status !== MethodStatuses.ok){
throw `There was an error indexing post (${post.id}). Error: ${postIndexingResult.error}`
}
console.log(`Post (${post.id}) successfully indexed`, postIndexingResult.result)
// Fetch the post from Socialkit nodes
const newPost = await socialkit.getPost(post.id)
All Socialkit Ceramic schemas are auto-generated as types. They are used when creating or updating content such as posts or contexts.
Indexed content has different types due to additional metadata, formatting and social graph additions.
You can auto-generated schemas here.
The index of our schema streams is here.
Indexed content types are here.
const post = await socialkit.createPost({
body: "This is some content",
context: "kjsd...ksx",
});
console.log("Created post:", post.id);
await post.waitIndexing();
console.log("Indexed post:", post.id);
import type { DIDPkh } from "@magmalayer/socialkit";
// Create an encrypted post that only the current user can read
// User *must* be authenticated with encryption scopes
const encryptedPost = await socialkit.createPost({
body: "This is content which will be encrypted",
encryptionRules: [
{
type: "dids",
dids: [socialkit.user.did as DIDPkh],
},
],
});
console.log("Created an encrypted post:", encryptedPost.id);
await encryptedPost.waitIndexing();
console.log("Indexed an encrypted post", encryptedPost.id);
// By default, all posts will be decrypted silently (won't throw an error if unable to decrypt)
const post = await socialkit.getPost("post_id");
// Disable post decryption
const post = await socialkit.getPost("post_id", { decryptSilently: false });
console.log({ post });
// Either of these fields can be null depending on initial post's state
console.log({ decrypted: post.body.plain, encrypted: post.body.encrypted });
FAQs
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.