@ibgib/core-gib 0.0.53 → 0.0.55

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.
@@ -31,7 +31,6 @@ import { ENCRYPTION_REL8N_NAME, ENCRYPTION_ATOM, ENCRYPTION_NAME_REGEXP, } from
31
31
  import { MetaspaceService } from "../../witness/space/metaspace/metaspace-types.mjs";
32
32
  import { IbGibSpaceAny } from "../../witness/space/space-base-v1.mjs";
33
33
  import { SpecialIbGibType } from '../other/other-types.mjs';
34
- import { encrypt } from '@ibgib/encrypt-gib/dist/encrypt-decrypt.mjs';
35
34
 
36
35
  /**
37
36
  * for verbose logging
@@ -46,39 +45,39 @@ export function validateCommonEncryptionData({
46
45
  const lc = `[${validateCommonEncryptionData.name}]`;
47
46
  try {
48
47
  if (logalot) { console.log(`${lc} starting...`); }
49
- if (!data) { throw new Error(`data required (E: )`); }
48
+ if (!data) { throw new Error(`data required (E: 9c7e015ad86041da89fa0a8490b19496)`); }
50
49
  const errors: string[] = [];
51
50
  const { name, uuid, classname, method, } = data;
52
51
 
53
52
  if (name) {
54
53
  if (!name.match(ENCRYPTION_NAME_REGEXP)) {
55
- errors.push(`name must match regexp: ${ENCRYPTION_NAME_REGEXP} (E: )`);
54
+ errors.push(`name must match regexp: ${ENCRYPTION_NAME_REGEXP} (E: 3408de089b194553a1b9d2eb49fdda1c)`);
56
55
  }
57
56
  } else {
58
- errors.push(`name required. (E: )`);
57
+ errors.push(`name required. (E: 1f4ec2f886a142279a91f852a13c3225)`);
59
58
  }
60
59
 
61
60
  if (method) {
62
61
  if (!VALID_ENCRYPTION_METHODS.includes(method)) {
63
- errors.push(`method (${method}) is invalid. must be one of ${VALID_ENCRYPTION_METHODS.join(', ')} (E: )`);
62
+ errors.push(`method (${method}) is invalid. must be one of ${VALID_ENCRYPTION_METHODS.join(', ')} (E: 84a382b525944082badae40aebed497d)`);
64
63
  }
65
64
  } else {
66
- errors.push(`method required. (E: )`);
65
+ errors.push(`method required. (E: 0bf6177233b24c9fa98499dc1453c0c9)`);
67
66
  }
68
67
 
69
68
  if (uuid) {
70
69
  if (!uuid.match(UUID_REGEXP)) {
71
- errors.push(`uuid must match regexp: ${UUID_REGEXP} (E: )`);
70
+ errors.push(`uuid must match regexp: ${UUID_REGEXP} (E: bf54ee4ac10a4ee3a8fd1f5db17f1866)`);
72
71
  }
73
72
  }
74
73
 
75
74
  if (classname) {
76
75
  if (!classname.match(CLASSNAME_REGEXP)) {
77
- errors.push(`classname must match regexp: ${CLASSNAME_REGEXP} (E: )`);
76
+ errors.push(`classname must match regexp: ${CLASSNAME_REGEXP} (E: 054087390a2d40daa6955e70e31c0cdb)`);
78
77
  }
79
78
  }
80
79
 
81
- if (method === EncryptionMethod.encrypt_gib_weak) {
80
+ if (method === EncryptionMethod.encrypt_gib) {
82
81
  const encryptGibErrors = validateCommonEncryptionData_encryptGib({ data });
83
82
  encryptGibErrors.forEach(x => errors.push(x));
84
83
  }
@@ -132,7 +131,7 @@ function validateCommonEncryptionData_encryptGib({
132
131
  }
133
132
  }
134
133
 
135
- if (data.salt) {
134
+ if (data.salt || data.salt === '') {
136
135
  if (typeof data.salt !== 'string') {
137
136
  errors.push(`invalid salt (${data.salt}, typeof: ${typeof data.salt}). must be "string". (E: 0bee1f049dfd4f6e937cd423bb1b0c90)`)
138
137
  }
@@ -162,18 +161,18 @@ export async function validateCommonEncryptionIbGib({
162
161
  }): Promise<string[] | undefined> {
163
162
  const lc = `[${validateCommonEncryptionIbGib.name}]`;
164
163
  try {
165
- if (logalot) { console.log(`${lc} starting... (I: )`); }
164
+ if (logalot) { console.log(`${lc} starting... (I: 48b13b0fe20146258ee921ed22a214d9)`); }
166
165
  const intrinsicErrors: string[] = await validateIbGibIntrinsically({ ibGib: ibGib }) ?? [];
167
166
 
168
- if (!ibGib.data) { throw new Error(`EncryptionIbGib.data required (E: )`); }
167
+ if (!ibGib.data) { throw new Error(`EncryptionIbGib.data required (E: bdc7bbea44e042118352f4fa512fea43)`); }
169
168
  const ibErrors: string[] = [];
170
169
 
171
170
  // ib
172
171
  let { atom, method, name, } =
173
172
  parseEncryptionIb({ ib: ibGib.ib });
174
- if (atom !== ENCRYPTION_ATOM) { ibErrors.push(`invalid encryption atom. must be ${ENCRYPTION_ATOM} (E: )`); }
175
- if (!method) { ibErrors.push(`encryption method required (E: )`); }
176
- if (!name) { ibErrors.push(`encryption name required (E: )`); }
173
+ if (atom !== ENCRYPTION_ATOM) { ibErrors.push(`invalid encryption atom. must be ${ENCRYPTION_ATOM} (E: 8437377bc6b548db846b8802e935812d)`); }
174
+ if (!method) { ibErrors.push(`encryption method required (E: b19999f74eff4d7da15867ba5907876b)`); }
175
+ if (!name) { ibErrors.push(`encryption name required (E: ae9bdc064f804f4a86f157cfe58274f7)`); }
177
176
 
178
177
  // data
179
178
  const dataErrors = validateCommonEncryptionData({ data: ibGib.data });
@@ -207,7 +206,7 @@ export function getEncryptionIb({
207
206
  const lc = `[${getEncryptionIb.name}]`;
208
207
  try {
209
208
  const validationErrors = validateCommonEncryptionData({ data });
210
- if (validationErrors.length > 0) { throw new Error(`invalid Encryption data: ${validationErrors} (E: )`); }
209
+ if (validationErrors.length > 0) { throw new Error(`invalid Encryption data: ${validationErrors} (E: f2f124c1b55a496c835849cc9e67a96f)`); }
211
210
 
212
211
  const { name, method } = data;
213
212
 
@@ -234,15 +233,15 @@ export function parseEncryptionIb({
234
233
  } {
235
234
  const lc = `[${parseEncryptionIb.name}]`;
236
235
  try {
237
- if (!ib) { throw new Error(`Encryption ib required (E: )`); }
236
+ if (!ib) { throw new Error(`Encryption ib required (E: 067fb72027f34ddc95dfba76fd429ed4)`); }
238
237
 
239
238
  const [atom, method, name] = ib.split(' ');
240
239
 
241
- if (atom !== ENCRYPTION_ATOM) { throw new Error(`atom !== ${ENCRYPTION_ATOM} (E: )`); }
240
+ if (atom !== ENCRYPTION_ATOM) { throw new Error(`atom !== ${ENCRYPTION_ATOM} (E: 8361b9630e3f4f309ce48f1db278cc74)`); }
242
241
 
243
- if (method !== EncryptionMethod.encrypt_gib_weak) { console.warn(`${lc} method !== EncryptionMethod.encrypt_gib_weak. atow (02/2024) .ncrypt_gib_weak is the only thing we got. (W: )`) }
242
+ if (method !== EncryptionMethod.encrypt_gib) { console.warn(`${lc} method (${method})!== EncryptionMethod.encrypt_gib. atow (02/2024) EncryptionMethod.encrypt_gib is the only thing we got. (W: 266540fa139544079e313e12d707aafe)`) }
244
243
 
245
- if (!name.match(ENCRYPTION_NAME_REGEXP)) { throw new Error(`!name.match(ENCRYPTION_NAME_REGEXP) (E: )`); }
244
+ if (!name.match(ENCRYPTION_NAME_REGEXP)) { throw new Error(`!name.match(ENCRYPTION_NAME_REGEXP) (E: 5a49f74179d44b83a4cb4310e05cb2e3)`); }
246
245
 
247
246
  return { atom, method, name, };
248
247
  } catch (error) {
@@ -265,11 +264,11 @@ export async function createAndRegisterNewEncryption({
265
264
  }): Promise<EncryptionIbGib_V1> {
266
265
  const lc = `[${createAndRegisterNewEncryption.name}]`;
267
266
  try {
268
- if (logalot) { console.log(`${lc} starting... (I: )`); }
267
+ if (logalot) { console.log(`${lc} starting... (I: 7839b94f046a43aebc2ac0ff350c464b)`); }
269
268
 
270
269
  let resEncryptionIbGib: EncryptionIbGib_V1;
271
270
 
272
- if (encryptionMethod !== EncryptionMethod.encrypt_gib_weak) { throw new Error(`unknown encryptionMethod (${encryptionMethod}). only "encrypt-gib" encryption method currently implemented. (E: )`); }
271
+ if (encryptionMethod !== EncryptionMethod.encrypt_gib) { throw new Error(`unknown encryptionMethod (${encryptionMethod}). only "encrypt-gib" encryption method currently implemented. (E: bfc617eb731a4f99821fcdd3feba3835)`); }
273
272
 
274
273
  resEncryptionIbGib = await createAndRegisterNewEncryption_encryptGib({
275
274
  encryptionInfo: encryptionInfo as EncryptionInfo_EncryptGib,
@@ -297,10 +296,10 @@ async function createAndRegisterNewEncryption_encryptGib({
297
296
  }): Promise<EncryptionIbGib_V1> {
298
297
  const lc = `[${createAndRegisterNewEncryption_encryptGib.name}]`;
299
298
  try {
300
- if (logalot) { console.log(`${lc} starting... (I: )`); }
299
+ if (logalot) { console.log(`${lc} starting... (I: 5413d44c92db43b0ab70afa962266828)`); }
301
300
 
302
301
  const { method: encryptionMethod } = encryptionInfo;
303
- if (encryptionMethod !== 'encrypt-gib (weak)') { throw new Error(`(UNEXPECTED) encryptionMethod !== 'encrypt-gib (weak)'? (E: )`); }
302
+ if (encryptionMethod !== EncryptionMethod.encrypt_gib) { throw new Error(`(UNEXPECTED) encryptionMethod (${encryptionMethod}) !== ${EncryptionMethod.encrypt_gib}? (E: 5b1d1d2cd00e4ae1a759da2c4071b46d)`); }
304
303
 
305
304
  // create the encryption ibgib
306
305
  const data: EncryptionData_V1 = {
@@ -319,7 +318,7 @@ async function createAndRegisterNewEncryption_encryptGib({
319
318
  // validate right away before anything else
320
319
  const validationErrors =
321
320
  await validateCommonEncryptionIbGib({ ibGib: encryptionIbGib }) ?? [];
322
- if (validationErrors.length > 0) { throw new Error(`(UNEXPECTED) newly created encryptionIbGib has validationErrors? validationErrors: ${validationErrors} (E: )`); }
321
+ if (validationErrors.length > 0) { throw new Error(`(UNEXPECTED) newly created encryptionIbGib has validationErrors? validationErrors: ${validationErrors} (E: 38791edd0b684eb58c6a194e055cadf9)`); }
323
322
 
324
323
  // save first in the space...
325
324
  await metaspace.persistTransformResult({ resTransform: resFirstGen, space });
@@ -7,7 +7,7 @@ import { ENCRYPTION_REL8N_NAME } from './encrypt-constants.mjs';
7
7
 
8
8
 
9
9
 
10
- export type EncryptionMethod = 'encrypt-gib (weak)';
10
+ export type EncryptionMethod = 'encrypt-gib';
11
11
  /**
12
12
  * Discriminator for the algorithm used in encryption that specifies the
13
13
  * algorithm used in encryption.
@@ -20,7 +20,7 @@ export const EncryptionMethod = {
20
20
  * custom probably very weak algorithm that uses indexing into a recursive
21
21
  * hash-based rounding function instead of keystream generation.
22
22
  */
