solid-ui 2.4.27-dc50c4e2 → 2.4.27-e6d67dd8

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.
@@ -1,5 +1,5 @@
1
1
  export declare function generatePrivateKey(): string;
2
2
  export declare function generatePublicKey(privateKey: string): string;
3
- export declare function getPublicKey(webId: any): string | undefined;
3
+ export declare function getPublicKey(webId: any): Promise<string | undefined>;
4
4
  export declare function getPrivateKey(webId: string): Promise<string>;
5
5
  //# sourceMappingURL=keys.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/chat/keys.ts"],"names":[],"mappings":"AAQA,wBAAgB,kBAAkB,IAAK,MAAM,CAE5C;AAED,wBAAgB,iBAAiB,CAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAgB,YAAY,CAAE,KAAK,KAAA,sBAGlC;AAsDD,wBAAsB,aAAa,CAAE,KAAK,EAAE,MAAM,mBAoCjD"}
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/chat/keys.ts"],"names":[],"mappings":"AAQA,wBAAgB,kBAAkB,IAAK,MAAM,CAE5C;AAED,wBAAgB,iBAAiB,CAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAsB,YAAY,CAAE,KAAK,KAAA,+BAaxC;AAED,wBAAsB,aAAa,CAAE,KAAK,EAAE,MAAM,mBAqDjD"}
package/lib/chat/keys.js CHANGED
@@ -17,6 +17,7 @@ var _utils = require("@noble/hashes/utils");
17
17
  var _signature = require("./signature");
18
18
  var _solidLogic = require("solid-logic");
19
19
  var $rdf = _interopRequireWildcard(require("rdflib"));
20
+ var _cryptoKeyHelpers = require("../utils/cryptoKeyHelpers");
20
21
  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
22
  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
23
  function generatePrivateKey() {
@@ -25,133 +26,102 @@ function generatePrivateKey() {
25
26
  function generatePublicKey(privateKey) {
26
27
  return (0, _utils.bytesToHex)(_secp256k.schnorr.getPublicKey(privateKey));
27
28
  }
28
- function getPublicKey(webId) {
29
- var publicKey = publicKeyExists(webId);
30
- return publicKey;
29
+ function getPublicKey(_x) {
30
+ return _getPublicKey.apply(this, arguments);
31
31
  }
32
- function publicKeyExists(webId) {
33
- // find publickey
34
- var url = new URL(webId);
35
- url.hash = '';
36
- /* debug.warn('Alain publicKeyExists')
37
- debug.warn(webId)
38
- debug.warn(url.href) */
39
- _solidLogic.store.fetcher.load(url.href);
40
- var publicKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'PublicKey'));
41
- return publicKey === null || publicKey === void 0 ? void 0 : publicKey.value; // as NamedNode
42
- }
43
-
44
- var privKeyUrl = function privKeyUrl(webId) {
45
- var url = new URL(webId);
46
- var privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl';
47
- return privateKeyUrl;
48
- };
49
- function privateKeyExists(_x) {
50
- return _privateKeyExists.apply(this, arguments);
51
- }
52
- function _privateKeyExists() {
53
- _privateKeyExists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
54
- var privateKeyUrl, privateKey, _err$response, data, contentType, response;
32
+ function _getPublicKey() {
33
+ _getPublicKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
34
+ var publicKeyDoc, key;
55
35
  return _regenerator["default"].wrap(function _callee$(_context) {
56
36
  while (1) switch (_context.prev = _context.next) {
57
37
  case 0:
58
- /* const url = new URL(webId)
59
- const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl' */
60
- privateKeyUrl = privKeyUrl(webId);
61
- /* debug.warn('Alain privateKeyExists')
62
- debug.warn(webId)
63
- debug.warn(privateKeyUrl) */
64
- _context.prev = 1;
65
- _solidLogic.store.fetcher.load(privateKeyUrl);
66
- privateKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'PrivateKey'));
67
- return _context.abrupt("return", privateKey === null || privateKey === void 0 ? void 0 : privateKey.value);
68
- case 7:
69
- _context.prev = 7;
70
- _context.t0 = _context["catch"](1);
71
- if (!((_context.t0 === null || _context.t0 === void 0 ? void 0 : (_err$response = _context.t0.response) === null || _err$response === void 0 ? void 0 : _err$response.status) === 404)) {
72
- _context.next = 24;
73
- break;
74
- }
38
+ _context.next = 2;
39
+ return _solidLogic.store.fetcher.load(webId);
40
+ case 2:
41
+ publicKeyDoc = (0, _cryptoKeyHelpers.pubKeyUrl)(webId);
42
+ _context.prev = 3;
43
+ _context.next = 6;
44
+ return _solidLogic.store.fetcher.load(publicKeyDoc);
45
+ case 6:
46
+ // url.href)
47
+ key = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'PublicKey'));
48
+ return _context.abrupt("return", key === null || key === void 0 ? void 0 : key.value);
49
+ case 10:
75
50
  _context.prev = 10;
76
- // create privateKey resource
77
- data = '';
78
- contentType = 'text/ttl';
79
- _context.next = 15;
80
- return _solidLogic.store.fetcher.webOperation('PUT', privateKeyUrl, {
81
- data: data,
82
- contentType: contentType
83
- });
84
- case 15:
85
- response = _context.sent;
86
- _context.next = 22;
87
- break;
88
- case 18:
89
- _context.prev = 18;
90
- _context.t1 = _context["catch"](10);
91
- debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context.t1);
92
- throw _context.t1;
93
- case 22:
94
- delete _solidLogic.store.fetcher.requested[privateKeyUrl]; // delete cached 404 error
51
+ _context.t0 = _context["catch"](3);
95
52
  return _context.abrupt("return", undefined);
96
- case 24:
97
- debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context.t0);
98
- throw _context.t0;
99
- case 26:
53
+ case 13:
100
54
  case "end":
