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

XdrWriterError [TypeError]: XDR Write Error: [object Object] is not a DecoratedSignatur #170

Open
jimmyzhao-57blocks opened this issue Sep 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jimmyzhao-57blocks
Copy link

Hi all,
I first use npm install @stellar/typescript-wallet-sdk. And when I was developing with typescript-wallet-sdk, I encountered the above error message (as mentioned in the title) while executing the code for submitting a transaction. My sample code is as follows:

const {
  walletSdk,
  Keypair,
  AccountKeypair,
  NativeAssetId,
} = require("@stellar/typescript-wallet-sdk");
const { xdr } = require("@stellar/stellar-sdk");

const sourcePublicKey = 'the from wallet address'
const destinationPublicKey = 'the to wallet address'
const wallet = walletSdk.Wallet.TestNet();
const server = wallet.stellar().server;

const sourceAccountPair = new AccountKeypair(
  Keypair.fromPublicKey(sourcePublicKey)
);
const txBuilder = await wallet.stellar().transaction({
  sourceAddress: sourceAccountPair,
});
const tx = txBuilder
  .transfer(destinationPublicKey, new NativeAssetId(), "10")
  .build();
// use 3rd party api to get the signature
const signature = mySignServer(tx...)
tx.addDecoratedSignature(
  new xdr.DecoratedSignature({
    signature,
    hint: Keypair.fromPublicKey(sourcePublicKey).signatureHint(),
  })
);
const transactionResult = await server.submitTransaction(tx); // <-- error this line

The error log:

node_modules/@stellar/typescript-wallet-sdk/lib/bundle.js:8359
      throw new _errors__WEBPACK_IMPORTED_MODULE_2__.XdrWriterError(`${value} is not a ${this.structName}`);
            ^
XdrWriterError [TypeError]: XDR Write Error: [object Object] is not a DecoratedSignature

The relevant code from bundle.js is as follows:

class Struct extends _xdr_type__WEBPACK_IMPORTED_MODULE_1__.XdrPrimitiveType {
  // other codes...
  static write(value, writer) {
    if (!(value instanceof this))
      throw new _errors__WEBPACK_IMPORTED_MODULE_2__.XdrWriterError(`${value} is not a ${this.structName}`); // this line is 8359
  }

I found that the bundle.js code includes the code from the stellar/js-xdr library, but this part of the code in js-xdr is clearly different from the one in bundle.js (the conditional statements are different).

The bundle.js file is located in the lib directory of typescript-wallet-sdk. This folder should have been generated when typescript-wallet-sdk was built and then published to npm. So, I'm wondering if it's an issue with the build process of typescript-wallet-sdk.
I suspect that the typescript-wallet-sdk library has not bundled the latest js-xdr code.

image

I would appreciate any advice from those with relevant experience on how to resolve this issue based on the current library. Thanks.

Here are the versions of my dependencies:
@stellar/typescript-wallet-sdk: 1.7.0
@stellar/stellar-sdk: 12.1.0
@stellar/stellar-base: 12.1.0
@stellar/js-xdr: 3.1.2
node version: 18.20.4

@jimmyzhao-57blocks jimmyzhao-57blocks added the bug Something isn't working label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant