-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rm ECSignature, add script.signature instead
- Loading branch information
Showing
17 changed files
with
330 additions
and
804 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
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var bip66 = require('bip66') | ||
var BigInteger = require('bigi') | ||
|
||
// BIP62: 1 byte hashType flag (only 0x01, 0x02, 0x03, 0x81, 0x82 and 0x83 are allowed) | ||
function decode (buffer) { | ||
var hashType = buffer.readUInt8(buffer.length - 1) | ||
var hashTypeMod = hashType & ~0x80 | ||
if (hashTypeMod <= 0 || hashTypeMod >= 4) throw new Error('Invalid hashType ' + hashType) | ||
|
||
var decode = bip66.decode(buffer.slice(0, -1)) | ||
|
||
return { | ||
signature: { | ||
r: BigInteger.fromDERInteger(decode.r), | ||
s: BigInteger.fromDERInteger(decode.s) | ||
}, | ||
hashType: hashType | ||
} | ||
} | ||
|
||
function encode (signature, hashType) { | ||
var hashTypeMod = hashType & ~0x80 | ||
if (hashTypeMod <= 0 || hashTypeMod >= 4) throw new Error('Invalid hashType ' + hashType) | ||
|
||
var hashTypeBuffer = new Buffer(1) | ||
hashTypeBuffer.writeUInt8(hashType, 0) | ||
|
||
var r = new Buffer(signature.r.toDERInteger()) | ||
var s = new Buffer(signature.s.toDERInteger()) | ||
|
||
return Buffer.concat([ | ||
bip66.encode(r, s), | ||
hashTypeBuffer | ||
]) | ||
} | ||
|
||
module.exports = { | ||
decode: decode, | ||
encode: encode | ||
} |
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
Oops, something went wrong.