Skip to content

Commit 00b789c

Browse files
Upgrade to latest polkadot with frequency _1.17.8_ (#990)
- siwf@latest - frequency-chain/ethereum-utils - frequency-scenario-template@latest - polkadot-api version that matches what's used by all of the above - stop exposing siwfv1 endpoints - take care of _some_ npm audit results - Added @frequency-chain/[email protected] to npm overrides to prevent version conflicts - Fixed TypeScript type issue in polkadot-api.service.ts - Added import type { u64 } from @polkadot/types-codec - Changed Codec?.toNumber() to (... as u64)?.toNumber() - Root cause: TypeScript type inference became stricter in @polkadot/api 16.4.3→16.4.8 Co-authored-by: shannonwells <[email protected]>
1 parent b06e620 commit 00b789c

29 files changed

+3651
-6321
lines changed

apps/account-api/k6-test/package-lock.json

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

apps/account-api/src/controllers/v1/accounts-v1.controller.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
import { AccountsService } from '#account-api/services/accounts.service';
22
import { AccountResponseDto, RetireMsaPayloadResponseDto } from '#types/dtos/account/accounts.response.dto';
3-
import { WalletLoginRequestDto } from '#types/dtos/account/wallet.login.request.dto';
4-
import { WalletLoginConfigResponseDto } from '#types/dtos/account/wallet.login.config.response.dto';
5-
import { WalletLoginResponseDto } from '#types/dtos/account/wallet.login.response.dto';
6-
import {
7-
Body,
8-
Controller,
9-
Get,
10-
Post,
11-
HttpCode,
12-
HttpStatus,
13-
Param,
14-
Inject,
15-
NotFoundException,
16-
ForbiddenException,
17-
} from '@nestjs/common';
3+
import { Body, Controller, Get, Post, HttpCode, HttpStatus, Param, Inject, NotFoundException } from '@nestjs/common';
184
import { ApiBody, ApiOkResponse, ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
195
import { RetireMsaRequestDto, TransactionResponse } from '#types/dtos/account';
206
import { AccountIdDto, MsaIdDto } from '#types/dtos/common';
@@ -31,15 +17,6 @@ export class AccountsControllerV1 {
3117
// eslint-disable-next-line no-empty-function
3218
) {}
3319

34-
@Get('siwf')
35-
@HttpCode(HttpStatus.OK)
36-
@ApiOperation({ summary: 'Get the Sign In With Frequency configuration' })
37-
@ApiOkResponse({ description: 'Returned SIWF Configuration data', type: WalletLoginConfigResponseDto })
38-
async getSIWFConfig(): Promise<WalletLoginConfigResponseDto> {
39-
this.logger.debug('Received request for Sign In With Frequency Configuration');
40-
return this.accountsService.getSIWFConfig();
41-
}
42-
4320
@Get(':msaId')
4421
@HttpCode(HttpStatus.OK)
4522
@ApiOperation({ summary: 'Fetch an account given an MSA Id' })
@@ -77,18 +54,6 @@ export class AccountsControllerV1 {
7754
throw new NotFoundException(`Failed to find the account ${accountId}`);
7855
}
7956

80-
@Post('siwf')
81-
@HttpCode(HttpStatus.CREATED)
82-
@ApiOperation({ summary: 'Request to Sign In With Frequency' })
83-
@ApiCreatedResponse({ description: 'Signed in successfully', type: WalletLoginResponseDto })
84-
async postSignInWithFrequency(@Body() walletLoginRequest: WalletLoginRequestDto): Promise<WalletLoginResponseDto> {
85-
if (this.config.isDeployedReadOnly && walletLoginRequest.signUp) {
86-
throw new ForbiddenException('New account sign-up unavailable in read-only mode');
87-
}
88-
this.logger.debug(`Received Sign In With Frequency request: ${JSON.stringify(walletLoginRequest)}`);
89-
return this.accountsService.signInWithFrequency(walletLoginRequest);
90-
}
91-
9257
@Get('retireMsa/:accountId')
9358
@HttpCode(HttpStatus.OK)
9459
@ApiOperation({ summary: 'Get a retireMsa unsigned, encoded extrinsic payload.' })

apps/account-api/src/controllers/v2/accounts-v2.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
BadRequestException,
2121
} from '@nestjs/common';
2222
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
23-
import { hasChainSubmissions, isPayloadClaimHandle } from '@projectlibertylabs/siwfv2';
23+
import { hasChainSubmissions, isPayloadClaimHandle } from '@projectlibertylabs/siwf';
2424
import { InjectPinoLogger, PinoLogger } from 'nestjs-pino';
2525

2626
// # SIWF Wallet API V2

apps/account-api/src/services/accounts.service.ts

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
import { BadRequestException, Inject, Injectable, UnprocessableEntityException } from '@nestjs/common';
2-
import { validateSignin, validateSignup } from '@projectlibertylabs/siwfv1';
1+
import { Inject, Injectable, UnprocessableEntityException } from '@nestjs/common';
32
import { BlockchainRpcQueryService } from '#blockchain/blockchain-rpc-query.service';
43
import { EnqueueService } from '#account-lib/services/enqueue-request.service';
5-
import { WalletLoginRequestDto } from '#types/dtos/account/wallet.login.request.dto';
6-
import { WalletLoginResponseDto } from '#types/dtos/account/wallet.login.response.dto';
74
import {
85
AccountResponseDto,
96
MsaIdResponseDto,
107
RetireMsaPayloadResponseDto,
118
} from '#types/dtos/account/accounts.response.dto';
12-
import { WalletLoginConfigResponseDto } from '#types/dtos/account/wallet.login.config.response.dto';
13-
import {
14-
PublishRetireMsaRequestDto,
15-
PublishSIWFSignupRequestDto,
16-
RetireMsaRequestDto,
17-
TransactionResponse,
18-
} from '#types/dtos/account';
9+
import { PublishRetireMsaRequestDto, RetireMsaRequestDto, TransactionResponse } from '#types/dtos/account';
1910
import { TransactionType } from '#types/account-webhook';
2011
import apiConfig, { IAccountApiConfig } from '#account-api/api.config';
2112
import blockchainConfig, { IBlockchainConfig } from '#blockchain/blockchain.config';
@@ -59,53 +50,6 @@ export class AccountsService {
5950
return null;
6051
}
6152

62-
async getSIWFConfig(): Promise<WalletLoginConfigResponseDto> {
63-
const { siwfNodeRpcUrl, siwfUrl }: IAccountApiConfig = this.apiCOnf;
64-
const { providerId } = this.blockchainConf;
65-
return {
66-
providerId: providerId.toString(),
67-
siwfUrl: siwfUrl.toString(),
68-
frequencyRpcUrl: siwfNodeRpcUrl?.toString(),
69-
};
70-
}
71-
72-
// eslint-disable-next-line class-methods-use-this
73-
async signInWithFrequency(request: WalletLoginRequestDto): Promise<WalletLoginResponseDto> {
74-
const api = (await this.blockchainService.getApi()) as ApiPromise;
75-
const { providerId } = this.blockchainConf;
76-
if (request.signUp) {
77-
try {
78-
const siwfPayload = await validateSignup(api, request.signUp, providerId.toString());
79-
// Pass all this data to the transaction publisher queue
80-
const referenceId: WalletLoginResponseDto =
81-
await this.enqueueService.enqueueRequest<PublishSIWFSignupRequestDto>({
82-
...siwfPayload,
83-
type: TransactionType.SIWF_SIGNUP,
84-
});
85-
return referenceId;
86-
} catch (e: any) {
87-
this.logger.error(`Failed Signup validation ${e.toString()}`);
88-
throw new UnprocessableEntityException('Failed to sign up');
89-
}
90-
} else if (request.signIn) {
91-
try {
92-
const parsedSignin = await validateSignin(api, request.signIn, 'localhost');
93-
const response: WalletLoginResponseDto = {
94-
referenceId: '0',
95-
msaId: parsedSignin.msaId,
96-
publicKey: parsedSignin.publicKey,
97-
};
98-
return response;
99-
} catch (e) {
100-
this.logger.error(`Error during SIWF signin request: ${e}`);
101-
const { cause } = e as any;
102-
this.logger.error(`cause: ${cause}`);
103-
throw new UnprocessableEntityException('Failed to Sign In With Frequency');
104-
}
105-
}
106-
throw new BadRequestException('Invalid Sign In With Frequency Request');
107-
}
108-
10953
async getRetireMsaPayload(accountId: string): Promise<RetireMsaPayloadResponseDto | null> {
11054
try {
11155
const msaId = await this.getMsaIdForAccountId(accountId);

apps/account-api/src/services/siwfV2-ethereum.mock.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SiwfResponse } from '@projectlibertylabs/siwfv2';
1+
import type { SiwfResponse } from '@projectlibertylabs/siwf';
22

33
// Mock Server Authorization Codes:
44
// validEthereumSiwfAddDelegationResponsePayload

apps/account-api/src/services/siwfV2.mock.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SiwfResponse } from '@projectlibertylabs/siwfv2';
1+
import type { SiwfResponse } from '@projectlibertylabs/siwf';
22
import { createServer, Server, IncomingMessage, ServerResponse } from 'node:http';
33
import { validEthereumSiwfLoginResponsePayload } from '#account-api/services/siwfV2-ethereum.mock.spec';
44
import { URL } from 'node:url';

apps/account-api/src/services/siwfV2.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect, it, jest } from '@jest/globals';
22
import { Test, TestingModule } from '@nestjs/testing';
33
import { BadRequestException } from '@nestjs/common';
4-
import { CurveType, decodeSignedRequest } from '@projectlibertylabs/siwfv2';
4+
import { CurveType, decodeSignedRequest } from '@projectlibertylabs/siwf';
55
import base64url from 'base64url';
66
import { SiwfV2Service } from './siwfV2.service';
77
import { WalletV2RedirectResponseDto } from '#types/dtos/account/wallet.v2.redirect.response.dto';

apps/account-api/src/services/siwfV2.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
isPayloadAddProvider,
1818
SiwfResponsePayload,
1919
isCredentialRecoverySecret,
20-
} from '@projectlibertylabs/siwfv2';
20+
} from '@projectlibertylabs/siwf';
2121
import apiConfig, { IAccountApiConfig } from '#account-api/api.config';
2222
import blockchainConfig, { IBlockchainConfig } from '#blockchain/blockchain.config';
2323
import { BlockchainRpcQueryService } from '#blockchain/blockchain-rpc-query.service';

apps/account-api/test/accounts.controller.e2e-spec.ts

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { RetireMsaPayloadResponseDto, RetireMsaRequestDto } from '#types/dtos/account';
12
import { HttpStatus, ValidationPipe, VersioningType } from '@nestjs/common';
23
import { Test, TestingModule } from '@nestjs/testing';
34
import { EventEmitter2 } from '@nestjs/event-emitter';
@@ -9,7 +10,6 @@ import { setupProviderAndUsers } from './e2e-setup.mock.spec';
910
import { u8aToHex } from '@polkadot/util';
1011
import { cryptoWaitReady } from '@polkadot/util-crypto';
1112
import { CacheMonitorService } from '#cache/cache-monitor.service';
12-
import { WalletLoginRequestDto, RetireMsaPayloadResponseDto, RetireMsaRequestDto } from '#types/dtos/account';
1313
import apiConfig, { IAccountApiConfig } from '#account-api/api.config';
1414
import { TimeoutInterceptor } from '#utils/interceptors/timeout.interceptor';
1515
import { NestExpressApplication } from '@nestjs/platform-express';
@@ -139,50 +139,6 @@ describe('Account Controller', () => {
139139
});
140140
});
141141

