Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
TypeError: no se pueden leer las propiedades de undefined (leyendo 'bufferToHex') - Metamask

Estoy tratando de encriptar un mensaje usando un método de la API RPC de Metamask ( aquí ). Primero uso 'eth_getEncryptionPublicKey' para obtener la clave de cifrado de la cuenta a la que estoy conectado. Luego uso el siguiente código para encriptar mi mensaje. Sin embargo, recibo el siguiente error y no entiendo cómo solucionarlo. Por favor, ¿alguien puede aconsejar?

No sé si esto tiene algo que ver con mis errores, pero '@metamask/eth-sig-util' está escrito en TypeScript.

 import ethUtil from 'ethereumjs-util'; import sigUtil from '@metamask/eth-sig-util'; const encryptString = (encryptionKey, text) => { console.log('encryptString.encryptionKey: ' + encryptionKey); console.log('encryptString.text: ' + text); const encryptedMessage = ethUtil.bufferToHex( Buffer.from( JSON.stringify( sigUtil.encrypt({ publicKey: encryptionKey, data: text, version: 'x25519-xsalsa20-poly1305', }) ), 'utf-8' ) );

};

consola:

 encryptString.publicKey: Rb1/QuAkQ7qpyo9wzY5+E0Kw2AkL1Vipb8LObOGkkNw= encryptString.text: Hello World

Error:

 Uncaught TypeError: Cannot read properties of undefined (reading 'bufferToHex')
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tuve el mismo error, usar estas importaciones funcionó para mí:

 import { bufferToHex } from 'ethereumjs-util'; import { encrypt } from '@metamask/eth-sig-util';

Código completo adaptado a tu caso:

 import { bufferToHex } from 'ethereumjs-util'; import { encrypt } from '@metamask/eth-sig-util'; const encryptedMessage = bufferToHex( Buffer.from( JSON.stringify( encrypt({ publicKey: encryptionKey, data: 'hello world!', version: 'x25519-xsalsa20-poly1305', }), ), 'utf8', ), ); console.log(`Encrypted message: ${encryptedMessage}`); const decryptedMessage = await window as.ethereum.request({ method: 'eth_decrypt', params: [encryptedMessage, account], }); console.log(`Decrypted message: ${decryptedMessage}`);

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!