{"id":15497207,"url":"https://github.com/jwerle/hidden-machine","last_synced_at":"2025-04-22T21:32:33.453Z","repository":{"id":57264043,"uuid":"175877076","full_name":"jwerle/hidden-machine","owner":"jwerle","description":"Compile JavaScript into a native addon for Node.js secured by libsodium","archived":false,"fork":false,"pushed_at":"2019-03-20T22:26:27.000Z","size":118,"stargazers_count":39,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-14T19:06:57.564Z","etag":null,"topics":["addon","encrypted","native","node","secretbox","sodium"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwerle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-15T19:07:24.000Z","updated_at":"2024-02-08T08:56:12.000Z","dependencies_parsed_at":"2022-08-25T02:51:52.879Z","dependency_job_id":null,"html_url":"https://github.com/jwerle/hidden-machine","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fhidden-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fhidden-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fhidden-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fhidden-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwerle","download_url":"https://codeload.github.com/jwerle/hidden-machine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250328740,"owners_count":21412675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addon","encrypted","native","node","secretbox","sodium"],"created_at":"2024-10-02T08:31:48.002Z","updated_at":"2025-04-22T21:32:33.435Z","avatar_url":"https://github.com/jwerle.png","language":"JavaScript","readme":"hidden-machine\n==============\n\nCompile JavaScript into a native addon for Node.js secured by libsodium\n\n## Install\n\n```sh\n$ npm install hidden-machine\n```\n\n## Usage\n\nIn your package.json, add the following `\"prepublish\"` script:\n\n```json\n...\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"install\": \"node-gyp-build\",\n    \"prepublish\": \"hidden-machine lib/index.js -o . --key=$SHARED_APP_KEY\"\n  }\n...\n```\n\nwhere `lib/` is the entry path to your module code `./` is the\noutput directory for a C file and a `binding.gyp` file, and `index.js`\nexports look something like:\n\n```js\nmodule.exports = (key) =\u003e require('node-gyp-build')(__dirname).initialize(key)\n```\n\nand the calling code calls `require('your-hidden-module')(Buffer.from(sharedApplicationKey, 'hex'))`.\n\nwhere `sharedApplicationKey` can be generated with by running the following:\n\n```sh\n$ hidden-machine --keygen ## use --json for JSON output\n...\n hidden-machine: publicKey= f4e6a97ae2a2d568de4f9b4144e736cd71ab338881cee6c44a48ced4cd66b504\n hidden-machine: secretKey= 3f9632bc7dc125fe399ed2f7739233274428bc96bdb8ece9ba5937a988fb5b4df4e6a97ae2a2d568de4f9b4144e736cd71ab338881cee6c44a48ced4cd66b504\n hidden-machine: secret= 211536a908a2e650f00c38867c9a4696a1d073323a0c2ac6a1a8f4012265f82a\n hidden-machine: key= 3f9632bc7dc125fe399ed2f7739233274428bc96bdb8ece9ba5937a988fb5b4d\n```\n\nand can be used when publishing or packing your module:\n\n```sh\n$ SHARED_APP_KEY=3f9632bc7dc125fe399ed2f7739233274428bc96bdb8ece9ba5937a988fb5b4d npm publish # or pack\n```\n\n## Example\n\n```js\nconst sharedApplicationKey = generateSharedApplicationKey()\nconst keyPair = getKeyPair()\nrequire('hidden-machine')('/path/to/input.js', {\n  publicKey: keyPair.publicKey,\n  secretKey: keyPair.secretKey,\n  key: sharedApplicationKey,\n}).then((result) =\u003e {\n  for (const step of result.steps) {\n    if ('Compiler' === step.name) {\n      console.log(step.output)\n    }\n  }\n})\n```\n\n### Example Generated `binding.gyp`\n\n```gyp\n{ # auto generated: Tue Mar 19 2019 19:47:54 GMT-0400 (Eastern Daylight Time)\n  \"targets\": [{\n    \"target_name\": \"module\",\n\n    \"sources\": [\n      \"module.c\"\n    ],\n\n    \"variables\": {\n      \"target_arch%\": \"\u003c!(node -p \\\"require('hidden-machine/arch')\\\")\u003e\"\n    },\n\n    \"cflags\": [\n      \"\u003c!(node -p \\\"require('hidden-machine/cflags')\\\")\"\n    ],\n\n    \"xcode_settings\": {\n      \"OTHER_CFLAGS\": [ \"\u003c!(node -p \\\"require('hidden-machine/cflags')\\\")\" ]\n    },\n\n    \"libraries\": [\n      \"\u003c!(node -p \\\"require('hidden-machine/libraries/sodium')\\\")\"\n    ],\n\n    \"include_dirs\": [\n      \"\u003c!(node -p \\\"require('hidden-machine/include/sodium')\\\")\",\n      \"\u003c!(node -p \\\"require('hidden-machine/include/napi')\\\")\",\n      \"\u003c!(node -p \\\"require('hidden-machine/include')\\\")\"\n    ],\n\n    \"conditions\": [\n      [\"OS != 'mac' and OS != 'win'\", {\n        \"link_settings\": {\n          \"libraries\": [\n            \"-Wl,\u003c!(node -p \\\"require('hidden-machine/ldflags')\\\")\"\n          ]\n        }\n      }]\n    ]\n  }]\n}\n```\n\n## API\n\n### `require('hidden-machine')(input, opts)`\n\nCompile `input` entry module into a native module with the following options:\n\n#### `opts.publicKey`\n\nAn optional public key to use for encryption.\n\n#### `opts.secretKey`\n\nAn optional secret key corresponding to the given public key to use for encryption.\n\n#### `opts.secret`\n\nA shared secret value that is a blake2b hashed and used as the seed for\npublic and secret key generation.\n\n#### `opts.nonce`\n\nThe initial nonce value used for each `crypto_secretbox_easy` on each\nbuffer segment.\n\n#### `opts.seed`\n\nAn optional initial seed value. If this is given, the secret is ignored.\n\n#### `opts.key`\n\nAn optional shared secret key that is used for encryption for each\n`crypto_secretbox_easy` call.\n\n#### `opts.compile`\n\nEverything is passed directly to [ncc](https://github.com/zeit/ncc)\nincluding:\n\n* `opts.compile.build` - Compiler output directory. (default: `build/`)\n* `opts.compile.output` - Optional build path prefix. (default: ``)\n\n#### `opts.bundle`\n\n* `opts.bundle.concurrency` - The number of concurrent tasks the bundler\n  will for each input target.\n\n## See Also\n\n* [Example HTTP server compiled with hidden-machine](https://github.com/jwerle/hidden-machine-example-http)\n* [A hidden machine to wish a secret happy birthday to @vipyne](https://github.com/jwerle/happy-birthday-vipyne)\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fhidden-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwerle%2Fhidden-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fhidden-machine/lists"}