@knuth/js-wasm 2.11.0 → 3.0.0

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 (74) hide show
  1. package/LICENSE.md +23 -0
  2. package/README.md +63 -27
  3. package/package.json +12 -7
  4. package/src/kth.js +6 -3
  5. package/src/kth.wasm +0 -0
  6. package/types/Bitcoin.d.ts +4 -0
  7. package/types/DerivationPath.d.ts +8 -0
  8. package/types/DoubleList.d.ts +5 -4
  9. package/types/EcCompressed.d.ts +8 -3
  10. package/types/EcPublic.d.ts +10 -4
  11. package/types/ElectrumClient.d.ts +79 -0
  12. package/types/EllipticCurve.d.ts +8 -2
  13. package/types/Hash.d.ts +5 -0
  14. package/types/HdPublic.d.ts +9 -3
  15. package/types/Input.d.ts +10 -7
  16. package/types/InputList.d.ts +6 -5
  17. package/types/Interpreter.d.ts +9 -1
  18. package/types/Kth.d.ts +4 -0
  19. package/types/LazySequence.d.ts +4 -0
  20. package/types/ListHelper.d.ts +12 -0
  21. package/types/ListNative.d.ts +4 -0
  22. package/types/NativeLifetime.d.ts +11 -0
  23. package/types/Opcode.d.ts +10 -3
  24. package/types/OpcodeAliases.d.ts +16 -0
  25. package/types/Operation.d.ts +31 -26
  26. package/types/OperationList.d.ts +6 -5
  27. package/types/Output.d.ts +11 -7
  28. package/types/OutputList.d.ts +6 -5
  29. package/types/OutputPoint.d.ts +8 -4
  30. package/types/PaymentAddress.d.ts +13 -8
  31. package/types/PaymentAddressList.d.ts +6 -5
  32. package/types/Program.d.ts +15 -2
  33. package/types/RuleFork.d.ts +4 -0
  34. package/types/Script.d.ts +34 -19
  35. package/types/ScriptFlags.d.ts +67 -0
  36. package/types/Secret.d.ts +4 -0
  37. package/types/SecretFunctions.d.ts +4 -0
  38. package/types/SighashAlgorithm.d.ts +4 -0
  39. package/types/SighashGuard.d.ts +10 -0
  40. package/types/StringList.d.ts +5 -4
  41. package/types/TokenData.d.ts +8 -3
  42. package/types/TokenDataBothKinds.d.ts +6 -3
  43. package/types/TokenDataFungible.d.ts +4 -0
  44. package/types/TokenDataNonFungible.d.ts +9 -2
  45. package/types/Transaction.d.ts +12 -10
  46. package/types/TransactionHelpers.d.ts +14 -0
  47. package/types/U32List.d.ts +5 -4
  48. package/types/U64List.d.ts +5 -4
  49. package/types/Utxo.d.ts +10 -6
  50. package/types/UtxoList.d.ts +6 -5
  51. package/types/Wallet.d.ts +28 -52
  52. package/types/WalletData.d.ts +5 -1
  53. package/types/WalletManager.d.ts +6 -3
  54. package/types/WalletUtils.d.ts +53 -0
  55. package/types/encoding.d.ts +4 -0
  56. package/types/env.d.ts +4 -0
  57. package/types/logger.d.ts +6 -0
  58. package/types/main.d.ts +75 -2
  59. package/types/nativeScope.d.ts +10 -0
  60. package/types/types.d.ts +4 -0
  61. package/types/utils.d.ts +4 -0
  62. package/types/wasm/EmscriptenModule.d.ts +4 -0
  63. package/types/wasm/bootloader.d.ts +4 -0
  64. package/types/wasm/exceptions.d.ts +4 -0
  65. package/types/wasm/glue.d.ts +937 -170
  66. package/types/wasm/glue_manual.d.ts +4 -0
  67. package/types/wasm/loadLib.d.ts +4 -0
  68. package/types/wasm/manualGeneratedTypes.d.ts +4 -0
  69. package/types/wasm/mem.d.ts +33 -1
  70. package/types/wasm/promises.d.ts +4 -0
  71. package/types/wasm/stack.d.ts +6 -0
  72. package/types/wasm/string.d.ts +13 -0
  73. package/types/LazySequence copy.d.ts +0 -0
  74. package/types/wasm/glue copy.d.ts +0 -230
