Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@hashrock
CreatedNovember 11, 2022 14:30
    • Star(0)You must be signed in to star a gist
    • Fork(0)You must be signed in to fork a gist

    Select an option

    Save hashrock/e003c7f023bfced46d97170e02ef65ae to your computer and use it in GitHub Desktop.
    Deno twtxt hash calc
    import{encode}from"https://deno.land/std@0.163.0/encoding/base32.ts";
    import{blake2b}from"https://esm.sh/blakejs@1.2.1";
    import{DateTime}from"https://esm.sh/luxon@3.1.0";
    import{assertEquals}from"https://deno.land/std@0.163.0/testing/asserts.ts";
    functionbase32(payload:Uint8Array){
    returnencode(payload).replace(/=/g,"").toLowerCase();
    }
    functionblake2b256(payload:string){
    returnblake2b(payload,undefined,32);
    }
    functionformatRFC3339(text:string){
    returnDateTime.fromISO(text,{setZone:true,zone:"utc"})
    .toFormat("yyyy-MM-dd'T'HH:mm:ssZZ")
    .replace(/\+00:00$/,"Z");
    }
    consttwt={
    url:"https://twtxt.net/user/prologic/twtxt.txt",
    hash:"o6dsrga",
    created:"2020-07-18T12:39:52Z",
    content:"Hello World! 😊",
    };
    constcreated=formatRFC3339(twt.created);
    constpayload=[twt.url,created,twt.content].join("\n");
    consthash=base32(blake2b256(payload)).slice(-7);
    Deno.test("hash",()=>{
    assertEquals(hash,twt.hash);
    });
    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp