ecash-lib 4.10.0 → 4.12.0
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/README.md +2 -0
- package/dist/consts.d.ts +11 -0
- package/dist/consts.d.ts.map +1 -1
- package/dist/consts.js +12 -1
- package/dist/consts.js.map +1 -1
- package/dist/ffi/ecash_lib_wasm_bg_browser.js +20489 -20489
- package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/psbt.d.ts +115 -0
- package/dist/psbt.d.ts.map +1 -0
- package/dist/psbt.js +743 -0
- package/dist/psbt.js.map +1 -0
- package/dist/script.d.ts +11 -1
- package/dist/script.d.ts.map +1 -1
- package/dist/script.js +24 -0
- package/dist/script.js.map +1 -1
- package/dist/signatories.d.ts +44 -0
- package/dist/signatories.d.ts.map +1 -0
- package/dist/signatories.js +206 -0
- package/dist/signatories.js.map +1 -0
- package/dist/tx.d.ts +60 -0
- package/dist/tx.d.ts.map +1 -1
- package/dist/tx.js +274 -0
- package/dist/tx.js.map +1 -1
- package/dist/txBuilder.d.ts +2 -30
- package/dist/txBuilder.d.ts.map +1 -1
- package/dist/txBuilder.js +1 -45
- package/dist/txBuilder.js.map +1 -1
- package/package.json +1 -1
- package/src/consts.ts +13 -0
- package/src/ffi/ecash_lib_wasm_bg_browser.js +20489 -20489
- package/src/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
- package/src/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
- package/src/index.ts +2 -0
- package/src/psbt.ts +908 -0
- package/src/script.ts +25 -1
- package/src/signatories.ts +296 -0
- package/src/tx.ts +330 -0
- package/src/txBuilder.ts +2 -74
package/src/txBuilder.ts
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
4
4
|
|
|
5
5
|
import { Ecc, EccDummy } from './ecc.js';
|
|
6
|
-
import {
|
|
7
|
-
import { WriterBytes } from './io/writerbytes.js';
|
|
8
|
-
import { pushBytesOp } from './op.js';
|
|
6
|
+
import type { Signatory } from './signatories.js';
|
|
9
7
|
import { Script } from './script.js';
|
|
10
|
-
import { SigHashType, SigHashTypeVariant } from './sigHashType.js';
|
|
11
8
|
import {
|
|
12
9
|
DEFAULT_TX_VERSION,
|
|
13
10
|
Tx,
|
|
@@ -18,27 +15,10 @@ import {
|
|
|
18
15
|
} from './tx.js';
|
|
19
16
|
import { UnsignedTx, UnsignedTxInput } from './unsignedTx.js';
|
|
20
17
|
|
|
21
|
-
/**
|
|
22
|
-
* Function that contains all the required data to sign a given `input` and
|
|
23
|
-
* return the scriptSig.
|
|
24
|
-
*
|
|
25
|
-
* Use it by attaching a `Signatory` to a TxBuilderInput, e.g. like this for a
|
|
26
|
-
* P2PKH input:
|
|
27
|
-
* ```ts
|
|
28
|
-
* new TxBuilder({
|
|
29
|
-
* inputs: [{
|
|
30
|
-
* input: { prevOut: ... },
|
|
31
|
-
* signatory: P2PKHSignatory(sk, pk, ALL_BIP143),
|
|
32
|
-
* }],
|
|
33
|
-
* ...
|
|
34
|
-
* })
|
|
35
|
-
* ```
|
|
36
|
-
**/
|
|
37
|
-
export type Signatory = (ecc: Ecc, input: UnsignedTxInput) => Script;
|
|
38
|
-
|
|
39
18
|
/** Builder input that bundles all the data required to sign a TxInput */
|
|
40
19
|
export interface TxBuilderInput {
|
|
41
20
|
input: TxInput;
|
|
21
|
+
/** Signing callback; see `Signatory` in `signatories.ts`. */
|
|
42
22
|
signatory?: Signatory;
|
|
43
23
|
}
|
|
44
24
|
|
|
@@ -226,55 +206,3 @@ export class TxBuilder {
|
|
|
226
206
|
export function calcTxFee(txSize: number, feePerKb: bigint): bigint {
|
|
227
207
|
return (BigInt(txSize) * BigInt(feePerKb) + 999n) / 1000n;
|
|
228
208
|
}
|
|
229
|
-
|
|
230
|
-
/** Append the sighash flags to the signature */
|
|
231
|
-
export function flagSignature(
|
|
232
|
-
sig: Uint8Array,
|
|
233
|
-
sigHashFlags: SigHashType,
|
|
234
|
-
): Uint8Array {
|
|
235
|
-
const writer = new WriterBytes(sig.length + 1);
|
|
236
|
-
writer.putBytes(sig);
|
|
237
|
-
writer.putU8(sigHashFlags.toInt() & 0xff);
|
|
238
|
-
return writer.data;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Sign the sighash using Schnorr for BIP143 signatures and ECDSA for Legacy
|
|
243
|
-
* signatures, and then flags the signature correctly
|
|
244
|
-
**/
|
|
245
|
-
export function signWithSigHash(
|
|
246
|
-
ecc: Ecc,
|
|
247
|
-
sk: Uint8Array,
|
|
248
|
-
sigHash: Uint8Array,
|
|
249
|
-
sigHashType: SigHashType,
|
|
250
|
-
): Uint8Array {
|
|
251
|
-
const sig =
|
|
252
|
-
sigHashType.variant == SigHashTypeVariant.LEGACY
|
|
253
|
-
? ecc.ecdsaSign(sk, sigHash)
|
|
254
|
-
: ecc.schnorrSign(sk, sigHash);
|
|
255
|
-
return flagSignature(sig, sigHashType);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** Signatory for a P2PKH input. Always uses Schnorr signatures */
|
|
259
|
-
export const P2PKHSignatory = (
|
|
260
|
-
sk: Uint8Array,
|
|
261
|
-
pk: Uint8Array,
|
|
262
|
-
sigHashType: SigHashType,
|
|
263
|
-
) => {
|
|
264
|
-
return (ecc: Ecc, input: UnsignedTxInput): Script => {
|
|
265
|
-
const preimage = input.sigHashPreimage(sigHashType);
|
|
266
|
-
const sighash = sha256d(preimage.bytes);
|
|
267
|
-
const sigFlagged = signWithSigHash(ecc, sk, sighash, sigHashType);
|
|
268
|
-
return Script.p2pkhSpend(pk, sigFlagged);
|
|
269
|
-
};
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
/** Signatory for a P2PK input. Always uses Schnorr signatures */
|
|
273
|
-
export const P2PKSignatory = (sk: Uint8Array, sigHashType: SigHashType) => {
|
|
274
|
-
return (ecc: Ecc, input: UnsignedTxInput): Script => {
|
|
275
|
-
const preimage = input.sigHashPreimage(sigHashType);
|
|
276
|
-
const sighash = sha256d(preimage.bytes);
|
|
277
|
-
const sigFlagged = signWithSigHash(ecc, sk, sighash, sigHashType);
|
|
278
|
-
return Script.fromOps([pushBytesOp(sigFlagged)]);
|
|
279
|
-
};
|
|
280
|
-
};
|