solid-ui 2.4.27-6c8461c9 → 2.4.27-70090f20

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, privateKey, errMsg;
88
+ var sts, now, timestamp, dateStamp, chatDocument, message, me, msg, oldMsgMaker, errMsg, privateKey, 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,57 +96,83 @@ 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;
101
- if (oldMsg) {
102
- // edit message replaces old one
103
- sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument));
104
- // do we need to rebuild oldMsg signaturen ?
105
- if (deleteIt) {
106
- sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument));
107
- msg.dateDeleted = dateStamp;
108
- }
109
- } else {
110
- // link new message to channel
111
- sts.push($rdf.st(_this.channel, ns.wf('message'), message, chatDocument));
99
+ msg = (0, _signature.getBlankMsg)();
100
+ msg.id = message.uri;
101
+ if (!oldMsg) {
102
+ _context2.next = 22;
103
+ break;
104
+ }
105
+ // edit message replaces old one
106
+ oldMsgMaker = _solidLogic.store.any(oldMsg, ns.foaf('maker')); // may not be needed here, but needed on READ
107
+ if (!(oldMsgMaker.uri === me.uri)) {
108
+ _context2.next = 16;
109
+ break;
110
+ }
111
+ sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument));
112
+ if (deleteIt) {
113
+ // we need to add a specific signature, else anyone can delete a msg ?
114
+ sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument));
115
+ // msg.dateDeleted = dateStamp
112
116
  }
117
+ _context2.next = 20;
118
+ break;
119
+ case 16:
120
+ errMsg = 'Error you cannot delete/edit a message from someone else : \n' + oldMsgMaker.uri;
121
+ debug.warn(errMsg);
122
+ alert(errMsg);
123
+ throw new Error(errMsg);
124
+ case 20:
125
+ _context2.next = 23;
126
+ break;
127
+ case 22:
128
+ // link new message to channel
129
+ sts.push($rdf.st(_this.channel, ns.wf('message'), message, chatDocument));
130
+ case 23:
113
131
  sts.push($rdf.st(message, ns.sioc('content'), _solidLogic.store.literal(text), chatDocument));
114
132
  msg.content = text;
115
133
  sts.push($rdf.st(message, ns.dct('created'), dateStamp, chatDocument));
116
- msg.created = dateStamp;
134
+ msg.created = dateStamp.value;
117
135
  if (!me) {
118
- _context2.next = 21;
136
+ _context2.next = 35;
119
137
  break;
120
138
  }
121
139
  sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument));
122
- msg.maker = me;
123
- // privateKey the cached private key of me, cache should be deleted after a certain time
124
- _context2.next = 19;
140
+ msg.maker = me.uri;
141
+ // privateKey the cached private key of me, cached in store
142
+ _context2.next = 32;
125
143
  return (0, _keys.getPrivateKey)(me);
126
- case 19:
144
+ case 32:
127
145
  privateKey = _context2.sent;
