Skip to content

Commit

Permalink
key changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SharonStrats committed Jun 6, 2023
1 parent e0a6f2e commit 7d93d5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/chat/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function validPublicKey (webId: NamedNode, publicKey: string | undefined,
return true
}

export async function generateAndStorePublicKey (webId: NamedNode, privateKey: string, publicKey: string | undefined, publicKeyDoc: string) {
export async function generateAndStoreNewPublicKey (webId: NamedNode, privateKey: string, publicKey: string | undefined, publicKeyDoc: string) {
const del = [$rdf.st(webId, ns.solid('publicKey'), $rdf.lit(publicKey || ''), store.sym(publicKeyDoc))]
const newPublicKey = generatePublicKey(privateKey)
const add = [$rdf.st(webId, ns.solid('publicKey'), $rdf.literal(newPublicKey), store.sym(publicKeyDoc))]
Expand All @@ -61,7 +61,7 @@ export async function createAndSaveKeyPairs (webId: NamedNode, publicKey: string
const add = [$rdf.st(webId, ns.solid('privateKey'), $rdf.literal(privateKey), store.sym(privateKeyDoc))]
await saveKeyAndHandleAcl(privateKeyDoc, [], add, webId.uri)

await generateAndStorePublicKey(webId, privateKey, publicKey, publicKeyDoc)
await generateAndStoreNewPublicKey(webId, privateKey, publicKey, publicKeyDoc)

return privateKey
}
Expand All @@ -80,7 +80,7 @@ export async function getPrivateKey (webId: NamedNode) {
privateKey = await createAndSaveKeyPairs(webId, publicKey, privateKeyDoc, publicKeyDoc)
}
if (!validPublicKey(webId, publicKey, privateKey)) {
await generateAndStorePublicKey(webId, privateKey, publicKey, publicKeyDoc)
await generateAndStoreNewPublicKey(webId, privateKey, publicKey, publicKeyDoc)
}

const keyContainer = privateKeyDoc.substring(0, privateKeyDoc.lastIndexOf('/') + 1)
Expand Down
2 changes: 2 additions & 0 deletions test/unit/chat/keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const webId = new NamedNode('https://alice.solidcommunity.net/profile/card#me')
jest.mock('../../../src/utils/keyHelpers/accessData')
store.fetcher.load = jest.fn()
store.any = jest.fn()
store.updater.updateMany = jest.fn()
store.fetcher.webOperation = jest.fn()

describe('generate key pair', () => {
it('private key exists is length 64', () => {
Expand Down

0 comments on commit 7d93d5d

Please sign in to comment.