ecash-lib 4.1.0 → 4.3.1
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 +3 -0
- package/dist/payment/output.d.ts +19 -4
- package/dist/payment/output.d.ts.map +1 -1
- package/dist/tx.d.ts +9 -0
- package/dist/tx.d.ts.map +1 -1
- package/dist/tx.js +14 -0
- package/dist/tx.js.map +1 -1
- package/package.json +1 -1
- package/src/payment/output.ts +25 -8
- package/src/tx.ts +17 -1
package/README.md
CHANGED
|
@@ -96,3 +96,6 @@ console.log(toHex(rawTx));
|
|
|
96
96
|
- 3.2.0 - Add method for parsing pushes from an EMPP OP_RETURN [D18057](https://reviews.bitcoinabc.org/D18057)
|
|
97
97
|
- 4.0.0 - Add constants and types to support `ecash-wallet` [D17822](https://reviews.bitcoinabc.org/D17822)
|
|
98
98
|
- 4.1.0 - Add Tx deserialization methods [D18393](https://reviews.bitcoinabc.org/D18393)
|
|
99
|
+
- 4.2.0 - Add Tx.txid() method to compute the TxId of a transaction [D18394](https://reviews.bitcoinabc.org/D18394)
|
|
100
|
+
- 4.3.0 - Export a Tx.toHex() method [D18396](https://reviews.bitcoinabc.org/D18396)
|
|
101
|
+
- 4.3.1 - Modify union type of payment outputs to include ecash-wallet template OP_RETURN [D18403](https://reviews.bitcoinabc.org/D18403)
|
package/dist/payment/output.d.ts
CHANGED
|
@@ -7,16 +7,31 @@ export type PaymentOutput = PaymentNonTokenOutput | PaymentTokenOutput;
|
|
|
7
7
|
*
|
|
8
8
|
* Note than an OP_RETURN output is a NonTokenPaymentOutput
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export type PaymentNonTokenOutput = {
|
|
11
11
|
/** The amount of satoshis in this tx output */
|
|
12
12
|
sats?: bigint;
|
|
13
13
|
/** The outputScript of this tx output */
|
|
14
14
|
script?: Script;
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The eCash address of this tx output
|
|
17
|
+
* Alternative to script - if script is provided, address should not be set
|
|
18
|
+
*/
|
|
19
|
+
address?: never;
|
|
20
|
+
} | {
|
|
21
|
+
/** The amount of satoshis in this tx output */
|
|
22
|
+
sats?: bigint;
|
|
23
|
+
/** The outputScript of this tx output */
|
|
24
|
+
script?: never;
|
|
25
|
+
/**
|
|
26
|
+
* The eCash address of this tx output
|
|
27
|
+
* Alternative to script - if script is not provided, address must be set
|
|
28
|
+
*/
|
|
29
|
+
address: string;
|
|
30
|
+
};
|
|
16
31
|
/**
|
|
17
32
|
* All token transaction outputs specified in Action have this shape
|
|
18
33
|
*/
|
|
19
|
-
export
|
|
34
|
+
export type PaymentTokenOutput = PaymentNonTokenOutput & {
|
|
20
35
|
/** The tokenId of the token associated with this tx output */
|
|
21
36
|
tokenId: string;
|
|
22
37
|
/**
|
|
@@ -27,5 +42,5 @@ export interface PaymentTokenOutput extends PaymentNonTokenOutput {
|
|
|
27
42
|
atoms: bigint;
|
|
28
43
|
/** Is this tx output a mint baton */
|
|
29
44
|
isMintBaton: boolean;
|
|
30
|
-
}
|
|
45
|
+
};
|
|
31
46
|
//# sourceMappingURL=output.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/payment/output.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,sEAAsE;AACtE,MAAM,MAAM,aAAa,GAAG,qBAAqB,GAAG,kBAAkB,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/payment/output.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,sEAAsE;AACtE,MAAM,MAAM,aAAa,GAAG,qBAAqB,GAAG,kBAAkB,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAC3B;IACI,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC;CACnB,GACD;IACI,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,MAAM,CAAC,EAAE,KAAK,CAAC;IACf;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAER;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,GAAG;IACrD,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,WAAW,EAAE,OAAO,CAAC;CACxB,CAAC"}
|
package/dist/tx.d.ts
CHANGED
|
@@ -70,6 +70,8 @@ export declare class Tx {
|
|
|
70
70
|
});
|
|
71
71
|
/** Serialize the tx to a byte array */
|
|
72
72
|
ser(): Uint8Array;
|
|
73
|
+
/** Serialize the tx to a hex string */
|
|
74
|
+
toHex(): string;
|
|
73
75
|
/** Calculate the serialized size of the tx */
|
|
74
76
|
serSize(): number;
|
|
75
77
|
/** Write the tx to the given writer */
|
|
@@ -78,6 +80,13 @@ export declare class Tx {
|
|
|
78
80
|
static deser(data: Uint8Array): Tx;
|
|
79
81
|
/** Deserialize a Tx from a hex string */
|
|
80
82
|
static fromHex(hex: string): Tx;
|
|
83
|
+
/**
|
|
84
|
+
* Compute the transaction ID (TxId) as a hex string (little-endian).
|
|
85
|
+
* This follows the eCash convention: the TxId is the double SHA256 of the
|
|
86
|
+
* serialized transaction, returned as a hex string in little-endian (reversed) order.
|
|
87
|
+
* See the node src/primitives/txid.h for more details.
|
|
88
|
+
*/
|
|
89
|
+
txid(): string;
|
|
81
90
|
}
|
|
82
91
|
export declare function readTxOutput(bytes: Bytes): TxOutput;
|
|
83
92
|
/** Write an outpoint to a Writer */
|
package/dist/tx.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../src/tx.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../src/tx.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC;;;;;;;IAOI;AACJ,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC,iDAAiD;AACjD,MAAM,WAAW,QAAQ;IACrB;;;QAGI;IACJ,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAC1B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,yCAAyC;AACzC,MAAM,WAAW,OAAO;IACpB,uCAAuC;IACvC,OAAO,EAAE,QAAQ,CAAC;IAClB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACvB;AAED,qCAAqC;AACrC,MAAM,WAAW,QAAQ;IACrB,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,6DAA6D;AAC7D,MAAM,WAAW,QAAQ;IACrB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,YAAY,CAAC,EAAE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WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAiBnD;AAED,yCAAyC;AACzC,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAKvD"}
|
package/dist/tx.js
CHANGED
|
@@ -10,6 +10,7 @@ const varsize_js_1 = require("./io/varsize.js");
|
|
|
10
10
|
const writerbytes_js_1 = require("./io/writerbytes.js");
|
|
11
11
|
const writerlength_js_1 = require("./io/writerlength.js");
|
|
12
12
|
const script_js_1 = require("./script.js");
|
|
13
|
+
const hash_js_1 = require("./hash.js");
|
|
13
14
|
/**
|
|
14
15
|
* Default value for nSequence of inputs if left undefined; this opts out of
|
|
15
16
|
* BIP68 relative lock-time, and if all inputs have this value, nLockTime is
|
|
@@ -35,6 +36,10 @@ class Tx {
|
|
|
35
36
|
this.write(writerBytes);
|
|
36
37
|
return writerBytes.data;
|
|
37
38
|
}
|
|
39
|
+
/** Serialize the tx to a hex string */
|
|
40
|
+
toHex() {
|
|
41
|
+
return (0, hex_js_1.toHex)(this.ser());
|
|
42
|
+
}
|
|
38
43
|
/** Calculate the serialized size of the tx */
|
|
39
44
|
serSize() {
|
|
40
45
|
const writerLength = new writerlength_js_1.WriterLength();
|
|
@@ -94,6 +99,15 @@ class Tx {
|
|
|
94
99
|
static fromHex(hex) {
|
|
95
100
|
return Tx.deser((0, hex_js_1.fromHex)(hex));
|
|
96
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Compute the transaction ID (TxId) as a hex string (little-endian).
|
|
104
|
+
* This follows the eCash convention: the TxId is the double SHA256 of the
|
|
105
|
+
* serialized transaction, returned as a hex string in little-endian (reversed) order.
|
|
106
|
+
* See the node src/primitives/txid.h for more details.
|
|
107
|
+
*/
|
|
108
|
+
txid() {
|
|
109
|
+
return (0, hex_js_1.toHexRev)((0, hash_js_1.sha256d)(this.ser()));
|
|
110
|
+
}
|
|
97
111
|
}
|
|
98
112
|
exports.Tx = Tx;
|
|
99
113
|
function readTxOutput(bytes) {
|
package/dist/tx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx.js","sourceRoot":"","sources":["../src/tx.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;AAEtE,4CAAsC;AACtC,
|
|
1
|
+
{"version":3,"file":"tx.js","sourceRoot":"","sources":["../src/tx.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;AAEtE,4CAAsC;AACtC,wCAAmE;AACnE,gDAA4D;AAE5D,wDAAkD;AAClD,0DAAoD;AACpD,2CAAqC;AACrC,uCAAoC;AAEpC;;;;;;;IAOI;AACS,QAAA,gBAAgB,GAAG,UAAU,CAAC;AAE3C,4EAA4E;AAC/D,QAAA,kBAAkB,GAAG,CAAC,CAAC;AA8CpC,2CAA2C;AAC3C,MAAa,EAAE;IAUX,YAAmB,MAKlB;QACG,IAAI,CAAC,OAAO,GAAG,MAAM,EAAE,OAAO,IAAI,0BAAkB,CAAC;QACrD,IAAI,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,MAAM,EAAE,OAAO,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,uCAAuC;IAChC,GAAG;QACN,MAAM,WAAW,GAAG,IAAI,4BAAW,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACxB,OAAO,WAAW,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED,uCAAuC;IAChC,KAAK;QACR,OAAO,IAAA,cAAK,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,8CAA8C;IACvC,OAAO;QACV,MAAM,YAAY,GAAG,IAAI,8BAAY,EAAE,CAA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AAE,KAAK,CAAC,QAAQ,IAAI;YACxB,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI;YACzB,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,EAAE;YACjD,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,EAAE;SACpD;KACJ,CAAC;AACN,CAAC;AAjBD,kCAiBC;AAED,yCAAyC;AACzC,SAAgB,YAAY,CAAC,MAAgB;IACzC,OAAO;QACH,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;KAC/B,CAAC;AACN,CAAC;AALD,oCAKC"}
|
package/package.json
CHANGED
package/src/payment/output.ts
CHANGED
|
@@ -13,17 +13,34 @@ export type PaymentOutput = PaymentNonTokenOutput | PaymentTokenOutput;
|
|
|
13
13
|
*
|
|
14
14
|
* Note than an OP_RETURN output is a NonTokenPaymentOutput
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
export type PaymentNonTokenOutput =
|
|
17
|
+
| {
|
|
18
|
+
/** The amount of satoshis in this tx output */
|
|
19
|
+
sats?: bigint;
|
|
20
|
+
/** The outputScript of this tx output */
|
|
21
|
+
script?: Script;
|
|
22
|
+
/**
|
|
23
|
+
* The eCash address of this tx output
|
|
24
|
+
* Alternative to script - if script is provided, address should not be set
|
|
25
|
+
*/
|
|
26
|
+
address?: never;
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
/** The amount of satoshis in this tx output */
|
|
30
|
+
sats?: bigint;
|
|
31
|
+
/** The outputScript of this tx output */
|
|
32
|
+
script?: never;
|
|
33
|
+
/**
|
|
34
|
+
* The eCash address of this tx output
|
|
35
|
+
* Alternative to script - if script is not provided, address must be set
|
|
36
|
+
*/
|
|
37
|
+
address: string;
|
|
38
|
+
};
|
|
22
39
|
|
|
23
40
|
/**
|
|
24
41
|
* All token transaction outputs specified in Action have this shape
|
|
25
42
|
*/
|
|
26
|
-
export
|
|
43
|
+
export type PaymentTokenOutput = PaymentNonTokenOutput & {
|
|
27
44
|
/** The tokenId of the token associated with this tx output */
|
|
28
45
|
tokenId: string;
|
|
29
46
|
/**
|
|
@@ -34,4 +51,4 @@ export interface PaymentTokenOutput extends PaymentNonTokenOutput {
|
|
|
34
51
|
atoms: bigint;
|
|
35
52
|
/** Is this tx output a mint baton */
|
|
36
53
|
isMintBaton: boolean;
|
|
37
|
-
}
|
|
54
|
+
};
|
package/src/tx.ts
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
4
4
|
|
|
5
5
|
import { Bytes } from './io/bytes.js';
|
|
6
|
-
import { fromHexRev, fromHex } from './io/hex.js';
|
|
6
|
+
import { fromHexRev, toHexRev, fromHex, toHex } from './io/hex.js';
|
|
7
7
|
import { writeVarSize, readVarSize } from './io/varsize.js';
|
|
8
8
|
import { Writer } from './io/writer.js';
|
|
9
9
|
import { WriterBytes } from './io/writerbytes.js';
|
|
10
10
|
import { WriterLength } from './io/writerlength.js';
|
|
11
11
|
import { Script } from './script.js';
|
|
12
|
+
import { sha256d } from './hash.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Default value for nSequence of inputs if left undefined; this opts out of
|
|
@@ -97,6 +98,11 @@ export class Tx {
|
|
|
97
98
|
return writerBytes.data;
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
/** Serialize the tx to a hex string */
|
|
102
|
+
public toHex(): string {
|
|
103
|
+
return toHex(this.ser());
|
|
104
|
+
}
|
|
105
|
+
|
|
100
106
|
/** Calculate the serialized size of the tx */
|
|
101
107
|
public serSize(): number {
|
|
102
108
|
const writerLength = new WriterLength();
|
|
@@ -159,6 +165,16 @@ export class Tx {
|
|
|
159
165
|
public static fromHex(hex: string): Tx {
|
|
160
166
|
return Tx.deser(fromHex(hex));
|
|
161
167
|
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Compute the transaction ID (TxId) as a hex string (little-endian).
|
|
171
|
+
* This follows the eCash convention: the TxId is the double SHA256 of the
|
|
172
|
+
* serialized transaction, returned as a hex string in little-endian (reversed) order.
|
|
173
|
+
* See the node src/primitives/txid.h for more details.
|
|
174
|
+
*/
|
|
175
|
+
public txid(): string {
|
|
176
|
+
return toHexRev(sha256d(this.ser()));
|
|
177
|
+
}
|
|
162
178
|
}
|
|
163
179
|
|
|
164
180
|
export function readTxOutput(bytes: Bytes): TxOutput {
|