Skip to content

Commit

Permalink
Merge pull request #327 from docknetwork/fix/range-proofs-presentatio…
Browse files Browse the repository at this point in the history
…ns-numbers

update the number placeholders for range proofs to match certs
  • Loading branch information
maycon-mello authored Jan 17, 2025
2 parents ce9e7f4 + 888eaed commit 2db6b60
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 19 deletions.
5 changes: 3 additions & 2 deletions integration-tests/verification-flow/proof-requests.ts

Large diffs are not rendered by default.

91 changes: 88 additions & 3 deletions integration-tests/verification-flow/range-proofs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
import {createVerificationController} from '@docknetwork/wallet-sdk-core/src/verification-controller';
import {createProofRequest} from '../helpers/certs-helpers';
import axios from 'axios';
import {boundCheckSnarkKey} from './proof-requests';

describe('Range proofs verification', () => {
it('should verify range proofs presentation without subject', async () => {
it('should create range proofs presentation without subject', async () => {
const wallet: IWallet = await getWallet();
const controller = await createVerificationController({
wallet,
Expand Down Expand Up @@ -46,9 +47,93 @@ describe('Range proofs verification', () => {
expect(
presentation.verifiableCredential[0].credentialSubject,
).toBeUndefined();
});

it('should generate range proofs presentation using number max placeholder', async () => {
const wallet: IWallet = await getWallet();
const controller = await createVerificationController({
wallet,
});

const credentialUrl =
'https://creds-testnet.truvera.io/3e824efbead0f72cbe0070923d981762122bf5440cfce513e96b65482ea4934a';
const password = '1234';
const {data: credential} = await axios.get(
`${credentialUrl}?p=${btoa(password)}`,
);

await getCredentialProvider().addCredential(credential);

const result = await controller.submitPresentation(presentation);
expect(result.verified).toBe(true);
await controller.start({
template: {
boundCheckSnarkKey,
signature: null,
qr: 'https://creds-testnet.truvera.io/proof/b8acdd33-e8e0-491f-8674-6ba521d9ea84',
id: 'b8acdd33-e8e0-491f-8674-6ba521d9ea84',
name: 'test data',
nonce: '798b999c18bb83f0f9669aac91c68910',
created: '2025-01-15T16:34:06.077Z',
response_url:
'https://api-testnet.truvera.io/proof-requests/b8acdd33-e8e0-491f-8674-6ba521d9ea84/send-presentation',
request: {
id: 'b8acdd33-e8e0-491f-8674-6ba521d9ea84',
input_descriptors: [
{
id: 'Credential 1',
name: 'test data',
purpose: 'test',
constraints: {
fields: [
{
path: ['$.credentialSubject.id'],
optional: false,
},
{
path: ['$.credentialSubject.number'],
filter: {
type: 'number',
exclusiveMinimum: 0,
},
optional: false,
predicate: 'required',
},
{
path: ['$.credentialSchema.id'],
filter: {
const:
'https://schema.truvera.io/TestingCheqdSchema-V1-1736958567072.json',
},
},
{
path: ['$.credentialSubject.name'],
optional: false,
},
],
},
},
],
},
type: 'proof-request',
},
});

const attributesToReveal = [
'credentialSubject.id',
'credentialSubject.name',
'credentialSubject.date',
'credentialSubject.number',
];

controller.selectedCredentials.set(credential.id, {
credential: credential,
attributesToReveal,
});

const presentation = await controller.createPresentation();

expect(
presentation.verifiableCredential[0].credentialSubject,
).toBeDefined();
});

afterAll(() => closeWallet());
Expand Down
7 changes: 2 additions & 5 deletions packages/wasm/src/services/credential/bound-check.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import {
applyEnforceBounds,
MAX_DATE_PLACEHOLDER,
MIN_DATE_PLACEHOLDER,
MAX_NUMBER,
fetchProvingKey,
isBase64OrDataUrl,
MIN_INTEGER,
} from './bound-check';
import {PresentationBuilder} from '@docknetwork/crypto-wasm-ts/lib';
import proofRequest from './proof-request.json';
import { replaceResponseURL } from '@docknetwork/wallet-sdk-core/src/helpers';
import assert from 'assert';
import { MAX_DATE_PLACEHOLDER, MAX_NUMBER, MIN_DATE_PLACEHOLDER, MIN_NUMBER } from './pex-helpers';

const testAPIURL = process.env.TESTING_API_URL || null;

Expand Down Expand Up @@ -218,7 +215,7 @@ describe('Bound check', () => {

const credIdx = 0;
const attributeName = 'credentialSubject.income';
const min = MIN_INTEGER;
const min = MIN_NUMBER;
const max = 20000;

expect(builder.enforceBounds).toHaveBeenCalledWith(
Expand Down
5 changes: 0 additions & 5 deletions packages/wasm/src/services/credential/bound-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,5 @@ export async function fetchProvingKey(proofRequest: ProofRequest) {
return {provingKey, provingKeyId: 'key0'};
}

export const MAX_DATE_PLACEHOLDER = 884541351600000;
export const MIN_DATE_PLACEHOLDER = -17592186044415;
export const MAX_NUMBER = Math.pow(100, 9);
export const MIN_INTEGER = -4294967295;

export const hasProvingKey = (proofRequest: ProofRequest) =>
!!proofRequest.boundCheckSnarkKey;
6 changes: 3 additions & 3 deletions packages/wasm/src/services/credential/pex-helpers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {JSONPath} from '@astronautlabs/jsonpath';

export const EPSILON_NUMBER = 0.0001;
export const EPSILON_NUMBER = 0.001;
export const EPSILON_INT = 1;

export const MAX_DATE_PLACEHOLDER = 884541351600000;
export const MIN_DATE_PLACEHOLDER = -17592186044415;
export const MAX_NUMBER = 100 ** 9;
export const MIN_NUMBER = -4294967295;
export const MAX_NUMBER = 100 ** 5;
export const MIN_NUMBER = -4294967294;

/*
PEX Filter rules:
Expand Down
2 changes: 1 addition & 1 deletion packages/wasm/src/services/credential/pex-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('pex helpers', () => {
{
attributeName: 'age',
min: 0,
max: 1000000000000000000,
max: 10000000000,
type: 'number',
format: undefined,
},
Expand Down

0 comments on commit 2db6b60

Please sign in to comment.