@ref0/git 0.12.0 → 0.14.0

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.
Files changed (247) hide show
  1. package/dist/access/private-refs.mjs +3 -3
  2. package/dist/auth/auth.d.mts +2 -2
  3. package/dist/auth/auth.mjs +3 -6
  4. package/dist/auth/authorize.mjs +1 -17
  5. package/dist/auth/helpers.mjs +3 -11
  6. package/dist/auth/host-services.mjs +11 -0
  7. package/dist/auth/policy.d.mts +27 -7
  8. package/dist/auth/policy.mjs +8 -4
  9. package/dist/auth/tokens-layer.d.mts +1 -2
  10. package/dist/auth/tokens-layer.mjs +2 -3
  11. package/dist/auth/tokens-public.d.mts +3 -3
  12. package/dist/auth/tokens.d.mts +1 -8
  13. package/dist/auth/tokens.mjs +1 -8
  14. package/dist/auth.d.mts +1 -4
  15. package/dist/auth.mjs +1 -3
  16. package/dist/client/git-http.mjs +18 -4
  17. package/dist/client/push-upload.mjs +33 -7
  18. package/dist/client/remote.mjs +94 -28
  19. package/dist/client/slice-push.d.mts +1 -1
  20. package/dist/contracts/access.d.mts +8 -8
  21. package/dist/contracts/actors.d.mts +2 -34
  22. package/dist/contracts/blobs.d.mts +2 -2
  23. package/dist/contracts/client.d.mts +8 -3
  24. package/dist/contracts/commits.d.mts +10 -2
  25. package/dist/contracts/commits.mjs +9 -1
  26. package/dist/contracts/files.d.mts +2 -2
  27. package/dist/contracts/forks.d.mts +11 -1
  28. package/dist/contracts/git.d.mts +18 -7
  29. package/dist/contracts/git.mjs +3 -2
  30. package/dist/contracts/lfs.d.mts +0 -7
  31. package/dist/contracts/objects.d.mts +80 -10
  32. package/dist/contracts/operations.d.mts +3 -0
  33. package/dist/contracts/operations.mjs +12 -2
  34. package/dist/contracts/push-uploads.d.mts +44 -5
  35. package/dist/contracts/push-uploads.mjs +7 -3
  36. package/dist/contracts/refs.d.mts +28 -6
  37. package/dist/contracts/remote.mjs +1 -3
  38. package/dist/contracts/repo-records.d.mts +1 -0
  39. package/dist/contracts/repos.d.mts +90 -2
  40. package/dist/contracts/repos.mjs +29 -2
  41. package/dist/contracts/result.d.mts +23 -18
  42. package/dist/contracts/result.mjs +17 -4
  43. package/dist/contracts/rules.d.mts +22 -22
  44. package/dist/contracts/server.d.mts +28 -77
  45. package/dist/contracts/signin.d.mts +1 -1
  46. package/dist/contracts/sync.d.mts +79 -19
  47. package/dist/contracts/sync.mjs +34 -10
  48. package/dist/contracts/tokens.d.mts +1 -6
  49. package/dist/contracts/tokens.mjs +1 -2
  50. package/dist/contracts/topics.d.mts +0 -5
  51. package/dist/contracts/work.d.mts +66 -2
  52. package/dist/contracts/work.mjs +8 -1
  53. package/dist/core/access.mjs +27 -5
  54. package/dist/core/ancestry.d.mts +9 -0
  55. package/dist/core/ancestry.mjs +6 -6
  56. package/dist/core/asked.mjs +42 -4
  57. package/dist/core/call-names.mjs +1 -0
  58. package/dist/core/call-services.mjs +2 -1
  59. package/dist/core/events/deliver.mjs +10 -2
  60. package/dist/core/forks.mjs +3 -3
  61. package/dist/core/imports.mjs +147 -9
  62. package/dist/core/index-job.mjs +9 -6
  63. package/dist/core/job-view.mjs +8 -9
  64. package/dist/core/mirror-rows.mjs +19 -4
  65. package/dist/core/objects/commits.mjs +16 -6
  66. package/dist/core/parts.d.mts +6 -1
  67. package/dist/core/parts.mjs +1 -4
  68. package/dist/core/purge.mjs +76 -6
  69. package/dist/core/push-decide.mjs +1 -1
  70. package/dist/core/push-files.d.mts +12 -0
  71. package/dist/core/push-files.mjs +225 -0
  72. package/dist/core/push-repo.d.mts +8 -0
  73. package/dist/core/push-repo.mjs +56 -0
  74. package/dist/core/push.d.mts +17 -0
  75. package/dist/core/push.mjs +98 -26
  76. package/dist/core/receipts.mjs +26 -10
  77. package/dist/core/ref-view.mjs +59 -5
  78. package/dist/core/refs.mjs +13 -8
  79. package/dist/core/repack.mjs +11 -8
  80. package/dist/core/repo-info.mjs +16 -9
  81. package/dist/core/repos.mjs +30 -14
  82. package/dist/core/seam.mjs +2 -2
  83. package/dist/core/view.d.mts +6 -0
  84. package/dist/core/view.mjs +45 -12
  85. package/dist/core/work.mjs +47 -22
  86. package/dist/effect.d.mts +3 -1
  87. package/dist/effect.mjs +3 -1
  88. package/dist/engine/reads.mjs +13 -6
  89. package/dist/engine/walk.mjs +4 -4
  90. package/dist/event-streams/event-streams.d.mts +1 -1
  91. package/dist/event-streams/event-streams.mjs +1 -1
  92. package/dist/event-streams/stream.d.mts +1 -1
  93. package/dist/event-streams/stream.mjs +1 -1
  94. package/dist/extend.d.mts +3 -3
  95. package/dist/extend.mjs +2 -2
  96. package/dist/http/answers.mjs +4 -2
  97. package/dist/http/core-parts.mjs +64 -15
  98. package/dist/http/handler.mjs +2 -2
  99. package/dist/http/node.mjs +5 -4
  100. package/dist/http/parts.d.mts +1 -0
  101. package/dist/http/push-upload-job.mjs +503 -0
  102. package/dist/http/push-uploads.d.mts +1 -0
  103. package/dist/http/push-uploads.mjs +114 -56
  104. package/dist/http/upload-pack.mjs +7 -6
  105. package/dist/index.d.mts +23 -24
  106. package/dist/index.mjs +4 -7
  107. package/dist/lfs/base.d.mts +7 -3
  108. package/dist/lfs/base.mjs +2 -1
  109. package/dist/lfs/copy.d.mts +46 -0
  110. package/dist/lfs/copy.mjs +26 -0
  111. package/dist/lfs/layer.mjs +4 -2
  112. package/dist/lfs/objects.d.mts +6 -0
  113. package/dist/lfs/objects.mjs +68 -41
  114. package/dist/lfs/rows.d.mts +13 -0
  115. package/dist/lfs/service.d.mts +1 -7
  116. package/dist/lfs/service.mjs +1 -9
  117. package/dist/lfs/upload-most.mjs +5 -5
  118. package/dist/node.d.mts +2 -2
  119. package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
  120. package/dist/protocol/bytes/sha256.d.mts +32 -0
  121. package/dist/protocol/bytes/sha256.mjs +105 -49
  122. package/dist/protocol/wire/advertisement.mjs +9 -4
  123. package/dist/protocol/wire/lines.d.mts +4 -2
  124. package/dist/protocol/wire/lines.mjs +11 -5
  125. package/dist/protocol/wire/push-uploads.mjs +13 -1
  126. package/dist/protocol/wire/v2.mjs +2 -2
  127. package/dist/protocol.d.mts +3 -1
  128. package/dist/protocol.mjs +3 -1
  129. package/dist/queue/advance.mjs +1 -1
  130. package/dist/queue/host.d.mts +1 -7
  131. package/dist/queue/host.mjs +1 -7
  132. package/dist/queue/layer.mjs +1 -1
  133. package/dist/queue/trim.mjs +1 -1
  134. package/dist/rest/blobs.d.mts +31 -23
  135. package/dist/rest/blobs.mjs +1 -1
  136. package/dist/rest/caller.d.mts +49 -9
  137. package/dist/rest/caller.mjs +1 -1
  138. package/dist/rest/client.d.mts +10 -3
  139. package/dist/rest/client.mjs +4 -0
  140. package/dist/rest/commits.d.mts +273 -240
  141. package/dist/rest/errors.d.mts +24 -4
  142. package/dist/rest/events.d.mts +9 -6
  143. package/dist/rest/events.mjs +1 -2
  144. package/dist/rest/files.d.mts +127 -115
  145. package/dist/rest/forks.d.mts +121 -97
  146. package/dist/rest/handler.mjs +4 -57
  147. package/dist/rest/handlers.d.mts +1 -1
  148. package/dist/rest/handlers.mjs +18 -4
  149. package/dist/rest/layer.mjs +2 -1
  150. package/dist/rest/me.d.mts +8 -4
  151. package/dist/rest/merges.d.mts +8 -4
  152. package/dist/rest/paths.mjs +1 -0
  153. package/dist/rest/queue.d.mts +282 -226
  154. package/dist/rest/refs.d.mts +205 -176
  155. package/dist/rest/repos.d.mts +108 -80
  156. package/dist/rest/tags.d.mts +24 -12
  157. package/dist/rest/tokens.d.mts +235 -211
  158. package/dist/rest/topics.d.mts +53 -33
  159. package/dist/rest/trees.d.mts +105 -89
  160. package/dist/rest/work.d.mts +467 -20
  161. package/dist/rest/work.mjs +8 -0
  162. package/dist/server/edge-node.d.mts +9 -13
  163. package/dist/server/edge-node.mjs +9 -12
  164. package/dist/server/git-layer.d.mts +1 -6
  165. package/dist/server/git-layer.mjs +2 -2
  166. package/dist/server/git-namespace.d.mts +3 -3
  167. package/dist/server/joined.d.mts +15 -22
  168. package/dist/server/joined.mjs +5 -29
  169. package/dist/server/lifecycle.mjs +107 -23
  170. package/dist/server/registry.mjs +9 -1
  171. package/dist/server/server.mjs +133 -212
  172. package/dist/storage/budget.mjs +2 -2
  173. package/dist/storage/clean-up.mjs +13 -10
  174. package/dist/storage/fetch.mjs +13 -8
  175. package/dist/storage/file-limits.mjs +24 -0
  176. package/dist/storage/index-build.d.mts +1 -0
  177. package/dist/storage/index-build.mjs +106 -62
  178. package/dist/storage/index-fetch.mjs +16 -3
  179. package/dist/storage/index-reach.mjs +33 -5
  180. package/dist/storage/index-remap.mjs +8 -1
  181. package/dist/storage/index-shallow.mjs +5 -3
  182. package/dist/storage/largest-files.mjs +48 -0
  183. package/dist/storage/lfs-pointers.mjs +10 -1
  184. package/dist/storage/loose.mjs +3 -1
  185. package/dist/storage/memory-budget.mjs +28 -4
  186. package/dist/storage/pack-reads.mjs +8 -8
  187. package/dist/storage/pack-receive.mjs +83 -25
  188. package/dist/storage/packs.mjs +37 -21
  189. package/dist/storage/prune-keep.mjs +203 -34
  190. package/dist/storage/prune-walk.mjs +54 -16
  191. package/dist/storage/prune.mjs +629 -196
  192. package/dist/storage/push-uploads.mjs +36 -12
  193. package/dist/storage/quarantine.mjs +9 -9
  194. package/dist/storage/ready.mjs +47 -19
  195. package/dist/storage/receive-bounds.mjs +29 -8
  196. package/dist/storage/receive-state.mjs +8 -0
  197. package/dist/storage/receive-steps.mjs +71 -18
  198. package/dist/storage/repack.d.mts +1 -1
  199. package/dist/storage/repack.mjs +1 -8
  200. package/dist/storage/rows.mjs +12 -1
  201. package/dist/storage/shallow.d.mts +1 -0
  202. package/dist/storage/shallow.mjs +26 -4
  203. package/dist/storage/stream-whole.mjs +5 -2
  204. package/dist/storage/visible.mjs +29 -1
  205. package/dist/storage/walk.mjs +2 -1
  206. package/dist/store/catalogue.mjs +1 -0
  207. package/dist/store/cursor-seal-namespace.d.mts +2 -0
  208. package/dist/store/cursor-seal-public.d.mts +5 -0
  209. package/dist/store/cursor-seal-public.mjs +5 -0
  210. package/dist/store/cursor-seal.d.mts +16 -2
  211. package/dist/store/cursor-seal.mjs +26 -14
  212. package/dist/store/errors.mjs +9 -1
  213. package/dist/store/records.d.mts +2 -0
  214. package/dist/store/records.mjs +9 -6
  215. package/dist/store/repo-record.d.mts +9 -7
  216. package/dist/store/repo-record.mjs +102 -19
  217. package/dist/store/scopes.mjs +10 -2
  218. package/dist/sync/bound.d.mts +2 -0
  219. package/dist/sync/bound.mjs +11 -2
  220. package/dist/sync/github.d.mts +6 -1
  221. package/dist/sync/github.mjs +55 -43
  222. package/dist/sync/http.mjs +36 -1
  223. package/dist/sync/import.mjs +1 -0
  224. package/dist/sync/layer.mjs +6 -2
  225. package/dist/sync/lfs-batch.mjs +119 -0
  226. package/dist/sync/lfs-copy.mjs +251 -0
  227. package/dist/sync/mirror.mjs +210 -137
  228. package/dist/sync/smart-http.mjs +4 -2
  229. package/dist/sync/step.mjs +25 -5
  230. package/dist/sync/tries.mjs +45 -14
  231. package/dist/sync.d.mts +2 -2
  232. package/dist/topics/host.mjs +1 -19
  233. package/dist/topics/layer.mjs +1 -1
  234. package/package.json +3 -8
  235. package/dist/auth/bridge.mjs +0 -30
  236. package/dist/auth/helpers.d.mts +0 -17
  237. package/dist/core/purge.d.mts +0 -8
  238. package/dist/core/registered-rows.d.mts +0 -5
  239. package/dist/core/repack.d.mts +0 -11
  240. package/dist/http/handler.d.mts +0 -2
  241. package/dist/rest/handler.d.mts +0 -21
  242. package/dist/rest.d.mts +0 -2
  243. package/dist/rest.mjs +0 -1
  244. package/dist/server/registry.d.mts +0 -16
  245. package/dist/server/server.d.mts +0 -36
  246. package/dist/storage/repack-job.d.mts +0 -3
  247. package/dist/topics/host.d.mts +0 -7
@@ -0,0 +1,46 @@
1
+ import "../contracts/git.mjs";
2
+ import { InternalRepoId } from "../contracts/ids.mjs";
3
+ import "../contracts/objects.mjs";
4
+ import { GitError } from "../contracts/result.mjs";
5
+ import { LfsStaging } from "./objects.mjs";
6
+ import { ListedRow } from "./rows.mjs";
7
+ import * as Effect from "effect/Effect";
8
+ import { Key, Row } from "@ref0/infra";
9
+ import * as Stream from "effect/Stream";
10
+ /**
11
+ * What import's copy of a source's Git LFS objects goes through, once `Lfs.layer` attached
12
+ * (#2397): LFS's own rows and bucket, as a Worker upload uses them, so a copied object is listed
13
+ * as an uploaded one is, and bytes that never list are deleted by upkeep as theirs are.
14
+ */
15
+ export interface LfsCopy {
16
+ /** Of `oids`, those `repo` lists, with their rows. */
17
+ readonly listed: (repo: InternalRepoId, oids: readonly string[]) => Effect.Effect<ReadonlyMap<string, ListedRow>, GitError>;
18
+ /**
19
+ * A staging key for each of `count` objects, each row added with upkeep's wake at its
20
+ * `removeAt`, `uploadGrace` from now: bytes put there that no commit lists are deleted then.
21
+ */
22
+ readonly stage: (repo: InternalRepoId, count: number) => Effect.Effect<readonly LfsStaging[], GitError>;
23
+ /**
24
+ * `body`, `size` bytes whose SHA-256 is `oid`, put at `staging`'s key with nothing buffered, the
25
+ * bucket checking the SHA-256: other bytes fail `INVALID_ARGUMENT`, keeping nothing. No
26
+ * interrupt cuts it short, for the reason `bucketPut` gives, so `body` must end or fail of
27
+ * itself, as import's download does once its try's signal aborts.
28
+ */
29
+ readonly put: (staging: LfsStaging, body: Stream.Stream<Uint8Array, GitError>, size: number, oid: string) => Effect.Effect<void, GitError>;
30
+ /**
31
+ * The writes that list each of `landed` at its staging key and drop its staging row, for the
32
+ * copy's own commit, which moves its cursor with them. A staged object that didn't land keeps
33
+ * its row: a put that failed may still have stored its bytes, so upkeep deletes them at
34
+ * `removeAt`.
35
+ */
36
+ readonly listing: (landed: readonly LfsLanded[]) => {
37
+ readonly put: readonly Row[];
38
+ readonly delete: readonly Key[];
39
+ };
40
+ }
41
+ /** An object the copy put, checked, at its staging key. */
42
+ export interface LfsLanded {
43
+ readonly oid: string;
44
+ readonly size: number;
45
+ readonly staging: LfsStaging;
46
+ }
@@ -0,0 +1,26 @@
1
+ import { bucketDo } from "../storage/calls.mjs";
2
+ import { listedOf, stagedKeys } from "./objects.mjs";
3
+ import { listedKey, uploadGrace } from "./rows.mjs";
4
+ import * as Clock$1 from "effect/Clock";
5
+ import * as Effect from "effect/Effect";
6
+ // src/lfs/copy.ts
7
+ /** The copy over LFS's registration's rows and its bucket. */
8
+ const lfsCopy = (rows, bucket) => ({
9
+ listed: (repo, oids) => listedOf(rows, repo, oids),
10
+ stage: (repo, count) => Effect.flatMap(Clock$1.currentTimeMillis, (now) => stagedKeys(rows, repo, now + uploadGrace, count)),
11
+ put: (staging, body, size, oid) => Effect.asVoid(Effect.uninterruptible(bucketDo(bucket.put(staging.key, body, {
12
+ size,
13
+ sha256: oid
14
+ })))),
15
+ listing: (landed) => ({
16
+ put: landed.map(({ oid, size, staging }) => ({
17
+ ...listedKey(oid),
18
+ value: {
19
+ size,
20
+ key: staging.key
21
+ }
22
+ })),
23
+ delete: landed.map(({ staging }) => staging.row)
24
+ })
25
+ });
26
+ export { lfsCopy };
@@ -2,6 +2,7 @@ import { register } from "../contracts/git.mjs";
2
2
  import { callerFor, resolvedAs } from "../core/access.mjs";
