diff --git a/main.js b/main.js index 837647d..e8dce91 100644 --- a/main.js +++ b/main.js @@ -25,9 +25,9 @@ async function downloadFromMirror(mirror, tarball_filename) { const tarball_data = await fs.readFile(tarball_path); - const key = minisign.parseKey(MINISIGN_KEY); + const key = await minisign.parseKey(MINISIGN_KEY); const signature = minisign.parseSignature(signature_data); - if (!minisign.verifySignature(key, signature, tarball_data)) { + if (!await minisign.verifySignature(key, signature, tarball_data)) { throw new Error(`signature verification failed for '${mirror}/${tarball_filename}'`); } diff --git a/minisign.js b/minisign.js index 6fb43ef..715e686 100644 --- a/minisign.js +++ b/minisign.js @@ -1,20 +1,20 @@ -const sodium = require('sodium-native'); +const crypto = require('node:crypto'); // Parse a minisign key represented as a base64 string. // Throws exceptions on invalid keys. -function parseKey(key_str) { +async function parseKey(key_str) { const key_info = Buffer.from(key_str, 'base64'); const id = key_info.subarray(2, 10); const key = key_info.subarray(10); - if (key.byteLength !== sodium.crypto_sign_PUBLICKEYBYTES) { + if (key.byteLength !== 32) { throw new Error('invalid public key given'); } return { id: id, - key: key + key: await crypto.subtle.importKey('raw', key, 'Ed25519', false, ['verify']), }; } @@ -77,25 +77,29 @@ function parseSignature(sig_buf) { // Given a parsed key, parsed signature file, and raw file content, verifies the signature, // including the global signature (hence validating the trusted comment). Does not throw. // Returns 'true' if the signature is valid for this file, 'false' otherwise. -function verifySignature(pubkey, signature, file_content) { +async function verifySignature(pubkey, signature, file_content) { if (!signature.key_id.equals(pubkey.id)) { - return false; + return false; // wrong key } let signed_content; if (signature.algorithm.equals(Buffer.from('ED'))) { - signed_content = Buffer.alloc(sodium.crypto_generichash_BYTES_MAX); - sodium.crypto_generichash(signed_content, file_content); - } else { + const hash = crypto.createHash('BLAKE2b512'); + hash.update(file_content); + signed_content = hash.digest(); + } else if (signature.algorithm.equals(Buffer.from('Ed'))) { signed_content = file_content; + } else { + return false; // unsupported algorithm } - if (!sodium.crypto_sign_verify_detached(signature.signature, signed_content, pubkey.key)) { - return false; + + if (!await crypto.subtle.verify('Ed25519', pubkey.key, signature.signature, signed_content)) { + return false; // signature verification failure } const global_signed_content = Buffer.concat([signature.signature, signature.trusted_comment]); - if (!sodium.crypto_sign_verify_detached(signature.global_signature, global_signed_content, pubkey.key)) { - return false; + if (!await crypto.subtle.verify('Ed25519', pubkey.key, signature.global_signature, global_signed_content)) { + return false; // signature verification failure } return true; diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index f2d4280..6b6cc09 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -678,74 +678,6 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "license": "MIT" }, - "node_modules/bare-addon-resolve": { - "version": "1.9.4", - "resolved": "https://registry.npmjs.org/bare-addon-resolve/-/bare-addon-resolve-1.9.4.tgz", - "integrity": "sha512-unn6Vy/Yke6F99vg/7tcrvM2KUvIhTNniaSqDbam4AWkd4NhvDVSrQiRYVlNzUV2P7SPobkCK7JFVxrJk9btCg==", - "license": "Apache-2.0", - "dependencies": { - "bare-module-resolve": "^1.10.0", - "bare-semver": "^1.0.0" - }, - "peerDependencies": { - "bare-url": "*" - }, - "peerDependenciesMeta": { - "bare-url": { - "optional": true - } - } - }, - "node_modules/bare-module-resolve": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/bare-module-resolve/-/bare-module-resolve-1.11.1.tgz", - "integrity": "sha512-DCxeT9i8sTs3vUMA3w321OX/oXtNEu5EjObQOnTmCdNp5RXHBAvAaBDHvAi9ta0q/948QPz+co6SsGi6aQMYRg==", - "license": "Apache-2.0", - "dependencies": { - "bare-semver": "^1.0.0" - }, - "peerDependencies": { - "bare-url": "*" - }, - "peerDependenciesMeta": { - "bare-url": { - "optional": true - } - } - }, - "node_modules/bare-os": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/bare-os/-/bare-os-3.6.1.tgz", - "integrity": "sha512-uaIjxokhFidJP+bmmvKSgiMzj2sV5GPHaZVAIktcxcpCyBFFWO+YlikVAdhmUo2vYFvFhOXIAlldqV29L8126g==", - "license": "Apache-2.0", - "engines": { - "bare": ">=1.14.0" - } - }, - "node_modules/bare-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bare-path/-/bare-path-3.0.0.tgz", - "integrity": "sha512-tyfW2cQcB5NN8Saijrhqn0Zh7AnFNsnczRcuWODH0eYAXBsJ5gVxAUuNr7tsHSC6IZ77cA0SitzT+s47kot8Mw==", - "license": "Apache-2.0", - "dependencies": { - "bare-os": "^3.0.1" - } - }, - "node_modules/bare-semver": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/bare-semver/-/bare-semver-1.0.1.tgz", - "integrity": "sha512-UtggzHLiTrmFOC/ogQ+Hy7VfoKoIwrP1UFcYtTxoCUdLtsIErT8+SWtOC2DH/snT9h+xDrcBEPcwKei1mzemgg==", - "license": "Apache-2.0" - }, - "node_modules/bare-url": { - "version": "2.1.6", - "resolved": "https://registry.npmjs.org/bare-url/-/bare-url-2.1.6.tgz", - "integrity": "sha512-FgjDeR+/yDH34By4I0qB5NxAoWv7dOTYcOXwn73kr+c93HyC2lU6tnjifqUe33LKMJcDyCYPQjEAqgOQiXkE2Q==", - "license": "Apache-2.0", - "dependencies": { - "bare-path": "^3.0.0" - } - }, "node_modules/before-after-hook": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", @@ -1136,19 +1068,6 @@ "wrappy": "1" } }, - "node_modules/require-addon": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/require-addon/-/require-addon-1.1.0.tgz", - "integrity": "sha512-KbXAD5q2+v1GJnkzd8zzbOxchTkStSyJZ9QwoCq3QwEXAaIlG3wDYRZGzVD357jmwaGY7hr5VaoEAL0BkF0Kvg==", - "license": "Apache-2.0", - "dependencies": { - "bare-addon-resolve": "^1.3.0", - "bare-url": "^2.1.0" - }, - "engines": { - "bare": ">=1.10.0" - } - }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1184,15 +1103,6 @@ "semver": "bin/semver.js" } }, - "node_modules/sodium-native": { - "version": "4.3.3", - "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.3.3.tgz", - "integrity": "sha512-OnxSlN3uyY8D0EsLHpmm2HOFmKddQVvEMmsakCrXUzSd8kjjbzL413t4ZNF3n0UxSwNgwTyUvkmZHTfuCeiYSw==", - "license": "MIT", - "dependencies": { - "require-addon": "^1.1.0" - } - }, "node_modules/strnum": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.1.1.tgz", diff --git a/node_modules/bare-addon-resolve/LICENSE b/node_modules/bare-addon-resolve/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/node_modules/bare-addon-resolve/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/node_modules/bare-addon-resolve/README.md b/node_modules/bare-addon-resolve/README.md deleted file mode 100644 index 20cbf5f..0000000 --- a/node_modules/bare-addon-resolve/README.md +++ /dev/null @@ -1,164 +0,0 @@ -# bare-addon-resolve - -Low-level addon resolution algorithm for Bare. The algorithm is implemented as a generator function that yields either package manifests to be read or resolution candidates to be tested by the caller. As a convenience, the main export is a synchronous and asynchronous iterable that relies on package manifests being read by a callback. For asynchronous iteration, the callback may return promises which will be awaited before being passed to the generator. - -``` -npm i bare-addon-resolve -``` - -## Usage - -For synchronous resolution: - -```js -const resolve = require('bare-addon-resolve') - -function readPackage(url) { - // Read and parse `url` if it exists, otherwise `null` -} - -for (const resolution of resolve( - './addon', - new URL('file:///directory/'), - readPackage -)) { - console.log(resolution) -} -``` - -For asynchronous resolution: - -```js -const resolve = require('bare-addon-resolve') - -async function readPackage(url) { - // Read and parse `url` if it exists, otherwise `null` -} - -for await (const resolution of resolve( - './addon', - new URL('file:///directory/'), - readPackage -)) { - console.log(resolution) -} -``` - -## API - -#### `const resolver = resolve(specifier, parentURL[, options][, readPackage])` - -Resolve `specifier` relative to `parentURL`, which must be a WHATWG `URL` instance. `readPackage` is called with a `URL` instance for every package manifest to be read and must either return the parsed JSON package manifest, if it exists, or `null`. If `readPackage` returns a promise, synchronous iteration is not supported. - -Options include: - -```js -options = { - // A list of builtin addon specifiers. If matched, the protocol of the - // resolved URL will be `builtinProtocol`. - builtins: [], - // The protocol to use for resolved builtin addon specifiers. - builtinProtocol: 'builtin:', - // Whether or not addons linked ahead-of-time should be resolved. - linked: true, - // The protocol to use for addons linked ahead-of-time. - linkedProtocol: 'linked:', - // The supported import conditions. "default" is always recognized. - conditions: [], - // An array reference which will contain the matched conditions when yielding - // resolutions. - matchedConditions: [], - // The `-` combinations to look for when resolving dynamic - // addons. If empty, only builtin specifiers can be resolved. In Bare, - // pass `[Bare.Addon.host]`. - hosts: [], - // The file extensions to look for when resolving dynamic addons. - extensions: [], - // A map of preresolved imports with keys being serialized directory URLs and - // values being "imports" maps. - resolutions -} -``` - -#### `for (const resolution of resolver)` - -Synchronously iterate the addon resolution candidates. The resolved addon is the first candidate that exists as a file on the file system. - -#### `for await (const resolution of resolver)` - -Asynchronously iterate the addon resolution candidates. If `readPackage` returns promises, these will be awaited. The same comments as `for (const resolution of resolver)` apply. - -### Algorithm - -The following generator functions implement the resolution algorithm. The yielded values have the following shape: - -**Package manifest** - -```js -next.value = { - package: URL -} -``` - -If the package manifest identified by `next.value.package` exists, `generator.next()` must be passed the parsed JSON value of the manifest. If it does not exist, pass `null` instead. - -**Resolution candidate** - -```js -next.value = { - resolution: URL -} -``` - -If the addon identified by `next.value.resolution` exists, `generator.next()` may be passed `true` to signal that the resolution for the current set of conditions has been identified. If it does not exist, pass `false` instead. - -To drive the generator functions, a loop like the following can be used: - -```js -const generator = resolve.addon(specifier, parentURL) - -let next = generator.next() - -while (next.done !== true) { - const value = next.value - - if (value.package) { - // Read and parse `value.package` if it exists, otherwise `null` - let info - - next = generator.next(info) - } else { - const resolution = value.resolution - - // `true` if `resolution` was the correct candidate, otherwise `false` - let resolved - - next = generator.next(resolved) - } -} -``` - -Options are the same as `resolve()` for all functions. - -> [!WARNING] -> These functions are currently subject to change between minor releases. If using them directly, make sure to specify a tilde range (`~1.2.3`) when declaring the module dependency. - -#### `const generator = resolve.addon(specifier, parentURL[, options])` - -#### `const generator = resolve.url(url, parentURL[, options])` - -#### `const generator = resolve.package(packageSpecifier, packageVersion, parentURL[, options])` - -#### `const generator = resolve.packageSelf(packageName, packageSubpath, packageVersion, parentURL[, options])` - -#### `const generator = resolve.preresolved(directoryURL, resolutions[, options])` - -#### `const generator = resolve.file(filename, parentURL[, options])` - -#### `const generator = resolve.directory(dirname, version, parentURL[, options])` - -#### `const generator = resolve.linked(name, version[, options])` - -## License - -Apache-2.0 diff --git a/node_modules/bare-addon-resolve/index.d.ts b/node_modules/bare-addon-resolve/index.d.ts deleted file mode 100644 index b358c7b..0000000 --- a/node_modules/bare-addon-resolve/index.d.ts +++ /dev/null @@ -1,106 +0,0 @@ -import URL from 'bare-url' -import { - constants, - type Builtins, - type Conditions, - type ResolutionsMap -} from 'bare-module-resolve' - -type JSON = string | number | boolean | JSON[] | { [key: string]: JSON } - -interface ResolveOptions { - builtinProtocol?: string - builtins?: Builtins - conditions?: Conditions - extensions?: string[] - host?: string - hosts?: string[] - linked?: boolean - linkedProtocol?: string - matchedConditions?: string[] - resolutions?: ResolutionsMap -} - -declare function resolve( - specifier: string, - parentURL: URL, - readPackage?: (url: URL) => JSON | null -): Iterable - -declare function resolve( - specifier: string, - parentURL: URL, - readPackage: (url: URL) => Promise -): AsyncIterable - -declare function resolve( - specifier: string, - parentURL: URL, - opts: ResolveOptions, - readPackage?: (url: URL) => JSON | null -): Iterable - -declare function resolve( - specifier: string, - parentURL: URL, - opts: ResolveOptions, - readPackage: (url: URL) => Promise -): AsyncIterable - -declare namespace resolve { - export { constants, type ResolveOptions } - - export type Resolver = Generator< - { resolution: URL } | { package: URL }, - number, - void | boolean | JSON | null - > - - export function addon( - specifier: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function url( - specifier: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function package( - packageSpecifier: string, - packageVersion: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function packageSelf( - packageName: string, - packageSubpath: string, - packageVersion: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function file( - filename: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function directory( - dirname: string, - version: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function linked( - name: string, - version?: string, - opts?: ResolveOptions - ): Resolver -} - -export = resolve diff --git a/node_modules/bare-addon-resolve/index.js b/node_modules/bare-addon-resolve/index.js deleted file mode 100644 index ca9b565..0000000 --- a/node_modules/bare-addon-resolve/index.js +++ /dev/null @@ -1,505 +0,0 @@ -const resolve = require('bare-module-resolve') -const { Version } = require('bare-semver') -const errors = require('./lib/errors') - -module.exports = exports = function resolve( - specifier, - parentURL, - opts, - readPackage -) { - if (typeof opts === 'function') { - readPackage = opts - opts = {} - } else if (typeof readPackage !== 'function') { - readPackage = defaultReadPackage - } - - return { - *[Symbol.iterator]() { - const generator = exports.addon(specifier, parentURL, opts) - - let next = generator.next() - - while (next.done !== true) { - const value = next.value - - if (value.package) { - next = generator.next(readPackage(value.package)) - } else { - next = generator.next(yield value.resolution) - } - } - - return next.value - }, - - async *[Symbol.asyncIterator]() { - const generator = exports.addon(specifier, parentURL, opts) - - let next = generator.next() - - while (next.done !== true) { - const value = next.value - - if (value.package) { - next = generator.next(await readPackage(value.package)) - } else { - next = generator.next(yield value.resolution) - } - } - - return next.value - } - } -} - -function defaultReadPackage() { - return null -} - -const { UNRESOLVED, YIELDED, RESOLVED } = resolve.constants - -exports.constants = { - UNRESOLVED, - YIELDED, - RESOLVED -} - -exports.addon = function* (specifier, parentURL, opts = {}) { - const { resolutions = null } = opts - - if (exports.startsWithWindowsDriveLetter(specifier)) { - specifier = '/' + specifier - } - - let status - - if (resolutions) { - status = yield* resolve.preresolved(specifier, resolutions, parentURL, opts) - - if (status) return status - } - - status = yield* exports.url(specifier, parentURL, opts) - - if (status) return status - - let version = null - - const i = specifier.lastIndexOf('@') - - if (i > 0) { - version = specifier.substring(i + 1) - - try { - Version.parse(version) - - specifier = specifier.substring(0, i) - } catch { - version = null - } - } - - if ( - specifier === '.' || - specifier === '..' || - specifier[0] === '/' || - specifier[0] === '\\' || - specifier.startsWith('./') || - specifier.startsWith('.\\') || - specifier.startsWith('../') || - specifier.startsWith('..\\') - ) { - return yield* exports.directory(specifier, version, parentURL, opts) - } - - return yield* exports.package(specifier, version, parentURL, opts) -} - -exports.url = function* (url, parentURL, opts = {}) { - let resolution - try { - resolution = new URL(url) - } catch { - return UNRESOLVED - } - - const resolved = yield { resolution } - - return resolved ? RESOLVED : YIELDED -} - -exports.package = function* ( - packageSpecifier, - packageVersion, - parentURL, - opts = {} -) { - if (packageSpecifier === '') { - throw errors.INVALID_ADDON_SPECIFIER( - `Addon specifier '${packageSpecifier}' is not a valid package name` - ) - } - - let packageName - - if (packageSpecifier[0] !== '@') { - packageName = packageSpecifier.split('/', 1).join() - } else { - if (!packageSpecifier.includes('/')) { - throw errors.INVALID_ADDON_SPECIFIER( - `Addon specifier '${packageSpecifier}' is not a valid package name` - ) - } - - packageName = packageSpecifier.split('/', 2).join('/') - } - - if ( - packageName[0] === '.' || - packageName.includes('\\') || - packageName.includes('%') - ) { - throw errors.INVALID_ADDON_SPECIFIER( - `Addon specifier '${packageSpecifier}' is not a valid package name` - ) - } - - const packageSubpath = '.' + packageSpecifier.substring(packageName.length) - - const status = yield* exports.packageSelf( - packageName, - packageSubpath, - packageVersion, - parentURL, - opts - ) - - if (status) return status - - parentURL = new URL(parentURL.href) - - do { - const packageURL = new URL('node_modules/' + packageName + '/', parentURL) - - parentURL.pathname = parentURL.pathname.substring( - 0, - parentURL.pathname.lastIndexOf('/') - ) - - const info = yield { package: new URL('package.json', packageURL) } - - if (info) { - return yield* exports.directory( - packageSubpath, - packageVersion, - packageURL, - opts - ) - } - } while (parentURL.pathname !== '' && parentURL.pathname !== '/') - - return UNRESOLVED -} - -exports.packageSelf = function* ( - packageName, - packageSubpath, - packageVersion, - parentURL, - opts = {} -) { - for (const packageURL of resolve.lookupPackageScope(parentURL, opts)) { - const info = yield { package: packageURL } - - if (info) { - if (info.name === packageName) { - return yield* exports.directory( - packageSubpath, - packageVersion, - packageURL, - opts - ) - } - - break - } - } - - return UNRESOLVED -} - -exports.lookupPrebuildsScope = function* lookupPrebuildsScope(url, opts = {}) { - const { resolutions = null } = opts - - if (resolutions) { - for (const { resolution } of resolve.preresolved( - '#prebuilds', - resolutions, - url, - opts - )) { - if (resolution) return yield resolution - } - } - - const scopeURL = new URL(url.href) - - do { - yield new URL('prebuilds/', scopeURL) - - scopeURL.pathname = scopeURL.pathname.substring( - 0, - scopeURL.pathname.lastIndexOf('/') - ) - - if ( - scopeURL.pathname.length === 3 && - exports.isWindowsDriveLetter(scopeURL.pathname.substring(1)) - ) { - break - } - } while (scopeURL.pathname !== '' && scopeURL.pathname !== '/') -} - -exports.file = function* (filename, parentURL, opts = {}) { - if (parentURL.protocol === 'file:' && /%2f|%5c/i.test(filename)) { - throw errors.INVALID_ADDON_SPECIFIER( - `Addon specifier '${filename}' is invalid` - ) - } - - const { extensions = [] } = opts - - let status = UNRESOLVED - - for (const ext of extensions) { - if (yield { resolution: new URL(filename + ext, parentURL) }) { - return RESOLVED - } - - status = YIELDED - } - - return status -} - -exports.directory = function* (dirname, version, parentURL, opts = {}) { - const { - resolutions = null, - host = null, // Shorthand for single host resolution - hosts = host !== null ? [host] : [], - builtins = [], - matchedConditions = [] - } = opts - - let directoryURL - - if ( - dirname[dirname.length - 1] === '/' || - dirname[dirname.length - 1] === '\\' - ) { - directoryURL = new URL(dirname, parentURL) - } else { - directoryURL = new URL(dirname + '/', parentURL) - } - - // Internal preresolution path, do not depend on this! It will be removed without - // warning. - if (resolutions) { - const status = yield* resolve.preresolved( - 'bare:addon', - resolutions, - directoryURL, - opts - ) - - if (status) return status - } - - const unversioned = version === null - - let name = null - - const info = yield { package: new URL('package.json', directoryURL) } - - if (info) { - if (typeof info.name === 'string' && info.name !== '') { - if (info.name.includes('__')) { - throw errors.INVALID_PACKAGE_NAME( - `Package name '${info.name}' is invalid` - ) - } - - name = info.name.replace(/\//g, '__').replace(/^@/, '') - } else { - return UNRESOLVED - } - - if (typeof info.version === 'string' && info.version !== '') { - if (version !== null && info.version !== version) return UNRESOLVED - - version = info.version - } - } else { - return UNRESOLVED - } - - let status - - status = yield* resolve.builtinTarget(name, version, builtins, opts) - - if (status) return status - - for (const prebuildsURL of exports.lookupPrebuildsScope(directoryURL, opts)) { - status = UNRESOLVED - - for (const host of hosts) { - const conditions = host.split('-') - - matchedConditions.push(...conditions) - - if (version !== null) { - status |= yield* exports.file( - host + '/' + name + '@' + version, - prebuildsURL, - opts - ) - } - - if (unversioned) { - status |= yield* exports.file(host + '/' + name, prebuildsURL, opts) - } - - for (const _ of conditions) matchedConditions.pop() - } - - if (status === RESOLVED) return status - } - - return yield* exports.linked(name, version, opts) -} - -exports.linked = function* (name, version = null, opts = {}) { - const { - linked = true, - host = null, // Shorthand for single host resolution - hosts = host !== null ? [host] : [], - matchedConditions = [] - } = opts - - if (linked === false || hosts.length === 0) return UNRESOLVED - - let status = UNRESOLVED - - for (const host of hosts) { - const [platform = null] = host.split('-', 1) - - if (platform === null) continue - - matchedConditions.push(platform) - - status |= yield* platformArtefact(name, version, platform, opts) - - matchedConditions.pop() - } - - return status -} - -function* platformArtefact(name, version = null, platform, opts = {}) { - const { linkedProtocol = 'linked:' } = opts - - if (platform === 'darwin' || platform === 'ios') { - if (version !== null) { - if ( - yield { - resolution: new URL( - `${linkedProtocol}${name}.${version}.framework/${name}.${version}` - ) - } - ) { - return RESOLVED - } - - if (platform === 'darwin') { - if ( - yield { - resolution: new URL(`${linkedProtocol}lib${name}.${version}.dylib`) - } - ) { - return RESOLVED - } - } - } - - if ( - yield { - resolution: new URL(`${linkedProtocol}${name}.framework/${name}`) - } - ) { - return RESOLVED - } - - if (platform === 'darwin') { - if ( - yield { - resolution: new URL(`${linkedProtocol}lib${name}.dylib`) - } - ) { - return RESOLVED - } - } - - return YIELDED - } - - if (platform === 'linux' || platform === 'android') { - if (version !== null) { - if ( - yield { - resolution: new URL(`${linkedProtocol}lib${name}.${version}.so`) - } - ) { - return RESOLVED - } - } - - if ( - yield { - resolution: new URL(`${linkedProtocol}lib${name}.so`) - } - ) { - return RESOLVED - } - - return YIELDED - } - - if (platform === 'win32') { - if (version !== null) { - if ( - yield { - resolution: new URL(`${linkedProtocol}${name}-${version}.dll`) - } - ) { - return RESOLVED - } - } - - if ( - yield { - resolution: new URL(`${linkedProtocol}${name}.dll`) - } - ) { - return RESOLVED - } - } - - return UNRESOLVED -} - -exports.isWindowsDriveLetter = resolve.isWindowsDriveLetter - -exports.startsWithWindowsDriveLetter = resolve.startsWithWindowsDriveLetter diff --git a/node_modules/bare-addon-resolve/lib/errors.d.ts b/node_modules/bare-addon-resolve/lib/errors.d.ts deleted file mode 100644 index ecf2223..0000000 --- a/node_modules/bare-addon-resolve/lib/errors.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -declare class AddonResolveError extends Error { - readonly code: string - - static INVALID_ADDON_SPECIFIER(msg: string): AddonResolveError - static INVALID_PACKAGE_NAME(msg: string): AddonResolveError -} - -export = AddonResolveError diff --git a/node_modules/bare-addon-resolve/lib/errors.js b/node_modules/bare-addon-resolve/lib/errors.js deleted file mode 100644 index 96b6637..0000000 --- a/node_modules/bare-addon-resolve/lib/errors.js +++ /dev/null @@ -1,30 +0,0 @@ -module.exports = class AddonResolveError extends Error { - constructor(msg, code, fn = AddonResolveError) { - super(`${code}: ${msg}`) - this.code = code - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, fn) - } - } - - get name() { - return 'AddonResolveError' - } - - static INVALID_ADDON_SPECIFIER(msg) { - return new AddonResolveError( - msg, - 'INVALID_ADDON_SPECIFIER', - AddonResolveError.INVALID_ADDON_SPECIFIER - ) - } - - static INVALID_PACKAGE_NAME(msg) { - return new AddonResolveError( - msg, - 'INVALID_PACKAGE_NAME', - AddonResolveError.INVALID_PACKAGE_NAME - ) - } -} diff --git a/node_modules/bare-addon-resolve/package.json b/node_modules/bare-addon-resolve/package.json deleted file mode 100644 index 431d70c..0000000 --- a/node_modules/bare-addon-resolve/package.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "name": "bare-addon-resolve", - "version": "1.9.4", - "description": "Low-level addon resolution algorithm for Bare", - "exports": { - "./package": "./package.json", - ".": { - "types": "./index.d.ts", - "default": "./index.js" - }, - "./errors": { - "types": "./lib/errors.d.ts", - "default": "./lib/errors.js" - } - }, - "files": [ - "index.js", - "index.d.ts", - "lib" - ], - "scripts": { - "test": "prettier . --check && bare test.js" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/holepunchto/bare-addon-resolve.git" - }, - "author": "Holepunch", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/holepunchto/bare-addon-resolve/issues" - }, - "homepage": "https://github.com/holepunchto/bare-addon-resolve#readme", - "dependencies": { - "bare-module-resolve": "^1.10.0", - "bare-semver": "^1.0.0" - }, - "devDependencies": { - "bare-url": "^2.1.3", - "brittle": "^3.2.1", - "prettier": "^3.3.3", - "prettier-config-standard": "^7.0.0" - }, - "peerDependencies": { - "bare-url": "*" - }, - "peerDependenciesMeta": { - "bare-url": { - "optional": true - } - } -} diff --git a/node_modules/bare-module-resolve/LICENSE b/node_modules/bare-module-resolve/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/node_modules/bare-module-resolve/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/node_modules/bare-module-resolve/README.md b/node_modules/bare-module-resolve/README.md deleted file mode 100644 index d3ee1e5..0000000 --- a/node_modules/bare-module-resolve/README.md +++ /dev/null @@ -1,358 +0,0 @@ -# bare-module-resolve - -Low-level module resolution algorithm for Bare. The algorithm is implemented as a generator function that yields either package manifests to be read or resolution candidates to be tested by the caller. As a convenience, the main export is a synchronous and asynchronous iterable that relies on package manifests being read by a callback. For asynchronous iteration, the callback may return promises which will be awaited before being passed to the generator. - -``` -npm i bare-module-resolve -``` - -## Usage - -For synchronous resolution: - -```js -const resolve = require('bare-module-resolve') - -function readPackage(url) { - // Read and parse `url` if it exists, otherwise `null` -} - -for (const resolution of resolve( - './file.js', - new URL('file:///directory/'), - readPackage -)) { - console.log(resolution) -} -``` - -For asynchronous resolution: - -```js -const resolve = require('bare-module-resolve') - -async function readPackage(url) { - // Read and parse `url` if it exists, otherwise `null` -} - -for await (const resolution of resolve( - './file.js', - new URL('file:///directory/'), - readPackage -)) { - console.log(resolution) -} -``` - -## API - -#### `const resolver = resolve(specifier, parentURL[, options][, readPackage])` - -Resolve `specifier` relative to `parentURL`, which must be a WHATWG `URL` instance. `readPackage` is called with a `URL` instance for every package manifest to be read and must either return the parsed JSON package manifest, if it exists, or `null`. If `readPackage` returns a promise, synchronous iteration is not supported. - -Options include: - -```js -options = { - // A default "imports" map to apply to all specifiers. Follows the same - // syntax and rules as the "imports" property defined in `package.json`. - imports, - // A list of builtin module specifiers. If matched, the protocol of the - // resolved URL will be `builtinProtocol`. - builtins: [], - // The protocol to use for resolved builtin module specifiers. - builtinProtocol: 'builtin:', - // A list of module specifiers whose resolution should be deferred. If matched, - // the protocol of the resolved URL will be `deferredProtocol`. - defer: [], - // The protocol to use for resolved deferred module specifiers. - deferredProtocol: 'deferred:', - // The supported import conditions. "default" is always recognized. - conditions: [], - // An array reference which will contain the matched conditions when yielding - // resolutions. - matchedConditions: [], - // The supported engine versions. - engines: {}, - // The file extensions to look for. Must be provided to support extensionless - // specifier resolution and directory support, such as resolving './foo' to - // './foo.js' or './foo/index.js'. - extensions: [], - // A map of preresolved imports with keys being serialized parent URLs and - // values being "imports" maps. - resolutions -} -``` - -#### `for (const resolution of resolver)` - -Synchronously iterate the module resolution candidates. The resolved module is the first candidate that exists, either as a file on a file system, a resource at a URL, or something else entirely. - -#### `for await (const resolution of resolver)` - -Asynchronously iterate the module resolution candidates. If `readPackage` returns promises, these will be awaited. The same comments as `for (const resolution of resolver)` apply. - -### Algorithm - -The following generator functions implement the resolution algorithm, which has been adapted from the Node.js resolution algorithms for CommonJS and ES modules. Unlike Node.js, Bare uses the same resolution algorithm for both module formats. The yielded values have the following shape: - -**Package manifest** - -```js -next.value = { - package: URL -} -``` - -If the package manifest identified by `next.value.package` exists, `generator.next()` must be passed the parsed JSON value of the manifest. If it does not exist, pass `null` instead. - -**Resolution candidate** - -```js -next.value = { - resolution: URL -} -``` - -If the module identified by `next.value.resolution` exists, `generator.next()` may be passed `true` to signal that the resolution for the current set of conditions has been identified. If it does not exist, pass `false` instead. - -To drive the generator functions, a loop like the following can be used: - -```js -const generator = resolve.module(specifier, parentURL) - -let next = generator.next() - -while (next.done !== true) { - const value = next.value - - if (value.package) { - // Read and parse `value.package` if it exists, otherwise `null` - let info - - next = generator.next(info) - } else { - const resolution = value.resolution - - // `true` if `resolution` was the correct candidate, otherwise `false` - let resolved - - next = generator.next(resolved) - } -} -``` - -Options are the same as `resolve()` for all functions. - -> [!WARNING] -> These functions are currently subject to change between minor releases. If using them directly, make sure to specify a tilde range (`~1.2.3`) when declaring the module dependency. - -#### `const generator = resolve.module(specifier, parentURL[, options])` - -1. If `specifier` [starts with a Windows drive letter](https://url.spec.whatwg.org/#start-with-a-windows-drive-letter): - 1. Prepend `/` to `specifier`. -2. If `options.resolutions` is set: - 1. If `preresolved(specifier, options.resolutions, parentURL, options)` yields, return. -3. If `url(specifier, parentURL, options)` yields, return. -4. If `packageImports(specifier, parentURL, options)` yields, return. -5. If `specifier` equals `.` or `..`, or if `specifier` starts with `/`, `\`, `./`, `.\`, `../`, or `..\`: - 1. If `options.imports` is set: - 1. If `packageImportsExports(specifier, options.imports, parentURL, true, options)` yields, return. - 2. If `deferred(specifier, options)` yields, return. - 3. If `file(specifier, parentURL, false, options)` resolves, return. - 4. Return `directory(specifier, parentURL, options)`. -6. Return `package(specifier, parentURL, options)`. - -#### `const generator = resolve.url(url, parentURL[, options])` - -1. If `url` is not a valid URL, return. -2. If `options.imports` is set: - 1. If `packageImportsExports(url.href, options.imports, parentURL, true, options)` yields, return. -3. If `url.protocol` equals `options.deferredProtocol`: - 1. Let `specifier` be `url.pathname`. - 2. Return `module(specifier, parentURL, options)`. -4. If `url.protocol` equals `node:`: - 1. Let `specifier` be `url.pathname`. - 2. If `specifier` equals `.` or `..`, or if `specifier` starts with `/`, `\`, `./`, `.\`, `../`, or `..\`, throw. - 3. Return `package(specifier, parentURL, options)`. -5. Yield `url`. - -#### `const generator = resolve.preresolved(specifier, resolutions, parentURL[, options])` - -1. Let `imports` be `resolutions[parentURL]`. -2. If `imports` is a non-`null` object: - 1. Return `packageImportsExports(specifier, imports, parentURL, true, options)`. - -#### `const generator = resolve.deferred(specifier[, options])` - -1. If `options.defer` includes `specifier`: - 1. Yield `options.deferredProtocol` concatenated with `specifier` and return. - -#### `const generator = resolve.package(packageSpecifier, parentURL[, options])` - -1. If `packageSpecifier` is the empty string, throw. -2. If `packageSpecifier` does not start with `@`: - 1. Set `packageName` to the substring of `packageSpecifier` until the first `/` or the end of the string. -3. Let `packageName` be `undefined`. -4. Otherwise: - 1. If `packageSpecifier` does not include `/`, throw. - 2. Set `packageName` to the substring of `packageSpecifier` until the second `/` or the end of the string. -5. If `packageName` starts with `.` or includes `\` or `%`, throw. -6. If `builtinTarget(packageSpecifier, null, options.builtins, options)` yields, return. -7. If `deferred(packageSpecifier, options)` yields, return. -8. Let `packageSubpath` be `.` concatenated with the substring of `packageSpecifier` from the position at the length of `packageName`. -9. If `packageSelf(packageName, packageSubpath, parentURL, options)` yields, return. -10. Repeat: - 1. Let `packageURL` be the resolution of `node_modules/` concatenated with `packageName` and `/` relative to `parentURL`. - 2. Set `parentURL` to the substring of `parentURL` until the last `/`. - 3. Let `info` be the result of yielding the resolution of `package.json` relative to `packageURL`. - 4. If `info` is not `null`: - 1. If `info.engines` is set: - 1. Call `validateEngines(packageURL, info.engines, options)`. - 2. If `info.exports` is set: - 1. Return `packageExports(packageURL, packageSubpath, info.exports, options)`. - 3. If `packageSubpath` is `.`: - 1. If `info.main` is a non-empty string: - 1. Set `packageSubpath` to `info.main`. - 2. Otherwise: - 1. Return `file('index', packageURL, true, options)`. - 4. If `file(packageSubpath, packageURL, false, options)` resolves, return. - 5. Return `directory(packageSubpath, packageURL, options)`. - 5. If `parentURL` is the file system root, return. - -#### `const generator = resolve.packageSelf(packageName, packageSubpath, parentURL[, options])` - -1. For each value `packageURL` of `lookupPackageScope(parentURL, options)`: - 1. Let `info` be the result of yielding `packageURL`. - 2. If `info` is not `null`: - 1. If `info.name` does not equal `packageName`, return. - 2. If `info.exports` is set: - 1. Return `packageExports(packageURL, packageSubpath, info.exports, options)`. - 3. If `packageSubpath` is `.`: - 1. If `info.main` is a non-empty string: - 1. Set `packageSubpath` to `info.main`. - 2. Otherwise: - 1. Return `file('index', packageURL, true, options)`. - 4. If `file(packageSubpath, packageURL, false, options)` resolves, return. - 5. Return `directory(packageSubpath, packageURL, options)`. - -#### `const generator = resolve.packageExports(packageURL, subpath, exports[, options])` - -1. If `subpath` is `.`: - 1. Let `mainExport` be `undefined`. - 2. If `exports` is a string or an array: - 1. Set `mainExport` to `exports`. - 3. If `exports` is a non-`null` object: - 1. If some keys of `exports` start with `.`: - 1. If `.` is a key of `exports`: - 1. Set `mainExport` to `exports['.']`. - 2. Otherwise: - 1. Set `mainExport` to `exports`. - 4. If `mainExport` is not `undefined`: - 1. If `packageTarget(packageURL, mainExport, null, false, options)` yields, return. -2. Otherwise, if `exports` is a non-`null` object: - 1. If every key of `exports` starts with `.`: - 1. If `packageImportsExports(subpath, exports, packageURL, false, options)` yields, return. -3. Throw. - -#### `const generator = resolve.packageImports(specifier, parentURL[, options])` - -1. If `specifier` is `#` or starts with `#/`, throw. -2. For each value `packageURL` of `lookupPackageScope(parentURL, opions)`: - 1. Let `info` be the result of yielding `packageURL`. - 2. If `info` is not `null`: - 1. If `info.imports` is set: - 1. If `packageImportsExports(specifier, info.imports, packageURL, true, options)` yields, return. - 2. If specifier starts with `#`, throw. - 3. Return. -3. If `options.imports` is set: - 1. If `packageImportsExports(url.href, options.imports, parentURL, true, options)` yields, return. - -#### `const generator = resolve.packageImportsExports(matchKey, matchObject, packageURL, isImports[, options])` - -1. If `matchKey` is a key of `matchObject` and `matchKey` does not include `*`: - 1. Let `target` be `matchObject[matchKey]`. - 2. Return `packageTarget(packageURL, target, null, isImports, options)`. -2. Let `expansionKeys` be the keys of `matchObject` that include `*` sorted by `patternKeyCompare`. -3. For each value `expansionKey` of `expansionKeys`: - 1. Let `patternBase` be the substring of `expansionKey` until the first `*`. - 2. If `matchKey` starts with but isn't equal to `patternBase`: - 1. Let `patternTrailer` be the substring of `expansionKey` from the position at the index after the first `*`. - 2. If `patternTrailer` is the empty string, or if `matchKey` ends with `patternTrailer` and the length of `matchKey` is greater than or equal to the length of `expansionKey`: - 1. Let `target` be `matchObject[expansionKey]`. - 2. Let `patternMatch` be the substring of `matchKey` from the position at the length of `patternBase` until the length of `matchKey` minus the length of `patternTrailer`. - 3. Return `packageTarget(packageURL, target, patternMatch, isImports, options)`. - -#### `const generator = resolve.packageTarget(packageURL, target, patternMatch, isImports[, options])` - -1. If `target` is a string: - 1. If `target` does not start with `./` and `isImports` is `false`, throw. - 2. If `patternMatch` is not `null`: - 1. Replace every instance of `*` in `target` with `patternMatch`. - 3. If `url(target, packageURL, options)` yields, return. - 4. If `target` equals `.` or `..`, or if `target` starts with `/`, `./`, or `../`: - 1. Yield the resolution of `target` relative to `packageURL` and return. - 5. Return `package(target, packageURL, options)`. -2. If `target` is an array: - 1. For each value `targetValue` of `target`: - 1. If `packageTarget(packageURL, targetValue, patternMatch, isImports, options)` yields, return. -3. If `target` is a non-`null` object: - 1. For each key `condition` of `target`: - 1. If `condition` equals `default` or if `options.conditions` includes `condition`: - 1. Let `targetValue` be `target[condition]`. - 2. Return `packageTarget(packageURL, targetValue, patternMatch, isImports, options)`. - -#### `const generator = resolve.builtinTarget(packageSpecifier, packageVersion, target[, options])` - -1. If `target` is a string: - 1. If `target` does not start with `@`: - 1. Let `targetName` be the substring of `target` until the first `@` or the end of the string. - 2. Let `targetVersion` be the substring of `target` from the character following the first `@` and to the end of string, or `null` if no such substring exists. - 2. Otherwise: - 1. Let `targetName` be the substring of `target` until the second `@` or the end of the string. - 2. Let `targetVersion` be the substring of `target` from the character following the second `@` and to the end of string, or `null` if no such substring exists. - 3. If `packageSpecifier` equals `targetName`: - 1. If `packageVersion` is `null` and `targetVersion` is `null`: - 1. Yield `options.builtinProtocol` concatenated with `packageSpecifier` and return. - 2. Let `version` be `null`. - 3. If `packageVersion` is `null`, let `version` be `targetVersion`. - 4. Otherwise, if `targetVersion` is either `null` or equals `packageVersion`, let `version` be `packageVersion` - 5. If `version` is not `null`: - 1. Yield `options.builtinProtocol` concatenated with `packageSpecifier`, `@`, and `version` and return. -2. If `target` is an array: - 1. For each value `targetValue` of `target`: - 1. If `builtinTarget(packageSpecifier, packageVersion, targetValue, options)` yields, return. -3. If `target` is a non-`null` object: - 1. For each key `condition` of `target`: - 1. If `condition` equals `default` or if `options.conditions` includes `condition`: - 1. Let `targetValue` be `target[condition]`. - 2. Return `builtinTarget(packageSpecifier, packageVersion, targetValue, options)`. - -#### `const generator = resolve.file(filename, parentURL, isIndex[, options])` - -1. If `filename` equals `.` or `..`, or if `filename` ends with `/` or `\`, return. -2. If `parentURL` is a `file:` URL and `filename` includes encoded `/` or `\`, throw. -3. If `isIndex` is `false`: - 1. Yield the resolution of `filename` relative to `parentURL`. -4. For each value `ext` of `options.extensions`: - 1. Yield the resolution of `filename` concatenated with `ext` relative to `parentURL`. - -#### `const generator = resolve.directory(dirname, parentURL[, options])` - -1. Let `directoryURL` be `undefined`. -2. If `dirname` ends with `/` or `\`: - 1. Set `directoryURL` to the resolution of `dirname` relative to `parentURL`. -3. Otherwise: - 1. Set `directoryURL` to the resolution of `dirname` concatenated with `/` relative to `parentURL`. -4. Let `info` be the result of yielding the resolution of `package.json` relative to `directoryURL`. -5. If `info` is not `null`: - 1. If `info.exports` is set: - 1. Return `packageExports(directoryURL, '.', info.exports, options)`. - 2. If `info.main` is a non-empty string: - 1. If `file(info.main, directoryURL, false, options)` resolves, return. - 2. Return `directory(info.main, directoryURL, options)`. -6. Return `file('index', directoryURL, true, options)`. - -## License - -Apache-2.0 diff --git a/node_modules/bare-module-resolve/index.d.ts b/node_modules/bare-module-resolve/index.d.ts deleted file mode 100644 index 3bcb8a3..0000000 --- a/node_modules/bare-module-resolve/index.d.ts +++ /dev/null @@ -1,167 +0,0 @@ -import URL from 'bare-url' - -type ConditionalSpecifier = - | string - | ConditionalSpecifier[] - | { [condition: string]: ConditionalSpecifier } - -type ImportsMap = { [specifier: string]: ConditionalSpecifier } - -type ExportsMap = ImportsMap - -type ResolutionsMap = { [href: string]: ImportsMap } - -type Builtins = ConditionalSpecifier[] - -type Conditions = string[] | Conditions[] - -type Engines = { [name: string]: string } - -type JSON = string | number | boolean | JSON[] | { [key: string]: JSON } - -interface ResolveOptions { - builtinProtocol?: string - builtins?: Builtins - conditions?: Conditions - defer?: string[] - deferredProtocol?: string - engines?: Engines - extensions?: string[] - imports?: ImportsMap - matchedConditions?: string[] - resolutions?: ResolutionsMap -} - -declare function resolve( - specifier: string, - parentURL: URL, - readPackage?: (url: URL) => JSON | null -): Iterable - -declare function resolve( - specifier: string, - parentURL: URL, - readPackage: (url: URL) => Promise -): AsyncIterable - -declare function resolve( - specifier: string, - parentURL: URL, - opts: ResolveOptions, - readPackage?: (url: URL) => JSON | null -): Iterable - -declare function resolve( - specifier: string, - parentURL: URL, - opts: ResolveOptions, - readPackage: (url: URL) => Promise -): AsyncIterable - -declare namespace resolve { - export { - type ConditionalSpecifier, - type ImportsMap, - type ExportsMap, - type ResolutionsMap, - type Builtins, - type Conditions, - type Engines, - type ResolveOptions - } - - export const constants: { - UNRESOLVED: number - YIELDED: number - RESOLVED: number - } - - export type Resolver = Generator< - { package: URL } | { resolution: URL }, - number, - void | boolean | JSON | null - > - - export function module( - specifier: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function url( - url: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function preresolved( - specifier: string, - resolutions: ResolutionsMap, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function package( - packageSpecifier: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function packageSelf( - packageName: string, - packageSubpath: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function packageExports( - packageURL: URL, - subpath: string, - packageExports: ExportsMap, - opts?: ResolveOptions - ): Resolver - - export function packageImports( - specifier: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver - - export function packageImportsExports( - matchKey: string, - matchObject: ImportsMap | ExportsMap, - packageURL: URL, - isImports: boolean, - opts?: ResolveOptions - ): Resolver - - export function packageTarget( - packageURL: URL, - target: ConditionalSpecifier, - patternMatch: string, - isImports: boolean, - opts?: ResolveOptions - ): Resolver - - export function builtinTarget( - packageSpecifier: string, - packageVersion: string, - target: ConditionalSpecifier, - opts?: ResolveOptions - ): Resolver - - export function file( - filename: string, - parentURL: URL, - isIndex: boolean, - opts?: ResolveOptions - ): Resolver - - export function directory( - dirname: string, - parentURL: URL, - opts?: ResolveOptions - ): Resolver -} - -export = resolve diff --git a/node_modules/bare-module-resolve/index.js b/node_modules/bare-module-resolve/index.js deleted file mode 100644 index dab966f..0000000 --- a/node_modules/bare-module-resolve/index.js +++ /dev/null @@ -1,908 +0,0 @@ -const { satisfies } = require('bare-semver') -const errors = require('./lib/errors') - -module.exports = exports = function resolve( - specifier, - parentURL, - opts, - readPackage -) { - if (typeof opts === 'function') { - readPackage = opts - opts = {} - } else if (typeof readPackage !== 'function') { - readPackage = defaultReadPackage - } - - return { - *[Symbol.iterator]() { - const generator = exports.module(specifier, parentURL, opts) - - let next = generator.next() - - while (next.done !== true) { - const value = next.value - - if (value.package) { - next = generator.next(readPackage(value.package)) - } else { - next = generator.next(yield value.resolution) - } - } - - return next.value - }, - - async *[Symbol.asyncIterator]() { - const generator = exports.module(specifier, parentURL, opts) - - let next = generator.next() - - while (next.done !== true) { - const value = next.value - - if (value.package) { - next = generator.next(await readPackage(value.package)) - } else { - next = generator.next(yield value.resolution) - } - } - - return next.value - } - } -} - -function defaultReadPackage() { - return null -} - -// No resolution candidate was yielded -const UNRESOLVED = 0x0 -// At least 1 resolution candidate was yielded -const YIELDED = 0x1 -// At least 1 resolution candidate was yielded and resolved -const RESOLVED = YIELDED | 0x2 - -exports.constants = { - UNRESOLVED, - YIELDED, - RESOLVED -} - -exports.module = function* (specifier, parentURL, opts = {}) { - const { resolutions = null, imports = null } = opts - - if (exports.startsWithWindowsDriveLetter(specifier)) { - specifier = '/' + specifier - } - - let status - - if (resolutions) { - status = yield* exports.preresolved(specifier, resolutions, parentURL, opts) - - if (status) return status - } - - status = yield* exports.url(specifier, parentURL, opts) - - if (status) return status - - status = yield* exports.packageImports(specifier, parentURL, opts) - - if (status) return status - - if ( - specifier === '.' || - specifier === '..' || - specifier[0] === '/' || - specifier[0] === '\\' || - specifier.startsWith('./') || - specifier.startsWith('.\\') || - specifier.startsWith('../') || - specifier.startsWith('..\\') - ) { - if (imports) { - status = yield* exports.packageImportsExports( - specifier, - imports, - parentURL, - true, - opts - ) - - if (status) return status - } - - status = yield* exports.deferred(specifier, opts) - - if (status) return status - - status = yield* exports.file(specifier, parentURL, false, opts) - - if (status === RESOLVED) return status - - return yield* exports.directory(specifier, parentURL, opts) - } - - return yield* exports.package(specifier, parentURL, opts) -} - -exports.url = function* (url, parentURL, opts = {}) { - const { imports = null, deferredProtocol = 'deferred:' } = opts - - let resolution - try { - resolution = new URL(url) - } catch { - return UNRESOLVED - } - - if (imports) { - const status = yield* exports.packageImportsExports( - resolution.href, - imports, - parentURL, - true, - opts - ) - - if (status) return status - } - - if (resolution.protocol === deferredProtocol) { - const specifier = resolution.pathname - - return yield* exports.module(specifier, parentURL, opts) - } - - if (resolution.protocol === 'node:') { - const specifier = resolution.pathname - - if ( - specifier === '.' || - specifier === '..' || - specifier[0] === '/' || - specifier.startsWith('./') || - specifier.startsWith('../') - ) { - throw errors.INVALID_MODULE_SPECIFIER( - `Module specifier '${url}' is not a valid package name` - ) - } - - return yield* exports.package(specifier, parentURL, opts) - } - - const resolved = yield { resolution } - - return resolved ? RESOLVED : YIELDED -} - -exports.preresolved = function* (specifier, resolutions, parentURL, opts = {}) { - const imports = resolutions[parentURL.href] - - if (typeof imports === 'object' && imports !== null) { - return yield* exports.packageImportsExports( - specifier, - imports, - parentURL, - true, - opts - ) - } - - return UNRESOLVED -} - -exports.deferred = function* (specifier, opts = {}) { - const { deferredProtocol = 'deferred:', defer = [] } = opts - - if (defer.includes(specifier)) { - const resolved = yield { resolution: new URL(deferredProtocol + specifier) } - - return resolved ? RESOLVED : YIELDED - } - - return UNRESOLVED -} - -exports.package = function* (packageSpecifier, parentURL, opts = {}) { - const { builtins = [] } = opts - - if (packageSpecifier === '') { - throw errors.INVALID_MODULE_SPECIFIER( - `Module specifier '${packageSpecifier}' is not a valid package name` - ) - } - - let packageName - - if (packageSpecifier[0] !== '@') { - packageName = packageSpecifier.split('/', 1).join() - } else { - if (!packageSpecifier.includes('/')) { - throw errors.INVALID_MODULE_SPECIFIER( - `Module specifier '${packageSpecifier}' is not a valid package name` - ) - } - - packageName = packageSpecifier.split('/', 2).join('/') - } - - if ( - packageName[0] === '.' || - packageName.includes('\\') || - packageName.includes('%') - ) { - throw errors.INVALID_MODULE_SPECIFIER( - `Module specifier '${packageSpecifier}' is not a valid package name` - ) - } - - let status - - status = yield* exports.builtinTarget(packageSpecifier, null, builtins, opts) - - if (status) return status - - status = yield* exports.deferred(packageSpecifier, opts) - - if (status) return status - - let packageSubpath = '.' + packageSpecifier.substring(packageName.length) - - status = yield* exports.packageSelf( - packageName, - packageSubpath, - parentURL, - opts - ) - - if (status) return status - - parentURL = new URL(parentURL.href) - - do { - const packageURL = new URL('node_modules/' + packageName + '/', parentURL) - - parentURL.pathname = parentURL.pathname.substring( - 0, - parentURL.pathname.lastIndexOf('/') - ) - - const info = yield { package: new URL('package.json', packageURL) } - - if (info) { - if (info.engines) exports.validateEngines(packageURL, info.engines, opts) - - if (info.exports) { - return yield* exports.packageExports( - packageURL, - packageSubpath, - info.exports, - opts - ) - } - - if (packageSubpath === '.') { - if (typeof info.main === 'string' && info.main !== '') { - packageSubpath = info.main - } else { - return yield* exports.file('index', packageURL, true, opts) - } - } - - status = yield* exports.file(packageSubpath, packageURL, false, opts) - - if (status === RESOLVED) return status - - return yield* exports.directory(packageSubpath, packageURL, opts) - } - } while (parentURL.pathname !== '' && parentURL.pathname !== '/') - - return UNRESOLVED -} - -exports.packageSelf = function* ( - packageName, - packageSubpath, - parentURL, - opts = {} -) { - for (const packageURL of exports.lookupPackageScope(parentURL, opts)) { - const info = yield { package: packageURL } - - if (info) { - if (info.name !== packageName) return false - - if (info.exports) { - return yield* exports.packageExports( - packageURL, - packageSubpath, - info.exports, - opts - ) - } - - if (packageSubpath === '.') { - if (typeof info.main === 'string' && info.main !== '') { - packageSubpath = info.main - } else { - return yield* exports.file('index', packageURL, true, opts) - } - } - - const status = yield* exports.file( - packageSubpath, - packageURL, - false, - opts - ) - - if (status === RESOLVED) return status - - return yield* exports.directory(packageSubpath, packageURL, opts) - } - } - - return UNRESOLVED -} - -exports.packageExports = function* ( - packageURL, - subpath, - packageExports, - opts = {} -) { - if (subpath === '.') { - let mainExport - - if (typeof packageExports === 'string' || Array.isArray(packageExports)) { - mainExport = packageExports - } else if (typeof packageExports === 'object' && packageExports !== null) { - const keys = Object.keys(packageExports) - - if (keys.some((key) => key.startsWith('.'))) { - if ('.' in packageExports) mainExport = packageExports['.'] - } else { - mainExport = packageExports - } - } - - if (mainExport) { - const status = yield* exports.packageTarget( - packageURL, - mainExport, - null, - false, - opts - ) - - if (status) return status - } - } else if (typeof packageExports === 'object' && packageExports !== null) { - const keys = Object.keys(packageExports) - - if (keys.every((key) => key.startsWith('.'))) { - const status = yield* exports.packageImportsExports( - subpath, - packageExports, - packageURL, - false, - opts - ) - - if (status) return status - } - } - - packageURL = new URL('package.json', packageURL) - - throw errors.PACKAGE_PATH_NOT_EXPORTED( - `Package subpath '${subpath}' is not defined by "exports" in '${packageURL}'` - ) -} - -exports.packageImports = function* (specifier, parentURL, opts = {}) { - const { imports = null } = opts - - if (specifier === '#' || specifier.startsWith('#/')) { - throw errors.INVALID_MODULE_SPECIFIER( - `Module specifier '${specifier}' is not a valid internal imports specifier` - ) - } - - for (const packageURL of exports.lookupPackageScope(parentURL, opts)) { - const info = yield { package: packageURL } - - if (info) { - if (info.imports) { - const status = yield* exports.packageImportsExports( - specifier, - info.imports, - packageURL, - true, - opts - ) - - if (status) return status - } - - if (specifier.startsWith('#')) { - throw errors.PACKAGE_IMPORT_NOT_DEFINED( - `Package import specifier '${specifier}' is not defined by "imports" in '${packageURL}'` - ) - } - - break - } - } - - if (imports) { - const status = yield* exports.packageImportsExports( - specifier, - imports, - parentURL, - true, - opts - ) - - if (status) return status - } - - return UNRESOLVED -} - -exports.packageImportsExports = function* ( - matchKey, - matchObject, - packageURL, - isImports, - opts = {} -) { - if (matchKey in matchObject && !matchKey.includes('*')) { - const target = matchObject[matchKey] - - return yield* exports.packageTarget( - packageURL, - target, - null, - isImports, - opts - ) - } - - const expansionKeys = Object.keys(matchObject) - .filter((key) => key.includes('*')) - .sort(exports.patternKeyCompare) - - for (const expansionKey of expansionKeys) { - const patternIndex = expansionKey.indexOf('*') - const patternBase = expansionKey.substring(0, patternIndex) - - if (matchKey.startsWith(patternBase) && matchKey !== patternBase) { - const patternTrailer = expansionKey.substring(patternIndex + 1) - - if ( - patternTrailer === '' || - (matchKey.endsWith(patternTrailer) && - matchKey.length >= expansionKey.length) - ) { - const target = matchObject[expansionKey] - - const patternMatch = matchKey.substring( - patternBase.length, - matchKey.length - patternTrailer.length - ) - - return yield* exports.packageTarget( - packageURL, - target, - patternMatch, - isImports, - opts - ) - } - } - } - - return UNRESOLVED -} - -exports.validateEngines = function validateEngines( - packageURL, - packageEngines, - opts = {} -) { - const { engines = {} } = opts - - for (const [engine, range] of Object.entries(packageEngines)) { - if (engine in engines) { - const version = engines[engine] - - if (!satisfies(version, range)) { - packageURL = new URL('package.json', packageURL) - - throw errors.UNSUPPORTED_ENGINE( - `Package not compatible with engine '${engine}' ${version}, requires range '${range}' defined by "engines" in '${packageURL}'` - ) - } - } - } -} - -exports.patternKeyCompare = function patternKeyCompare(keyA, keyB) { - const patternIndexA = keyA.indexOf('*') - const patternIndexB = keyB.indexOf('*') - const baseLengthA = patternIndexA === -1 ? keyA.length : patternIndexA + 1 - const baseLengthB = patternIndexB === -1 ? keyB.length : patternIndexB + 1 - if (baseLengthA > baseLengthB) return -1 - if (baseLengthB > baseLengthA) return 1 - if (patternIndexA === -1) return 1 - if (patternIndexB === -1) return -1 - if (keyA.length > keyB.length) return -1 - if (keyB.length > keyA.length) return 1 - return 0 -} - -exports.packageTarget = function* ( - packageURL, - target, - patternMatch, - isImports, - opts = {} -) { - const { conditions = [], matchedConditions = [] } = opts - - if (typeof target === 'string') { - if (!target.startsWith('./') && !isImports) { - packageURL = new URL('package.json', packageURL) - - throw errors.INVALID_PACKAGE_TARGET( - `Invalid target '${target}' defined by "exports" in '${packageURL}'` - ) - } - - if (patternMatch !== null) { - target = target.replaceAll('*', patternMatch) - } - - const status = yield* exports.url(target, packageURL, opts) - - if (status) return status - - if ( - target === '.' || - target === '..' || - target[0] === '/' || - target.startsWith('./') || - target.startsWith('../') - ) { - const resolved = yield { resolution: new URL(target, packageURL) } - - return resolved ? RESOLVED : YIELDED - } - - return yield* exports.package(target, packageURL, opts) - } - - if (Array.isArray(target)) { - for (const targetValue of target) { - const status = yield* exports.packageTarget( - packageURL, - targetValue, - patternMatch, - isImports, - opts - ) - - if (status) return status - } - } else if (typeof target === 'object' && target !== null) { - let status = UNRESOLVED - - for (const [condition, targetValue, subset] of exports.conditionMatches( - target, - conditions, - opts - )) { - matchedConditions.push(condition) - - status |= yield* exports.packageTarget( - packageURL, - targetValue, - patternMatch, - isImports, - { ...opts, conditions: subset } - ) - - matchedConditions.pop() - } - - if (status) return status - } - - return UNRESOLVED -} - -exports.builtinTarget = function* ( - packageSpecifier, - packageVersion, - target, - opts = {} -) { - const { - builtinProtocol = 'builtin:', - conditions = [], - matchedConditions = [] - } = opts - - if (typeof target === 'string') { - const targetParts = target.split('@') - - let targetName - let targetVersion - - if (target[0] !== '@') { - targetName = targetParts[0] - targetVersion = targetParts[1] || null - } else { - targetName = targetParts.slice(0, 2).join('@') - targetVersion = targetParts[2] || null - } - - if (packageSpecifier === targetName) { - if (packageVersion === null && targetVersion === null) { - const resolved = yield { - resolution: new URL(builtinProtocol + packageSpecifier) - } - - return resolved ? RESOLVED : YIELDED - } - - let version = null - - if (packageVersion === null) { - version = targetVersion - } else if (targetVersion === null || packageVersion === targetVersion) { - version = packageVersion - } - - if (version !== null) { - const resolved = yield { - resolution: new URL( - builtinProtocol + packageSpecifier + '@' + version - ) - } - - return resolved ? RESOLVED : YIELDED - } - } - } else if (Array.isArray(target)) { - for (const targetValue of target) { - const status = yield* exports.builtinTarget( - packageSpecifier, - packageVersion, - targetValue, - opts - ) - - if (status) return status - } - } else if (typeof target === 'object' && target !== null) { - let status = UNRESOLVED - - for (const [condition, targetValue, subset] of exports.conditionMatches( - target, - conditions, - opts - )) { - matchedConditions.push(condition) - - status |= yield* exports.builtinTarget( - packageSpecifier, - packageVersion, - targetValue, - { ...opts, conditions: subset } - ) - - matchedConditions.pop() - } - - if (status) return status - } - - return UNRESOLVED -} - -exports.conditionMatches = function* conditionMatches( - target, - conditions, - opts = {} -) { - if (conditions.every((condition) => typeof condition === 'string')) { - const keys = Object.keys(target) - - for (const condition of keys) { - if (condition === 'default' || conditions.includes(condition)) { - yield [condition, target[condition], conditions] - - return true - } - } - - return false - } - - let yielded = false - - for (const subset of conditions) { - if (yield* conditionMatches(target, subset, opts)) { - yielded = true - } - } - - return yielded -} - -exports.lookupPackageScope = function* lookupPackageScope(url, opts = {}) { - const { resolutions = null } = opts - - if (resolutions) { - for (const { resolution } of exports.preresolved( - '#package', - resolutions, - url, - opts - )) { - if (resolution) return yield resolution - } - - // Internal preresolution path, do not depend on this! It will be removed without - // warning. - for (const { resolution } of exports.preresolved( - 'bare:package', - resolutions, - url, - opts - )) { - if (resolution) return yield resolution - } - } - - const scopeURL = new URL(url.href) - - do { - if (scopeURL.pathname.endsWith('/node_modules')) break - - yield new URL('package.json', scopeURL) - - scopeURL.pathname = scopeURL.pathname.substring( - 0, - scopeURL.pathname.lastIndexOf('/') - ) - - if ( - scopeURL.pathname.length === 3 && - exports.isWindowsDriveLetter(scopeURL.pathname.substring(1)) - ) { - break - } - } while (scopeURL.pathname !== '' && scopeURL.pathname !== '/') -} - -exports.file = function* (filename, parentURL, isIndex, opts = {}) { - if ( - filename === '.' || - filename === '..' || - filename[filename.length - 1] === '/' || - filename[filename.length - 1] === '\\' - ) { - return UNRESOLVED - } - - if (parentURL.protocol === 'file:' && /%2f|%5c/i.test(filename)) { - throw errors.INVALID_MODULE_SPECIFIER( - `Module specifier '${filename}' is invalid` - ) - } - - const { extensions = [] } = opts - - let status = UNRESOLVED - - if (!isIndex) { - if (yield { resolution: new URL(filename, parentURL) }) { - return RESOLVED - } - - status = YIELDED - } - - for (const ext of extensions) { - if (yield { resolution: new URL(filename + ext, parentURL) }) { - return RESOLVED - } - - status = YIELDED - } - - return status -} - -exports.directory = function* (dirname, parentURL, opts = {}) { - let directoryURL - - if ( - dirname[dirname.length - 1] === '/' || - dirname[dirname.length - 1] === '\\' - ) { - directoryURL = new URL(dirname, parentURL) - } else { - directoryURL = new URL(dirname + '/', parentURL) - } - - const info = yield { package: new URL('package.json', directoryURL) } - - if (info) { - if (info.exports) { - return yield* exports.packageExports( - directoryURL, - '.', - info.exports, - opts - ) - } - - if (typeof info.main === 'string' && info.main !== '') { - const status = yield* exports.file(info.main, directoryURL, false, opts) - - if (status === RESOLVED) return status - - return yield* exports.directory(info.main, directoryURL, opts) - } - } - - return yield* exports.file('index', directoryURL, true, opts) -} - -// https://infra.spec.whatwg.org/#ascii-upper-alpha -function isASCIIUpperAlpha(c) { - return c >= 0x41 && c <= 0x5a -} - -// https://infra.spec.whatwg.org/#ascii-lower-alpha -function isASCIILowerAlpha(c) { - return c >= 0x61 && c <= 0x7a -} - -// https://infra.spec.whatwg.org/#ascii-alpha -function isASCIIAlpha(c) { - return isASCIIUpperAlpha(c) || isASCIILowerAlpha(c) -} - -// https://url.spec.whatwg.org/#windows-drive-letter -exports.isWindowsDriveLetter = function isWindowsDriveLetter(input) { - return ( - input.length >= 2 && - isASCIIAlpha(input.charCodeAt(0)) && - (input.charCodeAt(1) === 0x3a || input.charCodeAt(1) === 0x7c) - ) -} - -// https://url.spec.whatwg.org/#start-with-a-windows-drive-letter -exports.startsWithWindowsDriveLetter = function startsWithWindowsDriveLetter( - input -) { - return ( - input.length >= 2 && - exports.isWindowsDriveLetter(input) && - (input.length === 2 || - input.charCodeAt(2) === 0x2f || - input.charCodeAt(2) === 0x5c || - input.charCodeAt(2) === 0x3f || - input.charCodeAt(2) === 0x23) - ) -} diff --git a/node_modules/bare-module-resolve/lib/errors.d.ts b/node_modules/bare-module-resolve/lib/errors.d.ts deleted file mode 100644 index e700a15..0000000 --- a/node_modules/bare-module-resolve/lib/errors.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -declare class ModuleResolveError extends Error { - readonly code: string - - static INVALID_MODULE_SPECIFIER(msg: string): ModuleResolveError - static INVALID_PACKAGE_TARGET(msg: string): ModuleResolveError - static PACKAGE_PATH_NOT_EXPORTED(msg: string): ModuleResolveError - static PACKAGE_IMPORT_NOT_DEFINED(msg: string): ModuleResolveError - static UNSUPPORTED_ENGINE(msg: string): ModuleResolveError -} - -export = ModuleResolveError diff --git a/node_modules/bare-module-resolve/lib/errors.js b/node_modules/bare-module-resolve/lib/errors.js deleted file mode 100644 index c194b9c..0000000 --- a/node_modules/bare-module-resolve/lib/errors.js +++ /dev/null @@ -1,54 +0,0 @@ -module.exports = class ModuleResolveError extends Error { - constructor(msg, code, fn = ModuleResolveError) { - super(`${code}: ${msg}`) - this.code = code - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, fn) - } - } - - get name() { - return 'ModuleResolveError' - } - - static INVALID_MODULE_SPECIFIER(msg) { - return new ModuleResolveError( - msg, - 'INVALID_MODULE_SPECIFIER', - ModuleResolveError.INVALID_MODULE_SPECIFIER - ) - } - - static INVALID_PACKAGE_TARGET(msg) { - return new ModuleResolveError( - msg, - 'INVALID_PACKAGE_TARGET', - ModuleResolveError.INVALID_PACKAGE_TARGET - ) - } - - static PACKAGE_PATH_NOT_EXPORTED(msg) { - return new ModuleResolveError( - msg, - 'PACKAGE_PATH_NOT_EXPORTED', - ModuleResolveError.PACKAGE_PATH_NOT_EXPORTED - ) - } - - static PACKAGE_IMPORT_NOT_DEFINED(msg) { - return new ModuleResolveError( - msg, - 'PACKAGE_IMPORT_NOT_DEFINED', - ModuleResolveError.PACKAGE_IMPORT_NOT_DEFINED - ) - } - - static UNSUPPORTED_ENGINE(msg) { - return new ModuleResolveError( - msg, - 'UNSUPPORTED_ENGINE', - ModuleResolveError.UNSUPPORTED_ENGINE - ) - } -} diff --git a/node_modules/bare-module-resolve/package.json b/node_modules/bare-module-resolve/package.json deleted file mode 100644 index 18b2bf8..0000000 --- a/node_modules/bare-module-resolve/package.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "bare-module-resolve", - "version": "1.11.1", - "description": "Low-level module resolution algorithm for Bare", - "exports": { - "./package": "./package.json", - ".": { - "types": "./index.d.ts", - "default": "./index.js" - }, - "./errors": { - "types": "./lib/errors.d.ts", - "default": "./lib/errors.js" - } - }, - "files": [ - "index.js", - "index.d.ts", - "lib" - ], - "scripts": { - "test": "prettier . --check && bare test.js" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/holepunchto/bare-module-resolve.git" - }, - "author": "Holepunch", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/holepunchto/bare-module-resolve/issues" - }, - "homepage": "https://github.com/holepunchto/bare-module-resolve#readme", - "dependencies": { - "bare-semver": "^1.0.0" - }, - "devDependencies": { - "bare-url": "^2.1.3", - "brittle": "^3.2.1", - "prettier": "^3.3.3", - "prettier-config-standard": "^7.0.0" - }, - "peerDependencies": { - "bare-url": "*" - }, - "peerDependenciesMeta": { - "bare-url": { - "optional": true - } - } -} diff --git a/node_modules/bare-os/CMakeLists.txt b/node_modules/bare-os/CMakeLists.txt deleted file mode 100644 index 8002082..0000000 --- a/node_modules/bare-os/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare) - -project(bare_os C) - -add_bare_module(bare_os) - -target_sources( - ${bare_os} - PRIVATE - binding.c -) diff --git a/node_modules/bare-os/LICENSE b/node_modules/bare-os/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/node_modules/bare-os/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/node_modules/bare-os/README.md b/node_modules/bare-os/README.md deleted file mode 100644 index 0e29c28..0000000 --- a/node_modules/bare-os/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# bare-os - -Operating system utilities for Javascript. - -``` -npm i bare-os -``` - -## License - -Apache-2.0 diff --git a/node_modules/bare-os/binding.c b/node_modules/bare-os/binding.c deleted file mode 100644 index 3b4266a..0000000 --- a/node_modules/bare-os/binding.c +++ /dev/null @@ -1,1119 +0,0 @@ -#include -#include -#include -#include -#include -#include - -static uv_rwlock_t bare_os_env_lock; - -static uv_once_t bare_os_env_lock_guard = UV_ONCE_INIT; - -static void -bare_os__on_env_lock_init(void) { - int err = uv_rwlock_init(&bare_os_env_lock); - assert(err == 0); -} - -static js_value_t * -bare_os_type(js_env_t *env, js_callback_info_t *info) { - int err; - - uv_utsname_t buffer; - err = uv_os_uname(&buffer); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_string_utf8(env, (utf8_t *) buffer.sysname, -1, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_version(js_env_t *env, js_callback_info_t *info) { - int err; - - uv_utsname_t buffer; - err = uv_os_uname(&buffer); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_string_utf8(env, (utf8_t *) buffer.version, -1, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_release(js_env_t *env, js_callback_info_t *info) { - int err; - - uv_utsname_t buffer; - err = uv_os_uname(&buffer); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_string_utf8(env, (utf8_t *) buffer.release, -1, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_machine(js_env_t *env, js_callback_info_t *info) { - int err; - - uv_utsname_t buffer; - err = uv_os_uname(&buffer); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_string_utf8(env, (utf8_t *) buffer.machine, -1, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_exec_path(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t len = 4096; - char exec_path[4096]; - - err = uv_exepath(exec_path, &len); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_string_utf8(env, (utf8_t *) exec_path, len, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_pid(js_env_t *env, js_callback_info_t *info) { - int err; - - js_value_t *result; - err = js_create_uint32(env, uv_os_getpid(), &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_ppid(js_env_t *env, js_callback_info_t *info) { - int err; - - js_value_t *result; - err = js_create_uint32(env, uv_os_getppid(), &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_cwd(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t len = 4096; - char cwd[4096]; - - err = uv_cwd(cwd, &len); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_string_utf8(env, (utf8_t *) cwd, len, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_chdir(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t argc = 1; - js_value_t *argv[1]; - - err = js_get_callback_info(env, info, &argc, argv, NULL, NULL); - assert(err == 0); - - assert(argc == 1); - - utf8_t dir[4096]; - err = js_get_value_string_utf8(env, argv[0], dir, 4096, NULL); - assert(err == 0); - - err = uv_chdir((char *) dir); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - return NULL; -} - -static js_value_t * -bare_os_tmpdir(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t len = 4096; - char tmpdir[4096]; - - err = uv_os_tmpdir(tmpdir, &len); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_string_utf8(env, (utf8_t *) tmpdir, len, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_homedir(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t len = 4096; - char homedir[4096]; - - err = uv_os_homedir(homedir, &len); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_string_utf8(env, (utf8_t *) homedir, len, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_hostname(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t len = UV_MAXHOSTNAMESIZE; - char hostname[UV_MAXHOSTNAMESIZE]; - - err = uv_os_gethostname(hostname, &len); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_string_utf8(env, (utf8_t *) hostname, len, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_user_info(js_env_t *env, js_callback_info_t *info) { - int err; - - uv_passwd_t pwd; - err = uv_os_get_passwd(&pwd); - if (err != 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_object(env, &result); - assert(err == 0); - - js_value_t *uid; - err = js_create_int32(env, pwd.uid, &uid); - assert(err == 0); - - err = js_set_named_property(env, result, "uid", uid); - assert(err == 0); - - js_value_t *gid; - err = js_create_int32(env, pwd.gid, &gid); - assert(err == 0); - - err = js_set_named_property(env, result, "gid", gid); - assert(err == 0); - - js_value_t *username; - err = js_create_string_utf8(env, (utf8_t *) pwd.username, strlen(pwd.username), &username); - assert(err == 0); - - err = js_set_named_property(env, result, "username", username); - assert(err == 0); - - js_value_t *homedir; - err = js_create_string_utf8(env, (utf8_t *) pwd.homedir, strlen(pwd.homedir), &homedir); - assert(err == 0); - - err = js_set_named_property(env, result, "homedir", homedir); - assert(err == 0); - - js_value_t *shell; - - if (pwd.shell == NULL) { - err = js_get_null(env, &shell); - assert(err == 0); - } else { - err = js_create_string_utf8(env, (utf8_t *) pwd.shell, -1, &shell); - assert(err == 0); - } - - err = js_set_named_property(env, result, "shell", shell); - assert(err == 0); - - uv_os_free_passwd(&pwd); - - return result; -} - -static js_value_t * -bare_os_kill(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t argc = 2; - js_value_t *argv[2]; - - err = js_get_callback_info(env, info, &argc, argv, NULL, NULL); - assert(err == 0); - - assert(argc == 2); - - uint32_t pid; - err = js_get_value_uint32(env, argv[0], &pid); - assert(err == 0); - - uint32_t signum; - err = js_get_value_uint32(env, argv[1], &signum); - assert(err == 0); - - err = uv_kill(pid, signum); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - return NULL; -} - -static js_value_t * -bare_os_available_parallelism(js_env_t *env, js_callback_info_t *info) { - int err; - - js_value_t *result; - err = js_create_int64(env, uv_available_parallelism(), &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_cpu_usage(js_env_t *env, js_callback_info_t *info) { - int err; - - uv_rusage_t usage; - err = uv_getrusage(&usage); - assert(err == 0); - - js_value_t *result; - err = js_create_object(env, &result); - assert(err == 0); - -#define V(name, property) \ - { \ - uv_timeval_t time = usage.ru_##property; \ -\ - js_value_t *value; \ - err = js_create_int64(env, time.tv_sec * 1e6 + time.tv_usec, &value); \ - assert(err == 0); \ -\ - err = js_set_named_property(env, result, name, value); \ - assert(err == 0); \ - } - - V("user", utime) - V("system", stime) -#undef V - - return result; -} - -static js_value_t * -bare_os_cpu_usage_thread(js_env_t *env, js_callback_info_t *info) { - int err; - - uv_rusage_t usage; - err = uv_getrusage_thread(&usage); - assert(err == 0); - - js_value_t *result; - err = js_create_object(env, &result); - assert(err == 0); - -#define V(name, property) \ - { \ - uv_timeval_t time = usage.ru_##property; \ -\ - js_value_t *value; \ - err = js_create_int64(env, time.tv_sec * 1e6 + time.tv_usec, &value); \ - assert(err == 0); \ -\ - err = js_set_named_property(env, result, name, value); \ - assert(err == 0); \ - } - - V("user", utime) - V("system", stime) -#undef V - - return result; -} - -static js_value_t * -bare_os_resource_usage(js_env_t *env, js_callback_info_t *info) { - int err; - - uv_rusage_t usage; - err = uv_getrusage(&usage); - assert(err == 0); - - js_value_t *result; - err = js_create_object(env, &result); - assert(err == 0); - -#define V(name, property) \ - { \ - uv_timeval_t time = usage.ru_##property; \ -\ - js_value_t *value; \ - err = js_create_int64(env, time.tv_sec * 1e6 + time.tv_usec, &value); \ - assert(err == 0); \ -\ - err = js_set_named_property(env, result, name, value); \ - assert(err == 0); \ - } - - V("userCPUTime", utime) - V("systemCPUTime", stime) -#undef V - -#define V(name, property) \ - { \ - js_value_t *value; \ - err = js_create_int64(env, usage.ru_##property, &value); \ - assert(err == 0); \ -\ - err = js_set_named_property(env, result, name, value); \ - assert(err == 0); \ - } - - V("maxRSS", maxrss) - V("sharedMemorySize", ixrss) - V("unsharedDataSize", idrss) - V("unsharedStackSize", isrss) - V("minorPageFault", minflt) - V("majorPageFault", majflt) - V("swappedOut", nswap) - V("fsRead", inblock) - V("fsWrite", oublock) - V("ipcSent", msgsnd) - V("ipcReceived", msgrcv) - V("signalsCount", nsignals) - V("voluntaryContextSwitches", nvcsw) - V("involuntaryContextSwitches", nivcsw) -#undef V - - return result; -} - -static js_value_t * -bare_os_memory_usage(js_env_t *env, js_callback_info_t *info) { - int err; - - js_heap_statistics_t stats = { - .version = 1, - - // Since 0 - .total_heap_size = -1, - .used_heap_size = -1, - - // Since 1 - .external_memory = -1, - }; - - err = js_get_heap_statistics(env, &stats); - assert(err == 0); - - js_value_t *result; - err = js_create_object(env, &result); - assert(err == 0); - - size_t rss; - err = uv_resident_set_memory(&rss); - assert(err == 0); - - js_value_t *value; - err = js_create_int64(env, rss, &value); - assert(err == 0); - - err = js_set_named_property(env, result, "rss", value); - assert(err == 0); - -#define V(name, property) \ - { \ - if (stats.property != (size_t) -1) { \ - js_value_t *value; \ - err = js_create_int64(env, stats.property, &value); \ - assert(err == 0); \ -\ - err = js_set_named_property(env, result, name, value); \ - assert(err == 0); \ - } \ - } - - V("heapTotal", total_heap_size) - V("heapUsed", used_heap_size) - V("external", external_memory) -#undef V - - return result; -} - -static js_value_t * -bare_os_freemem(js_env_t *env, js_callback_info_t *info) { - int err; - - js_value_t *result; - err = js_create_int64(env, uv_get_free_memory(), &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_totalmem(js_env_t *env, js_callback_info_t *info) { - int err; - - js_value_t *result; - err = js_create_int64(env, uv_get_total_memory(), &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_uptime(js_env_t *env, js_callback_info_t *info) { - int err; - - double uptime; - err = uv_uptime(&uptime); - assert(err == 0); - - js_value_t *result; - err = js_create_double(env, uptime, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_loadavg(js_env_t *env, js_callback_info_t *info) { - int err; - - double *data; - - js_value_t *arraybuffer; - err = js_create_arraybuffer(env, sizeof(double) * 3, (void **) &data, &arraybuffer); - assert(err == 0); - - js_value_t *result; - err = js_create_typedarray(env, js_float64array, 3, arraybuffer, 0, &result); - assert(err == 0); - - uv_loadavg(data); - - return result; -} - -static js_value_t * -bare_os_cpus(js_env_t *env, js_callback_info_t *info) { - int err; - - uv_cpu_info_t *cpus; - int len; - err = uv_cpu_info(&cpus, &len); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_array_with_length(env, len, &result); - assert(err == 0); - - for (uint32_t i = 0, n = len; i < n; i++) { - uv_cpu_info_t cpu = cpus[i]; - - js_value_t *item; - err = js_create_object(env, &item); - assert(err == 0); - - err = js_set_element(env, result, i, item); - assert(err == 0); - -#define V(name, type, ...) \ - { \ - js_value_t *val; \ - err = type(env, ##__VA_ARGS__, &val); \ - assert(err == 0); \ - err = js_set_named_property(env, item, name, val); \ - assert(err == 0); \ - } - - V("model", js_create_string_utf8, (const utf8_t *) cpu.model, -1) - V("speed", js_create_double, cpu.speed) - V("times", js_create_object) -#undef V - - js_value_t *times; - err = js_get_named_property(env, item, "times", ×); - assert(err == 0); - -#define V(name) \ - { \ - js_value_t *val; \ - err = js_create_int64(env, cpu.cpu_times.name, &val); \ - assert(err == 0); \ - err = js_set_named_property(env, times, #name, val); \ - assert(err == 0); \ - } - - V(user) - V(nice) - V(sys) - V(idle) - V(irq) -#undef V - } - - uv_free_cpu_info(cpus, len); - - return result; -} - -static js_value_t * -bare_os_get_process_title(js_env_t *env, js_callback_info_t *info) { - int err; - - char title[256]; - err = uv_get_process_title(title, 256); - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_string_utf8(env, (utf8_t *) title, -1, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_set_process_title(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t argc = 1; - js_value_t *argv[1]; - - err = js_get_callback_info(env, info, &argc, argv, NULL, NULL); - assert(err == 0); - - assert(argc == 1); - - utf8_t data[256]; - err = js_get_value_string_utf8(env, argv[0], data, 256, NULL); - assert(err == 0); - - err = uv_set_process_title((char *) data); - assert(err == 0); - - return NULL; -} - -static js_value_t * -bare_os_get_env_keys(js_env_t *env, js_callback_info_t *info) { - int err; - - uv_env_item_t *items; - int len; - - uv_rwlock_rdlock(&bare_os_env_lock); - - err = uv_os_environ(&items, &len); - - uv_rwlock_rdunlock(&bare_os_env_lock); - - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - return NULL; - } - - js_value_t *result; - err = js_create_array_with_length(env, len, &result); - assert(err == 0); - - for (int i = 0; i < len; i++) { - uv_env_item_t *item = &items[i]; - - js_value_t *val; - err = js_create_string_utf8(env, (utf8_t *) item->name, -1, &val); - assert(err == 0); - - err = js_set_element(env, result, i, val); - assert(err == 0); - } - - uv_os_free_environ(items, len); - - return result; -} - -static js_value_t * -bare_os_get_env(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t argc = 1; - js_value_t *argv[1]; - - err = js_get_callback_info(env, info, &argc, argv, NULL, NULL); - assert(err == 0); - - assert(argc == 1); - - size_t name_len; - err = js_get_value_string_utf8(env, argv[0], NULL, 0, &name_len); - assert(err == 0); - - name_len += 1 /* NULL */; - - utf8_t *name = malloc(name_len); - err = js_get_value_string_utf8(env, argv[0], name, name_len, &name_len); - assert(err == 0); - - uv_rwlock_rdlock(&bare_os_env_lock); - - size_t value_len = 256; - char *value = malloc(value_len); - err = uv_os_getenv((char *) name, value, &value_len); - - js_value_t *result; - - if (err == UV_ENOENT) { - err = js_get_undefined(env, &result); - assert(err == 0); - } else { - if (err == UV_ENOBUFS) { - value = realloc(value, value_len); - - err = uv_os_getenv((char *) name, value, &value_len); - assert(err == 0); - } else if (err < 0) { - uv_rwlock_rdunlock(&bare_os_env_lock); - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - free(name); - return NULL; - } - - err = js_create_string_utf8(env, (utf8_t *) value, value_len, &result); - assert(err == 0); - } - - uv_rwlock_rdunlock(&bare_os_env_lock); - - free(name); - free(value); - - return result; -} - -static js_value_t * -bare_os_has_env(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t argc = 1; - js_value_t *argv[1]; - - err = js_get_callback_info(env, info, &argc, argv, NULL, NULL); - assert(err == 0); - - assert(argc == 1); - - size_t name_len; - err = js_get_value_string_utf8(env, argv[0], NULL, 0, &name_len); - assert(err == 0); - - utf8_t *name = malloc(++name_len); - err = js_get_value_string_utf8(env, argv[0], name, name_len, &name_len); - assert(err == 0); - - uv_rwlock_rdlock(&bare_os_env_lock); - - size_t value_len = 1; - char value[1]; - err = uv_os_getenv((char *) name, value, &value_len); - - uv_rwlock_rdunlock(&bare_os_env_lock); - - if (err != 0 && err != UV_ENOENT && err != UV_ENOBUFS) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - free(name); - return NULL; - } - - free(name); - - js_value_t *result; - err = js_get_boolean(env, err != UV_ENOENT, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_os_set_env(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t argc = 2; - js_value_t *argv[2]; - - err = js_get_callback_info(env, info, &argc, argv, NULL, NULL); - assert(err == 0); - - assert(argc == 2); - - size_t name_len; - err = js_get_value_string_utf8(env, argv[0], NULL, 0, &name_len); - assert(err == 0); - - utf8_t *name = malloc(++name_len); - err = js_get_value_string_utf8(env, argv[0], name, name_len, &name_len); - assert(err == 0); - - size_t value_len; - err = js_get_value_string_utf8(env, argv[1], NULL, 0, &value_len); - assert(err == 0); - - utf8_t *value = malloc(++value_len); - err = js_get_value_string_utf8(env, argv[1], value, value_len, &value_len); - assert(err == 0); - - uv_rwlock_wrlock(&bare_os_env_lock); - - err = uv_os_setenv((char *) name, (char *) value); - - uv_rwlock_wrunlock(&bare_os_env_lock); - - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - free(name); - free(value); - return NULL; - } - - free(name); - free(value); - - return NULL; -} - -static js_value_t * -bare_os_unset_env(js_env_t *env, js_callback_info_t *info) { - int err; - - size_t argc = 1; - js_value_t *argv[1]; - - err = js_get_callback_info(env, info, &argc, argv, NULL, NULL); - assert(err == 0); - - assert(argc == 1); - - size_t name_len; - err = js_get_value_string_utf8(env, argv[0], NULL, 0, &name_len); - assert(err == 0); - - utf8_t *name = malloc(++name_len); - err = js_get_value_string_utf8(env, argv[0], name, name_len, &name_len); - assert(err == 0); - - uv_rwlock_wrlock(&bare_os_env_lock); - - err = uv_os_unsetenv((char *) name); - - uv_rwlock_wrunlock(&bare_os_env_lock); - - if (err < 0) { - js_throw_error(env, uv_err_name(err), uv_strerror(err)); - free(name); - return NULL; - } - - free(name); - - return NULL; -} - -static js_value_t * -bare_os_exports(js_env_t *env, js_value_t *exports) { - uv_once(&bare_os_env_lock_guard, bare_os__on_env_lock_init); - - int err; - -#define V(name, str) \ - { \ - js_value_t *val; \ - err = js_create_string_utf8(env, (utf8_t *) str, -1, &val); \ - assert(err == 0); \ - err = js_set_named_property(env, exports, name, val); \ - assert(err == 0); \ - } - - V("platform", BARE_PLATFORM) - V("arch", BARE_ARCH) -#undef V - -#define V(name, fn) \ - { \ - js_value_t *val; \ - err = js_create_function(env, name, -1, fn, NULL, &val); \ - assert(err == 0); \ - err = js_set_named_property(env, exports, name, val); \ - assert(err == 0); \ - } - - V("type", bare_os_type) - V("version", bare_os_version) - V("release", bare_os_release) - V("machine", bare_os_machine) - V("execPath", bare_os_exec_path) - V("pid", bare_os_pid) - V("ppid", bare_os_ppid) - V("cwd", bare_os_cwd) - V("chdir", bare_os_chdir) - V("tmpdir", bare_os_tmpdir) - V("homedir", bare_os_homedir) - V("hostname", bare_os_hostname) - V("kill", bare_os_kill) - V("availableParallelism", bare_os_available_parallelism) - V("cpuUsage", bare_os_cpu_usage) - V("threadCpuUsage", bare_os_cpu_usage_thread) - V("resourceUsage", bare_os_resource_usage) - V("memoryUsage", bare_os_memory_usage) - V("freemem", bare_os_freemem) - V("totalmem", bare_os_totalmem) - V("uptime", bare_os_uptime) - V("loadavg", bare_os_loadavg) - V("cpus", bare_os_cpus) - V("getProcessTitle", bare_os_get_process_title) - V("setProcessTitle", bare_os_set_process_title) - V("getEnvKeys", bare_os_get_env_keys) - V("getEnv", bare_os_get_env) - V("hasEnv", bare_os_get_env) - V("setEnv", bare_os_set_env) - V("unsetEnv", bare_os_unset_env) - V("userInfo", bare_os_user_info) -#undef V - - const union { - uint8_t u8[2]; - uint16_t u16; - } byte_order = {{1, 0}}; - - js_value_t *is_little_endian; - err = js_get_boolean(env, byte_order.u16 == 1, &is_little_endian); - assert(err == 0); - - err = js_set_named_property(env, exports, "isLittleEndian", is_little_endian); - assert(err == 0); - - js_value_t *signals; - err = js_create_object(env, &signals); - assert(err == 0); - - err = js_set_named_property(env, exports, "signals", signals); - assert(err == 0); - -#define V(name) \ - { \ - js_value_t *val; \ - err = js_create_uint32(env, name, &val); \ - assert(err == 0); \ - err = js_set_named_property(env, signals, #name, val); \ - assert(err == 0); \ - } - -#ifdef SIGHUP - V(SIGHUP); -#endif -#ifdef SIGINT - V(SIGINT); -#endif -#ifdef SIGQUIT - V(SIGQUIT); -#endif -#ifdef SIGILL - V(SIGILL); -#endif -#ifdef SIGTRAP - V(SIGTRAP); -#endif -#ifdef SIGABRT - V(SIGABRT); -#endif -#ifdef SIGIOT - V(SIGIOT); -#endif -#ifdef SIGBUS - V(SIGBUS); -#endif -#ifdef SIGFPE - V(SIGFPE); -#endif -#ifdef SIGKILL - V(SIGKILL); -#endif -#ifdef SIGUSR1 - V(SIGUSR1); -#endif -#ifdef SIGSEGV - V(SIGSEGV); -#endif -#ifdef SIGUSR2 - V(SIGUSR2); -#endif -#ifdef SIGPIPE - V(SIGPIPE); -#endif -#ifdef SIGALRM - V(SIGALRM); -#endif -#ifdef SIGTERM - V(SIGTERM); -#endif -#ifdef SIGCHLD - V(SIGCHLD); -#endif -#ifdef SIGSTKFLT - V(SIGSTKFLT); -#endif -#ifdef SIGCONT - V(SIGCONT); -#endif -#ifdef SIGSTOP - V(SIGSTOP); -#endif -#ifdef SIGTSTP - V(SIGTSTP); -#endif -#ifdef SIGBREAK - V(SIGBREAK); -#endif -#ifdef SIGTTIN - V(SIGTTIN); -#endif -#ifdef SIGTTOU - V(SIGTTOU); -#endif -#ifdef SIGURG - V(SIGURG); -#endif -#ifdef SIGXCPU - V(SIGXCPU); -#endif -#ifdef SIGXFSZ - V(SIGXFSZ); -#endif -#ifdef SIGVTALRM - V(SIGVTALRM); -#endif -#ifdef SIGPROF - V(SIGPROF); -#endif -#ifdef SIGWINCH - V(SIGWINCH); -#endif -#ifdef SIGIO - V(SIGIO); -#endif -#ifdef SIGPOLL - V(SIGPOLL); -#endif -#ifdef SIGLOST - V(SIGLOST); -#endif -#ifdef SIGPWR - V(SIGPWR); -#endif -#ifdef SIGINFO - V(SIGINFO); -#endif -#ifdef SIGSYS - V(SIGSYS); -#endif -#ifdef SIGUNUSED - V(SIGUNUSED); -#endif -#undef V - - js_value_t *errnos; - err = js_create_object(env, &errnos); - assert(err == 0); - - err = js_set_named_property(env, exports, "errnos", errnos); - assert(err == 0); - -#define V(name, msg) \ - { \ - js_value_t *val; \ - err = js_create_int32(env, UV_##name, &val); \ - assert(err == 0); \ - err = js_set_named_property(env, errnos, #name, val); \ - assert(err == 0); \ - } - - UV_ERRNO_MAP(V); -#undef V - - return exports; -} - -BARE_MODULE(bare_os, bare_os_exports) diff --git a/node_modules/bare-os/binding.js b/node_modules/bare-os/binding.js deleted file mode 100644 index cea4630..0000000 --- a/node_modules/bare-os/binding.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require.addon() diff --git a/node_modules/bare-os/index.d.ts b/node_modules/bare-os/index.d.ts deleted file mode 100644 index c2de24f..0000000 --- a/node_modules/bare-os/index.d.ts +++ /dev/null @@ -1,109 +0,0 @@ -export const constants: { - signals: Record - errnos: Record -} - -export const EOL: '\r\n' | '\n' - -export function platform(): 'android' | 'darwin' | 'ios' | 'linux' | 'win32' - -export function arch(): 'arm' | 'arm64' | 'ia32' | 'x64' - -export function type(): string - -export function version(): string - -export function release(): string - -export function machine(): string - -export function execPath(): string - -export function pid(): number - -export function ppid(): number - -export function cwd(): string - -export function chdir(dir: string): string - -export function tmpdir(): string - -export function homedir(): string - -export function hostname(): string - -export function kill(pid: number, signal?: string | number): void - -export function endianness(): 'LE' | 'BE' - -export function availableParallelism(): number - -export interface CpuUsage { - user: number - system: number -} - -export function cpuUsage(previous?: CpuUsage): CpuUsage - -export function threadCpuUsage(previous?: CpuUsage): CpuUsage - -export function resourceUsage(): { - userCPUTime: number - systemCPUTime: number - maxRSS: number - sharedMemorySize: number - unsharedDataSize: number - unsharedStackSize: number - minorPageFault: number - majorPageFault: number - swappedOut: number - fsRead: number - fsWrite: number - ipcSent: number - ipcReceived: number - signalsCount: number - voluntaryContextSwitches: number - involuntaryContextSwitches: number -} - -export function memoryUsage(): { - rss: number - heapTotal: number - heapUsed: number - external: number -} - -export function freemem(): number - -export function totalmem(): number - -export function uptime(): number - -export function loadavg(): ArrayLike - -export function cpus(): { - model: string - speed: number - times: { - user: number - nice: number - sys: number - idle: number - irq: number - } -}[] - -export function getProcessTitle(): string - -export function setProcessTitle(title: unknown): void - -export function getEnvKeys(): string[] - -export function getEnv(name: string): string | undefined - -export function hasEnv(name: string): boolean - -export function setEnv(name: string, value: string): void - -export function unsetEnv(name: string): void diff --git a/node_modules/bare-os/index.js b/node_modules/bare-os/index.js deleted file mode 100644 index c536947..0000000 --- a/node_modules/bare-os/index.js +++ /dev/null @@ -1,99 +0,0 @@ -const binding = require('./binding') -const errors = require('./lib/errors') -const constants = require('./lib/constants') - -exports.constants = constants - -exports.EOL = binding.platform === 'win32' ? '\r\n' : '\n' - -exports.platform = function platform() { - return binding.platform -} - -exports.arch = function arch() { - return binding.arch -} - -exports.type = binding.type -exports.version = binding.version -exports.release = binding.release -exports.machine = binding.machine -exports.execPath = binding.execPath -exports.pid = binding.pid -exports.ppid = binding.ppid -exports.cwd = binding.cwd -exports.chdir = binding.chdir -exports.tmpdir = binding.tmpdir -exports.homedir = binding.homedir -exports.hostname = binding.hostname -exports.userInfo = binding.userInfo - -exports.kill = function kill(pid, signal = constants.signals.SIGTERM) { - if (typeof signal === 'string') { - if (signal in constants.signals === false) { - throw errors.UNKNOWN_SIGNAL('Unknown signal: ' + signal) - } - - signal = constants.signals[signal] - } - - binding.kill(pid, signal) -} - -exports.endianness = function endianness() { - return binding.isLittleEndian ? 'LE' : 'BE' -} - -exports.availableParallelism = binding.availableParallelism - -exports.cpuUsage = function cpuUsage(previous) { - const current = binding.cpuUsage() - - if (previous) { - return { - user: current.user - previous.user, - system: current.system - previous.system - } - } - - return current -} - -exports.threadCpuUsage = function threadCpuUsage(previous) { - const current = binding.threadCpuUsage() - - if (previous) { - return { - user: current.user - previous.user, - system: current.system - previous.system - } - } - - return current -} - -exports.resourceUsage = binding.resourceUsage -exports.memoryUsage = binding.memoryUsage -exports.freemem = binding.freemem -exports.totalmem = binding.totalmem -exports.uptime = binding.uptime -exports.loadavg = binding.loadavg -exports.cpus = binding.cpus - -exports.getProcessTitle = binding.getProcessTitle - -exports.setProcessTitle = function setProcessTitle(title) { - if (typeof title !== 'string') title = title.toString() - - if (title.length >= 256) { - throw errors.TITLE_OVERFLOW('Process title is too long') - } - - binding.setProcessTitle(title) -} - -exports.getEnvKeys = binding.getEnvKeys -exports.getEnv = binding.getEnv -exports.hasEnv = binding.hasEnv -exports.setEnv = binding.setEnv -exports.unsetEnv = binding.unsetEnv diff --git a/node_modules/bare-os/lib/constants.js b/node_modules/bare-os/lib/constants.js deleted file mode 100644 index e809511..0000000 --- a/node_modules/bare-os/lib/constants.js +++ /dev/null @@ -1,6 +0,0 @@ -const binding = require('../binding') - -module.exports = { - signals: binding.signals, - errnos: binding.errnos -} diff --git a/node_modules/bare-os/lib/errors.js b/node_modules/bare-os/lib/errors.js deleted file mode 100644 index 31d14f9..0000000 --- a/node_modules/bare-os/lib/errors.js +++ /dev/null @@ -1,22 +0,0 @@ -module.exports = class OSError extends Error { - constructor(msg, code, fn = OSError) { - super(`${code}: ${msg}`) - this.code = code - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, fn) - } - } - - get name() { - return 'OSError' - } - - static UNKNOWN_SIGNAL(msg) { - return new OSError(msg, 'UNKNOWN_SIGNAL', OSError.UNKNOWN_SIGNAL) - } - - static TITLE_OVERFLOW(msg) { - return new OSError(msg, 'TITLE_OVERFLOW', OSError.TITLE_OVERFLOW) - } -} diff --git a/node_modules/bare-os/package.json b/node_modules/bare-os/package.json deleted file mode 100644 index 9184f1a..0000000 --- a/node_modules/bare-os/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "bare-os", - "version": "3.6.1", - "description": "Operating system utilities for Javascript", - "exports": { - ".": { - "types": "./index.d.ts", - "default": "./index.js" - }, - "./package": "./package.json", - "./constants": "./lib/constants.js", - "./errors": "./lib/errors.js" - }, - "files": [ - "index.js", - "index.d.ts", - "binding.c", - "binding.js", - "CMakeLists.txt", - "lib", - "prebuilds" - ], - "addon": true, - "scripts": { - "test": "prettier . --check && bare test.js" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/holepunchto/bare-os.git" - }, - "author": "Holepunch", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/holepunchto/bare-os/issues" - }, - "homepage": "https://github.com/holepunchto/bare-os#readme", - "engines": { - "bare": ">=1.14.0" - }, - "devDependencies": { - "brittle": "^3.1.1", - "cmake-bare": "^1.1.6", - "prettier": "^3.4.2", - "prettier-config-standard": "^7.0.0" - } -} diff --git a/node_modules/bare-os/prebuilds/android-arm/bare-os.bare b/node_modules/bare-os/prebuilds/android-arm/bare-os.bare deleted file mode 100644 index d680d29..0000000 Binary files a/node_modules/bare-os/prebuilds/android-arm/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/android-arm64/bare-os.bare b/node_modules/bare-os/prebuilds/android-arm64/bare-os.bare deleted file mode 100644 index dfdd58a..0000000 Binary files a/node_modules/bare-os/prebuilds/android-arm64/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/android-ia32/bare-os.bare b/node_modules/bare-os/prebuilds/android-ia32/bare-os.bare deleted file mode 100644 index cfa387e..0000000 Binary files a/node_modules/bare-os/prebuilds/android-ia32/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/android-x64/bare-os.bare b/node_modules/bare-os/prebuilds/android-x64/bare-os.bare deleted file mode 100644 index e723d78..0000000 Binary files a/node_modules/bare-os/prebuilds/android-x64/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/darwin-arm64/bare-os.bare b/node_modules/bare-os/prebuilds/darwin-arm64/bare-os.bare deleted file mode 100644 index c123f45..0000000 Binary files a/node_modules/bare-os/prebuilds/darwin-arm64/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/darwin-x64/bare-os.bare b/node_modules/bare-os/prebuilds/darwin-x64/bare-os.bare deleted file mode 100644 index 65f4a61..0000000 Binary files a/node_modules/bare-os/prebuilds/darwin-x64/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/ios-arm64-simulator/bare-os.bare b/node_modules/bare-os/prebuilds/ios-arm64-simulator/bare-os.bare deleted file mode 100644 index 7a57582..0000000 Binary files a/node_modules/bare-os/prebuilds/ios-arm64-simulator/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/ios-arm64/bare-os.bare b/node_modules/bare-os/prebuilds/ios-arm64/bare-os.bare deleted file mode 100644 index c363431..0000000 Binary files a/node_modules/bare-os/prebuilds/ios-arm64/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/ios-x64-simulator/bare-os.bare b/node_modules/bare-os/prebuilds/ios-x64-simulator/bare-os.bare deleted file mode 100644 index d7f2198..0000000 Binary files a/node_modules/bare-os/prebuilds/ios-x64-simulator/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/linux-arm64/bare-os.bare b/node_modules/bare-os/prebuilds/linux-arm64/bare-os.bare deleted file mode 100644 index ae8234b..0000000 Binary files a/node_modules/bare-os/prebuilds/linux-arm64/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/linux-x64/bare-os.bare b/node_modules/bare-os/prebuilds/linux-x64/bare-os.bare deleted file mode 100644 index 975418d..0000000 Binary files a/node_modules/bare-os/prebuilds/linux-x64/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/win32-arm64/bare-os.bare b/node_modules/bare-os/prebuilds/win32-arm64/bare-os.bare deleted file mode 100644 index ff53e0c..0000000 Binary files a/node_modules/bare-os/prebuilds/win32-arm64/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-os/prebuilds/win32-x64/bare-os.bare b/node_modules/bare-os/prebuilds/win32-x64/bare-os.bare deleted file mode 100644 index 10f3774..0000000 Binary files a/node_modules/bare-os/prebuilds/win32-x64/bare-os.bare and /dev/null differ diff --git a/node_modules/bare-path/LICENSE b/node_modules/bare-path/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/node_modules/bare-path/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/node_modules/bare-path/NOTICE b/node_modules/bare-path/NOTICE deleted file mode 100644 index 1ee8d0e..0000000 --- a/node_modules/bare-path/NOTICE +++ /dev/null @@ -1,28 +0,0 @@ -Copyright 2023 Holepunch Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - ---- - -Copyright Joyent, Inc. and other Node contributors. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to permit -persons to whom the Software is furnished to do so, subject to the -following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. diff --git a/node_modules/bare-path/README.md b/node_modules/bare-path/README.md deleted file mode 100644 index de52659..0000000 --- a/node_modules/bare-path/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# bare-path - -Path manipulation library for JavaScript. - -``` -npm i bare-path -``` - -## Usage - -``` js -const path = require('bare-path') - -path.join('foo', 'bar') // foo/bar on posix, foo\bar on windows -``` - -## License - -Apache-2.0 diff --git a/node_modules/bare-path/index.js b/node_modules/bare-path/index.js deleted file mode 100644 index 4832215..0000000 --- a/node_modules/bare-path/index.js +++ /dev/null @@ -1,11 +0,0 @@ -/* global Bare */ - -// This export SHOULD NOT be shortened in any way as having the full -// `module.exports = require(...)` statement is crucial for synthesizing -// ESM exports. - -if (Bare.platform === 'win32') { - module.exports = require('./lib/win32') -} else { - module.exports = require('./lib/posix') -} diff --git a/node_modules/bare-path/lib/constants.js b/node_modules/bare-path/lib/constants.js deleted file mode 100644 index 5ce4866..0000000 --- a/node_modules/bare-path/lib/constants.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - CHAR_UPPERCASE_A: 0x41, - CHAR_LOWERCASE_A: 0x61, - CHAR_UPPERCASE_Z: 0x5a, - CHAR_LOWERCASE_Z: 0x7a, - CHAR_DOT: 0x2e, - CHAR_FORWARD_SLASH: 0x2f, - CHAR_BACKWARD_SLASH: 0x5c, - CHAR_COLON: 0x3a, - CHAR_QUESTION_MARK: 0x3f -} diff --git a/node_modules/bare-path/lib/posix.js b/node_modules/bare-path/lib/posix.js deleted file mode 100644 index ebe0a66..0000000 --- a/node_modules/bare-path/lib/posix.js +++ /dev/null @@ -1,242 +0,0 @@ -const os = require('bare-os') - -const { normalizeString } = require('./shared') -const { - CHAR_DOT, - CHAR_FORWARD_SLASH -} = require('./constants') - -function isPosixPathSeparator (code) { - return code === CHAR_FORWARD_SLASH -} - -exports.win32 = require('./win32') -exports.posix = exports - -exports.sep = '/' -exports.delimiter = ':' - -exports.resolve = function resolve (...args) { - let resolvedPath = '' - let resolvedAbsolute = false - - for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) { - const path = i >= 0 ? args[i] : os.cwd() - - if (path.length === 0) { - continue - } - - resolvedPath = `${path}/${resolvedPath}` - resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH - } - - resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator) - - if (resolvedAbsolute) { - return `/${resolvedPath}` - } - - return resolvedPath.length > 0 ? resolvedPath : '.' -} - -exports.normalize = function normalize (path) { - if (path.length === 0) return '.' - - const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH - const trailingSeparator = path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH - - path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator) - - if (path.length === 0) { - if (isAbsolute) return '/' - return trailingSeparator ? './' : '.' - } - - if (trailingSeparator) path += '/' - - return isAbsolute ? `/${path}` : path -} - -exports.isAbsolute = function isAbsolute (path) { - return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH -} - -exports.join = function join (...args) { - if (args.length === 0) return '.' - let joined - for (let i = 0; i < args.length; ++i) { - const arg = args[i] - if (arg.length > 0) { - if (joined === undefined) joined = arg - else joined += `/${arg}` - } - } - if (joined === undefined) return '.' - return exports.normalize(joined) -} - -exports.relative = function relative (from, to) { - if (from === to) return '' - - from = exports.resolve(from) - to = exports.resolve(to) - - if (from === to) return '' - - const fromStart = 1 - const fromEnd = from.length - const fromLen = fromEnd - fromStart - const toStart = 1 - const toLen = to.length - toStart - - const length = (fromLen < toLen ? fromLen : toLen) - let lastCommonSep = -1 - let i = 0 - for (; i < length; i++) { - const fromCode = from.charCodeAt(fromStart + i) - if (fromCode !== to.charCodeAt(toStart + i)) { - break - } else if (fromCode === CHAR_FORWARD_SLASH) { - lastCommonSep = i - } - } - if (i === length) { - if (toLen > length) { - if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) { - return to.substring(toStart + i + 1) - } - if (i === 0) { - return to.substring(toStart + i) - } - } else if (fromLen > length) { - if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) { - lastCommonSep = i - } else if (i === 0) { - lastCommonSep = 0 - } - } - } - - let out = '' - for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { - if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) { - out += out.length === 0 ? '..' : '/..' - } - } - - return `${out}${to.substring(toStart + lastCommonSep)}` -} - -exports.toNamespacedPath = function toNamespacedPath (path) { - return path -} - -exports.dirname = function dirname (path) { - if (path.length === 0) return '.' - const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH - let end = -1 - let matchedSlash = true - for (let i = path.length - 1; i >= 1; --i) { - if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) { - if (!matchedSlash) { - end = i - break - } - } else { - matchedSlash = false - } - } - - if (end === -1) return hasRoot ? '/' : '.' - if (hasRoot && end === 1) return '//' - return path.substring(0, end) -} - -exports.basename = function basename (path, suffix) { - let start = 0 - let end = -1 - let matchedSlash = true - - if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) { - if (suffix === path) { return '' } - let extIdx = suffix.length - 1 - let firstNonSlashEnd = -1 - for (let i = path.length - 1; i >= 0; --i) { - const code = path.charCodeAt(i) - if (code === CHAR_FORWARD_SLASH) { - if (!matchedSlash) { - start = i + 1 - break - } - } else { - if (firstNonSlashEnd === -1) { - matchedSlash = false - firstNonSlashEnd = i + 1 - } - if (extIdx >= 0) { - if (code === suffix.charCodeAt(extIdx)) { - if (--extIdx === -1) { - end = i - } - } else { - extIdx = -1 - end = firstNonSlashEnd - } - } - } - } - - if (start === end) end = firstNonSlashEnd - else if (end === -1) end = path.length - return path.substring(start, end) - } - - for (let i = path.length - 1; i >= 0; --i) { - if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) { - if (!matchedSlash) { - start = i + 1 - break - } - } else if (end === -1) { - matchedSlash = false - end = i + 1 - } - } - - if (end === -1) return '' - return path.substring(start, end) -} - -exports.extname = function extname (path) { - let startDot = -1 - let startPart = 0 - let end = -1 - let matchedSlash = true - let preDotState = 0 - for (let i = path.length - 1; i >= 0; --i) { - const code = path.charCodeAt(i) - if (code === CHAR_FORWARD_SLASH) { - if (!matchedSlash) { - startPart = i + 1 - break - } - continue - } - if (end === -1) { - matchedSlash = false - end = i + 1 - } - if (code === CHAR_DOT) { - if (startDot === -1) startDot = i - else if (preDotState !== 1) preDotState = 1 - } else if (startDot !== -1) { - preDotState = -1 - } - } - - if (startDot === -1 || end === -1 || preDotState === 0 || (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) { - return '' - } - return path.substring(startDot, end) -} diff --git a/node_modules/bare-path/lib/shared.js b/node_modules/bare-path/lib/shared.js deleted file mode 100644 index 0640aea..0000000 --- a/node_modules/bare-path/lib/shared.js +++ /dev/null @@ -1,67 +0,0 @@ -const { - CHAR_DOT, - CHAR_FORWARD_SLASH -} = require('./constants') - -exports.normalizeString = function normalizeString (path, allowAboveRoot, separator, isPathSeparator) { - let res = '' - let lastSegmentLength = 0 - let lastSlash = -1 - let dots = 0 - let code = 0 - for (let i = 0; i <= path.length; ++i) { - if (i < path.length) { - code = path.charCodeAt(i) - } else if (isPathSeparator(code)) { - break - } else { - code = CHAR_FORWARD_SLASH - } - - if (isPathSeparator(code)) { - if (lastSlash === i - 1 || dots === 1) ; - else if (dots === 2) { - if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== CHAR_DOT || res.charCodeAt(res.length - 2) !== CHAR_DOT) { - if (res.length > 2) { - const lastSlashIndex = res.lastIndexOf(separator) - if (lastSlashIndex === -1) { - res = '' - lastSegmentLength = 0 - } else { - res = res.substring(0, lastSlashIndex) - lastSegmentLength = - res.length - 1 - res.lastIndexOf(separator) - } - lastSlash = i - dots = 0 - continue - } else if (res.length !== 0) { - res = '' - lastSegmentLength = 0 - lastSlash = i - dots = 0 - continue - } - } - if (allowAboveRoot) { - res += res.length > 0 ? `${separator}..` : '..' - lastSegmentLength = 2 - } - } else { - if (res.length > 0) { - res += `${separator}${path.substring(lastSlash + 1, i)}` - } else { - res = path.substring(lastSlash + 1, i) - } - lastSegmentLength = i - lastSlash - 1 - } - lastSlash = i - dots = 0 - } else if (code === CHAR_DOT && dots !== -1) { - ++dots - } else { - dots = -1 - } - } - return res -} diff --git a/node_modules/bare-path/lib/win32.js b/node_modules/bare-path/lib/win32.js deleted file mode 100644 index 62617f9..0000000 --- a/node_modules/bare-path/lib/win32.js +++ /dev/null @@ -1,513 +0,0 @@ -const os = require('bare-os') - -const { normalizeString } = require('./shared') -const { - CHAR_UPPERCASE_A, - CHAR_LOWERCASE_A, - CHAR_UPPERCASE_Z, - CHAR_LOWERCASE_Z, - CHAR_DOT, - CHAR_FORWARD_SLASH, - CHAR_BACKWARD_SLASH, - CHAR_COLON, - CHAR_QUESTION_MARK -} = require('./constants') - -function isWindowsPathSeparator (code) { - return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH -} - -function isWindowsDeviceRoot (code) { - return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) || - (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z) -} - -exports.posix = require('./posix') -exports.win32 = exports - -exports.sep = '\\' -exports.delimiter = ';' - -exports.resolve = function resolve (...args) { - let resolvedDevice = '' - let resolvedTail = '' - let resolvedAbsolute = false - - for (let i = args.length - 1; i >= -1; i--) { - let path - if (i >= 0) { - path = args[i] - - if (path.length === 0) continue - } else if (resolvedDevice.length === 0) { - path = os.cwd() - } else { - path = os.getEnv(`=${resolvedDevice}`) || os.cwd() - - if (path === undefined || (path.substring(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() && path.charCodeAt(2) === CHAR_BACKWARD_SLASH)) { - path = `${resolvedDevice}\\` - } - } - - const len = path.length - let rootEnd = 0 - let device = '' - let isAbsolute = false - const code = path.charCodeAt(0) - - if (len === 1) { - if (isWindowsPathSeparator(code)) { - rootEnd = 1 - isAbsolute = true - } - } else if (isWindowsPathSeparator(code)) { - isAbsolute = true - - if (isWindowsPathSeparator(path.charCodeAt(1))) { - let j = 2 - let last = j - while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) { - j++ - } - if (j < len && j !== last) { - const firstPart = path.substring(last, j) - last = j - while (j < len && isWindowsPathSeparator(path.charCodeAt(j))) { - j++ - } - if (j < len && j !== last) { - last = j - while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) { - j++ - } - if (j === len || j !== last) { - device = `\\\\${firstPart}\\${path.substring(last, j)}` - rootEnd = j - } - } - } - } else { - rootEnd = 1 - } - } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) { - device = path.substring(0, 2) - rootEnd = 2 - if (len > 2 && isWindowsPathSeparator(path.charCodeAt(2))) { - isAbsolute = true - rootEnd = 3 - } - } - - if (device.length > 0) { - if (resolvedDevice.length > 0) { - if (device.toLowerCase() !== resolvedDevice.toLowerCase()) { continue } - } else { - resolvedDevice = device - } - } - - if (resolvedAbsolute) { - if (resolvedDevice.length > 0) { break } - } else { - resolvedTail = `${path.substring(rootEnd)}\\${resolvedTail}` - resolvedAbsolute = isAbsolute - if (isAbsolute && resolvedDevice.length > 0) { - break - } - } - } - - resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isWindowsPathSeparator) - - return resolvedAbsolute ? `${resolvedDevice}\\${resolvedTail}` : `${resolvedDevice}${resolvedTail}` || '.' -} - -exports.normalize = function normalize (path) { - const len = path.length - if (len === 0) return '.' - let rootEnd = 0 - let device - let isAbsolute = false - const code = path.charCodeAt(0) - - if (len === 1) { - return code === CHAR_FORWARD_SLASH ? '\\' : path - } - - if (isWindowsPathSeparator(code)) { - isAbsolute = true - - if (isWindowsPathSeparator(path.charCodeAt(1))) { - let j = 2 - let last = j - while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) { - j++ - } - if (j < len && j !== last) { - const firstPart = path.substring(last, j) - last = j - while (j < len && isWindowsPathSeparator(path.charCodeAt(j))) { - j++ - } - if (j < len && j !== last) { - last = j - while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) { - j++ - } - if (j === len) { - return `\\\\${firstPart}\\${path.substring(last)}\\` - } - if (j !== last) { - device = `\\\\${firstPart}\\${path.substring(last, j)}` - rootEnd = j - } - } - } - } else { - rootEnd = 1 - } - } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) { - device = path.substring(0, 2) - rootEnd = 2 - if (len > 2 && isWindowsPathSeparator(path.charCodeAt(2))) { - isAbsolute = true - rootEnd = 3 - } - } - - let tail = rootEnd < len ? normalizeString(path.substring(rootEnd), !isAbsolute, '\\', isWindowsPathSeparator) : '' - if (tail.length === 0 && !isAbsolute) { - tail = '.' - } - if (tail.length > 0 && isWindowsPathSeparator(path.charCodeAt(len - 1))) { - tail += '\\' - } - if (device === undefined) { - return isAbsolute ? `\\${tail}` : tail - } - return isAbsolute ? `${device}\\${tail}` : `${device}${tail}` -} - -exports.isAbsolute = function isAbsolute (path) { - const len = path.length - if (len === 0) return false - - const code = path.charCodeAt(0) - - return isWindowsPathSeparator(code) || (len > 2 && isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON && isWindowsPathSeparator(path.charCodeAt(2))) -} - -exports.join = function join (...args) { - if (args.length === 0) return '.' - - let joined - let firstPart - for (let i = 0; i < args.length; ++i) { - const arg = args[i] - if (arg.length > 0) { - if (joined === undefined) joined = firstPart = arg - else joined += `\\${arg}` - } - } - - if (joined === undefined) return '.' - - let needsReplace = true - let slashCount = 0 - if (isWindowsPathSeparator(firstPart.charCodeAt(0))) { - ++slashCount - const firstLen = firstPart.length - if (firstLen > 1 && isWindowsPathSeparator(firstPart.charCodeAt(1))) { - ++slashCount - if (firstLen > 2) { - if (isWindowsPathSeparator(firstPart.charCodeAt(2))) { - ++slashCount - } else { - needsReplace = false - } - } - } - } - if (needsReplace) { - while (slashCount < joined.length && isWindowsPathSeparator(joined.charCodeAt(slashCount))) { - slashCount++ - } - - if (slashCount >= 2) { - joined = `\\${joined.substring(slashCount)}` - } - } - - return exports.normalize(joined) -} - -exports.relative = function relative (from, to) { - if (from === to) return '' - - const fromOrig = exports.resolve(from) - const toOrig = exports.resolve(to) - - if (fromOrig === toOrig) return '' - - from = fromOrig.toLowerCase() - to = toOrig.toLowerCase() - - if (from === to) return '' - - let fromStart = 0 - while (fromStart < from.length && from.charCodeAt(fromStart) === CHAR_BACKWARD_SLASH) { - fromStart++ - } - let fromEnd = from.length - while (fromEnd - 1 > fromStart && from.charCodeAt(fromEnd - 1) === CHAR_BACKWARD_SLASH) { - fromEnd-- - } - const fromLen = fromEnd - fromStart - - let toStart = 0 - while (toStart < to.length && to.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) { - toStart++ - } - let toEnd = to.length - while (toEnd - 1 > toStart && to.charCodeAt(toEnd - 1) === CHAR_BACKWARD_SLASH) { - toEnd-- - } - const toLen = toEnd - toStart - - const length = fromLen < toLen ? fromLen : toLen - let lastCommonSep = -1 - let i = 0 - for (; i < length; i++) { - const fromCode = from.charCodeAt(fromStart + i) - if (fromCode !== to.charCodeAt(toStart + i)) { - break - } else if (fromCode === CHAR_BACKWARD_SLASH) { - lastCommonSep = i - } - } - - if (i !== length) { - if (lastCommonSep === -1) return toOrig - } else { - if (toLen > length) { - if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) { - return toOrig.substring(toStart + i + 1) - } - if (i === 2) { - return toOrig.substring(toStart + i) - } - } - if (fromLen > length) { - if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) { - lastCommonSep = i - } else if (i === 2) { - lastCommonSep = 3 - } - } - if (lastCommonSep === -1) lastCommonSep = 0 - } - - let out = '' - for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { - if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) { - out += out.length === 0 ? '..' : '\\..' - } - } - - toStart += lastCommonSep - - if (out.length > 0) { - return `${out}${toOrig.substring(toStart, toEnd)}` - } - if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) { - ++toStart - } - return toOrig.substring(toStart, toEnd) -} - -exports.toNamespacedPath = function toNamespacedPath (path) { - if (path.length === 0) return path - - const resolvedPath = exports.resolve(path) - - if (resolvedPath.length <= 2) return path - - if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) { - if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) { - const code = resolvedPath.charCodeAt(2) - if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) { - return `\\\\?\\UNC\\${resolvedPath.substring(2)}` - } - } - } else if ( - isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) && - resolvedPath.charCodeAt(1) === CHAR_COLON && - resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH - ) { - return `\\\\?\\${resolvedPath}` - } - - return path -} - -exports.dirname = function dirname (path) { - const len = path.length - if (len === 0) return '.' - let rootEnd = -1 - let offset = 0 - const code = path.charCodeAt(0) - - if (len === 1) { - return isWindowsPathSeparator(code) ? path : '.' - } - - if (isWindowsPathSeparator(code)) { - rootEnd = offset = 1 - - if (isWindowsPathSeparator(path.charCodeAt(1))) { - let j = 2 - let last = j - while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) { - j++ - } - if (j < len && j !== last) { - last = j - while (j < len && isWindowsPathSeparator(path.charCodeAt(j))) { - j++ - } - if (j < len && j !== last) { - last = j - while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) { - j++ - } - if (j === len) { - return path - } - if (j !== last) { - rootEnd = offset = j + 1 - } - } - } - } - } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) { - rootEnd = len > 2 && isWindowsPathSeparator(path.charCodeAt(2)) ? 3 : 2 - offset = rootEnd - } - - let end = -1 - let matchedSlash = true - for (let i = len - 1; i >= offset; --i) { - if (isWindowsPathSeparator(path.charCodeAt(i))) { - if (!matchedSlash) { - end = i - break - } - } else { - matchedSlash = false - } - } - - if (end === -1) { - if (rootEnd === -1) return '.' - - end = rootEnd - } - return path.substring(0, end) -} - -exports.basename = function basename (path, suffix) { - let start = 0 - let end = -1 - let matchedSlash = true - - if (path.length >= 2 && isWindowsDeviceRoot(path.charCodeAt(0)) && path.charCodeAt(1) === CHAR_COLON) { - start = 2 - } - - if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) { - if (suffix === path) return '' - let extIdx = suffix.length - 1 - let firstNonSlashEnd = -1 - for (let i = path.length - 1; i >= start; --i) { - const code = path.charCodeAt(i) - if (isWindowsPathSeparator(code)) { - if (!matchedSlash) { - start = i + 1 - break - } - } else { - if (firstNonSlashEnd === -1) { - matchedSlash = false - firstNonSlashEnd = i + 1 - } - if (extIdx >= 0) { - if (code === suffix.charCodeAt(extIdx)) { - if (--extIdx === -1) { - end = i - } - } else { - extIdx = -1 - end = firstNonSlashEnd - } - } - } - } - - if (start === end) end = firstNonSlashEnd - else if (end === -1) end = path.length - return path.substring(start, end) - } - for (let i = path.length - 1; i >= start; --i) { - if (isWindowsPathSeparator(path.charCodeAt(i))) { - if (!matchedSlash) { - start = i + 1 - break - } - } else if (end === -1) { - matchedSlash = false - end = i + 1 - } - } - - if (end === -1) return '' - return path.substring(start, end) -} - -exports.extname = function extname (path) { - let start = 0 - let startDot = -1 - let startPart = 0 - let end = -1 - let matchedSlash = true - let preDotState = 0 - - if (path.length >= 2 && path.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path.charCodeAt(0))) { - start = startPart = 2 - } - - for (let i = path.length - 1; i >= start; --i) { - const code = path.charCodeAt(i) - if (isWindowsPathSeparator(code)) { - if (!matchedSlash) { - startPart = i + 1 - break - } - continue - } - if (end === -1) { - matchedSlash = false - end = i + 1 - } - if (code === CHAR_DOT) { - if (startDot === -1) startDot = i - else if (preDotState !== 1) preDotState = 1 - } else if (startDot !== -1) { - preDotState = -1 - } - } - - if (startDot === -1 || end === -1 || preDotState === 0 || (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) { - return '' - } - return path.substring(startDot, end) -} diff --git a/node_modules/bare-path/package.json b/node_modules/bare-path/package.json deleted file mode 100644 index 7a0a023..0000000 --- a/node_modules/bare-path/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "bare-path", - "version": "3.0.0", - "description": "Path manipulation library for JavaScript", - "exports": { - ".": "./index.js", - "./package": "./package.json", - "./posix": "./lib/posix.js", - "./win32": "./lib/win32.js" - }, - "files": [ - "index.js", - "lib", - "NOTICE" - ], - "scripts": { - "test": "standard && bare test.js" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/holepunchto/bare-path.git" - }, - "author": "Holepunch", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/holepunchto/bare-path/issues" - }, - "homepage": "https://github.com/holepunchto/bare-path#readme", - "dependencies": { - "bare-os": "^3.0.1" - }, - "devDependencies": { - "brittle": "^3.3.2", - "standard": "^17.0.0" - } -} diff --git a/node_modules/bare-semver/LICENSE b/node_modules/bare-semver/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/node_modules/bare-semver/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/node_modules/bare-semver/README.md b/node_modules/bare-semver/README.md deleted file mode 100644 index 6003ceb..0000000 --- a/node_modules/bare-semver/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# bare-semver - -Minimal semantic versioning library for Bare. - -``` -npm i bare-semver -``` - -## Usage - -```js -const { Version } = require('bare-semver') - -Version.parse('1.2.3') -``` - -## License - -Apache-2.0 diff --git a/node_modules/bare-semver/index.js b/node_modules/bare-semver/index.js deleted file mode 100644 index 10b9612..0000000 --- a/node_modules/bare-semver/index.js +++ /dev/null @@ -1,13 +0,0 @@ -exports.constants = require('./lib/constants') -exports.errors = require('./lib/errors') - -const Version = exports.Version = require('./lib/version') -const Range = exports.Range = require('./lib/range') -exports.Comparator = require('./lib/comparator') - -exports.satisfies = function satisfies (version, range) { - if (typeof version === 'string') version = Version.parse(version) - if (typeof range === 'string') range = Range.parse(range) - - return range.test(version) -} diff --git a/node_modules/bare-semver/lib/comparator.js b/node_modules/bare-semver/lib/comparator.js deleted file mode 100644 index 96c79e3..0000000 --- a/node_modules/bare-semver/lib/comparator.js +++ /dev/null @@ -1,32 +0,0 @@ -const constants = require('./constants') - -const symbols = { - [constants.EQ]: '=', - [constants.LT]: '<', - [constants.LTE]: '<=', - [constants.GT]: '>', - [constants.GTE]: '>=' -} - -module.exports = class Comparator { - constructor (operator, version) { - this.operator = operator - this.version = version - } - - test (version) { - const result = version.compare(this.version) - - switch (this.operator) { - case constants.LT: return result < 0 - case constants.LTE: return result <= 0 - case constants.GT: return result > 0 - case constants.GTE: return result >= 0 - default: return result === 0 - } - } - - toString () { - return symbols[this.operator] + this.version - } -} diff --git a/node_modules/bare-semver/lib/constants.js b/node_modules/bare-semver/lib/constants.js deleted file mode 100644 index e33513f..0000000 --- a/node_modules/bare-semver/lib/constants.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - EQ: 1, - LT: 2, - LTE: 3, - GT: 4, - GTE: 5 -} diff --git a/node_modules/bare-semver/lib/errors.js b/node_modules/bare-semver/lib/errors.js deleted file mode 100644 index 684658a..0000000 --- a/node_modules/bare-semver/lib/errors.js +++ /dev/null @@ -1,22 +0,0 @@ -module.exports = class SemVerError extends Error { - constructor (msg, code, fn = SemVerError) { - super(`${code}: ${msg}`) - this.code = code - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, fn) - } - } - - get name () { - return 'SemVerError' - } - - static INVALID_VERSION (msg, fn = SemVerError.INVALID_VERSION) { - return new SemVerError(msg, 'INVALID_VERSION', fn) - } - - static INVALID_RANGE (msg, fn = SemVerError.INVALID_RANGE) { - return new SemVerError(msg, 'INVALID_RANGE', fn) - } -} diff --git a/node_modules/bare-semver/lib/range.js b/node_modules/bare-semver/lib/range.js deleted file mode 100644 index ad36210..0000000 --- a/node_modules/bare-semver/lib/range.js +++ /dev/null @@ -1,117 +0,0 @@ -const constants = require('./constants') -const errors = require('./errors') -const Version = require('./version') -const Comparator = require('./comparator') - -const Range = module.exports = exports = class Range { - constructor (comparators = []) { - this.comparators = comparators - } - - test (version) { - for (const set of this.comparators) { - let matches = true - - for (const comparator of set) { - if (comparator.test(version)) continue - matches = false - break - } - - if (matches) return true - } - - return false - } - - toString () { - let result = '' - let first = true - - for (const set of this.comparators) { - if (first) first = false - else result += ' || ' - - result += set.join(' ') - } - - return result - } -} - -exports.parse = function parse (input, state = { position: 0, partial: false }) { - let i = state.position - let c - - const unexpected = (expected) => { - let msg - - if (i >= input.length) { - msg = `Unexpected end of input in '${input}'` - } else { - msg = `Unexpected token '${input[i]}' in '${input}' at position ${i}` - } - - if (expected) msg += `, ${expected}` - - throw errors.INVALID_VERSION(msg, unexpected) - } - - const comparators = [] - - while (i < input.length) { - const set = [] - - while (i < input.length) { - c = input[i] - - let operator = constants.EQ - - if (c === '<') { - operator = constants.LT - c = input[++i] - - if (c === '=') { - operator = constants.LTE - c = input[++i] - } - } else if (c === '>') { - operator = constants.GT - c = input[++i] - - if (c === '=') { - operator = constants.GTE - c = input[++i] - } - } else if (c === '=') { - c = input[++i] - } - - const state = { position: i, partial: true } - - set.push(new Comparator(operator, Version.parse(input, state))) - - c = input[i = state.position] - - while (c === ' ') c = input[++i] - - if (c === '|' && input[i + 1] === '|') { - c = input[i += 2] - - while (c === ' ') c = input[++i] - - break - } - - if (c && c !== '<' && c !== '>') unexpected('expected \'||\', \'<\', or \'>\'') - } - - if (set.length) comparators.push(set) - } - - if (i < input.length && state.partial === false) unexpected('expected end of input') - - state.position = i - - return new Range(comparators) -} diff --git a/node_modules/bare-semver/lib/version.js b/node_modules/bare-semver/lib/version.js deleted file mode 100644 index 1b2e14b..0000000 --- a/node_modules/bare-semver/lib/version.js +++ /dev/null @@ -1,190 +0,0 @@ -const errors = require('./errors') - -const Version = module.exports = exports = class Version { - constructor (major, minor, patch, opts = {}) { - const { - prerelease = [], - build = [] - } = opts - - this.major = major - this.minor = minor - this.patch = patch - this.prerelease = prerelease - this.build = build - } - - compare (version) { - return exports.compare(this, version) - } - - toString () { - let result = `${this.major}.${this.minor}.${this.patch}` - - if (this.prerelease.length) { - result += '-' + this.prerelease.join('.') - } - - if (this.build.length) { - result += '+' + this.build.join('.') - } - - return result - } -} - -exports.parse = function parse (input, state = { position: 0, partial: false }) { - let i = state.position - let c - - const unexpected = (expected) => { - let msg - - if (i >= input.length) { - msg = `Unexpected end of input in '${input}'` - } else { - msg = `Unexpected token '${input[i]}' in '${input}' at position ${i}` - } - - if (expected) msg += `, ${expected}` - - throw errors.INVALID_VERSION(msg, unexpected) - } - - const components = [] - - while (components.length < 3) { - c = input[i] - - if (components.length > 0) { - if (c === '.') c = input[++i] - else unexpected('expected \'.\'') - } - - if (c === '0') { - components.push(0) - - i++ - } else if (c >= '1' && c <= '9') { - let j = 0 - do c = input[i + ++j] - while (c >= '0' && c <= '9') - - components.push(parseInt(input.substring(i, i + j))) - - i += j - } else unexpected('expected /[0-9]/') - } - - const prerelease = [] - - if (input[i] === '-') { - i++ - - while (true) { - c = input[i] - - let tag = '' - let j = 0 - - while (c >= '0' && c <= '9') c = input[i + ++j] - - let isNumeric = false - - if (j) { - tag += input.substring(i, i + j) - - c = input[i += j] - - isNumeric = tag[0] !== '0' || tag.length === 1 - } - - j = 0 - - while ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c === '-') c = input[i + ++j] - - if (j) { - tag += input.substring(i, i + j) - - c = input[i += j] - } else if (!isNumeric) unexpected('expected /[a-zA-Z-]/') - - prerelease.push(tag) - - if (c === '.') c = input[++i] - else break - } - } - - const build = [] - - if (input[i] === '+') { - i++ - - while (true) { - c = input[i] - - let tag = '' - let j = 0 - - while ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c === '-') c = input[i + ++j] - - if (j) { - tag += input.substring(i, i + j) - - c = input[i += j] - } else unexpected('expected /[0-9a-zA-Z-]/') - - build.push(tag) - - if (c === '.') c = input[++i] - else break - } - } - - if (i < input.length && state.partial === false) unexpected('expected end of input') - - state.position = i - - return new Version(...components, { prerelease, build }) -} - -const integer = /^[0-9]+$/ - -exports.compare = function compare (a, b) { - if (a.major > b.major) return 1 - if (a.major < b.major) return -1 - - if (a.minor > b.minor) return 1 - if (a.minor < b.minor) return -1 - - if (a.patch > b.patch) return 1 - if (a.patch < b.patch) return -1 - - if (a.prerelease.length === 0) return b.prerelease.length === 0 ? 0 : 1 - if (b.prerelease.length === 0) return -1 - - let i = 0 - do { - let x = a.prerelease[i] - let y = b.prerelease[i] - - if (x === undefined) return y === undefined ? 0 : -1 - if (y === undefined) return 1 - - if (x === y) continue - - const xInt = integer.test(x) - const yInt = integer.test(y) - - if (xInt && yInt) { - x = +x - y = +y - } else { - if (xInt) return -1 - if (yInt) return 1 - } - - return x > y ? 1 : -1 - } while (++i) -} diff --git a/node_modules/bare-semver/package.json b/node_modules/bare-semver/package.json deleted file mode 100644 index ca874c1..0000000 --- a/node_modules/bare-semver/package.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "bare-semver", - "version": "1.0.1", - "description": "Minimal semantic versioning library for Bare", - "exports": { - ".": "./index.js", - "./package": "./package.json", - "./constants": "./lib/constants.js", - "./errors": "./lib/errors.js", - "./version": "./lib/version.js", - "./range": "./lib/range.js", - "./comparator": "./lib/comparator.js" - }, - "files": [ - "index.js", - "lib" - ], - "scripts": { - "test": "standard && bare test.js" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/holepunchto/bare-semver.git" - }, - "author": "Holepunch", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/holepunchto/bare-semver/issues" - }, - "homepage": "https://github.com/holepunchto/bare-semver#readme", - "devDependencies": { - "brittle": "^3.2.1", - "standard": "^17.0.0" - } -} diff --git a/node_modules/bare-url/CMakeLists.txt b/node_modules/bare-url/CMakeLists.txt deleted file mode 100644 index d57964a..0000000 --- a/node_modules/bare-url/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare) -find_package(cmake-fetch REQUIRED PATHS node_modules/cmake-fetch) - -project(bare_url C) - -fetch_package("github:holepunchto/libutf#9c5d642") -fetch_package("github:holepunchto/liburl#03f1488") - -add_bare_module(bare_url) - -target_sources( - ${bare_url} - PRIVATE - binding.c -) - -target_link_libraries( - ${bare_url} - PRIVATE - $ - PUBLIC - url -) diff --git a/node_modules/bare-url/LICENSE b/node_modules/bare-url/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/node_modules/bare-url/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/node_modules/bare-url/README.md b/node_modules/bare-url/README.md deleted file mode 100644 index 2ed4f46..0000000 --- a/node_modules/bare-url/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# bare-url - -WHATWG URL implementation for JavaScript. - -``` -npm i bare-url -``` - -## Usage - -```js -const url = require('bare-url') - -const p = url.fileURLToPath('file:///foo') // --> /foo -``` - -## License - -Apache-2.0 diff --git a/node_modules/bare-url/binding.c b/node_modules/bare-url/binding.c deleted file mode 100644 index a6f8d1d..0000000 --- a/node_modules/bare-url/binding.c +++ /dev/null @@ -1,188 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static js_type_tag_t bare_url__tag = {0x6f1fd92f476698b0, 0x93b59c349143ee50}; - -static js_value_t * -bare_url_parse (js_env_t *env, js_callback_info_t *info) { - int err; - - size_t argc = 4; - js_value_t *argv[4]; - - err = js_get_callback_info(env, info, &argc, argv, NULL, NULL); - assert(err == 0); - - assert(argc == 4); - - bool should_throw; - err = js_get_value_bool(env, argv[3], &should_throw); - assert(err == 0); - - bool has_base; - err = js_is_string(env, argv[1], &has_base); - assert(err == 0); - - url_t base; - url_init(&base); - - if (has_base) { - size_t len; - err = js_get_value_string_utf8(env, argv[1], NULL, 0, &len); - assert(err == 0); - - utf8_t *input = malloc(len); - err = js_get_value_string_utf8(env, argv[1], input, len, NULL); - assert(err == 0); - - err = url_parse(&base, input, len, NULL); - - free(input); - - if (err < 0) { - url_destroy(&base); - - if (should_throw) js_throw_error(env, NULL, "Invalid base URL"); - - return NULL; - } - } - - size_t len; - err = js_get_value_string_utf8(env, argv[0], NULL, 0, &len); - assert(err == 0); - - utf8_t *input = malloc(len); - err = js_get_value_string_utf8(env, argv[0], input, len, NULL); - assert(err == 0); - - js_value_t *handle; - - url_t url; - url_init(&url); - - err = url_parse(&url, input, len, has_base ? &base : NULL); - - free(input); - - if (err < 0) { - url_destroy(&base); - url_destroy(&url); - - if (should_throw) js_throw_error(env, NULL, "Invalid URL"); - - return NULL; - } - - js_value_t *href; - err = js_create_string_utf8(env, url.href.data, url.href.len, &href); - assert(err == 0); - - uint32_t *components; - err = js_get_typedarray_info(env, argv[2], NULL, (void **) &components, NULL, NULL, NULL); - assert(err == 0); - - memcpy(components, &url.components, sizeof(url.components)); - - url_destroy(&base); - url_destroy(&url); - - return href; -} - -static js_value_t * -bare_url_can_parse (js_env_t *env, js_callback_info_t *info) { - int err; - - size_t argc = 2; - js_value_t *argv[2]; - - err = js_get_callback_info(env, info, &argc, argv, NULL, NULL); - assert(err == 0); - - assert(argc == 2); - - bool has_base; - err = js_is_string(env, argv[1], &has_base); - assert(err == 0); - - url_t base; - url_init(&base); - - if (has_base) { - size_t len; - err = js_get_value_string_utf8(env, argv[1], NULL, 0, &len); - assert(err == 0); - - utf8_t *input = malloc(len); - err = js_get_value_string_utf8(env, argv[1], input, len, NULL); - assert(err == 0); - - err = url_parse(&base, input, len, NULL); - - free(input); - - if (err < 0) { - url_destroy(&base); - - js_value_t *result; - err = js_get_boolean(env, false, &result); - assert(err == 0); - - return result; - } - } - - size_t len; - err = js_get_value_string_utf8(env, argv[0], NULL, 0, &len); - assert(err == 0); - - utf8_t *input = malloc(len); - err = js_get_value_string_utf8(env, argv[0], input, len, NULL); - assert(err == 0); - - url_t url; - url_init(&url); - - err = url_parse(&url, input, len, has_base ? &base : NULL); - - free(input); - - url_destroy(&base); - url_destroy(&url); - - js_value_t *result; - err = js_get_boolean(env, err == 0, &result); - assert(err == 0); - - return result; -} - -static js_value_t * -bare_url_exports (js_env_t *env, js_value_t *exports) { - int err; - -#define V(name, fn) \ - { \ - js_value_t *val; \ - err = js_create_function(env, name, -1, fn, NULL, &val); \ - assert(err == 0); \ - err = js_set_named_property(env, exports, name, val); \ - assert(err == 0); \ - } - - V("parse", bare_url_parse) - V("canParse", bare_url_can_parse) -#undef V - - return exports; -} - -BARE_MODULE(bare_url, bare_url_exports) diff --git a/node_modules/bare-url/binding.js b/node_modules/bare-url/binding.js deleted file mode 100644 index cea4630..0000000 --- a/node_modules/bare-url/binding.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require.addon() diff --git a/node_modules/bare-url/global.d.ts b/node_modules/bare-url/global.d.ts deleted file mode 100644 index 5baa595..0000000 --- a/node_modules/bare-url/global.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as url from '.' - -type URLConstructor = typeof url.URL - -declare global { - type URL = url.URL - - const URL: URLConstructor -} diff --git a/node_modules/bare-url/global.js b/node_modules/bare-url/global.js deleted file mode 100644 index 647cd02..0000000 --- a/node_modules/bare-url/global.js +++ /dev/null @@ -1 +0,0 @@ -global.URL = require('.') diff --git a/node_modules/bare-url/index.d.ts b/node_modules/bare-url/index.d.ts deleted file mode 100644 index 7bd7c8e..0000000 --- a/node_modules/bare-url/index.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -import URLError from './lib/errors' - -interface URL { - href: string - protocol: string - username: string - password: string - host: string - hostname: string - port: string - pathname: string - search: string - hash: string - - toString(): string - toJSON(): string -} - -declare class URL { - constructor(input: string, base?: string | URL) -} - -declare namespace URL { - export function isURL(value: unknown): value is URL - - export function parse(input: string, base?: string | URL): URL | null - - export function canParse(input: string, base?: string | URL): boolean - - export function fileURLToPath(url: URL | string): string - - export function pathToFileURL(pathname: string): URL - - export { URL, type URLError, URLError as errors } -} - -export = URL diff --git a/node_modules/bare-url/index.js b/node_modules/bare-url/index.js deleted file mode 100644 index 2424079..0000000 --- a/node_modules/bare-url/index.js +++ /dev/null @@ -1,374 +0,0 @@ -const path = require('bare-path') -const binding = require('./binding') -const errors = require('./lib/errors') - -const kind = Symbol.for('bare.url.kind') - -const isWindows = Bare.platform === 'win32' - -module.exports = exports = class URL { - static get [kind]() { - return 0 // Compatibility version - } - - constructor(input, base, opts = {}) { - if (arguments.length === 0) throw errors.INVALID_URL() - - input = `${input}` - - if (base !== undefined) base = `${base}` - - this._components = new Uint32Array(8) - - this._parse(input, base, opts.throw !== false) - } - - get [kind]() { - return URL[kind] - } - - // https://url.spec.whatwg.org/#dom-url-href - - get href() { - return this._href - } - - set href(value) { - this._update(value) - } - - // https://url.spec.whatwg.org/#dom-url-protocol - - get protocol() { - return this._slice(0, this._components[0]) + ':' - } - - set protocol(value) { - this._update( - this._replace(value.replace(/:+$/, ''), 0, this._components[0]) - ) - } - - // https://url.spec.whatwg.org/#dom-url-username - - get username() { - return this._slice(this._components[0] + 3 /* :// */, this._components[1]) - } - - set username(value) { - if (cannotHaveCredentialsOrPort(this)) { - return - } - - if (this.username === '') value += '@' - - this._update( - this._replace( - value, - this._components[0] + 3 /* :// */, - this._components[1] - ) - ) - } - - // https://url.spec.whatwg.org/#dom-url-password - - get password() { - return this._href.slice( - this._components[1] + 1 /* : */, - this._components[2] - 1 /* @ */ - ) - } - - set password(value) { - if (cannotHaveCredentialsOrPort(this)) { - return - } - - let start = this._components[1] + 1 /* : */ - let end = this._components[2] - 1 /* @ */ - - if (this.password === '') { - value = ':' + value - start-- - } - - if (this.username === '') { - value += '@' - end++ - } - - this._update(this._replace(value, start, end)) - } - - // https://url.spec.whatwg.org/#dom-url-host - - get host() { - return this._slice(this._components[2], this._components[5]) - } - - set host(value) { - if (hasOpaquePath(this)) { - return - } - - this._update( - this._replace( - value, - this._components[2], - this._components[value.includes(':') ? 5 : 3] - ) - ) - } - - // https://url.spec.whatwg.org/#dom-url-hostname - - get hostname() { - return this._slice(this._components[2], this._components[3]) - } - - set hostname(value) { - if (hasOpaquePath(this)) { - return - } - - this._update(this._replace(value, this._components[2], this._components[3])) - } - - // https://url.spec.whatwg.org/#dom-url-port - - get port() { - return this._slice(this._components[3] + 1 /* : */, this._components[5]) - } - - set port(value) { - if (cannotHaveCredentialsOrPort(this)) { - return - } - - let start = this._components[3] + 1 /* : */ - - if (this.port === '') { - value = ':' + value - start-- - } - - this._update(this._replace(value, start, this._components[5])) - } - - // https://url.spec.whatwg.org/#dom-url-pathname - - get pathname() { - return this._slice(this._components[5], this._components[6] - 1 /* ? */) - } - - set pathname(value) { - if (hasOpaquePath(this)) { - return - } - - if (value[0] !== '/' && value[0] !== '\\') { - value = '/' + value - } - - this._update( - this._replace(value, this._components[5], this._components[6] - 1 /* ? */) - ) - } - - // https://url.spec.whatwg.org/#dom-url-search - - get search() { - return this._slice( - this._components[6] - 1 /* ? */, - this._components[7] - 1 /* # */ - ) - } - - set search(value) { - if (value && value[0] !== '?') value = '?' + value - - this._update( - this._replace( - value, - this._components[6] - 1 /* ? */, - this._components[7] - 1 /* # */ - ) - ) - } - - // https://url.spec.whatwg.org/#dom-url-hash - - get hash() { - return this._slice(this._components[7] - 1 /* # */) - } - - set hash(value) { - if (value && value[0] !== '#') value = '#' + value - - this._update(this._replace(value, this._components[7] - 1 /* # */)) - } - - toString() { - return this._href - } - - toJSON() { - return this._href - } - - [Symbol.for('bare.inspect')]() { - return { - __proto__: { constructor: URL }, - - href: this.href, - protocol: this.protocol, - username: this.username, - password: this.password, - host: this.host, - hostname: this.hostname, - port: this.port, - pathname: this.pathname, - search: this.search, - hash: this.hash - } - } - - _slice(start, end = this._href.length) { - return this._href.slice(start, end) - } - - _replace(replacement, start, end = this._href.length) { - return this._slice(0, start) + replacement + this._slice(end) - } - - _parse(href, base, shouldThrow) { - try { - this._href = binding.parse( - String(href), - base ? String(base) : null, - this._components, - shouldThrow - ) - } catch (err) { - if (err instanceof TypeError) throw err - - throw errors.INVALID_URL() - } - } - - _update(href) { - try { - this._parse(href, null, true) - } catch (err) { - if (err instanceof TypeError) throw err - } - } -} - -// https://url.spec.whatwg.org/#url-opaque-path -function hasOpaquePath(url) { - return url.pathname[0] !== '/' -} - -// https://url.spec.whatwg.org/#cannot-have-a-username-password-port -function cannotHaveCredentialsOrPort(url) { - return url.hostname === '' || url.protocol === 'file:' -} - -const URL = exports - -exports.URL = URL // For Node.js compatibility - -exports.errors = errors - -exports.isURL = function isURL(value) { - if (value instanceof URL) return true - - return ( - typeof value === 'object' && value !== null && value[kind] === URL[kind] - ) -} - -exports.parse = function parse(input, base) { - const url = new URL(input, base, { throw: false }) - return url.href ? url : null -} - -exports.canParse = function canParse(input, base) { - return binding.canParse(String(input), base ? String(base) : null) -} - -exports.fileURLToPath = function fileURLToPath(url) { - if (typeof url === 'string') { - url = new URL(url) - } - - if (url.protocol !== 'file:') { - throw errors.INVALID_URL_SCHEME('The URL must use the file: protocol') - } - - if (isWindows) { - if (/%2f|%5c/i.test(url.pathname)) { - throw errors.INVALID_FILE_URL_PATH( - 'The file: URL path must not include encoded \\ or / characters' - ) - } - } else { - if (url.hostname) { - throw errors.INVALID_FILE_URL_HOST( - "The file: URL host must be 'localhost' or empty" - ) - } - - if (/%2f/i.test(url.pathname)) { - throw errors.INVALID_FILE_URL_PATH( - 'The file: URL path must not include encoded / characters' - ) - } - } - - const pathname = path.normalize(decodeURIComponent(url.pathname)) - - if (isWindows) { - if (url.hostname) return '\\\\' + url.hostname + pathname - - const letter = pathname.charCodeAt(1) | 0x20 - - if ( - letter < 0x61 /* a */ || - letter > 0x7a /* z */ || - pathname.charCodeAt(2) !== 0x3a /* : */ - ) { - throw errors.INVALID_FILE_URL_PATH('The file: URL path must be absolute') - } - - return pathname.slice(1) - } - - return pathname -} - -exports.pathToFileURL = function pathToFileURL(pathname) { - let resolved = path.resolve(pathname) - - if (pathname[pathname.length - 1] === '/') { - resolved += '/' - } else if (isWindows && pathname[pathname.length - 1] === '\\') { - resolved += '\\' - } - - resolved = resolved - .replaceAll('%', '%25') // Must be first - .replaceAll('#', '%23') - .replaceAll('?', '%3f') - .replaceAll('\n', '%0a') - .replaceAll('\r', '%0d') - .replaceAll('\t', '%09') - - if (!isWindows) { - resolved = resolved.replaceAll('\\', '%5c') - } - - return new URL('file:' + resolved) -} diff --git a/node_modules/bare-url/lib/errors.d.ts b/node_modules/bare-url/lib/errors.d.ts deleted file mode 100644 index 29ef71b..0000000 --- a/node_modules/bare-url/lib/errors.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -declare class URLError extends Error { - static INVALID_URL(msg?: string): URLError - static INVALID_URL_SCHEME(msg?: string): URLError - static INVALID_FILE_URL_HOST(msg?: string): URLError - static INVALID_FILE_URL_PATH(msg?: string): URLError -} - -export = URLError diff --git a/node_modules/bare-url/lib/errors.js b/node_modules/bare-url/lib/errors.js deleted file mode 100644 index 0acc1ee..0000000 --- a/node_modules/bare-url/lib/errors.js +++ /dev/null @@ -1,38 +0,0 @@ -module.exports = class URLError extends Error { - constructor(msg, code, fn = URLError) { - super(`${code}: ${msg}`) - this.code = code - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, fn) - } - } - - get name() { - return 'URLError' - } - - static INVALID_URL(msg = 'Invalid URL') { - return new URLError(msg, 'INVALID_URL', URLError.INVALID_URL) - } - - static INVALID_URL_SCHEME(msg = 'Invalid URL') { - return new URLError(msg, 'INVALID_URL_SCHEME', URLError.INVALID_URL_SCHEME) - } - - static INVALID_FILE_URL_HOST(msg = 'Invalid file: URL host') { - return new URLError( - msg, - 'INVALID_FILE_URL_HOST', - URLError.INVALID_FILE_URL_HOST - ) - } - - static INVALID_FILE_URL_PATH(msg = 'Invalid file: URL path') { - return new URLError( - msg, - 'INVALID_FILE_URL_PATH', - URLError.INVALID_FILE_URL_PATH - ) - } -} diff --git a/node_modules/bare-url/package.json b/node_modules/bare-url/package.json deleted file mode 100644 index a65f9f7..0000000 --- a/node_modules/bare-url/package.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "bare-url", - "version": "2.1.6", - "description": "WHATWG URL implementation for JavaScript", - "exports": { - "./package": "./package.json", - ".": { - "types": "./index.d.ts", - "default": "./index.js" - }, - "./global": { - "types": "./global.d.ts", - "default": "./global.js" - } - }, - "files": [ - "index.js", - "index.d.ts", - "global.js", - "global.d.ts", - "binding.c", - "binding.js", - "CMakeLists.txt", - "lib", - "prebuilds" - ], - "addon": true, - "scripts": { - "test": "prettier . --check && bare test.js" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/holepunchto/bare-url.git" - }, - "author": "Holepunch", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/holepunchto/bare-url/issues" - }, - "homepage": "https://github.com/holepunchto/bare-url", - "dependencies": { - "bare-path": "^3.0.0" - }, - "devDependencies": { - "brittle": "^3.3.2", - "cmake-bare": "^1.1.6", - "cmake-fetch": "^1.0.0", - "prettier": "^3.3.3", - "prettier-config-standard": "^7.0.0" - } -} diff --git a/node_modules/bare-url/prebuilds/android-arm/bare-url.bare b/node_modules/bare-url/prebuilds/android-arm/bare-url.bare deleted file mode 100644 index 0038491..0000000 Binary files a/node_modules/bare-url/prebuilds/android-arm/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/android-arm64/bare-url.bare b/node_modules/bare-url/prebuilds/android-arm64/bare-url.bare deleted file mode 100644 index 9b0b667..0000000 Binary files a/node_modules/bare-url/prebuilds/android-arm64/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/android-ia32/bare-url.bare b/node_modules/bare-url/prebuilds/android-ia32/bare-url.bare deleted file mode 100644 index e278efe..0000000 Binary files a/node_modules/bare-url/prebuilds/android-ia32/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/android-x64/bare-url.bare b/node_modules/bare-url/prebuilds/android-x64/bare-url.bare deleted file mode 100644 index b844f41..0000000 Binary files a/node_modules/bare-url/prebuilds/android-x64/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/darwin-arm64/bare-url.bare b/node_modules/bare-url/prebuilds/darwin-arm64/bare-url.bare deleted file mode 100644 index 2f3b8c8..0000000 Binary files a/node_modules/bare-url/prebuilds/darwin-arm64/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/darwin-x64/bare-url.bare b/node_modules/bare-url/prebuilds/darwin-x64/bare-url.bare deleted file mode 100644 index e3b4a94..0000000 Binary files a/node_modules/bare-url/prebuilds/darwin-x64/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/ios-arm64-simulator/bare-url.bare b/node_modules/bare-url/prebuilds/ios-arm64-simulator/bare-url.bare deleted file mode 100644 index be03b24..0000000 Binary files a/node_modules/bare-url/prebuilds/ios-arm64-simulator/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/ios-arm64/bare-url.bare b/node_modules/bare-url/prebuilds/ios-arm64/bare-url.bare deleted file mode 100644 index 4e80833..0000000 Binary files a/node_modules/bare-url/prebuilds/ios-arm64/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/ios-x64-simulator/bare-url.bare b/node_modules/bare-url/prebuilds/ios-x64-simulator/bare-url.bare deleted file mode 100644 index 2aba7ed..0000000 Binary files a/node_modules/bare-url/prebuilds/ios-x64-simulator/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/linux-arm64/bare-url.bare b/node_modules/bare-url/prebuilds/linux-arm64/bare-url.bare deleted file mode 100644 index 07da7d3..0000000 Binary files a/node_modules/bare-url/prebuilds/linux-arm64/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/linux-x64/bare-url.bare b/node_modules/bare-url/prebuilds/linux-x64/bare-url.bare deleted file mode 100644 index 2bc5202..0000000 Binary files a/node_modules/bare-url/prebuilds/linux-x64/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare b/node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare deleted file mode 100644 index 2488424..0000000 Binary files a/node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare and /dev/null differ diff --git a/node_modules/bare-url/prebuilds/win32-x64/bare-url.bare b/node_modules/bare-url/prebuilds/win32-x64/bare-url.bare deleted file mode 100644 index 67817ed..0000000 Binary files a/node_modules/bare-url/prebuilds/win32-x64/bare-url.bare and /dev/null differ diff --git a/node_modules/require-addon/LICENSE b/node_modules/require-addon/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/node_modules/require-addon/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/node_modules/require-addon/README.md b/node_modules/require-addon/README.md deleted file mode 100644 index 9655759..0000000 --- a/node_modules/require-addon/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# require-addon - -Import native addons across JavaScript runtimes. - -``` -npm i require-addon -``` - -## Usage - -```js -require.addon = require('require-addon') - -const bindings = require.addon('.', __filename) -``` - -## License - -Apache-2.0 diff --git a/node_modules/require-addon/index.js b/node_modules/require-addon/index.js deleted file mode 100644 index 694d399..0000000 --- a/node_modules/require-addon/index.js +++ /dev/null @@ -1,9 +0,0 @@ -const runtime = require('./lib/runtime') - -if (runtime === 'bare') { - module.exports = require('./lib/runtime/bare') -} else if (runtime === 'node') { - module.exports = require('./lib/runtime/node') -} else { - module.exports = require('./lib/runtime/default') -} diff --git a/node_modules/require-addon/lib/runtime.js b/node_modules/require-addon/lib/runtime.js deleted file mode 100644 index b14299c..0000000 --- a/node_modules/require-addon/lib/runtime.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = - typeof Bare !== 'undefined' - ? 'bare' - : typeof process !== 'undefined' - ? 'node' - : 'unknown' diff --git a/node_modules/require-addon/lib/runtime/bare.js b/node_modules/require-addon/lib/runtime/bare.js deleted file mode 100644 index 37597a5..0000000 --- a/node_modules/require-addon/lib/runtime/bare.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require.addon.bind(require) diff --git a/node_modules/require-addon/lib/runtime/default.js b/node_modules/require-addon/lib/runtime/default.js deleted file mode 100644 index bd6099b..0000000 --- a/node_modules/require-addon/lib/runtime/default.js +++ /dev/null @@ -1,9 +0,0 @@ -if (typeof require.addon === 'function') { - module.exports = require.addon.bind(require) -} else { - module.exports = function addon(specifier, parentURL) { - throw new Error( - `Cannot find addon '${specifier}' imported from '${parentURL}'` - ) - } -} diff --git a/node_modules/require-addon/lib/runtime/node.js b/node_modules/require-addon/lib/runtime/node.js deleted file mode 100644 index d1c727e..0000000 --- a/node_modules/require-addon/lib/runtime/node.js +++ /dev/null @@ -1,42 +0,0 @@ -if (typeof require.addon === 'function') { - module.exports = require.addon.bind(require) -} else { - const url = require('url') - const resolve = require('bare-addon-resolve') - - const host = process.platform + '-' + process.arch - const conditions = ['node', process.platform, process.arch] - const extensions = ['.node'] - - module.exports = function addon(specifier, parentURL) { - if (typeof parentURL === 'string') parentURL = url.pathToFileURL(parentURL) - - for (const resolution of resolve( - specifier, - parentURL, - { host, conditions, extensions }, - readPackage - )) { - switch (resolution.protocol) { - case 'file:': - try { - return require(url.fileURLToPath(resolution)) - } catch { - continue - } - } - } - - throw new Error( - `Cannot find addon '${specifier}' imported from '${parentURL.href}'` - ) - - function readPackage(packageURL) { - try { - return require(url.fileURLToPath(packageURL)) - } catch (err) { - return null - } - } - } -} diff --git a/node_modules/require-addon/package.json b/node_modules/require-addon/package.json deleted file mode 100644 index 3ac5e81..0000000 --- a/node_modules/require-addon/package.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "name": "require-addon", - "version": "1.1.0", - "description": "Import native addons across JavaScript runtimes", - "exports": { - ".": "./index.js", - "./package": "./package.json" - }, - "imports": { - "fs": { - "bare": "bare-fs", - "default": "fs" - }, - "path": { - "bare": "bare-path", - "default": "path" - }, - "url": { - "bare": "bare-url", - "default": "url" - } - }, - "files": [ - "index.js", - "lib" - ], - "scripts": { - "test": "npm run lint && npm run test:bare && npm run test:node", - "test:bare": "bare test.js", - "test:node": "node test.js", - "lint": "prettier . --check" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/holepunchto/require-addon.git" - }, - "author": "Holepunch", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/holepunchto/require-addon/issues" - }, - "homepage": "https://github.com/holepunchto/require-addon#readme", - "engines": { - "bare": ">=1.10.0" - }, - "dependencies": { - "bare-addon-resolve": "^1.3.0", - "bare-url": "^2.1.0" - }, - "devDependencies": { - "bare-bundle": "^1.8.1", - "bare-bundle-evaluate": "^1.1.0", - "bare-fs": "^4.0.0", - "bare-path": "^3.0.0", - "brittle": "^3.7.0", - "prettier": "^3.4.1", - "prettier-config-standard": "^7.0.0" - } -} diff --git a/node_modules/sodium-native/CMakeLists.txt b/node_modules/sodium-native/CMakeLists.txt deleted file mode 100644 index b4908f0..0000000 --- a/node_modules/sodium-native/CMakeLists.txt +++ /dev/null @@ -1,249 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare) -find_package(cmake-fetch REQUIRED PATHS node_modules/cmake-fetch) -find_package(cmake-napi REQUIRED PATHS node_modules/cmake-napi) - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -project(sodium_native C ASM) - -fetch_package("github:jedisct1/libsodium#stable" SOURCE_DIR sodium) - -bare_target(target) - -if(target MATCHES "win32") - add_compile_options(/MT$<$:d>) -endif() - -file(COPY_FILE "${sodium}/builds/msvc/version.h" "${sodium}/src/libsodium/include/sodium/version.h") - -file(GLOB_RECURSE sodium_headers CONFIGURE_DEPENDS "${sodium}/src/libsodium/**/*.h") -file(GLOB_RECURSE sodium_sources CONFIGURE_DEPENDS "${sodium}/src/libsodium/**/*.c") -file(GLOB_RECURSE sodium_asm_sources CONFIGURE_DEPENDS "${sodium}/src/libsodium/**/*.S") - -add_library(sodium OBJECT) - -target_sources( - sodium - INTERFACE - ${sodium_headers} - PRIVATE - ${sodium_sources} -) - -target_include_directories( - sodium - INTERFACE - "${sodium}/src/libsodium/include" - PRIVATE - "${sodium}/src/libsodium/include/sodium" -) - -if(NOT target MATCHES "win32") - target_compile_options( - sodium - PRIVATE - -fvisibility=hidden - -fno-strict-aliasing - -fwrapv - -flax-vector-conversions - ) -endif() - -target_compile_definitions( - sodium - PUBLIC - SODIUM_STATIC=1 - PRIVATE - _GNU_SOURCE=1 - CONFIGURED=1 - DEV_MODE=1 - HAVE_ATOMIC_OPS=1 - HAVE_C11_MEMORY_FENCES=1 - HAVE_CET_H=1 - HAVE_GCC_MEMORY_FENCES=1 - HAVE_INLINE_ASM=1 - HAVE_INTTYPES_H=1 - HAVE_STDINT_H=1 - HAVE_TI_MODE=1 -) - -if(target MATCHES "darwin|ios") - target_compile_definitions( - sodium - PRIVATE - ASM_HIDE_SYMBOL=.private_extern - TLS=_Thread_local - HAVE_ARC4RANDOM=1 - HAVE_ARC4RANDOM_BUF=1 - HAVE_CATCHABLE_ABRT=1 - HAVE_CATCHABLE_SEGV=1 - HAVE_CLOCK_GETTIME=1 - HAVE_GETPID=1 - HAVE_MADVISE=1 - HAVE_MEMSET_S=1 - HAVE_MLOCK=1 - HAVE_MMAP=1 - HAVE_MPROTECT=1 - HAVE_NANOSLEEP=1 - HAVE_POSIX_MEMALIGN=1 - HAVE_PTHREAD=1 - HAVE_PTHREAD_PRIO_INHERIT=1 - HAVE_RAISE=1 - HAVE_SYSCONF=1 - HAVE_SYS_MMAN_H=1 - HAVE_SYS_PARAM_H=1 - HAVE_WEAK_SYMBOLS=1 - ) - - if(NOT target MATCHES "ios") - target_compile_definitions( - sodium - PRIVATE - HAVE_GETENTROPY=1 - HAVE_SYS_RANDOM_H=1 - ) - endif() -endif() - -if(target MATCHES "linux") - target_compile_definitions( - sodium - PRIVATE - ASM_HIDE_SYMBOL=.hidden - TLS=_Thread_local - HAVE_CATCHABLE_ABRT=1 - HAVE_CATCHABLE_SEGV=1 - HAVE_CLOCK_GETTIME=1 - HAVE_GETPID=1 - HAVE_MADVISE=1 - HAVE_MLOCK=1 - HAVE_MMAP=1 - HAVE_MPROTECT=1 - HAVE_NANOSLEEP=1 - HAVE_POSIX_MEMALIGN=1 - HAVE_PTHREAD_PRIO_INHERIT=1 - HAVE_PTHREAD=1 - HAVE_RAISE=1 - HAVE_SYSCONF=1 - HAVE_SYS_AUXV_H=1 - HAVE_SYS_MMAN_H=1 - HAVE_SYS_PARAM_H=1 - HAVE_SYS_RANDOM_H=1 - HAVE_WEAK_SYMBOLS=1 - ) -endif() - -if(target MATCHES "win32") - target_compile_definitions( - sodium - PRIVATE - _CRT_SECURE_NO_WARNINGS=1 - HAVE_RAISE=1 - ) -endif() - -if(target MATCHES "x64") - target_compile_definitions( - sodium - PRIVATE - HAVE_CPUID=1 - HAVE_RDRAND=1 - HAVE_EMMINTRIN_H=1 # SSE2 - HAVE_PMMINTRIN_H=1 # SSE3 - HAVE_TMMINTRIN_H=1 # SSSE3 - HAVE_SMMINTRIN_H=1 # SSE4.1 - HAVE_WMMINTRIN_H=1 # AES - HAVE_AVXINTRIN_H=1 # AVX - HAVE_AVX2INTRIN_H=1 # AVX2 - HAVE_AVX512FINTRIN_H # AVX512F - ) - - if(NOT target MATCHES "win32") - target_compile_definitions( - sodium - PRIVATE - HAVE_AMD64_ASM=1 - HAVE_AVX_ASM=1 - ) - - target_sources( - sodium - PRIVATE - ${sodium_asm_sources} - ) - endif() -endif() - -if(target MATCHES "arm64") - target_compile_definitions( - sodium - PRIVATE - HAVE_ARMCRYPTO=1 - ) -endif() - -if(CMAKE_C_BYTE_ORDER MATCHES "BIG_ENDIAN") - target_compile_definitions( - sodium - PRIVATE - NATIVE_BIG_ENDIAN=1 - ) -else() - target_compile_definitions( - sodium - PRIVATE - NATIVE_LITTLE_ENDIAN=1 - ) -endif() - -if(target MATCHES "linux|android") - target_link_options( - sodium - PUBLIC - -Wl,-z,noexecstack - ) -endif() - -add_bare_module(sodium_native_bare) - -target_sources( - ${sodium_native_bare} - PRIVATE - binding.c - macros.h - extensions/tweak/tweak.c - extensions/tweak/tweak.h - extensions/pbkdf2/pbkdf2.c - extensions/pbkdf2/pbkdf2.h -) - -target_link_libraries( - ${sodium_native_bare} - PRIVATE - $ - PUBLIC - sodium -) - -add_napi_module(sodium_native_node) - -target_sources( - ${sodium_native_node} - PRIVATE - binding.c - macros.h - extensions/tweak/tweak.c - extensions/tweak/tweak.h - extensions/pbkdf2/pbkdf2.c - extensions/pbkdf2/pbkdf2.h -) - -target_link_libraries( - ${sodium_native_node} - PRIVATE - $ - PUBLIC - sodium -) diff --git a/node_modules/sodium-native/LICENSE b/node_modules/sodium-native/LICENSE deleted file mode 100644 index aebbe8d..0000000 --- a/node_modules/sodium-native/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 Mathias Buus and Emil Bay - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/node_modules/sodium-native/README.md b/node_modules/sodium-native/README.md deleted file mode 100644 index 93a11b6..0000000 --- a/node_modules/sodium-native/README.md +++ /dev/null @@ -1,51 +0,0 @@ -# sodium-native - -Low level bindings for [libsodium](https://github.com/jedisct1/libsodium). - -``` -npm install sodium-native -``` - -The goal of this project is to be thin, stable, unopionated wrapper around libsodium. - -All methods exposed are more or less a direct translation of the libsodium c-api. -This means that most data types are buffers and you have to manage allocating return values and passing them in as arguments instead of receiving them as return values. - -This makes this API harder to use than other libsodium wrappers out there, but also means that you'll be able to get a lot of perf / memory improvements as you can do stuff like inline encryption / decryption, reuse buffers etc. - -This also makes this library useful as a foundation for more high level crypto abstractions that you want to make. - -## Usage - -``` js -var sodium = require('sodium-native') - -var nonce = Buffer.alloc(sodium.crypto_secretbox_NONCEBYTES) -var key = sodium.sodium_malloc(sodium.crypto_secretbox_KEYBYTES) // secure buffer -var message = Buffer.from('Hello, World!') -var ciphertext = Buffer.alloc(message.length + sodium.crypto_secretbox_MACBYTES) - -sodium.randombytes_buf(nonce) // insert random data into nonce -sodium.randombytes_buf(key) // insert random data into key - -// encrypted message is stored in ciphertext. -sodium.crypto_secretbox_easy(ciphertext, message, nonce, key) - -console.log('Encrypted message:', ciphertext) - -var plainText = Buffer.alloc(ciphertext.length - sodium.crypto_secretbox_MACBYTES) - -if (!sodium.crypto_secretbox_open_easy(plainText, ciphertext, nonce, key)) { - console.log('Decryption failed!') -} else { - console.log('Decrypted message:', plainText, '(' + plainText.toString() + ')') -} -``` - -## Documentation - -Complete documentation may be found on the [sodium-friends website](https://sodium-friends.github.io/docs/docs/getstarted) - -## License - -MIT diff --git a/node_modules/sodium-native/binding.c b/node_modules/sodium-native/binding.c deleted file mode 100644 index a7b2e76..0000000 --- a/node_modules/sodium-native/binding.c +++ /dev/null @@ -1,3470 +0,0 @@ -#include -#include -#include -#include -#include "macros.h" -#include "extensions/tweak/tweak.h" -#include "extensions/pbkdf2/pbkdf2.h" - -static uint8_t typedarray_width (napi_typedarray_type type) { - switch (type) { - case napi_int8_array: return 1; - case napi_uint8_array: return 1; - case napi_uint8_clamped_array: return 1; - case napi_int16_array: return 2; - case napi_uint16_array: return 2; - case napi_int32_array: return 4; - case napi_uint32_array: return 4; - case napi_float32_array: return 4; - case napi_float64_array: return 8; - case napi_bigint64_array: return 8; - case napi_biguint64_array: return 8; - default: return 0; - } -} - -static void sn_sodium_free_finalise (napi_env env, void *finalise_data, void *finalise_hint) { - napi_adjust_external_memory(env, -4 * 4096, NULL); - sodium_free(finalise_data); -} - -napi_value sn_sodium_memzero (napi_env env, napi_callback_info info) { - SN_ARGV(1, sodium_memzero) - - SN_ARGV_TYPEDARRAY(buf, 0) - - sodium_memzero(buf_data, buf_size); - - return NULL; -} - -napi_value sn_sodium_mlock (napi_env env, napi_callback_info info) { - SN_ARGV(1, sodium_mlock) - - SN_ARGV_TYPEDARRAY(buf, 0) - - SN_RETURN(sodium_mlock(buf_data, buf_size), "memory lock failed") -} - -napi_value sn_sodium_munlock (napi_env env, napi_callback_info info) { - SN_ARGV(1, sodium_munlock) - - SN_ARGV_TYPEDARRAY(buf, 0) - - SN_RETURN(sodium_munlock(buf_data, buf_size), "memory unlock failed") -} - -napi_value sn_sodium_free (napi_env env, napi_callback_info info) { - SN_ARGV(1, sodium_free) - - SN_ARGV_TYPEDARRAY_PTR(buf, 0) - - if (buf_data == NULL) return NULL; - - napi_value array_buf; - - SN_STATUS_THROWS(napi_get_named_property(env, argv[0], "buffer", &array_buf), "failed to get arraybuffer"); - SN_STATUS_THROWS(napi_remove_wrap(env, array_buf, NULL), "failed to remove wrap"); // remove the finalizer - SN_STATUS_THROWS(napi_detach_arraybuffer(env, array_buf), "failed to detach array buffer"); - napi_adjust_external_memory(env, -4 * 4096, NULL); - sodium_free(buf_data); - - return NULL; -} - -napi_value sn_sodium_malloc (napi_env env, napi_callback_info info) { - SN_ARGV(1, sodium_malloc); - - SN_ARGV_UINT32(size, 0) - - void *ptr = sodium_malloc(size); - - SN_THROWS(ptr == NULL, "ENOMEM") - napi_adjust_external_memory(env, 4 * 4096, NULL); - - SN_THROWS(ptr == NULL, "sodium_malloc failed"); - - napi_value buf, value, array_buf; - - SN_STATUS_THROWS(napi_create_external_buffer(env, size, ptr, NULL, NULL, &buf), "failed to create a n-api buffer") - SN_STATUS_THROWS(napi_get_boolean(env, true, &value), "failed to create boolean") - - SN_STATUS_THROWS(napi_get_named_property(env, buf, "buffer", &array_buf), "failed to get arraybuffer") - SN_STATUS_THROWS(napi_set_named_property(env, buf, "secure", value), "failed to set secure property") - - SN_STATUS_THROWS(napi_wrap(env, array_buf, ptr, sn_sodium_free_finalise, NULL, NULL), "failed to wrap") - - return buf; -} - -napi_value sn_sodium_mprotect_noaccess (napi_env env, napi_callback_info info) { - SN_ARGV(1, sodium_mprotect_noaccess); - - SN_ARGV_TYPEDARRAY_PTR(buf, 0) - - SN_RETURN(sodium_mprotect_noaccess(buf_data), "failed to lock buffer") -} - - -napi_value sn_sodium_mprotect_readonly (napi_env env, napi_callback_info info) { - SN_ARGV(1, sodium_readonly); - - SN_ARGV_TYPEDARRAY_PTR(buf, 0) - - SN_RETURN(sodium_mprotect_readonly(buf_data), "failed to unlock buffer") -} - - -napi_value sn_sodium_mprotect_readwrite (napi_env env, napi_callback_info info) { - SN_ARGV(1, sodium_readwrite); - - SN_ARGV_TYPEDARRAY_PTR(buf, 0) - - SN_RETURN(sodium_mprotect_readwrite(buf_data), "failed to unlock buffer") -} - -napi_value sn_randombytes_random (napi_env env, napi_callback_info info) { - napi_value result; - - napi_create_uint32(env, randombytes_random(), &result); - return result; -} - -napi_value sn_randombytes_uniform (napi_env env, napi_callback_info info) { - SN_ARGV(1, randombytes_uniform); - - SN_ARGV_UINT32(upper_bound, 0) - - napi_value result; - napi_create_uint32(env, randombytes_uniform(upper_bound), &result); - return result; -} - -napi_value sn_randombytes_buf (napi_env env, napi_callback_info info) { - SN_ARGV(1, randombytes_buf) - - SN_ARGV_TYPEDARRAY(buf, 0) - - randombytes_buf(buf_data, buf_size); - - return NULL; -} - -napi_value sn_randombytes_buf_deterministic (napi_env env, napi_callback_info info) { - SN_ARGV(2, randombytes_buf) - - SN_ARGV_TYPEDARRAY(buf, 0) - SN_ARGV_TYPEDARRAY(seed, 1) - - SN_ASSERT_LENGTH(seed_size, randombytes_SEEDBYTES, "seed") - - randombytes_buf_deterministic(buf_data, buf_size, seed_data); - - return NULL; -} - -napi_value sn_sodium_memcmp(napi_env env, napi_callback_info info) { - SN_ARGV(2, sodium_memcmp); - - SN_ARGV_TYPEDARRAY(b1, 0) - SN_ARGV_TYPEDARRAY(b2, 1) - - SN_THROWS(b1_size != b2_size, "buffers must be of same length") - - SN_RETURN_BOOLEAN(sodium_memcmp(b1_data, b2_data, b1_size)) -} - -napi_value sn_sodium_increment(napi_env env, napi_callback_info info) { - SN_ARGV(1, sodium_increment); - SN_ARGV_TYPEDARRAY(n, 0) - - sodium_increment(n_data, n_size); - - return NULL; -} - -napi_value sn_sodium_add(napi_env env, napi_callback_info info) { - SN_ARGV(2, sodium_add); - - SN_ARGV_TYPEDARRAY(a, 0) - SN_ARGV_TYPEDARRAY(b, 1) - - SN_THROWS(a_size != b_size, "buffers must be of same length") - sodium_add(a_data, b_data, a_size); - - return NULL; -} - -napi_value sn_sodium_sub(napi_env env, napi_callback_info info) { - SN_ARGV(2, sodium_sub); - - SN_ARGV_TYPEDARRAY(a, 0) - SN_ARGV_TYPEDARRAY(b, 1) - - SN_THROWS(a_size != b_size, "buffers must be of same length") - sodium_sub(a_data, b_data, a_size); - - return NULL; -} - -napi_value sn_sodium_compare(napi_env env, napi_callback_info info) { - SN_ARGV(2, sodium_compare); - - SN_ARGV_TYPEDARRAY(a, 0) - SN_ARGV_TYPEDARRAY(b, 1) - - SN_THROWS(a_size != b_size, "buffers must be of same length") - int cmp = sodium_compare(a_data, b_data, a_size); - - napi_value result; - napi_create_int32(env, cmp, &result); - - return result; -} - -napi_value sn_sodium_is_zero(napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(1, 2, sodium_is_zero); - - SN_ARGV_TYPEDARRAY(a, 0) - - size_t a_full = a_size; - - if (argc == 2) { - SN_OPT_ARGV_UINT32(a_size, 1) - SN_THROWS(a_size > a_full, "len must be shorter than 'buf.byteLength'") - } - - SN_RETURN_BOOLEAN_FROM_1(sodium_is_zero(a_data, a_size)) -} - -napi_value sn_sodium_pad(napi_env env, napi_callback_info info) { - SN_ARGV(3, sodium_pad); - - SN_ARGV_TYPEDARRAY(buf, 0) - SN_ARGV_UINT32(unpadded_buflen, 1) - SN_ARGV_UINT32(blocksize, 2) - - SN_THROWS(unpadded_buflen > buf_size, "unpadded length cannot exceed buffer length") - SN_THROWS(blocksize > buf_size, "block size cannot exceed buffer length") - SN_THROWS(blocksize < 1, "block sizemust be at least 1 byte") - SN_THROWS(buf_size < unpadded_buflen + (blocksize - (unpadded_buflen % blocksize)), "buf not long enough") - - napi_value result; - size_t padded_buflen; - sodium_pad(&padded_buflen, buf_data, unpadded_buflen, blocksize, buf_size); - napi_create_uint32(env, padded_buflen, &result); - return result; -} - -napi_value sn_sodium_unpad(napi_env env, napi_callback_info info) { - SN_ARGV(3, sodium_unpad); - - SN_ARGV_TYPEDARRAY(buf, 0) - SN_ARGV_UINT32(padded_buflen, 1) - SN_ARGV_UINT32(blocksize, 2) - - SN_THROWS(padded_buflen > buf_size, "unpadded length cannot exceed buffer length") - SN_THROWS(blocksize > buf_size, "block size cannot exceed buffer length") - SN_THROWS(blocksize < 1, "block size must be at least 1 byte") - - napi_value result; - size_t unpadded_buflen; - sodium_unpad(&unpadded_buflen, buf_data, padded_buflen, blocksize); - napi_create_uint32(env, unpadded_buflen, &result); - return result; -} - -napi_value sn_crypto_sign_keypair(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_sign_keypair) - - SN_ARGV_TYPEDARRAY(pk, 0) - SN_ARGV_TYPEDARRAY(sk, 1) - - SN_ASSERT_LENGTH(pk_size, crypto_sign_PUBLICKEYBYTES, "pk") - SN_ASSERT_LENGTH(sk_size, crypto_sign_SECRETKEYBYTES, "sk") - - SN_RETURN(crypto_sign_keypair(pk_data, sk_data), "keypair generation failed") -} - -napi_value sn_crypto_sign_seed_keypair(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_sign_seed_keypair) - - SN_ARGV_TYPEDARRAY(pk, 0) - SN_ARGV_TYPEDARRAY(sk, 1) - SN_ARGV_TYPEDARRAY(seed, 2) - - SN_ASSERT_LENGTH(pk_size, crypto_sign_PUBLICKEYBYTES, "pk") - SN_ASSERT_LENGTH(sk_size, crypto_sign_SECRETKEYBYTES, "sk") - SN_ASSERT_LENGTH(seed_size, crypto_sign_SEEDBYTES, "seed") - - SN_RETURN(crypto_sign_seed_keypair(pk_data, sk_data, seed_data), "keypair generation failed") -} - -napi_value sn_crypto_sign(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_sign) - - SN_ARGV_TYPEDARRAY(sm, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(sk, 2) - - SN_THROWS(sm_size != crypto_sign_BYTES + m_size, "sm must be 'm.byteLength + crypto_sign_BYTES' bytes") - SN_ASSERT_LENGTH(sk_size, crypto_sign_SECRETKEYBYTES, "sk") - - SN_RETURN(crypto_sign(sm_data, NULL, m_data, m_size, sk_data), "signature failed") -} - -napi_value sn_crypto_sign_open(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_sign_open) - - SN_ARGV_TYPEDARRAY(m, 0) - SN_ARGV_TYPEDARRAY(sm, 1) - SN_ARGV_TYPEDARRAY(pk, 2) - - SN_THROWS(m_size != sm_size - crypto_sign_BYTES, "m must be 'sm.byteLength - crypto_sign_BYTES' bytes") - SN_ASSERT_MIN_LENGTH(sm_size, crypto_sign_BYTES, "sm") - SN_ASSERT_LENGTH(pk_size, crypto_sign_PUBLICKEYBYTES, "pk") - - SN_RETURN_BOOLEAN(crypto_sign_open(m_data, NULL, sm_data, sm_size, pk_data)) -} - -napi_value sn_crypto_sign_detached(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_sign_detached) - - SN_ARGV_TYPEDARRAY(sig, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(sk, 2) - - SN_ASSERT_LENGTH(sig_size, crypto_sign_BYTES, "sm") - SN_ASSERT_LENGTH(sk_size, crypto_sign_SECRETKEYBYTES, "sk") - - SN_RETURN(crypto_sign_detached(sig_data, NULL, m_data, m_size, sk_data), "signature failed") -} - -napi_value sn_crypto_sign_verify_detached(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_sign_verify_detached) - - SN_ARGV_TYPEDARRAY(sig, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(pk, 2) - - SN_ASSERT_MIN_LENGTH(sig_size, crypto_sign_BYTES, "sig") - SN_ASSERT_LENGTH(pk_size, crypto_sign_PUBLICKEYBYTES, "pk") - - SN_RETURN_BOOLEAN(crypto_sign_verify_detached(sig_data, m_data, m_size, pk_data)) -} - -napi_value sn_crypto_sign_ed25519_sk_to_pk(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_sign_ed25519_sk_to_pk) - - SN_ARGV_TYPEDARRAY(pk, 0) - SN_ARGV_TYPEDARRAY(sk, 1) - - SN_ASSERT_LENGTH(pk_size, crypto_sign_PUBLICKEYBYTES, "pk") - SN_ASSERT_LENGTH(sk_size, crypto_sign_SECRETKEYBYTES, "sk") - - SN_RETURN(crypto_sign_ed25519_sk_to_pk(pk_data, sk_data), "public key generation failed") -} - -napi_value sn_crypto_sign_ed25519_pk_to_curve25519(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_sign_ed25519_sk_to_pk) - - SN_ARGV_TYPEDARRAY(x25519_pk, 0) - SN_ARGV_TYPEDARRAY(ed25519_pk, 1) - - SN_ASSERT_LENGTH(x25519_pk_size, crypto_box_PUBLICKEYBYTES, "x25519_pk") - SN_ASSERT_LENGTH(ed25519_pk_size, crypto_sign_PUBLICKEYBYTES, "ed25519_pk") - - SN_RETURN(crypto_sign_ed25519_pk_to_curve25519(x25519_pk_data, ed25519_pk_data), "public key conversion failed") -} - -napi_value sn_crypto_sign_ed25519_sk_to_curve25519(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_sign_ed25519_sk_to_pk) - - SN_ARGV_TYPEDARRAY(x25519_sk, 0) - SN_ARGV_TYPEDARRAY(ed25519_sk, 1) - - SN_ASSERT_LENGTH(x25519_sk_size, crypto_box_SECRETKEYBYTES, "x25519_sk") - SN_THROWS(ed25519_sk_size != crypto_sign_SECRETKEYBYTES && ed25519_sk_size != crypto_box_SECRETKEYBYTES, "ed25519_sk should either be 'crypto_sign_SECRETKEYBYTES' bytes or 'crypto_sign_SECRETKEYBYTES - crypto_sign_PUBLICKEYBYTES' bytes") - - SN_RETURN(crypto_sign_ed25519_sk_to_curve25519(x25519_sk_data, ed25519_sk_data), "secret key conversion failed") -} - -napi_value sn_crypto_generichash(napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(2, 3, crypto_generichash) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(in, 1) - - SN_ASSERT_MIN_LENGTH(out_size, crypto_generichash_BYTES_MIN, "out") - SN_ASSERT_MAX_LENGTH(out_size, crypto_generichash_BYTES_MAX, "out") - - void *key_data = NULL; - size_t key_size = 0; - - if (argc == 3) { - SN_OPT_ARGV_TYPEDARRAY(key, 2) - SN_THROWS(key_size < crypto_generichash_KEYBYTES_MIN, "key") - SN_ASSERT_MIN_LENGTH(key_size, crypto_generichash_KEYBYTES_MIN, "key") - SN_ASSERT_MAX_LENGTH(key_size, crypto_generichash_KEYBYTES_MAX, "key") - } - - SN_RETURN(crypto_generichash(out_data, out_size, in_data, in_size, key_data, key_size), "hash failed") -} - -napi_value sn_crypto_generichash_batch(napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(2, 3, crypto_generichash) - - SN_ARGV_TYPEDARRAY(out, 0) - - uint32_t batch_length; - napi_get_array_length(env, argv[1], &batch_length); - - SN_ASSERT_MIN_LENGTH(out_size, crypto_generichash_BYTES_MIN, "out") - SN_ASSERT_MAX_LENGTH(out_size, crypto_generichash_BYTES_MAX, "out") - - void *key_data = NULL; - size_t key_size = 0; - - if (argc == 3) { - SN_OPT_ARGV_TYPEDARRAY(key, 2) - SN_ASSERT_MIN_LENGTH(key_size, crypto_generichash_KEYBYTES_MIN, "key") - SN_ASSERT_MAX_LENGTH(key_size, crypto_generichash_KEYBYTES_MAX, "key") - } - - crypto_generichash_state state; - crypto_generichash_init(&state, key_data, key_size, out_size); - for (uint32_t i = 0; i < batch_length; i++) { - napi_value element; - napi_get_element(env, argv[1], i, &element); - SN_TYPEDARRAY_ASSERT(buf, element, "batch element should be passed as a TypedArray") - SN_TYPEDARRAY(buf, element) - crypto_generichash_update(&state, buf_data, buf_size); - } - - SN_RETURN(crypto_generichash_final(&state, out_data, out_size), "batch failed") -} - -napi_value sn_crypto_generichash_keygen(napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_generichash_keygen) - - SN_ARGV_TYPEDARRAY(key, 0) - - SN_ASSERT_LENGTH(key_size, crypto_generichash_KEYBYTES, "key") - - crypto_generichash_keygen(key_data); - - return NULL; -} - -napi_value sn_crypto_generichash_init(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_generichash_init) - - SN_ARGV_BUFFER_CAST(crypto_generichash_state *, state, 0) - SN_ARGV_OPTS_TYPEDARRAY(key, 1) - SN_ARGV_UINT32(outlen, 2) - - SN_THROWS(state_size != sizeof(crypto_generichash_state), "state must be 'crypto_generichash_STATEBYTES' bytes") - - if (key_data != NULL) { - SN_ASSERT_MIN_LENGTH(key_size, crypto_generichash_KEYBYTES_MIN, "key") - SN_ASSERT_MAX_LENGTH(key_size, crypto_generichash_KEYBYTES_MAX, "key") - } - - SN_RETURN(crypto_generichash_init(state, key_data, key_size, outlen), "hash failed to initialise") -} - -napi_value sn_crypto_generichash_update(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_generichash_update) - - SN_ARGV_BUFFER_CAST(crypto_generichash_state *, state, 0) - SN_ARGV_TYPEDARRAY(in, 1) - - SN_THROWS(state_size != sizeof(crypto_generichash_state), "state must be 'crypto_generichash_STATEBYTES' bytes") - - SN_RETURN(crypto_generichash_update(state, in_data, in_size), "update failed") -} - -napi_value sn_crypto_generichash_final(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_generichash_final) - - SN_ARGV_BUFFER_CAST(crypto_generichash_state *, state, 0) - SN_ARGV_TYPEDARRAY(out, 1) - - SN_THROWS(state_size != sizeof(crypto_generichash_state), "state must be 'crypto_generichash_STATEBYTES' bytes") - - SN_RETURN(crypto_generichash_final(state, out_data, out_size), "digest failed") -} - -napi_value sn_crypto_box_keypair(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_box_keypair) - - SN_ARGV_TYPEDARRAY(pk, 0) - SN_ARGV_TYPEDARRAY(sk, 1) - - SN_ASSERT_LENGTH(pk_size, crypto_box_PUBLICKEYBYTES, "pk") - SN_ASSERT_LENGTH(sk_size, crypto_box_SECRETKEYBYTES, "sk") - - SN_RETURN(crypto_box_keypair(pk_data, sk_data), "keypair generation failed") -} - -napi_value sn_crypto_box_seed_keypair(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_box_seed_keypair) - - SN_ARGV_TYPEDARRAY(pk, 0) - SN_ARGV_TYPEDARRAY(sk, 1) - SN_ARGV_TYPEDARRAY(seed, 2) - - SN_ASSERT_LENGTH(pk_size, crypto_box_PUBLICKEYBYTES, "pk") - SN_ASSERT_LENGTH(sk_size, crypto_box_SECRETKEYBYTES, "sk") - SN_ASSERT_LENGTH(seed_size, crypto_box_SEEDBYTES, "seed") - - SN_RETURN(crypto_box_seed_keypair(pk_data, sk_data, seed_data), "keypair generation failed") -} - -napi_value sn_crypto_box_easy(napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_box_easy) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_TYPEDARRAY(pk, 3) - SN_ARGV_TYPEDARRAY(sk, 4) - - SN_THROWS(c_size != m_size + crypto_box_MACBYTES, "c must be 'm.byteLength + crypto_box_MACBYTES' bytes") - SN_ASSERT_LENGTH(n_size, crypto_box_NONCEBYTES, "n") - SN_ASSERT_LENGTH(sk_size, crypto_box_SECRETKEYBYTES, "sk") - SN_ASSERT_LENGTH(pk_size, crypto_box_PUBLICKEYBYTES, "pk") - - SN_RETURN(crypto_box_easy(c_data, m_data, m_size, n_data, pk_data, sk_data), "crypto box failed") -} - -napi_value sn_crypto_box_open_easy(napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_box_open_easy) - - SN_ARGV_TYPEDARRAY(m, 0) - SN_ARGV_TYPEDARRAY(c, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_TYPEDARRAY(pk, 3) - SN_ARGV_TYPEDARRAY(sk, 4) - - SN_THROWS(m_size != c_size - crypto_box_MACBYTES, "m must be 'c.byteLength - crypto_box_MACBYTES' bytes") - SN_ASSERT_MIN_LENGTH(c_size, crypto_box_MACBYTES, "c") - SN_ASSERT_LENGTH(n_size, crypto_box_NONCEBYTES, "n") - SN_ASSERT_LENGTH(sk_size, crypto_box_SECRETKEYBYTES, "sk") - SN_ASSERT_LENGTH(pk_size, crypto_box_PUBLICKEYBYTES, "pk") - - SN_RETURN_BOOLEAN(crypto_box_open_easy(m_data, c_data, c_size, n_data, pk_data, sk_data)) -} - -napi_value sn_crypto_box_detached(napi_env env, napi_callback_info info) { - SN_ARGV(6, crypto_box_detached) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(mac, 1) - SN_ARGV_TYPEDARRAY(m, 2) - SN_ARGV_TYPEDARRAY(n, 3) - SN_ARGV_TYPEDARRAY(pk, 4) - SN_ARGV_TYPEDARRAY(sk, 5) - - SN_THROWS(c_size != m_size, "c must be 'm.byteLength' bytes") - SN_ASSERT_LENGTH(mac_size, crypto_box_MACBYTES, "mac") - SN_ASSERT_LENGTH(n_size, crypto_box_NONCEBYTES, "n") - SN_ASSERT_LENGTH(sk_size, crypto_box_SECRETKEYBYTES, "sk") - SN_ASSERT_LENGTH(pk_size, crypto_box_PUBLICKEYBYTES, "pk") - - SN_RETURN(crypto_box_detached(c_data, mac_data, m_data, m_size, n_data, pk_data, sk_data), "signature failed") -} - -napi_value sn_crypto_box_open_detached(napi_env env, napi_callback_info info) { - SN_ARGV(6, crypto_box_open_detached) - - SN_ARGV_TYPEDARRAY(m, 0) - SN_ARGV_TYPEDARRAY(c, 1) - SN_ARGV_TYPEDARRAY(mac, 2) - SN_ARGV_TYPEDARRAY(n, 3) - SN_ARGV_TYPEDARRAY(pk, 4) - SN_ARGV_TYPEDARRAY(sk, 5) - - SN_THROWS(m_size != c_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(mac_size, crypto_box_MACBYTES, "mac") - SN_ASSERT_LENGTH(n_size, crypto_box_NONCEBYTES, "n") - SN_ASSERT_LENGTH(sk_size, crypto_box_SECRETKEYBYTES, "sk") - SN_ASSERT_LENGTH(pk_size, crypto_box_PUBLICKEYBYTES, "pk") - - SN_RETURN_BOOLEAN(crypto_box_open_detached(m_data, c_data, mac_data, c_size, n_data, pk_data, sk_data)) -} - -napi_value sn_crypto_box_seal(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_box_seal) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(pk, 2) - - SN_THROWS(c_size != m_size + crypto_box_SEALBYTES, "c must be 'm.byteLength + crypto_box_SEALBYTES' bytes") - SN_ASSERT_LENGTH(pk_size, crypto_box_PUBLICKEYBYTES, "pk") - - SN_RETURN(crypto_box_seal(c_data, m_data, m_size, pk_data), "failed to create seal") -} - -napi_value sn_crypto_box_seal_open(napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_box_seal_open) - - SN_ARGV_TYPEDARRAY(m, 0) - SN_ARGV_TYPEDARRAY(c, 1) - SN_ARGV_TYPEDARRAY(pk, 2) - SN_ARGV_TYPEDARRAY(sk, 3) - - SN_THROWS(m_size != c_size - crypto_box_SEALBYTES, "m must be 'c.byteLength - crypto_box_SEALBYTES' bytes") - SN_ASSERT_MIN_LENGTH(c_size, crypto_box_SEALBYTES, "c") - SN_ASSERT_LENGTH(sk_size, crypto_box_SECRETKEYBYTES, "sk") - SN_ASSERT_LENGTH(pk_size, crypto_box_PUBLICKEYBYTES, "pk") - - SN_RETURN_BOOLEAN(crypto_box_seal_open(m_data, c_data, c_size, pk_data, sk_data)) -} - -napi_value sn_crypto_secretbox_easy(napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_secretbox_easy) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_TYPEDARRAY(k, 3) - - SN_THROWS(c_size != m_size + crypto_secretbox_MACBYTES, "c must be 'm.byteLength + crypto_secretbox_MACBYTES' bytes") - SN_ASSERT_LENGTH(n_size, crypto_secretbox_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_secretbox_KEYBYTES, "k") - - SN_RETURN(crypto_secretbox_easy(c_data, m_data, m_size, n_data, k_data), "crypto secretbox failed") -} - -napi_value sn_crypto_secretbox_open_easy(napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_secretbox_open_easy) - - SN_ARGV_TYPEDARRAY(m, 0) - SN_ARGV_TYPEDARRAY(c, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_TYPEDARRAY(k, 3) - - SN_THROWS(m_size != c_size - crypto_secretbox_MACBYTES, "m must be 'c - crypto_secretbox_MACBYTES' bytes") - SN_ASSERT_MIN_LENGTH(c_size, crypto_secretbox_MACBYTES, "c") - SN_ASSERT_LENGTH(n_size, crypto_secretbox_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_secretbox_KEYBYTES, "k") - - SN_RETURN_BOOLEAN(crypto_secretbox_open_easy(m_data, c_data, c_size, n_data, k_data)) -} - -napi_value sn_crypto_secretbox_detached(napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_secretbox_detached) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(mac, 1) - SN_ARGV_TYPEDARRAY(m, 2) - SN_ARGV_TYPEDARRAY(n, 3) - SN_ARGV_TYPEDARRAY(k, 4) - - SN_THROWS(c_size != m_size, "c must 'm.byteLength' bytes") - SN_ASSERT_LENGTH(mac_size, crypto_secretbox_MACBYTES, "mac") - SN_ASSERT_LENGTH(n_size, crypto_secretbox_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_secretbox_KEYBYTES, "k") - - SN_RETURN(crypto_secretbox_detached(c_data, mac_data, m_data, m_size, n_data, k_data), "failed to open box") -} - -napi_value sn_crypto_secretbox_open_detached(napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_secretbox_open_detached) - - SN_ARGV_TYPEDARRAY(m, 0) - SN_ARGV_TYPEDARRAY(c, 1) - SN_ARGV_TYPEDARRAY(mac, 2) - SN_ARGV_TYPEDARRAY(n, 3) - SN_ARGV_TYPEDARRAY(k, 4) - - SN_THROWS(m_size != c_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(mac_size, crypto_secretbox_MACBYTES, "mac") - SN_ASSERT_LENGTH(n_size, crypto_secretbox_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_secretbox_KEYBYTES, "k") - - SN_RETURN_BOOLEAN(crypto_secretbox_open_detached(m_data, c_data, mac_data, c_size, n_data, k_data)) -} - -napi_value sn_crypto_stream(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_ASSERT_LENGTH(n_size, crypto_stream_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_KEYBYTES, "k") - - SN_RETURN(crypto_stream(c_data, c_size, n_data, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_xor(napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_stream_xor) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_TYPEDARRAY(k, 3) - - SN_THROWS(c_size != m_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_KEYBYTES, "k") - - SN_RETURN(crypto_stream_xor(c_data, m_data, m_size, n_data, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_chacha20(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_chacha20) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_ASSERT_LENGTH(n_size, crypto_stream_chacha20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_chacha20_KEYBYTES, "k") - - SN_RETURN(crypto_stream_chacha20(c_data, c_size, n_data, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_chacha20_xor (napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_stream_chacha20_xor) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_TYPEDARRAY(k, 3) - - SN_THROWS(c_size != m_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_chacha20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_chacha20_KEYBYTES, "k") - - SN_RETURN(crypto_stream_chacha20_xor(c_data, m_data, m_size, n_data, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_chacha20_xor_ic(napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_stream_chacha20_xor_ic) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_UINT32(ic, 3) - SN_ARGV_TYPEDARRAY(k, 4) - - SN_THROWS(c_size != m_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_chacha20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_chacha20_KEYBYTES, "k") - - SN_RETURN(crypto_stream_chacha20_xor_ic(c_data, m_data, m_size, n_data, ic, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_chacha20_ietf(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_chacha20_ietf) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_ASSERT_LENGTH(n_size, crypto_stream_chacha20_ietf_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_chacha20_ietf_KEYBYTES, "k") - - SN_RETURN(crypto_stream_chacha20_ietf(c_data, c_size, n_data, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_chacha20_ietf_xor(napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_stream_chacha20_ietf_xor) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_TYPEDARRAY(k, 3) - - SN_THROWS(c_size != m_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_chacha20_ietf_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_chacha20_ietf_KEYBYTES, "k") - - SN_RETURN(crypto_stream_chacha20_ietf_xor(c_data, m_data, m_size, n_data, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_chacha20_ietf_xor_ic(napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_stream_chacha20_ietf_xor_ic) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_UINT32(ic, 3) - SN_ARGV_TYPEDARRAY(k, 4) - - SN_THROWS(c_size != m_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_chacha20_ietf_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_chacha20_ietf_KEYBYTES, "k") - - SN_RETURN(crypto_stream_chacha20_ietf_xor_ic(c_data, m_data, m_size, n_data, ic, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_xchacha20(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_xchacha20) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_ASSERT_LENGTH(n_size, crypto_stream_xchacha20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_xchacha20_KEYBYTES, "k") - - SN_RETURN(crypto_stream_xchacha20(c_data, c_size, n_data, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_xchacha20_xor (napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_stream_xchacha20_xor) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_TYPEDARRAY(k, 3) - - SN_THROWS(c_size != m_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_xchacha20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_xchacha20_KEYBYTES, "k") - - SN_RETURN(crypto_stream_xchacha20_xor(c_data, m_data, m_size, n_data, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_xchacha20_xor_ic(napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_stream_xchacha20_xor_ic) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_UINT32(ic, 3) - SN_ARGV_TYPEDARRAY(k, 4) - - SN_THROWS(c_size != m_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_xchacha20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_xchacha20_KEYBYTES, "k") - - SN_RETURN(crypto_stream_xchacha20_xor_ic(c_data, m_data, m_size, n_data, ic, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_salsa20(napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_salsa20) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_ASSERT_LENGTH(n_size, crypto_stream_salsa20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_salsa20_KEYBYTES, "k") - - SN_RETURN(crypto_stream_salsa20(c_data, c_size, n_data, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_salsa20_xor (napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_stream_salsa20_xor) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_TYPEDARRAY(k, 3) - - SN_THROWS(c_size != m_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_salsa20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_salsa20_KEYBYTES, "k") - - SN_RETURN(crypto_stream_salsa20_xor(c_data, m_data, m_size, n_data, k_data), "stream encryption failed") -} - -napi_value sn_crypto_stream_salsa20_xor_ic(napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_stream_salsa20_xor_ic) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(n, 2) - SN_ARGV_UINT32(ic, 3) - SN_ARGV_TYPEDARRAY(k, 4) - - SN_THROWS(c_size != m_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_salsa20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_salsa20_KEYBYTES, "k") - - SN_RETURN(crypto_stream_salsa20_xor_ic(c_data, m_data, m_size, n_data, ic, k_data), "stream encryption failed") -} - -napi_value sn_crypto_auth (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_auth) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(in, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_ASSERT_LENGTH(out_size, crypto_auth_BYTES, "out") - SN_ASSERT_LENGTH(k_size, crypto_auth_KEYBYTES, "k") - - SN_RETURN(crypto_auth(out_data, in_data, in_size, k_data), "failed to generate authentication tag") -} - -napi_value sn_crypto_auth_verify (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_auth_verify) - - SN_ARGV_TYPEDARRAY(h, 0) - SN_ARGV_TYPEDARRAY(in, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_ASSERT_LENGTH(h_size, crypto_auth_BYTES, "h") - SN_ASSERT_LENGTH(k_size, crypto_auth_KEYBYTES, "k") - - SN_RETURN_BOOLEAN(crypto_auth_verify(h_data, in_data, in_size, k_data)) -} - -napi_value sn_crypto_onetimeauth (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_onetimeauth) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(in, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_ASSERT_LENGTH(out_size, crypto_onetimeauth_BYTES, "out") - SN_ASSERT_LENGTH(k_size, crypto_onetimeauth_KEYBYTES, "k") - - SN_RETURN(crypto_onetimeauth(out_data, in_data, in_size, k_data), "failed to generate onetime authentication tag") -} - -napi_value sn_crypto_onetimeauth_init (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_onetimeauth_init) - - SN_ARGV_BUFFER_CAST(crypto_onetimeauth_state *, state, 0) - SN_ARGV_TYPEDARRAY(k, 1) - - SN_THROWS(state_size != sizeof(crypto_onetimeauth_state), "state must be 'crypto_onetimeauth_STATEBYTES' bytes") - SN_ASSERT_LENGTH(k_size, crypto_onetimeauth_KEYBYTES, "k") - - SN_RETURN(crypto_onetimeauth_init(state, k_data), "failed to initialise onetime authentication") -} - -napi_value sn_crypto_onetimeauth_update(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_onetimeauth_update) - - SN_ARGV_BUFFER_CAST(crypto_onetimeauth_state *, state, 0) - SN_ARGV_TYPEDARRAY(in, 1) - - SN_THROWS(state_size != sizeof(crypto_onetimeauth_state), "state must be 'crypto_onetimeauth_STATEBYTES' bytes") - - SN_RETURN(crypto_onetimeauth_update(state, in_data, in_size), "update failed") -} - -napi_value sn_crypto_onetimeauth_final(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_onetimeauth_final) - - SN_ARGV_BUFFER_CAST(crypto_onetimeauth_state *, state, 0) - SN_ARGV_TYPEDARRAY(out, 1) - - SN_THROWS(state_size != sizeof(crypto_onetimeauth_state), "state must be 'crypto_onetimeauth_STATEBYTES' bytes") - SN_ASSERT_LENGTH(out_size, crypto_onetimeauth_BYTES, "out") - - SN_RETURN(crypto_onetimeauth_final(state, out_data), "failed to generate authentication tag") -} - -napi_value sn_crypto_onetimeauth_verify (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_onetimeauth_verify) - - SN_ARGV_TYPEDARRAY(h, 0) - SN_ARGV_TYPEDARRAY(in, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_ASSERT_LENGTH(h_size, crypto_onetimeauth_BYTES, "h") - SN_ASSERT_LENGTH(k_size, crypto_onetimeauth_KEYBYTES, "k") - - SN_RETURN_BOOLEAN(crypto_onetimeauth_verify(h_data, in_data, in_size, k_data)) -} - -// CHECK: memlimit can be >32bit -napi_value sn_crypto_pwhash (napi_env env, napi_callback_info info) { - SN_ARGV(6, crypto_pwhash) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(passwd, 1) - SN_ARGV_TYPEDARRAY(salt, 2) - SN_ARGV_UINT64(opslimit, 3) - SN_ARGV_UINT64(memlimit, 4) - SN_ARGV_UINT8(alg, 5) - - SN_ASSERT_MIN_LENGTH(out_size, crypto_pwhash_BYTES_MIN, "out") - SN_ASSERT_MAX_LENGTH(out_size, crypto_pwhash_BYTES_MAX, "out") - SN_ASSERT_LENGTH(salt_size, crypto_pwhash_SALTBYTES, "salt") - SN_ASSERT_MIN_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MIN, "opslimit") - SN_ASSERT_MAX_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MAX, "opslimit") - SN_ASSERT_MIN_LENGTH(memlimit, crypto_pwhash_MEMLIMIT_MIN, "memlimit") - SN_ASSERT_MAX_LENGTH(memlimit, (int64_t) crypto_pwhash_MEMLIMIT_MAX, "memlimit") - SN_THROWS(alg < 1 || alg > 2, "alg must be either Argon2i 1.3 or Argon2id 1.3") - - SN_RETURN(crypto_pwhash(out_data, out_size, passwd_data, passwd_size, salt_data, opslimit, memlimit, alg), "password hashing failed, check memory requirements.") -} - -napi_value sn_crypto_pwhash_str (napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_pwhash_str) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(passwd, 1) - SN_ARGV_UINT64(opslimit, 2) - SN_ARGV_UINT64(memlimit, 3) - - SN_ASSERT_LENGTH(out_size, crypto_pwhash_STRBYTES, "out") - SN_ASSERT_MIN_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MIN, "opslimit") - SN_ASSERT_MAX_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MAX, "opslimit") - SN_ASSERT_MIN_LENGTH(memlimit, crypto_pwhash_MEMLIMIT_MIN, "memlimit") - SN_ASSERT_MAX_LENGTH(memlimit, (int64_t) crypto_pwhash_MEMLIMIT_MAX, "memlimit") - - SN_RETURN(crypto_pwhash_str(out_data, passwd_data, passwd_size, opslimit, memlimit), "password hashing failed, check memory requirements.") -} - -napi_value sn_crypto_pwhash_str_verify (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_pwhash_str_verify) - - SN_ARGV_TYPEDARRAY(str, 0) - SN_ARGV_TYPEDARRAY(passwd, 1) - - SN_ASSERT_LENGTH(str_size, crypto_pwhash_STRBYTES, "str") - - SN_RETURN_BOOLEAN(crypto_pwhash_str_verify(str_data, passwd_data, passwd_size)) -} - -// CHECK: returns 1, 0, -1 -napi_value sn_crypto_pwhash_str_needs_rehash (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_pwhash_str_needs_rehash) - - SN_ARGV_TYPEDARRAY(str, 0) - SN_ARGV_UINT64(opslimit, 1) - SN_ARGV_UINT64(memlimit, 2) - - SN_ASSERT_LENGTH(str_size, crypto_pwhash_STRBYTES, "str") - SN_ASSERT_MIN_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MIN, "opslimit") - SN_ASSERT_MAX_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MAX, "opslimit") - SN_ASSERT_MIN_LENGTH(memlimit, crypto_pwhash_MEMLIMIT_MIN, "memlimit") - SN_ASSERT_MAX_LENGTH(memlimit, (int64_t) crypto_pwhash_MEMLIMIT_MAX, "memlimit") - - SN_RETURN_BOOLEAN_FROM_1(crypto_pwhash_str_needs_rehash(str_data, opslimit, memlimit)) -} - -// CHECK: memlimit can be >32bit -napi_value sn_crypto_pwhash_scryptsalsa208sha256 (napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_pwhash_scryptsalsa208sha256) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(passwd, 1) - SN_ARGV_TYPEDARRAY(salt, 2) - SN_ARGV_UINT64(opslimit, 3) - SN_ARGV_UINT64(memlimit, 4) - - SN_ASSERT_MIN_LENGTH(out_size, crypto_pwhash_scryptsalsa208sha256_BYTES_MIN, "out") - SN_ASSERT_MAX_LENGTH(out_size, crypto_pwhash_scryptsalsa208sha256_BYTES_MAX, "out") - SN_ASSERT_LENGTH(salt_size, crypto_pwhash_scryptsalsa208sha256_SALTBYTES, "salt") - SN_ASSERT_MIN_LENGTH(opslimit, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN, "opslimit") - SN_ASSERT_MAX_LENGTH(opslimit, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX, "opslimit") - SN_ASSERT_MIN_LENGTH(memlimit, crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN, "memlimit") - SN_ASSERT_MAX_LENGTH(memlimit, (int64_t) crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX, "memlimit") - - SN_RETURN(crypto_pwhash_scryptsalsa208sha256(out_data, out_size, passwd_data, passwd_size, salt_data, opslimit, memlimit), "password hashing failed, check memory requirements.") -} - -napi_value sn_crypto_pwhash_scryptsalsa208sha256_str (napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_pwhash_scryptsalsa208sha256_str) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(passwd, 1) - SN_ARGV_UINT64(opslimit, 2) - SN_ARGV_UINT64(memlimit, 3) - - SN_ASSERT_LENGTH(out_size, crypto_pwhash_scryptsalsa208sha256_STRBYTES, "out") - SN_ASSERT_MIN_LENGTH(opslimit, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN, "opslimit") - SN_ASSERT_MAX_LENGTH(opslimit, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX, "opslimit") - SN_ASSERT_MIN_LENGTH(memlimit, crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN, "memlimit") - SN_ASSERT_MAX_LENGTH(memlimit, (int64_t) crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX, "memlimit") - - SN_RETURN(crypto_pwhash_scryptsalsa208sha256_str(out_data, passwd_data, passwd_size, opslimit, memlimit), "password hashing failed, check memory requirements.") -} - -napi_value sn_crypto_pwhash_scryptsalsa208sha256_str_verify (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_pwhash_scryptsalsa208sha256_str_verify) - - SN_ARGV_TYPEDARRAY(str, 0) - SN_ARGV_TYPEDARRAY(passwd, 1) - - SN_ASSERT_LENGTH(str_size, crypto_pwhash_scryptsalsa208sha256_STRBYTES, "str") - - SN_RETURN_BOOLEAN(crypto_pwhash_scryptsalsa208sha256_str_verify(str_data, passwd_data, passwd_size)) -} - -napi_value sn_crypto_pwhash_scryptsalsa208sha256_str_needs_rehash (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_pwhash_scryptsalsa208sha256_str_needs_rehash) - - SN_ARGV_TYPEDARRAY(str, 0) - SN_ARGV_UINT64(opslimit, 1) - SN_ARGV_UINT64(memlimit, 2) - - SN_ASSERT_LENGTH(str_size, crypto_pwhash_scryptsalsa208sha256_STRBYTES, "str") - SN_ASSERT_MIN_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MIN, "opslimit") - SN_ASSERT_MAX_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MAX, "opslimit") - SN_ASSERT_MIN_LENGTH(memlimit, crypto_pwhash_MEMLIMIT_MIN, "memlimit") - SN_ASSERT_MAX_LENGTH(memlimit, (int64_t) crypto_pwhash_MEMLIMIT_MAX, "memlimit") - - SN_RETURN_BOOLEAN_FROM_1(crypto_pwhash_scryptsalsa208sha256_str_needs_rehash(str_data, opslimit, memlimit)) -} - -napi_value sn_crypto_kx_keypair (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_kx_keypair) - - SN_ARGV_TYPEDARRAY(pk, 0) - SN_ARGV_TYPEDARRAY(sk, 1) - - SN_ASSERT_LENGTH(pk_size, crypto_kx_PUBLICKEYBYTES, "pk") - SN_ASSERT_LENGTH(sk_size, crypto_kx_SECRETKEYBYTES, "sk") - - SN_RETURN(crypto_kx_keypair(pk_data, sk_data), "failed to generate keypair") -} - -napi_value sn_crypto_kx_seed_keypair (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_kx_seed_keypair) - - SN_ARGV_TYPEDARRAY(pk, 0) - SN_ARGV_TYPEDARRAY(sk, 1) - SN_ARGV_TYPEDARRAY(seed, 2) - - SN_ASSERT_LENGTH(pk_size, crypto_kx_PUBLICKEYBYTES, "pk") - SN_ASSERT_LENGTH(sk_size, crypto_kx_SECRETKEYBYTES, "sk") - SN_ASSERT_LENGTH(seed_size, crypto_kx_SEEDBYTES, "seed") - - SN_RETURN(crypto_kx_seed_keypair(pk_data, sk_data, seed_data), "failed to derive keypair from seed") -} - -napi_value sn_crypto_kx_client_session_keys (napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_kx_client_session_keys) - - SN_ARGV_OPTS_TYPEDARRAY(rx, 0) - SN_ARGV_OPTS_TYPEDARRAY(tx, 1) - - SN_THROWS(rx_data == NULL && tx_data == NULL, "at least one session key must be specified") - - SN_ARGV_TYPEDARRAY(client_pk, 2) - SN_ARGV_TYPEDARRAY(client_sk, 3) - SN_ARGV_TYPEDARRAY(server_pk, 4) - - SN_ASSERT_LENGTH(client_pk_size, crypto_kx_PUBLICKEYBYTES, "client_pk") - SN_ASSERT_LENGTH(client_sk_size, crypto_kx_SECRETKEYBYTES, "client_sk") - SN_ASSERT_LENGTH(server_pk_size, crypto_kx_PUBLICKEYBYTES, "server_pk") - - SN_THROWS(tx_size != crypto_kx_SESSIONKEYBYTES && tx_data != NULL, "transmitting key buffer must be 'crypto_kx_SESSIONKEYBYTES' bytes or null") - SN_THROWS(rx_size != crypto_kx_SESSIONKEYBYTES && rx_data != NULL, "receiving key buffer must be 'crypto_kx_SESSIONKEYBYTES' bytes or null") - - SN_RETURN(crypto_kx_client_session_keys(rx_data, tx_data, client_pk_data, client_sk_data, server_pk_data), "failed to derive session keys") -} - -napi_value sn_crypto_kx_server_session_keys (napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_kx_server_session_keys) - - SN_ARGV_OPTS_TYPEDARRAY(rx, 0) - SN_ARGV_OPTS_TYPEDARRAY(tx, 1) - - SN_THROWS(rx_data == NULL && tx_data == NULL, "at least one session key must be specified") - - SN_ARGV_TYPEDARRAY(server_pk, 2) - SN_ARGV_TYPEDARRAY(server_sk, 3) - SN_ARGV_TYPEDARRAY(client_pk, 4) - - SN_ASSERT_LENGTH(server_pk_size, crypto_kx_PUBLICKEYBYTES, "server_pk") - SN_ASSERT_LENGTH(server_sk_size, crypto_kx_SECRETKEYBYTES, "server_sk") - SN_ASSERT_LENGTH(client_pk_size, crypto_kx_PUBLICKEYBYTES, "client_pk") - - SN_THROWS(tx_size != crypto_kx_SESSIONKEYBYTES && tx_data != NULL, "transmitting key buffer must be 'crypto_kx_SESSIONKEYBYTES' bytes or null") - SN_THROWS(rx_size != crypto_kx_SESSIONKEYBYTES && rx_data != NULL, "receiving key buffer must be 'crypto_kx_SESSIONKEYBYTES' bytes or null") - - SN_RETURN(crypto_kx_server_session_keys(rx_data, tx_data, server_pk_data, server_sk_data, client_pk_data), "failed to derive session keys") -} - -napi_value sn_crypto_scalarmult_base (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_scalarmult_base) - - SN_ARGV_TYPEDARRAY(q, 0) - SN_ARGV_TYPEDARRAY(n, 1) - - SN_ASSERT_LENGTH(q_size, crypto_scalarmult_BYTES, "q") - SN_ASSERT_LENGTH(n_size, crypto_scalarmult_SCALARBYTES, "n") - - SN_RETURN(crypto_scalarmult_base(q_data, n_data), "failed to derive public key") -} - -napi_value sn_crypto_scalarmult (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_scalarmult) - - SN_ARGV_TYPEDARRAY(q, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(p, 2) - - SN_ASSERT_LENGTH(q_size, crypto_scalarmult_BYTES, "q") - SN_ASSERT_LENGTH(n_size, crypto_scalarmult_SCALARBYTES, "n") - SN_ASSERT_LENGTH(p_size, crypto_scalarmult_BYTES, "p") - - SN_RETURN(crypto_scalarmult(q_data, n_data, p_data), "failed to derive shared secret") -} - -napi_value sn_crypto_scalarmult_ed25519_base (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_scalarmult_ed25519_base) - - SN_ARGV_TYPEDARRAY(q, 0) - SN_ARGV_TYPEDARRAY(n, 1) - - SN_ASSERT_LENGTH(q_size, crypto_scalarmult_ed25519_BYTES, "q") - SN_ASSERT_LENGTH(n_size, crypto_scalarmult_ed25519_SCALARBYTES, "n") - - SN_RETURN(crypto_scalarmult_ed25519_base(q_data, n_data), "failed to derive public key") -} - -napi_value sn_crypto_scalarmult_ed25519 (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_scalarmult_ed25519) - - SN_ARGV_TYPEDARRAY(q, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(p, 2) - - SN_ASSERT_LENGTH(q_size, crypto_scalarmult_ed25519_BYTES, "q") - SN_ASSERT_LENGTH(n_size, crypto_scalarmult_ed25519_SCALARBYTES, "n") - SN_ASSERT_LENGTH(p_size, crypto_scalarmult_ed25519_BYTES, "p") - - SN_RETURN(crypto_scalarmult_ed25519(q_data, n_data, p_data), "failed to derive shared secret") -} - -napi_value sn_crypto_core_ed25519_is_valid_point (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_core_ed25519_is_valid_point) - - SN_ARGV_TYPEDARRAY(p, 0) - - SN_ASSERT_LENGTH(p_size, crypto_core_ed25519_BYTES, "p") - - SN_RETURN_BOOLEAN_FROM_1(crypto_core_ed25519_is_valid_point(p_data)) -} - -napi_value sn_crypto_core_ed25519_from_uniform (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_core_ed25519_from_uniform) - - SN_ARGV_TYPEDARRAY(p, 0) - SN_ARGV_TYPEDARRAY(r, 1) - - SN_ASSERT_LENGTH(p_size, crypto_core_ed25519_BYTES, "p") - SN_ASSERT_LENGTH(r_size, crypto_core_ed25519_UNIFORMBYTES, "r") - - SN_RETURN(crypto_core_ed25519_from_uniform(p_data, r_data), "could not generate curve point from input") -} - -napi_value sn_crypto_scalarmult_ed25519_base_noclamp (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_scalarmult_ed25519_base_noclamp) - - SN_ARGV_TYPEDARRAY(q, 0) - SN_ARGV_TYPEDARRAY(n, 1) - - SN_ASSERT_LENGTH(q_size, crypto_scalarmult_ed25519_BYTES, "q") - SN_ASSERT_LENGTH(n_size, crypto_scalarmult_ed25519_SCALARBYTES, "n") - - SN_RETURN(crypto_scalarmult_ed25519_base_noclamp(q_data, n_data), "failed to derive public key") -} - -napi_value sn_crypto_scalarmult_ed25519_noclamp (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_scalarmult_ed25519_noclamp) - - SN_ARGV_TYPEDARRAY(q, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(p, 2) - - SN_ASSERT_LENGTH(q_size, crypto_scalarmult_ed25519_BYTES, "q") - SN_ASSERT_LENGTH(n_size, crypto_scalarmult_ed25519_SCALARBYTES, "n") - SN_ASSERT_LENGTH(p_size, crypto_scalarmult_ed25519_BYTES, "p") - - SN_RETURN(crypto_scalarmult_ed25519_noclamp(q_data, n_data, p_data), "failed to derive shared secret") -} - -napi_value sn_crypto_core_ed25519_add (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_core_ed25519_add) - - SN_ARGV_TYPEDARRAY(r, 0) - SN_ARGV_TYPEDARRAY(p, 1) - SN_ARGV_TYPEDARRAY(q, 2) - - SN_ASSERT_LENGTH(r_size, crypto_core_ed25519_BYTES, "r") - SN_ASSERT_LENGTH(p_size, crypto_core_ed25519_BYTES, "p") - SN_ASSERT_LENGTH(q_size, crypto_core_ed25519_BYTES, "q") - - SN_RETURN(crypto_core_ed25519_add(r_data, p_data, q_data), "could not add curve points") -} - -napi_value sn_crypto_core_ed25519_sub (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_core_ed25519_sub) - - SN_ARGV_TYPEDARRAY(r, 0) - SN_ARGV_TYPEDARRAY(p, 1) - SN_ARGV_TYPEDARRAY(q, 2) - - SN_ASSERT_LENGTH(r_size, crypto_core_ed25519_BYTES, "r") - SN_ASSERT_LENGTH(p_size, crypto_core_ed25519_BYTES, "p") - SN_ASSERT_LENGTH(q_size, crypto_core_ed25519_BYTES, "q") - - SN_RETURN(crypto_core_ed25519_sub(r_data, p_data, q_data), "could not add curve points") -} - -napi_value sn_crypto_core_ed25519_scalar_random (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_core_ed25519_scalar_random) - - SN_ARGV_TYPEDARRAY(r, 0) - - SN_ASSERT_LENGTH(r_size, crypto_core_ed25519_SCALARBYTES, "r") - - crypto_core_ed25519_scalar_random(r_data); - - return NULL; -} - -napi_value sn_crypto_core_ed25519_scalar_reduce (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_core_ed25519_scalar_reduce) - - SN_ARGV_TYPEDARRAY(r, 0) - SN_ARGV_TYPEDARRAY(s, 1) - - SN_ASSERT_LENGTH(r_size, crypto_core_ed25519_SCALARBYTES, "r") - SN_ASSERT_LENGTH(s_size, crypto_core_ed25519_NONREDUCEDSCALARBYTES, "s") - - crypto_core_ed25519_scalar_reduce(r_data, s_data); - - return NULL; -} - -napi_value sn_crypto_core_ed25519_scalar_invert (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_core_ed25519_scalar_invert) - - SN_ARGV_TYPEDARRAY(recip, 0) - SN_ARGV_TYPEDARRAY(s, 1) - - SN_ASSERT_LENGTH(recip_size, crypto_core_ed25519_SCALARBYTES, "recip") - SN_ASSERT_LENGTH(s_size, crypto_core_ed25519_SCALARBYTES, "s") - - crypto_core_ed25519_scalar_invert(recip_data, s_data); - - return NULL; -} - -napi_value sn_crypto_core_ed25519_scalar_negate (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_core_ed25519_scalar_negate) - - SN_ARGV_TYPEDARRAY(neg, 0) - SN_ARGV_TYPEDARRAY(s, 1) - - SN_ASSERT_LENGTH(neg_size, crypto_core_ed25519_SCALARBYTES, "neg") - SN_ASSERT_LENGTH(s_size, crypto_core_ed25519_SCALARBYTES, "s") - - crypto_core_ed25519_scalar_negate(neg_data, s_data); - - return NULL; -} - -napi_value sn_crypto_core_ed25519_scalar_complement (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_core_ed25519_scalar_complement) - - SN_ARGV_TYPEDARRAY(comp, 0) - SN_ARGV_TYPEDARRAY(s, 1) - - SN_ASSERT_LENGTH(comp_size, crypto_core_ed25519_SCALARBYTES, "comp") - SN_ASSERT_LENGTH(s_size, crypto_core_ed25519_SCALARBYTES, "s") - - crypto_core_ed25519_scalar_complement(comp_data, s_data); - - return NULL; -} - -napi_value sn_crypto_core_ed25519_scalar_add (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_core_ed25519_scalar_add) - - SN_ARGV_TYPEDARRAY(z, 0) - SN_ARGV_TYPEDARRAY(x, 1) - SN_ARGV_TYPEDARRAY(y, 2) - - SN_ASSERT_LENGTH(z_size, crypto_core_ed25519_SCALARBYTES, "z") - SN_ASSERT_LENGTH(x_size, crypto_core_ed25519_SCALARBYTES, "x") - SN_ASSERT_LENGTH(y_size, crypto_core_ed25519_SCALARBYTES, "y") - - crypto_core_ed25519_scalar_add(z_data, x_data, y_data); - - return NULL; -} - -napi_value sn_crypto_core_ed25519_scalar_sub (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_core_ed25519_scalar_sub) - - SN_ARGV_TYPEDARRAY(z, 0) - SN_ARGV_TYPEDARRAY(x, 1) - SN_ARGV_TYPEDARRAY(y, 2) - - SN_ASSERT_LENGTH(z_size, crypto_core_ed25519_SCALARBYTES, "z") - SN_ASSERT_LENGTH(x_size, crypto_core_ed25519_SCALARBYTES, "x") - SN_ASSERT_LENGTH(y_size, crypto_core_ed25519_SCALARBYTES, "y") - - crypto_core_ed25519_scalar_sub(z_data, x_data, y_data); - - return NULL; -} - -napi_value sn_crypto_shorthash (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_shorthash) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(in, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_ASSERT_LENGTH(out_size, crypto_shorthash_BYTES, "out") - SN_ASSERT_LENGTH(k_size, crypto_shorthash_KEYBYTES, "k") - - SN_RETURN(crypto_shorthash(out_data, in_data, in_size, k_data), "could not compute hash") -} - -napi_value sn_crypto_kdf_keygen (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_kdf_keygen) - - SN_ARGV_TYPEDARRAY(key, 0) - - SN_ASSERT_LENGTH(key_size, crypto_kdf_KEYBYTES, "key") - - crypto_kdf_keygen(key_data); - - return NULL; -} - -napi_value sn_crypto_kdf_derive_from_key (napi_env env, napi_callback_info info) { - SN_ARGV(4, crypto_kdf_derive_from_key) - - SN_ARGV_TYPEDARRAY(subkey, 0) - SN_ARGV_UINT64(subkey_id, 1) - SN_ARGV_TYPEDARRAY(ctx, 2) - SN_ARGV_TYPEDARRAY(key, 3) - - SN_ASSERT_MIN_LENGTH(subkey_size, crypto_kdf_BYTES_MIN, "subkey") - SN_ASSERT_MAX_LENGTH(subkey_size, crypto_kdf_BYTES_MAX, "subkey") - SN_ASSERT_LENGTH(ctx_size, crypto_kdf_CONTEXTBYTES, "ctx") - SN_ASSERT_LENGTH(key_size, crypto_kdf_KEYBYTES, "key") - - SN_RETURN(crypto_kdf_derive_from_key(subkey_data, subkey_size, subkey_id, ctx_data, key_data), "could not generate key") -} - -napi_value sn_crypto_hash (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_hash_sha256) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(in, 1) - - SN_ASSERT_LENGTH(out_size, crypto_hash_BYTES, "out") - - SN_RETURN(crypto_hash(out_data, in_data, in_size), "could not compute hash") -} - -napi_value sn_crypto_hash_sha256 (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_hash_sha256) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(in, 1) - - SN_ASSERT_LENGTH(out_size, crypto_hash_sha256_BYTES, "out") - - SN_RETURN(crypto_hash_sha256(out_data, in_data, in_size), "could not compute hash") -} - -napi_value sn_crypto_hash_sha256_init (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_hash_sha256_init) - - SN_ARGV_BUFFER_CAST(crypto_hash_sha256_state *, state, 0) - - SN_THROWS(state_size != sizeof(crypto_hash_sha256_state), "state must be 'crypto_hash_sha256_STATEBYTES' bytes") - - SN_RETURN(crypto_hash_sha256_init(state), "failed to initialise sha256") -} - -napi_value sn_crypto_hash_sha256_update(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_hash_sha256_update) - - SN_ARGV_BUFFER_CAST(crypto_hash_sha256_state *, state, 0) - SN_ARGV_TYPEDARRAY(in, 1) - - SN_THROWS(state_size != sizeof(crypto_hash_sha256_state), "state must be 'crypto_hash_sha256_STATEBYTES' bytes") - - SN_RETURN(crypto_hash_sha256_update(state, in_data, in_size), "update failed") -} - -napi_value sn_crypto_hash_sha256_final(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_hash_sha256_final) - - SN_ARGV_BUFFER_CAST(crypto_hash_sha256_state *, state, 0) - SN_ARGV_TYPEDARRAY(out, 1) - - SN_THROWS(state_size != sizeof(crypto_hash_sha256_state), "state must be 'crypto_hash_sha256_STATEBYTES' bytes") - SN_ASSERT_LENGTH(out_size, crypto_hash_sha256_BYTES, "state") - - SN_RETURN(crypto_hash_sha256_final(state, out_data), "failed to finalise") -} - -napi_value sn_crypto_hash_sha512 (napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_hash_sha512) - - SN_ARGV_TYPEDARRAY(out, 0) - SN_ARGV_TYPEDARRAY(in, 1) - - SN_ASSERT_LENGTH(out_size, crypto_hash_sha512_BYTES, "out") - - SN_RETURN(crypto_hash_sha512(out_data, in_data, in_size), "could not compute hash") -} - -napi_value sn_crypto_hash_sha512_init (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_hash_sha512_init) - - SN_ARGV_BUFFER_CAST(crypto_hash_sha512_state *, state, 0) - - SN_THROWS(state_size != sizeof(crypto_hash_sha512_state), "state must be 'crypto_hash_sha256_STATEBYTES' bytes") - - SN_RETURN(crypto_hash_sha512_init(state), "failed to initialise sha512") -} - -napi_value sn_crypto_hash_sha512_update(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_hash_sha512_update) - - SN_ARGV_BUFFER_CAST(crypto_hash_sha512_state *, state, 0) - SN_ARGV_TYPEDARRAY(in, 1) - - SN_THROWS(state_size != sizeof(crypto_hash_sha512_state), "state must be 'crypto_hash_sha256_STATEBYTES' bytes") - - SN_RETURN(crypto_hash_sha512_update(state, in_data, in_size), "update failed") -} - -napi_value sn_crypto_hash_sha512_final(napi_env env, napi_callback_info info) { - SN_ARGV(2, crypto_hash_sha512_final) - - SN_ARGV_BUFFER_CAST(crypto_hash_sha512_state *, state, 0) - SN_ARGV_TYPEDARRAY(out, 1) - - SN_THROWS(state_size != sizeof(crypto_hash_sha512_state), "state must be 'crypto_hash_sha256_STATEBYTES' bytes") - SN_ASSERT_LENGTH(out_size, crypto_hash_sha512_BYTES, "out") - - SN_RETURN(crypto_hash_sha512_final(state, out_data), "failed to finalise hash") -} - -napi_value sn_crypto_aead_xchacha20poly1305_ietf_keygen (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_aead_xchacha20poly1305_ietf_keygen) - - SN_ARGV_TYPEDARRAY(k, 0) - - SN_ASSERT_LENGTH(k_size, crypto_aead_xchacha20poly1305_ietf_KEYBYTES, "k") - - crypto_aead_xchacha20poly1305_ietf_keygen(k_data); - return NULL; -} - -napi_value sn_crypto_aead_xchacha20poly1305_ietf_encrypt (napi_env env, napi_callback_info info) { - SN_ARGV(6, crypto_aead_xchacha20poly1305_ietf_encrypt) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_OPTS_TYPEDARRAY(ad, 2) - SN_ARGV_CHECK_NULL(nsec, 3) - SN_ARGV_TYPEDARRAY(npub, 4) - SN_ARGV_TYPEDARRAY(k, 5) - - SN_THROWS(!nsec_is_null, "nsec must always be set to null") - - SN_THROWS(c_size != m_size + crypto_aead_xchacha20poly1305_ietf_ABYTES, "c must 'm.byteLength + crypto_aead_xchacha20poly1305_ietf_ABYTES' bytes") - SN_THROWS(c_size > 0xffffffff, "c.byteLength must be a 32bit integer") - SN_ASSERT_LENGTH(npub_size, crypto_aead_xchacha20poly1305_ietf_NPUBBYTES, "npub") - SN_ASSERT_LENGTH(k_size, crypto_aead_xchacha20poly1305_ietf_KEYBYTES, "k") - - unsigned long long clen; - SN_CALL(crypto_aead_xchacha20poly1305_ietf_encrypt(c_data, &clen, m_data, m_size, ad_data, ad_size, NULL, npub_data, k_data), "could not encrypt data") - - napi_value result; - SN_STATUS_THROWS(napi_create_uint32(env, (uint32_t) clen, &result), "") - return result; -} - -napi_value sn_crypto_aead_xchacha20poly1305_ietf_decrypt (napi_env env, napi_callback_info info) { - SN_ARGV(6, crypto_aead_xchacha20poly1305_ietf_decrypt) - - SN_ARGV_TYPEDARRAY(m, 0) - SN_ARGV_CHECK_NULL(nsec, 1) - SN_ARGV_TYPEDARRAY(c, 2) - SN_ARGV_OPTS_TYPEDARRAY(ad, 3) - SN_ARGV_TYPEDARRAY(npub, 4) - SN_ARGV_TYPEDARRAY(k, 5) - - SN_THROWS(!nsec_is_null, "nsec must always be set to null") - - SN_THROWS(m_size != c_size - crypto_aead_xchacha20poly1305_ietf_ABYTES, "m must 'c.byteLength - crypto_aead_xchacha20poly1305_ietf_ABYTES' bytes") - SN_ASSERT_LENGTH(npub_size, crypto_aead_xchacha20poly1305_ietf_NPUBBYTES, "npub") - SN_ASSERT_LENGTH(k_size, crypto_aead_xchacha20poly1305_ietf_KEYBYTES, "k") - SN_THROWS(m_size > 0xffffffff, "m.byteLength must be a 32bit integer") - - unsigned long long mlen; - SN_CALL(crypto_aead_xchacha20poly1305_ietf_decrypt(m_data, &mlen, NULL, c_data, c_size, ad_data, ad_size, npub_data, k_data), "could not verify data") - - napi_value result; - SN_STATUS_THROWS(napi_create_uint32(env, (uint32_t) mlen, &result), "") - return result; -} - -napi_value sn_crypto_aead_xchacha20poly1305_ietf_encrypt_detached (napi_env env, napi_callback_info info) { - SN_ARGV(7, crypto_aead_xchacha20poly1305_ietf_encrypt_detached) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(mac, 1) - SN_ARGV_TYPEDARRAY(m, 2) - SN_ARGV_OPTS_TYPEDARRAY(ad, 3) - SN_ARGV_CHECK_NULL(nsec, 4) - SN_ARGV_TYPEDARRAY(npub, 5) - SN_ARGV_TYPEDARRAY(k, 6) - - SN_THROWS(!nsec_is_null, "nsec must always be set to null") - - SN_THROWS(c_size != m_size, "c must be 'm.byteLength' bytes") - SN_ASSERT_LENGTH(mac_size, crypto_aead_xchacha20poly1305_ietf_ABYTES, "mac") - SN_ASSERT_LENGTH(npub_size, crypto_aead_xchacha20poly1305_ietf_NPUBBYTES, "npub") - SN_ASSERT_LENGTH(k_size, crypto_aead_xchacha20poly1305_ietf_KEYBYTES, "k") - - unsigned long long maclen; - SN_CALL(crypto_aead_xchacha20poly1305_ietf_encrypt_detached(c_data, mac_data, &maclen, m_data, m_size, ad_data, ad_size, NULL, npub_data, k_data), "could not encrypt data") - - napi_value result; - SN_STATUS_THROWS(napi_create_uint32(env, (uint32_t) maclen, &result), "") - return result; -} - -napi_value sn_crypto_aead_xchacha20poly1305_ietf_decrypt_detached (napi_env env, napi_callback_info info) { - SN_ARGV(7, crypto_aead_xchacha20poly1305_ietf_decrypt_detached) - - SN_ARGV_TYPEDARRAY(m, 0) - SN_ARGV_CHECK_NULL(nsec, 1) - SN_ARGV_TYPEDARRAY(c, 2) - SN_ARGV_TYPEDARRAY(mac, 3) - SN_ARGV_OPTS_TYPEDARRAY(ad, 4) - SN_ARGV_TYPEDARRAY(npub, 5) - SN_ARGV_TYPEDARRAY(k, 6) - - SN_THROWS(!nsec_is_null, "nsec must always be set to null") - - SN_THROWS(m_size != c_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(mac_size, crypto_aead_xchacha20poly1305_ietf_ABYTES, "mac") - SN_ASSERT_LENGTH(npub_size, crypto_aead_xchacha20poly1305_ietf_NPUBBYTES, "npub") - SN_ASSERT_LENGTH(k_size, crypto_aead_xchacha20poly1305_ietf_KEYBYTES, "k") - - SN_RETURN(crypto_aead_xchacha20poly1305_ietf_decrypt_detached(m_data, NULL, c_data, c_size, mac_data, ad_data, ad_size, npub_data, k_data), "could not verify data") -} - -napi_value sn_crypto_aead_chacha20poly1305_ietf_keygen (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_aead_chacha20poly1305_ietf_keygen) - - SN_ARGV_TYPEDARRAY(k, 0) - - SN_ASSERT_LENGTH(k_size, crypto_aead_chacha20poly1305_ietf_KEYBYTES, "k") - - crypto_aead_chacha20poly1305_ietf_keygen(k_data); - return NULL; -} - -napi_value sn_crypto_aead_chacha20poly1305_ietf_encrypt (napi_env env, napi_callback_info info) { - SN_ARGV(6, crypto_aead_chacha20poly1305_ietf_encrypt) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_OPTS_TYPEDARRAY(ad, 2) - SN_ARGV_CHECK_NULL(nsec, 3) - SN_ARGV_TYPEDARRAY(npub, 4) - SN_ARGV_TYPEDARRAY(k, 5) - - SN_THROWS(!nsec_is_null, "nsec must always be set to null") - - SN_THROWS(c_size != m_size + crypto_aead_chacha20poly1305_ietf_ABYTES, "c must 'm.byteLength + crypto_aead_chacha20poly1305_ietf_ABYTES' bytes") - SN_THROWS(c_size > 0xffffffff, "c.byteLength must be a 32bit integer") - SN_ASSERT_LENGTH(npub_size, crypto_aead_chacha20poly1305_ietf_NPUBBYTES, "npub") - SN_ASSERT_LENGTH(k_size, crypto_aead_chacha20poly1305_ietf_KEYBYTES, "k") - - unsigned long long clen; - SN_CALL(crypto_aead_chacha20poly1305_ietf_encrypt(c_data, &clen, m_data, m_size, ad_data, ad_size, NULL, npub_data, k_data), "could not encrypt data") - - napi_value result; - SN_STATUS_THROWS(napi_create_uint32(env, (uint32_t) clen, &result), "") - return result; -} - -napi_value sn_crypto_aead_chacha20poly1305_ietf_decrypt (napi_env env, napi_callback_info info) { - SN_ARGV(6, crypto_aead_chacha20poly1305_ietf_decrypt) - - SN_ARGV_TYPEDARRAY(m, 0) - SN_ARGV_CHECK_NULL(nsec, 1) - SN_ARGV_TYPEDARRAY(c, 2) - SN_ARGV_OPTS_TYPEDARRAY(ad, 3) - SN_ARGV_TYPEDARRAY(npub, 4) - SN_ARGV_TYPEDARRAY(k, 5) - - SN_THROWS(!nsec_is_null, "nsec must always be set to null") - - SN_THROWS(m_size != c_size - crypto_aead_chacha20poly1305_ietf_ABYTES, "m must 'c.byteLength - crypto_aead_chacha20poly1305_ietf_ABYTES' bytes") - SN_ASSERT_LENGTH(npub_size, crypto_aead_chacha20poly1305_ietf_NPUBBYTES, "npub") - SN_ASSERT_LENGTH(k_size, crypto_aead_chacha20poly1305_ietf_KEYBYTES, "k") - SN_THROWS(m_size > 0xffffffff, "m.byteLength must be a 32bit integer") - - unsigned long long mlen; - SN_CALL(crypto_aead_chacha20poly1305_ietf_decrypt(m_data, &mlen, NULL, c_data, c_size, ad_data, ad_size, npub_data, k_data), "could not verify data") - - napi_value result; - SN_STATUS_THROWS(napi_create_uint32(env, (uint32_t) mlen, &result), "") - return result; -} - -napi_value sn_crypto_aead_chacha20poly1305_ietf_encrypt_detached (napi_env env, napi_callback_info info) { - SN_ARGV(7, crypto_aead_chacha20poly1305_ietf_encrypt_detached) - - SN_ARGV_TYPEDARRAY(c, 0) - SN_ARGV_TYPEDARRAY(mac, 1) - SN_ARGV_TYPEDARRAY(m, 2) - SN_ARGV_OPTS_TYPEDARRAY(ad, 3) - SN_ARGV_CHECK_NULL(nsec, 4) - SN_ARGV_TYPEDARRAY(npub, 5) - SN_ARGV_TYPEDARRAY(k, 6) - - SN_THROWS(!nsec_is_null, "nsec must always be set to null") - - SN_THROWS(c_size != m_size, "c must be 'm.byteLength' bytes") - SN_ASSERT_LENGTH(mac_size, crypto_aead_chacha20poly1305_ietf_ABYTES, "mac") - SN_ASSERT_LENGTH(npub_size, crypto_aead_chacha20poly1305_ietf_NPUBBYTES, "npub") - SN_ASSERT_LENGTH(k_size, crypto_aead_chacha20poly1305_ietf_KEYBYTES, "k") - - unsigned long long maclen; - SN_CALL(crypto_aead_chacha20poly1305_ietf_encrypt_detached(c_data, mac_data, &maclen, m_data, m_size, ad_data, ad_size, NULL, npub_data, k_data), "could not encrypt data") - - napi_value result; - SN_STATUS_THROWS(napi_create_uint32(env, (uint32_t) maclen, &result), "") - return result; -} - -napi_value sn_crypto_aead_chacha20poly1305_ietf_decrypt_detached (napi_env env, napi_callback_info info) { - SN_ARGV(7, crypto_aead_chacha20poly1305_ietf_decrypt_detached) - - SN_ARGV_TYPEDARRAY(m, 0) - SN_ARGV_CHECK_NULL(nsec, 1) - SN_ARGV_TYPEDARRAY(c, 2) - SN_ARGV_TYPEDARRAY(mac, 3) - SN_ARGV_OPTS_TYPEDARRAY(ad, 4) - SN_ARGV_TYPEDARRAY(npub, 5) - SN_ARGV_TYPEDARRAY(k, 6) - - SN_THROWS(!nsec_is_null, "nsec must always be set to null") - - SN_THROWS(m_size != c_size, "m must be 'c.byteLength' bytes") - SN_ASSERT_LENGTH(mac_size, crypto_aead_chacha20poly1305_ietf_ABYTES, "mac") - SN_ASSERT_LENGTH(npub_size, crypto_aead_chacha20poly1305_ietf_NPUBBYTES, "npub") - SN_ASSERT_LENGTH(k_size, crypto_aead_chacha20poly1305_ietf_KEYBYTES, "k") - - SN_RETURN(crypto_aead_chacha20poly1305_ietf_decrypt_detached(m_data, NULL, c_data, c_size, mac_data, ad_data, ad_size, npub_data, k_data), "could not verify data") -} - -napi_value sn_crypto_secretstream_xchacha20poly1305_keygen (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_secretstream_xchacha20poly1305_keygen) - - SN_ARGV_TYPEDARRAY(k, 0) - - SN_ASSERT_LENGTH(k_size, crypto_secretstream_xchacha20poly1305_KEYBYTES, "k") - - crypto_secretstream_xchacha20poly1305_keygen(k_data); - - return NULL; -} - -napi_value sn_crypto_secretstream_xchacha20poly1305_init_push (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_secretstream_xchacha20poly1305_init_push) - - SN_ARGV_BUFFER_CAST(crypto_secretstream_xchacha20poly1305_state *, state, 0) - SN_ARGV_TYPEDARRAY(header, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_THROWS(state_size != sizeof(crypto_secretstream_xchacha20poly1305_state), "state must be 'crypto_secretstream_xchacha20poly1305_STATEBYTES' bytes") - SN_ASSERT_LENGTH(header_size, crypto_secretstream_xchacha20poly1305_HEADERBYTES, "header") - SN_ASSERT_LENGTH(k_size, crypto_secretstream_xchacha20poly1305_KEYBYTES, "k") - - SN_RETURN(crypto_secretstream_xchacha20poly1305_init_push(state, header_data, k_data), "initial push failed") -} - -napi_value sn_crypto_secretstream_xchacha20poly1305_push (napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_secretstream_xchacha20poly1305_push) - - SN_ARGV_BUFFER_CAST(crypto_secretstream_xchacha20poly1305_state *, state, 0) - SN_ARGV_TYPEDARRAY(c, 1) - SN_ARGV_TYPEDARRAY(m, 2) - SN_ARGV_OPTS_TYPEDARRAY(ad, 3) - SN_ARGV_UINT8(tag, 4) - - SN_THROWS(state_size != sizeof(crypto_secretstream_xchacha20poly1305_state), "state must be state must be 'crypto_secretstream_xchacha20poly1305_STATEBYTES' bytes") - SN_ASSERT_MAX_LENGTH(m_size, crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX, "m") - SN_THROWS(c_size != m_size + crypto_secretstream_xchacha20poly1305_ABYTES, "c must be 'm.byteLength + crypto_secretstream_xchacha20poly1305_ABYTES' bytes") - SN_THROWS(c_size > 0xffffffff, "c.byteLength must be a 32bit integer") - - unsigned long long clen; - SN_CALL(crypto_secretstream_xchacha20poly1305_push(state, c_data, &clen, m_data, m_size, ad_data, ad_size, tag), "push failed") - - napi_value result; - SN_STATUS_THROWS(napi_create_uint32(env, (uint32_t) clen, &result), "") - return result; -} - -napi_value sn_crypto_secretstream_xchacha20poly1305_init_pull (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_secretstream_xchacha20poly1305_init_pull) - - SN_ARGV_BUFFER_CAST(crypto_secretstream_xchacha20poly1305_state *, state, 0) - SN_ARGV_TYPEDARRAY(header, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_THROWS(state_size != sizeof(crypto_secretstream_xchacha20poly1305_state), "state must be 'crypto_secretstream_xchacha20poly1305_STATEBYTES' bytes") - SN_ASSERT_LENGTH(header_size, crypto_secretstream_xchacha20poly1305_HEADERBYTES, "header") - SN_ASSERT_LENGTH(k_size, crypto_secretstream_xchacha20poly1305_KEYBYTES, "k") - - SN_RETURN(crypto_secretstream_xchacha20poly1305_init_pull(state, header_data, k_data), "initial pull failed") -} - -napi_value sn_crypto_secretstream_xchacha20poly1305_pull (napi_env env, napi_callback_info info) { - SN_ARGV(5, crypto_secretstream_xchacha20poly1305_pull) - - SN_ARGV_BUFFER_CAST(crypto_secretstream_xchacha20poly1305_state *, state, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(tag, 2) - SN_ARGV_TYPEDARRAY(c, 3) - SN_ARGV_OPTS_TYPEDARRAY(ad, 4) - - SN_THROWS(state_size != sizeof(crypto_secretstream_xchacha20poly1305_state), "state must be 'crypto_secretstream_xchacha20poly1305_STATEBYTES' bytes") - SN_ASSERT_MIN_LENGTH(c_size, crypto_secretstream_xchacha20poly1305_ABYTES, "c") - SN_ASSERT_LENGTH(tag_size, 1, "tag") - SN_THROWS(m_size != c_size - crypto_secretstream_xchacha20poly1305_ABYTES, "m must be 'c.byteLength - crypto_secretstream_xchacha20poly1305_ABYTES") - SN_THROWS(m_size > 0xffffffff, "m.byteLength must be a 32bit integer") - - unsigned long long mlen; - SN_CALL(crypto_secretstream_xchacha20poly1305_pull(state, m_data, &mlen, tag_data, c_data, c_size, ad_data, ad_size), "pull failed") - - napi_value result; - SN_STATUS_THROWS(napi_create_uint32(env, (uint32_t) mlen, &result), "") - return result; -} - -napi_value sn_crypto_secretstream_xchacha20poly1305_rekey (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_secretstream_xchacha20poly1305_rekey) - - SN_ARGV_BUFFER_CAST(crypto_secretstream_xchacha20poly1305_state *, state, 0) - - SN_THROWS(state_size != sizeof(crypto_secretstream_xchacha20poly1305_state), "state must be 'crypto_secretstream_xchacha20poly1305_STATEBYTES' bytes") - - crypto_secretstream_xchacha20poly1305_rekey(state); - - return NULL; -} - -typedef struct sn_async_task_t { - uv_work_t task; - - enum { - sn_async_task_promise, - sn_async_task_callback - } type; - - void *req; - int code; - - napi_deferred deferred; - napi_ref cb; -} sn_async_task_t; - -typedef struct sn_async_pwhash_request { - napi_env env; - napi_ref out_ref; - unsigned char *out_data; - size_t out_size; - napi_ref pwd_ref; - const char *pwd_data; - size_t pwd_size; - napi_ref salt_ref; - unsigned char *salt; - uint32_t opslimit; - uint32_t memlimit; - uint32_t alg; -} sn_async_pwhash_request; - -static void async_pwhash_execute (uv_work_t *uv_req) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_request *req = (sn_async_pwhash_request *) task->req; - task->code = crypto_pwhash(req->out_data, - req->out_size, - req->pwd_data, - req->pwd_size, - req->salt, - req->opslimit, - req->memlimit, - req->alg); -} - -static void async_pwhash_complete (uv_work_t *uv_req, int status) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_request *req = (sn_async_pwhash_request *) task->req; - - napi_handle_scope scope; - napi_open_handle_scope(req->env, &scope); - - napi_value global; - napi_get_global(req->env, &global); - - SN_ASYNC_COMPLETE("failed to compute password hash") - - napi_close_handle_scope(req->env, scope); - - napi_delete_reference(req->env, req->out_ref); - napi_delete_reference(req->env, req->pwd_ref); - napi_delete_reference(req->env, req->salt_ref); - - free(req); - free(task); -} - -napi_value sn_crypto_pwhash_async (napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(6, 7, crypto_pwhash_async) - - SN_ARGV_BUFFER_CAST(unsigned char *, out, 0) - SN_ARGV_BUFFER_CAST(char *, pwd, 1) - SN_ARGV_BUFFER_CAST(unsigned char *, salt, 2) - SN_ARGV_UINT64(opslimit, 3) - SN_ARGV_UINT64(memlimit, 4) - SN_ARGV_UINT8(alg, 5) - - SN_ASSERT_MIN_LENGTH(out_size, crypto_pwhash_BYTES_MIN, "out") - SN_ASSERT_MAX_LENGTH(out_size, crypto_pwhash_BYTES_MAX, "out") - SN_ASSERT_LENGTH(salt_size, crypto_pwhash_SALTBYTES, "salt") - SN_ASSERT_MIN_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MIN, "opslimit") - SN_ASSERT_MAX_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MAX, "opslimit") - SN_ASSERT_MIN_LENGTH(memlimit, crypto_pwhash_MEMLIMIT_MIN, "memlimit") - SN_ASSERT_MAX_LENGTH(memlimit, (int64_t) crypto_pwhash_MEMLIMIT_MAX, "memlimit") - SN_THROWS(alg < 1 || alg > 2, "alg must be either Argon2i 1.3 or Argon2id 1.3") - - sn_async_pwhash_request *req = (sn_async_pwhash_request *) malloc(sizeof(sn_async_pwhash_request)); - - req->env = env; - req->out_data = out; - req->out_size = out_size; - req->pwd_data = pwd; - req->pwd_size = pwd_size; - req->salt = salt; - req->opslimit = opslimit; - req->memlimit = memlimit; - req->alg = alg; - - sn_async_task_t *task = (sn_async_task_t *) malloc(sizeof(sn_async_task_t)); - SN_ASYNC_TASK(6) - - SN_STATUS_THROWS(napi_create_reference(env, out_argv, 1, &req->out_ref), "") - SN_STATUS_THROWS(napi_create_reference(env, pwd_argv, 1, &req->pwd_ref), "") - SN_STATUS_THROWS(napi_create_reference(env, salt_argv, 1, &req->salt_ref), "") - - SN_QUEUE_TASK(task, async_pwhash_execute, async_pwhash_complete) - - return promise; -} - -typedef struct sn_async_pwhash_str_request { - uv_work_t task; - napi_env env; - napi_ref out_ref; - char *out_data; - napi_ref pwd_ref; - const char *pwd_data; - size_t pwd_size; - uint32_t opslimit; - uint32_t memlimit; -} sn_async_pwhash_str_request; - -static void async_pwhash_str_execute (uv_work_t *uv_req) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_str_request *req = (sn_async_pwhash_str_request *) task->req; - task->code = crypto_pwhash_str(req->out_data, - req->pwd_data, - req->pwd_size, - req->opslimit, - req->memlimit); -} - -static void async_pwhash_str_complete (uv_work_t *uv_req, int status) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_str_request *req = (sn_async_pwhash_str_request *) task->req; - - napi_handle_scope scope; - napi_open_handle_scope(req->env, &scope); - - napi_value global; - napi_get_global(req->env, &global); - - SN_ASYNC_COMPLETE("failed to compute password hash") - - napi_close_handle_scope(req->env, scope); - - napi_delete_reference(req->env, req->out_ref); - napi_delete_reference(req->env, req->pwd_ref); - - free(req); - free(task); -} - -napi_value sn_crypto_pwhash_str_async (napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(4, 5, crypto_pwhash_str_async) - - SN_ARGV_BUFFER_CAST(char *, out, 0) - SN_ARGV_BUFFER_CAST(char *, pwd, 1) - SN_ARGV_UINT64(opslimit, 2) - SN_ARGV_UINT64(memlimit, 3) - - SN_ASSERT_LENGTH(out_size, crypto_pwhash_STRBYTES, "out") - SN_ASSERT_MIN_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MIN, "opslimit") - SN_ASSERT_MAX_LENGTH(opslimit, crypto_pwhash_OPSLIMIT_MAX, "opslimit") - SN_ASSERT_MIN_LENGTH(memlimit, crypto_pwhash_MEMLIMIT_MIN, "memlimit") - SN_ASSERT_MAX_LENGTH(memlimit, (int64_t) crypto_pwhash_MEMLIMIT_MAX, "memlimit") - - sn_async_pwhash_str_request *req = (sn_async_pwhash_str_request *) malloc(sizeof(sn_async_pwhash_str_request)); - req->env = env; - req->out_data = out; - req->pwd_data = pwd; - req->pwd_size = pwd_size; - req->opslimit = opslimit; - req->memlimit = memlimit; - - sn_async_task_t *task = (sn_async_task_t *) malloc(sizeof(sn_async_task_t)); - SN_ASYNC_TASK(4) - - SN_STATUS_THROWS(napi_create_reference(env, out_argv, 1, &req->out_ref), "") - SN_STATUS_THROWS(napi_create_reference(env, pwd_argv, 1, &req->pwd_ref), "") - - SN_QUEUE_TASK(task, async_pwhash_str_execute, async_pwhash_str_complete) - - return promise; -} - -typedef struct sn_async_pwhash_str_verify_request { - uv_work_t task; - napi_env env; - napi_ref str_ref; - char *str_data; - napi_ref pwd_ref; - const char *pwd_data; - size_t pwd_size; -} sn_async_pwhash_str_verify_request; - -static void async_pwhash_str_verify_execute (uv_work_t *uv_req) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_str_verify_request *req = (sn_async_pwhash_str_verify_request *) task->req; - task->code = crypto_pwhash_str_verify(req->str_data, req->pwd_data, req->pwd_size); -} - -static void async_pwhash_str_verify_complete (uv_work_t *uv_req, int status) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_str_verify_request *req = (sn_async_pwhash_str_verify_request *) task->req; - - napi_handle_scope scope; - napi_open_handle_scope(req->env, &scope); - - napi_value global; - napi_get_global(req->env, &global); - - napi_value argv[2]; - - // Due to the way that crypto_pwhash_str_verify signals error different - // from a verification mismatch, we will count all errors as mismatch. - // The other possible error is wrong argument sizes, which is protected - // by macros above - napi_get_null(req->env, &argv[0]); - napi_get_boolean(req->env, task->code == 0, &argv[1]); - - switch (task->type) { - case sn_async_task_promise: { - napi_resolve_deferred(req->env, task->deferred, argv[1]); - task->deferred = NULL; - break; - } - - case sn_async_task_callback: { - napi_value callback; - napi_get_reference_value(req->env, task->cb, &callback); - - napi_value return_val; - SN_CALL_FUNCTION(req->env, global, callback, 2, argv, &return_val) - break; - } - } - - napi_close_handle_scope(req->env, scope); - - napi_delete_reference(req->env, req->str_ref); - napi_delete_reference(req->env, req->pwd_ref); - - free(req); - free(task); -} - -napi_value sn_crypto_pwhash_str_verify_async (napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(2, 3, crypto_pwhash_str_async) - - SN_ARGV_BUFFER_CAST(char *, str, 0) - SN_ARGV_BUFFER_CAST(char *, pwd, 1) - - SN_ASSERT_LENGTH(str_size, crypto_pwhash_STRBYTES, "str") - - sn_async_pwhash_str_verify_request *req = (sn_async_pwhash_str_verify_request *) malloc(sizeof(sn_async_pwhash_str_verify_request)); - req->env = env; - req->str_data = str; - req->pwd_data = pwd; - req->pwd_size = pwd_size; - - sn_async_task_t *task = (sn_async_task_t *) malloc(sizeof(sn_async_task_t)); - SN_ASYNC_TASK(2) - - SN_STATUS_THROWS(napi_create_reference(env, str_argv, 1, &req->str_ref), "") - SN_STATUS_THROWS(napi_create_reference(env, pwd_argv, 1, &req->pwd_ref), "") - - SN_QUEUE_TASK(task, async_pwhash_str_verify_execute, async_pwhash_str_verify_complete) - - return promise; -} - -typedef struct sn_async_pwhash_scryptsalsa208sha256_request { - uv_work_t task; - napi_env env; - napi_ref out_ref; - unsigned char *out_data; - size_t out_size; - napi_ref pwd_ref; - const char *pwd_data; - size_t pwd_size; - napi_ref salt_ref; - unsigned char *salt; - uint32_t opslimit; - uint32_t memlimit; -} sn_async_pwhash_scryptsalsa208sha256_request; - -static void async_pwhash_scryptsalsa208sha256_execute (uv_work_t *uv_req) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_scryptsalsa208sha256_request *req = (sn_async_pwhash_scryptsalsa208sha256_request *) task->req; - task->code = crypto_pwhash_scryptsalsa208sha256(req->out_data, - req->out_size, - req-> pwd_data, - req->pwd_size, - req->salt, - req->opslimit, - req->memlimit); -} - -static void async_pwhash_scryptsalsa208sha256_complete (uv_work_t *uv_req, int status) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_scryptsalsa208sha256_request *req = (sn_async_pwhash_scryptsalsa208sha256_request *) task->req; - - napi_handle_scope scope; - napi_open_handle_scope(req->env, &scope); - - napi_value global; - napi_get_global(req->env, &global); - - SN_ASYNC_COMPLETE("failed to compute password hash") - - napi_close_handle_scope(req->env, scope); - - napi_delete_reference(req->env, req->out_ref); - napi_delete_reference(req->env, req->pwd_ref); - napi_delete_reference(req->env, req->salt_ref); - - free(req); - free(task); -} - -napi_value sn_crypto_pwhash_scryptsalsa208sha256_async (napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(5, 6, crypto_pwhash_scryptsalsa208sha256_async) - - SN_ARGV_BUFFER_CAST(unsigned char *, out, 0) - SN_ARGV_BUFFER_CAST(char *, pwd, 1) - SN_ARGV_BUFFER_CAST(unsigned char *, salt, 2) - SN_ARGV_UINT64(opslimit, 3) - SN_ARGV_UINT64(memlimit, 4) - - SN_ASSERT_MIN_LENGTH(out_size, crypto_pwhash_scryptsalsa208sha256_BYTES_MIN, "out") - SN_ASSERT_MAX_LENGTH(out_size, crypto_pwhash_scryptsalsa208sha256_BYTES_MAX, "out") - SN_ASSERT_LENGTH(salt_size, crypto_pwhash_scryptsalsa208sha256_SALTBYTES, "salt") - SN_ASSERT_MIN_LENGTH(opslimit, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN, "opslimit") - SN_ASSERT_MAX_LENGTH(opslimit, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX, "opslimit") - SN_ASSERT_MIN_LENGTH(memlimit, crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN, "memlimit") - SN_ASSERT_MAX_LENGTH(memlimit, (int64_t) crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX, "memlimit") - - sn_async_pwhash_scryptsalsa208sha256_request *req = (sn_async_pwhash_scryptsalsa208sha256_request *) malloc(sizeof(sn_async_pwhash_scryptsalsa208sha256_request)); - req->env = env; - req->out_data = out; - req->out_size = out_size; - req->pwd_data = pwd; - req->pwd_size = pwd_size; - req-> salt = salt; - req->opslimit = opslimit; - req->memlimit = memlimit; - - sn_async_task_t *task = (sn_async_task_t *) malloc(sizeof(sn_async_task_t)); - SN_ASYNC_TASK(5) - - SN_STATUS_THROWS(napi_create_reference(env, out_argv, 1, &req->out_ref), "") - SN_STATUS_THROWS(napi_create_reference(env, pwd_argv, 1, &req->pwd_ref), "") - SN_STATUS_THROWS(napi_create_reference(env, salt_argv, 1, &req->salt_ref), "") - - SN_QUEUE_TASK(task, async_pwhash_scryptsalsa208sha256_execute, async_pwhash_scryptsalsa208sha256_complete) - - return promise; -} - -typedef struct sn_async_pwhash_scryptsalsa208sha256_str_request { - uv_work_t task; - napi_env env; - napi_ref out_ref; - char *out_data; - napi_ref pwd_ref; - const char *pwd_data; - size_t pwd_size; - uint32_t opslimit; - uint32_t memlimit; -} sn_async_pwhash_scryptsalsa208sha256_str_request; - -static void async_pwhash_scryptsalsa208sha256_str_execute (uv_work_t *uv_req) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_scryptsalsa208sha256_str_request *req = (sn_async_pwhash_scryptsalsa208sha256_str_request *) task->req; - task->code = crypto_pwhash_scryptsalsa208sha256_str(req->out_data, - req->pwd_data, - req->pwd_size, - req->opslimit, - req->memlimit); -} - -static void async_pwhash_scryptsalsa208sha256_str_complete (uv_work_t *uv_req, int status) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_scryptsalsa208sha256_str_request *req = (sn_async_pwhash_scryptsalsa208sha256_str_request *) task->req; - - napi_handle_scope scope; - napi_open_handle_scope(req->env, &scope); - - napi_value global; - napi_get_global(req->env, &global); - - SN_ASYNC_COMPLETE("failed to compute password hash") - - napi_close_handle_scope(req->env, scope); - - napi_delete_reference(req->env, req->out_ref); - napi_delete_reference(req->env, req->pwd_ref); - - free(req); - free(task); -} - -napi_value sn_crypto_pwhash_scryptsalsa208sha256_str_async (napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(4, 5, crypto_pwhash_scryptsalsa208sha256_str_async) - - SN_ARGV_BUFFER_CAST(char *, out, 0) - SN_ARGV_BUFFER_CAST(char *, pwd, 1) - SN_ARGV_UINT64(opslimit, 2) - SN_ARGV_UINT64(memlimit, 3) - - SN_ASSERT_LENGTH(out_size, crypto_pwhash_scryptsalsa208sha256_STRBYTES, "out") - SN_ASSERT_MIN_LENGTH(opslimit, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN, "opslimit") - SN_ASSERT_MAX_LENGTH(opslimit, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX, "opslimit") - SN_ASSERT_MIN_LENGTH(memlimit, crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN, "memlimit") - SN_ASSERT_MAX_LENGTH(memlimit, (int64_t) crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX, "memlimit") - - sn_async_pwhash_scryptsalsa208sha256_str_request *req = (sn_async_pwhash_scryptsalsa208sha256_str_request *) malloc(sizeof(sn_async_pwhash_scryptsalsa208sha256_str_request)); - req->env = env; - req->out_data = out; - req->pwd_data = pwd; - req->pwd_size = pwd_size; - req->opslimit = opslimit; - req->memlimit = memlimit; - - sn_async_task_t *task = (sn_async_task_t *) malloc(sizeof(sn_async_task_t)); - SN_ASYNC_TASK(4) - - SN_STATUS_THROWS(napi_create_reference(env, out_argv, 1, &req->out_ref), "") - SN_STATUS_THROWS(napi_create_reference(env, pwd_argv, 1, &req->pwd_ref), "") - - SN_QUEUE_TASK(task, async_pwhash_scryptsalsa208sha256_str_execute, async_pwhash_scryptsalsa208sha256_str_complete) - - return promise; -} - -typedef struct sn_async_pwhash_scryptsalsa208sha256_str_verify_request { - uv_work_t task; - napi_env env; - napi_ref str_ref; - char *str_data; - napi_ref pwd_ref; - const char *pwd_data; - size_t pwd_size; -} sn_async_pwhash_scryptsalsa208sha256_str_verify_request; - -static void async_pwhash_scryptsalsa208sha256_str_verify_execute (uv_work_t *uv_req) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_scryptsalsa208sha256_str_verify_request *req = (sn_async_pwhash_scryptsalsa208sha256_str_verify_request *) task->req; - task->code = crypto_pwhash_scryptsalsa208sha256_str_verify(req->str_data, req->pwd_data, req->pwd_size); -} - -static void async_pwhash_scryptsalsa208sha256_str_verify_complete (uv_work_t *uv_req, int status) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pwhash_scryptsalsa208sha256_str_verify_request *req = (sn_async_pwhash_scryptsalsa208sha256_str_verify_request *) task->req; - - napi_handle_scope scope; - napi_open_handle_scope(req->env, &scope); - - napi_value global; - napi_get_global(req->env, &global); - - napi_value argv[2]; - - // Due to the way that crypto_pwhash_scryptsalsa208sha256_str_verify - // signal serror different from a verification mismatch, we will count - // all errors as mismatch. The other possible error is wrong argument - // sizes, which is protected by macros above - napi_get_null(req->env, &argv[0]); - napi_get_boolean(req->env, task->code == 0, &argv[1]); - - switch (task->type) { - case sn_async_task_promise: { - napi_resolve_deferred(req->env, task->deferred, argv[1]); - task->deferred = NULL; - break; - } - - case sn_async_task_callback: { - napi_value callback; - napi_get_reference_value(req->env, task->cb, &callback); - - napi_value return_val; - SN_CALL_FUNCTION(req->env, global, callback, 2, argv, &return_val) - break; - } - } - - napi_close_handle_scope(req->env, scope); - - napi_delete_reference(req->env, req->str_ref); - napi_delete_reference(req->env, req->pwd_ref); - - free(req); - free(task); -} - -napi_value sn_crypto_pwhash_scryptsalsa208sha256_str_verify_async (napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(2, 3, crypto_pwhash_scryptsalsa208sha256_str_async) - - SN_ARGV_BUFFER_CAST(char *, str, 0) - SN_ARGV_BUFFER_CAST(char *, pwd, 1) - - SN_ASSERT_LENGTH(str_size, crypto_pwhash_scryptsalsa208sha256_STRBYTES, "str") - - sn_async_pwhash_scryptsalsa208sha256_str_verify_request *req = (sn_async_pwhash_scryptsalsa208sha256_str_verify_request *) malloc(sizeof(sn_async_pwhash_scryptsalsa208sha256_str_verify_request)); - req->env = env; - req->str_data = str; - req->pwd_data = pwd; - req->pwd_size = pwd_size; - - sn_async_task_t *task = (sn_async_task_t *) malloc(sizeof(sn_async_task_t)); - SN_ASYNC_TASK(2) - - SN_STATUS_THROWS(napi_create_reference(env, str_argv, 1, &req->str_ref), "") - SN_STATUS_THROWS(napi_create_reference(env, pwd_argv, 1, &req->pwd_ref), "") - - SN_QUEUE_TASK(task, async_pwhash_scryptsalsa208sha256_str_verify_execute, async_pwhash_scryptsalsa208sha256_str_verify_complete) - - return promise; -} - -typedef struct sn_crypto_stream_xor_state { - unsigned char n[crypto_stream_NONCEBYTES]; - unsigned char k[crypto_stream_KEYBYTES]; - unsigned char next_block[64]; - int remainder; - uint64_t block_counter; -} sn_crypto_stream_xor_state; - -napi_value sn_crypto_stream_xor_wrap_init (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_xor_instance_init) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_xor_state *, state, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_xor_state), "state must be 'sn_crypto_stream_xor_STATEBYTES' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_KEYBYTES, "k") - - state->remainder = 0; - state->block_counter = 0; - memcpy(state->n, n_data, crypto_stream_NONCEBYTES); - memcpy(state->k, k_data, crypto_stream_KEYBYTES); - - return NULL; -} - -napi_value sn_crypto_stream_xor_wrap_update (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_xor_instance_init) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_xor_state *, state, 0) - SN_ARGV_BUFFER_CAST(unsigned char *, c, 1) - SN_ARGV_BUFFER_CAST(unsigned char *, m, 2) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_xor_state), "state must be 'sn_crypto_stream_xor_STATEBYTES' bytes") - SN_THROWS(c_size != m_size, "c must be 'm.byteLength' bytes") - - unsigned char *next_block = state->next_block; - - if (state->remainder) { - uint64_t offset = 0; - int rem = state->remainder; - - while (rem < 64 && offset < m_size) { - c[offset] = next_block[rem] ^ m[offset]; - offset++; - rem++; - } - - c += offset; - m += offset; - m_size -= offset; - state->remainder = rem == 64 ? 0 : rem; - - if (!m_size) return NULL; - } - - state->remainder = m_size & 63; - m_size -= state->remainder; - crypto_stream_xsalsa20_xor_ic(c, m, m_size, state->n, state->block_counter, state->k); - state->block_counter += m_size / 64; - - if (state->remainder) { - sodium_memzero(next_block + state->remainder, 64 - state->remainder); - memcpy(next_block, m + m_size, state->remainder); - - crypto_stream_xsalsa20_xor_ic(next_block, next_block, 64, state->n, state->block_counter, state->k); - memcpy(c + m_size, next_block, state->remainder); - - state->block_counter++; - } - - return NULL; -} - -napi_value sn_crypto_stream_xor_wrap_final (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_stream_xor_instance_init) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_xor_state *, state, 0) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_xor_state), "state must be 'sn_crypto_stream_xor_STATEBYTES' bytes") - - sodium_memzero(state->n, sizeof(state->n)); - sodium_memzero(state->k, sizeof(state->k)); - sodium_memzero(state->next_block, sizeof(state->next_block)); - state->remainder = 0; - - return NULL; -} - -typedef struct sn_crypto_stream_chacha20_xor_state { - unsigned char n[crypto_stream_chacha20_NONCEBYTES]; - unsigned char k[crypto_stream_chacha20_KEYBYTES]; - unsigned char next_block[64]; - int remainder; - uint64_t block_counter; -} sn_crypto_stream_chacha20_xor_state; - -napi_value sn_crypto_stream_chacha20_xor_wrap_init (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_chacha20_xor_instance_init) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_chacha20_xor_state *, state, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_chacha20_xor_state), "state must be 'crypto_stream_chacha20_xor_STATEBYTES' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_chacha20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_chacha20_KEYBYTES, "k") - - state->remainder = 0; - state->block_counter = 0; - memcpy(state->n, n_data, crypto_stream_chacha20_NONCEBYTES); - memcpy(state->k, k_data, crypto_stream_chacha20_KEYBYTES); - - return NULL; -} - -napi_value sn_crypto_stream_chacha20_xor_wrap_update (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_chacha20_xor_instance_init) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_chacha20_xor_state *, state, 0) - SN_ARGV_BUFFER_CAST(unsigned char *, c, 1) - SN_ARGV_BUFFER_CAST(unsigned char *, m, 2) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_chacha20_xor_state), "state must be 'crypto_stream_chacha20_xor_STATEBYTES' bytes") - SN_THROWS(c_size != m_size, "c must be 'm.byteLength' bytes") - - unsigned char *next_block = state->next_block; - - if (state->remainder) { - uint64_t offset = 0; - int rem = state->remainder; - - while (rem < 64 && offset < m_size) { - c[offset] = next_block[rem] ^ m[offset]; - offset++; - rem++; - } - - c += offset; - m += offset; - m_size -= offset; - state->remainder = rem == 64 ? 0 : rem; - - if (!m_size) return NULL; - } - - state->remainder = m_size & 63; - m_size -= state->remainder; - crypto_stream_chacha20_xor_ic(c, m, m_size, state->n, state->block_counter, state->k); - state->block_counter += m_size / 64; - - if (state->remainder) { - sodium_memzero(next_block + state->remainder, 64 - state->remainder); - memcpy(next_block, m + m_size, state->remainder); - - crypto_stream_chacha20_xor_ic(next_block, next_block, 64, state->n, state->block_counter, state->k); - memcpy(c + m_size, next_block, state->remainder); - - state->block_counter++; - } - - return NULL; -} - -napi_value sn_crypto_stream_chacha20_xor_wrap_final (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_stream_chacha20_xor_instance_init) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_chacha20_xor_state *, state, 0) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_chacha20_xor_state), "state must be 'crypto_stream_chacha20_xor_STATEBYTES' bytes") - - sodium_memzero(state->n, sizeof(state->n)); - sodium_memzero(state->k, sizeof(state->k)); - sodium_memzero(state->next_block, sizeof(state->next_block)); - state->remainder = 0; - - return NULL; -} - -typedef struct sn_crypto_stream_chacha20_ietf_xor_state { - unsigned char n[crypto_stream_chacha20_ietf_NONCEBYTES]; - unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES]; - unsigned char next_block[64]; - int remainder; - uint64_t block_counter; -} sn_crypto_stream_chacha20_ietf_xor_state; - -napi_value sn_crypto_stream_chacha20_ietf_xor_wrap_init (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_chacha20_ietf_xor_wrap_init) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_chacha20_ietf_xor_state *, state, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_chacha20_ietf_xor_state), "state must be 'crypto_stream_chacha20_ietf_xor_STATEBYTES' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_chacha20_ietf_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_chacha20_ietf_KEYBYTES, "k") - - state->remainder = 0; - state->block_counter = 0; - memcpy(state->n, n_data, crypto_stream_chacha20_ietf_NONCEBYTES); - memcpy(state->k, k_data, crypto_stream_chacha20_ietf_KEYBYTES); - - return NULL; -} - -napi_value sn_crypto_stream_chacha20_ietf_xor_wrap_update (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_chacha20_ietf_xor_wrap_update) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_chacha20_ietf_xor_state *, state, 0) - SN_ARGV_BUFFER_CAST(unsigned char *, c, 1) - SN_ARGV_BUFFER_CAST(unsigned char *, m, 2) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_chacha20_ietf_xor_state), "state must be 'crypto_stream_chacha20_ietf_xor_STATEBYTES' bytes") - SN_THROWS(c_size != m_size, "c must be 'm.byteLength' bytes") - - unsigned char *next_block = state->next_block; - - if (state->remainder) { - uint64_t offset = 0; - int rem = state->remainder; - - while (rem < 64 && offset < m_size) { - c[offset] = next_block[rem] ^ m[offset]; - offset++; - rem++; - } - - c += offset; - m += offset; - m_size -= offset; - state->remainder = rem == 64 ? 0 : rem; - - if (!m_size) return NULL; - } - - state->remainder = m_size & 63; - m_size -= state->remainder; - crypto_stream_chacha20_ietf_xor_ic(c, m, m_size, state->n, state->block_counter, state->k); - state->block_counter += m_size / 64; - - if (state->remainder) { - sodium_memzero(next_block + state->remainder, 64 - state->remainder); - memcpy(next_block, m + m_size, state->remainder); - - crypto_stream_chacha20_ietf_xor_ic(next_block, next_block, 64, state->n, state->block_counter, state->k); - memcpy(c + m_size, next_block, state->remainder); - - state->block_counter++; - } - - return NULL; -} - -napi_value sn_crypto_stream_chacha20_ietf_xor_wrap_final (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_stream_chacha20_ietf_xor_wrap_final) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_chacha20_ietf_xor_state *, state, 0) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_chacha20_ietf_xor_state), "state must be 'crypto_stream_chacha20_ietf_xor_STATEBYTES' bytes") - - sodium_memzero(state->n, sizeof(state->n)); - sodium_memzero(state->k, sizeof(state->k)); - sodium_memzero(state->next_block, sizeof(state->next_block)); - state->remainder = 0; - - return NULL; -} - -typedef struct sn_crypto_stream_xchacha20_xor_state { - unsigned char n[crypto_stream_xchacha20_NONCEBYTES]; - unsigned char k[crypto_stream_xchacha20_KEYBYTES]; - unsigned char next_block[64]; - int remainder; - uint64_t block_counter; -} sn_crypto_stream_xchacha20_xor_state; - -napi_value sn_crypto_stream_xchacha20_xor_wrap_init (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_xchacha20_xor_wrap_init) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_xchacha20_xor_state *, state, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_xchacha20_xor_state), "state must be 'crypto_stream_xchacha20_xor_STATEBYTES' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_xchacha20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_xchacha20_KEYBYTES, "k") - - state->remainder = 0; - state->block_counter = 0; - memcpy(state->n, n_data, crypto_stream_xchacha20_NONCEBYTES); - memcpy(state->k, k_data, crypto_stream_xchacha20_KEYBYTES); - - return NULL; -} - -napi_value sn_crypto_stream_xchacha20_xor_wrap_update (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_xchacha20_xor_wrap_update) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_xchacha20_xor_state *, state, 0) - SN_ARGV_BUFFER_CAST(unsigned char *, c, 1) - SN_ARGV_BUFFER_CAST(unsigned char *, m, 2) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_xchacha20_xor_state), "state must be 'crypto_stream_xchacha20_xor_STATEBYTES' bytes") - SN_THROWS(c_size != m_size, "c must be 'm.byteLength' bytes") - - unsigned char *next_block = state->next_block; - - if (state->remainder) { - uint64_t offset = 0; - int rem = state->remainder; - - while (rem < 64 && offset < m_size) { - c[offset] = next_block[rem] ^ m[offset]; - offset++; - rem++; - } - - c += offset; - m += offset; - m_size -= offset; - state->remainder = rem == 64 ? 0 : rem; - - if (!m_size) return NULL; - } - - state->remainder = m_size & 63; - m_size -= state->remainder; - crypto_stream_xchacha20_xor_ic(c, m, m_size, state->n, state->block_counter, state->k); - state->block_counter += m_size / 64; - - if (state->remainder) { - sodium_memzero(next_block + state->remainder, 64 - state->remainder); - memcpy(next_block, m + m_size, state->remainder); - - crypto_stream_xchacha20_xor_ic(next_block, next_block, 64, state->n, state->block_counter, state->k); - memcpy(c + m_size, next_block, state->remainder); - - state->block_counter++; - } - - return NULL; -} - -napi_value sn_crypto_stream_xchacha20_xor_wrap_final (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_stream_xchacha20_xor_wrap_final) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_xchacha20_xor_state *, state, 0) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_xchacha20_xor_state), "state must be 'crypto_stream_xchacha20_xor_STATEBYTES' bytes") - - sodium_memzero(state->n, sizeof(state->n)); - sodium_memzero(state->k, sizeof(state->k)); - sodium_memzero(state->next_block, sizeof(state->next_block)); - state->remainder = 0; - - return NULL; -} - -typedef struct sn_crypto_stream_salsa20_xor_state { - unsigned char n[crypto_stream_salsa20_NONCEBYTES]; - unsigned char k[crypto_stream_salsa20_KEYBYTES]; - unsigned char next_block[64]; - int remainder; - uint64_t block_counter; -} sn_crypto_stream_salsa20_xor_state; - -napi_value sn_crypto_stream_salsa20_xor_wrap_init (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_salsa20_xor_wrap_init) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_salsa20_xor_state *, state, 0) - SN_ARGV_TYPEDARRAY(n, 1) - SN_ARGV_TYPEDARRAY(k, 2) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_salsa20_xor_state), "state must be 'crypto_stream_salsa20_xor_STATEBYTES' bytes") - SN_ASSERT_LENGTH(n_size, crypto_stream_salsa20_NONCEBYTES, "n") - SN_ASSERT_LENGTH(k_size, crypto_stream_salsa20_KEYBYTES, "k") - - state->remainder = 0; - state->block_counter = 0; - memcpy(state->n, n_data, crypto_stream_salsa20_NONCEBYTES); - memcpy(state->k, k_data, crypto_stream_salsa20_KEYBYTES); - - return NULL; -} - -napi_value sn_crypto_stream_salsa20_xor_wrap_update (napi_env env, napi_callback_info info) { - SN_ARGV(3, crypto_stream_salsa20_xor_wrap_update) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_salsa20_xor_state *, state, 0) - SN_ARGV_BUFFER_CAST(unsigned char *, c, 1) - SN_ARGV_BUFFER_CAST(unsigned char *, m, 2) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_salsa20_xor_state), "state must be 'crypto_stream_salsa20_xor_STATEBYTES' bytes") - SN_THROWS(c_size != m_size, "c must be 'm.byteLength' bytes") - - unsigned char *next_block = state->next_block; - - if (state->remainder) { - uint64_t offset = 0; - int rem = state->remainder; - - while (rem < 64 && offset < m_size) { - c[offset] = next_block[rem] ^ m[offset]; - offset++; - rem++; - } - - c += offset; - m += offset; - m_size -= offset; - state->remainder = rem == 64 ? 0 : rem; - - if (!m_size) return NULL; - } - - state->remainder = m_size & 63; - m_size -= state->remainder; - crypto_stream_salsa20_xor_ic(c, m, m_size, state->n, state->block_counter, state->k); - state->block_counter += m_size / 64; - - if (state->remainder) { - sodium_memzero(next_block + state->remainder, 64 - state->remainder); - memcpy(next_block, m + m_size, state->remainder); - - crypto_stream_salsa20_xor_ic(next_block, next_block, 64, state->n, state->block_counter, state->k); - memcpy(c + m_size, next_block, state->remainder); - - state->block_counter++; - } - - return NULL; -} - -napi_value sn_crypto_stream_salsa20_xor_wrap_final (napi_env env, napi_callback_info info) { - SN_ARGV(1, crypto_stream_salsa20_xor_wrap_final) - - SN_ARGV_BUFFER_CAST(sn_crypto_stream_salsa20_xor_state *, state, 0) - - SN_THROWS(state_size != sizeof(sn_crypto_stream_salsa20_xor_state), "state must be 'crypto_stream_salsa20_xor_STATEBYTES' bytes") - - sodium_memzero(state->n, sizeof(state->n)); - sodium_memzero(state->k, sizeof(state->k)); - sodium_memzero(state->next_block, sizeof(state->next_block)); - state->remainder = 0; - - return NULL; -} - -// Experimental API - -napi_value sn_extension_tweak_ed25519_base (napi_env env, napi_callback_info info) { - SN_ARGV(3, extension_tweak_ed25519_base) - - SN_ARGV_TYPEDARRAY(n, 0) - SN_ARGV_TYPEDARRAY(p, 1) - SN_ARGV_TYPEDARRAY(ns, 2) - - SN_ASSERT_LENGTH(n_size, sn__extension_tweak_ed25519_SCALARBYTES, "n") - SN_ASSERT_LENGTH(p_size, sn__extension_tweak_ed25519_BYTES, "p") - - sn__extension_tweak_ed25519_base(p_data, n_data, ns_data, ns_size); - - return NULL; -} - -napi_value sn_extension_tweak_ed25519_sign_detached (napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(3, 4, extension_tweak_ed25519_sign_detached) - - SN_ARGV_TYPEDARRAY(sig, 0) - SN_ARGV_TYPEDARRAY(m, 1) - SN_ARGV_TYPEDARRAY(scalar, 2) - SN_ARGV_OPTS_TYPEDARRAY(pk, 3) - - SN_ASSERT_LENGTH(sig_size, crypto_sign_BYTES, "sig") - SN_ASSERT_LENGTH(scalar_size, sn__extension_tweak_ed25519_SCALARBYTES, "scalar") - - if (pk_data != NULL) { - SN_ASSERT_LENGTH(pk_size, crypto_sign_PUBLICKEYBYTES, "pk") - } - - SN_RETURN(sn__extension_tweak_ed25519_sign_detached(sig_data, NULL, m_data, m_size, scalar_data, pk_data), "failed to compute signature") -} - -napi_value sn_extension_tweak_ed25519_sk_to_scalar (napi_env env, napi_callback_info info) { - SN_ARGV(2, extension_tweak_ed25519_sk_to_scalar) - - SN_ARGV_TYPEDARRAY(n, 0) - SN_ARGV_TYPEDARRAY(sk, 1) - - SN_ASSERT_LENGTH(n_size, sn__extension_tweak_ed25519_SCALARBYTES, "n") - SN_ASSERT_LENGTH(sk_size, crypto_sign_SECRETKEYBYTES, "sk") - - sn__extension_tweak_ed25519_sk_to_scalar(n_data, sk_data); - - return NULL; -} - -napi_value sn_extension_tweak_ed25519_scalar (napi_env env, napi_callback_info info) { - SN_ARGV(3, extension_tweak_ed25519_scalar) - - SN_ARGV_TYPEDARRAY(scalar_out, 0) - SN_ARGV_TYPEDARRAY(scalar, 1) - SN_ARGV_TYPEDARRAY(ns, 2) - - SN_ASSERT_LENGTH(scalar_out_size, sn__extension_tweak_ed25519_SCALARBYTES, "scalar_out") - SN_ASSERT_LENGTH(scalar_size, sn__extension_tweak_ed25519_SCALARBYTES, "scalar") - - sn__extension_tweak_ed25519_scalar(scalar_out_data, scalar_data, ns_data, ns_size); - - return NULL; -} - -napi_value sn_extension_tweak_ed25519_pk (napi_env env, napi_callback_info info) { - SN_ARGV(3, extension_tweak_ed25519_pk) - - SN_ARGV_TYPEDARRAY(tpk, 0) - SN_ARGV_TYPEDARRAY(pk, 1) - SN_ARGV_TYPEDARRAY(ns, 2) - - SN_ASSERT_LENGTH(tpk_size, crypto_sign_PUBLICKEYBYTES, "tpk") - SN_ASSERT_LENGTH(pk_size, crypto_sign_PUBLICKEYBYTES, "pk") - - SN_RETURN(sn__extension_tweak_ed25519_pk(tpk_data, pk_data, ns_data, ns_size), "failed to tweak public key") -} - -napi_value sn_extension_tweak_ed25519_keypair (napi_env env, napi_callback_info info) { - SN_ARGV(4, extension_tweak_ed25519_keypair) - - SN_ARGV_TYPEDARRAY(pk, 0) - SN_ARGV_TYPEDARRAY(scalar_out, 1) - SN_ARGV_TYPEDARRAY(scalar_in, 2) - SN_ARGV_TYPEDARRAY(ns, 3) - - SN_ASSERT_LENGTH(pk_size, sn__extension_tweak_ed25519_BYTES, "pk") - SN_ASSERT_LENGTH(scalar_out_size, sn__extension_tweak_ed25519_SCALARBYTES, "scalar_out") - SN_ASSERT_LENGTH(scalar_in_size, sn__extension_tweak_ed25519_SCALARBYTES, "scalar_in") - - sn__extension_tweak_ed25519_keypair(pk_data, scalar_out_data, scalar_in_data, ns_data, ns_size); - - return NULL; -} - -napi_value sn_extension_tweak_ed25519_scalar_add (napi_env env, napi_callback_info info) { - SN_ARGV(3, extension_tweak_ed25519_scalar_add) - - SN_ARGV_TYPEDARRAY(scalar_out, 0) - SN_ARGV_TYPEDARRAY(scalar, 1) - SN_ARGV_TYPEDARRAY(n, 2) - - SN_ASSERT_LENGTH(scalar_out_size, sn__extension_tweak_ed25519_SCALARBYTES, "scalar_out") - SN_ASSERT_LENGTH(scalar_size, sn__extension_tweak_ed25519_SCALARBYTES, "scalar") - SN_ASSERT_LENGTH(n_size, sn__extension_tweak_ed25519_SCALARBYTES, "n") - - sn__extension_tweak_ed25519_scalar_add(scalar_out_data, scalar_data, n_data); - - return NULL; -} - -napi_value sn_extension_tweak_ed25519_pk_add (napi_env env, napi_callback_info info) { - SN_ARGV(3, extension_tweak_ed25519_pk) - - SN_ARGV_TYPEDARRAY(tpk, 0) - SN_ARGV_TYPEDARRAY(pk, 1) - SN_ARGV_TYPEDARRAY(p, 2) - - SN_ASSERT_LENGTH(tpk_size, crypto_sign_PUBLICKEYBYTES, "tpk") - SN_ASSERT_LENGTH(pk_size, crypto_sign_PUBLICKEYBYTES, "pk") - SN_ASSERT_LENGTH(p_size, crypto_sign_PUBLICKEYBYTES, "p") - - SN_RETURN(sn__extension_tweak_ed25519_pk_add(tpk_data, pk_data, p_data), "failed to add tweak to public key") -} - -napi_value sn_extension_tweak_ed25519_keypair_add (napi_env env, napi_callback_info info) { - SN_ARGV(4, extension_tweak_ed25519_keypair_add) - - SN_ARGV_TYPEDARRAY(pk, 0) - SN_ARGV_TYPEDARRAY(scalar_out, 1) - SN_ARGV_TYPEDARRAY(scalar_in, 2) - SN_ARGV_TYPEDARRAY(tweak, 3) - - SN_ASSERT_LENGTH(pk_size, sn__extension_tweak_ed25519_BYTES, "pk") - SN_ASSERT_LENGTH(scalar_out_size, sn__extension_tweak_ed25519_SCALARBYTES, "scalar_out") - SN_ASSERT_LENGTH(scalar_in_size, sn__extension_tweak_ed25519_SCALARBYTES, "scalar_in") - SN_ASSERT_LENGTH(tweak_size, sn__extension_tweak_ed25519_SCALARBYTES, "tweak") - - SN_RETURN(sn__extension_tweak_ed25519_keypair_add(pk_data, scalar_out_data, scalar_in_data, tweak_data), "failed to add tweak to keypair") -} - -napi_value sn_extension_pbkdf2_sha512 (napi_env env, napi_callback_info info) { - SN_ARGV(5, extension_pbkdf2_sha512) - - SN_ARGV_BUFFER_CAST(unsigned char *, out, 0) - SN_ARGV_BUFFER_CAST(unsigned char *, passwd, 1) - SN_ARGV_BUFFER_CAST(unsigned char *, salt, 2) - SN_ARGV_UINT64(iter, 3) - SN_ARGV_UINT64(outlen, 4) - - SN_ASSERT_MIN_LENGTH(iter, sn__extension_pbkdf2_sha512_ITERATIONS_MIN, "iterations") - SN_ASSERT_MAX_LENGTH(outlen, sn__extension_pbkdf2_sha512_BYTES_MAX, "outlen") - - SN_ASSERT_MIN_LENGTH(out_size, outlen, "out") - - SN_RETURN(sn__extension_pbkdf2_sha512(passwd, passwd_size, salt, salt_size, iter, out, outlen), "failed to add tweak to public key") -} - -typedef struct sn_async_pbkdf2_sha512_request { - napi_env env; - unsigned char *out_data; - size_t out_size; - napi_ref out_ref; - size_t outlen; - napi_ref pwd_ref; - const unsigned char *pwd_data; - size_t pwd_size; - napi_ref salt_ref; - unsigned char *salt_data; - size_t salt_size; - uint64_t iter; -} sn_async_pbkdf2_sha512_request; - -static void async_pbkdf2_sha512_execute (uv_work_t *uv_req) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pbkdf2_sha512_request *req = (sn_async_pbkdf2_sha512_request *) task->req; - task->code = sn__extension_pbkdf2_sha512(req->pwd_data, - req->pwd_size, - req->salt_data, - req->salt_size, - req->iter, - req->out_data, - req->outlen); -} - -static void async_pbkdf2_sha512_complete (uv_work_t *uv_req, int status) { - sn_async_task_t *task = (sn_async_task_t *) uv_req; - sn_async_pbkdf2_sha512_request *req = (sn_async_pbkdf2_sha512_request *) task->req; - - napi_handle_scope scope; - napi_open_handle_scope(req->env, &scope); - - napi_value global; - napi_get_global(req->env, &global); - - SN_ASYNC_COMPLETE("failed to compute kdf") - - napi_close_handle_scope(req->env, scope); - - napi_delete_reference(req->env, req->out_ref); - napi_delete_reference(req->env, req->pwd_ref); - napi_delete_reference(req->env, req->salt_ref); - - free(req); - free(task); -} - -napi_value sn_extension_pbkdf2_sha512_async (napi_env env, napi_callback_info info) { - SN_ARGV_OPTS(5, 6, extension_pbkdf2_sha512_async) - - SN_ARGV_BUFFER_CAST(unsigned char *, out, 0) - SN_ARGV_BUFFER_CAST(unsigned char *, pwd, 1) - SN_ARGV_BUFFER_CAST(unsigned char *, salt, 2) - SN_ARGV_UINT64(iter, 3) - SN_ARGV_UINT64(outlen, 4) - - SN_ASSERT_MIN_LENGTH(iter, sn__extension_pbkdf2_sha512_ITERATIONS_MIN, "iterations") - SN_ASSERT_MAX_LENGTH(outlen, sn__extension_pbkdf2_sha512_BYTES_MAX, "outlen") - SN_ASSERT_MIN_LENGTH(out_size, outlen, "output") - - sn_async_pbkdf2_sha512_request *req = (sn_async_pbkdf2_sha512_request *) malloc(sizeof(sn_async_pbkdf2_sha512_request)); - - req->env = env; - req->out_data = out; - req->out_size = out_size; - req->pwd_data = pwd; - req->pwd_size = pwd_size; - req->salt_data = salt; - req->salt_size = salt_size; - req->iter = iter; - req->outlen = outlen; - - sn_async_task_t *task = (sn_async_task_t *) malloc(sizeof(sn_async_task_t)); - SN_ASYNC_TASK(5); - - SN_STATUS_THROWS(napi_create_reference(env, out_argv, 1, &req->out_ref), "") - SN_STATUS_THROWS(napi_create_reference(env, pwd_argv, 1, &req->pwd_ref), "") - SN_STATUS_THROWS(napi_create_reference(env, salt_argv, 1, &req->salt_ref), "") - - SN_QUEUE_TASK(task, async_pbkdf2_sha512_execute, async_pbkdf2_sha512_complete) - - return promise; -} - -static napi_value create_sodium_native (napi_env env) { - SN_THROWS(sodium_init() == -1, "sodium_init() failed") - - napi_value exports; - napi_create_object(env, &exports); - - // memory - - SN_EXPORT_FUNCTION(sodium_memzero, sn_sodium_memzero) - SN_EXPORT_FUNCTION(sodium_mlock, sn_sodium_mlock) - SN_EXPORT_FUNCTION(sodium_munlock, sn_sodium_munlock) - SN_EXPORT_FUNCTION(sodium_malloc, sn_sodium_malloc) - SN_EXPORT_FUNCTION(sodium_free, sn_sodium_free) - SN_EXPORT_FUNCTION(sodium_mprotect_noaccess, sn_sodium_mprotect_noaccess) - SN_EXPORT_FUNCTION(sodium_mprotect_readonly, sn_sodium_mprotect_readonly) - SN_EXPORT_FUNCTION(sodium_mprotect_readwrite, sn_sodium_mprotect_readwrite) - - // randombytes - - SN_EXPORT_FUNCTION(randombytes_buf, sn_randombytes_buf) - SN_EXPORT_FUNCTION(randombytes_buf_deterministic, sn_randombytes_buf_deterministic) - SN_EXPORT_FUNCTION(randombytes_uniform, sn_randombytes_uniform) - SN_EXPORT_FUNCTION(randombytes_random, sn_randombytes_random) - SN_EXPORT_UINT32(randombytes_SEEDBYTES, randombytes_SEEDBYTES) - - // sodium helpers - - SN_EXPORT_FUNCTION(sodium_memcmp, sn_sodium_memcmp) - SN_EXPORT_FUNCTION(sodium_increment, sn_sodium_increment) - SN_EXPORT_FUNCTION(sodium_add, sn_sodium_add) - SN_EXPORT_FUNCTION(sodium_sub, sn_sodium_sub) - SN_EXPORT_FUNCTION(sodium_compare, sn_sodium_compare) - SN_EXPORT_FUNCTION(sodium_is_zero, sn_sodium_is_zero) - SN_EXPORT_FUNCTION(sodium_pad, sn_sodium_pad) - SN_EXPORT_FUNCTION(sodium_unpad, sn_sodium_unpad) - - // crypto_aead - - SN_EXPORT_FUNCTION(crypto_aead_xchacha20poly1305_ietf_keygen, sn_crypto_aead_xchacha20poly1305_ietf_keygen) - SN_EXPORT_FUNCTION(crypto_aead_xchacha20poly1305_ietf_encrypt, sn_crypto_aead_xchacha20poly1305_ietf_encrypt) - SN_EXPORT_FUNCTION(crypto_aead_xchacha20poly1305_ietf_decrypt, sn_crypto_aead_xchacha20poly1305_ietf_decrypt) - SN_EXPORT_FUNCTION(crypto_aead_xchacha20poly1305_ietf_encrypt_detached, sn_crypto_aead_xchacha20poly1305_ietf_encrypt_detached) - SN_EXPORT_FUNCTION(crypto_aead_xchacha20poly1305_ietf_decrypt_detached, sn_crypto_aead_xchacha20poly1305_ietf_decrypt_detached) - SN_EXPORT_UINT32(crypto_aead_xchacha20poly1305_ietf_ABYTES, crypto_aead_xchacha20poly1305_ietf_ABYTES) - SN_EXPORT_UINT32(crypto_aead_xchacha20poly1305_ietf_KEYBYTES, crypto_aead_xchacha20poly1305_ietf_KEYBYTES) - SN_EXPORT_UINT32(crypto_aead_xchacha20poly1305_ietf_NPUBBYTES, crypto_aead_xchacha20poly1305_ietf_NPUBBYTES) - SN_EXPORT_UINT32(crypto_aead_xchacha20poly1305_ietf_NSECBYTES, crypto_aead_xchacha20poly1305_ietf_NSECBYTES) - SN_EXPORT_UINT64(crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX, crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX) - - SN_EXPORT_FUNCTION(crypto_aead_chacha20poly1305_ietf_keygen, sn_crypto_aead_chacha20poly1305_ietf_keygen) - SN_EXPORT_FUNCTION(crypto_aead_chacha20poly1305_ietf_encrypt, sn_crypto_aead_chacha20poly1305_ietf_encrypt) - SN_EXPORT_FUNCTION(crypto_aead_chacha20poly1305_ietf_decrypt, sn_crypto_aead_chacha20poly1305_ietf_decrypt) - SN_EXPORT_FUNCTION(crypto_aead_chacha20poly1305_ietf_encrypt_detached, sn_crypto_aead_chacha20poly1305_ietf_encrypt_detached) - SN_EXPORT_FUNCTION(crypto_aead_chacha20poly1305_ietf_decrypt_detached, sn_crypto_aead_chacha20poly1305_ietf_decrypt_detached) - SN_EXPORT_UINT32(crypto_aead_chacha20poly1305_ietf_ABYTES, crypto_aead_chacha20poly1305_ietf_ABYTES) - SN_EXPORT_UINT32(crypto_aead_chacha20poly1305_ietf_KEYBYTES, crypto_aead_chacha20poly1305_ietf_KEYBYTES) - SN_EXPORT_UINT32(crypto_aead_chacha20poly1305_ietf_NPUBBYTES, crypto_aead_chacha20poly1305_ietf_NPUBBYTES) - SN_EXPORT_UINT32(crypto_aead_chacha20poly1305_ietf_NSECBYTES, crypto_aead_chacha20poly1305_ietf_NSECBYTES) - SN_EXPORT_UINT64(crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX, crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX) - - // crypto_auth - - SN_EXPORT_FUNCTION(crypto_auth, sn_crypto_auth) - SN_EXPORT_FUNCTION(crypto_auth_verify, sn_crypto_auth_verify) - SN_EXPORT_UINT32(crypto_auth_BYTES, crypto_auth_BYTES) - SN_EXPORT_UINT32(crypto_auth_KEYBYTES, crypto_auth_KEYBYTES) - SN_EXPORT_STRING(crypto_auth_PRIMITIVE, crypto_auth_PRIMITIVE) - - // crypto_box - - SN_EXPORT_FUNCTION(crypto_box_keypair, sn_crypto_box_keypair) - SN_EXPORT_FUNCTION(crypto_box_seed_keypair, sn_crypto_box_seed_keypair) - SN_EXPORT_FUNCTION(crypto_box_easy, sn_crypto_box_easy) - SN_EXPORT_FUNCTION(crypto_box_open_easy, sn_crypto_box_open_easy) - SN_EXPORT_FUNCTION(crypto_box_detached, sn_crypto_box_detached) - SN_EXPORT_FUNCTION(crypto_box_open_detached, sn_crypto_box_open_detached) - SN_EXPORT_FUNCTION(crypto_box_seal, sn_crypto_box_seal) - SN_EXPORT_FUNCTION(crypto_box_seal_open, sn_crypto_box_seal_open) - SN_EXPORT_UINT32(crypto_box_SEEDBYTES, crypto_box_SEEDBYTES) - SN_EXPORT_UINT32(crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES) - SN_EXPORT_UINT32(crypto_box_SECRETKEYBYTES, crypto_box_SECRETKEYBYTES) - SN_EXPORT_UINT32(crypto_box_NONCEBYTES, crypto_box_NONCEBYTES) - SN_EXPORT_UINT32(crypto_box_MACBYTES, crypto_box_MACBYTES) - SN_EXPORT_UINT32(crypto_box_SEALBYTES, crypto_box_SEALBYTES) - SN_EXPORT_STRING(crypto_box_PRIMITIVE, crypto_box_PRIMITIVE) - - // crypto_core - - SN_EXPORT_FUNCTION(crypto_core_ed25519_is_valid_point, sn_crypto_core_ed25519_is_valid_point) - SN_EXPORT_FUNCTION(crypto_core_ed25519_from_uniform, sn_crypto_core_ed25519_from_uniform) - SN_EXPORT_FUNCTION(crypto_core_ed25519_add, sn_crypto_core_ed25519_add) - SN_EXPORT_FUNCTION(crypto_core_ed25519_sub, sn_crypto_core_ed25519_sub) - SN_EXPORT_FUNCTION(crypto_core_ed25519_scalar_random, sn_crypto_core_ed25519_scalar_random) - SN_EXPORT_FUNCTION(crypto_core_ed25519_scalar_reduce, sn_crypto_core_ed25519_scalar_reduce) - SN_EXPORT_FUNCTION(crypto_core_ed25519_scalar_invert, sn_crypto_core_ed25519_scalar_invert) - SN_EXPORT_FUNCTION(crypto_core_ed25519_scalar_negate, sn_crypto_core_ed25519_scalar_negate) - SN_EXPORT_FUNCTION(crypto_core_ed25519_scalar_complement, sn_crypto_core_ed25519_scalar_complement) - SN_EXPORT_FUNCTION(crypto_core_ed25519_scalar_add, sn_crypto_core_ed25519_scalar_add) - SN_EXPORT_FUNCTION(crypto_core_ed25519_scalar_sub, sn_crypto_core_ed25519_scalar_sub) - SN_EXPORT_UINT32(crypto_core_ed25519_BYTES, crypto_core_ed25519_BYTES) - SN_EXPORT_UINT32(crypto_core_ed25519_UNIFORMBYTES, crypto_core_ed25519_UNIFORMBYTES) - SN_EXPORT_UINT32(crypto_core_ed25519_SCALARBYTES, crypto_core_ed25519_SCALARBYTES) - SN_EXPORT_UINT32(crypto_core_ed25519_NONREDUCEDSCALARBYTES, crypto_core_ed25519_NONREDUCEDSCALARBYTES) - - // crypto_kdf - - SN_EXPORT_FUNCTION(crypto_kdf_keygen, sn_crypto_kdf_keygen) - SN_EXPORT_FUNCTION(crypto_kdf_derive_from_key, sn_crypto_kdf_derive_from_key) - SN_EXPORT_UINT32(crypto_kdf_BYTES_MIN, crypto_kdf_BYTES_MIN) - SN_EXPORT_UINT32(crypto_kdf_BYTES_MAX, crypto_kdf_BYTES_MAX) - SN_EXPORT_UINT32(crypto_kdf_CONTEXTBYTES, crypto_kdf_CONTEXTBYTES) - SN_EXPORT_UINT32(crypto_kdf_KEYBYTES, crypto_kdf_KEYBYTES) - SN_EXPORT_STRING(crypto_kdf_PRIMITIVE, crypto_kdf_PRIMITIVE) - - // crypto_kx - - SN_EXPORT_FUNCTION(crypto_kx_keypair, sn_crypto_kx_keypair) - SN_EXPORT_FUNCTION(crypto_kx_seed_keypair, sn_crypto_kx_seed_keypair) - SN_EXPORT_FUNCTION(crypto_kx_client_session_keys, sn_crypto_kx_client_session_keys) - SN_EXPORT_FUNCTION(crypto_kx_server_session_keys, sn_crypto_kx_server_session_keys) - SN_EXPORT_UINT32(crypto_kx_PUBLICKEYBYTES, crypto_kx_PUBLICKEYBYTES) - SN_EXPORT_UINT32(crypto_kx_SECRETKEYBYTES, crypto_kx_SECRETKEYBYTES) - SN_EXPORT_UINT32(crypto_kx_SEEDBYTES, crypto_kx_SEEDBYTES) - SN_EXPORT_UINT32(crypto_kx_SESSIONKEYBYTES, crypto_kx_SESSIONKEYBYTES) - SN_EXPORT_STRING(crypto_kx_PRIMITIVE, crypto_kx_PRIMITIVE) - - // crypto_generichash - - SN_EXPORT_FUNCTION(crypto_generichash, sn_crypto_generichash) - SN_EXPORT_FUNCTION(crypto_generichash_batch, sn_crypto_generichash_batch) - SN_EXPORT_FUNCTION(crypto_generichash_keygen, sn_crypto_generichash_keygen) - SN_EXPORT_FUNCTION(crypto_generichash_init, sn_crypto_generichash_init) - SN_EXPORT_FUNCTION(crypto_generichash_update, sn_crypto_generichash_update) - SN_EXPORT_FUNCTION(crypto_generichash_final, sn_crypto_generichash_final) - SN_EXPORT_UINT32(crypto_generichash_STATEBYTES, sizeof(crypto_generichash_state)) - SN_EXPORT_STRING(crypto_generichash_PRIMITIVE, crypto_generichash_PRIMITIVE) - SN_EXPORT_UINT32(crypto_generichash_BYTES_MIN, crypto_generichash_BYTES_MIN) - SN_EXPORT_UINT32(crypto_generichash_BYTES_MAX, crypto_generichash_BYTES_MAX) - SN_EXPORT_UINT32(crypto_generichash_BYTES, crypto_generichash_BYTES) - SN_EXPORT_UINT32(crypto_generichash_KEYBYTES_MIN, crypto_generichash_KEYBYTES_MIN) - SN_EXPORT_UINT32(crypto_generichash_KEYBYTES_MAX, crypto_generichash_KEYBYTES_MAX) - SN_EXPORT_UINT32(crypto_generichash_KEYBYTES, crypto_generichash_KEYBYTES) - - // crypto_hash - - SN_EXPORT_FUNCTION(crypto_hash, sn_crypto_hash) - SN_EXPORT_UINT32(crypto_hash_BYTES, crypto_hash_BYTES) - SN_EXPORT_STRING(crypto_hash_PRIMITIVE, crypto_hash_PRIMITIVE) - - SN_EXPORT_FUNCTION(crypto_hash_sha256, sn_crypto_hash_sha256) - SN_EXPORT_FUNCTION(crypto_hash_sha256_init, sn_crypto_hash_sha256_init) - SN_EXPORT_FUNCTION(crypto_hash_sha256_update, sn_crypto_hash_sha256_update) - SN_EXPORT_FUNCTION(crypto_hash_sha256_final, sn_crypto_hash_sha256_final) - SN_EXPORT_UINT32(crypto_hash_sha256_STATEBYTES, sizeof(crypto_hash_sha256_state)) - SN_EXPORT_UINT32(crypto_hash_sha256_BYTES, crypto_hash_sha256_BYTES) - - SN_EXPORT_FUNCTION(crypto_hash_sha512, sn_crypto_hash_sha512) - SN_EXPORT_FUNCTION(crypto_hash_sha512_init, sn_crypto_hash_sha512_init) - SN_EXPORT_FUNCTION(crypto_hash_sha512_update, sn_crypto_hash_sha512_update) - SN_EXPORT_FUNCTION(crypto_hash_sha512_final, sn_crypto_hash_sha512_final) - SN_EXPORT_UINT32(crypto_hash_sha512_STATEBYTES, sizeof(crypto_hash_sha512_state)) - SN_EXPORT_UINT32(crypto_hash_sha512_BYTES, crypto_hash_sha512_BYTES) - - // crypto_onetimeauth - - SN_EXPORT_FUNCTION(crypto_onetimeauth, sn_crypto_onetimeauth) - SN_EXPORT_FUNCTION(crypto_onetimeauth_verify, sn_crypto_onetimeauth_verify) - SN_EXPORT_FUNCTION(crypto_onetimeauth_init, sn_crypto_onetimeauth_init) - SN_EXPORT_FUNCTION(crypto_onetimeauth_update, sn_crypto_onetimeauth_update) - SN_EXPORT_FUNCTION(crypto_onetimeauth_final, sn_crypto_onetimeauth_final) - SN_EXPORT_UINT32(crypto_onetimeauth_STATEBYTES, sizeof(crypto_onetimeauth_state)) - SN_EXPORT_UINT32(crypto_onetimeauth_BYTES, crypto_onetimeauth_BYTES) - SN_EXPORT_UINT32(crypto_onetimeauth_KEYBYTES, crypto_onetimeauth_KEYBYTES) - SN_EXPORT_STRING(crypto_onetimeauth_PRIMITIVE, crypto_onetimeauth_PRIMITIVE) - - // crypto_pwhash - - SN_EXPORT_FUNCTION(crypto_pwhash, sn_crypto_pwhash) - SN_EXPORT_FUNCTION(crypto_pwhash_str, sn_crypto_pwhash_str) - SN_EXPORT_FUNCTION(crypto_pwhash_str_verify, sn_crypto_pwhash_str_verify) - SN_EXPORT_FUNCTION(crypto_pwhash_str_needs_rehash, sn_crypto_pwhash_str_needs_rehash) - SN_EXPORT_FUNCTION(crypto_pwhash_async, sn_crypto_pwhash_async) - SN_EXPORT_FUNCTION(crypto_pwhash_str_async, sn_crypto_pwhash_str_async) - SN_EXPORT_FUNCTION(crypto_pwhash_str_verify_async, sn_crypto_pwhash_str_verify_async) - SN_EXPORT_UINT32(crypto_pwhash_ALG_ARGON2I13, crypto_pwhash_ALG_ARGON2I13) - SN_EXPORT_UINT32(crypto_pwhash_ALG_ARGON2ID13, crypto_pwhash_ALG_ARGON2ID13) - SN_EXPORT_UINT32(crypto_pwhash_ALG_DEFAULT, crypto_pwhash_ALG_DEFAULT) - SN_EXPORT_UINT32(crypto_pwhash_BYTES_MIN, crypto_pwhash_BYTES_MIN) - SN_EXPORT_UINT32(crypto_pwhash_BYTES_MAX, crypto_pwhash_BYTES_MAX) - SN_EXPORT_UINT32(crypto_pwhash_PASSWD_MIN, crypto_pwhash_PASSWD_MIN) - SN_EXPORT_UINT32(crypto_pwhash_PASSWD_MAX, crypto_pwhash_PASSWD_MAX) - SN_EXPORT_UINT32(crypto_pwhash_SALTBYTES, crypto_pwhash_SALTBYTES) - SN_EXPORT_UINT32(crypto_pwhash_STRBYTES, crypto_pwhash_STRBYTES) - SN_EXPORT_STRING(crypto_pwhash_STRPREFIX, crypto_pwhash_STRPREFIX) - SN_EXPORT_UINT32(crypto_pwhash_OPSLIMIT_MIN, crypto_pwhash_OPSLIMIT_MIN) - SN_EXPORT_UINT32(crypto_pwhash_OPSLIMIT_MAX, crypto_pwhash_OPSLIMIT_MAX) - SN_EXPORT_UINT32(crypto_pwhash_MEMLIMIT_MIN, crypto_pwhash_MEMLIMIT_MIN) - SN_EXPORT_UINT32(crypto_pwhash_MEMLIMIT_MAX, crypto_pwhash_MEMLIMIT_MAX) - SN_EXPORT_UINT32(crypto_pwhash_OPSLIMIT_INTERACTIVE, crypto_pwhash_OPSLIMIT_INTERACTIVE) - SN_EXPORT_UINT32(crypto_pwhash_MEMLIMIT_INTERACTIVE, crypto_pwhash_MEMLIMIT_INTERACTIVE) - SN_EXPORT_UINT32(crypto_pwhash_OPSLIMIT_MODERATE, crypto_pwhash_OPSLIMIT_MODERATE) - SN_EXPORT_UINT32(crypto_pwhash_MEMLIMIT_MODERATE, crypto_pwhash_MEMLIMIT_MODERATE) - SN_EXPORT_UINT32(crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_OPSLIMIT_SENSITIVE) - SN_EXPORT_UINT32(crypto_pwhash_MEMLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE) - SN_EXPORT_STRING(crypto_pwhash_PRIMITIVE, crypto_pwhash_PRIMITIVE) - - SN_EXPORT_FUNCTION(crypto_pwhash_scryptsalsa208sha256, sn_crypto_pwhash_scryptsalsa208sha256) - SN_EXPORT_FUNCTION(crypto_pwhash_scryptsalsa208sha256_str, sn_crypto_pwhash_scryptsalsa208sha256_str) - SN_EXPORT_FUNCTION(crypto_pwhash_scryptsalsa208sha256_str_verify, sn_crypto_pwhash_scryptsalsa208sha256_str_verify) - SN_EXPORT_FUNCTION(crypto_pwhash_scryptsalsa208sha256_str_needs_rehash, sn_crypto_pwhash_scryptsalsa208sha256_str_needs_rehash) - SN_EXPORT_FUNCTION(crypto_pwhash_scryptsalsa208sha256_async, sn_crypto_pwhash_scryptsalsa208sha256_async) - SN_EXPORT_FUNCTION(crypto_pwhash_scryptsalsa208sha256_str_async, sn_crypto_pwhash_scryptsalsa208sha256_str_async) - SN_EXPORT_FUNCTION(crypto_pwhash_scryptsalsa208sha256_str_verify_async, sn_crypto_pwhash_scryptsalsa208sha256_str_verify_async) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_BYTES_MIN, crypto_pwhash_scryptsalsa208sha256_BYTES_MIN) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_BYTES_MAX, crypto_pwhash_scryptsalsa208sha256_BYTES_MAX) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_PASSWD_MIN, crypto_pwhash_scryptsalsa208sha256_PASSWD_MIN) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_PASSWD_MAX, crypto_pwhash_scryptsalsa208sha256_PASSWD_MAX) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_SALTBYTES, crypto_pwhash_scryptsalsa208sha256_SALTBYTES) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_STRBYTES, crypto_pwhash_scryptsalsa208sha256_STRBYTES) - SN_EXPORT_STRING(crypto_pwhash_scryptsalsa208sha256_STRPREFIX, crypto_pwhash_scryptsalsa208sha256_STRPREFIX) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN, crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX, crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE, crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE, crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE) - SN_EXPORT_UINT32(crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE, crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE) - - // crypto_scalarmult - - SN_EXPORT_FUNCTION(crypto_scalarmult_base, sn_crypto_scalarmult_base) - SN_EXPORT_FUNCTION(crypto_scalarmult, sn_crypto_scalarmult) - SN_EXPORT_STRING(crypto_scalarmult_PRIMITIVE, crypto_scalarmult_PRIMITIVE) - SN_EXPORT_UINT32(crypto_scalarmult_BYTES, crypto_scalarmult_BYTES) - SN_EXPORT_UINT32(crypto_scalarmult_SCALARBYTES, crypto_scalarmult_SCALARBYTES) - - SN_EXPORT_FUNCTION(crypto_scalarmult_ed25519_base, sn_crypto_scalarmult_ed25519_base) - SN_EXPORT_FUNCTION(crypto_scalarmult_ed25519, sn_crypto_scalarmult_ed25519) - SN_EXPORT_FUNCTION(crypto_scalarmult_ed25519_base_noclamp, sn_crypto_scalarmult_ed25519_base_noclamp) - SN_EXPORT_FUNCTION(crypto_scalarmult_ed25519_noclamp, sn_crypto_scalarmult_ed25519_noclamp) - SN_EXPORT_UINT32(crypto_scalarmult_ed25519_BYTES, crypto_scalarmult_ed25519_BYTES) - SN_EXPORT_UINT32(crypto_scalarmult_ed25519_SCALARBYTES, crypto_scalarmult_ed25519_SCALARBYTES) - - // crypto_secretbox - - SN_EXPORT_FUNCTION(crypto_secretbox_easy, sn_crypto_secretbox_easy) - SN_EXPORT_FUNCTION(crypto_secretbox_open_easy, sn_crypto_secretbox_open_easy) - SN_EXPORT_FUNCTION(crypto_secretbox_detached, sn_crypto_secretbox_detached) - SN_EXPORT_FUNCTION(crypto_secretbox_open_detached, sn_crypto_secretbox_open_detached) - SN_EXPORT_UINT32(crypto_secretbox_KEYBYTES, crypto_secretbox_KEYBYTES) - SN_EXPORT_UINT32(crypto_secretbox_NONCEBYTES, crypto_secretbox_NONCEBYTES) - SN_EXPORT_UINT32(crypto_secretbox_MACBYTES, crypto_secretbox_MACBYTES) - SN_EXPORT_STRING(crypto_secretbox_PRIMITIVE, crypto_secretbox_PRIMITIVE) - - // crypto_secretstream - - SN_EXPORT_FUNCTION(crypto_secretstream_xchacha20poly1305_keygen, sn_crypto_secretstream_xchacha20poly1305_keygen) - SN_EXPORT_FUNCTION(crypto_secretstream_xchacha20poly1305_init_push, sn_crypto_secretstream_xchacha20poly1305_init_push) - SN_EXPORT_FUNCTION(crypto_secretstream_xchacha20poly1305_init_pull, sn_crypto_secretstream_xchacha20poly1305_init_pull) - SN_EXPORT_FUNCTION(crypto_secretstream_xchacha20poly1305_push, sn_crypto_secretstream_xchacha20poly1305_push) - SN_EXPORT_FUNCTION(crypto_secretstream_xchacha20poly1305_pull, sn_crypto_secretstream_xchacha20poly1305_pull) - SN_EXPORT_FUNCTION(crypto_secretstream_xchacha20poly1305_rekey, sn_crypto_secretstream_xchacha20poly1305_rekey) - SN_EXPORT_UINT32(crypto_secretstream_xchacha20poly1305_STATEBYTES, sizeof(crypto_secretstream_xchacha20poly1305_state)) - SN_EXPORT_UINT32(crypto_secretstream_xchacha20poly1305_ABYTES, crypto_secretstream_xchacha20poly1305_ABYTES) - SN_EXPORT_UINT32(crypto_secretstream_xchacha20poly1305_HEADERBYTES, crypto_secretstream_xchacha20poly1305_HEADERBYTES) - SN_EXPORT_UINT32(crypto_secretstream_xchacha20poly1305_KEYBYTES, crypto_secretstream_xchacha20poly1305_KEYBYTES) - SN_EXPORT_UINT32(crypto_secretstream_xchacha20poly1305_TAGBYTES, 1) - SN_EXPORT_UINT64(crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX, crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX) - SN_EXPORT_UINT32(crypto_secretstream_xchacha20poly1305_TAG_MESSAGE, crypto_secretstream_xchacha20poly1305_TAG_MESSAGE) - SN_EXPORT_UINT32(crypto_secretstream_xchacha20poly1305_TAG_PUSH, crypto_secretstream_xchacha20poly1305_TAG_PUSH) - SN_EXPORT_UINT32(crypto_secretstream_xchacha20poly1305_TAG_REKEY, crypto_secretstream_xchacha20poly1305_TAG_REKEY) - SN_EXPORT_UINT32(crypto_secretstream_xchacha20poly1305_TAG_FINAL, crypto_secretstream_xchacha20poly1305_TAG_FINAL) - - // crypto_shorthash - - SN_EXPORT_FUNCTION(crypto_shorthash, sn_crypto_shorthash) - SN_EXPORT_UINT32(crypto_shorthash_BYTES, crypto_shorthash_BYTES) - SN_EXPORT_UINT32(crypto_shorthash_KEYBYTES, crypto_shorthash_KEYBYTES) - SN_EXPORT_STRING(crypto_shorthash_PRIMITIVE, crypto_shorthash_PRIMITIVE) - - // crypto_sign - - SN_EXPORT_FUNCTION(crypto_sign_keypair, sn_crypto_sign_keypair) - SN_EXPORT_FUNCTION(crypto_sign_seed_keypair, sn_crypto_sign_seed_keypair) - SN_EXPORT_FUNCTION(crypto_sign, sn_crypto_sign) - SN_EXPORT_FUNCTION(crypto_sign_open, sn_crypto_sign_open) - SN_EXPORT_FUNCTION(crypto_sign_detached, sn_crypto_sign_detached) - SN_EXPORT_FUNCTION(crypto_sign_verify_detached, sn_crypto_sign_verify_detached) - SN_EXPORT_FUNCTION(crypto_sign_ed25519_sk_to_pk, sn_crypto_sign_ed25519_sk_to_pk) - SN_EXPORT_FUNCTION(crypto_sign_ed25519_pk_to_curve25519, sn_crypto_sign_ed25519_pk_to_curve25519) - SN_EXPORT_FUNCTION(crypto_sign_ed25519_sk_to_curve25519, sn_crypto_sign_ed25519_sk_to_curve25519) - SN_EXPORT_UINT32(crypto_sign_SEEDBYTES, crypto_sign_SEEDBYTES) - SN_EXPORT_UINT32(crypto_sign_PUBLICKEYBYTES, crypto_sign_PUBLICKEYBYTES) - SN_EXPORT_UINT32(crypto_sign_SECRETKEYBYTES, crypto_sign_SECRETKEYBYTES) - SN_EXPORT_UINT32(crypto_sign_BYTES, crypto_sign_BYTES) - - // crypto_stream - - SN_EXPORT_FUNCTION(crypto_stream, sn_crypto_stream) - SN_EXPORT_UINT32(crypto_stream_KEYBYTES, crypto_stream_KEYBYTES) - SN_EXPORT_UINT32(crypto_stream_NONCEBYTES, crypto_stream_NONCEBYTES) - SN_EXPORT_STRING(crypto_stream_PRIMITIVE, crypto_stream_PRIMITIVE) - - SN_EXPORT_FUNCTION(crypto_stream_xor, sn_crypto_stream_xor) - SN_EXPORT_FUNCTION(crypto_stream_xor_init, sn_crypto_stream_xor_wrap_init) - SN_EXPORT_FUNCTION(crypto_stream_xor_update, sn_crypto_stream_xor_wrap_update) - SN_EXPORT_FUNCTION(crypto_stream_xor_final, sn_crypto_stream_xor_wrap_final) - SN_EXPORT_UINT32(crypto_stream_xor_STATEBYTES, sizeof(sn_crypto_stream_xor_state)) - - SN_EXPORT_FUNCTION(crypto_stream_chacha20, sn_crypto_stream_chacha20) - SN_EXPORT_UINT32(crypto_stream_chacha20_KEYBYTES, crypto_stream_chacha20_KEYBYTES) - SN_EXPORT_UINT32(crypto_stream_chacha20_NONCEBYTES, crypto_stream_chacha20_NONCEBYTES) - SN_EXPORT_UINT64(crypto_stream_chacha20_MESSAGEBYTES_MAX, crypto_stream_chacha20_MESSAGEBYTES_MAX) - - SN_EXPORT_FUNCTION(crypto_stream_chacha20_xor, sn_crypto_stream_chacha20_xor) - SN_EXPORT_FUNCTION(crypto_stream_chacha20_xor_ic, sn_crypto_stream_chacha20_xor_ic) - SN_EXPORT_FUNCTION(crypto_stream_chacha20_xor_init, sn_crypto_stream_chacha20_xor_wrap_init) - SN_EXPORT_FUNCTION(crypto_stream_chacha20_xor_update, sn_crypto_stream_chacha20_xor_wrap_update) - SN_EXPORT_FUNCTION(crypto_stream_chacha20_xor_final, sn_crypto_stream_chacha20_xor_wrap_final) - SN_EXPORT_UINT32(crypto_stream_chacha20_xor_STATEBYTES, sizeof(sn_crypto_stream_chacha20_xor_state)) - - SN_EXPORT_FUNCTION(crypto_stream_chacha20_ietf, sn_crypto_stream_chacha20_ietf) - SN_EXPORT_UINT32(crypto_stream_chacha20_ietf_KEYBYTES, crypto_stream_chacha20_ietf_KEYBYTES) - SN_EXPORT_UINT32(crypto_stream_chacha20_ietf_NONCEBYTES, crypto_stream_chacha20_ietf_NONCEBYTES) - SN_EXPORT_UINT64(crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX, crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX) - SN_EXPORT_UINT32(crypto_stream_chacha20_ietf_xor_STATEBYTES, sizeof(sn_crypto_stream_chacha20_ietf_xor_state)) - - SN_EXPORT_FUNCTION(crypto_stream_chacha20_ietf_xor, sn_crypto_stream_chacha20_ietf_xor) - SN_EXPORT_FUNCTION(crypto_stream_chacha20_ietf_xor_ic, sn_crypto_stream_chacha20_ietf_xor_ic) - SN_EXPORT_FUNCTION(crypto_stream_chacha20_ietf_xor_init, sn_crypto_stream_chacha20_ietf_xor_wrap_init) - SN_EXPORT_FUNCTION(crypto_stream_chacha20_ietf_xor_update, sn_crypto_stream_chacha20_ietf_xor_wrap_update) - SN_EXPORT_FUNCTION(crypto_stream_chacha20_ietf_xor_final, sn_crypto_stream_chacha20_ietf_xor_wrap_final) - - SN_EXPORT_FUNCTION(crypto_stream_xchacha20, sn_crypto_stream_xchacha20) - SN_EXPORT_UINT32(crypto_stream_xchacha20_KEYBYTES, crypto_stream_xchacha20_KEYBYTES) - SN_EXPORT_UINT32(crypto_stream_xchacha20_NONCEBYTES, crypto_stream_xchacha20_NONCEBYTES) - SN_EXPORT_UINT64(crypto_stream_xchacha20_MESSAGEBYTES_MAX, crypto_stream_xchacha20_MESSAGEBYTES_MAX) - - SN_EXPORT_FUNCTION(crypto_stream_xchacha20_xor, sn_crypto_stream_xchacha20_xor) - SN_EXPORT_FUNCTION(crypto_stream_xchacha20_xor_ic, sn_crypto_stream_xchacha20_xor_ic) - SN_EXPORT_FUNCTION(crypto_stream_xchacha20_xor_init, sn_crypto_stream_xchacha20_xor_wrap_init) - SN_EXPORT_FUNCTION(crypto_stream_xchacha20_xor_update, sn_crypto_stream_xchacha20_xor_wrap_update) - SN_EXPORT_FUNCTION(crypto_stream_xchacha20_xor_final, sn_crypto_stream_xchacha20_xor_wrap_final) - SN_EXPORT_FUNCTION(crypto_stream_xchacha20, sn_crypto_stream_xchacha20) - SN_EXPORT_UINT32(crypto_stream_xchacha20_xor_STATEBYTES, sizeof(sn_crypto_stream_xchacha20_xor_state)) - - SN_EXPORT_FUNCTION(crypto_stream_salsa20, sn_crypto_stream_salsa20) - SN_EXPORT_UINT32(crypto_stream_salsa20_KEYBYTES, crypto_stream_salsa20_KEYBYTES) - SN_EXPORT_UINT32(crypto_stream_salsa20_NONCEBYTES, crypto_stream_salsa20_NONCEBYTES) - SN_EXPORT_UINT64(crypto_stream_salsa20_MESSAGEBYTES_MAX, crypto_stream_salsa20_MESSAGEBYTES_MAX) - - SN_EXPORT_FUNCTION(crypto_stream_salsa20_xor, sn_crypto_stream_salsa20_xor) - SN_EXPORT_FUNCTION(crypto_stream_salsa20_xor_ic, sn_crypto_stream_salsa20_xor_ic) - SN_EXPORT_FUNCTION(crypto_stream_salsa20_xor_init, sn_crypto_stream_salsa20_xor_wrap_init) - SN_EXPORT_FUNCTION(crypto_stream_salsa20_xor_update, sn_crypto_stream_salsa20_xor_wrap_update) - SN_EXPORT_FUNCTION(crypto_stream_salsa20_xor_final, sn_crypto_stream_salsa20_xor_wrap_final) - SN_EXPORT_UINT32(crypto_stream_salsa20_xor_STATEBYTES, sizeof(sn_crypto_stream_salsa20_xor_state)) - - // extensions - - // tweak - - SN_EXPORT_FUNCTION(extension_tweak_ed25519_base, sn_extension_tweak_ed25519_base) - SN_EXPORT_FUNCTION(extension_tweak_ed25519_sign_detached, sn_extension_tweak_ed25519_sign_detached) - SN_EXPORT_FUNCTION(extension_tweak_ed25519_sk_to_scalar, sn_extension_tweak_ed25519_sk_to_scalar) - SN_EXPORT_FUNCTION(extension_tweak_ed25519_scalar, sn_extension_tweak_ed25519_scalar) - SN_EXPORT_FUNCTION(extension_tweak_ed25519_pk, sn_extension_tweak_ed25519_pk) - SN_EXPORT_FUNCTION(extension_tweak_ed25519_keypair, sn_extension_tweak_ed25519_keypair) - SN_EXPORT_FUNCTION(extension_tweak_ed25519_scalar_add, sn_extension_tweak_ed25519_scalar_add) - SN_EXPORT_FUNCTION(extension_tweak_ed25519_pk_add, sn_extension_tweak_ed25519_pk_add) - SN_EXPORT_FUNCTION(extension_tweak_ed25519_keypair_add, sn_extension_tweak_ed25519_keypair_add) - SN_EXPORT_UINT32(extension_tweak_ed25519_BYTES, sn__extension_tweak_ed25519_BYTES) - SN_EXPORT_UINT32(extension_tweak_ed25519_SCALARBYTES, sn__extension_tweak_ed25519_SCALARBYTES) - - // pbkdf2 - - SN_EXPORT_FUNCTION(extension_pbkdf2_sha512, sn_extension_pbkdf2_sha512) - SN_EXPORT_FUNCTION(extension_pbkdf2_sha512_async, sn_extension_pbkdf2_sha512_async) - SN_EXPORT_UINT32(extension_pbkdf2_sha512_SALTBYTES, sn__extension_pbkdf2_sha512_SALTBYTES) - SN_EXPORT_UINT32(extension_pbkdf2_sha512_HASHBYTES, sn__extension_pbkdf2_sha512_HASHBYTES) - SN_EXPORT_UINT32(extension_pbkdf2_sha512_ITERATIONS_MIN, sn__extension_pbkdf2_sha512_ITERATIONS_MIN) - SN_EXPORT_UINT64(extension_pbkdf2_sha512_BYTES_MAX, sn__extension_pbkdf2_sha512_BYTES_MAX) - - return exports; -} - -static napi_value Init(napi_env env, napi_value exports) { - return create_sodium_native(env); -} - -NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/node_modules/sodium-native/extensions/pbkdf2/pbkdf2.c b/node_modules/sodium-native/extensions/pbkdf2/pbkdf2.c deleted file mode 100644 index c1bad30..0000000 --- a/node_modules/sodium-native/extensions/pbkdf2/pbkdf2.c +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * Copyright 2005,2007,2009 Colin Percival - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Adapted from libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf-sha256.c - */ - -#include -#include - -#include "pbkdf2.h" - -/** - * pbkdf2_sha512(passwd, passwdlen, salt, saltlen, c, buf, dkLen): - * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and - * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). - */ -int -sn__extension_pbkdf2_sha512(const unsigned char *passwd, size_t passwdlen, - const unsigned char *salt, size_t saltlen, uint64_t c, - unsigned char *buf, size_t dkLen) -{ - crypto_auth_hmacsha512_state PShctx, hctx; - size_t i; - unsigned char ivec[4]; - unsigned char U[64]; - unsigned char T[64]; - uint64_t j; - unsigned int k; - size_t clen; - - if (dkLen > sn__extension_pbkdf2_sha512_BYTES_MAX) { - return -1; - } - - crypto_auth_hmacsha512_init(&PShctx, passwd, passwdlen); - crypto_auth_hmacsha512_update(&PShctx, salt, saltlen); - - for (i = 0; i * crypto_auth_hmacsha512_BYTES < dkLen; i++) { - SN_PBKDF2_STORE32_BE(ivec, (uint32_t)(i + 1)); - memcpy(&hctx, &PShctx, sizeof(crypto_auth_hmacsha512_state)); - crypto_auth_hmacsha512_update(&hctx, ivec, 4); - crypto_auth_hmacsha512_final(&hctx, U); - - memcpy(T, U, crypto_auth_hmacsha512_BYTES); - /* LCOV_EXCL_START */ - for (j = 2; j <= c; j++) { - crypto_auth_hmacsha512_init(&hctx, passwd, passwdlen); - crypto_auth_hmacsha512_update(&hctx, U, crypto_auth_hmacsha512_BYTES); - crypto_auth_hmacsha512_final(&hctx, U); - - for (k = 0; k < crypto_auth_hmacsha512_BYTES; k++) { - T[k] ^= U[k]; - } - } - /* LCOV_EXCL_STOP */ - - clen = dkLen - i * crypto_auth_hmacsha512_BYTES; - if (clen > crypto_auth_hmacsha512_BYTES) { - clen = crypto_auth_hmacsha512_BYTES; - } - memcpy(&buf[i * crypto_auth_hmacsha512_BYTES], T, clen); - } - sodium_memzero((void *) &PShctx, sizeof PShctx); - - return 0; -} diff --git a/node_modules/sodium-native/extensions/pbkdf2/pbkdf2.h b/node_modules/sodium-native/extensions/pbkdf2/pbkdf2.h deleted file mode 100644 index 562d34f..0000000 --- a/node_modules/sodium-native/extensions/pbkdf2/pbkdf2.h +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * Copyright 2005,2007,2009 Colin Percival - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -/* - * Adapted from libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf-sha256.c - */ - -#include - -#define SN_PBKDF2_STORE32_BE(buf, n32) \ - buf[0] = n32 >> 24 & 0xff; \ - buf[1] = n32 >> 16 & 0xff; \ - buf[2] = n32 >> 8 & 0xff; \ - buf[3] = n32 >> 0 & 0xff; - -#define sn__extension_pbkdf2_sha512_SALTBYTES 16U - -#define sn__extension_pbkdf2_sha512_HASHBYTES crypto_hash_sha512_BYTES - -#define sn__extension_pbkdf2_sha512_ITERATIONS_MIN 1U - -#define sn__extension_pbkdf2_sha512_BYTES_MAX 0x3fffffffc0ULL - -/** - * extension_pbkdf2_sha512(passwd, passwdlen, salt, saltlen, c, buf, dkLen): - * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and - * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). - */ -int sn__extension_pbkdf2_sha512(const unsigned char *, size_t, const unsigned char *, size_t, - uint64_t, unsigned char *, size_t); diff --git a/node_modules/sodium-native/extensions/tweak/tweak.c b/node_modules/sodium-native/extensions/tweak/tweak.c deleted file mode 100644 index a4813a0..0000000 --- a/node_modules/sodium-native/extensions/tweak/tweak.c +++ /dev/null @@ -1,206 +0,0 @@ -#include "tweak.h" - -/* - *EXPERIMENTAL API* - - This module is an experimental implementation of a key tweaking protocol - over ed25519 keys. The signature algorithm has been reimplemented from - libsodium, but the nonce generation algorithm is *non-standard*. - - Use at your own risk -*/ - -static void _extension_tweak_nonce (unsigned char *nonce, const unsigned char *n, - const unsigned char *m, unsigned long long mlen) -{ - // dom2(x, y) with x = 0 (not prehashed) and y = "crypto_tweak_ed25519" - static const unsigned char TWEAK_PREFIX[32 + 2 + 20] = { - 'S', 'i', 'g', 'E', 'd', '2', '5', '5', '1', '9', ' ', - 'n', 'o', ' ', 'E', 'd', '2', '5', '5', '1', '9', ' ', - 'c', 'o', 'l', 'l', 'i', 's', 'i', 'o', 'n', 's', 0, - 20, 'c', 'r', 'y', 'p', 't', 'o', '_', 't', 'w', 'e', - 'a', 'k', '_', 'e', 'd', '2', '5', '5', '1', '9' - }; - - crypto_hash_sha512_state hs; - - crypto_hash_sha512_init(&hs); - crypto_hash_sha512_update(&hs, TWEAK_PREFIX, sizeof TWEAK_PREFIX); - crypto_hash_sha512_update(&hs, n, 32); - crypto_hash_sha512_update(&hs, m, mlen); - crypto_hash_sha512_final(&hs, nonce); -} - -static inline void -_crypto_sign_ed25519_clamp(unsigned char k[32]) -{ - k[0] &= 248; - k[31] &= 127; - k[31] |= 64; -} - -static void _extension_tweak_ed25519(unsigned char *q, unsigned char *n, - const unsigned char *ns, unsigned long long nslen) -{ - sodium_memzero(q, sizeof q); - - crypto_hash(n, ns, nslen); - n[31] &= 127; // clear highest bit - - crypto_scalarmult_ed25519_base_noclamp(q, n); - - // hash tweak until we get a valid tweaked q - while (crypto_core_ed25519_is_valid_point(q) != 1) { - crypto_hash(n, n, 32); - n[31] &= 127; // clear highest bit - - crypto_scalarmult_ed25519_base_noclamp(q, n); - } -} - -void sn__extension_tweak_ed25519_base(unsigned char *pk, unsigned char *scalar, - const unsigned char *ns, unsigned long long nslen) -{ - unsigned char n64[64]; - - _extension_tweak_ed25519(pk, n64, ns, nslen); - - SN_TWEAK_COPY_32(scalar, n64) -} - -int sn__extension_tweak_ed25519_sign_detached(unsigned char *sig, unsigned long long *siglen_p, - const unsigned char *m, unsigned long long mlen, - const unsigned char *n, unsigned char *pk) -{ - crypto_hash_sha512_state hs; - - unsigned char nonce[64]; - unsigned char R[32]; - unsigned char hram[64]; - unsigned char _pk[32]; - - // check if pk was passed - if (pk == NULL) { - pk = _pk; - - // derive pk from scalar - if (crypto_scalarmult_ed25519_base_noclamp(pk, n) != 0) { - return -1; - } - } - - _extension_tweak_nonce(nonce, n, m, mlen); - crypto_core_ed25519_scalar_reduce(nonce, nonce); - - // R = G ^ nonce : curve point from nonce - if (crypto_scalarmult_ed25519_base_noclamp(R, nonce) != 0) { - return -1; - } - - // generate challenge as h(ram) = hash(R, pk, message) - crypto_hash_sha512_init(&hs); - crypto_hash_sha512_update(&hs, R, 32); - crypto_hash_sha512_update(&hs, pk, 32); - crypto_hash_sha512_update(&hs, m, mlen); - - crypto_hash_sha512_final(&hs, hram); - - crypto_core_ed25519_scalar_reduce(hram, hram); - - // sig = nonce + n * h(ram) - crypto_core_ed25519_scalar_mul(sig, hram, n); - crypto_core_ed25519_scalar_add(sig + 32, nonce, sig); - - SN_TWEAK_COPY_32(sig, R) - - if (siglen_p != NULL) { - *siglen_p = 64U; - } - - return 0; -} - -// tweak a secret key -void sn__extension_tweak_ed25519_sk_to_scalar(unsigned char *n, const unsigned char *sk) -{ - unsigned char n64[64]; - - // get sk scalar from seed, cf. crypto_sign_keypair_seed - crypto_hash(n64, sk, 32); - _crypto_sign_ed25519_clamp(n64); - - SN_TWEAK_COPY_32(n, n64) -} - -// tweak a secret key -void sn__extension_tweak_ed25519_scalar(unsigned char *scalar_out, - const unsigned char *scalar, - const unsigned char *ns, - unsigned long long nslen) -{ - unsigned char n[64]; - unsigned char q[32]; - - _extension_tweak_ed25519(q, n, ns, nslen); - crypto_core_ed25519_scalar_add(scalar_out, scalar, n); -} - -// tweak a public key -int sn__extension_tweak_ed25519_pk(unsigned char *tpk, - const unsigned char *pk, - const unsigned char *ns, - unsigned long long nslen) -{ - unsigned char n[64]; - unsigned char q[32]; - - _extension_tweak_ed25519(q, n, ns, nslen); - return crypto_core_ed25519_add(tpk, q, pk); -} - - -void sn__extension_tweak_ed25519_keypair(unsigned char *pk, unsigned char *scalar_out, - unsigned char *scalar, const unsigned char *ns, - unsigned long long nslen) -{ - unsigned char n64[64]; - - crypto_hash(n64, ns, nslen); - n64[31] &= 127; // clear highest bit - - sn__extension_tweak_ed25519_scalar_add(scalar_out, scalar, n64); - crypto_scalarmult_ed25519_base_noclamp(pk, scalar_out); - - // hash tweak until we get a valid tweaked point - while (crypto_core_ed25519_is_valid_point(pk) != 1) { - crypto_hash(n64, n64, 32); - n64[31] &= 127; // clear highest bit - - sn__extension_tweak_ed25519_scalar_add(scalar_out, scalar, n64); - crypto_scalarmult_ed25519_base_noclamp(pk, scalar_out); - } -} - -// add tweak to scalar -void sn__extension_tweak_ed25519_scalar_add(unsigned char *scalar_out, - const unsigned char *scalar, - const unsigned char *n) -{ - crypto_core_ed25519_scalar_add(scalar_out, scalar, n); -} - -// add tweak point to public key -int sn__extension_tweak_ed25519_pk_add(unsigned char *tpk, - const unsigned char *pk, - const unsigned char *q) -{ - return crypto_core_ed25519_add(tpk, pk, q); -} - - -int sn__extension_tweak_ed25519_keypair_add(unsigned char *pk, unsigned char *scalar_out, - unsigned char *scalar, const unsigned char *tweak) -{ - sn__extension_tweak_ed25519_scalar_add(scalar_out, scalar, tweak); - return crypto_scalarmult_ed25519_base_noclamp(pk, scalar_out); -} \ No newline at end of file diff --git a/node_modules/sodium-native/extensions/tweak/tweak.h b/node_modules/sodium-native/extensions/tweak/tweak.h deleted file mode 100644 index 2fdb6ca..0000000 --- a/node_modules/sodium-native/extensions/tweak/tweak.h +++ /dev/null @@ -1,54 +0,0 @@ -#include - -// copy 32 bytes using int64_t pointers -#define SN_TWEAK_COPY_32(a, b) \ - { \ - long long *dst = (long long *) a; \ - long long *src = (long long *) b; \ - dst[0] = src[0]; \ - dst[1] = src[1]; \ - dst[2] = src[2]; \ - dst[3] = src[3]; \ - } - -#define sn__extension_tweak_ed25519_BYTES crypto_sign_ed25519_PUBLICKEYBYTES - -#define sn__extension_tweak_ed25519_SCALARBYTES crypto_scalarmult_ed25519_SCALARBYTES - -int sn__extension_tweak_ed25519_sign_detached(unsigned char *sig, unsigned long long *siglen_p, - const unsigned char *m, unsigned long long mlen, - const unsigned char *n, unsigned char *pk); - -void sn__extension_tweak_ed25519_base(unsigned char *pk, unsigned char *scalar, - const unsigned char *ns, unsigned long long nslen); - -void sn__extension_tweak_ed25519_sk_to_scalar(unsigned char *scalar, const unsigned char *sk); - -// tweak a secret key -void sn__extension_tweak_ed25519_scalar(unsigned char *scalar_out, - const unsigned char *scalar, - const unsigned char *ns, - unsigned long long nslen); - -// tweak a public key -int sn__extension_tweak_ed25519_pk(unsigned char *tpk, - const unsigned char *pk, - const unsigned char *ns, - unsigned long long nslen); - -void sn__extension_tweak_ed25519_keypair(unsigned char *pk, unsigned char *scalar_out, - unsigned char *scalar, const unsigned char *ns, - unsigned long long nslen); - -// add tweak scalar to private key -void sn__extension_tweak_ed25519_scalar_add(unsigned char *scalar_out, - const unsigned char *scalar, - const unsigned char *n); - -// add tweak point to public key -int sn__extension_tweak_ed25519_pk_add(unsigned char *tpk, - const unsigned char *pk, - const unsigned char *q); - -int sn__extension_tweak_ed25519_keypair_add(unsigned char *pk, unsigned char *scalar_out, - unsigned char *scalar, const unsigned char *tweak); diff --git a/node_modules/sodium-native/index.js b/node_modules/sodium-native/index.js deleted file mode 100644 index 6f7d6f0..0000000 --- a/node_modules/sodium-native/index.js +++ /dev/null @@ -1,3 +0,0 @@ -require.addon = require('require-addon') - -module.exports = require.addon('.', __filename) diff --git a/node_modules/sodium-native/macros.h b/node_modules/sodium-native/macros.h deleted file mode 100644 index 4d5003b..0000000 --- a/node_modules/sodium-native/macros.h +++ /dev/null @@ -1,319 +0,0 @@ -#define SN_STATUS_THROWS(call, message) \ - if ((call) != napi_ok) { \ - napi_throw_error(env, NULL, message); \ - return NULL; \ - } - -#define SN_STATUS_THROWS_VOID(call, message) \ - if ((call) != napi_ok) { \ - napi_throw_error(env, NULL, message); \ - return; \ - } - -#define SN_THROWS(condition, message) \ - if ((condition)) { \ - napi_throw_error(env, NULL, message); \ - return NULL; \ - } - -#define SN_BUFFER_CAST(type, name, val) \ - type name; \ - size_t name##_size; \ - SN_STATUS_THROWS(napi_get_buffer_info(env, val, (void **) &name, &name##_size), "") - -#define SN_TYPE_ASSERT(name, var, type, message) \ - napi_valuetype name##_valuetype; \ - SN_STATUS_THROWS(napi_typeof(env, var, &name##_valuetype), ""); \ - if (name##_valuetype != type) { \ - napi_throw_type_error(env, NULL, message); \ - return NULL; \ - } - -#define SN_TYPEDARRAY_ASSERT(name, var, message) \ - bool name##_is_typedarray; \ - SN_STATUS_THROWS(napi_is_typedarray(env, var, &name##_is_typedarray), ""); \ - if (name##_is_typedarray != true) { \ - napi_throw_type_error(env, NULL, message); \ - return NULL; \ - } - -#define SN_ASSERT_MIN_LENGTH(length, constant, name) \ - SN_THROWS(length < constant, #name " must be at least " #constant " bytes long") - - -#define SN_ASSERT_MAX_LENGTH(length, constant, name) \ - SN_THROWS(length > constant, #name " must be at most " #constant " bytes long") - - -#define SN_ASSERT_LENGTH(length, constant, name) \ - SN_THROWS(length != constant, #name " must be " #constant " bytes long") - -#define SN_RANGE_THROWS(condition, message) \ - if (condition) { \ - napi_throw_range_error(env, NULL, message); \ - return NULL; \ - } - -#define SN_ARGV(n, method_name) \ - napi_value argv[n]; \ - size_t argc = n; \ - SN_STATUS_THROWS(napi_get_cb_info(env, info, &argc, argv, NULL, NULL), ""); \ - if (argc != n) { \ - napi_throw_type_error(env, NULL, #method_name " requires " #n " argument(s)"); \ - return NULL; \ - } - -#define SN_ARGV_OPTS(required, total, method_name) \ - napi_value argv[total]; \ - size_t argc = total; \ - SN_STATUS_THROWS(napi_get_cb_info(env, info, &argc, argv, NULL, NULL), ""); \ - if (argc < required) { \ - napi_throw_type_error(env, NULL, #method_name " requires at least " #required " argument(s)"); \ - return NULL; \ - } - -#define SN_EXPORT_FUNCTION(name, cb) \ - { \ - napi_value name##_fn; \ - SN_STATUS_THROWS(napi_create_function(env, #name, NAPI_AUTO_LENGTH, cb, NULL, &name##_fn), "") \ - SN_STATUS_THROWS(napi_set_named_property(env, exports, #name, name##_fn), "") \ - } - -#define SN_EXPORT_UINT32(name, num) \ - { \ - napi_value name##_num; \ - SN_STATUS_THROWS(napi_create_uint32(env, (uint32_t) num, &name##_num), "") \ - SN_STATUS_THROWS(napi_set_named_property(env, exports, #name, name##_num), "") \ - } - -#define SN_EXPORT_UINT64(name, num) \ - { \ - napi_value name##_num; \ - uint64_t max = 0x1fffffffffffffULL; \ - SN_STATUS_THROWS(napi_create_int64(env, (uint64_t) (max < num ? max : num), &name##_num), "") \ - SN_STATUS_THROWS(napi_set_named_property(env, exports, #name, name##_num), "") \ - } - -#define SN_EXPORT_STRING(name, string) \ - { \ - napi_value name##_string; \ - SN_STATUS_THROWS(napi_create_string_utf8(env, string, NAPI_AUTO_LENGTH, &name##_string), "") \ - SN_STATUS_THROWS(napi_set_named_property(env, exports, #name, name##_string), "") \ - } - -#define SN_ARGV_CHECK_NULL(name, index) \ - napi_valuetype name##_valuetype; \ - SN_STATUS_THROWS(napi_typeof(env, argv[index], &name##_valuetype), "") \ - bool name##_is_null = name##_valuetype == napi_null; - -#define SN_ARGV_OPTS_TYPEDARRAY(name, index) \ - napi_valuetype name##_valuetype; \ - void *name##_data = NULL; \ - size_t name##_size = 0; \ - SN_STATUS_THROWS(napi_typeof(env, argv[index], &name##_valuetype), "") \ - if (name##_valuetype != napi_null && name##_valuetype != napi_undefined) { \ - napi_value name##_argv = argv[index]; \ - SN_TYPEDARRAY_ASSERT(name, name##_argv, #name " must be an instance of TypedArray") \ - SN_OPT_TYPEDARRAY(name, name##_argv) \ - } - -#define SN_TYPEDARRAY(name, var) \ - napi_typedarray_type name##_type; \ - size_t name##_length; \ - void *name##_data; \ - napi_get_typedarray_info(env, (var), &name##_type, &name##_length, &name##_data, NULL, NULL); \ - uint8_t name##_width = typedarray_width(name##_type); \ - SN_THROWS(name##_width == 0, "Unexpected TypedArray type") \ - size_t name##_size = name##_length * name##_width; - -#define SN_TYPEDARRAY_PTR(name, var) \ - napi_typedarray_type name##_type; \ - size_t name##_length; \ - void *name##_data; \ - napi_get_typedarray_info(env, (var), &name##_type, &name##_length, &name##_data, NULL, NULL); \ - uint8_t name##_width = typedarray_width(name##_type); \ - SN_THROWS(name##_width == 0, "Unexpected TypedArray type") \ - -#define SN_OPT_TYPEDARRAY(name, var) \ - napi_typedarray_type name##_type; \ - size_t name##_length; \ - napi_get_typedarray_info(env, (var), &name##_type, &name##_length, &name##_data, NULL, NULL); \ - uint8_t name##_width = typedarray_width(name##_type); \ - SN_THROWS(name##_width == 0, "Unexpected TypedArray type") \ - name##_size = name##_length * name##_width; - -#define SN_UINT8(name, val) \ - uint32_t name##_int32; \ - if (napi_get_value_uint32(env, val, &name##_int32) != napi_ok) { \ - napi_throw_error(env, "EINVAL", "Expected number"); \ - return NULL; \ - } \ - SN_THROWS(name##_int32 > 255, "expect uint8") \ - unsigned char name = 0xff & name##_int32; - -#define SN_UINT32(name, val) \ - uint32_t name; \ - if (napi_get_value_uint32(env, val, &name) != napi_ok) { \ - napi_throw_error(env, "EINVAL", "Expected number"); \ - return NULL; \ - } - -#define SN_OPT_UINT32(name, val) \ - if (napi_get_value_uint32(env, val, (uint32_t *) &name) != napi_ok) { \ - napi_throw_error(env, "EINVAL", "Expected number"); \ - return NULL; \ - } - -#define SN_UINT64(name, val) \ - int64_t name##_i64; \ - if (napi_get_value_int64(env, val, &name##_i64) != napi_ok) { \ - napi_throw_error(env, "EINVAL", "Expected number"); \ - return NULL; \ - } \ - if (name##_i64 < 0) { \ - napi_throw_error(env, "EINVAL", "Expected positive number"); \ - return NULL; \ - } \ - uint64_t name = (uint64_t) name##_i64; - -#define SN_ARGV_TYPEDARRAY(name, index) \ - napi_value name##_argv = argv[index]; \ - SN_TYPEDARRAY_ASSERT(name, name##_argv, #name " must be an instance of TypedArray") \ - SN_TYPEDARRAY(name, name##_argv) - -#define SN_ARGV_TYPEDARRAY_PTR(name, index) \ - napi_value name##_argv = argv[index]; \ - SN_TYPEDARRAY_ASSERT(name, name##_argv, #name " must be an instance of TypedArray") \ - SN_TYPEDARRAY_PTR(name, name##_argv) - -#define SN_ARGV_BUFFER_CAST(type, name, index) \ - napi_value name##_argv = argv[index]; \ - SN_BUFFER_CAST(type, name, name##_argv) - -#define SN_OPT_ARGV_TYPEDARRAY(name, index) \ - napi_value name##_argv = argv[index]; \ - SN_TYPEDARRAY_ASSERT(name, name##_argv, #name " must be an instance of TypedArray") \ - SN_OPT_TYPEDARRAY(name, name##_argv) - -#define SN_ARGV_UINT8(name, index) \ - napi_value name##_argv = argv[index]; \ - SN_TYPE_ASSERT(name, name##_argv, napi_number, #name " must be an instance of Number") \ - SN_UINT8(name, name##_argv) - -#define SN_ARGV_UINT32(name, index) \ - napi_value name##_argv = argv[index]; \ - SN_TYPE_ASSERT(name, name##_argv, napi_number, #name " must be an instance of Number") \ - SN_UINT32(name, name##_argv) - -#define SN_ARGV_UINT64(name, index) \ - napi_value name##_argv = argv[index]; \ - SN_TYPE_ASSERT(name, name##_argv, napi_number, #name " must be an instance of Number") \ - SN_UINT64(name, name##_argv) - -#define SN_OPT_ARGV_UINT32(name, index) \ - napi_value name##_argv = argv[index]; \ - SN_TYPE_ASSERT(name, name##_argv, napi_number, #name " must be an instance of Number") \ - SN_OPT_UINT32(name, name##_argv) - -#define SN_CALL(call, message) \ - int success = call; \ - SN_THROWS(success != 0, message) - -#define SN_CALL_FUNCTION(env, ctx, cb, n, argv, res) \ - if (napi_make_callback(env, NULL, ctx, cb, n, argv, res) == napi_pending_exception) { \ - napi_value fatal_exception; \ - napi_get_and_clear_last_exception(env, &fatal_exception); \ - napi_fatal_exception(env, fatal_exception); \ - } - -#define SN_RETURN(call, message) \ - int success = call; \ - SN_THROWS(success != 0, message) \ - return NULL; - -#define SN_RETURN_BOOLEAN(call) \ - int success = call; \ - napi_value result; \ - SN_THROWS(napi_get_boolean(env, success == 0, &result) != napi_ok, "result not boolean") \ - return result; - -#define SN_RETURN_BOOLEAN_FROM_1(call) \ - int success = call; \ - napi_value result; \ - SN_THROWS(napi_get_boolean(env, success != 0, &result) != napi_ok, "result not boolean") \ - return result; - -#define SN_ASYNC_CHECK_FOR_ERROR(message) \ - if (req->n == 0) { \ - napi_get_null(req->env, &argv[0]); \ - } else { \ - napi_value err_msg; \ - napi_create_string_utf8(req->env, #message, NAPI_AUTO_LENGTH, &err_msg); \ - napi_create_error(req->env, NULL, err_msg, &argv[0]); \ - } - -#define SN_CALLBACK_CHECK_FOR_ERROR(message) \ - if (task->code == 0) { \ - napi_get_null(req->env, &argv[0]); \ - } else { \ - napi_value err_msg; \ - napi_create_string_utf8(req->env, #message, NAPI_AUTO_LENGTH, &err_msg); \ - napi_create_error(req->env, NULL, err_msg, &argv[0]); \ - } - -#define SN_QUEUE_WORK(req, execute, complete) \ - uv_loop_t *loop; \ - napi_get_uv_event_loop(env, &loop); \ - uv_queue_work(loop, (uv_work_t *) req, execute, complete); - -#define SN_QUEUE_TASK(task, execute, complete) \ - uv_loop_t *loop; \ - napi_get_uv_event_loop(env, &loop); \ - uv_queue_work(loop, (uv_work_t *) task, execute, complete); - -#define SN_ASYNC_TASK(cb_pos) \ - task->req = (void *) req; \ - napi_value promise; \ - if (argc > cb_pos) { \ - task->type = sn_async_task_callback; \ - promise = NULL; \ - napi_value cb = argv[cb_pos]; \ - napi_valuetype type; \ - SN_STATUS_THROWS(napi_typeof(env, cb, &type), "") \ - if (type != napi_function) { \ - napi_throw_error(env, "EINVAL", "Callback must be a function"); \ - return NULL; \ - } \ - SN_STATUS_THROWS(napi_create_reference(env, cb, 1, &task->cb), "") \ - } else { \ - task->type = sn_async_task_promise; \ - napi_create_promise(env, &task->deferred, &promise); \ - } - -#define SN_ASYNC_COMPLETE(message) \ - napi_value argv[1]; \ - switch (task->type) { \ - case sn_async_task_promise: { \ - if (task->code == 0) { \ - napi_get_null(req->env, &argv[0]); \ - napi_resolve_deferred(req->env, task->deferred, argv[0]); \ - } else { \ - napi_value err_msg; \ - napi_create_string_utf8(req->env, #message, NAPI_AUTO_LENGTH, &err_msg); \ - napi_create_error(req->env, NULL, err_msg, &argv[0]); \ - napi_reject_deferred(req->env, task->deferred, argv[0]); \ - } \ - task->deferred = NULL; \ - break; \ - } \ - case sn_async_task_callback: { \ - SN_CALLBACK_CHECK_FOR_ERROR(#message) \ - napi_value callback; \ - napi_get_reference_value(req->env, task->cb, &callback); \ - napi_value return_val; \ - SN_CALL_FUNCTION(req->env, global, callback, 1, argv, &return_val) \ - napi_close_handle_scope(req->env, scope); \ - napi_delete_reference(req->env, task->cb); \ - break; \ - } \ - } diff --git a/node_modules/sodium-native/package.json b/node_modules/sodium-native/package.json deleted file mode 100644 index 3fa2611..0000000 --- a/node_modules/sodium-native/package.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "name": "sodium-native", - "version": "4.3.3", - "description": "Low level bindings for libsodium", - "main": "index.js", - "files": [ - "index.js", - "binding.c", - "macros.h", - "extensions", - "prebuilds", - "CMakeLists.txt" - ], - "addon": true, - "dependencies": { - "require-addon": "^1.1.0" - }, - "devDependencies": { - "brittle": "^3.5.0", - "cmake-bare": "^1.1.10", - "cmake-fetch": "^1.0.1", - "cmake-napi": "^1.0.5", - "standard": "^17.1.0" - }, - "scripts": { - "test": "standard && brittle test/*.js" - }, - "standard": { - "ignore": [ - "/test/fixtures/*.js" - ] - }, - "repository": { - "type": "git", - "url": "https://github.com/holepunchto/sodium-native.git" - }, - "contributors": [ - "Emil Bay (http://bayes.dk)", - "Mathias Buus (https://mafinto.sh)", - "Christophe Diederichs " - ], - "license": "MIT", - "bugs": { - "url": "https://github.com/holepunchto/sodium-native/issues" - }, - "homepage": "https://github.com/holepunchto/sodium-native" -} diff --git a/node_modules/sodium-native/prebuilds/android-arm/sodium-native.bare b/node_modules/sodium-native/prebuilds/android-arm/sodium-native.bare deleted file mode 100644 index f60eed5..0000000 Binary files a/node_modules/sodium-native/prebuilds/android-arm/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/android-arm/sodium-native.node b/node_modules/sodium-native/prebuilds/android-arm/sodium-native.node deleted file mode 100644 index 9964d99..0000000 Binary files a/node_modules/sodium-native/prebuilds/android-arm/sodium-native.node and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/android-arm64/sodium-native.bare b/node_modules/sodium-native/prebuilds/android-arm64/sodium-native.bare deleted file mode 100644 index 145fee8..0000000 Binary files a/node_modules/sodium-native/prebuilds/android-arm64/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/android-arm64/sodium-native.node b/node_modules/sodium-native/prebuilds/android-arm64/sodium-native.node deleted file mode 100644 index 815bf17..0000000 Binary files a/node_modules/sodium-native/prebuilds/android-arm64/sodium-native.node and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/android-ia32/sodium-native.bare b/node_modules/sodium-native/prebuilds/android-ia32/sodium-native.bare deleted file mode 100644 index 3725606..0000000 Binary files a/node_modules/sodium-native/prebuilds/android-ia32/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/android-ia32/sodium-native.node b/node_modules/sodium-native/prebuilds/android-ia32/sodium-native.node deleted file mode 100644 index 2dc6088..0000000 Binary files a/node_modules/sodium-native/prebuilds/android-ia32/sodium-native.node and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/android-x64/sodium-native.bare b/node_modules/sodium-native/prebuilds/android-x64/sodium-native.bare deleted file mode 100644 index fc81f1c..0000000 Binary files a/node_modules/sodium-native/prebuilds/android-x64/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/android-x64/sodium-native.node b/node_modules/sodium-native/prebuilds/android-x64/sodium-native.node deleted file mode 100644 index 1a0243e..0000000 Binary files a/node_modules/sodium-native/prebuilds/android-x64/sodium-native.node and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/darwin-arm64/sodium-native.bare b/node_modules/sodium-native/prebuilds/darwin-arm64/sodium-native.bare deleted file mode 100644 index acd41dd..0000000 Binary files a/node_modules/sodium-native/prebuilds/darwin-arm64/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/darwin-arm64/sodium-native.node b/node_modules/sodium-native/prebuilds/darwin-arm64/sodium-native.node deleted file mode 100644 index e6f7aa6..0000000 Binary files a/node_modules/sodium-native/prebuilds/darwin-arm64/sodium-native.node and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/darwin-x64/sodium-native.bare b/node_modules/sodium-native/prebuilds/darwin-x64/sodium-native.bare deleted file mode 100644 index cf23389..0000000 Binary files a/node_modules/sodium-native/prebuilds/darwin-x64/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/darwin-x64/sodium-native.node b/node_modules/sodium-native/prebuilds/darwin-x64/sodium-native.node deleted file mode 100644 index 1a926f1..0000000 Binary files a/node_modules/sodium-native/prebuilds/darwin-x64/sodium-native.node and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/ios-arm64-simulator/sodium-native.bare b/node_modules/sodium-native/prebuilds/ios-arm64-simulator/sodium-native.bare deleted file mode 100644 index 4625860..0000000 Binary files a/node_modules/sodium-native/prebuilds/ios-arm64-simulator/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/ios-arm64/sodium-native.bare b/node_modules/sodium-native/prebuilds/ios-arm64/sodium-native.bare deleted file mode 100644 index aa39b89..0000000 Binary files a/node_modules/sodium-native/prebuilds/ios-arm64/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/ios-x64-simulator/sodium-native.bare b/node_modules/sodium-native/prebuilds/ios-x64-simulator/sodium-native.bare deleted file mode 100644 index cead0f7..0000000 Binary files a/node_modules/sodium-native/prebuilds/ios-x64-simulator/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/linux-arm64/sodium-native.bare b/node_modules/sodium-native/prebuilds/linux-arm64/sodium-native.bare deleted file mode 100644 index 972ede4..0000000 Binary files a/node_modules/sodium-native/prebuilds/linux-arm64/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/linux-arm64/sodium-native.node b/node_modules/sodium-native/prebuilds/linux-arm64/sodium-native.node deleted file mode 100644 index eb10f4f..0000000 Binary files a/node_modules/sodium-native/prebuilds/linux-arm64/sodium-native.node and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/linux-x64/sodium-native.bare b/node_modules/sodium-native/prebuilds/linux-x64/sodium-native.bare deleted file mode 100644 index 1cfcb76..0000000 Binary files a/node_modules/sodium-native/prebuilds/linux-x64/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/linux-x64/sodium-native.node b/node_modules/sodium-native/prebuilds/linux-x64/sodium-native.node deleted file mode 100644 index 0e373ec..0000000 Binary files a/node_modules/sodium-native/prebuilds/linux-x64/sodium-native.node and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/win32-arm64/sodium-native.bare b/node_modules/sodium-native/prebuilds/win32-arm64/sodium-native.bare deleted file mode 100644 index 7203866..0000000 Binary files a/node_modules/sodium-native/prebuilds/win32-arm64/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/win32-arm64/sodium-native.node b/node_modules/sodium-native/prebuilds/win32-arm64/sodium-native.node deleted file mode 100644 index 5b7659d..0000000 Binary files a/node_modules/sodium-native/prebuilds/win32-arm64/sodium-native.node and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/win32-x64/sodium-native.bare b/node_modules/sodium-native/prebuilds/win32-x64/sodium-native.bare deleted file mode 100644 index b5f877c..0000000 Binary files a/node_modules/sodium-native/prebuilds/win32-x64/sodium-native.bare and /dev/null differ diff --git a/node_modules/sodium-native/prebuilds/win32-x64/sodium-native.node b/node_modules/sodium-native/prebuilds/win32-x64/sodium-native.node deleted file mode 100644 index 0f72042..0000000 Binary files a/node_modules/sodium-native/prebuilds/win32-x64/sodium-native.node and /dev/null differ diff --git a/package-lock.json b/package-lock.json index fd83ed4..71d9d08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,8 +12,7 @@ "@actions/cache": "^4.0.2", "@actions/core": "^1.11.1", "@actions/github": "^6.0.1", - "@actions/tool-cache": "^2.0.2", - "sodium-native": "^4.3.3" + "@actions/tool-cache": "^2.0.2" } }, "node_modules/@actions/cache": { @@ -690,74 +689,6 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "license": "MIT" }, - "node_modules/bare-addon-resolve": { - "version": "1.9.4", - "resolved": "https://registry.npmjs.org/bare-addon-resolve/-/bare-addon-resolve-1.9.4.tgz", - "integrity": "sha512-unn6Vy/Yke6F99vg/7tcrvM2KUvIhTNniaSqDbam4AWkd4NhvDVSrQiRYVlNzUV2P7SPobkCK7JFVxrJk9btCg==", - "license": "Apache-2.0", - "dependencies": { - "bare-module-resolve": "^1.10.0", - "bare-semver": "^1.0.0" - }, - "peerDependencies": { - "bare-url": "*" - }, - "peerDependenciesMeta": { - "bare-url": { - "optional": true - } - } - }, - "node_modules/bare-module-resolve": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/bare-module-resolve/-/bare-module-resolve-1.11.1.tgz", - "integrity": "sha512-DCxeT9i8sTs3vUMA3w321OX/oXtNEu5EjObQOnTmCdNp5RXHBAvAaBDHvAi9ta0q/948QPz+co6SsGi6aQMYRg==", - "license": "Apache-2.0", - "dependencies": { - "bare-semver": "^1.0.0" - }, - "peerDependencies": { - "bare-url": "*" - }, - "peerDependenciesMeta": { - "bare-url": { - "optional": true - } - } - }, - "node_modules/bare-os": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/bare-os/-/bare-os-3.6.1.tgz", - "integrity": "sha512-uaIjxokhFidJP+bmmvKSgiMzj2sV5GPHaZVAIktcxcpCyBFFWO+YlikVAdhmUo2vYFvFhOXIAlldqV29L8126g==", - "license": "Apache-2.0", - "engines": { - "bare": ">=1.14.0" - } - }, - "node_modules/bare-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bare-path/-/bare-path-3.0.0.tgz", - "integrity": "sha512-tyfW2cQcB5NN8Saijrhqn0Zh7AnFNsnczRcuWODH0eYAXBsJ5gVxAUuNr7tsHSC6IZ77cA0SitzT+s47kot8Mw==", - "license": "Apache-2.0", - "dependencies": { - "bare-os": "^3.0.1" - } - }, - "node_modules/bare-semver": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/bare-semver/-/bare-semver-1.0.1.tgz", - "integrity": "sha512-UtggzHLiTrmFOC/ogQ+Hy7VfoKoIwrP1UFcYtTxoCUdLtsIErT8+SWtOC2DH/snT9h+xDrcBEPcwKei1mzemgg==", - "license": "Apache-2.0" - }, - "node_modules/bare-url": { - "version": "2.1.6", - "resolved": "https://registry.npmjs.org/bare-url/-/bare-url-2.1.6.tgz", - "integrity": "sha512-FgjDeR+/yDH34By4I0qB5NxAoWv7dOTYcOXwn73kr+c93HyC2lU6tnjifqUe33LKMJcDyCYPQjEAqgOQiXkE2Q==", - "license": "Apache-2.0", - "dependencies": { - "bare-path": "^3.0.0" - } - }, "node_modules/before-after-hook": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", @@ -1148,19 +1079,6 @@ "wrappy": "1" } }, - "node_modules/require-addon": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/require-addon/-/require-addon-1.1.0.tgz", - "integrity": "sha512-KbXAD5q2+v1GJnkzd8zzbOxchTkStSyJZ9QwoCq3QwEXAaIlG3wDYRZGzVD357jmwaGY7hr5VaoEAL0BkF0Kvg==", - "license": "Apache-2.0", - "dependencies": { - "bare-addon-resolve": "^1.3.0", - "bare-url": "^2.1.0" - }, - "engines": { - "bare": ">=1.10.0" - } - }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1196,15 +1114,6 @@ "semver": "bin/semver.js" } }, - "node_modules/sodium-native": { - "version": "4.3.3", - "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.3.3.tgz", - "integrity": "sha512-OnxSlN3uyY8D0EsLHpmm2HOFmKddQVvEMmsakCrXUzSd8kjjbzL413t4ZNF3n0UxSwNgwTyUvkmZHTfuCeiYSw==", - "license": "MIT", - "dependencies": { - "require-addon": "^1.1.0" - } - }, "node_modules/strnum": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.1.1.tgz", diff --git a/package.json b/package.json index f015a8d..54b9069 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "@actions/cache": "^4.0.2", "@actions/core": "^1.11.1", "@actions/github": "^6.0.1", - "@actions/tool-cache": "^2.0.2", - "sodium-native": "^4.3.3" + "@actions/tool-cache": "^2.0.2" } }