Skip to content

feat!: modernize as @atomichub/atomicassets v2.0.0 - #1

Merged
robrigo merged 3 commits into
mainfrom
feat/v2-modernization
Jul 16, 2026
Merged

feat!: modernize as @atomichub/atomicassets v2.0.0#1
robrigo merged 3 commits into
mainfrom
feat/v2-modernization

Conversation

@robrigo

@robrigo robrigo commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Why

The upstream pinknetworkx package froze in 2022 while the AtomicAssets contract kept evolving. This modernizes the fork as @atomichub/atomicassets 2.0.0: native BigInt replaces the big-integer dependency (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 (mediatype on schemas, mutable_data on templates) with action helpers for createtempl2, settempldata, and setschematyp. Format stays narrow ({name, type}) so schema-object extras cannot leak into createschema action data.

Validation

45 serialization and action tests pass, including byte-for-byte codec equivalence against the v1 big-integer implementation. A scratch consumer installing via github: ref confirms prepare produces the build output, the codec round-trips, and both module formats resolve.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-integer usage with native BigInt across 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.

Comment on lines 8 to 10
const length = Number(varint_decode(state));
state.position += length;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Serialization/Binary.ts Outdated
Comment on lines 71 to 77
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));
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread src/Schema/VectorSchema.ts Outdated
Comment on lines +9 to +10
deserialize(state: SerializationState): any {
const length = varint_decode(state).toJSNumber();
const length = Number(varint_decode(state));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@robrigo
robrigo force-pushed the feat/v2-modernization branch 6 times, most recently from fada9b9 to 25f7afe Compare July 15, 2026 21:54
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.
@robrigo
robrigo force-pushed the feat/v2-modernization branch from 25f7afe to d845188 Compare July 15, 2026 22:12
@robrigo
robrigo requested a review from Copilot July 15, 2026 23:57
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 53 out of 57 changed files in this pull request and generated 3 comments.

Comment on lines +12 to +15
export function toByteArray(data: ByteInput): Uint8Array {
if (typeof data === 'string') {
return hex_decode(data.startsWith('\\x') ? data.substring(2) : data);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +35 to +38
// 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 } {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +35 to +39
return {
...field,
mediatype: type?.mediatype || derivedType,
info: type?.info || null
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@robrigo
robrigo requested a review from Copilot July 16, 2026 01:22
@robrigo
robrigo merged commit 80580c5 into main Jul 16, 2026
7 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 53 out of 57 changed files in this pull request and generated 1 comment.

Comment on lines +22 to +25
export type ApiSchemaFormatField = SchemaObject & {
mediatype?: string | null;
info?: string | null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants