Skip to content

Commit

Permalink
WIP: store CameraSource in Proof
Browse files Browse the repository at this point in the history
  • Loading branch information
sultanmyrza committed Nov 22, 2023
1 parent a5886be commit a47617a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/app/shared/collector/collector.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ export class CollectorService {
async run(assets: Assets, capturedTimestamp: number, source: CameraSource) {
const truth = await this.collectTruth(assets, capturedTimestamp);
const proof = await Proof.from(this.mediaStore, assets, truth);
await this.generateSignature(proof, source);
proof.cameraSource = source;
await this.generateSignature(proof, proof.cameraSource);
proof.isCollected = true;
return proof;
}

// FIXME: @sultanmyrza get cameraSource from proof.cameraSource instead of passing separately
// TODO: @sultanmyrza remove 2nd parameter and make sure all other places get called accordinglyt
async generateSignature(proof: Proof, source: CameraSource) {
const recorder =
CaptureAppWebCryptoApiSignatureProvider.recorderFor(source);
const recorder = CaptureAppWebCryptoApiSignatureProvider.recorderFor(
proof.cameraSource
);
const proofMetadata = await proof.generateProofMetadata(recorder);
const { signatures, integritySha } = await this.signProofMetadata(
proofMetadata,
Expand Down
10 changes: 10 additions & 0 deletions src/app/shared/repositories/proof/proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export class Proof {

integritySha?: string = undefined;

/**
* Since capture cam originally capture photos/videos from camera we set cameraSource to
* CameraSource.Camera by default. If user picks photo/video from galley then cameraSource
* should be changed to CameraSource.Photos
*/
cameraSource: CameraSource = CameraSource.Camera;

get timestamp() {
return this.truth.timestamp;
}
Expand Down Expand Up @@ -116,6 +123,7 @@ export class Proof {
proof.isCollected = indexedProofView.isCollected ?? false;
proof.signatureVersion = indexedProofView.signatureVersion;
proof.integritySha = indexedProofView.integritySha;
proof.cameraSource = indexedProofView.cameraSource;
return proof;
}

Expand Down Expand Up @@ -285,6 +293,7 @@ export class Proof {
diaBackendAssetId: this.diaBackendAssetId,
isCollected: this.isCollected,
integritySha: this.integritySha,
cameraSource: this.cameraSource,
};
}

Expand Down Expand Up @@ -418,6 +427,7 @@ export interface IndexedProofView extends Tuple {
readonly diaBackendAssetId?: string;
readonly isCollected?: boolean;
readonly integritySha?: string;
readonly cameraSource: CameraSource;
}

/**
Expand Down

0 comments on commit a47617a

Please sign in to comment.