node-red-contrib-nostr 0.1.6 → 0.2.2
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/dist/core/event.js +4 -4
- package/dist/crypto/keys.d.ts +0 -2
- package/dist/crypto/keys.js +18 -66
- package/dist/nips/nip04.js +7 -40
- package/package.json +11 -11
package/dist/core/event.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EventBuilder = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
5
|
+
const utils_js_1 = require("@noble/hashes/utils.js");
|
|
6
6
|
const keys_1 = require("../crypto/keys");
|
|
7
7
|
class EventBuilder {
|
|
8
8
|
static async createEvent(kind, content, privateKey, tags = []) {
|
|
@@ -26,7 +26,7 @@ class EventBuilder {
|
|
|
26
26
|
event.tags,
|
|
27
27
|
event.content
|
|
28
28
|
]);
|
|
29
|
-
event.id = (0,
|
|
29
|
+
event.id = (0, utils_js_1.bytesToHex)((0, sha2_js_1.sha256)(Buffer.from(serialized)));
|
|
30
30
|
// Sign the event
|
|
31
31
|
event.sig = await this.keyManager.sign(privateKey, event.id);
|
|
32
32
|
return event;
|
|
@@ -46,7 +46,7 @@ class EventBuilder {
|
|
|
46
46
|
event.tags,
|
|
47
47
|
event.content
|
|
48
48
|
]);
|
|
49
|
-
const id = (0,
|
|
49
|
+
const id = (0, utils_js_1.bytesToHex)((0, sha2_js_1.sha256)(Buffer.from(serialized)));
|
|
50
50
|
if (id !== event.id) {
|
|
51
51
|
return false;
|
|
52
52
|
}
|
package/dist/crypto/keys.d.ts
CHANGED
|
@@ -29,8 +29,6 @@ export declare function npubToHex(npub: string): string;
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function getPublicKey(privateKeyHex: string): Promise<string>;
|
|
31
31
|
export declare class KeyManager {
|
|
32
|
-
private secp256k1Promise;
|
|
33
|
-
constructor();
|
|
34
32
|
generatePrivateKey(): Promise<string>;
|
|
35
33
|
getPublicKey(privateKey: string): Promise<string>;
|
|
36
34
|
sign(privateKey: string, message: string): Promise<string>;
|
package/dist/crypto/keys.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.KeyManager = void 0;
|
|
37
4
|
exports.getDefaultReaderKeys = getDefaultReaderKeys;
|
|
@@ -39,9 +6,10 @@ exports.generateKeyPair = generateKeyPair;
|
|
|
39
6
|
exports.hexToNpub = hexToNpub;
|
|
40
7
|
exports.npubToHex = npubToHex;
|
|
41
8
|
exports.getPublicKey = getPublicKey;
|
|
9
|
+
const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
|
|
42
10
|
const bech32_1 = require("bech32");
|
|
43
|
-
const
|
|
44
|
-
const
|
|
11
|
+
const utils_js_1 = require("@noble/hashes/utils.js");
|
|
12
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
45
13
|
// Lazily-initialized ephemeral key pair for read-only operations.
|
|
46
14
|
// Generated at first use so no secret material is stored in source code.
|
|
47
15
|
let _defaultReaderKeys = null;
|
|
@@ -51,24 +19,16 @@ async function getDefaultReaderKeys() {
|
|
|
51
19
|
}
|
|
52
20
|
return _defaultReaderKeys;
|
|
53
21
|
}
|
|
54
|
-
let secp256k1;
|
|
55
|
-
async function initSecp256k1() {
|
|
56
|
-
if (!secp256k1) {
|
|
57
|
-
secp256k1 = await Promise.resolve().then(() => __importStar(require('@noble/secp256k1')));
|
|
58
|
-
}
|
|
59
|
-
return secp256k1;
|
|
60
|
-
}
|
|
61
22
|
/**
|
|
62
23
|
* Generate a new Nostr key pair
|
|
63
24
|
* @returns {Promise<Object>} Object containing private and public keys
|
|
64
25
|
*/
|
|
65
26
|
async function generateKeyPair() {
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const publicKey = secp.getPublicKey(privateKey, true);
|
|
27
|
+
const privateKey = secp256k1_js_1.secp256k1.utils.randomSecretKey();
|
|
28
|
+
const publicKey = secp256k1_js_1.secp256k1.getPublicKey(privateKey, true);
|
|
69
29
|
return {
|
|
70
|
-
privateKey:
|
|
71
|
-
publicKey:
|
|
30
|
+
privateKey: (0, utils_js_1.bytesToHex)(privateKey),
|
|
31
|
+
publicKey: (0, utils_js_1.bytesToHex)(publicKey)
|
|
72
32
|
};
|
|
73
33
|
}
|
|
74
34
|
/**
|
|
@@ -95,34 +55,26 @@ function npubToHex(npub) {
|
|
|
95
55
|
* @returns {Promise<string>} Public key in hex format
|
|
96
56
|
*/
|
|
97
57
|
async function getPublicKey(privateKeyHex) {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
return Buffer.from(publicKey).toString('hex');
|
|
58
|
+
const publicKey = secp256k1_js_1.secp256k1.getPublicKey((0, utils_js_1.hexToBytes)(privateKeyHex), true);
|
|
59
|
+
return (0, utils_js_1.bytesToHex)(publicKey);
|
|
101
60
|
}
|
|
102
61
|
class KeyManager {
|
|
103
|
-
constructor() {
|
|
104
|
-
this.secp256k1Promise = initSecp256k1();
|
|
105
|
-
}
|
|
106
62
|
async generatePrivateKey() {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
return Buffer.from(privateKey).toString('hex');
|
|
63
|
+
const privateKey = secp256k1_js_1.secp256k1.utils.randomSecretKey();
|
|
64
|
+
return (0, utils_js_1.bytesToHex)(privateKey);
|
|
110
65
|
}
|
|
111
66
|
async getPublicKey(privateKey) {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
return Buffer.from(publicKey).toString('hex');
|
|
67
|
+
const publicKey = secp256k1_js_1.secp256k1.getPublicKey((0, utils_js_1.hexToBytes)(privateKey), true);
|
|
68
|
+
return (0, utils_js_1.bytesToHex)(publicKey);
|
|
115
69
|
}
|
|
116
70
|
async sign(privateKey, message) {
|
|
117
|
-
const
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
return (0, utils_1.bytesToHex)(signature.toCompactRawBytes());
|
|
71
|
+
const messageHash = (0, sha2_js_1.sha256)(new TextEncoder().encode(message));
|
|
72
|
+
const signature = secp256k1_js_1.secp256k1.sign(messageHash, (0, utils_js_1.hexToBytes)(privateKey));
|
|
73
|
+
return (0, utils_js_1.bytesToHex)(signature);
|
|
121
74
|
}
|
|
122
75
|
async verify(publicKey, message, signature) {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
return secp.verify(signature, messageHash, publicKey);
|
|
76
|
+
const messageHash = (0, sha2_js_1.sha256)(new TextEncoder().encode(message));
|
|
77
|
+
return secp256k1_js_1.secp256k1.verify((0, utils_js_1.hexToBytes)(signature), messageHash, (0, utils_js_1.hexToBytes)(publicKey));
|
|
126
78
|
}
|
|
127
79
|
}
|
|
128
80
|
exports.KeyManager = KeyManager;
|
package/dist/nips/nip04.js
CHANGED
|
@@ -1,55 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.NIP04 = void 0;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
4
|
+
const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
|
|
5
|
+
const utils_js_1 = require("@noble/hashes/utils.js");
|
|
6
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
40
7
|
const event_1 = require("../core/event");
|
|
41
8
|
class NIP04 {
|
|
42
9
|
static async encrypt(privateKey, publicKey, _text) {
|
|
43
|
-
const sharedPoint = secp256k1.getSharedSecret((0,
|
|
10
|
+
const sharedPoint = secp256k1_js_1.secp256k1.getSharedSecret((0, utils_js_1.hexToBytes)(privateKey), (0, utils_js_1.hexToBytes)(publicKey));
|
|
44
11
|
const sharedX = sharedPoint.slice(1, 33);
|
|
45
12
|
// In a real implementation, we'd use this shared secret with
|
|
46
13
|
// proper encryption. This is just a placeholder.
|
|
47
|
-
const key = (0,
|
|
14
|
+
const key = (0, sha2_js_1.sha256)(sharedX);
|
|
48
15
|
// TODO: Implement actual encryption using AES-256-CBC
|
|
49
|
-
return (0,
|
|
16
|
+
return (0, utils_js_1.bytesToHex)(key);
|
|
50
17
|
}
|
|
51
18
|
static async decrypt(privateKey, publicKey, _encryptedText) {
|
|
52
|
-
const sharedPoint = secp256k1.getSharedSecret((0,
|
|
19
|
+
const sharedPoint = secp256k1_js_1.secp256k1.getSharedSecret((0, utils_js_1.hexToBytes)(privateKey), (0, utils_js_1.hexToBytes)(publicKey));
|
|
53
20
|
const _sharedX = sharedPoint.slice(1, 33);
|
|
54
21
|
// TODO: Implement actual decryption using AES-256-CBC
|
|
55
22
|
return "decrypted text";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-nostr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Node-RED nodes for seamless Nostr protocol integration. Features robust WebSocket handling, event filtering, and NPUB-based routing. Built with TypeScript for type safety and extensive testing. Perfect for Nostr automation flows.",
|
|
5
5
|
"author": "vveerrgg",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -49,30 +49,30 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@noble/
|
|
53
|
-
"@noble/
|
|
52
|
+
"@noble/curves": "^2.0.1",
|
|
53
|
+
"@noble/hashes": "^2.0.1",
|
|
54
54
|
"bech32": "^2.0.0",
|
|
55
|
-
"nostr-tools": "^
|
|
56
|
-
"nostr-websocket-utils": "
|
|
55
|
+
"nostr-tools": "^2.23.3",
|
|
56
|
+
"nostr-websocket-utils": "file:../nostr-websocket-utils",
|
|
57
57
|
"ws": "^8.19.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@eslint/js": "^10.0.1",
|
|
61
|
-
"@types/node": "^
|
|
61
|
+
"@types/node": "^22.19.15",
|
|
62
62
|
"@types/node-red": "^1.3.5",
|
|
63
63
|
"@types/ws": "^8.18.1",
|
|
64
64
|
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
65
65
|
"@typescript-eslint/parser": "^8.56.0",
|
|
66
|
-
"@vitest/coverage-v8": "^
|
|
67
|
-
"@vitest/ui": "^
|
|
68
|
-
"eslint": "^10.0.
|
|
66
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
67
|
+
"@vitest/ui": "^4.0.18",
|
|
68
|
+
"eslint": "^10.0.3",
|
|
69
69
|
"node-red": "^4.1.5",
|
|
70
70
|
"node-red-node-test-helper": "^0.3.6",
|
|
71
71
|
"typescript": "^5.9.3",
|
|
72
|
-
"vitest": "^
|
|
72
|
+
"vitest": "^4.0.18"
|
|
73
73
|
},
|
|
74
74
|
"engines": {
|
|
75
|
-
"node": ">=
|
|
75
|
+
"node": ">=18.0.0"
|
|
76
76
|
},
|
|
77
77
|
"repository": {
|
|
78
78
|
"type": "git",
|