3
3
  import { seenIn } from "../core/objects/reading.mjs";
4
4
  import { LfsBase } from "./base.mjs";
5
+ import { lfsCopy } from "./copy.mjs";
5
6
  import { objectOf } from "./objects.mjs";
6
7
  import { pointerCheck } from "./pointers.mjs";
7
8
  import { lfsPurge } from "./purge.mjs";
@@ -24,7 +25,7 @@ var Lfs = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/Lfs")) {};
24
25
  const lfsRegistration = /* @__PURE__ */ Effect.fnUntraced(function* (registration, options = {}) {
25
26
  const base = yield* LfsBase;
26
27
  const { needs, bucket, links, requestLimits } = base;
27
- if (bucket === void 0) return yield* Effect.die(/* @__PURE__ */ new TypeError("lfs() keeps its objects in the adapter's bucket: give the adapter a bucket"));
28
+ if (bucket === void 0) return yield* Effect.die(/* @__PURE__ */ new TypeError("Lfs.layer() keeps its objects in the host's bucket: provide Bucket.Bucket"));
28
29
  const caps = {
29
30
  bodyCap: options.bodyCap ?? requestLimits.bodyBytes,
30
31
  cpuMs: options.cpuMs ?? requestLimits.cpuMs
@@ -51,7 +52,8 @@ const lfsRegistration = /* @__PURE__ */ Effect.fnUntraced(function* (registratio
51
52
  seen: (blobs) => Effect.provideContext(Effect.flatMap(resolvedAs(input.repo, input.objects.repo), (resolved) => seenIn(input.caller, resolved, blobs)), needs)
52
53
  })
53
54
  },
54
- read
55
+ read,
56
+ copy: lfsCopy(registration.rows, bucket)
55
57
  });
56
58
  yield* registration.addUpkeep(lfsUpkeep(registration.rows, bucket, links !== void 0));
57
59
  yield* registration.addPurge(lfsPurge(registration.rows, bucket));
@@ -5,6 +5,7 @@ import "../contracts/git.mjs";
5
5
  import { InternalRepoId, RepoName } from "../contracts/ids.mjs";
6
6
  import "../contracts/result.mjs";
7
7
  import "effect/Effect";
8
+ import { Key } from "@ref0/infra";
8
9
  /** One request to a repo's `info/lfs/`, from a caller `identify` answered. */
9
10
  export interface LfsCall {
10
11
  readonly caller: Caller;
@@ -13,6 +14,11 @@ export interface LfsCall {
13
14
  /** The repo's URL as the client named it, which a Worker's links point under. */
14
15
  readonly repoUrl: string;
15
16
  }
17
+ /** An object's staging key in the bucket, and the row that has upkeep delete it unless listed. */
18
+ export interface LfsStaging {
19
+ readonly key: string;
20
+ readonly row: Key;
21
+ }
16
22
  /** What `objectOf` reads: an object of `repo`'s, for `caller`, of `size` when it's given. */
17
23
  export interface ObjectRead {
18
24
  readonly caller: Caller;
@@ -1,4 +1,3 @@
1
- import { nativeSha256Hasher } from "../protocol/bytes/sha256-hasher.mjs";
2
1
  import { gathered } from "../protocol/bytes/streams.mjs";
3
2
  import { contended, openFor } from "../core/access.mjs";
4
3
  import { ownWriter } from "../core/own-writes.mjs";
@@ -19,6 +18,7 @@ import { fail, gitError, httpStatus } from "../contracts/result.mjs";
19
18
  import * as Clock$1 from "effect/Clock";
20
19
  import * as Effect from "effect/Effect";
21
20
  import * as Option from "effect/Option";
21
+ import * as Result from "effect/Result";
22
22
  import { Unavailable } from "@ref0/infra";
23
23
  import * as Stream from "effect/Stream";
24
24
  import * as DateTime from "effect/DateTime";
@@ -337,9 +337,11 @@ const verify = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
337
337
  return yield* contended();
338
338
  });
339
339
  /**
340
- * `PUT objects/<oid>`, a Worker upload: streams the body to a staging key of its own while it
341
- * hashes it, and lists the object at that key when the hash is its oid. Its staging row, added
342
- * before a byte is written, has upkeep delete the bytes if they're never listed.
340
+ * `PUT objects/<oid>`, a Worker upload: streams the body to a staging key of its own, put with its
341
+ * oid as the SHA-256 the bucket checks, so the Worker never hashes it, and lists the object at that
342
+ * key once the bucket took it. A body that isn't its oid the bucket refuses, keeping nothing of it.
343
+ * Its staging row, added before a byte is written, has upkeep delete the bytes if they're never
344
+ * listed.
343
345
  */
344
346
  const receive = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
345
347
  if (!isLfsOid(oid)) return yield* fail("INVALID_ARGUMENT", "An oid is a SHA-256, as 64 lowercase hex digits");
@@ -356,47 +358,70 @@ const receive = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
356
358
  const upload = rows?.upload;
357
359
  if (upload === void 0 || upload.expiresAt < started) return yield* fail("FAILED_PRECONDITION", "No upload link for this object is live", { hint: "Ask the batch API again" });
358
360
  if (upload.size > parts.uploadMost.bytes) return lfsAnswer(413, { message: pastMost(parts.uploadMost) });
359
- const id = randomText(16);
360
- const key = stagingKey(repo.internalId, id);
361
- const staged = stagingId(started + uploadGrace, id);
362
- yield* registered.add(repo.internalId, {
363
- put: [{
364
- collection: lfsCollections.staging,
365
- id: staged,
366
- value: {
367
- key,
368
- removeAt: started + uploadGrace
369
- }
370
- }],
371
- wake: started + uploadGrace
372
- });
373
- const hashed = hashing(call.request.body, upload.size);
374
- yield* Effect.uninterruptible(bucketDo(bucket.put(key, hashed.body, { size: upload.size }))).pipe(Effect.mapError((error) => hashed.past() ? pastSize(upload.size) : error));
375
- if ((yield* hashed.hasher.hex) !== oid) {
376
- yield* dropStaged(parts, repo.internalId, key, staged);
361
+ const [staging] = yield* stagedKeys(registered, repo.internalId, started + uploadGrace, 1);
362
+ if (staging === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("One staging key asked, none made"));
363
+ const { key } = staging;
364
+ const sent = counted(call.request.body, upload.size);
365
+ const put = yield* Effect.result(Effect.uninterruptible(bucketDo(bucket.put(key, sent.body, {
366
+ size: upload.size,
367
+ sha256: oid
368
+ }))));
369
+ if (Result.isFailure(put)) {
370
+ if (sent.past()) return yield* Effect.fail(pastSize(upload.size));
371
+ if (sent.size() < upload.size) return yield* Effect.fail(shortSize(upload.size, sent.size()));
372
+ if (put.failure.code !== "INVALID_ARGUMENT") return yield* Effect.fail(put.failure);
373
+ yield* dropStaged(parts, repo.internalId, staging.row.id);
377
374
  return yield* fail("INVALID_ARGUMENT", "The bytes' SHA-256 isn't the oid");
378
375
  }
379
376
  return yield* listStaged(registered, call.caller, repo, {
380
377
  oid,
381
378
  size: upload.size,
382
379
  key,
383
- staged,
380
+ staged: staging.row.id,
384
381
  deadline: started + streamMost,
385
382
  unseen
386
383
  });
387
384
  });
388
385
  /**
389
- * Deletes refused bytes at once, then their staging row at the version it's read at (#1940). A
390
- * failure of either leaves the row, whose wake has upkeep delete the bytes at its removeAt, and is
391
- * no reason to answer it in place of the refusal.
386
+ * `count` staging keys in `repo`, each row added with upkeep's wake at `removeAt`: bytes put at a
387
+ * key that no commit lists by then are deleted, as `endStages` does. A Worker upload's staging and
388
+ * an import's copy's, one way (#2397).
389
+ */
390
+ const stagedKeys = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, removeAt, count) {
391
+ const staging = Array.from({ length: count }, () => {
392
+ const id = randomText(16);
393
+ return {
394
+ key: stagingKey(repo, id),
395
+ row: {
396
+ collection: lfsCollections.staging,
397
+ id: stagingId(removeAt, id)
398
+ }
399
+ };
400
+ });
401
+ if (staging.length === 0) return staging;
402
+ yield* rows.add(repo, {
403
+ put: staging.map(({ key, row }) => ({
404
+ ...row,
405
+ value: {
406
+ key,
407
+ removeAt
408
+ }
409
+ })),
410
+ wake: removeAt
411
+ });
412
+ return staging;
413
+ });
414
+ /**
415
+ * Deletes the staging row of bytes the bucket refused, keeping none of them, at the version it's
416
+ * read at (#1940). A failure leaves the row, whose wake has upkeep delete its key at its removeAt,
417
+ * and is no reason to answer it in place of the refusal.
392
418
  */
393
- const dropStaged = /* @__PURE__ */ Effect.fnUntraced(function* (parts, repo, key, staged) {
419
+ const dropStaged = /* @__PURE__ */ Effect.fnUntraced(function* (parts, repo, staged) {
394
420
  const row = {
395
421
  collection: lfsCollections.staging,
396
422
  id: staged
397
423
  };
398
424
  yield* bestEffort(Effect.gen(function* () {
399
- yield* bucketDo(parts.bucket.remove(key));
400
425
  const read = yield* parts.rows.read(repo, [row]);
401
426
  yield* parts.rows.commit(repo, read.version, { delete: [row] });
402
427
  }));
@@ -410,6 +435,7 @@ const lengthOf = (request) => {
410
435
  return Number.isSafeInteger(length) ? length : void 0;
411
436
  };
412
437
  const pastSize = (size) => gitError("INVALID_ARGUMENT", `The bytes run past the ${size} the batch named`);
438
+ const shortSize = (size, sent) => gitError("INVALID_ARGUMENT", `The bytes end at ${sent}, short of the ${size} the batch named`);
413
439
  /**
414
440
  * An answer to a request whose body isn't needed: the body is let go first, and a cancel that
415
441
  * rejects is no reason to fail an upload that's done.
@@ -419,13 +445,12 @@ const answered = (request) => Effect.promise(async () => {
419
445
  return lfsAnswer(200, { message: "Already uploaded" });
420
446
  });
421
447
  /**
422
- * `body` as it streams to the bucket, gathered into pieces of `uploadPieceBytes`, counted, and
423
- * hashed through the runtime's own SHA-256, each piece's write awaited before it goes on, failing
424
- * past `most` bytes. No piece reaches more than one byte past what `most` leaves, so a body that
425
- * runs past it is read no further than that byte's chunk.
448
+ * `body` as it streams to the bucket, gathered into pieces of `uploadPieceBytes` and counted,
449
+ * failing past `most` bytes, or at its end short of them, before the bucket checks its hash. No
450
+ * piece reaches more than one byte past what `most` leaves, so a body that runs past it is read no
451
+ * further than that byte's chunk.
426
452
  */
427
- const hashing = (body, most) => {
428
- const hasher = nativeSha256Hasher();
453
+ const counted = (body, most) => {
429
454
  let size = 0;
430
455
  const read = Stream.fromReadableStream({
431
456
  evaluate: () => body === null ? new ReadableStream({ start: (controller) => controller.close() }) : gathered(body, (given) => Math.min(uploadPieceBytes, Math.max(1, most - given + 1))),
@@ -434,14 +459,16 @@ const hashing = (body, most) => {
434
459
  cause
435
460
  })
436
461
  });
462
+ const sized = Stream.mapEffect(read, (chunk) => {
463
+ size += chunk.length;
464
+ if (size > most) return Effect.fail(pastSize(most));
465
+ return Effect.succeed(chunk);
466
+ });
467
+ const ended = Stream.suspend(() => size < most ? Stream.fail(shortSize(most, size)) : Stream.empty);
437
468
  return {
438
- body: Stream.mapEffect(read, (chunk) => {
439
- size += chunk.length;
440
- if (size > most) return Effect.fail(pastSize(most));
441
- return Effect.as(hasher.write(chunk), chunk);
442
- }),
469
+ body: Stream.concat(sized, ended),
443
470
  past: () => size > most,
444
- hasher
471
+ size: () => size
445
472
  };
446
473
  };
447
474
  /** Lists a Worker upload's bytes at their staging key, in the commit that drops its staging row. */
@@ -530,4 +557,4 @@ const send = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
530
557
  }
531
558
  });
532
559
  });
