@dengxifeng/davey 0.1.9

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/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Davey!
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@snazzah/davey?maxAge=3600)](https://www.npmjs.com/package/@snazzah/davey) [![install size](https://packagephobia.com/badge?p=@snazzah/davey)](https://packagephobia.com/result?p=@snazzah/davey) [![NPM downloads](https://img.shields.io/npm/dt/@snazzah/davey?maxAge=3600)](https://www.npmjs.com/package/@snazzah/davey) [![discord chat](https://img.shields.io/discord/311027228177727508?logo=discord&logoColor=white&color=5865F2)](https://snaz.in/discord)
4
+
5
+ A [Discord Audio & Video End-to-End Encryption (DAVE) Protocol](https://daveprotocol.com/) implementation using [OpenMLS](https://openmls.tech/) built with [NAPI-RS](https://napi.rs/).
6
+
7
+ > Proper documentation does not exist yet, but you can [read the usage document](https://github.com/Snazzah/davey/blob/master/docs/USAGE.md) and review the [type definitions](https://github.com/Snazzah/davey/blob/master/index.d.ts) for available methods.
8
+
9
+ ```ts
10
+ import { DAVESession, ProposalsOperationType, MediaType, Codec } from '@snazzah/davey';
11
+
12
+ const session = new DAVESession(
13
+ 1, // dave version
14
+ '158049329150427136', // user id
15
+ '927310423890473011', // channel id
16
+ );
17
+
18
+ // Set the external sender of the session from opcode 25
19
+ session.setExternalSender(externalSenderBuffer);
20
+
21
+ // Get the key package buffer to send to Discord
22
+ session.getSerializedKeyPackage();
23
+
24
+ // Process a proposals
25
+ session.processProposals(
26
+ ProposalsOperationType.APPEND, // the type of proposals operation
27
+ proposalsBuffer, // proposals or proposal refs buffer
28
+ recognizedUserIds, // an array of user IDs in the session, optional but recommended
29
+ );
30
+
31
+ // Process a commit
32
+ session.processCommit(commitBuffer);
33
+
34
+ // Process a welcome
35
+ session.processWelcome(welcomeBuffer);
36
+
37
+ // The current voice privacy code of the session, updated after a commit/welcome
38
+ session.voicePrivacyCode; // a 30 digit string or an empty string for not started sessions
39
+
40
+ // Encrypt/decrypt voice packets
41
+ if (session.ready) {
42
+ // Encrypt packets with a specified media type and codec, use this before transport encryption
43
+ session.encrypt(MediaType.AUDIO, Codec.OPUS, packet);
44
+ // Really only opus is supported right now so just use the shorthand method
45
+ session.encryptOpus(packet);
46
+ // Decrypt a packet from a user, use this after transport decryption
47
+ session.decrypt(userId, MediaType.AUDIO, incomingPacket);
48
+ }
49
+ ```
50
+
51
+ #### References
52
+
53
+ - [daveprotocol.com](https://daveprotocol.com/)
54
+ - [discord/libdave](https://github.com/discord/libdave)
55
+ - [Discord Dev Docs - Voice - E2EE](https://discord.com/developers/docs/topics/voice-connections#endtoend-encryption-dave-protocol)
56
+ - [NAPI-RS](https://napi.rs/docs/introduction/getting-started)
57
+ - [OpenMLS Book](https://book.openmls.tech/introduction.html)
58
+ - [Voice Model - High Level Summary - DPP](https://dpp.dev/voice-model.html)
package/browser.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@snazzah/davey-wasm32-wasi'
package/index.d.ts ADDED
@@ -0,0 +1,260 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ /** The type of codec being used. */
4
+ export declare const enum Codec {
5
+ UNKNOWN = 0,
6
+ OPUS = 1,
7
+ VP8 = 2,
8
+ VP9 = 3,
9
+ H264 = 4,
10
+ H265 = 5,
11
+ AV1 = 6
12
+ }
13
+
14
+ /** The maximum supported version of the DAVE protocol. */
15
+ export const DAVE_PROTOCOL_VERSION: number
16
+
17
+ export interface DecryptionStats {
18
+ /** Number of decryption successes */
19
+ successes: number
20
+ /** Number of decryption failures */
21
+ failures: number
22
+ /** Total decryption duration in microseconds */
23
+ duration: number
24
+ /** Total amounts of decryption attempts */
25
+ attempts: number
26
+ /** Total amounts of packets that passed through */
27
+ passthroughs: number
28
+ }
29
+
30
+ export interface EncryptionStats {
31
+ /** Number of encryption successes */
32
+ successes: number
33
+ /** Number of encryption failures */
34
+ failures: number
35
+ /** Total encryption duration in microseconds */
36
+ duration: number
37
+ /** Total amounts of encryption attempts */
38
+ attempts: number
39
+ /** Maximum attempts reached at encryption */
40
+ maxAttempts: number
41
+ }
42
+
43
+ /** The type of media being referenced. */
44
+ export declare const enum MediaType {
45
+ AUDIO = 0,
46
+ VIDEO = 1
47
+ }
48
+
49
+ /**
50
+ * The operation type of the proposals payload.
51
+ * @see https://daveprotocol.com/#dave_mls_proposals-27
52
+ */
53
+ export declare const enum ProposalsOperationType {
54
+ APPEND = 0,
55
+ REVOKE = 1
56
+ }
57
+
58
+ /** The status of the DAVE session. */
59
+ export declare const enum SessionStatus {
60
+ INACTIVE = 0,
61
+ PENDING = 1,
62
+ AWAITING_RESPONSE = 2,
63
+ ACTIVE = 3
64
+ }
65
+ export declare class DAVESession {
66
+ /**
67
+ * @param protocolVersion The protocol version to use.
68
+ * @param userId The user ID of the session.
69
+ * @param channelId The channel ID of the session.
70
+ * @param keyPair The key pair to use for this session. Will generate a new one if not specified.
71
+ */
72
+ constructor(protocolVersion: number, userId: string, channelId: string, keyPair?: SigningKeyPair | undefined | null)
73
+ /**
74
+ * Resets and re-initializes the session.
75
+ * @param protocolVersion The protocol version to use.
76
+ * @param userId The user ID of the session.
77
+ * @param channelId The channel ID of the session.
78
+ * @param keyPair The key pair to use for this session. Will generate a new one if not specified.
79
+ */
80
+ reinit(protocolVersion: number, userId: string, channelId: string, keyPair?: SigningKeyPair | undefined | null): void
81
+ /**
82
+ * Resets the session by deleting the group and clearing the storage.
83
+ * If you want to re-initialize the session, use {@link reinit}.
84
+ */
85
+ reset(): void
86
+ /** The DAVE protocol version used for this session. */
87
+ get protocolVersion(): number
88
+ /** The user ID for this session. */
89
+ get userId(): string
90
+ /** The channel ID (group ID in MLS standards) for this session. */
91
+ get channelId(): string
92
+ /** The epoch for this session, `undefined` if there is no group yet. */
93
+ get epoch(): bigint | null
94
+ /** Your own leaf index for this session, `undefined` if there is no group yet. */
95
+ get ownLeafIndex(): number | null
96
+ /** The ciphersuite being used in this session. */
97
+ get ciphersuite(): number
98
+ /** The current status of the session. */
99
+ get status(): SessionStatus
100
+ /** Whether the session is ready to encrypt/decrypt. */
101
+ get ready(): boolean
102
+ /** Get the epoch authenticator of this session's group. */
103
+ getEpochAuthenticator(): Buffer | null
104
+ /**
105
+ * Get the voice privacy code of this session's group.
106
+ * The result of this is created and cached each time a new transition is executed.
107
+ * This is the equivalent of `generateDisplayableCode(epochAuthenticator, 30, 5)`.
108
+ * @returns The current voice privacy code, or an empty string if the session is not active.
109
+ * @see https://daveprotocol.com/#displayable-codes
110
+ */
111
+ get voicePrivacyCode(): string
112
+ /**
113
+ * Set the external sender this session will recieve from.
114
+ * @param externalSenderData The serialized external sender data.
115
+ * @throws Will throw if the external sender is invalid, or if the group has been established already.
116
+ * @see https://daveprotocol.com/#dave_mls_external_sender_package-25
117
+ */
118
+ setExternalSender(externalSenderData: Buffer): void
119
+ /**
120
+ * Create, store, and return the serialized key package buffer.
121
+ * Key packages are not meant to be reused, and will be recreated on each call of this function.
122
+ */
123
+ getSerializedKeyPackage(): Buffer
124
+ /**
125
+ * Process proposals from the voice server.
126
+ * @param operationType The operation type of the proposals.
127
+ * @param proposals The vector of proposals or proposal refs of the payload. (depending on operation type)
128
+ * @param recognizedUserIds The recognized set of user IDs gathered from the voice gateway. Recommended to set so that incoming users are checked against.
129
+ * @returns A commit (if there were queued proposals) and a welcome (if a member was added) that should be used to send an [opcode 28: dave_mls_commit_welcome](https://daveprotocol.com/#dave_mls_commit_welcome-28) ONLY if a commit was returned.
130
+ * @see https://daveprotocol.com/#dave_mls_proposals-27
131
+ */
132
+ processProposals(operationType: ProposalsOperationType, proposals: Buffer, recognizedUserIds?: Array<string> | undefined | null): ProposalsResult
133
+ /**
134
+ * Process a welcome message.
135
+ * @param welcome The welcome message to process.
136
+ * @throws Will throw an error if the welcome is invalid. Send an [opcode 31: dave_mls_invalid_commit_welcome](https://daveprotocol.com/#dave_mls_invalid_commit_welcome-31) if this occurs.
137
+ * @see https://daveprotocol.com/#dave_mls_welcome-30
138
+ */
139
+ processWelcome(welcome: Buffer): void
140
+ /**
141
+ * Process a commit.
142
+ * @param commit The commit to process.
143
+ * @throws Will throw an error if the commit is invalid. Send an [opcode 31: dave_mls_invalid_commit_welcome](https://daveprotocol.com/#dave_mls_invalid_commit_welcome-31) if this occurs.
144
+ * @see https://daveprotocol.com/#dave_mls_announce_commit_transition-29
145
+ */
146
+ processCommit(commit: Buffer): void
147
+ /**
148
+ * Get the verification code of another member of the group.
149
+ * This is the equivalent of `generateDisplayableCode(getPairwiseFingerprint(0, userId), 45, 5)`.
150
+ * @see https://daveprotocol.com/#displayable-codes
151
+ */
152
+ getVerificationCode(userId: string): Promise<string>
153
+ /**
154
+ * Create a pairwise fingerprint of you and another member.
155
+ * @see https://daveprotocol.com/#verification-fingerprint
156
+ */
157
+ getPairwiseFingerprint(version: number, userId: string): Promise<Buffer>
158
+ /**
159
+ * End-to-end encrypt a packet.
160
+ * @param mediaType The type of media to encrypt
161
+ * @param codec The codec of the packet
162
+ * @param packet The packet to encrypt
163
+ */
164
+ encrypt(mediaType: MediaType, codec: Codec, packet: Buffer): Buffer
165
+ /**
166
+ * End-to-end encrypt an opus packet.
167
+ * This is the shorthand for `encrypt(MediaType.AUDIO, Codec.OPUS, packet)`
168
+ * @param packet The packet to encrypt
169
+ */
170
+ encryptOpus(packet: Buffer): Buffer
171
+ /**
172
+ * Get encryption stats.
173
+ * @param [mediaType=MediaType.AUDIO] The media type, defaults to `MediaType.AUDIO`
174
+ */
175
+ getEncryptionStats(mediaType?: MediaType | undefined | null): EncryptionStats | null
176
+ /**
177
+ * Decrypt an end-to-end encrypted packet.
178
+ * @param userId The user ID of the packet
179
+ * @param mediaType The type of media to decrypt
180
+ * @param packet The packet to decrypt
181
+ */
182
+ decrypt(userId: string, mediaType: MediaType, packet: Buffer): Buffer
183
+ /**
184
+ * Get decryption stats.
185
+ * @param userId The user ID
186
+ * @param [mediaType=MediaType.AUDIO] The media type, defaults to `MediaType.AUDIO`
187
+ */
188
+ getDecryptionStats(userId: string, mediaType?: MediaType | undefined | null): DecryptionStats | null
189
+ /**
190
+ * Get the IDs of the users in the current group.
191
+ * @returns An array of user IDs, or an empty array if there is no group.
192
+ */
193
+ getUserIds(): Array<string>
194
+ /**
195
+ * Check whether this user's decryptor is in passthrough mode.
196
+ * If passthrough mode is enabled, then unencrypted packets are allowed to be passed through the decryptor.
197
+ * @param userId The user ID
198
+ */
199
+ canPassthrough(userId: string): boolean
200
+ /**
201
+ * Set whether passthrough mode is enabled on all decryptors.
202
+ * @param passthroughMode Whether to enable passthrough mode
203
+ * @param [transitionExpiry=10] The transition expiry (in seconds) to use when disabling passthrough mode, defaults to 10 seconds
204
+ */
205
+ setPassthroughMode(passthroughMode: boolean, transitionExpiry?: number | undefined | null): void
206
+ /** @ignore */
207
+ toString(): string
208
+ }
209
+ export type DaveSession = DAVESession
210
+
211
+ /** Whether davey is using a debug build. */
212
+ export const DEBUG_BUILD: boolean
213
+
214
+ /**
215
+ * Generate a displayable code.
216
+ * @see https://daveprotocol.com/#displayable-codes
217
+ * @param data The data to generate a code with
218
+ * @param desiredLength The desired length of the code
219
+ * @param groupSize The group size of the code
220
+ */
221
+ export declare function generateDisplayableCode(data: Buffer, desiredLength: number, groupSize: number): string
222
+
223
+ /**
224
+ * Generate a key fingerprint.
225
+ * @see https://daveprotocol.com/#verification-fingerprint
226
+ * @param version The version of the fingerprint
227
+ * @param key The key to fingerprint
228
+ * @param userId The user ID of this fingerprint
229
+ */
230
+ export declare function generateKeyFingerprint(version: number, key: Buffer, userId: string): Buffer
231
+
232
+ /** Create a P256 signing key pair. */
233
+ export declare function generateP256Keypair(): SigningKeyPair
234
+
235
+ /**
236
+ * Generate a pairwise fingerprint.
237
+ * @see https://daveprotocol.com/#verification-fingerprint
238
+ * @param version The version of the fingerprint
239
+ * @param localKey The local user's key
240
+ * @param localKeyId The local user's ID
241
+ * @param remoteKey The remote user's key
242
+ * @param remoteKeyId The remote user's ID
243
+ */
244
+ export declare function generatePairwiseFingerprint(version: number, localKey: Buffer, localUserId: string, remoteKey: Buffer, remoteUserId: string): Promise<Buffer>
245
+
246
+ export interface ProposalsResult {
247
+ commit?: Buffer
248
+ welcome?: Buffer
249
+ }
250
+
251
+ /** A signing key pair. */
252
+ export interface SigningKeyPair {
253
+ /** The private key of this key pair. */
254
+ private: Buffer
255
+ /** The public key of this key pair. */
256
+ public: Buffer
257
+ }
258
+
259
+ /** The version of the davey package being used. */
260
+ export const VERSION: string
package/index.js ADDED
@@ -0,0 +1,523 @@
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ const { createRequire } = require('node:module')
7
+ require = createRequire(__filename)
8
+
9
+ const { readFileSync } = require('node:fs')
10
+ let nativeBinding = null
11
+ const loadErrors = []
12
+
13
+ const isMusl = () => {
14
+ let musl = false
15
+ if (process.platform === 'linux') {
16
+ musl = isMuslFromFilesystem()
17
+ if (musl === null) {
18
+ musl = isMuslFromReport()
19
+ }
20
+ if (musl === null) {
21
+ musl = isMuslFromChildProcess()
22
+ }
23
+ }
24
+ return musl
25
+ }
26
+
27
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
28
+
29
+ const isMuslFromFilesystem = () => {
30
+ try {
31
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
32
+ } catch {
33
+ return null
34
+ }
35
+ }
36
+
37
+ const isMuslFromReport = () => {
38
+ let report = null
39
+ if (typeof process.report?.getReport === 'function') {
40
+ process.report.excludeNetwork = true
41
+ report = process.report.getReport()
42
+ }
43
+ if (!report) {
44
+ return null
45
+ }
46
+ if (report.header && report.header.glibcVersionRuntime) {
47
+ return false
48
+ }
49
+ if (Array.isArray(report.sharedObjects)) {
50
+ if (report.sharedObjects.some(isFileMusl)) {
51
+ return true
52
+ }
53
+ }
54
+ return false
55
+ }
56
+
57
+ const isMuslFromChildProcess = () => {
58
+ try {
59
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
60
+ } catch (e) {
61
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
62
+ return false
63
+ }
64
+ }
65
+
66
+ function requireNative() {
67
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
68
+ try {
69
+ nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
70
+ } catch (err) {
71
+ loadErrors.push(err)
72
+ }
73
+ } else if (process.platform === 'android') {
74
+ if (process.arch === 'arm64') {
75
+ try {
76
+ return require('./davey.android-arm64.node')
77
+ } catch (e) {
78
+ loadErrors.push(e)
79
+ }
80
+ try {
81
+ const binding = require('@snazzah/davey-android-arm64')
82
+ const bindingPackageVersion = require('@snazzah/davey-android-arm64/package.json').version
83
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
84
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
85
+ }
86
+ return binding
87
+ } catch (e) {
88
+ loadErrors.push(e)
89
+ }
90
+ } else if (process.arch === 'arm') {
91
+ try {
92
+ return require('./davey.android-arm-eabi.node')
93
+ } catch (e) {
94
+ loadErrors.push(e)
95
+ }
96
+ try {
97
+ const binding = require('@snazzah/davey-android-arm-eabi')
98
+ const bindingPackageVersion = require('@snazzah/davey-android-arm-eabi/package.json').version
99
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
100
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
101
+ }
102
+ return binding
103
+ } catch (e) {
104
+ loadErrors.push(e)
105
+ }
106
+ } else {
107
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
108
+ }
109
+ } else if (process.platform === 'win32') {
110
+ if (process.arch === 'x64') {
111
+ try {
112
+ return require('./davey.win32-x64-msvc.node')
113
+ } catch (e) {
114
+ loadErrors.push(e)
115
+ }
116
+ try {
117
+ const binding = require('@snazzah/davey-win32-x64-msvc')
118
+ const bindingPackageVersion = require('@snazzah/davey-win32-x64-msvc/package.json').version
119
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
120
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
121
+ }
122
+ return binding
123
+ } catch (e) {
124
+ loadErrors.push(e)
125
+ }
126
+ } else if (process.arch === 'ia32') {
127
+ try {
128
+ return require('./davey.win32-ia32-msvc.node')
129
+ } catch (e) {
130
+ loadErrors.push(e)
131
+ }
132
+ try {
133
+ const binding = require('@snazzah/davey-win32-ia32-msvc')
134
+ const bindingPackageVersion = require('@snazzah/davey-win32-ia32-msvc/package.json').version
135
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
136
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
137
+ }
138
+ return binding
139
+ } catch (e) {
140
+ loadErrors.push(e)
141
+ }
142
+ } else if (process.arch === 'arm64') {
143
+ try {
144
+ return require('./davey.win32-arm64-msvc.node')
145
+ } catch (e) {
146
+ loadErrors.push(e)
147
+ }
148
+ try {
149
+ const binding = require('@snazzah/davey-win32-arm64-msvc')
150
+ const bindingPackageVersion = require('@snazzah/davey-win32-arm64-msvc/package.json').version
151
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
152
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
153
+ }
154
+ return binding
155
+ } catch (e) {
156
+ loadErrors.push(e)
157
+ }
158
+ } else {
159
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
160
+ }
161
+ } else if (process.platform === 'darwin') {
162
+ try {
163
+ return require('./davey.darwin-universal.node')
164
+ } catch (e) {
165
+ loadErrors.push(e)
166
+ }
167
+ try {
168
+ const binding = require('@snazzah/davey-darwin-universal')
169
+ const bindingPackageVersion = require('@snazzah/davey-darwin-universal/package.json').version
170
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
172
+ }
173
+ return binding
174
+ } catch (e) {
175
+ loadErrors.push(e)
176
+ }
177
+ if (process.arch === 'x64') {
178
+ try {
179
+ return require('./davey.darwin-x64.node')
180
+ } catch (e) {
181
+ loadErrors.push(e)
182
+ }
183
+ try {
184
+ const binding = require('@snazzah/davey-darwin-x64')
185
+ const bindingPackageVersion = require('@snazzah/davey-darwin-x64/package.json').version
186
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
187
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
188
+ }
189
+ return binding
190
+ } catch (e) {
191
+ loadErrors.push(e)
192
+ }
193
+ } else if (process.arch === 'arm64') {
194
+ try {
195
+ return require('./davey.darwin-arm64.node')
196
+ } catch (e) {
197
+ loadErrors.push(e)
198
+ }
199
+ try {
200
+ const binding = require('@snazzah/davey-darwin-arm64')
201
+ const bindingPackageVersion = require('@snazzah/davey-darwin-arm64/package.json').version
202
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
203
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
204
+ }
205
+ return binding
206
+ } catch (e) {
207
+ loadErrors.push(e)
208
+ }
209
+ } else {
210
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
211
+ }
212
+ } else if (process.platform === 'freebsd') {
213
+ if (process.arch === 'x64') {
214
+ try {
215
+ return require('./davey.freebsd-x64.node')
216
+ } catch (e) {
217
+ loadErrors.push(e)
218
+ }
219
+ try {
220
+ const binding = require('@snazzah/davey-freebsd-x64')
221
+ const bindingPackageVersion = require('@snazzah/davey-freebsd-x64/package.json').version
222
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
223
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
224
+ }
225
+ return binding
226
+ } catch (e) {
227
+ loadErrors.push(e)
228
+ }
229
+ } else if (process.arch === 'arm64') {
230
+ try {
231
+ return require('./davey.freebsd-arm64.node')
232
+ } catch (e) {
233
+ loadErrors.push(e)
234
+ }
235
+ try {
236
+ const binding = require('@snazzah/davey-freebsd-arm64')
237
+ const bindingPackageVersion = require('@snazzah/davey-freebsd-arm64/package.json').version
238
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
239
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
240
+ }
241
+ return binding
242
+ } catch (e) {
243
+ loadErrors.push(e)
244
+ }
245
+ } else {
246
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
247
+ }
248
+ } else if (process.platform === 'linux') {
249
+ if (process.arch === 'x64') {
250
+ if (isMusl()) {
251
+ try {
252
+ return require('./davey.linux-x64-musl.node')
253
+ } catch (e) {
254
+ loadErrors.push(e)
255
+ }
256
+ try {
257
+ const binding = require('@snazzah/davey-linux-x64-musl')
258
+ const bindingPackageVersion = require('@snazzah/davey-linux-x64-musl/package.json').version
259
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
260
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
261
+ }
262
+ return binding
263
+ } catch (e) {
264
+ loadErrors.push(e)
265
+ }
266
+ } else {
267
+ try {
268
+ return require('./davey.linux-x64-gnu.node')
269
+ } catch (e) {
270
+ loadErrors.push(e)
271
+ }
272
+ try {
273
+ const binding = require('@snazzah/davey-linux-x64-gnu')
274
+ const bindingPackageVersion = require('@snazzah/davey-linux-x64-gnu/package.json').version
275
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
276
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
277
+ }
278
+ return binding
279
+ } catch (e) {
280
+ loadErrors.push(e)
281
+ }
282
+ }
283
+ } else if (process.arch === 'arm64') {
284
+ if (isMusl()) {
285
+ try {
286
+ return require('./davey.linux-arm64-musl.node')
287
+ } catch (e) {
288
+ loadErrors.push(e)
289
+ }
290
+ try {
291
+ const binding = require('@snazzah/davey-linux-arm64-musl')
292
+ const bindingPackageVersion = require('@snazzah/davey-linux-arm64-musl/package.json').version
293
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
294
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
295
+ }
296
+ return binding
297
+ } catch (e) {
298
+ loadErrors.push(e)
299
+ }
300
+ } else {
301
+ try {
302
+ return require('./davey.linux-arm64-gnu.node')
303
+ } catch (e) {
304
+ loadErrors.push(e)
305
+ }
306
+ try {
307
+ const binding = require('@snazzah/davey-linux-arm64-gnu')
308
+ const bindingPackageVersion = require('@snazzah/davey-linux-arm64-gnu/package.json').version
309
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
310
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
311
+ }
312
+ return binding
313
+ } catch (e) {
314
+ loadErrors.push(e)
315
+ }
316
+ }
317
+ } else if (process.arch === 'arm') {
318
+ if (isMusl()) {
319
+ try {
320
+ return require('./davey.linux-arm-musleabihf.node')
321
+ } catch (e) {
322
+ loadErrors.push(e)
323
+ }
324
+ try {
325
+ const binding = require('@snazzah/davey-linux-arm-musleabihf')
326
+ const bindingPackageVersion = require('@snazzah/davey-linux-arm-musleabihf/package.json').version
327
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
328
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
329
+ }
330
+ return binding
331
+ } catch (e) {
332
+ loadErrors.push(e)
333
+ }
334
+ } else {
335
+ try {
336
+ return require('./davey.linux-arm-gnueabihf.node')
337
+ } catch (e) {
338
+ loadErrors.push(e)
339
+ }
340
+ try {
341
+ const binding = require('@snazzah/davey-linux-arm-gnueabihf')
342
+ const bindingPackageVersion = require('@snazzah/davey-linux-arm-gnueabihf/package.json').version
343
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
344
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
345
+ }
346
+ return binding
347
+ } catch (e) {
348
+ loadErrors.push(e)
349
+ }
350
+ }
351
+ } else if (process.arch === 'riscv64') {
352
+ if (isMusl()) {
353
+ try {
354
+ return require('./davey.linux-riscv64-musl.node')
355
+ } catch (e) {
356
+ loadErrors.push(e)
357
+ }
358
+ try {
359
+ const binding = require('@snazzah/davey-linux-riscv64-musl')
360
+ const bindingPackageVersion = require('@snazzah/davey-linux-riscv64-musl/package.json').version
361
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
362
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
363
+ }
364
+ return binding
365
+ } catch (e) {
366
+ loadErrors.push(e)
367
+ }
368
+ } else {
369
+ try {
370
+ return require('./davey.linux-riscv64-gnu.node')
371
+ } catch (e) {
372
+ loadErrors.push(e)
373
+ }
374
+ try {
375
+ const binding = require('@snazzah/davey-linux-riscv64-gnu')
376
+ const bindingPackageVersion = require('@snazzah/davey-linux-riscv64-gnu/package.json').version
377
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
378
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
379
+ }
380
+ return binding
381
+ } catch (e) {
382
+ loadErrors.push(e)
383
+ }
384
+ }
385
+ } else if (process.arch === 'ppc64') {
386
+ try {
387
+ return require('./davey.linux-ppc64-gnu.node')
388
+ } catch (e) {
389
+ loadErrors.push(e)
390
+ }
391
+ try {
392
+ const binding = require('@snazzah/davey-linux-ppc64-gnu')
393
+ const bindingPackageVersion = require('@snazzah/davey-linux-ppc64-gnu/package.json').version
394
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
395
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
396
+ }
397
+ return binding
398
+ } catch (e) {
399
+ loadErrors.push(e)
400
+ }
401
+ } else if (process.arch === 's390x') {
402
+ try {
403
+ return require('./davey.linux-s390x-gnu.node')
404
+ } catch (e) {
405
+ loadErrors.push(e)
406
+ }
407
+ try {
408
+ const binding = require('@snazzah/davey-linux-s390x-gnu')
409
+ const bindingPackageVersion = require('@snazzah/davey-linux-s390x-gnu/package.json').version
410
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
+ }
413
+ return binding
414
+ } catch (e) {
415
+ loadErrors.push(e)
416
+ }
417
+ } else {
418
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
419
+ }
420
+ } else if (process.platform === 'openharmony') {
421
+ if (process.arch === 'arm64') {
422
+ try {
423
+ return require('./davey.openharmony-arm64.node')
424
+ } catch (e) {
425
+ loadErrors.push(e)
426
+ }
427
+ try {
428
+ const binding = require('@snazzah/davey-openharmony-arm64')
429
+ const bindingPackageVersion = require('@snazzah/davey-openharmony-arm64/package.json').version
430
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
431
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
432
+ }
433
+ return binding
434
+ } catch (e) {
435
+ loadErrors.push(e)
436
+ }
437
+ } else if (process.arch === 'x64') {
438
+ try {
439
+ return require('./davey.openharmony-x64.node')
440
+ } catch (e) {
441
+ loadErrors.push(e)
442
+ }
443
+ try {
444
+ const binding = require('@snazzah/davey-openharmony-x64')
445
+ const bindingPackageVersion = require('@snazzah/davey-openharmony-x64/package.json').version
446
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
447
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
448
+ }
449
+ return binding
450
+ } catch (e) {
451
+ loadErrors.push(e)
452
+ }
453
+ } else if (process.arch === 'arm') {
454
+ try {
455
+ return require('./davey.openharmony-arm.node')
456
+ } catch (e) {
457
+ loadErrors.push(e)
458
+ }
459
+ try {
460
+ const binding = require('@snazzah/davey-openharmony-arm')
461
+ const bindingPackageVersion = require('@snazzah/davey-openharmony-arm/package.json').version
462
+ if (bindingPackageVersion !== '0.1.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
463
+ throw new Error(`Native binding package version mismatch, expected 0.1.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
464
+ }
465
+ return binding
466
+ } catch (e) {
467
+ loadErrors.push(e)
468
+ }
469
+ } else {
470
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
471
+ }
472
+ } else {
473
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
474
+ }
475
+ }
476
+
477
+ nativeBinding = requireNative()
478
+
479
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
480
+ try {
481
+ nativeBinding = require('./davey.wasi.cjs')
482
+ } catch (err) {
483
+ if (process.env.NAPI_RS_FORCE_WASI) {
484
+ loadErrors.push(err)
485
+ }
486
+ }
487
+ if (!nativeBinding) {
488
+ try {
489
+ nativeBinding = require('@snazzah/davey-wasm32-wasi')
490
+ } catch (err) {
491
+ if (process.env.NAPI_RS_FORCE_WASI) {
492
+ loadErrors.push(err)
493
+ }
494
+ }
495
+ }
496
+ }
497
+
498
+ if (!nativeBinding) {
499
+ if (loadErrors.length > 0) {
500
+ throw new Error(
501
+ `Cannot find native binding. ` +
502
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
503
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
504
+ { cause: loadErrors }
505
+ )
506
+ }
507
+ throw new Error(`Failed to load native binding`)
508
+ }
509
+
510
+ module.exports = nativeBinding
511
+ module.exports.Codec = nativeBinding.Codec
512
+ module.exports.DAVE_PROTOCOL_VERSION = nativeBinding.DAVE_PROTOCOL_VERSION
513
+ module.exports.MediaType = nativeBinding.MediaType
514
+ module.exports.ProposalsOperationType = nativeBinding.ProposalsOperationType
515
+ module.exports.SessionStatus = nativeBinding.SessionStatus
516
+ module.exports.DAVESession = nativeBinding.DAVESession
517
+ module.exports.DaveSession = nativeBinding.DaveSession
518
+ module.exports.DEBUG_BUILD = nativeBinding.DEBUG_BUILD
519
+ module.exports.generateDisplayableCode = nativeBinding.generateDisplayableCode
520
+ module.exports.generateKeyFingerprint = nativeBinding.generateKeyFingerprint
521
+ module.exports.generateP256Keypair = nativeBinding.generateP256Keypair
522
+ module.exports.generatePairwiseFingerprint = nativeBinding.generatePairwiseFingerprint
523
+ module.exports.VERSION = nativeBinding.VERSION
package/package.json ADDED
@@ -0,0 +1,135 @@
1
+ {
2
+ "name": "@dengxifeng/davey",
3
+ "version": "0.1.9",
4
+ "description": "DAVE protocol implementation",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "browser": "browser.js",
8
+ "repository": "https://github.com/Snazzah/davey",
9
+ "license": "MIT",
10
+ "author": {
11
+ "name": "Snazzah",
12
+ "email": "me@snazzah.com",
13
+ "url": "https://snazzah.com/"
14
+ },
15
+ "funding": {
16
+ "url": "https://github.com/sponsors/Snazzah"
17
+ },
18
+ "keywords": [
19
+ "discord",
20
+ "e2ee",
21
+ "mls",
22
+ "napi-rs",
23
+ "NAPI",
24
+ "N-API",
25
+ "Rust",
26
+ "node-addon",
27
+ "node-addon-api"
28
+ ],
29
+ "files": [
30
+ "index.d.ts",
31
+ "index.js",
32
+ "browser.js"
33
+ ],
34
+ "napi": {
35
+ "binaryName": "davey",
36
+ "targets": [
37
+ "x86_64-apple-darwin",
38
+ "aarch64-apple-darwin",
39
+ "x86_64-unknown-linux-gnu",
40
+ "x86_64-pc-windows-msvc",
41
+ "x86_64-unknown-linux-musl",
42
+ "aarch64-unknown-linux-gnu",
43
+ "i686-pc-windows-msvc",
44
+ "armv7-unknown-linux-gnueabihf",
45
+ "aarch64-linux-android",
46
+ "x86_64-unknown-freebsd",
47
+ "aarch64-unknown-linux-musl",
48
+ "aarch64-pc-windows-msvc",
49
+ "armv7-linux-androideabi",
50
+ "riscv64gc-unknown-linux-gnu",
51
+ "wasm32-wasi-preview1-threads"
52
+ ]
53
+ },
54
+ "engines": {
55
+ "node": ">= 10"
56
+ },
57
+ "publishConfig": {
58
+ "registry": "https://registry.npmjs.org/",
59
+ "access": "public"
60
+ },
61
+ "devDependencies": {
62
+ "@emnapi/core": "^1.3.1",
63
+ "@emnapi/runtime": "^1.3.1",
64
+ "@napi-rs/cli": "^3.1.5",
65
+ "@napi-rs/wasm-runtime": "^0.2.7",
66
+ "@noble/hashes": "1.5.0",
67
+ "@oxc-node/core": "^0.0.20",
68
+ "@taplo/cli": "^0.7.0",
69
+ "@types/node": "^22.13.5",
70
+ "@tybys/wasm-util": "^0.9.0",
71
+ "ava": "^6.2.0",
72
+ "base64-js": "1.5.1",
73
+ "emnapi": "^1.3.1",
74
+ "mitata": "^1.0.34",
75
+ "npm-run-all2": "^7.0.2",
76
+ "oxlint": "^0.15.12",
77
+ "prettier": "^3.5.2",
78
+ "typescript": "^5.7.3"
79
+ },
80
+ "ava": {
81
+ "extensions": {
82
+ "ts": "module"
83
+ },
84
+ "files": [
85
+ "test/**/*"
86
+ ],
87
+ "timeout": "2m",
88
+ "workerThreads": false,
89
+ "environmentVariables": {
90
+ "TS_NODE_PROJECT": "./tsconfig.json"
91
+ },
92
+ "nodeArguments": [
93
+ "--import",
94
+ "@oxc-node/core/register"
95
+ ]
96
+ },
97
+ "prettier": {
98
+ "printWidth": 120,
99
+ "semi": true,
100
+ "trailingComma": "all",
101
+ "singleQuote": true,
102
+ "arrowParens": "always"
103
+ },
104
+ "optionalDependencies": {
105
+ "@snazzah/davey-darwin-x64": "0.1.9",
106
+ "@snazzah/davey-darwin-arm64": "0.1.9",
107
+ "@snazzah/davey-linux-x64-gnu": "0.1.9",
108
+ "@snazzah/davey-win32-x64-msvc": "0.1.9",
109
+ "@snazzah/davey-linux-x64-musl": "0.1.9",
110
+ "@snazzah/davey-linux-arm64-gnu": "0.1.9",
111
+ "@snazzah/davey-win32-ia32-msvc": "0.1.9",
112
+ "@snazzah/davey-linux-arm-gnueabihf": "0.1.9",
113
+ "@snazzah/davey-android-arm64": "0.1.9",
114
+ "@snazzah/davey-freebsd-x64": "0.1.9",
115
+ "@snazzah/davey-linux-arm64-musl": "0.1.9",
116
+ "@snazzah/davey-win32-arm64-msvc": "0.1.9",
117
+ "@snazzah/davey-android-arm-eabi": "0.1.9",
118
+ "@dengxifeng/davey-linux-riscv64-gnu": "0.1.9",
119
+ "@snazzah/davey-wasm32-wasi": "0.1.9"
120
+ },
121
+ "scripts": {
122
+ "artifacts": "napi artifacts",
123
+ "bench": "node --import @oxc-node/core/register --expose-gc benchmark/bench.ts",
124
+ "build": "napi build --platform --release",
125
+ "build:debug": "napi build --platform",
126
+ "format": "run-p format:prettier format:rs format:toml",
127
+ "changelog": "node --import @oxc-node/core/register scripts/changelog.mts",
128
+ "format:prettier": "prettier . -w",
129
+ "format:toml": "taplo format",
130
+ "format:rs": "cargo fmt",
131
+ "lint": "oxlint",
132
+ "test": "ava",
133
+ "version": "napi version"
134
+ }
135
+ }