@ckbfs/api 1.2.3 → 1.2.5

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/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Script, Signer, Transaction } from "@ckb-ccc/core";
2
- import { calculateChecksum, verifyChecksum, updateChecksum, verifyWitnessChecksum } from './utils/checksum';
3
- import { createCKBFSCell, createPublishTransaction, createAppendTransaction, publishCKBFS, appendCKBFS, CKBFSCellOptions, PublishOptions, AppendOptions } from './utils/transaction';
4
- import { readFile, readFileAsText, readFileAsUint8Array, writeFile, getContentType, splitFileIntoChunks, combineChunksToFile, getFileContentFromChain, saveFileFromChain } from './utils/file';
5
- import { createCKBFSWitness, createTextCKBFSWitness, extractCKBFSWitnessContent, isCKBFSWitness, createChunkedCKBFSWitnesses } from './utils/witness';
6
- import { CKBFSData, BackLinkV1, BackLinkV2, CKBFSDataType, BackLinkType, CKBFS_HEADER, CKBFS_HEADER_STRING } from './utils/molecule';
7
- import { NetworkType, ProtocolVersion, DEFAULT_NETWORK, DEFAULT_VERSION, CKBFS_CODE_HASH, CKBFS_TYPE_ID, ADLER32_CODE_HASH, ADLER32_TYPE_ID, DEP_GROUP_TX_HASH, DEPLOY_TX_HASH, getCKBFSScriptConfig, CKBFSScriptConfig } from './utils/constants';
2
+ import { calculateChecksum, verifyChecksum, updateChecksum, verifyWitnessChecksum } from "./utils/checksum";
3
+ import { createCKBFSCell, createPublishTransaction as utilCreatePublishTransaction, createAppendTransaction as utilCreateAppendTransaction, publishCKBFS as utilPublishCKBFS, appendCKBFS as utilAppendCKBFS, CKBFSCellOptions, PublishOptions, AppendOptions } from "./utils/transaction";
4
+ import { readFile, readFileAsText, readFileAsUint8Array, writeFile, getContentType, splitFileIntoChunks, combineChunksToFile, getFileContentFromChain, saveFileFromChain, getFileContentFromChainByTypeId, saveFileFromChainByTypeId, decodeFileFromChainByTypeId, getFileContentFromChainByIdentifier, saveFileFromChainByIdentifier, decodeFileFromChainByIdentifier, parseIdentifier, IdentifierType, decodeWitnessContent, decodeMultipleWitnessContents, extractFileFromWitnesses, decodeFileFromWitnessData, saveFileFromWitnessData } from "./utils/file";
5
+ import { createCKBFSWitness, createTextCKBFSWitness, extractCKBFSWitnessContent, isCKBFSWitness, createChunkedCKBFSWitnesses } from "./utils/witness";
6
+ import { CKBFSData, BackLinkV1, BackLinkV2, CKBFSDataType, BackLinkType, CKBFS_HEADER, CKBFS_HEADER_STRING } from "./utils/molecule";
7
+ import { NetworkType, ProtocolVersion, ProtocolVersionType, DEFAULT_NETWORK, DEFAULT_VERSION, CKBFS_CODE_HASH, CKBFS_TYPE_ID, ADLER32_CODE_HASH, ADLER32_TYPE_ID, DEP_GROUP_TX_HASH, DEPLOY_TX_HASH, getCKBFSScriptConfig, CKBFSScriptConfig } from "./utils/constants";
8
8
  /**
9
9
  * Custom options for file publishing and appending
10
10
  */
@@ -14,15 +14,27 @@ export interface FileOptions {
14
14
  capacity?: bigint;
15
15
  feeRate?: number;
16
16
  network?: NetworkType;
17
- version?: string;
17
+ version?: ProtocolVersionType;
18
18
  useTypeID?: boolean;
19
19
  }
20
+ /**
21
+ * Options required when publishing content directly (string or Uint8Array)
22
+ */
23
+ export type PublishContentOptions = Omit<FileOptions, "capacity" | "contentType" | "filename"> & Required<Pick<FileOptions, "contentType" | "filename">> & {
24
+ capacity?: bigint;
25
+ };
26
+ /**
27
+ * Options required when appending content directly (string or Uint8Array)
28
+ */
29
+ export type AppendContentOptions = Omit<FileOptions, "contentType" | "filename" | "capacity"> & {
30
+ capacity?: bigint;
31
+ };
20
32
  /**
21
33
  * Configuration options for the CKBFS SDK
22
34
  */
23
35
  export interface CKBFSOptions {
24
36
  chunkSize?: number;
25
- version?: string;
37
+ version?: ProtocolVersionType;
26
38
  useTypeID?: boolean;
27
39
  network?: NetworkType;
28
40
  }
