@ckbfs/api 2.0.5 → 2.0.7
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/dist/index.d.ts +5 -2
- package/dist/index.js +4 -2
- package/dist/utils/constants.js +9 -0
- package/dist/utils/transactions/shared.d.ts +1 -0
- package/dist/utils/transactions/v3.d.ts +1 -0
- package/dist/utils/transactions/v3.js +3 -2
- package/examples/nervape.ts +18 -15
- package/package.json +1 -1
- package/src/index.ts +5 -0
- package/src/utils/constants.ts +16 -0
- package/src/utils/transactions/shared.ts +1 -0
- package/src/utils/transactions/v1v2.ts +2 -1
- package/src/utils/transactions/v3.ts +6 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Script, Signer, Transaction } from "@ckb-ccc/core";
|
|
2
2
|
import { calculateChecksum, verifyChecksum, updateChecksum, verifyWitnessChecksum, verifyV3WitnessChecksum, verifyV3WitnessChain } from "./utils/checksum";
|
|
3
|
-
import { createCKBFSCell, createPublishTransaction as utilCreatePublishTransaction, preparePublishTransaction, createAppendTransaction as utilCreateAppendTransaction, prepareAppendTransaction, createAppendTransactionDry, publishCKBFS as utilPublishCKBFS, appendCKBFS as utilAppendCKBFS, CKBFSCellOptions, PublishOptions, AppendOptions, AppendV3Options, TransferV3Options } from "./utils/transaction";
|
|
3
|
+
import { createCKBFSCell, createPublishTransaction as utilCreatePublishTransaction, preparePublishTransaction, createAppendTransaction as utilCreateAppendTransaction, prepareAppendTransaction, createAppendTransactionDry, publishCKBFS as utilPublishCKBFS, appendCKBFS as utilAppendCKBFS, CKBFSCellOptions, PublishOptions, AppendOptions, AppendV3Options, TransferV3Options, createAppendV3Transaction } from "./utils/transaction";
|
|
4
4
|
import { readFile, readFileAsText, readFileAsUint8Array, writeFile, getContentType, splitFileIntoChunks, combineChunksToFile, getFileContentFromChain, saveFileFromChain, getFileContentFromChainByTypeId, saveFileFromChainByTypeId, decodeFileFromChainByTypeId, getFileContentFromChainByIdentifier, saveFileFromChainByIdentifier, decodeFileFromChainByIdentifier, parseIdentifier, IdentifierType, decodeWitnessContent, decodeMultipleWitnessContents, extractFileFromWitnesses, decodeFileFromWitnessData, saveFileFromWitnessData, getFileContentFromChainV3, getFileContentFromChainByIdentifierV3, saveFileFromChainByIdentifierV3, resolveCKBFSCell } from "./utils/file";
|
|
5
5
|
import { createCKBFSWitness, createTextCKBFSWitness, extractCKBFSWitnessContent, isCKBFSWitness, createChunkedCKBFSWitnesses, createCKBFSV3Witness, createChunkedCKBFSV3Witnesses, extractCKBFSV3WitnessContent, isCKBFSV3Witness, CKBFSV3WitnessOptions } from "./utils/witness";
|
|
6
6
|
import { CKBFSData, BackLinkV1, BackLinkV2, CKBFSDataType, BackLinkType, CKBFS_HEADER, CKBFS_HEADER_STRING } from "./utils/molecule";
|
|
@@ -28,6 +28,7 @@ export type PublishContentOptions = Omit<FileOptions, "capacity" | "contentType"
|
|
|
28
28
|
*/
|
|
29
29
|
export type AppendContentOptions = Omit<FileOptions, "contentType" | "filename" | "capacity"> & {
|
|
30
30
|
capacity?: bigint;
|
|
31
|
+
witnessStartIndex?: number;
|
|
31
32
|
};
|
|
32
33
|
/**
|
|
33
34
|
* Configuration options for the CKBFS SDK
|
|
@@ -96,6 +97,7 @@ export declare class CKBFS {
|
|
|
96
97
|
previousTxHash?: string;
|
|
97
98
|
previousWitnessIndex?: number;
|
|
98
99
|
previousChecksum?: number;
|
|
100
|
+
witnessStartIndex?: number;
|
|
99
101
|
}): Promise<string>;
|
|
100
102
|
/**
|
|
101
103
|
* Appends content (string or Uint8Array) directly to an existing CKBFS file
|
|
@@ -130,6 +132,7 @@ export declare class CKBFS {
|
|
|
130
132
|
previousTxHash?: string;
|
|
131
133
|
previousWitnessIndex?: number;
|
|
132
134
|
previousChecksum?: number;
|
|
135
|
+
witnessStartIndex?: number;
|
|
133
136
|
}): Promise<Transaction>;
|
|
134
137
|
/**
|
|
135
138
|
* Creates a new transaction for appending content (string or Uint8Array) directly, but doesn't sign or send it
|
|
@@ -194,4 +197,4 @@ export declare class CKBFS {
|
|
|
194
197
|
*/
|
|
195
198
|
createPublishV3Transaction(filePath: string, options?: Omit<FileOptions, 'version'>): Promise<Transaction>;
|
|
196
199
|
}
|
|
197
|
-
export { calculateChecksum, verifyChecksum, updateChecksum, verifyWitnessChecksum, verifyV3WitnessChecksum, verifyV3WitnessChain, createCKBFSCell, utilCreatePublishTransaction as createPublishTransaction, preparePublishTransaction, utilCreateAppendTransaction as createAppendTransaction, prepareAppendTransaction, utilPublishCKBFS as publishCKBFS, utilAppendCKBFS as appendCKBFS, createAppendTransactionDry, readFile, readFileAsText, readFileAsUint8Array, writeFile, getContentType, splitFileIntoChunks, combineChunksToFile, getFileContentFromChain, saveFileFromChain, getFileContentFromChainByTypeId, saveFileFromChainByTypeId, decodeFileFromChainByTypeId, getFileContentFromChainByIdentifier, saveFileFromChainByIdentifier, decodeFileFromChainByIdentifier, parseIdentifier, IdentifierType, decodeWitnessContent, decodeMultipleWitnessContents, extractFileFromWitnesses, decodeFileFromWitnessData, saveFileFromWitnessData, getFileContentFromChainV3, getFileContentFromChainByIdentifierV3, saveFileFromChainByIdentifierV3, createCKBFSWitness, createTextCKBFSWitness, extractCKBFSWitnessContent, isCKBFSWitness, createChunkedCKBFSWitnesses, createCKBFSV3Witness, createChunkedCKBFSV3Witnesses, extractCKBFSV3WitnessContent, isCKBFSV3Witness, resolveCKBFSCell, CKBFSV3WitnessOptions, CKBFSData, BackLinkV1, BackLinkV2, CKBFSDataType, BackLinkType, CKBFSCellOptions, PublishOptions, AppendOptions, CKBFS_HEADER, CKBFS_HEADER_STRING, NetworkType, ProtocolVersion, ProtocolVersionType, DEFAULT_NETWORK, DEFAULT_VERSION, CKBFS_CODE_HASH, CKBFS_TYPE_ID, ADLER32_CODE_HASH, ADLER32_TYPE_ID, DEP_GROUP_TX_HASH, DEPLOY_TX_HASH, getCKBFSScriptConfig, CKBFSScriptConfig, };
|
|
200
|
+
export { calculateChecksum, verifyChecksum, updateChecksum, verifyWitnessChecksum, verifyV3WitnessChecksum, verifyV3WitnessChain, createCKBFSCell, utilCreatePublishTransaction as createPublishTransaction, preparePublishTransaction, utilCreateAppendTransaction as createAppendTransaction, prepareAppendTransaction, utilPublishCKBFS as publishCKBFS, utilAppendCKBFS as appendCKBFS, createAppendTransactionDry, createAppendV3Transaction, readFile, readFileAsText, readFileAsUint8Array, writeFile, getContentType, splitFileIntoChunks, combineChunksToFile, getFileContentFromChain, saveFileFromChain, getFileContentFromChainByTypeId, saveFileFromChainByTypeId, decodeFileFromChainByTypeId, getFileContentFromChainByIdentifier, saveFileFromChainByIdentifier, decodeFileFromChainByIdentifier, parseIdentifier, IdentifierType, decodeWitnessContent, decodeMultipleWitnessContents, extractFileFromWitnesses, decodeFileFromWitnessData, saveFileFromWitnessData, getFileContentFromChainV3, getFileContentFromChainByIdentifierV3, saveFileFromChainByIdentifierV3, createCKBFSWitness, createTextCKBFSWitness, extractCKBFSWitnessContent, isCKBFSWitness, createChunkedCKBFSWitnesses, createCKBFSV3Witness, createChunkedCKBFSV3Witnesses, extractCKBFSV3WitnessContent, isCKBFSV3Witness, resolveCKBFSCell, CKBFSV3WitnessOptions, CKBFSData, BackLinkV1, BackLinkV2, CKBFSDataType, BackLinkType, CKBFSCellOptions, PublishOptions, AppendOptions, CKBFS_HEADER, CKBFS_HEADER_STRING, NetworkType, ProtocolVersion, ProtocolVersionType, DEFAULT_NETWORK, DEFAULT_VERSION, CKBFS_CODE_HASH, CKBFS_TYPE_ID, ADLER32_CODE_HASH, ADLER32_TYPE_ID, DEP_GROUP_TX_HASH, DEPLOY_TX_HASH, getCKBFSScriptConfig, CKBFSScriptConfig, };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.getCKBFSScriptConfig = exports.DEPLOY_TX_HASH = exports.DEP_GROUP_TX_HASH = exports.ADLER32_TYPE_ID = exports.ADLER32_CODE_HASH = exports.CKBFS_TYPE_ID = exports.CKBFS_CODE_HASH = exports.DEFAULT_VERSION = exports.DEFAULT_NETWORK = exports.ProtocolVersion = exports.NetworkType = exports.CKBFS_HEADER_STRING = exports.CKBFS_HEADER = exports.BackLinkV2 = exports.BackLinkV1 = exports.CKBFSData = void 0;
|
|
3
|
+
exports.isCKBFSV3Witness = exports.extractCKBFSV3WitnessContent = exports.createChunkedCKBFSV3Witnesses = exports.createCKBFSV3Witness = exports.createChunkedCKBFSWitnesses = exports.isCKBFSWitness = exports.extractCKBFSWitnessContent = exports.createTextCKBFSWitness = exports.createCKBFSWitness = exports.saveFileFromChainByIdentifierV3 = exports.getFileContentFromChainByIdentifierV3 = exports.getFileContentFromChainV3 = exports.saveFileFromWitnessData = exports.decodeFileFromWitnessData = exports.extractFileFromWitnesses = exports.decodeMultipleWitnessContents = exports.decodeWitnessContent = exports.IdentifierType = exports.parseIdentifier = exports.decodeFileFromChainByIdentifier = exports.saveFileFromChainByIdentifier = exports.getFileContentFromChainByIdentifier = exports.decodeFileFromChainByTypeId = exports.saveFileFromChainByTypeId = exports.getFileContentFromChainByTypeId = exports.saveFileFromChain = exports.getFileContentFromChain = exports.combineChunksToFile = exports.splitFileIntoChunks = exports.getContentType = exports.writeFile = exports.readFileAsUint8Array = exports.readFileAsText = exports.readFile = exports.createAppendV3Transaction = exports.createAppendTransactionDry = exports.appendCKBFS = exports.publishCKBFS = exports.prepareAppendTransaction = exports.createAppendTransaction = exports.preparePublishTransaction = exports.createPublishTransaction = exports.createCKBFSCell = exports.verifyV3WitnessChain = exports.verifyV3WitnessChecksum = exports.verifyWitnessChecksum = exports.updateChecksum = exports.verifyChecksum = exports.calculateChecksum = exports.CKBFS = void 0;
|
|
4
|
+
exports.getCKBFSScriptConfig = exports.DEPLOY_TX_HASH = exports.DEP_GROUP_TX_HASH = exports.ADLER32_TYPE_ID = exports.ADLER32_CODE_HASH = exports.CKBFS_TYPE_ID = exports.CKBFS_CODE_HASH = exports.DEFAULT_VERSION = exports.DEFAULT_NETWORK = exports.ProtocolVersion = exports.NetworkType = exports.CKBFS_HEADER_STRING = exports.CKBFS_HEADER = exports.BackLinkV2 = exports.BackLinkV1 = exports.CKBFSData = exports.resolveCKBFSCell = void 0;
|
|
5
5
|
const core_1 = require("@ckb-ccc/core");
|
|
6
6
|
const checksum_1 = require("./utils/checksum");
|
|
7
7
|
Object.defineProperty(exports, "calculateChecksum", { enumerable: true, get: function () { return checksum_1.calculateChecksum; } });
|
|
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "prepareAppendTransaction", { enumerable: true, g
|
|
|
19
19
|
Object.defineProperty(exports, "createAppendTransactionDry", { enumerable: true, get: function () { return transaction_1.createAppendTransactionDry; } });
|
|
20
20
|
Object.defineProperty(exports, "publishCKBFS", { enumerable: true, get: function () { return transaction_1.publishCKBFS; } });
|
|
21
21
|
Object.defineProperty(exports, "appendCKBFS", { enumerable: true, get: function () { return transaction_1.appendCKBFS; } });
|
|
22
|
+
Object.defineProperty(exports, "createAppendV3Transaction", { enumerable: true, get: function () { return transaction_1.createAppendV3Transaction; } });
|
|
22
23
|
const file_1 = require("./utils/file");
|
|
23
24
|
Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return file_1.readFile; } });
|
|
24
25
|
Object.defineProperty(exports, "readFileAsText", { enumerable: true, get: function () { return file_1.readFileAsText; } });
|
|
@@ -478,6 +479,7 @@ class CKBFS {
|
|
|
478
479
|
previousTxHash: options.previousTxHash,
|
|
479
480
|
previousWitnessIndex: options.previousWitnessIndex,
|
|
480
481
|
previousChecksum: options.previousChecksum,
|
|
482
|
+
witnessStartIndex: options.witnessStartIndex,
|
|
481
483
|
});
|
|
482
484
|
}
|
|
483
485
|
else {
|
package/dist/utils/constants.js
CHANGED
|
@@ -20,6 +20,7 @@ exports.ProtocolVersion = {
|
|
|
20
20
|
exports.CKBFS_CODE_HASH = {
|
|
21
21
|
[NetworkType.Mainnet]: {
|
|
22
22
|
[exports.ProtocolVersion.V2]: "0x31e6376287d223b8c0410d562fb422f04d1d617b2947596a14c3d2efb7218d3a",
|
|
23
|
+
[exports.ProtocolVersion.V3]: "0xb5d13ffe0547c78021c01fe24dce2e959a1ed8edbca3cb93dd2e9f57fb56d695",
|
|
23
24
|
},
|
|
24
25
|
[NetworkType.Testnet]: {
|
|
25
26
|
[exports.ProtocolVersion.V1]: "0xe8905ad29a02cf8befa9c258f4f941773839a618d75a64afc22059de9413f712",
|
|
@@ -30,6 +31,7 @@ exports.CKBFS_CODE_HASH = {
|
|
|
30
31
|
exports.CKBFS_TYPE_ID = {
|
|
31
32
|
[NetworkType.Mainnet]: {
|
|
32
33
|
[exports.ProtocolVersion.V2]: "0xfd2058c9a0c0183354cf637e25d2707ffa9bb6fa2ba9b29f4ebc6be3e54ad7eb",
|
|
34
|
+
[exports.ProtocolVersion.V3]: "0xcc5411e8b70e551d7a3dd806256533cff6bc12118b48dd7b2d5d2292c3651add",
|
|
33
35
|
},
|
|
34
36
|
[NetworkType.Testnet]: {
|
|
35
37
|
[exports.ProtocolVersion.V1]: "0x88ef4d436af35684a27edda0d44dd8771318330285f90f02d13606e095aea86f",
|
|
@@ -41,6 +43,7 @@ exports.CKBFS_TYPE_ID = {
|
|
|
41
43
|
exports.ADLER32_CODE_HASH = {
|
|
42
44
|
[NetworkType.Mainnet]: {
|
|
43
45
|
[exports.ProtocolVersion.V2]: "0x2138683f76944437c0c643664120d620bdb5858dd6c9d1d156805e279c2c536f",
|
|
46
|
+
[exports.ProtocolVersion.V3]: "0xbd944c8c5aa127270b591d50ab899c9a2a3e4429300db4ea3d7523aa592c1db1",
|
|
44
47
|
},
|
|
45
48
|
[NetworkType.Testnet]: {
|
|
46
49
|
[exports.ProtocolVersion.V1]: "0x8af42cd329cf1bcffb4c73b48252e99cb32346fdbc1cdaa5ae1d000232d47e84",
|
|
@@ -51,6 +54,7 @@ exports.ADLER32_CODE_HASH = {
|
|
|
51
54
|
exports.ADLER32_TYPE_ID = {
|
|
52
55
|
[NetworkType.Mainnet]: {
|
|
53
56
|
[exports.ProtocolVersion.V2]: "0x641c01d590833a3f5471bd441651d9f2a8a200141949cdfeef2d68d8094c5876",
|
|
57
|
+
[exports.ProtocolVersion.V3]: "0x01b150adbbcba724a3917aefec6453ce4dbf70072d31ad42d0f3429ea32c692b",
|
|
54
58
|
},
|
|
55
59
|
[NetworkType.Testnet]: {
|
|
56
60
|
[exports.ProtocolVersion.V1]: "0xccf29a0d8e860044a3d2f6a6e709f6572f77e4fe245fadd212fc342337048d60",
|
|
@@ -62,6 +66,7 @@ exports.ADLER32_TYPE_ID = {
|
|
|
62
66
|
exports.DEP_GROUP_TX_HASH = {
|
|
63
67
|
[NetworkType.Mainnet]: {
|
|
64
68
|
[exports.ProtocolVersion.V2]: "0xfab07962ed7178ed88d450774e2a6ecd50bae856bdb9b692980be8c5147d1bfa",
|
|
69
|
+
[exports.ProtocolVersion.V3]: "0x03deba7f8206c81981d6f6a2d61b67dde75b4df91cbcfaf2e2fb041ba50c4719",
|
|
65
70
|
},
|
|
66
71
|
[NetworkType.Testnet]: {
|
|
67
72
|
[exports.ProtocolVersion.V1]: "0xc8fd44aba36f0c4b37536b6c7ea3b88df65fa97e02f77cd33b9bf20bf241a09b",
|
|
@@ -76,6 +81,10 @@ exports.DEPLOY_TX_HASH = {
|
|
|
76
81
|
ckbfs: "0xc9b6698f44c3b80e7e1c48823b2714e432b93f0206ffaf9df885d23267ed2ebc",
|
|
77
82
|
adler32: "0xc9b6698f44c3b80e7e1c48823b2714e432b93f0206ffaf9df885d23267ed2ebc",
|
|
78
83
|
},
|
|
84
|
+
[exports.ProtocolVersion.V3]: {
|
|
85
|
+
ckbfs: "0xd25f2c32f56c28c630d4f91955f1b3c9cd53e26fa0745d540d934e8e3d3c2853",
|
|
86
|
+
adler32: "0xd25f2c32f56c28c630d4f91955f1b3c9cd53e26fa0745d540d934e8e3d3c2853",
|
|
87
|
+
},
|
|
79
88
|
},
|
|
80
89
|
[NetworkType.Testnet]: {
|
|
81
90
|
[exports.ProtocolVersion.V1]: {
|
|
@@ -217,12 +217,12 @@ async function createPublishV3Transaction(signer, options) {
|
|
|
217
217
|
* @returns Promise resolving to the prepared transaction and the output index of CKBFS Cell
|
|
218
218
|
*/
|
|
219
219
|
async function prepareAppendV3Transaction(options) {
|
|
220
|
-
const { from, ckbfsCell, contentChunks, network = constants_1.DEFAULT_NETWORK, previousTxHash, previousWitnessIndex, previousChecksum, } = options;
|
|
220
|
+
const { from, ckbfsCell, contentChunks, network = constants_1.DEFAULT_NETWORK, previousTxHash, previousWitnessIndex, previousChecksum, witnessStartIndex, } = options;
|
|
221
221
|
// Calculate new checksum by updating from previous checksum
|
|
222
222
|
const combinedContent = Buffer.concat(contentChunks);
|
|
223
223
|
const newChecksum = await (0, checksum_1.updateChecksum)(previousChecksum, combinedContent);
|
|
224
224
|
// Calculate the actual witness indices where our content is placed
|
|
225
|
-
const contentStartIndex = from?.witnesses.length ||
|
|
225
|
+
const contentStartIndex = witnessStartIndex || from?.witnesses.length || 0;
|
|
226
226
|
// Create CKBFS v3 witnesses with backlink info
|
|
227
227
|
const ckbfsWitnesses = (0, witness_1.createChunkedCKBFSV3Witnesses)(contentChunks, {
|
|
228
228
|
previousTxHash,
|
|
@@ -350,6 +350,7 @@ async function createAppendV3Transaction(signer, options) {
|
|
|
350
350
|
// Add more inputs to cover the increased capacity
|
|
351
351
|
await preTx.completeInputsByCapacity(signer);
|
|
352
352
|
}
|
|
353
|
+
await preTx.completeInputsByCapacity(signer);
|
|
353
354
|
const witnesses = [];
|
|
354
355
|
// add empty witness for signer if ckbfs's lock is the same as signer's lock
|
|
355
356
|
if (address.script.hash() === lock.hash()) {
|
package/examples/nervape.ts
CHANGED
|
@@ -18,7 +18,10 @@ import {
|
|
|
18
18
|
ClientPublicTestnet,
|
|
19
19
|
ClientPublicMainnet,
|
|
20
20
|
Transaction,
|
|
21
|
-
ccc
|
|
21
|
+
ccc,
|
|
22
|
+
SignerCkbPrivateKey,
|
|
23
|
+
fixedPointFrom,
|
|
24
|
+
Signer
|
|
22
25
|
} from "@ckb-ccc/core";
|
|
23
26
|
import {
|
|
24
27
|
transferSpore
|
|
@@ -30,7 +33,7 @@ const client = new ClientPublicTestnet()
|
|
|
30
33
|
|
|
31
34
|
export const TestnetTraceLockDep = {
|
|
32
35
|
outPoint: {
|
|
33
|
-
txHash: "
|
|
36
|
+
txHash: "0x7a3e492188438ca4b260fed0f7a00d18ec9e4671a8c3b54fc2b3b49447ab2e2f",
|
|
34
37
|
index: 0x0,
|
|
35
38
|
},
|
|
36
39
|
depType: "code",
|
|
@@ -66,7 +69,7 @@ const ShadowDep = TestnetShadowDep
|
|
|
66
69
|
|
|
67
70
|
const TraceLogCodeHash = "0xbd7e56daaa4cc9ecf488a50d2f4db2a55a7c86eb2df2157d24a62be9be5b34ab"
|
|
68
71
|
const ShadowSporeCodeHash = "0x6361d4b20d845953d9c9431bbba08905573005a71e2a2432e7e0e7c685666f24"
|
|
69
|
-
const CKB_PRIVATE_KEY = "
|
|
72
|
+
const CKB_PRIVATE_KEY = "0x620ab1e4273b937032380e9f851c3119427ba965805bebcdce60a4494fd3074d"
|
|
70
73
|
|
|
71
74
|
const ckbfs = new CKBFS(
|
|
72
75
|
CKB_PRIVATE_KEY,
|
|
@@ -161,19 +164,17 @@ export async function giveName(name: string, ckbfsId: string) {
|
|
|
161
164
|
const content = `GIVE_NAME,NEW_NAME:${name}\n`
|
|
162
165
|
|
|
163
166
|
console.log("ckbfsCell=", ckbfsCell)
|
|
164
|
-
|
|
165
|
-
const previousData = {
|
|
166
|
-
previousTxHash: ckbfsCell.outPoint.txHash,
|
|
167
|
-
previousWitnessIndex: ckbfsCell.data?.index || 0,
|
|
168
|
-
previousChecksum: ckbfsCell.data?.checksum || 0
|
|
169
|
-
};
|
|
167
|
+
|
|
170
168
|
const signer = ckbfs['signer']
|
|
171
169
|
const address = await signer.getRecommendedAddress()
|
|
170
|
+
console.log("address=", address)
|
|
172
171
|
const addressHash = await getAddressScriptHash(address)
|
|
173
172
|
console.log("addressHash=", addressHash)
|
|
174
|
-
let tx = await ckbfs.createAppendContentTransaction(content, ckbfsCell,
|
|
173
|
+
let tx = await ckbfs.createAppendContentTransaction(content, ckbfsCell, {
|
|
174
|
+
witnessStartIndex: 1,
|
|
175
|
+
});
|
|
175
176
|
tx.addCellDeps(TestnetTraceLockDep)
|
|
176
|
-
console.log(tx.stringify())
|
|
177
|
+
// console.log("tx=", JSON.stringify(JSON.parse(tx.stringify()), null, 2))
|
|
177
178
|
const txHash = await signer.sendTransaction(tx)
|
|
178
179
|
console.log(`File appended successfully! Transaction Hash: ${txHash}`);
|
|
179
180
|
return { txHash, log: content }
|
|
@@ -381,11 +382,12 @@ async function testReresolve(ckbfsId: string) {
|
|
|
381
382
|
return data
|
|
382
383
|
}
|
|
383
384
|
|
|
385
|
+
|
|
384
386
|
// mintAll()
|
|
385
387
|
|
|
386
|
-
//
|
|
388
|
+
//mint("X30125NMNVAP000201").then(console.log)
|
|
387
389
|
|
|
388
|
-
//
|
|
390
|
+
//claim("ckt1qyq0zr47f0p8sm5d3cvtlpkljs7zvqcw7ngqnfscx0", "0xa3347c13f0419d9013a3f48a2b9ad993c2b6b5806827f3bf37480a58580d669d", "0x0084106b9bea08f512e35b725c4a710ebf09cb65c05601ebde8d911bc6c662bf")
|
|
389
391
|
|
|
390
392
|
// getCkbfsCellInfo("0xdb0b0b637060d2f6c42c4429e712fa043c1937968c03c54a5014b4595f88413a").then((data) => {
|
|
391
393
|
// console.log("ckbfs data=", data)
|
|
@@ -399,8 +401,9 @@ async function testReresolve(ckbfsId: string) {
|
|
|
399
401
|
// })
|
|
400
402
|
|
|
401
403
|
|
|
402
|
-
getCellInfoFromV3Transaction("0x54c86dbdc6bdafb4616221d54cfc0ff186a4a772eba509838684f8e1ea271b40").then(console.log)
|
|
404
|
+
// getCellInfoFromV3Transaction("0x54c86dbdc6bdafb4616221d54cfc0ff186a4a772eba509838684f8e1ea271b40").then(console.log)
|
|
403
405
|
|
|
404
|
-
getCkbfsCellInfo("
|
|
406
|
+
//getCkbfsCellInfo("0xe58baa82c4844add60911bb890487fea3c45436b9d7b203cc1065301d0a9c503").then(console.log)
|
|
407
|
+
giveName("bbb", "0xe58baa82c4844add60911bb890487fea3c45436b9d7b203cc1065301d0a9c503").then(console.log)
|
|
405
408
|
|
|
406
409
|
// testReresolve("0x0084106b9bea08f512e35b725c4a710ebf09cb65c05601ebde8d911bc6c662bf").then(console.log)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -142,6 +142,7 @@ export type AppendContentOptions = Omit<
|
|
|
142
142
|
"contentType" | "filename" | "capacity"
|
|
143
143
|
> & {
|
|
144
144
|
capacity?: bigint;
|
|
145
|
+
witnessStartIndex?: number;
|
|
145
146
|
};
|
|
146
147
|
|
|
147
148
|
/**
|
|
@@ -395,6 +396,7 @@ export class CKBFS {
|
|
|
395
396
|
previousTxHash?: string;
|
|
396
397
|
previousWitnessIndex?: number;
|
|
397
398
|
previousChecksum?: number;
|
|
399
|
+
witnessStartIndex?: number;
|
|
398
400
|
} = {},
|
|
399
401
|
): Promise<string> {
|
|
400
402
|
// Read the file and split into chunks
|
|
@@ -638,6 +640,7 @@ export class CKBFS {
|
|
|
638
640
|
previousTxHash?: string;
|
|
639
641
|
previousWitnessIndex?: number;
|
|
640
642
|
previousChecksum?: number;
|
|
643
|
+
witnessStartIndex?: number;
|
|
641
644
|
} = {},
|
|
642
645
|
): Promise<Transaction> {
|
|
643
646
|
// Read the file and split into chunks
|
|
@@ -666,6 +669,7 @@ export class CKBFS {
|
|
|
666
669
|
previousTxHash: options.previousTxHash,
|
|
667
670
|
previousWitnessIndex: options.previousWitnessIndex,
|
|
668
671
|
previousChecksum: options.previousChecksum,
|
|
672
|
+
witnessStartIndex: options.witnessStartIndex,
|
|
669
673
|
});
|
|
670
674
|
} else {
|
|
671
675
|
// Legacy V1/V2 behavior or when V3 backlink params are missing
|
|
@@ -1005,6 +1009,7 @@ export {
|
|
|
1005
1009
|
utilPublishCKBFS as publishCKBFS,
|
|
1006
1010
|
utilAppendCKBFS as appendCKBFS,
|
|
1007
1011
|
createAppendTransactionDry,
|
|
1012
|
+
createAppendV3Transaction,
|
|
1008
1013
|
// File utilities
|
|
1009
1014
|
readFile,
|
|
1010
1015
|
readFileAsText,
|
package/src/utils/constants.ts
CHANGED
|
@@ -23,6 +23,8 @@ export const CKBFS_CODE_HASH: Record<NetworkType, Record<string, string>> = {
|
|
|
23
23
|
[NetworkType.Mainnet]: {
|
|
24
24
|
[ProtocolVersion.V2]:
|
|
25
25
|
"0x31e6376287d223b8c0410d562fb422f04d1d617b2947596a14c3d2efb7218d3a",
|
|
26
|
+
[ProtocolVersion.V3]:
|
|
27
|
+
"0xb5d13ffe0547c78021c01fe24dce2e959a1ed8edbca3cb93dd2e9f57fb56d695",
|
|
26
28
|
},
|
|
27
29
|
[NetworkType.Testnet]: {
|
|
28
30
|
[ProtocolVersion.V1]:
|
|
@@ -38,6 +40,8 @@ export const CKBFS_TYPE_ID: Record<NetworkType, Record<string, string>> = {
|
|
|
38
40
|
[NetworkType.Mainnet]: {
|
|
39
41
|
[ProtocolVersion.V2]:
|
|
40
42
|
"0xfd2058c9a0c0183354cf637e25d2707ffa9bb6fa2ba9b29f4ebc6be3e54ad7eb",
|
|
43
|
+
[ProtocolVersion.V3]:
|
|
44
|
+
"0xcc5411e8b70e551d7a3dd806256533cff6bc12118b48dd7b2d5d2292c3651add",
|
|
41
45
|
},
|
|
42
46
|
[NetworkType.Testnet]: {
|
|
43
47
|
[ProtocolVersion.V1]:
|
|
@@ -54,6 +58,8 @@ export const ADLER32_CODE_HASH: Record<NetworkType, Record<string, string>> = {
|
|
|
54
58
|
[NetworkType.Mainnet]: {
|
|
55
59
|
[ProtocolVersion.V2]:
|
|
56
60
|
"0x2138683f76944437c0c643664120d620bdb5858dd6c9d1d156805e279c2c536f",
|
|
61
|
+
[ProtocolVersion.V3]:
|
|
62
|
+
"0xbd944c8c5aa127270b591d50ab899c9a2a3e4429300db4ea3d7523aa592c1db1",
|
|
57
63
|
},
|
|
58
64
|
[NetworkType.Testnet]: {
|
|
59
65
|
[ProtocolVersion.V1]:
|
|
@@ -69,6 +75,8 @@ export const ADLER32_TYPE_ID: Record<NetworkType, Record<string, string>> = {
|
|
|
69
75
|
[NetworkType.Mainnet]: {
|
|
70
76
|
[ProtocolVersion.V2]:
|
|
71
77
|
"0x641c01d590833a3f5471bd441651d9f2a8a200141949cdfeef2d68d8094c5876",
|
|
78
|
+
[ProtocolVersion.V3]:
|
|
79
|
+
"0x01b150adbbcba724a3917aefec6453ce4dbf70072d31ad42d0f3429ea32c692b",
|
|
72
80
|
},
|
|
73
81
|
[NetworkType.Testnet]: {
|
|
74
82
|
[ProtocolVersion.V1]:
|
|
@@ -85,6 +93,8 @@ export const DEP_GROUP_TX_HASH: Record<NetworkType, Record<string, string>> = {
|
|
|
85
93
|
[NetworkType.Mainnet]: {
|
|
86
94
|
[ProtocolVersion.V2]:
|
|
87
95
|
"0xfab07962ed7178ed88d450774e2a6ecd50bae856bdb9b692980be8c5147d1bfa",
|
|
96
|
+
[ProtocolVersion.V3]:
|
|
97
|
+
"0x03deba7f8206c81981d6f6a2d61b67dde75b4df91cbcfaf2e2fb041ba50c4719",
|
|
88
98
|
},
|
|
89
99
|
[NetworkType.Testnet]: {
|
|
90
100
|
[ProtocolVersion.V1]:
|
|
@@ -108,6 +118,12 @@ export const DEPLOY_TX_HASH: Record<
|
|
|
108
118
|
adler32:
|
|
109
119
|
"0xc9b6698f44c3b80e7e1c48823b2714e432b93f0206ffaf9df885d23267ed2ebc",
|
|
110
120
|
},
|
|
121
|
+
[ProtocolVersion.V3]: {
|
|
122
|
+
ckbfs:
|
|
123
|
+
"0xd25f2c32f56c28c630d4f91955f1b3c9cd53e26fa0745d540d934e8e3d3c2853",
|
|
124
|
+
adler32:
|
|
125
|
+
"0xd25f2c32f56c28c630d4f91955f1b3c9cd53e26fa0745d540d934e8e3d3c2853",
|
|
126
|
+
},
|
|
111
127
|
},
|
|
112
128
|
[NetworkType.Testnet]: {
|
|
113
129
|
[ProtocolVersion.V1]: {
|
|
@@ -29,7 +29,8 @@ export interface PublishOptions extends BasePublishOptions {}
|
|
|
29
29
|
/**
|
|
30
30
|
* Options for appending content to a CKBFS file (V1/V2)
|
|
31
31
|
*/
|
|
32
|
-
export interface AppendOptions extends BaseAppendOptions {
|
|
32
|
+
export interface AppendOptions extends BaseAppendOptions {
|
|
33
|
+
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Creates a CKBFS cell
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ccc, Transaction, Script, Signer } from "@ckb-ccc/core";
|
|
2
2
|
import { calculateChecksum, updateChecksum } from "../checksum";
|
|
3
|
-
import { CKBFSData, CKBFSDataType } from "../molecule";
|
|
3
|
+
import { CKBFSData, CKBFSDataType, CKBFSDataV3 } from "../molecule";
|
|
4
4
|
import { createChunkedCKBFSV3Witnesses, CKBFSV3WitnessOptions } from "../witness";
|
|
5
5
|
import {
|
|
6
6
|
getCKBFSScriptConfig,
|
|
@@ -45,6 +45,7 @@ export interface AppendV3Options {
|
|
|
45
45
|
network?: NetworkType;
|
|
46
46
|
version: typeof ProtocolVersion.V3;
|
|
47
47
|
from?: Transaction;
|
|
48
|
+
witnessStartIndex?: number;
|
|
48
49
|
previousTxHash: string;
|
|
49
50
|
previousWitnessIndex: number;
|
|
50
51
|
previousChecksum: number;
|
|
@@ -357,6 +358,7 @@ export async function prepareAppendV3Transaction(
|
|
|
357
358
|
previousTxHash,
|
|
358
359
|
previousWitnessIndex,
|
|
359
360
|
previousChecksum,
|
|
361
|
+
witnessStartIndex,
|
|
360
362
|
} = options;
|
|
361
363
|
|
|
362
364
|
// Calculate new checksum by updating from previous checksum
|
|
@@ -364,7 +366,7 @@ export async function prepareAppendV3Transaction(
|
|
|
364
366
|
const newChecksum = await updateChecksum(previousChecksum, combinedContent);
|
|
365
367
|
|
|
366
368
|
// Calculate the actual witness indices where our content is placed
|
|
367
|
-
const contentStartIndex = from?.witnesses.length ||
|
|
369
|
+
const contentStartIndex = witnessStartIndex || from?.witnesses.length || 0;
|
|
368
370
|
|
|
369
371
|
// Create CKBFS v3 witnesses with backlink info
|
|
370
372
|
const ckbfsWitnesses = createChunkedCKBFSV3Witnesses(contentChunks, {
|
|
@@ -517,6 +519,8 @@ export async function createAppendV3Transaction(
|
|
|
517
519
|
await preTx.completeInputsByCapacity(signer);
|
|
518
520
|
}
|
|
519
521
|
|
|
522
|
+
await preTx.completeInputsByCapacity(signer);
|
|
523
|
+
|
|
520
524
|
const witnesses: any = [];
|
|
521
525
|
// add empty witness for signer if ckbfs's lock is the same as signer's lock
|
|
522
526
|
if (address.script.hash() === lock.hash()) {
|