Skip to content

Commit

Permalink
docs: NIP13
Browse files Browse the repository at this point in the history
  • Loading branch information
ethicnology committed Jan 20, 2025
1 parent d1c3bb6 commit 02f3f2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ flutter pub add nostr
- [x] [NIP 05 Mapping Nostr keys to DNS-based internet identifiers](https://github.com/nostr-protocol/nips/blob/master/05.md)
- [x] [NIP 09 Event Deletion Request](https://github.com/nostr-protocol/nips/blob/master/09.md)
- [x] [NIP 10 Conventions for clients' use of e and p tags in text events](https://github.com/nostr-protocol/nips/blob/master/10.md)
- [x] [NIP 13 Proof of Work](https://github.com/nostr-protocol/nips/blob/master/13.md)
- [x] [NIP 15 End of Stored Events Notice](https://github.com/nostr-protocol/nips/blob/master/15.md)
- [x] [NIP 19 bech32-encoded entities](https://github.com/nostr-protocol/nips/blob/master/19.md)
- [x] [NIP 20 Command Results](https://github.com/nostr-protocol/nips/blob/master/20.md)
Expand Down
14 changes: 14 additions & 0 deletions lib/src/nips/nip_013.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import 'dart:math';

/// Proof of Work (NIP-13)
///
/// NIP-13 introduces Proof of Work (PoW) for nostr notes to deter spam. PoW is validated by counting the number of leading zero bits in a note's ID (difficulty).
///
/// Example:
/// An ID `000000000e9d97a1ab09fc381030b346cdd7a142ad57e6df0b46dc9bef6c7e2d` has a difficulty of `36` with 36 leading zero bits.
///
/// Mining involves generating an ID with a desired difficulty by iteratively modifying a `nonce` tag.
class Nip13 {
/// Calculates the number of leading zero bits in a hexadecimal string.
///
/// ```dart
/// int difficulty = Nip13.countLeadingZeroes("000000000e9d97a1ab09fc381030b346cdd7a142ad57e6df0b46dc9bef6c7e2d");
/// print(difficulty); // 36
/// ```
static int countLeadingZeroes(String hex) {
int count = 0;
for (int i = 0; i < hex.length; i++) {
Expand Down

0 comments on commit 02f3f2f

Please sign in to comment.