@ckb-ccc/core 1.11.3 → 1.11.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @ckb-ccc/core
2
2
 
3
+ ## 1.11.5
4
+ ### Patch Changes
5
+
6
+
7
+
8
+ - [#306](https://github.com/ckb-devrel/ccc/pull/306) [`cec9b39`](https://github.com/ckb-devrel/ccc/commit/cec9b39345fc37a6ae72c0774059b2e31efc9e89) Thanks [@Hanssen0](https://github.com/Hanssen0)! - fix(core): nostr signature verification
9
+
10
+
11
+
12
+ - [#304](https://github.com/ckb-devrel/ccc/pull/304) [`c95913f`](https://github.com/ckb-devrel/ccc/commit/c95913f58c889c9d8c0b164014f9917501c11dbc) Thanks [@Hanssen0](https://github.com/Hanssen0)! - fix(core): `ccc.mol.codec` decorator
13
+
14
+ * The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
15
+ * Decorator function return type '...' is not assignable to type '...'
16
+
17
+ ## 1.11.4
18
+ ### Patch Changes
19
+
20
+
21
+
22
+ - [#295](https://github.com/ckb-devrel/ccc/pull/295) [`1eb030f`](https://github.com/ckb-devrel/ccc/commit/1eb030fde95c545561a092a4025747e6d14fc8de) Thanks [@Hanssen0](https://github.com/Hanssen0)! - fix(core): `ClientCacheMemory.findCells` never stops
23
+
3
24
  ## 1.11.3
4
25
  ### Patch Changes
5
26
 
@@ -13,43 +13,40 @@ export declare function filterNumByRange(lengthLike: NumLike, range: [NumLike, N
13
13
  export declare function filterScriptByLenRange(valueLike?: ScriptLike, scriptLenRange?: [NumLike, NumLike]): boolean;
14
14
  export declare function filterCell(searchKeyLike: ClientCollectableSearchKeyLike, cellLike: CellLike): boolean;
15
15
  /**
16
- * A Least Recently Used (LRU) cache implemented using a Map.
17
- *
18
- * This class extends the built-in Map to provide an LRU cache with a fixed capacity.
19
- * When the cache is full, the least recently used entry is automatically evicted.
20
- *
21
- * @template K The type of the keys in the cache.
22
- * @template V The type of the values in the cache.
16
+ * A Map-like class that implements a "Least Recently Used" (LRU) cache policy.
17
+ * When the cache reaches its capacity, the least recently used item is removed.
18
+ * @public
23
19
  */
24
20
  export declare class MapLru<K, V> extends Map<K, V> {
25
21
  private readonly capacity;
22
+ private readonly lru;
26
23
  /**
27
- * Constructs a new MapLru instance.
28
- *
29
- * @param capacity The maximum number of entries the cache can hold. Must be a positive integer.
30
- * @throws {Error} If the capacity is not a positive integer.
24
+ * @param capacity - The maximum number of items to store in the cache. Must be a positive integer.
31
25
  */
32
26
  constructor(capacity: number);
33
27
  /**
34
- * Retrieves a value from the cache.
35
- *
36
- * If the key is present in the cache, the value is moved to the most-recently-used position.
37
- *
38
- * @param key The key of the value to retrieve.
39
- * @returns The value associated with the key, or undefined if the key is not present.
28
+ * Retrieves the value for a given key and marks it as recently used.
29
+ * @param key - The key of the element to retrieve.
30
+ * @returns The value associated with the key, or `undefined` if the key is not in the cache.
40
31
  */
41
32
  get(key: K): V | undefined;
42
33
  /**
43
- * Inserts a new value into the cache, or updates an existing value.
44
- *
45
- * If the key is already present in the cache, it is first deleted so that the re-insertion
46
- * moves it to the most-recently-used position.
47
- * If the cache is over capacity after the insertion, the least recently used entry is evicted.
48
- *
49
- * @param key The key of the value to insert or update.
50
- * @param value The value to associate with the key.
51
- * @returns This MapLru instance.
34
+ * Adds or updates a key-value pair in the cache and marks the key as recently used.
35
+ * If setting a new key causes the cache to exceed its capacity, the least recently used item is evicted.
36
+ * @param key - The key of the element to add or update.
37
+ * @param value - The value of the element to add or update.
38
+ * @returns The `MapLru` instance.
52
39
  */
53
40
  set(key: K, value: V): this;
41
+ /**
42
+ * Removes the specified element from the cache.
43
+ * @param key - The key of the element to remove.
44
+ * @returns `true` if an element in the `MapLru` object existed and has been removed, or `false` if the element does not exist.
45
+ */
46
+ delete(key: K): boolean;
47
+ /**
48
+ * Removes all key-value pairs from the cache.
49
+ */
50
+ clear(): void;
54
51
  }
55
52
  //# sourceMappingURL=memory.advanced.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory.advanced.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.advanced.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAU,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,8BAA8B,EAE/B,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,4BAA4B,QAA0B,CAAC;AAGpE,MAAM,MAAM,UAAU,GAClB;IACE,KAAK;IACL,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAAC,CAAC;CAC1E,GACD,CAAC,IAAI,EAAE,IAAI,CAAC,GACZ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAEtB,wBAAgB,UAAU,CACxB,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,OAAO,GAAG,SAAS,EAC/B,UAAU,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GACzC,OAAO,CAgBT;AAED,wBAAgB,YAAY,CAC1B,SAAS,EAAE,UAAU,GAAG,SAAS,EACjC,UAAU,EAAE,UAAU,GAAG,SAAS,EAClC,UAAU,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,GACzC,OAAO,CAkBT;AAED,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,OAAO,EACnB,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,GACpC,OAAO,CAQT;AAED,wBAAgB,sBAAsB,CACpC,SAAS,CAAC,EAAE,UAAU,EACtB,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAClC,OAAO,CAYT;AAED,wBAAgB,UAAU,CACxB,aAAa,E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G,SAAS,EACjC,UAAU,EAAE,UAAU,GAAG,SAAS,EAClC,UAAU,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,GACzC,OAAO,CAkBT;AAED,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,OAAO,EACnB,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,GACpC,OAAO,CAQT;AAED,wBAAgB,sBAAsB,CACpC,SAAS,CAAC,EAAE,UAAU,EACtB,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAClC,OAAO,CAYT;AAED,wBAAgB,UAAU,CACxB,aAAa,EAAE,8BAA8B,EAC7C,QAAQ,EAAE,QAAQ,GACjB,OAAO,CA4CT;AAED;;;;GAIG;AACH,qBAAa,MAAM,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAM7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IALrC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAwB;IAE5C;;OAEG;gBAC0B,QAAQ,EAAE,MAAM;IAQ7C;;;;OAIG;IACM,GAAG,CAAC,GAAG,EAAE,CAAC;IAWnB;;;;;;OAMG;IACM,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;IAc7B;;;;OAIG;IACM,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAShC;;OAEG;IACM,KAAK;CAIf"}
@@ -80,67 +80,70 @@ export function filterCell(searchKeyLike, cellLike) {
80
80
  return true;
81
81
  }
82
82
  /**
83
- * A Least Recently Used (LRU) cache implemented using a Map.
84
- *
85
- * This class extends the built-in Map to provide an LRU cache with a fixed capacity.
86
- * When the cache is full, the least recently used entry is automatically evicted.
87
- *
88
- * @template K The type of the keys in the cache.
89
- * @template V The type of the values in the cache.
83
+ * A Map-like class that implements a "Least Recently Used" (LRU) cache policy.
84
+ * When the cache reaches its capacity, the least recently used item is removed.
85
+ * @public
90
86
  */
91
87
  export class MapLru extends Map {
92
88
  /**
93
- * Constructs a new MapLru instance.
94
- *
95
- * @param capacity The maximum number of entries the cache can hold. Must be a positive integer.
96
- * @throws {Error} If the capacity is not a positive integer.
89
+ * @param capacity - The maximum number of items to store in the cache. Must be a positive integer.
97
90
  */
98
91
  constructor(capacity) {
99
92
  super();
100
93
  this.capacity = capacity;
94
+ this.lru = new Set();
101
95
  if (!Number.isInteger(capacity) || capacity < 1) {
102
96
  throw new Error("Capacity must be a positive integer");
103
97
  }
104
98
  }
105
99
  /**
106
- * Retrieves a value from the cache.
107
- *
108
- * If the key is present in the cache, the value is moved to the most-recently-used position.
109
- *
110
- * @param key The key of the value to retrieve.
111
- * @returns The value associated with the key, or undefined if the key is not present.
100
+ * Retrieves the value for a given key and marks it as recently used.
101
+ * @param key - The key of the element to retrieve.
102
+ * @returns The value associated with the key, or `undefined` if the key is not in the cache.
112
103
  */
113
104
  get(key) {
114
- // Check if the key exists. If not, return undefined.
115
105
  if (!super.has(key)) {
116
- return undefined;
106
+ return;
117
107
  }
118
- const value = super.get(key);
119
- // Move to most-recently-used position
120
- super.delete(key);
121
- super.set(key, value);
122
- return value;
108
+ this.lru.delete(key);
109
+ this.lru.add(key);
110
+ return super.get(key);
123
111
  }
124
112
  /**
125
- * Inserts a new value into the cache, or updates an existing value.
126
- *
127
- * If the key is already present in the cache, it is first deleted so that the re-insertion
128
- * moves it to the most-recently-used position.
129
- * If the cache is over capacity after the insertion, the least recently used entry is evicted.
130
- *
131
- * @param key The key of the value to insert or update.
132
- * @param value The value to associate with the key.
133
- * @returns This MapLru instance.
113
+ * Adds or updates a key-value pair in the cache and marks the key as recently used.
114
+ * If setting a new key causes the cache to exceed its capacity, the least recently used item is evicted.
115
+ * @param key - The key of the element to add or update.
116
+ * @param value - The value of the element to add or update.
117
+ * @returns The `MapLru` instance.
134
118
  */
135
119
  set(key, value) {
136
- // Delete and re-insert to move key to the end (most-recently-used)
137
- super.delete(key);
138
120
  super.set(key, value);
139
- // Evict oldest if over capacity
140
- if (super.size > this.capacity) {
141
- const oldestKey = super.keys().next().value;
142
- super.delete(oldestKey);
121
+ this.lru.delete(key);
122
+ this.lru.add(key);
123
+ // Evict the oldest entry if capacity is exceeded.
124
+ if (this.lru.size > this.capacity) {
125
+ const oldestKey = this.lru.keys().next().value;
126
+ this.delete(oldestKey);
143
127
  }
144
128
  return this;
145
129
  }
130
+ /**
131
+ * Removes the specified element from the cache.
132
+ * @param key - The key of the element to remove.
133
+ * @returns `true` if an element in the `MapLru` object existed and has been removed, or `false` if the element does not exist.
134
+ */
135
+ delete(key) {
136
+ if (!super.delete(key)) {
137
+ return false;
138
+ }
139
+ this.lru.delete(key);
140
+ return true;
141
+ }
142
+ /**
143
+ * Removes all key-value pairs from the cache.
144
+ */
145
+ clear() {
146
+ super.clear();
147
+ this.lru.clear();
148
+ }
146
149
  }
@@ -8,7 +8,6 @@ export declare class ClientCacheMemory extends ClientCache {
8
8
  private readonly maxCells;
9
9
  private readonly maxTxs;
10
10
  private readonly maxBlocks;
11
- private readonly confirmedBlockTime;
12
11
  /**
13
12
  * OutPoint => [isLive, Cell | OutPoint]
14
13
  */
@@ -25,14 +24,15 @@ export declare class ClientCacheMemory extends ClientCache {
25
24
  * Block Hash => Block Header / Full Block
26
25
  */
27
26
  private readonly knownBlocks;
27
+ private readonly confirmedBlockTime;
28
28
  /**
29
29
  * @param maxCells - Maximum number of cells to store in the cache. Defaults to 512.
30
30
  * @param maxTxs - Maximum number of transactions to store in the cache. Defaults to 256.
31
31
  * @param maxBlocks - Maximum number of blocks to store in the cache. Defaults to 128.
32
- * @param confirmedBlockTime - Time in milliseconds after which a block is considered confirmed.
33
- * Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
32
+ * @param confirmedBlockTimeLike - Time in milliseconds after which a block is considered confirmed.
33
+ * Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
34
34
  */
35
- constructor(maxCells?: number, maxTxs?: number, maxBlocks?: number, confirmedBlockTime?: bigint);
35
+ constructor(maxCells?: number, maxTxs?: number, maxBlocks?: number, confirmedBlockTimeLike?: NumLike);
36
36
  markUsableNoCache(...cellLikes: (CellLike | CellLike[])[]): Promise<void>;
37
37
  markUnusable(...outPointLikes: (OutPointLike | OutPointLike[])[]): Promise<void>;
38
38
  clear(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAY,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAW,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAgB,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,yBAAyB,EACzB,6BAA6B,EAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAQzC,qBAAa,iBAAkB,SAAQ,WAAW;IAgC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IAlCrC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;IAEnD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA4C;IAE9E;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAsB;IAEvD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAG1B;IAEF;;;;;;OAMG;gBAEgB,QAAQ,SAAM,EACd,MAAM,SAAM,EACZ,SAAS,SAAM,E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AS,CAAC;IAWnE,gBAAgB,CACpB,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAUnC,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO;CAGvD"}
@@ -9,19 +9,19 @@ export class ClientCacheMemory extends ClientCache {
9
9
  * @param maxCells - Maximum number of cells to store in the cache. Defaults to 512.
10
10
  * @param maxTxs - Maximum number of transactions to store in the cache. Defaults to 256.
11
11
  * @param maxBlocks - Maximum number of blocks to store in the cache. Defaults to 128.
12
- * @param confirmedBlockTime - Time in milliseconds after which a block is considered confirmed.
13
- * Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
12
+ * @param confirmedBlockTimeLike - Time in milliseconds after which a block is considered confirmed.
13
+ * Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
14
14
  */
15
- constructor(maxCells = 512, maxTxs = 256, maxBlocks = 128, confirmedBlockTime = DEFAULT_CONFIRMED_BLOCK_TIME) {
15
+ constructor(maxCells = 512, maxTxs = 256, maxBlocks = 128, confirmedBlockTimeLike = DEFAULT_CONFIRMED_BLOCK_TIME) {
16
16
  super();
17
17
  this.maxCells = maxCells;
18
18
  this.maxTxs = maxTxs;
19
19
  this.maxBlocks = maxBlocks;
20
- this.confirmedBlockTime = confirmedBlockTime;
21
20
  this.cells = new MapLru(this.maxCells);
22
21
  this.knownTransactions = new MapLru(this.maxTxs);
23
22
  this.knownBlockHashes = new MapLru(this.maxBlocks);
24
23
  this.knownBlocks = new MapLru(this.maxBlocks);
24
+ this.confirmedBlockTime = numFrom(confirmedBlockTimeLike);
25
25
  }
26
26
  async markUsableNoCache(...cellLikes) {
27
27
  cellLikes.flat().forEach((cellLike) => {
@@ -102,11 +102,11 @@ export declare abstract class Entity {
102
102
  * }
103
103
  * ```
104
104
  */
105
- export declare function codec<Encodable, TypeLike extends Encodable, Decoded extends TypeLike, Type extends object & TypeLike, ConstructorType extends Constructor<Type> & {
105
+ export declare function codec<Encodable, TypeLike extends Encodable, Decoded extends TypeLike>(codec: Codec<Encodable, Decoded>): <Type extends TypeLike, ConstructorType extends Constructor<Type> & {
106
106
  from(decoded: TypeLike): Type;
107
107
  byteLength?: number;
108
108
  encode(encodable: TypeLike): Bytes;
109
- decode(bytesLike: BytesLike): TypeLike;
109
+ decode(bytesLike: BytesLike): Type;
110
110
  fromBytes(bytes: BytesLike): Type;
111
- }>(codec: Codec<Encodable, Decoded>): (Constructor: ConstructorType) => ConstructorType;
111
+ }>(Constructor: ConstructorType, ..._: unknown[]) => ConstructorType;
112
112
  //# sourceMappingURL=entity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../src/molecule/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAW,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;GAGG;AACH,8BAAsB,MAAM;IAC1B;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,WAAW;QA6D1C;;;;WAIG;mBACQ,KAAK;QAMhB;;;;WAIG;iBACM,OAAO;QAMhB;;;;;WAKG;kBACO,WAAW,GAAG,OAAO;QAe/B;;;;WAIG;gBACK,GAAG;;QA3GX;;;;WAIG;qBACiB,MAAM;QAC1B;;;;;;;WAOG;kBACc,WAAW,GAAG,KAAK;QAKpC;;;;;;;WAOG;kBACc,SAAS,GAAG,OAAO;QAMpC;;;;;;;WAOG;0BACsB,SAAS,GAAG,OAAO;QAM5C;;;;;;;WAOG;gBACY,WAAW,GAAG,OAAO;;IA4DxC,QAAQ,CAAC,OAAO,IAAI,KAAK;IACzB,QAAQ,CAAC,IAAI,IAAI,GAAG;I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QAMpC;;;;;;;WAOG;0BACsB,SAAS,GAAG,OAAO;QAM5C;;;;;;;WAOG;gBACY,WAAW,GAAG,OAAO;;IA4DxC,QAAQ,CAAC,OAAO,IAAI,KAAK;IACzB,QAAQ,CAAC,IAAI,IAAI,GAAG;IACpB,QAAQ,CAAC,KAAK,IAAI,MAAM;CACzB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CACnB,SAAS,EACT,QAAQ,SAAS,SAAS,EAC1B,OAAO,SAAS,QAAQ,EACxB,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,IAE9B,IAAI,SAAS,QAAQ,EACrB,eAAe,SAAS,WAAW,CAAC,IAAI,CAAC,GAAG;IAC1C,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,SAAS,EAAE,QAAQ,GAAG,KAAK,CAAC;IACnC,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IACnC,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACnC,EACD,aAAa,eAAe,EAAE,GAAG,GAAG,OAAO,EAAE,qBAchD"}
@@ -115,7 +115,7 @@ export class Entity {
115
115
  * ```
116
116
  */
117
117
  export function codec(codec) {
118
- return function (Constructor) {
118
+ return function (Constructor, ..._) {
119
119
  Constructor.byteLength = codec.byteLength;
120
120
  Constructor.encode = function (encodable) {
121
121
  return codec.encode(encodable);
@@ -1,5 +1,5 @@
1
1
  import { schnorr } from "@noble/curves/secp256k1";
2
- import { sha256 } from "@noble/hashes/sha256";
2
+ import { sha256 } from "@noble/hashes/sha2.js";
3
3
  import { bech32 } from "bech32";
4
4
  import { bytesFrom } from "../../bytes/index.js";
5
5
  import { hexFrom } from "../../hex/index.js";
@@ -43,11 +43,11 @@ export function nostrEventHash(event) {
43
43
  }
44
44
  export function verifyMessageNostrEvent(message, signature, address) {
45
45
  const { words } = bech32.decode(address);
46
- const publicKey = hexFrom(bech32.fromWords(words)).slice(2);
46
+ const pubkey = hexFrom(bech32.fromWords(words)).slice(2);
47
47
  const event = buildNostrEventFromMessage(message);
48
- const eventHash = nostrEventHash(event);
48
+ const eventHash = nostrEventHash({ ...event, pubkey });
49
49
  try {
50
- return schnorr.verify(hexFrom(signature).slice(2), eventHash, publicKey);
50
+ return schnorr.verify(hexFrom(signature).slice(2), eventHash, pubkey);
51
51
  }
52
52
  catch (_) {
53
53
  return false;
@@ -13,43 +13,40 @@ export declare function filterNumByRange(lengthLike: NumLike, range: [NumLike, N
13
13
  export declare function filterScriptByLenRange(valueLike?: ScriptLike, scriptLenRange?: [NumLike, NumLike]): boolean;
14
14
  export declare function filterCell(searchKeyLike: ClientCollectableSearchKeyLike, cellLike: CellLike): boolean;
15
15
  /**
16
- * A Least Recently Used (LRU) cache implemented using a Map.
17
- *
18
- * This class extends the built-in Map to provide an LRU cache with a fixed capacity.
19
- * When the cache is full, the least recently used entry is automatically evicted.
20
- *
21
- * @template K The type of the keys in the cache.
22
- * @template V The type of the values in the cache.
16
+ * A Map-like class that implements a "Least Recently Used" (LRU) cache policy.
17
+ * When the cache reaches its capacity, the least recently used item is removed.
18
+ * @public
23
19
  */
24
20
  export declare class MapLru<K, V> extends Map<K, V> {
25
21
  private readonly capacity;
22
+ private readonly lru;
26
23
  /**
27
- * Constructs a new MapLru instance.
28
- *
29
- * @param capacity The maximum number of entries the cache can hold. Must be a positive integer.
30
- * @throws {Error} If the capacity is not a positive integer.
24
+ * @param capacity - The maximum number of items to store in the cache. Must be a positive integer.
31
25
  */
32
26
  constructor(capacity: number);
33
27
  /**
34
- * Retrieves a value from the cache.
35
- *
36
- * If the key is present in the cache, the value is moved to the most-recently-used position.
37
- *
38
- * @param key The key of the value to retrieve.
39
- * @returns The value associated with the key, or undefined if the key is not present.
28
+ * Retrieves the value for a given key and marks it as recently used.
29
+ * @param key - The key of the element to retrieve.
30
+ * @returns The value associated with the key, or `undefined` if the key is not in the cache.
40
31
  */
41
32
  get(key: K): V | undefined;
42
33
  /**
43
- * Inserts a new value into the cache, or updates an existing value.
44
- *
45
- * If the key is already present in the cache, it is first deleted so that the re-insertion
46
- * moves it to the most-recently-used position.
47
- * If the cache is over capacity after the insertion, the least recently used entry is evicted.
48
- *
49
- * @param key The key of the value to insert or update.
50
- * @param value The value to associate with the key.
51
- * @returns This MapLru instance.
34
+ * Adds or updates a key-value pair in the cache and marks the key as recently used.
35
+ * If setting a new key causes the cache to exceed its capacity, the least recently used item is evicted.
36
+ * @param key - The key of the element to add or update.
37
+ * @param value - The value of the element to add or update.
38
+ * @returns The `MapLru` instance.
52
39
  */
53
40
  set(key: K, value: V): this;
41
+ /**
42
+ * Removes the specified element from the cache.
43
+ * @param key - The key of the element to remove.
44
+ * @returns `true` if an element in the `MapLru` object existed and has been removed, or `false` if the element does not exist.
45
+ */
46
+ delete(key: K): boolean;
47
+ /**
48
+ * Removes all key-value pairs from the cache.
49
+ */
50
+ clear(): void;
54
51
  }
55
52
  //# sourceMappingURL=memory.advanced.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory.advanced.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.advanced.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAU,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,8BAA8B,EAE/B,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,4BAA4B,QAA0B,CAAC;AAGpE,MAAM,MAAM,UAAU,GAClB;IACE,KAAK;IACL,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAAC,CAAC;CAC1E,GACD,CAAC,IAAI,EAAE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AAQ,CAAC,QAAQ;IALrC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAwB;IAE5C;;OAEG;gBAC0B,QAAQ,EAAE,MAAM;IAQ7C;;;;OAIG;IACM,GAAG,CAAC,GAAG,EAAE,CAAC;IAWnB;;;;;;OAMG;IACM,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;IAc7B;;;;OAIG;IACM,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAShC;;OAEG;IACM,KAAK;CAIf"}
@@ -88,68 +88,71 @@ function filterCell(searchKeyLike, cellLike) {
88
88
  return true;
89
89
  }
90
90
  /**
91
- * A Least Recently Used (LRU) cache implemented using a Map.
92
- *
93
- * This class extends the built-in Map to provide an LRU cache with a fixed capacity.
94
- * When the cache is full, the least recently used entry is automatically evicted.
95
- *
96
- * @template K The type of the keys in the cache.
97
- * @template V The type of the values in the cache.
91
+ * A Map-like class that implements a "Least Recently Used" (LRU) cache policy.
92
+ * When the cache reaches its capacity, the least recently used item is removed.
93
+ * @public
98
94
  */
99
95
  class MapLru extends Map {
100
96
  /**
101
- * Constructs a new MapLru instance.
102
- *
103
- * @param capacity The maximum number of entries the cache can hold. Must be a positive integer.
104
- * @throws {Error} If the capacity is not a positive integer.
97
+ * @param capacity - The maximum number of items to store in the cache. Must be a positive integer.
105
98
  */
106
99
  constructor(capacity) {
107
100
  super();
108
101
  this.capacity = capacity;
102
+ this.lru = new Set();
109
103
  if (!Number.isInteger(capacity) || capacity < 1) {
110
104
  throw new Error("Capacity must be a positive integer");
111
105
  }
112
106
  }
113
107
  /**
114
- * Retrieves a value from the cache.
115
- *
116
- * If the key is present in the cache, the value is moved to the most-recently-used position.
117
- *
118
- * @param key The key of the value to retrieve.
119
- * @returns The value associated with the key, or undefined if the key is not present.
108
+ * Retrieves the value for a given key and marks it as recently used.
109
+ * @param key - The key of the element to retrieve.
110
+ * @returns The value associated with the key, or `undefined` if the key is not in the cache.
120
111
  */
121
112
  get(key) {
122
- // Check if the key exists. If not, return undefined.
123
113
  if (!super.has(key)) {
124
- return undefined;
114
+ return;
125
115
  }
126
- const value = super.get(key);
127
- // Move to most-recently-used position
128
- super.delete(key);
129
- super.set(key, value);
130
- return value;
116
+ this.lru.delete(key);
117
+ this.lru.add(key);
118
+ return super.get(key);
131
119
  }
132
120
  /**
133
- * Inserts a new value into the cache, or updates an existing value.
134
- *
135
- * If the key is already present in the cache, it is first deleted so that the re-insertion
136
- * moves it to the most-recently-used position.
137
- * If the cache is over capacity after the insertion, the least recently used entry is evicted.
138
- *
139
- * @param key The key of the value to insert or update.
140
- * @param value The value to associate with the key.
141
- * @returns This MapLru instance.
121
+ * Adds or updates a key-value pair in the cache and marks the key as recently used.
122
+ * If setting a new key causes the cache to exceed its capacity, the least recently used item is evicted.
123
+ * @param key - The key of the element to add or update.
124
+ * @param value - The value of the element to add or update.
125
+ * @returns The `MapLru` instance.
142
126
  */
143
127
  set(key, value) {
144
- // Delete and re-insert to move key to the end (most-recently-used)
145
- super.delete(key);
146
128
  super.set(key, value);
147
- // Evict oldest if over capacity
148
- if (super.size > this.capacity) {
149
- const oldestKey = super.keys().next().value;
150
- super.delete(oldestKey);
129
+ this.lru.delete(key);
130
+ this.lru.add(key);
131
+ // Evict the oldest entry if capacity is exceeded.
132
+ if (this.lru.size > this.capacity) {
133
+ const oldestKey = this.lru.keys().next().value;
134
+ this.delete(oldestKey);
151
135
  }
152
136
  return this;
153
137
  }
138
+ /**
139
+ * Removes the specified element from the cache.
140
+ * @param key - The key of the element to remove.
141
+ * @returns `true` if an element in the `MapLru` object existed and has been removed, or `false` if the element does not exist.
142
+ */
143
+ delete(key) {
144
+ if (!super.delete(key)) {
145
+ return false;
146
+ }
147
+ this.lru.delete(key);
148
+ return true;
149
+ }
150
+ /**
151
+ * Removes all key-value pairs from the cache.
152
+ */
153
+ clear() {
154
+ super.clear();
155
+ this.lru.clear();
156
+ }
154
157
  }
155
158
  exports.MapLru = MapLru;
@@ -8,7 +8,6 @@ export declare class ClientCacheMemory extends ClientCache {
8
8
  private readonly maxCells;
9
9
  private readonly maxTxs;
10
10
  private readonly maxBlocks;
11
- private readonly confirmedBlockTime;
12
11
  /**
13
12
  * OutPoint => [isLive, Cell | OutPoint]
14
13
  */
@@ -25,14 +24,15 @@ export declare class ClientCacheMemory extends ClientCache {
25
24
  * Block Hash => Block Header / Full Block
26
25
  */
27
26
  private readonly knownBlocks;
27
+ private readonly confirmedBlockTime;
28
28
  /**
29
29
  * @param maxCells - Maximum number of cells to store in the cache. Defaults to 512.
30
30
  * @param maxTxs - Maximum number of transactions to store in the cache. Defaults to 256.
31
31
  * @param maxBlocks - Maximum number of blocks to store in the cache. Defaults to 128.
32
- * @param confirmedBlockTime - Time in milliseconds after which a block is considered confirmed.
33
- * Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
32
+ * @param confirmedBlockTimeLike - Time in milliseconds after which a block is considered confirmed.
33
+ * Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
34
34
  */
35
- constructor(maxCells?: number, maxTxs?: number, maxBlocks?: number, confirmedBlockTime?: bigint);
35
+ constructor(maxCells?: number, maxTxs?: number, maxBlocks?: number, confirmedBlockTimeLike?: NumLike);
36
36
  markUsableNoCache(...cellLikes: (CellLike | CellLike[])[]): Promise<void>;
37
37
  markUnusable(...outPointLikes: (OutPointLike | OutPointLike[])[]): Promise<void>;
38
38
  clear(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAY,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAW,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAgB,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AA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AS,CAAC;IAS9D,0BAA0B,CAC9B,GAAG,YAAY,EAAE,CACb,6BAA6B,GAC7B,6BAA6B,EAAE,CAClC,EAAE,GACF,OAAO,CAAC,IAAI,CAAC;IAMV,sBAAsB,CAC1B,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC;IAK3C,aAAa,CACjB,GAAG,OAAO,EAAE,CAAC,qBAAqB,GAAG,qBAAqB,EAAE,CAAC,EAAE,GAC9D,OAAO,CAAC,IAAI,CAAC;IAaV,eAAe,CACnB,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAQnC,iBAAiB,CACrB,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAUnC,YAAY,CAChB,GAAG,MAAM,EAAE,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,EAAE,GACjD,OAAO,CAAC,IAAI,CAAC;IAQV,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAWnE,gBAAgB,CACpB,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAUnC,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO;CAGvD"}
@@ -12,19 +12,19 @@ class ClientCacheMemory extends cache_js_1.ClientCache {
12
12
  * @param maxCells - Maximum number of cells to store in the cache. Defaults to 512.
13
13
  * @param maxTxs - Maximum number of transactions to store in the cache. Defaults to 256.
14
14
  * @param maxBlocks - Maximum number of blocks to store in the cache. Defaults to 128.
15
- * @param confirmedBlockTime - Time in milliseconds after which a block is considered confirmed.
16
- * Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
15
+ * @param confirmedBlockTimeLike - Time in milliseconds after which a block is considered confirmed.
16
+ * Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
17
17
  */
18
- constructor(maxCells = 512, maxTxs = 256, maxBlocks = 128, confirmedBlockTime = memory_advanced_js_1.DEFAULT_CONFIRMED_BLOCK_TIME) {
18
+ constructor(maxCells = 512, maxTxs = 256, maxBlocks = 128, confirmedBlockTimeLike = memory_advanced_js_1.DEFAULT_CONFIRMED_BLOCK_TIME) {
19
19
  super();
20
20
  this.maxCells = maxCells;
21
21
  this.maxTxs = maxTxs;
22
22
  this.maxBlocks = maxBlocks;
23
- this.confirmedBlockTime = confirmedBlockTime;
24
23
  this.cells = new memory_advanced_js_1.MapLru(this.maxCells);
25
24
  this.knownTransactions = new memory_advanced_js_1.MapLru(this.maxTxs);
26
25
  this.knownBlockHashes = new memory_advanced_js_1.MapLru(this.maxBlocks);
27
26
  this.knownBlocks = new memory_advanced_js_1.MapLru(this.maxBlocks);
27
+ this.confirmedBlockTime = (0, index_js_3.numFrom)(confirmedBlockTimeLike);
28
28
  }
29
29
  async markUsableNoCache(...cellLikes) {
30
30
  cellLikes.flat().forEach((cellLike) => {
@@ -102,11 +102,11 @@ export declare abstract class Entity {
102
102
  * }
103
103
  * ```
104
104
  */
105
- export declare function codec<Encodable, TypeLike extends Encodable, Decoded extends TypeLike, Type extends object & TypeLike, ConstructorType extends Constructor<Type> & {
105
+ export declare function codec<Encodable, TypeLike extends Encodable, Decoded extends TypeLike>(codec: Codec<Encodable, Decoded>): <Type extends TypeLike, ConstructorType extends Constructor<Type> & {
106
106
  from(decoded: TypeLike): Type;
107
107
  byteLength?: number;
108
108
  encode(encodable: TypeLike): Bytes;
109
- decode(bytesLike: BytesLike): TypeLike;
109
+ decode(bytesLike: BytesLike): Type;
110
110
  fromBytes(bytes: BytesLike): Type;
111
- }>(codec: Codec<Encodable, Decoded>): (Constructor: ConstructorType) => ConstructorType;
111
+ }>(Constructor: ConstructorType, ..._: unknown[]) => ConstructorType;
112
112
  //# sourceMappingURL=entity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../src/mol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,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,SAAS,EAAE,QAAQ,GAAG,KAAK,CAAC;IACnC,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IACnC,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACnC,EACD,aAAa,eAAe,EAAE,GAAG,GAAG,OAAO,EAAE,qBAchD"}
@@ -120,7 +120,7 @@ exports.Entity = Entity;
120
120
  * ```
121
121
  */
122
122
  function codec(codec) {
123
- return function (Constructor) {
123
+ return function (Constructor, ..._) {
124
124
  Constructor.byteLength = codec.byteLength;
125
125
  Constructor.encode = function (encodable) {
126
126
  return codec.encode(encodable);
@@ -4,7 +4,7 @@ exports.buildNostrEventFromMessage = buildNostrEventFromMessage;
4
4
  exports.nostrEventHash = nostrEventHash;
5
5
  exports.verifyMessageNostrEvent = verifyMessageNostrEvent;
6
6
  const secp256k1_1 = require("@noble/curves/secp256k1");
7
- const sha256_1 = require("@noble/hashes/sha256");
7
+ const sha2_js_1 = require("@noble/hashes/sha2.js");
8
8
  const bech32_1 = require("bech32");
9
9
  const index_js_1 = require("../../bytes/index.js");
10
10
  const index_js_2 = require("../../hex/index.js");
@@ -44,15 +44,15 @@ function nostrEventHash(event) {
44
44
  event.tags,
45
45
  event.content,
46
46
  ]);
47
- return (0, sha256_1.sha256)((0, index_js_1.bytesFrom)(serialized, "utf8"));
47
+ return (0, sha2_js_1.sha256)((0, index_js_1.bytesFrom)(serialized, "utf8"));
48
48
  }
49
49
  function verifyMessageNostrEvent(message, signature, address) {
50
50
  const { words } = bech32_1.bech32.decode(address);
51
- const publicKey = (0, index_js_2.hexFrom)(bech32_1.bech32.fromWords(words)).slice(2);
51
+ const pubkey = (0, index_js_2.hexFrom)(bech32_1.bech32.fromWords(words)).slice(2);
52
52
  const event = buildNostrEventFromMessage(message);
53
- const eventHash = nostrEventHash(event);
53
+ const eventHash = nostrEventHash({ ...event, pubkey });
54
54
  try {
55
- return secp256k1_1.schnorr.verify((0, index_js_2.hexFrom)(signature).slice(2), eventHash, publicKey);
55
+ return secp256k1_1.schnorr.verify((0, index_js_2.hexFrom)(signature).slice(2), eventHash, pubkey);
56
56
  }
57
57
  catch (_) {
58
58
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/core",
3
- "version": "1.11.3",
3
+ "version": "1.11.5",
4
4
  "description": "Core of CCC - CKBer's Codebase",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -145,73 +145,80 @@ export function filterCell(
145
145
  }
146
146
 
147
147
  /**
148
- * A Least Recently Used (LRU) cache implemented using a Map.
149
- *
150
- * This class extends the built-in Map to provide an LRU cache with a fixed capacity.
151
- * When the cache is full, the least recently used entry is automatically evicted.
152
- *
153
- * @template K The type of the keys in the cache.
154
- * @template V The type of the values in the cache.
148
+ * A Map-like class that implements a "Least Recently Used" (LRU) cache policy.
149
+ * When the cache reaches its capacity, the least recently used item is removed.
150
+ * @public
155
151
  */
156
152
  export class MapLru<K, V> extends Map<K, V> {
153
+ private readonly lru: Set<K> = new Set<K>();
154
+
157
155
  /**
158
- * Constructs a new MapLru instance.
159
- *
160
- * @param capacity The maximum number of entries the cache can hold. Must be a positive integer.
161
- * @throws {Error} If the capacity is not a positive integer.
156
+ * @param capacity - The maximum number of items to store in the cache. Must be a positive integer.
162
157
  */
163
158
  constructor(private readonly capacity: number) {
164
159
  super();
160
+
165
161
  if (!Number.isInteger(capacity) || capacity < 1) {
166
162
  throw new Error("Capacity must be a positive integer");
167
163
  }
168
164
  }
169
165
 
170
166
  /**
171
- * Retrieves a value from the cache.
172
- *
173
- * If the key is present in the cache, the value is moved to the most-recently-used position.
174
- *
175
- * @param key The key of the value to retrieve.
176
- * @returns The value associated with the key, or undefined if the key is not present.
167
+ * Retrieves the value for a given key and marks it as recently used.
168
+ * @param key - The key of the element to retrieve.
169
+ * @returns The value associated with the key, or `undefined` if the key is not in the cache.
177
170
  */
178
- override get(key: K): V | undefined {
179
- // Check if the key exists. If not, return undefined.
171
+ override get(key: K) {
180
172
  if (!super.has(key)) {
181
- return undefined;
173
+ return;
182
174
  }
183
175
 
184
- const value = super.get(key) as V;
176
+ this.lru.delete(key);
177
+ this.lru.add(key);
185
178
 
186
- // Move to most-recently-used position
187
- super.delete(key);
188
- super.set(key, value);
189
-
190
- return value;
179
+ return super.get(key);
191
180
  }
192
181
 
193
182
  /**
194
- * Inserts a new value into the cache, or updates an existing value.
195
- *
196
- * If the key is already present in the cache, it is first deleted so that the re-insertion
197
- * moves it to the most-recently-used position.
198
- * If the cache is over capacity after the insertion, the least recently used entry is evicted.
199
- *
200
- * @param key The key of the value to insert or update.
201
- * @param value The value to associate with the key.
202
- * @returns This MapLru instance.
183
+ * Adds or updates a key-value pair in the cache and marks the key as recently used.
184
+ * If setting a new key causes the cache to exceed its capacity, the least recently used item is evicted.
185
+ * @param key - The key of the element to add or update.
186
+ * @param value - The value of the element to add or update.
187
+ * @returns The `MapLru` instance.
203
188
  */
204
- override set(key: K, value: V): this {
205
- // Delete and re-insert to move key to the end (most-recently-used)
206
- super.delete(key);
189
+ override set(key: K, value: V) {
207
190
  super.set(key, value);
208
191
 
209
- // Evict oldest if over capacity
210
- if (super.size > this.capacity) {
211
- const oldestKey = super.keys().next().value!;
212
- super.delete(oldestKey);
213
- }
192
+ this.lru.delete(key);
193
+ this.lru.add(key);
214
194
 
195
+ // Evict the oldest entry if capacity is exceeded.
196
+ if (this.lru.size > this.capacity) {
197
+ const oldestKey = this.lru.keys().next().value!;
198
+ this.delete(oldestKey);
199
+ }
215
200
  return this;
216
201
  }
202
+
203
+ /**
204
+ * Removes the specified element from the cache.
205
+ * @param key - The key of the element to remove.
206
+ * @returns `true` if an element in the `MapLru` object existed and has been removed, or `false` if the element does not exist.
207
+ */
208
+ override delete(key: K): boolean {
209
+ if (!super.delete(key)) {
210
+ return false;
211
+ }
212
+
213
+ this.lru.delete(key);
214
+ return true;
215
+ }
216
+
217
+ /**
218
+ * Removes all key-value pairs from the cache.
219
+ */
220
+ override clear() {
221
+ super.clear();
222
+ this.lru.clear();
223
+ }
217
224
  }
@@ -42,18 +42,20 @@ export class ClientCacheMemory extends ClientCache {
42
42
  Pick<ClientBlock, "header"> | ClientBlock
43
43
  >;
44
44
 
45
+ private readonly confirmedBlockTime;
46
+
45
47
  /**
46
48
  * @param maxCells - Maximum number of cells to store in the cache. Defaults to 512.
47
49
  * @param maxTxs - Maximum number of transactions to store in the cache. Defaults to 256.
48
50
  * @param maxBlocks - Maximum number of blocks to store in the cache. Defaults to 128.
49
- * @param confirmedBlockTime - Time in milliseconds after which a block is considered confirmed.
50
- * Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
51
+ * @param confirmedBlockTimeLike - Time in milliseconds after which a block is considered confirmed.
52
+ * Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
51
53
  */
52
54
  constructor(
53
55
  private readonly maxCells = 512,
54
56
  private readonly maxTxs = 256,
55
57
  private readonly maxBlocks = 128,
56
- private readonly confirmedBlockTime = DEFAULT_CONFIRMED_BLOCK_TIME,
58
+ confirmedBlockTimeLike: NumLike = DEFAULT_CONFIRMED_BLOCK_TIME,
57
59
  ) {
58
60
  super();
59
61
 
@@ -66,6 +68,8 @@ export class ClientCacheMemory extends ClientCache {
66
68
  string,
67
69
  Pick<ClientBlock, "header"> | ClientBlock
68
70
  >(this.maxBlocks);
71
+
72
+ this.confirmedBlockTime = numFrom(confirmedBlockTimeLike);
69
73
  }
70
74
 
71
75
  async markUsableNoCache(
@@ -156,16 +156,17 @@ export function codec<
156
156
  Encodable,
157
157
  TypeLike extends Encodable,
158
158
  Decoded extends TypeLike,
159
- Type extends object & TypeLike,
160
- ConstructorType extends Constructor<Type> & {
161
- from(decoded: TypeLike): Type;
162
- byteLength?: number;
163
- encode(encodable: TypeLike): Bytes;
164
- decode(bytesLike: BytesLike): TypeLike;
165
- fromBytes(bytes: BytesLike): Type;
166
- },
167
159
  >(codec: Codec<Encodable, Decoded>) {
168
- return function (Constructor: ConstructorType) {
160
+ return function <
161
+ Type extends TypeLike,
162
+ ConstructorType extends Constructor<Type> & {
163
+ from(decoded: TypeLike): Type;
164
+ byteLength?: number;
165
+ encode(encodable: TypeLike): Bytes;
166
+ decode(bytesLike: BytesLike): Type;
167
+ fromBytes(bytes: BytesLike): Type;
168
+ },
169
+ >(Constructor: ConstructorType, ..._: unknown[]) {
169
170
  Constructor.byteLength = codec.byteLength;
170
171
  Constructor.encode = function (encodable: TypeLike) {
171
172
  return codec.encode(encodable);
@@ -1,5 +1,5 @@
1
1
  import { schnorr } from "@noble/curves/secp256k1";
2
- import { sha256 } from "@noble/hashes/sha256";
2
+ import { sha256 } from "@noble/hashes/sha2.js";
3
3
  import { bech32 } from "bech32";
4
4
  import { Bytes, BytesLike, bytesFrom } from "../../bytes/index.js";
5
5
  import { hexFrom } from "../../hex/index.js";
@@ -59,13 +59,13 @@ export function verifyMessageNostrEvent(
59
59
  address: string,
60
60
  ): boolean {
61
61
  const { words } = bech32.decode(address);
62
- const publicKey = hexFrom(bech32.fromWords(words)).slice(2);
62
+ const pubkey = hexFrom(bech32.fromWords(words)).slice(2);
63
63
 
64
64
  const event = buildNostrEventFromMessage(message);
65
- const eventHash = nostrEventHash(event);
65
+ const eventHash = nostrEventHash({ ...event, pubkey });
66
66
 
67
67
  try {
68
- return schnorr.verify(hexFrom(signature).slice(2), eventHash, publicKey);
68
+ return schnorr.verify(hexFrom(signature).slice(2), eventHash, pubkey);
69
69
  } catch (_) {
70
70
  return false;
71
71
  }
File without changes