@ibgib/space-gib 0.0.8 → 0.0.9
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/client/bootstrap.mjs +1 -1
- package/dist/client/{chunk-DBHMHCGD.mjs → chunk-ACIGPCQW.mjs} +95 -29
- package/dist/client/{chunk-DBHMHCGD.mjs.map → chunk-ACIGPCQW.mjs.map} +3 -3
- package/dist/client/{chunk-SUQ5QJH4.mjs → chunk-QRMTJE6M.mjs} +23 -23
- package/dist/client/{chunk-SUQ5QJH4.mjs.map → chunk-QRMTJE6M.mjs.map} +3 -3
- package/dist/client/index.mjs +1 -1
- package/dist/client/script.mjs +1 -1
- package/dist/server/server.mjs +247 -141
- package/dist/server/server.mjs.map +2 -2
- package/package.json +4 -4
- package/src/client/AUTO-GENERATED-version.mts +1 -1
- package/src/client/api/space-gib-api-bridge.mts +37 -8
- package/src/client/components/keystone-creator/keystone-creator.mts +5 -5
- package/src/client/components/keystone-details/keystone-details.css +42 -0
- package/src/client/components/keystone-details/keystone-details.html +24 -0
- package/src/client/components/keystone-details/keystone-details.mts +217 -17
- package/src/client/dev-tools/common.mts +4 -4
- package/src/server/serve-gib/handlers/api/keystone/keystone-evolve.handler.mts +12 -3
package/dist/client/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Qb as c,Rb as l,Tb as a,a as r,i as e,mb as n,nb as i,qc as s}from"./chunk-
|
|
1
|
+
import{Qb as c,Rb as l,Tb as a,a as r,i as e,mb as n,nb as i,qc as s}from"./chunk-QRMTJE6M.mjs";l(i);var m=n;async function d(){let o=`[${d.name}]`;try{m&&console.log(`${o} starting... (I: 3d893846d02c4ff49181f9b8e586eb74)`),console.time(o),document.addEventListener("DOMContentLoaded",async()=>{try{console.timeLog(o,"DOMContentLoaded fired"),await c(i),console.timeLog(o,"initIbGibStorage complete"),await a("./bootstrap.mjs"),console.timeLog(o,"dynamicallyLoadBootstrapScript complete"),s(),console.timeLog(o,"initDevTools complete"),console.timeEnd(o)}catch(t){throw console.error(`${o} ${e(t)}`),t}})}catch(t){console.timeEnd(o);debugger;throw console.error(`${o} ${e(t)}`),t}finally{m&&console.log(`${o} complete.`)}}r(d,"spinOffStartup");d();
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/client/script.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{p as e}from"./chunk-
|
|
1
|
+
import{p as e}from"./chunk-ACIGPCQW.mjs";import"./chunk-QRMTJE6M.mjs";console.log("space-gib early script executing...");e();
|
|
2
2
|
//# sourceMappingURL=script.mjs.map
|
package/dist/server/server.mjs
CHANGED
|
@@ -17900,6 +17900,15 @@ var KeystoneStrategy_HashRevealV1 = class _KeystoneStrategy_HashRevealV1 extends
|
|
|
17900
17900
|
}
|
|
17901
17901
|
}
|
|
17902
17902
|
};
|
|
17903
|
+
async function deriveDelegateSecret({ masterSecret }) {
|
|
17904
|
+
const salt = await hash({ s: masterSecret, algorithm: HashAlgorithm.sha_512 });
|
|
17905
|
+
return await kdf_recursiveSaltWrap({
|
|
17906
|
+
masterSecret,
|
|
17907
|
+
salt,
|
|
17908
|
+
rounds: 1e3,
|
|
17909
|
+
algorithm: HashAlgorithm.sha_512
|
|
17910
|
+
});
|
|
17911
|
+
}
|
|
17903
17912
|
|
|
17904
17913
|
// ../../libs/core-gib/dist/keystone/strategy/keystone-strategy-factory.mjs
|
|
17905
17914
|
var KeystoneStrategyFactory = class _KeystoneStrategyFactory {
|
|
@@ -19775,35 +19784,38 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
|
|
|
19775
19784
|
* This creates a new frame signed by the specified `signingPoolId` using `signingSecret`.
|
|
19776
19785
|
*
|
|
19777
19786
|
* Supports recovery (signing via `custodian-manage` using the custodian secret) and normal rotation
|
|
19778
|
-
* (signing via `manage` using the old password).
|
|
19787
|
+
* (signing via `manage` using the old password). **I DONT THINK THIS IS POSSIBLE. WE WOULD NEED CUSTODIAN MANAGE POOLS ON ALL THE DELEGATES AS WELL**
|
|
19779
19788
|
*
|
|
19780
|
-
* @param
|
|
19781
|
-
* - Visibility: Public (Public Merkle frame, safe for ledger).
|
|
19782
|
-
* - Generator: Client/Server (Constructed locally and synced).
|
|
19789
|
+
* @param signingSecret
|
|
19783
19790
|
*
|
|
19784
|
-
* @param
|
|
19785
|
-
* - Visibility: Private (Confidential secret credential. Must never go over the wire).
|
|
19786
|
-
* - Generator: Client (From user input in settings).
|
|
19787
|
-
*
|
|
19788
|
-
* @param signingSecret The secret of the pool authorizing this change (either old passphrase or derived custodian secret).
|
|
19789
|
-
* - Visibility: Private (Confidential secret. Must never go over the wire).
|
|
19790
|
-
* - Generator: Client/Server (Known only to the signing party).
|
|
19791
|
-
*
|
|
19792
|
-
* @param signingPoolId The ID of the pool used to authorize the rotation (defaults to 'manage').
|
|
19793
|
-
* - Visibility: Public (Non-sensitive ID string).
|
|
19794
|
-
* - Generator: Client/Server (From pool configuration).
|
|
19791
|
+
* @param signingPoolId
|
|
19795
19792
|
*/
|
|
19796
|
-
async changePassword({
|
|
19793
|
+
async changePassword({ keystoneIbGib, keystoneAddr, newMasterSecret, signingSecret, signingPoolId = POOL_ID_MANAGE, poolIds, frameDetails, metaspace, space }) {
|
|
19797
19794
|
const lc2 = `${this.lc}[${this.changePassword.name}]`;
|
|
19798
19795
|
try {
|
|
19799
19796
|
if (logalot41) {
|
|
19800
|
-
console.log(`${lc2} starting
|
|
19797
|
+
console.log(`${lc2} starting... (I: 9e3ff83ebd74511f9dad784a1020d926)`);
|
|
19798
|
+
}
|
|
19799
|
+
if (!keystoneIbGib && !keystoneAddr) {
|
|
19800
|
+
throw new Error(`Either keystoneIbGib or keystoneAddr required. (E: d1b8c8cb75f2c022284e69b8c30af826)`);
|
|
19801
|
+
}
|
|
19802
|
+
if (keystoneIbGib && keystoneAddr) {
|
|
19803
|
+
const checkAddr = getIbGibAddr({ ibGib: keystoneIbGib });
|
|
19804
|
+
if (checkAddr !== keystoneAddr) {
|
|
19805
|
+
throw new Error(`(UNEXPECTED) both keystoneIbGib (addr: ${checkAddr}) and keystoneAddr (${keystoneAddr}) provided, but the addrs are unequal? Note that only one is required for this function, but if both are provided the addrs must match exactly. (E: c5574f7e353a48b0bba94a1862af4e26)`);
|
|
19806
|
+
}
|
|
19801
19807
|
}
|
|
19808
|
+
keystoneAddr ??= getIbGibAddr({ ibGib: keystoneIbGib });
|
|
19809
|
+
const latestKeystone = await this.getLatestKeystone({
|
|
19810
|
+
addr: keystoneAddr,
|
|
19811
|
+
metaspace,
|
|
19812
|
+
space
|
|
19813
|
+
});
|
|
19802
19814
|
if (!latestKeystone.data) {
|
|
19803
|
-
throw new Error(`latestKeystone.data falsy`);
|
|
19815
|
+
throw new Error(`latestKeystone.data falsy (E: 22e498eb8308a33e68b812d8d3905826)`);
|
|
19804
19816
|
}
|
|
19805
19817
|
if (latestKeystone.data.revocationInfo) {
|
|
19806
|
-
throw new Error(`Keystone has been revoked. Cannot change password. (E:
|
|
19818
|
+
throw new Error(`Keystone has been revoked. Cannot change password. (E: 726298617e8508b3c83b5e985a03e826)`);
|
|
19807
19819
|
}
|
|
19808
19820
|
const prevPools = latestKeystone.data.challengePools;
|
|
19809
19821
|
const signingPool = prevPools.find((p) => p.id === signingPoolId);
|
|
@@ -19878,17 +19890,44 @@ var KeystoneService_V1 = class _KeystoneService_V1 {
|
|
|
19878
19890
|
proofs: [proof],
|
|
19879
19891
|
frameDetails,
|
|
19880
19892
|
checkpointDetails,
|
|
19881
|
-
...latestKeystone.data.delegates ? { delegates: latestKeystone.data.delegates } :
|
|
19893
|
+
...latestKeystone.data.delegates ? { delegates: latestKeystone.data.delegates } : void 0
|
|
19882
19894
|
};
|
|
19883
|
-
|
|
19895
|
+
const newKeystoneIbGib = await evolvePersistAndRegisterKeystone({
|
|
19884
19896
|
prevIbGib: latestKeystone,
|
|
19885
19897
|
newData,
|
|
19886
19898
|
metaspace,
|
|
19887
19899
|
space
|
|
19888
19900
|
});
|
|
19901
|
+
const newDelegates = [];
|
|
19902
|
+
if ((poolIds ?? []).length === 0) {
|
|
19903
|
+
const delegateSigningSecret = await deriveDelegateSecret({ masterSecret: signingSecret });
|
|
19904
|
+
const delegateNewMasterSecret = await deriveDelegateSecret({ masterSecret: newMasterSecret });
|
|
19905
|
+
const delegateTjpAddrs = Object.keys(latestKeystone.data.delegates ?? {});
|
|
19906
|
+
for (const delegateTjpAddr of delegateTjpAddrs) {
|
|
19907
|
+
const { newKeystone: newDelegate, newDelegates: newDelegatesSecondOrder } = await this.changePassword({
|
|
19908
|
+
keystoneAddr: delegateTjpAddr,
|
|
19909
|
+
metaspace,
|
|
19910
|
+
space,
|
|
19911
|
+
newMasterSecret: delegateNewMasterSecret,
|
|
19912
|
+
signingSecret: delegateSigningSecret,
|
|
19913
|
+
signingPoolId,
|
|
19914
|
+
poolIds: void 0,
|
|
19915
|
+
frameDetails
|
|
19916
|
+
});
|
|
19917
|
+
if (newDelegatesSecondOrder && newDelegatesSecondOrder.length > 0) {
|
|
19918
|
+
throw new Error(`(UNEXPECTED) Delegate keystone has its own delegate(s)? ATOW (07/20/2026) second order delegates are not supported. (E: de45a7b7d9b8f61f6e58158269acba26)`);
|
|
19919
|
+
}
|
|
19920
|
+
newDelegates.push(newDelegate);
|
|
19921
|
+
}
|
|
19922
|
+
}
|
|
19923
|
+
return { newKeystone: newKeystoneIbGib, newDelegates: newDelegates.length > 0 ? newDelegates : void 0 };
|
|
19889
19924
|
} catch (error) {
|
|
19890
19925
|
console.error(`${lc2} ${extractErrorMsg(error)}`);
|
|
19891
19926
|
throw error;
|
|
19927
|
+
} finally {
|
|
19928
|
+
if (logalot41) {
|
|
19929
|
+
console.log(`${lc2} complete.`);
|
|
19930
|
+
}
|
|
19892
19931
|
}
|
|
19893
19932
|
}
|
|
19894
19933
|
/**
|
|
@@ -20080,17 +20119,31 @@ async function validateAndRegisterPostKeystones({ ibGibs, metaspace, space }) {
|
|
|
20080
20119
|
}
|
|
20081
20120
|
}
|
|
20082
20121
|
}
|
|
20083
|
-
async function validateAndRegisterEvolveKeystone({ domainAddr, keystoneIbGib,
|
|
20122
|
+
async function validateAndRegisterEvolveKeystone({ domainAddr, keystoneIbGib, relatedKeystoneIbGibs = [], metaspace, space }) {
|
|
20084
20123
|
const lc2 = `[${validateAndRegisterEvolveKeystone.name}]`;
|
|
20085
20124
|
try {
|
|
20086
20125
|
if (logalot42) {
|
|
20087
20126
|
console.log(`${lc2} starting... (I: 42b826a690881cd5a8fe520cbdfad826)`);
|
|
20088
20127
|
}
|
|
20089
|
-
const addr = getIbGibAddr({ ibGib: keystoneIbGib });
|
|
20090
20128
|
const intrinsicErrors = await validateIbGibIntrinsically({ ibGib: keystoneIbGib });
|
|
20091
20129
|
if (intrinsicErrors && intrinsicErrors.length > 0) {
|
|
20092
20130
|
throw new Error(`Intrinsic keystone validation failed: ${intrinsicErrors.join(", ")} (E: 38ea984585edc6ee88d2a698c7895826)`);
|
|
20093
20131
|
}
|
|
20132
|
+
const proofs = keystoneIbGib.data?.proofs ?? [];
|
|
20133
|
+
if (proofs.length === 0) {
|
|
20134
|
+
throw new Error("No proofs found in evolved keystone data (E: 399f8f51c78d722252ddb2894fdbe25)");
|
|
20135
|
+
}
|
|
20136
|
+
if (proofs.length !== 1) {
|
|
20137
|
+
throw new Error(`evolving keystone with proofs.length !== 1? (E: 14e058a34964dcd7181395382cc60826)`);
|
|
20138
|
+
}
|
|
20139
|
+
const claim = proofs[0].claim;
|
|
20140
|
+
if (!claim) {
|
|
20141
|
+
throw new Error(`proof.claim is falsy (E: 54be88be2c975ef18e571a4286928826)`);
|
|
20142
|
+
}
|
|
20143
|
+
const verb = claim.verb;
|
|
20144
|
+
if (!verb) {
|
|
20145
|
+
throw new Error(`claim.verb is falsy (E: 92cf38af58db2cd90e7132b8940fe326)`);
|
|
20146
|
+
}
|
|
20094
20147
|
const keystoneService = new KeystoneService_V1();
|
|
20095
20148
|
let parentKeystone;
|
|
20096
20149
|
try {
|
|
@@ -20108,132 +20161,185 @@ async function validateAndRegisterEvolveKeystone({ domainAddr, keystoneIbGib, re
|
|
|
20108
20161
|
throw new Error(`Incoming keystone does not have a TJP address (E: d288fae39b7d825d)`);
|
|
20109
20162
|
}
|
|
20110
20163
|
const isDelegate = incomingTjpAddr !== parentTjpAddr;
|
|
20111
|
-
|
|
20112
|
-
|
|
20113
|
-
|
|
20114
|
-
|
|
20115
|
-
|
|
20116
|
-
|
|
20117
|
-
|
|
20118
|
-
|
|
20119
|
-
|
|
20120
|
-
|
|
20121
|
-
|
|
20122
|
-
|
|
20123
|
-
|
|
20124
|
-
|
|
20125
|
-
|
|
20126
|
-
|
|
20127
|
-
|
|
20128
|
-
|
|
20129
|
-
|
|
20130
|
-
|
|
20131
|
-
|
|
20132
|
-
|
|
20133
|
-
|
|
20134
|
-
|
|
20135
|
-
|
|
20136
|
-
currentIbGib: keystoneIbGib,
|
|
20137
|
-
prevIbGib
|
|
20138
|
-
});
|
|
20139
|
-
if (validationErrors && validationErrors.length > 0) {
|
|
20140
|
-
throw new Error(`Keystone evolution validation failed: ${validationErrors.join(", ")} (E: 5212f8492ac839953842631834bcd826)`);
|
|
20141
|
-
}
|
|
20142
|
-
} else {
|
|
20143
|
-
const validationErrors = await keystoneService.validateKeystoneGraph({
|
|
20144
|
-
keystoneIbGib,
|
|
20145
|
-
getLatest: false,
|
|
20146
|
-
invalidIfMoreRecentKeystoneFoundInSpace: false,
|
|
20147
|
-
space
|
|
20148
|
-
});
|
|
20149
|
-
if (validationErrors && validationErrors.length > 0) {
|
|
20150
|
-
throw new Error(`Keystone graph validation failed: ${validationErrors.join(", ")} (E: 3a288fae39b7d82e)`);
|
|
20151
|
-
}
|
|
20152
|
-
}
|
|
20153
|
-
const proofs = keystoneIbGib.data?.proofs ?? [];
|
|
20154
|
-
if (proofs.length === 0) {
|
|
20155
|
-
throw new Error("No proofs found in evolved keystone data");
|
|
20156
|
-
}
|
|
20157
|
-
const poolIds = /* @__PURE__ */ new Set();
|
|
20158
|
-
for (const proof of proofs) {
|
|
20159
|
-
for (const solution of proof.solutions || []) {
|
|
20160
|
-
if (solution.poolId) {
|
|
20161
|
-
poolIds.add(solution.poolId);
|
|
20162
|
-
}
|
|
20163
|
-
}
|
|
20164
|
-
}
|
|
20165
|
-
if (poolIds.size > 1) {
|
|
20166
|
-
throw new Error(`Multiple pools evolved (${Array.from(poolIds).join(", ")}). Only one pool evolution allowed at a time. (E: 4a9b28ae33e8e3eb4ddbad981aa7b126)`);
|
|
20167
|
-
}
|
|
20168
|
-
if (proofs.length !== 1) {
|
|
20169
|
-
throw new Error(`evolving keystone with proofs.length !== 1? (E: 14e058a34964dcd7181395382cc60826)`);
|
|
20170
|
-
}
|
|
20171
|
-
const claim = proofs[0].claim;
|
|
20172
|
-
if (!claim) {
|
|
20173
|
-
throw new Error(`proof.claim is falsy (E: 54be88be2c975ef18e571a4286928826)`);
|
|
20164
|
+
switch (verb) {
|
|
20165
|
+
case KEYSTONE_VERB_MANAGE:
|
|
20166
|
+
await validateManageEvolveKeystone({
|
|
20167
|
+
keystoneIbGib,
|
|
20168
|
+
relatedKeystoneIbGibs,
|
|
20169
|
+
parentKeystone,
|
|
20170
|
+
isDelegate,
|
|
20171
|
+
domainAddr,
|
|
20172
|
+
metaspace,
|
|
20173
|
+
space
|
|
20174
|
+
});
|
|
20175
|
+
break;
|
|
20176
|
+
case KEYSTONE_VERB_SYNC:
|
|
20177
|
+
await validateSyncEvolveKeystone({
|
|
20178
|
+
keystoneIbGib,
|
|
20179
|
+
relatedKeystoneIbGibs,
|
|
20180
|
+
parentKeystone,
|
|
20181
|
+
isDelegate,
|
|
20182
|
+
domainAddr,
|
|
20183
|
+
metaspace,
|
|
20184
|
+
space
|
|
20185
|
+
});
|
|
20186
|
+
break;
|
|
20187
|
+
default:
|
|
20188
|
+
throw new Error(`Unsupported keystone evolution verb: ${verb} (E: eca4681b05486d1f784c0cb815ef9926)`);
|
|
20174
20189
|
}
|
|
20175
|
-
|
|
20176
|
-
|
|
20177
|
-
|
|
20190
|
+
} catch (error) {
|
|
20191
|
+
console.error(`${lc2} ${extractErrorMsg(error)}`);
|
|
20192
|
+
throw error;
|
|
20193
|
+
} finally {
|
|
20194
|
+
if (logalot42) {
|
|
20195
|
+
console.log(`${lc2} complete.`);
|
|
20178
20196
|
}
|
|
20179
|
-
|
|
20180
|
-
|
|
20181
|
-
|
|
20182
|
-
|
|
20183
|
-
|
|
20184
|
-
|
|
20185
|
-
|
|
20186
|
-
|
|
20187
|
-
|
|
20197
|
+
}
|
|
20198
|
+
}
|
|
20199
|
+
async function validateManageEvolveKeystone({ keystoneIbGib, relatedKeystoneIbGibs, parentKeystone, isDelegate, domainAddr, metaspace, space }) {
|
|
20200
|
+
const lc2 = `[validateManageEvolveKeystone]`;
|
|
20201
|
+
const keystoneService = new KeystoneService_V1();
|
|
20202
|
+
const transitionErrors = await keystoneService.validate({
|
|
20203
|
+
currentIbGib: keystoneIbGib,
|
|
20204
|
+
prevIbGib: parentKeystone
|
|
20205
|
+
});
|
|
20206
|
+
if (transitionErrors && transitionErrors.length > 0) {
|
|
20207
|
+
throw new Error(`Parent Domain Identity evolution validation failed: ${transitionErrors.join(", ")} (E: 5212f8492ac839953842631834bcd826)`);
|
|
20208
|
+
}
|
|
20209
|
+
const proof = keystoneIbGib.data?.proofs?.[0];
|
|
20210
|
+
const claim = proof?.claim;
|
|
20211
|
+
const claimType = claim?.details?.type;
|
|
20212
|
+
const prevDelegates = parentKeystone.data?.delegates ?? {};
|
|
20213
|
+
const currDelegates = keystoneIbGib.data?.delegates ?? {};
|
|
20214
|
+
switch (claimType) {
|
|
20215
|
+
case KEYSTONE_CLAIM_TYPE_CHANGE_PASSWORD:
|
|
20216
|
+
case KEYSTONE_CLAIM_TYPE_ADD_POOL:
|
|
20217
|
+
case KEYSTONE_CLAIM_TYPE_REMOVE_POOL:
|
|
20218
|
+
case KEYSTONE_CLAIM_TYPE_REPLACE_POOL:
|
|
20219
|
+
default:
|
|
20220
|
+
for (const related of relatedKeystoneIbGibs) {
|
|
20221
|
+
const ibIsValid = await validateKeystoneIb({ ib: related.ib });
|
|
20222
|
+
if (!ibIsValid) {
|
|
20223
|
+
throw new Error(`Invalid related keystone ibgib. related.ib (${related.ib}) is not a valid keystone ib. (E: 89dff2f48fa8c33b449081e2478c6826)`);
|
|
20224
|
+
}
|
|
20225
|
+
const relatedTjp = getTjpAddr({ ibGib: related });
|
|
20226
|
+
if (!relatedTjp) {
|
|
20227
|
+
throw new Error(`Related keystone in relatedKeystoneIbGibs is missing a TJP address (E: 2fe5a68438e288ab4e86c90d81d142826)`);
|
|
20228
|
+
}
|
|
20229
|
+
const relatedAddr = getIbGibAddr({ ibGib: related });
|
|
20230
|
+
const delegateInfo = currDelegates[relatedTjp];
|
|
20231
|
+
if (!delegateInfo) {
|
|
20232
|
+
throw new Error(`Related keystone (${relatedTjp}) is not a registered delegate under parent Domain Identity (E: 3fe5a68438e288ab4e86c90d81d142826)`);
|
|
20233
|
+
}
|
|
20234
|
+
const delegateIsNewlyRegistered = !prevDelegates[relatedTjp];
|
|
20235
|
+
if (delegateIsNewlyRegistered) {
|
|
20236
|
+
const delegateKeystone = related;
|
|
20237
|
+
if (delegateKeystone.data?.n !== 0) {
|
|
20238
|
+
throw new Error(`Newly registered delegate keystone (${relatedAddr}) has data.n !== 0 (${delegateKeystone.data?.n}). Registering non-genesis delegate keystones is not supported at this time. (E: 4cdd0dee42d7d437ef6af698150cfe26)`);
|
|
20188
20239
|
}
|
|
20189
|
-
const
|
|
20190
|
-
|
|
20191
|
-
|
|
20240
|
+
const genesisErrors = await keystoneService.validateGenesisKeystone({
|
|
20241
|
+
keystoneIbGib: delegateKeystone
|
|
20242
|
+
});
|
|
20243
|
+
if (genesisErrors && genesisErrors.length > 0) {
|
|
20244
|
+
throw new Error(`Genesis validation failed for new delegate keystone ${relatedAddr}: ${genesisErrors.join(", ")} (E: d8afdc1dbed48c000455b35585dc26826)`);
|
|
20245
|
+
}
|
|
20246
|
+
} else {
|
|
20247
|
+
let prevDelegateTip;
|
|
20248
|
+
try {
|
|
20249
|
+
prevDelegateTip = await keystoneService.getLatestKeystone({
|
|
20250
|
+
addr: relatedTjp,
|
|
20251
|
+
metaspace,
|
|
20252
|
+
space
|
|
20253
|
+
});
|
|
20254
|
+
} catch (err) {
|
|
20255
|
+
throw new Error(`Could not find previous delegate tip for ${relatedTjp} in space: ${extractErrorMsg(err)} (E: 5fe5a68438e288ab4e86c90d81d142826)`);
|
|
20256
|
+
}
|
|
20257
|
+
const evolutionErrors = await keystoneService.validate({
|
|
20258
|
+
currentIbGib: related,
|
|
20259
|
+
prevIbGib: prevDelegateTip
|
|
20260
|
+
});
|
|
20261
|
+
if (evolutionErrors && evolutionErrors.length > 0) {
|
|
20262
|
+
throw new Error(`Evolution transition validation failed for delegate keystone ${relatedAddr}: ${evolutionErrors.join(", ")} (E: 6fe5a68438e288ab4e86c90d81d142826)`);
|
|
20192
20263
|
}
|
|
20193
20264
|
}
|
|
20194
20265
|
}
|
|
20195
|
-
|
|
20196
|
-
|
|
20197
|
-
|
|
20198
|
-
|
|
20199
|
-
|
|
20200
|
-
|
|
20201
|
-
}
|
|
20202
|
-
return;
|
|
20203
|
-
}
|
|
20204
|
-
if (verb !== "sync") {
|
|
20205
|
-
throw new Error(`non-sync/non-manage keystone evolution not yet implemented (E: eca4681b05486d1f784c0cb815ef9926)`);
|
|
20206
|
-
}
|
|
20207
|
-
if (!isDelegate) {
|
|
20208
|
-
throw new Error(`Root Domain Identity (${parentTjpAddr}) is not allowed to sync directly. A delegate must be used. (E: 2c88fae39b7d82fd)`);
|
|
20209
|
-
}
|
|
20210
|
-
const sAddr = claim.target;
|
|
20211
|
-
if (!sAddr) {
|
|
20212
|
-
throw new Error("No target address found in sync claim");
|
|
20213
|
-
}
|
|
20214
|
-
const sIbGib = relatedIbGibs.find((ibGib) => getIbGibAddr({ ibGib }) === sAddr);
|
|
20215
|
-
if (!sIbGib) {
|
|
20216
|
-
throw new Error(`Session keystone ${sAddr} must be provided in relatedIbGibs (E: fe5a68438e288ab4e86c90d81d142826)`);
|
|
20217
|
-
}
|
|
20218
|
-
const sIntrinsicErrors = await validateIbGibIntrinsically({ ibGib: sIbGib });
|
|
20219
|
-
if (sIntrinsicErrors && sIntrinsicErrors.length > 0) {
|
|
20220
|
-
throw new Error(`Intrinsic validation failed for S^Stjp: ${sIntrinsicErrors.join(", ")} (E: 802d8350c3cccbd7184dd43866c05526)`);
|
|
20266
|
+
break;
|
|
20267
|
+
}
|
|
20268
|
+
await metaspace.put({ ibGibs: [keystoneIbGib, ...relatedKeystoneIbGibs], space });
|
|
20269
|
+
await metaspace.registerNewIbGib({ ibGib: keystoneIbGib, space });
|
|
20270
|
+
for (const related of relatedKeystoneIbGibs) {
|
|
20271
|
+
if (related.ib?.startsWith("keystone")) {
|
|
20272
|
+
await metaspace.registerNewIbGib({ ibGib: related, space });
|
|
20221
20273
|
}
|
|
20222
|
-
|
|
20223
|
-
|
|
20224
|
-
|
|
20274
|
+
}
|
|
20275
|
+
}
|
|
20276
|
+
async function validateSyncEvolveKeystone({ keystoneIbGib, relatedKeystoneIbGibs, parentKeystone, isDelegate, domainAddr, metaspace, space }) {
|
|
20277
|
+
const lc2 = `[validateSyncEvolveKeystone]`;
|
|
20278
|
+
const keystoneService = new KeystoneService_V1();
|
|
20279
|
+
if (!isDelegate) {
|
|
20280
|
+
throw new Error(`Root Domain Identity (${domainAddr}) is not allowed to sync directly. A delegate must be used. (E: 2c88fae39b7d82fd)`);
|
|
20281
|
+
}
|
|
20282
|
+
const incomingTjpAddr = getTjpAddr({ ibGib: keystoneIbGib });
|
|
20283
|
+
if (!incomingTjpAddr) {
|
|
20284
|
+
throw new Error(`Incoming delegate keystone missing TJP address (E: d288fae39b7d825e)`);
|
|
20285
|
+
}
|
|
20286
|
+
const delegateInfo = parentKeystone.data?.delegates?.[incomingTjpAddr];
|
|
20287
|
+
if (!delegateInfo) {
|
|
20288
|
+
throw new Error(`Incoming delegate keystone (${incomingTjpAddr}) is not registered under parent Domain Identity (E: c288fae39b7d82fe)`);
|
|
20289
|
+
}
|
|
20290
|
+
const allowedVerbs = delegateInfo.allowedVerbs ?? [];
|
|
20291
|
+
if (!allowedVerbs.includes(KEYSTONE_VERB_SYNC)) {
|
|
20292
|
+
throw new Error(`Incoming delegate keystone is not authorized for sync. Allowed verbs: ${allowedVerbs.join(", ")} (E: a288fae39b7d82ff)`);
|
|
20293
|
+
}
|
|
20294
|
+
let prevDelegateTip;
|
|
20295
|
+
try {
|
|
20296
|
+
prevDelegateTip = await keystoneService.getLatestKeystone({
|
|
20297
|
+
addr: incomingTjpAddr,
|
|
20298
|
+
metaspace,
|
|
20299
|
+
space
|
|
20300
|
+
});
|
|
20301
|
+
} catch (err) {
|
|
20302
|
+
}
|
|
20303
|
+
if (prevDelegateTip) {
|
|
20304
|
+
const validationErrors = await keystoneService.validate({
|
|
20305
|
+
currentIbGib: keystoneIbGib,
|
|
20306
|
+
prevIbGib: prevDelegateTip
|
|
20307
|
+
});
|
|
20308
|
+
if (validationErrors && validationErrors.length > 0) {
|
|
20309
|
+
throw new Error(`Delegate keystone evolution validation failed: ${validationErrors.join(", ")} (E: 5212f8492ac839953842631834bcd827)`);
|
|
20225
20310
|
}
|
|
20226
|
-
|
|
20227
|
-
await
|
|
20228
|
-
|
|
20229
|
-
|
|
20230
|
-
|
|
20231
|
-
|
|
20232
|
-
|
|
20233
|
-
if (
|
|
20234
|
-
|
|
20311
|
+
} else {
|
|
20312
|
+
const validationErrors = await keystoneService.validateKeystoneGraph({
|
|
20313
|
+
keystoneIbGib,
|
|
20314
|
+
getLatest: false,
|
|
20315
|
+
invalidIfMoreRecentKeystoneFoundInSpace: false,
|
|
20316
|
+
space
|
|
20317
|
+
});
|
|
20318
|
+
if (validationErrors && validationErrors.length > 0) {
|
|
20319
|
+
throw new Error(`Delegate keystone graph validation failed: ${validationErrors.join(", ")} (E: 3a288fae39b7d82f)`);
|
|
20235
20320
|
}
|
|
20236
20321
|
}
|
|
20322
|
+
const proof = keystoneIbGib.data?.proofs?.[0];
|
|
20323
|
+
const claim = proof?.claim;
|
|
20324
|
+
const sAddr = claim?.target;
|
|
20325
|
+
if (!sAddr) {
|
|
20326
|
+
throw new Error("No target address found in sync claim");
|
|
20327
|
+
}
|
|
20328
|
+
const sIbGib = relatedKeystoneIbGibs.find((ibGib) => getIbGibAddr({ ibGib }) === sAddr);
|
|
20329
|
+
if (!sIbGib) {
|
|
20330
|
+
throw new Error(`Session keystone ${sAddr} must be provided in relatedKeystoneIbGibs (E: fe5a68438e288ab4e86c90d81d142826)`);
|
|
20331
|
+
}
|
|
20332
|
+
const sIntrinsicErrors = await validateIbGibIntrinsically({ ibGib: sIbGib });
|
|
20333
|
+
if (sIntrinsicErrors && sIntrinsicErrors.length > 0) {
|
|
20334
|
+
throw new Error(`Intrinsic validation failed for S^Stjp: ${sIntrinsicErrors.join(", ")} (E: 802d8350c3cccbd7184dd43866c05526)`);
|
|
20335
|
+
}
|
|
20336
|
+
const sGenesisErrors = await keystoneService.validateGenesisKeystone({ keystoneIbGib: sIbGib });
|
|
20337
|
+
if (sGenesisErrors && sGenesisErrors.length > 0) {
|
|
20338
|
+
throw new Error(`Genesis validation failed for S^Stjp: ${sGenesisErrors.join(", ")} (E: 8afdc1dbed48c000455b35585dc26826)`);
|
|
20339
|
+
}
|
|
20340
|
+
await metaspace.put({ ibGibs: [keystoneIbGib, sIbGib], space });
|
|
20341
|
+
await metaspace.registerNewIbGib({ ibGib: keystoneIbGib, space });
|
|
20342
|
+
await metaspace.registerNewIbGib({ ibGib: sIbGib, space });
|
|
20237
20343
|
}
|
|
20238
20344
|
|
|
20239
20345
|
// src/server/serve-gib/handlers/api/keystone/keystone-post.handler.mts
|
|
@@ -20999,7 +21105,7 @@ var KeystoneEvolveHandler = class _KeystoneEvolveHandler extends ServeGibHandler
|
|
|
20999
21105
|
} catch (err) {
|
|
21000
21106
|
return this.error(400, "Invalid request JSON body: bodyStr does NOT parse. (E: 2f81c8c80a6884ff32b877671e92f326)");
|
|
21001
21107
|
}
|
|
21002
|
-
const { keystoneIbGib,
|
|
21108
|
+
const { keystoneIbGib, relatedKeystoneIbGibs = [] } = parsed;
|
|
21003
21109
|
if (!keystoneIbGib) {
|
|
21004
21110
|
return this.error(400, "Invalid request. Body must contain keystoneIbGib (E: e234647f79282982c8012fe8015f5826)");
|
|
21005
21111
|
}
|
|
@@ -21010,7 +21116,7 @@ var KeystoneEvolveHandler = class _KeystoneEvolveHandler extends ServeGibHandler
|
|
|
21010
21116
|
await validateAndRegisterEvolveKeystone({
|
|
21011
21117
|
domainAddr,
|
|
21012
21118
|
keystoneIbGib,
|
|
21013
|
-
|
|
21119
|
+
relatedKeystoneIbGibs,
|
|
21014
21120
|
metaspace: reqCtx.metaspace,
|
|
21015
21121
|
space
|
|
21016
21122
|
});
|