nostr-tools 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +142 -0
- package/.prettierrc.yaml +4 -3
- package/event.js +1 -1
- package/nip04.js +36 -0
- package/package.json +2 -2
- package/utils.js +1 -1
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parserOptions": {
|
|
3
|
+
"ecmaVersion": 9,
|
|
4
|
+
"ecmaFeatures": {
|
|
5
|
+
"jsx": true
|
|
6
|
+
},
|
|
7
|
+
"sourceType": "module",
|
|
8
|
+
"allowImportExportEverywhere": false
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
"env": {
|
|
12
|
+
"es6": true,
|
|
13
|
+
"node": true
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
"plugins": [
|
|
17
|
+
"babel"
|
|
18
|
+
],
|
|
19
|
+
|
|
20
|
+
"globals": {
|
|
21
|
+
"document": false,
|
|
22
|
+
"navigator": false,
|
|
23
|
+
"window": false,
|
|
24
|
+
"location": false,
|
|
25
|
+
"URL": false,
|
|
26
|
+
"URLSearchParams": false,
|
|
27
|
+
"fetch": false,
|
|
28
|
+
"EventSource": false,
|
|
29
|
+
"localStorage": false,
|
|
30
|
+
"sessionStorage": false
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
"rules": {
|
|
34
|
+
"accessor-pairs": 2,
|
|
35
|
+
"arrow-spacing": [2, { "before": true, "after": true }],
|
|
36
|
+
"block-spacing": [2, "always"],
|
|
37
|
+
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
|
|
38
|
+
"comma-dangle": 0,
|
|
39
|
+
"comma-spacing": [2, { "before": false, "after": true }],
|
|
40
|
+
"comma-style": [2, "last"],
|
|
41
|
+
"constructor-super": 2,
|
|
42
|
+
"curly": [0, "multi-line"],
|
|
43
|
+
"dot-location": [2, "property"],
|
|
44
|
+
"eol-last": 2,
|
|
45
|
+
"eqeqeq": [2, "allow-null"],
|
|
46
|
+
"generator-star-spacing": [2, { "before": true, "after": true }],
|
|
47
|
+
"handle-callback-err": [2, "^(err|error)$" ],
|
|
48
|
+
"indent": 0,
|
|
49
|
+
"jsx-quotes": [2, "prefer-double"],
|
|
50
|
+
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
|
|
51
|
+
"keyword-spacing": [2, { "before": true, "after": true }],
|
|
52
|
+
"new-cap": 0,
|
|
53
|
+
"new-parens": 0,
|
|
54
|
+
"no-array-constructor": 2,
|
|
55
|
+
"no-caller": 2,
|
|
56
|
+
"no-class-assign": 2,
|
|
57
|
+
"no-cond-assign": 2,
|
|
58
|
+
"no-const-assign": 2,
|
|
59
|
+
"no-control-regex": 0,
|
|
60
|
+
"no-debugger": 0,
|
|
61
|
+
"no-delete-var": 2,
|
|
62
|
+
"no-dupe-args": 2,
|
|
63
|
+
"no-dupe-class-members": 2,
|
|
64
|
+
"no-dupe-keys": 2,
|
|
65
|
+
"no-duplicate-case": 2,
|
|
66
|
+
"no-empty-character-class": 2,
|
|
67
|
+
"no-empty-pattern": 2,
|
|
68
|
+
"no-eval": 0,
|
|
69
|
+
"no-ex-assign": 2,
|
|
70
|
+
"no-extend-native": 2,
|
|
71
|
+
"no-extra-bind": 2,
|
|
72
|
+
"no-extra-boolean-cast": 2,
|
|
73
|
+
"no-extra-parens": [2, "functions"],
|
|
74
|
+
"no-fallthrough": 2,
|
|
75
|
+
"no-floating-decimal": 2,
|
|
76
|
+
"no-func-assign": 2,
|
|
77
|
+
"no-implied-eval": 2,
|
|
78
|
+
"no-inner-declarations": [0, "functions"],
|
|
79
|
+
"no-invalid-regexp": 2,
|
|
80
|
+
"no-irregular-whitespace": 2,
|
|
81
|
+
"no-iterator": 2,
|
|
82
|
+
"no-label-var": 2,
|
|
83
|
+
"no-labels": [2, { "allowLoop": false, "allowSwitch": false }],
|
|
84
|
+
"no-lone-blocks": 2,
|
|
85
|
+
"no-mixed-spaces-and-tabs": 2,
|
|
86
|
+
"no-multi-spaces": 2,
|
|
87
|
+
"no-multi-str": 2,
|
|
88
|
+
"no-multiple-empty-lines": [2, { "max": 2 }],
|
|
89
|
+
"no-native-reassign": 2,
|
|
90
|
+
"no-negated-in-lhs": 2,
|
|
91
|
+
"no-new": 0,
|
|
92
|
+
"no-new-func": 2,
|
|
93
|
+
"no-new-object": 2,
|
|
94
|
+
"no-new-require": 2,
|
|
95
|
+
"no-new-symbol": 2,
|
|
96
|
+
"no-new-wrappers": 2,
|
|
97
|
+
"no-obj-calls": 2,
|
|
98
|
+
"no-octal": 2,
|
|
99
|
+
"no-octal-escape": 2,
|
|
100
|
+
"no-path-concat": 0,
|
|
101
|
+
"no-proto": 2,
|
|
102
|
+
"no-redeclare": 2,
|
|
103
|
+
"no-regex-spaces": 2,
|
|
104
|
+
"no-return-assign": 0,
|
|
105
|
+
"no-self-assign": 2,
|
|
106
|
+
"no-self-compare": 2,
|
|
107
|
+
"no-sequences": 2,
|
|
108
|
+
"no-shadow-restricted-names": 2,
|
|
109
|
+
"no-spaced-func": 2,
|
|
110
|
+
"no-sparse-arrays": 2,
|
|
111
|
+
"no-this-before-super": 2,
|
|
112
|
+
"no-throw-literal": 2,
|
|
113
|
+
"no-trailing-spaces": 2,
|
|
114
|
+
"no-undef": 2,
|
|
115
|
+
"no-undef-init": 2,
|
|
116
|
+
"no-unexpected-multiline": 2,
|
|
117
|
+
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
|
|
118
|
+
"no-unreachable": 2,
|
|
119
|
+
"no-unused-vars": [2, { "vars": "local", "args": "none", "varsIgnorePattern": "^_"}],
|
|
120
|
+
"no-useless-call": 2,
|
|
121
|
+
"no-useless-constructor": 2,
|
|
122
|
+
"no-with": 2,
|
|
123
|
+
"one-var": [0, { "initialized": "never" }],
|
|
124
|
+
"operator-linebreak": [2, "after", { "overrides": { "?": "before", ":": "before" } }],
|
|
125
|
+
"padded-blocks": [2, "never"],
|
|
126
|
+
"quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
|
|
127
|
+
"semi": [2, "never"],
|
|
128
|
+
"semi-spacing": [2, { "before": false, "after": true }],
|
|
129
|
+
"space-before-blocks": [2, "always"],
|
|
130
|
+
"space-before-function-paren": 0,
|
|
131
|
+
"space-in-parens": [2, "never"],
|
|
132
|
+
"space-infix-ops": 2,
|
|
133
|
+
"space-unary-ops": [2, { "words": true, "nonwords": false }],
|
|
134
|
+
"spaced-comment": 0,
|
|
135
|
+
"template-curly-spacing": [2, "never"],
|
|
136
|
+
"use-isnan": 2,
|
|
137
|
+
"valid-typeof": 2,
|
|
138
|
+
"wrap-iife": [2, "any"],
|
|
139
|
+
"yield-star-spacing": [2, "both"],
|
|
140
|
+
"yoda": [0]
|
|
141
|
+
}
|
|
142
|
+
}
|
package/.prettierrc.yaml
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
semi: false
|
|
1
2
|
arrowParens: avoid
|
|
2
|
-
|
|
3
|
-
jsxBracketSameLine: false
|
|
3
|
+
insertPragma: false
|
|
4
4
|
printWidth: 80
|
|
5
5
|
proseWrap: preserve
|
|
6
|
-
semi: false
|
|
7
6
|
singleQuote: true
|
|
8
7
|
trailingComma: none
|
|
9
8
|
useTabs: false
|
|
9
|
+
jsxBracketSameLine: false
|
|
10
|
+
bracketSpacing: false
|
package/event.js
CHANGED
package/nip04.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as secp256k1 from '@noble/secp256k1'
|
|
2
|
+
|
|
3
|
+
export function encrypt(privkey, pubkey, text) {
|
|
4
|
+
const key = secp256k1.getSharedSecret(privkey, '02' + pubkey)
|
|
5
|
+
const normalizedKey = getOnlyXFromFullSharedSecret(key)
|
|
6
|
+
|
|
7
|
+
let iv = crypto.randomFillSync(new Uint8Array(16))
|
|
8
|
+
var cipher = crypto.createCipheriv(
|
|
9
|
+
'aes-256-cbc',
|
|
10
|
+
Buffer.from(normalizedKey, 'hex'),
|
|
11
|
+
iv
|
|
12
|
+
)
|
|
13
|
+
let encryptedMessage = cipher.update(text, 'utf8', 'base64')
|
|
14
|
+
encryptedMessage += cipher.final('base64')
|
|
15
|
+
|
|
16
|
+
return [encryptedMessage, Buffer.from(iv.buffer).toString('base64')]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function decrypt(privkey, pubkey, ciphertext, iv) {
|
|
20
|
+
const key = secp256k1.getSharedSecret(privkey, '02' + pubkey)
|
|
21
|
+
const normalizedKey = getOnlyXFromFullSharedSecret(key)
|
|
22
|
+
|
|
23
|
+
var decipher = crypto.createDecipheriv(
|
|
24
|
+
'aes-256-cbc',
|
|
25
|
+
Buffer.from(normalizedKey, 'hex'),
|
|
26
|
+
Buffer.from(iv, 'base64')
|
|
27
|
+
)
|
|
28
|
+
let decryptedMessage = decipher.update(ciphertext, 'base64')
|
|
29
|
+
decryptedMessage += decipher.final('utf8')
|
|
30
|
+
|
|
31
|
+
return decryptedMessage
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getOnlyXFromFullSharedSecret(fullSharedSecretCoordinates) {
|
|
35
|
+
return fullSharedSecretCoordinates.substr(2, 64)
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nostr-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Tools for making a Nostr client.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"url": "https://github.com/fiatjaf/nostr-tools.git"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"@noble/secp256k1": "^1.3.0",
|
|
11
12
|
"buffer": "^6.0.3",
|
|
12
13
|
"dns-packet": "^5.2.4",
|
|
13
|
-
"noble-secp256k1": "^1.1.1",
|
|
14
14
|
"websocket-polyfill": "^0.0.3"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
package/utils.js
CHANGED