mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31ab318387 |
2
index.js
2
index.js
@@ -21,3 +21,5 @@ export {
|
||||
getPublicKey,
|
||||
getBlankEvent
|
||||
}
|
||||
export * from './nip04'
|
||||
export * from './nip05'
|
||||
|
||||
3
nip04.js
3
nip04.js
@@ -1,12 +1,11 @@
|
||||
import {Buffer} from 'buffer'
|
||||
import randomBytes from 'randombytes'
|
||||
import * as secp256k1 from '@noble/secp256k1'
|
||||
|
||||
export function encrypt(privkey, pubkey, text) {
|
||||
const key = secp256k1.getSharedSecret(privkey, '02' + pubkey)
|
||||
const normalizedKey = getOnlyXFromFullSharedSecret(key)
|
||||
|
||||
let iv = Uint8Array.from(randomBytes(16))
|
||||
let iv = crypto.randomFillSync(new Uint8Array(16))
|
||||
var cipher = crypto.createCipheriv(
|
||||
'aes-256-cbc',
|
||||
Buffer.from(normalizedKey, 'hex'),
|
||||
|
||||
17
nip06.js
17
nip06.js
@@ -1,17 +0,0 @@
|
||||
import createHmac from 'create-hmac'
|
||||
import randomBytes from 'randombytes'
|
||||
import * as bip39 from 'bip39'
|
||||
|
||||
export function privateKeyFromSeed(seed) {
|
||||
let hmac = createHmac('sha512', Buffer.from('Nostr seed', 'utf8'))
|
||||
hmac.update(seed)
|
||||
return hmac.digest().slice(0, 32).toString('hex')
|
||||
}
|
||||
|
||||
export function seedFromWords(mnemonic) {
|
||||
return bip39.mnemonicToSeedSync(mnemonic)
|
||||
}
|
||||
|
||||
export function generateSeedWords() {
|
||||
return bip39.entropyToMnemonic(randomBytes(16).toString('hex'))
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nostr-tools",
|
||||
"version": "0.8.0",
|
||||
"version": "0.6.5",
|
||||
"description": "Tools for making a Nostr client.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -8,11 +8,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@noble/secp256k1": "^1.3.0",
|
||||
"bip39": "^3.0.4",
|
||||
"buffer": "^6.0.3",
|
||||
"create-hmac": "^1.1.7",
|
||||
"dns-packet": "^5.2.4",
|
||||
"randombytes": "^2.1.0",
|
||||
"websocket-polyfill": "^0.0.3"
|
||||
},
|
||||
"keywords": [
|
||||
|
||||
8
pool.js
8
pool.js
@@ -29,23 +29,19 @@ export function relayPool(globalPrivateKey) {
|
||||
const activeFilters = filter
|
||||
|
||||
activeSubscriptions[id] = {
|
||||
sub: ({cb = activeCallback, filter = activeFilters}) => {
|
||||
sub: ({cb = activeCallback, filter = activeFilters}) =>
|
||||
Object.entries(subControllers).map(([relayURL, sub]) => [
|
||||
relayURL,
|
||||
sub.sub({cb, filter}, id)
|
||||
])
|
||||
return activeSubscriptions[id]
|
||||
},
|
||||
]),
|
||||
addRelay: relay => {
|
||||
subControllers[relay.url] = relay.sub({cb, filter})
|
||||
return activeSubscriptions[id]
|
||||
},
|
||||
removeRelay: relayURL => {
|
||||
if (relayURL in subControllers) {
|
||||
subControllers[relayURL].unsub()
|
||||
if (Object.keys(subControllers).length === 0) unsub()
|
||||
}
|
||||
return activeSubscriptions[id]
|
||||
},
|
||||
unsub: () => {
|
||||
Object.values(subControllers).forEach(sub => sub.unsub())
|
||||
|
||||
2
relay.js
2
relay.js
@@ -84,6 +84,8 @@ export function relayConnect(url, onNotice) {
|
||||
if (channels[channel]) {
|
||||
channels[channel](event)
|
||||
}
|
||||
} else {
|
||||
console.warn('got event with invalid signature from ' + url, event)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
16
rollup.config.js
Normal file
16
rollup.config.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import pkg from './package.json'
|
||||
|
||||
export default {
|
||||
input: 'index.js',
|
||||
output: [
|
||||
{
|
||||
name: 'nostrtools',
|
||||
file: pkg.browser,
|
||||
format: 'umd'
|
||||
},
|
||||
{
|
||||
file: pkg.module,
|
||||
format: 'es'
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user