@zeroad.network/token 0.13.10 → 0.13.11
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/dist/{browser-Bx6W_oKL.mjs → browser-4DOrMTCi.mjs} +1 -1
- package/dist/{browser-B9BhMU2_.cjs → browser-CBvcQzoQ.cjs} +0 -1
- package/dist/browser.mjs +1 -1
- package/dist/index.cjs +22 -19
- package/dist/index.d.cts +14 -9
- package/dist/index.d.mts +14 -9
- package/dist/index.mjs +24 -21
- package/package.json +1 -1
|
@@ -118,4 +118,4 @@ function decodeServerHeader(headerValue) {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export { CLIENT_HEADERS as C,
|
|
121
|
+
export { CLIENT_HEADERS as C, FEATURES as F, PROTOCOL_VERSION as P, SERVER_HEADERS as S, ZEROAD_NETWORK_PUBLIC_KEY as Z, setLogLevel as a, CURRENT_PROTOCOL_VERSION as b, decodeServerHeader as d, encodeServerHeader as e, fromBase64 as f, hasFlag as h, log as l, setFlags as s, toBase64 as t };
|
|
@@ -123,7 +123,6 @@ function decodeServerHeader(headerValue) {
|
|
|
123
123
|
exports.CLIENT_HEADERS = CLIENT_HEADERS;
|
|
124
124
|
exports.CURRENT_PROTOCOL_VERSION = CURRENT_PROTOCOL_VERSION;
|
|
125
125
|
exports.FEATURES = FEATURES;
|
|
126
|
-
exports.FEATURE_MAP = FEATURE_MAP;
|
|
127
126
|
exports.PROTOCOL_VERSION = PROTOCOL_VERSION;
|
|
128
127
|
exports.SERVER_HEADERS = SERVER_HEADERS;
|
|
129
128
|
exports.ZEROAD_NETWORK_PUBLIC_KEY = ZEROAD_NETWORK_PUBLIC_KEY;
|
package/dist/browser.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { C as CLIENT_HEADERS,
|
|
1
|
+
export { C as CLIENT_HEADERS, b as CURRENT_PROTOCOL_VERSION, F as FEATURES, P as PROTOCOL_VERSION, S as SERVER_HEADERS, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader } from './browser-4DOrMTCi.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-CBvcQzoQ.cjs');
|
|
4
4
|
var node_buffer = require('node:buffer');
|
|
5
5
|
var node_crypto = require('node:crypto');
|
|
6
6
|
|
|
@@ -38,26 +38,29 @@ function importPublicKey(publicKeyBase64) {
|
|
|
38
38
|
const VERSION_BYTES = 1;
|
|
39
39
|
const NONCE_BYTES = 4;
|
|
40
40
|
const SEPARATOR = ".";
|
|
41
|
-
|
|
41
|
+
const FEATURES_TO_ACTIONS = {
|
|
42
|
+
[browser.FEATURES.CLEAN_WEB]: [
|
|
43
|
+
"HIDE_ADVERTISEMENTS",
|
|
44
|
+
"HIDE_COOKIE_CONSENT_SCREEN",
|
|
45
|
+
"HIDE_MARKETING_DIALOGS",
|
|
46
|
+
"DISABLE_NON_FUNCTIONAL_TRACKING"
|
|
47
|
+
],
|
|
48
|
+
[browser.FEATURES.ONE_PASS]: ["DISABLE_CONTENT_PAYWALL", "ENABLE_SUBSCRIPTION_ACCESS"]
|
|
49
|
+
};
|
|
50
|
+
function parseClientToken(headerValue, options) {
|
|
42
51
|
const headerValueAsString = Array.isArray(headerValue) ? headerValue[0] : headerValue;
|
|
43
|
-
const data = decodeClientHeader(headerValueAsString, publicKey);
|
|
52
|
+
const data = decodeClientHeader(headerValueAsString, options.publicKey || browser.ZEROAD_NETWORK_PUBLIC_KEY);
|
|
44
53
|
let flags = 0;
|
|
45
54
|
if (data && data.expiresAt.getTime() >= Date.now()) flags = data.flags;
|
|
46
|
-
if (flags && data?.clientId && data.clientId !== clientId) flags = 0;
|
|
47
|
-
const
|
|
48
|
-
for (const [feature,
|
|
49
|
-
|
|
55
|
+
if (flags && data?.clientId && data.clientId !== options.clientId) flags = 0;
|
|
56
|
+
const context = /* @__PURE__ */ new Map();
|
|
57
|
+
for (const [feature, actionNames] of Object.entries(FEATURES_TO_ACTIONS)) {
|
|
58
|
+
const decision = options.features.includes(Number(feature)) && browser.hasFlag(Number(feature), flags);
|
|
59
|
+
for (const actionName of actionNames) {
|
|
60
|
+
context.set(actionName, decision);
|
|
61
|
+
}
|
|
50
62
|
}
|
|
51
|
-
|
|
52
|
-
const hasOnePass = features.includes("ONE_PASS");
|
|
53
|
-
return {
|
|
54
|
-
HIDE_ADVERTISEMENTS: hasCleanWeb,
|
|
55
|
-
HIDE_COOKIE_CONSENT_SCREEN: hasCleanWeb,
|
|
56
|
-
HIDE_MARKETING_DIALOGS: hasCleanWeb,
|
|
57
|
-
DISABLE_NON_FUNCTIONAL_TRACKING: hasCleanWeb,
|
|
58
|
-
DISABLE_CONTENT_PAYWALL: hasOnePass,
|
|
59
|
-
ENABLE_SUBSCRIPTION_ACCESS: hasOnePass
|
|
60
|
-
};
|
|
63
|
+
return Object.fromEntries(context);
|
|
61
64
|
}
|
|
62
65
|
function decodeClientHeader(headerValue, publicKey) {
|
|
63
66
|
if (!headerValue?.length) return;
|
|
@@ -116,8 +119,8 @@ function as32BitNumber(byteArray, begin) {
|
|
|
116
119
|
function Site(options) {
|
|
117
120
|
const serverHeaderValue = browser.encodeServerHeader(options.clientId, options.features);
|
|
118
121
|
return {
|
|
119
|
-
parseClientToken: (headerValue) => parseClientToken(headerValue, options.clientId,
|
|
120
|
-
CLIENT_HEADER_NAME: browser.CLIENT_HEADERS.HELLO,
|
|
122
|
+
parseClientToken: (headerValue) => parseClientToken(headerValue, { clientId: options.clientId, features: options.features }),
|
|
123
|
+
CLIENT_HEADER_NAME: browser.CLIENT_HEADERS.HELLO.toLowerCase(),
|
|
121
124
|
SERVER_HEADER_NAME: browser.SERVER_HEADERS.WELCOME,
|
|
122
125
|
SERVER_HEADER_VALUE: serverHeaderValue
|
|
123
126
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { a as CURRENT_PROTOCOL_VERSION, W as WelcomeHeader, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader, e as encodeServerHeader } from './browser-BiNZ2c6t.cjs';
|
|
1
|
+
import { F as FEATURES, P as PROTOCOL_VERSION, S as SERVER_HEADERS } from './browser-BiNZ2c6t.cjs';
|
|
2
|
+
export { C as CLIENT_HEADERS, a as CURRENT_PROTOCOL_VERSION, W as WelcomeHeader, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader, e as encodeServerHeader } from './browser-BiNZ2c6t.cjs';
|
|
3
3
|
|
|
4
4
|
type LogLevel = "error" | "warn" | "info" | "debug";
|
|
5
5
|
declare function setLogLevel(level: LogLevel): void;
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
type FEATURE_ACTIONS = "HIDE_ADVERTISEMENTS" | "HIDE_COOKIE_CONSENT_SCREEN" | "HIDE_MARKETING_DIALOGS" | "DISABLE_NON_FUNCTIONAL_TRACKING" | "DISABLE_CONTENT_PAYWALL" | "ENABLE_SUBSCRIPTION_ACCESS";
|
|
8
8
|
type ClientHeaderValue = string | string[] | undefined;
|
|
9
|
-
type
|
|
10
|
-
|
|
9
|
+
type TokenContext = Record<FEATURE_ACTIONS, boolean>;
|
|
10
|
+
type ParseClientTokenOptions = {
|
|
11
|
+
clientId: string;
|
|
12
|
+
features: FEATURES[];
|
|
13
|
+
publicKey?: string;
|
|
14
|
+
};
|
|
15
|
+
declare function parseClientToken(headerValue: ClientHeaderValue, options: ParseClientTokenOptions): TokenContext;
|
|
11
16
|
type DecodedClientHeader = {
|
|
12
17
|
version: PROTOCOL_VERSION;
|
|
13
18
|
expiresAt: Date;
|
|
@@ -28,11 +33,11 @@ type SiteOptions = {
|
|
|
28
33
|
features: FEATURES[];
|
|
29
34
|
};
|
|
30
35
|
declare function Site(options: SiteOptions): {
|
|
31
|
-
parseClientToken: (headerValue: ClientHeaderValue) =>
|
|
32
|
-
CLIENT_HEADER_NAME:
|
|
36
|
+
parseClientToken: (headerValue: ClientHeaderValue) => TokenContext;
|
|
37
|
+
CLIENT_HEADER_NAME: string;
|
|
33
38
|
SERVER_HEADER_NAME: SERVER_HEADERS;
|
|
34
39
|
SERVER_HEADER_VALUE: string;
|
|
35
40
|
};
|
|
36
41
|
|
|
37
|
-
export {
|
|
38
|
-
export type { ClientHeaderValue, DecodedClientHeader,
|
|
42
|
+
export { FEATURES, PROTOCOL_VERSION, SERVER_HEADERS, Site, decodeClientHeader, encodeClientHeader, parseClientToken, setLogLevel };
|
|
43
|
+
export type { ClientHeaderValue, DecodedClientHeader, FEATURE_ACTIONS, ParseClientTokenOptions, TokenContext };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { a as CURRENT_PROTOCOL_VERSION, W as WelcomeHeader, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader, e as encodeServerHeader } from './browser-BiNZ2c6t.mjs';
|
|
1
|
+
import { F as FEATURES, P as PROTOCOL_VERSION, S as SERVER_HEADERS } from './browser-BiNZ2c6t.mjs';
|
|
2
|
+
export { C as CLIENT_HEADERS, a as CURRENT_PROTOCOL_VERSION, W as WelcomeHeader, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader, e as encodeServerHeader } from './browser-BiNZ2c6t.mjs';
|
|
3
3
|
|
|
4
4
|
type LogLevel = "error" | "warn" | "info" | "debug";
|
|
5
5
|
declare function setLogLevel(level: LogLevel): void;
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
type FEATURE_ACTIONS = "HIDE_ADVERTISEMENTS" | "HIDE_COOKIE_CONSENT_SCREEN" | "HIDE_MARKETING_DIALOGS" | "DISABLE_NON_FUNCTIONAL_TRACKING" | "DISABLE_CONTENT_PAYWALL" | "ENABLE_SUBSCRIPTION_ACCESS";
|
|
8
8
|
type ClientHeaderValue = string | string[] | undefined;
|
|
9
|
-
type
|
|
10
|
-
|
|
9
|
+
type TokenContext = Record<FEATURE_ACTIONS, boolean>;
|
|
10
|
+
type ParseClientTokenOptions = {
|
|
11
|
+
clientId: string;
|
|
12
|
+
features: FEATURES[];
|
|
13
|
+
publicKey?: string;
|
|
14
|
+
};
|
|
15
|
+
declare function parseClientToken(headerValue: ClientHeaderValue, options: ParseClientTokenOptions): TokenContext;
|
|
11
16
|
type DecodedClientHeader = {
|
|
12
17
|
version: PROTOCOL_VERSION;
|
|
13
18
|
expiresAt: Date;
|
|
@@ -28,11 +33,11 @@ type SiteOptions = {
|
|
|
28
33
|
features: FEATURES[];
|
|
29
34
|
};
|
|
30
35
|
declare function Site(options: SiteOptions): {
|
|
31
|
-
parseClientToken: (headerValue: ClientHeaderValue) =>
|
|
32
|
-
CLIENT_HEADER_NAME:
|
|
36
|
+
parseClientToken: (headerValue: ClientHeaderValue) => TokenContext;
|
|
37
|
+
CLIENT_HEADER_NAME: string;
|
|
33
38
|
SERVER_HEADER_NAME: SERVER_HEADERS;
|
|
34
39
|
SERVER_HEADER_VALUE: string;
|
|
35
40
|
};
|
|
36
41
|
|
|
37
|
-
export {
|
|
38
|
-
export type { ClientHeaderValue, DecodedClientHeader,
|
|
42
|
+
export { FEATURES, PROTOCOL_VERSION, SERVER_HEADERS, Site, decodeClientHeader, encodeClientHeader, parseClientToken, setLogLevel };
|
|
43
|
+
export type { ClientHeaderValue, DecodedClientHeader, FEATURE_ACTIONS, ParseClientTokenOptions, TokenContext };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as
|
|
2
|
-
export {
|
|
1
|
+
import { F as FEATURES, Z as ZEROAD_NETWORK_PUBLIC_KEY, h as hasFlag, f as fromBase64, P as PROTOCOL_VERSION, l as log, s as setFlags, t as toBase64, e as encodeServerHeader, S as SERVER_HEADERS, C as CLIENT_HEADERS } from './browser-4DOrMTCi.mjs';
|
|
2
|
+
export { b as CURRENT_PROTOCOL_VERSION, d as decodeServerHeader, a as setLogLevel } from './browser-4DOrMTCi.mjs';
|
|
3
3
|
import { Buffer } from 'node:buffer';
|
|
4
4
|
import { verify as verify$1, randomBytes, sign as sign$1, createPublicKey, createPrivateKey } from 'node:crypto';
|
|
5
5
|
|
|
@@ -37,26 +37,29 @@ function importPublicKey(publicKeyBase64) {
|
|
|
37
37
|
const VERSION_BYTES = 1;
|
|
38
38
|
const NONCE_BYTES = 4;
|
|
39
39
|
const SEPARATOR = ".";
|
|
40
|
-
|
|
40
|
+
const FEATURES_TO_ACTIONS = {
|
|
41
|
+
[FEATURES.CLEAN_WEB]: [
|
|
42
|
+
"HIDE_ADVERTISEMENTS",
|
|
43
|
+
"HIDE_COOKIE_CONSENT_SCREEN",
|
|
44
|
+
"HIDE_MARKETING_DIALOGS",
|
|
45
|
+
"DISABLE_NON_FUNCTIONAL_TRACKING"
|
|
46
|
+
],
|
|
47
|
+
[FEATURES.ONE_PASS]: ["DISABLE_CONTENT_PAYWALL", "ENABLE_SUBSCRIPTION_ACCESS"]
|
|
48
|
+
};
|
|
49
|
+
function parseClientToken(headerValue, options) {
|
|
41
50
|
const headerValueAsString = Array.isArray(headerValue) ? headerValue[0] : headerValue;
|
|
42
|
-
const data = decodeClientHeader(headerValueAsString, publicKey);
|
|
51
|
+
const data = decodeClientHeader(headerValueAsString, options.publicKey || ZEROAD_NETWORK_PUBLIC_KEY);
|
|
43
52
|
let flags = 0;
|
|
44
53
|
if (data && data.expiresAt.getTime() >= Date.now()) flags = data.flags;
|
|
45
|
-
if (flags && data?.clientId && data.clientId !== clientId) flags = 0;
|
|
46
|
-
const
|
|
47
|
-
for (const [feature,
|
|
48
|
-
|
|
54
|
+
if (flags && data?.clientId && data.clientId !== options.clientId) flags = 0;
|
|
55
|
+
const context = /* @__PURE__ */ new Map();
|
|
56
|
+
for (const [feature, actionNames] of Object.entries(FEATURES_TO_ACTIONS)) {
|
|
57
|
+
const decision = options.features.includes(Number(feature)) && hasFlag(Number(feature), flags);
|
|
58
|
+
for (const actionName of actionNames) {
|
|
59
|
+
context.set(actionName, decision);
|
|
60
|
+
}
|
|
49
61
|
}
|
|
50
|
-
|
|
51
|
-
const hasOnePass = features.includes("ONE_PASS");
|
|
52
|
-
return {
|
|
53
|
-
HIDE_ADVERTISEMENTS: hasCleanWeb,
|
|
54
|
-
HIDE_COOKIE_CONSENT_SCREEN: hasCleanWeb,
|
|
55
|
-
HIDE_MARKETING_DIALOGS: hasCleanWeb,
|
|
56
|
-
DISABLE_NON_FUNCTIONAL_TRACKING: hasCleanWeb,
|
|
57
|
-
DISABLE_CONTENT_PAYWALL: hasOnePass,
|
|
58
|
-
ENABLE_SUBSCRIPTION_ACCESS: hasOnePass
|
|
59
|
-
};
|
|
62
|
+
return Object.fromEntries(context);
|
|
60
63
|
}
|
|
61
64
|
function decodeClientHeader(headerValue, publicKey) {
|
|
62
65
|
if (!headerValue?.length) return;
|
|
@@ -115,11 +118,11 @@ function as32BitNumber(byteArray, begin) {
|
|
|
115
118
|
function Site(options) {
|
|
116
119
|
const serverHeaderValue = encodeServerHeader(options.clientId, options.features);
|
|
117
120
|
return {
|
|
118
|
-
parseClientToken: (headerValue) => parseClientToken(headerValue, options.clientId,
|
|
119
|
-
CLIENT_HEADER_NAME: CLIENT_HEADERS.HELLO,
|
|
121
|
+
parseClientToken: (headerValue) => parseClientToken(headerValue, { clientId: options.clientId, features: options.features }),
|
|
122
|
+
CLIENT_HEADER_NAME: CLIENT_HEADERS.HELLO.toLowerCase(),
|
|
120
123
|
SERVER_HEADER_NAME: SERVER_HEADERS.WELCOME,
|
|
121
124
|
SERVER_HEADER_VALUE: serverHeaderValue
|
|
122
125
|
};
|
|
123
126
|
}
|
|
124
127
|
|
|
125
|
-
export { CLIENT_HEADERS, PROTOCOL_VERSION, SERVER_HEADERS, Site, ZEROAD_NETWORK_PUBLIC_KEY, decodeClientHeader, encodeClientHeader, encodeServerHeader, parseClientToken };
|
|
128
|
+
export { CLIENT_HEADERS, FEATURES, PROTOCOL_VERSION, SERVER_HEADERS, Site, ZEROAD_NETWORK_PUBLIC_KEY, decodeClientHeader, encodeClientHeader, encodeServerHeader, parseClientToken };
|