Skip to content

Commit

Permalink
feat(src/numbers_c2pa/core.py): update create_c2pa_manifest to includ…
Browse files Browse the repository at this point in the history
…e asset tree info and better capture details

Signed-off-by: James Chien <[email protected]>
  • Loading branch information
shc261392 committed Jun 10, 2024
1 parent 51a2854 commit e02600a
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions src/numbers_c2pa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import subprocess # nosec
from datetime import datetime
from decimal import Decimal
from tempfile import TemporaryDirectory
from typing import Any, Dict, List, Optional

Expand Down Expand Up @@ -52,16 +53,24 @@ def create_c2pa_manifest(
creator_public_key: str,
asset_hash: str,
date_created: datetime,
location_created: str,
date_captured: Optional[datetime],
latitude: Optional[str] = None,
longitude: Optional[str] = None,
date_captured: Optional[datetime] = None,
alg: str = 'es256',
ta_url: str = 'http://timestamp.digicert.com',
vendor: str = 'numbersprotocol',
claim_generator: str = 'Numbers_Protocol',
digital_source_type: Optional[str] = None,
generated_by: Optional[str] = None,
asset_tree_cid: Optional[str] = None,
asset_tree_sha256: Optional[str] = None,
asset_tree_signature: Optional[str] = None,
committer: Optional[str] = None,
):
captureTimestamp = date_captured.timestamp() if date_captured else None
capture_timestamp = date_captured.timestamp() if date_captured else None
datetime_origianl = date_captured.strftime('%Y-%m-%dT%H:%M:%SZ') if date_captured else None
formattedLatitude = f'{Decimal(latitude):.12f}' if latitude else None
formattedLongitude = f'{Decimal(longitude):.12f}' if longitude else None
manifest = {
'alg': alg,
'ta_url': ta_url,
Expand All @@ -74,14 +83,15 @@ def create_c2pa_manifest(
'data': {
'@context': 'https://schema.org',
'@type': 'CreativeWork',
'url': f'https://verify.numbersprotocol.io/asset-profile/{nid}',
'author': [
{
'@type': 'Person',
'name': creator_public_key,
}
],
'dateCreated': date_created.strftime('%Y-%m-%dT%H:%M:%SZ'),
'locationCreated': location_created,
'locationCreated': f'{formattedLatitude}, {formattedLongitude}' if latitude and longitude else None,
'identifier': nid,
}
},
Expand All @@ -95,15 +105,42 @@ def create_c2pa_manifest(
],
}
},
{
'label': 'numbers.assetTree',
'data': {
'assetTreeCid': asset_tree_cid,
'assetTreeSha256': asset_tree_sha256,
'assetTreeSignature': asset_tree_signature,
'committer': committer,
}
},
{
'label': 'numbers.integrity.json',
'data': {
'nid': nid,
'publicKey': creator_public_key,
'mediaHash': asset_hash,
'captureTimestamp': captureTimestamp,
'captureTimestamp': capture_timestamp,
}
}
},
{
'label': 'stds.exif',
'data': {
'@context': {
'EXIF': 'http://ns.adobe.com/EXIF/1.0/',
'EXIFEX': 'http://cipa.jp/EXIF/2.32/',
'dc': 'http://purl.org/dc/elements/1.1/',
'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'tiff': 'http://ns.adobe.com/tiff/1.0/',
'xmp': 'http://ns.adobe.com/xap/1.0/'
},
'EXIF:GPSLatitude': formattedLatitude,
'EXIF:GPSLongitude': formattedLongitude,
"EXIF:GPSTimeStamp": datetime_origianl,
'EXIF:DateTimeOriginal': datetime_origianl,
},
'kind': 'Json'
},
]
}
if digital_source_type:
Expand Down

0 comments on commit e02600a

Please sign in to comment.