仕様が数字の件、理系に略語を作らせると大抵ろくでもないことになるから数字にしておいたほうがマシだと思う。
This looks great! I will adapt nostr-keyx to NIP-46.
なのでこのシークレットさえ安全に保存しておけば、どのアプリを使っても大丈夫です。
Google Authenticator や Anthy で QR コードを読み取った後、QR コードが読み取れない人用のリンクをクリックしてそこで表示されるテキスト (例: "JBSWY3DPEHPK3PXP") を安全な場所(macOS ならキーチェーンアクセス) に保存しておけば、アプリが消えても復活できます。
2要素認証のコードはこんな感じ。secret はサービス側で QR コードを表示された時に、表示するオプションがあるのでそれを押すと base32 テキストが出てきます。
```
// https://www.rfc-editor.org/rfc/rfc4226#page-6
const hotp = (secret: BinaryLike, count: number, digits: number = 6) => {
const c = Buffer.alloc(8);
c.writeBigInt64BE(BigInt(count));
const hs = createHmac('sha1', secret).update(c).digest();
const s = (hs.readUInt32BE(hs[19] & 0x0f) & 0x7fffffff);
return (s % (10 ** digits)).toString().padStart(digits, '0');
};
// https://www.rfc-editor.org/rfc/rfc6238#page-4
const totp = (secret: BinaryLike, time: number, step: number = 30, digits: number = 6, t0: number = 0) => {
const count = Math.floor((time - t0) / step);
return hotp(secret, count, digits);
};
// https://github.com/google/google-authenticator/wiki/Key-Uri-Format#secret
const twoFA = (secret: string, length: number = 1) => {
const sec = base32.decode(secret);
const now = Math.floor(Date.now() / 1000);
return { totp: Array.from({ length }, (_, i) => totp(sec, now + 30 * i, 30, 6)), time: 30 - (now % 30) };
}
```
一応未来のトークンも表示できるようにしたので30秒縛りがなくなります 😀
2要素認証のコードはこんな感じ。secret はサービス側で QR コードを表示された時に、表示するオプションがあるのでそれを押すと base32 テキストが出てきます。
```
// https://www.rfc-editor.org/rfc/rfc4226#page-6
const hotp = (secret: BinaryLike, count: number, digits: number = 6) => {
const c = Buffer.alloc(8);
c.writeBigInt64BE(BigInt(count));
const hs = createHmac('sha1', secret).update(c).digest();
const s = (hs.readUInt32BE(hs[19] & 0x0f) & 0x7fffffff);
return (s % (10 ** digits)).toString().padStart(digits, '0');
};
// https://www.rfc-editor.org/rfc/rfc6238#page-4
const totp = (secret: BinaryLike, time: number, step: number = 30, digits: number = 6, t0: number = 0) => {
const count = Math.floor((time - t0) / step);
return hotp(secret, count, digits);
};
// https://github.com/google/google-authenticator/wiki/Key-Uri-Format#secret
const twoFA = (secret: string, length: number = 1) => {
const sec = base32.decode(secret);
const now = Math.floor(Date.now() / 1000);
return { totp: Array.from({ length }, (_, i) => totp(sec, now + 30 * i, 30, 6)), time: 30 - (now % 30) };
}
```
2要素認証 は node で10行くらいで書けるのでシークレットさえちゃんと保存しておけばどうにかなることを最近知りました。
OS 標準以外だと HashiCorp Vault というのが良さそうかな?
1. Windows において、macOS のキーチェーンアクセスに相当するのは Windows Credential Manager
2. パスワードは cmdkey.exe で作成/削除出来るが取得は出来ない
3. パスワードを取得するには PowerShell スクリプトが必要
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmdkey
3 が面倒そう...
1. Windows において、macOS のキーチェーンアクセスに相当するのは Windows Credential Manager
2. パスワードは cmdkey.exe で作成/削除出来るが取得は出来ない
3. パスワードを取得するには PowerShell スクリプトが必要
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmdkey
JavaScript の range の書き方。
これは知らなかった。map もついでに出来てしまう。
Array.from({ length: 5 }, (_, i) => i * 2)
今まではこっちを使っていたけど、ちょっと技巧に走りすぎている感がある。
[...Array(5).keys()].map(i => i * 2)
どのリレーがどの NIP に対応しているか API で検索できた。
curl -s https://api.nostr.watch/v1/online | jq | wc -l # 336
curl -s https://api.nostr.watch/v1/nip/40 | jq | wc -l # 113
こないだ話題になっていた期限付きメッセージ(NIP-40)に対応しているのは3分の1くらい。
MFM (Misskey Flavored Markdown) 、ライブラリとして切り出されているのでNostrでもMFM対応クライアントはすぐ作れる https://github.com/misskey-dev/mfm.js
HTMLタグ読めるクライアントより安心だね!
#[0]
Misskey ちょっとみてみた。複数の Mastodon サーバを検索できるっぽい。
https://misskey.io/search?q=arxiv.org
検索 API もあった。
https://misskey.kurume-nct.com/api-doc#tag/notes/operation/notes/search
https://misskey.kurume-nct.com/api-doc#section/Usage
ちょっと情報が古いのが気になるけど Twitter API の代替候補にはなるかも。
Chrome Web Store に登録して、インストーラーの用意までしないとなかなか難しそうですね。Chrome Web Store は一度登録したことがあるので、もうすこし固まったら申請してみます。