Use swap method that works with react-native

This commit is contained in:
Jackson Mills
2022-07-15 15:54:08 -07:00
parent 60e90aaed0
commit d07efd5bc4

View File

@@ -177,10 +177,14 @@ function bufferToArray(buf: Buffer): number[] {
* @returns A buffer containing the same data with reversed endianness
*/
function swap128(buf: Buffer): Buffer {
const result = Buffer.alloc(16)
result.writeBigUInt64LE(buf.readBigUInt64BE(0), 8)
result.writeBigUInt64LE(buf.readBigUInt64BE(8), 0)
return result
// Interprets buffer as an array of (two, in this case) 64-bit numbers and swaps byte order in-place.
const reversedBytes = buf.swap64()
// Swap the two 64-bit numbers since our buffer is 128 bits.
return Buffer.concat(
[reversedBytes.slice(8, 16), reversedBytes.slice(0, 8)],
16,
)
}
export { rfc1751MnemonicToKey, keyToRFC1751Mnemonic }