Skip to content

Commit

Permalink
rollback creating identity by snap_GetEntropy
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Feb 9, 2024
1 parent e9c0d3b commit b01193c
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,34 +243,41 @@ export const onRpcRequest = async ({
},
}));

if (res) {
const identity = await Identity.create(params?.privateKeyHex);
if (!res) {
throw new Error('User rejected request');
}

await setItemInStore(StorageKeys.identity, {
privateKeyHex: identity.privateKeyHex,
did: identity.didString,
didBigInt: identity.identityIdBigIntString,
});
const entropy = await snap.request({
method: 'snap_getEntropy',
params: { version: 1 },
});
const keyHex = entropy.startsWith('0x') ? entropy.substring(2) : entropy;

await snap.request({
method: 'snap_dialog',
params: {
type: 'alert',
content: panel([
heading('Your RariMe is ready for use!'),
divider(),
text('Your unique identifier(DID):'),
copyable(identity.didString),
]),
},
});
const identity = await Identity.create(params?.privateKeyHex || keyHex);

return {
identityIdString: identity.didString,
identityIdBigIntString: identity.identityIdBigIntString,
};
}
throw new Error('User rejected request');
await setItemInStore(StorageKeys.identity, {
privateKeyHex: identity.privateKeyHex,
did: identity.didString,
didBigInt: identity.identityIdBigIntString,
});

await snap.request({
method: 'snap_dialog',
params: {
type: 'alert',
content: panel([
heading('Your RariMe is ready for use!'),
divider(),
text('Your unique identifier(DID):'),
copyable(identity.didString),
]),
},
});

return {
identityIdString: identity.didString,
identityIdBigIntString: identity.identityIdBigIntString,
};
}

case RPCMethods.GetIdentity: {
Expand Down

0 comments on commit b01193c

Please sign in to comment.