@tinycloud/node-sdk 3.1.0-beta.1 → 3.1.0-beta.10
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-Bm76PnOz.d.cts → core-CC7uDKZP.d.cts} +77 -6
- package/dist/{core-Bm76PnOz.d.ts → core-CC7uDKZP.d.ts} +77 -6
- package/dist/core.cjs +308 -111
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +314 -112
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +366 -143
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +372 -145
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -4404,19 +4404,19 @@ var init_lib4 = __esm({
|
|
|
4404
4404
|
resolve(value);
|
|
4405
4405
|
});
|
|
4406
4406
|
}
|
|
4407
|
-
return new (P || (P = Promise))(function(resolve,
|
|
4407
|
+
return new (P || (P = Promise))(function(resolve, reject2) {
|
|
4408
4408
|
function fulfilled(value) {
|
|
4409
4409
|
try {
|
|
4410
4410
|
step(generator.next(value));
|
|
4411
4411
|
} catch (e) {
|
|
4412
|
-
|
|
4412
|
+
reject2(e);
|
|
4413
4413
|
}
|
|
4414
4414
|
}
|
|
4415
4415
|
function rejected(value) {
|
|
4416
4416
|
try {
|
|
4417
4417
|
step(generator["throw"](value));
|
|
4418
4418
|
} catch (e) {
|
|
4419
|
-
|
|
4419
|
+
reject2(e);
|
|
4420
4420
|
}
|
|
4421
4421
|
}
|
|
4422
4422
|
function step(result) {
|
|
@@ -8040,19 +8040,19 @@ var init_typed_data = __esm({
|
|
|
8040
8040
|
resolve(value);
|
|
8041
8041
|
});
|
|
8042
8042
|
}
|
|
8043
|
-
return new (P || (P = Promise))(function(resolve,
|
|
8043
|
+
return new (P || (P = Promise))(function(resolve, reject2) {
|
|
8044
8044
|
function fulfilled(value) {
|
|
8045
8045
|
try {
|
|
8046
8046
|
step(generator.next(value));
|
|
8047
8047
|
} catch (e) {
|
|
8048
|
-
|
|
8048
|
+
reject2(e);
|
|
8049
8049
|
}
|
|
8050
8050
|
}
|
|
8051
8051
|
function rejected(value) {
|
|
8052
8052
|
try {
|
|
8053
8053
|
step(generator["throw"](value));
|
|
8054
8054
|
} catch (e) {
|
|
8055
|
-
|
|
8055
|
+
reject2(e);
|
|
8056
8056
|
}
|
|
8057
8057
|
}
|
|
8058
8058
|
function step(result) {
|
|
@@ -14898,14 +14898,14 @@ var require_scrypt = __commonJS({
|
|
|
14898
14898
|
}
|
|
14899
14899
|
const lib = {
|
|
14900
14900
|
scrypt: function(password, salt, N2, r2, p, dkLen, progressCallback) {
|
|
14901
|
-
return new Promise(function(resolve,
|
|
14901
|
+
return new Promise(function(resolve, reject2) {
|
|
14902
14902
|
let lastProgress = 0;
|
|
14903
14903
|
if (progressCallback) {
|
|
14904
14904
|
progressCallback(0);
|
|
14905
14905
|
}
|
|
14906
14906
|
_scrypt(password, salt, N2, r2, p, dkLen, function(error, progress, key2) {
|
|
14907
14907
|
if (error) {
|
|
14908
|
-
|
|
14908
|
+
reject2(error);
|
|
14909
14909
|
} else if (key2) {
|
|
14910
14910
|
if (progressCallback && lastProgress !== 1) {
|
|
14911
14911
|
progressCallback(1);
|
|
@@ -15294,19 +15294,19 @@ var init_keystore = __esm({
|
|
|
15294
15294
|
resolve(value);
|
|
15295
15295
|
});
|
|
15296
15296
|
}
|
|
15297
|
-
return new (P || (P = Promise))(function(resolve,
|
|
15297
|
+
return new (P || (P = Promise))(function(resolve, reject2) {
|
|
15298
15298
|
function fulfilled(value) {
|
|
15299
15299
|
try {
|
|
15300
15300
|
step(generator.next(value));
|
|
15301
15301
|
} catch (e) {
|
|
15302
|
-
|
|
15302
|
+
reject2(e);
|
|
15303
15303
|
}
|
|
15304
15304
|
}
|
|
15305
15305
|
function rejected(value) {
|
|
15306
15306
|
try {
|
|
15307
15307
|
step(generator["throw"](value));
|
|
15308
15308
|
} catch (e) {
|
|
15309
|
-
|
|
15309
|
+
reject2(e);
|
|
15310
15310
|
}
|
|
15311
15311
|
}
|
|
15312
15312
|
function step(result) {
|
|
@@ -15607,19 +15607,19 @@ var init_lib25 = __esm({
|
|
|
15607
15607
|
resolve(value);
|
|
15608
15608
|
});
|
|
15609
15609
|
}
|
|
15610
|
-
return new (P || (P = Promise))(function(resolve,
|
|
15610
|
+
return new (P || (P = Promise))(function(resolve, reject2) {
|
|
15611
15611
|
function fulfilled(value) {
|
|
15612
15612
|
try {
|
|
15613
15613
|
step(generator.next(value));
|
|
15614
15614
|
} catch (e) {
|
|
15615
|
-
|
|
15615
|
+
reject2(e);
|
|
15616
15616
|
}
|
|
15617
15617
|
}
|
|
15618
15618
|
function rejected(value) {
|
|
15619
15619
|
try {
|
|
15620
15620
|
step(generator["throw"](value));
|
|
15621
15621
|
} catch (e) {
|
|
15622
|
-
|
|
15622
|
+
reject2(e);
|
|
15623
15623
|
}
|
|
15624
15624
|
}
|
|
15625
15625
|
function step(result) {
|
|
@@ -15689,19 +15689,19 @@ var init_lib26 = __esm({
|
|
|
15689
15689
|
resolve(value);
|
|
15690
15690
|
});
|
|
15691
15691
|
}
|
|
15692
|
-
return new (P || (P = Promise))(function(resolve,
|
|
15692
|
+
return new (P || (P = Promise))(function(resolve, reject2) {
|
|
15693
15693
|
function fulfilled(value) {
|
|
15694
15694
|
try {
|
|
15695
15695
|
step(generator.next(value));
|
|
15696
15696
|
} catch (e) {
|
|
15697
|
-
|
|
15697
|
+
reject2(e);
|
|
15698
15698
|
}
|
|
15699
15699
|
}
|
|
15700
15700
|
function rejected(value) {
|
|
15701
15701
|
try {
|
|
15702
15702
|
step(generator["throw"](value));
|
|
15703
15703
|
} catch (e) {
|
|
15704
|
-
|
|
15704
|
+
reject2(e);
|
|
15705
15705
|
}
|
|
15706
15706
|
}
|
|
15707
15707
|
function step(result) {
|
|
@@ -16011,19 +16011,19 @@ var init_lib27 = __esm({
|
|
|
16011
16011
|
resolve(value);
|
|
16012
16012
|
});
|
|
16013
16013
|
}
|
|
16014
|
-
return new (P || (P = Promise))(function(resolve,
|
|
16014
|
+
return new (P || (P = Promise))(function(resolve, reject2) {
|
|
16015
16015
|
function fulfilled(value) {
|
|
16016
16016
|
try {
|
|
16017
16017
|
step(generator.next(value));
|
|
16018
16018
|
} catch (e) {
|
|
16019
|
-
|
|
16019
|
+
reject2(e);
|
|
16020
16020
|
}
|
|
16021
16021
|
}
|
|
16022
16022
|
function rejected(value) {
|
|
16023
16023
|
try {
|
|
16024
16024
|
step(generator["throw"](value));
|
|
16025
16025
|
} catch (e) {
|
|
16026
|
-
|
|
16026
|
+
reject2(e);
|
|
16027
16027
|
}
|
|
16028
16028
|
}
|
|
16029
16029
|
function step(result) {
|
|
@@ -16249,19 +16249,19 @@ var init_geturl = __esm({
|
|
|
16249
16249
|
resolve(value);
|
|
16250
16250
|
});
|
|
16251
16251
|
}
|
|
16252
|
-
return new (P || (P = Promise))(function(resolve,
|
|
16252
|
+
return new (P || (P = Promise))(function(resolve, reject2) {
|
|
16253
16253
|
function fulfilled(value) {
|
|
16254
16254
|
try {
|
|
16255
16255
|
step(generator.next(value));
|
|
16256
16256
|
} catch (e) {
|
|
16257
|
-
|
|
16257
|
+
reject2(e);
|
|
16258
16258
|
}
|
|
16259
16259
|
}
|
|
16260
16260
|
function rejected(value) {
|
|
16261
16261
|
try {
|
|
16262
16262
|
step(generator["throw"](value));
|
|
16263
16263
|
} catch (e) {
|
|
16264
|
-
|
|
16264
|
+
reject2(e);
|
|
16265
16265
|
}
|
|
16266
16266
|
}
|
|
16267
16267
|
function step(result) {
|
|
@@ -16402,14 +16402,14 @@ function _fetchData(connection, body, processFunc) {
|
|
|
16402
16402
|
options.headers = flatHeaders;
|
|
16403
16403
|
const runningTimeout = (function() {
|
|
16404
16404
|
let timer = null;
|
|
16405
|
-
const promise = new Promise(function(resolve,
|
|
16405
|
+
const promise = new Promise(function(resolve, reject2) {
|
|
16406
16406
|
if (timeout) {
|
|
16407
16407
|
timer = setTimeout(() => {
|
|
16408
16408
|
if (timer == null) {
|
|
16409
16409
|
return;
|
|
16410
16410
|
}
|
|
16411
16411
|
timer = null;
|
|
16412
|
-
|
|
16412
|
+
reject2(logger28.makeError("timeout", Logger.errors.TIMEOUT, {
|
|
16413
16413
|
requestBody: bodyify(options.body, flatHeaders["content-type"]),
|
|
16414
16414
|
requestMethod: options.method,
|
|
16415
16415
|
timeout,
|
|
@@ -16572,7 +16572,7 @@ function poll(func, options) {
|
|
|
16572
16572
|
if (options.interval == null) {
|
|
16573
16573
|
options.interval = 250;
|
|
16574
16574
|
}
|
|
16575
|
-
return new Promise(function(resolve,
|
|
16575
|
+
return new Promise(function(resolve, reject2) {
|
|
16576
16576
|
let timer = null;
|
|
16577
16577
|
let done = false;
|
|
16578
16578
|
const cancel = () => {
|
|
@@ -16588,7 +16588,7 @@ function poll(func, options) {
|
|
|
16588
16588
|
if (options.timeout) {
|
|
16589
16589
|
timer = setTimeout(() => {
|
|
16590
16590
|
if (cancel()) {
|
|
16591
|
-
|
|
16591
|
+
reject2(new Error("timeout"));
|
|
16592
16592
|
}
|
|
16593
16593
|
}, options.timeout);
|
|
16594
16594
|
}
|
|
@@ -16608,7 +16608,7 @@ function poll(func, options) {
|
|
|
16608
16608
|
attempt++;
|
|
16609
16609
|
if (attempt > retryLimit) {
|
|
16610
16610
|
if (cancel()) {
|
|
16611
|
-
|
|
16611
|
+
reject2(new Error("retry limit reached"));
|
|
16612
16612
|
}
|
|
16613
16613
|
return;
|
|
16614
16614
|
}
|
|
@@ -16624,7 +16624,7 @@ function poll(func, options) {
|
|
|
16624
16624
|
return null;
|
|
16625
16625
|
}, function(error) {
|
|
16626
16626
|
if (cancel()) {
|
|
16627
|
-
|
|
16627
|
+
reject2(error);
|
|
16628
16628
|
}
|
|
16629
16629
|
});
|
|
16630
16630
|
}
|
|
@@ -16648,19 +16648,19 @@ var init_lib28 = __esm({
|
|
|
16648
16648
|
resolve(value);
|
|
16649
16649
|
});
|
|
16650
16650
|
}
|
|
16651
|
-
return new (P || (P = Promise))(function(resolve,
|
|
16651
|
+
return new (P || (P = Promise))(function(resolve, reject2) {
|
|
16652
16652
|
function fulfilled(value) {
|
|
16653
16653
|
try {
|
|
16654
16654
|
step(generator.next(value));
|
|
16655
16655
|
} catch (e) {
|
|
16656
|
-
|
|
16656
|
+
reject2(e);
|
|
16657
16657
|
}
|
|
16658
16658
|
}
|
|
16659
16659
|
function rejected(value) {
|
|
16660
16660
|
try {
|
|
16661
16661
|
step(generator["throw"](value));
|
|
16662
16662
|
} catch (e) {
|
|
16663
|
-
|
|
16663
|
+
reject2(e);
|
|
16664
16664
|
}
|
|
16665
16665
|
}
|
|
16666
16666
|
function step(result) {
|
|
@@ -17072,9 +17072,13 @@ __export(index_exports, {
|
|
|
17072
17072
|
PrefixedKVService: () => import_sdk_core13.PrefixedKVService,
|
|
17073
17073
|
PrivateKeySigner: () => PrivateKeySigner,
|
|
17074
17074
|
ProtocolMismatchError: () => import_sdk_core22.ProtocolMismatchError,
|
|
17075
|
+
RUNTIME_DELEGATION_REJECTIONS: () => RUNTIME_DELEGATION_REJECTIONS,
|
|
17076
|
+
RuntimeDelegationRejectedError: () => RuntimeDelegationRejectedError,
|
|
17075
17077
|
SECRET_NAME_RE: () => import_sdk_core16.SECRET_NAME_RE,
|
|
17076
17078
|
SQLAction: () => import_sdk_core14.SQLAction,
|
|
17077
17079
|
SQLService: () => import_sdk_core14.SQLService,
|
|
17080
|
+
STORAGE_FULL_MESSAGE: () => import_sdk_core11.STORAGE_FULL_MESSAGE,
|
|
17081
|
+
STORAGE_WRITE_TOO_LARGE_MESSAGE: () => import_sdk_core11.STORAGE_WRITE_TOO_LARGE_MESSAGE,
|
|
17078
17082
|
SecretsService: () => import_sdk_core16.SecretsService,
|
|
17079
17083
|
ServiceContext: () => import_sdk_core23.ServiceContext,
|
|
17080
17084
|
SessionExpiredError: () => import_sdk_core12.SessionExpiredError,
|
|
@@ -17150,6 +17154,7 @@ __export(index_exports, {
|
|
|
17150
17154
|
isCapabilitySubset: () => import_sdk_core12.isCapabilitySubset,
|
|
17151
17155
|
isEvmAddress: () => import_sdk_core11.isEvmAddress,
|
|
17152
17156
|
isNetworkId: () => import_sdk_core17.isNetworkId,
|
|
17157
|
+
isStorageFullError: () => import_sdk_core11.isStorageFullError,
|
|
17153
17158
|
loadManifest: () => import_sdk_core12.loadManifest,
|
|
17154
17159
|
makePkhSpaceId: () => import_sdk_core11.makePkhSpaceId,
|
|
17155
17160
|
makePublicSpaceId: () => import_sdk_core21.makePublicSpaceId,
|
|
@@ -17210,6 +17215,9 @@ var _NodeWasmBindings = class _NodeWasmBindings {
|
|
|
17210
17215
|
validatePersistedSession(proof) {
|
|
17211
17216
|
return (0, import_node_sdk_wasm.validatePersistedSession)(proof);
|
|
17212
17217
|
}
|
|
17218
|
+
validateSessionGrant(proof) {
|
|
17219
|
+
return (0, import_node_sdk_wasm.validateSessionGrant)(proof);
|
|
17220
|
+
}
|
|
17213
17221
|
createSessionManager() {
|
|
17214
17222
|
return new import_node_sdk_wasm.TCWSessionManager();
|
|
17215
17223
|
}
|
|
@@ -17368,6 +17376,10 @@ var MemorySessionStorage = class {
|
|
|
17368
17376
|
// src/authorization/NodeUserAuthorization.ts
|
|
17369
17377
|
var DECRYPT_ACTION = import_sdk_core2.ENCRYPTION.DECRYPT;
|
|
17370
17378
|
var NETWORK_CREATE_ACTION = import_sdk_core2.ENCRYPTION.NETWORK_CREATE;
|
|
17379
|
+
function describeHostFailure(result) {
|
|
17380
|
+
const text = result.error?.trim();
|
|
17381
|
+
return text ? `${result.status} - ${text}` : `${result.status}`;
|
|
17382
|
+
}
|
|
17371
17383
|
function canonicalizeOpenKeyManifestJson(value) {
|
|
17372
17384
|
const json = JSON.stringify(value);
|
|
17373
17385
|
if (json === void 0) {
|
|
@@ -17896,10 +17908,12 @@ var NodeUserAuthorization = class {
|
|
|
17896
17908
|
return;
|
|
17897
17909
|
}
|
|
17898
17910
|
try {
|
|
17899
|
-
const created =
|
|
17900
|
-
if (!created) {
|
|
17901
|
-
const err =
|
|
17902
|
-
|
|
17911
|
+
const created = await this.hostSpace();
|
|
17912
|
+
if (!created.success) {
|
|
17913
|
+
const err = Object.assign(
|
|
17914
|
+
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
17915
|
+
{ cause: created }
|
|
17916
|
+
);
|
|
17903
17917
|
throw err;
|
|
17904
17918
|
}
|
|
17905
17919
|
} catch (error) {
|
|
@@ -17915,8 +17929,9 @@ var NodeUserAuthorization = class {
|
|
|
17915
17929
|
this._tinyCloudSession.delegationHeader
|
|
17916
17930
|
);
|
|
17917
17931
|
if (!retryResult.success) {
|
|
17918
|
-
const err =
|
|
17919
|
-
`Failed to activate session after creating space: ${retryResult
|
|
17932
|
+
const err = Object.assign(
|
|
17933
|
+
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
17934
|
+
{ cause: retryResult }
|
|
17920
17935
|
);
|
|
17921
17936
|
handler.onSpaceCreationFailed?.(creationContext, err);
|
|
17922
17937
|
throw err;
|
|
@@ -17933,10 +17948,12 @@ var NodeUserAuthorization = class {
|
|
|
17933
17948
|
return;
|
|
17934
17949
|
}
|
|
17935
17950
|
try {
|
|
17936
|
-
const created =
|
|
17937
|
-
if (!created) {
|
|
17938
|
-
const err =
|
|
17939
|
-
|
|
17951
|
+
const created = await this.hostSpace();
|
|
17952
|
+
if (!created.success) {
|
|
17953
|
+
const err = Object.assign(
|
|
17954
|
+
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
17955
|
+
{ cause: created }
|
|
17956
|
+
);
|
|
17940
17957
|
throw err;
|
|
17941
17958
|
}
|
|
17942
17959
|
} catch (error) {
|
|
@@ -17952,8 +17969,9 @@ var NodeUserAuthorization = class {
|
|
|
17952
17969
|
this._tinyCloudSession.delegationHeader
|
|
17953
17970
|
);
|
|
17954
17971
|
if (!retryResult.success) {
|
|
17955
|
-
const err =
|
|
17956
|
-
`Failed to activate session after creating space: ${retryResult
|
|
17972
|
+
const err = Object.assign(
|
|
17973
|
+
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
17974
|
+
{ cause: retryResult }
|
|
17957
17975
|
);
|
|
17958
17976
|
handler.onSpaceCreationFailed?.(creationContext, err);
|
|
17959
17977
|
throw err;
|
|
@@ -17961,7 +17979,10 @@ var NodeUserAuthorization = class {
|
|
|
17961
17979
|
handler.onSpaceCreated?.(creationContext);
|
|
17962
17980
|
return;
|
|
17963
17981
|
}
|
|
17964
|
-
throw
|
|
17982
|
+
throw Object.assign(
|
|
17983
|
+
new Error(`Failed to activate session: ${describeHostFailure(result)}`),
|
|
17984
|
+
{ cause: result }
|
|
17985
|
+
);
|
|
17965
17986
|
}
|
|
17966
17987
|
recordActivationSkippedSpaces(result, primarySpaceId) {
|
|
17967
17988
|
if (result.success) {
|
|
@@ -18751,14 +18772,14 @@ var NodeUserAuthorization = class {
|
|
|
18751
18772
|
* Request signature via event emitter with timeout.
|
|
18752
18773
|
*/
|
|
18753
18774
|
requestSignatureViaEmitter(request, emitter, timeout) {
|
|
18754
|
-
return new Promise((resolve,
|
|
18775
|
+
return new Promise((resolve, reject2) => {
|
|
18755
18776
|
const timeoutId = setTimeout(() => {
|
|
18756
|
-
|
|
18777
|
+
reject2(new Error("Sign request timed out"));
|
|
18757
18778
|
}, timeout);
|
|
18758
18779
|
const respond = async (response) => {
|
|
18759
18780
|
clearTimeout(timeoutId);
|
|
18760
18781
|
if (!response.approved) {
|
|
18761
|
-
|
|
18782
|
+
reject2(
|
|
18762
18783
|
new Error(response.reason ?? "Sign request rejected via emitter")
|
|
18763
18784
|
);
|
|
18764
18785
|
} else {
|
|
@@ -19337,6 +19358,25 @@ function jsonFromVerifier(value) {
|
|
|
19337
19358
|
function verifierRecapEntries(entries) {
|
|
19338
19359
|
return entries.map((entry) => Array.isArray(entry.caveats) ? { ...entry, caveats: entry.caveats.map((caveat) => jsonFromVerifier(caveat)) } : entry);
|
|
19339
19360
|
}
|
|
19361
|
+
function exactVerifiedRecap(verified) {
|
|
19362
|
+
const exactRecap = Array.isArray(verified.verifiedRecap) ? verifierRecapEntries(verified.verifiedRecap) : verified.verifiedRecap;
|
|
19363
|
+
if (!Array.isArray(exactRecap) || !exactRecap.every(
|
|
19364
|
+
(entry) => entry !== null && typeof entry === "object" && typeof entry.service === "string" && typeof entry.space === "string" && typeof entry.path === "string" && Array.isArray(entry.actions) && entry.actions.every((action) => typeof action === "string") && Array.isArray(entry.caveats) && entry.caveats.every(
|
|
19365
|
+
(caveat) => caveat !== null && typeof caveat === "object" && !Array.isArray(caveat)
|
|
19366
|
+
)
|
|
19367
|
+
)) {
|
|
19368
|
+
throw new UnsupportedSessionRestoreError(
|
|
19369
|
+
"it cannot reconstruct caveat-preserving persisted ReCap authority"
|
|
19370
|
+
);
|
|
19371
|
+
}
|
|
19372
|
+
return exactRecap.map((entry) => ({
|
|
19373
|
+
service: entry.service,
|
|
19374
|
+
space: entry.space,
|
|
19375
|
+
path: entry.path,
|
|
19376
|
+
actions: [...entry.actions],
|
|
19377
|
+
caveats: cloneRecapCaveats(entry.caveats)
|
|
19378
|
+
}));
|
|
19379
|
+
}
|
|
19340
19380
|
var ServiceGraphLifetime = class {
|
|
19341
19381
|
constructor(invokeFn, invokeAnyFn, fetchFn) {
|
|
19342
19382
|
this.invokeFn = invokeFn;
|
|
@@ -19432,7 +19472,7 @@ function persistedExpiry(value) {
|
|
|
19432
19472
|
function sameInstant(left, right) {
|
|
19433
19473
|
return left.getTime() === right.getTime();
|
|
19434
19474
|
}
|
|
19435
|
-
function
|
|
19475
|
+
function describeHostFailure2(result) {
|
|
19436
19476
|
const text = result.error?.trim();
|
|
19437
19477
|
return text ? `${result.status} - ${text}` : `${result.status}`;
|
|
19438
19478
|
}
|
|
@@ -20239,7 +20279,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20239
20279
|
marker
|
|
20240
20280
|
);
|
|
20241
20281
|
if (!written.ok) {
|
|
20242
|
-
throw
|
|
20282
|
+
throw Object.assign(
|
|
20283
|
+
new Error(`Failed to write bootstrap completion marker: ${written.error.message}`),
|
|
20284
|
+
{ cause: written.error }
|
|
20285
|
+
);
|
|
20243
20286
|
}
|
|
20244
20287
|
}
|
|
20245
20288
|
isAcceptedBootstrapCompletionMarker(value) {
|
|
@@ -20285,17 +20328,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20285
20328
|
rawAbilities
|
|
20286
20329
|
});
|
|
20287
20330
|
} catch (err) {
|
|
20288
|
-
throw
|
|
20289
|
-
|
|
20331
|
+
throw Object.assign(
|
|
20332
|
+
new Error(
|
|
20333
|
+
`Account bootstrap aborted: signature rejected for space "${step.space}". Cause: ${err instanceof Error ? err.message : String(err)}`
|
|
20334
|
+
),
|
|
20335
|
+
{ cause: err }
|
|
20290
20336
|
);
|
|
20291
20337
|
}
|
|
20292
20338
|
sessions.set(step.space, session);
|
|
20293
20339
|
}
|
|
20294
20340
|
for (const step of steps) {
|
|
20295
20341
|
if (step.kind !== "host") continue;
|
|
20296
|
-
const hosted = await auth.
|
|
20297
|
-
if (!hosted) {
|
|
20298
|
-
throw
|
|
20342
|
+
const hosted = await auth.hostOwnedSpaceResult(step.spaceId, "bootstrap-host");
|
|
20343
|
+
if (!hosted.success) {
|
|
20344
|
+
throw Object.assign(
|
|
20345
|
+
new Error(`Failed to host bootstrap space ${step.spaceId}: ${describeHostFailure2(hosted)}`),
|
|
20346
|
+
{ cause: hosted }
|
|
20347
|
+
);
|
|
20299
20348
|
}
|
|
20300
20349
|
}
|
|
20301
20350
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -20307,8 +20356,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20307
20356
|
}
|
|
20308
20357
|
const activated = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
|
|
20309
20358
|
if (!activated.success || activated.skipped?.includes(step.spaceId)) {
|
|
20310
|
-
throw
|
|
20311
|
-
|
|
20359
|
+
throw Object.assign(
|
|
20360
|
+
new Error(
|
|
20361
|
+
`Failed to activate bootstrap session for ${step.spaceId}: ${activated.success ? "space was skipped" : describeHostFailure2(activated)}`
|
|
20362
|
+
),
|
|
20363
|
+
{ cause: activated }
|
|
20312
20364
|
);
|
|
20313
20365
|
}
|
|
20314
20366
|
this.registerBootstrapRuntimeGrant(
|
|
@@ -20321,7 +20373,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20321
20373
|
if (step.kind === "account-index-schema") {
|
|
20322
20374
|
const ensured = await this.account.index.ensure();
|
|
20323
20375
|
if (!ensured.ok) {
|
|
20324
|
-
throw new Error(`Failed to create account index schema: ${ensured.error.message}`);
|
|
20376
|
+
throw Object.assign(new Error(`Failed to create account index schema: ${ensured.error.message}`), { cause: ensured.error });
|
|
20325
20377
|
}
|
|
20326
20378
|
}
|
|
20327
20379
|
if (step.kind === "seed-spaces") {
|
|
@@ -20336,8 +20388,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20336
20388
|
}))
|
|
20337
20389
|
);
|
|
20338
20390
|
if (!registered.ok) {
|
|
20339
|
-
throw
|
|
20340
|
-
`Failed to seed account spaces: ${registered.error.message}`
|
|
20391
|
+
throw Object.assign(
|
|
20392
|
+
new Error(`Failed to seed account spaces: ${registered.error.message}`),
|
|
20393
|
+
{ cause: registered.error }
|
|
20341
20394
|
);
|
|
20342
20395
|
}
|
|
20343
20396
|
const batchError = registered.data.recoveredFromBatchError;
|
|
@@ -20358,7 +20411,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20358
20411
|
{ assumeUnregistered: true }
|
|
20359
20412
|
);
|
|
20360
20413
|
if (!registered.ok) {
|
|
20361
|
-
throw new Error(`Failed to seed bootstrap applications: ${registered.error.message}`);
|
|
20414
|
+
throw Object.assign(new Error(`Failed to seed bootstrap applications: ${registered.error.message}`), { cause: registered.error });
|
|
20362
20415
|
}
|
|
20363
20416
|
}
|
|
20364
20417
|
if (step.kind === "encryption-network-create") {
|
|
@@ -20376,8 +20429,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20376
20429
|
]
|
|
20377
20430
|
});
|
|
20378
20431
|
if (!migrated.ok) {
|
|
20379
|
-
throw
|
|
20380
|
-
`Failed to create secret_records schema: ${migrated.error.message}`
|
|
20432
|
+
throw Object.assign(
|
|
20433
|
+
new Error(`Failed to create secret_records schema: ${migrated.error.message}`),
|
|
20434
|
+
{ cause: migrated.error }
|
|
20381
20435
|
);
|
|
20382
20436
|
}
|
|
20383
20437
|
}
|
|
@@ -20644,6 +20698,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20644
20698
|
);
|
|
20645
20699
|
return;
|
|
20646
20700
|
}
|
|
20701
|
+
if ((0, import_sdk_core7.isStorageFullError)(error) || (0, import_sdk_core7.isStorageFullError)(error?.cause) || message.includes(import_sdk_core7.STORAGE_FULL_MESSAGE) || message.includes(import_sdk_core7.STORAGE_WRITE_TOO_LARGE_MESSAGE)) {
|
|
20702
|
+
console.warn("TinyCloud account registry sync stopped: storage is full", error);
|
|
20703
|
+
return;
|
|
20704
|
+
}
|
|
20647
20705
|
lastError = error;
|
|
20648
20706
|
if (attempt < delays.length - 1) {
|
|
20649
20707
|
await new Promise((resolve) => setTimeout(resolve, delays[attempt]));
|
|
@@ -20718,14 +20776,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20718
20776
|
}
|
|
20719
20777
|
if (!activation.success && activation.status !== 404) {
|
|
20720
20778
|
throw Object.assign(
|
|
20721
|
-
new Error(`Failed to check owned space ${spaceId}: ${
|
|
20779
|
+
new Error(`Failed to check owned space ${spaceId}: ${describeHostFailure2(activation)}`),
|
|
20722
20780
|
{ cause: activation }
|
|
20723
20781
|
);
|
|
20724
20782
|
}
|
|
20725
20783
|
const created = await this.auth.hostOwnedSpaceResult(spaceId);
|
|
20726
20784
|
if (!created.success) {
|
|
20727
20785
|
throw Object.assign(
|
|
20728
|
-
new Error(`Failed to create owned space ${spaceId}: ${
|
|
20786
|
+
new Error(`Failed to create owned space ${spaceId}: ${describeHostFailure2(created)}`),
|
|
20729
20787
|
{ cause: created }
|
|
20730
20788
|
);
|
|
20731
20789
|
}
|
|
@@ -20734,7 +20792,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20734
20792
|
if (!retry.success || retry.skipped?.includes(spaceId)) {
|
|
20735
20793
|
throw Object.assign(
|
|
20736
20794
|
new Error(
|
|
20737
|
-
`Failed to activate session after creating owned space ${spaceId}: ${retry.success ? "space was skipped" :
|
|
20795
|
+
`Failed to activate session after creating owned space ${spaceId}: ${retry.success ? "space was skipped" : describeHostFailure2(retry)}`
|
|
20738
20796
|
),
|
|
20739
20797
|
{ cause: retry }
|
|
20740
20798
|
);
|
|
@@ -20771,19 +20829,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20771
20829
|
if (!host) {
|
|
20772
20830
|
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
20773
20831
|
}
|
|
20774
|
-
const hosted = await this.auth.
|
|
20775
|
-
|
|
20776
|
-
|
|
20777
|
-
|
|
20778
|
-
|
|
20832
|
+
const hosted = await this.auth.hostOwnedSpaceResult(spaceId);
|
|
20833
|
+
if (!hosted.success) {
|
|
20834
|
+
throw Object.assign(
|
|
20835
|
+
new Error(`Failed to host owned space ${spaceId}: ${describeHostFailure2(hosted)}`),
|
|
20836
|
+
{ cause: hosted }
|
|
20837
|
+
);
|
|
20779
20838
|
}
|
|
20780
20839
|
const activation = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
20781
20840
|
host,
|
|
20782
20841
|
session.delegationHeader
|
|
20783
20842
|
);
|
|
20784
20843
|
if (!activation.success || activation.skipped?.includes(spaceId)) {
|
|
20785
|
-
throw
|
|
20786
|
-
|
|
20844
|
+
throw Object.assign(
|
|
20845
|
+
new Error(
|
|
20846
|
+
`Failed to activate session for owned space ${spaceId}: ${activation.success ? "space was skipped" : describeHostFailure2(activation)}`
|
|
20847
|
+
),
|
|
20848
|
+
{ cause: activation }
|
|
20787
20849
|
);
|
|
20788
20850
|
}
|
|
20789
20851
|
try {
|
|
@@ -20979,23 +21041,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20979
21041
|
throw new InvalidRestoredSessionError(error instanceof Error ? error.message : String(error));
|
|
20980
21042
|
}
|
|
20981
21043
|
})();
|
|
20982
|
-
|
|
20983
|
-
if (!Array.isArray(exactRecap) || !exactRecap.every(
|
|
20984
|
-
(entry) => entry !== null && typeof entry === "object" && typeof entry.service === "string" && typeof entry.space === "string" && typeof entry.path === "string" && Array.isArray(entry.actions) && entry.actions.every((action) => typeof action === "string") && Array.isArray(entry.caveats) && entry.caveats.every(
|
|
20985
|
-
(caveat) => caveat !== null && typeof caveat === "object" && !Array.isArray(caveat)
|
|
20986
|
-
)
|
|
20987
|
-
)) {
|
|
20988
|
-
throw new UnsupportedSessionRestoreError(
|
|
20989
|
-
"it cannot reconstruct caveat-preserving persisted ReCap authority"
|
|
20990
|
-
);
|
|
20991
|
-
}
|
|
20992
|
-
stagedRecap = exactRecap.map((entry) => ({
|
|
20993
|
-
service: entry.service,
|
|
20994
|
-
space: entry.space,
|
|
20995
|
-
path: entry.path,
|
|
20996
|
-
actions: [...entry.actions],
|
|
20997
|
-
caveats: cloneRecapCaveats(entry.caveats)
|
|
20998
|
-
}));
|
|
21044
|
+
stagedRecap = exactVerifiedRecap(verified);
|
|
20999
21045
|
const signedExpiry = verified.expiresAt === void 0 ? void 0 : persistedExpiry(verified.expiresAt);
|
|
21000
21046
|
const persistedPolicyExpiry = sessionData.expiresAt === void 0 ? void 0 : persistedExpiry(sessionData.expiresAt);
|
|
21001
21047
|
if (signedExpiry && persistedPolicyExpiry && !sameInstant(signedExpiry, persistedPolicyExpiry)) {
|
|
@@ -21799,7 +21845,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21799
21845
|
if (cached) return cached;
|
|
21800
21846
|
const response = await fetch(`${this.config.host}/info`);
|
|
21801
21847
|
if (!response.ok) {
|
|
21802
|
-
throw
|
|
21848
|
+
throw await (0, import_sdk_core7.httpResponseError)(response, "Failed to fetch node info");
|
|
21803
21849
|
}
|
|
21804
21850
|
const info = await response.json();
|
|
21805
21851
|
if (typeof info.nodeId !== "string" || info.nodeId.length === 0) {
|
|
@@ -21849,9 +21895,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21849
21895
|
);
|
|
21850
21896
|
if (response.status === 404) return null;
|
|
21851
21897
|
if (!response.ok) {
|
|
21852
|
-
throw
|
|
21853
|
-
`Failed to fetch encryption network ${networkId}: HTTP ${response.status} ${await response.text()}`
|
|
21854
|
-
);
|
|
21898
|
+
throw await (0, import_sdk_core7.httpResponseError)(response, `Failed to fetch encryption network ${networkId}`);
|
|
21855
21899
|
}
|
|
21856
21900
|
const body = await response.json();
|
|
21857
21901
|
return "descriptor" in body && body.descriptor ? body.descriptor : body;
|
|
@@ -22352,7 +22396,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22352
22396
|
headers: { accept: "application/json", "content-type": "application/json", authorization },
|
|
22353
22397
|
body: (0, import_sdk_core7.canonicalizeEncryptionJson)(request)
|
|
22354
22398
|
});
|
|
22355
|
-
if (!response.ok) throw
|
|
22399
|
+
if (!response.ok) throw await (0, import_sdk_core7.httpResponseError)(response, "V3 share delivery authorization failed");
|
|
22356
22400
|
const verified = (0, import_sdk_core7.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
|
|
22357
22401
|
request,
|
|
22358
22402
|
senderKeyDid: this.credentialHolderDid,
|
|
@@ -22574,9 +22618,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22574
22618
|
);
|
|
22575
22619
|
}
|
|
22576
22620
|
if (!response.ok) {
|
|
22577
|
-
throw
|
|
22578
|
-
`Failed to create encryption network ${networkId}: HTTP ${response.status} ${await response.text()}`
|
|
22579
|
-
);
|
|
22621
|
+
throw await (0, import_sdk_core7.httpResponseError)(response, `Failed to create encryption network ${networkId}`);
|
|
22580
22622
|
}
|
|
22581
22623
|
const created = await response.json();
|
|
22582
22624
|
return created.descriptor;
|
|
@@ -22860,6 +22902,42 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22860
22902
|
(left, right) => left.service.localeCompare(right.service) || (left.space ?? "").localeCompare(right.space ?? "") || left.path.localeCompare(right.path) || left.actions.join("\0").localeCompare(right.actions.join("\0"))
|
|
22861
22903
|
);
|
|
22862
22904
|
}
|
|
22905
|
+
/**
|
|
22906
|
+
* Verify a wallet-signed session grant (a CACAO built from a SIWE and its
|
|
22907
|
+
* EIP-191 signature) issued to this instance's live session key. The
|
|
22908
|
+
* verifier rebuilds the CACAO from `siwe` and `signature`, so the grant is
|
|
22909
|
+
* accepted only when its authorization bytes and CID are exactly that CACAO,
|
|
22910
|
+
* its signer is `address`, its audience is this session key, it is valid
|
|
22911
|
+
* now, and its ReCap covers `spaceId` or names only raw encryption networks
|
|
22912
|
+
* (a decrypt-only grant has no space). Returns the signed ReCap and expiry.
|
|
22913
|
+
* Bindings without `validateSessionGrant` fall back to the session verifier,
|
|
22914
|
+
* which also refuses decrypt-only grants.
|
|
22915
|
+
*/
|
|
22916
|
+
verifySessionGrant(grant) {
|
|
22917
|
+
const bindings = this.wasmBindings;
|
|
22918
|
+
const validate5 = typeof bindings.validateSessionGrant === "function" ? bindings.validateSessionGrant.bind(bindings) : bindings.validatePersistedSession?.bind(bindings);
|
|
22919
|
+
if (validate5 === void 0) {
|
|
22920
|
+
throw new UnsupportedSessionRestoreError("it cannot verify persisted SIWE authority");
|
|
22921
|
+
}
|
|
22922
|
+
const verified = validate5({
|
|
22923
|
+
delegationHeader: { Authorization: grant.delegationHeader.Authorization },
|
|
22924
|
+
delegationCid: grant.delegationCid,
|
|
22925
|
+
spaceId: grant.spaceId,
|
|
22926
|
+
jwk: this.sessionKeyJwk,
|
|
22927
|
+
address: (0, import_sdk_core7.canonicalizeAddress)(grant.address),
|
|
22928
|
+
chainId: grant.chainId,
|
|
22929
|
+
siwe: grant.siwe,
|
|
22930
|
+
signature: grant.signature
|
|
22931
|
+
});
|
|
22932
|
+
if (typeof verified.expiresAt !== "string") {
|
|
22933
|
+
throw new Error("Session grant has no signed expiry.");
|
|
22934
|
+
}
|
|
22935
|
+
const expiresAt = new Date(verified.expiresAt);
|
|
22936
|
+
if (!Number.isFinite(expiresAt.getTime())) {
|
|
22937
|
+
throw new Error("Session grant has an invalid signed expiry.");
|
|
22938
|
+
}
|
|
22939
|
+
return { recap: exactVerifiedRecap(verified), expiresAt };
|
|
22940
|
+
}
|
|
22863
22941
|
/**
|
|
22864
22942
|
* Install a portable runtime permission delegation into this SDK instance so
|
|
22865
22943
|
* matching service calls and downstream `delegateTo()` calls can use it.
|
|
@@ -22884,8 +22962,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22884
22962
|
delegation.delegationHeader
|
|
22885
22963
|
);
|
|
22886
22964
|
if (!activateResult.success) {
|
|
22887
|
-
throw
|
|
22888
|
-
`Failed to activate runtime permission delegation: ${activateResult
|
|
22965
|
+
throw Object.assign(
|
|
22966
|
+
new Error(`Failed to activate runtime permission delegation: ${describeHostFailure2(activateResult)}`),
|
|
22967
|
+
{ cause: activateResult }
|
|
22889
22968
|
);
|
|
22890
22969
|
}
|
|
22891
22970
|
this.runtimePermissionGrants = this.runtimePermissionGrants.filter(
|
|
@@ -22981,8 +23060,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22981
23060
|
delegatedSession.delegationHeader
|
|
22982
23061
|
);
|
|
22983
23062
|
if (!activateResult.success) {
|
|
22984
|
-
throw
|
|
22985
|
-
`Failed to activate runtime permission delegation: ${activateResult
|
|
23063
|
+
throw Object.assign(
|
|
23064
|
+
new Error(`Failed to activate runtime permission delegation: ${describeHostFailure2(activateResult)}`),
|
|
23065
|
+
{ cause: activateResult }
|
|
22986
23066
|
);
|
|
22987
23067
|
}
|
|
22988
23068
|
const delegation = this.runtimeDelegationFromSession(
|
|
@@ -22990,7 +23070,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
22990
23070
|
delegatedEntries,
|
|
22991
23071
|
spaceId,
|
|
22992
23072
|
session,
|
|
22993
|
-
expiresAt
|
|
23073
|
+
expiresAt,
|
|
23074
|
+
{ siwe: prepared.siwe, signature: signature2 }
|
|
22994
23075
|
);
|
|
22995
23076
|
this.runtimePermissionGrants.push({
|
|
22996
23077
|
session: {
|
|
@@ -23167,7 +23248,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
23167
23248
|
delegationSession.delegationHeader
|
|
23168
23249
|
);
|
|
23169
23250
|
if (!activateResult.success) {
|
|
23170
|
-
throw
|
|
23251
|
+
throw Object.assign(
|
|
23252
|
+
new Error(`Failed to activate public space delegation: ${describeHostFailure2(activateResult)}`),
|
|
23253
|
+
{ cause: activateResult }
|
|
23254
|
+
);
|
|
23171
23255
|
}
|
|
23172
23256
|
if (this._capabilityRegistry && this.session) {
|
|
23173
23257
|
const sessionKey = {
|
|
@@ -23520,8 +23604,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
23520
23604
|
delegationHeader
|
|
23521
23605
|
);
|
|
23522
23606
|
if (!activateResult.success) {
|
|
23523
|
-
throw
|
|
23524
|
-
`Failed to activate delegation with host: ${activateResult
|
|
23607
|
+
throw Object.assign(
|
|
23608
|
+
new Error(`Failed to activate delegation with host: ${describeHostFailure2(activateResult)}`),
|
|
23609
|
+
{ cause: activateResult }
|
|
23525
23610
|
);
|
|
23526
23611
|
}
|
|
23527
23612
|
return {
|
|
@@ -23557,8 +23642,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
23557
23642
|
delegationHeader
|
|
23558
23643
|
);
|
|
23559
23644
|
if (!activateResult.success) {
|
|
23560
|
-
throw
|
|
23561
|
-
`Failed to activate delegation with host: ${activateResult
|
|
23645
|
+
throw Object.assign(
|
|
23646
|
+
new Error(`Failed to activate delegation with host: ${describeHostFailure2(activateResult)}`),
|
|
23647
|
+
{ cause: activateResult }
|
|
23562
23648
|
);
|
|
23563
23649
|
}
|
|
23564
23650
|
return {
|
|
@@ -23771,7 +23857,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
23771
23857
|
}
|
|
23772
23858
|
return grants;
|
|
23773
23859
|
}
|
|
23774
|
-
runtimeDelegationFromSession(delegatedSession, entries, spaceId, session, expiresAt) {
|
|
23860
|
+
runtimeDelegationFromSession(delegatedSession, entries, spaceId, session, expiresAt, siweProof) {
|
|
23775
23861
|
const resources = this.delegatedResourcesForEntries(entries, spaceId);
|
|
23776
23862
|
const primary = resources[0];
|
|
23777
23863
|
return {
|
|
@@ -23786,7 +23872,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
23786
23872
|
delegateDID: session.verificationMethod,
|
|
23787
23873
|
ownerAddress: session.address,
|
|
23788
23874
|
chainId: session.chainId,
|
|
23789
|
-
host: this.config.host
|
|
23875
|
+
host: this.config.host,
|
|
23876
|
+
siweProof
|
|
23790
23877
|
};
|
|
23791
23878
|
}
|
|
23792
23879
|
runtimeGrantFromDelegation(delegation, session) {
|
|
@@ -23979,6 +24066,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
23979
24066
|
if (grantedAction === requestedAction) {
|
|
23980
24067
|
return true;
|
|
23981
24068
|
}
|
|
24069
|
+
if ((0, import_sdk_core7.isExplicitOnlyAction)(requestedAction)) {
|
|
24070
|
+
return false;
|
|
24071
|
+
}
|
|
23982
24072
|
if (grantedAction.endsWith("/*")) {
|
|
23983
24073
|
const prefix = grantedAction.slice(0, -2);
|
|
23984
24074
|
return requestedAction.startsWith(`${prefix}/`);
|
|
@@ -24165,7 +24255,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
24165
24255
|
delegationSession.delegationHeader
|
|
24166
24256
|
);
|
|
24167
24257
|
if (!activateResult.success) {
|
|
24168
|
-
throw
|
|
24258
|
+
throw Object.assign(
|
|
24259
|
+
new Error(`Failed to activate delegation: ${describeHostFailure2(activateResult)}`),
|
|
24260
|
+
{ cause: activateResult }
|
|
24261
|
+
);
|
|
24169
24262
|
}
|
|
24170
24263
|
const result = {
|
|
24171
24264
|
cid: delegationSession.delegationCid,
|
|
@@ -24315,7 +24408,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
24315
24408
|
invokerSession.delegationHeader
|
|
24316
24409
|
);
|
|
24317
24410
|
if (!activateResult.success) {
|
|
24318
|
-
throw
|
|
24411
|
+
throw Object.assign(
|
|
24412
|
+
new Error(`Failed to activate delegated session: ${describeHostFailure2(activateResult)}`),
|
|
24413
|
+
{ cause: activateResult }
|
|
24414
|
+
);
|
|
24319
24415
|
}
|
|
24320
24416
|
const session = {
|
|
24321
24417
|
address: mySession.address,
|
|
@@ -24432,7 +24528,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
24432
24528
|
subDelegationSession.delegationHeader
|
|
24433
24529
|
);
|
|
24434
24530
|
if (!activateResult.success) {
|
|
24435
|
-
throw
|
|
24531
|
+
throw Object.assign(
|
|
24532
|
+
new Error(`Failed to activate sub-delegation: ${describeHostFailure2(activateResult)}`),
|
|
24533
|
+
{ cause: activateResult }
|
|
24534
|
+
);
|
|
24436
24535
|
}
|
|
24437
24536
|
return {
|
|
24438
24537
|
cid: subDelegationSession.delegationCid,
|
|
@@ -24647,6 +24746,29 @@ var import_sdk_core12 = require("@tinycloud/sdk-core");
|
|
|
24647
24746
|
|
|
24648
24747
|
// src/delegation.ts
|
|
24649
24748
|
var import_sdk_core9 = require("@tinycloud/sdk-core");
|
|
24749
|
+
var RUNTIME_DELEGATION_REJECTIONS = [
|
|
24750
|
+
"host_mismatch",
|
|
24751
|
+
"expired",
|
|
24752
|
+
"cid_mismatch",
|
|
24753
|
+
"authority_invalid",
|
|
24754
|
+
"proof_missing",
|
|
24755
|
+
"proof_invalid",
|
|
24756
|
+
"owner_mismatch",
|
|
24757
|
+
"audience_mismatch",
|
|
24758
|
+
"resources_mismatch",
|
|
24759
|
+
"unsupported",
|
|
24760
|
+
"activation_rejected"
|
|
24761
|
+
];
|
|
24762
|
+
var RuntimeDelegationRejectedError = class extends Error {
|
|
24763
|
+
constructor(reason, message) {
|
|
24764
|
+
super(message);
|
|
24765
|
+
this.name = "RuntimeDelegationRejectedError";
|
|
24766
|
+
this.reason = reason;
|
|
24767
|
+
}
|
|
24768
|
+
};
|
|
24769
|
+
function reject(reason, message) {
|
|
24770
|
+
throw new RuntimeDelegationRejectedError(reason, message);
|
|
24771
|
+
}
|
|
24650
24772
|
var SERVICE_BY_SHORT_NAME = {
|
|
24651
24773
|
kv: "tinycloud.kv",
|
|
24652
24774
|
sql: "tinycloud.sql",
|
|
@@ -24793,6 +24915,15 @@ function signedAuthorityFromCompactUcan(authorization) {
|
|
|
24793
24915
|
abilities
|
|
24794
24916
|
));
|
|
24795
24917
|
}
|
|
24918
|
+
return canonicalSignedAuthority({
|
|
24919
|
+
issuer: payload.iss,
|
|
24920
|
+
audience: payload.aud,
|
|
24921
|
+
expiry,
|
|
24922
|
+
proofs: [...payload.prf],
|
|
24923
|
+
...remainingRedelegationDepth === void 0 ? {} : { remainingRedelegationDepth }
|
|
24924
|
+
}, permissions);
|
|
24925
|
+
}
|
|
24926
|
+
function canonicalSignedAuthority(signed2, permissions) {
|
|
24796
24927
|
if (permissions.length === 0) {
|
|
24797
24928
|
throw new Error("Validated runtime delegation has no signed capabilities.");
|
|
24798
24929
|
}
|
|
@@ -24804,15 +24935,84 @@ function signedAuthorityFromCompactUcan(authorization) {
|
|
|
24804
24935
|
actions: [...permission.actions],
|
|
24805
24936
|
...permission.caveats === void 0 ? {} : { caveats: permission.caveats }
|
|
24806
24937
|
}));
|
|
24807
|
-
return {
|
|
24808
|
-
|
|
24809
|
-
|
|
24810
|
-
|
|
24811
|
-
|
|
24812
|
-
|
|
24813
|
-
|
|
24814
|
-
|
|
24815
|
-
|
|
24938
|
+
return { ...signed2, permissions: canonicalPermissions, resources: canonicalResources };
|
|
24939
|
+
}
|
|
24940
|
+
var RAW_ENCRYPTION_PREFIX = "urn:tinycloud:encryption:";
|
|
24941
|
+
var PKH_SPACE = /^tinycloud:pkh:eip155:(\d+):(0x[0-9a-fA-F]{40}):(.+)$/;
|
|
24942
|
+
function comparableSpace(space) {
|
|
24943
|
+
const match = PKH_SPACE.exec(space);
|
|
24944
|
+
return match ? `tinycloud:pkh:eip155:${match[1]}:${match[2].toLowerCase()}:${match[3]}` : space;
|
|
24945
|
+
}
|
|
24946
|
+
function signedAuthorityFromSessionGrant(node, delegation, authorization, cid) {
|
|
24947
|
+
const proof = delegation.siweProof;
|
|
24948
|
+
if (proof === void 0 || proof === null || typeof proof !== "object" || typeof proof.siwe !== "string" || typeof proof.signature !== "string") {
|
|
24949
|
+
reject(
|
|
24950
|
+
"proof_missing",
|
|
24951
|
+
"Runtime delegation is a wallet-signed session grant stored without its signed SIWE proof, so its authority cannot be verified."
|
|
24952
|
+
);
|
|
24953
|
+
}
|
|
24954
|
+
if (typeof node.verifySessionGrant !== "function") {
|
|
24955
|
+
reject("unsupported", "This runtime cannot verify wallet-signed session grants.");
|
|
24956
|
+
}
|
|
24957
|
+
const owner = `did:pkh:eip155:${delegation.chainId}:${delegation.ownerAddress}`;
|
|
24958
|
+
if (typeof node.did !== "string" || !didPrincipalsMatch(owner, node.did)) {
|
|
24959
|
+
reject("owner_mismatch", "Runtime delegation is not signed by this session's owner.");
|
|
24960
|
+
}
|
|
24961
|
+
let verified;
|
|
24962
|
+
try {
|
|
24963
|
+
verified = node.verifySessionGrant({
|
|
24964
|
+
delegationHeader: { Authorization: authorization },
|
|
24965
|
+
delegationCid: cid,
|
|
24966
|
+
spaceId: delegation.spaceId,
|
|
24967
|
+
address: delegation.ownerAddress,
|
|
24968
|
+
chainId: delegation.chainId,
|
|
24969
|
+
siwe: proof.siwe,
|
|
24970
|
+
signature: proof.signature
|
|
24971
|
+
});
|
|
24972
|
+
} catch (error) {
|
|
24973
|
+
reject("proof_invalid", error instanceof Error ? error.message : String(error));
|
|
24974
|
+
}
|
|
24975
|
+
const space = comparableSpace(delegation.spaceId);
|
|
24976
|
+
const spaceOwner = PKH_SPACE.exec(delegation.spaceId);
|
|
24977
|
+
if (!spaceOwner || !didPrincipalsMatch(`did:pkh:eip155:${spaceOwner[1]}:${spaceOwner[2]}`, owner)) {
|
|
24978
|
+
reject("authority_invalid", "Runtime delegation space is not owned by its signer.");
|
|
24979
|
+
}
|
|
24980
|
+
const groups = /* @__PURE__ */ new Map();
|
|
24981
|
+
for (const entry of verified.recap) {
|
|
24982
|
+
const service = entry.service.startsWith("tinycloud.") ? entry.service : `tinycloud.${entry.service}`;
|
|
24983
|
+
const raw = entry.space === "encryption";
|
|
24984
|
+
if (raw) {
|
|
24985
|
+
if (service !== "tinycloud.encryption" || !entry.path.startsWith(RAW_ENCRYPTION_PREFIX)) {
|
|
24986
|
+
reject("authority_invalid", "Runtime delegation has an unsupported signed raw resource.");
|
|
24987
|
+
}
|
|
24988
|
+
const networkOwner = entry.path.slice(RAW_ENCRYPTION_PREFIX.length, entry.path.lastIndexOf(":"));
|
|
24989
|
+
if (!didPrincipalsMatch(networkOwner, owner)) {
|
|
24990
|
+
reject("authority_invalid", "Runtime delegation names an encryption network its signer does not own.");
|
|
24991
|
+
}
|
|
24992
|
+
} else if (service === "tinycloud.encryption" || comparableSpace(entry.space) !== space) {
|
|
24993
|
+
reject("authority_invalid", "Runtime delegation has signed authority outside its space.");
|
|
24994
|
+
}
|
|
24995
|
+
const caveats = signedCaveats(entry.caveats ?? []);
|
|
24996
|
+
const key2 = JSON.stringify([service, raw ? "" : entry.space, entry.path, (0, import_sdk_core9.canonicalizeRecapCaveats)(caveats)]);
|
|
24997
|
+
const group = groups.get(key2) ?? {
|
|
24998
|
+
service,
|
|
24999
|
+
...raw ? {} : { space: entry.space },
|
|
25000
|
+
path: entry.path,
|
|
25001
|
+
actions: [],
|
|
25002
|
+
...caveats === void 0 ? {} : { caveats }
|
|
25003
|
+
};
|
|
25004
|
+
for (const action of entry.actions) {
|
|
25005
|
+
if (!group.actions.includes(action)) group.actions.push(action);
|
|
25006
|
+
}
|
|
25007
|
+
groups.set(key2, group);
|
|
25008
|
+
}
|
|
25009
|
+
return canonicalSignedAuthority({
|
|
25010
|
+
issuer: owner,
|
|
25011
|
+
// The verifier bound the SIWE audience to this runtime's own session key.
|
|
25012
|
+
audience: node.sessionDid,
|
|
25013
|
+
expiry: verified.expiresAt,
|
|
25014
|
+
proofs: []
|
|
25015
|
+
}, [...groups.values()]);
|
|
24816
25016
|
}
|
|
24817
25017
|
function canonicalResourcesFromPortableDelegation(delegation) {
|
|
24818
25018
|
if (delegation.resources !== void 0 && delegation.resources.length > 0) {
|
|
@@ -24848,46 +25048,58 @@ function resourcesMatch(actual, expected) {
|
|
|
24848
25048
|
async function activateValidatedRuntimeDelegation(node, delegation, options) {
|
|
24849
25049
|
const host = normalizedHost(options.host);
|
|
24850
25050
|
if (delegation.host !== void 0 && normalizedHost(delegation.host) !== host) {
|
|
24851
|
-
|
|
25051
|
+
reject(
|
|
25052
|
+
"host_mismatch",
|
|
24852
25053
|
`Runtime delegation host '${delegation.host}' does not match expected host '${options.host}'.`
|
|
24853
25054
|
);
|
|
24854
25055
|
}
|
|
24855
25056
|
if (!(delegation.expiry instanceof Date) || Number.isNaN(delegation.expiry.getTime())) {
|
|
24856
|
-
|
|
25057
|
+
reject("authority_invalid", "Runtime delegation has an invalid expiry.");
|
|
24857
25058
|
}
|
|
24858
25059
|
if (delegation.expiry.getTime() <= Date.now()) {
|
|
24859
|
-
|
|
25060
|
+
reject("expired", "Runtime delegation is expired.");
|
|
24860
25061
|
}
|
|
24861
25062
|
const authorization = delegation.delegationHeader?.Authorization;
|
|
24862
25063
|
if (typeof authorization !== "string" || authorization.length === 0) {
|
|
24863
|
-
|
|
25064
|
+
reject("authority_invalid", "Runtime delegation is missing authorization bytes.");
|
|
24864
25065
|
}
|
|
24865
25066
|
const cid = node.computeDelegationCid(authorization);
|
|
24866
25067
|
if (cid !== delegation.cid) {
|
|
24867
|
-
|
|
25068
|
+
reject("cid_mismatch", "Runtime delegation CID does not match authorization bytes.");
|
|
25069
|
+
}
|
|
25070
|
+
const compact = authorizationWithoutBearer(authorization).split(".").length === 3;
|
|
25071
|
+
let signed2;
|
|
25072
|
+
try {
|
|
25073
|
+
signed2 = compact ? signedAuthorityFromCompactUcan(authorization) : signedAuthorityFromSessionGrant(node, delegation, authorization, cid);
|
|
25074
|
+
} catch (error) {
|
|
25075
|
+
if (error instanceof RuntimeDelegationRejectedError) throw error;
|
|
25076
|
+
reject("authority_invalid", error instanceof Error ? error.message : String(error));
|
|
24868
25077
|
}
|
|
24869
|
-
const signed2 = signedAuthorityFromCompactUcan(authorization);
|
|
24870
25078
|
if (signed2.expiry.getTime() <= Date.now()) {
|
|
24871
|
-
|
|
25079
|
+
reject("expired", "Runtime delegation is expired.");
|
|
24872
25080
|
}
|
|
24873
25081
|
if (delegation.expiry.getTime() !== signed2.expiry.getTime()) {
|
|
24874
|
-
|
|
25082
|
+
reject("authority_invalid", "Runtime delegation expiry does not match signed authority.");
|
|
24875
25083
|
}
|
|
24876
25084
|
if (!didPrincipalsMatch(signed2.audience, node.sessionDid)) {
|
|
24877
|
-
|
|
25085
|
+
reject(
|
|
25086
|
+
"audience_mismatch",
|
|
24878
25087
|
`Runtime delegation targets ${signed2.audience} but this session is ${node.sessionDid}.`
|
|
24879
25088
|
);
|
|
24880
25089
|
}
|
|
24881
25090
|
if (!didPrincipalsMatch(delegation.delegateDID, signed2.audience)) {
|
|
24882
|
-
|
|
25091
|
+
reject("audience_mismatch", "Runtime delegation audience does not match signed authority.");
|
|
25092
|
+
}
|
|
25093
|
+
if (compact && !resourcesMatch(canonicalResourcesFromPortableDelegation(delegation), signed2.resources)) {
|
|
25094
|
+
reject("resources_mismatch", "Runtime delegation resources do not match signed authority.");
|
|
24883
25095
|
}
|
|
24884
|
-
|
|
24885
|
-
|
|
24886
|
-
throw new Error("Runtime delegation resources do not match signed authority.");
|
|
25096
|
+
if (options.authorize !== void 0 && !options.authorize(signed2.permissions)) {
|
|
25097
|
+
throw new Error("Runtime delegation is not authorized for this runtime.");
|
|
24887
25098
|
}
|
|
24888
25099
|
const previouslyInstalled = node.getRuntimePermissionDelegations().find((candidate) => candidate.cid === cid);
|
|
24889
25100
|
if (previouslyInstalled !== void 0 && previouslyInstalled.delegationHeader.Authorization !== authorization) {
|
|
24890
|
-
|
|
25101
|
+
reject(
|
|
25102
|
+
"cid_mismatch",
|
|
24891
25103
|
"A different authorization is already installed for this runtime delegation CID."
|
|
24892
25104
|
);
|
|
24893
25105
|
}
|
|
@@ -24917,22 +25129,28 @@ async function activateValidatedRuntimeDelegation(node, delegation, options) {
|
|
|
24917
25129
|
})),
|
|
24918
25130
|
expiry: new Date(signed2.expiry),
|
|
24919
25131
|
delegateDID: signed2.audience,
|
|
24920
|
-
host
|
|
25132
|
+
host,
|
|
25133
|
+
...compact ? {} : { siweProof: delegation.siweProof }
|
|
24921
25134
|
};
|
|
24922
|
-
|
|
24923
|
-
|
|
24924
|
-
|
|
24925
|
-
|
|
25135
|
+
try {
|
|
25136
|
+
if (node.isSessionOnly === true && typeof node.did === "string" && (0, import_sdk_core9.principalDidEquals)(node.did, node.sessionDid) && typeof node.useDelegation === "function") {
|
|
25137
|
+
await node.useDelegation(installedCandidate);
|
|
25138
|
+
} else {
|
|
25139
|
+
await node.useRuntimeDelegation(installedCandidate);
|
|
25140
|
+
}
|
|
25141
|
+
} catch (error) {
|
|
25142
|
+
reject("activation_rejected", error instanceof Error ? error.message : String(error));
|
|
24926
25143
|
}
|
|
24927
25144
|
const installed = node.getRuntimePermissionDelegations().find((candidate) => candidate.cid === cid);
|
|
24928
25145
|
if (!installed) {
|
|
24929
|
-
|
|
25146
|
+
reject("activation_rejected", "Runtime delegation activation did not install the validated authority.");
|
|
24930
25147
|
}
|
|
24931
25148
|
if (installed.delegationHeader.Authorization !== authorization || !didPrincipalsMatch(installed.delegateDID, signed2.audience) || installed.expiry.getTime() !== signed2.expiry.getTime() || !resourcesMatch(
|
|
24932
25149
|
canonicalResourcesFromPortableDelegation(installed),
|
|
24933
25150
|
signed2.resources
|
|
24934
25151
|
) || normalizedHost(installed.host ?? "") !== host) {
|
|
24935
|
-
|
|
25152
|
+
reject(
|
|
25153
|
+
"activation_rejected",
|
|
24936
25154
|
"Runtime delegation activation installed authority that differs from the validated authority."
|
|
24937
25155
|
);
|
|
24938
25156
|
}
|
|
@@ -25081,9 +25299,13 @@ var import_sdk_core23 = require("@tinycloud/sdk-core");
|
|
|
25081
25299
|
PrefixedKVService,
|
|
25082
25300
|
PrivateKeySigner,
|
|
25083
25301
|
ProtocolMismatchError,
|
|
25302
|
+
RUNTIME_DELEGATION_REJECTIONS,
|
|
25303
|
+
RuntimeDelegationRejectedError,
|
|
25084
25304
|
SECRET_NAME_RE,
|
|
25085
25305
|
SQLAction,
|
|
25086
25306
|
SQLService,
|
|
25307
|
+
STORAGE_FULL_MESSAGE,
|
|
25308
|
+
STORAGE_WRITE_TOO_LARGE_MESSAGE,
|
|
25087
25309
|
SecretsService,
|
|
25088
25310
|
ServiceContext,
|
|
25089
25311
|
SessionExpiredError,
|
|
@@ -25159,6 +25381,7 @@ var import_sdk_core23 = require("@tinycloud/sdk-core");
|
|
|
25159
25381
|
isCapabilitySubset,
|
|
25160
25382
|
isEvmAddress,
|
|
25161
25383
|
isNetworkId,
|
|
25384
|
+
isStorageFullError,
|
|
25162
25385
|
loadManifest,
|
|
25163
25386
|
makePkhSpaceId,
|
|
25164
25387
|
makePublicSpaceId,
|