@autonomys/auto-dag-data 1.0.3 → 1.0.5

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.
Files changed (61) hide show
  1. package/dist/cid/index.d.ts.map +1 -1
  2. package/dist/cid/index.js +5 -2
  3. package/dist/encryption/index.js +6 -6
  4. package/package.json +5 -3
  5. package/src/cid/index.ts +5 -2
  6. package/src/encryption/index.ts +6 -6
  7. package/tests/encryption.spec.ts +37 -0
  8. package/dist/ipld/blockstore/base.d.ts +0 -9
  9. package/dist/ipld/blockstore/base.d.ts.map +0 -1
  10. package/dist/ipld/blockstore/base.js +0 -1
  11. package/dist/ipld/blockstore/index.d.ts +0 -3
  12. package/dist/ipld/blockstore/index.d.ts.map +0 -1
  13. package/dist/ipld/blockstore/index.js +0 -2
  14. package/dist/ipld/blockstore/memory.d.ts +0 -13
  15. package/dist/ipld/blockstore/memory.d.ts.map +0 -1
  16. package/dist/ipld/blockstore/memory.js +0 -57
  17. package/dist/src/cid/index.d.ts +0 -9
  18. package/dist/src/cid/index.d.ts.map +0 -1
  19. package/dist/src/cid/index.js +0 -20
  20. package/dist/src/index.d.ts +0 -4
  21. package/dist/src/index.d.ts.map +0 -1
  22. package/dist/src/index.js +0 -3
  23. package/dist/src/ipld/builders.d.ts +0 -11
  24. package/dist/src/ipld/builders.d.ts.map +0 -1
  25. package/dist/src/ipld/builders.js +0 -13
  26. package/dist/src/ipld/chunker.d.ts +0 -22
  27. package/dist/src/ipld/chunker.d.ts.map +0 -1
  28. package/dist/src/ipld/chunker.js +0 -144
  29. package/dist/src/ipld/index.d.ts +0 -4
  30. package/dist/src/ipld/index.d.ts.map +0 -1
  31. package/dist/src/ipld/index.js +0 -3
  32. package/dist/src/ipld/nodes.d.ts +0 -15
  33. package/dist/src/ipld/nodes.d.ts.map +0 -1
  34. package/dist/src/ipld/nodes.js +0 -89
  35. package/dist/src/ipld/utils.d.ts +0 -5
  36. package/dist/src/ipld/utils.d.ts.map +0 -1
  37. package/dist/src/ipld/utils.js +0 -51
  38. package/dist/src/metadata/index.d.ts +0 -3
  39. package/dist/src/metadata/index.d.ts.map +0 -1
  40. package/dist/src/metadata/index.js +0 -2
  41. package/dist/src/metadata/offchain/base.d.ts +0 -4
  42. package/dist/src/metadata/offchain/base.d.ts.map +0 -1
  43. package/dist/src/metadata/offchain/base.js +0 -1
  44. package/dist/src/metadata/offchain/file.d.ts +0 -16
  45. package/dist/src/metadata/offchain/file.d.ts.map +0 -1
  46. package/dist/src/metadata/offchain/file.js +0 -19
  47. package/dist/src/metadata/offchain/folder.d.ts +0 -17
  48. package/dist/src/metadata/offchain/folder.d.ts.map +0 -1
  49. package/dist/src/metadata/offchain/folder.js +0 -10
  50. package/dist/src/metadata/offchain/index.d.ts +0 -4
  51. package/dist/src/metadata/offchain/index.d.ts.map +0 -1
  52. package/dist/src/metadata/offchain/index.js +0 -3
  53. package/dist/src/metadata/onchain/index.d.ts +0 -3
  54. package/dist/src/metadata/onchain/index.d.ts.map +0 -1
  55. package/dist/src/metadata/onchain/index.js +0 -2
  56. package/dist/src/metadata/onchain/protobuf/OnchainMetadata.d.ts +0 -28
  57. package/dist/src/metadata/onchain/protobuf/OnchainMetadata.d.ts.map +0 -1
  58. package/dist/src/metadata/onchain/protobuf/OnchainMetadata.js +0 -112
  59. package/dist/src/metadata/onchain/utils.d.ts +0 -4
  60. package/dist/src/metadata/onchain/utils.d.ts.map +0 -1
  61. package/dist/src/metadata/onchain/utils.js +0 -12
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cid/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAGtC,OAAO,EAAc,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAErD,eAAO,MAAM,WAAW,KAAO,CAAA;AAE/B,eAAO,MAAM,SAAS,SAAU,MAAM,4BAErC,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,GAAG,WAEnC,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,MAAM,qEAEtC,CAAA;AAED,eAAO,MAAM,gBAAgB,SAAU,MAAM,4BAE5C,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,GAAG,eAAyB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cid/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAGtC,OAAO,EAAc,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAErD,eAAO,MAAM,WAAW,KAAO,CAAA;AAE/B,eAAO,MAAM,SAAS,SAAU,MAAM,4BAIrC,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,GAAG,WAEnC,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,MAAM,qEAEtC,CAAA;AAED,eAAO,MAAM,gBAAgB,SAAU,MAAM,4BAE5C,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,GAAG,eAAyB,CAAA"}
package/dist/cid/index.js CHANGED
@@ -1,4 +1,5 @@
1
- import { hash } from 'blake3';
1
+ import { blake3Hash } from '@webbuf/blake3';
2
+ import { WebBuf } from '@webbuf/webbuf';
2
3
  import * as base32 from 'multiformats/bases/base32';
3
4
  import { CID } from 'multiformats/cid';
4
5
  import * as raw from 'multiformats/codecs/raw';
@@ -6,7 +7,9 @@ import { create } from 'multiformats/hashes/digest';
6
7
  import { encodeNode } from '../ipld/utils.js';
7
8
  export const BLAKE3_CODE = 0x1f;
8
9
  export const cidOfNode = (node) => {
9
- return cidFromBlakeHash(hash(encodeNode(node)));
10
+ const encodedNode = WebBuf.from(encodeNode(node));
11
+ const hash = Buffer.from(blake3Hash(encodedNode).buf);
12
+ return cidFromBlakeHash(hash);
10
13
  };