@@ -65,13 +77,28 @@ export declare class CKBFS {
65
77
  */
66
78
  publishFile(filePath: string, options?: FileOptions): Promise<string>;
67
79
  /**
68
- * Appends content to an existing CKBFS file
80
+ * Publishes content (string or Uint8Array) directly to CKBFS
81
+ * @param content The content string or byte array to publish
82
+ * @param options Options for publishing the content (contentType and filename are required)
83
+ * @returns Promise resolving to the transaction hash
84
+ */
85
+ publishContent(content: string | Uint8Array, options: PublishContentOptions): Promise<string>;
86
+ /**
87
+ * Appends content from a file to an existing CKBFS file
69
88
  * @param filePath The path to the file containing the content to append
70
89
  * @param ckbfsCell The CKBFS cell to append to
71
90
  * @param options Additional options for the append operation
72
91
  * @returns Promise resolving to the transaction hash
73
92
  */
74
- appendFile(filePath: string, ckbfsCell: AppendOptions['ckbfsCell'], options?: Omit<FileOptions, 'contentType' | 'filename'>): Promise<string>;
93
+ appendFile(filePath: string, ckbfsCell: AppendOptions["ckbfsCell"], options?: Omit<FileOptions, "contentType" | "filename">): Promise<string>;
94
+ /**
95
+ * Appends content (string or Uint8Array) directly to an existing CKBFS file
96
+ * @param content The content string or byte array to append
97
+ * @param ckbfsCell The CKBFS cell to append to
98
+ * @param options Additional options for the append operation
99
+ * @returns Promise resolving to the transaction hash
100
+ */
101
+ appendContent(content: string | Uint8Array, ckbfsCell: AppendOptions["ckbfsCell"], options?: AppendContentOptions): Promise<string>;
75
102
  /**
76
103
  * Creates a new transaction for publishing a file but doesn't sign or send it
77
104
  * @param filePath The path to the file to publish
@@ -80,12 +107,27 @@ export declare class CKBFS {
80
107
  */
81
108
  createPublishTransaction(filePath: string, options?: FileOptions): Promise<Transaction>;
82
109
  /**
83
- * Creates a new transaction for appending content but doesn't sign or send it
110
+ * Creates a new transaction for publishing content (string or Uint8Array) directly, but doesn't sign or send it
111
+ * @param content The content string or byte array to publish
112
+ * @param options Options for publishing the content (contentType and filename are required)
113
+ * @returns Promise resolving to the unsigned transaction
114
+ */
115
+ createPublishContentTransaction(content: string | Uint8Array, options: PublishContentOptions): Promise<Transaction>;
116
+ /**
117
+ * Creates a new transaction for appending content from a file but doesn't sign or send it
84
118
  * @param filePath The path to the file containing the content to append
85
119
  * @param ckbfsCell The CKBFS cell to append to
86
120
  * @param options Additional options for the append operation
87
121
  * @returns Promise resolving to the unsigned transaction
88
122
  */
89
- createAppendTransaction(filePath: string, ckbfsCell: AppendOptions['ckbfsCell'], options?: Omit<FileOptions, 'contentType' | 'filename'>): Promise<Transaction>;
123
+ createAppendTransaction(filePath: string, ckbfsCell: AppendOptions["ckbfsCell"], options?: Omit<FileOptions, "contentType" | "filename">): Promise<Transaction>;
124
+ /**
125
+ * Creates a new transaction for appending content (string or Uint8Array) directly, but doesn't sign or send it
126
+ * @param content The content string or byte array to append
127
+ * @param ckbfsCell The CKBFS cell to append to
128
+ * @param options Additional options for the append operation
129
+ * @returns Promise resolving to the unsigned transaction
130
+ */
131
+ createAppendContentTransaction(content: string | Uint8Array, ckbfsCell: AppendOptions["ckbfsCell"], options?: AppendContentOptions): Promise<Transaction>;
90
132
  }
