@veramo/utils
Advanced tools
Comparing version 3.1.5-next.126 to 3.1.5-next.127
@@ -8,2 +8,12 @@ export declare function bytesToBase64url(b: Uint8Array): string; | ||
export declare function decodeJoseBlob(blob: string): any; | ||
/** | ||
* Converts a hex string (with or without prefix) to a byte array (Uint8Array) | ||
* | ||
* @param hexString - The string representing the encoding | ||
* @returns the `Uint8Array` represented by the given string | ||
* | ||
* @throws `illegal_argument` error if the parameter is not a string | ||
*/ | ||
export declare function hexToBytes(hexString: string): Uint8Array; | ||
export declare function bytesToHex(byteArray: Uint8Array, prefix?: boolean): string; | ||
//# sourceMappingURL=encodings.d.ts.map |
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeJoseBlob = exports.encodeJoseBlob = exports.decodeBase64url = exports.encodeBase64url = exports.bytesToBase64 = exports.base64ToBytes = exports.bytesToBase64url = void 0; | ||
exports.bytesToHex = exports.hexToBytes = exports.decodeJoseBlob = exports.encodeJoseBlob = exports.decodeBase64url = exports.encodeBase64url = exports.bytesToBase64 = exports.base64ToBytes = exports.bytesToBase64url = void 0; | ||
const u8a = __importStar(require("uint8arrays")); | ||
@@ -58,2 +58,31 @@ function bytesToBase64url(b) { | ||
exports.decodeJoseBlob = decodeJoseBlob; | ||
/** | ||
* Converts a hex string (with or without prefix) to a byte array (Uint8Array) | ||
* | ||
* @param hexString - The string representing the encoding | ||
* @returns the `Uint8Array` represented by the given string | ||
* | ||
* @throws `illegal_argument` error if the parameter is not a string | ||
*/ | ||
function hexToBytes(hexString) { | ||
// @ts-ignore | ||
if (hexString instanceof Uint8Array) { | ||
return Uint8Array.from(hexString); | ||
} | ||
if (typeof hexString !== 'string') { | ||
throw new Error('illegal_argument: a string must be provided for a hex-string to byte array conversion'); | ||
} | ||
const noPrefix = hexString.startsWith('0x') ? hexString.substring(2) : hexString; | ||
const padded = noPrefix.length % 2 !== 0 ? `0${noPrefix}` : noPrefix; | ||
return u8a.fromString(padded.toLowerCase(), 'base16'); | ||
} | ||
exports.hexToBytes = hexToBytes; | ||
function bytesToHex(byteArray, prefix = false) { | ||
if (!(byteArray instanceof Uint8Array)) { | ||
throw new Error('illegal_argument: only byte arrays can be converted to hex encoding'); | ||
} | ||
const result = u8a.toString(byteArray, 'base16'); | ||
return prefix ? `0x${result}` : result; | ||
} | ||
exports.bytesToHex = bytesToHex; | ||
//# sourceMappingURL=encodings.js.map |
{ | ||
"name": "@veramo/utils", | ||
"description": "Helper methods for Veramo plugins", | ||
"version": "3.1.5-next.126+219cde25", | ||
"version": "3.1.5-next.127+0c77d03e", | ||
"main": "build/index.js", | ||
@@ -13,9 +13,9 @@ "types": "build/index.d.ts", | ||
"@stablelib/ed25519": "^1.0.2", | ||
"@veramo/core": "^3.1.5-next.126+219cde25", | ||
"@veramo/core": "^3.1.5-next.127+0c77d03e", | ||
"blakejs": "^1.1.1", | ||
"cross-fetch": "^3.1.4", | ||
"debug": "^4.3.3", | ||
"did-jwt": "^5.12.3", | ||
"did-jwt-vc": "^2.1.9", | ||
"did-resolver": "3.2.2", | ||
"did-jwt": "^6.1.2", | ||
"did-jwt-vc": "^2.1.12", | ||
"did-resolver": "^3.2.2", | ||
"uint8arrays": "^3.0.0", | ||
@@ -42,3 +42,3 @@ "uuid": "^8.3.0" | ||
"keywords": [], | ||
"gitHead": "219cde250e8d4f06d7978afcc38a04471342fd21" | ||
"gitHead": "0c77d03ec5ec9e2091de3f74f67ab86a22cde197" | ||
} |
@@ -73,3 +73,3 @@ import { | ||
'https://veramo.io/contexts/profile/v1', | ||
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld', | ||
'https://w3id.org/security/suites/secp256k1recovery-2020/v2', | ||
], | ||
@@ -76,0 +76,0 @@ type: ['VerifiableCredential', 'Profile'], |
@@ -15,3 +15,3 @@ import { getChainIdForDidEthr, getEthereumAddress } from '../did-utils' | ||
'controller': 'did:ethr:0x1B54DaD834f2017ab66C1a1ffF74425889141e51', | ||
'blockchainAccountId':'did:ethr:0x1B54DaD834f2017ab66C1a1ffF74425889141e51@eip155:1' | ||
'blockchainAccountId':'eip155:1:0x1B54DaD834f2017ab66C1a1ffF74425889141e51' | ||
})).toEqual(1) | ||
@@ -27,4 +27,4 @@ expect(getChainIdForDidEthr({ | ||
'type': 'EcdsaSecp256k1RecoveryMethod2020', | ||
'controller': 'did:ethr:0x1B54DaD834f2017ab66C1a1ffF74425889141e51', | ||
'blockchainAccountId':'did:ethr:rinkeby:0x1B54DaD834f2017ab66C1a1ffF74425889141e51@eip155:4' | ||
'controller': 'did:ethr:rinkeby:0x1B54DaD834f2017ab66C1a1ffF74425889141e51', | ||
'blockchainAccountId':'eip155:4:0x1B54DaD834f2017ab66C1a1ffF74425889141e51' | ||
})).toEqual(4) | ||
@@ -38,3 +38,3 @@ }) | ||
'controller': 'did:ethr:0x1B54DaD834f2017ab66C1a1ffF74425889141e51', | ||
'blockchainAccountId': '0x1B54DaD834f2017ab66C1a1ffF74425889141e51@eip155:1' | ||
'blockchainAccountId': 'eip155:1:0x1B54DaD834f2017ab66C1a1ffF74425889141e51' | ||
} | ||
@@ -41,0 +41,0 @@ |
@@ -31,1 +31,30 @@ import * as u8a from 'uint8arrays' | ||
} | ||
/** | ||
* Converts a hex string (with or without prefix) to a byte array (Uint8Array) | ||
* | ||
* @param hexString - The string representing the encoding | ||
* @returns the `Uint8Array` represented by the given string | ||
* | ||
* @throws `illegal_argument` error if the parameter is not a string | ||
*/ | ||
export function hexToBytes(hexString: string): Uint8Array { | ||
// @ts-ignore | ||
if (hexString instanceof Uint8Array) { | ||
return Uint8Array.from(hexString) | ||
} | ||
if (typeof hexString !== 'string') { | ||
throw new Error('illegal_argument: a string must be provided for a hex-string to byte array conversion') | ||
} | ||
const noPrefix = hexString.startsWith('0x') ? hexString.substring(2) : hexString | ||
const padded = noPrefix.length % 2 !== 0 ? `0${noPrefix}` : noPrefix | ||
return u8a.fromString(padded.toLowerCase(), 'base16') | ||
} | ||
export function bytesToHex(byteArray: Uint8Array, prefix: boolean = false): string { | ||
if (!(byteArray instanceof Uint8Array)) { | ||
throw new Error('illegal_argument: only byte arrays can be converted to hex encoding') | ||
} | ||
const result = u8a.toString(byteArray, 'base16') | ||
return prefix ? `0x${result}` : result | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
94017
37
1497
- Removedcanonicalize@1.0.8(transitive)
- Removeddid-jwt@5.12.4(transitive)
Updateddid-jwt@^6.1.2
Updateddid-jwt-vc@^2.1.12
Updateddid-resolver@^3.2.2