fn new_proof_timestamp(mut cx: FunctionContext) -> JsResult<JsObject> {
    let token_buffer: Handle<JsArrayBuffer> = cx.argument(0)?;
    let id_buffer: Handle<JsArrayBuffer> = cx.argument(1)?;
    let blindings_vec = obj_field_to_vec!(cx, 2);

    let token_bytes = cx.borrow(&token_buffer, |data| data.as_slice());
    if token_bytes.len() != Token::BYTES {
        return Err(Throw);
    }

    let mut blindings = Vec::with_capacity(blindings_vec.len());
    for b in blindings_vec {
        let a = b.downcast::<JsArrayBuffer>().or_throw(&mut cx)?;
        let blinding_bytes = cx.borrow(&a, |data| data.as_slice());

        if blinding_bytes.len() != Blinding::BYTES {
            return Err(Throw);
        }
        let blinding = Blinding::from_bytes(&<[u8; Blinding::BYTES]>::try_from(blinding_bytes).unwrap()).unwrap();
        blindings.push(blinding);
    }

    let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
    let timestamp_bytes = timestamp.as_micros().to_be_bytes();
    let token = Token::from_bytes(&<[u8; Token::BYTES]>::try_from(token_bytes).unwrap()).unwrap();
    let id_bytes = cx.borrow(&id_buffer, |data| data.as_slice());

    let proof = Proof::new(&token, blindings.as_slice(), id_bytes, &timestamp_bytes[..], OsRng{}).ok_or_else(|| Throw)?;

    let result = JsObject::new(&mut cx);
    let proof_bytes = slice_to_js_array_buffer!(&proof.to_bytes()[..], cx);
    let timestamp_bytes = slice_to_js_array_buffer!(&timestamp_bytes[..], cx);
    result.set(&mut cx, "proof", proof_bytes)?;
    result.set(&mut cx, "timestamp", timestamp_bytes)?;
    Ok(result)
}
/// Generates a new proof using the current system timestamp as the nonce
/// @param ArrayBuffer `token` - The token or blinded token for which to generate a proof
/// @param ArrayBuffer `id` - The identifier to use for this token
/// @param Array<ArrayBuffer> `blindings` - All the blindings applied to the token
/// @returns {
///     "proof": ArrayBuffer,
///     "timestamp": ArrayBuffer
/// }
Generates a new proof using the current system timestamp as the nonce
Generates a new proof using the current system timestamp as the nonce
fn new_proof_timestamp(mut cx: FunctionContext) -> JsResult<JsObject> {
    let token_buffer: Handle<JsArrayBuffer> = cx.argument(0)?;
    let id_buffer: Handle<JsArrayBuffer> = cx.argument(1)?;
    let blindings_vec = obj_field_to_vec!(cx, 2);
    let token_bytes = cx.borrow(&token_buffer, |data| data.as_slice());
    if token_bytes.len() != Token::BYTES {
        return Err(Throw);
    }
    let mut blindings = Vec::with_capacity(blindings_vec.len());
    for b in blindings_vec {
        let a = b.downcast::<JsArrayBuffer>().or_throw(&mut cx)?;
        let blinding_bytes = cx.borrow(&a, |data| data.as_slice());
        if blinding_bytes.len() != Blinding::BYTES {
            return Err(Throw);
        }
        let blinding = Blinding::from_bytes(&<[u8; Blinding::BYTES]>::try_from(blinding_bytes).unwrap()).unwrap();
        blindings.push(blinding);
    }
    let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
    let timestamp_bytes = timestamp.as_micros().to_be_bytes();
    let token = Token::from_bytes(&<[u8; Token::BYTES]>::try_from(token_bytes).unwrap()).unwrap();
    let id_bytes = cx.borrow(&id_buffer, |data| data.as_slice());
    let proof = Proof::new(&token, blindings.as_slice(), id_bytes, &timestamp_bytes[..], OsRng{}).ok_or_else(|| Throw)?;
    let result = JsObject::new(&mut cx);
    let proof_bytes = slice_to_js_array_buffer!(&proof.to_bytes()[..], cx);
    let timestamp_bytes = slice_to_js_array_buffer!(&timestamp_bytes[..], cx);
    result.set(&mut cx, "proof", proof_bytes)?;
    result.set(&mut cx, "timestamp", timestamp_bytes)?;
    Ok(result)
}
fn new_proof_timestamp ( mut cx : FunctionContext ) -> JsResult < JsObject > { let token_buffer : Handle < JsArrayBuffer > = cx . argument ( 0 ) ? ; let id_buffer : Handle < JsArrayBuffer > = cx . argument ( 1 ) ? ; let blindings_vec = obj_field_to_vec ! ( cx 2 ) ; let token_bytes = cx . borrow ( & token_buffer , | data | data . as_slice ( ) ) ; if token_bytes . len ( ) != Token :: BYTES { return Err ( Throw ) ; } let mut blindings = Vec :: with_capacity ( blindings_vec . len ( ) ) ; for b in blindings_vec { let a = b . downcast :: < JsArrayBuffer > ( ) . or_throw ( & mut cx ) ? ; let blinding_bytes = cx . borrow ( & a , | data | data . as_slice ( ) ) ; if blinding_bytes . len ( ) != Blinding :: BYTES { return Err ( Throw ) ; } let blinding = Blinding :: from_bytes ( & < [ u8 ; Blinding :: BYTES ] > :: try_from ( blinding_bytes ) . unwrap ( ) ) . unwrap ( ) ; blindings . push ( blinding ) ; } let timestamp = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) ; let timestamp_bytes = timestamp . as_micros ( ) . to_be_bytes ( ) ; let token = Token :: from_bytes ( & < [ u8 ; Token :: BYTES ] > :: try_from ( token_bytes ) . unwrap ( ) ) . unwrap ( ) ; let id_bytes = cx . borrow ( & id_buffer , | data | data . as_slice ( ) ) ; let proof = Proof :: new ( & token , blindings . as_slice ( ) , id_bytes , & timestamp_bytes [ .. ] , OsRng { } ) . ok_or_else ( | | Throw ) ? ; let result = JsObject :: new ( & mut cx ) ; let proof_bytes = slice_to_js_array_buffer ! ( proof to_bytes ( ) [ ] cx ) ; let timestamp_bytes = slice_to_js_array_buffer ! ( timestamp_bytes [ ] cx ) ; result . set ( & mut cx , " " , proof_bytes ) ? ; result . set ( & mut cx , " " , timestamp_bytes ) ? ; Ok ( result ) }
Generates a new proof using the current system timestamp as the nonce
Generates a new proof using the current system timestamp as the nonce
cx
FunctionContext
{
"proof": ArrayBuffer,
"timestamp": ArrayBuffer
}
{ " proof " : ArrayBuffer " timestamp " : ArrayBuffer }
cx
FunctionContext
ArrayBuffer
`id` - The identifier to use for this token
` id ` - The identifier to use for this token
Array<ArrayBuffer>
`blindings` - All the blindings applied to the token
` blindings ` - All the blindings applied to the token