Skip to content

Commit 89dfa5b

Browse files
committed
fix: author validation
1 parent 8648a5d commit 89dfa5b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lib/validator.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ const utils = require('./utils')
1010
const types = require('./types')
1111
const errors = require('./errors')
1212
const MESSAGE_TYPE = require('./constants').TYPES.MESSAGE
13-
const PERMALINK = constants.PERMALINK
14-
const PREVLINK = constants.PREVLINK
15-
const SIG = constants.SIG
16-
const TYPE = constants.TYPE
13+
const {
14+
PERMALINK,
15+
PREVLINK,
16+
SIG,
17+
TYPE,
18+
AUTHOR
19+
} = require('@tradle/constants')
1720

1821
/**
1922
* message / object validation
@@ -140,16 +143,22 @@ module.exports = function validator (node) {
140143
}
141144

142145
function checkAuthentic (wrapper, cb) {
143-
const object = wrapper.object
146+
const { object, link, author } = wrapper
144147
const sig = object[SIG]
145-
const link = wrapper.link
148+
if (object[AUTHOR] !== author.permalink) {
149+
return cb(new errors.Author({
150+
author: object[AUTHOR],
151+
sig
152+
}))
153+
}
154+
146155
utils.extractSigPubKey(object, function (err, signingKey) {
147156
if (err || !signingKey) return cb(new errors.InvalidSignature({ sig }))
148157

149158
const pubKey = utils.findPubKey(wrapper.author.object, signingKey)
150159
if (!pubKey) {
151160
return cb(new errors.Author({
152-
author: wrapper.author.link,
161+
author: author.permalink,
153162
sig: sig
154163
}))
155164
}

0 commit comments

Comments
 (0)