including interface for nip07 (#403)

* including interface for nip07

* fix types for NIP-07

* including NIP-07 export to jsr

* fix readme about nip07

* including in nip7 interface an output signature compatible with the event returned by the signer
This commit is contained in:
António Conselheiro
2024-05-26 11:58:12 -03:00
committed by GitHub
parent 9f5984d78d
commit 88454de628
7 changed files with 36 additions and 1 deletions

View File

@@ -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

View File

@@ -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'

View File

@@ -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",

16
nip07.ts Normal file
View File

@@ -0,0 +1,16 @@
import { EventTemplate, NostrEvent } from './core.ts'
import { RelayRecord } from './index.ts'
export interface Nip07 {
getPublicKey(): Promise<string>
signEvent(event: EventTemplate): Promise<NostrEvent>
getRelays(): Promise<RelayRecord>
nip04?: {
encrypt(pubkey: string, plaintext: string): Promise<string>
ecrypt(pubkey: string, ciphertext: string): Promise<string>
}
nip44?: {
encrypt(pubkey: string, plaintext: string): Promise<string>
decrypt(pubkey: string, ciphertext: string): Promise<string>
}
}

View File

@@ -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<RelayRecord> {
return JSON.parse(await this.sendRequest('get_relays', []))
}

View File

@@ -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",

View File

@@ -20,4 +20,6 @@ export class Relay extends AbstractRelay {
}
}
export type RelayRecord = Record<string, { read: boolean; write: boolean }>;
export * from './abstract-relay.ts'