urbit-ob, but in Dart

This is urbit-ob but in dart, and only implementing the functions I care about:

  • String ob.patp(BigInt)
  • BigInt ob.patp2dec(String)
  • String ob.patq(List<int>)
  • List<int> ob.patq2buf(String)
  • Clan clan(BigInt)

Features

  • works
  • works in VM & JS runtimes
  • test suite that matches urbit-ob

Example

import 'package:urbit_ob/urbit_ob.dart' as ob;

final point = BigInt.from(19268096);
final data = BigInt.from(2884880786);
final name = "~bosnyt-raddux";

// patp
assert(ob.patp(point) == name);
assert(ob.patp2dec(name) == point);

// patq
assert(ob.patq(encodeBigInt(data)) == name);
assert(ob.patq2buf(name) == encodeBigInt(data));

Missing

idk how to encode strings that match BN.js's encoding, so string patqs won't be compatible between dart and js until that works

for example, if you encode 'hello world' as a utf8 byte list in dart, you'll get

utf8.encode('hello world');
// -> [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]

but when you encode a string as a byte array using BN.js you get

new BN('hello world').toArray()
// -> [ 4, 86, 168, 105, 235 ]

it seems like this encoding is done here in BN.js and i've tried to port it over in test/cases.dart but it's confusing to me.

Tests

look they work in the vm!

pub run test

whoa, they work in chrome!

puh run test -p chrome

Libraries

urbit_ob
Support for doing something awesome. [...]