@ckbfs/api 1.2.4 → 1.2.6
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 +40 -6
- 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 +317 -97
- 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/dist/utils/file.d.ts
CHANGED
@@ -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>;
|