Use this file to discover all available pages before exploring further.
Dfns supports the following asymmetric key algorithms for credentials:
ECDSA
EDDSA
RSA
Dfns supports many different curves. You can use any curve that is supported by Node JS’ crypto library.Dfns recommends the following curves / modulus lengths:
# Recommended: Generate a EDDSA Private Key# NOTE: This is not the key for the blockchain, only for the API.# NOTE: EDDSA keys do not work in Postman!openssl genpkey -algorithm Ed25519 -out ed25519key.pem# Generate the Public Keyopenssl pkey -in ed25519key.pem -pubout -out ed25519key.pub.pem#OR # Generate a ECDSA Private Key# NOTE: This is not the key for the blockchain, only for the API.openssl ecparam -genkey -name prime256v1 -noout -out prime256v1.pem# Generate the Public Keyopenssl pkey -in prime256v1.pem -pubout -out prime256v1.pub.pem#OR # Generate RSA Private Keyopenssl genrsa -out rsa3072.pem 3072# Generate the Public Keyopenssl pkey -in rsa3072.pem -pubout -out rsa3072.pub.pem
On MacOS you may need to update your openssl version to add support for EDDSA keys
# Generate a ECDSA Private Keyaws kms create-key --key-spec ECC_NIST_P256 --key-usage SIGN_VERIFY# Get the Public Keyaws kms get-public-key --key-id <KEY_ID># Generate a RSA Private Keyaws kms create-key --key-spec RSA_3072 --key-usage SIGN_VERIFY# Get the Public Keyaws kms get-public-key --key-id <KEY_ID>
An ECDSA (which includes EDDSA) signature consists of two values; a r and a s. Different crypto libraries use different formats for encoding these two values. The two most popular formats are ASN.1 / DER format and raw format.Dfns APIs expects ECDSA/EDDSA signatures to use the ASN.1 / DER format.
With raw, the r and s values are directly concatenated together to form the signature. Each value must be exactly 32 bytes long, with 0s added to the beginning of the r/s if it is less then 32 bytes.
With ASN.1 / DER, the values are encoded using a deterministic format. The first byte is a magic value (0x30) that is used to identify the encoding. The second byte is the remaining length of the signature. The remaining bytes are the encoded r and s values. Each one is formated with its first byte being a magic value / separator (0x02). The second byte being the length of the value. And the remaining bytes being the value as a minimal-sized signed big-endian hex number. This means the number has all leading zeros removed, then the first byte must be a positive number (0x00-0x7F). If the minimized number starts with a negative value (0x80-0xFF) a zero is added to the beginning of the number. This means the final length of the value could be anywhere between 1 bytes and 33 bytes.
Base64 is a popular way of encoding large values into a string that contains only printable characters.Base64Url is an extension of Base64 encoding, but replaces characters that are not safe in URLs with different characters. It also minimizes the string, removing the extra padding characters. The Dfns auth system leverages Base64Url encoding in many different places.In Node.js, Buffer has built-in support for Base64Url as an encoding type. In Python, use the base64 module.
// Convert a string to a base64url stringBuffer.from('somerandomvalue').toString('base64url')// Convert a base64url string to a stringBuffer.from('c29tZXJhbmRvbXZhbHVl', 'base64url').toString()
For places where Buffer is not available in JavaScript, or an older Buffer implementation is used, this code can be used to convert a value to a Base64Url encoded string:
function arrayBufferToBase64(buffer) { const bytes = new Uint8Array(buffer) return btoa(String.fromCharCode(...bytes))}function arrayBufferToBase64Url(buffer) { return arrayBufferToBase64(buffer) .replace(/=/g, '') .replace(/\+/g, '-') .replace(/\//g, '_')}
Do not double-encode signatures. A common mistake is passing a base64 string to an encoding function like base64url(). These functions encode data, they don’t convert between formats.
Double-encoding causes Invalid signature errors. To diagnose: decode your signature with echo "<signature>" | base64 -D. If the output looks like another base64 string (e.g., MEYCIQCDsx...) instead of binary data, it’s double-encoded.