From 7aebcfc43f4ea28b705d0a65e8239f9ffe5e5dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 30 Apr 2025 12:21:51 +0400 Subject: [PATCH] Add nprofile property to profile model --- models/profile.ts | 7 +++++++ tests/models/article_test.ts | 2 +- tests/models/profile_test.ts | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/models/profile.ts b/models/profile.ts index f213fa0..b354c06 100644 --- a/models/profile.ts +++ b/models/profile.ts @@ -59,6 +59,13 @@ export default class Profile { return nip19.npubEncode(this.pubkey); } + get nprofile(): string { + return nip19.nprofileEncode({ + pubkey: this.pubkey, + relays: [config.relay_urls[0]], + }); + } + get profileUrl(): string { return `${config.base_url}/@${this.username}`; } diff --git a/tests/models/article_test.ts b/tests/models/article_test.ts index 4519ec7..6d52076 100644 --- a/tests/models/article_test.ts +++ b/tests/models/article_test.ts @@ -69,7 +69,7 @@ describe("Article", () => { describe("#naddr", () => { it("returns a bech32 addressable event ID", () => { expect(article.naddr).toMatch( - /naddr1qvzqqqr4gupzq8meqkx80g3yuklzymy0qf/, + /^naddr1qvzqqqr4gupzq8meqkx80g3yuklzymy0qf/, ); }); }); diff --git a/tests/models/profile_test.ts b/tests/models/profile_test.ts index 42d2e54..4c18a0c 100644 --- a/tests/models/profile_test.ts +++ b/tests/models/profile_test.ts @@ -40,4 +40,12 @@ describe("Profile", () => { ); }); }); + + describe("#nprofile", () => { + it("returns a bech32 profile ID", () => { + expect(profile.nprofile).toMatch( + /^nprofile1qyt8wumn8ghj7mn0wd68ytntdaek6mmn9ehhyecqyq0hjpvvw73zfed7yf/, + ); + }); + }); });