TBD54566975 / web5-js

Monorepo for the Web5 JS TypeScript implementation
https://tbd54566975.github.io/web5-js/
Apache License 2.0
127 stars 48 forks source link

Confusing method signature #740

Open nitro-neal opened 2 months ago

nitro-neal commented 2 months ago

Updated: Scroll to bottom - https://github.com/TBD54566975/web5-js/issues/740#issuecomment-2233929020

Make sure we can import a portable did:dht that is no published.

  let issuerDid = '{"uri":"did:dht:91szhs8sagq3rq9x6fraono8gci7ekcz7s5ubfenjpkqk1dbi8po","document":{"id":"did:dht:91szhs8sagq3rq9x6fraono8gci7ekcz7s5ubfenjpkqk1dbi8po","verificationMethod":[{"id":"did:dht:91szhs8sagq3rq9x6fraono8gci7ekcz7s5ubfenjpkqk1dbi8po#0","type":"JsonWebKey","controller":"did:dht:91szhs8sagq3rq9x6fraono8gci7ekcz7s5ubfenjpkqk1dbi8po","publicKeyJwk":{"crv":"Ed25519","kty":"OKP","x":"_K1-WPbBnZI77_FJiAoHMyvUKZfttzCVAktU5Uhhqds","kid":"jO36EX1wmepvGW12XKt2flvysx9De9xSKePhkjGCl90","alg":"EdDSA"}}],"authentication":["did:dht:91szhs8sagq3rq9x6fraono8gci7ekcz7s5ubfenjpkqk1dbi8po#0"],"assertionMethod":["did:dht:91szhs8sagq3rq9x6fraono8gci7ekcz7s5ubfenjpkqk1dbi8po#0"],"capabilityDelegation":["did:dht:91szhs8sagq3rq9x6fraono8gci7ekcz7s5ubfenjpkqk1dbi8po#0"],"capabilityInvocation":["did:dht:91szhs8sagq3rq9x6fraono8gci7ekcz7s5ubfenjpkqk1dbi8po#0"]},"metadata":{"published":false,"versionId":"1718733387"},"privateKeys":[{"crv":"Ed25519","d":"TiHl5oXKLf8eB0ipacSGIJIkuS0UNrHC5OQoYSBK0Os","kty":"OKP","x":"_K1-WPbBnZI77_FJiAoHMyvUKZfttzCVAktU5Uhhqds","kid":"jO36EX1wmepvGW12XKt2flvysx9De9xSKePhkjGCl90","alg":"EdDSA"}]}'

  const issuerPortableDid = JSON.parse(issuerDid);
  const issuer = await DidDht.import({ issuerPortableDid });
  await DidDht.publish({ did: issuer });

this did looks valid but it crashes on import, maybe becasue published is false.

chris-tbd commented 1 month ago

Filed another issue here since I'm seeing this on published dids as well: https://github.com/TBD54566975/tbdex-js/issues/259

nitro-neal commented 1 month ago

here is my method signature:

public static async import({ portableDid, keyManager = new LocalKeyManager() }: {

if I do this it works: customerDid = await DidDht.import({ portableDid });

if I mistakenly do this it still compiles and crashes later on:

customerDid = await DidDht.import({ customerPortableDid });

Can I change my message signaure or some typescript compile time thing to not let this happen?

chat gpt has a solution: https://chatgpt.com/share/e/311e2c09-953a-42c9-9008-d90bfe9d1507