Skip to content

Commit

Permalink
chore: merge develop and fix conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Urban Vidovič <urbanfoundit@gmail.com>
  • Loading branch information
pseudobun committed Jun 28, 2023
2 parents 20455a2 + 62bd89c commit 6e50fb6
Show file tree
Hide file tree
Showing 58 changed files with 4,726 additions and 4,112 deletions.
3 changes: 2 additions & 1 deletion packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"lint:prettier": "prettier . --check",
"serve": "mm-snap serve",
"start": "pnpm mm-snap --version && pnpm build && pnpm serve",
"test": "pnpm jest",
"test": "cross-env NODE_OPTIONS=--max-old-space-size=4096 jest",
"test:ci": "pnpm run test --silent --coverage"
},
"dependencies": {
Expand All @@ -73,6 +73,7 @@
"@veramo/core": "5.2.0",
"@veramo/credential-eip712": "5.2.0",
"@veramo/credential-ld": "5.2.0",
"@veramo/credential-status": "5.1.2",
"@veramo/credential-w3c": "5.2.0",
"@veramo/did-manager": "5.1.2",
"@veramo/did-provider-ethr": "5.1.2",
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/masca.git"
},
"source": {
"shasum": "fV2l/zAnk2S5b+qDpBPwfwHg6DDueoE34sPJdFQmpHA=",
"shasum": "RjAmo9dZHap4P/FgOzhlHxMJcMur+nnUjP9ybpO3Hp4=",
"location": {
"npm": {
"filePath": "dist/snap.js",
Expand Down
7 changes: 3 additions & 4 deletions packages/snap/src/utils/keyPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const methodIndexMapping: Record<AvailableMethods, number> = {
'did:key': 0,
'did:key:ebsi': 0,
'did:jwk': 1,
'did:ethr': 0,
'did:pkh': 0,
'did:ethr': 3,
'did:pkh': 3,
};

export async function getAccountIndexFromEntropy(params: {
Expand Down Expand Up @@ -50,11 +50,10 @@ export async function getAddressKeyDeriver(
ct = didCoinTypeMappping[method];
}

// FIXME: in future coinType 60 will be rejected when passed to this method
const bip44CoinTypeNode = (await snap.request({
method: 'snap_getBip44Entropy',
params: {
coinType: ct,
coinType: 1236,
},
})) as BIP44CoinTypeNode;
return bip44CoinTypeNode;
Expand Down
6 changes: 6 additions & 0 deletions packages/snap/src/utils/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export function isValidCreateVPRequest(
if (
'proofOptions' in param &&
param.proofOptions !== null &&
param.proofOptions !== undefined &&
param.proofOptions?.domain !== null &&
param.proofOptions?.domain !== undefined &&
typeof param.proofOptions?.domain !== 'string'
) {
throw new Error('Domain is not a string');
Expand All @@ -110,7 +112,9 @@ export function isValidCreateVPRequest(
if (
'proofOptions' in param &&
param.proofOptions !== null &&
param.proofOptions !== undefined &&
param.proofOptions?.challenge !== null &&
param.proofOptions?.challenge !== undefined &&
typeof param.proofOptions?.challenge !== 'string'
) {
throw new Error('Challenge is not a string');
Expand All @@ -120,7 +124,9 @@ export function isValidCreateVPRequest(
if (
'proofOptions' in param &&
param.proofOptions !== null &&
param.proofOptions !== undefined &&
param.proofOptions?.type !== null &&
param.proofOptions?.type !== undefined &&
typeof param.proofOptions?.type !== 'string'
) {
throw new Error('Type is not a string');
Expand Down
9 changes: 9 additions & 0 deletions packages/snap/src/veramo/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MetaMaskInpageProvider } from '@metamask/providers';
import type { SnapsGlobalObject } from '@metamask/snaps-types';
import {
createAgent,
CredentialStatus,
type ICredentialVerifier,
type IDataStore,
type IDIDManager,
Expand All @@ -24,6 +25,7 @@ import {
type TAgent,
} from '@veramo/core';
import { CredentialIssuerEIP712 } from '@veramo/credential-eip712';
import { CredentialStatusPlugin } from '@veramo/credential-status';
import {
CredentialPlugin,
type ICredentialIssuer,
Expand Down Expand Up @@ -121,6 +123,13 @@ export const getAgent = async (
plugins: [
new CredentialPlugin(),
new CredentialIssuerEIP712(),
new CredentialStatusPlugin({
// TODO implement this
StatusList2021Entry: (
_credential: any,
_didDoc: any
): Promise<CredentialStatus> => Promise.resolve({ revoked: false }),
}),
new KeyManager({
store: new MemoryKeyStore(),
kms: {
Expand Down
55 changes: 55 additions & 0 deletions packages/snap/tests/data/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { MinimalImportableKey } from '@veramo/core';

export const mnemonic =
'prosper pair similar canoe work humble loud wild aunt reunion olive obscure';
export const account = '0xb6665128eE91D84590f70c3268765384A9CAfBCd';
export const account2 = '0x461e557A07AC110BC947F18b3828e26f013dac39';
export const privateKey =
'0x63ce0077f0d617dbf54d5f335de2983313c6356f25b45e0f68f85bee1490a6ae';
export const privateKey2 =
'0xb29764680b2a07fa4a762d255e3f689fb5c05cc885e6dfd3de5d5948b5a6b47f';

export const importablePrivateKey: MinimalImportableKey = {
kid: 'importedTestKey',
kms: 'snap',
type: 'Secp256k1',
privateKeyHex: privateKey.substring(2),
} as const;

// Query params

// For exampleJWT.json
export const jsonPath =
'$[?(@.data.credentialSubject.placeOfBirth == "Asgard")]';

// For exampleJWT_2.json & VCs returned by createTestVCs()
export const jsonPath2 =
'$[?(@.data.credentialSubject.accomplishmentType == "Developer Certificate")]';

// Errors

export const resolutionNotFound = {
didDocument: null,
didResolutionMetadata: {
error: 'invalidDid',
message: 'Error: invalidDid: invalid key type',
},
didDocumentMetadata: {},
};

export const resolutionMethodNotSupported = {
didDocument: null,
didResolutionMetadata: {
error: 'unsupportedDidMethod',
},
didDocumentMetadata: {},
};

export const resolutionInvalidDID = {
didDocument: null,
didResolutionMetadata: {
error: 'invalidDid',
message: 'Not a valid did:ethr: 0x5:0x123',
},
didDocumentMetadata: {},
};
18 changes: 18 additions & 0 deletions packages/snap/tests/data/credentials/examplePayload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": ["VerifiableCredential", "ProgramCompletionCertificate"],
"credentialSubject": {
"accomplishmentType": "Developer Certificate",
"learnerName": "John Doe",
"achievement": "Certified Solidity Developer 2",
"courseProvider": "https://blockchain-lab.um.si/",
"id": "did:web:example.johndoe.com"
},
"credentialSchema": {
"id": "https://beta.api.schemas.serto.id/v1/public/program-completion-certificate/1.0/json-schema.json",
"type": "JsonSchemaValidator2018"
},
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://beta.api.schemas.serto.id/v1/public/program-completion-certificate/1.0/ld-context.json"
]
}
30 changes: 30 additions & 0 deletions packages/snap/tests/data/defaultSnapState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MascaAccountState, MascaState } from '@blockchain-lab-um/masca-types';

import { getEmptyAccountState } from '../../src/utils/config';

const defaultSnapState = (address: string): MascaState => {
const accountState: Record<string, MascaAccountState> = {};
accountState[address] = getEmptyAccountState();

return {
accountState,
currentAccount: address,
snapConfig: {
dApp: {
disablePopups: false,
friendlyDapps: [],
},
snap: {
acceptedTerms: true,
},
},
};
};

export const getDefaultSnapState = (address: string): MascaState => {
const state = structuredClone(defaultSnapState(address));
// Session is valid for two years from 15/06/2023 for address 1 only
state.accountState[address].ceramicSession =
'eyJzZXNzaW9uS2V5U2VlZCI6IlJCcGVUK3poMmFpQ2xOTVBZYXllYUFSSVBhVkZUZ1pZVHU4M3I0dHBpR1U9IiwiY2FjYW8iOnsiaCI6eyJ0IjoiZWlwNDM2MSJ9LCJwIjp7ImRvbWFpbiI6Ik15Tm9kZUFwcCIsImlhdCI6IjIwMjMtMDYtMTVUMTI6Mjc6NTguNzgyWiIsImlzcyI6ImRpZDpwa2g6ZWlwMTU1OjE6MHhiNjY2NTEyOGVlOTFkODQ1OTBmNzBjMzI2ODc2NTM4NGE5Y2FmYmNkIiwiYXVkIjoiZGlkOmtleTp6Nk1rd1V6aW5FU2lGdWo2dlR1bk1kbVYyTWtvbm1ud3lkdlE4Rjlwc0xzQ0xyUW8iLCJ2ZXJzaW9uIjoiMSIsIm5vbmNlIjoiSnFKTTNZcFc5ayIsImV4cCI6IjIwMjUtMDYtMTRUMTI6Mjc6NTguNzgyWiIsInN0YXRlbWVudCI6IkdpdmUgdGhpcyBhcHBsaWNhdGlvbiBhY2Nlc3MgdG8gc29tZSBvZiB5b3VyIGRhdGEgb24gQ2VyYW1pYyIsInJlc291cmNlcyI6WyJjZXJhbWljOi8vKj9tb2RlbD1ranpsNmh2ZnJidzZjNmlkYWFjdzVkNGdjNDgxZW5wYmV1djRmYXQ2NmdqcTFrazlpdnRhbmFkc2UwNzQ2ZGwiXX0sInMiOnsidCI6ImVpcDE5MSIsInMiOiIweGNmZjk0YjgyZmVlODZmZmM0Zjg0ZjYxODFmMDRkNGY2NGY5ZmVmZTAyODgyNzg4Mzc1M2ZhNWFiYThiM2VkYWQ3NzdhZThjMGY3ZTQ0MTIzMzM2ZmQzNjIwNjA5MWE0NmM0MDYxZTQzZGY4OGVhYzdmZWI2ZTE2M2Y5Yzc2OWI3MWMifX19';
return structuredClone(state);
};
60 changes: 60 additions & 0 deletions packages/snap/tests/data/documentResolution/cheqdResolution.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"did": "did:cheqd:mainnet:Ps1ysXP2Ae6GBfxNhNQNKN",
"didDocumentMetadata": {
"created": "2022-04-05T11:49:19Z",
"versionId": "4fa8e367-c70e-533e-babf-3732d9761061"
},
"didResolutionMetadata": {
"contentType": "application/did+ld+json",
"retrieved": "2023-06-01T09:34:29Z",
"did": {
"didString": "did:cheqd:mainnet:Ps1ysXP2Ae6GBfxNhNQNKN",
"methodSpecificId": "mainnet:Ps1ysXP2Ae6GBfxNhNQNKN",
"method": "cheqd"
},
"pattern": "^(did:cheqd:.+)$",
"driverUrl": "http://cheqd-did-driver:8080/1.0/identifiers/$1",
"duration": 1034
},
"didDocument": {
"@context": [
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/suites/ed25519-2020/v1"
],
"id": "did:cheqd:mainnet:Ps1ysXP2Ae6GBfxNhNQNKN",
"verificationMethod": [
{
"id": "did:cheqd:mainnet:Ps1ysXP2Ae6GBfxNhNQNKN#key1",
"type": "Ed25519VerificationKey2020",
"controller": "did:cheqd:mainnet:Ps1ysXP2Ae6GBfxNhNQNKN",
"publicKeyMultibase": "z6Mkta7joRuvDh7UnoESdgpr9dDUMh5LvdoECDi3WGrJoscA"
}
],
"authentication": ["did:cheqd:mainnet:Ps1ysXP2Ae6GBfxNhNQNKN#key1"],
"service": [
{
"id": "did:cheqd:mainnet:Ps1ysXP2Ae6GBfxNhNQNKN#website",
"type": "LinkedDomains",
"serviceEndpoint": ["https://www.cheqd.io"]
},
{
"id": "did:cheqd:mainnet:Ps1ysXP2Ae6GBfxNhNQNKN#non-fungible-image",
"type": "LinkedDomains",
"serviceEndpoint": [
"https://gateway.ipfs.io/ipfs/bafybeihetj2ng3d74k7t754atv2s5dk76pcqtvxls6dntef3xa6rax25xe"
]
},
{
"id": "did:cheqd:mainnet:Ps1ysXP2Ae6GBfxNhNQNKN#twitter",
"type": "LinkedDomains",
"serviceEndpoint": ["https://twitter.com/cheqd_io"]
},
{
"id": "did:cheqd:mainnet:Ps1ysXP2Ae6GBfxNhNQNKN#linkedin",
"type": "LinkedDomains",
"serviceEndpoint": ["https://www.linkedin.com/company/cheqd-identity/"]
}
]
},
"@context": "https://w3id.org/did-resolution/v1"
}
40 changes: 40 additions & 0 deletions packages/snap/tests/data/documentResolution/ebsiResolution.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"did": "did:ebsi:ziE2n8Ckhi6ut5Z8Cexrihd",
"didDocumentMetadata": {},
"didResolutionMetadata": {
"contentType": "application/did+ld+json",
"pattern": "^(did:ebsi:.+)$",
"driverUrl": "https://api-pilot.ebsi.eu/did-registry/v3/identifiers/$1",
"duration": 953,
"did": {
"didString": "did:ebsi:ziE2n8Ckhi6ut5Z8Cexrihd",
"methodSpecificId": "ziE2n8Ckhi6ut5Z8Cexrihd",
"method": "ebsi"
}
},
"didDocument": {
"@context": [
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/suites/jws-2020/v1"
],
"authentication": ["did:ebsi:ziE2n8Ckhi6ut5Z8Cexrihd#key-1"],
"service": [],
"id": "did:ebsi:ziE2n8Ckhi6ut5Z8Cexrihd",
"assertionMethod": ["did:ebsi:ziE2n8Ckhi6ut5Z8Cexrihd#key-1"],
"verificationMethod": [
{
"id": "did:ebsi:ziE2n8Ckhi6ut5Z8Cexrihd#key-1",
"controller": "did:ebsi:ziE2n8Ckhi6ut5Z8Cexrihd",
"type": "JsonWebKey2020",
"publicKeyJwk": {
"kty": "EC",
"crv": "secp256k1",
"x": "masUHNuJ0oH0C_e5rLUu5VKwmU2l-a7rrNTqA__afN8",
"y": "UmGGX_WgRFXbw6qTli9xcQ0owtkZVuUGVyM23e8rZe8",
"kid": "did:ebsi:ziE2n8Ckhi6ut5Z8Cexrihd#keys-1"
}
}
]
},
"@context": "https://w3id.org/did-resolution/v1"
}
48 changes: 48 additions & 0 deletions packages/snap/tests/data/documentResolution/ensResolution.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"did": "did:ens:vitalik.eth",
"didDocumentMetadata": {},
"didResolutionMetadata": {
"pattern": "^(did:ens:.+)$",
"driverUrl": "http://uni-resolver-driver-did-uport:8081/1.0/identifiers/",
"duration": 461,
"did": {
"didString": "did:ens:vitalik.eth",
"methodSpecificId": "vitalik.eth",
"method": "ens"
},
"contentType": "application/did+ld+json",
"convertedFrom": "application/did+json",
"convertedTo": "application/did+ld+json"
},
"didDocument": {
"assertionMethod": [
"did:ens:vitalik.eth#0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
],
"service": [
{
"id": "did:ens:vitalik.eth#Web3PublicProfile-0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"type": "Web3PublicProfile",
"serviceEndpoint": "vitalik.eth"
}
],
"capabilityDelegation": [
"did:ens:vitalik.eth#0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
],
"id": "did:ens:vitalik.eth",
"verificationMethod": [
{
"id": "did:ens:vitalik.eth#0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"type": "EcdsaSecp256k1RecoveryMethod2020",
"controller": "did:ens:vitalik.eth",
"blockchainAccountId": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045@eip155:1"
}
],
"capabilityInvocation": [
"did:ens:vitalik.eth#0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
],
"authentication": [
"did:ens:vitalik.eth#0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
]
},
"@context": "https://w3id.org/did-resolution/v1"
}
26 changes: 26 additions & 0 deletions packages/snap/tests/data/documentResolution/ethrResolution.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"didDocumentMetadata": {},
"didResolutionMetadata": { "contentType": "application/did+ld+json" },
"didDocument": {
"@context": [
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/suites/secp256k1recovery-2020/v2"
],
"id": "did:ethr:0x1:0xb6665128eE91D84590f70c3268765384A9CAfBCd",
"verificationMethod": [
{
"id": "did:ethr:0x1:0xb6665128eE91D84590f70c3268765384A9CAfBCd#controller",
"type": "EcdsaSecp256k1RecoveryMethod2020",
"controller": "did:ethr:0x1:0xb6665128eE91D84590f70c3268765384A9CAfBCd",
"blockchainAccountId": "eip155:1:0xb6665128eE91D84590f70c3268765384A9CAfBCd"
}
],
"authentication": [
"did:ethr:0x1:0xb6665128eE91D84590f70c3268765384A9CAfBCd#controller"
],
"assertionMethod": [
"did:ethr:0x1:0xb6665128eE91D84590f70c3268765384A9CAfBCd#controller"
]
},
"did": "did:ethr:0x1:0xb6665128eE91D84590f70c3268765384A9CAfBCd#controller"
}
Loading

0 comments on commit 6e50fb6

Please sign in to comment.