Compare commits
No commits in common. "1fb77669e62c24b279419c315bc78d8098bea882" and "36dd76a88f68424ea82fc7e82997b5e69693f8e2" have entirely different histories.
1fb77669e6
...
36dd76a88f
|
|
@ -1,34 +0,0 @@
|
||||||
import { nip19 } from 'nostr-tools';
|
|
||||||
import { HABLA_BASE } from './config';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Argumente für NIP-19 addressable-event-Pointer.
|
|
||||||
* Validierung (hex-Länge etc.) wird an `nip19.naddrEncode` delegiert.
|
|
||||||
*/
|
|
||||||
export interface NaddrArgs {
|
|
||||||
pubkey: string;
|
|
||||||
kind: number;
|
|
||||||
identifier: string;
|
|
||||||
relays?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Baut einen `naddr1…`-Bech32-String (NIP-19) für ein addressable Event.
|
|
||||||
* Wird u. a. für Habla.news-Deep-Links genutzt.
|
|
||||||
*/
|
|
||||||
export function buildNaddr(args: NaddrArgs): string {
|
|
||||||
return nip19.naddrEncode({
|
|
||||||
pubkey: args.pubkey,
|
|
||||||
kind: args.kind,
|
|
||||||
identifier: args.identifier,
|
|
||||||
relays: args.relays ?? []
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Habla.news-Deep-Link auf ein addressable Event.
|
|
||||||
* Fallback für „Post nicht gefunden" / JS-lose Clients.
|
|
||||||
*/
|
|
||||||
export function buildHablaLink(args: NaddrArgs): string {
|
|
||||||
return `${HABLA_BASE}${buildNaddr(args)}`;
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
import { describe, expect, it } from 'vitest';
|
|
||||||
import { buildHablaLink } from '$lib/nostr/naddr';
|
|
||||||
|
|
||||||
describe('buildHablaLink', () => {
|
|
||||||
it('erzeugt einen habla.news/a/-Link mit naddr1-Bech32', () => {
|
|
||||||
const link = buildHablaLink({
|
|
||||||
pubkey: '4fa5d1c413e2b45e10d40bf3562ab701a5331206e359c90baae0e99bfd6c6e41',
|
|
||||||
kind: 30023,
|
|
||||||
identifier: 'dezentrale-oep-oer',
|
|
||||||
relays: ['wss://relay.damus.io'],
|
|
||||||
});
|
|
||||||
expect(link).toMatch(/^https:\/\/habla\.news\/a\/naddr1[a-z0-9]+$/);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('ist deterministisch für gleiche Inputs', () => {
|
|
||||||
const args = {
|
|
||||||
pubkey: '4fa5d1c413e2b45e10d40bf3562ab701a5331206e359c90baae0e99bfd6c6e41',
|
|
||||||
kind: 30023,
|
|
||||||
identifier: 'foo',
|
|
||||||
relays: ['wss://relay.damus.io'],
|
|
||||||
};
|
|
||||||
expect(buildHablaLink(args)).toBe(buildHablaLink(args));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('funktioniert ohne relays (optional)', () => {
|
|
||||||
const link = buildHablaLink({
|
|
||||||
pubkey: '4fa5d1c413e2b45e10d40bf3562ab701a5331206e359c90baae0e99bfd6c6e41',
|
|
||||||
kind: 30023,
|
|
||||||
identifier: 'foo',
|
|
||||||
});
|
|
||||||
expect(link).toMatch(/^https:\/\/habla\.news\/a\/naddr1[a-z0-9]+$/);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('erzeugt unterschiedliche Links für unterschiedliche Inputs', () => {
|
|
||||||
const base = {
|
|
||||||
pubkey: '4fa5d1c413e2b45e10d40bf3562ab701a5331206e359c90baae0e99bfd6c6e41',
|
|
||||||
kind: 30023,
|
|
||||||
relays: [],
|
|
||||||
};
|
|
||||||
const a = buildHablaLink({ ...base, identifier: 'foo' });
|
|
||||||
const b = buildHablaLink({ ...base, identifier: 'bar' });
|
|
||||||
expect(a).not.toBe(b);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Loading…
Reference in New Issue