Skip to content

Commit

Permalink
Merge pull request #7 from susumuota/fix-typo
Browse files Browse the repository at this point in the history
fix: typo.
  • Loading branch information
susumuota committed Apr 2, 2023
2 parents 128c48f + 8c06151 commit 6bdeaaa
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
34 changes: 14 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

## Installation

- Work in progress. See Development section for now.

```bash
npm install nostrain
```
Expand All @@ -18,8 +16,8 @@ npm install nostrain

### Generating a private key and a public key

```typescript
import { generatePrivateKey, getPublicKey } from '../dist/nostrain';
```javascript
import { generatePrivateKey, getPublicKey } from 'nostrain';

const sk = generatePrivateKey(); // `sk` is a hex string
const pk = getPublicKey(sk); // `pk` is a hex string
Expand All @@ -29,16 +27,15 @@ console.log({ sk, pk });

### Creating, signing and verifying events

```typescript
```javascript
import {
validateEvent,
verifySignature,
signEvent,
getEventHash,
generatePrivateKey,
getPublicKey
} from '../dist/nostrain';
import type { Event } from '../dist/index';
} from 'nostrain';

const privateKey = generatePrivateKey();

Expand All @@ -50,7 +47,7 @@ const event = {
pubkey: getPublicKey(privateKey),
id: '',
sig: '',
} as Event;
};

event.id = getEventHash(event);
event.sig = signEvent(event, privateKey);
Expand All @@ -74,8 +71,8 @@ See [src/references.test.ts](https://github.com/susumuota/nostrain/blob/main/src

### Querying profile data from a NIP-05 address

```typescript
import { nip05 } from '../dist/nostrain';
```javascript
import { nip05 } from 'nostrain';

const profile = await nip05.queryProfile('jb55.com');

Expand All @@ -84,15 +81,13 @@ console.log({ profile });

### Encoding and decoding NIP-19 codes

```typescript
import { nip19, generatePrivateKey, getPublicKey } from '../dist/nostrain';
import type { ProfilePointer } from '../dist/nip19';
```javascript
import { nip19, generatePrivateKey, getPublicKey } from 'nostrain';

{
const sk = generatePrivateKey();
const nsec = nip19.nsecEncode(sk);
const { type, data } = nip19.decode(nsec);

console.log({ sk, nsec, type, data });
}

Expand All @@ -109,21 +104,20 @@ import type { ProfilePointer } from '../dist/nip19';
'wss://relay.nostr.example.mydomain.example.com',
'wss://nostr.banana.com',
];
const nprofile = nip19.nprofileEncode({ pubkey: pk, relays } as ProfilePointer);
const nprofile = nip19.nprofileEncode({ pubkey: pk, relays });
const { type, data } = nip19.decode(nprofile);
console.log({ pk, relays, nprofile, type, data });
}
```

### Encrypting and decrypting direct messages

```typescript
```javascript
import crypto from 'node:crypto';

// @ts-ignore
globalThis.crypto = crypto;

import { nip04, getPublicKey, generatePrivateKey } from '../dist/nostrain';
import { nip04, getPublicKey, generatePrivateKey } from 'nostrain';

// sender
const sk1 = generatePrivateKey();
Expand All @@ -145,8 +139,8 @@ console.log({ message, ciphertext, plaintext });

### Performing and checking for delegation

```typescript
import { nip26, getPublicKey, generatePrivateKey } from '../dist/nostrain';
```javascript
import { nip26, getPublicKey, generatePrivateKey } from 'nostrain';

// delegator
const sk1 = generatePrivateKey();
Expand Down
2 changes: 2 additions & 0 deletions examples/delegation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com>
// SPDX-License-Identifier: MIT

// node examples/delegation.js

import { nip26, getPublicKey, generatePrivateKey } from 'nostrain';

// delegator
Expand Down
3 changes: 2 additions & 1 deletion examples/encrypt.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com>
// SPDX-License-Identifier: MIT

// node examples/encrypt.js

import crypto from 'node:crypto';

// @ts-ignore
globalThis.crypto = crypto;

import { nip04, getPublicKey, generatePrivateKey } from 'nostrain';
Expand Down
2 changes: 1 addition & 1 deletion examples/event.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com>
// SPDX-License-Identifier: MIT

// npx tsx examples/event.ts
// node examples/event.ts

import {
validateEvent,
Expand Down
2 changes: 1 addition & 1 deletion examples/keys.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com>
// SPDX-License-Identifier: MIT

// npx tsx examples/keys.ts
// node examples/keys.js

import { generatePrivateKey, getPublicKey } from 'nostrain';

Expand Down
2 changes: 2 additions & 0 deletions examples/nip05.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com>
// SPDX-License-Identifier: MIT

// node examples/nip05.js

import { nip05 } from 'nostrain';

const profile = await nip05.queryProfile('jb55.com');
Expand Down
3 changes: 2 additions & 1 deletion examples/npub.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-FileCopyrightText: 2023 Susumu OTA <1632335+susumuota@users.noreply.github.com>
// SPDX-License-Identifier: MIT

// node examples/npub.js

import { nip19, generatePrivateKey, getPublicKey } from 'nostrain';

{
const sk = generatePrivateKey();
const nsec = nip19.nsecEncode(sk);
const { type, data } = nip19.decode(nsec);

console.log({ sk, nsec, type, data });
}

Expand Down

0 comments on commit 6bdeaaa

Please sign in to comment.