Snort の markdown がひどい...
S. Ota
_@susumuota.github.io
npub1susu...0yu8
A programmer. An author of nostr-keyx. Interests: Reinforcement Learning, Natural Language Processing and Artificial General Intelligence.
NIP-06 の実装方法 (*0)
- BIP-39 にてニーモニック(= entropy) を生成
- 256 bit (32 byte)の疑似乱数を生成 (entropy と呼ぶ)
- entropy からニーモニックに変換
- entropy とニーモニックは1対1に相互に変換可能(Reversible, base2048 相当なので)
- BIP-32 にて entropy から Nostr 秘密鍵を導出
- entropy をシードとしてマスターキーを生成 (*1) (*2)
- マスターキーから Nostr 用の秘密鍵を導出 (*3) (*4)
- ここで導出しているので Nostr 秘密鍵から元の entropy = ニーモニックに変換することは出来ない
- (*0)
- (*1)
- (*2)
- (*3)
- (*4)
- 実装例
-
-
にメモを書いているのでまとまったら NIP-06 に写しておきます。
GitHub
nips/06.md at master · nostr-protocol/nips
Nostr Implementation Possibilities. Contribute to nostr-protocol/nips development by creating an account on GitHub.
GitHub
scure-bip32/index.ts at 2274f2f42c5382dd08aab747ba7c8686322e706d · paulmillr/scure-bip32
Secure, audited & minimal implementation of BIP32 hierarchical deterministic (HD) wallets. - paulmillr/scure-bip32
BIP32 - Hierarchical Deterministic Wallets
Read more about the BIP32 on {{appUrl}} - Hierarchical Deterministic Wallets
GitHub
scure-bip32/index.ts at 2274f2f42c5382dd08aab747ba7c8686322e706d · paulmillr/scure-bip32
Secure, audited & minimal implementation of BIP32 hierarchical deterministic (HD) wallets. - paulmillr/scure-bip32
BIP32 - Hierarchical Deterministic Wallets
Read more about the BIP32 on {{appUrl}} - Hierarchical Deterministic Wallets
GitHub
nostr-keyx/bin/genkey.ts at main · susumuota/nostr-keyx
A NIP-07 browser extension that uses the OS's keychain or YubiKey to protect your private keys. - susumuota/nostr-keyx
GitHub
NIP06 support by w3irdrobot · Pull Request #425 · v0l/snort
This PR updates the new private key generation to be NIP06-compliant. This basically means the entropy is generated using a mnemonic phrase per BIP...
nostr
s_ota - nostr
pubkey: npub1susumuq8u7v0sp2f5jl3wjuh8hpc3cqe2tc2j5h4gu7ze7z20asq2w0yu8 主要クライアントのデフォルトリレー Snort デフォルト...
ニーモニックの計算方法(BIP-39)
- strength 256 bitの場合
- 256 bit (32 byte)の疑似乱数を生成 (entropy と呼ぶ) (*1)
- entropy のチェックサムを計算(SHA256 の 0 バイト目, 8 bit) (*2)
- それをくっつけて 256 + 8 = 264 bit (33バイト)の整数を生成
- 264 bit の整数は
2^264 = 2^(11*24) = (2^11)^24 = 2048^24
- となり、2048個の単語リストから1単語ずつ選んで24個並べると表現出来る
base64 を知ってる人は base2048 と考えれば簡単。
- base64: データを 6 bit ずつ分割し、それぞれ 64 個 (2^6個) の文字のうち一つを割り当てていく
- base2048: データを 11 bit ずつ分割し、それぞれ 2048 個 (2^11個) の単語のうち一つを割り当てていく
(*1)
(*2)
GitHub
scure-bip39/src/index.ts at 2da299230e35dcbfc32b0d30a8df7918fc7c3b21 · paulmillr/scure-bip39
Secure, audited & minimal implementation of BIP39 mnemonic phrases - paulmillr/scure-bip39
GitHub
scure-bip39/src/index.ts at 2da299230e35dcbfc32b0d30a8df7918fc7c3b21 · paulmillr/scure-bip39
Secure, audited & minimal implementation of BIP39 mnemonic phrases - paulmillr/scure-bip39
BIP39 - Mnemonic code for generating deterministic keys
Read more about the BIP39 on {{appUrl}} - Mnemonic code for generating deterministic keys
秘密鍵は32バイトなら何でもいいわけじゃなくて、公開鍵の生成の時に、
Fail if d' = 0 or d' ≥ n.
という条件があるので 0000... や FFFF.... とかは公開鍵生成の時にNGになるはず。

GitHub
bips/bip-0340.mediawiki at master · bitcoin/bips
Bitcoin Improvement Proposals. Contribute to bitcoin/bips development by creating an account on GitHub.
一応結果はこんな感じ。
秘密鍵から公開鍵の計算に29秒
32バイトのメッセージの署名に158秒
検証に86秒。
```
Test vector #0:
pubkey_gen took: 29071585
schnorr_sign took: 158253199
* Passed signing test.
schnorr_verify took: 85828791
* Passed verification test.
```
Raspberry Pi Pico + MicroPython + secp256k1.schnorr.sign は動くけど遅すぎ。次は Raspberry Pi Zero W やってみる。
Raspberry Pi Pico の MicroPython で secp256k1.schnorr.sign を計算させてみた。32バイトのメッセージの署名に3分くらいかかる。テストは全部通った。途中の計算をキャッシュ出来そうなのでもう少し速く計算できそうなのでやってみる。

GitHub
bips/bip-0340 at master · bitcoin/bips
Bitcoin Improvement Proposals. Contribute to bitcoin/bips development by creating an account on GitHub.
うちの環境だけかもしれませんが、以下のエラーがでまくってました。
Uncaught (in promise) undefined
astraea.mousedev.page/:1


Astraea v1.5.0 テスト。@error さんが結構居る。
ニーモニックから秘密鍵に変換できるけど、秘密鍵からニーモニックは変換できないはず(要確認)
NIP-06 (BIP-39) のニーモニックは恣意的には選べない。チェックサムを計算しているので。

GitHub
scure-bip39/src/index.ts at 2da299230e35dcbfc32b0d30a8df7918fc7c3b21 · paulmillr/scure-bip39
Secure, audited & minimal implementation of BIP39 mnemonic phrases - paulmillr/scure-bip39
ニーモニックは、自分が覚えやすいフレーズを恣意的に選んでもいいのだろうか。
ニーモニックはドラクエの復活の呪文🤙


beta.iris.to 違いがよくわからない
