Socket
Socket
Sign inDemoInstall

@vechain/sdk-core

Package Overview
Dependencies
Maintainers
8
Versions
32
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.30 to 1.0.0-beta.31

src/hdkey/HDKey.ts

10

package.json
{
"name": "@vechain/sdk-core",
"version": "1.0.0-beta.30",
"version": "1.0.0-beta.31",
"description": "Includes modules for fundamental operations like hashing and cryptography",

@@ -31,3 +31,3 @@ "author": "vechain Foundation",

"scripts": {
"build": "rm -rf ./dist && tsup src/index.ts --format cjs,esm --external @noble/hashes --dts",
"build": "rm -rf ./dist && tsup-node src/index.ts --format cjs,esm --dts",
"lint": "eslint --ext .ts src --ext .ts tests",

@@ -44,6 +44,6 @@ "format": "prettier --write src/**/*.ts tests/**/*.ts",

"@scure/bip32": "^1.4.0",
"@scure/bip39": "^1.3.0",
"@scure/bip39": "^1.4.0",
"@types/elliptic": "^6.4.18",
"@vechain/sdk-errors": "1.0.0-beta.30",
"@vechain/sdk-logging": "1.0.0-beta.30",
"@vechain/sdk-errors": "1.0.0-beta.31",
"@vechain/sdk-logging": "1.0.0-beta.31",
"bignumber.js": "^9.1.2",

@@ -50,0 +50,0 @@ "blakejs": "^1.2.1",

import { CertificateSignature } from '@vechain/sdk-errors';
import fastJsonStableStringify from 'fast-json-stable-stringify';
import { Blake2b256 } from '../hash';
import { secp256k1 } from '../secp256k1';
import { Address, Hex, Txt } from '../vcdm';
import { Blake2b256 } from '../vcdm/hash/Blake2b256';
import { Secp256k1 } from '../secp256k1';
import { type Certificate } from './types';

@@ -65,3 +65,3 @@

* - {@link Blake2b256.of};
* - {@link secp256k1.sign}.
* - {@link Secp256k1.sign}.
*

@@ -81,3 +81,3 @@ * @param {Certificate} cert - The certificate to be signed.

signature: Hex.of(
secp256k1.sign(Blake2b256.of(encode(cert)).bytes, privateKey)
Secp256k1.sign(Blake2b256.of(encode(cert)).bytes, privateKey)
).toString()

@@ -100,3 +100,3 @@ };

* - {@link Blake2b256.of};
* - {@link secp256k1.recover}.
* - {@link Secp256k1.recover}.
*

@@ -133,3 +133,3 @@ * @param {Certificate} cert - The certificate to verify.

// The signer address is compared in lowercase to avoid
const signer = Address.ofPublicKey(secp256k1.recover(hash, sign))
const signer = Address.ofPublicKey(Secp256k1.recover(hash, sign))
.toString()

@@ -136,0 +136,0 @@ .toLowerCase();

@@ -9,4 +9,4 @@ import { ethers } from 'ethers';

export * from './encoding';
export * from './hash';
export * from './hdnode';
export * from './vcdm/hash/Hash';
export * from './hdkey';
export * from './keystore';

@@ -13,0 +13,0 @@ export * from './secp256k1';

@@ -1,4 +0,3 @@

import { dataUtils } from '../../../utils';
import { InvalidRLP } from '@vechain/sdk-errors';
import { Hex } from '../../../vcdm';
import { FPN, Hex, HexUInt } from '../../../vcdm';
import { type RLPInput } from '../types';

@@ -70,3 +69,3 @@

* @remarks
* The input string can represent an integer in either decimal or hexadecimal format.
* The input string can represent an unsigned integer in either decimal or hexadecimal format.
*

@@ -80,7 +79,6 @@ * @param str - A string expected to represent a non-negative integer.

const _validateNumericKindString = (str: string, context: string): void => {
const isHex = Hex.isValid0x(str);
const isDecimal = dataUtils.isDecimalString(str);
const isHexUInt = HexUInt.isValid0x(str);
const isDecimal = FPN.isNaturalExpression(str);
// Ensure the string is either a hex or decimal number.
if (!isHex && !isDecimal) {
if (!isHexUInt && !isDecimal) {
throw new InvalidRLP(

@@ -99,3 +97,3 @@ '_validateNumericKindString()',

// Ensure hex numbers are of a valid length.
if (isHex && str.length <= 2) {
if (isHexUInt && str.length <= 2) {
throw new InvalidRLP(

@@ -102,0 +100,0 @@ '_validateNumericKindString()',

/**
* 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 { ethers } from 'ethers';
import { secp256k1 } from '../../../secp256k1';
import { Secp256k1 } from '../../../secp256k1';
import {

@@ -14,3 +15,2 @@ InvalidKeystore,

import { type Keystore, type KeystoreAccount } from '../../types';
import { Address } from '../../../vcdm';

@@ -29,3 +29,3 @@ /**

// Public and Address are derived from a private key
const derivePublicKey = secp256k1.derivePublicKey(privateKey);
const derivePublicKey = Secp256k1.derivePublicKey(privateKey);
const deriveAddress = Address.ofPublicKey(

@@ -32,0 +32,0 @@ Buffer.from(derivePublicKey)

@@ -6,9 +6,9 @@ /**

*/
import * as n_utils from '@noble/curves/abstract/utils';
import { Address, Hex } from '../../../vcdm';
import { InvalidKeystoreParams, stringifyData } from '@vechain/sdk-errors';
import { Keccak256 } from '../../../vcdm/hash/Keccak256';
import { Secp256k1 } from '../../../secp256k1';
import { ctr } from '@noble/ciphers/aes';
import * as n_utils from '@noble/curves/abstract/utils';
import { scrypt } from '@noble/hashes/scrypt';
import { InvalidKeystoreParams, stringifyData } from '@vechain/sdk-errors';
import { Keccak256 } from '../../../hash';
import { secp256k1 } from '../../../secp256k1';
import { Address, Hex } from '../../../vcdm';
import { type Keystore, type KeystoreAccount } from '../../types';

@@ -198,3 +198,3 @@

const salt =
options.salt ?? secp256k1.randomBytes(KEYSTORE_CRYPTO_PARAMS_DKLEN);
options.salt ?? Secp256k1.randomBytes(KEYSTORE_CRYPTO_PARAMS_DKLEN);
// Override the scrypt password-based key derivation function parameters,

@@ -315,4 +315,4 @@ let N = SCRYPT_PARAMS.N;

* - `privateKey` wiped after use.
* - {@link secp256k1.derivePublicKey}.
* - {@link secp256k1.randomBytes}.
* - {@link Secp256k1.derivePublicKey}.
* - {@link Secp256k1.randomBytes}.
* - [scrypt](https://github.com/paulmillr/noble-hashes/?tab=readme-ov-file#scrypt).

@@ -347,3 +347,3 @@ *

// Override initialization vector.
const iv = options.iv ?? secp256k1.randomBytes(16);
const iv = options.iv ?? Secp256k1.randomBytes(16);
if (iv.length !== 16)

@@ -357,3 +357,3 @@ throw new InvalidKeystoreParams(

// Override the uuid.
const uuidRandom = options.uuid ?? secp256k1.randomBytes(16);
const uuidRandom = options.uuid ?? Secp256k1.randomBytes(16);

@@ -360,0 +360,0 @@ if (uuidRandom.length !== 16)

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

export * from './secp256k1';
export * from './Secp256k1';

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

import { secp256k1 } from '../../secp256k1';
import { Address } from '../../vcdm';
import { Secp256k1 } from '../../secp256k1';
import { Transaction } from '../transaction';

@@ -9,3 +10,2 @@ import {

import { type TransactionBody } from '../types';
import { Address } from '../../vcdm';

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

// Check if the private key is valid
if (!secp256k1.isValidPrivateKey(signerPrivateKey)) {
if (!Secp256k1.isValidPrivateKey(signerPrivateKey)) {
throw new InvalidSecp256k1PrivateKey(

@@ -45,3 +45,3 @@ `TransactionHandler.sign()`,

// Sign transaction
const signature = secp256k1.sign(
const signature = Secp256k1.sign(
transactionToSign.getSignatureHash(),

@@ -72,3 +72,3 @@ signerPrivateKey

// Check if the private key of the signer is valid
if (!secp256k1.isValidPrivateKey(signerPrivateKey)) {
if (!Secp256k1.isValidPrivateKey(signerPrivateKey)) {
throw new InvalidSecp256k1PrivateKey(

@@ -81,3 +81,3 @@ `TransactionHandler.signWithDelegator()`,

// Check if the private key of the delegator is valid
if (!secp256k1.isValidPrivateKey(delegatorPrivateKey)) {
if (!Secp256k1.isValidPrivateKey(delegatorPrivateKey)) {
throw new InvalidSecp256k1PrivateKey(

@@ -103,8 +103,8 @@ `TransactionHandler.signWithDelegator()`,

Address.ofPublicKey(
Buffer.from(secp256k1.derivePublicKey(signerPrivateKey))
Secp256k1.derivePublicKey(signerPrivateKey)
).toString()
);
const signature = Buffer.concat([
secp256k1.sign(transactionHash, signerPrivateKey),
secp256k1.sign(delegatedHash, delegatorPrivateKey)
Secp256k1.sign(transactionHash, signerPrivateKey),
Secp256k1.sign(delegatedHash, delegatorPrivateKey)
]);

@@ -111,0 +111,0 @@

@@ -0,1 +1,3 @@

import { Address, Hex } from '../vcdm';
import { Blake2b256 } from '../vcdm/hash/Blake2b256';
import {

@@ -7,5 +9,3 @@ InvalidSecp256k1Signature,

} from '@vechain/sdk-errors';
import { type RLPValidObject } from '../encoding';
import { Blake2b256 } from '../hash';
import { secp256k1 } from '../secp256k1';
import { Secp256k1 } from '../secp256k1';
import {

@@ -19,3 +19,3 @@ BLOCK_REF_LENGTH,

} from '../utils';
import { Address, Hex } from '../vcdm';
import { type RLPValidObject } from '../encoding';
import { type TransactionBody } from './types';

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

// Recover public key
const delegatorPublicKey = secp256k1.recover(
const delegatorPublicKey = Secp256k1.recover(
this.getSignatureHash(this.origin),

@@ -255,3 +255,3 @@ signatureSliced

// Recover public key
const originPublicKey = secp256k1.recover(
const originPublicKey = Secp256k1.recover(
this.getSignatureHash(),

@@ -258,0 +258,0 @@ signatureSliced

@@ -10,10 +10,2 @@ /**

/**
* Regular expression pattern for matching integers expressed as base 10 strings.
*
* @type {RegExp}
* @constant
*/
const INTEGER_REGEX: RegExp = /^\d+$/;
/**
* Regular expression for matching numeric values expressed as base 10 strings.

@@ -36,2 +28,2 @@ *

export { INTEGER_REGEX, NUMERIC_REGEX, ZERO_BYTES };
export { NUMERIC_REGEX, ZERO_BYTES };
export * from './abi';
export * from './data';
export * from './hdnode';
export * from './secp256k1';
export * from './transaction';

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

import * as n_utils from '@noble/curves/abstract/utils';
import { Hex } from '../../vcdm/Hex';
import { INTEGER_REGEX, NUMERIC_REGEX, ZERO_BYTES } from '../const';
import { Txt } from '../../vcdm';
import * as nc_utils from '@noble/curves/abstract/utils';
import { Hex, Txt } from '../../vcdm';
import { InvalidDataType } from '@vechain/sdk-errors';
import { ZERO_BYTES } from '../const';

@@ -68,4 +67,4 @@ /**

return zeroPadding === 'left'
? Hex.of(n_utils.concatBytes(pad, valueInBytes)).toString()
: Hex.of(n_utils.concatBytes(valueInBytes, pad)).toString();
? Hex.of(nc_utils.concatBytes(pad, valueInBytes)).toString()
: Hex.of(nc_utils.concatBytes(valueInBytes, pad)).toString();
} catch (e) {

@@ -81,31 +80,5 @@ throw new InvalidDataType(

/**
* Checks whether the given string is a decimal number.
*
* @param {string} data - The string to be checked.
* @returns {boolean} - True if the string represents a decimal number, false otherwise.
*
* @see {@link INTEGER_REGEX}
*/
const isDecimalString = (data: string): boolean => {
return INTEGER_REGEX.test(data);
};
/**
* Checks whether the provided string is a valid decimal numeric string.
*
* @param {string} value - The value to check.
* @returns {boolean} - Returns true if the value is numeric, false otherwise.
*
* @see {@link NUMERIC_REGEX}
*/
const isNumeric = (value: string): boolean => {
return NUMERIC_REGEX.test(value);
};
export const dataUtils = {
decodeBytes32String,
encodeBytes32String,
isDecimalString,
isNumeric
encodeBytes32String
};
export * from './const';
export * from './data';
export * from './hdnode';
export * from './transaction';
export * from './units';
import { InvalidOperation } from '@vechain/sdk-errors';
import { type Address } from '../Address';
import { type Currency } from '../Currency';
import { type Currency } from '../currency/Currency';
import { type VeChainDataModel } from '../VeChainDataModel';

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

@@ -0,12 +1,12 @@

import { Keccak256 } from './hash/Keccak256';
import { HDKey } from '../hdkey';
import { Hex } from './Hex';
import { HexUInt } from './HexUInt';
import { Secp256k1 } from '../secp256k1';
import { Txt } from './Txt';
import {
InvalidDataType,
InvalidHDNode,
InvalidHDKey,
InvalidSecp256k1PrivateKey
} from '@vechain/sdk-errors';
import { Keccak256 } from '../hash';
import { HDNode } from '../hdnode';
import { secp256k1 } from '../secp256k1';
import { Hex } from './Hex';
import { HexUInt } from './HexUInt';
import { Txt } from './Txt';

@@ -98,3 +98,3 @@ /**

* @remarks Security auditable method, depends on
* * {@link secp256k1.derivePublicKey}.
* * {@link Secp256k1.derivePublicKey}.
*/

@@ -107,3 +107,3 @@ public static ofPrivateKey(

return Address.ofPublicKey(
secp256k1.derivePublicKey(privateKey, isCompressed)
Secp256k1.derivePublicKey(privateKey, isCompressed)
);

@@ -131,7 +131,7 @@ } catch (error) {

* @remarks Security auditable method, depends on
* * {@link secp256k1.inflatePublicKey}.
* * {@link Secp256k1.inflatePublicKey}.
*/
public static ofPublicKey(publicKey: Uint8Array): Address {
try {
const publicKeyInflated = secp256k1.inflatePublicKey(publicKey);
const publicKeyInflated = Secp256k1.inflatePublicKey(publicKey);
const publicKeyHash = Keccak256.of(

@@ -159,3 +159,3 @@ publicKeyInflated.slice(1)

* - {@link bip32.HDKey}(https://github.com/paulmillr/scure-bip32)
* - {@link HDNode}
* - {@link HDKey}
*

@@ -169,3 +169,3 @@ * @example `m/0` (default)

* @return {Address} - The derived address.
* @throws {InvalidHDNode}
* @throws {InvalidHDKey}
*

@@ -177,3 +177,3 @@ */

): Address {
const root = HDNode.fromMnemonic(mnemonic);
const root = HDKey.fromMnemonic(mnemonic);
try {

@@ -185,3 +185,3 @@ // Public key is always available.

} catch (error) {
throw new InvalidHDNode(
throw new InvalidHDKey(
'mnemonic.deriveAddress()',

@@ -188,0 +188,0 @@ 'Invalid derivation path given as input.',

import * as nc_utils from '@noble/curves/abstract/utils';
import { Blake2b256 } from '../hash';
import { Blake2b256 } from './hash/Blake2b256';
import { Hex } from './Hex';

@@ -4,0 +4,0 @@ import { InvalidDataType, InvalidOperation } from '@vechain/sdk-errors';

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

*/
public readonly sign;
public readonly sign: number;

@@ -76,0 +76,0 @@ /**

export * from './account';
export * from './Address';
export * from './BloomFilter';
export * from './Currency';
export * from './Hash';
export * from './currency/Currency';
export * from './FPN';
export * from './hash';
export * from './Hex';

@@ -7,0 +8,0 @@ export * from './HexInt';

@@ -9,7 +9,7 @@ import {

InvalidDataType,
InvalidHDNode,
InvalidHDNodeMnemonic,
InvalidHDKey,
InvalidHDKeyMnemonic,
InvalidOperation
} from '@vechain/sdk-errors';
import { HDNode } from '../hdnode';
import { HDKey } from '../hdkey';
import { Address } from './Address';

@@ -141,6 +141,6 @@ import { type VeChainDataModel } from './VeChainDataModel';

*
* @throws {InvalidHDNode}
* @throws {InvalidHDKey}
*
* @remarks Security auditable method, depends on
* * {@link HDNode}.
* * {@link HDKey}.
*/

@@ -151,3 +151,3 @@ public static toPrivateKey(

): Uint8Array {
const root = HDNode.fromMnemonic(words);
const root = HDKey.fromMnemonic(words);
// Any exception involving mnemonic words is thrown before this point: words are not leaked next.

@@ -158,3 +158,3 @@ try {

} catch (error) {
throw new InvalidHDNode(
throw new InvalidHDKey(
'mnemonic.derivePrivateKey()',

@@ -204,3 +204,3 @@ 'Invalid derivation path given as input.',

} catch (error) {
throw new InvalidHDNodeMnemonic(
throw new InvalidHDKeyMnemonic(
'Mnemonic.of',

@@ -207,0 +207,0 @@ 'error while generating mnemonic',

@@ -24,15 +24,5 @@ import { Hex } from './Hex';

* @param {HexUInt} huint - The hexadecimal value representing the ThorId.
*
* @throws {InvalidDataType} - If the provided value is not a valid ThorId expression.
*/
protected constructor(huint: HexUInt) {
if (ThorId.isValid(huint.digits)) {
super(Hex.POSITIVE, huint.digits);
} else {
throw new InvalidDataType(
'ThorId.constructor',
'not a ThorId expression',
{ hex: huint }
);
}
super(Hex.POSITIVE, huint.fit(ThorId.DIGITS).digits);
}

@@ -83,6 +73,6 @@

try {
if (exp instanceof Hex) {
return new ThorId(exp.fit(this.DIGITS));
if (exp instanceof HexUInt) {
return new ThorId(exp);
}
return new ThorId(HexUInt.of(exp).fit(ThorId.DIGITS));
return new ThorId(HexUInt.of(exp));
} catch (e) {

@@ -89,0 +79,0 @@ throw new InvalidDataType(

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