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

pletyvo

v0.0.1-17

Published

**Unstable version. Things may change.**

Downloads

63

Readme

Unstable version. Things may change.

js-pletyvo

Universal, typed and tree-shakable JavaScript client for the Pletyvo decentralized platform.

Install

pnpm add pletyvo

Usage

Firstly, you will need a client. A client is an object containing all necessary logic to interact with a Pletyvo gateway. Create one with PletyvoClient:

const client = new PletyvoClient( {
	gateway: 'http://testnet.pletyvo.osyah.com/api',
	network: '0191e5b0-b730-7167-965a-083f5b759c32',
} )

Valid configuration options are:

  • gateway?: string
  • network?: stringidentifier of network to use
  • fetch?: (url: string, init: RequestInit) => Promise<Response> – override HTTP client

Protocols are the fundamental concept in Pletyvo. This module represents them as classes with functionality implemented as methods. To use a protocol, you must instantiate it and register it in the client through client's with method. The first protocol you'll most likely need is dApp, implemented by PletyvoDapp class:

const pletyvo = client.with( [
	new Dapp(),
] )

The value returned by PletyvoClient..with is a handy object with all registered protocols as fields:

await pletyvo.dapp.events() // Array<DappEvent>

Some protocols may depend on other protocols. In particular, practically all protocols depend on dApp. To use a dependant protocol or some of its features, you should manually configure and register its dependencies, which are typically listed in protocol's documentation.

Built-in protocols

dApp

Platform docs: dApp

  • creating events with dapp.eventCreate requires configuring authentication
  • dapp.event/dapp.events wrap fetched events in DappEvent objects containing methods for accessing event type bytes and parsing their data (not cached!)
const createdEventId = await pletyvo.dapp.eventCreate( 0, 2, 0, 2, {
	content: 'Hello, dApp!',
	channel: '0191e5b1-6f26-7c0f-b87c-72712e48f42b'
} ) // string

const detailedEventInfo = await pletyvo.dapp.event(createdEventId) // DappEvent
detailedEventInfo.data() // "Hello, dApp!"
detailedEventInfo.event() // 1
detailedEventInfo.aggregate() // 2
detailedEventInfo.version() // 3
detailedEventInfo.protocol() // 4

const twentyPreviousEvents = await pletyvo.dapp.events( {limit: 20, before: detailedEventInfo.id} ) // Array<DappEvent>
twentyPreviousEvents.length // 20

dApp: cryptography

Creating events requires from you to pass signer option to Dapp, whose value must be an object implementing DappSigner interface.

This package includes a signer for the only cryptographic algorithm supported by Pletvyo at the moment, ED25519, implementing it as a thin wrapper around @noble/ed25519.

To use the signer, firstly generate a private key through DappSignerEd25519.randomPrivateKey (an alias to @noble/ed25519-s utils.randomPrivateKey) or use the one you already have, then pass it to a new signer instance.

const privateKey = DappSignerEd25519.randomPrivateKey()
const signer = new DappSignerEd25519(privateKey)

const pletyvo = client.with( [
	new Dapp( {signer} ),
] )

await pletyvo.dapp.eventCreate( 0, 2, 0, 2, {
	content: 'Hello, dApp!',
	channel: '0191e5b1-6f26-7c0f-b87c-72712e48f42b'
} )

Delivery

Platform docs: Delivery

Registry

Platform docs: Registry

Advanced: custom protocols

A protocol is a class that implements a simple interface:

interface PletyvoProtocol {
	get name(): string
	set client(next: PletyvoClient)
}

Start by adding the name field and making it readonly or adding as const to the literal for client's type magic to work, then define client field without initializing it (non-null assertion is okay there):

class Custom implements Protocol {
	name = 'custom' as const
	client!: Client
}

There you go. Now the protocol is registerable through Client..with, so you can start implementing its functionality.

As already stated, every Pletyvo protocol in fact depends on dApp. Besides, depending on other protocols may be helpful to you. To access them, use Client..protocol method which acts as a service locator:

class Custom implements Protocol {
	name = 'custom' as const
	client!: Client

	async doSomething() {
		const dapp = this.client.protocol(Dapp)
		return await dapp.eventCreate( 7, 7, 7, 7, {do: 'something'} )
	}
}