All Projects → FleekHQ → Space Sdk

FleekHQ / Space Sdk

Licence: mit
The Space SDK is a JavaScript/Typescript library for building web and mobile applications leveraging Open Web and distributed protocols like IPFS, Textile, GunDB, and Ethereum.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Space Sdk

Peergos
A p2p, secure file storage, social network and application protocol
Stars: ✭ 895 (+862.37%)
Mutual labels:  storage, ipfs
Space Daemon
The Space Daemon packages together IPFS, Textile Threads/Buckets, and Textile Powergate (Filecoin*) into one easy to install Daemon to make it easy to build peer to peer and privacy focused apps.
Stars: ✭ 151 (+62.37%)
Mutual labels:  storage, ipfs
Orion
[Moved to Gitlab] Easy to Use, Inter Planetary File System (IPFS) desktop client
Stars: ✭ 115 (+23.66%)
Mutual labels:  storage, ipfs
estuary
A custom IPFS/Filecoin node that makes it easy to pin IPFS content and make Filecoin deals.
Stars: ✭ 195 (+109.68%)
Mutual labels:  storage, ipfs
nft.storage
😋 Free decentralized storage and bandwidth for NFTs on IPFS and Filecoin.
Stars: ✭ 309 (+232.26%)
Mutual labels:  storage, ipfs
S4
S4 is 100% S3 compatible storage, accessed through Tor and distributed using IPFS.
Stars: ✭ 67 (-27.96%)
Mutual labels:  storage, ipfs
Temporal
☄️ Temporal is an easy-to-use, enterprise-grade interface into distributed and decentralized storage
Stars: ✭ 202 (+117.2%)
Mutual labels:  storage, ipfs
Ipfs Deploy
Zero-Config CLI to Deploy Static Websites to IPFS
Stars: ✭ 740 (+695.7%)
Mutual labels:  storage, ipfs
Vault
Easy persistence of Contentful data for Android over SQLite.
Stars: ✭ 80 (-13.98%)
Mutual labels:  storage, sdk
Linkedin Api Php Client
LinkedIn API PHP SDK with OAuth 2 support. Can be used for social sign in or sharing on LinkedIn. Has a good usage examples
Stars: ✭ 88 (-5.38%)
Mutual labels:  sdk
Cpm8266
Z80-CP/M2.2 emulation on ESP8266 NONOS SDK + the NoSDK from cnlohr
Stars: ✭ 91 (-2.15%)
Mutual labels:  sdk
Auth0
Go SDK for the Auth0 platform
Stars: ✭ 87 (-6.45%)
Mutual labels:  sdk
Go Cos
腾讯云对象存储服务 COS(Cloud Object Storage) Go SDK(XML API)
Stars: ✭ 88 (-5.38%)
Mutual labels:  sdk
Hoarder
A simple, api-driven storage system for storing code builds and cached libraries for cloud-based deployment services.
Stars: ✭ 91 (-2.15%)
Mutual labels:  storage
Storj
Ongoing Storj v3 development. Decentralized cloud object storage that is affordable, easy to use, private, and secure.
Stars: ✭ 1,278 (+1274.19%)
Mutual labels:  storage
Stellar Ios Mac Sdk
Stellar SDK for iOS & macOS - Swift, Stellar, Horizon, Soneso
Stars: ✭ 92 (-1.08%)
Mutual labels:  sdk
Hedera Sdk Js
Hedera™ Hashgraph SDK for JavaScript/TypeScript
Stars: ✭ 87 (-6.45%)
Mutual labels:  sdk
Go Storage
An application-oriented unified storage layer for Golang.
Stars: ✭ 87 (-6.45%)
Mutual labels:  storage
Algoliasearch Client Android
Algolia Search API Client for Android
Stars: ✭ 92 (-1.08%)
Mutual labels:  sdk
Package Managers
[ARCHIVED] 📦 IPFS Package Managers Task Force
Stars: ✭ 91 (-2.15%)
Mutual labels:  ipfs

Space SDK

Fleek Dev Slack License

Javascript/Typescript library for interacting with Space in web/browser applications via an implementation of the Space API. Build websites or applications that can easily leverage Open Web protocols (IPFS, Textile, GunDB, Ethereum) to enable Web3-ready features like:

  • File and directory storage / retrieval in user-controlled, encrypted, and distributed storage.
  • Key-pair based identity management and challenge-based authentication.
  • Decentralized and secure key and bucket metadata storage.
  • Private and end-to-end encrypted, or public file sharing.

The Space SDK is a close friend of the Space Daemon, its desktop-focused counterpart.

You can find the SDK's documentation here:

Default Implementations

The Space SDK is modular and protocol agnostic. You can use the APIs and interfaces as is, with Space's default implementations, or replace them with your own custom ones. |Feature |Description | Service/Protocol |-: |- |- | | Users | Key-pair based identity creation, and challenge authentication. | Textile Users API | Storage | File, directory, and bucket creation/listing. | IPFS / Textile | Metadata | Secure Bucket/directory schema storage | GunDB | Sharing | Private and public file sharing | Textile |


Introduction

@spacehq/sdk provides a suit of functionality to perform different action on Space.

Installation

Install the sdk using this npm command:

npm install @spacehq/sdk

Usage

Space SDK provides an interface perform the following actions:

  • Creating identities

  • Create files and directories

  • List files and directories

  • Creating buckets

  • Sharing buckets

Full SDK Documentation with examples can be found here

1. Identities

This involves managing users and their identities.

import { Users } from '@spacehq/sdk';

const users = new Users({ endpoint: 'wss://dev.space.storage' });

// createIdentity generate a random keypair identity
const identity = await users.createIdentity();

