From b6e30358be967ddbbb623e2aa28e2ae89c9d85ed Mon Sep 17 00:00:00 2001 From: classicalliu Date: Tue, 8 Oct 2019 01:18:14 +0800 Subject: [PATCH 1/2] feat: bump sdk to v0.22.0 --- packages/neuron-ui/package.json | 2 +- packages/neuron-wallet/package.json | 6 +-- .../database/chain/entities/transaction.ts | 4 +- packages/neuron-wallet/src/env.ts | 2 +- .../neuron-wallet/src/models/lock-utils.ts | 7 ++- packages/neuron-wallet/src/services/cells.ts | 2 +- .../src/services/tx/transaction-generator.ts | 4 +- .../src/services/tx/transaction-service.ts | 4 +- .../neuron-wallet/src/services/wallets.ts | 20 +++----- .../startup/sync-block-task/init-database.ts | 2 + .../neuron-wallet/src/types/cell-types.ts | 8 +-- .../tests/models/lock-utils.test.ts | 16 +++--- .../tests/services/cells.test.ts | 6 +-- .../tests/services/wallets.test.ts | 9 ++-- yarn.lock | 51 ++++++++----------- 15 files changed, 62 insertions(+), 81 deletions(-) diff --git a/packages/neuron-ui/package.json b/packages/neuron-ui/package.json index 7504478707..036dde0c9a 100644 --- a/packages/neuron-ui/package.json +++ b/packages/neuron-ui/package.json @@ -43,7 +43,7 @@ "last 2 chrome versions" ], "dependencies": { - "@nervosnetwork/ckb-sdk-core": "0.21.0", + "@nervosnetwork/ckb-sdk-core": "0.22.0", "@uifabric/experiments": "7.16.1", "@uifabric/styling": "7.6.2", "canvg": "2.0.0", diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 5abac9a1ef..c2b4800eeb 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -34,8 +34,8 @@ ] }, "dependencies": { - "@nervosnetwork/ckb-sdk-core": "0.21.0", - "@nervosnetwork/ckb-sdk-utils": "0.21.0", + "@nervosnetwork/ckb-sdk-core": "0.22.0", + "@nervosnetwork/ckb-sdk-utils": "0.22.0", "bn.js": "4.11.8", "chalk": "2.4.2", "electron-log": "3.0.7", @@ -51,7 +51,7 @@ "uuid": "3.3.3" }, "devDependencies": { - "@nervosnetwork/ckb-types": "0.21.0", + "@nervosnetwork/ckb-types": "0.22.0", "@types/electron-devtools-installer": "2.2.0", "@types/elliptic": "6.4.9", "@types/sqlite3": "3.1.5", diff --git a/packages/neuron-wallet/src/database/chain/entities/transaction.ts b/packages/neuron-wallet/src/database/chain/entities/transaction.ts index ef3c763633..3cbcae9063 100644 --- a/packages/neuron-wallet/src/database/chain/entities/transaction.ts +++ b/packages/neuron-wallet/src/database/chain/entities/transaction.ts @@ -11,7 +11,7 @@ import { AfterRemove, } from 'typeorm' import { remote } from 'electron' -import { Witness, Transaction as TransactionInterface, TransactionStatus, CellDep } from 'types/cell-types' +import { Transaction as TransactionInterface, TransactionStatus, CellDep } from 'types/cell-types' import TxDbChangedSubject from 'models/subjects/tx-db-changed-subject' import InputEntity from './input' import OutputEntity from './output' @@ -47,7 +47,7 @@ export default class Transaction extends BaseEntity { @Column({ type: 'simple-json', }) - witnesses!: Witness[] + witnesses!: string[] @Column({ type: 'varchar', diff --git a/packages/neuron-wallet/src/env.ts b/packages/neuron-wallet/src/env.ts index 4e9b84fde9..7e4721adfe 100644 --- a/packages/neuron-wallet/src/env.ts +++ b/packages/neuron-wallet/src/env.ts @@ -50,7 +50,7 @@ const env: ENV = { name: 'Local', remote: 'http://localhost:8114', type: 1, - chain: 'ckb_devnet', + chain: 'ckb_dev', }, ], }, diff --git a/packages/neuron-wallet/src/models/lock-utils.ts b/packages/neuron-wallet/src/models/lock-utils.ts index 4c19809139..6ac0094768 100644 --- a/packages/neuron-wallet/src/models/lock-utils.ts +++ b/packages/neuron-wallet/src/models/lock-utils.ts @@ -85,7 +85,7 @@ export default class LockUtils { const lock: Script = { codeHash: systemScript.codeHash, - args: [LockUtils.addressToBlake160(address)], + args: LockUtils.addressToBlake160(address), hashType, } return lock @@ -113,7 +113,7 @@ export default class LockUtils { } static lockScriptToAddress(lock: Script): string { - const blake160: string = lock.args![0] + const blake160: string = lock.args! return this.blake160ToAddress(blake160) } @@ -127,8 +127,7 @@ export default class LockUtils { } static addressToBlake160(address: string): string { - const prefix = env.testnet ? core.utils.AddressPrefix.Testnet : core.utils.AddressPrefix.Mainnet - const result: string = core.utils.parseAddress(address, prefix, 'hex') as string + const result: string = core.utils.parseAddress(address, 'hex') as string const hrp: string = `0100` let blake160: string = result.slice(hrp.length + 2, result.length) if (!blake160.startsWith('0x')) { diff --git a/packages/neuron-wallet/src/services/cells.ts b/packages/neuron-wallet/src/services/cells.ts index 59ee071edf..0717f698ca 100644 --- a/packages/neuron-wallet/src/services/cells.ts +++ b/packages/neuron-wallet/src/services/cells.ts @@ -159,7 +159,7 @@ export default class CellsService { if (!args) { return undefined } - return args[0] + return args }) .filter(blake160 => !!blake160) as string[] diff --git a/packages/neuron-wallet/src/services/tx/transaction-generator.ts b/packages/neuron-wallet/src/services/tx/transaction-generator.ts index 8e26b7a891..d37bdad2d1 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-generator.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-generator.ts @@ -34,7 +34,7 @@ export class TransactionGenerator { data: '0x', lock: { codeHash, - args: [blake160], + args: blake160, hashType, }, } @@ -53,7 +53,7 @@ export class TransactionGenerator { data: '0x', lock: { codeHash, - args: [changeBlake160], + args: changeBlake160, hashType, }, } diff --git a/packages/neuron-wallet/src/services/tx/transaction-service.ts b/packages/neuron-wallet/src/services/tx/transaction-service.ts index ea608f3b84..ebe924e05c 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-service.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-service.ts @@ -269,11 +269,11 @@ export class TransactionsService { let outputBlake160s: string[] = [] if (tx.inputs) { inputBlake160s = tx.inputs - .map(input => input.lock && input.lock.args && input.lock.args[0]) + .map(input => input.lock && input.lock.args) .filter(blake160 => blake160) as string[] } if (tx.outputs) { - outputBlake160s = tx.outputs.map(output => output.lock.args![0]) + outputBlake160s = tx.outputs.map(output => output.lock.args!) } return [...new Set(inputBlake160s.concat(outputBlake160s))] } diff --git a/packages/neuron-wallet/src/services/wallets.ts b/packages/neuron-wallet/src/services/wallets.ts index 683e4f9410..d137e19cb8 100644 --- a/packages/neuron-wallet/src/services/wallets.ts +++ b/packages/neuron-wallet/src/services/wallets.ts @@ -4,7 +4,7 @@ import { AccountExtendedPublicKey, PathAndPrivateKey } from 'models/keys/key' import Keystore from 'models/keys/keystore' import Store from 'models/store' import LockUtils from 'models/lock-utils' -import { Witness, TransactionWithoutHash, Input } from 'types/cell-types' +import { TransactionWithoutHash, Input } from 'types/cell-types' import ConvertTo from 'types/convert-to' import Blake2b from 'utils/blake2b' import { WalletNotFound, IsRequired, UsedName } from 'exceptions' @@ -380,8 +380,8 @@ export default class WalletService { const paths = addressInfos.map(info => info.path) const pathAndPrivateKeys = this.getPrivateKeys(wallet, paths, password) - const witnesses: Witness[] = inputs!.map((input: Input) => { - const blake160: string = input.lock!.args![0] + const witnesses: string[] = inputs!.map((input: Input) => { + const blake160: string = input.lock!.args! const info = addressInfos.find(i => i.blake160 === blake160) const { path } = info! const pathAndPrivateKey = pathAndPrivateKeys.find(p => p.path === path) @@ -389,7 +389,7 @@ export default class WalletService { throw new Error('no private key found') } const { privateKey } = pathAndPrivateKey - const witness = this.signWitness({ data: [] }, privateKey, txHash) + const witness = this.signWitness('', privateKey, txHash) return witness }) @@ -443,19 +443,15 @@ export default class WalletService { return addr!.address } - public signWitness = (witness: Witness, privateKey: string, txHash: string): Witness => { + public signWitness = (witness: string, privateKey: string, txHash: string): string => { const addrObj = core.generateAddress(privateKey) - const oldData = witness.data + const oldData = witness const blake2b = new Blake2b() blake2b.update(txHash) - oldData.forEach(data => { - blake2b.update(data) - }) + blake2b.update(oldData) const message = blake2b.digest() const signature = addrObj.signRecoverable(message) - const newWitness: Witness = { - data: [signature], - } + const newWitness = signature return newWitness } diff --git a/packages/neuron-wallet/src/startup/sync-block-task/init-database.ts b/packages/neuron-wallet/src/startup/sync-block-task/init-database.ts index 93ea191d83..2728d9baae 100644 --- a/packages/neuron-wallet/src/startup/sync-block-task/init-database.ts +++ b/packages/neuron-wallet/src/startup/sync-block-task/init-database.ts @@ -2,6 +2,7 @@ import initConnection from 'database/chain/ormconfig' import Utils from 'services/sync/utils' import { updateMetaInfo, getMetaInfo } from 'database/chain/meta-info' import LockUtils from 'models/lock-utils' +import logger from 'utils/logger' import genesisBlockHash from './genesis' export const initDatabase = async () => { @@ -11,6 +12,7 @@ export const initDatabase = async () => { const systemScriptInfo = await LockUtils.systemScript() updateMetaInfo({ genesisBlockHash: hash, systemScriptInfo }) } catch (err) { + logger.debug('initDatabase error:', err) try { const metaInfo = getMetaInfo() await initConnection(metaInfo.genesisBlockHash) diff --git a/packages/neuron-wallet/src/types/cell-types.ts b/packages/neuron-wallet/src/types/cell-types.ts index ec440857de..150dec9946 100644 --- a/packages/neuron-wallet/src/types/cell-types.ts +++ b/packages/neuron-wallet/src/types/cell-types.ts @@ -45,7 +45,7 @@ export interface TransactionWithoutHash { value?: string blockNumber?: string blockHash?: string - witnesses?: Witness[] + witnesses?: string[] type?: string description?: string status?: TransactionStatus @@ -65,10 +65,6 @@ export interface Input { lock?: Script } -export interface Witness { - data: string[] -} - export interface Cell { capacity: string data?: string @@ -85,7 +81,7 @@ export interface OutPoint { } export interface Script { - args?: string[] + args?: string codeHash?: string | null hashType: ScriptHashType } diff --git a/packages/neuron-wallet/tests/models/lock-utils.test.ts b/packages/neuron-wallet/tests/models/lock-utils.test.ts index bd2fa60ea7..6f9e4ded1f 100644 --- a/packages/neuron-wallet/tests/models/lock-utils.test.ts +++ b/packages/neuron-wallet/tests/models/lock-utils.test.ts @@ -3,32 +3,32 @@ import LockUtils from '../../src/models/lock-utils' const systemScript = { outPoint: { - txHash: '0x74e34a76d68f5ed864c0ad139a82461ee809e981939cd9cfcd92ac0fdbb1114b', + txHash: '0xb815a396c5226009670e89ee514850dcde452bca746cdd6b41c104b50e559c70', index: '0', }, - codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', + codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8', hashType: ScriptHashType.Type, } describe('LockUtils Test', () => { const bob = { lockScript: { - codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', - args: ['0x36c329ed630d6ce750712a477543672adab57f4c'], + codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8', + args: '0x36c329ed630d6ce750712a477543672adab57f4c', hashType: ScriptHashType.Type, }, - lockHash: '0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba', + lockHash: '0x1f2615a8dde4e28ca736ff763c2078aff990043f4cbf09eb4b3a58a140a0862d', address: 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83', blake160: '0x36c329ed630d6ce750712a477543672adab57f4c', } const alice = { lockScript: { - codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', - args: ['0xe2193df51d78411601796b35b17b4f8f2cd85bd0'], + codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8', + args: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0', hashType: ScriptHashType.Type, }, - lockHash: '0x489306d801d54bee2d8562ae20fdc53635b568f8107bddff15bb357f520cc02c', + lockHash: '0xa35eda3e71e86e4e22b7924012b6a6e90809dc7a68621d5f7a7c40eea01be45e', address: 'ckt1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gqfvmy2v', blake160: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0', } diff --git a/packages/neuron-wallet/tests/services/cells.test.ts b/packages/neuron-wallet/tests/services/cells.test.ts index 3040481e72..98a4676440 100644 --- a/packages/neuron-wallet/tests/services/cells.test.ts +++ b/packages/neuron-wallet/tests/services/cells.test.ts @@ -32,7 +32,7 @@ describe('CellsService', () => { const bob = { lockScript: { codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', - args: ['0x36c329ed630d6ce750712a477543672adab57f4c'], + args: '0x36c329ed630d6ce750712a477543672adab57f4c', hashType: ScriptHashType.Type, }, lockHash: '0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba', @@ -43,7 +43,7 @@ describe('CellsService', () => { const alice = { lockScript: { codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', - args: ['0xe2193df51d78411601796b35b17b4f8f2cd85bd0'], + args: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0', hashType: ScriptHashType.Type, }, lockHash: '0x489306d801d54bee2d8562ae20fdc53635b568f8107bddff15bb357f520cc02c', @@ -85,7 +85,7 @@ describe('CellsService', () => { const typeScript: Script = { codeHash: randomHex(), - args: [], + args: '', hashType: ScriptHashType.Data, } diff --git a/packages/neuron-wallet/tests/services/wallets.test.ts b/packages/neuron-wallet/tests/services/wallets.test.ts index 28f7bbbe7d..69ce960a40 100644 --- a/packages/neuron-wallet/tests/services/wallets.test.ts +++ b/packages/neuron-wallet/tests/services/wallets.test.ts @@ -1,5 +1,4 @@ import WalletService, { WalletProperties } from '../../src/services/wallets' -import { Witness } from '../../src/types/cell-types' import Keystore from '../../src/models/keys/keystore' import Keychain from '../../src/models/keys/keychain' import { mnemonicToSeedSync } from '../../src/models/keys/mnemonic' @@ -175,17 +174,15 @@ describe('wallet service', () => { }) describe('sign witness', () => { - const witness: Witness = { data: [] } + const witness: string = '' const privateKey: string = '0xe79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3' const txHash = '0x00f5f31941964004d665a8762df8eb4fab53b5ef8437b7d34a38e018b1409054' - const expectedData = [ - '0x99b79ff84dc39de16ec7ed2e9a2836a2560b95a71041ad3a6c00b2d31844db4c26b760918bbe08747ead167cccb35b1b9ba4db42896c19e412b885cd6589d41a00', - ] + const expectedData = '0x99b79ff84dc39de16ec7ed2e9a2836a2560b95a71041ad3a6c00b2d31844db4c26b760918bbe08747ead167cccb35b1b9ba4db42896c19e412b885cd6589d41a00' it('success', () => { const wallet = new WalletService() const newWitness = wallet.signWitness(witness, privateKey, txHash) - expect(newWitness.data).toEqual(expectedData) + expect(newWitness).toEqual(expectedData) }) }) diff --git a/yarn.lock b/yarn.lock index b23e07cdfd..42b67faf55 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2079,45 +2079,36 @@ call-me-maybe "^1.0.1" glob-to-regexp "^0.3.0" -"@nervosnetwork/ckb-sdk-address@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-address/-/ckb-sdk-address-0.21.0.tgz#bf78b3bcb84f80566d9167c5b38d9dac8b5eb81f" - integrity sha512-2sYFh38/DYHbb2OCvyTB3UGbrdbGU2qj47dQY82lsznDphblC6h/VLwISlaE/xQ04de/idb0Uc0fHVAqA4lkEg== +"@nervosnetwork/ckb-sdk-core@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-core/-/ckb-sdk-core-0.22.0.tgz#dc4e93d425154e0dfeb40c08932095c0b99b8947" + integrity sha512-HKFFD4L3tK5yWsVSPn0t5qc+NZ35wmoEpd2q5wJtTt8rpLb0n1lJKKk8MQCRhWLR9a8UPskISrLDLyI2uQ7Q8Q== dependencies: - "@nervosnetwork/ckb-sdk-utils" "0.21.0" - "@nervosnetwork/ckb-types" "0.21.0" + "@nervosnetwork/ckb-sdk-rpc" "0.22.0" + "@nervosnetwork/ckb-sdk-utils" "0.22.0" + "@nervosnetwork/ckb-types" "0.22.0" -"@nervosnetwork/ckb-sdk-core@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-core/-/ckb-sdk-core-0.21.0.tgz#60d5bb5bb2c80b31a77c221ab06fded4d34b72c0" - integrity sha512-zS8vp01t5iYqXDsAjlhcdZafIXaYkJoYXSC1cnCh3dr23iaYuYjDz9/mbe2j/fZ4p46c1NSqQRpo4TGubhSm1g== +"@nervosnetwork/ckb-sdk-rpc@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-rpc/-/ckb-sdk-rpc-0.22.0.tgz#f5a4b8459941fed110505b92fa94014d8853073b" + integrity sha512-auc2RqktbvQqyn8LcTnLVjgAMXIm1C0zLIHEEltngXQbZA5YeLXfJnC0RSSvpwloThgFpuKPvTy19b2/N9YzNg== dependencies: - "@nervosnetwork/ckb-sdk-address" "0.21.0" - "@nervosnetwork/ckb-sdk-rpc" "0.21.0" - "@nervosnetwork/ckb-sdk-utils" "0.21.0" - "@nervosnetwork/ckb-types" "0.21.0" - -"@nervosnetwork/ckb-sdk-rpc@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-rpc/-/ckb-sdk-rpc-0.21.0.tgz#4ff7d8e16b716c49ad5e9cc32868324921ba6b3b" - integrity sha512-0Dz871S9slwFPASs3Dz/07kkRK99T3uFo60zgyt1GSEmGoSREqXOwzaXbEU2lqPLvmFz1GP+T/mHt4TtIf7nWg== - dependencies: - "@nervosnetwork/ckb-sdk-utils" "0.21.0" + "@nervosnetwork/ckb-sdk-utils" "0.22.0" axios "0.19.0" -"@nervosnetwork/ckb-sdk-utils@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-utils/-/ckb-sdk-utils-0.21.0.tgz#461c9864d511bd4b9fb4469f4f0a35b4e631e589" - integrity sha512-MNMG1cx8w+qLrF1iKJLT8NgpZ+gaFrbvgtYF9SCqQiChqZI2iQyBdT7QyBQ/XPIRi5EKyEjyFH5+ofPwukWDFA== +"@nervosnetwork/ckb-sdk-utils@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-utils/-/ckb-sdk-utils-0.22.0.tgz#94a0e03cec53ff6bfe4664e9afc4d84a0e01ee77" + integrity sha512-Rz6s9drKhBlZM1NVMpz5wP1WPMDOD6VIpwUpATF7zcpeyzMHJtFgZjGAOeDGuP1OMNZIQzUMW5v7RB3MpzXAQQ== dependencies: - "@nervosnetwork/ckb-types" "0.21.0" + "@nervosnetwork/ckb-types" "0.22.0" blake2b-wasm "1.1.7" elliptic "6.5.1" -"@nervosnetwork/ckb-types@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-types/-/ckb-types-0.21.0.tgz#20cfc81f2eef8c7baa36f0ada4f7642aee0eaf39" - integrity sha512-1VhtubsnTkY+rP+CiQ25nXoK+5SLWlf+aUsGJ7HhWhjP1gzlBJKXB3EAoa92FZzmfARJ7U3QKJoAEV4Bo6KXkQ== +"@nervosnetwork/ckb-types@0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-types/-/ckb-types-0.22.0.tgz#9191c3f1c8da4bc6c5f6a23910eee0c9ec8f267d" + integrity sha512-fA9QD851/PBhBEIWnh9N1S9p+ntEoMNw/GwpsLsL/LfXebzpWxrc10UJgTkOrJEz+Si1MSLz2SKGYGJKRrccTw== "@nodelib/fs.scandir@2.1.2": version "2.1.2" From f87bb77edce3a65b89aee15ae0fb8595a8046b49 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Tue, 8 Oct 2019 15:41:14 +0800 Subject: [PATCH 2/2] chore: using sdk to sign witness --- packages/neuron-wallet/src/services/wallets.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/neuron-wallet/src/services/wallets.ts b/packages/neuron-wallet/src/services/wallets.ts index d137e19cb8..e6b475f018 100644 --- a/packages/neuron-wallet/src/services/wallets.ts +++ b/packages/neuron-wallet/src/services/wallets.ts @@ -6,7 +6,6 @@ import Store from 'models/store' import LockUtils from 'models/lock-utils' import { TransactionWithoutHash, Input } from 'types/cell-types' import ConvertTo from 'types/convert-to' -import Blake2b from 'utils/blake2b' import { WalletNotFound, IsRequired, UsedName } from 'exceptions' import { Address as AddressInterface } from 'database/address/dao' import Keychain from 'models/keys/keychain' @@ -444,15 +443,10 @@ export default class WalletService { } public signWitness = (witness: string, privateKey: string, txHash: string): string => { - const addrObj = core.generateAddress(privateKey) - const oldData = witness - const blake2b = new Blake2b() - blake2b.update(txHash) - blake2b.update(oldData) - const message = blake2b.digest() - const signature = addrObj.signRecoverable(message) - const newWitness = signature - return newWitness + return core.signWitnesses(privateKey)({ + transactionHash: txHash, + witnesses: [witness] + })[0] } // Derivate all child private keys for specified BIP44 paths.