@concordium/common-sdk
Advanced tools
Comparing version
import { ContractAddress, CryptographicParameters } from './types'; | ||
import { AttributeType } from './web3ProofTypes'; | ||
export declare type VerifyWeb3IdCredentialSignatureInput = { | ||
globalContext: CryptographicParameters; | ||
signature: string; | ||
values: Record<string, string | bigint>; | ||
values: Record<string, AttributeType>; | ||
randomness: Record<string, string>; | ||
@@ -7,0 +8,0 @@ holder: string; |
@@ -29,2 +29,3 @@ "use strict"; | ||
const json_bigint_1 = require("json-bigint"); | ||
const VerifiablePresentation_1 = require("./types/VerifiablePresentation"); | ||
/** | ||
@@ -35,3 +36,3 @@ * Verifies that the given signature is correct for the given values/randomness/holder/issuerPublicKey/issuerContract | ||
// Use json-bigint stringify to ensure we can handle bigints | ||
return wasm.verifyWeb3IdCredentialSignature((0, json_bigint_1.stringify)(input)); | ||
return wasm.verifyWeb3IdCredentialSignature((0, json_bigint_1.stringify)(input, VerifiablePresentation_1.replaceDateWithTimeStampAttribute)); | ||
} | ||
@@ -38,0 +39,0 @@ exports.verifyWeb3IdCredentialSignature = verifyWeb3IdCredentialSignature; |
@@ -436,2 +436,39 @@ "use strict"; | ||
/** | ||
* Helper to check if an attribute value is in the given range. | ||
*/ | ||
function isInRange(value, lower, upper) { | ||
if (typeof value === 'string' && | ||
typeof lower === 'string' && | ||
typeof upper === 'string') { | ||
return (0, web3IdHelpers_1.isStringAttributeInRange)(value, lower, upper); | ||
} | ||
if (typeof value === 'bigint' && | ||
typeof lower === 'bigint' && | ||
typeof upper === 'bigint') { | ||
return lower <= value && upper > value; | ||
} | ||
if (value instanceof Date && | ||
lower instanceof Date && | ||
upper instanceof Date) { | ||
return (lower.getTime() <= value.getTime() && | ||
upper.getTime() > value.getTime()); | ||
} | ||
// Mismatch in types. | ||
return false; | ||
} | ||
/** | ||
* Helper to check if an attribute value is in the given set. | ||
*/ | ||
function isInSet(value, set) { | ||
if (typeof value === 'string' || typeof value === 'bigint') { | ||
return set.includes(value); | ||
} | ||
if (value instanceof Date) { | ||
return set | ||
.map((date) => (date instanceof Date ? date.getTime() : undefined)) | ||
.includes(value.getTime()); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Given an atomic statement and a prover's attributes, determine whether the statement is fulfilled. | ||
@@ -441,9 +478,12 @@ */ | ||
const attribute = attributes[statement.attributeTag]; | ||
if (attribute === undefined) { | ||
return false; | ||
} | ||
switch (statement.type) { | ||
case commonProofTypes_1.StatementTypes.AttributeInRange: | ||
return isInRange(attribute, statement.lower, statement.upper); | ||
case commonProofTypes_1.StatementTypes.AttributeInSet: | ||
return statement.set.includes(attribute); | ||
return isInSet(attribute, statement.set); | ||
case commonProofTypes_1.StatementTypes.AttributeNotInSet: | ||
return !statement.set.includes(attribute); | ||
case commonProofTypes_1.StatementTypes.AttributeInRange: | ||
return statement.upper > attribute && attribute >= statement.lower; | ||
return !isInSet(attribute, statement.set); | ||
case commonProofTypes_1.StatementTypes.RevealAttribute: | ||
@@ -450,0 +490,0 @@ return attribute !== undefined; |
{ | ||
"name": "@concordium/common-sdk", | ||
"version": "9.1.0", | ||
"version": "9.1.1", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "engines": { |
1473567
8.25%130
10.17%33728
7.22%