Skip to content

Commit

Permalink
[ᚬmaster] Rc/v0.26.4 (#417)
Browse files Browse the repository at this point in the history
[ᚬmaster] Rc/v0.26.4
  • Loading branch information
Keith-CY authored Jan 2, 2020
2 parents 28ff958 + c1e494a commit 9f0d1b6
Show file tree
Hide file tree
Showing 21 changed files with 150 additions and 24 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.26.4](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.26.3...v0.26.4) (2020-01-02)


### Features

* **rpc:** add the new rpc method of get_capacity_by_lock_hash ([9628084](https://github.com/nervosnetwork/ckb-sdk-js/commit/9628084ba6111e2580d793a752992f45e142fcc5))





## [0.26.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.26.2...v0.26.3) (2019-12-23)

**Note:** Version bump only for package ckb-sdk-js
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ After that you can use the `ckb` object to generate addresses, send requests, et

## Default RPC

Please see [Default RPC](https://github.com/nervosnetwork/ckb-sdk-js/blob/develop/packages/ckb-sdk-rpc/src/defaultRPC.ts#L176)
Please see [Default RPC](https://github.com/nervosnetwork/ckb-sdk-js/blob/develop/packages/ckb-sdk-rpc/src/defaultRPC.ts#L182)

## Persistent Connection

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "0.26.3"
"version": "0.26.4"
}
8 changes: 8 additions & 0 deletions packages/ckb-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.26.4](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.26.3...v0.26.4) (2020-01-02)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-core





## [0.26.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.26.2...v0.26.3) (2019-12-23)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-core
Expand Down
10 changes: 5 additions & 5 deletions packages/ckb-sdk-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-core",
"version": "0.26.3",
"version": "0.26.4",
"description": "JavaScript SDK for Nervos Network CKB Project",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
Expand Down Expand Up @@ -31,9 +31,9 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-rpc": "0.26.3",
"@nervosnetwork/ckb-sdk-utils": "0.26.3",
"@nervosnetwork/ckb-types": "0.26.3"
"@nervosnetwork/ckb-sdk-rpc": "0.26.4",
"@nervosnetwork/ckb-sdk-utils": "0.26.4",
"@nervosnetwork/ckb-types": "0.26.4"
},
"gitHead": "e963f874553075afcb2d666dc9d883c6d87bae94"
"gitHead": "9f485f3db58382495fbf9cbadc0f9fd089872850"
}
11 changes: 11 additions & 0 deletions packages/ckb-sdk-rpc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.26.4](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.26.3...v0.26.4) (2020-01-02)


### Features

* **rpc:** add the new rpc method of get_capacity_by_lock_hash ([9628084](https://github.com/nervosnetwork/ckb-sdk-js/commit/9628084ba6111e2580d793a752992f45e142fcc5))





## [0.26.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.26.2...v0.26.3) (2019-12-23)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-rpc
Expand Down
4 changes: 2 additions & 2 deletions packages/ckb-sdk-rpc/__tests__/ckb-rpc-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('ckb-rpc settings and helpers', () => {
expect(rpc.node.httpsAgent).toBeDefined()
})

it('has 29 default rpc', () => {
expect(rpc.methods.length).toBe(29)
it('has 30 default rpc', () => {
expect(rpc.methods.length).toBe(30)
})

it('set node url to http://test.localhost:8114', () => {
Expand Down
14 changes: 14 additions & 0 deletions packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -1291,5 +1291,19 @@
"feeRate": "0x7d0"
}
}
],
"toCapacityByLockHash": [
{
"result": {
"block_number": "0x400",
"capacity": "0xb00fb84df292",
"cells_count": "0x3f5"
},
"expected": {
"blockNumber": "0x400",
"capacity": "0xb00fb84df292",
"cellsCount": "0x3f5"
}
}
]
}
8 changes: 4 additions & 4 deletions packages/ckb-sdk-rpc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-rpc",
"version": "0.26.3",
"version": "0.26.4",
"description": "RPC module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js/packages/ckb-rpc#readme",
Expand Down Expand Up @@ -33,12 +33,12 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-utils": "0.26.3",
"@nervosnetwork/ckb-sdk-utils": "0.26.4",
"axios": "0.19.0"
},
"devDependencies": {
"@nervosnetwork/ckb-types": "0.26.3",
"@nervosnetwork/ckb-types": "0.26.4",
"dotenv": "8.1.0"
},
"gitHead": "e963f874553075afcb2d666dc9d883c6d87bae94"
"gitHead": "9f485f3db58382495fbf9cbadc0f9fd089872850"
}
8 changes: 8 additions & 0 deletions packages/ckb-sdk-rpc/src/defaultRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ const defaultRPC: CKBComponents.Method[] = [
method: 'calculate_dao_maximum_withdraw',
paramsFormatters: [paramsFmts.toOutPoint, paramsFmts.toHash],
},
{
name: 'getCapacityByLockHash',
method: 'get_capacity_by_lock_hash',
paramsFormatters: [paramsFmts.toHash],
resultFormatters: resultFmts.toCapacityByLockHash,
},
]

export class DefaultRPC {
Expand Down Expand Up @@ -475,6 +481,8 @@ export class DefaultRPC {
outPoint: CKBComponents.OutPoint,
withdrawBlockHash: CKBComponents.Hash256,
) => Promise<string>

public getCapacityByLockHash!: (lockHash: CKBComponents.Hash) => Promise<CKBComponents.CapacityByLockHash>
}

export default DefaultRPC
12 changes: 12 additions & 0 deletions packages/ckb-sdk-rpc/src/resultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@ const formatter = {
...rest,
}
},
toCapacityByLockHash: (capacityByLockHash: RPC.CapacityByLockHash): CKBComponents.CapacityByLockHash => {
if (!capacityByLockHash) {
return capacityByLockHash
}
const { cells_count: cellsCount, block_number: blockNumber, capacity, ...rest } = capacityByLockHash
return {
blockNumber,
capacity,
cellsCount,
...rest,
}
},
}

export default formatter
Expand Down
6 changes: 6 additions & 0 deletions packages/ckb-sdk-rpc/types/rpc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,11 @@ declare module RPC {
export interface FeeRate {
fee_rate: Number
}

export interface CapacityByLockHash {
block_number: BlockNumber
capacity: Capacity
cells_count: Number
}
}
/* eslint-enable camelcase */
8 changes: 8 additions & 0 deletions packages/ckb-sdk-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.26.4](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.26.3...v0.26.4) (2020-01-02)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-utils





## [0.26.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.26.2...v0.26.3) (2019-12-23)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-utils
Expand Down
7 changes: 7 additions & 0 deletions packages/ckb-sdk-utils/__tests__/ecpair/ecpare.fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
"privateKey": "0xe79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3",
"compressed": true,
"publicKey": "0x024a501efd328e062c8675f2365970728c859c592beeefd6be8ead3d901330bc01"
},
"privateKeyHasInvalidLength": {
"privateKey": "0xf70eea3041c793746f07d47f28a62d6555041b9edc74501a75ffbf47c55fc9",
"exception": "Private key has invalid length"
},
"leadingZeroShouldBeRemained": {
"privateKey": "0x00f70eea3041c793746f07d47f28a62d6555041b9edc74501a75ffbf47c55fc9"
}
}
}
16 changes: 14 additions & 2 deletions packages/ckb-sdk-utils/__tests__/ecpair/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ECPair', () => {
it('new ecpair with empty options, default compressed should be true', () => {
const fixture = instantiateFixtures.withEmptyOption

const ecpair = new ECPair(hexToBytes(fixture.privateKey), {})
const ecpair = new ECPair(fixture.privateKey, {})
expect(ecpair.compressed).toBe(fixture.compressed)
expect(ecpair.privateKey).toEqual(fixture.privateKey)
expect(ecpair.publicKey).toBe(fixture.publicKey)
Expand All @@ -33,7 +33,7 @@ describe('ECPair', () => {
it('new ecpair with default options which should be { compressed: true }', () => {
const fixture = instantiateFixtures.withDefaultOption

const ecpair = new ECPair(hexToBytes(fixture.privateKey))
const ecpair = new ECPair(fixture.privateKey)
expect(ecpair.compressed).toBe(fixture.compressed)
expect(ecpair.privateKey).toEqual(fixture.privateKey)
expect(ecpair.publicKey).toBe(fixture.publicKey)
Expand All @@ -48,6 +48,18 @@ describe('ECPair', () => {
expect(() => new ECPair(privateKey, {})).toThrow(new HexStringShouldStartWith0x(privateKey))
})

it('shoule throw an error if private key has invalid length', () => {
const fixture = instantiateFixtures.privateKeyHasInvalidLength
expect(() => new ECPair(fixture.privateKey)).toThrow(new Error(fixture.exception))
expect(() => new ECPair(hexToBytes(fixture.privateKey), 'hex')).toThrow(fixture.exception)
})

it('leading 0 of private key should be remained', () => {
const fixture = instantiateFixtures.leadingZeroShouldBeRemained
const key = new ECPair(fixture.privateKey)
expect(key.privateKey).toBe(fixture.privateKey)
})

it('sign and verify message', () => {
sigFixtures.forEach(fixture => {
const ecpair = new ECPair(`0x${fixture.privkey}`)
Expand Down
6 changes: 3 additions & 3 deletions packages/ckb-sdk-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-utils",
"version": "0.26.3",
"version": "0.26.4",
"description": "Utils module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
Expand Down Expand Up @@ -31,7 +31,7 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-types": "0.26.3",
"@nervosnetwork/ckb-types": "0.26.4",
"blake2b-wasm": "2.1.0",
"elliptic": "6.5.1",
"jsbi": "3.1.1"
Expand All @@ -41,5 +41,5 @@
"@types/elliptic": "6.4.8",
"@types/utf8": "2.1.6"
},
"gitHead": "e963f874553075afcb2d666dc9d883c6d87bae94"
"gitHead": "9f485f3db58382495fbf9cbadc0f9fd089872850"
}
14 changes: 12 additions & 2 deletions packages/ckb-sdk-utils/src/ecpair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,28 @@ class ECPair {
sk: Uint8Array | string,
{ compressed = true }: Options = {
compressed: true,
}
},
) {
if (sk === undefined) throw new ArgumentRequired('Private key')

if (typeof sk === 'string' && !sk.startsWith('0x')) {
throw new HexStringShouldStartWith0x(sk)
}

if (typeof sk === 'string' && sk.length !== 66) {
throw new Error('Private key has invalid length')
}

if (typeof sk === 'object' && sk.byteLength !== 32) {
throw new Error('Private key has invalid length')
}

this.key = ec.keyFromPrivate(typeof sk === 'string' ? sk.replace(/^0x/, '') : sk)
this.compressed = compressed
}

get privateKey() {
return `0x${this.key.getPrivate('hex')}`
return `0x${this.key.getPrivate('hex').padStart(64, '0')}`
}

get publicKey() {
Expand Down
6 changes: 4 additions & 2 deletions packages/ckb-sdk-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ export { serializeScript, serializeRawTransaction, serializeTransaction, seriali

declare const TextDecoder: any // should be removed when the type definition of TextDecoder updates
declare const TextEncoder: any // should be removed when the type definition of TextEncoder updates
export const { blake2b, bech32, blake160 } = crypto
const textEncoder = new (typeof TextEncoder !== 'undefined' ? TextEncoder : util.TextEncoder)()
const textDecoder = new (typeof TextDecoder !== 'undefined' ? TextDecoder : util.TextDecoder)()
export const PERSONAL = textEncoder.encode('ckb-default-hash')
export { JSBI }

export const hexToBytes = (rawhex: string | number) => {
Expand Down Expand Up @@ -57,6 +55,10 @@ export const utf8ToBytes = (str: string) => textEncoder.encode(str)

export const utf8ToHex = (str: string) => bytesToHex(utf8ToBytes(str))

export const PERSONAL = textEncoder.encode('ckb-default-hash')

export const { blake2b, bech32, blake160 } = crypto

export const scriptToHash = (script: CKBComponents.Script) => {
if (!script) throw new ArgumentRequired('Script')
const serializedScript = serializeScript(script)
Expand Down
11 changes: 11 additions & 0 deletions packages/ckb-types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.26.4](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.26.3...v0.26.4) (2020-01-02)


### Features

* **rpc:** add the new rpc method of get_capacity_by_lock_hash ([9628084](https://github.com/nervosnetwork/ckb-sdk-js/commit/9628084ba6111e2580d793a752992f45e142fcc5))





## [0.26.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.26.2...v0.26.3) (2019-12-23)

**Note:** Version bump only for package @nervosnetwork/ckb-types
Expand Down
6 changes: 6 additions & 0 deletions packages/ckb-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,10 @@ declare namespace CKBComponents {
export interface RawTransactionToSign extends Omit<RawTransaction, 'witnesses'> {
witnesses: (WitnessArgs | Witness)[]
}

export interface CapacityByLockHash {
blockNumber: BlockNumber
capacity: Capacity
cellsCount: Number
}
}
4 changes: 2 additions & 2 deletions packages/ckb-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-types",
"version": "0.26.3",
"version": "0.26.4",
"description": "Type module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
Expand All @@ -23,5 +23,5 @@
"scripts": {
"doc": "../../node_modules/.bin/typedoc --out docs ./index.d.ts --mode modules --includeDeclarations --excludeExternals --ignoreCompilerErrors --theme default --readme README.md"
},
"gitHead": "e963f874553075afcb2d666dc9d883c6d87bae94"
"gitHead": "9f485f3db58382495fbf9cbadc0f9fd089872850"
}

0 comments on commit 9f0d1b6

Please sign in to comment.