Skip to content

Commit

Permalink
add logs, update ipfs urls CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Oct 23, 2023
1 parent 49a64fe commit db65ce7
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/connector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/rarime-connector",
"version": "0.8.0",
"version": "0.8.1-rc.0",
"description": "Facilitates interaction between a DApp and RariMe MetaMask snap",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/connector/src/version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.8.x"
"version": "0.8.1-rc.0"
}
2 changes: 1 addition & 1 deletion packages/site/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "site",
"version": "0.8.0",
"version": "0.8.1-rc.0",
"private": true,
"license": "(MIT-0 OR Apache-2.0)",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/rarime",
"version": "0.8.0",
"version": "0.8.1-rc.0",
"description": "RariMe is a MetaMask Snap that safely holds any of your credentials and allows you to prove your identity without revealing any personal data. Powered by Rarimo Protocol and Zero-Knowledge Proof technology.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -45,7 +45,7 @@
"@metamask/snaps-jest": "0.35.2-flask.1",
"@metamask/snaps-types": "0.32.2",
"@metamask/snaps-ui": "0.32.2",
"@rarimo/rarime-connector": "0.8.0",
"@rarimo/rarime-connector": "0.8.1-rc.0",
"buffer": "6.0.3",
"ethers": "5.7.2",
"intl": "1.2.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "0.8.0",
"version": "0.8.1-rc.0",
"description": "Securely store and manage all of your identity credentials. Use them across chains with ZK-protected privacy guarantees.",
"proposedName": "RariMe",
"repository": {
"type": "git",
"url": "https://github.com/rarimo/rarime.git"
},
"source": {
"shasum": "y+9O7z7mlNe85T/RCp32jySBwGoJ9tf0NrKlLrpgNdw=",
"shasum": "l9sx59QHb7OyZgZQvGpG5N3wHY66XzqnWfgayNk347E=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
20 changes: 10 additions & 10 deletions packages/snap/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ export const config = {
},

CIRCUIT_AUTH_WASM_URL:
'https://ipfs.tokend.io/ipfs/ipfs/QmYd41GHrKQLqbk96zHbmHU5rGVcxwmAgBpRqLCGLK7LQu',
'https://storage.googleapis.com/rarimo-store/snap/QmYd41GHrKQLqbk96zHbmHU5rGVcxwmAgBpRqLCGLK7LQu',
CIRCUIT_AUTH_FINAL_KEY_URL:
'https://ipfs.tokend.io/ipfs/ipfs/QmWKor7i9r2zbM6oqSdgPUCvgyYESH39qXk1f5tbdeaAg7',
'https://storage.googleapis.com/rarimo-store/snap/QmWKor7i9r2zbM6oqSdgPUCvgyYESH39qXk1f5tbdeaAg7',
CIRCUIT_SIG_V2_ON_CHAIN_WASM_URL:
'https://ipfs.tokend.io/ipfs/ipfs/QmS4vURQ1c8tgALSokdTYVqx5E9FmASbu964W3JevnM3B4',
'https://storage.googleapis.com/rarimo-store/snap/QmS4vURQ1c8tgALSokdTYVqx5E9FmASbu964W3JevnM3B4',
CIRCUIT_SIG_V2_ON_CHAIN_FINAL_KEY_URL:
'https://ipfs.tokend.io/ipfs/ipfs/QmT45Y62hfZnADq6VvKGjNR8foNb2KjcyG4AStRRAN9iHm',
'https://storage.googleapis.com/rarimo-store/snap/QmT45Y62hfZnADq6VvKGjNR8foNb2KjcyG4AStRRAN9iHm',
CIRCUIT_SIG_V2_WASM_URL:
'https://ipfs.tokend.io/ipfs/ipfs/QmYB5QLvH5ihiedxvzkG3XPQngjxcS8wc1xCAoKnGS5GfC',
'https://storage.googleapis.com/rarimo-store/snap/QmYB5QLvH5ihiedxvzkG3XPQngjxcS8wc1xCAoKnGS5GfC',
CIRCUIT_SIG_V2_FINAL_KEY_URL:
'https://ipfs.tokend.io/ipfs/ipfs/QmeXxRXxYGCwa48ANikH5Knzi9cgkmhumPbMtjTKNYkThL',
'https://storage.googleapis.com/rarimo-store/snap/QmeXxRXxYGCwa48ANikH5Knzi9cgkmhumPbMtjTKNYkThL',
CIRCUIT_MTP_V2_WASM_URL:
'https://ipfs.tokend.io/ipfs/ipfs/QmRqGgnN6Qy4LuPxQKH2wrADNe4aJb8wYJhS1ky9zbLS8t',
'https://storage.googleapis.com/rarimo-store/snap/QmRqGgnN6Qy4LuPxQKH2wrADNe4aJb8wYJhS1ky9zbLS8t',
CIRCUIT_MTP_V2_FINAL_KEY_URL:
'https://ipfs.tokend.io/ipfs/ipfs/QmcLyDLPWJpyEWeR9KkWQuGHAqifnwpDAWBX1R6a7g6F6a',
'https://storage.googleapis.com/rarimo-store/snap/QmcLyDLPWJpyEWeR9KkWQuGHAqifnwpDAWBX1R6a7g6F6a',
CIRCUIT_MTP_V2_ON_CHAIN_WASM_URL:
'https://ipfs.tokend.io/ipfs/ipfs/QmPtPiFgZigau2VNpSCoagNj36ZpuuATRNvyNPAvvUgvq6',
'https://storage.googleapis.com/rarimo-store/snap/QmPtPiFgZigau2VNpSCoagNj36ZpuuATRNvyNPAvvUgvq6',
CIRCUIT_MTP_V2_ON_CHAIN_FINAL_KEY_URL:
'https://ipfs.tokend.io/ipfs/ipfs/QmU8fC3xwjMcmnsB88SrdKRZpskhxUwBRnaLMa1AcN9ERj',
'https://storage.googleapis.com/rarimo-store/snap/QmU8fC3xwjMcmnsB88SrdKRZpskhxUwBRnaLMa1AcN9ERj',
};

