solid-ui 2.4.27-8b9aa479 → 2.4.27-8e7523bf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,257 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,5 +0,0 @@
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: any): Promise<any>;
5
- //# sourceMappingURL=keys.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/chat/keys.ts"],"names":[],"mappings":"AAOA,wBAAgB,kBAAkB,IAAK,MAAM,CAE5C;AAED,wBAAgB,iBAAiB,CAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAgB,YAAY,CAAE,KAAK,KAAA,OAQlC;AAmBD,wBAAsB,aAAa,CAAE,KAAK,KAAA,gBAsBzC"}
package/lib/chat/keys.js DELETED
@@ -1,88 +0,0 @@
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 _secp256k = require("@noble/curves/secp256k1");
15
- var _utils = require("@noble/hashes/utils");
16
- var _signature = require("./signature");
17
- var _solidLogic = require("solid-logic");
18
- var $rdf = _interopRequireWildcard(require("rdflib"));
19
- 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
- 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
- function generatePrivateKey() {
22
- return (0, _utils.bytesToHex)(_secp256k.schnorr.utils.randomPrivateKey());
23
- }
24
- function generatePublicKey(privateKey) {
25
- return (0, _utils.bytesToHex)(_secp256k.schnorr.getPublicKey(privateKey));
26
- }
27
- function getPublicKey(webId) {
28
- // find publickey
29
- /* const url = new URL(webId)
30
- url.hash = ''
31
- store.fetcher.load(url.href)
32
- let publicKey = store.any(store.sym(webId), store.sym(CERT +'publicKey')) */
33
- var publicKey = publicKeyExists(webId);
34
- return publicKey === null || publicKey === void 0 ? void 0 : publicKey.uri;
35
- }
36
- function publicKeyExists(webId) {
37
- // find publickey
38
- var url = new URL(webId);
39
- url.hash = '';
40
- _solidLogic.store.fetcher.load(url.href);
41
- var publicKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'publicKey'));
42
- return publicKey;
43
- }
44
- function privateKeyExists(webId) {
45
- var url = new URL(webId);
46
- var privateKeyUrl = url.hostname + '/profile/privateKey.ttl';
47
- _solidLogic.store.fetcher.load(privateKeyUrl);
48
- var privateKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'privateKey'));
49
- return privateKey;
50
- }
51
- function getPrivateKey(_x) {
52
- return _getPrivateKey.apply(this, arguments);
53
- }
54
- function _getPrivateKey() {
55
- _getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
56
- var url, privateKeyUrl, publicKey, privateKey, del, add;
57
- return _regenerator["default"].wrap(function _callee$(_context) {
58
- while (1) switch (_context.prev = _context.next) {
59
- case 0:
60
- url = new URL(webId);
61
- privateKeyUrl = url.hostname + '/profile/privateKey.ttl'; // find publickey
62
- publicKey = publicKeyExists(webId); // find privateKey
63
- privateKey = privateKeyExists(webId); // create key pair
64
- if (!(!privateKey || !publicKey)) {
65
- _context.next = 15;
66
- break;
67
- }
68
- del = [];
69
- add = [];
70
- if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'privateKey'), privateKey, $rdf.sym(privateKeyUrl)));
71
- if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'publicKey'), publicKey, $rdf.sym(url.href)));
72
- privateKey = _solidLogic.store.sym(generatePrivateKey());
73
- publicKey = _solidLogic.store.sym(generatePublicKey(privateKey.uri));
74
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'privateKey'), $rdf.literal(privateKey.uri), $rdf.sym(privateKeyUrl)));
75
- add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'publicKey'), $rdf.literal(publicKey.uri), $rdf.sym(url.href)));
76
- _context.next = 15;
77
- return _solidLogic.store.updater.updateMany(del, add);
78
- case 15:
79
- return _context.abrupt("return", privateKey.uri);
80
- case 16:
81
- case "end":
82
- return _context.stop();
83
- }
84
- }, _callee);
85
- }));
86
- return _getPrivateKey.apply(this, arguments);
87
- }
88
- //# sourceMappingURL=keys.js.map
@@ -1 +0,0 @@
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\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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AG,CAACR,GAAG,CAACM,IAAI,CAAC,CAAC,CAAC;UAE9GZ,UAAU,GAAGS,iBAAK,CAACK,GAAG,CAACpB,kBAAkB,EAAE,CAAC;UAC5CS,SAAS,GAAGM,iBAAK,CAACK,GAAG,CAACf,iBAAiB,CAACC,UAAU,CAACK,GAAG,CAAC,CAAC;UAExDwB,GAAG,CAACM,IAAI,CAACjE,IAAI,CAACkE,EAAE,CAAClE,IAAI,CAAC4C,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,27 +0,0 @@
1
- export declare const utf8Decoder: TextDecoder;
2
- export declare const utf8Encoder: TextEncoder;
3
- export declare const SEC = "https://w3id.org/security#";
4
- export declare const CERT = "http://www.w3.org/ns/auth/cert#";
5
- export type MsgTemplate = {
6
- id: string;
7
- created: string;
8
- dateDeleted: string;
9
- content: string;
10
- maker: string;
11
- sig: string;
12
- };
13
- export type UnsignedMsg = MsgTemplate & {
14
- pubkey: string;
15
- };
16
- export type Message = UnsignedMsg & {
17
- id: string;
18
- sig: string;
19
- };
20
- export declare function getBlankMsg(): MsgTemplate;
21
- export declare function finishMsg(t: MsgTemplate, privateKey: string): Message;
22
- export declare function serializeMsg(msg: UnsignedMsg): string;
23
- export declare function getMsgHash(message: UnsignedMsg): string;
24
- export declare function validateMsg<T>(message: T): message is T & UnsignedMsg;
25
- export declare function verifySignature(sig: string, message: Message, pubKey: string): boolean;
26
- export declare function signMsg(message: UnsignedMsg, key: string): string;
27
- //# sourceMappingURL=signature.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/chat/signature.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,WAAW,aAA2B,CAAA;AACnD,eAAO,MAAM,WAAW,aAAoB,CAAA;AAE5C,eAAO,MAAM,GAAG,+BAA+B,CAAA;AAC/C,eAAO,MAAM,IAAI,oCAAoC,CAAA;AA2BrD,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,wBAAgB,WAAW,IAAK,WAAW,CAS1C;AAED,wBAAgB,SAAS,CAAE,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAOtE;AAED,wBAAgB,YAAY,CAAE,GAAG,EAAE,WAAW,GAAG,MAAM,CAMtD;AAED,wBAAgB,UAAU,CAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAGxD;AAID,wBAAgB,WAAW,CAAC,CAAC,EAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,WAAW,CAkBtE;AAED,wBAAgB,eAAe,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAMvF;AAED,wBAAgB,OAAO,CAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIlE"}
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SEC = exports.CERT = void 0;
7
- exports.finishMsg = finishMsg;
8
- exports.getBlankMsg = getBlankMsg;
9
- exports.getMsgHash = getMsgHash;
10
- exports.serializeMsg = serializeMsg;
11
- exports.signMsg = signMsg;
12
- exports.utf8Encoder = exports.utf8Decoder = void 0;
13
- exports.validateMsg = validateMsg;
14
- exports.verifySignature = verifySignature;
15
- var _secp256k = require("@noble/curves/secp256k1");
16
- var _sha = require("@noble/hashes/sha256");
17
- var _utils = require("@noble/hashes/utils");
18
- // import {utf8Encoder} from './utils'
19
- // import { getPublicKey } from './keys'
20
-
21
- var utf8Decoder = new TextDecoder('utf-8');
22
- exports.utf8Decoder = utf8Decoder;
23
- var utf8Encoder = new TextEncoder();
24
- exports.utf8Encoder = utf8Encoder;
25
- var SEC = 'https://w3id.org/security#'; // Proof, VerificationMethod
26
- exports.SEC = SEC;
27
- var CERT = 'http://www.w3.org/ns/auth/cert#'; // PrivatKey, PublicKey
28
-
29
- /* eslint-disable no-unused-vars */
30
- /* export enum Kind {
31
- Metadata = 0,
32
- Text = 1,
33
- RecommendRelay = 2,
34
- Contacts = 3,
35
- EncryptedDirectMessage = 4,
36
- EventDeletion = 5,
37
- Reaction = 7,
38
- BadgeAward = 8,
39
- ChannelCreation = 40,
40
- ChannelMetadata = 41,
41
- ChannelMessage = 42,
42
- ChannelHideMessage = 43,
43
- ChannelMuteUser = 44,
44
- Report = 1984,
45
- ZapRequest = 9734,
46
- Zap = 9735,
47
- RelayList = 10002,
48
- ClientAuth = 22242,
49
- BadgeDefinition = 30008,
50
- ProfileBadge = 30009,
51
- Article = 30023
52
- } */
53
- exports.CERT = CERT;
54
- function getBlankMsg() {
55
- return {
56
- id: '',
57
- created: '',
58
- dateDeleted: '',
59
- content: '',
60
- maker: '',
61
- sig: ''
62
- };
63
- }
64
- function finishMsg(t, privateKey) {
65
- // to update to chat message triples
66
- var message = t;
67
- // message.pubkey = getPublicKey(privateKey)
68
- message.id = getMsgHash(message);
69
- message.sig = signMsg(message, privateKey);
70
- return message;
71
- }
72
- function serializeMsg(msg) {
73
- // to update to chat messages triples
74
- /* if (!validateMsg(msg))
75
- throw new Error("can't serialize message with wrong or missing properties") */
76
-
77
- return JSON.stringify(msg);
78
- }
79
- function getMsgHash(message) {
80
- var msgHash = (0, _sha.sha256)(utf8Encoder.encode(serializeMsg(message)));
81
- return (0, _utils.bytesToHex)(msgHash);
82
- }
83
- var isRecord = function isRecord(obj) {
84
- return obj instanceof Object;
85
- };
86
- function validateMsg(message) {
87
- /* if (!isRecord(message)) return false
88
- if (typeof message.kind !== 'number') return false
89
- if (typeof message.content !== 'string') return false
90
- if (typeof message.created_at !== 'number') return false
91
- if (typeof message.pubkey !== 'string') return false
92
- if (!message.pubkey.match(/^[a-f0-9]{64}$/)) return false
93
- if (!Array.isArray(message.tags)) return false
94
- for (let i = 0; i < message.tags.length; i++) {
95
- let tag = message.tags[i]
96
- if (!Array.isArray(tag)) return false
97
- for (let j = 0; j < tag.length; j++) {
98
- if (typeof tag[j] === 'object') return false
99
- }
100
- } */
101
-
102
- return true;
103
- }
104
- function verifySignature(sig, message, pubKey) {
105
- return _secp256k.schnorr.verify(sig, getMsgHash(message), pubKey);
106
- }
107
- function signMsg(message, key) {
108
- return (0, _utils.bytesToHex)(_secp256k.schnorr.sign(getMsgHash(message), key));
109
- }
110
- //# sourceMappingURL=signature.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signature.js","names":["_secp256k","require","_sha","_utils","utf8Decoder","TextDecoder","exports","utf8Encoder","TextEncoder","SEC","CERT","getBlankMsg","id","created","dateDeleted","content","maker","sig","finishMsg","t","privateKey","message","getMsgHash","signMsg","serializeMsg","msg","JSON","stringify","msgHash","sha256","encode","bytesToHex","isRecord","obj","Object","validateMsg","verifySignature","pubKey","schnorr","verify","key","sign"],"sources":["../../src/chat/signature.ts"],"sourcesContent":["import { schnorr } from '@noble/curves/secp256k1'\r\nimport { sha256 } from '@noble/hashes/sha256'\r\nimport { bytesToHex } from '@noble/hashes/utils'\r\n\r\n// import {utf8Encoder} from './utils'\r\n// import { getPublicKey } from './keys'\r\n\r\nexport const utf8Decoder = new TextDecoder('utf-8')\r\nexport const utf8Encoder = new TextEncoder()\r\n\r\nexport const SEC = 'https://w3id.org/security#' // Proof, VerificationMethod\r\nexport const CERT = 'http://www.w3.org/ns/auth/cert#' // PrivatKey, PublicKey\r\n\r\n/* eslint-disable no-unused-vars */\r\n/* export enum Kind {\r\n Metadata = 0,\r\n Text = 1,\r\n RecommendRelay = 2,\r\n Contacts = 3,\r\n EncryptedDirectMessage = 4,\r\n EventDeletion = 5,\r\n Reaction = 7,\r\n BadgeAward = 8,\r\n ChannelCreation = 40,\r\n ChannelMetadata = 41,\r\n ChannelMessage = 42,\r\n ChannelHideMessage = 43,\r\n ChannelMuteUser = 44,\r\n Report = 1984,\r\n ZapRequest = 9734,\r\n Zap = 9735,\r\n RelayList = 10002,\r\n ClientAuth = 22242,\r\n BadgeDefinition = 30008,\r\n ProfileBadge = 30009,\r\n Article = 30023\r\n} */\r\n\r\nexport type MsgTemplate = {\r\n id: string\r\n created: string\r\n dateDeleted: string\r\n content: string\r\n maker: string\r\n sig: string\r\n}\r\n\r\nexport type UnsignedMsg = MsgTemplate & {\r\n pubkey: string\r\n}\r\n\r\nexport type Message = UnsignedMsg & {\r\n id: string\r\n sig: string\r\n}\r\n\r\nexport function getBlankMsg (): MsgTemplate {\r\n return {\r\n id: '',\r\n created: '',\r\n dateDeleted: '',\r\n content: '',\r\n maker: '',\r\n sig: ''\r\n }\r\n}\r\n\r\nexport function finishMsg (t: MsgTemplate, privateKey: string): Message {\r\n // to update to chat message triples\r\n const message = t as Message\r\n // message.pubkey = getPublicKey(privateKey)\r\n message.id = getMsgHash(message)\r\n message.sig = signMsg(message, privateKey)\r\n return message\r\n}\r\n\r\nexport function serializeMsg (msg: UnsignedMsg): string {\r\n // to update to chat messages triples\r\n /* if (!validateMsg(msg))\r\n throw new Error(\"can't serialize message with wrong or missing properties\") */\r\n\r\n return JSON.stringify(msg)\r\n}\r\n\r\nexport function getMsgHash (message: UnsignedMsg): string {\r\n const msgHash = sha256(utf8Encoder.encode(serializeMsg(message)))\r\n return bytesToHex(msgHash)\r\n}\r\n\r\nconst isRecord = (obj: unknown): obj is Record<string, unknown> => obj instanceof Object\r\n\r\nexport function validateMsg<T> (message: T): message is T & UnsignedMsg {\r\n /* if (!isRecord(message)) return false\r\n if (typeof message.kind !== 'number') return false\r\n if (typeof message.content !== 'string') return false\r\n if (typeof message.created_at !== 'number') return false\r\n if (typeof message.pubkey !== 'string') return false\r\n if (!message.pubkey.match(/^[a-f0-9]{64}$/)) return false\r\n\r\n if (!Array.isArray(message.tags)) return false\r\n for (let i = 0; i < message.tags.length; i++) {\r\n let tag = message.tags[i]\r\n if (!Array.isArray(tag)) return false\r\n for (let j = 0; j < tag.length; j++) {\r\n if (typeof tag[j] === 'object') return false\r\n }\r\n } */\r\n\r\n return true\r\n}\r\n\r\nexport function verifySignature (sig: string, message: Message, pubKey: string): boolean {\r\n return schnorr.verify(\r\n sig,\r\n getMsgHash(message),\r\n pubKey\r\n )\r\n}\r\n\r\nexport function signMsg (message: UnsignedMsg, key: string): string {\r\n return bytesToHex(\r\n schnorr.sign(getMsgHash(message), key)\r\n )\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA;AACA;;AAEO,IAAMG,WAAW,GAAG,IAAIC,WAAW,CAAC,OAAO,CAAC;AAAAC,OAAA,CAAAF,WAAA,GAAAA,WAAA;AAC5C,IAAMG,WAAW,GAAG,IAAIC,WAAW,EAAE;AAAAF,OAAA,CAAAC,WAAA,GAAAA,WAAA;AAErC,IAAME,GAAG,GAAG,4BAA4B,EAAC;AAAAH,OAAA,CAAAG,GAAA,GAAAA,GAAA;AACzC,IAAMC,IAAI,GAAG,iCAAiC,EAAC;;AAEtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAtBAJ,OAAA,CAAAI,IAAA,GAAAA,IAAA;AA0CO,SAASC,WAAWA,CAAA,EAAiB;EAC1C,OAAO;IACLC,EAAE,EAAE,EAAE;IACNC,OAAO,EAAE,EAAE;IACXC,WAAW,EAAE,EAAE;IACfC,OAAO,EAAE,EAAE;IACXC,KAAK,EAAE,EAAE;IACTC,GAAG,EAAE;EACP,CAAC;AACH;AAEO,SAASC,SAASA,CAAEC,CAAc,EAAEC,UAAkB,EAAW;EACtE;EACA,IAAMC,OAAO,GAAGF,CAAY;EAC5B;EACAE,OAAO,CAACT,EAAE,GAAGU,UAAU,CAACD,OAAO,CAAC;EAChCA,OAAO,CAACJ,GAAG,GAAGM,OAAO,CAACF,OAAO,EAAED,UAAU,CAAC;EAC1C,OAAOC,OAAO;AAChB;AAEO,SAASG,YAAYA,CAAEC,GAAgB,EAAU;EACtD;EACA;AACF;;EAEE,OAAOC,IAAI,CAACC,SAAS,CAACF,GAAG,CAAC;AAC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