@ckbfs/api 1.2.4 → 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/README.md +506 -74
- package/code.png +0 -0
- package/demo-output.txt +1 -0
- package/direct_direct_content_example.txt +1 -0
- package/dist/index.d.ts +55 -13
- package/dist/index.js +143 -18
- package/dist/utils/constants.d.ts +7 -3
- package/dist/utils/constants.js +41 -34
- package/dist/utils/file.d.ts +179 -0
- package/dist/utils/file.js +599 -31
- package/dist/utils/molecule.d.ts +3 -2
- package/dist/utils/molecule.js +22 -24
- package/dist/utils/transaction.d.ts +10 -4
- package/dist/utils/transaction.js +29 -27
- package/examples/example.txt +1 -0
- package/examples/identifier-test.ts +178 -0
- package/examples/index.ts +36 -24
- package/examples/publish.ts +39 -5
- package/examples/retrieve.ts +542 -77
- package/examples/witness-decode-demo.ts +190 -0
- package/identifier_direct_content_example.txt +1 -0
- package/package-lock.json +4978 -0
- package/package.json +3 -2
- package/src/index.ts +312 -96
- package/src/utils/constants.ts +77 -43
- package/src/utils/file.ts +864 -59
- package/src/utils/molecule.ts +41 -36
- package/src/utils/transaction.ts +172 -146
- package/traditional_direct_content_example.txt +1 -0
- package/typeid_direct_content_example.txt +1 -0
- package/.cursor/rules/typescript.mdc +0 -49
- package/ABC.LOGS +0 -1
- package/RFC.v2.md +0 -341
- package/append.txt +0 -1
- package/example.txt +0 -1
- package/publish-tx-hash-v1.txt +0 -1
- package/src/utils/createPublishTransaction +0 -24
- package/test-download.txt +0 -2
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ckbfs/api",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.5",
|
4
4
|
"description": "SDK for CKBFS protocol on CKB",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": "Code Monad<code@lab-11.org>",
|
@@ -15,7 +15,8 @@
|
|
15
15
|
"example": "ts-node examples/index.ts",
|
16
16
|
"example:publish": "ts-node examples/publish.ts",
|
17
17
|
"example:append": "ts-node examples/append.ts",
|
18
|
-
"example:retrieve": "ts-node examples/retrieve.ts"
|
18
|
+
"example:retrieve": "ts-node examples/retrieve.ts",
|
19
|
+
"example:witness-decode-demo": "ts-node examples/witness-decode-demo.ts"
|
19
20
|
},
|
20
21
|
"keywords": [
|
21
22
|
"ckb",
|
package/src/index.ts
CHANGED
@@ -1,20 +1,26 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
} from
|
1
|
+
import {
|
2
|
+
Script,
|
3
|
+
Signer,
|
4
|
+
Transaction,
|
5
|
+
ClientPublicTestnet,
|
6
|
+
SignerCkbPrivateKey,
|
7
|
+
} from "@ckb-ccc/core";
|
8
|
+
import {
|
9
|
+
calculateChecksum,
|
10
|
+
verifyChecksum,
|
11
|
+
updateChecksum,
|
12
|
+
verifyWitnessChecksum,
|
13
|
+
} from "./utils/checksum";
|
8
14
|
import {
|
9
15
|
createCKBFSCell,
|
10
|
-
createPublishTransaction,
|
11
|
-
createAppendTransaction,
|
12
|
-
publishCKBFS,
|
13
|
-
appendCKBFS,
|
16
|
+
createPublishTransaction as utilCreatePublishTransaction,
|
17
|
+
createAppendTransaction as utilCreateAppendTransaction,
|
18
|
+
publishCKBFS as utilPublishCKBFS,
|
19
|
+
appendCKBFS as utilAppendCKBFS,
|
14
20
|
CKBFSCellOptions,
|
15
21
|
PublishOptions,
|
16
|
-
AppendOptions
|
17
|
-
} from
|
22
|
+
AppendOptions,
|
23
|
+
} from "./utils/transaction";
|
18
24
|
import {
|
19
25
|
readFile,
|
20
26
|
readFileAsText,
|
@@ -24,15 +30,28 @@ import {
|
|
24
30
|
splitFileIntoChunks,
|
25
31
|
combineChunksToFile,
|
26
32
|
getFileContentFromChain,
|
27
|
-
saveFileFromChain
|
28
|
-
|
33
|
+
saveFileFromChain,
|
34
|
+
getFileContentFromChainByTypeId,
|
35
|
+
saveFileFromChainByTypeId,
|
36
|
+
decodeFileFromChainByTypeId,
|
37
|
+
getFileContentFromChainByIdentifier,
|
38
|
+
saveFileFromChainByIdentifier,
|
39
|
+
decodeFileFromChainByIdentifier,
|
40
|
+
parseIdentifier,
|
41
|
+
IdentifierType,
|
42
|
+
decodeWitnessContent,
|
43
|
+
decodeMultipleWitnessContents,
|
44
|
+
extractFileFromWitnesses,
|
45
|
+
decodeFileFromWitnessData,
|
46
|
+
saveFileFromWitnessData,
|
47
|
+
} from "./utils/file";
|
29
48
|
import {
|
30
49
|
createCKBFSWitness,
|
31
50
|
createTextCKBFSWitness,
|
32
51
|
extractCKBFSWitnessContent,
|
33
52
|
isCKBFSWitness,
|
34
|
-
createChunkedCKBFSWitnesses
|
35
|
-
} from
|
53
|
+
createChunkedCKBFSWitnesses,
|
54
|
+
} from "./utils/witness";
|
36
55
|
import {
|
37
56
|
CKBFSData,
|
38
57
|
BackLinkV1,
|
@@ -40,11 +59,12 @@ import {
|
|
40
59
|
CKBFSDataType,
|
41
60
|
BackLinkType,
|
42
61
|
CKBFS_HEADER,
|
43
|
-
CKBFS_HEADER_STRING
|
44
|
-
} from
|
62
|
+
CKBFS_HEADER_STRING,
|
63
|
+
} from "./utils/molecule";
|
45
64
|
import {
|
46
65
|
NetworkType,
|
47
66
|
ProtocolVersion,
|
67
|
+
ProtocolVersionType,
|
48
68
|
DEFAULT_NETWORK,
|
49
69
|
DEFAULT_VERSION,
|
50
70
|
CKBFS_CODE_HASH,
|
@@ -54,8 +74,12 @@ import {
|
|
54
74
|
DEP_GROUP_TX_HASH,
|
55
75
|
DEPLOY_TX_HASH,
|
56
76
|
getCKBFSScriptConfig,
|
57
|
-
CKBFSScriptConfig
|
58
|
-
} from
|
77
|
+
CKBFSScriptConfig,
|
78
|
+
} from "./utils/constants";
|
79
|
+
import { ensureHexPrefix } from "./utils/transaction";
|
80
|
+
|
81
|
+
// Helper to encode string to Uint8Array
|
82
|
+
const textEncoder = new TextEncoder();
|
59
83
|
|
60
84
|
/**
|
61
85
|
* Custom options for file publishing and appending
|
@@ -66,16 +90,35 @@ export interface FileOptions {
|
|
66
90
|
capacity?: bigint;
|
67
91
|
feeRate?: number;
|
68
92
|
network?: NetworkType;
|
69
|
-
version?:
|
93
|
+
version?: ProtocolVersionType;
|
70
94
|
useTypeID?: boolean;
|
71
95
|
}
|
72
96
|
|
97
|
+
/**
|
98
|
+
* Options required when publishing content directly (string or Uint8Array)
|
99
|
+
*/
|
100
|
+
export type PublishContentOptions = Omit<
|
101
|
+
FileOptions,
|
102
|
+
"capacity" | "contentType" | "filename"
|
103
|
+
> &
|
104
|
+
Required<Pick<FileOptions, "contentType" | "filename">> & {
|
105
|
+
capacity?: bigint;
|
106
|
+
};
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Options required when appending content directly (string or Uint8Array)
|
110
|
+
*/
|
111
|
+
export type AppendContentOptions = Omit<
|
112
|
+
FileOptions,
|
113
|
+
"contentType" | "filename" | "capacity"
|
114
|
+
> & { capacity?: bigint };
|
115
|
+
|
73
116
|
/**
|
74
117
|
* Configuration options for the CKBFS SDK
|
75
118
|
*/
|
76
119
|
export interface CKBFSOptions {
|
77
120
|
chunkSize?: number;
|
78
|
-
version?:
|
121
|
+
version?: ProtocolVersionType;
|
79
122
|
useTypeID?: boolean;
|
80
123
|
network?: NetworkType;
|
81
124
|
}
|
@@ -87,9 +130,9 @@ export class CKBFS {
|
|
87
130
|
private signer: Signer;
|
88
131
|
private chunkSize: number;
|
89
132
|
private network: NetworkType;
|
90
|
-
private version:
|
133
|
+
private version: ProtocolVersionType;
|
91
134
|
private useTypeID: boolean;
|
92
|
-
|
135
|
+
|
93
136
|
/**
|
94
137
|
* Creates a new CKBFS SDK instance
|
95
138
|
* @param signerOrPrivateKey The signer instance or CKB private key to use for signing transactions
|
@@ -99,15 +142,20 @@ export class CKBFS {
|
|
99
142
|
constructor(
|
100
143
|
signerOrPrivateKey: Signer | string,
|
101
144
|
networkOrOptions: NetworkType | CKBFSOptions = DEFAULT_NETWORK,
|
102
|
-
options?: CKBFSOptions
|
145
|
+
options?: CKBFSOptions,
|
103
146
|
) {
|
104
147
|
// Determine if first parameter is a Signer or privateKey
|
105
|
-
if (typeof signerOrPrivateKey ===
|
148
|
+
if (typeof signerOrPrivateKey === "string") {
|
106
149
|
// Initialize with private key
|
107
150
|
const privateKey = signerOrPrivateKey;
|
108
|
-
const network =
|
109
|
-
|
110
|
-
|
151
|
+
const network =
|
152
|
+
typeof networkOrOptions === "string"
|
153
|
+
? networkOrOptions
|
154
|
+
: DEFAULT_NETWORK;
|
155
|
+
const opts =
|
156
|
+
options ||
|
157
|
+
(typeof networkOrOptions === "object" ? networkOrOptions : {});
|
158
|
+
|
111
159
|
const client = new ClientPublicTestnet();
|
112
160
|
this.signer = new SignerCkbPrivateKey(client, privateKey);
|
113
161
|
this.network = network;
|
@@ -117,15 +165,15 @@ export class CKBFS {
|
|
117
165
|
} else {
|
118
166
|
// Initialize with signer
|
119
167
|
this.signer = signerOrPrivateKey;
|
120
|
-
const opts = typeof networkOrOptions ===
|
121
|
-
|
168
|
+
const opts = typeof networkOrOptions === "object" ? networkOrOptions : {};
|
169
|
+
|
122
170
|
this.network = opts.network || DEFAULT_NETWORK;
|
123
171
|
this.chunkSize = opts.chunkSize || 30 * 1024;
|
124
172
|
this.version = opts.version || DEFAULT_VERSION;
|
125
173
|
this.useTypeID = opts.useTypeID || false;
|
126
174
|
}
|
127
175
|
}
|
128
|
-
|
176
|
+
|
129
177
|
/**
|
130
178
|
* Gets the recommended address object for the signer
|
131
179
|
* @returns Promise resolving to the address object
|
@@ -133,7 +181,7 @@ export class CKBFS {
|
|
133
181
|
async getAddress() {
|
134
182
|
return this.signer.getRecommendedAddressObj();
|
135
183
|
}
|
136
|
-
|
184
|
+
|
137
185
|
/**
|
138
186
|
* Gets the lock script for the signer
|
139
187
|
* @returns Promise resolving to the lock script
|
@@ -142,7 +190,7 @@ export class CKBFS {
|
|
142
190
|
const address = await this.getAddress();
|
143
191
|
return address.script;
|
144
192
|
}
|
145
|
-
|
193
|
+
|
146
194
|
/**
|
147
195
|
* Gets the CKBFS script configuration for the current settings
|
148
196
|
* @returns The CKBFS script configuration
|
@@ -150,34 +198,37 @@ export class CKBFS {
|
|
150
198
|
getCKBFSConfig(): CKBFSScriptConfig {
|
151
199
|
return getCKBFSScriptConfig(this.network, this.version, this.useTypeID);
|
152
200
|
}
|
153
|
-
|
201
|
+
|
154
202
|
/**
|
155
203
|
* Publishes a file to CKBFS
|
156
204
|
* @param filePath The path to the file to publish
|
157
205
|
* @param options Options for publishing the file
|
158
206
|
* @returns Promise resolving to the transaction hash
|
159
207
|
*/
|
160
|
-
async publishFile(
|
208
|
+
async publishFile(
|
209
|
+
filePath: string,
|
210
|
+
options: FileOptions = {},
|
211
|
+
): Promise<string> {
|
161
212
|
// Read the file and split into chunks
|
162
213
|
const fileContent = readFileAsUint8Array(filePath);
|
163
214
|
const contentChunks = [];
|
164
|
-
|
215
|
+
|
165
216
|
for (let i = 0; i < fileContent.length; i += this.chunkSize) {
|
166
217
|
contentChunks.push(fileContent.slice(i, i + this.chunkSize));
|
167
218
|
}
|
168
|
-
|
219
|
+
|
169
220
|
// Get the lock script
|
170
221
|
const lock = await this.getLock();
|
171
|
-
|
222
|
+
|
172
223
|
// Determine content type if not provided
|
173
224
|
const contentType = options.contentType || getContentType(filePath);
|
174
|
-
|
225
|
+
|
175
226
|
// Use the filename from the path if not provided
|
176
227
|
const pathParts = filePath.split(/[\\\/]/);
|
177
228
|
const filename = options.filename || pathParts[pathParts.length - 1];
|
178
|
-
|
179
|
-
// Create and sign the transaction
|
180
|
-
const tx = await
|
229
|
+
|
230
|
+
// Create and sign the transaction using the utility function
|
231
|
+
const tx = await utilPublishCKBFS(this.signer, {
|
181
232
|
contentChunks,
|
182
233
|
contentType,
|
183
234
|
filename,
|
@@ -186,79 +237,162 @@ export class CKBFS {
|
|
186
237
|
feeRate: options.feeRate,
|
187
238
|
network: options.network || this.network,
|
188
239
|
version: options.version || this.version,
|
189
|
-
useTypeID:
|
240
|
+
useTypeID:
|
241
|
+
options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
|
190
242
|
});
|
191
243
|
|
192
|
-
console.log(
|
193
|
-
|
244
|
+
console.log("Publish file tx:", tx.stringify());
|
245
|
+
|
194
246
|
// Send the transaction
|
195
247
|
const txHash = await this.signer.sendTransaction(tx);
|
196
|
-
|
197
|
-
return txHash;
|
248
|
+
|
249
|
+
return ensureHexPrefix(txHash);
|
250
|
+
}
|
251
|
+
|
252
|
+
/**
|
253
|
+
* Publishes content (string or Uint8Array) directly to CKBFS
|
254
|
+
* @param content The content string or byte array to publish
|
255
|
+
* @param options Options for publishing the content (contentType and filename are required)
|
256
|
+
* @returns Promise resolving to the transaction hash
|
257
|
+
*/
|
258
|
+
async publishContent(
|
259
|
+
content: string | Uint8Array,
|
260
|
+
options: PublishContentOptions,
|
261
|
+
): Promise<string> {
|
262
|
+
const contentBytes =
|
263
|
+
typeof content === "string" ? textEncoder.encode(content) : content;
|
264
|
+
const contentChunks = [];
|
265
|
+
|
266
|
+
for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
|
267
|
+
contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
|
268
|
+
}
|
269
|
+
|
270
|
+
const lock = await this.getLock();
|
271
|
+
|
272
|
+
// Use provided contentType and filename (required)
|
273
|
+
const { contentType, filename } = options;
|
274
|
+
|
275
|
+
const tx = await utilPublishCKBFS(this.signer, {
|
276
|
+
contentChunks,
|
277
|
+
contentType,
|
278
|
+
filename,
|
279
|
+
lock,
|
280
|
+
capacity: options.capacity,
|
281
|
+
feeRate: options.feeRate,
|
282
|
+
network: options.network || this.network,
|
283
|
+
version: options.version || this.version,
|
284
|
+
useTypeID:
|
285
|
+
options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
|
286
|
+
});
|
287
|
+
|
288
|
+
console.log("Publish content tx:", tx.stringify());
|
289
|
+
|
290
|
+
const txHash = await this.signer.sendTransaction(tx);
|
291
|
+
return ensureHexPrefix(txHash);
|
198
292
|
}
|
199
|
-
|
293
|
+
|
200
294
|
/**
|
201
|
-
* Appends content to an existing CKBFS file
|
295
|
+
* Appends content from a file to an existing CKBFS file
|
202
296
|
* @param filePath The path to the file containing the content to append
|
203
297
|
* @param ckbfsCell The CKBFS cell to append to
|
204
298
|
* @param options Additional options for the append operation
|
205
299
|
* @returns Promise resolving to the transaction hash
|
206
300
|
*/
|
207
301
|
async appendFile(
|
208
|
-
filePath: string,
|
209
|
-
ckbfsCell: AppendOptions[
|
210
|
-
options: Omit<FileOptions,
|
302
|
+
filePath: string,
|
303
|
+
ckbfsCell: AppendOptions["ckbfsCell"],
|
304
|
+
options: Omit<FileOptions, "contentType" | "filename"> = {},
|
211
305
|
): Promise<string> {
|
212
306
|
// Read the file and split into chunks
|
213
307
|
const fileContent = readFileAsUint8Array(filePath);
|
214
308
|
const contentChunks = [];
|
215
|
-
|
309
|
+
|
216
310
|
for (let i = 0; i < fileContent.length; i += this.chunkSize) {
|
217
311
|
contentChunks.push(fileContent.slice(i, i + this.chunkSize));
|
218
312
|
}
|
219
|
-
|
220
|
-
// Create and sign the transaction
|
221
|
-
const tx = await
|
313
|
+
|
314
|
+
// Create and sign the transaction using the utility function
|
315
|
+
const tx = await utilAppendCKBFS(this.signer, {
|
222
316
|
ckbfsCell,
|
223
317
|
contentChunks,
|
224
318
|
feeRate: options.feeRate,
|
225
319
|
network: options.network || this.network,
|
226
|
-
version: options.version || this.version
|
320
|
+
version: options.version || this.version,
|
227
321
|
});
|
228
|
-
|
322
|
+
|
323
|
+
console.log("Append file tx:", tx.stringify());
|
324
|
+
|
229
325
|
// Send the transaction
|
230
326
|
const txHash = await this.signer.sendTransaction(tx);
|
231
|
-
|
232
|
-
return txHash;
|
327
|
+
|
328
|
+
return ensureHexPrefix(txHash);
|
233
329
|
}
|
234
|
-
|
330
|
+
|
331
|
+
/**
|
332
|
+
* Appends content (string or Uint8Array) directly to an existing CKBFS file
|
333
|
+
* @param content The content string or byte array to append
|
334
|
+
* @param ckbfsCell The CKBFS cell to append to
|
335
|
+
* @param options Additional options for the append operation
|
336
|
+
* @returns Promise resolving to the transaction hash
|
337
|
+
*/
|
338
|
+
async appendContent(
|
339
|
+
content: string | Uint8Array,
|
340
|
+
ckbfsCell: AppendOptions["ckbfsCell"],
|
341
|
+
options: AppendContentOptions = {},
|
342
|
+
): Promise<string> {
|
343
|
+
const contentBytes =
|
344
|
+
typeof content === "string" ? textEncoder.encode(content) : content;
|
345
|
+
const contentChunks = [];
|
346
|
+
|
347
|
+
for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
|
348
|
+
contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
|
349
|
+
}
|
350
|
+
|
351
|
+
const tx = await utilAppendCKBFS(this.signer, {
|
352
|
+
ckbfsCell,
|
353
|
+
contentChunks,
|
354
|
+
feeRate: options.feeRate,
|
355
|
+
network: options.network || this.network,
|
356
|
+
version: options.version || this.version,
|
357
|
+
// No useTypeID option for append
|
358
|
+
});
|
359
|
+
|
360
|
+
console.log("Append content tx:", tx.stringify());
|
361
|
+
|
362
|
+
const txHash = await this.signer.sendTransaction(tx);
|
363
|
+
return ensureHexPrefix(txHash);
|
364
|
+
}
|
365
|
+
|
235
366
|
/**
|
236
367
|
* Creates a new transaction for publishing a file but doesn't sign or send it
|
237
368
|
* @param filePath The path to the file to publish
|
238
369
|
* @param options Options for publishing the file
|
239
370
|
* @returns Promise resolving to the unsigned transaction
|
240
371
|
*/
|
241
|
-
async createPublishTransaction(
|
372
|
+
async createPublishTransaction(
|
373
|
+
filePath: string,
|
374
|
+
options: FileOptions = {},
|
375
|
+
): Promise<Transaction> {
|
242
376
|
// Read the file and split into chunks
|
243
377
|
const fileContent = readFileAsUint8Array(filePath);
|
244
378
|
const contentChunks = [];
|
245
|
-
|
379
|
+
|
246
380
|
for (let i = 0; i < fileContent.length; i += this.chunkSize) {
|
247
381
|
contentChunks.push(fileContent.slice(i, i + this.chunkSize));
|
248
382
|
}
|
249
|
-
|
383
|
+
|
250
384
|
// Get the lock script
|
251
385
|
const lock = await this.getLock();
|
252
|
-
|
386
|
+
|
253
387
|
// Determine content type if not provided
|
254
388
|
const contentType = options.contentType || getContentType(filePath);
|
255
|
-
|
389
|
+
|
256
390
|
// Use the filename from the path if not provided
|
257
391
|
const pathParts = filePath.split(/[\\\/]/);
|
258
392
|
const filename = options.filename || pathParts[pathParts.length - 1];
|
259
|
-
|
260
|
-
// Create the transaction
|
261
|
-
return
|
393
|
+
|
394
|
+
// Create the transaction using the utility function
|
395
|
+
return utilCreatePublishTransaction(this.signer, {
|
262
396
|
contentChunks,
|
263
397
|
contentType,
|
264
398
|
filename,
|
@@ -267,37 +401,105 @@ export class CKBFS {
|
|
267
401
|
feeRate: options.feeRate,
|
268
402
|
network: options.network || this.network,
|
269
403
|
version: options.version || this.version,
|
270
|
-
useTypeID:
|
404
|
+
useTypeID:
|
405
|
+
options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
|
271
406
|
});
|
272
407
|
}
|
273
|
-
|
408
|
+
|
274
409
|
/**
|
275
|
-
* Creates a new transaction for
|
410
|
+
* Creates a new transaction for publishing content (string or Uint8Array) directly, but doesn't sign or send it
|
411
|
+
* @param content The content string or byte array to publish
|
412
|
+
* @param options Options for publishing the content (contentType and filename are required)
|
413
|
+
* @returns Promise resolving to the unsigned transaction
|
414
|
+
*/
|
415
|
+
async createPublishContentTransaction(
|
416
|
+
content: string | Uint8Array,
|
417
|
+
options: PublishContentOptions,
|
418
|
+
): Promise<Transaction> {
|
419
|
+
const contentBytes =
|
420
|
+
typeof content === "string" ? textEncoder.encode(content) : content;
|
421
|
+
const contentChunks = [];
|
422
|
+
|
423
|
+
for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
|
424
|
+
contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
|
425
|
+
}
|
426
|
+
|
427
|
+
const lock = await this.getLock();
|
428
|
+
|
429
|
+
// Use provided contentType and filename (required)
|
430
|
+
const { contentType, filename } = options;
|
431
|
+
|
432
|
+
return utilCreatePublishTransaction(this.signer, {
|
433
|
+
contentChunks,
|
434
|
+
contentType,
|
435
|
+
filename,
|
436
|
+
lock,
|
437
|
+
capacity: options.capacity,
|
438
|
+
feeRate: options.feeRate,
|
439
|
+
network: options.network || this.network,
|
440
|
+
version: options.version || this.version,
|
441
|
+
useTypeID:
|
442
|
+
options.useTypeID !== undefined ? options.useTypeID : this.useTypeID,
|
443
|
+
});
|
444
|
+
}
|
445
|
+
|
446
|
+
/**
|
447
|
+
* Creates a new transaction for appending content from a file but doesn't sign or send it
|
276
448
|
* @param filePath The path to the file containing the content to append
|
277
449
|
* @param ckbfsCell The CKBFS cell to append to
|
278
450
|
* @param options Additional options for the append operation
|
279
451
|
* @returns Promise resolving to the unsigned transaction
|
280
452
|
*/
|
281
453
|
async createAppendTransaction(
|
282
|
-
filePath: string,
|
283
|
-
ckbfsCell: AppendOptions[
|
284
|
-
options: Omit<FileOptions,
|
454
|
+
filePath: string,
|
455
|
+
ckbfsCell: AppendOptions["ckbfsCell"],
|
456
|
+
options: Omit<FileOptions, "contentType" | "filename"> = {},
|
285
457
|
): Promise<Transaction> {
|
286
458
|
// Read the file and split into chunks
|
287
459
|
const fileContent = readFileAsUint8Array(filePath);
|
288
460
|
const contentChunks = [];
|
289
|
-
|
461
|
+
|
290
462
|
for (let i = 0; i < fileContent.length; i += this.chunkSize) {
|
291
463
|
contentChunks.push(fileContent.slice(i, i + this.chunkSize));
|
292
464
|
}
|
293
|
-
|
294
|
-
// Create the transaction
|
295
|
-
return
|
465
|
+
|
466
|
+
// Create the transaction using the utility function
|
467
|
+
return utilCreateAppendTransaction(this.signer, {
|
296
468
|
ckbfsCell,
|
297
469
|
contentChunks,
|
298
470
|
feeRate: options.feeRate,
|
299
471
|
network: options.network || this.network,
|
300
|
-
version: options.version || this.version
|
472
|
+
version: options.version || this.version,
|
473
|
+
});
|
474
|
+
}
|
475
|
+
|
476
|
+
/**
|
477
|
+
* Creates a new transaction for appending content (string or Uint8Array) directly, but doesn't sign or send it
|
478
|
+
* @param content The content string or byte array to append
|
479
|
+
* @param ckbfsCell The CKBFS cell to append to
|
480
|
+
* @param options Additional options for the append operation
|
481
|
+
* @returns Promise resolving to the unsigned transaction
|
482
|
+
*/
|
483
|
+
async createAppendContentTransaction(
|
484
|
+
content: string | Uint8Array,
|
485
|
+
ckbfsCell: AppendOptions["ckbfsCell"],
|
486
|
+
options: AppendContentOptions = {},
|
487
|
+
): Promise<Transaction> {
|
488
|
+
const contentBytes =
|
489
|
+
typeof content === "string" ? textEncoder.encode(content) : content;
|
490
|
+
const contentChunks = [];
|
491
|
+
|
492
|
+
for (let i = 0; i < contentBytes.length; i += this.chunkSize) {
|
493
|
+
contentChunks.push(contentBytes.slice(i, i + this.chunkSize));
|
494
|
+
}
|
495
|
+
|
496
|
+
return utilCreateAppendTransaction(this.signer, {
|
497
|
+
ckbfsCell,
|
498
|
+
contentChunks,
|
499
|
+
feeRate: options.feeRate,
|
500
|
+
network: options.network || this.network,
|
501
|
+
version: options.version || this.version,
|
502
|
+
// No useTypeID option for append
|
301
503
|
});
|
302
504
|
}
|
303
505
|
}
|
@@ -309,14 +511,14 @@ export {
|
|
309
511
|
verifyChecksum,
|
310
512
|
updateChecksum,
|
311
513
|
verifyWitnessChecksum,
|
312
|
-
|
313
|
-
// Transaction utilities
|
514
|
+
|
515
|
+
// Transaction utilities (Exporting original names from transaction.ts)
|
314
516
|
createCKBFSCell,
|
315
|
-
createPublishTransaction,
|
316
|
-
createAppendTransaction,
|
317
|
-
publishCKBFS,
|
318
|
-
appendCKBFS,
|
319
|
-
|
517
|
+
utilCreatePublishTransaction as createPublishTransaction,
|
518
|
+
utilCreateAppendTransaction as createAppendTransaction,
|
519
|
+
utilPublishCKBFS as publishCKBFS,
|
520
|
+
utilAppendCKBFS as appendCKBFS,
|
521
|
+
|
320
522
|
// File utilities
|
321
523
|
readFile,
|
322
524
|
readFileAsText,
|
@@ -327,33 +529,47 @@ export {
|
|
327
529
|
combineChunksToFile,
|
328
530
|
getFileContentFromChain,
|
329
531
|
saveFileFromChain,
|
330
|
-
|
532
|
+
getFileContentFromChainByTypeId,
|
533
|
+
saveFileFromChainByTypeId,
|
534
|
+
decodeFileFromChainByTypeId,
|
535
|
+
getFileContentFromChainByIdentifier,
|
536
|
+
saveFileFromChainByIdentifier,
|
537
|
+
decodeFileFromChainByIdentifier,
|
538
|
+
parseIdentifier,
|
539
|
+
IdentifierType,
|
540
|
+
decodeWitnessContent,
|
541
|
+
decodeMultipleWitnessContents,
|
542
|
+
extractFileFromWitnesses,
|
543
|
+
decodeFileFromWitnessData,
|
544
|
+
saveFileFromWitnessData,
|
545
|
+
|
331
546
|
// Witness utilities
|
332
547
|
createCKBFSWitness,
|
333
548
|
createTextCKBFSWitness,
|
334
549
|
extractCKBFSWitnessContent,
|
335
550
|
isCKBFSWitness,
|
336
551
|
createChunkedCKBFSWitnesses,
|
337
|
-
|
552
|
+
|
338
553
|
// Molecule definitions
|
339
554
|
CKBFSData,
|
340
555
|
BackLinkV1,
|
341
556
|
BackLinkV2,
|
342
|
-
|
557
|
+
|
343
558
|
// Types
|
344
559
|
CKBFSDataType,
|
345
560
|
BackLinkType,
|
346
561
|
CKBFSCellOptions,
|
347
562
|
PublishOptions,
|
348
563
|
AppendOptions,
|
349
|
-
|
564
|
+
|
350
565
|
// Constants
|
351
566
|
CKBFS_HEADER,
|
352
567
|
CKBFS_HEADER_STRING,
|
353
|
-
|
568
|
+
|
354
569
|
// CKBFS Protocol Constants & Configuration
|
355
570
|
NetworkType,
|
356
571
|
ProtocolVersion,
|
572
|
+
ProtocolVersionType,
|
357
573
|
DEFAULT_NETWORK,
|
358
574
|
DEFAULT_VERSION,
|
359
575
|
CKBFS_CODE_HASH,
|
@@ -363,5 +579,5 @@ export {
|
|
363
579
|
DEP_GROUP_TX_HASH,
|
364
580
|
DEPLOY_TX_HASH,
|
365
581
|
getCKBFSScriptConfig,
|
366
|
-
CKBFSScriptConfig
|
367
|
-
};
|
582
|
+
CKBFSScriptConfig,
|
583
|
+
};
|