Update ws merged (#90)

Co-authored-by: thomas-senechal <thomas.senechal@pm.me>
This commit is contained in:
turnoffthiscomputer
2025-02-13 04:23:51 +01:00
committed by GitHub
parent 6d4c211c51
commit 54ffcb69e4
36 changed files with 907 additions and 2609 deletions

1
sdk/core/.yarnrc.yml Normal file
View File

@@ -0,0 +1 @@
nodeLinker: node-modules

View File

@@ -2,11 +2,13 @@ import { SelfVerifierReport } from './src/SelfVerifierReport';
import { SelfVerifier } from './src/SelfVerifier';
import { countryCodes } from '../../common/src/constants/constants';
import {
OpenPassportAttestation,
OpenPassportDynamicAttestation,
SelfAttestation,
// OpenPassportDynamicAttestation,
} from '../../common/src/utils/selfAttestation';
export {
SelfVerifier,
SelfVerifierReport,
countryCodes,
SelfAttestation,
};

View File

@@ -1,34 +1,14 @@
import {
countryNames,
} from '../../../common/src/constants/constants';
import type { SelfAttestation } from '../../../common/src/utils/selfAttestation';
import {
parsePublicSignalsDisclose,
} from '../../../common/src/utils/selfAttestation';
import {
formatForbiddenCountriesListFromCircuitOutput,
getAttributeFromUnpackedReveal,
unpackReveal,
} from '../../../common/src/utils/circuits/formatOutputs';
import { castToScope } from '../../../common/src/utils/circuits/uuid';
import { SelfVerifierReport } from './SelfVerifierReport';
import {
registryAbi
} from "./abi/IdentityRegistryImplV1";
import {
verifyAllAbi
} from "./abi/VerifyAll";
import { ethers } from 'ethers';
import { countryNames } from '../../../common/src/constants/constants';
import { SelfAttestation } from '../../../common/src/utils/selfAttestation';
import { SelfVerifierReport } from './SelfVerifierReport';
import { registryAbi } from './abi/IdentityRegistryImplV1';
import { verifyAllAbi } from './abi/VerifyAll';
// import type { VcAndDiscloseHubProofStruct } from "../../../common/src/utils/contracts/typechain-types/contracts/IdentityVerificationHubImplV1.sol/IdentityVerificationHubImplV1";
import {
groth16,
Groth16Proof,
PublicSignals
} from 'snarkjs';
import { groth16, Groth16Proof, PublicSignals } from 'snarkjs';
import { CIRCUIT_CONSTANTS, revealedDataTypes } from '../../../common/src/constants/constants';
export class AttestationVerifier {
protected devMode: boolean;
protected scope: string;
protected report: SelfVerifierReport;
@@ -61,11 +41,7 @@ export class AttestationVerifier {
}
public async verify(proof: Groth16Proof, publicSignals: PublicSignals): Promise<SelfAttestation> {
const solidityProof = await groth16.exportSolidityCallData(
proof,
publicSignals,
);
const solidityProof = await groth16.exportSolidityCallData(proof, publicSignals);
const vcAndDiscloseHubProof: any = {
olderThanEnabled: this.minimumAge.enabled,
@@ -73,8 +49,8 @@ export class AttestationVerifier {
forbiddenCountriesEnabled: this.excludedCountries.enabled,
forbiddenCountriesListPacked: BigInt(this.excludedCountries.value.length),
ofacEnabled: this.ofac,
vcAndDiscloseProof: solidityProof
}
vcAndDiscloseProof: solidityProof,
};
const result = await this.verifyAllContract.verifyAll(
this.targetRootTimestamp,
@@ -93,11 +69,11 @@ export class AttestationVerifier {
console.log(result);
const credentialSubject = {
userId: "",
userId: '',
application: this.scope,
merkle_root: "",
attestation_id: "",
current_date: "",
merkle_root: '',
attestation_id: '',
current_date: '',
issuing_state: result[0],
name: result[1],
passport_number: result[2],
@@ -108,7 +84,7 @@ export class AttestationVerifier {
older_than: result[7],
valid: result[8],
nullifier: publicSignals[CIRCUIT_CONSTANTS.REGISTER_NULLIFIER_INDEX],
}
};
const attestation: SelfAttestation = {
'@context': ['https://www.w3.org/2018/credentials/v1'],
@@ -117,18 +93,16 @@ export class AttestationVerifier {
issuanceDate: new Date().toISOString(),
credentialSubject: credentialSubject,
proof: {
type: "Groth16Proof",
verificationMethod: "Vc and Disclose",
type: 'Groth16Proof',
verificationMethod: 'Vc and Disclose',
value: {
proof: proof,
publicSignals: publicSignals,
},
vkey: "",
}
}
vkey: '',
},
};
return attestation;
}
}

View File

@@ -1,33 +1,27 @@
// import {
// ArgumentsDisclose,
// ArgumentsProveOffChain,
// ArgumentsProveOnChain,
// ArgumentsRegister,
// Mode,
// SelfAppPartial,
// SelfApp
// } from '../../../common/src/utils/appType';
import {
DEFAULT_RPC_URL,
countryNames,
} from '../../../common/src/constants/constants';
// import { UserIdType } from '../../../common/src/utils/circuits/uuid';
import { AttestationVerifier } from './AttestationVerifier';
export class SelfVerifier extends AttestationVerifier {
import msgpack from 'msgpack-lite';
import pako from 'pako';
import { DEFAULT_RPC_URL, TREE_TRACKER_URL, countryNames } from '../../../common/src/constants/constants';
import {
ArgumentsDisclose,
ArgumentsProveOffChain,
ArgumentsRegister,
DisclosureOptions,
SelfApp,
SelfAppPartial,
} from '../../../common/src/utils/appType';
import { UserIdType } from '../../../common/src/utils/circuits/uuid';
import { AttestationVerifier } from './AttestationVerifier';
export class SelfVerifier extends AttestationVerifier {
constructor(
scope: string,
scope: string,
devMode: boolean = false,
rpcUrl: string = DEFAULT_RPC_URL,
registryContractAddress: `0x${string}`,
hubContractAddress: `0x${string}`
) {
super(
devMode,
rpcUrl,
registryContractAddress,
hubContractAddress
);
super(devMode, rpcUrl, registryContractAddress, hubContractAddress);
this.scope = scope;
}
@@ -72,18 +66,20 @@ export class SelfVerifier extends AttestationVerifier {
return this;
}
toDisclosureOptions(): DisclosureOptions {
return [
{ key: 'minimumAge', ...this.minimumAge },
{ key: 'nationality', ...this.nationality },
{ key: 'excludedCountries', ...this.excludedCountries },
{ key: 'ofac', enabled: this.ofac },
];
}
// TODO: related to the qr code
getIntent(
appName: string,
userId: string,
userIdType: UserIdType,
sessionId: string,
websocketUrl: string = WEBSOCKET_URL
): string {
getIntent(appName: string, userId: string, userIdType: UserIdType, sessionId: string): string {
const intent_raw: SelfAppPartial = {
appName: appName,
scope: this.scope,
websocketUrl: websocketUrl,
sessionId: sessionId,
userId: userId,
userIdType: userIdType,
@@ -91,15 +87,11 @@ export class SelfVerifier extends AttestationVerifier {
};
let selfArguments: ArgumentsProveOffChain | ArgumentsRegister;
const argsVcAndDisclose: ArgumentsDisclose = {
disclosureOptions: {
minimumAge: this.minimumAge,
nationality: this.nationality,
excludedCountries: this.excludedCountries,
ofac: this.ofac,
};
selfArguments = argsVcAndDisclose;
}
const argsVcAndDisclose: ArgumentsDisclose = {
disclosureOptions: this.toDisclosureOptions(),
commitmentMerkleTreeUrl: TREE_TRACKER_URL,
};
selfArguments = argsVcAndDisclose;
const intent: SelfApp = {
...intent_raw,