Skip to content

Commit

Permalink
SRP rc for socket 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
heapwolf committed Oct 2, 2023
1 parent 4852089 commit 9f613ed
Show file tree
Hide file tree
Showing 6 changed files with 640 additions and 431 deletions.
2 changes: 1 addition & 1 deletion api/stream-relay/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class Cache {
if (!key || !key.slice) continue
if (prefix.length && !key.startsWith(prefix)) continue
const hex = key.slice(prefix.length, prefix.length + 1)
children[parseInt(hex, 16)].push(key)
if (children[parseInt(hex, 16)]) children[parseInt(hex, 16)].push(key)
}

// compute a checksum for all child members (deterministically)
Expand Down
18 changes: 12 additions & 6 deletions api/stream-relay/encryption.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@ export class Encryption {
return sodium.randombytes_buf(32)
}

static async createClusterId (sharedKey) {
const key = sharedKey || await Encryption.createSharedKey()
return Buffer.from(key || '').toString('base64')
}

static async createKeyPair (seed) {
await sodium.ready
seed = seed || await Encryption.createSharedKey()
seed = seed || sodium.randombytes_buf(32)

if (typeof seed === 'string') {
seed = sodium.crypto_generichash(32, seed)
}

return sodium.crypto_sign_seed_keypair(seed)
}

static async createId (str = randomBytes(32)) {
return (await sha256(str)).toString('hex')
}

static async createClusterId (value) {
await sodium.ready
value = value || sodium.randombytes_buf(32)
return Buffer.from(value).toString('base64')
}

static async createSubclusterId (value) {
return Buffer.from(value).toString('base64')
}
Expand Down
Loading

0 comments on commit 9f613ed

Please sign in to comment.