From 672f92b1bd3850c369cbef646c8ece8a58fafc16 Mon Sep 17 00:00:00 2001 From: Mircea Nistor Date: Wed, 22 Feb 2023 13:11:51 +0100 Subject: [PATCH] fix(credential-eip712): compatibility improvements for EthereumEIP712Signature2021 (#1131) --- __tests__/fixtures/cred1.json | 42 ++++ __tests__/fixtures/cred2.json | 185 ++++++++++++++++++ __tests__/fixtures/cred3.json | 136 +++++++++++++ __tests__/fixtures/cred4.json | 29 +++ __tests__/localMemoryStoreAgent.test.ts | 56 +++--- __tests__/shared/credentialInterop.ts | 42 ++++ __tests__/shared/verifiableDataEIP712.ts | 2 +- .../src/agent/CredentialEIP712.ts | 48 +++-- .../credential-ld/src/contexts/eip712.json | 93 +++++++++ .../credential-ld/src/ld-default-contexts.ts | 43 ++-- 10 files changed, 610 insertions(+), 66 deletions(-) create mode 100644 __tests__/fixtures/cred1.json create mode 100644 __tests__/fixtures/cred2.json create mode 100644 __tests__/fixtures/cred3.json create mode 100644 __tests__/fixtures/cred4.json create mode 100644 __tests__/shared/credentialInterop.ts create mode 100644 packages/credential-ld/src/contexts/eip712.json diff --git a/__tests__/fixtures/cred1.json b/__tests__/fixtures/cred1.json new file mode 100644 index 000000000..94104f00e --- /dev/null +++ b/__tests__/fixtures/cred1.json @@ -0,0 +1,42 @@ +{ + "id": "http://example.com/credentials/3527", + "name": "begd", + "type": [ + "VerifiableCredential", + "OpenBadgeCredential" + ], + "proof": { + "type": "Ed25519Signature2020", + "created": "2023-02-11T02:40:43.841Z", + "@context": [ + "https://w3id.org/security/suites/ed25519-2020/v1" + ], + "proofValue": "z3JLZ5fbUY4J4XyaaVhTyHaC5djPHKVgGYKF8necUHJhZi1Z9aNFvittgA5NkQ3obbVj5DiAD4GwfyxtSovBnWVAt", + "proofPurpose": "assertionMethod", + "verificationMethod": "did:key:z6MkqqPLdAy3mL5JFHEBmpuj7NjTEPnMifr2kz83XsbbgkyY#z6MkqqPLdAy3mL5JFHEBmpuj7NjTEPnMifr2kz83XsbbgkyY" + }, + "issuer": "did:key:z6MkqqPLdAy3mL5JFHEBmpuj7NjTEPnMifr2kz83XsbbgkyY", + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://purl.imsglobal.org/spec/ob/v3p0/context.json" + ], + "issuanceDate": "2023-02-11T02:40:43.832Z", + "credentialSubject": { + "id": "did:key:z6MkqqPLdAy3mL5JFHEBmpuj7NjTEPnMifr2kz83XsbbgkyY", + "type": [ + "AchievementSubject" + ], + "achievement": { + "id": "https://example.com/achievements/21st-century-skills/teamwork", + "name": "begd", + "type": [ + "Achievement" + ], + "criteria": { + "narrative": "hcgij" + }, + "description": "ghfh", + "achievementType": "License" + } + } +} diff --git a/__tests__/fixtures/cred2.json b/__tests__/fixtures/cred2.json new file mode 100644 index 000000000..ca9306d66 --- /dev/null +++ b/__tests__/fixtures/cred2.json @@ -0,0 +1,185 @@ +{ + "id": "ceramic://kjzl6cwe1jw14amq2gh9w54p7mqkyvudy8z1bexw1w9b9vw3ikac6ahwhyurrll", + "_type": [ + "VerifiableCredential", + "CredScoreGTEGood", + "Credit", + "Borrowing", + "Finance", + "DeFi", + "WorkExperience" + ], + "proof": { + "type": "EthereumEip712Signature2021", + "eip712": { + "types": { + "Issuer": [ + { + "name": "id", + "type": "string" + }, + { + "name": "ethereumAddress", + "type": "address" + } + ], + "EIP712Domain": [ + { + "name": "name", + "type": "string" + }, + { + "name": "version", + "type": "string" + }, + { + "name": "chainId", + "type": "uint256" + }, + { + "name": "verifyingContract", + "type": "address" + } + ], + "CredentialSchema": [ + { + "name": "id", + "type": "string" + }, + { + "name": "_type", + "type": "string" + } + ], + "CredentialSubject": [ + { + "name": "id", + "type": "string" + }, + { + "name": "ethereumAddress", + "type": "address" + }, + { + "name": "_type", + "type": "string" + }, + { + "name": "typeSchema", + "type": "string" + }, + { + "name": "value", + "type": "string" + }, + { + "name": "encrypted", + "type": "string" + }, + { + "name": "trust", + "type": "uint8" + }, + { + "name": "stake", + "type": "uint256" + }, + { + "name": "price", + "type": "uint256" + }, + { + "name": "nbf", + "type": "uint256" + }, + { + "name": "exp", + "type": "uint256" + } + ], + "VerifiableCredential": [ + { + "name": "_context", + "type": "string" + }, + { + "name": "_type", + "type": "string" + }, + { + "name": "id", + "type": "string" + }, + { + "name": "issuer", + "type": "Issuer" + }, + { + "name": "credentialSubject", + "type": "CredentialSubject" + }, + { + "name": "credentialSchema", + "type": "CredentialSchema" + }, + { + "name": "issuanceDate", + "type": "string" + }, + { + "name": "expirationDate", + "type": "string" + } + ] + }, + "domain": { + "name": "Krebit", + "chainId": 137, + "version": "1.0", + "verifyingContract": "0xdEb4810c8AB3f9De3F253064A40b1D0c8703fbbf" + }, + "primaryType": "VerifiableCredential" + }, + "created": "2023-02-10T19:19:14.884Z", + "proofValue": "0x50af66d10f4754db27218c99cb1026f66da1f1958c4be7fc0e671aa62cce5e360c3f2d9e08807a6dca3802fc6e2151e60293d4d712f7c79b069cce77b52af1721c", + "proofPurpose": "assertionMethod", + "ethereumAddress": "0x5AFd488fe9843E51db54B2262F247572926aea5F", + "verificationMethod": "did:pkh:eip155:1:0x5afd488fe9843e51db54b2262f247572926aea5f#ethereumAddress" + }, + "issuer": { + "id": "did:pkh:eip155:1:0x5afd488fe9843e51db54b2262f247572926aea5f", + "ethereumAddress": "0x5AFd488fe9843E51db54B2262F247572926aea5F" + }, + "_context": [ + "https://www.w3.org/2018/credentials/v1", + "https://w3id.org/security/suites/eip712sig-2021" + ], + "issuanceDate": "2023-02-10T19:14:14.881Z", + "expirationDate": "2026-02-10T19:19:14.841Z", + "credentialSchema": { + "id": "https://github.com/KrebitDAO/eip712-vc", + "type": "Eip712SchemaValidator2021" + }, + "credentialSubject": { + "id": "did:pkh:eip155:1:0xee55527cf8ea371ac9d574e7e861d28a27b241a4", + "did": "did:pkh:eip155:1:0xee55527cf8ea371ac9d574e7e861d28a27b241a4", + "exp": 1770751154, + "nbf": 1676056454, + "tags": [ + "Credit", + "Borrowing", + "Finance", + "DeFi", + "WorkExperience" + ], + "type": "CredScoreGTEGood", + "price": 0, + "stake": 1, + "trust": 100, + "value": "{\"name\":\"Cred Protocol Score >= Good\",\"entity\":\"credprotocol.com\",\"proof\":{\"account\":\"0xEE55527CF8ea371Ac9D574E7e861D28A27b241a4\",\"creation_date_utc\":\"2023-02-10 19:19:13\",\"model_version\":\"nebula_1.0.6\",\"value\":803,\"decile\":\"4.00\",\"value_rating\":\"Good\"}}", + "encrypted": "none", + "typeSchema": "krebit://schemas/certificate", + "expirationDate": "2026-02-10T19:19:14.841Z", + "ethereumAddress": "0xee55527cf8ea371ac9d574e7e861d28a27b241a4" + } +} diff --git a/__tests__/fixtures/cred3.json b/__tests__/fixtures/cred3.json new file mode 100644 index 000000000..aabf7bd6e --- /dev/null +++ b/__tests__/fixtures/cred3.json @@ -0,0 +1,136 @@ +{ + "id": "kjzl6cwe1jw14bn99lu4spvfdvjyxtm4cg2ys5jmd0gqjaov5fqifwlf0af3hbt-did:pkh:eip155:1:0xde695cbb6ec0cf3f4c9564070baeb032552c5111", + "type": [ + "VerifiableCredential", + "EventAttendanceCredential" + ], + "proof": { + "type": "EthereumEip712Signature2021", + "eip712": { + "types": { + "Issuer": [ + { + "name": "id", + "type": "string" + }, + { + "name": "ethereumAddress", + "type": "string" + } + ], + "EIP712Domain": [ + { + "name": "name", + "type": "string" + }, + { + "name": "version", + "type": "string" + }, + { + "name": "chainId", + "type": "uint256" + }, + { + "name": "verifyingContract", + "type": "address" + } + ], + "CredentialSchema": [ + { + "name": "id", + "type": "string" + }, + { + "name": "type", + "type": "string" + } + ], + "CredentialSubject": [ + { + "name": "id", + "type": "string" + }, + { + "name": "eventName", + "type": "string" + }, + { + "name": "eventIcon", + "type": "string" + }, + { + "name": "eventId", + "type": "string" + } + ], + "VerifiableCredential": [ + { + "name": "@context", + "type": "string[]" + }, + { + "name": "type", + "type": "string[]" + }, + { + "name": "id", + "type": "string" + }, + { + "name": "issuer", + "type": "Issuer" + }, + { + "name": "credentialSubject", + "type": "CredentialSubject" + }, + { + "name": "credentialSchema", + "type": "CredentialSchema" + }, + { + "name": "issuanceDate", + "type": "string" + }, + { + "name": "expirationDate", + "type": "string" + } + ] + }, + "domain": { + "name": "Verifiable Event Attendance", + "chainId": 1, + "version": "1", + "verifyingContract": "0x00000000000000000000000000000000000000000000" + }, + "primaryType": "VerifiableCredential" + }, + "created": "2023-02-17T02:55:22.601Z", + "proofValue": "0xc8cd38c1ba36b2209a334de8f412a8a7f8bbc20639d981c41806444e7cc2e1396d42264957771823c5f7b3f846d141333486e0c78f88ed2d657cad3f9325a64f1c", + "proofPurpose": "assertionMethod", + "ethereumAddress": "0xf6dcc520f11ad600da7E01da44e0e70D094ea246", + "verificationMethod": "did:pkh:eip155:1:0xf6dcc520f11ad600da7e01da44e0e70d094ea246#ethereumAddress" + }, + "issuer": { + "id": "did:pkh:eip155:1:0xf6dcc520f11ad600da7e01da44e0e70d094ea246", + "ethereumAddress": "0xf6dcc520f11ad600da7E01da44e0e70D094ea246" + }, + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://raw.githubusercontent.com/w3c-ccg/ethereum-eip712-signature-2021-spec/main/contexts/v1/index.json" + ], + "issuanceDate": "2023-02-17T02:55:22.549Z", + "expirationDate": "2123-02-17T02:55:22.549Z", + "credentialSchema": { + "id": "https://app.vess.id/schemas/EventAttendance.json", + "type": "Eip712SchemaValidator2021" + }, + "credentialSubject": { + "id": "did:pkh:eip155:1:0xde695cbb6ec0cf3f4c9564070baeb032552c5111", + "eventId": "kjzl6cwe1jw14bn99lu4spvfdvjyxtm4cg2ys5jmd0gqjaov5fqifwlf0af3hbt", + "eventIcon": "https://bafybeibgqa2kti2c53vq7tajbidclxbjytsgucqjdffmc2yniepejiqs7i.ipfs.w3s.link/nec_preevent.png", + "eventName": "NEC Web3 Community Pre-Event" + } +} diff --git a/__tests__/fixtures/cred4.json b/__tests__/fixtures/cred4.json new file mode 100644 index 000000000..f4ffad2fe --- /dev/null +++ b/__tests__/fixtures/cred4.json @@ -0,0 +1,29 @@ +{ + "type": [ + "VerifiableCredential" + ], + "proof": { + "jws": "eyJhbGciOiJFZERTQSIsImNyaXQiOlsiYjY0Il0sImI2NCI6ZmFsc2V9.._T9sbXJAcDPWT9WX02uT4Ky5LGGjmQoo2VeglQgxzgsfJyUfBFIahn40d0d_58UShoPOfmfDEKJvuM_2W0wJCg", + "type": "Ed25519Signature2018", + "created": "2023-02-08T20:19:52.256Z", + "proofPurpose": "assertionMethod", + "verificationMethod": "did:key:z6MkghvGHLobLEdj1bgRLhS4LPGJAvbMA1tn2zcRyqmYU5LC#z6MkghvGHLobLEdj1bgRLhS4LPGJAvbMA1tn2zcRyqmYU5LC" + }, + "issuer": "did:key:z6MkghvGHLobLEdj1bgRLhS4LPGJAvbMA1tn2zcRyqmYU5LC", + "@context": [ + "https://www.w3.org/2018/credentials/v1" + ], + "issuanceDate": "2023-02-08T20:19:52.255Z", + "expirationDate": "2023-05-09T20:19:52.255Z", + "credentialSubject": { + "id": "did:pkh:eip155:1:0xACFB657781452e50f6Bd126e01C2aEF6817a5D48", + "hash": "v0.0.0:bJHkYMu57TlOcBYT9oGiywDXSHPCidOZl0CQ2DhNJKE=", + "@context": [ + { + "hash": "https://schema.org/Text", + "provider": "https://schema.org/Text" + } + ], + "provider": "Github" + } +} diff --git a/__tests__/localMemoryStoreAgent.test.ts b/__tests__/localMemoryStoreAgent.test.ts index e96d2a5ec..7a6dc3a8a 100644 --- a/__tests__/localMemoryStoreAgent.test.ts +++ b/__tests__/localMemoryStoreAgent.test.ts @@ -16,9 +16,7 @@ import { IResolver, TAgent, } from '../packages/core-types/src' -import { - createAgent -} from '../packages/core/src' +import { createAgent } from '../packages/core/src' import { MessageHandler } from '../packages/message-handler/src' import { KeyManager, MemoryKeyStore, MemoryPrivateKeyStore } from '../packages/key-manager/src' import { DIDManager, MemoryDIDStore } from '../packages/did-manager/src' @@ -32,7 +30,7 @@ import { ICredentialIssuerLD, LdDefaultContexts, VeramoEcdsaSecp256k1RecoverySignature2020, - VeramoEd25519Signature2018, + VeramoEd25519Signature2018, VeramoEd25519Signature2020, VeramoJsonWebSignature2020, } from '../packages/credential-ld/src' import { EthrDIDProvider } from '../packages/did-provider-ethr/src' import { WebDIDProvider } from '../packages/did-provider-web/src' @@ -49,7 +47,6 @@ import { Web3KeyManagementSystem } from '../packages/kms-web3/src' import { DataStore, DataStoreORM, Entities, migrations } from '../packages/data-store/src' import { FakeDidProvider, FakeDidResolver } from '../packages/test-utils/src' -import { Resolver } from 'did-resolver' import { getResolver as ethrDidResolver } from 'ethr-did-resolver' import { getResolver as webDidResolver } from 'web-did-resolver' import { contexts as credential_contexts } from '@transmute/credentials-context' @@ -57,20 +54,21 @@ import * as fs from 'fs' import { jest } from '@jest/globals' // Shared tests -import verifiableDataJWT from './shared/verifiableDataJWT' -import verifiableDataLD from './shared/verifiableDataLD' -import verifiableDataEIP712 from './shared/verifiableDataEIP712' -import handleSdrMessage from './shared/handleSdrMessage' -import resolveDid from './shared/resolveDid' -import webDidFlow from './shared/webDidFlow' -import saveClaims from './shared/saveClaims' -import documentationExamples from './shared/documentationExamples' -import keyManager from './shared/keyManager' -import didManager from './shared/didManager' -import didCommPacking from './shared/didCommPacking' -import messageHandler from './shared/messageHandler' -import utils from './shared/utils' -import credentialStatus from './shared/credentialStatus' +import verifiableDataJWT from './shared/verifiableDataJWT.js' +import verifiableDataLD from './shared/verifiableDataLD.js' +import verifiableDataEIP712 from './shared/verifiableDataEIP712.js' +import handleSdrMessage from './shared/handleSdrMessage.js' +import resolveDid from './shared/resolveDid.js' +import webDidFlow from './shared/webDidFlow.js' +import saveClaims from './shared/saveClaims.js' +import documentationExamples from './shared/documentationExamples.js' +import keyManager from './shared/keyManager.js' +import didManager from './shared/didManager.js' +import didCommPacking from './shared/didCommPacking.js' +import messageHandler from './shared/messageHandler.js' +import utils from './shared/utils.js' +import credentialStatus from './shared/credentialStatus.js' +import credentialInterop from './shared/credentialInterop.js' jest.setTimeout(60000) @@ -167,13 +165,11 @@ const setup = async (options?: IAgentOptions): Promise => { }, }), new DIDResolverPlugin({ - resolver: new Resolver({ - ...ethrDidResolver({ infuraProjectId }), - ...webDidResolver(), - ...getDidKeyResolver(), - ...getDidPkhResolver(), - ...new FakeDidResolver(() => agent).getDidFakeResolver(), - }), + ...ethrDidResolver({ infuraProjectId }), + ...webDidResolver(), + ...getDidKeyResolver(), + ...getDidPkhResolver(), + ...new FakeDidResolver(() => agent).getDidFakeResolver(), }), new DataStore(dbConnection), new DataStoreORM(dbConnection), @@ -190,7 +186,12 @@ const setup = async (options?: IAgentOptions): Promise => { new CredentialIssuerEIP712(), new CredentialIssuerLD({ contextMaps: [LdDefaultContexts, credential_contexts as any], - suites: [new VeramoEcdsaSecp256k1RecoverySignature2020(), new VeramoEd25519Signature2018()], + suites: [ + new VeramoEcdsaSecp256k1RecoverySignature2020(), + new VeramoEd25519Signature2018(), + new VeramoJsonWebSignature2020(), + new VeramoEd25519Signature2020(), + ], }), new SelectiveDisclosure(), ...(options?.plugins || []), @@ -233,4 +234,5 @@ describe('Local in-memory integration tests', () => { didCommPacking(testContext) utils(testContext) credentialStatus(testContext) + credentialInterop(testContext) }) diff --git a/__tests__/shared/credentialInterop.ts b/__tests__/shared/credentialInterop.ts new file mode 100644 index 000000000..053fab292 --- /dev/null +++ b/__tests__/shared/credentialInterop.ts @@ -0,0 +1,42 @@ +// noinspection ES6PreferShortImport + +import { + ICredentialPlugin, + IDataStore, + IDataStoreORM, + IDIDManager, + TAgent, +} from '../../packages/core-types/src' + +import * as fs from 'fs' + +type ConfiguredAgent = TAgent + +export default (testContext: { + getAgent: () => ConfiguredAgent + setup: () => Promise + tearDown: () => Promise +}) => { + describe('credential interop', () => { + let agent: ConfiguredAgent + + beforeAll(async () => { + await testContext.setup() + agent = testContext.getAgent() + }) + afterAll(testContext.tearDown) + + test.each([ + // ['cred1.json'], + // ['cred2.json'], + ['cred3.json'], + ['cred4.json'], + ])("should verify credential from the wild: '%s'", async (text) => { + let credential = (await fs.promises.readFile(`./__tests__/fixtures/${text}`, 'utf8')).toString() + credential = JSON.parse(credential) + + const { verified, error } = await agent.verifyCredential({ credential }) + expect(verified).toBe(true) + }) + }) +} diff --git a/__tests__/shared/verifiableDataEIP712.ts b/__tests__/shared/verifiableDataEIP712.ts index 0d5365de9..201276b04 100644 --- a/__tests__/shared/verifiableDataEIP712.ts +++ b/__tests__/shared/verifiableDataEIP712.ts @@ -30,11 +30,11 @@ export default (testContext: { beforeAll(async () => { await testContext.setup() agent = testContext.getAgent() + identifier = await agent.didManagerCreate({ kms: 'local' }) }) afterAll(testContext.tearDown) it('should create identifier', async () => { - identifier = await agent.didManagerCreate({ kms: 'local' }) expect(identifier).toHaveProperty('did') expect(identifier?.keys[0]?.meta?.algorithms).toContain('eth_signTypedData') }) diff --git a/packages/credential-eip712/src/agent/CredentialEIP712.ts b/packages/credential-eip712/src/agent/CredentialEIP712.ts index 5cb2e2c9f..1d9cd3bff 100644 --- a/packages/credential-eip712/src/agent/CredentialEIP712.ts +++ b/packages/credential-eip712/src/agent/CredentialEIP712.ts @@ -120,7 +120,7 @@ export class CredentialIssuerEIP712 implements IAgentPlugin { credential['proof']['proofValue'] = signature credential['proof']['eip712'] = { domain, - messageSchema: allTypes, + types: allTypes, primaryType, } @@ -135,21 +135,29 @@ export class CredentialIssuerEIP712 implements IAgentPlugin { const { credential } = args if (!credential.proof || !credential.proof.proofValue) throw new Error('invalid_argument: proof is undefined') - if (!credential.proof.eip712 || !credential.proof.eip712.messageSchema || !credential.proof.eip712.domain) - throw new Error('invalid_argument: proof.eip712 is missing expected properties') const { proof, ...signingInput } = credential - const { proofValue, eip712, ...verifyInputProof } = proof + const { proofValue, eip712, eip712Domain, ...verifyInputProof } = proof const verificationMessage = { ...signingInput, proof: verifyInputProof, } + const compat = { + ...eip712Domain, + ...eip712 + } + + compat.types = compat.types || compat.messageSchema + + if (!compat.primaryType || !compat.types || !compat.domain) + throw new Error('invalid_argument: proof is missing expected properties') + const objectToVerify = { message: verificationMessage, - domain: eip712.domain, - types: eip712.messageSchema, - primaryType: eip712.primaryType, + domain: compat.domain, + types: compat.types, + primaryType: compat.primaryType, } const recovered = recoverTypedSignature({ @@ -266,7 +274,7 @@ export class CredentialIssuerEIP712 implements IAgentPlugin { presentation.proof.eip712 = { domain, - messageSchema: allTypes, + types: allTypes, primaryType, } @@ -280,25 +288,29 @@ export class CredentialIssuerEIP712 implements IAgentPlugin { ): Promise { const { presentation } = args if (!presentation.proof || !presentation.proof.proofValue) throw new Error('Proof is undefined') - if ( - !presentation.proof.eip712 || - !presentation.proof.eip712.messageSchema || - !presentation.proof.eip712.domain - ) - throw new Error('proof.eip712 is undefined') const { proof, ...signingInput } = presentation - const { proofValue, eip712, ...verifyInputProof } = proof + const { proofValue, eip712, eip712Domain, ...verifyInputProof } = proof const verificationMessage = { ...signingInput, proof: verifyInputProof, } + const compat = { + ...eip712Domain, + ...eip712 + } + + compat.types = compat.types || compat.messageSchema + + if (!compat.primaryType || !compat.types || !compat.domain) + throw new Error('invalid_argument: presentation proof is missing expected properties') + const objectToVerify = { message: verificationMessage, - domain: eip712.domain, - types: eip712.messageSchema, - primaryType: eip712.primaryType, + domain: compat.domain, + types: compat.types, + primaryType: compat.primaryType, } const recovered = recoverTypedSignature({ diff --git a/packages/credential-ld/src/contexts/eip712.json b/packages/credential-ld/src/contexts/eip712.json new file mode 100644 index 000000000..995be0260 --- /dev/null +++ b/packages/credential-ld/src/contexts/eip712.json @@ -0,0 +1,93 @@ +{ + "@context": { + "@version": 1.1, + "@protected": true, + "Eip712SchemaValidator2021": "https://w3id.org/security#Eip712SchemaValidator2021", + "EthereumEip712Signature2021": { + "@id": "https://w3id.org/security#EthereumEip712Signature2021", + "@context": { + "@version": 1.1, + "@protected": true, + "id": "@id", + "type": "@type", + "created": { + "@id": "http://purl.org/dc/terms/created", + "@type": "http://www.w3.org/2001/XMLSchema#dateTime" + }, + "domain": "https://w3id.org/security#domain", + "proofPurpose": { + "@id": "https://w3id.org/security#proofPurpose", + "@type": "@vocab", + "@context": { + "@version": 1.1, + "@protected": true, + "id": "@id", + "type": "@type", + "assertionMethod": { + "@id": "https://w3id.org/security#assertionMethod", + "@type": "@id", + "@container": "@set" + }, + "authentication": { + "@id": "https://w3id.org/security#authenticationMethod", + "@type": "@id", + "@container": "@set" + }, + "capabilityInvocation": { + "@id": "https://w3id.org/security#capabilityInvocationMethod", + "@type": "@id", + "@container": "@set" + }, + "capabilityDelegation": { + "@id": "https://w3id.org/security#capabilityDelegationMethod", + "@type": "@id", + "@container": "@set" + } + } + }, + "eip712Domain": { + "@id": "https://w3c-ccg.github.io/ethereum-eip712-signature-2021-spec/#eip712-domain", + "@context": { + "@version": 1.1, + "@protected": true, + "id": "@id", + "type": "@type", + "messageSchema": { + "@id": "https://w3c-ccg.github.io/ethereum-eip712-signature-2021-spec/#message-schema", + "@type": "@json" + }, + "primaryType": "https://w3c-ccg.github.io/ethereum-eip712-signature-2021-spec/#primary-type", + "domain": { + "@id": "https://w3c-ccg.github.io/ethereum-eip712-signature-2021-spec/#domain", + "@type": "@json" + } + } + }, + "eip712": { + "@id": "https://w3c-ccg.github.io/ethereum-eip712-signature-2021-spec/#eip712-domain", + "@context": { + "@version": 1.1, + "@protected": true, + "id": "@id", + "type": "@type", + "types": { + "@id": "https://w3c-ccg.github.io/ethereum-eip712-signature-2021-spec/#message-schema", + "@type": "@json" + }, + "primaryType": "https://w3c-ccg.github.io/ethereum-eip712-signature-2021-spec/#primary-type", + "domain": { + "@id": "https://w3c-ccg.github.io/ethereum-eip712-signature-2021-spec/#domain", + "@type": "@json" + } + } + }, + "proofValue": "https://w3id.org/security#proofValue", + "verificationMethod": { + "@id": "https://w3id.org/security#verificationMethod", + "@type": "@id" + }, + "canonicalizationHash": "https://w3id.org/security/suites/eip712sig-2021#canonicalizationHash" + } + } + } +} diff --git a/packages/credential-ld/src/ld-default-contexts.ts b/packages/credential-ld/src/ld-default-contexts.ts index 3c8f6cfe2..f4b0fbe5a 100644 --- a/packages/credential-ld/src/ld-default-contexts.ts +++ b/packages/credential-ld/src/ld-default-contexts.ts @@ -1,16 +1,17 @@ -import contextCredentialV1 from "./contexts/www.w3.org_2018_credentials_v1.json" assert { type: 'json' } -import contextDidV1 from "./contexts/www.w3.org_ns_did_v1.json" assert { type: 'json' } -import contextSecurityV1 from "./contexts/w3id.org_security_v1.json" assert { type: 'json' } -import contextSecurityV2 from "./contexts/w3id.org_security_v2.json" assert { type: 'json' } -import contextSecurityV3 from "./contexts/w3id.org_security_v3-unstable.json" assert { type: 'json' } -import contextSuitesEd25519 from "./contexts/w3id.org_security_suites_ed25519-2018_v1.json" assert { type: 'json' } -import contextSuitesX25519 from "./contexts/w3id.org_security_suites_x25519-2019_v1.json" assert { type: 'json' } -import contextProfile from "./contexts/veramo.io_contexts_profile_v1.json" assert { type: 'json' } -import contextLdsEcdsaSecpRecovery2020_0 from "./contexts/lds-ecdsa-secp256k1-recovery2020-0.0.json" assert { type: 'json' } -import contextLdsEcdsaSecpRecovery2020_2 from "./contexts/w3id.org_security_suites_secp256k1recovery-2020_v2.json" assert { type: 'json' } -import contextSuitesSecp from "./contexts/w3id.org_security_suites_secp256k1recovery-2020_v2.json" assert { type: 'json' } +import contextCredentialV1 from './contexts/www.w3.org_2018_credentials_v1.json' assert { type: 'json' } +import contextDidV1 from './contexts/www.w3.org_ns_did_v1.json' assert { type: 'json' } +import contextSecurityV1 from './contexts/w3id.org_security_v1.json' assert { type: 'json' } +import contextSecurityV2 from './contexts/w3id.org_security_v2.json' assert { type: 'json' } +import contextSecurityV3 from './contexts/w3id.org_security_v3-unstable.json' assert { type: 'json' } +import contextSuitesEd25519 from './contexts/w3id.org_security_suites_ed25519-2018_v1.json' assert { type: 'json' } +import contextSuitesX25519 from './contexts/w3id.org_security_suites_x25519-2019_v1.json' assert { type: 'json' } +import contextProfile from './contexts/veramo.io_contexts_profile_v1.json' assert { type: 'json' } +import contextLdsEcdsaSecpRecovery2020_0 from './contexts/lds-ecdsa-secp256k1-recovery2020-0.0.json' assert { type: 'json' } +import contextLdsEcdsaSecpRecovery2020_2 from './contexts/w3id.org_security_suites_secp256k1recovery-2020_v2.json' assert { type: 'json' } +import contextSuitesSecp from './contexts/w3id.org_security_suites_secp256k1recovery-2020_v2.json' assert { type: 'json' } import contextSuitesEd25519_2020 from './contexts/ed25519-signature-2020-v1.json' assert { type: 'json' } import contextSuitesJws_2020 from './contexts/json-web-signature-2020-v1.json' assert { type: 'json' } +import contextSuiteEip712 from './contexts/eip712.json' assert { type: 'json' } /** * Provides a hardcoded map of common Linked Data `@context` definitions. @@ -31,14 +32,16 @@ export const LdDefaultContexts = new Map([ ['https://w3id.org/security/suites/x25519-2019/v1', contextSuitesX25519], ['https://w3id.org/security/suites/ed25519-2020/v1', contextSuitesEd25519_2020], ['https://w3id.org/security/suites/jws-2020/v1', contextSuitesJws_2020], - // ['https://w3id.org/did/v0.11', require('./contexts/did_v0.11.json')], - // ['https://veramo.io/contexts/socialmedia/v1', require('./contexts/socialmedia-v1.json')], - // ['https://veramo.io/contexts/kyc/v1', require('./contexts/kyc-v1.json')], ['https://veramo.io/contexts/profile/v1', contextProfile], - // ['https://ns.did.ai/transmute/v1', require('./contexts/transmute_v1.json')], - ['https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld', contextLdsEcdsaSecpRecovery2020_0], - ['https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-2.0.jsonld', contextLdsEcdsaSecpRecovery2020_2], - ['https://w3id.org/security/suites/secp256k1recovery-2020/v2', contextSuitesSecp] - // ['https://w3id.org/security/suites/ed25519-2018/v1', require('./contexts/ed25519-signature-2018-v1.json')], - // ['https://w3id.org/security/suites/x25519-2019/v1', require('./contexts/X25519KeyAgreementKey2019.json')], + [ + 'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld', + contextLdsEcdsaSecpRecovery2020_0, + ], + [ + 'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-2.0.jsonld', + contextLdsEcdsaSecpRecovery2020_2, + ], + ['https://w3id.org/security/suites/secp256k1recovery-2020/v2', contextSuitesSecp], + ['https://w3id.org/security/suites/eip712sig-2021', contextSuiteEip712], + ['https://w3c-ccg.github.io/ethereum-eip712-signature-2021-spec/', contextSuiteEip712], ])