@ibgib/core-gib 0.1.4 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/dist/assumptions.respec.mjs.map +1 -1
- package/dist/common/alias/alias-helper.mjs +1 -1
- package/dist/common/alias/alias-helper.mjs.map +1 -1
- package/dist/common/comment/comment-helper.mjs.map +1 -1
- package/dist/common/display/display-helper.mjs.map +1 -1
- package/dist/common/display/display-types.d.mts +1 -1
- package/dist/common/display/display-types.d.mts.map +1 -1
- package/dist/common/encrypt/encrypt-helper.mjs.map +1 -1
- package/dist/common/encrypt/encrypt-types.d.mts +1 -1
- package/dist/common/encrypt/encrypt-types.d.mts.map +1 -1
- package/dist/common/error/error-helper.mjs.map +1 -1
- package/dist/common/form/form-helper.mjs.map +1 -1
- package/dist/common/form/form-items.d.mts.map +1 -1
- package/dist/common/import-export/import-export-helper.web.mjs.map +1 -1
- package/dist/common/link/link-helper.mjs.map +1 -1
- package/dist/common/meta-stone/meta-stone-helper.mjs.map +1 -1
- package/dist/common/meta-stone/meta-stone.respec.mjs.map +1 -1
- package/dist/common/other/graph-helper.mjs +3 -3
- package/dist/common/other/graph-helper.mjs.map +1 -1
- package/dist/common/other/ibgib-helper.mjs.map +1 -1
- package/dist/common/other/ibgib-helper.respec.mjs.map +1 -1
- package/dist/common/other/other-constants.mjs +4 -4
- package/dist/common/other/other-constants.mjs.map +1 -1
- package/dist/common/other/other-helper.web.mjs.map +1 -1
- package/dist/common/other/other-types.d.mts +10 -10
- package/dist/common/other/other-types.d.mts.map +1 -1
- package/dist/common/other/svg-helper.mjs.map +1 -1
- package/dist/common/pic/pic-helper.mjs.map +1 -1
- package/dist/common/pubsub/observable/observable-base-v1.mjs +1 -1
- package/dist/common/pubsub/observable/observable-base-v1.mjs.map +1 -1
- package/dist/common/pubsub/observable/observable-event/observable-event-helper.mjs.map +1 -1
- package/dist/common/pubsub/observable/observable-helper.mjs.map +1 -1
- package/dist/common/pubsub/observable/observable-types.d.mts +1 -1
- package/dist/common/pubsub/observable/observable-types.d.mts.map +1 -1
- package/dist/common/pubsub/observer/observer-helper.mjs.map +1 -1
- package/dist/common/pubsub/observer/observer-types.d.mts.map +1 -1
- package/dist/common/pubsub/subject/subject-helper.mjs.map +1 -1
- package/dist/common/pubsub/subject/subject-types.d.mts +1 -1
- package/dist/common/pubsub/subject/subject-types.d.mts.map +1 -1
- package/dist/common/pubsub/subject/subject-v1.mjs.map +1 -1
- package/dist/common/pubsub/subject/subject.respec.mjs.map +1 -1
- package/dist/common/pubsub/subscription/subscription-helper.mjs.map +1 -1
- package/dist/common/pubsub/subscription/subscription-types.d.mts.map +1 -1
- package/dist/common/pubsub/subscription/subscription-v1.mjs.map +1 -1
- package/dist/common/secret/secret-helper.mjs.map +1 -1
- package/dist/common/secret/secret-types.d.mts +1 -1
- package/dist/common/secret/secret-types.d.mts.map +1 -1
- package/dist/common/secret/secret.respec.mjs +1 -1
- package/dist/common/secret/secret.respec.mjs.map +1 -1
- package/dist/common/tag/tag-helper.mjs.map +1 -1
- package/dist/core-helper.respec.mjs.map +1 -1
- package/dist/keystone/keystone-config-builder.d.mts +77 -0
- package/dist/keystone/keystone-config-builder.d.mts.map +1 -0
- package/dist/keystone/keystone-config-builder.mjs +157 -0
- package/dist/keystone/keystone-config-builder.mjs.map +1 -0
- package/dist/keystone/keystone-constants.d.mts +36 -0
- package/dist/keystone/keystone-constants.d.mts.map +1 -0
- package/dist/keystone/keystone-constants.mjs +39 -0
- package/dist/keystone/keystone-constants.mjs.map +1 -0
- package/dist/keystone/keystone-helpers.d.mts +117 -0
- package/dist/keystone/keystone-helpers.d.mts.map +1 -0
- package/dist/keystone/keystone-helpers.mjs +455 -0
- package/dist/keystone/keystone-helpers.mjs.map +1 -0
- package/dist/keystone/keystone-service-v1.d.mts +77 -0
- package/dist/keystone/keystone-service-v1.d.mts.map +1 -0
- package/dist/keystone/keystone-service-v1.mjs +502 -0
- package/dist/keystone/keystone-service-v1.mjs.map +1 -0
- package/dist/keystone/keystone-service-v1.respec.d.mts +2 -0
- package/dist/keystone/keystone-service-v1.respec.d.mts.map +1 -0
- package/dist/keystone/keystone-service-v1.respec.mjs +460 -0
- package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -0
- package/dist/keystone/keystone-types.d.mts +248 -0
- package/dist/keystone/keystone-types.d.mts.map +1 -0
- package/dist/keystone/keystone-types.mjs +50 -0
- package/dist/keystone/keystone-types.mjs.map +1 -0
- package/dist/keystone/strategy/hash-reveal-v1/hash-reveal-v1.d.mts +35 -0
- package/dist/keystone/strategy/hash-reveal-v1/hash-reveal-v1.d.mts.map +1 -0
- package/dist/keystone/strategy/hash-reveal-v1/hash-reveal-v1.mjs +107 -0
- package/dist/keystone/strategy/hash-reveal-v1/hash-reveal-v1.mjs.map +1 -0
- package/dist/keystone/strategy/keystone-strategy-factory.d.mts +15 -0
- package/dist/keystone/strategy/keystone-strategy-factory.d.mts.map +1 -0
- package/dist/keystone/strategy/keystone-strategy-factory.mjs +26 -0
- package/dist/keystone/strategy/keystone-strategy-factory.mjs.map +1 -0
- package/dist/keystone/strategy/keystone-strategy.d.mts +48 -0
- package/dist/keystone/strategy/keystone-strategy.d.mts.map +1 -0
- package/dist/keystone/strategy/keystone-strategy.mjs +14 -0
- package/dist/keystone/strategy/keystone-strategy.mjs.map +1 -0
- package/dist/respec-gib.node.mjs +3 -1
- package/dist/respec-gib.node.mjs.map +1 -1
- package/dist/spec-helper.node.respec.d.mts.map +1 -1
- package/dist/spec-helper.node.respec.mjs +4 -6
- package/dist/spec-helper.node.respec.mjs.map +1 -1
- package/dist/timeline/timeline-api.mjs +12 -12
- package/dist/timeline/timeline-api.mjs.map +1 -1
- package/dist/witness/anonymous-fn/anonymous-fn-helper.mjs.map +1 -1
- package/dist/witness/anonymous-fn/anonymous-fn-v1.mjs.map +1 -1
- package/dist/witness/app/app-base-v1.mjs.map +1 -1
- package/dist/witness/app/app-helper.mjs.map +1 -1
- package/dist/witness/app/app-types.d.mts.map +1 -1
- package/dist/witness/factory/dynamic-form-factory-base.mjs.map +1 -1
- package/dist/witness/light-witness-base-v1.mjs.map +1 -1
- package/dist/witness/robbot/robbot-base-v1.mjs +1 -1
- package/dist/witness/robbot/robbot-base-v1.mjs.map +1 -1
- package/dist/witness/robbot/robbot-helper.mjs.map +1 -1
- package/dist/witness/robbot/robbot-types.d.mts +20 -20
- package/dist/witness/robbot/robbot-types.d.mts.map +1 -1
- package/dist/witness/space/bootstrap/bootstrap-helper.mjs.map +1 -1
- package/dist/witness/space/filesystem-space/filesystem-space-v1.mjs.map +1 -1
- package/dist/witness/space/filesystem-space/filesystem-space-v1.respec.mjs.map +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-helper.mjs.map +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.d.mts.map +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs.map +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_createAndInit.node-filesystem-space-v1.respec.mjs.map +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_persistTransformResult.node-filesystem-space-v1.respec.mjs.map +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_putGetDelete.node-filesystem-space-v1.respec.mjs.map +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space/respec/testSpace_registerNewIbGib_GetLatest.node-filesystem-space-v1.respec.mjs.map +1 -1
- package/dist/witness/space/inner-space/inner-space-v1.mjs.map +1 -1
- package/dist/witness/space/inner-space/inner-space-v1.respec.mjs.map +1 -1
- package/dist/witness/space/metaspace/metaspace-base.mjs +1 -1
- package/dist/witness/space/metaspace/metaspace-base.mjs.map +1 -1
- package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mjs.map +1 -1
- package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs.map +1 -1
- package/dist/witness/space/outer-space/outer-space-helper.mjs.map +1 -1
- package/dist/witness/space/outer-space/outer-space-types.d.mts.map +1 -1
- package/dist/witness/space/outer-space/outer-space-types.mjs +1 -1
- package/dist/witness/space/outer-space/outer-space-types.mjs.map +1 -1
- package/dist/witness/space/reconciliation-space/reconciliation-space-base.mjs.map +1 -1
- package/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs.map +1 -1
- package/dist/witness/space/space-base-v1.mjs.map +1 -1
- package/dist/witness/space/space-constants.mjs +4 -4
- package/dist/witness/space/space-constants.mjs.map +1 -1
- package/dist/witness/space/space-helper.mjs +2 -2
- package/dist/witness/space/space-helper.mjs.map +1 -1
- package/dist/witness/space/space-respec-helper.mjs.map +1 -1
- package/dist/witness/space/space-types.d.mts +4 -4
- package/dist/witness/space/space-types.d.mts.map +1 -1
- package/dist/witness/witness-base-v1.mjs.map +1 -1
- package/dist/witness/witness-form-builder.mjs.map +1 -1
- package/dist/witness/witness-helper.mjs.map +1 -1
- package/dist/witness/witness-with-context/witness-with-context-base-v1.mjs.map +1 -1
- package/package.json +6 -5
- package/src/keystone/README.md +162 -0
- package/src/keystone/keystone-config-builder.mts +187 -0
- package/src/keystone/keystone-constants.mts +44 -0
- package/src/keystone/keystone-helpers.mts +571 -0
- package/src/keystone/keystone-service-v1.mts +611 -0
- package/src/keystone/keystone-service-v1.respec.mts +555 -0
- package/src/keystone/keystone-types.mts +315 -0
- package/src/keystone/strategy/hash-reveal-v1/hash-reveal-v1.mts +146 -0
- package/src/keystone/strategy/keystone-strategy-factory.mts +35 -0
- package/src/keystone/strategy/keystone-strategy.mts +71 -0
- package/src/respec-gib.node.mts +3 -1
- package/src/spec-helper.node.respec.mts +4 -6
- package/src/witness/robbot/robbot-base-v1.mts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keystone-config-builder.mjs","sourceR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,EAAE;YAC9B,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,MAAM,EAAE,IAAI,CAAC,OAAO;SACvB,CAAC;IACN,CAAC;CACJ;AAED,8EAA8E;AAC9E,4CAA4C;AAC5C,8EAA8E;AAE9E,MAAM,OAAO,cAAc;IACvB,MAAM,CAAC,IAAI;QACP,OAAO,IAAI,4BAA4B,EAAE,CAAC;IAC9C,CAAC;CAIJ;AAED,8EAA8E;AAC9E,8BAA8B;AAC9B,8EAA8E;AAE9E,MAAM,UAAU,wBAAwB,CAAC,OAAe,eAAe;IACnE,OAAO,cAAc,CAAC,IAAI,EAAE;SACvB,QAAQ,CAAC,IAAI,CAAC;SACd,QAAQ,CAAC,GAAG,CAAC;SACb,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;SAChB,qBAAqB,CAAC,QAAQ,CAAC;SAC/B,KAAK,EAAE,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAe,cAAc;IACpE,OAAO,cAAc,CAAC,IAAI,EAAE;SACvB,QAAQ,CAAC,IAAI,CAAC;SACd,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC;SACvB,QAAQ,CAAC,GAAG,CAAC;SACb,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC;SAClB,qBAAqB,CAAC,yBAAyB,CAAC,aAAa,CAAC;SAC9D,QAAQ,CAAC,CAAC,oBAAoB,CAAC,CAAC;SAChC,KAAK,EAAE,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const KEYSTONE_ATOM = "keystone";
|
|
2
|
+
/**
|
|
3
|
+
* @see {@link KeystoneVerb.REVOKE}
|
|
4
|
+
*/
|
|
5
|
+
export declare const KEYSTONE_VERB_REVOKE = "revoke";
|
|
6
|
+
/**
|
|
7
|
+
* @see {@link KeystoneVerb.MANAGE}
|
|
8
|
+
*/
|
|
9
|
+
export declare const KEYSTONE_VERB_MANAGE = "manage";
|
|
10
|
+
export type KeystoneVerb = typeof KEYSTONE_VERB_REVOKE | typeof KEYSTONE_VERB_MANAGE;
|
|
11
|
+
/**
|
|
12
|
+
* Verbs that describe actions that can be authorized by a Keystone.
|
|
13
|
+
*/
|
|
14
|
+
export declare const KeystoneVerb: {
|
|
15
|
+
/**
|
|
16
|
+
* The specific ibGib address for the 'revoke' verb.
|
|
17
|
+
* Used in Claims to indicate the Keystone should be considered dead.
|
|
18
|
+
*/
|
|
19
|
+
REVOKE: "revoke";
|
|
20
|
+
/**
|
|
21
|
+
* The meta-verb used to authorize structural changes to the Keystone,
|
|
22
|
+
* specifically adding or removing challenge pools.
|
|
23
|
+
*
|
|
24
|
+
* "Root access" to the identity.
|
|
25
|
+
*/
|
|
26
|
+
MANAGE: "manage";
|
|
27
|
+
};
|
|
28
|
+
export declare const KEYSTONE_VERB_VALID_VALUES: ("revoke" | "manage")[];
|
|
29
|
+
export declare function isKeystoneVerb(value: string): value is KeystoneVerb;
|
|
30
|
+
/**
|
|
31
|
+
* Standard pool IDs can be conventionally named after their primary verb.
|
|
32
|
+
*/
|
|
33
|
+
export declare const POOL_ID_REVOKE = "revoke";
|
|
34
|
+
export declare const POOL_ID_MANAGE = "manage";
|
|
35
|
+
export declare const POOL_ID_DEFAULT = "default";
|
|
36
|
+
//# sourceMappingURL=keystone-constants.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keystone-constants.d.mts","sourceRoot":"","sources":["../../src/keystone/keystone-constants.mts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,aAAa,CAAC;AAGxC;;GAEG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAC7C;;GAEG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAC7C,MAAM,MAAM,YAAY,GAClB,OAAO,oBAAoB,GAC3B,OAAO,oBAAoB,CAAC;AAElC;;GAEG;AACH,eAAO,MAAM,YAAY;IACrB;;;OAGG;;IAEH;;;;;OAKG;;CAEoC,CAAC;AAC5C,eAAO,MAAM,0BAA0B,yBAA8B,CAAC;AACtE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,YAAY,CAEnE;AAGD;;GAEG;AACH,eAAO,MAAM,cAAc,WAAuB,CAAC;AACnD,eAAO,MAAM,cAAc,WAAuB,CAAC;AACnD,eAAO,MAAM,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const KEYSTONE_ATOM = "keystone";
|
|
2
|
+
// #region KeystoneVerb enum
|
|
3
|
+
/**
|
|
4
|
+
* @see {@link KeystoneVerb.REVOKE}
|
|
5
|
+
*/
|
|
6
|
+
export const KEYSTONE_VERB_REVOKE = "revoke";
|
|
7
|
+
/**
|
|
8
|
+
* @see {@link KeystoneVerb.MANAGE}
|
|
9
|
+
*/
|
|
10
|
+
export const KEYSTONE_VERB_MANAGE = "manage";
|
|
11
|
+
/**
|
|
12
|
+
* Verbs that describe actions that can be authorized by a Keystone.
|
|
13
|
+
*/
|
|
14
|
+
export const KeystoneVerb = {
|
|
15
|
+
/**
|
|
16
|
+
* The specific ibGib address for the 'revoke' verb.
|
|
17
|
+
* Used in Claims to indicate the Keystone should be considered dead.
|
|
18
|
+
*/
|
|
19
|
+
REVOKE: KEYSTONE_VERB_REVOKE,
|
|
20
|
+
/**
|
|
21
|
+
* The meta-verb used to authorize structural changes to the Keystone,
|
|
22
|
+
* specifically adding or removing challenge pools.
|
|
23
|
+
*
|
|
24
|
+
* "Root access" to the identity.
|
|
25
|
+
*/
|
|
26
|
+
MANAGE: KEYSTONE_VERB_MANAGE,
|
|
27
|
+
};
|
|
28
|
+
export const KEYSTONE_VERB_VALID_VALUES = Object.values(KeystoneVerb);
|
|
29
|
+
export function isKeystoneVerb(value) {
|
|
30
|
+
return KEYSTONE_VERB_VALID_VALUES.includes(value);
|
|
31
|
+
}
|
|
32
|
+
// #endregion KeystoneVerb enum
|
|
33
|
+
/**
|
|
34
|
+
* Standard pool IDs can be conventionally named after their primary verb.
|
|
35
|
+
*/
|
|
36
|
+
export const POOL_ID_REVOKE = KEYSTONE_VERB_REVOKE;
|
|
37
|
+
export const POOL_ID_MANAGE = KEYSTONE_VERB_MANAGE;
|
|
38
|
+
export const POOL_ID_DEFAULT = "default";
|
|
39
|
+
//# sourceMappingURL=keystone-constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keystone-constants.mjs","sourceRoot":"","sources":["../../src/keystone/keystone-constants.mts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;AAExC,4BAA4B;AAC5B;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AAC7C;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AAK7C;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB;;;OAGG;IACH,MAAM,EAAE,oBAAoB;IAC5B;;;;;OAKG;IACH,MAAM,EAAE,oBAAoB;CACW,CAAC;AAC5C,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AACtE,MAAM,UAAU,cAAc,CAAC,KAAa;IACxC,OAAO,0BAA0B,CAAC,QAAQ,CAAC,KAAqB,CAAC,CAAC;AACtE,CAAC;AACD,+BAA+B;AAE/B;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AACnD,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AACnD,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Ib } from "@ibgib/ts-gib/dist/types.mjs";
|
|
2
|
+
import { KeystoneData_V1, KeystoneIbGib_V1, KeystoneIbInfo_V1, KeystoneChallengePool, DeterministicResult, KeystoneProof, KeystonePoolConfig } from "./keystone-types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* space-delimited keystone ib containing select keystone metadata.
|
|
5
|
+
*
|
|
6
|
+
* NOTE: This must match {@link parseKeystoneIb}
|
|
7
|
+
* @see {@link KeystoneIbInfo_V1}
|
|
8
|
+
*/
|
|
9
|
+
export declare function getKeystoneIb({ keystoneData, }: {
|
|
10
|
+
keystoneData: KeystoneData_V1;
|
|
11
|
+
}): Promise<Ib>;
|
|
12
|
+
/**
|
|
13
|
+
* NOTE: This must match {@link getKeystoneIb}
|
|
14
|
+
* @see {@link KeystoneIbInfo_V1}
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseKeystoneIb({ ib, }: {
|
|
17
|
+
ib: Ib;
|
|
18
|
+
}): Promise<KeystoneIbInfo_V1>;
|
|
19
|
+
/**
|
|
20
|
+
* The Policy Engine.
|
|
21
|
+
* Calculates exactly which challenges MUST be consumed based on config and demands.
|
|
22
|
+
* Enforces STRICT DISTINCTNESS (No double-dipping).
|
|
23
|
+
*/
|
|
24
|
+
export declare function getDeterministicRequirements({ pool, requiredChallengeIds, targetAddr }: {
|
|
25
|
+
pool: KeystoneChallengePool;
|
|
26
|
+
requiredChallengeIds?: string[];
|
|
27
|
+
targetAddr?: string;
|
|
28
|
+
}): DeterministicResult;
|
|
29
|
+
/**
|
|
30
|
+
* Helper to update the Binding Map when adding new Challenge IDs.
|
|
31
|
+
* Uses "Implicit Bucketing" (ID start char) but can be extended for full coverage.
|
|
32
|
+
*/
|
|
33
|
+
export declare function addToBindingMap(map: {
|
|
34
|
+
[char: string]: string[];
|
|
35
|
+
}, challengeId: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Helper to clean up Binding Map when removing IDs.
|
|
38
|
+
*/
|
|
39
|
+
export declare function removeFromBindingMap(map: {
|
|
40
|
+
[char: string]: string[];
|
|
41
|
+
}, challengeId: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Selects the specific pool to use for an operation based on ID, filter criteria, or verb authorization.
|
|
44
|
+
*
|
|
45
|
+
* @returns The matching KeystoneChallengePool
|
|
46
|
+
* @throws If no pool matches or if multiple pools match but one was expected.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveTargetPool({ pools, poolId, poolFilter, verb, }: {
|
|
49
|
+
pools: KeystoneChallengePool[];
|
|
50
|
+
/**
|
|
51
|
+
* Explicit ID of the pool to use.
|
|
52
|
+
*/
|
|
53
|
+
poolId?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Optional predicate to find a pool.
|
|
56
|
+
* Useful for finding delegates via metadata.
|
|
57
|
+
*/
|
|
58
|
+
poolFilter?: (pool: KeystoneChallengePool) => boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The verb being performed (e.g. 'revoke', 'manage', 'post').
|
|
61
|
+
* Used for authorization checks and auto-resolution.
|
|
62
|
+
*/
|
|
63
|
+
verb?: string;
|
|
64
|
+
}): KeystoneChallengePool;
|
|
65
|
+
/**
|
|
66
|
+
* Calculates the complete list of Challenge IDs to solve for a given operation.
|
|
67
|
+
* Combines Deterministic requirements (Mandatory/Binding/FIFO) with Stochastic requirements.
|
|
68
|
+
*
|
|
69
|
+
* @returns Array of unique challenge IDs.
|
|
70
|
+
*/
|
|
71
|
+
export declare function selectChallengeIds({ pool, targetAddr, requiredChallengeIds, }: {
|
|
72
|
+
pool: KeystoneChallengePool;
|
|
73
|
+
/**
|
|
74
|
+
* The address of the target ibgib (used for binding entropy).
|
|
75
|
+
*/
|
|
76
|
+
targetAddr?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Explicit demands from a verifier.
|
|
79
|
+
*/
|
|
80
|
+
requiredChallengeIds?: string[];
|
|
81
|
+
}): string[];
|
|
82
|
+
/**
|
|
83
|
+
* Calculates the NEXT state of the Challenge Pools given a specific consumption event.
|
|
84
|
+
* Handles TopUp, ReplaceAll, Consume, and ScorchedEarth strategies.
|
|
85
|
+
*
|
|
86
|
+
* @returns The new array of KeystoneChallengePools (including the modified one).
|
|
87
|
+
*/
|
|
88
|
+
export declare function applyReplenishmentStrategy({ prevPools, targetPoolId, consumedIds, masterSecret, strategy, config, }: {
|
|
89
|
+
prevPools: KeystoneChallengePool[];
|
|
90
|
+
targetPoolId: string;
|
|
91
|
+
consumedIds: string[];
|
|
92
|
+
masterSecret: string;
|
|
93
|
+
/**
|
|
94
|
+
* The instantiated KeystoneStrategy (e.g. HashRevealV1) used to generate new challenges.
|
|
95
|
+
*/
|
|
96
|
+
strategy: any;
|
|
97
|
+
config: KeystonePoolConfig;
|
|
98
|
+
}): Promise<KeystoneChallengePool[]>;
|
|
99
|
+
/**
|
|
100
|
+
* Validates the transition from Prev -> Curr.
|
|
101
|
+
* Enforces Cryptography AND Behavioral Policy.
|
|
102
|
+
*
|
|
103
|
+
* @returns Array of validation error strings. Empty array means Valid.
|
|
104
|
+
*/
|
|
105
|
+
export declare function validateKeystoneTransition({ currentIbGib, prevIbGib, }: {
|
|
106
|
+
currentIbGib: KeystoneIbGib_V1;
|
|
107
|
+
prevIbGib: KeystoneIbGib_V1;
|
|
108
|
+
}): Promise<string[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Helper to verify a single proof against a specific pool.
|
|
111
|
+
*/
|
|
112
|
+
export declare function verifyProofAgainstPool({ proof, pool, errors, }: {
|
|
113
|
+
proof: KeystoneProof;
|
|
114
|
+
pool: KeystoneChallengePool;
|
|
115
|
+
errors: string[];
|
|
116
|
+
}): Promise<void>;
|
|
117
|
+
//# sourceMappingURL=keystone-helpers.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keystone-helpers.d.mts","sourceRoot":"","sources":["../../src/keystone/keystone-helpers.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAmB,MAAM,8BAA8B,CAAC;AAMnE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,aAAa,EAAE,kBAAkB,EAAuE,MAAM,sBAAsB,CAAC;AAOhP;;;;;GAKG;AACH,wBAAsB,aAA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AAE,qBAAqB,CAAC;IAC5B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACnC,GAAG,MAAM,EAAE,CA+BX;AAoBD;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAAC,EAC7C,SAAS,EACT,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,MAAM,GACT,EAAE;IACC,SAAS,EAAE,qBAAqB,EAAE,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC;IACd,MAAM,EAAE,kBAAkB,CAAC;CAC9B,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAiEnC;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAAC,EAC7C,YAAY,EACZ,SAAS,GACZ,EAAE;IACC,YAAY,EAAE,gBAAgB,CAAC;IAC/B,SAAS,EAAE,gBAAgB,CAAC;CAC/B,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAoDpB;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,EACzC,KAAK,EACL,IAAI,EACJ,MAAM,GACT,EAAE;IACC,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,qBAAqB,CAAC;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAC;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4DhB"}
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { extractErrorMsg, hash, pretty } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
2
|
+
import { getIbAndGib, getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
|
|
3
|
+
import { validateIbGibIntrinsically } from "@ibgib/ts-gib/dist/V1/validate-helper.mjs";
|
|
4
|
+
import { GLOBAL_LOG_A_LOT } from "../core-constants.mjs";
|
|
5
|
+
import { KEYSTONE_ATOM } from "./keystone-constants.mjs";
|
|
6
|
+
import { KeystoneReplenishStrategy, KEYSTONE_REPLENISH_STRATEGY_VALID_VALUES } from "./keystone-types.mjs";
|
|
7
|
+
import { KeystoneStrategyFactory } from "./strategy/keystone-strategy-factory.mjs";
|
|
8
|
+
const logalot = GLOBAL_LOG_A_LOT;
|
|
9
|
+
/**
|
|
10
|
+
* space-delimited keystone ib containing select keystone metadata.
|
|
11
|
+
*
|
|
12
|
+
* NOTE: This must match {@link parseKeystoneIb}
|
|
13
|
+
* @see {@link KeystoneIbInfo_V1}
|
|
14
|
+
*/
|
|
15
|
+
export async function getKeystoneIb({ keystoneData, }) {
|
|
16
|
+
const lc = `[${getKeystoneIb.name}]`;
|
|
17
|
+
try {
|
|
18
|
+
if (logalot) {
|
|
19
|
+
console.log(`${lc} starting... (I: c3022a146faac9730154f34d1439a225)`);
|
|
20
|
+
}
|
|
21
|
+
const atom = KEYSTONE_ATOM;
|
|
22
|
+
const ib = [
|
|
23
|
+
atom,
|
|
24
|
+
].join(' ');
|
|
25
|
+
return ib;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
if (logalot) {
|
|
33
|
+
console.log(`${lc} complete.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* NOTE: This must match {@link getKeystoneIb}
|
|
39
|
+
* @see {@link KeystoneIbInfo_V1}
|
|
40
|
+
*/
|
|
41
|
+
export async function parseKeystoneIb({ ib, }) {
|
|
42
|
+
const lc = `[${parseKeystoneIb.name}]`;
|
|
43
|
+
try {
|
|
44
|
+
if (logalot) {
|
|
45
|
+
console.log(`${lc} starting... (I: 73cb6832984255ed48b2f44db6a21e25)`);
|
|
46
|
+
}
|
|
47
|
+
const [atom] = ib.split(' ');
|
|
48
|
+
if (atom !== KEYSTONE_ATOM) {
|
|
49
|
+
throw new Error(`invalid keystone ib. atom found in ib (${atom}) does not match keystone atom (${KEYSTONE_ATOM}) (E: 79b3d587824c4271b6e60acc76e0c825)`);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
atom,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
if (logalot) {
|
|
61
|
+
console.log(`${lc} complete.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The Policy Engine.
|
|
67
|
+
* Calculates exactly which challenges MUST be consumed based on config and demands.
|
|
68
|
+
* Enforces STRICT DISTINCTNESS (No double-dipping).
|
|
69
|
+
*/
|
|
70
|
+
export function getDeterministicRequirements({ pool, requiredChallengeIds, targetAddr }) {
|
|
71
|
+
const behavior = pool.config.behavior;
|
|
72
|
+
const mandatory = new Set();
|
|
73
|
+
// Start with all available IDs.
|
|
74
|
+
// We assume Object.keys respects insertion order (ES2015+), crucial for FIFO.
|
|
75
|
+
let available = Object.keys(pool.challenges);
|
|
76
|
+
// ---------------------------------------------------------
|
|
77
|
+
// 1. Alice's Demands (Explicit Requirements)
|
|
78
|
+
// ---------------------------------------------------------
|
|
79
|
+
if (requiredChallengeIds && requiredChallengeIds.length > 0) {
|
|
80
|
+
for (const id of requiredChallengeIds) {
|
|
81
|
+
if (!pool.challenges[id]) {
|
|
82
|
+
throw new Error(`(UNEXPECTED) Required challenge ID not found in pool: ${id} (E: 2c9f8...)`);
|
|
83
|
+
}
|
|
84
|
+
// Strict: Consume it.
|
|
85
|
+
if (!available.includes(id)) {
|
|
86
|
+
// Should be caught by check above, but handles duplicates in 'demands'
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
mandatory.add(id);
|
|
90
|
+
}
|
|
91
|
+
// Remove from available pool
|
|
92
|
+
available = available.filter(id => !mandatory.has(id));
|
|
93
|
+
}
|
|
94
|
+
// ---------------------------------------------------------
|
|
95
|
+
// 2. Target Binding (Explicit Buckets)
|
|
96
|
+
// ---------------------------------------------------------
|
|
97
|
+
if (behavior.targetBindingChars > 0 && targetAddr) {
|
|
98
|
+
const { gib } = getIbAndGib({ ibGibAddr: targetAddr });
|
|
99
|
+
if (gib) {
|
|
100
|
+
// Get required hex prefixes (e.g. 'a', 'b', 'c', '1')
|
|
101
|
+
const prefixes = gib.substring(0, behavior.targetBindingChars).toLowerCase();
|
|
102
|
+
for (const char of prefixes) {
|
|
103
|
+
// Look in the Explicit Bucket
|
|
104
|
+
const bucket = pool.bindingMap[char] || [];
|
|
105
|
+
// Find the first ID in this bucket that is still in 'available'
|
|
106
|
+
const match = bucket.find(id => available.includes(id));
|
|
107
|
+
if (!match) {
|
|
108
|
+
throw new Error(`Entropy Exhaustion. Cannot satisfy binding for char '${char}'. (E: 8d3a1...)`);
|
|
109
|
+
}
|
|
110
|
+
// Strict: Consume it.
|
|
111
|
+
mandatory.add(match);
|
|
112
|
+
available = available.filter(id => id !== match);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// ---------------------------------------------------------
|
|
117
|
+
// 3. FIFO (Sequential)
|
|
118
|
+
// ---------------------------------------------------------
|
|
119
|
+
if (behavior.selectSequentially > 0) {
|
|
120
|
+
// Take the first N from the remaining available list
|
|
121
|
+
if (available.length < behavior.selectSequentially) {
|
|
122
|
+
console.error(`[getDeterministicRequirements] Entropy Exhaustion! AvailableCount: ${available.length}, Required Seq: ${behavior.selectSequentially}. Available IDs: ${available.join(',')}`);
|
|
123
|
+
throw new Error(`Entropy Exhaustion. Insufficient challenges for FIFO requirement. (E: 9c2b4...)`);
|
|
124
|
+
}
|
|
125
|
+
const fifoIds = available.slice(0, behavior.selectSequentially);
|
|
126
|
+
fifoIds.forEach(id => mandatory.add(id));
|
|
127
|
+
// Remove from available
|
|
128
|
+
available = available.slice(behavior.selectSequentially);
|
|
129
|
+
}
|
|
130
|
+
return { mandatoryIds: mandatory, availableIds: available };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Helper to update the Binding Map when adding new Challenge IDs.
|
|
134
|
+
* Uses "Implicit Bucketing" (ID start char) but can be extended for full coverage.
|
|
135
|
+
*/
|
|
136
|
+
export function addToBindingMap(map, challengeId) {
|
|
137
|
+
const firstChar = challengeId.charAt(0).toLowerCase();
|
|
138
|
+
// Validate it is hex
|
|
139
|
+
if (/[0-9a-f]/.test(firstChar)) {
|
|
140
|
+
if (!map[firstChar])
|
|
141
|
+
map[firstChar] = [];
|
|
142
|
+
map[firstChar].push(challengeId);
|
|
143
|
+
// OPTIONAL: Implement Full Coverage Strategy here?
|
|
144
|
+
// e.g. map[challengeId[1]].push(challengeId) ...
|
|
145
|
+
// For V1, we stick to Native/Implicit bucket (Index 0).
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Helper to clean up Binding Map when removing IDs.
|
|
150
|
+
*/
|
|
151
|
+
export function removeFromBindingMap(map, challengeId) {
|
|
152
|
+
// Since we don't know exactly which buckets an ID is in (if we did multi-bucket),
|
|
153
|
+
// we strictly should scan all. For V1 Native, we check first char.
|
|
154
|
+
// SAFE IMPLEMENTATION: Scan all buckets.
|
|
155
|
+
for (const key of Object.keys(map)) {
|
|
156
|
+
map[key] = map[key].filter(id => id !== challengeId);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Selects the specific pool to use for an operation based on ID, filter criteria, or verb authorization.
|
|
161
|
+
*
|
|
162
|
+
* @returns The matching KeystoneChallengePool
|
|
163
|
+
* @throws If no pool matches or if multiple pools match but one was expected.
|
|
164
|
+
*/
|
|
165
|
+
export function resolveTargetPool({ pools, poolId, poolFilter, verb, }) {
|
|
166
|
+
const lc = `[resolveTargetPool]`;
|
|
167
|
+
try {
|
|
168
|
+
let pool;
|
|
169
|
+
if (poolId) {
|
|
170
|
+
// 1. Explicit ID Strategy
|
|
171
|
+
pool = pools.find(p => p.id === poolId);
|
|
172
|
+
if (!pool) {
|
|
173
|
+
throw new Error(`Pool not found with ID: ${poolId} (E: 4a2b17428515c1e82813158581898125)`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (poolFilter) {
|
|
177
|
+
// 2. Filter Strategy
|
|
178
|
+
const matches = pools.filter(poolFilter);
|
|
179
|
+
if (matches.length === 0) {
|
|
180
|
+
throw new Error(`No pool matched the provided filter. (E: 5b3c27428515c1e82813158581898125)`);
|
|
181
|
+
}
|
|
182
|
+
// For now, we take the first match. In future, might want to be strict about uniqueness.
|
|
183
|
+
pool = matches[0];
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
// 3. Auto-Resolution by Verb Strategy
|
|
187
|
+
if (!verb) {
|
|
188
|
+
throw new Error(`Cannot auto-resolve pool without a verb. (E: 6c4d37428515c1e82813158581898125)`);
|
|
189
|
+
}
|
|
190
|
+
// Priority A: Look for Specific Match (Pool explicitly lists this verb)
|
|
191
|
+
pool = pools.find(p => p.config.allowedVerbs && p.config.allowedVerbs.includes(verb));
|
|
192
|
+
// Priority B: Look for General/Default (No restrictions / Wildcard)
|
|
193
|
+
if (!pool) {
|
|
194
|
+
pool = pools.find(p => !p.config.allowedVerbs || p.config.allowedVerbs.length === 0);
|
|
195
|
+
}
|
|
196
|
+
if (!pool) {
|
|
197
|
+
throw new Error(`No suitable pool found for verb: ${verb} (E: 7d5e47428515c1e82813158581898125)`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// 4. Authorization Check (Applies to all strategies if verb is present)
|
|
201
|
+
if (verb && pool.config.allowedVerbs && pool.config.allowedVerbs.length > 0) {
|
|
202
|
+
if (!pool.config.allowedVerbs.includes(verb)) {
|
|
203
|
+
throw new Error(`Pool ${pool.id} is not authorized for verb: ${verb} (E: 8e6f57428515c1e82813158581898125)`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return pool;
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Calculates the complete list of Challenge IDs to solve for a given operation.
|
|
215
|
+
* Combines Deterministic requirements (Mandatory/Binding/FIFO) with Stochastic requirements.
|
|
216
|
+
*
|
|
217
|
+
* @returns Array of unique challenge IDs.
|
|
218
|
+
*/
|
|
219
|
+
export function selectChallengeIds({ pool, targetAddr, requiredChallengeIds, }) {
|
|
220
|
+
const lc = `[selectChallengeIds]`;
|
|
221
|
+
try {
|
|
222
|
+
// 1. Get Deterministic Requirements
|
|
223
|
+
const { mandatoryIds, availableIds } = getDeterministicRequirements({
|
|
224
|
+
pool,
|
|
225
|
+
requiredChallengeIds,
|
|
226
|
+
targetAddr
|
|
227
|
+
});
|
|
228
|
+
// 2. Stochastic Selection
|
|
229
|
+
const randomCount = pool.config.behavior.selectRandomly;
|
|
230
|
+
const randomIds = [];
|
|
231
|
+
if (randomCount > 0) {
|
|
232
|
+
if (availableIds.length < randomCount) {
|
|
233
|
+
throw new Error(`Insufficient challenges for random requirement. Need ${randomCount}, have ${availableIds.length} (E: 9f7a67428515c1e82813158581898125)`);
|
|
234
|
+
}
|
|
235
|
+
// Shuffle & Pick
|
|
236
|
+
// Note: simple Math.random sort is sufficient for V1 stochastic selection
|
|
237
|
+
// as we are just picking from valid available options.
|
|
238
|
+
const shuffled = [...availableIds].sort(() => 0.5 - Math.random());
|
|
239
|
+
randomIds.push(...shuffled.slice(0, randomCount));
|
|
240
|
+
}
|
|
241
|
+
// 3. Combine
|
|
242
|
+
return [...mandatoryIds, ...randomIds];
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Generates an opaque, collision-resistant ID for a challenge.
|
|
251
|
+
* atow (2025/12/22) - Hash(Salt + Timestamp + Index)
|
|
252
|
+
*/
|
|
253
|
+
async function generateOpaqueChallengeId({ salt, timestamp, index }) {
|
|
254
|
+
// Use first 16 chars of hex (64 bits) for brevity + safety.
|
|
255
|
+
const raw = await hash({ s: `${salt}${timestamp}${index}` });
|
|
256
|
+
return raw.substring(0, 16);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Calculates the NEXT state of the Challenge Pools given a specific consumption event.
|
|
260
|
+
* Handles TopUp, ReplaceAll, Consume, and ScorchedEarth strategies.
|
|
261
|
+
*
|
|
262
|
+
* @returns The new array of KeystoneChallengePools (including the modified one).
|
|
263
|
+
*/
|
|
264
|
+
export async function applyReplenishmentStrategy({ prevPools, targetPoolId, consumedIds, masterSecret, strategy, config, }) {
|
|
265
|
+
const lc = `[applyReplenishmentStrategy]`;
|
|
266
|
+
try {
|
|
267
|
+
const newPools = JSON.parse(JSON.stringify(prevPools));
|
|
268
|
+
const targetIdx = newPools.findIndex((p) => p.id === targetPoolId);
|
|
269
|
+
if (targetIdx === -1) {
|
|
270
|
+
throw new Error(`Target pool ${targetPoolId} not found in keystone data. (E: 75200388d22744838634524233772545)`);
|
|
271
|
+
}
|
|
272
|
+
const pool = newPools[targetIdx];
|
|
273
|
+
const poolSecret = await strategy.derivePoolSecret({ masterSecret });
|
|
274
|
+
const timestamp = Date.now().toString();
|
|
275
|
+
const strategyType = config.behavior.replenish;
|
|
276
|
+
// Clean up Binding Map for consumed IDs
|
|
277
|
+
consumedIds.forEach(id => {
|
|
278
|
+
if (pool.bindingMap) {
|
|
279
|
+
removeFromBindingMap(pool.bindingMap, id);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
if (strategyType === KeystoneReplenishStrategy.topUp) {
|
|
283
|
+
// Remove consumed
|
|
284
|
+
consumedIds.forEach(id => delete pool.challenges[id]);
|
|
285
|
+
// Add New
|
|
286
|
+
for (let i = 0; i < consumedIds.length; i++) {
|
|
287
|
+
const newId = await generateOpaqueChallengeId({
|
|
288
|
+
salt: config.salt, timestamp, index: i
|
|
289
|
+
});
|
|
290
|
+
const solution = await strategy.generateSolution({
|
|
291
|
+
poolSecret, poolId: pool.id, challengeId: newId
|
|
292
|
+
});
|
|
293
|
+
pool.challenges[newId] = await strategy.generateChallenge({ solution });
|
|
294
|
+
// Update Binding Map
|
|
295
|
+
if (!pool.bindingMap) {
|
|
296
|
+
pool.bindingMap = {};
|
|
297
|
+
}
|
|
298
|
+
addToBindingMap(pool.bindingMap, newId);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
else if (strategyType === KeystoneReplenishStrategy.replaceAll) {
|
|
302
|
+
pool.challenges = {};
|
|
303
|
+
pool.bindingMap = {};
|
|
304
|
+
for (let i = 0; i < config.behavior.size; i++) {
|
|
305
|
+
const newId = await generateOpaqueChallengeId({
|
|
306
|
+
salt: config.salt, timestamp, index: i
|
|
307
|
+
});
|
|
308
|
+
const solution = await strategy.generateSolution({
|
|
309
|
+
poolSecret, poolId: pool.id, challengeId: newId
|
|
310
|
+
});
|
|
311
|
+
pool.challenges[newId] = await strategy.generateChallenge({ solution });
|
|
312
|
+
addToBindingMap(pool.bindingMap, newId);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
else if (strategyType === KeystoneReplenishStrategy.consume) {
|
|
316
|
+
consumedIds.forEach(id => delete pool.challenges[id]);
|
|
317
|
+
}
|
|
318
|
+
else if (strategyType === KeystoneReplenishStrategy.scorchedEarth) {
|
|
319
|
+
pool.challenges = {};
|
|
320
|
+
pool.bindingMap = {};
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
throw new Error(`Unknown replenish strategy: ${strategyType}. Valid list: ${pretty(KEYSTONE_REPLENISH_STRATEGY_VALID_VALUES)} (E: 0acf56f1e1486240080e11e8046d0825)`);
|
|
324
|
+
}
|
|
325
|
+
return newPools;
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Validates the transition from Prev -> Curr.
|
|
334
|
+
* Enforces Cryptography AND Behavioral Policy.
|
|
335
|
+
*
|
|
336
|
+
* @returns Array of validation error strings. Empty array means Valid.
|
|
337
|
+
*/
|
|
338
|
+
export async function validateKeystoneTransition({ currentIbGib, prevIbGib, }) {
|
|
339
|
+
const lc = `[${validateKeystoneTransition.name}]`;
|
|
340
|
+
const errors = [];
|
|
341
|
+
try {
|
|
342
|
+
if (!currentIbGib) {
|
|
343
|
+
throw new Error(`(UNEXPECTED) currentIbGib falsy? (E: 3c0f02655fa8279e386a079ebb604b25)`);
|
|
344
|
+
}
|
|
345
|
+
if (!prevIbGib) {
|
|
346
|
+
throw new Error(`(UNEXPECTED) prevIbGib falsy? (E: 0d07c812634d839c784f31b8848ba825)`);
|
|
347
|
+
}
|
|
348
|
+
// intrinsic validation
|
|
349
|
+
const validationErrors = await validateIbGibIntrinsically({ ibGib: currentIbGib });
|
|
350
|
+
if (validationErrors && validationErrors.length > 0) {
|
|
351
|
+
errors.push(...validationErrors);
|
|
352
|
+
}
|
|
353
|
+
const currData = currentIbGib.data;
|
|
354
|
+
const prevData = prevIbGib.data;
|
|
355
|
+
for (const proof of currData.proofs) {
|
|
356
|
+
if (proof.solutions.length === 0) {
|
|
357
|
+
errors.push(`Proof ${proof.id || 'unknown'} has no solutions.`);
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
const poolId = proof.solutions[0].poolId;
|
|
361
|
+
// Standard Verification (Internal Pools Only)
|
|
362
|
+
// The pool MUST be present in the previous frame.
|
|
363
|
+
const pool = prevData.challengePools.find(p => p.id === poolId);
|
|
364
|
+
if (!pool) {
|
|
365
|
+
errors.push(`Proof references unknown pool: ${poolId}`);
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
await verifyProofAgainstPool({ proof, pool, errors });
|
|
369
|
+
} // End proof loop
|
|
370
|
+
// Revocation Logic checks
|
|
371
|
+
if (currData.revocationInfo) {
|
|
372
|
+
const target = currData.revocationInfo.proof.claim.target;
|
|
373
|
+
const expectedTarget = getIbGibAddr({ ibGib: prevIbGib });
|
|
374
|
+
if (target !== expectedTarget) {
|
|
375
|
+
errors.push(`Revocation target mismatch. Expected ${expectedTarget}, got ${target}`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return errors;
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
382
|
+
throw error; // System errors still throw
|
|
383
|
+
}
|
|
384
|
+
finally {
|
|
385
|
+
if (logalot) {
|
|
386
|
+
console.log(`${lc} complete.`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Helper to verify a single proof against a specific pool.
|
|
392
|
+
*/
|
|
393
|
+
export async function verifyProofAgainstPool({ proof, pool, errors, }) {
|
|
394
|
+
const lc = `[${verifyProofAgainstPool.name}]`;
|
|
395
|
+
try {
|
|
396
|
+
if (logalot) {
|
|
397
|
+
console.log(`${lc} starting... (I: b8f9b6085888eea2258bf579ecd5e825)`);
|
|
398
|
+
}
|
|
399
|
+
// 0. VERB AUTH
|
|
400
|
+
if (pool.config.allowedVerbs && pool.config.allowedVerbs.length > 0) {
|
|
401
|
+
if (!proof.claim.verb || !pool.config.allowedVerbs.includes(proof.claim.verb)) {
|
|
402
|
+
errors.push(`Policy Violation: Pool ${pool.id} used for unauthorized verb ${proof.claim.verb}`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
// 1. Reconstruct Deterministic Requirements
|
|
406
|
+
const { mandatoryIds, availableIds } = getDeterministicRequirements({
|
|
407
|
+
pool,
|
|
408
|
+
requiredChallengeIds: proof.requiredChallengeIds,
|
|
409
|
+
targetAddr: proof.claim.target // Not used extensively in V1 logic yet, mainly for logging/context
|
|
410
|
+
});
|
|
411
|
+
// 2. Check Mandatory
|
|
412
|
+
const proofIds = new Set(proof.solutions.map(s => s.challengeId));
|
|
413
|
+
for (const id of mandatoryIds) {
|
|
414
|
+
if (!proofIds.has(id)) {
|
|
415
|
+
errors.push(`Policy Violation: Missing mandatory challenge ${id}`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
// 3. Stochastic
|
|
419
|
+
const randomCandidates = [...proofIds].filter(id => !mandatoryIds.has(id));
|
|
420
|
+
const requiredRandomCount = pool.config.behavior.selectRandomly;
|
|
421
|
+
if (randomCandidates.length < requiredRandomCount) {
|
|
422
|
+
errors.push(`Policy Violation: Insufficient random count. Need ${requiredRandomCount}, got ${randomCandidates.length}`);
|
|
423
|
+
}
|
|
424
|
+
// 4. Validity (Double Dip / Existence)
|
|
425
|
+
for (const id of randomCandidates) {
|
|
426
|
+
if (!availableIds.includes(id)) {
|
|
427
|
+
errors.push(`Policy Violation: ID ${id} is invalid or double-dipped.`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
// 5. Crypto
|
|
431
|
+
const strategy = KeystoneStrategyFactory.create({ config: pool.config });
|
|
432
|
+
for (const solution of proof.solutions) {
|
|
433
|
+
const challenge = pool.challenges[solution.challengeId];
|
|
434
|
+
if (!challenge) {
|
|
435
|
+
errors.push(`Crypto Violation: Challenge ${solution.challengeId} not found in pool.`);
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
const isValid = await strategy.validateSolution({ solution, challenge });
|
|
439
|
+
if (!isValid) {
|
|
440
|
+
errors.push(`Crypto Violation: Solution for ${solution.challengeId} is invalid.`);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
447
|
+
throw error;
|
|
448
|
+
}
|
|
449
|
+
finally {
|
|
450
|
+
if (logalot) {
|
|
451
|
+
console.log(`${lc} complete.`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
//# sourceMappingURL=keystone-helpers.mjs.map
|