@ckbfs/api 1.5.1 → 2.0.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 +31 -6
- package/RFC.v3.md +210 -0
- package/dist/index.d.ts +72 -7
- package/dist/index.js +437 -75
- package/dist/utils/checksum.d.ts +16 -0
- package/dist/utils/checksum.js +74 -8
- package/dist/utils/constants.d.ts +2 -1
- package/dist/utils/constants.js +12 -2
- package/dist/utils/file.d.ts +44 -0
- package/dist/utils/file.js +303 -30
- package/dist/utils/molecule.d.ts +13 -1
- package/dist/utils/molecule.js +32 -5
- package/dist/utils/transaction-backup.d.ts +117 -0
- package/dist/utils/transaction-backup.js +624 -0
- package/dist/utils/transaction.d.ts +7 -115
- package/dist/utils/transaction.js +45 -622
- package/dist/utils/transactions/index.d.ts +8 -0
- package/dist/utils/transactions/index.js +31 -0
- package/dist/utils/transactions/shared.d.ts +57 -0
- package/dist/utils/transactions/shared.js +17 -0
- package/dist/utils/transactions/v1v2.d.ts +80 -0
- package/dist/utils/transactions/v1v2.js +592 -0
- package/dist/utils/transactions/v3.d.ts +124 -0
- package/dist/utils/transactions/v3.js +369 -0
- package/dist/utils/witness.d.ts +45 -0
- package/dist/utils/witness.js +145 -3
- package/examples/append-v3.ts +310 -0
- package/examples/chunked-publish.ts +307 -0
- package/examples/publish-v3.ts +152 -0
- package/examples/publish.ts +4 -4
- package/examples/retrieve-v3.ts +222 -0
- package/package.json +6 -2
- package/small-example.txt +1 -0
- package/src/index.ts +568 -87
- package/src/utils/checksum.ts +90 -9
- package/src/utils/constants.ts +19 -2
- package/src/utils/file.ts +386 -35
- package/src/utils/molecule.ts +43 -6
- package/src/utils/transaction-backup.ts +849 -0
- package/src/utils/transaction.ts +39 -848
- package/src/utils/transactions/index.ts +16 -0
- package/src/utils/transactions/shared.ts +64 -0
- package/src/utils/transactions/v1v2.ts +791 -0
- package/src/utils/transactions/v3.ts +564 -0
- package/src/utils/witness.ts +193 -0
package/src/utils/molecule.ts
CHANGED
|
@@ -58,6 +58,17 @@ export const CKBFSDataV2 = molecule.table(
|
|
|
58
58
|
["indexes", "checksum", "contentType", "filename", "backLinks"],
|
|
59
59
|
);
|
|
60
60
|
|
|
61
|
+
// V3: CKBFSData has no backLinks (moved to witnesses)
|
|
62
|
+
export const CKBFSDataV3 = molecule.table(
|
|
63
|
+
{
|
|
64
|
+
index: number.Uint32,
|
|
65
|
+
checksum: number.Uint32,
|
|
66
|
+
contentType: blockchain.Bytes,
|
|
67
|
+
filename: blockchain.Bytes,
|
|
68
|
+
},
|
|
69
|
+
["index", "checksum", "contentType", "filename"],
|
|
70
|
+
);
|
|
71
|
+
|
|
61
72
|
// Type definitions for TypeScript
|
|
62
73
|
export type BackLinkTypeV1 = {
|
|
63
74
|
index: number;
|
|
@@ -79,14 +90,22 @@ export type BackLinkType = {
|
|
|
79
90
|
txHash: string;
|
|
80
91
|
};
|
|
81
92
|
|
|
82
|
-
//
|
|
93
|
+
// V3 specific type
|
|
94
|
+
export type CKBFSDataTypeV3 = {
|
|
95
|
+
index: number;
|
|
96
|
+
checksum: number;
|
|
97
|
+
contentType: string;
|
|
98
|
+
filename: string;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Combined CKBFSData type that works with all versions
|
|
83
102
|
export type CKBFSDataType = {
|
|
84
103
|
index?: number;
|
|
85
104
|
indexes?: number[];
|
|
86
105
|
checksum: number;
|
|
87
106
|
contentType: string;
|
|
88
107
|
filename: string;
|
|
89
|
-
backLinks
|
|
108
|
+
backLinks?: BackLinkType[];
|
|
90
109
|
};
|
|
91
110
|
|
|
92
111
|
// Helper function to get indexes array from data
|
|
@@ -131,14 +150,22 @@ export const CKBFSData = {
|
|
|
131
150
|
data: CKBFSDataType,
|
|
132
151
|
version: ProtocolVersionType = ProtocolVersion.V2,
|
|
133
152
|
): Uint8Array => {
|
|
134
|
-
if (version === ProtocolVersion.
|
|
153
|
+
if (version === ProtocolVersion.V3) {
|
|
154
|
+
// V3 formatting - no backLinks, uses single index
|
|
155
|
+
return CKBFSDataV3.pack({
|
|
156
|
+
index: getIndex(data),
|
|
157
|
+
checksum: data.checksum,
|
|
158
|
+
contentType: ccc.bytesFrom(data.contentType, "utf8"),
|
|
159
|
+
filename: ccc.bytesFrom(data.filename, "utf8"),
|
|
160
|
+
});
|
|
161
|
+
} else if (version === ProtocolVersion.V1) {
|
|
135
162
|
// V1 formatting - uses single index
|
|
136
163
|
return CKBFSDataV1.pack({
|
|
137
164
|
index: getIndex(data),
|
|
138
165
|
checksum: data.checksum,
|
|
139
166
|
contentType: ccc.bytesFrom(data.contentType, "utf8"),
|
|
140
167
|
filename: ccc.bytesFrom(data.filename, "utf8"),
|
|
141
|
-
backLinks: data.backLinks.map((bl) => {
|
|
168
|
+
backLinks: (data.backLinks || []).map((bl) => {
|
|
142
169
|
// Ensure txHash is in proper format for molecule encoding
|
|
143
170
|
const txHash =
|
|
144
171
|
typeof bl.txHash === "string"
|
|
@@ -159,7 +186,7 @@ export const CKBFSData = {
|
|
|
159
186
|
checksum: data.checksum,
|
|
160
187
|
contentType: ccc.bytesFrom(data.contentType, "utf8"),
|
|
161
188
|
filename: ccc.bytesFrom(data.filename, "utf8"),
|
|
162
|
-
backLinks: data.backLinks.map((bl) => {
|
|
189
|
+
backLinks: (data.backLinks || []).map((bl) => {
|
|
163
190
|
// Ensure txHash is in proper format for molecule encoding
|
|
164
191
|
const txHash = typeof bl.txHash === "string" ? bl.txHash : bl.txHash;
|
|
165
192
|
|
|
@@ -177,7 +204,17 @@ export const CKBFSData = {
|
|
|
177
204
|
version: ProtocolVersionType = ProtocolVersion.V2,
|
|
178
205
|
): CKBFSDataType => {
|
|
179
206
|
try {
|
|
180
|
-
if (version === ProtocolVersion.
|
|
207
|
+
if (version === ProtocolVersion.V3) {
|
|
208
|
+
// V3 format - no backLinks
|
|
209
|
+
const unpacked = CKBFSDataV3.unpack(buf);
|
|
210
|
+
return {
|
|
211
|
+
index: unpacked.index,
|
|
212
|
+
checksum: unpacked.checksum,
|
|
213
|
+
contentType: ccc.bytesTo(unpacked.contentType, "utf8"),
|
|
214
|
+
filename: ccc.bytesTo(unpacked.filename, "utf8"),
|
|
215
|
+
backLinks: [], // V3 has no backLinks in cell data
|
|
216
|
+
};
|
|
217
|
+
} else if (version === ProtocolVersion.V1) {
|
|
181
218
|
const unpacked = CKBFSDataV1.unpack(buf);
|
|
182
219
|
return {
|
|
183
220
|
index: unpacked.index,
|