npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@synonymdev/slashtags-sdk

v1.0.0-alpha.42

Published

slashtags development kit

Downloads

1,715

Readme

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.