Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/penpenpng/nip07-awaiter
https://github.com/penpenpng/nip07-awaiter
nip-07 nostr
Last synced: 27 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/penpenpng/nip07-awaiter
- Owner: penpenpng
- License: mit
- Created: 2023-10-03T13:14:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-09T15:08:39.000Z (4 months ago)
- Last Synced: 2024-09-10T20:01:19.155Z (3 months ago)
- Topics: nip-07, nostr
- Language: TypeScript
- Homepage:
- Size: 94.7 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nostr - nip07-awaiter - awaiter.svg?style=social) - Minimal utility to access NIP-07 interface safely. (Libraries / Client reviews and/or comparisons)
README
# nip07-awaiter
**nip07-awaiter** provides a few utilities to detect initialization of [NIP-07](https://github.com/nostr-protocol/nips/blob/master/07.md) interface (`window.nostr`).
## Installation
```
npm install nip07-awaiter
```or
```html
```
## Usage
### `waitNostr()`
Return a promise. It is to be resolved as `window.nostr` when it is installed or as soon as possible thereafter.
If `window.nostr` is not installed after waiting the given time, it is to be resolved as `undefined`.```js
import { waitNostr } from "nip07-awaiter";// It will be resolved as `window.nostr` or `undefined` within 1 sec.
const nostrOrUndefined = await waitNostr(1000);
```If needed, you can pass a [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). When aborted `waitNostr()` rejects and return the reason.
```js
const controller = new AbortController();
const { signal } = controller;waitNostr(10 * 1000, { signal });
```### `getNostr()`
`getNostr()` return synchronously NIP-07 interface if exists.
```js
import { getNostr } from "nip07-awaiter";const pubkey = await getNostr()?.getPublicKey();
```### `isNostr()`
`isNostr()` is a type gurad function. Return true if the given value is a NIP-07 extension.
```js
import { isNostr } from "nip07-awaiter";if (isNostr(window.nostr)) {
console.log(await window.nostr.getPublicKey());
}
```