@bsv/sdk 1.0.0 → 1.0.1

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 (123) hide show
  1. package/README.md +25 -3
  2. package/package.json +9 -5
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
  4. package/.github/ISSUE_TEMPLATE/discussion.md +0 -24
  5. package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +0 -23
  6. package/CHANGELOG.md +0 -72
  7. package/CONTRIBUTING.md +0 -85
  8. package/ROADMAP.md +0 -3
  9. package/docs/getting-started/COMMONJS.md +0 -94
  10. package/docs/getting-started/REACT-TS.md +0 -131
  11. package/docs/getting-started/TS-NODE.md +0 -106
  12. package/docs/getting-started/VUE.md +0 -103
  13. package/jest.config.js +0 -6
  14. package/mod.ts +0 -8
  15. package/src/compat/BSM.ts +0 -51
  16. package/src/compat/ECIES.ts +0 -557
  17. package/src/compat/HD.ts +0 -348
  18. package/src/compat/Mnemonic.ts +0 -295
  19. package/src/compat/__tests/BSM.test.ts +0 -38
  20. package/src/compat/__tests/ECIES.test.ts +0 -90
  21. package/src/compat/__tests/HD.test.ts +0 -405
  22. package/src/compat/__tests/Mnemonic.test.ts +0 -177
  23. package/src/compat/__tests/Mnemonic.vectors.ts +0 -172
  24. package/src/compat/bip-39-wordlist-en.ts +0 -2053
  25. package/src/compat/index.ts +0 -4
  26. package/src/messages/EncryptedMessage.ts +0 -70
  27. package/src/messages/SignedMessage.ts +0 -87
  28. package/src/messages/__tests/EncryptedMessage.test.ts +0 -36
  29. package/src/messages/__tests/SignedMessage.test.ts +0 -53
  30. package/src/messages/index.ts +0 -2
  31. package/src/primitives/AESGCM.ts +0 -479
  32. package/src/primitives/BasePoint.ts +0 -21
  33. package/src/primitives/BigNumber.ts +0 -4619
  34. package/src/primitives/Curve.ts +0 -1163
  35. package/src/primitives/DRBG.ts +0 -102
  36. package/src/primitives/ECDSA.ts +0 -164
  37. package/src/primitives/Hash.ts +0 -1420
  38. package/src/primitives/JacobianPoint.ts +0 -410
  39. package/src/primitives/K256.ts +0 -116
  40. package/src/primitives/Mersenne.ts +0 -123
  41. package/src/primitives/MontgomoryMethod.ts +0 -160
  42. package/src/primitives/Point.ts +0 -852
  43. package/src/primitives/PrivateKey.ts +0 -195
  44. package/src/primitives/PublicKey.ts +0 -154
  45. package/src/primitives/Random.ts +0 -55
  46. package/src/primitives/ReductionContext.ts +0 -528
  47. package/src/primitives/Signature.ts +0 -235
  48. package/src/primitives/SymmetricKey.ts +0 -75
  49. package/src/primitives/TransactionSignature.ts +0 -189
  50. package/src/primitives/__tests/AESGCM.test.ts +0 -338
  51. package/src/primitives/__tests/BRC42.private.vectors.ts +0 -33
  52. package/src/primitives/__tests/BRC42.public.vectors.ts +0 -33
  53. package/src/primitives/__tests/BigNumber.arithmatic.test.ts +0 -572
  54. package/src/primitives/__tests/BigNumber.binary.test.ts +0 -203
  55. package/src/primitives/__tests/BigNumber.constructor.test.ts +0 -176
  56. package/src/primitives/__tests/BigNumber.dhGroup.test.ts +0 -18
  57. package/src/primitives/__tests/BigNumber.fixtures.ts +0 -264
  58. package/src/primitives/__tests/BigNumber.serializers.test.ts +0 -157
  59. package/src/primitives/__tests/BigNumber.utils.test.ts +0 -347
  60. package/src/primitives/__tests/Curve.unit.test.ts +0 -192
  61. package/src/primitives/__tests/DRBG.test.ts +0 -18
  62. package/src/primitives/__tests/DRBG.vectors.ts +0 -167
  63. package/src/primitives/__tests/ECDH.test.ts +0 -31
  64. package/src/primitives/__tests/ECDSA.test.ts +0 -58
  65. package/src/primitives/__tests/HMAC.test.ts +0 -59
  66. package/src/primitives/__tests/Hash.test.ts +0 -121
  67. package/src/primitives/__tests/PBKDF2.vectors.ts +0 -119
  68. package/src/primitives/__tests/PrivateKey.test.ts +0 -17
  69. package/src/primitives/__tests/PublicKey.test.ts +0 -66
  70. package/src/primitives/__tests/Random.test.ts +0 -14
  71. package/src/primitives/__tests/Reader.test.ts +0 -296
  72. package/src/primitives/__tests/ReductionContext.test.ts +0 -279
  73. package/src/primitives/__tests/SymmetricKey.test.ts +0 -58
  74. package/src/primitives/__tests/SymmetricKey.vectors.ts +0 -40
  75. package/src/primitives/__tests/Writer.test.ts +0 -198
  76. package/src/primitives/__tests/sighash.vectors.ts +0 -3503
  77. package/src/primitives/__tests/utils.test.ts +0 -108
  78. package/src/primitives/index.ts +0 -8
  79. package/src/primitives/utils.ts +0 -665
  80. package/src/script/LockingScript.ts +0 -30
  81. package/src/script/OP.ts +0 -219
  82. package/src/script/Script.ts +0 -426
  83. package/src/script/ScriptChunk.ts +0 -7
  84. package/src/script/ScriptTemplate.ts +0 -36
  85. package/src/script/Spend.ts +0 -1379
  86. package/src/script/UnlockingScript.ts +0 -30
  87. package/src/script/__tests/Script.test.ts +0 -369
  88. package/src/script/__tests/Spend.test.ts +0 -248
  89. package/src/script/__tests/script.invalid.vectors.ts +0 -925
  90. package/src/script/__tests/script.valid.vectors.ts +0 -1120
  91. package/src/script/__tests/scriptFromVector.ts +0 -42
  92. package/src/script/__tests/spend.valid.vectors.ts +0 -2288
  93. package/src/script/index.ts +0 -7
  94. package/src/script/templates/P2PKH.ts +0 -109
  95. package/src/script/templates/RPuzzle.ts +0 -140
  96. package/src/script/templates/index.ts +0 -2
  97. package/src/transaction/Broadcaster.ts +0 -42
  98. package/src/transaction/ChainTracker.ts +0 -22
  99. package/src/transaction/FeeModel.ts +0 -13
  100. package/src/transaction/MerklePath.ts +0 -259
  101. package/src/transaction/Transaction.ts +0 -602
  102. package/src/transaction/TransactionInput.ts +0 -63
  103. package/src/transaction/TransactionOutput.ts +0 -37
  104. package/src/transaction/__tests/MerklePath.test.ts +0 -181
  105. package/src/transaction/__tests/Transaction.test.ts +0 -413
  106. package/src/transaction/__tests/bigtx.vectors.ts +0 -4
  107. package/src/transaction/__tests/bump.invalid.vectors.ts +0 -8
  108. package/src/transaction/__tests/bump.valid.vectors.ts +0 -4
  109. package/src/transaction/__tests/tx.invalid.vectors.ts +0 -281
  110. package/src/transaction/__tests/tx.valid.vectors.ts +0 -364
  111. package/src/transaction/broadcasters/ARC.ts +0 -106
  112. package/src/transaction/broadcasters/__tests/ARC.test.ts +0 -115
  113. package/src/transaction/broadcasters/index.ts +0 -1
  114. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +0 -71
  115. package/src/transaction/fee-models/index.ts +0 -1
  116. package/src/transaction/index.ts +0 -6
  117. package/ts2md.json +0 -5
  118. package/tsconfig.base.json +0 -26
  119. package/tsconfig.cjs.json +0 -11
  120. package/tsconfig.eslint.json +0 -12
  121. package/tsconfig.esm.json +0 -9
  122. package/tsconfig.json +0 -17
  123. package/tsconfig.types.json +0 -11
