Skip to content

Commit

Permalink
[C-927] Fix 0x prefix in native (#3788)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson authored Aug 31, 2022
1 parent 287f5e2 commit b2033d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions libs/src/api/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class Account extends Base {

const unixTs = Math.round(new Date().getTime() / 1000) // current unix timestamp (sec)
const data = `Click sign to authenticate with identity service: ${unixTs}`
const signature = await this.web3Manager.sign(data)
const signature = await this.web3Manager.sign(Buffer.from(data, 'utf-8'))

const recoveryData = {
login: recoveryInfo.login,
Expand Down Expand Up @@ -709,7 +709,9 @@ export class Account extends Base {
this.REQUIRES(Services.IDENTITY_SERVICE)
const unixTs = Math.round(new Date().getTime() / 1000) // current unix timestamp (sec)
const message = `Click sign to authenticate with identity service: ${unixTs}`
const signature = await this.ethWeb3Manager.sign(message)
const signature = await this.ethWeb3Manager.sign(
Buffer.from(message, 'utf-8')
)
const wallet = this.ethWeb3Manager.getWalletAddress()
return await this.identityService.updateMinimumDelegationAmount(
wallet,
Expand Down
4 changes: 3 additions & 1 deletion libs/src/services/identity/IdentityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,9 @@ export class IdentityService {
if (this.web3Manager) {
const unixTs = Math.round(new Date().getTime() / 1000) // current unix timestamp (sec)
const message = `Click sign to authenticate with identity service: ${unixTs}`
const signature = await this.web3Manager?.sign(message)
const signature = await this.web3Manager?.sign(
Buffer.from(message, 'utf-8')
)
return {
[AuthHeaders.MESSAGE]: message,
[AuthHeaders.SIGNATURE]: signature
Expand Down
6 changes: 3 additions & 3 deletions libs/src/services/web3Manager/Web3Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ export class Web3Manager {
* Signs provided string data (should be timestamped).
* @param data
*/
async sign(data: string) {
async sign(data: string | Buffer) {
if (this.useExternalWeb3) {
const account = this.getWalletAddress()
if (this.isServer) {
return await this.web3?.eth.sign(
this.web3.utils.fromUtf8(data),
this.web3.utils.fromUtf8(data as string),
account
)
} else {
return await this.web3?.eth.personal.sign(
this.web3.utils.fromUtf8(data),
this.web3.utils.fromUtf8(data as string),
account,
''
)
Expand Down

0 comments on commit b2033d5

Please sign in to comment.