Skip to main content

utils package

Contains helper methods for Veramo plugins.

Enumerations

EnumerationDescription
SupportedKeyTypes

Functions

FunctionDescription
asArray(arg)(BETA) Ensures that a given input is an array. If the input is a single item, it is converted to an array with a single entry.
bytesToBase64(b)Encodes a Uint8Array to a base64 string representation with padding.
bytesToHex(byteArray, prefix)(BETA) Converts a Uint8Array input to a hex string
bytesToUtf8String(b)Builds a string from a Uint8Array using the utf-8 encoding.
compressIdentifierSecp256k1Keys(identifier)(BETA) Converts any Secp256k1 public keys of an IIdentifier to their compressed form.
computeEntryHash(input)(BETA) Computes a hash for a given credential or presentation. This hash is usable as an internal ID for database indexing
concat(arrays, length)(BETA) Concatenates a bunch of arrays into one Uint8Array
convertEd25519PrivateKeyToX25519(privateKey)(BETA) Converts Ed25519 private keys to X25519
convertEd25519PublicKeyToX25519(publicKey)(BETA) Converts Ed25519 public keys to X25519
convertIdentifierEncryptionKeys(identifier)(BETA) Converts any Ed25519 keys of an IIdentifier to X25519 to be usable for encryption.
createJWK(keyType, pubKey, passedKeyUse)
decodeBase64url(s)(BETA) Decodes a base64url string to a utf8 string represented by the same bytes.
decodeCredentialToObject(input)(BETA) Parses a W3CVerifiableCredential and converts it to a VerifiableCredential so it is easier to use programmatically.
decodeJoseBlob(blob)(BETA) Decodes a base64url string representing stringified JSON to a JSON object.
decodePresentationToObject(input)(BETA) Parses a W3CVerifiablePresentation and converts it to a VerifiablePresentation so it is easier to use programmatically.
dereferenceDidKeys(didDocument, section, context)

(BETA) Dereferences keys from DID document and normalizes them for easy comparison.

When dereferencing keyAgreement keys, only Ed25519 and X25519 curves are supported. Other key types are omitted from the result and Ed25519 keys are converted to X25519

encodeBase64url(s)(BETA) Encodes the bytes of an input string to base64url
encodeJoseBlob(payload)(BETA) Stringifies a JSON object and encodes the bytes of the resulting string to a base64url representation.
extractIssuer(input, options)(BETA) Decodes a credential or presentation and returns the issuer ID iss from a JWT or issuer/issuer.id from a VC or holder from a VP
extractPublicKeyHex(pk, convert)(BETA) Converts the publicKey of a VerificationMethod to hex encoding (publicKeyHex)
generateJwkFromVerificationMethod(keyType, key, keyUse)
getChainId(verificationMethod)(BETA) Extracts the chain ID from a supporting legacy representations as well.
getEthereumAddress(verificationMethod)(BETA) Extracts an ethereum address from a supporting legacy representations.
getKeyUse(keyType, passedKeyUse)
hexToBytes(hexString)(BETA) Converts a hex string (with or without prefix) to a byte array (Uint8Array)
intersect(a, b)Compute the intersection of two arrays Elements are compared by reference so object types will appear as unique even if they contain the same data.
isDefined(arg)(BETA) Checks if a variable is defined and not null. After this check, typescript sees the variable as defined.
isIterable(obj)(BETA) Checks if an object is iterable (can be used for for..of)
isJWK(data)
mapIdentifierKeysToDoc(identifier, section, context, resolutionOptions)(BETA) Maps the keys of a locally managed IIdentifier to the corresponding entries from the DID document.
processEntryToArray(inputEntryOrArray, startWithEntry)(BETA) Processes an entry or an array of entries into an array of entries. If a startWithEntry param is provided, it is set as the first item in the result array.
removeDIDParameters(did)(BETA) Remove all DID parameters from a DID url
resolveDidOrThrow(didUrl, context, resolutionOptions)(BETA) Resolve a DID document or throw an error if the resolution fails.
stringToUtf8Bytes(s)Encodes a string to a Uint8Array using the utf-8 encoding.

Variables

VariableDescription
MANDATORY_CREDENTIAL_CONTEXTEvery Verifiable Credential @context property must contain this.

Type Aliases

Type AliasDescription
JwkDidSupportedKeyTypes
KeyUse
RecordLike

(BETA) A mapping of string to another type. Both Map and Record are accepted.

This API may change without a BREAKING CHANGE notice.