File tree Expand file tree Collapse file tree 8 files changed +591
-1039
lines changed Expand file tree Collapse file tree 8 files changed +591
-1039
lines changed Original file line number Diff line number Diff line change 5555 "tsc" : " ../../config/cli/ts-compile.sh"
5656 },
5757 "dependencies" : {
58- "@chainsafe/snappy-stream" : " ^5.1.2" ,
5958 "@ethereumjs/block" : " ^10.0.0" ,
6059 "@ethereumjs/blockchain" : " ^10.0.0" ,
6160 "@ethereumjs/rlp" : " ^10.0.0" ,
6261 "@ethereumjs/util" : " ^10.0.0" ,
6362 "level" : " ^9.0.0" ,
64- "micro-eth-signer" : " ^0.14.0"
63+ "micro-eth-signer" : " ^0.14.0" ,
64+ "snappyjs" : " ^0.7.0"
65+ },
66+ "devDependencies" : {
67+ "@types/snappyjs" : " ^0.7.1"
6568 },
6669 "engines" : {
6770 "node" : " >=18"
Original file line number Diff line number Diff line change 1+ export function checksum ( value : Uint8Array ) : Uint8Array {
2+ const x = calculate ( value )
3+ const result = new Uint8Array ( 4 )
4+
5+ // As defined in section 3 of https://github.com/google/snappy/blob/master/framing_format.txt
6+ // And other implementations for reference:
7+ // Go: https://github.com/golang/snappy/blob/2e65f85255dbc3072edf28d6b5b8efc472979f5a/snappy.go#L97
8+ // Python: https://github.com/andrix/python-snappy/blob/602e9c10d743f71bef0bac5e4c4dffa17340d7b3/snappy/snappy.py#L70
9+ // Mask the right hand to (32 - 17) = 15 bits -> 0x7fff, to keep correct 32 bit values.
10+ // Shift the left hand with >>> for correct 32 bit intermediate result.
11+ // Then final >>> 0 for 32 bits output
12+ const masked = ( ( ( x >>> 15 ) | ( ( x & 0x7fff ) << 17 ) ) + 0xa282ead8 ) >>> 0
13+
14+ // Write the 32-bit value in little-endian format
15+ result [ 0 ] = masked & 0xff
16+ result [ 1 ] = ( masked >> 8 ) & 0xff
17+ result [ 2 ] = ( masked >> 16 ) & 0xff
18+ result [ 3 ] = ( masked >> 24 ) & 0xff
19+
20+ return result
21+ }
22+
23+ const kCRCTable = Int32Array . of (
24+ 0x00000000 ,
25+ 0xf26b8303 ,
26+ 0xe13b70f7 ,
27+ 0x1350f3f4 ,
28+ 0xc79a971f ,
29+ 0x35f1141c ,
30+ 0x26a1e7e8 ,
31+ 0xd4ca64eb ,
32+ 0x8ad958cf ,
33+ 0x78b2dbcc ,
34+ 0x6be22838 ,
35+ 0x9989ab3b ,
36+ 0x4d43cfd0 ,
37+ 0xbf284cd3 ,
38+ 0xac78bf27 ,
39+ 0x5e133c24 ,
40+ 0x105ec76f ,
41+ 0xe235446c ,
42+ 0xf165b798 ,
43+ 0x030e349b ,
44+ 0xd7c45070 ,
45+ 0x25afd373 ,
46+ 0x36ff2087 ,
47+ 0xc494a384 ,
48+ 0x9a879fa0 ,
49+ 0x68ec1ca3 ,
50+ 0x7bbcef57 ,
51+ 0x89d76c54 ,
52+ 0x5d1d08bf ,
53+ 0xaf768bbc ,
54+ 0xbc267848 ,
55+ 0x4e4dfb4b ,
56+ 0x20bd8ede ,
57+ 0xd2d60ddd ,
58+ 0xc186fe29 ,
59+ 0x33ed7d2a ,
60+ 0xe72719c1 ,
61+ 0x154c9ac2 ,
62+ 0x061c6936 ,
63+ 0xf477ea35 ,
64+ 0xaa64d611 ,
65+ 0x580f5512 ,
66+ 0x4b5fa6e6 ,
67+ 0xb93425e5 ,
68+ 0x6dfe410e ,
69+ 0x9f95c20d ,
70+ 0x8cc531f9 ,
71+ 0x7eaeb2fa ,
72+ 0x30e349b1 ,
73+ 0xc288cab2 ,
74+ 0xd1d83946 ,
75+ 0x23b3ba45 ,
76+ 0xf779deae ,
77+ 0x05125dad ,
78+ 0x1642ae59 ,
79+ 0xe4292d5a ,
80+ 0xba3a117e ,
81+ 0x4851927d ,
82+ 0x5b016189 ,
83+ 0xa96ae28a ,
84+ 0x7da08661 ,
85+ 0x8fcb0562 ,
86+ 0x9c9bf696 ,
87+ 0x6ef07595 ,
88+ 0x417b1dbc ,
89+ 0xb3109ebf ,
90+ 0xa0406d4b ,
91+ 0x522bee48 ,
92+ 0x86e18aa3 ,
93+ 0x748a09a0 ,
94+ 0x67dafa54 ,
95+ 0x95b17957 ,
96+ 0xcba24573 ,
97+ 0x39c9c670 ,
98+ 0x2a993584 ,
99+ 0xd8f2b687 ,
100+ 0x0c38d26c ,
101+ 0xfe53516f ,
102+ 0xed03a29b ,
103+ 0x1f682198 ,
104+ 0x5125dad3 ,
105+ 0xa34e59d0 ,
106+ 0xb01eaa24 ,
107+ 0x42752927 ,
108+ 0x96bf4dcc ,
109+ 0x64d4cecf ,
110+ 0x77843d3b ,
111+ 0x85efbe38 ,
112+ 0xdbfc821c ,
113+ 0x2997011f ,
114+ 0x3ac7f2eb ,
115+ 0xc8ac71e8 ,
116+ 0x1c661503 ,
117+ 0xee0d9600 ,
118+ 0xfd5d65f4 ,
119+ 0x0f36e6f7 ,
120+ 0x61c69362 ,
121+ 0x93ad1061 ,
122+ 0x80fde395 ,
123+ 0x72966096 ,
124+ 0xa65c047d ,
125+ 0x5437877e ,
126+ 0x4767748a ,
127+ 0xb50cf789 ,
128+ 0xeb1fcbad ,
129+ 0x197448ae ,
130+ 0x0a24bb5a ,
131+ 0xf84f3859 ,
132+ 0x2c855cb2 ,
133+ 0xdeeedfb1 ,
134+ 0xcdbe2c45 ,
135+ 0x3fd5af46 ,
136+ 0x7198540d ,
137+ 0x83f3d70e ,
138+ 0x90a324fa ,
139+ 0x62c8a7f9 ,
140+ 0xb602c312 ,
141+ 0x44694011 ,
142+ 0x5739b3e5 ,
143+ 0xa55230e6 ,
144+ 0xfb410cc2 ,
145+ 0x092a8fc1 ,
146+ 0x1a7a7c35 ,
147+ 0xe811ff36 ,
148+ 0x3cdb9bdd ,
149+ 0xceb018de ,
150+ 0xdde0eb2a ,
151+ 0x2f8b6829 ,
152+ 0x82f63b78 ,
153+ 0x709db87b ,
154+ 0x63cd4b8f ,
155+ 0x91a6c88c ,
156+ 0x456cac67 ,
157+ 0xb7072f64 ,
158+ 0xa457dc90 ,
159+ 0x563c5f93 ,
160+ 0x082f63b7 ,
161+ 0xfa44e0b4 ,
162+ 0xe9141340 ,
163+ 0x1b7f9043 ,
164+ 0xcfb5f4a8 ,
165+ 0x3dde77ab ,
166+ 0x2e8e845f ,
167+ 0xdce5075c ,
168+ 0x92a8fc17 ,
169+ 0x60c37f14 ,
170+ 0x73938ce0 ,
171+ 0x81f80fe3 ,
172+ 0x55326b08 ,
173+ 0xa759e80b ,
174+ 0xb4091bff ,
175+ 0x466298fc ,
176+ 0x1871a4d8 ,
177+ 0xea1a27db ,
178+ 0xf94ad42f ,
179+ 0x0b21572c ,
180+ 0xdfeb33c7 ,
181+ 0x2d80b0c4 ,
182+ 0x3ed04330 ,
183+ 0xccbbc033 ,
184+ 0xa24bb5a6 ,
185+ 0x502036a5 ,
186+ 0x4370c551 ,
187+ 0xb11b4652 ,
188+ 0x65d122b9 ,
189+ 0x97baa1ba ,
190+ 0x84ea524e ,
191+ 0x7681d14d ,
192+ 0x2892ed69 ,
193+ 0xdaf96e6a ,
194+ 0xc9a99d9e ,
195+ 0x3bc21e9d ,
196+ 0xef087a76 ,
197+ 0x1d63f975 ,
198+ 0x0e330a81 ,
199+ 0xfc588982 ,
200+ 0xb21572c9 ,
201+ 0x407ef1ca ,
202+ 0x532e023e ,
203+ 0xa145813d ,
204+ 0x758fe5d6 ,
205+ 0x87e466d5 ,
206+ 0x94b49521 ,
207+ 0x66df1622 ,
208+ 0x38cc2a06 ,
209+ 0xcaa7a905 ,
210+ 0xd9f75af1 ,
211+ 0x2b9cd9f2 ,
212+ 0xff56bd19 ,
213+ 0x0d3d3e1a ,
214+ 0x1e6dcdee ,
215+ 0xec064eed ,
216+ 0xc38d26c4 ,
217+ 0x31e6a5c7 ,
218+ 0x22b65633 ,
219+ 0xd0ddd530 ,
220+ 0x0417b1db ,
221+ 0xf67c32d8 ,
222+ 0xe52cc12c ,
223+ 0x1747422f ,
224+ 0x49547e0b ,
225+ 0xbb3ffd08 ,
226+ 0xa86f0efc ,
227+ 0x5a048dff ,
228+ 0x8ecee914 ,
229+ 0x7ca56a17 ,
230+ 0x6ff599e3 ,
231+ 0x9d9e1ae0 ,
232+ 0xd3d3e1ab ,
233+ 0x21b862a8 ,
234+ 0x32e8915c ,
235+ 0xc083125f ,
236+ 0x144976b4 ,
237+ 0xe622f5b7 ,
238+ 0xf5720643 ,
239+ 0x07198540 ,
240+ 0x590ab964 ,
241+ 0xab613a67 ,
242+ 0xb831c993 ,
243+ 0x4a5a4a90 ,
244+ 0x9e902e7b ,
245+ 0x6cfbad78 ,
246+ 0x7fab5e8c ,
247+ 0x8dc0dd8f ,
248+ 0xe330a81a ,
249+ 0x115b2b19 ,
250+ 0x020bd8ed ,
251+ 0xf0605bee ,
252+ 0x24aa3f05 ,
253+ 0xd6c1bc06 ,
254+ 0xc5914ff2 ,
255+ 0x37faccf1 ,
256+ 0x69e9f0d5 ,
257+ 0x9b8273d6 ,
258+ 0x88d28022 ,
259+ 0x7ab90321 ,
260+ 0xae7367ca ,
261+ 0x5c18e4c9 ,
262+ 0x4f48173d ,
263+ 0xbd23943e ,
264+ 0xf36e6f75 ,
265+ 0x0105ec76 ,
266+ 0x12551f82 ,
267+ 0xe03e9c81 ,
268+ 0x34f4f86a ,
269+ 0xc69f7b69 ,
270+ 0xd5cf889d ,
271+ 0x27a40b9e ,
272+ 0x79b737ba ,
273+ 0x8bdcb4b9 ,
274+ 0x988c474d ,
275+ 0x6ae7c44e ,
276+ 0xbe2da0a5 ,
277+ 0x4c4623a6 ,
278+ 0x5f16d052 ,
279+ 0xad7d5351 ,
280+ )
281+
282+ export function calculate ( buf : Uint8Array , initial ?: number ) {
283+ let crc = ( initial ?? 0 ) ^ - 1
284+ for ( let i = 0 ; i < buf . length ; i ++ ) {
285+ crc = kCRCTable [ ( crc ^ buf [ i ] ) & 0xff ] ^ ( crc >>> 8 )
286+ }
287+ return ( crc ^ - 1 ) >>> 0
288+ }
You can’t perform that action at this time.
0 commit comments