Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose certain functions from @stellar/js-xdr so downstream don't need to mix dependencies. #744

Merged
merged 4 commits into from
May 14, 2024
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/npm_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ jobs:
- name: Deprecate the old package
run: |
npm deprecate stellar-base@"<= 11.0.0" "⚠️ This package has moved to @stellar/stellar-base! 🚚"
npm deprecate @stellar/stellar-base@"= 11.1.0" "⚠️ This version contains breaking changes, use v11.0.1 for compatibility or upgrade to v12."
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
## Unreleased


## [`v11.1.0`](https://github.com/stellar/js-stellar-base/compare/v11.0.1...v11.1.0)
## [`v12.0.0-rc.1`](https://github.com/stellar/js-stellar-base/compare/v11.0.1...v12.0.0-rc.1)

### Added
### Breaking Changes
* The generated XDR has been upgraded to match the upcoming Protocol 21, namely [stellar/stellar-xdr@`1a04392`](https://github.com/stellar/stellar-xdr/commit/1a04392432dacc0092caaeae22a600ea1af3c6a5) ([#738](https://github.com/stellar/js-stellar-base/pull/738)).

### Added
* To facilitate serialization and deserialization for downstream systems, this package now exports `cereal.XdrWriter` and `cereal.XdrReader` which come directly from `@stellar/js-xdr` ([TODO]()).

### Fixed
* Updated various dependencies ([#737](https://github.com/stellar/js-stellar-base/pull/737), [#739](https://github.com/stellar/js-stellar-base/pull/739)).

Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable import/no-import-module-exports */
import xdr from './xdr';
import cereal from './jsxdr';

export { xdr };
export { cereal };
export { hash } from './hashing';
export { sign, verify, FastSigning } from './signing';
export {
Expand Down
4 changes: 4 additions & 0 deletions src/jsxdr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { XdrWriter, XdrReader } from '@stellar/js-xdr';

const cereal = { XdrWriter, XdrReader };
export default cereal;
5 changes: 5 additions & 0 deletions test/unit/soroban_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
describe('Soroban', function () {
it('should have XDR serialization', function () {
expect(StellarBase.cereal).not.to.be.undefined;
console.log(StellarBase.cereal);
});

describe('formatTokenAmount', function () {
const SUCCESS_TEST_CASES = [
{ amount: '1000000001', decimals: 7, expected: '100.0000001' },
Expand Down
38 changes: 38 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1268,3 +1268,41 @@ export namespace Soroban {
function formatTokenAmount(address: string, decimals: number): string;
function parseTokenAmount(value: string, decimals: number): string;
}

export namespace cereal {
// These belong in @stellar/js-xdr but that would be a huge lift since we'd
// need types for the whole thing.
export class XdrWriter {
constructor(buffer?: Buffer|number);

alloc(size: number): number;
resize(minRequiredSize: number): void;
finalize(): Buffer;
toArray(): number[];

write(value: Buffer|string, size: number): XdrReader;
writeInt32BE(value: number): void;
writeUInt32BE(value: number): void;
writeBigInt64BE(value: BigInt): void;
writeBigUInt64BE(value: BigInt): void;
writeFloatBE(value: number): void;
writeDoubleBE(value: number): void;
}

export class XdrReader {
constructor(data: Buffer);

eof: boolean;
advance(size: number): number;
rewind(): void;
ensureInputConsumed(): void;

read(size: number): Buffer;
readInt32BE(): number;
readUInt32BE(): number;
readBigInt64BE(): BigInt;
readBigUInt64BE(): BigInt;
readFloatBE(): number;
readDoubleBE(): number;
}
}
Loading