Expose bip39 to script, and fix some things around base64 so that I can round trip it properly.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4729 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-01-03 17:25:34 +00:00
parent 34a87d8b3b
commit c78753f3ff
3 changed files with 62 additions and 7 deletions

View File

@ -45,12 +45,12 @@ function readSession(session) {
let jwt_parts = session?.split('.');
if (jwt_parts?.length === 3) {
let [header, payload, signature] = jwt_parts;
header = JSON.parse(base64Decode(unb64url(header)));
header = JSON.parse(utf8Decode(base64Decode(unb64url(header))));
if (header.typ === 'JWT' && header.alg === 'HS256') {
signature = unb64url(signature);
let id = ssb.getIdentities(':auth');
if (id?.length && ssb.hmacsha256verify(id[0], payload, signature)) {
let result = JSON.parse(base64Decode(unb64url(payload)));
let result = JSON.parse(utf8Decode(base64Decode(unb64url(payload))));
let now = new Date().valueOf()
if (now < result.exp) {
print(`JWT valid for another ${(result.exp - now) / 1000} seconds.`);