@@ -3,6 +3,7 @@ import { schnorr } from '@noble/curves/secp256k1'
33import { bytesToHex } from '@noble/hashes/utils'
44import { CERT } from './signature'
55import { store } from 'solid-logic'
6+ import { NamedNode } from 'rdflib'
67import * as $rdf from 'rdflib'
78import { publicKeyExists , pubKeyUrl , privKeyUrl , privateKeyExists } from '../utils/cryptoKeyHelpers'
89
@@ -16,10 +17,10 @@ export function generatePublicKey (privateKey: string): string {
1617
1718export async function getPublicKey ( webId ) {
1819 await store . fetcher . load ( webId )
19- const publicKeyDoc = pubKeyUrl ( webId )
20+ const publicKeyDoc = await pubKeyUrl ( webId )
2021 try {
2122 await store . fetcher . load ( publicKeyDoc ) // url.href)
22- const key = store . any ( store . sym ( webId ) , store . sym ( CERT + 'PublicKey' ) )
23+ const key = store . any ( webId , store . sym ( CERT + 'PublicKey' ) )
2324 return key ?. value // as NamedNode
2425 } catch ( err ) {
2526 return undefined
@@ -29,11 +30,11 @@ export async function getPublicKey (webId) {
2930 // return publicKey
3031}
3132
32- export async function getPrivateKey ( webId : string ) {
33+ export async function getPrivateKey ( webId : NamedNode ) {
3334 await store . fetcher . load ( webId )
3435 // find keys url's
35- const publicKeyDoc = pubKeyUrl ( webId )
36- const privateKeyDoc = privKeyUrl ( webId )
36+ const publicKeyDoc = await pubKeyUrl ( webId )
37+ const privateKeyDoc = await privKeyUrl ( webId )
3738
3839 // find key pair
3940 const publicKey = await publicKeyExists ( webId )
@@ -50,28 +51,28 @@ export async function getPrivateKey (webId: string) {
5051 if ( ! privateKey || ! publicKey || ! validPublicKey ) {
5152 let del : any [ ] = [ ]
5253 let add : any [ ] = [ ]
53- // if (privateKey) del.push($rdf.st($rdf.sym( webId), $rdf .sym(CERT + 'PrivateKey'), $rdf.lit(privateKey), $rdf .sym(privateKeyDoc)))
54+ // if (privateKey) del.push($rdf.st(webId, store .sym(CERT + 'PrivateKey'), $rdf.lit(privateKey), store .sym(privateKeyDoc)))
5455
5556 if ( ! privateKey ) {
5657 // add = []
5758 privateKey = generatePrivateKey ( )
58- add = [ $rdf . st ( $rdf . sym ( webId ) , $rdf . sym ( CERT + 'PrivateKey' ) , $rdf . literal ( privateKey ) , $rdf . sym ( privateKeyDoc ) ) ]
59- await saveKey ( privateKeyDoc , [ ] , add , webId )
59+ add = [ $rdf . st ( webId , store . sym ( CERT + 'PrivateKey' ) , $rdf . literal ( privateKey ) , store . sym ( privateKeyDoc ) ) ]
60+ await saveKey ( privateKeyDoc , [ ] , add , webId . uri )
6061 }
6162 if ( ! publicKey || ! validPublicKey ) {
6263 del = [ ]
6364 // delete invalid public key
6465 if ( publicKey ) {
65- del = [ $rdf . st ( $rdf . sym ( webId ) , $rdf . sym ( CERT + 'PublicKey' ) , $rdf . lit ( publicKey ) , $rdf . sym ( publicKeyDoc ) ) ]
66+ del = [ $rdf . st ( webId , store . sym ( CERT + 'PublicKey' ) , $rdf . lit ( publicKey ) , store . sym ( publicKeyDoc ) ) ]
6667 debug . log ( del )
6768 }
6869 // update new valid key
6970 const newPublicKey = generatePublicKey ( privateKey )
70- add = [ $rdf . st ( $rdf . sym ( webId ) , $rdf . sym ( CERT + 'PublicKey' ) , $rdf . literal ( newPublicKey ) , $rdf . sym ( publicKeyDoc ) ) ]
71+ add = [ $rdf . st ( webId , store . sym ( CERT + 'PublicKey' ) , $rdf . literal ( newPublicKey ) , store . sym ( publicKeyDoc ) ) ]
7172 await saveKey ( publicKeyDoc , del , add )
7273 }
7374 const keyContainer = privateKeyDoc . substring ( 0 , privateKeyDoc . lastIndexOf ( '/' ) + 1 )
74- await setAcl ( keyContainer , keyContainerAclBody ( webId ) ) // includes DELETE and PUT
75+ await setAcl ( keyContainer , keyContainerAclBody ( webId . uri ) ) // includes DELETE and PUT
7576 }
7677 return privateKey as string
7778}
@@ -131,8 +132,8 @@ async function setAcl (keyDoc, aclBody) {
131132 await store . fetcher . load ( keyDoc )
132133
133134 // FIXME: check the Why value on this quad:
134- debug . log ( store . statementsMatching ( $rdf . sym ( keyDoc ) , $rdf . sym ( 'http://www.iana.org/assignments/link-relations/acl' ) ) )
135- const keyAclDoc = store . any ( $rdf . sym ( keyDoc ) , $rdf . sym ( 'http://www.iana.org/assignments/link-relations/acl' ) )
135+ debug . log ( store . statementsMatching ( store . sym ( keyDoc ) , store . sym ( 'http://www.iana.org/assignments/link-relations/acl' ) ) )
136+ const keyAclDoc = store . any ( store . sym ( keyDoc ) , store . sym ( 'http://www.iana.org/assignments/link-relations/acl' ) )
136137 if ( ! keyAclDoc ) {
137138 throw new Error ( 'Key ACL doc not found!' )
138139 }
@@ -162,7 +163,7 @@ async function saveKey (keyDoc, del, add, me = '') {
162163 // delete keyAclDoc
163164 try {
164165 // get keyAcldoc
165- const keyAclDoc = store . any ( $rdf . sym ( keyDoc ) , $rdf . sym ( 'http://www.iana.org/assignments/link-relations/acl' ) )
166+ const keyAclDoc = store . any ( store . sym ( keyDoc ) , store . sym ( 'http://www.iana.org/assignments/link-relations/acl' ) )
166167 if ( keyAclDoc ) {
167168 // delete READ only keyAclDoc. This is possible if the webId is an owner
168169 try {
0 commit comments