Skip to content

Commit a78d923

Browse files
authored
Update to TypeScript 5.9; change from Uint8Array to Uint8Array<ArrayBuffer> (#354)
1 parent dd24681 commit a78d923

File tree

14 files changed

+51
-51
lines changed

14 files changed

+51
-51
lines changed

examples/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "MIT",
1111
"dependencies": {
1212
"@confluentinc/kafka-javascript": "file:../..",
13-
"typescript": "^5.4.4"
13+
"typescript": "^5.9.2"
1414
},
1515
"devDependencies": {
1616
"@types/node": "^20.12.5"

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"node-gyp": "^9.3.1",
5050
"nyc": "^17.1.0",
5151
"ts-jest": "^29.2.5",
52-
"typescript": "^5.5.4",
52+
"typescript": "^5.9.2",
5353
"typescript-eslint": "^8.2.0"
5454
},
5555
"dependencies": {

schemaregistry/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"mocha": "^10.7.0",
2626
"node-gyp": "^9.3.1",
2727
"ts-jest": "^29.2.4",
28-
"typescript": "^5.5.4",
28+
"typescript": "^5.9.2",
2929
"typescript-eslint": "^8.2.0"
3030
},
3131
"dependencies": {

schemaregistry/rules/encryption/encrypt-executor.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export class EncryptionExecutor implements RuleExecutor {
170170
}
171171

172172
export class Cryptor {
173-
static readonly EMPTY_AAD = Buffer.from([])
173+
static readonly EMPTY_AAD: Uint8Array<ArrayBuffer> = new Uint8Array(0)
174174

175175
dekFormat: DekFormat
176176
isDeterministic: boolean
@@ -222,13 +222,13 @@ export class Cryptor {
222222
switch (this.dekFormat) {
223223
case DekFormat.AES256_SIV:
224224
const aesSivKey = fromBinary(AesSivKeySchema, dek)
225-
rawKey = aesSivKey.keyValue
226-
return Buffer.from(await this.encryptWithAesSiv(rawKey, plaintext))
225+
rawKey = new Uint8Array(aesSivKey.keyValue)
226+
return Buffer.from(await this.encryptWithAesSiv(rawKey as Uint8Array<ArrayBuffer>, new Uint8Array(plaintext)))
227227
case DekFormat.AES128_GCM:
228228
case DekFormat.AES256_GCM:
229229
const aesGcmKey = fromBinary(AesGcmKeySchema, dek)
230-
rawKey = aesGcmKey.keyValue
231-
return Buffer.from(await this.encryptWithAesGcm(rawKey, plaintext))
230+
rawKey = new Uint8Array(aesGcmKey.keyValue)
231+
return Buffer.from(await this.encryptWithAesGcm(rawKey as Uint8Array<ArrayBuffer>, new Uint8Array(plaintext)))
232232
default:
233233
throw new RuleError('unsupported dek format')
234234
}
@@ -239,34 +239,34 @@ export class Cryptor {
239239
switch (this.dekFormat) {
240240
case DekFormat.AES256_SIV:
241241
const aesSivKey = fromBinary(AesSivKeySchema, dek)
242-
rawKey = aesSivKey.keyValue
243-
return Buffer.from(await this.decryptWithAesSiv(rawKey, ciphertext))
242+
rawKey = new Uint8Array(aesSivKey.keyValue)
243+
return Buffer.from(await this.decryptWithAesSiv(rawKey as Uint8Array<ArrayBuffer>, new Uint8Array(ciphertext)))
244244
case DekFormat.AES128_GCM:
245245
case DekFormat.AES256_GCM:
246246
const aesGcmKey = fromBinary(AesGcmKeySchema, dek)
247-
rawKey = aesGcmKey.keyValue
248-
return Buffer.from(await this.decryptWithAesGcm(rawKey, ciphertext))
247+
rawKey = new Uint8Array(aesGcmKey.keyValue)
248+
return Buffer.from(await this.decryptWithAesGcm(rawKey as Uint8Array<ArrayBuffer>, new Uint8Array(ciphertext)))
249249
default:
250250
throw new RuleError('unsupported dek format')
251251
}
252252
}
253253

254-
async encryptWithAesSiv(key: Uint8Array, plaintext: Uint8Array): Promise<Uint8Array> {
254+
async encryptWithAesSiv(key: Uint8Array<ArrayBuffer>, plaintext: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>> {
255255
const aead = await aesSivFromRawKey(key)
256256
return aead.encrypt(plaintext, Cryptor.EMPTY_AAD)
257257
}
258258

259-
async decryptWithAesSiv(key: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array> {
259+
async decryptWithAesSiv(key: Uint8Array<ArrayBuffer>, ciphertext: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>> {
260260
const aead = await aesSivFromRawKey(key)
261261
return aead.decrypt(ciphertext, Cryptor.EMPTY_AAD)
262262
}
263263

264-
async encryptWithAesGcm(key: Uint8Array, plaintext: Uint8Array): Promise<Uint8Array> {
264+
async encryptWithAesGcm(key: Uint8Array<ArrayBuffer>, plaintext: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>> {
265265
const aead = await aesGcmFromRawKey(key)
266266
return aead.encrypt(plaintext, Cryptor.EMPTY_AAD)
267267
}
268268

269-
async decryptWithAesGcm(key: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array> {
269+
async decryptWithAesGcm(key: Uint8Array<ArrayBuffer>, ciphertext: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>> {
270270
const aead = await aesGcmFromRawKey(key)
271271
return aead.decrypt(ciphertext, Cryptor.EMPTY_AAD)
272272
}

schemaregistry/rules/encryption/tink/aead.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export abstract class Aead {
2929
* @returns resulting ciphertext
3030
*
3131
*/
32-
abstract encrypt(plaintext: Uint8Array, opt_associatedData?: Uint8Array|null):
33-
Promise<Uint8Array>;
32+
abstract encrypt(plaintext: Uint8Array<ArrayBuffer>, opt_associatedData?: Uint8Array<ArrayBuffer>|null):
33+
Promise<Uint8Array<ArrayBuffer>>;
3434

3535
/**
3636
* Decrypts ciphertext with associated authenticated data.
@@ -46,6 +46,6 @@ export abstract class Aead {
4646
* @returns resulting plaintext
4747
*/
4848
abstract decrypt(
49-
ciphertext: Uint8Array,
50-
opt_associatedData?: Uint8Array|null): Promise<Uint8Array>;
49+
ciphertext: Uint8Array<ArrayBuffer>,
50+
opt_associatedData?: Uint8Array<ArrayBuffer>|null): Promise<Uint8Array<ArrayBuffer>>;
5151
}

schemaregistry/rules/encryption/tink/aes_gcm.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export class AesGcm extends Aead {
3434

3535
/**
3636
*/
37-
async encrypt(plaintext: Uint8Array, associatedData?: Uint8Array):
38-
Promise<Uint8Array> {
37+
async encrypt(plaintext: Uint8Array<ArrayBuffer>, associatedData?: Uint8Array<ArrayBuffer>):
38+
Promise<Uint8Array<ArrayBuffer>> {
3939
Validators.requireUint8Array(plaintext);
4040
if (associatedData != null) {
4141
Validators.requireUint8Array(associatedData);
@@ -56,8 +56,8 @@ export class AesGcm extends Aead {
5656

5757
/**
5858
*/
59-
async decrypt(ciphertext: Uint8Array, associatedData?: Uint8Array):
60-
Promise<Uint8Array> {
59+
async decrypt(ciphertext: Uint8Array<ArrayBuffer>, associatedData?: Uint8Array<ArrayBuffer>):
60+
Promise<Uint8Array<ArrayBuffer>> {
6161
Validators.requireUint8Array(ciphertext);
6262
if (ciphertext.length < IV_SIZE_IN_BYTES + TAG_SIZE_IN_BITS / 8) {
6363
throw new SecurityException('ciphertext too short');
@@ -88,7 +88,7 @@ export class AesGcm extends Aead {
8888
}
8989
}
9090

91-
export async function fromRawKey(key: Uint8Array): Promise<Aead> {
91+
export async function fromRawKey(key: Uint8Array<ArrayBuffer>): Promise<Aead> {
9292
Validators.requireUint8Array(key);
9393
Validators.validateAesKeySize(key.length);
9494
const webCryptoKey = await crypto.subtle.importKey(

schemaregistry/rules/encryption/tink/aes_siv.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ import {SIV, SoftCryptoProvider} from "@hackbg/miscreant-esm";
1313
*
1414
*/
1515
export class AesSiv extends Aead {
16-
constructor(private readonly key: Uint8Array) {
16+
constructor(private readonly key: Uint8Array<ArrayBuffer>) {
1717
super();
1818
}
1919

2020
/**
2121
*/
22-
async encrypt(plaintext: Uint8Array, associatedData?: Uint8Array):
23-
Promise<Uint8Array> {
22+
async encrypt(plaintext: Uint8Array<ArrayBuffer>, associatedData?: Uint8Array<ArrayBuffer>):
23+
Promise<Uint8Array<ArrayBuffer>> {
2424
let key = await SIV.importKey(this.key, "AES-CMAC-SIV", new SoftCryptoProvider());
2525
return key.seal(plaintext, associatedData != null ? [associatedData] : []);
2626
}
2727

2828
/**
2929
*/
30-
async decrypt(ciphertext: Uint8Array, associatedData?: Uint8Array):
31-
Promise<Uint8Array> {
30+
async decrypt(ciphertext: Uint8Array<ArrayBuffer>, associatedData?: Uint8Array<ArrayBuffer>):
31+
Promise<Uint8Array<ArrayBuffer>> {
3232
let key = await SIV.importKey(this.key, "AES-CMAC-SIV", new SoftCryptoProvider());
3333
return key.open(ciphertext, associatedData != null? [associatedData] : []);
3434
}
3535
}
3636

37-
export async function fromRawKey(key: Uint8Array): Promise<Aead> {
37+
export async function fromRawKey(key: Uint8Array<ArrayBuffer>): Promise<Aead> {
3838
return new AesSiv(key);
3939
}

schemaregistry/rules/encryption/tink/bytes.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {InvalidArgumentsException} from './exception/invalid_arguments_exception
1111
* @param ba2 - The second bytearray to check.
1212
* @returns If the array are equal.
1313
*/
14-
export function isEqual(ba1: Uint8Array, ba2: Uint8Array): boolean {
14+
export function isEqual(ba1: Uint8Array<ArrayBuffer>, ba2: Uint8Array<ArrayBuffer>): boolean {
1515
if (ba1.length !== ba2.length) {
1616
return false;
1717
}
@@ -25,7 +25,7 @@ export function isEqual(ba1: Uint8Array, ba2: Uint8Array): boolean {
2525
/**
2626
* Returns a new array that is the result of joining the arguments.
2727
*/
28-
export function concat(...var_args: Uint8Array[]): Uint8Array {
28+
export function concat(...var_args: Uint8Array<ArrayBuffer>[]): Uint8Array<ArrayBuffer> {
2929
let length = 0;
3030
for (let i = 0; i < arguments.length; i++) {
3131
// eslint-disable-next-line prefer-rest-params
@@ -48,7 +48,7 @@ export function concat(...var_args: Uint8Array[]): Uint8Array {
4848
* @returns The number as a big-endian byte array.
4949
* @throws {@link InvalidArgumentsException}
5050
*/
51-
export function fromNumber(value: number): Uint8Array {
51+
export function fromNumber(value: number): Uint8Array<ArrayBuffer> {
5252
if (Number.isNaN(value) || value % 1 !== 0) {
5353
throw new InvalidArgumentsException('cannot convert non-integer value');
5454
}
@@ -81,7 +81,7 @@ export function fromNumber(value: number): Uint8Array {
8181
* @returns the byte array output
8282
* @throws {@link InvalidArgumentsException}
8383
*/
84-
export function fromHex(hex: string): Uint8Array {
84+
export function fromHex(hex: string): Uint8Array<ArrayBuffer> {
8585
if (hex.length % 2 != 0) {
8686
throw new InvalidArgumentsException(
8787
'Hex string length must be multiple of 2');
@@ -99,7 +99,7 @@ export function fromHex(hex: string): Uint8Array {
9999
* @param bytes - the byte array input
100100
* @returns hex the output
101101
*/
102-
export function toHex(bytes: Uint8Array): string {
102+
export function toHex(bytes: Uint8Array<ArrayBuffer>): string {
103103
let result = '';
104104
for (let i = 0; i < bytes.length; i++) {
105105
const hexByte = bytes[i].toString(16);
@@ -116,7 +116,7 @@ export function toHex(bytes: Uint8Array): string {
116116
* alphabet, which does not require escaping for use in URLs.
117117
* @returns the byte array output
118118
*/
119-
export function fromBase64(encoded: string, opt_webSafe?: boolean): Uint8Array {
119+
export function fromBase64(encoded: string, opt_webSafe?: boolean): Uint8Array<ArrayBuffer> {
120120
if (opt_webSafe) {
121121
const normalBase64 = encoded.replace(/-/g, '+').replace(/_/g, '/');
122122
return fromByteString(window.atob(normalBase64));
@@ -132,7 +132,7 @@ export function fromBase64(encoded: string, opt_webSafe?: boolean): Uint8Array {
132132
* alphabet, which does not require escaping for use in URLs.
133133
* @returns base64 output
134134
*/
135-
export function toBase64(bytes: Uint8Array, opt_webSafe?: boolean): string {
135+
export function toBase64(bytes: Uint8Array<ArrayBuffer>, opt_webSafe?: boolean): string {
136136
const encoded = window
137137
.btoa(
138138
/* padding */
@@ -151,7 +151,7 @@ export function toBase64(bytes: Uint8Array, opt_webSafe?: boolean): string {
151151
* @param str - the input
152152
* @returns the byte array output
153153
*/
154-
export function fromByteString(str: string): Uint8Array {
154+
export function fromByteString(str: string): Uint8Array<ArrayBuffer> {
155155
const output = [];
156156
let p = 0;
157157
for (let i = 0; i < str.length; i++) {
@@ -170,7 +170,7 @@ export function fromByteString(str: string): Uint8Array {
170170
* characters.
171171
* @returns Stringification of the array.
172172
*/
173-
export function toByteString(bytes: Uint8Array): string {
173+
export function toByteString(bytes: Uint8Array<ArrayBuffer>): string {
174174
let str = '';
175175
for (let i = 0; i < bytes.length; i += 1) {
176176
str += String.fromCharCode(bytes[i]);

schemaregistry/rules/encryption/tink/hkdf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import * as Validators from './validators';
2828
* @returns Output keying material (okm).
2929
*/
3030
export async function compute(
31-
size: number, hash: string, ikm: Uint8Array, info: Uint8Array,
32-
opt_salt?: Uint8Array): Promise<Uint8Array> {
31+
size: number, hash: string, ikm: Uint8Array<ArrayBuffer>, info: Uint8Array<ArrayBuffer>,
32+
opt_salt?: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>> {
3333
let digestSize;
3434
if (!Number.isInteger(size)) {
3535
throw new InvalidArgumentsException('size must be an integer');

0 commit comments

Comments
 (0)