Skip to content

Commit

Permalink
Merge pull request #2 from numbersprotocol/feature-verifiable-data
Browse files Browse the repository at this point in the history
Add more verifiable data
  • Loading branch information
shc261392 authored Jun 12, 2024
2 parents 51a2854 + 9997444 commit 785fa1e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ disable=
too-few-public-methods,
too-many-public-methods,
too-many-arguments,
too-many-locals,
unspecified-encoding,

[flake8]
Expand Down
61 changes: 55 additions & 6 deletions src/numbers_c2pa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import os
import subprocess # nosec
from datetime import datetime
from decimal import Decimal
from tempfile import TemporaryDirectory
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Union

import requests

Expand All @@ -18,6 +19,18 @@ def _mimetype_to_ext(asset_mime_type: str):
return ext


def format_datetime(date: Optional[datetime], to_timestamp=False) -> Optional[Union[str, int]]:
if not date:
return None
if to_timestamp:
return int(date.timestamp())
return date.strftime('%Y-%m-%dT%H:%M:%SZ')


def format_geolocation(value: Optional[str]) -> Optional[str]:
return f'{Decimal(value):.12f}' if value else None


def c2patool_inject(
file_path: str,
manifest_path: str,
Expand Down Expand Up @@ -52,16 +65,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
location_created = (
f'{format_geolocation(latitude)}, {format_geolocation(longitude)}'
if latitude and longitude else None
)
manifest = {
'alg': alg,
'ta_url': ta_url,
Expand All @@ -74,6 +95,7 @@ def create_c2pa_manifest(
'data': {
'@context': 'https://schema.org',
'@type': 'CreativeWork',
'url': f'https://verify.numbersprotocol.io/asset-profile/{nid}',
'author': [
{
'@type': 'Person',
Expand All @@ -95,15 +117,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': format_datetime(date_captured, to_timestamp=True),
}
}
},
{
'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': format_geolocation(latitude),
'EXIF:GPSLongitude': format_geolocation(longitude),
"EXIF:GPSTimeStamp": format_datetime(date_captured),
'EXIF:DateTimeOriginal': format_datetime(date_captured),
},
'kind': 'Json'
},
]
}
if digital_source_type:
Expand Down

0 comments on commit 785fa1e

Please sign in to comment.