Skip to content

use ts-sdk - #267

Open
zhfnjust wants to merge 3 commits into
masterfrom
remove_bsv
Open

use ts-sdk#267
zhfnjust wants to merge 3 commits into
masterfrom
remove_bsv

Conversation

@zhfnjust

Copy link
Copy Markdown
Contributor

No description provided.

@zhfnjustzhfnjust changed the title Remove bsvuse ts-sdkApr 10, 2024
@YinanDanielZhou

Copy link
Copy Markdown

Just curious, this PR is intended to replace the sCrypt-Inc/bsv dependency with the bitcoin-sv/ts-sdk dependency, correct? Is it still on going?

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the codebase to use a new TypeScript SDK abstraction layer instead of directly using the bsv library. The main purpose is to introduce a chain abstraction through a factory pattern that enables support for multiple blockchain implementations while maintaining compatibility with existing code.

  • Introduces a new Chain factory pattern with BSV implementation
  • Removes direct bsv library dependencies and replaces with abstracted interfaces
  • Updates test files to use the new SDK patterns and transaction handling
  • Migrates utility functions to use the new chain abstraction layer

Reviewed Changes

Copilot reviewed 54 out of 55 changed files in this pull request and generated 6 comments.

Show a summary per file
FileDescription
test/utils.test.tsRemoves int2Asm function tests and updates imports
test/tx.test.tsNew test file demonstrating SDK usage patterns
test/helper.tsUpdates transaction creation to use Chain factory
test/counter.test.tsMigrates test to use new transaction and verification patterns
test/accumulatorMultiSig.test.tsUpdates to use SDK primitives for key generation
test/abi.test.tsConverts to Chain factory for cryptographic operations
src/utils.tsMajor refactor to use Chain abstraction instead of bsv directly
src/stateful.tsUpdates to use Chain factory for script and reader operations
src/serializer.tsMigrates to Chain factory for script operations
src/launchConfig.tsAdds type casting for bigint comparison
src/index.tsRemoves exported utility functions and constants
src/deserializer.tsUpdates to use Chain factory for script parsing
src/contract.tsMajor refactor to use Chain abstraction for transaction verification
src/compilerWrapper.tsUpdates hash function encoding parameter
src/chain/*New abstraction layer with BSV implementation
src/builtins.tsUpdates to use Chain factory for cryptographic operations
src/abi.tsMigrates to Chain factory for script operations
package.jsonUpdates dependencies to use @bsv/sdk instead of bsv

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadtest/tx.test.ts

const key = factory.PrivateKey.fromRandom();
// tx.addInput()
console.log(key.toAddress())

CopilotAIAug 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file appears to be a temporary development/debugging file with console.log statements and incomplete test structure. Consider removing this file or converting it into proper unit tests with assertions.

Suggested change
console.log(key.toAddress())
import*asassertfrom"assert";
describe("Chain Factory and Script Tests",function(){
it("should create and manipulate LockingScript correctly",function(){
constfactory=Chain.getFactory();
consts=factory.LockingScript.fromHex('76a914212771cc264264057238cc3b98a03ddd9aa3a31c88ac');
s.writeNumber(3).writeBn(BigInt(30));
s.writeOpCode(OP.OP_2SWAP);
constss=factory.UnlockingScript.fromHex('020111');
s.writeScript(ss);
// Check that s.toASM() returns a non-empty string
assert.ok(typeofs.toASM()==="string"&&s.toASM().length>0,"ASM should be a non-empty string");
});
it("should create Transaction from hex",function(){
constfactory=Chain.getFactory();
consttx=factory.Transaction.fromHex('01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1a034fcd0c2f7461616c2e636f6d2ffd54e6dd4fe37955f2600000ffffffff0161cf4025000000001976a914522cf9e7626d9bd8729e5a1398ece40dad1b6a2f88ac00000000');
assert.ok(tx,"Transaction should be created");
});
it("should create empty Transaction",function(){
constfactory=Chain.getFactory();
consttx1=factory.Transaction.from();
assert.ok(tx1,"Empty Transaction should be created");
});
it("should generate a random PrivateKey and get its address",function(){
constfactory=Chain.getFactory();
constkey=factory.PrivateKey.fromRandom();
constaddress=key.toAddress();
assert.ok(typeofaddress==="string"&&address.length>0,"Address should be a non-empty string");
});
});

Copilot uses AI. Check for mistakes.
Comment threadtest/counter.test.ts

console.log('result', result)

let callTx = new Transaction()

CopilotAIAug 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable callTx is declared but Transaction is not imported. This will cause a runtime error since Transaction is undefined in this scope.

Copilot uses AI. Check for mistakes.
Comment threadsrc/contract.ts
}));

const abn = unpack(this.flattenSha256(a[0], keyType));
const bbn = unpack(this.flattenSha256(b[0], keyType));

CopilotAIAug 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing a[0] in this context appears incorrect. The variable a is the first element of a map entry, so it should be a instead of a[0]. This pattern is repeated on multiple lines.

Suggested change
constbbn=unpack(this.flattenSha256(b[0],keyType));
constabn=unpack(this.flattenSha256(a,keyType));
constbbn=unpack(this.flattenSha256(b,keyType));

Copilot uses AI. Check for mistakes.
Comment threadsrc/contract.ts
}));

const abn = unpack(this.flattenSha256(a[0], keyType));
const bbn = unpack(this.flattenSha256(b[0], keyType));

CopilotAIAug 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above - accessing a[0] when a is already the key element. Should be a instead of a[0].

Suggested change
constbbn=unpack(this.flattenSha256(b[0],keyType));
constabn=unpack(this.flattenSha256(a,keyType));
constbbn=unpack(this.flattenSha256(b,keyType));

Copilot uses AI. Check for mistakes.
Comment threadsrc/builtins.ts
export function pack(n: bigint): Bytes {
const num = new bsv.crypto.BN(n);
return num.toSM({ endian: 'little' }).toString('hex');
return num2bin(n);

CopilotAIAug 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function calls num2bin(n) but num2bin is not imported or defined in this scope. This will cause a runtime error.

Copilot uses AI. Check for mistakes.
Comment threadsrc/builtins.ts
*/
export function unpack(a: Bytes): bigint {
return BigInt(bin2num(a));
return bin2num(a);

CopilotAIAug 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function calls bin2num(a) but bin2num is not imported or defined in this scope. This will cause a runtime error.

Suggested change
returnbin2num(a);
returnbin2num(toHex(a));

Copilot uses AI. Check for mistakes.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@zhfnjust@YinanDanielZhou