From 1ca33fa10fcd2bbfedb592de5fdbad9c057bf153 Mon Sep 17 00:00:00 2001 From: Vitor Marthendal Nunes Date: Thu, 5 Dec 2024 11:30:08 -0300 Subject: [PATCH] Chore: credentials updates (#55) * chore: add create identifier script * feat: add profile image url to credential --- apps/api-credentials/src/app/verify/discord.ts | 1 + apps/api-credentials/src/app/verify/github.ts | 4 ++-- apps/api-credentials/src/app/verify/x.ts | 1 + .../src/lib/veramo/actions/create-credential.ts | 14 +++++++++++--- .../src/scripts/create-identifier.ts | 11 +++++++++++ 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 apps/api-credentials/src/scripts/create-identifier.ts diff --git a/apps/api-credentials/src/app/verify/discord.ts b/apps/api-credentials/src/app/verify/discord.ts index 40dbef0d..dfcb5034 100644 --- a/apps/api-credentials/src/app/verify/discord.ts +++ b/apps/api-credentials/src/app/verify/discord.ts @@ -49,6 +49,7 @@ verifyDiscordApp.get( handle: user.username, verifiedAt: new Date().toISOString(), platformProfileUrl: `https://discordapp.com/users/${user.id}`, + platformProfileImageUrl: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}`, }, }); const issuer = diff --git a/apps/api-credentials/src/app/verify/github.ts b/apps/api-credentials/src/app/verify/github.ts index c9895840..9a0721df 100644 --- a/apps/api-credentials/src/app/verify/github.ts +++ b/apps/api-credentials/src/app/verify/github.ts @@ -40,16 +40,16 @@ verifyGithubApp.get( } let credential: VerifiableCredential; - try { credential = await createCredential({ credentialSubject: { id: did, platform: 'github', - platformUserId: user.id, + platformUserId: user.id.toString(), handle: `@${user.login}`, verifiedAt: new Date().toISOString(), platformProfileUrl: `https://github.com/${user.login}`, + platformProfileImageUrl: user.avatar_url, }, }); const issuer = diff --git a/apps/api-credentials/src/app/verify/x.ts b/apps/api-credentials/src/app/verify/x.ts index fa31c004..3ccdadf9 100644 --- a/apps/api-credentials/src/app/verify/x.ts +++ b/apps/api-credentials/src/app/verify/x.ts @@ -50,6 +50,7 @@ verifyXApp.get( handle: `@${user.username}`, verifiedAt: new Date().toISOString(), platformProfileUrl: `https://x.com/${user.username}`, + platformProfileImageUrl: user.profile_image_url, }, }); diff --git a/apps/api-credentials/src/lib/veramo/actions/create-credential.ts b/apps/api-credentials/src/lib/veramo/actions/create-credential.ts index 7d14f462..b4cd2b37 100644 --- a/apps/api-credentials/src/lib/veramo/actions/create-credential.ts +++ b/apps/api-credentials/src/lib/veramo/actions/create-credential.ts @@ -1,9 +1,17 @@ import { alias, veramoAgent } from '../agent.js'; +type Platform = 'x' | 'github' | 'discord'; + type CreateCredentialParams = { - // TODO: Process credential correctly - // biome-ignore lint/suspicious/noExplicitAny: any - credentialSubject: any; + credentialSubject: { + id: string; + platform: Platform; + platformUserId: string; + handle: string; + verifiedAt: string; + platformProfileUrl: string; + platformProfileImageUrl: string | undefined; + }; }; export async function createCredential({ credentialSubject, diff --git a/apps/api-credentials/src/scripts/create-identifier.ts b/apps/api-credentials/src/scripts/create-identifier.ts new file mode 100644 index 00000000..57a4f14f --- /dev/null +++ b/apps/api-credentials/src/scripts/create-identifier.ts @@ -0,0 +1,11 @@ +import { createIdentifier } from '../lib/veramo/actions/create-identifier.js'; + +async function main() { + const identifier = await createIdentifier(); + console.log('New identifier created'); + console.log(JSON.stringify(identifier, null, 2)); +} + +(async () => { + await main(); +})();