Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions .eslintrc

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [14, 16, 18, 20, 22, 24]
node-version: [22, 24]
name: Node.js v${{ matrix.node-version }}
runs-on: ubuntu-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: '${{ matrix.node-version }}'
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install dependencies
run: make node_modules
- name: Run checks
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.23.2
26 changes: 17 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
SRC_FILES := $(shell find src -name '*.ts')
TEST_FILES := $(wildcard test/*.ts)
BIN := ./node_modules/.bin
MOCHA_OPTS := -u tdd -r ts-node/register -r tsconfig-paths/register --extension ts --no-experimental-strip-types
MOCHA_OPTS := -u tdd --require tsx --extension ts
MOCHA_ENV := TSX_TSCONFIG_PATH=test/tsconfig.json NODE_OPTIONS='--no-experimental-strip-types'

lib: ${SRC_FILES} package.json tsconfig.json node_modules rollup.config.mjs
@${BIN}/rollup -c && touch lib

.PHONY: test
test: lib node_modules
@TS_NODE_PROJECT='./test/tsconfig.json' \
${BIN}/mocha ${MOCHA_OPTS} test/*.ts --grep '$(grep)'
@${MOCHA_ENV} ${BIN}/mocha ${MOCHA_OPTS} test/*.ts --grep '$(grep)'

.PHONY: test-coverage
test-coverage: lib node_modules
@TS_NODE_PROJECT='./test/tsconfig.json' \
${BIN}/nyc --reporter=html \
@${MOCHA_ENV} ${BIN}/nyc --reporter=html \
${BIN}/mocha ${MOCHA_OPTS} -R nyan test/*.ts

.PHONY: coverage
Expand All @@ -23,17 +22,16 @@ coverage: test-coverage

.PHONY: ci-test
ci-test: lib node_modules
@TS_NODE_PROJECT='./test/tsconfig.json' \
${BIN}/nyc --reporter=text \
@${MOCHA_ENV} ${BIN}/nyc --reporter=text \
${BIN}/mocha ${MOCHA_OPTS} -R list test/*.ts

.PHONY: check
check: node_modules
@${BIN}/eslint src --ext .ts --max-warnings 0 --format unix && echo "Ok"
@${BIN}/eslint src --max-warnings 0 && echo "Ok"

.PHONY: format
format: node_modules
@${BIN}/eslint src --ext .ts --fix
@${BIN}/eslint src --fix

test/browser.html: lib $(TEST_FILES) test/rollup.config.mjs node_modules
@${BIN}/rollup -c test/rollup.config.mjs
Expand All @@ -42,6 +40,16 @@ test/browser.html: lib $(TEST_FILES) test/rollup.config.mjs node_modules
browser-test: test/browser.html
@open test/browser.html

.PHONY: mock-prune
mock-prune: lib node_modules
@MOCK_LOG=$$(mktemp); \
${MOCHA_ENV} MOCK_LOG=$$MOCK_LOG ${BIN}/mocha ${MOCHA_OPTS} test/*.ts >/dev/null || \
(echo "Suite not passing, refusing to prune" && exit 1); \
for f in test/data/*.json; do \
grep -q $$(basename $$f) $$MOCK_LOG || rm -v $$f; \
done; \
rm -f $$MOCK_LOG

node_modules:
yarn install --non-interactive --frozen-lockfile --ignore-scripts

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Avaiable on npm: https://www.npmjs.com/package/@wharfkit/antelope
npm install @wharfkit/antelope
```

Version 2.x requires Node.js 20.19 or later (or a bundler that consumes ES modules) and a JavaScript environment with BigInt and WebCrypto support. Projects on older Node.js versions should continue using the 1.x releases:

```
npm install @wharfkit/antelope@1
```

## API Documentation

https://wharfkit.github.io/antelope/
Expand Down Expand Up @@ -50,7 +56,7 @@ grep="bug-report" make test
Or running `mocha` directly from the installed `./node_modules` folder:

```bash
TS_NODE_PROJECT='./test/tsconfig.json' ./node_modules/.bin/mocha -u tdd -r ts-node/register -r tsconfig-paths/register --extension ts test/*.ts --grep="bug-report"
TSX_TSCONFIG_PATH='./test/tsconfig.json' ./node_modules/.bin/mocha -u tdd --require tsx --extension ts test/*.ts --grep="bug-report"
```

Once your test is failing and successfully shows the issue occurring, please submit a pull request to this repository. Feel free to include any additional details in the body of the pull request that might help us understand the situation.
Expand Down
34 changes: 34 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
import eslintPluginPrettier from 'eslint-plugin-prettier/recommended'
import esx from 'eslint-plugin-es-x'

export default tseslint.config(
{
ignores: ['lib/*', 'node_modules/**'],
},
eslint.configs.recommended,
...tseslint.configs.recommended,
eslintPluginPrettier,
{
plugins: {
'es-x': esx,
},
rules: {
'prettier/prettier': 'warn',
'no-console': 'warn',
'sort-imports': ['warn', {ignoreCase: true, ignoreDeclarationSort: true}],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-empty-function': 'warn',
'@typescript-eslint/no-this-alias': 'off',
'no-inner-declarations': 'off',
'es-x/no-optional-chaining': 'error',
'es-x/no-class-fields': 'off',
'es-x/no-export-ns-from': 'off',
'preserve-caught-error': 'off',
},
}
)
73 changes: 36 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "@wharfkit/antelope",
"description": "Library for working with Antelope powered blockchains.",
"version": "1.2.0",
"version": "2.0.0-rc1",
"homepage": "https://github.com/wharfkit/antelope",
"license": "BSD-3-Clause-No-Military-License",
"engines": {
"node": ">=20.19.0"
},
"main": "lib/antelope.js",
"module": "lib/antelope.m.js",
"types": "lib/antelope.d.ts",
Expand All @@ -20,44 +23,40 @@
"prepare": "make"
},
"dependencies": {
"bn.js": "^4.11.9",
"brorand": "^1.1.0",
"elliptic": "^6.5.4",
"hash.js": "^1.0.0",
"pako": "^2.1.0",
"tslib": "^2.0.3"
"@noble/curves": "^2.2.0",
"@noble/hashes": "^2.2.0",
"bn.js": "^5.2.5",
"pako": "^3.0.1",
"tslib": "^2.8.1"
},
"devDependencies": {
"@rollup/plugin-alias": "^4.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.0.0",
"@rollup/plugin-virtual": "^3.0.1",
"@types/bn.js": "^5.1.0",
"@types/elliptic": "^6.4.12",
"@types/mocha": "^10.0.0",
"@types/node": "^18.6.5",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"chai": "^4.3.4",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-es-x": "^6.0.0",
"eslint-plugin-prettier": "^4.0.0",
"gh-pages": "^5.0.0",
"mocha": "^10.1.0",
"node-fetch": "^2.6.1",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"rollup": "^3.17.2",
"rollup-plugin-dts": "^5.2.0",
"ts-node": "^10.0.0",
"tsconfig-paths": "^4.1.0",
"typedoc": "^0.23.10",
"typescript": "^4.1.2"
"@eslint/js": "^10.0.0",
"@rollup/plugin-alias": "^6.0.0",
"@rollup/plugin-commonjs": "^29.0.3",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-replace": "^6.0.3",
"@rollup/plugin-terser": "^1.0.0",
"@rollup/plugin-typescript": "^12.3.0",
"@rollup/plugin-virtual": "^3.0.2",
"@types/bn.js": "^5.2.0",
"@types/mocha": "^10.0.10",
"@types/node": "^22.20.1",
"chai": "^6.2.2",
"eslint": "^10.8.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-es-x": "^10.0.0",
"eslint-plugin-prettier": "^5.5.6",
"gh-pages": "^6.3.0",
"mocha": "^11.8.0",
"nyc": "^18.0.0",
"prettier": "^3.9.6",
"rollup": "^4.62.4",
"rollup-plugin-dts": "^6.5.1",
"tsx": "^4.19.0",
"typedoc": "^0.28.20",
"typescript": "^5.9.3",
"typescript-eslint": "^8.66.0"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
4 changes: 2 additions & 2 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fs from 'fs'
import path from 'path'
import {URL} from 'url'
import {fileURLToPath} from 'url'

import dts from 'rollup-plugin-dts'
import typescript from '@rollup/plugin-typescript'

// eslint-disable-next-line es-x/no-import-meta
const __dirname = path.dirname(new URL(import.meta.url).pathname)
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json')))

const license = fs.readFileSync('LICENSE').toString('utf-8').trim()
Expand Down
8 changes: 4 additions & 4 deletions src/api/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface APIProvider {
export interface FetchProviderOptions {
/**
* Fetch instance, must be provided in non-browser environments.
* You can use the node-fetch package in Node.js.
* Node.js 18+ includes a built-in fetch implementation.
*/
fetch?: Fetch
/**
Expand All @@ -46,10 +46,10 @@ export class FetchProvider implements APIProvider {
this.headers = options.headers
}
if (!options.fetch) {
if (typeof window !== 'undefined' && window.fetch) {
if (typeof globalThis !== 'undefined' && globalThis.fetch) {
this.fetch = globalThis.fetch.bind(globalThis)
} else if (typeof window !== 'undefined' && window.fetch) {
this.fetch = window.fetch.bind(window)
} else if (typeof global !== 'undefined' && global.fetch) {
this.fetch = global.fetch.bind(global)
} else {
throw new Error('Missing fetch')
}
Expand Down
26 changes: 19 additions & 7 deletions src/api/v1/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class ChainAPI {
): Promise<GetTableRowsResponse<TableIndexTypes[Key]>>
async get_table_rows<
Row extends ABISerializableConstructor,
Index extends TableIndexType = Name
Index extends TableIndexType = Name,
>(
params: GetTableRowsParamsTyped<Index, Row>
): Promise<GetTableRowsResponse<Index, InstanceType<Row>>>
Expand All @@ -305,6 +305,10 @@ export class ChainAPI {
key_type = 'sha256'
} else if (isInstanceOf(someBound, Checksum160)) {
key_type = 'ripemd160'
} else if (isInstanceOf(someBound, Float128)) {
key_type = 'float128'
} else if (isInstanceOf(someBound, Float64)) {
key_type = 'float64'
}
}
if (!key_type) {
Expand All @@ -315,14 +319,21 @@ export class ChainAPI {
// if we know the row type don't ask the node to perform abi decoding
json = type === undefined
}
let upper_bound = params.upper_bound
if (upper_bound && typeof upper_bound !== 'string') {
upper_bound = String(upper_bound)
let encode_type = params.encode_type
if (
!encode_type &&
(isInstanceOf(params.lower_bound, Float128) ||
isInstanceOf(params.upper_bound, Float128))
) {
encode_type = 'hex'
}
let lower_bound = params.lower_bound
if (lower_bound && typeof lower_bound !== 'string') {
lower_bound = String(lower_bound)
const boundString = (bound: any) => {
if (!bound) return bound
if (isInstanceOf(bound, Float128) && encode_type === 'hex') return bound.toBoundHex()
return String(bound)
}
const upper_bound = boundString(params.upper_bound)
const lower_bound = boundString(params.lower_bound)
let scope = params.scope
if (typeof scope === 'undefined') {
scope = String(Name.from(params.code))
Expand All @@ -339,6 +350,7 @@ export class ChainAPI {
limit: params.limit !== undefined ? UInt32.from(params.limit) : undefined,
scope,
key_type,
encode_type,
json,
upper_bound,
lower_bound,
Expand Down
Loading
Loading