@ibgib/core-gib 0.0.26 → 0.0.28

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.
Files changed (87) hide show
  1. package/.vscode/core-gib-snippets.code-snippets +119 -13
  2. package/.vscode/settings.json +1 -0
  3. package/dist/witness/app/app-base-v1.d.mts +3 -3
  4. package/dist/witness/app/app-base-v1.d.mts.map +1 -1
  5. package/dist/witness/app/app-base-v1.mjs.map +1 -1
  6. package/dist/witness/app/app-types.d.mts +6 -6
  7. package/dist/witness/app/app-types.d.mts.map +1 -1
  8. package/dist/witness/app/app-types.mjs +1 -1
  9. package/dist/witness/app/app-types.mjs.map +1 -1
  10. package/dist/witness/keystone/keystone-base-v1.d.mts +183 -0
  11. package/dist/witness/keystone/keystone-base-v1.d.mts.map +1 -0
  12. package/dist/witness/keystone/keystone-base-v1.mjs +392 -0
  13. package/dist/witness/keystone/keystone-base-v1.mjs.map +1 -0
  14. package/dist/witness/keystone/keystone-constants.d.mts +2 -0
  15. package/dist/witness/keystone/keystone-constants.d.mts.map +1 -0
  16. package/dist/witness/keystone/keystone-constants.mjs +2 -0
  17. package/dist/witness/keystone/keystone-constants.mjs.map +1 -0
  18. package/dist/witness/keystone/keystone-helper.d.mts +9 -0
  19. package/dist/witness/keystone/keystone-helper.d.mts.map +1 -0
  20. package/dist/witness/keystone/keystone-helper.mjs +53 -0
  21. package/dist/witness/keystone/keystone-helper.mjs.map +1 -0
  22. package/dist/witness/keystone/keystone-types.d.mts +164 -0
  23. package/dist/witness/keystone/keystone-types.d.mts.map +1 -0
  24. package/dist/witness/keystone/keystone-types.mjs +46 -0
  25. package/dist/witness/keystone/keystone-types.mjs.map +1 -0
  26. package/dist/witness/keystone/keystone.d.mts +2 -0
  27. package/dist/witness/keystone/keystone.d.mts.map +1 -0
  28. package/dist/witness/keystone/keystone.mjs +2 -0
  29. package/dist/witness/keystone/keystone.mjs.map +1 -0
  30. package/dist/witness/keystone/keystone.respec.d.mts +11 -0
  31. package/dist/witness/keystone/keystone.respec.d.mts.map +1 -0
  32. package/dist/witness/keystone/keystone.respec.mjs +11 -0
  33. package/dist/witness/keystone/keystone.respec.mjs.map +1 -0
  34. package/dist/witness/keystone/math-keystone/math-keystone-constants.d.mts +2 -0
  35. package/dist/witness/keystone/math-keystone/math-keystone-constants.d.mts.map +1 -0
  36. package/dist/witness/keystone/math-keystone/math-keystone-constants.mjs +2 -0
  37. package/dist/witness/keystone/math-keystone/math-keystone-constants.mjs.map +1 -0
  38. package/dist/witness/keystone/math-keystone/math-keystone-helper.d.mts +13 -0
  39. package/dist/witness/keystone/math-keystone/math-keystone-helper.d.mts.map +1 -0
  40. package/dist/witness/keystone/math-keystone/math-keystone-helper.mjs +41 -0
  41. package/dist/witness/keystone/math-keystone/math-keystone-helper.mjs.map +1 -0
  42. package/dist/witness/keystone/math-keystone/math-keystone-types.d.mts +80 -0
  43. package/dist/witness/keystone/math-keystone/math-keystone-types.d.mts.map +1 -0
  44. package/dist/witness/keystone/math-keystone/math-keystone-types.mjs +9 -0
  45. package/dist/witness/keystone/math-keystone/math-keystone-types.mjs.map +1 -0
  46. package/dist/witness/keystone/math-keystone/math-keystone-v1.d.mts +34 -0
  47. package/dist/witness/keystone/math-keystone/math-keystone-v1.d.mts.map +1 -0
  48. package/dist/witness/keystone/math-keystone/math-keystone-v1.mjs +119 -0
  49. package/dist/witness/keystone/math-keystone/math-keystone-v1.mjs.map +1 -0
  50. package/dist/witness/keystone/math-keystone/math-keystone.respec.d.mts +20 -0
  51. package/dist/witness/keystone/math-keystone/math-keystone.respec.d.mts.map +1 -0
  52. package/dist/witness/keystone/math-keystone/math-keystone.respec.mjs +76 -0
  53. package/dist/witness/keystone/math-keystone/math-keystone.respec.mjs.map +1 -0
  54. package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.d.mts +2 -0
  55. package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.d.mts.map +1 -0
  56. package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.mjs +2 -0
  57. package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.mjs.map +1 -0
  58. package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.d.mts +2 -0
  59. package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.d.mts.map +1 -0
  60. package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.mjs +2 -0
  61. package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.mjs.map +1 -0
  62. package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.d.mts +2 -0
  63. package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.d.mts.map +1 -0
  64. package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.mjs +2 -0
  65. package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.mjs.map +1 -0
  66. package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.d.mts +2 -0
  67. package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.d.mts.map +1 -0
  68. package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.mjs +2 -0
  69. package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.mjs.map +1 -0
  70. package/package.json +1 -1
  71. package/src/witness/app/app-base-v1.mts +6 -6
  72. package/src/witness/app/app-types.mts +11 -8
  73. package/src/witness/keystone/keystone-base-v1.mts +450 -0
  74. package/src/witness/keystone/keystone-constants.mts +0 -0
  75. package/src/witness/keystone/keystone-helper.mts +56 -0
  76. package/src/witness/keystone/keystone-types.mts +200 -0
  77. package/src/witness/keystone/keystone.mts +0 -0
  78. package/src/witness/keystone/keystone.respec.mts +9 -0
  79. package/src/witness/keystone/math-keystone/math-keystone-constants.mts +0 -0
  80. package/src/witness/keystone/math-keystone/math-keystone-helper.mts +47 -0
  81. package/src/witness/keystone/math-keystone/math-keystone-types.mts +115 -0
  82. package/src/witness/keystone/math-keystone/math-keystone-v1.mts +139 -0
  83. package/src/witness/keystone/math-keystone/math-keystone.respec.mts +123 -0
  84. package/src/witness/keystone/zkp-keystone/zkp-keystone-constants.mts +0 -0
  85. package/src/witness/keystone/zkp-keystone/zkp-keystone-helper.mts +0 -0
  86. package/src/witness/keystone/zkp-keystone/zkp-keystone-types.mts +0 -0
  87. package/src/witness/keystone/zkp-keystone/zkp-keystone-v1.mts +0 -0
