Skip to content

Commit 3106fc1

Browse files
committed
script: refactor isCanonicalPubKey to bitcoin-core equivalent
1 parent 0ff5bd5 commit 3106fc1

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/script.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,17 @@ function decompile (buffer) {
118118

119119
function isCanonicalPubKey (buffer) {
120120
if (!Buffer.isBuffer(buffer)) return false
121-
122-
try {
123-
ecurve.Point.decodeFrom(curve, buffer)
124-
} catch (e) {
125-
if (!(e.message.match(/Invalid sequence (length|tag)/))) {
126-
throw e
127-
}
128-
129-
return false
121+
if (buffer.length < 33) return false
122+
123+
switch (buffer[0]) {
124+
case 0x02:
125+
case 0x03:
126+
return buffer.length === 33
127+
case 0x04:
128+
return buffer.length === 65
130129
}
131130

132-
return true
131+
return false
133132
}
134133

135134
function isCanonicalSignature (buffer) {

0 commit comments

Comments
 (0)