@celo/poprf
Advanced tools
+1
-1
| { | ||
| "name": "@celo/poprf", | ||
| "description": "A threshold-computable partially-oblivous psuedo-random function", | ||
| "version": "0.1.0", | ||
| "version": "0.1.1", | ||
| "license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "repository": { |
+2
-2
@@ -168,7 +168,7 @@ /* tslint:disable */ | ||
| */ | ||
| readonly blindingFactor: Uint8Array; | ||
| readonly blindedMessage: Uint8Array; | ||
| /** | ||
| * @returns {Uint8Array} | ||
| */ | ||
| readonly message: Uint8Array; | ||
| readonly blindingFactor: Uint8Array; | ||
| } | ||
@@ -175,0 +175,0 @@ /** |
+102
-18
| let imports = {}; | ||
| imports['__wbindgen_placeholder__'] = module.exports; | ||
| let wasm; | ||
| const { TextDecoder, inspect } = require(`util`); | ||
| const { TextDecoder, TextEncoder, inspect } = require(`util`); | ||
@@ -59,2 +59,10 @@ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); | ||
| } | ||
| let cachegetInt32Memory0 = null; | ||
| function getInt32Memory0() { | ||
| if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { | ||
| cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); | ||
| } | ||
| return cachegetInt32Memory0; | ||
| } | ||
| /** | ||
@@ -77,18 +85,21 @@ * Given a message and a seed, it will blind it and return the blinded message | ||
| module.exports.blindMsg = function(message, seed) { | ||
| var ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc); | ||
| var len0 = WASM_VECTOR_LEN; | ||
| var ptr1 = passArray8ToWasm0(seed, wasm.__wbindgen_malloc); | ||
| var len1 = WASM_VECTOR_LEN; | ||
| var ret = wasm.blindMsg(ptr0, len0, ptr1, len1); | ||
| return BlindedMessage.__wrap(ret); | ||
| try { | ||
| const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
| var ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc); | ||
| var len0 = WASM_VECTOR_LEN; | ||
| var ptr1 = passArray8ToWasm0(seed, wasm.__wbindgen_malloc); | ||
| var len1 = WASM_VECTOR_LEN; | ||
| wasm.blindMsg(retptr, ptr0, len0, ptr1, len1); | ||
| var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
| var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
| var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
| if (r2) { | ||
| throw takeObject(r1); | ||
| } | ||
| return BlindedMessage.__wrap(r0); | ||
| } finally { | ||
| wasm.__wbindgen_add_to_stack_pointer(16); | ||
| } | ||
| }; | ||
| let cachegetInt32Memory0 = null; | ||
| function getInt32Memory0() { | ||
| if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { | ||
| cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); | ||
| } | ||
| return cachegetInt32Memory0; | ||
| } | ||
| function getArrayU8FromWasm0(ptr, len) { | ||
@@ -387,2 +398,54 @@ return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); | ||
| let cachedTextEncoder = new TextEncoder('utf-8'); | ||
| const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' | ||
| ? function (arg, view) { | ||
| return cachedTextEncoder.encodeInto(arg, view); | ||
| } | ||
| : function (arg, view) { | ||
| const buf = cachedTextEncoder.encode(arg); | ||
| view.set(buf); | ||
| return { | ||
| read: arg.length, | ||
| written: buf.length | ||
| }; | ||
| }); | ||
| function passStringToWasm0(arg, malloc, realloc) { | ||
| if (realloc === undefined) { | ||
| const buf = cachedTextEncoder.encode(arg); | ||
| const ptr = malloc(buf.length); | ||
| getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); | ||
| WASM_VECTOR_LEN = buf.length; | ||
| return ptr; | ||
| } | ||
| let len = arg.length; | ||
| let ptr = malloc(len); | ||
| const mem = getUint8Memory0(); | ||
| let offset = 0; | ||
| for (; offset < len; offset++) { | ||
| const code = arg.charCodeAt(offset); | ||
| if (code > 0x7F) break; | ||
| mem[ptr + offset] = code; | ||
| } | ||
| if (offset !== len) { | ||
| if (offset !== 0) { | ||
| arg = arg.slice(offset); | ||
| } | ||
| ptr = realloc(ptr, len, len = offset + arg.length * 3); | ||
| const view = getUint8Memory0().subarray(ptr + offset, ptr + len); | ||
| const ret = encodeString(arg, view); | ||
| offset += ret.written; | ||
| } | ||
| WASM_VECTOR_LEN = offset; | ||
| return ptr; | ||
| } | ||
| /** | ||
@@ -402,3 +465,3 @@ * A blinded message along with the blinding_factor used to produce it | ||
| return { | ||
| message: this.message, | ||
| blindedMessage: this.blindedMessage, | ||
| blindingFactor: this.blindingFactor, | ||
@@ -430,6 +493,6 @@ }; | ||
| */ | ||
| get message() { | ||
| get blindedMessage() { | ||
| try { | ||
| const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
| wasm.blindedmessage_message(retptr, this.ptr); | ||
| wasm.blindedmessage_blindedMessage(retptr, this.ptr); | ||
| var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
@@ -633,2 +696,23 @@ var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
| module.exports.__wbg_new_693216e109162396 = function() { | ||
| var ret = new Error(); | ||
| return addHeapObject(ret); | ||
| }; | ||
| module.exports.__wbg_stack_0ddaca5d1abfb52f = function(arg0, arg1) { | ||
| var ret = getObject(arg1).stack; | ||
| var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
| var len0 = WASM_VECTOR_LEN; | ||
| getInt32Memory0()[arg0 / 4 + 1] = len0; | ||
| getInt32Memory0()[arg0 / 4 + 0] = ptr0; | ||
| }; | ||
| module.exports.__wbg_error_09919627ac0992f5 = function(arg0, arg1) { | ||
| try { | ||
| console.error(getStringFromWasm0(arg0, arg1)); | ||
| } finally { | ||
| wasm.__wbindgen_free(arg0, arg1); | ||
| } | ||
| }; | ||
| module.exports.__wbindgen_throw = function(arg0, arg1) { | ||
@@ -635,0 +719,0 @@ throw new Error(getStringFromWasm0(arg0, arg1)); |
+4
-4
@@ -36,3 +36,3 @@ # Celo POPRF | ||
| ```typescript | ||
| import '@celo/poprf' | ||
| import * as poprf from '@celo/poprf' | ||
| import 'crypto' | ||
@@ -47,9 +47,9 @@ | ||
| // Client: Blind the message to send to the server. | ||
| const blindMessage = poprf.blindMsg(message, crypto.randomBytes(32)) | ||
| const { blindedMessage, blindingFactor } = poprf.blindMsg(message, crypto.randomBytes(32)) | ||
| // Server: Evaluate the POPRF over the blinded message and tag. | ||
| const response = poprf.blindEval(keypair.privateKey, tag, blindMessage.message) | ||
| const response = poprf.blindEval(keypair.privateKey, tag, blindedMessage) | ||
| // Client: Unblind and verify the evaluation returned from the server. | ||
| const result = poprf.unblindResp(keypair.publicKey, blindMessage.blindingFactor, tag, response) | ||
| const result = poprf.unblindResp(keypair.publicKey, blindingFactor, tag, response) | ||
| ``` |
Sorry, the diff of this file is not supported yet
877
8.81%357117
-9.72%