Compare commits

...

4 Commits

Author SHA1 Message Date
fiatjaf
02cacd4446 return sub object from .sub() and other methods. 2021-12-12 06:47:52 -03:00
fiatjaf
a99188e4cf remove log line for events with invalid signature. 2021-12-12 05:54:48 -03:00
fiatjaf
93b22e48a6 add nip06. 2021-12-11 19:46:51 -03:00
fiatjaf
57b9bac9b1 end the rollup madness, just ship the source. 2021-12-11 09:01:52 -03:00
7 changed files with 30 additions and 34 deletions

View File

@@ -21,5 +21,3 @@ export {
getPublicKey,
getBlankEvent
}
export * from './nip04'
export * from './nip05'

View File

@@ -1,11 +1,12 @@
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 = crypto.randomFillSync(new Uint8Array(16))
let iv = Uint8Array.from(randomBytes(16))
var cipher = crypto.createCipheriv(
'aes-256-cbc',
Buffer.from(normalizedKey, 'hex'),

17
nip06.js Normal file
View File

@@ -0,0 +1,17 @@
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'))
}

View File

@@ -1,18 +1,18 @@
{
"name": "nostr-tools",
"version": "0.6.4",
"version": "0.8.0",
"description": "Tools for making a Nostr client.",
"main": "dist/nostr-tools.esm.min.js",
"module": "dist/nostr-tools.esm.min.js",
"browser": "dist/nostr-tools.umd.min.js",
"repository": {
"type": "git",
"url": "https://github.com/fiatjaf/nostr-tools.git"
},
"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": [
@@ -26,11 +26,5 @@
"censorship",
"censorship-resistance",
"client"
],
"devDependencies": {
"rollup": "^2.61.1"
},
"scripts": {
"prepublish": "rollup -c"
}
]
}

View File

@@ -29,19 +29,23 @@ 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())

View File

@@ -84,8 +84,6 @@ export function relayConnect(url, onNotice) {
if (channels[channel]) {
channels[channel](event)
}
} else {
console.warn('got event with invalid signature from ' + url, event)
}
return
}

View File

@@ -1,16 +0,0 @@
import pkg from './package.json'
export default {
input: 'index.js',
output: [
{
name: 'nostrtools',
file: pkg.browser,
format: 'umd'
},
{
file: pkg.module,
format: 'es'
}
]
}