@ibgib/web-gib 0.0.11 → 0.0.13
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/agent-texts/common-agent-texts.d.mts +0 -6
- package/dist/agent-texts/common-agent-texts.d.mts.map +1 -1
- package/dist/agent-texts/common-agent-texts.mjs +34 -35
- package/dist/agent-texts/common-agent-texts.mjs.map +1 -1
- package/dist/agent-texts/primary-agent-texts.d.mts +1 -15
- package/dist/agent-texts/primary-agent-texts.d.mts.map +1 -1
- package/dist/agent-texts/primary-agent-texts.mjs +21 -26
- package/dist/agent-texts/primary-agent-texts.mjs.map +1 -1
- package/dist/agent-texts/project-agent-texts.d.mts +1 -7
- package/dist/agent-texts/project-agent-texts.d.mts.map +1 -1
- package/dist/agent-texts/project-agent-texts.mjs +28 -28
- package/dist/agent-texts/project-agent-texts.mjs.map +1 -1
- package/dist/agent-texts/project-child-text-agent-texts.d.mts +1 -4
- package/dist/agent-texts/project-child-text-agent-texts.d.mts.map +1 -1
- package/dist/agent-texts/project-child-text-agent-texts.mjs +30 -25
- package/dist/agent-texts/project-child-text-agent-texts.mjs.map +1 -1
- package/dist/agent-texts/projects-agent-texts.d.mts +1 -3
- package/dist/agent-texts/projects-agent-texts.d.mts.map +1 -1
- package/dist/agent-texts/projects-agent-texts.mjs +15 -14
- package/dist/agent-texts/projects-agent-texts.mjs.map +1 -1
- package/dist/agent-texts/raw-agent-texts.d.mts +1 -3
- package/dist/agent-texts/raw-agent-texts.d.mts.map +1 -1
- package/dist/agent-texts/raw-agent-texts.mjs +17 -16
- package/dist/agent-texts/raw-agent-texts.mjs.map +1 -1
- package/dist/agent-texts/text-editor-agent-texts.d.mts +1 -5
- package/dist/agent-texts/text-editor-agent-texts.d.mts.map +1 -1
- package/dist/agent-texts/text-editor-agent-texts.mjs +19 -18
- package/dist/agent-texts/text-editor-agent-texts.mjs.map +1 -1
- package/dist/common/project/project-constants.d.mts +1 -0
- package/dist/common/project/project-constants.d.mts.map +1 -1
- package/dist/common/project/project-constants.mjs +1 -0
- package/dist/common/project/project-constants.mjs.map +1 -1
- package/dist/common/project/project-helper.d.mts.map +1 -1
- package/dist/common/project/project-helper.mjs +1 -2
- package/dist/common/project/project-helper.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 +156 -0
- package/dist/keystone/keystone-config-builder.mjs.map +1 -0
- package/dist/keystone/keystone-constants.d.mts +15 -0
- package/dist/keystone/keystone-constants.d.mts.map +1 -0
- package/dist/keystone/keystone-constants.mjs +15 -0
- package/dist/keystone/keystone-constants.mjs.map +1 -0
- package/dist/keystone/keystone-helpers.d.mts +54 -0
- package/dist/keystone/keystone-helpers.d.mts.map +1 -0
- package/dist/keystone/keystone-helpers.mjs +155 -0
- package/dist/keystone/keystone-helpers.mjs.map +1 -0
- package/dist/keystone/keystone-service-v1.d.mts +81 -0
- package/dist/keystone/keystone-service-v1.d.mts.map +1 -0
- package/dist/keystone/keystone-service-v1.mjs +606 -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 +443 -0
- package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -0
- package/dist/keystone/keystone-types.d.mts +231 -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 +106 -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/witness/agent/agent-constants.d.mts +9 -0
- package/dist/witness/agent/agent-constants.d.mts.map +1 -1
- package/dist/witness/agent/agent-constants.mjs +9 -0
- package/dist/witness/agent/agent-constants.mjs.map +1 -1
- package/dist/witness/agent/agent-one-file.d.mts.map +1 -1
- package/dist/witness/agent/agent-one-file.mjs.map +1 -1
- package/dist/witness/agent/agent-types.d.mts +4 -4
- package/dist/witness/agent/agent-types.d.mts.map +1 -1
- package/dist/witness/agent/agent-types.mjs +2 -3
- package/dist/witness/agent/agent-types.mjs.map +1 -1
- package/package.json +1 -1
- package/src/agent-texts/common-agent-texts.mts +35 -37
- package/src/agent-texts/primary-agent-texts.mts +20 -29
- package/src/agent-texts/project-agent-texts.mts +27 -28
- package/src/agent-texts/project-child-text-agent-texts.mts +29 -29
- package/src/agent-texts/projects-agent-texts.mts +14 -14
- package/src/agent-texts/raw-agent-texts.mts +16 -16
- package/src/agent-texts/text-editor-agent-texts.mts +18 -18
- package/src/common/project/project-constants.mts +2 -0
- package/src/common/project/project-helper.mts +2 -3
- package/src/keystone/keystone-config-builder.mts +186 -0
- package/src/keystone/keystone-constants.mts +16 -0
- package/src/keystone/keystone-helpers.mts +207 -0
- package/src/keystone/keystone-service-v1.mts +725 -0
- package/src/keystone/keystone-service-v1.respec.mts +540 -0
- package/src/keystone/keystone-types.mts +295 -0
- package/src/keystone/strategy/hash-reveal-v1/hash-reveal-v1.mts +145 -0
- package/src/keystone/strategy/keystone-strategy-factory.mts +35 -0
- package/src/keystone/strategy/keystone-strategy.mts +71 -0
- package/src/witness/agent/agent-constants.mts +10 -0
- package/src/witness/agent/agent-one-file.mts +0 -1
- package/src/witness/agent/agent-types.mts +9 -7
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { AGENT_INITIAL_CHAT_HI_PLEASEINTRO_YOURSELF, AGENT_SYSTEM_PROMPT_COMMON_INSTRUCTIONS } from "./common-agent-texts.mjs";
|
|
1
|
+
// import { AGENT_INITIAL_CHAT_HI_PLEASEINTRO_YOURSELF, AGENT_SYSTEM_PROMPT_COMMON_INSTRUCTIONS } from "./common-agent-texts.mjs";
|
|
2
2
|
|
|
3
|
-
export const AGENT_GOAL_PROJECTSAGENT = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
].join('\n');
|
|
3
|
+
// export const AGENT_GOAL_PROJECTSAGENT = [
|
|
4
|
+
// `In general, your goal is just to do your best to parse the chat texts and choose the best course of action in terms of one or more functions. Please refer to those available function schemas and descriptions.`,
|
|
5
|
+
// `Usually, you will want to talk with them via the tell user function.`,
|
|
6
|
+
// `As a projects manager agent, you are responsible for CRUD project ibgibs. In ibgib, "project" is basically a focus of effort. You can have a project like conventional projects in code, but because of the granular version-control-like power of ibgib, you can consider a sub-component of a project itself to be a project. This is th conventional progress of work: you work on some "thing", then when it gets large enough, you break it apart into sub-"things". A "project" is this idea of a "thing", but really it's an "ibgib". But people don't know what that means. `,
|
|
7
|
+
// `But concretely, at this stage in development, I'm not quite sure what projects will entail as far implementation goes. Your job though will be to do management of them, e.g., creating projects, inter-project actions like copying/importing ibgibs, etc.`,
|
|
8
|
+
// ].join('\n');
|
|
9
9
|
|
|
10
|
-
export const AGENT_INITIAL_SYSTEM_TEXT_PROJECTSAGENT = [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
].join('\n');
|
|
10
|
+
// export const AGENT_INITIAL_SYSTEM_TEXT_PROJECTSAGENT = [
|
|
11
|
+
// AGENT_SYSTEM_PROMPT_COMMON_INSTRUCTIONS,
|
|
12
|
+
// AGENT_GOAL_PROJECTSAGENT,
|
|
13
|
+
// ].join('\n');
|
|
14
14
|
|
|
15
|
-
export const AGENT_INITIAL_CHAT_TEXT_PROJECTSAGENT = [
|
|
16
|
-
|
|
17
|
-
].join('\n')
|
|
15
|
+
// export const AGENT_INITIAL_CHAT_TEXT_PROJECTSAGENT = [
|
|
16
|
+
// AGENT_INITIAL_CHAT_HI_PLEASEINTRO_YOURSELF,
|
|
17
|
+
// ].join('\n')
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { AGENT_GOAL_COMMON, AGENT_INITIAL_CHAT_HI_PLEASEINTRO_YOURSELF, AGENT_SYSTEM_PROMPT_COMMON_INSTRUCTIONS, AGENT_WEBSITE_DESCRIPTION } from "./common-agent-texts.mjs";
|
|
1
|
+
// import { AGENT_GOAL_COMMON, AGENT_INITIAL_CHAT_HI_PLEASEINTRO_YOURSELF, AGENT_SYSTEM_PROMPT_COMMON_INSTRUCTIONS, AGENT_WEBSITE_DESCRIPTION } from "./common-agent-texts.mjs";
|
|
2
2
|
|
|
3
|
-
export const AGENT_GOAL_RAWAGENT = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
].join('\n');
|
|
3
|
+
// export const AGENT_GOAL_RAWAGENT = [
|
|
4
|
+
// AGENT_GOAL_COMMON,
|
|
5
|
+
// `You yourself are a "raw component" agent. This component just shows the user the raw details of an ibgib. Your job is to provide information guidance for this ibgib. In the future, you may be equipped with tools to edit the ibgib, but for now the ibgib is readonly.`,
|
|
6
|
+
// ].join('\n');
|
|
7
7
|
|
|
8
|
-
export const AGENT_INITIAL_SYSTEM_TEXT_RAWAGENT = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
].join('\n');
|
|
16
|
-
export const AGENT_INITIAL_CHAT_TEXT_RAWAGENT = [
|
|
17
|
-
|
|
18
|
-
].join('\n');
|
|
8
|
+
// export const AGENT_INITIAL_SYSTEM_TEXT_RAWAGENT = [
|
|
9
|
+
// AGENT_SYSTEM_PROMPT_COMMON_INSTRUCTIONS,
|
|
10
|
+
// AGENT_GOAL_RAWAGENT,
|
|
11
|
+
// AGENT_WEBSITE_DESCRIPTION,
|
|
12
|
+
// `Now, that's just to give you info on the website. Your job is not primarily to answer questions about the website. Your primary job is dealing with the ibgib being presented to the user. This includes answering any questions regarding the ibgib's various fields.`,
|
|
13
|
+
// `Currently, the raw view that the user sees will be in the center panel as one of a project's child tabs. So say a user is editing a child ibgib as if it is like a text document. It is possible they want to see the internal details of the ibgib for some reason. So they open the raw viewer.`,
|
|
14
|
+
// `This will also be a backup viewer in case there is some error, but this is not the primary use case.`,
|
|
15
|
+
// ].join('\n');
|
|
16
|
+
// export const AGENT_INITIAL_CHAT_TEXT_RAWAGENT = [
|
|
17
|
+
// AGENT_INITIAL_CHAT_HI_PLEASEINTRO_YOURSELF,
|
|
18
|
+
// ].join('\n');
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { AGENT_GOAL_COMMON, AGENT_INITIAL_CHAT_HI_PLEASEINTRO_YOURSELF, AGENT_SYSTEM_PROMPT_COMMON_INSTRUCTIONS, AGENT_WEBSITE_DESCRIPTION } from "./common-agent-texts.mjs";
|
|
1
|
+
// import { AGENT_GOAL_COMMON, AGENT_INITIAL_CHAT_HI_PLEASEINTRO_YOURSELF, AGENT_SYSTEM_PROMPT_COMMON_INSTRUCTIONS, AGENT_WEBSITE_DESCRIPTION } from "./common-agent-texts.mjs";
|
|
2
2
|
|
|
3
|
-
export const AGENT_SPECIAL_IBGIB_TYPE_TEXTEDITORAGENT = 'texteditoragent';
|
|
4
|
-
export const AGENT_GOAL_TEXTEDITORAGENT = [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
].join('\n');
|
|
3
|
+
// export const AGENT_SPECIAL_IBGIB_TYPE_TEXTEDITORAGENT = 'texteditoragent';
|
|
4
|
+
// export const AGENT_GOAL_TEXTEDITORAGENT = [
|
|
5
|
+
// AGENT_GOAL_COMMON,
|
|
6
|
+
// `You yourself are a "text editor component" agent. This component simply enables editing of text somewhere in an ibgib. Your job is to provide information guidance for this ibgib.`,
|
|
7
|
+
// ].join('\n');
|
|
8
8
|
|
|
9
|
-
export const AGENT_INITIAL_SYSTEM_TEXT_TEXTEDITORAGENT = [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
].join('\n');
|
|
17
|
-
export const AGENT_INITIAL_CHAT_TEXT_TEXTEDITORAGENT = [
|
|
18
|
-
|
|
19
|
-
].join('\n');
|
|
20
|
-
export const CHAT_WITH_AGENT_PLACEHOLDER_TEXTEDITORAGENT = '';
|
|
9
|
+
// export const AGENT_INITIAL_SYSTEM_TEXT_TEXTEDITORAGENT = [
|
|
10
|
+
// AGENT_SYSTEM_PROMPT_COMMON_INSTRUCTIONS,
|
|
11
|
+
// AGENT_GOAL_TEXTEDITORAGENT,
|
|
12
|
+
// AGENT_WEBSITE_DESCRIPTION,
|
|
13
|
+
// `Now, that's just to give you info on the website. Your job is not primarily to answer questions about the website. Your primary job is dealing with the ibgib being presented to the user. This includes answering any questions regarding the ibgib's various fields.`,
|
|
14
|
+
// `Currently, the text editor view that the user sees will be in the center panel as one of a project's child tabs. So say a user is editing a child ibgib as if it is like a text document. It is possible they want to see the internal details of the ibgib for some reason. So they open the text editor viewer.`,
|
|
15
|
+
// `This will also be a backup viewer in case there is some error, but this is not the primary use case.`,
|
|
16
|
+
// ].join('\n');
|
|
17
|
+
// export const AGENT_INITIAL_CHAT_TEXT_TEXTEDITORAGENT = [
|
|
18
|
+
// AGENT_INITIAL_CHAT_HI_PLEASEINTRO_YOURSELF,
|
|
19
|
+
// ].join('\n');
|
|
20
|
+
// export const CHAT_WITH_AGENT_PLACEHOLDER_TEXTEDITORAGENT = '';
|
|
@@ -18,13 +18,12 @@ import { GLOBAL_LOG_A_LOT } from '../../constants.mjs';
|
|
|
18
18
|
import {
|
|
19
19
|
PROJECT_ATOM, PROJECT_DESC_REGEXP, PROJECT_NAME_REGEXP,
|
|
20
20
|
DEFAULT_PROJECT_SAFE_NAME_LENGTH, DEFAULT_PROJECT_ADDL_METADATA_LENGTH,
|
|
21
|
-
PROJECT_CHILD_DEFAULT_REL8N_NAME,
|
|
22
|
-
} from './project-constants.mjs';
|
|
21
|
+
PROJECT_CHILD_DEFAULT_REL8N_NAME, AGENT_SPECIAL_IBGIB_TYPE_PROJECTAGENT,
|
|
22
|
+
} from './project-constants.mjs';
|
|
23
23
|
import {
|
|
24
24
|
ProjectData_V1, ProjectIbGib_V1, ProjectIbInfo, ProjectAddlMetadataInfo,
|
|
25
25
|
} from './project-types.mjs';
|
|
26
26
|
import { getAgentsSvc } from '../../witness/agent/agents-service-v1.mjs';
|
|
27
|
-
import { AGENT_SPECIAL_IBGIB_TYPE_PROJECTAGENT } from '../../agent-texts/project-agent-texts.mjs';
|
|
28
27
|
|
|
29
28
|
const logalot = GLOBAL_LOG_A_LOT;
|
|
30
29
|
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KeystonePoolConfig,
|
|
3
|
+
KeystonePoolConfig_HashV1,
|
|
4
|
+
KeystonePoolBehavior,
|
|
5
|
+
KeystoneReplenishStrategy,
|
|
6
|
+
KeystonePoolConfigBase
|
|
7
|
+
} from './keystone-types.mjs';
|
|
8
|
+
import { POOL_ID_DEFAULT, POOL_ID_REVOKE, VERB_REVOKE } from './keystone-constants.mjs';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Abstract Base Builder.
|
|
12
|
+
* Handles configuration common to ALL strategies (Salt, Size, Replenishment, Selection).
|
|
13
|
+
*
|
|
14
|
+
* @template TConfig The concrete config type being built.
|
|
15
|
+
*/
|
|
16
|
+
export abstract class KeystoneConfigBuilderBase<TConfig extends KeystonePoolConfigBase> {
|
|
17
|
+
protected _salt: string = 'default';
|
|
18
|
+
protected _size: number = 100;
|
|
19
|
+
protected _replenish: KeystoneReplenishStrategy = 'top-up';
|
|
20
|
+
protected _seq: number = 0;
|
|
21
|
+
protected _rand: number = 0;
|
|
22
|
+
protected _verbs: string[] = [];
|
|
23
|
+
protected _targetBinding: number = 0; // Default 0
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Sets the unique salt/ID for this pool.
|
|
28
|
+
*/
|
|
29
|
+
withSalt(salt: string): this {
|
|
30
|
+
this._salt = salt;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Sets the total number of challenges to maintain in the pool.
|
|
36
|
+
*/
|
|
37
|
+
withSize(size: number): this {
|
|
38
|
+
this._size = size;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Binds challenge selection to the content address of the target.
|
|
44
|
+
* @param chars Number of hex characters to match (e.g. 4).
|
|
45
|
+
*/
|
|
46
|
+
withTargetBinding(chars: number): this {
|
|
47
|
+
this._targetBinding = chars;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Configures the pool to use strictly Sequential (FIFO) selection.
|
|
53
|
+
* @param count Number of challenges to consume per sign.
|
|
54
|
+
*/
|
|
55
|
+
withFIFO(count: number): this {
|
|
56
|
+
this._seq = count;
|
|
57
|
+
this._rand = 0;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Configures the pool to use strictly Random selection.
|
|
63
|
+
* @param count Number of challenges to consume per sign.
|
|
64
|
+
*/
|
|
65
|
+
withRandom(count: number): this {
|
|
66
|
+
this._seq = 0;
|
|
67
|
+
this._rand = count;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Configures the pool to use Hybrid (Both FIFO and Random) selection.
|
|
73
|
+
*/
|
|
74
|
+
withHybrid(seqCount: number, randCount: number): this {
|
|
75
|
+
this._seq = seqCount;
|
|
76
|
+
this._rand = randCount;
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Sets the replenishment strategy.
|
|
82
|
+
*/
|
|
83
|
+
withReplenishStrategy(strategy: KeystoneReplenishStrategy): this {
|
|
84
|
+
this._replenish = strategy;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Constructs the behavioral config object.
|
|
90
|
+
* Helper for subclasses.
|
|
91
|
+
*/
|
|
92
|
+
protected buildBehavior(): KeystonePoolBehavior {
|
|
93
|
+
return {
|
|
94
|
+
size: this._size,
|
|
95
|
+
replenish: this._replenish,
|
|
96
|
+
selectSequentially: this._seq,
|
|
97
|
+
selectRandomly: this._rand,
|
|
98
|
+
targetBindingChars: this._targetBinding,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Restricts this pool to specific verbs.
|
|
104
|
+
* @param verbs List of verb addresses (e.g. 'revoke^gib')
|
|
105
|
+
*/
|
|
106
|
+
forVerbs(verbs: string[]): this {
|
|
107
|
+
this._verbs = verbs;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
protected buildBase(): KeystonePoolConfigBase {
|
|
112
|
+
// Helper to keep the concrete build() clean
|
|
113
|
+
return {
|
|
114
|
+
type: 'hash-reveal-v1', // This is overridden by concrete/interface usually, but needed for base shape
|
|
115
|
+
salt: this._salt,
|
|
116
|
+
allowedVerbs: this._verbs
|
|
117
|
+
} as any;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
abstract build(): TConfig;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Concrete Builder for Hash-Reveal V1 Strategy.
|
|
125
|
+
*/
|
|
126
|
+
export class KeystoneConfigBuilder_HashV1 extends KeystoneConfigBuilderBase<KeystonePoolConfig_HashV1> {
|
|
127
|
+
private _algo: 'SHA-256' | 'SHA-512' = 'SHA-256';
|
|
128
|
+
private _rounds: number = 1;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Sets the hashing strength.
|
|
132
|
+
*/
|
|
133
|
+
withHash(algo: 'SHA-256' | 'SHA-512', rounds: number = 1): this {
|
|
134
|
+
this._algo = algo;
|
|
135
|
+
this._rounds = rounds;
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
build(): KeystonePoolConfig_HashV1 {
|
|
140
|
+
return {
|
|
141
|
+
type: 'hash-reveal-v1',
|
|
142
|
+
salt: this._salt,
|
|
143
|
+
allowedVerbs: this._verbs, // <--- Mapped here
|
|
144
|
+
behavior: this.buildBehavior(),
|
|
145
|
+
algo: this._algo,
|
|
146
|
+
rounds: this._rounds,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ===========================================================================
|
|
152
|
+
// STATIC ENTRY POINT (Optional Convenience)
|
|
153
|
+
// ===========================================================================
|
|
154
|
+
|
|
155
|
+
export class KeystoneConfig {
|
|
156
|
+
static hash(): KeystoneConfigBuilder_HashV1 {
|
|
157
|
+
return new KeystoneConfigBuilder_HashV1();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Future:
|
|
161
|
+
// static pow(): KeystoneConfigBuilder_PoW { ... }
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ===========================================================================
|
|
165
|
+
// FACTORY FUNCTIONS (Presets)
|
|
166
|
+
// ===========================================================================
|
|
167
|
+
|
|
168
|
+
export function createStandardPoolConfig(salt: string = POOL_ID_DEFAULT): KeystonePoolConfig {
|
|
169
|
+
return KeystoneConfig.hash()
|
|
170
|
+
.withSalt(salt)
|
|
171
|
+
.withSize(100)
|
|
172
|
+
.withHybrid(2, 2)
|
|
173
|
+
.withReplenishStrategy('top-up')
|
|
174
|
+
.build();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function createRevocationPoolConfig(salt: string = POOL_ID_REVOKE): KeystonePoolConfig {
|
|
178
|
+
return KeystoneConfig.hash()
|
|
179
|
+
.withSalt(salt)
|
|
180
|
+
.withHash('SHA-256', 10)
|
|
181
|
+
.withSize(500)
|
|
182
|
+
.withHybrid(10, 10)
|
|
183
|
+
.withReplenishStrategy(KeystoneReplenishStrategy.scorchedEarth)
|
|
184
|
+
.forVerbs([VERB_REVOKE])
|
|
185
|
+
.build();
|
|
186
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const KEYSTONE_ATOM = "keystone";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The specific ibGib address for the 'revoke' verb.
|
|
5
|
+
* Used in Claims to indicate the Keystone should be considered dead.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This is a primitive ibGib address (ib='revoke', gib='gib'),
|
|
8
|
+
* _but with the `gib` being implied_.
|
|
9
|
+
*/
|
|
10
|
+
export const VERB_REVOKE = "revoke";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Standard pool IDs can be conventionally named after their primary verb.
|
|
14
|
+
*/
|
|
15
|
+
export const POOL_ID_REVOKE = VERB_REVOKE;
|
|
16
|
+
export const POOL_ID_DEFAULT = "default";
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { extractErrorMsg } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
2
|
+
import { Ib, TransformResult } from "@ibgib/ts-gib/dist/types.mjs";
|
|
3
|
+
import { getIbAndGib } from "@ibgib/ts-gib/dist/helper.mjs";
|
|
4
|
+
import { Factory_V1 } from "@ibgib/ts-gib/dist/V1/factory.mjs";
|
|
5
|
+
|
|
6
|
+
import { GLOBAL_LOG_A_LOT } from "../constants.mjs";
|
|
7
|
+
import { KEYSTONE_ATOM } from "./keystone-constants.mjs";
|
|
8
|
+
import { KeystoneData_V1, KeystoneIbGib_V1, KeystoneIbInfo_V1, KeystoneChallengePool } from "./keystone-types.mjs";
|
|
9
|
+
import { getGib } from "@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs";
|
|
10
|
+
|
|
11
|
+
const logalot = GLOBAL_LOG_A_LOT;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* space-delimited keystone ib containing select keystone metadata.
|
|
15
|
+
*
|
|
16
|
+
* NOTE: This must match {@link parseKeystoneIb}
|
|
17
|
+
* @see {@link KeystoneIbInfo_V1}
|
|
18
|
+
*/
|
|
19
|
+
export async function getKeystoneIb({
|
|
20
|
+
keystoneData,
|
|
21
|
+
}: {
|
|
22
|
+
keystoneData: KeystoneData_V1,
|
|
23
|
+
}): Promise<Ib> {
|
|
24
|
+
const lc = `[${getKeystoneIb.name}]`;
|
|
25
|
+
try {
|
|
26
|
+
if (logalot) { console.log(`${lc} starting... (I: c3022a146faac9730154f34d1439a225)`); }
|
|
27
|
+
|
|
28
|
+
const atom = KEYSTONE_ATOM;
|
|
29
|
+
|
|
30
|
+
const ib = [
|
|
31
|
+
atom,
|
|
32
|
+
].join(' ');
|
|
33
|
+
|
|
34
|
+
return ib;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
37
|
+
throw error;
|
|
38
|
+
} finally {
|
|
39
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* NOTE: This must match {@link getKeystoneIb}
|
|
45
|
+
* @see {@link KeystoneIbInfo_V1}
|
|
46
|
+
*/
|
|
47
|
+
export async function parseKeystoneIb({
|
|
48
|
+
ib,
|
|
49
|
+
}: {
|
|
50
|
+
ib: Ib,
|
|
51
|
+
}): Promise<KeystoneIbInfo_V1> {
|
|
52
|
+
const lc = `[${parseKeystoneIb.name}]`;
|
|
53
|
+
try {
|
|
54
|
+
if (logalot) { console.log(`${lc} starting... (I: 73cb6832984255ed48b2f44db6a21e25)`); }
|
|
55
|
+
const [
|
|
56
|
+
atom
|
|
57
|
+
] = ib.split(' ');
|
|
58
|
+
|
|
59
|
+
if (atom !== KEYSTONE_ATOM) {
|
|
60
|
+
throw new Error(`invalid keystone ib. atom found in ib (${atom}) does not match keystone atom (${KEYSTONE_ATOM}) (E: 79b3d587824c4271b6e60acc76e0c825)`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
atom,
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
68
|
+
throw error;
|
|
69
|
+
} finally {
|
|
70
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface DeterministicResult {
|
|
75
|
+
/**
|
|
76
|
+
* The Set of IDs that MUST be present in the solution.
|
|
77
|
+
* Includes Alice's Demands + Target Binding Matches + FIFO.
|
|
78
|
+
*/
|
|
79
|
+
mandatoryIds: Set<string>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The IDs remaining in the pool that are valid candidates for
|
|
83
|
+
* the Random/Stochastic step.
|
|
84
|
+
*/
|
|
85
|
+
availableIds: string[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The Policy Engine.
|
|
90
|
+
* Calculates exactly which challenges MUST be consumed based on config and demands.
|
|
91
|
+
* Enforces STRICT DISTINCTNESS (No double-dipping).
|
|
92
|
+
*/
|
|
93
|
+
export function getDeterministicRequirements({
|
|
94
|
+
pool,
|
|
95
|
+
requiredChallengeIds,
|
|
96
|
+
targetAddr
|
|
97
|
+
}: {
|
|
98
|
+
pool: KeystoneChallengePool;
|
|
99
|
+
requiredChallengeIds?: string[];
|
|
100
|
+
targetAddr?: string;
|
|
101
|
+
}): DeterministicResult {
|
|
102
|
+
const behavior = pool.config.behavior;
|
|
103
|
+
const mandatory = new Set<string>();
|
|
104
|
+
|
|
105
|
+
// Start with all available IDs.
|
|
106
|
+
// We assume Object.keys respects insertion order (ES2015+), crucial for FIFO.
|
|
107
|
+
let available = Object.keys(pool.challenges);
|
|
108
|
+
|
|
109
|
+
// ---------------------------------------------------------
|
|
110
|
+
// 1. Alice's Demands (Explicit Requirements)
|
|
111
|
+
// ---------------------------------------------------------
|
|
112
|
+
if (requiredChallengeIds && requiredChallengeIds.length > 0) {
|
|
113
|
+
for (const id of requiredChallengeIds) {
|
|
114
|
+
if (!pool.challenges[id]) {
|
|
115
|
+
throw new Error(`(UNEXPECTED) Required challenge ID not found in pool: ${id} (E: 2c9f8...)`);
|
|
116
|
+
}
|
|
117
|
+
// Strict: Consume it.
|
|
118
|
+
if (!available.includes(id)) {
|
|
119
|
+
// Should be caught by check above, but handles duplicates in 'demands'
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
mandatory.add(id);
|
|
123
|
+
}
|
|
124
|
+
// Remove from available pool
|
|
125
|
+
available = available.filter(id => !mandatory.has(id));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ---------------------------------------------------------
|
|
129
|
+
// 2. Target Binding (Explicit Buckets)
|
|
130
|
+
// ---------------------------------------------------------
|
|
131
|
+
if (behavior.targetBindingChars > 0 && targetAddr) {
|
|
132
|
+
const { gib } = getIbAndGib({ ibGibAddr: targetAddr });
|
|
133
|
+
if (gib) {
|
|
134
|
+
// Get required hex prefixes (e.g. 'a', 'b', 'c', '1')
|
|
135
|
+
const prefixes = gib.substring(0, behavior.targetBindingChars).toLowerCase();
|
|
136
|
+
|
|
137
|
+
for (const char of prefixes) {
|
|
138
|
+
// Look in the Explicit Bucket
|
|
139
|
+
const bucket = pool.bindingMap[char] || [];
|
|
140
|
+
|
|
141
|
+
// Find the first ID in this bucket that is still in 'available'
|
|
142
|
+
const match = bucket.find(id => available.includes(id));
|
|
143
|
+
|
|
144
|
+
if (!match) {
|
|
145
|
+
throw new Error(`Entropy Exhaustion. Cannot satisfy binding for char '${char}'. (E: 8d3a1...)`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Strict: Consume it.
|
|
149
|
+
mandatory.add(match);
|
|
150
|
+
available = available.filter(id => id !== match);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ---------------------------------------------------------
|
|
156
|
+
// 3. FIFO (Sequential)
|
|
157
|
+
// ---------------------------------------------------------
|
|
158
|
+
if (behavior.selectSequentially > 0) {
|
|
159
|
+
// Take the first N from the remaining available list
|
|
160
|
+
if (available.length < behavior.selectSequentially) {
|
|
161
|
+
throw new Error(`Entropy Exhaustion. Insufficient challenges for FIFO requirement. (E: 9c2b4...)`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const fifoIds = available.slice(0, behavior.selectSequentially);
|
|
165
|
+
fifoIds.forEach(id => mandatory.add(id));
|
|
166
|
+
|
|
167
|
+
// Remove from available
|
|
168
|
+
available = available.slice(behavior.selectSequentially);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return { mandatoryIds: mandatory, availableIds: available };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Helper to update the Binding Map when adding new Challenge IDs.
|
|
176
|
+
* Uses "Implicit Bucketing" (ID start char) but can be extended for full coverage.
|
|
177
|
+
*/
|
|
178
|
+
export function addToBindingMap(
|
|
179
|
+
map: { [char: string]: string[] },
|
|
180
|
+
challengeId: string
|
|
181
|
+
): void {
|
|
182
|
+
const firstChar = challengeId.charAt(0).toLowerCase();
|
|
183
|
+
// Validate it is hex
|
|
184
|
+
if (/[0-9a-f]/.test(firstChar)) {
|
|
185
|
+
if (!map[firstChar]) map[firstChar] = [];
|
|
186
|
+
map[firstChar].push(challengeId);
|
|
187
|
+
|
|
188
|
+
// OPTIONAL: Implement Full Coverage Strategy here?
|
|
189
|
+
// e.g. map[challengeId[1]].push(challengeId) ...
|
|
190
|
+
// For V1, we stick to Native/Implicit bucket (Index 0).
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Helper to clean up Binding Map when removing IDs.
|
|
196
|
+
*/
|
|
197
|
+
export function removeFromBindingMap(
|
|
198
|
+
map: { [char: string]: string[] },
|
|
199
|
+
challengeId: string
|
|
200
|
+
): void {
|
|
201
|
+
// Since we don't know exactly which buckets an ID is in (if we did multi-bucket),
|
|
202
|
+
// we strictly should scan all. For V1 Native, we check first char.
|
|
203
|
+
// SAFE IMPLEMENTATION: Scan all buckets.
|
|
204
|
+
for (const key of Object.keys(map)) {
|
|
205
|
+
map[key] = map[key].filter(id => id !== challengeId);
|
|
206
|
+
}
|
|
207
|
+
}
|