Replace typescript compiler with native tsgo compiler

This commit is contained in:
Jamie
2026-03-17 14:38:10 -07:00
committed by GitHub
parent 3851a3905a
commit 023ae37492
207 changed files with 1819 additions and 1270 deletions

View File

@@ -7,45 +7,45 @@
import { Buffer } from 'buffer';
export class Bytes {
public fromBase64(value: string): Uint8Array {
public fromBase64(value: string): Uint8Array<ArrayBuffer> {
return Buffer.from(value, 'base64');
}
public fromBase64url(value: string): Uint8Array {
public fromBase64url(value: string): Uint8Array<ArrayBuffer> {
return Buffer.from(value, 'base64url');
}
public fromHex(value: string): Uint8Array {
public fromHex(value: string): Uint8Array<ArrayBuffer> {
return Buffer.from(value, 'hex');
}
// TODO(indutny): deprecate it
public fromBinary(value: string): Uint8Array {
public fromBinary(value: string): Uint8Array<ArrayBuffer> {
return Buffer.from(value, 'binary');
}
public fromString(value: string): Uint8Array {
public fromString(value: string): Uint8Array<ArrayBuffer> {
return Buffer.from(value);
}
public toBase64(data: Uint8Array): string {
public toBase64(data: Uint8Array<ArrayBuffer>): string {
return Buffer.from(data).toString('base64');
}
public toBase64url(data: Uint8Array): string {
public toBase64url(data: Uint8Array<ArrayBuffer>): string {
return Buffer.from(data).toString('base64url');
}
public toHex(data: Uint8Array): string {
public toHex(data: Uint8Array<ArrayBuffer>): string {
return Buffer.from(data).toString('hex');
}
// TODO(indutny): deprecate it
public toBinary(data: Uint8Array): string {
public toBinary(data: Uint8Array<ArrayBuffer>): string {
return Buffer.from(data).toString('binary');
}
public toString(data: Uint8Array): string {
public toString(data: Uint8Array<ArrayBuffer>): string {
return Buffer.from(data).toString();
}
@@ -53,24 +53,28 @@ export class Bytes {
return Buffer.byteLength(value);
}
public concatenate(list: ReadonlyArray<Uint8Array>): Uint8Array {
public concatenate(
list: ReadonlyArray<Uint8Array<ArrayBuffer>>
): Uint8Array<ArrayBuffer> {
return Buffer.concat(list);
}
public isEmpty(data: Uint8Array | null | undefined): boolean {
public isEmpty(data: Uint8Array<ArrayBuffer> | null | undefined): boolean {
if (!data) {
return true;
}
return data.length === 0;
}
public isNotEmpty(data: Uint8Array | null | undefined): data is Uint8Array {
public isNotEmpty(
data: Uint8Array<ArrayBuffer> | null | undefined
): data is Uint8Array<ArrayBuffer> {
return !this.isEmpty(data);
}
public areEqual(
a: Uint8Array | null | undefined,
b: Uint8Array | null | undefined
a: Uint8Array<ArrayBuffer> | null | undefined,
b: Uint8Array<ArrayBuffer> | null | undefined
): boolean {
if (!a || !b) {
return !a && !b;
@@ -79,7 +83,7 @@ export class Bytes {
return Buffer.compare(a, b) === 0;
}
public readBigUint64BE(value: Uint8Array): bigint {
public readBigUint64BE(value: Uint8Array<ArrayBuffer>): bigint {
const buffer = Buffer.from(value);
return buffer.readBigUint64BE();
}

View File

@@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
import { Buffer } from 'node:buffer';
import type { Decipher } from 'node:crypto';
import type { Decipheriv } from 'node:crypto';
import crypto from 'node:crypto';
import { strictAssert } from '../util/assert.std.js';
@@ -12,14 +12,20 @@ import { CipherType } from '../types/Crypto.std.js';
const AUTH_TAG_SIZE = 16;
export class Crypto {
public sign(key: Uint8Array, data: Uint8Array): Uint8Array {
public sign(
key: Uint8Array<ArrayBuffer>,
data: Uint8Array<ArrayBuffer>
): Uint8Array<ArrayBuffer> {
return crypto
.createHmac('sha256', Buffer.from(key))
.update(Buffer.from(data))
.digest();
}
public hash(type: HashType, data: Uint8Array): Uint8Array {
public hash(
type: HashType,
data: Uint8Array<ArrayBuffer>
): Uint8Array<ArrayBuffer> {
return crypto.createHash(type).update(Buffer.from(data)).digest();
}
@@ -31,12 +37,12 @@ export class Crypto {
iv,
aad,
}: Readonly<{
key: Uint8Array;
plaintext: Uint8Array;
iv: Uint8Array;
aad?: Uint8Array;
key: Uint8Array<ArrayBuffer>;
plaintext: Uint8Array<ArrayBuffer>;
iv: Uint8Array<ArrayBuffer>;
aad?: Uint8Array<ArrayBuffer>;
}>
): Uint8Array {
): Uint8Array<ArrayBuffer> {
if (cipherType === CipherType.AES256GCM) {
const gcm = crypto.createCipheriv(
cipherType,
@@ -76,13 +82,13 @@ export class Crypto {
iv,
aad,
}: Readonly<{
key: Uint8Array;
ciphertext: Uint8Array;
iv: Uint8Array;
aad?: Uint8Array;
key: Uint8Array<ArrayBuffer>;
ciphertext: Uint8Array<ArrayBuffer>;
iv: Uint8Array<ArrayBuffer>;
aad?: Uint8Array<ArrayBuffer>;
}>
): Uint8Array {
let decipher: Decipher;
): Uint8Array<ArrayBuffer> {
let decipher: Decipheriv;
let input = Buffer.from(ciphertext);
if (cipherType === CipherType.AES256GCM) {
const gcm = crypto.createDecipheriv(
@@ -123,11 +129,14 @@ export class Crypto {
return crypto.randomInt(min, max);
}
public getRandomBytes(size: number): Uint8Array {
public getRandomBytes(size: number): Uint8Array<ArrayBuffer> {
return crypto.randomBytes(size);
}
public constantTimeEqual(left: Uint8Array, right: Uint8Array): boolean {
public constantTimeEqual(
left: Uint8Array<ArrayBuffer>,
right: Uint8Array<ArrayBuffer>
): boolean {
return crypto.timingSafeEqual(Buffer.from(left), Buffer.from(right));
}
}