Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add tag NFT token metadata restricted assets #396

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('common/asset/createTokenMetadata', () => {
isBooleanAmount: true,
name: 'TestfeldNiedersachsen_ALKS_ODR_sample',
description: 'simple hdmap example file on Testfeld Niedersachsen for ALKS scenario',
tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', 'ASAM OpenDRIVE 1.6'],
tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', 'ASAM OpenDRIVE 1.6', 'containsAccessRestrictedLinks'],
minter: 'MINTER',
creators: ['CREATOR'],
publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'],
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('common/asset/createTokenMetadata', () => {
isBooleanAmount: true,
name: 'TestfeldNiedersachsen_ALKS_ODR_sample',
description: 'simple hdmap example file on Testfeld Niedersachsen for ALKS scenario',
tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', 'ASAM OpenDRIVE 1.6'],
tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', 'ASAM OpenDRIVE 1.6', 'containsAccessRestrictedLinks'],
jdsika marked this conversation as resolved.
Show resolved Hide resolved
minter: 'MINTER',
creators: ['CREATOR'],
publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'],
Expand Down
8 changes: 5 additions & 3 deletions apps/envited.ascs.digital/common/asset/createTokenMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { equals } from 'ramda'
import { append, equals } from 'ramda'

import { extractFilenameFromPath, formatAssetUri, formatIpfsUri } from './createTokenMetadata.utils'
import { Manifest } from './types'
import { formatManifestLinkPath } from './validateAndCreateMetadata.utils'
import { formatManifestLinkPath, hasManifestAccessRestrictedLinks } from './validateAndCreateMetadata.utils'

export const createTokenMetadata = ({
asset,
Expand Down Expand Up @@ -44,13 +44,15 @@ export const createTokenMetadata = ({
const version = domainMetadata.data['hdmap:format']['hdmap:version']['@value']
const today = new Date()
const date = today.toISOString().split('T')[0]
const tags = ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', `${formatType} ${version}`]
const hasAccessRestrictedLinks = hasManifestAccessRestrictedLinks(manifest.data)

return {
decimals: 0,
isBooleanAmount: true,
name,
description,
tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', `${formatType} ${version}`],
tags: hasAccessRestrictedLinks ? append('containsAccessRestrictedLinks')(tags) : tags,
minter,
creators: [creator],
publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import manifest from '../fixtures/manifest.json'
import manifestRemoteAssetData from '../fixtures/manifestRemoteAssetData.json'
import * as SUT from './validateAndCreateMetadata.utils'

describe('common/asset/validateAndCreateMetadata.utils', () => {
Expand Down Expand Up @@ -345,4 +346,18 @@ describe('common/asset/validateAndCreateMetadata.utils', () => {
])
})
})

describe('hasManifestAccessRestrictedLinks', () => {
it('should return true when there is a external link', () => {
const result = SUT.hasManifestAccessRestrictedLinks(manifest as any)

expect(result).toEqual(true)
})

it('should return false when there are not external links found', () => {
const result = SUT.hasManifestAccessRestrictedLinks(manifestRemoteAssetData as any)

expect(result).toEqual(true)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import * as raw from 'multiformats/codecs/raw'
import { Hasher } from 'multiformats/dist/src/hashes/hasher'
import { sha256 } from 'multiformats/hashes/sha2'
import {
any,
append,
concat,
equals,
find,
groupBy,
is,
Expand Down Expand Up @@ -92,6 +94,13 @@ export const formatManifestLinkPath = replace('./', '')

export const isRemoteUrl = startsWith('https://')

export const hasManifestAccessRestrictedLinks = (manifest: Manifest) =>
pipe(
getAllManifestLinks,
map((link: ManifestLink) => isRemoteUrl(link['manifest:path']['@value'])),
(x: boolean[]) => any(equals(true))(x),
)(manifest)

export const getPathsFromManifestLinks = (links: ManifestLink[]) =>
pipe(
map((link: ManifestLink) =>
Expand Down
Loading