@zeroad.network/token 0.13.8 → 0.13.10

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.
@@ -38,12 +38,18 @@ var PROTOCOL_VERSION = /* @__PURE__ */ ((PROTOCOL_VERSION2) => {
38
38
  })(PROTOCOL_VERSION || {});
39
39
  const CURRENT_PROTOCOL_VERSION = 1 /* V_1 */;
40
40
 
41
- let SITE_FEATURES_NATIVE$1;
42
- const getSiteFeaturesNative = () => {
43
- if (SITE_FEATURES_NATIVE$1?.length) return SITE_FEATURES_NATIVE$1;
44
- return SITE_FEATURES_NATIVE$1 = Object.entries(FEATURES).filter(([key]) => isNaN(Number(key)));
45
- };
46
- const toBase64 = (data) => {
41
+ let cachedFeatures;
42
+ function FEATURE_MAP() {
43
+ if (cachedFeatures) return cachedFeatures;
44
+ cachedFeatures = /* @__PURE__ */ new Map();
45
+ for (const key of Object.keys(FEATURES)) {
46
+ if (!isNaN(Number(key))) continue;
47
+ const typedKey = key;
48
+ cachedFeatures.set(typedKey, FEATURES[typedKey]);
49
+ }
50
+ return cachedFeatures;
51
+ }
52
+ function toBase64(data) {
47
53
  if (typeof data.toBase64 === "function") return data.toBase64();
48
54
  if (typeof Buffer !== "undefined") return Buffer.from(data).toString("base64");
49
55
  if (typeof btoa === "function") {
@@ -54,8 +60,8 @@ const toBase64 = (data) => {
54
60
  return btoa(binary);
55
61
  }
56
62
  throw new Error("Base64 encoding not supported in this environment");
57
- };
58
- const fromBase64 = (input) => {
63
+ }
64
+ function fromBase64(input) {
59
65
  if (typeof Uint8Array.fromBase64 === "function") return Uint8Array.fromBase64(input);
60
66
  if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(input, "base64"));
61
67
  if (typeof atob === "function") {
@@ -67,15 +73,14 @@ const fromBase64 = (input) => {
67
73
  return bytes;
68
74
  }
69
75
  throw new Error("Base64 decoding not supported in this environment");
70
- };
71
- const assert = (value, message) => {
76
+ }
77
+ function assert(value, message) {
72
78
  if (!value) throw new Error(message);
73
- };
74
- const hasFlag = (flag, flags) => Boolean(flag & flags);
79
+ }
80
+ const hasFlag = (bit, flags) => Boolean(bit & flags);
75
81
  const setFlags = (features = []) => features.reduce((acc, feature) => acc | feature, 0);
76
82
 
77
83
  const SEPARATOR = "^";
78
- const SITE_FEATURES_NATIVE = getSiteFeaturesNative();
79
84
  const validFeatureValues = Object.values(FEATURES).filter((key) => !isNaN(Number(key)));
80
85
  const validFeatureKeys = Object.values(FEATURES).filter((key) => isNaN(Number(key)));
81
86
  function encodeServerHeader(clientId, features) {
@@ -101,9 +106,9 @@ function decodeServerHeader(headerValue) {
101
106
  "Invalid or unsupported protocol version"
102
107
  );
103
108
  assert(Number(flags).toFixed(0).toString() === flags, "Invalid flags number");
104
- let features = [];
105
- for (const [feature, shift] of SITE_FEATURES_NATIVE) {
106
- if (hasFlag(Number(flags), shift)) features.push(feature);
109
+ const features = [];
110
+ for (const [feature, bit] of FEATURE_MAP()) {
111
+ if (hasFlag(Number(flags), bit)) features.push(feature);
107
112
  }
108
113
  return {
109
114
  version: Number(protocolVersion),
@@ -118,13 +123,13 @@ function decodeServerHeader(headerValue) {
118
123
  exports.CLIENT_HEADERS = CLIENT_HEADERS;
119
124
  exports.CURRENT_PROTOCOL_VERSION = CURRENT_PROTOCOL_VERSION;
120
125
  exports.FEATURES = FEATURES;
126
+ exports.FEATURE_MAP = FEATURE_MAP;
121
127
  exports.PROTOCOL_VERSION = PROTOCOL_VERSION;
122
128
  exports.SERVER_HEADERS = SERVER_HEADERS;
123
129
  exports.ZEROAD_NETWORK_PUBLIC_KEY = ZEROAD_NETWORK_PUBLIC_KEY;
124
130
  exports.decodeServerHeader = decodeServerHeader;
125
131
  exports.encodeServerHeader = encodeServerHeader;
126
132
  exports.fromBase64 = fromBase64;
127
- exports.getSiteFeaturesNative = getSiteFeaturesNative;
128
133
  exports.hasFlag = hasFlag;
129
134
  exports.log = log;
130
135
  exports.setFlags = setFlags;
@@ -36,12 +36,18 @@ var PROTOCOL_VERSION = /* @__PURE__ */ ((PROTOCOL_VERSION2) => {
36
36
  })(PROTOCOL_VERSION || {});
37
37
  const CURRENT_PROTOCOL_VERSION = 1 /* V_1 */;
38
38
 
39
- let SITE_FEATURES_NATIVE$1;
40
- const getSiteFeaturesNative = () => {
41
- if (SITE_FEATURES_NATIVE$1?.length) return SITE_FEATURES_NATIVE$1;
42
- return SITE_FEATURES_NATIVE$1 = Object.entries(FEATURES).filter(([key]) => isNaN(Number(key)));
43
- };
44
- const toBase64 = (data) => {
39
+ let cachedFeatures;
40
+ function FEATURE_MAP() {
41
+ if (cachedFeatures) return cachedFeatures;
42
+ cachedFeatures = /* @__PURE__ */ new Map();
43
+ for (const key of Object.keys(FEATURES)) {
44
+ if (!isNaN(Number(key))) continue;
45
+ const typedKey = key;
46
+ cachedFeatures.set(typedKey, FEATURES[typedKey]);
47
+ }
48
+ return cachedFeatures;
49
+ }
50
+ function toBase64(data) {
45
51
  if (typeof data.toBase64 === "function") return data.toBase64();
46
52
  if (typeof Buffer !== "undefined") return Buffer.from(data).toString("base64");
47
53
  if (typeof btoa === "function") {
@@ -52,8 +58,8 @@ const toBase64 = (data) => {
52
58
  return btoa(binary);
53
59
  }
54
60
  throw new Error("Base64 encoding not supported in this environment");
55
- };
56
- const fromBase64 = (input) => {
61
+ }
62
+ function fromBase64(input) {
57
63
  if (typeof Uint8Array.fromBase64 === "function") return Uint8Array.fromBase64(input);
58
64
  if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(input, "base64"));
59
65
  if (typeof atob === "function") {
@@ -65,15 +71,14 @@ const fromBase64 = (input) => {
65
71
  return bytes;
66
72
  }
67
73
  throw new Error("Base64 decoding not supported in this environment");
68
- };
69
- const assert = (value, message) => {
74
+ }
75
+ function assert(value, message) {
70
76
  if (!value) throw new Error(message);
71
- };
72
- const hasFlag = (flag, flags) => Boolean(flag & flags);
77
+ }
78
+ const hasFlag = (bit, flags) => Boolean(bit & flags);
73
79
  const setFlags = (features = []) => features.reduce((acc, feature) => acc | feature, 0);
74
80
 
75
81
  const SEPARATOR = "^";
76
- const SITE_FEATURES_NATIVE = getSiteFeaturesNative();
77
82
  const validFeatureValues = Object.values(FEATURES).filter((key) => !isNaN(Number(key)));
78
83
  const validFeatureKeys = Object.values(FEATURES).filter((key) => isNaN(Number(key)));
79
84
  function encodeServerHeader(clientId, features) {
@@ -99,9 +104,9 @@ function decodeServerHeader(headerValue) {
99
104
  "Invalid or unsupported protocol version"
100
105
  );
101
106
  assert(Number(flags).toFixed(0).toString() === flags, "Invalid flags number");
102
- let features = [];
103
- for (const [feature, shift] of SITE_FEATURES_NATIVE) {
104
- if (hasFlag(Number(flags), shift)) features.push(feature);
107
+ const features = [];
108
+ for (const [feature, bit] of FEATURE_MAP()) {
109
+ if (hasFlag(Number(flags), bit)) features.push(feature);
105
110
  }
106
111
  return {
107
112
  version: Number(protocolVersion),
@@ -113,4 +118,4 @@ function decodeServerHeader(headerValue) {
113
118
  }
114
119
  }
115
120
 
116
- 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, getSiteFeaturesNative as g, hasFlag as h, log as l, setFlags as s, toBase64 as t };
121
+ export { CLIENT_HEADERS as C, FEATURE_MAP as F, PROTOCOL_VERSION as P, SERVER_HEADERS as S, ZEROAD_NETWORK_PUBLIC_KEY as Z, setLogLevel as a, FEATURES as b, CURRENT_PROTOCOL_VERSION as c, decodeServerHeader as d, encodeServerHeader as e, fromBase64 as f, hasFlag as h, log as l, setFlags as s, toBase64 as t };
@@ -1 +1 @@
1
- export { C as CLIENT_HEADERS, a 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-BiNZ2c6t.mjs';
1
+ export { C as CLIENT_HEADERS, a as CURRENT_PROTOCOL_VERSION, F as FEATURES, P as PROTOCOL_VERSION, S as SERVER_HEADERS, W as WelcomeHeader, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader } from './browser-BiNZ2c6t.mjs';
package/dist/browser.mjs CHANGED
@@ -1 +1 @@
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-Citg0bh9.mjs';
1
+ export { C as CLIENT_HEADERS, c as CURRENT_PROTOCOL_VERSION, b as FEATURES, P as PROTOCOL_VERSION, S as SERVER_HEADERS, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader } from './browser-Bx6W_oKL.mjs';
package/dist/index.cjs CHANGED
@@ -1,11 +1,20 @@
1
1
  'use strict';
2
2
 
3
- var browser = require('./browser-CMCq-bkd.cjs');
3
+ var browser = require('./browser-B9BhMU2_.cjs');
4
4
  var node_buffer = require('node:buffer');
5
5
  var node_crypto = require('node:crypto');
6
6
 
7
7
  const keyCache = /* @__PURE__ */ new Map();
8
- const importPrivateKey = (privateKeyBase64) => {
8
+ function sign(data, privateKey) {
9
+ const key = importPrivateKey(privateKey);
10
+ return node_crypto.sign(null, node_buffer.Buffer.from(data), key);
11
+ }
12
+ function verify(data, signature, publicKey) {
13
+ const key = importPublicKey(publicKey);
14
+ return node_crypto.verify(null, node_buffer.Buffer.from(data), key, node_buffer.Buffer.from(signature));
15
+ }
16
+ const nonce = (size) => new Uint8Array(node_crypto.randomBytes(size));
17
+ function importPrivateKey(privateKeyBase64) {
9
18
  if (keyCache.has(privateKeyBase64)) return keyCache.get(privateKeyBase64);
10
19
  const key = node_crypto.createPrivateKey({
11
20
  key: node_buffer.Buffer.from(privateKeyBase64, "base64"),
@@ -14,8 +23,8 @@ const importPrivateKey = (privateKeyBase64) => {
14
23
  });
15
24
  keyCache.set(privateKeyBase64, key);
16
25
  return key;
17
- };
18
- const importPublicKey = (publicKeyBase64) => {
26
+ }
27
+ function importPublicKey(publicKeyBase64) {
19
28
  if (keyCache.has(publicKeyBase64)) return keyCache.get(publicKeyBase64);
20
29
  const key = node_crypto.createPublicKey({
21
30
  key: node_buffer.Buffer.from(publicKeyBase64, "base64"),
@@ -24,28 +33,21 @@ const importPublicKey = (publicKeyBase64) => {
24
33
  });
25
34
  keyCache.set(publicKeyBase64, key);
26
35
  return key;
27
- };
28
- const sign = (data, privateKey) => {
29
- const key = importPrivateKey(privateKey);
30
- return node_crypto.sign(null, node_buffer.Buffer.from(data), key);
31
- };
32
- const verify = (data, signature, publicKey) => {
33
- const key = importPublicKey(publicKey);
34
- return node_crypto.verify(null, node_buffer.Buffer.from(data), key, node_buffer.Buffer.from(signature));
35
- };
36
- const nonce = (size) => new Uint8Array(node_crypto.randomBytes(size));
36
+ }
37
37
 
38
38
  const VERSION_BYTES = 1;
39
39
  const NONCE_BYTES = 4;
40
40
  const SEPARATOR = ".";
41
- const SITE_FEATURES_NATIVE = browser.getSiteFeaturesNative();
42
41
  function parseClientToken(headerValue, clientId, publicKey) {
43
42
  const headerValueAsString = Array.isArray(headerValue) ? headerValue[0] : headerValue;
44
43
  const data = decodeClientHeader(headerValueAsString, publicKey);
45
44
  let flags = 0;
46
45
  if (data && data.expiresAt.getTime() >= Date.now()) flags = data.flags;
47
46
  if (flags && data?.clientId && data.clientId !== clientId) flags = 0;
48
- const features = SITE_FEATURES_NATIVE.map(([feature, shift]) => browser.hasFlag(flags, shift) && feature).filter((e) => !!e);
47
+ const features = [];
48
+ for (const [feature, bit] of browser.FEATURE_MAP()) {
49
+ if (browser.hasFlag(Number(flags), bit)) features.push(feature);
50
+ }
49
51
  const hasCleanWeb = features.includes("CLEAN_WEB");
50
52
  const hasOnePass = features.includes("ONE_PASS");
51
53
  return {
package/dist/index.mjs CHANGED
@@ -1,10 +1,19 @@
1
- import { g as getSiteFeaturesNative, 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, Z as ZEROAD_NETWORK_PUBLIC_KEY } from './browser-Citg0bh9.mjs';
2
- export { b as CURRENT_PROTOCOL_VERSION, F as FEATURES, d as decodeServerHeader, a as setLogLevel } from './browser-Citg0bh9.mjs';
1
+ import { F as FEATURE_MAP, f as fromBase64, P as PROTOCOL_VERSION, l as log, s as setFlags, t as toBase64, h as hasFlag, e as encodeServerHeader, S as SERVER_HEADERS, C as CLIENT_HEADERS, Z as ZEROAD_NETWORK_PUBLIC_KEY } from './browser-Bx6W_oKL.mjs';
2
+ export { c as CURRENT_PROTOCOL_VERSION, b as FEATURES, d as decodeServerHeader, a as setLogLevel } from './browser-Bx6W_oKL.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
 
6
6
  const keyCache = /* @__PURE__ */ new Map();
7
- const importPrivateKey = (privateKeyBase64) => {
7
+ function sign(data, privateKey) {
8
+ const key = importPrivateKey(privateKey);
9
+ return sign$1(null, Buffer.from(data), key);
10
+ }
11
+ function verify(data, signature, publicKey) {
12
+ const key = importPublicKey(publicKey);
13
+ return verify$1(null, Buffer.from(data), key, Buffer.from(signature));
14
+ }
15
+ const nonce = (size) => new Uint8Array(randomBytes(size));
16
+ function importPrivateKey(privateKeyBase64) {
8
17
  if (keyCache.has(privateKeyBase64)) return keyCache.get(privateKeyBase64);
9
18
  const key = createPrivateKey({
10
19
  key: Buffer.from(privateKeyBase64, "base64"),
@@ -13,8 +22,8 @@ const importPrivateKey = (privateKeyBase64) => {
13
22
  });
14
23
  keyCache.set(privateKeyBase64, key);
15
24
  return key;
16
- };
17
- const importPublicKey = (publicKeyBase64) => {
25
+ }
26
+ function importPublicKey(publicKeyBase64) {
18
27
  if (keyCache.has(publicKeyBase64)) return keyCache.get(publicKeyBase64);
19
28
  const key = createPublicKey({
20
29
  key: Buffer.from(publicKeyBase64, "base64"),
@@ -23,28 +32,21 @@ const importPublicKey = (publicKeyBase64) => {
23
32
  });
24
33
  keyCache.set(publicKeyBase64, key);
25
34
  return key;
26
- };
27
- const sign = (data, privateKey) => {
28
- const key = importPrivateKey(privateKey);
29
- return sign$1(null, Buffer.from(data), key);
30
- };
31
- const verify = (data, signature, publicKey) => {
32
- const key = importPublicKey(publicKey);
33
- return verify$1(null, Buffer.from(data), key, Buffer.from(signature));
34
- };
35
- const nonce = (size) => new Uint8Array(randomBytes(size));
35
+ }
36
36
 
37
37
  const VERSION_BYTES = 1;
38
38
  const NONCE_BYTES = 4;
39
39
  const SEPARATOR = ".";
40
- const SITE_FEATURES_NATIVE = getSiteFeaturesNative();
41
40
  function parseClientToken(headerValue, clientId, publicKey) {
42
41
  const headerValueAsString = Array.isArray(headerValue) ? headerValue[0] : headerValue;
43
42
  const data = decodeClientHeader(headerValueAsString, publicKey);
44
43
  let flags = 0;
45
44
  if (data && data.expiresAt.getTime() >= Date.now()) flags = data.flags;
46
45
  if (flags && data?.clientId && data.clientId !== clientId) flags = 0;
47
- const features = SITE_FEATURES_NATIVE.map(([feature, shift]) => hasFlag(flags, shift) && feature).filter((e) => !!e);
46
+ const features = [];
47
+ for (const [feature, bit] of FEATURE_MAP()) {
48
+ if (hasFlag(Number(flags), bit)) features.push(feature);
49
+ }
48
50
  const hasCleanWeb = features.includes("CLEAN_WEB");
49
51
  const hasOnePass = features.includes("ONE_PASS");
50
52
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeroad.network/token",
3
- "version": "0.13.8",
3
+ "version": "0.13.10",
4
4
  "license": "Apache-2.0",
5
5
  "repository": "github:laurynas-karvelis/zeroad-token-typescript",
6
6
  "homepage": "https://zeroad.network",
@@ -44,8 +44,9 @@
44
44
  "hono"
45
45
  ],
46
46
  "engines": {
47
- "node": ">= 18.0.0",
48
- "bun": ">=1.2.6"
47
+ "node": ">=16.0.0",
48
+ "bun": ">=1.1.0",
49
+ "deno": ">=2.0.0"
49
50
  },
50
51
  "main": "./dist/index.cjs",
51
52
  "module": "./dist/index.mjs",
@@ -74,8 +75,8 @@
74
75
  },
75
76
  "dependencies": {},
76
77
  "devDependencies": {
77
- "@types/bun": "^1.3.3",
78
- "@types/node": "^24.10.0",
78
+ "@types/bun": "^1.3.4",
79
+ "@types/node": "^24.10.2",
79
80
  "pkgroll": "^2.21.4",
80
81
  "prettier": "^3.7.4",
81
82
  "typescript": "^5.9.3"