Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use async hypercore-encryption module #676

Merged
merged 13 commits into from
Mar 26, 2025
Merged

Use async hypercore-encryption module #676

merged 13 commits into from
Mar 26, 2025

Conversation

chm-diederichs
Copy link
Contributor

No description provided.

@chm-diederichs
Copy link
Contributor Author

we need to publish https://github.com/holepunchto/hypercore-block-encryption once we're happy with it

index.js Outdated
@@ -1119,3 +1140,16 @@ function getEncryptionOption (opts) {
if (!opts.encryption) return null
return b4a.isBuffer(opts.encryption) ? { key: opts.encryption } : opts.encryption
}

function isEncryptionProvider (e) {
return !!(e && (e instanceof HypercoreEncryption || (e.encrypt && typeof e.encrypt === 'function')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just do the instanceof check

@@ -1046,14 +1077,14 @@ function toHex (buf) {
return buf && b4a.toString(buf, 'hex')
}

function preappend (blocks) {
async function preappend (blocks) {
const offset = this.state.length
const fork = this.state.encryptionFork

if (this.encryption.compat !== this.core.compat) this._updateEncryption()

for (let i = 0; i < blocks.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this maybe be done in parallel using something like await Promise.all(blocks.map(encrypt))? This seems like a major perf regression otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as today since sync right now, but we can adjust later. the async'ness is there for flexibility. for now lets keep it simple.

@chm-diederichs chm-diederichs changed the title Use async hypercore-block-encryption module Use async hypercore-encryption module Mar 25, 2025
@mafintosh mafintosh merged commit e922402 into main Mar 26, 2025
4 checks passed
@mafintosh mafintosh deleted the encryption-provider branch March 26, 2025 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants