0.0.39 • Published 2 years ago

instaparty v0.0.39

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Instaparty

Instant Private Party Creator

Instaparty lets you instantly create crypto wallet authorized websites.

Usage

Create a project folder and initialize:

instaparty <role> <NPM package>

This will:

  1. create a folder named <role>
  2. attach the <NPM package> auth engine to the <role>
  3. create a route named /<role>, where the site will be available

If no <NPM package> is specified, this role will allow anyone to login. Example:

instaparty user

will create a /user route and allow anyone to log in and access the route.

Tutorial

1. Access list based authorization

The following command will:

  1. create a route at /members
  2. this route will be protected by listparty module
mkdir my-app
cd my-app
instaparty members listparty

open members/members.txt and paste a line separated list of addreses. For example:

0x00192fb10df37c9fb26829eb2cc623cd1bf599e8
0x372d427b85d00538fb6512a6ef76c62b9664949b

Test by running npm run dev and going to http://localhost:3000/members

You should see the default webpage. To use your own website, just paste all your website files into the members/instaparty folder and run npm run start

2. NFT based authorization

The following command will:

  1. create a route at /holders
  2. this route will be protected by nftparty module
mkdir my-app
cd my-app
instaparty holders nftparty

open holders/config.yaml and customize. For example:

ADDRESS: "0xf7d134224a66c6a4ddeb7dee714a280b99044805"
BALANCE: 1
RPC: "https://eth-mainnet.alchemyapi.io/v2/N3VL8CEuBmuDK9bezhh2FxHIEO8aZM4z"

where:

  • ADDRESS: is the contract address for the NFT collection
  • BALANCE: is the minimum balance required to access the route
  • RPC: is the JSON RPC endpoint url for getting the blockchain state (for example Alchemy, Quicknode, etc.)

3. Multiple roles and routes

You can have multiple routes. Let's try combining the two examples above:

mkdir my-app
cd my-app
instaparty holders nftparty
instaparty members guestparty

This will:

  1. create two folders: holders and members
  2. create two routes /holders and /members
  3. The /holders route will be protected with the nftparty module
  4. The /members route will be protected with the guestparty module

Building and publishing Party modules

You can easily write Instaparty auth modules. Start by initializing an empty Instaparty template:

instaparty

This will create 2 things:

  1. an index.js file
  2. a defaults folder

Let's take a look at a PPPM module with allow list authorization:

1. customize index.js

The index.js file contains the authorization logic. The default file will look like this:

module.exports = {
  authorize: async (req, account) => {
    
  }
}

Now let's add some logic to the authorize() function:

const { members } = require('./members.json')
module.exports = {
  authorize: async (req, account) => {
    if (members.includes(account)) {
      return { member: true }
    } else {
      throw new Error("not a member")
    }
  }
}

Here's how it works:

  1. Imports the members.json file (covered in the next section)
  2. Checks if the authenticated account is part of the members.json array.
  3. The authorization succeeds if true, otherwise throws an error (no login)

2. customize defaults folder

The template files are automatically copied to the project folder when a user runs pppm install <package_name>.

Often you want to make it easy for the users by automatically initializing their project folder with some default files, which they can modify to customize their configuration (instead of writing those files from scratch).

In this case we want to provide a default members.json file. When a user runs pppm install, this will be copied to their project folder, and they can modify it to customize.

Now let's write a default members.json file:

{
  "members: []
}

3. customize README.md

This part is optional, but you may want to add a README.md file to the folder, which you can use to explain how to use the module.

The README.md file will be printed when

  • a user first installs the module with pppm install
  • a user calls pppm help

You may also want to add a README.md file that will be printed ahen

4. publish to NPM

At this point, your folder structure for the module would look like this:

.
├── README.md
├── defaults
│   └── members.json
├── index.js
└── package.json

Open package.json and update the package name to whatever you want. In this case let's say we want to publish it as accessparty. The final package.json may look like this:

{
  "name": "accessparty",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "MIT"
}

To publish, run:

npm publish

5. use

Now that we've published the module to NPM, how do we use it?

Let's say we named this package accessparty. We can now use this with:

pppm init
pppm install accessparty

This will create the following folder structure:

.
├── members.json
├── index.js
└── package.json
[
  "0xFb7b2717F7a2a30B42e21CEf03Dd0fC76Ef761E9",
  "0x00192fb10df37c9fb26829eb2cc623cd1bf599e8",
  "0x372d427b85d00538fb6512a6ef76c62b9664949b"
]
0.0.39

2 years ago

0.0.38

2 years ago

0.0.37

2 years ago

0.0.36

2 years ago

0.0.35

2 years ago

0.0.34

2 years ago

0.0.33

2 years ago

0.0.32

2 years ago

0.0.31

2 years ago

0.0.30

2 years ago

0.0.29

2 years ago

0.0.28

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago