From 6b7af61b10cd1aa12963168e563fe99a855becda Mon Sep 17 00:00:00 2001 From: phillmac Date: Wed, 24 Jun 2020 18:24:42 +1000 Subject: [PATCH] Suport new base36 format, Improve unwieldy logic --- src/orbit-db-address.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/orbit-db-address.js b/src/orbit-db-address.js index 9a4f67e..5bfcd6a 100644 --- a/src/orbit-db-address.js +++ b/src/orbit-db-address.js @@ -26,8 +26,18 @@ class OrbitDBAddress { let accessControllerHash + const validateHash = (hash) => { + const prefixes = ['zd', 'Qm', 'ba', 'k5'] + for (const p of prefixes) { + if (hash.indexOf(p) > -1) { + return true + } + } + return false + } + try { - accessControllerHash = (parts[0].indexOf('zd') > -1 || parts[0].indexOf('Qm') > -1 || parts[0].indexOf('ba') > -1) + accessControllerHash = validateHash(parts[0]) ? new CID(parts[0]).toBaseEncodedString() : null } catch (e) {