You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@dfinity/principal

Package Overview
Dependencies
Maintainers
0
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dfinity/principal

JavaScript and TypeScript library to work with Internet Computer principals

3.1.0
latest
Source
npmnpm
Version published
Weekly downloads
140K
-15.88%
Maintainers
0
Weekly downloads
 
Created

What is @dfinity/principal?

@dfinity/principal is an npm package used for handling Principal IDs in the DFINITY Internet Computer ecosystem. It provides utilities for creating, parsing, and validating Principal IDs, which are unique identifiers for canisters and users on the Internet Computer.

What are @dfinity/principal's main functionalities?

Create a Principal

This feature allows you to create a Principal object from a text representation. The code sample demonstrates how to create a Principal from a text string and then convert it back to a text representation.

const { Principal } = require('@dfinity/principal');
const principal = Principal.fromText('aaaaa-aa');
console.log(principal.toText());

Validate a Principal

This feature is used to validate a Principal ID. The code sample shows how to attempt to create a Principal from a text string and handle any errors if the Principal is invalid.

const { Principal } = require('@dfinity/principal');
try {
  const principal = Principal.fromText('aaaaa-aa');
  console.log('Valid Principal:', principal.toText());
} catch (error) {
  console.error('Invalid Principal:', error);
}

Convert Principal to Uint8Array

This feature allows you to convert a Principal to a Uint8Array, which is useful for low-level operations or when working with binary data. The code sample demonstrates this conversion.

const { Principal } = require('@dfinity/principal');
const principal = Principal.fromText('aaaaa-aa');
const bytes = principal.toUint8Array();
console.log(bytes);

Other packages similar to @dfinity/principal

Keywords

internet computer

FAQs

Package last updated on 24 Jul 2025

Did you know?

Socket

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.

Install

Related posts