@dfinity/principal
Advanced tools
Comparing version 0.11.3 to 0.12.0
export declare class Principal { | ||
private _arr; | ||
static anonymous(): Principal; | ||
/** | ||
* Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'` | ||
* @returns {Principal} principal of the management canister | ||
*/ | ||
static managementCanister(): Principal; | ||
static selfAuthenticating(publicKey: Uint8Array): Principal; | ||
@@ -16,2 +21,20 @@ static from(other: unknown): Principal; | ||
toString(): string; | ||
/** | ||
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification | ||
* @param {Principal} other - a {@link Principal} to compare | ||
* @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than | ||
*/ | ||
compareTo(other: Principal): 'lt' | 'eq' | 'gt'; | ||
/** | ||
* Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method | ||
* @param other a {@link Principal} to compare | ||
* @returns {boolean} boolean | ||
*/ | ||
ltEq(other: Principal): boolean; | ||
/** | ||
* Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method | ||
* @param other a {@link Principal} to compare | ||
* @returns {boolean} boolean | ||
*/ | ||
gtEq(other: Principal): boolean; | ||
} |
@@ -9,2 +9,3 @@ "use strict"; | ||
const ANONYMOUS_SUFFIX = 4; | ||
const MANAGEMENT_CANISTER_PRINCIPAL_HEX_STR = 'aaaaa-aa'; | ||
const fromHexString = (hexString) => { var _a; return new Uint8Array(((_a = hexString.match(/.{1,2}/g)) !== null && _a !== void 0 ? _a : []).map(byte => parseInt(byte, 16))); }; | ||
@@ -20,2 +21,9 @@ const toHexString = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), ''); | ||
} | ||
/** | ||
* Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'` | ||
* @returns {Principal} principal of the management canister | ||
*/ | ||
static managementCanister() { | ||
return this.fromHex(MANAGEMENT_CANISTER_PRINCIPAL_HEX_STR); | ||
} | ||
static selfAuthenticating(publicKey) { | ||
@@ -79,4 +87,41 @@ const sha = (0, sha224_1.sha224)(publicKey); | ||
} | ||
/** | ||
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification | ||
* @param {Principal} other - a {@link Principal} to compare | ||
* @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than | ||
*/ | ||
compareTo(other) { | ||
for (let i = 0; i < Math.min(this._arr.length, other._arr.length); i++) { | ||
if (this._arr[i] < other._arr[i]) | ||
return 'lt'; | ||
else if (this._arr[i] > other._arr[i]) | ||
return 'gt'; | ||
} | ||
// Here, at least one principal is a prefix of the other principal (they could be the same) | ||
if (this._arr.length < other._arr.length) | ||
return 'lt'; | ||
if (this._arr.length > other._arr.length) | ||
return 'gt'; | ||
return 'eq'; | ||
} | ||
/** | ||
* Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method | ||
* @param other a {@link Principal} to compare | ||
* @returns {boolean} boolean | ||
*/ | ||
ltEq(other) { | ||
const cmp = this.compareTo(other); | ||
return cmp == 'lt' || cmp == 'eq'; | ||
} | ||
/** | ||
* Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method | ||
* @param other a {@link Principal} to compare | ||
* @returns {boolean} boolean | ||
*/ | ||
gtEq(other) { | ||
const cmp = this.compareTo(other); | ||
return cmp == 'gt' || cmp == 'eq'; | ||
} | ||
} | ||
exports.Principal = Principal; | ||
//# sourceMappingURL=index.js.map |
export declare class Principal { | ||
private _arr; | ||
static anonymous(): Principal; | ||
/** | ||
* Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'` | ||
* @returns {Principal} principal of the management canister | ||
*/ | ||
static managementCanister(): Principal; | ||
static selfAuthenticating(publicKey: Uint8Array): Principal; | ||
@@ -16,2 +21,20 @@ static from(other: unknown): Principal; | ||
toString(): string; | ||
/** | ||
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification | ||
* @param {Principal} other - a {@link Principal} to compare | ||
* @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than | ||
*/ | ||
compareTo(other: Principal): 'lt' | 'eq' | 'gt'; | ||
/** | ||
* Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method | ||
* @param other a {@link Principal} to compare | ||
* @returns {boolean} boolean | ||
*/ | ||
ltEq(other: Principal): boolean; | ||
/** | ||
* Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method | ||
* @param other a {@link Principal} to compare | ||
* @returns {boolean} boolean | ||
*/ | ||
gtEq(other: Principal): boolean; | ||
} |
@@ -6,2 +6,3 @@ import { decode, encode } from './utils/base32'; | ||
const ANONYMOUS_SUFFIX = 4; | ||
const MANAGEMENT_CANISTER_PRINCIPAL_HEX_STR = 'aaaaa-aa'; | ||
const fromHexString = (hexString) => { var _a; return new Uint8Array(((_a = hexString.match(/.{1,2}/g)) !== null && _a !== void 0 ? _a : []).map(byte => parseInt(byte, 16))); }; | ||
@@ -17,2 +18,9 @@ const toHexString = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), ''); | ||
} | ||
/** | ||
* Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'` | ||
* @returns {Principal} principal of the management canister | ||
*/ | ||
static managementCanister() { | ||
return this.fromHex(MANAGEMENT_CANISTER_PRINCIPAL_HEX_STR); | ||
} | ||
static selfAuthenticating(publicKey) { | ||
@@ -76,3 +84,40 @@ const sha = sha224(publicKey); | ||
} | ||
/** | ||
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification | ||
* @param {Principal} other - a {@link Principal} to compare | ||
* @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than | ||
*/ | ||
compareTo(other) { | ||
for (let i = 0; i < Math.min(this._arr.length, other._arr.length); i++) { | ||
if (this._arr[i] < other._arr[i]) | ||
return 'lt'; | ||
else if (this._arr[i] > other._arr[i]) | ||
return 'gt'; | ||
} | ||
// Here, at least one principal is a prefix of the other principal (they could be the same) | ||
if (this._arr.length < other._arr.length) | ||
return 'lt'; | ||
if (this._arr.length > other._arr.length) | ||
return 'gt'; | ||
return 'eq'; | ||
} | ||
/** | ||
* Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method | ||
* @param other a {@link Principal} to compare | ||
* @returns {boolean} boolean | ||
*/ | ||
ltEq(other) { | ||
const cmp = this.compareTo(other); | ||
return cmp == 'lt' || cmp == 'eq'; | ||
} | ||
/** | ||
* Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method | ||
* @param other a {@link Principal} to compare | ||
* @returns {boolean} boolean | ||
*/ | ||
gtEq(other) { | ||
const cmp = this.compareTo(other); | ||
return cmp == 'gt' || cmp == 'eq'; | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@dfinity/principal", | ||
"version": "0.11.3", | ||
"version": "0.12.0", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101547
667