@openlv/core 0.0.1-beta.1
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/LICENSE +165 -0
- package/README.md +3 -0
- package/dist/encryption/asymmetric.d.ts +22 -0
- package/dist/encryption/asymmetric.js +90 -0
- package/dist/encryption/asymmetric.js.map +1 -0
- package/dist/encryption/asymmetric.test.d.ts +1 -0
- package/dist/encryption/asymmetric.test.js +38 -0
- package/dist/encryption/asymmetric.test.js.map +1 -0
- package/dist/encryption/base64.d.ts +2 -0
- package/dist/encryption/base64.js +16 -0
- package/dist/encryption/base64.js.map +1 -0
- package/dist/encryption/base64.test.d.ts +1 -0
- package/dist/encryption/base64.test.js +21 -0
- package/dist/encryption/base64.test.js.map +1 -0
- package/dist/encryption/handshake.d.ts +10 -0
- package/dist/encryption/handshake.js +37 -0
- package/dist/encryption/handshake.js.map +1 -0
- package/dist/encryption/handshake.test.d.ts +1 -0
- package/dist/encryption/handshake.test.js +16 -0
- package/dist/encryption/handshake.test.js.map +1 -0
- package/dist/encryption/hash.d.ts +13 -0
- package/dist/encryption/hash.js +32 -0
- package/dist/encryption/hash.js.map +1 -0
- package/dist/encryption/index.d.ts +6 -0
- package/dist/encryption/index.js +7 -0
- package/dist/encryption/index.js.map +1 -0
- package/dist/encryption/random.d.ts +8 -0
- package/dist/encryption/random.js +21 -0
- package/dist/encryption/random.js.map +1 -0
- package/dist/errors/base.d.ts +29 -0
- package/dist/errors/base.js +99 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +5 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/signal.d.ts +4 -0
- package/dist/errors/signal.js +7 -0
- package/dist/errors/signal.js.map +1 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +3 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/messages/index.d.ts +21 -0
- package/dist/messages/index.js +2 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/session.d.ts +23 -0
- package/dist/session.js +2 -0
- package/dist/session.js.map +1 -0
- package/dist/settings.d.ts +15 -0
- package/dist/settings.js +2 -0
- package/dist/settings.js.map +1 -0
- package/dist/utils/encryption.d.ts +88 -0
- package/dist/utils/encryption.js +245 -0
- package/dist/utils/encryption.js.map +1 -0
- package/dist/utils/url.d.ts +3 -0
- package/dist/utils/url.js +66 -0
- package/dist/utils/url.js.map +1 -0
- package/dist/utils/url.test.d.ts +1 -0
- package/dist/utils/url.test.js +29 -0
- package/dist/utils/url.test.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export const encodeConnectionURL = (payload) => {
|
|
2
|
+
const params = new URLSearchParams();
|
|
3
|
+
params.set("h", payload.h);
|
|
4
|
+
params.set("k", payload.k);
|
|
5
|
+
if (payload.p) {
|
|
6
|
+
params.set("p", payload.p);
|
|
7
|
+
}
|
|
8
|
+
if (payload.s) {
|
|
9
|
+
params.set("s", payload.s);
|
|
10
|
+
}
|
|
11
|
+
return `openlv://${payload.sessionId}?${params.toString()}`;
|
|
12
|
+
};
|
|
13
|
+
export const decodeConnectionURL = (url) => {
|
|
14
|
+
// Type check and validation
|
|
15
|
+
if (typeof url !== "string") {
|
|
16
|
+
throw new Error(`Invalid URL type: expected string, got ${typeof url}`);
|
|
17
|
+
}
|
|
18
|
+
if (!url || url.trim() === "") {
|
|
19
|
+
throw new Error("URL cannot be empty");
|
|
20
|
+
}
|
|
21
|
+
if (!url.startsWith("openlv://")) {
|
|
22
|
+
throw new Error(`Invalid URL format: must start with 'openlv://', got: ${url}`);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const urlObj = new URL(url);
|
|
26
|
+
const sessionId = urlObj.hostname || urlObj.pathname.replace("/", "");
|
|
27
|
+
const h = urlObj.searchParams.get("h") || "";
|
|
28
|
+
const k = urlObj.searchParams.get("k") || "";
|
|
29
|
+
const s = urlObj.searchParams.get("s") || undefined;
|
|
30
|
+
const p = urlObj.searchParams.get("p") || "mqtt";
|
|
31
|
+
if (!sessionId) {
|
|
32
|
+
throw new Error("Session ID is required in URL");
|
|
33
|
+
}
|
|
34
|
+
// Validate session ID format (16 characters, URL-safe alphabet)
|
|
35
|
+
if (!/^[A-Za-z0-9_-]{16}$/.test(sessionId)) {
|
|
36
|
+
throw new Error("Invalid session ID format: must be 16 URL-safe characters");
|
|
37
|
+
}
|
|
38
|
+
if (!h) {
|
|
39
|
+
throw new Error("Public key hash (h parameter) is required in URL");
|
|
40
|
+
}
|
|
41
|
+
// Validate public key hash format (16 hex characters)
|
|
42
|
+
if (!/^[0-9a-f]{16}$/.test(h)) {
|
|
43
|
+
throw new Error("Invalid public key hash format: must be 16 hex characters");
|
|
44
|
+
}
|
|
45
|
+
if (!k) {
|
|
46
|
+
throw new Error("Shared key (k parameter) is required in URL");
|
|
47
|
+
}
|
|
48
|
+
// Validate shared key format (32 hex characters)
|
|
49
|
+
if (!/^[0-9a-f]{32}$/.test(k)) {
|
|
50
|
+
throw new Error(`Invalid shared key format: must be 32 hex characters, received: ${k}`);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
sessionId,
|
|
54
|
+
h,
|
|
55
|
+
k,
|
|
56
|
+
// TODO: figure out why '' empty string and not undefined
|
|
57
|
+
s: s ? decodeURIComponent(s) : "",
|
|
58
|
+
p,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
63
|
+
throw new Error(`Failed to parse URL: ${url}. Original error: ${errorMessage}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAEA,MAA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C,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;YACjC,CAAC;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QAE3D,MAAM,IAAI,KAAK,CACb,wBAAwB,GAAG,qBAAqB,YAAY,EAAE,CAC/D,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { decodeConnectionURL, encodeConnectionURL } from "./url.js";
|
|
3
|
+
const testCases = [
|
|
4
|
+
{
|
|
5
|
+
url: "openlv://k7n8m9x2w5q1p3r6?h=a1b2c3d4e5f60708&k=0123456789abcdef0123456789abcdef&p=mqtt&s=wss%3A%2F%2Ftest.mosquitto.org%3A8081%2Fmqtt",
|
|
6
|
+
expected: {
|
|
7
|
+
sessionId: "k7n8m9x2w5q1p3r6",
|
|
8
|
+
h: "a1b2c3d4e5f60708",
|
|
9
|
+
k: "0123456789abcdef0123456789abcdef",
|
|
10
|
+
p: "mqtt",
|
|
11
|
+
s: "wss://test.mosquitto.org:8081/mqtt",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
describe("URL Utilities", () => {
|
|
16
|
+
test("should decode connection URL", () => {
|
|
17
|
+
testCases.forEach((testCase) => {
|
|
18
|
+
const result = decodeConnectionURL(testCase.url);
|
|
19
|
+
expect(result).toEqual(testCase.expected);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
test("should encode connection URL", () => {
|
|
23
|
+
testCases.forEach((testCase) => {
|
|
24
|
+
const result = encodeConnectionURL(testCase.expected);
|
|
25
|
+
expect(result).toEqual(testCase.url);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=url.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.test.js","sourceRoot":"","sources":["../../src/utils/url.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpE,MAAM,SAAS,GAAG;IAChB;QACE,GAAG,EAAE,uIAAuI;QAC5I,QAAQ,EAAE;YACR,SAAS,EAAE,kBAAkB;YAC7B,CAAC,EAAE,kBAAkB;YACrB,CAAC,EAAE,kCAAkC;YACrC,CAAC,EAAE,MAAM;YACT,CAAC,EAAE,oCAAoC;SACxC;KACF;CACF,CAAC;AAEF,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACxC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC7B,MAAM,MAAM,GAAG,mBAAmB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAEjD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACxC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC7B,MAAM,MAAM,GAAG,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAEtD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openlv/core",
|
|
3
|
+
"version": "0.0.1-beta.1",
|
|
4
|
+
"license": "LGPL-3.0-only",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"open-lavatory"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/v3xlabs/open-lavatory",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/v3xlabs/open-lavatory/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/v3xlabs/open-lavatory.git",
|
|
15
|
+
"directory": "packages/core"
|
|
16
|
+
},
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Open-Lavatory",
|
|
19
|
+
"url": "https://github.com/v3xlabs/open-lavatory"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./encryption": {
|
|
30
|
+
"types": "./dist/encryption/index.d.ts",
|
|
31
|
+
"default": "./dist/encryption/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./errors": {
|
|
34
|
+
"types": "./dist/errors/index.d.ts",
|
|
35
|
+
"default": "./dist/errors/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./icons": {
|
|
38
|
+
"types": "./dist/icons/index.d.ts",
|
|
39
|
+
"default": "./dist/icons/index.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"README.md"
|
|
46
|
+
],
|
|
47
|
+
"sideEffects": false,
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"eventemitter3": "^5.0.1",
|
|
50
|
+
"tweetnacl": "^1.0.3"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"typescript": "^5",
|
|
54
|
+
"vitest": "^4"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@wagmi/core": "2",
|
|
58
|
+
"viem": "2",
|
|
59
|
+
"wagmi": "2"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public",
|
|
63
|
+
"tag": "beta"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsc",
|
|
67
|
+
"test": "vitest"
|
|
68
|
+
}
|
|
69
|
+
}
|