@alephium/web3 0.0.3

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 (59) hide show
  1. package/.gitattributes +1 -0
  2. package/LICENSE +165 -0
  3. package/README.md +136 -0
  4. package/contracts/add.ral +12 -0
  5. package/contracts/greeter-main.ral +8 -0
  6. package/contracts/greeter.ral +5 -0
  7. package/contracts/main.ral +8 -0
  8. package/contracts/sub.ral +9 -0
  9. package/dev/user.conf +24 -0
  10. package/dist/alephium-web3.min.js +3 -0
  11. package/dist/alephium-web3.min.js.LICENSE.txt +27 -0
  12. package/dist/alephium-web3.min.js.map +1 -0
  13. package/dist/api/api-alephium.d.ts +1292 -0
  14. package/dist/api/api-alephium.js +761 -0
  15. package/dist/api/api-explorer.d.ts +350 -0
  16. package/dist/api/api-explorer.js +297 -0
  17. package/dist/cli/create-project.d.ts +2 -0
  18. package/dist/cli/create-project.js +87 -0
  19. package/dist/lib/address.d.ts +1 -0
  20. package/dist/lib/address.js +42 -0
  21. package/dist/lib/bs58.d.ts +4 -0
  22. package/dist/lib/bs58.js +26 -0
  23. package/dist/lib/clique.d.ts +23 -0
  24. package/dist/lib/clique.js +149 -0
  25. package/dist/lib/constants.d.ts +2 -0
  26. package/dist/lib/constants.js +22 -0
  27. package/dist/lib/contract.d.ts +152 -0
  28. package/dist/lib/contract.js +711 -0
  29. package/dist/lib/djb2.d.ts +1 -0
  30. package/dist/lib/djb2.js +27 -0
  31. package/dist/lib/explorer.d.ts +8 -0
  32. package/dist/lib/explorer.js +46 -0
  33. package/dist/lib/index.d.ts +12 -0
  34. package/dist/lib/index.js +60 -0
  35. package/dist/lib/node.d.ts +10 -0
  36. package/dist/lib/node.js +64 -0
  37. package/dist/lib/numbers.d.ts +7 -0
  38. package/dist/lib/numbers.js +128 -0
  39. package/dist/lib/password-crypto.d.ts +2 -0
  40. package/dist/lib/password-crypto.js +68 -0
  41. package/dist/lib/signer.d.ts +17 -0
  42. package/dist/lib/signer.js +70 -0
  43. package/dist/lib/storage-browser.d.ts +9 -0
  44. package/dist/lib/storage-browser.js +52 -0
  45. package/dist/lib/storage-node.d.ts +9 -0
  46. package/dist/lib/storage-node.js +65 -0
  47. package/dist/lib/utils.d.ts +11 -0
  48. package/dist/lib/utils.js +135 -0
  49. package/dist/lib/wallet.d.ts +30 -0
  50. package/dist/lib/wallet.js +142 -0
  51. package/gitignore +9 -0
  52. package/package.json +113 -0
  53. package/scripts/check-versions.js +45 -0
  54. package/scripts/rename-gitignore.js +24 -0
  55. package/scripts/start-devnet.js +141 -0
  56. package/scripts/stop-devnet.js +32 -0
  57. package/templates/README.md +34 -0
  58. package/templates/package.json +29 -0
  59. package/webpack.config.js +57 -0
