@atproto/common 0.4.12 → 0.5.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @atproto/common
2
2
 
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`46550d6`](https://github.com/bluesky-social/atproto/commit/46550d6c1ffb298f57d54eb1904067b2df5a40af)]:
8
+ - @atproto/lex-cbor@0.0.1
9
+ - @atproto/lex-data@0.0.1
10
+ - @atproto/common-web@0.4.5
11
+
12
+ ## 0.5.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#4366](https://github.com/bluesky-social/atproto/pull/4366) [`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove `utf8ToB64Url` and `b64UrlToUtf8` utilities
17
+
18
+ - [#4366](https://github.com/bluesky-social/atproto/pull/4366) [`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove `sha256ToCid` utility
19
+
20
+ ### Patch Changes
21
+
22
+ - [#4366](https://github.com/bluesky-social/atproto/pull/4366) [`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Deprecate "ipld" functions (use `@atproto/lex-data`, `@atproto/lex-json` and `@atproto/lex-cbor` instead)
23
+
24
+ - Updated dependencies [[`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7), [`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7), [`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7)]:
25
+ - @atproto/common-web@0.4.4
26
+
3
27
  ## 0.4.12
4
28
 
5
29
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"buffers.js","sourceRoot":"","sources":["../src/buffers.ts"],"names":[],"mappings":";;AAAA,kCAEC;AAED,4CAKC;AATD,SAAgB,WAAW,CAAC,KAAiB;IAC3C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;AACtE,CAAC;AAED,SAAgB,gBAAgB,CAAC,KAAiB;IAChD,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CACvB,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CACpC,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"buffers.js","sourceRoot":"","sources":["../src/buffers.ts"],"names":[],"mappings":";;AAAA,kCAEC;AAED,4CAKC;AATD,SAAgB,WAAW,CAAC,KAAiB;IAC3C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;AACtE,CAAC;AAED,SAAgB,gBAAgB,CAAC,KAAiB;IAChD,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CACvB,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CACpC,CAAA;AACH,CAAC","sourcesContent":["export function ui8ToBuffer(bytes: Uint8Array): Buffer {\n return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n}\n\nexport function ui8ToArrayBuffer(bytes: Uint8Array): ArrayBuffer {\n return bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteLength + bytes.byteOffset,\n )\n}\n"]}
package/dist/dates.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"dates.js","sourceRoot":"","sources":["../src/dates.ts"],"names":[],"mappings":";;AAIA,kDAWC;AAfD,uEAA+D;AAE/D,6FAA6F;AAC7F,2EAA2E;AAC3E,SAAgB,mBAAmB,CAAC,OAAe;IACjD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAA;IAC9B,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IAClC,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;IAC9B,IAAI,CAAC,IAAA,+CAAoB,EAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,2GAA2G;QAC3G,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IAClC,CAAC;IACD,OAAO,GAAG,CAAA,CAAC,2BAA2B;AACxC,CAAC"}
1
+ {"version":3,"file":"dates.js","sourceRoot":"","sources":["../src/dates.ts"],"names":[],"mappings":";;AAIA,kDAWC;AAfD,uEAA+D;AAE/D,6FAA6F;AAC7F,2EAA2E;AAC3E,SAAgB,mBAAmB,CAAC,OAAe;IACjD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAA;IAC9B,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IAClC,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;IAC9B,IAAI,CAAC,IAAA,+CAAoB,EAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,2GAA2G;QAC3G,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IAClC,CAAC;IACD,OAAO,GAAG,CAAA,CAAC,2BAA2B;AACxC,CAAC","sourcesContent":["import { isValidISODateString } from 'iso-datestring-validator'\n\n// Normalize date strings to simplified ISO so that the lexical sort preserves temporal sort.\n// Rather than failing on an invalid date format, returns valid unix epoch.\nexport function toSimplifiedISOSafe(dateStr: string) {\n const date = new Date(dateStr)\n if (isNaN(date.getTime())) {\n return new Date(0).toISOString()\n }\n const iso = date.toISOString()\n if (!isValidISODateString(iso)) {\n // Occurs in rare cases, e.g. where resulting UTC year is negative. These also don't preserve lexical sort.\n return new Date(0).toISOString()\n }\n return iso // YYYY-MM-DDTHH:mm:ss.sssZ\n}\n"]}
package/dist/env.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";;;AAAA,oDAA0D;AAEnD,MAAM,MAAM,GAAG,CAAC,IAAY,EAAsB,EAAE;IACzD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,OAAO,IAAA,iCAAoB,EAAC,GAAG,EAAE,SAAS,CAAC,CAAA;AAC7C,CAAC,CAAA;AAHY,QAAA,MAAM,UAGlB;AAEM,MAAM,MAAM,GAAG,CAAC,IAAY,EAAsB,EAAE;IACzD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAC3D,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAJY,QAAA,MAAM,UAIlB;AAEM,MAAM,OAAO,GAAG,CAAC,IAAY,EAAuB,EAAE;IAC3D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,GAAG;QAAE,OAAO,IAAI,CAAA;IAC9C,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,GAAG;QAAE,OAAO,KAAK,CAAA;IAChD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AALY,Q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AO,WAKnB;AAEM,MAAM,OAAO,GAAG,CAAC,IAAY,EAAY,EAAE;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACpD,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC,CAAA;AAJY,QAAA,OAAO,WAInB","sourcesContent":["import { parseIntWithFallback } from '@atproto/common-web'\n\nexport const envInt = (name: string): number | undefined => {\n const str = process.env[name]\n return parseIntWithFallback(str, undefined)\n}\n\nexport const envStr = (name: string): string | undefined => {\n const str = process.env[name]\n if (str === undefined || str.length === 0) return undefined\n return str\n}\n\nexport const envBool = (name: string): boolean | undefined => {\n const str = process.env[name]\n if (str === 'true' || str === '1') return true\n if (str === 'false' || str === '0') return false\n return undefined\n}\n\nexport const envList = (name: string): string[] => {\n const str = process.env[name]\n if (str === undefined || str.length === 0) return []\n return str.split(',')\n}\n"]}
package/dist/fs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAmC;AACnC,gEAAiC;AACjC,oDAAsD;AAE/C,MAAM,UAAU,GAAG,KAAK,EAAE,QAAgB,EAAoB,EAAE;IACrE,IAAI,CAAC;QACH,MAAM,kBAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,mBAAS,CAAC,IAAI,CAAC,CAAA;QACzC,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,IAAA,6BAAgB,EAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnD,OAAO,KAAK,CAAA;QACd,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC,CAAA;AAVY,QAAA,UA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C,CAAA;AAZY,QAAA,UAAU,cAYtB;AAEM,MAAM,cAAc,GAAG,KAAK,EACjC,OAAe,EACf,OAAe,EACA,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,kBAAE,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,IAAA,6BAAgB,EAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnD,OAAM;QACR,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC,CAAA;AAZY,QAAA,cAAc,kBAY1B","sourcesContent":["import { constants } from 'node:fs'\nimport fs from 'node:fs/promises'\nimport { isErrnoException } from '@atproto/common-web'\n\nexport const fileExists = async (location: string): Promise<boolean> => {\n try {\n await fs.access(location, constants.F_OK)\n return true\n } catch (err) {\n if (isErrnoException(err) && err.code === 'ENOENT') {\n return false\n }\n throw err\n }\n}\n\nexport const readIfExists = async (\n filepath: string,\n): Promise<Uint8Array | undefined> => {\n try {\n return await fs.readFile(filepath)\n } catch (err) {\n if (isErrnoException(err) && err.code === 'ENOENT') {\n return\n }\n throw err\n }\n}\n\nexport const rmIfExists = async (\n filepath: string,\n recursive = false,\n): Promise<void> => {\n try {\n await fs.rm(filepath, { recursive })\n } catch (err) {\n if (isErrnoException(err) && err.code === 'ENOENT') {\n return\n }\n throw err\n }\n}\n\nexport const renameIfExists = async (\n oldPath: string,\n newPath: string,\n): Promise<void> => {\n try {\n await fs.rename(oldPath, newPath)\n } catch (err) {\n if (isErrnoException(err) && err.code === 'ENOENT') {\n return\n }\n throw err\n }\n}\n"]}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAmC;AACnC,4CAAyB;AACzB,0CAAuB;AACvB,wCAAqB;AACrB,uCAAoB;AACpB,yCAAsB;AACtB,+CAA4B;AAC5B,2CAAwB;AACxB,8CAA2B;AAC3B,4CAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAmC;AACnC,4CAAyB;AACzB,0CAAuB;AACvB,wCAAqB;AACrB,uCAAoB;AACpB,yCAAsB;AACtB,+CAA4B;AAC5B,2CAAwB;AACxB,8CAA2B;AAC3B,4CAAyB","sourcesContent":["export * from '@atproto/common-web'\nexport * from './buffers'\nexport * from './dates'\nexport * from './env'\nexport * from './fs'\nexport * from './ipld'\nexport * from './ipld-multi'\nexport * from './logger'\nexport * from './obfuscate'\nexport * from './streams'\n"]}
@@ -1,2 +1,6 @@
1
- export declare const cborDecodeMulti: (encoded: Uint8Array) => unknown[];
1
+ import { LexValue } from '@atproto/lex-data';
2
+ /**
3
+ * @deprecated Use {@link decodeAll} from `@atproto/lex-cbor` instead.
4
+ */
5
+ export declare function cborDecodeMulti(encoded: Uint8Array): LexValue[];
2
6
  //# sourceMappingURL=ipld-multi.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ipld-multi.d.ts","sourceRoot":"","sources":["../src/ipld-multi.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,eAAe,GAAI,SAAS,UAAU,KAAG,OAAO,EAM5D,CAAA"}
1
+ {"version":3,"file":"ipld-multi.d.ts","sourceRoot":"","sources":["../src/ipld-multi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE5C;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,QAAQ,EAAE,CAE/D"}
@@ -1,68 +1,11 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.cborDecodeMulti = void 0;
37
- const cborx = __importStar(require("cbor-x"));
38
- const cid_1 = require("multiformats/cid");
39
- // add extension for decoding CIDs
40
- // decoding code taken from @ipld/dag-cbor
41
- // does not support encoding cids
42
- cborx.addExtension({
43
- Class: cid_1.CID,
44
- tag: 42,
45
- encode: () => {
46
- throw new Error('cannot encode cids');
47
- },
48
- decode: (bytes) => {
49
- if (bytes[0] !== 0) {
50
- throw new Error('Invalid CID for CBOR tag 42; expected leading 0x00');
51
- }
52
- return cid_1.CID.decode(bytes.subarray(1)); // ignore leading 0x00
53
- },
54
- });
55
- const decoder = new cborx.Decoder({
56
- // @ts-ignore
57
- int64AsNumber: true, // not in types for some reason
58
- useRecords: false,
59
- });
60
- const cborDecodeMulti = (encoded) => {
61
- const decoded = [];
62
- decoder.decodeMultiple(encoded, (value) => {
63
- decoded.push(value);
64
- });
65
- return decoded;
66
- };
67
3
  exports.cborDecodeMulti = cborDecodeMulti;
4
+ const lex_cbor_1 = require("@atproto/lex-cbor");
5
+ /**
6
+ * @deprecated Use {@link decodeAll} from `@atproto/lex-cbor` instead.
7
+ */
8
+ function cborDecodeMulti(encoded) {
9
+ return Array.from((0, lex_cbor_1.decodeAll)(encoded));
10
+ }
68
11
  //# sourceMappingURL=ipld-multi.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ipld-multi.js","sourceRoot":"","sources":["../src/ipld-multi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAA+B;AAC/B,0CAAsC;AAEtC,kCAAkC;AAClC,0CAA0C;AAC1C,iCAAiC;AACjC,KAAK,CAAC,YAAY,CAAC;IACjB,KAAK,EAAE,SAAG;IACV,GAAG,EAAE,EAAE;IACP,MAAM,EAAE,GAAG,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;IACvC,CAAC;IACD,MAAM,EAAE,CAAC,KAAiB,EAAO,EAAE;QACjC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;QACvE,CAAC;QACD,OAAO,SAAG,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA,CAAC,sBAAsB;IAC7D,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC;IAChC,aAAa;IACb,aAAa,EAAE,IAAI,EAAE,+BAA+B;IACpD,UAAU,EAAE,KAAK;CAClB,CAAC,CAAA;AAEK,MAAM,eAAe,GAAG,CAAC,OAAmB,EAAa,EAAE;IAChE,MAAM,OAAO,GAAc,EAAE,CAAA;IAC7B,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QACxC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC,CAAC,CAAA;IACF,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AANY,QAAA,eAAe,mBAM3B"}
1
+ {"version":3,"file":"ipld-multi.js","sourceRoot":"","sources":["../src/ipld-multi.ts"],"names":[],"mappings":";;AAMA,0CAEC;AARD,gDAA6C;AAG7C;;GAEG;AACH,SAAgB,eAAe,CAAC,OAAmB;IACjD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAA,oBAAS,EAAC,OAAO,CAAC,CAAC,CAAA;AACvC,CAAC","sourcesContent":["import { decodeAll } from '@atproto/lex-cbor'\nimport { LexValue } from '@atproto/lex-data'\n\n/**\n * @deprecated Use {@link decodeAll} from `@atproto/lex-cbor` instead.\n */\nexport function cborDecodeMulti(encoded: Uint8Array): LexValue[] {\n return Array.from(decodeAll(encoded))\n}\n"]}
package/dist/ipld.d.ts CHANGED
@@ -1,17 +1,48 @@
1
1
  import { Transform } from 'node:stream';
2
- import * as cborCodec from '@ipld/dag-cbor';
3
- import * as Block from 'multiformats/block';
4
- import { CID } from 'multiformats/cid';
5
- export declare const cborEncode: typeof cborCodec.encode;
6
- export declare const cborDecode: typeof cborCodec.decode;
7
- export declare const dataToCborBlock: (data: unknown) => Promise<Block.Block<unknown>>;
8
- export declare const cidForCbor: (data: unknown) => Promise<CID>;
9
- export declare const isValidCid: (cidStr: string) => Promise<boolean>;
10
- export declare const cborBytesToRecord: (bytes: Uint8Array) => Record<string, unknown>;
11
- export declare const verifyCidForBytes: (cid: CID, bytes: Uint8Array) => Promise<void>;
12
- export declare const sha256ToCid: (hash: Uint8Array, codec: number) => CID;
13
- export declare const sha256RawToCid: (hash: Uint8Array) => CID;
14
- export declare const parseCidFromBytes: (cidBytes: Uint8Array) => CID;
2
+ import { Block, ByteView } from 'multiformats/block';
3
+ import { cidForRawHash, parseCidFromBytes, verifyCidForBytes } from '@atproto/lex-cbor';
4
+ import { CID } from '@atproto/lex-data';
5
+ /**
6
+ * @deprecated Use {@link encode} from `@atproto/lex-cbor` instead.
7
+ */
8
+ declare const cborEncodeLegacy: <T = unknown>(data: T) => ByteView<T>;
9
+ export { cborEncodeLegacy as cborEncode };
10
+ /**
11
+ * @deprecated Use {@link decode} from `@atproto/lex-cbor` instead.
12
+ */
13
+ declare const cborDecodeLegacy: <T = unknown>(bytes: ByteView<T>) => T;
14
+ export { cborDecodeLegacy as cborDecode };
15
+ /**
16
+ * @deprecated Use {@link encode} and {@link cidForCbor} from `@atproto/lex-cbor` instead.
17
+ */
18
+ export declare function dataToCborBlock<T>(value: T): Promise<Block<T>>;
19
+ /**
20
+ * @deprecated Use {@link cidForLex} from `@atproto/lex-cbor` instead.
21
+ */
22
+ export declare const cidForCborLegacy: (data: unknown) => Promise<CID>;
23
+ export { cidForCborLegacy as cidForCbor };
24
+ /**
25
+ * @deprecated Use {@link validateCidString} from '@atproto/lex-data' instead.
26
+ */
27
+ export declare function isValidCid(cidStr: string): Promise<boolean>;
28
+ /**
29
+ * @deprecated Use {@link decode} from `@atproto/lex-cbor`, and {@link isTypedLexMap} from `@atproto/lex-data` instead.
30
+ */
31
+ export declare function cborBytesToRecord(bytes: Uint8Array): Record<string, unknown>;
32
+ /**
33
+ * @deprecated Use {@link verifyCidForBytes} from `@atproto/lex-cbor` instead.
34
+ */
35
+ declare const verifyCidForBytesLegacy: typeof verifyCidForBytes;
36
+ export { verifyCidForBytesLegacy as verifyCidForBytes };
37
+ /**
38
+ * @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.
39
+ */
40
+ export declare const sha256RawToCid: typeof cidForRawHash;
41
+ /**
42
+ * @deprecated Use {@link parseCidFromBytes} from `@atproto/lex-cbor` instead.
43
+ */
44
+ declare const parseCidFromBytesLegacy: typeof parseCidFromBytes;
45
+ export { parseCidFromBytesLegacy as parseCidFromBytes };
15
46
  export declare class VerifyCidTransform extends Transform {
16
47
  cid: CID;
17
48
  constructor(cid: CID);
@@ -1 +1 @@
1
- {"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AA;AAE3C;;GAEG;AACH,QAAA,MAAM,uBAAuB,0BAAoB,CAAA;AACjD,OAAO,EAAE,uBAAuB,IAAI,iBAAiB,EAAE,CAAA;AAEvD,qBAAa,kBAAmB,SAAQ,SAAS;IAC5B,GAAG,EAAE,GAAG;gBAAR,GAAG,EAAE,GAAG;CAqB5B;AAKD,qBAAa,cAAe,SAAQ,KAAK;IAE9B,QAAQ,EAAE,GAAG;IACb,MAAM,EAAE,GAAG;gBADX,QAAQ,EAAE,GAAG,EACb,MAAM,EAAE,GAAG;CAIrB"}
package/dist/ipld.js CHANGED
@@ -1,121 +1,74 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.VerifyCidError = exports.VerifyCidTransform = exports.parseCidFromBytes = exports.sha256RawToCid = exports.sha256ToCid = exports.verifyCidForBytes = exports.cborBytesToRecord = exports.isValidCid = exports.cidForCbor = exports.dataToCborBlock = exports.cborDecode = exports.cborEncode = void 0;
37
- const node_crypto_1 = require("node:crypto");
38
- const node_stream_1 = require("node:stream");
39
- const cborCodec = __importStar(require("@ipld/dag-cbor"));
40
- const mf = __importStar(require("multiformats"));
41
- const Block = __importStar(require("multiformats/block"));
42
- const cid_1 = require("multiformats/cid");
43
- const rawCodec = __importStar(require("multiformats/codecs/raw"));
44
- const sha2_1 = require("multiformats/hashes/sha2");
45
- const common_web_1 = require("@atproto/common-web");
46
- exports.cborEncode = cborCodec.encode;
47
- exports.cborDecode = cborCodec.decode;
48
- const dataToCborBlock = async (data) => {
49
- return Block.encode({
50
- value: data,
51
- codec: cborCodec,
52
- hasher: sha2_1.sha256,
53
- });
54
- };
3
+ exports.VerifyCidError = exports.VerifyCidTransform = exports.parseCidFromBytes = exports.sha256RawToCid = exports.verifyCidForBytes = exports.cidForCbor = exports.cidForCborLegacy = exports.cborDecode = exports.cborEncode = void 0;
55
4
  exports.dataToCborBlock = dataToCborBlock;
56
- const cidForCbor = async (data) => {
57
- const block = await (0, exports.dataToCborBlock)(data);
58
- return block.cid;
59
- };
60
- exports.cidForCbor = cidForCbor;
61
- const isValidCid = async (cidStr) => {
62
- try {
63
- const parsed = cid_1.CID.parse(cidStr);
64
- return parsed.toString() === cidStr;
65
- }
66
- catch (err) {
67
- return false;
68
- }
69
- };
70
5
  exports.isValidCid = isValidCid;
71
- const cborBytesToRecord = (bytes) => {
72
- const val = (0, exports.cborDecode)(bytes);
73
- if (!common_web_1.check.is(val, common_web_1.schema.map)) {
74
- throw new Error(`Expected object, got: ${val}`);
75
- }
76
- return val;
77
- };
78
6
  exports.cborBytesToRecord = cborBytesToRecord;
79
- const verifyCidForBytes = async (cid, bytes) => {
80
- const digest = await sha2_1.sha256.digest(bytes);
81
- const expected = cid_1.CID.createV1(cid.code, digest);
82
- if (!cid.equals(expected)) {
83
- throw new Error(`Not a valid CID for bytes. Expected: ${expected.toString()} Got: ${cid.toString()}`);
84
- }
85
- };
86
- exports.verifyCidForBytes = verifyCidForBytes;
87
- const sha256ToCid = (hash, codec) => {
88
- const digest = mf.digest.create(sha2_1.sha256.code, hash);
89
- return cid_1.CID.createV1(codec, digest);
90
- };
91
- exports.sha256ToCid = sha256ToCid;
92
- const sha256RawToCid = (hash) => {
93
- return (0, exports.sha256ToCid)(hash, rawCodec.code);
94
- };
95
- exports.sha256RawToCid = sha256RawToCid;
96
- // @NOTE: Only supports DASL CIDs
97
- // https://dasl.ing/cid.html
98
- const parseCidFromBytes = (cidBytes) => {
99
- const version = cidBytes[0];
100
- if (version !== 0x01) {
101
- throw new Error(`Unsupported CID version: ${version}`);
102
- }
103
- const codec = cidBytes[1];
104
- if (codec !== 0x55 && codec !== 0x71) {
105
- throw new Error(`Unsupported CID codec: ${codec}`);
106
- }
107
- const hashType = cidBytes[2];
108
- if (hashType !== 0x12) {
109
- throw new Error(`Unsupported CID hash function: ${hashType}`);
110
- }
111
- const hashLength = cidBytes[3];
112
- if (hashLength !== 32) {
113
- throw new Error(`Unexpected CID hash length: ${hashLength}`);
114
- }
115
- const rest = cidBytes.slice(4);
116
- return (0, exports.sha256ToCid)(rest, codec);
117
- };
118
- exports.parseCidFromBytes = parseCidFromBytes;
7
+ const node_crypto_1 = require("node:crypto");
8
+ const node_stream_1 = require("node:stream");
9
+ const block_1 = require("multiformats/block");
10
+ const lex_cbor_1 = require("@atproto/lex-cbor");
11
+ const lex_data_1 = require("@atproto/lex-data");
12
+ /**
13
+ * @deprecated Use {@link encode} from `@atproto/lex-cbor` instead.
14
+ */
15
+ const cborEncodeLegacy = lex_cbor_1.encode;
16
+ exports.cborEncode = cborEncodeLegacy;
17
+ /**
18
+ * @deprecated Use {@link decode} from `@atproto/lex-cbor` instead.
19
+ */
20
+ const cborDecodeLegacy = lex_cbor_1.decode;
21
+ exports.cborDecode = cborDecodeLegacy;
22
+ /**
23
+ * @deprecated Use {@link encode} and {@link cidForCbor} from `@atproto/lex-cbor` instead.
24
+ */
25
+ async function dataToCborBlock(value) {
26
+ return (0, block_1.encode)({
27
+ value,
28
+ codec: {
29
+ name: 'at-cbor', // Not actually used
30
+ code: lex_data_1.DAG_CBOR_MULTICODEC,
31
+ encode: lex_cbor_1.encode,
32
+ },
33
+ hasher: lex_cbor_1.hasher,
34
+ });
35
+ }
36
+ /**
37
+ * @deprecated Use {@link cidForLex} from `@atproto/lex-cbor` instead.
38
+ */
39
+ exports.cidForCborLegacy = lex_cbor_1.cidForLex;
40
+ exports.cidForCbor = exports.cidForCborLegacy;
41
+ /**
42
+ * @deprecated Use {@link validateCidString} from '@atproto/lex-data' instead.
43
+ */
44
+ async function isValidCid(cidStr) {
45
+ // @NOTE we keep the wrapper function to return a Promise (for backward
46
+ // compatibility).
47
+ return (0, lex_data_1.validateCidString)(cidStr);
48
+ }
49
+ /**
50
+ * @deprecated Use {@link decode} from `@atproto/lex-cbor`, and {@link isTypedLexMap} from `@atproto/lex-data` instead.
51
+ */
52
+ function cborBytesToRecord(bytes) {
53
+ const data = (0, lex_cbor_1.decode)(bytes);
54
+ if ((0, lex_data_1.isTypedLexMap)(data))
55
+ return data;
56
+ throw new Error(`Expected record with $type property`);
57
+ }
58
+ /**
59
+ * @deprecated Use {@link verifyCidForBytes} from `@atproto/lex-cbor` instead.
60
+ */
61
+ const verifyCidForBytesLegacy = lex_cbor_1.verifyCidForBytes;
62
+ exports.verifyCidForBytes = verifyCidForBytesLegacy;
63
+ /**
64
+ * @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.
65
+ */
66
+ exports.sha256RawToCid = lex_cbor_1.cidForRawHash;
67
+ /**
68
+ * @deprecated Use {@link parseCidFromBytes} from `@atproto/lex-cbor` instead.
69
+ */
70
+ const parseCidFromBytesLegacy = lex_cbor_1.parseCidFromBytes;
71
+ exports.parseCidFromBytes = parseCidFromBytesLegacy;
119
72
  class VerifyCidTransform extends node_stream_1.Transform {
120
73
  constructor(cid) {
121
74
  const hasher = (0, node_crypto_1.createHash)('sha256');
@@ -126,7 +79,7 @@ class VerifyCidTransform extends node_stream_1.Transform {
126
79
  },
127
80
  flush(callback) {
128
81
  try {
129
- const actual = (0, exports.sha256RawToCid)(hasher.digest());
82
+ const actual = (0, lex_cbor_1.cidForRawHash)(hasher.digest());
130
83
  if (actual.equals(cid)) {
131
84
  return callback();
132
85
  }
package/dist/ipld.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ipld.js","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAwC;AACxC,6CAAuC;AACvC,0DAA2C;AAC3C,iDAAkC;AAClC,0DAA2C;AAC3C,0CAAsC;AACtC,kEAAmD;AACnD,mDAAiD;AACjD,oDAAmD;AAEtC,QAAA,UAAU,GAAG,SAAS,CAAC,MAAM,CAAA;AAC7B,QAAA,UAAU,GAAG,SAAS,CAAC,MAAM,CAAA;AAEnC,MAAM,eAAe,GAAG,KAAK,EAAE,IAAa,EAAE,EAAE;IACrD,OAAO,KAAK,CAAC,MAAM,CAAC;QAClB,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,aAAM;KACf,CAAC,CAAA;AACJ,CAAC,CAAA;AANY,QAAA,eAAe,mBAM3B;AAEM,MAAM,UAAU,GAAG,KAAK,EAAE,IAAa,EAAgB,EAAE;IAC9D,MAAM,KAAK,GAAG,MAAM,IAAA,uBAAe,EAAC,IAAI,CAAC,CAAA;IACzC,OAAO,KAAK,CAAC,GAAG,CAAA;AAClB,CAAC,CAAA;AAHY,QAAA,UAAU,cAGtB;AAEM,MAAM,UAAU,GAAG,KAAK,EAAE,MAAc,EAAoB,EAAE;IACnE,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAG,CAAC,KAAK,CA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 'node:stream'\nimport { Block, ByteView, encode as encodeBlock } from 'multiformats/block'\nimport {\n // eslint-disable-next-line\n cidForCbor,\n cidForLex,\n cidForRawHash,\n decode,\n encode,\n hasher,\n parseCidFromBytes,\n verifyCidForBytes,\n} from '@atproto/lex-cbor'\nimport {\n CID,\n DAG_CBOR_MULTICODEC,\n LexValue,\n isTypedLexMap,\n validateCidString,\n} from '@atproto/lex-data'\n\n/**\n * @deprecated Use {@link encode} from `@atproto/lex-cbor` instead.\n */\nconst cborEncodeLegacy = encode as <T = unknown>(data: T) => ByteView<T>\nexport { cborEncodeLegacy as cborEncode }\n\n/**\n * @deprecated Use {@link decode} from `@atproto/lex-cbor` instead.\n */\nconst cborDecodeLegacy = decode as <T = unknown>(bytes: ByteView<T>) => T\nexport { cborDecodeLegacy as cborDecode }\n\n/**\n * @deprecated Use {@link encode} and {@link cidForCbor} from `@atproto/lex-cbor` instead.\n */\nexport async function dataToCborBlock<T>(value: T): Promise<Block<T>> {\n return encodeBlock<T, 0x71, 0x12>({\n value,\n codec: {\n name: 'at-cbor', // Not actually used\n code: DAG_CBOR_MULTICODEC,\n encode: encode as (data: T) => ByteView<T>,\n },\n hasher,\n })\n}\n\n/**\n * @deprecated Use {@link cidForLex} from `@atproto/lex-cbor` instead.\n */\nexport const cidForCborLegacy = cidForLex as (data: unknown) => Promise<CID>\nexport { cidForCborLegacy as cidForCbor }\n\n/**\n * @deprecated Use {@link validateCidString} from '@atproto/lex-data' instead.\n */\nexport async function isValidCid(cidStr: string): Promise<boolean> {\n // @NOTE we keep the wrapper function to return a Promise (for backward\n // compatibility).\n return validateCidString(cidStr)\n}\n\n/**\n * @deprecated Use {@link decode} from `@atproto/lex-cbor`, and {@link isTypedLexMap} from `@atproto/lex-data` instead.\n */\nexport function cborBytesToRecord(bytes: Uint8Array): Record<string, unknown> {\n const data = decode(bytes) as LexValue\n if (isTypedLexMap(data)) return data\n\n throw new Error(`Expected record with $type property`)\n}\n\n/**\n * @deprecated Use {@link verifyCidForBytes} from `@atproto/lex-cbor` instead.\n */\nconst verifyCidForBytesLegacy = verifyCidForBytes\nexport { verifyCidForBytesLegacy as verifyCidForBytes }\n\n/**\n * @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.\n */\nexport const sha256RawToCid = cidForRawHash\n\n/**\n * @deprecated Use {@link parseCidFromBytes} from `@atproto/lex-cbor` instead.\n */\nconst parseCidFromBytesLegacy = parseCidFromBytes\nexport { parseCidFromBytesLegacy as parseCidFromBytes }\n\nexport class VerifyCidTransform extends Transform {\n constructor(public cid: CID) {\n const hasher = createHash('sha256')\n super({\n transform(chunk, encoding, callback) {\n hasher.update(chunk)\n callback(null, chunk)\n },\n flush(callback) {\n try {\n const actual = cidForRawHash(hasher.digest())\n if (actual.equals(cid)) {\n return callback()\n } else {\n return callback(new VerifyCidError(cid, actual))\n }\n } catch (err) {\n return callback(asError(err))\n }\n },\n })\n }\n}\n\nconst asError = (err: unknown): Error =>\n err instanceof Error ? err : new Error('Unexpected error', { cause: err })\n\nexport class VerifyCidError extends Error {\n constructor(\n public expected: CID,\n public actual: CID,\n ) {\n super('Bad cid check')\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,+BAAwC;AAExC,MAAM,iBAAiB,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;AAClD,MAAM,cAAc,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;KACnD,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;KACjB,KAAK,CAAC,GAAG,CAAC,CAAA;AAEb,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;AAC1C,MAAM,OAAO,GACX,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,CAAA;AAEnE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG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C,WAAW,CAAA;AAC1C,MAAM,OAAO,GACX,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,CAAA;AAEnE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM,CAAA;AAE7C,MAAM,MAAM,GAAG;IACb,OAAO;IACP,KAAK;CACN,CAAA;AAED,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe;IAC5C,CAAC,CAAC,IAAA,WAAI,EAAC,MAAM,EAAE,IAAA,kBAAW,EAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACxD,CAAC,CAAC,IAAA,WAAI,EAAC,MAAM,CAAC,CAAA;AAEhB,MAAM,UAAU,GAAgC,EAAE,CAAA;AAE3C,MAAM,eAAe,GAAG,CAAC,IAAY,EAAe,EAAE;IAC3D,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,gBAAgB,GACpB,OAAO,IAAI,CAAC,iBAAiB,IAAI,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAErE,gGAAgG;IAChG,UAAU,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CACjC,EAAE,IAAI,EAAE,EACR,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,CAC/C,CAAA;IACD,OAAO,UAAU,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC,CAAA;AAXY,QAAA,eAAe,mBAW3B","sourcesContent":["import { destination, pino } from 'pino'\n\nconst allSystemsEnabled = !process.env.LOG_SYSTEMS\nconst enabledSystems = (process.env.LOG_SYSTEMS || '')\n .replace(',', ' ')\n .split(' ')\n\nconst enabledEnv = process.env.LOG_ENABLED\nconst enabled =\n enabledEnv === 'true' || enabledEnv === 't' || enabledEnv === '1'\n\nconst level = process.env.LOG_LEVEL || 'info'\n\nconst config = {\n enabled,\n level,\n}\n\nconst rootLogger = process.env.LOG_DESTINATION\n ? pino(config, destination(process.env.LOG_DESTINATION))\n : pino(config)\n\nconst subsystems: Record<string, pino.Logger> = {}\n\nexport const subsystemLogger = (name: string): pino.Logger => {\n if (subsystems[name]) return subsystems[name]\n const subsystemEnabled =\n enabled && (allSystemsEnabled || enabledSystems.indexOf(name) > -1)\n\n // can't disable child loggers, so we just set their level to fatal to effectively turn them off\n subsystems[name] = rootLogger.child(\n { name },\n { level: subsystemEnabled ? level : 'silent' },\n )\n return subsystems[name]\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"obfuscate.js","sourceRoot":"","sources":["../src/obfuscate.ts"],"names":[],"mappings":";;AAAA,wCAGC;AAED,sCAEC;AAED,4CAYC;AAED,kDAgBC;AAED,wCASC;AAED,0CAEC;AAED,wCAGC;AAED,oCAuBC;AApFD,SAAgB,cAAc,CAAC,KAAa;IAC1C,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACxC,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAA;AAC3D,CAAC;AAED,SAAgB,aAAa,CAAC,IAAY;IACxC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAA;AAC9D,CAAC;AAED,SAAgB,gBAAgB,CAAC,OAA+B;IAC9D,MAAM,iBAAiB,GAA2B,EAAE,CAAA;IACpD,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,eAAe,EAAE,CAAC;YAC1C,iBAAiB,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC,OAAO,CAA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AAG,CAAC,EAAE,SAAS,CAAC,CAAA;QACvD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QACtE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QACvC,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ;YAAE,OAAO,OAAO,CAAC,GAAG,CAAA;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,cAAc;QACd,OAAO,IAAI,CAAA;IACb,CAAC;IAED,sBAAsB;IACtB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,aAAa,CAAA;AAClD,CAAC","sourcesContent":["export function obfuscateEmail(email: string) {\n const [local, domain] = email.split('@')\n return `${obfuscateWord(local)}@${obfuscateWord(domain)}`\n}\n\nexport function obfuscateWord(word: string) {\n return `${word.charAt(0)}***${word.charAt(word.length - 1)}`\n}\n\nexport function obfuscateHeaders(headers: Record<string, string>) {\n const obfuscatedHeaders: Record<string, string> = {}\n for (const key in headers) {\n if (key.toLowerCase() === 'authorization') {\n obfuscatedHeaders[key] = obfuscateAuthHeader(headers[key])\n } else if (key.toLowerCase() === 'dpop') {\n obfuscatedHeaders[key] = obfuscateJwt(headers[key]) || 'Invalid'\n } else {\n obfuscatedHeaders[key] = headers[key]\n }\n }\n return obfuscatedHeaders\n}\n\nexport function obfuscateAuthHeader(authHeader: string): string {\n // This is a hot path (runs on every request). Avoid using split() or regex.\n\n const spaceIdx = authHeader.indexOf(' ')\n if (spaceIdx === -1) return 'Invalid'\n\n const type = authHeader.slice(0, spaceIdx)\n switch (type.toLowerCase()) {\n case 'bearer':\n case 'dpop':\n return `${type} ${obfuscateBearer(authHeader.slice(spaceIdx + 1))}`\n case 'basic':\n return `${type} ${obfuscateBasic(authHeader.slice(spaceIdx + 1)) || 'Invalid'}`\n default:\n return `Invalid`\n }\n}\n\nexport function obfuscateBasic(token: string): null | string {\n if (!token) return null\n const buffer = Buffer.from(token, 'base64')\n if (!buffer.length) return null // Buffer.from will silently ignore invalid base64 chars\n const authHeader = buffer.toString('utf8')\n const colIdx = authHeader.indexOf(':')\n if (colIdx === -1) return null\n const username = authHeader.slice(0, colIdx)\n return `${username}:***`\n}\n\nexport function obfuscateBearer(token: string): string {\n return obfuscateJwt(token) || obfuscateToken(token)\n}\n\nexport function obfuscateToken(token: string): string {\n if (token.length >= 12) return obfuscateWord(token)\n return token ? '***' : ''\n}\n\nexport function obfuscateJwt(token: string): null | string {\n const firstDot = token.indexOf('.')\n if (firstDot === -1) return null\n\n const secondDot = token.indexOf('.', firstDot + 1)\n if (secondDot === -1) return null\n\n // Expected to be missing\n const thirdDot = token.indexOf('.', secondDot + 1)\n if (thirdDot !== -1) return null\n\n try {\n const payloadEnc = token.slice(firstDot + 1, secondDot)\n const payloadJson = Buffer.from(payloadEnc, 'base64').toString('utf8')\n const payload = JSON.parse(payloadJson)\n if (typeof payload.sub === 'string') return payload.sub\n } catch {\n // Invalid JWT\n return null\n }\n\n // Strip the signature\n return token.slice(0, secondDot) + '.obfuscated'\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"streams.js","sourceRoot":"","sources":["../src/streams.ts"],"names":[],"mappings":";;;AAgGA,oCAOC;AAQD,wCAqBC;AApID,6CAQoB;AACpB,yCAA+E;AAExE,MAAM,mBAAmB,GAAG,CAAC,GAAG,OAAiB,EAAE,EAAE;IAC1D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;QAEvB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,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formCallback,\n pipeline,\n} from 'node:stream'\nimport { createBrotliDecompress, createGunzip, createInflate } from 'node:zlib'\n\nexport const forwardStreamErrors = (...streams: Stream[]) => {\n for (let i = 1; i < streams.length; ++i) {\n const prev = streams[i - 1]\n const next = streams[i]\n\n prev.once('error', (err) => next.emit('error', err))\n }\n}\n\nexport const cloneStream = (stream: Readable): Readable => {\n const passthrough = new PassThrough()\n forwardStreamErrors(stream, passthrough)\n return stream.pipe(passthrough)\n}\n\nexport const streamSize = async (stream: Readable): Promise<number> => {\n let size = 0\n for await (const chunk of stream) {\n size += Buffer.byteLength(chunk)\n }\n return size\n}\n\nexport const streamToBytes = async (stream: AsyncIterable<Uint8Array>) =>\n // @NOTE Though Buffer is a sub-class of Uint8Array, we have observed\n // inconsistencies when using a Buffer in place of Uint8Array. For this\n // reason, we convert the Buffer to a Uint8Array.\n new Uint8Array(await streamToNodeBuffer(stream))\n\n// streamToBuffer identifier name already taken by @atproto/common-web\nexport const streamToNodeBuffer = async (\n stream: Iterable<Uint8Array> | AsyncIterable<Uint8Array>,\n): Promise<Buffer> => {\n const chunks: Uint8Array[] = []\n let totalLength = 0 // keep track of total length for Buffer.concat\n for await (const chunk of stream) {\n if (chunk instanceof Uint8Array) {\n chunks.push(chunk)\n totalLength += Buffer.byteLength(chunk)\n } else {\n throw new TypeError('expected Uint8Array')\n }\n }\n return Buffer.concat(chunks, totalLength)\n}\n\nexport const byteIterableToStream = (\n iter: AsyncIterable<Uint8Array>,\n): Readable => {\n return Readable.from(iter, { objectMode: false })\n}\n\nexport const bytesToStream = (bytes: Uint8Array): Readable => {\n const stream = new Readable()\n stream.push(bytes)\n stream.push(null)\n return stream\n}\n\nexport class MaxSizeChecker extends Transform {\n totalSize = 0\n constructor(\n public maxSize: number,\n public createError: () => Error,\n ) {\n super()\n }\n _transform(chunk: Uint8Array, _enc: BufferEncoding, cb: TransformCallback) {\n this.totalSize += chunk.length\n if (this.totalSize > this.maxSize) {\n cb(this.createError())\n } else {\n cb(null, chunk)\n }\n }\n}\n\nexport function decodeStream(\n stream: Readable,\n contentEncoding?: string | string[],\n): Readable\nexport function decodeStream(\n stream: AsyncIterable<Uint8Array>,\n contentEncoding?: string | string[],\n): AsyncIterable<Uint8Array> | Readable\nexport function decodeStream(\n stream: Readable | AsyncIterable<Uint8Array>,\n contentEncoding?: string | string[],\n): Readable | AsyncIterable<Uint8Array> {\n const decoders = createDecoders(contentEncoding)\n if (decoders.length === 0) return stream\n return pipeline([stream as Readable, ...decoders], () => {}) as Duplex\n}\n\n/**\n * Create a series of decoding streams based on the content-encoding header. The\n * resulting streams should be piped together to decode the content.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1}\n */\nexport function createDecoders(contentEncoding?: string | string[]): Duplex[] {\n const decoders: Duplex[] = []\n\n if (contentEncoding?.length) {\n const encodings: string[] = Array.isArray(contentEncoding)\n ? contentEncoding.flatMap(commaSplit)\n : contentEncoding.split(',')\n for (const encoding of encodings) {\n const normalizedEncoding = normalizeEncoding(encoding)\n\n // @NOTE\n // > The default (identity) encoding [...] is used only in the\n // > Accept-Encoding header, and SHOULD NOT be used in the\n // > Content-Encoding header.\n if (normalizedEncoding === 'identity') continue\n\n decoders.push(createDecoder(normalizedEncoding))\n }\n }\n\n return decoders.reverse()\n}\n\nfunction commaSplit(header: string): string[] {\n return header.split(',')\n}\n\nfunction normalizeEncoding(encoding: string) {\n // https://www.rfc-editor.org/rfc/rfc7231#section-3.1.2.1\n // > All content-coding values are case-insensitive...\n return encoding.trim().toLowerCase()\n}\n\nfunction createDecoder(normalizedEncoding: string): Duplex {\n switch (normalizedEncoding) {\n // https://www.rfc-editor.org/rfc/rfc9112.html#section-7.2\n case 'gzip':\n case 'x-gzip':\n return createGunzip()\n case 'deflate':\n return createInflate()\n case 'br':\n return createBrotliDecompress()\n case 'identity':\n return new PassThrough()\n default:\n throw new TypeError(\n `Unsupported content-encoding: \"${normalizedEncoding}\"`,\n )\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/common",
3
- "version": "0.4.12",
3
+ "version": "0.5.1",
4
4
  "license": "MIT",
5
5
  "description": "Shared web-platform-friendly code for atproto libraries",
6
6
  "keywords": [
@@ -18,12 +18,12 @@
18
18
  "node": ">=18.7.0"
19
19
  },
20
20
  "dependencies": {
21
- "@ipld/dag-cbor": "^7.0.3",
22
- "cbor-x": "^1.5.1",
23
21
  "iso-datestring-validator": "^2.2.2",
24
22
  "multiformats": "^9.9.0",
25
23
  "pino": "^8.21.0",
26
- "@atproto/common-web": "^0.4.3"
24
+ "@atproto/common-web": "^0.4.5",
25
+ "@atproto/lex-cbor": "0.0.1",
26
+ "@atproto/lex-data": "0.0.1"
27
27
  },
28
28
  "devDependencies": {
29
29
  "jest": "^28.1.2",
package/src/ipld-multi.ts CHANGED
@@ -1,33 +1,9 @@
1
- import * as cborx from 'cbor-x'
2
- import { CID } from 'multiformats/cid'
1
+ import { decodeAll } from '@atproto/lex-cbor'
2
+ import { LexValue } from '@atproto/lex-data'
3
3
 
4
- // add extension for decoding CIDs
5
- // decoding code taken from @ipld/dag-cbor
6
- // does not support encoding cids
7
- cborx.addExtension({
8
- Class: CID,
9
- tag: 42,
10
- encode: () => {
11
- throw new Error('cannot encode cids')
12
- },
13
- decode: (bytes: Uint8Array): CID => {
14
- if (bytes[0] !== 0) {
15
- throw new Error('Invalid CID for CBOR tag 42; expected leading 0x00')
16
- }
17
- return CID.decode(bytes.subarray(1)) // ignore leading 0x00
18
- },
19
- })
20
-
21
- const decoder = new cborx.Decoder({
22
- // @ts-ignore
23
- int64AsNumber: true, // not in types for some reason
24
- useRecords: false,
25
- })
26
-
27
- export const cborDecodeMulti = (encoded: Uint8Array): unknown[] => {
28
- const decoded: unknown[] = []
29
- decoder.decodeMultiple(encoded, (value) => {
30
- decoded.push(value)
31
- })
32
- return decoded
4
+ /**
5
+ * @deprecated Use {@link decodeAll} from `@atproto/lex-cbor` instead.
6
+ */
7
+ export function cborDecodeMulti(encoded: Uint8Array): LexValue[] {
8
+ return Array.from(decodeAll(encoded))
33
9
  }
package/src/ipld.ts CHANGED
@@ -1,89 +1,93 @@
1
1
  import { createHash } from 'node:crypto'
2
2
  import { Transform } from 'node:stream'
3
- import * as cborCodec from '@ipld/dag-cbor'
4
- import * as mf from 'multiformats'
5
- import * as Block from 'multiformats/block'
6
- import { CID } from 'multiformats/cid'
7
- import * as rawCodec from 'multiformats/codecs/raw'
8
- import { sha256 } from 'multiformats/hashes/sha2'
9
- import { check, schema } from '@atproto/common-web'
3
+ import { Block, ByteView, encode as encodeBlock } from 'multiformats/block'
4
+ import {
5
+ // eslint-disable-next-line
6
+ cidForCbor,
7
+ cidForLex,
8
+ cidForRawHash,
9
+ decode,
10
+ encode,
11
+ hasher,
12
+ parseCidFromBytes,
13
+ verifyCidForBytes,
14
+ } from '@atproto/lex-cbor'
15
+ import {
16
+ CID,
17
+ DAG_CBOR_MULTICODEC,
18
+ LexValue,
19
+ isTypedLexMap,
20
+ validateCidString,
21
+ } from '@atproto/lex-data'
10
22
 
11
- export const cborEncode = cborCodec.encode
12
- export const cborDecode = cborCodec.decode
23
+ /**
24
+ * @deprecated Use {@link encode} from `@atproto/lex-cbor` instead.
25
+ */
26
+ const cborEncodeLegacy = encode as <T = unknown>(data: T) => ByteView<T>
27
+ export { cborEncodeLegacy as cborEncode }
13
28
 
14
- export const dataToCborBlock = async (data: unknown) => {
15
- return Block.encode({
16
- value: data,
17
- codec: cborCodec,
18
- hasher: sha256,
29
+ /**
30
+ * @deprecated Use {@link decode} from `@atproto/lex-cbor` instead.
31
+ */
32
+ const cborDecodeLegacy = decode as <T = unknown>(bytes: ByteView<T>) => T
33
+ export { cborDecodeLegacy as cborDecode }
34
+
35
+ /**
36
+ * @deprecated Use {@link encode} and {@link cidForCbor} from `@atproto/lex-cbor` instead.
37
+ */
38
+ export async function dataToCborBlock<T>(value: T): Promise<Block<T>> {
39
+ return encodeBlock<T, 0x71, 0x12>({
40
+ value,
41
+ codec: {
42
+ name: 'at-cbor', // Not actually used
43
+ code: DAG_CBOR_MULTICODEC,
44
+ encode: encode as (data: T) => ByteView<T>,
45
+ },
46
+ hasher,
19
47
  })
20
48
  }
21
49
 
22
- export const cidForCbor = async (data: unknown): Promise<CID> => {
23
- const block = await dataToCborBlock(data)
24
- return block.cid
25
- }
50
+ /**
51
+ * @deprecated Use {@link cidForLex} from `@atproto/lex-cbor` instead.
52
+ */
53
+ export const cidForCborLegacy = cidForLex as (data: unknown) => Promise<CID>
54
+ export { cidForCborLegacy as cidForCbor }
26
55
 
27
- export const isValidCid = async (cidStr: string): Promise<boolean> => {
28
- try {
29
- const parsed = CID.parse(cidStr)
30
- return parsed.toString() === cidStr
31
- } catch (err) {
32
- return false
33
- }
56
+ /**
57
+ * @deprecated Use {@link validateCidString} from '@atproto/lex-data' instead.
58
+ */
59
+ export async function isValidCid(cidStr: string): Promise<boolean> {
60
+ // @NOTE we keep the wrapper function to return a Promise (for backward
61
+ // compatibility).
62
+ return validateCidString(cidStr)
34
63
  }
35
64
 
36
- export const cborBytesToRecord = (
37
- bytes: Uint8Array,
38
- ): Record<string, unknown> => {
39
- const val = cborDecode(bytes)
40
- if (!check.is(val, schema.map)) {
41
- throw new Error(`Expected object, got: ${val}`)
42
- }
43
- return val
44
- }
65
+ /**
66
+ * @deprecated Use {@link decode} from `@atproto/lex-cbor`, and {@link isTypedLexMap} from `@atproto/lex-data` instead.
67
+ */
68
+ export function cborBytesToRecord(bytes: Uint8Array): Record<string, unknown> {
69
+ const data = decode(bytes) as LexValue
70
+ if (isTypedLexMap(data)) return data
45
71
 
46
- export const verifyCidForBytes = async (cid: CID, bytes: Uint8Array) => {
47
- const digest = await sha256.digest(bytes)
48
- const expected = CID.createV1(cid.code, digest)
49
- if (!cid.equals(expected)) {
50
- throw new Error(
51
- `Not a valid CID for bytes. Expected: ${expected.toString()} Got: ${cid.toString()}`,
52
- )
53
- }
72
+ throw new Error(`Expected record with $type property`)
54
73
  }
55
74
 
56
- export const sha256ToCid = (hash: Uint8Array, codec: number): CID => {
57
- const digest = mf.digest.create(sha256.code, hash)
58
- return CID.createV1(codec, digest)
59
- }
75
+ /**
76
+ * @deprecated Use {@link verifyCidForBytes} from `@atproto/lex-cbor` instead.
77
+ */
78
+ const verifyCidForBytesLegacy = verifyCidForBytes
79
+ export { verifyCidForBytesLegacy as verifyCidForBytes }
60
80
 
61
- export const sha256RawToCid = (hash: Uint8Array): CID => {
62
- return sha256ToCid(hash, rawCodec.code)
63
- }
81
+ /**
82
+ * @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.
83
+ */
84
+ export const sha256RawToCid = cidForRawHash
64
85
 
65
- // @NOTE: Only supports DASL CIDs
66
- // https://dasl.ing/cid.html
67
- export const parseCidFromBytes = (cidBytes: Uint8Array): CID => {
68
- const version = cidBytes[0]
69
- if (version !== 0x01) {
70
- throw new Error(`Unsupported CID version: ${version}`)
71
- }
72
- const codec = cidBytes[1]
73
- if (codec !== 0x55 && codec !== 0x71) {
74
- throw new Error(`Unsupported CID codec: ${codec}`)
75
- }
76
- const hashType = cidBytes[2]
77
- if (hashType !== 0x12) {
78
- throw new Error(`Unsupported CID hash function: ${hashType}`)
79
- }
80
- const hashLength = cidBytes[3]
81
- if (hashLength !== 32) {
82
- throw new Error(`Unexpected CID hash length: ${hashLength}`)
83
- }
84
- const rest = cidBytes.slice(4)
85
- return sha256ToCid(rest, codec)
86
- }
86
+ /**
87
+ * @deprecated Use {@link parseCidFromBytes} from `@atproto/lex-cbor` instead.
88
+ */
89
+ const parseCidFromBytesLegacy = parseCidFromBytes
90
+ export { parseCidFromBytesLegacy as parseCidFromBytes }
87
91
 
88
92
  export class VerifyCidTransform extends Transform {
89
93
  constructor(public cid: CID) {
@@ -95,7 +99,7 @@ export class VerifyCidTransform extends Transform {
95
99
  },
96
100
  flush(callback) {
97
101
  try {
98
- const actual = sha256RawToCid(hasher.digest())
102
+ const actual = cidForRawHash(hasher.digest())
99
103
  if (actual.equals(cid)) {
100
104
  return callback()
101
105
  } else {
@@ -1,5 +1,7 @@
1
- import { CID } from 'multiformats/cid'
1
+ /* eslint-disable import/no-deprecated */
2
+
2
3
  import * as ui8 from 'uint8arrays'
4
+ import { CID } from '@atproto/lex-data'
3
5
  import { cborDecodeMulti, cborEncode } from '../src'
4
6
 
5
7
  describe('ipld decode multi', () => {
@@ -1,4 +1,4 @@
1
- import { CID } from 'multiformats/cid'
1
+ import { CID } from '@atproto/lex-data'
2
2
 
3
3
  export const vectors = [
4
4
  {
@@ -1,3 +1,5 @@
1
+ /* eslint-disable import/no-deprecated */
2
+
1
3
  import * as ui8 from 'uint8arrays'
2
4
  import {
3
5
  cborDecode,