Skip to content

Commit 269a092

Browse files
feat: Upgrade TypeScript and tsdoc (#1850)
* feat: upgrade to typescript 5.9 * chore: update tsdoc --------- Co-authored-by: Léo Pradel <pradel.leo@gmail.com>
1 parent 163f679 commit 269a092

25 files changed

Lines changed: 478 additions & 264 deletions

File tree

‎package-lock.json‎

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

‎package.json‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
"@stacks/prettier-config": "^0.0.10",
3333
"@types/bs58check": "^2.1.0",
3434
"@types/jest": "^29.5.3",
35-
"@typescript-eslint/eslint-plugin": "^6.3.0",
36-
"@typescript-eslint/parser": "^6.3.0",
35+
"@typescript-eslint/eslint-plugin": "^8.0.0",
36+
"@typescript-eslint/parser": "^8.0.0",
3737
"assert": "^2.0.0",
3838
"conventional-changelog-conventionalcommits": "^6.1.0",
3939
"esbuild": "^0.19.0",
4040
"esbuild-loader": "^4.0.0",
41-
"eslint": "^8.46.0",
41+
"eslint": "^8.57.0",
4242
"eslint-config-prettier": "^9.0.0",
4343
"eslint-plugin-import": "^2.28.0",
4444
"eslint-plugin-node": "^11.1.0",
@@ -54,9 +54,8 @@
5454
"rimraf": "^5.0.1",
5555
"stream-http": "^3.2.0",
5656
"ts-jest": "^29.1.1",
57-
"typedoc": "^0.24.8",
58-
"typedoc-plugin-replace-text": "^3.1.0",
59-
"typescript": "^5.1.6",
57+
"typedoc": "^0.28.18",
58+
"typescript": "^5.9.3",
6059
"webpack": "^5.88.2",
6160
"webpack-bundle-analyzer": "^4.9.0",
6261
"webpack-cli": "^5.1.4"

‎packages/auth/src/messages.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
makeECPrivateKey,
1414
publicKeyToBtcAddress,
1515
} from '@stacks/encryption';
16-
import { SECP256K1Client, TokenSigner } from 'jsontokens';
16+
import { Json, SECP256K1Client, TokenSigner } from 'jsontokens';
1717
import { AuthScope, DEFAULT_SCOPE } from './constants';
1818
import { makeDIDFromAddress } from './dids';
1919

