Skip to content

Commit

Permalink
Merge pull request #29 from nash-io/ts/update-fill-order-payload-gene…
Browse files Browse the repository at this point in the history
…ration

Ts/update fill order payload generation
  • Loading branch information
localhuman authored Jan 26, 2021
2 parents 6abf674 + 17c82fc commit d104e2e
Show file tree
Hide file tree
Showing 25 changed files with 623 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: '10'
node-version: '14'
- run: yarn install --frozen-lockfile
- run: yarn test:lint
- run: yarn test:unit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: '10'
node-version: '14'
- run: yarn install --frozen-lockfile
- run: yarn docs
- name: Deploy docs 🚀
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [4.0.7](https://github.com/nash-io/nash-protocol/compare/v4.0.1...v4.0.7) (2021-01-26)

### [4.0.5](https://github.com/nash-io/nash-protocol/compare/v4.0.3...v4.0.5) (2021-01-21)

### [4.0.3](https://github.com/nash-io/nash-protocol/compare/v4.0.1...v4.0.3) (2021-01-21)

### [4.0.1](https://github.com/nash-io/nash-protocol/compare/v3.3.24...v4.0.1) (2020-12-15)

### [3.3.24](https://github.com/nash-io/nash-protocol/compare/v3.3.14...v3.3.24) (2020-12-15)

### [3.3.14](https://github.com/nash-io/nash-protocol/compare/v3.3.11...v3.3.14) (2020-11-24)

### [3.3.21](https://github.com/nash-io/nash-protocol/compare/v3.3.11...v3.3.21) (2020-12-16)

### [3.3.11](https://github.com/nash-io/nash-protocol/compare/v3.4.7...v3.3.11) (2020-08-11)
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neon-exchange/nash-protocol",
"version": "3.3.21",
"version": "4.0.7",
"description": "TypeScript implementation of Nash crypto routines",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand All @@ -10,7 +10,7 @@
"license": "MIT",
"keywords": [],
"scripts": {
"copy:nativewasm": "cp -r src/wasm build/main/wasm && cp src/native/index_osx.node build/main/native && cp src/native/index_linux.node build/main/native && cp -r wasm-webpack build/module/wasm && rm -r build/module/mpc-lib && cp -r wasm-webpack build/module/mpc-lib",
"copy:nativewasm": "cp -r src/wasm build/main/wasm && cp src/native/index_osx.node build/main/native && cp src/native/index_linux.node build/main/native && cp src/native/index_win.node build/main/native && cp -r wasm-webpack build/module/wasm && rm -r build/module/mpc-lib && cp -r wasm-webpack build/module/mpc-lib",
"copy:wasm": "cp -r src/wasm build/main/wasm && cp -r wasm-webpack build/module/wasm",
"build": "yarn clean && yarn build:main && yarn build:module && yarn copy:nativewasm",
"build:main": "tsc -p tsconfig.json",
Expand All @@ -37,7 +37,7 @@
"preinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('nash-protocol must be installed with Yarn: https://yarnpkg.com/')\""
},
"engines": {
"node": ">=8.9"
"node": ">=14.3"
},
"dependencies": {
"bignumber.js": "8.1.1",
Expand Down Expand Up @@ -66,7 +66,7 @@
"@types/elliptic": "6.4.5",
"@types/jest": "23.3.9",
"@types/lodash": "4.14.122",
"@types/node": "13.7.0",
"@types/node": "^14.14.14",
"@types/randombytes": "2.0.0",
"jest": "23.6.0",
"nyc": "13.1.0",
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/blockchain_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"blockchain": "eth",
"hash": "aed88173df2578fad078c48a33f0040364989fa8",
"precision": 18
},
"bat": {
"blockchain": "eth",
"hash": "abcd",
"precision": 18
}
},
"marketData": {
Expand Down Expand Up @@ -98,6 +103,12 @@
"minTradeSize": 4,
"minTradeIncrement": 4,
"minTradeIncrementB": 4
},
"eth_bat": {
"minTickSize": 2,
"minTradeSize": 5,
"minTradeIncrement": 8,
"minTradeIncrementB": 5
}
},
"payloadSigningKey": {
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
"minTradeIncrement": 5,
"minTradeIncrementB": 5
},
"eth_bat": {
"minTickSize": 2,
"minTradeSize": 5,
"minTradeIncrement": 5,
"minTradeIncrementB": 5
},
"gas_eth": {
"minTickSize": 8,
"minTradeSize": 4,
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/signatureVectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
"allowTaker": false,
"amount": {
"value": "10.000000",
"currency": "gas"
"currency": "neo"
},
"buyOrSell": "SELL",
"marketName": "gas_neo",
"marketName": "neo_gas",
"cancellationPolicy": "immediate_or_cancel",
"limitPrice": {
"value": "17.000",
Expand Down
8 changes: 5 additions & 3 deletions src/constants/rates.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const minOrderRate = 0
export const maxOrderRate = 'ffffffffffffffff' // 18446744073709551615
export const maxFeeRate = 250000
export const MIN_ORDER_RATE = 0
export const MAX_ORDER_RATE = 'ffffffffffffffff' // 18446744073709551615
export const MAX_ORDER_AMOUNT = MAX_ORDER_RATE
export const MAX_FEE_RATE = 0.0025
export const BLOCKCHAIN_PRECISION = 8
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { default as getSecretKey } from './getSecretKey'
export { default as mnemonicToMasterSeed } from './mnemonicToMasterSeed'
export { default as mnemonicToSecretKey } from './mnemonicToSecretKey'
export { computePresig } from './mpc/computePresig'
export { fillRPool, configurePoolSettings } from './mpc/fillRPool'
export { fillRPool, configurePoolSettings, getDhPoolSize } from './mpc/fillRPool'
export { fillRPoolIfNeeded } from './mpc/fillRPool'
export { generateAPIKeys } from './mpc/generateAPIKeys'
export { createAPIKey } from './mpc/createAPIKey'
Expand Down
6 changes: 1 addition & 5 deletions src/mpc/computePresig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ export async function computePresig(params: ComputePresigParams): Promise<Presig
})

const [comutePresigOk, presigOrErrorMessage, r] = JSON.parse(
MPCWallet.compute_presig(
JSON.stringify(params.apiKey),
params.messageHash,
JSON.stringify(BlockchainCurve[params.blockchain])
)
MPCWallet.compute_presig(JSON.stringify(params.apiKey), params.messageHash, BlockchainCurve[params.blockchain])
) as [boolean, string, string]
if (comutePresigOk === false) {
throw new Error('Error computing presig: ' + presigOrErrorMessage)
Expand Down
6 changes: 3 additions & 3 deletions src/mpc/fillRPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export const configurePoolSettings = (poolSize: number, minPoolSize?: number) =>
MIN_RPOOL_SIZE = Math.max(BLOCK_RPOOL_SIZE, minPoolSize || poolSize / 2)
}

async function getDhPoolSize(fillPoolParams: FillRPoolParams): Promise<number> {
export async function getDhPoolSize(fillPoolParams: FillRPoolParams): Promise<number> {
const MPCWallet = await import('../mpc-lib')
const curveStr = JSON.stringify(BlockchainCurve[fillPoolParams.blockchain])
const curveStr = BlockchainCurve[fillPoolParams.blockchain]
const [getRPoolSizeSuccess, msgOrSize] = JSON.parse(MPCWallet.get_rpool_size(curveStr)) as [boolean, number | string]
if (getRPoolSizeSuccess === false) {
throw new Error('Error querying rpool size. ' + (msgOrSize as string))
Expand All @@ -31,7 +31,7 @@ const _FILL_JOB: Record<Curve, Promise<void> | null> = {
async function _fill(fillPoolParams: FillRPoolParams): Promise<void> {
const { fillPoolFn, blockchain, paillierPkStr } = fillPoolParams
const MPCWallet = await import('../mpc-lib')
const curveStr = JSON.stringify(BlockchainCurve[blockchain])
const curveStr = BlockchainCurve[fillPoolParams.blockchain]
const [initDHSuccess, clientDHSecrets, clientDHPublics] = JSON.parse(MPCWallet.dh_init(RPOOL_SIZE, curveStr)) as [
boolean,
string[],
Expand Down
13 changes: 7 additions & 6 deletions src/native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ const loadNodeFile = (): NodeFileInterface => {
// case 'freebsd':
// case 'openbsd':
// case 'sunos':
// case 'win32':
// case 'cygwin':
// case 'netbsd':
case 'cygwin':
case 'win32':
return require('./index_win.node')
case 'linux':
return require('./index_linux.node')
case 'darwin':
Expand All @@ -35,25 +36,25 @@ export function dh_init(size: number, curve: string): string {
if (wasm === MpcWallet) {
return wasm.dh_init(size, curve)
}
return MpcWallet.dh_init(size, JSON.parse(curve))
return MpcWallet.dh_init(size, curve)
}
export function fill_rpool(clientDHSecrets: string, serverDHPublics: string, curve: string, pkstr: string): string {
if (wasm === MpcWallet) {
return wasm.fill_rpool(clientDHSecrets, serverDHPublics, curve, pkstr)
}
return MpcWallet.fill_rpool(clientDHSecrets, serverDHPublics, JSON.parse(curve), pkstr)
return MpcWallet.fill_rpool(clientDHSecrets, serverDHPublics, pkstr, curve)
}
export function get_rpool_size(curve: string): string {
if (wasm === MpcWallet) {
return wasm.get_rpool_size(curve)
}
return MpcWallet.get_rpool_size(JSON.parse(curve))
return MpcWallet.get_rpool_size(curve)
}
export function compute_presig(apiKeyStr: string, msgHashStr: string, curve: string): string {
if (wasm === MpcWallet) {
return wasm.compute_presig(apiKeyStr, msgHashStr, curve)
}
return MpcWallet.compute_presig(apiKeyStr, msgHashStr, JSON.parse(curve))
return MpcWallet.compute_presig(apiKeyStr, msgHashStr, curve)
}

export const init_api_childkey_creator = wasm.init_api_childkey_creator
Expand Down
Binary file modified src/native/index_linux.node
Binary file not shown.
Binary file modified src/native/index_osx.node
100644 → 100755
Binary file not shown.
Binary file added src/native/index_win.node
Binary file not shown.
Loading

0 comments on commit d104e2e

Please sign in to comment.