feat!: modernize as @atomichub/atomicassets v2.0.0 - #1
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the SDK into the @atomichub/atomicassets v2.0.0 fork by replacing legacy dependencies/tooling (big-integer, node-fetch, webpack/tslint) with native BigInt + native fetch and a tsup-based dual CJS/ESM + browser-global build, while extending the public type/action surface to support AtomicAssets v2 contract fields/actions.
Changes:
- Replaced
big-integerusage with nativeBigIntacross serialization/parsers and updated tests accordingly. - Switched build/lint toolchain from webpack/TSLint to tsup + ESLint; updated package metadata/exports for dual-module publishing.
- Added v2-aware API/types and action helpers (
mediatype,mutable_data,createtempl2,settempldata,setschematyp) plus new tests for the v2 surface.
Reviewed changes
Copilot reviewed 37 out of 41 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
webpack.prod.js |
Removes legacy webpack browser build configuration. |
tsup.config.ts |
Adds tsup config for CJS/ESM builds plus IIFE browser global output. |
tslint.json |
Removes deprecated TSLint configuration. |
tsconfig.web.json |
Removes separate web tsconfig tied to the deleted webpack build. |
tsconfig.json |
Updates TS target/libs/types and compiler options for the modernized toolchain. |
test/schema_v2.test.ts |
Adds tests for v2 schema additions (mediatype) and mutable_data typing. |
test/rpcapi.test.ts |
Removes explicit node-fetch injection in favor of native fetch path. |
test/explorerapi.test.ts |
Removes explicit node-fetch injection in favor of native fetch path. |
test/binary.test.ts |
Updates assertions to reflect bigint-returning helpers (Number(...) conversions). |
test/binary_coercion.test.ts |
Adds tests pinning BigInt fail-fast coercion behavior. |
test/actions_v2.test.ts |
Adds tests for new v2 action helper methods and normalization behavior. |
src/Serialization/TypeParser/VariableParser.ts |
Migrates varint length decoding to BigInt/Number conversion for variable-length bytes. |
src/Serialization/TypeParser/VariableIntegerParser.ts |
Migrates variable integer parsing/limits from big-integer to native BigInt. |
src/Serialization/TypeParser/FloatingParser.ts |
Cleans up require usage for vendored float helper. |
src/Serialization/TypeParser/FixedIntegerParser.ts |
Migrates fixed integer parsing from big-integer to native BigInt bit operations. |
src/Serialization/Binary.ts |
Reimplements binary varint/zigzag/sign helpers using native BigInt. |
src/Schema/VectorSchema.ts |
Migrates vector length decoding to BigInt/Number conversion. |
src/Schema/MappingSchema.ts |
Updates varint identifier comparisons/conversions for bigint-returning decode. |
src/Schema/index.ts |
Extends schema format entries with optional v2 mediatype. |
src/index.ts |
Expands root exports (schema interfaces/types, generator types, explorer param/enums, objects). |
src/API/Rpc/Template.ts |
Removes legacy TSLint suppression comments. |
src/API/Rpc/Schema.ts |
Aligns RPC schema formatting/types with updated schema objects. |
src/API/Rpc/RpcCache.ts |
Updates RPC cache schema format typing to reuse SchemaObject. |
src/API/Rpc/Offer.ts |
Removes legacy TSLint suppression comments. |
src/API/Rpc/index.ts |
Uses globalThis.fetch fallback instead of global cast. |
src/API/Rpc/Collection.ts |
Removes legacy TSLint suppression comments. |
src/API/Rpc/Asset.ts |
Removes legacy TSLint suppression comments. |
src/API/Explorer/Objects.ts |
Adds mutable_data to templates; renames ISchema to IApiSchema. |
src/API/Explorer/index.ts |
Uses globalThis.fetch fallback; updates schema return types to IApiSchema. |
src/Actions/Rpc.ts |
Removes legacy TSLint suppression comment. |
src/Actions/Generator.ts |
Adds v2 action helpers + types (Format narrow, SchemaFormatType, new methods). |
src/Actions/Explorer.ts |
Removes legacy TSLint suppression comment. |
package.json |
Renames/scope-bumps package to 2.0.0, adds exports/files, switches scripts to tsup/eslint, removes runtime deps. |
LICENSE |
Updates fork copyright notice. |
eslint.config.js |
Adds flat ESLint config for typescript-eslint and migration constraints. |
dist/atomicassets.js |
Removes committed bundle output from the repository. |
.npmignore |
Removes npmignore in favor of files allowlist in package.json. |
.gitignore |
Ignores dist/ output directory alongside build/. |
.github/workflows/publish.yml |
Adds tag-triggered npm publish workflow. |
.github/workflows/ci.yml |
Adds CI workflow for build/lint/test across Node 18–24. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const length = Number(varint_decode(state)); | ||
| state.position += length; | ||
|
|
There was a problem hiding this comment.
Applied: the varint length is now bounds-checked against the remaining buffer as a bigint before Number conversion, so an oversized length throws DeserializationError instead of corrupting state.position.
| if (n > 2n ** BigInt(8 * size)) { | ||
| throw new Error('cannot unsign integer: too big'); | ||
| } | ||
|
|
||
| if (n.greater(bigInt(2).pow(8 * size - 1))) { | ||
| return n.minus(1).xor(bigInt(2).pow(8 * size).minus(1)).negate(); | ||
| if (n > 2n ** BigInt(8 * size - 1)) { | ||
| return -((n - 1n) ^ (2n ** BigInt(8 * size) - 1n)); | ||
| } |
There was a problem hiding this comment.
Applied: both comparisons are now inclusive (>=), so the sign-bit value decodes negative and 2^(8*size) is rejected. Covered by a new boundary test (128/127/255/256 at size 1).
| deserialize(state: SerializationState): any { | ||
| const length = varint_decode(state).toJSNumber(); | ||
| const length = Number(varint_decode(state)); |
There was a problem hiding this comment.
Applied: the decoded length is validated against the remaining byte count as a bigint before Number conversion; every element consumes at least one byte, so a length larger than the remainder is always invalid and now throws immediately.
fada9b9 to
25f7afe
Compare
Fork of the abandoned pinknetworkx/atomicassets-js, republished under the atomichub scope with native AtomicAssets v2 awareness. Adds the optional mediatype hint on schema-format entries and mutable_data on templates, plus the assets v2 action helpers createtempl2, settempldata, and setschematyp, so consumers no longer need local shims for v2 fields. The wire codec (serialize/deserialize/ObjectSchema) is preserved byte-identical through a swap of big-integer for native BigInt, leaving the package with zero runtime dependencies. Transport moves to native fetch and the build is dual-format via tsup (CJS, ESM loadable under raw Node and bundlers, plus an IIFE global), replacing the tslint and webpack toolchain with ESLint and TypeScript 6.
25f7afe to
d845188
Compare
A pushed v* tag alone could publish; the npm-publish environment holds the run for maintainer approval and gives npm's trusted publisher config an environment to pin to, so only approved runs of this workflow can mint a publish token. The npm upgrade step meets trusted publishing's >=11.5.1 CLI floor ahead of the post-bootstrap OIDC cutover.
| export function toByteArray(data: ByteInput): Uint8Array { | ||
| if (typeof data === 'string') { | ||
| return hex_decode(data.startsWith('\\x') ? data.substring(2) : data); | ||
| } |
There was a problem hiding this comment.
Applied in d92cfad: hex_decode now rejects non-hex and odd-length input with DeserializationError (matching the base58 guard) instead of letting parseInt NaN coerce to zero bytes. Covered by new codec guard tests.
| // The return is typed for the dominant case — a MappingSchema root decoding | ||
| // to a plain object. A bare ValueSchema/VectorSchema root yields a | ||
| // scalar/array instead; such callers know their shape and can assert it. | ||
| export function deserialize(data: ByteInput, schema: ISchema): { [key: string]: any } { |
There was a problem hiding this comment.
Deliberate, documented in the comment above the function: the return is typed for the dominant MappingSchema case; a bare ValueSchema/VectorSchema root caller knows its shape and asserts it. Widening to any would degrade typing for every ordinary caller to help the rare one.
| return { | ||
| ...field, | ||
| mediatype: type?.mediatype || derivedType, | ||
| info: type?.info || null | ||
| }; |
There was a problem hiding this comment.
Intentional: this function was upstreamed verbatim from the deployed atomicassets API (eosio-contract-api formatSchema), which normalizes blank info to null with the same || — and since setschematyp defaults info to an empty string, switching to ?? would flip most rows in live API responses from null to "". Blank info is treated as absent by design.
…bytes hex_decode fed non-hex or odd-length input through parseInt, whose NaN results Uint8Array coerces to 0, so a corrupted hex string decoded into wrong bytes with no error. The public ByteInput widening on deserialize exposes this path to arbitrary caller strings, so malformed input now throws DeserializationError, matching the base58 guard.
| export type ApiSchemaFormatField = SchemaObject & { | ||
| mediatype?: string | null; | ||
| info?: string | null; | ||
| }; |
Why
The upstream pinknetworkx package froze in 2022 while the AtomicAssets contract kept evolving. This modernizes the fork as
@atomichub/atomicassets2.0.0: native BigInt replaces thebig-integerdependency (zero runtime deps), native fetch replaces node-fetch, tsup emits a dual CJS/ESM build plus an IIFE browser global in place of the tslint/webpack toolchain, and the type surface gains the v2 contract fields (mediatypeon schemas,mutable_dataon templates) with action helpers forcreatetempl2,settempldata, andsetschematyp.Formatstays narrow ({name, type}) so schema-object extras cannot leak intocreateschemaaction data.Validation
45 serialization and action tests pass, including byte-for-byte codec equivalence against the v1
big-integerimplementation. A scratch consumer installing viagithub:ref confirmsprepareproduces the build output, the codec round-trips, and both module formats resolve.