Skip to content

Commit

Permalink
Fixed handling legacy DIDs (#34)
Browse files Browse the repository at this point in the history
* detect unsupported did method

* update creating proof msg

* hotfix

* update subtitles for proof generating method

* Update packages/snap/src/index.ts

* update changelog & bump v

* hotfix

* changelog

* silence recreating identity

* update changelog, rollback snap manifest files

* hotfix

* Update CHANGELOG.md

* bump v

---------

Co-authored-by: Ihor Diachenko <[email protected]>
  • Loading branch information
lukachi and ihordiachenko authored Feb 5, 2024
1 parent 8da36ed commit a95d079
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `@rarimo/rarime`:
- Creating proof "approve message"

### Fixed
- `@rarimo/rarime`:
- `Creating Identity` - added more checks within DID.parse to handle legacy DIDs

## [2.0.2] - 2024-02-01
### Added
- `@rarimo/rarime`:
Expand Down
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": "2.0.3",
"version": "2.0.3-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": "2.0.3"
"version": "2.0.3-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": "2.0.3",
"version": "2.0.3-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": "2.0.3",
"version": "2.0.3-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 @@ -56,7 +56,7 @@
"@metamask/snaps-jest": "^4.0.0",
"@metamask/snaps-sdk": "^1.1.0",
"@metamask/snaps-utils": "^4.0.0",
"@rarimo/rarime-connector": "2.0.3",
"@rarimo/rarime-connector": "2.0.3-rc.0",
"buffer": "6.0.3",
"dids": "4.0.4",
"ethers": "5.7.2",
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": "2.0.3",
"version": "2.0.3-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": "dzRQl3ZoJOO/JgVTiWHQbfti5MJuZJUcL0skXceVsTs=",
"shasum": "IBF9Zeb8j5hVhCK31vFpPD+Iz/ZBYw0CqmW46faRcLg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
14 changes: 14 additions & 0 deletions packages/snap/src/helpers/identity-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ export const parseDidV2 = (did: string): DID => {

return DID.parse(`did:iden3:readonly:${splitted[splitted.length - 1]}`);
};

export const isDidSupported = (identityId: string): boolean => {
try {
const parsed = DID.parse(identityId);

const id = DID.idFromDID(parsed);

const parts = DID.decodePartsFromId(id);

return !DID.isUnsupported(parts.method, parts.blockchain, parts.networkId);
} catch (error) {
return false;
}
};
47 changes: 24 additions & 23 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getHostname,
getProviderChainInfo,
getRarimoCoreUrl,
isDidSupported,
loadDataFromRarimoCore,
migrateVCsToLastCeramicModel,
parseDidV2,
Expand Down Expand Up @@ -155,31 +156,31 @@ export const onRpcRequest = async ({
case RPCMethods.CreateIdentity: {
const identityStorage = await getItemFromStore(StorageKeys.identity);

if (identityStorage?.did && identityStorage?.didBigInt) {
try {
if (DID.parse(identityStorage?.did)) {
return {
identityIdString: identityStorage.did,
identityIdBigIntString: identityStorage.didBigInt,
};
}
} catch (error) {
/* empty */
}
if (
identityStorage?.did &&
identityStorage?.didBigInt &&
isDidSupported(identityStorage.did)
) {
return {
identityIdString: identityStorage.did,
identityIdBigIntString: identityStorage.didBigInt,
};
}

const res = await snap.request({
method: 'snap_dialog',
params: {
type: 'confirmation',
content: panel([
heading('Identity creation'),
divider(),
text(`You don't have an identity yet`),
text('Would you like to create?'),
]),
},
});
const res =
Boolean(identityStorage?.did && identityStorage?.didBigInt) ||
(await snap.request({
method: 'snap_dialog',
params: {
type: 'confirmation',
content: panel([
heading('Identity creation'),
divider(),
text(`You don't have an identity yet`),
text('Would you like to create one?'),
]),
},
}));

if (res) {
const entropy = await snap.request({
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7460,7 +7460,7 @@ __metadata:
languageName: node
linkType: hard

"@rarimo/[email protected], @rarimo/rarime-connector@workspace:^, @rarimo/rarime-connector@workspace:packages/connector":
"@rarimo/[email protected]-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 @@ -7505,7 +7505,7 @@ __metadata:
"@metamask/snaps-jest": ^4.0.0
"@metamask/snaps-sdk": ^1.1.0
"@metamask/snaps-utils": ^4.0.0
"@rarimo/rarime-connector": 2.0.3
"@rarimo/rarime-connector": 2.0.3-rc.0
"@typechain/ethers-v5": 11.1.1
"@types/intl": 1.2.0
"@types/lodash": ^4.14.202
Expand Down

0 comments on commit a95d079

Please sign in to comment.