142-
describe('(POST) /accounts/siwf', () => {
143-
it('Sign Up With Frequency request should work', async () => {
144-
const siwfRequest: WalletLoginRequestDto = {
145-
signIn: {},
146-
signUp: {
147-
extrinsics: [
148-
{
149-
pallet: 'msa',
150-
extrinsicName: 'createSponsoredAccountWithDelegation',
151-
encodedExtrinsic:
152-
'0xed01043c01b01b4dcafc8a8e73bff98e7558249f53cd0e0e64fa6b8f0159f0913d4874d9360176644186458bad3b00bbd0ac21e6c9bd5a8bed9ced7a772d11a9aac025b47f6559468808e272696f596a02af230951861027c0dc30f7163ecf316838a0723483010000000000000014000000000000000000004d000000',
153-
},
154-
{
155-
pallet: 'handles',
156-
extrinsicName: 'claimHandle',
157-
encodedExtrinsic:
158-
'0xb901044200b01b4dcafc8a8e73bff98e7558249f53cd0e0e64fa6b8f0159f0913d4874d93601225508ae2da9804c60660a150277eb32b2a0f6b9c8f6e07dd6cad799cb31ae1dfb43896f488e9c0b7ec8b530d930b3f9b690683f2765d5def3fee3fc6540d58714656e6464794d000000',
159-
},
160-
],
161-
},
162-
};
163-
164-
await request(httpServer).post(`/v1/accounts/siwf`).send(siwfRequest).expect(201);
165-
});
166-
167-
it('Sign In With Frequency request should work', (done) => {
168-
const siwfRequest: WalletLoginRequestDto = {
169-
signIn: {
170-
siwsPayload: {
171-
message:
172-
'localhost wants you to sign in with your Frequency account:\n5Fghb4Wt3sg9cF6Q2Qucp5jXV5pL2U9uaYXwR9R8W8SYe9np\n\nThe domain localhost wants you to sign in with your Frequency account via localhost\n\nURI: http://localhost:5173/signin/confirm\nNonce: N6rLwqyz34oUxJEXJ\nIssued At: 2024-03-05T23:18:03.041Z\nExpiration Time: 2024-03-05T23:23:03.041Z',
173-
signature:
174-
'0x38faa2fc6f59bef8ffccfc929fb966e1d53ba45e3af7a029ea1d636eaddcbe78a4be0f89eaf7ff7bbaef20a070ad65f9d0f876889686687ef623214fddddb18b',
175-
},
176-
},
177-
signUp: {
178-
extrinsics: [],
179-
},
180-
};
181-
182-
request(httpServer).post(`/v1/accounts/siwf`).send(siwfRequest).expect(201).end(done);
183-
});
184-
});
185-
186142
describe('retireMsa', () => {
187143
it('(GET) /v1/accounts/retireMsa/:accountId get payload for retireMsa, given a valid accountId', async () => {
188144
const accountId = users[0].keypair.address;

apps/account-api/test/accounts.v2.controller.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HttpStatus, ValidationPipe, VersioningType } from '@nestjs/common';
22
import { Test, TestingModule } from '@nestjs/testing';
33
import { EventEmitter2 } from '@nestjs/event-emitter';
44
import { cryptoWaitReady } from '@polkadot/util-crypto';
5-
import { decodeSignedRequest } from '@projectlibertylabs/siwfv2';
5+
import { decodeSignedRequest } from '@projectlibertylabs/siwf';
66
import type { Server } from 'node:http';
77
import base64url from 'base64url';
88
import request from 'supertest';

0 commit comments

Comments
 (0)