@atproto/common 0.3.3 → 0.3.4

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,12 @@
1
1
  # @atproto/common
2
2
 
3
+ ## 0.3.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`4eaadc0ac`](https://github.com/bluesky-social/atproto/commit/4eaadc0acb6b73b9745dd7a2b929d02e58083ab0)]:
8
+ - @atproto/common-web@0.2.4
9
+
3
10
  ## 0.3.3
4
11
 
5
12
  ### Patch Changes
package/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  Dual MIT/Apache-2.0 License
2
2
 
3
- Copyright (c) 2022-2023 Bluesky PBC, and Contributors
3
+ Copyright (c) 2022-2024 Bluesky 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/env.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const envInt: (name: string) => number | undefined;
2
+ export declare const envStr: (name: string) => string | undefined;
3
+ export declare const envBool: (name: string) => boolean | undefined;
4
+ export declare const envList: (name: string) => string[];
package/dist/fs.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export declare const fileExists: (location: string) => Promise<boolean>;
2
+ export declare const readIfExists: (filepath: string) => Promise<Uint8Array | undefined>;
3
+ export declare const rmIfExists: (filepath: string, recursive?: boolean) => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from '@atproto/common-web';
2
2
  export * from './dates';
3
+ export * from './env';
3
4
  export * from './fs';
4
5
  export * from './ipld';
5
6
  export * from './ipld-multi';
package/dist/index.js CHANGED
@@ -8866,30 +8866,292 @@ var require_dist = __commonJS({
8866
8866
  }
8867
8867
  });
8868
8868
 
8869
- // ../../node_modules/.pnpm/node-gyp-build-optional-packages@5.0.3/node_modules/node-gyp-build-optional-packages/index.js
8869
+ // ../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/process.js
8870
+ var require_process = __commonJS({
8871
+ "../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/process.js"(exports, module2) {
8872
+ "use strict";
8873
+ var isLinux = () => process.platform === "linux";
8874
+ var report = null;
8875
+ var getReport = () => {
8876
+ if (!report) {
8877
+ report = isLinux() && process.report ? process.report.getReport() : {};
8878
+ }
8879
+ return report;
8880
+ };
8881
+ module2.exports = { isLinux, getReport };
8882
+ }
8883
+ });
8884
+
8885
+ // ../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/filesystem.js
8886
+ var require_filesystem = __commonJS({
8887
+ "../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/filesystem.js"(exports, module2) {
8888
+ "use strict";
8889
+ var fs2 = require("fs");
8890
+ var LDD_PATH = "/usr/bin/ldd";
8891
+ var readFileSync = (path) => fs2.readFileSync(path, "utf-8");
8892
+ var readFile = (path) => new Promise((resolve, reject) => {
8893
+ fs2.readFile(path, "utf-8", (err, data) => {
8894
+ if (err) {
8895
+ reject(err);
8896
+ } else {
8897
+ resolve(data);
8898
+ }
8899
+ });
8900
+ });
8901
+ module2.exports = {
8902
+ LDD_PATH,
8903
+ readFileSync,
8904
+ readFile
8905
+ };
8906
+ }
8907
+ });
8908
+
8909
+ // ../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/detect-libc.js
8910
+ var require_detect_libc = __commonJS({
8911
+ "../../node_modules/.pnpm/detect-libc@2.0.2/node_modules/detect-libc/lib/detect-libc.js"(exports, module2) {
8912
+ "use strict";
8913
+ var childProcess = require("child_process");
8914
+ var { isLinux, getReport } = require_process();
8915
+ var { LDD_PATH, readFile, readFileSync } = require_filesystem();
8916
+ var cachedFamilyFilesystem;
8917
+ var cachedVersionFilesystem;
8918
+ var command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true";
8919
+ var commandOut = "";
8920
+ var safeCommand = () => {
8921
+ if (!commandOut) {
8922
+ return new Promise((resolve) => {
8923
+ childProcess.exec(command, (err, out) => {
8924
+ commandOut = err ? " " : out;
8925
+ resolve(commandOut);
8926
+ });
8927
+ });
8928
+ }
8929
+ return commandOut;
8930
+ };
8931
+ var safeCommandSync = () => {
8932
+ if (!commandOut) {
8933
+ try {
8934
+ commandOut = childProcess.execSync(command, { encoding: "utf8" });
8935
+ } catch (_err) {
8936
+ commandOut = " ";
8937
+ }
8938
+ }
8939
+ return commandOut;
8940
+ };
8941
+ var GLIBC = "glibc";
8942
+ var RE_GLIBC_VERSION = /GLIBC\s(\d+\.\d+)/;
8943
+ var MUSL = "musl";
8944
+ var GLIBC_ON_LDD = GLIBC.toUpperCase();
8945
+ var MUSL_ON_LDD = MUSL.toLowerCase();
8946
+ var isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
8947
+ var familyFromReport = () => {
8948
+ const report = getReport();
8949
+ if (report.header && report.header.glibcVersionRuntime) {
8950
+ return GLIBC;
8951
+ }
8952
+ if (Array.isArray(report.sharedObjects)) {
8953
+ if (report.sharedObjects.some(isFileMusl)) {
8954
+ return MUSL;
8955
+ }
8956
+ }
8957
+ return null;
8958
+ };
8959
+ var familyFromCommand = (out) => {
8960
+ const [getconf, ldd1] = out.split(/[\r\n]+/);
8961
+ if (getconf && getconf.includes(GLIBC)) {
8962
+ return GLIBC;
8963
+ }
8964
+ if (ldd1 && ldd1.includes(MUSL)) {
8965
+ return MUSL;
8966
+ }
8967
+ return null;
8968
+ };
8969
+ var getFamilyFromLddContent = (content) => {
8970
+ if (content.includes(MUSL_ON_LDD)) {
8971
+ return MUSL;
8972
+ }
8973
+ if (content.includes(GLIBC_ON_LDD)) {
8974
+ return GLIBC;
8975
+ }
8976
+ return null;
8977
+ };
8978
+ var familyFromFilesystem = async () => {
8979
+ if (cachedFamilyFilesystem !== void 0) {
8980
+ return cachedFamilyFilesystem;
8981
+ }
8982
+ cachedFamilyFilesystem = null;
8983
+ try {
8984
+ const lddContent = await readFile(LDD_PATH);
8985
+ cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
8986
+ } catch (e) {
8987
+ }
8988
+ return cachedFamilyFilesystem;
8989
+ };
8990
+ var familyFromFilesystemSync = () => {
8991
+ if (cachedFamilyFilesystem !== void 0) {
8992
+ return cachedFamilyFilesystem;
8993
+ }
8994
+ cachedFamilyFilesystem = null;
8995
+ try {
8996
+ const lddContent = readFileSync(LDD_PATH);
8997
+ cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
8998
+ } catch (e) {
8999
+ }
9000
+ return cachedFamilyFilesystem;
9001
+ };
9002
+ var family = async () => {
9003
+ let family2 = null;
9004
+ if (isLinux()) {
9005
+ family2 = await familyFromFilesystem();
9006
+ if (!family2) {
9007
+ family2 = familyFromReport();
9008
+ }
9009
+ if (!family2) {
9010
+ const out = await safeCommand();
9011
+ family2 = familyFromCommand(out);
9012
+ }
9013
+ }
9014
+ return family2;
9015
+ };
9016
+ var familySync = () => {
9017
+ let family2 = null;
9018
+ if (isLinux()) {
9019
+ family2 = familyFromFilesystemSync();
9020
+ if (!family2) {
9021
+ family2 = familyFromReport();
9022
+ }
9023
+ if (!family2) {
9024
+ const out = safeCommandSync();
9025
+ family2 = familyFromCommand(out);
9026
+ }
9027
+ }
9028
+ return family2;
9029
+ };
9030
+ var isNonGlibcLinux = async () => isLinux() && await family() !== GLIBC;
9031
+ var isNonGlibcLinuxSync = () => isLinux() && familySync() !== GLIBC;
9032
+ var versionFromFilesystem = async () => {
9033
+ if (cachedVersionFilesystem !== void 0) {
9034
+ return cachedVersionFilesystem;
9035
+ }
9036
+ cachedVersionFilesystem = null;
9037
+ try {
9038
+ const lddContent = await readFile(LDD_PATH);
9039
+ const versionMatch = lddContent.match(RE_GLIBC_VERSION);
9040
+ if (versionMatch) {
9041
+ cachedVersionFilesystem = versionMatch[1];
9042
+ }
9043
+ } catch (e) {
9044
+ }
9045
+ return cachedVersionFilesystem;
9046
+ };
9047
+ var versionFromFilesystemSync = () => {
9048
+ if (cachedVersionFilesystem !== void 0) {
9049
+ return cachedVersionFilesystem;
9050
+ }
9051
+ cachedVersionFilesystem = null;
9052
+ try {
9053
+ const lddContent = readFileSync(LDD_PATH);
9054
+ const versionMatch = lddContent.match(RE_GLIBC_VERSION);
9055
+ if (versionMatch) {
9056
+ cachedVersionFilesystem = versionMatch[1];
9057
+ }
9058
+ } catch (e) {
9059
+ }
9060
+ return cachedVersionFilesystem;
9061
+ };
9062
+ var versionFromReport = () => {
9063
+ const report = getReport();
9064
+ if (report.header && report.header.glibcVersionRuntime) {
9065
+ return report.header.glibcVersionRuntime;
9066
+ }
9067
+ return null;
9068
+ };
9069
+ var versionSuffix = (s) => s.trim().split(/\s+/)[1];
9070
+ var versionFromCommand = (out) => {
9071
+ const [getconf, ldd1, ldd2] = out.split(/[\r\n]+/);
9072
+ if (getconf && getconf.includes(GLIBC)) {
9073
+ return versionSuffix(getconf);
9074
+ }
9075
+ if (ldd1 && ldd2 && ldd1.includes(MUSL)) {
9076
+ return versionSuffix(ldd2);
9077
+ }
9078
+ return null;
9079
+ };
9080
+ var version2 = async () => {
9081
+ let version3 = null;
9082
+ if (isLinux()) {
9083
+ version3 = await versionFromFilesystem();
9084
+ if (!version3) {
9085
+ version3 = versionFromReport();
9086
+ }
9087
+ if (!version3) {
9088
+ const out = await safeCommand();
9089
+ version3 = versionFromCommand(out);
9090
+ }
9091
+ }
9092
+ return version3;
9093
+ };
9094
+ var versionSync = () => {
9095
+ let version3 = null;
9096
+ if (isLinux()) {
9097
+ version3 = versionFromFilesystemSync();
9098
+ if (!version3) {
9099
+ version3 = versionFromReport();
9100
+ }
9101
+ if (!version3) {
9102
+ const out = safeCommandSync();
9103
+ version3 = versionFromCommand(out);
9104
+ }
9105
+ }
9106
+ return version3;
9107
+ };
9108
+ module2.exports = {
9109
+ GLIBC,
9110
+ MUSL,
9111
+ family,
9112
+ familySync,
9113
+ isNonGlibcLinux,
9114
+ isNonGlibcLinuxSync,
9115
+ version: version2,
9116
+ versionSync
9117
+ };
9118
+ }
9119
+ });
9120
+
9121
+ // ../../node_modules/.pnpm/node-gyp-build-optional-packages@5.1.1/node_modules/node-gyp-build-optional-packages/index.js
8870
9122
  var require_node_gyp_build_optional_packages = __commonJS({
8871
- "../../node_modules/.pnpm/node-gyp-build-optional-packages@5.0.3/node_modules/node-gyp-build-optional-packages/index.js"(exports, module2) {
9123
+ "../../node_modules/.pnpm/node-gyp-build-optional-packages@5.1.1/node_modules/node-gyp-build-optional-packages/index.js"(exports, module2) {
8872
9124
  var fs2 = require("fs");
8873
9125
  var path = require("path");
8874
- var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
9126
+ var url = require("url");
8875
9127
  var vars = process.config && process.config.variables || {};
8876
9128
  var prebuildsOnly = !!process.env.PREBUILDS_ONLY;
8877
- var abi = process.versions.modules;
9129
+ var versions = process.versions;
9130
+ var abi = versions.modules;
9131
+ if (versions.deno || process.isBun) {
9132
+ abi = "unsupported";
9133
+ }
8878
9134
  var runtime = isElectron() ? "electron" : "node";
8879
9135
  var arch = process.arch;
8880
9136
  var platform = process.platform;
8881
- var libc = process.env.LIBC || (isAlpine(platform) ? "musl" : "glibc");
9137
+ var libc = process.env.LIBC || (isMusl(platform) ? "musl" : "glibc");
8882
9138
  var armv = process.env.ARM_VERSION || (arch === "arm64" ? "8" : vars.arm_version) || "";
8883
- var uv = (process.versions.uv || "").split(".")[0];
9139
+ var uv = (versions.uv || "").split(".")[0];
8884
9140
  module2.exports = load;
8885
9141
  function load(dir) {
8886
- return runtimeRequire(load.path(dir));
9142
+ if (typeof __webpack_require__ === "function")
9143
+ return __non_webpack_require__(load.path(dir));
9144
+ else
9145
+ return require(load.path(dir));
8887
9146
  }
8888
9147
  load.path = function(dir) {
8889
9148
  dir = path.resolve(dir || ".");
8890
- var packageName;
9149
+ var packageName = "";
8891
9150
  try {
8892
- packageName = runtimeRequire(path.join(dir, "package.json")).name;
9151
+ if (typeof __webpack_require__ === "function")
9152
+ packageName = __non_webpack_require__(path.join(dir, "package.json")).name;
9153
+ else
9154
+ packageName = require(path.join(dir, "package.json")).name;
8893
9155
  var varName = packageName.toUpperCase().replace(/-/g, "_") + "_PREBUILD";
8894
9156
  if (process.env[varName])
8895
9157
  dir = process.env[varName];
@@ -8911,7 +9173,7 @@ var require_node_gyp_build_optional_packages = __commonJS({
8911
9173
  return nearby;
8912
9174
  var platformPackage = (packageName[0] == "@" ? "" : "@" + packageName + "/") + packageName + "-" + platform + "-" + arch;
8913
9175
  try {
8914
- var prebuildPackage = path.dirname(require("module").createRequire(path.join(dir, "package.json")).resolve(platformPackage));
9176
+ var prebuildPackage = path.dirname(require("module").createRequire(url.pathToFileURL(path.join(dir, "package.json"))).resolve(platformPackage));
8915
9177
  return resolveFile(prebuildPackage);
8916
9178
  } catch (error) {
8917
9179
  }
@@ -8927,7 +9189,7 @@ var require_node_gyp_build_optional_packages = __commonJS({
8927
9189
  process.versions.electron ? "electron=" + process.versions.electron : "",
8928
9190
  typeof __webpack_require__ === "function" ? "webpack=true" : ""
8929
9191
  ].filter(Boolean).join(" ");
8930
- throw new Error("No native build was found for " + target2 + "\n loaded from: " + dir + " and package: " + platformPackage + "\n");
9192
+ throw new Error("No native build was found for " + target2 + "\n attempted loading from: " + dir + " and package: " + platformPackage + "\n");
8931
9193
  function resolve(dir2) {
8932
9194
  var tuples = readdirSync(path.join(dir2, "prebuilds")).map(parseTuple);
8933
9195
  var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0];
@@ -9050,8 +9312,11 @@ var require_node_gyp_build_optional_packages = __commonJS({
9050
9312
  return true;
9051
9313
  return typeof window !== "undefined" && window.process && window.process.type === "renderer";
9052
9314
  }
9053
- function isAlpine(platform2) {
9054
- return platform2 === "linux" && fs2.existsSync("/etc/alpine-release");
9315
+ function isMusl(platform2) {
9316
+ if (platform2 !== "linux")
9317
+ return false;
9318
+ const { familySync, MUSL } = require_detect_libc();
9319
+ return familySync() === MUSL;
9055
9320
  }
9056
9321
  load.parseTags = parseTags;
9057
9322
  load.matchTags = matchTags;
@@ -9062,9 +9327,9 @@ var require_node_gyp_build_optional_packages = __commonJS({
9062
9327
  }
9063
9328
  });
9064
9329
 
9065
- // ../../node_modules/.pnpm/cbor-extract@2.1.1/node_modules/cbor-extract/index.js
9330
+ // ../../node_modules/.pnpm/cbor-extract@2.2.0/node_modules/cbor-extract/index.js
9066
9331
  var require_cbor_extract = __commonJS({
9067
- "../../node_modules/.pnpm/cbor-extract@2.1.1/node_modules/cbor-extract/index.js"(exports, module2) {
9332
+ "../../node_modules/.pnpm/cbor-extract@2.2.0/node_modules/cbor-extract/index.js"(exports, module2) {
9068
9333
  module2.exports = require_node_gyp_build_optional_packages()(__dirname);
9069
9334
  }
9070
9335
  });
@@ -13063,9 +13328,11 @@ __export(src_exports3, {
13063
13328
  TID: () => TID,
13064
13329
  VerifyCidError: () => VerifyCidError,
13065
13330
  VerifyCidTransform: () => VerifyCidTransform,
13331
+ addHoursToDate: () => addHoursToDate,
13066
13332
  allComplete: () => allComplete,
13067
13333
  asyncFilter: () => asyncFilter,
13068
13334
  b64UrlToUtf8: () => b64UrlToUtf8,
13335
+ backoffMs: () => backoffMs,
13069
13336
  bailableWait: () => bailableWait,
13070
13337
  byteIterableToStream: () => byteIterableToStream,
13071
13338
  bytesToStream: () => bytesToStream,
@@ -13083,6 +13350,10 @@ __export(src_exports3, {
13083
13350
  dedupeStrs: () => dedupeStrs,
13084
13351
  def: () => def,
13085
13352
  didDocument: () => didDocument,
13353
+ envBool: () => envBool,
13354
+ envInt: () => envInt,
13355
+ envList: () => envList,
13356
+ envStr: () => envStr,
13086
13357
  errHasMsg: () => errHasMsg,
13087
13358
  fileExists: () => fileExists,
13088
13359
  flattenUint8Arrays: () => flattenUint8Arrays,
@@ -13093,7 +13364,9 @@ __export(src_exports3, {
13093
13364
  getNotifEndpoint: () => getNotifEndpoint,
13094
13365
  getPdsEndpoint: () => getPdsEndpoint,
13095
13366
  getServiceEndpoint: () => getServiceEndpoint,
13367
+ getSigningDidKey: () => getSigningDidKey,
13096
13368
  getSigningKey: () => getSigningKey,
13369
+ getVerificationMaterial: () => getVerificationMaterial,
13097
13370
  graphemeLen: () => graphemeLen,
13098
13371
  handleAllSettledErrors: () => handleAllSettledErrors,
13099
13372
  ipldEquals: () => ipldEquals,
@@ -13103,6 +13376,7 @@ __export(src_exports3, {
13103
13376
  isValidDidDoc: () => isValidDidDoc,
13104
13377
  jitter: () => jitter,
13105
13378
  jsonToIpld: () => jsonToIpld,
13379
+ keyBy: () => keyBy,
13106
13380
  lessThanAgoMs: () => lessThanAgoMs,
13107
13381
  mapDefined: () => mapDefined,
13108
13382
  noUndefinedVals: () => noUndefinedVals,
@@ -13110,6 +13384,9 @@ __export(src_exports3, {
13110
13384
  parseLanguage: () => parseLanguage,
13111
13385
  range: () => range,
13112
13386
  readFromGenerator: () => readFromGenerator,
13387
+ readIfExists: () => readIfExists,
13388
+ retry: () => retry,
13389
+ rmIfExists: () => rmIfExists,
13113
13390
  s32decode: () => s32decode,
13114
13391
  s32encode: () => s32encode,
13115
13392
  schema: () => schema,
@@ -13264,6 +13541,12 @@ var parseIntWithFallback = (value, fallback) => {
13264
13541
  };
13265
13542
 
13266
13543
  // ../common-web/src/arrays.ts
13544
+ var keyBy = (arr, key) => {
13545
+ return arr.reduce((acc, cur) => {
13546
+ acc[cur[key]] = cur;
13547
+ return acc;
13548
+ }, {});
13549
+ };
13267
13550
  var mapDefined = (arr, fn) => {
13268
13551
  const output = [];
13269
13552
  for (const item of arr) {
@@ -13333,6 +13616,7 @@ var AsyncBuffer = class {
13333
13616
  constructor(maxSize) {
13334
13617
  this.maxSize = maxSize;
13335
13618
  this.buffer = [];
13619
+ this.closed = false;
13336
13620
  this.promise = Promise.resolve();
13337
13621
  this.resolve = () => null;
13338
13622
  this.resetPromise();
@@ -13343,6 +13627,9 @@ var AsyncBuffer = class {
13343
13627
  get size() {
13344
13628
  return this.buffer.length;
13345
13629
  }
13630
+ get isClosed() {
13631
+ return this.closed;
13632
+ }
13346
13633
  resetPromise() {
13347
13634
  this.promise = new Promise((r) => this.resolve = r);
13348
13635
  }
@@ -13356,7 +13643,17 @@ var AsyncBuffer = class {
13356
13643
  }
13357
13644
  async *events() {
13358
13645
  while (true) {
13646
+ if (this.closed && this.buffer.length === 0) {
13647
+ if (this.toThrow) {
13648
+ throw this.toThrow;
13649
+ } else {
13650
+ return;
13651
+ }
13652
+ }
13359
13653
  await this.promise;
13654
+ if (this.toThrow) {
13655
+ throw this.toThrow;
13656
+ }
13360
13657
  if (this.maxSize && this.size > this.maxSize) {
13361
13658
  throw new AsyncBufferFullError(this.maxSize);
13362
13659
  }
@@ -13369,6 +13666,15 @@ var AsyncBuffer = class {
13369
13666
  }
13370
13667
  }
13371
13668
  }
13669
+ throw(err) {
13670
+ this.toThrow = err;
13671
+ this.closed = true;
13672
+ this.resolve();
13673
+ }
13674
+ close() {
13675
+ this.closed = true;
13676
+ this.resolve();
13677
+ }
13372
13678
  };
13373
13679
  var AsyncBufferFullError = class extends Error {
13374
13680
  constructor(maxSize) {
@@ -14684,6 +14990,43 @@ var ipldEquals = (a, b) => {
14684
14990
  return a === b;
14685
14991
  };
14686
14992
 
14993
+ // ../common-web/src/retry.ts
14994
+ async function retry(fn, opts = {}) {
14995
+ const { maxRetries = 3, retryable = () => true, getWaitMs = backoffMs } = opts;
14996
+ let retries = 0;
14997
+ let doneError;
14998
+ while (!doneError) {
14999
+ try {
15000
+ return await fn();
15001
+ } catch (err) {
15002
+ const waitMs = getWaitMs(retries);
15003
+ const willRetry = retries < maxRetries && waitMs !== null && retryable(err);
15004
+ if (willRetry) {
15005
+ retries += 1;
15006
+ if (waitMs !== 0) {
15007
+ await wait(waitMs);
15008
+ }
15009
+ } else {
15010
+ doneError = err;
15011
+ }
15012
+ }
15013
+ }
15014
+ throw doneError;
15015
+ }
15016
+ function backoffMs(n, multiplier = 100, max = 1e3) {
15017
+ const exponentialMs = Math.pow(2, n) * multiplier;
15018
+ const ms = Math.min(exponentialMs, max);
15019
+ return jitter2(ms);
15020
+ }
15021
+ function jitter2(value) {
15022
+ const delta = value * 0.15;
15023
+ return value + randomRange(-delta, delta);
15024
+ }
15025
+ function randomRange(from3, to) {
15026
+ const rand = Math.random() * (to - from3);
15027
+ return rand + from3;
15028
+ }
15029
+
14687
15030
  // ../../node_modules/.pnpm/zod@3.21.4/node_modules/zod/lib/index.mjs
14688
15031
  var util;
14689
15032
  (function(util2) {
@@ -18311,6 +18654,11 @@ var DAY = HOUR * 24;
18311
18654
  var lessThanAgoMs = (time, range2) => {
18312
18655
  return Date.now() < time.getTime() + range2;
18313
18656
  };
18657
+ var addHoursToDate = (hours, startingDate) => {
18658
+ const currentDate = startingDate ? new Date(startingDate) : new Date();
18659
+ currentDate.setHours(currentDate.getHours() + hours);
18660
+ return currentDate;
18661
+ };
18314
18662
 
18315
18663
  // ../common-web/src/strings.ts
18316
18664
  var import_graphemer = __toESM(require_lib());
@@ -18369,6 +18717,9 @@ var getHandle = (doc) => {
18369
18717
  return found.slice(5);
18370
18718
  };
18371
18719
  var getSigningKey = (doc) => {
18720
+ return getVerificationMaterial(doc, "atproto");
18721
+ };
18722
+ var getVerificationMaterial = (doc, keyId) => {
18372
18723
  const did = getDid(doc);
18373
18724
  let keys = doc.verificationMethod;
18374
18725
  if (!keys)
@@ -18378,7 +18729,7 @@ var getSigningKey = (doc) => {
18378
18729
  if (!Array.isArray(keys)) {
18379
18730
  keys = [keys];
18380
18731
  }
18381
- const found = keys.find((key) => key.id === "#atproto" || key.id === `${did}#atproto`);
18732
+ const found = keys.find((key) => key.id === `#${keyId}` || key.id === `${did}#${keyId}`);
18382
18733
  if (!found?.publicKeyMultibase)
18383
18734
  return void 0;
18384
18735
  return {
@@ -18386,6 +18737,12 @@ var getSigningKey = (doc) => {
18386
18737
  publicKeyMultibase: found.publicKeyMultibase
18387
18738
  };
18388
18739
  };
18740
+ var getSigningDidKey = (doc) => {
18741
+ const parsed = getSigningKey(doc);
18742
+ if (!parsed)
18743
+ return;
18744
+ return `did:key:${parsed.publicKeyMultibase}`;
18745
+ };
18389
18746
  var getPdsEndpoint = (doc) => {
18390
18747
  return getServiceEndpoint(doc, {
18391
18748
  id: "#atproto_pds",
@@ -18417,7 +18774,7 @@ var getServiceEndpoint = (doc, opts) => {
18417
18774
  const found = services.find((service2) => service2.id === opts.id || service2.id === `${did}${opts.id}`);
18418
18775
  if (!found)
18419
18776
  return void 0;
18420
- if (found.type !== opts.type) {
18777
+ if (opts.type && found.type !== opts.type) {
18421
18778
  return void 0;
18422
18779
  }
18423
18780
  if (typeof found.serviceEndpoint !== "string") {
@@ -18472,6 +18829,32 @@ function toSimplifiedISOSafe(dateStr) {
18472
18829
  return iso;
18473
18830
  }
18474
18831
 
18832
+ // src/env.ts
18833
+ var envInt = (name3) => {
18834
+ const str = process.env[name3];
18835
+ return parseIntWithFallback(str, void 0);
18836
+ };
18837
+ var envStr = (name3) => {
18838
+ const str = process.env[name3];
18839
+ if (str === void 0 || str.length === 0)
18840
+ return void 0;
18841
+ return str;
18842
+ };
18843
+ var envBool = (name3) => {
18844
+ const str = process.env[name3];
18845
+ if (str === "true" || str === "1")
18846
+ return true;
18847
+ if (str === "false" || str === "0")
18848
+ return false;
18849
+ return void 0;
18850
+ };
18851
+ var envList = (name3) => {
18852
+ const str = process.env[name3];
18853
+ if (str === void 0 || str.length === 0)
18854
+ return [];
18855
+ return str.split(",");
18856
+ };
18857
+
18475
18858
  // src/fs.ts
18476
18859
  var import_fs = require("fs");
18477
18860
  var import_promises = __toESM(require("fs/promises"));
@@ -18486,6 +18869,26 @@ var fileExists = async (location) => {
18486
18869
  throw err;
18487
18870
  }
18488
18871
  };
18872
+ var readIfExists = async (filepath) => {
18873
+ try {
18874
+ return await import_promises.default.readFile(filepath);
18875
+ } catch (err) {
18876
+ if (isErrnoException(err) && err.code === "ENOENT") {
18877
+ return;
18878
+ }
18879
+ throw err;
18880
+ }
18881
+ };
18882
+ var rmIfExists = async (filepath, recursive = false) => {
18883
+ try {
18884
+ await import_promises.default.rm(filepath, { recursive });
18885
+ } catch (err) {
18886
+ if (isErrnoException(err) && err.code === "ENOENT") {
18887
+ return;
18888
+ }
18889
+ throw err;
18890
+ }
18891
+ };
18489
18892
 
18490
18893
  // src/ipld.ts
18491
18894
  var import_crypto2 = __toESM(require("crypto"));
@@ -22588,9 +22991,11 @@ function ui8ToArrayBuffer(bytes) {
22588
22991
  TID,
22589
22992
  VerifyCidError,
22590
22993
  VerifyCidTransform,
22994
+ addHoursToDate,
22591
22995
  allComplete,
22592
22996
  asyncFilter,
22593
22997
  b64UrlToUtf8,
22998
+ backoffMs,
22594
22999
  bailableWait,
22595
23000
  byteIterableToStream,
22596
23001
  bytesToStream,
@@ -22608,6 +23013,10 @@ function ui8ToArrayBuffer(bytes) {
22608
23013
  dedupeStrs,
22609
23014
  def,
22610
23015
  didDocument,
23016
+ envBool,
23017
+ envInt,
23018
+ envList,
23019
+ envStr,
22611
23020
  errHasMsg,
22612
23021
  fileExists,
22613
23022
  flattenUint8Arrays,
@@ -22618,7 +23027,9 @@ function ui8ToArrayBuffer(bytes) {
22618
23027
  getNotifEndpoint,
22619
23028
  getPdsEndpoint,
22620
23029
  getServiceEndpoint,
23030
+ getSigningDidKey,
22621
23031
  getSigningKey,
23032
+ getVerificationMaterial,
22622
23033
  graphemeLen,
22623
23034
  handleAllSettledErrors,
22624
23035
  ipldEquals,
@@ -22628,6 +23039,7 @@ function ui8ToArrayBuffer(bytes) {
22628
23039
  isValidDidDoc,
22629
23040
  jitter,
22630
23041
  jsonToIpld,
23042
+ keyBy,
22631
23043
  lessThanAgoMs,
22632
23044
  mapDefined,
22633
23045
  noUndefinedVals,
@@ -22635,6 +23047,9 @@ function ui8ToArrayBuffer(bytes) {
22635
23047
  parseLanguage,
22636
23048
  range,
22637
23049
  readFromGenerator,
23050
+ readIfExists,
23051
+ retry,
23052
+ rmIfExists,
22638
23053
  s32decode,
22639
23054
  s32encode,
22640
23055
  schema,