diff --git a/src/tabris/Crypto.js b/src/tabris/Crypto.js index 270d2d8a0..727a5aad0 100644 --- a/src/tabris/Crypto.js +++ b/src/tabris/Crypto.js @@ -20,6 +20,7 @@ export default class Crypto extends NativeObject { throw new Error('Not enough random bytes available'); } new Uint8Array(typedArray.buffer).set(values); + return typedArray; } } diff --git a/test/tabris/Crypto.test.js b/test/tabris/Crypto.test.js index 1ebd23ed8..503c419c5 100644 --- a/test/tabris/Crypto.test.js +++ b/test/tabris/Crypto.test.js @@ -130,6 +130,13 @@ describe('Crypto', function() { expect(buffer[2]).to.equal(0xffffffff); }); + it('returns given array', function() { + const buffer = new Uint32Array(3); + returnValue = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 1, 255, 255, 255, 255]); + + expect(crypto.getRandomValues(buffer)).to.equal(buffer); + }); + }); }); diff --git a/typings/global/crypto.d.ts b/typings/global/crypto.d.ts index 4643cab49..03254f86d 100644 --- a/typings/global/crypto.d.ts +++ b/typings/global/crypto.d.ts @@ -1,9 +1,7 @@ -declare class Crypto { - - getRandomValues( - typedArray: Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array - ): void; +type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array; +declare class Crypto { + getRandomValues(typedArray: TypedArray): TypedArray; } -declare var crypto: Crypto; \ No newline at end of file +declare var crypto: Crypto;