Skip to content

Commit 05d8e8d

Browse files
authored
Merge pull request #236 from sCrypt-Inc/rename
Rename SigHash to SignatureHashType
2 parents e25ef49 + 8603e86 commit 05d8e8d

4 files changed

Lines changed: 29 additions & 29 deletions

File tree

src/scryptTypes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function HashedMap(map: Map<SupportedParamType, SupportedParamType>): Has
112112
return map as HashedMap;
113113
}
114114

115-
export enum SigHash {
115+
export enum SignatureHashType {
116116
ALL = 0x41,
117117
NONE = 0x42,
118118
SINGLE = 0x43,
@@ -121,12 +121,12 @@ export enum SigHash {
121121
ANYONECANPAY_SINGLE = 0xc3,
122122
}
123123

124-
export function SigHashType(s: SigHash | 0): SigHashType {
124+
export function SigHashType(s: SignatureHashType | 0): SigHashType {
125125
if (s == 0) {
126126
return '00' as SigHashType;
127-
} else if (s === SigHash.ALL || s === SigHash.NONE || s === SigHash.SINGLE
128-
|| s === SigHash.ANYONECANPAY_ALL || s === SigHash.ANYONECANPAY_NONE || s === SigHash.ANYONECANPAY_SINGLE) {
129-
return `${(s as SigHash).toString(16)}` as SigHashType;
127+
} else if (s === SignatureHashType.ALL || s === SignatureHashType.NONE || s === SignatureHashType.SINGLE
128+
|| s === SignatureHashType.ANYONECANPAY_ALL || s === SignatureHashType.ANYONECANPAY_NONE || s === SignatureHashType.ANYONECANPAY_SINGLE) {
129+
return `${(s as SignatureHashType).toString(16)}` as SigHashType;
130130
}
131131
throw new Error(`unsupported SigHashType: ${s}`);
132132
}

test/erc20.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { newTx, loadArtifact } from './helper';
44
import { buildContractClass } from '../src/contract';
55
import { bsv, getPreimage, signTx } from '../src/utils';
66
import { PubKey, toHex } from '../src';
7-
import { Sig, SigHash, SigHashPreimage } from '../src/scryptTypes';
7+
import { Sig, SignatureHashType, SigHashPreimage } from '../src/scryptTypes';
88

99
const inputIndex = 0;
1010
const inputSatoshis = 100000;
@@ -51,9 +51,9 @@ describe('Test sCrypt contract erc20 In Javascript', () => {
5151
}))
5252

5353

54-
preimage = getPreimage(tx, coin.lockingScript, inputSatoshis, 0, SigHash.SINGLE)
54+
preimage = getPreimage(tx, coin.lockingScript, inputSatoshis, 0, SignatureHashType.SINGLE)
5555

56-
const sigMinter = signTx(tx, privateKeyMinter, coin.lockingScript, inputSatoshis, 0, SigHash.SINGLE);
56+
const sigMinter = signTx(tx, privateKeyMinter, coin.lockingScript, inputSatoshis, 0, SignatureHashType.SINGLE);
5757

5858
// set txContext for verification
5959
coin.txContext = {
@@ -104,9 +104,9 @@ describe('Test sCrypt contract erc20 In Javascript', () => {
104104
}))
105105

106106

107-
preimage = getPreimage(tx, coin.lockingScript, inputSatoshis, 0, SigHash.SINGLE)
107+
preimage = getPreimage(tx, coin.lockingScript, inputSatoshis, 0, SignatureHashType.SINGLE)
108108

109-
const senderSig = signTx(tx, privateKeyMinter, coin.lockingScript, inputSatoshis, 0, SigHash.SINGLE);
109+
const senderSig = signTx(tx, privateKeyMinter, coin.lockingScript, inputSatoshis, 0, SignatureHashType.SINGLE);
110110

111111
// set txContext for verification
112112
coin.txContext = {
@@ -166,9 +166,9 @@ describe('Test sCrypt contract erc20 In Javascript', () => {
166166
}))
167167

168168

169-
preimage = getPreimage(tx, coin.lockingScript, inputSatoshis, 0, SigHash.SINGLE)
169+
preimage = getPreimage(tx, coin.lockingScript, inputSatoshis, 0, SignatureHashType.SINGLE)
170170

171-
const senderSig = signTx(tx, senderPrivateKey, coin.lockingScript, inputSatoshis, 0, SigHash.SINGLE);
171+
const senderSig = signTx(tx, senderPrivateKey, coin.lockingScript, inputSatoshis, 0, SignatureHashType.SINGLE);
172172

173173
// set txContext for verification
174174
coin.txContext = {

test/launchConfig.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { assert, expect } from 'chai';
22
import { excludeMembers, loadArtifact, newTx } from './helper';
33
import { buildContractClass } from '../src/contract';
4-
import { Bool, Bytes, Int, PrivKey, PubKey, Ripemd160, Sha256, SigHashPreimage, SigHashType, OpCodeType, SigHash, Sig } from '../src/scryptTypes';
4+
import { Bool, Bytes, Int, PrivKey, PubKey, Ripemd160, Sha256, SigHashPreimage, SigHashType, OpCodeType, SignatureHashType, Sig } from '../src/scryptTypes';
55
import { bsv, getPreimage, uri2path } from '../src/utils';
66
import { readFileSync } from 'fs';
77

@@ -22,7 +22,7 @@ describe('genLaunchConfig', () => {
2222
Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4"),
2323
Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
2424
OpCodeType('76'),
25-
SigHashType(SigHash.ALL),
25+
SigHashType(SignatureHashType.ALL),
2626
Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541")
2727
);
2828

@@ -33,7 +33,7 @@ describe('genLaunchConfig', () => {
3333
stateExample.ripemd160 = Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4");
3434
stateExample.sha256 = Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
3535
stateExample.opCodeType = OpCodeType('76');
36-
stateExample.sigHashType = SigHashType(SigHash.ALL);
36+
stateExample.sigHashType = SigHashType(SignatureHashType.ALL);
3737
stateExample.sig = Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541");
3838

3939

@@ -45,7 +45,7 @@ describe('genLaunchConfig', () => {
4545
ripemd160: Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4"),
4646
sha256: Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
4747
opCodeType: OpCodeType('76'),
48-
sigHashType: SigHashType(SigHash.ALL),
48+
sigHashType: SigHashType(SignatureHashType.ALL),
4949
sig: Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541")
5050
});
5151

test/state.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { assert, expect } from 'chai';
22
import { loadArtifact, newTx } from './helper';
33
import { buildContractClass } from '../src/contract';
4-
import { Bool, Bytes, Int, PrivKey, PubKey, Ripemd160, Sha256, SigHashPreimage, SigHashType, OpCodeType, SigHash, Sig } from '../src/scryptTypes';
4+
import { Bool, Bytes, Int, PrivKey, PubKey, Ripemd160, Sha256, SigHashPreimage, SigHashType, OpCodeType, SignatureHashType, Sig } from '../src/scryptTypes';
55
import { bsv, getPreimage } from '../src/utils';
66

77
const inputIndex = 0;
@@ -22,7 +22,7 @@ describe('state_test', () => {
2222
Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4"),
2323
Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
2424
OpCodeType("76"),
25-
SigHashType(SigHash.ALL),
25+
SigHashType(SignatureHashType.ALL),
2626
Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541"),
2727
);
2828

@@ -44,7 +44,7 @@ describe('state_test', () => {
4444
Ripemd160("02"),
4545
Sha256("03"),
4646
OpCodeType('76'),
47-
SigHashType(SigHash.ALL),
47+
SigHashType(SignatureHashType.ALL),
4848
Sig("05")
4949
);
5050

@@ -76,7 +76,7 @@ describe('state_test', () => {
7676
Ripemd160("02"),
7777
Sha256("03"),
7878
OpCodeType('76'),
79-
SigHashType(SigHash.ALL),
79+
SigHashType(SignatureHashType.ALL),
8080
Sig("05")
8181
);
8282

@@ -97,7 +97,7 @@ describe('state_test', () => {
9797
Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4"),
9898
Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
9999
OpCodeType('76'),
100-
SigHashType(SigHash.ALL),
100+
SigHashType(SignatureHashType.ALL),
101101
Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541")
102102
);
103103

@@ -108,7 +108,7 @@ describe('state_test', () => {
108108
stateExample.ripemd160 = Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4");
109109
stateExample.sha256 = Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
110110
stateExample.opCodeType = OpCodeType('76');
111-
stateExample.sigHashType = SigHashType(SigHash.ALL);
111+
stateExample.sigHashType = SigHashType(SignatureHashType.ALL);
112112
stateExample.sig = Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541");
113113

114114
let newStateExample = StateExample.fromHex(stateExample.lockingScript.toHex());
@@ -120,7 +120,7 @@ describe('state_test', () => {
120120
expect(newStateExample.ripemd160 === Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4")).to.be.true;
121121
expect(newStateExample.sha256 === Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")).to.be.true;
122122
expect(newStateExample.opCodeType === OpCodeType('76')).to.be.true;
123-
expect(newStateExample.sigHashType === SigHashType(SigHash.ALL)).to.be.true;
123+
expect(newStateExample.sigHashType === SigHashType(SignatureHashType.ALL)).to.be.true;
124124
expect(newStateExample.sig === Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541")).to.be.true;
125125
});
126126

@@ -133,7 +133,7 @@ describe('state_test', () => {
133133
Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4"),
134134
Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
135135
OpCodeType('76'),
136-
SigHashType(SigHash.ALL),
136+
SigHashType(SignatureHashType.ALL),
137137
Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541")
138138
);
139139

@@ -144,7 +144,7 @@ describe('state_test', () => {
144144
stateExample.ripemd160 = Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4");
145145
stateExample.sha256 = Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
146146
stateExample.opCodeType = OpCodeType('76');
147-
stateExample.sigHashType = SigHashType(SigHash.ALL);
147+
stateExample.sigHashType = SigHashType(SignatureHashType.ALL);
148148
stateExample.sig = Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541");
149149

150150

@@ -156,7 +156,7 @@ describe('state_test', () => {
156156
ripemd160: Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4"),
157157
sha256: Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
158158
opCodeType: OpCodeType('76'),
159-
sigHashType: SigHashType(SigHash.ALL),
159+
sigHashType: SigHashType(SignatureHashType.ALL),
160160
sig: Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541")
161161
});
162162

@@ -185,7 +185,7 @@ describe('state_test', () => {
185185
stateExample.ripemd160 = Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4");
186186
stateExample.sha256 = Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
187187
stateExample.opCodeType = OpCodeType('76');
188-
stateExample.sigHashType = SigHashType(SigHash.ALL);
188+
stateExample.sigHashType = SigHashType(SignatureHashType.ALL);
189189
stateExample.sig = Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541");
190190

191191

@@ -198,7 +198,7 @@ describe('state_test', () => {
198198
ripemd160: Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4"),
199199
sha256: Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
200200
opCodeType: OpCodeType('76'),
201-
sigHashType: SigHashType(SigHash.ALL),
201+
sigHashType: SigHashType(SignatureHashType.ALL),
202202
sig: Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541")
203203
})
204204

@@ -229,7 +229,7 @@ describe('state_test', () => {
229229
Ripemd160("40933785f6695815a7e1afb59aff20226bbb5bd4"),
230230
Sha256("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
231231
OpCodeType('76'),
232-
SigHashType(SigHash.ALL),
232+
SigHashType(SignatureHashType.ALL),
233233
Sig("304402207b6ce0aaae3a379721a364ab11414abd658a9940c10d48cd0bc6b273e81d058902206f6c0671066aef4c0de58ab8c349fde38ef3ea996b9f2e79241ebad96049299541")
234234
);
235235

0 commit comments

Comments
 (0)