instaparty v0.0.39
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:
- create a folder named
<role> - attach the
<NPM package>auth engine to the<role> - 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 userwill create a /user route and allow anyone to log in and access the route.
Tutorial
1. Access list based authorization
The following command will:
- create a route at
/members - this route will be protected by
listpartymodule
mkdir my-app
cd my-app
instaparty members listpartyopen members/members.txt and paste a line separated list of addreses. For example:
0x00192fb10df37c9fb26829eb2cc623cd1bf599e8
0x372d427b85d00538fb6512a6ef76c62b9664949bTest 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:
- create a route at
/holders - this route will be protected by
nftpartymodule
mkdir my-app
cd my-app
instaparty holders nftpartyopen 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 collectionBALANCE: is the minimum balance required to access the routeRPC: 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 guestpartyThis will:
- create two folders:
holdersandmembers - create two routes
/holdersand/members - The
/holdersroute will be protected with thenftpartymodule - The
/membersroute will be protected with theguestpartymodule
Building and publishing Party modules
You can easily write Instaparty auth modules. Start by initializing an empty Instaparty template:
instapartyThis will create 2 things:
- an
index.jsfile - a
defaultsfolder
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:
- Imports the
members.jsonfile (covered in the next section) - Checks if the authenticated account is part of the
members.jsonarray. - 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.jsonOpen 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 publish5. 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 accesspartyThis will create the following folder structure:
.
├── members.json
├── index.js
└── package.json[
"0xFb7b2717F7a2a30B42e21CEf03Dd0fC76Ef761E9",
"0x00192fb10df37c9fb26829eb2cc623cd1bf599e8",
"0x372d427b85d00538fb6512a6ef76c62b9664949b"
]3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago