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

@dfinity/utils

Package Overview
Dependencies
Maintainers
10
Versions
890
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dfinity/utils

A collection of utilities and constants for NNS/SNS projects.

  • 0.0.5-next-2022-10-09
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.2K
increased by7.2%
Maintainers
10
Weekly downloads
 
Created
Source

utils-js

A collection of utilities and constants for NNS/SNS projects.

npm version GitHub license

Table of contents

Installation

You can use utils-js by installing it in your project.

npm i @dfinity/utils

The bundle needs peer dependencies, be sure that following resources are available in your project as well.

npm i @dfinity/agent @dfinity/candid @dfinity/principal

Features

utils-js implements following features:

:toolbox: Functions

:gear: defaultAgent

Get a default agent that connects to mainnet with the anonymous identity.

FunctionType
defaultAgent() => Agent
:gear: createAgent

Create an agent for a given identity

FunctionType
createAgent({ identity, host, fetchRootKey, }: { identity: Identity; host?: string; fetchRootKey?: boolean; }) => Promise<HttpAgent>

Parameters:

  • identity: A mandatory identity to use for the agent
  • host: An optional host to connect to
  • fetchRootKey: Fetch root key for certificate validation during local development or on testnet
:gear: createServices
FunctionType
createServices<T>({ options: { canisterId, serviceOverride, certifiedServiceOverride, agent: agentOption, }, idlFactory, certifiedIdlFactory, }: { options: RequiredCanisterOptions<T>; idlFactory: InterfaceFactory; certifiedIdlFactory: InterfaceFactory; }) => { ...; }
:gear: uint8ArrayToBigInt
FunctionType
uint8ArrayToBigInt(array: Uint8Array) => bigint
:gear: arrayBufferToUint8Array
FunctionType
arrayBufferToUint8Array(buffer: ArrayBuffer) => Uint8Array
:gear: uint8ArrayToArrayOfNumber
FunctionType
uint8ArrayToArrayOfNumber(array: Uint8Array) => number[]
:gear: arrayOfNumberToUint8Array
FunctionType
arrayOfNumberToUint8Array(numbers: number[]) => Uint8Array
:gear: asciiStringToByteArray
FunctionType
asciiStringToByteArray(text: string) => number[]
:gear: assertNonNullish
FunctionType
assertNonNullish<T>(value: T, message?: string) => asserts value is NonNullable<T>
:gear: toNullable
FunctionType
toNullable<T>(value?: T) => [] or [T]
:gear: fromNullable
FunctionType
fromNullable<T>(value: [] or [T]) => T
:gear: fromDefinedNullable
FunctionType
fromDefinedNullable<T>(value: [] or [T]) => T
:gear: principalToSubAccount

Convert a principal to a Uint8Array 32 length. e.g. Useful to convert a canister ID when topping up cycles with the Cmc canister

FunctionType
principalToSubAccount(principal: Principal) => Uint8Array

Parameters:

  • principal: The principal that needs to be converted to Subaccount

:factory: NullishError

Constructors

public

Parameters:

  • message

Keywords

FAQs

Package last updated on 09 Oct 2022

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

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