@alephium/web3 0.2.0-rc.8 → 0.2.0-test.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 (75) hide show
  1. package/.eslintignore +2 -2
  2. package/.eslintrc.json +21 -0
  3. package/LICENSE +165 -0
  4. package/README.md +135 -2
  5. package/contracts/add/add.ral +13 -0
  6. package/contracts/greeter_main.ral +1 -1
  7. package/contracts/main.ral +4 -0
  8. package/contracts/sub/sub.ral +10 -0
  9. package/contracts/test/metadata.ral +18 -0
  10. package/contracts/test/warnings.ral +8 -0
  11. package/dist/alephium-web3.min.js +1 -1
  12. package/dist/alephium-web3.min.js.LICENSE.txt +17 -0
  13. package/dist/alephium-web3.min.js.map +1 -1
  14. package/dist/scripts/create-project.js +1 -1
  15. package/dist/src/api/api-alephium.d.ts +6 -19
  16. package/dist/src/api/api-explorer.d.ts +16 -16
  17. package/dist/src/api/index.js +1 -5
  18. package/dist/src/contract/contract.d.ts +16 -31
  19. package/dist/src/contract/contract.js +96 -123
  20. package/dist/src/contract/index.js +1 -5
  21. package/dist/src/index.d.ts +0 -1
  22. package/dist/src/index.js +1 -19
  23. package/dist/src/signer/index.d.ts +1 -0
  24. package/dist/src/signer/index.js +2 -5
  25. package/dist/src/signer/node-wallet.d.ts +11 -0
  26. package/dist/src/signer/node-wallet.js +57 -0
  27. package/dist/src/signer/signer.js +1 -5
  28. package/dist/src/test/index.d.ts +6 -0
  29. package/dist/src/test/index.js +41 -0
  30. package/dist/src/test/privatekey-wallet.d.ts +11 -0
  31. package/dist/src/test/privatekey-wallet.js +68 -0
  32. package/dist/src/transaction/index.d.ts +1 -0
  33. package/dist/src/transaction/index.js +2 -5
  34. package/dist/src/transaction/sign-verify.d.ts +2 -0
  35. package/dist/src/transaction/sign-verify.js +58 -0
  36. package/dist/src/utils/index.d.ts +1 -0
  37. package/dist/src/utils/index.js +2 -5
  38. package/dist/src/utils/password-crypto.d.ts +2 -0
  39. package/dist/src/utils/password-crypto.js +69 -0
  40. package/dist/src/utils/utils.d.ts +2 -3
  41. package/dist/src/utils/utils.js +15 -16
  42. package/gitignore +9 -0
  43. package/package.json +32 -6
  44. package/scripts/create-project.ts +1 -1
  45. package/src/api/api-alephium.ts +0 -14
  46. package/src/contract/contract.ts +102 -176
  47. package/src/contract/ralph.test.ts +178 -0
  48. package/src/fixtures/address.json +36 -0
  49. package/src/fixtures/balance.json +9 -0
  50. package/src/fixtures/self-clique.json +19 -0
  51. package/src/fixtures/transaction.json +13 -0
  52. package/src/fixtures/transactions.json +179 -0
  53. package/src/index.ts +0 -2
  54. package/src/signer/fixtures/genesis.json +26 -0
  55. package/src/signer/fixtures/wallets.json +26 -0
  56. package/src/signer/index.ts +1 -0
  57. package/src/signer/node-wallet.ts +65 -0
  58. package/src/test/index.ts +31 -0
  59. package/src/test/privatekey-wallet.ts +57 -0
  60. package/src/transaction/index.ts +1 -0
  61. package/src/transaction/sign-verify.test.ts +50 -0
  62. package/src/transaction/sign-verify.ts +39 -0
  63. package/src/utils/address.test.ts +47 -0
  64. package/src/utils/djb2.test.ts +35 -0
  65. package/src/utils/index.ts +1 -0
  66. package/src/utils/password-crypto.test.ts +27 -0
  67. package/src/utils/password-crypto.ts +77 -0
  68. package/src/utils/utils.test.ts +161 -0
  69. package/src/utils/utils.ts +7 -7
  70. package/templates/base/package.json +1 -1
  71. package/templates/react/package.json +1 -1
  72. package/test/contract.test.ts +213 -0
  73. package/test/events.test.ts +141 -0
  74. package/test/transaction.test.ts +73 -0
  75. package/jest-config.json +0 -11