128
- sts.push($rdf.st(message, $rdf.sym("".concat(_signature.SEC, "Proof")), $rdf.sym((0, _signature.signMsg)(msg, privateKey), chatDocument)));
129
- case 21:
130
- _context2.prev = 21;
131
- _context2.next = 24;
146
+ // me.uri)
147
+ // const privateKey0 = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'
148
+ sig = (0, _signature.signMsg)(msg, privateKey); // const pubKey0 = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'
149
+ /* const pubKey = await getPublicKey(me)
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 35:
156
+ _context2.prev = 35;
157
+ _context2.next = 38;
132
158
  return _solidLogic.store.updater.update([], sts);
133
- case 24:
134
- _context2.next = 32;
159
+ case 38:
160
+ _context2.next = 46;
135
161
  break;
136
- case 26:
137
- _context2.prev = 26;
138
- _context2.t0 = _context2["catch"](21);
139
- errMsg = 'Error saving chat message: ' + _context2.t0;
140
- debug.warn(errMsg);
141
- alert(errMsg);
142
- throw new Error(errMsg);
143
- case 32:
162
+ case 40:
163
+ _context2.prev = 40;
164
+ _context2.t0 = _context2["catch"](35);
165
+ _errMsg = 'Error saving chat message: ' + _context2.t0;
166
+ debug.warn(_errMsg);
167
+ alert(_errMsg);
168
+ throw new Error(_errMsg);
169
+ case 46:
144
170
  return _context2.abrupt("return", message);
145
- case 33:
171
+ case 47:
146
172
  case "end":
147
173
  return _context2.stop();
148
174
  }
149
- }, _callee2, null, [[21, 26]]);
175
+ }, _callee2, null, [[35, 40]]);
150
176
  })();
151
177
  });
152
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","privateKey","errMsg","_callee2$","_context2","Date","getTime","term","leafDocumentFromDate","store","sym","uri","authn","currentUser","getBlankMsg","id","push","st","mostRecentVersion","dct","schema","dateDeleted","wf","sioc","literal","content","created","foaf","maker","getPrivateKey","sent","concat","SEC","signMsg","updater","update","t0","warn","alert","Error","_x2","_deleteMessage","_callee3","_callee3$","_context3","deleteMessage","_x3","exports","originalVersion","any","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 sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument))\n // do we need to rebuild oldMsg signaturen ?\n if (deleteIt) {\n sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument))\n msg.dateDeleted = dateStamp\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,w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,GAAG,CACP,wDAAwD,GAAG5G,GAAG,CAC/D;YAAAwG,SAAA,CAAAzF,IAAA;YAAAyF,SAAA,CAAAxF,IAAA;YAAA,OAEkB+B,iBAAK,CAAC0D,OAAO,CAACI,YAAY,CAAC,KAAK,EAAE7G,GAAG,CAACiD,GAAG,EAAE;cAC1DmD,IAAI,EAAJA,IAAI;cACJD,WAAW,EAAXA;YACF,CAAC,CAAC;UAAA;YAHFG,QAAQ,GAAAE,SAAA,CAAApC,IAAA;YAAAoC,SAAA,CAAAxF,IAAA;YAAA;UAAA;YAAAwF,SAAA,CAAAzF,IAAA;YAAAyF,SAAA,CAAAM,EAAA,GAAAN,SAAA;YAKR7I,KAAK,CAACiJ,GAAG,CAAC,gCAAgC,GAAG5G,GAAG,GAAG,IAAI,GAAAwG,SAAA,CAAAM,EAAM,CAAC;YAAA,MAAAN,SAAA,CAAAM,EAAA;UAAA;YAGhE,OAAO/D,iBAAK,CAAC0D,OAAO,CAACM,SAAS,CAAC/G,GAAG,CAACiD,GAAG,CAAC,EAAC;YACxC;YAAA,OAAAuD,SAAA,CAAAvF,MAAA,WACOqF,QAAQ;UAAA;YAEf3I,KAAK,CAACiJ,GAAG,CACP,6CAA6C,GAAG5G,GAAG,GAAG,IAAI,GAAAwG,SAAA,CAAA9B,EAAM,CACjE;YAAA,MAAA8B,SAAA,CAAA9B,EAAA;UAAA;YAAA,OAAA8B,SAAA,CAAAvF,MAAA,WAKEqF,QAAQ;UAAA;UAAA;YAAA,OAAAE,SAAA,CAAArF,IAAA;QAAA;MAAA,GAAAkF,QAAA;IAAA;EAAA,CAChB;EAAA,OAAAH,mBAAA,CAAA5E,KAAA,OAAAC,SAAA;AAAA"}
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","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","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) // me.uri)\n // const privateKey0 = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'\n\n const sig = signMsg(msg, privateKey)\n // const pubKey0 = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'\n /* const pubKey = await getPublicKey(me)\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,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAA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AAAH,SAAA,CAAA3F,IAAA;cAAA;YAAA;YAC7BrD,KAAK,CAACoJ,GAAG,CACP,wDAAwD,GAAG/G,GAAG,CAC/D;YAAA2G,SAAA,CAAA5F,IAAA;YAAA4F,SAAA,CAAA3F,IAAA;YAAA,OAEkBkC,iBAAK,CAAC0D,OAAO,CAACI,YAAY,CAAC,KAAK,EAAEhH,GAAG,CAACoD,GAAG,EAAE;cAC1DmD,IAAI,EAAJA,IAAI;cACJD,WAAW,EAAXA;YACF,CAAC,CAAC;UAAA;YAHFG,QAAQ,GAAAE,SAAA,CAAAjC,IAAA;YAAAiC,SAAA,CAAA3F,IAAA;YAAA;UAAA;YAAA2F,SAAA,CAAA5F,IAAA;YAAA4F,SAAA,CAAAM,EAAA,GAAAN,SAAA;YAKRhJ,KAAK,CAACoJ,GAAG,CAAC,gCAAgC,GAAG/G,GAAG,GAAG,IAAI,GAAA2G,SAAA,CAAAM,EAAM,CAAC;YAAA,MAAAN,SAAA,CAAAM,EAAA;UAAA;YAGhE,OAAO/D,iBAAK,CAAC0D,OAAO,CAACM,SAAS,CAAClH,GAAG,CAACoD,GAAG,CAAC,EAAC;YACxC;YAAA,OAAAuD,SAAA,CAAA1F,MAAA,WACOwF,QAAQ;UAAA;YAEf9I,KAAK,CAACoJ,GAAG,CACP,6CAA6C,GAAG/G,GAAG,GAAG,IAAI,GAAA2G,SAAA,CAAA1B,EAAM,CACjE;YAAA,MAAA0B,SAAA,CAAA1B,EAAA;UAAA;YAAA,OAAA0B,SAAA,CAAA1F,MAAA,WAKEwF,QAAQ;UAAA;UAAA;YAAA,OAAAE,SAAA,CAAAxF,IAAA;QAAA;MAAA,GAAAqF,QAAA;IAAA;EAAA,CAChB;EAAA,OAAAH,mBAAA,CAAA/E,KAAA,OAAAC,SAAA;AAAA"}
@@ -1,5 +1,13 @@
1
+ import { NamedNode } from 'rdflib';
1
2
  export declare function generatePrivateKey(): string;
2
3
  export declare function generatePublicKey(privateKey: string): string;
3
- export declare function getPublicKey(webId: any): any;
4
- export declare function getPrivateKey(webId: any): Promise<any>;
4
+ /**
5
+ * getPublicKey
6
+ * used for displaying messages in chat, therefore does not
7
+ * create a new key if not found
8
+ * @param webId
9
+ * @returns string | undefined
10
+ */
11
+ export declare function getPublicKey(webId: NamedNode): Promise<string | undefined>;
12
+ export declare function getPrivateKey(webId: NamedNode): Promise<string>;
5
13
  //# 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,OAQlC;AAmBD,wBAAsB,aAAa,CAAE,KAAK,KAAA,gBAsBzC"}
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/chat/keys.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAKlC,wBAAgB,kBAAkB,IAAK,MAAM,CAE5C;AAED,wBAAgB,iBAAiB,CAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAE,KAAK,EAAE,SAAS,+BAUnD;AAED,wBAAsB,aAAa,CAAE,KAAK,EAAE,SAAS,mBA6CpD"}
package/lib/chat/keys.js CHANGED
@@ -11,80 +11,213 @@ exports.getPrivateKey = getPrivateKey;
11
11
  exports.getPublicKey = getPublicKey;
12
12
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
13
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
+ var debug = _interopRequireWildcard(require("../debug"));
14
15
  var _secp256k = require("@noble/curves/secp256k1");
15
16
  var _utils = require("@noble/hashes/utils");
16
17
  var _signature = require("./signature");
17
18
  var _solidLogic = require("solid-logic");
18
19
  var $rdf = _interopRequireWildcard(require("rdflib"));
20
+ var _accessData = require("../utils/keyHelpers/accessData");
21
+ var _acl = require("../utils/keyHelpers/acl");
19
22
  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); }
20
23
  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; }
21
- // should have webcrypto.getRandomValues defined
22
-
23
24
  function generatePrivateKey() {
24
25
  return (0, _utils.bytesToHex)(_secp256k.schnorr.utils.randomPrivateKey());
25
26
  }
26
27
  function generatePublicKey(privateKey) {
27
28
  return (0, _utils.bytesToHex)(_secp256k.schnorr.getPublicKey(privateKey));
28
29
  }
29
- function getPublicKey(webId) {
30
- // find publickey
31
- /* const url = new URL(webId)
32
- url.hash = ''
33
- store.fetcher.load(url.href)
34
- let publicKey = store.any(store.sym(webId), store.sym(CERT +'publicKey')) */
35
- var publicKey = publicKeyExists(webId);
36
- return publicKey === null || publicKey === void 0 ? void 0 : publicKey.uri;
37
- }
38
- function publicKeyExists(webId) {
39
- // find publickey
40
- var url = new URL(webId);
41
- url.hash = '';
42
- _solidLogic.store.fetcher.load(url.href);
43
- var publicKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'publicKey'));
44
- return publicKey;
30
+
31
+ /**
32
+ * getPublicKey
33
+ * used for displaying messages in chat, therefore does not
34
+ * create a new key if not found
35
+ * @param webId
36
+ * @returns string | undefined
37
+ */
38
+ function getPublicKey(_x) {
39
+ return _getPublicKey.apply(this, arguments);
45
40
  }
46
- function privateKeyExists(webId) {
47
- var url = new URL(webId);
48
- var privateKeyUrl = url.hostname + '/profile/privateKey.ttl';
49
- _solidLogic.store.fetcher.load(privateKeyUrl);
50
- var privateKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'privateKey'));
51
- return privateKey;
41
+ function _getPublicKey() {
42
+ _getPublicKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
43
+ var publicKeyDoc, key;
44
+ return _regenerator["default"].wrap(function _callee$(_context) {
45
+ while (1) switch (_context.prev = _context.next) {
46
+ case 0:
47
+ _context.next = 2;
48
+ return _solidLogic.store.fetcher.load(webId);
49
+ case 2:
50
+ _context.next = 4;
51
+ return (0, _accessData.pubKeyUrl)(webId);
52
+ case 4:
53
+ publicKeyDoc = _context.sent;
54
+ _context.prev = 5;
55
+ _context.next = 8;
56
+ return _solidLogic.store.fetcher.load(publicKeyDoc);
57
+ case 8:
58
+ // url.href)
59
+ key = _solidLogic.store.any(webId, _solidLogic.store.sym(_signature.CERT + 'PublicKey'));
60
+ return _context.abrupt("return", key === null || key === void 0 ? void 0 : key.value);
61
+ case 12:
62
+ _context.prev = 12;
63
+ _context.t0 = _context["catch"](5);
64
+ return _context.abrupt("return", undefined);
65
+ case 15:
66
+ case "end":
67
+ return _context.stop();
68
+ }
69
+ }, _callee, null, [[5, 12]]);
70
+ }));
71
+ return _getPublicKey.apply(this, arguments);
52
72
  }
