Coder Social home page Coder Social logo

docknetwork / crypto-wasm-ts Goto Github PK

View Code? Open in Web Editor NEW
22.0 11.0 6.0 15.05 MB

Typescript abstractions over Rust crypto library's WASM wrapper

License: Apache License 2.0

TypeScript 95.65% JavaScript 0.06% Circom 4.29%
cryptography zero-knowledge-proofs accumulator signature-scheme anonymous-credentials circom privacy-enhancing-technologies zk-snarks

crypto-wasm-ts's People

Contributors

cykoder avatar lovesh avatar nicobao avatar olegnn avatar osinakayah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crypto-wasm-ts's Issues

Add pseudonyms support for presentation

Hi!

I will be using dock libraries and dock wallet for https://github.com/privency

The voting system relies heavily on hash of credential attributes - aka pseudonyms.

Pseudonyms have been implemented in Pseudonym.js, and thoroughly tested in pseudonym.spec.ts, but they are not available in Presentations.

I worked on adding support for pseudonyms in presentation, allowing:

  • pseudonyms based on secret only
  • attributes-bound pseudonyms based on attributes only. Attributes can be taken from different credentials.
  • attributes-bound pseudonyms based on attributes + secret. Attributes can be taken from different credentials.
  • presenting the pseudonyms
  • only presenting zk proof of pseudonym calculation, without revealing pseudonym itself. Possibility to also present a proof that the calculated pseudonym is equal to another unrevealed attribute

I am sending a draft PR, and would love your feedback.
After work is finished here, I'm happy to help bringing support for it in the wallet.

This line fails, the entry at the given index is sometimes not defined

dsForAll[i].push(universalAccumulatorComputeD(nonMembers[i], currentBatch));

Here's a rough reproducer

async function perfTest<T>(name: string, rounds: number, f: (i: number) => Promise<T>): Promise<T[]> {
	const result: T[] = []
	const startTime = Date.now()
	for (let i = 0; i < rounds; i++) {
		result.push(await f(i))
	}
	const endTime = Date.now()

	console.log(`Performance test for ${name}: Ran ${rounds} rounds in ${endTime - startTime} ms\nAverage time: ${(endTime - startTime) / rounds} ms`)

	return result
}

const params = UniversalAccumulator.generateParams()
		const keypair = UniversalAccumulator.generateKeypair(params)
		const state = new InMemoryUniversalState()
		const init = new InMemoryInitialElementsStore()

		const test_data_count = 20
		const test_non_data_count = 10
		const accum = await UniversalAccumulator.initialize(0, params, keypair.secretKey, init)

		// Append random data
		const testData = [...Array(test_data_count)].map(() => crypto.randomBytes(32))
		await perfTest('append single', test_data_count, async (i) => {
			const data = UniversalAccumulator.encodeBytesAsAccumulatorMember(testData[i])
			await accum.add(data, keypair.sk, state)
			return data
		})
		
		// Generate non-membership proofs
		const nonData = [...Array(test_non_data_count)].map(() => UniversalAccumulator.encodeBytesAsAccumulatorMember(crypto.randomBytes(32)))
		const witness = await perfTest('non-member single prove', nonData.length, async (i) => {
			const witness = await accum.nonMembershipWitness(nonData[i], state, keypair.sk, params, init)
			return witness
		})

		const validator = UniversalAccumulator.fromAccumulated(accum.accumulated)
		await perfTest('non-member single validate', nonData.length, async (i) => {
			const valid = validator.verifyNonMembershipWitness(nonData[i], witness[i], keypair.pk, params)
			expect(valid).toEqual(true)
		})

		// Batch non-membership proofs
		const batch = [...Array(test_non_data_count)].map(() => UniversalAccumulator.encodeBytesAsAccumulatorMember(crypto.randomBytes(32)))
		const [batchWitness] = await perfTest('non-member batch prove', 1, async () => {
			const witness = await accum.nonMembershipWitnessesForBatch(batch, state, keypair.sk, params, init)
			return witness
		})
		void batchWitness

		// await perfTest('non-member batch verify', batchWitness.length, async (i) => {
		// 	const valid = validator.verifyNonMembershipWitness(batch[i], batchWitness[i], keypair.pk, params)
		// 	expect(valid).toEqual(true)
		// })

Using crypto-wasm-ts in a browser

I'm trying to use the module in a browser, but it cannot be resolved correctly: Uncaught TypeError: Failed to resolve module specifier "@docknetwork/crypto-wasm-ts".

Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.