11
14
  export const cidToString = (cid) => {
12
15
  return cid.toString(base32.base32);
@@ -88,16 +88,16 @@ export const decryptFile = function (file_1, password_1, _a) {
88
88
  for (var _e = true, file_2 = __asyncValues(file), file_2_1; file_2_1 = yield __await(file_2.next()), _b = file_2_1.done, !_b; _e = true) {
89
89
  _d = file_2_1.value;
90
90
  _e = false;
91
- const chunk = _d;
92
- chunks = Buffer.concat([chunks, chunk]);
91
+ const bufferSlice = _d;
92
+ chunks = Buffer.concat([chunks, bufferSlice]);
93
93
  if (chunks.length >= SALT_SIZE && !key) {
94
- const salt = chunks.subarray(0, 32);
94
+ const salt = chunks.subarray(0, SALT_SIZE);
95
95
  key = yield __await(getKeyFromPassword({ password, salt }));
96
96
  chunks = chunks.subarray(SALT_SIZE);
97
97
  }
98
98
  while (key && chunks.length >= chunkSize) {
99
99
  const iv = chunks.subarray(0, IV_SIZE);
100
- const encryptedChunk = chunk.subarray(IV_SIZE, chunkSize);
100
+ const encryptedChunk = chunks.subarray(IV_SIZE, chunkSize);
101
101
  const decrypted = yield __await(crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, encryptedChunk));
102
102
  chunks = chunks.subarray(chunkSize);
103
103
  yield yield __await(Buffer.from(decrypted));
@@ -113,8 +113,8 @@ export const decryptFile = function (file_1, password_1, _a) {
113
113
  }
114
114
  if (key && chunks.length > 0) {
115
115
  const iv = chunks.subarray(0, IV_SIZE);
116
- const encryptedChunk = chunks.subarray(IV_SIZE, chunkSize);
117
- const decrypted = yield __await(crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, encryptedChunk));
116
+ const chunk = chunks.subarray(IV_SIZE, chunkSize);
117
+ const decrypted = yield __await(crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, chunk));
118
118
  yield yield __await(Buffer.from(decrypted));
119
119
  }
120
120
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@autonomys/auto-dag-data",
3
3
  "packageManager": "yarn@4.1.1",
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "repository": {
@@ -35,12 +35,14 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@ipld/dag-pb": "^4.1.2",
38
- "blake3": "1.1.0",
38
+ "@webbuf/blake3": "^3.0.26",
39
+ "@webbuf/fixedbuf": "^3.0.26",
40
+ "@webbuf/webbuf": "^3.0.26",
39
41
  "fflate": "^0.8.2",
40
42
  "multiformats": "^13.2.2",
41
43
  "protobufjs": "^7.4.0",
42
44
  "protons": "^7.6.0",
43
45
  "protons-runtime": "^5.5.0"
44
46
  },
45
- "gitHead": "15b7535a4e4f0ff7d66b20941b76dcf6a3e56005"
47
+ "gitHead": "2ee93dd0867c16e0a42f2f47b2fa66bc41ba29cf"
46
48
  }
package/src/cid/index.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { hash } from 'blake3'
1
+ import { blake3Hash } from '@webbuf/blake3'
2
+ import { WebBuf } from '@webbuf/webbuf'
2
3
  import * as base32 from 'multiformats/bases/base32'
3
4
  import { CID } from 'multiformats/cid'
4
5
  import * as raw from 'multiformats/codecs/raw'
@@ -8,7 +9,9 @@ import { encodeNode, PBNode } from '../ipld/utils.js'
8
9
  export const BLAKE3_CODE = 0x1f
9
10
 
10
11
  export const cidOfNode = (node: PBNode) => {
11
- return cidFromBlakeHash(hash(encodeNode(node)))
12
+ const encodedNode = WebBuf.from(encodeNode(node))
13
+ const hash = Buffer.from(blake3Hash(encodedNode).buf)
14
+ return cidFromBlakeHash(hash)
12
15
  }
13
16
 
14
17
  export const cidToString = (cid: CID) => {
@@ -72,18 +72,18 @@ export const decryptFile = async function* (
72
72
 
73
73
  let key: CryptoKey | undefined = undefined
74
74
  let chunks = Buffer.alloc(0)
75
- for await (const chunk of file) {
76
- chunks = Buffer.concat([chunks, chunk])
75
+ for await (const bufferSlice of file) {
76
+ chunks = Buffer.concat([chunks, bufferSlice])
77
77
 
78
78
  if (chunks.length >= SALT_SIZE && !key) {
79
- const salt = chunks.subarray(0, 32)
79
+ const salt = chunks.subarray(0, SALT_SIZE)
80
80
  key = await getKeyFromPassword({ password, salt })
81
81
  chunks = chunks.subarray(SALT_SIZE)
82
82
  }
83
83
 
84
84
  while (key && chunks.length >= chunkSize) {
85
85
  const iv = chunks.subarray(0, IV_SIZE)
86
- const encryptedChunk = chunk.subarray(IV_SIZE, chunkSize)
86
+ const encryptedChunk = chunks.subarray(IV_SIZE, chunkSize)
87
87
  const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, encryptedChunk)
88
88
  chunks = chunks.subarray(chunkSize)
89
89
  yield Buffer.from(decrypted)
@@ -92,8 +92,8 @@ export const decryptFile = async function* (
92
92
 
93
93
  if (key && chunks.length > 0) {
94
94
  const iv = chunks.subarray(0, IV_SIZE)
95
- const encryptedChunk = chunks.subarray(IV_SIZE, chunkSize)
96
- const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, encryptedChunk)
95
+ const chunk = chunks.subarray(IV_SIZE, chunkSize)
96
+ const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, chunk)
97
97
  yield Buffer.from(decrypted)
98
98
  }
99
99
  }
@@ -64,4 +64,41 @@ describe('encryption', () => {
64
64
 
65
65
  expect(decryptedBuffer.toString()).toBe(file.toString())
66
66
  })
67
+
68
+ it('encrypts and decrypts a file with a password (with chunking)', async () => {
69
+ const chunk = 'hello'
70
+ const ONE_MB = 1024 * 1024
71
+ const file = Buffer.from(chunk.repeat(2 * ONE_MB))
72
+ const password = 'password'
73
+
74
+ const encrypted = encryptFile(
75
+ (async function* () {
76
+ yield file
77
+ })(),
78
+ password,
79
+ {
80
+ algorithm: EncryptionAlgorithm.AES_256_GCM,
81
+ },
82
+ )
83
+
84
+ let encryptedBuffer = Buffer.alloc(0)
85
+ for await (const chunk of encrypted) {
86
+ encryptedBuffer = Buffer.concat([encryptedBuffer, chunk])
87
+ }
88
+
89
+ const decrypted = decryptFile(
90
+ (async function* () {
91
+ yield encryptedBuffer
92
+ })(),
93
+ password,
94
+ {
95
+ algorithm: EncryptionAlgorithm.AES_256_GCM,
96
+ },
97
+ )
98
+
99
+ let decryptedBuffer = Buffer.alloc(0)
100
+ for await (const chunk of decrypted) {
101
+ decryptedBuffer = Buffer.concat([decryptedBuffer, chunk])
102
+ }
103
+ })
67
104
  })
