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

rjsvm

v0.2.5

Published

[![Current Version](https://img.shields.io/npm/v/rjsvm.svg)](https://www.npmjs.com/package/rjsvm) [![Weekly Downloads](https://img.shields.io/npm/dw/rjsvm?color=important)](https://www.npmjs.com/package/rjsvm) [![License Type](https://img.shields.io/npm/l

Downloads

14

Readme

Overview

Current Version Weekly Downloads License Type

The Ripple JavaScript Virtual Machine, or RJSVM, aims to standardize and simplify the development of applications that employ the Ripple blockchain as state storage. Internally it employs xrpIO to read and write all necessary data.

How to install

npm i rjsvm

How it works

The JSVM package comes with two major parts: The RJSVM itself and the Datawriter. The former is used to define initial program state, callable endpoints, and the associated their associated logic. The Datawriter serves as the glue between users and a RJSVM.

Due to the blockchain's properties of providing persistent and absolutely ordered transactions every copy of a RJSVM will behave exactly identically.

rjsvm schema

In order to provide a more robust environment and quasi-typesafe execution this package also requires zod.

A basic example

RJSVM

import { RJSVM_Builder, RJSVM_Implementations, RJSVM_Interface, RJSVM, RJSVM_Config } from "rjsvm";
import { z } from "zod";

// Begin by defining the parameter type using Zod
const blogpostSchema = z.object({
    title: z.string(),
    body: z.string(),
    from: z.string(),
})
type Blogpost = z.infer<typeof blogpostSchema>

// Define the shape of the state the RJSVM will manipulate
type State = {
    data: Blogpost[]
}

// Define the RJSVM endpoints
type RJSVMEndpoints = {
    submit: (data: Blogpost) => void
    ownerSubmit: (data: Blogpost) => void
    remove: (data: Blogpost) => void
}

// Define initial RJSVM state. The 'owner' and 'state' fields are both required.
abstract class RJSVM_Base
extends RJSVM<State, RJSVMEndpoints>
implements RJSVM_Interface<RJSVM_Base> {
    owner = ownerWallet.address

    state: State = {
        blogposts: []
    }
}

// Implement the program logic
const RJSVM_Contract: RJSVM_Implementations<RJSVM_Base> = {
    // Endpoints may declare a minimum fee in order to be applied
    submit: {
        implementation: function (env, data) {
            this.state.blogposts.unshift(data)
        },
        visibility: 'public',
        fee: 10,
        parameterSchema: blogpostSchema
    },

    // Endpoints can be owner-exclusive in order to grant free access
    ownerSubmit: {
        implementation: function (env, shout) {
            this.state.blogposts.unshift(shout)
        },
        visibility: 'owner',
        parameterSchema: blogpostSchema
    },

    // Owner-exclusive endpoints can also be used to implement protected functionality
    remove: {
        implementation: function (env, data) {
            this.state.blogposts = this.state.blogposts.filter(post => post.title != post.title)
        },
        visibility: 'owner',
        parameterSchema: blogpostSchema,
    }
}

// Finally build and connect the RJSVM
const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract);

const conf: RJSVM_Config = {
    listeningAddress: listeningWallet.address,          // The XRP address to check for endpoint calls
    rippleNode: "wss://s.altnet.rippletest.net:51233"   // Any online XRP node connected to the right chain
}

const rjsvm = new Rjsvm(conf)
rjsvm.connect()

Datawriter

import { Datawriter } from "rjsvm";

const datawriter = new Datawriter({
    sendWallet: userWallet,                     // A wallet controlled by the user
    receiveAddress: drainWallet.address,        // A secondary address controlled by the user
    xrpNode: xrpNode,                           // Any online XRP node connected to the right chain
    contractAddress: listeningWallet.address    // The XRP associated with the RJSVM
})

datawriter.callEndpoint('submit', { 
    title: "My first blogpost", 
    body: "Hello hello this is a blogpost!", 
    from: "#1 RJSVM User in the world" 
}, 10)
// once the ripple blockchain persists the transaction, all copies of the RJSVM defined above will contain this blogpost

datawriter.callEndpoint('submit', { 
    title: "A underfunded blogpost", 
    body: "Oh no this will never show up!", 
    from: "#1 RJSVM User in the world" 
})
// Insufficient fee, the RJSVMs will not contain this blogpost. No refunds.

datawriter.ownerSubmit('ownerSubmit', { 
    title: "A underprivileged blogpost", 
    body: "Oh no this will never show up!", 
    from: "#1 RJSVM User in the world" 
})
// userWallet.address != ownerWallet.address, the RJSVMs will not contain this blogpost.

For a full list of examples please refer to the unit tests