@bcts/known-values 1.0.0-alpha.17 → 1.0.0-alpha.18

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.
@@ -1,4 +1,5 @@
1
1
  import { KnownValue } from "./known-value";
2
+ import { loadBundledRegistries } from "./bundled-registries";
2
3
  import { KnownValuesStore } from "./known-values-store";
3
4
 
4
5
  // For definitions see: https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2023-002-known-value.md#appendix-a-registry
@@ -194,7 +195,7 @@ export const PROVENANCE_GENERATOR = new KnownValue(68, "provenanceGenerator");
194
195
  //
195
196
 
196
197
  export const PRIVILEGE_ALL = new KnownValue(70, "All");
197
- export const PRIVILEGE_AUTH = new KnownValue(71, "Auth");
198
+ export const PRIVILEGE_AUTH = new KnownValue(71, "Authorize");
198
199
  export const PRIVILEGE_SIGN = new KnownValue(72, "Sign");
199
200
  export const PRIVILEGE_ENCRYPT = new KnownValue(73, "Encrypt");
200
201
  export const PRIVILEGE_ELIDE = new KnownValue(74, "Elide");
@@ -240,9 +241,9 @@ export const MASTER_KEY_TYPE = new KnownValue(203, "MasterKey");
240
241
  //
241
242
 
242
243
  export const ASSET = new KnownValue(300, "asset");
243
- export const BITCOIN_VALUE = new KnownValue(301, "BTC");
244
- export const ETHEREUM_VALUE = new KnownValue(302, "ETH");
245
- export const TEZOS_VALUE = new KnownValue(303, "XTZ");
244
+ export const BITCOIN_VALUE = new KnownValue(301, "Bitcoin");
245
+ export const ETHEREUM_VALUE = new KnownValue(302, "Ethereum");
246
+ export const TEZOS_VALUE = new KnownValue(303, "Tezos");
246
247
  // 304-399 *unassigned*
247
248
 
248
249
  //
@@ -261,8 +262,8 @@ export const TEST_NET_VALUE = new KnownValue(402, "TestNet");
261
262
  export const BIP32_KEY_TYPE = new KnownValue(500, "BIP32Key");
262
263
  export const CHAIN_CODE = new KnownValue(501, "chainCode");
263
264
  export const DERIVATION_PATH_TYPE = new KnownValue(502, "DerivationPath");
264
- export const PARENT_PATH = new KnownValue(503, "parent");
265
- export const CHILDREN_PATH = new KnownValue(504, "children");
265
+ export const PARENT_PATH = new KnownValue(503, "parentPath");
266
+ export const CHILDREN_PATH = new KnownValue(504, "childrenPath");
266
267
  export const PARENT_FINGERPRINT = new KnownValue(505, "parentFingerprint");
267
268
  export const PSBT_TYPE = new KnownValue(506, "PSBT");
268
269
  export const OUTPUT_DESCRIPTOR_TYPE = new KnownValue(507, "OutputDescriptor");
@@ -273,7 +274,7 @@ export const OUTPUT_DESCRIPTOR = new KnownValue(508, "outputDescriptor");
273
274
  // Graphs
274
275
  //
275
276
 
276
- export const GRAPH = new KnownValue(600, "graph");
277
+ export const GRAPH = new KnownValue(600, "Graph");
277
278
  export const SOURCE_TARGET_GRAPH = new KnownValue(601, "SourceTargetGraph");
278
279
  export const PARENT_CHILD_GRAPH = new KnownValue(602, "ParentChildGraph");
279
280
  export const DIGRAPH = new KnownValue(603, "Digraph");
@@ -294,7 +295,9 @@ export const SOURCE = new KnownValue(702, "source");
294
295
  export const TARGET = new KnownValue(703, "target");
295
296
  export const PARENT = new KnownValue(704, "parent");
296
297
  export const CHILD = new KnownValue(705, "child");
297
- // 706-... *unassigned*
298
+ export const SELF_RAW = 706n;
299
+ export const SELF = new KnownValue(706, "Self");
300
+ // 707-... *unassigned*
298
301
 
299
302
  /**
300
303
  * A lazily initialized singleton that holds the global registry of known
@@ -318,108 +321,119 @@ export class LazyKnownValues {
318
321
  * This method guarantees that initialization occurs exactly once.
319
322
  */
