Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
4 changes: 2 additions & 2 deletions src/components/Common/SignSendTx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import {mapState} from 'vuex'
import delay from 'delay'
import {DEFAULT_SCRYPT} from '../../core/consts'
import { getRestClient } from '../../core/utils'
import { getRestClient, encryptedPrivateKeyFromAccount } from '../../core/utils'
import {legacySignWithLedger, checkPublicKeyIsInTheConnectedLedger} from '../../core/ontLedger'
import {Crypto, TransactionBuilder, TxSignature, utils, RestClient, WebsocketClient, Transaction, OntAssetTxBuilder} from 'ontology-ts-sdk'
// common component to sign tx or messages with wallet or ledger.
Expand Down Expand Up @@ -93,7 +93,7 @@ export default {
}
if (this.wallet.key) {
this.$store.dispatch("showLoadingModals");
const enc = new Crypto.PrivateKey(this.wallet.key);
const enc = encryptedPrivateKeyFromAccount(this.wallet);
let pri;
try {
pri = enc.decrypt(
Expand Down
4 changes: 2 additions & 2 deletions src/components/CommonWallet/CommonRedeem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import { TEST_NET, MAIN_NET, ONT_CONTRACT, ONT_PASS_NODE, DEFAULT_SCRYPT, GAS_PR
import {mapState} from 'vuex'
import {getDeviceInfo, getPublicKey, checkPublicKeyIsInTheConnectedLedger} from '../../core/ontLedger'
import {BigNumber} from 'bignumber.js'
import { getRestClient } from '../../core/utils'
import { getRestClient, encryptedPrivateKeyFromAccount } from '../../core/utils'
export default {
name: 'CommonRedeem',
components: {
Expand Down Expand Up @@ -183,7 +183,7 @@ export default {
const tx = OntAssetTxBuilder.makeWithdrawOngTx(from, to, amount, from, GAS_PRICE, GAS_LIMIT);
if(this.type === 'commonWallet') {
this.$store.dispatch('showLoadingModals')
const enc = new Crypto.PrivateKey(this.currentWallet.key)
const enc = encryptedPrivateKeyFromAccount(this.currentWallet)
let pri;
try {
pri = enc.decrypt(this.password, from, this.currentWallet.salt, DEFAULT_SCRYPT)
Expand Down
4 changes: 2 additions & 2 deletions src/components/CommonWallet/SendConfirm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ import axios from 'axios';
import {getDeviceInfo, getPublicKey, checkPublicKeyIsInTheConnectedLedger} from '../../core/ontLedger'
// import $ from 'jquery'
import {BigNumber} from 'bignumber.js'
import { getRestClient } from '../../core/utils'
import { getRestClient, encryptedPrivateKeyFromAccount } from '../../core/utils'

export default {
name: 'SendConfirm',
Expand Down Expand Up @@ -335,7 +335,7 @@ export default {

if (this.isCommonWallet) {
this.$store.dispatch('showLoadingModals')
const enc = new Crypto.PrivateKey(this.currentWallet.key)
const enc = encryptedPrivateKeyFromAccount(this.currentWallet)
let pri;
try {
pri = enc.decrypt(this.password, new Crypto.Address(this.currentWallet.address), this.currentWallet.salt, DEFAULT_SCRYPT)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Identitys/Create/BasicInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import dbService from '../../../core/dbService'
import {DEFAULT_SCRYPT, TEST_NET, MAIN_NET} from '../../../core/consts'
import {legacySignWithLedger} from '../../../core/ontLedger'
import { getRestClient } from '../../../core/utils'
import { getRestClient, encryptedPrivateKeyFromAccount } from '../../../core/utils'

export default {
name: 'BasicInfo',
Expand Down Expand Up @@ -139,7 +139,7 @@ import { getRestClient } from '../../../core/utils'
// const tx = Object.assign({}, res);
this.$store.dispatch('showLoadingModals')
if(this.payerWalletType === 'commonWallet') {
const enc = new Crypto.PrivateKey(this.payerWallet.key)
const enc = encryptedPrivateKeyFromAccount(this.payerWallet)
let pri;
try {
pri = enc.decrypt(this.payerPassword, new Crypto.Address(this.payerWallet.address), this.payerWallet.salt, DEFAULT_SCRYPT)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Identitys/IdentityView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<script>
import {Wallet, Account, Crypto, Identity} from 'ontology-ts-sdk';
import dbService from '../../core/dbService'
import { formatScryptParams } from '../../core/utils'
import { formatScryptParams, encryptedPrivateKeyFromAccount } from '../../core/utils'
export default {
name: "IdentityView",
props: ['identity'],
Expand Down Expand Up @@ -105,7 +105,7 @@
}
this.$store.dispatch('showLoadingModals')
const controlData = this.identity.controls[0];
const enc = new Crypto.PrivateKey(controlData.key)
const enc = encryptedPrivateKeyFromAccount(controlData)
let pri;
const scrypt = this.identity.scrypt ||
{
Expand Down
4 changes: 2 additions & 2 deletions src/components/Identitys/Import/BasicInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import dbService from '../../../core/dbService'
import {DEFAULT_SCRYPT, TEST_NET, MAIN_NET} from '../../../core/consts'
// import $ from 'jquery'
import { getNodeUrl, getRestClient, formatScryptParams } from '../../../core/utils';
import { getNodeUrl, getRestClient, formatScryptParams, encryptedPrivateKeyFromAccount } from '../../../core/utils';

export default {
name: 'BasicInfo',
Expand Down Expand Up @@ -96,7 +96,7 @@ import { getNodeUrl, getRestClient, formatScryptParams } from '../../../core/uti
}
let identity = new Identity();
try {
const encryptedPrivateKeyObj = new Crypto.PrivateKey(keystore.key);
const encryptedPrivateKeyObj = encryptedPrivateKeyFromAccount(keystore);
const addr = new Crypto.Address(keystore.address);
const label = keystore.label || 'Identity'
const salt = keystore.salt
Expand Down
21 changes: 18 additions & 3 deletions src/components/JsonWallet/Import/BasicInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ textarea::-webkit-input-placeholder {
:data-vv-as="$t('FormField.privateKey')" name="pk" v-model="pk"
:placeholder="$t('importJsonWallet.privateKeyTip')"></a-input>
<span class="v-validate-span-errors" v-show="errors.has('pk')">{{ errors.first('pk') }}</span>
<a-checkbox v-model="pkExodusEd25519" class="input" style="margin-top: 12px; display: block;">
{{ $t('importJsonWallet.exodusEd25519Import') }}
</a-checkbox>
<p v-show="pkExodusEd25519" class="tip" style="margin-top: 8px;">{{ $t('importJsonWallet.exodusEd25519Hint') }}</p>
<a-input type="password" class="input input-password" v-validate="{ required: true, min: 6 }"
:data-vv-as="$t('FormField.password')" name="pkPassword" v-model="pkPassword"
:placeholder="$t('importJsonWallet.setPassword')"></a-input>
Expand Down Expand Up @@ -268,7 +272,7 @@ import FileHelper from "../../../core/fileHelper"
import dbService from '../../../core/dbService'
import { DEFAULT_SCRYPT } from '../../../core/consts'
// import $ from 'jquery'
import { isHexString, convertScryptParams } from '../../../core/utils'
import { isHexString, convertScryptParams, encryptedPrivateKeyFromAccount } from '../../../core/utils'

export default {
name: 'BasicInfo',
Expand All @@ -278,6 +282,7 @@ export default {

pk: '',
pkLabel: '',
pkExodusEd25519: false,
pkPassword: '',
pkRePassword: '',

Expand Down Expand Up @@ -362,9 +367,19 @@ export default {
}
},
importAccountForPK() {
let privateKey;
if (this.pkExodusEd25519) {
privateKey = new Crypto.PrivateKey(
this.pk,
Crypto.KeyType.EDDSA,
new Crypto.KeyParameters(Crypto.CurveLabel.ED25519)
);
} else {
privateKey = new Crypto.PrivateKey(this.pk);
}
let body = {
label: this.pkLabel,
privateKey: new Crypto.PrivateKey(this.pk),
privateKey,
password: this.pkPassword
}
if (!isHexString(this.pk)) {
Expand Down Expand Up @@ -446,7 +461,7 @@ export default {
}

try {
const enc = new Crypto.PrivateKey(account.key);
const enc = encryptedPrivateKeyFromAccount(account);
const address = new Crypto.Address(account.address)
let scrypt = convertScryptParams(this.datWallet.scrypt)
let pri;
Expand Down
5 changes: 3 additions & 2 deletions src/components/JsonWallet/View/Details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
import FileHelper from "../../../core/fileHelper"
import {DEFAULT_SCRYPT} from '../../../core/consts'
import {Crypto} from 'ontology-ts-sdk'
import { encryptedPrivateKeyFromAccount } from '../../../core/utils'
import dbService from '../../../core/dbService'
export default {
name: "JsonWalletDetails",
Expand Down Expand Up @@ -174,7 +175,7 @@
return;
}
this.$store.dispatch('showLoadingModals')
const enc = new Crypto.PrivateKey(this.wallet.key)
const enc = encryptedPrivateKeyFromAccount(this.wallet)
let pri;
try {
pri = enc.decrypt(this.password, new Crypto.Address(this.wallet.address), this.wallet.salt, DEFAULT_SCRYPT)
Expand Down Expand Up @@ -234,7 +235,7 @@
this.$validator.validateAll().then(result => {
if(result) {
this.$store.dispatch('showLoadingModals').then( () => {
const enc = new Crypto.PrivateKey(this.wallet.key)
const enc = encryptedPrivateKeyFromAccount(this.wallet)
let pri;
try {
pri = enc.decrypt(this.oldPassword, new Crypto.Address(this.wallet.address), this.wallet.salt, DEFAULT_SCRYPT)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Node/NodeStake/NodeStakeInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ import Breadcrumb from "../../Breadcrumb";
import { mapState } from "vuex";
import { Crypto, TransactionBuilder, utils, TxSignature, GovernanceTxBuilder, RestClient } from "ontology-ts-sdk";
import {legacySignWithLedger, checkPublicKeyIsInTheConnectedLedger} from '../../../core/ontLedger'
import {varifyPositiveInt, getNodeUrl} from '../../../core/utils.js'
import {varifyPositiveInt, getNodeUrl, encryptedPrivateKeyFromAccount} from '../../../core/utils.js'
import axios from "axios";
import {
ONT_PASS_NODE,
Expand Down Expand Up @@ -320,7 +320,7 @@ export default {
this.refundClicked = true;
if (this.stakeWallet.key) {
this.$store.dispatch("showLoadingModals");
const enc = new Crypto.PrivateKey(this.stakeWallet.key);
const enc = encryptedPrivateKeyFromAccount(this.stakeWallet);
let pri;
try {
pri = enc.decrypt(
Expand Down
5 changes: 3 additions & 2 deletions src/components/Node/NodeStake/NodeStakeRegister.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import { GAS_PRICE, GAS_LIMIT, TEST_NET, MAIN_NET, ONT_PASS_NODE, ONT_PASS_NODE_
import { Crypto, TransactionBuilder, RestClient, utils, GovernanceTxBuilder, TxSignature } from "ontology-ts-sdk";
import axios from 'axios'
import {legacySignWithLedger} from '../../../core/ontLedger'
import { encryptedPrivateKeyFromAccount } from '../../../core/utils'

export default {
name: "NodeStakeRegister",
Expand Down Expand Up @@ -181,7 +182,7 @@ export default {
return;
}
if (this.ontidPassword) {
const enc = new Crypto.PrivateKey(this.stakeIdentity.controls[0].key);
const enc = encryptedPrivateKeyFromAccount(this.stakeIdentity.controls[0]);
let pri;
try {
pri = enc.decrypt(
Expand Down Expand Up @@ -212,7 +213,7 @@ export default {
return;
}
if(this.stakeWallet.key) {
const enc = new Crypto.PrivateKey(this.stakeWallet.key);
const enc = encryptedPrivateKeyFromAccount(this.stakeWallet);
let pri;
try {
pri = enc.decrypt(
Expand Down
4 changes: 2 additions & 2 deletions src/components/SharedWallet/PAX/SignProcess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<script>
import Breadcrumb from '../../Breadcrumb'
import {mapState} from 'vuex'
import { getRestClient } from '../../../core/utils'
import { getRestClient, encryptedPrivateKeyFromAccount } from '../../../core/utils'
import {Transaction, Crypto, TransactionBuilder, TxSignature, utils, RestClient} from 'ontology-ts-sdk'
import {legacySignWithLedger} from '../../../core/ontLedger'
import {PAX_API} from '../../../core/consts'
Expand Down Expand Up @@ -258,7 +258,7 @@ export default {
})

if (this.currentSigner.type === 'CommonWallet') {
const enc = new Crypto.PrivateKey(this.currentSigner.wallet.key)
const enc = encryptedPrivateKeyFromAccount(this.currentSigner.wallet)
const pri = decryptWallet({
key: this.currentSigner.wallet.key,
address: this.currentSigner.address,
Expand Down
4 changes: 2 additions & 2 deletions src/components/SharedWallet/PAX/StartProcess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ import {mapState} from 'vuex'
import {legacySignWithLedger} from '../../../core/ontLedger'
import {Transaction, Crypto, TransactionBuilder, TxSignature, utils} from 'ontology-ts-sdk'
import {PAX_API} from '../../../core/consts'
import {decryptWallet} from '../../../core/utils'
import {decryptWallet, encryptedPrivateKeyFromAccount} from '../../../core/utils'

export default {
name: 'StartProcess',
Expand Down Expand Up @@ -286,7 +286,7 @@ export default {
})
//sponsorPayer
if (this.sponsorPayer.type === 'CommonWallet') {
const enc = new Crypto.PrivateKey(this.sponsorPayer.wallet.key)
const enc = encryptedPrivateKeyFromAccount(this.sponsorPayer.wallet)
const pri = decryptWallet({
key: this.sponsorPayer.wallet.key,
address: this.sponsorPayer.address,
Expand Down
3 changes: 2 additions & 1 deletion src/components/SharedWallet/Transfer/InputPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import axios from 'axios'
import dbService from '../../../core/dbService'
import { BigNumber } from 'bignumber.js';
import {legacySignWithLedger, checkPublicKeyIsInTheConnectedLedger} from '../../../core/ontLedger'
import { encryptedPrivateKeyFromAccount } from '../../../core/utils'

export default {
name:'InputPassword',
Expand Down Expand Up @@ -190,7 +191,7 @@ export default {
//sponsorWallet

if (this.sponsorWallet.type === 'CommonWallet') {
const enc = new Crypto.PrivateKey(this.sponsorWallet.wallet.key)
const enc = encryptedPrivateKeyFromAccount(this.sponsorWallet.wallet)
let pri;
try {
pri = enc.decrypt(this.password, new Crypto.Address(this.sponsorWallet.address), this.sponsorWallet.wallet.salt, DEFAULT_SCRYPT)
Expand Down
4 changes: 2 additions & 2 deletions src/components/SharedWallet/Transfer/PendingTxSign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ import {ONT_PASS_NODE, ONT_PASS_NODE_PRD, ONT_PASS_URL, DEFAULT_SCRYPT, TEST_NET
import axios from 'axios'
import dbService from '../../../core/dbService'
import {legacySignWithLedger, checkPublicKeyIsInTheConnectedLedger} from '../../../core/ontLedger'
import { getRestClient } from '../../../core/utils';
import { getRestClient, encryptedPrivateKeyFromAccount } from '../../../core/utils';

export default {
name:'PendingTxSign',
Expand Down Expand Up @@ -139,7 +139,7 @@ export default {
const M = tx.sigs[0].M;
const pks = tx.sigs[0].pubKeys;
if (this.currentSigner.type === 'CommonWallet') {
const enc = new Crypto.PrivateKey(this.currentSigner.key)
const enc = encryptedPrivateKeyFromAccount(this.currentSigner)
let pri;
try {
pri = enc.decrypt(this.password, new Crypto.Address(this.currentSigner.address), this.currentSigner.salt, DEFAULT_SCRYPT)
Expand Down
18 changes: 18 additions & 0 deletions src/core/ontologyEd25519SignFix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* ontology-ts-sdk hashes the tx hash again with SHA512 before Ed25519 signing (Key.computeHash for
* EDDSAwithSHA512). The Ontology node verifies with ed25519.Verify(pub, txHash32, sig) — the same
* 32-byte double-SHA256 payload as getSignContent(), not SHA512(txHash). Without this patch, Exodus /
* Ed25519 accounts fail signature verification on-chain.
*/
import { Crypto } from 'ontology-ts-sdk'

const keyProto = Object.getPrototypeOf(Crypto.PrivateKey.prototype)
const orig = keyProto.computeHash

keyProto.computeHash = function (msg, scheme) {
if (scheme && scheme.hex === 10) {
// SignatureScheme.EDDSAwithSHA512 — sign raw tx digest hex from getSignContent()
return msg
}
return orig.call(this, msg, scheme)
}
18 changes: 17 additions & 1 deletion src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,24 @@ export function convertStr2Number(str, decimal = 0) {
return val.toNumber();
}

/**
* Wraps an encrypted account `key` for decryption. ECDSA (default) accounts
* work with the key string alone; EDDSA/Ed25519 accounts require algorithm + parameters from the keystore.
* @param {object} account - Wallet account object (e.g. `wallet` from DB or `account.toJsonObj()`)
*/
export function encryptedPrivateKeyFromAccount(account) {
if (account && account.algorithm && account.parameters) {
return new Crypto.PrivateKey(
account.key,
Crypto.KeyType.fromLabel(account.algorithm),
Crypto.KeyParameters.deserializeJson(account.parameters)
)
}
return new Crypto.PrivateKey(account.key)
}

export function decryptWallet(wallet, password, scrypt = DEFAULT_SCRYPT) {
const enc = new Crypto.PrivateKey(wallet.key)
const enc = encryptedPrivateKeyFromAccount(wallet)
let pri;
try {
pri = enc.decrypt(password, new Crypto.Address(wallet.address), wallet.salt, scrypt)
Expand Down
2 changes: 2 additions & 0 deletions src/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ export default {
success: 'Import wallet successfully!',
saveDbFailed: 'Save to keystore failed. Please try later.',
invalidPrivateKey: 'Please enter valid private key.',
exodusEd25519Import: 'Exodus / BIP32 Ed25519',
exodusEd25519Hint: 'Use this when importing the 64-character hex private key from Exodus (or another wallet that uses BIP32 with Ed25519 on this path). Standard OWallet import uses ECDSA P-256.',
setPassword: 'Set password',
importFirstDefault: 'Will only import the default wallet or the first wallet in the .dat file'
},
Expand Down
2 changes: 2 additions & 0 deletions src/lang/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ export default {
success: '导入钱包成功',
saveDbFailed: '保存到Keystore失败。请稍后重试。',
invalidPrivateKey: '请输入正确的私钥',
exodusEd25519Import: 'Exodus / BIP32 Ed25519',
exodusEd25519Hint: '从 Exodus(或其他在此路径使用 BIP32 + Ed25519 的钱包)导入 64 位十六进制私钥时请勾选。默认导入使用 ECDSA P-256。',
setPassword: '设置密码',
importFirstDefault: '只导入.dat文件中的默认钱包或第一个钱包'
},
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './core/ontologyEd25519SignFix'
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/Vote.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NODE_CURRENT_STAKES,OFF_CHAIN_NODES, VOTE_ROLE, DEFAULT_SCRYPT, ONT_PASS_NODE, ONT_PASS_NODE_PRD,
ONT_PASS_URL } from '../../core/consts'
import httpService, { getRestClient } from '../../core/utils'
import httpService, { getRestClient, encryptedPrivateKeyFromAccount } from '../../core/utils'
import { TransactionBuilder, Crypto, utils, Parameter, ParameterType, TxSignature, WebsocketClient } from 'ontology-ts-sdk'
import {
message
Expand Down Expand Up @@ -159,7 +159,7 @@ function formatVoteInfo(infos) {

const handleSignTx = async function (tx, wallet, password, walletType = 'commonWallet') {
if (walletType === 'commonWallet') {
const enc = new Crypto.PrivateKey(wallet.key);
const enc = encryptedPrivateKeyFromAccount(wallet);
let pri;
try {
pri = enc.decrypt(
Expand Down
Loading