@ibgib/web-gib 0.0.11 → 0.0.12
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/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/package.json +1 -1
- 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
|
@@ -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
|
+
}
|