Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/typescript-rewrite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@evervault/sdk": major
---

Rewrite the SDK in TypeScript. The package now ships a compiled `dist/` bundle with dual ESM and CommonJS entry points plus bundled type declarations (built with `tsup`), replacing the previously shipped JavaScript source and the `tsc`-generated `types/` directory.

The public API is unchanged: `require('@evervault/sdk')` still returns the `EvervaultClient` class, `import Evervault from '@evervault/sdk'` works for ESM consumers, and every client method keeps the same signature and runtime behaviour (including the on-the-wire encryption formats). This is released as a major version only because the package's internal file layout and `exports` map changed, which can affect consumers that imported internal file paths directly.
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: ['javascript']
language: ['javascript-typescript']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

Expand All @@ -42,7 +42,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -55,7 +55,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -68,6 +68,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: '/language:${{matrix.language}}'
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm run lint
- run: pnpm run typecheck
- run: pnpm run build
- run: pnpm run test:coverage
- run: |
sudo apt-get update ; sudo apt-get install -y libfaketime
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
types
.direnv

# Compiled JS emitted from lib/*.ts for running the test suite under plain Node
lib/**/*.js
lib/**/*.js.map

# Logs
logs
*.log
Expand Down
3 changes: 3 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"timeout": 30000
}
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist
node_modules
coverage
pnpm-lock.yaml
lib/**/*.js
lib/**/*.js.map
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ tabWidth: 2
semi: true
singleQuote: true
bracketSpacing: true
jsxBracketSameLine: false
arrowParens: 'always'
insertPragma: false
8 changes: 5 additions & 3 deletions lib/config.js → lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { version } = require('../package.json');
import { version } from '../package.json';
import type { MasterConfig } from './types';

const DEFAULT_API_URL = 'https://api.evervault.com';
const DEFAULT_TUNNEL_HOSTNAME = 'https://relay.evervault.com:443';
Expand All @@ -9,8 +10,7 @@ const DEFAULT_MAX_FILE_SIZE_IN_MB = 25;
const DEFAULT_ATTEST_POLL_INTERVAL = 120;
const DEFAULT_PCR_PROVIDER_POLL_INTERVAL = 60;

/** @type {import('./types').MasterConfig} */
module.exports = {
const config: MasterConfig = {
http: {
baseUrl: process.env.EV_API_URL || DEFAULT_API_URL,
userAgent: `evervault-node/${version}`,
Expand Down Expand Up @@ -61,3 +61,5 @@ module.exports = {
},
},
};

export = config;
32 changes: 24 additions & 8 deletions lib/core/attestationDoc.js → lib/core/attestationDoc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
const RepeatedTimer = require('./repeatedTimer');
import RepeatedTimer from './repeatedTimer';
import type { HttpClient } from './http';
import type { MasterConfig } from '../types';

class AttestationDoc {
constructor(config, http, enclaves, appUuid, hostname) {
appUuid: string;
http: HttpClient;
enclaves: string[];
config: MasterConfig;
polling: ReturnType<typeof RepeatedTimer> | null;
attestationDocCache: Record<string, string> | null;
hostname: string;

constructor(
config: MasterConfig,
http: HttpClient,
enclaves: string[],
appUuid: string,
hostname: string
) {
this.appUuid = appUuid.replace(/_/g, '-');
this.http = http;
this.enclaves = enclaves;
Expand All @@ -25,21 +41,21 @@ class AttestationDoc {
return null;
};

loadAttestationDoc = async (name) => {
loadAttestationDoc = async (name: string) => {
try {
const response = await this.http.getAttestationDoc(
name,
this.appUuid,
this.hostname
);
this.attestationDocCache[name] = response.attestation_doc;
this.attestationDocCache![name] = response.attestation_doc;
} catch (e) {
console.warn(`Couldn't load attestation doc for ${name} ${e}`);
}
};

get = (name) => {
const doc = this.attestationDocCache[name];
get = (name: string) => {
const doc = this.attestationDocCache![name];
if (!doc) {
console.warn(`No attestation doc found for ${name}`);
}
Expand All @@ -65,10 +81,10 @@ class AttestationDoc {
_getAttestationDocs = async () => {
await Promise.all(
this.enclaves.map(async (name) => {
await this.loadAttestationDoc(name, this.appUuid);
await this.loadAttestationDoc(name);
})
);
};
}

module.exports = AttestationDoc;
export default AttestationDoc;
Loading