@autonomys/auto-dag-data 1.0.11 → 1.1.0
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
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
The **Autonomys Auto Dag Data SDK** (`@autonomys/auto-dag-data`) provides utilities for creating and managing IPLD DAGs (InterPlanetary Linked Data Directed Acyclic Graphs) for files and folders. It facilitates chunking large files, handling metadata, and creating folder structures suitable for distributed storage systems like IPFS.
|
|
12
12
|
|
|
13
|
+
### This package is an ES Module package and it's designed to work with ESM applications.
|
|
14
|
+
|
|
15
|
+
Check [this tutorial](https://dev.to/mangadev/set-up-a-backend-nodejs-typescript-jest-using-es-modules-1530) in how to setup a ES module application.
|
|
16
|
+
|
|
13
17
|
## Features
|
|
14
18
|
|
|
15
19
|
- **File Chunking and DAG Creation**: Efficiently split large files into smaller chunks and create IPLD DAGs.
|
|
@@ -2,6 +2,7 @@ import { AwaitIterable } from 'interface-store';
|
|
|
2
2
|
import { EncryptionOptions } from '../metadata/index.js';
|
|
3
3
|
import type { PickPartial } from '../utils/types.js';
|
|
4
4
|
import { PasswordGenerationOptions } from './types.js';
|
|
5
|
+
export declare const crypto: globalThis.Crypto;
|
|
5
6
|
export declare const ENCRYPTING_CHUNK_SIZE: number;
|
|
6
7
|
export declare const getKeyFromPassword: ({ password, salt }: PasswordGenerationOptions) => Promise<CryptoKey>;
|
|
7
8
|
export declare const encryptFile: (file: AwaitIterable<Buffer>, password: string, { chunkSize, algorithm }: PickPartial<EncryptionOptions, "algorithm">) => AsyncIterable<Buffer>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encryption/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encryption/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAuB,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAEtD,eAAO,MAAM,MAAM,mBAA+D,CAAA;AAElF,eAAO,MAAM,qBAAqB,QAAc,CAAA;AAMhD,eAAO,MAAM,kBAAkB,uBAA8B,yBAAyB,uBAyBrF,CAAA;AAED,eAAO,MAAM,WAAW,SAChB,aAAa,CAAC,MAAM,CAAC,YACjB,MAAM,4BACkC,WAAW,CAAC,iBAAiB,EAAE,WAAW,CAAC,KAC5F,aAAa,CAAC,MAAM,CAetB,CAAA;AAED,eAAO,MAAM,WAAW,SAChB,aAAa,CAAC,MAAM,CAAC,YACjB,MAAM,4BACiC,WAAW,CAAC,iBAAiB,EAAE,WAAW,CAAC,KAC3F,aAAa,CAAC,MAAM,CA+BtB,CAAA"}
|
package/dist/encryption/index.js
CHANGED
|
@@ -28,10 +28,9 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
28
28
|
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
29
29
|
};
|
|
30
30
|
import { Crypto } from '@peculiar/webcrypto';
|
|
31
|
-
import { randomBytes } from 'crypto';
|
|
32
31
|
import { EncryptionAlgorithm } from '../metadata/index.js';
|
|
33
32
|
import { asyncByChunk } from '../utils/async.js';
|
|
34
|
-
const crypto = new Crypto();
|
|
33
|
+
export const crypto = typeof window === 'undefined' ? new Crypto() : window.crypto;
|
|
35
34
|
export const ENCRYPTING_CHUNK_SIZE = 1024 * 1024;
|
|
36
35
|
const IV_SIZE = 16;
|
|
37
36
|
const TAG_SIZE = 16;
|
|
@@ -54,7 +53,7 @@ export const encryptFile = function (file_1, password_1, _a) {
|
|
|
54
53
|
if (algorithm !== EncryptionAlgorithm.AES_256_GCM) {
|
|
55
54
|
throw new Error('Unsupported encryption algorithm');
|
|
56
55
|
}
|
|
57
|
-
const salt =
|
|
56
|
+
const salt = crypto.getRandomValues(Buffer.alloc(SALT_SIZE));
|
|
58
57
|
const key = yield __await(getKeyFromPassword({ password, salt }));
|
|
59
58
|
yield yield __await(salt);
|
|
60
59
|
try {
|
package/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-dag-data",
|
|
3
3
|
"packageManager": "yarn@4.1.1",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
10
|
"url": "https://github.com/autonomys/auto-sdk"
|
|
10
11
|
},
|
|
11
12
|
"author": {
|
|
12
13
|
"name": "Autonomys",
|
|
13
|
-
"url": "https://www.autonomys.
|
|
14
|
+
"url": "https://www.autonomys.xyz"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/autonomys/auto-sdk/issues"
|
|
14
18
|
},
|
|
15
|
-
"type": "module",
|
|
16
19
|
"scripts": {
|
|
17
20
|
"build": "tsc",
|
|
18
21
|
"pb": "yarn protons src/metadata/onchain/protobuf/OnchainMetadata.proto -o src/metadata/onchain/protobuf",
|
|
@@ -48,5 +51,5 @@
|
|
|
48
51
|
"protons": "^7.6.0",
|
|
49
52
|
"protons-runtime": "^5.5.0"
|
|
50
53
|
},
|
|
51
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "8729780d591683cf6fd62333526cd91789994c87"
|
|
52
55
|
}
|
package/src/encryption/index.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Crypto } from '@peculiar/webcrypto'
|
|
2
|
-
import { randomBytes } from 'crypto'
|
|
3
2
|
import { AwaitIterable } from 'interface-store'
|
|
4
3
|
import { EncryptionAlgorithm, EncryptionOptions } from '../metadata/index.js'
|
|
5
4
|
import { asyncByChunk } from '../utils/async.js'
|
|
6
5
|
import type { PickPartial } from '../utils/types.js'
|
|
7
6
|
import { PasswordGenerationOptions } from './types.js'
|
|
8
7
|
|
|
9
|
-
const crypto = new Crypto()
|
|
8
|
+
export const crypto = typeof window === 'undefined' ? new Crypto() : window.crypto
|
|
10
9
|
|
|
11
10
|
export const ENCRYPTING_CHUNK_SIZE = 1024 * 1024
|
|
12
11
|
const IV_SIZE = 16
|
|
@@ -50,7 +49,7 @@ export const encryptFile = async function* (
|
|
|
50
49
|
throw new Error('Unsupported encryption algorithm')
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
const salt =
|
|
52
|
+
const salt = crypto.getRandomValues(Buffer.alloc(SALT_SIZE))
|
|
54
53
|
const key = await getKeyFromPassword({ password, salt })
|
|
55
54
|
|
|
56
55
|
yield salt
|