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 all commits
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
43 changes: 39 additions & 4 deletions apps/envited.ascs.digital/common/asset/createTokenMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { TOKEN_TAGS } from '../constants/tokenTags'
import domainMetadata from '../fixtures/domainMetadata.json'
import manifest from '../fixtures/manifest.json'
import manifestLicenseRefCustomCommercialAgreement from '../fixtures/manifestLicenseRefCustomCommercialAgreement.json'
import manifestLicenseRefPolicySmartContract from '../fixtures/manifestLicenseRefPolicySmartContract.json'
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 () => {
Expand All @@ -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'],
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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'],
Expand Down
16 changes: 13 additions & 3 deletions apps/envited.ascs.digital/common/asset/createTokenMetadata.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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'],
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('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)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions apps/envited.ascs.digital/common/constants/tokenTags.ts
Original file line number Diff line number Diff line change
@@ -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',
}
Loading