Skip to content

Commit

Permalink
feat: bump sdk to v0.22.0
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Oct 7, 2019
1 parent de940d4 commit b6e3035
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 81 deletions.
2 changes: 1 addition & 1 deletion packages/neuron-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/neuron-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -47,7 +47,7 @@ export default class Transaction extends BaseEntity {
@Column({
type: 'simple-json',
})
witnesses!: Witness[]
witnesses!: string[]

@Column({
type: 'varchar',
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const env: ENV = {
name: 'Local',
remote: 'http://localhost:8114',
type: 1,
chain: 'ckb_devnet',
chain: 'ckb_dev',
},
],
},
Expand Down
7 changes: 3 additions & 4 deletions packages/neuron-wallet/src/models/lock-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/services/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default class CellsService {
if (!args) {
return undefined
}
return args[0]
return args
})
.filter(blake160 => !!blake160) as string[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class TransactionGenerator {
data: '0x',
lock: {
codeHash,
args: [blake160],
args: blake160,
hashType,
},
}
Expand All @@ -53,7 +53,7 @@ export class TransactionGenerator {
data: '0x',
lock: {
codeHash,
args: [changeBlake160],
args: changeBlake160,
hashType,
},
}
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/services/tx/transaction-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
}
Expand Down
20 changes: 8 additions & 12 deletions packages/neuron-wallet/src/services/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -380,16 +380,16 @@ 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)
if (!pathAndPrivateKey) {
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
})

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions packages/neuron-wallet/src/types/cell-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface TransactionWithoutHash {
value?: string
blockNumber?: string
blockHash?: string
witnesses?: Witness[]
witnesses?: string[]
type?: string
description?: string
status?: TransactionStatus
Expand All @@ -65,10 +65,6 @@ export interface Input {
lock?: Script
}

export interface Witness {
data: string[]
}

export interface Cell {
capacity: string
data?: string
Expand All @@ -85,7 +81,7 @@ export interface OutPoint {
}

export interface Script {
args?: string[]
args?: string
codeHash?: string | null
hashType: ScriptHashType
}
16 changes: 8 additions & 8 deletions packages/neuron-wallet/tests/models/lock-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand Down
6 changes: 3 additions & 3 deletions packages/neuron-wallet/tests/services/cells.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('CellsService', () => {
const bob = {
lockScript: {
codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2',
args: ['0x36c329ed630d6ce750712a477543672adab57f4c'],
args: '0x36c329ed630d6ce750712a477543672adab57f4c',
hashType: ScriptHashType.Type,
},
lockHash: '0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba',
Expand All @@ -43,7 +43,7 @@ describe('CellsService', () => {
const alice = {
lockScript: {
codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2',
args: ['0xe2193df51d78411601796b35b17b4f8f2cd85bd0'],
args: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0',
hashType: ScriptHashType.Type,
},
lockHash: '0x489306d801d54bee2d8562ae20fdc53635b568f8107bddff15bb357f520cc02c',
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('CellsService', () => {

const typeScript: Script = {
codeHash: randomHex(),
args: [],
args: '',
hashType: ScriptHashType.Data,
}

Expand Down
9 changes: 3 additions & 6 deletions packages/neuron-wallet/tests/services/wallets.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
})
})

Expand Down
51 changes: 21 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]":
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/[email protected]":
version "2.1.2"
Expand Down

0 comments on commit b6e3035

Please sign in to comment.