Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

seal.gno

0.99 Kb · 27 lines
 1package memba_notes_v1
 2
 3import (
 4	"crypto/sha256"
 5	"encoding/hex"
 6	"strconv"
 7)
 8
 9// Decorative fingerprint from public ciphertext only. It is not a historical
10// inclusion proof or proof of knowledge of a plaintext/key.
11func seal(body []byte) string {
12	hash := sha256.Sum256(body)
13	glyphs := []rune("◇◆○●□■△▲✦")
14	out := "```\n"
15	for i := 0; i < 81; i++ {
16		out += string(glyphs[int(hash[i%32]+byte(i/32))%len(glyphs)])
17		if i%9 == 8 {
18			out += "\n"
19		}
20	}
21	return out + "```\n"
22}
23func SealJSON(idHex string) string {
24	n := find(readID(idHex))
25	hash := sha256.Sum256(n.Body)
26	return `{"id":` + q(idText(n.ID)) + `,"state_revision":` + u(n.Revision) + `,"body_revision":` + u(n.BodyRevision) + `,"epoch":` + u(uint64(n.Epoch)) + `,"ciphertext_sha256":` + q(hex.EncodeToString(hash[:])) + `,"encrypted":` + strconv.FormatBool(encrypted(n.Mode) && !n.Deleted) + `,"deleted":` + strconv.FormatBool(n.Deleted) + `,"height":` + q(strconv.FormatInt(n.Last.Height, 10)) + `,"historical_proof":false}`
27}