Skip to content

Commit

Permalink
chore: Add README for common package
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed Aug 16, 2024
1 parent 797fa6d commit 82cb39e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
85 changes: 85 additions & 0 deletions packages/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# @peculiar/attestation-common

A common module providing tools and interfaces for verifying HSM attestation files from various HSMs, including support for certificate chain validation and attestation data extraction.

## Installation

To install the library, use npm:

```sh
npm install @peculiar/attestation-common
```

## Usage

This example demonstrates how to use the common attestation interfaces and types:

```typescript
import { X509Certificate, PublicKey } from "@peculiar/x509";
import {
Attestation,
AttestationVerificationParams,
AttestationVerificationResult,
AttestationProvider,
} from "@peculiar/attestation-common";

// Example implementation of an AttestationProvider
class ExampleAttestationProvider implements AttestationProvider {
format = "example";

async read(data: BufferSource): Promise<Attestation> {
// Implement the logic to read attestation data
return {
format: this.format,
publicKey: new PublicKey(/* public key data */),
metadata: {
/* metadata */
},
};
}

async verify(
params: AttestationVerificationParams
): Promise<AttestationVerificationResult> {
// Implement the logic to verify attestation data
return {
status: true,
chain: params.intermediateCerts,
signer: params.intermediateCerts[0],
};
}
}

// Example usage
const provider = new ExampleAttestationProvider();

// Example attestation data and certificate chain data
const attestationData = new Uint8Array([
/* attestation data bytes */
]);
const certChainPem = `-----BEGIN CERTIFICATE-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7V1...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7V1...
-----END CERTIFICATE-----`;

// Read the attestation data
const attestation = await provider.read(attestationData);

// Decode the certificate chain
const certBlobs = x509.PemConverter.decode(certChainPem);
const certs = certBlobs.map((blob) => new x509.X509Certificate(blob));

// Verify the attestation using the provided certificate chain
const result = await provider.verify({
attestation,
intermediateCerts: certs,
});

console.log(result);
```

## License

This project is licensed under the MIT License.
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@peculiar/attestation-common",
"version": "1.0.0",
"description": "Common module for attestation packages",
"description": "A common module providing tools and interfaces for verifying HSM attestation files.",
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"types": "build/types/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { X509Certificate, PublicKey } from '@peculiar/x509';

export interface Attestation<T = any> {
format: string;
publicKey: PublicKey;
Expand Down

0 comments on commit 82cb39e

Please sign in to comment.