Repository navigation
Expand file tree
/
Copy paths.html
More file actions
156 lines (149 loc) · 8.29 KB
/
Copy paths.html
File metadata and controls
156 lines (149 loc) · 8.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Summon — RAR</title>
<!-- Scan-to-summon landing page. A QR code on a card encodes
https://kody-w.github.io/RAR/s.html#<seed> (an agent card)
https://kody-w.github.io/RAR/s.html#stack=<name> (a stack)
This page only SHOWS the card. It never installs anything itself and never
carries code: "Summon" hands the seed to the owner's own paired Brainstem
summon sidecar, which re-fetches from RAR and checks every sha256, and the
Brainstem kernel checks it again on import. Pairing (once per phone):
s.html#pair=<sidecar-url> e.g. http://my-mac.tailnet.ts.net:7390 -->
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
background: #0d1117; color: #e6edf3; margin: 0; padding: 24px 16px; }
main { max-width: 440px; margin: 0 auto; }
.card { background: #161b22; border: 1px solid #30363d; border-radius: 16px; padding: 22px; }
h1 { font-size: 24px; margin: 0 0 4px; }
.by { color: #8b949e; font-size: 14px; }
p { line-height: 1.5; }
.warn { color: #f0883e; }
button, .btn { display: block; width: 100%; box-sizing: border-box; text-align: center; padding: 16px;
margin-top: 18px; font-size: 18px; border: 0; border-radius: 12px; background: #2f81f7;
color: #fff; text-decoration: none; cursor: pointer; }
button[disabled] { background: #30363d; color: #8b949e; cursor: default; }
details { margin-top: 18px; color: #8b949e; font-size: 14px; }
input { width: 100%; box-sizing: border-box; padding: 10px; margin-top: 8px; border-radius: 8px;
border: 1px solid #30363d; background: #0d1117; color: #e6edf3; }
a { color: #58a6ff; }
</style>
</head>
<body>
<main>
<div class="card" id="card"><p>Loading the card…</p></div>
<div id="action"></div>
<details id="more"><summary>Details</summary><div id="details"></div></details>
</main>
<script>
(function () {
"use strict";
var KEY = "rar.summon.sidecar", PKEY = "rar.summon.key";
// A pairing link is "pair=<sidecar-url>&k=<pairing key>"; the key proves this phone was paired at the Mac.
function savePair(s) {
var m = String(s).replace(/^.*#?pair=/, "").split("&k=");
var u = safeUrl(m[0]);
if (!u) { return null; }
localStorage.setItem(KEY, u);
if (m[1]) { localStorage.setItem(PKEY, m[1]); } else { localStorage.removeItem(PKEY); }
return u;
}
var hash = decodeURIComponent((location.hash || "").replace(/^#/, ""));
var card = document.getElementById("card");
var action = document.getElementById("action");
var details = document.getElementById("details");
function esc(s) { var d = document.createElement("div"); d.textContent = String(s == null ? "" : s); return d.innerHTML; }
function safeUrl(u) { try { var x = new URL(u); return (x.protocol === "http:" || x.protocol === "https:") ? x.origin : null; } catch (e) { return null; } }
if (hash.indexOf("pair=") === 0) {
var url = savePair(hash);
card.innerHTML = url
? "<h1>Paired</h1><p>This phone now summons into <b>" + esc(url) + "</b>. Scan any RAR card to summon it.</p>"
: "<h1>Pairing failed</h1><p class='warn'>That pairing link is not a valid address.</p>";
return;
}
// Chants: 7 words = a 64-bit seed (rapp_sdk.seed_to_words). The word list is the
// protocol, so read it from rapp_sdk.py itself rather than keeping a second copy.
function chantToSeed(chant) {
return fetch("rapp_sdk.py", { cache: "force-cache" }).then(function (r) { return r.text(); }).then(function (src) {
var m = src.match(/MNEMONIC_WORDS = """([\s\S]*?)"""/);
if (!m) throw new Error("word list missing");
var list = m[1].trim().split(/\s+/), idx = {};
list.forEach(function (w, i) { idx[w] = i; });
var words = chant.toUpperCase().replace(/[-,.]/g, " ").trim().split(/\s+/);
if (words.length !== 7) throw new Error("A chant is exactly 7 words.");
var seed = BigInt(0);
for (var i = 0; i < 7; i++) {
if (!(words[i] in idx)) throw new Error("\"" + words[i] + "\" is not a chant word.");
seed |= BigInt(idx[words[i]]) << BigInt(10 * i);
}
return seed.toString();
});
}
function chantBox(msg) {
card.innerHTML = "<h1>Say the chant</h1><p>" + esc(msg || "Type or dictate the card's 7 words.") + "</p>" +
"<input id='chant' autocomplete='off' autocapitalize='characters' placeholder='WORD WORD WORD WORD WORD WORD WORD'>" +
"<button id='speak'>Summon by chant</button>";
document.getElementById("speak").onclick = function () {
location.hash = "chant=" + document.getElementById("chant").value.trim().replace(/\s+/g, "-");
location.reload();
};
}
if (hash.indexOf("chant=") === 0) {
chantToSeed(hash.slice(6)).then(function (seed) { location.replace("#" + seed); location.reload(); })
.catch(function (e) { chantBox(e.message); });
return;
}
var isStack = hash.indexOf("stack=") === 0;
var key = isStack ? hash.slice(6) : hash;
if (!key) { chantBox(); return; }
// Seeds are 64-bit: JSON.parse would round them (18289705222458979460 -> ...80000),
// so quote every seed as text before parsing and compare seeds only as strings.
function parseExact(text) {
text = text.replace(/("_seed"\s*:\s*)(\d+)/g, '$1"$2"');
text = text.replace(/("_seed_aliases"\s*:\s*\[)([^\]]*)\]/g, function (m, head, body) {
return head + body.replace(/(\d+)/g, '"$1"') + "]";
});
return JSON.parse(text);
}
fetch("registry.json", { cache: "no-cache" }).then(function (r) { return r.text(); }).then(parseExact).then(function (reg) {
var item = null, ok = true, title, by, what, path;
if (isStack) {
(reg.stack_packs || []).forEach(function (p) { if (p.name === key) item = p; });
if (item) { title = item.display_name; by = "Stack"; what = item.purpose; ok = item._verified === true; path = "s/stack/" + encodeURIComponent(item.name); }
} else {
(reg.agents || []).forEach(function (a) {
if (String(a._seed) === key || (a._seed_aliases || []).map(String).indexOf(key) >= 0) item = a;
});
if (!item) (reg.stack_packs || []).forEach(function (p) { if (String(p._seed) === key) { item = p; isStack = true; } });
if (item && isStack) { title = item.display_name; by = "Stack"; what = item.purpose; ok = item._verified === true; path = "s/stack/" + encodeURIComponent(item.name); }
else if (item) { title = item.display_name; by = item.author; what = item.description; ok = item._lifecycle === "notarized"; path = "s/" + encodeURIComponent(String(item._seed)); }
}
if (!item) { card.innerHTML = "<h1>Card not found</h1><p class='warn'>No card in RAR matches this code.</p>"; return; }
var chant = item._incantation ? "<p class='by'>Chant: <b>" + esc(item._incantation) + "</b></p>" : "";
card.innerHTML = "<h1>" + esc(title) + "</h1><div class='by'>by " + esc(by) + "</div><p>" + esc(what) + "</p>" + chant +
(ok ? "" : "<p class='warn'>Not verified in RAR yet, so it can't be summoned.</p>");
details.innerHTML = "<p>" + esc(isStack ? item.path : item.name) + " · version " + esc(item.version) + "</p>" +
"<p>Summon sends only this card's code to your own Brainstem. Your Brainstem downloads it from RAR and checks its fingerprint before installing.</p>";
var side = localStorage.getItem(KEY);
if (!ok) {
action.innerHTML = "<button disabled>Summon</button>";
} else if (side) {
action.innerHTML = "<a class='btn' id='go'>Summon into my Brainstem</a>";
var pk = localStorage.getItem(PKEY);
document.getElementById("go").href = side + "/" + path + (pk ? "?k=" + encodeURIComponent(pk) : "");
} else {
action.innerHTML = "<button disabled>Summon</button><p class='by'>Pair this phone with your Brainstem first: open its pairing QR code, or paste its summon address:</p>" +
"<input id='pair' placeholder='paste the pairing link from your Mac'><button id='save'>Pair</button>";
document.getElementById("save").onclick = function () {
if (savePair(document.getElementById("pair").value.trim())) { location.reload(); }
};
}
}).catch(function () {
card.innerHTML = "<h1>Couldn't reach RAR</h1><p class='warn'>Check your connection and scan again.</p>";
});
})();
</script>
</body>
</html>