@tinycloud/node-sdk 3.1.0-beta.5 → 3.1.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.cjs +101 -58
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +102 -58
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +101 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +102 -58
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/core.cjs
CHANGED
|
@@ -336,6 +336,10 @@ var defaultSignStrategy = { type: "auto-sign" };
|
|
|
336
336
|
// src/authorization/NodeUserAuthorization.ts
|
|
337
337
|
var DECRYPT_ACTION = import_sdk_core3.ENCRYPTION.DECRYPT;
|
|
338
338
|
var NETWORK_CREATE_ACTION = import_sdk_core3.ENCRYPTION.NETWORK_CREATE;
|
|
339
|
+
function describeHostFailure(result) {
|
|
340
|
+
const text = result.error?.trim();
|
|
341
|
+
return text ? `${result.status} - ${text}` : `${result.status}`;
|
|
342
|
+
}
|
|
339
343
|
function canonicalizeOpenKeyManifestJson(value) {
|
|
340
344
|
const json = JSON.stringify(value);
|
|
341
345
|
if (json === void 0) {
|
|
@@ -864,10 +868,12 @@ var NodeUserAuthorization = class {
|
|
|
864
868
|
return;
|
|
865
869
|
}
|
|
866
870
|
try {
|
|
867
|
-
const created =
|
|
868
|
-
if (!created) {
|
|
869
|
-
const err =
|
|
870
|
-
|
|
871
|
+
const created = await this.hostSpace();
|
|
872
|
+
if (!created.success) {
|
|
873
|
+
const err = Object.assign(
|
|
874
|
+
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
875
|
+
{ cause: created }
|
|
876
|
+
);
|
|
871
877
|
throw err;
|
|
872
878
|
}
|
|
873
879
|
} catch (error) {
|
|
@@ -883,8 +889,9 @@ var NodeUserAuthorization = class {
|
|
|
883
889
|
this._tinyCloudSession.delegationHeader
|
|
884
890
|
);
|
|
885
891
|
if (!retryResult.success) {
|
|
886
|
-
const err =
|
|
887
|
-
`Failed to activate session after creating space: ${retryResult
|
|
892
|
+
const err = Object.assign(
|
|
893
|
+
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
894
|
+
{ cause: retryResult }
|
|
888
895
|
);
|
|
889
896
|
handler.onSpaceCreationFailed?.(creationContext, err);
|
|
890
897
|
throw err;
|
|
@@ -901,10 +908,12 @@ var NodeUserAuthorization = class {
|
|
|
901
908
|
return;
|
|
902
909
|
}
|
|
903
910
|
try {
|
|
904
|
-
const created =
|
|
905
|
-
if (!created) {
|
|
906
|
-
const err =
|
|
907
|
-
|
|
911
|
+
const created = await this.hostSpace();
|
|
912
|
+
if (!created.success) {
|
|
913
|
+
const err = Object.assign(
|
|
914
|
+
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
915
|
+
{ cause: created }
|
|
916
|
+
);
|
|
908
917
|
throw err;
|
|
909
918
|
}
|
|
910
919
|
} catch (error) {
|
|
@@ -920,8 +929,9 @@ var NodeUserAuthorization = class {
|
|
|
920
929
|
this._tinyCloudSession.delegationHeader
|
|
921
930
|
);
|
|
922
931
|
if (!retryResult.success) {
|
|
923
|
-
const err =
|
|
924
|
-
`Failed to activate session after creating space: ${retryResult
|
|
932
|
+
const err = Object.assign(
|
|
933
|
+
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
934
|
+
{ cause: retryResult }
|
|
925
935
|
);
|
|
926
936
|
handler.onSpaceCreationFailed?.(creationContext, err);
|
|
927
937
|
throw err;
|
|
@@ -929,7 +939,10 @@ var NodeUserAuthorization = class {
|
|
|
929
939
|
handler.onSpaceCreated?.(creationContext);
|
|
930
940
|
return;
|
|
931
941
|
}
|
|
932
|
-
throw
|
|
942
|
+
throw Object.assign(
|
|
943
|
+
new Error(`Failed to activate session: ${describeHostFailure(result)}`),
|
|
944
|
+
{ cause: result }
|
|
945
|
+
);
|
|
933
946
|
}
|
|
934
947
|
recordActivationSkippedSpaces(result, primarySpaceId) {
|
|
935
948
|
if (result.success) {
|
|
@@ -2404,7 +2417,7 @@ function persistedExpiry(value) {
|
|
|
2404
2417
|
function sameInstant(left, right) {
|
|
2405
2418
|
return left.getTime() === right.getTime();
|
|
2406
2419
|
}
|
|
2407
|
-
function
|
|
2420
|
+
function describeHostFailure2(result) {
|
|
2408
2421
|
const text = result.error?.trim();
|
|
2409
2422
|
return text ? `${result.status} - ${text}` : `${result.status}`;
|
|
2410
2423
|
}
|
|
@@ -3211,7 +3224,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3211
3224
|
marker
|
|
3212
3225
|
);
|
|
3213
3226
|
if (!written.ok) {
|
|
3214
|
-
throw
|
|
3227
|
+
throw Object.assign(
|
|
3228
|
+
new Error(`Failed to write bootstrap completion marker: ${written.error.message}`),
|
|
3229
|
+
{ cause: written.error }
|
|
3230
|
+
);
|
|
3215
3231
|
}
|
|
3216
3232
|
}
|
|
3217
3233
|
isAcceptedBootstrapCompletionMarker(value) {
|
|
@@ -3257,17 +3273,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3257
3273
|
rawAbilities
|
|
3258
3274
|
});
|
|
3259
3275
|
} catch (err) {
|
|
3260
|
-
throw
|
|
3261
|
-
|
|
3276
|
+
throw Object.assign(
|
|
3277
|
+
new Error(
|
|
3278
|
+
`Account bootstrap aborted: signature rejected for space "${step.space}". Cause: ${err instanceof Error ? err.message : String(err)}`
|
|
3279
|
+
),
|
|
3280
|
+
{ cause: err }
|
|
3262
3281
|
);
|
|
3263
3282
|
}
|
|
3264
3283
|
sessions.set(step.space, session);
|
|
3265
3284
|
}
|
|
3266
3285
|
for (const step of steps) {
|
|
3267
3286
|
if (step.kind !== "host") continue;
|
|
3268
|
-
const hosted = await auth.
|
|
3269
|
-
if (!hosted) {
|
|
3270
|
-
throw
|
|
3287
|
+
const hosted = await auth.hostOwnedSpaceResult(step.spaceId, "bootstrap-host");
|
|
3288
|
+
if (!hosted.success) {
|
|
3289
|
+
throw Object.assign(
|
|
3290
|
+
new Error(`Failed to host bootstrap space ${step.spaceId}: ${describeHostFailure2(hosted)}`),
|
|
3291
|
+
{ cause: hosted }
|
|
3292
|
+
);
|
|
3271
3293
|
}
|
|
3272
3294
|
}
|
|
3273
3295
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -3279,8 +3301,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3279
3301
|
}
|
|
3280
3302
|
const activated = await (0, import_sdk_core8.activateSessionWithHost)(host, session.delegationHeader);
|
|
3281
3303
|
if (!activated.success || activated.skipped?.includes(step.spaceId)) {
|
|
3282
|
-
throw
|
|
3283
|
-
|
|
3304
|
+
throw Object.assign(
|
|
3305
|
+
new Error(
|
|
3306
|
+
`Failed to activate bootstrap session for ${step.spaceId}: ${activated.success ? "space was skipped" : describeHostFailure2(activated)}`
|
|
3307
|
+
),
|
|
3308
|
+
{ cause: activated }
|
|
3284
3309
|
);
|
|
3285
3310
|
}
|
|
3286
3311
|
this.registerBootstrapRuntimeGrant(
|
|
@@ -3293,7 +3318,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3293
3318
|
if (step.kind === "account-index-schema") {
|
|
3294
3319
|
const ensured = await this.account.index.ensure();
|
|
3295
3320
|
if (!ensured.ok) {
|
|
3296
|
-
throw new Error(`Failed to create account index schema: ${ensured.error.message}`);
|
|
3321
|
+
throw Object.assign(new Error(`Failed to create account index schema: ${ensured.error.message}`), { cause: ensured.error });
|
|
3297
3322
|
}
|
|
3298
3323
|
}
|
|
3299
3324
|
if (step.kind === "seed-spaces") {
|
|
@@ -3308,8 +3333,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3308
3333
|
}))
|
|
3309
3334
|
);
|
|
3310
3335
|
if (!registered.ok) {
|
|
3311
|
-
throw
|
|
3312
|
-
`Failed to seed account spaces: ${registered.error.message}`
|
|
3336
|
+
throw Object.assign(
|
|
3337
|
+
new Error(`Failed to seed account spaces: ${registered.error.message}`),
|
|
3338
|
+
{ cause: registered.error }
|
|
3313
3339
|
);
|
|
3314
3340
|
}
|
|
3315
3341
|
const batchError = registered.data.recoveredFromBatchError;
|
|
@@ -3330,7 +3356,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3330
3356
|
{ assumeUnregistered: true }
|
|
3331
3357
|
);
|
|
3332
3358
|
if (!registered.ok) {
|
|
3333
|
-
throw new Error(`Failed to seed bootstrap applications: ${registered.error.message}`);
|
|
3359
|
+
throw Object.assign(new Error(`Failed to seed bootstrap applications: ${registered.error.message}`), { cause: registered.error });
|
|
3334
3360
|
}
|
|
3335
3361
|
}
|
|
3336
3362
|
if (step.kind === "encryption-network-create") {
|
|
@@ -3348,8 +3374,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3348
3374
|
]
|
|
3349
3375
|
});
|
|
3350
3376
|
if (!migrated.ok) {
|
|
3351
|
-
throw
|
|
3352
|
-
`Failed to create secret_records schema: ${migrated.error.message}`
|
|
3377
|
+
throw Object.assign(
|
|
3378
|
+
new Error(`Failed to create secret_records schema: ${migrated.error.message}`),
|
|
3379
|
+
{ cause: migrated.error }
|
|
3353
3380
|
);
|
|
3354
3381
|
}
|
|
3355
3382
|
}
|
|
@@ -3694,14 +3721,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3694
3721
|
}
|
|
3695
3722
|
if (!activation.success && activation.status !== 404) {
|
|
3696
3723
|
throw Object.assign(
|
|
3697
|
-
new Error(`Failed to check owned space ${spaceId}: ${
|
|
3724
|
+
new Error(`Failed to check owned space ${spaceId}: ${describeHostFailure2(activation)}`),
|
|
3698
3725
|
{ cause: activation }
|
|
3699
3726
|
);
|
|
3700
3727
|
}
|
|
3701
3728
|
const created = await this.auth.hostOwnedSpaceResult(spaceId);
|
|
3702
3729
|
if (!created.success) {
|
|
3703
3730
|
throw Object.assign(
|
|
3704
|
-
new Error(`Failed to create owned space ${spaceId}: ${
|
|
3731
|
+
new Error(`Failed to create owned space ${spaceId}: ${describeHostFailure2(created)}`),
|
|
3705
3732
|
{ cause: created }
|
|
3706
3733
|
);
|
|
3707
3734
|
}
|
|
@@ -3710,7 +3737,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3710
3737
|
if (!retry.success || retry.skipped?.includes(spaceId)) {
|
|
3711
3738
|
throw Object.assign(
|
|
3712
3739
|
new Error(
|
|
3713
|
-
`Failed to activate session after creating owned space ${spaceId}: ${retry.success ? "space was skipped" :
|
|
3740
|
+
`Failed to activate session after creating owned space ${spaceId}: ${retry.success ? "space was skipped" : describeHostFailure2(retry)}`
|
|
3714
3741
|
),
|
|
3715
3742
|
{ cause: retry }
|
|
3716
3743
|
);
|
|
@@ -3747,19 +3774,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3747
3774
|
if (!host) {
|
|
3748
3775
|
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
3749
3776
|
}
|
|
3750
|
-
const hosted = await this.auth.
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3777
|
+
const hosted = await this.auth.hostOwnedSpaceResult(spaceId);
|
|
3778
|
+
if (!hosted.success) {
|
|
3779
|
+
throw Object.assign(
|
|
3780
|
+
new Error(`Failed to host owned space ${spaceId}: ${describeHostFailure2(hosted)}`),
|
|
3781
|
+
{ cause: hosted }
|
|
3782
|
+
);
|
|
3755
3783
|
}
|
|
3756
3784
|
const activation = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
3757
3785
|
host,
|
|
3758
3786
|
session.delegationHeader
|
|
3759
3787
|
);
|
|
3760
3788
|
if (!activation.success || activation.skipped?.includes(spaceId)) {
|
|
3761
|
-
throw
|
|
3762
|
-
|
|
3789
|
+
throw Object.assign(
|
|
3790
|
+
new Error(
|
|
3791
|
+
`Failed to activate session for owned space ${spaceId}: ${activation.success ? "space was skipped" : describeHostFailure2(activation)}`
|
|
3792
|
+
),
|
|
3793
|
+
{ cause: activation }
|
|
3763
3794
|
);
|
|
3764
3795
|
}
|
|
3765
3796
|
try {
|
|
@@ -4775,7 +4806,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4775
4806
|
if (cached) return cached;
|
|
4776
4807
|
const response = await fetch(`${this.config.host}/info`);
|
|
4777
4808
|
if (!response.ok) {
|
|
4778
|
-
throw
|
|
4809
|
+
throw await (0, import_sdk_core8.httpResponseError)(response, "Failed to fetch node info");
|
|
4779
4810
|
}
|
|
4780
4811
|
const info = await response.json();
|
|
4781
4812
|
if (typeof info.nodeId !== "string" || info.nodeId.length === 0) {
|
|
@@ -4825,9 +4856,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4825
4856
|
);
|
|
4826
4857
|
if (response.status === 404) return null;
|
|
4827
4858
|
if (!response.ok) {
|
|
4828
|
-
throw
|
|
4829
|
-
`Failed to fetch encryption network ${networkId}: HTTP ${response.status} ${await response.text()}`
|
|
4830
|
-
);
|
|
4859
|
+
throw await (0, import_sdk_core8.httpResponseError)(response, `Failed to fetch encryption network ${networkId}`);
|
|
4831
4860
|
}
|
|
4832
4861
|
const body = await response.json();
|
|
4833
4862
|
return "descriptor" in body && body.descriptor ? body.descriptor : body;
|
|
@@ -5328,7 +5357,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5328
5357
|
headers: { accept: "application/json", "content-type": "application/json", authorization },
|
|
5329
5358
|
body: (0, import_sdk_core8.canonicalizeEncryptionJson)(request)
|
|
5330
5359
|
});
|
|
5331
|
-
if (!response.ok) throw
|
|
5360
|
+
if (!response.ok) throw await (0, import_sdk_core8.httpResponseError)(response, "V3 share delivery authorization failed");
|
|
5332
5361
|
const verified = (0, import_sdk_core8.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
|
|
5333
5362
|
request,
|
|
5334
5363
|
senderKeyDid: this.credentialHolderDid,
|
|
@@ -5550,9 +5579,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5550
5579
|
);
|
|
5551
5580
|
}
|
|
5552
5581
|
if (!response.ok) {
|
|
5553
|
-
throw
|
|
5554
|
-
`Failed to create encryption network ${networkId}: HTTP ${response.status} ${await response.text()}`
|
|
5555
|
-
);
|
|
5582
|
+
throw await (0, import_sdk_core8.httpResponseError)(response, `Failed to create encryption network ${networkId}`);
|
|
5556
5583
|
}
|
|
5557
5584
|
const created = await response.json();
|
|
5558
5585
|
return created.descriptor;
|
|
@@ -5860,8 +5887,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5860
5887
|
delegation.delegationHeader
|
|
5861
5888
|
);
|
|
5862
5889
|
if (!activateResult.success) {
|
|
5863
|
-
throw
|
|
5864
|
-
`Failed to activate runtime permission delegation: ${activateResult
|
|
5890
|
+
throw Object.assign(
|
|
5891
|
+
new Error(`Failed to activate runtime permission delegation: ${describeHostFailure2(activateResult)}`),
|
|
5892
|
+
{ cause: activateResult }
|
|
5865
5893
|
);
|
|
5866
5894
|
}
|
|
5867
5895
|
this.runtimePermissionGrants = this.runtimePermissionGrants.filter(
|
|
@@ -5957,8 +5985,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5957
5985
|
delegatedSession.delegationHeader
|
|
5958
5986
|
);
|
|
5959
5987
|
if (!activateResult.success) {
|
|
5960
|
-
throw
|
|
5961
|
-
`Failed to activate runtime permission delegation: ${activateResult
|
|
5988
|
+
throw Object.assign(
|
|
5989
|
+
new Error(`Failed to activate runtime permission delegation: ${describeHostFailure2(activateResult)}`),
|
|
5990
|
+
{ cause: activateResult }
|
|
5962
5991
|
);
|
|
5963
5992
|
}
|
|
5964
5993
|
const delegation = this.runtimeDelegationFromSession(
|
|
@@ -6143,7 +6172,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6143
6172
|
delegationSession.delegationHeader
|
|
6144
6173
|
);
|
|
6145
6174
|
if (!activateResult.success) {
|
|
6146
|
-
throw
|
|
6175
|
+
throw Object.assign(
|
|
6176
|
+
new Error(`Failed to activate public space delegation: ${describeHostFailure2(activateResult)}`),
|
|
6177
|
+
{ cause: activateResult }
|
|
6178
|
+
);
|
|
6147
6179
|
}
|
|
6148
6180
|
if (this._capabilityRegistry && this.session) {
|
|
6149
6181
|
const sessionKey = {
|
|
@@ -6496,8 +6528,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6496
6528
|
delegationHeader
|
|
6497
6529
|
);
|
|
6498
6530
|
if (!activateResult.success) {
|
|
6499
|
-
throw
|
|
6500
|
-
`Failed to activate delegation with host: ${activateResult
|
|
6531
|
+
throw Object.assign(
|
|
6532
|
+
new Error(`Failed to activate delegation with host: ${describeHostFailure2(activateResult)}`),
|
|
6533
|
+
{ cause: activateResult }
|
|
6501
6534
|
);
|
|
6502
6535
|
}
|
|
6503
6536
|
return {
|
|
@@ -6533,8 +6566,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6533
6566
|
delegationHeader
|
|
6534
6567
|
);
|
|
6535
6568
|
if (!activateResult.success) {
|
|
6536
|
-
throw
|
|
6537
|
-
`Failed to activate delegation with host: ${activateResult
|
|
6569
|
+
throw Object.assign(
|
|
6570
|
+
new Error(`Failed to activate delegation with host: ${describeHostFailure2(activateResult)}`),
|
|
6571
|
+
{ cause: activateResult }
|
|
6538
6572
|
);
|
|
6539
6573
|
}
|
|
6540
6574
|
return {
|
|
@@ -7141,7 +7175,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7141
7175
|
delegationSession.delegationHeader
|
|
7142
7176
|
);
|
|
7143
7177
|
if (!activateResult.success) {
|
|
7144
|
-
throw
|
|
7178
|
+
throw Object.assign(
|
|
7179
|
+
new Error(`Failed to activate delegation: ${describeHostFailure2(activateResult)}`),
|
|
7180
|
+
{ cause: activateResult }
|
|
7181
|
+
);
|
|
7145
7182
|
}
|
|
7146
7183
|
const result = {
|
|
7147
7184
|
cid: delegationSession.delegationCid,
|
|
@@ -7291,7 +7328,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7291
7328
|
invokerSession.delegationHeader
|
|
7292
7329
|
);
|
|
7293
7330
|
if (!activateResult.success) {
|
|
7294
|
-
throw
|
|
7331
|
+
throw Object.assign(
|
|
7332
|
+
new Error(`Failed to activate delegated session: ${describeHostFailure2(activateResult)}`),
|
|
7333
|
+
{ cause: activateResult }
|
|
7334
|
+
);
|
|
7295
7335
|
}
|
|
7296
7336
|
const session = {
|
|
7297
7337
|
address: mySession.address,
|
|
@@ -7408,7 +7448,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7408
7448
|
subDelegationSession.delegationHeader
|
|
7409
7449
|
);
|
|
7410
7450
|
if (!activateResult.success) {
|
|
7411
|
-
throw
|
|
7451
|
+
throw Object.assign(
|
|
7452
|
+
new Error(`Failed to activate sub-delegation: ${describeHostFailure2(activateResult)}`),
|
|
7453
|
+
{ cause: activateResult }
|
|
7454
|
+
);
|
|
7412
7455
|
}
|
|
7413
7456
|
return {
|
|
7414
7457
|
cid: subDelegationSession.delegationCid,
|