@zeroad.network/token 0.13.5 → 0.13.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -53
- package/dist/browser.d.cts +10 -7
- package/dist/browser.d.mts +10 -7
- package/package.json +28 -4
package/README.md
CHANGED
|
@@ -1,41 +1,45 @@
|
|
|
1
1
|
# Introduction
|
|
2
2
|
|
|
3
|
-
This NPM module is
|
|
3
|
+
This NPM module is designed for sites running Node.js, Bun, or Deno that participate in the [Zero Ad Network](https://zeroad.network) program.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The `@zeroad.network/token` module is a lightweight, TypeScript-ready, open-source, and fully tested HTTP-header-based "access/entitlement token" library with no production dependencies.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
For detailed guides and implementation instructions, see the [official Zero Ad Network documentation](https://docs.zeroad.network).
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
9
|
+
## Runtime Compatibility
|
|
10
|
+
|
|
11
|
+
| Runtime | Version | ESM | CJS |
|
|
12
|
+
| :------ | :------ | :-: | :-: |
|
|
13
|
+
| Node.js | 16+ | ✅ | ✅ |
|
|
14
|
+
| Bun | 1.1.0+ | ✅ | ✅ |
|
|
15
|
+
| Deno | 2.0.0+ | ✅ | ✅ |
|
|
14
16
|
|
|
15
17
|
## Purpose
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
The module helps developers to:
|
|
20
|
+
|
|
21
|
+
- Inject a valid site's HTTP Response Header (**Welcome Header**) into every endpoint. Example:
|
|
18
22
|
|
|
19
|
-
- Inject a valid site's HTTP Response Header known as "Welcome Header" to every endpoint. An example:
|
|
20
23
|
```http
|
|
21
24
|
X-Better-Web-Welcome: "AZqnKU56eIC7vCD1PPlwHg^1^3"
|
|
22
25
|
```
|
|
23
|
-
|
|
26
|
+
|
|
27
|
+
- Detect and parse Zero Ad Network user tokens sent via HTTP Request Header. Example:
|
|
28
|
+
|
|
24
29
|
```http
|
|
25
30
|
X-Better-Web-Hello: "Aav2IXRoh0oKBw==.2yZfC2/pM9DWfgX+von4IgWLmN9t67HJHLiee/gx4+pFIHHurwkC3PCHT1Kaz0yUhx3crUaxST+XLlRtJYacAQ=="
|
|
26
31
|
```
|
|
27
|
-
- If found, parse the token from the HTTP Request Header value and verify its integrity.
|
|
28
|
-
- (Optionally) Generate a valid "Welcome Header" value when `siteId` UUID and site `features` array are provided.
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
- Verify token integrity locally.
|
|
34
|
+
- Optionally generate a valid "Welcome Header" when `siteId` and `features` are provided.
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
## Implementation Details
|
|
33
37
|
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
38
|
+
- Uses `node:crypto` to verify token signatures with Zero Ad Network's public ED25519 key.
|
|
39
|
+
- Decodes token payload to extract protocol version, expiration timestamp, and site features.
|
|
40
|
+
- Generates a feature map; expired tokens produce all flags as `false`.
|
|
37
41
|
|
|
38
|
-
Parsed token
|
|
42
|
+
Parsed token example:
|
|
39
43
|
|
|
40
44
|
```js
|
|
41
45
|
{
|
|
@@ -47,27 +51,29 @@ Parsed token result example:
|
|
|
47
51
|
};
|
|
48
52
|
```
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
As per our exploratory test results in attempts to cache the token and its parsed results in Redis - it takes longer to retrieve the cached result than to verify token payload integrity.
|
|
54
|
+
- Verification occurs locally; no data leaves your server.
|
|
55
|
+
- Parsing and verification adds roughly 0.06ms–0.6ms to endpoint execution time (tested on M1 MacBook Pro). Performance may vary.
|
|
56
|
+
- Redis caching tests show local verification is faster than retrieving cached results.
|
|
55
57
|
|
|
56
|
-
##
|
|
58
|
+
## Benefits of Joining
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
Partnering with Zero Ad Network allows your site to:
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
- Generate a new revenue stream
|
|
63
|
+
- Provide a clean, unobstructed user experience
|
|
64
|
+
- Contribute to a more joyful, user-friendly internet
|
|
61
65
|
|
|
62
|
-
##
|
|
66
|
+
## Onboarding Your Site
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
1. [Sign up](https://zeroad.network/login) with Zero Ad Network.
|
|
69
|
+
2. [Register your site](https://zeroad.network/publisher/sites/add) to receive your unique `X-Better-Web-Welcome` header.
|
|
65
70
|
|
|
66
|
-
|
|
71
|
+
Your site must include this header on all publicly accessible HTML or RESTful endpoints so that Zero Ad Network users’ browser extensions can recognize participation.
|
|
67
72
|
|
|
68
|
-
## Module
|
|
73
|
+
## Module Installation
|
|
69
74
|
|
|
70
|
-
|
|
75
|
+
- Written entirely in TypeScript with full types and interfaces.
|
|
76
|
+
- Supports both ESM (`import`) and CommonJS (`require`). ESM is recommended when possible.
|
|
71
77
|
|
|
72
78
|
To install the module use your favourite package manager:
|
|
73
79
|
|
|
@@ -90,15 +96,15 @@ deno add npm:@zeroad.network/token
|
|
|
90
96
|
|
|
91
97
|
## Examples
|
|
92
98
|
|
|
93
|
-
|
|
99
|
+
For more example implementations using `Express.js` (JavaScript), `Hono`, and `Fastify` (TypeScript), visit the [examples section on our GitHub repository](https://github.com/laurynas-karvelis/zeroad-token-typescript/tree/main/examples/).
|
|
94
100
|
|
|
95
|
-
|
|
101
|
+
The following JavaScript example provides a quick reference, demonstrating how to:
|
|
96
102
|
|
|
97
|
-
- Inject the "Welcome Header" into
|
|
98
|
-
- Parse user's token from
|
|
99
|
-
- Use the `tokenContext`
|
|
103
|
+
- Inject the "Welcome Header" into responses
|
|
104
|
+
- Parse the user's token from the request header
|
|
105
|
+
- Use the `tokenContext` in controllers and templates
|
|
100
106
|
|
|
101
|
-
|
|
107
|
+
Minimal Express.js v5 app example:
|
|
102
108
|
|
|
103
109
|
```js
|
|
104
110
|
import express from "express";
|
|
@@ -106,42 +112,42 @@ import { Site } from "@zeroad.network/token";
|
|
|
106
112
|
|
|
107
113
|
const app = express();
|
|
108
114
|
|
|
109
|
-
// Initialize
|
|
110
|
-
// "Welcome Header" value is
|
|
115
|
+
// Initialize the Zero Ad Network module at app startup.
|
|
116
|
+
// The "Welcome Header" value is obtained during site registration on the Zero Ad Network platform (https://zeroad.network).
|
|
111
117
|
const ZERO_AD_NETWORK_WELCOME_HEADER_VALUE = "AZqnKU56eIC7vCD1PPlwHg^1^3";
|
|
112
118
|
const site = Site(ZERO_AD_NETWORK_WELCOME_HEADER_VALUE);
|
|
113
119
|
|
|
114
120
|
app
|
|
115
|
-
//
|
|
121
|
+
// Apply middleware for all routes
|
|
116
122
|
.use((req, res, next) => {
|
|
117
|
-
// Inject "X-Better-Web-Welcome" header
|
|
123
|
+
// Inject the "X-Better-Web-Welcome" header into the response
|
|
118
124
|
res.set(site.SERVER_HEADER_NAME, site.SERVER_HEADER_VALUE);
|
|
119
125
|
|
|
120
|
-
// Parse the
|
|
121
|
-
//
|
|
122
|
-
req.tokenContext = site.parseToken(req.get
|
|
126
|
+
// Parse the incoming user token from the request header
|
|
127
|
+
// Attach the parsed token data to the request object for downstream use
|
|
128
|
+
req.tokenContext = site.parseToken(req.get(site.CLIENT_HEADER_NAME));
|
|
123
129
|
|
|
124
130
|
next();
|
|
125
131
|
})
|
|
126
132
|
.get("/", (req, res) => {
|
|
127
|
-
//
|
|
133
|
+
// Access parsed token data for this request
|
|
128
134
|
console.log(req.tokenContext);
|
|
129
135
|
|
|
130
|
-
//
|
|
136
|
+
// Example structure of tokenContext:
|
|
131
137
|
req.tokenContext = {
|
|
132
|
-
// If
|
|
138
|
+
// If true: Hide advertisements on the page
|
|
133
139
|
ADS_OFF: boolean,
|
|
134
|
-
// If
|
|
140
|
+
// If true: Hide Cookie Consent screens and opt out non-functional trackers
|
|
135
141
|
COOKIE_CONSENT_OFF: boolean,
|
|
136
|
-
// If
|
|
142
|
+
// If true: Hide marketing dialogs or popups (e.g., newsletter, promotions)
|
|
137
143
|
MARKETING_DIALOG_OFF: boolean,
|
|
138
|
-
// If
|
|
144
|
+
// If true: Provide automatic access to paywalled content
|
|
139
145
|
CONTENT_PAYWALL_OFF: boolean,
|
|
140
|
-
// If
|
|
146
|
+
// If true: Provide access to site features behind SaaS subscription (at least basic plan)
|
|
141
147
|
SUBSCRIPTION_ACCESS_ON: boolean,
|
|
142
148
|
};
|
|
143
149
|
|
|
144
|
-
//
|
|
150
|
+
// Adjust content in your templates based on tokenContext values
|
|
145
151
|
res.render("index.ejs", { tokenContext });
|
|
146
152
|
});
|
|
147
153
|
|
package/dist/browser.d.cts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Used to verify `X-Better-Web-
|
|
2
|
+
* Official Zero Ad Network public key.
|
|
3
|
+
* Used to verify that `X-Better-Web-Hello` header values are authentic
|
|
4
|
+
* and have not been tampered with.
|
|
4
5
|
*/
|
|
5
6
|
declare const ZEROAD_NETWORK_PUBLIC_KEY: string;
|
|
6
7
|
declare enum FEATURES {
|
|
7
|
-
/**
|
|
8
|
+
/** Disable all advertisements on the page */
|
|
8
9
|
ADS_OFF = 1,
|
|
9
|
-
/**
|
|
10
|
+
/** Disable all Cookie Consent screens (headers, footers, or dialogs)
|
|
11
|
+
and fully opt out of non-functional trackers */
|
|
10
12
|
COOKIE_CONSENT_OFF = 2,
|
|
11
|
-
/**
|
|
13
|
+
/** Disable all marketing dialogs or popups (e.g., newsletters, promotions) */
|
|
12
14
|
MARKETING_DIALOG_OFF = 4,
|
|
13
|
-
/** Provide automatic access to
|
|
15
|
+
/** Provide automatic access to content that is normally paywalled */
|
|
14
16
|
CONTENT_PAYWALL_OFF = 8,
|
|
15
|
-
/**
|
|
17
|
+
/** Grant automatic access to site features behind a SaaS,
|
|
18
|
+
at least the basic subscription plan */
|
|
16
19
|
SUBSCRIPTION_ACCESS_ON = 16
|
|
17
20
|
}
|
|
18
21
|
type UUID = string;
|
package/dist/browser.d.mts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Used to verify `X-Better-Web-
|
|
2
|
+
* Official Zero Ad Network public key.
|
|
3
|
+
* Used to verify that `X-Better-Web-Hello` header values are authentic
|
|
4
|
+
* and have not been tampered with.
|
|
4
5
|
*/
|
|
5
6
|
declare const ZEROAD_NETWORK_PUBLIC_KEY: string;
|
|
6
7
|
declare enum FEATURES {
|
|
7
|
-
/**
|
|
8
|
+
/** Disable all advertisements on the page */
|
|
8
9
|
ADS_OFF = 1,
|
|
9
|
-
/**
|
|
10
|
+
/** Disable all Cookie Consent screens (headers, footers, or dialogs)
|
|
11
|
+
and fully opt out of non-functional trackers */
|
|
10
12
|
COOKIE_CONSENT_OFF = 2,
|
|
11
|
-
/**
|
|
13
|
+
/** Disable all marketing dialogs or popups (e.g., newsletters, promotions) */
|
|
12
14
|
MARKETING_DIALOG_OFF = 4,
|
|
13
|
-
/** Provide automatic access to
|
|
15
|
+
/** Provide automatic access to content that is normally paywalled */
|
|
14
16
|
CONTENT_PAYWALL_OFF = 8,
|
|
15
|
-
/**
|
|
17
|
+
/** Grant automatic access to site features behind a SaaS,
|
|
18
|
+
at least the basic subscription plan */
|
|
16
19
|
SUBSCRIPTION_ACCESS_ON = 16
|
|
17
20
|
}
|
|
18
21
|
type UUID = string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeroad.network/token",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.7",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": "github:laurynas-karvelis/zeroad-token-typescript",
|
|
6
6
|
"homepage": "https://zeroad.network",
|
|
@@ -14,10 +14,34 @@
|
|
|
14
14
|
"./dist/**/*"
|
|
15
15
|
],
|
|
16
16
|
"keywords": [
|
|
17
|
-
"better web",
|
|
18
17
|
"zero ad network",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
18
|
+
"zeroad",
|
|
19
|
+
"zero-ad",
|
|
20
|
+
"token",
|
|
21
|
+
"access-token",
|
|
22
|
+
"http-header",
|
|
23
|
+
"welcome-header",
|
|
24
|
+
"auth",
|
|
25
|
+
"authorization",
|
|
26
|
+
"subscription",
|
|
27
|
+
"feature-flags",
|
|
28
|
+
"entitlement",
|
|
29
|
+
"ad-free",
|
|
30
|
+
"ads-free",
|
|
31
|
+
"paywall",
|
|
32
|
+
"content-access",
|
|
33
|
+
"middleware",
|
|
34
|
+
"typescript",
|
|
35
|
+
"javascript",
|
|
36
|
+
"nodejs",
|
|
37
|
+
"deno",
|
|
38
|
+
"bun",
|
|
39
|
+
"esm",
|
|
40
|
+
"cjs",
|
|
41
|
+
"web-server",
|
|
42
|
+
"express",
|
|
43
|
+
"fastify",
|
|
44
|
+
"hono"
|
|
21
45
|
],
|
|
22
46
|
"engines": {
|
|
23
47
|
"node": ">= 18.0.0",
|