@@ -8,6 +8,7 @@ let Secp256k1 = require("@dashincubator/secp256k1");
8
8
* @prop {KeySet } set
9
9
* @prop {KeySignAsn1 } signAsn1
10
10
* @prop {KeySignMagic } magicSign
11
+ * @prop {DoubleSHA256 } doubleSha256
11
12
* @prop {KeySignP1363 } signP1363
12
13
* @prop {ASN1ToP1363Signature } asn1ToP1363Signature
13
14
*/
@@ -26,6 +27,12 @@ let Secp256k1 = require("@dashincubator/secp256k1");
26
27
* @returns {Promise<Uint8Array> }
27
28
*/
28
29
30
+ /**
31
+ * @callback DoubleSHA256
32
+ * @param {Uint8Array } dataBytes
33
+ * @returns {Promise<Uint8Array> }
34
+ */
35
+
29
36
/**
30
37
* @callback KeySignMagic
31
38
* @param {Object } opts
@@ -85,6 +92,21 @@ KeyUtils.signAsn1 = async function (privKeyBytes, hashBytes) {
85
92
return sigBytes ;
86
93
} ;
87
94
95
+ KeyUtils . doubleSha256 = async function ( bytes ) {
96
+ let firstHash = await sha256 ( bytes ) ;
97
+ let secondHash = await sha256 ( firstHash ) ;
98
+ return secondHash ;
99
+ } ;
100
+
101
+ /**
102
+ * @param {Uint8Array } bytes
103
+ */
104
+ async function sha256 ( bytes ) {
105
+ let hashBuffer = await crypto . subtle . digest ( "SHA-256" , bytes ) ;
106
+ let hashBytes = new Uint8Array ( hashBuffer ) ;
107
+ return hashBytes ;
108
+ }
109
+
88
110
KeyUtils . magicSign = async function ( { privKeyBytes, doubleSha256Bytes } ) {
89
111
if ( doubleSha256Bytes ?. length !== 32 ) {
90
112
throw new Error ( `'doubleSha256Bytes' must be a 32-byte double sha256 hash` ) ;
0 commit comments