viem 1.0.1 → 1.0.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.
- package/dist/cjs/utils/hash/getEventSelector.js +5 -1
- package/dist/cjs/utils/hash/getEventSelector.js.map +1 -1
- package/dist/cjs/utils/hash/getFunctionSelector.js +5 -1
- package/dist/cjs/utils/hash/getFunctionSelector.js.map +1 -1
- package/dist/cjs/utils/hash/hashFunction.js +5 -1
- package/dist/cjs/utils/hash/hashFunction.js.map +1 -1
- package/dist/esm/utils/hash/getEventSelector.js +6 -2
- package/dist/esm/utils/hash/getEventSelector.js.map +1 -1
- package/dist/esm/utils/hash/getFunctionSelector.js +6 -2
- package/dist/esm/utils/hash/getFunctionSelector.js.map +1 -1
- package/dist/esm/utils/hash/hashFunction.js +3 -0
- package/dist/esm/utils/hash/hashFunction.js.map +1 -1
- package/dist/types/utils/hash/getEventSelector.d.ts +2 -1
- package/dist/types/utils/hash/getEventSelector.d.ts.map +1 -1
- package/dist/types/utils/hash/getFunctionSelector.d.ts +2 -1
- package/dist/types/utils/hash/getFunctionSelector.d.ts.map +1 -1
- package/dist/types/utils/hash/hashFunction.d.ts +2 -0
- package/dist/types/utils/hash/hashFunction.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/utils/hash/getEventSelector.ts +6 -2
- package/src/utils/hash/getFunctionSelector.ts +6 -2
- package/src/utils/hash/hashFunction.ts +5 -0
@@ -2,6 +2,10 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getEventSelector = void 0;
|
4
4
|
const hashFunction_js_1 = require("./hashFunction.js");
|
5
|
-
const getEventSelector = (event) =>
|
5
|
+
const getEventSelector = (event) => {
|
6
|
+
if (typeof event === 'string')
|
7
|
+
return (0, hashFunction_js_1.hashFunction)(event);
|
8
|
+
return (0, hashFunction_js_1.hashAbiItem)(event);
|
9
|
+
};
|
6
10
|
exports.getEventSelector = getEventSelector;
|
7
11
|
//# sourceMappingURL=getEventSelector.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getEventSelector.js","sourceRoot":"","sources":["../../../../src/utils/hash/getEventSelector.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"getEventSelector.js","sourceRoot":"","sources":["../../../../src/utils/hash/getEventSelector.ts"],"names":[],"mappings":";;;AAGA,uDAA6D;AAEtD,MAAM,gBAAgB,GAAG,CAAC,KAAiC,EAAE,EAAE;IACpE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAA,8BAAY,EAAC,KAAK,CAAC,CAAA;IACzD,OAAO,IAAA,6BAAW,EAAC,KAAK,CAAC,CAAA;AAC3B,CAAC,CAAA;AAHY,QAAA,gBAAgB,oBAG5B"}
|
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFunctionSelector = void 0;
|
4
4
|
const slice_js_1 = require("../data/slice.js");
|
5
5
|
const hashFunction_js_1 = require("./hashFunction.js");
|
6
|
-
const getFunctionSelector = (fn) =>
|
6
|
+
const getFunctionSelector = (fn) => {
|
7
|
+
if (typeof fn === 'string')
|
8
|
+
return (0, slice_js_1.slice)((0, hashFunction_js_1.hashFunction)(fn), 0, 4);
|
9
|
+
return (0, slice_js_1.slice)((0, hashFunction_js_1.hashAbiItem)(fn), 0, 4);
|
10
|
+
};
|
7
11
|
exports.getFunctionSelector = getFunctionSelector;
|
8
12
|
//# sourceMappingURL=getFunctionSelector.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getFunctionSelector.js","sourceRoot":"","sources":["../../../../src/utils/hash/getFunctionSelector.ts"],"names":[],"mappings":";;;AAAA,+CAAwC;
|
1
|
+
{"version":3,"file":"getFunctionSelector.js","sourceRoot":"","sources":["../../../../src/utils/hash/getFunctionSelector.ts"],"names":[],"mappings":";;;AAAA,+CAAwC;AAGxC,uDAA6D;AAEtD,MAAM,mBAAmB,GAAG,CAAC,EAAwB,EAAE,EAAE;IAC9D,IAAI,OAAO,EAAE,KAAK,QAAQ;QAAE,OAAO,IAAA,gBAAK,EAAC,IAAA,8BAAY,EAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAChE,OAAO,IAAA,gBAAK,EAAC,IAAA,6BAAW,EAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;AACrC,CAAC,CAAA;AAHY,QAAA,mBAAmB,uBAG/B"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.hashFunction = void 0;
|
3
|
+
exports.hashAbiItem = exports.hashFunction = void 0;
|
4
4
|
const extractFunctionParts_js_1 = require("../contract/extractFunctionParts.js");
|
5
5
|
const toBytes_js_1 = require("../encoding/toBytes.js");
|
6
6
|
const keccak256_js_1 = require("./keccak256.js");
|
@@ -11,4 +11,8 @@ function hashFunction(def) {
|
|
11
11
|
return hash(`${name}(${params.map(({ type }) => type).join(',')})`);
|
12
12
|
}
|
13
13
|
exports.hashFunction = hashFunction;
|
14
|
+
function hashAbiItem(def) {
|
15
|
+
return hash(`${def.name}(${def.inputs.map(({ type }) => type).join(',')})`);
|
16
|
+
}
|
17
|
+
exports.hashAbiItem = hashAbiItem;
|
14
18
|
//# sourceMappingURL=hashFunction.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hashFunction.js","sourceRoot":"","sources":["../../../../src/utils/hash/hashFunction.ts"],"names":[],"mappings":";;;AAAA,iFAG4C;AAC5C,uDAAgD;
|
1
|
+
{"version":3,"file":"hashFunction.js","sourceRoot":"","sources":["../../../../src/utils/hash/hashFunction.ts"],"names":[],"mappings":";;;AAAA,iFAG4C;AAC5C,uDAAgD;AAGhD,iDAA0C;AAE1C,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,IAAA,wBAAS,EAAC,IAAA,oBAAO,EAAC,KAAK,CAAC,CAAC,CAAA;AAEzD,SAAgB,YAAY,CAAC,GAAW;IACtC,MAAM,IAAI,GAAG,IAAA,6CAAmB,EAAC,GAAG,CAAC,CAAA;IACrC,MAAM,MAAM,GAAG,IAAA,+CAAqB,EAAC,GAAG,CAAC,IAAI,EAAE,CAAA;IAC/C,OAAO,IAAI,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACrE,CAAC;AAJD,oCAIC;AAED,SAAgB,WAAW,CAAC,GAA2B;IACrD,OAAO,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAC7E,CAAC;AAFD,kCAEC"}
|
@@ -1,3 +1,7 @@
|
|
1
|
-
import { hashFunction } from './hashFunction.js';
|
2
|
-
export const getEventSelector = (event) =>
|
1
|
+
import { hashAbiItem, hashFunction } from './hashFunction.js';
|
2
|
+
export const getEventSelector = (event) => {
|
3
|
+
if (typeof event === 'string')
|
4
|
+
return hashFunction(event);
|
5
|
+
return hashAbiItem(event);
|
6
|
+
};
|
3
7
|
//# sourceMappingURL=getEventSelector.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getEventSelector.js","sourceRoot":"","sources":["../../../../src/utils/hash/getEventSelector.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"getEventSelector.js","sourceRoot":"","sources":["../../../../src/utils/hash/getEventSelector.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAE7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAiC,EAAE,EAAE;IACpE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,YAAY,CAAC,KAAK,CAAC,CAAA;IACzD,OAAO,WAAW,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC,CAAA"}
|
@@ -1,4 +1,8 @@
|
|
1
1
|
import { slice } from '../data/slice.js';
|
2
|
-
import { hashFunction } from './hashFunction.js';
|
3
|
-
export const getFunctionSelector = (fn) =>
|
2
|
+
import { hashAbiItem, hashFunction } from './hashFunction.js';
|
3
|
+
export const getFunctionSelector = (fn) => {
|
4
|
+
if (typeof fn === 'string')
|
5
|
+
return slice(hashFunction(fn), 0, 4);
|
6
|
+
return slice(hashAbiItem(fn), 0, 4);
|
7
|
+
};
|
4
8
|
//# sourceMappingURL=getFunctionSelector.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getFunctionSelector.js","sourceRoot":"","sources":["../../../../src/utils/hash/getFunctionSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;
|
1
|
+
{"version":3,"file":"getFunctionSelector.js","sourceRoot":"","sources":["../../../../src/utils/hash/getFunctionSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAGxC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAE7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAAwB,EAAE,EAAE;IAC9D,IAAI,OAAO,EAAE,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAChE,OAAO,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;AACrC,CAAC,CAAA"}
|
@@ -7,4 +7,7 @@ export function hashFunction(def) {
|
|
7
7
|
const params = extractFunctionParams(def) || [];
|
8
8
|
return hash(`${name}(${params.map(({ type }) => type).join(',')})`);
|
9
9
|
}
|
10
|
+
export function hashAbiItem(def) {
|
11
|
+
return hash(`${def.name}(${def.inputs.map(({ type }) => type).join(',')})`);
|
12
|
+
}
|
10
13
|
//# sourceMappingURL=hashFunction.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hashFunction.js","sourceRoot":"","sources":["../../../../src/utils/hash/hashFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;
|
1
|
+
{"version":3,"file":"hashFunction.js","sourceRoot":"","sources":["../../../../src/utils/hash/hashFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;AAEzD,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,MAAM,IAAI,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAA;IACrC,MAAM,MAAM,GAAG,qBAAqB,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;IAC/C,OAAO,IAAI,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACrE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAA2B;IACrD,OAAO,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAC7E,CAAC"}
|
@@ -1,3 +1,4 @@
|
|
1
1
|
import type { EventDefinition } from '../../types/contract.js';
|
2
|
-
|
2
|
+
import type { AbiEvent } from 'abitype';
|
3
|
+
export declare const getEventSelector: (event: EventDefinition | AbiEvent) => `0x${string}`;
|
3
4
|
//# sourceMappingURL=getEventSelector.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getEventSelector.d.ts","sourceRoot":"","sources":["../../../../src/utils/hash/getEventSelector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;
|
1
|
+
{"version":3,"file":"getEventSelector.d.ts","sourceRoot":"","sources":["../../../../src/utils/hash/getEventSelector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAIvC,eAAO,MAAM,gBAAgB,UAAW,eAAe,GAAG,QAAQ,kBAGjE,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getFunctionSelector.d.ts","sourceRoot":"","sources":["../../../../src/utils/hash/getFunctionSelector.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"getFunctionSelector.d.ts","sourceRoot":"","sources":["../../../../src/utils/hash/getFunctionSelector.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAI1C,eAAO,MAAM,mBAAmB,OAAQ,MAAM,GAAG,WAAW,kBAG3D,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hashFunction.d.ts","sourceRoot":"","sources":["../../../../src/utils/hash/hashFunction.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"hashFunction.d.ts","sourceRoot":"","sources":["../../../../src/utils/hash/hashFunction.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAMpD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,iBAIvC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,GAAG,QAAQ,iBAEtD"}
|
package/package.json
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
import type { EventDefinition } from '../../types/contract.js'
|
2
|
+
import type { AbiEvent } from 'abitype'
|
2
3
|
|
3
|
-
import { hashFunction } from './hashFunction.js'
|
4
|
+
import { hashAbiItem, hashFunction } from './hashFunction.js'
|
4
5
|
|
5
|
-
export const getEventSelector = (event: EventDefinition) =>
|
6
|
+
export const getEventSelector = (event: EventDefinition | AbiEvent) => {
|
7
|
+
if (typeof event === 'string') return hashFunction(event)
|
8
|
+
return hashAbiItem(event)
|
9
|
+
}
|
@@ -1,5 +1,9 @@
|
|
1
1
|
import { slice } from '../data/slice.js'
|
2
|
+
import type { AbiFunction } from 'abitype'
|
2
3
|
|
3
|
-
import { hashFunction } from './hashFunction.js'
|
4
|
+
import { hashAbiItem, hashFunction } from './hashFunction.js'
|
4
5
|
|
5
|
-
export const getFunctionSelector = (fn: string
|
6
|
+
export const getFunctionSelector = (fn: string | AbiFunction) => {
|
7
|
+
if (typeof fn === 'string') return slice(hashFunction(fn), 0, 4)
|
8
|
+
return slice(hashAbiItem(fn), 0, 4)
|
9
|
+
}
|
@@ -3,6 +3,7 @@ import {
|
|
3
3
|
extractFunctionParams,
|
4
4
|
} from '../contract/extractFunctionParts.js'
|
5
5
|
import { toBytes } from '../encoding/toBytes.js'
|
6
|
+
import type { AbiEvent, AbiFunction } from 'abitype'
|
6
7
|
|
7
8
|
import { keccak256 } from './keccak256.js'
|
8
9
|
|
@@ -13,3 +14,7 @@ export function hashFunction(def: string) {
|
|
13
14
|
const params = extractFunctionParams(def) || []
|
14
15
|
return hash(`${name}(${params.map(({ type }) => type).join(',')})`)
|
15
16
|
}
|
17
|
+
|
18
|
+
export function hashAbiItem(def: AbiFunction | AbiEvent) {
|
19
|
+
return hash(`${def.name}(${def.inputs.map(({ type }) => type).join(',')})`)
|
20
|
+
}
|