Skip to content

Commit bd1e1e1

Browse files
authored
sigstore type refactoring (#550)
Signed-off-by: Brian DeHamer <bdehamer@github.com>
1 parent 24abc28 commit bd1e1e1

File tree

17 files changed

+120
-131
lines changed

17 files changed

+120
-131
lines changed

.changeset/lucky-mangos-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sigstore': patch
3+
---
4+
5+
Internal refactoring of Typescript types

packages/client/src/__tests__/__fixtures__/trust.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import * as sigstore from '../../types/sigstore';
16+
import { TrustedRoot } from '@sigstore/protobuf-specs';
17+
1718
const trustedRootJSON = {
1819
mediaType: 'application/vnd.dev.sigstore.trustedroot+json;version=0.1',
1920
tlogs: [
@@ -103,4 +104,4 @@ const trustedRootJSON = {
103104
timestampAuthorities: [],
104105
};
105106

106-
export const trustedRoot = sigstore.TrustedRoot.fromJSON(trustedRootJSON);
107+
export const trustedRoot = TrustedRoot.fromJSON(trustedRootJSON);

packages/client/src/__tests__/ca/verify/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { trustedRoot } from '../../__fixtures__/trust';
2121
describe('verifySigningCertificate', () => {
2222
// Temporary until we reconsole bundle formats
2323
const bundleJSON = bundles.dsse.valid.withSigningCert;
24-
const bundle = sigstore.Bundle.fromJSON(
24+
const bundle = sigstore.bundleFromJSON(
2525
bundleJSON
2626
) as sigstore.BundleWithCertificateChain;
2727

packages/client/src/__tests__/sigstore.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import { TUFError } from '@sigstore/tuf';
17-
import mocktuf, { Target } from '@tufjs/repo-mock';
18-
import { PolicyError, VerificationError } from '../error';
19-
import { Signer } from '../sign';
20-
import { attest, sign, tuf, verify } from '../sigstore';
2116
import {
2217
Bundle,
2318
HashAlgorithm,
2419
TimestampVerificationData,
2520
TransparencyLogEntry,
2621
TrustedRoot,
2722
X509CertificateChain,
28-
} from '../types/sigstore';
23+
} from '@sigstore/protobuf-specs';
24+
import { TUFError } from '@sigstore/tuf';
25+
import mocktuf, { Target } from '@tufjs/repo-mock';
26+
import { PolicyError, VerificationError } from '../error';
27+
import { Signer } from '../sign';
28+
import { attest, sign, tuf, verify } from '../sigstore';
2929
import bundles from './__fixtures__/bundles';
3030
import { trustedRoot } from './__fixtures__/trust';
3131

packages/client/src/__tests__/tlog/verify/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { trustedRoot } from '../../__fixtures__/trust';
2222
describe('verifyTLogEntries', () => {
2323
const bundle = sigstore.bundleFromJSON(
2424
bundles.signature.valid.withSigningCert
25-
) as sigstore.BundleWithVerificationMaterial;
25+
) as sigstore.Bundle;
2626

2727
const options: sigstore.ArtifactVerificationOptions_TlogOptions = {
2828
disable: false,
@@ -42,7 +42,7 @@ describe('verifyTLogEntries', () => {
4242
describe('when the bundle does NOT have a signing certificate', () => {
4343
const bundle = sigstore.bundleFromJSON(
4444
bundles.signature.valid.withPublicKey
45-
) as sigstore.BundleWithVerificationMaterial;
45+
) as sigstore.Bundle;
4646

4747
it('does NOT throw an error', () => {
4848
expect(() =>
@@ -83,7 +83,7 @@ describe('verifyTLogEntries', () => {
8383
describe('when tlog entries are missing data necessary for verification', () => {
8484
const bundle = sigstore.bundleFromJSON(
8585
bundles.dsse.invalid.tlogKindVersionMissing
86-
) as sigstore.BundleWithVerificationMaterial;
86+
) as sigstore.Bundle;
8787

8888
it('throws an error', () => {
8989
expect(() => verifyTLogEntries(bundle, trustedRoot, options)).toThrow(

packages/client/src/__tests__/types/sigstore/index.test.ts

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
import type { Entry } from '../../../external/rekor';
1617
import { SignatureMaterial } from '../../../types/signature';
1718
import * as sigstore from '../../../types/sigstore';
1819
import { encoding as enc, pem } from '../../../util';
1920
import bundles from '../../__fixtures__/bundles/';
2021

21-
import type { Entry } from '../../../external/rekor';
22-
23-
describe('isBundleWithVerificationMaterial', () => {
24-
describe('when the bundle contains verification material', () => {
25-
const json = bundles.dsse.valid.withSigningCert;
26-
const bundle = sigstore.Bundle.fromJSON(json);
27-
28-
it('returns true', () => {
29-
expect(sigstore.isBundleWithVerificationMaterial(bundle)).toBe(true);
30-
});
31-
});
32-
33-
describe('when the bundle does NOT contain verification material', () => {
34-
const bundle: sigstore.Bundle = {
35-
mediaType: 'application/vnd.dev.cosign.simplesigning.v1+json',
36-
verificationMaterial: undefined,
37-
content: {
38-
$case: 'messageSignature',
39-
messageSignature: {
40-
messageDigest: {
41-
algorithm: sigstore.HashAlgorithm.SHA2_256,
42-
digest: Buffer.from(''),
43-
},
44-
signature: Buffer.from(''),
45-
},
46-
},
47-
};
48-
49-
it('returns false', () => {
50-
expect(sigstore.isBundleWithVerificationMaterial(bundle)).toBe(false);
51-
});
52-
});
53-
});
54-
5522
describe('isBundleWithCertificateChain', () => {
5623
describe('when the bundle contains a certificate chain', () => {
5724
const json = bundles.dsse.valid.withSigningCert;
58-
const bundle = sigstore.Bundle.fromJSON(json);
25+
const bundle = sigstore.bundleFromJSON(json);
5926

6027
it('returns true', () => {
6128
expect(sigstore.isBundleWithCertificateChain(bundle)).toBe(true);
@@ -64,7 +31,7 @@ describe('isBundleWithCertificateChain', () => {
6431

6532
describe('when the bundle does NOT contain a certificate chain', () => {
6633
const json = bundles.dsse.valid.withPublicKey;
67-
const bundle = sigstore.Bundle.fromJSON(json);
34+
const bundle = sigstore.bundleFromJSON(json);
6835

6936
it('returns false', () => {
7037
expect(sigstore.isBundleWithCertificateChain(bundle)).toBe(false);

packages/client/src/__tests__/types/sigstore/serialized.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import {
17-
Bundle,
16+
import { Bundle, hashAlgorithmToJSON } from '@sigstore/protobuf-specs';
17+
import type {
1818
Envelope,
1919
HashAlgorithm,
20-
hashAlgorithmToJSON,
2120
MessageSignature,
2221
PublicKeyIdentifier,
2322
SerializedBundle,

packages/client/src/__tests__/types/sigstore/validate.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616
import { ValidationError } from '../../../error';
17-
import {
18-
assertValidBundle,
17+
import { assertValidBundle } from '../../../types/sigstore/validate';
18+
19+
import type {
1920
Bundle,
2021
Signature,
2122
X509Certificate,
22-
} from '../../../types/sigstore';
23+
} from '@sigstore/protobuf-specs';
2324

2425
describe('assertValidBundle', () => {
2526
describe('when the bundle is completely empty', () => {

packages/client/src/__tests__/x509/cert.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import * as sigstore from '../../types/sigstore';
16+
import { TransparencyLogInstance } from '@sigstore/protobuf-specs';
1717
import { pem } from '../../util';
1818
import { x509Certificate } from '../../x509/cert';
1919
import { certificates } from '../__fixtures__/certs';
@@ -290,8 +290,8 @@ describe('x509Certificate', () => {
290290
logId: { keyId: 'CGCS8ChS/2hF0dFrJ4ScRWcYrBY9wzjSbea8IgY2b3I=' },
291291
};
292292

293-
const logs: sigstore.TransparencyLogInstance[] = [
294-
sigstore.TransparencyLogInstance.fromJSON(ctl),
293+
const logs: TransparencyLogInstance[] = [
294+
TransparencyLogInstance.fromJSON(ctl),
295295
];
296296

297297
describe('when the certificate does NOT have an SCT extension', () => {

packages/client/src/__tests__/x509/sct.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import * as sigstore from '../../types/sigstore';
16+
import { TransparencyLogInstance } from '@sigstore/protobuf-specs';
1717
import { SignedCertificateTimestamp } from '../../x509/sct';
1818

1919
describe('SignedCertificateTimestamp', () => {
@@ -130,8 +130,8 @@ describe('SignedCertificateTimestamp', () => {
130130
logId: { keyId: Buffer.from(logID, 'hex') },
131131
};
132132

133-
const logs: sigstore.TransparencyLogInstance[] = [
134-
sigstore.TransparencyLogInstance.fromJSON(ctl),
133+
const logs: TransparencyLogInstance[] = [
134+
TransparencyLogInstance.fromJSON(ctl),
135135
];
136136

137137
describe('when the signature is valid', () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy