animo / aries-mobile-sdk

Apache License 2.0
8 stars 2 forks source link

add Aries Askar as wallet/storage implementation besides Indy SDK #15

Open TimoGlastra opened 2 years ago

TimoGlastra commented 2 years ago

Create abstraction in AFJ that allows us to use both the current, Indy SDK, wallet/storage and a new Aries Askar wallet/storage implementation

TimoGlastra commented 2 years ago

Untitled-2021-10-05-1552 (1)

This approach is the same for Indy Credx (#14), Indy VDR (#12) and Aries Askar (#15). For description of Indy Format see #22

TimoGlastra commented 2 years ago

Wallet design

Remove createDid from the wallet. Wallet only focusses on creating and managing keys. Extend to support multiple key types

interface WalletManagement {
  initialize(walletConfig: WalletConfig): Promise<void>;
  create(walletConfig: WalletConfig): Promise<void>;
  open(walletConfig: WalletConfig): Promise<void>;
  close(): Promise<void>;
  delete(): Promise<void>;
}

interface SignOptions {
  data: Buffer | Buffer[];
  publicKey: Buffer;
  keyType: KeyType;
}

interface VerifyOptions {
  data: Buffer | Buffer[];
  signature: Buffer;
  publicKey: Buffer;
  // May be inferred
  keyType: KeyType;
}

interface PackOptions {
  payload: Buffer | string;
  recipientKeys: string[];
  senderKey: string;
}

interface UnpackOptions {
  payload: Buffer;
}

interface UnpackResult {
  payload: string;
  recipientKey: string;
  senderKey?: string;
}

interface Wallet {
  sign(options: SignOptions): Promise<Buffer>;
  verify(options: VerifyOptions): Promise<boolean>;

  pack(options: PackOptions): Promise<Buffer>;
  unpack(options: UnpackOptions): Promise<UnpackResult>;

  generateNonce(): Promise<string>;
}

interface DidRegistrar {
  create();
  update();
  deactivate();
}

// DidRegistrar calls the wallet to create the needed keys
// DidRegistrar creates a did record storing details about a specific did
//  - could only be a did with some metadata (in case of did:key or simple did:peer)
//  - or could be a complete DIDDoc (in case of complex did:peer)

// need to remove seed from startup parameters, you should just call did registrar if you want to call it.
// If the did already exists on the ledger you should somehow be able to add the key to the wallet based on a seed, resolve the did from the ledger, and be able to mark it as owned by me
// no reason at all to only have a single public did
// when issuing with indy credentials, the credential definition determines the did to use for issuance