Skip to content

Commit c198221

Browse files
authored
Merge pull request #274 from contentauth/link-action-ingr
docs for linking actions and ingredients
2 parents 6c78134 + f24479d commit c198221

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

docs/manifest/writing/ingredients.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,68 @@ When ingredients are added, the SDK validates their Content Credentials (if any)
7070
Ingredient certificates are validated when they are added to the manifest store, NOT during validation of the composed asset.
7171
:::
7272

73+
## Linking actions and ingredients
74+
75+
To link an action and an ingredient, reuse the ingredient ID in the action's `ingredientsId` array when building the manifest. The examples given here are for Python, but the same technique works in any language.
76+
77+
This example and others are in the Python library:
78+
79+
- [An ingredient with a `c2pa.opened` action](https://github.com/contentauth/c2pa-python/blob/main/tests/test_unit_tests.py#L2927).
80+
- [An ingredient with one `c2pa.opened` and one `c2pa.placed` action](https://github.com/contentauth/c2pa-python/blob/main/tests/test_unit_tests.py#L3011).
81+
- [Multiple ingredients with `c2pa.placed` action](https://github.com/contentauth/c2pa-python/blob/main/tests/test_unit_tests.py#L3117).
82+
83+
First, get an ID for the ingredient; [for example](https://github.com/contentauth/c2pa-python/blob/main/tests/test_unit_tests.py#L2934):
84+
85+
```python
86+
parent_ingredient_id = "xmp:iid:a965983b-36fb-445a-aa80-a2d911dcc53c"
87+
```
88+
89+
Use that ID when the manifest gets defined in an `ingredientsId` array; [for example](https://github.com/contentauth/c2pa-python/blob/main/tests/test_unit_tests.py#L2958):
90+
91+
```json
92+
...
93+
"assertions": [
94+
{
95+
"label": "c2pa.actions.v2",
96+
"data": {
97+
"actions": [
98+
{
99+
"action": "c2pa.opened",
100+
"softwareAgent": {
101+
"name": "Opened asset",
102+
},
103+
"parameters": {
104+
"ingredientIds": [
105+
parent_ingredient_id
106+
]
107+
},
108+
...
109+
```
110+
111+
Then the SDK links the ingredient with the action.
112+
113+
This also works with an ingredient JSON with the "add ingredient" function; [for example](https://github.com/contentauth/c2pa-python/blob/main/tests/test_unit_tests.py#L2971-L2985):
114+
115+
```python
116+
ingredient_json = {
117+
"relationship": "parentOf",
118+
"instance_id": parent_ingredient_id
119+
}
120+
# An opened ingredient is always a parent--exactly one parent ingredient is allowed.
121+
122+
# Read the input file (A.jpg will be signed)
123+
with open(self.testPath2, "rb") as test_file:
124+
file_content = test_file.read()
125+
126+
builder = Builder.from_json(manifestDefinition)
127+
128+
# Add C.jpg as the parent "opened" ingredient
129+
with open(self.testPath, 'rb') as f:
130+
builder.add_ingredient(ingredient_json, "image/jpeg", f)
131+
...
132+
```
133+
134+
135+
136+
73137

0 commit comments

Comments
 (0)