Skip to content

Commit 8a4ffd2

Browse files
committed
Clean up linting issues
1 parent 05e6d44 commit 8a4ffd2

File tree

8 files changed

+103
-89
lines changed

8 files changed

+103
-89
lines changed

typescript/packages/plugins/data-access/src/__tests__/data-access.service.test.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ vi.mock('@radiustechsystems/ai-agent-wallet', () => ({
1616
type RadiusWalletInterface = any;
1717

1818
import { DataAccessService } from '../data-access.service';
19-
import {
19+
import {
2020
CheckDataAccessParameters,
2121
CreateAccessTokenParameters,
2222
CreateChallengeParameters,
23-
GenerateAuthSignatureParameters,
23+
GenerateAuthSignatureParameters,
2424
GetBalanceDetailsParameters,
2525
GetBalanceParameters,
2626
HandleHttp402ResponseParameters,
2727
RecoverSignerParameters,
28-
VerifySignatureParameters
28+
VerifySignatureParameters,
2929
} from '../parameters';
3030
import type { DataAccessOptions } from '../types';
3131

@@ -161,23 +161,23 @@ describe('DataAccessService', () => {
161161
const params = new GenerateAuthSignatureParameters();
162162
params.resourceUrl = 'http://localhost:3000/content/123';
163163
// tierId is optional, so we don't need to set it
164-
164+
165165
const result = await service.generateAuthSignature(mockWalletClient, params);
166-
166+
167167
expect(result).toHaveProperty('signature');
168168
expect(result).toHaveProperty('authHeaders');
169169
expect(result.authHeaders).toHaveProperty('Authorization');
170170
expect(result.authHeaders.Authorization).toMatch(/^Signature challenge=/);
171171
});
172-
172+
173173
test('should use provided challenge if available', async () => {
174174
const params = new GenerateAuthSignatureParameters();
175175
params.resourceUrl = 'http://localhost:3000/content/123';
176176
// tierId is optional
177177
params.challenge = 'test-challenge';
178-
178+
179179
const result = await service.generateAuthSignature(mockWalletClient, params);
180-
180+
181181
expect(result).toHaveProperty('signature');
182182
expect(result.authHeaders.Authorization).toContain('challenge="test-challenge"');
183183
});
@@ -188,28 +188,28 @@ describe('DataAccessService', () => {
188188
const params = new CreateAccessTokenParameters();
189189
params.resourceUrl = 'http://localhost:3000/content/123';
190190
params.tierId = 1;
191-
191+
192192
const result = await service.createAccessToken(mockWalletClient, params);
193-
193+
194194
expect(result).toHaveProperty('token');
195195
expect(result).toHaveProperty('authHeaders');
196196
expect(result.authHeaders).toHaveProperty('Authorization');
197197
expect(result.authHeaders.Authorization).toMatch(/^Bearer /);
198-
198+
199199
const decoded = jwt.decode(result.token);
200200
expect(decoded).toHaveProperty('tierId', 1);
201201
expect(decoded).toHaveProperty('iat');
202202
});
203-
203+
204204
test('should respect custom expiration time', async () => {
205205
const params = new CreateAccessTokenParameters();
206206
params.resourceUrl = 'http://localhost:3000/content/123';
207207
params.tierId = 2;
208208
params.expiresIn = '2h';
209-
209+
210210
const result = await service.createAccessToken(mockWalletClient, params);
211211
const decoded = jwt.decode(result.token) as { exp: number; iat: number };
212-
212+
213213
// Check that expiration is roughly 2 hours after issuance
214214
expect(decoded.exp - decoded.iat).toBeCloseTo(7200, -2); // 2 hours in seconds, with tolerance
215215
});
@@ -222,9 +222,9 @@ describe('DataAccessService', () => {
222222
params.challenge = JSON.stringify({ message: 'test challenge' });
223223
params.signature = '0xsignature';
224224
params.tierId = 1;
225-
225+
226226
const result = await service.verifySignature(mockWalletClient, params);
227-
227+
228228
expect(result).toHaveProperty('verified');
229229
expect(result).toHaveProperty('balance');
230230
expect(result).toHaveProperty('signer');
@@ -237,9 +237,9 @@ describe('DataAccessService', () => {
237237
const params = new RecoverSignerParameters();
238238
params.challenge = JSON.stringify({ message: 'test challenge' });
239239
params.signature = '0xsignature';
240-
240+
241241
const result = await service.recoverSigner(mockWalletClient, params);
242-
242+
243243
expect(result).toHaveProperty('signer');
244244
expect(result.signer).toBe('0xmockaddress');
245245
});
@@ -249,20 +249,20 @@ describe('DataAccessService', () => {
249249
test('should get token balance for tier', async () => {
250250
const params = new GetBalanceParameters();
251251
params.tierId = 1;
252-
252+
253253
const result = await service.getBalance(mockWalletClient, params);
254-
254+
255255
expect(result).toHaveProperty('balance');
256256
expect(typeof result.balance).toBe('number');
257257
});
258-
258+
259259
test('should accept custom address parameter', async () => {
260260
const params = new GetBalanceParameters();
261261
params.tierId = 1;
262262
params.address = '0xcustomaddress';
263-
263+
264264
const result = await service.getBalance(mockWalletClient, params);
265-
265+
266266
expect(result).toHaveProperty('balance');
267267
});
268268
});
@@ -271,12 +271,12 @@ describe('DataAccessService', () => {
271271
test('should get detailed balance information', async () => {
272272
const params = new GetBalanceDetailsParameters();
273273
params.tierId = 1;
274-
274+
275275
const result = await service.getBalanceDetails(mockWalletClient, params);
276-
276+
277277
expect(result).toHaveProperty('balanceGroups');
278278
expect(Array.isArray(result.balanceGroups)).toBe(true);
279-
279+
280280
if (result.balanceGroups.length > 0) {
281281
expect(result.balanceGroups[0]).toHaveProperty('balance');
282282
expect(result.balanceGroups[0]).toHaveProperty('expiresAt');
@@ -288,9 +288,9 @@ describe('DataAccessService', () => {
288288
test('should create an authentication challenge', async () => {
289289
const params = new CreateChallengeParameters();
290290
params.address = '0xmockaddress';
291-
291+
292292
const result = await service.createChallenge(mockWalletClient, params);
293-
293+
294294
expect(result).toHaveProperty('challenge');
295295
expect(result.challenge).toHaveProperty('types');
296296
expect(result.challenge).toHaveProperty('primaryType', 'Auth');

typescript/packages/plugins/data-access/src/__tests__/parameters.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ describe('Parameter Classes', () => {
7070
});
7171

7272
describe('VerifySignatureParameters', () => {
73-
testParameterClass(VerifySignatureParameters, ['resourceUrl', 'challenge', 'signature', 'tierId'], []);
73+
testParameterClass(
74+
VerifySignatureParameters,
75+
['resourceUrl', 'challenge', 'signature', 'tierId'],
76+
[],
77+
);
7478
});
7579

7680
describe('GetBalanceParameters', () => {

typescript/packages/plugins/data-access/src/abi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,5 @@ export const dataAccessABI = [
125125
outputs: [{ name: '', type: 'string' }],
126126
stateMutability: 'view',
127127
type: 'function',
128-
}
128+
},
129129
];

typescript/packages/plugins/data-access/src/data-access.contract.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class DataAccessContract {
3131
});
3232

3333
return result.value as string;
34-
} catch (error) {
34+
} catch {
3535
// If we can't get the project ID from the contract, use the one from constructor
3636
return this.projectId;
3737
}
@@ -94,7 +94,7 @@ export class DataAccessContract {
9494
}
9595

9696
// Use proper typing for the contract response
97-
return (result.value as RawBalanceGroup[]).map(item => ({
97+
return (result.value as RawBalanceGroup[]).map((item) => ({
9898
balance: BigInt(item.balance.toString()),
9999
expiresAt: BigInt(item.expiresAt.toString()),
100100
}));
@@ -336,13 +336,13 @@ export class DataAccessContract {
336336
]);
337337

338338
// Construct tier metadata
339-
// Note: Name, description, and domains would typically come from token URI
339+
// Note: Name, description, and domains would typically come from token URI
340340
// or an off-chain registry. For this implementation, we use placeholders.
341341
const tier: AccessTier = {
342342
id: tierId,
343343
name: `Tier ${tierId}`,
344344
description: `Access tier ${tierId}`,
345-
domains: [], // This would be populated from off-chain metadata
345+
domains: [], // This would be populated from off-chain metadata
346346
price,
347347
ttl,
348348
active,
@@ -371,12 +371,12 @@ export class DataAccessContract {
371371
async getAvailableTiers(knownTierIds: number[] = [1, 2, 3]): Promise<AccessTier[]> {
372372
try {
373373
const tiers: AccessTier[] = [];
374-
374+
375375
for (const tierId of knownTierIds) {
376376
try {
377377
const isActive = await this.isActive(tierId);
378378
const isForSale = await this.isForSale(tierId);
379-
379+
380380
// Only include active tiers that are for sale
381381
if (isActive && isForSale) {
382382
const tier = await this.getTierMetadata(tierId);
@@ -387,7 +387,7 @@ export class DataAccessContract {
387387
console.warn(`Skipping tier ${tierId}: ${error}`);
388388
}
389389
}
390-
390+
391391
return tiers;
392392
} catch (error) {
393393
console.error(`Error getting tiers: ${error}`);
@@ -428,19 +428,19 @@ export class DataAccessContract {
428428
try {
429429
// Use balanceDetails to get expiration information
430430
const details = await this.balanceDetails(walletAddress, tierId);
431-
431+
432432
if (details.length === 0) {
433433
return 0; // No tokens, so no expiration
434434
}
435-
435+
436436
// Find the latest expiration date
437437
let latestExpiry = 0n;
438438
for (const detail of details) {
439439
if (detail.balance > 0n && detail.expiresAt > latestExpiry) {
440440
latestExpiry = detail.expiresAt;
441441
}
442442
}
443-
443+
444444
return Number(latestExpiry);
445445
} catch (error) {
446446
throw new ContractError(

typescript/packages/plugins/data-access/src/data-access.plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class DataAccessPlugin extends PluginBase<RadiusWalletInterface> {
2727
}
2828

2929
// projectId is now optional since it can be retrieved from the contract
30-
30+
3131
super('dataAccess', [new DataAccessService(options)]);
3232
}
3333

typescript/packages/plugins/data-access/src/data-access.service.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,32 @@ import {
55
TransactionError,
66
} from '@radiustechsystems/ai-agent-wallet';
77
import jwt, { type Algorithm, type JsonWebTokenError } from 'jsonwebtoken';
8+
import type { StringValue } from 'ms';
89
import { DataAccessContract } from './data-access.contract';
910
import type {
1011
CheckDataAccessParameters,
1112
CreateAccessTokenParameters,
13+
CreateChallengeParameters,
1214
GenerateAuthSignatureParameters,
15+
GetBalanceDetailsParameters,
16+
GetBalanceParameters,
1317
HandleHttp402ResponseParameters,
1418
PurchaseDataAccessParameters,
15-
VerifySignatureParameters,
16-
GetBalanceParameters,
17-
GetBalanceDetailsParameters,
18-
CreateChallengeParameters,
1919
RecoverSignerParameters,
20+
VerifySignatureParameters,
2021
} from './parameters';
2122
import type {
2223
AccessResult,
2324
AccessTier,
24-
TypedData,
2525
AuthChallenge,
26+
BalanceGroup,
2627
Contract,
2728
DataAccessOptions,
2829
JWTOptions,
2930
Network,
30-
BalanceGroup,
3131
SignatureResult,
32+
TypedData,
3233
} from './types';
33-
import type { StringValue } from 'ms';
3434

3535
/**
3636
* Service class for the DataAccess plugin
@@ -93,7 +93,9 @@ export class DataAccessService {
9393
getProjectId: async () => this.contract.projectId || '0x0',
9494
hasValidAccess: async () => true,
9595
balanceOf: async () => 1,
96-
balanceDetails: async () => [{ balance: BigInt(1), expiresAt: BigInt(Date.now() + 3600000) }],
96+
balanceDetails: async () => [
97+
{ balance: BigInt(1), expiresAt: BigInt(Date.now() + 3600000) },
98+
],
9799
balanceOfSigner: async () => 1,
98100
recoverSigner: async () => walletClient.getAddress(),
99101
getAvailableTiers: async () => [
@@ -190,7 +192,7 @@ export class DataAccessService {
190192
if (this.config.customTierSelector) {
191193
return this.config.customTierSelector(affordableTiers);
192194
}
193-
// Fall through to default if custom selector not provided
195+
// Fall through to default if custom selector not provided
194196

195197
default:
196198
// Default to cheapest
@@ -201,13 +203,16 @@ export class DataAccessService {
201203
/**
202204
* Create a JWT token
203205
*/
204-
205-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
206-
private createToken(payload: Record<string, any>, expiresIn: number | StringValue = '1h'): string {
206+
207+
private createToken(
208+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
209+
payload: Record<string, any>,
210+
expiresIn: number | StringValue = '1h',
211+
): string {
207212
// Create a new sign options object
208-
const signOpts: jwt.SignOptions = {
213+
const signOpts: jwt.SignOptions = {
209214
...this.jwt.signOpts,
210-
expiresIn
215+
expiresIn,
211216
};
212217

213218
return jwt.sign(payload, this.jwt.secret, signOpts);
@@ -221,7 +226,7 @@ export class DataAccessService {
221226
const nonce = Buffer.from(Math.random().toString(36) + Date.now().toString(36))
222227
.toString('hex')
223228
.substring(0, 32);
224-
229+
225230
const timestamp = Math.floor(Date.now() / 1000);
226231

227232
// Create the auth challenge message
@@ -567,7 +572,10 @@ export class DataAccessService {
567572
): Promise<{ token: string; authHeaders: Record<string, string> }> {
568573
try {
569574
// Create the JWT access token
570-
const token = this.generateAccessToken(parameters.tierId, parameters.expiresIn as number | StringValue);
575+
const token = this.generateAccessToken(
576+
parameters.tierId,
577+
parameters.expiresIn as number | StringValue,
578+
);
571579

572580
return {
573581
token,
@@ -596,7 +604,7 @@ export class DataAccessService {
596604
const balance = await dataAccess.balanceOfSigner(
597605
parameters.challenge,
598606
parameters.signature,
599-
parameters.tierId
607+
parameters.tierId,
600608
);
601609

602610
// Get signer address
@@ -681,7 +689,7 @@ export class DataAccessService {
681689
description: 'Create an authentication challenge',
682690
})
683691
async createChallenge(
684-
walletClient: RadiusWalletInterface,
692+
// walletClient: RadiusWalletInterface,
685693
parameters: CreateChallengeParameters,
686694
): Promise<{ challenge: TypedData }> {
687695
try {

0 commit comments

Comments
 (0)