Skip to content

Commit 6f34d30

Browse files
authored
feat: additional builder methods (#34)
* feat: additional builder methods * chore: changeset
1 parent db8171b commit 6f34d30

File tree

7 files changed

+64
-4
lines changed

7 files changed

+64
-4
lines changed

.changeset/busy-buckets-play.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@contentauth/c2pa-wasm': patch
3+
'@contentauth/c2pa-web': patch
4+
---
5+
6+
Add builder methods: setRemoteUrl, setNoEmbed, and setThumbnailFromBlob

packages/c2pa-wasm/src/wasm_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ impl WasmBuilder {
4646
/// The URL must return the manifest data and is injected into the destination asset when signing.
4747
/// For remote-only manifests, set the `no_embed` flag to `true`.
4848
#[wasm_bindgen(js_name = setRemoteUrl)]
49-
pub fn set_remote_url(&mut self, format: &str) {
50-
self.builder.set_remote_url(format);
49+
pub fn set_remote_url(&mut self, url: &str) {
50+
self.builder.set_remote_url(url);
5151
}
5252

5353
/// Sets the state of the no_embed flag.

packages/c2pa-web/src/lib/builder.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { describe, expect, test } from 'vitest';
1111
import { createC2pa } from './c2pa.js';
1212

13-
import wasmSrc from '@contentauth/c2pa-wasm/assets/c2pa_bg.wasm?url';
13+
import wasmSrc from '@contentauth/c2pa-web/resources/c2pa.wasm?url';
1414
import { ManifestDefinition } from '@contentauth/c2pa-types';
1515

1616
describe('builder', () => {

packages/c2pa-web/src/lib/builder.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ export interface BuilderFactory {
2828
* Exposes methods for building C2PA manifests and signing assets.
2929
*/
3030
export interface Builder {
31+
/**
32+
* Sets the remote URL for a remote manifest. The manifest is expected to be available at this location.
33+
*
34+
* @param url URL pointing to the location the remote manifest will be stored.
35+
*/
36+
setRemoteUrl: (url: string) => Promise<void>;
37+
38+
/**
39+
* Sets the state of the no_embed flag. To skip embedding a manifest (e.g. for the remote-only case) set this to `true`.
40+
*
41+
* @param noEmbed Value to set the no_embed flag.
42+
* @returns
43+
*/
44+
setNoEmbed: (noEmbed: boolean) => Promise<void>;
45+
46+
/**
47+
* Set a thumbnail from a blob to be included in the manifest. The blob should represent the asset being signed.
48+
*
49+
* @param format Format of the thumbnail
50+
* @param blob Blob of the thumbnail bytes
51+
*/
52+
setThumbnailFromBlob: (format: string, blob: Blob) => Promise<void>;
53+
3154
/**
3255
* Add an ingredient to the builder from a definition, format, and blob.
3356
* Values specified in the ingredient definition will be merged with the ingredient, and these values take precendence.
@@ -103,6 +126,18 @@ function createBuilder(
103126
const { tx } = worker;
104127

105128
return {
129+
async setRemoteUrl(url) {
130+
await tx.builder_setRemoteUrl(id, url);
131+
},
132+
133+
async setNoEmbed(noEmbed) {
134+
await tx.builder_setNoEmbed(id, noEmbed);
135+
},
136+
137+
async setThumbnailFromBlob(format, blob) {
138+
await tx.builder_setThumbnailFromBlob(id, format, blob);
139+
},
140+
106141
async addIngredientFromBlob(
107142
ingredientDefinition: Ingredient,
108143
format: string,

packages/c2pa-web/src/lib/reader.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { describe, expect, test } from 'vitest';
1111
import { createC2pa } from './c2pa.js';
1212
import { Settings } from './settings.js';
13-
import wasmSrc from '@contentauth/c2pa-wasm/assets/c2pa_bg.wasm?url';
13+
import wasmSrc from '@contentauth/c2pa-web/resources/c2pa.wasm?url';
1414

1515
import C_with_CAWG_data from '../../test/fixtures/assets/C_with_CAWG_data.jpg';
1616
import C_with_CAWG_data_thumbnail from '../../test/fixtures/assets/C_with_CAWG_data_thumbnail.jpg';

packages/c2pa-web/src/lib/worker.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ rx({
7272
const builderId = builderMap.add(builder);
7373
return builderId;
7474
},
75+
builder_setRemoteUrl(builderId, url) {
76+
const builder = builderMap.get(builderId);
77+
builder.setRemoteUrl(url);
78+
},
79+
builder_setNoEmbed(builderId, noEmbed) {
80+
const builder = builderMap.get(builderId);
81+
builder.setNoEmbed(noEmbed);
82+
},
83+
builder_setThumbnailFromBlob(builderId, format, blob) {
84+
const builder = builderMap.get(builderId);
85+
builder.setThumbnailFromBlob(format, blob);
86+
},
7587
builder_addIngredientFromBlob(builderId, json, format, blob) {
7688
const builder = builderMap.get(builderId);
7789
builder.addIngredientFromBlob(json, format, blob);

packages/c2pa-web/src/lib/worker/rpc.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ const { createTx, rx } = channel<{
3535
builder_fromJson: (json: string) => number;
3636

3737
// Builder methods
38+
builder_setRemoteUrl: (builderId: number, url: string) => void;
39+
builder_setNoEmbed: (builderId: number, noEmbed: boolean) => void;
40+
builder_setThumbnailFromBlob: (
41+
builderId: number,
42+
format: string,
43+
blob: Blob
44+
) => void;
3845
builder_addIngredientFromBlob: (
3946
builderId: number,
4047
json: string,

0 commit comments

Comments
 (0)