bsv2 2.1.0 → 2.1.2

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 (241) hide show
  1. package/dist/bsv2.mjs +1 -1
  2. package/dist/bsv2.umd.js +1 -1
  3. package/package.json +7 -3
  4. package/.babel.test +0 -10
  5. package/.editorconfig +0 -4
  6. package/.env.defaults +0 -1
  7. package/.env.schema +0 -1
  8. package/.husky/pre-commit +0 -1
  9. package/.mocharc.yml +0 -4
  10. package/.nvmrc +0 -1
  11. package/.travis.yml +0 -7
  12. package/babel.config.cjs +0 -44
  13. package/benchmark.js +0 -42
  14. package/bin/bsv.js +0 -11
  15. package/bin/network.js +0 -93
  16. package/build/index.html +0 -20
  17. package/doc/assets/anchor.js +0 -350
  18. package/doc/assets/bass-addons.css +0 -12
  19. package/doc/assets/bass.css +0 -544
  20. package/doc/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
  21. package/doc/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
  22. package/doc/assets/fonts/LICENSE.txt +0 -93
  23. package/doc/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
  24. package/doc/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
  25. package/doc/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
  26. package/doc/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
  27. package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
  28. package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
  29. package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
  30. package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
  31. package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
  32. package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
  33. package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
  34. package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
  35. package/doc/assets/fonts/source-code-pro.css +0 -23
  36. package/doc/assets/github.css +0 -123
  37. package/doc/assets/site.js +0 -168
  38. package/doc/assets/split.css +0 -15
  39. package/doc/assets/split.js +0 -782
  40. package/doc/assets/style.css +0 -147
  41. package/doc/index.html +0 -9461
  42. package/entry.js +0 -81
  43. package/eslint.config.mjs +0 -8
  44. package/index.js +0 -98
  45. package/karma.conf.ts +0 -77
  46. package/lib/ach.js +0 -59
  47. package/lib/address.js +0 -266
  48. package/lib/aes.js +0 -57
  49. package/lib/aescbc.js +0 -38
  50. package/lib/base-58-check.js +0 -83
  51. package/lib/base-58.js +0 -59
  52. package/lib/bip-32.js +0 -472
  53. package/lib/bip-39-en-wordlist.js +0 -2054
  54. package/lib/bip-39-en.js +0 -10
  55. package/lib/bip-39-es-wordlist.js +0 -2055
  56. package/lib/bip-39-es.js +0 -10
  57. package/lib/bip-39-jp-wordlist.js +0 -2053
  58. package/lib/bip-39-jp.js +0 -10
  59. package/lib/bip-39-words.js +0 -5
  60. package/lib/bip-39.js +0 -286
  61. package/lib/block-header.js +0 -79
  62. package/lib/block.js +0 -132
  63. package/lib/bn.js +0 -462
  64. package/lib/br.js +0 -172
  65. package/lib/bsm.js +0 -127
  66. package/lib/bw.js +0 -188
  67. package/lib/cbc.js +0 -140
  68. package/lib/cmp.js +0 -37
  69. package/lib/config.js +0 -50
  70. package/lib/constants.js +0 -150
  71. package/lib/ecdsa.js +0 -496
  72. package/lib/ecies.js +0 -151
  73. package/lib/hash-cache.js +0 -41
  74. package/lib/hash.js +0 -191
  75. package/lib/interp.js +0 -2017
  76. package/lib/inv.js +0 -49
  77. package/lib/key-pair.js +0 -133
  78. package/lib/mainnet-address.js +0 -5
  79. package/lib/mainnet-bip-32.js +0 -5
  80. package/lib/mainnet-key-pair.js +0 -5
  81. package/lib/mainnet-priv-key.js +0 -5
  82. package/lib/merkle.js +0 -92
  83. package/lib/msg.js +0 -184
  84. package/lib/op-code.js +0 -400
  85. package/lib/point.js +0 -134
  86. package/lib/priv-key.js +0 -157
  87. package/lib/pub-key.js +0 -230
  88. package/lib/random.js +0 -28
  89. package/lib/script.js +0 -828
  90. package/lib/sig-operations.js +0 -120
  91. package/lib/sig.js +0 -399
  92. package/lib/struct.js +0 -392
  93. package/lib/testnet-address.js +0 -5
  94. package/lib/testnet-bip-32.js +0 -5
  95. package/lib/testnet-key-pair.js +0 -5
  96. package/lib/testnet-priv-key.js +0 -5
  97. package/lib/tx-builder.js +0 -593
  98. package/lib/tx-in.js +0 -172
  99. package/lib/tx-out-map.js +0 -57
  100. package/lib/tx-out.js +0 -73
  101. package/lib/tx-verifier.js +0 -209
  102. package/lib/tx.js +0 -430
  103. package/lib/var-int.js +0 -73
  104. package/lib/version.js +0 -92
  105. package/lib/workers-result.js +0 -65
  106. package/lib/workers.js +0 -77
  107. package/load-babel.js +0 -5
  108. package/mtest/test.html +0 -17
  109. package/mtest/test.js +0 -2
  110. package/mtest/test.mjs +0 -2
  111. package/mtest/webpack.config.js +0 -115
  112. package/out/Sig.html +0 -541
  113. package/out/bip-32.js.html +0 -523
  114. package/out/bip-39.js.html +0 -336
  115. package/out/block.js.html +0 -183
  116. package/out/bn.js.html +0 -512
  117. package/out/ecdsa.js.html +0 -546
  118. package/out/fonts/OpenSans-Bold-webfont.eot +0 -0
  119. package/out/fonts/OpenSans-Bold-webfont.svg +0 -1830
  120. package/out/fonts/OpenSans-Bold-webfont.woff +0 -0
  121. package/out/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  122. package/out/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  123. package/out/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  124. package/out/fonts/OpenSans-Italic-webfont.eot +0 -0
  125. package/out/fonts/OpenSans-Italic-webfont.svg +0 -1830
  126. package/out/fonts/OpenSans-Italic-webfont.woff +0 -0
  127. package/out/fonts/OpenSans-Light-webfont.eot +0 -0
  128. package/out/fonts/OpenSans-Light-webfont.svg +0 -1831
  129. package/out/fonts/OpenSans-Light-webfont.woff +0 -0
  130. package/out/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  131. package/out/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  132. package/out/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  133. package/out/fonts/OpenSans-Regular-webfont.eot +0 -0
  134. package/out/fonts/OpenSans-Regular-webfont.svg +0 -1831
  135. package/out/fonts/OpenSans-Regular-webfont.woff +0 -0
  136. package/out/global.html +0 -220
  137. package/out/index.html +0 -128
  138. package/out/interp.js.html +0 -2064
  139. package/out/merkle.js.html +0 -143
  140. package/out/msg.js.html +0 -235
  141. package/out/priv-key.js.html +0 -208
  142. package/out/pub-key.js.html +0 -281
  143. package/out/script.js.html +0 -876
  144. package/out/scripts/linenumber.js +0 -25
  145. package/out/scripts/prettify/Apache-License-2.0.txt +0 -202
  146. package/out/scripts/prettify/lang-css.js +0 -2
  147. package/out/scripts/prettify/prettify.js +0 -28
  148. package/out/sig-operations.js.html +0 -171
  149. package/out/sig.js.html +0 -450
  150. package/out/struct.js.html +0 -440
  151. package/out/styles/jsdoc-default.css +0 -358
  152. package/out/styles/prettify-jsdoc.css +0 -111
  153. package/out/styles/prettify-tomorrow.css +0 -132
  154. package/out/tx-builder.js.html +0 -644
  155. package/out/tx-in.js.html +0 -223
  156. package/out/tx-verifier.js.html +0 -260
  157. package/out/tx.js.html +0 -481
  158. package/test/ach.js +0 -172
  159. package/test/address.js +0 -464
  160. package/test/aes.js +0 -96
  161. package/test/aescbc.js +0 -65
  162. package/test/base-58-check.js +0 -128
  163. package/test/base-58.js +0 -113
  164. package/test/bip-32.js +0 -721
  165. package/test/bip-39.js +0 -282
  166. package/test/block-header.js +0 -152
  167. package/test/block.js +0 -243
  168. package/test/bn.js +0 -643
  169. package/test/br.js +0 -353
  170. package/test/bsm.js +0 -141
  171. package/test/bw.js +0 -292
  172. package/test/cbc.js +0 -335
  173. package/test/cmp.js +0 -56
  174. package/test/data/bip69.json +0 -215
  175. package/test/data/bitcoind/base58_keys_invalid.json +0 -152
  176. package/test/data/bitcoind/base58_keys_valid.json +0 -452
  177. package/test/data/bitcoind/blocks.json +0 -27
  178. package/test/data/bitcoind/script_tests.json +0 -2244
  179. package/test/data/bitcoind/sig_canonical.json +0 -7
  180. package/test/data/bitcoind/sig_noncanonical.json +0 -22
  181. package/test/data/bitcoind/tx_invalid.json +0 -177
  182. package/test/data/bitcoind/tx_valid.json +0 -224
  183. package/test/data/blk86756-testnet.dat +0 -0
  184. package/test/data/blk86756-testnet.js +0 -12
  185. package/test/data/blk86756-testnet.json +0 -684
  186. package/test/data/ecdsa.json +0 -230
  187. package/test/data/messages.json +0 -22
  188. package/test/data/sighash.json +0 -1004
  189. package/test/data/tx_creation.json +0 -85
  190. package/test/ecdsa.js +0 -748
  191. package/test/ecies.js +0 -238
  192. package/test/global.js +0 -13
  193. package/test/hash-cache.js +0 -52
  194. package/test/hash.js +0 -354
  195. package/test/index.js +0 -10
  196. package/test/interp.js +0 -512
  197. package/test/inv.js +0 -65
  198. package/test/key-pair.js +0 -243
  199. package/test/merkle.js +0 -179
  200. package/test/msg.js +0 -295
  201. package/test/op-code.js +0 -79
  202. package/test/point.js +0 -375
  203. package/test/priv-key.js +0 -264
  204. package/test/pub-key.js +0 -549
  205. package/test/random.js +0 -31
  206. package/test/script.js +0 -1340
  207. package/test/sig-operations.js +0 -149
  208. package/test/sig.js +0 -662
  209. package/test/struct.js +0 -552
  210. package/test/tx-builder.js +0 -2104
  211. package/test/tx-in.js +0 -198
  212. package/test/tx-out-map.js +0 -104
  213. package/test/tx-out.js +0 -162
  214. package/test/tx-verifier.js +0 -246
  215. package/test/tx.js +0 -539
  216. package/test/var-int.js +0 -132
  217. package/test/vectors/aes.json +0 -10392
  218. package/test/vectors/aescbc.json +0 -620
  219. package/test/vectors/bip39.json +0 -502
  220. package/test/vectors/bip69.json +0 -215
  221. package/test/vectors/bitcoin-abc/script_tests.json +0 -48
  222. package/test/vectors/bitcoin-abc/sighash.json +0 -7004
  223. package/test/vectors/bitcoin-sv/script_tests.json +0 -248
  224. package/test/vectors/bitcoind/script_invalid.json +0 -1151
  225. package/test/vectors/bitcoind/script_valid.json +0 -1462
  226. package/test/vectors/bitcoind/sighash.json +0 -3503
  227. package/test/vectors/bitcoind/tx_invalid.json +0 -883
  228. package/test/vectors/bitcoind/tx_valid.json +0 -1150
  229. package/test/vectors/coolest-tx-ever-sent.json +0 -8
  230. package/test/vectors/ecdsa.json +0 -300
  231. package/test/vectors/hash.json +0 -6133
  232. package/test/vectors/kdf.json +0 -47
  233. package/test/vectors/largesttx.json +0 -5
  234. package/test/vectors/largesttxblock.json +0 -6
  235. package/test/vectors/sig.json +0 -79
  236. package/test/vectors/sighash-single-bug.json +0 -8
  237. package/test/version.js +0 -81
  238. package/test/workers-result.js +0 -89
  239. package/test/workers.js +0 -91
  240. package/test-index.js +0 -3
  241. package/vite.config.js +0 -36