533
- export { batch, listedOf, objectOf, receive, send, verify };
560
+ export { batch, listedOf, objectOf, receive, send, stagedKeys, verify };
@@ -0,0 +1,13 @@
1
+ import "../contracts/ids.mjs";
2
+ import * as Schema from "effect/Schema";
3
+ import { Key, Moment, Read } from "@ref0/infra";
4
+ /**
5
+ * A listed object: its bytes are at `key`, checked. A signed upload's are at its upload row's
6
+ * `objectKey`, and a Worker upload's stay at the staging key they streamed to, which only they
7
+ * were ever written to.
8
+ */
9
+ export declare const ListedRow: Schema.Struct<{
10
+ readonly size: Schema.Int;
11
+ readonly key: Schema.String;
12
+ }>;
13
+ export type ListedRow = typeof ListedRow.Type;
@@ -1,4 +1,3 @@
1
- import { LfsFeature, LfsOptions } from "../contracts/lfs.mjs";
2
1
  import { GitError } from "../contracts/result.mjs";
3
2
  import "../core/parts.mjs";
4
3
  import { LfsCall } from "./objects.mjs";
@@ -9,9 +8,4 @@ export interface LfsRoute extends LfsCall {
9
8
  readonly route: string;
10
9
  }
11
10
  /** Git LFS's API for a server's repos, its objects in `bucket`. */
12
- export type LfsService = (call: LfsRoute) => Effect.Effect<Response, GitError>;
13
- /**
14
- * Turns on Git LFS, its objects in the adapter's bucket: a server without it has no LFS. `options`
15
- * win over the adapter's `RequestLimits`, as `LfsOptions` says.
16
- */
17
- export declare const lfs: (options?: LfsOptions) => LfsFeature;
11
+ export type LfsService = (call: LfsRoute) => Effect.Effect<Response, GitError>;
@@ -4,14 +4,6 @@ import { batch, receive, send, verify } from "./objects.mjs";
4
4
  import { lfsAnswer } from "./wire.mjs";
5
5
  import * as Effect from "effect/Effect";
6
6
  // src/lfs/service.ts
7
- /**
8
- * Turns on Git LFS, its objects in the adapter's bucket: a server without it has no LFS. `options`
9
- * win over the adapter's `RequestLimits`, as `LfsOptions` says.
10
- */
11
- const lfs = (options = {}) => ({
12
- ...options,
13
- kind: "lfs"
14
- });
15
7
  const methodNotAllowed = (allow) => Effect.succeed(lfsAnswer(405, { message: "Method not allowed" }, { allow }));
16
8
  /** LFS's routes over `parts`, provided `needs`, the server's services, which `openRepo` reads. */
17
9
  const lfsService = (needs, parts) => (call) => Effect.provideContext(served(parts, call), needs);
@@ -35,4 +27,4 @@ const served = (parts, call) => {
35
27
  if (unlocking !== void 0) return method === "POST" ? unlock(parts, call, unlocking) : methodNotAllowed("POST");
36
28
  return fail("NOT_FOUND", "No such LFS route");
37
29
  };
38
- export { lfs, lfsService };
30
+ export { lfsService };
@@ -3,18 +3,18 @@ import { largestObject } from "./rows.mjs";
3
3
  /**
4
4
  * The largest Git LFS upload through the server, `workerUploadMost`, for a bucket that signs no
5
5
  * links: the least of what the platform's body cap passes on, what its CPU cap lets the upload
6
- * hash and store, and `largestObject`. A larger one is refused before a byte streams, at the
6
+ * stream to the bucket, and `largestObject`. A larger one is refused before a byte streams, at the
7
7
  * batch, so git-lfs never starts it.
8
8
  */
9
9
  /** The share of a request's CPU an upload may spend: the rest is its rows', its put's and the runtime's. */
10
10
  const cpuShare = .8;
11
11
  /**
12
12
  * The bytes an upload through a Worker gathers from its body's chunks before each goes on to its
13
- * hash and its put, since a client's body reaches a Worker in chunks of at most 4,096 B, each
14
- * paid for once over (run 46342279485, #2296): one piece an upload, held as it streams.
13
+ * put, which checks its SHA-256, since a client's body reaches a Worker in chunks of at most
14
+ * 4,096 B, each paid for once over (run 46342279485, #2296): one piece an upload, held as it streams.
15
15
  */
16
16
  const uploadPieceBytes = 1024 ** 2;
17
- /** The bytes `cpuMs` of CPU hashes and stores, at `uploadMsPerMiB` within `cpuShare` of it. */
17
+ /** The bytes `cpuMs` of CPU streams to a checked put, at `uploadMsPerMiB` within `cpuShare` of it. */
18
18
  const cpuBytes = (cpuMs) => Math.floor(cpuShare * cpuMs / 22 * 1024 ** 2);
19
19
  /** The largest upload `caps` let finish: `largestObject` where neither binds below it. */
