@bitgo-beta/sdk-coin-irys 0.0.1-alpha.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/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2022 BitGo
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ export * from './lib';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lib"), exports);
18
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLHdDQUFzQiIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gJy4vbGliJztcbiJdfQ==
@@ -0,0 +1,108 @@
1
+ import { CommitmentType, CommitmentTransactionFields, CommitmentTransactionBuildResult, EncodedSignedCommitmentTransaction, EncodedCommitmentType } from './iface';
2
+ /**
3
+ * Builder for Irys commitment transactions (STAKE, PLEDGE).
4
+ *
5
+ * Commitment transactions are NOT standard EVM transactions. They use a custom
6
+ * 7-field RLP encoding with keccak256 prehash and raw ECDSA signing.
7
+ *
8
+ * Usage (STAKE):
9
+ * const builder = new IrysCommitmentTransactionBuilder(apiUrl, chainId);
10
+ * builder.setCommitmentType({ type: CommitmentTypeId.STAKE });
11
+ * builder.setFee(fee);
12
+ * builder.setValue(value);
13
+ * builder.setSigner(signerAddress);
14
+ * const result = await builder.build(); // fetches anchor, RLP encodes, returns prehash
15
+ *
16
+ * Usage (PLEDGE):
17
+ * builder.setCommitmentType({ type: CommitmentTypeId.PLEDGE, pledgeCount: 0n });
18
+ */
19
+ export declare class IrysCommitmentTransactionBuilder {
20
+ private _irysApiUrl;
21
+ private _chainId;
22
+ private _commitmentType?;
23
+ private _fee?;
24
+ private _value?;
25
+ private _signer?;
26
+ private _anchor?;
27
+ constructor(irysApiUrl: string, chainId: bigint);
28
+ /**
29
+ * Set the commitment type for this transaction.
30
+ * STAKE is a single-operation type.
31
+ * PLEDGE requires pledgeCount.
32
+ */
33
+ setCommitmentType(type: CommitmentType): this;
34
+ /** Set the transaction fee (from Irys price API) */
35
+ setFee(fee: bigint): this;
36
+ /** Set the transaction value (from Irys price API) */
37
+ setValue(value: bigint): this;
38
+ /** Set the signer address (20-byte Ethereum address as Uint8Array) */
39
+ setSigner(signer: Uint8Array): this;
40
+ /**
41
+ * Manually set the anchor (for testing). If not set, build() fetches it from the API.
42
+ */
43
+ setAnchor(anchor: Uint8Array): this;
44
+ /**
45
+ * Fetch the current anchor (block hash) from the Irys API.
46
+ * This is the nonce equivalent for commitment transactions.
47
+ * Called during build() if anchor hasn't been manually set.
48
+ */
49
+ fetchAnchor(): Promise<Uint8Array>;
50
+ /**
51
+ * Encode the commitment type for RLP signing.
52
+ *
53
+ * CRITICAL: STAKE (1) MUST be a flat number, NOT an array.
54
+ * PLEDGE MUST be a nested array. The Irys Rust decoder
55
+ * rejects non-canonical encoding.
56
+ *
57
+ * Reference: irys-js/src/common/commitmentTransaction.ts lines 180-199
58
+ */
59
+ static encodeCommitmentTypeForSigning(type: CommitmentType): number | bigint | Uint8Array | (number | bigint | Uint8Array)[];
60
+ /**
61
+ * Encode the commitment type for the JSON broadcast payload.
62
+ */
63
+ static encodeCommitmentTypeForBroadcast(type: CommitmentType): EncodedCommitmentType;
64
+ /**
65
+ * Validate that all required fields are set before building.
66
+ */
67
+ private validateFields;
68
+ /**
69
+ * Build the unsigned commitment transaction.
70
+ *
71
+ * 1. Validates all fields are set
72
+ * 2. Fetches anchor from Irys API (if not manually set) -- done LAST to minimize expiration
73
+ * 3. RLP encodes the 7 fields in exact order
74
+ * 4. Computes keccak256 prehash
75
+ * 5. Returns prehash (for HSM) and rlpEncoded (for HSM validation)
76
+ */
77
+ build(): Promise<CommitmentTransactionBuildResult>;
78
+ /**
79
+ * RLP encode the 7 commitment transaction fields.
80
+ *
81
+ * Field order is CRITICAL and must match the Irys protocol exactly:
82
+ * [version, anchor, signer, commitmentType, chainId, fee, value]
83
+ *
84
+ * Reference: irys-js/src/common/commitmentTransaction.ts lines 405-419
85
+ */
86
+ rlpEncode(fields: CommitmentTransactionFields): Uint8Array;
87
+ /**
88
+ * Compute the prehash: keccak256(rlpEncoded).
89
+ * Returns 32 bytes.
90
+ */
91
+ computePrehash(rlpEncoded: Uint8Array): Uint8Array;
92
+ /**
93
+ * Compute the transaction ID from a signature.
94
+ * txId = base58(keccak256(signature))
95
+ *
96
+ * @param signature - 65-byte raw ECDSA signature (r || s || v)
97
+ */
98
+ static computeTxId(signature: Uint8Array): string;
99
+ /**
100
+ * Create the JSON broadcast payload from a signed transaction.
101
+ *
102
+ * @param fields - The transaction fields used to build the transaction
103
+ * @param signature - 65-byte raw ECDSA signature
104
+ * @returns JSON payload ready for POST /v1/commitment-tx
105
+ */
106
+ static createBroadcastPayload(fields: CommitmentTransactionFields, signature: Uint8Array): EncodedSignedCommitmentTransaction;
107
+ }
108
+ //# sourceMappingURL=commitmentTransactionBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commitmentTransactionBuilder.d.ts","sourceRoot":"","sources":["../../../src/lib/commitmentTransactionBuilder.ts"],"names":[],"mappings":"A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B,GAAG,UAAU;IAc1D;;;OAGG;IACH,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU;IAKlD;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM;IAQjD;;;;;;OAMG;IACH,MAAM,CAAC,sBAAsB,CAC3B,MAAM,EAAE,2BAA2B,EACnC,SAAS,EAAE,UAAU,GACpB,kCAAkC;CActC"}
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.IrysCommitmentTransactionBuilder = void 0;
7
+ const rlp_1 = require("@ethereumjs/rlp");
8
+ const utils_1 = require("ethers/lib/utils");
9
+ const superagent_1 = __importDefault(require("superagent"));
10
+ const iface_1 = require("./iface");
11
+ const utils_2 = require("./utils");
12
+ /**
13
+ * Builder for Irys commitment transactions (STAKE, PLEDGE).
14
+ *
15
+ * Commitment transactions are NOT standard EVM transactions. They use a custom
16
+ * 7-field RLP encoding with keccak256 prehash and raw ECDSA signing.
17
+ *
18
+ * Usage (STAKE):
19
+ * const builder = new IrysCommitmentTransactionBuilder(apiUrl, chainId);
20
+ * builder.setCommitmentType({ type: CommitmentTypeId.STAKE });
21
+ * builder.setFee(fee);
22
+ * builder.setValue(value);
23
+ * builder.setSigner(signerAddress);
24
+ * const result = await builder.build(); // fetches anchor, RLP encodes, returns prehash
25
+ *
26
+ * Usage (PLEDGE):
27
+ * builder.setCommitmentType({ type: CommitmentTypeId.PLEDGE, pledgeCount: 0n });
28
+ */
29
+ class IrysCommitmentTransactionBuilder {
30
+ constructor(irysApiUrl, chainId) {
31
+ this._irysApiUrl = irysApiUrl;
32
+ this._chainId = chainId;
33
+ }
34
+ /**
35
+ * Set the commitment type for this transaction.
36
+ * STAKE is a single-operation type.
37
+ * PLEDGE requires pledgeCount.
38
+ */
39
+ setCommitmentType(type) {
40
+ this._commitmentType = type;
41
+ return this;
42
+ }
43
+ /** Set the transaction fee (from Irys price API) */
44
+ setFee(fee) {
45
+ this._fee = fee;
46
+ return this;
47
+ }
48
+ /** Set the transaction value (from Irys price API) */
49
+ setValue(value) {
50
+ this._value = value;
51
+ return this;
52
+ }
53
+ /** Set the signer address (20-byte Ethereum address as Uint8Array) */
54
+ setSigner(signer) {
55
+ if (signer.length !== 20) {
56
+ throw new Error(`Signer must be 20 bytes, got ${signer.length}`);
57
+ }
58
+ this._signer = signer;
59
+ return this;
60
+ }
61
+ /**
62
+ * Manually set the anchor (for testing). If not set, build() fetches it from the API.
63
+ */
64
+ setAnchor(anchor) {
65
+ if (anchor.length !== 32) {
66
+ throw new Error(`Anchor must be 32 bytes, got ${anchor.length}`);
67
+ }
68
+ this._anchor = anchor;
69
+ return this;
70
+ }
71
+ /**
72
+ * Fetch the current anchor (block hash) from the Irys API.
73
+ * This is the nonce equivalent for commitment transactions.
74
+ * Called during build() if anchor hasn't been manually set.
75
+ */
76
+ async fetchAnchor() {
77
+ const response = await superagent_1.default.get(`${this._irysApiUrl}/anchor`).accept('json');
78
+ if (!response.ok) {
79
+ throw new Error(`Failed to fetch anchor: ${response.status} ${response.text}`);
80
+ }
81
+ const anchorInfo = response.body;
82
+ return (0, utils_2.decodeBase58ToFixed)(anchorInfo.blockHash, 32);
83
+ }
84
+ /**
85
+ * Encode the commitment type for RLP signing.
86
+ *
87
+ * CRITICAL: STAKE (1) MUST be a flat number, NOT an array.
88
+ * PLEDGE MUST be a nested array. The Irys Rust decoder
89
+ * rejects non-canonical encoding.
90
+ *
91
+ * Reference: irys-js/src/common/commitmentTransaction.ts lines 180-199
92
+ */
93
+ static encodeCommitmentTypeForSigning(type) {
94
+ switch (type.type) {
95
+ case iface_1.CommitmentTypeId.STAKE:
96
+ return iface_1.CommitmentTypeId.STAKE; // flat number
97
+ case iface_1.CommitmentTypeId.PLEDGE:
98
+ return [iface_1.CommitmentTypeId.PLEDGE, type.pledgeCount]; // nested array
99
+ default:
100
+ throw new Error(`Unknown commitment type`);
101
+ }
102
+ }
103
+ /**
104
+ * Encode the commitment type for the JSON broadcast payload.
105
+ */
106
+ static encodeCommitmentTypeForBroadcast(type) {
107
+ switch (type.type) {
108
+ case iface_1.CommitmentTypeId.STAKE:
109
+ return { type: 'stake' };
110
+ case iface_1.CommitmentTypeId.PLEDGE:
111
+ return { type: 'pledge', pledgeCountBeforeExecuting: type.pledgeCount.toString() };
112
+ default:
113
+ throw new Error(`Unknown commitment type`);
114
+ }
115
+ }
116
+ /**
117
+ * Validate that all required fields are set before building.
118
+ */
119
+ validateFields() {
120
+ if (!this._commitmentType)
121
+ throw new Error('Commitment type is required');
122
+ if (this._fee === undefined)
123
+ throw new Error('Fee is required');
124
+ if (this._value === undefined)
125
+ throw new Error('Value is required');
126
+ if (!this._signer)
127
+ throw new Error('Signer is required');
128
+ }
129
+ /**
130
+ * Build the unsigned commitment transaction.
131
+ *
132
+ * 1. Validates all fields are set
133
+ * 2. Fetches anchor from Irys API (if not manually set) -- done LAST to minimize expiration
134
+ * 3. RLP encodes the 7 fields in exact order
135
+ * 4. Computes keccak256 prehash
136
+ * 5. Returns prehash (for HSM) and rlpEncoded (for HSM validation)
137
+ */
138
+ async build() {
139
+ this.validateFields();
140
+ // Fetch anchor LAST -- it expires in ~45 blocks (~9 min)
141
+ if (!this._anchor) {
142
+ this._anchor = await this.fetchAnchor();
143
+ }
144
+ const fields = {
145
+ version: iface_1.COMMITMENT_TX_VERSION,
146
+ anchor: this._anchor,
147
+ signer: this._signer,
148
+ commitmentType: this._commitmentType,
149
+ chainId: this._chainId,
150
+ fee: this._fee,
151
+ value: this._value,
152
+ };
153
+ const rlpEncoded = this.rlpEncode(fields);
154
+ const prehash = this.computePrehash(rlpEncoded);
155
+ return { prehash, rlpEncoded, fields };
156
+ }
157
+ /**
158
+ * RLP encode the 7 commitment transaction fields.
159
+ *
160
+ * Field order is CRITICAL and must match the Irys protocol exactly:
161
+ * [version, anchor, signer, commitmentType, chainId, fee, value]
162
+ *
163
+ * Reference: irys-js/src/common/commitmentTransaction.ts lines 405-419
164
+ */
165
+ rlpEncode(fields) {
166
+ const rlpFields = [
167
+ fields.version,
168
+ fields.anchor,
169
+ fields.signer,
170
+ IrysCommitmentTransactionBuilder.encodeCommitmentTypeForSigning(fields.commitmentType),
171
+ fields.chainId,
172
+ fields.fee,
173
+ fields.value,
174
+ ];
175
+ return rlp_1.RLP.encode(rlpFields);
176
+ }
177
+ /**
178
+ * Compute the prehash: keccak256(rlpEncoded).
179
+ * Returns 32 bytes.
180
+ */
181
+ computePrehash(rlpEncoded) {
182
+ const hash = (0, utils_1.keccak256)(rlpEncoded);
183
+ return (0, utils_1.arrayify)(hash);
184
+ }
185
+ /**
186
+ * Compute the transaction ID from a signature.
187
+ * txId = base58(keccak256(signature))
188
+ *
189
+ * @param signature - 65-byte raw ECDSA signature (r || s || v)
190
+ */
191
+ static computeTxId(signature) {
192
+ if (signature.length !== 65) {
193
+ throw new Error(`Signature must be 65 bytes, got ${signature.length}`);
194
+ }
195
+ const idBytes = (0, utils_1.arrayify)((0, utils_1.keccak256)(signature));
196
+ return (0, utils_2.encodeBase58)(idBytes);
197
+ }
198
+ /**
199
+ * Create the JSON broadcast payload from a signed transaction.
200
+ *
201
+ * @param fields - The transaction fields used to build the transaction
202
+ * @param signature - 65-byte raw ECDSA signature
203
+ * @returns JSON payload ready for POST /v1/commitment-tx
204
+ */
205
+ static createBroadcastPayload(fields, signature) {
206
+ const txId = IrysCommitmentTransactionBuilder.computeTxId(signature);
207
+ return {
208
+ version: fields.version,
209
+ anchor: (0, utils_2.encodeBase58)(fields.anchor),
210
+ signer: (0, utils_2.encodeBase58)(fields.signer),
211
+ commitmentType: IrysCommitmentTransactionBuilder.encodeCommitmentTypeForBroadcast(fields.commitmentType),
212
+ chainId: fields.chainId.toString(),
213
+ fee: fields.fee.toString(),
214
+ value: fields.value.toString(),
215
+ id: txId,
216
+ signature: (0, utils_2.encodeBase58)(signature),
217
+ };
218
+ }
219
+ }
220
+ exports.IrysCommitmentTransactionBuilder = IrysCommitmentTransactionBuilder;
221
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWl0bWVudFRyYW5zYWN0aW9uQnVpbGRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9saWIvY29tbWl0bWVudFRyYW5zYWN0aW9uQnVpbGRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSx5Q0FBc0M7QUFDdEMsNENBQXVEO0FBQ3ZELDREQUFpQztBQUNqQyxtQ0FTaUI7QUFDakIsbUNBQTREO0FBRTVEOzs7Ozs7Ozs7Ozs7Ozs7O0dBZ0JHO0FBQ0gsTUFBYSxnQ0FBZ0M7SUFTM0MsWUFBWSxVQUFrQixFQUFFLE9BQWU7UUFDN0MsSUFBSSxDQUFDLFdBQVcsR0FBRyxVQUFVLENBQUM7UUFDOUIsSUFBSSxDQUFDLFFBQVEsR0FBRyxPQUFPLENBQUM7SUFDMUIsQ0FBQztJQUVEOzs7O09BSUc7SUFDSCxpQkFBaUIsQ0FBQyxJQUFvQjtRQUNwQyxJQUFJLENBQUMsZUFBZSxHQUFHLElBQUksQ0FBQztRQUM1QixPQUFPLElBQUksQ0FBQztJQUNkLENBQUM7SUFFRCxvREFBb0Q7SUFDcEQsTUFBTSxDQUFDLEdBQVc7UUFDaEIsSUFBSSxDQUFDLElBQUksR0FBRyxHQUFHLENBQUM7UUFDaEIsT0FBTyxJQUFJLENBQUM7SUFDZCxDQUFDO0lBRUQsc0RBQXNEO0lBQ3RELFFBQVEsQ0FBQyxLQUFhO1FBQ3BCLElBQUksQ0FBQyxNQUFNLEdBQUcsS0FBSyxDQUFDO1FBQ3BCLE9BQU8sSUFBSSxDQUFDO0lBQ2QsQ0FBQztJQUVELHNFQUFzRTtJQUN0RSxT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xuICAgKiBAcmV0dXJucyBKU09OIHBheWxvYWQgcmVhZHkgZm9yIFBPU1QgL3YxL2NvbW1pdG1lbnQtdHhcbiAgICovXG4gIHN0YXRpYyBjcmVhdGVCcm9hZGNhc3RQYXlsb2FkKFxuICAgIGZpZWxkczogQ29tbWl0bWVudFRyYW5zYWN0aW9uRmllbGRzLFxuICAgIHNpZ25hdHVyZTogVWludDhBcnJheVxuICApOiBFbmNvZGVkU2lnbmVkQ29tbWl0bWVudFRyYW5zYWN0aW9uIHtcbiAgICBjb25zdCB0eElkID0gSXJ5c0NvbW1pdG1lbnRUcmFuc2FjdGlvbkJ1aWxkZXIuY29tcHV0ZVR4SWQoc2lnbmF0dXJlKTtcbiAgICByZXR1cm4ge1xuICAgICAgdmVyc2lvbjogZmllbGRzLnZlcnNpb24sXG4gICAgICBhbmNob3I6IGVuY29kZUJhc2U1OChmaWVsZHMuYW5jaG9yKSxcbiAgICAgIHNpZ25lcjogZW5jb2RlQmFzZTU4KGZpZWxkcy5zaWduZXIpLFxuICAgICAgY29tbWl0bWVudFR5cGU6IElyeXNDb21taXRtZW50VHJhbnNhY3Rpb25CdWlsZGVyLmVuY29kZUNvbW1pdG1lbnRUeXBlRm9yQnJvYWRjYXN0KGZpZWxkcy5jb21taXRtZW50VHlwZSksXG4gICAgICBjaGFpbklkOiBmaWVsZHMuY2hhaW5JZC50b1N0cmluZygpLFxuICAgICAgZmVlOiBmaWVsZHMuZmVlLnRvU3RyaW5nKCksXG4gICAgICB2YWx1ZTogZmllbGRzLnZhbHVlLnRvU3RyaW5nKCksXG4gICAgICBpZDogdHhJZCxcbiAgICAgIHNpZ25hdHVyZTogZW5jb2RlQmFzZTU4KHNpZ25hdHVyZSksXG4gICAgfTtcbiAgfVxufVxuIl19
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Commitment type IDs matching the Irys protocol.
3
+ * STAKE is a flat value in RLP encoding.
4
+ * PLEDGE is encoded as a nested array.
5
+ */
6
+ export declare enum CommitmentTypeId {
7
+ STAKE = 1,
8
+ PLEDGE = 2
9
+ }
10
+ export type StakeCommitmentType = {
11
+ type: CommitmentTypeId.STAKE;
12
+ };
13
+ export type PledgeCommitmentType = {
14
+ type: CommitmentTypeId.PLEDGE;
15
+ pledgeCount: bigint;
16
+ };
17
+ export type CommitmentType = StakeCommitmentType | PledgeCommitmentType;
18
+ /** Version 2 is the current commitment transaction version */
19
+ export declare const COMMITMENT_TX_VERSION = 2;
20
+ /** Irys chain IDs */
21
+ export declare const IRYS_MAINNET_CHAIN_ID = 3282n;
22
+ export declare const IRYS_TESTNET_CHAIN_ID = 1270n;
23
+ /**
24
+ * The 7 fields of an unsigned commitment transaction,
25
+ * in the exact order required for RLP encoding.
26
+ */
27
+ export interface CommitmentTransactionFields {
28
+ version: number;
29
+ anchor: Uint8Array;
30
+ signer: Uint8Array;
31
+ commitmentType: CommitmentType;
32
+ chainId: bigint;
33
+ fee: bigint;
34
+ value: bigint;
35
+ }
36
+ /**
37
+ * JSON payload for broadcasting a signed commitment transaction
38
+ * via POST /v1/commitment-tx
39
+ */
40
+ export interface EncodedSignedCommitmentTransaction {
41
+ version: number;
42
+ anchor: string;
43
+ signer: string;
44
+ commitmentType: EncodedCommitmentType;
45
+ chainId: string;
46
+ fee: string;
47
+ value: string;
48
+ id: string;
49
+ signature: string;
50
+ }
51
+ export type EncodedCommitmentType = {
52
+ type: 'stake';
53
+ } | {
54
+ type: 'pledge';
55
+ pledgeCountBeforeExecuting: string;
56
+ };
57
+ /**
58
+ * Anchor info returned by GET /v1/anchor
59
+ */
60
+ export interface AnchorInfo {
61
+ blockHash: string;
62
+ }
63
+ /**
64
+ * Result of building an unsigned commitment transaction.
65
+ * Contains the prehash (for HSM signing) and the RLP-encoded bytes (for HSM validation).
66
+ */
67
+ export interface CommitmentTransactionBuildResult {
68
+ /** keccak256(rlpEncoded) - 32 bytes, used as prehash for signing */
69
+ prehash: Uint8Array;
70
+ /** Full RLP-encoded transaction bytes - sent to HSM for validation before signing */
71
+ rlpEncoded: Uint8Array;
72
+ /** The transaction fields used to build this result */
73
+ fields: CommitmentTransactionFields;
74
+ }
75
+ /**
76
+ * Result after signing. Contains everything needed for broadcast.
77
+ */
78
+ export interface SignedCommitmentTransactionResult {
79
+ /** Transaction ID: base58(keccak256(signature)) */
80
+ txId: string;
81
+ /** 65-byte raw ECDSA signature (r || s || v) */
82
+ signature: Uint8Array;
83
+ /** JSON payload ready for POST /v1/commitment-tx */
84
+ broadcastPayload: EncodedSignedCommitmentTransaction;
85
+ }
86
+ //# sourceMappingURL=iface.d.ts.map