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