-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #403 from enkryptcom/develop
Release: v1.34.0
- Loading branch information
Showing
5 changed files
with
64 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/extension/src/providers/bitcoin/libs/sign-message-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { sha256 } from "ethereumjs-util"; | ||
|
||
const MAGIC_BYTES = Buffer.from("Bitcoin Signed Message:\n"); | ||
|
||
const varintBufNum = (n: number) => { | ||
let buf; | ||
if (n < 253) { | ||
buf = Buffer.alloc(1); | ||
buf.writeUInt8(n, 0); | ||
} else if (n < 0x10000) { | ||
buf = Buffer.alloc(1 + 2); | ||
buf.writeUInt8(253, 0); | ||
buf.writeUInt16LE(n, 1); | ||
} else if (n < 0x100000000) { | ||
buf = Buffer.alloc(1 + 4); | ||
buf.writeUInt8(254, 0); | ||
buf.writeUInt32LE(n, 1); | ||
} else { | ||
buf = Buffer.alloc(1 + 8); | ||
buf.writeUInt8(255, 0); | ||
buf.writeInt32LE(n & -1, 1); | ||
buf.writeUInt32LE(Math.floor(n / 0x100000000), 5); | ||
} | ||
return buf; | ||
}; | ||
|
||
export const magicHash = (messageBuffer: Buffer) => { | ||
const prefix1 = varintBufNum(MAGIC_BYTES.length); | ||
const prefix2 = varintBufNum(messageBuffer.length); | ||
const buf = Buffer.concat([prefix1, MAGIC_BYTES, prefix2, messageBuffer]); | ||
return sha256(sha256(buf)); | ||
}; | ||
|
||
export const toCompact = ( | ||
i: number, | ||
signature: Uint8Array, | ||
compressed: boolean | ||
) => { | ||
if (!(i === 0 || i === 1 || i === 2 || i === 3)) { | ||
throw new Error("i must be equal to 0, 1, 2, or 3"); | ||
} | ||
let val = i + 27 + 4; | ||
if (!compressed) { | ||
val = val - 4; | ||
} | ||
return Buffer.concat([Uint8Array.of(val), Uint8Array.from(signature)]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75347fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Virus total analysis
chrome:
https://www.virustotal.com/gui/file/254b883a44dc1fcb0bd75315eed2544de1629661c3508ab441be5f592dcf60cc
firefox:
https://www.virustotal.com/gui/file/dafcf8f656fbfe0b2cdd61c76e11a4b5258b9316e84073866d5f80714e941bca
75347fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Virus total analysis
chrome:
https://www.virustotal.com/gui/file/3e8296a3075b0757234cfaf9ca3e7415a75704b9cafec232f5aeab55ad108688
firefox:
https://www.virustotal.com/gui/file/07580e3baece730eb33897c050759d122d37e930ea43cbe7bcdcab2c810ddc47