1.0.0-alpha.42 • Published 10 months ago

@synonymdev/slashtags-sdk v1.0.0-alpha.42

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

slashtags-sdk

Software development kit for Slashtags

This SDK offers a high level batteries-included abstraction layer for these low level building blocks.

If you are building a webapp over Slashtags, or adding Slashtags support to your existing wallet/application, this package is for you.

Goals

  • Beginner friendly Developing for p2p systems is hard, and this SDK is designed to implement best practices and optimization while avoiding common pitfalls.
  • Cross platform This SDK tries to support all the major platforms and browsers.
  • Key management Derive and manage all keyPairs and addresses in a from the same seed.
  • WoT support As we develop and experiment with managing contacts, connections and shared data (attestation, reputation etc), this SDK will be updated to support those features out of the box.
  • Full featured As Slashtags develop and higher level solutions and optimizations (storage services, relays, etc) are developed, this SDK will be updated to support them.

Security

While deriving Slashtags from a mnemonic seed phrase is an important part of Slashtag's strategy for key management and decentralized identifier's long term success, it is important to note that this SDK does not require access to the mnemonic seed phrase or the master private key that secures other assets.

Rather your application needs to derive a primaryKey first as defined in the Key Derivation spec, then pass it in the primaryKey option at instantiation new SDK({ primaryKey }).

See how to derive primaryKey from a mnemonic seed phrase in Javascript: examples/primarykey/.

Installation

npm install @synonymdev/slashtags-sdk

Usage

import SDK from '@synonymdev/slashtags-sdk'
import c from 'compact-encoding'

const sdk = new SDK()

const alice = sdk.slashtag() // return the default slashtag
const drive = alice.drivestore.get() // returns the /public drive

await drive.put('/profile.json', c.encode(c.json, {name: 'alice'}))

await sdk.swarm.flush() // await for the public drive to be announced

const sdk2 = new SDK({ storage: './reader' })

const clone = sdk2.drive(drive.key) 

const profile = await clone.get('/profile.json').then(b => b && c.decode(c.json, b))

Browser support

Browsers don't allow for raw sockets, so you will need to run a DHT Relay somewhere and connect it to the SDK.

Easiest way to run a local relay is through the CLI module:

npm i -g @synonymdev/slasthags-cli

slash daemon start

Then in browser:

const sdk = new SDK({ relay: 'ws://localhost:45475'});

See browser example

API

const sdk = new SDK([options])

Create a new SDK instance.

options is an object that includes:

  • primaryKey optional 32 bytes used to derive all the keyPairs for Slashtags and their components, if not provided, a random on will be generated.
  • bootstrap A list of bootstrap nodes, useful for running a testnet
  • relay A websocket DHT relay, useful for running the SDK in browser, or routing connection through different IP.
  • storage A path to the storage directory, defaults to ${homedir()}/.slashtags/ in home directory, or a Random Access Storage instance in browser.

const slashtag = new sdk.slashtag([name])

Creates a slasthag instance using a name. If no name is given it returns the default Slashtag.

const drive = new sdk.drive(key)

Creates a readonly Hyperdrive session, and internally joining its discovery key as a client if not already joined.

await sdk.close()

Closes all Slahstags created by this SDK as well as any other resources managed by the SDK to enable graceful shutdown.

sdk.joinSeeders([server])

Helper function to join the seeders topic

3rd party seeders are conventionally swarming around a well-known topic, this function helps willing clients to discover seeders through that topic, which helps to find hypercores even when their authors are not online, if they upload their cores to a highly available seeeder.

  • server set it to true to annouce your server as a seeder.

constants.PRIMARY_KEY_DERIVATION_PATH

Derivation path for generating a PrimaryKey from a Bitcoion seed.

import bip39 from 'bip39'
import { BIP32Factory as bip32 } from 'bip32'
import * as ecc from 'tiny-secp256k1'
import SDK, { constants } from '@synonymdev/slashtags-sdk'

const seed = await bip39.mnemonicToSeed(mnemonic)
const root = bip32(ecc).fromSeed(seed) // Network: bitcoin mainnet
const primaryKey = root.derivePath(constants.PRIMARY_KEY_DERIVATION_PATH).privateKey

const sdk = new SDK({ primaryKey })

constants.MNEMONIC_TO_PRIMARY_KEY_TEST_VECTORS

Test vectors to make sure your wallet generates the correct primary key from menemonic phrase.

1.0.0-alpha.42

10 months ago

1.0.0-alpha.39

1 year ago

1.0.0-alpha.41

11 months ago

1.0.0-alpha.40

12 months ago

1.0.0-wip.1

1 year ago

1.0.0-wip.0

1 year ago

1.0.0-wip.2

1 year ago

1.0.0-wip.4

1 year ago

1.0.0-alpha.38

1 year ago

1.0.0-alpha.37

1 year ago

1.0.0-alpha.36

1 year ago

1.0.0-alpha.35

1 year ago

1.0.0-alpha.30

2 years ago

1.0.0-alpha.32

1 year ago

1.0.0-alpha.31

2 years ago

1.0.0-alpha.34

1 year ago

1.0.0-alpha.33

1 year ago

1.0.0-alpha.27

2 years ago

1.0.0-alpha.28

2 years ago

1.0.0-alpha.19

2 years ago

1.0.0-alpha.16

2 years ago

1.0.0-alpha.15

2 years ago

1.0.0-alpha.18

2 years ago

1.0.0-alpha.17

2 years ago

1.0.0-alpha.14

2 years ago

1.0.0-alpha.21

2 years ago

1.0.0-alpha.20

2 years ago

1.0.0-alpha.26

2 years ago

1.0.0-alpha.23

2 years ago

1.0.0-alpha.22

2 years ago

1.0.0-alpha.25

2 years ago

1.0.0-alpha.24

2 years ago

1.0.0-alpha.9

2 years ago

1.0.0-alpha.8

2 years ago

1.0.0-alpha.7

2 years ago

1.0.0-alpha.6

2 years ago

1.0.0-alpha.10

2 years ago

1.0.0-alpha.5

2 years ago

1.0.0-alpha.4

2 years ago

1.0.0-alpha.3

2 years ago

1.0.0-alpha.12

2 years ago

1.0.0-alpha.11

2 years ago

1.0.0-alpha.13

2 years ago

1.0.0-alpha.2

2 years ago

1.0.0-alpha.1

2 years ago

1.0.0-alpha.0

2 years ago

0.1.0-alpha.6

2 years ago

0.1.0-alpha.5

2 years ago

0.1.0-alpha.4

2 years ago

0.1.0-alpha.3

2 years ago

0.1.0-alpha.2

2 years ago

0.1.0-alpha.1

2 years ago