Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@veramo/credential-eip712

Package Overview
Dependencies
Maintainers
3
Versions
286
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@veramo/credential-eip712 - npm Package Compare versions

Comparing version 3.1.6-next.168 to 3.1.6-next.169

2

build/agent/CredentialEIP712.d.ts

@@ -1,2 +0,2 @@

import { IAgentPlugin, VerifiableCredential, VerifiablePresentation } from "@veramo/core";
import { IAgentPlugin, VerifiableCredential, VerifiablePresentation } from '@veramo/core';
import { ICreateVerifiableCredentialEIP712Args, ICreateVerifiablePresentationEIP712Args, ICredentialIssuerEIP712, IRequiredContext } from '../types/ICredentialEIP712';

@@ -3,0 +3,0 @@ /**

@@ -40,3 +40,3 @@ "use strict";

verifyCredentialEIP712: this.verifyCredentialEIP712.bind(this),
verifyPresentationEIP712: this.verifyPresentationEIP712.bind(this)
verifyPresentationEIP712: this.verifyPresentationEIP712.bind(this),
};

@@ -56,3 +56,3 @@ }

if (!issuer || typeof issuer === 'undefined') {
throw new Error('invalid_argument: args.credential.issuer must not be empty');
throw new Error('invalid_argument: credential.issuer must not be empty');
}

@@ -64,9 +64,9 @@ let keyRef = args.keyRef;

if (!key)
throw Error('No signing key for ' + identifier.did);
throw Error('key_not_found: No suitable signing key is known for ' + identifier.did);
keyRef = key.kid;
}
const extendedKeys = yield (0, utils_1.mapIdentifierKeysToDoc)(identifier, 'verificationMethod', context);
const extendedKey = extendedKeys.find(key => key.kid === keyRef);
const extendedKey = extendedKeys.find((key) => key.kid === keyRef);
if (!extendedKey)
throw Error('Key not found');
throw Error('key_not_found: The signing key is not available in the issuer DID document');
const chainId = (0, utils_1.getChainIdForDidEthr)(extendedKey.meta.verificationMethod);

@@ -76,4 +76,4 @@ const credential = Object.assign(Object.assign({}, args === null || args === void 0 ? void 0 : args.credential), { '@context': credentialContext, type: credentialType, issuanceDate, proof: {

created: issuanceDate,
proofPurpose: "assertionMethod",
type: "EthereumEip712Signature2021",
proofPurpose: 'assertionMethod',
type: 'EthereumEip712Signature2021',
} });

@@ -83,6 +83,6 @@ const message = credential;

chainId,
name: "VerifiableCredential",
version: "1",
name: 'VerifiableCredential',
version: '1',
};
const primaryType = "VerifiableCredential";
const primaryType = 'VerifiableCredential';
const allTypes = (0, eip_712_types_generation_1.getEthTypesFromInputDoc)(credential, primaryType);

@@ -107,7 +107,5 @@ const types = Object.assign({}, allTypes);

if (!credential.proof || !credential.proof.proofValue)
throw new Error("Proof is undefined");
if (!credential.proof.eip712 ||
!credential.proof.eip712.messageSchema ||
!credential.proof.eip712.domain)
throw new Error("eip712 is undefined");
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 } = credential, signingInput = __rest(credential, ["proof"]);

@@ -120,3 +118,3 @@ const { proofValue, eip712 } = proof, verifyInputProof = __rest(proof, ["proofValue", "eip712"]);

types: eip712.messageSchema,
primaryType: eip712.primaryType
primaryType: eip712.primaryType,
};

@@ -126,7 +124,7 @@ const recovered = (0, eth_sig_util_1.recoverTypedSignature)({

signature: proofValue,
version: eth_sig_util_1.SignTypedDataVersion.V4
version: eth_sig_util_1.SignTypedDataVersion.V4,
});
const issuer = (0, utils_1.extractIssuer)(credential);
if (!issuer || typeof issuer === 'undefined') {
throw new Error('invalid_argument: args.credential.issuer must not be empty');
throw new Error('invalid_argument: credential.issuer must not be empty');
}

@@ -142,5 +140,5 @@ const didDocument = yield (0, utils_1.resolveDidOrThrow)(issuer, context);

else {
throw new Error("Recovered Address does not match issuer");
throw new Error('resolver_error: issuer DIDDocument does not contain any verificationMethods');
}
return true;
return false;
});

@@ -160,3 +158,3 @@ }

if (!(0, utils_1.isDefined)(args.presentation.holder)) {
throw new Error('invalid_argument: args.presentation.holder must not be empty');
throw new Error('invalid_argument: presentation.holder must not be empty');
}

@@ -180,3 +178,3 @@ if (args.presentation.verifiableCredential) {

catch (e) {
throw new Error('invalid_argument: args.presentation.holder must be a DID managed by this agent');
throw new Error('invalid_argument: presentation.holder must be a DID managed by this agent');
}

@@ -187,9 +185,9 @@ let keyRef = args.keyRef;

if (!key)
throw Error('No signing key for ' + identifier.did);
throw Error('key_not_found: No suitable signing key is known for ' + identifier.did);
keyRef = key.kid;
}
const extendedKeys = yield (0, utils_1.mapIdentifierKeysToDoc)(identifier, 'verificationMethod', context);
const extendedKey = extendedKeys.find(key => key.kid === keyRef);
const extendedKey = extendedKeys.find((key) => key.kid === keyRef);
if (!extendedKey)
throw Error('Key not found');
throw Error('key_not_found: The signing key is not available in the issuer DID document');
const chainId = (0, utils_1.getChainIdForDidEthr)(extendedKey.meta.verificationMethod);

@@ -199,4 +197,4 @@ presentation['proof'] = {

created: issuanceDate,
proofPurpose: "assertionMethod",
type: "EthereumEip712Signature2021",
proofPurpose: 'assertionMethod',
type: 'EthereumEip712Signature2021',
};

@@ -206,4 +204,4 @@ const message = presentation;

chainId,
name: "VerifiablePresentation",
version: "1",
name: 'VerifiablePresentation',
version: '1',
};

@@ -228,41 +226,39 @@ const primaryType = 'VerifiablePresentation';

return __awaiter(this, void 0, void 0, function* () {
try {
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("eip712 is undefined");
const { proof } = presentation, signingInput = __rest(presentation, ["proof"]);
const { proofValue, eip712 } = proof, verifyInputProof = __rest(proof, ["proofValue", "eip712"]);
const verificationMessage = Object.assign(Object.assign({}, signingInput), { proof: verifyInputProof });
const objectToVerify = {
message: verificationMessage,
domain: eip712.domain,
types: eip712.messageSchema,
primaryType: eip712.primaryType
};
const recovered = (0, eth_sig_util_1.recoverTypedSignature)({
data: objectToVerify,
signature: proofValue,
version: eth_sig_util_1.SignTypedDataVersion.V4
});
const issuer = (0, utils_1.extractIssuer)(presentation);
if (!issuer || typeof issuer === 'undefined') {
throw new Error('invalid_argument: args.presentation.issuer must not be empty');
}
const didDocument = yield (0, utils_1.resolveDidOrThrow)(issuer, context);
if (didDocument.verificationMethod) {
for (const verificationMethod of didDocument.verificationMethod) {
if (((_a = (0, utils_1.getEthereumAddress)(verificationMethod)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === recovered.toLowerCase()) {
return true;
}
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 } = presentation, signingInput = __rest(presentation, ["proof"]);
const { proofValue, eip712 } = proof, verifyInputProof = __rest(proof, ["proofValue", "eip712"]);
const verificationMessage = Object.assign(Object.assign({}, signingInput), { proof: verifyInputProof });
const objectToVerify = {
message: verificationMessage,
domain: eip712.domain,
types: eip712.messageSchema,
primaryType: eip712.primaryType,
};
const recovered = (0, eth_sig_util_1.recoverTypedSignature)({
data: objectToVerify,
signature: proofValue,
version: eth_sig_util_1.SignTypedDataVersion.V4,
});
const issuer = (0, utils_1.extractIssuer)(presentation);
if (!issuer || typeof issuer === 'undefined') {
throw new Error('invalid_argument: args.presentation.issuer must not be empty');
}
const didDocument = yield (0, utils_1.resolveDidOrThrow)(issuer, context);
if (didDocument.verificationMethod) {
for (const verificationMethod of didDocument.verificationMethod) {
if (((_a = (0, utils_1.getEthereumAddress)(verificationMethod)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === recovered.toLowerCase()) {
return true;
}
}
throw new Error("Recovered Address does not match issuer");
}
catch (e) {
throw new Error(e);
else {
throw new Error('resolver_error: holder DIDDocument does not contain any verificationMethods');
}
return false;
});

@@ -269,0 +265,0 @@ }

{
"name": "@veramo/credential-eip712",
"description": "Veramo plugin for working with EIP712 Verifiable Credentials & Presentations.",
"version": "3.1.6-next.168+ac0c05b3",
"version": "3.1.6-next.169+b987fc09",
"main": "build/index.js",

@@ -18,4 +18,4 @@ "types": "build/index.d.ts",

"@metamask/eth-sig-util": "^4.0.1",
"@veramo/core": "^3.1.6-next.168+ac0c05b3",
"@veramo/utils": "^3.1.6-next.168+ac0c05b3",
"@veramo/core": "^3.1.6-next.169+b987fc09",
"@veramo/utils": "^3.1.6-next.169+b987fc09",
"debug": "^4.3.3",

@@ -52,3 +52,3 @@ "eip-712-types-generation": "^0.1.6"

"keywords": [],
"gitHead": "ac0c05b32da286df1d8b3af9c39724b4bf44c990"
"gitHead": "b987fc0903a31d3bbffb43fef872be4d6c62c2ad"
}
import {
CredentialPayload, IAgentPlugin, IIdentifier, PresentationPayload, VerifiableCredential, VerifiablePresentation
} from "@veramo/core"
CredentialPayload,
IAgentPlugin,
IIdentifier,
PresentationPayload,
VerifiableCredential,
VerifiablePresentation,
} from '@veramo/core'
import {
extractIssuer, getChainIdForDidEthr,
extractIssuer,
getChainIdForDidEthr,
getEthereumAddress,
isDefined,
MANDATORY_CREDENTIAL_CONTEXT, mapIdentifierKeysToDoc, processEntryToArray,
resolveDidOrThrow
} from "@veramo/utils"
MANDATORY_CREDENTIAL_CONTEXT,
mapIdentifierKeysToDoc,
processEntryToArray,
resolveDidOrThrow,
} from '@veramo/utils'
import { schema } from '../index'

@@ -20,6 +28,6 @@

IVerifyCredentialEIP712Args,
IVerifyPresentationEIP712Args
IVerifyPresentationEIP712Args,
} from '../types/ICredentialEIP712'
import { getEthTypesFromInputDoc } from "eip-712-types-generation"
import { getEthTypesFromInputDoc } from 'eip-712-types-generation'

@@ -40,3 +48,3 @@ /**

verifyCredentialEIP712: this.verifyCredentialEIP712.bind(this),
verifyPresentationEIP712: this.verifyPresentationEIP712.bind(this)
verifyPresentationEIP712: this.verifyPresentationEIP712.bind(this),
}

@@ -62,3 +70,3 @@ }

if (!issuer || typeof issuer === 'undefined') {
throw new Error('invalid_argument: args.credential.issuer must not be empty')
throw new Error('invalid_argument: credential.issuer must not be empty')
}

@@ -71,4 +79,6 @@

if (!keyRef) {
const key = identifier.keys.find((k) => k.type === 'Secp256k1' && k.meta?.algorithms?.includes('eth_signTypedData'))
if (!key) throw Error('No signing key for ' + identifier.did)
const key = identifier.keys.find(
(k) => k.type === 'Secp256k1' && k.meta?.algorithms?.includes('eth_signTypedData'),
)
if (!key) throw Error('key_not_found: No suitable signing key is known for ' + identifier.did)
keyRef = key.kid

@@ -78,4 +88,5 @@ }

const extendedKeys = await mapIdentifierKeysToDoc(identifier, 'verificationMethod', context)
const extendedKey = extendedKeys.find(key => key.kid === keyRef)
if (!extendedKey) throw Error('Key not found')
const extendedKey = extendedKeys.find((key) => key.kid === keyRef)
if (!extendedKey)
throw Error('key_not_found: The signing key is not available in the issuer DID document')

@@ -92,16 +103,16 @@ const chainId = getChainIdForDidEthr(extendedKey.meta.verificationMethod)

created: issuanceDate,
proofPurpose: "assertionMethod",
type: "EthereumEip712Signature2021",
}
proofPurpose: 'assertionMethod',
type: 'EthereumEip712Signature2021',
},
}
const message = credential;
const message = credential
const domain = {
chainId,
name: "VerifiableCredential",
version: "1",
};
name: 'VerifiableCredential',
version: '1',
}
const primaryType = "VerifiableCredential"
const allTypes = getEthTypesFromInputDoc(credential, primaryType);
const primaryType = 'VerifiableCredential'
const allTypes = getEthTypesFromInputDoc(credential, primaryType)
const types = { ...allTypes }

@@ -113,3 +124,3 @@

credential['proof']['proofValue'] = signature;
credential['proof']['proofValue'] = signature
credential['proof']['eip712'] = {

@@ -121,20 +132,21 @@ domain,

return credential as VerifiableCredential;
return credential as VerifiableCredential
}
/** {@inheritdoc ICredentialIssuerEIP712.verifyCredentialEIP712} */
private async verifyCredentialEIP712(args: IVerifyCredentialEIP712Args, context: IRequiredContext): Promise<boolean> {
private async verifyCredentialEIP712(
args: IVerifyCredentialEIP712Args,
context: IRequiredContext,
): Promise<boolean> {
const { credential } = args
if (!credential.proof || !credential.proof.proofValue) throw new Error("Proof is undefined")
if (
!credential.proof.eip712 ||
!credential.proof.eip712.messageSchema ||
!credential.proof.eip712.domain
) throw new Error("eip712 is undefined");
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 { proof, ...signingInput } = credential
const { proofValue, eip712, ...verifyInputProof } = proof
const verificationMessage = {
...signingInput,
proof: verifyInputProof
proof: verifyInputProof,
}

@@ -146,3 +158,3 @@

types: eip712.messageSchema,
primaryType: eip712.primaryType
primaryType: eip712.primaryType,
}

@@ -153,3 +165,3 @@

signature: proofValue,
version: SignTypedDataVersion.V4
version: SignTypedDataVersion.V4,
})

@@ -159,6 +171,6 @@

if (!issuer || typeof issuer === 'undefined') {
throw new Error('invalid_argument: args.credential.issuer must not be empty')
throw new Error('invalid_argument: credential.issuer must not be empty')
}
const didDocument = await resolveDidOrThrow(issuer, context);
const didDocument = await resolveDidOrThrow(issuer, context)

@@ -171,8 +183,7 @@ if (didDocument.verificationMethod) {

}
} else {
throw new Error('resolver_error: issuer DIDDocument does not contain any verificationMethods')
}
else {
throw new Error("Recovered Address does not match issuer")
}
return true;
return false
}

@@ -203,3 +214,3 @@

if (!isDefined(args.presentation.holder)) {
throw new Error('invalid_argument: args.presentation.holder must not be empty')
throw new Error('invalid_argument: presentation.holder must not be empty')
}

@@ -223,3 +234,3 @@

} catch (e) {
throw new Error('invalid_argument: args.presentation.holder must be a DID managed by this agent')
throw new Error('invalid_argument: presentation.holder must be a DID managed by this agent')
}

@@ -230,4 +241,6 @@

if (!keyRef) {
const key = identifier.keys.find((k) => k.type === 'Secp256k1' && k.meta?.algorithms?.includes('eth_signTypedData'))
if (!key) throw Error('No signing key for ' + identifier.did)
const key = identifier.keys.find(
(k) => k.type === 'Secp256k1' && k.meta?.algorithms?.includes('eth_signTypedData'),
)
if (!key) throw Error('key_not_found: No suitable signing key is known for ' + identifier.did)
keyRef = key.kid

@@ -237,4 +250,5 @@ }

