Skip to content

Examples

WARNING

These examples were written with an old version of the SDK, this page is being updated.

Web: Full example

A demo project is available at https://github.com/seald/sdk-web-chat-demo/.

The project is a simple chat, built with React and Firebase.

The repository contains 2 branches:

  • master which contains the normal chat, without encryption
  • encrypted which encrypts all messages with the Seald SDK and secures identities with the @seald-io/sdk-plugin-ssks-password plugin

You can compare the two, to see how the Seald SDK was added, at https://github.com/seald/sdk-web-chat-demo/compare/encrypted

React-native : minimal example

A demo project is available at https://github.com/seald/sdk-react-native-demo.

The project is a minimal demonstration, containing no user interface, just a button to execute a demonstration function.

This test function will :

  • Instantiate an SDK instance, sdk1, with the SSKS Password plugin, create an identity, and save it.
  • Instantiate a second SDK instance, sdk2, similar to the first, with a second identity.
  • The sdk1 instance creates an encrypted exchange session to share with the sdk2.
  • The sdk1 encrypts a message for the members of the session. sdk2 decrypts the message
  • sdk2 encrypt a response for members of the session. sdk1 decrypts the message
  • Instantiate an SDK instance, sdk3, and retrieve the identity created by sdk1.
  • sdk3 reconnects to the previously created encryption session, and check that it can decrypt the messages.

Quick example

If you want to just take a quick look, here is a snippet of how to use the Seald SDK :

js
import SealdSDK from '@seald-io/sdk'
import SealdSDKPluginSSKSPassword from '@seald-io/sdk-plugin-ssks-password'

const appId = '00000000-0000-1000-a000-7ea300000000' // The Seald appID of my app
const apiURL = 'https://api.staging-0.seald.io/' // URL of the API server to use
const keyStorageURL = 'https://ssks.staging-0.seald.io/' // URL of the identity storage server to use
const myUserId = 'My-User-ID-in-my-app' // The ID of the current user inside my app

const seald = SealdSDK({ appId, apiURL, plugins: [SealdSDKPluginSSKSPassword(keyStorageURL)] })
await seald.initialize()

// If you are creating the account for the first time
const password = 'SuperSecretPassword' // The password of the user. Will be used to encrypt their identity keys
const signupJWT = 'json-web-token-for-signup' // Computed by your server
const { sealdId: mySealdId } = await seald.initiateIdentity({ signupJWT }) // Create the Seald identity
await seald.ssksPassword.saveIdentity({ userId: myUserId, password }) // Save the Seald identity, encrypted by the password, on the SSKS server

// If you are retrieving an already created account
const password_ = 'SuperSecretPassword' // The password of the user. Will be used to decrypt their identity keys
const { sealdId: retrievedSealdId } = await seald.ssksPassword.retrieveIdentity({ userId: myUserId, password: password_ })

// Encrypt / decrypt files
const encryptedFile = await seald.encryptFile('Secret file content', 'SecretFile.txt', { sealdIds: [otherUserSealdId] })
const decryptedFile = await seald.decryptFile(encryptedFile)

// Using sessions
const session = await seald.createEncryptionSession({ sealdIds: [otherUserSealdId] })
const encryptedMessage = await session.encryptMessage('SecretMessage')
const decryptedMessage = await session.decryptMessage(encryptedMessage)
await session.addRecipients({ sealdIds: [anotherUserSealdId] })
await session.revokeRecipients({ sealdIds: [otherUserSealdId] })

const sessionBis = await seald.retrieveEncryptionSession({ encryptedMessage })
const decryptedMessageBis = await sessionBis.decryptMessage(encryptedMessage)
import SealdSDK from '@seald-io/sdk'
import SealdSDKPluginSSKSPassword from '@seald-io/sdk-plugin-ssks-password'

const appId = '00000000-0000-1000-a000-7ea300000000' // The Seald appID of my app
const apiURL = 'https://api.staging-0.seald.io/' // URL of the API server to use
const keyStorageURL = 'https://ssks.staging-0.seald.io/' // URL of the identity storage server to use
const myUserId = 'My-User-ID-in-my-app' // The ID of the current user inside my app

const seald = SealdSDK({ appId, apiURL, plugins: [SealdSDKPluginSSKSPassword(keyStorageURL)] })
await seald.initialize()

// If you are creating the account for the first time
const password = 'SuperSecretPassword' // The password of the user. Will be used to encrypt their identity keys
const signupJWT = 'json-web-token-for-signup' // Computed by your server
const { sealdId: mySealdId } = await seald.initiateIdentity({ signupJWT }) // Create the Seald identity
await seald.ssksPassword.saveIdentity({ userId: myUserId, password }) // Save the Seald identity, encrypted by the password, on the SSKS server

// If you are retrieving an already created account
const password_ = 'SuperSecretPassword' // The password of the user. Will be used to decrypt their identity keys
const { sealdId: retrievedSealdId } = await seald.ssksPassword.retrieveIdentity({ userId: myUserId, password: password_ })

// Encrypt / decrypt files
const encryptedFile = await seald.encryptFile('Secret file content', 'SecretFile.txt', { sealdIds: [otherUserSealdId] })
const decryptedFile = await seald.decryptFile(encryptedFile)

// Using sessions
const session = await seald.createEncryptionSession({ sealdIds: [otherUserSealdId] })
const encryptedMessage = await session.encryptMessage('SecretMessage')
const decryptedMessage = await session.decryptMessage(encryptedMessage)
await session.addRecipients({ sealdIds: [anotherUserSealdId] })
await session.revokeRecipients({ sealdIds: [otherUserSealdId] })

const sessionBis = await seald.retrieveEncryptionSession({ encryptedMessage })
const decryptedMessageBis = await sessionBis.decryptMessage(encryptedMessage)