diff --git a/apps/envited.ascs.digital/common/asset/createTokenMetadata.test.ts b/apps/envited.ascs.digital/common/asset/createTokenMetadata.test.ts index 6f9441f8..514d045b 100644 --- a/apps/envited.ascs.digital/common/asset/createTokenMetadata.test.ts +++ b/apps/envited.ascs.digital/common/asset/createTokenMetadata.test.ts @@ -1,3 +1,4 @@ +import { TOKEN_TAGS } from '../constants/tokenTags' import domainMetadata from '../fixtures/domainMetadata.json' import manifest from '../fixtures/manifest.json' import manifestLicenseRefCustomCommercialAgreement from '../fixtures/manifestLicenseRefCustomCommercialAgreement.json' @@ -5,6 +6,10 @@ import manifestLicenseRefPolicySmartContract from '../fixtures/manifestLicenseRe import manifestRemoteAssetData from '../fixtures/manifestRemoteAssetData.json' import * as SUT from './createTokenMetadata' +export const TEST_TOKEN_TAGS = { + ASAM_OPENDRIVE_VERSION: 'ASAM OpenDRIVE 1.6', +} + describe('common/asset/createTokenMetadata', () => { describe('createTokenMetadata', () => { it('should extract data from manifest and domainMetadata and create a token metadata object', async () => { @@ -15,7 +20,15 @@ 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: [ + TOKEN_TAGS.GAIA_X, + TOKEN_TAGS.ASCS, + TOKEN_TAGS.ENVITED_X, + TOKEN_TAGS.EVES, + TOKEN_TAGS.NFT, + TEST_TOKEN_TAGS.ASAM_OPENDRIVE_VERSION, + TOKEN_TAGS.THIRD_PARTY_HOSTED, + ], minter: 'MINTER', creators: ['CREATOR'], publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'], @@ -112,7 +125,15 @@ 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: [ + TOKEN_TAGS.GAIA_X, + TOKEN_TAGS.ASCS, + TOKEN_TAGS.ENVITED_X, + TOKEN_TAGS.EVES, + TOKEN_TAGS.NFT, + TEST_TOKEN_TAGS.ASAM_OPENDRIVE_VERSION, + TOKEN_TAGS.THIRD_PARTY_HOSTED, + ], minter: 'MINTER', creators: ['CREATOR'], publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'], @@ -209,7 +230,14 @@ 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: [ + TOKEN_TAGS.GAIA_X, + TOKEN_TAGS.ASCS, + TOKEN_TAGS.ENVITED_X, + TOKEN_TAGS.EVES, + TOKEN_TAGS.NFT, + TEST_TOKEN_TAGS.ASAM_OPENDRIVE_VERSION, + ], minter: 'MINTER', creators: ['CREATOR'], publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'], @@ -306,7 +334,14 @@ 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: [ + TOKEN_TAGS.GAIA_X, + TOKEN_TAGS.ASCS, + TOKEN_TAGS.ENVITED_X, + TOKEN_TAGS.EVES, + TOKEN_TAGS.NFT, + TEST_TOKEN_TAGS.ASAM_OPENDRIVE_VERSION, + ], minter: 'MINTER', creators: ['CREATOR'], publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'], diff --git a/apps/envited.ascs.digital/common/asset/createTokenMetadata.ts b/apps/envited.ascs.digital/common/asset/createTokenMetadata.ts index b0354562..5a460ff7 100644 --- a/apps/envited.ascs.digital/common/asset/createTokenMetadata.ts +++ b/apps/envited.ascs.digital/common/asset/createTokenMetadata.ts @@ -1,8 +1,9 @@ -import { equals } from 'ramda' +import { append, equals } from 'ramda' +import { TOKEN_TAGS } from '../constants/tokenTags' import { extractFilenameFromPath, formatAssetUri, formatIpfsUri } from './createTokenMetadata.utils' import { Manifest } from './types' -import { formatManifestLinkPath } from './validateAndCreateMetadata.utils' +import { formatManifestLinkPath, hasManifestThirdPartyLinks } from './validateAndCreateMetadata.utils' export const createTokenMetadata = ({ asset, @@ -44,13 +45,22 @@ 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 = [ + TOKEN_TAGS.GAIA_X, + TOKEN_TAGS.ASCS, + TOKEN_TAGS.ENVITED_X, + TOKEN_TAGS.EVES, + TOKEN_TAGS.NFT, + `${formatType} ${version}`, + ] + const isThirdPartyHosted = hasManifestThirdPartyLinks(manifest.data) return { decimals: 0, isBooleanAmount: true, name, description, - tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', `${formatType} ${version}`], + tags: isThirdPartyHosted ? append(TOKEN_TAGS.THIRD_PARTY_HOSTED)(tags) : tags, minter, creators: [creator], publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'], diff --git a/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.utils.test.ts b/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.utils.test.ts index 71c16024..9a822582 100644 --- a/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.utils.test.ts +++ b/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.utils.test.ts @@ -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', () => { @@ -345,4 +346,18 @@ describe('common/asset/validateAndCreateMetadata.utils', () => { ]) }) }) + + describe('hasManifestThirdPartyLinks', () => { + it('should return true when there is a external link', () => { + const result = SUT.hasManifestThirdPartyLinks(manifest as any) + + expect(result).toEqual(true) + }) + + it('should return false when there are not external links found', () => { + const result = SUT.hasManifestThirdPartyLinks(manifestRemoteAssetData as any) + + expect(result).toEqual(true) + }) + }) }) diff --git a/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.utils.ts b/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.utils.ts index 02f0b6a2..21698696 100644 --- a/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.utils.ts +++ b/apps/envited.ascs.digital/common/asset/validateAndCreateMetadata.utils.ts @@ -3,10 +3,13 @@ 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, + includes, is, isNil, map, @@ -91,6 +94,17 @@ export const getAllManifestLinks = (manifest: Manifest) => export const formatManifestLinkPath = replace('./', '') export const isRemoteUrl = startsWith('https://') +export const isSelfHosted = includes('.envited-x.net') + +export const hasManifestThirdPartyLinks = (manifest: Manifest) => + pipe( + getAllManifestLinks, + map( + (link: ManifestLink) => + isRemoteUrl(link['manifest:path']['@value']) && !isSelfHosted(link['manifest:path']['@value']), + ), + (x: boolean[]) => any(equals(true))(x), + )(manifest) export const getPathsFromManifestLinks = (links: ManifestLink[]) => pipe( diff --git a/apps/envited.ascs.digital/common/constants/tokenTags.ts b/apps/envited.ascs.digital/common/constants/tokenTags.ts new file mode 100644 index 00000000..86cb5a8f --- /dev/null +++ b/apps/envited.ascs.digital/common/constants/tokenTags.ts @@ -0,0 +1,8 @@ +export const TOKEN_TAGS = { + GAIA_X: 'GaiaX', + ASCS: 'ASCS', + ENVITED_X: 'ENVITED-X', + EVES: 'EVES', + NFT: 'nft', + THIRD_PARTY_HOSTED: 'Third Party Hosted', +}