const extendedKeys = await mapIdentifierKeysToDoc(identifier, 'verificationMethod', context)
const extendedKey = extendedKeys.find(key => key.kid === keyRef)
if (!extendedKey) throw Error('Key not found')
const extendedKey = extendedKeys.find((key) => key.kid === keyRef)
if (!extendedKey)
throw Error('key_not_found: The signing key is not available in the issuer DID document')

@@ -245,15 +259,15 @@ const chainId = getChainIdForDidEthr(extendedKey.meta.verificationMethod)

created: issuanceDate,
proofPurpose: "assertionMethod",
type: "EthereumEip712Signature2021",
proofPurpose: 'assertionMethod',
type: 'EthereumEip712Signature2021',
}
const message = presentation;
const message = presentation
const domain = {
chainId,
name: "VerifiablePresentation",
version: "1",
};
name: 'VerifiablePresentation',
version: '1',
}
const primaryType = 'VerifiablePresentation'
const allTypes = getEthTypesFromInputDoc(presentation, primaryType);
const allTypes = getEthTypesFromInputDoc(presentation, primaryType)
const types = { ...allTypes }

@@ -265,5 +279,4 @@

presentation.proof.proofValue = signature
presentation.proof.proofValue = signature;
presentation.proof.eip712 = {

@@ -273,3 +286,3 @@ domain,

primaryType,
};
}

@@ -280,52 +293,54 @@ return presentation as VerifiablePresentation

/** {@inheritdoc ICredentialIssuerEIP712.verifyPresentationEIP712} */
private async verifyPresentationEIP712(args: IVerifyPresentationEIP712Args, context: IRequiredContext): Promise<boolean> {
try {
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("eip712 is undefined");
private async verifyPresentationEIP712(
args: IVerifyPresentationEIP712Args,
context: IRequiredContext,
): Promise<boolean> {
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 verificationMessage = {
...signingInput,
proof: verifyInputProof
}
const { proof, ...signingInput } = presentation
const { proofValue, eip712, ...verifyInputProof } = proof
const verificationMessage = {
...signingInput,
proof: verifyInputProof,
}
const objectToVerify = {
message: verificationMessage,
domain: eip712.domain,
types: eip712.messageSchema,
primaryType: eip712.primaryType
}
const objectToVerify = {
message: verificationMessage,
domain: eip712.domain,
types: eip712.messageSchema,
primaryType: eip712.primaryType,
}
const recovered = recoverTypedSignature({
data: objectToVerify,
signature: proofValue,
version: SignTypedDataVersion.V4
})
const recovered = recoverTypedSignature({
data: objectToVerify,
signature: proofValue,
version: SignTypedDataVersion.V4,
})
const issuer = extractIssuer(presentation)
if (!issuer || typeof issuer === 'undefined') {
throw new Error('invalid_argument: args.presentation.issuer must not be empty')
}
const issuer = extractIssuer(presentation)
if (!issuer || typeof issuer === 'undefined') {
throw new Error('invalid_argument: args.presentation.issuer must not be empty')
}
const didDocument = await resolveDidOrThrow(issuer, context);
const didDocument = await resolveDidOrThrow(issuer, context)
if (didDocument.verificationMethod) {
for (const verificationMethod of didDocument.verificationMethod) {
if (getEthereumAddress(verificationMethod)?.toLowerCase() === recovered.toLowerCase()) {
return true
}
if (didDocument.verificationMethod) {
for (const verificationMethod of didDocument.verificationMethod) {
if (getEthereumAddress(verificationMethod)?.toLowerCase() === recovered.toLowerCase()) {
return true
}
}
} else {
throw new Error('resolver_error: holder DIDDocument does not contain any verificationMethods')
}
throw new Error("Recovered Address does not match issuer")
} catch (e: any) {
throw new Error(e);
}
return false
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc