diff --git a/.gitignore b/.gitignore index 00cbbdf..568aa46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +package-lock.json # Logs logs *.log diff --git a/README.md b/README.md index 9c30cdd..6b6ab8a 100644 --- a/README.md +++ b/README.md @@ -1 +1,18 @@ -# OpenPGP-plugin \ No newline at end of file +# @isomorphic-git/openpgp-plugin + +OpenPGP.js plugin for isomorphic-git + +## Usage + +```js +const { GitOpenPGP } = require('@isomorphic-git/openpgp-plugin') +const git = require('isomorphic-git') + +git.use(GitOpenPGP) + +// Now you can use git.sign() and git.verify() +``` + +## Tests + +TBD \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..ee68978 --- /dev/null +++ b/index.js @@ -0,0 +1,39 @@ +const openpgp = require('openpgp/dist/openpgp.min.js') + +module.exports.GitOpenPGP = { + name: 'GitOpenPGP', + signingHelper: { + async sign ({ payload, secretKey }) { + let { signature } = await openpgp.sign({ + data: payload, + privateKeys: openpgp.key.readArmored(secretKey).keys, + detached: true, + armor: true + }) + return signature + }, + async verify ({ payload, signature, publicKey }) { + // let msg = openpgp.message.readSignedContent(payload, signature) + let {signatures} = await openpgp.verify({ + message: openpgp.message.fromText(payload), + signature: openpgp.signature.readArmored(signature), + publicKeys: openpgp.key.readArmored(publicKey).keys + }) + let invalid = [] + let valid = [] + for (let sig of signatures) { + if (sig.valid) { + valid.push(sig.keyid.toHex()) + } else { + invalid.push(sig.keyid.toHex()) + } + } + // We do this extra mashing to simplify client-side logic that + // is less interested in the values than the presence of values + let result = {} + if (valid.length > 0) result.valid = valid + if (invalid.length > 0) result.invalid = invalid + return result + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..f2923ed --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "@isomorphic-git/openpgp-plugin", + "version": "0.0.0-development", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 0" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/isomorphic-git/openpgp-plugin.git" + }, + "keywords": [], + "author": "William Hilton ", + "license": "LGPL-3.0+", + "bugs": { + "url": "https://github.com/isomorphic-git/openpgp-plugin/issues" + }, + "homepage": "https://github.com/isomorphic-git/openpgp-plugin#readme", + "dependencies": { + "openpgp": "3.0.4" + } +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..f45d8f1 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "config:base" + ] +}