cashscript 0.7.1 → 0.7.2
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.
|
@@ -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) {
|
|
@@ -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) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cashscript",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
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.2",
|
|
46
46
|
"bip68": "^1.0.4",
|
|
47
47
|
"bitcoin-rpc-promise-retry": "^1.3.0",
|
|
48
48
|
"delay": "^5.0.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"ts-jest": "^26.5.1",
|
|
57
57
|
"typescript": "^4.1.5"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "0ec0bd1447e2f89e396c3b7e2c027a121e11f4e1"
|
|
60
60
|
}
|