Skip to content

Commit a063a72

Browse files
authored
Merge pull request #1 from block-core/profile-metadata
Attach nostr metadata as profile to didDocumentMetdata
2 parents 7fc557f + b84ee5d commit a063a72

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/resolver.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class BlockcoreDidResolver {
2929

3030
const pool = new SimplePool();
3131
const services = [] as any[];
32+
let profile = null;
3233

3334
const metadata = await pool.get(this.#relays, {
3435
kinds: [kinds.Metadata],
@@ -43,8 +44,8 @@ export class BlockcoreDidResolver {
4344
pool.close(this.#relays);
4445

4546
if (metadata?.content) {
46-
const metadataObject = JSON.parse(metadata.content);
47-
const website = metadataObject.website;
47+
profile = JSON.parse(metadata.content);
48+
const website = profile.website;
4849

4950
if (website) {
5051
services.push({
@@ -55,7 +56,7 @@ export class BlockcoreDidResolver {
5556
}
5657

5758
// TODO: Is there any use putting NIP05 in DID Document?
58-
// const nip05 = metadataObject.nip05;
59+
// const nip05 = profile.nip05;
5960
// if (nip05) {
6061
// services.push({
6162
// id: `${parsed.did}#nip05`,
@@ -86,7 +87,10 @@ export class BlockcoreDidResolver {
8687
retrieved: new Date().toISOString(),
8788
},
8889
didDocumentMetadata: {
90+
created: profile?.created_at,
91+
updated: profile?.created_at,
8992
deactivated: false, // TODO: Check if the key is deactivated.
93+
profile
9094
},
9195
};
9296

test/identity.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ test('Create the resolver', async t => {
2626

2727
t.assert(didResolution.didDocument.verificationMethod[0].publicKeyMultibase == 'z6DtPPzVD8nXDKTHG3x8cx8UpoVP6VSBsXaDhSWcoysUnkEY');
2828
t.assert(didResolution.didDocument.service[0].serviceEndpoint == 'https://sondreb.com');
29+
t.assert(didResolution.didDocumentMetadata.profile !== null);
30+
t.assert(didResolution.didDocumentMetadata.profile.name == 'sondreb');
2931

3032
didResolution = await resolver.resolve('null');
3133
t.assert(didResolution.didResolutionMetadata.error == 'invalidDid');
@@ -53,4 +55,6 @@ test('Verify relay without profile or relay list', async t => {
5355

5456
t.assert(didResolution.didDocument.verificationMethod[0].publicKeyMultibase == 'z6DtPPzVD8nXDKTHG3x8cx8UpoVP6VSBsXaDhSWcoysUnkEY');
5557
t.assert(didResolution.didDocument.service.length == 0);
58+
59+
t.assert(didResolution.didDocumentMetadata.profile == null);
5660
});

0 commit comments

Comments
 (0)