Skip to content

Instantly share code, notes, and snippets.

@Nuhvi
Last active October 9, 2022 14:55
Show Gist options
  • Save Nuhvi/8b27974e46aef9ca51448bdd36916ab9 to your computer and use it in GitHub Desktop.
Save Nuhvi/8b27974e46aef9ca51448bdd36916ab9 to your computer and use it in GitHub Desktop.
test hyperdrive keychain PR backward compatibility
import * as SlashURL from '@synonymdev/slashtags-url'
import Corestore from 'corestore'
import Hyperdrive from 'hyperdrive'
import Hyperswarm from 'hyperswarm'
import RAM from 'random-access-memory'
const swarm = new Hyperswarm()
const corestore = new Corestore(RAM)
swarm.on('connection', socket => corestore.replicate(socket))
let url = 'slashfeed:kgw7hqj4usek78smxczgrcxqn313s7qnpnc7so7guegziwjic6yy#encryptionKey=nds189gg3hgpei45y79f9ho6s6yh4sm3su1bw4yktt9gtggxtxty'
const parsed = SlashURL.parse(url)
const key = parsed.key
const encryptionKey =parsed.privateQuery.encryptionKey && SlashURL.decode(parsed.privateQuery.encryptionKey)
const drive = new Hyperdrive(corestore, key, { encryptionKey })
await drive.ready()
swarm.join(drive.discoveryKey, {server: false, client: true})
const done = drive.findingPeers()
swarm.flush().then(done, done)
const list = []
for await (let entry of drive.readdir()){
list.push(entry)
}
console.log(list)
swarm.destroy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment