@atproto/common 0.5.9 → 0.5.10

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,16 @@
1
1
  # @atproto/common
2
2
 
3
+ ## 0.5.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [`49b3806`](https://github.com/bluesky-social/atproto/commit/49b38069ed4b5bd1ef71e967c78e5123b1c1f6f1) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update dependency on `@atproto/common-web`
8
+
9
+ - Updated dependencies [[`369bb02`](https://github.com/bluesky-social/atproto/commit/369bb02b9f80f0e15e5242e54f09bd4e01117f3a)]:
10
+ - @atproto/lex-data@0.0.10
11
+ - @atproto/common-web@0.4.15
12
+ - @atproto/lex-cbor@0.0.10
13
+
3
14
  ## 0.5.9
4
15
 
5
16
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"ipld.d.ts","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAyB,MAAM,oBAAoB,CAAA;AAG3E,OAAO,EACL,KAAK,GAAG,EACR,GAAG,EAWJ,MAAM,mBAAmB,CAAA;AAE1B;;GAEG;AACH,QAAA,MAAM,gBAAgB,EAAa,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAA;AACxE,OAAO,EAAE,gBAAgB,IAAI,UAAU,EAAE,CAAA;AAEzC;;GAEG;AACH,QAAA,MAAM,gBAAgB,EAAa,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AACzE,OAAO,EAAE,gBAAgB,IAAI,UAAU,EAAE,CAAA;AAEzC;;GAEG;AACH,wBAAsB,eAAe,CAAC,CAAC,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AAE,GAAG,EACb,MAAM,EAAE,GAAG;CAIrB"}
package/dist/ipld.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable import/no-deprecated */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.VerifyCidError = exports.VerifyCidTransform = exports.cborDecode = exports.cborEncode = void 0;
5
4
  exports.dataToCborBlock = dataToCborBlock;
package/dist/ipld.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ipld.js","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":";AAAA,yCAAyC;;;AAqCzC,0CAUC;AAQ4B,sCAAU;AAKvC,gCAIC;AAKD,8CAKC;AAKD,8CAOC;AAKD,wCAEC;AAKD,8CAEC;AAlGD,6CAAwC;AACxC,6CAAuC;AACvC,8CAA2E;AAC3E,mDAA2D;AAC3D,gDAA6D;AAC7D,gDAa0B;AAE1B;;GAEG;AACH,MAAM,gBAAgB,GAAG,iBAA+C,CAAA;AAC3C,sCAAU;AAEvC;;GAEG;AACH,MAAM,gBAAgB,GAAG,iBAAgD,CAAA;AAC5C,sCAAU;AAEvC;;GAEG;AACI,KAAK,UAAU,eAAe,CAAI,KAAQ;IAC/C,OAAO,IAAA,cAAW,EAAgB;QAChC,KAAK;QACL,KAAK,EAAE;YACL,IAAI,EAAE,SAAS,EAAE,oBAAoB;YACrC,IAAI,EAAE,8BAAmB;YACzB,MAAM,EAAE,iBAAkC;SAC3C;QACD,MAAM,EAAN,aAAM;KACP,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,gBAAgB,CAAC,IAAa;IAC3C,OAAO,IAAA,4BAAiB,EAAC,MAAM,IAAA,oBAAS,EAAC,IAAgB,CAAC,CAAC,CAAA;AAC7D,CAAC;AAGD;;GAEG;AACI,KAAK,UAAU,UAAU,CAAC,MAAc;IAC7C,uEAAuE;IACvE,kBAAkB;IAClB,OAAO,IAAA,4BAAiB,EAAC,MAAM,CAAC,CAAA;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9C,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;wBACvB,OAAO,QAAQ,EAAE,CAAA;oBACnB,CAAC;yBAAM,CAAC;wBACN,OAAO,QAAQ,CAAC,IAAI,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;oBAClD,CAAC;gBACH,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;gBAC/B,CAAC;YACH,CAAC;SACF,CAAC,CAAA;QAnBQ;;;;mBAAO,GAAG;WAAK;IAoB3B,CAAC;CACF;AAtBD,gDAsBC;AAED,MAAM,OAAO,GAAG,CAAC,GAAY,EAAS,EAAE,CACtC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;AAE5E,MAAa,cAAe,SAAQ,KAAK;IACvC,YACS,QAAa,EACb,MAAW;QAElB,KAAK,CAAC,eAAe,CAAC,CAAA;QAHtB;;;;mBAAO,QAAQ;WAAK;QACpB;;;;mBAAO,MAAM;WAAK;IAGpB,CAAC;CACF;AAPD,wCAOC","sourcesContent":["/* eslint-disable import/no-deprecated */\n\nimport { createHash } from 'node:crypto'\nimport { Transform } from 'node:stream'\nimport { Block, ByteView, encode as encodeBlock } from 'multiformats/block'\nimport { sha256 as hasher } from 'multiformats/hashes/sha2'\nimport { cidForLex, decode, encode } from '@atproto/lex-cbor'\nimport {\n type CID,\n Cid,\n DAG_CBOR_MULTICODEC,\n LexValue,\n asMultiformatsCID,\n // eslint-disable-next-line\n cidForCbor,\n cidForRawHash,\n decodeCid,\n isCidForBytes,\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 */\nasync function cidForCborLegacy(data: unknown): Promise<CID> {\n return asMultiformatsCID(await cidForLex(data as LexValue))\n}\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 isCidForBytes} from `@atproto/lex-cbor` instead.\n */\nexport async function verifyCidForBytes(\n cid: Cid,\n bytes: Uint8Array,\n): Promise<void> {\n if (!(await isCidForBytes(cid, bytes))) {\n throw new Error(`Not a valid CID for bytes (${cid.toString()})`)\n }\n}\n\n/**\n * @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.\n */\nexport function sha256RawToCid(hash: Uint8Array): CID {\n return asMultiformatsCID(cidForRawHash(hash))\n}\n\n/**\n * @deprecated Use {@link decodeCid} from `@atproto/lex-cbor` instead.\n */\nexport function parseCidFromBytes(bytes: Uint8Array): CID {\n return asMultiformatsCID(decodeCid(bytes, { flavor: 'dasl' }))\n}\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 = sha256RawToCid(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
+ {"version":3,"file":"ipld.js","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":";;;AAmCA,0CAUC;AAQ4B,sCAAU;AAKvC,gCAIC;AAKD,8CAKC;AAKD,8CAOC;AAKD,wCAEC;AAKD,8CAEC;AAlGD,6CAAwC;AACxC,6CAAuC;AACvC,8CAA2E;AAC3E,mDAA2D;AAC3D,gDAA6D;AAC7D,gDAa0B;AAE1B;;GAEG;AACH,MAAM,gBAAgB,GAAG,iBAA+C,CAAA;AAC3C,sCAAU;AAEvC;;GAEG;AACH,MAAM,gBAAgB,GAAG,iBAAgD,CAAA;AAC5C,sCAAU;AAEvC;;GAEG;AACI,KAAK,UAAU,eAAe,CAAI,KAAQ;IAC/C,OAAO,IAAA,cAAW,EAAgB;QAChC,KAAK;QACL,KAAK,EAAE;YACL,IAAI,EAAE,SAAS,EAAE,oBAAoB;YACrC,IAAI,EAAE,8BAAmB;YACzB,MAAM,EAAE,iBAAkC;SAC3C;QACD,MAAM,EAAN,aAAM;KACP,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,gBAAgB,CAAC,IAAa;IAC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AM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;gBACpB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YACvB,CAAC;YACD,KAAK,CAAC,QAAQ;gBACZ,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;oBAC9C,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;wBACvB,OAAO,QAAQ,EAAE,CAAA;oBACnB,CAAC;yBAAM,CAAC;wBACN,OAAO,QAAQ,CAAC,IAAI,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;oBAClD,CAAC;gBACH,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;gBAC/B,CAAC;YACH,CAAC;SACF,CAAC,CAAA;QAnBQ;;;;mBAAO,GAAG;WAAK;IAoB3B,CAAC;CACF;AAtBD,gDAsBC;AAED,MAAM,OAAO,GAAG,CAAC,GAAY,EAAS,EAAE,CACtC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;AAE5E,MAAa,cAAe,SAAQ,KAAK;IACvC,YACS,QAAa,EACb,MAAW;QAElB,KAAK,CAAC,eAAe,CAAC,CAAA;QAHtB;;;;mBAAO,QAAQ;WAAK;QACpB;;;;mBAAO,MAAM;WAAK;IAGpB,CAAC;CACF;AAPD,wCAOC","sourcesContent":["import { createHash } from 'node:crypto'\nimport { Transform } from 'node:stream'\nimport { Block, ByteView, encode as encodeBlock } from 'multiformats/block'\nimport { sha256 as hasher } from 'multiformats/hashes/sha2'\nimport { cidForLex, decode, encode } from '@atproto/lex-cbor'\nimport {\n type CID,\n Cid,\n DAG_CBOR_MULTICODEC,\n LexValue,\n asMultiformatsCID,\n // eslint-disable-next-line\n cidForCbor,\n cidForRawHash,\n decodeCid,\n isCidForBytes,\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 */\nasync function cidForCborLegacy(data: unknown): Promise<CID> {\n return asMultiformatsCID(await cidForLex(data as LexValue))\n}\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 isCidForBytes} from `@atproto/lex-cbor` instead.\n */\nexport async function verifyCidForBytes(\n cid: Cid,\n bytes: Uint8Array,\n): Promise<void> {\n if (!(await isCidForBytes(cid, bytes))) {\n throw new Error(`Not a valid CID for bytes (${cid.toString()})`)\n }\n}\n\n/**\n * @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.\n */\nexport function sha256RawToCid(hash: Uint8Array): CID {\n return asMultiformatsCID(cidForRawHash(hash))\n}\n\n/**\n * @deprecated Use {@link decodeCid} from `@atproto/lex-cbor` instead.\n */\nexport function parseCidFromBytes(bytes: Uint8Array): CID {\n return asMultiformatsCID(decodeCid(bytes, { flavor: 'dasl' }))\n}\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 = sha256RawToCid(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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/common",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "license": "MIT",
5
5
  "description": "Shared web-platform-friendly code for atproto libraries",
6
6
  "keywords": [
@@ -21,9 +21,9 @@
21
21
  "iso-datestring-validator": "^2.2.2",
22
22
  "multiformats": "^9.9.0",
23
23
  "pino": "^8.21.0",
24
- "@atproto/common-web": "^0.4.13",
25
- "@atproto/lex-cbor": "0.0.9",
26
- "@atproto/lex-data": "0.0.9"
24
+ "@atproto/common-web": "^0.4.15",
25
+ "@atproto/lex-cbor": "^0.0.10",
26
+ "@atproto/lex-data": "^0.0.10"
27
27
  },
28
28
  "devDependencies": {
29
29
  "jest": "^28.1.2",
package/src/ipld.ts CHANGED
@@ -1,5 +1,3 @@
1
- /* eslint-disable import/no-deprecated */
2
-
3
1
  import { createHash } from 'node:crypto'
4
2
  import { Transform } from 'node:stream'
5
3
  import { Block, ByteView, encode as encodeBlock } from 'multiformats/block'
@@ -1,5 +1,3 @@
1
- /* eslint-disable import/no-deprecated */
2
-
3
1
  import * as ui8 from 'uint8arrays'
4
2
  import { CID } from '@atproto/lex-data'
5
3
  import { cborDecodeMulti, cborEncode } from '../src'
@@ -1,5 +1,3 @@
1
- /* eslint-disable import/no-deprecated */
2
-
3
1
  import * as ui8 from 'uint8arrays'
4
2
  import {
5
3
  cborDecode,