@ckbfs/api 1.5.0 → 2.0.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.
Files changed (45) hide show
  1. package/README.md +31 -6
  2. package/RFC.v3.md +210 -0
  3. package/dist/index.d.ts +72 -7
  4. package/dist/index.js +440 -75
  5. package/dist/utils/checksum.d.ts +16 -0
  6. package/dist/utils/checksum.js +74 -8
  7. package/dist/utils/constants.d.ts +2 -1
  8. package/dist/utils/constants.js +12 -2
  9. package/dist/utils/file.d.ts +44 -0
  10. package/dist/utils/file.js +303 -30
  11. package/dist/utils/molecule.d.ts +13 -1
  12. package/dist/utils/molecule.js +32 -5
  13. package/dist/utils/transaction-backup.d.ts +117 -0
  14. package/dist/utils/transaction-backup.js +624 -0
  15. package/dist/utils/transaction.d.ts +7 -105
  16. package/dist/utils/transaction.js +45 -565
  17. package/dist/utils/transactions/index.d.ts +8 -0
  18. package/dist/utils/transactions/index.js +31 -0
  19. package/dist/utils/transactions/shared.d.ts +57 -0
  20. package/dist/utils/transactions/shared.js +17 -0
  21. package/dist/utils/transactions/v1v2.d.ts +80 -0
  22. package/dist/utils/transactions/v1v2.js +592 -0
  23. package/dist/utils/transactions/v3.d.ts +124 -0
  24. package/dist/utils/transactions/v3.js +369 -0
  25. package/dist/utils/witness.d.ts +45 -0
  26. package/dist/utils/witness.js +145 -3
  27. package/examples/append-v3.ts +310 -0
  28. package/examples/chunked-publish.ts +307 -0
  29. package/examples/publish-v3.ts +152 -0
  30. package/examples/publish.ts +4 -4
  31. package/examples/retrieve-v3.ts +222 -0
  32. package/package.json +6 -2
  33. package/small-example.txt +1 -0
  34. package/src/index.ts +568 -87
  35. package/src/utils/checksum.ts +90 -9
  36. package/src/utils/constants.ts +19 -2
  37. package/src/utils/file.ts +386 -35
  38. package/src/utils/molecule.ts +43 -6
  39. package/src/utils/transaction-backup.ts +849 -0
  40. package/src/utils/transaction.ts +39 -848
  41. package/src/utils/transactions/index.ts +16 -0
  42. package/src/utils/transactions/shared.ts +64 -0
  43. package/src/utils/transactions/v1v2.ts +791 -0
  44. package/src/utils/transactions/v3.ts +564 -0
  45. package/src/utils/witness.ts +193 -0