101
55
  return _context.stop();
102
56
  }
103
- }, _callee, null, [[1, 7], [10, 18]]);
57
+ }, _callee, null, [[3, 10]]);
104
58
  }));
105
- return _privateKeyExists.apply(this, arguments);
59
+ return _getPublicKey.apply(this, arguments);
106
60
  }
107
61
  function getPrivateKey(_x2) {
108
62
  return _getPrivateKey.apply(this, arguments);
109
63
  }
110
64
  function _getPrivateKey() {
111
65
  _getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(webId) {
112
- var url, privateKeyUrl, publicKey, privateKey, del, add;
66
+ var publicKeyDoc, privateKeyDoc, publicKey, privateKey, validPublicKey, del, add, newPublicKey;
113
67
  return _regenerator["default"].wrap(function _callee2$(_context2) {
114
68
  while (1) switch (_context2.prev = _context2.next) {
115
69
  case 0:
116
- url = new URL(webId);
117
- url.hash = '';
118
- /* const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl' */
119
- privateKeyUrl = privKeyUrl(webId); // find publickey
120
- publicKey = publicKeyExists(webId); // debug.warn('publicKey ' + publicKey)
121
- // find privateKey
70
+ _context2.next = 2;
71
+ return _solidLogic.store.fetcher.load(webId);
72
+ case 2:
73
+ // find keys url's
74
+ publicKeyDoc = (0, _cryptoKeyHelpers.pubKeyUrl)(webId);
75
+ privateKeyDoc = (0, _cryptoKeyHelpers.privKeyUrl)(webId); // find key pair
122
76
  _context2.next = 6;
123
- return privateKeyExists(webId);
77
+ return (0, _cryptoKeyHelpers.publicKeyExists)(webId);
124
78
  case 6:
79
+ publicKey = _context2.sent;
80
+ _context2.next = 9;
81
+ return (0, _cryptoKeyHelpers.privateKeyExists)(webId);
82
+ case 9:
125
83
  privateKey = _context2.sent;
126
- // debug.warn('privateKey ' + privateKey)
127
- if (privateKey && publicKey !== generatePublicKey(privateKey)) debug.warn('publicKey is not valid');
128
-
129
- // simulate new key pair
130
- /* const newPrivateKey = generatePrivateKey()
131
- const newPublicKey = generatePublicKey(newPrivateKey)
132
- debug.log('newPrivateKey ' + newPrivateKey)
133
- debug.log('newPublicKey ' + newPublicKey) */
84
+ // is publicKey valid ?
85
+ validPublicKey = true;
86
+ if (privateKey && publicKey !== generatePublicKey(privateKey)) {
87
+ if (confirm('This is strange the publicKey is not valid for\n' + webId + '\'shall we repair keeping the private key ?')) validPublicKey = false;
88
+ }
134
89
 
135
- // create key pair
136
- if (!(!privateKey || !publicKey)) {
137
- _context2.next = 19;
90
+ // create key pair or repair publicKey
91
+ if (!(!privateKey || !publicKey || !validPublicKey)) {
92
+ _context2.next = 27;
138
93
  break;
139
94
  }
140
95
  del = [];
141
- add = [];
142
- if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PrivateKey'), $rdf.lit(privateKey), $rdf.sym(privateKeyUrl)));
143
- if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PublicKey'), $rdf.lit(publicKey), $rdf.sym(url.href)));
96
+ add = []; // if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PrivateKey'), $rdf.lit(privateKey), $rdf.sym(privateKeyDoc)))
97
+ if (privateKey) {
98
+ _context2.next = 20;
99
+ break;
100
+ }
101
+ // add = []
144
102
  privateKey = generatePrivateKey();
145
- publicKey = generatePublicKey(privateKey);
146
- /* debug.log('newPrivateKey-1 ' + privateKey)
147
- debug.log('newPublicKey-1 ' + publicKey) */
148
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PrivateKey'), $rdf.literal(privateKey), $rdf.sym(privateKeyUrl)));
149
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PublicKey'), $rdf.literal(publicKey), $rdf.sym(url.href)));
150
- _context2.next = 19;
151
- return _solidLogic.store.updater.updateMany(del, add);
152
- case 19:
153
- return _context2.abrupt("return", privateKey);
103
+ add = [$rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PrivateKey'), $rdf.literal(privateKey), $rdf.sym(privateKeyDoc))];
104
+ _context2.next = 20;
105
+ return saveKey(privateKeyDoc, [], add, webId);
154
106
  case 20:
107
+ if (!(!publicKey || !validPublicKey)) {
108
+ _context2.next = 27;
109
+ break;
110
+ }
111
+ del = [];
112
+ // delete invalid public key
113
+ if (publicKey) {
114
+ del = [$rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PublicKey'), $rdf.lit(publicKey), $rdf.sym(publicKeyDoc))];
115
+ debug.log(del);
116
+ }
117
+ // update new valid key
118
+ newPublicKey = generatePublicKey(privateKey);
119
+ add = [$rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PublicKey'), $rdf.literal(newPublicKey), $rdf.sym(publicKeyDoc))];
120
+ _context2.next = 27;
121
+ return saveKey(publicKeyDoc, del, add);
122
+ case 27:
123
+ return _context2.abrupt("return", privateKey);
124
+ case 28:
155
125
  case "end":
156
126
  return _context2.stop();
157
127
  }
@@ -159,4 +129,106 @@ function _getPrivateKey() {
159
129
  }));
160
130
  return _getPrivateKey.apply(this, arguments);
161
131
  }
132
+ function setAcl(_x3) {
133
+ return _setAcl.apply(this, arguments);
134
+ }
135
+ function _setAcl() {
136
+ _setAcl = (0, _asyncToGenerator2["default"])(function (keyDoc) {
137
+ var me = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
138
+ return /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
139
+ var keyAclDoc, keyAgent, aclBody, aclResponse;
140
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
141
+ while (1) switch (_context3.prev = _context3.next) {
142
+ case 0:
143
+ _context3.next = 2;
144
+ return _solidLogic.store.fetcher.load(keyDoc);
145
+ case 2:
146
+ // FIXME: check the Why value on this quad:
147
+ keyAclDoc = _solidLogic.store.any($rdf.sym(keyDoc), $rdf.sym('http://www.iana.org/assignments/link-relations/acl'));
148
+ if (keyAclDoc) {
149
+ _context3.next = 5;
150
+ break;
151
+ }
152
+ throw new Error('Key ACL doc not found!');
153
+ case 5:
154
+ keyAgent = 'acl:agentClass foaf:agent';
155
+ if (me !== null && me !== void 0 && me.length) keyAgent = "acl:agent <".concat(me, ">");
156
+ aclBody = "\n@prefix foaf: <http://xmlns.com/foaf/0.1/>.\n@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n<#Read>\n a acl:Authorization;\n ".concat(keyAgent, ";\n acl:accessTo <").concat(keyDoc.split('/').pop(), ">;\n acl:mode acl:Read.\n");
157
+ _context3.next = 10;
158
+ return _solidLogic.store.fetcher.webOperation('PUT', keyAclDoc.value, {
159
+ data: aclBody,
160
+ contentType: 'text/turtle'
161
+ });
162
+ case 10:
163
+ aclResponse = _context3.sent;
164
+ case 11:
165
+ case "end":
166
+ return _context3.stop();
167
+ }
168
+ }, _callee3);
169
+ })();
170
+ });
171
+ return _setAcl.apply(this, arguments);
172
+ }
173
+ function saveKey(_x4, _x5, _x6) {
174
+ return _saveKey.apply(this, arguments);
175
+ }
176
+ function _saveKey() {
177
+ _saveKey = (0, _asyncToGenerator2["default"])(function (keyDoc, del, add) {
178
+ var me = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
179
+ return /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
180
+ var keyAclDoc, response;
181
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
182
+ while (1) switch (_context4.prev = _context4.next) {
183
+ case 0:
184
+ _context4.prev = 0;
185
+ // get keyAcldoc
186
+ keyAclDoc = _solidLogic.store.any($rdf.sym(keyDoc), $rdf.sym('http://www.iana.org/assignments/link-relations/acl'));
187
+ if (keyAclDoc) {
188
+ _context4.next = 4;
189
+ break;
190
+ }
191
+ throw new Error("".concat(keyDoc, " ACL doc not found!"));
192
+ case 4:
193
+ _context4.prev = 4;
194
+ _context4.next = 7;
195
+ return _solidLogic.store.fetcher.webOperation('DELETE', keyAclDoc.value);
196
+ case 7:
197
+ response = _context4.sent;
198
+ // this may fail if webId is not an owner
199
+ debug.log('delete ' + keyAclDoc.value + ' ' + response.status); // should test 404 and 2xx
200
+ _context4.next = 16;
201
+ break;
202
+ case 11:
203
+ _context4.prev = 11;
204
+ _context4.t0 = _context4["catch"](4);
205
+ if (!(_context4.t0.response.status !== 404)) {
206
+ _context4.next = 15;
207
+ break;
208
+ }
209
+ throw new Error(_context4.t0);
210
+ case 15:
211
+ debug.log('delete ' + keyAclDoc.value + ' ' + _context4.t0.response.status); // should test 404 and 2xx
212
+ case 16:
213
+ _context4.next = 18;
214
+ return _solidLogic.store.updater.updateMany(del, add);
215
+ case 18:
216
+ _context4.next = 20;
217
+ return setAcl(keyDoc, me);
218
+ case 20:
219
+ _context4.next = 25;
220
+ break;
221
+ case 22:
222
+ _context4.prev = 22;
223
+ _context4.t1 = _context4["catch"](0);
224
+ throw new Error(_context4.t1);
225
+ case 25:
226
+ case "end":
227
+ return _context4.stop();
228
+ }
229
+ }, _callee4, null, [[0, 22], [4, 11]]);
230
+ })();
231
+ });
232
+ return _saveKey.apply(this, arguments);
233
+ }
162
234
  //# sourceMappingURL=keys.js.map
