Skip to content

Commit 2fb61c8

Browse files
committed
BitGo specific
1 parent 9b86c33 commit 2fb61c8

File tree

7 files changed

+21
-9
lines changed

7 files changed

+21
-9
lines changed

src/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import * as networks from './networks';
44
import * as payments from './payments';
55
import * as script from './script';
66
import * as taproot from './taproot';
7-
export { address, crypto, networks, payments, script, taproot };
7+
import * as ScriptSignature from './script_signature';
8+
export { ScriptSignature, address, crypto, networks, payments, script, taproot, };
89
export { Block } from './block';
910
export { TaggedHashPrefix } from './crypto';
1011
export { Psbt, PsbtTxInput, PsbtTxOutput, Signer, SignerAsync, HDSigner, HDSignerAsync, } from './psbt';

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
Object.defineProperty(exports, '__esModule', { value: true });
3-
exports.Transaction = exports.opcodes = exports.Psbt = exports.Block = exports.taproot = exports.script = exports.payments = exports.networks = exports.crypto = exports.address = void 0;
3+
exports.Transaction = exports.opcodes = exports.Psbt = exports.Block = exports.taproot = exports.script = exports.payments = exports.networks = exports.crypto = exports.address = exports.ScriptSignature = void 0;
44
const address = require('./address');
55
exports.address = address;
66
const crypto = require('./crypto');
@@ -13,6 +13,8 @@ const script = require('./script');
1313
exports.script = script;
1414
const taproot = require('./taproot');
1515
exports.taproot = taproot;
16+
const ScriptSignature = require('./script_signature');
17+
exports.ScriptSignature = ScriptSignature;
1618
var block_1 = require('./block');
1719
Object.defineProperty(exports, 'Block', {
1820
enumerable: true,

src/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function isCanonicalPubKey(buffer) {
167167
}
168168
exports.isCanonicalPubKey = isCanonicalPubKey;
169169
function isDefinedHashType(hashType) {
170-
const hashTypeMod = hashType & ~0x80;
170+
const hashTypeMod = hashType & ~0xc0;
171171
// return hashTypeMod > SIGHASH_ALL && hashTypeMod < SIGHASH_SINGLE
172172
return hashTypeMod > 0x00 && hashTypeMod < 0x04;
173173
}

src/script_signature.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function fromDER(x) {
2323
// BIP62: 1 byte hashType flag (only 0x01, 0x02, 0x03, 0x81, 0x82 and 0x83 are allowed)
2424
function decode(buffer) {
2525
const hashType = buffer.readUInt8(buffer.length - 1);
26-
const hashTypeMod = hashType & ~0x80;
26+
const hashTypeMod = hashType & ~0xc0;
2727
if (hashTypeMod <= 0 || hashTypeMod >= 4)
2828
throw new Error('Invalid hashType ' + hashType);
2929
const decoded = bip66.decode(buffer.slice(0, -1));
@@ -41,7 +41,7 @@ function encode(signature, hashType) {
4141
},
4242
{ signature, hashType },
4343
);
44-
const hashTypeMod = hashType & ~0x80;
44+
const hashTypeMod = hashType & ~0xc0;
4545
if (hashTypeMod <= 0 || hashTypeMod >= 4)
4646
throw new Error('Invalid hashType ' + hashType);
4747
const hashTypeBuffer = Buffer.allocUnsafe(1);

ts_src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ import * as networks from './networks';
44
import * as payments from './payments';
55
import * as script from './script';
66
import * as taproot from './taproot';
7+
import * as ScriptSignature from './script_signature';
78

8-
export { address, crypto, networks, payments, script, taproot };
9+
export {
10+
ScriptSignature,
11+
address,
12+
crypto,
13+
networks,
14+
payments,
15+
script,
16+
taproot,
17+
};
918

1019
export { Block } from './block';
1120
export { TaggedHashPrefix } from './crypto';

ts_src/script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export function isCanonicalPubKey(buffer: Buffer): boolean {
196196
}
197197

198198
export function isDefinedHashType(hashType: number): boolean {
199-
const hashTypeMod = hashType & ~0x80;
199+
const hashTypeMod = hashType & ~0xc0;
200200

201201
// return hashTypeMod > SIGHASH_ALL && hashTypeMod < SIGHASH_SINGLE
202202
return hashTypeMod > 0x00 && hashTypeMod < 0x04;

ts_src/script_signature.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface ScriptSignature {
2828
// BIP62: 1 byte hashType flag (only 0x01, 0x02, 0x03, 0x81, 0x82 and 0x83 are allowed)
2929
export function decode(buffer: Buffer): ScriptSignature {
3030
const hashType = buffer.readUInt8(buffer.length - 1);
31-
const hashTypeMod = hashType & ~0x80;
31+
const hashTypeMod = hashType & ~0xc0;
3232
if (hashTypeMod <= 0 || hashTypeMod >= 4)
3333
throw new Error('Invalid hashType ' + hashType);
3434

@@ -49,7 +49,7 @@ export function encode(signature: Buffer, hashType: number): Buffer {
4949
{ signature, hashType },
5050
);
5151

52-
const hashTypeMod = hashType & ~0x80;
52+
const hashTypeMod = hashType & ~0xc0;
5353
if (hashTypeMod <= 0 || hashTypeMod >= 4)
5454
throw new Error('Invalid hashType ' + hashType);
5555

0 commit comments

Comments
 (0)