67
67
68
68
/**
69
69
* @callback TxCreate
70
- * @param {TxDeps } keyUtils
70
+ * @param {TxKeyUtils } keyUtils
71
71
* @returns {tx }
72
72
*/
73
73
@@ -273,6 +273,9 @@ var DashTx = ("object" === typeof module && exports) || {};
273
273
return pubKeyBytes ;
274
274
} ;
275
275
}
276
+ /** @type {TxDeps } */
277
+ //@ts -ignore
278
+ let keyDeps = keyUtils ;
276
279
277
280
let txInst = { } ;
278
281
@@ -314,7 +317,7 @@ var DashTx = ("object" === typeof module && exports) || {};
314
317
315
318
for ( let i = 0 ; i < txInfo . inputs . length ; i += 1 ) {
316
319
let txInput = txInfo . inputs [ i ] ;
317
- let privBytes = await keyUtils . getPrivateKey ( txInput , i , txInfo . inputs ) ;
320
+ let privBytes = await keyDeps . getPrivateKey ( txInput , i , txInfo . inputs ) ;
318
321
if ( privBytes ) {
319
322
txInput = await txInst . hashAndSignInput (
320
323
privBytes ,
@@ -359,7 +362,7 @@ var DashTx = ("object" === typeof module && exports) || {};
359
362
let txBytes = Tx . utils . hexToBytes ( txHex ) ;
360
363
let txHashBuf = await Tx . doubleSha256 ( txBytes ) ;
361
364
362
- let sigBuf = await keyUtils . sign ( privBytes , txHashBuf ) ;
365
+ let sigBuf = await keyDeps . sign ( privBytes , txHashBuf ) ;
363
366
let sigHex = "" ;
364
367
if ( "string" === typeof sigBuf ) {
365
368
console . warn ( `sign() should return a Uint8Array of an ASN.1 signature` ) ;
@@ -370,7 +373,10 @@ var DashTx = ("object" === typeof module && exports) || {};
370
373
371
374
let pubKeyHex = txInput . publicKey ;
372
375
if ( ! pubKeyHex ) {
373
- let pubKey = await keyUtils . getPublicKey ( txInput , i , txInfo . inputs ) ;
376
+ let pubKey = await keyDeps . getPublicKey ( txInput , i , txInfo . inputs ) ;
377
+ if ( ! pubKey ) {
378
+ throw new Error ( `no public key for input ${ i } ` ) ;
379
+ }
374
380
pubKeyHex = Tx . utils . bytesToHex ( pubKey ) ;
375
381
}
376
382
if ( "string" !== typeof pubKeyHex ) {
@@ -1930,12 +1936,13 @@ if ("object" === typeof module) {
1930
1936
*/
1931
1937
1932
1938
/**
1933
- * @typedef TxDeps
1939
+ * @typedef TxKeyUtils
1934
1940
* @prop {TxGetPrivateKey } getPrivateKey
1935
- * @prop {TxGetPublicKey } getPublicKey - efficiently get public key bytes
1936
- * @prop {TxToPublicKey } [ toPublicKey] - convert private bytes to pub bytes
1941
+ * @prop {TxGetPublicKey } [ getPublicKey] - efficiently get public key bytes
1942
+ * @prop {TxToPublicKey } toPublicKey - convert private bytes to pub bytes
1937
1943
* @prop {TxSign } sign
1938
1944
*/
1945
+ /** @typedef {Required<TxKeyUtils> } TxDeps */
1939
1946
1940
1947
/**
1941
1948
* @typedef TxFees
@@ -2151,17 +2158,17 @@ if ("object" === typeof module) {
2151
2158
/**
2152
2159
* @callback TxGetPrivateKey
2153
2160
* @param {TxInputForSig } txInput
2154
- * @param {Uint53 } i
2155
- * @param {Array<TxInputRaw|TxInputForSig> } txInputs
2156
- * @returns {Promise<TxPrivateKey> } - private key Uint8Array
2161
+ * @param {Uint53 } [i]
2162
+ * @param {Array<TxInputRaw|TxInputForSig> } [ txInputs]
2163
+ * @returns {Promise<TxPrivateKey? > } - private key Uint8Array
2157
2164
*/
2158
2165
2159
2166
/**
2160
2167
* @callback TxGetPublicKey
2161
2168
* @param {TxInputForSig } txInput
2162
- * @param {Uint53 } i
2163
- * @param {Array<TxInputRaw|TxInputForSig> } txInputs
2164
- * @returns {Promise<TxPublicKey> } - public key Uint8Array
2169
+ * @param {Uint53 } [i]
2170
+ * @param {Array<TxInputRaw|TxInputForSig> } [ txInputs]
2171
+ * @returns {Promise<TxPublicKey? > } - public key Uint8Array
2165
2172
*/
2166
2173
2167
2174
/**
0 commit comments