create static method

Future<DelegationChain> create(
  1. SignIdentity from,
  2. PublicKey to,
  3. DateTime? expiration,
  4. {DelegationChain? previous,
  5. List<Principal>? targets}

Create a delegation chain between two (or more) keys. By default, the expiration time will be very short (15 minutes).

To build a chain of more than 2 identities, this function needs to be called multiple times, passing the previous delegation chain into the options argument. For example:

@example const rootKey = createKey(); const middleKey = createKey(); const bottomeKey = createKey();

const rootToMiddle = await DelegationChain.create( root, middle.getPublicKey(), Date.parse('2100-01-01'), ); const middleToBottom = await DelegationChain.create( middle, bottom.getPublicKey(), Date.parse('2100-01-01'), { previous: rootToMiddle }, );

// We can now use a delegation identity that uses the delegation above: const identity = DelegationIdentity.fromDelegation(bottomKey, middleToBottom);

@param from The identity that will delegate. @param to The identity that gets delegated. It can now sign messages as if it was the identity above. @param expiration The length the delegation is valid. By default, 15 minutes from calling this function. @param options A set of options for this delegation. expiration and previous @param options.previous - Another DelegationChain that this chain should start with. @param options.targets - targets that scope the delegation (e.g. Canister Principals)


static Future<DelegationChain> create(
    SignIdentity from, PublicKey to, DateTime? expiration,
    {DelegationChain? previous, List<Principal>? targets}) async {
  expiration ??= DateTime.fromMillisecondsSinceEpoch( + 15 * 60 * 1000);
  final delegation =
      await _createSingleDelegation(from, to, expiration, targets);

  return DelegationChain(
    [...(previous?.delegations ?? []), delegation],
    previous?.publicKey ?? from.getPublicKey().toDer(),