Skip to content

Commit

Permalink
Merge pull request #499 from nervosnetwork/rc/v0.36.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Sep 26, 2020
2 parents 8a34900 + 368917d commit 7005892
Show file tree
Hide file tree
Showing 31 changed files with 993 additions and 134 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module.exports = {
}]
},
"globals": {
"BigInt": "readonly"
"BigInt": "readonly",
"globalThis": "readonly",
},
"env": {
"node": true,
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ packages/*/lib
playground.ts

#docs
docs
/docs
# ignore for deploy docs
package-lock.json

Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.36.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.36.0...v0.36.1) (2020-09-26)


### Features

* **utils:** disable blake2b-wasm when the host is iOS 11 ([4c70554](https://github.com/nervosnetwork/ckb-sdk-js/commit/4c7055466aeb2b8cd2fda2ae927e88cb699d161b))
* **utils:** add a method to reconcile transactions ([1ae64cd](https://github.com/nervosnetwork/ckb-sdk-js/commit/1ae64cd258cacffcb77e664bb3853dd4c7ec9150))





# [0.36.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.35.0...v0.36.0) (2020-09-21)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.36.0"
"version": "0.36.1"
}
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.36.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.36.0...v0.36.1) (2020-09-26)

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





# [0.36.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.35.0...v0.36.0) (2020-09-21)


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.36.0",
"version": "0.36.1",
"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,10 +31,10 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-rpc": "0.36.0",
"@nervosnetwork/ckb-sdk-utils": "0.36.0",
"@nervosnetwork/ckb-types": "0.36.0",
"@nervosnetwork/ckb-sdk-rpc": "0.36.1",
"@nervosnetwork/ckb-sdk-utils": "0.36.1",
"@nervosnetwork/ckb-types": "0.36.1",
"tslib": "2.0.1"
},
"gitHead": "d0adcbb7e6743fdcc049984534afab13f5ede178"
"gitHead": "b34332872a9168a1879d3020ca3546b72816823a"
}
8 changes: 8 additions & 0 deletions packages/ckb-sdk-rpc/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.36.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.36.0...v0.36.1) (2020-09-26)

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





# [0.36.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.35.0...v0.36.0) (2020-09-21)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-rpc
Expand Down
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.36.0",
"version": "0.36.1",
"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.36.0",
"@nervosnetwork/ckb-sdk-utils": "0.36.1",
"axios": "0.19.2",
"tslib": "2.0.1"
},
"devDependencies": {
"@nervosnetwork/ckb-types": "0.36.0"
"@nervosnetwork/ckb-types": "0.36.1"
},
"gitHead": "d0adcbb7e6743fdcc049984534afab13f5ede178"
"gitHead": "b34332872a9168a1879d3020ca3546b72816823a"
}
12 changes: 12 additions & 0 deletions packages/ckb-sdk-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.36.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.36.0...v0.36.1) (2020-09-26)


### Features

* **utils:** disable blake2b-wasm when the host is iOS 11 ([4c70554](https://github.com/nervosnetwork/ckb-sdk-js/commit/4c7055466aeb2b8cd2fda2ae927e88cb699d161b))
* **utils:** add a method to reconcile transactions ([1ae64cd](https://github.com/nervosnetwork/ckb-sdk-js/commit/1ae64cd258cacffcb77e664bb3853dd4c7ec9150))





# [0.36.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.35.0...v0.36.0) (2020-09-21)


Expand Down
35 changes: 35 additions & 0 deletions packages/ckb-sdk-utils/__tests__/crypto/bech32.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { bech32 } = require('../..')
const fixtures = require('./bech32.fixtures.json')

describe('bech32', () => {
fixtures.bech32.valid.forEach(f => {
it(`fromWords/toWords ${f.hex}`, () => {
if (f.hex) {
const words = bech32.toWords(Buffer.from(f.hex, 'hex'))
const bytes = Buffer.from(bech32.fromWords(f.words))
expect(words.join('')).toEqual(f.words.join(''))
expect(bytes.toString('hex')).toBe(f.hex)
}
})

it(`encode ${f.prefix}`, () => {
const encoded = bech32.encode(f.prefix, f.words, f.limit)
expect(encoded).toBe(f.string.toLowerCase())
})

it(`decode ${f.string}`, () => {
const decoded = bech32.decode(f.string, f.limit)
expect(decoded.prefix).toBe(f.prefix.toLowerCase())
expect(decoded.words.join('')).toBe(f.words.join(''))
})

it(`fails for ${f.string} with 1 bit flipped`, () => {
const buf = Buffer.from(f.string, 'utf8')
buf[f.string.lastIndexOf('1') + 1] ^= 0x1
const str = buf.toString('utf8')
expect(() => {
bech32.decode(str, f.limit)
}).toThrow()
})
})
})
12 changes: 12 additions & 0 deletions packages/ckb-sdk-utils/__tests__/crypto/blake160.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { blake160 } = require('../..')

describe('blake160', () => {
it('blake160', () => {
const fixture = {
message: '024a501efd328e062c8675f2365970728c859c592beeefd6be8ead3d901330bc01',
digest: '36c329ed630d6ce750712a477543672adab57f4c',
}
const digest = blake160(new Uint8Array(Buffer.from(fixture.message, 'hex')), 'hex')
expect(digest).toBe(fixture.digest)
})
})
101 changes: 101 additions & 0 deletions packages/ckb-sdk-utils/__tests__/crypto/blake2b.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const { blake2b, PERSONAL } = require('../..')
const { ready } = require('../../lib/crypto/blake2b')
const fixtures = require('./blake2b.fixtures.json')

describe('blake2b', () => {
it('blake2b([]) with personal', () => {
const fixture = {
message: new Uint8Array(),
digest: '44f4c69744d5f8c55d642062949dcae49bc4e7ef43d388c5a12f42b5633d163e',
}
const s = blake2b(32, null, null, PERSONAL)
s.update(fixture.message)
const digest = s.digest('hex')
expect(digest).toBe(fixture.digest)
})

it('blake2b(Buffer.from("The quick brown fox jumps over the lazy dog")) with personal', () => {
const fixture = {
message: 'The quick brown fox jumps over the lazy dog',
digest: 'abfa2c08d62f6f567d088d6ba41d3bbbb9a45c241a8e3789ef39700060b5cee2',
}
const s = blake2b(32, null, null, PERSONAL)
s.update(new Uint8Array(Buffer.from(fixture.message, 'utf8')))
const digest = s.digest('hex')
expect(digest).toBe(fixture.digest)
})

test.each(fixtures)('%s', ({ outlen, out, input, key, salt, personal }) => {
if (+outlen < 16) {
expect(() => {
blake2b(
outlen,
key ? new Uint8Array(Buffer.from(key, 'hex')) : null,
salt ? new Uint8Array(Buffer.from(salt, 'hex')) : null,
personal ? new Uint8Array(Buffer.from(personal, 'hex')) : null,
)
}).toThrowError(`Expect outlen to be at least 16, but ${outlen} received`)
} else {
const s = blake2b(
outlen,
key ? new Uint8Array(Buffer.from(key, 'hex')) : null,
salt ? new Uint8Array(Buffer.from(salt, 'hex')) : null,
personal ? new Uint8Array(Buffer.from(personal, 'hex')) : null,
)
s.update(new Uint8Array(Buffer.from(input, 'hex')))
const digest = s.digest('hex')
expect(digest).toBe(out)
}
})
})

describe('blake2b-wasm-ready', () => {
afterEach(() => {
delete globalThis.navigator
})

describe("When it's in browser but not iOS 11", () => {
beforeEach(() => {
Object.defineProperty(globalThis, 'navigator', {
value: {
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_4 like Mac OS X)',
},
})
})

it('callback should be invoked without error', () => {
expect.assertions(1)
ready(err => {
expect(err).toBeUndefined()
})
})
})

describe("When it's not in browser and navigator is undefined", () => {
beforeEach(() => {
delete globalThis.navigator
})
it('callback should be invoked without error', () => {
expect.assertions(1)
ready(err => {
expect(err).toBeUndefined()
})
})
})

describe("When it's iOS 11", () => {
beforeEach(() => {
Object.defineProperty(globalThis, 'navigator', {
value: {
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_1 like Mac OS X)',
},
})
})
it('callback should be invoked with error', () => {
expect.assertions(1)
ready(err => {
expect(err).toEqual(new Error('blake2b-wasm is unavailable on iOS 11'))
})
})
})
})
7 changes: 7 additions & 0 deletions packages/ckb-sdk-utils/__tests__/exceptions/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,12 @@
"code": 101,
"message": "Expect PERSONAL length to be 16, but 32 received"
}
},
"ReconciliationException": {
"params": [],
"expected": {
"code": 105,
"message": "Fail to reconcile transaction, try to increase extra count or check the transaction"
}
}
}
Loading

0 comments on commit 7005892

Please sign in to comment.