@zeroad.network/token 0.13.6 → 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 +58 -54
- package/dist/browser.d.cts +10 -7
- package/dist/browser.d.mts +10 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,43 +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
|
-
The `@zeroad.network/token` module
|
|
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
|
-
## Runtime
|
|
9
|
+
## Runtime Compatibility
|
|
10
10
|
|
|
11
|
-
| Runtime |
|
|
12
|
-
| :------ |
|
|
13
|
-
| Node.js | 16+
|
|
14
|
-
| Bun | 1.1.0+
|
|
15
|
-
| Deno | 2.0.0+
|
|
11
|
+
| Runtime | Version | ESM | CJS |
|
|
12
|
+
| :------ | :------ | :-: | :-: |
|
|
13
|
+
| Node.js | 16+ | ✅ | ✅ |
|
|
14
|
+
| Bun | 1.1.0+ | ✅ | ✅ |
|
|
15
|
+
| Deno | 2.0.0+ | ✅ | ✅ |
|
|
16
16
|
|
|
17
17
|
## Purpose
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
The module helps developers to:
|
|
20
|
+
|
|
21
|
+
- Inject a valid site's HTTP Response Header (**Welcome Header**) into every endpoint. Example:
|
|
20
22
|
|
|
21
|
-
- Inject a valid site's HTTP Response Header known as "Welcome Header" to every endpoint. An example:
|
|
22
23
|
```http
|
|
23
24
|
X-Better-Web-Welcome: "AZqnKU56eIC7vCD1PPlwHg^1^3"
|
|
24
25
|
```
|
|
25
|
-
|
|
26
|
+
|
|
27
|
+
- Detect and parse Zero Ad Network user tokens sent via HTTP Request Header. Example:
|
|
28
|
+
|
|
26
29
|
```http
|
|
27
30
|
X-Better-Web-Hello: "Aav2IXRoh0oKBw==.2yZfC2/pM9DWfgX+von4IgWLmN9t67HJHLiee/gx4+pFIHHurwkC3PCHT1Kaz0yUhx3crUaxST+XLlRtJYacAQ=="
|
|
28
31
|
```
|
|
29
|
-
- If found, parse the token from the HTTP Request Header value and verify its integrity.
|
|
30
|
-
- (Optionally) Generate a valid "Welcome Header" value when `siteId` UUID and site `features` array are provided.
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
- Verify token integrity locally.
|
|
34
|
+
- Optionally generate a valid "Welcome Header" when `siteId` and `features` are provided.
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
## Implementation Details
|
|
35
37
|
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
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`.
|
|
39
41
|
|
|
40
|
-
Parsed token
|
|
42
|
+
Parsed token example:
|
|
41
43
|
|
|
42
44
|
```js
|
|
43
45
|
{
|
|
@@ -49,27 +51,29 @@ Parsed token result example:
|
|
|
49
51
|
};
|
|
50
52
|
```
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
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.
|
|
57
57
|
|
|
58
|
-
##
|
|
58
|
+
## Benefits of Joining
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
Partnering with Zero Ad Network allows your site to:
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
- Generate a new revenue stream
|
|
63
|
+
- Provide a clean, unobstructed user experience
|
|
64
|
+
- Contribute to a more joyful, user-friendly internet
|
|
63
65
|
|
|
64
|
-
##
|
|
66
|
+
## Onboarding Your Site
|
|
65
67
|
|
|
66
|
-
|
|
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.
|
|
67
70
|
|
|
68
|
-
|
|
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.
|
|
69
72
|
|
|
70
|
-
## Module
|
|
73
|
+
## Module Installation
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
- Written entirely in TypeScript with full types and interfaces.
|
|
76
|
+
- Supports both ESM (`import`) and CommonJS (`require`). ESM is recommended when possible.
|
|
73
77
|
|
|
74
78
|
To install the module use your favourite package manager:
|
|
75
79
|
|
|
@@ -92,15 +96,15 @@ deno add npm:@zeroad.network/token
|
|
|
92
96
|
|
|
93
97
|
## Examples
|
|
94
98
|
|
|
95
|
-
|
|
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/).
|
|
96
100
|
|
|
97
|
-
|
|
101
|
+
The following JavaScript example provides a quick reference, demonstrating how to:
|
|
98
102
|
|
|
99
|
-
- Inject the "Welcome Header" into
|
|
100
|
-
- Parse user's token from
|
|
101
|
-
- 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
|
|
102
106
|
|
|
103
|
-
|
|
107
|
+
Minimal Express.js v5 app example:
|
|
104
108
|
|
|
105
109
|
```js
|
|
106
110
|
import express from "express";
|
|
@@ -108,42 +112,42 @@ import { Site } from "@zeroad.network/token";
|
|
|
108
112
|
|
|
109
113
|
const app = express();
|
|
110
114
|
|
|
111
|
-
// Initialize
|
|
112
|
-
// "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).
|
|
113
117
|
const ZERO_AD_NETWORK_WELCOME_HEADER_VALUE = "AZqnKU56eIC7vCD1PPlwHg^1^3";
|
|
114
118
|
const site = Site(ZERO_AD_NETWORK_WELCOME_HEADER_VALUE);
|
|
115
119
|
|
|
116
120
|
app
|
|
117
|
-
//
|
|
121
|
+
// Apply middleware for all routes
|
|
118
122
|
.use((req, res, next) => {
|
|
119
|
-
// Inject "X-Better-Web-Welcome" header
|
|
123
|
+
// Inject the "X-Better-Web-Welcome" header into the response
|
|
120
124
|
res.set(site.SERVER_HEADER_NAME, site.SERVER_HEADER_VALUE);
|
|
121
125
|
|
|
122
|
-
// Parse the
|
|
123
|
-
//
|
|
124
|
-
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));
|
|
125
129
|
|
|
126
130
|
next();
|
|
127
131
|
})
|
|
128
132
|
.get("/", (req, res) => {
|
|
129
|
-
//
|
|
133
|
+
// Access parsed token data for this request
|
|
130
134
|
console.log(req.tokenContext);
|
|
131
135
|
|
|
132
|
-
//
|
|
136
|
+
// Example structure of tokenContext:
|
|
133
137
|
req.tokenContext = {
|
|
134
|
-
// If
|
|
138
|
+
// If true: Hide advertisements on the page
|
|
135
139
|
ADS_OFF: boolean,
|
|
136
|
-
// If
|
|
140
|
+
// If true: Hide Cookie Consent screens and opt out non-functional trackers
|
|
137
141
|
COOKIE_CONSENT_OFF: boolean,
|
|
138
|
-
// If
|
|
142
|
+
// If true: Hide marketing dialogs or popups (e.g., newsletter, promotions)
|
|
139
143
|
MARKETING_DIALOG_OFF: boolean,
|
|
140
|
-
// If
|
|
144
|
+
// If true: Provide automatic access to paywalled content
|
|
141
145
|
CONTENT_PAYWALL_OFF: boolean,
|
|
142
|
-
// If
|
|
146
|
+
// If true: Provide access to site features behind SaaS subscription (at least basic plan)
|
|
143
147
|
SUBSCRIPTION_ACCESS_ON: boolean,
|
|
144
148
|
};
|
|
145
149
|
|
|
146
|
-
//
|
|
150
|
+
// Adjust content in your templates based on tokenContext values
|
|
147
151
|
res.render("index.ejs", { tokenContext });
|
|
148
152
|
});
|
|
149
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;
|