File tree 4 files changed +103
-1
lines changed
4 files changed +103
-1
lines changed Original file line number Diff line number Diff line change 291
291
" CSS selector" ,
292
292
" Extract EXIF" ,
293
293
" Extract ID3" ,
294
- " Extract Files"
294
+ " Extract Files" ,
295
+ " Extract Bitcoin Addresses"
295
296
]
296
297
},
297
298
{
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author homer.jonathan [[email protected] ]
3
+ * @copyright Crown Copyright 2021
4
+ * @license Apache-2.0
5
+ */
6
+
7
+ import Operation from "../Operation.mjs" ;
8
+ import { search } from "../lib/Extract.mjs" ;
9
+
10
+ /**
11
+ * Extract Bitcoin addresses operation
12
+ */
13
+ class ExtractBitcoinAddresses extends Operation {
14
+
15
+ /**
16
+ * ExtractIPAddresses constructor
17
+ */
18
+ constructor ( ) {
19
+ super ( ) ;
20
+
21
+ this . name = "Extract Bitcoin Addresses" ;
22
+ this . module = "Regex" ;
23
+ this . description = "Extracts all Bitcoin addresses in input provided. " ;
24
+ this . inputType = "string" ;
25
+ this . outputType = "string" ;
26
+ this . args = [
27
+ {
28
+ "name" : "Display total" ,
29
+ "type" : "boolean" ,
30
+ "value" : false
31
+ }
32
+ ] ;
33
+ }
34
+
35
+ /**
36
+ * @param {string } input
37
+ * @param {Object[] } args
38
+ * @returns {string }
39
+ */
40
+ run ( input , args ) {
41
+ const [ displayTotal ] = args ,
42
+ bitcoin = "(?:[13]{1}[a-km-zA-HJ-NP-Z1-9]{26,33}|bc1[a-z0-9]{39,59})" ;
43
+
44
+ const bitcoins = bitcoin ;
45
+
46
+ if ( bitcoins ) {
47
+ const regex = new RegExp ( bitcoins , "ig" ) ;
48
+ return search ( input , regex , null , displayTotal ) ;
49
+ } else {
50
+ return "" ;
51
+ }
52
+ }
53
+
54
+ }
55
+
56
+ export default ExtractBitcoinAddresses ;
Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ import "./tests/Unicode.mjs";
104
104
import "./tests/RSA.mjs" ;
105
105
import "./tests/CBOREncode.mjs" ;
106
106
import "./tests/CBORDecode.mjs" ;
107
+ import "./tests/ExtractBitcoinAddresses.mjs" ;
107
108
108
109
109
110
// Cannot test operations that use the File type yet
Original file line number Diff line number Diff line change
1
+ /**
2
+ * extract bitcoin address tests.
3
+ *
4
+ * @author homerjonathan [[email protected] ]
5
+ * @copyright Crown Copyright 2021
6
+ * @license Apache-2.0
7
+ */
8
+ import TestRegister from "../../lib/TestRegister.mjs" ;
9
+
10
+ TestRegister . addTests ( [
11
+ {
12
+ name : "Extract Bitcoin Addresse" ,
13
+ input : "Ransomware I received once! My modest consulting fee is 1650 US Dollars transferred in Bitcoin. Exchange rate at the time of the transfer.\nYou need to send that amount to this wallet: 1HSb4fZHmyNro5LGyjQFpcDwqKjRUqJhh2" ,
14
+ expectedOutput : "1HSb4fZHmyNro5LGyjQFpcDwqKjRUqJhh2\n" ,
15
+ recipeConfig : [
16
+ {
17
+ "op" : "Extract Bitcoin Addresses" ,
18
+ "args" : [ false ]
19
+ } ,
20
+ ] ,
21
+ } ,
22
+ {
23
+ name : "Extract Bitcoin Addresse - Display total" ,
24
+ input : "Ransomware I received once! My modest consulting fee is 1650 US Dollars transferred in Bitcoin. Exchange rate at the time of the transfer.\nYou need to send that amount to this wallet: 1HSb4fZHmyNro5LGyjQFpcDwqKjRUqJhh2" ,
25
+ expectedOutput : "Total found: 1\n\n1HSb4fZHmyNro5LGyjQFpcDwqKjRUqJhh2\n" ,
26
+ recipeConfig : [
27
+ {
28
+ "op" : "Extract Bitcoin Addresses" ,
29
+ "args" : [ true ]
30
+ } ,
31
+ ] ,
32
+ } ,
33
+ {
34
+ name : "Extract Mulitple Bitcoin Addresses" ,
35
+ input : "1HSb4fZHmyNro5LGyjQFpcDwqKjRUqJhh2 and 17U1BaXwyuxeX2sZyMjC25G8skrZ8mtTdz plus this one 1NGCsGqSdNEKpptQ4DKbJEva59cTSk369o" ,
36
+ expectedOutput : "1HSb4fZHmyNro5LGyjQFpcDwqKjRUqJhh2\n17U1BaXwyuxeX2sZyMjC25G8skrZ8mtTdz\n1NGCsGqSdNEKpptQ4DKbJEva59cTSk369o\n" ,
37
+ recipeConfig : [
38
+ {
39
+ "op" : "Extract Bitcoin Addresses" ,
40
+ "args" : [ false ]
41
+ } ,
42
+ ] ,
43
+ } ,
44
+ ] ) ;
You can’t perform that action at this time.
0 commit comments