Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cabal-club/cabal-core
Browse files Browse the repository at this point in the history
  • Loading branch information
substack committed May 22, 2020
2 parents 1e0a8a8 + 22decd7 commit 97b91c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
17 changes: 5 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Cabal (storage, key, opts) {
if (Buffer.isBuffer(key)) key = key.toString('hex')
if (!key.startsWith('cabal://')) key = 'cabal://' + key
const uri = new URL(key)
this.key = sanitizeKey(uri.host)
this.key = sanitizeKey(key)
this.modKeys = uri.searchParams.getAll('mod')
this.adminKeys = uri.searchParams.getAll('admin')
}
Expand Down Expand Up @@ -258,22 +258,15 @@ function generateKeyHex () {
}

function isHypercoreKey (key) {
if (typeof key === 'string') return /^[0-9a-f]{64}$/.test(key)
if (typeof key === 'string') return /^[0-9A-Fa-f]{64}$/.test(key)
else if (Buffer.isBuffer(key)) return key.length === 32
}

// Ensures 'key' is a hex string
function sanitizeKey (key) {
// force to hex string
if (Buffer.isBuffer(key)) {
key = key.toString('hex')
}

// remove any protocol uri prefix
if (typeof key === 'string') key = key.replace(/^.*:\/\//, '')
else key = undefined

return key
const match = key.match(/^cabal:\/\/([0-9A-Fa-f]{64})/)
if (match === null) return undefined
return match[1]
}

function noop () {}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cabal-core",
"version": "11.1.0",
"version": "11.1.1",
"description": " p2p db functions for chat ",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 97b91c8

Please sign in to comment.