solid-ui 2.4.27-9f7a01da → 2.4.27-a15832a6

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/lib/chat/keys.js DELETED
@@ -1,183 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.generatePrivateKey = generatePrivateKey;
9
- exports.generatePublicKey = generatePublicKey;
10
- exports.getPrivateKey = getPrivateKey;
11
- exports.getPublicKey = getPublicKey;
12
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
- var debug = _interopRequireWildcard(require("../debug"));
15
- var _secp256k = require("@noble/curves/secp256k1");
16
- var _utils = require("@noble/hashes/utils");
17
- var _signature = require("./signature");
18
- var _solidLogic = require("solid-logic");
19
- var $rdf = _interopRequireWildcard(require("rdflib"));
20
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
- function generatePrivateKey() {
23
- return (0, _utils.bytesToHex)(_secp256k.schnorr.utils.randomPrivateKey());
24
- }
25
- function generatePublicKey(privateKey) {
26
- return (0, _utils.bytesToHex)(_secp256k.schnorr.getPublicKey(privateKey));
27
- }
28
- function getPublicKey(webId) {
29
- var publicKey = publicKeyExists(webId);
30
- return publicKey;
31
- }
32
- var pubKeyUrl = function pubKeyUrl(webId) {
33
- var url = new URL(webId);
34
- var publicKeyUrl = url.origin + '/profile/keys/publicKey.ttl';
35
- return publicKeyUrl;
36
- };
37
- function publicKeyExists(_x) {
38
- return _publicKeyExists.apply(this, arguments);
39
- }
40
- function _publicKeyExists() {
41
- _publicKeyExists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
42
- var publicKey;
43
- return _regenerator["default"].wrap(function _callee$(_context) {
44
- while (1) switch (_context.prev = _context.next) {
45
- case 0:
46
- _context.next = 2;
47
- return _solidLogic.store.fetcher.load(pubKeyUrl(webId));
48
- case 2:
49
- // url.href)
50
- publicKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'PublicKey'));
51
- return _context.abrupt("return", publicKey === null || publicKey === void 0 ? void 0 : publicKey.value);
52
- case 4:
53
- case "end":
54
- return _context.stop();
55
- }
56
- }, _callee);
57
- }));
58
- return _publicKeyExists.apply(this, arguments);
59
- }
60
- var privKeyUrl = function privKeyUrl(webId) {
61
- var url = new URL(webId);
62
- var privateKeyUrl = url.origin + '/profile/keys/privateKey.ttl';
63
- return privateKeyUrl;
64
- };
65
- function privateKeyExists(_x2) {
66
- return _privateKeyExists.apply(this, arguments);
67
- }
68
- function _privateKeyExists() {
69
- _privateKeyExists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(webId) {
70
- var privateKeyUrl, privateKey, _err$response, data, contentType, response;
71
- return _regenerator["default"].wrap(function _callee2$(_context2) {
72
- while (1) switch (_context2.prev = _context2.next) {
73
- case 0:
74
- /* const url = new URL(webId)
75
- const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl' */
76
- privateKeyUrl = privKeyUrl(webId);
77
- /* debug.warn('Alain privateKeyExists')
78
- debug.warn(webId)
79
- debug.warn(privateKeyUrl) */
80
- _context2.prev = 1;
81
- _context2.next = 4;
82
- return _solidLogic.store.fetcher.load(privateKeyUrl);
83
- case 4:
84
- privateKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'PrivateKey'));
85
- return _context2.abrupt("return", privateKey === null || privateKey === void 0 ? void 0 : privateKey.value);
86
- case 8:
87
- _context2.prev = 8;
88
- _context2.t0 = _context2["catch"](1);
89
- if (!((_context2.t0 === null || _context2.t0 === void 0 ? void 0 : (_err$response = _context2.t0.response) === null || _err$response === void 0 ? void 0 : _err$response.status) === 404)) {
90
- _context2.next = 25;
91
- break;
92
- }
93
- _context2.prev = 11;
94
- // create privateKey resource
95
- data = '';
96
- contentType = 'text/ttl';
97
- _context2.next = 16;
98
- return _solidLogic.store.fetcher.webOperation('PUT', privateKeyUrl, {
99
- data: data,
100
- contentType: contentType
101
- });
102
- case 16:
103
- response = _context2.sent;
104
- _context2.next = 23;
105
- break;
106
- case 19:
107
- _context2.prev = 19;
108
- _context2.t1 = _context2["catch"](11);
109
- debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context2.t1);
110
- throw _context2.t1;
111
- case 23:
112
- delete _solidLogic.store.fetcher.requested[privateKeyUrl]; // delete cached 404 error
113
- return _context2.abrupt("return", undefined);
114
- case 25:
115
- debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context2.t0);
116
- throw _context2.t0;
117
- case 27:
118
- case "end":
119
- return _context2.stop();
120
- }
121
- }, _callee2, null, [[1, 8], [11, 19]]);
122
- }));
123
- return _privateKeyExists.apply(this, arguments);
124
- }
125
- function getPrivateKey(_x3) {
126
- return _getPrivateKey.apply(this, arguments);
127
- }
128
- function _getPrivateKey() {
129
- _getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(webId) {
130
- var publicKeyUrl, privateKeyUrl, publicKey, privateKey, del, add;
131
- return _regenerator["default"].wrap(function _callee3$(_context3) {
132
- while (1) switch (_context3.prev = _context3.next) {
133
- case 0:
134
- /* const url = new URL(webId)
135
- url.hash = '' */
136
- /* const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl' */
137
- publicKeyUrl = pubKeyUrl(webId);
138
- privateKeyUrl = privKeyUrl(webId); // find publickey
139
- _context3.next = 4;
140
- return publicKeyExists(webId);
141
- case 4:
142
- publicKey = _context3.sent;
143
- _context3.next = 7;
144
- return privateKeyExists(webId);
145
- case 7:
146
- privateKey = _context3.sent;
147
- // debug.warn('privateKey ' + privateKey)
148
- if (privateKey && publicKey !== generatePublicKey(privateKey)) debug.warn('publicKey is not valid');
149
-
150
- // simulate new key pair
151
- /* const newPrivateKey = generatePrivateKey()
152
- const newPublicKey = generatePublicKey(newPrivateKey)
153
- debug.log('newPrivateKey ' + newPrivateKey)
154
- debug.log('newPublicKey ' + newPublicKey) */
155
-
156
- // create key pair
157
- if (!(!privateKey || !publicKey)) {
158
- _context3.next = 20;
159
- break;
160
- }
161
- del = [];
162
- add = [];
163
- if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PrivateKey'), $rdf.lit(privateKey), $rdf.sym(privateKeyUrl)));
164
- if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PublicKey'), $rdf.lit(publicKey), $rdf.sym(publicKeyUrl)));
165
- privateKey = generatePrivateKey();
166
- publicKey = generatePublicKey(privateKey);
167
- /* debug.log('newPrivateKey-1 ' + privateKey)
168
- debug.log('newPublicKey-1 ' + publicKey) */
169
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PrivateKey'), $rdf.literal(privateKey), $rdf.sym(privateKeyUrl)));
170
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PublicKey'), $rdf.literal(publicKey), $rdf.sym(publicKeyUrl)));
171
- _context3.next = 20;
172
- return _solidLogic.store.updater.updateMany(del, add);
173
- case 20:
174
- return _context3.abrupt("return", privateKey);
175
- case 21:
176
- case "end":
177
- return _context3.stop();
178
- }
179
- }, _callee3);
180
- }));
181
- return _getPrivateKey.apply(this, arguments);
182
- }
183
- //# sourceMappingURL=keys.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keys.js","names":["debug","_interopRequireWildcard","require","_secp256k","_utils","_signature","_solidLogic","$rdf","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","generatePrivateKey","bytesToHex","schnorr","utils","randomPrivateKey","generatePublicKey","privateKey","getPublicKey","webId","publicKey","publicKeyExists","pubKeyUrl","url","URL","publicKeyUrl","origin","_x","_publicKeyExists","apply","arguments","_asyncToGenerator2","_regenerator","mark","_callee","wrap","_callee$","_context","prev","next","store","fetcher","load","any","sym","CERT","abrupt","value","stop","privKeyUrl","privateKeyUrl","privateKeyExists","_x2","_privateKeyExists","_callee2","_err$response","data","contentType","response","_callee2$","_context2","t0","status","webOperation","sent","t1","log","requested","undefined","getPrivateKey","_x3","_getPrivateKey","_callee3","del","add","_callee3$","_context3","warn","push","st","lit","literal","updater","updateMany"],"sources":["../../src/chat/keys.ts"],"sourcesContent":["import * as debug from '../debug'\r\nimport { schnorr } from '@noble/curves/secp256k1'\r\nimport { bytesToHex } from '@noble/hashes/utils'\r\nimport { CERT } from './signature'\r\nimport { store } from 'solid-logic'\r\nimport * as $rdf from 'rdflib'\r\nimport { NamedNode, literal } from 'rdflib'\r\n\r\nexport function generatePrivateKey (): string {\r\n return bytesToHex(schnorr.utils.randomPrivateKey())\r\n}\r\n\r\nexport function generatePublicKey (privateKey: string): string {\r\n return bytesToHex(schnorr.getPublicKey(privateKey))\r\n}\r\n\r\nexport function getPublicKey (webId) {\r\n const publicKey = publicKeyExists(webId)\r\n return publicKey\r\n}\r\n\r\nconst pubKeyUrl = (webId: string) => {\r\n const url = new URL(webId)\r\n const publicKeyUrl = url.origin + '/profile/keys/publicKey.ttl'\r\n return publicKeyUrl\r\n}\r\n\r\nasync function publicKeyExists (webId: string) {\r\n // find publickey\r\n /* const url = new URL(webId)\r\n url.hash = '' */\r\n /* debug.warn('Alain publicKeyExists')\r\n debug.warn(webId)\r\n debug.warn(url.href) */\r\n await store.fetcher.load(pubKeyUrl(webId)) // url.href)\r\n const publicKey = store.any(store.sym(webId), store.sym(CERT + 'PublicKey'))\r\n return publicKey?.value // as NamedNode\r\n}\r\n\r\nconst privKeyUrl = (webId: string) => {\r\n const url = new URL(webId)\r\n const privateKeyUrl = url.origin + '/profile/keys/privateKey.ttl'\r\n return privateKeyUrl\r\n}\r\n\r\nasync function privateKeyExists (webId: string) {\r\n /* const url = new URL(webId)\r\n const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl' */\r\n const privateKeyUrl = privKeyUrl(webId)\r\n /* debug.warn('Alain privateKeyExists')\r\n debug.warn(webId)\r\n debug.warn(privateKeyUrl) */\r\n try {\r\n await store.fetcher.load(privateKeyUrl)\r\n const privateKey = store.any(store.sym(webId), store.sym(CERT + 'PrivateKey'))\r\n return privateKey?.value // as NamedNode\r\n } catch (err) {\r\n if (err?.response?.status === 404) {\r\n try {\r\n // create privateKey resource\r\n const data = ''\r\n const contentType = 'text/ttl'\r\n const response = await store.fetcher.webOperation('PUT', privateKeyUrl, {\r\n data,\r\n contentType\r\n })\r\n // create ACL resource\r\n } catch (err) {\r\n debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + err)\r\n throw err\r\n }\r\n delete store.fetcher.requested[privateKeyUrl] // delete cached 404 error\r\n return undefined\r\n }\r\n debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + err)\r\n throw err\r\n }\r\n}\r\n\r\nexport async function getPrivateKey (webId: string) {\r\n /* const url = new URL(webId)\r\n url.hash = '' */\r\n /* const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl' */\r\n const publicKeyUrl = pubKeyUrl(webId)\r\n const privateKeyUrl = privKeyUrl(webId)\r\n\r\n // find publickey\r\n let publicKey = await publicKeyExists(webId)\r\n // debug.warn('publicKey ' + publicKey)\r\n // find privateKey\r\n let privateKey = await privateKeyExists(webId)\r\n // debug.warn('privateKey ' + privateKey)\r\n if (privateKey && (publicKey !== generatePublicKey(privateKey as string))) debug.warn('publicKey is not valid')\r\n\r\n // simulate new key pair\r\n /* const newPrivateKey = generatePrivateKey()\r\n const newPublicKey = generatePublicKey(newPrivateKey)\r\n debug.log('newPrivateKey ' + newPrivateKey)\r\n debug.log('newPublicKey ' + newPublicKey) */\r\n\r\n // create key pair\r\n if (!privateKey || !publicKey) {\r\n const del: any[] = []\r\n const add: any[] = []\r\n if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PrivateKey'), $rdf.lit(privateKey), $rdf.sym(privateKeyUrl)))\r\n if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PublicKey'), $rdf.lit(publicKey), $rdf.sym(publicKeyUrl)))\r\n\r\n privateKey = generatePrivateKey()\r\n publicKey = generatePublicKey(privateKey)\r\n /* debug.log('newPrivateKey-1 ' + privateKey)\r\n debug.log('newPublicKey-1 ' + publicKey) */\r\n add.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PrivateKey'), $rdf.literal(privateKey), $rdf.sym(privateKeyUrl)))\r\n add.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PublicKey'), $rdf.literal(publicKey), $rdf.sym(publicKeyUrl)))\r\n await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AG,EAAEC,GAAG,CAAC;QAAA;UAAA,OAAAE,SAAA,CAAA9B,MAAA,WAEnC7B,UAAU;QAAA;QAAA;UAAA,OAAA2D,SAAA,CAAA5B,IAAA;MAAA;IAAA,GAAAwB,QAAA;EAAA,CAClB;EAAA,OAAAD,cAAA,CAAA1C,KAAA,OAAAC,SAAA;AAAA"}
@@ -1,27 +0,0 @@
1
- export declare const utf8Decoder: TextDecoder;
2
- export declare const utf8Encoder: TextEncoder;
3
- export declare const SEC = "https://w3id.org/security#";
4
- export declare const CERT = "http://www.w3.org/ns/auth/cert#";
5
- export type MsgTemplate = {
6
- id: string;
7
- created: string;
8
- dateDeleted: string;
9
- content: string;
10
- maker: string;
11
- sig: string;
12
- };
13
- export type UnsignedMsg = MsgTemplate & {
14
- pubkey: string;
15
- };
16
- export type Message = UnsignedMsg & {
17
- id: string;
18
- sig: string;
19
- };
20
- export declare function getBlankMsg(): MsgTemplate;
21
- export declare function finishMsg(t: MsgTemplate, privateKey: string): Message;
22
- export declare function serializeMsg(msg: UnsignedMsg): string;
23
- export declare function getMsgHash(message: UnsignedMsg): string;
24
- export declare function validateMsg<T>(message: T): message is T & UnsignedMsg;
25
- export declare function verifySignature(sig: string, message: Message, pubKey: string): boolean;
26
- export declare function signMsg(message: UnsignedMsg, key: string): string;
27
- //# sourceMappingURL=signature.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/chat/signature.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,WAAW,aAA2B,CAAA;AACnD,eAAO,MAAM,WAAW,aAAoB,CAAA;AAE5C,eAAO,MAAM,GAAG,+BAA+B,CAAA;AAC/C,eAAO,MAAM,IAAI,oCAAoC,CAAA;AA2BrD,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,wBAAgB,WAAW,IAAK,WAAW,CAS1C;AAED,wBAAgB,SAAS,CAAE,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAOtE;AAED,wBAAgB,YAAY,CAAE,GAAG,EAAE,WAAW,GAAG,MAAM,CAMtD;AAED,wBAAgB,UAAU,CAAE,OAAO,EAAE,WAAW,UAG/C;AAID,wBAAgB,WAAW,CAAC,CAAC,EAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,WAAW,CAkBtE;AAED,wBAAgB,eAAe,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAMvF;AAED,wBAAgB,OAAO,CAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIlE"}
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SEC = exports.CERT = void 0;
7
- exports.finishMsg = finishMsg;
8
- exports.getBlankMsg = getBlankMsg;
9
- exports.getMsgHash = getMsgHash;
10
- exports.serializeMsg = serializeMsg;
11
- exports.signMsg = signMsg;
12
- exports.utf8Encoder = exports.utf8Decoder = void 0;
13
- exports.validateMsg = validateMsg;
14
- exports.verifySignature = verifySignature;
15
- var _secp256k = require("@noble/curves/secp256k1");
16
- var _utils = require("@noble/hashes/utils");
17
- var _sha = require("@noble/hashes/sha256");
18
- // import {utf8Encoder} from './utils'
19
- // import { getPublicKey } from './keys'
20
-
21
- var utf8Decoder = new TextDecoder('utf-8');
22
- exports.utf8Decoder = utf8Decoder;
23
- var utf8Encoder = new TextEncoder();
24
- exports.utf8Encoder = utf8Encoder;
25
- var SEC = 'https://w3id.org/security#'; // Proof, VerificationMethod
26
- exports.SEC = SEC;
27
- var CERT = 'http://www.w3.org/ns/auth/cert#'; // PrivateKey, PublicKey
28
-
29
- /* eslint-disable no-unused-vars */
30
- /* export enum Kind {
31
- Metadata = 0,
32
- Text = 1,
33
- RecommendRelay = 2,
34
- Contacts = 3,
35
- EncryptedDirectMessage = 4,
36
- EventDeletion = 5,
37
- Reaction = 7,
38
- BadgeAward = 8,
39
- ChannelCreation = 40,
40
- ChannelMetadata = 41,
41
- ChannelMessage = 42,
42
- ChannelHideMessage = 43,
43
- ChannelMuteUser = 44,
44
- Report = 1984,
45
- ZapRequest = 9734,
46
- Zap = 9735,
47
- RelayList = 10002,
48
- ClientAuth = 22242,
49
- BadgeDefinition = 30008,
50
- ProfileBadge = 30009,
51
- Article = 30023
52
- } */
53
- exports.CERT = CERT;
54
- function getBlankMsg() {
55
- return {
56
- id: '',
57
- created: '',
58
- dateDeleted: '',
59
- content: '',
60
- maker: '',
61
- sig: ''
62
- };
63
- }
64
- function finishMsg(t, privateKey) {
65
- // to update to chat message triples
66
- var message = t;
67
- // message.pubkey = getPublicKey(privateKey)
68
- message.id = getMsgHash(message);
69
- message.sig = signMsg(message, privateKey);
70
- return message;
71
- }
72
- function serializeMsg(msg) {
73
- // to update to chat messages triples
74
- /* if (!validateMsg(msg))
75
- throw new Error("can't serialize message with wrong or missing properties") */
76
-
77
- return JSON.stringify(msg);
78
- }
79
- function getMsgHash(message) {
80
- var msgHash = (0, _sha.sha256)(utf8Encoder.encode(serializeMsg(message)));
81
- return (0, _utils.bytesToHex)(msgHash);
82
- }
83
- var isRecord = function isRecord(obj) {
84
- return obj instanceof Object;
85
- };
86
- function validateMsg(message) {
87
- /* if (!isRecord(message)) return false
88
- if (typeof message.kind !== 'number') return false
89
- if (typeof message.content !== 'string') return false
90
- if (typeof message.created_at !== 'number') return false
91
- if (typeof message.pubkey !== 'string') return false
92
- if (!message.pubkey.match(/^[a-f0-9]{64}$/)) return false
93
- if (!Array.isArray(message.tags)) return false
94
- for (let i = 0; i < message.tags.length; i++) {
95
- let tag = message.tags[i]
96
- if (!Array.isArray(tag)) return false
97
- for (let j = 0; j < tag.length; j++) {
98
- if (typeof tag[j] === 'object') return false
99
- }
100
- } */
101
-
102
- return true;
103
- }
104
- function verifySignature(sig, message, pubKey) {
105
- return _secp256k.schnorr.verify(sig, getMsgHash(message), pubKey);
106
- }
107
- function signMsg(message, key) {
108
- return (0, _utils.bytesToHex)(_secp256k.schnorr.sign(getMsgHash(message), key));
109
- }
110
- //# sourceMappingURL=signature.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signature.js","names":["_secp256k","require","_utils","_sha","utf8Decoder","TextDecoder","exports","utf8Encoder","TextEncoder","SEC","CERT","getBlankMsg","id","created","dateDeleted","content","maker","sig","finishMsg","t","privateKey","message","getMsgHash","signMsg","serializeMsg","msg","JSON","stringify","msgHash","sha256","encode","bytesToHex","isRecord","obj","Object","validateMsg","verifySignature","pubKey","schnorr","verify","key","sign"],"sources":["../../src/chat/signature.ts"],"sourcesContent":["import { schnorr } from '@noble/curves/secp256k1'\r\nimport { bytesToHex } from '@noble/hashes/utils'\r\nimport { sha256 } from '@noble/hashes/sha256'\r\n\r\n// import {utf8Encoder} from './utils'\r\n// import { getPublicKey } from './keys'\r\n\r\nexport const utf8Decoder = new TextDecoder('utf-8')\r\nexport const utf8Encoder = new TextEncoder()\r\n\r\nexport const SEC = 'https://w3id.org/security#' // Proof, VerificationMethod\r\nexport const CERT = 'http://www.w3.org/ns/auth/cert#' // PrivateKey, PublicKey\r\n\r\n/* eslint-disable no-unused-vars */\r\n/* export enum Kind {\r\n Metadata = 0,\r\n Text = 1,\r\n RecommendRelay = 2,\r\n Contacts = 3,\r\n EncryptedDirectMessage = 4,\r\n EventDeletion = 5,\r\n Reaction = 7,\r\n BadgeAward = 8,\r\n ChannelCreation = 40,\r\n ChannelMetadata = 41,\r\n ChannelMessage = 42,\r\n ChannelHideMessage = 43,\r\n ChannelMuteUser = 44,\r\n Report = 1984,\r\n ZapRequest = 9734,\r\n Zap = 9735,\r\n RelayList = 10002,\r\n ClientAuth = 22242,\r\n BadgeDefinition = 30008,\r\n ProfileBadge = 30009,\r\n Article = 30023\r\n} */\r\n\r\nexport type MsgTemplate = {\r\n id: string\r\n created: string\r\n dateDeleted: string\r\n content: string\r\n maker: string\r\n sig: string\r\n}\r\n\r\nexport type UnsignedMsg = MsgTemplate & {\r\n pubkey: string\r\n}\r\n\r\nexport type Message = UnsignedMsg & {\r\n id: string\r\n sig: string\r\n}\r\n\r\nexport function getBlankMsg (): MsgTemplate {\r\n return {\r\n id: '',\r\n created: '',\r\n dateDeleted: '',\r\n content: '',\r\n maker: '',\r\n sig: ''\r\n }\r\n}\r\n\r\nexport function finishMsg (t: MsgTemplate, privateKey: string): Message {\r\n // to update to chat message triples\r\n const message = t as Message\r\n // message.pubkey = getPublicKey(privateKey)\r\n message.id = getMsgHash(message)\r\n message.sig = signMsg(message, privateKey)\r\n return message\r\n}\r\n\r\nexport function serializeMsg (msg: UnsignedMsg): string {\r\n // to update to chat messages triples\r\n /* if (!validateMsg(msg))\r\n throw new Error(\"can't serialize message with wrong or missing properties\") */\r\n\r\n return JSON.stringify(msg)\r\n}\r\n\r\nexport function getMsgHash (message: UnsignedMsg) {\r\n const msgHash = sha256(utf8Encoder.encode(serializeMsg(message)))\r\n return bytesToHex(msgHash)\r\n}\r\n\r\nconst isRecord = (obj: unknown): obj is Record<string, unknown> => obj instanceof Object\r\n\r\nexport function validateMsg<T> (message: T): message is T & UnsignedMsg {\r\n /* if (!isRecord(message)) return false\r\n if (typeof message.kind !== 'number') return false\r\n if (typeof message.content !== 'string') return false\r\n if (typeof message.created_at !== 'number') return false\r\n if (typeof message.pubkey !== 'string') return false\r\n if (!message.pubkey.match(/^[a-f0-9]{64}$/)) return false\r\n\r\n if (!Array.isArray(message.tags)) return false\r\n for (let i = 0; i < message.tags.length; i++) {\r\n let tag = message.tags[i]\r\n if (!Array.isArray(tag)) return false\r\n for (let j = 0; j < tag.length; j++) {\r\n if (typeof tag[j] === 'object') return false\r\n }\r\n } */\r\n\r\n return true\r\n}\r\n\r\nexport function verifySignature (sig: string, message: Message, pubKey: string): boolean {\r\n return schnorr.verify(\r\n sig,\r\n getMsgHash(message),\r\n pubKey\r\n )\r\n}\r\n\r\nexport function signMsg (message: UnsignedMsg, key: string): string {\r\n return bytesToHex(\r\n schnorr.sign(getMsgHash(message), key)\r\n )\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AAEA;AACA;;AAEO,IAAMG,WAAW,GAAG,IAAIC,WAAW,CAAC,OAAO,CAAC;AAAAC,OAAA,CAAAF,WAAA,GAAAA,WAAA;AAC5C,IAAMG,WAAW,GAAG,IAAIC,WAAW,EAAE;AAAAF,OAAA,CAAAC,WAAA,GAAAA,WAAA;AAErC,IAAME,GAAG,GAAG,4BAA4B,EAAC;AAAAH,OAAA,CAAAG,GAAA,GAAAA,GAAA;AACzC,IAAMC,IAAI,GAAG,iCAAiC,EAAC;;AAEtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAtBAJ,OAAA,CAAAI,IAAA,GAAAA,IAAA;AA0CO,SAASC,WAAWA,CAAA,EAAiB;EAC1C,OAAO;IACLC,EAAE,EAAE,EAAE;IACNC,OAAO,EAAE,EAAE;IACXC,WAAW,EAAE,EAAE;IACfC,OAAO,EAAE,EAAE;IACXC,KAAK,EAAE,EAAE;IACTC,GAAG,EAAE;EACP,CAAC;AACH;AAE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