// the new keypair can be used to authenticate a new user
// `users.authenticate()` generates hub API session tokens for the keypair identity.
const user = await users.authenticate(identity);
// `user` can be used with the storage class to provide identity.

// user's identity can also be backed up with a special recovery phrase
const uuid = 'specify-uuid-representing-user-in-your-system';
const passphrase = 'specify-unique-pass-phrase-related-to-backup-type';
const backupType = VaultBackupType.Google;
await users.backupKeysByPassphrase(uuid, passphrase, backupType, user.identity);

// backed up users identity can also be recovered later
const recoveredUser = await users.recoverKeysByPassphrase(uuid, passphrase, backupType);
// `recoveredUser` has same authentication as `user` above.

Check the User's class for more examples of how to manage users with the sdk.

2. Storage

This involves operations to create and list files and directories in space storage.

import { UserStorage, AddItemsResultSummary } from '@spacehq/sdk';

const storage = new UserStorage(user);
await storage.createFolder({ bucket: 'personal', path: 'topFolder' });
const result = await storage.listDirectory({ bucket: 'personal', path: '' });
// result contains `topFolder` items

// upload a file
const uploadResponse = await spaceStorage.addItems({
   bucket: 'personal',
   files: [
     {
       path: 'file.txt',
       content: '',
     },
     {
       path: 'space.png',
       content: '',
     }
   ],
});
// uploadresponse is an event listener
uploadResponse.once('done', (data: AddItemsEventData) => {
  const summary = data as AddItemsResultSummary;
  // returns a summary of all files and their upload status
});

3. Sharing

This includes operations to share your storage items with existing user (identites)

// WIP - Coming soon!

Migrating from Space Daemon

If you are already familiar with the space daemon and its gRPC methods and would like to start using the space-sdk here are some pointers on how those gRPC methods correspond to functionalities exposed by the space-sdk.

Key Pairs (GenerateKeyPair)

In the sdk the concept of Key Pairs is represented as an Identity. To create a new Identity similar to the GenerateKeyPair method, you would do:

import { Users, BrowserStorage } from '@spacehq/sdk';

const users = new Users({ endpoint: 'wss://auth-dev.space.storage' });

// createIdentity generate a random keypair identity
const identity = await users.createIdentity();

identity represents a keypair and its primary key is accessible via identity.public.toString().

Managing authenticated users

In space-daemon the generated keypair is stored in the operating systems keychain but in space-sdk you would need to provide an IdentityStorage to the Users class when initializing it. For the browser environment there exists a BrowserStorage implementation you can use.

import { Users, BrowserStorage } from '@spacehq/sdk';

const users = await Users.withStorage(
    new BrowserStorage(), 
    { endpoint: 'wss://auth-dev.space.storage' }
);

Users.withStorage will load and authenticate all identities that exist inside the provided IdentityStorage. You can access all authenticated users through the Users.list method.

const spaceUsers = await users.list();

To authenticate a new user identity and get a SpaceUser, you can call the Users.authenticate method:

const spaceUser = await users.authenticate(identity);

Users.authentication would do two things:

  • Generate a SpaceUser.
  • Stores the new users information in the IdentityStorage, so subsequent initialization of Users.withStorage() would have the users loaded.

NOTE: An existing space user can also be gotten from Users.recoverKeysByPassphrase.

To delete a user from users lists, you can delete the user by pass the publicKey of that user to Users.remove.

await users.remove(spaceUser.identity.public.toString());

Managing current active user

If you have the concept of a current active user in your application that uses space-sdk. We recommend that you keep track of that users public key in your application and use it to filter the list method's result to get the authenticated SpaceUser for that public key.

On logout, you can call the remove method to stop tracking the user.

GetAPISessionToken

In space daemon GetAPISessionToken returns the message:

message GetAPISessionTokensResponse {
  string hubToken = 1;
  string servicesToken = 2;
}

In order to get the servicesToken and hubToken for a particular user, you would need to authenticate that user identity:

const spaceUser = await users.authenticate(identity);

The spaceUser.token value is the servicesToken, while the spaceUser.storageAuth.token is the hubToken.

Also, note that when an existing user is recovered via the Users.recoverKeysByPassphrase method, the SpaceUser returns is also authenticated and has the session tokens.

GetPublicKey

In space daemon GetPublicKey returned the id of the current keypair in keychain, but since space-sdk returns the identity object. You can get the public key bytes for a particular identity through identity.public.pubKey.

Also, an authenticated SpaceUser identity can be found in the identity field.

Storage Methods (createFolder, listDirectory, openFile, addItems)

The storage gRPC methods on space daemon can now be performed using the UserStorage class of the space-sdk.

import { UserStorage, AddItemsResultSummary } from '@spacehq/sdk';

const storage = new UserStorage(user);
await storage.createFolder({ bucket: 'personal', path: 'topFolder' });
const result = await storage.listDirectory({ path: '' });
// result contains `topFolder` items

// upload a file
const uploadResponse = await spaceStorage.addItems({
   bucket: 'personal',
   files: [
     {
       path: 'file.txt',
       content: 'plain-text-value',
     },
     {
       path: 'space.png',
       content: '', // could also be a ReadableStream<Uint8Array> or ArrayBuffer
     }
   ],
});
// uploadresponse is an event listener
uploadResponse.once('done', (data: AddItemsEventData) => {
  const summary = data as AddItemsResultSummary;
  // returns a summary of all files and their upload status
});

// read content of an uploaded file
const fileResponse = await storage.openFile({ bucket: 'personal', path: '/file.txt'});
const fileContent = await fileResponse.consumeStream();
// new TextDecoder('utf8').decode(actualTxtContent) == 'plain-text-value'

Contributing

All contributions are welcome. Before getting started, kindly take some time to review our contributing guidelines and code of conduct.

LICENSE

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].