@ckbfs/api 1.3.0 → 1.5.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/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; } });
@@ -62,26 +76,37 @@ class CKBFS {
62
76
  */
63
77
  constructor(signerOrPrivateKey, networkOrOptions = constants_1.DEFAULT_NETWORK, options) {
64
78
  // Determine if first parameter is a Signer or privateKey
65
- if (typeof signerOrPrivateKey === 'string') {
79
+ if (typeof signerOrPrivateKey === "string") {
66
80
  // Initialize with private key
67
81
  const privateKey = signerOrPrivateKey;
68
- const network = typeof networkOrOptions === 'string' ? networkOrOptions : constants_1.DEFAULT_NETWORK;
69
- const opts = options || (typeof networkOrOptions === 'object' ? networkOrOptions : {});
70
- const client = new core_1.ClientPublicTestnet();
82
+ const network = typeof networkOrOptions === "string"
83
+ ? networkOrOptions
84
+ : constants_1.DEFAULT_NETWORK;
85
+ const opts = options ||
86
+ (typeof networkOrOptions === "object" ? networkOrOptions : {});
87
+ const client = network === "mainnet"
88
+ ? new core_1.ClientPublicMainnet({
89
+ url: opts.rpcUrl,
90
+ })
91
+ : new core_1.ClientPublicTestnet({
92
+ url: opts.rpcUrl,
93
+ });
71
94
  this.signer = new core_1.SignerCkbPrivateKey(client, privateKey);
72
95
  this.network = network;
73
96
  this.chunkSize = opts.chunkSize || 30 * 1024;
74
97
  this.version = opts.version || constants_1.DEFAULT_VERSION;
75
98
  this.useTypeID = opts.useTypeID || false;
99
+ this.rpcUrl = opts.rpcUrl || client.url;
76
100
  }
77
101
  else {
78
102
  // Initialize with signer
79
103
  this.signer = signerOrPrivateKey;
80
- const opts = typeof networkOrOptions === 'object' ? networkOrOptions : {};
104
+ const opts = typeof networkOrOptions === "object" ? networkOrOptions : {};
81
105
  this.network = opts.network || constants_1.DEFAULT_NETWORK;
82
106
  this.chunkSize = opts.chunkSize || 30 * 1024;
83
107
  this.version = opts.version || constants_1.DEFAULT_VERSION;
84
108
  this.useTypeID = opts.useTypeID || false;
109
+ this.rpcUrl = opts.rpcUrl || this.signer.client.url;
85
110
  }
86
111
  }
87
112
  /**
@@ -136,9 +161,9 @@ class CKBFS {
136
161
  feeRate: options.feeRate,
137
162
  network: options.network || this.network,
138
163
  version: options.version || this.version,
139
- useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID
164
+ useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
140
165
  });
141
- console.log('Publish file tx:', tx.stringify());
166
+ console.log("Publish file tx:", tx.stringify());
142
167
  // Send the transaction
143
168
  const txHash = await this.signer.sendTransaction(tx);
144
169
  return (0, transaction_2.ensureHexPrefix)(txHash);
@@ -150,7 +175,7 @@ class CKBFS {
150
175
  * @returns Promise resolving to the transaction hash
151
176
  */
152
177
  async publishContent(content, options) {
153
- const contentBytes = typeof content === 'string' ? textEncoder.encode(content) : content;
178
+ const contentBytes = typeof content === "string" ? textEncoder.encode(content) : content;
154
179
  const contentChunks = [];
155
180
  for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
156
181
  contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
@@ -167,9 +192,9 @@ class CKBFS {
167
192
  feeRate: options.feeRate,
168
193
  network: options.network || this.network,
169
194
  version: options.version || this.version,
170
- useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID
195
+ useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
171
196
  });
172
- console.log('Publish content tx:', tx.stringify());
197
+ console.log("Publish content tx:", tx.stringify());
173
198
  const txHash = await this.signer.sendTransaction(tx);
174
199
  return (0, transaction_2.ensureHexPrefix)(txHash);
175
200
  }
@@ -193,9 +218,9 @@ class CKBFS {
193
218
  contentChunks,
194
219
  feeRate: options.feeRate,
195
220
  network: options.network || this.network,
196
- version: options.version || this.version
221
+ version: options.version || this.version,
197
222
  });