@@ -1,567 +1,47 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureHexPrefix = ensureHexPrefix;
4
- exports.createCKBFSCell = createCKBFSCell;
5
- exports.preparePublishTransaction = preparePublishTransaction;
6
- exports.createPublishTransaction = createPublishTransaction;
7
- exports.createAppendTransaction = createAppendTransaction;
8
- exports.createAppendTransactionDry = createAppendTransactionDry;
9
- exports.publishCKBFS = publishCKBFS;
10
- exports.appendCKBFS = appendCKBFS;
11
- const core_1 = require("@ckb-ccc/core");
12
- const checksum_1 = require("./checksum");
13
- const molecule_1 = require("./molecule");
14
- const witness_1 = require("./witness");
15
- const constants_1 = require("./constants");
16
- /**
17
- * Ensures a string is prefixed with '0x'
18
- * @param value The string to ensure is hex prefixed
19
- * @returns A hex prefixed string
20
- */
21
- function ensureHexPrefix(value) {
22
- if (value.startsWith("0x")) {
23
- return value;
24
- }
25
- return `0x${value}`;
26
- }
27
- /**
28
- * Creates a CKBFS cell
29
- * @param options Options for creating the CKBFS cell
30
- * @returns The created cell output
31
- */
32
- function createCKBFSCell(options) {
33
- const { contentType, filename, capacity, lock, network = constants_1.DEFAULT_NETWORK, version = constants_1.DEFAULT_VERSION, useTypeID = false, } = options;
34
- // Get CKBFS script config
35
- const config = (0, constants_1.getCKBFSScriptConfig)(network, version, useTypeID);
36
- // Create pre CKBFS type script
37
- const preCkbfsTypeScript = new core_1.Script(ensureHexPrefix(config.codeHash), config.hashType, "0x0000000000000000000000000000000000000000000000000000000000000000");
38
- // Return the cell output
39
- return {
40
- lock,
41
- type: preCkbfsTypeScript,
42
- capacity: capacity || 200n * 100000000n, // Default 200 CKB
43
- };
44
- }
45
2
  /**
46
- * Prepares a transaction for publishing a file to CKBFS without fee and change handling
47
- * You will need to manually set the typeID if you did not provide inputs, or just check is return value emptyTypeID is true
48
- * @param options Options for publishing the file
49
- * @returns Promise resolving to the prepared transaction and the output index of CKBFS Cell
50
- */
51
- async function preparePublishTransaction(options) {
52
- const { from, contentChunks, contentType, filename, lock, capacity, network = constants_1.DEFAULT_NETWORK, version = constants_1.DEFAULT_VERSION, useTypeID = false, } = options;
53
- // Calculate checksum for the combined content
54
- const combinedContent = Buffer.concat(contentChunks);
55
- const checksum = await (0, checksum_1.calculateChecksum)(combinedContent);
56
- // Create CKBFS witnesses - each chunk already includes the CKBFS header
57
- // Pass 0 as version byte - this is the protocol version byte in the witness header
58
- // not to be confused with the Protocol Version (V1 vs V2)
59
- const ckbfsWitnesses = (0, witness_1.createChunkedCKBFSWitnesses)(contentChunks);
60
- // Calculate the actual witness indices where our content is placed
61
- const contentStartIndex = from?.witnesses.length || 1;
62
- const witnessIndices = Array.from({ length: contentChunks.length }, (_, i) => contentStartIndex + i);
63
- // Create CKBFS cell output data based on version
64
- let outputData;
65
- if (version === constants_1.ProtocolVersion.V1) {
66
- // V1 format: Single index field (a single number, not an array)
67
- // For V1, use the first index where content is placed
68
- outputData = molecule_1.CKBFSData.pack({
69
- index: contentStartIndex,
70
- checksum,
71
- contentType: contentType,
72
- filename: filename,
73
- backLinks: [],
74
- }, version);
75
- }
76
- else {
77
- // V2 format: Multiple indexes (array of numbers)
78
- // For V2, use all the indices where content is placed
79
- outputData = molecule_1.CKBFSData.pack({
80
- indexes: witnessIndices,
81
- checksum,
82
- contentType,
83
- filename,
84
- backLinks: [],
85
- }, version);
86
- }
87
- // Get CKBFS script config
88
- const config = (0, constants_1.getCKBFSScriptConfig)(network, version, useTypeID);
89
- const preCkbfsTypeScript = new core_1.Script(ensureHexPrefix(config.codeHash), config.hashType, "0x0000000000000000000000000000000000000000000000000000000000000000");
90
- const ckbfsCellSize = BigInt(outputData.length +
91
- preCkbfsTypeScript.occupiedSize +
92
- lock.occupiedSize +
93
- 8) * 100000000n;
94
- // Create pre transaction without cell deps initially
95
- let preTx;
96
- if (from) {
97
- // If from is not empty, inject/merge the fields
98
- preTx = core_1.Transaction.from({
99
- ...from,
100
- outputs: from.outputs.length === 0
101
- ? [
102
- createCKBFSCell({
103
- contentType,
104
- filename,
105
- lock,
106
- network,
107
- version,
108
- useTypeID,
109
- capacity: ckbfsCellSize || capacity,
110
- }),
111
- ]
112
- : [
113
- ...from.outputs,
114
- createCKBFSCell({
115
- contentType,
116
- filename,
117
- lock,
118
- network,
119
- version,
120
- useTypeID,
121
- capacity: ckbfsCellSize || capacity,
122
- }),
123
- ],
124
- witnesses: from.witnesses.length === 0
125
- ? [
126
- [], // Empty secp witness for signing if not provided
127
- ...ckbfsWitnesses.map((w) => `0x${Buffer.from(w).toString("hex")}`),
128
- ]
129
- : [
130
- ...from.witnesses,
131
- ...ckbfsWitnesses.map((w) => `0x${Buffer.from(w).toString("hex")}`),
132
- ],
133
- outputsData: from.outputsData.length === 0
134
- ? [outputData]
135
- : [
136
- ...from.outputsData,
137
- outputData,
138
- ],
139
- });
140
- }
141
- else {
142
- preTx = core_1.Transaction.from({
143
- outputs: [
144
- createCKBFSCell({
145
- contentType,
146
- filename,
147
- lock,
148
- network,
149
- version,
150
- useTypeID,
151
- capacity: ckbfsCellSize || capacity,
152
- }),
153
- ],
154
- witnesses: [
155
- [], // Empty secp witness for signing
156
- ...ckbfsWitnesses.map((w) => `0x${Buffer.from(w).toString("hex")}`),
157
- ],
158
- outputsData: [outputData],
159
- });
160
- }
161
- // Add the CKBFS dep group cell dependency
162
- preTx.addCellDeps({
163
- outPoint: {
164
- txHash: ensureHexPrefix(config.depTxHash),
165
- index: config.depIndex || 0,
166
- },
167
- depType: "depGroup",
168
- });
169
- // Create type ID args
170
- const outputIndex = from ? from.outputs.length : 0;
171
- const args = preTx.inputs.length > 0 ? core_1.ccc.hashTypeId(preTx.inputs[0], outputIndex) : "0x0000000000000000000000000000000000000000000000000000000000000000";
172
- // Create CKBFS type script with type ID
173
- const ckbfsTypeScript = new core_1.Script(ensureHexPrefix(config.codeHash), config.hashType, args);
174
- // Create final transaction with same cell deps as preTx
175
- const tx = core_1.Transaction.from({
176
- cellDeps: preTx.cellDeps,
177
- witnesses: preTx.witnesses,
178
- outputsData: preTx.outputsData,
179
- inputs: preTx.inputs,
180
- outputs: outputIndex === 0
181
- ? [
182
- {
183
- lock,
184
- type: ckbfsTypeScript,
185
- capacity: preTx.outputs[outputIndex].capacity,
186
- },
187
- ]
188
- : [
189
- ...preTx.outputs.slice(0, outputIndex), // Include rest of outputs (e.g., change)
190
- {
191
- lock,
192
- type: ckbfsTypeScript,
193
- capacity: preTx.outputs[outputIndex].capacity,
194
- },
195
- ],
196
- });
197
- return { tx, outputIndex, emptyTypeID: args === "0x0000000000000000000000000000000000000000000000000000000000000000" };
198
- }
199
- /**
200
- * Creates a transaction for publishing a file to CKBFS
201
- * @param signer The signer to use for the transaction
202
- * @param options Options for publishing the file
203
- * @returns Promise resolving to the created transaction
204
- */
205
- async function createPublishTransaction(signer, options) {
206
- const { feeRate, lock, } = options;
207
- // Use preparePublishTransaction to create the base transaction
208
- const { tx: preTx, outputIndex, emptyTypeID } = await preparePublishTransaction(options);
209
- // Complete inputs by capacity
210
- await preTx.completeInputsByCapacity(signer);
211
- // Complete fee change to lock
212
- await preTx.completeFeeChangeToLock(signer, lock, feeRate || 2000);
213
- // If emptyTypeID is true, we need to create the proper type ID args
214
- if (emptyTypeID) {
215
- // Get CKBFS script config
216
- const config = (0, constants_1.getCKBFSScriptConfig)(options.network || constants_1.DEFAULT_NETWORK, options.version || constants_1.DEFAULT_VERSION, options.useTypeID || false);
217
- // Create type ID args
218
- const args = core_1.ccc.hashTypeId(preTx.inputs[0], outputIndex);
219
- // Create CKBFS type script with type ID
220
- const ckbfsTypeScript = new core_1.Script(ensureHexPrefix(config.codeHash), config.hashType, args);
221
- // Create final transaction with updated type script
222
- const tx = core_1.Transaction.from({
223
- cellDeps: preTx.cellDeps,
224
- witnesses: preTx.witnesses,
225
- outputsData: preTx.outputsData,
226
- inputs: preTx.inputs,
227
- outputs: outputIndex === 0
228
- ? [{
229
- lock,
230
- type: ckbfsTypeScript,
231
- capacity: preTx.outputs[outputIndex].capacity,
232
- }]
233
- : [
234
- ...preTx.outputs.slice(0, outputIndex), // Include outputs before CKBFS cell
235
- {
236
- lock,
237
- type: ckbfsTypeScript,
238
- capacity: preTx.outputs[outputIndex].capacity,
239
- }
240
- ],
241
- });
242
- return tx;
243
- }
244
- else {
245
- // If typeID was already set properly, just reset the first witness for signing
246
- const tx = core_1.Transaction.from({
247
- cellDeps: preTx.cellDeps,
248
- witnesses: preTx.witnesses,
249
- outputsData: preTx.outputsData,
250
- inputs: preTx.inputs,
251
- outputs: preTx.outputs,
252
- });
253
- return tx;
254
- }
255
- }
256
- /**
257
- * Creates a transaction for appending content to a CKBFS file
258
- * @param signer The signer to use for the transaction
259
- * @param options Options for appending content
260
- * @returns Promise resolving to the created transaction
261
- */
262
- async function createAppendTransaction(signer, options) {
263
- const { ckbfsCell, contentChunks, feeRate, network = constants_1.DEFAULT_NETWORK, version = constants_1.DEFAULT_VERSION, } = options;
264
- const { outPoint, data, type, lock, capacity } = ckbfsCell;
265
- // Get CKBFS script config early to use version info
266
- const config = (0, constants_1.getCKBFSScriptConfig)(network, version);
267
- // Create CKBFS witnesses - each chunk already includes the CKBFS header
268
- // Pass 0 as version byte - this is the protocol version byte in the witness header
269
- // not to be confused with the Protocol Version (V1 vs V2)
270
- const ckbfsWitnesses = (0, witness_1.createChunkedCKBFSWitnesses)(contentChunks);
271
- // Combine the new content chunks for checksum calculation
272
- const combinedContent = Buffer.concat(contentChunks);
273
- // Update the existing checksum with the new content - this matches Adler32's
274
- // cumulative nature as required by Rule 11 in the RFC
275
- const contentChecksum = await (0, checksum_1.updateChecksum)(data.checksum, combinedContent);
276
- console.log(`Updated checksum from ${data.checksum} to ${contentChecksum} for appended content`);
277
- // Get the recommended address to ensure lock script cell deps are included
278
- const address = await signer.getRecommendedAddressObj();
279
- // Calculate the actual witness indices where our content is placed
280
- // CKBFS data starts at index 1 if signer's lock script is the same as ckbfs's lock script
281
- // else CKBFS data starts at index 0
282
- const contentStartIndex = address.script.hash() === lock.hash() ? 1 : 0;
283
- const witnessIndices = Array.from({ length: contentChunks.length }, (_, i) => contentStartIndex + i);
284
- // Create backlink for the current state based on version
285
- let newBackLink;
286
- if (version === constants_1.ProtocolVersion.V1) {
287
- // V1 format: Use index field (single number)
288
- newBackLink = {
289
- // In V1, field order is index, checksum, txHash
290
- // and index is a single number value, not an array
291
- index: data.index ||
292
- (data.indexes && data.indexes.length > 0 ? data.indexes[0] : 0),
293
- checksum: data.checksum,
294
- txHash: outPoint.txHash,
295
- };
296
- }
297
- else {
298
- // V2 format: Use indexes field (array of numbers)
299
- newBackLink = {
300
- // In V2, field order is indexes, checksum, txHash
301
- // and indexes is an array of numbers
302
- indexes: data.indexes || (data.index ? [data.index] : []),
303
- checksum: data.checksum,
304
- txHash: outPoint.txHash,
305
- };
306
- }
307
- // Update backlinks - add the new one to the existing backlinks array
308
- const backLinks = [...(data.backLinks || []), newBackLink];
309
- // Define output data based on version
310
- let outputData;
311
- if (version === constants_1.ProtocolVersion.V1) {
312
- // In V1, index is a single number, not an array
313
- // The first witness index is used (V1 can only reference one witness)
314
- outputData = molecule_1.CKBFSData.pack({
315
- index: witnessIndices[0], // Use only the first index as a number
316
- checksum: contentChecksum,
317
- contentType: data.contentType,
318
- filename: data.filename,
319
- backLinks,
320
- }, constants_1.ProtocolVersion.V1); // Explicitly use V1 for packing
321
- }
322
- else {
323
- // In V2, indexes is an array of witness indices
324
- outputData = molecule_1.CKBFSData.pack({
325
- indexes: witnessIndices,
326
- checksum: contentChecksum,
327
- contentType: data.contentType,
328
- filename: data.filename,
329
- backLinks,
330
- }, constants_1.ProtocolVersion.V2); // Explicitly use V2 for packing
331
- }
332
- // Pack the original data to get its size - use the appropriate version
333
- const originalData = molecule_1.CKBFSData.pack(data, version);
334
- const originalDataSize = originalData.length;
335
- // Get sizes and calculate capacity requirements
336
- const newDataSize = outputData.length;
337
- // Calculate the required capacity for the output cell
338
- // This accounts for:
339
- // 1. The output data size
340
- // 2. The type script's occupied size
341
- // 3. The lock script's occupied size
342
- // 4. A constant of 8 bytes (for header overhead)
343
- const ckbfsCellSize = BigInt(outputData.length + type.occupiedSize + lock.occupiedSize + 8) *
344
- 100000000n;
345
- console.log(`Original capacity: ${capacity}, Calculated size: ${ckbfsCellSize}, Data size: ${outputData.length}`);
346
- // Use the maximum value between calculated size and original capacity
347
- // to ensure we have enough capacity but don't decrease capacity unnecessarily
348
- const outputCapacity = ckbfsCellSize > capacity ? ckbfsCellSize : capacity;
349
- // Create initial transaction with the CKBFS cell input
350
- const tx = core_1.Transaction.from({
351
- inputs: [
352
- {
353
- previousOutput: {
354
- txHash: outPoint.txHash,
355
- index: outPoint.index,
356
- },
357
- since: "0x0",
358
- },
359
- ],
360
- outputs: [
361
- {
362
- lock,
363
- type,
364
- capacity: outputCapacity,
365
- },
366
- ],
367
- outputsData: [outputData],
368
- });
369
- // Add the CKBFS dep group cell dependency
370
- tx.addCellDeps({
371
- outPoint: {
372
- txHash: ensureHexPrefix(config.depTxHash),
373
- index: config.depIndex || 0,
374
- },
375
- depType: "depGroup",
376
- });
377
- const inputsBefore = tx.inputs.length;
378
- // If we need more capacity than the original cell had, add additional inputs
379
- if (outputCapacity > capacity) {
380
- console.log(`Need additional capacity: ${outputCapacity - capacity} shannons`);
381
- // Add more inputs to cover the increased capacity
382
- await tx.completeInputsByCapacity(signer);
383
- }
384
- const witnesses = [];
385
- // add empty witness for signer if ckbfs's lock is the same as signer's lock
386
- if (address.script.hash() === lock.hash()) {
387
- witnesses.push("0x");
388
- }
389
- // add ckbfs witnesses
390
- witnesses.push(...ckbfsWitnesses.map((w) => `0x${Buffer.from(w).toString("hex")}`));
391
- // Add empty witnesses for signer's input
392
- // This is to ensure that the transaction is valid and can be signed
393
- for (let i = inputsBefore; i < tx.inputs.length; i++) {
394
- witnesses.push("0x");
395
- }
396
- tx.witnesses = witnesses;
397
- // Complete fee
398
- await tx.completeFeeChangeToLock(signer, address.script, feeRate || 2000);
399
- return tx;
400
- }
401
- /**
402
- * Creates a transaction for appending content to a CKBFS file
403
- * @param signer The signer to use for the transaction
404
- * @param options Options for appending content
405
- * @returns Promise resolving to the created transaction
406
- */
407
- async function createAppendTransactionDry(signer, options) {
408
- const { ckbfsCell, contentChunks, network = constants_1.DEFAULT_NETWORK, version = constants_1.DEFAULT_VERSION, } = options;
409
- const { outPoint, data, type, lock, capacity } = ckbfsCell;
410
- // Get CKBFS script config early to use version info
411
- const config = (0, constants_1.getCKBFSScriptConfig)(network, version);
412
- // Create CKBFS witnesses - each chunk already includes the CKBFS header
413
- // Pass 0 as version byte - this is the protocol version byte in the witness header
414
- // not to be confused with the Protocol Version (V1 vs V2)
415
- const ckbfsWitnesses = (0, witness_1.createChunkedCKBFSWitnesses)(contentChunks);
416
- // Combine the new content chunks for checksum calculation
417
- const combinedContent = Buffer.concat(contentChunks);
418
- // Update the existing checksum with the new content - this matches Adler32's
419
- // cumulative nature as required by Rule 11 in the RFC
420
- const contentChecksum = await (0, checksum_1.updateChecksum)(data.checksum, combinedContent);
421
- console.log(`Updated checksum from ${data.checksum} to ${contentChecksum} for appended content`);
422
- // Get the recommended address to ensure lock script cell deps are included
423
- const address = await signer.getRecommendedAddressObj();
424
- // Calculate the actual witness indices where our content is placed
425
- // CKBFS data starts at index 1 if signer's lock script is the same as ckbfs's lock script
426
- // else CKBFS data starts at index 0
427
- const contentStartIndex = address.script.hash() === lock.hash() ? 1 : 0;
428
- const witnessIndices = Array.from({ length: contentChunks.length }, (_, i) => contentStartIndex + i);
429
- // Create backlink for the current state based on version
430
- let newBackLink;
431
- if (version === constants_1.ProtocolVersion.V1) {
432
- // V1 format: Use index field (single number)
433
- newBackLink = {
434
- // In V1, field order is index, checksum, txHash
435
- // and index is a single number value, not an array
436
- index: data.index ||
437
- (data.indexes && data.indexes.length > 0 ? data.indexes[0] : 0),
438
- checksum: data.checksum,
439
- txHash: outPoint.txHash,
440
- };
441
- }
442
- else {
443
- // V2 format: Use indexes field (array of numbers)
444
- newBackLink = {
445
- // In V2, field order is indexes, checksum, txHash
446
- // and indexes is an array of numbers
447
- indexes: data.indexes || (data.index ? [data.index] : []),
448
- checksum: data.checksum,
449
- txHash: outPoint.txHash,
450
- };
451
- }
452
- // Update backlinks - add the new one to the existing backlinks array
453
- const backLinks = [...(data.backLinks || []), newBackLink];
454
- // Define output data based on version
455
- let outputData;
456
- if (version === constants_1.ProtocolVersion.V1) {
457
- // In V1, index is a single number, not an array
458
- // The first witness index is used (V1 can only reference one witness)
459
- outputData = molecule_1.CKBFSData.pack({
460
- index: witnessIndices[0], // Use only the first index as a number
461
- checksum: contentChecksum,
462
- contentType: data.contentType,
463
- filename: data.filename,
464
- backLinks,
465
- }, constants_1.ProtocolVersion.V1); // Explicitly use V1 for packing
466
- }
467
- else {
468
- // In V2, indexes is an array of witness indices
469
- outputData = molecule_1.CKBFSData.pack({
470
- indexes: witnessIndices,
471
- checksum: contentChecksum,
472
- contentType: data.contentType,
473
- filename: data.filename,
474
- backLinks,
475
- }, constants_1.ProtocolVersion.V2); // Explicitly use V2 for packing
476
- }
477
- // Pack the original data to get its size - use the appropriate version
478
- const originalData = molecule_1.CKBFSData.pack(data, version);
479
- const originalDataSize = originalData.length;
480
- // Get sizes and calculate capacity requirements
481
- const newDataSize = outputData.length;
482
- // Calculate the required capacity for the output cell
483
- // This accounts for:
484
- // 1. The output data size
485
- // 2. The type script's occupied size
486
- // 3. The lock script's occupied size
487
- // 4. A constant of 8 bytes (for header overhead)
488
- const ckbfsCellSize = BigInt(outputData.length + type.occupiedSize + lock.occupiedSize + 8) *
489
- 100000000n;
490
- console.log(`Original capacity: ${capacity}, Calculated size: ${ckbfsCellSize}, Data size: ${outputData.length}`);
491
- // Use the maximum value between calculated size and original capacity
492
- // to ensure we have enough capacity but don't decrease capacity unnecessarily
493
- const outputCapacity = ckbfsCellSize > capacity ? ckbfsCellSize : capacity;
494
- // Create initial transaction with the CKBFS cell input
495
- const tx = core_1.Transaction.from({
496
- inputs: [
497
- {
498
- previousOutput: {
499
- txHash: outPoint.txHash,
500
- index: outPoint.index,
501
- },
502
- since: "0x0",
503
- },
504
- ],
505
- outputs: [
506
- {
507
- lock,
508
- type,
509
- capacity: outputCapacity,
510
- },
511
- ],
512
- outputsData: [outputData],
513
- });
514
- // Add the CKBFS dep group cell dependency
515
- tx.addCellDeps({
516
- outPoint: {
517
- txHash: ensureHexPrefix(config.depTxHash),
518
- index: config.depIndex || 0,
519
- },
520
- depType: "depGroup",
521
- });
522
- const inputsBefore = tx.inputs.length;
523
- // // If we need more capacity than the original cell had, add additional inputs
524
- // if (outputCapacity > capacity) {
525
- // console.log(
526
- // `Need additional capacity: ${outputCapacity - capacity} shannons`,
527
- // );
528
- // // Add more inputs to cover the increased capacity
529
- // await tx.completeInputsByCapacity(signer);
530
- // }
531
- const witnesses = [];
532
- // add empty witness for signer if ckbfs's lock is the same as signer's lock
533
- if (address.script.hash() === lock.hash()) {
534
- witnesses.push("0x");
535
- }
536
- // add ckbfs witnesses
537
- witnesses.push(...ckbfsWitnesses.map((w) => `0x${Buffer.from(w).toString("hex")}`));
538
- // Add empty witnesses for signer's input
539
- // This is to ensure that the transaction is valid and can be signed
540
- for (let i = inputsBefore; i < tx.inputs.length; i++) {
541
- witnesses.push("0x");
542
- }
543
- tx.witnesses = witnesses;
544
- // Complete fee
545
- //await tx.completeFeeChangeToLock(signer, address.script, feeRate || 2000);
546
- return tx;
547
- }
548
- /**
549
- * Creates a complete transaction for publishing a file to CKBFS
550
- * @param signer The signer to use for the transaction
551
- * @param options Options for publishing the file
552
- * @returns Promise resolving to the signed transaction
553
- */
554
- async function publishCKBFS(signer, options) {
555
- const tx = await createPublishTransaction(signer, options);
556
- return signer.signTransaction(tx);
557
- }
558
- /**
559
- * Creates a complete transaction for appending content to a CKBFS file
560
- * @param signer The signer to use for the transaction
561
- * @param options Options for appending content
562
- * @returns Promise resolving to the signed transaction
563
- */
564
- async function appendCKBFS(signer, options) {
565
- const tx = await createAppendTransaction(signer, options);
566
- return signer.signTransaction(tx);
567
- }
3
+ * Legacy transaction utilities - re-exports from version-specific modules
4
+ * This file maintains backward compatibility while the actual implementation
5
+ * has been moved to version-specific files in the transactions/ directory
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.transferCKBFSV3 = exports.appendCKBFSV3 = exports.publishCKBFSV3 = exports.createTransferV3Transaction = exports.createAppendV3Transaction = exports.createPublishV3Transaction = exports.preparePublishV3Transaction = exports.createCKBFSV3Cell = exports.appendCKBFS = exports.publishCKBFS = exports.createAppendTransactionDry = exports.createAppendTransaction = exports.prepareAppendTransaction = exports.createPublishTransaction = exports.preparePublishTransaction = exports.createCKBFSCell = exports.ensureHexPrefix = void 0;
23
+ // Re-export shared utilities
24
+ var shared_1 = require("./transactions/shared");
25
+ Object.defineProperty(exports, "ensureHexPrefix", { enumerable: true, get: function () { return shared_1.ensureHexPrefix; } });
26
+ // Re-export V1/V2 utilities for backward compatibility
27
+ var v1v2_1 = require("./transactions/v1v2");
28
+ Object.defineProperty(exports, "createCKBFSCell", { enumerable: true, get: function () { return v1v2_1.createCKBFSCell; } });
29
+ Object.defineProperty(exports, "preparePublishTransaction", { enumerable: true, get: function () { return v1v2_1.preparePublishTransaction; } });
30
+ Object.defineProperty(exports, "createPublishTransaction", { enumerable: true, get: function () { return v1v2_1.createPublishTransaction; } });
31
+ Object.defineProperty(exports, "prepareAppendTransaction", { enumerable: true, get: function () { return v1v2_1.prepareAppendTransaction; } });
32
+ Object.defineProperty(exports, "createAppendTransaction", { enumerable: true, get: function () { return v1v2_1.createAppendTransaction; } });
33
+ Object.defineProperty(exports, "createAppendTransactionDry", { enumerable: true, get: function () { return v1v2_1.createAppendTransactionDry; } });
34
+ Object.defineProperty(exports, "publishCKBFS", { enumerable: true, get: function () { return v1v2_1.publishCKBFS; } });
35
+ Object.defineProperty(exports, "appendCKBFS", { enumerable: true, get: function () { return v1v2_1.appendCKBFS; } });
36
+ // Re-export V3 utilities
37
+ var v3_1 = require("./transactions/v3");
38
+ Object.defineProperty(exports, "createCKBFSV3Cell", { enumerable: true, get: function () { return v3_1.createCKBFSV3Cell; } });
39
+ Object.defineProperty(exports, "preparePublishV3Transaction", { enumerable: true, get: function () { return v3_1.preparePublishV3Transaction; } });
40
+ Object.defineProperty(exports, "createPublishV3Transaction", { enumerable: true, get: function () { return v3_1.createPublishV3Transaction; } });
41
+ Object.defineProperty(exports, "createAppendV3Transaction", { enumerable: true, get: function () { return v3_1.createAppendV3Transaction; } });
42
+ Object.defineProperty(exports, "createTransferV3Transaction", { enumerable: true, get: function () { return v3_1.createTransferV3Transaction; } });
43
+ Object.defineProperty(exports, "publishCKBFSV3", { enumerable: true, get: function () { return v3_1.publishCKBFSV3; } });
44
+ Object.defineProperty(exports, "appendCKBFSV3", { enumerable: true, get: function () { return v3_1.appendCKBFSV3; } });
45
+ Object.defineProperty(exports, "transferCKBFSV3", { enumerable: true, get: function () { return v3_1.transferCKBFSV3; } });
46
+ // Re-export all from transactions index
47
+ __exportStar(require("./transactions"), exports);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Transaction utilities for all CKBFS protocol versions
3
+ */
4
+ export * from "./shared";
5
+ export * from "./v1v2";
6
+ export * from "./v3";
7
+ export { createCKBFSCell } from "./v1v2";
8
+ export { createCKBFSV3Cell } from "./v3";
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * Transaction utilities for all CKBFS protocol versions
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.createCKBFSV3Cell = exports.createCKBFSCell = void 0;
21
+ // Shared utilities and interfaces
22
+ __exportStar(require("./shared"), exports);
23
+ // V1 and V2 transaction utilities
24
+ __exportStar(require("./v1v2"), exports);
25
+ // V3 transaction utilities
26
+ __exportStar(require("./v3"), exports);
27
+ // Re-export for backward compatibility
28
+ var v1v2_1 = require("./v1v2");
29
+ Object.defineProperty(exports, "createCKBFSCell", { enumerable: true, get: function () { return v1v2_1.createCKBFSCell; } });
30
+ var v3_1 = require("./v3");
31
+ Object.defineProperty(exports, "createCKBFSV3Cell", { enumerable: true, get: function () { return v3_1.createCKBFSV3Cell; } });