diff --git a/packages/connector/package.json b/packages/connector/package.json index 05b87929..34ff0eca 100644 --- a/packages/connector/package.json +++ b/packages/connector/package.json @@ -1,6 +1,6 @@ { "name": "@rarimo/rarime-connector", - "version": "2.1.0-rc.17", + "version": "2.1.0-rc.18", "description": "Facilitates interaction between a DApp and RariMe MetaMask snap", "repository": { "type": "git", diff --git a/packages/connector/src/consts/general.ts b/packages/connector/src/consts/general.ts index afc71c31..1347dc21 100644 --- a/packages/connector/src/consts/general.ts +++ b/packages/connector/src/consts/general.ts @@ -1,2 +1,2 @@ export const CORE_POLLING_INTERVAL = 5_000; -export const SUPPORTED_METAMASK_VERSION = '11.12.0'; +export const SUPPORTED_METAMASK_VERSION = '11.13.0'; diff --git a/packages/connector/src/version.json b/packages/connector/src/version.json index edbc4475..4178887f 100644 --- a/packages/connector/src/version.json +++ b/packages/connector/src/version.json @@ -1,3 +1,3 @@ { - "version": "2.1.0-rc.17" + "version": "2.1.0-rc.18" } diff --git a/packages/snap/package.json b/packages/snap/package.json index 76873f77..4160c4f6 100644 --- a/packages/snap/package.json +++ b/packages/snap/package.json @@ -1,6 +1,6 @@ { "name": "@rarimo/rarime", - "version": "2.1.0-rc.17", + "version": "2.1.0-rc.18", "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", @@ -10,8 +10,8 @@ "files": [ "dist/", "images/", - "assets/circuits/auth", - "assets/circuits/credentialAtomicQueryMTPV2OnChain", + "assets/circuits/auth/", + "assets/circuits/credentialAtomicQueryMTPV2OnChain/", "snap.manifest.json", "README.md" ], diff --git a/packages/snap/package/README.md b/packages/snap/package/README.md new file mode 100644 index 00000000..e581392e --- /dev/null +++ b/packages/snap/package/README.md @@ -0,0 +1,230 @@ +# RariMe + +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. + +## Methods + +### Create an identity + +To create an identity you need to call this method: + +```javascript +await window.ethereum.request({ + method: 'wallet_invokeSnap', + params: { + snapId: 'snapId', + request: { method: 'create_identity' }, + }, +}); +``` + +### Get identity + +Returns DID and DID in big int string format if they are exists, otherwise method throws error. + +```javascript +await window.ethereum.request({ + method: 'wallet_invokeSnap', + params: { + snapId: 'snapId', + request: { method: 'get_identity' }, + }, +}); +``` + +### Export identity + +To export an identity you need to call this method: + +```javascript +await window.ethereum.request({ + method: 'wallet_invokeSnap', + params: { + snapId: 'snapId', + request: { method: 'export_identity' }, + }, +}); +``` + +### Save Verifiable Credentials + +To save Verifiable Credentials you need to call this method with params: + +```javascript +await window.ethereum.request({ + method: 'wallet_invokeSnap', + params: { + snapId: 'snapId', + request: { + method: 'save_credentials', + params: { + body: { + credentials: [ + { + description: 'Natural Person', + id: '86531650-023c-4c6c-a437-a82e137ead68', + }, + ], + url: 'http://127.0.0.1:8000/integrations/issuer/v1/public/claims/offers/callback', + }, + from: 'did:iden3:tJnRoZ1KqUPbsfVGrk8io51iqoRc5dGhj5LLMHSrD', + id: '026035f6-42f6-4a2d-b516-0b11d2674850', + thid: '348b7198-7cb1-46f4-bc0a-98a358f65539', + to: 'did:iden3:tTxif8ahrSqRWavS8Qatrp4ZEJvPdu3ELSMgqTEQN', + typ: 'application/iden3comm-plain-json', + type: 'https://iden3-communication.io/credentials/1.0/offer', + }, + }, + }, +}); +``` + +where: + +- **id**: request identifier +- **thid**: ID of the message thread +- **from**: identifier of the person from whom the offer was received +- **to**: identifier of the person who received the offer +- **typ**: media type of the message. In our case, it is the type of the protocol of the packed message application/iden3comm-plain-json +- **type**: type of iden3comm protocol message +- **body** + - **credentials[0]** + - **description**: description of the schema + - **id**: credential id + - **url**: URL to which requested information is sent and response is received + +### Remove Verifiable Credentials + +```javascript +return await window.ethereum.request({ + method: 'wallet_invokeSnap', + params: { + request: { + method: 'remove_credentials', + params: { + ids: [ + 'https://example.issuer.node.api.com/v1/credentials/86531650-023c-4c6c-a437-a82e137ead68', + ], + }, + }, + snapId: 'local:http://localhost:8081', + }, +}); +``` + +where: + +- **ids**: list of claim ids to remove, e. g. `W3CCredential.id` + +### Create a proof + +Make sure you are on the correct network before creating a proof! +Returns ZKProof for off-chain and updateStateTx, statesMerkleData, ZKProof for on-chain +To create a proof you need to call this method with params: + +```javascript +await window.ethereum.request({ + method: 'wallet_invokeSnap', + params: { + snapId: 'snapId', + request: { + method: 'create_proof', + params: { + circuitId: 'credentialAtomicQuerySigV2OnChain', + issuerDid: 'did:iden3:[...]', + accountAddress: '0x......', + challenge: '1251760352881625298994789945427452069454957821390', // BigInt string + query: { + allowedIssuers: ['*'], + credentialSubject: { + isNatural: { + $eq: 1, + }, + }, + type: 'IdentityProviders', + }, + }, + }, + }, +}); +``` + +where: + +- **circuitId**: type of proof +- **accountAddress**(optional): Metamask user address for onchain proofs +- **issuerDid**: did of the issuer trusted by the verifier +- **challenge**(optional): text that will be signed +- **query** + - **allowedIssuers**: types of issuers allowed + - **\***: all types of Issuers are allowed + - **context**: URL for getting the vocabulary for the credential + - **type**: type of credentials allowed + - **credentialSubject**: query request to a query circuit + +### Check state contract + +Returns `true` if the state contract on current chain need to be synced: + +```javascript +await window.ethereum.request({ + method: 'wallet_invokeSnap', + params: { + snapId: 'snapId', + request: { + method: 'check_state_contract_sync', + }, + }, +}); +``` + +### Get Verifiable Credentials + +- Only supported domains + +Return a list of Verifiable Credentials: + +```javascript +await window.ethereum.request({ + method: 'wallet_invokeSnap', + params: { + snapId: 'snapId', + request: { + method: 'get_credentials', + }, + }, +}); +``` + +## Testing + +The snap comes with some basic tests, to demonstrate how to write tests for +snaps. To test the snap, run `yarn test` in this directory. This will use +[`@metamask/snaps-jest`](https://github.com/MetaMask/snaps/tree/main/packages/snaps-jest) +to run the tests in `src/index.test.ts`. + +## Development + +## Prepare ceramic json files and deploy (example) + +### Prerequisites + +First things first, follow steps on Ceramic composeDB [guide](https://developers.ceramic.network/docs/composedb/set-up-your-environment#setup) to prepare environment and get `CERAMIC_URL` with `DID_PRIVATE_KEY` variables. + +### Run script to prepare json files + +```bash +CERAMIC_URL=http://... DID_PRIVATE_KEY=fbb8731ecc9c36542f9caf9d9e3535c8... yarn workspace @rarimo/rarime ceramic:prepare-vc +``` + +### Run Graphql server locally + +```bash +CERAMIC_URL=http://... DID_PRIVATE_KEY=fbb8731ecc9c36542f9caf9d9e3535c8... yarn workspace @rarimo/rarime ceramic:graphql-server +``` + +## Notes + +- Babel is used for transpiling TypeScript to JavaScript, so when building with + the CLI, `transpilationMode` must be set to `localOnly` (default) or + `localAndDeps`. diff --git a/packages/snap/package/assets/circuits/auth/circuit.wasm b/packages/snap/package/assets/circuits/auth/circuit.wasm new file mode 100644 index 00000000..d44976ed Binary files /dev/null and b/packages/snap/package/assets/circuits/auth/circuit.wasm differ diff --git a/packages/snap/package/assets/circuits/auth/circuit_final.zkey b/packages/snap/package/assets/circuits/auth/circuit_final.zkey new file mode 100644 index 00000000..cb66562d Binary files /dev/null and b/packages/snap/package/assets/circuits/auth/circuit_final.zkey differ diff --git a/packages/snap/package/assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit.wasm b/packages/snap/package/assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit.wasm new file mode 100644 index 00000000..bc370189 Binary files /dev/null and b/packages/snap/package/assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit.wasm differ diff --git a/packages/snap/package/assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey b/packages/snap/package/assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey new file mode 100644 index 00000000..36e352b4 Binary files /dev/null and b/packages/snap/package/assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey differ diff --git a/packages/snap/package/assets/circuits/credentialAtomicQueryMTPV2OnChain/verification_key.json b/packages/snap/package/assets/circuits/credentialAtomicQueryMTPV2OnChain/verification_key.json new file mode 100644 index 00000000..a7ac13b7 --- /dev/null +++ b/packages/snap/package/assets/circuits/credentialAtomicQueryMTPV2OnChain/verification_key.json @@ -0,0 +1,135 @@ +{ + "protocol": "groth16", + "curve": "bn128", + "nPublic": 11, + "vk_alpha_1": [ + "20491192805390485299153009773594534940189261866228447918068658471970481763042", + "9383485363053290200918347156157836566562967994039712273449902621266178545958", + "1" + ], + "vk_beta_2": [ + [ + "6375614351688725206403948262868962793625744043794305715222011528459656738731", + "4252822878758300859123897981450591353533073413197771768651442665752259397132" + ], + [ + "10505242626370262277552901082094356697409835680220590971873171140371331206856", + "21847035105528745403288232691147584728191162732299865338377159692350059136679" + ], + ["1", "0"] + ], + "vk_gamma_2": [ + [ + "10857046999023057135944570762232829481370756359578518086990519993285655852781", + "11559732032986387107991004021392285783925812861821192530917403151452391805634" + ], + [ + "8495653923123431417604973247489272438418190587263600148770280649306958101930", + "4082367875863433681332203403145435568316851327593401208105741076214120093531" + ], + ["1", "0"] + ], + "vk_delta_2": [ + [ + "21107007358082136795614874512538836487771939470796762405748007366166733704104", + "10069053650952764050770858763214373754669660210324204774418789033662943009749" + ], + [ + "8559222867245112767064473074858818732424559824983124225374445082554790506808", + "4852486786898691455964846082763016922630372558821263656172370355988314898575" + ], + ["1", "0"] + ], + "vk_alphabeta_12": [ + [ + [ + "2029413683389138792403550203267699914886160938906632433982220835551125967885", + "21072700047562757817161031222997517981543347628379360635925549008442030252106" + ], + [ + "5940354580057074848093997050200682056184807770593307860589430076672439820312", + "12156638873931618554171829126792193045421052652279363021382169897324752428276" + ], + [ + "7898200236362823042373859371574133993780991612861777490112507062703164551277", + "7074218545237549455313236346927434013100842096812539264420499035217050630853" + ] + ], + [ + [ + "7077479683546002997211712695946002074877511277312570035766170199895071832130", + "10093483419865920389913245021038182291233451549023025229112148274109565435465" + ], + [ + "4595479056700221319381530156280926371456704509942304414423590385166031118820", + "19831328484489333784475432780421641293929726139240675179672856274388269393268" + ], + [ + "11934129596455521040620786944827826205713621633706285934057045369193958244500", + "8037395052364110730298837004334506829870972346962140206007064471173334027475" + ] + ] + ], + "IC": [ + [ + "1313452981527053129337572951247197324361989034671138626745310268341512913566", + "15303507074060980322389491486850010383524156520378503449579570642767442684301", + "1" + ], + [ + "19469759548582862041953210077461806234755067239635831761330214958262728102210", + "16182855449814336395630220912227600929619756764754084585163045607249874698864", + "1" + ], + [ + "5328220111696630739082100852965753471276442277347833726730125705096477686086", + "18905255288005092837452154631677141443252188654645540166408868771529766552954", + "1" + ], + [ + "10933184819912527903586676306361564765563053120720138042486726178048079682568", + "18280626518907496130958526005677563160967544228407334084744886760261543167298", + "1" + ], + [ + "11558797904750992453617754478260603596631069504995139547656018378652112039786", + "7387560020132856716152855364841368262707029595898949014465420811988605836841", + "1" + ], + [ + "258345740540242369340676522345540363903777759573849221853370493977314124714", + "8261745575084416750025555445617776886593428107172740509334601364674159098729", + "1" + ], + [ + "12229618381132244012134195568281704584580345418094236823704672151870483088680", + "19652481126909183227792433955062439643525977794731426347743513078747968248518", + "1" + ], + [ + "21501269229626602828017941470237394838663343517747470934919163514713566489074", + "10918047203423236169474519778878366520860074771272087858656960949070403283927", + "1" + ], + [ + "560417708851693272956571111854350209791303214876197214262570647517120871869", + "188344482860559912840076092213437046073780559836275799283864998836054113147", + "1" + ], + [ + "12941763790218889190383140140219843141955553218417052891852216993045901023120", + "12682291388476462975465775054567905896202239758296039216608811622228355512204", + "1" + ], + [ + "11112576039136275785110528933884279009037779878785871940581425517795519742410", + "6613377654128709188004788921975143848004552607600543819185067176149822253345", + "1" + ], + [ + "13613305841160720689914712433320508347546323189059844660259139894452538774575", + "5325101314795154200638690464360192908052407201796948025470533168336651686116", + "1" + ] + ] +} diff --git a/packages/snap/package/images/icon.svg b/packages/snap/package/images/icon.svg new file mode 100644 index 00000000..ae3ab83a --- /dev/null +++ b/packages/snap/package/images/icon.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/packages/snap/package/package.json b/packages/snap/package/package.json new file mode 100644 index 00000000..4160c4f6 --- /dev/null +++ b/packages/snap/package/package.json @@ -0,0 +1,100 @@ +{ + "name": "@rarimo/rarime", + "version": "2.1.0-rc.18", + "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", + "url": "https://github.com/rarimo/rarime.git" + }, + "license": "(MIT-0 OR Apache-2.0)", + "files": [ + "dist/", + "images/", + "assets/circuits/auth/", + "assets/circuits/credentialAtomicQueryMTPV2OnChain/", + "snap.manifest.json", + "README.md" + ], + "scripts": { + "build": "yarn clean && node build.js && yarn build:post && yarn bundle:eval && yarn bundle:manifest", + "build:clean": "yarn clean && yarn build", + "build:post": "node post-process.js", + "bundle:eval": "mm-snap eval -b dist/bundle.js", + "bundle:manifest": "mm-snap manifest --fix", + "ceramic:graphql-server": "composedb graphql:server --ceramic-url=$CERAMIC_URL --graphiql ./ceramic/composites/VerifiableCredentialsV2-runtime.json --did-private-key=$DID_PRIVATE_KEY --port=5005", + "ceramic:prepare-vc": "node ceramic-prepare-vc.mjs", + "clean": "rimraf dist", + "composedb": "composedb", + "generate-graphql-types": "graphql-codegen --config ./codegen.ts", + "lint": "yarn lint:eslint && yarn lint:misc --check", + "lint:eslint": "eslint . --cache --ext js,ts", + "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write", + "lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path .gitignore", + "prepublishOnly": "yarn && yarn build", + "serve": "mm-snap serve", + "start": "nodemon --watch src/ --ext ts --exec 'yarn build && yarn serve'", + "typia:generate": "typia generate --input src/typia-templates --output src/typia-generated --project tsconfig.json", + "preversion": "yarn && yarn build && git add snap.manifest.json" + }, + "dependencies": { + "@apollo/client": "^3.8.7", + "@ceramicnetwork/http-client": "2.27.0", + "@composedb/client": "^0.6.0", + "@ethersproject/abi": "5.0.0", + "@ethersproject/bytes": "5.7.0", + "@ethersproject/keccak256": "5.7.0", + "@ethersproject/providers": "5.7.2", + "@glazed/did-datastore": "0.3.2", + "@iden3/js-crypto": "1.0.3", + "@iden3/js-iden3-core": "1.2.1", + "@iden3/js-jsonld-merklization": "1.1.2", + "@iden3/js-jwz": "1.3.0", + "@iden3/js-merkletree": "1.1.2", + "@metamask/snaps-jest": "^5.0.0", + "@metamask/snaps-sdk": "^3.0.1", + "@metamask/snaps-utils": "^7.0.3", + "@rarimo/rarime-connector": "workspace:^", + "buffer": "6.0.3", + "dids": "4.0.4", + "ethers": "5.7.2", + "graphql": "^16.8.1", + "graphql-tag": "^2.12.6", + "intl": "1.2.5", + "key-did-provider-ed25519": "3.0.2", + "key-did-resolver": "3.0.0", + "lodash": "^4.17.21", + "snarkjs": "^0.7.2", + "typia": "4.1.3", + "uuid": "9.0.0" + }, + "devDependencies": { + "@composedb/types": "^0.5.1", + "@graphql-codegen/cli": "^5.0.0", + "@graphql-codegen/typescript": "^4.0.1", + "@graphql-codegen/typescript-document-nodes": "^4.0.1", + "@graphql-codegen/typescript-operations": "^4.0.1", + "@jest/globals": "29.5.0", + "@lavamoat/allow-scripts": "2.0.3", + "@metamask/auto-changelog": "^3.4.4", + "@metamask/snaps-cli": "^6.1.0", + "@typechain/ethers-v5": "11.1.1", + "@types/intl": "1.2.0", + "@types/lodash": "^4.14.202", + "@types/uuid": "9.0.2", + "esbuild": "0.17.19", + "node-stdlib-browser": "1.2.0", + "nodemon": "2.0.20", + "npm-commands": "^1.2.1", + "rimraf": "3.0.2", + "typechain": "8.3.1", + "typescript": "4.7.4" + }, + "packageManager": "yarn@3.2.1", + "engines": { + "node": ">=16.0.0" + }, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org/" + } +} diff --git a/packages/snap/package/snap.manifest.json b/packages/snap/package/snap.manifest.json new file mode 100644 index 00000000..b6a783b3 --- /dev/null +++ b/packages/snap/package/snap.manifest.json @@ -0,0 +1,40 @@ +{ + "version": "2.1.0-rc.18", + "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": "tKCoTXua9T5xc9XxKcK7afiSE1WDczUBPVl3rhhKhBA=", + "location": { + "npm": { + "filePath": "dist/bundle.js", + "iconPath": "images/icon.svg", + "packageName": "@rarimo/rarime", + "registry": "https://registry.npmjs.org/" + } + }, + "files": [ + "./assets/circuits/auth/circuit.wasm", + "./assets/circuits/auth/circuit_final.zkey", + "./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit.wasm", + "./assets/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey" + ] + }, + "initialPermissions": { + "snap_dialog": {}, + "endowment:rpc": { + "dapps": true, + "snaps": true, + "maxRequestTime": 180000 + }, + "snap_manageState": {}, + "endowment:network-access": {}, + "endowment:webassembly": {}, + "endowment:ethereum-provider": {}, + "snap_getEntropy": {} + }, + "manifestVersion": "0.1" +} diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index fce6891b..3e2167ae 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -1,5 +1,5 @@ { - "version": "2.1.0-rc.17", + "version": "2.1.0-rc.18", "description": "Securely store and manage all of your identity credentials. Use them across chains with ZK-protected privacy guarantees.", "proposedName": "RariMe", "repository": { @@ -7,7 +7,7 @@ "url": "https://github.com/rarimo/rarime.git" }, "source": { - "shasum": "tKCoTXua9T5xc9XxKcK7afiSE1WDczUBPVl3rhhKhBA=", + "shasum": "AZlDJsV6PX/MhjBOkzj7PrvSJuIvIiaSzPcwMkKevl8=", "location": { "npm": { "filePath": "dist/bundle.js",