Skip to content

Commit

Permalink
Initial code
Browse files Browse the repository at this point in the history
  • Loading branch information
billiegoose committed Apr 15, 2018
1 parent 6a75cfe commit b3120ca
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package-lock.json
# Logs
logs
*.log
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# OpenPGP-plugin
# @isomorphic-git/openpgp-plugin

OpenPGP.js plugin for isomorphic-git 1.x

## 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

## License

In keeping with the OpenPGP.js license, this project is licensed under the
GNU Lesser General Public License v3.0
39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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
}
}
}
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": ["isomorphic-git-plugin"],
"author": "William Hilton <wmhilton@gmail.com>",
"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"
}
}

0 comments on commit b3120ca

Please sign in to comment.