-
-
Notifications
You must be signed in to change notification settings - Fork 101
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 Closes #590 Signed-off-by: Yuki Kishimoto <[email protected]>
- Loading branch information
1 parent
c09d8de
commit d01a2bf
Showing
3 changed files
with
99 additions
and
2 deletions.
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,64 @@ | ||
const { loadWasmSync, Keys, EventBuilder, Nip19Profile, Nip19Event, Coordinate} = require("@rust-nostr/nostr"); | ||
|
||
function run(){ | ||
// Load WASM | ||
loadWasmSync(); | ||
|
||
let keys = Keys.generate(); | ||
|
||
console.log(); | ||
console.log("Nostr URIs:"); | ||
|
||
// ANCHOR: npub | ||
// UNCOMMENT_ON_RELEASE: let pk_uri = keys.publicKey.toNostrUri(); | ||
// UNCOMMENT_ON_RELEASE: console.log(` Public key (URI): ${pk_uri}`); | ||
// ANCHOR_END: npub | ||
|
||
console.log(); | ||
// ANCHOR: note | ||
let event = EventBuilder.textNote("Hello from rust-nostr JS bindings!", []).toEvent(keys); | ||
// UNCOMMENT_ON_RELEASE: let note_uri = event.id.toNostrUri() | ||
// UNCOMMENT_ON_RELEASE: console.log(` Event (URI): ${note_uri}`); | ||
// 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 | ||
|
||
} | ||
|
||
module.exports.run = 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