Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abitype

Package Overview
Dependencies
Maintainers
2
Versions
182
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abitype - npm Package Compare versions

Comparing version 0.10.0-canary.20230712T161506 to 0.10.0-canary.20230712T202156

2

dist/cjs/version.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = void 0;
exports.version = '0.10.0-canary.20230712T161506';
exports.version = '0.10.0-canary.20230712T202156';
//# sourceMappingURL=version.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Abi = exports.AbiItemType = exports.AbiError = exports.AbiEvent = exports.AbiReceive = exports.AbiFallback = exports.AbiConstructor = exports.AbiFunction = exports.AbiStateMutability = exports.AbiEventParameter = exports.AbiParameter = exports.SolidityArray = exports.SolidityArrayWithTuple = exports.SolidityArrayWithoutTuple = exports.SolidityInt = exports.SolidityTuple = exports.SolidityString = exports.SolidityFunction = exports.SolidityBytes = exports.SolidityBool = exports.SolidityAddress = exports.Address = void 0;
exports.TypedData = exports.TypedDataParameter = exports.TypedDataType = exports.TypedDataDomain = exports.Abi = exports.AbiItemType = exports.AbiError = exports.AbiEvent = exports.AbiReceive = exports.AbiFallback = exports.AbiConstructor = exports.AbiFunction = exports.AbiStateMutability = exports.AbiEventParameter = exports.AbiParameter = exports.SolidityArray = exports.SolidityArrayWithTuple = exports.SolidityArrayWithoutTuple = exports.SolidityInt = exports.SolidityTuple = exports.SolidityString = exports.SolidityFunction = exports.SolidityBytes = exports.SolidityBool = exports.SolidityAddress = exports.Address = void 0;
const zod_1 = require("zod");
const utils_js_1 = require("./human-readable/runtime/utils.js");
const regex_js_1 = require("./regex.js");
const Identifier = zod_1.z.string().regex(/[a-zA-Z$_][a-zA-Z0-9$_]*/);
exports.Address = zod_1.z.string().transform((val, ctx) => {

@@ -34,3 +36,3 @@ const regex = /^0x[a-fA-F0-9]{40}$/;

exports.AbiParameter = zod_1.z.lazy(() => zod_1.z.intersection(zod_1.z.object({
name: zod_1.z.string().optional(),
name: Identifier.optional(),
internalType: zod_1.z.string().optional(),

@@ -77,3 +79,3 @@ }), zod_1.z.union([

inputs: zod_1.z.array(exports.AbiParameter),
name: zod_1.z.string(),
name: Identifier,
outputs: zod_1.z.array(exports.AbiParameter),

@@ -121,3 +123,3 @@ payable: zod_1.z.boolean().optional(),

inputs: zod_1.z.array(exports.AbiEventParameter),
name: zod_1.z.string(),
name: Identifier,
});

@@ -165,3 +167,3 @@ exports.AbiError = zod_1.z.object({

inputs: zod_1.z.array(exports.AbiParameter),
name: zod_1.z.string(),
name: zod_1.z.string().regex(/[a-zA-Z$_][a-zA-Z0-9$_]*/),
outputs: zod_1.z.array(exports.AbiParameter),

@@ -183,2 +185,77 @@ }),

]));
exports.TypedDataDomain = zod_1.z.object({
chainId: zod_1.z.number().optional(),
name: Identifier.optional(),
salt: zod_1.z.string().optional(),
verifyingContract: exports.Address.optional(),
version: zod_1.z.string().optional(),
});
exports.TypedDataType = zod_1.z.union([
exports.SolidityAddress,
exports.SolidityBool,
exports.SolidityBytes,
exports.SolidityString,
exports.SolidityInt,
exports.SolidityArray,
]);
exports.TypedDataParameter = zod_1.z.object({
name: Identifier,
type: zod_1.z.string(),
});
exports.TypedData = zod_1.z
.record(Identifier, zod_1.z.array(exports.TypedDataParameter))
.transform((val, ctx) => validateTypedDataKeys(val, ctx));
function validateTypedDataKeys(typedData, zodContext) {
const keys = Object.keys(typedData);
for (let i = 0; i < keys.length; i++) {
if ((0, utils_js_1.isSolidityType)(keys[i])) {
zodContext.addIssue({
code: 'custom',
message: `Invalid key. ${keys[i]} is a solidity type.`,
});
return zod_1.z.NEVER;
}
validateTypedDataParameters(keys[i], typedData, zodContext);
}
return typedData;
}
const typeWithoutTupleRegex = /^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*?)(?<array>(?:\[\d*?\])+?)?$/;
function validateTypedDataParameters(key, typedData, zodContext, ancestors = new Set()) {
const val = typedData[key];
const length = val.length;
for (let i = 0; i < length; i++) {
if (val[i]?.type === key) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${key} is a self reference.`,
});
return zod_1.z.NEVER;
}
const match = (0, regex_js_1.execTyped)(typeWithoutTupleRegex, val[i]?.type);
if (!match?.type) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${key} does not have a type.`,
});
return zod_1.z.NEVER;
}
if (match.type in typedData) {
if (ancestors.has(match.type)) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${match.type} is a circular reference.`,
});
return zod_1.z.NEVER;
}
validateTypedDataParameters(match.type, typedData, zodContext, new Set([...ancestors, match.type]));
}
else if (!(0, utils_js_1.isSolidityType)(match.type)) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${match.type} is not a valid EIP-712 type.`,
});
}
}
return;
}
//# sourceMappingURL=zod.js.map

@@ -1,2 +0,2 @@

export const version = '0.10.0-canary.20230712T161506';
export const version = '0.10.0-canary.20230712T202156';
//# sourceMappingURL=version.js.map
import { z } from 'zod';
import { bytesRegex, integerRegex } from './regex.js';
import { isSolidityType } from './human-readable/runtime/utils.js';
import { bytesRegex, execTyped, integerRegex } from './regex.js';
const Identifier = z.string().regex(/[a-zA-Z$_][a-zA-Z0-9$_]*/);
export const Address = z.string().transform((val, ctx) => {

@@ -31,3 +33,3 @@ const regex = /^0x[a-fA-F0-9]{40}$/;

export const AbiParameter = z.lazy(() => z.intersection(z.object({
name: z.string().optional(),
name: Identifier.optional(),
internalType: z.string().optional(),

@@ -74,3 +76,3 @@ }), z.union([

inputs: z.array(AbiParameter),
name: z.string(),
name: Identifier,
outputs: z.array(AbiParameter),

@@ -118,3 +120,3 @@ payable: z.boolean().optional(),

inputs: z.array(AbiEventParameter),
name: z.string(),
name: Identifier,
});

@@ -162,3 +164,3 @@ export const AbiError = z.object({

inputs: z.array(AbiParameter),
name: z.string(),
name: z.string().regex(/[a-zA-Z$_][a-zA-Z0-9$_]*/),
outputs: z.array(AbiParameter),

@@ -180,2 +182,77 @@ }),

]));
export const TypedDataDomain = z.object({
chainId: z.number().optional(),
name: Identifier.optional(),
salt: z.string().optional(),
verifyingContract: Address.optional(),
version: z.string().optional(),
});
export const TypedDataType = z.union([
SolidityAddress,
SolidityBool,
SolidityBytes,
SolidityString,
SolidityInt,
SolidityArray,
]);
export const TypedDataParameter = z.object({
name: Identifier,
type: z.string(),
});
export const TypedData = z
.record(Identifier, z.array(TypedDataParameter))
.transform((val, ctx) => validateTypedDataKeys(val, ctx));
function validateTypedDataKeys(typedData, zodContext) {
const keys = Object.keys(typedData);
for (let i = 0; i < keys.length; i++) {
if (isSolidityType(keys[i])) {
zodContext.addIssue({
code: 'custom',
message: `Invalid key. ${keys[i]} is a solidity type.`,
});
return z.NEVER;
}
validateTypedDataParameters(keys[i], typedData, zodContext);
}
return typedData;
}
const typeWithoutTupleRegex = /^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*?)(?<array>(?:\[\d*?\])+?)?$/;
function validateTypedDataParameters(key, typedData, zodContext, ancestors = new Set()) {
const val = typedData[key];
const length = val.length;
for (let i = 0; i < length; i++) {
if (val[i]?.type === key) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${key} is a self reference.`,
});
return z.NEVER;
}
const match = execTyped(typeWithoutTupleRegex, val[i]?.type);
if (!match?.type) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${key} does not have a type.`,
});
return z.NEVER;
}
if (match.type in typedData) {
if (ancestors.has(match.type)) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${match.type} is a circular reference.`,
});
return z.NEVER;
}
validateTypedDataParameters(match.type, typedData, zodContext, new Set([...ancestors, match.type]));
}
else if (!isSolidityType(match.type)) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${match.type} is not a valid EIP-712 type.`,
});
}
}
return;
}
//# sourceMappingURL=zod.js.map

