From 8a6ee5d72d5375697fec65ecc2a2b1970af05e37 Mon Sep 17 00:00:00 2001 From: Maycon Mello Date: Thu, 31 Aug 2023 13:39:39 -0300 Subject: [PATCH] range proofs part 2 --- jest.config.js | 1 + packages/cli/src/commands/verification.ts | 3 +++ packages/core/src/helpers.ts | 8 +++++++- packages/wasm/package.json | 5 ++++- .../src/services/credential/range-proof.test.ts | 9 +++++++++ .../wasm/src/services/credential/range-proof.ts | 16 ++++++++++++++++ packages/wasm/src/services/credential/service.ts | 4 ++++ packages/wasm/tsconfig.json | 4 +--- setup-tests.js | 12 ++++++------ 9 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 packages/wasm/src/services/credential/range-proof.test.ts create mode 100644 packages/wasm/src/services/credential/range-proof.ts diff --git a/jest.config.js b/jest.config.js index 8675c9f6..ce9e1591 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,5 @@ module.exports = { + preset: "ts-jest", testEnvironment: 'node', testTimeout: 30000, maxConcurrency: 2, diff --git a/packages/cli/src/commands/verification.ts b/packages/cli/src/commands/verification.ts index f9fd8471..6ea0438b 100644 --- a/packages/cli/src/commands/verification.ts +++ b/packages/cli/src/commands/verification.ts @@ -34,6 +34,9 @@ verificationCommands template = await clipboardy.read(); } } + + console.log('Got template', template); + console.log('Starting verification flow...'); await controller.start({ template, diff --git a/packages/core/src/helpers.ts b/packages/core/src/helpers.ts index 19520353..5e95ace7 100644 --- a/packages/core/src/helpers.ts +++ b/packages/core/src/helpers.ts @@ -12,7 +12,12 @@ function isURL(str) { } export function getJSONFromURL(url: string) { - return axios.get(url).then(res => res.data); + return axios + .get(url) + .then(res => res.data) + .catch(err => { + console.error(`Error fetching ${url}`, err); + }); } export function getJSON(jsonOrURL: string | any) { @@ -24,6 +29,7 @@ export function getJSON(jsonOrURL: string | any) { if (typeof jsonOrURL === 'string') { if (isURL(jsonOrURL)) { + console.log(`Fetching ${jsonOrURL}`); return getJSONFromURL(jsonOrURL); } else { return JSON.parse(jsonOrURL); diff --git a/packages/wasm/package.json b/packages/wasm/package.json index 58715906..a0a732fb 100644 --- a/packages/wasm/package.json +++ b/packages/wasm/package.json @@ -50,6 +50,9 @@ "devDependencies": { "realm": "^10.10.1", "@babel/node": "^7.16.0", - "sinon": "^12.0.1" + "sinon": "^12.0.1", + "jest": "29.6.1", + "ts-jest": "29.1.0", + "typescript": "^5.0.4" } } diff --git a/packages/wasm/src/services/credential/range-proof.test.ts b/packages/wasm/src/services/credential/range-proof.test.ts new file mode 100644 index 00000000..6d3923a7 --- /dev/null +++ b/packages/wasm/src/services/credential/range-proof.test.ts @@ -0,0 +1,9 @@ +import {createRangeProofPresentation} from "./range-proof"; +import {utilCryptoService} from "../util-crypto"; + +describe('Test range proofs', () => { + it('expect presentation to be created', async () => { + const result = await createRangeProofPresentation(); + expect(result).toBe(true); + }); +}); diff --git a/packages/wasm/src/services/credential/range-proof.ts b/packages/wasm/src/services/credential/range-proof.ts new file mode 100644 index 00000000..79c51171 --- /dev/null +++ b/packages/wasm/src/services/credential/range-proof.ts @@ -0,0 +1,16 @@ +import {LegoProvingKeyUncompressed, LegoVerifyingKeyUncompressed, LegoProvingKey } from '@docknetwork/crypto-wasm-ts/lib/legosnark' +import {BoundCheckSnarkSetup} from '@docknetwork/crypto-wasm-ts/lib/bound-check'; +import {initializeWasm} from '@docknetwork/crypto-wasm-ts/lib/index'; + +export async function createRangeProofPresentation() { + await initializeWasm(); + + // let snarkProvingKey: LegoProvingKeyUncompressed; + // let snarkVerifyingKey: LegoVerifyingKeyUncompressed; + // + const pk:LegoProvingKey = BoundCheckSnarkSetup(); + // snarkProvingKey = pk.decompress(); + // snarkVerifyingKey = pk.getVerifyingKeyUncompressed(); + + return true; +} diff --git a/packages/wasm/src/services/credential/service.ts b/packages/wasm/src/services/credential/service.ts index f2cd62ef..b9fab2eb 100644 --- a/packages/wasm/src/services/credential/service.ts +++ b/packages/wasm/src/services/credential/service.ts @@ -180,6 +180,10 @@ class CredentialService { return VerifiableCredential.fromJSON(credentialJSON); }); } + + async testRangeProof() { + console.log('test') + } } export const credentialService = new CredentialService(); diff --git a/packages/wasm/tsconfig.json b/packages/wasm/tsconfig.json index b71b1a57..7b2498a5 100644 --- a/packages/wasm/tsconfig.json +++ b/packages/wasm/tsconfig.json @@ -25,7 +25,5 @@ }, "esm": true }, - "include": ["src/**/*"], - "exclude": ["**/__tests__/**/*", "**/build/**/*"] + "include": ["src/**/*"] } - \ No newline at end of file diff --git a/setup-tests.js b/setup-tests.js index 5a54d6d6..ab5ae25e 100644 --- a/setup-tests.js +++ b/setup-tests.js @@ -24,12 +24,12 @@ const cfg = {url: 'http://localhost'}; const dom = new JSDOM('', cfg); global.window = dom.window; global.document = dom.window.document; - -Object.keys(global.window).forEach(property => { - if (typeof global[property] === 'undefined') { - global[property] = global.window[property]; - } -}); +// +// Object.keys(global.window).forEach(property => { +// if (typeof global[property] === 'undefined') { +// global[property] = global.window[property]; +// } +// }); global.navigator = { userAgent: 'node.js',