@leofcoin/codec-format-interface 1.7.13 → 1.7.15

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 vandeurenglenn
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2022 vandeurenglenn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # codec-format-interface
2
-
3
- ## usage
2
+
3
+ TypeScript/JavaScript interface for defining and working with codec formats.
4
+
5
+ ## Usage
4
6
 
5
7
  ```js
6
8
  import FormatInterface from '@leofcoin/codec-format-interface'
@@ -14,19 +16,42 @@ class MyFormat extends FormatInterface {
14
16
  }
15
17
 
16
18
  constructor(data) {
17
- super(data, { name: 'my-format', hashFormat = 'bs32' })
19
+ super(data, { name: 'my-format', hashFormat: 'bs32' })
18
20
  }
19
21
  }
20
-
21
22
  ```
22
23
 
23
- ## build for browser
24
- ### rollup
24
+ ## API
25
+
26
+ - **FormatInterface**: Base class for creating custom codec formats.
27
+ - `constructor(data, options)`: Initialize with data and options.
28
+ - `proto`: Getter for the protocol definition.
29
+ - `toBs58()`, `toBs32()`, `hash()`: Encoding and hashing utilities.
30
+
31
+ ## Build for Browser
32
+
33
+ ### Rollup Example
25
34
  ```js
26
35
  import resolve from '@rollup/plugin-node-resolve'
27
- ...
36
+ import typescript from '@rollup/plugin-typescript'
37
+
38
+ export default {
39
+ input: 'src/index.ts',
40
+ output: {
41
+ dir: 'exports',
42
+ format: 'es'
43
+ },
28
44
  plugins: [
29
- resolve()
45
+ resolve(),
46
+ typescript()
30
47
  ]
31
- ...
32
- ```
48
+ }
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
54
+
55
+ ## License
56
+
57
+ MIT
@@ -0,0 +1,8 @@
1
+ # Exports Directory
2
+
3
+ This directory contains the public API surface of the package. Only files in this directory are considered part of the public API and are safe to import from other projects.
4
+
5
+ - `index.js` / `index.d.ts`: Main entry point
6
+ - Other files: Specific interfaces and codecs
7
+
8
+ Do not import from internal `src/` files directly.
@@ -14,6 +14,10 @@ export default class BasicInterface {
14
14
  get proto(): object;
15
15
  decode(encoded?: Uint8Array): Object;
16
16
  encode(decoded?: object): Uint8Array;
17
+ static _protoCache: WeakMap<object, {
18
+ keys: string[];
19
+ values: any[];
20
+ }>;
17
21
  protoEncode(data: object): Uint8Array;
18
22
  protoDecode(data: Uint8Array): object;
19
23
  isHex(string: string): boolean;
@@ -4,8 +4,44 @@ import isHex from '@vandeurenglenn/is-hex';
4
4
  import proto from '@vandeurenglenn/proto-array';
5
5
  import { fromBase58, fromHex, toHex, toBase32, toBase58 } from '@vandeurenglenn/typed-array-utils';
6
6
 
7
- const jsonStringifyBigInt = (key, value) => typeof value === 'bigint' ? { $bigint: value.toString() } : value;
8
- const jsonParseBigInt = (key, value) => typeof value === 'object' && value.$bigint ? BigInt(value.$bigint) : value;
7
+ const BASE64_CHUNK_SIZE = 0x8000;
8
+ const uint8ArrayToBase64 = (value) => {
9
+ if (typeof Buffer !== 'undefined')
10
+ return Buffer.from(value).toString('base64');
11
+ let binary = '';
12
+ for (let offset = 0; offset < value.length; offset += BASE64_CHUNK_SIZE) {
13
+ const slice = value.subarray(offset, offset + BASE64_CHUNK_SIZE);
14
+ binary += String.fromCharCode(...slice);
15
+ }
16
+ return btoa(binary);
17
+ };
18
+ const base64ToUint8Array = (value) => {
19
+ if (typeof Buffer !== 'undefined')
20
+ return new Uint8Array(Buffer.from(value, 'base64'));
21
+ const binary = atob(value);
22
+ const output = new Uint8Array(binary.length);
23
+ for (let i = 0; i < binary.length; i++)
24
+ output[i] = binary.charCodeAt(i);
25
+ return output;
26
+ };
27
+ const jsonStringifyBigInt = (key, value) => {
28
+ if (typeof value === 'bigint')
29
+ return { $bigint: value.toString() };
30
+ if (value instanceof Uint8Array)
31
+ return { $uint8array: uint8ArrayToBase64(value) };
32
+ return value;
33
+ };
34
+ const jsonParseBigInt = (key, value) => {
35
+ if (typeof value === 'object' && value) {
36
+ if (value.$bigint)
37
+ return BigInt(value.$bigint);
38
+ if (value.$uint8array)
39
+ return base64ToUint8Array(value.$uint8array);
40
+ }
41
+ return value;
42
+ };
43
+ const _textEncoder = new TextEncoder();
44
+ const _textDecoder = new TextDecoder();
9
45
  class BasicInterface {
10
46
  #encoded;
11
47
  #decoded;
@@ -40,20 +76,49 @@ class BasicInterface {
40
76
  }
41
77
  decode(encoded) {
42
78
  encoded = encoded || this.encoded;
43
- return new Object();
79
+ // Example: decode as JSON if possible (override in subclass)
80
+ try {
81
+ return JSON.parse(_textDecoder.decode(encoded), jsonParseBigInt);
82
+ }
83
+ catch {
84
+ return new Object();
85
+ }
44
86
  }
45
87
  encode(decoded) {
46
88
  decoded = decoded || this.decoded;
47
- return new Uint8Array();
89
+ // Example: encode as JSON (override in subclass)
90
+ return _textEncoder.encode(JSON.stringify(decoded, jsonStringifyBigInt));
48
91
  }
49
92
  // get Codec(): Codec {}
93
+ // Cache proto keys/values for reuse
94
+ static _protoCache = new WeakMap();
50
95
  protoEncode(data) {
51
- // check schema
96
+ let cache = BasicInterface._protoCache.get(this.proto);
97
+ if (!cache) {
98
+ cache = {
99
+ keys: Object.keys(this.proto),
100
+ values: Object.values(this.proto)
101
+ };
102
+ BasicInterface._protoCache.set(this.proto, cache);
103
+ }
104
+ // Use proto.encode directly, but avoid new array allocations inside encode if possible
52
105
  return proto.encode(this.proto, data, false);
53
106
  }
54
107
  protoDecode(data) {
55
- // check schema
56
- return proto.decode(this.proto, data, false);
108
+ // Use a static output object if possible (not thread-safe, but safe for single-threaded use)
109
+ if (!this._decodeOutput)
110
+ this._decodeOutput = {};
111
+ const result = proto.decode(this.proto, data, false);
112
+ // Copy properties to static object to avoid new allocations
113
+ Object.keys(result).forEach((k) => {
114
+ this._decodeOutput[k] = result[k];
115
+ });
116
+ // Remove any keys not in result
117
+ Object.keys(this._decodeOutput).forEach((k) => {
118
+ if (!(k in result))
119
+ delete this._decodeOutput[k];
120
+ });
121
+ return this._decodeOutput;
57
122
  }
58
123
  isHex(string) {
59
124
  return isHex(string);
@@ -86,7 +151,10 @@ class BasicInterface {
86
151
  return this.decode(fromHex(string));
87
152
  }
88
153
  fromArray(array) {
89
- return this.decode(Uint8Array.from([...array]));
154
+ // Avoid unnecessary copy if already Uint8Array
155
+ if (array instanceof Uint8Array)
156
+ return this.decode(array);
157
+ return this.decode(Uint8Array.from(array));
90
158
  }
91
159
  fromEncoded(encoded) {
92
160
  return this.decode(encoded);
@@ -94,15 +162,21 @@ class BasicInterface {
94
162
  toString() {
95
163
  if (!this.encoded)
96
164
  this.encode();
97
- return this.encoded.toString();
165
+ // Use cached string if available
166
+ if (!this._string)
167
+ this._string = Array.prototype.join.call(this.encoded, ',');
168
+ return this._string;
98
169
  }
99
170
  toHex() {
100
171
  if (!this.encoded)
101
172
  this.encode();
102
- return toHex(this.encoded
103
- .toString()
104
- .split(',')
105
- .map((number) => Number(number)));
173
+ // Use cached hex if available
174
+ if (!this._hex) {
175
+ if (!this._string)
176
+ this._string = Array.prototype.join.call(this.encoded, ',');
177
+ this._hex = toHex(this._string.split(',').map(Number));
178
+ }
179
+ return this._hex;
106
180
  }
107
181
  /**
108
182
  * @return {String} encoded
@@ -110,7 +184,10 @@ class BasicInterface {
110
184
  toBs32() {
111
185
  if (!this.encoded)
112
186
  this.encode();
113
- return toBase32(this.encoded);
187
+ // Use cached bs32 if available
188
+ if (!this._bs32)
189
+ this._bs32 = toBase32(this.encoded);
190
+ return this._bs32;
114
191
  }
115
192
  /**
116
193
  * @return {String} encoded
@@ -123,3 +200,4 @@ class BasicInterface {
123
200
  }
124
201
 
125
202
  export { BasicInterface as default, jsonParseBigInt, jsonStringifyBigInt };
203
+ //# sourceMappingURL=basic-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic-interface.js","sources":["../src/basic-interface.ts"],"sourcesContent":["import base32 from '@vandeurenglenn/base32'\nimport base58 from '@vandeurenglenn/base58'\nimport type { base58String } from '@vandeurenglenn/base58'\nimport type { base32String } from '@vandeurenglenn/base32'\nimport isHex from '@vandeurenglenn/is-hex'\nimport proto from '@vandeurenglenn/proto-array'\nimport {\n fromBase32,\n fromBase58,\n fromString,\n fromHex,\n fromArrayLike,\n fromUintArrayString,\n toBase32,\n toBase58,\n toHex\n} from '@vandeurenglenn/typed-array-utils'\n\nconst BASE64_CHUNK_SIZE = 0x8000\n\nconst uint8ArrayToBase64 = (value: Uint8Array): string => {\n if (typeof Buffer !== 'undefined') return Buffer.from(value).toString('base64')\n let binary = ''\n for (let offset = 0; offset < value.length; offset += BASE64_CHUNK_SIZE) {\n const slice = value.subarray(offset, offset + BASE64_CHUNK_SIZE)\n binary += String.fromCharCode(...slice)\n }\n return btoa(binary)\n}\n\nconst base64ToUint8Array = (value: string): Uint8Array => {\n if (typeof Buffer !== 'undefined') return new Uint8Array(Buffer.from(value, 'base64'))\n const binary = atob(value)\n const output = new Uint8Array(binary.length)\n for (let i = 0; i < binary.length; i++) output[i] = binary.charCodeAt(i)\n return output\n}\n\nexport const jsonStringifyBigInt = (key, value) => {\n if (typeof value === 'bigint') return { $bigint: value.toString() }\n if (value instanceof Uint8Array) return { $uint8array: uint8ArrayToBase64(value) }\n return value\n}\n\nexport const jsonParseBigInt = (key, value) => {\n if (typeof value === 'object' && value) {\n if (value.$bigint) return BigInt(value.$bigint)\n if (value.$uint8array) return base64ToUint8Array(value.$uint8array)\n }\n return value\n}\n\nconst _textEncoder = new TextEncoder()\nconst _textDecoder = new TextDecoder()\n\nexport default class BasicInterface {\n #encoded: Uint8Array\n #decoded: object\n name: string\n #proto: object\n\n get keys() {\n // handles proto keys\n // protokey -> key\n return Object.keys(this.#proto).map((key) => (key.endsWith('?') ? key.split('?')[0] : key))\n }\n\n get encoded() {\n if (!this.#encoded) this.#encoded = this.encode()\n return this.#encoded\n }\n\n set encoded(value) {\n this.#encoded = value\n }\n\n get decoded() {\n if (!this.#decoded) this.#decoded = this.decode()\n return this.#decoded\n }\n\n set decoded(value) {\n this.#decoded = value\n }\n\n set proto(value) {\n this.#proto = value\n }\n\n get proto() {\n return this.#proto\n }\n\n decode(encoded?: Uint8Array): Object {\n encoded = encoded || this.encoded\n // Example: decode as JSON if possible (override in subclass)\n try {\n return JSON.parse(_textDecoder.decode(encoded), jsonParseBigInt)\n } catch {\n return new Object()\n }\n }\n\n encode(decoded?: object): Uint8Array {\n decoded = decoded || this.decoded\n // Example: encode as JSON (override in subclass)\n return _textEncoder.encode(JSON.stringify(decoded, jsonStringifyBigInt))\n }\n // get Codec(): Codec {}\n\n // Cache proto keys/values for reuse\n static _protoCache = new WeakMap<object, { keys: string[]; values: any[] }>()\n\n protoEncode(data: object): Uint8Array {\n let cache = BasicInterface._protoCache.get(this.proto)\n if (!cache) {\n cache = {\n keys: Object.keys(this.proto),\n values: Object.values(this.proto)\n }\n BasicInterface._protoCache.set(this.proto, cache)\n }\n // Use proto.encode directly, but avoid new array allocations inside encode if possible\n return proto.encode(this.proto, data, false)\n }\n\n protoDecode(data: Uint8Array): object {\n // Use a static output object if possible (not thread-safe, but safe for single-threaded use)\n if (!this._decodeOutput) this._decodeOutput = {}\n const result = proto.decode(this.proto, data, false)\n // Copy properties to static object to avoid new allocations\n Object.keys(result).forEach((k) => {\n this._decodeOutput[k] = result[k]\n })\n // Remove any keys not in result\n Object.keys(this._decodeOutput).forEach((k) => {\n if (!(k in result)) delete this._decodeOutput[k]\n })\n return this._decodeOutput\n }\n\n isHex(string: string): boolean {\n return isHex(string)\n }\n isBase32(string: string): boolean {\n return base32.isBase32(string)\n }\n isBase58(string: string): boolean {\n return base58.isBase58(string)\n }\n\n fromBs32(encoded: string): object {\n return this.decode(base32.decode(encoded))\n }\n\n fromBs58(encoded: base58String): object {\n return this.decode(fromBase58(encoded))\n }\n\n async toArray() {\n const array: number[] = []\n for await (const value of this.encoded.values()) {\n array.push(value)\n }\n return array\n }\n\n fromString(string: string): object {\n const array: string[] = string.split(',')\n const arrayLike = array.map((string) => Number(string))\n return this.decode(Uint8Array.from(arrayLike))\n }\n\n fromHex(string: string): object {\n return this.decode(fromHex(string))\n }\n\n fromArray(array: number[]): object {\n // Avoid unnecessary copy if already Uint8Array\n if (array instanceof Uint8Array) return this.decode(array)\n return this.decode(Uint8Array.from(array))\n }\n\n fromEncoded(encoded: Uint8Array) {\n return this.decode(encoded)\n }\n\n toString(): string {\n if (!this.encoded) this.encode()\n // Use cached string if available\n if (!this._string) this._string = Array.prototype.join.call(this.encoded, ',')\n return this._string\n }\n\n toHex(): string {\n if (!this.encoded) this.encode()\n // Use cached hex if available\n if (!this._hex) {\n if (!this._string) this._string = Array.prototype.join.call(this.encoded, ',')\n this._hex = toHex(this._string.split(',').map(Number))\n }\n return this._hex\n }\n\n /**\n * @return {String} encoded\n */\n toBs32(): base32String {\n if (!this.encoded) this.encode()\n // Use cached bs32 if available\n if (!this._bs32) this._bs32 = toBase32(this.encoded)\n return this._bs32\n }\n\n /**\n * @return {String} encoded\n */\n toBs58(): base58String {\n if (!this.encoded) this.encode()\n return toBase58(this.encoded)\n }\n}\n"],"names":[],"mappings":";;;;;;AAkBA,MAAM,iBAAiB,GAAG,MAAM;AAEhC,MAAM,kBAAkB,GAAG,CAAC,KAAiB,KAAY;IACvD,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAC/E,IAAI,MAAM,GAAG,EAAE;AACf,IAAA,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,IAAI,iBAAiB,EAAE;AACvE,QAAA,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAAC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;AAEG;IACH,MAAM,GAAA;QACJ,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,MAAM,EAAE;;QAEhC,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;QACpD,OAAO,IAAI,CAAC,KAAK;IACnB;AAEA;;AAEG;IACH,MAAM,GAAA;QACJ,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,MAAM,EAAE;AAChC,QAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;IAC/B;;;;;"}
@@ -0,0 +1,209 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var base32 = require('@vandeurenglenn/base32');
6
+ var base58 = require('@vandeurenglenn/base58');
7
+ var isHex = require('@vandeurenglenn/is-hex');
8
+ var proto = require('@vandeurenglenn/proto-array');
9
+ var typedArrayUtils = require('@vandeurenglenn/typed-array-utils');
10
+
11
+ const BASE64_CHUNK_SIZE = 0x8000;
12
+ const uint8ArrayToBase64 = (value) => {
13
+ if (typeof Buffer !== 'undefined')
14
+ return Buffer.from(value).toString('base64');
15
+ let binary = '';
16
+ for (let offset = 0; offset < value.length; offset += BASE64_CHUNK_SIZE) {
17
+ const slice = value.subarray(offset, offset + BASE64_CHUNK_SIZE);
18
+ binary += String.fromCharCode(...slice);
19
+ }
20
+ return btoa(binary);
21
+ };
22
+ const base64ToUint8Array = (value) => {
23
+ if (typeof Buffer !== 'undefined')
24
+ return new Uint8Array(Buffer.from(value, 'base64'));
25
+ const binary = atob(value);
26
+ const output = new Uint8Array(binary.length);
27
+ for (let i = 0; i < binary.length; i++)
28
+ output[i] = binary.charCodeAt(i);
29
+ return output;
30
+ };
31
+ const jsonStringifyBigInt = (key, value) => {
32
+ if (typeof value === 'bigint')
33
+ return { $bigint: value.toString() };
34
+ if (value instanceof Uint8Array)
35
+ return { $uint8array: uint8ArrayToBase64(value) };
36
+ return value;
37
+ };
38
+ const jsonParseBigInt = (key, value) => {
39
+ if (typeof value === 'object' && value) {
40
+ if (value.$bigint)
41
+ return BigInt(value.$bigint);
42
+ if (value.$uint8array)
43
+ return base64ToUint8Array(value.$uint8array);
44
+ }
45
+ return value;
46
+ };
47
+ const _textEncoder = new TextEncoder();
48
+ const _textDecoder = new TextDecoder();
49
+ class BasicInterface {
50
+ #encoded;
51
+ #decoded;
52
+ name;
53
+ #proto;
54
+ get keys() {
55
+ // handles proto keys
56
+ // protokey -> key
57
+ return Object.keys(this.#proto).map((key) => (key.endsWith('?') ? key.split('?')[0] : key));
58
+ }
59
+ get encoded() {
60
+ if (!this.#encoded)
61
+ this.#encoded = this.encode();
62
+ return this.#encoded;
63
+ }
64
+ set encoded(value) {
65
+ this.#encoded = value;
66
+ }
67
+ get decoded() {
68
+ if (!this.#decoded)
69
+ this.#decoded = this.decode();
70
+ return this.#decoded;
71
+ }
72
+ set decoded(value) {
73
+ this.#decoded = value;
74
+ }
75
+ set proto(value) {
76
+ this.#proto = value;
77
+ }
78
+ get proto() {
79
+ return this.#proto;
80
+ }
81
+ decode(encoded) {
82
+ encoded = encoded || this.encoded;
83
+ // Example: decode as JSON if possible (override in subclass)
84
+ try {
85
+ return JSON.parse(_textDecoder.decode(encoded), jsonParseBigInt);
86
+ }
87
+ catch {
88
+ return new Object();
89
+ }
90
+ }
91
+ encode(decoded) {
92
+ decoded = decoded || this.decoded;
93
+ // Example: encode as JSON (override in subclass)
94
+ return _textEncoder.encode(JSON.stringify(decoded, jsonStringifyBigInt));
95
+ }
96
+ // get Codec(): Codec {}
97
+ // Cache proto keys/values for reuse
98
+ static _protoCache = new WeakMap();
99
+ protoEncode(data) {
100
+ let cache = BasicInterface._protoCache.get(this.proto);
101
+ if (!cache) {
102
+ cache = {
103
+ keys: Object.keys(this.proto),
104
+ values: Object.values(this.proto)
105
+ };
106
+ BasicInterface._protoCache.set(this.proto, cache);
107
+ }
108
+ // Use proto.encode directly, but avoid new array allocations inside encode if possible
109
+ return proto.encode(this.proto, data, false);
110
+ }
111
+ protoDecode(data) {
112
+ // Use a static output object if possible (not thread-safe, but safe for single-threaded use)
113
+ if (!this._decodeOutput)
114
+ this._decodeOutput = {};
115
+ const result = proto.decode(this.proto, data, false);
116
+ // Copy properties to static object to avoid new allocations
117
+ Object.keys(result).forEach((k) => {
118
+ this._decodeOutput[k] = result[k];
119
+ });
120
+ // Remove any keys not in result
121
+ Object.keys(this._decodeOutput).forEach((k) => {
122
+ if (!(k in result))
123
+ delete this._decodeOutput[k];
124
+ });
125
+ return this._decodeOutput;
126
+ }
127
+ isHex(string) {
128
+ return isHex(string);
129
+ }
130
+ isBase32(string) {
131
+ return base32.isBase32(string);
132
+ }
133
+ isBase58(string) {
134
+ return base58.isBase58(string);
135
+ }
136
+ fromBs32(encoded) {
137
+ return this.decode(base32.decode(encoded));
138
+ }
139
+ fromBs58(encoded) {
140
+ return this.decode(typedArrayUtils.fromBase58(encoded));
141
+ }
142
+ async toArray() {
143
+ const array = [];
144
+ for await (const value of this.encoded.values()) {
145
+ array.push(value);
146
+ }
147
+ return array;
148
+ }
149
+ fromString(string) {
150
+ const array = string.split(',');
151
+ const arrayLike = array.map((string) => Number(string));
152
+ return this.decode(Uint8Array.from(arrayLike));
153
+ }
154
+ fromHex(string) {
155
+ return this.decode(typedArrayUtils.fromHex(string));
156
+ }
157
+ fromArray(array) {
158
+ // Avoid unnecessary copy if already Uint8Array
159
+ if (array instanceof Uint8Array)
160
+ return this.decode(array);
161
+ return this.decode(Uint8Array.from(array));
162
+ }
163
+ fromEncoded(encoded) {
164
+ return this.decode(encoded);
165
+ }
166
+ toString() {
167
+ if (!this.encoded)
168
+ this.encode();
169
+ // Use cached string if available
170
+ if (!this._string)
171
+ this._string = Array.prototype.join.call(this.encoded, ',');
172
+ return this._string;
173
+ }
174
+ toHex() {
175
+ if (!this.encoded)
176
+ this.encode();
177
+ // Use cached hex if available
178
+ if (!this._hex) {
179
+ if (!this._string)
180
+ this._string = Array.prototype.join.call(this.encoded, ',');
181
+ this._hex = typedArrayUtils.toHex(this._string.split(',').map(Number));
182
+ }
183
+ return this._hex;
184
+ }
185
+ /**
186
+ * @return {String} encoded
187
+ */
188
+ toBs32() {
189
+ if (!this.encoded)
190
+ this.encode();
191
+ // Use cached bs32 if available
192
+ if (!this._bs32)
193
+ this._bs32 = typedArrayUtils.toBase32(this.encoded);
194
+ return this._bs32;
195
+ }
196
+ /**
197
+ * @return {String} encoded
198
+ */
199
+ toBs58() {
200
+ if (!this.encoded)
201
+ this.encode();
202
+ return typedArrayUtils.toBase58(this.encoded);
203
+ }
204
+ }
205
+
206
+ exports.default = BasicInterface;
207
+ exports.jsonParseBigInt = jsonParseBigInt;
208
+ exports.jsonStringifyBigInt = jsonStringifyBigInt;
209
+ //# sourceMappingURL=basic-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic-interface.js","sources":["../../src/basic-interface.ts"],"sourcesContent":["import base32 from '@vandeurenglenn/base32'\nimport base58 from '@vandeurenglenn/base58'\nimport type { base58String } from '@vandeurenglenn/base58'\nimport type { base32String } from '@vandeurenglenn/base32'\nimport isHex from '@vandeurenglenn/is-hex'\nimport proto from '@vandeurenglenn/proto-array'\nimport {\n fromBase32,\n fromBase58,\n fromString,\n fromHex,\n fromArrayLike,\n fromUintArrayString,\n toBase32,\n toBase58,\n toHex\n} from '@vandeurenglenn/typed-array-utils'\n\nconst BASE64_CHUNK_SIZE = 0x8000\n\nconst uint8ArrayToBase64 = (value: Uint8Array): string => {\n if (typeof Buffer !== 'undefined') return Buffer.from(value).toString('base64')\n let binary = ''\n for (let offset = 0; offset < value.length; offset += BASE64_CHUNK_SIZE) {\n const slice = value.subarray(offset, offset + BASE64_CHUNK_SIZE)\n binary += String.fromCharCode(...slice)\n }\n return btoa(binary)\n}\n\nconst base64ToUint8Array = (value: string): Uint8Array => {\n if (typeof Buffer !== 'undefined') return new Uint8Array(Buffer.from(value, 'base64'))\n const binary = atob(value)\n const output = new Uint8Array(binary.length)\n for (let i = 0; i < binary.length; i++) output[i] = binary.charCodeAt(i)\n return output\n}\n\nexport const jsonStringifyBigInt = (key, value) => {\n if (typeof value === 'bigint') return { $bigint: value.toString() }\n if (value instanceof Uint8Array) return { $uint8array: uint8ArrayToBase64(value) }\n return value\n}\n\nexport const jsonParseBigInt = (key, value) => {\n if (typeof value === 'object' && value) {\n if (value.$bigint) return BigInt(value.$bigint)\n if (value.$uint8array) return base64ToUint8Array(value.$uint8array)\n }\n return value\n}\n\nconst _textEncoder = new TextEncoder()\nconst _textDecoder = new TextDecoder()\n\nexport default class BasicInterface {\n #encoded: Uint8Array\n #decoded: object\n name: string\n #proto: object\n\n get keys() {\n // handles proto keys\n // protokey -> key\n return Object.keys(this.#proto).map((key) => (key.endsWith('?') ? key.split('?')[0] : key))\n }\n\n get encoded() {\n if (!this.#encoded) this.#encoded = this.encode()\n return this.#encoded\n }\n\n set encoded(value) {\n this.#encoded = value\n }\n\n get decoded() {\n if (!this.#decoded) this.#decoded = this.decode()\n return this.#decoded\n }\n\n set decoded(value) {\n this.#decoded = value\n }\n\n set proto(value) {\n this.#proto = value\n }\n\n get proto() {\n return this.#proto\n }\n\n decode(encoded?: Uint8Array): Object {\n encoded = encoded || this.encoded\n // Example: decode as JSON if possible (override in subclass)\n try {\n return JSON.parse(_textDecoder.decode(encoded), jsonParseBigInt)\n } catch {\n return new Object()\n }\n }\n\n encode(decoded?: object): Uint8Array {\n decoded = decoded || this.decoded\n // Example: encode as JSON (override in subclass)\n return _textEncoder.encode(JSON.stringify(decoded, jsonStringifyBigInt))\n }\n // get Codec(): Codec {}\n\n // Cache proto keys/values for reuse\n static _protoCache = new WeakMap<object, { keys: string[]; values: any[] }>()\n\n protoEncode(data: object): Uint8Array {\n let cache = BasicInterface._protoCache.get(this.proto)\n if (!cache) {\n cache = {\n keys: Object.keys(this.proto),\n values: Object.values(this.proto)\n }\n BasicInterface._protoCache.set(this.proto, cache)\n }\n // Use proto.encode directly, but avoid new array allocations inside encode if possible\n return proto.encode(this.proto, data, false)\n }\n\n protoDecode(data: Uint8Array): object {\n // Use a static output object if possible (not thread-safe, but safe for single-threaded use)\n if (!this._decodeOutput) this._decodeOutput = {}\n const result = proto.decode(this.proto, data, false)\n // Copy properties to static object to avoid new allocations\n Object.keys(result).forEach((k) => {\n this._decodeOutput[k] = result[k]\n })\n // Remove any keys not in result\n Object.keys(this._decodeOutput).forEach((k) => {\n if (!(k in result)) delete this._decodeOutput[k]\n })\n return this._decodeOutput\n }\n\n isHex(string: string): boolean {\n return isHex(string)\n }\n isBase32(string: string): boolean {\n return base32.isBase32(string)\n }\n isBase58(string: string): boolean {\n return base58.isBase58(string)\n }\n\n fromBs32(encoded: string): object {\n return this.decode(base32.decode(encoded))\n }\n\n fromBs58(encoded: base58String): object {\n return this.decode(fromBase58(encoded))\n }\n\n async toArray() {\n const array: number[] = []\n for await (const value of this.encoded.values()) {\n array.push(value)\n }\n return array\n }\n\n fromString(string: string): object {\n const array: string[] = string.split(',')\n const arrayLike = array.map((string) => Number(string))\n return this.decode(Uint8Array.from(arrayLike))\n }\n\n fromHex(string: string): object {\n return this.decode(fromHex(string))\n }\n\n fromArray(array: number[]): object {\n // Avoid unnecessary copy if already Uint8Array\n if (array instanceof Uint8Array) return this.decode(array)\n return this.decode(Uint8Array.from(array))\n }\n\n fromEncoded(encoded: Uint8Array) {\n return this.decode(encoded)\n }\n\n toString(): string {\n if (!this.encoded) this.encode()\n // Use cached string if available\n if (!this._string) this._string = Array.prototype.join.call(this.encoded, ',')\n return this._string\n }\n\n toHex(): string {\n if (!this.encoded) this.encode()\n // Use cached hex if available\n if (!this._hex) {\n if (!this._string) this._string = Array.prototype.join.call(this.encoded, ',')\n this._hex = toHex(this._string.split(',').map(Number))\n }\n return this._hex\n }\n\n /**\n * @return {String} encoded\n */\n toBs32(): base32String {\n if (!this.encoded) this.encode()\n // Use cached bs32 if available\n if (!this._bs32) this._bs32 = toBase32(this.encoded)\n return this._bs32\n }\n\n /**\n * @return {String} encoded\n */\n toBs58(): base58String {\n if (!this.encoded) this.encode()\n return toBase58(this.encoded)\n }\n}\n"],"names":["fromBase58","fromHex","toHex","toBase32","toBase58"],"mappings":";;;;;;;;;;AAkBA,MAAM,iBAAiB,GAAG,MAAM;AAEhC,MAAM,kBAAkB,GAAG,CAAC,KAAiB,KAAY;IACvD,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAC/E,IAAI,MAAM,GAAG,EAAE;AACf,IAAA,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,IAAI,iBAAiB,EAAE;AACvE,QAAA,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAAC;QAChE,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;IACzC;AACA,IAAA,OAAO,IAAI,CAAC,MAAM,CAAC;AACrB,CAAC;AAED,MAAM,kBAAkB,GAAG,CAAC,KAAa,KAAgB;IACvD,IAAI,OAAO,MAAM,KAAK,WAAW;AAAE,QAAA,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACtF,IAAA,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC;AAC5C,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;AACxE,IAAA,OAAO,MAAM;AACf,CAAC;MAEY,mBAAmB,G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