solid-ui 2.4.27-9d7e618e → 2.4.27-9f7a01da

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.
@@ -85,7 +85,7 @@ var ChatChannel = /*#__PURE__*/function () {
85
85
  var oldMsg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
86
86
  var deleteIt = arguments.length > 2 ? arguments[2] : undefined;
87
87
  return /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
88
- var sts, now, timestamp, dateStamp, chatDocument, message, me, msg, oldMsgMaker, errMsg, privateKey, _errMsg;
88
+ var sts, now, timestamp, dateStamp, chatDocument, message, me, msg, oldMsgMaker, errMsg, privateKey, pubKey, sig, _errMsg;
89
89
  return _regenerator["default"].wrap(function _callee2$(_context2) {
90
90
  while (1) switch (_context2.prev = _context2.next) {
91
91
  case 0:
@@ -96,8 +96,8 @@ var ChatChannel = /*#__PURE__*/function () {
96
96
  chatDocument = oldMsg ? oldMsg.doc() : _this.dateFolder.leafDocumentFromDate(now);
97
97
  message = _solidLogic.store.sym(chatDocument.uri + '#' + 'Msg' + timestamp); // const content = store.literal(text)
98
98
  me = _solidLogic.authn.currentUser(); // If already logged on
99
- msg = _signature.getBlankMsg;
100
- msg.id = message;
99
+ msg = (0, _signature.getBlankMsg)();
100
+ msg.id = message.uri;
101
101
  if (!oldMsg) {
102
102
  _context2.next = 22;
103
103
  break;
@@ -112,7 +112,7 @@ var ChatChannel = /*#__PURE__*/function () {
112
112
  if (deleteIt) {
113
113
  // we need to add a specific signature, else anyone can delete a msg ?
114
114
  sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument));
115
- msg.dateDeleted = dateStamp;
115
+ // msg.dateDeleted = dateStamp
116
116
  }
117
117
  _context2.next = 20;
118
118
  break;
@@ -131,40 +131,48 @@ var ChatChannel = /*#__PURE__*/function () {
131
131
  sts.push($rdf.st(message, ns.sioc('content'), _solidLogic.store.literal(text), chatDocument));
132
132
  msg.content = text;
133
133
  sts.push($rdf.st(message, ns.dct('created'), dateStamp, chatDocument));
134
- msg.created = dateStamp;
134
+ msg.created = dateStamp.value;
135
135
  if (!me) {
136
- _context2.next = 34;
136
+ _context2.next = 36;
137
137
  break;
138
138
  }
139
139
  sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument));
140
- msg.maker = me;
141
- // privateKey the cached private key of me, cache should be deleted after a certain time
140
+ msg.maker = me.uri;
141
+ // privateKey the cached private key of me, cached in store
142
142
  _context2.next = 32;
143
- return (0, _keys.getPrivateKey)(me);
143
+ return (0, _keys.getPrivateKey)(me.uri);
144
144
  case 32:
145
145
  privateKey = _context2.sent;
146
- sts.push($rdf.st(message, $rdf.sym("".concat(_signature.SEC, "Proof")), $rdf.sym((0, _signature.signMsg)(msg, privateKey), chatDocument)));
147
- case 34:
148
- _context2.prev = 34;
149
- _context2.next = 37;
146
+ // const privateKey0 = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'
147
+ // const pubKey0 = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'
148
+ pubKey = (0, _keys.getPublicKey)(me.uri);
149
+ sig = (0, _signature.signMsg)(msg, privateKey);
150
+ /* const verify = verifySignature(sig, msg, pubKey) // alain to remove
151
+ debug.warn('sig ' + sig)
152
+ debug.warn('verifySign ' + verify)
153
+ debug.warn(msg) */
154
+ sts.push($rdf.st(message, $rdf.sym("".concat(_signature.SEC, "Proof")), $rdf.lit(sig), chatDocument));
155
+ case 36:
156
+ _context2.prev = 36;
157
+ _context2.next = 39;
150
158
  return _solidLogic.store.updater.update([], sts);
151
- case 37:
152
- _context2.next = 45;
153
- break;
154
159
  case 39:
155
- _context2.prev = 39;
156
- _context2.t0 = _context2["catch"](34);
160
+ _context2.next = 47;
161
+ break;
162
+ case 41:
163
+ _context2.prev = 41;
164
+ _context2.t0 = _context2["catch"](36);
157
165
  _errMsg = 'Error saving chat message: ' + _context2.t0;
158
166
  debug.warn(_errMsg);
159
167
  alert(_errMsg);
160
168
  throw new Error(_errMsg);
161
- case 45:
169
+ case 47:
162
170
  return _context2.abrupt("return", message);
163
- case 46:
171
+ case 48:
164
172
  case "end":
165
173
  return _context2.stop();
166
174
  }
167
- }, _callee2, null, [[34, 39]]);
175
+ }, _callee2, null, [[36, 41]]);
168
176
  })();
169
177
  });
170
178
  function updateMessage(_x2) {
@@ -1 +1 @@
1
- {"version":3,"file":"chatLogic.js","names":["debug","_interopRequireWildcard","require","_dateFolder","_solidLogic","ns","$rdf","utils","_signature","_keys","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ChatChannel","channel","options","_classCallCheck2","channelRoot","doc","dateFolder","DateFolder","div","_createClass2","value","_createMessage","_asyncToGenerator2","_regenerator","mark","_callee","text","wrap","_callee$","_context","prev","next","abrupt","updateMessage","stop","createMessage","_x","apply","arguments","_updateMessage","_this","oldMsg","length","undefined","deleteIt","_callee2","sts","now","timestamp","dateStamp","chatDocument","message","me","msg","oldMsgMaker","errMsg","privateKey","_errMsg","_callee2$","_context2","Date","getTime","term","leafDocumentFromDate","store","sym","uri","authn","currentUser","getBlankMsg","id","any","foaf","push","st","mostRecentVersion","dct","schema","dateDeleted","warn","alert","Error","wf","sioc","literal","content","created","maker","getPrivateKey","sent","concat","SEC","signMsg","updater","update","t0","_x2","_deleteMessage","_callee3","_callee3$","_context3","deleteMessage","_x3","exports","originalVersion","isDeleted","holds","isReplaced","isHidden","nick","person","s","label","_createIfNotExists","_x4","_createIfNotExists2","contentType","data","_callee4","response","_callee4$","_context4","fetcher","load","status","log","webOperation","t1","requested"],"sources":["../../src/chat/chatLogic.js"],"sourcesContent":["/**\n * Contains the [[ChatChannel]] class and logic for Solid Chat\n * @packageDocumentation\n */\n\nimport * as debug from '../debug'\nimport { DateFolder } from './dateFolder'\nimport { store, authn } from 'solid-logic'\nimport * as ns from '../ns'\nimport * as $rdf from 'rdflib' // pull in first avoid cross-refs\nimport * as utils from '../utils'\nimport { getBlankMsg, signMsg, SEC } from './signature'\nimport { getPrivateKey } from './keys'\n\n/* The Solid logic for a 'LongChat'\n*/\n/**\n * Common code for a chat (discussion area of messages about something)\n * This version runs over a series of files for different time periods\n *\n * Parameters for the whole chat like its title are stored on\n * index.ttl#this and the chats messages are stored in YYYY/MM/DD/chat.ttl\n *\n */\n\nexport class ChatChannel {\n constructor (channel, options) {\n this.channel = channel\n this.channelRoot = channel.doc()\n this.options = options\n this.dateFolder = new DateFolder(this.channelRoot, 'chat.ttl')\n this.div = null // : HTMLElement\n }\n\n /* Store a new message in the web,\n */\n async createMessage (text) {\n return this.updateMessage(text)\n }\n\n /* Store a new message in the web,\n as a replacement for an existing one.\n The old one iis left, and the two are linked\n */\n async updateMessage (text, oldMsg = null, deleteIt) {\n const sts = []\n const now = new Date()\n const timestamp = '' + now.getTime()\n const dateStamp = $rdf.term(now)\n const chatDocument = oldMsg ? oldMsg.doc() : this.dateFolder.leafDocumentFromDate(now)\n const message = store.sym(chatDocument.uri + '#' + 'Msg' + timestamp)\n // const content = store.literal(text)\n\n const me = authn.currentUser() // If already logged on\n\n const msg = getBlankMsg\n msg.id = message\n if (oldMsg) { // edit message replaces old one\n const oldMsgMaker = store.any(oldMsg, ns.foaf('maker')) // may not be needed here, but needed on READ\n if (oldMsgMaker.uri === me.uri) {\n sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument))\n if (deleteIt) { // we need to add a specific signature, else anyone can delete a msg ?\n sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument))\n msg.dateDeleted = dateStamp\n }\n } else {\n const errMsg = 'Error you cannot delete/edit a message from someone else : \\n' + oldMsgMaker.uri\n debug.warn(errMsg)\n alert(errMsg)\n throw new Error(errMsg)\n }\n } else { // link new message to channel\n sts.push($rdf.st(this.channel, ns.wf('message'), message, chatDocument))\n }\n sts.push(\n $rdf.st(message, ns.sioc('content'), store.literal(text), chatDocument)\n )\n msg.content = text\n\n sts.push(\n $rdf.st(message, ns.dct('created'), dateStamp, chatDocument)\n )\n msg.created = dateStamp\n if (me) {\n sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument))\n msg.maker = me\n // privateKey the cached private key of me, cache should be deleted after a certain time\n const privateKey = await getPrivateKey(me)\n sts.push($rdf.st(message, $rdf.sym(`${SEC}Proof`), $rdf.sym(signMsg(msg, privateKey), chatDocument)))\n }\n try {\n await store.updater.update([], sts)\n } catch (err) {\n const errMsg = 'Error saving chat message: ' + err\n debug.warn(errMsg)\n alert(errMsg)\n throw new Error(errMsg)\n }\n return message\n }\n\n /* Mark a message as deleted\n * Wee add a new version of the message,m witha deletion flag (deletion date)\n * so that the deletion can be revoked by adding another non-deleted update\n */\n async deleteMessage (message) {\n return this.updateMessage('(message deleted)', message, true)\n }\n} // class ChatChannel\n\nexport function originalVersion (message) {\n let msg = message\n while (msg) {\n message = msg\n msg = store.any(null, ns.dct('isReplacedBy'), message, message.doc())\n }\n return message\n}\n\nexport function mostRecentVersion (message) {\n let msg = message\n while (msg) {\n message = msg\n msg = store.any(message, ns.dct('isReplacedBy'), null, message.doc())\n }\n return message\n}\n\nexport function isDeleted (message) {\n return store.holds(message, ns.schema('dateDeleted'), null, message.doc())\n}\n\nexport function isReplaced (message) {\n return store.holds(message, ns.dct('isReplacedBy'), null, message.doc())\n}\n\nexport function isHidden (message) {\n return this.isDeleted(message) || this.isReplaced(message)\n}\n\n// A Nickname for a person\n\nexport function nick (person) {\n const s = store.any(person, ns.foaf('nick'))\n if (s) return '' + s.value\n return '' + utils.label(person)\n}\n\nexport async function _createIfNotExists (doc, contentType = 'text/turtle', data = '') {\n let response\n try {\n response = await store.fetcher.load(doc)\n } catch (err) {\n if (err.response.status === 404) {\n debug.log(\n 'createIfNotExists: doc does NOT exist, will create... ' + doc\n )\n try {\n response = await store.fetcher.webOperation('PUT', doc.uri, {\n data,\n contentType\n })\n } catch (err) {\n debug.log('createIfNotExists doc FAILED: ' + doc + ': ' + err)\n throw err\n }\n delete store.fetcher.requested[doc.uri] // delete cached 404 error\n // debug.log('createIfNotExists doc created ok ' + doc)\n return response\n } else {\n debug.log(\n 'createIfNotExists doc load error NOT 404: ' + doc + ': ' + err\n )\n throw err\n }\n }\n // debug.log('createIfNotExists: doc exists, all good: ' + doc)\n return response\n}\n// ends\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAKA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,EAAA,GAAAJ,uBAAA,CAAAC,OAAA;AACA,IAAAI,IAAA,GAAAL,uBAAA,CAAAC,OAAA;AACA,IAAAK,KAAA,GAAAN,uBAAA,CAAAC,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AAAsC,SAAAQ,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,SAAAV,wBAAAc,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,CA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ils","_signature","_keys","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ChatChannel","channel","options","_classCallCheck2","channelRoot","doc","dateFolder","DateFolder","div","_createClass2","value","_createMessage","_asyncToGenerator2","_regenerator","mark","_callee","text","wrap","_callee$","_context","prev","next","abrupt","updateMessage","stop","createMessage","_x","apply","arguments","_updateMessage","_this","oldMsg","length","undefined","deleteIt","_callee2","sts","now","timestamp","dateStamp","chatDocument","message","me","msg","oldMsgMaker","errMsg","privateKey","pubKey","sig","_errMsg","_callee2$","_context2","Date","getTime","term","leafDocumentFromDate","store","sym","uri","authn","currentUser","getBlankMsg","id","any","foaf","push","st","mostRecentVersion","dct","schema","warn","alert","Error","wf","sioc","literal","content","created","maker","getPrivateKey","sent","getPublicKey","signMsg","concat","SEC","lit","updater","update","t0","_x2","_deleteMessage","_callee3","_callee3$","_context3","deleteMessage","_x3","exports","originalVersion","isDeleted","holds","isReplaced","isHidden","nick","person","s","label","_createIfNotExists","_x4","_createIfNotExists2","contentType","data","_callee4","response","_callee4$","_context4","fetcher","load","status","log","webOperation","t1","requested"],"sources":["../../src/chat/chatLogic.js"],"sourcesContent":["/**\n * Contains the [[ChatChannel]] class and logic for Solid Chat\n * @packageDocumentation\n */\n\nimport * as debug from '../debug'\nimport { DateFolder } from './dateFolder'\nimport { store, authn } from 'solid-logic'\nimport * as ns from '../ns'\nimport * as $rdf from 'rdflib' // pull in first avoid cross-refs\nimport * as utils from '../utils'\nimport { getBlankMsg, signMsg, SEC, verifySignature } from './signature'\nimport { getPrivateKey, getPublicKey } from './keys'\n\n/* The Solid logic for a 'LongChat'\n*/\n/**\n * Common code for a chat (discussion area of messages about something)\n * This version runs over a series of files for different time periods\n *\n * Parameters for the whole chat like its title are stored on\n * index.ttl#this and the chats messages are stored in YYYY/MM/DD/chat.ttl\n *\n */\n\nexport class ChatChannel {\n constructor (channel, options) {\n this.channel = channel\n this.channelRoot = channel.doc()\n this.options = options\n this.dateFolder = new DateFolder(this.channelRoot, 'chat.ttl')\n this.div = null // : HTMLElement\n }\n\n /* Store a new message in the web,\n */\n async createMessage (text) {\n return this.updateMessage(text)\n }\n\n /* Store a new message in the web,\n as a replacement for an existing one.\n The old one iis left, and the two are linked\n */\n async updateMessage (text, oldMsg = null, deleteIt) {\n const sts = []\n const now = new Date()\n const timestamp = '' + now.getTime()\n const dateStamp = $rdf.term(now)\n const chatDocument = oldMsg ? oldMsg.doc() : this.dateFolder.leafDocumentFromDate(now)\n const message = store.sym(chatDocument.uri + '#' + 'Msg' + timestamp)\n // const content = store.literal(text)\n\n const me = authn.currentUser() // If already logged on\n\n const msg = getBlankMsg()\n msg.id = message.uri\n if (oldMsg) { // edit message replaces old one\n const oldMsgMaker = store.any(oldMsg, ns.foaf('maker')) // may not be needed here, but needed on READ\n if (oldMsgMaker.uri === me.uri) {\n sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument))\n if (deleteIt) { // we need to add a specific signature, else anyone can delete a msg ?\n sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument))\n // msg.dateDeleted = dateStamp\n }\n } else {\n const errMsg = 'Error you cannot delete/edit a message from someone else : \\n' + oldMsgMaker.uri\n debug.warn(errMsg)\n alert(errMsg)\n throw new Error(errMsg)\n }\n } else { // link new message to channel\n sts.push($rdf.st(this.channel, ns.wf('message'), message, chatDocument))\n }\n sts.push(\n $rdf.st(message, ns.sioc('content'), store.literal(text), chatDocument)\n )\n msg.content = text\n\n sts.push(\n $rdf.st(message, ns.dct('created'), dateStamp, chatDocument)\n )\n msg.created = dateStamp.value\n if (me) {\n sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument))\n msg.maker = me.uri\n // privateKey the cached private key of me, cached in store\n const privateKey = await getPrivateKey(me.uri)\n // const privateKey0 = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'\n // const pubKey0 = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'\n const pubKey = getPublicKey(me.uri)\n\n const sig = signMsg(msg, privateKey)\n /* const verify = verifySignature(sig, msg, pubKey) // alain to remove\n debug.warn('sig ' + sig)\n debug.warn('verifySign ' + verify)\n debug.warn(msg) */\n sts.push($rdf.st(message, $rdf.sym(`${SEC}Proof`), $rdf.lit(sig), chatDocument))\n }\n try {\n await store.updater.update([], sts)\n } catch (err) {\n const errMsg = 'Error saving chat message: ' + err\n debug.warn(errMsg)\n alert(errMsg)\n throw new Error(errMsg)\n }\n return message\n }\n\n /* Mark a message as deleted\n * Wee add a new version of the message,m witha deletion flag (deletion date)\n * so that the deletion can be revoked by adding another non-deleted update\n */\n async deleteMessage (message) {\n return this.updateMessage('(message deleted)', message, true)\n }\n} // class ChatChannel\n\nexport function originalVersion (message) {\n let msg = message\n while (msg) {\n message = msg\n msg = store.any(null, ns.dct('isReplacedBy'), message, message.doc())\n }\n return message\n}\n\nexport function mostRecentVersion (message) {\n let msg = message\n while (msg) {\n message = msg\n msg = store.any(message, ns.dct('isReplacedBy'), null, message.doc())\n }\n return message\n}\n\nexport function isDeleted (message) {\n return store.holds(message, ns.schema('dateDeleted'), null, message.doc())\n}\n\nexport function isReplaced (message) {\n return store.holds(message, ns.dct('isReplacedBy'), null, message.doc())\n}\n\nexport function isHidden (message) {\n return this.isDeleted(message) || this.isReplaced(message)\n}\n\n// A Nickname for a person\n\nexport function nick (person) {\n const s = store.any(person, ns.foaf('nick'))\n if (s) return '' + s.value\n return '' + utils.label(person)\n}\n\nexport async function _createIfNotExists (doc, contentType = 'text/turtle', data = '') {\n let response\n try {\n response = await store.fetcher.load(doc)\n } catch (err) {\n if (err.response.status === 404) {\n debug.log(\n 'createIfNotExists: doc does NOT exist, will create... ' + doc\n )\n try {\n response = await store.fetcher.webOperation('PUT', doc.uri, {\n data,\n contentType\n })\n } catch (err) {\n debug.log('createIfNotExists doc FAILED: ' + doc + ': ' + err)\n throw err\n }\n delete store.fetcher.requested[doc.uri] // delete cached 404 error\n // debug.log('createIfNotExists doc created ok ' + doc)\n return response\n } else {\n debug.log(\n 'createIfNotExists doc load error NOT 404: ' + doc + ': ' + err\n )\n throw err\n }\n }\n // debug.log('createIfNotExists: doc exists, all good: ' + doc)\n return response\n}\n// ends\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAKA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,EAAA,GAAAJ,uBAAA,CAAAC,OAAA;AACA,IAAAI,IAAA,GAAAL,uBAAA,CAAAC,OAAA;AACA,IAAAK,KAAA,GAAAN,uBAAA,CAAAC,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AAAoD,SAAAQ,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,SAAAV,wBAAAc,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,G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AAuF,QAAA;IAAA;EAAA,CAChB;EAAA,OAAAH,mBAAA,CAAAjF,KAAA,OAAAC,SAAA;AAAA"}
@@ -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): any;
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,OAGlC;AAyCD,wBAAsB,aAAa,CAAE,KAAK,EAAE,MAAM,mBAsBjD"}
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,+BAGlC;AA4DD,wBAAsB,aAAa,CAAE,KAAK,EAAE,MAAM,mBAqCjD"}
package/lib/chat/keys.js CHANGED
@@ -27,107 +27,156 @@ function generatePublicKey(privateKey) {
27
27
  }
28
28
  function getPublicKey(webId) {
29
29
  var publicKey = publicKeyExists(webId);
30
- return publicKey === null || publicKey === void 0 ? void 0 : publicKey.uri;
30
+ return publicKey;
31
31
  }
32
- function publicKeyExists(webId) {
33
- // find publickey
32
+ var pubKeyUrl = function pubKeyUrl(webId) {
34
33
  var url = new URL(webId);
35
- url.hash = '';
36
- _solidLogic.store.fetcher.load(url.href);
37
- var publicKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'publicKey'));
38
- return publicKey;
34
+ var publicKeyUrl = url.origin + '/profile/keys/publicKey.ttl';
35
+ return publicKeyUrl;
36
+ };
37
+ function publicKeyExists(_x) {
38
+ return _publicKeyExists.apply(this, arguments);
39
39
  }
40
- function privateKeyExists(_x) {
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) {
41
66
  return _privateKeyExists.apply(this, arguments);
42
67
  }
43
68
  function _privateKeyExists() {
44
- _privateKeyExists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
45
- var url, privateKeyUrl, privateKey, _err$response, data, contentType, response;
46
- return _regenerator["default"].wrap(function _callee$(_context) {
47
- while (1) switch (_context.prev = _context.next) {
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) {
48
73
  case 0:
49
- url = new URL(webId);
50
- privateKeyUrl = url.hostname + '/profile/privateKey.ttl';
51
- _context.prev = 2;
52
- _solidLogic.store.fetcher.load(privateKeyUrl);
53
- privateKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'privateKey'));
54
- return _context.abrupt("return", privateKey);
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);
55
86
  case 8:
56
- _context.prev = 8;
57
- _context.t0 = _context["catch"](2);
58
- 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)) {
59
- _context.next = 25;
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;
60
91
  break;
61
92
  }
62
- _context.prev = 11;
93
+ _context2.prev = 11;
63
94
  // create privateKey resource
64
95
  data = '';
65
96
  contentType = 'text/ttl';
66
- _context.next = 16;
97
+ _context2.next = 16;
67
98
  return _solidLogic.store.fetcher.webOperation('PUT', privateKeyUrl, {
68
99
  data: data,
69
100
  contentType: contentType
70
101
  });
71
102
  case 16:
72
- response = _context.sent;
73
- _context.next = 23;
103
+ response = _context2.sent;
104
+ _context2.next = 23;
74
105
  break;
75
106
  case 19:
76
- _context.prev = 19;
77
- _context.t1 = _context["catch"](11);
78
- debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context.t1);
79
- throw _context.t1;
107
+ _context2.prev = 19;
108
+ _context2.t1 = _context2["catch"](11);
109
+ debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context2.t1);
110
+ throw _context2.t1;
80
111
  case 23:
81
112
  delete _solidLogic.store.fetcher.requested[privateKeyUrl]; // delete cached 404 error
82
- return _context.abrupt("return", undefined);
113
+ return _context2.abrupt("return", undefined);
83
114
  case 25:
84
- debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context.t0);
85
- throw _context.t0;
115
+ debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context2.t0);
116
+ throw _context2.t0;
86
117
  case 27:
87
118
  case "end":
88
- return _context.stop();
119
+ return _context2.stop();
89
120
  }
90
- }, _callee, null, [[2, 8], [11, 19]]);
121
+ }, _callee2, null, [[1, 8], [11, 19]]);
91
122
  }));
92
123
  return _privateKeyExists.apply(this, arguments);
93
124
  }
94
- function getPrivateKey(_x2) {
125
+ function getPrivateKey(_x3) {
95
126
  return _getPrivateKey.apply(this, arguments);
96
127
  }
97
128
  function _getPrivateKey() {
98
- _getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(webId) {
99
- var url, privateKeyUrl, publicKey, privateKey, del, add;
100
- return _regenerator["default"].wrap(function _callee2$(_context2) {
101
- while (1) switch (_context2.prev = _context2.next) {
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) {
102
133
  case 0:
103
- url = new URL(webId);
104
- privateKeyUrl = url.hostname + '/profile/privateKey.ttl'; // find publickey
105
- publicKey = publicKeyExists(webId); // find privateKey
106
- _context2.next = 5;
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;
107
144
  return privateKeyExists(webId);
108
- case 5:
109
- privateKey = _context2.sent;
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
110
157
  if (!(!privateKey || !publicKey)) {
111
- _context2.next = 17;
158
+ _context3.next = 20;
112
159
  break;
113
160
  }
114
161
  del = [];
115
162
  add = [];
116
- if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'privateKey'), privateKey, $rdf.sym(privateKeyUrl)));
117
- if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'publicKey'), publicKey, $rdf.sym(url.href)));
118
- privateKey = _solidLogic.store.sym(generatePrivateKey());
119
- publicKey = _solidLogic.store.sym(generatePublicKey(privateKey.uri));
120
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'privateKey'), $rdf.literal(privateKey.uri), $rdf.sym(privateKeyUrl)));
121
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'publicKey'), $rdf.literal(publicKey.uri), $rdf.sym(url.href)));
122
- _context2.next = 17;
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;
123
172
  return _solidLogic.store.updater.updateMany(del, add);
124
- case 17:
125
- return _context2.abrupt("return", privateKey.uri);
126
- case 18:
173
+ case 20:
174
+ return _context3.abrupt("return", privateKey);
175
+ case 21:
127
176
  case "end":
128
- return _context2.stop();
177
+ return _context3.stop();
129
178
  }
130
- }, _callee2);
179
+ }, _callee3);
131
180
  }));
132
181
  return _getPrivateKey.apply(this, arguments);
133
182
  }
@@ -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","uri","url","URL","hash","store","fetcher","load","href","any","sym","CERT","privateKeyExists","_x","_privateKeyExists","apply","arguments","_asyncToGenerator2","_regenerator","mark","_callee","privateKeyUrl","_err$response","data","contentType","response","wrap","_callee$","_context","prev","next","hostname","abrupt","t0","status","webOperation","sent","t1","log","requested","undefined","stop","getPrivateKey","_x2","_getPrivateKey","_callee2","del","add","_callee2$","_context2","push","st","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?.uri as any\r\n}\r\n\r\nfunction publicKeyExists (webId: string): NamedNode {\r\n // find publickey\r\n const url = new URL(webId)\r\n url.hash = ''\r\n store.fetcher.load(url.href)\r\n const publicKey = store.any(store.sym(webId), store.sym(CERT + 'publicKey'))\r\n return publicKey as NamedNode\r\n}\r\n\r\nasync function privateKeyExists (webId: string) {\r\n const url = new URL(webId)\r\n const privateKeyUrl = url.hostname + '/profile/privateKey.ttl'\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 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 const privateKeyUrl = url.hostname + '/profile/privateKey.ttl'\r\n // find publickey\r\n let publicKey = publicKeyExists(webId)\r\n // find privateKey\r\n let privateKey = await privateKeyExists(webId)\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'), privateKey, $rdf.sym(privateKeyUrl)))\r\n if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'publicKey'), publicKey, $rdf.sym(url.href)))\r\n\r\n privateKey = store.sym(generatePrivateKey())\r\n publicKey = store.sym(generatePublicKey(privateKey.uri))\r\n\r\n add.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'privateKey'), $rdf.literal(privateKey.uri), $rdf.sym(privateKeyUrl)))\r\n add.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'publicKey'), $rdf.literal(publicKey.uri), $rdf.sym(url.href)))\r\n await store.updater.updateMany(del, add)\r\n }\r\n return privateKey.uri 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,wBAA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ACC,eAAI,GAAG,WAAW,CAAC,EAAEZ,SAAS,EAAEhC,IAAI,CAAC2C,GAAG,CAACR,GAAG,CAACM,IAAI,CAAC,CAAC,CAAC;UAE9GZ,UAAU,GAAGS,iBAAK,CAACK,GAAG,CAACpB,kBAAkB,EAAE,CAAC;UAC5CS,SAAS,GAAGM,iBAAK,CAACK,GAAG,CAACf,iBAAiB,CAACC,UAAU,CAACK,GAAG,CAAC,CAAC;UAExD8C,GAAG,CAACG,IAAI,CAACnF,IAAI,CAACoF,EAAE,CAACpF,IAAI,CAAC2C,GAAG,CAACZ,KAAK,CAAC,EAAE/B,IAAI,CAAC2C,GAAG,CAACC,eAAI,GAAG,YAAY,CAAC,EAAE5C,IAAI,CAACqF,OAAO,CAACxD,UAAU,CAACK,GAAG,CAAC,EAAElC,IAAI,CAAC2C,GAAG,CAACW,aAAa,CAAC,CAAC,CAAC;UACxH0B,GAAG,CAACG,IAAI,CAACnF,IAAI,CAACoF,EAAE,CAACpF,IAAI,CAAC2C,GAAG,CAACZ,KAAK,CAAC,EAAE/B,IAAI,CAAC2C,GAAG,CAACC,eAAI,GAAG,WAAW,CAAC,EAAE5C,IAAI,CAACqF,OAAO,CAACrD,SAAS,CAACE,GAAG,CAAC,EAAElC,IAAI,CAAC2C,GAAG,CAACR,GAAG,CAACM,IAAI,CAAC,CAAC,CAAC;UAAAyC,SAAA,CAAAnB,IAAA;UAAA,OAC3GzB,iBAAK,CAACgD,OAAO,CAACC,UAAU,CAACR,GAAG,EAAEC,GAAG,CAAC;QAAA;UAAA,OAAAE,SAAA,CAAAjB,MAAA,WAEnCpC,UAAU,CAACK,GAAG;QAAA;QAAA;UAAA,OAAAgD,SAAA,CAAAR,IAAA;MAAA;IAAA,GAAAI,QAAA;EAAA,CACtB;EAAA,OAAAD,cAAA,CAAA7B,KAAA,OAAAC,SAAA;AAAA"}
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 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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,CAACwD,GAAG,CAACnB,YAAY,CAAC,CAAC,CAAC;UAE5HR,UAAU,GAAGN,kBAAkB,EAAE;UACjCS,SAAS,GAAGJ,iBAAiB,CAACC,UAAU,CAAC;UACzC;AACJ;UACIyD,GAAG,CAACI,IAAI,CAAC1F,IAAI,CAAC2F,EAAE,CAAC3F,IAAI,CAACwD,GAAG,CAACzB,KAAK,CAAC,EAAE/B,IAAI,CAACwD,GAAG,CAACC,eAAI,GAAG,YAAY,CAAC,EAAEzD,IAAI,CAAC6F,OAAO,CAAChE,UAAU,CAAC,EAAE7B,IAAI,CAACwD,GAAG,CAACM,aAAa,CAAC,CAAC,CAAC;UACpHwB,GAAG,CAACI,IAAI,CAAC1F,IAAI,CAAC2F,EAAE,CAAC3F,IAAI,CAACwD,GAAG,CAACzB,KAAK,CAAC,EAAE/B,IAAI,CAACwD,GAAG,CAACC,eAAI,GAAG,WAAW,CAAC,EAAEzD,IAAI,CAAC6F,OAAO,CAAC7D,SAAS,CAAC,EAAEhC,IAAI,CAACwD,GAAG,CAACnB,YAAY,CAAC,CAAC,CAAC;UAAAmD,SAAA,CAAArC,IAAA;UAAA,OAC3GC,iBAAK,CAAC0C,OAAO,CAACC,UAAU,CAACV,GAAG,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"}
@@ -115,21 +115,46 @@ function renderMessageRow(channelObject, message, fresh, options, userContext) {
115
115
  var creator = _solidLogic.store.any(message, ns.foaf('maker'));
116
116
  var date = _solidLogic.store.any(message, ns.dct('created'));
117
117
  var latestVersion = (0, _chatLogic.mostRecentVersion)(message);
118
- var content = _solidLogic.store.any(latestVersion, ns.sioc('content'));
119
- var signature = _solidLogic.store.any(message, $rdf.sym("".concat(_signature.SEC, "Proof")));
118
+ var latestVersionCreator = _solidLogic.store.any(latestVersion, ns.foaf('maker'));
119
+ // use latest content if same owner, else use original
120
+ var msgId = creator.uri === latestVersionCreator.uri ? latestVersion : message;
121
+ var content = _solidLogic.store.any(msgId, ns.sioc('content'));
122
+ 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));
120
124
 
121
125
  // verify signature
122
126
  var msg = (0, _signature.getBlankMsg)();
123
- msg.id = message;
124
- msg.created = date;
125
- // this is not correct.
126
- // If the message has been edited/deleted we must verify the latest message and may be the intermediate ones
127
- msg.content = content;
128
- msg.maker = creator;
129
-
130
- // pubKey could be store in a cache for all makers
131
- var pubKey = (0, _keys.getPublicKey)(creator); // alain no
132
- if (!(0, _signature.verifySignature)(signature, msg, pubKey)) throw new Error();
127
+ msg.id = msgId.uri;
128
+ msg.created = _solidLogic.store.any(msgId, ns.dct('created')).value;
129
+ msg.content = content.value;
130
+ msg.maker = creator.uri;
131
+ try {
132
+ var publicKey = function publicKey(webId) {
133
+ var pubKey;
134
+ (0, _keys.getPublicKey)(webId).then(function (publicKey) {
135
+ debug.log('alain publicKey ' + publicKey);
136
+ pubKey = publicKey;
137
+ });
138
+ return pubKey;
139
+ };
140
+ var pubKey = publicKey(creator.uri); // await getPublicKey(creator.uri)
141
+ debug.log('alain pubKey ' + pubKey);
142
+ debug.log(creator.uri);
143
+ } catch (err) {
144
+ debug.warn(err);
145
+ }
146
+ try {
147
+ // pubKey could be store in a cache for all makers
148
+ /* const pubKey0 = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'
149
+ debug.warn('publicKeys\n' + pubKey0 + '\n' + pubKey)
150
+ const privKey0 = getPrivateKey(creator.uri) // alain to remove
151
+ // unsigned messages should be signaled as unsecured
152
+ debug.warn(msg)
153
+ debug.warn(signature?.value) */
154
+ if (signature !== null && signature !== void 0 && signature.value && !(0, _signature.verifySignature)(signature.value, msg, pubKey)) throw new Error('invalid signature');
155
+ } catch (err) {
156
+ debug.log(err);
157
+ }
133
158
  var originalMessage = (0, _chatLogic.originalVersion)(message);
134
159
  var edited = !message.sameTerm(originalMessage);
135
160
  var sortDate = _solidLogic.store.the(originalMessage, ns.dct('created'), null, originalMessage.doc()); // In message