solid-ui 2.4.27-98e67fad → 2.4.27-9d7e618e

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.
Files changed (86) hide show
  1. package/dist/670.solid-ui.min.js +1 -0
  2. package/dist/805.solid-ui.min.js +3 -0
  3. package/dist/805.solid-ui.min.js.LICENSE.txt +58 -0
  4. package/dist/805.solid-ui.min.js.map +1 -0
  5. package/dist/_2b19.solid-ui.js +14 -0
  6. package/dist/_2b19.solid-ui.js.map +1 -0
  7. package/dist/index.html +1 -9
  8. package/dist/{main.js → solid-ui.js} +6215 -19327
  9. package/dist/solid-ui.js.map +1 -0
  10. package/dist/solid-ui.min.js +3 -0
  11. package/dist/solid-ui.min.js.LICENSE.txt +54 -0
  12. package/dist/solid-ui.min.js.map +1 -0
  13. package/dist/vendors-node_modules_jsonld_lib_jsonld_js.solid-ui.js +12134 -0
  14. package/dist/vendors-node_modules_jsonld_lib_jsonld_js.solid-ui.js.map +1 -0
  15. package/lib/acl/access-controller.d.ts +2 -3
  16. package/lib/acl/access-controller.d.ts.map +1 -1
  17. package/lib/acl/access-controller.js +17 -15
  18. package/lib/acl/access-controller.js.map +1 -1
  19. package/lib/acl/access-groups.d.ts.map +1 -1
  20. package/lib/acl/access-groups.js +78 -8
  21. package/lib/acl/access-groups.js.map +1 -1
  22. package/lib/acl/acl-control.d.ts.map +1 -1
  23. package/lib/acl/acl-control.js +10 -11
  24. package/lib/acl/acl-control.js.map +1 -1
  25. package/lib/acl/acl.d.ts +1 -1
  26. package/lib/acl/acl.js +1 -1
  27. package/lib/acl/acl.js.map +1 -1
  28. package/lib/acl/add-agent-buttons.d.ts.map +1 -1
  29. package/lib/acl/add-agent-buttons.js +4 -3
  30. package/lib/acl/add-agent-buttons.js.map +1 -1
  31. package/lib/chat/chatLogic.js +62 -26
  32. package/lib/chat/chatLogic.js.map +1 -1
  33. package/lib/chat/crypto.d.ts +1 -0
  34. package/lib/chat/crypto.d.ts.map +1 -0
  35. package/lib/chat/crypto.js +257 -0
  36. package/lib/chat/crypto.js.map +1 -0
  37. package/lib/chat/keys.d.ts +5 -0
  38. package/lib/chat/keys.d.ts.map +1 -0
  39. package/lib/chat/keys.js +134 -0
  40. package/lib/chat/keys.js.map +1 -0
  41. package/lib/chat/message.js +16 -0
  42. package/lib/chat/message.js.map +1 -1
  43. package/lib/chat/signature.d.ts +27 -0
  44. package/lib/chat/signature.d.ts.map +1 -0
  45. package/lib/chat/signature.js +110 -0
  46. package/lib/chat/signature.js.map +1 -0
  47. package/lib/footer/index.d.ts.map +1 -1
  48. package/lib/footer/index.js +5 -1
  49. package/lib/footer/index.js.map +1 -1
  50. package/lib/header/index.d.ts.map +1 -1
  51. package/lib/header/index.js +41 -20
  52. package/lib/header/index.js.map +1 -1
  53. package/lib/login/login.d.ts.map +1 -1
  54. package/lib/login/login.js +13 -15
  55. package/lib/login/login.js.map +1 -1
  56. package/lib/style.js +60 -2
  57. package/lib/style.js.map +1 -1
  58. package/lib/utils/headerFooterHelpers.d.ts +0 -4
  59. package/lib/utils/headerFooterHelpers.d.ts.map +1 -1
  60. package/lib/utils/headerFooterHelpers.js +0 -27
  61. package/lib/utils/headerFooterHelpers.js.map +1 -1
  62. package/lib/versionInfo.js +5 -5
  63. package/lib/versionInfo.js.map +1 -1
  64. package/lib/widgets/buttons.d.ts.map +1 -1
  65. package/lib/widgets/buttons.js +43 -49
  66. package/lib/widgets/buttons.js.map +1 -1
  67. package/lib/widgets/forms.js +8 -4
  68. package/lib/widgets/forms.js.map +1 -1
  69. package/package.json +13 -10
  70. package/dist/main.js.map +0 -1
  71. package/lib/acl/styles.d.ts +0 -90
  72. package/lib/acl/styles.d.ts.map +0 -1
  73. package/lib/acl/styles.js +0 -98
  74. package/lib/acl/styles.js.map +0 -1
  75. package/lib/footer/styleMap.d.ts +0 -8
  76. package/lib/footer/styleMap.d.ts.map +0 -1
  77. package/lib/footer/styleMap.js +0 -15
  78. package/lib/footer/styleMap.js.map +0 -1
  79. package/lib/header/styleMap.d.ts +0 -117
  80. package/lib/header/styleMap.d.ts.map +0 -1
  81. package/lib/header/styleMap.js +0 -139
  82. package/lib/header/styleMap.js.map +0 -1
  83. package/lib/jss/index.d.ts +0 -20
  84. package/lib/jss/index.d.ts.map +0 -1
  85. package/lib/jss/index.js +0 -47
  86. package/lib/jss/index.js.map +0 -1
@@ -23,6 +23,8 @@ var _solidLogic = require("solid-logic");
23
23
  var ns = _interopRequireWildcard(require("../ns"));
24
24
  var $rdf = _interopRequireWildcard(require("rdflib"));
25
25
  var utils = _interopRequireWildcard(require("../utils"));
26
+ var _signature = require("./signature");
27
+ var _keys = require("./keys");
26
28
  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); }
27
29
  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; }
28
30
  /**
@@ -83,7 +85,7 @@ var ChatChannel = /*#__PURE__*/function () {
83
85
  var oldMsg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
84
86
  var deleteIt = arguments.length > 2 ? arguments[2] : undefined;
85
87
  return /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
86
- var sts, now, timestamp, dateStamp, chatDocument, message, me, msg;
88
+ var sts, now, timestamp, dateStamp, chatDocument, message, me, msg, oldMsgMaker, errMsg, privateKey, _errMsg;
87
89
  return _regenerator["default"].wrap(function _callee2$(_context2) {
88
90
  while (1) switch (_context2.prev = _context2.next) {
89
91
  case 0:
@@ -94,41 +96,75 @@ var ChatChannel = /*#__PURE__*/function () {
94
96
  chatDocument = oldMsg ? oldMsg.doc() : _this.dateFolder.leafDocumentFromDate(now);
95
97
  message = _solidLogic.store.sym(chatDocument.uri + '#' + 'Msg' + timestamp); // const content = store.literal(text)
96
98
  me = _solidLogic.authn.currentUser(); // If already logged on
97
- if (oldMsg) {
98
- // edit message replaces old one
99
- sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument));
100
- if (deleteIt) {
101
- sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument));
102
- }
103
- } else {
104
- // link new message to channel
105
- sts.push($rdf.st(_this.channel, ns.wf('message'), message, chatDocument));
99
+ msg = _signature.getBlankMsg;
100
+ msg.id = message;
101
+ if (!oldMsg) {
102
+ _context2.next = 22;
103
+ break;
106
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;
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:
107
131
  sts.push($rdf.st(message, ns.sioc('content'), _solidLogic.store.literal(text), chatDocument));
132
+ msg.content = text;
108
133
  sts.push($rdf.st(message, ns.dct('created'), dateStamp, chatDocument));
109
- if (me) {
110
- sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument));
134
+ msg.created = dateStamp;
135
+ if (!me) {
136
+ _context2.next = 34;
137
+ break;
111
138
  }
112
- _context2.prev = 11;
113
- _context2.next = 14;
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
142
+ _context2.next = 32;
143
+ return (0, _keys.getPrivateKey)(me);
144
+ case 32:
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;
114
150
  return _solidLogic.store.updater.update([], sts);
115
- case 14:
116
- _context2.next = 22;
151
+ case 37:
152
+ _context2.next = 45;
117
153
  break;
118
- case 16:
119
- _context2.prev = 16;
120
- _context2.t0 = _context2["catch"](11);
121
- msg = 'Error saving chat message: ' + _context2.t0;
122
- debug.warn(msg);
123
- alert(msg);
124
- throw new Error(msg);
125
- case 22:
154
+ case 39:
155
+ _context2.prev = 39;
156
+ _context2.t0 = _context2["catch"](34);
157
+ _errMsg = 'Error saving chat message: ' + _context2.t0;
158
+ debug.warn(_errMsg);
159
+ alert(_errMsg);
160
+ throw new Error(_errMsg);
161
+ case 45:
126
162
  return _context2.abrupt("return", message);
127
- case 23:
163
+ case 46:
128
164
  case "end":
129
165
  return _context2.stop();
130
166
  }
131
- }, _callee2, null, [[11, 16]]);
167
+ }, _callee2, null, [[34, 39]]);
132
168
  })();
133
169
  });
134
170
  function updateMessage(_x2) {
@@ -1 +1 @@
1
- {"version":3,"file":"chatLogic.js","names":["debug","_interopRequireWildcard","require","_dateFolder","_solidLogic","ns","$rdf","utils","_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","_callee2$","_context2","Date","getTime","term","leafDocumentFromDate","store","sym","uri","authn","currentUser","push","st","mostRecentVersion","dct","schema","wf","sioc","literal","foaf","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","sent","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'\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 if (oldMsg) { // edit message replaces old one\n sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument))\n if (deleteIt) {\n sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument))\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 sts.push(\n $rdf.st(message, ns.dct('created'), dateStamp, chatDocument)\n )\n if (me) {\n sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument))\n }\n try {\n await store.updater.update([], sts)\n } catch (err) {\n const msg = 'Error saving chat message: ' + err\n debug.warn(msg)\n alert(msg)\n throw new Error(msg)\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;AAAiC,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;AAA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AAA,CAAA9B,EAAM,CACjE;YAAA,MAAA8B,SAAA,CAAA9B,EAAA;UAAA;YAAA,OAAA8B,SAAA,CAAA1E,MAAA,WAKEwE,QAAQ;UAAA;UAAA;YAAA,OAAAE,SAAA,CAAAxE,IAAA;QAAA;MAAA,GAAAqE,QAAA;IAAA;EAAA,CAChB;EAAA,OAAAH,mBAAA,CAAA/D,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","_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,CAAAE,wBAA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d.ts","sourceRoot":"","sources":["../../src/chat/crypto.ts"],"names":[],"mappings":""}
@@ -0,0 +1,257 @@
1
+ /* import { literal, quad, Statement } from 'rdflib';
2
+ // import { PODCHAT, removeHashFromUrl } from './Constants';
3
+ import { authn } from 'solid-logic'
4
+ import * as UI from 'solid-ui'
5
+ import * as $rdf from 'rdflib'
6
+
7
+ const ns = UI.ns
8
+
9
+ const removeHashFromUrl = (url: string) => {
10
+ const newUrl = new URL(url)
11
+ newUrl.hash = ''
12
+ return newUrl.href
13
+ }
14
+ const PODCHAT_NS = 'https://www.pod-chat.com/';
15
+ const PODCHAT = {
16
+ LongChatMessage: PODCHAT_NS + 'LongChatMessage',
17
+ LongChatMessageReply: PODCHAT_NS + 'LongChatMessageReply',
18
+ RSAPublicKey: PODCHAT_NS + 'RSAPublicKey',
19
+ RSAPrivateKey: PODCHAT_NS + 'RSAPrivateKey',
20
+ signature: PODCHAT_NS + 'signature'
21
+ }
22
+
23
+ // import rdfStore, { extractObjectLastValue } from './RdfStore';
24
+
25
+ export type RdfStore = {
26
+ cache: Store,
27
+ fetcher: Fetcher,
28
+ updateManager: UpdateManager
29
+ }
30
+ function extractObject({ cache }: RdfStore, webid: string, resourceUrl: string, predicate: PredicateType): Array<Node> {
31
+ return cache.each(cache.sym(webid), predicate, undefined, cache.sym(resourceUrl));
32
+ }
33
+ function extractObjectLastValue(rdfStore: RdfStore, webid: string, resourceUrl: string, predicate: PredicateType): string | undefined {
34
+ return extractObject(rdfStore, webid, resourceUrl, predicate).map(q => q.value).pop();
35
+ }
36
+
37
+ export const prepareRsaKeyPair = async (profileId: string, rsaPrivateKeyResourceUrl: string): Promise<void> => {
38
+
39
+ const privKey = await getPrivateKey(rsaPrivateKeyResourceUrl);
40
+ const pubKey = await getPublicKey(profileId);
41
+
42
+ if (!privKey || !pubKey) {
43
+ await createKeyPair(profileId, rsaPrivateKeyResourceUrl);
44
+ const privKeyNew = await getPrivateKey(rsaPrivateKeyResourceUrl);
45
+ const pubKeyNew = await getPublicKey(profileId);
46
+ if (!privKeyNew || !pubKeyNew) {
47
+ throw new Error('Unable to create RSA keypair.');
48
+ }
49
+ }
50
+ }
51
+
52
+ export const signMessage = async (rsaPrivateKeyResourceUrl: string, messageContent: string): Promise<string | undefined> => {
53
+ const privateKey = await getPrivateKey(rsaPrivateKeyResourceUrl);
54
+ if (privateKey) {
55
+ const messageContentEnc = new TextEncoder().encode(messageContent);
56
+ const signature = await window.crypto.subtle.sign(
57
+ {
58
+ name: "RSA-PSS",
59
+ saltLength: 32,
60
+ },
61
+ privateKey,
62
+ messageContentEnc
63
+ );
64
+ const exportedAsString = ab2str(signature);
65
+ const exportedAsBase64 = window.btoa(exportedAsString);
66
+ return exportedAsBase64;
67
+ }
68
+
69
+ return undefined;
70
+ }
71
+
72
+ export const verifyMessage = async (profileId: string, messageId: string, messageContent: string, signatureEncoded: string): Promise<{ messageId: string, trusted: boolean }> => {
73
+ let encoded = new TextEncoder().encode(messageContent);
74
+ const publicKey = await getPublicKey(profileId);
75
+ // base64 decode the string to get the binary data
76
+ const binaryDerString = window.atob(signatureEncoded);
77
+ // convert from a binary string to an ArrayBuffer
78
+ const signature = str2ab(binaryDerString);
79
+
80
+ if (publicKey) {
81
+ const trusted = await window.crypto.subtle.verify(
82
+ {
83
+ name: "RSA-PSS",
84
+ saltLength: 32,
85
+ },
86
+ publicKey,
87
+ signature,
88
+ encoded
89
+ );
90
+ return { messageId, trusted };
91
+ }
92
+
93
+ return { messageId, trusted: false };
94
+ }
95
+
96
+ const getPublicKey = async (profileId: string): Promise<CryptoKey | undefined> => {
97
+ const profileResourceUrl = removeHashFromUrl(profileId);
98
+ await rdfStore.fetcher.load(profileResourceUrl);
99
+ const pubKeyEncoded = extractObjectLastValue(rdfStore, PODCHAT.RSAPublicKey, profileResourceUrl, rdfStore.cache.sym(SIOC.content_encoded));
100
+ if (pubKeyEncoded) {
101
+ return importPublicKey(pubKeyEncoded);
102
+ }
103
+
104
+ return undefined;
105
+ }
106
+
107
+ const getPrivateKey = async (rsaPrivateKeyResourceUrl: string): Promise<CryptoKey | undefined> => {
108
+ await rdfStore.fetcher.load(rsaPrivateKeyResourceUrl);
109
+ const privKeyEncoded = extractObjectLastValue(rdfStore, PODCHAT.RSAPrivateKey, rsaPrivateKeyResourceUrl, rdfStore.cache.sym(SIOC.content_encoded));
110
+ if (privKeyEncoded) {
111
+ return importPrivateKey(privKeyEncoded);
112
+ }
113
+ return undefined;
114
+ }
115
+
116
+ /*
117
+ Import a PEM encoded RSA private key, to use for RSA-PSS signing.
118
+ Takes a string containing the PEM encoded key, and returns a Promise
119
+ that will resolve to a CryptoKey representing the private key.
120
+ */
121
+ /* function importPrivateKey(pem: string) {
122
+ // base64 decode the string to get the binary data
123
+ const binaryDerString = window.atob(pem);
124
+ // convert from a binary string to an ArrayBuffer
125
+ const binaryDer = str2ab(binaryDerString);
126
+
127
+ return window.crypto.subtle.importKey(
128
+ "pkcs8",
129
+ binaryDer,
130
+ {
131
+ name: "RSA-PSS",
132
+ // Consider using a 4096-bit key for systems that require long-term security
133
+ //modulusLength: 4096,
134
+ //publicExponent: new Uint8Array([1, 0, 1]),
135
+ hash: "SHA-256",
136
+ },
137
+ true,
138
+ ["sign"]
139
+ );
140
+ }
141
+
142
+ /*
143
+ Import a PEM encoded RSA public key, to use for RSA-OAEP encryption.
144
+ Takes a string containing the PEM encoded key, and returns a Promise
145
+ that will resolve to a CryptoKey representing the public key.
146
+ */
147
+ /* function importPublicKey(pem: string) {
148
+ // base64 decode the string to get the binary data
149
+ const binaryDerString = window.atob(pem);
150
+ // convert from a binary string to an ArrayBuffer
151
+ const binaryDer = str2ab(binaryDerString);
152
+
153
+ return window.crypto.subtle.importKey(
154
+ "spki",
155
+ binaryDer,
156
+ {
157
+ name: "RSA-PSS",
158
+ hash: "SHA-256"
159
+ },
160
+ true,
161
+ ["verify"]
162
+ );
163
+ }
164
+
165
+ /* const createKeyPair = async (profileId: string, rsaPrivateKeyResourceUrl: string) => {
166
+ const key = await window.crypto.subtle
167
+ .generateKey(
168
+ {
169
+ name: "RSA-PSS",
170
+ // Consider using a 4096-bit key for systems that require long-term security
171
+ modulusLength: 4096,
172
+ publicExponent: new Uint8Array([1, 0, 1]),
173
+ hash: "SHA-256",
174
+ },
175
+ true,
176
+ ["sign", "verify"]
177
+ );
178
+
179
+ await privKeyPkcs8Pem(key.privateKey, profileId, rsaPrivateKeyResourceUrl);
180
+ await pubKeySpkiPem(key.publicKey, profileId);
181
+ } */
182
+
183
+ /* async function privKeyPkcs8Pem(privKey: CryptoKey, profileId: string, rsaPrivateKeyResourceUrl: string) {
184
+ const exported = await window.crypto.subtle.exportKey("pkcs8", privKey);
185
+ const exportedAsString = ab2str(exported);
186
+ const exportedAsBase64 = window.btoa(exportedAsString);
187
+ const del: Statement[] = [];
188
+ const ins: Statement[] = [];
189
+ del.push(...rdfStore.cache.statementsMatching(
190
+ rdfStore.cache.sym(PODCHAT.RSAPrivateKey),
191
+ rdfStore.cache.sym(SIOC.content_encoded),
192
+ undefined,
193
+ rdfStore.cache.sym(rsaPrivateKeyResourceUrl)
194
+ ));
195
+ ins.push(quad(
196
+ rdfStore.cache.sym(PODCHAT.RSAPrivateKey),
197
+ rdfStore.cache.sym(SIOC.content_encoded),
198
+ literal(exportedAsBase64), // alain
199
+ rdfStore.cache.sym(rsaPrivateKeyResourceUrl)
200
+ ));
201
+ await rdfStore.updateManager.update(del, ins);
202
+ await aclForResource(rsaPrivateKeyResourceUrl, profileId);
203
+ }
204
+
205
+ async function aclForResource(resourceUrl: string, ownerId: string) {
206
+ const ins: Statement[] = [];
207
+ const aclResourceUrl = resourceUrl + '.acl';
208
+ const graph = rdfStore.cache.sym(aclResourceUrl);
209
+ const aclId = rdfStore.cache.sym(aclResourceUrl + '#ControlReadWrite');
210
+ ins.push(quad(aclId, rdfStore.cache.sym(RDF.type), rdfStore.cache.sym(ACL.Authorization), graph));
211
+ ins.push(quad(aclId, rdfStore.cache.sym(ACL.accessTo), rdfStore.cache.sym(resourceUrl), graph));
212
+ [ACL.Control, ACL.Write, ACL.Read].forEach(mode => {
213
+ ins.push(quad(aclId, rdfStore.cache.sym(ACL.mode), rdfStore.cache.sym(mode), graph));
214
+ });
215
+ ins.push(quad(aclId, rdfStore.cache.sym(ACL.agent), rdfStore.cache.sym(ownerId), graph));
216
+ await rdfStore.updateManager.update([], ins);
217
+ }
218
+
219
+ async function pubKeySpkiPem(pubKey: CryptoKey, profileId: string) {
220
+ const exported = await window.crypto.subtle.exportKey("spki", pubKey);
221
+ const exportedAsString = ab2str(exported);
222
+ const exportedAsBase64 = window.btoa(exportedAsString);
223
+ const profileResourceUrl = removeHashFromUrl(profileId);
224
+ const del: Statement[] = [];
225
+ const ins: Statement[] = [];
226
+ del.push(...rdfStore.cache.statementsMatching(
227
+ rdfStore.cache.sym(PODCHAT.RSAPublicKey),
228
+ rdfStore.cache.sym(SIOC.content_encoded),
229
+ undefined,
230
+ rdfStore.cache.sym(profileResourceUrl)
231
+ ));
232
+ ins.push(quad(
233
+ rdfStore.cache.sym(PODCHAT.RSAPublicKey),
234
+ rdfStore.cache.sym(SIOC.content_encoded),
235
+ literal(exportedAsBase64), // alain
236
+ rdfStore.cache.sym(profileResourceUrl)
237
+ ));
238
+ await rdfStore.updateManager.update(del, ins);
239
+ }
240
+
241
+ /*
242
+ Convert an ArrayBuffer into a string
243
+ */
244
+ /* function ab2str(buf: ArrayBuffer) {
245
+ return String.fromCharCode.apply(null, new Uint8Array(buf) as unknown as number[]);
246
+ }
247
+
248
+ function str2ab(str: string) {
249
+ const buf = new ArrayBuffer(str.length);
250
+ const bufView = new Uint8Array(buf);
251
+ for (let i = 0, strLen = str.length; i < strLen; i++) {
252
+ bufView[i] = str.charCodeAt(i);
253
+ }
254
+ return buf;
255
+ } */
256
+ "use strict";
257
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","names":[],"sources":["../../src/chat/crypto.ts"],"sourcesContent":["/* import { literal, quad, Statement } from 'rdflib';\r\n// import { PODCHAT, removeHashFromUrl } from './Constants';\r\nimport { authn } from 'solid-logic'\r\nimport * as UI from 'solid-ui'\r\nimport * as $rdf from 'rdflib'\r\n\r\nconst ns = UI.ns\r\n\r\nconst removeHashFromUrl = (url: string) => {\r\n const newUrl = new URL(url)\r\n newUrl.hash = ''\r\n return newUrl.href\r\n}\r\nconst PODCHAT_NS = 'https://www.pod-chat.com/';\r\nconst PODCHAT = {\r\n LongChatMessage: PODCHAT_NS + 'LongChatMessage',\r\n LongChatMessageReply: PODCHAT_NS + 'LongChatMessageReply',\r\n RSAPublicKey: PODCHAT_NS + 'RSAPublicKey',\r\n RSAPrivateKey: PODCHAT_NS + 'RSAPrivateKey',\r\n signature: PODCHAT_NS + 'signature'\r\n}\r\n\r\n// import rdfStore, { extractObjectLastValue } from './RdfStore';\r\n\r\nexport type RdfStore = {\r\n cache: Store,\r\n fetcher: Fetcher,\r\n updateManager: UpdateManager\r\n}\r\nfunction extractObject({ cache }: RdfStore, webid: string, resourceUrl: string, predicate: PredicateType): Array<Node> {\r\n return cache.each(cache.sym(webid), predicate, undefined, cache.sym(resourceUrl));\r\n}\r\nfunction extractObjectLastValue(rdfStore: RdfStore, webid: string, resourceUrl: string, predicate: PredicateType): string | undefined {\r\n return extractObject(rdfStore, webid, resourceUrl, predicate).map(q => q.value).pop();\r\n}\r\n\r\nexport const prepareRsaKeyPair = async (profileId: string, rsaPrivateKeyResourceUrl: string): Promise<void> => {\r\n\r\n const privKey = await getPrivateKey(rsaPrivateKeyResourceUrl);\r\n const pubKey = await getPublicKey(profileId);\r\n\r\n if (!privKey || !pubKey) {\r\n await createKeyPair(profileId, rsaPrivateKeyResourceUrl);\r\n const privKeyNew = await getPrivateKey(rsaPrivateKeyResourceUrl);\r\n const pubKeyNew = await getPublicKey(profileId);\r\n if (!privKeyNew || !pubKeyNew) {\r\n throw new Error('Unable to create RSA keypair.');\r\n }\r\n }\r\n}\r\n\r\nexport const signMessage = async (rsaPrivateKeyResourceUrl: string, messageContent: string): Promise<string | undefined> => {\r\n const privateKey = await getPrivateKey(rsaPrivateKeyResourceUrl);\r\n if (privateKey) {\r\n const messageContentEnc = new TextEncoder().encode(messageContent);\r\n const signature = await window.crypto.subtle.sign(\r\n {\r\n name: \"RSA-PSS\",\r\n saltLength: 32,\r\n },\r\n privateKey,\r\n messageContentEnc\r\n );\r\n const exportedAsString = ab2str(signature);\r\n const exportedAsBase64 = window.btoa(exportedAsString);\r\n return exportedAsBase64;\r\n }\r\n\r\n return undefined;\r\n}\r\n\r\nexport const verifyMessage = async (profileId: string, messageId: string, messageContent: string, signatureEncoded: string): Promise<{ messageId: string, trusted: boolean }> => {\r\n let encoded = new TextEncoder().encode(messageContent);\r\n const publicKey = await getPublicKey(profileId);\r\n // base64 decode the string to get the binary data\r\n const binaryDerString = window.atob(signatureEncoded);\r\n // convert from a binary string to an ArrayBuffer\r\n const signature = str2ab(binaryDerString);\r\n\r\n if (publicKey) {\r\n const trusted = await window.crypto.subtle.verify(\r\n {\r\n name: \"RSA-PSS\",\r\n saltLength: 32,\r\n },\r\n publicKey,\r\n signature,\r\n encoded\r\n );\r\n return { messageId, trusted };\r\n }\r\n\r\n return { messageId, trusted: false };\r\n}\r\n\r\nconst getPublicKey = async (profileId: string): Promise<CryptoKey | undefined> => {\r\n const profileResourceUrl = removeHashFromUrl(profileId);\r\n await rdfStore.fetcher.load(profileResourceUrl);\r\n const pubKeyEncoded = extractObjectLastValue(rdfStore, PODCHAT.RSAPublicKey, profileResourceUrl, rdfStore.cache.sym(SIOC.content_encoded));\r\n if (pubKeyEncoded) {\r\n return importPublicKey(pubKeyEncoded);\r\n }\r\n\r\n return undefined;\r\n}\r\n\r\nconst getPrivateKey = async (rsaPrivateKeyResourceUrl: string): Promise<CryptoKey | undefined> => {\r\n await rdfStore.fetcher.load(rsaPrivateKeyResourceUrl);\r\n const privKeyEncoded = extractObjectLastValue(rdfStore, PODCHAT.RSAPrivateKey, rsaPrivateKeyResourceUrl, rdfStore.cache.sym(SIOC.content_encoded));\r\n if (privKeyEncoded) {\r\n return importPrivateKey(privKeyEncoded);\r\n }\r\n return undefined;\r\n}\r\n\r\n/*\r\n Import a PEM encoded RSA private key, to use for RSA-PSS signing.\r\n Takes a string containing the PEM encoded key, and returns a Promise\r\n that will resolve to a CryptoKey representing the private key.\r\n */\r\n/* function importPrivateKey(pem: string) {\r\n // base64 decode the string to get the binary data\r\n const binaryDerString = window.atob(pem);\r\n // convert from a binary string to an ArrayBuffer\r\n const binaryDer = str2ab(binaryDerString);\r\n\r\n return window.crypto.subtle.importKey(\r\n \"pkcs8\",\r\n binaryDer,\r\n {\r\n name: \"RSA-PSS\",\r\n // Consider using a 4096-bit key for systems that require long-term security\r\n //modulusLength: 4096,\r\n //publicExponent: new Uint8Array([1, 0, 1]),\r\n hash: \"SHA-256\",\r\n },\r\n true,\r\n [\"sign\"]\r\n );\r\n}\r\n\r\n/*\r\n Import a PEM encoded RSA public key, to use for RSA-OAEP encryption.\r\n Takes a string containing the PEM encoded key, and returns a Promise\r\n that will resolve to a CryptoKey representing the public key.\r\n */\r\n/* function importPublicKey(pem: string) {\r\n // base64 decode the string to get the binary data\r\n const binaryDerString = window.atob(pem);\r\n // convert from a binary string to an ArrayBuffer\r\n const binaryDer = str2ab(binaryDerString);\r\n\r\n return window.crypto.subtle.importKey(\r\n \"spki\",\r\n binaryDer,\r\n {\r\n name: \"RSA-PSS\",\r\n hash: \"SHA-256\"\r\n },\r\n true,\r\n [\"verify\"]\r\n );\r\n}\r\n\r\n/* const createKeyPair = async (profileId: string, rsaPrivateKeyResourceUrl: string) => {\r\n const key = await window.crypto.subtle\r\n .generateKey(\r\n {\r\n name: \"RSA-PSS\",\r\n // Consider using a 4096-bit key for systems that require long-term security\r\n modulusLength: 4096,\r\n publicExponent: new Uint8Array([1, 0, 1]),\r\n hash: \"SHA-256\",\r\n },\r\n true,\r\n [\"sign\", \"verify\"]\r\n );\r\n\r\n await privKeyPkcs8Pem(key.privateKey, profileId, rsaPrivateKeyResourceUrl);\r\n await pubKeySpkiPem(key.publicKey, profileId);\r\n} */\r\n\r\n/* async function privKeyPkcs8Pem(privKey: CryptoKey, profileId: string, rsaPrivateKeyResourceUrl: string) {\r\n const exported = await window.crypto.subtle.exportKey(\"pkcs8\", privKey);\r\n const exportedAsString = ab2str(exported);\r\n const exportedAsBase64 = window.btoa(exportedAsString);\r\n const del: Statement[] = [];\r\n const ins: Statement[] = [];\r\n del.push(...rdfStore.cache.statementsMatching(\r\n rdfStore.cache.sym(PODCHAT.RSAPrivateKey),\r\n rdfStore.cache.sym(SIOC.content_encoded),\r\n undefined,\r\n rdfStore.cache.sym(rsaPrivateKeyResourceUrl)\r\n ));\r\n ins.push(quad(\r\n rdfStore.cache.sym(PODCHAT.RSAPrivateKey),\r\n rdfStore.cache.sym(SIOC.content_encoded),\r\n literal(exportedAsBase64), // alain\r\n rdfStore.cache.sym(rsaPrivateKeyResourceUrl)\r\n ));\r\n await rdfStore.updateManager.update(del, ins);\r\n await aclForResource(rsaPrivateKeyResourceUrl, profileId);\r\n}\r\n\r\nasync function aclForResource(resourceUrl: string, ownerId: string) {\r\n const ins: Statement[] = [];\r\n const aclResourceUrl = resourceUrl + '.acl';\r\n const graph = rdfStore.cache.sym(aclResourceUrl);\r\n const aclId = rdfStore.cache.sym(aclResourceUrl + '#ControlReadWrite');\r\n ins.push(quad(aclId, rdfStore.cache.sym(RDF.type), rdfStore.cache.sym(ACL.Authorization), graph));\r\n ins.push(quad(aclId, rdfStore.cache.sym(ACL.accessTo), rdfStore.cache.sym(resourceUrl), graph));\r\n [ACL.Control, ACL.Write, ACL.Read].forEach(mode => {\r\n ins.push(quad(aclId, rdfStore.cache.sym(ACL.mode), rdfStore.cache.sym(mode), graph));\r\n });\r\n ins.push(quad(aclId, rdfStore.cache.sym(ACL.agent), rdfStore.cache.sym(ownerId), graph));\r\n await rdfStore.updateManager.update([], ins);\r\n}\r\n\r\nasync function pubKeySpkiPem(pubKey: CryptoKey, profileId: string) {\r\n const exported = await window.crypto.subtle.exportKey(\"spki\", pubKey);\r\n const exportedAsString = ab2str(exported);\r\n const exportedAsBase64 = window.btoa(exportedAsString);\r\n const profileResourceUrl = removeHashFromUrl(profileId);\r\n const del: Statement[] = [];\r\n const ins: Statement[] = [];\r\n del.push(...rdfStore.cache.statementsMatching(\r\n rdfStore.cache.sym(PODCHAT.RSAPublicKey),\r\n rdfStore.cache.sym(SIOC.content_encoded),\r\n undefined,\r\n rdfStore.cache.sym(profileResourceUrl)\r\n ));\r\n ins.push(quad(\r\n rdfStore.cache.sym(PODCHAT.RSAPublicKey),\r\n rdfStore.cache.sym(SIOC.content_encoded),\r\n literal(exportedAsBase64), // alain\r\n rdfStore.cache.sym(profileResourceUrl)\r\n ));\r\n await rdfStore.updateManager.update(del, ins);\r\n}\r\n\r\n/*\r\n Convert an ArrayBuffer into a string\r\n */\r\n/* function ab2str(buf: ArrayBuffer) {\r\n return String.fromCharCode.apply(null, new Uint8Array(buf) as unknown as number[]);\r\n}\r\n\r\nfunction str2ab(str: string) {\r\n const buf = new ArrayBuffer(str.length);\r\n const bufView = new Uint8Array(buf);\r\n for (let i = 0, strLen = str.length; i < strLen; i++) {\r\n bufView[i] = str.charCodeAt(i);\r\n }\r\n return buf;\r\n} */\r\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAXA"}
@@ -0,0 +1,5 @@
1
+ export declare function generatePrivateKey(): string;
2
+ export declare function generatePublicKey(privateKey: string): string;
3
+ export declare function getPublicKey(webId: any): any;
4
+ export declare function getPrivateKey(webId: string): Promise<string>;
5
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.generatePrivateKey = generatePrivateKey;
9
+ exports.generatePublicKey = generatePublicKey;
10
+ exports.getPrivateKey = getPrivateKey;
11
+ exports.getPublicKey = getPublicKey;
12
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
+ var debug = _interopRequireWildcard(require("../debug"));
15
+ var _secp256k = require("@noble/curves/secp256k1");
16
+ var _utils = require("@noble/hashes/utils");
17
+ var _signature = require("./signature");
18
+ var _solidLogic = require("solid-logic");
19
+ var $rdf = _interopRequireWildcard(require("rdflib"));
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
+ function generatePrivateKey() {
23
+ return (0, _utils.bytesToHex)(_secp256k.schnorr.utils.randomPrivateKey());
24
+ }
25
+ function generatePublicKey(privateKey) {
26
+ return (0, _utils.bytesToHex)(_secp256k.schnorr.getPublicKey(privateKey));
27
+ }
28
+ function getPublicKey(webId) {
29
+ var publicKey = publicKeyExists(webId);
30
+ return publicKey === null || publicKey === void 0 ? void 0 : publicKey.uri;
31
+ }
32
+ function publicKeyExists(webId) {
33
+ // find publickey
34
+ 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;
39
+ }
40
+ function privateKeyExists(_x) {
41
+ return _privateKeyExists.apply(this, arguments);
42
+ }
43
+ 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) {
48
+ 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);
55
+ 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;
60
+ break;
61
+ }
62
+ _context.prev = 11;
63
+ // create privateKey resource
64
+ data = '';
65
+ contentType = 'text/ttl';
66
+ _context.next = 16;
67
+ return _solidLogic.store.fetcher.webOperation('PUT', privateKeyUrl, {
68
+ data: data,
69
+ contentType: contentType
70
+ });
71
+ case 16:
72
+ response = _context.sent;
73
+ _context.next = 23;
74
+ break;
75
+ 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;
80
+ case 23:
81
+ delete _solidLogic.store.fetcher.requested[privateKeyUrl]; // delete cached 404 error
82
+ return _context.abrupt("return", undefined);
83
+ case 25:
84
+ debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context.t0);
85
+ throw _context.t0;
86
+ case 27:
87
+ case "end":
88
+ return _context.stop();
89
+ }
90
+ }, _callee, null, [[2, 8], [11, 19]]);
91
+ }));
92
+ return _privateKeyExists.apply(this, arguments);
93
+ }
94
+ function getPrivateKey(_x2) {
95
+ return _getPrivateKey.apply(this, arguments);
96
+ }
97
+ 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) {
102
+ 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;
107
+ return privateKeyExists(webId);
108
+ case 5:
109
+ privateKey = _context2.sent;
110
+ if (!(!privateKey || !publicKey)) {
111
+ _context2.next = 17;
112
+ break;
113
+ }
114
+ del = [];
115
+ 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;
123
+ return _solidLogic.store.updater.updateMany(del, add);
124
+ case 17:
125
+ return _context2.abrupt("return", privateKey.uri);
126
+ case 18:
127
+ case "end":
128
+ return _context2.stop();
129
+ }
130
+ }, _callee2);
131
+ }));
132
+ return _getPrivateKey.apply(this, arguments);
133
+ }
134
+ //# sourceMappingURL=keys.js.map