@@ -186,8 +186,7 @@ export async function decryptPrivateKey(
186186
*/
187187
export async function makeAuthResponse(
188188
privateKey: string,
189-
// eslint-disable-next-line @typescript-eslint/ban-types
190-
profile: {} = {},
189+
profile: object = {},
191190
metadata: AuthMetadata | null,
192191
coreToken: string | null = null,
193192
appPrivateKey: string | null = null,
@@ -245,5 +244,5 @@ export async function makeAuthResponse(
245244

246245
/* Sign and return the token */
247246
const tokenSigner = new TokenSigner('ES256k', privateKey);
248-
return tokenSigner.sign(payload);
247+
return tokenSigner.sign(payload as Json);
249248
}

‎packages/auth/src/verification.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,19 @@ export function isRedirectUriValid(token: string) {
168168
* @private
169169
* @ignore
170170
*/
171-
export async function verifyAuthRequest(token: string): Promise<boolean> {
171+
export function verifyAuthRequest(token: string): Promise<boolean> {
172172
if (decodeToken(token).header.alg === 'none') {
173173
throw new Error('Token must be signed in order to be verified');
174174
}
175-
const values = await Promise.all([
175+
const values = [
176176
isExpirationDateValid(token),
177177
isIssuanceDateValid(token),
178178
doSignaturesMatchPublicKeys(token),
179179
doPublicKeysMatchIssuer(token),
180180
isManifestUriValid(token),
181181
isRedirectUriValid(token),
182-
]);
183-
return values.every(val => val);
182+
];
183+
return Promise.resolve(values.every(val => val));
184184
}
185185

186186
/**
@@ -208,12 +208,12 @@ export async function verifyAuthRequestAndLoadManifest(token: string): Promise<a
208208
* @private
209209
* @ignore
210210
*/
211-
export async function verifyAuthResponse(token: string): Promise<boolean> {
212-
const conditions = await Promise.all([
211+
export function verifyAuthResponse(token: string): Promise<boolean> {
212+
const conditions = [
213213
isExpirationDateValid(token),
214214
isIssuanceDateValid(token),
215215
doSignaturesMatchPublicKeys(token),
216216
doPublicKeysMatchIssuer(token),
217-
]);
218-
return conditions.every(val => val);
217+
];
218+
return Promise.resolve(conditions.every(val => val));
219219
}

‎packages/cli/src/auth.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ export interface NamedIdentityType {
4747
idAddress: string;
4848
privateKey: string;
4949
index: number;
50-
// eslint-disable-next-line @typescript-eslint/ban-types
51-
profile: Object;
50+
profile: object;
5251
profileUrl: string;
5352
}
5453

‎packages/cli/src/cli.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import * as path from 'path';
4444
import * as process from 'process';
4545
import * as winston from 'winston';
4646

47-
// eslint-disable-next-line @typescript-eslint/no-var-requires
47+
// eslint-disable-next-line @typescript-eslint/no-require-imports
4848
const c32check = require('c32check');
4949

5050
import { UserData } from '@stacks/auth';
@@ -466,6 +466,7 @@ async function migrateSubdomains(_network: CLINetworkAdapter, args: string[]): P
466466
return fetch(migrationURL, options)
467467
.then(response => {
468468
if (response.status === 404) {
469+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
469470
return Promise.reject({
470471
status: response.status,
471472
error: response.statusText,
@@ -520,6 +521,7 @@ function balance(_network: CLINetworkAdapter, args: string[]): Promise<string> {
520521
return fetch(`${url}${ACCOUNT_PATH}/${address}?proof=0`)
521522
.then(response => {
522523
if (response.status === 404) {
524+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
523525
return Promise.reject({
524526
status: response.status,
525527
error: response.statusText,
@@ -1229,7 +1231,7 @@ function gaiaDumpBucket(_network: CLINetworkAdapter, args: string[]): Promise<st
12291231

12301232
console.log(`Download ${fileUrl} to ${destPath}`);
12311233
return fetch(fileUrl)
1232-
.then((resp: any) => {
1234+
.then((resp): Promise<string | ArrayBuffer> => {
12331235
if (resp.status !== 200) {
12341236
throw new Error(`Bad status code for ${fileUrl}: ${resp.status}`);
12351237
}
@@ -1246,12 +1248,16 @@ function gaiaDumpBucket(_network: CLINetworkAdapter, args: string[]): Promise<st
12461248
return resp.arrayBuffer();
12471249
}
12481250
})
1249-
.then((filebytes: Buffer | ArrayBuffer) => {
1251+
.then((filebytes: string | ArrayBuffer) => {
12501252
return new Promise((resolve, reject) => {
12511253
try {
1252-
fs.writeFileSync(destPath, Buffer.from(filebytes), { encoding: null, mode: 0o660 });
1254+
fs.writeFileSync(destPath, Buffer.from(filebytes as ArrayBuffer), {
1255+
encoding: null,
1256+
mode: 0o660,
1257+
});
12531258
resolve();
12541259
} catch (e) {
1260+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
12551261
reject(e);
12561262
}
12571263
});
@@ -2118,7 +2124,7 @@ export function CLIMain() {
21182124
.then((result: string | Buffer) => {
21192125
try {
21202126
// if this is a JSON object with 'status', set the exit code
2121-
if (result instanceof Buffer) {
2127+
if (Buffer.isBuffer(result)) {
21222128
return result;
21232129
} else {
21242130
const resJson: any = JSON.parse(result);

‎packages/cli/src/data.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as URL from 'url';
33
import * as crypto from 'crypto';
44
import * as jsontokens from 'jsontokens';
55

6-
// eslint-disable-next-line @typescript-eslint/no-var-requires
6+
// eslint-disable-next-line @typescript-eslint/no-require-imports
77
const ZoneFile = require('zone-file');
88

99
import { canonicalPrivateKey, getPublicKeyFromPrivateKey } from './utils';

‎packages/cli/src/keys.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// TODO: most of this code should be in blockstack.js
22
// Will remove most of this code once the wallet functionality is there instead.
33

4-
// eslint-disable-next-line @typescript-eslint/no-var-requires
4+
// eslint-disable-next-line @typescript-eslint/no-require-imports
55
const c32check = require('c32check');
66

77
import { HDKey } from '@scure/bip32';

‎packages/cli/src/network.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class CLINetworkAdapter {
203203
} else if (resp.status !== 200) {
204204
throw new Error(`Bad response status: ${resp.status}`);
205205
} else {
206-
return Promise.all([resp.json(), blockHeight]);
206+
return resp.json().then((namespaceJson: any) => [namespaceJson, blockHeight]);
207207
}
208208
})
209209
.then(([namespaceInfo, blockHeight]: [any, number]) => {

‎packages/cli/src/utils.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929

3030
import { StacksNetwork, TransactionVersion } from '@stacks/network';
3131

32-
// eslint-disable-next-line @typescript-eslint/no-var-requires
32+
// eslint-disable-next-line @typescript-eslint/no-require-imports
3333
const ZoneFile = require('zone-file');
3434

3535
import {
@@ -383,8 +383,7 @@ export function hash160(buff: Buffer): Buffer {
383383
/*
384384
* Sign a profile into a JWT
385385
*/
386-
// eslint-disable-next-line @typescript-eslint/ban-types
387-
export function makeProfileJWT(profileData: Object, privateKey: string): string {
386+
export function makeProfileJWT(profileData: object, privateKey: string): string {
388387
const signedToken = blockstack.signProfileToken(profileData, privateKey);
389388
const wrappedToken = blockstack.wrapProfileToken(signedToken);
390389
const tokenRecords = [wrappedToken];

0 commit comments

Comments
 (0)