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

abitype

Package Overview
Dependencies
Maintainers
2
Versions
180
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.0.10 to 0.0.11

24

dist/abi.d.ts

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

import { Config, DefaultConfig } from './config';
import { ResolvedConfig } from './config';
import { Range } from './types';

@@ -13,10 +13,7 @@ export declare type Address = `0x${string}`;

export declare type SolidityInt = `${'u' | ''}int${MBits}`;
declare type FixedArrayLowerBound = Config['FixedArrayLengthLowerBound'] extends number ? Config['FixedArrayLengthLowerBound'] : DefaultConfig['FixedArrayLengthLowerBound'];
declare type FixedArrayUpperBound = Config['FixedArrayLengthUpperBound'] extends number ? Config['FixedArrayLengthUpperBound'] : DefaultConfig['FixedArrayLengthUpperBound'];
export declare type SolidityFixedArrayRange = Range<FixedArrayLowerBound, FixedArrayUpperBound>[number];
export declare type SolidityFixedArrayRange = Range<ResolvedConfig['FixedArrayLengthLowerBound'], ResolvedConfig['FixedArrayLengthUpperBound']>[number];
export declare type SolidityFixedArraySizeLookup = {
[Prop in SolidityFixedArrayRange as `${Prop}`]: Prop;
};
declare type MAXIMUM_DEPTH = Config['ArrayMaxDepth'] extends number ? Config['ArrayMaxDepth'] : DefaultConfig['ArrayMaxDepth'];
declare type BuildArrayTypes<T extends string, Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? T : T extends `${any}[${SolidityFixedArrayRange | ''}]` ? BuildArrayTypes<T | `${T}[${SolidityFixedArrayRange | ''}]`, [...Depth, 1]> : BuildArrayTypes<`${T}[${SolidityFixedArrayRange | ''}]`, [...Depth, 1]>;
declare type BuildArrayTypes<T extends string, Depth extends ReadonlyArray<number> = []> = ResolvedConfig['ArrayMaxDepth'] extends false ? `${T}[${string}]` : Depth['length'] extends ResolvedConfig['ArrayMaxDepth'] ? T : T extends `${any}[${SolidityFixedArrayRange | ''}]` ? BuildArrayTypes<T | `${T}[${SolidityFixedArrayRange | ''}]`, [...Depth, 1]> : BuildArrayTypes<`${T}[${SolidityFixedArrayRange | ''}]`, [...Depth, 1]>;
export declare type SolidityArrayWithoutTuple = BuildArrayTypes<SolidityAddress | SolidityBool | SolidityBytes | SolidityFunction | SolidityInt | SolidityString>;

@@ -85,6 +82,17 @@ export declare type SolidityArrayWithTuple = BuildArrayTypes<SolidityTuple>;

/**
* Contract ABI Specification
* https://docs.soliditylang.org/en/latest/abi-spec.html#json
* Contract [ABI Specification](https://docs.soliditylang.org/en/latest/abi-spec.html#json)
*/
export declare type Abi = readonly (AbiFunction | AbiEvent | AbiError)[];
export declare type TypedDataType = Exclude<AbiType, SolidityArray | SolidityFunction | SolidityTuple> | SolidityArrayWithoutTuple;
/**
* [EIP-712](https://eips.ethereum.org/EIPS/eip-712#definition-of-typed-structured-data-%F0%9D%95%8A) Typed Data Specification
*/
export declare type TypedData = {
[key: string]: readonly {
name: string;
type: TypedDataType | keyof TypedData | `${keyof TypedData}[${string | ''}]`;
}[];
} & {
[_ in TypedDataType]?: never;
};
export {};
/**
* Override `Config` to customize type options
*
* ```
* // create abitype.d.ts in your project source
* // if it isn't being picked up, check tsconfig compilerOptions.types
* @example
* declare module 'abitype' {
* export interface Config {
* FixedArrayUpperBound: 6
* FixedArrayLengthUpperBound: 6
* }
* }
* ```
*/

@@ -25,1 +22,6 @@ export interface Config {

}
export interface ResolvedConfig {
ArrayMaxDepth: Config['ArrayMaxDepth'] extends number | false ? Config['ArrayMaxDepth'] : DefaultConfig['ArrayMaxDepth'];
FixedArrayLengthLowerBound: Config['FixedArrayLengthLowerBound'] extends number ? Config['FixedArrayLengthLowerBound'] : DefaultConfig['FixedArrayLengthLowerBound'];
FixedArrayLengthUpperBound: Config['FixedArrayLengthUpperBound'] extends number ? Config['FixedArrayLengthUpperBound'] : DefaultConfig['FixedArrayLengthUpperBound'];
}

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

export type { Abi, AbiError, AbiEvent, AbiFunction, AbiInternalType, AbiParameter, AbiStateMutability, AbiType, Address, SolidityAddress, SolidityArray, SolidityArrayWithoutTuple, SolidityArrayWithTuple, SolidityBool, SolidityBytes, SolidityFixedArrayRange, SolidityFixedArraySizeLookup, SolidityFunction, SolidityInt, SolidityString, SolidityTuple, } from './abi';
export type { Abi, AbiError, AbiEvent, AbiFunction, AbiInternalType, AbiParameter, AbiStateMutability, AbiType, Address, SolidityAddress, SolidityArray, SolidityArrayWithoutTuple, SolidityArrayWithTuple, SolidityBool, SolidityBytes, SolidityFixedArrayRange, SolidityFixedArraySizeLookup, SolidityFunction, SolidityInt, SolidityString, SolidityTuple, TypedData, TypedDataType, } from './abi';
export type { Config, DefaultConfig } from './config';
export type { AbiEventSignature, AbiFunctionSignature, AbiParameterToPrimitiveType, AbiParametersToPrimitiveTypes, AbiTypeToPrimitiveType, ExtractAbiError, ExtractAbiErrorNames, ExtractAbiErrors, ExtractAbiEvent, ExtractAbiEventNames, ExtractAbiEvents, ExtractAbiFunction, ExtractAbiFunctionNames, ExtractAbiFunctions, IsAbi, } from './utils';
export type { AbiEventSignature, AbiFunctionSignature, AbiParameterToPrimitiveType, AbiParametersToPrimitiveTypes, AbiTypeToPrimitiveType, ExtractAbiError, ExtractAbiErrorNames, ExtractAbiErrors, ExtractAbiEvent, ExtractAbiEventNames, ExtractAbiEvents, ExtractAbiFunction, ExtractAbiFunctionNames, ExtractAbiFunctions, IsAbi, TypedDataToPrimitiveTypes, } from './utils';

@@ -14,7 +14,7 @@ /**

/**
* Create tuple of {@link TType} type with {@link TSize} size
* Create tuple of {@link Type} type with {@link Size} size
*
* @param TType - Type of tuple
* @param TSize - Size of tuple
* @returns Tuple of {@link TType} type with {@link TSize} size
* @param Type - Type of tuple
* @param Size - Size of tuple
* @returns Tuple of {@link Type} type with {@link Size} size
*

@@ -25,4 +25,15 @@ * @example

*/
export declare type Tuple<TType, TSize extends number> = TSize extends TSize ? number extends TSize ? TType[] : _TupleOf<TType, TSize, []> : never;
export declare type Tuple<Type, Size extends number> = Size extends Size ? number extends Size ? Type[] : _TupleOf<Type, Size, []> : never;
declare type _TupleOf<TNumber, TSize extends number, R extends unknown[]> = R['length'] extends TSize ? R : _TupleOf<TNumber, TSize, [TNumber, ...R]>;
/**
* Merges two types into new type
*
* @param Object1 - Object to merge into
* @param Object2 - Object to merge and override keys from {@link Object1}
*
* @example
* type Result = Merge<{ foo: string }, { foo: number; bar: string }>
* { foo: number; bar: string }
*/
export declare type Merge<Object1, Object2> = Omit<Object1, keyof Object2> & Object2;
export {};

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

