@atproto/common 0.5.1 → 0.5.3

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,23 @@
1
1
  # @atproto/common
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`693784c`](https://github.com/bluesky-social/atproto/commit/693784c3a0dee4b6a29aa1e018fce682dcae148f), [`693784c`](https://github.com/bluesky-social/atproto/commit/693784c3a0dee4b6a29aa1e018fce682dcae148f), [`7e1d458`](https://github.com/bluesky-social/atproto/commit/7e1d45877bca0f615e7b1313cfcc66823b3de758)]:
8
+ - @atproto/lex-data@0.0.3
9
+ - @atproto/common-web@0.4.7
10
+ - @atproto/lex-cbor@0.0.3
11
+
12
+ ## 0.5.2
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [[`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`688f9d6`](https://github.com/bluesky-social/atproto/commit/688f9d67597ba96d6e9c4a4aec4d394d42f4cbf4)]:
17
+ - @atproto/lex-data@0.0.2
18
+ - @atproto/lex-cbor@0.0.2
19
+ - @atproto/common-web@0.4.6
20
+
3
21
  ## 0.5.1
4
22
 
5
23
  ### Patch Changes
package/dist/ipld.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Transform } from 'node:stream';
2
2
  import { Block, ByteView } from 'multiformats/block';
3
- import { cidForRawHash, parseCidFromBytes, verifyCidForBytes } from '@atproto/lex-cbor';
3
+ import { verifyCidForBytes } from '@atproto/lex-cbor';
4
4
  import { CID } from '@atproto/lex-data';
5
5
  /**
6
6
  * @deprecated Use {@link encode} from `@atproto/lex-cbor` instead.
@@ -37,11 +37,11 @@ export { verifyCidForBytesLegacy as verifyCidForBytes };
37
37
  /**
38
38
  * @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.
39
39
  */
40
- export declare const sha256RawToCid: typeof cidForRawHash;
40
+ export declare const sha256RawToCid: (hash: Uint8Array) => CID;
41
41
  /**
42
42
  * @deprecated Use {@link parseCidFromBytes} from `@atproto/lex-cbor` instead.
43
43
  */
44
- declare const parseCidFromBytesLegacy: typeof parseCidFromBytes;
44
+ declare const parseCidFromBytesLegacy: (bytes: Uint8Array) => CID;
45
45
  export { parseCidFromBytesLegacy as parseCidFromBytes };
46
46
  export declare class VerifyCidTransform extends Transform {
47
47
  cid: CID;
@@ -1 +1 @@
1
- {"version":3,"file":"ipld.d.ts","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAyB,MAAM,oBAAoB,CAAA;AAC3E,OAAO,EAIL,aAAa,EAIb,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,GAAG,EAKJ,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,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAUpE;AAED;;GAEG;AACH,eAAO,MAAM,gBAAg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;gBADX,QAAQ,EAAE,GAAG,EACb,MAAM,EAAE,GAAG;CAIrB"}
package/dist/ipld.js CHANGED
@@ -79,7 +79,7 @@ class VerifyCidTransform extends node_stream_1.Transform {
79
79
  },
80
80
  flush(callback) {
81
81
  try {
82
- const actual = (0, lex_cbor_1.cidForRawHash)(hasher.digest());
82
+ const actual = (0, exports.sha256RawToCid)(hasher.digest());
83
83
  if (actual.equals(cid)) {
84
84
  return callback();
85
85
  }
package/dist/ipld.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ipld.js","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":";;;AAqCA,0CAUC;AAWD,gCAIC;AAKD,8CAKC;AAxED,6CAAwC;AACxC,6CAAuC;AACvC,8CAA2E;AAC3E,gDAU0B;AAC1B,gDAM0B;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,iBAAM;KACP,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACU,QAAA,gBAAgB,GAAG,oBAA4C,CAAA;AAC/C,qBADhB,wBAAgB,CACU;AAEvC;;GAEG;AACI,KAAK,UAAU,UAAU,CAAC,MAAc;IAC7C,uEAAuE;IACvE,kBAAkB;IAClB,OAAO,IAAA,4BAAiB,EAAC,MAAM,CAAC,CAAA;AAClC,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAAiB;IACjD,MAAM,IAAI,GAAG,IAAA,iBAAM,EAAC,KAAK,CAAa,CAAA;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,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 {\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
+ {"version":3,"file":"ipld.js","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":";;;AAqCA,0CAUC;AAWD,gCAIC;AAKD,8CAKC;AAxED,6CAAwC;AACxC,6CAAuC;AACvC,8CAA2E;AAC3E,gDAU0B;AAC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AE,QAAQ;gBACjC,MAAM,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,IAAA,sBAAc,EAAC,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 {\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 as (hash: Uint8Array) => CID\n\n/**\n * @deprecated Use {@link parseCidFromBytes} from `@atproto/lex-cbor` instead.\n */\nconst parseCidFromBytesLegacy = parseCidFromBytes as (bytes: Uint8Array) => CID\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 = 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.1",
3
+ "version": "0.5.3",
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.5",
25
- "@atproto/lex-cbor": "0.0.1",
26
- "@atproto/lex-data": "0.0.1"
24
+ "@atproto/common-web": "^0.4.7",
25
+ "@atproto/lex-cbor": "0.0.3",
26
+ "@atproto/lex-data": "0.0.3"
27
27
  },
28
28
  "devDependencies": {
29
29
  "jest": "^28.1.2",
package/src/ipld.ts CHANGED
@@ -81,12 +81,12 @@ export { verifyCidForBytesLegacy as verifyCidForBytes }
81
81
  /**
82
82
  * @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.
83
83
  */
84
- export const sha256RawToCid = cidForRawHash
84
+ export const sha256RawToCid = cidForRawHash as (hash: Uint8Array) => CID
85
85
 
86
86
  /**
87
87
  * @deprecated Use {@link parseCidFromBytes} from `@atproto/lex-cbor` instead.
88
88
  */
89
- const parseCidFromBytesLegacy = parseCidFromBytes
89
+ const parseCidFromBytesLegacy = parseCidFromBytes as (bytes: Uint8Array) => CID
90
90
  export { parseCidFromBytesLegacy as parseCidFromBytes }
91
91
 
92
92
  export class VerifyCidTransform extends Transform {
@@ -99,7 +99,7 @@ export class VerifyCidTransform extends Transform {
99
99
  },
100
100
  flush(callback) {
101
101
  try {
102
- const actual = cidForRawHash(hasher.digest())
102
+ const actual = sha256RawToCid(hasher.digest())
103
103
  if (actual.equals(cid)) {
104
104
  return callback()
105
105
  } else {
@@ -1,4 +1,4 @@
1
- import { CID } from '@atproto/lex-data'
1
+ import { parseCid } from '@atproto/lex-data'
2
2
 
3
3
  export const vectors = [
4
4
  {
@@ -65,7 +65,7 @@ export const vectors = [
65
65
  },
66
66
  },
67
67
  ipld: {
68
- a: CID.parse(
68
+ a: parseCid(
69
69
  'bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a',
70
70
  ),
71
71
  b: new Uint8Array([
@@ -75,7 +75,7 @@ export const vectors = [
75
75
  ]),
76
76
  c: {
77
77
  $type: 'blob',
78
- ref: CID.parse(
78
+ ref: parseCid(
79
79
  'bafkreiccldh766hwcnuxnf2wh6jgzepf2nlu2lvcllt63eww5p6chi4ity',
80
80
  ),
81
81
  mimeType: 'image/jpeg',
@@ -114,10 +114,10 @@ export const vectors = [
114
114
  },
115
115
  ],
116
116
  ipld: [
117
- CID.parse('bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a'),
118
- CID.parse('bafyreigoxt64qghytzkr6ik7qvtzc7lyytiq5xbbrokbxjows2wp7vmo6q'),
119
- CID.parse('bafyreiaizynclnqiolq7byfpjjtgqzn4sfrsgn7z2hhf6bo4utdwkin7ke'),
120
- CID.parse('bafyreifd4w4tcr5tluxz7osjtnofffvtsmgdqcfrfi6evjde4pl27lrjpy'),
117
+ parseCid('bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a'),
118
+ parseCid('bafyreigoxt64qghytzkr6ik7qvtzc7lyytiq5xbbrokbxjows2wp7vmo6q'),
119
+ parseCid('bafyreiaizynclnqiolq7byfpjjtgqzn4sfrsgn7z2hhf6bo4utdwkin7ke'),
120
+ parseCid('bafyreifd4w4tcr5tluxz7osjtnofffvtsmgdqcfrfi6evjde4pl27lrjpy'),
121
121
  ],
122
122
  cbor: new Uint8Array([
123
123
  132, 216, 42, 88, 37, 0, 1, 113, 18, 32, 101, 6, 42, 90, 90, 0, 252, 22,
@@ -166,10 +166,10 @@ export const vectors = [
166
166
  b: [
167
167
  {
168
168
  d: [
169
- CID.parse(
169
+ parseCid(
170
170
  'bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a',
171
171
  ),
172
- CID.parse(
172
+ parseCid(
173
173
  'bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a',
174
174
  ),
175
175
  ],