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

@veramo/utils

Package Overview
Dependencies
Maintainers
3
Versions
374
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@veramo/utils - npm Package Compare versions

Comparing version 5.5.3 to 5.5.4-next.18

2

build/credential-utils.d.ts

@@ -48,3 +48,3 @@ import { CredentialPayload, IMessage, PresentationPayload, VerifiableCredential, VerifiablePresentation, W3CVerifiableCredential, W3CVerifiablePresentation } from '@veramo/core-types';

* @param input - the credential or presentation whose issuer/holder needs to be extracted.
* @param options
* @param options - options for the extraction
* removeParameters - Remove all DID parameters from the issuer ID

@@ -51,0 +51,0 @@ *

import { asArray, isDefined } from './type-utils.js';
import { decodeJWT } from 'did-jwt';
import { normalizeCredential, normalizePresentation } from 'did-jwt-vc';
import { blake2b } from '@noble/hashes/blake2b';
import { bytesToHex } from './encodings.js';
import { code, encode, prepare } from '@ipld/dag-pb';
import * as Digest from 'multiformats/hashes/digest';
import { CID } from 'multiformats/cid';
import { UnixFS } from 'ipfs-unixfs';
import { sha256 } from '@noble/hashes/sha256';
/**

@@ -81,3 +84,9 @@ * Every Verifiable Credential `@context` property must contain this.

}
return bytesToHex(blake2b(hashable));
const unixfs = new UnixFS({
type: 'file',
data: new TextEncoder().encode(hashable)
});
const bytes = encode(prepare({ Data: unixfs.marshal() }));
const digest = Digest.create(18, sha256(bytes));
return CID.create(0, code, digest).toString();
}

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

* @param input - the credential or presentation whose issuer/holder needs to be extracted.
* @param options
* @param options - options for the extraction
* removeParameters - Remove all DID parameters from the issuer ID

@@ -92,0 +101,0 @@ *

@@ -1,8 +0,7 @@

import { computePublicKey } from '@ethersproject/signing-key';
import { computeAddress } from '@ethersproject/transactions';
import { SigningKey, computeAddress } from 'ethers';
import { extractPublicKeyBytes } from 'did-jwt';
import { isDefined } from './type-utils.js';
import Debug from 'debug';
import { base58ToBytes, base64ToBytes, bytesToHex, hexToBytes, multibaseKeyToBytes } from './encodings.js';
import { bytesToHex, hexToBytes } from './encodings.js';
import { ed25519 } from '@noble/curves/ed25519';
import { secp256k1 } from '@noble/curves/secp256k1';
const debug = Debug('veramo:utils');

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

const publicBytes = hexToBytes(key.publicKeyHex);
key.publicKeyHex = computePublicKey(publicBytes, true).substring(2);
key.publicKeyHex = SigningKey.computePublicKey(publicBytes, true).substring(2);
key.meta = { ...key.meta };

@@ -141,3 +140,3 @@ key.meta.ethereumAddress = computeAddress('0x' + key.publicKeyHex);

const pbBytes = extractPublicKeyBytes(verificationMethod);
const pbHex = computePublicKey(pbBytes, false);
const pbHex = SigningKey.computePublicKey(pbBytes, false);
vmEthAddr = computeAddress(pbHex).toLowerCase();

@@ -148,31 +147,2 @@ }

}
function extractPublicKeyBytes(pk) {
if (pk.publicKeyBase58) {
return base58ToBytes(pk.publicKeyBase58);
}
else if (pk.publicKeyMultibase) {
return multibaseKeyToBytes(pk.publicKeyMultibase);
}
else if (pk.publicKeyBase64) {
return base64ToBytes(pk.publicKeyBase64);
}
else if (pk.publicKeyHex) {
return hexToBytes(pk.publicKeyHex);
}
else if (pk.publicKeyJwk &&
pk.publicKeyJwk.crv === 'secp256k1' &&
pk.publicKeyJwk.x &&
pk.publicKeyJwk.y) {
return secp256k1.ProjectivePoint.fromAffine({
x: BigInt('0x' + bytesToHex(base64ToBytes(pk.publicKeyJwk.x))),
y: BigInt('0x' + bytesToHex(base64ToBytes(pk.publicKeyJwk.y))),
}).toRawBytes(false);
}
else if (pk.publicKeyJwk &&
(pk.publicKeyJwk.crv === 'Ed25519' || pk.publicKeyJwk.crv === 'X25519') &&
pk.publicKeyJwk.x) {
return base64ToBytes(pk.publicKeyJwk.x);
}
return new Uint8Array();
}
/**

@@ -179,0 +149,0 @@ * Extracts the chain ID from a {@link did-resolver#VerificationMethod | verification method} supporting legacy

@@ -0,19 +1,4 @@

import { bytesToBase58, base58ToBytes, base64ToBytes, bytesToBase64url, bytesToMultibase, multibaseToBytes } from 'did-jwt';
export { bytesToBase58, base58ToBytes, bytesToBase64url, base64ToBytes, multibaseToBytes, bytesToMultibase };
/**
* Converts a Uint8Array to a base64url string
* @param b - the array to be converted
*
* @public
*/
export declare function bytesToBase64url(b: Uint8Array): string;
/**
* Converts a base64url string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export declare function base64ToBytes(s: string): Uint8Array;
/**
* Encodes a Uint8Array to a base64 string representation with padding.

@@ -93,43 +78,2 @@ * @param b - the byte array to convert

/**
* Converts a base58 string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export declare function base58ToBytes(s: string): Uint8Array;
/**
* Converts a base58 string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export declare function bytesToBase58(byteArray: Uint8Array): string;
/**
* Converts a multibase string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export declare function multibaseKeyToBytes(s: string): Uint8Array;
/**
* Converts a Uint8Array to a multibase string.
*
* @param b - the array to be converted
* @param type - the type of the key to be represented
*
* @throws if the array is not formatted correctly.
*
* @public
*/
export declare function bytesToMultibase(byteArray: Uint8Array, type: string): string;
/**
* Concatenates a bunch of arrays into one Uint8Array

@@ -136,0 +80,0 @@ * @param arrays - the arrays to be concatenated

import { fromString, toString, concat as concatArrays } from 'uint8arrays';
import { base64, base64url } from 'multiformats/bases/base64';
import { base16, base16upper } from 'multiformats/bases/base16';
import { base10 } from 'multiformats/bases/base10';
import { base58btc } from 'multiformats/bases/base58';
import { hexToBytes as hexToBytesRaw, bytesToHex as bytesToHexRaw, bytesToBase58, base58ToBytes, base64ToBytes, bytesToBase64url, bytesToMultibase, multibaseToBytes, } from 'did-jwt';
const u8a = { toString, fromString, concatArrays };
export { bytesToBase58, base58ToBytes, bytesToBase64url, base64ToBytes, multibaseToBytes, bytesToMultibase };
/**
* Converts a Uint8Array to a base64url string
* @param b - the array to be converted
*
* @public
*/
export function bytesToBase64url(b) {
return u8a.toString(b, 'base64url');
}
/**
* Converts a base64url string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export function base64ToBytes(s) {
const inputBase64Url = s.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
return u8a.fromString(inputBase64Url, 'base64url');
}
/**
* Encodes a Uint8Array to a base64 string representation with padding.

@@ -111,5 +87,3 @@ * @param b - the byte array to convert

}
const noPrefix = hexString.startsWith('0x') ? hexString.substring(2) : hexString;
const padded = noPrefix.length % 2 !== 0 ? `0${noPrefix}` : noPrefix;
return u8a.fromString(padded.toLowerCase(), 'base16');
return hexToBytesRaw(hexString);
}

@@ -132,87 +106,6 @@ /**

}
const result = u8a.toString(byteArray, 'base16');
const result = bytesToHexRaw(byteArray);
return prefix ? `0x${result}` : result;
}
/**
* Converts a base58 string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export function base58ToBytes(s) {
return u8a.fromString(s, 'base58btc');
}
/**
* Converts a base58 string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export function bytesToBase58(byteArray) {
return u8a.toString(byteArray, 'base58btc');
}
/**
* Converts a multibase string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export function multibaseKeyToBytes(s) {
if (s.charAt(0) !== 'z') {
throw new Error('invalid multibase string: string is not base58 encoded (does not start with "z")');
}
const baseDecoder = base58btc.decoder
.or(base10.decoder)
.or(base16.decoder)
.or(base16upper.decoder)
.or(base64.decoder)
.or(base64url.decoder);
const bytes = baseDecoder.decode(s);
if (bytes.length !== 34) {
throw new Error('invalid multibase string: length is not 34 bytes');
}
// only ed25519-pub and x25519-pub multicodecs supported now
if (bytes[0] !== 0xed && bytes[0] !== 0xec) {
throw new Error('invalid multibase string: first byte is not 0xed');
}
if (bytes[1] !== 0x01) {
throw new Error('invalid multibase string: second byte is not 0x01');
}
return bytes.slice(2);
}
/**
* Converts a Uint8Array to a multibase string.
*
* @param b - the array to be converted
* @param type - the type of the key to be represented
*
* @throws if the array is not formatted correctly.
*
* @public
*/
export function bytesToMultibase(byteArray, type) {
if (byteArray.length !== 32) {
throw new Error('invalid byte array: length is not 32 bytes');
}
const bytes = new Uint8Array(34);
if (type === 'Ed25519') {
bytes[0] = 0xed;
}
else if (type === 'X25519') {
bytes[0] = 0xec;
}
bytes[1] = 0x01;
bytes.set(byteArray, 2);
return base58btc.encode(bytes);
}
/**
* Concatenates a bunch of arrays into one Uint8Array

@@ -219,0 +112,0 @@ * @param arrays - the arrays to be concatenated

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

*
* @public
*/
export declare function intersect<T>(a: T[] | any, b: any[] | any): T[];
//# sourceMappingURL=type-utils.d.ts.map

@@ -42,2 +42,3 @@ /**

*
* @public
*/

@@ -44,0 +45,0 @@ export function intersect(a, b) {

{
"name": "@veramo/utils",
"description": "Helper methods for Veramo plugins",
"version": "5.5.3",
"version": "5.5.4-next.18+a324b304",
"main": "build/index.js",

@@ -13,13 +13,12 @@ "exports": "./build/index.js",

"dependencies": {
"@ethersproject/signing-key": "^5.7.0",
"@ethersproject/transactions": "^5.7.0",
"@ipld/dag-pb": "^4.0.5",
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1",
"@veramo/core-types": "^5.5.3",
"@veramo/core-types": "^5.5.4-next.18+a324b304",
"credential-status": "^2.0.5",
"cross-fetch": "^4.0.0",
"debug": "^4.3.3",
"did-jwt": "^7.2.5",
"did-jwt-vc": "^3.2.5",
"did-jwt": "^7.4.1",
"did-jwt-vc": "^3.2.10",
"did-resolver": "^4.1.0",
"ipfs-unixfs": "^11.1.0",
"multiformats": "^12.0.1",

@@ -66,3 +65,3 @@ "uint8arrays": "^4.0.6"

],
"gitHead": "35d9920683d3fccb4cfcae4d3d3bf79bcbbb227b"
"gitHead": "a324b304fddce189ac1380a7fa336a279f44564c"
}

@@ -184,3 +184,3 @@ import {

expect(computeEntryHash(serializedCred)).toEqual(
'452f0fb4b876e22867585ee15a6aabb7a6f9ccccf6a2ee664e9f7618737792d64b219fef0792b9d73f3ff756a265083526ecb7313ae4972ef6290b600cacbe88',
'QmYBWeZCoB1zbJwGou1svfgrq9muVQyy7uzokMfdeSEoHH',
)

@@ -212,3 +212,3 @@ })

expect(computeEntryHash(serializedCred)).toEqual(
'357436ca94682f2872b26c35a64d52c8e12dfbf86561a8f219cb395482f5978758fb577c927874cdb01189853054433a07eca81a4b3a999be12290021eb9bcbb',
'QmYeBhqpqiFUcsTS1qz7tkuVCJq8Z4VrrSJsjJc4Q7k9ig',
)

@@ -215,0 +215,0 @@ })

@@ -73,3 +73,3 @@ import { extractPublicKeyHex, getChainIdForDidEthr, getEthereumAddress } from '../did-utils.js'

const publicKeyHex = '6bb3f30242ac89bb6baa169fd5d1fea5adb61ce5b3cfee9e157e699a51983869'
const computedMultibase = bytesToMultibase(hexToBytes(publicKeyHex), 'Ed25519')
const computedMultibase = bytesToMultibase(hexToBytes(publicKeyHex), 'base58btc', 'ed25519-pub')
// // multibase

@@ -95,3 +95,3 @@ // let expectedMultibase = `z8FRmkyRH9xAsLCk51yXN2Qy6uq4eN4iAesa3v3Hv889v`;

const publicKeyHex = '6bb3f30242ac89bb6baa169fd5d1fea5adb61ce5b3cfee9e157e699a51983869'
const computedMultibase = bytesToMultibase(hexToBytes(publicKeyHex), 'Ed25519')
const computedMultibase = bytesToMultibase(hexToBytes(publicKeyHex), 'base58btc', 'ed25519-pub')

@@ -103,5 +103,5 @@ // // multibase + multicodec

const computedXMultibase = bytesToMultibase(hexToBytes(publicKeyHex), 'X25519')
const computedXMultibase = bytesToMultibase(hexToBytes(publicKeyHex), 'base58btc', 'x25519-pub')
let expectedXMultibase = `z6LSivbwHHE9FQtcRb7qYd3KM1Bakybm4ftKXrHjQVwSqVvg`;
expect(computedXMultibase).toEqual(expectedXMultibase)

@@ -108,0 +108,0 @@

@@ -14,4 +14,7 @@ import { asArray, isDefined } from './type-utils.js'

import { normalizeCredential, normalizePresentation } from 'did-jwt-vc'
import { blake2b } from '@noble/hashes/blake2b'
import { bytesToHex } from './encodings.js'
import { code, encode, prepare } from '@ipld/dag-pb'
import * as Digest from 'multiformats/hashes/digest'
import { CID } from 'multiformats/cid'
import { UnixFS } from 'ipfs-unixfs'
import { sha256 } from '@noble/hashes/sha256'

@@ -100,3 +103,11 @@ /**

}
return bytesToHex(blake2b(hashable))
const unixfs = new UnixFS({
type: 'file',
data: new TextEncoder().encode(hashable)
})
const bytes = encode(prepare({ Data: unixfs.marshal() }))
const digest = Digest.create(18, sha256(bytes))
return CID.create(0, code, digest).toString()
}

@@ -109,3 +120,3 @@

* @param input - the credential or presentation whose issuer/holder needs to be extracted.
* @param options
* @param options - options for the extraction
* removeParameters - Remove all DID parameters from the issuer ID

@@ -112,0 +123,0 @@ *

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

import { computePublicKey } from '@ethersproject/signing-key'
import { computeAddress } from '@ethersproject/transactions'
import { SigningKey, computeAddress } from 'ethers'
import { DIDDocumentSection, IAgentContext, IIdentifier, IKey, IResolver } from '@veramo/core-types'
import { DIDDocument, VerificationMethod } from 'did-resolver'
import { extractPublicKeyBytes } from 'did-jwt'
import {

@@ -12,5 +12,4 @@ _ExtendedIKey,

import Debug from 'debug'
import { base58ToBytes, base64ToBytes, bytesToHex, hexToBytes, multibaseKeyToBytes } from './encodings.js'
import { bytesToHex, hexToBytes } from './encodings.js'
import { ed25519 } from '@noble/curves/ed25519'
import { secp256k1 } from '@noble/curves/secp256k1'

@@ -91,3 +90,3 @@ const debug = Debug('veramo:utils')

const publicBytes = hexToBytes(key.publicKeyHex)
key.publicKeyHex = computePublicKey(publicBytes, true).substring(2)
key.publicKeyHex = SigningKey.computePublicKey(publicBytes, true).substring(2)
key.meta = { ...key.meta }

@@ -159,3 +158,3 @@ key.meta.ethereumAddress = computeAddress('0x' + key.publicKeyHex)

const pbBytes = extractPublicKeyBytes(verificationMethod)
const pbHex = computePublicKey(pbBytes, false)
const pbHex = SigningKey.computePublicKey(pbBytes, false)

@@ -168,35 +167,2 @@ vmEthAddr = computeAddress(pbHex).toLowerCase()

interface LegacyVerificationMethod extends VerificationMethod {
publicKeyBase64: string
}
function extractPublicKeyBytes(pk: VerificationMethod): Uint8Array {
if (pk.publicKeyBase58) {
return base58ToBytes(pk.publicKeyBase58)
} else if (pk.publicKeyMultibase) {
return multibaseKeyToBytes(pk.publicKeyMultibase)
} else if ((<LegacyVerificationMethod>pk).publicKeyBase64) {
return base64ToBytes((<LegacyVerificationMethod>pk).publicKeyBase64)
} else if (pk.publicKeyHex) {
return hexToBytes(pk.publicKeyHex)
} else if (
pk.publicKeyJwk &&
pk.publicKeyJwk.crv === 'secp256k1' &&
pk.publicKeyJwk.x &&
pk.publicKeyJwk.y
) {
return secp256k1.ProjectivePoint.fromAffine({
x: BigInt('0x' + bytesToHex(base64ToBytes(pk.publicKeyJwk.x))),
y: BigInt('0x' + bytesToHex(base64ToBytes(pk.publicKeyJwk.y))),
}).toRawBytes(false)
} else if (
pk.publicKeyJwk &&
(pk.publicKeyJwk.crv === 'Ed25519' || pk.publicKeyJwk.crv === 'X25519') &&
pk.publicKeyJwk.x
) {
return base64ToBytes(pk.publicKeyJwk.x)
}
return new Uint8Array()
}
/**

@@ -203,0 +169,0 @@ * Extracts the chain ID from a {@link did-resolver#VerificationMethod | verification method} supporting legacy

import { fromString, toString, concat as concatArrays } from 'uint8arrays'
import { base64, base64url } from 'multiformats/bases/base64'
import { base16, base16upper } from 'multiformats/bases/base16'
import { base10 } from 'multiformats/bases/base10'
import { base58btc } from 'multiformats/bases/base58'
import {
hexToBytes as hexToBytesRaw,
bytesToHex as bytesToHexRaw,
bytesToBase58,
base58ToBytes,
base64ToBytes,
bytesToBase64url,
bytesToMultibase,
multibaseToBytes,
} from 'did-jwt'
const u8a = { toString, fromString, concatArrays }
/**
* Converts a Uint8Array to a base64url string
* @param b - the array to be converted
*
* @public
*/
export function bytesToBase64url(b: Uint8Array): string {
return u8a.toString(b, 'base64url')
export {
bytesToBase58,
base58ToBytes,
bytesToBase64url,
base64ToBytes,
multibaseToBytes,
bytesToMultibase
}
/**
* Converts a base64url string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export function base64ToBytes(s: string): Uint8Array {
const inputBase64Url = s.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '')
return u8a.fromString(inputBase64Url, 'base64url')
}
/**
* Encodes a Uint8Array to a base64 string representation with padding.

@@ -122,5 +113,3 @@ * @param b - the byte array to convert

}
const noPrefix = hexString.startsWith('0x') ? hexString.substring(2) : hexString
const padded = noPrefix.length % 2 !== 0 ? `0${noPrefix}` : noPrefix
return u8a.fromString(padded.toLowerCase(), 'base16')
return hexToBytesRaw(hexString)
}

@@ -144,3 +133,3 @@

}
const result = u8a.toString(byteArray, 'base16')
const result = bytesToHexRaw(byteArray)
return prefix ? `0x${result}` : result

@@ -150,92 +139,2 @@ }

/**
* Converts a base58 string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export function base58ToBytes(s: string): Uint8Array {
return u8a.fromString(s, 'base58btc')
}
/**
* Converts a base58 string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export function bytesToBase58(byteArray: Uint8Array): string {
return u8a.toString(byteArray, 'base58btc')
}
/**
* Converts a multibase string to the Uint8Array it represents.
*
* @param s - the string to be converted
*
* @throws if the string is not formatted correctly.
*
* @public
*/
export function multibaseKeyToBytes(s: string): Uint8Array {
if (s.charAt(0) !== 'z') {
throw new Error('invalid multibase string: string is not base58 encoded (does not start with "z")')
}
const baseDecoder = base58btc.decoder
.or(base10.decoder)
.or(base16.decoder)
.or(base16upper.decoder)
.or(base64.decoder)
.or(base64url.decoder)
const bytes = baseDecoder.decode(s)
if (bytes.length !== 34) {
throw new Error('invalid multibase string: length is not 34 bytes')
}
// only ed25519-pub and x25519-pub multicodecs supported now
if (bytes[0] !== 0xed && bytes[0] !== 0xec) {
throw new Error('invalid multibase string: first byte is not 0xed')
}
if (bytes[1] !== 0x01) {
throw new Error('invalid multibase string: second byte is not 0x01')
}
return bytes.slice(2)
}
/**
* Converts a Uint8Array to a multibase string.
*
* @param b - the array to be converted
* @param type - the type of the key to be represented
*
* @throws if the array is not formatted correctly.
*
* @public
*/
export function bytesToMultibase(byteArray: Uint8Array, type: string): string {
if (byteArray.length !== 32) {
throw new Error('invalid byte array: length is not 32 bytes')
}
const bytes = new Uint8Array(34)
if (type === 'Ed25519') {
bytes[0] = 0xed
} else if (type === 'X25519') {
bytes[0] = 0xec
}
bytes[1] = 0x01
bytes.set(byteArray, 2)
return base58btc.encode(bytes)
}
/**
* Concatenates a bunch of arrays into one Uint8Array

@@ -242,0 +141,0 @@ * @param arrays - the arrays to be concatenated

@@ -45,2 +45,3 @@ /**

*
* @public
*/

@@ -47,0 +48,0 @@ export function intersect<T>(a: T[] | any, b: any[] | any): T[] {

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

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

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