solid-ui 2.4.27-1b50dba8 → 2.4.27-20175fe3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/solid-ui.js +1200 -1039
- package/dist/solid-ui.js.map +1 -1
- package/dist/solid-ui.min.js +1 -1
- package/dist/solid-ui.min.js.map +1 -1
- package/lib/chat/chatLogic.js +63 -37
- package/lib/chat/chatLogic.js.map +1 -1
- package/lib/chat/keys.d.ts +2 -2
- package/lib/chat/keys.d.ts.map +1 -1
- package/lib/chat/keys.js +107 -35
- package/lib/chat/keys.js.map +1 -1
- package/lib/chat/message.js +23 -12
- package/lib/chat/message.js.map +1 -1
- package/lib/chat/signature.d.ts.map +1 -1
- package/lib/chat/signature.js +2 -2
- package/lib/chat/signature.js.map +1 -1
- package/lib/versionInfo.js +2 -2
- package/lib/versionInfo.js.map +1 -1
- package/package.json +1 -1
- package/lib/chat/crypto.d.ts +0 -1
- package/lib/chat/crypto.d.ts.map +0 -1
- package/lib/chat/crypto.js +0 -257
- package/lib/chat/crypto.js.map +0 -1
package/lib/chat/chatLogic.js
CHANGED
|
@@ -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,
|
|
88
|
+
var sts, now, timestamp, dateStamp, chatDocument, message, me, msg, oldMsgMaker, errMsg, privateKey, pubKey, sig, _errMsg;
|
|
89
89
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
90
90
|
while (1) switch (_context2.prev = _context2.next) {
|
|
91
91
|
case 0:
|
|
@@ -96,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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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 =
|
|
136
|
+
_context2.next = 36;
|
|
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,
|
|
124
|
-
_context2.next =
|
|
125
|
-
return (0, _keys.getPrivateKey)(me);
|
|
126
|
-
case
|
|
140
|
+
msg.maker = me.uri;
|
|
141
|
+
// privateKey the cached private key of me, cached in store
|
|
142
|
+
_context2.next = 32;
|
|
143
|
+
return (0, _keys.getPrivateKey)(me.uri);
|
|
144
|
+
case 32:
|
|
127
145
|
privateKey = _context2.sent;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
146
|
+
// const privateKey0 = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'
|
|
147
|
+
// const pubKey0 = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'
|
|
148
|
+
pubKey = (0, _keys.getPublicKey)(me.uri);
|
|
149
|
+
sig = (0, _signature.signMsg)(msg, privateKey);
|
|
150
|
+
/* const verify = verifySignature(sig, msg, pubKey) // alain to remove
|
|
151
|
+
debug.warn('sig ' + sig)
|
|
152
|
+
debug.warn('verifySign ' + verify)
|
|
153
|
+
debug.warn(msg) */
|
|
154
|
+
sts.push($rdf.st(message, $rdf.sym("".concat(_signature.SEC, "Proof")), $rdf.lit(sig), chatDocument));
|
|
155
|
+
case 36:
|
|
156
|
+
_context2.prev = 36;
|
|
157
|
+
_context2.next = 39;
|
|
132
158
|
return _solidLogic.store.updater.update([], sts);
|
|
133
|
-
case
|
|
134
|
-
_context2.next =
|
|
159
|
+
case 39:
|
|
160
|
+
_context2.next = 47;
|
|
135
161
|
break;
|
|
136
|
-
case
|
|
137
|
-
_context2.prev =
|
|
138
|
-
_context2.t0 = _context2["catch"](
|
|
139
|
-
|
|
140
|
-
debug.warn(
|
|
141
|
-
alert(
|
|
142
|
-
throw new Error(
|
|
143
|
-
case
|
|
162
|
+
case 41:
|
|
163
|
+
_context2.prev = 41;
|
|
164
|
+
_context2.t0 = _context2["catch"](36);
|
|
165
|
+
_errMsg = 'Error saving chat message: ' + _context2.t0;
|
|
166
|
+
debug.warn(_errMsg);
|
|
167
|
+
alert(_errMsg);
|
|
168
|
+
throw new Error(_errMsg);
|
|
169
|
+
case 47:
|
|
144
170
|
return _context2.abrupt("return", message);
|
|
145
|
-
case
|
|
171
|
+
case 48:
|
|
146
172
|
case "end":
|
|
147
173
|
return _context2.stop();
|
|
148
174
|
}
|
|
149
|
-
}, _callee2, null, [[
|
|
175
|
+
}, _callee2, null, [[36, 41]]);
|
|
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,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAV,wBAAAc,GAAA,EAAAJ,WAAA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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","pubKey","sig","_errMsg","_callee2$","_context2","Date","getTime","term","leafDocumentFromDate","store","sym","uri","authn","currentUser","getBlankMsg","id","any","foaf","push","st","mostRecentVersion","dct","schema","warn","alert","Error","wf","sioc","literal","content","created","maker","getPrivateKey","sent","getPublicKey","signMsg","concat","SEC","lit","updater","update","t0","_x2","_deleteMessage","_callee3","_callee3$","_context3","deleteMessage","_x3","exports","originalVersion","isDeleted","holds","isReplaced","isHidden","nick","person","s","label","_createIfNotExists","_x4","_createIfNotExists2","contentType","data","_callee4","response","_callee4$","_context4","fetcher","load","status","log","webOperation","t1","requested"],"sources":["../../src/chat/chatLogic.js"],"sourcesContent":["/**\n * Contains the [[ChatChannel]] class and logic for Solid Chat\n * @packageDocumentation\n */\n\nimport * as debug from '../debug'\nimport { DateFolder } from './dateFolder'\nimport { store, authn } from 'solid-logic'\nimport * as ns from '../ns'\nimport * as $rdf from 'rdflib' // pull in first avoid cross-refs\nimport * as utils from '../utils'\nimport { getBlankMsg, signMsg, SEC, verifySignature } from './signature'\nimport { getPrivateKey, getPublicKey } from './keys'\n\n/* The Solid logic for a 'LongChat'\n*/\n/**\n * Common code for a chat (discussion area of messages about something)\n * This version runs over a series of files for different time periods\n *\n * Parameters for the whole chat like its title are stored on\n * index.ttl#this and the chats messages are stored in YYYY/MM/DD/chat.ttl\n *\n */\n\nexport class ChatChannel {\n constructor (channel, options) {\n this.channel = channel\n this.channelRoot = channel.doc()\n this.options = options\n this.dateFolder = new DateFolder(this.channelRoot, 'chat.ttl')\n this.div = null // : HTMLElement\n }\n\n /* Store a new message in the web,\n */\n async createMessage (text) {\n return this.updateMessage(text)\n }\n\n /* Store a new message in the web,\n as a replacement for an existing one.\n The old one iis left, and the two are linked\n */\n async updateMessage (text, oldMsg = null, deleteIt) {\n const sts = []\n const now = new Date()\n const timestamp = '' + now.getTime()\n const dateStamp = $rdf.term(now)\n const chatDocument = oldMsg ? oldMsg.doc() : this.dateFolder.leafDocumentFromDate(now)\n const message = store.sym(chatDocument.uri + '#' + 'Msg' + timestamp)\n // const content = store.literal(text)\n\n const me = authn.currentUser() // If already logged on\n\n const msg = getBlankMsg()\n msg.id = message.uri\n if (oldMsg) { // edit message replaces old one\n const oldMsgMaker = store.any(oldMsg, ns.foaf('maker')) // may not be needed here, but needed on READ\n if (oldMsgMaker.uri === me.uri) {\n sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument))\n if (deleteIt) { // we need to add a specific signature, else anyone can delete a msg ?\n sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument))\n // msg.dateDeleted = dateStamp\n }\n } else {\n const errMsg = 'Error you cannot delete/edit a message from someone else : \\n' + oldMsgMaker.uri\n debug.warn(errMsg)\n alert(errMsg)\n throw new Error(errMsg)\n }\n } else { // link new message to channel\n sts.push($rdf.st(this.channel, ns.wf('message'), message, chatDocument))\n }\n sts.push(\n $rdf.st(message, ns.sioc('content'), store.literal(text), chatDocument)\n )\n msg.content = text\n\n sts.push(\n $rdf.st(message, ns.dct('created'), dateStamp, chatDocument)\n )\n msg.created = dateStamp.value\n if (me) {\n sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument))\n msg.maker = me.uri\n // privateKey the cached private key of me, cached in store\n const privateKey = await getPrivateKey(me.uri)\n // const privateKey0 = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'\n // const pubKey0 = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'\n const pubKey = getPublicKey(me.uri)\n\n const sig = signMsg(msg, privateKey)\n /* const verify = verifySignature(sig, msg, pubKey) // alain to remove\n debug.warn('sig ' + sig)\n debug.warn('verifySign ' + verify)\n debug.warn(msg) */\n sts.push($rdf.st(message, $rdf.sym(`${SEC}Proof`), $rdf.lit(sig), chatDocument))\n }\n try {\n await store.updater.update([], sts)\n } catch (err) {\n const errMsg = 'Error saving chat message: ' + err\n debug.warn(errMsg)\n alert(errMsg)\n throw new Error(errMsg)\n }\n return message\n }\n\n /* Mark a message as deleted\n * Wee add a new version of the message,m witha deletion flag (deletion date)\n * so that the deletion can be revoked by adding another non-deleted update\n */\n async deleteMessage (message) {\n return this.updateMessage('(message deleted)', message, true)\n }\n} // class ChatChannel\n\nexport function originalVersion (message) {\n let msg = message\n while (msg) {\n message = msg\n msg = store.any(null, ns.dct('isReplacedBy'), message, message.doc())\n }\n return message\n}\n\nexport function mostRecentVersion (message) {\n let msg = message\n while (msg) {\n message = msg\n msg = store.any(message, ns.dct('isReplacedBy'), null, message.doc())\n }\n return message\n}\n\nexport function isDeleted (message) {\n return store.holds(message, ns.schema('dateDeleted'), null, message.doc())\n}\n\nexport function isReplaced (message) {\n return store.holds(message, ns.dct('isReplacedBy'), null, message.doc())\n}\n\nexport function isHidden (message) {\n return this.isDeleted(message) || this.isReplaced(message)\n}\n\n// A Nickname for a person\n\nexport function nick (person) {\n const s = store.any(person, ns.foaf('nick'))\n if (s) return '' + s.value\n return '' + utils.label(person)\n}\n\nexport async function _createIfNotExists (doc, contentType = 'text/turtle', data = '') {\n let response\n try {\n response = await store.fetcher.load(doc)\n } catch (err) {\n if (err.response.status === 404) {\n debug.log(\n 'createIfNotExists: doc does NOT exist, will create... ' + doc\n )\n try {\n response = await store.fetcher.webOperation('PUT', doc.uri, {\n data,\n contentType\n })\n } catch (err) {\n debug.log('createIfNotExists doc FAILED: ' + doc + ': ' + err)\n throw err\n }\n delete store.fetcher.requested[doc.uri] // delete cached 404 error\n // debug.log('createIfNotExists doc created ok ' + doc)\n return response\n } else {\n debug.log(\n 'createIfNotExists doc load error NOT 404: ' + doc + ': ' + err\n )\n throw err\n }\n }\n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A7F,IAAA;cAAA;YAAA;YAC7BrD,KAAK,CAACsJ,GAAG,CACP,wDAAwD,GAAGjH,GAAG,CAC/D;YAAA6G,SAAA,CAAA9F,IAAA;YAAA8F,SAAA,CAAA7F,IAAA;YAAA,OAEkBmC,iBAAK,CAAC2D,OAAO,CAACI,YAAY,CAAC,KAAK,EAAElH,GAAG,CAACqD,GAAG,EAAE;cAC1DoD,IAAI,EAAJA,IAAI;cACJD,WAAW,EAAXA;YACF,CAAC,CAAC;UAAA;YAHFG,QAAQ,GAAAE,SAAA,CAAAlC,IAAA;YAAAkC,SAAA,CAAA7F,IAAA;YAAA;UAAA;YAAA6F,SAAA,CAAA9F,IAAA;YAAA8F,SAAA,CAAAM,EAAA,GAAAN,SAAA;YAKRlJ,KAAK,CAACsJ,GAAG,CAAC,gCAAgC,GAAGjH,GAAG,GAAG,IAAI,GAAA6G,SAAA,CAAAM,EAAM,CAAC;YAAA,MAAAN,SAAA,CAAAM,EAAA;UAAA;YAGhE,OAAOhE,iBAAK,CAAC2D,OAAO,CAACM,SAAS,CAACpH,GAAG,CAACqD,GAAG,CAAC,EAAC;YACxC;YAAA,OAAAwD,SAAA,CAAA5F,MAAA,WACO0F,QAAQ;UAAA;YAEfhJ,KAAK,CAACsJ,GAAG,CACP,6CAA6C,GAAGjH,GAAG,GAAG,IAAI,GAAA6G,SAAA,CAAA1B,EAAM,CACjE;YAAA,MAAA0B,SAAA,CAAA1B,EAAA;UAAA;YAAA,OAAA0B,SAAA,CAAA5F,MAAA,WAKE0F,QAAQ;UAAA;UAAA;YAAA,OAAAE,SAAA,CAAA1F,IAAA;QAAA;MAAA,GAAAuF,QAAA;IAAA;EAAA,CAChB;EAAA,OAAAH,mBAAA,CAAAjF,KAAA,OAAAC,SAAA;AAAA"}
|
package/lib/chat/keys.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare function generatePrivateKey(): string;
|
|
2
2
|
export declare function generatePublicKey(privateKey: string): string;
|
|
3
|
-
export declare function getPublicKey(webId: any):
|
|
4
|
-
export declare function getPrivateKey(webId:
|
|
3
|
+
export declare function getPublicKey(webId: any): string | undefined;
|
|
4
|
+
export declare function getPrivateKey(webId: string): Promise<string>;
|
|
5
5
|
//# sourceMappingURL=keys.d.ts.map
|
package/lib/chat/keys.d.ts.map
CHANGED
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/chat/keys.ts"],"names":[],"mappings":"AAQA,wBAAgB,kBAAkB,IAAK,MAAM,CAE5C;AAED,wBAAgB,iBAAiB,CAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAgB,YAAY,CAAE,KAAK,KAAA,sBAGlC;AAsDD,wBAAsB,aAAa,CAAE,KAAK,EAAE,MAAM,mBAoCjD"}
|
package/lib/chat/keys.js
CHANGED
|
@@ -11,6 +11,7 @@ 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");
|
|
@@ -18,8 +19,6 @@ var _solidLogic = require("solid-logic");
|
|
|
18
19
|
var $rdf = _interopRequireWildcard(require("rdflib"));
|
|
19
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); }
|
|
20
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; }
|
|
21
|
-
// should have webcrypto.getRandomValues defined
|
|
22
|
-
|
|
23
22
|
function generatePrivateKey() {
|
|
24
23
|
return (0, _utils.bytesToHex)(_secp256k.schnorr.utils.randomPrivateKey());
|
|
25
24
|
}
|
|
@@ -27,63 +26,136 @@ function generatePublicKey(privateKey) {
|
|
|
27
26
|
return (0, _utils.bytesToHex)(_secp256k.schnorr.getPublicKey(privateKey));
|
|
28
27
|
}
|
|
29
28
|
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
29
|
var publicKey = publicKeyExists(webId);
|
|
36
|
-
return publicKey
|
|
30
|
+
return publicKey;
|
|
37
31
|
}
|
|
38
32
|
function publicKeyExists(webId) {
|
|
39
33
|
// find publickey
|
|
40
34
|
var url = new URL(webId);
|
|
41
35
|
url.hash = '';
|
|
36
|
+
/* debug.warn('Alain publicKeyExists')
|
|
37
|
+
debug.warn(webId)
|
|
38
|
+
debug.warn(url.href) */
|
|
42
39
|
_solidLogic.store.fetcher.load(url.href);
|
|
43
|
-
var publicKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + '
|
|
44
|
-
return publicKey;
|
|
40
|
+
var publicKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'PublicKey'));
|
|
41
|
+
return publicKey === null || publicKey === void 0 ? void 0 : publicKey.value; // as NamedNode
|
|
45
42
|
}
|
|
46
|
-
|
|
43
|
+
|
|
44
|
+
var privKeyUrl = function privKeyUrl(webId) {
|
|
47
45
|
var url = new URL(webId);
|
|
48
|
-
var privateKeyUrl = url.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
var privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl';
|
|
47
|
+
return privateKeyUrl;
|
|
48
|
+
};
|
|
49
|
+
function privateKeyExists(_x) {
|
|
50
|
+
return _privateKeyExists.apply(this, arguments);
|
|
51
|
+
}
|
|
52
|
+
function _privateKeyExists() {
|
|
53
|
+
_privateKeyExists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
|
|
54
|
+
var privateKeyUrl, privateKey, _err$response, data, contentType, response;
|
|
55
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
56
|
+
while (1) switch (_context.prev = _context.next) {
|
|
57
|
+
case 0:
|
|
58
|
+
/* const url = new URL(webId)
|
|
59
|
+
const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl' */
|
|
60
|
+
privateKeyUrl = privKeyUrl(webId);
|
|
61
|
+
/* debug.warn('Alain privateKeyExists')
|
|
62
|
+
debug.warn(webId)
|
|
63
|
+
debug.warn(privateKeyUrl) */
|
|
64
|
+
_context.prev = 1;
|
|
65
|
+
_solidLogic.store.fetcher.load(privateKeyUrl);
|
|
66
|
+
privateKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'PrivateKey'));
|
|
67
|
+
return _context.abrupt("return", privateKey === null || privateKey === void 0 ? void 0 : privateKey.value);
|
|
68
|
+
case 7:
|
|
69
|
+
_context.prev = 7;
|
|
70
|
+
_context.t0 = _context["catch"](1);
|
|
71
|
+
if (!((_context.t0 === null || _context.t0 === void 0 ? void 0 : (_err$response = _context.t0.response) === null || _err$response === void 0 ? void 0 : _err$response.status) === 404)) {
|
|
72
|
+
_context.next = 24;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
_context.prev = 10;
|
|
76
|
+
// create privateKey resource
|
|
77
|
+
data = '';
|
|
78
|
+
contentType = 'text/ttl';
|
|
79
|
+
_context.next = 15;
|
|
80
|
+
return _solidLogic.store.fetcher.webOperation('PUT', privateKeyUrl, {
|
|
81
|
+
data: data,
|
|
82
|
+
contentType: contentType
|
|
83
|
+
});
|
|
84
|
+
case 15:
|
|
85
|
+
response = _context.sent;
|
|
86
|
+
_context.next = 22;
|
|
87
|
+
break;
|
|
88
|
+
case 18:
|
|
89
|
+
_context.prev = 18;
|
|
90
|
+
_context.t1 = _context["catch"](10);
|
|
91
|
+
debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context.t1);
|
|
92
|
+
throw _context.t1;
|
|
93
|
+
case 22:
|
|
94
|
+
delete _solidLogic.store.fetcher.requested[privateKeyUrl]; // delete cached 404 error
|
|
95
|
+
return _context.abrupt("return", undefined);
|
|
96
|
+
case 24:
|
|
97
|
+
debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + _context.t0);
|
|
98
|
+
throw _context.t0;
|
|
99
|
+
case 26:
|
|
100
|
+
case "end":
|
|
101
|
+
return _context.stop();
|
|
102
|
+
}
|
|
103
|
+
}, _callee, null, [[1, 7], [10, 18]]);
|
|
104
|
+
}));
|
|
105
|
+
return _privateKeyExists.apply(this, arguments);
|
|
52
106
|
}
|
|
53
|
-
function getPrivateKey(
|
|
107
|
+
function getPrivateKey(_x2) {
|
|
54
108
|
return _getPrivateKey.apply(this, arguments);
|
|
55
109
|
}
|
|
56
110
|
function _getPrivateKey() {
|
|
57
|
-
_getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
111
|
+
_getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(webId) {
|
|
58
112
|
var url, privateKeyUrl, publicKey, privateKey, del, add;
|
|
59
|
-
return _regenerator["default"].wrap(function
|
|
60
|
-
while (1) switch (
|
|
113
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
114
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
61
115
|
case 0:
|
|
62
116
|
url = new URL(webId);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
117
|
+
url.hash = '';
|
|
118
|
+
/* const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl' */
|
|
119
|
+
privateKeyUrl = privKeyUrl(webId); // find publickey
|
|
120
|
+
publicKey = publicKeyExists(webId); // debug.warn('publicKey ' + publicKey)
|
|
121
|
+
// find privateKey
|
|
122
|
+
_context2.next = 6;
|
|
123
|
+
return privateKeyExists(webId);
|
|
124
|
+
case 6:
|
|
125
|
+
privateKey = _context2.sent;
|
|
126
|
+
// debug.warn('privateKey ' + privateKey)
|
|
127
|
+
if (privateKey && publicKey !== generatePublicKey(privateKey)) debug.warn('publicKey is not valid');
|
|
128
|
+
|
|
129
|
+
// simulate new key pair
|
|
130
|
+
/* const newPrivateKey = generatePrivateKey()
|
|
131
|
+
const newPublicKey = generatePublicKey(newPrivateKey)
|
|
132
|
+
debug.log('newPrivateKey ' + newPrivateKey)
|
|
133
|
+
debug.log('newPublicKey ' + newPublicKey) */
|
|
134
|
+
|
|
135
|
+
// create key pair
|
|
66
136
|
if (!(!privateKey || !publicKey)) {
|
|
67
|
-
|
|
137
|
+
_context2.next = 19;
|
|
68
138
|
break;
|
|
69
139
|
}
|
|
70
140
|
del = [];
|
|
71
141
|
add = [];
|
|
72
|
-
if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + '
|
|
73
|
-
if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + '
|
|
74
|
-
privateKey =
|
|
75
|
-
publicKey =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
142
|
+
if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PrivateKey'), $rdf.lit(privateKey), $rdf.sym(privateKeyUrl)));
|
|
143
|
+
if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PublicKey'), $rdf.lit(publicKey), $rdf.sym(url.href)));
|
|
144
|
+
privateKey = generatePrivateKey();
|
|
145
|
+
publicKey = generatePublicKey(privateKey);
|
|
146
|
+
/* debug.log('newPrivateKey-1 ' + privateKey)
|
|
147
|
+
debug.log('newPublicKey-1 ' + publicKey) */
|
|
148
|
+
add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PrivateKey'), $rdf.literal(privateKey), $rdf.sym(privateKeyUrl)));
|
|
149
|
+
add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'PublicKey'), $rdf.literal(publicKey), $rdf.sym(url.href)));
|
|
150
|
+
_context2.next = 19;
|
|
79
151
|
return _solidLogic.store.updater.updateMany(del, add);
|
|
80
|
-
case
|
|
81
|
-
return
|
|
82
|
-
case
|
|
152
|
+
case 19:
|
|
153
|
+
return _context2.abrupt("return", privateKey);
|
|
154
|
+
case 20:
|
|
83
155
|
case "end":
|
|
84
|
-
return
|
|
156
|
+
return _context2.stop();
|
|
85
157
|
}
|
|
86
|
-
},
|
|
158
|
+
}, _callee2);
|
|
87
159
|
}));
|
|
88
160
|
return _getPrivateKey.apply(this, arguments);
|
|
89
161
|
}
|
package/lib/chat/keys.js.map
CHANGED
|
@@ -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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GAAG,CAACZ,KAAK,CAAC,EAAEhC,IAAI,CAAC4C,GAAG,CAACC,eAAI,GAAG,YAAY,CAAC,EAAE7C,IAAI,CAACmE,OAAO,CAACrC,UAAU,CAACK,GAAG,CAAC,EAAEnC,IAAI,CAAC4C,GAAG,CAACG,aAAa,CAAC,CAAC,CAAC;UACxHY,GAAG,CAACM,IAAI,CAACjE,IAAI,CAACkE,EAAE,CAAClE,IAAI,CAAC4C,GAAG,CAACZ,KAAK,CAAC,EAAEhC,IAAI,CAAC4C,GAAG,CAACC,eAAI,GAAG,WAAW,CAAC,EAAE7C,IAAI,CAACmE,OAAO,CAAClC,SAAS,CAACE,GAAG,CAAC,EAAEnC,IAAI,CAAC4C,GAAG,CAACR,GAAG,CAACM,IAAI,CAAC,CAAC,CAAC;UAAAoB,QAAA,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","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","generatePrivateKey","bytesToHex","schnorr","utils","randomPrivateKey","generatePublicKey","privateKey","getPublicKey","webId","publicKey","publicKeyExists","url","URL","hash","store","fetcher","load","href","any","sym","CERT","value","privKeyUrl","privateKeyUrl","protocol","host","privateKeyExists","_x","_privateKeyExists","apply","arguments","_asyncToGenerator2","_regenerator","mark","_callee","_err$response","data","contentType","response","wrap","_callee$","_context","prev","next","abrupt","t0","status","webOperation","sent","t1","log","requested","undefined","stop","getPrivateKey","_x2","_getPrivateKey","_callee2","del","add","_callee2$","_context2","warn","push","st","lit","literal","updater","updateMany"],"sources":["../../src/chat/keys.ts"],"sourcesContent":["import * as debug from '../debug'\r\nimport { schnorr } from '@noble/curves/secp256k1'\r\nimport { bytesToHex } from '@noble/hashes/utils'\r\nimport { CERT } from './signature'\r\nimport { store } from 'solid-logic'\r\nimport * as $rdf from 'rdflib'\r\nimport { NamedNode, literal } from 'rdflib'\r\n\r\nexport function generatePrivateKey (): string {\r\n return bytesToHex(schnorr.utils.randomPrivateKey())\r\n}\r\n\r\nexport function generatePublicKey (privateKey: string): string {\r\n return bytesToHex(schnorr.getPublicKey(privateKey))\r\n}\r\n\r\nexport function getPublicKey (webId) {\r\n const publicKey = publicKeyExists(webId)\r\n return publicKey\r\n}\r\n\r\nfunction publicKeyExists (webId: string) {\r\n // find publickey\r\n const url = new URL(webId)\r\n url.hash = ''\r\n /* debug.warn('Alain publicKeyExists')\r\n debug.warn(webId)\r\n debug.warn(url.href) */\r\n store.fetcher.load(url.href)\r\n const publicKey = store.any(store.sym(webId), store.sym(CERT + 'PublicKey'))\r\n return publicKey?.value // as NamedNode\r\n}\r\n\r\nconst privKeyUrl = (webId: string) => {\r\n const url = new URL(webId)\r\n const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl'\r\n return privateKeyUrl\r\n}\r\n\r\nasync function privateKeyExists (webId: string) {\r\n /* const url = new URL(webId)\r\n const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl' */\r\n const privateKeyUrl = privKeyUrl(webId)\r\n /* debug.warn('Alain privateKeyExists')\r\n debug.warn(webId)\r\n debug.warn(privateKeyUrl) */\r\n try {\r\n store.fetcher.load(privateKeyUrl)\r\n const privateKey = store.any(store.sym(webId), store.sym(CERT + 'PrivateKey'))\r\n return privateKey?.value // as NamedNode\r\n } catch (err) {\r\n if (err?.response?.status === 404) {\r\n try {\r\n // create privateKey resource\r\n const data = ''\r\n const contentType = 'text/ttl'\r\n const response = await store.fetcher.webOperation('PUT', privateKeyUrl, {\r\n data,\r\n contentType\r\n })\r\n // create ACL resource\r\n } catch (err) {\r\n debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + err)\r\n throw err\r\n }\r\n delete store.fetcher.requested[privateKeyUrl] // delete cached 404 error\r\n return undefined\r\n }\r\n debug.log('createIfNotExists doc FAILED: ' + privateKeyUrl + ': ' + err)\r\n throw err\r\n }\r\n}\r\n\r\nexport async function getPrivateKey (webId: string) {\r\n const url = new URL(webId)\r\n url.hash = ''\r\n /* const privateKeyUrl = url.protocol + '//' + url.host + '/profile/privateKey.ttl' */\r\n const privateKeyUrl = privKeyUrl(webId)\r\n\r\n // find publickey\r\n let publicKey = publicKeyExists(webId)\r\n // debug.warn('publicKey ' + publicKey)\r\n // find privateKey\r\n let privateKey = await privateKeyExists(webId)\r\n // debug.warn('privateKey ' + privateKey)\r\n if (privateKey && (publicKey !== generatePublicKey(privateKey as string))) debug.warn('publicKey is not valid')\r\n\r\n // simulate new key pair\r\n /* const newPrivateKey = generatePrivateKey()\r\n const newPublicKey = generatePublicKey(newPrivateKey)\r\n debug.log('newPrivateKey ' + newPrivateKey)\r\n debug.log('newPublicKey ' + newPublicKey) */\r\n\r\n // create key pair\r\n if (!privateKey || !publicKey) {\r\n const del: any[] = []\r\n const add: any[] = []\r\n if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PrivateKey'), $rdf.lit(privateKey), $rdf.sym(privateKeyUrl)))\r\n if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PublicKey'), $rdf.lit(publicKey), $rdf.sym(url.href)))\r\n\r\n privateKey = generatePrivateKey()\r\n publicKey = generatePublicKey(privateKey)\r\n /* debug.log('newPrivateKey-1 ' + privateKey)\r\n debug.log('newPublicKey-1 ' + publicKey) */\r\n add.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PrivateKey'), $rdf.literal(privateKey), $rdf.sym(privateKeyUrl)))\r\n add.push($rdf.st($rdf.sym(webId), $rdf.sym(CERT + 'PublicKey'), $rdf.literal(publicKey), $rdf.sym(url.href)))\r\n await store.updater.updateMany(del, add)\r\n }\r\n return privateKey as string\r\n}\r\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAN,uBAAA,CAAAC,OAAA;AAA8B,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAR,wBAAAY,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,aAAAE,OAAA,CAAAF,GAAA,yBAAAA,GAAA,uCAAAA,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,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,GAAAC,MAAA,CAA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CAACxD,SAAS,CAAC,EAAEhC,IAAI,CAAC0C,GAAG,CAACR,GAAG,CAACM,IAAI,CAAC,CAAC,CAAC;UAExHX,UAAU,GAAGN,kBAAkB,EAAE;UACjCS,SAAS,GAAGJ,iBAAiB,CAACC,UAAU,CAAC;UACzC;AACJ;UACIqD,GAAG,CAACI,IAAI,CAACtF,IAAI,CAACuF,EAAE,CAACvF,IAAI,CAAC0C,GAAG,CAACX,KAAK,CAAC,EAAE/B,IAAI,CAAC0C,GAAG,CAACC,eAAI,GAAG,YAAY,CAAC,EAAE3C,IAAI,CAACyF,OAAO,CAAC5D,UAAU,CAAC,EAAE7B,IAAI,CAAC0C,GAAG,CAACI,aAAa,CAAC,CAAC,CAAC;UACpHoC,GAAG,CAACI,IAAI,CAACtF,IAAI,CAACuF,EAAE,CAACvF,IAAI,CAAC0C,GAAG,CAACX,KAAK,CAAC,EAAE/B,IAAI,CAAC0C,GAAG,CAACC,eAAI,GAAG,WAAW,CAAC,EAAE3C,IAAI,CAACyF,OAAO,CAACzD,SAAS,CAAC,EAAEhC,IAAI,CAAC0C,GAAG,CAACR,GAAG,CAACM,IAAI,CAAC,CAAC,CAAC;UAAA4C,SAAA,CAAAlB,IAAA;UAAA,OACvG7B,iBAAK,CAACqD,OAAO,CAACC,UAAU,CAACV,GAAG,EAAEC,GAAG,CAAC;QAAA;UAAA,OAAAE,SAAA,CAAAjB,MAAA,WAEnCtC,UAAU;QAAA;QAAA;UAAA,OAAAuD,SAAA,CAAAR,IAAA;MAAA;IAAA,GAAAI,QAAA;EAAA,CAClB;EAAA,OAAAD,cAAA,CAAA3B,KAAA,OAAAC,SAAA;AAAA"}
|
package/lib/chat/message.js
CHANGED
|
@@ -115,21 +115,32 @@ 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
|
|
119
|
-
|
|
118
|
+
var latestVersionCreator = _solidLogic.store.any(latestVersion, ns.foaf('maker'));
|
|
119
|
+
// use latest content if same owner, else use original
|
|
120
|
+
var msgId = creator === latestVersionCreator ? latestVersion : message;
|
|
121
|
+
var content = _solidLogic.store.any(msgId, ns.sioc('content'));
|
|
122
|
+
var signature = _solidLogic.store.any(msgId, $rdf.sym("".concat(_signature.SEC, "Proof")));
|
|
123
|
+
debug.log('alain ' + (signature === null || signature === void 0 ? void 0 : signature.value));
|
|
120
124
|
|
|
121
125
|
// verify signature
|
|
122
126
|
var msg = (0, _signature.getBlankMsg)();
|
|
123
|
-
msg.id =
|
|
124
|
-
msg.created =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
msg.id = msgId.uri;
|
|
128
|
+
msg.created = _solidLogic.store.any(msgId, ns.dct('created')).value;
|
|
129
|
+
msg.content = content.value;
|
|
130
|
+
msg.maker = creator.uri;
|
|
131
|
+
try {
|
|
132
|
+
// pubKey could be store in a cache for all makers
|
|
133
|
+
var pubKey = (0, _keys.getPublicKey)(creator.uri);
|
|
134
|
+
/* const pubKey0 = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'
|
|
135
|
+
debug.warn('publicKeys\n' + pubKey0 + '\n' + pubKey)
|
|
136
|
+
const privKey0 = getPrivateKey(creator.uri) // alain to remove
|
|
137
|
+
// unsigned messages should be signaled as unsecured
|
|
138
|
+
debug.warn(msg)
|
|
139
|
+
debug.warn(signature?.value) */
|
|
140
|
+
if (signature !== null && signature !== void 0 && signature.value && !(0, _signature.verifySignature)(signature.value, msg, pubKey)) throw new Error('invalid signature');
|
|
141
|
+
} catch (err) {
|
|
142
|
+
debug.log(err);
|
|
143
|
+
}
|
|
133
144
|
var originalMessage = (0, _chatLogic.originalVersion)(message);
|
|
134
145
|
var edited = !message.sameTerm(originalMessage);
|
|
135
146
|
var sortDate = _solidLogic.store.the(originalMessage, ns.dct('created'), null, originalMessage.doc()); // In message
|