@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/dist/utils/molecule.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { molecule, number } from "@ckb-lumos/codec";
|
|
2
|
+
import { ProtocolVersionType } from "./constants";
|
|
2
3
|
/**
|
|
3
4
|
* Molecule definitions for CKBFS data structures.
|
|
4
5
|
*/
|
|
@@ -70,8 +71,8 @@ export type CKBFSDataType = {
|
|
|
70
71
|
backLinks: BackLinkType[];
|
|
71
72
|
};
|
|
72
73
|
export declare const CKBFSData: {
|
|
73
|
-
pack: (data: CKBFSDataType, version?:
|
|
74
|
-
unpack: (buf: Uint8Array, version?:
|
|
74
|
+
pack: (data: CKBFSDataType, version?: ProtocolVersionType) => Uint8Array;
|
|
75
|
+
unpack: (buf: Uint8Array, version?: ProtocolVersionType) => CKBFSDataType;
|
|
75
76
|
};
|
|
76
77
|
export declare const CKBFS_HEADER: Uint8Array<ArrayBuffer>;
|
|
77
78
|
export declare const CKBFS_HEADER_STRING = "CKBFS";
|
package/dist/utils/molecule.js
CHANGED
|
@@ -45,13 +45,13 @@ exports.CKBFSDataV2 = codec_1.molecule.table({
|
|
|
45
45
|
function getIndexes(data) {
|
|
46
46
|
if (data.indexes)
|
|
47
47
|
return data.indexes;
|
|
48
|
-
if (typeof data.index ===
|
|
48
|
+
if (typeof data.index === "number")
|
|
49
49
|
return [data.index];
|
|
50
50
|
return [];
|
|
51
51
|
}
|
|
52
52
|
// Helper function to get single index from data
|
|
53
53
|
function getIndex(data) {
|
|
54
|
-
if (typeof data.index ===
|
|
54
|
+
if (typeof data.index === "number")
|
|
55
55
|
return data.index;
|
|
56
56
|
if (data.indexes && data.indexes.length > 0)
|
|
57
57
|
return data.indexes[0];
|
|
@@ -59,7 +59,7 @@ function getIndex(data) {
|
|
|
59
59
|
}
|
|
60
60
|
// Helper function to safely get either index or indexes from BackLinkType for V1
|
|
61
61
|
function getBackLinkIndex(bl) {
|
|
62
|
-
if (typeof bl.index ===
|
|
62
|
+
if (typeof bl.index === "number") {
|
|
63
63
|
return bl.index;
|
|
64
64
|
}
|
|
65
65
|
if (Array.isArray(bl.indexes) && bl.indexes.length > 0) {
|
|
@@ -72,7 +72,7 @@ function getBackLinkIndexes(bl) {
|
|
|
72
72
|
if (Array.isArray(bl.indexes)) {
|
|
73
73
|
return bl.indexes;
|
|
74
74
|
}
|
|
75
|
-
if (typeof bl.index ===
|
|
75
|
+
if (typeof bl.index === "number") {
|
|
76
76
|
return [bl.index];
|
|
77
77
|
}
|
|
78
78
|
return [0];
|
|
@@ -85,11 +85,11 @@ exports.CKBFSData = {
|
|
|
85
85
|
return exports.CKBFSDataV1.pack({
|
|
86
86
|
index: getIndex(data),
|
|
87
87
|
checksum: data.checksum,
|
|
88
|
-
contentType: core_1.ccc.bytesFrom(data.contentType,
|
|
89
|
-
filename: core_1.ccc.bytesFrom(data.filename,
|
|
90
|
-
backLinks: data.backLinks.map(bl => {
|
|
88
|
+
contentType: core_1.ccc.bytesFrom(data.contentType, "utf8"),
|
|
89
|
+
filename: core_1.ccc.bytesFrom(data.filename, "utf8"),
|
|
90
|
+
backLinks: data.backLinks.map((bl) => {
|
|
91
91
|
// Ensure txHash is in proper format for molecule encoding
|
|
92
|
-
const txHash = typeof bl.txHash ===
|
|
92
|
+
const txHash = typeof bl.txHash === "string"
|
|
93
93
|
? core_1.ccc.bytesFrom(bl.txHash)
|
|
94
94
|
: bl.txHash;
|
|
95
95
|
return {
|
|
@@ -105,13 +105,11 @@ exports.CKBFSData = {
|
|
|
105
105
|
return exports.CKBFSDataV2.pack({
|
|
106
106
|
indexes: getIndexes(data),
|
|
107
107
|
checksum: data.checksum,
|
|
108
|
-
contentType: core_1.ccc.bytesFrom(data.contentType,
|
|
109
|
-
filename: core_1.ccc.bytesFrom(data.filename,
|
|
110
|
-
backLinks: data.backLinks.map(bl => {
|
|
108
|
+
contentType: core_1.ccc.bytesFrom(data.contentType, "utf8"),
|
|
109
|
+
filename: core_1.ccc.bytesFrom(data.filename, "utf8"),
|
|
110
|
+
backLinks: data.backLinks.map((bl) => {
|
|
111
111
|
// Ensure txHash is in proper format for molecule encoding
|
|
112
|
-
const txHash = typeof bl.txHash ===
|
|
113
|
-
? bl.txHash
|
|
114
|
-
: bl.txHash;
|
|
112
|
+
const txHash = typeof bl.txHash === "string" ? bl.txHash : bl.txHash;
|
|
115
113
|
return {
|
|
116
114
|
indexes: getBackLinkIndexes(bl),
|
|
117
115
|
checksum: bl.checksum,
|
|
@@ -128,9 +126,9 @@ exports.CKBFSData = {
|
|
|
128
126
|
return {
|
|
129
127
|
index: unpacked.index,
|
|
130
128
|
checksum: unpacked.checksum,
|
|
131
|
-
contentType: core_1.ccc.bytesTo(unpacked.contentType,
|
|
132
|
-
filename: core_1.ccc.bytesTo(unpacked.filename,
|
|
133
|
-
backLinks: unpacked.backLinks.map(bl => ({
|
|
129
|
+
contentType: core_1.ccc.bytesTo(unpacked.contentType, "utf8"),
|
|
130
|
+
filename: core_1.ccc.bytesTo(unpacked.filename, "utf8"),
|
|
131
|
+
backLinks: unpacked.backLinks.map((bl) => ({
|
|
134
132
|
index: bl.index,
|
|
135
133
|
checksum: bl.checksum,
|
|
136
134
|
txHash: bl.txHash,
|
|
@@ -143,9 +141,9 @@ exports.CKBFSData = {
|
|
|
143
141
|
return {
|
|
144
142
|
indexes: unpacked.indexes,
|
|
145
143
|
checksum: unpacked.checksum,
|
|
146
|
-
contentType: core_1.ccc.bytesTo(unpacked.contentType,
|
|
147
|
-
filename: core_1.ccc.bytesTo(unpacked.filename,
|
|
148
|
-
backLinks: unpacked.backLinks.map(bl => ({
|
|
144
|
+
contentType: core_1.ccc.bytesTo(unpacked.contentType, "utf8"),
|
|
145
|
+
filename: core_1.ccc.bytesTo(unpacked.filename, "utf8"),
|
|
146
|
+
backLinks: unpacked.backLinks.map((bl) => ({
|
|
149
147
|
indexes: bl.indexes,
|
|
150
148
|
checksum: bl.checksum,
|
|
151
149
|
txHash: bl.txHash,
|
|
@@ -154,11 +152,11 @@ exports.CKBFSData = {
|
|
|
154
152
|
}
|
|
155
153
|
}
|
|
156
154
|
catch (error) {
|
|
157
|
-
console.error(
|
|
158
|
-
throw new Error(
|
|
155
|
+
console.error("Error unpacking CKBFSData:", error);
|
|
156
|
+
throw new Error("Failed to unpack CKBFSData: " + error);
|
|
159
157
|
}
|
|
160
|
-
}
|
|
158
|
+
},
|
|
161
159
|
};
|
|
162
160
|
// Constants for CKBFS protocol
|
|
163
|
-
exports.CKBFS_HEADER = new Uint8Array([0x43,
|
|
161
|
+
exports.CKBFS_HEADER = new Uint8Array([0x43, 0x4b, 0x42, 0x46, 0x53]); // "CKBFS" in ASCII
|
|
164
162
|
exports.CKBFS_HEADER_STRING = "CKBFS";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ccc, Transaction, Script, Signer } from "@ckb-ccc/core";
|
|
2
|
-
import { CKBFSDataType } from
|
|
3
|
-
import { NetworkType } from
|
|
2
|
+
import { CKBFSDataType } from "./molecule";
|
|
3
|
+
import { NetworkType, ProtocolVersionType } from "./constants";
|
|
4
4
|
/**
|
|
5
5
|
* Utility functions for CKB transaction creation and handling
|
|
6
6
|
*/
|
|
@@ -13,7 +13,7 @@ export interface CKBFSCellOptions {
|
|
|
13
13
|
capacity?: bigint;
|
|
14
14
|
lock: Script;
|
|
15
15
|
network?: NetworkType;
|
|
16
|
-
version?:
|
|
16
|
+
version?: ProtocolVersionType;
|
|
17
17
|
useTypeID?: boolean;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -22,6 +22,7 @@ export interface CKBFSCellOptions {
|
|
|
22
22
|
export interface PublishOptions extends CKBFSCellOptions {
|
|
23
23
|
contentChunks: Uint8Array[];
|
|
24
24
|
feeRate?: number;
|
|
25
|
+
from?: Transaction;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Options for appending content to a CKBFS file
|
|
@@ -40,7 +41,7 @@ export interface AppendOptions {
|
|
|
40
41
|
contentChunks: Uint8Array[];
|
|
41
42
|
feeRate?: number;
|
|
42
43
|
network?: NetworkType;
|
|
43
|
-
version?:
|
|
44
|
+
version?: ProtocolVersionType;
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* Ensures a string is prefixed with '0x'
|
|
@@ -58,6 +59,17 @@ export declare function createCKBFSCell(options: CKBFSCellOptions): {
|
|
|
58
59
|
type: ccc.Script;
|
|
59
60
|
capacity: bigint;
|
|
60
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Prepares a transaction for publishing a file to CKBFS without fee and change handling
|
|
64
|
+
* You will need to manually set the typeID if you did not provide inputs, or just check is return value emptyTypeID is true
|
|
65
|
+
* @param options Options for publishing the file
|
|
66
|
+
* @returns Promise resolving to the prepared transaction and the output index of CKBFS Cell
|
|
67
|
+
*/
|
|
68
|
+
export declare function preparePublishTransaction(options: PublishOptions): Promise<{
|
|
69
|
+
tx: Transaction;
|
|
70
|
+
outputIndex: number;
|
|
71
|
+
emptyTypeID: boolean;
|
|
72
|
+
}>;
|
|
61
73
|
/**
|
|
62
74
|
* Creates a transaction for publishing a file to CKBFS
|
|
63
75
|
* @param signer The signer to use for the transaction
|
|
@@ -72,6 +84,13 @@ export declare function createPublishTransaction(signer: Signer, options: Publis
|
|
|
72
84
|
* @returns Promise resolving to the created transaction
|
|
73
85
|
*/
|
|
74
86
|
export declare function createAppendTransaction(signer: Signer, options: AppendOptions): Promise<Transaction>;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a transaction for appending content to a CKBFS file
|
|
89
|
+
* @param signer The signer to use for the transaction
|
|
90
|
+
* @param options Options for appending content
|
|
91
|
+
* @returns Promise resolving to the created transaction
|
|
92
|
+
*/
|
|
93
|
+
export declare function createAppendTransactionDry(signer: Signer, options: AppendOptions): Promise<Transaction>;
|
|
75
94
|
/**
|
|
76
95
|
* Creates a complete transaction for publishing a file to CKBFS
|
|
77
96
|
* @param signer The signer to use for the transaction
|