cashscript 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/SignatureTemplate.d.ts +3 -2
- package/dist/main/SignatureTemplate.js +5 -2
- package/dist/main/interfaces.d.ts +3 -0
- package/dist/main/interfaces.js +3 -0
- package/dist/main/network/ElectrumNetworkProvider.js +6 -2
- package/dist/main/utils.js +3 -1
- package/dist/module/SignatureTemplate.d.ts +3 -2
- package/dist/module/SignatureTemplate.js +6 -3
- package/dist/module/interfaces.d.ts +3 -0
- package/dist/module/interfaces.js +3 -0
- package/dist/module/network/ElectrumNetworkProvider.js +6 -2
- package/dist/module/utils.js +3 -1
- package/package.json +3 -4
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Secp256k1 } from '@bitauth/libauth';
|
|
2
|
-
import { HashType } from './interfaces.js';
|
|
2
|
+
import { HashType, SignatureAlgorithm } from './interfaces.js';
|
|
3
3
|
export default class SignatureTemplate {
|
|
4
4
|
private hashtype;
|
|
5
|
+
private signatureAlgorithm;
|
|
5
6
|
private privateKey;
|
|
6
|
-
constructor(signer: Keypair | Uint8Array | string, hashtype?: HashType);
|
|
7
|
+
constructor(signer: Keypair | Uint8Array | string, hashtype?: HashType, signatureAlgorithm?: SignatureAlgorithm);
|
|
7
8
|
generateSignature(payload: Uint8Array, secp256k1: Secp256k1, bchForkId?: boolean): Uint8Array;
|
|
8
9
|
getHashType(bchForkId?: boolean): number;
|
|
9
10
|
getPublicKey(secp256k1: Secp256k1): Uint8Array;
|
|
@@ -4,8 +4,9 @@ const libauth_1 = require("@bitauth/libauth");
|
|
|
4
4
|
const utils_1 = require("@cashscript/utils");
|
|
5
5
|
const interfaces_js_1 = require("./interfaces.js");
|
|
6
6
|
class SignatureTemplate {
|
|
7
|
-
constructor(signer, hashtype = interfaces_js_1.HashType.SIGHASH_ALL) {
|
|
7
|
+
constructor(signer, hashtype = interfaces_js_1.HashType.SIGHASH_ALL, signatureAlgorithm = interfaces_js_1.SignatureAlgorithm.SCHNORR) {
|
|
8
8
|
this.hashtype = hashtype;
|
|
9
|
+
this.signatureAlgorithm = signatureAlgorithm;
|
|
9
10
|
if (isKeypair(signer)) {
|
|
10
11
|
const wif = signer.toWIF();
|
|
11
12
|
this.privateKey = decodeWif(wif);
|
|
@@ -18,7 +19,9 @@ class SignatureTemplate {
|
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
generateSignature(payload, secp256k1, bchForkId) {
|
|
21
|
-
const signature =
|
|
22
|
+
const signature = this.signatureAlgorithm === interfaces_js_1.SignatureAlgorithm.SCHNORR
|
|
23
|
+
? secp256k1.signMessageHashSchnorr(this.privateKey, payload)
|
|
24
|
+
: secp256k1.signMessageHashDER(this.privateKey, payload);
|
|
22
25
|
return Uint8Array.from([...signature, this.getHashType(bchForkId)]);
|
|
23
26
|
}
|
|
24
27
|
getHashType(bchForkId = true) {
|
package/dist/main/interfaces.js
CHANGED
|
@@ -22,6 +22,9 @@ var HashType;
|
|
|
22
22
|
const literal = (l) => l;
|
|
23
23
|
exports.Network = {
|
|
24
24
|
MAINNET: literal('mainnet'),
|
|
25
|
+
TESTNET3: literal('testnet3'),
|
|
26
|
+
TESTNET4: literal('testnet4'),
|
|
27
|
+
CHIPNET: literal('chipnet'),
|
|
25
28
|
TESTNET: literal('testnet'),
|
|
26
29
|
STAGING: literal('staging'),
|
|
27
30
|
REGTEST: literal('regtest'),
|
|
@@ -35,7 +35,7 @@ class ElectrumNetworkProvider {
|
|
|
35
35
|
this.electrum.addServer('bch.loping.net', 50004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
|
|
36
36
|
this.electrum.addServer('electrum.imaginary.cash', 50004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
|
|
37
37
|
}
|
|
38
|
-
else if (network === interfaces_js_1.Network.TESTNET) {
|
|
38
|
+
else if (network === interfaces_js_1.Network.TESTNET || network === interfaces_js_1.Network.TESTNET3) {
|
|
39
39
|
// Initialise a 1-of-2 Electrum Cluster with 2 hardcoded servers
|
|
40
40
|
this.electrum = new electrum_cash_1.ElectrumCluster('CashScript Application', '1.4.1', 1, 2, electrum_cash_1.ClusterOrder.PRIORITY);
|
|
41
41
|
this.electrum.addServer('blackie.c3-soft.com', 60004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
|
|
@@ -43,10 +43,14 @@ class ElectrumNetworkProvider {
|
|
|
43
43
|
// this.electrum.addServer('bch.loping.net', 60004, ElectrumTransport.WSS.Scheme, false);
|
|
44
44
|
// this.electrum.addServer('testnet.imaginary.cash', 50004, ElectrumTransport.WSS.Scheme);
|
|
45
45
|
}
|
|
46
|
-
else if (network === interfaces_js_1.Network.STAGING) {
|
|
46
|
+
else if (network === interfaces_js_1.Network.STAGING || network === interfaces_js_1.Network.TESTNET4) {
|
|
47
47
|
this.electrum = new electrum_cash_1.ElectrumCluster('CashScript Application', '1.4.1', 1, 1, electrum_cash_1.ClusterOrder.PRIORITY);
|
|
48
48
|
this.electrum.addServer('testnet4.imaginary.cash', 50004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
|
|
49
49
|
}
|
|
50
|
+
else if (network === interfaces_js_1.Network.CHIPNET) {
|
|
51
|
+
this.electrum = new electrum_cash_1.ElectrumCluster('CashScript Application', '1.4.1', 1, 1, electrum_cash_1.ClusterOrder.PRIORITY);
|
|
52
|
+
this.electrum.addServer('chipnet.imaginary.cash/', 50004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
|
|
53
|
+
}
|
|
50
54
|
else {
|
|
51
55
|
throw new Error(`Tried to instantiate an ElectrumNetworkProvider for unsupported network ${network}`);
|
|
52
56
|
}
|
package/dist/main/utils.js
CHANGED
|
@@ -169,8 +169,10 @@ function getNetworkPrefix(network) {
|
|
|
169
169
|
case interfaces_js_1.Network.MAINNET:
|
|
170
170
|
return 'bitcoincash';
|
|
171
171
|
case interfaces_js_1.Network.STAGING:
|
|
172
|
-
|
|
172
|
+
case interfaces_js_1.Network.TESTNET4:
|
|
173
173
|
case interfaces_js_1.Network.TESTNET:
|
|
174
|
+
case interfaces_js_1.Network.TESTNET3:
|
|
175
|
+
case interfaces_js_1.Network.CHIPNET:
|
|
174
176
|
return 'bchtest';
|
|
175
177
|
case interfaces_js_1.Network.REGTEST:
|
|
176
178
|
return 'bchreg';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Secp256k1 } from '@bitauth/libauth';
|
|
2
|
-
import { HashType } from './interfaces.js';
|
|
2
|
+
import { HashType, SignatureAlgorithm } from './interfaces.js';
|
|
3
3
|
export default class SignatureTemplate {
|
|
4
4
|
private hashtype;
|
|
5
|
+
private signatureAlgorithm;
|
|
5
6
|
private privateKey;
|
|
6
|
-
constructor(signer: Keypair | Uint8Array | string, hashtype?: HashType);
|
|
7
|
+
constructor(signer: Keypair | Uint8Array | string, hashtype?: HashType, signatureAlgorithm?: SignatureAlgorithm);
|
|
7
8
|
generateSignature(payload: Uint8Array, secp256k1: Secp256k1, bchForkId?: boolean): Uint8Array;
|
|
8
9
|
getHashType(bchForkId?: boolean): number;
|
|
9
10
|
getPublicKey(secp256k1: Secp256k1): Uint8Array;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { decodePrivateKeyWif, SigningSerializationFlag } from '@bitauth/libauth';
|
|
2
2
|
import { sha256 } from '@cashscript/utils';
|
|
3
|
-
import { HashType } from './interfaces.js';
|
|
3
|
+
import { HashType, SignatureAlgorithm } from './interfaces.js';
|
|
4
4
|
export default class SignatureTemplate {
|
|
5
|
-
constructor(signer, hashtype = HashType.SIGHASH_ALL) {
|
|
5
|
+
constructor(signer, hashtype = HashType.SIGHASH_ALL, signatureAlgorithm = SignatureAlgorithm.SCHNORR) {
|
|
6
6
|
this.hashtype = hashtype;
|
|
7
|
+
this.signatureAlgorithm = signatureAlgorithm;
|
|
7
8
|
if (isKeypair(signer)) {
|
|
8
9
|
const wif = signer.toWIF();
|
|
9
10
|
this.privateKey = decodeWif(wif);
|
|
@@ -16,7 +17,9 @@ export default class SignatureTemplate {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
generateSignature(payload, secp256k1, bchForkId) {
|
|
19
|
-
const signature =
|
|
20
|
+
const signature = this.signatureAlgorithm === SignatureAlgorithm.SCHNORR
|
|
21
|
+
? secp256k1.signMessageHashSchnorr(this.privateKey, payload)
|
|
22
|
+
: secp256k1.signMessageHashDER(this.privateKey, payload);
|
|
20
23
|
return Uint8Array.from([...signature, this.getHashType(bchForkId)]);
|
|
21
24
|
}
|
|
22
25
|
getHashType(bchForkId = true) {
|
|
@@ -18,6 +18,9 @@ export var HashType;
|
|
|
18
18
|
const literal = (l) => l;
|
|
19
19
|
export const Network = {
|
|
20
20
|
MAINNET: literal('mainnet'),
|
|
21
|
+
TESTNET3: literal('testnet3'),
|
|
22
|
+
TESTNET4: literal('testnet4'),
|
|
23
|
+
CHIPNET: literal('chipnet'),
|
|
21
24
|
TESTNET: literal('testnet'),
|
|
22
25
|
STAGING: literal('staging'),
|
|
23
26
|
REGTEST: literal('regtest'),
|
|
@@ -33,7 +33,7 @@ export default class ElectrumNetworkProvider {
|
|
|
33
33
|
this.electrum.addServer('bch.loping.net', 50004, ElectrumTransport.WSS.Scheme, false);
|
|
34
34
|
this.electrum.addServer('electrum.imaginary.cash', 50004, ElectrumTransport.WSS.Scheme, false);
|
|
35
35
|
}
|
|
36
|
-
else if (network === Network.TESTNET) {
|
|
36
|
+
else if (network === Network.TESTNET || network === Network.TESTNET3) {
|
|
37
37
|
// Initialise a 1-of-2 Electrum Cluster with 2 hardcoded servers
|
|
38
38
|
this.electrum = new ElectrumCluster('CashScript Application', '1.4.1', 1, 2, ClusterOrder.PRIORITY);
|
|
39
39
|
this.electrum.addServer('blackie.c3-soft.com', 60004, ElectrumTransport.WSS.Scheme, false);
|
|
@@ -41,10 +41,14 @@ export default class ElectrumNetworkProvider {
|
|
|
41
41
|
// this.electrum.addServer('bch.loping.net', 60004, ElectrumTransport.WSS.Scheme, false);
|
|
42
42
|
// this.electrum.addServer('testnet.imaginary.cash', 50004, ElectrumTransport.WSS.Scheme);
|
|
43
43
|
}
|
|
44
|
-
else if (network === Network.STAGING) {
|
|
44
|
+
else if (network === Network.STAGING || network === Network.TESTNET4) {
|
|
45
45
|
this.electrum = new ElectrumCluster('CashScript Application', '1.4.1', 1, 1, ClusterOrder.PRIORITY);
|
|
46
46
|
this.electrum.addServer('testnet4.imaginary.cash', 50004, ElectrumTransport.WSS.Scheme, false);
|
|
47
47
|
}
|
|
48
|
+
else if (network === Network.CHIPNET) {
|
|
49
|
+
this.electrum = new ElectrumCluster('CashScript Application', '1.4.1', 1, 1, ClusterOrder.PRIORITY);
|
|
50
|
+
this.electrum.addServer('chipnet.imaginary.cash/', 50004, ElectrumTransport.WSS.Scheme, false);
|
|
51
|
+
}
|
|
48
52
|
else {
|
|
49
53
|
throw new Error(`Tried to instantiate an ElectrumNetworkProvider for unsupported network ${network}`);
|
|
50
54
|
}
|
package/dist/module/utils.js
CHANGED
|
@@ -154,8 +154,10 @@ export function getNetworkPrefix(network) {
|
|
|
154
154
|
case Network.MAINNET:
|
|
155
155
|
return 'bitcoincash';
|
|
156
156
|
case Network.STAGING:
|
|
157
|
-
|
|
157
|
+
case Network.TESTNET4:
|
|
158
158
|
case Network.TESTNET:
|
|
159
|
+
case Network.TESTNET3:
|
|
160
|
+
case Network.CHIPNET:
|
|
159
161
|
return 'bchtest';
|
|
160
162
|
case Network.REGTEST:
|
|
161
163
|
return 'bchreg';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cashscript",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Easily write and interact with Bitcoin Cash contracts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitcoin cash",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@bitauth/libauth": "^1.18.1",
|
|
45
|
-
"@cashscript/utils": "^0.7.
|
|
45
|
+
"@cashscript/utils": "^0.7.3",
|
|
46
46
|
"bip68": "^1.0.4",
|
|
47
47
|
"bitcoin-rpc-promise-retry": "^1.3.0",
|
|
48
48
|
"delay": "^5.0.0",
|
|
@@ -55,6 +55,5 @@
|
|
|
55
55
|
"jest": "^26.6.3",
|
|
56
56
|
"ts-jest": "^26.5.1",
|
|
57
57
|
"typescript": "^4.1.5"
|
|
58
|
-
}
|
|
59
|
-
"gitHead": "ba6756003d0d220c5d8c67c8459c65ced0152189"
|
|
58
|
+
}
|
|
60
59
|
}
|