Reference Script for 011 Examples

Tags: packet, example

This script generates the examples used in 011-PACKETS-BASIC-EXAMPLE.md.

#!/bin/bash -e

blob_msg="HPPR Quickstart

HPPR packets are content-addressed using BLAKE3.
This Blob contains raw markdown data."

plex_msg="Plex
This is a plex packet with metadata and links."

seal_msg="Seal
This is a signed packet that wraps a plex packet."

#- Deterministic test-only signatures.
export _UNSAFE_VULNERABLE_HPP_HSB3_DETERMINISTIC_AUX_SEED="examples"
export HPPR_SIGNING_SECRET="&.ydejWAbshBxyrcKILG3bXkD7fU5c72LtHvLJRfzGXal.H3"
tai="1640995200:000000000"

out="./spec/011-PACKETS-BASIC-EXAMPLE.md"

#- Blob
echo -n "$blob_msg" | mkpac --blob > "$out"
blob_hash=$(head -n 1 "$out" | awk '{print $2}')

#- Plex
echo -n "$plex_msg" | mkpac \
  --group a-group \
  --api some-api \
  --key our-collection/item \
  -t "$tai" \
  -H "+Link: source $blob_hash" \
  -H "X-Custom: header value" \
  -H "Multiple-Values: B" \
  -H "Multiple-Values: A" \
  >> "$out"

#- Seal
echo -n "$seal_msg" | mkpac \
  --seal-with "$HPPR_SIGNING_SECRET" \
  --group a-group \
  --api some-api \
  --key our-collection/item \
  -t "$tai" \
  >> "$out"