holochain-open-dev / holoom

Tools for weaving blockchain data into holochain
1 stars 1 forks source link

Spec Context Signing #27

Open 8e8b2c opened 6 days ago

8e8b2c commented 6 days ago

Discussion incoming...

8e8b2c commented 6 days ago

Example user story:

A user participates in a tournament, for which the match data is present in holoom, and they have winnings which require a signed context in order to claim.

NB: At some point before the tournament ended the user bound their external gamer ID (that is present in the match data) against their holochain agent, with use of holoom's ExternalId related tools.

At the close of the tournament, the owner of the winnings pool declared the following recipe and context signing offer:

// Recipe -> hashed to `some-fixed-recipe-address`
// Linked as: 'championships/123/player_winnings_context_for_signing'
{
  '$arguments': [{ name: 'winnings_recipient', type: 'EvmAddress' }]
  final_match_ids_name: { type: 'Constant', 'championships/123/match_ids_final' },
  match_ids: { type: 'GetLatestDocWithIdentifier', var_name: 'final_match_ids_name'  },
  matches: { type: 'GetDocsListedByVar', var_name: 'match_ids' },
  final_tickets_name: { type: 'Constant', 'championships/123/tickets_final' },
  tickets: { type: 'GetLatestDocWithIdentifier', var_name: 'final_tickets_name' },
  winnings_map: {
    type: 'Jq',
    in: ['matches', 'tickets'],
    program: '# build map { player_id -> winnings_and_ticket_number }'
  },
  external_id: { type: 'GetCallerExternalId' },
  '$return': {
    type: 'Jq',
    in: ['external_id', 'winnings_map', 'winnings_recipient'],
    program: `# select player split and arrange u256 array: [
      user_pubkey,
      winnings_recipient,
      winnings_percentage_split,
      flow_contract_address,
    ]'`
  }
}

// Signing offer -> hashed to `some-signing-offer-address`
// Linked as: 'championships/123/player_winnings_signing_offer'
{
  recipe_ah: 'some-fixed-recipe-address',
  u256_count: 4,
}

The user requests a signed context via the following flow. NB: this is executed in the UI of a happ, be it in a holo-network-backed browser webpage, a holochain launcher webhapp, or a bundled standalone executable.

const recipient = getWhicheverEvmWalletAddressUserSpecified();
const recipe = await holoomClient.getNamedRecipe(
  'championships/123/player_winnings_context_for_signing'
);
const execution = await  holoomClient.executeRecipe(
  recipe.actionHash,
  { arguments: [recipient]
});
const signingOffer = await holoomClient.getNamedSigningOffer(
  'championships/123/player_winnings_signing_offer'
);
const signedContext = await holoomClient.requestSignedContext(
  signingOffer.actionHash,
  execution.actionHash
);
8e8b2c commented 6 days ago

The user story for a meta-gamer would similar, but would instead produce a context of form:

[ticket_number, winnings_percentage_split, flow_contract_address]

The recipe would be modified to take a ticket number as an argument instead, which is used to select the split (external_id no longer needed).

8e8b2c commented 6 days ago

NB: this is executed in the UI of a happ, be it in a holo-network-backed browser webpage, a holochain launcher webhapp, or a bundled standalone executable.

Realistically it has to be a holo-network-backed browser webpage, else it's inconvenient to interact with the user's EVM wallet.