on master help sign in
crypto: sign messages with sha256
003c083tomholford
src/lib/authToken.ts+4−8
@@ -1,5 +1,5 @@
1+import { crypto } from 'bitcoinjs-lib';
1import { ecdsaSign } from 'secp256k1';
2import { ecdsaSign } from 'secp256k1';
2−import { keccak256 } from 'web3-utils';
3
3
4import { WALLET_TYPES } from './constants';
4import { WALLET_TYPES } from './constants';
5import { ledgerSignMessage } from './ledger';
5import { ledgerSignMessage } from './ledger';
@@ -9,13 +9,9 @@ const MESSAGE = 'Bridge Authentication Token';
9
9
10function signMessage(privateKey: Buffer) {
10function signMessage(privateKey: Buffer) {
11 const msg = '\x19Ethereum Signed Message:\n' + MESSAGE.length + MESSAGE;
11 const msg = '\x19Ethereum Signed Message:\n' + MESSAGE.length + MESSAGE;
12− // TODO: Signing function expects 32 length Buffer,
12+ // #ecdsaSign requires a 32-byte buffer, hence sha256
13− // confirm if it is okay / expected to slice it like this?
14− // Based on reading docs and comment threads, it seems that
15− // this limit is sometimes enforced, and varies depending on
16− // the implementation
17− const msgHash = Buffer.from(keccak256(msg)).slice(0, 32);
13+ const hashed = crypto.sha256(Buffer.from(msg));
18− const { signature } = ecdsaSign(msgHash, privateKey);
14+ const { signature } = ecdsaSign(Buffer.from(hashed), privateKey);
19
15
20 // add key recovery parameter
16 // add key recovery parameter
21 const ethSignature = new Uint8Array(65);
17 const ethSignature = new Uint8Array(65);