198
- console.log('Append file tx:', tx.stringify());
223
+ console.log("Append file tx:", tx.stringify());
199
224
  // Send the transaction
200
225
  const txHash = await this.signer.sendTransaction(tx);
201
226
  return (0, transaction_2.ensureHexPrefix)(txHash);
@@ -208,7 +233,7 @@ class CKBFS {
208
233
  * @returns Promise resolving to the transaction hash
209
234
  */
210
235
  async appendContent(content, ckbfsCell, options = {}) {
211
- const contentBytes = typeof content === 'string' ? textEncoder.encode(content) : content;
236
+ const contentBytes = typeof content === "string" ? textEncoder.encode(content) : content;
212
237
  const contentChunks = [];
213
238
  for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
214
239
  contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
@@ -218,10 +243,10 @@ class CKBFS {
218
243
  contentChunks,
219
244
  feeRate: options.feeRate,
220
245
  network: options.network || this.network,
221
- version: options.version || this.version
246
+ version: options.version || this.version,
222
247
  // No useTypeID option for append
223
248
  });
224
- console.log('Append content tx:', tx.stringify());
249
+ console.log("Append content tx:", tx.stringify());
225
250
  const txHash = await this.signer.sendTransaction(tx);
226
251
  return (0, transaction_2.ensureHexPrefix)(txHash);
227
252
  }
@@ -255,7 +280,7 @@ class CKBFS {
255
280
  feeRate: options.feeRate,
256
281
  network: options.network || this.network,
257
282
  version: options.version || this.version,
258
- useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID
283
+ useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
259
284
  });
260
285
  }
261
286
  /**
@@ -265,7 +290,7 @@ class CKBFS {
265
290
  * @returns Promise resolving to the unsigned transaction
266
291
  */
267
292
  async createPublishContentTransaction(content, options) {
268
- const contentBytes = typeof content === 'string' ? textEncoder.encode(content) : content;
293
+ const contentBytes = typeof content === "string" ? textEncoder.encode(content) : content;
269
294
  const contentChunks = [];
270
295
  for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
271
296
  contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
@@ -282,7 +307,7 @@ class CKBFS {
282
307
  feeRate: options.feeRate,
283
308
  network: options.network || this.network,
284
309
  version: options.version || this.version,
285
- useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID
310
+ useTypeID: options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
286
311
  });
287
312
  }
288
313
  /**
@@ -305,7 +330,7 @@ class CKBFS {
305
330
  contentChunks,
306
331
  feeRate: options.feeRate,
307
332
  network: options.network || this.network,
308
- version: options.version || this.version
333
+ version: options.version || this.version,
309
334
  });
310
335
  }
311
336
  /**
@@ -316,7 +341,7 @@ class CKBFS {
316
341
  * @returns Promise resolving to the unsigned transaction
317
342
  */
318
343
  async createAppendContentTransaction(content, ckbfsCell, options = {}) {
319
- const contentBytes = typeof content === 'string' ? textEncoder.encode(content) : content;
344
+ const contentBytes = typeof content === "string" ? textEncoder.encode(content) : content;
320
345
  const contentChunks = [];
321
346
  for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
322
347
  contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
@@ -326,7 +351,7 @@ class CKBFS {
326
351
  contentChunks,
327
352
  feeRate: options.feeRate,
328
353
  network: options.network || this.network,
329
- version: options.version || this.version
354
+ version: options.version || this.version,
330
355
  // No useTypeID option for append
331
356
  });
332
357
  }
