@gjsify/webcrypto 0.25.1 → 0.26.0
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.
- package/lib/esm/random.js +1 -1
- package/package.json +4 -4
package/lib/esm/random.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";const e=65536,t=[`webcrypto`,`urandom`];let n=!1,r=null;function gjsGi(){return globalThis.imports?.gi}function isSecureRandomSource(e){return t.includes(e)}function fillFromWebCrypto(t,n){for(let r=0;r<t.length;r+=e){let i=Math.min(t.length-r,e);n.getRandomValues(new Uint8Array(t.buffer,t.byteOffset+r,i))}}function openUrandom(){if(r!==null)return r;let e=gjsGi()?.Gio;if(!e)return r=!1,!1;try{r=e.File.new_for_path(`/dev/urandom`).read(null)}catch{r=!1}return r}function fillFromUrandom(e){let t=openUrandom();if(!t)return!1;try{let n=0;for(;n<e.length;){let r=t.read_bytes(e.length-n,null).toArray();if(r.length===0)return!1;e.set(r,n),n+=r.length}return!0}catch{return!1}}function fillFromGLib(e){let t=gjsGi()?.GLib;if(!t?.random_int_range)return!1;for(let n=0;n<e.length;n++)e[n]=t.random_int_range(0,256);return!0}function fillFromMath(e){for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256)}function warnInsecureOnce(e){n||(n=!0,console.warn(`[@gjsify/
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=65536,t=[`webcrypto`,`urandom`];let n=!1,r=null;function gjsGi(){return globalThis.imports?.gi}function isSecureRandomSource(e){return t.includes(e)}function fillFromWebCrypto(t,n){for(let r=0;r<t.length;r+=e){let i=Math.min(t.length-r,e);n.getRandomValues(new Uint8Array(t.buffer,t.byteOffset+r,i))}}function openUrandom(){if(r!==null)return r;let e=gjsGi()?.Gio;if(!e)return r=!1,!1;try{r=e.File.new_for_path(`/dev/urandom`).read(null)}catch{r=!1}return r}function fillFromUrandom(e){let t=openUrandom();if(!t)return!1;try{let n=0;for(;n<e.length;){let r=t.read_bytes(e.length-n,null).toArray();if(r.length===0)return!1;e.set(r,n),n+=r.length}return!0}catch{return!1}}function fillFromGLib(e){let t=gjsGi()?.GLib;if(!t?.random_int_range)return!1;for(let n=0;n<e.length;n++)e[n]=t.random_int_range(0,256);return!0}function fillFromMath(e){for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256)}function warnInsecureOnce(e){n||(n=!0,console.warn(`[@gjsify/webcrypto] No cryptographically secure random source available — falling back to "${e}". Neither GLib.Random nor Math.random is suitable for keys, tokens or IVs. Expected sources: WebCrypto (globalThis.crypto) or /dev/urandom via Gio on GJS.`))}function fillRandomBytes(e,t={}){if(e.length===0)return`webcrypto`;let n=t.webcrypto===void 0?globalThis.crypto??null:t.webcrypto;return n&&typeof n.getRandomValues==`function`?(fillFromWebCrypto(e,n),`webcrypto`):fillFromUrandom(e)?`urandom`:fillFromGLib(e)?(warnInsecureOnce(`glib`),`glib`):(fillFromMath(e),warnInsecureOnce(`math`),`math`)}function _resetRandomSourceCache(){r=null,n=!1}export{_resetRandomSourceCache,fillRandomBytes,isSecureRandomSource};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/webcrypto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "W3C WebCrypto API (SubtleCrypto) for GJS using @gjsify/crypto primitives",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"crypto"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@gjsify/dom-exception": "^0.
|
|
52
|
+
"@gjsify/dom-exception": "^0.26.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@gjsify/cli": "^0.
|
|
56
|
-
"@gjsify/unit": "^0.
|
|
55
|
+
"@gjsify/cli": "^0.26.0",
|
|
56
|
+
"@gjsify/unit": "^0.26.0",
|
|
57
57
|
"@types/node": "^25.9.2",
|
|
58
58
|
"typescript": "^6.0.3"
|
|
59
59
|
},
|