
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
asn1tools-js
Advanced tools
ASN.1 encoding and decoding library for TypeScript/JavaScript, compatible with Python asn1tools
A TypeScript implementation of ASN.1 (Abstract Syntax Notation One) encoding and decoding library, designed to be compatible with the Python asn1tools library. This library provides comprehensive support for message encoding/decoding in distributed systems and network protocols.
asn1tools for easy migrationnpm install asn1tools-js
import { compileString } from 'asn1tools-js';
const schema = `
Messages DEFINITIONS ::= BEGIN
DataRequest ::= SEQUENCE {
messageId INTEGER,
version INTEGER,
category INTEGER,
size INTEGER
}
END
`;
const spec = compileString(schema);
const encoded = spec.encode('DataRequest', {
messageId: 123,
version: 1,
category: 2,
size: 500
});
const decoded = spec.decode('DataRequest', encoded);
OER produces a more compact, fixed-layout wire format. Pass { codec: 'oer' } when compiling:
import { compileString } from 'asn1tools-js';
const schema = `
Messages DEFINITIONS ::= BEGIN
BYTE ::= INTEGER (-128..127)
SHORT ::= INTEGER (-32768..32767)
INT ::= INTEGER (-2147483648..2147483647)
LONG ::= INTEGER (-9223372036854775808..9223372036854775807)
SimpleMessage ::= SEQUENCE {
id LONG,
flag BOOLEAN,
data OCTET STRING (SIZE(20))
}
END
`;
const spec = compileString(schema, { codec: 'oer' });
const encoded = spec.encode('SimpleMessage', {
id: 42n,
flag: true,
data: new Uint8Array(20).fill(0xAB)
});
const decoded = spec.decode('SimpleMessage', encoded);
Key differences from BER:
| Feature | BER | OER |
|---|---|---|
| Encoding layout | Tag-Length-Value (TLV) | Fixed-width, no tag/length for known-size types |
| Integer encoding | Variable-length, minimal octets | Fixed-width based on range constraint |
| BOOLEAN | 3 bytes (tag + length + value) | 1 byte (0x00 / 0x01) |
| SEQUENCE wrapper | Tag + length + members | Members concatenated directly |
| SEQUENCE OF count | Wrapped in SEQUENCE TLV | OER length-determinant prefix |
| CHOICE tag | BER context-specific tag | 1-byte index |
| Single-pass encode | No (requires length pre-calculation) | Yes |
| ASN.1 Type | OER Encoding |
|---|---|
| BOOLEAN | 1 byte (0x00 = false, 0x01 = true) |
| INTEGER with range constraint | Fixed-width (1/2/4/8 bytes) based on range |
| OCTET STRING (SIZE(N)) | N bytes, raw |
| SEQUENCE | Concatenation of member encodings |
| SEQUENCE OF | Length-determinant count + concatenated elements |
| CHOICE | 1-byte tag index + selected alternative |
The OER length-determinant for SEQUENCE OF counts:
import { hexToBytes, bytesToHex } from 'asn1tools-js';
const identifier = hexToBytes('973539beb5008a29ca866b178ce99f2782b5e39a');
const hexString = bytesToHex(identifier);
| ASN.1 Type | TypeScript Mapping | Description |
|---|---|---|
INTEGER | number | bigint | Signed integers with automatic bigint handling |
BOOLEAN | boolean | True/false values |
OCTET STRING | Uint8Array | Binary data, identifiers, checksums |
NULL | null | Null values |
ENUMERATED | string | Named enumeration values |
SEQUENCE | object | Structured data objects |
SEQUENCE OF | Array<T> | Arrays of elements |
CHOICE | object | Union types with single active member |
compileFiles(filenames: string[], options?: CompileOptions): SpecificationCompiles ASN.1 files into a specification object.
const spec = compileFiles(['messages.asn'], { codec: 'oer' });
compileString(content: string, options?: CompileOptions): SpecificationCompiles ASN.1 content from a string.
const spec = compileString(asnContent); // BER (default)
const spec = compileString(asnContent, { codec: 'oer' }); // OER
CompileOptions| Option | Type | Default | Description |
|---|---|---|---|
codec | 'ber' | 'oer' | 'ber' | Encoding rules to use |
encode(typeName: string, value: any): Uint8Array — Encode a value using the specified typedecode(typeName: string, data: Uint8Array): any — Decode binary data using the specified typegetTypeNames(): string[] — Returns all available type namesgetModuleNames(): string[] — Returns all available module namesnpm test
The library includes comprehensive tests for both BER and OER:
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
ASN.1 encoding and decoding library for TypeScript/JavaScript, compatible with Python asn1tools
We found that asn1tools-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.