320
323
  get(): KnownValuesStore {
321
- this._data ??= new KnownValuesStore([
322
- UNIT,
323
- IS_A,
324
- ID,
325
- SIGNED,
326
- NOTE,
327
- HAS_RECIPIENT,
328
- SSKR_SHARE,
329
- CONTROLLER,
330
- KEY,
331
- DEREFERENCE_VIA,
332
- ENTITY,
333
- NAME,
334
- LANGUAGE,
335
- ISSUER,
336
- HOLDER,
337
- SALT,
338
- DATE,
339
- UNKNOWN_VALUE,
340
- VERSION_VALUE,
341
- HAS_SECRET,
342
- DIFF_EDITS,
343
- VALID_FROM,
344
- VALID_UNTIL,
345
- POSITION,
346
- NICKNAME,
347
- ATTACHMENT,
348
- VENDOR,
349
- CONFORMS_TO,
350
- ALLOW,
351
- DENY,
352
- ENDPOINT,
353
- DELEGATE,
354
- PROVENANCE,
355
- PRIVATE_KEY,
356
- SERVICE,
357
- CAPABILITY,
358
- PROVENANCE_GENERATOR,
359
- PRIVILEGE_ALL,
360
- PRIVILEGE_AUTH,
361
- PRIVILEGE_SIGN,
362
- PRIVILEGE_ENCRYPT,
363
- PRIVILEGE_ELIDE,
364
- PRIVILEGE_ISSUE,
365
- PRIVILEGE_ACCESS,
366
- PRIVILEGE_DELEGATE,
367
- PRIVILEGE_VERIFY,
368
- PRIVILEGE_UPDATE,
369
- PRIVILEGE_TRANSFER,
370
- PRIVILEGE_ELECT,
371
- PRIVILEGE_BURN,
372
- PRIVILEGE_REVOKE,
373
- BODY,
374
- RESULT,
375
- ERROR,
376
- OK_VALUE,
377
- PROCESSING_VALUE,
378
- SENDER,
379
- SENDER_CONTINUATION,
380
- RECIPIENT_CONTINUATION,
381
- CONTENT,
382
- SEED_TYPE,
383
- PRIVATE_KEY_TYPE,
384
- PUBLIC_KEY_TYPE,
385
- MASTER_KEY_TYPE,
386
- ASSET,
387
- BITCOIN_VALUE,
388
- ETHEREUM_VALUE,
389
- TEZOS_VALUE,
390
- NETWORK,
391
- MAIN_NET_VALUE,
392
- TEST_NET_VALUE,
393
- BIP32_KEY_TYPE,
394
- CHAIN_CODE,
395
- DERIVATION_PATH_TYPE,
396
- PARENT_PATH,
397
- CHILDREN_PATH,
398
- PARENT_FINGERPRINT,
399
- PSBT_TYPE,
400
- OUTPUT_DESCRIPTOR_TYPE,
401
- OUTPUT_DESCRIPTOR,
402
- GRAPH,
403
- SOURCE_TARGET_GRAPH,
404
- PARENT_CHILD_GRAPH,
405
- DIGRAPH,
406
- ACYCLIC_GRAPH,
407
- MULTIGRAPH,
408
- PSEUDOGRAPH,
409
- GRAPH_FRAGMENT,
410
- DAG,
411
- TREE,
412
- FOREST,
413
- COMPOUND_GRAPH,
414
- HYPERGRAPH,
415
- DIHYPERGRAPH,
416
- NODE,
417
- EDGE,
418
- SOURCE,
419
- TARGET,
420
- PARENT,
421
- CHILD,
422
- ]);
324
+ if (this._data === undefined) {
325
+ const store = new KnownValuesStore([
326
+ UNIT,
327
+ IS_A,
328
+ ID,
329
+ SIGNED,
330
+ NOTE,
331
+ HAS_RECIPIENT,
332
+ SSKR_SHARE,
333
+ CONTROLLER,
334
+ KEY,
335
+ DEREFERENCE_VIA,
336
+ ENTITY,
337
+ NAME,
338
+ LANGUAGE,
339
+ ISSUER,
340
+ HOLDER,
341
+ SALT,
342
+ DATE,
343
+ UNKNOWN_VALUE,
344
+ VERSION_VALUE,
345
+ HAS_SECRET,
346
+ DIFF_EDITS,
347
+ VALID_FROM,
348
+ VALID_UNTIL,
349
+ POSITION,
350
+ NICKNAME,
351
+ ATTACHMENT,
352
+ VENDOR,
353
+ CONFORMS_TO,
354
+ ALLOW,
355
+ DENY,
356
+ ENDPOINT,
357
+ DELEGATE,
358
+ PROVENANCE,
359
+ PRIVATE_KEY,
360
+ SERVICE,
361
+ CAPABILITY,
362
+ PROVENANCE_GENERATOR,
363
+ PRIVILEGE_ALL,
364
+ PRIVILEGE_AUTH,
365
+ PRIVILEGE_SIGN,
366
+ PRIVILEGE_ENCRYPT,
367
+ PRIVILEGE_ELIDE,
368
+ PRIVILEGE_ISSUE,
369
+ PRIVILEGE_ACCESS,
370
+ PRIVILEGE_DELEGATE,
371
+ PRIVILEGE_VERIFY,
372
+ PRIVILEGE_UPDATE,
373
+ PRIVILEGE_TRANSFER,
374
+ PRIVILEGE_ELECT,
375
+ PRIVILEGE_BURN,
376
+ PRIVILEGE_REVOKE,
377
+ BODY,
378
+ RESULT,
379
+ ERROR,
380
+ OK_VALUE,
381
+ PROCESSING_VALUE,
382
+ SENDER,
383
+ SENDER_CONTINUATION,
384
+ RECIPIENT_CONTINUATION,
385
+ CONTENT,
386
+ SEED_TYPE,
387
+ PRIVATE_KEY_TYPE,
388
+ PUBLIC_KEY_TYPE,
389
+ MASTER_KEY_TYPE,
390
+ ASSET,
391
+ BITCOIN_VALUE,
392
+ ETHEREUM_VALUE,
393
+ TEZOS_VALUE,
394
+ NETWORK,
395
+ MAIN_NET_VALUE,
396
+ TEST_NET_VALUE,
397
+ BIP32_KEY_TYPE,
398
+ CHAIN_CODE,
399
+ DERIVATION_PATH_TYPE,
400
+ PARENT_PATH,
401
+ CHILDREN_PATH,
402
+ PARENT_FINGERPRINT,
403
+ PSBT_TYPE,
404
+ OUTPUT_DESCRIPTOR_TYPE,
405
+ OUTPUT_DESCRIPTOR,
406
+ GRAPH,
407
+ SOURCE_TARGET_GRAPH,
408
+ PARENT_CHILD_GRAPH,
409
+ DIGRAPH,
410
+ ACYCLIC_GRAPH,
411
+ MULTIGRAPH,
412
+ PSEUDOGRAPH,
413
+ GRAPH_FRAGMENT,
414
+ DAG,
415
+ TREE,
416
+ FOREST,
417
+ COMPOUND_GRAPH,
418
+ HYPERGRAPH,
419
+ DIHYPERGRAPH,
420
+ NODE,
421
+ EDGE,
422
+ SOURCE,
423
+ TARGET,
424
+ PARENT,
425
+ CHILD,
426
+ ]);
427
+
428
+ // Load bundled registry values from JSON data files.
429
+ // These are embedded at build time and available in all environments.
430
+ // Matching Rust behavior: later inserts overwrite earlier ones.
431
+ for (const value of loadBundledRegistries()) {
432
+ store.insert(value);
433
+ }
434
+
435
+ this._data = store;
436
+ }
423
437
  return this._data;
424
438
  }
425
439
  }
@@ -318,6 +318,16 @@ export class KnownValuesStore {
318
318
  * Internal helper method to insert a KnownValue into the store's maps.
319
319
  */
320
320
  private _insert(knownValue: KnownValue): void {
321
+ // If there's an existing value with the same codepoint, remove its name
322
+ // from the name index to avoid stale entries
323
+ const existing = this.knownValuesByRawValue.get(knownValue.valueBigInt());
324
+ if (existing !== undefined) {
325
+ const oldName = existing.assignedName();
326
+ if (oldName !== undefined && oldName !== "") {
327
+ this.knownValuesByAssignedName.delete(oldName);
328
+ }
329
+ }
330
+
321
331
  this.knownValuesByRawValue.set(knownValue.valueBigInt(), knownValue);
322
332
  const assignedName = knownValue.assignedName();
323
333
  if (assignedName !== undefined && assignedName !== "") {