Skip to content

Commit

Permalink
update sign message
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjah committed Nov 28, 2024
1 parent b8e722e commit d25ab45
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/bearbyWallet/BearbyAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,14 @@ export class BearbyAccount implements Provider {
return networkInfos();
}

public async sign(data: Buffer | Uint8Array | string): Promise<SignedData> {
public async sign(data: Uint8Array | string): Promise<SignedData> {
// await this.connect();

let strData: string;
if (data instanceof Uint8Array) {
strData = new TextDecoder().decode(data);
}
if (data instanceof Buffer) {
strData = data.toString();
}

try {
const signature = await web3.wallet.signMessage(strData);

Expand Down
18 changes: 10 additions & 8 deletions src/massaStation/MassaStationAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
MASSA_STATION_ACCOUNTS_URL,
} from './MassaStationWallet';
import { argsToBase64, uint8ArrayToBase64 } from '../utils/argsToBase64';
import bs58check from 'bs58check';
import {
ExecuteFunctionBody,
MSAccountSignPayload,
Expand Down Expand Up @@ -33,11 +32,13 @@ import {
ReadSCParams,
SCEvent,
SignedData,
SignOptions,
SmartContract,
strToBytes,
} from '@massalabs/massa-web3';
import { getClient, networkInfos } from './utils/network';
import { WalletName } from '../wallet';
import bs58check from 'bs58check';

/**
* This module contains the MassaStationAccount class. It is responsible for representing an account in
Expand Down Expand Up @@ -71,14 +72,14 @@ export class MassaStationAccount implements Provider {
return Mas.fromString(final ? balances.final : balances.pending);
}

public async sign(data: Buffer | Uint8Array | string): Promise<SignedData> {
// TODO: Massa Station has 2 endpoints sign (to sign operation) and signMessage (to sign a message).
// To fix the current implementation we provide a dumb description and set DisplayData to true but it
// must this feature must be implemented in the future.
public async sign(
data: Uint8Array | string,
opts?: SignOptions,
): Promise<SignedData> {
const signData: MSAccountSignPayload = {
description: '',
message: data.toString(),
DisplayData: true,
description: opts?.description ?? '',
message: typeof data === 'string' ? data : new TextDecoder().decode(data),
DisplayData: opts?.displayData ?? true,
};

const res = await postRequest<MSAccountSignResp>(
Expand All @@ -90,6 +91,7 @@ export class MassaStationAccount implements Provider {
throw errorHandler(operationType.Sign, res.error);
}

// MS Wallet encodes signature in base64... so we need to decode it en re-encode it in base58
const signature = bs58check.encode(
Buffer.from(res.result.signature, 'base64'),
);
Expand Down

0 comments on commit d25ab45

Please sign in to comment.