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

@vechain/sdk-core

Package Overview
Dependencies
Maintainers
8
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vechain/sdk-core - npm Package Compare versions

Comparing version 1.0.0-beta.31 to 1.0.0-beta.32

src/certificate/Certificate.ts

19

package.json
{
"name": "@vechain/sdk-core",
"version": "1.0.0-beta.31",
"description": "Includes modules for fundamental operations like hashing and cryptography",
"author": "vechain Foundation",
"version": "1.0.0-beta.32",
"description": "This module is crafted for dApp development and various blockchain operations that seamlessly unfold offline",
"author": "VeChain Foundation",
"license": "MIT",

@@ -19,3 +19,2 @@ "homepage": "https://github.com/vechain/vechain-sdk-js",

],
"private": false,
"main": "dist/index.js",

@@ -33,2 +32,3 @@ "module": "dist/index.mjs",

"build": "rm -rf ./dist && tsup-node src/index.ts --format cjs,esm --dts",
"check:circular-dependencies": "npx madge --exclude 'transaction/Clause.ts' --circular --extensions ts src",
"lint": "eslint --ext .ts src --ext .ts tests",

@@ -43,17 +43,18 @@ "format": "prettier --write src/**/*.ts tests/**/*.ts",

"@ethereumjs/rlp": "^5.0.2",
"@noble/ciphers": "^0.6.0",
"@noble/ciphers": "^1.0.0",
"@scure/bip32": "^1.4.0",
"@scure/bip39": "^1.4.0",
"@types/elliptic": "^6.4.18",
"@vechain/sdk-errors": "1.0.0-beta.31",
"@vechain/sdk-logging": "1.0.0-beta.31",
"@vechain/sdk-errors": "1.0.0-beta.32",
"@vechain/sdk-logging": "1.0.0-beta.32",
"bignumber.js": "^9.1.2",
"blakejs": "^1.2.1",
"elliptic": "^6.5.7",
"ethers": "6.13.2",
"fast-json-stable-stringify": "^2.1.0"
"fast-json-stable-stringify": "^2.1.0",
"viem": "^2.21.14"
},
"devDependencies": {
"bignumber.js": "^9.1.2",
"thor-devkit": "^2.0.9"
}
}

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

export * from './certificate';
export * from './types.d';
export * from './Certificate';
export type * from './CertificateData';
import { ethers } from 'ethers';
// Our core library
export * from './abi';
export * from './certificate';
export * from './clause';
export * from './contract';
export * from './encoding';
export * from './vcdm/hash/Hash';
export * from './hdkey';

@@ -11,0 +6,0 @@ export * from './keystore';

@@ -5,6 +5,6 @@ import * as s_bip32 from '@scure/bip32';

import { base58 } from '@scure/base';
import { FixedPointNumber } from '../vcdm/FixedPointNumber';
import { Sha256 } from '../vcdm/hash/Sha256';
import { HexUInt } from '../vcdm/HexUInt';
import { FPN } from '../vcdm';
import { Secp256k1 } from '../secp256k1';
import { Sha256 } from '../vcdm/hash/Sha256';
import { Secp256k1 } from '../secp256k1/Secp256k1';
import {

@@ -56,4 +56,4 @@ InvalidHDKey,

*
* @param {string[]} words An array of words representing the mnemonic.
* @param {string} path The derivation path to derive the child node.
* @param {string[]} words - An array of words representing the mnemonic.
* @param {string} path - The derivation path to derive the child node.
* Default value is {@link VET_DERIVATION_PATH}.

@@ -106,4 +106,4 @@ *

*
* @param {Uint8Array} privateKey The private key.
* @param {Uint8Array} chainCode The chain code.
* @param {Uint8Array} - privateKey The private key.
* @param {Uint8Array} - chainCode The chain code.
*

@@ -141,3 +141,4 @@ * @returns Returns the hierarchical deterministic key from `privateKey` and `chainCode`.

) as HDKey;
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
throw new InvalidSecp256k1PrivateKey(

@@ -165,6 +166,6 @@ 'HDNode.fromPrivateKey',

*
* @param {Uint8Array} publicKey The public key bytes.
* @param {Uint8Array} chainCode The chain code bytes.
* @param {Uint8Array} publicKey - The public key bytes.
* @param {Uint8Array} chainCode - The chain code bytes.
*
* @returns {bip32.HDKey} Returns the hierarchical deterministic key from `public` and `chainCode`.
* @returns {HDKey} Returns the hierarchical deterministic key from `public` and `chainCode`.
*

@@ -177,3 +178,3 @@ * @throws {InvalidHDKey} if the `publicKey` is invalid.

* * {@link Sha256};
* * [s_bip32.HDKey.fromExtendedKey](https://github.com/paulmillr/scure-bip32).
* * [HDKey.fromExtendedKey](https://github.com/paulmillr/scure-bip32).
*/

@@ -235,5 +236,5 @@ public static fromPublicKey(

// "number"
FPN.isNaturalExpression(component) ||
FixedPointNumber.isNaturalExpression(component) ||
// "number'"
(FPN.isNaturalExpression(component.slice(0, -1)) &&
(FixedPointNumber.isNaturalExpression(component.slice(0, -1)) &&
component.endsWith("'"))

@@ -240,0 +241,0 @@ );

/**
* Implements the JSON Keystore v3 Wallet encryption, decryption, and validation functionality.
*/
import { Address } from '../../../vcdm';
import { ethers } from 'ethers';
import { Hex } from '../../../vcdm/Hex';
import { SCRYPT_PARAMS } from './const';
import { Secp256k1 } from '../../../secp256k1';
import {

@@ -14,3 +9,7 @@ InvalidKeystore,

} from '@vechain/sdk-errors';
import { ethers } from 'ethers';
import { Secp256k1 } from '../../../secp256k1';
import { Address, HexUInt } from '../../../vcdm';
import { type Keystore, type KeystoreAccount } from '../../types';
import { SCRYPT_PARAMS } from './const';

@@ -25,3 +24,3 @@ /**

async function encrypt(
privateKey: Buffer,
privateKey: Uint8Array,
password: string

@@ -31,5 +30,3 @@ ): Promise<Keystore> {

const derivePublicKey = Secp256k1.derivePublicKey(privateKey);
const deriveAddress = Address.ofPublicKey(
Buffer.from(derivePublicKey)
).toString();
const deriveAddress = Address.ofPublicKey(derivePublicKey).toString();

@@ -39,3 +36,3 @@ // Create keystore account compatible with ethers

address: deriveAddress,
privateKey: Hex.of(privateKey).toString()
privateKey: HexUInt.of(privateKey).toString()
};

@@ -88,2 +85,3 @@

)) as KeystoreAccount;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {

@@ -90,0 +88,0 @@ throw new InvalidKeystoreParams(

@@ -7,5 +7,4 @@ /**

import * as n_utils from '@noble/curves/abstract/utils';
import { Address, Hex } from '../../../vcdm';
import { Address, Hex, Keccak256 } from '../../../vcdm';
import { InvalidKeystoreParams, stringifyData } from '@vechain/sdk-errors';
import { Keccak256 } from '../../../vcdm/hash/Keccak256';
import { Secp256k1 } from '../../../secp256k1';

@@ -565,3 +564,4 @@ import { ctr } from '@noble/ciphers/aes';

}
} catch (error) {} // Return false if parsing fails.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {} // Return false if parsing fails.
return false;

@@ -568,0 +568,0 @@ }

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

export * from './types.d';
export type * from './types.d';
export * from './keystore';

@@ -28,3 +28,3 @@ import { VeChainSDKLogger } from '@vechain/sdk-logging';

async function encrypt(
privateKey: Buffer,
privateKey: Uint8Array,
password: string

@@ -31,0 +31,0 @@ ): Promise<Keystore> {

@@ -32,3 +32,3 @@ import * as nc_utils from '@noble/curves/abstract/utils';

*/
private static readonly SIGNATURE_LENGTH = 65;
public static readonly SIGNATURE_LENGTH = 65;

@@ -114,3 +114,4 @@ /**

return nc_secp256k1.utils.randomPrivateKey();
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
// Generate an ECDSA key pair

@@ -204,6 +205,7 @@ const cryptoKey = await global.crypto.subtle.generateKey(

*/
public static randomBytes(bytesLength?: number | undefined): Uint8Array {
public static randomBytes(bytesLength?: number): Uint8Array {
try {
return nh_randomBytes(bytesLength);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return global.crypto.getRandomValues(

@@ -210,0 +212,0 @@ new Uint8Array(bytesLength ?? 32)

@@ -1,4 +0,7 @@

export * from './transaction';
export * from './transaction-handler';
export * from './types.d';
export * from './Clause';
export * from './Transaction';
export * from '../utils/const/network';
export type * from './ClauseOptions';
export type * from './DeployParams';
export type * from './TransactionBody';
export type * from './TransactionClause';
export * from './abi';
export * from './data';
export * from './transaction';
import * as nc_utils from '@noble/curves/abstract/utils';
import { Hex, Txt } from '../../vcdm';
import { InvalidDataType } from '@vechain/sdk-errors';
import { Hex } from '../../vcdm/Hex';
import { Txt } from '../../vcdm/Txt';
import { ZERO_BYTES } from '../const';

@@ -5,0 +6,0 @@

export * from './const';
export * from './data';
export * from './transaction';
export * from './units';

@@ -95,11 +95,15 @@ import { InvalidOperation } from '@vechain/sdk-errors';

public compareTo(that: Account): number {
const typeCompareTo = this.type.localeCompare(that.type);
if (typeCompareTo !== 0) {
return typeCompareTo;
const typeDiff = this.type.localeCompare(that.type);
if (typeDiff === 0) {
const addressDiff = this.address.compareTo(that.address);
if (addressDiff === 0) {
const codeDiff = this.balance.code.compareTo(that.balance.code);
if (codeDiff === 0) {
return this.balance.value.compareTo(that.balance.value);
}
return codeDiff;
}
return addressDiff;
}
const addressCompareTo = this.address.compareTo(that.address);
if (addressCompareTo !== 0) {
return addressCompareTo;
}
return this.balance.compareTo(that.balance);
return typeDiff;
}

@@ -124,3 +128,3 @@

public toString(): string {
return `${this.type} Address: ${this.address.toString()} Balance: ${this.balance.bi.toString()}`;
return `${this.type} Address: ${this.address.toString()} Balance: ${this.balance.value} ${this.balance.code}`;
}

@@ -127,0 +131,0 @@ }

import { Keccak256 } from './hash/Keccak256';
import { HDKey } from '../hdkey';
import { HDKey } from '../hdkey/HDKey';
import { Hex } from './Hex';
import { HexUInt } from './HexUInt';
import { Secp256k1 } from '../secp256k1';
import { Secp256k1 } from '../secp256k1/Secp256k1';
import { Txt } from './Txt';

@@ -22,3 +22,3 @@ import {

*
* @param {HexUInt} huint The HexUInt object representing the hexadecimal value.
* @param {HexUInt} huint - The HexUInt object representing the hexadecimal value.
*

@@ -45,3 +45,3 @@ * @returns {string} The checksummed address.

*
* @param {string} exp Expression to validate
* @param {string} exp - Expression to validate
*

@@ -57,3 +57,3 @@ * @returns {boolean} true if the expression is a valid address, false otherwise

*
* @param exp The expression to convert. It can be of type bigint, number, string, Uint8Array, or HexUInt.
* @param exp - The expression to convert. It can be of type bigint, number, string, Uint8Array, or HexUInt.
*

@@ -82,7 +82,7 @@ * @returns {Address} The converted hexadecimal unsigned integer.

} catch (error) {
this.throwInvalidDataType(
error,
throw new InvalidDataType(
'Address.of',
'not a valid hexadecimal positive integer expression',
{ exp: `${exp}`, error }
{ exp: `${exp}` },
error
);

@@ -95,5 +95,5 @@ }

*
* @param {Uint8Array} privateKey The private key to convert.
* @param {Uint8Array} privateKey - The private key to convert.
*
* @param {boolean} [isCompressed=true] The flag to indicate if the derived public key should be compressed.
* @param {boolean} [isCompressed=true] - The flag to indicate if the derived public key should be compressed.
*

@@ -117,7 +117,7 @@ * @returns {Address} The converted address.

}
this.throwInvalidDataType(
error,
throw new InvalidDataType(
'Address.ofPrivateKey',
'not a valid private key',
{ privateKey: `${privateKey}`, error }
{ privateKey: `${privateKey}` },
error
);

@@ -130,3 +130,3 @@ }

*
* @param {Uint8Array} publicKey The public key to convert.
* @param {Uint8Array} publicKey - The public key to convert.
*

@@ -146,7 +146,7 @@ * @returns {Address} The converted address.

} catch (error) {
this.throwInvalidDataType(
error,
throw new InvalidDataType(
'Address.ofPublicKey',
'not a valid public key',
{ publicKey: `${publicKey}`, error }
{ publicKey: `${publicKey}` },
error
);

@@ -153,0 +153,0 @@ }

@@ -0,22 +1,29 @@

import { type FixedPointNumber } from '../FixedPointNumber';
import { type Txt } from '../Txt';
import { type VeChainDataModel } from '../VeChainDataModel';
import { type FPN } from '../FPN';
/**
* Interface representing the properties for currency implementation
* that extends from VeChainDataModel.
*
* @interface Currency
* @extends {VeChainDataModel<Currency>}
*/
export interface Currency extends VeChainDataModel<Currency> {
get code(): string;
/**
* Return the code as a Txt object.
*
* @return {Txt} The code object
*
* @remarks Since currency codes likely use Unicode composite symbols,
* {@link Txt} type enforce the reresentation of the code is normalized.
*/
get code(): Txt;
get value(): FPN;
/**
* Return the current value as an FixedPointNumber (Fixed-Point Number).
*
* @return {FixedPointNumber} The current value in Fixed-Point Number format.
*/
get value(): FixedPointNumber;
}
// class Wei<Digits> implements Currency<Digits.wei> {
// }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
enum Digits {
wei,
kwei = 3,
mwei = 6,
gwei = 9,
szabo = 12,
finney = 15,
ether = 18
}
import { blake2b as nh_blake2b } from '@noble/hashes/blake2b';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, Txt, type Hash } from '../index';
import { Hex } from '../Hex';
import { HexUInt } from '../HexUInt';
import { Txt } from '../Txt';

@@ -10,5 +11,4 @@ /**

* @extends HexUInt
* @implements Hash
*/
class Blake2b256 extends HexUInt implements Hash {
class Blake2b256 extends HexUInt {
/**

@@ -15,0 +15,0 @@ * Generates the [BLAKE](https://en.wikipedia.org/wiki/BLAKE_(hash_function)) [BLAKE2B 256](https://www.blake2.net/) hash of the given input.

export * from './Blake2b256';
export * from './Hash';
export * from './Keccak256';
export * from './Sha256';
import { keccak_256 as nh_keccak_256 } from '@noble/hashes/sha3';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, Txt, type Hash } from '../index';
import { Hex } from '../Hex';
import { HexUInt } from '../HexUInt';
import { Txt } from '../Txt';

@@ -10,5 +11,4 @@ /**

* @extends HexUInt
* @implements Hash
*/
class Keccak256 extends HexUInt implements Hash {
class Keccak256 extends HexUInt {
/**

@@ -15,0 +15,0 @@ * Generates the [SHA-3](https://en.wikipedia.org/wiki/SHA-3) [KECCAK 256](https://keccak.team/keccak.html) hash of the given input.

import * as nh_sha256 from '@noble/hashes/sha256';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, Txt, type Hash } from '../index';
import { Hex } from '../Hex';
import { HexUInt } from '../HexUInt';
import { Txt } from '../Txt';

@@ -12,3 +13,3 @@ /**

*/
class Sha256 extends HexUInt implements Hash {
class Sha256 extends HexUInt {
/**

@@ -15,0 +16,0 @@ * Generates the [SHA 256](https://en.wikipedia.org/wiki/SHA-2) hash of the given input.

import * as nc_utils from '@noble/curves/abstract/utils';
import * as nh_utils from '@noble/hashes/utils';
import {
InvalidOperation,
InvalidDataType,
type ObjectErrorData
} from '@vechain/sdk-errors';
import { InvalidDataType, InvalidOperation } from '@vechain/sdk-errors';
import { type VeChainDataModel } from './VeChainDataModel';

@@ -40,2 +36,7 @@

/**
* A constant string prefix used in hexadecimal notation.
*/
public static readonly PREFIX = '0x';
/**
* The radix used for representing numbers base 16 in a positional numeral notation system.

@@ -45,3 +46,3 @@ *

*/
protected static readonly RADIX: number = 16;
public static readonly RADIX: number = 16;

@@ -341,24 +342,2 @@ /**

/**
* Error handler for Hex and its subclasses so we do not hide them.
* To be used only for nested errors.
*
* @param error - The error to handle from the subclass.
* @param methodName - The name of the method that threw the error.
* @param {string} errorMessage - The error message to throw.
* @param {ObjectErrorData} data - The data to include in the error.
* @throws {InvalidDataType} - Throws an error with the given message and data.
*/
protected static throwInvalidDataType(
error: unknown,
methodName: string,
errorMessage: string,
data: ObjectErrorData
): never {
if (error instanceof InvalidDataType) {
throw error;
}
throw new InvalidDataType(methodName, errorMessage, data, error);
}
/**
* Returns a string representation of the object.

@@ -365,0 +344,0 @@ *

@@ -0,6 +1,8 @@

export * from './abi';
export * from './account';
export * from './Address';
export * from './BloomFilter';
export * from './currency/Currency';
export * from './FPN';
export * from './currency';
export * from './encoding';
export * from './FixedPointNumber';
export * from './hash';

@@ -15,2 +17,2 @@ export * from './Hex';

export * from './Txt';
export * from './VeChainDataModel';
export type * from './VeChainDataModel';

@@ -28,2 +28,9 @@ import {

/**
* The Mnemonic class provides functionality related to mnemonic phrases, including encoding to bytes,
* generating, validating, and deriving keys from mnemonic words based on the BIP39 standard.
* It implements the VeChainDataModel interface.
*
* @implements VeChainDataModel
*/
class Mnemonic implements VeChainDataModel<Mnemonic> {

@@ -78,3 +85,3 @@ /**

*
* @param _that The mnemonic to compare with.
* @param that - The mnemonic to compare with.
*/

@@ -100,3 +107,3 @@ public compareTo(_that: Mnemonic): number {

*
* @param numberOfWords The number of words.
* @param numberOfWords - The number of words.
*

@@ -172,4 +179,4 @@ * @returns {number} The corresponding strength.

*
* @param {WordlistSizeType} wordlistSize The number of words to generate the mnemonic.
* @param {function} [randomGenerator] The random generator function used to generate the entropy.
* @param {WordlistSizeType} wordlistSize - The number of words to generate the mnemonic.
* @param {function} [randomGenerator] - The random generator function used to generate the entropy.
*

@@ -216,3 +223,3 @@ * @returns {Mnemonic} The generated mnemonic.

*
* @param {string | string[]} words The mnemonic words to check.
* @param {string | string[]} words - The mnemonic words to check.
*

@@ -219,0 +226,0 @@ * @returns {boolean} true if the words are valid, false otherwise.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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