Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 1.17 KB

README.md

File metadata and controls

36 lines (27 loc) · 1.17 KB

autoisolate

script-addressed autobase executed with isolated vm.

for building composable autobase-protocols

usage

const toUppercaseAddress = 'hyp1pqdnvkw95qufp9czn8540f2lazdecn2cht475n08zaz6fkpatq2tshqltq2'

const base = new Autobase(opts)
const isolate = new Autoisolate(toUppercaseAddress, { 
  autobase: base,
  isolate: new Isolate()
})

await isolate.ready()
await base.append('hello world')
const node = await base.view.get(0)

console.log(node.value.toString()) // HELLO WORLD

where toUppercaseAddress is the the key used to lookup the apply function for an autobase from the DHT

const script = dedent`
  function apply (batch) {
    return batch.map(({ value }) => Buffer.from(Buffer.toString(value).toUpperCase()))
  }
`
const toUppercaseAddress = Autoisolate.encodeScript(script)
const { value } = await dht.immutableGet(toUppercaseAddress)
console.log(script === value.toString()) // true