Skip to content

Commit

Permalink
Merge pull request #982 from crypto-com/dev
Browse files Browse the repository at this point in the history
Internal Release v0.6.8
  • Loading branch information
crypto-matto authored Feb 14, 2022
2 parents 1aad103 + e191a28 commit 125a7c7
Show file tree
Hide file tree
Showing 26 changed files with 555 additions and 152 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
*Unreleased*

*Released*
## [v0.6.8] - 2022-02-11
### Additions
- Wrapped ETH NFT support on Crypto.org chain
- Add NFT attributes display support
### Bug fixes
- Missing Ledger sign methods support
- Fix potential app crash in Wallet Page
- Align NFT minting metadata

## [v0.6.7] - 2022-01-28
### Bug fixes
- Incorrect delegation items
Expand Down
39 changes: 39 additions & 0 deletions electron/IpcMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,44 @@ export class IpcMain {
}
event.returnValue = ret;
});
ipcMain.on('ethSignPersonalMessage', async (event: any, arg: any) => {
let ret = {};
console.log('ethSignPersonalMessage, ', arg.message, ' . ', arg.index);

try {
const sig = await this.ethProvider.signPersonalMessage(arg.message, arg.index);
ret = {
sig,
success: true,
label: 'ethSignPersonalMessage reply',
};
} catch (e) {
ret = {
success: false,
error: e.toString(),
};
console.error('ethSignPersonalMessage error ', e);
}

event.returnValue = ret;
});
ipcMain.on('ethSignTypedDataV4', async (event: any, arg: any) => {
let ret = {};
try {
const sig = await this.ethProvider.signTypedDataV4(arg.typedData, arg.index);
ret = {
sig,
success: true,
label: 'ethSignTypedDataV4 reply',
};
} catch (e) {
ret = {
success: false,
error: e.toString(),
};
console.error('ethSignTypedDataV4 error ' + e);
}
event.returnValue = ret;
});
}
}
58 changes: 53 additions & 5 deletions electron/LedgerEthSigner.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* eslint-disable prefer-template */
import TransportHID from '@ledgerhq/hw-transport-node-hid';
import Eth from '@ledgerhq/hw-app-eth';
import { ethers } from 'ethers';
import Web3 from 'web3';
import { TypedDataUtils } from 'eth-sig-util';

export class LedgerEthSigner {
public app: any;
public app: Eth | undefined;

public transport: TransportHID | null;

constructor() {
this.transport = null;
}
Expand All @@ -22,15 +26,15 @@ export class LedgerEthSigner {
if (this.transport != null) {
this.transport.close();
this.transport = null;
this.app = null;
this.app = undefined;
}
}

async getAddress(index: number = 0, display: boolean): Promise<string> {
try {
const path: string = `44'/60'/0'/0/${index}`;
await this.createTransport();
const retAddress = await this.app.getAddress(path, display, false);
const retAddress = await this.app!.getAddress(path, display, false);
return retAddress.address;
} finally {
await this.closeTransport();
Expand Down Expand Up @@ -81,7 +85,7 @@ export class LedgerEthSigner {
};

const unsignedTx = ethers.utils.serializeTransaction(baseTx).substring(2);
const sig = await this.app.signTransaction(path, unsignedTx);
const sig = await this.app!.signTransaction(path, unsignedTx);
// to prevent possible padding issue
const sigR = LedgerEthSigner.padZeroString(sig.r, 32);
const sigS = LedgerEthSigner.padZeroString(sig.s, 32);
Expand Down Expand Up @@ -138,7 +142,7 @@ export class LedgerEthSigner {
await this.createTransport();
const path: string = `44'/60'/0'/0/${index}`;
const web3 = new Web3(url);
const from_addr = (await this.app.getAddress(path)).address;
const from_addr = (await this.app!.getAddress(path)).address;
const nonce = await web3.eth.getTransactionCount(from_addr);
const signedTx = await this.doSignTx(
path,
Expand All @@ -157,4 +161,48 @@ export class LedgerEthSigner {
await this.closeTransport();
}
}

async signPersonalMessage(msg: string, index = 0) {
try {
await this.createTransport();
const path: string = `44'/60'/0'/0/${index}`;
const sig = await this.app!.signPersonalMessage(path, Buffer.from(msg).toString('hex'));
return LedgerEthSigner.getHexlifySignature(sig);
} finally {
await this.closeTransport();
}
}

static getHexlifySignature(sig: { v: number; r: string; s: string }) {
const v = sig.v - 27;
let vStr = v.toString(16);
if (vStr.length < 2) {
vStr = '0' + v;
}

return '0x' + sig.r + sig.s + vStr;
}

async signTypedDataV4(typedData: any, index = 0) {
try {
await this.createTransport();
const path: string = `44'/60'/0'/0/${index}`;

const data = JSON.parse(typedData);

const domainSeparator = TypedDataUtils.hashStruct('EIP712Domain', data.domain, data.types);

const hashedMessage = TypedDataUtils.hashStruct(data.primaryType, data.message, data.types);

const sig = await this.app!.signEIP712HashedMessage(
path,
ethers.utils.hexlify(domainSeparator),
ethers.utils.hexlify(hashedMessage),
);

return LedgerEthSigner.getHexlifySignature(sig);
} finally {
await this.closeTransport();
}
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chain-desktop-wallet",
"version": "0.6.7",
"version": "0.6.8",
"description": "Crypto.com Chain Desktop Wallet App",
"repository": "github:crypto-com/chain-desktop-wallet",
"author": "Crypto.org <[email protected]>",
Expand All @@ -18,12 +18,14 @@
"@ledgerhq/hw-transport-node-hid": "^6.6.0",
"@ledgerhq/hw-transport-webhid": "5.48.0",
"@ledgerhq/hw-transport-webusb": "5.48.0",
"@types/bluebird": "3.5.36",
"antd": "4.16.0",
"axios": "0.21.2",
"bech32": "2.0.0",
"bfj": "7.0.2",
"big.js": "6.0.3",
"bignumber.js": "9.0.1",
"bluebird": "3.7.2",
"camelcase": "6.2.0",
"copyfiles": "2.4.1",
"cross-env": "7.0.3",
Expand Down
19 changes: 18 additions & 1 deletion src/config/StaticConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const NOT_KNOWN_YET_VALUE = 'TO_BE_DECIDED';
export const MODERATION_CONFIG_FILE_URL =
'https://raw.githubusercontent.com/crypto-com/chain-desktop-wallet/dev/config/app.moderation.json';


export const UNBLOCKING_PERIOD_IN_DAYS = {
UNDELEGATION: {
MAINNET: '28',
Expand Down Expand Up @@ -260,6 +259,24 @@ export const NFT_VIDEO_DENOM_SCHEMA = {
},
},
};
export const NFT_WRAPPED_ETH_DENOM_SCHEMA = {
title: 'Asset Metadata',
type: 'Object',
properties: {
isExternal: {
type: 'boolean',
description: 'Describes whether the NFT is external or internal to the Crypto.org chain',
},
network: {
type: 'string',
description: 'Identifies the original network of the NFT',
},
identifier: {
type: 'string',
description: 'An identifier with the format: {contact_address}/{tokenID}',
},
},
};

export const MAX_IMAGE_SIZE = 10 * 1024 * 1024;
export const MAX_VIDEO_SIZE = 20 * 1024 * 1024;
Expand Down
3 changes: 3 additions & 0 deletions src/language/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@
"nft.nftCollection.table1.viewAction": "Action",
"nft.nftCollection.table1.action1": "View",
"nft.detailModal.subtitle": "Description",
"nft.detailModal.attributes": "Attributes",
"nft.detailModal.traitType": "Trait Type",
"nft.detailModal.value": "Value",
"nft.detailModal.label1": "Denom ID",
"nft.detailModal.label2": "Denom Name",
"nft.detailModal.label3": "Token ID",
Expand Down
3 changes: 3 additions & 0 deletions src/language/ko-KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,9 @@
"nft.nftCollection.table1.viewAction": "활동",
"nft.nftCollection.table1.action1": "보기",
"nft.detailModal.subtitle": "삭제에 대해",
"nft.detailModal.attributes": "속성",
"nft.detailModal.traitType": "특성",
"nft.detailModal.value": "",
"nft.detailModal.label1": "디놈 ID",
"nft.detailModal.label2": "디놈 이름",
"nft.detailModal.label3": "토큰 ID",
Expand Down
3 changes: 3 additions & 0 deletions src/language/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@
"nft.nftCollection.table1.viewAction": "操作",
"nft.nftCollection.table1.action1": "浏览",
"nft.detailModal.subtitle": "关于",
"nft.detailModal.attributes": "属性",
"nft.detailModal.traitType": "特征",
"nft.detailModal.value": "",
"nft.detailModal.label1": "系列 ID",
"nft.detailModal.label2": "系列名称",
"nft.detailModal.label3": "代币 ID",
Expand Down
3 changes: 3 additions & 0 deletions src/language/zh-HK.json
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@
"nft.nftCollection.table1.viewAction": "操作",
"nft.nftCollection.table1.action1": "瀏覽",
"nft.detailModal.subtitle": "關於",
"nft.detailModal.attributes": "屬性",
"nft.detailModal.traitType": "特徵",
"nft.detailModal.value": "",
"nft.detailModal.label1": "系列 ID",
"nft.detailModal.label2": "系列名稱",
"nft.detailModal.label3": "代幣 ID",
Expand Down
Loading

0 comments on commit 125a7c7

Please sign in to comment.