@zeroad.network/token 0.12.0 → 0.13.0
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 +4 -4
- package/dist/{browser-C50SBRBw.cjs → browser-C2zgnAdK.cjs} +1 -1
- package/dist/{browser-ByaVwJr6.mjs → browser-DDeUUPbU.mjs} +1 -1
- package/dist/browser.d.cts +3 -5
- package/dist/browser.d.mts +3 -5
- package/dist/browser.mjs +1 -1
- package/dist/index.cjs +5 -6
- package/dist/index.d.cts +8 -8
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +6 -7
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -44,23 +44,23 @@ Take the simplest JavaScript example as a reference. The most basic, and honestl
|
|
|
44
44
|
|
|
45
45
|
```js
|
|
46
46
|
import express from "express";
|
|
47
|
-
import {
|
|
47
|
+
import { Site } from "@zeroad.network/token";
|
|
48
48
|
|
|
49
49
|
const app = express();
|
|
50
50
|
|
|
51
51
|
// Initialize your Zero Ad Network module
|
|
52
52
|
// Welcome Header Value acquired during Site Registration process at Zero Ad Network platform
|
|
53
53
|
const ZERO_AD_NETWORK_WELCOME_HEADER_VALUE = "AZqnKU56eIC7vCD1PPlwHg^1^3";
|
|
54
|
-
const
|
|
54
|
+
const site = Site(ZERO_AD_NETWORK_WELCOME_HEADER_VALUE);
|
|
55
55
|
|
|
56
56
|
app
|
|
57
57
|
.use((req, res, next) => {
|
|
58
58
|
// X-Better-Web-Welcome header injection can could have it's own simple middleware like this:
|
|
59
|
-
res.set(
|
|
59
|
+
res.set(site.SERVER_HEADER_NAME, site.SERVER_HEADER_VALUE);
|
|
60
60
|
|
|
61
61
|
// Process request token from incoming client token header value.
|
|
62
62
|
// And attach processed token info to request for downstream usage.
|
|
63
|
-
req.tokenContext =
|
|
63
|
+
req.tokenContext = site.parseToken(req.get[site.CLIENT_HEADER_NAME]);
|
|
64
64
|
|
|
65
65
|
next();
|
|
66
66
|
})
|
|
@@ -102,7 +102,7 @@ function log(level, ...args) {
|
|
|
102
102
|
const SEPARATOR = "^";
|
|
103
103
|
const SITE_FEATURES_NATIVE = getSiteFeaturesNative();
|
|
104
104
|
class ServerHeader {
|
|
105
|
-
NAME = SERVER_HEADERS.WELCOME
|
|
105
|
+
NAME = SERVER_HEADERS.WELCOME;
|
|
106
106
|
VALUE;
|
|
107
107
|
constructor(options) {
|
|
108
108
|
if (typeof options === "string") {
|
|
@@ -100,7 +100,7 @@ function log(level, ...args) {
|
|
|
100
100
|
const SEPARATOR = "^";
|
|
101
101
|
const SITE_FEATURES_NATIVE = getSiteFeaturesNative();
|
|
102
102
|
class ServerHeader {
|
|
103
|
-
NAME = SERVER_HEADERS.WELCOME
|
|
103
|
+
NAME = SERVER_HEADERS.WELCOME;
|
|
104
104
|
VALUE;
|
|
105
105
|
constructor(options) {
|
|
106
106
|
if (typeof options === "string") {
|
package/dist/browser.d.cts
CHANGED
|
@@ -31,13 +31,11 @@ type ServerHeaderExtendedOptions = {
|
|
|
31
31
|
features: FEATURES[];
|
|
32
32
|
};
|
|
33
33
|
type ServerHeaderOptions = NonNullable<string | ServerHeaderExtendedOptions>;
|
|
34
|
-
type WelcomeHeaderParseResult = WelcomeHeader | undefined;
|
|
35
34
|
type WelcomeHeader = {
|
|
36
35
|
version: PROTOCOL_VERSION;
|
|
37
36
|
features: (keyof typeof FEATURES)[];
|
|
38
37
|
siteId: UUID;
|
|
39
38
|
};
|
|
40
|
-
type ClientHeaderParseResult = ClientParsedHeader | undefined;
|
|
41
39
|
type ClientParsedHeader = {
|
|
42
40
|
version: PROTOCOL_VERSION;
|
|
43
41
|
expiresAt: Date;
|
|
@@ -45,12 +43,12 @@ type ClientParsedHeader = {
|
|
|
45
43
|
};
|
|
46
44
|
|
|
47
45
|
declare class ServerHeader {
|
|
48
|
-
NAME:
|
|
46
|
+
NAME: SERVER_HEADERS;
|
|
49
47
|
VALUE: string;
|
|
50
48
|
constructor(options: ServerHeaderOptions);
|
|
51
49
|
encode(siteId: UUID, features: FEATURES[]): string;
|
|
52
|
-
static decode(headerValue: string | undefined):
|
|
50
|
+
static decode(headerValue: string | undefined): WelcomeHeader | undefined;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
export { CLIENT_HEADERS, CURRENT_PROTOCOL_VERSION, FEATURES, PROTOCOL_VERSION, SERVER_HEADERS, ServerHeader, ZEROAD_NETWORK_PUBLIC_KEY };
|
|
56
|
-
export type {
|
|
54
|
+
export type { ClientParsedHeader, ServerHeaderExtendedOptions, ServerHeaderOptions, UUID, WelcomeHeader };
|
package/dist/browser.d.mts
CHANGED
|
@@ -31,13 +31,11 @@ type ServerHeaderExtendedOptions = {
|
|
|
31
31
|
features: FEATURES[];
|
|
32
32
|
};
|
|
33
33
|
type ServerHeaderOptions = NonNullable<string | ServerHeaderExtendedOptions>;
|
|
34
|
-
type WelcomeHeaderParseResult = WelcomeHeader | undefined;
|
|
35
34
|
type WelcomeHeader = {
|
|
36
35
|
version: PROTOCOL_VERSION;
|
|
37
36
|
features: (keyof typeof FEATURES)[];
|
|
38
37
|
siteId: UUID;
|
|
39
38
|
};
|
|
40
|
-
type ClientHeaderParseResult = ClientParsedHeader | undefined;
|
|
41
39
|
type ClientParsedHeader = {
|
|
42
40
|
version: PROTOCOL_VERSION;
|
|
43
41
|
expiresAt: Date;
|
|
@@ -45,12 +43,12 @@ type ClientParsedHeader = {
|
|
|
45
43
|
};
|
|
46
44
|
|
|
47
45
|
declare class ServerHeader {
|
|
48
|
-
NAME:
|
|
46
|
+
NAME: SERVER_HEADERS;
|
|
49
47
|
VALUE: string;
|
|
50
48
|
constructor(options: ServerHeaderOptions);
|
|
51
49
|
encode(siteId: UUID, features: FEATURES[]): string;
|
|
52
|
-
static decode(headerValue: string | undefined):
|
|
50
|
+
static decode(headerValue: string | undefined): WelcomeHeader | undefined;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
export { CLIENT_HEADERS, CURRENT_PROTOCOL_VERSION, FEATURES, PROTOCOL_VERSION, SERVER_HEADERS, ServerHeader, ZEROAD_NETWORK_PUBLIC_KEY };
|
|
56
|
-
export type {
|
|
54
|
+
export type { ClientParsedHeader, ServerHeaderExtendedOptions, ServerHeaderOptions, UUID, WelcomeHeader };
|
package/dist/browser.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { C as CLIENT_HEADERS, c as CURRENT_PROTOCOL_VERSION, F as FEATURES, P as PROTOCOL_VERSION, b as SERVER_HEADERS, S as ServerHeader, Z as ZEROAD_NETWORK_PUBLIC_KEY } from './browser-
|
|
1
|
+
export { C as CLIENT_HEADERS, c as CURRENT_PROTOCOL_VERSION, F as FEATURES, P as PROTOCOL_VERSION, b as SERVER_HEADERS, S as ServerHeader, Z as ZEROAD_NETWORK_PUBLIC_KEY } from './browser-DDeUUPbU.mjs';
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var browser = require('./browser-
|
|
3
|
+
var browser = require('./browser-C2zgnAdK.cjs');
|
|
4
4
|
var crypto = require('crypto');
|
|
5
5
|
|
|
6
6
|
const importPrivateKey = (privateKeyBase64) => {
|
|
@@ -44,7 +44,7 @@ class ClientHeader {
|
|
|
44
44
|
cryptoPrivateKey;
|
|
45
45
|
publicKey;
|
|
46
46
|
privateKey;
|
|
47
|
-
NAME = browser.CLIENT_HEADERS.HELLO
|
|
47
|
+
NAME = browser.CLIENT_HEADERS.HELLO;
|
|
48
48
|
constructor(publicKey, privateKey) {
|
|
49
49
|
this.publicKey = publicKey;
|
|
50
50
|
this.privateKey = privateKey;
|
|
@@ -52,9 +52,8 @@ class ClientHeader {
|
|
|
52
52
|
parseToken(headerValue) {
|
|
53
53
|
const headerValueAsString = Array.isArray(headerValue) ? headerValue[0] : headerValue;
|
|
54
54
|
const data = this.decode(headerValueAsString);
|
|
55
|
-
const expired = !data || data.expiresAt.getTime() < Date.now();
|
|
56
55
|
const result = {};
|
|
57
|
-
if (!data ||
|
|
56
|
+
if (!data || data.expiresAt.getTime() < Date.now()) {
|
|
58
57
|
for (const [feature] of SITE_FEATURES_NATIVE) {
|
|
59
58
|
result[feature] = false;
|
|
60
59
|
}
|
|
@@ -113,7 +112,7 @@ const mergeByteArrays = (arrays) => {
|
|
|
113
112
|
return data;
|
|
114
113
|
};
|
|
115
114
|
|
|
116
|
-
function
|
|
115
|
+
function Site(options) {
|
|
117
116
|
const serverHeader = new browser.ServerHeader(options);
|
|
118
117
|
const clientHeader = new ClientHeader(browser.ZEROAD_NETWORK_PUBLIC_KEY);
|
|
119
118
|
return {
|
|
@@ -133,4 +132,4 @@ exports.SERVER_HEADERS = browser.SERVER_HEADERS;
|
|
|
133
132
|
exports.ServerHeader = browser.ServerHeader;
|
|
134
133
|
exports.ZEROAD_NETWORK_PUBLIC_KEY = browser.ZEROAD_NETWORK_PUBLIC_KEY;
|
|
135
134
|
exports.ClientHeader = ClientHeader;
|
|
136
|
-
exports.
|
|
135
|
+
exports.Site = Site;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { CLIENT_HEADERS, ClientParsedHeader, PROTOCOL_VERSION, FEATURES, ServerHeaderOptions, SERVER_HEADERS } from './browser.cjs';
|
|
2
|
+
export { CURRENT_PROTOCOL_VERSION, ServerHeader, ServerHeaderExtendedOptions, UUID, WelcomeHeader, ZEROAD_NETWORK_PUBLIC_KEY } from './browser.cjs';
|
|
3
3
|
|
|
4
4
|
declare class ClientHeader {
|
|
5
5
|
private cryptoPublicKey;
|
|
6
6
|
private cryptoPrivateKey;
|
|
7
7
|
private publicKey;
|
|
8
8
|
private privateKey;
|
|
9
|
-
NAME:
|
|
9
|
+
NAME: CLIENT_HEADERS;
|
|
10
10
|
constructor(publicKey: string, privateKey?: string);
|
|
11
11
|
parseToken(headerValue: string | string[] | undefined): Record<"ADS_OFF" | "COOKIE_CONSENT_OFF" | "MARKETING_DIALOG_OFF" | "CONTENT_PAYWALL_OFF" | "SUBSCRIPTION_ACCESS_ON", boolean>;
|
|
12
|
-
decode(headerValue: string | undefined):
|
|
12
|
+
decode(headerValue: string | undefined): ClientParsedHeader | undefined;
|
|
13
13
|
encode(version: PROTOCOL_VERSION, expiresAt: Date, features: FEATURES[]): string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
type LogLevel = "error" | "warn" | "info" | "debug";
|
|
17
17
|
declare function setLogLevel(level: LogLevel): void;
|
|
18
18
|
|
|
19
|
-
declare function
|
|
19
|
+
declare function Site(options: ServerHeaderOptions): {
|
|
20
20
|
setLogLevel: typeof setLogLevel;
|
|
21
21
|
parseToken: (headerValue: string | string[] | undefined) => Record<"ADS_OFF" | "COOKIE_CONSENT_OFF" | "MARKETING_DIALOG_OFF" | "CONTENT_PAYWALL_OFF" | "SUBSCRIPTION_ACCESS_ON", boolean>;
|
|
22
|
-
CLIENT_HEADER_NAME:
|
|
23
|
-
SERVER_HEADER_NAME:
|
|
22
|
+
CLIENT_HEADER_NAME: CLIENT_HEADERS;
|
|
23
|
+
SERVER_HEADER_NAME: SERVER_HEADERS;
|
|
24
24
|
SERVER_HEADER_VALUE: string;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export { ClientHeader,
|
|
27
|
+
export { CLIENT_HEADERS, ClientHeader, ClientParsedHeader, FEATURES, PROTOCOL_VERSION, SERVER_HEADERS, ServerHeaderOptions, Site };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { CLIENT_HEADERS, ClientParsedHeader, PROTOCOL_VERSION, FEATURES, ServerHeaderOptions, SERVER_HEADERS } from './browser.mjs';
|
|
2
|
+
export { CURRENT_PROTOCOL_VERSION, ServerHeader, ServerHeaderExtendedOptions, UUID, WelcomeHeader, ZEROAD_NETWORK_PUBLIC_KEY } from './browser.mjs';
|
|
3
3
|
|
|
4
4
|
declare class ClientHeader {
|
|
5
5
|
private cryptoPublicKey;
|
|
6
6
|
private cryptoPrivateKey;
|
|
7
7
|
private publicKey;
|
|
8
8
|
private privateKey;
|
|
9
|
-
NAME:
|
|
9
|
+
NAME: CLIENT_HEADERS;
|
|
10
10
|
constructor(publicKey: string, privateKey?: string);
|
|
11
11
|
parseToken(headerValue: string | string[] | undefined): Record<"ADS_OFF" | "COOKIE_CONSENT_OFF" | "MARKETING_DIALOG_OFF" | "CONTENT_PAYWALL_OFF" | "SUBSCRIPTION_ACCESS_ON", boolean>;
|
|
12
|
-
decode(headerValue: string | undefined):
|
|
12
|
+
decode(headerValue: string | undefined): ClientParsedHeader | undefined;
|
|
13
13
|
encode(version: PROTOCOL_VERSION, expiresAt: Date, features: FEATURES[]): string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
type LogLevel = "error" | "warn" | "info" | "debug";
|
|
17
17
|
declare function setLogLevel(level: LogLevel): void;
|
|
18
18
|
|
|
19
|
-
declare function
|
|
19
|
+
declare function Site(options: ServerHeaderOptions): {
|
|
20
20
|
setLogLevel: typeof setLogLevel;
|
|
21
21
|
parseToken: (headerValue: string | string[] | undefined) => Record<"ADS_OFF" | "COOKIE_CONSENT_OFF" | "MARKETING_DIALOG_OFF" | "CONTENT_PAYWALL_OFF" | "SUBSCRIPTION_ACCESS_ON", boolean>;
|
|
22
|
-
CLIENT_HEADER_NAME:
|
|
23
|
-
SERVER_HEADER_NAME:
|
|
22
|
+
CLIENT_HEADER_NAME: CLIENT_HEADERS;
|
|
23
|
+
SERVER_HEADER_NAME: SERVER_HEADERS;
|
|
24
24
|
SERVER_HEADER_VALUE: string;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export { ClientHeader,
|
|
27
|
+
export { CLIENT_HEADERS, ClientHeader, ClientParsedHeader, FEATURES, PROTOCOL_VERSION, SERVER_HEADERS, ServerHeaderOptions, Site };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getSiteFeaturesNative, C as CLIENT_HEADERS, h as hasFeature, f as fromBase64, P as PROTOCOL_VERSION, l as log, s as setFeatures, t as toBase64, S as ServerHeader, a as setLogLevel, Z as ZEROAD_NETWORK_PUBLIC_KEY } from './browser-
|
|
2
|
-
export { c as CURRENT_PROTOCOL_VERSION, F as FEATURES, b as SERVER_HEADERS } from './browser-
|
|
1
|
+
import { g as getSiteFeaturesNative, C as CLIENT_HEADERS, h as hasFeature, f as fromBase64, P as PROTOCOL_VERSION, l as log, s as setFeatures, t as toBase64, S as ServerHeader, a as setLogLevel, Z as ZEROAD_NETWORK_PUBLIC_KEY } from './browser-DDeUUPbU.mjs';
|
|
2
|
+
export { c as CURRENT_PROTOCOL_VERSION, F as FEATURES, b as SERVER_HEADERS } from './browser-DDeUUPbU.mjs';
|
|
3
3
|
import { createPublicKey, verify as verify$1, randomBytes, createPrivateKey, sign as sign$1 } from 'crypto';
|
|
4
4
|
|
|
5
5
|
const importPrivateKey = (privateKeyBase64) => {
|
|
@@ -43,7 +43,7 @@ class ClientHeader {
|
|
|
43
43
|
cryptoPrivateKey;
|
|
44
44
|
publicKey;
|
|
45
45
|
privateKey;
|
|
46
|
-
NAME = CLIENT_HEADERS.HELLO
|
|
46
|
+
NAME = CLIENT_HEADERS.HELLO;
|
|
47
47
|
constructor(publicKey, privateKey) {
|
|
48
48
|
this.publicKey = publicKey;
|
|
49
49
|
this.privateKey = privateKey;
|
|
@@ -51,9 +51,8 @@ class ClientHeader {
|
|
|
51
51
|
parseToken(headerValue) {
|
|
52
52
|
const headerValueAsString = Array.isArray(headerValue) ? headerValue[0] : headerValue;
|
|
53
53
|
const data = this.decode(headerValueAsString);
|
|
54
|
-
const expired = !data || data.expiresAt.getTime() < Date.now();
|
|
55
54
|
const result = {};
|
|
56
|
-
if (!data ||
|
|
55
|
+
if (!data || data.expiresAt.getTime() < Date.now()) {
|
|
57
56
|
for (const [feature] of SITE_FEATURES_NATIVE) {
|
|
58
57
|
result[feature] = false;
|
|
59
58
|
}
|
|
@@ -112,7 +111,7 @@ const mergeByteArrays = (arrays) => {
|
|
|
112
111
|
return data;
|
|
113
112
|
};
|
|
114
113
|
|
|
115
|
-
function
|
|
114
|
+
function Site(options) {
|
|
116
115
|
const serverHeader = new ServerHeader(options);
|
|
117
116
|
const clientHeader = new ClientHeader(ZEROAD_NETWORK_PUBLIC_KEY);
|
|
118
117
|
return {
|
|
@@ -124,4 +123,4 @@ function ZeroAdNetwork(options) {
|
|
|
124
123
|
};
|
|
125
124
|
}
|
|
126
125
|
|
|
127
|
-
export { CLIENT_HEADERS, ClientHeader, PROTOCOL_VERSION, ServerHeader,
|
|
126
|
+
export { CLIENT_HEADERS, ClientHeader, PROTOCOL_VERSION, ServerHeader, Site, ZEROAD_NETWORK_PUBLIC_KEY };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeroad.network/token",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": "github:laurynas-karvelis/zeroad-token-ts",
|
|
6
6
|
"homepage": "https://zeroad.network",
|
|
@@ -42,9 +42,6 @@
|
|
|
42
42
|
"default": "./dist/browser.mjs"
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
|
-
"output": {
|
|
46
|
-
"exports": "named"
|
|
47
|
-
},
|
|
48
45
|
"scripts": {
|
|
49
46
|
"keys:generate": "bun run ./src/tools/cli.ts",
|
|
50
47
|
"prettier": "prettier . --write",
|