helium / maker-starter-app

Apache License 2.0
36 stars 39 forks source link

How to get keypair for API Authorization #22

Closed estherlinlin closed 2 years ago

estherlinlin commented 2 years ago

Problem

Our team is developing maker-app base on this repository. Currently we are migrating update and transfer hotspot features from helium-app, but encounter an issue 401 authorization fail, when calling API from wallet endpoint https://wallet.api.helium.systems/api

status:401 message: POST url:https://wallet.api.helium.systems/api/transactions]

We need keypair to generate token for the Authorization header in api request, (keypair are also needed when calling transaction APIs) but we only could retrieve walletLinkToken when user sign in by linking helium account.

How can we get the keypair for API authorization and transaction signing? Or is there a way to get keypair from walletLinkToken?

Related Code

src/utils/secureAccount.ts

export const createKeypair = async (
  givenMnemonic: Mnemonic | Array<string> | null = null,
) => {
  ...
  const { keypair: keypairRaw, address } = await Keypair.fromMnemonic(mnemonic)

  await Promise.all([
    setSecureItem('mnemonic', JSON.stringify(mnemonic.words)),
    setSecureItem('keypair', JSON.stringify(keypairRaw)),
    setSecureItem('address', address.b58),
  ])
}

export const getKeypair = async (): Promise<Keypair | undefined> => {
  const keypairStr = await getSecureItem('keypair')
  if (keypairStr) {
    const keypairRaw = JSON.parse(keypairStr)
    return new Keypair(keypairRaw)
  }
}
estherlinlin commented 2 years ago

We found the solution in the latest update. Thanks! 🙏 The flow of transfer hotspot and assert location has changed by submitting the transaction on helium official hotspot app, it seems that it is not allowed to go through whole transaction only by maker app.

MykhailoMashchenko commented 2 years ago

Hi, we are currently trying to get this keypair keys to work with https://wallet.api.helium.systems/api. Any help with that? Thx