Skip to content

Commit

Permalink
feat: switch to MetaMask private keys (#45)
Browse files Browse the repository at this point in the history
* feat: add ceramic tests

* feat: add test for did key document

* fix: fix yarn install problem

* fix: update yarn lock

* fix: fix yarnrc.yml

* fix: remove SnapKeyStore

* fix: fixes lint issues, adds interactive-tools

* feat: add bip44entropy

* chore: get latest commit

* fix: fix some old issues and add jest-eslint plugin

* fix: ignore coverage in prettier

* chore: upgrade veramo + metamask

* docs: update discord link

Co-authored-by: martines3000 <domajnko.martin@gmail.com>

* chore: upgrade veramo + metamask

* fix: create apiParams object

* fix: fix veramoCreateVP

* chore: remove unnecessary imports

* feat: upgrade to CredentialPlugin

* feat: add getKeysFromAddress function

* feat: generate public key from private key

* fix: fix some tests

* Merge feat/ceramic-tests into feat/mm-private-keys (#44)

* docs: remove mentions of rinkeby (#34)

* docs: remove rinkeby mentions

Co-authored-by: martines3000 <domajnko.martin@gmail.com>

* fix: fixes deploy workflow (#37)

* fix: should fix deploy_docs workflow

* fix: depend on built packages when starting snap package (#38)

* fix: release please for monorepo (#39)

* fix: should fix release-please workflow

* chore: try to fix release

* chore: add dispatch to release

* chore: change last release sha

* chore: update bootstrap-sha

* fix: fix some old issues and add jest-eslint plugin

* fix: ignore coverage in prettier

* chore: upgrade veramo + metamask

* docs: update discord link

* feat: integrates nx-cloud and updates workflows (#42)

* feat: adds nx-cloud and updates workflows

* fix: change default branch and set node-version

* fix: volta pin versions

* chore: test forked workflow

* chore: try removing @main

* chore: try using local workflow

* fix: fixes typo and secrets

* chore: update yarn.lock

* chore: lint

* fix: deploy_docs.yml

Co-authored-by: martines3000 <domajnko.martin@gmail.com>
Co-authored-by: Martin Domajnko <35891136+martines3000@users.noreply.github.com>
Co-authored-by: Urban <urbanfoundit@gmail.com>

* feat: fix tests

* chore: lint

* fix: yarn lock

* fix: fix verifyPresentation

* chore: remove console

* fix: add coin_type parameter

* fix: move constants

* fix: lint

* feat: adds `snap_getBip44Entropy` implementation to tests

* fix: pr feedback

* fix: pr feedback

* fix: refactor keyPair.ts

* chore: lint

Co-authored-by: martines3000 <domajnko.martin@gmail.com>
Co-authored-by: Martin Domajnko <35891136+martines3000@users.noreply.github.com>
Co-authored-by: Urban <urbanfoundit@gmail.com>
  • Loading branch information
4 people authored Nov 11, 2022
1 parent 872ddae commit ca75794
Show file tree
Hide file tree
Showing 55 changed files with 3,038 additions and 3,430 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ on:
jobs:
test-deploy:
if: github.event_name != 'push'

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
with:
fetch-depth: 0
- uses: nrwl/nx-set-shas@v3

- uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn

- name: Install dependencies
run: yarn install --immutable
- name: Lint
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nx-cloud-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ jobs:
# Set node/npm/yarn versions using volta, with optional overrides provided by the consumer
- uses: volta-cli/action@v4
with:
node-version: "${{ inputs.node-version }}"
npm-version: "${{ inputs.npm-version }}"
yarn-version: "${{ inputs.yarn-version }}"
node-version: '${{ inputs.node-version }}'
npm-version: '${{ inputs.npm-version }}'
yarn-version: '${{ inputs.yarn-version }}'

# Install pnpm with exact version provided by consumer or fallback to latest
- name: Install PNPM
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
build
dist
.docusaurus
coverage
541 changes: 541 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
checksumBehavior: update

compressionLevel: 0

enableGlobalCache: true

enableInlineBuilds: true

nmMode: hardlinks-local

nodeLinker: node-modules
Expand All @@ -13,7 +17,22 @@ plugins:
spec: '@yarnpkg/plugin-workspace-tools'
- path: .yarn/plugins/@yarnpkg/plugin-engines.cjs
spec: 'https://raw.githubusercontent.com/devoto13/yarn-plugin-engines/main/bundles/%40yarnpkg/plugin-engines.js'
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: '@yarnpkg/plugin-interactive-tools'

yarnPath: .yarn/releases/yarn-3.2.4.cjs
supportedArchitectures:
cpu:
- current
- x86
- ia32
libc:
- current
- glibc
- musl
os:
- current
- darwin
- linux
- win32

enableInlineBuilds: true
yarnPath: .yarn/releases/yarn-3.2.4.cjs
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@nrwl/jest": "15.0.3",
"@nrwl/nx-cloud": "^15.0.2",
"@types/eslint": "^7",
"@types/node": "^18.11.5",
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"eslint": "^8.20.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@
},
"dependencies": {
"@blockchain-lab-um/ssi-snap-types": "*",
"@veramo/core": "^4.0.2-next.9"
"@veramo/core": "^4.1.1"
},
"devDependencies": {
"@types/node": "^12.12.35",
"@types/rimraf": "^3",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
Expand Down
6 changes: 5 additions & 1 deletion packages/connector/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"pretty": true /* Stylize errors and messages using color and context. */,

"lib": ["es6", "dom", "es2017"],
"typeRoots": ["node_modules/@types", "src/types"]
"typeRoots": [
"./node_modules/@types",
"../../node_modules/@types",
"src/types"
]
},
"include": ["src/**/*.ts"]
}
2 changes: 1 addition & 1 deletion packages/docs/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ What are the use cases for **SSI** in **dApps**?
- No gas identity data (everything is off-chain)
- Everything you come up with ... :)

Want to join the discussion or interested in contributing? Join the [Discord](https://discord.gg/cKA24TuMUd).
Want to join the discussion or interested in contributing? Join the [Discord](https://discord.gg/BUXRpwwjfr).
4 changes: 2 additions & 2 deletions packages/docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const config = {
position: 'right',
},
{
href: 'https://discord.gg/jNzEkAEG',
href: 'https://discord.gg/BUXRpwwjfr',
label: 'Discord',
position: 'right',
},
Expand Down Expand Up @@ -112,7 +112,7 @@ const config = {
},
{
label: 'Discord',
href: 'https://discord.gg/cKA24TuMUd',
href: 'https://discord.gg/BUXRpwwjfr',
},
{
label: 'LinkedIn',
Expand Down
1 change: 0 additions & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"@docusaurus/module-type-aliases": "^2.0.0-rc.1",
"@tsconfig/docusaurus": "^1.0.6",
"@tsconfig/node16": "^1.0.3",
"@types/node": "16.11.45",
"@types/react": "17.0.47",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
Expand Down
9 changes: 9 additions & 0 deletions packages/snap/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
module.exports = {
root: true,
extends: ['../../.eslintrc.js'],
overrides: [
{
files: ['tests/**/*.ts'],
plugins: ['jest'],
extends: ['plugin:jest/recommended'],
rules: { 'jest/prefer-expect-assertions': 'off' },
env: { jest: true },
},
],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.eslint.json',
Expand Down
5 changes: 4 additions & 1 deletion packages/snap/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export default {
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
// globals: {},
globals: {
window: {},
},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",
Expand Down Expand Up @@ -186,5 +188,6 @@ export default {

// Whether to use watchman for file crawling
// watchman: true,

testTimeout: 120000,
};
41 changes: 21 additions & 20 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,26 @@
"@babel/runtime": "7.17.2",
"@blockchain-lab-um/ssi-snap-types": "*",
"@blockchain-lab-um/veramo-vc-manager": "*",
"@ceramicnetwork/blockchain-utils-linking": "2.1.0",
"@ceramicnetwork/blockchain-utils-linking": "2.3.0",
"@ceramicnetwork/http-client": "2.7.0",
"@glazed/did-datastore": "0.3.2",
"@glazed/did-session": "0.1.1",
"@metamask/key-tree": "^4.0.0",
"@types/uuid": "8.3.4",
"@veramo/core": "4.0.2-next.9",
"@veramo/credential-eip712": "4.0.2-next.9",
"@veramo/credential-w3c": "4.0.2-next.9",
"@veramo/data-store": "4.0.2-next.9",
"@veramo/did-jwt": "4.0.2-next.9",
"@veramo/did-manager": "4.0.2-next.9",
"@veramo/did-provider-ethr": "4.0.2-next.9",
"@veramo/did-resolver": "4.0.2-next.9",
"@veramo/key-manager": "4.0.2-next.9",
"@veramo/kms-local": "4.0.2-next.9",
"@veramo/kms-web3": "4.0.2-next.9",
"@veramo/message-handler": "4.0.2-next.9",
"@veramo/selective-disclosure": "4.0.2-next.9",
"@veramo/utils": "4.0.2-next.15",
"@veramo/core": "4.1.1",
"@veramo/credential-eip712": "4.1.1",
"@veramo/credential-w3c": "4.1.1",
"@veramo/data-store": "4.1.1",
"@veramo/did-jwt": "4.1.1",
"@veramo/did-manager": "4.1.1",
"@veramo/did-provider-ethr": "4.1.2",
"@veramo/did-resolver": "4.1.1",
"@veramo/key-manager": "4.1.1",
"@veramo/kms-local": "4.1.1",
"@veramo/kms-web3": "4.1.1",
"@veramo/message-handler": "4.1.1",
"@veramo/selective-disclosure": "4.1.1",
"@veramo/utils": "4.1.1",
"ceramic-cacao": "^1.4.0",
"did-jwt-vc": "2.1.9",
"did-resolver": "3.2.0",
Expand All @@ -98,19 +99,19 @@
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@metamask/providers": "^9.0.0",
"@metamask/snap-types": "^0.21.0",
"@metamask/snaps-cli": "^0.21.0",
"@metamask/snaps-webpack-plugin": "^0.21.0",
"@metamask/snap-types": "^0.22.3",
"@metamask/snaps-cli": "^0.22.3",
"@metamask/snaps-webpack-plugin": "^0.22.3",
"@types/jest": "^29.0.2",
"@types/lodash.clonedeep": "^4.5.7",
"@types/node": "^18.7.18",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"audit-ci": "^6.3.0",
"babel-loader": "^8.2.5",
"eslint": "^8.20.0",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.3",
"eslint-plugin-prettier": "^4.2.1",
"eslint-webpack-plugin": "^3.2.0",
"fork-ts-checker-webpack-plugin": "^7.2.13",
Expand Down
7 changes: 6 additions & 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": "iYHhNh4Ck21x3UkfVAikKob0OLnb//O9cDrv6faJGx8=",
"shasum": "WdmmD8Jikfk4Nym6g2ALq0oSQSYZPwV3iIMCay1biOE=",
"location": {
"npm": {
"filePath": "dist/snap.js",
Expand All @@ -19,6 +19,11 @@
},
"initialPermissions": {
"snap_confirm": {},
"snap_getBip44Entropy": [
{
"coinType": 60
}
],
"snap_manageState": {},
"endowment:network-access": {},
"eth_accounts": {
Expand Down
8 changes: 8 additions & 0 deletions packages/snap/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const availableVCStores = ['snap', 'ceramic'] as const;

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

export const didCoinTypeMappping: Record<string, number> = {
'did:ethr': 60,
'did:key': 60,
};
1 change: 0 additions & 1 deletion packages/snap/src/did/didMethods.ts

This file was deleted.

24 changes: 11 additions & 13 deletions packages/snap/src/did/key/keyDidResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ParsedDID,
Resolvable,
} from 'did-resolver';
import { getDidKeyIdentifier } from './keyDidUtils';
import { getCurrentAccount, getPublicKey } from '../../utils/snapUtils';
import { SnapProvider } from '@metamask/snap-types';
import { getSnapState } from '../../utils/stateUtils';
Expand All @@ -19,26 +18,25 @@ export const resolveSecp256k1 = async (
did: string
): Promise<DIDDocument> => {
const state = await getSnapState(wallet);
const DID = getDidKeyIdentifier(state, account);
const publicKey = await getPublicKey(wallet, state, account);
const publicKey = await getPublicKey({ wallet, state, account });

// TODO: Change id ?
const didDocument: DIDDocument = {
id: `${did}#${DID}`,
id: `did:key:${did}#${did}`,
'@context': [
'https://www.w3.org/ns/did/v1',
'https://w3id.org/security/suites/secp256k1-2019/v1',
],
assertionMethod: [`${did}#${DID}`],
authentication: [`${did}#${DID}`],
capabilityInvocation: [`${did}#${DID}`],
capabilityDelegation: [`${did}#${DID}`],
keyAgreement: [`${did}#${DID}`],
assertionMethod: [`did:key:${did}#${did}`],
authentication: [`did:key:${did}#${did}`],
capabilityInvocation: [`did:key:${did}#${did}`],
capabilityDelegation: [`did:key:${did}#${did}`],
keyAgreement: [`did:key:${did}#${did}`],
verificationMethod: [
{
id: `${did}#${DID}`,
id: `did:key:${did}#${did}`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: `${did}#${DID}`,
controller: `did:key:${did}#${did}`,
publicKeyHex: publicKey.split('0x')[1],
},
],
Expand All @@ -61,8 +59,8 @@ const startsWithMap: Record<string, ResolutionFunction> = {
export const resolveDidKey: DIDResolver = async (
didUrl: string,
parsed: ParsedDID,
_resolver: Resolvable,
_options: DIDResolutionOptions
resolver: Resolvable,
options: DIDResolutionOptions
): Promise<DIDResolutionResult> => {
try {
// FIXME: Update this part
Expand Down
Loading

0 comments on commit ca75794

Please sign in to comment.