mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-10 17:18:51 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c538efa38 | ||
|
|
013daae91b | ||
|
|
75660e7ff1 |
@@ -3,22 +3,6 @@ import fetch from 'node-fetch'
|
|||||||
|
|
||||||
import { useFetchImplementation, queryProfile, NIP05_REGEX, isNip05 } from './nip05.ts'
|
import { useFetchImplementation, queryProfile, NIP05_REGEX, isNip05 } from './nip05.ts'
|
||||||
|
|
||||||
test('fetch nip05 profiles', async () => {
|
|
||||||
useFetchImplementation(fetch)
|
|
||||||
|
|
||||||
let p1 = await queryProfile('jb55.com')
|
|
||||||
expect(p1!.pubkey).toEqual('32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245')
|
|
||||||
expect(p1!.relays).toEqual(['wss://relay.damus.io'])
|
|
||||||
|
|
||||||
let p2 = await queryProfile('jb55@jb55.com')
|
|
||||||
expect(p2!.pubkey).toEqual('32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245')
|
|
||||||
expect(p2!.relays).toEqual(['wss://relay.damus.io'])
|
|
||||||
|
|
||||||
let p3 = await queryProfile('_@fiatjaf.com')
|
|
||||||
expect(p3!.pubkey).toEqual('3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d')
|
|
||||||
expect(p3!.relays).toEqual(['wss://pyramid.fiatjaf.com', 'wss://nos.lol'])
|
|
||||||
})
|
|
||||||
|
|
||||||
test('validate NIP05_REGEX', () => {
|
test('validate NIP05_REGEX', () => {
|
||||||
expect(NIP05_REGEX.test('_@bob.com.br')).toBeTrue()
|
expect(NIP05_REGEX.test('_@bob.com.br')).toBeTrue()
|
||||||
expect(NIP05_REGEX.test('bob@bob.com.br')).toBeTrue()
|
expect(NIP05_REGEX.test('bob@bob.com.br')).toBeTrue()
|
||||||
@@ -30,3 +14,14 @@ test('validate NIP05_REGEX', () => {
|
|||||||
expect(isNip05('bob@bob.com.br')).toBeTrue()
|
expect(isNip05('bob@bob.com.br')).toBeTrue()
|
||||||
expect(isNip05('b&b@bob.com.br')).toBeFalse()
|
expect(isNip05('b&b@bob.com.br')).toBeFalse()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('fetch nip05 profiles', async () => {
|
||||||
|
useFetchImplementation(fetch)
|
||||||
|
|
||||||
|
let p2 = await queryProfile('compile-error.net')
|
||||||
|
expect(p2!.pubkey).toEqual('2c7cc62a697ea3a7826521f3fd34f0cb273693cbe5e9310f35449f43622a5cdc')
|
||||||
|
|
||||||
|
let p3 = await queryProfile('_@fiatjaf.com')
|
||||||
|
expect(p3!.pubkey).toEqual('3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d')
|
||||||
|
expect(p3!.relays).toEqual(['wss://pyramid.fiatjaf.com', 'wss://nos.lol'])
|
||||||
|
})
|
||||||
|
|||||||
4
nip28.ts
4
nip28.ts
@@ -1,5 +1,5 @@
|
|||||||
import { Event, finalizeEvent } from './pure.ts'
|
import { Event, finalizeEvent } from './pure.ts'
|
||||||
import { ChannelCreation, ChannelHideMessage, ChannelMessage, ChannelMetadata, ChannelMuteUser } from './kinds.ts'
|
import { ChannelCreation, ChannelHideMessage, ChannelMessage, ChannelMetadata as KindChannelMetadata, ChannelMuteUser } from './kinds.ts'
|
||||||
|
|
||||||
export interface ChannelMetadata {
|
export interface ChannelMetadata {
|
||||||
name: string
|
name: string
|
||||||
@@ -78,7 +78,7 @@ export const channelMetadataEvent = (t: ChannelMetadataEventTemplate, privateKey
|
|||||||
|
|
||||||
return finalizeEvent(
|
return finalizeEvent(
|
||||||
{
|
{
|
||||||
kind: ChannelMetadata,
|
kind: KindChannelMetadata,
|
||||||
tags: [['e', t.channel_create_event_id], ...(t.tags ?? [])],
|
tags: [['e', t.channel_create_event_id], ...(t.tags ?? [])],
|
||||||
content: content,
|
content: content,
|
||||||
created_at: t.created_at,
|
created_at: t.created_at,
|
||||||
|
|||||||
7
nip46.ts
7
nip46.ts
@@ -89,6 +89,8 @@ export class BunkerSigner {
|
|||||||
private secretKey: Uint8Array
|
private secretKey: Uint8Array
|
||||||
public bp: BunkerPointer
|
public bp: BunkerPointer
|
||||||
|
|
||||||
|
private cachedPubKey: string | undefined
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of the Nip46 class.
|
* Creates a new instance of the Nip46 class.
|
||||||
* @param relays - An array of relay addresses.
|
* @param relays - An array of relay addresses.
|
||||||
@@ -213,7 +215,10 @@ export class BunkerSigner {
|
|||||||
* pubkey may be different.)
|
* pubkey may be different.)
|
||||||
*/
|
*/
|
||||||
async getPublicKey(): Promise<string> {
|
async getPublicKey(): Promise<string> {
|
||||||
return await this.sendRequest('get_public_key', [])
|
if (!this.cachedPubKey) {
|
||||||
|
this.cachedPubKey = await this.sendRequest('get_public_key', [])
|
||||||
|
}
|
||||||
|
return this.cachedPubKey
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.9.0",
|
"version": "2.9.1",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user