enum CHAINS {
Expand Down
11 changes: 11 additions & 0 deletions packages/snap/src/helpers/proof-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,17 @@ export const newCircuitClaimData = async (
const circuitClaim = new CircuitClaim();
circuitClaim.claim = coreClaim;
circuitClaim.issuerId = DID.parse(credential.issuer).id;
console.log('credential.proof', credential.proof);

const smtProof = getIden3SparseMerkleTreeProof(credential.proof!);
console.log('smtProof', smtProof);

if (smtProof) {
const data = await loadDataByUrl(
smtProof.id,
convertEndianSwappedCoreStateHashHex(coreStateHash),
);
console.log('data', data);

circuitClaim.incProof = {
proof: data.mtp,
Expand All @@ -192,20 +195,26 @@ export const newCircuitClaimData = async (
data.issuer.rootOfRoots,
),
};
console.log('circuitClaim.incProof', circuitClaim.incProof);
}

const sigProof = getBJJSignature2021Proof(credential.proof!);
console.log('sigProof', sigProof);

if (sigProof) {
const decodedSignature = Hex.decodeString(sigProof.signature);
console.log('decodedSignature', decodedSignature);
const signature = Signature.newFromCompressed(decodedSignature);
console.log('signature', signature);
const issuerAuthClaimIncMtp = await loadDataByUrl(
sigProof.issuerData.updateUrl,
convertEndianSwappedCoreStateHashHex(coreStateHash),
);
console.log('issuerAuthClaimIncMtp', issuerAuthClaimIncMtp);
const rs: RevocationStatus = await getRevocationStatus(
sigProof.issuerData.credentialStatus!,
);
console.log('rs', rs);

const issuerAuthNonRevProof: MTProof = {
treeState: buildTreeState(
Expand All @@ -216,6 +225,7 @@ export const newCircuitClaimData = async (
),
proof: rs.mtp,
};
console.log('issuerAuthNonRevProof', issuerAuthNonRevProof);
if (!sigProof.issuerData.mtp) {
throw new Error('issuer auth credential must have a mtp proof');
}
Expand All @@ -238,6 +248,7 @@ export const newCircuitClaimData = async (
issuerAuthClaim: new Claim().fromHex(sigProof.issuerData.authCoreClaim),
issuerAuthNonRevProof,
};
console.log('circuitClaim.signatureProof', circuitClaim.signatureProof);
}

return circuitClaim;
Expand Down
24 changes: 24 additions & 0 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,38 +209,62 @@ export const onRpcRequest: OnRpcRequestHandler = async ({

if (res) {
const identity = await Identity.create(identityStorage.privateKeyHex);
console.log('identity', identity);

const zkpGen = new ZkpGen(identity, createProofRequest, credentials[0]);
console.log('zkpGen', zkpGen);

// ================ LOAD STATE DETAILS =====================

const chainInfo = await getProviderChainInfo();
console.log('chainInfo', chainInfo);

const rarimoCoreUrl = getRarimoCoreUrl(chainInfo.id);
console.log('rarimoCoreUrl', rarimoCoreUrl);

const isSynced = await checkIfStateSynced();
console.log('isSynced', isSynced);

const ID = DID.parse(credentials[0].issuer).id;
const issuerHexId = `0x0${ID.bigInt().toString(16)}`;
console.log('issuerHexId', issuerHexId);

const stateData = await loadDataFromRarimoCore<GetStateInfoResponse>(
`/rarimo/rarimo-core/identity/state/${issuerHexId}`,
);
console.log('stateData', stateData);
const merkleProof = await loadDataFromRarimoCore<MerkleProof>(
`/rarimo/rarimo-core/identity/state/${issuerHexId}/proof`,
stateData.state.createdAtBlock,
);
console.log('merkleProof', merkleProof);

const operation = await getCoreOperationByIndex(
stateData.state.lastUpdateOperationIndex,
);
console.log('operation', operation);

// ================== USE STATE DETAILS TO GEN PROOF =====================

const zkpProof = await zkpGen.generateProof(
stateData.state.hash,
operation.operation.details.GISTHash,
);
console.log('zkpProof', zkpProof);

console.log({
chainInfo,
rarimoCoreUrl,
isSynced,

issuerHexId,

stateData: stateData.state,
merkleProof,
operation: operation.operation,

zkpProof,
});

return {
chainInfo,
Expand Down
20 changes: 20 additions & 0 deletions packages/snap/src/zkp-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,21 @@ export class ZkpGen {
const preparedCredential = await getPreparedCredential(
this.verifiableCredential,
);
console.log('preparedCredential', preparedCredential);

this.circuitClaimData = await newCircuitClaimData(
preparedCredential.credential,
preparedCredential.credentialCoreClaim,
coreStateHash,
);
console.log('circuitClaimData', this.circuitClaimData);

this.query = await toCircuitsQuery(
this.proofRequest.query,
preparedCredential.credential,
preparedCredential.credentialCoreClaim,
);
console.log('query', this.query);

this.nonRevProof = {
proof: preparedCredential.revStatus.mtp,
Expand All @@ -106,47 +109,63 @@ export class ZkpGen {
preparedCredential.revStatus.issuer.rootOfRoots!,
),
};
console.log('nonRevProof', this.nonRevProof);

this.timestamp = Math.floor(Date.now() / 1000);
console.log('timestamp', this.timestamp);

this.nodeAuxIssuerAuthNonRev = getNodeAuxValue(
this.circuitClaimData.signatureProof.issuerAuthNonRevProof.proof,
);
console.log('nodeAuxIssuerAuthNonRev', this.nodeAuxIssuerAuthNonRev);
this.nodeAuxNonRev = getNodeAuxValue(this.nonRevProof.proof);
console.log('nodeAuxNonRev', this.nodeAuxNonRev);
this.nodAuxJSONLD = getNodeAuxValue(this.query.valueProof!.mtp);
console.log('nodAuxJSONLD', this.nodAuxJSONLD);
this.value = prepareCircuitArrayValues(
this.query.values,
defaultValueArraySize,
).map((a) => a.toString());
console.log('value', this.value);

if (
this.proofRequest.circuitId === CircuitId.AtomicQuerySigV2OnChain ||
this.proofRequest.circuitId === CircuitId.AtomicQueryMTPV2OnChain
) {
console.log('this.proofRequest.circuitId === CircuitId.AtomicQuerySigV2OnChain || this.proofRequest.circuitId === CircuitId.AtomicQueryMTPV2OnChain');
const providerChainInfo = await getProviderChainInfo();
console.log('providerChainInfo', providerChainInfo);

const gistInfo = await getGISTProof({
rpcUrl: getRarimoEvmRpcUrl(providerChainInfo.id),
contractAddress: getRarimoStateContractAddress(providerChainInfo.id),
userId: this.identity.identityIdBigIntString,
rootHash: operationGistHash,
});
console.log('gistInfo', gistInfo);
this.gistProof = toGISTProof(gistInfo);
console.log('gistProof', this.gistProof);

const challenge = fromLittleEndian(
Hex.decodeString(this.proofRequest.accountAddress!.substring(2)),
).toString();
console.log('challenge', challenge);
this.challenge = BigInt(this.proofRequest.challenge ?? challenge);
console.log('this.challenge', this.challenge);

this.signatureChallenge = this.identity.privateKey.signPoseidon(
this.challenge,
);
console.log('this.signatureChallenge', this.signatureChallenge);

this.globalNodeAux = getNodeAuxValue(this.gistProof.proof);
console.log('this.globalNodeAux', this.globalNodeAux);
this.nodeAuxAuth = getNodeAuxValue(this.identity.authClaimNonRevProof);
console.log('this.nodeAuxAuth', this.nodeAuxAuth);
}

const circuiInfo = this.getCircuitInfo();
console.log('circuiInfo', circuiInfo);

const [wasm, provingKey] = await Promise.all([
readBytesFile(circuiInfo.wasm),
Expand All @@ -157,6 +176,7 @@ export class ZkpGen {
provingKey,
wasm,
);
console.log('subjectProof', this.subjectProof);

return this.subjectProof;
}
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6271,7 +6271,7 @@ __metadata:
languageName: node
linkType: hard

"@rarimo/[email protected], @rarimo/rarime-connector@workspace:^, @rarimo/rarime-connector@workspace:packages/connector":
"@rarimo/[email protected].1-rc.0, @rarimo/rarime-connector@workspace:^, @rarimo/rarime-connector@workspace:packages/connector":
version: 0.0.0-use.local
resolution: "@rarimo/rarime-connector@workspace:packages/connector"
dependencies:
Expand Down Expand Up @@ -6306,7 +6306,7 @@ __metadata:
"@metamask/snaps-jest": 0.35.2-flask.1
"@metamask/snaps-types": 0.32.2
"@metamask/snaps-ui": 0.32.2
"@rarimo/rarime-connector": 0.8.0
"@rarimo/rarime-connector": 0.8.1-rc.0
"@typechain/ethers-v5": 11.1.1
"@types/intl": 1.2.0
"@types/uuid": 9.0.2
Expand Down

0 comments on commit db65ce7

Please sign in to comment.