signStringOrJson function
Signs the given String (normal or Json-Object) or Json-Object (Dart Map<String, dynamic>) toSign
with key-pair of didToSignWith
.
Returned signature is formatted as jws. If a detached jws (header..signature) should be returned detached
must be set to true.
If no custom jwsHeader
is given, the default one is
{
"alg" : "ES256K-R",
"b64" : false,
"crit" : ["b64"]
}
if did is of type did:ethr or
{
"alg" : "EdDSA",
"crv" : "Ed25519"
}
if did is of type did:key with appropriate key-Material If a custom one should be used, it has to be given in its json representation (dart String or Map) and the value of alg has to be ES256K-R or EdDSA with curve Ed25519, because for now this is the only supported signature algorithm.
Implementation
Future<String> signStringOrJson(
{WalletStore? wallet,
String? didToSignWith,
Map<String, dynamic>? jwk,
required dynamic toSign,
Signer? signer,
bool detached = false,
dynamic jwsHeader}) async {
signer ??= jwk != null
? _determineSignerForJwk(jwk, null)
: _determineSignerForDid(didToSignWith!, null);
return signer.sign(
data: toSign,
wallet: wallet,
did: didToSignWith,
jwk: jwk,
detached: detached,
jwsHeader: jwsHeader);
}