@quentinadam/evm-base 0.1.1 → 0.1.2

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.
@@ -0,0 +1,6 @@
1
+ export default class MethodSignatureRegistry {
2
+ #private;
3
+ static register(method: string): void;
4
+ static decode(selector: string): string | undefined;
5
+ }
6
+ //# sourceMappingURL=MethodSignatureRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodSignatureRegistry.d.ts","sourceRoot":"","sources":["../src/MethodSignatureRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,OAAO,uBAAuB;;IAG1C,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAI9B,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAwBpD"}
@@ -0,0 +1,31 @@
1
+ import keccak256 from '@quentinadam/hash/keccak256';
2
+ export default class MethodSignatureRegistry {
3
+ static #methods = new Map();
4
+ static register(method) {
5
+ this.#methods.set(keccak256(method).slice(0, 4).toHex(), method);
6
+ }
7
+ static decode(selector) {
8
+ return this.#methods.get(selector);
9
+ }
10
+ static {
11
+ /* @__PURE__ */ (() => {
12
+ const methods = [
13
+ 'approve(address,uint256)',
14
+ 'burn(address,uint256)',
15
+ 'burn(uint256)',
16
+ 'deposit()',
17
+ 'mint(address,uint256)',
18
+ 'mint(uint256)',
19
+ 'sweep()',
20
+ 'sweep(address)',
21
+ 'transfer(address,uint256)',
22
+ 'transferFrom(address,address,uint256)',
23
+ 'withdraw(uint256)',
24
+ ];
25
+ for (const method of methods) {
26
+ this.register(method);
27
+ }
28
+ })();
29
+ }
30
+ }
31
+ //# sourceMappingURL=MethodSignatureRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodSignatureRegistry.js","sourceRoot":"","sources":["../src/MethodSignatureRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,6BAA6B,CAAC;AAEpD,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C,MAAM,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE5C,MAAM,CAAC,QAAQ,CAAC,MAAc;QAC5B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,QAAgB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED;QACE,eAAe,CAAC,CAAC,GAAG,EAAE;YACpB,MAAM,OAAO,GAAG;gBACd,0BAA0B;gBAC1B,uBAAuB;gBACvB,eAAe;gBACf,WAAW;gBACX,uBAAuB;gBACvB,eAAe;gBACf,SAAS;gBACT,gBAAgB;gBAChB,2BAA2B;gBAC3B,uCAAuC;gBACvC,mBAAmB;aACpB,CAAC;YACF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACxB,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type InspectFn = (value: unknown, options?: unknown) => string;
2
+ export default function createInspectableDataWrapper(bytes: Uint8Array): object;
3
+ //# sourceMappingURL=createInspectableDataWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createInspectableDataWrapper.d.ts","sourceRoot":"","sources":["../src/createInspectableDataWrapper.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,4BAA4B,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CA8B9E"}
@@ -0,0 +1,29 @@
1
+ import MethodSignatureRegistry from "./MethodSignatureRegistry.js";
2
+ export default function createInspectableDataWrapper(bytes) {
3
+ return new (class InspectableDataWrapper {
4
+ #bytes;
5
+ constructor(bytes) {
6
+ this.#bytes = bytes;
7
+ }
8
+ #customInspect(inspect, options) {
9
+ if (this.#bytes.length === 0) {
10
+ return inspect([], options);
11
+ }
12
+ const selector = this.#bytes.slice(0, 4).toHex();
13
+ const lines = [MethodSignatureRegistry.decode(selector) ?? selector];
14
+ let index = 4;
15
+ while (index < this.#bytes.length) {
16
+ lines.push(this.#bytes.slice(index, index + 32).toHex());
17
+ index += 32;
18
+ }
19
+ return inspect(lines, options);
20
+ }
21
+ [Symbol.for('Deno.customInspect')](inspect, options) {
22
+ return this.#customInspect(inspect, options);
23
+ }
24
+ [Symbol.for('nodejs.util.inspect.custom')](_depth, options, inspect) {
25
+ return this.#customInspect(inspect, options);
26
+ }
27
+ })(bytes);
28
+ }
29
+ //# sourceMappingURL=createInspectableDataWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createInspectableDataWrapper.js","sourceRoot":"","sources":["../src/createInspectableDataWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AAInE,MAAM,CAAC,OAAO,UAAU,4BAA4B,CAAC,KAAiB;IACpE,OAAO,IAAI,CAAC,MAAM,sBAAsB;QAC7B,MAAM,CAAa;QAE5B,YAAY,KAAiB;YAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACtB,CAAC;QAED,cAAc,CAAC,OAAkB,EAAE,OAAgB;YACjD,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC7B,OAAO,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;YAC9B,CAAC;YACD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,CAAC,uBAAuB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC;YACrE,IAAI,KAAK,GAAG,CAAC,CAAC;YACd,OAAO,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;gBACzD,KAAK,IAAI,EAAE,CAAC;YACd,CAAC;YACD,OAAO,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC;QAED,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,OAAkB,EAAE,OAAgB;YACrE,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;QAED,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,CAAC,MAAc,EAAE,OAAgB,EAAE,OAAkB;YAC7F,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;KACF,CAAC,CAAC,KAAK,CAAC,CAAC;AACZ,CAAC"}
package/dist/mod.d.ts CHANGED
@@ -4,12 +4,14 @@ import computeCREATE2Address from './computeCREATE2Address.ts';
4
4
  import computeCREATEAddress from './computeCREATEAddress.ts';