@@ -1,9 +0,0 @@
1
- import { BaseBlockstore } from 'blockstore-core';
2
- import type { Pair } from 'interface-blockstore';
3
- import { AbortOptions, AwaitIterable } from 'interface-store';
4
- import { MetadataType } from '../../metadata/index.js';
5
- export interface IPLDBlockstore extends BaseBlockstore {
6
- getFilteredMany(nodeType: MetadataType, options?: AbortOptions): AwaitIterable<Pair['cid']>;
7
- getSize(cid: Pair['cid']): Promise<number>;
8
- }
9
- //# sourceMappingURL=base.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/ipld/blockstore/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEtD,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,eAAe,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;IAC3F,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAC3C"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export * from './base.js';
2
- export * from './memory.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ipld/blockstore/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './base.js';
2
- export * from './memory.js';
@@ -1,13 +0,0 @@
1
- import { MemoryBlockstore } from 'blockstore-core';
2
- import { Pair } from 'interface-blockstore';
3
- import { AbortOptions, AwaitIterable } from 'interface-store';
4
- import { CID, Version } from 'multiformats';
5
- import { MetadataType } from '../../metadata/index.js';
6
- import { IPLDBlockstore } from './base.js';
7
- export declare class MemoryIPLDBlockstore extends MemoryBlockstore implements IPLDBlockstore {
8
- private readonly nodeByType;
9
- getFilteredMany(nodeType: MetadataType, options?: AbortOptions): AwaitIterable<Pair['cid']>;
10
- put(key: CID<unknown, number, number, Version>, val: Uint8Array): Promise<CID<unknown, number, number, Version>>;
11
- getSize(cid: CID): Promise<number>;
12
- }
13
- //# sourceMappingURL=memory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/ipld/blockstore/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAoC,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE1C,qBAAa,oBAAqB,SAAQ,gBAAiB,YAAW,cAAc;IAClF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiC;IACrD,eAAe,CACpB,QAAQ,EAAE,YAAY,EACtB,OAAO,CAAC,EAAE,YAAY,GACrB,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAMvB,GAAG,CACP,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAC1C,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAM3C,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;CAKzC"}
@@ -1,57 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
11
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
14
- return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
15
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
16
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
17
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
18
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
19
- function fulfill(value) { resume("next", value); }
20
- function reject(value) { resume("throw", value); }
21
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
22
- };
23
- import { MemoryBlockstore } from 'blockstore-core';
24
- import { decodeIPLDNodeData } from '../../metadata/index.js';
25
- export class MemoryIPLDBlockstore extends MemoryBlockstore {
26
- constructor() {
27
- super(...arguments);
28
- this.nodeByType = new Map();
29
- }
30
- getFilteredMany(nodeType, options) {
31
- return __asyncGenerator(this, arguments, function* getFilteredMany_1() {
32
- var _a;
33
- for (const cid of (_a = this.nodeByType.get(nodeType)) !== null && _a !== void 0 ? _a : []) {
34
- yield yield __await(cid);
35
- }
36
- });
37
- }
38
- put(key, val) {
39
- const _super = Object.create(null, {
40
- put: { get: () => super.put }
41
- });
42
- return __awaiter(this, void 0, void 0, function* () {
43
- var _a;
44
- const data = decodeIPLDNodeData(val);
45
- this.nodeByType.set(data.type, [...((_a = this.nodeByType.get(data.type)) !== null && _a !== void 0 ? _a : []), key]);
46
- return _super.put.call(this, key, val);
47
- });
48
- }
49
- getSize(cid) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- var _a;
52
- const bytes = yield this.get(cid);
53
- const data = decodeIPLDNodeData(bytes);
54
- return (_a = data.size) !== null && _a !== void 0 ? _a : 0;
55
- });
56
- }
57
- }
@@ -1,9 +0,0 @@
1
- import { PBNode } from '@ipld/dag-pb';
2
- import { CID } from 'multiformats/cid';
3
- export declare const BLAKE3_CODE = 31;
4
- export declare const cidOfNode: (node: PBNode) => CID<unknown, 85, 31, 1>;
5
- export declare const cidToString: (cid: CID) => string;
6
- export declare const stringToCid: (str: string) => CID<unknown, number, number, import("multiformats/cid").Version>;
7
- export declare const cidFromBlakeHash: (hash: Buffer) => CID<unknown, 85, 31, 1>;
8
- export declare const blake3HashFromCid: (cid: CID) => Uint8Array;
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cid/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAKtC,eAAO,MAAM,WAAW,KAAO,CAAA;AAE/B,eAAO,MAAM,SAAS,SAAU,MAAM,4BAErC,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,GAAG,WAEnC,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,MAAM,qEAEtC,CAAA;AAED,eAAO,MAAM,gBAAgB,SAAU,MAAM,4BAE5C,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,GAAG,eAAyB,CAAA"}
@@ -1,20 +0,0 @@
1
- import { encode } from '@ipld/dag-pb';
2
- import { hash } from 'blake3';
3
- import { CID } from 'multiformats/cid';
4
- import * as base32 from 'multiformats/bases/base32';
5
- import * as raw from 'multiformats/codecs/raw';
6
- import { create } from 'multiformats/hashes/digest';
7
- export const BLAKE3_CODE = 0x1f;
8
- export const cidOfNode = (node) => {
9
- return cidFromBlakeHash(hash(encode(node)));
10
- };
11
- export const cidToString = (cid) => {
12
- return cid.toString(base32.base32);
13
- };
14
- export const stringToCid = (str) => {
15
- return CID.parse(str, base32.base32);
16
- };
17
- export const cidFromBlakeHash = (hash) => {
18
- return CID.create(1, raw.code, create(BLAKE3_CODE, hash));
19
- };
20
- export const blake3HashFromCid = (cid) => cid.multihash.digest;
@@ -1,4 +0,0 @@
1
- export * from './cid/index.js';
2
- export * from './ipld/index.js';
3
- export * from './metadata/index.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA"}
package/dist/src/index.js DELETED
@@ -1,3 +0,0 @@
1
- export * from './cid/index.js';
2
- export * from './ipld/index.js';
3
- export * from './metadata/index.js';
@@ -1,11 +0,0 @@
1
- import { PBNode } from '@ipld/dag-pb';
2
- import { CID } from 'multiformats/cid';
3
- export interface Builders {
4
- inlink: (links: CID[], size: number, linkDepth: number, chunkSize: number) => PBNode;
5
- chunk: (data: Buffer) => PBNode;
6
- root: (links: CID[], size: number, linkDepth: number, name?: string, maxNodeSize?: number) => PBNode;
7
- single: (data: Buffer, filename?: string) => PBNode;
8
- }
9
- export declare const metadataBuilders: Builders;
10
- export declare const fileBuilders: Builders;
11
- //# sourceMappingURL=builders.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/ipld/builders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAYtC,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IACpF,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IAC/B,IAAI,EAAE,CACJ,KAAK,EAAE,GAAG,EAAE,EACZ,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,KACjB,MAAM,CAAA;IACX,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;CACpD;AACD,eAAO,MAAM,gBAAgB,EAAE,QAK9B,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,QAK1B,CAAA"}
@@ -1,13 +0,0 @@
1
- import { createChunkedFileIpldNode, createChunkedMetadataIpldNode, createFileChunkIpldNode, createFileInlinkIpldNode, createMetadataChunkIpldNode, createMetadataInlinkIpldNode, createSingleFileIpldNode, createSingleMetadataIpldNode, } from './nodes.js';
2
- export const metadataBuilders = {
3
- inlink: createMetadataInlinkIpldNode,
4
- chunk: createMetadataChunkIpldNode,
5
- root: createChunkedMetadataIpldNode,
6
- single: createSingleMetadataIpldNode,
7
- };
8
- export const fileBuilders = {
9
- inlink: createFileInlinkIpldNode,
10
- chunk: createFileChunkIpldNode,
11
- root: createChunkedFileIpldNode,
12
- single: createSingleFileIpldNode,
13
- };
@@ -1,22 +0,0 @@
1
- import { PBNode } from '@ipld/dag-pb';
2
- import { CID } from 'multiformats';
3
- import { OffchainMetadata } from '../metadata/index.js';
4
- export declare const DEFAULT_MAX_CHUNK_SIZE: number;
5
- export declare const DEFAULT_MAX_LINK_PER_NODE: number;
6
- export interface IPLDDag {
7
- headCID: CID;
8
- nodes: Map<CID, PBNode>;
9
- }
10
- export declare const createFileIPLDDag: (file: AsyncIterable<Buffer>, filename?: string, { chunkSize, maxLinkPerNode }?: {
11
- chunkSize: number;
12
- maxLinkPerNode: number;
13
- }) => Promise<IPLDDag>;
14
- export declare const createMetadataIPLDDag: (metadata: OffchainMetadata, limits?: {
15
- chunkSize: number;
16
- maxLinkPerNode: number;
17
- }) => Promise<IPLDDag>;
18
- export declare const createFolderIPLDDag: (children: CID[], name: string, size: number, { maxLinkPerNode }?: {
19
- maxLinkPerNode: number;
20
- }) => IPLDDag;
21
- export declare const ensureNodeMaxSize: (node: PBNode, maxSize?: number) => PBNode;
22
- //# sourceMappingURL=chunker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunker.d.ts","sourceRoot":"","sources":["../../../src/ipld/chunker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAElC,OAAO,EAAgB,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAKrE,eAAO,MAAM,sBAAsB,QAAY,CAAA;AAC/C,eAAO,MAAM,yBAAyB,QAA8B,CAAA;AAEpE,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,GAAG,CAAA;IACZ,KAAK,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;CACxB;AAED,eAAO,MAAM,iBAAiB,SACtB,aAAa,CAAC,MAAM,CAAC,aAChB,MAAM,kCACc;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,KAI3E,OAAO,CAAC,OAAO,CAEjB,CAAA;AAED,eAAO,MAAM,qBAAqB,aACtB,gBAAgB,WAClB;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,KAIpD,OAAO,CAAC,OAAO,CAWjB,CAAA;AA6DD,eAAO,MAAM,mBAAmB,aACpB,GAAG,EAAE,QACT,MAAM,QACN,MAAM,uBACQ;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,KAC7C,OAyBF,CAAA;AAED,eAAO,MAAM,iBAAiB,SACtB,MAAM,YACH,MAAM,KACd,MAOF,CAAA"}
@@ -1,144 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
11
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
14
- return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
15
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
16
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
17
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
18
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
19
- function fulfill(value) { resume("next", value); }
20
- function reject(value) { resume("throw", value); }
21
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
22
- };
23
- var __asyncValues = (this && this.__asyncValues) || function (o) {
24
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
25
- var m = o[Symbol.asyncIterator], i;
26
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
27
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
28
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
29
- };
30
- import { cidOfNode } from '../cid/index.js';
31
- import { IPLDNodeData } from '../metadata/index.js';
32
- import { fileBuilders, metadataBuilders } from './builders.js';
33
- import { createFolderInlinkIpldNode, createFolderIpldNode } from './nodes.js';
34
- import { chunkBuffer, encodeNode } from './utils.js';
35
- export const DEFAULT_MAX_CHUNK_SIZE = 1024 * 64;
36
- export const DEFAULT_MAX_LINK_PER_NODE = DEFAULT_MAX_CHUNK_SIZE / 64;
37
- export const createFileIPLDDag = (file, filename, { chunkSize, maxLinkPerNode } = {
38
- chunkSize: DEFAULT_MAX_CHUNK_SIZE,
39
- maxLinkPerNode: DEFAULT_MAX_LINK_PER_NODE,
40
- }) => {
41
- return createBufferIPLDDag(file, filename, fileBuilders, { chunkSize, maxLinkPerNode });
42
- };
43
- export const createMetadataIPLDDag = (metadata_1, ...args_1) => __awaiter(void 0, [metadata_1, ...args_1], void 0, function* (metadata, limits = {
44
- chunkSize: DEFAULT_MAX_CHUNK_SIZE,
45
- maxLinkPerNode: DEFAULT_MAX_LINK_PER_NODE,
46
- }) {
47
- const buffer = Buffer.from(JSON.stringify(metadata));
48
- const name = `${metadata.name}.metadata.json`;
49
- return createBufferIPLDDag((function () {
50
- return __asyncGenerator(this, arguments, function* () {
51
- yield yield __await(buffer);
52
- });
53
- })(), name, metadataBuilders, limits);
54
- });
55
- const createBufferIPLDDag = (buffer_1, filename_1, builders_1, ...args_1) => __awaiter(void 0, [buffer_1, filename_1, builders_1, ...args_1], void 0, function* (buffer, filename, builders, { chunkSize, maxLinkPerNode } = {
56
- chunkSize: DEFAULT_MAX_CHUNK_SIZE,
57
- maxLinkPerNode: DEFAULT_MAX_LINK_PER_NODE,
58
- }) {
59
- var _a, e_1, _b, _c;
60
- const bufferChunks = chunkBuffer(buffer, chunkSize);
61
- let totalSize = 0;
62
- const nodes = new Map();
63
- let CIDs = [];
64
- try {
65
- for (var _d = true, bufferChunks_1 = __asyncValues(bufferChunks), bufferChunks_1_1; bufferChunks_1_1 = yield bufferChunks_1.next(), _a = bufferChunks_1_1.done, !_a; _d = true) {
66
- _c = bufferChunks_1_1.value;
67
- _d = false;
68
- const chunk = _c;
69
- const node = builders.chunk(chunk);
70
- const cid = cidOfNode(node);
71
- nodes.set(cid, node);
72
- totalSize += chunk.byteLength;
73
- CIDs.push(cid);
74
- }
75
- }
76
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
77
- finally {
78
- try {
79
- if (!_d && !_a && (_b = bufferChunks_1.return)) yield _b.call(bufferChunks_1);
80
- }
81
- finally { if (e_1) throw e_1.error; }
82
- }
83
- if (CIDs.length === 1) {
84
- const node = nodes.get(CIDs[0]);
85
- const data = IPLDNodeData.decode(Buffer.from(node.Data));
86
- const singleNode = builders.single(Buffer.from(data.data), filename);
87
- const headCID = cidOfNode(singleNode);
88
- return {
89
- headCID,
90
- nodes: new Map([[headCID, singleNode]]),
91
- };
92
- }
93
- let depth = 1;
94
- while (CIDs.length > maxLinkPerNode) {
95
- const newCIDs = [];
96
- for (let i = 0; i < CIDs.length; i += maxLinkPerNode) {
97
- const chunk = CIDs.slice(i, i + maxLinkPerNode);
98
- const node = builders.inlink(chunk, chunk.length, depth, chunkSize);
99
- const cid = cidOfNode(node);
100
- nodes.set(cid, node);
101
- newCIDs.push(cid);
102
- }
103
- depth++;
104
- CIDs = newCIDs;
105
- }
106
- const head = builders.root(CIDs, totalSize, depth, filename, chunkSize);
107
- const headCID = cidOfNode(head);
108
- nodes.set(headCID, head);
109
- return {
110
- headCID,
111
- nodes,
112
- };
113
- });
114
- export const createFolderIPLDDag = (children, name, size, { maxLinkPerNode } = { maxLinkPerNode: DEFAULT_MAX_LINK_PER_NODE }) => {
115
- const nodes = new Map();
116
- let cids = children;
117
- let depth = 0;
118
- while (cids.length > maxLinkPerNode) {
119
- const newCIDs = [];
120
- for (let i = 0; i < cids.length; i += maxLinkPerNode) {
121
- const chunk = cids.slice(i, i + maxLinkPerNode);
122
- const node = createFolderInlinkIpldNode(chunk, depth);
123
- const cid = cidOfNode(node);
124
- nodes.set(cid, node);
125
- newCIDs.push(cid);
126
- }
127
- cids = newCIDs;
128
- depth++;
129
- }
130
- const node = createFolderIpldNode(cids, name, depth, size);
131
- const cid = cidOfNode(node);
132
- nodes.set(cid, node);
133
- return {
134
- headCID: cid,
135
- nodes,
136
- };
137
- };
138
- export const ensureNodeMaxSize = (node, maxSize = DEFAULT_MAX_CHUNK_SIZE) => {
139
- const nodeSize = encodeNode(node).byteLength;
140
- if (nodeSize > maxSize) {
141
- throw new Error(`Node is too large to fit in a single chunk: ${nodeSize} > ${maxSize}`);
142
- }
143
- return node;
144
- };
@@ -1,4 +0,0 @@
1
- export * from './chunker.js';
2
- export * from './nodes.js';
3
- export { encodeNode } from './utils.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ipld/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './chunker.js';
2
- export * from './nodes.js';
3
- export { encodeNode } from './utils.js';
@@ -1,15 +0,0 @@
1
- import { PBNode } from '@ipld/dag-pb';
2
- import { CID } from 'multiformats/cid';
3
- import { OffchainMetadata } from '../metadata/index.js';
4
- export declare const createFileChunkIpldNode: (data: Buffer) => PBNode;
5
- export declare const createChunkedFileIpldNode: (links: CID[], size: number, linkDepth: number, name?: string, maxNodeSize?: number) => PBNode;
6
- export declare const createFileInlinkIpldNode: (links: CID[], size: number, linkDepth: number, maxNodeSize?: number) => PBNode;
7
- export declare const createSingleFileIpldNode: (data: Buffer, name?: string) => PBNode;
8
- export declare const createMetadataInlinkIpldNode: (links: CID[], size: number, linkDepth: number, maxNodeSize?: number) => PBNode;
9
- export declare const createSingleMetadataIpldNode: (data: Buffer, name?: string) => PBNode;
10
- export declare const createMetadataChunkIpldNode: (data: Buffer) => PBNode;
11
- export declare const createChunkedMetadataIpldNode: (links: CID[], size: number, linkDepth: number, name?: string, maxNodeSize?: number) => PBNode;
12
- export declare const createFolderIpldNode: (links: CID[], name: string, linkDepth: number, size: number, maxNodeSize?: number) => PBNode;
13
- export declare const createFolderInlinkIpldNode: (links: CID[], linkDepth: number, maxNodeSize?: number) => PBNode;
14
- export declare const createMetadataNode: (metadata: OffchainMetadata, maxNodeSize?: number) => PBNode;
15
- //# sourceMappingURL=nodes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../../src/ipld/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAKvD,eAAO,MAAM,uBAAuB,SAAU,MAAM,KAAG,MASpD,CAAA;AAKH,eAAO,MAAM,yBAAyB,UAC7B,GAAG,EAAE,QACN,MAAM,aACD,MAAM,SACV,MAAM,gBACA,MAAM,KAClB,MAYA,CAAA;AAGH,eAAO,MAAM,wBAAwB,UAC5B,GAAG,EAAE,QACN,MAAM,aACD,MAAM,gBACJ,MAAM,KAClB,MAWA,CAAA;AAKH,eAAO,MAAM,wBAAwB,SAAU,MAAM,SAAS,MAAM,KAAG,MAUpE,CAAA;AAKH,eAAO,MAAM,4BAA4B,UAChC,GAAG,EAAE,QACN,MAAM,aACD,MAAM,gBACJ,MAAM,KAClB,MAWA,CAAA;AAKH,eAAO,MAAM,4BAA4B,SAAU,MAAM,SAAS,MAAM,KAAG,MAUxE,CAAA;AAEH,eAAO,MAAM,2BAA2B,SAAU,MAAM,KAAG,MAQxD,CAAA;AAEH,eAAO,MAAM,6BAA6B,UACjC,GAAG,EAAE,QACN,MAAM,aACD,MAAM,SACV,MAAM,gBACA,MAAM,KAClB,MAYA,CAAA;AAKH,eAAO,MAAM,oBAAoB,UACxB,GAAG,EAAE,QACN,MAAM,aACD,MAAM,QACX,MAAM,gBACC,MAAM,KAClB,MAYA,CAAA;AAEH,eAAO,MAAM,0BAA0B,UAC9B,GAAG,EAAE,aACD,MAAM,gBACJ,MAAM,KAClB,MAUA,CAAA;AAGH,eAAO,MAAM,kBAAkB,aACnB,gBAAgB,gBACb,MAAM,KAClB,MAcF,CAAA"}
@@ -1,89 +0,0 @@
1
- import { createNode } from '@ipld/dag-pb';
2
- import { encodeIPLDNodeData, MetadataType } from '../metadata/onchain/index.js';
3
- import { DEFAULT_MAX_CHUNK_SIZE, ensureNodeMaxSize } from './chunker.js';
4
- /// Creates a file chunk ipld node
5
- export const createFileChunkIpldNode = (data) => createNode(encodeIPLDNodeData({
6
- type: MetadataType.FileChunk,
7
- size: data.length,
8
- linkDepth: 0,
9
- data,
10
- }), []);
11
- // Creates a file ipld node
12
- // links: the CIDs of the file's contents
13
- // @todo: add the file's metadata
14
- export const createChunkedFileIpldNode = (links, size, linkDepth, name, maxNodeSize = DEFAULT_MAX_CHUNK_SIZE) => ensureNodeMaxSize(createNode(encodeIPLDNodeData({
15
- type: MetadataType.File,
16
- name,
17
- size,
18
- linkDepth,
19
- }), links.map((cid) => ({ Hash: cid }))), maxNodeSize);
20
- // Creates a file ipld node
21
- // links: the CIDs of the file's contents
22
- export const createFileInlinkIpldNode = (links, size, linkDepth, maxNodeSize = DEFAULT_MAX_CHUNK_SIZE) => ensureNodeMaxSize(createNode(encodeIPLDNodeData({
23
- type: MetadataType.FileInlink,
24
- size,
25
- linkDepth,
26
- }), links.map((cid) => ({ Hash: cid }))), maxNodeSize);
27
- // Creates a file ipld node
28
- // links: the CIDs of the file's contents
29
- // @todo: add the file's metadata
30
- export const createSingleFileIpldNode = (data, name) => createNode(encodeIPLDNodeData({
31
- type: MetadataType.File,
32
- name,
33
- size: data.length,
34
- linkDepth: 0,
35
- data,
36
- }), []);
37
- // Creates a file ipld node
38
- // links: the CIDs of the file's contents
39
- // @todo: add the file's metadata
40
- export const createMetadataInlinkIpldNode = (links, size, linkDepth, maxNodeSize = DEFAULT_MAX_CHUNK_SIZE) => ensureNodeMaxSize(createNode(encodeIPLDNodeData({
41
- type: MetadataType.FileInlink,
42
- size,
43
- linkDepth,
44
- }), links.map((cid) => ({ Hash: cid }))), maxNodeSize);
45
- // Creates a file ipld node
46
- // links: the CIDs of the file's contents
47
- // @todo: add the file's metadata
48
- export const createSingleMetadataIpldNode = (data, name) => createNode(encodeIPLDNodeData({
49
- type: MetadataType.Metadata,
50
- name,
51
- size: data.length,
52
- linkDepth: 0,
53
- data,
54
- }), []);
55
- export const createMetadataChunkIpldNode = (data) => createNode(encodeIPLDNodeData({
56
- type: MetadataType.MetadataChunk,
57
- size: data.length,
58
- linkDepth: 0,
59
- data,
60
- }));
61
- export const createChunkedMetadataIpldNode = (links, size, linkDepth, name, maxNodeSize = DEFAULT_MAX_CHUNK_SIZE) => ensureNodeMaxSize(createNode(encodeIPLDNodeData({
62
- type: MetadataType.Metadata,
63
- name,
64
- size,
65
- linkDepth,
66
- }), links.map((cid) => ({ Hash: cid }))), maxNodeSize);
67
- // Creates a folder ipld node
68
- // links: the CIDs of the folder's contents
69
- // @todo: add the folder's metadata
70
- export const createFolderIpldNode = (links, name, linkDepth, size, maxNodeSize = DEFAULT_MAX_CHUNK_SIZE) => ensureNodeMaxSize(createNode(encodeIPLDNodeData({
71
- type: MetadataType.Folder,
72
- name,
73
- size,
74
- linkDepth,
75
- }), links.map((cid) => ({ Hash: cid }))), maxNodeSize);
76
- export const createFolderInlinkIpldNode = (links, linkDepth, maxNodeSize = DEFAULT_MAX_CHUNK_SIZE) => ensureNodeMaxSize(createNode(encodeIPLDNodeData({
77
- type: MetadataType.FolderInlink,
78
- linkDepth,
79
- }), links.map((cid) => ({ Hash: cid }))), maxNodeSize);
80
- /// Creates a metadata ipld node
81
- export const createMetadataNode = (metadata, maxNodeSize = DEFAULT_MAX_CHUNK_SIZE) => {
82
- const data = Buffer.from(JSON.stringify(metadata));
83
- return ensureNodeMaxSize(createNode(encodeIPLDNodeData({
84
- type: MetadataType.Metadata,
85
- name: metadata.name,
86
- linkDepth: 0,
87
- data,
88
- })), maxNodeSize);
89
- };
@@ -1,5 +0,0 @@
1
- import { PBNode } from '@ipld/dag-pb';
2
- export declare const chunkBuffer: (buffer: AsyncIterable<Buffer>, chunkSize: number) => AsyncIterable<Buffer>;
3
- export declare const encodeNode: (node: PBNode) => Buffer;
4
- export declare const decodeNode: (data: Uint8Array) => PBNode;
5
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/ipld/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,EAAE,MAAM,cAAc,CAAA;AAErD,eAAO,MAAM,WAAW,WACd,aAAa,CAAC,MAAM,CAAC,aAClB,MAAM,KAChB,aAAa,CAAC,MAAM,CAYtB,CAAA;AAED,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,MAAmC,CAAA;AAE7E,eAAO,MAAM,UAAU,SAAU,UAAU,KAAG,MAAsB,CAAA"}
@@ -1,51 +0,0 @@
1
- var __asyncValues = (this && this.__asyncValues) || function (o) {
2
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
3
- var m = o[Symbol.asyncIterator], i;
4
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
5
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
6
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
7
- };
8
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
9
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
10
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
11
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
12
- return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
13
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
14
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
15
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
16
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
17
- function fulfill(value) { resume("next", value); }
18
- function reject(value) { resume("throw", value); }
19
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
20
- };
21
- import { decode, encode } from '@ipld/dag-pb';
22
- export const chunkBuffer = function (buffer, chunkSize) {
23
- return __asyncGenerator(this, arguments, function* () {
24
- var _a, e_1, _b, _c;
25
- let target = Buffer.alloc(0);
26
- try {
27
- for (var _d = true, buffer_1 = __asyncValues(buffer), buffer_1_1; buffer_1_1 = yield __await(buffer_1.next()), _a = buffer_1_1.done, !_a; _d = true) {
28
- _c = buffer_1_1.value;
29
- _d = false;
30
- let chunk = _c;
31
- target = Buffer.concat([target, chunk]);
32
- while (target.length >= chunkSize) {
33
- yield yield __await(target.subarray(0, chunkSize));
34
- target = target.subarray(chunkSize);
35
- }
36
- }
37
- }
38
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
39
- finally {
40
- try {
41
- if (!_d && !_a && (_b = buffer_1.return)) yield __await(_b.call(buffer_1));
42
- }
43
- finally { if (e_1) throw e_1.error; }
44
- }
45
- if (target.length > 0) {
46
- yield yield __await(target);
47
- }
48
- });
49
- };
50
- export const encodeNode = (node) => Buffer.from(encode(node));
51
- export const decodeNode = (data) => decode(data);
@@ -1,3 +0,0 @@
1
- export * from './offchain/index.js';
2
- export * from './onchain/index.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metadata/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './offchain/index.js';
2
- export * from './onchain/index.js';
@@ -1,4 +0,0 @@
1
- import { OffchainFileMetadata } from './file.js';
2
- import { OffchainFolderMetadata } from './folder.js';
3
- export type OffchainMetadata = OffchainFolderMetadata | OffchainFileMetadata;
4
- //# sourceMappingURL=base.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/metadata/offchain/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEpD,MAAM,MAAM,gBAAgB,GAAG,sBAAsB,GAAG,oBAAoB,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- import { IPLDDag } from '../../index.js';
2
- export type OffchainFileMetadata = {
3
- type: 'file';
4
- dataCid: string;
5
- name?: string;
6
- mimeType?: string;
7
- totalSize: number;
8
- totalChunks: number;
9
- chunks: ChunkInfo[];
10
- };
11
- export interface ChunkInfo {
12
- size: number;
13
- cid: string;
14
- }
15
- export declare const fileMetadata: (dag: IPLDDag, totalSize: number, name?: string, mimeType?: string) => OffchainFileMetadata;
16
- //# sourceMappingURL=file.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../../src/metadata/offchain/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,OAAO,EAA8B,MAAM,gBAAgB,CAAA;AAE5F,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,SAAS,EAAE,CAAA;CACpB,CAAA;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,eAAO,MAAM,YAAY,QAClB,OAAO,aACD,MAAM,SACV,MAAM,aACF,MAAM,KAChB,oBAiBF,CAAA"}
@@ -1,19 +0,0 @@
1
- import { cidOfNode, cidToString, IPLDNodeData } from '../../index.js';
2
- export const fileMetadata = (dag, totalSize, name, mimeType) => {
3
- const chunks = Array.from(dag.nodes.values()).filter((n) => n.Data && IPLDNodeData.decode(n.Data).data);
4
- return {
5
- type: 'file',
6
- dataCid: cidToString(dag.headCID),
7
- name,
8
- mimeType,
9
- totalSize,
10
- totalChunks: chunks.length,
11
- chunks: chunks.map((chunk) => {
12
- var _a, _b;
13
- return ({
14
- cid: cidToString(cidOfNode(chunk)),
15
- size: (_b = (_a = chunk.Data) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
16
- });
17
- }),
18
- };
19
- };
@@ -1,17 +0,0 @@
1
- interface ChildrenMetadata {
2
- type: 'folder' | 'file';
3
- name?: string;
4
- cid: string;
5
- totalSize: number;
6
- }
7
- export type OffchainFolderMetadata = {
8
- type: 'folder';
9
- dataCid: string;
10
- name?: string;
11
- totalSize: number;
12
- totalFiles: number;
13
- children: ChildrenMetadata[];
14
- };
15
- export declare const folderMetadata: (cid: string, children: ChildrenMetadata[], name?: string) => OffchainFolderMetadata;
16
- export {};
17
- //# sourceMappingURL=folder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"folder.d.ts","sourceRoot":"","sources":["../../../../src/metadata/offchain/folder.ts"],"names":[],"mappings":"AAAA,UAAU,gBAAgB;IACxB,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,QAAQ,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,gBAAgB,EAAE,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,cAAc,QACpB,MAAM,YACD,gBAAgB,EAAE,SACrB,MAAM,KACZ,sBASF,CAAA"}
@@ -1,10 +0,0 @@
1
- export const folderMetadata = (cid, children, name) => {
2
- return {
3
- dataCid: cid,
4
- totalSize: children.reduce((acc, child) => acc + child.totalSize, 0),
5
- totalFiles: children.length,
6
- children,
7
- type: 'folder',
8
- name,
9
- };
10
- };
@@ -1,4 +0,0 @@
1
- export * from './base.js';
2
- export * from './file.js';
3
- export * from './folder.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/metadata/offchain/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './base.js';
2
- export * from './file.js';
3
- export * from './folder.js';
@@ -1,3 +0,0 @@
1
- export * from './protobuf/OnchainMetadata.js';
2
- export * from './utils.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/metadata/onchain/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,YAAY,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './protobuf/OnchainMetadata.js';
2
- export * from './utils.js';
@@ -1,28 +0,0 @@
1
- import { type Codec, type DecodeOptions } from 'protons-runtime';
2
- import type { Uint8ArrayList } from 'uint8arraylist';
3
- export interface IPLDNodeData {
4
- type: MetadataType;
5
- linkDepth: number;
6
- size?: number;
7
- name?: string;
8
- data?: Uint8Array;
9
- }
10
- export declare namespace IPLDNodeData {
11
- const codec: () => Codec<IPLDNodeData>;
12
- const encode: (obj: Partial<IPLDNodeData>) => Uint8Array;
13
- const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<IPLDNodeData>) => IPLDNodeData;
14
- }
15
- export declare enum MetadataType {
16
- File = "File",
17
- FileInlink = "FileInlink",
18
- FileChunk = "FileChunk",
19
- Folder = "Folder",
20
- FolderInlink = "FolderInlink",
21
- Metadata = "Metadata",
22
- MetadataInlink = "MetadataInlink",
23
- MetadataChunk = "MetadataChunk"
24
- }
25
- export declare namespace MetadataType {
26
- const codec: () => Codec<MetadataType>;
27
- }
28
- //# sourceMappingURL=OnchainMetadata.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OnchainMetadata.d.ts","sourceRoot":"","sources":["../../../../../src/metadata/onchain/protobuf/OnchainMetadata.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAAiB,KAAK,aAAa,EAAuC,MAAM,iBAAiB,CAAA;AACpH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,YAAY,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB;AAED,yBAAiB,YAAY,CAAC;IAGrB,MAAM,KAAK,QAAO,KAAK,CAAC,YAAY,CA+E1C,CAAA;IAEM,MAAM,MAAM,QAAS,OAAO,CAAC,YAAY,CAAC,KAAG,UAEnD,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,SAAS,aAAa,CAAC,YAAY,CAAC,KAAG,YAE7F,CAAA;CACF;AAED,oBAAY,YAAY;IACtB,IAAI,SAAS;IACb,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,QAAQ,aAAa;IACrB,cAAc,mBAAmB;IACjC,aAAa,kBAAkB;CAChC;AAaD,yBAAiB,YAAY,CAAC;IACrB,MAAM,KAAK,QAAO,KAAK,CAAC,YAAY,CAE1C,CAAA;CACF"}
@@ -1,112 +0,0 @@
1
- /* eslint-disable import/export */
2
- /* eslint-disable complexity */
3
- /* eslint-disable @typescript-eslint/no-namespace */
4
- /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
5
- /* eslint-disable @typescript-eslint/no-empty-interface */
6
- import { decodeMessage, encodeMessage, enumeration, message } from 'protons-runtime';
7
- export var IPLDNodeData;
8
- (function (IPLDNodeData) {
9
- let _codec;
10
- IPLDNodeData.codec = () => {
11
- if (_codec == null) {
12
- _codec = message((obj, w, opts = {}) => {
13
- if (opts.lengthDelimited !== false) {
14
- w.fork();
15
- }
16
- if (obj.type != null && __MetadataTypeValues[obj.type] !== 0) {
17
- w.uint32(8);
18
- MetadataType.codec().encode(obj.type, w);
19
- }
20
- if ((obj.linkDepth != null && obj.linkDepth !== 0)) {
21
- w.uint32(16);
22
- w.int32(obj.linkDepth);
23
- }
24
- if (obj.size != null) {
25
- w.uint32(24);
26
- w.int32(obj.size);
27
- }
28
- if (obj.name != null) {
29
- w.uint32(34);
30
- w.string(obj.name);
31
- }
32
- if (obj.data != null) {
33
- w.uint32(42);
34
- w.bytes(obj.data);
35
- }
36
- if (opts.lengthDelimited !== false) {
37
- w.ldelim();
38
- }
39
- }, (reader, length, opts = {}) => {
40
- const obj = {
41
- type: MetadataType.File,
42
- linkDepth: 0
43
- };
44
- const end = length == null ? reader.len : reader.pos + length;
45
- while (reader.pos < end) {
46
- const tag = reader.uint32();
47
- switch (tag >>> 3) {
48
- case 1: {
49
- obj.type = MetadataType.codec().decode(reader);
50
- break;
51
- }
52
- case 2: {
53
- obj.linkDepth = reader.int32();
54
- break;
55
- }
56
- case 3: {
57
- obj.size = reader.int32();
58
- break;
59
- }
60
- case 4: {
61
- obj.name = reader.string();
62
- break;
63
- }
64
- case 5: {
65
- obj.data = reader.bytes();
66
- break;
67
- }
68
- default: {
69
- reader.skipType(tag & 7);
70
- break;
71
- }
72
- }
73
- }
74
- return obj;
75
- });
76
- }
77
- return _codec;
78
- };
79
- IPLDNodeData.encode = (obj) => {
80
- return encodeMessage(obj, IPLDNodeData.codec());
81
- };
82
- IPLDNodeData.decode = (buf, opts) => {
83
- return decodeMessage(buf, IPLDNodeData.codec(), opts);
84
- };
85
- })(IPLDNodeData || (IPLDNodeData = {}));
86
- export var MetadataType;
87
- (function (MetadataType) {
88
- MetadataType["File"] = "File";
89
- MetadataType["FileInlink"] = "FileInlink";
90
- MetadataType["FileChunk"] = "FileChunk";
91
- MetadataType["Folder"] = "Folder";
92
- MetadataType["FolderInlink"] = "FolderInlink";
93
- MetadataType["Metadata"] = "Metadata";
94
- MetadataType["MetadataInlink"] = "MetadataInlink";
95
- MetadataType["MetadataChunk"] = "MetadataChunk";
96
- })(MetadataType || (MetadataType = {}));
97
- var __MetadataTypeValues;
98
- (function (__MetadataTypeValues) {
99
- __MetadataTypeValues[__MetadataTypeValues["File"] = 0] = "File";
100
- __MetadataTypeValues[__MetadataTypeValues["FileInlink"] = 1] = "FileInlink";
101
- __MetadataTypeValues[__MetadataTypeValues["FileChunk"] = 2] = "FileChunk";
102
- __MetadataTypeValues[__MetadataTypeValues["Folder"] = 3] = "Folder";
103
- __MetadataTypeValues[__MetadataTypeValues["FolderInlink"] = 4] = "FolderInlink";
104
- __MetadataTypeValues[__MetadataTypeValues["Metadata"] = 5] = "Metadata";
105
- __MetadataTypeValues[__MetadataTypeValues["MetadataInlink"] = 6] = "MetadataInlink";
106
- __MetadataTypeValues[__MetadataTypeValues["MetadataChunk"] = 7] = "MetadataChunk";
107
- })(__MetadataTypeValues || (__MetadataTypeValues = {}));
108
- (function (MetadataType) {
109
- MetadataType.codec = () => {
110
- return enumeration(__MetadataTypeValues);
111
- };
112
- })(MetadataType || (MetadataType = {}));
@@ -1,4 +0,0 @@
1
- import { IPLDNodeData } from '../onchain/index.js';
2
- export declare const encodeIPLDNodeData: (metadata: IPLDNodeData) => Uint8Array;
3
- export declare const decodeIPLDNodeData: (data: Uint8Array) => IPLDNodeData;
4
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/metadata/onchain/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,eAAO,MAAM,kBAAkB,aAAc,YAAY,KAAG,UAE3D,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU,UAAU,KAAG,YAOrD,CAAA"}
@@ -1,12 +0,0 @@
1
- import { decode } from '@ipld/dag-pb';
2
- import { IPLDNodeData } from '../onchain/index.js';
3
- export const encodeIPLDNodeData = (metadata) => {
4
- return IPLDNodeData.encode(metadata);
5
- };
6
- export const decodeIPLDNodeData = (data) => {
7
- const decoded = decode(data);
8
- if (!decoded.Data) {
9
- throw new Error('Invalid data');
10
- }
11
- return IPLDNodeData.decode(decoded.Data);
12
- };