Skip to content

Commit d3c576f

Browse files
committed
moves proving utils to the common
1 parent d02b381 commit d3c576f

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

app/src/utils/proving/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export {
99
encryptAES256GCM,
1010
getPayload,
1111
getWSDbRelayerUrl,
12-
} from '@/utils/proving/provingUtils';
12+
} from '@selfxyz/common/utils/proving';
1313

1414
// From loadingScreenStateText - used in loading screen
1515
export { getLoadingScreenText } from '@/utils/proving/loadingScreenStateText';

app/src/utils/proving/provingMachine.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import {
1414
getCircuitNameFromPassportData,
1515
getSolidityPackedUserContextData,
1616
} from '@selfxyz/common/utils';
17+
import {
18+
clientKey,
19+
clientPublicKeyHex,
20+
ec,
21+
encryptAES256GCM,
22+
getPayload,
23+
getWSDbRelayerUrl,
24+
} from '@selfxyz/common/utils/proving';
1725

1826
import { PassportEvents, ProofEvents } from '@/consts/analytics';
1927
import { navigationRef } from '@/navigation';
@@ -33,14 +41,6 @@ import {
3341
generateTEEInputsDSC,
3442
generateTEEInputsRegister,
3543
} from '@/utils/proving/provingInputs';
36-
import {
37-
clientKey,
38-
clientPublicKeyHex,
39-
ec,
40-
encryptAES256GCM,
41-
getPayload,
42-
getWSDbRelayerUrl,
43-
} from '@/utils/proving/provingUtils';
4444
import {
4545
checkIfPassportDscIsInTree,
4646
checkPassportSupported,

common/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@
280280
"types": "./dist/esm/src/utils/passports/passport_parsing/parseDscCertificateData.d.ts",
281281
"import": "./dist/esm/src/utils/passports/passport_parsing/parseDscCertificateData.js",
282282
"require": "./dist/cjs/src/utils/passports/passport_parsing/parseDscCertificateData.cjs"
283+
},
284+
"./utils/proving": {
285+
"types": "./dist/esm/src/utils/proving.d.ts",
286+
"import": "./dist/esm/src/utils/proving.js",
287+
"require": "./dist/cjs/src/utils/proving.cjs"
283288
},
284289
"./utils/scope": {
285290
"types": "./dist/esm/src/utils/scope.d.ts",

app/src/utils/proving/provingUtils.ts renamed to common/src/utils/proving.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import forge from 'node-forge';
44

5-
import {
6-
WS_DB_RELAYER,
7-
WS_DB_RELAYER_STAGING,
8-
} from '@selfxyz/common/constants';
9-
import type { EndpointType } from '@selfxyz/common/utils';
10-
import { initElliptic } from '@selfxyz/common/utils';
5+
import { WS_DB_RELAYER, WS_DB_RELAYER_STAGING } from '../constants/index.js';
6+
import { initElliptic } from '../utils/certificate_parsing/elliptic.js';
7+
import type { EndpointType } from './appType.js';
118

129
const elliptic = initElliptic();
1310
const { ec: EC } = elliptic;
@@ -32,28 +29,24 @@ export type TEEPayloadDisclose = TEEPayloadBase & {
3229
version: number;
3330
};
3431

32+
// // eslint-disable-next-line -- ec must be created first
3533
export const ec = new EC('p256');
36-
34+
// eslint-disable-next-line -- clientKey is created from ec so must be second
3735
export const clientKey = ec.genKeyPair();
3836

3937
type RegisterSuffixes = '' | '_id';
4038
type DscSuffixes = '' | '_id';
4139
type DiscloseSuffixes = '' | '_id';
4240
type ProofTypes = 'register' | 'dsc' | 'disclose';
43-
type RegisterProofType =
44-
`${Extract<ProofTypes, 'register'>}${RegisterSuffixes}`;
41+
type RegisterProofType = `${Extract<ProofTypes, 'register'>}${RegisterSuffixes}`;
4542
type DscProofType = `${Extract<ProofTypes, 'dsc'>}${DscSuffixes}`;
46-
type DiscloseProofType =
47-
`${Extract<ProofTypes, 'disclose'>}${DiscloseSuffixes}`;
43+
type DiscloseProofType = `${Extract<ProofTypes, 'disclose'>}${DiscloseSuffixes}`;
4844

4945
export const clientPublicKeyHex =
5046
clientKey.getPublic().getX().toString('hex').padStart(64, '0') +
5147
clientKey.getPublic().getY().toString('hex').padStart(64, '0');
5248

53-
export function encryptAES256GCM(
54-
plaintext: string,
55-
key: forge.util.ByteStringBuffer,
56-
) {
49+
export function encryptAES256GCM(plaintext: string, key: forge.util.ByteStringBuffer) {
5750
const iv = forge.random.getBytesSync(12);
5851
const cipher = forge.cipher.createCipher('AES-GCM', key);
5952
cipher.start({ iv: iv, tagLength: 128 });
@@ -75,7 +68,7 @@ export function getPayload(
7568
endpointType: EndpointType,
7669
endpoint: string,
7770
version: number = 1,
78-
userDefinedData: string = '',
71+
userDefinedData: string = ''
7972
) {
8073
if (circuitType === 'disclose') {
8174
const payload: TEEPayloadDisclose = {

common/tsup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default defineConfig([
2626
'src/utils/hash': 'src/utils/hash.ts',
2727
'src/utils/bytes': 'src/utils/bytes.ts',
2828
'src/utils/trees': 'src/utils/trees.ts',
29+
'src/utils/proving': 'src/utils/proving.ts',
2930
'src/utils/scope': 'src/utils/scope.ts',
3031
'src/utils/appType': 'src/utils/appType.ts',
3132
'src/utils/date': 'src/utils/date.ts',

0 commit comments

Comments
 (0)