Skip to content

Commit 644edb9

Browse files
committed
Add Extractor to find Bitcoin Addresses in Text
1 parent a3b873f commit 644edb9

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

Diff for: src/core/config/Categories.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@
291291
"CSS selector",
292292
"Extract EXIF",
293293
"Extract ID3",
294-
"Extract Files"
294+
"Extract Files",
295+
"Extract Bitcoin Addresses"
295296
]
296297
},
297298
{

Diff for: src/core/operations/ExtractBitcoinAddresses.mjs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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;

Diff for: tests/operations/index.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import "./tests/Unicode.mjs";
104104
import "./tests/RSA.mjs";
105105
import "./tests/CBOREncode.mjs";
106106
import "./tests/CBORDecode.mjs";
107+
import "./tests/ExtractBitcoinAddresses.mjs";
107108

108109

109110
// Cannot test operations that use the File type yet

Diff for: tests/operations/tests/ExtractBitcoinAddresses.mjs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
]);

0 commit comments

Comments
 (0)