aepp-sdk-js icon indicating copy to clipboard operation
aepp-sdk-js copied to clipboard

inconvenient usage of FATE variant types related to AENS

Open marc0olo opened this issue 3 years ago • 13 comments

this issue is closely related to https://github.com/aeternity/aepp-sdk-js/issues/1253 which is now solved and yes, we are able to handle those types now in the SDK.

as @thepiwo recently updated AEproject I took the chance to revisit my old draft PR where I wanted to test all the delegation signature stuff and opened a bunch of issues, see https://github.com/aeternity/aepp-sophia-examples/pull/67

actually I finally succeeded in encoding/decoding AENS relevant stuff (yeah 😎) but I am not really happy in the way we have to deal with the pointers right now:

js test

  it('should add and get pointers correctly', async () => {
      const accountPointerKey = SCHEMA.NAME_ID_KEY['ak'];
      const oraclePointerKey = SCHEMA.NAME_ID_KEY['ok'];
      const contractPointerKey = SCHEMA.NAME_ID_KEY['ct'];
      const channelPointerKey = SCHEMA.NAME_ID_KEY['ch'];
      let getPointersResult = await contract.methods.get_pointers(testName);
      console.log(getPointersResult.decodedResult);
      await contract.methods.add_key(nameOwnerKeypair.publicKey, testName, accountPointerKey, {'AENS.AccountPt':[nameOwnerKeypair.publicKey]}, aensDelegationSignature, { onAccount: delegateKeypair });
      await contract.methods.add_key(nameOwnerKeypair.publicKey, testName, oraclePointerKey, {'AENS.OraclePt':[nameOwnerKeypair.publicKey]}, aensDelegationSignature, { onAccount: delegateKeypair });
      await contract.methods.add_key(nameOwnerKeypair.publicKey, testName, contractPointerKey, {'AENS.ContractPt':[nameOwnerKeypair.publicKey]}, aensDelegationSignature, { onAccount: delegateKeypair });
      await contract.methods.add_key(nameOwnerKeypair.publicKey, testName, channelPointerKey, {'AENS.ChannelPt':[nameOwnerKeypair.publicKey]}, aensDelegationSignature, { onAccount: delegateKeypair });
      let aensName = await contract.methods.get_name(testName);
      console.log(aensName.decodedResult);
      pointers = await contract.methods.get_pointers(testName);
      console.log(pointers.decodedResult);
  });

test output

Map(0) {}
{
  'AENS.Name': [
    'ak_2VARB6P7nzKt4VvaPYLYVQgRfE92ahJJoYWuNc6eUvFSYgYiR3',
    { FixedTTL: [Array] },
    Map(4) {
      'channel' => [Object],
      'oracle_pubkey' => [Object],
      'account_pubkey' => [Object],
      'contract_pubkey' => [Object]
    }
  ]
}
Map(4) {
  'channel' => {
    'AENS.ChannelPt': [ 'ak_2VARB6P7nzKt4VvaPYLYVQgRfE92ahJJoYWuNc6eUvFSYgYiR3' ]
  },
  'oracle_pubkey' => {
    'AENS.OraclePt': [ 'ak_2VARB6P7nzKt4VvaPYLYVQgRfE92ahJJoYWuNc6eUvFSYgYiR3' ]
  },
  'account_pubkey' => {
    'AENS.AccountPt': [ 'ak_2VARB6P7nzKt4VvaPYLYVQgRfE92ahJJoYWuNc6eUvFSYgYiR3' ]
  },
  'contract_pubkey' => {
    'AENS.ContractPt': [ 'ak_2VARB6P7nzKt4VvaPYLYVQgRfE92ahJJoYWuNc6eUvFSYgYiR3' ]
  }
}
      ✔ should add and get pointers correctly (801ms)

I think it's really inconvenient to provide a variant for oracle, contract or channel which has the ak_ prefix in the required value. probably FATE internally represents it like this.

ideally the map of pointers would look like this:

Map(4) {
  'channel' => 'ch_2VARB6P7nzKt4VvaPYLYVQgRfE92ahJJoYWuNc6eUvFSYgYiR3',
  'oracle_pubkey' => 'ok_2VARB6P7nzKt4VvaPYLYVQgRfE92ahJJoYWuNc6eUvFSYgYiR3',
  'account_pubkey' => 'ak_2VARB6P7nzKt4VvaPYLYVQgRfE92ahJJoYWuNc6eUvFSYgYiR3',
  'contract_pubkey' => 'ct_2VARB6P7nzKt4VvaPYLYVQgRfE92ahJJoYWuNc6eUvFSYgYiR3'
}

what do others think regarding this? make we can introduce some helper functions for transforming functions in both directions.

we should also consider https://github.com/aeternity/aepp-sdk-js/issues/1240 when addressing this. maybe even independent of this. currently we still don't allow custom keys in the SDK.

cc @dincho @mradkov @davidyuk

marc0olo avatar Nov 24 '21 00:11 marc0olo