Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lightning-digital-entertainment/nodestr

A nip07 provider and polyfill for NodeJS
https://github.com/lightning-digital-entertainment/nodestr

Last synced: 24 days ago
JSON representation

A nip07 provider and polyfill for NodeJS

Awesome Lists containing this project

README

        

# nodestr

A nip07 provider and polyfill for node js.

Depends on the _@nostr-tools_ package.

## Installation

```
npm i nodestr
```

## Implementation Roadmap

- [x] signEvent
- [x] getPublicKey
- [ ] encrypt
- [ ] decrypt
- [ ] NIP46 Support

## Usage

```js
const { Nip07Provider } = require("nodestr");

// Instantiate the NIP07Provider with a ConfigObject and register its methods on the global object.
new Nip07Provider({
secretKeyMethod: "file",
keyFilePath: "/your/path/to/keyfile",
}).register();

// Once the provider is registered it will polyfill the global window object with nip07 methods:
window.nostr
.signEvent({
kind: 1,
content: "This is a test",
tags: [],
created_at: Math.floor(Date.now() / 1000),
})
.then((event) => {
console.log(event);
});

window.nostr.getPublicKey().then((pubkey) => {
console.log(pubkey);
});
```

### Config Object

- secretKeyMethod
- throwaway: create a new key for this process and save it in memory
- file: read a key from a utf-8 encoded text file
- nip46: WIP - Communicate with a remote signer as per NIP-46
- keyFilePath: The path to a local key file (Required when secretKeyMethod is 'file').

```ts
type ProviderConfig = {
secretKeyMethod: "throwaway" | "file" | "nip46";
keyFilePath?: string;
};
```