@corewire/core 0.0.0 → 1.0.0-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.
@@ -0,0 +1,111 @@
1
+ declare namespace aes_d_exports {
2
+ export { decrypt$1 as decrypt, encrypt$1 as encrypt };
3
+ }
4
+ /**
5
+ * AES-128-CTR fallback for legacy HAP pairing. It has no authentication tag; the pairing flow relies on Ed25519 signatures in the TLV payload.
6
+ *
7
+ * @param key - 16-byte AES key.
8
+ * @param iv - 16-byte initialization vector.
9
+ */
10
+ declare function encrypt$1(key: Buffer, iv: Buffer, plaintext: Buffer): Buffer;
11
+ /**
12
+ * Decrypts data using AES-128-CTR.
13
+ *
14
+ * @param key - 16-byte AES key.
15
+ * @param iv - 16-byte initialization vector.
16
+ */
17
+ declare function decrypt$1(key: Buffer, iv: Buffer, ciphertext: Buffer): Buffer;
18
+ declare namespace chacha20_d_exports {
19
+ export { CHACHA20_AUTH_TAG_LENGTH, CHACHA20_NONCE_LENGTH, EncryptedData, decrypt, encrypt, padNonce };
20
+ }
21
+ /** Length in bytes of the Poly1305 authentication tag appended to ciphertext. */
22
+ declare const CHACHA20_AUTH_TAG_LENGTH = 16;
23
+ /** Required nonce length in bytes for ChaCha20-Poly1305. Shorter nonces are zero-padded. */
24
+ declare const CHACHA20_NONCE_LENGTH = 12;
25
+ /**
26
+ * Decrypts a ChaCha20-Poly1305 sealed message and verifies its authentication tag.
27
+ *
28
+ * @param key - 256-bit encryption key.
29
+ * @param nonce - Nonce (up to 12 bytes; shorter nonces are left-padded with zeros).
30
+ * @param aad - Additional authenticated data, or null if none.
31
+ * @param ciphertext - The encrypted payload (without the auth tag).
32
+ * @param authTag - The 16-byte Poly1305 authentication tag.
33
+ * @throws DecryptionError if the authentication tag does not match.
34
+ */
35
+ declare function decrypt(key: Buffer, nonce: Buffer, aad: Buffer | null, ciphertext: Buffer, authTag: Buffer): Buffer;
36
+ /**
37
+ * Encrypts a plaintext message using ChaCha20-Poly1305 authenticated encryption.
38
+ *
39
+ * @param key - 256-bit encryption key.
40
+ * @param nonce - Nonce (up to 12 bytes; shorter nonces are left-padded with zeros).
41
+ * @param aad - Additional authenticated data, or null if none.
42
+ * @returns The ciphertext and its Poly1305 authentication tag.
43
+ */
44
+ declare function encrypt(key: Buffer, nonce: Buffer, aad: Buffer | null, plaintext: Buffer): EncryptedData;
45
+ /** Left-pads a nonce with zero bytes to 12 bytes. A nonce of 12 bytes or more comes back unchanged. */
46
+ declare function padNonce(nonce: Buffer): Buffer;
47
+ /** Output of {@link encrypt}, with the authentication tag split from the ciphertext. */
48
+ type EncryptedData = {
49
+ readonly ciphertext: Buffer; /** The 16-byte Poly1305 tag. */
50
+ readonly authTag: Buffer;
51
+ };
52
+ //#endregion
53
+ //#region src/crypto/types.d.ts
54
+ /** An Ed25519 key pair for signing, or a Curve25519 key pair for key exchange. */
55
+ type KeyPair = {
56
+ readonly publicKey: Uint8Array;
57
+ readonly secretKey: Uint8Array;
58
+ };
59
+ declare namespace curve25519_d_exports {
60
+ export { generateKeyPair$1 as generateKeyPair, generateSharedSecKey };
61
+ }
62
+ /**
63
+ * Generates a new Curve25519 key pair for Diffie-Hellman key exchange.
64
+ */
65
+ declare function generateKeyPair$1(): KeyPair;
66
+ /**
67
+ * Derives a Curve25519 shared secret.
68
+ *
69
+ * @param priKey - Local private key.
70
+ * @param pubKey - Remote public key.
71
+ * @returns 32-byte shared secret.
72
+ */
73
+ declare function generateSharedSecKey(priKey: Uint8Array, pubKey: Uint8Array): Uint8Array;
74
+ declare namespace ed25519_d_exports {
75
+ export { generateKeyPair, sign, verify };
76
+ }
77
+ /**
78
+ * Generates a new Ed25519 key pair for digital signature operations.
79
+ */
80
+ declare function generateKeyPair(): KeyPair;
81
+ /** Signs a message with an Ed25519 secret key and returns the 64-byte signature. */
82
+ declare function sign(message: Uint8Array, secretKey: Uint8Array): Uint8Array;
83
+ /** Checks a 64-byte Ed25519 signature over a message against the signer's public key. */
84
+ declare function verify(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean;
85
+ declare namespace hkdf_d_exports {
86
+ export { HKDFOptions, derive, deriveEncryptionKeys };
87
+ }
88
+ /** Input of an HKDF derivation. */
89
+ type HKDFOptions = {
90
+ /** A Node.js digest name, such as `sha512`. */readonly hash: string; /** The input key material, such as a Diffie-Hellman shared secret. */
91
+ readonly key: Buffer; /** Length of the derived key in bytes. */
92
+ readonly length: number; /** Salt for the extract step; may be empty. */
93
+ readonly salt: Buffer; /** Info for the expand step. */
94
+ readonly info: Buffer;
95
+ };
96
+ /** HKDF key derivation as defined in RFC 5869. */
97
+ declare function derive(options: HKDFOptions): Buffer;
98
+ /**
99
+ * Derives 32-byte read and write keys with HKDF-SHA512. Salt and info strings depend on the protocol and stream.
100
+ *
101
+ * @param sharedSecret - Pair-verify or pair-setup shared secret.
102
+ * @param salt - Protocol-specific salt, such as `Control-Salt`.
103
+ * @param readInfo - Info string for the decrypt key.
104
+ * @param writeInfo - Info string for the encrypt key.
105
+ */
106
+ declare function deriveEncryptionKeys(sharedSecret: Buffer, salt: string, readInfo: string, writeInfo: string): {
107
+ readKey: Buffer;
108
+ writeKey: Buffer;
109
+ };
110
+ //#endregion
111
+ export { aes_d_exports as AES, chacha20_d_exports as ChaCha20, curve25519_d_exports as Curve25519, ed25519_d_exports as Ed25519, hkdf_d_exports as HKDF, type HKDFOptions, type KeyPair };
@@ -0,0 +1,3 @@
1
+ import { c as curve25519_exports, d as chacha20_exports, i as ed25519_exports, m as aes_exports, r as hkdf_exports } from "./crypto-CXSIS6si.mjs";
2
+
3
+ export { aes_exports as AES, chacha20_exports as ChaCha20, curve25519_exports as Curve25519, ed25519_exports as Ed25519, hkdf_exports as HKDF };
@@ -0,0 +1,110 @@
1
+ import { r as Logger } from "./reporter-Dn7n2TXN.mjs";
2
+
3
+ //#region src/discovery/types.d.ts
4
+ /** One service instance that an mDNS scan found. */
5
+ type DiscoveryResult = {
6
+ /** The mDNS host name, e.g. `Woonkamer-TV.local`. */readonly id: string;
7
+ readonly fqdn: string;
8
+ readonly address: string;
9
+ readonly txt: Readonly<Record<string, string>>;
10
+ readonly service: {
11
+ readonly port: number;
12
+ readonly protocol: "tcp" | "udp";
13
+ readonly type: string;
14
+ };
15
+ };
16
+ type DiscoverOptions = {
17
+ /** Reuse a scan that is less than 30 seconds old. Default: true. */readonly useCache?: boolean;
18
+ };
19
+ //#endregion
20
+ //#region src/discovery/discovery.d.ts
21
+ /**
22
+ * Finds the services of one mDNS service type. Each protocol package knows its own service
23
+ * type and what its TXT record means.
24
+ *
25
+ * Results stay cached for 30 seconds per service type, and concurrent scans for the same types
26
+ * share one multicast query. All instances share the cache on purpose, so protocol packages and
27
+ * `@corewire/devices` do not each flood the network with their own query.
28
+ */
29
+ declare class Discovery {
30
+ #private;
31
+ get service(): string;
32
+ /** @param service - The mDNS service type, such as `_hap._tcp.local`. */
33
+ constructor(service: string);
34
+ find(useCache?: boolean): Promise<DiscoveryResult[]>;
35
+ /**
36
+ * Scans again until a device with this id answers. Skips the cache on every attempt.
37
+ *
38
+ * @param timeout - Delay in milliseconds between attempts.
39
+ * @throws {DiscoveryError} If the device does not answer within `tries` attempts.
40
+ */
41
+ findUntil(id: string, tries?: number, timeout?: number): Promise<DiscoveryResult>;
42
+ /**
43
+ * Queries one host with unicast DNS-SD, bypassing the cache.
44
+ *
45
+ * @param timeout - Discovery duration in seconds.
46
+ * @param wakePorts - Ports to knock on first, to wake a sleeping device.
47
+ */
48
+ findByAddress(address: string, timeout?: number, wakePorts?: readonly number[]): Promise<DiscoveryResult | null>;
49
+ /** Scans for several service types with one multicast query, shared with a scan in flight for the same types. */
50
+ static findServices(services: readonly string[], useCache?: boolean): Promise<Map<string, DiscoveryResult[]>>;
51
+ static clearCache(): void;
52
+ /** Knocks on each port to wake a sleeping device. */
53
+ static wake(address: string, ports: readonly number[]): Promise<void>;
54
+ }
55
+ //#endregion
56
+ //#region src/discovery/mdns.d.ts
57
+ /** An mDNS service instance, resolved to an address and port. */
58
+ type MdnsService = {
59
+ readonly name: string;
60
+ readonly type: string;
61
+ readonly address: string;
62
+ readonly port: number;
63
+ readonly properties: Record<string, string>;
64
+ };
65
+ /**
66
+ * Queries hosts with unicast DNS-SD. It knocks on the `wakePorts` of each host first, then
67
+ * sends the queries to port 5353 of each host every second. It stops when `timeout` ends or
68
+ * every host answered for every service.
69
+ *
70
+ * @param hosts - IP addresses of the hosts to query.
71
+ * @param timeout - Duration in seconds.
72
+ */
73
+ declare function mdnsUnicast(hosts: string[], services: string[], timeout?: number, wakePorts?: readonly number[]): Promise<MdnsService[]>;
74
+ /**
75
+ * Discovers services with multicast DNS-SD on every local interface. It binds port 5353 when
76
+ * it can, plus one socket on a random port per interface.
77
+ *
78
+ * @param timeout - Duration in seconds.
79
+ */
80
+ declare function mdnsMulticast(services: string[], timeout?: number): Promise<MdnsService[]>;
81
+ //#endregion
82
+ //#region src/discovery/responder.d.ts
83
+ /** The service that an {@link MdnsResponder} advertises. */
84
+ type AdvertisedService = {
85
+ /** The DNS-SD instance name, which controllers show to the user. */readonly instance: string; /** The service type, such as `_companion-link._tcp.local`. */
86
+ readonly type: string; /** The host name that the SRV and A records publish, ending in `.local`. */
87
+ readonly host: string; /** The TCP port the service listens on. */
88
+ readonly port: number; /** The properties of the TXT record. An empty value publishes the bare key. */
89
+ readonly txt: Record<string, string>;
90
+ };
91
+ /**
92
+ * Advertises one service with PTR, SRV, TXT and A records every 2 seconds, and again on each
93
+ * query that mentions its type. It does not parse DNS questions, so it suits quiet test networks.
94
+ * A controller can need the instance name and TXT record of a real device before it lists the service.
95
+ */
96
+ declare class MdnsResponder {
97
+ #private;
98
+ /**
99
+ * @param address - The local IPv4 address that the A record publishes.
100
+ */
101
+ constructor(logger: Logger, service: AdvertisedService, address?: string);
102
+ /** Returns the first non-internal IPv4 address of this host, or `0.0.0.0` if none is found. */
103
+ static localAddress(): string;
104
+ /** Binds the multicast socket and announces the service every 2 seconds. */
105
+ start(): void;
106
+ /** Stops announcing and closes the socket. */
107
+ stop(): void;
108
+ }
109
+ //#endregion
110
+ export { type AdvertisedService, type DiscoverOptions, Discovery, type DiscoveryResult, MdnsResponder, type MdnsService, mdnsMulticast, mdnsUnicast };