@openlv/core 0.0.1 → 0.1.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/dist/encryption/asymmetric.d.ts +2 -4
- package/dist/encryption/asymmetric.js +11 -11
- package/dist/encryption/asymmetric.js.map +1 -1
- package/dist/encryption/handshake.js +12 -10
- package/dist/encryption/handshake.js.map +1 -1
- package/dist/encryption/hash.js +2 -5
- package/dist/encryption/hash.js.map +1 -1
- package/dist/errors.d.ts +3 -28
- package/dist/errors.js +11 -92
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/log.d.ts +1 -0
- package/dist/log.js +31 -0
- package/dist/log.js.map +1 -0
- package/dist/make.d.ts +0 -5
- package/dist/make.js +0 -3
- package/dist/make.js.map +1 -1
- package/dist/session.d.ts +1 -1
- package/dist/session.js.map +1 -1
- package/dist/url/index.js +4 -9
- package/dist/url/index.js.map +1 -1
- package/package.json +3 -9
- package/dist/messages.d.ts +0 -21
- package/dist/messages.js +0 -2
- package/dist/messages.js.map +0 -1
|
@@ -15,8 +15,6 @@ export type EncKeypair = {
|
|
|
15
15
|
decryptionKey: DecryptionKey;
|
|
16
16
|
};
|
|
17
17
|
export declare const generateKeyPair: () => Promise<EncKeypair>;
|
|
18
|
-
export declare const initEncryptionKeys: (initParameters?: SessionLinkParameters) => Promise<{
|
|
19
|
-
|
|
20
|
-
decryptionKey: DecryptionKey;
|
|
21
|
-
relyingEncryptionKey: EncryptionKey;
|
|
18
|
+
export declare const initEncryptionKeys: (initParameters?: SessionLinkParameters) => Promise<EncKeypair & {
|
|
19
|
+
relyingEncryptionKey?: EncryptionKey;
|
|
22
20
|
}>;
|
|
@@ -25,6 +25,9 @@ const decomposePayload = (payload) => {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
export const createEncryptionKey = async (publicKey) => {
|
|
28
|
+
if (publicKey.length !== PUBLIC_KEY_BYTES) {
|
|
29
|
+
throw new Error(`Public key must be ${PUBLIC_KEY_BYTES} bytes, got ${publicKey.length}`);
|
|
30
|
+
}
|
|
28
31
|
const serializedPublicKey = toBase64(publicKey);
|
|
29
32
|
return {
|
|
30
33
|
toString: () => serializedPublicKey,
|
|
@@ -63,20 +66,17 @@ export const generateKeyPair = async () => {
|
|
|
63
66
|
};
|
|
64
67
|
export const initEncryptionKeys = async (initParameters) => {
|
|
65
68
|
const { encryptionKey, decryptionKey } = await generateKeyPair();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
encryptionKey,
|
|
72
|
-
decryptionKey,
|
|
73
|
-
relyingEncryptionKey,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
69
|
+
// Note: the peer key is deliberately left undefined until discovered —
|
|
70
|
+
// falling back to our own key would silently encrypt to ourselves.
|
|
71
|
+
const publicKey = initParameters && "publicKey" in initParameters
|
|
72
|
+
? initParameters.publicKey
|
|
73
|
+
: undefined;
|
|
76
74
|
return {
|
|
77
75
|
encryptionKey,
|
|
78
76
|
decryptionKey,
|
|
79
|
-
relyingEncryptionKey:
|
|
77
|
+
relyingEncryptionKey: publicKey
|
|
78
|
+
? await parseEncryptionKey(publicKey)
|
|
79
|
+
: undefined,
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
82
|
//# sourceMappingURL=asymmetric.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asymmetric.js","sourceRoot":"","sources":["../../src/encryption/asymmetric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAGlD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,WAAW,GAAG,EAAE,CAAC;AA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AAC;AACJ,CAAC,CAAC;AAOF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,IAAyB,EAAE;IAC7D,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;IACjD,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAEjD,OAAO;QACL,aAAa,EAAE,MAAM,mBAAmB,CAAC,SAAS,CAAC;QACnD,aAAa,EAAE,MAAM,mBAAmB,CAAC,SAAS,CAAC;KACpD,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,cAAsC,EAC2B,EAAE;IACnE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,MAAM,eAAe,EAAE,CAAC;IAEjE,uEAAuE;IACvE,mEAAmE;IACnE,MAAM,SAAS,GACX,cAAc,IAAI,WAAW,IAAI,cAAc;QAC/C,CAAC,CAAE,cAAc,CAAC,SAAoB;QACtC,CAAC,CAAC,SAAS,CAAC;IAEhB,OAAO;QACL,aAAa;QACb,aAAa;QACb,oBAAoB,EAAE,SAAS;YAC7B,CAAC,CAAC,MAAM,kBAAkB,CAAC,SAAS,CAAC;YACrC,CAAC,CAAC,SAAS;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { secretbox } from \"@noble/ciphers/salsa.js\";\nimport { x25519 } from \"@noble/curves/ed25519.js\";\n\nimport type { SessionLinkParameters } from \"../session.js\";\nimport { fromBase64, toBase64 } from \"./base64.js\";\n\nconst PUBLIC_KEY_BYTES = 32;\nconst NONCE_BYTES = 24;\n\nconst composePayload = (\n ephemeralPublicKey: Uint8Array,\n nonce: Uint8Array,\n ciphertext: Uint8Array,\n): string => {\n const payload = new Uint8Array(\n ephemeralPublicKey.length + nonce.length + ciphertext.length,\n );\n\n payload.set(ephemeralPublicKey, 0);\n payload.set(nonce, ephemeralPublicKey.length);\n payload.set(ciphertext, ephemeralPublicKey.length + nonce.length);\n\n return toBase64(payload);\n};\n\nconst decomposePayload = (\n payload: string,\n): {\n ephemeralPublicKey: Uint8Array;\n nonce: Uint8Array;\n ciphertext: Uint8Array;\n} => {\n const bytes = fromBase64(payload);\n\n if (bytes.length <= PUBLIC_KEY_BYTES + NONCE_BYTES) {\n throw new Error(\"Encrypted payload is malformed.\");\n }\n\n const ephemeralPublicKey = bytes.slice(0, PUBLIC_KEY_BYTES);\n const nonce = bytes.slice(PUBLIC_KEY_BYTES, PUBLIC_KEY_BYTES + NONCE_BYTES);\n const ciphertext = bytes.slice(PUBLIC_KEY_BYTES + NONCE_BYTES);\n\n return {\n ephemeralPublicKey,\n nonce,\n ciphertext,\n };\n};\n\nexport type EncryptionKey = {\n toString: () => string;\n encrypt: (message: string) => Promise<string>;\n};\n\nexport type DecryptionKey = {\n toString: () => string;\n decrypt: (message: string) => Promise<string>;\n};\n\nexport const createEncryptionKey = async (\n publicKey: Uint8Array,\n): Promise<EncryptionKey> => {\n if (publicKey.length !== PUBLIC_KEY_BYTES) {\n throw new Error(\n `Public key must be ${PUBLIC_KEY_BYTES} bytes, got ${publicKey.length}`,\n );\n }\n\n const serializedPublicKey = toBase64(publicKey);\n\n return {\n toString: () => serializedPublicKey,\n encrypt: async (message: string) => {\n const ephemeralSecret = x25519.utils.randomSecretKey();\n const ephemeralPublic = x25519.getPublicKey(ephemeralSecret);\n const nonce = crypto.getRandomValues(new Uint8Array(NONCE_BYTES));\n const { seal } = secretbox(\n x25519.getSharedSecret(ephemeralSecret, publicKey),\n nonce,\n );\n const ciphertext = seal(new TextEncoder().encode(message));\n\n return composePayload(ephemeralPublic, nonce, ciphertext);\n },\n };\n};\n\nexport const parseEncryptionKey = async (\n serializedKey: string,\n): Promise<EncryptionKey> => createEncryptionKey(fromBase64(serializedKey));\n\nexport const createDecryptionKey = async (\n secretKey: Uint8Array,\n): Promise<DecryptionKey> => {\n const serializedSecretKey = toBase64(secretKey);\n\n return {\n toString: () => serializedSecretKey,\n decrypt: async (message: string) => {\n if (!message) {\n throw new Error(\"Cannot decrypt an empty payload\");\n }\n\n const { ephemeralPublicKey, nonce, ciphertext }\n = decomposePayload(message);\n const { open } = secretbox(\n x25519.getSharedSecret(secretKey, ephemeralPublicKey),\n nonce,\n );\n\n return new TextDecoder().decode(open(ciphertext));\n },\n };\n};\n\nexport type EncKeypair = {\n encryptionKey: EncryptionKey;\n decryptionKey: DecryptionKey;\n};\n\nexport const generateKeyPair = async (): Promise<EncKeypair> => {\n const secretKey = x25519.utils.randomSecretKey();\n const publicKey = x25519.getPublicKey(secretKey);\n\n return {\n encryptionKey: await createEncryptionKey(publicKey),\n decryptionKey: await createDecryptionKey(secretKey),\n };\n};\n\nexport const initEncryptionKeys = async (\n initParameters?: SessionLinkParameters,\n): Promise<EncKeypair & { relyingEncryptionKey?: EncryptionKey; }> => {\n const { encryptionKey, decryptionKey } = await generateKeyPair();\n\n // Note: the peer key is deliberately left undefined until discovered —\n // falling back to our own key would silently encrypt to ourselves.\n const publicKey\n = initParameters && \"publicKey\" in initParameters\n ? (initParameters.publicKey as string)\n : undefined;\n\n return {\n encryptionKey,\n decryptionKey,\n relyingEncryptionKey: publicKey\n ? await parseEncryptionKey(publicKey)\n : undefined,\n };\n};\n"]}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { bytesToHex, hexToBytes } from "@noble/ciphers/utils.js";
|
|
2
|
+
const HANDSHAKE_KEY_BYTES = 16;
|
|
3
|
+
const IV_BYTES = 12;
|
|
2
4
|
export const deriveSymmetricKey = async (k) => {
|
|
3
|
-
const baseKey =
|
|
5
|
+
const baseKey = Uint8Array.from(hexToBytes(k));
|
|
6
|
+
if (baseKey.length !== HANDSHAKE_KEY_BYTES) {
|
|
7
|
+
throw new Error(`Handshake key must be ${HANDSHAKE_KEY_BYTES} bytes, got ${baseKey.length}`);
|
|
8
|
+
}
|
|
4
9
|
const sharedSecret = await crypto.subtle.importKey("raw", baseKey, { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
|
|
5
10
|
return {
|
|
6
11
|
toString: () => k,
|
|
7
12
|
encrypt: async (message) => {
|
|
8
|
-
const iv = crypto.getRandomValues(new Uint8Array(
|
|
13
|
+
const iv = crypto.getRandomValues(new Uint8Array(IV_BYTES));
|
|
9
14
|
const encrypted = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, sharedSecret, new TextEncoder().encode(message));
|
|
10
15
|
const combined = new Uint8Array(iv.length + encrypted.byteLength);
|
|
11
16
|
combined.set(iv);
|
|
@@ -16,8 +21,8 @@ export const deriveSymmetricKey = async (k) => {
|
|
|
16
21
|
const combined = new Uint8Array(atob(message)
|
|
17
22
|
.split("")
|
|
18
23
|
.map(char => char.codePointAt(0)));
|
|
19
|
-
const iv = combined.slice(0,
|
|
20
|
-
const encrypted = combined.slice(
|
|
24
|
+
const iv = combined.slice(0, IV_BYTES);
|
|
25
|
+
const encrypted = combined.slice(IV_BYTES);
|
|
21
26
|
const decrypted = await crypto.subtle.decrypt({ name: "AES-GCM", iv }, sharedSecret, encrypted);
|
|
22
27
|
const decoder = new TextDecoder();
|
|
23
28
|
return decoder.decode(decrypted);
|
|
@@ -28,11 +33,8 @@ export const deriveSymmetricKey = async (k) => {
|
|
|
28
33
|
* Generate a 16-byte random shared key and return as hex
|
|
29
34
|
*/
|
|
30
35
|
export const generateHandshakeKey = async () => {
|
|
31
|
-
const array = new Uint8Array(
|
|
36
|
+
const array = new Uint8Array(HANDSHAKE_KEY_BYTES);
|
|
32
37
|
crypto.getRandomValues(array);
|
|
33
|
-
|
|
34
|
-
.map(b => b.toString(16).padStart(2, "0"))
|
|
35
|
-
.join("");
|
|
36
|
-
return await deriveSymmetricKey(keyHex);
|
|
38
|
+
return await deriveSymmetricKey(bytesToHex(array));
|
|
37
39
|
};
|
|
38
40
|
//# sourceMappingURL=handshake.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handshake.js","sourceRoot":"","sources":["../../src/encryption/handshake.ts"],"names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} from \"@noble/ciphers/utils.js\";\n\nexport type SymmetricKey = {\n toString: () => string;\n encrypt: (message: string) => Promise<string>;\n decrypt: (message: string) => Promise<string>;\n};\n\nconst HANDSHAKE_KEY_BYTES = 16;\nconst IV_BYTES = 12;\n\nexport const deriveSymmetricKey = async (k: string): Promise<SymmetricKey> => {\n const baseKey = Uint8Array.from(hexToBytes(k));\n\n if (baseKey.length !== HANDSHAKE_KEY_BYTES) {\n throw new Error(\n `Handshake key must be ${HANDSHAKE_KEY_BYTES} bytes, got ${baseKey.length}`,\n );\n }\n\n const sharedSecret = await crypto.subtle.importKey(\n \"raw\",\n baseKey,\n { name: \"AES-GCM\" },\n false,\n [\"encrypt\", \"decrypt\"],\n );\n\n return {\n toString: () => k,\n encrypt: async (message: string) => {\n const iv = crypto.getRandomValues(new Uint8Array(IV_BYTES));\n const encrypted = await crypto.subtle.encrypt(\n { name: \"AES-GCM\", iv },\n sharedSecret,\n new TextEncoder().encode(message),\n );\n const combined = new Uint8Array(iv.length + encrypted.byteLength);\n\n combined.set(iv);\n combined.set(new Uint8Array(encrypted), iv.length);\n\n return btoa(String.fromCharCode.apply(null, Array.from(combined)));\n },\n decrypt: async (message: string) => {\n const combined = new Uint8Array(\n atob(message)\n .split(\"\")\n .map(char => char.codePointAt(0)!),\n );\n const iv = combined.slice(0, IV_BYTES);\n const encrypted = combined.slice(IV_BYTES);\n const decrypted = await crypto.subtle.decrypt(\n { name: \"AES-GCM\", iv },\n sharedSecret,\n encrypted,\n );\n const decoder = new TextDecoder();\n\n return decoder.decode(decrypted);\n },\n };\n};\n\n/**\n * Generate a 16-byte random shared key and return as hex\n */\nexport const generateHandshakeKey = async (): Promise<SymmetricKey> => {\n const array = new Uint8Array(HANDSHAKE_KEY_BYTES);\n\n crypto.getRandomValues(array);\n\n return await deriveSymmetricKey(bytesToHex(array));\n};\n"]}
|
package/dist/encryption/hash.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bytesToHex } from "@noble/ciphers/utils.js";
|
|
1
2
|
const HASH_LENGTH = 16;
|
|
2
3
|
/**
|
|
3
4
|
* Hashes a public key using SHA-256 and returns the first 16 bytes as a hex string
|
|
@@ -5,11 +6,7 @@ const HASH_LENGTH = 16;
|
|
|
5
6
|
export const hashPublicKey = async (publicKey) => {
|
|
6
7
|
const buffer = new TextEncoder().encode(publicKey.toString());
|
|
7
8
|
const hash = await crypto.subtle.digest("SHA-256", buffer);
|
|
8
|
-
|
|
9
|
-
const hashHex = Array.from(hashArray)
|
|
10
|
-
.map(b => b.toString(16).padStart(2, "0"))
|
|
11
|
-
.join("");
|
|
12
|
-
return hashHex.slice(0, HASH_LENGTH);
|
|
9
|
+
return bytesToHex(new Uint8Array(hash)).slice(0, HASH_LENGTH);
|
|
13
10
|
};
|
|
14
11
|
export const validatePublicKeyHash = async (publicKey, hash) => {
|
|
15
12
|
const computedHash = await hashPublicKey(publicKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/encryption/hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/encryption/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAIrD,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,SAAwB,EACP,EAAE;IACnB,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAE3D,OAAO,UAAU,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EACxC,SAAwB,EACxB,IAAY,EACM,EAAE;IACpB,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,SAAS,CAAC,CAAC;IAEpD,OAAO,YAAY,KAAK,IAAI,CAAC;AAC/B,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,WAA+B,EAC/B,aAA4B,EAC5B,EAAE;IACF,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG,WAAW,IAAI,OAAO,CAAC;IACpC,MAAM,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC;IAEhC,OAAO;QACL,IAAI;QACJ,MAAM;KACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { bytesToHex } from \"@noble/ciphers/utils.js\";\n\nimport type { EncryptionKey } from \"./asymmetric.js\";\n\nconst HASH_LENGTH = 16;\n\n/**\n * Hashes a public key using SHA-256 and returns the first 16 bytes as a hex string\n */\nexport const hashPublicKey = async (\n publicKey: EncryptionKey,\n): Promise<string> => {\n const buffer = new TextEncoder().encode(publicKey.toString());\n const hash = await crypto.subtle.digest(\"SHA-256\", buffer);\n\n return bytesToHex(new Uint8Array(hash)).slice(0, HASH_LENGTH);\n};\n\nexport const validatePublicKeyHash = async (\n publicKey: EncryptionKey,\n hash: string,\n): Promise<boolean> => {\n const computedHash = await hashPublicKey(publicKey);\n\n return computedHash === hash;\n};\n\n/**\n * determines/or generates the hash and dictates wether is host or not\n */\nexport const initHash = async (\n initialHash: string | undefined,\n encryptionKey: EncryptionKey,\n) => {\n const ourHash = await hashPublicKey(encryptionKey);\n const hash = initialHash || ourHash;\n const isHost = hash === ourHash;\n\n return {\n hash,\n isHost,\n };\n};\n"]}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
getDocsUrl?: ((args: BaseErrorParameters) => string | undefined) | undefined;
|
|
3
|
-
version?: string | undefined;
|
|
4
|
-
};
|
|
5
|
-
export declare const setErrorConfig: (config: ErrorConfig) => void;
|
|
6
|
-
type BaseErrorParameters = {
|
|
7
|
-
cause?: BaseError | Error | undefined;
|
|
8
|
-
details?: string | undefined;
|
|
9
|
-
docsBaseUrl?: string | undefined;
|
|
10
|
-
docsPath?: string | undefined;
|
|
11
|
-
docsSlug?: string | undefined;
|
|
12
|
-
metaMessages?: string[] | undefined;
|
|
13
|
-
name?: string | undefined;
|
|
14
|
-
};
|
|
15
|
-
export type BaseErrorType = BaseError & {
|
|
16
|
-
name: "BaseError";
|
|
17
|
-
};
|
|
18
|
-
export declare class BaseError extends Error {
|
|
19
|
-
details: string;
|
|
20
|
-
docsPath?: string | undefined;
|
|
21
|
-
metaMessages?: string[] | undefined;
|
|
22
|
-
shortMessage: string;
|
|
23
|
-
version: string;
|
|
1
|
+
export declare class OpenLVError extends Error {
|
|
24
2
|
name: string;
|
|
25
|
-
constructor(shortMessage: string, args?: BaseErrorParameters);
|
|
26
|
-
walk(): Error;
|
|
27
|
-
walk(fn: (err: unknown) => boolean): Error | null;
|
|
28
3
|
}
|
|
29
|
-
export declare class SignalNoConnectionError extends
|
|
4
|
+
export declare class SignalNoConnectionError extends OpenLVError {
|
|
5
|
+
name: string;
|
|
30
6
|
constructor();
|
|
31
7
|
}
|
|
32
|
-
export {};
|
package/dist/errors.js
CHANGED
|
@@ -1,104 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// docsBaseUrl,
|
|
6
|
-
// docsPath = '',
|
|
7
|
-
// docsSlug,
|
|
8
|
-
// }: BaseErrorParameters) =>
|
|
9
|
-
// docsPath
|
|
10
|
-
// ? `${docsBaseUrl ?? 'https://viem.sh'}${docsPath}${docsSlug ? `#${docsSlug}` : ''
|
|
11
|
-
// }`
|
|
12
|
-
// : undefined,
|
|
13
|
-
version,
|
|
14
|
-
};
|
|
15
|
-
export const setErrorConfig = (config) => {
|
|
16
|
-
errorConfig = config;
|
|
17
|
-
};
|
|
18
|
-
export class BaseError extends Error {
|
|
19
|
-
constructor(shortMessage, args = {}) {
|
|
20
|
-
const details = (() => {
|
|
21
|
-
if (args.cause instanceof BaseError)
|
|
22
|
-
return args.cause.details;
|
|
23
|
-
if (args.cause?.message)
|
|
24
|
-
return args.cause.message;
|
|
25
|
-
return args.details;
|
|
26
|
-
})();
|
|
27
|
-
const docsPath = (() => {
|
|
28
|
-
if (args.cause instanceof BaseError)
|
|
29
|
-
return args.cause.docsPath || args.docsPath;
|
|
30
|
-
return args.docsPath;
|
|
31
|
-
})();
|
|
32
|
-
const docsUrl = errorConfig.getDocsUrl?.({ ...args, docsPath });
|
|
33
|
-
const message = [
|
|
34
|
-
shortMessage || "An error occurred.",
|
|
35
|
-
"",
|
|
36
|
-
...(args.metaMessages ? [...args.metaMessages, ""] : []),
|
|
37
|
-
...(docsUrl ? [`Docs: ${docsUrl}`] : []),
|
|
38
|
-
...(details ? [`Details: ${details}`] : []),
|
|
39
|
-
...(errorConfig.version ? [`Version: ${errorConfig.version}`] : []),
|
|
40
|
-
].join("\n");
|
|
41
|
-
super(message, args.cause ? { cause: args.cause } : undefined);
|
|
42
|
-
Object.defineProperty(this, "details", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true,
|
|
46
|
-
value: void 0
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(this, "docsPath", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: void 0
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(this, "metaMessages", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
configurable: true,
|
|
57
|
-
writable: true,
|
|
58
|
-
value: void 0
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(this, "shortMessage", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
configurable: true,
|
|
63
|
-
writable: true,
|
|
64
|
-
value: void 0
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(this, "version", {
|
|
1
|
+
export class OpenLVError extends Error {
|
|
2
|
+
constructor() {
|
|
3
|
+
super(...arguments);
|
|
4
|
+
Object.defineProperty(this, "name", {
|
|
67
5
|
enumerable: true,
|
|
68
6
|
configurable: true,
|
|
69
7
|
writable: true,
|
|
70
|
-
value:
|
|
8
|
+
value: "OpenLVError"
|
|
71
9
|
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class SignalNoConnectionError extends OpenLVError {
|
|
13
|
+
constructor() {
|
|
14
|
+
super("Signaling connection is not established");
|
|
72
15
|
Object.defineProperty(this, "name", {
|
|
73
16
|
enumerable: true,
|
|
74
17
|
configurable: true,
|
|
75
18
|
writable: true,
|
|
76
|
-
value: "
|
|
19
|
+
value: "SignalNoConnectionError"
|
|
77
20
|
});
|
|
78
|
-
this.details = details;
|
|
79
|
-
this.docsPath = docsPath;
|
|
80
|
-
this.metaMessages = args.metaMessages;
|
|
81
|
-
this.name = args.name ?? this.name;
|
|
82
|
-
this.shortMessage = shortMessage;
|
|
83
|
-
this.version = version;
|
|
84
|
-
}
|
|
85
|
-
walk(fn) {
|
|
86
|
-
return walk(this, fn);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const walk = (err, fn) => {
|
|
90
|
-
if (fn?.(err))
|
|
91
|
-
return err;
|
|
92
|
-
if (err
|
|
93
|
-
&& typeof err === "object"
|
|
94
|
-
&& "cause" in err
|
|
95
|
-
&& err.cause !== undefined)
|
|
96
|
-
return walk(err.cause, fn);
|
|
97
|
-
return fn ? null : err;
|
|
98
|
-
};
|
|
99
|
-
export class SignalNoConnectionError extends BaseError {
|
|
100
|
-
constructor() {
|
|
101
|
-
super(["Hello", "World"].join("\n"), { name: "SignalConnectionError" });
|
|
102
21
|
}
|
|
103
22
|
}
|
|
104
23
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAAtC;;QACW;;;;mBAAO,aAAa;WAAC;IAChC,CAAC;CAAA;AAED,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IAGtD;QACE,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAH1C;;;;mBAAO,yBAAyB;WAAC;IAI1C,CAAC;CACF","sourcesContent":["export class OpenLVError extends Error {\n override name = \"OpenLVError\";\n}\n\nexport class SignalNoConnectionError extends OpenLVError {\n override name = \"SignalNoConnectionError\";\n\n constructor() {\n super(\"Signaling connection is not established\");\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** biome-ignore-all lint/performance/noReExportAll: package entrypoint */
|
|
2
2
|
/** biome-ignore-all lint/performance/noBarrelFile: package entrypoint */
|
|
3
|
+
export * from "./log.js";
|
|
3
4
|
export * from "./make.js";
|
|
4
|
-
export * from "./messages.js";
|
|
5
5
|
export * from "./session.js";
|
|
6
6
|
export * from "./url/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** biome-ignore-all lint/performance/noReExportAll: package entrypoint */
|
|
2
2
|
/** biome-ignore-all lint/performance/noBarrelFile: package entrypoint */
|
|
3
|
+
export * from "./log.js";
|
|
3
4
|
export * from "./make.js";
|
|
4
|
-
export * from "./messages.js";
|
|
5
5
|
export * from "./session.js";
|
|
6
6
|
export * from "./url/index.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,yEAAyE;AAEzE,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,yEAAyE;AAEzE,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC","sourcesContent":["/** biome-ignore-all lint/performance/noReExportAll: package entrypoint */\n/** biome-ignore-all lint/performance/noBarrelFile: package entrypoint */\n\nexport * from \"./log.js\";\nexport * from \"./make.js\";\nexport * from \"./session.js\";\nexport * from \"./url/index.js\";\n"]}
|
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createLogger: (scope: string, color?: string) => (...args: Parameters<typeof console.log>) => void;
|
package/dist/log.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug logging is disabled by default so that key material, handshake
|
|
3
|
+
* traffic, and RPC payloads never reach the console in production.
|
|
4
|
+
*
|
|
5
|
+
* Enable it by setting `globalThis.OPENLV_DEBUG = true`, adding an
|
|
6
|
+
* `openlv:debug` key to localStorage, or setting the `OPENLV_DEBUG`
|
|
7
|
+
* environment variable (Node).
|
|
8
|
+
*/
|
|
9
|
+
const isDebugEnabled = () => {
|
|
10
|
+
try {
|
|
11
|
+
const g = globalThis;
|
|
12
|
+
return Boolean(g.OPENLV_DEBUG
|
|
13
|
+
?? g.localStorage?.getItem("openlv:debug")
|
|
14
|
+
?? g.process?.env?.["OPENLV_DEBUG"]);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const supportsColor = typeof document !== "undefined";
|
|
21
|
+
export const createLogger = (scope, color = "gray") => (...args) => {
|
|
22
|
+
if (!isDebugEnabled())
|
|
23
|
+
return;
|
|
24
|
+
if (supportsColor) {
|
|
25
|
+
console.log(`%c[${scope}]%c`, `color: ${color}; font-weight: bold`, "color: inherit; font-weight: normal", ...args);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.log(`[${scope}]`, ...args);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=log.js.map
|
package/dist/log.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,cAAc,GAAG,GAAY,EAAE;IACnC,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,UAIT,CAAC;QAEF,OAAO,OAAO,CACZ,CAAC,CAAC,YAAY;eACX,CAAC,CAAC,YAAY,EAAE,OAAO,CAAC,cAAc,CAAC;eACvC,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,CACpC,CAAC;IACJ,CAAC;IACD,MAAM,CAAC;QACL,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,OAAO,QAAQ,KAAK,WAAW,CAAC;AAEtD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,KAAK,GAAG,MAAM,EAAE,EAAE,CAC5D,CAAC,GAAG,IAAoC,EAAE,EAAE;IAC1C,IAAI,CAAC,cAAc,EAAE;QAAE,OAAO;IAE9B,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,CAAC,GAAG,CACT,MAAM,KAAK,KAAK,EAChB,UAAU,KAAK,qBAAqB,EACpC,qCAAqC,EACrC,GAAG,IAAI,CACR,CAAC;IACJ,CAAC;SACI,CAAC;QACJ,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACrC,CAAC;AACH,CAAC,CAAC","sourcesContent":["/**\n * Debug logging is disabled by default so that key material, handshake\n * traffic, and RPC payloads never reach the console in production.\n *\n * Enable it by setting `globalThis.OPENLV_DEBUG = true`, adding an\n * `openlv:debug` key to localStorage, or setting the `OPENLV_DEBUG`\n * environment variable (Node).\n */\nconst isDebugEnabled = (): boolean => {\n try {\n const g = globalThis as {\n OPENLV_DEBUG?: unknown;\n localStorage?: Storage;\n process?: { env?: Record<string, string | undefined>; };\n };\n\n return Boolean(\n g.OPENLV_DEBUG\n ?? g.localStorage?.getItem(\"openlv:debug\")\n ?? g.process?.env?.[\"OPENLV_DEBUG\"],\n );\n }\n catch {\n return false;\n }\n};\n\nconst supportsColor = typeof document !== \"undefined\";\n\nexport const createLogger = (scope: string, color = \"gray\") =>\n (...args: Parameters<typeof console.log>) => {\n if (!isDebugEnabled()) return;\n\n if (supportsColor) {\n console.log(\n `%c[${scope}]%c`,\n `color: ${color}; font-weight: bold`,\n \"color: inherit; font-weight: normal\",\n ...args,\n );\n }\n else {\n console.log(`[${scope}]`, ...args);\n }\n };\n"]}
|
package/dist/make.d.ts
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
2
|
-
type Merge<T extends readonly object[]> = UnionToIntersection<T[number]>;
|
|
3
|
-
type EnsureAssignable<Have, Want> = Have extends Want ? unknown : never;
|
|
4
|
-
export declare const combine: <Target extends object, Parts extends readonly object[]>(...parts: Parts) => EnsureAssignable<Merge<Parts>, Target> extends unknown ? Target : never;
|
|
5
1
|
export declare const make: <M extends object, O extends object>(e: M, o: O) => M & O;
|
|
6
|
-
export {};
|
package/dist/make.js
CHANGED
package/dist/make.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make.js","sourceRoot":"","sources":["../src/make.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"make.js","sourceRoot":"","sources":["../src/make.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,CAAqC,CAAI,EAAE,CAAI,EAAE,EAAE,CACrE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAU,CAAC","sourcesContent":["export const make = <M extends object, O extends object>(e: M, o: O) =>\n Object.assign(e, o) as M & O;\n"]}
|
package/dist/session.d.ts
CHANGED
package/dist/session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"","sourcesContent":["import type { DecryptionKey, EncryptionKey } from \"./encryption/asymmetric.js\";\n\n// typescript type for 32 character hex string\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type Hex<_L> = string;\n\n/**\n * The parameters from the connection url\n */\nexport type SessionHandshakeParameters = {\n // Version of the openlv protocol\n version: 1;\n // Unique session identifier\n sessionId: Hex<16>;\n // Hash of peerA's public key\n h: Hex<16>;\n // Shared key for symmetric encryption during handshake\n k: Hex<
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"","sourcesContent":["import type { DecryptionKey, EncryptionKey } from \"./encryption/asymmetric.js\";\n\n// typescript type for 32 character hex string\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type Hex<_L> = string;\n\n/**\n * The parameters from the connection url\n */\nexport type SessionHandshakeParameters = {\n // Version of the openlv protocol\n version: 1;\n // Unique session identifier\n sessionId: Hex<16>;\n // Hash of peerA's public key\n h: Hex<16>;\n // Shared key for symmetric encryption during handshake (32 hex chars = 16 bytes)\n k: Hex<32>;\n // Protocol for signaling\n p: string;\n // Signaling server URL\n s: string;\n};\n\n/**\n * The parameters that describe a session\n * these can be used to restart a session\n */\nexport type SessionConnectionParameters = SessionHandshakeParameters & {\n relyingPublicKey: EncryptionKey;\n // Our public key for the relying party to encrypt messages to us\n encryptionKey: EncryptionKey;\n // Our private key for decrypting messages from the relying party\n decryptionKey: DecryptionKey;\n};\n\nexport type SessionCreationParameters = Pick<\n SessionHandshakeParameters,\n \"p\" | \"s\"\n>;\n\nexport type SessionLinkParameters =\n | SessionConnectionParameters\n | SessionHandshakeParameters\n | SessionCreationParameters;\n"]}
|
package/dist/url/index.js
CHANGED
|
@@ -12,16 +12,12 @@ export const encodeConnectionURL = (payload) => {
|
|
|
12
12
|
return `openlv://${payload.sessionId}@${OPENLV_PROTOCOL_VERSION}?${params.toString()}`;
|
|
13
13
|
};
|
|
14
14
|
export const decodeConnectionURL = (url) => {
|
|
15
|
-
|
|
16
|
-
if (typeof url !== "string") {
|
|
15
|
+
if (typeof url !== "string")
|
|
17
16
|
throw new TypeError(`Invalid URL type: expected string, got ${typeof url}`);
|
|
18
|
-
|
|
19
|
-
if (!url || url.trim() === "") {
|
|
17
|
+
if (!url || url.trim() === "")
|
|
20
18
|
throw new Error("URL cannot be empty");
|
|
21
|
-
|
|
22
|
-
if (!url.startsWith("openlv://")) {
|
|
19
|
+
if (!url.startsWith("openlv://"))
|
|
23
20
|
throw new Error(`Invalid URL format: must start with 'openlv://', got: ${url}`);
|
|
24
|
-
}
|
|
25
21
|
try {
|
|
26
22
|
const urlObj = new URL(url);
|
|
27
23
|
const sessionId = urlObj.username;
|
|
@@ -59,8 +55,7 @@ export const decodeConnectionURL = (url) => {
|
|
|
59
55
|
sessionId,
|
|
60
56
|
h,
|
|
61
57
|
k,
|
|
62
|
-
|
|
63
|
-
s: s ? decodeURIComponent(s) : "",
|
|
58
|
+
s: s ?? "",
|
|
64
59
|
p,
|
|
65
60
|
};
|
|
66
61
|
}
|
package/dist/url/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/url/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAEzC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAmC,EAAE,EAAE;IACzE,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IAErC,MAAM,CAAC,GAAG,CAAC,G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AwB,OAAO,qBAAqB,YAAY,EAAE,CAAC,CAAC;IACtF,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { SessionHandshakeParameters } from \"../session.js\";\n\nexport const OPENLV_PROTOCOL_VERSION = 1;\n\nexport const encodeConnectionURL = (payload: SessionHandshakeParameters) => {\n const params = new URLSearchParams();\n\n params.set(\"h\", payload.h);\n params.set(\"k\", payload.k);\n\n if (payload.p) {\n params.set(\"p\", payload.p);\n }\n\n if (payload.s) {\n params.set(\"s\", payload.s);\n }\n\n return `openlv://${payload.sessionId}@${OPENLV_PROTOCOL_VERSION}?${params.toString()}`;\n};\n\nexport const decodeConnectionURL = (\n url: string,\n): SessionHandshakeParameters => {\n if (typeof url !== \"string\") throw new TypeError(`Invalid URL type: expected string, got ${typeof url}`);\n\n if (!url || url.trim() === \"\") throw new Error(\"URL cannot be empty\");\n\n if (!url.startsWith(\"openlv://\")) throw new Error(\n `Invalid URL format: must start with 'openlv://', got: ${url}`,\n );\n\n try {\n const urlObj = new URL(url);\n const sessionId = urlObj.username;\n const version = Number(urlObj.hostname || urlObj.pathname.replace(\"/\", \"\"));\n\n if (version !== OPENLV_PROTOCOL_VERSION) {\n throw new Error(\n `Invalid protocol version: expected ${OPENLV_PROTOCOL_VERSION}, got ${version}`,\n );\n }\n\n const h = urlObj.searchParams.get(\"h\") || \"\";\n const k = urlObj.searchParams.get(\"k\") || \"\";\n const s = urlObj.searchParams.get(\"s\") || undefined;\n\n const p = urlObj.searchParams.get(\"p\") || \"mqtt\";\n\n if (!sessionId) {\n throw new Error(\"Session ID is required in URL\");\n }\n\n // Validate session ID format (16 characters, URL-safe alphabet)\n if (!/^[A-Za-z0-9_-]{16}$/.test(sessionId)) {\n throw new Error(\n \"Invalid session ID format: must be 16 URL-safe characters\",\n );\n }\n\n if (!h) {\n throw new Error(\"Public key hash (h parameter) is required in URL\");\n }\n\n // Validate public key hash format (16 hex characters)\n if (!/^[0-9a-f]{16}$/.test(h)) {\n throw new Error(\n \"Invalid public key hash format: must be 16 hex characters\",\n );\n }\n\n if (!k) {\n throw new Error(\"Shared key (k parameter) is required in URL\");\n }\n\n // Validate shared key format (32 hex characters)\n if (!/^[0-9a-f]{32}$/.test(k)) {\n throw new Error(\"Invalid shared key format: must be 32 lowercase hex characters\");\n }\n\n return {\n version,\n sessionId,\n h,\n k,\n s: s ?? \"\",\n p,\n };\n }\n catch (error) {\n const errorMessage\n = error instanceof Error ? error.message : \"Unknown error\";\n\n // Strip query string so handshake secrets (k) are not exposed in error messages\n const safeUrl = url.includes(\"?\") ? url.slice(0, url.indexOf(\"?\")) + \"?[redacted]\" : url;\n\n throw new Error(`Failed to parse URL: ${safeUrl}. Original error: ${errorMessage}`);\n }\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openlv/core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"open-lavatory"
|
|
6
6
|
],
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/v3xlabs/open-lavatory.git",
|
|
13
|
+
"url": "git+https://github.com/v3xlabs/open-lavatory.git",
|
|
14
14
|
"directory": "packages/core"
|
|
15
15
|
},
|
|
16
16
|
"license": "LGPL-3.0-only",
|
|
@@ -54,14 +54,8 @@
|
|
|
54
54
|
"typescript": "^5",
|
|
55
55
|
"vitest": "^4"
|
|
56
56
|
},
|
|
57
|
-
"peerDependencies": {
|
|
58
|
-
"@wagmi/core": "2",
|
|
59
|
-
"viem": "2",
|
|
60
|
-
"wagmi": "2"
|
|
61
|
-
},
|
|
62
57
|
"publishConfig": {
|
|
63
|
-
"access": "public"
|
|
64
|
-
"tag": "beta"
|
|
58
|
+
"access": "public"
|
|
65
59
|
},
|
|
66
60
|
"scripts": {
|
|
67
61
|
"build": "tsc",
|
package/dist/messages.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export type SignalMessageBase<T extends string, P> = {
|
|
2
|
-
type: T;
|
|
3
|
-
payload: P;
|
|
4
|
-
timestamp: number;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Flash message
|
|
8
|
-
* Sent to initiate handshake by non-host
|
|
9
|
-
*/
|
|
10
|
-
export type SignalMessageFlash = SignalMessageBase<"flash", object>;
|
|
11
|
-
export type SignalMessagePubkey = SignalMessageBase<"pubkey", {
|
|
12
|
-
publicKey: string;
|
|
13
|
-
dAppInfo?: {
|
|
14
|
-
name: string;
|
|
15
|
-
url: string;
|
|
16
|
-
icon: string;
|
|
17
|
-
};
|
|
18
|
-
}>;
|
|
19
|
-
export type SignalMessageAck = SignalMessageBase<"ack", undefined>;
|
|
20
|
-
export type SignalMessageData = SignalMessageBase<"data", object>;
|
|
21
|
-
export type SignalMessage = SignalMessageFlash | SignalMessagePubkey | SignalMessageAck | SignalMessageData;
|
package/dist/messages.js
DELETED
package/dist/messages.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"","sourcesContent":["export type SignalMessageBase<T extends string, P> = {\n type: T;\n payload: P;\n timestamp: number;\n};\n\n/**\n * Flash message\n * Sent to initiate handshake by non-host\n */\nexport type SignalMessageFlash = SignalMessageBase<\"flash\", object>;\n\nexport type SignalMessagePubkey = SignalMessageBase<\n \"pubkey\",\n {\n publicKey: string;\n dAppInfo?: {\n name: string;\n url: string;\n icon: string;\n };\n }\n>;\n\nexport type SignalMessageAck = SignalMessageBase<\"ack\", undefined>;\n\nexport type SignalMessageData = SignalMessageBase<\"data\", object>;\n\nexport type SignalMessage =\n | SignalMessageFlash\n | SignalMessagePubkey\n | SignalMessageAck\n | SignalMessageData;\n"]}
|