package/README.md CHANGED
@@ -31,8 +31,31 @@ npm install @bsv/sdk
31
31
 
32
32
  Here's a simple example of using the SDK to create and sign a transaction:
33
33
 
34
- ```typescript
35
- // TODO: Code Example Will Go Here
34
+ ```javascript
35
+ import { PrivateKey, P2PKH, Transaction, ARC } from '@bsv/sdk'
36
+
37
+ const privKey = PrivateKey.fromWif('L5EY1SbTvvPNSdCYQe1EJHfXCBBT4PmnF6CDbzCm9iifZptUvDGB')
38
+
39
+ const sourceTransaction = Transaction.fromHex('0200000001849c6419aec8b65d747cb72282cc02f3fc26dd018b46962f5de48957fac50528020000006a473044022008a60c611f3b48eaf0d07b5425d75f6ce65c3730bd43e6208560648081f9661b0220278fa51877100054d0d08e38e069b0afdb4f0f9d38844c68ee2233ace8e0de2141210360cd30f72e805be1f00d53f9ccd47dfd249cbb65b0d4aee5cfaf005a5258be37ffffffff03d0070000000000001976a914acc4d7c37bc9d0be0a4987483058a2d842f2265d88ac75330100000000001976a914db5b7964eecb19fcab929bf6bd29297ec005d52988ac809f7c09000000001976a914c0b0a42e92f062bdbc6a881b1777eed1213c19eb88ac00000000')
40
+
41
+ const version = 1
42
+ const input = {
43
+ sourceTransaction,
44
+ sourceOutputIndex: 0,
45
+ unlockingScriptTemplate: new P2PKH().unlock(privKey),
46
+ }
47
+ const output = {
48
+ lockingScript: new P2PKH().lock(privKey.toPublicKey().toHash()),
49
+ change: true
50
+ }
51
+
52
+ const tx = new Transaction(version, [input], [output])
53
+ await tx.fee()
54
+ await tx.sign()
55
+
56
+ // get your api key from https://console.taal.com
57
+ const apiKey = 'mainnet_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' // replace
58
+ await tx.broadcast(new ARC('https://api.taal.com/arc', apiKey))
36
59
  ```
37
60
 
38
61
  For a more detailed tutorial and advanced examples, check our [Documentation](#documentation).
@@ -67,7 +90,6 @@ We're always looking for contributors to help us improve the SDK. Whether it's b
67
90
  4. **Test**: Ensure all tests pass by running `npm test`.
68
91
  5. **Commit**: Commit your changes and push to your fork.
69
92
  6. **Pull Request**: Open a pull request from your fork to this repository.
70
-
71
93
  For more details, check the [contribution guidelines](./CONTRIBUTING.md).
72
94
 
73
95
  For information on past releases, check out the [changelog](./CHANGELOG.md). For future plans, check the [roadmap](./ROADMAP.md)!
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Standard Development Kit",
6
6
  "main": "dist/cjs/mod.js",
7
7
  "module": "dist/esm/mod.js",
8
8
  "types": "dist/types/mod.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "docs"
12
+ ],
9
13
  "exports": {
10
14
  ".": {
11
15
  "types": "./dist/types/mod.d.ts",
@@ -110,7 +114,7 @@
110
114
  },
111
115
  "repository": {
112
116
  "type": "git",
113
- "url": "git+https://github.com/bitcoin-sv/sdk.git"
117
+ "url": "git+https://github.com/bitcoin-sv/ts-sdk.git"
114
118
  },
115
119
  "keywords": [
116
120
  "BSV",
@@ -122,9 +126,9 @@
122
126
  "author": "BSV Blockchain Association",
123
127
  "license": "SEE LICENSE IN LICENSE.txt",
124
128
  "bugs": {
125
- "url": "https://github.com/bitcoin-sv/sdk/issues"
129
+ "url": "https://github.com/bitcoin-sv/ts-sdk/issues"
126
130
  },
127
- "homepage": "https://github.com/bitcoin-sv/sdk#readme",
131
+ "homepage": "https://github.com/bitcoin-sv/ts-sdk#readme",
128
132
  "devDependencies": {
129
133
  "@types/jest": "^29.5.5",
130
134
  "jest": "^29.7.0",
@@ -134,4 +138,4 @@
134
138
  "tsconfig-to-dual-package": "^1.2.0",
135
139
  "typescript": "^5.2.2"
136
140
  }
137
- }
141
+ }
@@ -1,40 +0,0 @@
1
- ---
2
- name: Bug Report
3
- about: Report a bug or an issue you've found with `@bsv/sdk`.
4
- title: "[BUG]"
5
- labels: bug
6
- assignees: ''
7
-
8
- ---
9
-
10
- ## Bug Description
11
-
12
- Briefly describe the bug/issue you've encountered.
13
-
14
- ## Steps to Reproduce
15
-
16
- 1. Step 1
17
- 2. Step 2
18
- 3. ...
19
-
20
- ## Expected Behavior
21
-
22
- What should have happened if the bug hadn't occurred?
23
-
24
- ## Actual Behavior
25
-
26
- What actually happened?
27
-
28
- ## Stack Traces or Screenshots
29
-
30
- If applicable, add screenshots or stack traces to help explain the issue.
31
-
32
- ## Environment
33
-
34
- - OS: [e.g. MacOS, Windows]
35
- - Node version: [e.g. 12.20]
36
- - `@bsv/sdk` version: [e.g. 1.2.3]
37
-
38
- ## Additional Information
39
-
40
- Provide any additional context or information about the bug.
@@ -1,24 +0,0 @@
1
- ---
2
- name: Discussion
3
- about: Propose a discussion or seek clarification about a feature or topic.
4
- title: "[DISCUSSION]"
5
- labels: discussion
6
- assignees: ''
7
-
8
- ---
9
-
10
- ## Summary
11
-
12
- Briefly describe the topic you'd like to discuss.
13
-
14
- ## Motivation
15
-
16
- Why do you believe this to be important?
17
-
18
- ## Description
19
-
20
- Provide a detailed description or elaborate on your topic.
21
-
22
- ## Additional References
23
-
24
- Provide any additional articles, links, or context that would help facilitate the discussion.
@@ -1,23 +0,0 @@
1
- ## Description of Changes
2
-
3
- Provide a brief description of the changes you've made.
4
-
5
- ## Linked Issues / Tickets
6
-
7
- Reference any related issues or tickets, e.g. "Closes #123".
8
-
9
- ## Testing Procedure
10
-
11
- Describe the tests you've added or any testing steps you've taken.
12
-
13
- - [ ] I have added new unit tests
14
- - [ ] All tests pass locally
15
- - [ ] I have tested manually in my local environment
16
-
17
- ## Checklist:
18
-
19
- - [ ] I have performed a self-review of my own code
20
- - [ ] I have made corresponding changes to the documentation
21
- - [ ] My changes generate no new warnings
22
- - [ ] I have updated `CHANGELOG.md` with my changes
23
- - [ ] I have run `npm run doc` and `npm run lint` one final time before requesting a review
package/CHANGELOG.md DELETED
@@ -1,72 +0,0 @@
1
- # CHANGELOG for `@bsv/sdk`
2
-
3
- All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
-
5
- ## Table of Contents
6
-
7
- - [Unreleased](#unreleased)
8
- - [1.0.0 - YYYY-MM-DD](#100---yyyy-mm-dd)
9
-
10
- ## [Unreleased]
11
-
12
- ### Added
13
- - (Include new features or significant user-visible enhancements here.)
14
-
15
- ### Changed
16
- - (Detail modifications that are non-breaking but relevant to the end-users.)
17
-
18
- ### Deprecated
19
- - (List features that are in the process of being phased out or replaced.)
20
-
21
- ### Removed
22
- - (Indicate features or capabilities that were taken out of the project.)
23
-
24
- ### Fixed
25
- - (Document bugs that were fixed since the last release.)
26
-
27
- ### Security
28
- - (Notify of any improvements related to security vulnerabilities or potential risks.)
29
-
30
- ---
31
-
32
- ## [1.0.0] - YYYY-MM-DD
33
-
34
- ### Added
35
- - Initial release of the BSV Blockchain Libraries Project SDK.
36
- - Sound Cryptographic Primitives for key management, signature computations, and encryption protocols.
37
- - Script Level Constructs with network-compliant script interpreter.
38
- - Comprehensive Transaction Construction and Signing API.
39
- - Mechanisms for Transaction Broadcast Management.
40
- - Tools for Merkle Proof Verification and representation.
41
- - Structures and interfaces for full Serializable SPV Structures.
42
- - Enhanced mechanisms for Secure Encryption and Signed Messages.
43
-
44
- ---
45
-
46
- ### Template for New Releases:
47
-
48
- Replace `X.X.X` with the new version number and `YYYY-MM-DD` with the release date:
49
-
50
- ```
51
- ## [X.X.X] - YYYY-MM-DD
52
-
53
- ### Added
54
- -
55
-
56
- ### Changed
57
- -
58
-
59
- ### Deprecated
60
- -
61
-
62
- ### Removed
63
- -
64
-
65
- ### Fixed
66
- -
67
-
68
- ### Security
69
- -
70
- ```
71
-
72
- Use this template as the starting point for each new version. Always update the "Unreleased" section with changes as they're implemented, and then move them under the new version header when that version is released.
package/CONTRIBUTING.md DELETED
@@ -1,85 +0,0 @@
1
- # CONTRIBUTING to `@bsv/sdk`
2
-
3
- Thank you for considering contributing to the BSV Blockchain Libraries Project! This document outlines the processes and practices we expect contributors to adhere to.
4
-
5
- ## Table of Contents
6
-
7
- 1. [General Guidelines](#general-guidelines)
8
- 2. [Code of Conduct](#code-of-conduct)
9
- 3. [Getting Started](#getting-started)
10
- 4. [Pull Request Process](#pull-request-process)
11
- 5. [Coding Conventions](#coding-conventions)
12
- 6. [Documentation and Testing](#documentation-and-testing)
13
- 7. [Contact & Support](#contact--support)
14
-
15
- ## General Guidelines
16
-
17
- - **Issues First**: If you're planning to add a new feature or change existing behavior, please open an issue first. This allows us to avoid multiple people working on similar features and provides a place for discussion.
18
-
19
- - **Stay Updated**: Always pull the latest changes from the main branch before creating a new branch or starting on new code.
20
-
21
- - **Simplicity Over Complexity**: Your solution should be as simple as possible, given the requirements.
22
-
23
- ## Code of Conduct
24
-
25
- ### Posting Issues and Comments
26
-
27
- - **Be Respectful**: Everyone is here to help and grow. Avoid any language that might be considered rude or offensive.
28
-
29
- - **Be Clear and Concise**: Always be clear about what you're suggesting or reporting. If an issue is related to a particular piece of code or a specific error message, include that in your comment.
30
-
31
- - **Stay On Topic**: Keep the conversation relevant to the issue at hand. If you have a new idea or unrelated question, please open a new issue.
32
-
33
- ### Coding and PRs
34
-
35
- - **Stay Professional**: Avoid including "fun" code, comments, or irrelevant file changes in your commits and pull requests.
36
-
37
- ## Getting Started
38
-
39
- 1. **Fork the Repository**: Click on the "Fork" button at the top-right corner of this repository.
40
-
41
- 2. **Clone the Forked Repository**: `git clone https://github.com/YOUR_USERNAME/ts-sdk.git`
42
-
43
- 3. **Navigate to the Directory**: `cd bsv-sdk`
44
-
45
- 4. **Install Dependencies**: Since we maintain all code within this library, there shouldn't be any runtime dependencies. Nevertheless, always run `npm install` after pulling to ensure tooling is up to date.
46
-
47
- ## Pull Request Process
48
-
49
- 1. **Create a Branch**: For every new feature or bugfix, create a new branch.
50
-
51
- 2. **Commit Your Changes**: Make your changes and commit them. Commit messages should be clear and concise to explain what was done.
52
-
53
- 3. **Run Tests**: Ensure all tests pass using Jest: `npm test`.
54
-
55
- 4. **Documentation**: All code must be fully annotated with comments. Update the documentation by running `npm run doc` before creating a pull request.
56
-
57
- 5. **Push to Your Fork**: `git push origin your-new-branch`.
58
-
59
- 6. **Open a Pull Request**: Go to your fork on GitHub and click "New Pull Request". Fill out the PR template, explaining your changes.
60
-
61
- 7. **Code Review**: At least two maintainers must review and approve the PR before it's merged. Address any feedback or changes requested.
62
-
63
- 8. **Merge**: Once approved, the PR will be merged into the main branch.
64
-
65
- ## Coding Conventions
66
-
67
- - **Code Style**: We use `ts-standard` for our TypeScript coding style. Run `npm run lint` to ensure your code adheres to this style.
68
-
69
- - **No Runtime Dependencies**: All code should be maintained within this library. Do not introduce external dependencies.
70
-
71
- - **Testing**: Always include tests for new code or changes. We aim for industry-standard levels of test coverage.
72
-
73
- - **Documentation**: All functions, classes, and modules should be documented. Use annotation comments to describe the purpose, parameters, and return values.
74
-
75
- ## Documentation and Testing
76
-
77
- - **Documentation**: Update the documentation whenever you add or modify the code. Run `npm run doc` to generate the latest docs.
78
-
79
- - **Testing**: We use Jest for all tests. Write comprehensive tests, ensuring edge cases are covered. All PRs should maintain or improve the current test coverage.
80
-
81
- ## Contact & Support
82
-
83
- If you have any questions or need assistance with your contributions, feel free to reach out. Remember, we're here to help each other grow and improve the `@bsv/sdk`.
84
-
85
- Thank you for being a part of this journey. Your contributions help shape the future of the BSV Blockchain Libraries Project!
package/ROADMAP.md DELETED
@@ -1,3 +0,0 @@
1
- # ROADMAP
2
-
3
- Until version 1.0 of this library is released, the roadmap is being managed internally by the development team. Please reach out if you have any questions.
@@ -1,94 +0,0 @@
1
- # Getting Started with BSV SDK in Node.js (CommonJS)
2
-
3
- Welcome to the quick start guide for the BSV SDK, tailored for Node.js applications using CommonJS syntax. This guide will walk you through the steps to install the SDK, set up your project, and run a simple example that leverages the BSV Blockchain Libraries Project for creating and signing a transaction. Whether you're working on an existing Node.js project or starting a new one, this guide will get you up and running with the BSV SDK in no time.
4
-
5
- ## Prerequisites
6
-
7
- Before you begin, ensure you have the following:
8
-
9
- - Node.js installed on your machine. The BSV SDK is compatible with Node.js version 10 or later.
10
- - An understanding of JavaScript or TypeScript.
11
- - A basic familiarity with blockchain concepts, particularly those related to Bitcoin SV (BSV).
12
-
13
- ## Installation
14
-
15
- First, you'll need to install the BSV SDK in your Node.js project. If you haven't already created a project, you can do so by running `npm init` in your project directory and following the prompts.
16
-
17
- To install the SDK, open your terminal, navigate to your project directory, and run:
18
-
19
- ```bash
20
- npm install @bsv/sdk
21
- ```
22
-
23
- This command will download and install the BSV SDK and its dependencies into your project.
24
-
25
- ## Setting Up Your Project
26
-
27
- To use the SDK in a Node.js project with CommonJS syntax, you'll need to require the SDK modules in your JavaScript files. Here's how to set up a basic project structure and include the BSV SDK:
28
-
29
- 1. **Create a New JavaScript File:** In your project directory, create a new file named `index.js` or any other name you prefer for your main application file.
30
-
31
- 2. **Require the BSV SDK:** At the top of your `index.js` file, require the BSV SDK modules you plan to use. For example, to work with transactions, you might start with:
32
-
33
- ```javascript
34
- const { Transaction } = require('@bsv/sdk');
35
- ```
36
-
37
- 3. **Configure Your Environment:** If your project involves interacting with the BSV blockchain network (e.g., sending transactions, querying blockchain data), ensure you have the necessary network configurations and API keys set up if required by the SDK or any third-party services you're using.
38
-
39
- ## Example: Creating and Signing a Transaction
40
-
41
- Let's walk through a simple example of using the BSV SDK to create and sign a transaction. This example will demonstrate how to construct a transaction, add inputs and outputs, and sign it using a private key.
42
-
43
- 1. **Prepare Your Script:** In your `index.js`, start by requiring the necessary modules from the SDK. For this example, we'll need `Transaction`, `PrivateKey`, and possibly other modules depending on the complexity of your transaction.
44
-
45
- ```javascript
46
- const { Transaction, PrivateKey } = require('@bsv/sdk');
47
- ```
48
-
49
- 2. **Create a New Transaction:** Initialize a new `Transaction` object.
50
-
51
- ```javascript
52
- let tx = new Transaction();
53
- ```
54
-
55
- 3. **Add Inputs and Outputs:** For this example, we'll add a dummy input and output. In a real-world scenario, you would fetch UTXO (Unspent Transaction Output) data from a blockchain explorer or your wallet.
56
-
57
- ```javascript
58
- // Dummy input and output, replace with real data
59
- tx.from({
60
- txId: 'your_utxo_txid',
61
- outputIndex: 0,
62
- address: 'your_address',
63
- satoshis: 1000
64
- });
65
- tx.to('recipient_address', 500); // Send 500 satoshis to recipient
66
- ```
67
-
68
- 4. **Sign the Transaction:** Use a `PrivateKey` instance to sign the transaction. Replace `'your_private_key'` with your actual private key.
69
-
70
- ```javascript
71
- const privateKey = new PrivateKey('your_private_key');
72
- tx.sign(privateKey);
73
- ```
74
-
75
- 5. **Broadcast the Transaction:** The SDK may provide a method to broadcast the transaction to the BSV network. This step varies depending on the SDK's capabilities and your setup.
76
-
77
- ```javascript
78
- // This is a conceptual step; refer to the SDK documentation for actual broadcasting
79
- tx.broadcast();
80
- ```
81
-
82
- ## Running Your Project
83
-
84
- After setting up your project and writing the example code, you can run your project by executing:
85
-
86
- ```bash
87
- node index.js
88
- ```
89
-
90
- This command will run your `index.js` file, which includes the BSV SDK transaction creation and signing logic.
91
-
92
- ## Conclusion
93
-
94
- You've now seen how to get started with the BSV SDK in a Node.js (CommonJS) environment, from installation to running a simple transaction example. This guide aimed to provide a straightforward path for integrating the B
@@ -1,131 +0,0 @@
1
- # Getting Started with BSV SDK in a React TypeScript Project
2
-
3
- Welcome to a quick start guide designed to get you up and running with the BSV SDK in your React TypeScript projects. The BSV SDK offers a comprehensive set of tools for developing applications on the BSV Blockchain, and integrating it into a React application is straightforward. Follow these steps to begin building scalable blockchain applications with ease.
4
-
5
- ## Prerequisites
6
-
7
- Before you start, ensure you have the following installed:
8
- - Node.js (preferably the latest LTS version)
9
- - npm (comes with Node.js) or Yarn
10
- - A code editor of your choice (VSCode is recommended for TypeScript projects)
11
-
12
- ## Step 1: Setting Up Your React TypeScript Project
13
-
14
- If you're starting from scratch, create a new React TypeScript project by running the following command in your terminal:
15
-
16
- ```bash
17
- npx create-react-app my-bsv-app --template typescript
18
- ```
19
-
20
- This command creates a new React application named `my-bsv-app` with TypeScript setup. If you already have a React TypeScript project, you can skip this step.
21
-
22
- ## Step 2: Installing the BSV SDK
23
-
24
- Navigate to your project directory in the terminal and install the BSV SDK by running:
25
-
26
- ```bash
27
- npm install @bsv/sdk
28
- ```
29
-
30
- or if you're using Yarn:
31
-
32
- ```bash
33
- yarn add @bsv/sdk
34
- ```
35
-
36
- This command adds the BSV SDK to your project, allowing you to interact with the BSV Blockchain.
37
-
38
- ## Step 3: Using the BSV SDK in Your React Application
39
-
40
- Now that you've installed the SDK, let's use it to create and sign a transaction. First, create a new component where you'll implement your blockchain logic.
41
-
42
- ### Create a New Component
43
-
44
- In your project's `src` directory, create a new file named `BlockchainExample.tsx`. This component will demonstrate a simple usage of the BSV SDK.
45
-
46
- ### Implementing the Component
47
-
48
- Paste the following code into `BlockchainExample.tsx`:
49
-
50
- ```typescript
51
- import React from 'react';
52
- // Import necessary modules from the SDK
53
- import { PrivateKey, Transaction } from '@bsv/sdk';
54
-
55
- const BlockchainExample: React.FC = () => {
56
- // Example function to create and sign a transaction
57
- const createTransaction = async () => {
58
- try {
59
- // Replace with actual private key and addresses
60
- const privateKey = new PrivateKey('<your-private-key>');
61
- const fromAddress = '<from-address>';
62
- const toAddress = '<to-address>';
63
- const satoshis = 1000; // Amount to send
64
-
65
- // Create a new transaction
66
- let tx = new Transaction();
67
- tx.from(fromAddress) // Specify the sender's address
68
- .to(toAddress, satoshis) // Specify the recipient and amount
69
- .sign(privateKey); // Sign the transaction with the private key
70
-
71
- console.log('Transaction created:', tx.toString());
72
- // Add logic to broadcast the transaction
73
- } catch (error) {
74
- console.error('Error creating transaction:', error);
75
- }
76
- };
77
-
78
- return (
79
- <div>
80
- <h2>Blockchain Example</h2>
81
- <button onClick={createTransaction}>Create Transaction</button>
82
- </div>
83
- );
84
- };
85
-
86
- export default BlockchainExample;
87
- ```
88
-
89
- **Note:** This is a simplified example for educational purposes. Replace placeholder values with actual private keys and addresses, and implement proper error handling and security measures in your real-world applications.
90
-
91
- ### Add the Component to Your App
92
-
93
- Open `src/App.tsx` and import `BlockchainExample`. Include it in your application's render method:
94
-
95
- ```typescript
96
- import React from 'react';
97
- import './App.css';
98
- import BlockchainExample from './BlockchainExample';
99
-
100
- function App() {
101
- return (
102
- <div className="App">
103
- <header className="App-header">
104
- <BlockchainExample />
105
- </header>
106
- </div>
107
- );
108
- }
109
-
110
- export default App;
111
- ```
112
-
113
- ## Step 4: Running Your Application
114
-
115
- Now that everything is set up, start your application by running:
116
-
117
- ```bash
118
- npm start
119
- ```
120
-
121
- or if you're using Yarn:
122
-
123
- ```bash
124
- yarn start
125
- ```
126
-
127
- Your application will open in your default web browser. You'll see a button labeled "Create Transaction" that, when clicked, will run the logic to create and sign a transaction using the BSV SDK.
128
-
129
- ## Next Steps
130
-
131
- This guide covered the basics to get you started with the BSV SDK in a React TypeScript project. Explore the SDK's comprehensive documentation to learn more about its capabilities, such as cryptographic primitives, script-level constructs, transaction construction, and much more. Happy coding!
@@ -1,106 +0,0 @@
1
- To get started with the BSV SDK in a Node.js TypeScript project, follow these steps to install, configure, and use the library efficiently. This guide will help you set up a basic project structure, install the SDK, and create a simple application that uses BSV SDK functionalities.
2
-
3
- ### Prerequisites
4
-
5
- Before you begin, ensure you have the following installed on your system:
6
-
7
- - Node.js (version 12.x or higher)
8
- - npm (usually comes with Node.js)
9
- - TypeScript (version 3.8 or higher)
10
-
11
- You can check the versions by running `node -v` and `npm -v` in your terminal.
12
-
13
- ### Step 1: Setting Up Your Project
14
-
15
- If you're starting a new project, create a new directory for your project and initialize it with npm:
16
-
17
- ```bash
18
- mkdir my-bsv-project
19
- cd my-bsv-project
20
- npm init -y
21
- ```
22
-
23
- Install TypeScript and ts-node (for executing TypeScript files directly) as dev dependencies:
24
-
25
- ```bash
26
- npm install typescript ts-node --save-dev
27
- ```
28
-
29
- Create a `tsconfig.json` file to configure TypeScript options:
30
-
31
- ```json
32
- {
33
- "compilerOptions": {
34
- "target": "es2018",
35
- "module": "commonjs",
36
- "strict": true,
37
- "esModuleInterop": true,
38
- "skipLibCheck": true,
39
- "forceConsistentCasingInFileNames": true,
40
- "outDir": "./dist"
41
- },
42
- "include": ["src/**/*"]
43
- }
44
- ```
45
-
46
- This configuration is a good starting point for Node.js projects. Adjust it as necessary for your project needs.
47
-
48
- ### Step 2: Installing BSV SDK
49
-
50
- Install the BSV SDK using npm:
51
-
52
- ```bash
53
- npm install @bsv/sdk
54
- ```
55
-
56
- This command installs the SDK and adds it to your project's `package.json` dependencies.
57
-
58
- ### Step 3: Creating a TypeScript File
59
-
60
- In your project directory, create a `src` folder to hold your TypeScript files:
61
-
62
- ```bash
63
- mkdir src
64
- ```
65
-
66
- Inside the `src` folder, create a file named `index.ts`. This file will contain your code to interact with the BSV blockchain using the SDK.
67
-
68
- ### Step 4: Using BSV SDK in Your Project
69
-
70
- Now, let's use the SDK to create and sign a transaction as an example. Open `src/index.ts` and add the following TypeScript code:
71
-
72
- ```typescript
73
- import { PrivateKey, Transaction } from '@bsv/sdk';
74
-
75
- async function createAndSignTransaction() {
76
- const privateKey = new PrivateKey();
77
- const address = privateKey.toAddress();
78
-
79
- const tx = new Transaction();
80
- tx.from(/* UTXO details here */);
81
- tx.to(address, 1000); // Send 1000 satoshis to our address
82
- tx.change(address); // Return the change to our address
83
- await tx.sign(privateKey);
84
-
85
- console.log(`Transaction ID: ${tx.id()}`);
86
- console.log(`Raw Transaction: ${tx.serialize()}`);
87
- }
88
-
89
- createAndSignTransaction().catch(console.error);
90
- ```
91
-
92
- Note: Replace `/* UTXO details here */` with actual UTXO (Unspent Transaction Output) details. This example assumes you have some UTXOs to spend.
93
-
94
- ### Step 5: Running Your Code
95
-
96
- Finally, run your TypeScript file with `ts-node`:
97
-
98
- ```bash
99
- npx ts-node src/index.ts
100
- ```
101
-
102
- This command compiles your TypeScript code to JavaScript and executes it, displaying the transaction ID and raw transaction in the console.
103
-
104
- ### Conclusion
105
-
106
- You've now set up a basic Node.js TypeScript project using the BSV SDK. This guide covered project initialization, SDK installation, and a simple application to create and sign transactions. Explore the SDK's extensive documentation to learn more about its features and capabilities for developing on the BSV blockchain.