(imageBuffer: Buffer, assertions: C2PAAssertions)
| 128 | * already take seconds, so the added latency is in the noise. |
| 129 | */ |
| 130 | export function signC2PA(imageBuffer: Buffer, assertions: C2PAAssertions): SignC2PAResult { |
| 131 | const signer = getSigner(); |
| 132 | const mimeType = assertions.mimeType || 'image/png'; |
| 133 | |
| 134 | const builder = Builder.withJson( |
| 135 | { |
| 136 | claim_generator: assertions.claimGenerator, |
| 137 | claim_generator_info: [ |
| 138 | { |
| 139 | name: assertions.claimGenerator, |
| 140 | version: AAO_TOOL_VERSION, |
| 141 | }, |
| 142 | ], |
| 143 | title: assertions.title, |
| 144 | format: mimeType, |
| 145 | instance_id: `urn:uuid:${randomUUID()}`, |
| 146 | ingredients: [], |
| 147 | assertions: [], |
| 148 | resources: { resources: {} }, |
| 149 | }, |
| 150 | BUILDER_SETTINGS, |
| 151 | ); |
| 152 | |
| 153 | // Declare this asset as AI-generated. The library auto-adds a c2pa.created |
| 154 | // action; we additionally emit an explicit actions assertion carrying the |
| 155 | // software agent so the generator + model version is visible to verifiers. |
| 156 | builder.setIntent({ create: AI_DIGITAL_SOURCE_TYPE }); |
| 157 | |
| 158 | // JSON-kind assertions are passed as pre-serialized strings; CBOR-kind |
| 159 | // assertions accept JS objects. We use JSON here for readability in verifier UIs. |
| 160 | builder.addAssertion( |
| 161 | 'c2pa.actions', |
| 162 | JSON.stringify({ |
| 163 | actions: [ |
| 164 | { |
| 165 | action: 'c2pa.created', |
| 166 | softwareAgent: assertions.softwareAgent, |
| 167 | digitalSourceType: AI_DIGITAL_SOURCE_TYPE, |
| 168 | }, |
| 169 | ], |
| 170 | }), |
| 171 | 'Json', |
| 172 | ); |
| 173 | |
| 174 | if (assertions.attributes && Object.keys(assertions.attributes).length > 0) { |
| 175 | builder.addAssertion( |
| 176 | AAO_ASSERTION_LABEL, |
| 177 | JSON.stringify({ generator_attributes: assertions.attributes }), |
| 178 | 'Json', |
| 179 | ); |
| 180 | } |
| 181 | |
| 182 | const dest: { buffer: Buffer | null } = { buffer: null }; |
| 183 | const manifestBytes = builder.sign( |
| 184 | signer, |
| 185 | { buffer: imageBuffer, mimeType }, |
| 186 | dest, |
| 187 | ); |
no test coverage detected