mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
adjust packages exported.
This commit is contained in:
37
README.md
37
README.md
@@ -221,43 +221,6 @@ assert(data.pubkey === pk)
|
|||||||
assert(data.relays.length === 2)
|
assert(data.relays.length === 2)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Encrypting and decrypting direct messages
|
|
||||||
|
|
||||||
```js
|
|
||||||
import {nip44, getPublicKey, generatePrivateKey} from 'nostr-tools'
|
|
||||||
|
|
||||||
// sender
|
|
||||||
let sk1 = generatePrivateKey()
|
|
||||||
let pk1 = getPublicKey(sk1)
|
|
||||||
|
|
||||||
// receiver
|
|
||||||
let sk2 = generatePrivateKey()
|
|
||||||
let pk2 = getPublicKey(sk2)
|
|
||||||
|
|
||||||
// on the sender side
|
|
||||||
let message = 'hello'
|
|
||||||
let key = nip44.getSharedSecret(sk1, pk2)
|
|
||||||
let ciphertext = nip44.encrypt(key, message)
|
|
||||||
|
|
||||||
let event = {
|
|
||||||
kind: 4,
|
|
||||||
pubkey: pk1,
|
|
||||||
tags: [['p', pk2]],
|
|
||||||
content: ciphertext,
|
|
||||||
...otherProperties,
|
|
||||||
}
|
|
||||||
|
|
||||||
sendEvent(event)
|
|
||||||
|
|
||||||
// on the receiver side
|
|
||||||
sub.on('event', async event => {
|
|
||||||
let sender = event.pubkey
|
|
||||||
// pk1 === sender
|
|
||||||
let _key = nip44.getSharedSecret(sk2, pk1)
|
|
||||||
let plaintext = nip44.decrypt(_key, event.content)
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
### Using from the browser (if you don't want to use a bundler)
|
### Using from the browser (if you don't want to use a bundler)
|
||||||
|
|
||||||
```html
|
```html
|
||||||
|
|||||||
3
index.ts
3
index.ts
@@ -8,6 +8,7 @@ export * from './references.ts'
|
|||||||
export * as nip04 from './nip04.ts'
|
export * as nip04 from './nip04.ts'
|
||||||
export * as nip05 from './nip05.ts'
|
export * as nip05 from './nip05.ts'
|
||||||
export * as nip10 from './nip10.ts'
|
export * as nip10 from './nip10.ts'
|
||||||
|
export * as nip11 from './nip11.ts'
|
||||||
export * as nip13 from './nip13.ts'
|
export * as nip13 from './nip13.ts'
|
||||||
export * as nip18 from './nip18.ts'
|
export * as nip18 from './nip18.ts'
|
||||||
export * as nip19 from './nip19.ts'
|
export * as nip19 from './nip19.ts'
|
||||||
@@ -15,9 +16,9 @@ export * as nip21 from './nip21.ts'
|
|||||||
export * as nip25 from './nip25.ts'
|
export * as nip25 from './nip25.ts'
|
||||||
export * as nip27 from './nip27.ts'
|
export * as nip27 from './nip27.ts'
|
||||||
export * as nip28 from './nip28.ts'
|
export * as nip28 from './nip28.ts'
|
||||||
|
export * as nip30 from './nip30.ts'
|
||||||
export * as nip39 from './nip39.ts'
|
export * as nip39 from './nip39.ts'
|
||||||
export * as nip42 from './nip42.ts'
|
export * as nip42 from './nip42.ts'
|
||||||
export * as nip44 from './nip44.ts'
|
|
||||||
export * as nip47 from './nip47.ts'
|
export * as nip47 from './nip47.ts'
|
||||||
export * as nip57 from './nip57.ts'
|
export * as nip57 from './nip57.ts'
|
||||||
export * as nip98 from './nip98.ts'
|
export * as nip98 from './nip98.ts'
|
||||||
|
|||||||
15
package.json
15
package.json
@@ -69,6 +69,11 @@
|
|||||||
"require": "./lib/cjs/nip10.js",
|
"require": "./lib/cjs/nip10.js",
|
||||||
"types": "./lib/types/nip10.d.ts"
|
"types": "./lib/types/nip10.d.ts"
|
||||||
},
|
},
|
||||||
|
"./nip11": {
|
||||||
|
"import": "./lib/esm/nip11.js",
|
||||||
|
"require": "./lib/cjs/nip11.js",
|
||||||
|
"types": "./lib/types/nip11.d.ts"
|
||||||
|
},
|
||||||
"./nip13": {
|
"./nip13": {
|
||||||
"import": "./lib/esm/nip13.js",
|
"import": "./lib/esm/nip13.js",
|
||||||
"require": "./lib/cjs/nip13.js",
|
"require": "./lib/cjs/nip13.js",
|
||||||
@@ -104,6 +109,11 @@
|
|||||||
"require": "./lib/cjs/nip28.js",
|
"require": "./lib/cjs/nip28.js",
|
||||||
"types": "./lib/types/nip28.d.ts"
|
"types": "./lib/types/nip28.d.ts"
|
||||||
},
|
},
|
||||||
|
"./nip30": {
|
||||||
|
"import": "./lib/esm/nip30.js",
|
||||||
|
"require": "./lib/cjs/nip30.js",
|
||||||
|
"types": "./lib/types/nip30.d.ts"
|
||||||
|
},
|
||||||
"./nip39": {
|
"./nip39": {
|
||||||
"import": "./lib/esm/nip39.js",
|
"import": "./lib/esm/nip39.js",
|
||||||
"require": "./lib/cjs/nip39.js",
|
"require": "./lib/cjs/nip39.js",
|
||||||
@@ -114,11 +124,6 @@
|
|||||||
"require": "./lib/cjs/nip42.js",
|
"require": "./lib/cjs/nip42.js",
|
||||||
"types": "./lib/types/nip42.d.ts"
|
"types": "./lib/types/nip42.d.ts"
|
||||||
},
|
},
|
||||||
"./nip44": {
|
|
||||||
"import": "./lib/esm/nip44.js",
|
|
||||||
"require": "./lib/cjs/nip44.js",
|
|
||||||
"types": "./lib/types/nip44.d.ts"
|
|
||||||
},
|
|
||||||
"./nip57": {
|
"./nip57": {
|
||||||
"import": "./lib/esm/nip57.js",
|
"import": "./lib/esm/nip57.js",
|
||||||
"require": "./lib/cjs/nip57.js",
|
"require": "./lib/cjs/nip57.js",
|
||||||
|
|||||||
Reference in New Issue
Block a user