@@ -0,0 +1,200 @@
1
+ /**
2
+ * @module keystone-types
3
+ */
4
+
5
+ import { IbGibData_V1, IbGibRel8ns_V1, IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
6
+ import { IbGib, IbGibAddr, TransformResult } from '@ibgib/ts-gib/dist/types.mjs';
7
+
8
+ import { WitnessWithContextData_V1, WitnessWithContextRel8ns_V1 } from '../witness-with-context/witness-with-context-types.mjs';
9
+ import { WitnessCmdData, WitnessCmdIbGib, WitnessCmdRel8ns } from '../witness-cmd/witness-cmd-types.mjs';
10
+ import { WitnessResultData, WitnessResultIbGib, WitnessResultRel8ns } from '../witness-types.mjs';
11
+ // import { IbGibSpaceOptionsData } from '@ibgib/core-gib/dist/witness/space/space-types.mjs';
12
+
13
+ import { GLOBAL_LOG_A_LOT } from '../../core-constants.mjs';
14
+ import { IbGibSpaceAny } from '../space/space-base-v1.mjs';
15
+ import { MetaspaceService } from '../space/metaspace/metaspace-types.mjs';
16
+ import { IbGibKeystoneAny } from './keystone-base-v1.mjs';
17
+ /**
18
+ * use for verbose logging.
19
+ */
20
+ const logalot = GLOBAL_LOG_A_LOT;
21
+
22
+ export type KeystoneScope = "any" | "transform";
23
+ export type KeystoneSubScope = "any" | "";
24
+
25
+ export type ExpirationFormat = "UTC";
26
+
27
+ export interface KeystoneData_V1<TChallenges, TSolutions> extends WitnessWithContextData_V1 {
28
+ /**
29
+ * @optional setting, which if set, this keystone has internal knowledge of
30
+ * its use.
31
+ */
32
+ scope?: string;
33
+ /**
34
+ *
35
+ */
36
+ tjpGib?: string;
37
+ /**
38
+ * @optional formatting of expiration timestamp
39
+ */
40
+ expirationFormat?: ExpirationFormat,
41
+ /**
42
+ * @optional timestamp at which time the keystone will be invalid.
43
+ */
44
+ expiration?: string;
45
+ /**
46
+ * If truthy, then there is a limited number of uses that the keystone can
47
+ * be utilized (challenged/mutated).
48
+ *
49
+ * # intent
50
+ *
51
+ * temporary keystones could be used for finite, pre-known numbers of
52
+ * "transactions".
53
+ */
54
+ remainingUses?: number;
55
+ /**
56
+ * atom corresponding to the type of challenge.
57
+ *
58
+ * @example 'zkp'
59
+ * @example 'math'
60
+ * @example 'honor'
61
+ */
62
+ challengeAtom: string;
63
+ challenges: TChallenges;
64
+ solutions: TSolutions;
65
+ }
66
+
67
+ export interface KeystoneRel8ns_V1 extends WitnessWithContextRel8ns_V1 {
68
+ }
69
+
70
+ /**
71
+ * Base of the ibgib data for any keystone.
72
+ *
73
+ * concrete implementations of keystones should add customized data.
74
+ */
75
+ export interface KeystoneIbGib_V1<KeystoneData_V1 extends IbGibData_V1, KeystoneRel8ns_V1 extends IbGibRel8ns_V1>
76
+ extends IbGib_V1<KeystoneData_V1, KeystoneRel8ns_V1> {
77
+
78
+ }
79
+
80
+ /**
81
+ * Cmds for interacting with ibgib spaces.
82
+ *
83
+ * Not all of these will be implemented for every space.
84
+ *
85
+ * ## todo
86
+ *
87
+ * change these commands to better structure, e.g., verb/do/mod, can/get/addrs
88
+ * */
89
+ export type KeystoneCmd =
90
+ 'challenge' | 'revoke';
91
+ /** Cmds for interacting with ibgib spaces. */
92
+ export const KeystoneCmd = {
93
+ /**
94
+ * it's more like a grunt that is intepreted by context from the robbot.
95
+ *
96
+ * my initial use of this will be to extend a keystone.
97
+ */
98
+ ib: 'ib' as KeystoneCmd,
99
+ /**
100
+ * it's more like a grunt that is intepreted by context from the robbot.
101
+ *
102
+ * my initial use of this will be to validate a keystone.
103
+ */
104
+ gib: 'gib' as KeystoneCmd,
105
+ /**
106
+ * third placeholder command.
107
+ *
108
+ * my initial use of this will be to finalize a keystone.
109
+ */
110
+ ibgib: 'ibgib' as KeystoneCmd,
111
+ }
112
+
113
+ /*o
114
+ * Flags to affect the command's interpretation.
115
+ */
116
+ export type KeystoneCmdModifier =
117
+ 'final';
118
+ /**
119
+ * Flags to affect the command's interpretation.
120
+ */
121
+ export const KeystoneCmdModifier = {
122
+ /**
123
+ * If final, then the cmd will be the last of the stone.
124
+ *
125
+ * ## notes
126
+ *
127
+ * I think this may just signal the beginning of the end, there may actually
128
+ * technically be more commands executed by the witness. but they would be
129
+ * cleanup commands. the point is that after this option
130
+ */
131
+ final: 'final' as KeystoneCmdModifier,
132
+ }
133
+
134
+ /**
135
+ * Information commonly required for keystones.
136
+ */
137
+ export interface KeystoneOptionsData extends WitnessCmdData<KeystoneCmd, KeystoneCmdModifier> {
138
+ spaceId?: string;
139
+ spaceAddr?: string;
140
+ }
141
+
142
+ export interface KeystoneOptionsRel8ns extends WitnessCmdRel8ns {
143
+ }
144
+
145
+ export interface KeystoneOptionsIbGib<
146
+ TIbGib extends IbGib = IbGib_V1,
147
+ TOptsData extends KeystoneOptionsData = KeystoneOptionsData,
148
+ TOptsRel8ns extends KeystoneOptionsRel8ns = KeystoneOptionsRel8ns,
149
+ > extends WitnessCmdIbGib<TIbGib, KeystoneCmd, KeystoneCmdModifier, TOptsData, TOptsRel8ns> {
150
+ space: IbGibSpaceAny;
151
+ metaspace: MetaspaceService;
152
+ }
153
+
154
+ /**
155
+ * Optional shape of result data to witness interactions.
156
+ *
157
+ * This is in addition of course to {@link WitnessResultData}.
158
+ *
159
+ * ## notes
160
+ *
161
+ * * I'm not sure what to do with this atm, so I'm just stubbing out...
162
+ */
163
+ export interface KeystoneResultData extends WitnessResultData {
164
+ /**
165
+ * redeclared from {@link WitnessResultData} for explicit focus. (i.e. not
166
+ * really necessary but it makes it more obvious that this is used.)
167
+ *
168
+ * ## when extending keystone
169
+ *
170
+ * new addrs added to the keystone dependency graph will be here.
171
+ */
172
+ addrs?: IbGibAddr[];
173
+ }
174
+
175
+ /**
176
+ * Marker interface rel8ns atm...
177
+ *
178
+ * I'm not sure what to do with this atm, so I'm just stubbing out...
179
+ */
180
+ export interface KeystoneResultRel8ns extends WitnessResultRel8ns { }
181
+
182
+ /**
183
+ * Shape of result ibgib if used for a robbot.
184
+ *
185
+ * I'm not sure what to do with this atm, so I'm just stubbing out...
186
+ */
187
+ export interface KeystoneResultIbGib<
188
+ TIbGib extends IbGib_V1,
189
+ TResultData extends KeystoneResultData,
190
+ TResultRel8ns extends KeystoneResultRel8ns
191
+ >
192
+ extends WitnessResultIbGib<TIbGib, TResultData, TResultRel8ns> {
193
+ /**
194
+ * In addition to the {@link WitnessResultIbGib} `ibGibs` property, this is
195
+ * provided for convenience which should differentiate between the most
196
+ * recent (newly created) keystone ibgib and the intermediate ibgibs created
197
+ * (e.g. dna).
198
+ */
199
+ resTransform: TransformResult<IbGibKeystoneAny>;
200
+ }
File without changes
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module keystone.respec.mts
3
+ *
4
+ * @see {@link './math-keystone/math-keystone.respec.mts'}
5
+ *
6
+ * In order to test the keystone at the base class, you have to create a mock.
7
+ * I've gone ahead and made a simplistic keystone at ./math-keystone which acts
8
+ * as this base keystone test.
9
+ */
@@ -0,0 +1,47 @@
1
+ import { pickRandom } from "@ibgib/helper-gib";
2
+
3
+ import {
4
+ MathChallengeInfo, MathChallengeType, MathChallengeInfo_Add
5
+ } from "./math-keystone-types.mjs";
6
+
7
+ import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
8
+ /**
9
+ * use for verbose logging.
10
+ */
11
+ const logalot = GLOBAL_LOG_A_LOT;
12
+
13
+ /**
14
+ * creates a new simple math challenge. only does 'add' atow.
15
+ *
16
+ * @returns math challenge info
17
+ */
18
+ export async function getMathChallenge({
19
+ challengeType,
20
+ }: {
21
+ /**
22
+ * If provided, will create this type of challenge.
23
+ */
24
+ challengeType?: MathChallengeType,
25
+ }): Promise<MathChallengeInfo> {
26
+ const lc = `[${getMathChallenge.name}]`;
27
+ try {
28
+ if (logalot) { console.log(`${lc} starting... (I: 75a805603968ca8a4b076caa2cf9bd23)`); }
29
+ if (challengeType && challengeType !== 'add') { throw new Error(`only 'add' implemented atow (E: 1e5bc2395395b8d48d61135b63a77923)`); }
30
+
31
+ // add
32
+ const x = Math.ceil(Math.random() * 999999);
33
+ const y = Math.ceil(Math.random() * 999999);
34
+ const challenge: MathChallengeInfo_Add = {
35
+ id: 'hmm',
36
+ op: 'add',
37
+ a: x,
38
+ b: y,
39
+ }
40
+ return challenge;
41
+ } catch (error) {
42
+ console.error(`${lc} ${error.message}`);
43
+ throw error;
44
+ } finally {
45
+ if (logalot) { console.log(`${lc} complete.`); }
46
+ }
47
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @module math-keystone-types
3
+ */
4
+
5
+ import { IbGibData_V1, IbGibRel8ns_V1, IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
6
+ import { IbGib } from '@ibgib/ts-gib/dist/types.mjs';
7
+
8
+ import {
9
+ KeystoneData_V1, KeystoneRel8ns_V1,
10
+ KeystoneOptionsData, KeystoneOptionsRel8ns, KeystoneOptionsIbGib,
11
+ KeystoneResultData, KeystoneResultRel8ns, KeystoneResultIbGib,
12
+ } from '../keystone-types.mjs';
13
+
14
+
15
+ import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
16
+ /**
17
+ * use for verbose logging.
18
+ */
19
+ const logalot = GLOBAL_LOG_A_LOT;
20
+
21
+ export interface MathKeystoneData_V1 extends KeystoneData_V1<MathChallengeInfo[], MathSolutionInfo[]> {
22
+ challengeAtom: 'math';
23
+ }
24
+
25
+ export interface MathKeystoneRel8ns_V1 extends KeystoneRel8ns_V1 {
26
+ }
27
+
28
+ /**
29
+ * needed? yagni?
30
+ */
31
+ export interface MathKeystoneAddlMetadata {
32
+ // atom: string;
33
+ // classnameIsh: string;
34
+ // nameIsh: string;
35
+ // idIsh: string;
36
+ }
37
+
38
+ /**
39
+ * keystone for math problem challenges.
40
+ *
41
+ * I'm using this largely as a test implementation, which both gives me a chance
42
+ * to futz around and learn, as well as help corroborate that unit tests are
43
+ * properly scoped.
44
+ */
45
+ export interface MathKeystoneIbGib_V1<MathKeystoneData_V1 extends IbGibData_V1, MathKeystoneRel8ns_V1 extends IbGibRel8ns_V1>
46
+ extends IbGib_V1<MathKeystoneData_V1, MathKeystoneRel8ns_V1> {
47
+
48
+ }
49
+
50
+ export interface MathKeystoneOptionsData extends KeystoneOptionsData {
51
+ }
52
+
53
+ export interface MathKeystoneOptionsRel8ns extends KeystoneOptionsRel8ns {
54
+ }
55
+
56
+ export interface MathKeystoneOptionsIbGib extends KeystoneOptionsIbGib {
57
+ }
58
+
59
+ /**
60
+ * @see {@link WitnessResultData}
61
+ */
62
+ export interface MathKeystoneResultData extends KeystoneResultData {
63
+ }
64
+
65
+ /**
66
+ */
67
+ export interface MathKeystoneResultRel8ns extends KeystoneResultRel8ns { }
68
+
69
+ /**
70
+ * Shape of result ibgib if used for a robbot.
71
+ *
72
+ * I'm not sure what to do with this atm, so I'm just stubbing out...
73
+ */
74
+ export interface MathKeystoneResultIbGib
75
+ extends KeystoneResultIbGib<IbGib_V1, MathKeystoneResultData, MathKeystoneResultRel8ns> {
76
+ }
77
+
78
+ export type MathChallengeOperation = 'add' | 'subtract';
79
+
80
+ /**
81
+ * info about our (simple atow) math challenge.
82
+ */
83
+ export interface MathChallengeInfo {
84
+ /**
85
+ * operation to be performed on number's `a` and `b`.
86
+ */
87
+ op: MathChallengeOperation;
88
+ /**
89
+ * id of the challenge
90
+ */
91
+ id: string;
92
+ /**
93
+ * left hand side of math challenge expression.
94
+ */
95
+ a: number;
96
+ /**
97
+ * right hande side of math challenge expression.
98
+ */
99
+ b: number;
100
+ }
101
+
102
+ export interface MathChallengeInfo_Add extends MathChallengeInfo {
103
+ }
104
+
105
+ /**
106
+ * info about our (simple atow) math challenge's solution.
107
+ */
108
+ export interface MathSolutionInfo {
109
+ challengeId: string;
110
+ solution: number;
111
+ }
112
+
113
+ export interface MathChallengeType {
114
+
115
+ }
@@ -0,0 +1,139 @@
1
+ import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
2
+ import { WitnessWithContextBase_V1 } from "../../witness-with-context/witness-with-context-base-v1.mjs";
3
+ import {
4
+ MathKeystoneOptionsData, MathKeystoneOptionsIbGib, MathKeystoneOptionsRel8ns,
5
+ MathKeystoneResultData, MathKeystoneResultIbGib, MathKeystoneResultRel8ns,
6
+ MathKeystoneData_V1, MathKeystoneRel8ns_V1, MathKeystoneIbGib_V1,
7
+ MathKeystoneAddlMetadata,
8
+ MathChallengeInfo, MathSolutionInfo,
9
+ } from "./math-keystone-types.mjs";
10
+ import { KeystoneBase_V1 } from "../keystone-base-v1.mjs";
11
+
12
+ import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
13
+ const logalot = GLOBAL_LOG_A_LOT;
14
+
15
+ /**
16
+ * witness for keystones that have math problems as the challenges.
17
+ *
18
+ * @see {@link MathKeystoneIbGib_V1}
19
+ */
20
+ export class MathKeystoneWitness_V1 extends KeystoneBase_V1<
21
+ MathChallengeInfo[], MathSolutionInfo[],
22
+ MathKeystoneOptionsData, MathKeystoneOptionsRel8ns, MathKeystoneOptionsIbGib,
23
+ MathKeystoneResultData, MathKeystoneResultRel8ns, MathKeystoneResultIbGib,
24
+ MathKeystoneData_V1, MathKeystoneRel8ns_V1> {
25
+
26
+ protected parseAddlMetadataString<TParseResult>({ ib }: { ib: string; }): TParseResult {
27
+ // const addlMetadataText = `${atom}_${classnameIsh}_${nameIsh}_${idIsh}`;
28
+ if (!ib) { throw new Error(`ib required (E: f3883d3ce90c4c15907dffa1c46e77d6)`); }
29
+ const lc = `[${this.parseAddlMetadataString.name}]`;
30
+ try {
31
+ const [atom, classnameIsh, nameIsh, idIsh] = ib.split('_');
32
+ const result = { atom, classnameIsh, nameIsh, idIsh, } as MathKeystoneAddlMetadata;
33
+ return result as TParseResult; // i'm not liking the TParseResult...hmm
34
+ } catch (error) {
35
+ console.error(`${lc} ${error.message}`);
36
+ throw error;
37
+ }
38
+ }
39
+
40
+ /**
41
+ * this is the primary command handler when extending a keystone, i.e. when
42
+ * signing some payload.
43
+ */
44
+ protected async extend({
45
+ arg,
46
+ }: {
47
+ arg: MathKeystoneOptionsIbGib,
48
+ }): Promise<MathKeystoneResultIbGib> {
49
+ const lc = `${this.lc}[${this.extend.name}]`;
50
+ try {
51
+ if (logalot) { console.log(`${lc} starting...`); }
52
+ // 1 .look at the specs for the keystone
53
+ // 2. determine requirements for keystone extension
54
+ // * for now, this is just the default (i.e. we skip these steps)
55
+
56
+ let nextChallenges: MathChallengeInfo[] = await this.getNextChallenges({ arg });
57
+ // get the next challenges to solve
58
+ // prompt user (if required) solve challenges
59
+ let nextSolutions: MathSolutionInfo[] = await this.getNextSolutions({ arg, nextChallenges });
60
+
61
+ throw new Error(`not impl (E: 470834fb2562dd33b49b8ec6c9be9423)`);
62
+
63
+ // validate nextSolutions
64
+ // await this.validateNextSolutions({ arg, nextChallenges, nextSolutions });
65
+
66
+ // perform keystone graph extension
67
+ // now that we have solutions
68
+
69
+ } catch (error) {
70
+ console.error(`${lc} ${error.message}`);
71
+ throw error;
72
+ } finally {
73
+ if (logalot) { console.log(`${lc} complete.`); }
74
+ }
75
+ }
76
+
77
+ /**
78
+ * chooses the next challenge infos in order to extend the keystone
79
+ * timeline.
80
+ */
81
+ async getNextChallenges({
82
+ arg,
83
+ }: {
84
+ arg: MathKeystoneOptionsIbGib,
85
+ }): Promise<MathChallengeInfo[]> {
86
+ const lc = `${this.lc}[${this.getNextChallenges.name}]`;
87
+ try {
88
+
89
+ if (logalot) { console.log(`${lc} starting... (I: e5cf6a884a093eddc1f297b2a63dd123)`); }
90
+ throw new Error(`not impl (E: 602bdd6bfa38db5acbd798e60c861623)`);
91
+
92
+ } catch (error) {
93
+ console.error(`${lc} ${error.message}`);
94
+ throw error;
95
+ } finally {
96
+ if (logalot) { console.log(`${lc} complete.`); }
97
+ }
98
+ }
99
+
100
+ async getNextSolutions({
101
+ arg,
102
+ nextChallenges,
103
+ }: {
104
+ arg: MathKeystoneOptionsIbGib,
105
+ nextChallenges: MathChallengeInfo[],
106
+ }): Promise<MathSolutionInfo[]> {
107
+ const lc = `${this.lc}[${this.getNextSolutions.name}]`;
108
+ try {
109
+ if (logalot) { console.log(`${lc} starting... (I: f77696f021a32ec474de3ebc2c7d7823)`); }
110
+
111
+ throw new Error(`not impl (E: d727a9e378da4ddcb90d0be3a995daeb)`);
112
+ } catch (error) {
113
+ console.error(`${lc} ${error.message}`);
114
+ throw error;
115
+ } finally {
116
+ if (logalot) { console.log(`${lc} complete.`); }
117
+ }
118
+ }
119
+
120
+ async validateNextSolutions({
121
+ arg,
122
+ }: {
123
+ arg: MathKeystoneOptionsIbGib,
124
+ }): Promise<string[]> {
125
+ const lc = `${this.lc}[${this.validateNextSolutions.name}]`;
126
+ let errors: string[] = [];
127
+ try {
128
+ if (logalot) { console.log(`${lc} starting... (I: 49fda11783ede527b64bf20e8a9feb23)`); }
129
+
130
+ throw new Error(`not impl (E: 5407f3d0b3d9729ee361a64cd411ea23)`);
131
+
132
+ } catch (error) {
133
+ console.error(`${lc} ${error.message}`);
134
+ throw error;
135
+ } finally {
136
+ if (logalot) { console.log(`${lc} complete.`); }
137
+ }
138
+ }
139
+ }
@@ -0,0 +1,123 @@
1
+ import * as pathUtils from 'path';
2
+
3
+ import {
4
+ firstOfAll, firstOfEach, ifWe, ifWeMight, iReckon,
5
+ lastOfAll, lastOfEach, respecfully, respecfullyDear,
6
+ } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
7
+ const maam = `[${import.meta.url}]`, sir = maam;
8
+
9
+ import { delay, extractErrorMsg, getTimestampInTicks, getUUID } from '@ibgib/helper-gib';
10
+ import { Gib } from '@ibgib/ts-gib/dist/types.mjs';
11
+ import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
12
+
13
+ import { KeystoneData_V1, KeystoneIbGib_V1, KeystoneRel8ns_V1 } from '../keystone-types.mjs';
14
+ import { IbGibKeystoneAny } from '../keystone-base-v1.mjs';
15
+
16
+ import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
17
+ import { WitnessWithContextBase_V1 } from '../../witness-with-context/witness-with-context-base-v1.mjs';
18
+
19
+ const logalot: boolean | number = GLOBAL_LOG_A_LOT || true;
20
+
21
+ const lcFile: string = `[${pathUtils.basename(import.meta.url)}]`;
22
+
23
+ // #region math mock/test helper functions/types
24
+
25
+ interface MathKeystoneData_V1 extends KeystoneData_V1<any, any> { }
26
+ interface MathKeystoneRel8ns_V1 extends KeystoneRel8ns_V1 { }
27
+ /**
28
+ * this keystone has math problems as its challenges
29
+ */
30
+ interface MathKeystoneIbGib_V1 extends KeystoneIbGib_V1<MathKeystoneData_V1, MathKeystoneRel8ns_V1> {
31
+ }
32
+ type MathType = "arithmetic";
33
+ interface MathKeystoneAddlMetadata {
34
+ atom: 'keystone_math';
35
+ mathType: MathType;
36
+ tjpGib: Gib;
37
+ }
38
+ export async function createKeystone(): Promise<IbGibKeystoneAny> {
39
+ const lc = `[${createKeystone.name}]`;
40
+ try {
41
+ if (logalot) { console.log(`${lc} starting... (I: ba9c092ad0b19a7fd1c5d98fb27b5923)`); }
42
+
43
+ throw new Error(`not impl (E: db37bc8b249841397316812a006bc223)`);
44
+
45
+ } catch (error) {
46
+ console.error(`${lc} ${error.message}`);
47
+ throw error;
48
+ } finally {
49
+ if (logalot) { console.log(`${lc} complete.`); }
50
+ }
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @returns validation error if any, else returns null
56
+ */
57
+ export async function validateKeystone({
58
+ keystoneLatest,
59
+ }: {
60
+ /**
61
+ * the latest (i.e. "head") keystone in the keystone's timeline.
62
+ */
63
+ keystoneLatest?: IbGibKeystoneAny,
64
+ /**
65
+ * keystones are a graph, and the idea is
66
+ */
67
+ dependencyGraph?: { [addr: string]: IbGib_V1 },
68
+ }): Promise<string[] | null> {
69
+ const lc = `[${validateKeystone.name}]`;
70
+ try {
71
+ throw new Error(`not imple yet (E: 2a80e8b2e6934b10a27df67395402c29)`);
72
+ } catch (error) {
73
+ console.error(`${lc} ${error.message}`);
74
+ throw error;
75
+ }
76
+ }
77
+
78
+ // #endregion math mock/test helper functions/types
79
+
80
+ /**
81
+ * witness for keystones that have math problems as the challenges.
82
+ */
83
+ class MathKeystoneWitness_V1
84
+ extends WitnessWithContextBase_V1<
85
+ any, any, any, // options
86
+ any, any, any, // result
87
+ MathKeystoneData_V1, MathKeystoneRel8ns_V1> {
88
+
89
+ protected parseAddlMetadataString<TParseResult>({ ib }: { ib: string; }): TParseResult {
90
+ // const addlMetadataText = `${atom}_${classnameIsh}_${nameIsh}_${idIsh}`;
91
+ if (!ib) { throw new Error(`ib required (E: f3883d3ce90c4c15907dffa1c46e77d6)`); }
92
+ const lc = `[${this.parseAddlMetadataString.name}]`;
93
+ try {
94
+ const [atom, classnameIsh, nameIsh, idIsh] = ib.split('_');
95
+ const result = { atom, classnameIsh, nameIsh, idIsh, } as unknown as MathKeystoneAddlMetadata;
96
+ return result as TParseResult; // i'm not liking the TParseResult...hmm
97
+ } catch (error) {
98
+ console.error(`${lc} ${error.message}`);
99
+ throw error;
100
+ }
101
+ }
102
+ protected witnessImpl(arg: any): Promise<any> {
103
+ throw new Error('Method not implemented.');
104
+ }
105
+
106
+ }
107
+
108
+ await respecfully(maam, lcFile, async () => {
109
+ let lc = lcFile.concat();
110
+
111
+ await respecfully(maam, `simple keystones (not composite)`, async () => {
112
+
113
+ await ifWe(maam, `createKeystone`, async () => {
114
+
115
+ });
116
+ await ifWe(maam, `validateKeystone`, async () => { });
117
+ await ifWe(maam, `iterateKeystone`, async () => { });
118
+ await ifWe(maam, `createKeystoneChallenge`, async () => { });
119
+ await ifWe(maam, `createKeystoneChallenge`, async () => { });
120
+
121
+ });
122
+
123
+ }, { logalot: !!logalot });