91
- export { calculateChecksum, verifyChecksum, updateChecksum, verifyWitnessChecksum, createCKBFSCell, createPublishTransaction, createAppendTransaction, publishCKBFS, appendCKBFS, readFile, readFileAsText, readFileAsUint8Array, writeFile, getContentType, splitFileIntoChunks, combineChunksToFile, getFileContentFromChain, saveFileFromChain, createCKBFSWitness, createTextCKBFSWitness, extractCKBFSWitnessContent, isCKBFSWitness, createChunkedCKBFSWitnesses, CKBFSData, BackLinkV1, BackLinkV2, CKBFSDataType, BackLinkType, CKBFSCellOptions, PublishOptions, AppendOptions, CKBFS_HEADER, CKBFS_HEADER_STRING, NetworkType, ProtocolVersion, DEFAULT_NETWORK, DEFAULT_VERSION, CKBFS_CODE_HASH, CKBFS_TYPE_ID, ADLER32_CODE_HASH, ADLER32_TYPE_ID, DEP_GROUP_TX_HASH, DEPLOY_TX_HASH, getCKBFSScriptConfig, CKBFSScriptConfig };
133
+ export { calculateChecksum, verifyChecksum, updateChecksum, verifyWitnessChecksum, createCKBFSCell, utilCreatePublishTransaction as createPublishTransaction, utilCreateAppendTransaction as createAppendTransaction, utilPublishCKBFS as publishCKBFS, utilAppendCKBFS as appendCKBFS, readFile, readFileAsText, readFileAsUint8Array, writeFile, getContentType, splitFileIntoChunks, combineChunksToFile, getFileContentFromChain, saveFileFromChain, getFileContentFromChainByTypeId, saveFileFromChainByTypeId, decodeFileFromChainByTypeId, getFileContentFromChainByIdentifier, saveFileFromChainByIdentifier, decodeFileFromChainByIdentifier, parseIdentifier, IdentifierType, decodeWitnessContent, decodeMultipleWitnessContents, extractFileFromWitnesses, decodeFileFromWitnessData, saveFileFromWitnessData, createCKBFSWitness, createTextCKBFSWitness, extractCKBFSWitnessContent, isCKBFSWitness, createChunkedCKBFSWitnesses, CKBFSData, BackLinkV1, BackLinkV2, CKBFSDataType, BackLinkType, CKBFSCellOptions, PublishOptions, AppendOptions, CKBFS_HEADER, CKBFS_HEADER_STRING, NetworkType, ProtocolVersion, ProtocolVersionType, DEFAULT_NETWORK, DEFAULT_VERSION, CKBFS_CODE_HASH, CKBFS_TYPE_ID, ADLER32_CODE_HASH, ADLER32_TYPE_ID, DEP_GROUP_TX_HASH, DEPLOY_TX_HASH, getCKBFSScriptConfig, CKBFSScriptConfig, };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCKBFSScriptConfig = exports.DEPLOY_TX_HASH = exports.DEP_GROUP_TX_HASH = exports.ADLER32_TYPE_ID = exports.ADLER32_CODE_HASH = exports.CKBFS_TYPE_ID = exports.CKBFS_CODE_HASH = exports.DEFAULT_VERSION = exports.DEFAULT_NETWORK = exports.ProtocolVersion = exports.NetworkType = exports.CKBFS_HEADER_STRING = exports.CKBFS_HEADER = exports.BackLinkV2 = exports.BackLinkV1 = exports.CKBFSData = exports.createChunkedCKBFSWitnesses = exports.isCKBFSWitness = exports.extractCKBFSWitnessContent = exports.createTextCKBFSWitness = exports.createCKBFSWitness = exports.saveFileFromChain = exports.getFileContentFromChain = exports.combineChunksToFile = exports.splitFileIntoChunks = exports.getContentType = exports.writeFile = exports.readFileAsUint8Array = exports.readFileAsText = exports.readFile = exports.appendCKBFS = exports.publishCKBFS = exports.createAppendTransaction = exports.createPublishTransaction = exports.createCKBFSCell = exports.verifyWitnessChecksum = exports.updateChecksum = exports.verifyChecksum = exports.calculateChecksum = exports.CKBFS = void 0;
3
+ exports.ADLER32_TYPE_ID = exports.ADLER32_CODE_HASH = exports.CKBFS_TYPE_ID = exports.CKBFS_CODE_HASH = exports.DEFAULT_VERSION = exports.DEFAULT_NETWORK = exports.ProtocolVersion = exports.NetworkType = exports.CKBFS_HEADER_STRING = exports.CKBFS_HEADER = exports.BackLinkV2 = exports.BackLinkV1 = exports.CKBFSData = exports.createChunkedCKBFSWitnesses = exports.isCKBFSWitness = exports.extractCKBFSWitnessContent = exports.createTextCKBFSWitness = exports.createCKBFSWitness = exports.saveFileFromWitnessData = exports.decodeFileFromWitnessData = exports.extractFileFromWitnesses = exports.decodeMultipleWitnessContents = exports.decodeWitnessContent = exports.IdentifierType = exports.parseIdentifier = exports.decodeFileFromChainByIdentifier = exports.saveFileFromChainByIdentifier = exports.getFileContentFromChainByIdentifier = exports.decodeFileFromChainByTypeId = exports.saveFileFromChainByTypeId = exports.getFileContentFromChainByTypeId = exports.saveFileFromChain = exports.getFileContentFromChain = exports.combineChunksToFile = exports.splitFileIntoChunks = exports.getContentType = exports.writeFile = exports.readFileAsUint8Array = exports.readFileAsText = exports.readFile = exports.appendCKBFS = exports.publishCKBFS = exports.createAppendTransaction = exports.createPublishTransaction = exports.createCKBFSCell = exports.verifyWitnessChecksum = exports.updateChecksum = exports.verifyChecksum = exports.calculateChecksum = exports.CKBFS = void 0;
4
+ exports.getCKBFSScriptConfig = exports.DEPLOY_TX_HASH = exports.DEP_GROUP_TX_HASH = void 0;
4
5
  const core_1 = require("@ckb-ccc/core");
5
6
  const checksum_1 = require("./utils/checksum");
6
7
  Object.defineProperty(exports, "calculateChecksum", { enumerable: true, get: function () { return checksum_1.calculateChecksum; } });