@@ -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;
@@ -63,3 +63,182 @@ export declare function getFileContentFromChain(client: any, outPoint: {
63
63
  * @returns The path where the file was saved
64
64
  */
65
65
  export declare function saveFileFromChain(content: Uint8Array, ckbfsData: any, outputPath?: string): string;
66
+ /**
67
+ * Decodes content from a single CKBFS witness
68
+ * @param witnessHex The witness data in hex format (with or without 0x prefix)
69
+ * @returns Object containing the decoded content and metadata, or null if not a valid CKBFS witness
70
+ */
71
+ export declare function decodeWitnessContent(witnessHex: string): {
72
+ content: Uint8Array;
73
+ isValid: boolean;
74
+ } | null;
75
+ /**
76
+ * Decodes and combines content from multiple CKBFS witnesses
77
+ * @param witnessHexArray Array of witness data in hex format
78
+ * @param preserveOrder Whether to preserve the order of witnesses (default: true)
79
+ * @returns Combined content from all valid CKBFS witnesses
80
+ */
81
+ export declare function decodeMultipleWitnessContents(witnessHexArray: string[], preserveOrder?: boolean): Uint8Array;
82
+ /**
83
+ * Extracts complete file content from witnesses using specified indexes
84
+ * @param witnesses Array of all witnesses from a transaction
85
+ * @param indexes Array of witness indexes that contain CKBFS content
86
+ * @returns Combined content from the specified witness indexes
87
+ */
88
+ export declare function extractFileFromWitnesses(witnesses: string[], indexes: number[]): Uint8Array;
89
+ /**
90
+ * Decodes file content directly from witness data without blockchain queries
91
+ * @param witnessData Object containing witness information
92
+ * @returns Object containing the decoded file content and metadata
93
+ */
94
+ export declare function decodeFileFromWitnessData(witnessData: {
95
+ witnesses: string[];
96
+ indexes: number[] | number;
97
+ filename?: string;
98
+ contentType?: string;
99
+ }): {
100
+ content: Uint8Array;
101
+ filename?: string;
102
+ contentType?: string;
103
+ size: number;
104
+ };
105
+ /**
106
+ * Saves decoded file content directly from witness data
107
+ * @param witnessData Object containing witness information
108
+ * @param outputPath Optional path to save the file
109
+ * @returns The path where the file was saved
110
+ */
111
+ export declare function saveFileFromWitnessData(witnessData: {
112
+ witnesses: string[];
113
+ indexes: number[] | number;
114
+ filename?: string;
115
+ contentType?: string;
116
+ }, outputPath?: string): string;
117
+ /**
118
+ * Identifier types for CKBFS cells
119
+ */
120
+ export declare enum IdentifierType {
121
+ TypeID = "typeId",
122
+ OutPoint = "outPoint",
123
+ Unknown = "unknown"
124
+ }
125
+ /**
126
+ * Parsed identifier information
127
+ */
128
+ export interface ParsedIdentifier {
129
+ type: IdentifierType;
130
+ typeId?: string;
131
+ txHash?: string;
132
+ index?: number;
133
+ original: string;
134
+ }
135
+ /**
136
+ * Detects and parses different CKBFS identifier formats
137
+ * @param identifier The identifier string to parse
138
+ * @returns Parsed identifier information
139
+ */
140
+ export declare function parseIdentifier(identifier: string): ParsedIdentifier;
141
+ /**
142
+ * Retrieves complete file content from the blockchain using any supported identifier
143
+ * @param client The CKB client to use for blockchain queries
144
+ * @param identifier The identifier (TypeID hex, CKBFS TypeID URI, or CKBFS outPoint URI)
145
+ * @param options Optional configuration for network, version, and useTypeID
146
+ * @returns Promise resolving to the complete file content and metadata
147
+ */
148
+ export declare function getFileContentFromChainByIdentifier(client: any, identifier: string, options?: {
149
+ network?: "mainnet" | "testnet";
150
+ version?: string;
151
+ useTypeID?: boolean;
152
+ }): Promise<{
153
+ content: Uint8Array;
154
+ filename: string;
155
+ contentType: string;
156
+ checksum: number;
157
+ size: number;
158
+ backLinks: any[];
159
+ parsedId: ParsedIdentifier;
160
+ } | null>;
161
+ /**
162
+ * Retrieves complete file content from the blockchain using TypeID (legacy function)
163
+ * @param client The CKB client to use for blockchain queries
164
+ * @param typeId The TypeID (args) of the CKBFS cell
165
+ * @param options Optional configuration for network, version, and useTypeID
166
+ * @returns Promise resolving to the complete file content and metadata
167
+ */
168
+ export declare function getFileContentFromChainByTypeId(client: any, typeId: string, options?: {
169
+ network?: "mainnet" | "testnet";
170
+ version?: string;
171
+ useTypeID?: boolean;
172
+ }): Promise<{
173
+ content: Uint8Array;
174
+ filename: string;
175
+ contentType: string;
176
+ checksum: number;
177
+ size: number;
178
+ backLinks: any[];
179
+ } | null>;
180
+ /**
181
+ * Saves file content retrieved from blockchain by identifier to disk
182
+ * @param client The CKB client to use for blockchain queries
183
+ * @param identifier The identifier (TypeID hex, CKBFS TypeID URI, or CKBFS outPoint URI)
184
+ * @param outputPath Optional path to save the file (defaults to filename from CKBFS data)
185
+ * @param options Optional configuration for network, version, and useTypeID
186
+ * @returns Promise resolving to the path where the file was saved, or null if file not found
187
+ */
188
+ export declare function saveFileFromChainByIdentifier(client: any, identifier: string, outputPath?: string, options?: {
189
+ network?: "mainnet" | "testnet";
190
+ version?: string;
191
+ useTypeID?: boolean;
192
+ }): Promise<string | null>;
193
+ /**
194
+ * Saves file content retrieved from blockchain by TypeID to disk (legacy function)
195
+ * @param client The CKB client to use for blockchain queries
196
+ * @param typeId The TypeID (args) of the CKBFS cell
197
+ * @param outputPath Optional path to save the file (defaults to filename from CKBFS data)
198
+ * @param options Optional configuration for network, version, and useTypeID
199
+ * @returns Promise resolving to the path where the file was saved, or null if file not found
200
+ */
201
+ export declare function saveFileFromChainByTypeId(client: any, typeId: string, outputPath?: string, options?: {
202
+ network?: "mainnet" | "testnet";
203
+ version?: string;
204
+ useTypeID?: boolean;
205
+ }): Promise<string | null>;
206
+ /**
207
+ * Decodes file content directly from identifier using witness decoding (new method)
208
+ * @param client The CKB client to use for blockchain queries
209
+ * @param identifier The identifier (TypeID hex, CKBFS TypeID URI, or CKBFS outPoint URI)
210
+ * @param options Optional configuration for network, version, and useTypeID
211
+ * @returns Promise resolving to the decoded file content and metadata, or null if not found
212
+ */
213
+ export declare function decodeFileFromChainByIdentifier(client: any, identifier: string, options?: {
214
+ network?: "mainnet" | "testnet";
215
+ version?: string;
216
+ useTypeID?: boolean;
217
+ }): Promise<{
218
+ content: Uint8Array;
219
+ filename: string;
220
+ contentType: string;
221
+ checksum: number;
222
+ size: number;
223
+ backLinks: any[];
224
+ parsedId: ParsedIdentifier;
225
+ } | null>;
226
+ /**
227
+ * Decodes file content directly from TypeID using witness decoding (legacy function)
228
+ * @param client The CKB client to use for blockchain queries
229
+ * @param typeId The TypeID (args) of the CKBFS cell
230
+ * @param options Optional configuration for network, version, and useTypeID
231
+ * @returns Promise resolving to the decoded file content and metadata, or null if not found
232
+ */
233
+ export declare function decodeFileFromChainByTypeId(client: any, typeId: string, options?: {
234
+ network?: "mainnet" | "testnet";
235
+ version?: string;
236
+ useTypeID?: boolean;
237
+ }): Promise<{
238
+ content: Uint8Array;
239
+ filename: string;
240
+ contentType: string;
241
+ checksum: number;
242
+ size: number;
243
+ backLinks: any[];
244
+ } | null>;