Skip to content

Commit

Permalink
Fix/disable init pairing if already paired (#48)
Browse files Browse the repository at this point in the history
* Disable init pairing rpc method is snap is alread paired (not for re pairing cases)

* Fix test cases for re pairing case
  • Loading branch information
dakshsilence committed Aug 8, 2024
1 parent d35f887 commit eb8862b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@silencelaboratories/silent-shard-snap-staging",
"version": "1.2.10-alpha.5",
"version": "1.2.10-alpha.6",
"author": "Silence Laboratories",
"license": "SEE LICENSE IN LICENSE.md",
"description": "Distributed wallet between Metamask plugin and SilentShard mobile app",
Expand Down Expand Up @@ -46,8 +46,8 @@
"@ethereumjs/util": "^9.0.3",
"@metamask/eth-sig-util": "^7.0.2",
"@metamask/keyring-api": "^8.0.0",
"@metamask/snaps-types": "^3.1.0",
"@metamask/snaps-sdk": "^6.0.0",
"@metamask/snaps-types": "^3.1.0",
"@metamask/utils": "^9.0.0",
"@silencelaboratories/ecdsa-tss": "^1.1.3",
"buffer": "^6.0.3",
Expand Down
4 changes: 2 additions & 2 deletions snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "1.2.10-alpha.5",
"version": "1.2.10-alpha.6",
"description": "Silent Shard creates a distributed self-custody account in MetaMask by generating a Distributed Private key between the browser extension and the Silent Shard mobile app using Multi-Party Computation (MPC). Thereby enabling a seamless 2FA experience for secure transactions.",
"proposedName": "Silent Shard",
"repository": {
"type": "git",
"url": "https://www.npmjs.com/package/@silencelaboratories/silent-shard-snap-staging"
},
"source": {
"shasum": "Vd+hfj/BzK795W/Fchm54oGPIebFupbZaBeForGFjX4=",
"shasum": "+2kFyjNbFXQw7xKfWLX+uf/J8fOh8+iXecM4BDhU9f4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
5 changes: 3 additions & 2 deletions src/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('test rpc requests to Snap', () => {
await backupPromise;

// Test init rePairing
const rePairingQrCode = await snapRepository.initPairing();
const rePairingQrCode = await snapRepository.initPairing(true);

// Test run rePairing
await simulator.pairing(rePairingQrCode, true);
Expand Down Expand Up @@ -199,7 +199,8 @@ describe('test rpc requests to Snap', () => {
}

// Test init rePairing
const rePairingQrCode = await snapRepository.initPairing();
simulator.A.changeSimulatorId();
const rePairingQrCode = await snapRepository.initPairing(true);
// Test run rePairing
await simulator.A.pairing(rePairingQrCode, true);
await snapRepository.runRePairing(simulator.A.getWalletAddress());
Expand Down
7 changes: 6 additions & 1 deletion src/__test__/simulator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Firebase } from './firebase';
import { SimulatorSdk } from './sdk';

export class Simulator {
#simulatorId: string = `simulator-${Math.floor(Math.random() * 1000000)}`;
sdk: SimulatorSdk | null = null;
firebase: Firebase;

Expand All @@ -25,12 +26,16 @@ export class Simulator {
try {
await this.firebase.signInFirebase();
// Using random UUID for testing only.
this.sdk = new SimulatorSdk(`simulator-${Math.floor(Math.random() * 1000000)}`, this.firebase.db);
this.sdk = new SimulatorSdk(this.#simulatorId, this.firebase.db);
} catch (error) {
console.error("signIn sim err", error);
}
};

changeSimulatorId = () => {
this.#simulatorId = `simulator-${Math.floor(Math.random() * 1000000)}`;
}

pairing = (qrCode: QrCode, isRepair = false) => {
try {
const sdk = this.getSdk();
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
const isRePair = (request.params as [{ isRePair: boolean }])[0]
.isRePair;
if (!isRePair) {
const isPairedRes = await sdk.isPaired();
if (isPairedRes.isPaired) {
throw new SnapError('Snap already paired', SnapErrorCode.SnapAlreadyPaired);
}
const initPairingRequest = await initPairingConfirmation();

if (!initPairingRequest) {
Expand Down
1 change: 1 addition & 0 deletions src/snap/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export enum SnapErrorCode {
UnknownMethod = 18,
UnknownError = 19,
BackupFailed = 20,
SnapAlreadyPaired = 21
}

0 comments on commit eb8862b

Please sign in to comment.