Skip to content

Commit

Permalink
use @tufjs/canonical-json in @tufjs/models (#279)
Browse files Browse the repository at this point in the history
Signed-off-by: Brian DeHamer <bdehamer@github.com>
  • Loading branch information
bdehamer committed Apr 11, 2023
1 parent 39befcd commit 4e4f6e9
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 74 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-wasps-check.md
@@ -0,0 +1,5 @@
---
'@tufjs/models': patch
---

Integrate @tufjs/canonical-json library
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/models/package.json
Expand Up @@ -33,7 +33,8 @@
"typescript": "^5.0.4"
},
"dependencies": {
"minimatch": "^8.0.3"
"minimatch": "^8.0.3",
"@tufjs/canonical-json": "1.0.0"
},
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
Expand Down
10 changes: 0 additions & 10 deletions packages/models/src/__tests__/utils/json.test.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/models/src/metadata.ts
@@ -1,3 +1,4 @@
import { canonicalize } from '@tufjs/canonical-json';
import util from 'util';
import { MetadataKind, Signable } from './base';
import { UnsignedMetadataError, ValueError } from './error';
Expand All @@ -8,8 +9,7 @@ import { Signature } from './signature';
import { Snapshot } from './snapshot';
import { Targets } from './targets';
import { Timestamp } from './timestamp';
import { guard, JSONObject, JSONValue } from './utils';
import { canonicalize } from './utils/json';
import { JSONObject, JSONValue, guard } from './utils';

type MetadataType = Root | Timestamp | Snapshot | Targets;

Expand Down Expand Up @@ -53,7 +53,7 @@ export class Metadata<T extends MetadataType> implements Signable {
}

public sign(signer: (data: Buffer) => Signature, append = true): void {
const bytes = canonicalize(this.signed.toJSON());
const bytes = Buffer.from(canonicalize(this.signed.toJSON()));
const signature = signer(bytes);

if (!append) {
Expand Down
58 changes: 0 additions & 58 deletions packages/models/src/utils/json.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/models/src/utils/verify.ts
@@ -1,13 +1,13 @@
import { canonicalize } from '@tufjs/canonical-json';
import crypto from 'crypto';
import { JSONObject } from '../utils/types';
import { canonicalize } from './json';

export const verifySignature = (
metaDataSignedData: JSONObject,
key: crypto.VerifyKeyObjectInput,
signature: string
): boolean => {
const canonicalData = canonicalize(metaDataSignedData) || '';
const canonicalData = Buffer.from(canonicalize(metaDataSignedData));

return crypto.verify(
undefined,
Expand Down

0 comments on commit 4e4f6e9

Please sign in to comment.