Add x-only public key helper and bytecode check#233
Conversation
Replace createPublicKey+toXOnly usage with createXOnlyPublicKey in PublicKeysRepository to produce x-only pubkeys. Add a defensive check to ContractEvaluator to reject empty contract bytecode. Apply minor formatting and refactors (wrapping/parameter formatting, compact filter formatting, single-line error logging, Uint8Array buffer handling) across TransactionConverterForAPI, PublicKeysRepository, and ContractEvaluator. Update tsconfig lib to use "ESNext".
Bump package version to 1.0.0-beta.1 and update multiple dependencies and dev tooling. Notable dependency updates: - @btc-vision/bip32 -> ^7.1.2 - @btc-vision/bitcoin -> ^7.0.0-rc.4 - @btc-vision/ecpair -> ^4.0.5 - @btc-vision/op-vm changed from local file reference to ^1.0.0-rc.0 - @btc-vision/transaction -> ^1.8.0-rc.3 Tooling updates: - @eslint/js -> ^10.0.1 - eslint -> ^10.0.0 - @typescript-eslint/* -> ^8.56.0 - typescript-eslint -> ^8.56.0 Also applied a minor import formatting change in src/src/vm/runtime/ContractEvaluator.ts to reflow a multi-line import for readability.
There was a problem hiding this comment.
Pull request overview
This PR introduces a helper function for x-only public key creation, adds defensive bytecode validation, updates dependencies, and applies formatting improvements across the codebase. The changes focus on improving code quality and maintainability in the OPNet Node Bitcoin smart contracts system.
Changes:
- Replace
createPublicKey + toXOnlywithcreateXOnlyPublicKeyfor x-only public key generation inPublicKeysRepository - Add empty bytecode validation check in
ContractEvaluatorto reject contracts with no bytecode beyond the version byte - Update dependency versions including @btc-vision packages, ESLint, and typescript-eslint
- Simplify tsconfig.json lib configuration to use only "ESNext"
- Apply formatting improvements (line wrapping, parameter formatting) across multiple files
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Simplified lib array to use only "ESNext" instead of multiple ES versions and "dom" |
| src/src/vm/runtime/ContractEvaluator.ts | Added empty bytecode check and improved parameter formatting for load/call methods |
| src/src/db/repositories/PublicKeysRepository.ts | Replaced toXOnly(createPublicKey) with createXOnlyPublicKey in p2op method, improved formatting |
| src/src/api/data-converter/TransactionConverterForAPI.ts | Improved ternary expression formatting for originalTransactionId |
| package.json | Updated version to 1.0.0-beta.1 and bumped multiple dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add error chaining ({ cause: e }) to many thrown Errors to preserve original exceptions and improve debugging. Update ESLint config to use combined configs, allowDefaultProject for projectService, and disable 'no-useless-assignment'. Update package.json dependencies/devDependencies (add various libp2p, bson, chalk, express, multiformats, uint8arraylist, @typescript-eslint/utils, etc.; remove some unused dev deps). Minor code cleanups: reformat imports in PublicKeysRepository, add bson Document type import to StorageInterfaces, and small formatting adjustments. Update tsconfig.json to include DOM lib and reformat compilerOptions/paths.
Replace internal @libp2p/interface/src imports with public @libp2p/interface type imports (Connection, ConnectionGater, IdentifyResult, MultiaddrConnection) in P2PManager and ReusableStreamManager to rely on the official package surface and avoid importing internal paths. Remove DOM from tsconfig libs to restrict ambient DOM types. Also apply minor formatting/whitespace cleanup in PublicKeysRepository.
Collapse the mongodb import into a single line and adjust minor whitespace around the p2tr assignment. These are purely formatting changes (no functional modifications) to tidy the file.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Anakun <96896824+BlobMaster41@users.noreply.github.com>
Update TransactionInput tests to expect Uint8Array instances instead of Buffer and use the toHex helper for hex comparisons. Added import from '@btc-vision/bitcoin', adjusted witness test name and various assertions to reflect the code returning Uint8Array (byte lengths) and ensure consistent hex checks across the file.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 23 out of 24 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Change key normalization to only remove a leading '0x' by checking startsWith('0x') and using slice(2) instead of replace('0x', ''). This avoids accidentally removing '0x' sequences occurring elsewhere in the string and preserves keys that don't have the prefix. Updates applied in PublicKeysRepository.ts before public-key validation and result handling.
Replace occurrences of .replace('0x','') with a safer check that only removes the "0x" prefix when present (uses startsWith('0x') ? slice(2) : str) across multiple modules. This avoids accidentally removing an interior "0x" and corrupting hex inputs, and standardizes hex handling for checksums, proofs, public keys, and buffers. Updated files include API routes, Merkle/Epoch processing, DB repositories, PoC networking/config, utilities, and VM validators to ensure consistent, correct hex parsing and subsequent length validations.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 34 out of 35 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add a defensive check to ContractEvaluator to reject empty contract bytecode. Apply minor formatting and refactors (wrapping/parameter formatting, compact filter formatting, single-line error logging, Uint8Array buffer handling) across TransactionConverterForAPI, PublicKeysRepository, and ContractEvaluator. Update tsconfig lib to use "ESNext".
Description
Type of Change
Checklist
Build & Tests
npm installcompletes without errorsnpm run buildcompletes without errorsnpm testpasses all testsCode Quality
Documentation
Security
OPNet Node Specific
Testing
Consensus Impact
Related Issues
By submitting this PR, I confirm that my contribution is made under the terms of the project's license.