@@ -1 +1 @@
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","url","URL","hash","store","fetcher","load","href","any","sym","CERT","value","privKeyUrl","privateKeyUrl","protocol","host","privateKeyExists","_x","_privateKeyExists","apply","arguments","_asyncToGenerator2","_regenerator","mark","_callee","_err$response","data","contentType","response","wrap","_callee$","_context","prev","next","abrupt","t0","status","webOperation","sent","t1","log","requested","undefined","stop","getPrivateKey","_x2","_getPrivateKey","_callee2","del","add","_callee2$","_context2","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\nfunction 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 store.fetcher.load(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.protocol + '//' + url.host + '/profile/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 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 privateKeyUrl = privKeyUrl(webId)\r\n\r\n // find publickey\r\n let publicKey = 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(url.href)))\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(url.href)))\r\n await store.updater.updateMany(del, add)\r\n }\r\n return privateKey as string\r\n}\r\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAN,uBAAA,CAAAC,OAAA;AAA8B,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAR,wBAAAY,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,aAAAE,OAAA,CAAAF,GAAA,yBAAAA,GAAA,uCAAAA,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GA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AAA;MAAA;IAAA,GAAAI,QAAA;EAAA,CAClB;EAAA,OAAAD,cAAA,CAAA3B,KAAA,OAAAC,SAAA;AAAA"}
1
+ {"version":3,"file":"keys.js","names":["debug","_interopRequireWildcard","require","_secp256k","_utils","_signature","_solidLogic","$rdf","_cryptoKeyHelpers","_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","_x","_getPublicKey","apply","arguments","_asyncToGenerator2","_regenerator","mark","_callee","webId","publicKeyDoc","wrap","_callee$","_context","prev","next","store","fetcher","load","pubKeyUrl","any","sym","CERT","abrupt","value","t0","undefined","stop","getPrivateKey","_x2","_getPrivateKey","_callee2","privateKeyDoc","publicKey","validPublicKey","del","add","newPublicKey","_callee2$","_context2","privKeyUrl","publicKeyExists","sent","privateKeyExists","confirm","st","literal","saveKey","lit","log","setAcl","_x3","_setAcl","keyDoc","me","length","_callee3","keyAclDoc","keyAgent","aclBody","aclResponse","_callee3$","_context3","Error","concat","split","pop","webOperation","data","contentType","_x4","_x5","_x6","_saveKey","_callee4","response","_callee4$","_context4","status","updater","updateMany","t1"],"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 { publicKeyExists, pubKeyUrl, privKeyUrl, privateKeyExists } from '../utils/cryptoKeyHelpers'\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 async function getPublicKey (webId) {\r\n await store.fetcher.load(webId)\r\n const publicKeyDoc = pubKeyUrl(webId)\r\n try {\r\n await store.fetcher.load(publicKeyDoc) // url.href)\r\n const key = store.any(store.sym(webId), store.sym(CERT + 'PublicKey'))\r\n return key?.value // as NamedNode\r\n } catch (err) {\r\n return undefined\r\n }\r\n // this is called in display message and should not try to create a publicKeyDoc\r\n // const publicKey = await publicKeyExists(webId)\r\n // return publicKey\r\n}\r\n\r\nexport async function getPrivateKey (webId: string) {\r\n await store.fetcher.load(webId)\r\n // find keys url's\r\n const publicKeyDoc = pubKeyUrl(webId)\r\n const privateKeyDoc = privKeyUrl(webId)\r\n\r\n // find key pair\r\n const publicKey = await publicKeyExists(webId)\r\n let privateKey = await privateKeyExists(webId)\r\n\r\n // is publicKey valid ?\r\n let validPublicKey = true\r\n if (privateKey && (publicKey !== generatePublicKey(privateKey as string))) {\r\n if (confirm('This is strange the publicKey is not valid for\\n' + webId +\r\n '\\'shall we repair keeping the private key ?')) validPublicKey = false\r\n }\r\n\r\n // create key pair or repair publicKey\r\n if (!privateKey || !publicKey || !validPublicKey) {\r\n let del: any[] = []\r\n let add: any[] = []\r\n // if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PrivateKey'), $rdf.lit(privateKey), $rdf.sym(privateKeyDoc)))\r\n\r\n if (!privateKey) {\r\n // add = []\r\n privateKey = generatePrivateKey()\r\n add = [$rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PrivateKey'), $rdf.literal(privateKey), $rdf.sym(privateKeyDoc))]\r\n await saveKey(privateKeyDoc, [], add, webId)\r\n }\r\n if (!publicKey || !validPublicKey) {\r\n del = []\r\n // delete invalid public key\r\n if (publicKey) {\r\n del = [$rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PublicKey'), $rdf.lit(publicKey), $rdf.sym(publicKeyDoc))]\r\n debug.log(del)\r\n }\r\n // update new valid key\r\n const newPublicKey = generatePublicKey(privateKey)\r\n add = [$rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PublicKey'), $rdf.literal(newPublicKey), $rdf.sym(publicKeyDoc))]\r\n await saveKey(publicKeyDoc, del, add)\r\n }\r\n /* debug.log('new key pair ' + webId)\r\n debug.log('newPrivateKey-1 ' + privateKey)\r\n debug.log('newPublicKey-1 ' + publicKey) */\r\n /* debug.log('del')\r\n debug.log(del)\r\n debug.log('add')\r\n debug.log(add) */\r\n // await store.updater.updateMany(del, add)\r\n // TODO create READ ACL's\r\n // await setAcl() // depends on which key has been updated\r\n }\r\n return privateKey as string\r\n}\r\n\r\nasync function setAcl (keyDoc, me = '') {\r\n // Some servers don't present a Link http response header\r\n // if the container doesn't exist yet, so refetch the container\r\n // now that it has been created:\r\n await store.fetcher.load(keyDoc)\r\n\r\n // FIXME: check the Why value on this quad:\r\n const keyAclDoc = store.any($rdf.sym(keyDoc), $rdf.sym('http://www.iana.org/assignments/link-relations/acl'))\r\n if (!keyAclDoc) {\r\n throw new Error('Key ACL doc not found!')\r\n }\r\n\r\n let keyAgent = 'acl:agentClass foaf:agent'\r\n if (me?.length) keyAgent = `acl:agent <${me}>`\r\n const aclBody = `\r\n@prefix foaf: <http://xmlns.com/foaf/0.1/>.\r\n@prefix acl: <http://www.w3.org/ns/auth/acl#>.\r\n<#Read>\r\n a acl:Authorization;\r\n ${keyAgent};\r\n acl:accessTo <${keyDoc.split('/').pop()}>;\r\n acl:mode acl:Read.\r\n`\r\n const aclResponse = await store.fetcher.webOperation('PUT', keyAclDoc.value, {\r\n data: aclBody,\r\n contentType: 'text/turtle'\r\n })\r\n}\r\n\r\nasync function saveKey (keyDoc, del, add, me = '') {\r\n try {\r\n // get keyAcldoc\r\n const keyAclDoc = store.any($rdf.sym(keyDoc), $rdf.sym('http://www.iana.org/assignments/link-relations/acl'))\r\n if (!keyAclDoc) {\r\n throw new Error(`${keyDoc} ACL doc not found!`)\r\n }\r\n // delete READ only keyAclDoc. This is possible if the webId is an owner\r\n try {\r\n const response = await store.fetcher.webOperation('DELETE', keyAclDoc.value) // this may fail if webId is not an owner\r\n debug.log('delete ' + keyAclDoc.value + ' ' + response.status) // should test 404 and 2xx\r\n } catch (err) {\r\n if (err.response.status !== 404) { throw new Error(err) }\r\n debug.log('delete ' + keyAclDoc.value + ' ' + err.response.status) // should test 404 and 2xx\r\n }\r\n\r\n // save key\r\n await store.updater.updateMany(del, add) // or a promise store.updater.update ?\r\n\r\n // create READ only ACL\r\n await setAcl(keyDoc, me)\r\n } catch (err) { throw new Error(err) }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAN,uBAAA,CAAAC,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAAoG,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAT,wBAAAa,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,aAAAE,OAAA,CAAAF,GAAA,yBAAAA,GAAA,uCAAAA,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,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D,EAAA,CAAIkD,QAAQ,CAACG,MAAM,KAAK,GAAG;cAAAD,SAAA,CAAA9D,IAAA;cAAA;YAAA;YAAA,MAAU,IAAIgD,KAAK,CAAAc,SAAA,CAAApD,EAAA,CAAK;UAAA;YACvD/D,KAAK,CAACuF,GAAG,CAAC,SAAS,GAAGQ,SAAS,CAACjC,KAAK,GAAG,GAAG,GAAGqD,SAAA,CAAApD,EAAA,CAAIkD,QAAQ,CAACG,MAAM,CAAC,EAAC;UAAA;YAAAD,SAAA,CAAA9D,IAAA;YAAA,OAI/DC,iBAAK,CAAC+D,OAAO,CAACC,UAAU,CAAC7C,GAAG,EAAEC,GAAG,CAAC;UAAA;YAAAyC,SAAA,CAAA9D,IAAA;YAAA,OAGlCmC,MAAM,CAACG,MAAM,EAAEC,EAAE,CAAC;UAAA;YAAAuB,SAAA,CAAA9D,IAAA;YAAA;UAAA;YAAA8D,SAAA,CAAA/D,IAAA;YAAA+D,SAAA,CAAAI,EAAA,GAAAJ,SAAA;YAAA,MACJ,IAAId,KAAK,CAAAc,SAAA,CAAAI,EAAA,CAAK;UAAA;UAAA;YAAA,OAAAJ,SAAA,CAAAlD,IAAA;QAAA;MAAA,GAAA+C,QAAA;IAAA;EAAA,CACrC;EAAA,OAAAD,QAAA,CAAAtE,KAAA,OAAAC,SAAA;AAAA"}
@@ -116,30 +116,37 @@ function renderMessageRow(channelObject, message, fresh, options, userContext) {
116
116
  var date = _solidLogic.store.any(message, ns.dct('created'));
117
117
  var latestVersion = (0, _chatLogic.mostRecentVersion)(message);
118
118
  var latestVersionCreator = _solidLogic.store.any(latestVersion, ns.foaf('maker'));
119
+
119
120
  // use latest content if same owner, else use original
120
- var msgId = creator === latestVersionCreator ? latestVersion : message;
121
+ var msgId = creator.uri === latestVersionCreator.uri ? latestVersion : message;
121
122
  var content = _solidLogic.store.any(msgId, ns.sioc('content'));
122
123
  var signature = _solidLogic.store.any(msgId, $rdf.sym("".concat(_signature.SEC, "Proof")));
123
- debug.log('alain ' + (signature === null || signature === void 0 ? void 0 : signature.value));
124
124
 
125
- // verify signature
125
+ // set message object
126
126
  var msg = (0, _signature.getBlankMsg)();
127
127
  msg.id = msgId.uri;
128
128
  msg.created = _solidLogic.store.any(msgId, ns.dct('created')).value;
129
129
  msg.content = content.value;
130
130
  msg.maker = creator.uri;
131
- try {
132
- // pubKey could be store in a cache for all makers
133
- var pubKey = (0, _keys.getPublicKey)(creator.uri);
134
- /* const pubKey0 = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'
135
- debug.warn('publicKeys\n' + pubKey0 + '\n' + pubKey)
136
- const privKey0 = getPrivateKey(creator.uri) // alain to remove
137
- // unsigned messages should be signaled as unsecured
138
- debug.warn(msg)
139
- debug.warn(signature?.value) */
140
- if (signature !== null && signature !== void 0 && signature.value && !(0, _signature.verifySignature)(signature.value, msg, pubKey)) throw new Error('invalid signature');
141
- } catch (err) {
142
- debug.log(err);
131
+
132
+ // unsigned message
133
+ if (!(signature !== null && signature !== void 0 && signature.value)) debug.warn(msgId.uri + ' is unsigned'); // TODO replace with UI (colored message ?)
134
+
135
+ // signed message, get public key and check signature
136
+ else {
137
+ (0, _keys.getPublicKey)(creator.uri).then(function (publicKey) {
138
+ debug.log(creator.uri + '\n' + msg.created + '\n' + msg.id + '\n' + publicKey);
139
+ if (!publicKey) {
140
+ // TODO try to recreate the publicKey
141
+ // if(me.uri === creator.uri) await getPrivateKey(creator.uri)
142
+ debug.warn('message is signed but ' + creator.uri + ' is missing publicKey');
143
+ }
144
+ // check that publicKey is a valid hex string
145
+ var regex = /[0-9A-Fa-f]{6}/g;
146
+ if (!(publicKey !== null && publicKey !== void 0 && publicKey.match(regex))) debug.warn('invalid publicKey hex string\n' + creator.uri + '\n' + publicKey);
147
+ // verify signature
148
+ else if (signature !== null && signature !== void 0 && signature.value && !(0, _signature.verifySignature)(signature === null || signature === void 0 ? void 0 : signature.value, msg, publicKey)) debug.warn('invalid signature\n' + msg.id);
149
+ });
143
150
  }
144
151
  var originalMessage = (0, _chatLogic.originalVersion)(message);
145
152
  var edited = !message.sameTerm(originalMessage);