@ibgib/core-gib 0.1.3 → 0.1.4
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/witness/space/inner-space/inner-space-v1.respec.mjs +4 -5
- package/dist/witness/space/inner-space/inner-space-v1.respec.mjs.map +1 -1
- package/package.json +4 -4
- package/src/witness/space/inner-space/inner-space-v1.respec.mts +4 -6
- package/dist/witness/keystone/keystone-base-v1.d.mts +0 -177
- package/dist/witness/keystone/keystone-base-v1.d.mts.map +0 -1
- package/dist/witness/keystone/keystone-base-v1.mjs +0 -397
- package/dist/witness/keystone/keystone-base-v1.mjs.map +0 -1
- package/dist/witness/keystone/keystone-constants.d.mts +0 -2
- package/dist/witness/keystone/keystone-constants.d.mts.map +0 -1
- package/dist/witness/keystone/keystone-constants.mjs +0 -2
- package/dist/witness/keystone/keystone-constants.mjs.map +0 -1
- package/dist/witness/keystone/keystone-helper.d.mts +0 -9
- package/dist/witness/keystone/keystone-helper.d.mts.map +0 -1
- package/dist/witness/keystone/keystone-helper.mjs +0 -53
- package/dist/witness/keystone/keystone-helper.mjs.map +0 -1
- package/dist/witness/keystone/keystone-types.d.mts +0 -164
- package/dist/witness/keystone/keystone-types.d.mts.map +0 -1
- package/dist/witness/keystone/keystone-types.mjs +0 -46
- package/dist/witness/keystone/keystone-types.mjs.map +0 -1
- package/dist/witness/keystone/keystone.d.mts +0 -2
- package/dist/witness/keystone/keystone.d.mts.map +0 -1
- package/dist/witness/keystone/keystone.mjs +0 -2
- package/dist/witness/keystone/keystone.mjs.map +0 -1
- package/dist/witness/keystone/keystone.respec.d.mts +0 -11
- package/dist/witness/keystone/keystone.respec.d.mts.map +0 -1
- package/dist/witness/keystone/keystone.respec.mjs +0 -11
- package/dist/witness/keystone/keystone.respec.mjs.map +0 -1
- package/dist/witness/keystone/math-keystone/math-keystone-constants.d.mts +0 -2
- package/dist/witness/keystone/math-keystone/math-keystone-constants.d.mts.map +0 -1
- package/dist/witness/keystone/math-keystone/math-keystone-constants.mjs +0 -2
- package/dist/witness/keystone/math-keystone/math-keystone-constants.mjs.map +0 -1
- package/dist/witness/keystone/math-keystone/math-keystone-helper.d.mts +0 -13
- package/dist/witness/keystone/math-keystone/math-keystone-helper.d.mts.map +0 -1
- package/dist/witness/keystone/math-keystone/math-keystone-helper.mjs +0 -41
- package/dist/witness/keystone/math-keystone/math-keystone-helper.mjs.map +0 -1
- package/dist/witness/keystone/math-keystone/math-keystone-types.d.mts +0 -80
- package/dist/witness/keystone/math-keystone/math-keystone-types.d.mts.map +0 -1
- package/dist/witness/keystone/math-keystone/math-keystone-types.mjs +0 -9
- package/dist/witness/keystone/math-keystone/math-keystone-types.mjs.map +0 -1
- package/dist/witness/keystone/math-keystone/math-keystone-v1.d.mts +0 -34
- package/dist/witness/keystone/math-keystone/math-keystone-v1.d.mts.map +0 -1
- package/dist/witness/keystone/math-keystone/math-keystone-v1.mjs +0 -119
- package/dist/witness/keystone/math-keystone/math-keystone-v1.mjs.map +0 -1
- package/dist/witness/keystone/math-keystone/math-keystone.respec.d.mts +0 -20
- package/dist/witness/keystone/math-keystone/math-keystone.respec.d.mts.map +0 -1
- package/dist/witness/keystone/math-keystone/math-keystone.respec.mjs +0 -76
- package/dist/witness/keystone/math-keystone/math-keystone.respec.mjs.map +0 -1
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.d.mts +0 -2
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.d.mts.map +0 -1
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.mjs +0 -2
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.mjs.map +0 -1
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.d.mts +0 -2
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.d.mts.map +0 -1
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.mjs +0 -2
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.mjs.map +0 -1
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.d.mts +0 -2
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.d.mts.map +0 -1
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.mjs +0 -2
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.mjs.map +0 -1
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.d.mts +0 -2
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.d.mts.map +0 -1
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.mjs +0 -2
- package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.mjs.map +0 -1
- package/src/witness/keystone/keystone-base-v1.mts +0 -450
- package/src/witness/keystone/keystone-constants.mts +0 -0
- package/src/witness/keystone/keystone-helper.mts +0 -56
- package/src/witness/keystone/keystone-types.mts +0 -200
- package/src/witness/keystone/keystone.mts +0 -0
- package/src/witness/keystone/keystone.respec.mts +0 -9
- package/src/witness/keystone/math-keystone/math-keystone-constants.mts +0 -0
- package/src/witness/keystone/math-keystone/math-keystone-helper.mts +0 -45
- package/src/witness/keystone/math-keystone/math-keystone-types.mts +0 -115
- package/src/witness/keystone/math-keystone/math-keystone-v1.mts +0 -139
- package/src/witness/keystone/math-keystone/math-keystone.respec.mts +0 -122
- package/src/witness/keystone/zkp-keystone/zkp-keystone-constants.mts +0 -0
- package/src/witness/keystone/zkp-keystone/zkp-keystone-helper.mts +0 -0
- package/src/witness/keystone/zkp-keystone/zkp-keystone-types.mts +0 -0
- package/src/witness/keystone/zkp-keystone/zkp-keystone-v1.mts +0 -0
|
@@ -1,450 +0,0 @@
|
|
|
1
|
-
import { IbGib_V1, IbGibRel8ns_V1, } from '@ibgib/ts-gib/dist/V1/index.mjs';
|
|
2
|
-
|
|
3
|
-
import { argy_, isArg, isCommand, resulty_ } from '../witness-helper.mjs';
|
|
4
|
-
import { MetaspaceService } from '../space/metaspace/metaspace-types.mjs';
|
|
5
|
-
import { WitnessWithContextBase_V1 } from '../witness-with-context/witness-with-context-base-v1.mjs';
|
|
6
|
-
import { ErrorIbGib_V1 } from '../../common/error/error-types.mjs';
|
|
7
|
-
import { getErrorIbGib } from '../../common/error/error-helper.mjs';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
KeystoneData_V1, KeystoneRel8ns_V1, KeystoneIbGib_V1,
|
|
11
|
-
KeystoneOptionsIbGib, KeystoneOptionsData, KeystoneOptionsRel8ns,
|
|
12
|
-
KeystoneResultIbGib, KeystoneResultData, KeystoneResultRel8ns,
|
|
13
|
-
KeystoneCmd, KeystoneCmdModifier,
|
|
14
|
-
// KeystoneCmd,
|
|
15
|
-
// KeystoneCmdData, KeystoneCmdRel8ns, KeystoneCmdIbGib,
|
|
16
|
-
// KeystoneResultData, KeystoneResultRel8ns, KeystoneResultIbGib,
|
|
17
|
-
} from './keystone-types.mjs';
|
|
18
|
-
import { validateCommonKeystoneData } from './keystone-helper.mjs';
|
|
19
|
-
|
|
20
|
-
import { PicIbGib_V1 } from '../../common/pic/pic-types.mjs';
|
|
21
|
-
import { CommentIbGib_V1 } from '../../common/comment/comment-types.mjs';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import { GLOBAL_LOG_A_LOT } from '../../core-constants.mjs';
|
|
25
|
-
const logalot = GLOBAL_LOG_A_LOT;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Keystone is the last major piece of the ibgib architecture. This is used to
|
|
29
|
-
* implement distributed identity that gets added on-chain alongside other data
|
|
30
|
-
* and metadata, instead of only relying solely upon asymmetric crypto for e.g.
|
|
31
|
-
* signatures.
|
|
32
|
-
*
|
|
33
|
-
* Override this class with specific concrete implementations of keystones,
|
|
34
|
-
* which atow I believe will differ mainly in their specific challenge
|
|
35
|
-
* implementations.
|
|
36
|
-
*
|
|
37
|
-
* ## notes
|
|
38
|
-
*
|
|
39
|
-
* ### composite keystones
|
|
40
|
-
*
|
|
41
|
-
* At first I was thinking I was going to make keystones composite (super
|
|
42
|
-
* keystones with rel8ns pointing to other keystones), but at least to start
|
|
43
|
-
* with, I will have a specific concrete implementation class that covers
|
|
44
|
-
* multiple keystone composition.
|
|
45
|
-
*/
|
|
46
|
-
export abstract class KeystoneBase_V1<
|
|
47
|
-
TChallenges, TSolutions,
|
|
48
|
-
TOptionsData extends KeystoneOptionsData,
|
|
49
|
-
TOptionsRel8ns extends KeystoneOptionsRel8ns,
|
|
50
|
-
TOptionsIbGib extends KeystoneOptionsIbGib<IbGib_V1, TOptionsData, TOptionsRel8ns>,
|
|
51
|
-
TResultData extends KeystoneResultData,
|
|
52
|
-
TResultRel8ns extends KeystoneResultRel8ns,
|
|
53
|
-
TResultIbGib extends KeystoneResultIbGib<IbGib_V1, TResultData, TResultRel8ns> | ErrorIbGib_V1,
|
|
54
|
-
TData extends KeystoneData_V1<TChallenges, TSolutions>,
|
|
55
|
-
TRel8ns extends KeystoneRel8ns_V1,
|
|
56
|
-
>
|
|
57
|
-
extends WitnessWithContextBase_V1<
|
|
58
|
-
TOptionsData, TOptionsRel8ns, TOptionsIbGib,
|
|
59
|
-
TResultData, TResultRel8ns, TResultIbGib,
|
|
60
|
-
TData, TRel8ns>
|
|
61
|
-
implements KeystoneIbGib_V1<TData, TRel8ns> {
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Log context for convenience with logging. (Ignore if you don't want to use this.)
|
|
65
|
-
*/
|
|
66
|
-
protected lc: string = `[${KeystoneBase_V1.name}]`;
|
|
67
|
-
|
|
68
|
-
// /**
|
|
69
|
-
// * Reference to the local ibgibs service, which is one way at getting at the
|
|
70
|
-
// * local user space.
|
|
71
|
-
// */
|
|
72
|
-
// metaspace: MetaspaceService | undefined;
|
|
73
|
-
|
|
74
|
-
constructor(initialData?: TData, initialRel8ns?: TRel8ns) {
|
|
75
|
-
super(initialData, initialRel8ns);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* At this point in time, the arg has already been intrinsically validated,
|
|
80
|
-
* as well as the internal state of this keystone.
|
|
81
|
-
*/
|
|
82
|
-
protected async witnessImpl(arg: TOptionsIbGib): Promise<TResultIbGib | undefined> {
|
|
83
|
-
const lc = `${this.lc}[${this.witnessImpl.name}]`;
|
|
84
|
-
try {
|
|
85
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
86
|
-
|
|
87
|
-
await this.loadNewerSelfIfAvailable();
|
|
88
|
-
|
|
89
|
-
let result: TResultIbGib | undefined = undefined;
|
|
90
|
-
|
|
91
|
-
if (isArg({ ibGib: (arg as IbGib_V1) })) {
|
|
92
|
-
result = await this.routeAndDoArg({ arg });
|
|
93
|
-
} else {
|
|
94
|
-
result = await this.doNonArg({ ibGib: arg });
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// if we didn't get a result, try the default.
|
|
98
|
-
if (!result) {
|
|
99
|
-
console.warn(`${lc} result still falsy. doing default handler. (W: 924d1fc93ad5464e81f71f2783d778a8)`);
|
|
100
|
-
result = await this.doDefault({ ibGib: arg });
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!result) { console.warn(`${lc} result falsy...Could not produce result? Was doDefault implemented in concrete class? (W: 78861cb3c37546fa8f0b2bee4c50f832)`); }
|
|
104
|
-
|
|
105
|
-
return result;
|
|
106
|
-
} catch (error) {
|
|
107
|
-
console.error(`${lc} ${error.message}`);
|
|
108
|
-
throw error;
|
|
109
|
-
} finally {
|
|
110
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Base routing executes different if incoming is a cmd options arg, i.e.,
|
|
116
|
-
* if the `data.cmd` is truthy (atow). {@link isArg} is expected to be true
|
|
117
|
-
* at this point. If not, logs an error, **but does not throw**, and returns
|
|
118
|
-
* undefined.
|
|
119
|
-
*
|
|
120
|
-
* Default routing checks arg for command, or if not, checks if comment/pic.
|
|
121
|
-
* If neither of those, then returns undefined atow.
|
|
122
|
-
*
|
|
123
|
-
* Override this function to create more advanced custom routing.
|
|
124
|
-
*
|
|
125
|
-
* ## notes
|
|
126
|
-
*
|
|
127
|
-
* In general, an app ibgib acts more like a normal application in that it
|
|
128
|
-
* accepts commands and not requests. Robbots are more geared to requests,
|
|
129
|
-
* handled semantically.
|
|
130
|
-
*
|
|
131
|
-
* @see {@link isArg}
|
|
132
|
-
* @see {@link doCmdArg}
|
|
133
|
-
* @see {@link doDefault}.
|
|
134
|
-
*/
|
|
135
|
-
protected async routeAndDoArg({
|
|
136
|
-
arg,
|
|
137
|
-
}: {
|
|
138
|
-
arg: TOptionsIbGib,
|
|
139
|
-
}): Promise<TResultIbGib | undefined> {
|
|
140
|
-
const lc = `${this.lc}[${this.routeAndDoArg.name}]`;
|
|
141
|
-
try {
|
|
142
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
143
|
-
const ibGib = arg as IbGib_V1;
|
|
144
|
-
if (!isArg({ ibGib })) { throw new Error(`ibGib is not an arg (E: 7e5ed6e3be45480e992c75a1c21f1b4e)`); }
|
|
145
|
-
if (isCommand({ ibGib })) {
|
|
146
|
-
return this.doCmdArg({ arg });
|
|
147
|
-
} else {
|
|
148
|
-
return undefined;
|
|
149
|
-
}
|
|
150
|
-
} catch (error) {
|
|
151
|
-
console.error(`${lc} ${error.message}`);
|
|
152
|
-
if (this.data?.catchAllErrors) {
|
|
153
|
-
return (await getErrorIbGib({ rawMsg: error.message })) as TResultIbGib;
|
|
154
|
-
} else {
|
|
155
|
-
throw error;
|
|
156
|
-
}
|
|
157
|
-
} finally {
|
|
158
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// #region do cmd args
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* By default, this routes to {@link doCmdIb}, {@link doCmdGib} & {@link
|
|
166
|
-
* doCmdIbgib}. This is largely to limit scope of responsibility of app to
|
|
167
|
-
* basic functions. But this is not a concrete rule written in stone.
|
|
168
|
-
*
|
|
169
|
-
* You can always override this and route to other commands before calling
|
|
170
|
-
* this with `super.doCmdArg` as a fallback (if you still want to use this
|
|
171
|
-
* function.)
|
|
172
|
-
*
|
|
173
|
-
* Note that this @throws an error if the data.cmd is not recognized. In this
|
|
174
|
-
* implementation, this occurs if it isn't an ib/gib/ibgib _command_.
|
|
175
|
-
*
|
|
176
|
-
* ## commands
|
|
177
|
-
*
|
|
178
|
-
* ### confirm
|
|
179
|
-
*
|
|
180
|
-
* confirm possession of the keystone via the keystone's challenges as set
|
|
181
|
-
* out in the keystone's metadata.
|
|
182
|
-
*
|
|
183
|
-
* ### confirm final
|
|
184
|
-
*
|
|
185
|
-
* final confirmation of a secret of the stone. "kills" the stone once used.
|
|
186
|
-
* The point is to verify if a participant has the full secret of the stone,
|
|
187
|
-
* and not just mimicked part of the stone's ownership.
|
|
188
|
-
*
|
|
189
|
-
* ### revoke
|
|
190
|
-
*
|
|
191
|
-
* revoke due to being broken.
|
|
192
|
-
* maybe is a flavor of the confirm final?
|
|
193
|
-
*/
|
|
194
|
-
protected doCmdArg({
|
|
195
|
-
arg,
|
|
196
|
-
}: {
|
|
197
|
-
arg: TOptionsIbGib,
|
|
198
|
-
}): Promise<TResultIbGib> {
|
|
199
|
-
const lc = `${this.lc}[${this.doCmdArg.name}]`;
|
|
200
|
-
try {
|
|
201
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
202
|
-
if (!arg.data?.cmd) { throw new Error(`invalid cmd arg. arg.data.cmd required. (E: 470aabf26ca6406b84dbae3b9b39639d)`); }
|
|
203
|
-
if (arg.data.cmd === KeystoneCmd.ib) {
|
|
204
|
-
return this.doCmdIb({ arg: arg });
|
|
205
|
-
} else if (arg.data.cmd === KeystoneCmd.gib) {
|
|
206
|
-
return this.doCmdGib({ arg: arg });
|
|
207
|
-
} else if (arg.data.cmd === KeystoneCmd.ibgib) {
|
|
208
|
-
return this.doCmdIbgib({ arg: arg });
|
|
209
|
-
} else {
|
|
210
|
-
throw new Error(`unknown arg.data.cmd: ${arg.data.cmd} (E: 0eb81ae8c3834f47865af0ac7b7a9fd6)`);
|
|
211
|
-
}
|
|
212
|
-
} catch (error) {
|
|
213
|
-
console.error(`${lc} ${error.message}`);
|
|
214
|
-
throw error;
|
|
215
|
-
} finally {
|
|
216
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
protected doCmdIb({
|
|
220
|
-
arg,
|
|
221
|
-
}: {
|
|
222
|
-
arg: TOptionsIbGib,
|
|
223
|
-
}): Promise<TResultIbGib> {
|
|
224
|
-
return this.extend({ arg });
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* this is the primary command handler when extending a keystone, i.e. when
|
|
228
|
-
* signing some payload.
|
|
229
|
-
*/
|
|
230
|
-
protected abstract extend({ arg }: { arg: TOptionsIbGib }): Promise<TResultIbGib>;
|
|
231
|
-
|
|
232
|
-
protected doCmdGib({
|
|
233
|
-
arg,
|
|
234
|
-
}: {
|
|
235
|
-
arg: TOptionsIbGib,
|
|
236
|
-
}): Promise<TResultIbGib> {
|
|
237
|
-
const lc = `${this.lc}[${this.doCmdGib.name}]`;
|
|
238
|
-
try {
|
|
239
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
240
|
-
throw new Error(`not implemented in base class (E: bb16814f46984a9dafac5b85d8ec1f74)`);
|
|
241
|
-
} catch (error) {
|
|
242
|
-
console.error(`${lc} ${error.message}`);
|
|
243
|
-
throw error;
|
|
244
|
-
} finally {
|
|
245
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
protected doCmdIbgib({
|
|
249
|
-
arg,
|
|
250
|
-
}: {
|
|
251
|
-
arg: TOptionsIbGib,
|
|
252
|
-
}): Promise<TResultIbGib> {
|
|
253
|
-
const lc = `${this.lc}[${this.doCmdIbgib.name}]`;
|
|
254
|
-
try {
|
|
255
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
256
|
-
throw new Error(`not implemented in base class (E: 6f3ed691d16a43f49145b2ed46fb28ba)`);
|
|
257
|
-
} catch (error) {
|
|
258
|
-
console.error(`${lc} ${error.message}`);
|
|
259
|
-
throw error;
|
|
260
|
-
} finally {
|
|
261
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// #endregion do cmd args
|
|
266
|
-
|
|
267
|
-
// #region other stubbed do functions (doPic, doComment, doDefault)
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Stubbed in base class for convenience. Doesn't have to be implemented.
|
|
271
|
-
*
|
|
272
|
-
* in the future, this may be able to be used for physical object
|
|
273
|
-
* verification via picture.
|
|
274
|
-
*/
|
|
275
|
-
protected doPic({
|
|
276
|
-
ibGib,
|
|
277
|
-
}: {
|
|
278
|
-
ibGib: PicIbGib_V1,
|
|
279
|
-
}): Promise<TResultIbGib | undefined> {
|
|
280
|
-
const lc = `${this.lc}[${this.doPic.name}]`;
|
|
281
|
-
try {
|
|
282
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
283
|
-
throw new Error(`not implemented in base class (E: ce5c9b30622f4b3bab198dde04de75e7)`);
|
|
284
|
-
} catch (error) {
|
|
285
|
-
console.error(`${lc} ${error.message}`);
|
|
286
|
-
throw error;
|
|
287
|
-
} finally {
|
|
288
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Stubbed in base class for convenience. Doesn't have to be implemented.
|
|
294
|
-
*
|
|
295
|
-
* in the future, this may be able to handle natural language and route
|
|
296
|
-
* accordingly.
|
|
297
|
-
*/
|
|
298
|
-
protected doComment({
|
|
299
|
-
ibGib,
|
|
300
|
-
}: {
|
|
301
|
-
ibGib: CommentIbGib_V1,
|
|
302
|
-
}): Promise<TResultIbGib | undefined> {
|
|
303
|
-
const lc = `${this.lc}[${this.doComment.name}]`;
|
|
304
|
-
try {
|
|
305
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
306
|
-
|
|
307
|
-
throw new Error(`not implemented in base class (E: c90f5bddaa58446fb4de638816974b6c)`);
|
|
308
|
-
} catch (error) {
|
|
309
|
-
console.error(`${lc} ${error.message}`);
|
|
310
|
-
throw error;
|
|
311
|
-
} finally {
|
|
312
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
protected doNonArg({
|
|
317
|
-
ibGib,
|
|
318
|
-
}: {
|
|
319
|
-
ibGib: TOptionsIbGib,
|
|
320
|
-
}): Promise<TResultIbGib | undefined> {
|
|
321
|
-
const lc = `${this.lc}[${this.doNonArg.name}]`;
|
|
322
|
-
try {
|
|
323
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
324
|
-
return this.doDefault({ ibGib });
|
|
325
|
-
} catch (error) {
|
|
326
|
-
console.error(`${lc} ${error.message}`);
|
|
327
|
-
throw error;
|
|
328
|
-
} finally {
|
|
329
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Stubbed in base class for convenience. Doesn't have to be implemented.
|
|
334
|
-
*/
|
|
335
|
-
protected doDefault({
|
|
336
|
-
ibGib,
|
|
337
|
-
}: {
|
|
338
|
-
ibGib: TOptionsIbGib,
|
|
339
|
-
}): Promise<TResultIbGib | undefined> {
|
|
340
|
-
const lc = `${this.lc}[${this.doDefault.name}]`;
|
|
341
|
-
try {
|
|
342
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
343
|
-
throw new Error(`not implemented in base class (E: bee031bb4c974a71bae82df7cff2b4e1)`);
|
|
344
|
-
// return this.doDefaultImpl({ibGib});
|
|
345
|
-
} catch (error) {
|
|
346
|
-
console.error(`${lc} ${error.message}`);
|
|
347
|
-
throw error;
|
|
348
|
-
} finally {
|
|
349
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// #endregion other stubbed do functions (doPic, doComment, doDefault)
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* validates against common app qualities.
|
|
357
|
-
*
|
|
358
|
-
* Override this with a call to `super.validateThis` for custom validation
|
|
359
|
-
* for descending app classes.
|
|
360
|
-
*
|
|
361
|
-
* @returns validation errors common to all apps, if any errors exist.
|
|
362
|
-
*/
|
|
363
|
-
protected async validateThis(): Promise<string[]> {
|
|
364
|
-
const lc = `${this.lc}[${this.validateThis.name}]`;
|
|
365
|
-
try {
|
|
366
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
367
|
-
if (!this.data) { throw new Error(`(UNEXPECTED) this.data falsy? (E: bd4b0fc836774eb288b8b07ec79cb4af)`); }
|
|
368
|
-
const errors = [
|
|
369
|
-
// ...await super.validateThis(),
|
|
370
|
-
...validateCommonKeystoneData({ appData: this.data }),
|
|
371
|
-
];
|
|
372
|
-
return errors;
|
|
373
|
-
} catch (error) {
|
|
374
|
-
console.error(`${lc} ${error.message}`);
|
|
375
|
-
throw error;
|
|
376
|
-
} finally {
|
|
377
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* builds an arg ibGib.
|
|
383
|
-
*
|
|
384
|
-
* wrapper convenience to avoid long generic calls.
|
|
385
|
-
*/
|
|
386
|
-
async argy<
|
|
387
|
-
TOptionsData extends KeystoneOptionsData = KeystoneOptionsData,
|
|
388
|
-
TOptionsRel8ns extends KeystoneOptionsRel8ns = KeystoneOptionsRel8ns,
|
|
389
|
-
TOptionsIbGib extends KeystoneOptionsIbGib<IbGib_V1, TOptionsData, TOptionsRel8ns> =
|
|
390
|
-
KeystoneOptionsIbGib<IbGib_V1, TOptionsData, TOptionsRel8ns>
|
|
391
|
-
>({
|
|
392
|
-
argData,
|
|
393
|
-
ibMetadata,
|
|
394
|
-
noTimestamp,
|
|
395
|
-
ibGibs,
|
|
396
|
-
}: {
|
|
397
|
-
argData: TOptionsData,
|
|
398
|
-
ibMetadata?: string,
|
|
399
|
-
noTimestamp?: boolean,
|
|
400
|
-
ibGibs?: IbGib_V1[],
|
|
401
|
-
}): Promise<TOptionsIbGib> {
|
|
402
|
-
const arg = await argy_<TOptionsData, TOptionsRel8ns, TOptionsIbGib>({
|
|
403
|
-
argData,
|
|
404
|
-
ibMetadata,
|
|
405
|
-
noTimestamp
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
if (ibGibs) { arg.ibGibs = ibGibs; }
|
|
409
|
-
|
|
410
|
-
return arg;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* builds a result ibGib, if indeed a result ibgib is required.
|
|
415
|
-
*
|
|
416
|
-
* This is only useful in apps that have more structured inputs/outputs.
|
|
417
|
-
* For those that simply accept any ibgib incoming and return a
|
|
418
|
-
* primitive like ib^gib or whatever, then this is unnecessary.
|
|
419
|
-
*
|
|
420
|
-
* wrapper convenience to avoid long generic calls.
|
|
421
|
-
*/
|
|
422
|
-
async resulty<
|
|
423
|
-
TResultData extends KeystoneResultData = KeystoneResultData,
|
|
424
|
-
TResultRel8ns extends KeystoneResultRel8ns = KeystoneResultRel8ns,
|
|
425
|
-
TResultIbGib extends KeystoneResultIbGib<IbGib_V1, TResultData, TResultRel8ns> =
|
|
426
|
-
KeystoneResultIbGib<IbGib_V1, TResultData, TResultRel8ns>
|
|
427
|
-
>({
|
|
428
|
-
resultData,
|
|
429
|
-
ibGibs,
|
|
430
|
-
}: {
|
|
431
|
-
resultData: TResultData,
|
|
432
|
-
ibGibs?: IbGib_V1[],
|
|
433
|
-
}): Promise<TResultIbGib> {
|
|
434
|
-
const result = await resulty_<TResultData, TResultIbGib>({
|
|
435
|
-
// ibMetadata: getKeystoneResultMetadata({space: this}),
|
|
436
|
-
resultData,
|
|
437
|
-
});
|
|
438
|
-
if (ibGibs) { result.ibGibs = ibGibs; }
|
|
439
|
-
return result;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* useful for when passing around instances of keystones where implementation
|
|
446
|
-
* details are not important.
|
|
447
|
-
*/
|
|
448
|
-
export interface IbGibKeystoneAny
|
|
449
|
-
extends KeystoneBase_V1<any, any, any, any, any, any, any, any, any, any> {
|
|
450
|
-
}
|
|
File without changes
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { GLOBAL_LOG_A_LOT } from "../../core-constants.mjs";
|
|
2
|
-
import { KeystoneData_V1 } from "./keystone-types.mjs";
|
|
3
|
-
|
|
4
|
-
const logalot = GLOBAL_LOG_A_LOT || false;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* validation of data common to all keystones (i.e. at the base class level).
|
|
8
|
-
* @returns error strings array of any validation errors. empty if none
|
|
9
|
-
*/
|
|
10
|
-
export function validateCommonKeystoneData({
|
|
11
|
-
appData,
|
|
12
|
-
}: {
|
|
13
|
-
appData: KeystoneData_V1<any, any> | undefined,
|
|
14
|
-
}): string[] {
|
|
15
|
-
const lc = `[${validateCommonKeystoneData.name}]`;
|
|
16
|
-
try {
|
|
17
|
-
if (logalot) { console.log(`${lc} starting...`); }
|
|
18
|
-
if (!appData) { throw new Error(`appData required (E: e22bd1940d1d436fbbed8126c11aa529)`); }
|
|
19
|
-
const errors: string[] = [];
|
|
20
|
-
|
|
21
|
-
console.warn(`${lc} not impl yet`)
|
|
22
|
-
// const {
|
|
23
|
-
// name, uuid, classname,
|
|
24
|
-
// } =
|
|
25
|
-
// appData;
|
|
26
|
-
|
|
27
|
-
// if (name) {
|
|
28
|
-
// if (!name.match(APP_NAME_REGEXP)) {
|
|
29
|
-
// errors.push(`name must match regexp: ${APP_NAME_REGEXP}`);
|
|
30
|
-
// }
|
|
31
|
-
// } else {
|
|
32
|
-
// errors.push(`name required.`);
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
// if (uuid) {
|
|
36
|
-
// if (!uuid.match(UUID_REGEXP)) {
|
|
37
|
-
// errors.push(`uuid must match regexp: ${UUID_REGEXP}`);
|
|
38
|
-
// }
|
|
39
|
-
// } else {
|
|
40
|
-
// errors.push(`uuid required.`);
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
// if (classname) {
|
|
44
|
-
// if (!classname.match(APP_NAME_REGEXP)) {
|
|
45
|
-
// errors.push(`classname must match regexp: ${APP_NAME_REGEXP}`);
|
|
46
|
-
// }
|
|
47
|
-
// }
|
|
48
|
-
|
|
49
|
-
return errors;
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.error(`${lc} ${error.message}`);
|
|
52
|
-
throw error;
|
|
53
|
-
} finally {
|
|
54
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,200 +0,0 @@
|
|
|
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
|
-
}
|