feat: publish public key, #357

This commit is contained in:
Friedger Müffke
2020-05-01 11:32:38 +02:00
committed by Hank Stoever
parent 42da3f1c0c
commit 7c0a1bb0a6
3 changed files with 16 additions and 4 deletions

View File

@@ -67,9 +67,12 @@ export class Identity {
profile.apps = {};
}
const challengeSigner = ECPair.fromPrivateKey(Buffer.from(appPrivateKey, 'hex'));
profile.apps[appDomain] = `${hubInfo.read_url_prefix}${await ecPairToAddress(
challengeSigner
)}`;
const storageUrl = `${hubInfo.read_url_prefix}${await ecPairToAddress(challengeSigner)}`;
profile.apps[appDomain] = storageUrl;
if (!profile.appsMeta) {
profile.appsMeta = {};
}
profile.appsMeta[appDomain] = { storage: storageUrl, publicKey: this.keyPair.keyID };
const gaiaHubConfig = await connectToGaiaHubWithConfig({
hubInfo,
privateKey: this.keyPair.key,

View File

@@ -24,6 +24,12 @@ export interface Profile {
apps?: {
[origin: string]: string;
};
appsMeta?: {
[origin: string]: {
publicKey: string;
storage: string;
};
};
name?: string;
image?: ProfileImage[];
[key: string]: any;

View File

@@ -56,7 +56,7 @@ test('adds to apps in profile if publish_data scope', async () => {
const { payload } = decoded as Decoded;
expect(payload.profile.apps['https://banter.pub']).not.toBeFalsy();
const profile = JSON.parse(fetchMock.mock.calls[7][1].body);
const { apps } = profile[0].decodedToken.payload.claim;
const { apps, appsMeta } = profile[0].decodedToken.payload.claim;
expect(apps[appDomain]).not.toBeFalsy();
const appPrivateKey = await decryptPrivateKey(transitPrivateKey, payload.private_key);
const challengeSigner = ECPair.fromPrivateKey(Buffer.from(appPrivateKey as string, 'hex'));
@@ -64,6 +64,9 @@ test('adds to apps in profile if publish_data scope', async () => {
challengeSigner
)}`;
expect(apps[appDomain]).toEqual(expectedDomain);
expect(appsMeta[appDomain]).not.toBeFalsy();
expect(appsMeta[appDomain].storage).toEqual(expectedDomain);
expect(appsMeta[appDomain].publicKey).toEqual(challengeSigner.publicKey.toString('hex'));
});
test('generates an app private key', async () => {