@ckbfs/api 1.2.1 → 1.2.4

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/ABC.LOGS ADDED
@@ -0,0 +1 @@
1
+ MINT,TO:ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdpallzwnhe64rqnqmev7hf98yrmh4yzucgdw7qwGIVE_NAME,NEW_NAME:NERVAPE_COOKIE
@@ -168,10 +168,12 @@ async function createAppendTransaction(signer, options) {
168
168
  // cumulative nature as required by Rule 11 in the RFC
169
169
  const contentChecksum = await (0, checksum_1.updateChecksum)(data.checksum, combinedContent);
170
170
  console.log(`Updated checksum from ${data.checksum} to ${contentChecksum} for appended content`);
171
+ // Get the recommended address to ensure lock script cell deps are included
172
+ const address = await signer.getRecommendedAddressObj();
171
173
  // Calculate the actual witness indices where our content is placed
172
- // Index 0 is reserved for the secp256k1 witness for signing
173
- // So our CKBFS data starts at index 1
174
- const contentStartIndex = 1;
174
+ // CKBFS data starts at index 1 if signer's lock script is the same as ckbfs's lock script
175
+ // else CKBFS data starts at index 0
176
+ const contentStartIndex = address.script.hash() === lock.hash() ? 1 : 0;
175
177
  const witnessIndices = Array.from({ length: contentChunks.length }, (_, i) => contentStartIndex + i);
176
178
  // Create backlink for the current state based on version
177
179
  let newBackLink;
@@ -254,10 +256,6 @@ async function createAppendTransaction(signer, options) {
254
256
  capacity: outputCapacity,
255
257
  }
256
258
  ],
257
- witnesses: [
258
- [], // Empty secp witness for signing
259
- ...ckbfsWitnesses.map(w => `0x${Buffer.from(w).toString('hex')}`),
260
- ],
261
259
  outputsData: [
262
260
  outputData,
263
261
  ]
@@ -270,16 +268,28 @@ async function createAppendTransaction(signer, options) {
270
268
  },
271
269
  depType: "depGroup"
272
270
  });
273
- // Get the recommended address to ensure lock script cell deps are included
274
- const address = await signer.getRecommendedAddressObj();
271
+ const inputsBefore = tx.inputs.length;
275
272
  // If we need more capacity than the original cell had, add additional inputs
276
273
  if (outputCapacity > capacity) {
277
274
  console.log(`Need additional capacity: ${outputCapacity - capacity} shannons`);
278
275
  // Add more inputs to cover the increased capacity
279
276
  await tx.completeInputsByCapacity(signer);
280
277
  }
278
+ const witnesses = [];
279
+ // add empty witness for signer if ckbfs's lock is the same as signer's lock
280
+ if (address.script.hash() === lock.hash()) {
281
+ witnesses.push('0x');
282
+ }
283
+ // add ckbfs witnesses
284
+ witnesses.push(...ckbfsWitnesses.map(w => `0x${Buffer.from(w).toString('hex')}`));
285
+ // Add empty witnesses for signer's input
286
+ // This is to ensure that the transaction is valid and can be signed
287
+ for (let i = inputsBefore; i < tx.inputs.length; i++) {
288
+ witnesses.push('0x');
289
+ }
290
+ tx.witnesses = witnesses;
281
291
  // Complete fee
282
- await tx.completeFeeChangeToLock(signer, lock || address.script, feeRate || 2000);
292
+ await tx.completeFeeChangeToLock(signer, address.script, feeRate || 2000);
283
293
  return tx;
284
294
  }
285
295
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckbfs/api",
3
- "version": "1.2.1",
3
+ "version": "1.2.4",
4
4
  "description": "SDK for CKBFS protocol on CKB",
5
5
  "license": "MIT",
6
6
  "author": "Code Monad<code@lab-11.org>",
@@ -280,10 +280,13 @@ export async function createAppendTransaction(
280
280
  const contentChecksum = await updateChecksum(data.checksum, combinedContent);
281
281
  console.log(`Updated checksum from ${data.checksum} to ${contentChecksum} for appended content`);
282
282
 
283
+ // Get the recommended address to ensure lock script cell deps are included
284
+ const address = await signer.getRecommendedAddressObj();
285
+
283
286
  // Calculate the actual witness indices where our content is placed
284
- // Index 0 is reserved for the secp256k1 witness for signing
285
- // So our CKBFS data starts at index 1
286
- const contentStartIndex = 1;
287
+ // CKBFS data starts at index 1 if signer's lock script is the same as ckbfs's lock script
288
+ // else CKBFS data starts at index 0
289
+ const contentStartIndex = address.script.hash() === lock.hash() ? 1 : 0;
287
290
  const witnessIndices = Array.from(
288
291
  { length: contentChunks.length },
289
292
  (_, i) => contentStartIndex + i
@@ -378,15 +381,12 @@ export async function createAppendTransaction(
378
381
  capacity: outputCapacity,
379
382
  }
380
383
  ],
381
- witnesses: [
382
- [], // Empty secp witness for signing
383
- ...ckbfsWitnesses.map(w => `0x${Buffer.from(w).toString('hex')}`),
384
- ],
385
384
  outputsData: [
386
385
  outputData,
387
386
  ]
388
387
  });
389
-
388
+
389
+
390
390
  // Add the CKBFS dep group cell dependency
391
391
  tx.addCellDeps({
392
392
  outPoint: {
@@ -396,18 +396,31 @@ export async function createAppendTransaction(
396
396
  depType: "depGroup"
397
397
  });
398
398
 
399
- // Get the recommended address to ensure lock script cell deps are included
400
- const address = await signer.getRecommendedAddressObj();
401
-
399
+ const inputsBefore = tx.inputs.length;
402
400
  // If we need more capacity than the original cell had, add additional inputs
403
401
  if (outputCapacity > capacity) {
404
402
  console.log(`Need additional capacity: ${outputCapacity - capacity} shannons`);
405
403
  // Add more inputs to cover the increased capacity
406
404
  await tx.completeInputsByCapacity(signer);
407
405
  }
408
-
406
+
407
+ const witnesses: any = []
408
+ // add empty witness for signer if ckbfs's lock is the same as signer's lock
409
+ if(address.script.hash() === lock.hash()) {
410
+ witnesses.push('0x')
411
+ }
412
+ // add ckbfs witnesses
413
+ witnesses.push(...ckbfsWitnesses.map(w => `0x${Buffer.from(w).toString('hex')}`))
414
+
415
+ // Add empty witnesses for signer's input
416
+ // This is to ensure that the transaction is valid and can be signed
417
+ for(let i = inputsBefore; i < tx.inputs.length; i++) {
418
+ witnesses.push('0x')
419
+ }
420
+ tx.witnesses = witnesses
421
+
409
422
  // Complete fee
410
- await tx.completeFeeChangeToLock(signer, lock || address.script, feeRate || 2000);
423
+ await tx.completeFeeChangeToLock(signer, address.script, feeRate || 2000);
411
424
 
412
425
  return tx;
413
426
  }