@needmoretruth/nmts-cli 0.45.0 → 0.47.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/AGENTS.md +8 -8
- package/CHANGELOG.md +78 -0
- package/README.ko.md +6 -3
- package/README.md +31 -11
- package/dist/api-advice.js +17 -2
- package/dist/api.d.ts +22 -0
- package/dist/api.js +49 -1
- package/dist/arg-options.d.ts +19 -1
- package/dist/args.js +14 -2
- package/dist/artifact-about.d.ts +1 -1
- package/dist/autonomy.js +3 -3
- package/dist/collision.d.ts +20 -3
- package/dist/collision.js +21 -3
- package/dist/commands/erase.js +1 -0
- package/dist/commands/handover.d.ts +15 -0
- package/dist/commands/handover.js +376 -0
- package/dist/commands/heavy-run.d.ts +59 -0
- package/dist/commands/heavy-run.js +247 -0
- package/dist/commands/heavy.d.ts +7 -0
- package/dist/commands/heavy.js +123 -0
- package/dist/commands/link.d.ts +12 -0
- package/dist/commands/link.js +121 -0
- package/dist/commands/ls.d.ts +5 -0
- package/dist/commands/ls.js +9 -1
- package/dist/commands/public-code-manage.d.ts +24 -0
- package/dist/commands/public-code-manage.js +217 -0
- package/dist/commands/public-code.d.ts +12 -1
- package/dist/commands/public-code.js +140 -45
- package/dist/commands/push-heavy.d.ts +6 -0
- package/dist/commands/push-heavy.js +128 -0
- package/dist/commands/push-tree.d.ts +24 -0
- package/dist/commands/push-tree.js +91 -0
- package/dist/commands/push.d.ts +4 -13
- package/dist/commands/push.js +7 -77
- package/dist/commands/put-heavy.d.ts +9 -0
- package/dist/commands/put-heavy.js +120 -0
- package/dist/commands/put-payer.d.ts +21 -0
- package/dist/commands/put-payer.js +24 -0
- package/dist/commands/put.d.ts +2 -2
- package/dist/commands/put.js +8 -7
- package/dist/commands/receive.js +14 -8
- package/dist/commands/s3.js +44 -10
- package/dist/commands/share-dispatch.js +14 -1
- package/dist/commands/share.d.ts +2 -0
- package/dist/commands/share.js +45 -35
- package/dist/commands/shares-sent.js +8 -3
- package/dist/crypto-surface.d.ts +35 -0
- package/dist/crypto-surface.js +13 -0
- package/dist/crypto.d.ts +8 -0
- package/dist/crypto.js +8 -0
- package/dist/download-part.d.ts +32 -1
- package/dist/download-part.js +95 -6
- package/dist/download-range.d.ts +19 -0
- package/dist/download-range.js +108 -0
- package/dist/download-sink.d.ts +15 -0
- package/dist/download.d.ts +14 -0
- package/dist/download.js +19 -4
- package/dist/handover-codes.d.ts +25 -0
- package/dist/handover-codes.js +106 -0
- package/dist/handover.d.ts +62 -0
- package/dist/handover.js +217 -0
- package/dist/heavy-api.d.ts +36 -0
- package/dist/heavy-api.js +107 -0
- package/dist/heavy-copy.d.ts +72 -0
- package/dist/heavy-copy.js +108 -0
- package/dist/heavy-evm.d.ts +20 -0
- package/dist/heavy-evm.js +106 -0
- package/dist/heavy-self-pay.d.ts +92 -0
- package/dist/heavy-self-pay.js +167 -0
- package/dist/heavy-upload.d.ts +87 -0
- package/dist/heavy-upload.js +154 -0
- package/dist/heavy-wallet-pay.d.ts +39 -0
- package/dist/heavy-wallet-pay.js +73 -0
- package/dist/help-options.js +13 -4
- package/dist/help.js +24 -3
- package/dist/links.d.ts +58 -0
- package/dist/links.js +206 -0
- package/dist/list-tier.d.ts +7 -0
- package/dist/list-tier.js +47 -0
- package/dist/main.js +13 -10
- package/dist/manifest-write.d.ts +4 -3
- package/dist/mcp-tools/reads.js +20 -6
- package/dist/mcp-tools/share.js +47 -1
- package/dist/mcp-tools/tiers.js +16 -1
- package/dist/platform-sign.d.ts +4 -4
- package/dist/platform-sign.js +3 -3
- package/dist/portable.d.ts +23 -0
- package/dist/portable.js +19 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/public-code-activity.d.ts +35 -0
- package/dist/public-code-activity.js +88 -0
- package/dist/public-code-refusals.d.ts +25 -0
- package/dist/public-code-refusals.js +87 -0
- package/dist/public-codes.d.ts +76 -0
- package/dist/public-codes.js +182 -0
- package/dist/recovery-build.js +16 -0
- package/dist/recovery-map-part.d.ts +82 -0
- package/dist/recovery-map-part.js +83 -0
- package/dist/recovery-map.d.ts +5 -40
- package/dist/recovery-map.js +18 -1
- package/dist/recovery-source.d.ts +3 -0
- package/dist/recovery-source.js +9 -0
- package/dist/risk.d.ts +55 -1
- package/dist/risk.js +55 -3
- package/dist/run-log.d.ts +1 -1
- package/dist/run-log.js +7 -1
- package/dist/s3/address.d.ts +20 -0
- package/dist/s3/address.js +97 -0
- package/dist/s3/answer.d.ts +48 -0
- package/dist/s3/answer.js +330 -0
- package/dist/s3/body-deframe.d.ts +49 -0
- package/dist/s3/body-deframe.js +264 -0
- package/dist/s3/body-measure.d.ts +13 -0
- package/dist/s3/body-measure.js +48 -0
- package/dist/s3/body-plan.d.ts +31 -0
- package/dist/s3/body-plan.js +159 -0
- package/dist/s3/body.d.ts +46 -0
- package/dist/s3/body.js +117 -0
- package/dist/s3/call.d.ts +36 -0
- package/dist/s3/call.js +42 -0
- package/dist/s3/checksum.d.ts +26 -0
- package/dist/s3/checksum.js +176 -0
- package/dist/s3/content-type.d.ts +3 -0
- package/dist/s3/content-type.js +49 -0
- package/dist/s3/contract.d.ts +91 -14
- package/dist/s3/drive-conditions.d.ts +47 -0
- package/dist/s3/drive-conditions.js +134 -0
- package/dist/s3/drive-key.d.ts +11 -0
- package/dist/s3/drive-key.js +58 -0
- package/dist/s3/drive-limits.d.ts +33 -0
- package/dist/s3/drive-limits.js +53 -0
- package/dist/s3/drive-lock.d.ts +11 -0
- package/dist/s3/drive-lock.js +47 -0
- package/dist/s3/drive-trashed-name.d.ts +13 -0
- package/dist/s3/drive-trashed-name.js +59 -0
- package/dist/s3/drive-write.d.ts +38 -0
- package/dist/s3/drive-write.js +258 -0
- package/dist/s3/drive.d.ts +59 -25
- package/dist/s3/drive.js +46 -77
- package/dist/s3/listing.d.ts +27 -1
- package/dist/s3/listing.js +62 -20
- package/dist/s3/long-answer.d.ts +12 -0
- package/dist/s3/long-answer.js +104 -0
- package/dist/s3/multipart-assemble.d.ts +17 -0
- package/dist/s3/multipart-assemble.js +68 -0
- package/dist/s3/multipart-sweep.d.ts +15 -0
- package/dist/s3/multipart-sweep.js +87 -0
- package/dist/s3/multipart-view.d.ts +45 -0
- package/dist/s3/multipart-view.js +232 -0
- package/dist/s3/multipart.d.ts +26 -19
- package/dist/s3/multipart.js +193 -78
- package/dist/s3/object-read.d.ts +17 -0
- package/dist/s3/object-read.js +127 -0
- package/dist/s3/object-write.d.ts +35 -0
- package/dist/s3/object-write.js +198 -0
- package/dist/s3/range.d.ts +14 -0
- package/dist/s3/range.js +80 -0
- package/dist/s3/response-sink.d.ts +12 -2
- package/dist/s3/response-sink.js +71 -7
- package/dist/s3/routes.d.ts +0 -1
- package/dist/s3/routes.js +242 -217
- package/dist/s3/same-file.d.ts +4 -1
- package/dist/s3/same-file.js +12 -3
- package/dist/s3/server.d.ts +54 -4
- package/dist/s3/server.js +174 -14
- package/dist/s3/sigv4-canonical.d.ts +91 -0
- package/dist/s3/sigv4-canonical.js +148 -0
- package/dist/s3/sigv4-presigned.d.ts +13 -0
- package/dist/s3/sigv4-presigned.js +82 -0
- package/dist/s3/sigv4.d.ts +26 -27
- package/dist/s3/sigv4.js +137 -102
- package/dist/s3/spool.d.ts +37 -0
- package/dist/s3/spool.js +104 -0
- package/dist/s3/staging.d.ts +90 -7
- package/dist/s3/staging.js +97 -66
- package/dist/s3/xml-multipart.d.ts +38 -0
- package/dist/s3/xml-multipart.js +47 -0
- package/dist/s3/xml-read.d.ts +28 -0
- package/dist/s3/xml-read.js +235 -0
- package/dist/s3/xml.d.ts +45 -2
- package/dist/s3/xml.js +72 -13
- package/dist/s3-gateway.d.ts +11 -5
- package/dist/s3-gateway.js +5 -2
- package/dist/seal.d.ts +1 -1
- package/dist/share-codes.d.ts +40 -0
- package/dist/share-codes.js +151 -0
- package/dist/share.d.ts +39 -0
- package/dist/share.js +54 -13
- package/dist/shared/lib/api/types-heavy.d.ts +167 -0
- package/dist/shared/lib/api/types-heavy.js +60 -0
- package/dist/shared/lib/drive/rebuild-verify.js +1 -0
- package/dist/shared/lib/filecoin/providers.d.ts +25 -0
- package/dist/shared/lib/filecoin/providers.js +58 -0
- package/dist/shared/lib/heavy/download.d.ts +48 -0
- package/dist/shared/lib/heavy/download.js +116 -0
- package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
- package/dist/shared/lib/heavy/order-plan.js +83 -0
- package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
- package/dist/shared/lib/heavy/order-runner.js +300 -0
- package/dist/shared/lib/heavy/order-types.d.ts +90 -0
- package/dist/shared/lib/heavy/order-types.js +6 -0
- package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
- package/dist/shared/lib/heavy/order-wire.js +113 -0
- package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
- package/dist/shared/lib/heavy/piece-cid.js +55 -0
- package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
- package/dist/shared/lib/heavy/sp-upload.js +112 -0
- package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
- package/dist/shared/lib/heavy/synapse-piece.js +8 -0
- package/dist/shared/lib/share/handover-format.d.ts +129 -0
- package/dist/shared/lib/share/handover-format.js +323 -0
- package/dist/shared/lib/share/public-link.d.ts +41 -0
- package/dist/shared/lib/share/public-link.js +107 -0
- package/dist/shared/lib/share/shared-file-info.js +1 -0
- package/dist/shared/lib/storage-network.d.ts +4 -4
- package/dist/shared/lib/storage-network.js +7 -7
- package/dist/shared/lib/storage-tier.d.ts +28 -0
- package/dist/shared/lib/storage-tier.js +63 -0
- package/dist/shared/lib/wallet/send-rules.js +1 -0
- package/dist/upload-file.d.ts +8 -0
- package/dist/upload-file.js +57 -25
- package/dist/upload-price-node.d.ts +3 -0
- package/dist/upload-price-node.js +3 -6
- package/dist/upload-price.d.ts +10 -0
- package/dist/upload-price.js +13 -1
- package/dist/upload-run.d.ts +80 -0
- package/dist/upload-run.js +173 -0
- package/dist/upload-steps.js +15 -4
- package/dist/upload-store.d.ts +15 -6
- package/dist/upload-store.js +6 -0
- package/dist/upload-wallet-put.d.ts +9 -4
- package/dist/upload-wallet-put.js +16 -6
- package/dist/upload-wallet.js +4 -0
- package/dist/upload-wire.d.ts +25 -0
- package/dist/upload-wire.js +20 -1
- package/dist/upload.js +28 -13
- package/dist/wallet-sign.js +2 -2
- package/docs/commands/handover.md +54 -0
- package/docs/commands/heavy.md +35 -0
- package/docs/commands/link.md +27 -0
- package/docs/commands/mcp.md +2 -1
- package/docs/commands/public-code.md +25 -6
- package/docs/commands/push.md +4 -1
- package/docs/commands/put.md +15 -1
- package/docs/commands/share.md +8 -3
- package/package.json +5 -2
- package/server.json +2 -2
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +106 -4
- package/vendor/nmts-crypto/nmts_crypto_wasm.js +286 -3
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +12 -1
package/dist/s3/xml.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The XML the S3 protocol answers in.
|
|
2
2
|
//
|
|
3
|
-
// ⛔ WRITTEN BY HAND, ON PURPOSE. Pulling in an XML builder to emit
|
|
3
|
+
// ⛔ WRITTEN BY HAND, ON PURPOSE. Pulling in an XML builder to emit a few fixed shapes would add a
|
|
4
4
|
// dependency to a tool whose whole dependency list is auditable in one screen, and this is the
|
|
5
5
|
// one place where the output is dictated by somebody else's specification -- there is nothing to
|
|
6
6
|
// design, only to match.
|
|
@@ -8,20 +8,47 @@
|
|
|
8
8
|
// ⚠ EVERY VALUE THAT CAME FROM A FILE NAME IS ESCAPED. Names in this drive are whatever a person
|
|
9
9
|
// typed, including `&` and `<`, and an unescaped one produces XML the client cannot parse -- a
|
|
10
10
|
// listing that fails for one badly-named file and works for everything else.
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* What XML 1.0 cannot carry at all, not even as a character reference: the C0 controls other than
|
|
13
|
+
* tab, line feed and carriage return; U+FFFE and U+FFFF; and half of a surrogate pair.
|
|
14
|
+
*/
|
|
15
|
+
const UNCARRIABLE = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]|\p{Cs}/gu;
|
|
16
|
+
/** What stands in for a character XML cannot carry. */
|
|
17
|
+
const REPLACEMENT = "\uFFFD";
|
|
18
|
+
/** `value` with every character no document may contain replaced by U+FFFD. */
|
|
19
|
+
function carriable(value) {
|
|
20
|
+
return value.replace(UNCARRIABLE, REPLACEMENT);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The five characters XML cannot carry raw, escaped -- and what it cannot carry at all, replaced.
|
|
24
|
+
*
|
|
25
|
+
* ⛔ A NAME WITH A CONTROL CHARACTER IN IT MUST NOT BREAK THE DOCUMENT IT IS LISTED IN. `` is no
|
|
26
|
+
* way out: XML 1.0 forbids the reference as it forbids the character, and a parser that meets
|
|
27
|
+
* either refuses the whole listing -- every other file in it along with the one badly named.
|
|
28
|
+
* Such a name is answered with U+FFFD in its place, which the client can at least see; the exact
|
|
29
|
+
* name is what `encoding-type=url` is for, and that path percent-encodes it before it gets here.
|
|
30
|
+
* ⚠ A CARRIAGE RETURN IS LEGAL BUT DOES NOT SURVIVE PARSING: a parser turns it into a line feed,
|
|
31
|
+
* and the client reads a different name from the one stored. As a reference it arrives intact.
|
|
32
|
+
*/
|
|
12
33
|
export function escapeXml(value) {
|
|
13
|
-
return value
|
|
34
|
+
return carriable(value)
|
|
14
35
|
.replace(/&/g, "&")
|
|
15
36
|
.replace(/</g, "<")
|
|
16
37
|
.replace(/>/g, ">")
|
|
17
38
|
.replace(/"/g, """)
|
|
18
|
-
.replace(/'/g, "'")
|
|
39
|
+
.replace(/'/g, "'")
|
|
40
|
+
.replace(/\r/g, "
");
|
|
19
41
|
}
|
|
20
|
-
const HEAD = `<?xml version="1.0" encoding="UTF-8"?>`;
|
|
21
|
-
const NS = `http://s3.amazonaws.com/doc/2006-03-01/`;
|
|
22
|
-
|
|
42
|
+
export const HEAD = `<?xml version="1.0" encoding="UTF-8"?>`;
|
|
43
|
+
export const NS = `http://s3.amazonaws.com/doc/2006-03-01/`;
|
|
44
|
+
/** Who owns and began everything here, as far as a client can be told. */
|
|
45
|
+
export const OWNER = `<ID>nmts</ID><DisplayName>nmts</DisplayName>`;
|
|
46
|
+
/** S3's error document. `requestId` names the answer it belongs to, when there is one to name. */
|
|
47
|
+
export function errorXml(code, message, resource, requestId) {
|
|
23
48
|
return (`${HEAD}<Error><Code>${escapeXml(code)}</Code><Message>${escapeXml(message)}</Message>` +
|
|
24
|
-
`<Resource>${escapeXml(resource)}</Resource
|
|
49
|
+
`<Resource>${escapeXml(resource)}</Resource>` +
|
|
50
|
+
(requestId === undefined ? "" : `<RequestId>${escapeXml(requestId)}</RequestId>`) +
|
|
51
|
+
`</Error>`);
|
|
25
52
|
}
|
|
26
53
|
/**
|
|
27
54
|
* The answer to `ListBuckets`.
|
|
@@ -35,8 +62,8 @@ export function listBucketsXml(buckets, createdAt) {
|
|
|
35
62
|
.map((bucket) => `<Bucket><Name>${escapeXml(bucket)}</Name>` +
|
|
36
63
|
`<CreationDate>${escapeXml(createdAt)}</CreationDate></Bucket>`)
|
|
37
64
|
.join("");
|
|
38
|
-
return (`${HEAD}<ListAllMyBucketsResult xmlns="${NS}"><Owner
|
|
39
|
-
`<
|
|
65
|
+
return (`${HEAD}<ListAllMyBucketsResult xmlns="${NS}"><Owner>${OWNER}</Owner>` +
|
|
66
|
+
`<Buckets>${rows}</Buckets></ListAllMyBucketsResult>`);
|
|
40
67
|
}
|
|
41
68
|
export function initiateUploadXml(bucket, key, uploadId) {
|
|
42
69
|
return (`${HEAD}<InitiateMultipartUploadResult xmlns="${NS}">` +
|
|
@@ -49,9 +76,15 @@ export function completeUploadXml(bucket, key, etag) {
|
|
|
49
76
|
`<Bucket>${escapeXml(bucket)}</Bucket><Key>${escapeXml(key)}</Key>` +
|
|
50
77
|
`<ETag>${escapeXml(etag)}</ETag></CompleteMultipartUploadResult>`);
|
|
51
78
|
}
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
79
|
+
/**
|
|
80
|
+
* `encoding-type=url` means every name in the answer comes back percent-encoded -- control
|
|
81
|
+
* characters included, which is how a client gets such a name exactly.
|
|
82
|
+
*
|
|
83
|
+
* ⚠ HALF A SURROGATE PAIR HAS NO UTF-8 FORM TO PERCENT-ENCODE, and `encodeURIComponent` throws on
|
|
84
|
+
* one; it is replaced first, as `escapeXml` would replace it.
|
|
85
|
+
*/
|
|
86
|
+
export function out(value, encodingType) {
|
|
87
|
+
return escapeXml(encodingType === "url" ? encodeURIComponent(value.replace(/\p{Cs}/gu, REPLACEMENT)) : value);
|
|
55
88
|
}
|
|
56
89
|
export function listObjectsXml(listing) {
|
|
57
90
|
const enc = listing.encodingType;
|
|
@@ -87,3 +120,29 @@ export function listObjectsXml(listing) {
|
|
|
87
120
|
parts.push(`</ListBucketResult>`);
|
|
88
121
|
return parts.join("");
|
|
89
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Where the bucket lives: nowhere a region names.
|
|
125
|
+
*
|
|
126
|
+
* ⚠ EMPTY IS S3'S OWN WAY OF SAYING `us-east-1`, which is what a client that asks should sign
|
|
127
|
+
* with — and this gateway accepts a signature in any region anyway.
|
|
128
|
+
*/
|
|
129
|
+
export function locationXml() {
|
|
130
|
+
return `${HEAD}<LocationConstraint xmlns="${NS}"/>`;
|
|
131
|
+
}
|
|
132
|
+
/** Versioning was never turned on, which S3 answers with an empty configuration. */
|
|
133
|
+
export function versioningXml() {
|
|
134
|
+
return `${HEAD}<VersioningConfiguration xmlns="${NS}"/>`;
|
|
135
|
+
}
|
|
136
|
+
export function copyObjectXml(etag, lastModified) {
|
|
137
|
+
return (`${HEAD}<CopyObjectResult xmlns="${NS}"><LastModified>${escapeXml(lastModified)}</LastModified>` +
|
|
138
|
+
`<ETag>${escapeXml(etag)}</ETag></CopyObjectResult>`);
|
|
139
|
+
}
|
|
140
|
+
/** The answer to `DeleteObjects`. In quiet mode the caller passes no `deleted`, as S3 does. */
|
|
141
|
+
export function deleteResultXml(outcome) {
|
|
142
|
+
const deleted = outcome.deleted.map((key) => `<Deleted><Key>${escapeXml(key)}</Key></Deleted>`).join("");
|
|
143
|
+
const errors = outcome.errors
|
|
144
|
+
.map((e) => `<Error><Key>${escapeXml(e.key)}</Key><Code>${escapeXml(e.code)}</Code>` +
|
|
145
|
+
`<Message>${escapeXml(e.message)}</Message></Error>`)
|
|
146
|
+
.join("");
|
|
147
|
+
return `${HEAD}<DeleteResult xmlns="${NS}">${deleted}${errors}</DeleteResult>`;
|
|
148
|
+
}
|
package/dist/s3-gateway.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
export { createGateway, gatewayHandler } from "./s3/server.ts";
|
|
2
|
-
export type { DriveSource, DriveWriter, GatewayHandler, GatewayOptions } from "./s3/server.ts";
|
|
1
|
+
export { BODY_IDLE_MS, checkContinueHandler, createGateway, failureReasonOf, GATEWAY_SERVER_OPTIONS, gatewayHandler, refusalBeforeBody, watchBodyIdle, } from "./s3/server.ts";
|
|
2
|
+
export type { EarlyRefusal, CopySource, DriveSource, DriveWriter, GatewayHandler, GatewayOptions, StoreOutcome, WriteMeta, } from "./s3/server.ts";
|
|
3
3
|
export { createDriveSource, fetchObject, placeOf, LIST_CACHE_MS } from "./s3/drive.ts";
|
|
4
|
-
export type { DriveAccount, DriveSourceOptions, ObjectReader } from "./s3/drive.ts";
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
4
|
+
export type { DriveAccount, DriveSourceOptions, ObjectReader, StoredFile } from "./s3/drive.ts";
|
|
5
|
+
export { createKeyLocks } from "./s3/drive-lock.ts";
|
|
6
|
+
export type { KeyLocks } from "./s3/drive-lock.ts";
|
|
7
|
+
export { freeTrashedName } from "./s3/drive-trashed-name.ts";
|
|
8
|
+
export { MAX_CONCURRENT_WRITES, MAX_UPLOADS_PER_BUCKET } from "./s3/drive-limits.ts";
|
|
9
|
+
export type { WriteCondition } from "./s3/drive-conditions.ts";
|
|
10
|
+
export type { RemoveOutcome } from "./s3/contract.ts";
|
|
11
|
+
export { createStaging, createStagingStore, SWEEP_EVERY_MS, UPLOAD_LIFETIME_MS } from "./s3/staging.ts";
|
|
12
|
+
export type { CompleteOptions, ObjectChecksum, PartChoice, StagedPart, StagedUpload, Staging, StagingOptions, StagingStore, StoreFile, UploadAccount, } from "./s3/staging.ts";
|
|
7
13
|
export type { GatewayCredential } from "./s3/sigv4.ts";
|
|
8
14
|
export type { DriveObject } from "./s3/listing.ts";
|
package/dist/s3-gateway.js
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
//
|
|
9
9
|
// ⚠ WHAT IS NOT HERE: the bucket name `nmts s3` uses, the address it binds, and the pair it prints
|
|
10
10
|
// when it starts. Those are that command's answers to questions a business answers for itself.
|
|
11
|
-
export { createGateway, gatewayHandler } from "./s3/server.js";
|
|
11
|
+
export { BODY_IDLE_MS, checkContinueHandler, createGateway, failureReasonOf, GATEWAY_SERVER_OPTIONS, gatewayHandler, refusalBeforeBody, watchBodyIdle, } from "./s3/server.js";
|
|
12
12
|
export { createDriveSource, fetchObject, placeOf, LIST_CACHE_MS } from "./s3/drive.js";
|
|
13
|
-
export {
|
|
13
|
+
export { createKeyLocks } from "./s3/drive-lock.js";
|
|
14
|
+
export { freeTrashedName } from "./s3/drive-trashed-name.js";
|
|
15
|
+
export { MAX_CONCURRENT_WRITES, MAX_UPLOADS_PER_BUCKET } from "./s3/drive-limits.js";
|
|
16
|
+
export { createStaging, createStagingStore, SWEEP_EVERY_MS, UPLOAD_LIFETIME_MS } from "./s3/staging.js";
|
package/dist/seal.d.ts
CHANGED
|
@@ -109,7 +109,7 @@ export declare function sealPart(crypt: CryptoGlue, dek: Uint8Array, chunks: Asy
|
|
|
109
109
|
index: number;
|
|
110
110
|
total: number;
|
|
111
111
|
plaintextLen: number;
|
|
112
|
-
}): Promise<Uint8Array
|
|
112
|
+
}): Promise<Uint8Array<ArrayBuffer>>;
|
|
113
113
|
/**
|
|
114
114
|
* Seal a whole file held in memory, as one part.
|
|
115
115
|
*
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type CryptoGlue } from "./crypto.ts";
|
|
2
|
+
import { type ShareKeys, type ShareSealed } from "./share.ts";
|
|
3
|
+
/** The largest number a code may carry — the server keeps it in a signed 32-bit column. */
|
|
4
|
+
export declare const CODE_INDEX_MAX: number;
|
|
5
|
+
/** A code number as a caller wrote it. Refused, never rounded: a neighbouring code is a different one. */
|
|
6
|
+
export declare function requireCodeIndex(value: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* Everything sharing needs for public code number `index` — the same shape `shareKeysOf` answers,
|
|
9
|
+
* which is exactly what it answers for 0. ⛔ The caller wipes it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function shareKeysAt(crypt: CryptoGlue, code: string, index: number): ShareKeys;
|
|
12
|
+
/** The keys of several codes of one NMTS key. */
|
|
13
|
+
export interface ShareKeyRing {
|
|
14
|
+
/** The keys at `index`, made on first use and kept. Not to be wiped by the caller. */
|
|
15
|
+
at(index: number): ShareKeys;
|
|
16
|
+
/** Wipes every key made and the root they grew from. */
|
|
17
|
+
wipe(): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The keys of several codes, from ONE run of the key's derivation, on first use. What stays between
|
|
21
|
+
* uses is code 0's keys and the 32-byte root the other numbers grow from — never the rest of the
|
|
22
|
+
* derivation. ⛔ `wipe()` wipes all of it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function shareKeyRing(crypt: CryptoGlue, code: string): ShareKeyRing;
|
|
25
|
+
/**
|
|
26
|
+
* Open one envelope with whichever of `indices` it was sealed to, trying them in the order given.
|
|
27
|
+
*
|
|
28
|
+
* ⛔ ONE REFUSAL FOR EVERY FAILURE. Which number was tried and how it failed is not something to
|
|
29
|
+
* report: a wrong code, a tampered envelope and a sender who is not who it claims all fail the
|
|
30
|
+
* same way, and saying which would be telling somebody holding the file more than the file says.
|
|
31
|
+
*/
|
|
32
|
+
export declare function openShareAnyCode(crypt: CryptoGlue, code: string, indices: readonly number[], sealed: ShareSealed): {
|
|
33
|
+
dek: Uint8Array;
|
|
34
|
+
index: number;
|
|
35
|
+
};
|
|
36
|
+
/** `openShareAnyCode` with a ring the caller holds, and wipes. */
|
|
37
|
+
export declare function openShareWithRing(crypt: CryptoGlue, ring: ShareKeyRing, indices: readonly number[], sealed: ShareSealed): {
|
|
38
|
+
dek: Uint8Array;
|
|
39
|
+
index: number;
|
|
40
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// The numbered public codes one NMTS key derives (NCF-3 §5.9).
|
|
2
|
+
//
|
|
3
|
+
// ⛔ EVERY NUMBER IS THE SAME KEY'S. Code 0 is the one every account has had from the start and comes
|
|
4
|
+
// straight out of the key's derivation (`shareKeysOf`); code N ≥ 1 is expanded from the 32-byte
|
|
5
|
+
// `shareIdRoot` slice of that derivation. Nothing is stored: the same key gives the same code at
|
|
6
|
+
// the same number on any machine, which is why a revoked code's shares still open here.
|
|
7
|
+
//
|
|
8
|
+
// ⛔ A SHARE NAMES NO RECIPIENT NUMBER. The received listing says which code the server filed a share
|
|
9
|
+
// under, and a handover file does not say at all, so `openShareAnyCode` tries the numbers it is
|
|
10
|
+
// given in order. A wrong number fails exactly as any other refusal does, so trying several
|
|
11
|
+
// weakens nothing.
|
|
12
|
+
//
|
|
13
|
+
// ⚠ THE KEY'S DERIVATION IS THE SLOW STEP — seconds, on purpose — and every number grows from its
|
|
14
|
+
// output. So anything that touches more than one number goes through ONE ring (`shareKeyRing`),
|
|
15
|
+
// which runs it once; `shareKeysAt` runs it for a single number.
|
|
16
|
+
import { DERIVED } from "./crypto.js";
|
|
17
|
+
import { NmtsError } from "./errors.js";
|
|
18
|
+
import { shareKeysFromDerived, shareKeysOf, unwrapWith } from "./share.js";
|
|
19
|
+
const IDENTITY_LEN = 4989;
|
|
20
|
+
const SEED_LEN = 32;
|
|
21
|
+
/** The largest number a code may carry — the server keeps it in a signed 32-bit column. */
|
|
22
|
+
export const CODE_INDEX_MAX = 2 ** 31 - 2;
|
|
23
|
+
/** A code number as a caller wrote it. Refused, never rounded: a neighbouring code is a different one. */
|
|
24
|
+
export function requireCodeIndex(value) {
|
|
25
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > CODE_INDEX_MAX) {
|
|
26
|
+
throw new NmtsError(`A public code's number is a whole number from 0 to ${CODE_INDEX_MAX}.`, { exitCode: 2 });
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
/** Keys at N ≥ 1 from an already-sliced `shareIdRoot`. The caller wipes the root. */
|
|
31
|
+
function keysFromRoot(crypt, root, index) {
|
|
32
|
+
const seeds = crypt.share_id_seeds(root, index);
|
|
33
|
+
const kemSeed = seeds.slice(0, SEED_LEN);
|
|
34
|
+
const authSecret = seeds.slice(SEED_LEN, 2 * SEED_LEN);
|
|
35
|
+
const sigSeed = seeds.slice(2 * SEED_LEN, 3 * SEED_LEN);
|
|
36
|
+
seeds.fill(0);
|
|
37
|
+
const wipe = () => {
|
|
38
|
+
kemSeed.fill(0);
|
|
39
|
+
authSecret.fill(0);
|
|
40
|
+
sigSeed.fill(0);
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
const identity = crypt.share_public_key_at(kemSeed, authSecret, sigSeed, index);
|
|
44
|
+
if (identity.length !== IDENTITY_LEN) {
|
|
45
|
+
throw new NmtsError(`Public code #${index}'s identity came out ${identity.length} bytes.`, {
|
|
46
|
+
nextStep: "Nothing was sent. The crypto engine and this tool disagree about the format.",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const address = crypt.share_address_at(sigSeed, index);
|
|
50
|
+
return { index, kemSeed, authSecret, sigSeed, address, identity, display: crypt.share_address_display(address), wipe };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
wipe();
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Run `body` with this key's `shareIdRoot`, wiped after. */
|
|
58
|
+
function withShareIdRoot(crypt, code, body) {
|
|
59
|
+
const derived = crypt.kdf_derive(crypt.account_code_parse(code));
|
|
60
|
+
const root = derived.slice(DERIVED.shareIdRoot[0], DERIVED.shareIdRoot[1]);
|
|
61
|
+
derived.fill(0);
|
|
62
|
+
try {
|
|
63
|
+
return body(root);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
root.fill(0);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Everything sharing needs for public code number `index` — the same shape `shareKeysOf` answers,
|
|
71
|
+
* which is exactly what it answers for 0. ⛔ The caller wipes it.
|
|
72
|
+
*/
|
|
73
|
+
export function shareKeysAt(crypt, code, index) {
|
|
74
|
+
requireCodeIndex(index);
|
|
75
|
+
if (index === 0)
|
|
76
|
+
return shareKeysOf(crypt, code);
|
|
77
|
+
return withShareIdRoot(crypt, code, (root) => keysFromRoot(crypt, root, index));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The keys of several codes, from ONE run of the key's derivation, on first use. What stays between
|
|
81
|
+
* uses is code 0's keys and the 32-byte root the other numbers grow from — never the rest of the
|
|
82
|
+
* derivation. ⛔ `wipe()` wipes all of it.
|
|
83
|
+
*/
|
|
84
|
+
export function shareKeyRing(crypt, code) {
|
|
85
|
+
const held = new Map();
|
|
86
|
+
let root = null;
|
|
87
|
+
const rootOf = () => {
|
|
88
|
+
if (root !== null)
|
|
89
|
+
return root;
|
|
90
|
+
const derived = crypt.kdf_derive(crypt.account_code_parse(code));
|
|
91
|
+
try {
|
|
92
|
+
held.set(0, shareKeysFromDerived(crypt, derived));
|
|
93
|
+
const made = derived.slice(DERIVED.shareIdRoot[0], DERIVED.shareIdRoot[1]);
|
|
94
|
+
root = made;
|
|
95
|
+
return made;
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
derived.fill(0);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
at(index) {
|
|
103
|
+
requireCodeIndex(index);
|
|
104
|
+
const from = rootOf();
|
|
105
|
+
const had = held.get(index);
|
|
106
|
+
if (had !== undefined)
|
|
107
|
+
return had;
|
|
108
|
+
const made = keysFromRoot(crypt, from, index);
|
|
109
|
+
held.set(index, made);
|
|
110
|
+
return made;
|
|
111
|
+
},
|
|
112
|
+
wipe() {
|
|
113
|
+
for (const keys of held.values())
|
|
114
|
+
keys.wipe();
|
|
115
|
+
held.clear();
|
|
116
|
+
root?.fill(0);
|
|
117
|
+
root = null;
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Open one envelope with whichever of `indices` it was sealed to, trying them in the order given.
|
|
123
|
+
*
|
|
124
|
+
* ⛔ ONE REFUSAL FOR EVERY FAILURE. Which number was tried and how it failed is not something to
|
|
125
|
+
* report: a wrong code, a tampered envelope and a sender who is not who it claims all fail the
|
|
126
|
+
* same way, and saying which would be telling somebody holding the file more than the file says.
|
|
127
|
+
*/
|
|
128
|
+
export function openShareAnyCode(crypt, code, indices, sealed) {
|
|
129
|
+
const ring = shareKeyRing(crypt, code);
|
|
130
|
+
try {
|
|
131
|
+
return openShareWithRing(crypt, ring, indices, sealed);
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
ring.wipe();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** `openShareAnyCode` with a ring the caller holds, and wipes. */
|
|
138
|
+
export function openShareWithRing(crypt, ring, indices, sealed) {
|
|
139
|
+
for (const index of indices) {
|
|
140
|
+
try {
|
|
141
|
+
return { dek: unwrapWith(crypt, ring.at(index), sealed), index };
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// The next number, or the one refusal below.
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
throw new NmtsError("It did not open with any of this account's public codes.", {
|
|
148
|
+
exitCode: 1,
|
|
149
|
+
nextStep: "Nothing was opened. The sender can seal it again to a public code this account holds.",
|
|
150
|
+
});
|
|
151
|
+
}
|
package/dist/share.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ import { type CryptoGlue } from "./crypto.ts";
|
|
|
7
7
|
* failures.
|
|
8
8
|
*/
|
|
9
9
|
export interface ShareKeys {
|
|
10
|
+
/**
|
|
11
|
+
* Which of this key's numbered public codes these are (NCF-3 §5.9). 0 is the code every account
|
|
12
|
+
* has had from the start; `share-codes.ts` derives the others.
|
|
13
|
+
*/
|
|
14
|
+
index: number;
|
|
10
15
|
/** Key-agreement seed. */
|
|
11
16
|
kemSeed: Uint8Array;
|
|
12
17
|
/** Proves this account SENT a share. */
|
|
@@ -23,6 +28,8 @@ export interface ShareKeys {
|
|
|
23
28
|
}
|
|
24
29
|
/** Derive everything sharing needs from an NMTS key. */
|
|
25
30
|
export declare function shareKeysOf(crypt: CryptoGlue, code: string): ShareKeys;
|
|
31
|
+
/** Code 0's keys out of one run of the key's derivation. The caller wipes `derived`. */
|
|
32
|
+
export declare function shareKeysFromDerived(crypt: CryptoGlue, derived: Uint8Array): ShareKeys;
|
|
26
33
|
/** The three sealed fields a share carries, base64url, exactly as they go to the server. */
|
|
27
34
|
export interface SharePayload {
|
|
28
35
|
dek_share_ct: string;
|
|
@@ -51,6 +58,11 @@ export declare function sealShare(crypt: CryptoGlue, input: {
|
|
|
51
58
|
size: number;
|
|
52
59
|
/** The file's whole-plaintext digest, opened from the account's own sealed copy. */
|
|
53
60
|
digest: Uint8Array;
|
|
61
|
+
/**
|
|
62
|
+
* The name document to seal in place of the share's own — a handover's, which also binds its
|
|
63
|
+
* parts list and network (NCF-3 §5.6). A built-in share never passes one.
|
|
64
|
+
*/
|
|
65
|
+
nameDocument?: string;
|
|
54
66
|
}): SharePayload;
|
|
55
67
|
/** One row of what somebody shared with this account, as the server describes it. */
|
|
56
68
|
export interface ReceivedRow {
|
|
@@ -59,11 +71,20 @@ export interface ReceivedRow {
|
|
|
59
71
|
/** Bytes on the storage network — NOT the file's length. The sealed document has that. */
|
|
60
72
|
size: number;
|
|
61
73
|
sender_public_key?: string;
|
|
74
|
+
/** Which of this account's public codes it was sent to. Absent from an older server: code 0. */
|
|
75
|
+
to_index?: number;
|
|
76
|
+
/** Whether the sender has revoked the code it was sent from. */
|
|
77
|
+
sender_code_revoked?: boolean;
|
|
62
78
|
dek_share_ct: string;
|
|
63
79
|
name_share_ct: string;
|
|
64
80
|
content_hash_share_ct: string;
|
|
65
81
|
created_at: string;
|
|
66
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Which of this account's codes a received row came to. A number the server should never send —
|
|
85
|
+
* negative, fractional, past a code's range — reads as 0, where the open then fails and says so.
|
|
86
|
+
*/
|
|
87
|
+
export declare function receivedIndex(row: ReceivedRow): number;
|
|
67
88
|
/** What a received share turns into once opened, or why it could not be. */
|
|
68
89
|
export interface OpenedShare {
|
|
69
90
|
id: string;
|
|
@@ -75,6 +96,9 @@ export interface OpenedShare {
|
|
|
75
96
|
size: number | null;
|
|
76
97
|
/** The sender's address, in readable form — only ever set when the open SUCCEEDED. */
|
|
77
98
|
sender: string | null;
|
|
99
|
+
/** Which of this account's public codes it came to, and whether the sender revoked theirs. */
|
|
100
|
+
toIndex: number;
|
|
101
|
+
senderRevoked: boolean;
|
|
78
102
|
/** The file's own key. Present only when it opened; the caller wipes it. */
|
|
79
103
|
dek: Uint8Array | null;
|
|
80
104
|
/** The sealed digest, carried through so a download can check the bytes. */
|
|
@@ -90,6 +114,21 @@ export interface OpenedShare {
|
|
|
90
114
|
* line — not to leave a gap somebody has no way to notice.
|
|
91
115
|
*/
|
|
92
116
|
export declare function openReceived(crypt: CryptoGlue, keys: ShareKeys, row: ReceivedRow): OpenedShare;
|
|
117
|
+
/** The sealed parts of one share that its recipient opens with. */
|
|
118
|
+
export interface ShareSealed {
|
|
119
|
+
senderPublic: Uint8Array;
|
|
120
|
+
envelope: Uint8Array;
|
|
121
|
+
itemId: string;
|
|
122
|
+
nameCt: Uint8Array;
|
|
123
|
+
digestCt: Uint8Array;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Open one envelope with one of this account's codes. Throws when it will not open.
|
|
127
|
+
*
|
|
128
|
+
* ⚠ THE RECIPIENT'S NUMBER IS PART OF WHAT OPENS IT, so the keys must be the code it was sent to:
|
|
129
|
+
* code 0 through the engine's first form, any other through its numbered one.
|
|
130
|
+
*/
|
|
131
|
+
export declare function unwrapWith(crypt: CryptoGlue, keys: ShareKeys, s: ShareSealed): Uint8Array;
|
|
93
132
|
/** The digest a recipient checks the downloaded bytes against. */
|
|
94
133
|
export declare function openSharedDigest(crypt: CryptoGlue, dek: Uint8Array, digestCt: string): Uint8Array | null;
|
|
95
134
|
/**
|
package/dist/share.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// made by the account it names. The claimed sender is therefore printed only AFTER the open
|
|
17
17
|
// succeeds — before that it is a claim, and printing a claim as a fact is how somebody trusts
|
|
18
18
|
// a file that was not sent by who it says.
|
|
19
|
+
import { fromBase64Url, toBase64Url } from "./bytes.js";
|
|
19
20
|
import { AAD, DERIVED } from "./crypto.js";
|
|
20
21
|
import { NmtsError } from "./errors.js";
|
|
21
22
|
import { decodeSharedFileInfo, encodeSharedFileInfo, } from "./shared/lib/share/shared-file-info.js";
|
|
@@ -27,12 +28,20 @@ const IDENTITY_LEN = 4989;
|
|
|
27
28
|
/** Derive everything sharing needs from an NMTS key. */
|
|
28
29
|
export function shareKeysOf(crypt, code) {
|
|
29
30
|
const derived = crypt.kdf_derive(crypt.account_code_parse(code));
|
|
31
|
+
try {
|
|
32
|
+
return shareKeysFromDerived(crypt, derived);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
derived.fill(0);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Code 0's keys out of one run of the key's derivation. The caller wipes `derived`. */
|
|
39
|
+
export function shareKeysFromDerived(crypt, derived) {
|
|
30
40
|
const slice = (range) => derived.slice(range[0], range[1]);
|
|
31
41
|
const kemSeed = slice(DERIVED.shareKemSeed);
|
|
32
42
|
const authSecret = slice(DERIVED.shareAuthSecret);
|
|
33
43
|
const sigSeed = slice(DERIVED.shareSigSeed);
|
|
34
44
|
const address = slice(DERIVED.shareAddress);
|
|
35
|
-
derived.fill(0);
|
|
36
45
|
const identity = crypt.share_public_key(kemSeed, authSecret, sigSeed);
|
|
37
46
|
if (identity.length !== IDENTITY_LEN) {
|
|
38
47
|
throw new NmtsError(`This account's sharing identity came out ${identity.length} bytes.`, {
|
|
@@ -40,6 +49,7 @@ export function shareKeysOf(crypt, code) {
|
|
|
40
49
|
});
|
|
41
50
|
}
|
|
42
51
|
return {
|
|
52
|
+
index: 0,
|
|
43
53
|
kemSeed,
|
|
44
54
|
authSecret,
|
|
45
55
|
sigSeed,
|
|
@@ -70,21 +80,34 @@ export function sealShare(crypt, input) {
|
|
|
70
80
|
});
|
|
71
81
|
}
|
|
72
82
|
// ⛔ SEALED FIRST, AND THESE EXACT BYTES ARE WHAT GETS SENT. See the module note.
|
|
73
|
-
const nameCt = crypt.envelope_seal(input.dek, encoder.encode(AAD.shareName), encoder.encode(encodeSharedFileInfo({ name: input.name, size: input.size })));
|
|
83
|
+
const nameCt = crypt.envelope_seal(input.dek, encoder.encode(AAD.shareName), encoder.encode(input.nameDocument ?? encodeSharedFileInfo({ name: input.name, size: input.size })));
|
|
74
84
|
const digestCt = crypt.envelope_seal(input.dek, encoder.encode(AAD.shareContentHash), input.digest);
|
|
75
85
|
if (digestCt.length !== DIGEST_ENVELOPE_LEN) {
|
|
76
86
|
throw new NmtsError(`A sealed content hash came out ${digestCt.length} bytes.`);
|
|
77
87
|
}
|
|
78
|
-
|
|
88
|
+
// ⚠ THE SENDER'S NUMBER IS INSIDE THE ENVELOPE: it names which of this key's codes sent it, so a
|
|
89
|
+
// code other than 0 wraps through the engine's numbered form.
|
|
90
|
+
const k = input.keys;
|
|
91
|
+
const envelope = k.index === 0
|
|
92
|
+
? crypt.share_wrap_dek(k.authSecret, k.sigSeed, input.recipientIdentity, input.recipientAddress, input.dek, input.itemId, nameCt, digestCt)
|
|
93
|
+
: crypt.share_wrap_dek_as(k.authSecret, k.sigSeed, k.index, input.recipientIdentity, input.recipientAddress, input.dek, input.itemId, nameCt, digestCt);
|
|
79
94
|
if (envelope.length !== ENVELOPE_LEN) {
|
|
80
95
|
throw new NmtsError(`A share envelope came out ${envelope.length} bytes.`);
|
|
81
96
|
}
|
|
82
97
|
return {
|
|
83
|
-
dek_share_ct:
|
|
84
|
-
name_share_ct:
|
|
85
|
-
content_hash_share_ct:
|
|
98
|
+
dek_share_ct: toBase64Url(envelope),
|
|
99
|
+
name_share_ct: toBase64Url(nameCt),
|
|
100
|
+
content_hash_share_ct: toBase64Url(digestCt),
|
|
86
101
|
};
|
|
87
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Which of this account's codes a received row came to. A number the server should never send —
|
|
105
|
+
* negative, fractional, past a code's range — reads as 0, where the open then fails and says so.
|
|
106
|
+
*/
|
|
107
|
+
export function receivedIndex(row) {
|
|
108
|
+
const n = row.to_index;
|
|
109
|
+
return typeof n === "number" && Number.isSafeInteger(n) && n >= 0 && n <= 2 ** 31 - 2 ? n : 0;
|
|
110
|
+
}
|
|
88
111
|
/**
|
|
89
112
|
* Open one received share.
|
|
90
113
|
*
|
|
@@ -98,6 +121,8 @@ export function openReceived(crypt, keys, row) {
|
|
|
98
121
|
itemId: row.item_id,
|
|
99
122
|
createdAt: row.created_at,
|
|
100
123
|
digestCt: row.content_hash_share_ct,
|
|
124
|
+
toIndex: receivedIndex(row),
|
|
125
|
+
senderRevoked: row.sender_code_revoked === true,
|
|
101
126
|
};
|
|
102
127
|
const unopened = (problem) => ({
|
|
103
128
|
...base,
|
|
@@ -112,13 +137,17 @@ export function openReceived(crypt, keys, row) {
|
|
|
112
137
|
// authenticate against, and an unauthenticated open is not one worth doing.
|
|
113
138
|
return unopened("the sender's published identity is not available");
|
|
114
139
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
140
|
+
// ⚠ Decoded inside the try: a row whose fields are not base64 is a row that will not open, and it
|
|
141
|
+
// is still listed.
|
|
142
|
+
let envelope = new Uint8Array(0);
|
|
143
|
+
let nameCt = new Uint8Array(0);
|
|
119
144
|
let dek;
|
|
120
145
|
try {
|
|
121
|
-
|
|
146
|
+
envelope = fromBase64Url(row.dek_share_ct);
|
|
147
|
+
nameCt = fromBase64Url(row.name_share_ct);
|
|
148
|
+
const digestCt = fromBase64Url(row.content_hash_share_ct);
|
|
149
|
+
const senderPublic = fromBase64Url(row.sender_public_key);
|
|
150
|
+
dek = unwrapWith(crypt, keys, { senderPublic, envelope, itemId: row.item_id, nameCt, digestCt });
|
|
122
151
|
}
|
|
123
152
|
catch {
|
|
124
153
|
return unopened("it did not open with this account's keys");
|
|
@@ -150,10 +179,21 @@ export function openReceived(crypt, keys, row) {
|
|
|
150
179
|
problem: null,
|
|
151
180
|
};
|
|
152
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Open one envelope with one of this account's codes. Throws when it will not open.
|
|
184
|
+
*
|
|
185
|
+
* ⚠ THE RECIPIENT'S NUMBER IS PART OF WHAT OPENS IT, so the keys must be the code it was sent to:
|
|
186
|
+
* code 0 through the engine's first form, any other through its numbered one.
|
|
187
|
+
*/
|
|
188
|
+
export function unwrapWith(crypt, keys, s) {
|
|
189
|
+
return keys.index === 0
|
|
190
|
+
? crypt.share_unwrap_dek(keys.kemSeed, keys.authSecret, keys.sigSeed, s.senderPublic, s.envelope, s.itemId, s.nameCt, s.digestCt)
|
|
191
|
+
: crypt.share_unwrap_dek_as(keys.kemSeed, keys.authSecret, keys.sigSeed, keys.index, s.senderPublic, s.envelope, s.itemId, s.nameCt, s.digestCt);
|
|
192
|
+
}
|
|
153
193
|
/** The digest a recipient checks the downloaded bytes against. */
|
|
154
194
|
export function openSharedDigest(crypt, dek, digestCt) {
|
|
155
195
|
try {
|
|
156
|
-
return crypt.envelope_open(dek, encoder.encode(AAD.shareContentHash),
|
|
196
|
+
return crypt.envelope_open(dek, encoder.encode(AAD.shareContentHash), fromBase64Url(digestCt));
|
|
157
197
|
}
|
|
158
198
|
catch {
|
|
159
199
|
return null;
|
|
@@ -187,7 +227,8 @@ export function identityMatches(crypt, identity, address) {
|
|
|
187
227
|
if (identity.length !== IDENTITY_LEN)
|
|
188
228
|
return false;
|
|
189
229
|
try {
|
|
190
|
-
|
|
230
|
+
const fingerprint = crypt.share_address_of(identity);
|
|
231
|
+
return fingerprint.length === address.length && fingerprint.every((byte, at) => byte === address[at]);
|
|
191
232
|
}
|
|
192
233
|
catch {
|
|
193
234
|
return false;
|