mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a99188e4cf | ||
|
|
93b22e48a6 |
2
index.js
2
index.js
@@ -21,5 +21,3 @@ export {
|
|||||||
getPublicKey,
|
getPublicKey,
|
||||||
getBlankEvent
|
getBlankEvent
|
||||||
}
|
}
|
||||||
export * from './nip04'
|
|
||||||
export * from './nip05'
|
|
||||||
|
|||||||
3
nip04.js
3
nip04.js
@@ -1,11 +1,12 @@
|
|||||||
import {Buffer} from 'buffer'
|
import {Buffer} from 'buffer'
|
||||||
|
import randomBytes from 'randombytes'
|
||||||
import * as secp256k1 from '@noble/secp256k1'
|
import * as secp256k1 from '@noble/secp256k1'
|
||||||
|
|
||||||
export function encrypt(privkey, pubkey, text) {
|
export function encrypt(privkey, pubkey, text) {
|
||||||
const key = secp256k1.getSharedSecret(privkey, '02' + pubkey)
|
const key = secp256k1.getSharedSecret(privkey, '02' + pubkey)
|
||||||
const normalizedKey = getOnlyXFromFullSharedSecret(key)
|
const normalizedKey = getOnlyXFromFullSharedSecret(key)
|
||||||
|
|
||||||
let iv = crypto.randomFillSync(new Uint8Array(16))
|
let iv = Uint8Array.from(randomBytes(16))
|
||||||
var cipher = crypto.createCipheriv(
|
var cipher = crypto.createCipheriv(
|
||||||
'aes-256-cbc',
|
'aes-256-cbc',
|
||||||
Buffer.from(normalizedKey, 'hex'),
|
Buffer.from(normalizedKey, 'hex'),
|
||||||
|
|||||||
17
nip06.js
Normal file
17
nip06.js
Normal 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'))
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "0.6.5",
|
"version": "0.7.2",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -8,8 +8,11 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/secp256k1": "^1.3.0",
|
"@noble/secp256k1": "^1.3.0",
|
||||||
|
"bip39": "^3.0.4",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
|
"create-hmac": "^1.1.7",
|
||||||
"dns-packet": "^5.2.4",
|
"dns-packet": "^5.2.4",
|
||||||
|
"randombytes": "^2.1.0",
|
||||||
"websocket-polyfill": "^0.0.3"
|
"websocket-polyfill": "^0.0.3"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
Reference in New Issue
Block a user