@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.
Files changed (45) hide show
  1. package/README.md +31 -6
  2. package/RFC.v3.md +210 -0
  3. package/dist/index.d.ts +72 -7
  4. package/dist/index.js +437 -75
  5. package/dist/utils/checksum.d.ts +16 -0
  6. package/dist/utils/checksum.js +74 -8
  7. package/dist/utils/constants.d.ts +2 -1
  8. package/dist/utils/constants.js +12 -2
  9. package/dist/utils/file.d.ts +44 -0
  10. package/dist/utils/file.js +303 -30
  11. package/dist/utils/molecule.d.ts +13 -1
  12. package/dist/utils/molecule.js +32 -5
  13. package/dist/utils/transaction-backup.d.ts +117 -0
  14. package/dist/utils/transaction-backup.js +624 -0
  15. package/dist/utils/transaction.d.ts +7 -115
  16. package/dist/utils/transaction.js +45 -622
  17. package/dist/utils/transactions/index.d.ts +8 -0
  18. package/dist/utils/transactions/index.js +31 -0
  19. package/dist/utils/transactions/shared.d.ts +57 -0
  20. package/dist/utils/transactions/shared.js +17 -0
  21. package/dist/utils/transactions/v1v2.d.ts +80 -0
  22. package/dist/utils/transactions/v1v2.js +592 -0
  23. package/dist/utils/transactions/v3.d.ts +124 -0
  24. package/dist/utils/transactions/v3.js +369 -0
  25. package/dist/utils/witness.d.ts +45 -0
  26. package/dist/utils/witness.js +145 -3
  27. package/examples/append-v3.ts +310 -0
  28. package/examples/chunked-publish.ts +307 -0
  29. package/examples/publish-v3.ts +152 -0
  30. package/examples/publish.ts +4 -4
  31. package/examples/retrieve-v3.ts +222 -0
  32. package/package.json +6 -2
  33. package/small-example.txt +1 -0
  34. package/src/index.ts +568 -87
  35. package/src/utils/checksum.ts +90 -9
  36. package/src/utils/constants.ts +19 -2
  37. package/src/utils/file.ts +386 -35
  38. package/src/utils/molecule.ts +43 -6
  39. package/src/utils/transaction-backup.ts +849 -0
  40. package/src/utils/transaction.ts +39 -848
  41. package/src/utils/transactions/index.ts +16 -0
  42. package/src/utils/transactions/shared.ts +64 -0
  43. package/src/utils/transactions/v1v2.ts +791 -0
  44. package/src/utils/transactions/v3.ts +564 -0
  45. package/src/utils/witness.ts +193 -0
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Transaction utilities for all CKBFS protocol versions
3
+ */
4
+ export * from "./shared";
5
+ export * from "./v1v2";
6
+ export * from "./v3";
7
+ export { createCKBFSCell } from "./v1v2";
8
+ export { createCKBFSV3Cell } from "./v3";
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * Transaction utilities for all CKBFS protocol versions
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.createCKBFSV3Cell = exports.createCKBFSCell = void 0;
21
+ // Shared utilities and interfaces
22
+ __exportStar(require("./shared"), exports);
23
+ // V1 and V2 transaction utilities
24
+ __exportStar(require("./v1v2"), exports);
25
+ // V3 transaction utilities
26
+ __exportStar(require("./v3"), exports);
27
+ // Re-export for backward compatibility
28
+ var v1v2_1 = require("./v1v2");
29
+ Object.defineProperty(exports, "createCKBFSCell", { enumerable: true, get: function () { return v1v2_1.createCKBFSCell; } });
30
+ var v3_1 = require("./v3");
31
+ Object.defineProperty(exports, "createCKBFSV3Cell", { enumerable: true, get: function () { return v3_1.createCKBFSV3Cell; } });
@@ -0,0 +1,57 @@
1
+ import { Script, Transaction } from "@ckb-ccc/core";
2
+ import { CKBFSDataType } from "../molecule";
3
+ import { NetworkType, ProtocolVersionType } from "../constants";
4
+ /**
5
+ * Shared interfaces and utilities for transaction handling across all versions
6
+ */
7
+ /**
8
+ * Ensures a string is prefixed with '0x'
9
+ * @param value The string to ensure is hex prefixed
10
+ * @returns A hex prefixed string
11
+ */
12
+ export declare function ensureHexPrefix(value: string): `0x${string}`;
13
+ /**
14
+ * Base options for creating a CKBFS cell
15
+ */
16
+ export interface BaseCKBFSCellOptions {
17
+ contentType: string;
18
+ filename: string;
19
+ capacity?: bigint;
20
+ lock: Script;
21
+ network?: NetworkType;
22
+ version?: ProtocolVersionType;
23
+ useTypeID?: boolean;
24
+ }
25
+ /**
26
+ * Base options for publishing a file to CKBFS
27
+ */
28
+ export interface BasePublishOptions extends BaseCKBFSCellOptions {
29
+ contentChunks: Uint8Array[];
30
+ feeRate?: number;
31
+ from?: Transaction;
32
+ }
33
+ /**
34
+ * Base options for appending content to a CKBFS file
35
+ */
36
+ export interface BaseAppendOptions {
37
+ ckbfsCell: {
38
+ outPoint: {
39
+ txHash: string;
40
+ index: number;
41
+ };
42
+ data: CKBFSDataType;
43
+ type: Script;
44
+ lock: Script;
45
+ capacity: bigint;
46
+ };
47
+ contentChunks: Uint8Array[];
48
+ feeRate?: number;
49
+ network?: NetworkType;
50
+ version?: ProtocolVersionType;
51
+ from?: Transaction;
52
+ }
53
+ /**
54
+ * Common CKBFS cell creation options
55
+ */
56
+ export interface CKBFSCellOptions extends BaseCKBFSCellOptions {
57
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureHexPrefix = ensureHexPrefix;
4
+ /**
5
+ * Shared interfaces and utilities for transaction handling across all versions
6
+ */
7
+ /**
8
+ * Ensures a string is prefixed with '0x'
9
+ * @param value The string to ensure is hex prefixed
10
+ * @returns A hex prefixed string
11
+ */
12
+ function ensureHexPrefix(value) {
13
+ if (value.startsWith("0x")) {
14
+ return value;
15
+ }
16
+ return `0x${value}`;
17
+ }
@@ -0,0 +1,80 @@
1
+ import { ccc, Transaction, Signer } from "@ckb-ccc/core";
2
+ import { BasePublishOptions, BaseAppendOptions, CKBFSCellOptions } from "./shared";
3
+ /**
4
+ * V1 and V2 CKBFS transaction utilities
5
+ */
6
+ /**
7
+ * Options for publishing a file to CKBFS (V1/V2)
8
+ */
9
+ export interface PublishOptions extends BasePublishOptions {
10
+ }
11
+ /**
12
+ * Options for appending content to a CKBFS file (V1/V2)
13
+ */
14
+ export interface AppendOptions extends BaseAppendOptions {
15
+ }
16
+ /**
17
+ * Creates a CKBFS cell
18
+ * @param options Options for creating the CKBFS cell
19
+ * @returns The created cell output
20
+ */
21
+ export declare function createCKBFSCell(options: CKBFSCellOptions): {
22
+ lock: ccc.Script;
23
+ type: ccc.Script;
24
+ capacity: bigint;
25
+ };
26
+ /**
27
+ * Prepares a transaction for publishing a file to CKBFS without fee and change handling
28
+ * You will need to manually set the typeID if you did not provide inputs, or just check is return value emptyTypeID is true
29
+ * @param options Options for publishing the file
30
+ * @returns Promise resolving to the prepared transaction and the output index of CKBFS Cell
31
+ */
32
+ export declare function preparePublishTransaction(options: PublishOptions): Promise<{
33
+ tx: Transaction;
34
+ outputIndex: number;
35
+ emptyTypeID: boolean;
36
+ }>;
37
+ /**
38
+ * Creates a transaction for publishing a file to CKBFS
39
+ * @param signer The signer to use for the transaction
40
+ * @param options Options for publishing the file
41
+ * @returns Promise resolving to the created transaction
42
+ */
43
+ export declare function createPublishTransaction(signer: Signer, options: PublishOptions): Promise<Transaction>;
44
+ /**
45
+ * Prepares a transaction for appending content to a CKBFS file without fee and change handling
46
+ * @param options Options for appending content
47
+ * @returns Promise resolving to the prepared transaction and the output index of CKBFS Cell
48
+ */
49
+ export declare function prepareAppendTransaction(options: AppendOptions): Promise<{
50
+ tx: Transaction;
51
+ outputIndex: number;
52
+ }>;
53
+ /**
54
+ * Creates a transaction for appending content to a CKBFS file
55
+ * @param signer The signer to use for the transaction
56
+ * @param options Options for appending content
57
+ * @returns Promise resolving to the created transaction
58
+ */
59
+ export declare function createAppendTransaction(signer: Signer, options: AppendOptions): Promise<Transaction>;
60
+ /**
61
+ * Creates a complete transaction for publishing a file to CKBFS
62
+ * @param signer The signer to use for the transaction
63
+ * @param options Options for publishing the file
64
+ * @returns Promise resolving to the signed transaction
65
+ */
66
+ export declare function publishCKBFS(signer: Signer, options: PublishOptions): Promise<Transaction>;
67
+ /**
68
+ * Creates a transaction for appending content to a CKBFS file (dry run without fee completion)
69
+ * @param signer The signer to use for the transaction
70
+ * @param options Options for appending content
71
+ * @returns Promise resolving to the created transaction
72
+ */
73
+ export declare function createAppendTransactionDry(signer: Signer, options: AppendOptions): Promise<Transaction>;
74
+ /**
75
+ * Creates a complete transaction for appending content to a CKBFS file
76
+ * @param signer The signer to use for the transaction
77
+ * @param options Options for appending content
78
+ * @returns Promise resolving to the signed transaction
79
+ */
80
+ export declare function appendCKBFS(signer: Signer, options: AppendOptions): Promise<Transaction>;