@totemsdk/core 1.2.3 → 1.2.4

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.
Files changed (2) hide show
  1. package/dist/bip39.js +12 -3
  2. package/package.json +1 -1
package/dist/bip39.js CHANGED
@@ -402,14 +402,23 @@ function phraseToSeed(rawPhrase) {
402
402
  * @returns Array of 24 random BIP39 words (lowercase)
403
403
  */
404
404
  function generateWordList() {
405
- if (typeof crypto === 'undefined' || !crypto.getRandomValues) {
405
+ const randomValues = new Uint32Array(24);
406
+ if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
407
+ crypto.getRandomValues(randomValues);
408
+ }
409
+ else if (typeof process !== 'undefined' && process.versions?.node) {
410
+ const nodeCrypto = Function('return require')()('crypto');
411
+ const bytes = nodeCrypto.randomBytes(96);
412
+ for (let i = 0; i < 24; i++) {
413
+ randomValues[i] = bytes.readUInt32BE(i * 4);
414
+ }
415
+ }
416
+ else {
406
417
  throw new Error('generateWordList: no cryptographically secure random source available. ' +
407
418
  'Seed generation requires crypto.getRandomValues (browser/Node 19+) or node:crypto.randomBytes (Node). ' +
408
419
  'Math.random() is not acceptable for key material.');
409
420
  }
410
421
  const words = [];
411
- const randomValues = new Uint32Array(24);
412
- crypto.getRandomValues(randomValues);
413
422
  for (let i = 0; i < 24; i++) {
414
423
  const index = randomValues[i] % exports.WORD_LIST.length;
415
424
  words.push(exports.WORD_LIST[index]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totemsdk/core",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Core cryptographic primitives for Totem SDK — backed by Rust/WASM",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",