Skip to content
This repository was archived by the owner on Jan 30, 2024. It is now read-only.
This repository was archived by the owner on Jan 30, 2024. It is now read-only.

Avoid to keep PrivateKey in HederaWallet object #5

@franfernandez20

Description

@franfernandez20

I propose changing the approach to sign transactions and messages. I would avoid storing the PrivateKey in an object and delegate its use to a signer element like Client or Wallet.

Example for transactions:

// [...]
await transaction.sign(this._privateKey)
// [...]

to

// [...]
await transaction.signWithOperator(this._client)
// [...]

Example for messages:

  public signMessages(bytes: string[]): HederaSignMessageResponse {
    return {
      signatures: bytes.map((bytes) => {
        const buf = Buffer.from(bytes, 'base64')
        this._client._operator?.transactionSigner(buf)
        const signedMessage = this._privateKey.sign(buf)
        return Buffer.from(signedMessage).toString('base64')
      }),
    }
  }

to

// [...]
 this._wallet = new Wallet(accountId, privateKey)
// [...]
  public signMessages(bytes: string[]): HederaSignMessageResponse {
    return {
      signatures: bytes.map((bytes) => {
        const buf = Buffer.from(bytes, 'base64')
        const signedMessage = await this._wallet.sign([buf])
        // or 
        // const signedMessage = await this._client.getOperator().transactionSigner(buf)
        return Buffer.from(signedMessage).toString('base64')
      }),
    }
  }

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions