@atproto/common 0.5.7 → 0.5.9
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 +18 -0
- package/LICENSE.txt +1 -1
- package/dist/dates.d.ts +1 -1
- package/dist/dates.d.ts.map +1 -1
- package/dist/ipld.d.ts +3 -3
- package/dist/ipld.d.ts.map +1 -1
- package/dist/ipld.js +12 -9
- package/dist/ipld.js.map +1 -1
- package/package.json +4 -4
- package/src/ipld.ts +11 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atproto/common
|
|
2
2
|
|
|
3
|
+
## 0.5.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`ecf5921`](https://github.com/bluesky-social/atproto/commit/ecf59214d59d9d2530c197c0679d26e76c6a60ef), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101)]:
|
|
8
|
+
- @atproto/common-web@0.4.13
|
|
9
|
+
- @atproto/lex-cbor@0.0.9
|
|
10
|
+
- @atproto/lex-data@0.0.9
|
|
11
|
+
|
|
12
|
+
## 0.5.8
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`dfd4bee`](https://github.com/bluesky-social/atproto/commit/dfd4bee4abbc1a3e53531bb499a6f3169c13ed9e), [`dfd4bee`](https://github.com/bluesky-social/atproto/commit/dfd4bee4abbc1a3e53531bb499a6f3169c13ed9e), [`dfd4bee`](https://github.com/bluesky-social/atproto/commit/dfd4bee4abbc1a3e53531bb499a6f3169c13ed9e), [`dfd4bee`](https://github.com/bluesky-social/atproto/commit/dfd4bee4abbc1a3e53531bb499a6f3169c13ed9e)]:
|
|
17
|
+
- @atproto/lex-data@0.0.8
|
|
18
|
+
- @atproto/common-web@0.4.12
|
|
19
|
+
- @atproto/lex-cbor@0.0.8
|
|
20
|
+
|
|
3
21
|
## 0.5.7
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Dual MIT/Apache-2.0 License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022-
|
|
3
|
+
Copyright (c) 2022-2026 Bluesky Social PBC, and Contributors
|
|
4
4
|
|
|
5
5
|
Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>).
|
|
6
6
|
|
package/dist/dates.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function toSimplifiedISOSafe(dateStr: string): string
|
|
1
|
+
export declare function toSimplifiedISOSafe(dateStr: string): `${string}-${string}-${string}T${string}:${string}:${string}Z`;
|
|
2
2
|
//# sourceMappingURL=dates.d.ts.map
|
package/dist/dates.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../src/dates.ts"],"names":[],"mappings":"AAIA,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../src/dates.ts"],"names":[],"mappings":"AAIA,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,kEAWlD"}
|
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 { CID, Cid } from '@atproto/lex-data';
|
|
3
|
+
import { type CID, Cid } from '@atproto/lex-data';
|
|
4
4
|
/**
|
|
5
5
|
* @deprecated Use {@link encode} from `@atproto/lex-cbor` instead.
|
|
6
6
|
*/
|
|
@@ -18,7 +18,7 @@ export declare function dataToCborBlock<T>(value: T): Promise<Block<T>>;
|
|
|
18
18
|
/**
|
|
19
19
|
* @deprecated Use {@link cidForLex} from `@atproto/lex-cbor` instead.
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
declare function cidForCborLegacy(data: unknown): Promise<CID>;
|
|
22
22
|
export { cidForCborLegacy as cidForCbor };
|
|
23
23
|
/**
|
|
24
24
|
* @deprecated Use {@link validateCidString} from '@atproto/lex-data' instead.
|
|
@@ -35,7 +35,7 @@ export declare function verifyCidForBytes(cid: Cid, bytes: Uint8Array): Promise<
|
|
|
35
35
|
/**
|
|
36
36
|
* @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.
|
|
37
37
|
*/
|
|
38
|
-
export declare
|
|
38
|
+
export declare function sha256RawToCid(hash: Uint8Array): CID;
|
|
39
39
|
/**
|
|
40
40
|
* @deprecated Use {@link decodeCid} from `@atproto/lex-cbor` instead.
|
|
41
41
|
*/
|
package/dist/ipld.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipld.d.ts","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":"
|
|
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,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,KAAK;IAE9B,QAAQ,EAAE,GAAG;IACb,MAAM,EAAE,GAAG;gBADX,QAAQ,EAAE,GAAG,EACb,MAAM,EAAE,GAAG;CAIrB"}
|
package/dist/ipld.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable import/no-deprecated */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VerifyCidError = exports.VerifyCidTransform = exports.
|
|
4
|
+
exports.VerifyCidError = exports.VerifyCidTransform = exports.cborDecode = exports.cborEncode = void 0;
|
|
4
5
|
exports.dataToCborBlock = dataToCborBlock;
|
|
6
|
+
exports.cidForCbor = cidForCborLegacy;
|
|
5
7
|
exports.isValidCid = isValidCid;
|
|
6
8
|
exports.cborBytesToRecord = cborBytesToRecord;
|
|
7
9
|
exports.verifyCidForBytes = verifyCidForBytes;
|
|
10
|
+
exports.sha256RawToCid = sha256RawToCid;
|
|
8
11
|
exports.parseCidFromBytes = parseCidFromBytes;
|
|
9
12
|
const node_crypto_1 = require("node:crypto");
|
|
10
13
|
const node_stream_1 = require("node:stream");
|
|
@@ -39,8 +42,9 @@ async function dataToCborBlock(value) {
|
|
|
39
42
|
/**
|
|
40
43
|
* @deprecated Use {@link cidForLex} from `@atproto/lex-cbor` instead.
|
|
41
44
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
async function cidForCborLegacy(data) {
|
|
46
|
+
return (0, lex_data_1.asMultiformatsCID)(await (0, lex_cbor_1.cidForLex)(data));
|
|
47
|
+
}
|
|
44
48
|
/**
|
|
45
49
|
* @deprecated Use {@link validateCidString} from '@atproto/lex-data' instead.
|
|
46
50
|
*/
|
|
@@ -69,15 +73,14 @@ async function verifyCidForBytes(cid, bytes) {
|
|
|
69
73
|
/**
|
|
70
74
|
* @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.
|
|
71
75
|
*/
|
|
72
|
-
|
|
76
|
+
function sha256RawToCid(hash) {
|
|
77
|
+
return (0, lex_data_1.asMultiformatsCID)((0, lex_data_1.cidForRawHash)(hash));
|
|
78
|
+
}
|
|
73
79
|
/**
|
|
74
80
|
* @deprecated Use {@link decodeCid} from `@atproto/lex-cbor` instead.
|
|
75
81
|
*/
|
|
76
82
|
function parseCidFromBytes(bytes) {
|
|
77
|
-
|
|
78
|
-
if (!cid)
|
|
79
|
-
throw new Error('Failed to parse CID from bytes');
|
|
80
|
-
return cid;
|
|
83
|
+
return (0, lex_data_1.asMultiformatsCID)((0, lex_data_1.decodeCid)(bytes, { flavor: 'dasl' }));
|
|
81
84
|
}
|
|
82
85
|
class VerifyCidTransform extends node_stream_1.Transform {
|
|
83
86
|
constructor(cid) {
|
|
@@ -89,7 +92,7 @@ class VerifyCidTransform extends node_stream_1.Transform {
|
|
|
89
92
|
},
|
|
90
93
|
flush(callback) {
|
|
91
94
|
try {
|
|
92
|
-
const actual =
|
|
95
|
+
const actual = sha256RawToCid(hasher.digest());
|
|
93
96
|
if (actual.equals(cid)) {
|
|
94
97
|
return callback();
|
|
95
98
|
}
|
package/dist/ipld.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipld.js","sourceRoot":"","sources":["../src/ipld.ts"],"names":[],"mappings":";;;
|
|
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,KAA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BAAO,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/common",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
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.
|
|
25
|
-
"@atproto/lex-cbor": "0.0.
|
|
26
|
-
"@atproto/lex-data": "0.0.
|
|
24
|
+
"@atproto/common-web": "^0.4.13",
|
|
25
|
+
"@atproto/lex-cbor": "0.0.9",
|
|
26
|
+
"@atproto/lex-data": "0.0.9"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"jest": "^28.1.2",
|
package/src/ipld.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
/* eslint-disable import/no-deprecated */
|
|
2
|
+
|
|
1
3
|
import { createHash } from 'node:crypto'
|
|
2
4
|
import { Transform } from 'node:stream'
|
|
3
5
|
import { Block, ByteView, encode as encodeBlock } from 'multiformats/block'
|
|
4
6
|
import { sha256 as hasher } from 'multiformats/hashes/sha2'
|
|
5
7
|
import { cidForLex, decode, encode } from '@atproto/lex-cbor'
|
|
6
8
|
import {
|
|
7
|
-
CID,
|
|
9
|
+
type CID,
|
|
8
10
|
Cid,
|
|
9
11
|
DAG_CBOR_MULTICODEC,
|
|
10
12
|
LexValue,
|
|
13
|
+
asMultiformatsCID,
|
|
11
14
|
// eslint-disable-next-line
|
|
12
15
|
cidForCbor,
|
|
13
16
|
cidForRawHash,
|
|
@@ -47,7 +50,9 @@ export async function dataToCborBlock<T>(value: T): Promise<Block<T>> {
|
|
|
47
50
|
/**
|
|
48
51
|
* @deprecated Use {@link cidForLex} from `@atproto/lex-cbor` instead.
|
|
49
52
|
*/
|
|
50
|
-
|
|
53
|
+
async function cidForCborLegacy(data: unknown): Promise<CID> {
|
|
54
|
+
return asMultiformatsCID(await cidForLex(data as LexValue))
|
|
55
|
+
}
|
|
51
56
|
export { cidForCborLegacy as cidForCbor }
|
|
52
57
|
|
|
53
58
|
/**
|
|
@@ -84,15 +89,15 @@ export async function verifyCidForBytes(
|
|
|
84
89
|
/**
|
|
85
90
|
* @deprecated Use {@link cidForRawHash} from `@atproto/lex-cbor` instead.
|
|
86
91
|
*/
|
|
87
|
-
export
|
|
92
|
+
export function sha256RawToCid(hash: Uint8Array): CID {
|
|
93
|
+
return asMultiformatsCID(cidForRawHash(hash))
|
|
94
|
+
}
|
|
88
95
|
|
|
89
96
|
/**
|
|
90
97
|
* @deprecated Use {@link decodeCid} from `@atproto/lex-cbor` instead.
|
|
91
98
|
*/
|
|
92
99
|
export function parseCidFromBytes(bytes: Uint8Array): CID {
|
|
93
|
-
|
|
94
|
-
if (!cid) throw new Error('Failed to parse CID from bytes')
|
|
95
|
-
return cid
|
|
100
|
+
return asMultiformatsCID(decodeCid(bytes, { flavor: 'dasl' }))
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
export class VerifyCidTransform extends Transform {
|