Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: snap types restructure #63

Merged
merged 33 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1e82529
feat: update vcStore
andyv09 Nov 15, 2022
a46dc4e
feat: update createVP & saveVC + add tests
andyv09 Nov 16, 2022
b42b4ca
test: add saveVC tests
andyv09 Nov 16, 2022
6f64c94
feat: deleteVC RPC method
andyv09 Nov 16, 2022
f890022
fix: rename vcStore to store
andyv09 Nov 16, 2022
047235c
fix: add options to saveVC
andyv09 Nov 16, 2022
fcee3e5
feat: query RPC method
andyv09 Nov 17, 2022
74448b3
fix: webpack build issue
andyv09 Nov 17, 2022
c6862d4
Merge branch 'develop' into feat/update-vcstore-settings
andyv09 Nov 17, 2022
9beff04
chore: prettier
andyv09 Nov 17, 2022
67ba010
chore: rename switchMethod to switchDIDMethod
andyv09 Nov 17, 2022
96e3d3c
fix: linting problems
andyv09 Nov 28, 2022
fa77a0d
Merge branch 'develop' into feat/update-vcstore-settings
andyv09 Nov 28, 2022
1c1b9b0
fix: fix merge errors
andyv09 Nov 28, 2022
d2e2150
feat: moved types and constant imports to ssi-snap-types package
tadejpodrekar Nov 28, 2022
f99a2df
feat: updated more imports
tadejpodrekar Nov 28, 2022
d0cad81
feat: changed types index file extension
tadejpodrekar Nov 28, 2022
a827d8d
fix: removed unused files and formatting
tadejpodrekar Nov 28, 2022
17dd257
Merge branch 'feat/update-vcstore-settings' of https://github.com/blo…
tadejpodrekar Nov 28, 2022
de8a875
fix: moved param types to ssi-snap-types
tadejpodrekar Nov 28, 2022
193de5e
fix: fixed lint errors and formatting
tadejpodrekar Nov 28, 2022
0700898
fix: fixed import
tadejpodrekar Nov 28, 2022
188e384
Merge branch 'develop' of https://github.com/blockchain-lab-um/ssi-sn…
tadejpodrekar Nov 30, 2022
78de35d
fix: correct import
tadejpodrekar Nov 30, 2022
fbd70ea
feat: fixed type imports after develop merge
tadejpodrekar Nov 30, 2022
22aa14f
fix: added missing changes from develop
tadejpodrekar Nov 30, 2022
ee0502f
chore: formatting
tadejpodrekar Nov 30, 2022
1fa6a99
fix: updated method names and params
tadejpodrekar Dec 1, 2022
5a53ed3
fix: updated snapApi params
tadejpodrekar Dec 1, 2022
073f44d
fix: fix typo
tadejpodrekar Dec 2, 2022
42d05b1
fix: put multicodec back to snap
martines3000 Dec 3, 2022
0fa760a
chore: lint
martines3000 Dec 3, 2022
0a436ad
fix: split type
martines3000 Dec 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/connector/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MetaMaskSSISnap } from './snap';
import { availableMethods } from '@blockchain-lab-um/ssi-snap-types';
import {
hasMetaMask,
isMetamaskSnapsSupported,
Expand All @@ -13,8 +14,6 @@ export {
isSnapInstalled,
} from './utils';

const availableMethods = ['did:ethr', 'did:key'] as const;

export type SnapInstallationParams = {
snapId?: string;
version?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/connector/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ declare global {
ethereum: {
isMetaMask: boolean;
isUnlocked: Promise<boolean>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
request: <T>(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
request: SnapRpcMethodRequest | { method: string; params?: any[] }
) => Promise<T>;
on: (eventName: unknown, callback: unknown) => unknown;
Expand Down
1 change: 1 addition & 0 deletions packages/connector/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type GetSnapsResponse = {
initialPermissions?: { [k: string]: unknown };
};
};

async function getWalletSnaps(): Promise<GetSnapsResponse> {
return await window.ethereum.request({
method: 'wallet_getSnaps',
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 @@ -7,7 +7,7 @@
"url": "https://github.com/blockchain-lab-um/ssi-snap.git"
},
"source": {
"shasum": "ezysdtfTZmZFD+9MzH+9lIuSkn7JUOIlL0LrMPQkdBw=",
"shasum": "7Z125vwgGxr55a8y60RygqL4DQjh9lBBJX2t0F+Uuf0=",
"location": {
"npm": {
"filePath": "dist/snap.js",
Expand Down
31 changes: 1 addition & 30 deletions packages/snap/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isIn = <T>(values: readonly T[], value: any): value is T => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return values.includes(value);
};

export const availableVCStores = ['snap', 'ceramic'] as const;
export type AvailableVCStores = typeof availableVCStores[number];

export const isAvailableVCStores = (x: string) => isIn(availableVCStores, x);

export const availableMethods = ['did:ethr', 'did:key'] as const;
export type AvailableMethods = typeof availableMethods[number];
export const isAvailableMethods = (x: string) => isIn(availableMethods, x);

export const didCoinTypeMappping: Record<string, number> = {
'did:ethr': 60,
'did:key': 60,
};

export const supportedProofFormats = [
'jwt',
'lds',
'EthereumEip712Signature2021',
] as const;

export type SupportedProofFormats = typeof supportedProofFormats[number];

export const isSupportedProofFormat = (x: string) =>
isIn(supportedProofFormats, x);
export * from './multicodec';
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Source: https://github.com/multiformats/multicodec/blob/master/table.csv

export type CodecName =
| 'secp256k1-priv'
| 'secp256k1-pub'
Expand Down
5 changes: 4 additions & 1 deletion packages/snap/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
SnapDIDStore,
SnapVCStore,
} from './veramo/plugins/snapDataStore/snapDataStore';
import { AvailableMethods, AvailableVCStores } from './constants/index';
import {
AvailableMethods,
AvailableVCStores,
} from '@blockchain-lab-um/ssi-snap-types';
import { SnapProvider } from '@metamask/snap-types';
import { BIP44CoinTypeNode } from '@metamask/key-tree';

Expand Down
4 changes: 2 additions & 2 deletions packages/snap/src/rpc/did/getAvailableMethods.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { availableMethods } from '../../constants/index';
import { availableMethods } from '@blockchain-lab-um/ssi-snap-types';

export function getAvailableMethods(): string[] {
return availableMethods.map((key) => key);
return availableMethods.map((key: string) => key);
}
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/did/switchMethod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SwitchMethodRequestParams } from 'src/utils/params';
import { SwitchMethodRequestParams } from '@blockchain-lab-um/ssi-snap-types';
import { ApiParams } from '../../interfaces';
import { changeCurrentMethod } from '../../utils/didUtils';
import { snapConfirm } from '../../utils/snapUtils';
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/snap/configure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/restrict-plus-operands */
import { ChangeInfuraTokenRequestParams } from 'src/utils/params';
import { ChangeInfuraTokenRequestParams } from '@blockchain-lab-um/ssi-snap-types';
import { ApiParams } from '../../interfaces';
import {
updateInfuraToken,
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/vc/createVP.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { veramoCreateVP } from '../../utils/veramoUtils';
import { VerifiablePresentation } from '@veramo/core';
import { ApiParams } from '../../interfaces';
import { AvailableVCStores } from 'src/constants';
import { AvailableVCStores } from '@blockchain-lab-um/ssi-snap-types';

type CreateVPRequestParams = {
vcs: [
Expand Down
3 changes: 1 addition & 2 deletions packages/snap/src/rpc/vc/queryVCs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { veramoListVCs } from '../../utils/veramoUtils';
import { VerifiableCredential } from '@veramo/core';
import { VCQuery } from '@blockchain-lab-um/ssi-snap-types';
import { VCQuery, QueryRequestParams } from '@blockchain-lab-um/ssi-snap-types';
import { snapConfirm } from '../../utils/snapUtils';
import { ApiParams } from '../../interfaces';
import { QueryRequestParams } from 'src/utils/params';

export async function queryVCs(
params: ApiParams,
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/vc/saveVC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SaveVCRequestParams } from 'src/utils/params';
import { SaveVCRequestParams } from '@blockchain-lab-um/ssi-snap-types';
import { ApiParams } from '../../interfaces';
import { snapConfirm } from '../../utils/snapUtils';
import { veramoSaveVC } from '../../utils/veramoUtils';
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/vcStore/getAvailableVCStores.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { availableVCStores } from '../../constants/index';
import { availableVCStores } from '@blockchain-lab-um/ssi-snap-types';

export function getAvailableVCStores(): string[] {
return availableVCStores.map((key: string) => key);
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/vcStore/setVCStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SetVCStoreRequestParams } from 'src/utils/params';
import { SetVCStoreRequestParams } from '@blockchain-lab-um/ssi-snap-types';
import { ApiParams } from '../../interfaces';
import { snapConfirm } from '../../utils/snapUtils';
import { updateSnapState } from '../../utils/stateUtils';
Expand Down
5 changes: 4 additions & 1 deletion packages/snap/src/utils/didUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { SnapProvider } from '@metamask/snap-types';
import { AvailableMethods, AvailableVCStores } from '../constants/index';
import {
AvailableMethods,
AvailableVCStores,
} from '@blockchain-lab-um/ssi-snap-types';
import { getDidKeyIdentifier } from '../did/key/keyDidUtils';
import { SSISnapState } from '../interfaces';
import { getCurrentNetwork } from './snapUtils';
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/utils/formatUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodecName, MULTICODECS } from '../constants/multicodecs';
import { CodecName, MULTICODECS } from '../constants';

/**
* Prefix a buffer with a multicodec-packed.
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/utils/keyPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import { ApiParams, SSISnapState } from 'src/interfaces';
import { getAccountIndex, setAccountIndex } from './snapUtils';
import { ethers } from 'ethers';
import { didCoinTypeMappping } from '../constants/index';
import { didCoinTypeMappping } from '@blockchain-lab-um/ssi-snap-types';
import { SnapProvider } from '@metamask/snap-types';

export async function getAddressKeyDeriver(
Expand Down
73 changes: 9 additions & 64 deletions packages/snap/src/utils/params.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,15 @@
import { W3CVerifiableCredential } from '@veramo/core';
import {
AvailableMethods,
AvailableVCStores,
isAvailableMethods,
isAvailableVCStores,
isAvailableMethods,
isSupportedProofFormat,
SupportedProofFormats,
} from '../constants';

export type CreateVPRequestParams = {
vcs: [
{
id: string;
metadata?: {
store?: AvailableVCStores;
};
}
];
proofFormat?: SupportedProofFormats;
proofOptions?: {
type?: string;
domain?: string;
challenge?: string;
};
};

type QueryFilter = { type: string; filter: unknown };

type QueryOptions = {
store?: AvailableVCStores | [AvailableVCStores];
returnStore?: boolean;
};

export type QueryRequestParams = {
filter?: QueryFilter;
options?: QueryOptions;
};

type SaveVCOptions = {
store?: AvailableVCStores | [AvailableVCStores];
};

export type SaveVCRequestParams = {
verifiableCredential: W3CVerifiableCredential;
options?: SaveVCOptions;
};

type DeleteVCRequestParams = {
id: string | [string];
options?: {
store?: AvailableVCStores | [AvailableVCStores];
};
};

export type ChangeInfuraTokenRequestParams = {
infuraToken: string;
};

export type SwitchMethodRequestParams = {
didMethod: AvailableMethods;
};

export type SetVCStoreRequestParams = {
store: AvailableVCStores;
value: boolean;
};
CreateVPRequestParams,
SaveVCRequestParams,
QueryRequestParams,
ChangeInfuraTokenRequestParams,
SwitchMethodRequestParams,
SetVCStoreRequestParams,
DeleteVCRequestParams,
} from '@blockchain-lab-um/ssi-snap-types';

function isStringArray(input: unknown): input is string[] {
return (
Expand Down
3 changes: 1 addition & 2 deletions packages/snap/src/utils/veramoUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Agent, getAgent } from './../veramo/setup';
import { VCQuery } from '@blockchain-lab-um/ssi-snap-types';
import { AvailableVCStores, VCQuery } from '@blockchain-lab-um/ssi-snap-types';
import {
IIdentifier,
MinimalImportableKey,
Expand All @@ -10,7 +10,6 @@ import {
import { getCurrentDid } from './didUtils';
import { getPublicKey, snapConfirm } from './snapUtils';
import { SnapProvider } from '@metamask/snap-types';
import { AvailableVCStores } from '../constants/index';
import { ApiParams } from '../interfaces';
import { snapGetKeysFromAddress } from './keyPair';
import { BIP44CoinTypeNode } from '@metamask/key-tree';
Expand Down
5 changes: 4 additions & 1 deletion packages/snap/tests/rpc/onRpcRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
exampleVC,
getDefaultSnapState,
} from '../testUtils/constants';
import { availableVCStores, availableMethods } from '../../src/constants/index';
import {
availableVCStores,
availableMethods,
} from '@blockchain-lab-um/ssi-snap-types';
import {
IVerifyResult,
VerifiableCredential,
Expand Down
30 changes: 30 additions & 0 deletions packages/types/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isIn = <T>(values: readonly T[], value: any): value is T => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return values.includes(value);
};

export const availableVCStores = ['snap', 'ceramic'] as const;
export type AvailableVCStores = typeof availableVCStores[number];

export const isAvailableVCStores = (x: string) => isIn(availableVCStores, x);

export const availableMethods = ['did:ethr', 'did:key'] as const;
export type AvailableMethods = typeof availableMethods[number];
export const isAvailableMethods = (x: string) => isIn(availableMethods, x);

export const didCoinTypeMappping: Record<string, number> = {
'did:ethr': 60,
'did:key': 60,
};

export const supportedProofFormats = [
'jwt',
'lds',
'EthereumEip712Signature2021',
] as const;

export type SupportedProofFormats = typeof supportedProofFormats[number];

export const isSupportedProofFormat = (x: string) =>
isIn(supportedProofFormats, x);
Loading