@aztec/foundation 0.87.2 → 0.87.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/random/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/random/index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,4BAOtC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,WAIpC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,WAIvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,eAGzB,CAAC"}
|
|
@@ -1,43 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import isNode from 'detect-node';
|
|
1
|
+
import { randomBytes as bbRandomBytes } from '@aztec/bb.js';
|
|
3
2
|
import { RandomnessSingleton } from './randomness_singleton.js';
|
|
4
|
-
// limit of Crypto.getRandomValues()
|
|
5
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
|
|
6
|
-
const MAX_BYTES = 65536;
|
|
7
|
-
const getWebCrypto = ()=>{
|
|
8
|
-
if (typeof window !== 'undefined' && window.crypto) {
|
|
9
|
-
return window.crypto;
|
|
10
|
-
}
|
|
11
|
-
if (typeof self !== 'undefined' && self.crypto) {
|
|
12
|
-
return self.crypto;
|
|
13
|
-
}
|
|
14
|
-
return undefined;
|
|
15
|
-
};
|
|
16
3
|
export const randomBytes = (len)=>{
|
|
17
4
|
const singleton = RandomnessSingleton.getInstance();
|
|
18
5
|
if (singleton.isDeterministic()) {
|
|
19
6
|
return singleton.getBytes(len);
|
|
20
7
|
}
|
|
21
|
-
|
|
22
|
-
return nodeCrypto.randomBytes(len);
|
|
23
|
-
}
|
|
24
|
-
const crypto = getWebCrypto();
|
|
25
|
-
if (!crypto) {
|
|
26
|
-
throw new Error('randomBytes UnsupportedEnvironment');
|
|
27
|
-
}
|
|
28
|
-
const buf = Buffer.allocUnsafe(len);
|
|
29
|
-
if (len > MAX_BYTES) {
|
|
30
|
-
// this is the max bytes crypto.getRandomValues
|
|
31
|
-
// can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
|
|
32
|
-
for(let generated = 0; generated < len; generated += MAX_BYTES){
|
|
33
|
-
// buffer.slice automatically checks if the end is past the end of
|
|
34
|
-
// the buffer so we don't have to here
|
|
35
|
-
crypto.getRandomValues(buf.slice(generated, generated + MAX_BYTES));
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
crypto.getRandomValues(buf);
|
|
39
|
-
}
|
|
40
|
-
return buf;
|
|
8
|
+
return Buffer.from(bbRandomBytes(len));
|
|
41
9
|
};
|
|
42
10
|
/**
|
|
43
11
|
* Generate a random integer less than max.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/foundation",
|
|
3
|
-
"version": "0.87.
|
|
3
|
+
"version": "0.87.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dest/index.js",
|
|
6
6
|
"types": "./dest/index.d.ts",
|
|
@@ -100,13 +100,11 @@
|
|
|
100
100
|
]
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@aztec/bb.js": "0.87.
|
|
103
|
+
"@aztec/bb.js": "0.87.3",
|
|
104
104
|
"@koa/cors": "^5.0.0",
|
|
105
105
|
"@noble/curves": "^1.2.0",
|
|
106
|
-
"bn.js": "^5.2.1",
|
|
107
106
|
"c-kzg": "4.0.0-alpha.1",
|
|
108
107
|
"colorette": "^2.0.20",
|
|
109
|
-
"debug": "^4.3.4",
|
|
110
108
|
"detect-node": "^2.1.0",
|
|
111
109
|
"hash.js": "^1.1.7",
|
|
112
110
|
"koa": "^2.16.1",
|
|
@@ -126,8 +124,6 @@
|
|
|
126
124
|
"devDependencies": {
|
|
127
125
|
"@jest/globals": "^29.5.0",
|
|
128
126
|
"@libp2p/interface": "1.3.1",
|
|
129
|
-
"@types/bn.js": "^5.1.3",
|
|
130
|
-
"@types/debug": "^4.1.7",
|
|
131
127
|
"@types/detect-node": "^2.0.0",
|
|
132
128
|
"@types/jest": "^29.5.0",
|
|
133
129
|
"@types/koa": "^2.15.0",
|
|
@@ -1,52 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import isNode from 'detect-node';
|
|
1
|
+
import { randomBytes as bbRandomBytes } from '@aztec/bb.js';
|
|
3
2
|
|
|
4
3
|
import { RandomnessSingleton } from './randomness_singleton.js';
|
|
5
4
|
|
|
6
|
-
// limit of Crypto.getRandomValues()
|
|
7
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
|
|
8
|
-
const MAX_BYTES = 65536;
|
|
9
|
-
|
|
10
|
-
const getWebCrypto = () => {
|
|
11
|
-
if (typeof window !== 'undefined' && window.crypto) {
|
|
12
|
-
return window.crypto;
|
|
13
|
-
}
|
|
14
|
-
if (typeof self !== 'undefined' && self.crypto) {
|
|
15
|
-
return self.crypto;
|
|
16
|
-
}
|
|
17
|
-
return undefined;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
5
|
export const randomBytes = (len: number) => {
|
|
21
6
|
const singleton = RandomnessSingleton.getInstance();
|
|
22
7
|
|
|
23
8
|
if (singleton.isDeterministic()) {
|
|
24
9
|
return singleton.getBytes(len);
|
|
25
10
|
}
|
|
26
|
-
|
|
27
|
-
if (isNode) {
|
|
28
|
-
return nodeCrypto.randomBytes(len) as Buffer;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const crypto = getWebCrypto();
|
|
32
|
-
if (!crypto) {
|
|
33
|
-
throw new Error('randomBytes UnsupportedEnvironment');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const buf = Buffer.allocUnsafe(len);
|
|
37
|
-
if (len > MAX_BYTES) {
|
|
38
|
-
// this is the max bytes crypto.getRandomValues
|
|
39
|
-
// can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
|
|
40
|
-
for (let generated = 0; generated < len; generated += MAX_BYTES) {
|
|
41
|
-
// buffer.slice automatically checks if the end is past the end of
|
|
42
|
-
// the buffer so we don't have to here
|
|
43
|
-
crypto.getRandomValues(buf.slice(generated, generated + MAX_BYTES));
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
crypto.getRandomValues(buf);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return buf;
|
|
11
|
+
return Buffer.from(bbRandomBytes(len)) as Buffer<ArrayBuffer>;
|
|
50
12
|
};
|
|
51
13
|
|
|
52
14
|
/**
|