Skip to content

Commit

Permalink
including interface for nip07 (#403)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
antonioconselheiro committed May 26, 2024
1 parent 9f5984d commit 88454de
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions nip07.ts
Original file line number Diff line number Diff line change
@@ -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>
}
}
3 changes: 2 additions & 1 deletion nip46.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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', []))
}

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ export class Relay extends AbstractRelay {
}
}

export type RelayRecord = Record<string, { read: boolean; write: boolean }>;

export * from './abstract-relay.ts'

0 comments on commit 88454de

Please sign in to comment.