This weekly debrief is for paying supporters of my work. Please only read if you’ve paid. Thanks!
→ Click here if you've paid ←
This week has been spent adding authentication for authors to the Bedrock Public Library, and working on an implementation of Bedrock for a tiny microcontroller.
Authentication
Continuing on from my work last week, I’ve been figuring out how authentication and session management is supposed to work for the Bedrock Public Library. If you’re just wanting to browse and check out items then you won’t need any kind of account, but if you want to become an author and upload your work then you’ll need to sign up.
The whole authentication process goes as follows:
- When an author signs up, they’ll choose a username and a password. All of their uploaded works will be filed under their username (in such a way that the username can be changed in the future). The password is hashed and stored in the database.
- To log in, the author enters their username and password into the login page. The API returns a signed JSON Web Token containing their username and permissions, which is stored in a cookie and sent with every API request.
- This session token lasts only 10 minutes. If a valid but expired token is sent to the server with a request, a new token is generated and returned in the response, keeping the session alive. The author can choose to log out everywhere, which will prevent any old session tokens from being refreshed. Tokens older than a few weeks will also fail to refresh, requiring the author to log in again.
This process has a few important benefits:
- it allows the author to stay in control of where they’re logged in
- it saves the author from having to log in every time they use the library
- it prevents the database from having to keep track of sessions
There’s not much else to say here, it’s all fairly run-of-the-mill web authentication stuff.
A minimal Bedrock
This was the exciting half of the week. I was getting bogged down in web developer land with the BPL stuff and I wanted something small and fun to distract myself with, so I started work on a new Bedrock implementation.
The idea for this one is to have Bedrock run on the weakest, cheapest, and smallest piece of hardware that I can get away with while still being completely usable as a computer. I’ve chosen the PIC12F1572 microcontroller, which is almost as close to baseline as you can get. It has:
- 8 pins (6 of the pins can be used for input / output)
- 2048 words of read-only program memory
- 256 bytes of read-write data memory
- 16 levels of stack
- an 8MHz instruction clock
- draws 7mW at full throttle (at least a month on 2 AA batteries)
Here’s a picture of the chip itself, with a AA battery for scale. The chip costs $2.04 NZD a piece, but if I go surface mount then I can get one for just $1.48 NZD (it’ll be almost microscopic, the body is 3mm x 3mm).

The Bedrock stacks will be stored in 240 bytes of data memory on the microcontroller (giving 120 bytes per stack, plenty enough for most programs), but I’ll need a separate memory chip to provide for the 64 kilobytes of program memory. I’m planning to use an MCP23LC512, which has the same footprint as the microcontroller and costs $3.97 NZD.
Finally, separate device boards will connect to the system via a bank of small 4-pin JST connectors.
Writing the program
I’m using Torque to write the program for the microcontroller. I’ve been having so much fun with it, I really love this little language. It’s fun piecing together DSLs with macros to make my code read like prose.
The following image shows the Torque implementations of the DUP, OVR, and SWP Bedrock instructions alongside the instruction descriptions in the Bedrock specification. If you squint your eyes just right, the code looks like a direct copy of the spec, which makes it really easy to check for errors.

I’ve written almost the entire program by now, besides the implementations of the LDD and STD instructions and a rudimentary bootloader. The next step is going to be the circuit design, figuring out the layout and the list of parts I’ll need, so that I can order them and fire up the soldering iron.
Thanks
Adieu to another week. Thanks to all of my supporters, I hope you all have a great week!