Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed signing for me on webpack #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
const openpgp = require('openpgp')

const toBinary = (data) => {
data = openpgp.util.encode_utf8(data)
data = openpgp.util.str_to_Uint8Array(data)
return data
}

module.exports.pgp = {
async sign ({ payload, secretKey }) {
// We need to use fromBinary because fromText screws with line endings
const data = toBinary(payload) //openpgp.util.encode_utf8(payload)
const data = openpgp.util.encode_utf8(payload)
const message = openpgp.message.fromBinary(data)
const privateKeys = (await openpgp.key.readArmored(secretKey)).keys
let { signature } = await openpgp.sign({
data,
message,
privateKeys,
detached: true,
armor: true
})
return { signature }
},
async verify ({ payload, publicKey, signature }) {
const data = toBinary(payload)
const data = openpgp.util.encode_utf8(payload)
const message = openpgp.message.fromBinary(data)
signature = await openpgp.signature.readArmored(signature)
const publicKeys = (await openpgp.key.readArmored(publicKey)).keys
Expand Down