authrite-utils v0.3.36
authrite-utils
This package offers essential utility functions used by authrite-js and authrite-express for tasks like mutual authentication. Additionally, it provides a valuable resource for those looking to implement the Authrite specification on a communication channel not yet supported.
API
Table of Contents
- createRequestSignature
- getCertificatesToInclude
- getRequestAuthHeaders
- verifyServerInitialResponse
- verifyServerResponse
- getResponseAuthHeaders
- validateAuthHeaders
- validateCertificates
- verifyCertificate
- verifyCertificateSignature
- decryptCertificateFields
- certifierInitialResponse
- certifierSignCheckArgs
- certifierCreateSignedCertificate
- decryptOwnedCertificateField
- decryptOwnedCertificateFields
- decryptOwnedCertificates
createRequestSignature
Creates a valid ECDSA message signature to include in an Authrite request
Parameters
objobject all params given in an objectobj.dataToSign(string | buffer) the data that should be signed with the derived private keyobj.requestNoncestring random data provided by the clientobj.serverInitialNoncestring random session data provided by the serverobj.clientPrivateKeystring? optional private key to use as the signing strategyobj.serverPublicKeystring the identity key of the server the request should be sent to
getCertificatesToInclude
Provide a list of certificates with acceptable type and certifier values for the request, based on what the server requested
Parameters
objobject all params provided in an object
getRequestAuthHeaders
Construct BRC-31 compliant authentication headers to send to the server Note: Currently assumes initial param validation has been done. TODO: Add it here as well Note: Also doesn't currently support the initial request response here. TODO: add it here as well
Parameters
objobject all params given in an objectobj.authriteVersionstring the current version of Authrite being usedobj.clientPublicKeystring of the current client making the requestobj.requestNoncestring random nonce provided by the clientobj.serverInitialNoncestring initial session nonce provided by the serverobj.requestSignaturestring message signature provided as a hex stringobj.certificatesToIncludeArray authrite certificates provided to the server upon request (optional, default'[]')obj.clientInitialNonce
Returns object valid auth headers
verifyServerInitialResponse
Verifies a server's initial response as part of the initial handshake
Parameters
objobject all params given in an objectobj.authriteVersionstring the current version of Authrite being used by the serverobj.baseUrlstring the baseUrl of the serverobj.signingStrategystring specifies which signing strategy should be usedobj.clientPrivateKey(string | buffer | undefined)? clientPrivateKey to use for key derivationobj.clientsobject object whose keys are base URLs and whose values are instances of the Client classobj.serversobject object whose keys are base URLs and whose values are instances of the Server classobj.serverResponseobject contains the server's response including the required authentication dataobj.certificatesArray the current available certificates
verifyServerResponse
Verifies a server's response after the initial handshake has happened
Parameters
objobject all params given in an objectobj.messageToVerifystring the message signed to verifyobj.headersobject the authentication headers provided by the serverobj.baseUrlstring the baseUrl of the serverobj.signingStrategystring specifies which signing strategy should be usedobj.clientsobject the clients the current Authrite instance is interacting withobj.serversobject the servers the current Authrite instance is interacting withobj.clientPrivateKey(string | buffer | undefined)? clientPrivateKey to use for key derivation
getResponseAuthHeaders
Constructs the required server response headers for a given client Supports initial request, and subsequent requests
Parameters
objobject all params given in an objectobj.authritestring the version of authrite being usedobj.messageTypestring type of message to respond toobj.serverPrivateKeystring server private key to use to derive the signing private keyobj.clientPublicKeystring public key of the senderobj.clientNoncestring random data provided by the clientobj.serverNoncestring random data provided by the serverobj.messageToSignstring expected message to be signed (optional, default'test')obj.certificatesArray provided certificates as requested by the client (optional, default[])obj.requestedCertificatesArray a structure indicating which certificates the client should provide
Returns object the required response headers for authentication
validateAuthHeaders
Used to validate client auth headers provided in a request
Parameters
objobject all params given in an object
Returns boolean the validation result
validateCertificates
Validates an array of certificates provided in a request
Parameters
objobject all params given in an object
Returns (Array | object) array of the validated certificates, or an Error object to return to the client
verifyCertificate
Verifies a certificate signature, structure, and revocation status
Parameters
certificatechain
verifyCertificateSignature
Verifies that the provided certificate has a valid signature. Also checks the structure of the certificate. Throws errors if the certificate is invalid.
Note: Does not guarantee that additional fields are not provided in this certificate structure!
Parameters
certificateObject The certificate to verify.
Returns Boolean true if the certificate is valid
decryptCertificateFields
Verifies that the provided certificate has a valid signature
Parameters
certificateObject The certificate to verify.keyringObject The keyring containing the encrypted fieldRevelationKeys.verifierPrivateKeystring A private key as a base64 string belonging to the certificate verifier. If not provided, the BabbageSDK decrypt function will be used instead.
Returns Object An object containing the decrypted fields.
certifierInitialResponse
Authrite Certifier Helper Function Creates a response object in the standard format for initialRequest.
Parameters
objObject All parameters for this function are provided in an object
certifierSignCheckArgs
Authrite Certifier Helper Function Checks the standard inputs to signCertificate for common errors. Returns null on success (no errors). Returns an object like { code: 'ERR_INVALID_REQUEST', description: '...' } on failure.
Parameters
objObject All parameters for this function are provided in an objectobj.clientNoncestring? random data selected by client. Typically 32 bytes in base64 encoding.obj.certifierPrivateKeystring? Certifier's private key. 32 random bytes in hex encoding.obj.certificateTypestring? Certificate type identifier. 32 bytes in base64 encoding.obj.messageTypestring? Must be the string 'certificateSigningRequest'.obj.typestring? The requested certificate type. Must equal certificateType.obj.serverSerialNoncestring? The serialNonce value returned by prior initialRequest.obj.serverValidationNoncestring? The validationNonce value returned by prior initialRequest.obj.serialNumberstring? The serialNumber value returned by prior initialRequest.obj.validationKeystring? The validationKey value returned by prior initialRequest.
certifierCreateSignedCertificate
Authrite Certifier Helper Function Checks the standard inputs to signCertificate for common errors. Returns null on success (no errors). Returns an object like { code: 'ERR_INVALID_REQUEST', description: '...' } on failure.
Parameters
objObject All parameters for this function are provided in an objectobj.validationKeystring? The validationKey value returned by prior initialRequest.obj.certifierPrivateKeystring? Certifier's private key. 32 random bytes in hex encoding.obj.certificateTypestring? Certificate type identifier. 32 bytes in base64 encoding.obj.serialNumberstring? The serialNumber value returned by prior initialRequest.obj.clientNoncestring? random data selected by client. Typically 32 bytes in base64 encoding.obj.messageTypestring? Must be the string 'certificateSigningRequest'.obj.typestring? The requested certificate type. Must equal certificateType.obj.serverSerialNoncestring? The serialNonce value returned by prior initialRequest.obj.serverValidationNoncestring? The validationNonce value returned by prior initialRequest.obj.subjectobj.fieldsobj.revocationOutpoint
decryptOwnedCertificateField
Decrypts a single certificate field for client-only use.
Parameters
objObject All parameters are provided in an object
Returns Promise[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) The decrypted field value for client-side-only use
decryptOwnedCertificateFields
Decrypts all fields in a certificate for client-only use.
Parameters
certificateObject The certificate containing fields to decryptcallerAgreesToKeepDataClientSideBoolean Whether the caller of this function agrees to keep the data client-side (optional, defaultfalse)
Returns Promise[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) Decrypted fields object for client-side-only use
decryptOwnedCertificates
Searches for user certificates, returning decrypted certificate fields for client-side-only use
Parameters
$0Object$0.certifiers$0.types$0.callerAgreesToKeepDataClientSide(optional, defaultfalse)
Returns Promise[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)> The set of decrypted certificates for client-only use
License
The license for the code in this repository is the Open BSV License.
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago