solid-ui 2.4.27-9d7e618e → 2.4.27-9ee704cb
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/README.md +6 -1
- package/dist/solid-ui.js +1680 -1219
- 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 +28 -20
- package/lib/chat/chatLogic.js.map +1 -1
- package/lib/chat/keys.d.ts +10 -2
- package/lib/chat/keys.d.ts.map +1 -1
- package/lib/chat/keys.js +185 -86
- package/lib/chat/keys.js.map +1 -1
- package/lib/chat/message.js +62 -17
- package/lib/chat/message.js.map +1 -1
- package/lib/chat/signature.d.ts +0 -2
- package/lib/chat/signature.d.ts.map +1 -1
- package/lib/chat/signature.js +24 -21
- package/lib/chat/signature.js.map +1 -1
- package/lib/utils/keyHelpers/accessData.d.ts +10 -0
- package/lib/utils/keyHelpers/accessData.d.ts.map +1 -0
- package/lib/utils/keyHelpers/accessData.js +209 -0
- package/lib/utils/keyHelpers/accessData.js.map +1 -0
- package/lib/utils/keyHelpers/acl.d.ts +20 -0
- package/lib/utils/keyHelpers/acl.d.ts.map +1 -0
- package/lib/utils/keyHelpers/acl.js +93 -0
- package/lib/utils/keyHelpers/acl.js.map +1 -0
- 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/crypto.js
DELETED
|
@@ -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
|
package/lib/chat/crypto.js.map
DELETED
|
@@ -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"}
|