Socket
Socket
Sign inDemoInstall

@dfinity/principal

Package Overview
Dependencies
Maintainers
10
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dfinity/principal - npm Package Compare versions

Comparing version 0.20.2 to 0.21.1

9

lib/cjs/index.d.ts

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

export declare const JSON_KEY_PRINCIPAL = "__principal__";
export declare type JsonnablePrincipal = {
[JSON_KEY_PRINCIPAL]: string;
};
export declare class Principal {

@@ -26,7 +22,2 @@ private _arr;

/**
* Serializes to JSON
* @returns {JsonnablePrincipal} a JSON object with a single key, {@link JSON_KEY_PRINCIPAL}, whose value is the principal as a string
*/
toJSON(): JsonnablePrincipal;
/**
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification

@@ -33,0 +24,0 @@ * @param {Principal} other - a {@link Principal} to compare

35

lib/cjs/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Principal = exports.JSON_KEY_PRINCIPAL = void 0;
exports.Principal = void 0;
const base32_1 = require("./utils/base32");
const getCrc_1 = require("./utils/getCrc");
const sha224_1 = require("./utils/sha224");
exports.JSON_KEY_PRINCIPAL = '__principal__';
const SELF_AUTHENTICATING_SUFFIX = 2;

@@ -14,6 +13,2 @@ const ANONYMOUS_SUFFIX = 4;

class Principal {
constructor(_arr) {
this._arr = _arr;
this._isPrincipal = true;
}
static anonymous() {

@@ -37,5 +32,2 @@ return new this(new Uint8Array([ANONYMOUS_SUFFIX]));

}
else if (Object.getPrototypeOf(other) === Uint8Array.prototype) {
return new Principal(other);
}
else if (typeof other === 'object' &&

@@ -52,16 +44,8 @@ other !== null &&

static fromText(text) {
let maybePrincipal = text;
// If formatted as JSON string, parse it first
if (text.includes(exports.JSON_KEY_PRINCIPAL)) {
const obj = JSON.parse(text);
if (exports.JSON_KEY_PRINCIPAL in obj) {
maybePrincipal = obj[exports.JSON_KEY_PRINCIPAL];
}
}
const canisterIdNoDash = maybePrincipal.toLowerCase().replace(/-/g, '');
const canisterIdNoDash = text.toLowerCase().replace(/-/g, '');
let arr = (0, base32_1.decode)(canisterIdNoDash);
arr = arr.slice(4, arr.length);
const principal = new this(arr);
if (principal.toText() !== maybePrincipal) {
throw new Error(`Principal "${principal.toText()}" does not have a valid checksum (original value "${maybePrincipal}" may not be a valid Principal ID).`);
if (principal.toText() !== text) {
throw new Error(`Principal "${principal.toText()}" does not have a valid checksum (original value "${text}" may not be a valid Principal ID).`);
}

@@ -73,2 +57,6 @@ return principal;

}
constructor(_arr) {
this._arr = _arr;
this._isPrincipal = true;
}
isAnonymous() {

@@ -102,9 +90,2 @@ return this._arr.byteLength === 1 && this._arr[0] === ANONYMOUS_SUFFIX;

/**
* Serializes to JSON
* @returns {JsonnablePrincipal} a JSON object with a single key, {@link JSON_KEY_PRINCIPAL}, whose value is the principal as a string
*/
toJSON() {
return { [exports.JSON_KEY_PRINCIPAL]: this.toText() };
}
/**
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification

@@ -111,0 +92,0 @@ * @param {Principal} other - a {@link Principal} to compare

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decode = exports.encode = void 0;
// tslint:disable:no-bitwise
const alphabet = 'abcdefghijklmnopqrstuvwxyz234567';

@@ -5,0 +6,0 @@ // Build a lookup table for decoding.

"use strict";
// tslint:disable:no-bitwise
Object.defineProperty(exports, "__esModule", { value: true });

@@ -47,2 +48,3 @@ exports.getCrc32 = void 0;

let crc = -1;
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < b.length; i++) {

@@ -49,0 +51,0 @@ const byte = b[i];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sha224 = void 0;
const sha256_1 = require("@noble/hashes/sha256");
const js_sha256_1 = require("js-sha256");
/**

@@ -10,5 +10,7 @@ * Returns the SHA224 hash of the buffer.

function sha224(data) {
return sha256_1.sha224.create().update(new Uint8Array(data)).digest();
const shaObj = js_sha256_1.sha224.create();
shaObj.update(data);
return new Uint8Array(shaObj.array());
}
exports.sha224 = sha224;
//# sourceMappingURL=sha224.js.map

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

export declare const JSON_KEY_PRINCIPAL = "__principal__";
export declare type JsonnablePrincipal = {
[JSON_KEY_PRINCIPAL]: string;
};
export declare class Principal {

@@ -26,7 +22,2 @@ private _arr;

/**
* Serializes to JSON
* @returns {JsonnablePrincipal} a JSON object with a single key, {@link JSON_KEY_PRINCIPAL}, whose value is the principal as a string
*/
toJSON(): JsonnablePrincipal;
/**
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification

@@ -33,0 +24,0 @@ * @param {Principal} other - a {@link Principal} to compare

import { decode, encode } from './utils/base32';
import { getCrc32 } from './utils/getCrc';
import { sha224 } from './utils/sha224';
export const JSON_KEY_PRINCIPAL = '__principal__';
const SELF_AUTHENTICATING_SUFFIX = 2;

@@ -11,6 +10,2 @@ const ANONYMOUS_SUFFIX = 4;

export class Principal {
constructor(_arr) {
this._arr = _arr;
this._isPrincipal = true;
}
static anonymous() {

@@ -34,5 +29,2 @@ return new this(new Uint8Array([ANONYMOUS_SUFFIX]));

}
else if (Object.getPrototypeOf(other) === Uint8Array.prototype) {
return new Principal(other);
}
else if (typeof other === 'object' &&

@@ -49,16 +41,8 @@ other !== null &&

static fromText(text) {
let maybePrincipal = text;
// If formatted as JSON string, parse it first
if (text.includes(JSON_KEY_PRINCIPAL)) {
const obj = JSON.parse(text);
if (JSON_KEY_PRINCIPAL in obj) {
maybePrincipal = obj[JSON_KEY_PRINCIPAL];
}
}
const canisterIdNoDash = maybePrincipal.toLowerCase().replace(/-/g, '');
const canisterIdNoDash = text.toLowerCase().replace(/-/g, '');
let arr = decode(canisterIdNoDash);
arr = arr.slice(4, arr.length);
const principal = new this(arr);
if (principal.toText() !== maybePrincipal) {
throw new Error(`Principal "${principal.toText()}" does not have a valid checksum (original value "${maybePrincipal}" may not be a valid Principal ID).`);
if (principal.toText() !== text) {
throw new Error(`Principal "${principal.toText()}" does not have a valid checksum (original value "${text}" may not be a valid Principal ID).`);
}

@@ -70,2 +54,6 @@ return principal;

}
constructor(_arr) {
this._arr = _arr;
this._isPrincipal = true;
}
isAnonymous() {

@@ -99,9 +87,2 @@ return this._arr.byteLength === 1 && this._arr[0] === ANONYMOUS_SUFFIX;

/**
* Serializes to JSON
* @returns {JsonnablePrincipal} a JSON object with a single key, {@link JSON_KEY_PRINCIPAL}, whose value is the principal as a string
*/
toJSON() {
return { [JSON_KEY_PRINCIPAL]: this.toText() };
}
/**
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification

@@ -108,0 +89,0 @@ * @param {Principal} other - a {@link Principal} to compare

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

// tslint:disable:no-bitwise
const alphabet = 'abcdefghijklmnopqrstuvwxyz234567';

@@ -2,0 +3,0 @@ // Build a lookup table for decoding.

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

// tslint:disable:no-bitwise
// This file is translated to JavaScript from

@@ -44,2 +45,3 @@ // https://lxp32.github.io/docs/a-simple-example-crc32-calculation/

let crc = -1;
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < b.length; i++) {

@@ -46,0 +48,0 @@ const byte = b[i];

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

import { sha224 as jsSha224 } from '@noble/hashes/sha256';
import { sha224 as jsSha224 } from 'js-sha256';
/**

@@ -7,4 +7,6 @@ * Returns the SHA224 hash of the buffer.

export function sha224(data) {
return jsSha224.create().update(new Uint8Array(data)).digest();
const shaObj = jsSha224.create();
shaObj.update(data);
return new Uint8Array(shaObj.array());
}
//# sourceMappingURL=sha224.js.map
{
"name": "@dfinity/principal",
"version": "0.20.2",
"version": "0.21.1",
"author": "DFINITY Stiftung <sdk@dfinity.org>",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

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

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

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

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