Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from libp2p/chore/update-multihashing-async-dep
Browse files Browse the repository at this point in the history
chore: update multihashing-async dep
  • Loading branch information
vasco-santos committed Jan 3, 2020
2 parents 636a8f1 + 87ed920 commit 3793ea0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
},
"homepage": "https://github.com/libp2p/js-libp2p-record",
"devDependencies": {
"aegir": "^20.0.0",
"aegir": "^20.5.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"libp2p-crypto": "~0.17.0",
"peer-id": "~0.13.2"
"peer-id": "~0.13.6"
},
"dependencies": {
"buffer-split": "^1.0.0",
"err-code": "^1.1.2",
"err-code": "^2.0.0",
"multihashes": "~0.4.15",
"multihashing-async": "~0.7.0",
"multihashing-async": "^0.8.0",
"protons": "^1.0.1"
},
"contributors": [
Expand Down
10 changes: 5 additions & 5 deletions src/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ const errcode = require('err-code')
*/
const bestRecord = (selectors, k, records) => {
if (records.length === 0) {
const errMsg = `No records given`
const errMsg = 'No records given'

throw errcode(errMsg, 'ERR_NO_RECORDS_RECEIVED')
throw errcode(new Error(errMsg), 'ERR_NO_RECORDS_RECEIVED')
}

const parts = bsplit(k, Buffer.from('/'))

if (parts.length < 3) {
const errMsg = `Record key does not have a selector function`
const errMsg = 'Record key does not have a selector function'

throw errcode(errMsg, 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY')
throw errcode(new Error(errMsg), 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY')
}

const selector = selectors[parts[1].toString()]

if (!selector) {
const errMsg = `Unrecognized key prefix: ${parts[1]}`

throw errcode(errMsg, 'ERR_UNRECOGNIZED_KEY_PREFIX')
throw errcode(new Error(errMsg), 'ERR_UNRECOGNIZED_KEY_PREFIX')
}

return selector(k, records)
Expand Down
4 changes: 2 additions & 2 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const verifyRecord = (validators, record) => {
const validator = validators[parts[1].toString()]

if (!validator) {
const errMsg = `Invalid record keytype`
const errMsg = 'Invalid record keytype'

throw errcode(errMsg, 'ERR_INVALID_RECORD_KEY_TYPE')
throw errcode(new Error(errMsg), 'ERR_INVALID_RECORD_KEY_TYPE')
}

return validator.func(key, record.value)
Expand Down
8 changes: 4 additions & 4 deletions src/validators/public-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ const errcode = require('err-code')
*/
const validatePublicKeyRecord = async (key, publicKey) => {
if (!Buffer.isBuffer(key)) {
throw errcode('"key" must be a Buffer', 'ERR_INVALID_RECORD_KEY_NOT_BUFFER')
throw errcode(new Error('"key" must be a Buffer'), 'ERR_INVALID_RECORD_KEY_NOT_BUFFER')
}

if (key.length < 5) {
throw errcode('invalid public key record', 'ERR_INVALID_RECORD_KEY_TOO_SHORT')
throw errcode(new Error('invalid public key record'), 'ERR_INVALID_RECORD_KEY_TOO_SHORT')
}

const prefix = key.slice(0, 4).toString()

if (prefix !== '/pk/') {
throw errcode('key was not prefixed with /pk/', 'ERR_INVALID_RECORD_KEY_BAD_PREFIX')
throw errcode(new Error('key was not prefixed with /pk/'), 'ERR_INVALID_RECORD_KEY_BAD_PREFIX')
}

const keyhash = key.slice(4)

const publicKeyHash = await multihashing(publicKey, 'sha2-256')

if (!keyhash.equals(publicKeyHash)) {
throw errcode('public key does not match passed in key', 'ERR_INVALID_RECORD_HASH_MISMATCH')
throw errcode(new Error('public key does not match passed in key'), 'ERR_INVALID_RECORD_HASH_MISMATCH')
}
}

Expand Down

0 comments on commit 3793ea0

Please sign in to comment.