package/entry.js DELETED
@@ -1,81 +0,0 @@
1
- /**
2
- * bsv
3
- * ===
4
- *
5
- * entry.js is the entry point for a the js bundlers.
6
- * Webpack and microbundlers, both start use this file as
7
- * the entry point to bundle the entire library.
8
- */
9
- import aes from 'aes'
10
- import bnjs from 'bn.js'
11
- import bs58 from 'bs58'
12
-
13
- import elliptic from 'bitcoin-elliptic'
14
- import hashjs from 'hash.js'
15
- import pbkdf2 from 'pbkdf2'
16
- import { Buffer } from 'buffer'
17
-
18
- import pkgInfo from './package.json' with { type: 'json' }
19
-
20
- // Dependencies, subject to change.
21
- const deps = {
22
- aes,
23
- bnjs,
24
- bs58,
25
- elliptic,
26
- hashjs,
27
- pbkdf2,
28
- Buffer
29
- }
30
-
31
- export { deps }
32
- const version = pkgInfo.version
33
- export { version }
34
-
35
- // Main bitcoin library - bitcoin protocols, standards, cryptography, and
36
- // utilities.
37
- export * from './lib/address'
38
-
39
- export * from './lib/bip-32'
40
- export * from './lib/bip-39'
41
- export * from './lib/bip-39-words'
42
- export * from './lib/bn'
43
- export * from './lib/br'
44
- export * from './lib/bsm'
45
- export * from './lib/bw'
46
- export * from './lib/base-58'
47
- export * from './lib/base-58-check'
48
- export * from './lib/block'
49
- export * from './lib/block-header'
50
- export * from './lib/constants'
51
- export * from './lib/ecdsa'
52
- export * from './lib/hash'
53
- export * from './lib/interp'
54
- export * from './lib/key-pair'
55
- export * from './lib/op-code'
56
- export * from './lib/point'
57
- export * from './lib/priv-key'
58
- export * from './lib/pub-key'
59
- export * from './lib/random'
60
- export * from './lib/script'
61
- export * from './lib/sig'
62
- export * from './lib/sig-operations'
63
- export * from './lib/struct'
64
- export * from './lib/tx'
65
- export * from './lib/tx-builder'
66
- export * from './lib/tx-in'
67
- export * from './lib/tx-out'
68
- export * from './lib/tx-out-map'
69
- export * from './lib/tx-verifier'
70
- export * from './lib/var-int'
71
- export * from './lib/workers'
72
- export * from './lib/workers-result'
73
- export * from './lib/cmp'
74
-
75
- // Encryption tools. Some bitcoin standards use Aes encryption, so that's why
76
- // these are available.
77
- export * from './lib/ach'
78
- export * from './lib/aes'
79
- export * from './lib/aescbc'
80
- export * from './lib/cbc'
81
- export * from './lib/ecies'
package/eslint.config.mjs DELETED
@@ -1,8 +0,0 @@
1
- import globals from "globals";
2
- import pluginJs from "@eslint/js";
3
-
4
-
5
- /** @type {import('eslint').Linter.Config[]} */
6
- export default [
7
- {languageOptions: { globals: {...globals.browser, ...globals.node} }},
8
- ];
package/index.js DELETED
@@ -1,98 +0,0 @@
1
- /**
2
- * bsv
3
- * ===
4
- *
5
- * index.js is an example of how to build a bundle with bsv. This
6
- * bundle includes the entire library, which uses the default configuration
7
- * (which is the same as Mainnet) and can be overridden. It also includes
8
- * Mainnet and Testnet configuration which are accessible even if you override
9
- * the defaults. It is not necessary to use Yours Bitcoin this way, since you
10
- * probably do not use every component, and therefore do not need to include
11
- * every component into your project. You can simply directly require the
12
- * elements of the library you need, and, if your project is browser-based,
13
- * browserify your project. For instance:
14
- * const Address = require('bsv/lib/address').
15
- */
16
- 'use strict'
17
- require('./lib/config')
18
-
19
- const bsv = module.exports
20
-
21
- bsv.version = require('./package').version
22
-
23
- // Main bitcoin library - bitcoin protocols, standards, cryptography, and
24
- // utilities.
25
- bsv.Address = require('./lib/address')
26
- bsv.Bip32 = require('./lib/bip-32')
27
- bsv.Bip39 = require('./lib/bip-39')
28
- bsv.Bn = require('./lib/bn')
29
- bsv.Br = require('./lib/br')
30
- bsv.Bsm = require('./lib/bsm')
31
- bsv.Bw = require('./lib/bw')
32
- bsv.Base58 = require('./lib/base-58')
33
- bsv.Base58Check = require('./lib/base-58-check')
34
- bsv.Block = require('./lib/block')
35
- bsv.BlockHeader = require('./lib/block-header')
36
- bsv.Constants = require('./lib/constants')
37
- bsv.Ecdsa = require('./lib/ecdsa')
38
- bsv.Hash = require('./lib/hash')
39
- bsv.Interp = require('./lib/interp')
40
- bsv.KeyPair = require('./lib/key-pair')
41
- bsv.OpCode = require('./lib/op-code')
42
- bsv.Point = require('./lib/point')
43
- bsv.PrivKey = require('./lib/priv-key')
44
- bsv.PubKey = require('./lib/pub-key')
45
- bsv.Random = require('./lib/random')
46
- bsv.Script = require('./lib/script')
47
- bsv.Sig = require('./lib/sig')
48
- bsv.SigOperations = require('./lib/sig-operations')
49
- bsv.Struct = require('./lib/struct')
50
- bsv.Tx = require('./lib/tx')
51
- bsv.TxBuilder = require('./lib/tx-builder')
52
- bsv.TxIn = require('./lib/tx-in')
53
- bsv.TxOut = require('./lib/tx-out')
54
- bsv.TxOutMap = require('./lib/tx-out-map')
55
- bsv.TxVerifier = require('./lib/tx-verifier')
56
- bsv.VarInt = require('./lib/var-int')
57
- bsv.Workers = require('./lib/workers')
58
- bsv.WorkersResult = require('./lib/workers-result')
59
- bsv.cmp = require('./lib/cmp')
60
-
61
- // Encryption tools. Some bitcoin standards use Aes encryption, so that's why
62
- // these are available.
63
- bsv.Ach = require('./lib/ach')
64
- bsv.Aes = require('./lib/aes')
65
- bsv.Aescbc = require('./lib/aescbc')
66
- bsv.Cbc = require('./lib/cbc')
67
- bsv.Ecies = require('./lib/ecies')
68
-
69
- // Dependencies, subject to change.
70
- bsv.deps = {}
71
- bsv.deps.aes = require('aes')
72
- bsv.deps.bnjs = require('bn.js')
73
- bsv.deps.bs58 = require('bs58')
74
- bsv.deps.Buffer = Buffer
75
- bsv.deps.elliptic = require('bitcoin-elliptic')
76
- bsv.deps.hashjs = require('hash.js')
77
- bsv.deps.pbkdf2compat = require('pbkdf2-compat')
78
-
79
- // Mainnet classes for your convenience (in case default is not what you want).
80
- const Mainnet = {}
81
- Object.keys(bsv).forEach(function (key) {
82
- Mainnet[key] = bsv[key].Mainnet
83
- ? bsv[key].Mainnet
84
- : bsv[key]
85
- })
86
-
87
- // Testnet classes for your convenience (in case default is not what you want).
88
- const Testnet = {}
89
- Object.keys(bsv).forEach(function (key) {
90
- Testnet[key] = bsv[key].Testnet
91
- ? bsv[key].Testnet
92
- : bsv[key]
93
- })
94
-
95
- bsv.Mainnet = Mainnet
96
- bsv.Testnet = Testnet
97
-
98
- bsv.env = import.meta.env
package/karma.conf.ts DELETED
@@ -1,77 +0,0 @@
1
- import webpack from 'webpack';
2
- // Karma configuration
3
- // Generated on Sat May 16 2020 20:12:10 GMT-0300 (Argentina Standard Time)
4
- export function (config) {
5
- config.set({
6
-
7
- // base path that will be used to resolve all patterns (eg. files, exclude)
8
- basePath: '',
9
-
10
- // frameworks to use
11
- // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
12
- frameworks: ['webpack', 'mocha'],
13
-
14
- // list of files / patterns to load in the browser
15
- files: [
16
- 'test/**/*.js'
17
- ],
18
-
19
- // list of files / patterns to exclude
20
- exclude: [
21
- ],
22
-
23
- // preprocess matching files before serving them to the browser
24
- // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
25
- preprocessors: {
26
- 'lib/**/*.js': [],
27
- 'test/**/*.js': ['webpack']
28
- },
29
-
30
- plugins: [
31
- require('karma-chrome-launcher'),
32
- require('karma-firefox-launcher'),
33
- require('karma-mocha'),
34
- require('karma-webpack')
35
- ],
36
-
37
- // test results reporter to use
38
- // possible values: 'dots', 'progress'
39
- // available reporters: https://npmjs.org/browse/keyword/karma-reporter
40
- reporters: ['progress'],
41
-
42
- // web server port
43
- port: 9876,
44
-
45
- // enable / disable colors in the output (reporters and logs)
46
- colors: true,
47
-
48
- // level of logging
49
- // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
50
- logLevel: config.LOG_INFO,
51
-
52
- // enable / disable watching file and executing tests whenever any file changes
53
- autoWatch: false,
54
-
55
- // start these browsers
56
- // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
57
- browsers: ['ChromeHeadless', 'FirefoxHeadless'],
58
-
59
- // Continuous Integration mode
60
- // if true, Karma captures browsers, runs the tests and exits
61
- singleRun: false,
62
-
63
- webpack: {
64
- mode: 'production',
65
- plugins: [
66
- new webpack.ProvidePlugin({
67
- process: 'process/browser',
68
- Buffer: ['buffer', 'Buffer']
69
- })
70
- ]
71
- },
72
-
73
- // Concurrency level
74
- // how many browser should be started simultaneous
75
- concurrency: Infinity
76
- })
77
- }
package/lib/ach.js DELETED
@@ -1,59 +0,0 @@
1
- /**
2
- * Ach (Aes+Cbc+Hmac) (experimental)
3
- * =================================
4
- *
5
- * An "encrypt-then-MAC" that uses Aes, Cbc and SHA256 Hmac. This is suitable
6
- * for general encryption of data.
7
- *
8
- * The encrypted data takes the form:
9
- * (256 bit hmac)(128 bit iv)(128+ bits Aes+Cbc encrypted message)
10
- */
11
- 'use strict'
12
-
13
- import { Aescbc } from './aescbc.js'
14
- import { Hash } from './hash.js'
15
- import { Random } from './random.js'
16
- import { Workers } from './workers.js'
17
- import { cmp } from './cmp.js'
18
-
19
- class Ach { }
20
-
21
- Ach.encrypt = function (messageBuf, cipherKeyBuf, ivBuf) {
22
- const encBuf = Aescbc.encrypt(messageBuf, cipherKeyBuf, ivBuf)
23
- const hmacbuf = Hash.sha256Hmac(encBuf, cipherKeyBuf)
24
- return Buffer.concat([hmacbuf, encBuf])
25
- }
26
-
27
- Ach.asyncEncrypt = async function (messageBuf, cipherKeyBuf, ivBuf) {
28
- if (!ivBuf) {
29
- ivBuf = Random.getRandomBuffer(128 / 8)
30
- }
31
- const args = [messageBuf, cipherKeyBuf, ivBuf]
32
- const workersResult = await Workers.asyncClassMethod(Ach, 'encrypt', args)
33
- return workersResult.resbuf
34
- }
35
-
36
- Ach.decrypt = function (encBuf, cipherKeyBuf) {
37
- if (encBuf.length < (256 + 128 + 128) / 8) {
38
- throw new Error(
39
- 'The encrypted data must be at least 256+128+128 bits, which is the length of the Hmac plus the iv plus the smallest encrypted data size'
40
- )
41
- }
42
- const hmacbuf = encBuf.slice(0, 256 / 8)
43
- encBuf = encBuf.slice(256 / 8, encBuf.length)
44
- const hmacbuf2 = Hash.sha256Hmac(encBuf, cipherKeyBuf)
45
- if (!cmp(hmacbuf, hmacbuf2)) {
46
- throw new Error(
47
- 'Message authentication failed - Hmacs are not equivalent'
48
- )
49
- }
50
- return Aescbc.decrypt(encBuf, cipherKeyBuf)
51
- }
52
-
53
- Ach.asyncDecrypt = async function (encBuf, cipherKeyBuf) {
54
- const args = [encBuf, cipherKeyBuf]
55
- const workersResult = await Workers.asyncClassMethod(Ach, 'decrypt', args)
56
- return workersResult.resbuf
57
- }
58
-
59
- export { Ach }
package/lib/address.js DELETED
@@ -1,266 +0,0 @@
1
- /**
2
- * Bitcoin Address
3
- * ===============
4
- *
5
- * A bitcoin address. Normal use cases:
6
- * const address = new Address().fromPubKey(pubKey)
7
- * const address = new Address().fromString(string)
8
- * const string = address.toString()
9
- * const script = address.toTxOutScript()
10
- * const isValid = Address.isValid(string)
11
- *
12
- * Can also do testnet:
13
- * const address = Address.Testnet()
14
- *
15
- * Note that an Address and an Addr are two completely different things. An
16
- * Address is what you send bitcoin to. An Addr is an ip address and port that
17
- * you connect to over the internet.
18
- */
19
- 'use strict'
20
-
21
- import { Base58Check } from './base-58-check.js'
22
- import { Constants } from './constants.js'
23
- import { Hash } from './hash.js'
24
- import { OpCode } from './op-code.js'
25
- import { PubKey } from './pub-key.js'
26
- import { PrivKey } from './priv-key.js'
27
- import { Script } from './script.js'
28
- import { Struct } from './struct.js'
29
- import { Workers } from './workers.js'
30
-
31
- class Address extends Struct {
32
- constructor (versionByteNum, hashBuf, constants = null) {
33
- super({ versionByteNum, hashBuf })
34
- constants = constants || Constants.Default.Address
35
- this.Constants = constants
36
- }
37
-
38
- fromBuffer (buf) {
39
- if (buf.length !== 1 + 20) {
40
- throw new Error('address buffers must be exactly 21 bytes')
41
- }
42
- if (
43
- buf[0] !== this.Constants.pubKeyHash
44
- ) {
45
- throw new Error('address: invalid versionByteNum byte')
46
- }
47
- this.versionByteNum = buf[0]
48
- this.hashBuf = buf.slice(1)
49
- return this
50
- }
51
-
52
- fromPubKeyHashBuf (hashBuf) {
53
- this.hashBuf = hashBuf
54
- this.versionByteNum = this.Constants.pubKeyHash
55
- return this
56
- }
57
-
58
- static fromPubKeyHashBuf (hashBuf) {
59
- return new this().fromPubKeyHashBuf(hashBuf)
60
- }
61
-
62
- fromPubKey (pubKey) {
63
- const hashBuf = Hash.sha256Ripemd160(pubKey.toBuffer())
64
- return this.fromPubKeyHashBuf(hashBuf)
65
- }
66
-
67
- static fromPubKey (pubKey) {
68
- return new this().fromPubKey(pubKey)
69
- }
70
-
71
- async asyncFromPubKey (pubKey) {
72
- const args = [pubKey]
73
- const workersResult = await Workers.asyncObjectMethod(
74
- this,
75
- 'fromPubKey',
76
- args
77
- )
78
- return this.fromFastBuffer(workersResult.resbuf)
79
- }
80
-
81
- static asyncFromPubKey (pubKey) {
82
- return new this().asyncFromPubKey(pubKey)
83
- }
84
-
85
- fromPrivKey (privKey) {
86
- const pubKey = new PubKey().fromPrivKey(privKey)
87
- const hashBuf = Hash.sha256Ripemd160(pubKey.toBuffer())
88
- return this.fromPubKeyHashBuf(hashBuf)
89
- }
90
-
91
- static fromPrivKey (privKey) {
92
- return new this().fromPrivKey(privKey)
93
- }
94
-
95
- async asyncFromPrivKey (privKey) {
96
- const args = [privKey]
97
- const workersResult = await Workers.asyncObjectMethod(
98
- this,
99
- 'fromPrivKey',
100
- args
101
- )
102
- return this.fromFastBuffer(workersResult.resbuf)
103
- }
104
-
105
- static asyncFromPrivKey (privKey) {
106
- return new this().fromPrivKey(privKey)
107
- }
108
-
109
- fromRandom () {
110
- const randomPrivKey = new PrivKey().fromRandom()
111
- return this.fromPrivKey(randomPrivKey)
112
- }
113
-
114
- static fromRandom () {
115
- return new this().fromRandom()
116
- }
117
-
118
- async asyncFromRandom () {
119
- const args = []
120
- const workersResult = await Workers.asyncObjectMethod(
121
- this,
122
- 'fromRandom',
123
- args
124
- )
125
- return this.fromFastBuffer(workersResult.resbuf)
126
- }
127
-
128
- static asyncFromRandom () {
129
- return new this().fromRandom()
130
- }
131
-
132
- fromString (str) {
133
- const buf = Base58Check.decode(str)
134
- return this.fromBuffer(buf)
135
- }
136
-
137
- async asyncFromString (str) {
138
- const args = [str]
139
- const workersResult = await Workers.asyncObjectMethod(
140
- this,
141
- 'fromString',
142
- args
143
- )
144
- return this.fromFastBuffer(workersResult.resbuf)
145
- }
146
-
147
- static asyncFromString (str) {
148
- return new this().asyncFromString(str)
149
- }
150
-
151
- static isValid (addrstr) {
152
- let address
153
- try {
154
- address = new Address().fromString(addrstr)
155
-
156
- } catch (e) {
157
- return false
158
- }
159
- return address.isValid()
160
- }
161
-
162
- isValid () {
163
- try {
164
- this.validate()
165
- return true
166
-
167
- } catch (e) {
168
- return false
169
- }
170
- }
171
-
172
- toTxOutScript () {
173
- const script = new Script()
174
- script.writeOpCode(OpCode.OP_DUP)
175
- script.writeOpCode(OpCode.OP_HASH160)
176
- script.writeBuffer(this.hashBuf)
177
- script.writeOpCode(OpCode.OP_EQUALVERIFY)
178
- script.writeOpCode(OpCode.OP_CHECKSIG)
179
-
180
- return script
181
- }
182
-
183
- fromTxInScript (script) {
184
- const pubKeyHashBuf = Hash.sha256Ripemd160(script.chunks[1].buf || Buffer.from('00'.repeat(32), 'hex'))
185
- return this.fromPubKeyHashBuf(pubKeyHashBuf)
186
- }
187
-
188
- static fromTxInScript (script) {
189
- return new this().fromTxInScript(script)
190
- }
191
-
192
- fromTxOutScript (script) {
193
- return this.fromPubKeyHashBuf(script.chunks[2].buf)
194
- }
195
-
196
- static fromTxOutScript (script) {
197
- return new this().fromTxOutScript(script)
198
- }
199
-
200
- toBuffer () {
201
- const versionByteBuf = Buffer.from([this.versionByteNum])
202
- const buf = Buffer.concat([versionByteBuf, this.hashBuf])
203
- return buf
204
- }
205
-
206
- toJSON () {
207
- const json = {}
208
- if (this.hashBuf) {
209
- json.hashBuf = this.hashBuf.toString('hex')
210
- }
211
- if (typeof this.versionByteNum !== 'undefined') {
212
- json.versionByteNum = this.versionByteNum
213
- }
214
- return json
215
- }
216
-
217
- fromJSON (json) {
218
- if (json.hashBuf) {
219
- this.hashBuf = Buffer.from(json.hashBuf, 'hex')
220
- }
221
- if (typeof json.versionByteNum !== 'undefined') {
222
- this.versionByteNum = json.versionByteNum
223
- }
224
- return this
225
- }
226
-
227
- toString () {
228
- return Base58Check.encode(this.toBuffer())
229
- }
230
-
231
- async asyncToString () {
232
- const args = []
233
- const workersResult = await Workers.asyncObjectMethod(
234
- this,
235
- 'toString',
236
- args
237
- )
238
- return JSON.parse(workersResult.resbuf.toString())
239
- }
240
-
241
- validate () {
242
- if (!Buffer.isBuffer(this.hashBuf) || this.hashBuf.length !== 20) {
243
- throw new Error('hashBuf must be a buffer of 20 bytes')
244
- }
245
- if (
246
- this.versionByteNum !== this.Constants.pubKeyHash
247
- ) {
248
- throw new Error('invalid versionByteNum')
249
- }
250
- return this
251
- }
252
- }
253
-
254
- Address.Mainnet = class extends Address {
255
- constructor (versionByteNum, hashBuf) {
256
- super(versionByteNum, hashBuf, Constants.Mainnet.Address)
257
- }
258
- }
259
-
260
- Address.Testnet = class extends Address {
261
- constructor (versionByteNum, hashBuf) {
262
- super(versionByteNum, hashBuf, Constants.Testnet.Address)
263
- }
264
- }
265
-
266
- export { Address }
package/lib/aes.js DELETED
@@ -1,57 +0,0 @@
1
- /**
2
- * Aes (experimental)
3
- * ==================
4
- *
5
- * Advanced Encryption Standard (Aes). This is a low-level tool for encrypting
6
- * or decrypting blocks of data. There is almost never a reason to use this -
7
- * don't use it unless you need to encrypt or decrypt individual blocks.
8
- */
9
- 'use strict'
10
-
11
- import _Aes from 'aes'
12
-
13
- class Aes { }
14
-
15
- Aes.encrypt = function (messageBuf, keyBuf) {
16
- const key = Aes.buf2Words(keyBuf)
17
- const message = Aes.buf2Words(messageBuf)
18
- const a = new _Aes(key)
19
- const enc = a.encrypt(message)
20
- const encBuf = Aes.words2Buf(enc)
21
- return encBuf
22
- }
23
-
24
- Aes.decrypt = function (encBuf, keyBuf) {
25
- const enc = Aes.buf2Words(encBuf)
26
- const key = Aes.buf2Words(keyBuf)
27
- const a = new _Aes(key)
28
- const message = a.decrypt(enc)
29
- const messageBuf = Aes.words2Buf(message)
30
- return messageBuf
31
- }
32
-
33
- Aes.buf2Words = function (buf) {
34
- if (buf.length % 4) {
35
- throw new Error('buf length must be a multiple of 4')
36
- }
37
-
38
- const words = []
39
-
40
- for (let i = 0; i < buf.length / 4; i++) {
41
- words.push(buf.readUInt32BE(i * 4))
42
- }
43
-
44
- return words
45
- }
46
-
47
- Aes.words2Buf = function (words) {
48
- const buf = Buffer.alloc(words.length * 4)
49
-
50
- for (let i = 0; i < words.length; i++) {
51
- buf.writeUInt32BE(words[i], i * 4)
52
- }
53
-
54
- return buf
55
- }
56
-
57
- export { Aes }
package/lib/aescbc.js DELETED
@@ -1,38 +0,0 @@
1
- /**
2
- * Aescbc (experimental)
3
- * =====================
4
- *
5
- * This is a convenience class for using Aes with Cbc. This is a low-level tool
6
- * that does not include authentication. You should only use this if you are
7
- * authenticating your data somehow else.
8
- */
9
- 'use strict'
10
-
11
- import { Aes } from './aes.js'
12
- import { Cbc } from './cbc.js'
13
- import { Random } from './random.js'
14
-
15
- class Aescbc { }
16
-
17
- Aescbc.encrypt = function (messageBuf, cipherKeyBuf, ivBuf, concatIvBuf = true) {
18
- ivBuf = ivBuf || Random.getRandomBuffer(128 / 8)
19
- const ctBuf = Cbc.encrypt(messageBuf, ivBuf, Aes, cipherKeyBuf)
20
- if (concatIvBuf) {
21
- return Buffer.concat([ivBuf, ctBuf])
22
- } else {
23
- return ctBuf
24
- }
25
- }
26
-
27
- Aescbc.decrypt = function (encBuf, cipherKeyBuf, ivBuf = false) {
28
- if (!ivBuf) {
29
- const ivBuf = encBuf.slice(0, 128 / 8)
30
- const ctBuf = encBuf.slice(128 / 8)
31
- return Cbc.decrypt(ctBuf, ivBuf, Aes, cipherKeyBuf)
32
- } else {
33
- const ctBuf = encBuf
34
- return Cbc.decrypt(ctBuf, ivBuf, Aes, cipherKeyBuf)
35
- }
36
- }
37
-
38
- export { Aescbc }