20
20
  const uploadMostOf = (caps) => {
@@ -39,7 +39,7 @@ const capsRefusal = (caps) => {
39
39
  /** What each cap that sets the largest upload is, as a refusal names it. */
40
40
  const setBy = {
41
41
  body: "the largest body its platform passes on",
42
- cpu: "what its CPU cap lets it hash and store",
42
+ cpu: "what its CPU cap lets it stream to the bucket",
43
43
  object: "R2's largest single put"
44
44
  };
45
45
  /** Why an upload of more than `most` is refused, and what takes it. */
package/dist/node.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { NodeAnswerer, toNodeHandler, toNodeMiddleware } from "./server/edge-node.mjs";
1
+ import { toNodeHandler, toNodeMiddleware } from "./server/edge-node.mjs";
2
2
  import { NodeHandler, NodeMiddleware, NodeNext, NodeRequest, NodeResponse } from "./http/node.mjs";
3
- export { type NodeAnswerer, type NodeHandler, type NodeMiddleware, type NodeNext, type NodeRequest, type NodeResponse, toNodeHandler, toNodeMiddleware };
3
+ export { type NodeHandler, type NodeMiddleware, type NodeNext, type NodeRequest, type NodeResponse, toNodeHandler, toNodeMiddleware };
@@ -0,0 +1,15 @@
1
+ import "./sha1-hasher.mjs";
2
+ import * as Effect from "effect/Effect";
3
+ /**
4
+ * A SHA-256 written a piece at a time as an upload's body streams through, as `@ref0/github`'s
5
+ * release asset in one request is (#2452), through the runtime's own hash: workerd's
6
+ * `crypto.DigestStream`, or Node's `createHash`, and `Sha256` where a runtime has neither.
7
+ * `sha1-hasher.ts` does the same for a pack's SHA-1.
8
+ */
9
+ /** A SHA-256 written a piece at a time, then its sum as 64 lowercase hex digits. */
10
+ export interface Sha256Hasher {
11
+ readonly write: (bytes: Uint8Array) => Effect.Effect<void>;
12
+ readonly hex: Effect.Effect<string>;
13
+ }
14
+ /** A `Sha256Hasher` through this runtime's own hash, or `Sha256` where it has none. */
15
+ export declare const nativeSha256Hasher: () => Sha256Hasher;
@@ -0,0 +1,32 @@
1
+ import * as Schema from "effect/Schema";
2
+ /**
3
+ * A SHA-256's state between writes: its eight words, the bytes it took, and the bytes past its last
4
+ * whole 64-byte block, as lowercase hex, as many as `length` leaves past a block. Decode stored
5
+ * state through it, so a damaged one fails by name before a `Sha256` goes on from it.
6
+ */
7
+ export declare const Sha256State: Schema.Struct<{
8
+ readonly words: Schema.Tuple<readonly [Schema.Number, Schema.Number, Schema.Number, Schema.Number, Schema.Number, Schema.Number, Schema.Number, Schema.Number]>;
9
+ readonly length: Schema.Int;
10
+ readonly pending: Schema.String;
11
+ }>;
12
+ export type Sha256State = typeof Sha256State.Type;
13
+ /** A stored state, checked: a typed failure for one no `Sha256` could have written. */
14
+ export declare const decodeSha256State: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => import("effect/Effect").Effect<{
15
+ readonly words: readonly [number, number, number, number, number, number, number, number];
16
+ readonly length: number;
17
+ readonly pending: string;
18
+ }, Schema.SchemaError, never>;
19
+ export declare class Sha256 {
20
+ #private;
21
+ /**
22
+ * A hash from the start, or going on from `state`, which it trusts: one `decodeSha256State`
23
+ * hasn't checked and that holds a block or more of pending bytes throws a `RangeError`.
24
+ */
25
+ constructor(state?: Sha256State);
26
+ /** Takes `bytes`, after every byte before them. */
27
+ update(bytes: Uint8Array): void;
28
+ /** The state to go on from, as plain data. */
29
+ state(): Sha256State;
30
+ /** The digest of every byte taken, as 64 lowercase hex digits; the hash takes no more after it. */
31
+ hex(): string;
32
+ }
@@ -1,9 +1,40 @@
1
+ import * as Schema from "effect/Schema";
2
+ import * as Result from "effect/Result";
3
+ import * as Hex from "effect/encoding/Hex";
1
4
  // src/protocol/bytes/sha256.ts
2
5
  /**
3
- * SHA-256, as FIPS 180-4 defines it, written a piece at a time: LFS checks an upload's bytes as
4
- * they stream past, and the runtime's `crypto.subtle` takes only bytes held whole.
6
+ * SHA-256, as FIPS 180-4 defines it, written a piece at a time, whose state is plain data: LFS
7
+ * checks an upload's bytes as they stream past, and a release asset's parts, each put in a request
8
+ * of its own, hash on from the state the part before left. The runtime's `crypto.subtle` takes only
9
+ * bytes held whole, and its `DigestStream` keeps its state where nothing can save it.
5
10
  */
6
- const rounds = Uint32Array.from([
11
+ const Word = /* @__PURE__ */ Schema.Number.check(Schema.isUint32());
12
+ /**
13
+ * A SHA-256's state between writes: its eight words, the bytes it took, and the bytes past its last
14
+ * whole 64-byte block, as lowercase hex, as many as `length` leaves past a block. Decode stored
15
+ * state through it, so a damaged one fails by name before a `Sha256` goes on from it.
16
+ */
17
+ const Sha256State = /* @__PURE__ */ Schema.Struct({
18
+ words: Schema.Tuple([
19
+ Word,
20
+ Word,
21
+ Word,
22
+ Word,
23
+ Word,
24
+ Word,
25
+ Word,
26
+ Word
27
+ ]),
28
+ length: Schema.Int.check(Schema.isBetween({
29
+ minimum: 0,
30
+ maximum: Number.MAX_SAFE_INTEGER / 8
31
+ })),
32
+ pending: Schema.String.check(Schema.isPattern(/^(?:[0-9a-f]{2}){0,63}$/))
33
+ }).check(Schema.makeFilter((state) => state.pending.length / 2 === state.length % 64 || "its pending bytes are not the bytes past its last whole block"));
34
+ /** A stored state, checked: a typed failure for one no `Sha256` could have written. */
35
+ const decodeSha256State = /* @__PURE__ */ Schema.decodeUnknownEffect(Sha256State);
36
+ /** The 64 round constants, signed 32-bit, as the rounds add them. */
37
+ const rounds = Int32Array.from([
7
38
  1116352408,
8
39
  1899447441,
9
40
  3049323471,
@@ -79,26 +110,51 @@ const initial = [
79
110
  528734635,
80
111
  1541459225
81
112
  ];
82
- const rotate = (word, by) => word >>> by | word << 32 - by;
83
113
  var Sha256 = class {
84
- #words = Uint32Array.from(initial);
114
+ #words;
85
115
  #block = /* @__PURE__ */ new Uint8Array(64);
86
- #schedule = /* @__PURE__ */ new Uint32Array(64);
87
- #filled = 0;
88
- #length = 0;
116
+ #blockView = new DataView(this.#block.buffer);
117
+ #schedule = /* @__PURE__ */ new Int32Array(64);
118
+ #filled;
119
+ #length;
120
+ /**
121
+ * A hash from the start, or going on from `state`, which it trusts: one `decodeSha256State`
122
+ * hasn't checked and that holds a block or more of pending bytes throws a `RangeError`.
123
+ */
124
+ constructor(state) {
125
+ const pending = state === void 0 ? /* @__PURE__ */ new Uint8Array(0) : Result.getOrThrow(Hex.decode(state.pending));
126
+ if (pending.length >= 64) throw new RangeError("a SHA-256's pending bytes fill a block");
127
+ this.#words = [...state?.words ?? initial];
128
+ this.#block.set(pending);
129
+ this.#filled = pending.length;
130
+ this.#length = state?.length ?? 0;
131
+ }
89
132
  /** Takes `bytes`, after every byte before them. */
90
133
  update(bytes) {
134
+ let at = 0;
91
135
  this.#length += bytes.length;
92
- for (let at = 0; at < bytes.length;) {
93
- const take = Math.min(64 - this.#filled, bytes.length - at);
94
- this.#block.set(bytes.subarray(at, at + take), this.#filled);
95
- this.#filled += take;
96
- at += take;
97
- if (this.#filled === 64) {
98
- this.#compress();
99
- this.#filled = 0;
100
- }
136
+ if (this.#filled > 0) {
137
+ at = Math.min(64 - this.#filled, bytes.length);
138
+ this.#block.set(bytes.subarray(0, at), this.#filled);
139
+ this.#filled += at;
140
+ if (this.#filled < 64) return;
141
+ this.#compress(this.#blockView, 0);
142
+ this.#filled = 0;
101
143
  }
144
+ if (at + 64 <= bytes.length) {
145
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
146
+ for (; at + 64 <= bytes.length; at += 64) this.#compress(view, at);
147
+ }
148
+ this.#block.set(bytes.subarray(at));
149
+ this.#filled = bytes.length - at;
150
+ }
151
+ /** The state to go on from, as plain data. */
152
+ state() {
153
+ return {
154
+ words: [...this.#words],
155
+ length: this.#length,
156
+ pending: Hex.encode(this.#block.subarray(0, this.#filled))
157
+ };
102
158
  }
103
159
  /** The digest of every byte taken, as 64 lowercase hex digits; the hash takes no more after it. */
104
160
  hex() {
@@ -106,51 +162,51 @@ var Sha256 = class {
106
162
  this.#block[this.#filled] = 128;
107
163
  this.#block.fill(0, this.#filled + 1);
108
164
  if (this.#filled >= 56) {
109
- this.#compress();
165
+ this.#compress(this.#blockView, 0);
110
166
  this.#block.fill(0);
111
167
  }
112
- const view = new DataView(this.#block.buffer);
113
- view.setUint32(56, Math.floor(bits / 2 ** 32));
114
- view.setUint32(60, bits >>> 0);
115
- this.#compress();
116
- return Array.from(this.#words, (word) => word.toString(16).padStart(8, "0")).join("");
168
+ this.#blockView.setUint32(56, Math.floor(bits / 2 ** 32));
169
+ this.#blockView.setUint32(60, bits >>> 0);
170
+ this.#compress(this.#blockView, 0);
171
+ return this.#words.map((word) => word.toString(16).padStart(8, "0")).join("");
117
172
  }
118
- #compress() {
173
+ /**
174
+ * Hashes the 64 bytes of `view` from `from` into the words, its working words in locals and its
175
+ * schedule in one reused array, each signed 32-bit until it's stored: an array of words read
176
+ * back through `?? 0` held it to about 55 MiB/s in Node.
177
+ */
178
+ #compress(view, from) {
119
179
  const w = this.#schedule;
120
- const view = new DataView(this.#block.buffer);
121
- for (let t = 0; t < 16; t += 1) w[t] = view.getUint32(t * 4);
180
+ for (let t = 0; t < 16; t += 1) w[t] = view.getInt32(from + t * 4);
122
181
  for (let t = 16; t < 64; t += 1) {
123
- const back2 = w[t - 2] ?? 0;
124
- const back15 = w[t - 15] ?? 0;
125
- const s0 = rotate(back15, 7) ^ rotate(back15, 18) ^ back15 >>> 3;
126
- const s1 = rotate(back2, 17) ^ rotate(back2, 19) ^ back2 >>> 10;
127
- w[t] = (w[t - 16] ?? 0) + s0 + (w[t - 7] ?? 0) + s1;
182
+ const back2 = w[t - 2];
183
+ const back15 = w[t - 15];
184
+ const s0 = (back15 >>> 7 | back15 << 25) ^ (back15 >>> 18 | back15 << 14) ^ back15 >>> 3;
185
+ const s1 = (back2 >>> 17 | back2 << 15) ^ (back2 >>> 19 | back2 << 13) ^ back2 >>> 10;
186
+ w[t] = w[t - 16] + s0 + w[t - 7] + s1 | 0;
128
187
  }
129
- let [a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0] = this.#words;
188
+ let [a, b, c, d, e, f, g, h] = this.#words;
130
189
  for (let t = 0; t < 64; t += 1) {
131
- const s1 = rotate(e, 6) ^ rotate(e, 11) ^ rotate(e, 25);
132
- const choice = e & f ^ ~e & g;
133
- const first = h + s1 + choice + (rounds[t] ?? 0) + (w[t] ?? 0) >>> 0;
134
- const second = (rotate(a, 2) ^ rotate(a, 13) ^ rotate(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
190
+ const s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
191
+ const first = h + s1 + (e & f ^ ~e & g) + rounds[t] + w[t] | 0;
192
+ const second = ((a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10)) + (a & b ^ a & c ^ b & c) | 0;
135
193
  h = g;
136
194
  g = f;
137
195
  f = e;
138
- e = d + first >>> 0;
196
+ e = d + first | 0;
139
197
  d = c;
140
198
  c = b;
141
199
  b = a;
142
- a = first + second >>> 0;
200
+ a = first + second | 0;
143
201
  }
144
- for (const [at, word] of [
145
- a,
146
- b,
147
- c,
148
- d,
149
- e,
150
- f,
151
- g,
152
- h
153
- ].entries()) this.#words[at] = (this.#words[at] ?? 0) + word;
202
+ this.#words[0] = this.#words[0] + a >>> 0;
203
+ this.#words[1] = this.#words[1] + b >>> 0;
204
+ this.#words[2] = this.#words[2] + c >>> 0;
205
+ this.#words[3] = this.#words[3] + d >>> 0;
206
+ this.#words[4] = this.#words[4] + e >>> 0;
207
+ this.#words[5] = this.#words[5] + f >>> 0;
208
+ this.#words[6] = this.#words[6] + g >>> 0;
209
+ this.#words[7] = this.#words[7] + h >>> 0;
154
210
  }
155
211
  };
156
- export { Sha256 };
212
+ export { Sha256, Sha256State, decodeSha256State };