-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Updated index.js - Added nip21.js - Updated nip21.md
- Loading branch information
1 parent
43ceffe
commit 42d8321
Showing
3 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const { loadWasmSync, Keys, EventBuilder, Nip19Profile, Nip19Event, Coordinate} = require("@rust-nostr/nostr"); | ||
|
||
function run(){ | ||
// Load WASM | ||
loadWasmSync(); | ||
|
||
console.log(); | ||
console.log("Nostr URIs:"); | ||
|
||
// ANCHOR: npub | ||
let keys = Keys.generate(); | ||
// bech32 npub | ||
let pk_bech32 = keys.publicKey.toBech32(); | ||
console.log(` Public key (bech32): ${pk_bech32}`); | ||
// ANCHOR_END: npub | ||
|
||
console.log(); | ||
// ANCHOR: note | ||
let event = EventBuilder.textNote("Hello from Rust Nostr JS Bindings!", []).toEvent(keys); | ||
|
||
// bech32 note | ||
let note_bech32 = event.id.toBech32() | ||
console.log(` Event (bech32): ${note_bech32}`); | ||
// ANCHOR_END: note | ||
|
||
console.log(); | ||
// ANCHOR: nprofile | ||
let relays = ["wss://relay.damus.io"]; | ||
let nprofile = new Nip19Profile(keys.publicKey, relays); | ||
|
||
// URI nprofile | ||
let nprofile_uri = nprofile.toNostrUri(); | ||
console.log(` Profile (URI): ${nprofile_uri}`); | ||
|
||
// bech32 nprofile | ||
let nprofile_bech32 = Nip19Profile.fromNostrUri(nprofile_uri).toBech32(); | ||
console.log(` Profile (bech32): ${nprofile_bech32}`); | ||
// ANCHOR_END: nprofile | ||
|
||
console.log(); | ||
// ANCHOR: nevent | ||
let nevent = new Nip19Event(event.id, keys.publicKey, null, relays); | ||
|
||
// URI nevent | ||
let nevent_uri = nevent.toNostrUri(); | ||
console.log(` Event (URI): ${nevent_uri}`); | ||
|
||
// bech32 nevent | ||
let nevent_bech32 = Nip19Event.fromNostrUri(nevent_uri).toBech32(); | ||
console.log(` Event (bech32): ${nevent_bech32}`); | ||
// ANCHOR_END: nevent | ||
|
||
console.log(); | ||
// ANCHOR: naddr | ||
// URI naddr | ||
let coord_uri = new Coordinate(event.kind, keys.publicKey).toNostrUri(); | ||
console.log(` Coordinate (URI): ${coord_uri}`); | ||
|
||
// bech32 naddr | ||
let coord_bech32 = new Coordinate(event.kind, keys.publicKey).toBech32(); | ||
console.log(` Coordinate (bech32): ${coord_bech32}`); | ||
// ANCHOR_END: naddr | ||
|
||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters