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 encryptionencrypted
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
Mobile apps : Minimal example
Demo projects are available for multiple platforms in different languages.
These projects are minimal demonstrations, containing no user interface. They are simply applications that import the Seald SDK and run a demo function that utilizes its core features.
You can find example applications for:
- React-Native: https://github.com/seald/seald-sdk-demo-app-react-native
- Flutter: https://github.com/seald/seald-sdk-demo-app-flutter
- Android (Kotlin): https://github.com/seald/seald-sdk-demo-app-android
- iOS (Objective-C with Cocoapods): https://github.com/seald/seald-sdk-demo-app-ios
- iOS (Swift with SPM): https://github.com/seald/seald-sdk-demo-app-ios-swift
Quick example
If you want to just take a quick look, here is a snippet of how to use the Seald SDK :
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)