ai-nevermore 0.0.6 → 0.0.7

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.
package/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  Nevermore
2
2
  =========
3
3
 
4
- Nevermore is a library to obfuscate plain text on the web to prevent AI scraping so while a user will see
4
+ Nevermore is a library to obfuscate media on the web to prevent AI scraping.
5
+
6
+ Text
7
+ ---
8
+ while a user will see
5
9
 
6
10
  ![original text](./images/original.png)
7
11
 
@@ -11,6 +15,44 @@ A scraper coming to your site will see something like
11
15
 
12
16
  Which will both prevent the scraper from acquiring your content as well as [poisoning the model trained](https://en.wikipedia.org/wiki/Adversarial_machine_learning#Data_poisoning) from it.
13
17
 
18
+ Images
19
+ ------
20
+
21
+ First you encode an image with:
22
+
23
+ `nevermore pseudoimage <target> --image-output <output> --encode`
24
+
25
+ which produces and encoded image, seemingly static filled.
26
+
27
+ Then you include the encoded image along with it's key(This uses the source directly, but it is also is compatible with your favorite build tool) the stub entries must point at any valid ESM file and are not used.
28
+
29
+ ```html
30
+ <html>
31
+ <head>
32
+ <script type="importmap">
33
+ {"imports":{
34
+ "node:os":"<path-to-stub>",
35
+ "node:stream":"<path-to-stub>",
36
+ "fs":"<path-to-stub>",
37
+ "os":"<path-to-stub>",
38
+ "module":"<path-to-stub>",
39
+ "nevermore/encoded-image":"./node_modules/nevermore/src/encoded-image-component.mjs",
40
+ "@environment-safe/canvas":"./node_modules/@environment-safe/canvas/src/index.mjs",
41
+ "@environment-safe/file":"./node_modules/@environment-safe/file/src/index.mjs",
42
+ "@environment-safe/elements":"./node_modules/@environment-safe/elements/src/index.mjs",
43
+ "@environment-safe/runtime-context":"./node_modules/@environment-safe/runtime-context/src/index.mjs"
44
+ }}
45
+ </script>
46
+ <script type="module">
47
+ import 'nevermore/encoded-image';
48
+ </script>
49
+ </head>
50
+ <body>
51
+ <encoded-image src="encoded-image-location" key="VFYZT-HPTRG-PGHRT"></encoded-image>
52
+ </body>
53
+ </html>
54
+ ```
55
+
14
56
  Programmatic Usage
15
57
  ------------------
16
58
  This library can be used to generate the html and css:
@@ -22,6 +64,19 @@ const { root, index } = await computeIndexKeys(inputText);
22
64
  const { html, css } = await generateHTMLAndCSS(root, index);
23
65
  ```
24
66
 
67
+ You can programmatically encode/decode images:
68
+ ```js
69
+ const image = new NevermoreImage({
70
+ url:'<target>',
71
+ maskDir: '<texture_dir>'
72
+ });
73
+ await image.ready;
74
+ const canvas = image.encode();
75
+ await Canvas.save('./encoded.jpg', canvas);
76
+ const decoded = image.decode();
77
+ await Canvas.save('./decoded.jpg', decoded);
78
+ ```
79
+
25
80
  Command Line Usage
26
81
  ------------------
27
82
  Install with `npm install -g ai-nevermore`
package/decoded.jpg ADDED
Binary file
package/demo.html ADDED
@@ -0,0 +1,24 @@
1
+ <html>
2
+ <head>
3
+ <script type="importmap">
4
+ {"imports":{
5
+ "node:os":"/src/encoded-image-component.mjs",
6
+ "node:stream":"/src/encoded-image-component.mjs",
7
+ "fs":"/src/encoded-image-component.mjs",
8
+ "os":"/src/encoded-image-component.mjs",
9
+ "module":"/src/encoded-image-component.mjs",
10
+ "nevermore/encoded-image-component":"./src/encoded-image-component.mjs",
11
+ "@environment-safe/canvas":"./node_modules/@environment-safe/canvas/src/index.mjs",
12
+ "@environment-safe/file":"./node_modules/@environment-safe/file/src/index.mjs",
13
+ "@environment-safe/elements":"./node_modules/@environment-safe/elements/src/index.mjs",
14
+ "@environment-safe/runtime-context":"./node_modules/@environment-safe/runtime-context/src/index.mjs"
15
+ }}
16
+ </script>
17
+ <script type="module">
18
+ import 'nevermore/encoded-image-component';
19
+ </script>
20
+ </head>
21
+ <body>
22
+ <encoded-image src="./out.jpg" key="VFYZT-HPTRG-PGHRT"></encoded-image>
23
+ </body>
24
+ </html>
package/out.jpg ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-nevermore",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "keywords": [
5
5
  "adversarial",
6
6
  "content",
@@ -21,6 +21,12 @@
21
21
  "./image": {
22
22
  "import": "./src/image.mjs"
23
23
  },
24
+ "./encoded-image": {
25
+ "import": "./src/encoded-image-component.mjs"
26
+ },
27
+ "./src/encoded-image-component.mjs": {
28
+ "import": "./src/encoded-image-component.mjs"
29
+ },
24
30
  "./src/image.mjs": {
25
31
  "import": "./src/image.mjs"
26
32
  },
@@ -38,12 +44,14 @@
38
44
  "single-file-demo": "./bin/nevermore pseudotext -U output.html nevermore.txt",
39
45
  "pipe-demo": "cat nevermore.txt | ./bin/nevermore pseudotext",
40
46
  "demo": "./bin/nevermore pseudotext -H out.html -C out.css nevermore.txt",
47
+ "web-decode-demo": "open http://localhost:8083/; npx http-server --cors --port 8083",
41
48
  "image-encode": "./bin/nevermore pseudoimage ./test.jpg --image-output out.jpg --encode",
42
49
  "image-decode": "./bin/nevermore pseudoimage ./out.jpg --image-output decoded.jpg --decode",
43
50
  "help": "./bin/nevermore --help"
44
51
  },
45
52
  "dependencies": {
46
53
  "@environment-safe/canvas": "^4.2.3",
54
+ "@environment-safe/elements": "^0.0.4",
47
55
  "@environment-safe/file": "^0.4.3",
48
56
  "object-hash": "^3.0.0",
49
57
  "parse-english": "^7.0.0",
@@ -0,0 +1,56 @@
1
+ import { HTMLElement, customElements } from '@environment-safe/elements';
2
+ import { Canvas } from '@environment-safe/canvas';
3
+ import { NevermoreImage } from './image.mjs';
4
+
5
+ let textureFuture = null;
6
+
7
+ const loadImage = async (url)=>{
8
+ return new Promise(r => {
9
+ let i = new Image();
10
+ i.onload = (() => r(i));
11
+ i.src = url;
12
+ });
13
+ };
14
+
15
+ export class EncodedImage extends HTMLElement {
16
+ constructor() {
17
+ super();
18
+ if(!textureFuture){
19
+ const urlRoot = this.getAttribute('textures') || './textures';
20
+ const type = this.getAttribute('type') || 'jpg';
21
+ textureFuture = new Promise(async (resolve)=>{
22
+ const list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
23
+ resolve(await Promise.all(list.map((id)=>{
24
+ return Canvas.load(`${urlRoot}/${id}.${type}`)
25
+ })));
26
+ });
27
+ }
28
+ this.attachShadow({mode: "open"});
29
+ const url = this.getAttribute('src');
30
+ const key = this.getAttribute('key');
31
+ this.shadowRoot.innerHTML = `<canvas></canvas>`;
32
+ (async ()=>{
33
+ const canvas = this.shadowRoot.querySelector('canvas');
34
+ const image = await loadImage(url);
35
+ canvas.width = image.width;
36
+ canvas.height = image.height;
37
+ const context = canvas.getContext('2d');
38
+ context.drawImage(image, 0, 0);
39
+ console.log('.')
40
+ const masks = await textureFuture;
41
+ const dictionary = {};
42
+ masks.forEach((mask, index)=>{
43
+ dictionary[(index + 10).toString(36).toUpperCase()] = mask;
44
+ //console.log( (index + 10).toString(36).toUpperCase() );
45
+ });
46
+ console.log('>>>', { url, masks, key })
47
+ this.image = new NevermoreImage({ url, masks, key, dictionary });
48
+ await this.image.ready;
49
+ this.image.decode();
50
+ context.drawImage(this.image.canvas, 0, 0);
51
+ })();
52
+ }
53
+ // Element functionality written in here
54
+ }
55
+
56
+ customElements.define("encoded-image", EncodedImage);
package/src/image.mjs CHANGED
@@ -77,6 +77,7 @@ export class NevermoreImage{
77
77
  if(!(
78
78
  options.masks || options.maskDir
79
79
  )) throw new Error('a set of masks are required');
80
+ this.textureDictionary = options.dictionary;
80
81
  this.ready = new Promise(async (resolve, reject)=>{
81
82
  // load all masks
82
83
  // TODO: load from cache