@tinycloud/cli 0.9.1-beta.4 → 0.9.1-beta.6
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/README.md +8 -0
- package/dist/index.js +588 -161
- package/dist/index.js.map +1 -1
- package/dist/legacy-entry.js +391 -76
- package/dist/legacy-entry.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
tinycloudConfigPath,
|
|
38
38
|
tinycloudHomePath
|
|
39
39
|
} from "@tinycloud/operations/state";
|
|
40
|
-
var CONFIG_DIR, PROFILES_DIR, CONFIG_FILE, DEFAULT_HOST, DEFAULT_PROFILE, ExitCode;
|
|
40
|
+
var CONFIG_DIR, PROFILES_DIR, CONFIG_FILE, DEFAULT_HOST, DEFAULT_OPENKEY_HOST, DEFAULT_PROFILE, DEFAULT_CHAIN_ID, ExitCode;
|
|
41
41
|
var init_constants = __esm({
|
|
42
42
|
"src/config/constants.ts"() {
|
|
43
43
|
"use strict";
|
|
@@ -45,7 +45,9 @@ var init_constants = __esm({
|
|
|
45
45
|
PROFILES_DIR = profilesPath();
|
|
46
46
|
CONFIG_FILE = tinycloudConfigPath();
|
|
47
47
|
DEFAULT_HOST = "https://node.tinycloud.xyz";
|
|
48
|
+
DEFAULT_OPENKEY_HOST = "https://openkey.so";
|
|
48
49
|
DEFAULT_PROFILE = "default";
|
|
50
|
+
DEFAULT_CHAIN_ID = 1;
|
|
49
51
|
ExitCode = {
|
|
50
52
|
SUCCESS: 0,
|
|
51
53
|
ERROR: 1,
|
|
@@ -6163,7 +6165,7 @@ function eddsa(Point2, cHash, eddsaOpts = {}) {
|
|
|
6163
6165
|
});
|
|
6164
6166
|
const { prehash } = eddsaOpts;
|
|
6165
6167
|
const { BASE, Fp: Fp2, Fn: Fn2 } = Point2;
|
|
6166
|
-
const
|
|
6168
|
+
const randomBytes5 = eddsaOpts.randomBytes || randomBytes;
|
|
6167
6169
|
const adjustScalarBytes2 = eddsaOpts.adjustScalarBytes || ((bytes3) => bytes3);
|
|
6168
6170
|
const domain = eddsaOpts.domain || ((data, ctx, phflag) => {
|
|
6169
6171
|
_abool2(phflag, "phflag");
|
|
@@ -6245,7 +6247,7 @@ function eddsa(Point2, cHash, eddsaOpts = {}) {
|
|
|
6245
6247
|
signature: 2 * _size,
|
|
6246
6248
|
seed: _size
|
|
6247
6249
|
};
|
|
6248
|
-
function randomSecretKey(seed =
|
|
6250
|
+
function randomSecretKey(seed = randomBytes5(lengths.seed)) {
|
|
6249
6251
|
return _abytes2(seed, lengths.seed, "seed");
|
|
6250
6252
|
}
|
|
6251
6253
|
function keygen(seed) {
|
|
@@ -9068,7 +9070,7 @@ function weierstrass(curveDef) {
|
|
|
9068
9070
|
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
9069
9071
|
if (["recovered", "canonical"].some((k) => k in opts))
|
|
9070
9072
|
throw new Error("sign() legacy options not supported");
|
|
9071
|
-
const { hash, randomBytes:
|
|
9073
|
+
const { hash, randomBytes: randomBytes5 } = CURVE;
|
|
9072
9074
|
let { lowS, prehash, extraEntropy: ent } = opts;
|
|
9073
9075
|
if (lowS == null)
|
|
9074
9076
|
lowS = true;
|
|
@@ -9080,7 +9082,7 @@ function weierstrass(curveDef) {
|
|
|
9080
9082
|
const d = normPrivateKeyToScalar(privateKey);
|
|
9081
9083
|
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
9082
9084
|
if (ent != null && ent !== false) {
|
|
9083
|
-
const e = ent === true ?
|
|
9085
|
+
const e = ent === true ? randomBytes5(Fp2.BYTES) : ent;
|
|
9084
9086
|
seedArgs.push(ensureBytes2("extraEntropy", e));
|
|
9085
9087
|
}
|
|
9086
9088
|
const seed = concatBytes3(...seedArgs);
|
|
@@ -14705,7 +14707,7 @@ var init_dist2 = __esm({
|
|
|
14705
14707
|
async handleErrorResponse(response, operation) {
|
|
14706
14708
|
const errorText = await response.text();
|
|
14707
14709
|
const errorBody = parseServiceErrorBody(errorText);
|
|
14708
|
-
const
|
|
14710
|
+
const errorCode2 = this.mapHttpStatusToErrorCode(
|
|
14709
14711
|
response.status,
|
|
14710
14712
|
errorBody.error
|
|
14711
14713
|
);
|
|
@@ -14723,7 +14725,7 @@ var init_dist2 = __esm({
|
|
|
14723
14725
|
if (resource) meta.resource = resource;
|
|
14724
14726
|
}
|
|
14725
14727
|
return err(
|
|
14726
|
-
serviceError(
|
|
14728
|
+
serviceError(errorCode2, message, "sql", { meta })
|
|
14727
14729
|
);
|
|
14728
14730
|
}
|
|
14729
14731
|
mapHttpStatusToErrorCode(status, serverError) {
|
|
@@ -15053,7 +15055,7 @@ var init_dist2 = __esm({
|
|
|
15053
15055
|
async handleErrorResponse(response, operation) {
|
|
15054
15056
|
const errorText = await response.text();
|
|
15055
15057
|
const errorBody = parseServiceErrorBody(errorText);
|
|
15056
|
-
const
|
|
15058
|
+
const errorCode2 = this.mapHttpStatusToErrorCode(
|
|
15057
15059
|
response.status,
|
|
15058
15060
|
errorBody.error
|
|
15059
15061
|
);
|
|
@@ -15071,7 +15073,7 @@ var init_dist2 = __esm({
|
|
|
15071
15073
|
if (resource) meta.resource = resource;
|
|
15072
15074
|
}
|
|
15073
15075
|
return err(
|
|
15074
|
-
serviceError(
|
|
15076
|
+
serviceError(errorCode2, message, "duckdb", { meta })
|
|
15075
15077
|
);
|
|
15076
15078
|
}
|
|
15077
15079
|
mapHttpStatusToErrorCode(status, serverError) {
|
|
@@ -17501,25 +17503,25 @@ function encodeTo(int, target, offset = 0) {
|
|
|
17501
17503
|
function encodingLength(int) {
|
|
17502
17504
|
return varint_default.encodingLength(int);
|
|
17503
17505
|
}
|
|
17504
|
-
function create(code222,
|
|
17505
|
-
const size2 =
|
|
17506
|
+
function create(code222, digest42) {
|
|
17507
|
+
const size2 = digest42.byteLength;
|
|
17506
17508
|
const sizeOffset = encodingLength(code222);
|
|
17507
17509
|
const digestOffset = sizeOffset + encodingLength(size2);
|
|
17508
17510
|
const bytes3 = new Uint8Array(digestOffset + size2);
|
|
17509
17511
|
encodeTo(code222, bytes3, 0);
|
|
17510
17512
|
encodeTo(size2, bytes3, sizeOffset);
|
|
17511
|
-
bytes3.set(
|
|
17512
|
-
return new Digest(code222, size2,
|
|
17513
|
+
bytes3.set(digest42, digestOffset);
|
|
17514
|
+
return new Digest(code222, size2, digest42, bytes3);
|
|
17513
17515
|
}
|
|
17514
17516
|
function decode4(multihash) {
|
|
17515
17517
|
const bytes3 = coerce22(multihash);
|
|
17516
17518
|
const [code222, sizeOffset] = decode3(bytes3);
|
|
17517
17519
|
const [size2, digestOffset] = decode3(bytes3.subarray(sizeOffset));
|
|
17518
|
-
const
|
|
17519
|
-
if (
|
|
17520
|
+
const digest42 = bytes3.subarray(sizeOffset + digestOffset);
|
|
17521
|
+
if (digest42.byteLength !== size2) {
|
|
17520
17522
|
throw new Error("Incorrect length");
|
|
17521
17523
|
}
|
|
17522
|
-
return new Digest(code222, size2,
|
|
17524
|
+
return new Digest(code222, size2, digest42, bytes3);
|
|
17523
17525
|
}
|
|
17524
17526
|
function equals2(a, b) {
|
|
17525
17527
|
if (a === b) {
|
|
@@ -17612,8 +17614,8 @@ function encodeCID(version3, code222, multihash) {
|
|
|
17612
17614
|
return bytes3;
|
|
17613
17615
|
}
|
|
17614
17616
|
async function computeCid(bytes3) {
|
|
17615
|
-
const
|
|
17616
|
-
return CID.create(1, code,
|
|
17617
|
+
const digest42 = create(SHA256_CODE, sha256(new Uint8Array(bytes3)));
|
|
17618
|
+
return CID.create(1, code, digest42).toString();
|
|
17617
17619
|
}
|
|
17618
17620
|
function isCanonicalRawCid(cidString) {
|
|
17619
17621
|
let cid2;
|
|
@@ -18254,8 +18256,8 @@ async function verifyEnvelopeV3(envelope, options) {
|
|
|
18254
18256
|
const expectedBindingDigestHex = hex(sha2562(new TextEncoder().encode(canonicalize2({ enforcerDid: binding.enforcerDid, nodeAudience: binding.nodeAudience }))));
|
|
18255
18257
|
if (binding.enforcerDid !== parsed.target.nodeAudience || binding.attestationBindingDigestHex !== expectedBindingDigestHex || bindingSignature.signerDid !== binding.nodeAudience || bindingSignature.suite !== "Ed25519" || Date.parse(binding.issuedAt) > Date.now() || Date.parse(binding.expiresAt) <= Date.now() || Date.parse(binding.expiresAt) < Date.parse(parsed.expiry)) return false;
|
|
18256
18258
|
try {
|
|
18257
|
-
const
|
|
18258
|
-
if (!ed25519.verify(fromBase64Url(bindingSignature.value),
|
|
18259
|
+
const digest42 = sha2562(new TextEncoder().encode(`${ATTESTED_ENFORCER_V2_DOMAIN}${canonicalize2(unsignedBinding)}`));
|
|
18260
|
+
if (!ed25519.verify(fromBase64Url(bindingSignature.value), digest42, ed25519PublicKeyFromDidKey(binding.nodeAudience), ED25519_VERIFY_OPTS2)) return false;
|
|
18259
18261
|
} catch {
|
|
18260
18262
|
return false;
|
|
18261
18263
|
}
|
|
@@ -19265,25 +19267,25 @@ function encodeTo2(int, target, offset = 0) {
|
|
|
19265
19267
|
function encodingLength2(int) {
|
|
19266
19268
|
return varint_default2.encodingLength(int);
|
|
19267
19269
|
}
|
|
19268
|
-
function create2(code32,
|
|
19269
|
-
const size2 =
|
|
19270
|
+
function create2(code32, digest42) {
|
|
19271
|
+
const size2 = digest42.byteLength;
|
|
19270
19272
|
const sizeOffset = encodingLength2(code32);
|
|
19271
19273
|
const digestOffset = sizeOffset + encodingLength2(size2);
|
|
19272
19274
|
const bytes3 = new Uint8Array(digestOffset + size2);
|
|
19273
19275
|
encodeTo2(code32, bytes3, 0);
|
|
19274
19276
|
encodeTo2(size2, bytes3, sizeOffset);
|
|
19275
|
-
bytes3.set(
|
|
19276
|
-
return new Digest2(code32, size2,
|
|
19277
|
+
bytes3.set(digest42, digestOffset);
|
|
19278
|
+
return new Digest2(code32, size2, digest42, bytes3);
|
|
19277
19279
|
}
|
|
19278
19280
|
function decode8(multihash) {
|
|
19279
19281
|
const bytes3 = coerce3(multihash);
|
|
19280
19282
|
const [code32, sizeOffset] = decode7(bytes3);
|
|
19281
19283
|
const [size2, digestOffset] = decode7(bytes3.subarray(sizeOffset));
|
|
19282
|
-
const
|
|
19283
|
-
if (
|
|
19284
|
+
const digest42 = bytes3.subarray(sizeOffset + digestOffset);
|
|
19285
|
+
if (digest42.byteLength !== size2) {
|
|
19284
19286
|
throw new Error("Incorrect length");
|
|
19285
19287
|
}
|
|
19286
|
-
return new Digest2(code32, size2,
|
|
19288
|
+
return new Digest2(code32, size2, digest42, bytes3);
|
|
19287
19289
|
}
|
|
19288
19290
|
function equals4(a, b) {
|
|
19289
19291
|
if (a === b) {
|
|
@@ -20110,11 +20112,11 @@ async function notifyShare(input) {
|
|
|
20110
20112
|
}
|
|
20111
20113
|
async function defaultIdempotencyKey(shareId, recipient) {
|
|
20112
20114
|
const canonicalRecipient = canonicalize2(recipient.trim().toLowerCase());
|
|
20113
|
-
const
|
|
20115
|
+
const digest42 = new Uint8Array(await crypto.subtle.digest(
|
|
20114
20116
|
"SHA-256",
|
|
20115
20117
|
new TextEncoder().encode(canonicalRecipient)
|
|
20116
20118
|
));
|
|
20117
|
-
return `tinycloud-share:${shareId}:${toBase64Url(
|
|
20119
|
+
return `tinycloud-share:${shareId}:${toBase64Url(digest42)}`;
|
|
20118
20120
|
}
|
|
20119
20121
|
function targetKind2(record2) {
|
|
20120
20122
|
if (record2.targetKind !== void 0) return record2.targetKind;
|
|
@@ -24415,10 +24417,10 @@ var init_dist3 = __esm({
|
|
|
24415
24417
|
/**
|
|
24416
24418
|
* Creates a multihash digest.
|
|
24417
24419
|
*/
|
|
24418
|
-
constructor(code222, size2,
|
|
24420
|
+
constructor(code222, size2, digest42, bytes3) {
|
|
24419
24421
|
this.code = code222;
|
|
24420
24422
|
this.size = size2;
|
|
24421
|
-
this.digest =
|
|
24423
|
+
this.digest = digest42;
|
|
24422
24424
|
this.bytes = bytes3;
|
|
24423
24425
|
}
|
|
24424
24426
|
};
|
|
@@ -24481,8 +24483,8 @@ var init_dist3 = __esm({
|
|
|
24481
24483
|
toV1() {
|
|
24482
24484
|
switch (this.version) {
|
|
24483
24485
|
case 0: {
|
|
24484
|
-
const { code: code222, digest:
|
|
24485
|
-
const multihash = create(code222,
|
|
24486
|
+
const { code: code222, digest: digest42 } = this.multihash;
|
|
24487
|
+
const multihash = create(code222, digest42);
|
|
24486
24488
|
return _CID.createV1(this.code, multihash);
|
|
24487
24489
|
}
|
|
24488
24490
|
case 1: {
|
|
@@ -24536,8 +24538,8 @@ var init_dist3 = __esm({
|
|
|
24536
24538
|
return new _CID(version3, code222, multihash, bytes3 ?? encodeCID(version3, code222, multihash.bytes));
|
|
24537
24539
|
} else if (value[cidSymbol] === true) {
|
|
24538
24540
|
const { version: version3, multihash, code: code222 } = value;
|
|
24539
|
-
const
|
|
24540
|
-
return _CID.create(version3, code222,
|
|
24541
|
+
const digest42 = decode4(multihash);
|
|
24542
|
+
return _CID.create(version3, code222, digest42);
|
|
24541
24543
|
} else {
|
|
24542
24544
|
return null;
|
|
24543
24545
|
}
|
|
@@ -24547,11 +24549,11 @@ var init_dist3 = __esm({
|
|
|
24547
24549
|
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
24548
24550
|
* @param digest - (Multi)hash of the of the content.
|
|
24549
24551
|
*/
|
|
24550
|
-
static create(version3, code222,
|
|
24552
|
+
static create(version3, code222, digest42) {
|
|
24551
24553
|
if (typeof code222 !== "number") {
|
|
24552
24554
|
throw new Error("String codecs are no longer supported");
|
|
24553
24555
|
}
|
|
24554
|
-
if (!(
|
|
24556
|
+
if (!(digest42.bytes instanceof Uint8Array)) {
|
|
24555
24557
|
throw new Error("Invalid digest");
|
|
24556
24558
|
}
|
|
24557
24559
|
switch (version3) {
|
|
@@ -24559,12 +24561,12 @@ var init_dist3 = __esm({
|
|
|
24559
24561
|
if (code222 !== DAG_PB_CODE) {
|
|
24560
24562
|
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
24561
24563
|
} else {
|
|
24562
|
-
return new _CID(version3, code222,
|
|
24564
|
+
return new _CID(version3, code222, digest42, digest42.bytes);
|
|
24563
24565
|
}
|
|
24564
24566
|
}
|
|
24565
24567
|
case 1: {
|
|
24566
|
-
const bytes3 = encodeCID(version3, code222,
|
|
24567
|
-
return new _CID(version3, code222,
|
|
24568
|
+
const bytes3 = encodeCID(version3, code222, digest42.bytes);
|
|
24569
|
+
return new _CID(version3, code222, digest42, bytes3);
|
|
24568
24570
|
}
|
|
24569
24571
|
default: {
|
|
24570
24572
|
throw new Error("Invalid version");
|
|
@@ -24574,8 +24576,8 @@ var init_dist3 = __esm({
|
|
|
24574
24576
|
/**
|
|
24575
24577
|
* Simplified version of `create` for CIDv0.
|
|
24576
24578
|
*/
|
|
24577
|
-
static createV0(
|
|
24578
|
-
return _CID.create(0, DAG_PB_CODE,
|
|
24579
|
+
static createV0(digest42) {
|
|
24580
|
+
return _CID.create(0, DAG_PB_CODE, digest42);
|
|
24579
24581
|
}
|
|
24580
24582
|
/**
|
|
24581
24583
|
* Simplified version of `create` for CIDv1.
|
|
@@ -24583,8 +24585,8 @@ var init_dist3 = __esm({
|
|
|
24583
24585
|
* @param code - Content encoding format code.
|
|
24584
24586
|
* @param digest - Multihash of the content.
|
|
24585
24587
|
*/
|
|
24586
|
-
static createV1(code222,
|
|
24587
|
-
return _CID.create(1, code222,
|
|
24588
|
+
static createV1(code222, digest42) {
|
|
24589
|
+
return _CID.create(1, code222, digest42);
|
|
24588
24590
|
}
|
|
24589
24591
|
/**
|
|
24590
24592
|
* Decoded a CID from its binary representation. The byte array must contain
|
|
@@ -24617,8 +24619,8 @@ var init_dist3 = __esm({
|
|
|
24617
24619
|
throw new Error("Incorrect length");
|
|
24618
24620
|
}
|
|
24619
24621
|
const digestBytes3 = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
24620
|
-
const
|
|
24621
|
-
const cid2 = specs.version === 0 ? _CID.createV0(
|
|
24622
|
+
const digest42 = new Digest(specs.multihashCode, specs.digestSize, digestBytes3, multihashBytes);
|
|
24623
|
+
const cid2 = specs.version === 0 ? _CID.createV0(digest42) : _CID.createV1(specs.codec, digest42);
|
|
24622
24624
|
return [cid2, bytes3.subarray(specs.size)];
|
|
24623
24625
|
}
|
|
24624
24626
|
/**
|
|
@@ -25265,10 +25267,10 @@ var init_dist3 = __esm({
|
|
|
25265
25267
|
/**
|
|
25266
25268
|
* Creates a multihash digest.
|
|
25267
25269
|
*/
|
|
25268
|
-
constructor(code32, size2,
|
|
25270
|
+
constructor(code32, size2, digest42, bytes3) {
|
|
25269
25271
|
this.code = code32;
|
|
25270
25272
|
this.size = size2;
|
|
25271
|
-
this.digest =
|
|
25273
|
+
this.digest = digest42;
|
|
25272
25274
|
this.bytes = bytes3;
|
|
25273
25275
|
}
|
|
25274
25276
|
};
|
|
@@ -25331,8 +25333,8 @@ var init_dist3 = __esm({
|
|
|
25331
25333
|
toV1() {
|
|
25332
25334
|
switch (this.version) {
|
|
25333
25335
|
case 0: {
|
|
25334
|
-
const { code: code32, digest:
|
|
25335
|
-
const multihash = create2(code32,
|
|
25336
|
+
const { code: code32, digest: digest42 } = this.multihash;
|
|
25337
|
+
const multihash = create2(code32, digest42);
|
|
25336
25338
|
return _CID2.createV1(this.code, multihash);
|
|
25337
25339
|
}
|
|
25338
25340
|
case 1: {
|
|
@@ -25386,8 +25388,8 @@ var init_dist3 = __esm({
|
|
|
25386
25388
|
return new _CID2(version3, code32, multihash, bytes3 ?? encodeCID2(version3, code32, multihash.bytes));
|
|
25387
25389
|
} else if (value[cidSymbol2] === true) {
|
|
25388
25390
|
const { version: version3, multihash, code: code32 } = value;
|
|
25389
|
-
const
|
|
25390
|
-
return _CID2.create(version3, code32,
|
|
25391
|
+
const digest42 = decode8(multihash);
|
|
25392
|
+
return _CID2.create(version3, code32, digest42);
|
|
25391
25393
|
} else {
|
|
25392
25394
|
return null;
|
|
25393
25395
|
}
|
|
@@ -25397,11 +25399,11 @@ var init_dist3 = __esm({
|
|
|
25397
25399
|
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
25398
25400
|
* @param digest - (Multi)hash of the of the content.
|
|
25399
25401
|
*/
|
|
25400
|
-
static create(version3, code32,
|
|
25402
|
+
static create(version3, code32, digest42) {
|
|
25401
25403
|
if (typeof code32 !== "number") {
|
|
25402
25404
|
throw new Error("String codecs are no longer supported");
|
|
25403
25405
|
}
|
|
25404
|
-
if (!(
|
|
25406
|
+
if (!(digest42.bytes instanceof Uint8Array)) {
|
|
25405
25407
|
throw new Error("Invalid digest");
|
|
25406
25408
|
}
|
|
25407
25409
|
switch (version3) {
|
|
@@ -25409,12 +25411,12 @@ var init_dist3 = __esm({
|
|
|
25409
25411
|
if (code32 !== DAG_PB_CODE2) {
|
|
25410
25412
|
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE2}) block encoding`);
|
|
25411
25413
|
} else {
|
|
25412
|
-
return new _CID2(version3, code32,
|
|
25414
|
+
return new _CID2(version3, code32, digest42, digest42.bytes);
|
|
25413
25415
|
}
|
|
25414
25416
|
}
|
|
25415
25417
|
case 1: {
|
|
25416
|
-
const bytes3 = encodeCID2(version3, code32,
|
|
25417
|
-
return new _CID2(version3, code32,
|
|
25418
|
+
const bytes3 = encodeCID2(version3, code32, digest42.bytes);
|
|
25419
|
+
return new _CID2(version3, code32, digest42, bytes3);
|
|
25418
25420
|
}
|
|
25419
25421
|
default: {
|
|
25420
25422
|
throw new Error("Invalid version");
|
|
@@ -25424,8 +25426,8 @@ var init_dist3 = __esm({
|
|
|
25424
25426
|
/**
|
|
25425
25427
|
* Simplified version of `create` for CIDv0.
|
|
25426
25428
|
*/
|
|
25427
|
-
static createV0(
|
|
25428
|
-
return _CID2.create(0, DAG_PB_CODE2,
|
|
25429
|
+
static createV0(digest42) {
|
|
25430
|
+
return _CID2.create(0, DAG_PB_CODE2, digest42);
|
|
25429
25431
|
}
|
|
25430
25432
|
/**
|
|
25431
25433
|
* Simplified version of `create` for CIDv1.
|
|
@@ -25433,8 +25435,8 @@ var init_dist3 = __esm({
|
|
|
25433
25435
|
* @param code - Content encoding format code.
|
|
25434
25436
|
* @param digest - Multihash of the content.
|
|
25435
25437
|
*/
|
|
25436
|
-
static createV1(code32,
|
|
25437
|
-
return _CID2.create(1, code32,
|
|
25438
|
+
static createV1(code32, digest42) {
|
|
25439
|
+
return _CID2.create(1, code32, digest42);
|
|
25438
25440
|
}
|
|
25439
25441
|
/**
|
|
25440
25442
|
* Decoded a CID from its binary representation. The byte array must contain
|
|
@@ -25467,8 +25469,8 @@ var init_dist3 = __esm({
|
|
|
25467
25469
|
throw new Error("Incorrect length");
|
|
25468
25470
|
}
|
|
25469
25471
|
const digestBytes3 = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
25470
|
-
const
|
|
25471
|
-
const cid2 = specs.version === 0 ? _CID2.createV0(
|
|
25472
|
+
const digest42 = new Digest2(specs.multihashCode, specs.digestSize, digestBytes3, multihashBytes);
|
|
25473
|
+
const cid2 = specs.version === 0 ? _CID2.createV0(digest42) : _CID2.createV1(specs.codec, digest42);
|
|
25472
25474
|
return [cid2, bytes3.subarray(specs.size)];
|
|
25473
25475
|
}
|
|
25474
25476
|
/**
|
|
@@ -26179,25 +26181,25 @@ function encodeTo3(int, target, offset = 0) {
|
|
|
26179
26181
|
function encodingLength3(int) {
|
|
26180
26182
|
return varint_default3.encodingLength(int);
|
|
26181
26183
|
}
|
|
26182
|
-
function create3(code32,
|
|
26183
|
-
const size2 =
|
|
26184
|
+
function create3(code32, digest42) {
|
|
26185
|
+
const size2 = digest42.byteLength;
|
|
26184
26186
|
const sizeOffset = encodingLength3(code32);
|
|
26185
26187
|
const digestOffset = sizeOffset + encodingLength3(size2);
|
|
26186
26188
|
const bytes22 = new Uint8Array(digestOffset + size2);
|
|
26187
26189
|
encodeTo3(code32, bytes22, 0);
|
|
26188
26190
|
encodeTo3(size2, bytes22, sizeOffset);
|
|
26189
|
-
bytes22.set(
|
|
26190
|
-
return new Digest3(code32, size2,
|
|
26191
|
+
bytes22.set(digest42, digestOffset);
|
|
26192
|
+
return new Digest3(code32, size2, digest42, bytes22);
|
|
26191
26193
|
}
|
|
26192
26194
|
function decode42(multihash) {
|
|
26193
26195
|
const bytes22 = coerce4(multihash);
|
|
26194
26196
|
const [code32, sizeOffset] = decode32(bytes22);
|
|
26195
26197
|
const [size2, digestOffset] = decode32(bytes22.subarray(sizeOffset));
|
|
26196
|
-
const
|
|
26197
|
-
if (
|
|
26198
|
+
const digest42 = bytes22.subarray(sizeOffset + digestOffset);
|
|
26199
|
+
if (digest42.byteLength !== size2) {
|
|
26198
26200
|
throw new Error("Incorrect length");
|
|
26199
26201
|
}
|
|
26200
|
-
return new Digest3(code32, size2,
|
|
26202
|
+
return new Digest3(code32, size2, digest42, bytes22);
|
|
26201
26203
|
}
|
|
26202
26204
|
function equals22(a, b) {
|
|
26203
26205
|
if (a === b) {
|
|
@@ -26322,14 +26324,14 @@ function digest2(input, options2) {
|
|
|
26322
26324
|
function from22({ name: name2, code: code32, encode: encode52, minDigestLength, maxDigestLength }) {
|
|
26323
26325
|
return new Hasher(name2, code32, encode52, minDigestLength, maxDigestLength);
|
|
26324
26326
|
}
|
|
26325
|
-
function createDigest(
|
|
26326
|
-
if (truncate != null && truncate !==
|
|
26327
|
-
if (truncate >
|
|
26328
|
-
throw new Error(`Invalid truncate option, must be less than or equal to ${
|
|
26327
|
+
function createDigest(digest42, code32, truncate) {
|
|
26328
|
+
if (truncate != null && truncate !== digest42.byteLength) {
|
|
26329
|
+
if (truncate > digest42.byteLength) {
|
|
26330
|
+
throw new Error(`Invalid truncate option, must be less than or equal to ${digest42.byteLength}`);
|
|
26329
26331
|
}
|
|
26330
|
-
|
|
26332
|
+
digest42 = digest42.subarray(0, truncate);
|
|
26331
26333
|
}
|
|
26332
|
-
return create3(code32,
|
|
26334
|
+
return create3(code32, digest42);
|
|
26333
26335
|
}
|
|
26334
26336
|
function sha(name2) {
|
|
26335
26337
|
return async (data) => new Uint8Array(await crypto.subtle.digest(name2, data));
|
|
@@ -27639,14 +27641,14 @@ var init_dist4 = __esm({
|
|
|
27639
27641
|
/**
|
|
27640
27642
|
* Creates a multihash digest.
|
|
27641
27643
|
*/
|
|
27642
|
-
constructor(code32, size2,
|
|
27644
|
+
constructor(code32, size2, digest42, bytes22) {
|
|
27643
27645
|
__publicField(this, "code");
|
|
27644
27646
|
__publicField(this, "size");
|
|
27645
27647
|
__publicField(this, "digest");
|
|
27646
27648
|
__publicField(this, "bytes");
|
|
27647
27649
|
this.code = code32;
|
|
27648
27650
|
this.size = size2;
|
|
27649
|
-
this.digest =
|
|
27651
|
+
this.digest = digest42;
|
|
27650
27652
|
this.bytes = bytes22;
|
|
27651
27653
|
}
|
|
27652
27654
|
};
|
|
@@ -27710,8 +27712,8 @@ var init_dist4 = __esm({
|
|
|
27710
27712
|
toV1() {
|
|
27711
27713
|
switch (this.version) {
|
|
27712
27714
|
case 0: {
|
|
27713
|
-
const { code: code32, digest:
|
|
27714
|
-
const multihash = create3(code32,
|
|
27715
|
+
const { code: code32, digest: digest42 } = this.multihash;
|
|
27716
|
+
const multihash = create3(code32, digest42);
|
|
27715
27717
|
return _CID3.createV1(this.code, multihash);
|
|
27716
27718
|
}
|
|
27717
27719
|
case 1: {
|
|
@@ -27764,8 +27766,8 @@ var init_dist4 = __esm({
|
|
|
27764
27766
|
return new _CID3(version3, code32, multihash, bytes22 ?? encodeCID3(version3, code32, multihash.bytes));
|
|
27765
27767
|
} else if (value[cidSymbol3] === true) {
|
|
27766
27768
|
const { version: version3, multihash, code: code32 } = value;
|
|
27767
|
-
const
|
|
27768
|
-
return _CID3.create(version3, code32,
|
|
27769
|
+
const digest42 = decode42(multihash);
|
|
27770
|
+
return _CID3.create(version3, code32, digest42);
|
|
27769
27771
|
} else {
|
|
27770
27772
|
return null;
|
|
27771
27773
|
}
|
|
@@ -27775,11 +27777,11 @@ var init_dist4 = __esm({
|
|
|
27775
27777
|
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
27776
27778
|
* @param digest - (Multi)hash of the of the content.
|
|
27777
27779
|
*/
|
|
27778
|
-
static create(version3, code32,
|
|
27780
|
+
static create(version3, code32, digest42) {
|
|
27779
27781
|
if (typeof code32 !== "number") {
|
|
27780
27782
|
throw new Error("String codecs are no longer supported");
|
|
27781
27783
|
}
|
|
27782
|
-
if (!(
|
|
27784
|
+
if (!(digest42.bytes instanceof Uint8Array)) {
|
|
27783
27785
|
throw new Error("Invalid digest");
|
|
27784
27786
|
}
|
|
27785
27787
|
switch (version3) {
|
|
@@ -27787,12 +27789,12 @@ var init_dist4 = __esm({
|
|
|
27787
27789
|
if (code32 !== DAG_PB_CODE3) {
|
|
27788
27790
|
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE3}) block encoding`);
|
|
27789
27791
|
} else {
|
|
27790
|
-
return new _CID3(version3, code32,
|
|
27792
|
+
return new _CID3(version3, code32, digest42, digest42.bytes);
|
|
27791
27793
|
}
|
|
27792
27794
|
}
|
|
27793
27795
|
case 1: {
|
|
27794
|
-
const bytes22 = encodeCID3(version3, code32,
|
|
27795
|
-
return new _CID3(version3, code32,
|
|
27796
|
+
const bytes22 = encodeCID3(version3, code32, digest42.bytes);
|
|
27797
|
+
return new _CID3(version3, code32, digest42, bytes22);
|
|
27796
27798
|
}
|
|
27797
27799
|
default: {
|
|
27798
27800
|
throw new Error("Invalid version");
|
|
@@ -27802,8 +27804,8 @@ var init_dist4 = __esm({
|
|
|
27802
27804
|
/**
|
|
27803
27805
|
* Simplified version of `create` for CIDv0.
|
|
27804
27806
|
*/
|
|
27805
|
-
static createV0(
|
|
27806
|
-
return _CID3.create(0, DAG_PB_CODE3,
|
|
27807
|
+
static createV0(digest42) {
|
|
27808
|
+
return _CID3.create(0, DAG_PB_CODE3, digest42);
|
|
27807
27809
|
}
|
|
27808
27810
|
/**
|
|
27809
27811
|
* Simplified version of `create` for CIDv1.
|
|
@@ -27811,8 +27813,8 @@ var init_dist4 = __esm({
|
|
|
27811
27813
|
* @param code - Content encoding format code.
|
|
27812
27814
|
* @param digest - Multihash of the content.
|
|
27813
27815
|
*/
|
|
27814
|
-
static createV1(code32,
|
|
27815
|
-
return _CID3.create(1, code32,
|
|
27816
|
+
static createV1(code32, digest42) {
|
|
27817
|
+
return _CID3.create(1, code32, digest42);
|
|
27816
27818
|
}
|
|
27817
27819
|
/**
|
|
27818
27820
|
* Decoded a CID from its binary representation. The byte array must contain
|
|
@@ -27845,8 +27847,8 @@ var init_dist4 = __esm({
|
|
|
27845
27847
|
throw new Error("Incorrect length");
|
|
27846
27848
|
}
|
|
27847
27849
|
const digestBytes3 = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
27848
|
-
const
|
|
27849
|
-
const cid2 = specs.version === 0 ? _CID3.createV0(
|
|
27850
|
+
const digest42 = new Digest3(specs.multihashCode, specs.digestSize, digestBytes3, multihashBytes);
|
|
27851
|
+
const cid2 = specs.version === 0 ? _CID3.createV0(digest42) : _CID3.createV1(specs.codec, digest42);
|
|
27850
27852
|
return [cid2, bytes22.subarray(specs.size)];
|
|
27851
27853
|
}
|
|
27852
27854
|
/**
|
|
@@ -28075,7 +28077,7 @@ var init_dist4 = __esm({
|
|
|
28075
28077
|
if (result instanceof Uint8Array) {
|
|
28076
28078
|
return createDigest(result, this.code, options2?.truncate);
|
|
28077
28079
|
}
|
|
28078
|
-
return result.then((
|
|
28080
|
+
return result.then((digest42) => createDigest(digest42, this.code, options2?.truncate));
|
|
28079
28081
|
} else {
|
|
28080
28082
|
throw Error("Unknown type, must be binary type");
|
|
28081
28083
|
}
|
|
@@ -30656,6 +30658,385 @@ var init_sdk = __esm({
|
|
|
30656
30658
|
}
|
|
30657
30659
|
});
|
|
30658
30660
|
|
|
30661
|
+
// src/auth/local-key.ts
|
|
30662
|
+
import { TCWSessionManager, importKey, initPanicHook } from "@tinycloud/node-sdk-wasm";
|
|
30663
|
+
import { PrivateKeySigner } from "@tinycloud/node-sdk";
|
|
30664
|
+
import { randomBytes as randomBytes3 } from "crypto";
|
|
30665
|
+
function ensureWasm() {
|
|
30666
|
+
if (!wasmInitialized) {
|
|
30667
|
+
initPanicHook();
|
|
30668
|
+
wasmInitialized = true;
|
|
30669
|
+
}
|
|
30670
|
+
}
|
|
30671
|
+
function generateKey2() {
|
|
30672
|
+
ensureWasm();
|
|
30673
|
+
const mgr = new TCWSessionManager();
|
|
30674
|
+
const keyId = mgr.createSessionKey("cli");
|
|
30675
|
+
const jwkStr = mgr.jwk(keyId);
|
|
30676
|
+
if (!jwkStr) throw new Error("Failed to generate key");
|
|
30677
|
+
const jwk = JSON.parse(jwkStr);
|
|
30678
|
+
const did = mgr.getDID(keyId);
|
|
30679
|
+
return { jwk, did };
|
|
30680
|
+
}
|
|
30681
|
+
function keyToDID(jwk) {
|
|
30682
|
+
ensureWasm();
|
|
30683
|
+
const mgr = new TCWSessionManager();
|
|
30684
|
+
const keyId = importKey(mgr, JSON.stringify(jwk), "imported");
|
|
30685
|
+
return mgr.getDID(keyId);
|
|
30686
|
+
}
|
|
30687
|
+
var wasmInitialized;
|
|
30688
|
+
var init_local_key = __esm({
|
|
30689
|
+
"src/auth/local-key.ts"() {
|
|
30690
|
+
"use strict";
|
|
30691
|
+
wasmInitialized = false;
|
|
30692
|
+
}
|
|
30693
|
+
});
|
|
30694
|
+
|
|
30695
|
+
// src/auth/browser-auth.ts
|
|
30696
|
+
import { createServer } from "http";
|
|
30697
|
+
import { createInterface } from "readline";
|
|
30698
|
+
function publicJwkForDelegation(jwk) {
|
|
30699
|
+
const publicJwk = {};
|
|
30700
|
+
for (const [key, value] of Object.entries(jwk)) {
|
|
30701
|
+
if (!PRIVATE_JWK_FIELDS.has(key)) {
|
|
30702
|
+
publicJwk[key] = value;
|
|
30703
|
+
}
|
|
30704
|
+
}
|
|
30705
|
+
return publicJwk;
|
|
30706
|
+
}
|
|
30707
|
+
function validateDelegationCallbackPayload(value) {
|
|
30708
|
+
if (!value || typeof value !== "object") return "expected an object";
|
|
30709
|
+
const v = value;
|
|
30710
|
+
if (!v.delegationHeader || typeof v.delegationHeader !== "object") {
|
|
30711
|
+
return "delegationHeader must be an object";
|
|
30712
|
+
}
|
|
30713
|
+
const auth = v.delegationHeader.Authorization;
|
|
30714
|
+
if (typeof auth !== "string" || !auth) {
|
|
30715
|
+
return "delegationHeader.Authorization must be a non-empty string";
|
|
30716
|
+
}
|
|
30717
|
+
if (typeof v.delegationCid !== "string" || !v.delegationCid) {
|
|
30718
|
+
return "delegationCid must be a non-empty string";
|
|
30719
|
+
}
|
|
30720
|
+
if (typeof v.spaceId !== "string" || !v.spaceId) {
|
|
30721
|
+
return "spaceId must be a non-empty string";
|
|
30722
|
+
}
|
|
30723
|
+
if (v.permissions !== void 0) {
|
|
30724
|
+
if (!Array.isArray(v.permissions)) {
|
|
30725
|
+
return "permissions, when present, must be an array";
|
|
30726
|
+
}
|
|
30727
|
+
for (let i = 0; i < v.permissions.length; i++) {
|
|
30728
|
+
const entry = v.permissions[i];
|
|
30729
|
+
if (!entry || typeof entry !== "object") {
|
|
30730
|
+
return `permissions[${i}] must be an object`;
|
|
30731
|
+
}
|
|
30732
|
+
const e = entry;
|
|
30733
|
+
if (typeof e.service !== "string" || !e.service) {
|
|
30734
|
+
return `permissions[${i}].service must be a non-empty string`;
|
|
30735
|
+
}
|
|
30736
|
+
if (typeof e.space !== "string") {
|
|
30737
|
+
return `permissions[${i}].space must be a string`;
|
|
30738
|
+
}
|
|
30739
|
+
if (typeof e.path !== "string") {
|
|
30740
|
+
return `permissions[${i}].path must be a string`;
|
|
30741
|
+
}
|
|
30742
|
+
if (!Array.isArray(e.actions) || e.actions.some((a) => typeof a !== "string" || !a)) {
|
|
30743
|
+
return `permissions[${i}].actions must be a non-empty string[]`;
|
|
30744
|
+
}
|
|
30745
|
+
}
|
|
30746
|
+
}
|
|
30747
|
+
return null;
|
|
30748
|
+
}
|
|
30749
|
+
var PRIVATE_JWK_FIELDS;
|
|
30750
|
+
var init_browser_auth = __esm({
|
|
30751
|
+
"src/auth/browser-auth.ts"() {
|
|
30752
|
+
"use strict";
|
|
30753
|
+
init_formatter();
|
|
30754
|
+
init_constants();
|
|
30755
|
+
PRIVATE_JWK_FIELDS = /* @__PURE__ */ new Set([
|
|
30756
|
+
"d",
|
|
30757
|
+
"p",
|
|
30758
|
+
"q",
|
|
30759
|
+
"dp",
|
|
30760
|
+
"dq",
|
|
30761
|
+
"qi",
|
|
30762
|
+
"oth",
|
|
30763
|
+
"k"
|
|
30764
|
+
]);
|
|
30765
|
+
}
|
|
30766
|
+
});
|
|
30767
|
+
|
|
30768
|
+
// src/auth/device-auth.ts
|
|
30769
|
+
var device_auth_exports = {};
|
|
30770
|
+
__export(device_auth_exports, {
|
|
30771
|
+
SHARE_DEVICE_DELEGATION_SECONDS: () => SHARE_DEVICE_DELEGATION_SECONDS,
|
|
30772
|
+
SHARE_DEVICE_PERMISSIONS: () => SHARE_DEVICE_PERMISSIONS,
|
|
30773
|
+
acquireShareDeviceDelegation: () => acquireShareDeviceDelegation,
|
|
30774
|
+
ensureShareDeviceAuthorization: () => ensureShareDeviceAuthorization,
|
|
30775
|
+
mergePrivateJwkIntoSession: () => mergePrivateJwkIntoSession
|
|
30776
|
+
});
|
|
30777
|
+
import {
|
|
30778
|
+
createDecipheriv,
|
|
30779
|
+
createHash,
|
|
30780
|
+
createHmac,
|
|
30781
|
+
createPublicKey,
|
|
30782
|
+
diffieHellman,
|
|
30783
|
+
generateKeyPairSync,
|
|
30784
|
+
randomBytes as randomBytes4
|
|
30785
|
+
} from "crypto";
|
|
30786
|
+
function digest4(value) {
|
|
30787
|
+
return createHash("sha256").update(value).digest("base64url");
|
|
30788
|
+
}
|
|
30789
|
+
function canonicalOrigin(value, label) {
|
|
30790
|
+
const url = new URL(value);
|
|
30791
|
+
const loopback = url.hostname === "127.0.0.1" || url.hostname === "localhost";
|
|
30792
|
+
if (url.origin !== value || url.protocol !== "https:" && !(loopback && url.protocol === "http:")) {
|
|
30793
|
+
throw new Error(`${label} must be a canonical HTTPS origin`);
|
|
30794
|
+
}
|
|
30795
|
+
return value;
|
|
30796
|
+
}
|
|
30797
|
+
function jsonEqual(left, right) {
|
|
30798
|
+
const canonical = (value) => Array.isArray(value) ? value.map(canonical) : value && typeof value === "object" ? Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, entry]) => [key, canonical(entry)])) : value;
|
|
30799
|
+
return JSON.stringify(canonical(left)) === JSON.stringify(canonical(right));
|
|
30800
|
+
}
|
|
30801
|
+
function validateStart(value) {
|
|
30802
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("OpenKey returned an invalid device authorization response");
|
|
30803
|
+
const result = value;
|
|
30804
|
+
if (typeof result.transactionId !== "string" || !/^[A-Za-z0-9_-]{20,}$/.test(result.transactionId) || typeof result.userCode !== "string" || !/^[A-Z2-9]{4}-[A-Z2-9]{4}$/.test(result.userCode) || typeof result.verificationUri !== "string" || typeof result.verificationUriComplete !== "string" || !Number.isSafeInteger(result.expiresIn) || Number(result.expiresIn) < 60 || !Number.isSafeInteger(result.interval) || Number(result.interval) < 1) throw new Error("OpenKey returned an invalid device authorization response");
|
|
30805
|
+
canonicalOrigin(new URL(result.verificationUri).origin, "verification URI");
|
|
30806
|
+
if (new URL(result.verificationUriComplete).origin !== new URL(result.verificationUri).origin) {
|
|
30807
|
+
throw new Error("OpenKey returned an invalid verification URI");
|
|
30808
|
+
}
|
|
30809
|
+
return result;
|
|
30810
|
+
}
|
|
30811
|
+
async function responseJson(response) {
|
|
30812
|
+
try {
|
|
30813
|
+
return await response.json();
|
|
30814
|
+
} catch {
|
|
30815
|
+
throw new Error(`OpenKey device authorization failed (HTTP ${response.status})`);
|
|
30816
|
+
}
|
|
30817
|
+
}
|
|
30818
|
+
function errorCode(value) {
|
|
30819
|
+
return value && typeof value === "object" && typeof value.error === "string" ? value.error : void 0;
|
|
30820
|
+
}
|
|
30821
|
+
function publicSessionJwk(value) {
|
|
30822
|
+
const publicJwk = publicJwkForDelegation(value);
|
|
30823
|
+
const record2 = publicJwk;
|
|
30824
|
+
if (record2.kty !== "OKP" || record2.crv !== "Ed25519" || typeof record2.x !== "string") {
|
|
30825
|
+
throw new Error("CLI session key is not a public Ed25519 JWK");
|
|
30826
|
+
}
|
|
30827
|
+
return publicJwk;
|
|
30828
|
+
}
|
|
30829
|
+
function publicRelayJwk(value) {
|
|
30830
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("OpenKey returned an invalid relay key");
|
|
30831
|
+
const jwk = value;
|
|
30832
|
+
if (jwk.kty !== "EC" || jwk.crv !== "P-256" || typeof jwk.x !== "string" || !/^[A-Za-z0-9_-]{43}$/.test(jwk.x) || typeof jwk.y !== "string" || !/^[A-Za-z0-9_-]{43}$/.test(jwk.y) || "d" in jwk) throw new Error("OpenKey returned an invalid relay key");
|
|
30833
|
+
return { kty: "EC", crv: "P-256", x: jwk.x, y: jwk.y };
|
|
30834
|
+
}
|
|
30835
|
+
function decodeCanonicalBase64Url(value, label) {
|
|
30836
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9_-]+$/.test(value)) throw new Error(`OpenKey returned an invalid ${label}`);
|
|
30837
|
+
const decoded = Buffer.from(value, "base64url");
|
|
30838
|
+
if (decoded.toString("base64url") !== value) throw new Error(`OpenKey returned an invalid ${label}`);
|
|
30839
|
+
return decoded;
|
|
30840
|
+
}
|
|
30841
|
+
function deriveRelayKey(sharedSecret, transactionId) {
|
|
30842
|
+
const extracted = createHmac("sha256", Buffer.from(transactionId)).update(sharedSecret).digest();
|
|
30843
|
+
return createHmac("sha256", extracted).update(Buffer.from("openkey-device-relay-v1")).update(Buffer.from([1])).digest();
|
|
30844
|
+
}
|
|
30845
|
+
function decryptRelayResult(envelope, transactionId, privateKey) {
|
|
30846
|
+
if (!envelope || typeof envelope !== "object" || Array.isArray(envelope)) throw new Error("OpenKey returned an invalid encrypted relay result");
|
|
30847
|
+
const relay = envelope;
|
|
30848
|
+
if (relay.version !== 1 || relay.algorithm !== "ECDH-P256-A256GCM") throw new Error("OpenKey returned an unsupported encrypted relay result");
|
|
30849
|
+
const peer = createPublicKey({ key: publicRelayJwk(relay.ephemeralPublicJwk), format: "jwk" });
|
|
30850
|
+
const nonce = decodeCanonicalBase64Url(relay.nonce, "relay nonce");
|
|
30851
|
+
const ciphertext = decodeCanonicalBase64Url(relay.ciphertext, "relay ciphertext");
|
|
30852
|
+
if (nonce.length !== 12 || ciphertext.length <= 16) throw new Error("OpenKey returned an invalid encrypted relay result");
|
|
30853
|
+
const sharedSecret = diffieHellman({ privateKey, publicKey: peer });
|
|
30854
|
+
const key = deriveRelayKey(sharedSecret, transactionId);
|
|
30855
|
+
const decipher = createDecipheriv("aes-256-gcm", key, nonce);
|
|
30856
|
+
decipher.setAAD(Buffer.from(transactionId));
|
|
30857
|
+
decipher.setAuthTag(ciphertext.subarray(ciphertext.length - 16));
|
|
30858
|
+
let value;
|
|
30859
|
+
try {
|
|
30860
|
+
value = JSON.parse(Buffer.concat([decipher.update(ciphertext.subarray(0, -16)), decipher.final()]).toString("utf8"));
|
|
30861
|
+
} catch {
|
|
30862
|
+
throw new Error("OpenKey returned an unreadable encrypted relay result");
|
|
30863
|
+
}
|
|
30864
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("OpenKey returned an invalid encrypted relay result");
|
|
30865
|
+
return value;
|
|
30866
|
+
}
|
|
30867
|
+
function assertShareDelegationPermissions(value) {
|
|
30868
|
+
if (!Array.isArray(value) || value.length !== 1) throw new Error("OpenKey returned a delegation outside the requested Share scope");
|
|
30869
|
+
const permission = value[0];
|
|
30870
|
+
if (!permission || permission.service !== "tinycloud.capabilities" && permission.service !== "capabilities" || permission.space !== "applications" && !(typeof permission.space === "string" && permission.space.endsWith(":applications")) || permission.path !== "" || !Array.isArray(permission.actions) || permission.actions.length !== 1 || permission.actions[0] !== "tinycloud.capabilities/read") throw new Error("OpenKey returned a delegation outside the requested Share scope");
|
|
30871
|
+
}
|
|
30872
|
+
function assertApprovedBinding(input) {
|
|
30873
|
+
if (input.binding.transactionId !== input.transactionId || input.binding.sessionDid !== input.sessionDid || input.binding.nodeOrigin !== input.nodeOrigin || input.binding.shareOrigin !== input.shareOrigin || !jsonEqual(input.binding.permissions, SHARE_DEVICE_PERMISSIONS)) throw new Error("OpenKey returned a delegation with the wrong device binding");
|
|
30874
|
+
const expiresAt = Date.parse(input.binding.delegationExpiresAt);
|
|
30875
|
+
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() || expiresAt > Date.now() + SHARE_DEVICE_DELEGATION_SECONDS * 1e3 + 3e4) {
|
|
30876
|
+
throw new Error("OpenKey returned a delegation outside the requested expiry window");
|
|
30877
|
+
}
|
|
30878
|
+
if (input.delegation.verificationMethod !== input.sessionDid) {
|
|
30879
|
+
throw new Error("OpenKey returned a delegation for a different CLI session DID");
|
|
30880
|
+
}
|
|
30881
|
+
assertShareDelegationPermissions(input.delegation.permissions);
|
|
30882
|
+
const delegationExpiryValue = input.delegation.expiresAt ?? input.delegation.expirationTime ?? input.delegation.expiry;
|
|
30883
|
+
const delegationExpiresAt = typeof delegationExpiryValue === "string" ? Date.parse(delegationExpiryValue) : Number.NaN;
|
|
30884
|
+
if (!Number.isFinite(delegationExpiresAt) || delegationExpiresAt !== expiresAt) {
|
|
30885
|
+
throw new Error("OpenKey returned a delegation outside the approved expiry window");
|
|
30886
|
+
}
|
|
30887
|
+
if (!input.delegation.jwk || typeof input.delegation.jwk !== "object" || !jsonEqual(publicSessionJwk(input.delegation.jwk), input.publicJwk)) {
|
|
30888
|
+
throw new Error("OpenKey returned a delegation for a different CLI session key");
|
|
30889
|
+
}
|
|
30890
|
+
const invalid = validateDelegationCallbackPayload(input.delegation);
|
|
30891
|
+
if (invalid) throw new Error(`OpenKey returned an invalid delegation: ${invalid}`);
|
|
30892
|
+
}
|
|
30893
|
+
async function acquireShareDeviceDelegation(input) {
|
|
30894
|
+
const openkeyHost = canonicalOrigin(input.openkeyHost ?? DEFAULT_OPENKEY_HOST, "OpenKey host");
|
|
30895
|
+
const nodeOrigin = canonicalOrigin(input.nodeOrigin, "TinyCloud node origin");
|
|
30896
|
+
const shareOrigin = canonicalOrigin(input.shareOrigin, "Share origin");
|
|
30897
|
+
const fetchFn = input.fetchFn ?? globalThis.fetch;
|
|
30898
|
+
const deviceSecret = randomBytes4(32).toString("base64url");
|
|
30899
|
+
const codeVerifier = randomBytes4(32).toString("base64url");
|
|
30900
|
+
const relayKeys = generateKeyPairSync("ec", { namedCurve: "prime256v1" });
|
|
30901
|
+
const relayPublicJwk = publicRelayJwk(relayKeys.publicKey.export({ format: "jwk" }));
|
|
30902
|
+
const publicJwk = publicSessionJwk(input.jwk);
|
|
30903
|
+
const startResponse = await fetchFn(`${openkeyHost}/api/device-authorizations`, {
|
|
30904
|
+
method: "POST",
|
|
30905
|
+
credentials: "omit",
|
|
30906
|
+
redirect: "error",
|
|
30907
|
+
referrerPolicy: "no-referrer",
|
|
30908
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
30909
|
+
body: JSON.stringify({
|
|
30910
|
+
deviceSecretHash: digest4(deviceSecret),
|
|
30911
|
+
codeChallenge: digest4(codeVerifier),
|
|
30912
|
+
relayPublicJwk,
|
|
30913
|
+
sessionDid: input.sessionDid,
|
|
30914
|
+
publicJwk,
|
|
30915
|
+
permissions: SHARE_DEVICE_PERMISSIONS,
|
|
30916
|
+
nodeOrigin,
|
|
30917
|
+
shareOrigin,
|
|
30918
|
+
delegationTtlSeconds: SHARE_DEVICE_DELEGATION_SECONDS
|
|
30919
|
+
})
|
|
30920
|
+
});
|
|
30921
|
+
const startValue = await responseJson(startResponse);
|
|
30922
|
+
if (!startResponse.ok) throw new Error(`OpenKey device authorization failed: ${errorCode(startValue) ?? startResponse.status}`);
|
|
30923
|
+
const started = validateStart(startValue);
|
|
30924
|
+
(input.emitInstructions ?? ((value) => {
|
|
30925
|
+
process.stderr.write(`OpenKey device authorization
|
|
30926
|
+
Visit: ${value.verificationUri}
|
|
30927
|
+
Code: ${value.userCode}
|
|
30928
|
+
|
|
30929
|
+
Waiting for approval\u2026
|
|
30930
|
+
`);
|
|
30931
|
+
}))({ verificationUri: started.verificationUri, verificationUriComplete: started.verificationUriComplete, userCode: started.userCode });
|
|
30932
|
+
const deadline = Date.now() + started.expiresIn * 1e3;
|
|
30933
|
+
let interval = started.interval;
|
|
30934
|
+
const wait = input.wait ?? ((milliseconds) => new Promise((resolve2) => setTimeout(resolve2, milliseconds)));
|
|
30935
|
+
while (Date.now() < deadline) {
|
|
30936
|
+
await wait(interval * 1e3);
|
|
30937
|
+
const response = await fetchFn(`${openkeyHost}/api/device-authorizations/token`, {
|
|
30938
|
+
method: "POST",
|
|
30939
|
+
credentials: "omit",
|
|
30940
|
+
redirect: "error",
|
|
30941
|
+
referrerPolicy: "no-referrer",
|
|
30942
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
30943
|
+
body: JSON.stringify({ transactionId: started.transactionId, deviceSecret, codeVerifier })
|
|
30944
|
+
});
|
|
30945
|
+
const value = await responseJson(response);
|
|
30946
|
+
const code4 = errorCode(value);
|
|
30947
|
+
if (response.status === 429 && code4 === "slow_down") {
|
|
30948
|
+
interval += 1;
|
|
30949
|
+
continue;
|
|
30950
|
+
}
|
|
30951
|
+
if (!response.ok) throw new Error(`OpenKey device authorization failed: ${code4 ?? response.status}`);
|
|
30952
|
+
const result = value;
|
|
30953
|
+
if (result.status === "pending") {
|
|
30954
|
+
interval = Math.max(interval, result.interval);
|
|
30955
|
+
continue;
|
|
30956
|
+
}
|
|
30957
|
+
if (result.status !== "approved" || !result.relay || !result.binding) {
|
|
30958
|
+
throw new Error("OpenKey returned an invalid device authorization result");
|
|
30959
|
+
}
|
|
30960
|
+
const delegation = decryptRelayResult(result.relay, started.transactionId, relayKeys.privateKey);
|
|
30961
|
+
assertApprovedBinding({ binding: result.binding, transactionId: started.transactionId, sessionDid: input.sessionDid, nodeOrigin, shareOrigin, publicJwk, delegation });
|
|
30962
|
+
return delegation;
|
|
30963
|
+
}
|
|
30964
|
+
throw new Error("OpenKey device authorization expired before approval");
|
|
30965
|
+
}
|
|
30966
|
+
function mergePrivateJwkIntoSession(session, key) {
|
|
30967
|
+
const sessionJwk = session.jwk;
|
|
30968
|
+
if (!sessionJwk || typeof sessionJwk !== "object") return session;
|
|
30969
|
+
const sessionJwkRecord = sessionJwk;
|
|
30970
|
+
if (typeof sessionJwkRecord.d === "string" && sessionJwkRecord.d.length > 0) return session;
|
|
30971
|
+
const privateParameter = key.d;
|
|
30972
|
+
if (typeof privateParameter !== "string" || privateParameter.length === 0) return session;
|
|
30973
|
+
return { ...session, jwk: { ...sessionJwkRecord, d: privateParameter } };
|
|
30974
|
+
}
|
|
30975
|
+
async function ensureShareDeviceAuthorization(input) {
|
|
30976
|
+
let profile = await ProfileManager.getProfile(input.profileName).catch(() => null);
|
|
30977
|
+
if (profile?.authMethod === "local" && input.allowReplaceLocal !== true) {
|
|
30978
|
+
throw new Error("This profile uses a local owner key. Run `tc auth login --device` explicitly to replace its authentication posture.");
|
|
30979
|
+
}
|
|
30980
|
+
let key = await ProfileManager.getKey(input.profileName);
|
|
30981
|
+
if (!key) {
|
|
30982
|
+
const generated = generateKey2();
|
|
30983
|
+
key = generated.jwk;
|
|
30984
|
+
await ProfileManager.setKey(input.profileName, key);
|
|
30985
|
+
}
|
|
30986
|
+
const sessionDid = keyToDID(key);
|
|
30987
|
+
profile = {
|
|
30988
|
+
...profile,
|
|
30989
|
+
name: input.profileName,
|
|
30990
|
+
host: input.nodeOrigin,
|
|
30991
|
+
chainId: profile?.chainId ?? DEFAULT_CHAIN_ID,
|
|
30992
|
+
spaceName: profile?.spaceName ?? "applications",
|
|
30993
|
+
did: sessionDid,
|
|
30994
|
+
sessionDid,
|
|
30995
|
+
createdAt: profile?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
30996
|
+
posture: "owner-openkey",
|
|
30997
|
+
operatorType: profile?.operatorType ?? "human",
|
|
30998
|
+
authMethod: "openkey",
|
|
30999
|
+
openkeyHost: input.openkeyHost ?? profile?.openkeyHost
|
|
31000
|
+
};
|
|
31001
|
+
await ProfileManager.setProfile(input.profileName, profile);
|
|
31002
|
+
const delegation = await acquireShareDeviceDelegation({
|
|
31003
|
+
sessionDid,
|
|
31004
|
+
jwk: key,
|
|
31005
|
+
nodeOrigin: input.nodeOrigin,
|
|
31006
|
+
shareOrigin: input.shareOrigin,
|
|
31007
|
+
openkeyHost: input.openkeyHost ?? profile.openkeyHost,
|
|
31008
|
+
fetchFn: input.fetchFn,
|
|
31009
|
+
emitInstructions: input.emitInstructions,
|
|
31010
|
+
wait: input.wait
|
|
31011
|
+
});
|
|
31012
|
+
const session = mergePrivateJwkIntoSession(delegation, key);
|
|
31013
|
+
await ProfileManager.setSession(input.profileName, session);
|
|
31014
|
+
const updatedProfile = {
|
|
31015
|
+
...profile,
|
|
31016
|
+
ownerDid: typeof session.ownerDid === "string" ? session.ownerDid : profile.ownerDid,
|
|
31017
|
+
spaceId: typeof session.spaceId === "string" ? session.spaceId : profile.spaceId
|
|
31018
|
+
};
|
|
31019
|
+
await ProfileManager.setProfile(input.profileName, updatedProfile);
|
|
31020
|
+
return { profile: updatedProfile, delegation: session };
|
|
31021
|
+
}
|
|
31022
|
+
var SHARE_DEVICE_DELEGATION_SECONDS, SHARE_DEVICE_PERMISSIONS;
|
|
31023
|
+
var init_device_auth = __esm({
|
|
31024
|
+
"src/auth/device-auth.ts"() {
|
|
31025
|
+
"use strict";
|
|
31026
|
+
init_constants();
|
|
31027
|
+
init_profiles();
|
|
31028
|
+
init_local_key();
|
|
31029
|
+
init_browser_auth();
|
|
31030
|
+
SHARE_DEVICE_DELEGATION_SECONDS = 30 * 24 * 60 * 60;
|
|
31031
|
+
SHARE_DEVICE_PERMISSIONS = [{
|
|
31032
|
+
service: "tinycloud.capabilities",
|
|
31033
|
+
space: "applications",
|
|
31034
|
+
path: "",
|
|
31035
|
+
actions: ["tinycloud.capabilities/read"]
|
|
31036
|
+
}];
|
|
31037
|
+
}
|
|
31038
|
+
});
|
|
31039
|
+
|
|
30659
31040
|
// src/index.ts
|
|
30660
31041
|
init_errors();
|
|
30661
31042
|
import { readFileSync as readFileSync2 } from "fs";
|
|
@@ -30966,11 +31347,11 @@ function parseShareTarget(value) {
|
|
|
30966
31347
|
if (value.includes("@")) return { kind: "email", address: value };
|
|
30967
31348
|
throw new CLIError("INVALID_ARGUMENT", "--to must be anyone, a did:, an email address, or domain:example.com", 2);
|
|
30968
31349
|
}
|
|
30969
|
-
function publishServices() {
|
|
31350
|
+
function publishServices(insecureLocalRegistry = false) {
|
|
30970
31351
|
return {
|
|
30971
31352
|
...shareServices.uploadBlob === void 0 ? {} : { uploadBlob: shareServices.uploadBlob },
|
|
30972
31353
|
...shareServices.authorizeUpload === void 0 ? {} : { authorizeUpload: shareServices.authorizeUpload },
|
|
30973
|
-
...shareServices.authorizeUpload === void 0 ? {} : { authorizationOrigin: SHARE_ORIGIN },
|
|
31354
|
+
...shareServices.authorizeUpload === void 0 || insecureLocalRegistry ? {} : { authorizationOrigin: SHARE_ORIGIN },
|
|
30974
31355
|
...shareServices.credentials === void 0 ? {} : { credentials: shareServices.credentials },
|
|
30975
31356
|
...shareServices.fetchFn === void 0 ? {} : { fetchFn: shareServices.fetchFn }
|
|
30976
31357
|
};
|
|
@@ -31016,6 +31397,9 @@ function inputUrl(value, stdin) {
|
|
|
31016
31397
|
if (value === void 0 || value.length === 0) throw new CLIError("INVALID_ARGUMENT", "a share URL or - is required", 2);
|
|
31017
31398
|
return Promise.resolve(value);
|
|
31018
31399
|
}
|
|
31400
|
+
function jsonOutput(options, command) {
|
|
31401
|
+
return options.json === true || command.optsWithGlobals().json === true;
|
|
31402
|
+
}
|
|
31019
31403
|
function expires(value) {
|
|
31020
31404
|
try {
|
|
31021
31405
|
return new Date(Date.now() + parseDuration(value));
|
|
@@ -31066,8 +31450,9 @@ function assertAggregateInputLimit(inputs, maxBytes) {
|
|
|
31066
31450
|
}
|
|
31067
31451
|
function registerShareCommand(program2) {
|
|
31068
31452
|
const share = program2.command("share").description("Publish and consume TinyCloud Share links");
|
|
31069
|
-
share.command("publish <files...>").description("Publish one or more bounded files as a Share").option("--name <filename>", "Filename for stdin input").option("--to <target>", "Share target", "anyone").option("--notify", "Request idempotent email delivery for addressed targets").option("--expires <duration>", "Share lifetime", "7d").option("--max-bytes <bytes>", "Bound input bytes").option("--media-type <type>", "Media type for a single input").option("--action <actions...>", "Addressed permission: read, list, or edit").option("--prefix", "Publish multiple inputs beneath one addressed prefix").option("--binary", "Allow non-UTF-8 bearer content").option("--inline", "Embed the sealed envelope in the URL fragment").option("--compact", "Use a CID-addressed compact link (default)").option("--json", "Print versioned redacted JSON").option("--registry <url>", "Authenticated registry upload endpoint", DEFAULT_REGISTRY).option("--viewer-origin <origin>", "Canonical HTTPS viewer origin", SHARE_ORIGIN).option("--insecure-registry", "Allow an explicit localhost HTTP registry for hermetic tests").action(async (files, options) => {
|
|
31453
|
+
share.command("publish <files...>").description("Publish one or more bounded files as a Share").option("--name <filename>", "Filename for stdin input").option("--to <target>", "Share target", "anyone").option("--notify", "Request idempotent email delivery for addressed targets").option("--expires <duration>", "Share lifetime", "7d").option("--max-bytes <bytes>", "Bound input bytes").option("--media-type <type>", "Media type for a single input").option("--action <actions...>", "Addressed permission: read, list, or edit").option("--prefix", "Publish multiple inputs beneath one addressed prefix").option("--binary", "Allow non-UTF-8 bearer content").option("--inline", "Embed the sealed envelope in the URL fragment").option("--compact", "Use a CID-addressed compact link (default)").option("--json", "Print versioned redacted JSON").option("--registry <url>", "Authenticated registry upload endpoint", DEFAULT_REGISTRY).option("--viewer-origin <origin>", "Canonical HTTPS viewer origin", SHARE_ORIGIN).option("--insecure-registry", "Allow an explicit localhost HTTP registry for hermetic tests").action(async (files, options, command) => {
|
|
31070
31454
|
try {
|
|
31455
|
+
const json = jsonOutput(options, command);
|
|
31071
31456
|
if (options.inline && options.compact) throw new CLIError("INVALID_ARGUMENT", "--inline and --compact are mutually exclusive", 2);
|
|
31072
31457
|
const maxBytes = byteLimit(options.maxBytes);
|
|
31073
31458
|
if (files.length === 0 || files.includes("-") && files.length > 1) throw new CLIError("INVALID_ARGUMENT", "stdin must be the only publish input", 2);
|
|
@@ -31096,10 +31481,10 @@ function registerShareCommand(program2) {
|
|
|
31096
31481
|
allowInsecureRegistry: options.insecureRegistry === true,
|
|
31097
31482
|
notify: options.notify === true,
|
|
31098
31483
|
targetAdapter: shareServices.targetAdapter,
|
|
31099
|
-
...publishServices()
|
|
31484
|
+
...publishServices(options.insecureRegistry === true)
|
|
31100
31485
|
});
|
|
31101
31486
|
if ("state" in result) {
|
|
31102
|
-
if (
|
|
31487
|
+
if (json) {
|
|
31103
31488
|
writeJson2({ protocol: "tinycloud-share", version: 1, authorization: authorizationRequiredJson(result) });
|
|
31104
31489
|
process.exitCode = 6;
|
|
31105
31490
|
return;
|
|
@@ -31112,25 +31497,27 @@ function registerShareCommand(program2) {
|
|
|
31112
31497
|
const delivery = await notifyShare({ shareId: record2.shareId, recipient: target.address, record: record2, adapter: shareServices.delivery });
|
|
31113
31498
|
if (delivery.state === "partial-failure") process.exitCode = 9;
|
|
31114
31499
|
}
|
|
31115
|
-
if (
|
|
31500
|
+
if (json) writeJson2(redactPublishedShare(result));
|
|
31116
31501
|
else publishHuman(result);
|
|
31117
31502
|
} catch (error) {
|
|
31118
31503
|
handleError(shareCliError(error));
|
|
31119
31504
|
}
|
|
31120
31505
|
});
|
|
31121
|
-
share.command("inspect [url]").description("Verify a share link and print safe metadata").option("--stdin", "Read the complete URL from stdin").option("--json", "Print versioned redacted JSON").option("--registry <url>", "Registry read endpoint", DEFAULT_READ_REGISTRY).option("--viewer-origin <origin>", "Require this canonical Share origin", SHARE_ORIGIN).action(async (url, options) => {
|
|
31506
|
+
share.command("inspect [url]").description("Verify a share link and print safe metadata").option("--stdin", "Read the complete URL from stdin").option("--json", "Print versioned redacted JSON").option("--registry <url>", "Registry read endpoint", DEFAULT_READ_REGISTRY).option("--viewer-origin <origin>", "Require this canonical Share origin", SHARE_ORIGIN).action(async (url, options, command) => {
|
|
31122
31507
|
try {
|
|
31508
|
+
const json = jsonOutput(options, command);
|
|
31123
31509
|
const link2 = await inputUrl(url, options.stdin === true);
|
|
31124
31510
|
const result = await inspectShare(link2, { registryBaseUrl: options.registry, expectedOrigin: options.viewerOrigin, ...fetchServices() });
|
|
31125
|
-
if (
|
|
31511
|
+
if (json) writeJson2(result);
|
|
31126
31512
|
else inspectHuman(result);
|
|
31127
31513
|
} catch (error) {
|
|
31128
31514
|
handleError(shareCliError(error));
|
|
31129
31515
|
}
|
|
31130
31516
|
});
|
|
31131
|
-
share.command("receive [url]").description("Verify and receive a share link").option("--stdin", "Read the complete URL from stdin").option("--output <directory>", "Create the file in this directory").option("--stdout", "Write verified plaintext bytes to stdout").option("--force", "Allow replacing an existing non-symlink output").option("--max-bytes <bytes>", "Bound received content bytes").option("--resume-token <token>", "Resume a previously returned recipient authorization step").option("--authorization-proof-file <path>", "Read the JSON authorization proof from a file").option("--json", "Print versioned redacted JSON").option("--registry <url>", "Registry read endpoint", DEFAULT_READ_REGISTRY).option("--viewer-origin <origin>", "Require this canonical Share origin", SHARE_ORIGIN).option("--legacy", "Read a legacy tc1: link (read-only)").action(async (url, options) => {
|
|
31517
|
+
share.command("receive [url]").description("Verify and receive a share link").option("--stdin", "Read the complete URL from stdin").option("--output <directory>", "Create the file in this directory").option("--stdout", "Write verified plaintext bytes to stdout").option("--force", "Allow replacing an existing non-symlink output").option("--max-bytes <bytes>", "Bound received content bytes").option("--resume-token <token>", "Resume a previously returned recipient authorization step").option("--authorization-proof-file <path>", "Read the JSON authorization proof from a file").option("--json", "Print versioned redacted JSON").option("--registry <url>", "Registry read endpoint", DEFAULT_READ_REGISTRY).option("--viewer-origin <origin>", "Require this canonical Share origin", SHARE_ORIGIN).option("--legacy", "Read a legacy tc1: link (read-only)").action(async (url, options, command) => {
|
|
31132
31518
|
try {
|
|
31133
|
-
|
|
31519
|
+
const json = jsonOutput(options, command);
|
|
31520
|
+
if (options.stdout && json) throw new CLIError("INVALID_ARGUMENT", "--stdout and --json are mutually exclusive", 2);
|
|
31134
31521
|
const maxBytes = byteLimit(options.maxBytes);
|
|
31135
31522
|
const link2 = await inputUrl(url, options.stdin === true);
|
|
31136
31523
|
const proof = await authorizationProof(options);
|
|
@@ -31142,7 +31529,7 @@ function registerShareCommand(program2) {
|
|
|
31142
31529
|
return;
|
|
31143
31530
|
}
|
|
31144
31531
|
const output2 = await writeShareOutput(options.output ?? ".", "share.md", bytes3, options.force === true);
|
|
31145
|
-
if (
|
|
31532
|
+
if (json) writeJson2({ protocol: "tinycloud-share", version: 1, legacy: true, path: output2 });
|
|
31146
31533
|
else receiveHuman(output2);
|
|
31147
31534
|
return;
|
|
31148
31535
|
}
|
|
@@ -31156,7 +31543,7 @@ function registerShareCommand(program2) {
|
|
|
31156
31543
|
...proof === void 0 ? {} : { authorizationProof: proof }
|
|
31157
31544
|
});
|
|
31158
31545
|
if ("state" in result) {
|
|
31159
|
-
if (
|
|
31546
|
+
if (json) {
|
|
31160
31547
|
writeJson2({ protocol: "tinycloud-share", version: 1, authorization: authorizationRequiredJson(result) });
|
|
31161
31548
|
process.exitCode = 6;
|
|
31162
31549
|
return;
|
|
@@ -31168,14 +31555,15 @@ function registerShareCommand(program2) {
|
|
|
31168
31555
|
return;
|
|
31169
31556
|
}
|
|
31170
31557
|
const output = await writeShareOutput(options.output ?? ".", result.metadata.display.filename ?? "share.md", result.bytes, options.force === true);
|
|
31171
|
-
if (
|
|
31558
|
+
if (json) receiveJson(result, output);
|
|
31172
31559
|
else receiveHuman(output);
|
|
31173
31560
|
} catch (error) {
|
|
31174
31561
|
handleError(shareCliError(error));
|
|
31175
31562
|
}
|
|
31176
31563
|
});
|
|
31177
|
-
share.command("migrate [url]").description("Read a legacy tc1 link and re-mint a modern Share link").option("--stdin", "Read the complete legacy link from stdin").option("--name <filename>", "Filename for the migrated content", "migrated.md").option("--to <target>", "Modern Share target", "anyone").option("--notify", "Request idempotent email delivery for addressed targets").option("--expires <duration>", "Modern share lifetime", "7d").option("--max-bytes <bytes>", "Bound migrated content bytes").option("--inline", "Embed the sealed envelope in the URL fragment").option("--registry <url>", "Authenticated registry upload endpoint", DEFAULT_REGISTRY).option("--viewer-origin <origin>", "Canonical HTTPS viewer origin", SHARE_ORIGIN).option("--insecure-registry", "Allow an explicit localhost HTTP registry for hermetic tests").option("--json", "Print versioned redacted JSON").action(async (url, options) => {
|
|
31564
|
+
share.command("migrate [url]").description("Read a legacy tc1 link and re-mint a modern Share link").option("--stdin", "Read the complete legacy link from stdin").option("--name <filename>", "Filename for the migrated content", "migrated.md").option("--to <target>", "Modern Share target", "anyone").option("--notify", "Request idempotent email delivery for addressed targets").option("--expires <duration>", "Modern share lifetime", "7d").option("--max-bytes <bytes>", "Bound migrated content bytes").option("--inline", "Embed the sealed envelope in the URL fragment").option("--registry <url>", "Authenticated registry upload endpoint", DEFAULT_REGISTRY).option("--viewer-origin <origin>", "Canonical HTTPS viewer origin", SHARE_ORIGIN).option("--insecure-registry", "Allow an explicit localhost HTTP registry for hermetic tests").option("--json", "Print versioned redacted JSON").action(async (url, options, command) => {
|
|
31178
31565
|
try {
|
|
31566
|
+
const json = jsonOutput(options, command);
|
|
31179
31567
|
if (shareServices.legacyReader === void 0) throw new CLIError("UNSUPPORTED_LINK", "legacy migration requires an installed read-only tc1 adapter", 2);
|
|
31180
31568
|
const link2 = await inputUrl(url, options.stdin === true);
|
|
31181
31569
|
if (!isLegacyShareLink(link2)) throw new CLIError("UNSUPPORTED_LINK", "only tc1: links can be migrated", 2);
|
|
@@ -31197,7 +31585,7 @@ function registerShareCommand(program2) {
|
|
|
31197
31585
|
allowInsecureRegistry: options.insecureRegistry === true,
|
|
31198
31586
|
notify: options.notify === true,
|
|
31199
31587
|
targetAdapter: shareServices.targetAdapter,
|
|
31200
|
-
...publishServices()
|
|
31588
|
+
...publishServices(options.insecureRegistry === true)
|
|
31201
31589
|
});
|
|
31202
31590
|
if ("state" in result) throw new CLIError(result.method === "openkey-device" ? "DEVICE_AUTH_REQUIRED" : "CLAIM_REQUIRED", "recipient authorization is required; continue through the configured authority adapter", 6);
|
|
31203
31591
|
const record2 = await rememberPublishedShare(result);
|
|
@@ -31211,41 +31599,44 @@ function registerShareCommand(program2) {
|
|
|
31211
31599
|
return result;
|
|
31212
31600
|
}
|
|
31213
31601
|
});
|
|
31214
|
-
if (
|
|
31602
|
+
if (json) writeJson2({ protocol: "tinycloud-share", version: 1, legacy: true, migrated: redactPublishedShare(migrated.migrated) });
|
|
31215
31603
|
else publishHuman(migrated.migrated);
|
|
31216
31604
|
} catch (error) {
|
|
31217
31605
|
handleError(shareCliError(error));
|
|
31218
31606
|
}
|
|
31219
31607
|
});
|
|
31220
|
-
share.command("list").description("List encrypted sender history without complete bearer URLs").option("--json", "Print versioned redacted JSON").action(async (options) => {
|
|
31608
|
+
share.command("list").description("List encrypted sender history without complete bearer URLs").option("--json", "Print versioned redacted JSON").action(async (options, command) => {
|
|
31221
31609
|
try {
|
|
31610
|
+
const json = jsonOutput(options, command);
|
|
31222
31611
|
if (shareServices.records === void 0) throw new CLIError("AUTH_REQUIRED", "sender history storage is not configured", 3);
|
|
31223
31612
|
const result = await listShares(shareServices.records);
|
|
31224
|
-
if (
|
|
31613
|
+
if (json) writeJson2({ protocol: "tinycloud-share", version: 1, shares: result });
|
|
31225
31614
|
else process.stdout.write(result.map((item) => `${item.shareId} ${item.target} ${item.expiresAt}`).join("\n") + (result.length ? "\n" : ""));
|
|
31226
31615
|
} catch (error) {
|
|
31227
31616
|
handleError(shareCliError(error));
|
|
31228
31617
|
}
|
|
31229
31618
|
});
|
|
31230
|
-
share.command("show <id>").description("Show one redacted sender-history record").option("--reveal-link", "Explicitly include the complete link").option("--json", "Print versioned redacted JSON").action(async (id, options) => {
|
|
31619
|
+
share.command("show <id>").description("Show one redacted sender-history record").option("--reveal-link", "Explicitly include the complete link").option("--json", "Print versioned redacted JSON").action(async (id, options, command) => {
|
|
31231
31620
|
try {
|
|
31232
|
-
|
|
31621
|
+
const json = jsonOutput(options, command);
|
|
31622
|
+
if (options.revealLink && json) throw new CLIError("INVALID_ARGUMENT", "--reveal-link cannot be combined with --json", 2);
|
|
31233
31623
|
if (shareServices.records === void 0) throw new CLIError("AUTH_REQUIRED", "sender history storage is not configured", 3);
|
|
31234
31624
|
const result = await showShare({ storage: shareServices.records, shareId: id, revealLink: options.revealLink === true, link: options.revealLink ? await shareServices.linkFor?.(id) : void 0 });
|
|
31235
|
-
if (
|
|
31625
|
+
if (json) writeJson2({ protocol: "tinycloud-share", version: 1, share: result });
|
|
31236
31626
|
else writeJson2(result);
|
|
31237
31627
|
} catch (error) {
|
|
31238
31628
|
handleError(shareCliError(error));
|
|
31239
31629
|
}
|
|
31240
31630
|
});
|
|
31241
|
-
share.command("notify <id>").description("Retry idempotent delivery without recreating the share").requiredOption("--to <address>", "Recipient email").option("--json", "Print versioned JSON").action(async (id, options) => {
|
|
31631
|
+
share.command("notify <id>").description("Retry idempotent delivery without recreating the share").requiredOption("--to <address>", "Recipient email").option("--json", "Print versioned JSON").action(async (id, options, command) => {
|
|
31242
31632
|
try {
|
|
31633
|
+
const json = jsonOutput(options, command);
|
|
31243
31634
|
if (shareServices.delivery === void 0) throw new CLIError("AUTH_REQUIRED", "delivery authority is not configured", 3);
|
|
31244
31635
|
if (shareServices.records === void 0) throw new CLIError("AUTH_REQUIRED", "sender history storage is not configured", 3);
|
|
31245
31636
|
const record2 = await shareServices.records.get(id);
|
|
31246
31637
|
if (record2 === void 0) throw new CLIError("NOT_FOUND", "share not found", 4);
|
|
31247
31638
|
const result = await notifyShare({ shareId: id, recipient: options.to, record: record2, adapter: shareServices.delivery });
|
|
31248
|
-
if (
|
|
31639
|
+
if (json) writeJson2(result);
|
|
31249
31640
|
else process.stdout.write(`${result.state}
|
|
31250
31641
|
`);
|
|
31251
31642
|
if (result.state === "partial-failure") process.exitCode = 9;
|
|
@@ -31253,8 +31644,9 @@ function registerShareCommand(program2) {
|
|
|
31253
31644
|
handleError(shareCliError(error));
|
|
31254
31645
|
}
|
|
31255
31646
|
});
|
|
31256
|
-
share.command("revoke <id>").description("Revoke addressed shares; report bearer retention honestly").option("--ancestor", "Revoke the owner delegation ancestry").option("--json", "Print versioned JSON").action(async (id, options) => {
|
|
31647
|
+
share.command("revoke <id>").description("Revoke addressed shares; report bearer retention honestly").option("--ancestor", "Revoke the owner delegation ancestry").option("--json", "Print versioned JSON").action(async (id, options, command) => {
|
|
31257
31648
|
try {
|
|
31649
|
+
const json = jsonOutput(options, command);
|
|
31258
31650
|
if (shareServices.records === void 0) throw new CLIError("AUTH_REQUIRED", "sender history storage is not configured", 3);
|
|
31259
31651
|
const record2 = shareServices.getRecord ? await shareServices.getRecord(id) : await shareServices.records.get(id);
|
|
31260
31652
|
if (record2 === void 0) throw new CLIError("NOT_FOUND", "share not found", 4);
|
|
@@ -31262,7 +31654,7 @@ function registerShareCommand(program2) {
|
|
|
31262
31654
|
if (result.state === "unsupported") {
|
|
31263
31655
|
throw new CLIError("UNSUPPORTED_TARGET", result.reason, 2);
|
|
31264
31656
|
}
|
|
31265
|
-
if (
|
|
31657
|
+
if (json) writeJson2({ protocol: "tinycloud-share", version: 1, result });
|
|
31266
31658
|
else process.stdout.write(`${result.state}
|
|
31267
31659
|
`);
|
|
31268
31660
|
} catch (error) {
|
|
@@ -31276,7 +31668,7 @@ init_profiles();
|
|
|
31276
31668
|
init_dist3();
|
|
31277
31669
|
import { readFile as readFile5, writeFile as writeFile2 } from "fs/promises";
|
|
31278
31670
|
import { join as join6 } from "path";
|
|
31279
|
-
import { createHash } from "crypto";
|
|
31671
|
+
import { createHash as createHash2 } from "crypto";
|
|
31280
31672
|
|
|
31281
31673
|
// ../share-envelope/dist/index.js
|
|
31282
31674
|
init_zod();
|
|
@@ -31757,25 +32149,25 @@ function encodeTo4(int, target, offset = 0) {
|
|
|
31757
32149
|
function encodingLength4(int) {
|
|
31758
32150
|
return varint_default4.encodingLength(int);
|
|
31759
32151
|
}
|
|
31760
|
-
function create4(code23,
|
|
31761
|
-
const size2 =
|
|
32152
|
+
function create4(code23, digest5) {
|
|
32153
|
+
const size2 = digest5.byteLength;
|
|
31762
32154
|
const sizeOffset = encodingLength4(code23);
|
|
31763
32155
|
const digestOffset = sizeOffset + encodingLength4(size2);
|
|
31764
32156
|
const bytes3 = new Uint8Array(digestOffset + size2);
|
|
31765
32157
|
encodeTo4(code23, bytes3, 0);
|
|
31766
32158
|
encodeTo4(size2, bytes3, sizeOffset);
|
|
31767
|
-
bytes3.set(
|
|
31768
|
-
return new Digest4(code23, size2,
|
|
32159
|
+
bytes3.set(digest5, digestOffset);
|
|
32160
|
+
return new Digest4(code23, size2, digest5, bytes3);
|
|
31769
32161
|
}
|
|
31770
32162
|
function decode43(multihash) {
|
|
31771
32163
|
const bytes3 = coerce5(multihash);
|
|
31772
32164
|
const [code23, sizeOffset] = decode33(bytes3);
|
|
31773
32165
|
const [size2, digestOffset] = decode33(bytes3.subarray(sizeOffset));
|
|
31774
|
-
const
|
|
31775
|
-
if (
|
|
32166
|
+
const digest5 = bytes3.subarray(sizeOffset + digestOffset);
|
|
32167
|
+
if (digest5.byteLength !== size2) {
|
|
31776
32168
|
throw new Error("Incorrect length");
|
|
31777
32169
|
}
|
|
31778
|
-
return new Digest4(code23, size2,
|
|
32170
|
+
return new Digest4(code23, size2, digest5, bytes3);
|
|
31779
32171
|
}
|
|
31780
32172
|
function equals23(a, b) {
|
|
31781
32173
|
if (a === b) {
|
|
@@ -31793,10 +32185,10 @@ var Digest4 = class {
|
|
|
31793
32185
|
/**
|
|
31794
32186
|
* Creates a multihash digest.
|
|
31795
32187
|
*/
|
|
31796
|
-
constructor(code23, size2,
|
|
32188
|
+
constructor(code23, size2, digest5, bytes3) {
|
|
31797
32189
|
this.code = code23;
|
|
31798
32190
|
this.size = size2;
|
|
31799
|
-
this.digest =
|
|
32191
|
+
this.digest = digest5;
|
|
31800
32192
|
this.bytes = bytes3;
|
|
31801
32193
|
}
|
|
31802
32194
|
};
|
|
@@ -31877,8 +32269,8 @@ var CID4 = class _CID4 {
|
|
|
31877
32269
|
toV1() {
|
|
31878
32270
|
switch (this.version) {
|
|
31879
32271
|
case 0: {
|
|
31880
|
-
const { code: code23, digest:
|
|
31881
|
-
const multihash = create4(code23,
|
|
32272
|
+
const { code: code23, digest: digest5 } = this.multihash;
|
|
32273
|
+
const multihash = create4(code23, digest5);
|
|
31882
32274
|
return _CID4.createV1(this.code, multihash);
|
|
31883
32275
|
}
|
|
31884
32276
|
case 1: {
|
|
@@ -31932,8 +32324,8 @@ var CID4 = class _CID4 {
|
|
|
31932
32324
|
return new _CID4(version3, code23, multihash, bytes3 ?? encodeCID4(version3, code23, multihash.bytes));
|
|
31933
32325
|
} else if (value[cidSymbol4] === true) {
|
|
31934
32326
|
const { version: version3, multihash, code: code23 } = value;
|
|
31935
|
-
const
|
|
31936
|
-
return _CID4.create(version3, code23,
|
|
32327
|
+
const digest5 = decode43(multihash);
|
|
32328
|
+
return _CID4.create(version3, code23, digest5);
|
|
31937
32329
|
} else {
|
|
31938
32330
|
return null;
|
|
31939
32331
|
}
|
|
@@ -31943,11 +32335,11 @@ var CID4 = class _CID4 {
|
|
|
31943
32335
|
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
31944
32336
|
* @param digest - (Multi)hash of the of the content.
|
|
31945
32337
|
*/
|
|
31946
|
-
static create(version3, code23,
|
|
32338
|
+
static create(version3, code23, digest5) {
|
|
31947
32339
|
if (typeof code23 !== "number") {
|
|
31948
32340
|
throw new Error("String codecs are no longer supported");
|
|
31949
32341
|
}
|
|
31950
|
-
if (!(
|
|
32342
|
+
if (!(digest5.bytes instanceof Uint8Array)) {
|
|
31951
32343
|
throw new Error("Invalid digest");
|
|
31952
32344
|
}
|
|
31953
32345
|
switch (version3) {
|
|
@@ -31955,12 +32347,12 @@ var CID4 = class _CID4 {
|
|
|
31955
32347
|
if (code23 !== DAG_PB_CODE4) {
|
|
31956
32348
|
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE4}) block encoding`);
|
|
31957
32349
|
} else {
|
|
31958
|
-
return new _CID4(version3, code23,
|
|
32350
|
+
return new _CID4(version3, code23, digest5, digest5.bytes);
|
|
31959
32351
|
}
|
|
31960
32352
|
}
|
|
31961
32353
|
case 1: {
|
|
31962
|
-
const bytes3 = encodeCID4(version3, code23,
|
|
31963
|
-
return new _CID4(version3, code23,
|
|
32354
|
+
const bytes3 = encodeCID4(version3, code23, digest5.bytes);
|
|
32355
|
+
return new _CID4(version3, code23, digest5, bytes3);
|
|
31964
32356
|
}
|
|
31965
32357
|
default: {
|
|
31966
32358
|
throw new Error("Invalid version");
|
|
@@ -31970,8 +32362,8 @@ var CID4 = class _CID4 {
|
|
|
31970
32362
|
/**
|
|
31971
32363
|
* Simplified version of `create` for CIDv0.
|
|
31972
32364
|
*/
|
|
31973
|
-
static createV0(
|
|
31974
|
-
return _CID4.create(0, DAG_PB_CODE4,
|
|
32365
|
+
static createV0(digest5) {
|
|
32366
|
+
return _CID4.create(0, DAG_PB_CODE4, digest5);
|
|
31975
32367
|
}
|
|
31976
32368
|
/**
|
|
31977
32369
|
* Simplified version of `create` for CIDv1.
|
|
@@ -31979,8 +32371,8 @@ var CID4 = class _CID4 {
|
|
|
31979
32371
|
* @param code - Content encoding format code.
|
|
31980
32372
|
* @param digest - Multihash of the content.
|
|
31981
32373
|
*/
|
|
31982
|
-
static createV1(code23,
|
|
31983
|
-
return _CID4.create(1, code23,
|
|
32374
|
+
static createV1(code23, digest5) {
|
|
32375
|
+
return _CID4.create(1, code23, digest5);
|
|
31984
32376
|
}
|
|
31985
32377
|
/**
|
|
31986
32378
|
* Decoded a CID from its binary representation. The byte array must contain
|
|
@@ -32013,8 +32405,8 @@ var CID4 = class _CID4 {
|
|
|
32013
32405
|
throw new Error("Incorrect length");
|
|
32014
32406
|
}
|
|
32015
32407
|
const digestBytes3 = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
32016
|
-
const
|
|
32017
|
-
const cid2 = specs.version === 0 ? _CID4.createV0(
|
|
32408
|
+
const digest5 = new Digest4(specs.multihashCode, specs.digestSize, digestBytes3, multihashBytes);
|
|
32409
|
+
const cid2 = specs.version === 0 ? _CID4.createV0(digest5) : _CID4.createV1(specs.codec, digest5);
|
|
32018
32410
|
return [cid2, bytes3.subarray(specs.size)];
|
|
32019
32411
|
}
|
|
32020
32412
|
/**
|
|
@@ -32634,6 +33026,7 @@ var MAX_INLINE_BYTES2 = 256 * 1024;
|
|
|
32634
33026
|
|
|
32635
33027
|
// src/share/adapters.ts
|
|
32636
33028
|
init_dist4();
|
|
33029
|
+
init_constants();
|
|
32637
33030
|
var DEFAULT_SHARE_ORIGIN = "https://share.tinycloud.xyz";
|
|
32638
33031
|
var ShareAuthorityError = class extends Error {
|
|
32639
33032
|
code;
|
|
@@ -32713,8 +33106,8 @@ function createEncryptedProfileHistory(profileName, sessionSigner) {
|
|
|
32713
33106
|
const derive = async (salt, legacy = false) => {
|
|
32714
33107
|
const secret = await profileSecret();
|
|
32715
33108
|
if (legacy) {
|
|
32716
|
-
const
|
|
32717
|
-
return crypto.subtle.importKey("raw",
|
|
33109
|
+
const digest5 = await crypto.subtle.digest("SHA-256", secret);
|
|
33110
|
+
return crypto.subtle.importKey("raw", digest5, { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
|
|
32718
33111
|
}
|
|
32719
33112
|
const material = await crypto.subtle.importKey("raw", secret, "PBKDF2", false, ["deriveKey"]);
|
|
32720
33113
|
return crypto.subtle.deriveKey({ name: "PBKDF2", salt, iterations: 1e5, hash: "SHA-256" }, material, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
|
|
@@ -32785,7 +33178,7 @@ function createEncryptedProfileHistory(profileName, sessionSigner) {
|
|
|
32785
33178
|
function createShareAuthorityAdapters(input = {}) {
|
|
32786
33179
|
const origin = input.origin ?? DEFAULT_SHARE_ORIGIN;
|
|
32787
33180
|
const fetchFn = input.fetchFn ?? globalThis.fetch;
|
|
32788
|
-
const
|
|
33181
|
+
const canonicalOrigin2 = (value, label) => {
|
|
32789
33182
|
if (typeof value !== "string") throw new Error(`share ${label} is unavailable`);
|
|
32790
33183
|
const parsed = new URL(value);
|
|
32791
33184
|
const loopback = parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost";
|
|
@@ -32810,17 +33203,17 @@ function createShareAuthorityAdapters(input = {}) {
|
|
|
32810
33203
|
if (decoded.length !== 32 || Buffer.from(decoded).toString("base64url") !== key) throw new Error("share node receipt key is invalid");
|
|
32811
33204
|
return decoded;
|
|
32812
33205
|
};
|
|
32813
|
-
const nodeOrigin =
|
|
33206
|
+
const nodeOrigin = canonicalOrigin2(input.nodeOrigin ?? object3.nodeOrigin, "node origin");
|
|
32814
33207
|
const nodeAudience = typeof object3.nodeAudience === "string" ? object3.nodeAudience : "";
|
|
32815
33208
|
const enforcerDid = typeof object3.enforcerDid === "string" ? object3.enforcerDid : nodeAudience;
|
|
32816
33209
|
const nodeInvitationKid = typeof object3.nodeInvitationKid === "string" ? object3.nodeInvitationKid : "";
|
|
32817
33210
|
if (!nodeAudience.startsWith("did:web:") || !nodeInvitationKid.startsWith(`${nodeAudience}#`) || !enforcerDid.startsWith("did:key:") && enforcerDid !== nodeAudience) throw new Error("share node trust binding is invalid");
|
|
32818
33211
|
return {
|
|
32819
|
-
shareOrigin:
|
|
32820
|
-
registryOrigin:
|
|
33212
|
+
shareOrigin: canonicalOrigin2(object3.shareOrigin, "origin"),
|
|
33213
|
+
registryOrigin: canonicalOrigin2(object3.registryOrigin, "registry origin"),
|
|
32821
33214
|
nodeOrigin,
|
|
32822
|
-
emailOrigin:
|
|
32823
|
-
credentialsOrigin:
|
|
33215
|
+
emailOrigin: canonicalOrigin2(input.emailOrigin ?? object3.emailOrigin, "email origin"),
|
|
33216
|
+
credentialsOrigin: canonicalOrigin2(object3.credentialsOrigin, "credentials origin"),
|
|
32824
33217
|
nodeAudience,
|
|
32825
33218
|
enforcerDid,
|
|
32826
33219
|
nodeInvitationKid,
|
|
@@ -33054,7 +33447,12 @@ function createShareAuthorityAdapters(input = {}) {
|
|
|
33054
33447
|
return {
|
|
33055
33448
|
targetAdapter,
|
|
33056
33449
|
authorization,
|
|
33057
|
-
records: input.profileName === void 0 ? createEncryptedSessionHistory() : createEncryptedProfileHistory(input.profileName, async (bytes3) =>
|
|
33450
|
+
records: input.profileName === void 0 ? createEncryptedSessionHistory() : createEncryptedProfileHistory(input.profileName, async (bytes3) => {
|
|
33451
|
+
const profileName = await input.profileName();
|
|
33452
|
+
const context = await ProfileManager.resolveContext({ profile: profileName });
|
|
33453
|
+
const { ensureAuthenticated: ensureAuthenticated2 } = await Promise.resolve().then(() => (init_sdk(), sdk_exports));
|
|
33454
|
+
return (await ensureAuthenticated2(context)).signSessionBytes(bytes3);
|
|
33455
|
+
}),
|
|
33058
33456
|
delivery,
|
|
33059
33457
|
revocation,
|
|
33060
33458
|
legacyReader,
|
|
@@ -33083,7 +33481,7 @@ function canonicalNodeAudience(origin) {
|
|
|
33083
33481
|
return `did:web:${new URL(origin).hostname}`;
|
|
33084
33482
|
}
|
|
33085
33483
|
function base64UrlSha256(value) {
|
|
33086
|
-
return
|
|
33484
|
+
return createHash2("sha256").update(value).digest("base64url");
|
|
33087
33485
|
}
|
|
33088
33486
|
async function authenticatedNodeForProfile(profileName, host) {
|
|
33089
33487
|
const context = await ProfileManager.resolveContext({ profile: profileName, host });
|
|
@@ -33164,14 +33562,33 @@ function createProductionUploadAuthorizer(input = {}) {
|
|
|
33164
33562
|
if (input.testOnly === true) {
|
|
33165
33563
|
const suppliedSession = input.sessionAuthorization === void 0 ? void 0 : await input.sessionAuthorization();
|
|
33166
33564
|
if (suppliedSession !== void 0) return suppliedSession;
|
|
33167
|
-
const
|
|
33168
|
-
if (
|
|
33565
|
+
const acquired2 = await input.acquireUploadAuthorization?.({ profileName, upload });
|
|
33566
|
+
if (acquired2 !== void 0) return acquired2;
|
|
33169
33567
|
}
|
|
33170
|
-
const
|
|
33171
|
-
|
|
33568
|
+
const existing = await ProfileManager.getProfile(profileName).catch(() => null);
|
|
33569
|
+
if (existing?.authMethod === "openkey") {
|
|
33570
|
+
try {
|
|
33571
|
+
return await openKeyUploadAuthorization({ fetchFn, origin, profileName, upload, node: await authenticatedNodeForProfile(profileName, existing.host) });
|
|
33572
|
+
} catch (error) {
|
|
33573
|
+
if (!(error instanceof ShareAuthorityError) || error.code !== "AUTH_REQUIRED") throw error;
|
|
33574
|
+
}
|
|
33575
|
+
}
|
|
33576
|
+
const { ensureShareDeviceAuthorization: ensureShareDeviceAuthorization2 } = await Promise.resolve().then(() => (init_device_auth(), device_auth_exports));
|
|
33577
|
+
const nodeOrigin = await (input.nodeOrigin?.() ?? Promise.resolve(existing?.host ?? process.env.TC_HOST ?? DEFAULT_HOST));
|
|
33578
|
+
const acquired = await ensureShareDeviceAuthorization2({
|
|
33579
|
+
profileName,
|
|
33580
|
+
nodeOrigin,
|
|
33581
|
+
shareOrigin: origin,
|
|
33582
|
+
openkeyHost: process.env.TC_OPENKEY_HOST ?? existing?.openkeyHost,
|
|
33583
|
+
fetchFn
|
|
33584
|
+
});
|
|
33585
|
+
return openKeyUploadAuthorization({
|
|
33586
|
+
fetchFn,
|
|
33587
|
+
origin,
|
|
33588
|
+
profileName,
|
|
33589
|
+
upload,
|
|
33590
|
+
node: await authenticatedNodeForProfile(profileName, acquired.profile.host)
|
|
33172
33591
|
});
|
|
33173
|
-
if (profile.authMethod === "openkey") return openKeyUploadAuthorization({ fetchFn, origin, profileName, upload, node: await authenticatedNodeForProfile(profileName, profile.host) });
|
|
33174
|
-
throw new ShareAuthorityError("AUTH_REQUIRED", "share upload requires an active OpenKey session");
|
|
33175
33592
|
};
|
|
33176
33593
|
}
|
|
33177
33594
|
|
|
@@ -33193,6 +33610,15 @@ function selectedShareProfile() {
|
|
|
33193
33610
|
}
|
|
33194
33611
|
return process.env.TC_PROFILE;
|
|
33195
33612
|
}
|
|
33613
|
+
function selectedShareHost() {
|
|
33614
|
+
const args = process.argv.slice(2);
|
|
33615
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
33616
|
+
const value = args[index];
|
|
33617
|
+
if (value === "--host" || value === "-H") return args[index + 1];
|
|
33618
|
+
if (value?.startsWith("--host=")) return value.slice("--host=".length);
|
|
33619
|
+
}
|
|
33620
|
+
return process.env.TC_HOST;
|
|
33621
|
+
}
|
|
33196
33622
|
program.name("tc").description("TinyCloud CLI \u2014 self-sovereign storage from the terminal").version(version2).option("-p, --profile <name>", "Profile to use").option("-H, --host <url>", "TinyCloud node URL").option("-v, --verbose", "Enable verbose output").option("--no-cache", "Disable caching").option("-q, --quiet", "Suppress non-essential output").option("--json", "Force JSON output");
|
|
33197
33623
|
program.hook("preAction", async (thisCommand) => {
|
|
33198
33624
|
const opts = thisCommand.optsWithGlobals();
|
|
@@ -33228,7 +33654,8 @@ configureShareCommandServices({
|
|
|
33228
33654
|
// touches profile state, and no secret is serialized into a publish result.
|
|
33229
33655
|
authorizeUpload: createProductionUploadAuthorizer({
|
|
33230
33656
|
fetchFn: globalThis.fetch,
|
|
33231
|
-
profileName: async () => selectedShareProfile() ?? (await ProfileManager.getConfig()).defaultProfile
|
|
33657
|
+
profileName: async () => selectedShareProfile() ?? (await ProfileManager.getConfig()).defaultProfile,
|
|
33658
|
+
nodeOrigin: async () => selectedShareHost() ?? (await ProfileManager.resolveContext({ profile: selectedShareProfile() })).host
|
|
33232
33659
|
}),
|
|
33233
33660
|
targetAdapter: shareAuthority.targetAdapter,
|
|
33234
33661
|
authorization: shareAuthority.authorization,
|