package/LICENSE.md ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016-present Knuth Project developers.
4
+ Copyright (c) 2009-2021 The Bitcoin developers
5
+ Copyright (c) 2009-2017 The Bitcoin Core developers
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge)](LICENSE.md)
7
7
  <a target="_blank" href="https://t.me/knuth_cash">![Telegram](https://img.shields.io/badge/telegram-chat-blue.svg?logo=telegram&style=for-the-badge)</a>
8
8
 
9
- **Knuth JS-WASM** brings the power of a full Bitcoin Cash node to JavaScript through WebAssembly. Build wallets, validate addresses, create transactions, and more — all running natively in the browser or Node.js.
9
+ **Knuth JS-WASM** provides Bitcoin Cash primitives through WebAssembly. Build wallets, validate addresses and work with transactions in browsers and Node.js. Version 3.0.0 uses KTH 1.5.2 and Emscripten 6.0.13.
10
10
 
11
11
  ## Installation
12
12
 
@@ -16,22 +16,37 @@ npm install @knuth/js-wasm
16
16
 
17
17
  ## Quick Start
18
18
 
19
- ```typescript
20
- import { PaymentAddress, Wallet, Kth } from '@knuth/js-wasm';
19
+ Load the WebAssembly module before calling native-backed APIs:
21
20
 
22
- // Check library info
23
- const config = Kth.getLibconfig();
24
- console.log(`Knuth WASM v${config.wasmLibraryVersion}`);
21
+ ```javascript
22
+ const { loadLib, PaymentAddress, Kth } = require('@knuth/js-wasm');
25
23
 
26
- // Validate and convert addresses
27
- const addr = PaymentAddress.fromString('bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a');
28
- if (addr) {
29
- console.log(`Cash Address: ${addr.encodedCashAddr()}`);
30
- console.log(`Legacy: ${addr.encodedLegacy()}`);
31
- console.log(`CashTokens: ${addr.encodedCashTokens()}`);
24
+ async function main() {
25
+ await loadLib(
26
+ require.resolve('@knuth/js-wasm/src/kth.wasm'),
27
+ require.resolve('@knuth/js-wasm')
28
+ );
29
+ console.log(Kth.getLibconfig().cppapiVersion); // 1.5.2
30
+
31
+ const address = PaymentAddress.fromString('bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a');
32
+ if (address) {
33
+ console.log(address.encodedLegacy());
34
+ }
32
35
  }
36
+
37
+ main().catch(console.error);
33
38
  ```
34
39
 
40
+ The following examples assume `loadLib()` has completed.
41
+
42
+ ## Migrating to 3.0.0
43
+
44
+ - Use `ScriptFlags` / `ScriptUpgrades` and `bigint` for current script flags; for example, `script.toString(ScriptFlags.noRules)`.
45
+ - Construct wallets with `new Wallet(mnemonic, path, network)` or a seed. Release their native state with `wallet.dispose()`.
46
+ - Token amounts and satoshi values use `bigint`. Invalid token factories can return no native handle.
47
+ - APIs returning native handles transfer ownership as described by their declarations. Release owned handles with `free()` when finished.
48
+ - Recompile TypeScript consumers against the declarations shipped with this version.
49
+
35
50
  ## Features
36
51
 
37
52
  ### Address Handling
@@ -67,17 +82,18 @@ const mnemonic = ['word1', 'word2', 'word3', '...', 'word12'];
67
82
  const derivationPath = "m/44'/145'/0'/0";
68
83
  const network = 'MAINNET';
69
84
 
70
- const wallet = Wallet.fromMnemonic(mnemonic, derivationPath, network);
85
+ const wallet = new Wallet(mnemonic, derivationPath, network);
71
86
 
72
87
  // Get a single address
73
- const address = await wallet.getAddress(0);
88
+ const address = wallet.getAddress(0);
74
89
  console.log(address.encoded()); // bitcoincash:qr9sawzzmstkluq9nqefsu7eqya4zk2w7udune2pmf
75
90
 
76
91
  // Get multiple addresses
77
- const addresses = await wallet.getAddresses(5);
92
+ const addresses = wallet.getAddresses(5);
78
93
  addresses.forEach((addr, i) => {
79
94
  console.log(`[${i}]: ${addr.encoded()}`);
80
95
  });
96
+ wallet.dispose();
81
97
  ```
82
98
 
83
99
  ### Transactions
@@ -103,16 +119,16 @@ if (tx) {
103
119
  Work with Bitcoin scripts:
104
120
 
105
121
  ```typescript
106
- import { Script, hexStrToBytes } from '@knuth/js-wasm';
122
+ import { Script, ScriptFlags, hexStrToBytes } from '@knuth/js-wasm';
107
123
 
108
124
  // Parse a P2PKH script
109
125
  const scriptBytes = hexStrToBytes('76a91406ccef231c2db72526df9338894ccf9355e8f12188ac');
110
126
  const script = Script.fromData(scriptBytes, false);
111
127
 
112
128
  if (script) {
113
- console.log(`Type: ${script.type}`); // pay_public_key_hash
129
+ console.log(`Type: ${script.pattern()}`); // pay_public_key_hash
114
130
  console.log(`Size: ${script.serializedSize}`); // 25
115
- console.log(script.toString(0)); // dup hash160 [...] equalverify checksig
131
+ console.log(script.toString(ScriptFlags.noRules)); // dup hash160 [...] equalverify checksig
116
132
  }
117
133
 
118
134
  // Create scripts from string
@@ -139,7 +155,7 @@ const hash160 = HashFunctions.hash160(message); // SHA256 + RIPEMD160
139
155
  Parse transactions with fungible and non-fungible tokens:
140
156
 
141
157
  ```typescript
142
- import { Transaction, hexStrToBytes, encodeHash } from '@knuth/js-wasm';
158
+ import { Transaction, TokenDataFungible, hexStrToBytes, encodeHash } from '@knuth/js-wasm';
143
159
 
144
160
  const tx = Transaction.fromData(hexStrToBytes(tokenTxHex));
145
161
  if (tx && tx.outputs) {
@@ -149,7 +165,7 @@ if (tx && tx.outputs) {
149
165
  console.log(`Category: ${encodeHash(output.tokenData.category)}`);
150
166
  console.log(`Kind: ${output.tokenData.kind}`); // 'fungible' or 'non_fungible'
151
167
 
152
- if (output.tokenData.kind === 'fungible') {
168
+ if (output.tokenData.data instanceof TokenDataFungible) {
153
169
  console.log(`Amount: ${output.tokenData.data.amount}`);
154
170
  }
155
171
  }
@@ -187,21 +203,41 @@ Try it in your browser at [kth.cash](https://kth.cash/#wasm-demo) — no install
187
203
  ## Browser Usage
188
204
 
189
205
  ```html
190
- <script src="https://unpkg.com/@knuth/js-wasm/src/kth.js"></script>
206
+ <script src="https://unpkg.com/@knuth/js-wasm@3.0.0/src/kth.js"></script>
191
207
  <script>
192
- // Wait for WASM to load
193
- Module.onRuntimeInitialized = () => {
194
- const addr = PaymentAddress.fromString('bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a');
195
- console.log(addr.encodedLegacy());
196
- };
208
+ const { loadLib, PaymentAddress } = __KTH_MODULE__;
209
+ loadLib(
210
+ 'https://unpkg.com/@knuth/js-wasm@3.0.0/src/kth.wasm',
211
+ 'https://unpkg.com/@knuth/js-wasm@3.0.0/src/kth.js'
212
+ ).then(() => {
213
+ const address = PaymentAddress.fromString('bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a');
214
+ if (address) console.log(address.encodedLegacy());
215
+ }).catch(console.error);
197
216
  </script>
198
217
  ```
199
218
 
200
219
  ## Requirements
201
220
 
202
- - Node.js 16+ or modern browser with WebAssembly support
221
+ - Node.js 22+ or a modern browser with WebAssembly support
203
222
  - ES2020+ (uses BigInt for satoshi values)
204
223
 
224
+ ## Development and releases
225
+
226
+ ```sh
227
+ yarn install --frozen-lockfile
228
+ npm run tscheck
229
+ npm test
230
+ npm run check:package
231
+ ```
232
+
233
+ CI validates Node.js 22, 24 and 26. Package checks load the packed runtime and compile a TypeScript consumer against its
234
+ declarations. Pull requests and pushes to master run validation only.
235
+
236
+ To publish a version, update `package.json`, merge the reviewed change with passing CI, then publish a GitHub release
237
+ whose tag is `v<package version>`. The release workflow validates the tagged package before publishing to npm with OIDC
238
+ trusted publishing and provenance. Draft and prerelease releases do not publish to npm. The trusted publisher uses
239
+ the existing `.github/workflows/kth.yml` workflow.
240
+
205
241
  ## Issues
206
242
 
207
243
  Please report issues in our [main repository](https://github.com/k-nuth/kth/issues).
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@knuth/js-wasm",
3
- "version": "2.11.0",
3
+ "version": "3.0.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "description": "",
7
+ "description": "Bitcoin Cash WebAssembly library for browsers and Node.js",
8
8
  "main": "src/kth.js",
9
9
  "files": [
10
10
  "src/kth.js",
@@ -14,7 +14,7 @@
14
14
  ],
15
15
  "types": "types/wasm/bootloader.d.ts",
16
16
  "devDependencies": {
17
- "@stylistic/eslint-plugin" : "2.10.1",
17
+ "@stylistic/eslint-plugin": "2.10.1",
18
18
  "@types/file-saver": "^2.0.7",
19
19
  "@types/jest": "^29.5.14",
20
20
  "@typescript-eslint/eslint-plugin": "^8.14.0",
@@ -29,20 +29,25 @@
29
29
  "ts-transformer-keys": "^0.4.4",
30
30
  "typescript": "^5.6.3",
31
31
  "webpack": "^5.96.1",
32
- "webpack-cli": "^5.1.4"
32
+ "webpack-cli": "^5.1.4",
33
+ "@types/node": "^22.10.0"
33
34
  },
34
35
  "scripts": {
35
- "test": "jest --runInBand --verbose"
36
+ "test": "jest --runInBand --verbose",
37
+ "tscheck": "tsc --project tsconfig.test.json --noEmit",
38
+ "check:package": "node .github/scripts/check-package.cjs"
36
39
  },
37
40
  "repository": {
38
41
  "type": "git",
39
42
  "url": "git+https://github.com/k-nuth/js-wasm.git"
40
43
  },
41
-
42
44
  "author": "Knuth Developers",
43
45
  "license": "MIT",
44
46
  "bugs": {
45
47
  "url": "https://github.com/k-nuth/kth/issues"
46
48
  },
47
- "homepage": "https://github.com/k-nuth"
49
+ "homepage": "https://github.com/k-nuth",
50
+ "engines": {
51
+ "node": ">=22"
52
+ }
48
53
  }