UNPKG

@toruslabs/metadata-helpers

Version:
32 lines (29 loc) 1.09 kB
export { invert, mod } from '@noble/curves/abstract/modular.js'; import { secp256k1 } from '@noble/curves/secp256k1.js'; export { secp256k1 } from '@noble/curves/secp256k1.js'; export { bytesToHex, bytesToNumberBE, bytesToNumberLE, numberToBytesBE, numberToHexUnpadded } from '@noble/curves/utils.js'; export { sha512 } from '@noble/hashes/sha2.js'; export { keccak_256 } from '@noble/hashes/sha3.js'; function toEthereumSignature(recoveredSig) { const ethSig = new Uint8Array(65); ethSig.set(recoveredSig.slice(1, 65), 0); // r + s ethSig[64] = recoveredSig[0]; // v at end return ethSig; } function getPublicKeyCoords(privateKeyBytes) { const pubKeyUncompressed = secp256k1.getPublicKey(privateKeyBytes, false); const x = pubKeyUncompressed.slice(1, 33); const y = pubKeyUncompressed.slice(33, 65); return { x, y }; } function coordsToPublicKey(x, y) { const pubKey = new Uint8Array(65); pubKey[0] = 0x04; // uncompressed prefix pubKey.set(x, 1); pubKey.set(y, 33); return pubKey; } export { coordsToPublicKey, getPublicKeyCoords, toEthereumSignature };