import { Abi, AbiEvent, AbiFunction, AbiParameter, AbiStateMutability, AbiType, Address, SolidityAddress, SolidityArray, SolidityBool, SolidityBytes, SolidityFixedArrayRange, SolidityFixedArraySizeLookup, SolidityFunction, SolidityInt, SolidityString, SolidityTuple } from './abi';
import { Tuple } from './types';
import { Abi, AbiEvent, AbiFunction, AbiParameter, AbiStateMutability, AbiType, Address, SolidityAddress, SolidityArray, SolidityBool, SolidityBytes, SolidityFixedArrayRange, SolidityFixedArraySizeLookup, SolidityFunction, SolidityInt, SolidityString, SolidityTuple, TypedData } from './abi';
import { Merge, Tuple } from './types';
/**

@@ -42,11 +42,7 @@ * Converts {@link AbiType} to corresponding TypeScript primitive type.

})['components'][number] as Component['name']]: AbiParameterToPrimitiveType<Component>;
} : TAbiParameter['type'] extends `${infer Head}[${'' | `${SolidityFixedArrayRange}`}]` ? TAbiParameter['type'] extends `${Head}[${infer Size}]` ? Size extends keyof SolidityFixedArraySizeLookup ? Tuple<AbiParameterToPrimitiveType<_ConvertAbiParameterType<TAbiParameter, Head>>, SolidityFixedArraySizeLookup[Size]> : AbiParameterToPrimitiveType<_ConvertAbiParameterType<TAbiParameter, Head>>[] : never : unknown;
declare type _ConvertAbiParameterType<TAbiParameter extends AbiParameter | {
name: string;
type: unknown;
}, TType extends AbiType | string> = {
[Property in keyof Omit<TAbiParameter, 'type'>]: TAbiParameter[Property];
} & {
type: TType;
};
} : TAbiParameter['type'] extends `${infer Head}[${'' | `${SolidityFixedArrayRange}`}]` ? TAbiParameter['type'] extends `${Head}[${infer Size}]` ? Size extends keyof SolidityFixedArraySizeLookup ? Tuple<AbiParameterToPrimitiveType<Merge<TAbiParameter, {
type: Head;
}>>, SolidityFixedArraySizeLookup[Size]> : AbiParameterToPrimitiveType<Merge<TAbiParameter, {
type: Head;
}>>[] : never : unknown;
/**

@@ -165,2 +161,31 @@ * Converts array of {@link AbiParameter} to corresponding TypeScript primitive types.

}>;
/**
* Converts {@link TTypedData} to corresponding TypeScript primitive types.
*
* @param TTypedData - {@link TypedData} to convert
* @returns Union of TypeScript primitive types
*/
export declare type TypedDataToPrimitiveTypes<TTypedData extends TypedData> = {
[K in keyof TTypedData]: {
[K2 in TTypedData[K][number] as K2['name']]: K2['type'] extends keyof TTypedData ? TypedDataToPrimitiveTypes<Exclude<TTypedData, K>>[K2['type']] : K2['type'] extends `${infer TType extends keyof TTypedData & string}[${infer Tail}]` ? AbiParameterToPrimitiveType<Merge<K2, {
type: `tuple[${Tail}]`;
components: _ConvertObjectsToComponents<TTypedData[TType], TTypedData>;
}>> : AbiParameterToPrimitiveType<K2>;
};
};
declare type _ConvertObjectsToComponents<TObjects extends readonly {
name: string;
type: unknown;
}[], TTypes extends TypedData> = {
[K in keyof TObjects]: TObjects[K] extends infer TObject extends {
name: string;
type: unknown;
} ? TObject['type'] extends keyof TTypes ? Merge<TObject, {
type: `tuple`;
components: _ConvertObjectsToComponents<TTypes[TObject['type']], TTypes>;
}> : TObject['type'] extends `${infer TType extends keyof TTypes & string}[${infer Tail}]` ? Merge<TObject, {
type: `tuple[${Tail}]`;
components: _ConvertObjectsToComponents<TTypes[TType], TTypes>;
}> : TObject : never;
};
export {};

@@ -5,3 +5,3 @@ {

"license": "WAGMIT",
"version": "0.0.10",
"version": "0.0.11",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -196,2 +196,4 @@ # AbiType

```ts
import { AbiEventSignature } from 'abitype'
type Result = AbiEventSignature<ExtractAbiEvent<typeof erc721Abi, 'Transfer'>>

@@ -205,2 +207,4 @@ ```

```ts
import { AbiFunctionSignature } from 'abitype'
type Result = AbiFunctionSignature<

@@ -211,2 +215,22 @@ ExtractAbiFunction<typeof erc721Abi, 'balanceOf'>

### TypedDataToPrimitiveTypes
Converts [EIP-712](https://eips.ethereum.org/EIPS/eip-712#definition-of-typed-structured-data-%F0%9D%95%8A) `TypedData` to corresponding TypeScript primitive type.
```ts
import { TypedDataToPrimitiveTypes } from 'abitype'
type Result = TypedDataToPrimitiveTypes<{
Person: [
{ name: 'name'; type: 'string' },
{ name: 'wallet'; type: 'address' },
]
Mail: [
{ name: 'from'; type: 'Person' },
{ name: 'to'; type: 'Person' },
{ name: 'contents'; type: 'string' },
]
}>
```
## Types

@@ -303,2 +327,18 @@

### TypedDataType
Subset of `AbiType` that excludes `tuple` and `function`
```ts
import { TypedDataType } from 'abitype'
```
### TypedData
[EIP-712](https://eips.ethereum.org/EIPS/eip-712#definition-of-typed-structured-data-%F0%9D%95%8A) Typed Data Specification
```ts
import { TypedData } from 'abitype'
```
## Configuration

@@ -308,7 +348,9 @@

- **`ArrayMaxDepth`** — Maximum depth for nested array types (e.g. `string[][]`). Defaults to `2`.
- **`FixedArrayLengthLowerBound`** — Lower bound for fixed array length. Defaults to `1`.
- **`FixedArrayLengthUpperBound`** — Upper bound for fixed array length. Defaults to `5`.
| Option | Type | Default | Description |
| ---------------------------- | ----------------- | ------- | -------------------------------------------------------------------------------------------------------- |
| `ArrayMaxDepth` | `number \| false` | `2` | Maximum depth for nested array types (e.g. `string[][]`). When `false`, there is no maximum array depth. |
| `FixedArrayLengthLowerBound` | `number` | `1` | Lower bound for fixed array length |
| `FixedArrayLengthUpperBound` | `number` | `5` | Upper bound for fixed array length |
Configuration options are customizable using [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html). First, create a declaration file (e.g. `abitype.d.ts`) in your project source and then extend the `Config` interface:
Configuration options are customizable using [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html). Just extend the `Config` interface either directly in your code or in a `d.ts` file (e.g. `abi.d.ts`):

@@ -315,0 +357,0 @@ ```ts

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