signStringOrJson function

Future<String> signStringOrJson(
  1. WalletStore wallet,
  2. String didToSignWith,
  3. dynamic toSign, {
  4. bool detached = false,
  5. dynamic jwsHeader,
})

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, dynamic toSign,
    {bool detached = false, dynamic jwsHeader}) async {
  if (didToSignWith.startsWith('did:ethr')) {
    return _signStringEthr(wallet, didToSignWith, toSign,
        detached: detached, jwsHeader: jwsHeader);
  } else if (didToSignWith.startsWith('did:key:z6Mk')) {
    return _signStringEddsa(wallet, didToSignWith, toSign,
        detached: detached, jwsHeader: jwsHeader);
  } else {
    throw UnimplementedError('did with type `$didToSignWith` '
        'is not supported for signing');
  }
}