@vechain/sdk-core
Advanced tools
Comparing version 1.0.0-beta.27 to 1.0.0-beta.28
{ | ||
"name": "@vechain/sdk-core", | ||
"version": "1.0.0-beta.27", | ||
"version": "1.0.0-beta.28", | ||
"description": "Includes modules for fundamental operations like hashing and cryptography", | ||
@@ -21,3 +21,2 @@ "author": "vechain Foundation", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
@@ -46,4 +45,4 @@ "files": [ | ||
"@types/elliptic": "^6.4.18", | ||
"@vechain/sdk-errors": "1.0.0-beta.27", | ||
"@vechain/sdk-logging": "1.0.0-beta.27", | ||
"@vechain/sdk-errors": "1.0.0-beta.28", | ||
"@vechain/sdk-logging": "1.0.0-beta.28", | ||
"bignumber.js": "^9.1.2", | ||
@@ -50,0 +49,0 @@ "blakejs": "^1.2.1", |
@@ -1,2 +0,2 @@ | ||
import { Hex, Hex0x } from '../utils'; | ||
import { Hex } from '../vcdm/Hex'; | ||
import { keccak256 } from '../hash'; | ||
@@ -58,5 +58,5 @@ import { secp256k1 } from '../secp256k1'; | ||
return toERC55Checksum( | ||
Hex0x.of( | ||
Hex.of( | ||
keccak256(secp256k1.inflatePublicKey(publicKey).slice(1)).slice(12) | ||
) | ||
).toString() | ||
); | ||
@@ -99,4 +99,4 @@ } | ||
const digits = Hex.canon(address.toLowerCase()); | ||
const hash = Hex.of(keccak256(digits)); | ||
const digits = Hex.of(address).hex; | ||
const hash = Hex.of(keccak256(digits)).hex; | ||
let result: string = '0x'; | ||
@@ -103,0 +103,0 @@ for (let i = 0; i < digits.length; i++) { |
import fastJsonStableStringify from 'fast-json-stable-stringify'; | ||
import { Hex, Hex0x } from '../utils'; | ||
import { CertificateSignature } from '@vechain/sdk-errors'; | ||
import { Hex, Txt } from '../vcdm'; | ||
import { addressUtils } from '../address-utils'; | ||
import { CertificateSignature } from '@vechain/sdk-errors'; | ||
import { Txt } from '../vcdm'; | ||
import { blake2b256 } from '../hash'; | ||
import { hexToBytes } from '@noble/curves/abstract/utils'; | ||
import { secp256k1 } from '../secp256k1'; | ||
@@ -76,3 +74,3 @@ import { type Certificate } from './types'; | ||
* | ||
* @throws {InvalidSecp256k1PrivateKeyError} - If the private key is invalid. | ||
* @throws {InvalidSecp256k1PrivateKey} - If the private key is invalid. | ||
* | ||
@@ -83,5 +81,5 @@ */ | ||
...cert, | ||
signature: Hex0x.of( | ||
signature: Hex.of( | ||
secp256k1.sign(blake2b256(encode(cert)), privateKey) | ||
) | ||
).toString() | ||
}; | ||
@@ -122,3 +120,4 @@ } | ||
// Invalid hexadecimal as signature. | ||
if (!Hex0x.isValid(cert.signature, false, true)) { | ||
// PROVISIONAL: until 1119 Certificate OOP | ||
if (!Hex.isValid0x(cert.signature) || cert.signature.length % 2 !== 0) { | ||
throw new CertificateSignature( | ||
@@ -132,3 +131,3 @@ 'certificate.verify()', | ||
// If the signature is not a string, an exception is thrown above. | ||
const sign = hexToBytes(Hex.canon(cert.signature)); | ||
const sign = Hex.of(cert.signature).bytes; | ||
const hash = blake2b256(encode(cert)); | ||
@@ -135,0 +134,0 @@ // The signer address is compared in lowercase to avoid |
@@ -0,3 +1,3 @@ | ||
import { Hex } from '../../../vcdm'; | ||
import { InvalidRLP } from '@vechain/sdk-errors'; | ||
import { Hex0x } from '../../../utils'; | ||
@@ -71,3 +71,5 @@ /** | ||
): string => { | ||
return Hex0x.of(buffer, bytes); | ||
return Hex.of(buffer) | ||
.fit(bytes * 2) | ||
.toString(); | ||
}; | ||
@@ -74,0 +76,0 @@ |
@@ -1,4 +0,4 @@ | ||
import { Hex0x } from '../../../utils'; | ||
import { Hex } from '../../../vcdm/Hex'; | ||
import { InvalidRLP } from '@vechain/sdk-errors'; | ||
import { type RLPInput } from '../types'; | ||
import { InvalidRLP } from '@vechain/sdk-errors'; | ||
@@ -27,3 +27,3 @@ /** | ||
// Check if data is a valid hex string with '0x' prefix. | ||
if (!Hex0x.isValid(data)) { | ||
if (!Hex.isValid(data)) { | ||
throw new InvalidRLP( | ||
@@ -30,0 +30,0 @@ 'assertValidHexBlobKindData()', |
@@ -1,4 +0,5 @@ | ||
import { dataUtils, Hex, Hex0x } from '../../../utils'; | ||
import { dataUtils } from '../../../utils'; | ||
import { InvalidRLP } from '@vechain/sdk-errors'; | ||
import { Hex } from '../../../vcdm/Hex'; | ||
import { type RLPInput } from '../types'; | ||
import { InvalidRLP } from '@vechain/sdk-errors'; | ||
@@ -78,3 +79,3 @@ /** | ||
const _validateNumericKindString = (str: string, context: string): void => { | ||
const isHex = Hex0x.isValid(str); | ||
const isHex = Hex.isValid0x(str); | ||
const isDecimal = dataUtils.isDecimalString(str); | ||
@@ -174,3 +175,3 @@ | ||
if (bi === 0n) return Buffer.alloc(0); | ||
const hex = Hex.of(bi); | ||
const hex = Hex.of(bi).hex; | ||
@@ -202,3 +203,3 @@ if (maxBytes !== undefined && hex.length > maxBytes * 2) { | ||
const bi = BigInt(Hex0x.of(buffer)); | ||
const bi = Hex.of(buffer).bi; | ||
const num = Number(bi); | ||
@@ -205,0 +206,0 @@ |
@@ -0,1 +1,3 @@ | ||
import { FixedHexBlobKind } from './fixedhexblob'; | ||
import { Hex } from '../../../../vcdm/Hex'; | ||
import { | ||
@@ -6,4 +8,2 @@ assertCompactFixedHexBlobBuffer, | ||
import { type BufferOutput, type DataOutput, type RLPInput } from '../../types'; | ||
import { FixedHexBlobKind } from './fixedhexblob'; | ||
import { Hex0x } from '../../../../utils'; | ||
@@ -42,3 +42,7 @@ /** | ||
return { | ||
decode: () => Hex0x.of(buffer, this.bytes) // Decode the buffer, returning a hex string with leading zeros. | ||
decode: () => | ||
// Decode the buffer, returning a hex string with leading zeros. | ||
Hex.of(buffer) | ||
.fit(this.bytes * 2) | ||
.toString() | ||
}; | ||
@@ -45,0 +49,0 @@ } |
@@ -0,1 +1,3 @@ | ||
import { Hex } from '../../../../vcdm/Hex'; | ||
import { ScalarKind } from '../scalarkind.abstract'; | ||
import { | ||
@@ -6,4 +8,2 @@ assertValidHexBlobKindBuffer, | ||
import { type DataOutput, type BufferOutput, type RLPInput } from '../../types'; | ||
import { ScalarKind } from '../scalarkind.abstract'; | ||
import { Hex0x } from '../../../../utils'; | ||
@@ -44,3 +44,3 @@ /** | ||
return { | ||
decode: () => Hex0x.of(buffer) | ||
decode: () => Hex.of(buffer).toString() | ||
}; | ||
@@ -47,0 +47,0 @@ } |
@@ -1,5 +0,4 @@ | ||
import { Hex, Hex0x } from '../utils'; | ||
import { Hex } from '../vcdm/Hex'; | ||
import { Txt } from '../vcdm'; | ||
import { blake2b } from '@noble/hashes/blake2b'; | ||
import { hexToBytes } from '@noble/hashes/utils'; | ||
import { type ReturnType } from './types'; | ||
@@ -17,3 +16,3 @@ import { InvalidDataType } from '@vechain/sdk-errors'; | ||
* | ||
* @throws {InvalidDataReturnType} - If the specified return type is invalid. | ||
* @throws {InvalidDataReturnError} - If the specified return type is invalid. | ||
* | ||
@@ -90,6 +89,6 @@ * @remark Use {@link blake2b256OfHex} to hash a string representing an array of bytes in hexadecimal form. | ||
const hash = blake2b256OfArray(data); | ||
return returnType === 'hex' ? Hex0x.of(hash) : hash; | ||
return returnType === 'hex' ? Hex.of(hash).toString() : hash; | ||
} else { | ||
const hash = blake2b256OfString(data); | ||
return returnType === 'hex' ? Hex0x.of(hash) : hash; | ||
return returnType === 'hex' ? Hex.of(hash).toString() : hash; | ||
} | ||
@@ -138,4 +137,4 @@ } | ||
try { | ||
const hash = blake2b256OfArray(hexToBytes(Hex.canon(hex))); | ||
return returnType === 'hex' ? Hex0x.of(hash) : hash; | ||
const hash = blake2b256OfArray(Hex.of(hex).bytes); | ||
return returnType === 'hex' ? Hex.of(hash).toString() : hash; | ||
} catch (e) { | ||
@@ -142,0 +141,0 @@ throw new InvalidDataType( |
@@ -1,5 +0,5 @@ | ||
import { Hex0x } from '../utils'; | ||
import { Hex } from '../vcdm/Hex'; | ||
import { InvalidDataType } from '@vechain/sdk-errors'; | ||
import { keccak_256 } from '@noble/hashes/sha3'; | ||
import { type ReturnType } from './types'; | ||
import { InvalidDataType } from '@vechain/sdk-errors'; | ||
@@ -72,5 +72,5 @@ /* --- Overloaded functions start --- */ | ||
const hash = keccak_256(data); | ||
return returnType === 'buffer' ? hash : Hex0x.of(hash); | ||
return returnType === 'buffer' ? hash : Hex.of(hash).toString(); | ||
} | ||
export { keccak256 }; |
@@ -1,5 +0,5 @@ | ||
import { Hex0x } from '../utils'; | ||
import { Hex } from '../vcdm/Hex'; | ||
import { InvalidDataType } from '@vechain/sdk-errors'; | ||
import { sha256 as _sha256 } from '@noble/hashes/sha256'; | ||
import { type ReturnType } from './types'; | ||
import { InvalidDataType } from '@vechain/sdk-errors'; | ||
@@ -68,5 +68,5 @@ /* --- Overloaded functions start --- */ | ||
const hash = _sha256(data); | ||
return returnType === 'buffer' ? hash : Hex0x.of(hash); | ||
return returnType === 'buffer' ? hash : Hex.of(hash).toString(); | ||
} | ||
export { sha256 }; |
/** | ||
* Implements the JSON Keystore v3 Wallet encryption, decryption, and validation functionality. | ||
*/ | ||
import { Hex } from '../../../vcdm/Hex'; | ||
import { SCRYPT_PARAMS } from './const'; | ||
import { addressUtils } from '../../../address-utils'; | ||
import { ethers } from 'ethers'; | ||
import { type Keystore, type KeystoreAccount } from '../../types'; | ||
import { secp256k1 } from '../../../secp256k1'; | ||
import { | ||
@@ -11,6 +14,3 @@ InvalidKeystore, | ||
} from '@vechain/sdk-errors'; | ||
import { secp256k1 } from '../../../secp256k1'; | ||
import { addressUtils } from '../../../address-utils'; | ||
import { Hex0x } from '../../../utils'; | ||
import { SCRYPT_PARAMS } from './const'; | ||
import { type Keystore, type KeystoreAccount } from '../../types'; | ||
@@ -37,3 +37,3 @@ /** | ||
address: deriveAddress, | ||
privateKey: Hex0x.of(privateKey) | ||
privateKey: Hex.of(privateKey).toString() | ||
}; | ||
@@ -40,0 +40,0 @@ |
@@ -7,10 +7,10 @@ /** | ||
import * as n_utils from '@noble/curves/abstract/utils'; | ||
import { Hex } from '../../../vcdm/Hex'; | ||
import { InvalidKeystoreParams, stringifyData } from '@vechain/sdk-errors'; | ||
import { ctr } from '@noble/ciphers/aes'; | ||
import { addressUtils } from '../../../address-utils'; | ||
import { keccak256 } from '../../../hash'; | ||
import { scrypt } from '@noble/hashes/scrypt'; | ||
import { secp256k1 } from '../../../secp256k1'; | ||
import { type Keystore, type KeystoreAccount } from '../../types'; | ||
import { addressUtils } from '../../../address-utils'; | ||
import { Hex, Hex0x } from '../../../utils'; | ||
import { secp256k1 } from '../../../secp256k1'; | ||
import { keccak256 } from '../../../hash'; | ||
@@ -369,13 +369,13 @@ /** | ||
return { | ||
address: Hex.canon( | ||
address: Hex.of( | ||
addressUtils.fromPublicKey( | ||
secp256k1.derivePublicKey(privateKey) | ||
) | ||
), | ||
).hex, | ||
crypto: { | ||
cipher: KEYSTORE_CRYPTO_CIPHER, | ||
cipherparams: { | ||
iv: Hex.of(iv) | ||
iv: Hex.of(iv).hex | ||
}, | ||
ciphertext: Hex.of(ciphertext), | ||
ciphertext: Hex.of(ciphertext).hex, | ||
kdf: 'scrypt', | ||
@@ -387,3 +387,3 @@ kdfparams: { | ||
r: kdf.r, | ||
salt: Hex.of(kdf.salt) | ||
salt: Hex.of(kdf.salt).hex | ||
}, | ||
@@ -393,3 +393,3 @@ // Compute the message authentication code, used to check the password. | ||
keccak256(n_utils.concatBytes(macPrefix, ciphertext)) | ||
) | ||
).hex | ||
}, | ||
@@ -515,3 +515,3 @@ id: uuidV4(uuidRandom), | ||
keccak256(n_utils.concatBytes(key.slice(16, 32), ciphertext)) | ||
) | ||
).hex | ||
) { | ||
@@ -535,3 +535,5 @@ throw new InvalidKeystoreParams( | ||
address !== | ||
addressUtils.toERC55Checksum(Hex0x.canon(keystore.address)) | ||
addressUtils.toERC55Checksum( | ||
Hex.of(keystore.address).toString() | ||
) | ||
) { | ||
@@ -547,3 +549,3 @@ throw new InvalidKeystoreParams( | ||
// @note: Convert the private key to a string to be compatible with ethers | ||
privateKey: Hex0x.of(privateKey) | ||
privateKey: Hex.of(privateKey).toString() | ||
} satisfies KeystoreAccount; | ||
@@ -599,3 +601,3 @@ } finally { | ||
bytes[8] = (bytes[8] & 0x3f) | 0x80; | ||
const value = Hex.of(bytes); | ||
const value = Hex.of(bytes).hex; | ||
return [ | ||
@@ -602,0 +604,0 @@ value.substring(0, 8), |
import * as n_utils from '@noble/curves/abstract/utils'; | ||
import { Hex, SIGNATURE_LENGTH } from '../utils'; | ||
import { Hex } from '../vcdm/Hex'; | ||
import { SIGNATURE_LENGTH } from '../utils'; | ||
import { randomBytes as _randomBytes } from '@noble/hashes/utils'; | ||
import { secp256k1 as n_secp256k1 } from '@noble/curves/secp256k1'; | ||
import { | ||
@@ -8,4 +11,2 @@ InvalidSecp256k1MessageHash, | ||
} from '@vechain/sdk-errors'; | ||
import { randomBytes as _randomBytes } from '@noble/hashes/utils'; | ||
import { secp256k1 as n_secp256k1 } from '@noble/curves/secp256k1'; | ||
@@ -117,3 +118,3 @@ /** | ||
const p = n_secp256k1.ProjectivePoint.fromAffine( | ||
n_secp256k1.ProjectivePoint.fromHex(Hex.of(x)).toAffine() | ||
n_secp256k1.ProjectivePoint.fromHex(Hex.of(x).hex).toAffine() | ||
); | ||
@@ -120,0 +121,0 @@ return p.toRawBytes(false); |
@@ -7,3 +7,2 @@ import { addressUtils } from '../address-utils'; | ||
BLOCK_REF_LENGTH, | ||
Hex0x, | ||
SIGNATURE_LENGTH, | ||
@@ -22,2 +21,3 @@ SIGNED_TRANSACTION_RLP, | ||
} from '@vechain/sdk-errors'; | ||
import { Hex } from '../vcdm/Hex'; | ||
@@ -433,3 +433,3 @@ /** | ||
body.blockRef !== undefined && | ||
Hex0x.isValid(body.blockRef) && | ||
Hex.isValid0x(body.blockRef) && | ||
Buffer.from(body.blockRef.slice(2), 'hex').length === | ||
@@ -436,0 +436,0 @@ BLOCK_REF_LENGTH && |
import * as n_utils from '@noble/curves/abstract/utils'; | ||
import { Hex } from '../../vcdm/Hex'; | ||
import { addressUtils } from '../../address-utils'; | ||
import { bloom } from '../../bloom'; | ||
import { | ||
@@ -8,5 +11,2 @@ InvalidAddress, | ||
} from '@vechain/sdk-errors'; | ||
import { Hex, Hex0x } from '../hex'; | ||
import { addressUtils } from '../../address-utils'; | ||
import { bloom } from '../../bloom'; | ||
@@ -56,4 +56,5 @@ /** | ||
addresses.forEach((address) => { | ||
if (addressUtils.isAddress(Hex0x.canon(address))) { | ||
keys.add(n_utils.hexToBytes(Hex.canon(address))); | ||
const hex = Hex.of(address); | ||
if (addressUtils.isAddress(hex.toString())) { | ||
keys.add(hex.bytes); | ||
} | ||
@@ -110,3 +111,3 @@ }); | ||
if (typeof data !== 'string' || !Hex0x.isValid(data, true)) { | ||
if (typeof data !== 'string' || !Hex.isValid(data)) { | ||
throw new InvalidDataType( | ||
@@ -126,7 +127,4 @@ 'bloomUtils.isInBloom()', | ||
} | ||
const bloomFilter = new bloom.Filter( | ||
n_utils.hexToBytes(Hex.canon(filter)), | ||
k | ||
); | ||
return bloomFilter.contains(n_utils.hexToBytes(Hex.canon(data))); | ||
const bloomFilter = new bloom.Filter(Hex.of(filter).bytes, k); | ||
return bloomFilter.contains(Hex.of(data).bytes); | ||
}; | ||
@@ -133,0 +131,0 @@ /** |
import * as n_utils from '@noble/curves/abstract/utils'; | ||
import { Hex, Hex0x } from '../hex'; | ||
import { Hex } from '../../vcdm/Hex'; | ||
import { INTEGER_REGEX, NUMERIC_REGEX, ZERO_BYTES } from '../const'; | ||
import { Txt } from '../../vcdm'; | ||
import { INTEGER_REGEX, NUMERIC_REGEX, ZERO_BYTES } from '../const'; | ||
import { InvalidDataType } from '@vechain/sdk-errors'; | ||
@@ -17,3 +17,3 @@ | ||
const decodeBytes32String = (hex: string): string => { | ||
if (!Hex0x.isValid(hex) || Hex.canon(hex).length !== 64) | ||
if (!Hex.isValid(hex) || Hex.of(hex).hex.length !== 64) | ||
throw new InvalidDataType( | ||
@@ -25,3 +25,3 @@ 'dataUtils.decodeBytes32String()', | ||
const valueInBytes = n_utils.hexToBytes(Hex.canon(hex)); | ||
const valueInBytes = Hex.of(hex).bytes; | ||
// Find the first zero byte. | ||
@@ -70,4 +70,4 @@ const firstZeroIndex = valueInBytes.findIndex((byte) => byte === 0); | ||
return zeroPadding === 'left' | ||
? Hex0x.of(n_utils.concatBytes(pad, valueInBytes)) | ||
: Hex0x.of(n_utils.concatBytes(valueInBytes, pad)); | ||
? Hex.of(n_utils.concatBytes(pad, valueInBytes)).toString() | ||
: Hex.of(n_utils.concatBytes(valueInBytes, pad)).toString(); | ||
} catch (e) { | ||
@@ -74,0 +74,0 @@ throw new InvalidDataType( |
@@ -5,5 +5,4 @@ export * from './const'; | ||
export * from './hdnode'; | ||
export * from './hex'; | ||
export * from './transaction'; | ||
export * from './units'; | ||
export * from './revision'; |
@@ -0,3 +1,3 @@ | ||
import { Hex } from '../../vcdm/Hex'; | ||
import { dataUtils } from '../data'; | ||
import { Hex0x } from '../hex'; | ||
@@ -33,3 +33,3 @@ /** | ||
revision === 'finalized' || | ||
(typeof revision === 'string' && Hex0x.isValid(revision)) || | ||
(typeof revision === 'string' && Hex.isValid0x(revision)) || | ||
(typeof revision === 'string' && dataUtils.isDecimalString(revision)) || | ||
@@ -36,0 +36,0 @@ (typeof revision === 'number' && revision >= 0) |
@@ -0,6 +1,6 @@ | ||
import { Hex } from '../../vcdm/Hex'; | ||
import { TRANSACTIONS_GAS_CONSTANTS } from '../const'; | ||
import { addressUtils } from '../../address-utils'; | ||
import { InvalidDataType } from '@vechain/sdk-errors'; | ||
import { type TransactionClause } from '../../transaction'; | ||
import { TRANSACTIONS_GAS_CONSTANTS } from '../const'; | ||
import { InvalidDataType } from '@vechain/sdk-errors'; | ||
import { Hex0x } from '../hex'; | ||
@@ -54,3 +54,3 @@ /** | ||
// Invalid data | ||
if (data !== '' && !Hex0x.isValid(data)) | ||
if (data !== '' && !Hex.isValid(data)) | ||
throw new InvalidDataType( | ||
@@ -57,0 +57,0 @@ '_calculateDataUsedGas()', |
@@ -1,4 +0,3 @@ | ||
import * as n_utils from '@noble/curves/abstract/utils'; | ||
import { BigNumber } from 'bignumber.js'; | ||
import { Hex, Hex0x } from '../hex'; | ||
import { Hex } from '../../vcdm/Hex'; | ||
import { InvalidDataType } from '@vechain/sdk-errors'; | ||
@@ -54,6 +53,4 @@ import { type WEI_UNITS } from './types'; | ||
case 'string': { | ||
if (Hex0x.isValid(value)) { | ||
bn = BigNumber( | ||
n_utils.hexToNumber(Hex.canon(value)).toString() | ||
); | ||
if (Hex.isValid0x(value)) { | ||
bn = BigNumber(Hex.of(value).bi.toString()); | ||
} else { | ||
@@ -60,0 +57,0 @@ bn = BigNumber(value); |
@@ -0,2 +1,6 @@ | ||
export * from './Hex'; | ||
export * from './HexInt'; | ||
export * from './HexUInt'; | ||
export * from './ThorId'; | ||
export * from './Txt'; | ||
export * from './VeChainDataModel'; |
@@ -59,5 +59,6 @@ import { InvalidCastType } from '@vechain/sdk-errors'; | ||
} catch (e) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
throw new InvalidCastType<Txt>( | ||
'Txt.bi', | ||
"can't cast to big integer", | ||
'Txt.bi()', | ||
"Can't cast to big integer", | ||
this, | ||
@@ -64,0 +65,0 @@ e |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
273647
97
7832
1
+ Added@vechain/sdk-errors@1.0.0-beta.28(transitive)
+ Added@vechain/sdk-logging@1.0.0-beta.28(transitive)
- Removed@vechain/sdk-errors@1.0.0-beta.27(transitive)
- Removed@vechain/sdk-logging@1.0.0-beta.27(transitive)