@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.
- package/dist/access/private-refs.mjs +3 -3
- package/dist/auth/auth.d.mts +2 -2
- package/dist/auth/auth.mjs +3 -6
- package/dist/auth/authorize.mjs +1 -17
- package/dist/auth/helpers.mjs +3 -11
- package/dist/auth/host-services.mjs +11 -0
- package/dist/auth/policy.d.mts +27 -7
- package/dist/auth/policy.mjs +8 -4
- package/dist/auth/tokens-layer.d.mts +1 -2
- package/dist/auth/tokens-layer.mjs +2 -3
- package/dist/auth/tokens-public.d.mts +3 -3
- package/dist/auth/tokens.d.mts +1 -8
- package/dist/auth/tokens.mjs +1 -8
- package/dist/auth.d.mts +1 -4
- package/dist/auth.mjs +1 -3
- package/dist/client/git-http.mjs +18 -4
- package/dist/client/push-upload.mjs +33 -7
- package/dist/client/remote.mjs +94 -28
- package/dist/client/slice-push.d.mts +1 -1
- package/dist/contracts/access.d.mts +8 -8
- package/dist/contracts/actors.d.mts +2 -34
- package/dist/contracts/blobs.d.mts +2 -2
- package/dist/contracts/client.d.mts +8 -3
- package/dist/contracts/commits.d.mts +10 -2
- package/dist/contracts/commits.mjs +9 -1
- package/dist/contracts/files.d.mts +2 -2
- package/dist/contracts/forks.d.mts +11 -1
- package/dist/contracts/git.d.mts +18 -7
- package/dist/contracts/git.mjs +3 -2
- package/dist/contracts/lfs.d.mts +0 -7
- package/dist/contracts/objects.d.mts +80 -10
- package/dist/contracts/operations.d.mts +3 -0
- package/dist/contracts/operations.mjs +12 -2
- package/dist/contracts/push-uploads.d.mts +44 -5
- package/dist/contracts/push-uploads.mjs +7 -3
- package/dist/contracts/refs.d.mts +28 -6
- package/dist/contracts/remote.mjs +1 -3
- package/dist/contracts/repo-records.d.mts +1 -0
- package/dist/contracts/repos.d.mts +90 -2
- package/dist/contracts/repos.mjs +29 -2
- package/dist/contracts/result.d.mts +23 -18
- package/dist/contracts/result.mjs +17 -4
- package/dist/contracts/rules.d.mts +22 -22
- package/dist/contracts/server.d.mts +28 -77
- package/dist/contracts/signin.d.mts +1 -1
- package/dist/contracts/sync.d.mts +79 -19
- package/dist/contracts/sync.mjs +34 -10
- package/dist/contracts/tokens.d.mts +1 -6
- package/dist/contracts/tokens.mjs +1 -2
- package/dist/contracts/topics.d.mts +0 -5
- package/dist/contracts/work.d.mts +66 -2
- package/dist/contracts/work.mjs +8 -1
- package/dist/core/access.mjs +27 -5
- package/dist/core/ancestry.d.mts +9 -0
- package/dist/core/ancestry.mjs +6 -6
- package/dist/core/asked.mjs +42 -4
- package/dist/core/call-names.mjs +1 -0
- package/dist/core/call-services.mjs +2 -1
- package/dist/core/events/deliver.mjs +10 -2
- package/dist/core/forks.mjs +3 -3
- package/dist/core/imports.mjs +147 -9
- package/dist/core/index-job.mjs +9 -6
- package/dist/core/job-view.mjs +8 -9
- package/dist/core/mirror-rows.mjs +19 -4
- package/dist/core/objects/commits.mjs +16 -6
- package/dist/core/parts.d.mts +6 -1
- package/dist/core/parts.mjs +1 -4
- package/dist/core/purge.mjs +76 -6
- package/dist/core/push-decide.mjs +1 -1
- package/dist/core/push-files.d.mts +12 -0
- package/dist/core/push-files.mjs +225 -0
- package/dist/core/push-repo.d.mts +8 -0
- package/dist/core/push-repo.mjs +56 -0
- package/dist/core/push.d.mts +17 -0
- package/dist/core/push.mjs +98 -26
- package/dist/core/receipts.mjs +26 -10
- package/dist/core/ref-view.mjs +59 -5
- package/dist/core/refs.mjs +13 -8
- package/dist/core/repack.mjs +11 -8
- package/dist/core/repo-info.mjs +16 -9
- package/dist/core/repos.mjs +30 -14
- package/dist/core/seam.mjs +2 -2
- package/dist/core/view.d.mts +6 -0
- package/dist/core/view.mjs +45 -12
- package/dist/core/work.mjs +47 -22
- package/dist/effect.d.mts +3 -1
- package/dist/effect.mjs +3 -1
- package/dist/engine/reads.mjs +13 -6
- package/dist/engine/walk.mjs +4 -4
- package/dist/event-streams/event-streams.d.mts +1 -1
- package/dist/event-streams/event-streams.mjs +1 -1
- package/dist/event-streams/stream.d.mts +1 -1
- package/dist/event-streams/stream.mjs +1 -1
- package/dist/extend.d.mts +3 -3
- package/dist/extend.mjs +2 -2
- package/dist/http/answers.mjs +4 -2
- package/dist/http/core-parts.mjs +64 -15
- package/dist/http/handler.mjs +2 -2
- package/dist/http/node.mjs +5 -4
- package/dist/http/parts.d.mts +1 -0
- package/dist/http/push-upload-job.mjs +503 -0
- package/dist/http/push-uploads.d.mts +1 -0
- package/dist/http/push-uploads.mjs +114 -56
- package/dist/http/upload-pack.mjs +7 -6
- package/dist/index.d.mts +23 -24
- package/dist/index.mjs +4 -7
- package/dist/lfs/base.d.mts +7 -3
- package/dist/lfs/base.mjs +2 -1
- package/dist/lfs/copy.d.mts +46 -0
- package/dist/lfs/copy.mjs +26 -0
- package/dist/lfs/layer.mjs +4 -2
- package/dist/lfs/objects.d.mts +6 -0
- package/dist/lfs/objects.mjs +68 -41
- package/dist/lfs/rows.d.mts +13 -0
- package/dist/lfs/service.d.mts +1 -7
- package/dist/lfs/service.mjs +1 -9
- package/dist/lfs/upload-most.mjs +5 -5
- package/dist/node.d.mts +2 -2
- package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
- package/dist/protocol/bytes/sha256.d.mts +32 -0
- package/dist/protocol/bytes/sha256.mjs +105 -49
- package/dist/protocol/wire/advertisement.mjs +9 -4
- package/dist/protocol/wire/lines.d.mts +4 -2
- package/dist/protocol/wire/lines.mjs +11 -5
- package/dist/protocol/wire/push-uploads.mjs +13 -1
- package/dist/protocol/wire/v2.mjs +2 -2
- package/dist/protocol.d.mts +3 -1
- package/dist/protocol.mjs +3 -1
- package/dist/queue/advance.mjs +1 -1
- package/dist/queue/host.d.mts +1 -7
- package/dist/queue/host.mjs +1 -7
- package/dist/queue/layer.mjs +1 -1
- package/dist/queue/trim.mjs +1 -1
- package/dist/rest/blobs.d.mts +31 -23
- package/dist/rest/blobs.mjs +1 -1
- package/dist/rest/caller.d.mts +49 -9
- package/dist/rest/caller.mjs +1 -1
- package/dist/rest/client.d.mts +10 -3
- package/dist/rest/client.mjs +4 -0
- package/dist/rest/commits.d.mts +273 -240
- package/dist/rest/errors.d.mts +24 -4
- package/dist/rest/events.d.mts +9 -6
- package/dist/rest/events.mjs +1 -2
- package/dist/rest/files.d.mts +127 -115
- package/dist/rest/forks.d.mts +121 -97
- package/dist/rest/handler.mjs +4 -57
- package/dist/rest/handlers.d.mts +1 -1
- package/dist/rest/handlers.mjs +18 -4
- package/dist/rest/layer.mjs +2 -1
- package/dist/rest/me.d.mts +8 -4
- package/dist/rest/merges.d.mts +8 -4
- package/dist/rest/paths.mjs +1 -0
- package/dist/rest/queue.d.mts +282 -226
- package/dist/rest/refs.d.mts +205 -176
- package/dist/rest/repos.d.mts +108 -80
- package/dist/rest/tags.d.mts +24 -12
- package/dist/rest/tokens.d.mts +235 -211
- package/dist/rest/topics.d.mts +53 -33
- package/dist/rest/trees.d.mts +105 -89
- package/dist/rest/work.d.mts +467 -20
- package/dist/rest/work.mjs +8 -0
- package/dist/server/edge-node.d.mts +9 -13
- package/dist/server/edge-node.mjs +9 -12
- package/dist/server/git-layer.d.mts +1 -6
- package/dist/server/git-layer.mjs +2 -2
- package/dist/server/git-namespace.d.mts +3 -3
- package/dist/server/joined.d.mts +15 -22
- package/dist/server/joined.mjs +5 -29
- package/dist/server/lifecycle.mjs +107 -23
- package/dist/server/registry.mjs +9 -1
- package/dist/server/server.mjs +133 -212
- package/dist/storage/budget.mjs +2 -2
- package/dist/storage/clean-up.mjs +13 -10
- package/dist/storage/fetch.mjs +13 -8
- package/dist/storage/file-limits.mjs +24 -0
- package/dist/storage/index-build.d.mts +1 -0
- package/dist/storage/index-build.mjs +106 -62
- package/dist/storage/index-fetch.mjs +16 -3
- package/dist/storage/index-reach.mjs +33 -5
- package/dist/storage/index-remap.mjs +8 -1
- package/dist/storage/index-shallow.mjs +5 -3
- package/dist/storage/largest-files.mjs +48 -0
- package/dist/storage/lfs-pointers.mjs +10 -1
- package/dist/storage/loose.mjs +3 -1
- package/dist/storage/memory-budget.mjs +28 -4
- package/dist/storage/pack-reads.mjs +8 -8
- package/dist/storage/pack-receive.mjs +83 -25
- package/dist/storage/packs.mjs +37 -21
- package/dist/storage/prune-keep.mjs +203 -34
- package/dist/storage/prune-walk.mjs +54 -16
- package/dist/storage/prune.mjs +629 -196
- package/dist/storage/push-uploads.mjs +36 -12
- package/dist/storage/quarantine.mjs +9 -9
- package/dist/storage/ready.mjs +47 -19
- package/dist/storage/receive-bounds.mjs +29 -8
- package/dist/storage/receive-state.mjs +8 -0
- package/dist/storage/receive-steps.mjs +71 -18
- package/dist/storage/repack.d.mts +1 -1
- package/dist/storage/repack.mjs +1 -8
- package/dist/storage/rows.mjs +12 -1
- package/dist/storage/shallow.d.mts +1 -0
- package/dist/storage/shallow.mjs +26 -4
- package/dist/storage/stream-whole.mjs +5 -2
- package/dist/storage/visible.mjs +29 -1
- package/dist/storage/walk.mjs +2 -1
- package/dist/store/catalogue.mjs +1 -0
- package/dist/store/cursor-seal-namespace.d.mts +2 -0
- package/dist/store/cursor-seal-public.d.mts +5 -0
- package/dist/store/cursor-seal-public.mjs +5 -0
- package/dist/store/cursor-seal.d.mts +16 -2
- package/dist/store/cursor-seal.mjs +26 -14
- package/dist/store/errors.mjs +9 -1
- package/dist/store/records.d.mts +2 -0
- package/dist/store/records.mjs +9 -6
- package/dist/store/repo-record.d.mts +9 -7
- package/dist/store/repo-record.mjs +102 -19
- package/dist/store/scopes.mjs +10 -2
- package/dist/sync/bound.d.mts +2 -0
- package/dist/sync/bound.mjs +11 -2
- package/dist/sync/github.d.mts +6 -1
- package/dist/sync/github.mjs +55 -43
- package/dist/sync/http.mjs +36 -1
- package/dist/sync/import.mjs +1 -0
- package/dist/sync/layer.mjs +6 -2
- package/dist/sync/lfs-batch.mjs +119 -0
- package/dist/sync/lfs-copy.mjs +251 -0
- package/dist/sync/mirror.mjs +210 -137
- package/dist/sync/smart-http.mjs +4 -2
- package/dist/sync/step.mjs +25 -5
- package/dist/sync/tries.mjs +45 -14
- package/dist/sync.d.mts +2 -2
- package/dist/topics/host.mjs +1 -19
- package/dist/topics/layer.mjs +1 -1
- package/package.json +3 -8
- package/dist/auth/bridge.mjs +0 -30
- package/dist/auth/helpers.d.mts +0 -17
- package/dist/core/purge.d.mts +0 -8
- package/dist/core/registered-rows.d.mts +0 -5
- package/dist/core/repack.d.mts +0 -11
- package/dist/http/handler.d.mts +0 -2
- package/dist/rest/handler.d.mts +0 -21
- package/dist/rest.d.mts +0 -2
- package/dist/rest.mjs +0 -1
- package/dist/server/registry.d.mts +0 -16
- package/dist/server/server.d.mts +0 -36
- package/dist/storage/repack-job.d.mts +0 -3
- 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 };
|
package/dist/lfs/layer.mjs
CHANGED
|
@@ -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("
|
|
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));
|
package/dist/lfs/objects.d.mts
CHANGED
|
@@ -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;
|
package/dist/lfs/objects.mjs
CHANGED
|
@@ -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
|
|
341
|
-
*
|
|
342
|
-
*
|
|
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
|
|
360
|
-
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
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,
|
|
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
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
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
|
|
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.
|
|
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
|
-
|
|
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;
|
package/dist/lfs/service.d.mts
CHANGED
|
@@ -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>;
|
package/dist/lfs/service.mjs
CHANGED
|
@@ -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 {
|
|
30
|
+
export { lfsService };
|
package/dist/lfs/upload-most.mjs
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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 {
|
|
1
|
+
import { toNodeHandler, toNodeMiddleware } from "./server/edge-node.mjs";
|
|
2
2
|
import { NodeHandler, NodeMiddleware, NodeNext, NodeRequest, NodeResponse } from "./http/node.mjs";
|
|
3
|
-
export { type
|
|
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
|
|
4
|
-
* they stream past, and
|
|
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
|
|
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
|
|
114
|
+
#words;
|
|
85
115
|
#block = /* @__PURE__ */ new Uint8Array(64);
|
|
86
|
-
#
|
|
87
|
-
#
|
|
88
|
-
#
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
this.#block.set(bytes.subarray(
|
|
95
|
-
this.#filled +=
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.#
|
|
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
|
-
|
|
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
|
-
|
|
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]
|
|
124
|
-
const back15 = w[t - 15]
|
|
125
|
-
const s0 =
|
|
126
|
-
const s1 =
|
|
127
|
-
w[t] =
|
|
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
|
|
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 =
|
|
132
|
-
const
|
|
133
|
-
const
|
|
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
|
|
196
|
+
e = d + first | 0;
|
|
139
197
|
d = c;
|
|
140
198
|
c = b;
|
|
141
199
|
b = a;
|
|
142
|
-
a = first + second
|
|
200
|
+
a = first + second | 0;
|
|
143
201
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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 };
|