Skip to content

Commit

Permalink
feat: use snaps sdk (#526)
Browse files Browse the repository at this point in the history
Co-authored-by: martines3000 <[email protected]>
  • Loading branch information
andyv09 and martines3000 authored Dec 1, 2023
1 parent 3952981 commit 9504781
Show file tree
Hide file tree
Showing 42 changed files with 249 additions and 205 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-bugs-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@blockchain-lab-um/masca': patch
---

Replaced @metamask/snaps-types, snaps-utils and snaps-ui with @metamask/snaps-sdk
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@
"[email protected]": "patches/[email protected]",
"@ceramicnetwork/[email protected]": "patches/@[email protected]",
"@changesets/[email protected]": "patches/@[email protected]",
"@metamask/[email protected]": "patches/@[email protected]",
"@metamask/[email protected]": "patches/@[email protected]"
"@metamask/[email protected]": "patches/@[email protected]"
},
"allowNonAppliedPatches": true
}
Expand Down
10 changes: 4 additions & 6 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@
"@iden3/js-jwz": "1.0.1",
"@iden3/js-merkletree": "1.0.0",
"@metamask/key-tree": "^9.0.0",
"@metamask/providers": "13.1.0",
"@metamask/snaps-types": "3.0.1",
"@metamask/snaps-ui": "3.1.0",
"@metamask/utils": "^8.2.0",
"@metamask/providers": "14.0.2",
"@metamask/snaps-sdk": "1.2.0",
"@metamask/utils": "^8.2.1",
"@types/lodash.clonedeep": "^4.5.7",
"@veramo/core": "5.5.3",
"@veramo/credential-eip712": "5.5.3",
Expand Down Expand Up @@ -103,8 +102,7 @@
},
"devDependencies": {
"@ceramicnetwork/streamid": "2.17.0",
"@metamask/snaps-cli": "3.0.1",
"@metamask/snaps-utils": "3.2.0",
"@metamask/snaps-cli": "3.0.3",
"@types/elliptic": "^6.4.16",
"@types/jsonpath": "^0.2.2",
"@types/lodash.clonedeep": "^4.5.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"./files/circuits/credentialAtomicQuerySigV2/circuit_final.zkey",
"./files/circuits/credentialAtomicQuerySigV2/verification_key.json"
],
"shasum": "WpJFHZRVxpZbp/XiJ2lU+H/rvJ9QrGUs7mMInPfmHP8="
"shasum": "fb99U1A+m3KT+osaZo2Jrk8adHkz+AVHKK6pY7L6nHQ="
},
"initialPermissions": {
"endowment:ethereum-provider": {},
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/Ethereum.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
didMethodChainIdMapping,
MethodsRequiringNetwork,
} from '@blockchain-lab-um/masca-types';
import { divider, heading, panel, text } from '@metamask/snaps-ui';
import { divider, heading, panel, text } from '@metamask/snaps-sdk';

import UIService from './UI.service';

Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/UI.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
heading,
panel,
text,
} from '@metamask/snaps-ui';
} from '@metamask/snaps-sdk';
import { W3CVerifiableCredential } from '@veramo/core';

import StorageService from './storage/Storage.service';
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './polyfills/intl';

import { isValidSetCurrentAccountRequest } from '@blockchain-lab-um/masca-types';
import { ResultObject, type Result } from '@blockchain-lab-um/utils';
import type { OnRpcRequestHandler } from '@metamask/snaps-types';
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk';

import GeneralService from './General.service';
import SnapService from './Snap.service';
Expand All @@ -14,7 +14,7 @@ import WalletService from './Wallet.service';
export const onRpcRequest: OnRpcRequestHandler = async ({
request,
origin,
}): Promise<Result<unknown>> => {
}): Promise<Result<any>> => {
try {
await StorageService.init();

Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/cron/handleAuthorizationFlow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { beforeAll, describe, expect, it } from 'vitest';

import { onRpcRequest } from '../../src';
Expand All @@ -10,7 +10,7 @@ import { getDefaultSnapState } from '../data/defaultSnapState';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('handlePolygonFlow', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;

beforeAll(async () => {
snapMock = createMockSnap();
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/addFriendlyDapp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CURRENT_STATE_VERSION } from '@blockchain-lab-um/masca-types';
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { beforeAll, describe, expect, it, vi } from 'vitest';

import { onRpcRequest } from '../../src';
Expand All @@ -11,7 +11,7 @@ import { getDefaultSnapState } from '../data/defaultSnapState';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('addFriendlyDapp', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;

beforeAll(async () => {
snapMock = createMockSnap();
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/createVerifiableCredential.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@blockchain-lab-um/masca-types';
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import type { VerifiableCredential } from '@veramo/core';
import { beforeAll, describe, expect, it } from 'vitest';

Expand Down Expand Up @@ -35,7 +35,7 @@ const stores: AvailableCredentialStores[][] = [

describe('createVerifiableCredential', () => {
describe.each(methods)('Using method %s', (method) => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;
let issuer: string;
let agent: Agent;

Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/createVerifiablePresentation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AvailableMethods, ProofOptions } from '@blockchain-lab-um/masca-types';
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { Json, SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider, type Json } from '@metamask/snaps-sdk';
import { VerifiablePresentation } from '@veramo/core';
import { beforeAll, describe, expect, it } from 'vitest';

Expand Down Expand Up @@ -45,7 +45,7 @@ const vcs = [

describe('createVerifiablePresentation', () => {
describe.each(methods)('Using method %s', (method) => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;
let issuer: string;
let agent: Agent;

Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/deleteVerifiableCredentials.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isError, isSuccess, Result } from '@blockchain-lab-um/utils';
import { IDataManagerSaveResult } from '@blockchain-lab-um/veramo-datamanager';
import { DIDDataStore } from '@glazed/did-datastore';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import type { VerifiableCredential } from '@veramo/core';
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

Expand All @@ -18,7 +18,7 @@ import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('deleteCredential', () => {
let ceramicData: StoredCredentials;
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;
let agent: Agent;
let generatedVC: VerifiableCredential;

Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/exportStateBackup.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isError, Result } from '@blockchain-lab-um/utils';
import { IDataManagerSaveResult } from '@blockchain-lab-um/veramo-datamanager';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import type { IIdentifier, VerifiableCredential } from '@veramo/core';
import { beforeAll, describe, expect, it } from 'vitest';

Expand All @@ -16,7 +16,7 @@ import { createTestVCs } from '../helpers/generateTestVCs';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('exportStateBackup', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;
let identifier: IIdentifier;
let agent: Agent;
let generatedVC: VerifiableCredential;
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/getAccountSettings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CURRENT_STATE_VERSION } from '@blockchain-lab-um/masca-types';
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { beforeAll, describe, expect, it } from 'vitest';

import { onRpcRequest } from '../../src';
Expand All @@ -10,7 +10,7 @@ import { getDefaultSnapState } from '../data/defaultSnapState';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('getAccountSettings', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;

beforeAll(async () => {
snapMock = createMockSnap();
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/getAvailableMethods.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { availableMethods } from '@blockchain-lab-um/masca-types';
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { beforeAll, describe, expect, it } from 'vitest';

import { onRpcRequest } from '../../src';
Expand All @@ -10,7 +10,7 @@ import { getDefaultSnapState } from '../data/defaultSnapState';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('getAvailableMethods', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;

beforeAll(async () => {
snapMock = createMockSnap();
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/getAvailableVCStores.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { availableCredentialStores } from '@blockchain-lab-um/masca-types';
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { beforeAll, describe, expect, it } from 'vitest';

import { onRpcRequest } from '../../src';
Expand All @@ -10,7 +10,7 @@ import { getDefaultSnapState } from '../data/defaultSnapState';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('getAvailableCredentialStores', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;

beforeAll(async () => {
snapMock = createMockSnap();
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/getDID.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { beforeAll, describe, expect, it } from 'vitest';

import { onRpcRequest } from '../../src';
Expand Down Expand Up @@ -34,7 +34,7 @@ const methods = [
];

describe('getDID', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;

beforeAll(async () => {
snapMock = createMockSnap();
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/getSelectedMethod.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { beforeAll, describe, expect, it } from 'vitest';

import { onRpcRequest } from '../../src';
Expand All @@ -9,7 +9,7 @@ import { getDefaultSnapState } from '../data/defaultSnapState';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('getSelectedMethod', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;

beforeAll(async () => {
snapMock = createMockSnap();
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/getSnapSettings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CURRENT_STATE_VERSION } from '@blockchain-lab-um/masca-types';
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { beforeAll, describe, expect, it } from 'vitest';

import { onRpcRequest } from '../../src';
Expand All @@ -10,7 +10,7 @@ import { getDefaultSnapState } from '../data/defaultSnapState';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('getSnapSettings', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;

beforeAll(async () => {
snapMock = createMockSnap();
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/getVCStore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { beforeAll, describe, expect, it } from 'vitest';

import { onRpcRequest } from '../../src';
Expand All @@ -9,7 +9,7 @@ import { getDefaultSnapState } from '../data/defaultSnapState';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('getVCStore', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;

beforeAll(async () => {
snapMock = createMockSnap();
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/importStateBackup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type MascaState } from '@blockchain-lab-um/masca-types';
import { isError, Result } from '@blockchain-lab-um/utils';
import { IDataManagerSaveResult } from '@blockchain-lab-um/veramo-datamanager';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import type { IIdentifier, VerifiableCredential } from '@veramo/core';
import cloneDeep from 'lodash.clonedeep';
import { beforeAll, describe, expect, it } from 'vitest';
Expand All @@ -17,7 +17,7 @@ import { createTestVCs } from '../helpers/generateTestVCs';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('importStateBackup', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;
let identifier: IIdentifier;
let agent: Agent;
let generatedVC: VerifiableCredential;
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/queryVerifiableCredentials.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isError, Result } from '@blockchain-lab-um/utils';
import { IDataManagerSaveResult } from '@blockchain-lab-um/veramo-datamanager';
import { DIDDataStore } from '@glazed/did-datastore';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { VerifiableCredential } from '@veramo/core';
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

Expand All @@ -18,7 +18,7 @@ import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('queryVerifiableCredentials', () => {
let ceramicData: StoredCredentials;
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;
let agent: Agent;
let generatedVC: VerifiableCredential;

Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/removeFriendlyDapp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CURRENT_STATE_VERSION } from '@blockchain-lab-um/masca-types';
import { isError, Result } from '@blockchain-lab-um/utils';
import { IDataManagerSaveResult } from '@blockchain-lab-um/veramo-datamanager';
import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { VerifiableCredential } from '@veramo/core';
import { beforeAll, describe, expect, it, vi } from 'vitest';

Expand All @@ -17,7 +17,7 @@ import { createTestVCs } from '../helpers/generateTestVCs';
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('removeFriendlyDapp', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;
let generatedVC: VerifiableCredential;

beforeAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/tests/e2e/resolveDID.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isError, Result } from '@blockchain-lab-um/utils';
import { MetaMaskInpageProvider } from '@metamask/providers';
import { SnapsGlobalObject } from '@metamask/snaps-types';
import { SnapsProvider } from '@metamask/snaps-sdk';
import { DIDResolutionResult } from 'did-resolver';
import { beforeAll, describe, expect, it } from 'vitest';

Expand All @@ -19,7 +19,7 @@ import {
import { createMockSnap, SnapMock } from '../helpers/snapMock';

describe('resolveDID', () => {
let snapMock: SnapsGlobalObject & SnapMock;
let snapMock: SnapsProvider & SnapMock;

const methods = [EBSI, ENS, ION, CHEQD, WEB, ETHR, KEY] as const;

Expand Down
Loading

0 comments on commit 9504781

Please sign in to comment.