licenx 0.0.0-stage → 1.0.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/CHANGELOG.md +4 -0
- package/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/THIRD_PARTY_NOTICES.txt +15918 -0
- package/dist/background.d.ts +2 -0
- package/dist/background.js +67 -0
- package/dist/build-info.json +8 -0
- package/dist/client.d.ts +37 -0
- package/dist/client.js +322 -0
- package/dist/identity.d.ts +4 -0
- package/dist/identity.js +35 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/messaging.d.ts +11 -0
- package/dist/messaging.js +17 -0
- package/dist/session.d.ts +6 -0
- package/dist/session.js +10 -0
- package/dist/storage.d.ts +14 -0
- package/dist/storage.js +58 -0
- package/dist/transport.d.ts +23 -0
- package/dist/transport.js +98 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +26 -0
- package/dist/wasm/licenx_wasm.d.ts +77 -0
- package/dist/wasm/licenx_wasm.js +672 -0
- package/dist/wasm/licenx_wasm_bg.wasm +0 -0
- package/dist/wasm/licenx_wasm_bg.wasm.d.ts +28 -0
- package/dist/wasm-loader.d.ts +3 -0
- package/dist/wasm-loader.js +14 -0
- package/docs/API_REFERENCE.md +21 -0
- package/docs/BUILD_AND_RELEASE.md +9 -0
- package/docs/COMPATIBILITY.md +7 -0
- package/docs/CONFIGURATION.md +17 -0
- package/docs/GUIDE_BN.md +19 -0
- package/docs/GUIDE_EN.md +19 -0
- package/docs/INTEGRATION_EXAMPLES.md +19 -0
- package/docs/LIFECYCLE.md +7 -0
- package/docs/QUICK_START.md +14 -0
- package/docs/README.md +5 -0
- package/docs/SECURITY.md +7 -0
- package/docs/TROUBLESHOOTING.md +19 -0
- package/examples/chrome/background.js +4 -0
- package/examples/chrome/manifest.json +23 -0
- package/examples/chrome/popup.html +4 -0
- package/examples/chrome/popup.js +12 -0
- package/examples/firefox/background.js +4 -0
- package/examples/firefox/manifest.json +36 -0
- package/examples/firefox/popup.html +4 -0
- package/examples/firefox/popup.js +12 -0
- package/licenx.config.example.json +10 -0
- package/package.json +41 -4
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { LicenXError } from "./types.js";
|
|
2
|
+
export const PATHS = { validate: "/api/v1/license/validate", ping: "/api/v1/license/ping", logout: "/api/v2/license/logout", stats: "/api/v1/device/stats" };
|
|
3
|
+
const LIMIT = 64 * 1024;
|
|
4
|
+
export function normalizedConfig(input) {
|
|
5
|
+
if (!input || typeof input.server_url !== "string")
|
|
6
|
+
throw new LicenXError("CONFIG_INVALID");
|
|
7
|
+
if (input.useWebSocket === true)
|
|
8
|
+
throw new LicenXError("UNSUPPORTED_TRANSPORT");
|
|
9
|
+
try {
|
|
10
|
+
const u = new URL(input.server_url.trim().replace(/\/+$/, "").replace(/\/api$/, ""));
|
|
11
|
+
if (u.protocol !== "https:" || u.username || u.password || u.search || u.hash || u.pathname !== "/" || !u.hostname)
|
|
12
|
+
throw new Error();
|
|
13
|
+
if (typeof input.app_name !== "string" || typeof input.app_version !== "string")
|
|
14
|
+
throw new Error();
|
|
15
|
+
return { ...input, server_url: u.origin, app_name: input.app_name.trim(), app_version: input.app_version.trim() };
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
throw new LicenXError("CONFIG_INVALID");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class Transport {
|
|
22
|
+
config;
|
|
23
|
+
api;
|
|
24
|
+
origin;
|
|
25
|
+
permission;
|
|
26
|
+
constructor(config, api) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
this.api = api;
|
|
29
|
+
const u = new URL(config.server_url);
|
|
30
|
+
this.origin = u.origin;
|
|
31
|
+
// Match patterns scope host; Fetch additionally pins exact scheme/port/origin.
|
|
32
|
+
this.permission = "https://" + u.hostname + "/*";
|
|
33
|
+
}
|
|
34
|
+
async requirePermission() {
|
|
35
|
+
try {
|
|
36
|
+
if (await this.api.permissions.contains({ origins: [this.permission] }))
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
catch { }
|
|
40
|
+
throw new LicenXError("PERMISSION_DENIED");
|
|
41
|
+
}
|
|
42
|
+
async post(path, body, bearer) {
|
|
43
|
+
if (!Object.values(PATHS).includes(path))
|
|
44
|
+
throw new LicenXError("CONFIG_INVALID");
|
|
45
|
+
await this.requirePermission();
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const seconds = this.config.request_timeout_seconds ?? 10;
|
|
48
|
+
const timer = setTimeout(() => controller.abort(), 1000 * (path === PATHS.ping ? Math.min(seconds, 20) : seconds));
|
|
49
|
+
try {
|
|
50
|
+
const headers = { "Content-Type": "application/json" };
|
|
51
|
+
if (bearer)
|
|
52
|
+
headers.Authorization = "Bearer " + bearer;
|
|
53
|
+
const response = await fetch(this.origin + path, { method: "POST", headers, body, signal: controller.signal,
|
|
54
|
+
credentials: "omit", redirect: "error", cache: "no-store", referrerPolicy: "no-referrer" });
|
|
55
|
+
if (response.redirected || response.url !== this.origin + path)
|
|
56
|
+
throw new LicenXError("INVALID_RESPONSE");
|
|
57
|
+
if (Number(response.headers.get("content-length")) > LIMIT)
|
|
58
|
+
throw new LicenXError("INVALID_RESPONSE");
|
|
59
|
+
const reader = response.body?.getReader();
|
|
60
|
+
const parts = [];
|
|
61
|
+
let length = 0;
|
|
62
|
+
if (reader)
|
|
63
|
+
try {
|
|
64
|
+
for (;;) {
|
|
65
|
+
const next = await reader.read();
|
|
66
|
+
if (next.done)
|
|
67
|
+
break;
|
|
68
|
+
length += next.value.length;
|
|
69
|
+
if (length > LIMIT) {
|
|
70
|
+
await reader.cancel();
|
|
71
|
+
throw new LicenXError("INVALID_RESPONSE");
|
|
72
|
+
}
|
|
73
|
+
parts.push(next.value);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
reader.releaseLock();
|
|
78
|
+
}
|
|
79
|
+
const bytes = new Uint8Array(length);
|
|
80
|
+
let offset = 0;
|
|
81
|
+
for (const p of parts) {
|
|
82
|
+
bytes.set(p, offset);
|
|
83
|
+
offset += p.length;
|
|
84
|
+
}
|
|
85
|
+
await this.requirePermission();
|
|
86
|
+
return { status: response.status, body: bytes };
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
if (e instanceof LicenXError)
|
|
90
|
+
throw e;
|
|
91
|
+
// Browser Fetch cannot reliably distinguish network/CORS/TLS. No grace on ambiguity.
|
|
92
|
+
throw new LicenXError(controller.signal.aborted ? "TIMEOUT" : "TLS_OR_TRANSPORT_UNVERIFIED");
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
server_url: string;
|
|
3
|
+
public_key_pem: string;
|
|
4
|
+
app_name: string;
|
|
5
|
+
app_version: string;
|
|
6
|
+
ping_interval_seconds?: number;
|
|
7
|
+
offline_grace_seconds?: number;
|
|
8
|
+
request_timeout_seconds?: number;
|
|
9
|
+
useWebSocket?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface Options {
|
|
12
|
+
retainSession?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export type State = "LoggedOut" | "Online" | "HttpFallback" | "OfflineGrace" | "PausedUnverified";
|
|
15
|
+
export interface Status {
|
|
16
|
+
authorized: boolean;
|
|
17
|
+
hasLoginSession: boolean;
|
|
18
|
+
state: State;
|
|
19
|
+
tier: string | null;
|
|
20
|
+
pendingRelease: boolean;
|
|
21
|
+
}
|
|
22
|
+
export type LogoutOutcome = "Released" | "AlreadyLoggedOut" | "RemoteUnconfirmed";
|
|
23
|
+
export type StatValue = string | number | boolean | null;
|
|
24
|
+
export type Stats = Record<string, StatValue>;
|
|
25
|
+
export interface StorageArea {
|
|
26
|
+
get(key: string): Promise<Record<string, unknown>>;
|
|
27
|
+
set(items: Record<string, unknown>): Promise<void>;
|
|
28
|
+
remove(key: string): Promise<void>;
|
|
29
|
+
setAccessLevel?(details: {
|
|
30
|
+
accessLevel: "TRUSTED_CONTEXTS";
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
type Listener<T extends unknown[]> = {
|
|
34
|
+
addListener(fn: (...args: T) => unknown): void;
|
|
35
|
+
};
|
|
36
|
+
export interface Sender {
|
|
37
|
+
id?: string;
|
|
38
|
+
url?: string;
|
|
39
|
+
origin?: string;
|
|
40
|
+
tab?: unknown;
|
|
41
|
+
}
|
|
42
|
+
export interface ExtensionApi {
|
|
43
|
+
storage: {
|
|
44
|
+
local: StorageArea;
|
|
45
|
+
session?: StorageArea;
|
|
46
|
+
};
|
|
47
|
+
permissions: {
|
|
48
|
+
contains(p: {
|
|
49
|
+
origins: string[];
|
|
50
|
+
}): Promise<boolean>;
|
|
51
|
+
onRemoved: Listener<[unknown]>;
|
|
52
|
+
onAdded?: Listener<[unknown]>;
|
|
53
|
+
};
|
|
54
|
+
runtime: {
|
|
55
|
+
id: string;
|
|
56
|
+
getURL(path: string): string;
|
|
57
|
+
onMessage: Listener<[unknown, Sender, (reply: unknown) => void]>;
|
|
58
|
+
onStartup: Listener<[]>;
|
|
59
|
+
onInstalled: Listener<[unknown]>;
|
|
60
|
+
};
|
|
61
|
+
alarms: {
|
|
62
|
+
get?(name: string): Promise<{
|
|
63
|
+
name: string;
|
|
64
|
+
periodInMinutes?: number;
|
|
65
|
+
} | undefined>;
|
|
66
|
+
create(name: string, info: {
|
|
67
|
+
periodInMinutes?: number;
|
|
68
|
+
delayInMinutes?: number;
|
|
69
|
+
}): void | Promise<void>;
|
|
70
|
+
onAlarm: Listener<[{
|
|
71
|
+
name: string;
|
|
72
|
+
}]>;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export declare function extensionApi(): ExtensionApi;
|
|
76
|
+
export declare const CODES: readonly ["CONFIG_INVALID", "IDENTITY_UNAVAILABLE", "INVALID_RESPONSE", "SIGNATURE_FAILED", "VALIDATION_BINDING_FAILED", "AUTH_REJECTED", "DENIAL_UNVERIFIED", "LICENSE_TERMINATED", "TIMEOUT", "SERVER_UNREACHABLE", "TLS_OR_TRANSPORT_UNVERIFIED", "SERVICE_UNAVAILABLE", "RATE_LIMITED", "NOT_AUTHORIZED", "SESSION_CHANGED", "PREVIOUS_SESSION_LOGOUT_FAILED", "INVALID_LOGOUT_PROOF", "INVALID_STATS", "STATS_UNAVAILABLE", "RANDOM_UNAVAILABLE", "UNSUPPORTED_TRANSPORT", "STORAGE_UNAVAILABLE", "PERMISSION_DENIED", "INITIALIZATION_FAILED", "MESSAGE_DENIED"];
|
|
77
|
+
export type ErrorCode = typeof CODES[number];
|
|
78
|
+
export declare function code(error: unknown, fallback?: ErrorCode): ErrorCode;
|
|
79
|
+
export declare class LicenXError extends Error {
|
|
80
|
+
readonly code: ErrorCode;
|
|
81
|
+
constructor(code: ErrorCode);
|
|
82
|
+
}
|
|
83
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function extensionApi() {
|
|
2
|
+
const g = globalThis;
|
|
3
|
+
const api = g.browser ?? g.chrome;
|
|
4
|
+
if (!api?.storage?.local || !api.permissions || !api.runtime || !api.alarms)
|
|
5
|
+
throw new Error("INITIALIZATION_FAILED");
|
|
6
|
+
return api;
|
|
7
|
+
}
|
|
8
|
+
export const CODES = [
|
|
9
|
+
"CONFIG_INVALID", "IDENTITY_UNAVAILABLE", "INVALID_RESPONSE", "SIGNATURE_FAILED", "VALIDATION_BINDING_FAILED",
|
|
10
|
+
"AUTH_REJECTED", "DENIAL_UNVERIFIED", "LICENSE_TERMINATED", "TIMEOUT", "SERVER_UNREACHABLE", "TLS_OR_TRANSPORT_UNVERIFIED",
|
|
11
|
+
"SERVICE_UNAVAILABLE", "RATE_LIMITED", "NOT_AUTHORIZED", "SESSION_CHANGED", "PREVIOUS_SESSION_LOGOUT_FAILED", "INVALID_LOGOUT_PROOF",
|
|
12
|
+
"INVALID_STATS", "STATS_UNAVAILABLE", "RANDOM_UNAVAILABLE", "UNSUPPORTED_TRANSPORT", "STORAGE_UNAVAILABLE", "PERMISSION_DENIED",
|
|
13
|
+
"INITIALIZATION_FAILED", "MESSAGE_DENIED"
|
|
14
|
+
];
|
|
15
|
+
export function code(error, fallback = "INVALID_RESPONSE") {
|
|
16
|
+
const value = typeof error === "string" ? error : error instanceof Error ? error.message : "";
|
|
17
|
+
return CODES.includes(value) ? value : fallback;
|
|
18
|
+
}
|
|
19
|
+
export class LicenXError extends Error {
|
|
20
|
+
code;
|
|
21
|
+
constructor(code) {
|
|
22
|
+
super(code);
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.name = "LicenXError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class Bridge {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
active_proof(): string | undefined;
|
|
8
|
+
candidate_proof(): string | undefined;
|
|
9
|
+
clear(): void;
|
|
10
|
+
commit_login(t: number): void;
|
|
11
|
+
discard_candidate(): void;
|
|
12
|
+
failed(code: string, t: number): void;
|
|
13
|
+
heartbeat(key: string, nonce: string, status: number, raw: Uint8Array | number[], t: number): void;
|
|
14
|
+
constructor(config: string, hwid: string);
|
|
15
|
+
pause(): void;
|
|
16
|
+
ping_body(key: string, nonce: string): string;
|
|
17
|
+
refresh_proof(key: string, nonce: string, status: number, raw: Uint8Array | number[]): string | undefined;
|
|
18
|
+
release_ok(status: number, raw: Uint8Array | number[]): boolean;
|
|
19
|
+
stage_login(key: string, nonce: string, raw: Uint8Array | number[]): void;
|
|
20
|
+
stats_body(raw: string): string;
|
|
21
|
+
stats_capability(key: string, nonce: string, raw: Uint8Array | number[]): string;
|
|
22
|
+
status(t: number): string;
|
|
23
|
+
validation_body(key: string, nonce: string, stats: boolean): string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
27
|
+
|
|
28
|
+
export interface InitOutput {
|
|
29
|
+
readonly memory: WebAssembly.Memory;
|
|
30
|
+
readonly __wbg_bridge_free: (a: number, b: number) => void;
|
|
31
|
+
readonly bridge_active_proof: (a: number, b: number) => void;
|
|
32
|
+
readonly bridge_candidate_proof: (a: number, b: number) => void;
|
|
33
|
+
readonly bridge_clear: (a: number) => void;
|
|
34
|
+
readonly bridge_commit_login: (a: number, b: number, c: number) => void;
|
|
35
|
+
readonly bridge_discard_candidate: (a: number) => void;
|
|
36
|
+
readonly bridge_failed: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
37
|
+
readonly bridge_heartbeat: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
|
|
38
|
+
readonly bridge_new: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
39
|
+
readonly bridge_pause: (a: number) => void;
|
|
40
|
+
readonly bridge_ping_body: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
41
|
+
readonly bridge_refresh_proof: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
42
|
+
readonly bridge_release_ok: (a: number, b: number, c: number, d: number) => number;
|
|
43
|
+
readonly bridge_stage_login: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
44
|
+
readonly bridge_stats_body: (a: number, b: number, c: number, d: number) => void;
|
|
45
|
+
readonly bridge_stats_capability: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
46
|
+
readonly bridge_status: (a: number, b: number, c: number) => void;
|
|
47
|
+
readonly bridge_validation_body: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
48
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
49
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
50
|
+
readonly __wbindgen_export: (a: number, b: number, c: number) => void;
|
|
51
|
+
readonly __wbindgen_export2: (a: number) => void;
|
|
52
|
+
readonly __wbindgen_export3: (a: number, b: number) => number;
|
|
53
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
|
|
54
|
+
readonly __wbindgen_start: () => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
61
|
+
* a precompiled `WebAssembly.Module`.
|
|
62
|
+
*
|
|
63
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
64
|
+
*
|
|
65
|
+
* @returns {InitOutput}
|
|
66
|
+
*/
|
|
67
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
71
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
72
|
+
*
|
|
73
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
74
|
+
*
|
|
75
|
+
* @returns {Promise<InitOutput>}
|
|
76
|
+
*/
|
|
77
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|