@@ -23,6 +24,19 @@ Object.defineProperty(exports, "splitFileIntoChunks", { enumerable: true, get: f
23
24
  Object.defineProperty(exports, "combineChunksToFile", { enumerable: true, get: function () { return file_1.combineChunksToFile; } });
24
25
  Object.defineProperty(exports, "getFileContentFromChain", { enumerable: true, get: function () { return file_1.getFileContentFromChain; } });
25
26
  Object.defineProperty(exports, "saveFileFromChain", { enumerable: true, get: function () { return file_1.saveFileFromChain; } });
27
+ Object.defineProperty(exports, "getFileContentFromChainByTypeId", { enumerable: true, get: function () { return file_1.getFileContentFromChainByTypeId; } });
28
+ Object.defineProperty(exports, "saveFileFromChainByTypeId", { enumerable: true, get: function () { return file_1.saveFileFromChainByTypeId; } });
29
+ Object.defineProperty(exports, "decodeFileFromChainByTypeId", { enumerable: true, get: function () { return file_1.decodeFileFromChainByTypeId; } });
30
+ Object.defineProperty(exports, "getFileContentFromChainByIdentifier", { enumerable: true, get: function () { return file_1.getFileContentFromChainByIdentifier; } });
31
+ Object.defineProperty(exports, "saveFileFromChainByIdentifier", { enumerable: true, get: function () { return file_1.saveFileFromChainByIdentifier; } });
32
+ Object.defineProperty(exports, "decodeFileFromChainByIdentifier", { enumerable: true, get: function () { return file_1.decodeFileFromChainByIdentifier; } });
33
+ Object.defineProperty(exports, "parseIdentifier", { enumerable: true, get: function () { return file_1.parseIdentifier; } });
34
+ Object.defineProperty(exports, "IdentifierType", { enumerable: true, get: function () { return file_1.IdentifierType; } });
35
+ Object.defineProperty(exports, "decodeWitnessContent", { enumerable: true, get: function () { return file_1.decodeWitnessContent; } });
36
+ Object.defineProperty(exports, "decodeMultipleWitnessContents", { enumerable: true, get: function () { return file_1.decodeMultipleWitnessContents; } });
37
+ Object.defineProperty(exports, "extractFileFromWitnesses", { enumerable: true, get: function () { return file_1.extractFileFromWitnesses; } });
38
+ Object.defineProperty(exports, "decodeFileFromWitnessData", { enumerable: true, get: function () { return file_1.decodeFileFromWitnessData; } });
39
+ Object.defineProperty(exports, "saveFileFromWitnessData", { enumerable: true, get: function () { return file_1.saveFileFromWitnessData; } });
26
40
  const witness_1 = require("./utils/witness");
27
41
  Object.defineProperty(exports, "createCKBFSWitness", { enumerable: true, get: function () { return witness_1.createCKBFSWitness; } });
28
42
  Object.defineProperty(exports, "createTextCKBFSWitness", { enumerable: true, get: function () { return witness_1.createTextCKBFSWitness; } });
@@ -47,6 +61,9 @@ Object.defineProperty(exports, "ADLER32_TYPE_ID", { enumerable: true, get: funct
47
61
  Object.defineProperty(exports, "DEP_GROUP_TX_HASH", { enumerable: true, get: function () { return constants_1.DEP_GROUP_TX_HASH; } });
48
62
  Object.defineProperty(exports, "DEPLOY_TX_HASH", { enumerable: true, get: function () { return constants_1.DEPLOY_TX_HASH; } });
49
63
  Object.defineProperty(exports, "getCKBFSScriptConfig", { enumerable: true, get: function () { return constants_1.getCKBFSScriptConfig; } });
64
+ const transaction_2 = require("./utils/transaction");
65
+ // Helper to encode string to Uint8Array
66
+ const textEncoder = new TextEncoder();
50
67
  /**
51
68
  * Main CKBFS SDK class
52
69
  */
@@ -59,11 +76,14 @@ class CKBFS {
59
76
  */
60
77
  constructor(signerOrPrivateKey, networkOrOptions = constants_1.DEFAULT_NETWORK, options) {
61
78
  // Determine if first parameter is a Signer or privateKey
62
- if (typeof signerOrPrivateKey === 'string') {
79
+ if (typeof signerOrPrivateKey === "string") {
63
80
  // Initialize with private key
64
81
  const privateKey = signerOrPrivateKey;
65
- const network = typeof networkOrOptions === 'string' ? networkOrOptions : constants_1.DEFAULT_NETWORK;
66
- const opts = options || (typeof networkOrOptions === 'object' ? networkOrOptions : {});
82
+ const network = typeof networkOrOptions === "string"
83
+ ? networkOrOptions
84
+ : constants_1.DEFAULT_NETWORK;
85
+ const opts = options ||
86
+ (typeof networkOrOptions === "object" ? networkOrOptions : {});
67
87
  const client = new core_1.ClientPublicTestnet();
68
88
  this.signer = new core_1.SignerCkbPrivateKey(client, privateKey);
69
89
  this.network = network;
@@ -74,7 +94,7 @@ class CKBFS {
74
94
  else {
75
95
  // Initialize with signer
76
96
  this.signer = signerOrPrivateKey;
77
- const opts = typeof networkOrOptions === 'object' ? networkOrOptions : {};
97
+ const opts = typeof networkOrOptions === "object" ? networkOrOptions : {};
78
98
  this.network = opts.network || constants_1.DEFAULT_NETWORK;
79
99
  this.chunkSize = opts.chunkSize || 30 * 1024;
80
100
  this.version = opts.version || constants_1.DEFAULT_VERSION;
@@ -123,7 +143,7 @@ class CKBFS {
123
143
  // Use the filename from the path if not provided
124
144
  const pathParts = filePath.split(/[\\\/]/);
125
145
  const filename = options.filename || pathParts[pathParts.length - 1];
126
- // Create and sign the transaction
146
+ // Create and sign the transaction using the utility function
127
147
  const tx = await (0, transaction_1.publishCKBFS)(this.signer, {
128
148
  contentChunks,
129
149
  contentType,
@@ -133,15 +153,45 @@ class CKBFS {
133
153
  feeRate: options.feeRate,
134
154
  network: options.network || this.network,
135
155
  version: options.version || this.version,
136
- useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID
156
+ useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
137
157
  });
138
- console.log('tx', tx.stringify());
158
+ console.log("Publish file tx:", tx.stringify());
139
159
  // Send the transaction
140
160
  const txHash = await this.signer.sendTransaction(tx);
141
- return txHash;
161
+ return (0, transaction_2.ensureHexPrefix)(txHash);
142
162
  }
143
163
  /**
144
- * Appends content to an existing CKBFS file
164
+ * Publishes content (string or Uint8Array) directly to CKBFS
165
+ * @param content The content string or byte array to publish
166
+ * @param options Options for publishing the content (contentType and filename are required)
167
+ * @returns Promise resolving to the transaction hash
168
+ */
169
+ async publishContent(content, options) {
170
+ const contentBytes = typeof content === "string" ? textEncoder.encode(content) : content;
171
+ const contentChunks = [];
172
+ for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
173
+ contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
174
+ }
175
+ const lock = await this.getLock();
176
+ // Use provided contentType and filename (required)
177
+ const { contentType, filename } = options;
178
+ const tx = await (0, transaction_1.publishCKBFS)(this.signer, {
179
+ contentChunks,
180
+ contentType,
181
+ filename,
182
+ lock,
183
+ capacity: options.capacity,
184
+ feeRate: options.feeRate,
185
+ network: options.network || this.network,
186
+ version: options.version || this.version,
187
+ useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
188
+ });
189
+ console.log("Publish content tx:", tx.stringify());
190
+ const txHash = await this.signer.sendTransaction(tx);
191
+ return (0, transaction_2.ensureHexPrefix)(txHash);
192
+ }
193
+ /**
194
+ * Appends content from a file to an existing CKBFS file
145
195
  * @param filePath The path to the file containing the content to append
146
196
  * @param ckbfsCell The CKBFS cell to append to
147
197
  * @param options Additional options for the append operation
@@ -154,17 +204,43 @@ class CKBFS {
154
204
  for (let i = 0; i < fileContent.length; i += this.chunkSize) {
155
205
  contentChunks.push(fileContent.slice(i, i + this.chunkSize));
156
206
  }
157
- // Create and sign the transaction
207
+ // Create and sign the transaction using the utility function
158
208
  const tx = await (0, transaction_1.appendCKBFS)(this.signer, {
159
209
  ckbfsCell,
160
210
  contentChunks,
161
211
  feeRate: options.feeRate,
162
212
  network: options.network || this.network,
163
- version: options.version || this.version
213
+ version: options.version || this.version,
164
214
  });
215
+ console.log("Append file tx:", tx.stringify());
165
216
  // Send the transaction
166
217
  const txHash = await this.signer.sendTransaction(tx);
167
- return txHash;
218
+ return (0, transaction_2.ensureHexPrefix)(txHash);
219
+ }
220
+ /**
221
+ * Appends content (string or Uint8Array) directly to an existing CKBFS file
222
+ * @param content The content string or byte array to append
223
+ * @param ckbfsCell The CKBFS cell to append to
224
+ * @param options Additional options for the append operation
225
+ * @returns Promise resolving to the transaction hash
226
+ */
227
+ async appendContent(content, ckbfsCell, options = {}) {
228
+ const contentBytes = typeof content === "string" ? textEncoder.encode(content) : content;
229
+ const contentChunks = [];
230
+ for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
231
+ contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
232
+ }
233
+ const tx = await (0, transaction_1.appendCKBFS)(this.signer, {
234
+ ckbfsCell,
235
+ contentChunks,
236
+ feeRate: options.feeRate,
237
+ network: options.network || this.network,
238
+ version: options.version || this.version,
239
+ // No useTypeID option for append
240
+ });
241
+ console.log("Append content tx:", tx.stringify());
242
+ const txHash = await this.signer.sendTransaction(tx);
243
+ return (0, transaction_2.ensureHexPrefix)(txHash);
168
244
  }
169
245
  /**
170
246
  * Creates a new transaction for publishing a file but doesn't sign or send it
@@ -186,7 +262,34 @@ class CKBFS {
186
262
  // Use the filename from the path if not provided
187
263
  const pathParts = filePath.split(/[\\\/]/);
188
264
  const filename = options.filename || pathParts[pathParts.length - 1];
189
- // Create the transaction
265
+ // Create the transaction using the utility function
266
+ return (0, transaction_1.createPublishTransaction)(this.signer, {
267
+ contentChunks,
268
+ contentType,
269
+ filename,
270
+ lock,
271
+ capacity: options.capacity,
272
+ feeRate: options.feeRate,
273
+ network: options.network || this.network,
274
+ version: options.version || this.version,
275
+ useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
276
+ });
277
+ }
278
+ /**
279
+ * Creates a new transaction for publishing content (string or Uint8Array) directly, but doesn't sign or send it
280
+ * @param content The content string or byte array to publish
281
+ * @param options Options for publishing the content (contentType and filename are required)
282
+ * @returns Promise resolving to the unsigned transaction
283
+ */
284
+ async createPublishContentTransaction(content, options) {
285
+ const contentBytes = typeof content === "string" ? textEncoder.encode(content) : content;
286
+ const contentChunks = [];
287
+ for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
288
+ contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
289
+ }
290
+ const lock = await this.getLock();
291
+ // Use provided contentType and filename (required)
292
+ const { contentType, filename } = options;
190
293
  return (0, transaction_1.createPublishTransaction)(this.signer, {
191
294
  contentChunks,
192
295
  contentType,
@@ -196,11 +299,11 @@ class CKBFS {
196
299
  feeRate: options.feeRate,
197
300
  network: options.network || this.network,
198
301
  version: options.version || this.version,
199
- useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID
302
+ useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
200
303
  });
201
304
  }
202
305
  /**
203
- * Creates a new transaction for appending content but doesn't sign or send it
306
+ * Creates a new transaction for appending content from a file but doesn't sign or send it
204
307
  * @param filePath The path to the file containing the content to append
205
308
  * @param ckbfsCell The CKBFS cell to append to
206
309
  * @param options Additional options for the append operation
@@ -213,13 +316,35 @@ class CKBFS {
213
316
  for (let i = 0; i < fileContent.length; i += this.chunkSize) {
214
317
  contentChunks.push(fileContent.slice(i, i + this.chunkSize));
215
318
  }
216
- // Create the transaction
319
+ // Create the transaction using the utility function
217
320
  return (0, transaction_1.createAppendTransaction)(this.signer, {
218
321
  ckbfsCell,
219
322
  contentChunks,
220
323
  feeRate: options.feeRate,
221
324
  network: options.network || this.network,
222
- version: options.version || this.version
325
+ version: options.version || this.version,
326
+ });
327
+ }
328
+ /**
329
+ * Creates a new transaction for appending content (string or Uint8Array) directly, but doesn't sign or send it
330
+ * @param content The content string or byte array to append
331
+ * @param ckbfsCell The CKBFS cell to append to
332
+ * @param options Additional options for the append operation
333
+ * @returns Promise resolving to the unsigned transaction
334
+ */
335
+ async createAppendContentTransaction(content, ckbfsCell, options = {}) {
336
+ const contentBytes = typeof content === "string" ? textEncoder.encode(content) : content;
337
+ const contentChunks = [];
338
+ for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
339
+ contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
340
+ }
341
+ return (0, transaction_1.createAppendTransaction)(this.signer, {
342
+ ckbfsCell,
343
+ contentChunks,
344
+ feeRate: options.feeRate,
345
+ network: options.network || this.network,
346
+ version: options.version || this.version,
347
+ // No useTypeID option for append
223
348
  });
224
349
  }
225
350
  }
@@ -9,7 +9,7 @@ export declare const ProtocolVersion: {
9
9
  readonly V1: "20240906.ce6724722cf6";
10
10
  readonly V2: "20241025.db973a8e8032";
11
11
  };
12
- export type ProtocolVersionType = typeof ProtocolVersion[keyof typeof ProtocolVersion];
12
+ export type ProtocolVersionType = (typeof ProtocolVersion)[keyof typeof ProtocolVersion] | string;
13
13
  export declare const CKBFS_CODE_HASH: Record<NetworkType, Record<string, string>>;
14
14
  export declare const CKBFS_TYPE_ID: Record<NetworkType, Record<string, string>>;
15
15
  export declare const ADLER32_CODE_HASH: Record<NetworkType, Record<string, string>>;
@@ -23,7 +23,7 @@ export declare const DEFAULT_VERSION: "20241025.db973a8e8032";
23
23
  export declare const DEFAULT_NETWORK = NetworkType.Testnet;
24
24
  export interface CKBFSScriptConfig {
25
25
  codeHash: string;
26
- hashType: 'data1' | 'type';
26
+ hashType: "data1" | "type";
27
27
  depTxHash: string;
28
28
  depIndex?: number;
29
29
  }
@@ -34,4 +34,8 @@ export interface CKBFSScriptConfig {
34
34
  * @param useTypeID Whether to use type ID instead of code hash (default: false)
35
35
  * @returns CKBFS script configuration
36
36
  */
37
- export declare function getCKBFSScriptConfig(network?: NetworkType, version?: string, useTypeID?: boolean): CKBFSScriptConfig;
37
+ export declare function getCKBFSScriptConfig(network?: NetworkType, version?: ProtocolVersionType, useTypeID?: boolean): CKBFSScriptConfig;
38
+ import { Hex, HashType, CellDepInfo, ScriptInfo } from "@ckb-ccc/core";
39
+ export declare class CKBFSScriptInfo extends ScriptInfo {
40
+ constructor(codeHash: Hex, hashType: HashType, cellDeps: CellDepInfo[]);
41
+ }
@@ -3,7 +3,7 @@
3
3
  * CKBFS protocol deployment constants
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DEFAULT_NETWORK = exports.DEFAULT_VERSION = exports.DEPLOY_TX_HASH = exports.DEP_GROUP_TX_HASH = exports.ADLER32_TYPE_ID = exports.ADLER32_CODE_HASH = exports.CKBFS_TYPE_ID = exports.CKBFS_CODE_HASH = exports.ProtocolVersion = exports.NetworkType = void 0;
6
+ exports.CKBFSScriptInfo = exports.DEFAULT_NETWORK = exports.DEFAULT_VERSION = exports.DEPLOY_TX_HASH = exports.DEP_GROUP_TX_HASH = exports.ADLER32_TYPE_ID = exports.ADLER32_CODE_HASH = exports.CKBFS_TYPE_ID = exports.CKBFS_CODE_HASH = exports.ProtocolVersion = exports.NetworkType = void 0;
7
7
  exports.getCKBFSScriptConfig = getCKBFSScriptConfig;
8
8
  var NetworkType;
9
9
  (function (NetworkType) {
@@ -12,75 +12,75 @@ var NetworkType;
12
12
  })(NetworkType || (exports.NetworkType = NetworkType = {}));
13
13
  // Use string literals for version values to avoid TypeScript indexing issues
14
14
  exports.ProtocolVersion = {
15
- V1: '20240906.ce6724722cf6', // Original version, compact and simple, suitable for small files
16
- V2: '20241025.db973a8e8032' // New version, more features and can do complex operations
15
+ V1: "20240906.ce6724722cf6", // Original version, compact and simple, suitable for small files
16
+ V2: "20241025.db973a8e8032", // New version, more features and can do complex operations
17
17
  };
18
18
  // CKBFS Type Script Constants
19
19
  exports.CKBFS_CODE_HASH = {
20
20
  [NetworkType.Mainnet]: {
21
- [exports.ProtocolVersion.V2]: '0x31e6376287d223b8c0410d562fb422f04d1d617b2947596a14c3d2efb7218d3a'
21
+ [exports.ProtocolVersion.V2]: "0x31e6376287d223b8c0410d562fb422f04d1d617b2947596a14c3d2efb7218d3a",
22
22
  },
23
23
  [NetworkType.Testnet]: {
24
- [exports.ProtocolVersion.V1]: '0xe8905ad29a02cf8befa9c258f4f941773839a618d75a64afc22059de9413f712',
25
- [exports.ProtocolVersion.V2]: '0x31e6376287d223b8c0410d562fb422f04d1d617b2947596a14c3d2efb7218d3a'
26
- }
24
+ [exports.ProtocolVersion.V1]: "0xe8905ad29a02cf8befa9c258f4f941773839a618d75a64afc22059de9413f712",
25
+ [exports.ProtocolVersion.V2]: "0x31e6376287d223b8c0410d562fb422f04d1d617b2947596a14c3d2efb7218d3a",
26
+ },
27
27
  };
28
28
  exports.CKBFS_TYPE_ID = {
29
29
  [NetworkType.Mainnet]: {
30
- [exports.ProtocolVersion.V2]: '0xfd2058c9a0c0183354cf637e25d2707ffa9bb6fa2ba9b29f4ebc6be3e54ad7eb'
30
+ [exports.ProtocolVersion.V2]: "0xfd2058c9a0c0183354cf637e25d2707ffa9bb6fa2ba9b29f4ebc6be3e54ad7eb",
31
31
  },
32
32
  [NetworkType.Testnet]: {
33
- [exports.ProtocolVersion.V1]: '0x88ef4d436af35684a27edda0d44dd8771318330285f90f02d13606e095aea86f',
34
- [exports.ProtocolVersion.V2]: '0x7c6dcab8268201f064dc8676b5eafa60ca2569e5c6209dcbab0eb64a9cb3aaa3'
35
- }
33
+ [exports.ProtocolVersion.V1]: "0x88ef4d436af35684a27edda0d44dd8771318330285f90f02d13606e095aea86f",
34
+ [exports.ProtocolVersion.V2]: "0x7c6dcab8268201f064dc8676b5eafa60ca2569e5c6209dcbab0eb64a9cb3aaa3",
35
+ },
36
36
  };
37
37
  // Adler32 Hasher Constants
38
38
  exports.ADLER32_CODE_HASH = {
39
39
  [NetworkType.Mainnet]: {
40
- [exports.ProtocolVersion.V2]: '0x2138683f76944437c0c643664120d620bdb5858dd6c9d1d156805e279c2c536f'
40
+ [exports.ProtocolVersion.V2]: "0x2138683f76944437c0c643664120d620bdb5858dd6c9d1d156805e279c2c536f",
41
41
  },
42
42
  [NetworkType.Testnet]: {
43
- [exports.ProtocolVersion.V1]: '0x8af42cd329cf1bcffb4c73b48252e99cb32346fdbc1cdaa5ae1d000232d47e84',
44
- [exports.ProtocolVersion.V2]: '0x2138683f76944437c0c643664120d620bdb5858dd6c9d1d156805e279c2c536f'
45
- }
43
+ [exports.ProtocolVersion.V1]: "0x8af42cd329cf1bcffb4c73b48252e99cb32346fdbc1cdaa5ae1d000232d47e84",
44
+ [exports.ProtocolVersion.V2]: "0x2138683f76944437c0c643664120d620bdb5858dd6c9d1d156805e279c2c536f",
45
+ },
46
46
  };
47
47
  exports.ADLER32_TYPE_ID = {
48
48
  [NetworkType.Mainnet]: {
49
- [exports.ProtocolVersion.V2]: '0x641c01d590833a3f5471bd441651d9f2a8a200141949cdfeef2d68d8094c5876'
49
+ [exports.ProtocolVersion.V2]: "0x641c01d590833a3f5471bd441651d9f2a8a200141949cdfeef2d68d8094c5876",
50
50
  },
51
51
  [NetworkType.Testnet]: {
52
- [exports.ProtocolVersion.V1]: '0xccf29a0d8e860044a3d2f6a6e709f6572f77e4fe245fadd212fc342337048d60',
53
- [exports.ProtocolVersion.V2]: '0x5f73f128be76e397f5a3b56c94ca16883a8ee91b498bc0ee80473818318c05ac'
54
- }
52
+ [exports.ProtocolVersion.V1]: "0xccf29a0d8e860044a3d2f6a6e709f6572f77e4fe245fadd212fc342337048d60",
53
+ [exports.ProtocolVersion.V2]: "0x5f73f128be76e397f5a3b56c94ca16883a8ee91b498bc0ee80473818318c05ac",
54
+ },
55
55
  };
56
56
  // Dep Group Transaction Constants
57
57
  exports.DEP_GROUP_TX_HASH = {
58
58
  [NetworkType.Mainnet]: {
59
- [exports.ProtocolVersion.V2]: '0xfab07962ed7178ed88d450774e2a6ecd50bae856bdb9b692980be8c5147d1bfa'
59
+ [exports.ProtocolVersion.V2]: "0xfab07962ed7178ed88d450774e2a6ecd50bae856bdb9b692980be8c5147d1bfa",
60
60
  },
61
61
  [NetworkType.Testnet]: {
62
- [exports.ProtocolVersion.V1]: '0xc8fd44aba36f0c4b37536b6c7ea3b88df65fa97e02f77cd33b9bf20bf241a09b',
63
- [exports.ProtocolVersion.V2]: '0x469af0d961dcaaedd872968a9388b546717a6ccfa47b3165b3f9c981e9d66aaa'
64
- }
62
+ [exports.ProtocolVersion.V1]: "0xc8fd44aba36f0c4b37536b6c7ea3b88df65fa97e02f77cd33b9bf20bf241a09b",
63
+ [exports.ProtocolVersion.V2]: "0x469af0d961dcaaedd872968a9388b546717a6ccfa47b3165b3f9c981e9d66aaa",
64
+ },
65
65
  };
66
66
  // Deploy Transaction Constants
67
67
  exports.DEPLOY_TX_HASH = {
68
68
  [NetworkType.Mainnet]: {
69
69
  [exports.ProtocolVersion.V2]: {
70
- ckbfs: '0xc9b6698f44c3b80e7e1c48823b2714e432b93f0206ffaf9df885d23267ed2ebc',
71
- adler32: '0xc9b6698f44c3b80e7e1c48823b2714e432b93f0206ffaf9df885d23267ed2ebc'
72
- }
70
+ ckbfs: "0xc9b6698f44c3b80e7e1c48823b2714e432b93f0206ffaf9df885d23267ed2ebc",
71
+ adler32: "0xc9b6698f44c3b80e7e1c48823b2714e432b93f0206ffaf9df885d23267ed2ebc",
72
+ },
73
73
  },
74
74
  [NetworkType.Testnet]: {
75
75
  [exports.ProtocolVersion.V1]: {
76
- ckbfs: '0xde8eb09151fbcdcba398423159ce348cc89a38a736de3fd0960b18b084465382',
77
- adler32: '0x042f264d7397a181437b51ff9981cf536f252ab5740b61ce52ce31ada04ed54b'
76
+ ckbfs: "0xde8eb09151fbcdcba398423159ce348cc89a38a736de3fd0960b18b084465382",
77
+ adler32: "0x042f264d7397a181437b51ff9981cf536f252ab5740b61ce52ce31ada04ed54b",
78
78
  },
79
79
  [exports.ProtocolVersion.V2]: {
80
- ckbfs: '0x2c8c9ad3134743368b5a79977648f96c5bd0aba187021a72fb624301064d3616',
81
- adler32: '0x2c8c9ad3134743368b5a79977648f96c5bd0aba187021a72fb624301064d3616'
82
- }
83
- }
80
+ ckbfs: "0x2c8c9ad3134743368b5a79977648f96c5bd0aba187021a72fb624301064d3616",
81
+ adler32: "0x2c8c9ad3134743368b5a79977648f96c5bd0aba187021a72fb624301064d3616",
82
+ },
83
+ },
84
84
  };
85
85
  // Default values - V2 is now the default
86
86
  exports.DEFAULT_VERSION = exports.ProtocolVersion.V2;
@@ -97,8 +97,15 @@ function getCKBFSScriptConfig(network = exports.DEFAULT_NETWORK, version = expor
97
97
  codeHash: useTypeID
98
98
  ? exports.CKBFS_TYPE_ID[network][version]
99
99
  : exports.CKBFS_CODE_HASH[network][version],
100
- hashType: useTypeID ? 'type' : 'data1',
100
+ hashType: useTypeID ? "type" : "data1",
101
101
  depTxHash: exports.DEP_GROUP_TX_HASH[network][version],
102
- depIndex: 0
102
+ depIndex: 0,
103
103
  };
104
104
  }
105
+ const core_1 = require("@ckb-ccc/core");
106
+ class CKBFSScriptInfo extends core_1.ScriptInfo {
107
+ constructor(codeHash, hashType, cellDeps) {
108
+ super(codeHash, hashType, cellDeps);
109
+ }
110
+ }
111
+ exports.CKBFSScriptInfo = CKBFSScriptInfo;