@@ -0,0 +1,141 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ const fs = require('fs')
20
+ const process = require('process')
21
+ const path = require('path')
22
+ const fetch = require('cross-fetch')
23
+ const spawn = require('child_process').spawn
24
+
25
+ async function _downloadFullNode(tag, fileName) {
26
+ const url = `https://github.com/alephium/alephium/releases/download/v${tag}/alephium-${tag}.jar`
27
+ const res0 = await fetch(url)
28
+ const fileUrl = res0.url
29
+ const res1 = await fetch(fileUrl)
30
+ await new Promise((resolve) => {
31
+ console.log(`Downloading jar file to: ${fileName}`)
32
+ const file = fs.createWriteStream(fileName)
33
+ res1.body.pipe(file)
34
+ file.on('finish', function () {
35
+ resolve()
36
+ })
37
+ })
38
+ }
39
+
40
+ async function downloadFullNode(tag, devDir, jarFile) {
41
+ if (!fs.existsSync(devDir)) {
42
+ fs.mkdirSync(devDir)
43
+ }
44
+ const jarExisted = fs.existsSync(jarFile)
45
+ if (!jarExisted) {
46
+ await _downloadFullNode(tag, jarFile)
47
+ }
48
+ }
49
+
50
+ function launchDevnet(devDir, jarFile) {
51
+ const pidFile = devDir + path.sep + 'alephium.pid'
52
+ try {
53
+ const pid = parseInt(fs.readFileSync(pidFile).toString())
54
+ if (pid) {
55
+ console.log(`Clearing the running devnet: ${pid}`)
56
+ process.kill(pid)
57
+ }
58
+ } catch (e) {
59
+ console.log(`Error in clearing the running devnet: ${e}`)
60
+ }
61
+ fs.rmSync(devDir + path.sep + 'logs', { recursive: true, force: true })
62
+ fs.rmSync(devDir + path.sep + 'network-4', { recursive: true, force: true })
63
+
64
+ const p = spawn('java', ['-jar', jarFile], {
65
+ detached: true,
66
+ stdio: 'ignore',
67
+ env: { ...process.env, ALEPHIUM_HOME: devDir, ALEPHIUM_ENABLE_DEBUG_LOGGING: 'true' }
68
+ })
69
+ p.unref()
70
+ console.log(`Devnet is launching with pid: ${p.pid}`)
71
+ fs.writeFileSync(devDir + path.sep + 'alephium.pid', p.pid.toString(), { falg: 'w' })
72
+ }
73
+
74
+ const testWallet = 'alephium-js-sdk-test-only-wallet'
75
+ const password = 'alph'
76
+ const mnemonic =
77
+ 'vault vault vault vault vault vault vault vault vault vault vault vault vault vault vault vault vault vault vault vault vault vault vault vault'
78
+
79
+ async function prepareWallet() {
80
+ const wallets = await fetch('http://127.0.0.1:22973/wallets', { method: 'Get' }).then((res) => res.json())
81
+ if (wallets.find((wallet) => wallet.walletName === testWallet)) {
82
+ unlockWallet()
83
+ } else {
84
+ createWallet()
85
+ }
86
+ }
87
+
88
+ async function createWallet() {
89
+ console.log('Create the test wallet')
90
+ await fetch('http://127.0.0.1:22973/wallets', {
91
+ method: 'Put',
92
+ body: `{"password":"${password}","mnemonic":"${mnemonic}","walletName":"${testWallet}"}`
93
+ })
94
+ }
95
+
96
+ async function unlockWallet() {
97
+ console.log('Unlock the test wallet')
98
+ await fetch('http://127.0.0.1:22973/wallets/alephium-js-sdk-test-only-wallet/unlock', {
99
+ method: 'POST',
100
+ body: '{ "password": "alph" }'
101
+ })
102
+ }
103
+
104
+ function timeout(ms) {
105
+ return new Promise((resolve) => setTimeout(resolve, ms))
106
+ }
107
+
108
+ async function wait() {
109
+ console.log('...')
110
+ try {
111
+ const res = await fetch('http://127.0.0.1:22973/infos/node', { method: 'Get' })
112
+ if (res.status != 200) {
113
+ await timeout(1000)
114
+ await wait()
115
+ } else {
116
+ console.log('Devnet is ready')
117
+ await timeout(1000)
118
+ new Promise((resolve) => {
119
+ resolve()
120
+ })
121
+ }
122
+ } catch (err) {
123
+ await timeout(1000)
124
+ await wait()
125
+ }
126
+ }
127
+
128
+ async function main() {
129
+ const tag = process.argv[2]
130
+ console.log(`Full node version: ${tag}`)
131
+ const devDir = path.resolve(process.cwd() + path.sep + 'dev')
132
+ const jarFile = `${devDir}${path.sep}alephium-${tag}.jar`
133
+
134
+ console.log(`Dev folder: ${devDir}`)
135
+ await downloadFullNode(tag, devDir, jarFile)
136
+ launchDevnet(devDir, jarFile)
137
+ await wait()
138
+ await prepareWallet()
139
+ }
140
+
141
+ main()
@@ -0,0 +1,32 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ const fs = require('fs')
20
+ const process = require('process')
21
+ const path = require('path')
22
+
23
+ const pidFile = process.cwd() + path.sep + 'dev' + path.sep + 'alephium.pid'
24
+ try {
25
+ const pid = parseInt(fs.readFileSync(pidFile).toString())
26
+ if (pid) {
27
+ console.log(`Stopping the running devnet: ${pid}`)
28
+ process.kill(pid)
29
+ }
30
+ } catch (e) {
31
+ console.log(`Error in stopping the running devnet: ${e}`)
32
+ }
@@ -0,0 +1,34 @@
1
+ # My dApp
2
+
3
+ ## Install
4
+
5
+ ```
6
+ npm install
7
+ ```
8
+
9
+ ## Compile
10
+
11
+ Compile the TypeScript files into JavaScript:
12
+
13
+ ```
14
+ npm run compile
15
+ ```
16
+
17
+ ## Start a devnet
18
+
19
+ ```
20
+ npm run devnet:start // this will start a devnet for smart contract tests
21
+ ```
22
+
23
+ ## Stop/restart devnet
24
+
25
+ ```
26
+ npm run devnet:stop
27
+ npm run devnet:restart
28
+ ```
29
+
30
+ ## Testing
31
+
32
+ ```
33
+ npm test
34
+ ```
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "my-dapp-template",
3
+ "version": "0.0.0",
4
+ "license": "GPL",
5
+ "type": "commonjs",
6
+ "files": [
7
+ "dist/*"
8
+ ],
9
+ "config": {
10
+ "alephium_version": "1.3.0"
11
+ },
12
+ "scripts": {
13
+ "compile": "rm -rf dist && npx tsc --build .",
14
+ "devnet:start": "node scripts/start-devnet.js ${npm_package_config_alephium_version}",
15
+ "devnet:stop": "node scripts/stop-devnet.js"
16
+ },
17
+ "dependencies": {
18
+ "@alephium/sdk": "~0.0.1"
19
+ },
20
+ "devDependencies": {
21
+ "@types/elliptic": "^6.4.13",
22
+ "@types/node": "^16.7.8",
23
+ "typescript": "^4.4.2"
24
+ },
25
+ "engines": {
26
+ "node": ">=14.0.0",
27
+ "npm": ">=7.0.0"
28
+ }
29
+ }
@@ -0,0 +1,57 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ const webpack = require('webpack')
20
+
21
+ module.exports = {
22
+ mode: 'production',
23
+ entry: {
24
+ alephium: './dist/lib/index.js'
25
+ },
26
+ plugins: [
27
+ new webpack.SourceMapDevToolPlugin({ filename: '[file].map' }),
28
+ new webpack.ProvidePlugin({
29
+ Buffer: ['buffer', 'Buffer']
30
+ }),
31
+ new webpack.IgnorePlugin({
32
+ checkResource(resource) {
33
+ // The "bip39/src/wordlists" node module consists of json files for multiple languages. We only need English.
34
+ return /.*\/wordlists\/(?!english).*\.json/.test(resource)
35
+ }
36
+ })
37
+ ],
38
+ resolve: {
39
+ extensions: ['.js'],
40
+ fallback: {
41
+ fs: false,
42
+ stream: require.resolve('stream-browserify'),
43
+ crypto: require.resolve('crypto-browserify'),
44
+ buffer: require.resolve('buffer/')
45
+ }
46
+ },
47
+ output: {
48
+ filename: 'alephium-web3.min.js',
49
+ library: {
50
+ name: 'alephium',
51
+ type: 'umd'
52
+ }
53
+ },
54
+ optimization: {
55
+ minimize: true
56
+ }
57
+ }