Skip to content

Commit a1a3d4d

Browse files
authored
Merge pull request #717 from MasterKale/fix/deno-2-4-support
Upgrade project to Deno v2.4
2 parents 518e0fb + 1a13250 commit a1a3d4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+224
-134
lines changed

.github/workflows/ciChecks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
node-version: [20, 22]
19-
deno-version: ['v2.1.x']
19+
deno-version: ['v2.1.x', 'v2.4.x']
2020

2121
steps:
2222
- uses: actions/checkout@v4

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ request new features, or to suggest changes to existing features.
8282

8383
Install the following before proceeding:
8484

85-
- **Deno v2.1.x**
85+
- **Deno v2.4.x**
8686

8787
After pulling down the code, set up dependencies:
8888

packages/browser/src/methods/startAuthentication.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
AuthenticationExtensionsClientInputs,
1515
AuthenticationExtensionsClientOutputs,
1616
PublicKeyCredentialRequestOptionsJSON,
17+
Uint8Array_,
1718
} from '../types/index.ts';
1819

1920
import { _browserSupportsWebAuthnInternals } from '../helpers/browserSupportsWebAuthn.ts';
@@ -41,7 +42,9 @@ const goodOpts1: PublicKeyCredentialRequestOptionsJSON = {
4142

4243
// With UTF-8 challenge
4344
const goodOpts2UTF8: PublicKeyCredentialRequestOptionsJSON = {
44-
challenge: bufferToBase64URLString(new TextEncoder().encode('やれやれだぜ')),
45+
challenge: bufferToBase64URLString(
46+
(new TextEncoder().encode('やれやれだぜ') as Uint8Array_).buffer,
47+
),
4548
allowCredentials: [],
4649
timeout: 1,
4750
};

packages/browser/src/types/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export interface AuthenticatorAssertionResponseJSON {
185185
*/
186186
export type WebAuthnCredential = {
187187
id: Base64URLString;
188-
publicKey: Uint8Array;
188+
publicKey: Uint8Array_;
189189
// Number of times this authenticator is expected to have been used
190190
counter: number;
191191
// From browser's `startRegistration()` -> RegistrationCredentialJSON.transports (API L2 and up)
@@ -293,3 +293,19 @@ export type AttestationFormat =
293293
| 'tpm'
294294
| 'apple'
295295
| 'none';
296+
297+
/**
298+
* Equivalent to `Uint8Array` before TypeScript 5.7, and `Uint8Array<ArrayBuffer>` in TypeScript 5.7
299+
* and beyond.
300+
*
301+
* **Context**
302+
*
303+
* `Uint8Array` became a generic type in TypeScript 5.7, requiring types defined simply as
304+
* `Uint8Array` to be refactored to `Uint8Array<ArrayBuffer>` starting in Deno 2.2. `Uint8Array` is
305+
* _not_ generic in Deno 2.1.x and earlier, though, so this type helps bridge this gap.
306+
*
307+
* Inspired by Deno's std library:
308+
*
309+
* https://github.com/denoland/std/blob/b5a5fe4f96b91c1fe8dba5cc0270092dd11d3287/bytes/_types.ts#L11
310+
*/
311+
export type Uint8Array_ = ReturnType<Uint8Array['slice']>;

packages/server/src/authentication/generateAuthenticationOptions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
AuthenticatorTransportFuture,
44
Base64URLString,
55
PublicKeyCredentialRequestOptionsJSON,
6+
Uint8Array_,
67
} from '../types/index.ts';
78
import { isoBase64URL, isoUint8Array } from '../helpers/iso/index.ts';
89
import { generateChallenge } from '../helpers/generateChallenge.ts';
@@ -28,7 +29,7 @@ export async function generateAuthenticationOptions(
2829
id: Base64URLString;
2930
transports?: AuthenticatorTransportFuture[];
3031
}[];
31-
challenge?: string | Uint8Array;
32+
challenge?: string | Uint8Array_;
3233
timeout?: number;
3334
userVerification?: 'required' | 'preferred' | 'discouraged';
3435
extensions?: AuthenticationExtensionsClientInputs;

packages/server/src/helpers/convertAAGUIDToString.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { isoUint8Array } from './iso/index.ts';
2+
import type { Uint8Array_ } from '../types/index.ts';
23

34
/**
45
* Convert the aaguid buffer in authData into a UUID string
56
*/
6-
export function convertAAGUIDToString(aaguid: Uint8Array): string {
7+
export function convertAAGUIDToString(aaguid: Uint8Array_): string {
78
// Raw Hex: adce000235bcc60a648b0b25f1f05503
89
const hex = isoUint8Array.toHex(aaguid);
910

packages/server/src/helpers/convertCOSEtoPKCS.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { isoCBOR, isoUint8Array } from './iso/index.ts';
2-
import { COSEKEYS, COSEPublicKeyEC2 } from './cose.ts';
2+
import { COSEKEYS, type COSEPublicKeyEC2 } from './cose.ts';
3+
import type { Uint8Array_ } from '../types/index.ts';
34

45
/**
56
* Takes COSE-encoded public key and converts it to PKCS key
67
*/
7-
export function convertCOSEtoPKCS(cosePublicKey: Uint8Array): Uint8Array {
8+
export function convertCOSEtoPKCS(cosePublicKey: Uint8Array_): Uint8Array_ {
89
// This is a little sloppy, I'm using COSEPublicKeyEC2 since it could have both x and y, but when
910
// there's no y it means it's probably better typed as COSEPublicKeyOKP. I'll leave this for now
1011
// and revisit it later if it ever becomes an actual problem.

packages/server/src/helpers/convertCertBufferToPEM.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { Base64URLString } from '../types/index.ts';
1+
import type { Base64URLString, Uint8Array_ } from '../types/index.ts';
22
import { isoBase64URL } from './iso/index.ts';
33

44
/**
55
* Convert buffer to an OpenSSL-compatible PEM text format.
66
*/
77
export function convertCertBufferToPEM(
8-
certBuffer: Uint8Array | Base64URLString,
8+
certBuffer: Uint8Array_ | Base64URLString,
99
): string {
1010
let b64cert: string;
1111

packages/server/src/helpers/convertPEMToBytes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { isoBase64URL } from './iso/index.ts';
2+
import type { Uint8Array_ } from '../types/index.ts';
23

34
/**
45
* Take a certificate in PEM format and convert it to bytes
56
*/
6-
export function convertPEMToBytes(pem: string): Uint8Array {
7+
export function convertPEMToBytes(pem: string): Uint8Array_ {
78
const certBase64 = pem
89
.replace('-----BEGIN CERTIFICATE-----', '')
910
.replace('-----END CERTIFICATE-----', '')

packages/server/src/helpers/convertX509PublicKeyToCOSE.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { AsnParser } from '@peculiar/asn1-schema';
22
import { Certificate } from '@peculiar/asn1-x509';
33
import { ECParameters, id_ecPublicKey, id_secp256r1, id_secp384r1 } from '@peculiar/asn1-ecc';
4+
import { id_rsaEncryption, RSAPublicKey } from '@peculiar/asn1-rsa';
5+
46
import {
57
COSECRV,
68
COSEKEYS,
@@ -9,12 +11,11 @@ import {
911
COSEPublicKeyEC2,
1012
COSEPublicKeyRSA,
1113
} from './cose.ts';
12-
import { RSAPublicKey } from '@peculiar/asn1-rsa';
13-
1414
import { mapX509SignatureAlgToCOSEAlg } from './mapX509SignatureAlgToCOSEAlg.ts';
15+
import type { Uint8Array_ } from '../types/index.ts';
1516

1617
export function convertX509PublicKeyToCOSE(
17-
x509Certificate: Uint8Array,
18+
x509Certificate: Uint8Array_,
1819
): COSEPublicKey {
1920
let cosePublicKey: COSEPublicKey = new Map();
2021

@@ -59,8 +60,8 @@ export function convertX509PublicKeyToCOSE(
5960
subjectPublicKeyInfo.subjectPublicKey,
6061
);
6162

62-
let x: Uint8Array;
63-
let y: Uint8Array;
63+
let x: Uint8Array_;
64+
let y: Uint8Array_;
6465
if (subjectPublicKey[0] === 0x04) {
6566
// Public key is in "uncompressed form", so we can split the remaining bytes in half
6667
let pointer = 1;
@@ -84,7 +85,7 @@ export function convertX509PublicKeyToCOSE(
8485
coseEC2PubKey.set(COSEKEYS.y, y);
8586

8687
cosePublicKey = coseEC2PubKey;
87-
} else if (publicKeyAlgorithmID === '1.2.840.113549.1.1.1') {
88+
} else if (publicKeyAlgorithmID === id_rsaEncryption) {
8889
/**
8990
* RSA public key
9091
*/

0 commit comments

Comments
 (0)