53
- function getPrivateKey(_x) {
73
+ function getPrivateKey(_x2) {
54
74
  return _getPrivateKey.apply(this, arguments);
55
75
  }
76
+ /**
77
+ * delete acl if keydoc exists
78
+ * create/edit keyDoc
79
+ * set keyDoc acl
80
+ */
56
81
  function _getPrivateKey() {
57
- _getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
58
- var url, privateKeyUrl, publicKey, privateKey, del, add;
59
- return _regenerator["default"].wrap(function _callee$(_context) {
60
- while (1) switch (_context.prev = _context.next) {
82
+ _getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(webId) {
83
+ var publicKeyDoc, privateKeyDoc, publicKey, privateKey, validPublicKey, del, add, newPublicKey, keyContainer;
84
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
85
+ while (1) switch (_context2.prev = _context2.next) {
61
86
  case 0:
62
- url = new URL(webId);
63
- privateKeyUrl = url.hostname + '/profile/privateKey.ttl'; // find publickey
64
- publicKey = publicKeyExists(webId); // find privateKey
65
- privateKey = privateKeyExists(webId); // create key pair
66
- if (!(!privateKey || !publicKey)) {
67
- _context.next = 15;
87
+ _context2.next = 2;
88
+ return _solidLogic.store.fetcher.load(webId);
89
+ case 2:
90
+ _context2.next = 4;
91
+ return (0, _accessData.pubKeyUrl)(webId);
92
+ case 4:
93
+ publicKeyDoc = _context2.sent;
94
+ _context2.next = 7;
95
+ return (0, _accessData.privKeyUrl)(webId);
96
+ case 7:
97
+ privateKeyDoc = _context2.sent;
98
+ _context2.next = 10;
99
+ return (0, _accessData.getExistingPublicKey)(webId, publicKeyDoc);
100
+ case 10:
101
+ publicKey = _context2.sent;
102
+ _context2.next = 13;
103
+ return (0, _accessData.getExistingPrivateKey)(webId, privateKeyDoc);
104
+ case 13:
105
+ privateKey = _context2.sent;
106
+ // is publicKey valid ?
107
+ validPublicKey = true;
108
+ if (privateKey && publicKey !== generatePublicKey(privateKey)) {
109
+ if (confirm('This is strange the publicKey is not valid for\n' + (webId === null || webId === void 0 ? void 0 : webId.uri) + '\'shall we repair keeping the private key ?')) validPublicKey = false;
110
+ }
111
+
112
+ // create key pair or repair publicKey
113
+ if (!(!privateKey || !publicKey || !validPublicKey)) {
114
+ _context2.next = 34;
68
115
  break;
69
116
  }
70
117
  del = [];
71
- add = [];
72
- if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'privateKey'), privateKey, $rdf.sym(privateKeyUrl)));
73
- if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'publicKey'), publicKey, $rdf.sym(url.href)));
74
- privateKey = _solidLogic.store.sym(generatePrivateKey());
75
- publicKey = _solidLogic.store.sym(generatePublicKey(privateKey.uri));
76
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'privateKey'), $rdf.literal(privateKey.uri), $rdf.sym(privateKeyUrl)));
77
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'publicKey'), $rdf.literal(publicKey.uri), $rdf.sym(url.href)));
78
- _context.next = 15;
79
- return _solidLogic.store.updater.updateMany(del, add);
80
- case 15:
81
- return _context.abrupt("return", privateKey.uri);
82
- case 16:
118
+ add = []; // if (privateKey) del.push($rdf.st(webId, store.sym(CERT + 'PrivateKey'), $rdf.lit(privateKey), store.sym(privateKeyDoc)))
119
+ if (privateKey) {
120
+ _context2.next = 24;
121
+ break;
122
+ }
123
+ // add = []
124
+ privateKey = generatePrivateKey();
125
+ add = [$rdf.st(webId, _solidLogic.store.sym(_signature.CERT + 'PrivateKey'), $rdf.literal(privateKey), _solidLogic.store.sym(privateKeyDoc))];
126
+ _context2.next = 24;
127
+ return saveKey(privateKeyDoc, [], add, webId.uri);
128
+ case 24:
129
+ if (!(!publicKey || !validPublicKey)) {
130
+ _context2.next = 31;
131
+ break;
132
+ }
133
+ del = [];
134
+ // delete invalid public key
135
+ if (publicKey) {
136
+ del = [$rdf.st(webId, _solidLogic.store.sym(_signature.CERT + 'PublicKey'), $rdf.lit(publicKey), _solidLogic.store.sym(publicKeyDoc))];
137
+ debug.log(del);
138
+ }
139
+ // update new valid key
140
+ newPublicKey = generatePublicKey(privateKey);
141
+ add = [$rdf.st(webId, _solidLogic.store.sym(_signature.CERT + 'PublicKey'), $rdf.literal(newPublicKey), _solidLogic.store.sym(publicKeyDoc))];
142
+ _context2.next = 31;
143
+ return saveKey(publicKeyDoc, del, add);
144
+ case 31:
145
+ keyContainer = privateKeyDoc.substring(0, privateKeyDoc.lastIndexOf('/') + 1);
146
+ _context2.next = 34;
147
+ return (0, _acl.setAcl)(keyContainer, (0, _acl.keyContainerAclBody)(webId.uri));
148
+ case 34:
149
+ return _context2.abrupt("return", privateKey);
150
+ case 35:
83
151
  case "end":
84
- return _context.stop();
152
+ return _context2.stop();
85
153
  }
86
- }, _callee);
154
+ }, _callee2);
87
155
  }));
88
156
  return _getPrivateKey.apply(this, arguments);
89
157
  }
158
+ function saveKey(_x3, _x4, _x5) {
159
+ return _saveKey.apply(this, arguments);
160
+ }
161
+ function _saveKey() {
162
+ _saveKey = (0, _asyncToGenerator2["default"])(function (keyDoc, del, add) {
163
+ var me = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
164
+ return /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
165
+ var keyAclDoc, response, aclBody;
166
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
167
+ while (1) switch (_context3.prev = _context3.next) {
168
+ case 0:
169
+ _context3.next = 2;
170
+ return _solidLogic.store.fetcher.load(keyDoc);
171
+ case 2:
172
+ _context3.prev = 2;
173
+ // get keyAcldoc
174
+ keyAclDoc = _solidLogic.store.any(_solidLogic.store.sym(keyDoc), _solidLogic.store.sym('http://www.iana.org/assignments/link-relations/acl'));
175
+ if (!keyAclDoc) {
176
+ _context3.next = 17;
177
+ break;
178
+ }
179
+ _context3.prev = 5;
180
+ _context3.next = 8;
181
+ return _solidLogic.store.fetcher.webOperation('DELETE', keyAclDoc.value);
182
+ case 8:
183
+ response = _context3.sent;
184
+ // this may fail if webId is not an owner
185
+ debug.log('delete ' + keyAclDoc.value + ' ' + response.status); // should test 404 and 2xx
186
+ _context3.next = 17;
187
+ break;
188
+ case 12:
189
+ _context3.prev = 12;
190
+ _context3.t0 = _context3["catch"](5);
191
+ if (!(_context3.t0.response.status !== 404)) {
192
+ _context3.next = 16;
193
+ break;
194
+ }
195
+ throw new Error(_context3.t0);
196
+ case 16:
197
+ debug.log('delete ' + keyAclDoc.value + ' ' + _context3.t0.response.status); // should test 404 and 2xx
198
+ case 17:
199
+ _context3.next = 19;
200
+ return _solidLogic.store.updater.updateMany(del, add);
201
+ case 19:
202
+ // or a promise store.updater.update ?
203
+ // create READ only ACL
204
+ aclBody = (0, _acl.keyAclBody)(keyDoc, me);
205
+ _context3.next = 22;
206
+ return (0, _acl.setAcl)(keyDoc, aclBody);
207
+ case 22:
208
+ _context3.next = 27;
209
+ break;
210
+ case 24:
211
+ _context3.prev = 24;
212
+ _context3.t1 = _context3["catch"](2);
213
+ throw new Error(_context3.t1);
214
+ case 27:
215
+ case "end":
216
+ return _context3.stop();
217
+ }
218
+ }, _callee3, null, [[2, 24], [5, 12]]);
219
+ })();
220
+ });
221
+ return _saveKey.apply(this, arguments);
222
+ }
90
223
  //# sourceMappingURL=keys.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"keys.js","names":["_secp256k","require","_utils","_signature","_solidLogic","$rdf","_interopRequireWildcard","_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","privateKeyUrl","hostname","getPrivateKey","_x","_getPrivateKey","apply","arguments","_asyncToGenerator2","_regenerator","mark","_callee","del","add","wrap","_callee$","_context","prev","next","push","st","literal","updater","updateMany","abrupt","stop"],"sources":["../../src/chat/keys.ts"],"sourcesContent":["import { 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\nimport crypto from 'crypto' // should have webcrypto.getRandomValues defined\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 // find publickey\r\n /* const url = new URL(webId)\r\n url.hash = ''\r\n store.fetcher.load(url.href)\r\n let publicKey = store.any(store.sym(webId), store.sym(CERT +'publicKey')) */\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\nfunction privateKeyExists (webId: string): NamedNode {\r\n const url = new URL(webId)\r\n const privateKeyUrl = url.hostname + '/profile/privateKey.ttl'\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}\r\n\r\nexport async function getPrivateKey (webId) {\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 = 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 any\r\n}\r\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAC,uBAAA,CAAAL,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,SAAAF,wBAAAM,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,GA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A,CAAAE,IAAA;UAAA,OAC3GzB,iBAAK,CAAC6B,OAAO,CAACC,UAAU,CAACX,GAAG,EAAEC,GAAG,CAAC;QAAA;UAAA,OAAAG,QAAA,CAAAQ,MAAA,WAEnCxC,UAAU,CAACK,GAAG;QAAA;QAAA;UAAA,OAAA2B,QAAA,CAAAS,IAAA;MAAA;IAAA,GAAAd,OAAA;EAAA,CACtB;EAAA,OAAAN,cAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA"}
1
+ {"version":3,"file":"keys.js","names":["debug","_interopRequireWildcard","require","_secp256k","_utils","_signature","_solidLogic","$rdf","_accessData","_acl","_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","sent","any","sym","CERT","abrupt","value","t0","undefined","stop","getPrivateKey","_x2","_getPrivateKey","_callee2","privateKeyDoc","publicKey","validPublicKey","del","add","newPublicKey","keyContainer","_callee2$","_context2","privKeyUrl","getExistingPublicKey","getExistingPrivateKey","confirm","uri","st","literal","saveKey","lit","log","substring","lastIndexOf","setAcl","keyContainerAclBody","_x3","_x4","_x5","_saveKey","keyDoc","me","length","_callee3","keyAclDoc","response","aclBody","_callee3$","_context3","webOperation","status","Error","updater","updateMany","keyAclBody","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 { NamedNode } from 'rdflib'\r\nimport * as $rdf from 'rdflib'\r\nimport { getExistingPublicKey, pubKeyUrl, privKeyUrl, getExistingPrivateKey } from '../utils/keyHelpers/accessData'\r\nimport { setAcl, keyContainerAclBody, keyAclBody } from '../utils/keyHelpers/acl'\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\n/**\r\n * getPublicKey\r\n * used for displaying messages in chat, therefore does not\r\n * create a new key if not found\r\n * @param webId\r\n * @returns string | undefined\r\n */\r\nexport async function getPublicKey (webId: NamedNode) {\r\n await store.fetcher.load(webId)\r\n const publicKeyDoc = await pubKeyUrl(webId)\r\n try {\r\n await store.fetcher.load(publicKeyDoc) // url.href)\r\n const key = store.any(webId, store.sym(CERT + 'PublicKey'))\r\n return key?.value // as NamedNode\r\n } catch (err) {\r\n return undefined\r\n }\r\n}\r\n\r\nexport async function getPrivateKey (webId: NamedNode) {\r\n await store.fetcher.load(webId)\r\n // find keys url's\r\n const publicKeyDoc = await pubKeyUrl(webId)\r\n const privateKeyDoc = await privKeyUrl(webId)\r\n\r\n // find key pair\r\n const publicKey = await getExistingPublicKey(webId, publicKeyDoc)\r\n let privateKey = await getExistingPrivateKey(webId, privateKeyDoc)\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?.uri +\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(webId, store.sym(CERT + 'PrivateKey'), $rdf.lit(privateKey), store.sym(privateKeyDoc)))\r\n\r\n if (!privateKey) {\r\n // add = []\r\n privateKey = generatePrivateKey()\r\n add = [$rdf.st(webId, store.sym(CERT + 'PrivateKey'), $rdf.literal(privateKey), store.sym(privateKeyDoc))]\r\n await saveKey(privateKeyDoc, [], add, webId.uri)\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(webId, store.sym(CERT + 'PublicKey'), $rdf.lit(publicKey), store.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(webId, store.sym(CERT + 'PublicKey'), $rdf.literal(newPublicKey), store.sym(publicKeyDoc))]\r\n await saveKey(publicKeyDoc, del, add)\r\n }\r\n const keyContainer = privateKeyDoc.substring(0, privateKeyDoc.lastIndexOf('/') + 1)\r\n await setAcl(keyContainer, keyContainerAclBody(webId.uri)) // includes DELETE and PUT\r\n }\r\n return privateKey as string\r\n}\r\n\r\n/**\r\n * delete acl if keydoc exists\r\n * create/edit keyDoc\r\n * set keyDoc acl\r\n */\r\nasync function saveKey (keyDoc: string, del, add, me: string = '') {\r\n await store.fetcher.load(keyDoc)\r\n // delete keyAclDoc\r\n try {\r\n // get keyAcldoc\r\n const keyAclDoc = store.any(store.sym(keyDoc), store.sym('http://www.iana.org/assignments/link-relations/acl'))\r\n if (keyAclDoc) {\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\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 const aclBody = keyAclBody(keyDoc, me)\r\n await setAcl(keyDoc, aclBody)\r\n } catch (err) { throw new Error(err) }\r\n}\r\n"],"mappings":";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CAAArD,IAAA;cAAA;YAAA;YAAA,MAAU,IAAIwD,KAAK,CAAAH,SAAA,CAAA1C,EAAA,CAAK;UAAA;YACvDjE,KAAK,CAAC0F,GAAG,CAAC,SAAS,GAAGa,SAAS,CAACvC,KAAK,GAAG,GAAG,GAAG2C,SAAA,CAAA1C,EAAA,CAAIuC,QAAQ,CAACK,MAAM,CAAC,EAAC;UAAA;YAAAF,SAAA,CAAArD,IAAA;YAAA,OAKjEC,iBAAK,CAACwD,OAAO,CAACC,UAAU,CAACrC,GAAG,EAAEC,GAAG,CAAC;UAAA;YAAC;YAEzC;YACM6B,OAAO,GAAG,IAAAQ,eAAU,EAACd,MAAM,EAAEC,EAAE,CAAC;YAAAO,SAAA,CAAArD,IAAA;YAAA,OAChC,IAAAuC,WAAM,EAACM,MAAM,EAAEM,OAAO,CAAC;UAAA;YAAAE,SAAA,CAAArD,IAAA;YAAA;UAAA;YAAAqD,SAAA,CAAAtD,IAAA;YAAAsD,SAAA,CAAAO,EAAA,GAAAP,SAAA;YAAA,MACT,IAAIG,KAAK,CAAAH,SAAA,CAAAO,EAAA,CAAK;UAAA;UAAA;YAAA,OAAAP,SAAA,CAAAxC,IAAA;QAAA;MAAA,GAAAmC,QAAA;IAAA;EAAA,CACrC;EAAA,OAAAJ,QAAA,CAAAxD,KAAA,OAAAC,SAAA;AAAA"}
@@ -115,21 +115,39 @@ 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'));
120
119
 
121
- // verify signature
120
+ // use latest content if same owner, else use original
121
+ var msgId = creator.uri === latestVersionCreator.uri ? latestVersion : message;
122
+ var content = _solidLogic.store.any(msgId, ns.sioc('content'));
123
+ var signature = _solidLogic.store.any(msgId, $rdf.sym("".concat(_signature.SEC, "Proof")));
124
+
125
+ // set message object
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;
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
+
132
+ // unsigned message
133
+ if (!(signature !== null && signature !== void 0 && signature.value)) debug.warn(msgId.uri + ' is unsigned'); // TODO replace with UI (colored message ?)
129
134
 
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();
135
+ // signed message, get public key and check signature
136
+ else {
137
+ (0, _keys.getPublicKey)(creator).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)
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
+ });
150
+ }
133
151
  var originalMessage = (0, _chatLogic.originalVersion)(message);
134
152
  var edited = !message.sameTerm(originalMessage);
135
153
  var sortDate = _solidLogic.store.the(originalMessage, ns.dct('created'), null, originalMessage.doc()); // In message