Skip to content

Commit

Permalink
update readme to mention fragment importing and nostr-wasm.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Dec 19, 2023
1 parent 9648de3 commit 6127b6f
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,35 @@ assert(data.pubkey === pk)
assert(data.relays.length === 2)
```

## Import modes

### Using just the packages you want

Importing the entirety of `nostr-tools` may bloat your build, so you should probably import individual packages instead:

```js
import { generateSecretKey, finalizeEvent, verifyEvent } from 'nostr-tools/pure'
import { matchFilter } from 'nostr-tools/filter'
import { decode, nprofileEncode, neventEncode, npubEncode } from 'nostr-tools/nip19'
// and so on and so forth
```

### Using it with `nostr-wasm`

[`nostr-wasm`](https://github.com/fiatjaf/nostr-wasm) is a thin wrapper over [libsecp256k1](https://github.com/bitcoin-core/secp256k1) compiled to WASM just for hashing, signing and verifying Nostr events.

```js
import { setNostrWasm, generateSecretKey, finalizeEvent, verifyEvent } from 'nostr-tools/pure'
import { initNostrWasm } from 'nostr-wasm'

initNostrWasm().then(setNostrWasm)

// or use 'nostr-wasm/gzipped' or even 'nostr-wasm/headless',
// see https://www.npmjs.com/package/nostr-wasm for options
```

This may be faster than the pure-JS [noble libraries](https://paulmillr.com/noble/) used by default and in `nostr-tools/pure`.

### Using from the browser (if you don't want to use a bundler)

```html
Expand All @@ -213,8 +242,7 @@ assert(data.relays.length === 2)

## Plumbing

1. Install [`just`](https://just.systems/)
2. `just -l`
To develop `nostr-tools`, install [`just`](https://just.systems/) and run `just -l` to see commands available.

## License

Expand Down

0 comments on commit 6127b6f

Please sign in to comment.