23
- encrypt_gib_weak: 'encrypt-gib (weak)' as EncryptionMethod,
23
+ encrypt_gib: 'encrypt-gib' as EncryptionMethod,
24
24
  }
25
25
  export const VALID_ENCRYPTION_METHODS = Object.values(EncryptionMethod);
26
26
 
@@ -41,7 +41,7 @@ export interface EncryptionInfo {
41
41
  * Parameter information that is specific to the encrypt-gib algorithm.
42
42
  */
43
43
  export interface EncryptionInfo_EncryptGib extends EncryptionInfo {
44
- method: 'encrypt-gib (weak)'
44
+ method: 'encrypt-gib'
45
45
  /**
46
46
  * This is the algorithm that encrypt-gib will use in its
47
47
  * internal hashing round function to encrypt the data.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @module encryption respec
3
+ *
4
+ * we gotta test our encryption ibgibs
5
+ */
6
+
7
+ // import { cwd, chdir, } from 'node:process';
8
+ // import { statSync } from 'node:fs';
9
+ // import { mkdir, } from 'node:fs/promises';
10
+ // import { ChildProcess, exec, ExecException } from 'node:child_process';
11
+ import * as pathUtils from 'path';
12
+
13
+ import {
14
+ firstOfAll, firstOfEach, ifWe, ifWeMight, iReckon,
15
+ lastOfAll, lastOfEach, respecfully, respecfullyDear
16
+ } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
17
+ const maam = `[${import.meta.url}]`, sir = maam;
18
+
19
+ import {
20
+ extractErrorMsg, delay, getSaferSubstring,
21
+ getTimestampInTicks, getUUID, pretty, HashAlgorithm, clone, getTimestamp,
22
+ } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
23
+
24
+ import { GLOBAL_LOG_A_LOT } from '../../core-constants.mjs';
25
+ import { EncryptionData_V1, EncryptionMethod } from './encrypt-types.mjs';
26
+ import { SaltStrategy } from '@ibgib/encrypt-gib/dist/types.mjs';
27
+ import { getEncryptionIb, parseEncryptionIb } from './encrypt-helper.mjs';
28
+ import { ENCRYPTION_ATOM } from './encrypt-constants.mjs';
29
+
30
+ /**
31
+ * for verbose logging
32
+ */
33
+ const logalot = GLOBAL_LOG_A_LOT; // change this when you want to turn off verbose logging
34
+
35
+ const lcFile: string = `[${pathUtils.basename(import.meta.url)}]`;
36
+
37
+ const atom = ENCRYPTION_ATOM;
38
+ const recursionCount = 168;
39
+ const hashAlgorithm: HashAlgorithm = 'SHA-256';
40
+ const saltPrependedPerHash = '';
41
+ const saltStrategy = SaltStrategy.prependPerHash;
42
+ const initialRecursions = 1000;
43
+ const recursionsPerHash = 2;
44
+ const method: EncryptionMethod = EncryptionMethod.encrypt_gib;
45
+
46
+ const salt_empty = ''; //
47
+ const description = 'description yo';
48
+
49
+ const blockName = `encryption ib`;
50
+ await respecfully(maam, blockName, async () => {
51
+ const lc = `${lcFile}[${blockName}]`;
52
+ debugger;
53
+
54
+ const name = await getUUID();
55
+ const timestampDate = new Date();
56
+ const timestamp = getTimestamp(timestampDate);
57
+ const timestampMs = timestampDate.getMilliseconds().toString();
58
+
59
+
60
+ const data_valid: EncryptionData_V1 = {
61
+ name,
62
+ hashAlgorithm,
63
+ initialRecursions: 1000,
64
+ method,
65
+ salt: salt_empty,
66
+ description,
67
+ encryptedDataDelimiter: undefined,
68
+ recursionsPerHash,
69
+ saltStrategy,
70
+ n: 0, timestamp, timestampMs,
71
+ };
72
+
73
+
74
+ await ifWe(maam, `getEncryptionIb`, async () => {
75
+ const data = data_valid;
76
+ let ib = getEncryptionIb({ data });
77
+ iReckon(sir, ib.includes(name)).asTo('name').isGonnaBeTrue();
78
+ iReckon(sir, ib.includes(method)).asTo('method').isGonnaBeTrue();
79
+ });
80
+ await ifWe(maam, `parseEncryptionIb`, async () => {
81
+ const data = data_valid;
82
+ let ib = getEncryptionIb({ data });
83
+ let parsed = parseEncryptionIb({ ib });
84
+
85
+ iReckon(sir, parsed.atom).asTo('atom').isGonnaBe(atom);
86
+ iReckon(sir, parsed.name).asTo('name').isGonnaBe(name);
87
+ iReckon(sir, parsed.method).asTo('method').isGonnaBe(method);
88
+ });
89
+
90
+ });
@@ -15,8 +15,7 @@ import {
15
15
  extractErrorMsg, delay, getSaferSubstring,
16
16
  getTimestampInTicks, getUUID, pretty, HashAlgorithm, getTimestamp,
17
17
  } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
18
- import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
19
- import { UUID_REGEXP, CLASSNAME_REGEXP, } from '@ibgib/helper-gib/dist/constants.mjs';
18
+ import { CLASSNAME_REGEXP, } from '@ibgib/helper-gib/dist/constants.mjs';
20
19
  import { Ib, } from '@ibgib/ts-gib/dist/types.mjs';
21
20
  import { validateIbGibIntrinsically } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
22
21
  import { Factory_V1 } from "@ibgib/ts-gib/dist/V1/factory.mjs";
@@ -26,7 +25,6 @@ import { CheckIfPasswordProbablyCorrectInfo, SecretData_V1, SecretIbGib_V1, Secr
26
25
  import { SECRET_ATOM, SECRET_NAME_REGEXP, SECRET_REL8N_NAME, } from './secret-constants.mjs';
27
26
  import { MetaspaceService } from "../../witness/space/metaspace/metaspace-types.mjs";
28
27
  import { IbGibSpaceAny } from "../../witness/space/space-base-v1.mjs";
29
- import { SpecialIbGibType } from "../other/other-types.mjs";
30
28
  import { INVALID_DATE_STRING } from '../other/other-constants.mjs';
31
29
  import { hash16816 } from '../other/ibgib-helper.mjs';
32
30
 
@@ -25,6 +25,7 @@ import { RootData } from '../../../common/root/root-types.mjs';
25
25
  import {
26
26
  CiphertextData, CiphertextIbGib_V1, CiphertextRel8ns,
27
27
  EncryptionData_V1, EncryptionIbGib_V1, EncryptionInfo_EncryptGib,
28
+ EncryptionMethod,
28
29
  } from '../../../common/encrypt/encrypt-types.mjs';
29
30
  import { RobbotIbGib_V1 } from '../../../witness/robbot/robbot-types.mjs';
30
31
  import { AppIbGib_V1 } from '../../../witness/app/app-types.mjs';
@@ -1796,7 +1797,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
1796
1797
  const lc = `${this.lc}[${this.getCiphertextIbGib.name}]`;
1797
1798
  try {
1798
1799
  const encryptionInfo = encryptionIbGib.data;
1799
- if (encryptionInfo?.method !== 'encrypt-gib (weak)') {
1800
+ if (encryptionInfo?.method !== EncryptionMethod.encrypt_gib) {
1800
1801
  throw new Error('only encrypt-gib is implemented.');
1801
1802
  }
1802
1803
  const info: EncryptionInfo_EncryptGib = encryptionInfo;