@@ -1,2 +0,2 @@

export declare const version = "0.10.0-canary.20230712T161506";
export declare const version = "0.10.0-canary.20230712T202156";
//# sourceMappingURL=version.d.ts.map

@@ -312,2 +312,250 @@ import { z } from 'zod';

}), unknown>]>, "many">;
export declare const TypedDataDomain: z.ZodObject<{
chainId: z.ZodOptional<z.ZodNumber>;
name: z.ZodOptional<z.ZodString>;
salt: z.ZodOptional<z.ZodString>;
verifyingContract: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
version: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
chainId?: number | undefined;
name?: string | undefined;
salt?: string | undefined;
verifyingContract?: `0x${string}` | undefined;
version?: string | undefined;
}, {
chainId?: number | undefined;
name?: string | undefined;
salt?: string | undefined;
verifyingContract?: string | undefined;
version?: string | undefined;
}>;
export declare const TypedDataType: z.ZodUnion<[z.ZodLiteral<"address">, z.ZodLiteral<"bool">, z.ZodString, z.ZodLiteral<"string">, z.ZodString, z.ZodUnion<[z.ZodString, z.ZodString]>]>;
export declare const TypedDataParameter: z.ZodObject<{
name: z.ZodString;
type: z.ZodString;
}, "strip", z.ZodTypeAny, {
type: string;
name: string;
}, {
type: string;
name: string;
}>;
export declare const TypedData: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
name: z.ZodString;
type: z.ZodString;
}, "strip", z.ZodTypeAny, {
type: string;
name: string;
}, {
type: string;
name: string;
}>, "many">>, {
[x: string]: readonly import("./abi.js").TypedDataParameter[];
[x: `string[${string}]`]: undefined;
[x: `function[${string}]`]: undefined;
[x: `bytes[${string}]`]: undefined;
[x: `bytes1[${string}]`]: undefined;
[x: `bytes2[${string}]`]: undefined;
[x: `bytes3[${string}]`]: undefined;
[x: `bytes4[${string}]`]: undefined;
[x: `bytes5[${string}]`]: undefined;
[x: `bytes6[${string}]`]: undefined;
[x: `bytes7[${string}]`]: undefined;
[x: `bytes8[${string}]`]: undefined;
[x: `bytes9[${string}]`]: undefined;
[x: `bytes10[${string}]`]: undefined;
[x: `bytes11[${string}]`]: undefined;
[x: `bytes12[${string}]`]: undefined;
[x: `bytes13[${string}]`]: undefined;
[x: `bytes14[${string}]`]: undefined;
[x: `bytes15[${string}]`]: undefined;
[x: `bytes16[${string}]`]: undefined;
[x: `bytes17[${string}]`]: undefined;
[x: `bytes18[${string}]`]: undefined;
[x: `bytes19[${string}]`]: undefined;
[x: `bytes20[${string}]`]: undefined;
[x: `bytes21[${string}]`]: undefined;
[x: `bytes22[${string}]`]: undefined;
[x: `bytes23[${string}]`]: undefined;
[x: `bytes24[${string}]`]: undefined;
[x: `bytes25[${string}]`]: undefined;
[x: `bytes26[${string}]`]: undefined;
[x: `bytes27[${string}]`]: undefined;
[x: `bytes28[${string}]`]: undefined;
[x: `bytes29[${string}]`]: undefined;
[x: `bytes30[${string}]`]: undefined;
[x: `bytes31[${string}]`]: undefined;
[x: `bytes32[${string}]`]: undefined;
[x: `int[${string}]`]: undefined;
[x: `int8[${string}]`]: undefined;
[x: `int16[${string}]`]: undefined;
[x: `int24[${string}]`]: undefined;
[x: `int32[${string}]`]: undefined;
[x: `int40[${string}]`]: undefined;
[x: `int48[${string}]`]: undefined;
[x: `int56[${string}]`]: undefined;
[x: `int64[${string}]`]: undefined;
[x: `int72[${string}]`]: undefined;
[x: `int80[${string}]`]: undefined;
[x: `int88[${string}]`]: undefined;
[x: `int96[${string}]`]: undefined;
[x: `int104[${string}]`]: undefined;
[x: `int112[${string}]`]: undefined;
[x: `int120[${string}]`]: undefined;
[x: `int128[${string}]`]: undefined;
[x: `int136[${string}]`]: undefined;
[x: `int144[${string}]`]: undefined;
[x: `int152[${string}]`]: undefined;
[x: `int160[${string}]`]: undefined;
[x: `int168[${string}]`]: undefined;
[x: `int176[${string}]`]: undefined;
[x: `int184[${string}]`]: undefined;
[x: `int192[${string}]`]: undefined;
[x: `int200[${string}]`]: undefined;
[x: `int208[${string}]`]: undefined;
[x: `int216[${string}]`]: undefined;
[x: `int224[${string}]`]: undefined;
[x: `int232[${string}]`]: undefined;
[x: `int240[${string}]`]: undefined;
[x: `int248[${string}]`]: undefined;
[x: `int256[${string}]`]: undefined;
[x: `uint[${string}]`]: undefined;
[x: `uint8[${string}]`]: undefined;
[x: `uint16[${string}]`]: undefined;
[x: `uint24[${string}]`]: undefined;
[x: `uint32[${string}]`]: undefined;
[x: `uint40[${string}]`]: undefined;
[x: `uint48[${string}]`]: undefined;
[x: `uint56[${string}]`]: undefined;
[x: `uint64[${string}]`]: undefined;
[x: `uint72[${string}]`]: undefined;
[x: `uint80[${string}]`]: undefined;
[x: `uint88[${string}]`]: undefined;
[x: `uint96[${string}]`]: undefined;
[x: `uint104[${string}]`]: undefined;
[x: `uint112[${string}]`]: undefined;
[x: `uint120[${string}]`]: undefined;
[x: `uint128[${string}]`]: undefined;
[x: `uint136[${string}]`]: undefined;
[x: `uint144[${string}]`]: undefined;
[x: `uint152[${string}]`]: undefined;
[x: `uint160[${string}]`]: undefined;
[x: `uint168[${string}]`]: undefined;
[x: `uint176[${string}]`]: undefined;
[x: `uint184[${string}]`]: undefined;
[x: `uint192[${string}]`]: undefined;
[x: `uint200[${string}]`]: undefined;
[x: `uint208[${string}]`]: undefined;
[x: `uint216[${string}]`]: undefined;
[x: `uint224[${string}]`]: undefined;
[x: `uint232[${string}]`]: undefined;
[x: `uint240[${string}]`]: undefined;
[x: `uint248[${string}]`]: undefined;
[x: `uint256[${string}]`]: undefined;
[x: `address[${string}]`]: undefined;
[x: `bool[${string}]`]: undefined;
string?: never;
bytes?: never;
bytes1?: never;
bytes2?: never;
bytes3?: never;
bytes4?: never;
bytes5?: never;
bytes6?: never;
bytes7?: never;
bytes8?: never;
bytes9?: never;
bytes10?: never;
bytes11?: never;
bytes12?: never;
bytes13?: never;
bytes14?: never;
bytes15?: never;
bytes16?: never;
bytes17?: never;
bytes18?: never;
bytes19?: never;
bytes20?: never;
bytes21?: never;
bytes22?: never;
bytes23?: never;
bytes24?: never;
bytes25?: never;
bytes26?: never;
bytes27?: never;
bytes28?: never;
bytes29?: never;
bytes30?: never;
bytes31?: never;
bytes32?: never;
int8?: never;
int16?: never;
int24?: never;
int32?: never;
int40?: never;
int48?: never;
int56?: never;
int64?: never;
int72?: never;
int80?: never;
int88?: never;
int96?: never;
int104?: never;
int112?: never;
int120?: never;
int128?: never;
int136?: never;
int144?: never;
int152?: never;
int160?: never;
int168?: never;
int176?: never;
int184?: never;
int192?: never;
int200?: never;
int208?: never;
int216?: never;
int224?: never;
int232?: never;
int240?: never;
int248?: never;
int256?: never;
uint8?: never;
uint16?: never;
uint24?: never;
uint32?: never;
uint40?: never;
uint48?: never;
uint56?: never;
uint64?: never;
uint72?: never;
uint80?: never;
uint88?: never;
uint96?: never;
uint104?: never;
uint112?: never;
uint120?: never;
uint128?: never;
uint136?: never;
uint144?: never;
uint152?: never;
uint160?: never;
uint168?: never;
uint176?: never;
uint184?: never;
uint192?: never;
uint200?: never;
uint208?: never;
uint216?: never;
uint224?: never;
uint232?: never;
uint240?: never;
uint248?: never;
uint256?: never;
address?: never;
bool?: never;
}, Record<string, {
type: string;
name: string;
}[]>>;
//# sourceMappingURL=zod.d.ts.map
{
"name": "abitype",
"description": "Strict TypeScript types for Ethereum ABIs",
"version": "0.10.0-canary.20230712T161506",
"version": "0.10.0-canary.20230712T202156",
"license": "MIT",

@@ -6,0 +6,0 @@ "repository": "wagmi-dev/abitype",

@@ -1,1 +0,1 @@

export const version = '0.10.0-canary.20230712T161506'
export const version = '0.10.0-canary.20230712T202156'

@@ -10,5 +10,10 @@ import { z } from 'zod'

Address as AddressType,
TypedData as TTypedData,
} from './abi.js'
import { bytesRegex, integerRegex } from './regex.js'
import { isSolidityType } from './human-readable/runtime/utils.js'
import { bytesRegex, execTyped, integerRegex } from './regex.js'
const Identifier = z.string().regex(/[a-zA-Z$_][a-zA-Z0-9$_]*/)
export const Address = z.string().transform((val, ctx) => {

@@ -51,3 +56,3 @@ const regex = /^0x[a-fA-F0-9]{40}$/

z.object({
name: z.string().optional(),
name: Identifier.optional(),
/** Representation used by Solidity compiler */

@@ -112,3 +117,3 @@ internalType: z.string().optional(),

inputs: z.array(AbiParameter),
name: z.string(),
name: Identifier,
outputs: z.array(AbiParameter),

@@ -185,3 +190,3 @@ /**

inputs: z.array(AbiEventParameter),
name: z.string(),
name: Identifier,
})

@@ -242,2 +247,3 @@

}
return val

@@ -268,3 +274,3 @@ },

inputs: z.array(AbiParameter),
name: z.string(),
name: z.string().regex(/[a-zA-Z$_][a-zA-Z0-9$_]*/),
outputs: z.array(AbiParameter),

@@ -289,1 +295,115 @@ }),

)
////////////////////////////////////////////////////////////////////////////////////////////////////
// Typed Data Types
export const TypedDataDomain = z.object({
chainId: z.number().optional(),
name: Identifier.optional(),
salt: z.string().optional(),
verifyingContract: Address.optional(),
version: z.string().optional(),
})
export const TypedDataType = z.union([
SolidityAddress,
SolidityBool,
SolidityBytes,
SolidityString,
SolidityInt,
SolidityArray,
])
export const TypedDataParameter = z.object({
name: Identifier,
type: z.string(),
})
export const TypedData = z
.record(Identifier, z.array(TypedDataParameter))
.transform((val, ctx) => validateTypedDataKeys(val, ctx))
// Helper Functions.
function validateTypedDataKeys(
typedData: Record<string, { type: string; name: string }[]>,
zodContext: z.RefinementCtx,
): TTypedData {
const keys = Object.keys(typedData)
for (let i = 0; i < keys.length; i++) {
if (isSolidityType(keys[i]!)) {
zodContext.addIssue({
code: 'custom',
message: `Invalid key. ${keys[i]} is a solidity type.`,
})
return z.NEVER
}
validateTypedDataParameters(keys[i]!, typedData, zodContext)
}
return typedData as any
}
const typeWithoutTupleRegex =
/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*?)(?<array>(?:\[\d*?\])+?)?$/
function validateTypedDataParameters(
key: string,
typedData: Record<string, { type: string; name: string }[]>,
zodContext: z.RefinementCtx,
ancestors = new Set<string>(),
) {
const val = typedData[key] as { type: string; name: string }[]
const length = val.length
for (let i = 0; i < length; i++) {
if (val[i]?.type! === key) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${key} is a self reference.`,
})
return z.NEVER
}
const match = execTyped<{ array?: string; type: string }>(
typeWithoutTupleRegex,
val[i]?.type!,
)
if (!match?.type) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${key} does not have a type.`,
})
return z.NEVER
}
if (match.type in typedData) {
if (ancestors.has(match.type)) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${match.type} is a circular reference.`,
})
return z.NEVER
}
validateTypedDataParameters(
match.type,
typedData,
zodContext,
new Set([...ancestors, match.type]),
)
} else if (!isSolidityType(match.type)) {
zodContext.addIssue({
code: 'custom',
message: `Invalid type. ${match.type} is not a valid EIP-712 type.`,
})
}
}
return
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc