diff --git a/README.md b/README.md index 215e6ea..82e2b59 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,17 @@ import { useFetchImplementation } from 'nostr-tools/nip05' useFetchImplementation(require('node-fetch')) ``` +### Including NIP-07 types +```js +import { Nip07 } from 'nostr-tools/nip07' + +declare global { + interface Window { + nostr?: Nip07; + } +} +``` + ### Encoding and decoding NIP-19 codes ```js diff --git a/index.ts b/index.ts index dd80f8b..5e2fb0e 100644 --- a/index.ts +++ b/index.ts @@ -6,6 +6,7 @@ export * from './references.ts' export * as nip04 from './nip04.ts' export * as nip05 from './nip05.ts' +export * as nip07 from './nip07.ts' export * as nip10 from './nip10.ts' export * as nip11 from './nip11.ts' export * as nip13 from './nip13.ts' diff --git a/jsr.json b/jsr.json index 8e52c9d..08f195f 100644 --- a/jsr.json +++ b/jsr.json @@ -16,6 +16,7 @@ "./nip04": "./nip04.ts", "./nip05": "./nip05.ts", "./nip06": "./nip06.ts", + "./nip07": "./nip07.ts", "./nip10": "./nip10.ts", "./nip11": "./nip11.ts", "./nip13": "./nip13.ts", diff --git a/nip07.ts b/nip07.ts new file mode 100644 index 0000000..ed32363 --- /dev/null +++ b/nip07.ts @@ -0,0 +1,16 @@ +import { EventTemplate, NostrEvent } from './core.ts' +import { RelayRecord } from './index.ts' + +export interface Nip07 { + getPublicKey(): Promise + signEvent(event: EventTemplate): Promise + getRelays(): Promise + nip04?: { + encrypt(pubkey: string, plaintext: string): Promise + ecrypt(pubkey: string, ciphertext: string): Promise + } + nip44?: { + encrypt(pubkey: string, plaintext: string): Promise + decrypt(pubkey: string, ciphertext: string): Promise + } +} diff --git a/nip46.ts b/nip46.ts index 3352cb0..9fb1481 100644 --- a/nip46.ts +++ b/nip46.ts @@ -7,6 +7,7 @@ import { NIP05_REGEX } from './nip05.ts' import { SimplePool } from './pool.ts' import { Handlerinformation, NostrConnect } from './kinds.ts' import { hexToBytes } from '@noble/hashes/utils' +import { RelayRecord } from './index.ts' var _fetch: any @@ -216,7 +217,7 @@ export class BunkerSigner { /** * Calls the "get_relays" method on the bunker. */ - async getRelays(): Promise<{ [relay: string]: { read: boolean; write: boolean } }> { + async getRelays(): Promise { return JSON.parse(await this.sendRequest('get_relays', [])) } diff --git a/package.json b/package.json index 5ec4150..755ad9a 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,9 @@ "require": "./lib/cjs/nip06.js", "types": "./lib/types/nip06.d.ts" }, + "./nip07": { + "types": "./lib/types/nip07.d.ts" + }, "./nip10": { "import": "./lib/esm/nip10.js", "require": "./lib/cjs/nip10.js", diff --git a/relay.ts b/relay.ts index acdb678..2753b5e 100644 --- a/relay.ts +++ b/relay.ts @@ -20,4 +20,6 @@ export class Relay extends AbstractRelay { } } +export type RelayRecord = Record; + export * from './abstract-relay.ts'