@@ -0,0 +1,178 @@
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
+ import { node } from '../api'
20
+ import * as ralph from './ralph'
21
+ import * as utils from '../utils'
22
+ import { Fields } from './contract'
23
+
24
+ describe('contract', function () {
25
+ it('should encode I256', async () => {
26
+ function test(i256: bigint, expected: string) {
27
+ expect(utils.binToHex(ralph.encodeI256(i256))).toEqual(expected)
28
+ }
29
+ test(BigInt('0'), '00')
30
+ test(BigInt('1'), '01')
31
+ test(BigInt('2'), '02')
32
+ test(BigInt('-1'), '3f')
33
+ test(BigInt('-2'), '3e')
34
+ test(BigInt('32'), '4020')
35
+ test(BigInt('33'), '4021')
36
+ test(BigInt('34'), '4022')
37
+ test(BigInt('31'), '1f')
38
+ test(BigInt('30'), '1e')
39
+ test(BigInt('8192'), '80002000')
40
+ test(BigInt('8193'), '80002001')
41
+ test(BigInt('8194'), '80002002')
42
+ test(BigInt('8191'), '5fff')
43
+ test(BigInt('8190'), '5ffe')
44
+ test(BigInt('536870912'), 'c020000000')
45
+ test(BigInt('536870913'), 'c020000001')
46
+ test(BigInt('536870914'), 'c020000002')
47
+ test(BigInt('536870911'), '9fffffff')
48
+ test(BigInt('536870910'), '9ffffffe')
49
+ test(
50
+ BigInt('57896044618658097711785492504343953926634992332820282019728792003956564819967'),
51
+ 'dc7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
52
+ )
53
+ test(
54
+ BigInt('57896044618658097711785492504343953926634992332820282019728792003956564819966'),
55
+ 'dc7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe'
56
+ )
57
+ test(
58
+ BigInt('57896044618658097711785492504343953926634992332820282019728792003956564819965'),
59
+ 'dc7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'
60
+ )
61
+ test(
62
+ BigInt('-57896044618658097711785492504343953926634992332820282019728792003956564819968'),
63
+ 'dc8000000000000000000000000000000000000000000000000000000000000000'
64
+ )
65
+ test(
66
+ BigInt('-57896044618658097711785492504343953926634992332820282019728792003956564819967'),
67
+ 'dc8000000000000000000000000000000000000000000000000000000000000001'
68
+ )
69
+ test(
70
+ BigInt('-57896044618658097711785492504343953926634992332820282019728792003956564819966'),
71
+ 'dc8000000000000000000000000000000000000000000000000000000000000002'
72
+ )
73
+
74
+ function fail(n: bigint) {
75
+ expect(() => ralph.encodeI256(n)).toThrow()
76
+ }
77
+ fail(BigInt('57896044618658097711785492504343953926634992332820282019728792003956564819968'))
78
+ fail(BigInt('57896044618658097711785492504343953926634992332820282019728792003956564819969'))
79
+ fail(BigInt('-57896044618658097711785492504343953926634992332820282019728792003956564819969'))
80
+ fail(BigInt('-57896044618658097711785492504343953926634992332820282019728792003956564819970'))
81
+ })
82
+
83
+ it('should encode U256', async () => {
84
+ function test(u256: bigint, expected: string) {
85
+ expect(utils.binToHex(ralph.encodeU256(u256))).toEqual(expected)
86
+ }
87
+ test(BigInt('0'), '00')
88
+ test(BigInt('1'), '01')
89
+ test(BigInt('2'), '02')
90
+ fail(BigInt('-1'))
91
+ fail(BigInt('-2'))
92
+ test(BigInt('64'), '4040')
93
+ test(BigInt('65'), '4041')
94
+ test(BigInt('66'), '4042')
95
+ test(BigInt('63'), '3f')
96
+ test(BigInt('62'), '3e')
97
+ test(BigInt('16384'), '80004000')
98
+ test(BigInt('16385'), '80004001')
99
+ test(BigInt('16386'), '80004002')
100
+ test(BigInt('16383'), '7fff')
101
+ test(BigInt('16382'), '7ffe')
102
+ test(BigInt('1073741824'), 'c040000000')
103
+ test(BigInt('1073741825'), 'c040000001')
104
+ test(BigInt('1073741826'), 'c040000002')
105
+ test(BigInt('1073741823'), 'bfffffff')
106
+ test(BigInt('1073741822'), 'bffffffe')
107
+ test(
108
+ BigInt('115792089237316195423570985008687907853269984665640564039457584007913129639935'),
109
+ 'dcffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
110
+ )
111
+ test(
112
+ BigInt('115792089237316195423570985008687907853269984665640564039457584007913129639934'),
113
+ 'dcfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe'
114
+ )
115
+ test(
116
+ BigInt('115792089237316195423570985008687907853269984665640564039457584007913129639933'),
117
+ 'dcfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'
118
+ )
119
+
120
+ function fail(n: bigint) {
121
+ expect(() => ralph.encodeU256(n)).toThrow()
122
+ }
123
+ fail(BigInt('115792089237316195423570985008687907853269984665640564039457584007913129639936'))
124
+ fail(BigInt('115792089237316195423570985008687907853269984665640564039457584007913129639937'))
125
+ })
126
+
127
+ it('should encode ByteVec', async () => {
128
+ const bytes = 'b382fc88aa31d63f4c2f3f8a03715ba2a629552e85431fb1c1d909bab46d1aae'
129
+ const bytecode = ralph.encodeScriptFieldAsString('ByteVec', bytes)
130
+ expect(bytecode).toEqual('144020b382fc88aa31d63f4c2f3f8a03715ba2a629552e85431fb1c1d909bab46d1aae')
131
+ })
132
+
133
+ it('should test buildScriptByteCode', async () => {
134
+ const variables = { x: true, y: 0x05, z: 'ff', a: '1C2RAVWSuaXw8xtUxqVERR7ChKBE1XgscNFw73NSHE1v3' }
135
+ const fieldsSig: node.FieldsSig = {
136
+ names: ['x', 'y', 'z', 'a'],
137
+ types: ['Bool', 'U256', 'ByteVec', 'Address'],
138
+ isMutable: [false, false, false, false]
139
+ }
140
+ const bytecode = ralph.buildScriptByteCode('-{0}-{1}-{2}-{3}-', variables, fieldsSig)
141
+ expect(bytecode).toEqual('-03-1305-1401ff-1500a3cd757be03c7dac8d48bf79e2a7d6e735e018a9c054b99138c7b29738c437ec-')
142
+ })
143
+
144
+ it('should test buildContractByteCode', async () => {
145
+ const fields: Fields = {
146
+ a: -1,
147
+ b: 1,
148
+ c: '23',
149
+ d: '1C2RAVWSuaXw8xtUxqVERR7ChKBE1XgscNFw73NSHE1v3',
150
+ e: [false, true]
151
+ }
152
+ const fieldsSig: node.FieldsSig = {
153
+ names: ['a', 'b', 'c', 'd', 'e'],
154
+ types: ['I256', 'U256', 'ByteVec', 'Address', '[Bool;2]'],
155
+ isMutable: [false, false, false, false]
156
+ }
157
+ const encoded = ralph.buildContractByteCode('ff', fields, fieldsSig)
158
+ expect(encoded).toEqual(
159
+ 'ff06013f02010301230400a3cd757be03c7dac8d48bf79e2a7d6e735e018a9c054b99138c7b29738c437ec00000001'
160
+ )
161
+ })
162
+
163
+ // it('should test buildByteCode', async () => {
164
+ // const compiled = {
165
+ // type: 'TemplateContractByteCode',
166
+ // filedLength: 1,
167
+ // methodsByteCode: [
168
+ // '01000203021205160016015f{subContractId:ByteVec}1702a00016002a16012aa100a000160016011602010002',
169
+ // '00000202020416001601000002'
170
+ // ]
171
+ // }
172
+ // const variables = { subContractId: '55834baf25f40fe5a8d6ac83c5f2b76a1677ed3ddbd6a79c4dea274992982e2b' }
173
+ // const bytecode = ralph.buildContractByteCode(compiled, variables)
174
+ // expect(bytecode).toEqual(
175
+ // '01024046405301000203021205160016015f14402055834baf25f40fe5a8d6ac83c5f2b76a1677ed3ddbd6a79c4dea274992982e2b1702a00016002a16012aa100a00016001601160201000200000202020416001601000002'
176
+ // )
177
+ // })
178
+ })
@@ -0,0 +1,36 @@
1
+ {
2
+ "hash": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
3
+ "details": {
4
+ "balance": "string",
5
+ "txNumber": 0
6
+ },
7
+ "transactions": [
8
+ {
9
+ "hash": "string",
10
+ "blockHash": "string",
11
+ "timestamp": 0,
12
+ "inputs": [
13
+ {
14
+ "outputRef": {
15
+ "hint": 0,
16
+ "key": "string"
17
+ },
18
+ "unlockScript": "string",
19
+ "txHashRef": "string",
20
+ "address": "string",
21
+ "amount": "string"
22
+ }
23
+ ],
24
+ "outputs": [
25
+ {
26
+ "amount": "string",
27
+ "address": "string",
28
+ "lockTime": 0,
29
+ "spent": "string"
30
+ }
31
+ ],
32
+ "gasAmount": 0,
33
+ "gasPrice": "string"
34
+ }
35
+ ]
36
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "data": {
3
+ "balance": "0",
4
+ "balanceHint": "0 ALPH",
5
+ "lockedBalance": "0",
6
+ "lockedBalanceHint": "0 ALPH",
7
+ "utxoNum": 0
8
+ }
9
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "data": {
3
+ "cliqueId": "02f342de9b742719e1e9c939c54a13db5a7e3c4926b04428cbc45d70f8e6bcef4d",
4
+ "networkId": 0,
5
+ "numZerosAtLeastInHash": 37,
6
+ "nodes": [
7
+ {
8
+ "address": "127.0.0.1",
9
+ "restPort": 12973,
10
+ "wsPort": 11973,
11
+ "minerApiPort": 10973
12
+ }
13
+ ],
14
+ "selfReady": true,
15
+ "synced": true,
16
+ "groupNumPerBroker": 4,
17
+ "groups": 4
18
+ }
19
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "created": {
3
+ "unsignedTx": "0ecd20654c2e2be708495853e8da35c664247040c00bd10b9b13",
4
+ "txId": "798e9e137aec7c2d59d9655b4ffa640f301f628bf7c365083bb255f6aa5f89ef",
5
+ "fromGroup": 2,
6
+ "toGroup": 1
7
+ },
8
+ "submitted": {
9
+ "txId": "503bfb16230888af4924aa8f8250d7d348b862e267d75d3147f1998050b6da69",
10
+ "fromGroup": 2,
11
+ "toGroup": 1
12
+ }
13
+ }
@@ -0,0 +1,179 @@
1
+ {
2
+ "oneInputOneOutput": {
3
+ "hash": "c99559da00e05bf967227c452f9dc33904cc8aac9819f71ca9b3382d037317c1",
4
+ "blockHash": "000000000000d3a4088bd4a177dd4c99f8df7642e095dd6f375d99d3a4a2760a",
5
+ "timestamp": 1639679587756,
6
+ "inputs": [
7
+ {
8
+ "outputRef": {
9
+ "hint": 269352581,
10
+ "key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
11
+ },
12
+ "unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
13
+ "txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
14
+ "address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
15
+ "amount": "100000000000000000000"
16
+ }
17
+ ],
18
+ "outputs": [
19
+ {
20
+ "hint": 1770492891,
21
+ "key": "685eedf4a7eef2cccd55dfcc0d7d72c2aef788b118236d2dc8b27d924206da9d",
22
+ "amount": "409200570768056060",
23
+ "address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA2",
24
+ "spent": "4d8e564e1731ecc09e167211c25da7b91a3fab8096a951a0df3b7ce1549d6cd9"
25
+ },
26
+ {
27
+ "hint": 269352581,
28
+ "key": "162784ca82a5dfc796bc6514658453e51aacdb48ed7bec716850152a61b55b82",
29
+ "amount": "50000000000000000000",
30
+ "address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
31
+ "spent": "f823bcb78fbbc6c18dea882fe697cb8be9c5e2cb020e65670041dbe39b80c3d8"
32
+ }
33
+ ],
34
+ "gasAmount": 68060,
35
+ "gasPrice": "100000000000"
36
+ },
37
+ "twoInputsOneOutput": {
38
+ "hash": "c99559da00e05bf967227c452f9dc33904cc8aac9819f71ca9b3382d037317c1",
39
+ "blockHash": "000000000000d3a4088bd4a177dd4c99f8df7642e095dd6f375d99d3a4a2760a",
40
+ "timestamp": 1639679587756,
41
+ "inputs": [
42
+ {
43
+ "outputRef": {
44
+ "hint": 269352581,
45
+ "key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
46
+ },
47
+ "unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
48
+ "txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
49
+ "address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
50
+ "amount": "100000000000000000000"
51
+ },
52
+ {
53
+ "outputRef": {
54
+ "hint": 269352581,
55
+ "key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
56
+ },
57
+ "unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
58
+ "txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
59
+ "address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
60
+ "amount": "100000000000000000000"
61
+ }
62
+ ],
63
+ "outputs": [
64
+ {
65
+ "hint": 1770492891,
66
+ "key": "685eedf4a7eef2cccd55dfcc0d7d72c2aef788b118236d2dc8b27d924206da9d",
67
+ "amount": "150000000000000000000",
68
+ "address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA2",
69
+ "spent": "4d8e564e1731ecc09e167211c25da7b91a3fab8096a951a0df3b7ce1549d6cd9"
70
+ },
71
+ {
72
+ "hint": 269352581,
73
+ "key": "162784ca82a5dfc796bc6514658453e51aacdb48ed7bec716850152a61b55b82",
74
+ "amount": "50000000000000000000",
75
+ "address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
76
+ "spent": "f823bcb78fbbc6c18dea882fe697cb8be9c5e2cb020e65670041dbe39b80c3d8"
77
+ }
78
+ ],
79
+ "gasAmount": 68060,
80
+ "gasPrice": "100000000000"
81
+ },
82
+ "twoInputsZeroOutput": {
83
+ "hash": "c99559da00e05bf967227c452f9dc33904cc8aac9819f71ca9b3382d037317c1",
84
+ "blockHash": "000000000000d3a4088bd4a177dd4c99f8df7642e095dd6f375d99d3a4a2760a",
85
+ "timestamp": 1639679587756,
86
+ "inputs": [
87
+ {
88
+ "outputRef": {
89
+ "hint": 269352581,
90
+ "key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
91
+ },
92
+ "unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
93
+ "txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
94
+ "address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
95
+ "amount": "100000000000000000000"
96
+ },
97
+ {
98
+ "outputRef": {
99
+ "hint": 269352581,
100
+ "key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
101
+ },
102
+ "unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
103
+ "txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
104
+ "address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
105
+ "amount": "100000000000000000000"
106
+ }
107
+ ],
108
+ "outputs": [
109
+ {
110
+ "hint": 1770492891,
111
+ "key": "685eedf4a7eef2cccd55dfcc0d7d72c2aef788b118236d2dc8b27d924206da9d",
112
+ "amount": "150000000000000000000",
113
+ "address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA2",
114
+ "spent": "4d8e564e1731ecc09e167211c25da7b91a3fab8096a951a0df3b7ce1549d6cd9"
115
+ },
116
+ {
117
+ "hint": 269352581,
118
+ "key": "162784ca82a5dfc796bc6514658453e51aacdb48ed7bec716850152a61b55b82",
119
+ "amount": "50000000000000000000",
120
+ "address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA3",
121
+ "spent": "f823bcb78fbbc6c18dea882fe697cb8be9c5e2cb020e65670041dbe39b80c3d8"
122
+ }
123
+ ],
124
+ "gasAmount": 68060,
125
+ "gasPrice": "100000000000"
126
+ },
127
+ "missingInputs": {
128
+ "hash": "c99559da00e05bf967227c452f9dc33904cc8aac9819f71ca9b3382d037317c1",
129
+ "blockHash": "000000000000d3a4088bd4a177dd4c99f8df7642e095dd6f375d99d3a4a2760a",
130
+ "timestamp": 1639679587756,
131
+ "outputs": [
132
+ {
133
+ "hint": 1770492891,
134
+ "key": "685eedf4a7eef2cccd55dfcc0d7d72c2aef788b118236d2dc8b27d924206da9d",
135
+ "amount": "150000000000000000000",
136
+ "address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA2",
137
+ "spent": "4d8e564e1731ecc09e167211c25da7b91a3fab8096a951a0df3b7ce1549d6cd9"
138
+ },
139
+ {
140
+ "hint": 269352581,
141
+ "key": "162784ca82a5dfc796bc6514658453e51aacdb48ed7bec716850152a61b55b82",
142
+ "amount": "50000000000000000000",
143
+ "address": "1D3cMU5kaHmm8rnhF5ZErqErnRgp5xopDheubHVUizWA3",
144
+ "spent": "f823bcb78fbbc6c18dea882fe697cb8be9c5e2cb020e65670041dbe39b80c3d8"
145
+ }
146
+ ],
147
+ "gasAmount": 68060,
148
+ "gasPrice": "100000000000"
149
+ },
150
+ "missingOutputs": {
151
+ "hash": "c99559da00e05bf967227c452f9dc33904cc8aac9819f71ca9b3382d037317c1",
152
+ "blockHash": "000000000000d3a4088bd4a177dd4c99f8df7642e095dd6f375d99d3a4a2760a",
153
+ "timestamp": 1639679587756,
154
+ "inputs": [
155
+ {
156
+ "outputRef": {
157
+ "hint": 269352581,
158
+ "key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
159
+ },
160
+ "unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
161
+ "txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
162
+ "address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
163
+ "amount": "100000000000000000000"
164
+ },
165
+ {
166
+ "outputRef": {
167
+ "hint": 269352581,
168
+ "key": "25abffce393aea71c3acf15c701ada53d69ccb4361d28f4b980560bca3303864"
169
+ },
170
+ "unlockScript": "00026e6e0839c322d59b54feb6501b207b8439ada411839268a5842e298acf8608d5",
171
+ "txHashRef": "1bd6040d255021cb4a551644f343344a2f1f0f32093244cbb273f6cdef55567f",
172
+ "address": "16sR3EMn2BdFgENRhz6N2TJ78nfaADdv3prKXUQMaB6m3",
173
+ "amount": "100000000000000000000"
174
+ }
175
+ ],
176
+ "gasAmount": 68060,
177
+ "gasPrice": "100000000000"
178
+ }
179
+ }
package/src/index.ts CHANGED
@@ -24,5 +24,3 @@ export * from './transaction'
24
24
 
25
25
  export * from './constants'
26
26
  export * from './global'
27
-
28
- export * as utils from './utils'
@@ -0,0 +1,26 @@
1
+ [
2
+ {
3
+ "address": "19XWyoWy6DjrRp7erWqPfBnh7HL1Sb2Ub8SVjux2d71Eb",
4
+ "pubKey": "03d3400977a9dabf737714ce672dd60e3e74afc7f9d61fa6a6d74f3e2909f7dc00",
5
+ "priKey": "fff733a4e95a5366625610e30d942587168130f82785c3609d92ae84c149e05e",
6
+ "mnemonic": "space window beach above tiger attract barrel noodle autumn grain update either twelve security shoe teach quote flip reflect maple bike polar ivory gadget"
7
+ },
8
+ {
9
+ "address": "1CsutTzw8WVhqr1PB6F1tYinuLihAsAm9FxE7rVkC3Z2u",
10
+ "pubKey": "02b3a0175856c1ac653720cc05eeb84263ec2036e9eeced748e8d643a8607901ae",
11
+ "priKey": "f004e2a5b9435531adef0954ce4106a494731379ee626365907d4e3ac639e9c6",
12
+ "mnemonic": "length hazard scene rabbit tiny soup page almost argue helmet cliff soap then bean artist teach guess sense dose near topic dinner option isolate"
13
+ },
14
+ {
15
+ "address": "1CwD52BrUj9e4WDJSZ7RXLU2A8us4ZFSmYBDKu98p7szi",
16
+ "pubKey": "03372b642615c8f32a4af2ca318bc5fc471828428dbc11e29d1a816d0d208d217d",
17
+ "priKey": "7ed7be6e1ba50c217b06f70a0b1e26e844907b3dec2e479ff5d206ad62a073e9",
18
+ "mnemonic": "head add industry horn prepare green budget divide attack reason finish purse flip congress book allow message salute turkey video quote pulse present private"
19
+ },
20
+ {
21
+ "address": "1BHSQ8JMeYHZe2kj3KmLjuQCSM3mvzYjNutz14uRPbxZM",
22
+ "pubKey": "02ea6e8cf78e57d4ab758ded570e1a6cd721e6586f34a1200f55a3d3c2a1b0374f",
23
+ "priKey": "7ced95c635863187db397d1b6406497654d27202e9b69edf9ae7f23ab346984b",
24
+ "mnemonic": "lottery mystery chase fatal rural snake moral cricket cash south pitch enlist loyal point turkey rally journey earth rifle deputy metal arm hospital tree"
25
+ }
26
+ ]
@@ -0,0 +1,26 @@
1
+ {
2
+ "wallets": [
3
+ {
4
+ "mnemonic": "scan pause slender around cube flavor neck shrug gadget ramp rude lend capable tone nose unhappy gift across cluster minor tragic fever detail script",
5
+ "seed": "f585d130dd79d3b5bd63aa99d9bc6e6107cfbbe393b86d70e865f6e75c60a37496afc1b25cd4d1ab3b82d9b41f469c6c112a9f310e441814147ff27a5d65882b",
6
+ "password": "36ae0b75ef06d2e902e473c879c6e853193760ffa5dc29dc8da76133149e0892",
7
+ "file": {
8
+ "encrypted": "b686b4fff0c97e7fcacfd47babccf3ebac60c65035ed1370741424b3de5dbb75d87ac7f7bc0a2309725ec3370c53cd0bc705e3d1e919cdbad539d334398498d29b97689b37c9447b4aaeef3b99d11cadb85028ece6baa62fe74750a26d02f06a71b8e2ff69e112d78999c7f787a7029120bc25ad28e2acfaf4f088b30fea2973e30bd3ced24880a610c121ceddab4e271c17d6dcd0bcec7e6aff921c9409a0bb2e478a5028f1aacc70c72ee7fc64ebc58b4e63db",
9
+ "salt": "fd90b530931ad2fc9a195b719c7f1ecea8519e49a5e9b96d527c87549445c587dd34385f28446b570062286e79600430d190a885198b224e1b10678a0cd6648b",
10
+ "iv": "620bec5b5c612ac5f1f82b529dbdb818ba78c0d5e298a08d4ed9ea63a0bf762ca54414d12bd312e101d16ef95350c46b5ea18cf78d83ed025d5a400406bcdf70",
11
+ "version": 1
12
+ }
13
+ },
14
+ {
15
+ "mnemonic": "fence motor uncle pass zero curve garlic match palm kingdom quality keep undo scissors host lend ginger human loop mad sting horse swap track",
16
+ "seed": "f346de0a6cb3c8f50eb651ed4f17d572f7184813d3366215b4a1a61d7c776bedca41373d9008176bac8cb2ff8216d5cc3542f37fd520b4938295ca85013dbb3c",
17
+ "password": "36ae0b75ef06d2e902e473c879c6e853193760ffa5dc29dc8da76133149e0892",
18
+ "file": {
19
+ "encrypted": "d908a9e2816be754f17b4e80789546783d9e4538240e6585fda17c16343569d03aaac0a10c61122e23d9aa1c988f55d9e88b4d7b271e1f631e8aee02d5dc9e077e6150732381ec06c6f18d4fdde7ed3e09494762d002232a12fbcb5d1f0ca9ac3e6d964d3eb06ed530b10b8b151a66e2ea1eb4e60241b24c631edb31aa7ae99cf5c7f74692f39c534e7deee4e168375da2e6b93b7236fdfcafaade2d2e641498e61888b16d05147a43bb8024",
20
+ "salt": "e30c12732903502d8257cec78c3a1d25b29cd77a45378c43d4c9aed0386fd3c278149354221bdcf18e156d6384f1cb20c120975957f37fa433526f516528d597",
21
+ "iv": "d28a2821343d525a5afc8a17167e0e7f52a7dbc36dcbfbc95819c7f33afd5c6a1cc97a65a2b2bc95387b220a2e9fda7237bd897dfd59ab98e9a7add0c5eeab30",
22
+ "version": 1
23
+ }
24
+ }
25
+ ]
26
+ }
@@ -17,3 +17,4 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
19
  export * from './signer'
20
+ export * from './node-wallet'
@@ -0,0 +1,65 @@
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
+ import { Account, SignerWithNodeProvider } from '../signer'
20
+
21
+ export class NodeWallet extends SignerWithNodeProvider {
22
+ public walletName: string
23
+ public accounts: Account[] | undefined
24
+
25
+ constructor(walletName: string, alwaysSubmitTx = true) {
26
+ super(alwaysSubmitTx)
27
+ this.walletName = walletName
28
+ }
29
+
30
+ async getAccounts(): Promise<Account[]> {
31
+ if (typeof this.accounts === 'undefined') {
32
+ this.accounts = await this.getAllAccounts()
33
+ }
34
+ return this.accounts
35
+ }
36
+
37
+ private async getAllAccounts(): Promise<Account[]> {
38
+ const walletAddresses = await this.provider.wallets.getWalletsWalletNameAddresses(this.walletName)
39
+ const accounts: Account[] = walletAddresses.addresses.map<Account>((acc) => ({
40
+ publicKey: acc.publicKey,
41
+ address: acc.address,
42
+ group: acc.group
43
+ }))
44
+ return accounts
45
+ }
46
+
47
+ async signRaw(signerAddress: string, hexString: string): Promise<string> {
48
+ const currentActiveAddressResponse = await this.provider.wallets.getWalletsWalletNameAddresses(this.walletName)
49
+ const { activeAddress } = currentActiveAddressResponse
50
+ await this.provider.wallets.postWalletsWalletNameChangeActiveAddress(this.walletName, { address: signerAddress })
51
+ const { signature } = await this.provider.wallets.postWalletsWalletNameSign(this.walletName, { data: hexString })
52
+
53
+ await this.provider.wallets.postWalletsWalletNameChangeActiveAddress(this.walletName, { address: activeAddress }) // set the address that's active back to previous state
54
+
55
+ return signature
56
+ }
57
+
58
+ async unlock(password: string): Promise<void> {
59
+ return await this.provider.wallets.postWalletsWalletNameUnlock(this.walletName, { password })
60
+ }
61
+
62
+ async lock(): Promise<void> {
63
+ return await this.provider.wallets.postWalletsWalletNameLock(this.walletName)
64
+ }
65
+ }
@@ -0,0 +1,31 @@
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
+ import { NodeWallet } from '../signer'
20
+
21
+ export const testWalletName = 'alephium-web3-test-only-wallet'
22
+ export const testAddress = '1DrDyTr9RpRsQnDnXo2YRiPzPW4ooHX5LLoqXrqfMrpQH'
23
+ export const testPassword = 'alph'
24
+
25
+ export async function testNodeWallet(): Promise<NodeWallet> {
26
+ const wallet = new NodeWallet(testWalletName)
27
+ await wallet.unlock(testPassword)
28
+ return wallet
29
+ }
30
+
31
+ export * from './privatekey-wallet'
@@ -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
+ import { ec as EC } from 'elliptic'
20
+ import { Account, SignerWithNodeProvider } from '../signer'
21
+ import * as utils from '../utils'
22
+
23
+ const ec = new EC('secp256k1')
24
+
25
+ export class PrivateKeyWallet extends SignerWithNodeProvider {
26
+ readonly privateKey: string
27
+ readonly publicKey: string
28
+ readonly address: string
29
+ readonly group: number
30
+
31
+ constructor(privateKey: string, alwaysSubmitTx = true) {
32
+ super(alwaysSubmitTx)
33
+ this.privateKey = privateKey
34
+ this.publicKey = utils.publicKeyFromPrivateKey(privateKey)
35
+ this.address = utils.addressFromPublicKey(this.publicKey)
36
+ this.group = utils.groupOfAddress(this.address)
37
+ }
38
+
39
+ static Random(alwaysSubmitTx = true): PrivateKeyWallet {
40
+ const keyPair = ec.genKeyPair()
41
+ return new PrivateKeyWallet(keyPair.getPrivate().toString('hex'), alwaysSubmitTx)
42
+ }
43
+
44
+ async getAccounts(): Promise<Account[]> {
45
+ return [{ address: this.address, publicKey: this.publicKey, group: this.group }]
46
+ }
47
+
48
+ async signRaw(signerAddress: string, hexString: string): Promise<string> {
49
+ if (signerAddress !== this.address) {
50
+ throw Error('Unmatched signer address')
51
+ }
52
+
53
+ const key = ec.keyFromPrivate(this.privateKey)
54
+ const signature = key.sign(hexString)
55
+ return utils.signatureEncode(signature)
56
+ }
57
+ }
@@ -16,4 +16,5 @@ You should have received a copy of the GNU Lesser General Public License
16
16
  along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
+ export * from './sign-verify'
19
20
  export * from './status'