5
5
  import Client from './Client.ts';
6
6
  import ClientError from './ClientError.ts';
7
+ import createInspectableDataWrapper from './createInspectableDataWrapper.ts';
7
8
  import DataEncoder from './DataEncoder.ts';
8
9
  import ClientHelper from './ClientHelper.ts';
9
10
  import type Log from './Log.ts';
11
+ import MethodSignatureRegistry from './MethodSignatureRegistry.ts';
10
12
  import MulticallClient from './MulticallClient.ts';
11
13
  import type Transaction from './Transaction.ts';
12
14
  import type TransactionReceipt from './TransactionReceipt.ts';
13
- export { ABI, Client, ClientError, ClientHelper, computeCREATE2Address, computeCREATEAddress, DataEncoder, MulticallClient, };
15
+ export { ABI, Client, ClientError, ClientHelper, computeCREATE2Address, computeCREATEAddress, createInspectableDataWrapper, DataEncoder, MethodSignatureRegistry, MulticallClient, };
14
16
  export type { Block, Log, Transaction, TransactionReceipt };
15
17
  //# sourceMappingURL=mod.d.ts.map
package/dist/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,eAAe,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,eAAe,GAChB,CAAC;AAEF,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAC7E,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,eAAe,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,4BAA4B,EAC5B,WAAW,EACX,uBAAuB,EACvB,eAAe,GAChB,CAAC;AAEF,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC"}
package/dist/mod.js CHANGED
@@ -3,8 +3,10 @@ import computeCREATE2Address from "./computeCREATE2Address.js";
3
3
  import computeCREATEAddress from "./computeCREATEAddress.js";
4
4
  import Client from "./Client.js";
5
5
  import ClientError from "./ClientError.js";
6
+ import createInspectableDataWrapper from "./createInspectableDataWrapper.js";
6
7
  import DataEncoder from "./DataEncoder.js";
7
8
  import ClientHelper from "./ClientHelper.js";
9
+ import MethodSignatureRegistry from "./MethodSignatureRegistry.js";
8
10
  import MulticallClient from "./MulticallClient.js";
9
- export { ABI, Client, ClientError, ClientHelper, computeCREATE2Address, computeCREATEAddress, DataEncoder, MulticallClient, };
11
+ export { ABI, Client, ClientError, ClientHelper, computeCREATE2Address, computeCREATEAddress, createInspectableDataWrapper, DataEncoder, MethodSignatureRegistry, MulticallClient, };
10
12
  //# sourceMappingURL=mod.js.map
package/dist/mod.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAE7C,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAInD,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,eAAe,GAChB,CAAC"}
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAC7E,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAE7C,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAInD,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,4BAA4B,EAC5B,WAAW,EACX,uBAAuB,EACvB,eAAe,GAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quentinadam/evm-base",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "EVM base library",
5
5
  "license": "MIT",
6
6
  "author": "Quentin Adam",
@@ -0,0 +1,34 @@
1
+ import keccak256 from '@quentinadam/hash/keccak256';
2
+
3
+ export default class MethodSignatureRegistry {
4
+ static #methods = new Map<string, string>();
5
+
6
+ static register(method: string) {
7
+ this.#methods.set(keccak256(method).slice(0, 4).toHex(), method);
8
+ }
9
+
10
+ static decode(selector: string): string | undefined {
11
+ return this.#methods.get(selector);
12
+ }
13
+
14
+ static {
15
+ /* @__PURE__ */ (() => {
16
+ const methods = [
17
+ 'approve(address,uint256)',
18
+ 'burn(address,uint256)',
19
+ 'burn(uint256)',
20
+ 'deposit()',
21
+ 'mint(address,uint256)',
22
+ 'mint(uint256)',
23
+ 'sweep()',
24
+ 'sweep(address)',
25
+ 'transfer(address,uint256)',
26
+ 'transferFrom(address,address,uint256)',
27
+ 'withdraw(uint256)',
28
+ ];
29
+ for (const method of methods) {
30
+ this.register(method);
31
+ }
32
+ })();
33
+ }
34
+ }
@@ -0,0 +1,35 @@
1
+ import MethodSignatureRegistry from './MethodSignatureRegistry.ts';
2
+
3
+ export type InspectFn = (value: unknown, options?: unknown) => string;
4
+
5
+ export default function createInspectableDataWrapper(bytes: Uint8Array): object {
6
+ return new (class InspectableDataWrapper {
7
+ readonly #bytes: Uint8Array;
8
+
9
+ constructor(bytes: Uint8Array) {
10
+ this.#bytes = bytes;
11
+ }
12
+
13
+ #customInspect(inspect: InspectFn, options: unknown): string {
14
+ if (this.#bytes.length === 0) {
15
+ return inspect([], options);
16
+ }
17
+ const selector = this.#bytes.slice(0, 4).toHex();
18
+ const lines = [MethodSignatureRegistry.decode(selector) ?? selector];
19
+ let index = 4;
20
+ while (index < this.#bytes.length) {
21
+ lines.push(this.#bytes.slice(index, index + 32).toHex());
22
+ index += 32;
23
+ }
24
+ return inspect(lines, options);
25
+ }
26
+
27
+ [Symbol.for('Deno.customInspect')](inspect: InspectFn, options: unknown): string {
28
+ return this.#customInspect(inspect, options);
29
+ }
30
+
31
+ [Symbol.for('nodejs.util.inspect.custom')](_depth: number, options: unknown, inspect: InspectFn): string {
32
+ return this.#customInspect(inspect, options);
33
+ }
34
+ })(bytes);
35
+ }
package/src/mod.ts CHANGED
@@ -4,9 +4,11 @@ import computeCREATE2Address from './computeCREATE2Address.ts';
4
4
  import computeCREATEAddress from './computeCREATEAddress.ts';
5
5
  import Client from './Client.ts';
6
6
  import ClientError from './ClientError.ts';
7
+ import createInspectableDataWrapper from './createInspectableDataWrapper.ts';
7
8
  import DataEncoder from './DataEncoder.ts';
8
9
  import ClientHelper from './ClientHelper.ts';
9
10
  import type Log from './Log.ts';
11
+ import MethodSignatureRegistry from './MethodSignatureRegistry.ts';
10
12
  import MulticallClient from './MulticallClient.ts';
11
13
  import type Transaction from './Transaction.ts';
12
14
  import type TransactionReceipt from './TransactionReceipt.ts';
@@ -18,7 +20,9 @@ export {
18
20
  ClientHelper,
19
21
  computeCREATE2Address,
20
22
  computeCREATEAddress,
23
+ createInspectableDataWrapper,
21
24
  DataEncoder,
25
+ MethodSignatureRegistry,
22
26
  MulticallClient,
23
27
  };
24
28